/usr/include/InsightToolkit/Review/itkQuadEdgeMeshEulerOperatorJoinVertexFunction.txx is in libinsighttoolkit3-dev 3.20.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 | /*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: itkQuadEdgeMeshEulerOperatorJoinVertexFunction.txx
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.
=========================================================================*/
#ifndef __itkQuadEdgeMeshEulerOperatorJoinVertexFunction_txx
#define __itkQuadEdgeMeshEulerOperatorJoinVertexFunction_txx
#include "itkQuadEdgeMeshEulerOperatorJoinVertexFunction.h"
#include "itkQuadEdgeMeshZipMeshFunction.h"
#include <list>
#include <algorithm>
namespace itk
{
template < class TMesh, class TQEType >
QuadEdgeMeshEulerOperatorJoinVertexFunction< TMesh, TQEType >::
QuadEdgeMeshEulerOperatorJoinVertexFunction() : Superclass(),
m_OldPointID( 0 ), m_EdgeStatus( STANDARD_CONFIG )
{}
//--------------------------------------------------------------------------
template < class TMesh, class TQEType >
void
QuadEdgeMeshEulerOperatorJoinVertexFunction< TMesh, TQEType >::
PrintSelf( std::ostream& os, Indent indent ) const
{
Superclass::PrintSelf( os, indent );
os << indent << "m_OldPointID: " << m_OldPointID <<std::endl;
os << indent << "m_EdgeStatus: ";
switch( m_EdgeStatus )
{
default:
case STANDARD_CONFIG:
os << "STANDARD_CONFIG" <<std::endl;
break;
case QUADEDGE_ISOLATED:
os << "QUADEDGE_ISOLATED" <<std::endl;
break;
case FACE_ISOLATED:
os << "FACE_ISOLATED" <<std::endl;
break;
case EDGE_NULL:
os << "EDGE_NULL" <<std::endl;
break;
case MESH_NULL:
os << "MESH_NULL" <<std::endl;
break;
case EDGE_ISOLATED:
os << "EDGE_ISOLATED" <<std::endl;
break;
case TOO_MANY_COMMON_VERTICES:
os << "TOO_MANY_COMMON_VERTICES" <<std::endl;
break;
case TETRAHEDRON_CONFIG:
os << "TETRAHEDRON_CONFIG" <<std::endl;
break;
case SAMOSA_CONFIG:
os << "SAMOSA_CONFIG" <<std::endl;
break;
case EYE_CONFIG:
os << "EYE_CONFIG" <<std::endl;
break;
case EDGE_JOINING_DIFFERENT_BORDERS:
os << "EDGE_JOINING_DIFFERENT_BORDERS" <<std::endl;
break;
}
}
//--------------------------------------------------------------------------
template < class TMesh, class TQEType >
typename QuadEdgeMeshEulerOperatorJoinVertexFunction< TMesh, TQEType >::OutputType
QuadEdgeMeshEulerOperatorJoinVertexFunction< TMesh, TQEType >::
Evaluate( QEType* e )
{
std::stack< QEType* > edges_to_be_deleted;
m_EdgeStatus = CheckStatus( e, edges_to_be_deleted );
switch( m_EdgeStatus )
{
default:
case STANDARD_CONFIG:
return Process( e );
// ******************************************************************
// Isolated quad edge
case QUADEDGE_ISOLATED:
return ProcessIsolatedQuadEdge( e );
// ******************************************************************
// Isolated face
case FACE_ISOLATED:
return ProcessIsolatedFace( e, edges_to_be_deleted );
// ******************************************************************
// e == 0
case EDGE_NULL:
// m_Mesh == 0
case MESH_NULL:
// e->IsIsolated() && e_sym->IsIsolated()
case EDGE_ISOLATED:
// more than 2 common vertices in 0-ring of org and dest respectively
case TOO_MANY_COMMON_VERTICES:
// Tetrahedron case
case TETRAHEDRON_CONFIG:
// Samosa case
case SAMOSA_CONFIG:
// Eye case
case EYE_CONFIG:
return( (QEType*) 0 );
case EDGE_JOINING_DIFFERENT_BORDERS:
return( (QEType*) 0 );
}
}
//--------------------------------------------------------------------------
template< class TMesh, class TQEType >
TQEType*
QuadEdgeMeshEulerOperatorJoinVertexFunction< TMesh, TQEType >::
Process( QEType* e )
{
QEType* e_sym = e->GetSym();
// General case
bool wasLeftFace = e->IsLeftSet( );
bool wasRiteFace = e->IsRightSet( );
bool wasLeftTriangle = e->IsLnextOfTriangle( );
bool wasRiteTriangle = e_sym->IsLnextOfTriangle( );
PointIdentifier NewDest = e->GetDestination( );
PointIdentifier NewOrg = e->GetOrigin( );
QEType* leftZip = e->GetLnext( );
QEType* riteZip = e->GetOprev( );
//
// \ | / //
// \ | / //
// \ | / //
// ------------------ b ------------- Y //
// ___/ | | //
// _<_leftZip__/ | | //
// / ^ | //
// X left e rite | //
// \____________ | | //
// \___ | | //
// \ | | //
// ------------------ a --riteZip->-- Y //
// / | \ //
// / | \ //
// / | \ //
//
this->m_Mesh->LightWeightDeleteEdge( e );
this->m_OldPointID = this->m_Mesh->Splice( leftZip, riteZip );
//
// | / __Y //
// | / __/ | //
// __<_leftZip___ | / __/ | //
// / \ | / __/ | //
// / \__ | / / | //
// X NOFACE __ [a = b] NOFACE | //
// \ / / / | \ \__ | //
// \______________/ _/ / | \ \__ | //
// __/ / | \ riteZip | //
// __/ / | \ \__| //
// / / | \ Y //
//
// When the Lnext and/or the Rnext ring of the argument edge was originaly
// the one[s] of a triangle, the above edge deletion created the odd
// situation of having two different edges adjacent to the same two
// vertices (which is quite a bad thing). This is was is depicted on
// the above ascii-graph, the original left face was a triangle and
// the resulting situation has two different edges adjacent to the
// two vertices X and a. In order to clean up things, we can call the
// Zip(MeshFunction) algorithm which handles this case.
// Once things are back to normal, we recreate faces when they were
// originaly present.
//
typedef QuadEdgeMeshZipMeshFunction< MeshType, QEType > Zip;
if( wasLeftTriangle )
{
typename Zip::Pointer zip = Zip::New( );
zip->SetInput( this->m_Mesh );
if( QEType::m_NoPoint != zip->Evaluate( leftZip ) )
{
itkDebugMacro( "Zip must return NoPoint (left)." );
return( (QEType*) 0 );
}
}
else
{
if( wasLeftFace )
{
this->m_Mesh->AddFace( leftZip );
}
}
// NewOrg = riteZip->GetOprev( )->GetDestination( );
if( wasRiteTriangle )
{
NewOrg = riteZip->GetDestination( );
typename Zip::Pointer zip = Zip::New( );
zip->SetInput( this->m_Mesh );
if( QEType::m_NoPoint != zip->Evaluate( riteZip ) )
{
itkDebugMacro( "Zip must return NoPoint (right)." );
return( (QEType*) 0 );
}
}
else
{
NewOrg = riteZip->GetLprev( )->GetOrigin( );
if( wasRiteFace )
{
this->m_Mesh->AddFace( riteZip );
}
}
OutputType result = this->m_Mesh->FindEdge( NewOrg, NewDest );
if( !result)
{
result = this->m_Mesh->FindEdge( NewDest )->GetSym( );
}
return( result );
}
//--------------------------------------------------------------------------
template < class TMesh, class TQEType >
TQEType*
QuadEdgeMeshEulerOperatorJoinVertexFunction< TMesh, TQEType >::
ProcessIsolatedQuadEdge( QEType* e )
{
QEType* temp = ( e->IsIsolated() == true ) ? e->GetSym() : e;
QEType* rebuildEdge = temp->GetOprev();
m_OldPointID = temp->GetSym()->GetOrigin();
bool e_leftset = e->IsLeftSet( );
this->m_Mesh->LightWeightDeleteEdge( e );
if( e_leftset )
{
this->m_Mesh->AddFace( rebuildEdge );
}
// this case has no symetric case in SPlitVertex
// i.e. it is impossible to reconstruct such a pathological
// case using SplitVertex. Thus the return value is
// of less interest.
// We return an edge whose dest is a, whichever.
return( rebuildEdge );
}
//--------------------------------------------------------------------------
template< class TMesh, class TQEType >
TQEType*
QuadEdgeMeshEulerOperatorJoinVertexFunction< TMesh, TQEType >::
ProcessIsolatedFace( QEType* e, std::stack< QEType* >& EdgesToBeDeleted )
{
PointIdentifier org = e->GetOrigin();
PointIdentifier dest = e->GetDestination();
// delete all elements
while( !EdgesToBeDeleted.empty() )
{
this->m_Mesh->LightWeightDeleteEdge( EdgesToBeDeleted.top() );
EdgesToBeDeleted.pop();
}
// it now retuns one edge from NewDest or NewOrg if there are any
// else NULL
QEType* temp = this->m_Mesh->FindEdge( dest );
if( temp != 0 )
{
return temp;
}
else
{
return this->m_Mesh->FindEdge( org );
}
}
//--------------------------------------------------------------------------
template < class TMesh, class TQEType >
bool
QuadEdgeMeshEulerOperatorJoinVertexFunction< TMesh, TQEType >::
IsFaceIsolated( QEType* e,
const bool& iWasLeftFace,
std::stack< TQEType* >& oToBeDeleted )
{
bool border;
QEType* e_sym = e->GetSym();
// turn around the face (left or right one) while edges are on the border
// and push them into a stack (which will be used to delete properly all
// elements )
QEType* temp = ( iWasLeftFace == true ) ? e : e_sym;
QEType* e_it = temp;
oToBeDeleted.push( e_it );
e_it = e_it->GetLnext();
do
{
oToBeDeleted.push( e_it );
border = e_it->IsAtBorder();
e_it = e_it->GetLnext();
} while( ( e_it != temp ) && border );
return border;
}
//--------------------------------------------------------------------------
template< class TMesh, class TQEType >
typename QuadEdgeMeshEulerOperatorJoinVertexFunction< TMesh, TQEType
>::EdgeStatusType
QuadEdgeMeshEulerOperatorJoinVertexFunction< TMesh, TQEType >::
CheckStatus( QEType* e, std::stack< TQEType* >& oToBeDeleted )
{
#ifndef NDEBUG
if( !e )
{
itkDebugMacro( "Input is not an edge." );
return EDGE_NULL;
}
if( !this->m_Mesh )
{
itkDebugMacro( "No mesh present." );
return MESH_NULL;
}
#endif
QEType* e_sym = e->GetSym();
bool IsEdgeIsolated = e->IsIsolated( );
bool IsSymEdgeIsolated = e_sym->IsIsolated( );
if( IsEdgeIsolated || IsSymEdgeIsolated )
{
if( IsEdgeIsolated && IsSymEdgeIsolated )
{
// We could shrink the edge to a point,
// But we consider this case to be degenerated.
itkDebugMacro( "Argument edge isolated." );
return EDGE_ISOLATED;
}
// One the endpoints (and only one) of the incoming edge is isolated.
// Instead of "shrinking" the edge it suffice to delete it. Note that
// this also avoids trouble since the definition of leftZip or riteZip
// would be improper in this case (in fact leftZip or riteZip would
// in fact be e or e->GetSym( )...
//
// When e is adjacent to a face, we must retrieve the edge [ a, b ]
// in order to rebuild the face after edge deletion. If the left face
// of e is set then the right face is also set... since it is the same
// face ! Here is the situation:
//
// b----a----X
// | | |
// | e |
// | | |
// | |
// X----X----X
//
// We are not yet sure of the orientation of e and which endpoint
// of e is attached in a.
return QUADEDGE_ISOLATED;
}
size_t number_common_vertices = CommonVertexNeighboor( e );
if( number_common_vertices > 2 )
{
itkDebugMacro("The 2 vertices have more than 2 common neighboor vertices.");
return TOO_MANY_COMMON_VERTICES;
}
if( number_common_vertices == 2 )
{
if( IsTetrahedron( e ) )
{
itkDebugMacro( "It forms a tetrahedron." );
return TETRAHEDRON_CONFIG;
}
}
// General case
bool wasLeftFace = e->IsLeftSet( );
bool wasRiteFace = e->IsRightSet( );
if( wasLeftFace && wasRiteFace )
{
if( IsSamosa( e ) )
{
itkDebugMacro( "SAMOSA_CONFIG." );
return SAMOSA_CONFIG;
}
if( IsEye( e ) )
{
itkDebugMacro( "EYE_CONFIG." );
return EYE_CONFIG;
}
if( IsEdgeLinkingTwoDifferentBorders( e ) )
{
itkDebugMacro( "EDGE_JOINING_DIFFERENT_BORDERS." );
return EDGE_JOINING_DIFFERENT_BORDERS;
}
}
else
{
if( wasLeftFace || wasRiteFace )
{
if( IsFaceIsolated( e, wasLeftFace, oToBeDeleted ) )
{
itkDebugMacro( "FACE_ISOLATED." );
return FACE_ISOLATED;
}
}
}
return STANDARD_CONFIG;
}
//--------------------------------------------------------------------------
template < class TMesh, class TQEType >
bool
QuadEdgeMeshEulerOperatorJoinVertexFunction< TMesh, TQEType >::
IsTetrahedron( QEType* e )
{
if( e->GetOrder() == 3 )
{
QEType* e_sym = e->GetSym();
if( e_sym->GetOrder() == 3 )
{
if( e->GetLprev()->GetOrder() == 3 )
{
if( e_sym->GetLprev()->GetOrder() == 3 )
{
bool left_triangle = e->IsLnextOfTriangle( );
bool right_triangle = e_sym->IsLnextOfTriangle( );
if( left_triangle && right_triangle )
{
CellIdentifier id_left_right_triangle;
if( e->GetLprev()->IsRightSet() )
{
id_left_right_triangle = e->GetLprev()->GetRight();
}
else
{
return false;
}
CellIdentifier id_left_left_triangle;
if( e->GetLnext()->IsRightSet() )
{
id_left_left_triangle = e->GetLnext()->GetRight();
}
else
{
return false;
}
CellIdentifier id_right_left_triangle;
if( e_sym->GetLnext()->IsRightSet() )
{
id_right_left_triangle = e_sym->GetLnext()->GetRight();
}
else
{
return false;
}
CellIdentifier id_right_right_triangle;
if( e_sym->GetLprev()->IsRightSet() )
{
id_right_right_triangle = e_sym->GetLprev()->GetRight();
}
else
{
return false;
}
if( ( id_left_right_triangle == id_right_left_triangle ) &&
( id_left_left_triangle == id_right_right_triangle ) )
{
return true;
}
}
}
}
}
}
return false;
}
//--------------------------------------------------------------------------
template < class TMesh, class TQEType >
bool
QuadEdgeMeshEulerOperatorJoinVertexFunction< TMesh, TQEType >::
IsSamosa( QEType* e )
{
return ( ( e->GetOrder() == 2 ) && ( e->GetSym()->GetOrder() == 2 ) );
}
//--------------------------------------------------------------------------
template < class TMesh, class TQEType >
bool
QuadEdgeMeshEulerOperatorJoinVertexFunction< TMesh, TQEType >::
IsEye( QEType* e )
{
bool OriginOrderIsTwo = ( e->GetOrder( ) == 2 );
bool DestinationOrderIsTwo = ( e->GetSym()->GetOrder( ) == 2 );
return ( ( OriginOrderIsTwo && !DestinationOrderIsTwo ) ||
( !OriginOrderIsTwo && DestinationOrderIsTwo ) );
}
//--------------------------------------------------------------------------
template < class TMesh, class TQEType >
size_t
QuadEdgeMeshEulerOperatorJoinVertexFunction< TMesh, TQEType >::
CommonVertexNeighboor( QEType* e )
{
QEType* qe = e;
QEType* e_it = qe->GetOnext( );
typedef std::list< PointIdentifier > PointIdentifierList;
PointIdentifierList dir_list;
PointIdentifierList sym_list;
PointIdentifierList intersection_list;
PointIdentifier id;
do
{
id = e_it->GetDestination();
dir_list.push_back( id );
e_it = e_it->GetOnext();
} while( e_it != qe );
qe = qe->GetSym();
e_it = qe;
do
{
id = e_it->GetDestination();
sym_list.push_back( id );
e_it = e_it->GetOnext();
} while( e_it != qe );
dir_list.sort();
sym_list.sort();
std::set_intersection( dir_list.begin(), dir_list.end(),
sym_list.begin(), sym_list.end(),
std::back_inserter( intersection_list ) );
return intersection_list.size();
}
//--------------------------------------------------------------------------
template < class TMesh, class TQEType >
bool
QuadEdgeMeshEulerOperatorJoinVertexFunction< TMesh, TQEType >::
IsEdgeLinkingTwoDifferentBorders( QEType* e )
{
QEType* t = e;
QEType* e_it = t;
bool org_border;
do
{
org_border = e_it->IsAtBorder();
e_it = e_it->GetOnext();
} while( ( e_it != t ) && ( !org_border ) );
if( !org_border )
{
return false;
}
else
{
t = e->GetSym();
e_it = t;
bool dest_border;
do
{
dest_border = e_it->IsAtBorder();
e_it = e_it->GetOnext();
} while( ( e_it != t ) && ( !dest_border ) );
if( !dest_border )
{
return false;
}
else
{
return true;
}
}
}
} // namespace itkQE
#endif
// eof - itkQuadEdgeMeshEulerOperatorJoinVertexFunction.txx
|