📄 itkquadedgemeshaddfacetest1.cxx
字号:
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkQuadEdgeMeshAddFaceTest1.cxx,v $
Language: C++
Date: $Date: 2007-09-05 18:46:45 $
Version: $Revision: 1.10 $
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 "itkQuadEdgeMesh.h"
#include "itkQuadEdgeMeshBoundaryEdgesMeshFunction.h"
int itkQuadEdgeMeshAddFaceTest1( int , char *[] )
{
typedef itk::QuadEdgeMesh< double, 3 > MeshType;
typedef MeshType::PointType PointType;
typedef MeshType::PointIdentifier PointIdentifier;
typedef MeshType::CellIdentifier CellIdentifier;
typedef std::vector< PointIdentifier > PointIdList;
MeshType::Pointer mesh = MeshType::New();
// //
// p3--------------p2 //
// / \ / \ //
// / \ / \ //
// / \ / \ //
// / \ / \ //
// / \ / \ //
// / \ / \ //
// / \ / \ //
// p4---------------p0--------------p1 //
// \ / \ / //
// \ / \ / //
// \ / \ / //
// \ / \ / //
// \ / \ / //
// \ / \ / //
// \ / \ / //
// p5---------------p6 //
/// //
const int NumPoints = 7;
PointIdentifier pid[NumPoints];
PointType::CoordRepType a = sqrt( 3.0 ) / 2.0;
typedef PointType::ValueArrayType ValueArrayType;
ValueArrayType pointCoordinates[NumPoints]=
{ { 0.0, 0.0, 0.0 },
{ 1.0, 0.0, 0.0 },
{ 0.5, a, 0.0 },
{ -0.5, a, 0.0 },
{ -1.0, 0.0, 0.0 },
{ -0.5, -a, 0.0 },
{ 0.5, -a, 0.0 } };
PointType points[NumPoints];
for(int j = 0; j < NumPoints; j++)
{
points[j] = pointCoordinates[j];
}
for(int i = 0; i < NumPoints; i++)
{
pid[i] = mesh->AddPoint( points[i] );
}
/////////////////////////////////////////////////////////////
std::cout << "Adding a degenerate triangle should return false"
<< std::endl;
if( !mesh->AddFaceTriangle( pid[0], pid[0], pid[2] ) )
{
std::cout << "Passed" << std::endl;
}
else
{
std::cout << "Failed" << std::endl;
return EXIT_FAILURE;
}
/////////////////////////////////////////////////////////////////////
std::cout << "Adding a triangle with three new edges" << std::endl;
// //
// p2 //
// / \ //
// / \ //
// / \ //
// / \ //
// / \ //
// / NEW \ //
// / \ //
// p0---------------p1 y
//
if( mesh->AddFaceTriangle( pid[0], pid[1], pid[2] ) &&
mesh->FindEdge( pid[0], pid[1] ) &&
mesh->FindEdge( pid[1], pid[0] ) &&
mesh->FindEdge( pid[1], pid[2] ) &&
mesh->FindEdge( pid[2], pid[1] ) &&
mesh->FindEdge( pid[2], pid[0] ) &&
mesh->FindEdge( pid[0], pid[2] ) )
{
std::cout << "Passed" << std::endl;
}
else
{
std::cout << "Failed" << std::endl;
return EXIT_FAILURE;
}
/////////////////////////////////////////////////////////////
std::cout << "Adding a triangle with two new edges" << std::endl;
// //
// p3--------------p2 //
// \ / \ //
// \ / \ //
// \ NEW / \ //
// \ / \ //
// \ / \ //
// \ / \ //
// \ / \ //
// p0--------------p1 //
// //
if( mesh->AddFaceTriangle( pid[ 0 ], pid[ 2 ], pid[ 3 ] ) )
{
std::cout << "Passed" << std::endl;
}
else
{
std::cout << "Failed" << std::endl;
return EXIT_FAILURE;
}
/////////////////////////////////////////////////////////////
std::cout << "Adding a flipped triangle" << std::endl;
// //
// p3--------------p2 //
// \ / \ //
// \ / \ //
// \ / \ //
// \ / \ //
// \ / \ //
// \ / \ //
// \ / \ //
// p4---------------p0--------------p1 //
// \ / //
// \ / //
// \ NEW / //
// \ / //
// \ / //
// \ / //
// \ / //
// p5 //
// //
if( mesh->AddFaceTriangle( pid[0], pid[5], pid[4] ) &&
mesh->FindEdge( pid[0], pid[5] ) &&
mesh->FindEdge( pid[5], pid[0] ) &&
mesh->FindEdge( pid[5], pid[4] ) &&
mesh->FindEdge( pid[4], pid[5] ) &&
mesh->FindEdge( pid[4], pid[0] ) &&
mesh->FindEdge( pid[0], pid[4] ) )
{
std::cout << "Passed" << std::endl;
}
else
{
std::cout << "Failed" << std::endl;
return EXIT_FAILURE;
}
/////////////////////////////////////////////////////////////
std::cout << "Adding a triangle with an inconsistent orientation should "
"return false" << std::endl;
// //
// p3--------------p2 //
// / \ / \ //
// / \ / \ //
// / \ / \ //
// / \ / \ //
// / \ / \ //
// / NEW \ / \ //
// / \ / \ //
// p4---------------p0--------------p1 //
// \ / //
// \ / //
// \ / //
// \ / //
// \ / //
// \ / //
// \ / //
// p5 //
// //
if( !mesh->AddFaceTriangle( pid[0], pid[3], pid[4] ) )
{
std::cout << "Passed" << std::endl;
}
else
{
std::cout << "Failed" << std::endl;
return EXIT_FAILURE;
}
///////////////////////////////////////////////////////////////////////
// typical cases
std::cout << "Reset triangles" << std::endl;
mesh = MeshType::New();
for(int i=0; i < NumPoints; i++)
{
pid[i] = mesh->AddPoint( points[i] );
}
///////////////////////////////////////////////////////////////////////
std::cout << "Adding triangles [0,1,2], [0,2,3], [0,4,5]" << std::endl;
if( mesh->AddFaceTriangle( pid[0], pid[1], pid[2] ) &&
mesh->AddFaceTriangle( pid[0], pid[2], pid[3] ) &&
mesh->AddFaceTriangle( pid[0], pid[4], pid[5] ) )
{
std::cout << "Passed" << std::endl;
}
else
{
std::cout << "Failed" << std::endl;
return EXIT_FAILURE;
}
///////////////////////////////////////////////////////////////////
std::cout << "Adding a triangle with one new edge" << std::endl;
// //
// p3--------------p2 //
// / \ / \ //
// / \ / \ //
// / \ / \ //
// / \ / \ //
// / \ / \ //
// / NEW \ / \ //
// / \ / \ //
// p4---------------p0--------------p1 //
// \ / //
// \ / //
// \ / //
// \ / //
// \ / //
// \ / //
// \ / //
// p5 //
// //
if( mesh->AddFaceTriangle( pid[0], pid[3], pid[4] ) )
{
std::cout << "Passed" << std::endl;
}
else
{
std::cout << "FAILED." << std::endl;
return EXIT_FAILURE;
}
/////////////////////////////////////////////////////////////////////
std::cout << "Adding a triangle with two new edges" << std::endl;
// //
// //
// p3--------------p2 //
// / \ / \ //
// / \ / \ //
// / \ / \ //
// / \ / \ //
// / \ / \ //
// / \ / \ //
// / \ / \ //
// p4---------------p0--------------p1 //
// \ / \ / //
// \ / \ / //
// \ / \ NEW / //
// \ / \ / //
// \ / \ / //
// \ / \ / //
// \ / \ / //
// p5 p6 //
// //
if( mesh->AddFaceTriangle( pid[0], pid[6], pid[1] ) )
{
std::cout << "Passed" << std::endl;
}
else
{
std::cout << "Failed" << std::endl;
return EXIT_FAILURE;
}
/////////////////////////////////////////////////////////////
std::cout << "Adding a triangle to close the 1-ring" << std::endl;
// //
// p3--------------p2 //
// / \ / \ //
// / \ / \ //
// / \ / \ //
// / \ / \ //
// / \ / \ //
// / \ / \ //
// / \ / \ //
// p4---------------p0--------------p1 //
// \ / \ / //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -