Comments (10)
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.
from itkshape.
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!
from itkshape.
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?
from itkshape.
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
from itkshape.
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
from itkshape.
Is there a use case for 2D mesh analysis?
2D meshes often make the most sense when working with 2D images.
from itkshape.
# 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)
👍
from itkshape.
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
.
from itkshape.
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.
from itkshape.
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.
from itkshape.
Related Issues (11)
- BUG: Filter not accepting mesh input for Python wrapping HOT 5
- Rename repository HOT 1
- Update CI for ITK 5.2.0
- Publish to PyPi HOT 1
- CMake errors linking ITK modules HOT 5
- Add to ITK as a Remote Module HOT 2
- ENH: Add updates from module template
- Wrapping not available HOT 1
- Wrapped Class Import Failure HOT 5
- Replace `M_PI` with ITK constants
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from itkshape.