28 #include <Inventor/nodes/SoSeparator.h>
29 #include <Inventor/nodes/SoTranslation.h>
30 #include <Inventor/nodes/SoRotationXYZ.h>
31 #include <Inventor/nodes/SoTransform.h>
32 #include <Inventor/nodes/SoLineSet.h>
33 #include <Inventor/nodes/SoVertexProperty.h>
34 #include <Inventor/nodes/SoCylinder.h>
35 #include <Inventor/nodes/SoComplexity.h>
36 #include <Inventor/nodes/SoDrawStyle.h>
44 #include <Eigen/Eigenvalues>
55 const double& sigmaScale,
57 const double& translate,
58 const bool& symmetric)
62 if (!covMatrixIsSane(
covmat)) {
63 VP1Msg::message(
"WARNING in VP1ErrorUtils: covariance matrix isn't sane (i.e. contains NaNs)");
66 if (sigmaScale!=sigmaScale)
VP1Msg::message(
"WARNING in VP1ErrorUtils: sigmaScale nan");
67 if (translate!=translate)
VP1Msg::message(
"WARNING in VP1ErrorUtils: translate nan");
71 if (eigensolver.info() != Eigen::Success) {
75 double v0 = eigensolver.eigenvalues()[0];
76 double v1 = eigensolver.eigenvalues()[1];
79 if ( (
v0-v1)<0.000005 ) {
80 VP1Msg::message(
"WARNING in VP1ErrorUtils: v0 or v1 is zero. Not drawing RotatedErrorEllipse");
95 sigmaScale * sqrt(v1) ,
98 SoRotationXYZ * r1 =
new SoRotationXYZ;
103 if (translate != 0.0)
105 SoTranslation *
t0 =
new SoTranslation;
106 t0->translation.setValue(0.0,0.0, translate );
110 gr->addChild( ellipse );
111 SoTranslation *
t1 =
new SoTranslation;
112 t1->translation.setValue(0.0,0.0, -2*translate );
117 gr->addChild( ellipse );
123 const double& sigmaScale,
135 SoVertexProperty * vertices =
new SoVertexProperty;
137 float xpos=0.5*std::fabs(
error*sigmaScale);
138 float ypos=0.5*std::fabs(
length);
140 vertices->vertex.set1Value(iver++,-xpos,-ypos,0.0);
141 vertices->vertex.set1Value(iver++,-xpos,+ypos,0.0);
142 vertices->vertex.set1Value(iver++,+xpos,-ypos,0.0);
143 vertices->vertex.set1Value(iver++,+xpos,+ypos,0.0);
146 SoLineSet * errbars =
new SoLineSet;
147 errbars->vertexProperty = vertices;
149 errbars->numVertices.set1Value(numlines++,2);
150 errbars->numVertices.set1Value(numlines++,2);
151 gr->addChild( errbars );
154 SoVertexProperty * vertices2 =
new SoVertexProperty;
155 vertices2->vertex.set1Value(iver++,-xpos,0.0,0.0);
156 vertices2->vertex.set1Value(iver++,+xpos,0.0,0.0);
158 SoLineSet * errbarConnection =
new SoLineSet;
159 errbarConnection->vertexProperty = vertices2;
160 errbarConnection->numVertices.set1Value(0,2);
162 SoDrawStyle *drawStyle =
new SoDrawStyle;
164 drawStyle->linePattern.setValue(0xFF00);
165 gr->addChild(drawStyle);
166 gr->addChild( errbarConnection );
173 SoSeparator* errDetailed,
177 const double& sigmaScale,
179 const bool& moveToSurface,
181 const bool& addTransform)
186 VP1Msg::message(
"WARNING in VP1ErrorUtils: covariance matrix isn't sane (i.e. contains NaNs)");
187 std::cout<<tmpcovmat<<std::endl;
191 SoSeparator * ellipseGrp =
new SoSeparator;
216 t1->translation.setValue(
p1.x(),
p1.y(),
p1.z());
217 errSimple->addChild(
t1 );
218 errDetailed->addChild(
t1 );
220 errSimple->addChild( ellipseGrp );
221 errDetailed->addChild( ellipseGrp );
228 SoSeparator* errDetailed,
232 const double& sigmaScale,
233 const bool& drawZErrCircles,
234 const bool& drawCylinder,
237 const bool& addTransform)
246 errDetailed->addChild(
t1 );
247 errSimple->addChild(
t1 );
250 const double sqrtv0 = sqrt( tmpcovmat(0,0) );
253 sqrtv1 = sqrt( tmpcovmat(1,1) );
265 const double rp =
radius + sigmaScale * sqrtv0;
266 const double rm =
radius - sigmaScale * sqrtv0;
269 SoTranslation *
t0 =
new SoTranslation;
273 SoSeparator * circleGrp =
new SoSeparator;
274 circleGrp->addChild(
t0);
276 SoSeparator * circleGrpSimple =
new SoSeparator;
277 circleGrpSimple->addChild(
t0);
279 SoVertexProperty *vertices =
new SoVertexProperty();
282 if ( drawZErrCircles )
285 zz[0] = -sigmaScale * sqrtv1;
287 zz[2] = +sigmaScale * sqrtv1;
307 SoLineSet * circles =
new SoLineSet();
308 SoLineSet * circlesSimple =
new SoLineSet();
311 int numlinesSimple(0);
312 for (
int k = 0;
k<Nrr;
k++)
314 for (
int j = 0; j<Nzz; j++)
316 vertices->vertex.set1Value(iver++,
rr[
k],0.0,zz[j]);
317 for (
int i = 1;
i < numNodes;
i++)
319 vertices->vertex.set1Value(iver++,
320 cos(2.0*
static_cast<double>(
i)*
M_PI/
static_cast<double>(numNodes))*
rr[
k],
321 sin(2.0*
static_cast<double>(
i)*
M_PI/
static_cast<double>(numNodes))*
rr[
k],
324 vertices->vertex.set1Value(iver++,
rr[
k],0.0,zz[j]);
326 circles->numVertices.set1Value(numlines++,numNodes+1);
330 circlesSimple->numVertices.set1Value(numlinesSimple++,numNodes+1);
334 circles->vertexProperty = vertices;
335 circleGrp->addChild( circles );
337 circlesSimple->vertexProperty = vertices;
338 circleGrpSimple->addChild( circlesSimple );
340 errDetailed->addChild( circleGrp );
341 errSimple->addChild( circleGrpSimple );
346 SoCylinder * outerCyl =
new SoCylinder;
347 outerCyl->removePart( SoCylinder::TOP );
348 outerCyl->removePart( SoCylinder::BOTTOM );
349 outerCyl->radius.setValue (
rp );
350 outerCyl->height.setValue ( 2.0 * sigmaScale * sqrtv1 );
352 SoSeparator * cylGrp =
new SoSeparator;
353 cylGrp->addChild(
t0);
355 SoGroup * outCylGrp =
new SoGroup;
356 SoRotationXYZ * outCylRot =
new SoRotationXYZ;
358 outCylRot->angle = M_PI_2;
359 outCylGrp->addChild(outCylRot);
360 outCylGrp->addChild(outerCyl);
361 cylGrp->addChild(outCylGrp);
365 errDetailed->addChild( trans );
366 errDetailed->addChild( cylGrp );