Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 2D mesh support #8

Open
2 tasks
thewtex opened this issue Mar 12, 2021 · 10 comments
Open
2 tasks

Add 2D mesh support #8

thewtex opened this issue Mar 12, 2021 · 10 comments
Assignees

Comments

@thewtex
Copy link
Contributor

thewtex commented Mar 12, 2021

We have to replace this block:

https://github.com/slicersalt/ITKMesh3DProcrustesAlignFilter/blob/783c04a51abea78e47e071cc66ed29cfdaa8a8a0/include/itkMesh3DProcrustesAlignFilter.h#L129-L151

maybe others?

  • Add a test with a 2D mesh.
  • Add wrapping for 2D mesh.
@tbirdso
Copy link
Contributor

tbirdso commented Mar 19, 2021

Looking through ITK it is unclear to what extent 2D meshes are supported, particularly in the Python wrapping.

itk.meshwrite is able to write out 2D meshes in .vtk format but itk.meshread always attempts to read meshes back in with 3D dimension. This can be traced back to itk::itkVTKPolyDataMeshIO which is fixed at reading in 3 dimensions:

this->m_PointDimension = 3; // vtk only support 3 dimensional points

Note that this isn't strictly correct -- .vtk legacy format documentation indicates The file format supports 1D, 2D, and 3D versions of most structures. We can also read 2D meshes back by templating a MeshFileReader object although this violates our goal of relying on Pythonic functional interfaces:

> reader = itk.MeshFileReader[type(filter.GetMean())].New()
> type(reader)
<class 'itk.itkMeshFileReaderPython.itkMeshFileReaderMD2'>
> reader.SetFileName('deleteme.vtk')
> reader.Update()
> reader.GetOutput()
<itk.itkMeshBasePython.itkMeshD2; proxy of <Swig Object of type 'itkMeshD2 *' at 0x00000278D247D990> >

However it doesn't appear that any unit tests are included for 2D mesh input and manipulation in ITK. itkMeshFileReadWriteTest, for instance, is fixed at dimension=3.

@thewtex Is this worth pursuing further as an ITK issue for supporting .vtk 1D/2D meshes? Is there a use case for 2D mesh analysis?

@tbirdso
Copy link
Contributor

tbirdso commented Mar 19, 2021

Side note that VTK is reverting to default to legacy 4.2 .vtk format rather than 5.1: https://discourse.vtk.org/t/legacy-polydata-file-compatibility/5354/4

@jcfr
Copy link

jcfr commented Mar 19, 2021

Is this worth pursuing further as an ITK issue for supporting .vtk 1D/2D meshes? Is there a use case for 2D mesh analysis?

Cc: @bpaniagua @lassoan

@thewtex
Copy link
Contributor Author

thewtex commented Mar 19, 2021

The only mesh file format that I recall currently works with 2D meshes in practice is .off.

.vtk 2D meshes would be nice to add, but I only think it is worthwhile if there is support in VTK.

@thewtex
Copy link
Contributor Author

thewtex commented Mar 19, 2021

Is there a use case for 2D mesh analysis?

2D meshes often make the most sense when working with 2D images.

@N-Dekker
Copy link

N-Dekker commented Aug 4, 2022

FYI I just encountered this issue in a different context as well. For an elastix/transformix unit test, I was trying to read a list of 2D points from the following vtk file, using the ITK Python Package:

# vtk DataFile Version 2.0
File written by itkPolyDataMeshIO
ASCII
DATASET POLYDATA
POINTS 4 double
0 0
1 0
0 1
0 0

Only then it appeared to me that itk.meshread did not do it correctly. Fortunately, I could still use itk.MeshFileReader[itk.Mesh[itk.D, 2]]. See https://github.com/SuperElastix/elastix/blob/832b18ecb3489c2082b6267f22bd53e93fa3132a/Testing/PythonTests/transformix_test.py#L475-L481

I also noticed that the corresponding C++ function in ITK does support 2D points, as long as the mesh type specified as template argument is also 2D:

auto mesh = itk::ReadMesh<itk::Mesh<double, 2>>("2d_points.vtk");

So I agree that it would be useful if itk.meshread would also support vtk files of 2D points. Possibly by an extra parameter, dimension, in order to support a call like itk.meshread(filename="2d_points.vtk", dimension=2)

Note that itk.meshwrite does support writing 2D points to a vtk file. 😃 As was already mentioned at #8 (comment) by Tom (@tbirdso).

My two cents!

N-Dekker added a commit to N-Dekker/ITK that referenced this issue Aug 15, 2022
`itk::MeshFileWriter` does allow writing non-3D points to a .vtk file, so it
appears both reasonable and useful for `itk::MeshFileReader` to allow reading
those points back.

Related to issue slicersalt/ITKShape#8 "Add 2D mesh support" by Matt McCormick.
N-Dekker added a commit to N-Dekker/ITK that referenced this issue Aug 15, 2022
`itk::MeshFileWriter` does allow writing non-3D points to a .vtk file, so it
appears both reasonable and useful for `itk::MeshFileReader` to allow reading
those points back.

Related to issue slicersalt/ITKShape#8 "Add 2D mesh support" by Matt McCormick.
N-Dekker added a commit to N-Dekker/ITK that referenced this issue Aug 15, 2022
`itk::MeshFileWriter` does allow writing non-3D points to a .vtk file, so it
appears both reasonable and useful for `itk::MeshFileReader` to allow reading
those points back.

Implemented by setting the PointDimension within MeshFileReader::GenerateData(),
and tested by GTest `VTKPolyDataMeshIO.SupportsAnyPointDimension`.

Related to issue slicersalt/ITKShape#8 "Add 2D mesh support"
by Matt McCormick.
N-Dekker added a commit to N-Dekker/ITK that referenced this issue Aug 15, 2022
`itk::MeshFileWriter` does allow writing non-3D points to a .vtk file, so it
appears both reasonable and useful for `itk::MeshFileReader` to allow reading
those points back.

Implemented by setting the PointDimension within MeshFileReader::GenerateData(),
and tested by GTest VTKPolyDataMeshIO.SupportsAnyPointDimensionGreaterThanZero.

Related to issue slicersalt/ITKShape#8 "Add 2D mesh support"
by Matt McCormick.
N-Dekker added a commit to N-Dekker/ITK that referenced this issue Aug 16, 2022
`itk::MeshFileWriter` does allow writing non-3D points to a .vtk file, so it
appears both reasonable and useful for `itk::MeshFileReader` to allow reading
those points back.

Implemented by setting the PointDimension within MeshFileReader::GenerateData(),
and tested by GTest VTKPolyDataMeshIO.SupportsPointDimensionsGreaterThanOne.

Related to issue slicersalt/ITKShape#8 "Add 2D mesh support"
by Matt McCormick.
@thewtex
Copy link
Contributor Author

thewtex commented Aug 16, 2022

# vtk DataFile Version 2.0
File written by itkPolyDataMeshIO
ASCII
DATASET POLYDATA
POINTS 4 double
0 0
1 0
0 1
0 0

This is not going to be a valid .vtk file, i.e. most other applications that support the .vtk file format will not be able to read it. POINTS is assumed to have 3 components. A 0 for the third component for 2D data is a reasonable approach.

So I agree that it would be useful if itk.meshread would also support vtk files of 2D points. Possibly by an extra parameter, dimension, in order to support a call like itk.meshread(filename="2d_points.vtk", dimension=2)

👍

@N-Dekker
Copy link

It seems to me that ITK has been able to both read and write 2D .vtk files for more than 10 years already. It "just" worked, "out of the box", using itk::MeshFileReader and itk::MeshFileWriter.

@thewtex
Copy link
Contributor Author

thewtex commented Aug 16, 2022

It is nice that .vtk files has worked for writing / reading from ITK. To get the most value out of a standard format, we will want to follow the standard so other tools and libraries following the standard can use the files.

@thewtex
Copy link
Contributor Author

thewtex commented Aug 16, 2022

From the standard:

The point coordinates are defined by the data in the POINTS section. This consists of x-y-z data values for each point.

dzenanz pushed a commit to InsightSoftwareConsortium/ITK that referenced this issue Aug 17, 2022
`itk::MeshFileWriter` does allow writing non-3D points to a .vtk file, so it
appears both reasonable and useful for `itk::MeshFileReader` to allow reading
those points back.

Implemented by setting the PointDimension within MeshFileReader::GenerateData(),
and tested by GTest VTKPolyDataMeshIO.SupportsPointDimensionsGreaterThanOne.

Related to issue slicersalt/ITKShape#8 "Add 2D mesh support"
by Matt McCormick.
hjmjohnson pushed a commit to hjmjohnson/ITK that referenced this issue Aug 26, 2022
`itk::MeshFileWriter` does allow writing non-3D points to a .vtk file, so it
appears both reasonable and useful for `itk::MeshFileReader` to allow reading
those points back.

Implemented by setting the PointDimension within MeshFileReader::GenerateData(),
and tested by GTest VTKPolyDataMeshIO.SupportsPointDimensionsGreaterThanOne.

Related to issue slicersalt/ITKShape#8 "Add 2D mesh support"
by Matt McCormick.
hjmjohnson pushed a commit to hjmjohnson/ITK that referenced this issue Aug 26, 2022
`itk::MeshFileWriter` does allow writing non-3D points to a .vtk file, so it
appears both reasonable and useful for `itk::MeshFileReader` to allow reading
those points back.

Implemented by setting the PointDimension within MeshFileReader::GenerateData(),
and tested by GTest VTKPolyDataMeshIO.SupportsPointDimensionsGreaterThanOne.

Related to issue slicersalt/ITKShape#8 "Add 2D mesh support"
by Matt McCormick.
hjmjohnson pushed a commit to hjmjohnson/ITK that referenced this issue Aug 26, 2022
`itk::MeshFileWriter` does allow writing non-3D points to a .vtk file, so it
appears both reasonable and useful for `itk::MeshFileReader` to allow reading
those points back.

Implemented by setting the PointDimension within MeshFileReader::GenerateData(),
and tested by GTest VTKPolyDataMeshIO.SupportsPointDimensionsGreaterThanOne.

Related to issue slicersalt/ITKShape#8 "Add 2D mesh support"
by Matt McCormick.
hjmjohnson pushed a commit to hjmjohnson/ITK that referenced this issue Aug 26, 2022
`itk::MeshFileWriter` does allow writing non-3D points to a .vtk file, so it
appears both reasonable and useful for `itk::MeshFileReader` to allow reading
those points back.

Implemented by setting the PointDimension within MeshFileReader::GenerateData(),
and tested by GTest VTKPolyDataMeshIO.SupportsPointDimensionsGreaterThanOne.

Related to issue slicersalt/ITKShape#8 "Add 2D mesh support"
by Matt McCormick.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants