本文整理汇总了C++中transformtype::Pointer::TransformPoint方法的典型用法代码示例。如果您正苦于以下问题:C++ Pointer::TransformPoint方法的具体用法?C++ Pointer::TransformPoint怎么用?C++ Pointer::TransformPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类transformtype::Pointer
的用法示例。
在下文中一共展示了Pointer::TransformPoint方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: scales
//.........这里部分代码省略.........
/* get centroid and extends of our pointsets */
//BoundingBoxType::Pointer sourceBoundingBox = BoundingBoxType::New();
//sourceBoundingBox->SetPoints(sourcePointSet->GetPoints());
//sourceBoundingBox->ComputeBoundingBox();
//BoundingBoxType::Pointer targetBoundingBox = BoundingBoxType::New();
//targetBoundingBox->SetPoints(targetPointSet->GetPoints());
//targetBoundingBox->ComputeBoundingBox();
TransformType::Pointer transform = TransformType::New();
transform->SetIdentity();
//transform->SetTranslation(targetBoundingBox->GetCenter() - sourceBoundingBox->GetCenter());
itk::LevenbergMarquardtOptimizer::Pointer optimizer = itk::LevenbergMarquardtOptimizer::New();
optimizer->SetUseCostFunctionGradient(false);
RegistrationType::Pointer registration = RegistrationType::New();
// Scale the translation components of the Transform in the Optimizer
itk::LevenbergMarquardtOptimizer::ScalesType scales(transform->GetNumberOfParameters());
const double translationScale = 5000; //sqrtf(targetBoundingBox->GetDiagonalLength2()) * 1000; // dynamic range of translations
const double rotationScale = 1.0; // dynamic range of rotations
scales[0] = 1.0 / rotationScale;
scales[1] = 1.0 / rotationScale;
scales[2] = 1.0 / rotationScale;
scales[3] = 1.0 / translationScale;
scales[4] = 1.0 / translationScale;
scales[5] = 1.0 / translationScale;
//scales.Fill(0.01);
unsigned long numberOfIterations = 80000;
double gradientTolerance = 1e-10; // convergence criterion
double valueTolerance = 1e-10; // convergence criterion
double epsilonFunction = 1e-10; // convergence criterion
optimizer->SetScales( scales );
optimizer->SetNumberOfIterations( numberOfIterations );
optimizer->SetValueTolerance( valueTolerance );
optimizer->SetGradientTolerance( gradientTolerance );
optimizer->SetEpsilonFunction( epsilonFunction );
registration->SetInitialTransformParameters( transform->GetParameters() );
//------------------------------------------------------
// Connect all the components required for Registration
//------------------------------------------------------
MetricType::Pointer metric = MetricType::New();
registration->SetMetric( metric );
registration->SetOptimizer( optimizer );
registration->SetTransform( transform );
registration->SetFixedPointSet( targetPointSet );
registration->SetMovingPointSet( sourcePointSet );
try
{
//registration->StartRegistration();
registration->Update();
}
catch( itk::ExceptionObject & e )
{
MITK_INFO << "Exception caught during ICP optimization: " << e;
return false;
//throw e;
}
MITK_INFO << "ICP successful: Solution = " << transform->GetParameters() << std::endl;
MITK_INFO << "Metric value: " << metric->GetValue(transform->GetParameters());
/* find point correspondences */
//mitk::PointLocator::Pointer pointLocator = mitk::PointLocator::New(); // <<- use mitk::PointLocator instead of searching manually?
//pointLocator->SetPoints()
for (LandmarkPointContainer::const_iterator sourcesIt = sources.begin(); sourcesIt != sources.end(); ++sourcesIt)
{
}
//MetricType::MeasureType closestDistances = metric->GetValue(transform->GetParameters());
//unsigned int index = 0;
LandmarkPointContainer sortedSources;
for (LandmarkPointContainer::const_iterator targetsIt = targets.begin(); targetsIt != targets.end(); ++targetsIt)
{
double minDistance = itk::NumericTraits<double>::max();
LandmarkPointContainer::iterator minDistanceIterator = sources.end();
for (LandmarkPointContainer::iterator sourcesIt = sources.begin(); sourcesIt != sources.end(); ++sourcesIt)
{
TransformInitializerType::LandmarkPointType transformedSource = transform->TransformPoint(*sourcesIt);
double dist = targetsIt->EuclideanDistanceTo(transformedSource);
MITK_INFO << "target: " << *targetsIt << ", source: " << *sourcesIt << ", transformed source: " << transformedSource << ", dist: " << dist;
if (dist < minDistance )
{
minDistanceIterator = sourcesIt;
minDistance = dist;
}
}
if (minDistanceIterator == sources.end())
return false;
MITK_INFO << "minimum distance point is: " << *minDistanceIterator << " (dist: " << targetsIt->EuclideanDistanceTo(transform->TransformPoint(*minDistanceIterator)) << ", minDist: " << minDistance << ")";
sortedSources.push_back(*minDistanceIterator); // this point is assigned
sources.erase(minDistanceIterator); // erase it from sources to avoid duplicate assigns
}
//for (LandmarkPointContainer::const_iterator sortedSourcesIt = sortedSources.begin(); targetsIt != sortedSources.end(); ++targetsIt)
sources = sortedSources;
return true;
}