ITK/Examples/Meshes/PointAndCellData: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Example illustrating)
 
(Deprecated content that is moved to sphinx)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
WARNING: This is a temporary example, intended to illustrate an issue [1] being discussed on the ITK mailing list.  The example will be revised or removed when the issue is resolved.
{{warning|1=The media wiki content on this page is no longer maintained.  The examples presented on the https://itk.org/Wiki/*  pages likely require ITK version 4.13 or earlier releasesIn many cases, the examples on this page no longer conform to the best practices for modern ITK versions.}}
 
[1] http://itk-insight-users.2283740.n2.nabble.com/Do-any-of-the-mesh-file-formats-store-CellData-td7587666.html
 
Contributed by: Davis Vigneault
 
==PointAndCellData.cxx==
 
<source lang="cpp">
 
#include "itkMesh.h"
#include "itkRegularSphereMeshSource.h"
#include "itkMeshFileWriter.h"
 
const unsigned int Dimension = 3;
typedef float      TCoordinate;
 
typedef itk::Mesh< TCoordinate, Dimension >   TMesh;
typedef itk::RegularSphereMeshSource< TMesh > TSphere;
typedef itk::MeshFileWriter< TMesh >          TMeshWriter;
 
int main()
{
 
  TSphere::Pointer sphere = TSphere::New();
  sphere->Update();
 
  TMesh::Pointer mesh = sphere->GetOutput();
  double value = 10;
  for (unsigned int i = 0; i < mesh->GetNumberOfCells(); ++i)
    mesh->SetCellData( i, value );
 
  for (unsigned int i = 0; i < mesh->GetNumberOfPoints(); ++i)
    mesh->SetPointData( i, value );
 
  std::cout << mesh->GetNumberOfCells() << std::endl; // 128
  std::cout << mesh->GetCellData() << std::endl; // A pointer
  std::cout << mesh->GetCellData()->Size() << std::endl << std::endl; // 128
 
  std::cout << mesh->GetNumberOfPoints() << std::endl; // 66
  std::cout << mesh->GetPointData() << std::endl; // Another pointer
  std::cout << mesh->GetPointData()->Size() << std::endl << std::endl; // 66
 
  TMeshWriter::Pointer meshWriter = TMeshWriter::New();
  meshWriter->SetFileName( "mesh.vtk" );
  meshWriter->SetInput( mesh );
  meshWriter->Update();
 
  std::cout << mesh->GetNumberOfCells() << std::endl; // 128
  std::cout << mesh->GetCellData() << std::endl; // Different Pointer
  std::cout << mesh->GetCellData()->Size() << std::endl << std::endl; // 0
 
  std::cout << mesh->GetNumberOfPoints() << std::endl; // 66
  std::cout << mesh->GetPointData() << std::endl; // Different pointer
  std::cout << mesh->GetPointData()->Size() << std::endl << std::endl; // 0
 
  return EXIT_SUCCESS;
 
}
 
</source>
 
{{ITKCMakeLists|{{SUBPAGENAME}}}}

Latest revision as of 17:16, 7 June 2019

Warning: The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/* pages likely require ITK version 4.13 or earlier releases. In many cases, the examples on this page no longer conform to the best practices for modern ITK versions.