17 #ifndef __itkSimplexMesh_txx
18 #define __itkSimplexMesh_txx
26 #include <vxl_version.h>
27 #if VXL_VERSION_DATE_FULL > 20040406
28 # include <vnl/vnl_cross.h>
29 # define itk_cross_3d vnl_cross_3d
31 # define itk_cross_3d cross_3d
42 template <
typename TPixelType,
unsigned int VDimension,
typename TMeshTraits>
46 m_GeometryData = GeometryMapType::New();
54 template <
typename TPixelType,
unsigned int VDimension,
typename TMeshTraits>
58 itkDebugMacro(
"Mesh Destructor ");
64 while (pointDataIterator != pointDataEnd)
74 geometryMap->Initialize();
75 this->ReleaseCellsMemory();
79 template <
typename TPixelType,
unsigned int VDimension,
typename TMeshTraits>
90 this->m_MaximumNumberOfRegions = mesh->GetMaximumNumberOfRegions();
95 itkExceptionMacro(<<
"itk::Mesh::CopyInformation() cannot cast "
96 <<
typeid(data).name() <<
" to "
104 template <
typename TPixelType,
unsigned int VDimension,
typename TMeshTraits>
110 geometry->
eps = value;
113 template <
typename TPixelType,
unsigned int VDimension,
typename TMeshTraits>
118 return m_GeometryData->GetElement(idx)->eps;
121 template <
typename TPixelType,
unsigned int VDimension,
typename TMeshTraits>
131 template <
typename TPixelType,
unsigned int VDimension,
typename TMeshTraits>
136 return m_GeometryData->GetElement(idx)->referenceMetrics;
139 template <
typename TPixelType,
unsigned int VDimension,
typename TMeshTraits>
145 geometry->
phi = value;
149 template <
typename TPixelType,
unsigned int VDimension,
typename TMeshTraits>
156 this->GetPoint(idx, &test);
158 return m_GeometryData->GetElement(idx)->phi;
161 template <
typename TPixelType,
unsigned int VDimension,
typename TMeshTraits>
171 template <
typename TPixelType,
unsigned int VDimension,
typename TMeshTraits>
176 return m_GeometryData->GetElement(idx)->meanCurvature;
179 template <
typename TPixelType,
unsigned int VDimension,
typename TMeshTraits>
189 template <
typename TPixelType,
unsigned int VDimension,
typename TMeshTraits>
194 return m_GeometryData->GetElement(idx)->circleRadius;
197 template <
typename TPixelType,
unsigned int VDimension,
typename TMeshTraits>
206 template <
typename TPixelType,
unsigned int VDimension,
typename TMeshTraits>
211 return m_GeometryData->GetElement(idx)->distance;
214 template <
typename TPixelType,
unsigned int VDimension,
typename TMeshTraits>
217 ::AddEdge(
unsigned long startPointId,
unsigned long endPointId)
220 unsigned long edgeId = m_LastCellId;
222 NewCellPointer->SetPointId( 0, startPointId );
223 NewCellPointer->SetPointId( 1, endPointId );
225 this->SetCell( edgeId, NewCellPointer );
230 template <
typename TPixelType,
unsigned int VDimension,
typename TMeshTraits>
235 this->SetCell( m_LastCellId , cellPointer );
237 return m_LastCellId-1;
240 template <
typename TPixelType,
unsigned int VDimension,
typename TMeshTraits>
245 this->GetCells()->DeleteIndex( replaceIndex );
246 this->SetCell( replaceIndex , cellPointer );
247 this->SetCellData( replaceIndex , (
PixelType) 1.0 );
252 template <
typename TPixelType,
unsigned int VDimension,
typename TMeshTraits>
257 this->Superclass::PrintSelf(os,indent);
259 os << indent <<
"LastCellId = " << m_LastCellId << std::endl;
264 os << indent <<
"Cells Point Ids:" << std::endl;
265 while ( cellIt != cells->End() )
267 os << indent <<
"cell id: " << cellIt->Index() <<
", point ids: ";
268 CellType *nextCell = cellIt->Value();
270 while (pointIt != nextCell->
PointIdsEnd() ) { os << *pointIt++ <<
"-"; }
276 os << indent <<
"Point locations:" << std::endl;
277 while ( pointsIt != this->GetPoints()->End() )
279 os << indent <<
"pt index:" << pointsIt->Index() <<
" , coords: " << pointsIt->Value() << std::endl;
287 while (pointDataIterator != pointDataEnd)
290 os << indent <<
"Mesh Geometry Data for point:"<< pointDataIterator->
Index() << std::endl;
291 os << indent <<
"Direct Neighbors indices: "
299 template <
typename TPixelType,
unsigned int VDimension,
typename TMeshTraits>
304 if (m_GeometryData->IndexExists(pointId))
306 delete m_GeometryData->GetElement(pointId);
308 m_GeometryData->InsertElement(pointId, geometryData);
312 template <
typename TPixelType,
unsigned int VDimension,
typename TMeshTraits>
317 return m_GeometryData->
GetElement(idx)->neighborIndices;
320 template <
typename TPixelType,
unsigned int VDimension,
typename TMeshTraits>
329 list->push_back(neighborArray[0]);
330 list->push_back(neighborArray[1]);
331 list->push_back(neighborArray[2]);
335 list = GetNeighbors(neighborArray[0], radius-1, list);
336 list = GetNeighbors(neighborArray[1], radius-1, list);
337 list = GetNeighbors(neighborArray[2], radius-1, list);
339 NeighborListType::iterator it = std::find( list->begin(),list->end(),idx );
340 if (it != list->end()) list->erase(it);
348 NeighborListType::iterator foundIt1 = std::find( list->begin(),list->end(),neighborArray[0] );
349 NeighborListType::iterator foundIt2 = std::find( list->begin(),list->end(),neighborArray[1] );
350 NeighborListType::iterator foundIt3 = std::find( list->begin(),list->end(),neighborArray[2] );
351 NeighborListType::iterator endIt = list->end();
352 bool found1=
false, found2=
false, found3=
false;
354 if (foundIt1 != endIt) found1 =
true;
355 if (foundIt2 != endIt) found2 =
true;
356 if (foundIt3 != endIt) found3 =
true;
358 if (!found1) list->push_back(neighborArray[0]);
359 if (!found2) list->push_back(neighborArray[1]);
360 if (!found3) list->push_back(neighborArray[2]);
368 list = GetNeighbors(neighborArray[0], radius-1, list);
369 list = GetNeighbors(neighborArray[1], radius-1, list);
370 list = GetNeighbors(neighborArray[2], radius-1, list);
376 template <
typename TPixelType,
unsigned int VDimension,
typename TMeshTraits>
383 for (
int i = 0; i < 3; i++)
385 if (data->
neighborIndices[i] == ((
unsigned long)NumericTraits<unsigned long>::max() ))
393 template <
typename TPixelType,
unsigned int VDimension,
typename TMeshTraits>
400 for (
int i = 0; i < 3;i++)
410 template <
typename TPixelType,
unsigned int VDimension,
typename TMeshTraits>
413 ::SwapNeighbors(
unsigned long pointIdx,
unsigned long firstIdx,
unsigned long secondIdx)
418 int secondFound = -1;
420 for (i = 0; i < 3;i++)
431 if(firstFound == -1 || secondFound == -1)
433 itkExceptionMacro(
"first and second not found");
439 template <
typename TPixelType,
unsigned int VDimension,
typename TMeshTraits>
451 IndexArray neighbors = this->GetNeighbors( idx );
452 this->GetPoint(idx,&p);
453 this->GetPoint(neighbors[0],&n1);
454 this->GetPoint(neighbors[1],&n2);
455 this->GetPoint(neighbors[2],&n3);