18 #include <Inventor/C/errors/debugerror.h>
19 #include <Inventor/nodes/SoTransform.h>
28 static bool isBad(
const double&
x,
const QString& ctxStr,
const double&
limit = 1.0e20 )
32 if (!ctxStr.isEmpty())
42 HepGeom::Vector3D<double> translation = transformation.getTranslation();
43 CLHEP::HepRotation
rotation = transformation.getRotation();
44 SoTransform *myTransform = tin ? tin :
new SoTransform();
45 myTransform->translation = SbVec3f(translation.x(),
53 bool inputok =
isSane( transformation,
"input HepGeom::Transform3D" );
54 bool outputok =
isSane( myTransform,
"output SoTransform" );
56 VP1Msg::messageVerbose(
"VP1LinAlgUtils::toSoTransform ERROR: Problems observed in input HepGeom::Transform3D");
59 if (inputok!=outputok)
60 VP1Msg::messageVerbose(
"VP1LinAlgUtils::toSoTransform Error introduced in HepGeom::Transform3D -> SoTransform conversion!");
72 SoTransform *myTransform = tin ? tin :
new SoTransform();
73 myTransform->translation = SbVec3f(translation.x(),
87 bool inputok =
isSane( transformation,
"input HepGeom::Transform3D" );
88 bool outputok =
isSane( myTransform,
"output SoTransform" );
90 VP1Msg::messageVerbose(
"VP1LinAlgUtils::toSoTransform ERROR: Problems observed in input HepGeom::Transform3D");
93 if (inputok!=outputok)
94 VP1Msg::messageVerbose(
"VP1LinAlgUtils::toSoTransform Error introduced in HepGeom::Transform3D -> SoTransform conversion!");
103 result.setTransform(xf->translation.getValue(), xf->rotation.getValue(),
104 xf->scaleFactor.getValue(), xf->scaleOrientation.getValue(), xf->center.getValue());
106 bool inputok =
isSane( xf,
"input SoTransform" );
109 VP1Msg::messageVerbose(
"VP1LinAlgUtils::transformToMatrix(SoTransform*,..) ERROR: Problems observed in input SoTransform");
111 VP1Msg::messageVerbose(
"VP1LinAlgUtils::transformToMatrix(SoTransform*,..) ERROR: Problems observed in output SbMatrix");
112 if (inputok!=outputok)
113 VP1Msg::messageVerbose(
"VP1LinAlgUtils::transformToMatrix(SoTransform*,..) Error introduced in SoTransform -> SbMatrix conversion!");
120 result = SbMatrix(heptr.xx(),heptr.yx(),heptr.zx(),0,
121 heptr.xy(),heptr.yy(),heptr.zy(),0,
122 heptr.xz(),heptr.yz(),heptr.zz(),0,
123 heptr.dx(),heptr.dy(),heptr.dz(),1);
125 bool inputok =
isSane( heptr,
"input HepGeom::Transform3D" );
128 VP1Msg::messageVerbose(
"VP1LinAlgUtils::transformToMatrix(HepGeom::Transform3D,..) ERROR: Problems observed in input HepGeom::Transform3D");
130 VP1Msg::messageVerbose(
"VP1LinAlgUtils::transformToMatrix(HepGeom::Transform3D,..) ERROR: Problems observed in output SbMatrix");
131 if (inputok!=outputok)
132 VP1Msg::messageVerbose(
"VP1LinAlgUtils::transformToMatrix(HepGeom::Transform3D,..) Error introduced in HepGeom::Transform3D -> SbMatrix conversion!");
139 SbVec3f translation, scaleFactor;
140 SbRotation
rotation, scaleOrientation;
141 matr.getTransform(translation,
rotation, scaleFactor, scaleOrientation, SbVec3f(0,0,0));
142 SoTransform *
t = tin ? tin :
new SoTransform;
143 t->translation.setValue(translation);
145 t->scaleFactor.setValue(scaleFactor);
146 t->scaleOrientation.setValue(scaleOrientation);
147 t->center.setValue(0,0,0);
149 bool inputok =
isSane( matr,
"input SbMatrix" );
150 bool outputok =
isSane(
t,
"output SoTransform" );
155 if (inputok!=outputok)
156 VP1Msg::messageVerbose(
"VP1LinAlgUtils::toSoTransform Error introduced in SoTransform -> SbMatrix conversion!");
163 float& translation_x,
float& translation_y,
float& translation_z,
164 float& rotaxis_x,
float& rotaxis_y,
float& rotaxis_z,
float& rotangle_radians )
166 SbVec3f translation, scaleFactor, rotaxis;
167 SbRotation
rotation, scaleOrientation;
168 matr.getTransform (translation,
rotation,scaleFactor,scaleOrientation,SbVec3f(0,0,0));
169 translation.getValue(translation_x,translation_y,translation_z);
170 rotation.getValue(rotaxis,rotangle_radians);
171 rotaxis.getValue(rotaxis_x,rotaxis_y,rotaxis_z);
173 if (!
isSane( matr,
"input SbMatrix" ))
174 VP1Msg::messageVerbose(
"VP1LinAlgUtils::decodeTransformation ERROR: Problems observed in output SbMatrix");
181 #define BAD(x) { ok=false; if (!ctxStr.isEmpty()) VP1Msg::messageVerbose("VP1LinAlgUtils ("+ctxStr+") ERROR: "+QString(x)); };
187 HepGeom::Vector3D<double> translation =
t.getTranslation();
188 CLHEP::HepRotation
rotation =
t.getRotation();
189 CLHEP::Hep3Vector rotationAxis;
190 double rotationAngle;
191 rotation.getAngleAxis(rotationAngle,rotationAxis);
199 BAD(
"Problem in raw 4x4 transformation matrix!");
201 BAD(
"Problem in translation!");
205 BAD(
"Problem in rotation");
207 BAD(
"Problem in rotationAxis");
209 BAD(
"Problem in rotationAngle");
212 const double det =
t.xx()*
t.yy()*
t.zz()
213 +
t.zx()*
t.xy()*
t.yz()
214 +
t.xz()*
t.yx()*
t.zy()
215 -
t.xx()*
t.zy()*
t.yz()
216 -
t.yx()*
t.xy()*
t.zz()
217 -
t.zx()*
t.yy()*
t.xz();
218 const double eps = 1.0e-5;
219 if (det<1.0-eps||det>1.0+eps)
233 double rotationAngle;
271 BAD(
"Problem in raw 4x4 transformation matrix!");
273 BAD(
"Problem in translation!");
277 BAD(
"Problem in rotation");
279 BAD(
"Problem in rotationAxis");
281 BAD(
"Problem in rotationAngle");
290 const double det =
t.matrix().determinant();
291 const double eps = 1.0e-5;
292 if ( det < 1.0-eps || det > 1.0+eps )
303 if (!ctxStr.isEmpty())
310 t->rotation.getValue().getValue(q0,q1, q2,q3);
312 BAD(
"Problem in quarternion representation of rotation!");
313 t->scaleOrientation.getValue().getValue(q0,q1, q2,q3);
315 BAD(
"Problem in quarternion representation of scaleOrientation!");
317 t->translation.getValue().getValue(
x,
y,
z);
319 BAD(
"Problem in translation!");
320 t->scaleFactor.getValue().getValue(
x,
y,
z);
322 BAD(
"Problem in scaleFactor!");
323 t->center.getValue().getValue(
x,
y,
z);
325 BAD(
"Problem in center!");
336 for (
int i = 0;
i < 4; ++
i)
337 for (
int j = 0; j < 4; ++j)
343 BAD(
"Problem in raw 4x4 matrix!");
345 SbVec3f translation, scaleFactor, rotaxis;
346 SbRotation
rotation, scaleOrientation;
347 matr.getTransform(translation,
rotation,scaleFactor,scaleOrientation,SbVec3f(0,0,0));
351 BAD(
"Problem in quarternion representation of rotation!");
352 scaleOrientation.getValue(q0,q1, q2,q3);
354 BAD(
"Problem in quarternion representation of scaleOrientation!");
356 translation.getValue(
x,
y,
z);
358 BAD(
"Problem in translation!");
359 scaleFactor.getValue(
x,
y,
z);
361 BAD(
"Problem in scaleFactor!");
363 const float eps = 1.0e-5;
364 const float det3 = matr.det3();
365 if (det3<1.0-eps||det3>1.0+eps)
366 BAD(
"Determinant of rotation part is not consistent with 1 (det3="+
QString::number(det3)+
")!");
367 const float det4 = matr.det4();
368 if (det4<1.0-eps||det4>1.0+eps)
369 BAD(
"Determinant of rotation part is not consistent with 1 (det4="+
QString::number(det4)+
")!");
377 double phi = (
x == 0.0f)? (
y==0.0
f?0.0:0.5*
M_PI) : std::abs(
atan(std::abs(
y/
static_cast<double>(
x))));
380 else if (x<0.0f&&y>=0.0
f)
382 else if (
x<0.0
f&&
y<0.0
f)
394 s = ( ((point)[0]-(point0)[0])*((point1)[0]-(point0)[0]) +
395 ((point)[1]-(point0)[1])*((point1)[1]-(point0)[1]) +
396 ((point)[2]-(point0)[2])*((point1)[2]-(point0)[2]) ) /
397 ( ((point1)[0]-(point0)[0])*((point1)[0]-(point0)[0]) +
398 ((point1)[1]-(point0)[1])*((point1)[1]-(point0)[1]) +
399 ((point1)[2]-(point0)[2])*((point1)[2]-(point0)[2]) );
427 double d3232 = p32.dot(p32);
429 double d1010 = p10.dot(p10);
430 if (d3232==0.0||d1010==0.0||d3232!=d3232||d1010!=d1010) {
434 VP1Msg::messageDebug(
"VP1LinAlgUtils distLineLineParam ERROR: One or both input lines ill defined");
438 double d3210 = p32.dot(p10);
439 double denom = d1010 * d3232 - d3210 * d3210;
441 double d0232 = p02.dot(p32);
445 VP1Msg::messageDebug(
"VP1LinAlgUtils distLineLineParam Warning: Input lines are parallel. Choosing arbitrary point of closest approach");
448 double d0210 = p02.dot(p10);
449 double numer = d0232 * d3210 - d0210 * d3232;
452 t = (d0232 + d3210 *
s) / d3232;