[Insight-users] Can a Vertex find its Lines?
Paul Dennis
aaeamdar at gmail.com
Thu Jul 26 18:16:25 EDT 2007
First of all, I apologize in advance if this is a stupid question that gets
asked every month. I'm relatively new to programming and even more new to
ITK, so I am unsure if this is a reasonable query or not.
Here's the problem: using the "Mesh" structure of ITK (an itk::Mesh), is it
possible for a VertexCell to have information about the higher-dimension
cells that it's associated with? In other words, is there an equivalent to:
pointerToMyVertexCell->GetLinesAssociatedWithMe(dimension);
My initial findings seem to indicate that no, there is no built in way to do
this in ITK. I am using a K-complex from the
itk::AutomaticTopologyMeshSource template. I have quite a few triangles,
each of which has 3 lines and 3 points attached to it. I'm using the
following code segment to iterate through all the cells and print out
information (sorry this is dense and without commenting):
void printCells(MeshType::Pointer pMesh)
{
CellIterator cellIterator = pMesh->GetCells()->Begin();
CellIterator cellEnd = pMesh->GetCells()->End();
CellType::CellAutoPointer tempCellPointer;
while( cellIterator != cellEnd )
{
CellType * pCell = cellIterator.Value();
cout << pCell->GetNameOfClass() << endl;
int type = pCell->GetType();
int a = pCell->GetNumberOfBoundaryFeatures(VERTEX_DIMENSION);
int b = pCell->GetNumberOfBoundaryFeatures(LINE_DIMENSION);
switch (type)
{
case CellType::VERTEX_CELL:
cout << "\tpointId = " <<
((VertexType*)pCell)->GetPointId() << endl;
cout << "numBoundfeats = " <<
((VertexType*)pCell)->GetNumberOfBoundaryFeatures(LINE_DIMENSION) << endl;
break;
case CellType::LINE_CELL:
for (int i = 0; i < a; i++)
{
pCell->GetBoundaryFeature(VERTEX_DIMENSION, i,
tempCellPointer);
cout << "\t" << tempCellPointer->GetNameOfClass() <<
endl;
VertexType * pVertex = dynamic_cast< VertexType* >(
tempCellPointer.GetPointer ());
assert (pVertex != NULL);
cout << "\t\tpointId = " << pVertex->GetPointId() <<
endl;
}
break;
case CellType::TRIANGLE_CELL:
for (int i = 0; i < b; i++)
{
pCell->GetBoundaryFeature(LINE_DIMENSION, i,
tempCellPointer);
cout << "\t" << tempCellPointer->GetNameOfClass() <<
endl;
int c =
tempCellPointer->GetNumberOfBoundaryFeatures(VERTEX_DIMENSION);
VertexType::CellAutoPointer tempVertexPointer;
for (int j = 0; j < c; j++)
{
tempCellPointer->GetBoundaryFeature(VERTEX_DIMENSION, j, tempVertexPointer);
cout << "\t\t" <<
tempVertexPointer->GetNameOfClass() << endl;
VertexType * pVertex = dynamic_cast< VertexType*
>(tempVertexPointer.GetPointer ());
assert (pVertex != NULL);
cout << "\t\t\t pointId = " <<
pVertex->GetPointId() << endl;
}
}
break;
default:
cout << "Unrecognized format." << endl;
break;
}
++cellIterator;
}
}
Which generates output like this:
TriangleCell
LineCell
VertexCell
pointId = 4223
VertexCell
pointId = 3958
etc etc...
However, so far I have only been able to iterate downwards in the dimension
tree (i.e. Triangle->Line->Vertex) and not up.
Alternatively, if it's not possible to find higher-dimension cells from
lower-dimension ones, is there a good way to find the neighboring
VertexCells of a given VertexCell? One approach would be to go through
allof the cells and call their euclideanDistanceTo(Point) methods, but
this
would be a)time-consuming and b) unreliable.
At the moment, I'm thinking of creating a separate array and filling it when
I call the addTriangle(Point, Point, Point) method so that I have
independent information about which triangles a given point is a member of.
Is there a better way?
Thanks,
Paul Dennis
--
-Deal in puns!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20070726/1f9e104e/attachment-0001.htm
More information about the Insight-users
mailing list