The below is the code in C++
typename ImageType::DirectionType imageDirection=inputImage->GetDirection();
//… mesh generated using itk::BinaryMask3DMeshSource
typename MeshType::Pointer mesh = meshSource->GetOutput();
typename PointsContainer::Pointer points = mesh->GetPoints();
PointsContainer::Iterator PointIterator = points->Begin();while(PointIterator !=points->End() )
{
PointType p=(PointIterator).Value();
PointType p2;
p2.Fill(0.0);for(unsigned int iPointDim=0; iPointDim< Dimension; iPointDim++) { for(unsigned int iDim=0; iDim<Dimension; iDim++) { p2[iPointDim] += imageDirection[iPointDim][iDim]*p[iDim]; } }
}
I tried to do the same thing in Python
- I read the (.hdr) image from file, getDirection() of this image.
- I generated a mesh using itk.BinaryMask3DMeshSource
- The while loop (from C++), I wrote as below:
for i in range(points.Size()):
p = points.ElementAt(i)
PixelType = itk.F
p2 = itk.Point[PixelType, Dimension]()
p2.Fill(0.0)
for iPointDim in range(0, Dimension):
for iDim in range(0, Dimension):
p2[iPointDim] += imageDirection_itk[iPointDim][iDim]*p[iDim];
==> But I received an error (TypeError: ‘itkMatrixD33’ object does not support indexing) at line “p2[iPointDim] += imageDirection_itk[iPointDim][iDim]*p[iDim];”