16 #include <vtkMatrix4x4.h>
17 #include <vtkTransform.h>
26 boost::array<double, 16>
flatten(
const Eigen::Affine3d*
self)
28 boost::array<double, 16> retval;
29 boost::array<double, 16>::iterator raw = retval.begin();
31 for (
int r = 0; r < 4; ++r)
32 for (
int c = 0; c < 4; ++c)
33 *raw++ = (*
self)(r, c);
42 for (
int r = 0; r < 4; ++r)
43 for (
int c = 0; c < 4; ++c)
44 (*
self)(r, c) = m->GetElement(r, c);
47 void fill(Eigen::Affine3d*
self,
float m[4][4])
51 for (
int r = 0; r < 4; ++r)
52 for (
int c = 0; c < 4; ++c)
53 (*
self)(r, c) = m[r][c];
60 void fill(Eigen::Affine3d*
self,
const double* raw)
62 for (
int r = 0; r < 4; ++r)
63 for (
int c = 0; c < 4; ++c)
64 (*
self)(r, c) = *raw++;
71 for (
int r = 0; r < 4; ++r)
72 for (
int c = 0; c < 4; ++c)
73 m->SetElement(r, c, (*
self)(r, c));
82 retval->SetMatrix(self->getVtkMatrix());
87 std::ostream&
put(
const Eigen::Affine3d*
self, std::ostream& s,
int indent,
char newline)
89 QString ind(indent,
' ');
91 std::ostringstream ss;
92 ss << setprecision(3) << std::fixed;
94 for (
unsigned i = 0; i < 4; ++i)
97 for (
unsigned j = 0; j < 4; ++j)
99 ss << setw(10) << (*self)(i, j) <<
" ";
120 if (raw.size() != 16)
123 return Eigen::Affine3d();
125 Eigen::Affine3d retval;
126 fill(&retval, &*raw.begin());
137 boost::array<double, 16> m = a.flatten();
138 boost::array<double, 16> n = b.flatten();
139 for (
int j = 0; j < 16; ++j)
160 retval.scale(scale_);
167 retval.translate(translation);
174 retval.rotate(Eigen::AngleAxisd(angle, Vector3D::UnitX()));
181 retval.rotate(Eigen::AngleAxisd(angle, Vector3D::UnitY()));
188 retval.rotate(Eigen::AngleAxisd(angle, Vector3D::UnitZ()));
203 return Transform3D::Identity();
215 kk =
cross(from, e_y);
219 retval.rotate(Eigen::AngleAxisd(
M_PI, kk));
224 double dotnormal =
dot(from, to)/from.length()/to.length();
225 double angle = acos(dotnormal);
228 retval.rotate(Eigen::AngleAxisd(angle, k.normal()));
242 for (
unsigned i = 0; i < scale.size(); ++i)
244 if (fabs(inrange[i]) < 1.0E-5)
247 scale[i] = outrange[i] / inrange[i];
258 t.matrix().col(0).head(3) = ivec;
259 t.matrix().col(1).head(3) = jvec;
260 t.matrix().col(2).head(3) =
cross(ivec, jvec);
261 t.matrix().col(3).head(3) = center;
276 return Transform3D::Identity();
281 Eigen::IOFormat singleLineFormatting(Eigen::StreamPrecision, Eigen::DontAlignCols,
", ",
" | ",
"",
"",
"",
"");
282 std::ostringstream stream;
283 stream <<
transform.matrix().format(singleLineFormatting);