<HTML>
<HEAD>
<TITLE>Re: [Insight-users] Can a Vertex find its Lines?</TITLE>
</HEAD>
<BODY>
<FONT FACE="Verdana, Helvetica, Arial"><SPAN STYLE='font-size:12.0px'>Hi paul,<BR>
<BR>
At the cell level, the cell interface API (boundaryfeatures functions) gives you only informations about their boundaries i.e. All the cells of (topological) dimension equal or inferior to itself&#8217;s. <BR>
<BR>
At the itk::Mesh level, you have an interface to get what you want, even though it has not been directly exported into a nice GetPointCells function. The structure is there though. You need to call BuildLinks first and then to access directly the CellLinksContainer. You can take a look at the implementation of getCellNeighbors to see how it works.<BR>
Indeed a lot of filter implementations recode a local array to stock this information (simplex mesh, spherical wavelet, ...). Alas.<BR>
<BR>
If you use the cvs version of ITK, compiled with the advanced USE_REVIEW option on, and if you mesh is a surface mesh, you can use an itk::QuadEdgeMesh which will give you a direct iterator to the 1-ring of a point (Point-&gt;GetEdge( )-&gt;BeginGeomOnext( )). This iterator is consistant with the orientation and allows you to access the points (GetDestination( )) as well of the faces (GetLeft( )) of the one ring.<BR>
<BR>
Alex.<BR>
<BR>
On 7/26/07 3:16 PM, &quot;Paul Dennis&quot; &lt;aaeamdar@gmail.com&gt; wrote:<BR>
<BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE="Verdana, Helvetica, Arial"><SPAN STYLE='font-size:12.0px'>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.<BR>
<BR>
Here's the problem: using the &quot;Mesh&quot; 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: <BR>
<BR>
pointerToMyVertexCell-&gt;GetLinesAssociatedWithMe(dimension);<BR>
<BR>
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): <BR>
<BR>
<BR>
void printCells(MeshType::Pointer pMesh)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CellIterator cellIterator &nbsp;&nbsp;&nbsp;= pMesh-&gt;GetCells()-&gt;Begin();<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CellIterator cellEnd &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= pMesh-&gt;GetCells()-&gt;End();<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CellType::CellAutoPointer tempCellPointer; <BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while( cellIterator != cellEnd )<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CellType * pCell = cellIterator.Value();<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt; pCell-&gt;GetNameOfClass() &lt;&lt; endl;<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int type = pCell-&gt;GetType(); <BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int a = pCell-&gt;GetNumberOfBoundaryFeatures(VERTEX_DIMENSION);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int b = pCell-&gt;GetNumberOfBoundaryFeatures(LINE_DIMENSION);<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch (type)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case CellType::VERTEX_CELL: <BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt; &quot;\tpointId = &quot; &lt;&lt; ((VertexType*)pCell)-&gt;GetPointId() &lt;&lt; endl;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt; &quot;numBoundfeats = &quot; &lt;&lt; ((VertexType*)pCell)-&gt;GetNumberOfBoundaryFeatures(LINE_DIMENSION) &lt;&lt; endl; <BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case CellType::LINE_CELL:<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (int i = 0; i &lt; a; i++)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pCell-&gt;GetBoundaryFeature(VERTEX_DIMENSION, i, tempCellPointer); <BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt; &quot;\t&quot; &lt;&lt; tempCellPointer-&gt;GetNameOfClass() &lt;&lt; endl;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;VertexType * pVertex = dynamic_cast&lt; VertexType* &gt;(tempCellPointer.GetPointer ());<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;assert (pVertex != NULL);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n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p;&nbsp;&nbsp;pCell-&gt;GetBoundaryFeature(LINE_DIMENSION, i, tempCellPointer); <BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt; &quot;\t&quot; &lt;&lt; tempCellPointer-&gt;GetNameOfClass() &lt;&lt; endl;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int c = tempCellPointer-&gt;GetNumberOfBoundaryFeatures(VERTEX_DIMENSION);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;VertexType::CellAutoPointer tempVertexPointer;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 0; j &lt; c; j++)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tempCellPointer-&gt;GetBoundaryFeature(VERTEX_DIMENSION, j, tempVertexPointer); <BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt; &quot;\t\t&quot; &lt;&lt; tempVertexPointer-&gt;GetNameOfClass() &lt;&lt; endl;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;VertexType * pVertex = dynamic_cast&lt; VertexType* &gt;(tempVertexPointer.GetPointer ());<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;assert (pVertex != NULL);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt; &quot;\t\t\t pointId = &quot; &lt;&lt; pVertex-&gt;GetPointId() &lt;&lt; endl;<BR>
&n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p;&nbsp;&nbsp;}<BR>
<BR>
Which generates output like this:<BR>
<BR>
TriangleCell<BR>
&nbsp;&nbsp;&nbsp;&nbsp;LineCell<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;VertexCell<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pointId = 4223<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;VertexCell<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pointId = 3958<BR>
etc etc...<BR>
<BR>
However, so far I have only been able to iterate downwards in the dimension tree (i.e. Triangle-&gt;Line-&gt;Vertex) and not up.<BR>
<BR>
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 all &nbsp;of the cells and call their euclideanDistanceTo(Point) methods, but this would be a)time-consuming and b) unreliable. <BR>
<BR>
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? <BR>
<BR>
Thanks,<BR>
Paul Dennis<BR>
</SPAN></FONT></BLOCKQUOTE><FONT FACE="Verdana, Helvetica, Arial"><SPAN STYLE='font-size:12.0px'><BR>
</SPAN></FONT>
</BODY>
</HTML>