37 #include <vtkMatrix4x4.h>
38 #include <vtkTransform.h>
44 namespace cx_transform3D_internal
47 boost::array<double, 16>
flatten(
const Eigen::Affine3d*
self)
49 boost::array<double, 16> retval;
50 boost::array<double, 16>::iterator raw = retval.begin();
52 for (
int r = 0; r < 4; ++r)
53 for (
int c = 0; c < 4; ++c)
54 *raw++ = (*
self)(r, c);
63 for (
int r = 0; r < 4; ++r)
64 for (
int c = 0; c < 4; ++c)
65 (*
self)(r, c) = m->GetElement(r, c);
68 void fill(Eigen::Affine3d*
self,
float m[4][4])
72 for (
int r = 0; r < 4; ++r)
73 for (
int c = 0; c < 4; ++c)
74 (*
self)(r, c) = m[r][c];
81 void fill(Eigen::Affine3d*
self,
const double* raw)
83 for (
int r = 0; r < 4; ++r)
84 for (
int c = 0; c < 4; ++c)
85 (*
self)(r, c) = *raw++;
92 for (
int r = 0; r < 4; ++r)
93 for (
int c = 0; c < 4; ++c)
94 m->SetElement(r, c, (*
self)(r, c));
103 retval->SetMatrix(self->getVtkMatrix());
108 std::ostream&
put(
const Eigen::Affine3d*
self, std::ostream& s,
int indent,
char newline)
110 QString ind(indent,
' ');
112 std::ostringstream ss;
113 ss << setprecision(3) << std::fixed;
115 for (
unsigned i = 0; i < 4; ++i)
118 for (
unsigned j = 0; j < 4; ++j)
120 ss << setw(10) << (*self)(i, j) <<
" ";
141 if (raw.size() != 16)
144 return Eigen::Affine3d();
146 Eigen::Affine3d retval;
147 fill(&retval, &*raw.begin());
158 boost::array<double, 16> m = a.flatten();
159 boost::array<double, 16> n = b.flatten();
160 for (
int j = 0; j < 16; ++j)
181 retval.scale(scale_);
188 retval.translate(translation);
195 retval.rotate(Eigen::AngleAxisd(angle, Vector3D::UnitX()));
202 retval.rotate(Eigen::AngleAxisd(angle, Vector3D::UnitY()));
209 retval.rotate(Eigen::AngleAxisd(angle, Vector3D::UnitZ()));
222 for (
unsigned i = 0; i < scale.size(); ++i)
224 if (fabs(inrange[i]) < 1.0E-5)
227 scale[i] = outrange[i] / inrange[i];
238 t.matrix().col(0).head(3) = ivec;
239 t.matrix().col(1).head(3) = jvec;
240 t.matrix().col(2).head(3) =
cross(ivec, jvec);
241 t.matrix().col(3).head(3) = center;
256 return Transform3D::Identity();
vtkSmartPointer< class vtkMatrix4x4 > vtkMatrix4x4Ptr
pcsRAS
Right-Anterior-Superior, used by Slicer3D, ITK-Snap, nifti.
DoubleBoundingBox3D transform(const Transform3D &m, const DoubleBoundingBox3D &bb)
Transform3D createTransformRotateY(const double angle)
Vector3D topRight() const
Transform3D createTransformScale(const Vector3D &scale_)
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
cxResource_EXPORT Transform3D createTransformFromReferenceToExternal(PATIENT_COORDINATE_SYSTEM external)
cxResource_EXPORT Transform3D createTransformLPS2RAS()
Vector3D bottomLeft() const
vtkSmartPointer< class vtkTransform > vtkTransformPtr
Transform3D createTransformNormalize(const DoubleBoundingBox3D &in, const DoubleBoundingBox3D &out)
bool similar(const DoubleBoundingBox3D &a, const DoubleBoundingBox3D &b, double tol)
Vector3D cross(const Vector3D &a, const Vector3D &b)
compute cross product of a and b.
Transform3D createTransformIJC(const Vector3D &ivec, const Vector3D &jvec, const Vector3D ¢er)
Transform3D createTransformTranslate(const Vector3D &translation)
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,xmax,ymin,ymax,zmin,zmax}, in order to simplify communication with vtk.
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Transform3D createTransformRotateZ(const double angle)
Transform3D createTransformRotateX(const double angle)
std::vector< double > convertQString2DoubleVector(const QString &input, bool *ok)