21 #ifndef MIRTK_Transformation_H 22 #define MIRTK_Transformation_H 24 #include "mirtk/TransformationConfig.h" 26 #include "mirtk/Observable.h" 28 #include "mirtk/Status.h" 29 #include "mirtk/BSpline.h" 30 #include "mirtk/Cfstream.h" 31 #include "mirtk/Indent.h" 32 #include "mirtk/PointSet.h" 33 #include "mirtk/Matrix.h" 34 #include "mirtk/Vector3D.h" 35 #include "mirtk/GenericImage.h" 37 #include "mirtk/TransformationType.h" 38 #include "mirtk/TransformationJacobian.h" 109 return New(static_cast<TransformationType>(type));
144 virtual void Put(
int,
double);
147 virtual void Put(
const DOFValue *);
150 virtual void Add(
const DOFValue *);
153 virtual double Update(
const DOFValue *);
156 virtual double Get(
int)
const;
159 virtual void Get(DOFValue *)
const;
177 int &,
int &,
int &,
double = 1)
const;
180 virtual void Reset();
207 double EvaluateRMSError(
const double *,
const double *,
const double *,
double,
208 double *,
double *,
double *,
int no)
const;
211 double EvaluateRMSError(
const double *,
const double *,
const double *,
const double *,
212 double *,
double *,
double *,
int no)
const;
216 int = 1,
double = .0);
229 int = 1,
double = .0);
235 virtual double Approximate(
const double *,
const double *,
const double *,
236 double *,
double *,
double *,
int,
237 int = 1,
double = .0);
243 virtual double Approximate(
const double *,
const double *,
const double *,
const double *,
244 double *,
double *,
double *,
int,
245 int = 1,
double = .0);
249 int = 1,
double = .0);
262 int = 1,
double = .0);
268 virtual double ApproximateAsNew(
const double *,
const double *,
const double *,
269 double *,
double *,
double *,
int,
270 int = 1,
double = .0);
276 virtual double ApproximateAsNew(
const double *,
const double *,
const double *,
const double *,
277 double *,
double *,
double *,
int,
278 int = 1,
double = .0);
283 const double *,
const double *,
const double *,
284 double *,
double = 1.0)
const;
289 const double *,
const double *,
const double *,
int,
290 double *,
double = 1.0)
const;
294 virtual void ApproximateGradient(
const double *,
const double *,
const double *,
const double *,
295 const double *,
const double *,
const double *,
int,
296 double *,
double = 1.0)
const;
301 virtual void ApproximateDOFs(
const double *,
const double *,
const double *,
const double *,
302 const double *,
const double *,
const double *,
int);
309 const double *,
const double *,
const double *,
int,
310 double *,
double = 1.0)
const;
319 virtual bool Set(
const char *,
const char *);
335 virtual void GlobalTransform(
double &,
double &,
double &,
double = 0,
double = NaN)
const = 0;
338 virtual void LocalTransform(
double &,
double &,
double &,
double = 0,
double = NaN)
const = 0;
341 virtual void Transform(
double &,
double &,
double &,
double = 0,
double = NaN)
const = 0;
350 virtual void Transform(
int,
double *,
double *,
double *,
double = 0,
double = NaN)
const;
353 virtual void Transform(
int,
double *,
double *,
double *,
const double *,
double = NaN)
const;
359 virtual void GlobalDisplacement(
double &,
double &,
double &,
double = 0,
double = NaN)
const;
362 virtual void LocalDisplacement(
double &,
double &,
double &,
double = 0,
double = NaN)
const;
365 virtual void Displacement(
double &,
double &,
double &,
double = 0,
double = NaN)
const;
414 double t,
double t0 = NaN,
418 virtual void GlobalInverse(
double &,
double &,
double &,
double = 0,
double = NaN)
const;
421 virtual bool LocalInverse(
double &,
double &,
double &,
double = 0,
double = NaN)
const;
424 virtual bool Inverse(
double &,
double &,
double &,
double = 0,
double = NaN)
const;
427 virtual bool Inverse(
Point &,
double = 0,
double = NaN)
const;
441 virtual bool InverseDisplacement(
double &,
double &,
double &,
double = 0,
double = NaN)
const;
493 virtual void LocalJacobian(
Matrix &,
double,
double,
double,
double = 0,
double = NaN)
const;
496 virtual void Jacobian(
Matrix &,
double,
double,
double,
double = 0,
double = NaN)
const;
499 virtual double GlobalJacobian(
double,
double,
double,
double = 0,
double = NaN)
const;
502 virtual double LocalJacobian(
double,
double,
double,
double = 0,
double = NaN)
const;
505 virtual double Jacobian(
double,
double,
double,
double = 0,
double = NaN)
const;
508 virtual void GlobalHessian(
Matrix [3],
double,
double,
double,
double = 0,
double = NaN)
const;
511 virtual void LocalHessian(
Matrix [3],
double,
double,
double,
double = 0,
double = NaN)
const;
514 virtual void Hessian(
Matrix [3],
double,
double,
double,
double = 0,
double = NaN)
const;
517 virtual void JacobianDOFs(
double [3],
int,
double,
double,
double,
double = 0,
double = NaN)
const;
540 double = NaN,
double = 1)
const;
546 double = NaN,
double = 1)
const;
551 double = NaN,
double = 1)
const;
558 const double * = NULL,
double = 1)
const;
564 const double * = NULL,
double = 1)
const;
569 const double * = NULL,
double = 1)
const;
574 double *,
double = 0,
double = NaN,
double = 1)
const;
583 virtual void Print(ostream &os,
Indent = 0)
const = 0;
586 virtual void Read(
const char *);
589 virtual void Write(
const char *)
const;
633 #define mirtkAbstractTransformationMacro(name) \ 634 mirtkAbstractMacro(name) 637 #define mirtkTransformationMacro(name) \ 638 mirtkObjectMacro(name) 659 if (this->
GetStatus(dof) == Active) ++nactive;
673 double norm, max = .0;
675 norm = abs(gradient[dof]);
676 if (norm > max) max = norm;
684 if (_Param[idx] != static_cast<DOFValue>(x)) {
685 _Param[idx] =
static_cast<DOFValue
>(x);
693 return static_cast<double>(_Param[idx]);
700 if (_Param[idx] != x[idx]) {
701 _Param[idx] = x[idx];
712 _Param[idx] += dx[idx];
721 double delta, max_delta = .0;
723 _Param[idx] += dx[idx];
724 delta = abs(dx[idx]);
725 if (delta > max_delta) max_delta = delta;
727 if (max_delta > .0) this->Changed(
true);
734 memcpy(x, _Param, _NumberOfDOFs *
sizeof(DOFValue));
752 return (_Param == t->
_Param);
773 if (this->
Get(i) != .0)
return false;
781 int &i2,
int &j2,
int &k2,
double fraction)
const 784 i2 = image->
X() - 1, j2 = image->
Y() -1, k2 = image->
Z() - 1;
807 for (
int i = 0; i < pset.
Size(); i++) this->
Transform(pset(i), t, t0);
820 for (
int i = 0; i < pset.
Size(); ++i) {
821 if (!this->
Inverse(pset(i), t, t0)) ++n;
905 bool ok = this->
Inverse(x, y, z, t, t0);
921 cerr << this->
NameOfClass() <<
"::GlobalJacobian: Not implemented" << endl;
928 cerr << this->
NameOfClass() <<
"::LocalJacobian: Not implemented" << endl;
935 cerr << this->
NameOfClass() <<
"::Jacobian: Not implemented" << endl;
942 cerr << this->
NameOfClass() <<
"::DeriveJacobianWrtDOF: Not implemented" << endl;
966 this->
Jacobian(jac, x, y, z, t, t0);
973 cerr << this->
NameOfClass() <<
"::GlobalHessian: Not implemented" << endl;
980 cerr << this->
NameOfClass() <<
"::LocalHessian: Not implemented" << endl;
987 cerr << this->
NameOfClass() <<
"::Hessian: Not implemented" << endl;
994 cerr << this->
NameOfClass() <<
"::JacobianDOFs: Not implemented" << endl;
1017 const double *t0,
double w)
const 1019 for (
int i = 0; i < n; ++i) {
1046 this->
Print(cout, indent);
1070 #endif // MIRTK_Transformation_H
double Det3x3() const
Calculate determinant of a 3x3 matrix.
bool IsEmpty() const
Whether image is uninitialized.
double _x
x coordinate of Point
bool IsTransformation(const char *name)
Array< Pair< string, string > > ParameterList
Ordered list of parameter name/value pairs.
Status
Enumeration of common states for entities such as objective function parameters.
int Y() const
Returns the number of voxels in the y-direction.
int X() const
Returns the number of voxels in the x-direction.
virtual const char * NameOfClass() const =0
Get name of class, which this object is an instance of.
virtual ParameterList Parameter() const
Get parameter name/value pairs.
double _z
z coordinate of Point
double _y
y coordinate of Point
int Z() const
Returns the number of voxels in the z-direction.