1
/*=========================================================================
3
Program: Insight Segmentation & Registration Toolkit
4
Module: $RCSfile: itkVTKPolyDataWriterTest.cxx,v $
6
Date: $Date: 2007-10-16 01:34:06 $
7
Version: $Revision: 1.2 $
9
Copyright (c) Insight Software Consortium. All rights reserved.
10
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
12
This software is distributed WITHOUT ANY WARRANTY; without even
13
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14
PURPOSE. See the above copyright notices for more information.
16
=========================================================================*/
18
#pragma warning ( disable : 4786 )
21
#include "itkTriangleCell.h"
22
#include "itkLineCell.h"
23
#include "itkVTKPolyDataWriter.h"
25
int itkVTKPolyDataWriterTest(int argc, char* argv[])
29
std::cerr << "Usage: itkVTKPolyDataWriter outputFileName" << std::endl;
33
const unsigned int PointDimension = 3;
35
typedef unsigned short PixelType;
36
typedef float PointType;
38
typedef itk::Mesh< PointType, PointDimension > MeshType;
40
typedef MeshType::CellTraits CellTraits;
41
typedef itk::CellInterface< PointType, CellTraits > CellInterfaceType;
42
typedef itk::TriangleCell< CellInterfaceType > TriangleCellType;
43
typedef itk::LineCell< CellInterfaceType > LineCellType;
45
typedef itk::VTKPolyDataWriter<MeshType> WriterType;
47
MeshType::Pointer mesh = MeshType::New();
49
const unsigned int numberOfPoints = 4;
50
const unsigned int numberOfCells = 9;
52
float rawPoints[12] = {
58
unsigned long rawCells[24] = {
70
mesh->GetPoints()->Reserve( numberOfPoints );
71
mesh->GetCells()->Reserve( numberOfCells );
73
MeshType::PointType point;
75
for(unsigned int i=0; i<numberOfPoints; i++)
77
point[0] = rawPoints[3*i];
78
point[1] = rawPoints[3*i+1];
79
point[2] = rawPoints[3*i+2];
80
mesh->SetPoint( i, point );
83
unsigned long pointIds[3];
85
MeshType::CellAutoPointer cell;
86
TriangleCellType * triangle;
89
for(unsigned int i=0; i<4; i++)
91
pointIds[0] = rawCells[3*i];
92
pointIds[1] = rawCells[3*i+1];
93
pointIds[2] = rawCells[3*i+2];
95
triangle = new TriangleCellType;
96
triangle->SetPointIds( pointIds );
97
cell.TakeOwnership( triangle );
98
mesh->SetCell( i, cell );
100
for(unsigned int i=4; i<10; i++)
102
pointIds[0] = rawCells[12+2*(i-4)];
103
pointIds[1] = rawCells[12+2*(i-4)+1];
105
line = new LineCellType;
106
line->SetPointIds( pointIds );
107
cell.TakeOwnership( line );
108
mesh->SetCell( i, cell );
111
WriterType::Pointer writer = WriterType::New();
112
writer->SetInput( mesh );
113
writer->SetFileName( argv[1] );
116
std::cout << __LINE__ << " PrintSelf\n" << writer;