1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
|
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: itkQuadEdgeMeshPointTest1.cxx
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#include "itkQuadEdgeMeshPoint.h"
#include "itkGeometricalQuadEdge.h"
#include "itkMesh.h"
int itkQuadEdgeMeshPointTest1( int , char* [] )
{
std::cout << "Testing points..." << std::endl;
//
// These typedefs are taken from a traditional itk mesh just
// to get definitions that are consistent with the derived class.
//
typedef itk::Mesh< float, 3 > NonQuadEdgeMeshType;
typedef NonQuadEdgeMeshType::PointIdentifier PointIdentifier;
typedef NonQuadEdgeMeshType::CellIdentifier FaceIdentifier;
typedef bool PrimalDataType;
typedef bool DualDataType;
const bool ThisIsDual = true;
typedef itk::GeometricalQuadEdge<
PointIdentifier, FaceIdentifier,
PrimalDataType, DualDataType,
ThisIsDual > QuadEdgeType;
typedef itk::QuadEdgeMeshPoint< float, 3, QuadEdgeType > PointType;
typedef PointType::Superclass SuperclassPointType;
PointType p0; // Test default constructor
PointType p1;
p1[0] = 17.7;
p1[1] = 39.7;
p1[2] = -49.7;
PointType p2( p1 ); // Test copy constructor
if( p1.EuclideanDistanceTo( p2 ) > 1e-6 )
{
std::cerr << "Error in the copy constructor" << std::endl;
return EXIT_FAILURE;
}
//
// Test assigment from an itk::Point
//
SuperclassPointType ps;
ps[0] = 29;
ps[1] = 31;
ps[2] = 37;
PointType pp = ps;
if( pp.EuclideanDistanceTo( ps ) > 1e-6 )
{
std::cerr << "Error in the array constructor" << std::endl;
return EXIT_FAILURE;
}
PointType pp2;
pp2.SetPoint( ps );
if( pp2.EuclideanDistanceTo( ps ) > 1e-6 )
{
std::cerr << "Error in the array constructor" << std::endl;
return EXIT_FAILURE;
}
PointType::ValueArrayType cc;
cc[0] = 17.7;
cc[1] = 39.7;
cc[2] = -49.7;
PointType p3( cc ); // Test Array based constructor
if( p2.EuclideanDistanceTo( p1 ) > 1e-6 )
{
std::cerr << "Error in the array constructor" << std::endl;
return EXIT_FAILURE;
}
PointType p4;
PointType p4b;
p4b = p4 = p1; // Test assignment operator to Self
if( p4.EuclideanDistanceTo( p1 ) > 1e-6 )
{
std::cerr << "Error in the assignment operator to Self" << std::endl;
return EXIT_FAILURE;
}
if( p4b.EuclideanDistanceTo( p4 ) > 1e-6 )
{
std::cerr << "Error in the assignment operator to Self" << std::endl;
return EXIT_FAILURE;
}
PointType::Superclass pp1;
pp1[0] = 17.7;
pp1[1] = 39.7;
pp1[2] = -49.7;
PointType p5;
PointType p5b;
p5b = p5 = pp1; // Test assignment operator from Superclass
if( p5.EuclideanDistanceTo( pp1 ) > 1e-6 )
{
std::cerr << "Error assignment operator from Superclass" << std::endl;
return EXIT_FAILURE;
}
if( p5b.EuclideanDistanceTo( p5 ) > 1e-6 )
{
std::cerr << "Error assignment operator from Superclass" << std::endl;
return EXIT_FAILURE;
}
PointType p6;
PointType p6b;
p6b = p6 = cc; // Test assignment operator from array
if( p6.EuclideanDistanceTo( p3 ) > 1e-6 )
{
std::cerr << "Error in the assignment operator from Array " << std::endl;
return EXIT_FAILURE;
}
if( p6b.EuclideanDistanceTo( p6 ) > 1e-6 )
{
std::cerr << "Error in the assignment operator from Array " << std::endl;
return EXIT_FAILURE;
}
QuadEdgeType * edge1 = new QuadEdgeType;
p6.SetEdge( edge1 );
if( p6.GetEdge() != edge1 )
{
std::cerr << "Error in SetEdge()/GetEdge() " << std::endl;
delete edge1;
return EXIT_FAILURE;
}
QuadEdgeType * edge2 = new QuadEdgeType;
p6.SetEdge( edge2 );
if( p6.GetEdge() != edge2 )
{
std::cerr << "Error in SetEdge()/GetEdge() " << std::endl;
delete edge1;
delete edge2;
return EXIT_FAILURE;
}
// The following tests are commented out
// because the point code is not safe yet.
#if POINTMAKESAFE
bool internal = p6.IsInternal();
if( internal != true ) // FIXME: verify with a realistic case
{
std::cerr << "Error in IsInternal() " << std::endl;
delete edge1;
delete edge2;
return EXIT_FAILURE;
}
PointType p7;
if( p7.IsInternal() )
{
std::cerr << "Error in IsInternal() " << std::endl;
return EXIT_FAILURE;
}
int valence = p6.GetValence();
if( valence != 1 )
{
std::cerr << "Error in GetValence() " << std::endl;
std::cerr << "valence = " << valence << std::endl;
return EXIT_FAILURE;
}
#endif
delete edge1;
delete edge2;
std::cout << "Test passed" << std::endl;
return EXIT_SUCCESS;
}
|