51 #pragma warning ( disable : 4786 ) 63 #include "itkTranslationTransform.h" 64 #include "itkEuclideanDistancePointMetric.h" 65 #include "itkLevenbergMarquardtOptimizer.h" 66 #include "itkPointSet.h" 67 #include "itkPointSetToPointSetRegistrationMethod.h" 88 void Execute(itk::Object *caller,
const itk::EventObject & event)
90 Execute((
const itk::Object *) caller, event);
93 void Execute(
const itk::Object *
object,
const itk::EventObject & event)
95 OptimizerPointer optimizer =
dynamic_cast<OptimizerPointer
>(object);
97 if (!itk::IterationEvent().CheckEvent(&event))
102 std::cout <<
"iteration Value = " << optimizer->GetCachedValue() << std::endl;
103 std::cout <<
"iteration Position = " << optimizer->GetCachedCurrentPosition();
104 std::cout << std::endl << std::endl;
126 typedef itk::EuclideanDistancePointMetric<PointSetType, PointSetType>
MetricType;
142 typedef itk::PointSetToPointSetRegistrationMethod<PointSetType, PointSetType>
RegistrationType;
147 bool registerPoints(std::vector<cx::Vector3D> ref, std::vector<cx::Vector3D> target);
148 bool registerPoints(PointSetType::Pointer fixedPointSet, PointSetType::Pointer movingPointSet);
149 PointSetType::Pointer toItk(std::vector<cx::Vector3D> input);
156 PointSetType::Pointer pointSet = PointSetType::New();
157 PointsContainer::Pointer pointContainer = PointsContainer::New();
160 for (
unsigned i = 0; i < input.size(); ++i)
162 point[0] = input[i][0];
163 point[1] = input[i][1];
164 point[2] = input[i][2];
165 pointContainer->InsertElement(i, point);
167 pointSet->SetPoints(pointContainer);
173 return registerPoints(toItk(ref), toItk(target));
182 MetricType::Pointer metric = MetricType::New();
188 TransformType::Pointer
transform = TransformType::New();
191 OptimizerType::Pointer optimizer = OptimizerType::New();
192 optimizer->SetUseCostFunctionGradient(
false);
195 RegistrationType::Pointer registration = RegistrationType::New();
198 OptimizerType::ScalesType scales(transform->GetNumberOfParameters());
199 std::cout <<
"transform->GetNumberOfParameters() " << transform->GetNumberOfParameters() << std::endl;
202 unsigned long numberOfIterations = 100;
203 double gradientTolerance = 1e-5;
204 double valueTolerance = 1e-5;
205 double epsilonFunction = 1e-6;
207 optimizer->SetScales(scales);
208 optimizer->SetNumberOfIterations(numberOfIterations);
209 optimizer->SetValueTolerance(valueTolerance);
210 optimizer->SetGradientTolerance(gradientTolerance);
211 optimizer->SetEpsilonFunction(epsilonFunction);
215 transform->SetIdentity();
217 registration->SetInitialTransformParameters(transform->GetParameters());
222 registration->SetMetric(metric);
223 registration->SetOptimizer(optimizer);
224 registration->SetTransform(transform);
225 registration->SetFixedPointSet(fixedPointSet);
226 registration->SetMovingPointSet(movingPointSet);
235 registration->Update();
236 }
catch (itk::ExceptionObject & e)
238 std::cout << e << std::endl;
242 mResult = cx::Transform3D::Identity();
243 for (
unsigned i = 0; i < transform->GetNumberOfParameters(); ++i)
244 mResult(i, 3) = transform->GetParameters()[i];
263 Transform3D LandmarkTranslationRegistration::registerPoints(std::vector<Vector3D> ref,
264 std::vector<Vector3D> target,
bool* ok)
266 if (ref.size() != target.size() || ref.empty())
268 std::cout <<
"Different sizes in ref and target: aborting registration." << std::endl;
270 return Transform3D::Identity();
282 Vector3D rr = (ref[0] + ref[1]) / 2.0;
283 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.