~ubuntu-branches/ubuntu/precise/insighttoolkit/precise

« back to all changes in this revision

Viewing changes to Testing/Code/Review/itkVTKPolyDataWriterTest.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Steve M. Robbins
  • Date: 2008-12-19 20:16:49 UTC
  • mfrom: (1.2.1 upstream) (4.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20081219201649-drt97guwl2ryt0cn

* New upstream version.
  - patches/nifti-versioning.patch: Remove.  Applied upstream.
  - control:
  - rules: Update version numbers, package names.

* control: Build-depend on uuid-dev (gdcm uses it).

* copyright: Update download URL.

* rules: Adhere to parallel=N in DEB_BUILD_OPTIONS by setting MAKEFLAGS.

* compat: Set to 7.
* control: Update build-dep on debhelper to version >= 7.

* CMakeCache.txt.debian: Set CMAKE_BUILD_TYPE to "RELEASE" so that we
  build with -O3 (not -O2), necessary to optimize the templated code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*=========================================================================
 
2
 
 
3
  Program:   Insight Segmentation & Registration Toolkit
 
4
  Module:    $RCSfile: itkVTKPolyDataWriterTest.cxx,v $
 
5
  Language:  C++
 
6
  Date:      $Date: 2007-10-16 01:34:06 $
 
7
  Version:   $Revision: 1.2 $
 
8
 
 
9
  Copyright (c) Insight Software Consortium. All rights reserved.
 
10
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
 
11
 
 
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.
 
15
 
 
16
=========================================================================*/
 
17
#if defined(_MSC_VER)
 
18
#pragma warning ( disable : 4786 )
 
19
#endif
 
20
 
 
21
#include "itkTriangleCell.h"
 
22
#include "itkLineCell.h"
 
23
#include "itkVTKPolyDataWriter.h"
 
24
 
 
25
int itkVTKPolyDataWriterTest(int argc, char* argv[])
 
26
{
 
27
  if( argc != 2 )
 
28
    {
 
29
    std::cerr << "Usage: itkVTKPolyDataWriter outputFileName" << std::endl;
 
30
    return EXIT_FAILURE;
 
31
    }
 
32
 
 
33
  const unsigned int PointDimension = 3;
 
34
 
 
35
  typedef unsigned short    PixelType;
 
36
  typedef float             PointType;
 
37
 
 
38
  typedef itk::Mesh< PointType, PointDimension >  MeshType;
 
39
 
 
40
  typedef MeshType::CellTraits                        CellTraits;
 
41
  typedef itk::CellInterface< PointType, CellTraits > CellInterfaceType;
 
42
  typedef itk::TriangleCell< CellInterfaceType >      TriangleCellType;
 
43
  typedef itk::LineCell< CellInterfaceType >          LineCellType;
 
44
 
 
45
  typedef itk::VTKPolyDataWriter<MeshType>   WriterType;
 
46
 
 
47
  MeshType::Pointer mesh = MeshType::New();
 
48
 
 
49
  const unsigned int numberOfPoints = 4;
 
50
  const unsigned int numberOfCells  = 9;
 
51
 
 
52
  float rawPoints[12] = {
 
53
    0.0, 0.0, 0.0,
 
54
    1.0, 1.0, 0.0,
 
55
    0.0, 1.0, 1.0,
 
56
    1.0, 0.0, 1.0 };
 
57
 
 
58
  unsigned long rawCells[24] = {
 
59
    0, 2, 1,
 
60
    0, 1, 3,
 
61
    0, 3, 2,
 
62
    1, 2, 3,
 
63
    0, 1,
 
64
    0, 2,
 
65
    0, 3,
 
66
    1, 2,
 
67
    1, 3,
 
68
    2, 3 };
 
69
 
 
70
  mesh->GetPoints()->Reserve( numberOfPoints );
 
71
  mesh->GetCells()->Reserve( numberOfCells );
 
72
 
 
73
  MeshType::PointType point;
 
74
 
 
75
  for(unsigned int i=0; i<numberOfPoints; i++)
 
76
    {
 
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 );
 
81
    }
 
82
 
 
83
  unsigned long pointIds[3];
 
84
 
 
85
  MeshType::CellAutoPointer cell;
 
86
  TriangleCellType * triangle;
 
87
  LineCellType *     line;
 
88
 
 
89
  for(unsigned int i=0; i<4; i++)
 
90
    {
 
91
    pointIds[0] = rawCells[3*i];
 
92
    pointIds[1] = rawCells[3*i+1];
 
93
    pointIds[2] = rawCells[3*i+2];
 
94
 
 
95
    triangle = new TriangleCellType;
 
96
    triangle->SetPointIds( pointIds );
 
97
    cell.TakeOwnership( triangle );
 
98
    mesh->SetCell( i, cell );
 
99
    }
 
100
  for(unsigned int i=4; i<10; i++)
 
101
    {
 
102
    pointIds[0] = rawCells[12+2*(i-4)];
 
103
    pointIds[1] = rawCells[12+2*(i-4)+1];
 
104
 
 
105
    line = new LineCellType;
 
106
    line->SetPointIds( pointIds );
 
107
    cell.TakeOwnership( line );
 
108
    mesh->SetCell( i, cell );
 
109
    }
 
110
 
 
111
  WriterType::Pointer writer = WriterType::New();
 
112
  writer->SetInput( mesh );
 
113
  writer->SetFileName( argv[1] );
 
114
  writer->Write();
 
115
 
 
116
  std::cout << __LINE__ << " PrintSelf\n" << writer;
 
117
 
 
118
  return EXIT_SUCCESS;
 
119
}