37 #include <vtkMatrix4x4.h> 38 #include <vtkTransform.h> 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()));
224 return Transform3D::Identity();
236 kk =
cross(from, e_y);
240 retval.rotate(Eigen::AngleAxisd(
M_PI, kk));
245 double dotnormal =
dot(from, to)/from.length()/to.length();
246 double angle = acos(dotnormal);
249 retval.rotate(Eigen::AngleAxisd(angle, k.normal()));
263 for (
unsigned i = 0; i < scale.size(); ++i)
265 if (fabs(inrange[i]) < 1.0E-5)
268 scale[i] = outrange[i] / inrange[i];
279 t.matrix().col(0).head(3) = ivec;
280 t.matrix().col(1).head(3) = jvec;
281 t.matrix().col(2).head(3) =
cross(ivec, jvec);
282 t.matrix().col(3).head(3) = center;
297 return Transform3D::Identity();
302 Eigen::IOFormat singleLineFormatting(Eigen::StreamPrecision, Eigen::DontAlignCols,
", ",
" | ",
"",
"",
"",
"");
303 std::ostringstream stream;
304 stream << transform.matrix().format(singleLineFormatting);
vtkSmartPointer< class vtkMatrix4x4 > vtkMatrix4x4Ptr
pcsRAS
Right-Anterior-Superior, used by Slicer3D, ITK-Snap, nifti, MINC.
Transform3D createTransformRotateY(const double angle)
bool similar(const Transform3D &a, const Transform3D &b, double tol)
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)
Transform3D createTransformRotationBetweenVectors(Vector3D from, Vector3D to)
cxResource_EXPORT Transform3D createTransformLPS2RAS()
std::string matrixAsSingleLineString(cx::Transform3D transform)
Vector3D bottomLeft() const
vtkSmartPointer< class vtkTransform > vtkTransformPtr
Transform3D createTransformNormalize(const DoubleBoundingBox3D &in, const DoubleBoundingBox3D &out)
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)
double dot(const Vector3D &a, const Vector3D &b)
compute inner product (or dot product) of a and b.
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)
float4 transform(float16 matrix, float4 voxel)
Namespace for all CustusX production code.