Search code examples
pythonitk

How to create a mesh object in ITK using Python bindings?


I am trying to create a Mesh object in Python. I am using the python bindings which are being installed from the following web page. As far as the c++ code is concerned we can do it as follows

      MeshType::Pointer mesh = MeshType::New();

I am very new to use even ITK. Have no idea how to create it. In the constructor of Mesh in the c++ documentation, it says one necessary argument which is the TPixelType. Unable to locate that as well.

Could anybody help me please with this.

Thanks


Solution

  • If I were you I would take a look at the Python bindings that come with ITK 4.0. You can get access to them by turning on the option WRAP_ITK_PYTHON in cmake.

    Once, you compile ITK with the python bindings turned on you can create 2 mesh types out of the box:

    import itk
    meshType2D = itk.Mesh.D2Q.New()
    meshType3D = itk.Mesh.D3Q.New()
    

    alternatively you can explicitly instantiate your classes as follows:

    import itk
    meshType2D = itk.Mesh[itk.D, 2, itk.QuadEdgeMeshTraits.D2BBFF]
    meshType3D = itk.Mesh[itk.D, 3, itk.QuadEdgeMeshTraits.D3BBFF]
    

    This will give you 2 and 3 dimensional meshes of double type pixel values with default mesh traits. As far as pixel types in ITK go, these amount to the basic C++ variables types: double, float, unsigned int, etc. These basic types are wrapped in python and can be found in the ITK namespace: itk.D, itk.F, itk.UI, etc.