How to fix 'itkMatrixD33' object does not support indexing (itk.BinaryMask3DMeshSource)

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;

   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

  1. I read the (.hdr) image from file, getDirection() of this image.
  2. I generated a mesh using itk.BinaryMask3DMeshSource
  3. 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]()
        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];”

Try imageDirection_itk(iPointDim, iDim) and imageDirection_itk.GetElement(iPointDim, iDim). Take a look at this post and the rest of that thread.

1 Like

Thank you. It works.
The next thing in C++ is,

// End while PointIterator

I though that this line “(PointIterator).Value()=p2” used to set value for the current point in while loop.
And I try to do like this in Python by the following

points.ElementAt(i) = p2

And I received the error “SyntaxError: can’t assign to function call”

Have you tried points.SetElement(i, p2)?

@Pranjal_Sahu might be more up to date on syntax for this.

1 Like

Yes, It work. Thank you so much