[Insight-users] About TransformPoint

Steven ITK itklearner at gmail.com
Mon Sep 3 21:44:07 EDT 2007


Hi Luis,

Thank you very much. Yes, I declared PointSet as float, Transform as double.
But, after I changed the PointSet to double, the compile error is still
there. I am using Visual Studio 2005. The compiler gave this:
Error 1 error C2664:
'itk::MatrixOffsetTransformBase<TScalarType,NInputDimensions,NOutputDimensions>::TransformPoint'
: cannot convert parameter 1 from 'PointType' to 'const
itk::Point<TCoordRep,NPointDimension> &' c:\steven\gdc.cpp 1379
I am not sure whether this is the full error message though.

==========================================
The code is like this:
IterativeClosestPoint(CString tFixedPointsFile, CString tMovingPointFile,
CString tRegisteredPointsFile, double tResultParametre[ ])
{
//convert filename parametres to char*
CStringA fixedFileName(tFixedPointsFile);
CStringA movingFileName(tMovingPointFile);
CStringA registeredFileName(tRegisteredPointsFile);

int i = 0; int j = 0;
double pi = 3.1415926535897932384626;

typedef itk::PointSet< double, Dimension >   PointSetType;
PointSetType::Pointer fixedPointSet  = PointSetType::New();
PointSetType::Pointer movingPointSet = PointSetType::New();
PointSetType::Pointer registeredPointSet = PointSetType::New();
typedef PointSetType::PointType     PointType;
PointType fixedPoint;
PointType movingPoint;
PointType registeredPoint;
typedef PointSetType::PointsContainer  PointsContainer;
PointsContainer::Pointer fixedPointContainer  = PointsContainer::New();
PointsContainer::Pointer movingPointContainer = PointsContainer::New();
PointsContainer::Pointer registeredPointContainer = PointsContainer::New();

// Read the file containing coordinates of fixed points.
std::ifstream   fixedFile;
fixedFile.open( fixedFileName );
if( fixedFile.fail() )
{
  return -1;
}

unsigned int pointId = 0;
fixedFile >> fixedPoint;
while( !fixedFile.eof() )
{
  pointId++;
}
fixedPointSet->SetPoints( fixedPointContainer );

// Read the file containing coordinates of moving points.
std::ifstream   movingFile;
movingFile.open( movingFileName );
if( movingFile.fail() )
{
  return -1;
}

pointId = 0;
movingFile >> movingPoint;
while( !movingFile.eof() )
{
  movingPointContainer->InsertElement( pointId, movingPoint );
  movingFile >> movingPoint;
  pointId++;
}
movingPointSet->SetPoints( movingPointContainer );

// Set up  the Metric
typedef itk::EuclideanDistancePointMetric<  PointSetType,
PointSetType>  MetricType;
typedef MetricType::TransformType                 TransformBaseType;
typedef TransformBaseType::ParametersType         ParametersType;
typedef TransformBaseType::JacobianType           JacobianType;

MetricType::Pointer  metric = MetricType::New();

// Set up a Transform
typedef itk::Euler3DTransform< double >      TransformType;
TransformType::Pointer transform = TransformType::New();

// Optimizer Type
typedef itk::LevenbergMarquardtOptimizer OptimizerType;
OptimizerType::Pointer      optimizer     = OptimizerType::New();
optimizer->SetUseCostFunctionGradient(false);

// Registration Method
typedef itk::PointSetToPointSetRegistrationMethod<  PointSetType,
PointSetType > RegistrationType;

RegistrationType::Pointer   registration  = RegistrationType::New();
// Scale the translation components of the Transform in the Optimizer
OptimizerType::ScalesType scales( transform->GetNumberOfParameters() );

const double translationScale = 1000.0;   // 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;

unsigned long   numberOfIterations =  2000;
double          gradientTolerance  =  1e-4;   // convergence criterion
double          valueTolerance     =  1e-4;   // convergence criterion
double          epsilonFunction    =  1e-5;   // convergence criterion

optimizer->SetScales( scales );
optimizer->SetNumberOfIterations( numberOfIterations );
optimizer->SetValueTolerance( valueTolerance );
optimizer->SetGradientTolerance( gradientTolerance );
optimizer->SetEpsilonFunction( epsilonFunction );

// Start from an Identity transform (in a normal case, the user
// can probably provide a better guess than the identity...
transform->SetIdentity();

registration->SetInitialTransformParameters( transform->GetParameters() );

// Connect all the components required for Registration
registration->SetMetric(        metric        );
registration->SetOptimizer(     optimizer     );
registration->SetTransform(     transform     );
registration->SetFixedPointSet( fixedPointSet );
registration->SetMovingPointSet(   movingPointSet   );

try
{
  registration->StartRegistration();
}
catch( itk::ExceptionObject & e )
{
  DisplayITKError(e);
  return -1;
}
for(i=0; i<6; i++) //first 3" rotation around x, y, z; last 3: translation
{
  tResultParametre[i] = transform->GetParameters()[i];
}

//Transform the moving pointset into registered pointset and Write the
registered points into registeredFileName
//========================
//Method 1: Use TransformMeshFilter<PointSetType, PointSetType,
TransformType>
//========================
//typedef itk::TransformMeshFilter<PointSetType, PointSetType,
TransformType> TransformFilterType;
//TransformFilterType::Pointer transformfilter= TransformFilterType::New();
//transformfilter->SetInput(movingPointSet);
//transformfilter->SetTransform(transform);
//try
//{
// transformfilter->Update();
//}
//catch( itk::ExceptionObject & e )
//{
// DisplayITKError(e);
// return -1;
//}
//registeredPointSet = transformfilter->GetOutput();

//===========================
//Method 2: Use TransformPoint for each individual point
//===========================
for(i = 0; i<movingPointSet->GetNumberOfPoints(); i++)
{
  movingPointSet->GetPoint( i, &movingPoint );
  registeredPoint =   transform->TransformPoint( movingPoint );
  registeredPointContainer->InsertElement( i, registeredPoint );
}
registeredPointSet->SetPoints(registeredPointContainer);

//Write the registered pointset into file
std::ofstream   registeredFile;
registeredFile.open( registeredFileName);
if( registeredFile.fail() )
{
  return -1;
}
for(i = 0; i<registeredPointSet->GetNumberOfPoints(); i++)
{
  registeredPointSet->GetPoint( i, & registeredPoint );
  for(j = 0; j<Dimension; j++)
  {
   registeredFile<<registeredPoint[j]<<"\t";
  }
  registeredFile<<endl;
}

return 1;
}
===========================================
The error message given at the beginning of this post is for codes with
Method 2 (Use TransformPoint() for each individual point).
When compiling the codes with Method 1 (Use
TransformMeshFilter<PointSetType, PointSetType, TransformType>), the error
message is:
Error 1 error C2664:
'itk::MatrixOffsetTransformBase<TScalarType,NInputDimensions,NOutputDimensions>::TransformPoint'
: cannot convert parameter 1 from 'const
itk::Point<TCoordRep,NPointDimension>' to 'const
itk::Point<TCoordRep,NPointDimension>
&' c:\steven\installation\itk\insighttoolkit-
3.2.0\code\basicfilters\itktransformmeshfilter.txx 95
The codes around the break point in the file "
insighttoolkit-3.2.0\code\basicfilters\itktransformmeshfilter.txx" are:

  typename InputPointsContainer::ConstIterator  inputPoint  =
inPoints->Begin();
  typename OutputPointsContainer::Iterator      outputPoint =
outPoints->Begin();

  while( inputPoint != inPoints->End() )
    {
    outputPoint.Value() =       m_Transform->TransformPoint(
inputPoint.Value() );  //HERE IS THE ERROR
    ++inputPoint;
    ++outputPoint;
    }
Could you please help me on this? Thank you again.

Regards,
Steven


On 9/3/07, Luis Ibanez <luis.ibanez at kitware.com> wrote:
>
> Hi Steven,
>
> 1) You didn't posted the full error message to the list.
>
>    Apparently you cut the part where the compiler tell us what
>    [TScalarType] you used when instantiating the Transform.
>
> 2) Most likely you are using a transform instantiated for "double",
>    and trying to use it for transforming points whose components
>    are "float".
>
>
> If that is the case you have two options:
>
>
> A) Declare the PointSet using "double" at a cost in memory
>    storage. this may be fine if you are not managing thousands
>    or millions of points.
>
> B) Declare the Transform to use "float" as its ScalarType.
>
>
> Option (A) is better if you care about the precision of the
> computations more than the memory allocation.
>
>
>    Regards,
>
>
>        Luis
>
>
> ---------------------
> Steven ITK wrote:
> > Hi, ITK Users,
> >
> > I have a compiling error when using TransformPoint:
> >
> > Error 1 error C2664:
> >
'itk::MatrixOffsetTransformBase<TScalarType,NInputDimensions,NOutputDimensions>::TransformPoint'
> > : *cannot convert* parameter 1 from *'PointType' to 'const
> > itk::Point<TCoordRep,NPointDimension> &' . *
> >
> > What I am trying to do is testing the example of Iterative Closest Point
> > Registration method (PointSetToPointSetRegistrationMethod). The
> > registration is working, but I had the problem to transform the moving
> > pointset to registered pointset using the transformation matrix obtained
> > from the reigstration.
> >
> > Here is my code:
> > //type define
> >  typedef itk::PointSet< float, Dimension >   PointSetType;
> >  PointSetType::Pointer fixedPointSet  = PointSetType::New();
> >  PointSetType::Pointer movingPointSet = PointSetType::New();
> >  PointSetType::Pointer registeredPointSet = PointSetType::New();
> >  typedef PointSetType::PointType     PointType;
> >  PointType fixedPoint;
> >  PointType movingPoint;
> >  PointType registeredPoint;
> >  typedef PointSetType::PointsContainer  PointsContainer;
> >  PointsContainer::Pointer fixedPointContainer  = PointsContainer::New();
> >  PointsContainer::Pointer movingPointContainer = PointsContainer::New();
> >  PointsContainer::Pointer registeredPointContainer =
PointsContainer::New();
> >
> > //Read in moving pointset and fixed pointset
> >
> > //do the registration
> >
> > got the transformation stored in *'transform'*
> >
> > // transform moving pointset
> >
> >  for(i = 0; i<movingPointSet->GetNumberOfPoints(); i++)
> >  {
> >   movingPointSet->GetPoint( i, &movingPoint );
> >   *registeredPoint =   transform->TransformPoint( movingPoint
> > );//error here*
> >   registeredPointContainer->InsertElement( i, registeredPoint );
> >  }
> >  registeredPointSet->SetPoints(registeredPointContainer);
> >
> > ==============================================================
> > I also tried this, got the similar error:
> >  typedef itk::TransformMeshFilter<PointSetType, PointSetType,
> > TransformType> TransformFilterType;
> >  TransformFilterType::Pointer transformfilter=
TransformFilterType::New();
> >  transformfilter->SetInput(movingPointSet);
> >  transformfilter->SetTransform(transform);
> >  try
> >  {
> >   transformfilter->Update();
> >  }
> >  catch( itk::ExceptionObject & e )
> >  {
> >   DisplayITKError(e);
> >   return -1;
> >  }
> >  registeredPointSet = transformfilter->GetOutput();
> >
> > ===============================================================
> >
> > Can you help me out of this? Thank you.
> >
> > Steven
> >
> >
> >
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Insight-users mailing list
> > Insight-users at itk.org
> > http://www.itk.org/mailman/listinfo/insight-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20070904/1e89584a/attachment-0001.html


More information about the Insight-users mailing list