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