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);
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.