[Insight-users] How can I view a metamesh.txt mesh file that I created with an itk::SpatialObjectWriter
John Drozd
john.drozd at gmail.com
Thu Jul 22 17:49:23 EDT 2010
Hello,
I figured it out. I wrote the mesh to a .vtk file using VTK coding and
viewed the mesh in Paraview.
The following links helped me considerably in achieving this:
http://www.itk.org/pipermail/insight-users/2002-September/001154.html
http://www.na-mic.org/svn/Slicer3-lib-mirrors/trunk/Insight/Testing/Code/Common/itkMeshSourceGraftOutputTest.cxx
thanks,
John
On Mon, Jun 28, 2010 at 8:15 PM, John Drozd <john.drozd at gmail.com> wrote:
> Hello,
>
> How can I view a metamesh.txt mesh file that I created with an
> itk::SpatialObjectWriter.
>
> I modified itk's example DeformableModel1.cxx to create the "metamesh.txt"
> file using a binary image that I segmented using the FuzzyConnectedness
> segmentation example in itk.
>
> I suspect I can use paraview to view a metamesh.txt file but I don't know
> the steps.
>
> Can anyone help?
>
> To illustrate my case, below are snippets of the contents of my
> metamesh.txt file:
>
> ObjectType = Scene
> NDims = 3
> NObjects = 1
> ObjectType = Mesh
> NDims = 3
> BinaryData = False
> TransformMatrix = 1 0 0 0 1 0 0 0 1
> Offset = 0 0 0
> CenterOfRotation = 0 0 0
> ElementSpacing = 1 1 1
> PointType = MET_FLOAT
> PointDataType = MET_SHORT
> CellDataType = MET_SHORT
> NCellTypes = 1
> PointDim = ID x y ...
> NPoints = 22863
> Points =
> 0 321.712 160.777 68.8275
> 1 322.185 160.305 68.8275
> 2 322.185 160.777 68.2237
> 3 322.658 160.777 68.8275
> 4 321.712 161.723 68.8275
> 5 322.185 161.723 68.2237
> 6 322.658 161.723 68.8275
> 7 321.712 162.669 68.8275
> 8 322.185 162.669 68.2237
>
> .............................
>
> 22855 319.821 164.088 132.221
> 22856 320.294 164.561 132.221
> 22857 319.348 165.506 132.221
> 22858 319.821 165.033 132.221
> 22859 320.294 165.506 132.221
> 22860 320.294 166.452 132.221
> 22861 319.821 165.979 132.221
> 22862 320.294 167.398 132.221
> CellType = TRI
> NCells = 45574
> Cells =
> 0 0 2 1
> 1 3 1 2
> 2 4 5 0
> 3 2 0 5
> 4 6 3 5
> 5 2 5 3
> 6 7 8 4
> 7 5 4 8
> 8 9 6 8
> 9 5 8 6
> 10 10 11 7
> 11 8 7 11
> 12 12 9 11
>
> .........................................
>
> 45567 22859 22793 22860
> 45568 22801 22797 22862
> 45569 22860 22862 22797
> 45570 22804 22862 22799
> 45571 22860 22799 22862
> 45572 22801 22862 22806
> 45573 22804 22806 22862
> NCellData = 45574
> CellDataSize = 273444
> CellData =
>
> (binary data)
>
>
> And Here is the code that generates my metamesh.txt file:
>
> #include <iostream>
>
>
> // Software Guide : BeginLatex
> //
> // We start by including the headers of the main classes required for this
> // example. The BinaryMask3DMeshSource is used to produce an initial
> // approximation of the shape to be segmented. This filter takes a binary
> // image as input and produces a Mesh as output using the marching cube
> // isocontouring algorithm.
> //
> // \index{itk::BinaryMask3DMeshSource!Header}
> //
> // Software Guide : EndLatex
>
> // Software Guide : BeginCodeSnippet
> #include "itkBinaryMask3DMeshSource.h"
> // Software Guide : EndCodeSnippet
>
>
> // Software Guide : BeginLatex
> //
> // Then we include the header of the DeformableMesh3DFilter that
> // implements the deformable model algorithm.
> //
> // \index{itk::DeformableMesh3DFilter!Header}
> //
> // Software Guide : EndLatex
>
> // Software Guide : BeginCodeSnippet
> #include "itkDeformableMesh3DFilter.h"
> // Software Guide : EndCodeSnippet
>
>
> // Software Guide : BeginLatex
> //
> // We also need the headers of the gradient filters that will be used for
> // computing the vector field. In our case they are the
> // GradientMagnitudeRecursiveGaussianImageFilter and
> // GradientRecursiveGaussianImageFilter.
> //
> // Software Guide : EndLatex
>
> // Software Guide : BeginCodeSnippet
> #include "itkGradientRecursiveGaussianImageFilter.h"
> #include "itkGradientMagnitudeRecursiveGaussianImageFilter.h"
> // Software Guide : EndCodeSnippet
>
>
> // Software Guide : BeginLatex
> //
> // The main data structures required in this example are the Image
> // and the Mesh classes. The deformable model \emph{per se} is
> // represented as a Mesh.
> //
> // Software Guide : EndLatex
>
> // Software Guide : BeginCodeSnippet
> #include "itkImage.h"
> #include "itkMesh.h"
> // Software Guide : EndCodeSnippet
>
>
> // Software Guide : BeginLatex
> //
> // The \code{PixelType} of the image derivatives is represented with a
> // \doxygen{CovariantVector}. We include its header in the following line.
> //
> // Software Guide : EndLatex
>
> // Software Guide : BeginCodeSnippet
> #include "itkCovariantVector.h"
> // Software Guide : EndCodeSnippet
>
> // Software Guide : BeginLatex
> //
> // The deformed mesh is converted into a binary image using the
> // \doxygen{PointSetToImageFilter}.
> //
> // Software Guide : EndLatex
>
> // Software Guide : BeginCodeSnippet
> #include "itkPointSetToImageFilter.h"
> // Software Guide : EndCodeSnippet
>
> // Software Guide : BeginLatex
> //
> // In order to read both the input image and the mask image, we need the
> // \doxygen{ImageFileReader} class. We also need the
> \doxygen{ImageFileWriter}
> // to save the resulting deformed mask image.
> //
> // Software Guide : EndLatex
>
> // Software Guide : BeginCodeSnippet
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> // Software Guide : EndCodeSnippet
>
> //added by jd
> //http://www.slideshare.net/kitware/itk-tutorial-presentation-slides948
> #include "itkSpatialObjectWriter.h"
> #include "itkMeshSpatialObject.h"
> #include "itkDefaultDynamicMeshTraits.h"
> //end of added code
>
> int main( int argc, char *argv[] )
> {
>
> if( argc < 4 )
> {
> std::cerr << "Missing Parameters " << std::endl;
> std::cerr << "Usage: " << argv[0];
> std::cerr << " InputImage BinaryImage DeformedMaskImage" << std::endl;
> return 1;
> }
>
>
> // Software Guide : BeginLatex
> //
> // Here we declare the type of the image to be processed. This implies a
> // decision about the \code{PixelType} and the dimension. The
> // DeformableMesh3DFilter is specialized for $3D$, so the choice
> // is clear in our case.
> //
> // Software Guide : EndLatex
>
> // Software Guide : BeginCodeSnippet
>
> const unsigned int Dimension = 3;
>
> typedef signed short PixelType;
>
> typedef itk::Image<PixelType, Dimension> ImageType;
> // Software Guide : EndCodeSnippet
>
>
> // Software Guide : BeginLatex
> //
> // The input to BinaryMask3DMeshSource is a binary mask that we
> // will read from a file. This mask could be the result of a rough
> // segmentation algorithm applied previously to the same anatomical
> // structure. We declare below the type of the binary mask image.
> //
> // Software Guide : EndLatex
>
> // Software Guide : BeginCodeSnippet
>
> typedef itk::Image< signed short, Dimension > BinaryImageType;
>
> // Software Guide : EndCodeSnippet
>
>
> // Software Guide : BeginLatex
> //
> // Then we define the type of the deformable mesh. We represent the
> // deformable model using the Mesh class. The \code{signed short} type
> used as
> // template parameter here is to be used to assign values to every point
> // of the Mesh.
> //
> // Software Guide : EndLatex
>
> // Software Guide : BeginCodeSnippet
>
> typedef itk::Mesh<signed short> MeshType;
>
> // Software Guide : EndCodeSnippet
>
>
> // Software Guide : BeginLatex
> //
> // The filter implementing the isocontouring algorithm is the
> // BinaryMask3DMeshSource filter.
> //
> // \index{itk::BinaryMask3DMeshSource!Instantiation}
> //
> // Software Guide : EndLatex
>
> // Software Guide : BeginCodeSnippet
> typedef itk::BinaryMask3DMeshSource< BinaryImageType, MeshType >
> MeshSourceType;
>
>
> // Software Guide : BeginLatex
> //
> // Let's declare two readers. The first will read the image to be
> // segmented. The second will read the binary mask containing a first
> // approximation of the segmentation that will be used to initialize a
> // mesh for the deformable model.
> //
> // Software Guide : EndLatex
>
> // Software Guide : BeginCodeSnippet
> typedef itk::ImageFileReader< ImageType > ReaderType;
> typedef itk::ImageFileReader< BinaryImageType > BinaryReaderType;
> ReaderType::Pointer imageReader = ReaderType::New();
> BinaryReaderType::Pointer maskReader = BinaryReaderType::New();
> // Software Guide : EndCodeSnippet
>
>
> // Software Guide : BeginLatex
> //
> // In this example we take the filenames of the input image and the
> binary
> // mask from the command line arguments.
> //
> // Software Guide : EndLatex
>
> // Software Guide : BeginCodeSnippet
> imageReader->SetFileName( argv[1] );
> maskReader->SetFileName( argv[2] );
> // Software Guide : EndCodeSnippet
>
>
>
>
> // Software Guide : BeginLatex
> //
> // Now we can construct the mesh source filter that implements the
> // isocontouring algorithm.
> //
> // \index{BinaryMask3DMeshSource!New()}
> // \index{BinaryMask3DMeshSource!Pointer}
> //
> // Software Guide : EndLatex
>
> // Software Guide : BeginCodeSnippet
> MeshSourceType::Pointer meshSource = MeshSourceType::New();
>
> BinaryImageType::Pointer mask = maskReader->GetOutput();
> meshSource->SetInput( mask );
>
> meshSource->SetObjectValue( 1 );
>
> std::cout << "Creating mesh..." << std::endl;
> try
> {
> meshSource->Update();
> }
> catch( itk::ExceptionObject & excep )
> {
> std::cerr << "Exception Caught !" << std::endl;
> std::cerr << excep << std::endl;
> }
>
> meshSource->GetOutput()->Print(std::cout);
>
> //from slideshare website
>
> typedef itk::MeshSpatialObject<MeshType>MeshSpatialObjectType;
>
> MeshSpatialObjectType::Pointer meshSO = MeshSpatialObjectType::New();
> meshSO->SetMesh(meshSource->GetOutput());
>
> typedef MeshSourceType::OutputMeshType OutputMeshType;
>
> typedef itk::SpatialObjectWriter<3,signed
> short,OutputMeshType::MeshTraits>WriterType;
> WriterType::Pointer writer=WriterType::New();
> writer->SetInput(meshSO);
> writer->SetFileName("metamesh.txt");
> writer->Update();
> //end of added code
>
> std::cout << "Deformable mesh created using Marching Cube!" << std::endl;
>
> return EXIT_SUCCESS;
> }
>
>
> Any help in giving me suggestions to view this mesh would be appreciated.
>
>
> Thank you,
> John
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100722/00a5f3ee/attachment-0001.htm>
More information about the Insight-users
mailing list