30 #pragma warning ( disable : 4786 ) 42 #include "itkTranslationTransform.h" 43 #include "itkEuclideanDistancePointMetric.h" 44 #include "itkLevenbergMarquardtOptimizer.h" 45 #include "itkPointSet.h" 46 #include "itkPointSetToPointSetRegistrationMethod.h" 67 void Execute(itk::Object *caller,
const itk::EventObject & event)
69 Execute((
const itk::Object *) caller, event);
72 void Execute(
const itk::Object *
object,
const itk::EventObject & event)
74 OptimizerPointer optimizer =
dynamic_cast<OptimizerPointer
>(object);
76 if (!itk::IterationEvent().CheckEvent(&event))
81 std::cout <<
"iteration Value = " << optimizer->GetCachedValue() << std::endl;
82 std::cout <<
"iteration Position = " << optimizer->GetCachedCurrentPosition();
83 std::cout << std::endl << std::endl;
105 typedef itk::EuclideanDistancePointMetric<PointSetType, PointSetType>
MetricType;
121 typedef itk::PointSetToPointSetRegistrationMethod<PointSetType, PointSetType>
RegistrationType;
126 bool registerPoints(std::vector<cx::Vector3D> ref, std::vector<cx::Vector3D> target);
127 bool registerPoints(PointSetType::Pointer fixedPointSet, PointSetType::Pointer movingPointSet);
128 PointSetType::Pointer toItk(std::vector<cx::Vector3D> input);
135 PointSetType::Pointer pointSet = PointSetType::New();
136 PointsContainer::Pointer pointContainer = PointsContainer::New();
139 for (
unsigned i = 0; i < input.size(); ++i)
141 point[0] = input[i][0];
142 point[1] = input[i][1];
143 point[2] = input[i][2];
144 pointContainer->InsertElement(i, point);
146 pointSet->SetPoints(pointContainer);
152 return registerPoints(toItk(ref), toItk(target));
161 MetricType::Pointer metric = MetricType::New();
167 TransformType::Pointer
transform = TransformType::New();
170 OptimizerType::Pointer optimizer = OptimizerType::New();
171 optimizer->SetUseCostFunctionGradient(
false);
174 RegistrationType::Pointer registration = RegistrationType::New();
177 OptimizerType::ScalesType scales(transform->GetNumberOfParameters());
178 std::cout <<
"transform->GetNumberOfParameters() " << transform->GetNumberOfParameters() << std::endl;
181 unsigned long numberOfIterations = 100;
182 double gradientTolerance = 1e-5;
183 double valueTolerance = 1e-5;
184 double epsilonFunction = 1e-6;
186 optimizer->SetScales(scales);
187 optimizer->SetNumberOfIterations(numberOfIterations);
188 optimizer->SetValueTolerance(valueTolerance);
189 optimizer->SetGradientTolerance(gradientTolerance);
190 optimizer->SetEpsilonFunction(epsilonFunction);
194 transform->SetIdentity();
196 registration->SetInitialTransformParameters(transform->GetParameters());
201 registration->SetMetric(metric);
202 registration->SetOptimizer(optimizer);
203 registration->SetTransform(transform);
204 registration->SetFixedPointSet(fixedPointSet);
205 registration->SetMovingPointSet(movingPointSet);
214 registration->Update();
215 }
catch (itk::ExceptionObject & e)
217 std::cout << e << std::endl;
221 mResult = cx::Transform3D::Identity();
222 for (
unsigned i = 0; i < transform->GetNumberOfParameters(); ++i)
223 mResult(i, 3) = transform->GetParameters()[i];
242 Transform3D LandmarkTranslationRegistration::registerPoints(std::vector<Vector3D> ref,
243 std::vector<Vector3D> target,
bool* ok)
245 if (ref.size() != target.size() || ref.empty())
247 std::cout <<
"Different sizes in ref and target: aborting registration." << std::endl;
249 return Transform3D::Identity();
261 Vector3D rr = (ref[0] + ref[1]) / 2.0;
262 Vector3D tt = (target[0] + target[1]) / 2.0;
itk::PointSet< float, Dimension > PointSetType
itk::SmartPointer< Self > Pointer
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
const OptimizerType * OptimizerPointer
const unsigned int Dimension
void Execute(itk::Object *caller, const itk::EventObject &event)
void Execute(const itk::Object *object, const itk::EventObject &event)
itk::TranslationTransform< double, Dimension > TransformType
PointSetType::PointType PointType
Transform3D createTransformTranslate(const Vector3D &translation)
MetricType::TransformType TransformBaseType
CommandIterationUpdate Self
PointSetType::Pointer toItk(std::vector< cx::Vector3D > input)
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
TransformBaseType::ParametersType ParametersType
itk::PointSetToPointSetRegistrationMethod< PointSetType, PointSetType > RegistrationType
itk::LevenbergMarquardtOptimizer OptimizerType
PointSetType::PointsContainer PointsContainer
TransformBaseType::JacobianType JacobianType
cx::Transform3D mResult
transform of movingPointSet
bool registerPoints(std::vector< cx::Vector3D > ref, std::vector< cx::Vector3D > target)
itk::EuclideanDistancePointMetric< PointSetType, PointSetType > MetricType
float4 transform(float16 matrix, float4 voxel)
itk::LevenbergMarquardtOptimizer OptimizerType
Namespace for all CustusX production code.