[ITK] [ITK-users] Do any of the mesh file formats store CellData?

Arnaud Gelas arnaudgelas at gmail.com
Fri Aug 14 02:54:20 EDT 2015


Hi Davis,

First of all, you do not need to call ReadPointData, especially if you want
to read cell data... Anyway, even if you make the change, it is not
required...

Then, if you look carefully at your code, it is normal that it segfault:

  float value2;
  auto mesh2 = reader->GetOutput();
  mesh2->SetCellData(0, value2);
  mesh2->GetCellData()->ElementAt(0);
  std::cout << value2 << std::endl; // Segfault or uninitialized

Right after reading the file, you set the data of the cell 0 to an
uninitialized value, then you get that value back but you do not store in
any variable. Finally, you print the uninitialzed value...

Best,
Arnaud


On Thu, Aug 13, 2015 at 7:55 PM, DVigneault <davis.vigneault at gmail.com>
wrote:

> All--
>
> Do any of the mesh file formats supported by ITK store CellData
> information?
> I've done a test where I've (a) created a mesh, (b) associated a value with
> each cell, (c) written it to file, (d) read it back in, and (e) attempted
> to
> read the associated value.  I did this for each file format.  When I ask
> for
> the cell's data, .vtk and .gii formats return uninitialized data, whereas
> .obj, .byu, .fcv, .fsa, .fsb, and .off segfault.
>
> I looked through itk::MeshFileWriter to see whether there were an option
> (such as WriteCellDataOn()), and there is a method WriteCellData() [1], but
> it is protected.  Looking at the header files of some of the individual
> writer objects (itkVTKPolyDataMeshIO, itkOBJMeshIO, etc), it looks like the
> WriteCellData(void *buffer) method is abstract.
>
> [1]
>
> http://www.itk.org/Doxygen/html/classitk_1_1MeshFileWriter.html#a1819df60ed20493f64a84c1728ddf26b
>
> I've pasted below the test program, in case the problem is due to a mistake
> I've made there.
>
> Best, and thanks!
>
> --Davis
>
> #include "itkMesh.h"
> #include "itkMeshFileReader.h"
> #include "itkMeshFileWriter.h"
> #include "itkRegularSphereMeshSource.h"
>
> const unsigned int Dimension = 3;
> typedef float      TCoordinate;
>
> typedef itk::Mesh< TCoordinate, Dimension >   TMesh;
> typedef itk::RegularSphereMeshSource< TMesh > TSphere;
> typedef itk::MeshFileReader< TMesh >          TMeshReader;
> typedef itk::MeshFileWriter< TMesh >          TMeshWriter;
>
> int main( int argc, char* argv[] )
> {
>
>   auto sphere = TSphere::New();
>   sphere->Update();
>
>   auto mesh = sphere->GetOutput();
>   double value = 10;
>   for (unsigned int i = 0; i < mesh->GetNumberOfCells(); ++i)
>     mesh->SetCellData( i, value);
>   std::cout << mesh->GetCellData()->ElementAt(0) << std::endl; // 10
>
>   auto meshWriter = TMeshWriter::New();
>   meshWriter->SetFileName( argv[1] );
>   meshWriter->SetInput( mesh );
>   meshWriter->Update();
>
>   auto reader = TMeshReader::New();
>   reader->SetFileName( argv[1] );
>   reader->ReadPointData();
>   reader->Update();
>
>   float value2;
>   auto mesh2 = reader->GetOutput();
>   mesh2->SetCellData(0, value2);
>   mesh2->GetCellData()->ElementAt(0);
>   std::cout << value2 << std::endl; // Segfault or uninitialized
>
>   return EXIT_SUCCESS;
>
> }
>
>
>
>
> --
> View this message in context:
> http://itk-insight-users.2283740.n2.nabble.com/Do-any-of-the-mesh-file-formats-store-CellData-tp7587666.html
> Sent from the ITK Insight Users mailing list archive at Nabble.com.
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/insight-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20150814/a08096b5/attachment.html>
-------------- next part --------------
_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users


More information about the Community mailing list