KWStyle - itkPolygonCell.txx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkPolygonCell.txx.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:45 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12   Portions of this code are covered under the VTK copyright.
13   See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details.
14
15      This software is distributed WITHOUT ANY WARRANTY; without even 
16      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
17 IND *****PURPOSE.  See the above copyright notices for more information.
18
19 =========================================================================*/
20 DEF #ifndef _itkPolygonCell_txx
21 DEF #define _itkPolygonCell_txx
22 #include "itkPolygonCell.h"
23
24
25 namespace itk
26 {
27
28 /**
29  * Standard CellInterface:
30  */
31 template <typename TCellInterface>
32 void
33 PolygonCell< TCellInterface >
34 ::MakeCopy(CellAutoPointer & cellPointer) const
35 {
36   Self * newPolygonCell = new Self;
37   cellPointer.TakeOwnership( newPolygonCell );
38   const unsigned long numberOfPoints = this->GetNumberOfPoints();
39   if ( numberOfPoints ) 
40     {
41     newPolygonCell->SetPointIds(0, numberOfPoints, this->GetPointIds());
42     }
43   else
44     {
45     newPolygonCell->ClearPoints(); 
46     // Make sure the new cell has no points or edges
47     }
48 }
49
50
51   
52 /**
53  * Standard CellInterface:
54  * Get the topological dimension of this cell.
55  */
56 template <typename TCellInterface>
57 unsigned int
58 PolygonCell< TCellInterface >
59 ::GetDimension(void) const
60 {
61   return Self::CellDimension;
62 }
63
64
65 /**
66  * Standard CellInterface:
67  * Get the number of points required to define the cell.
68  */
69 template <typename TCellInterface>
70 unsigned int
71 PolygonCell< TCellInterface >
72 ::GetNumberOfPoints(void) const
73 {
74   return static_cast<unsigned int>( m_PointIds.size() );
75 }  
76
77
78 /**
79  * Standard CellInterface:
80  * Get the number of boundary features of the given dimension.
81  */
82 template <typename TCellInterface>
83 typename PolygonCell< TCellInterface >::CellFeatureCount
84 PolygonCell< TCellInterface >
85 ::GetNumberOfBoundaryFeatures(int dimension) const
86 {
87   switch (dimension)
88     {
89     case 0: return this->GetNumberOfVertices();
90     case 1: return this->GetNumberOfEdges();
91     default: return 0;
92     }
93 }
94
95
96 /**
97  * Standard CellInterface:
98  * Get the boundary feature of the given dimension specified by the given
99  * cell feature Id.
100  * The Id can range from 0 to GetNumberOfBoundaryFeatures(dimension)-1.
101  */
102 template <typename TCellInterface>
103 bool
104 PolygonCell< TCellInterface >
105 ::GetBoundaryFeature(int dimension, CellFeatureIdentifier featureId,
106                      CellAutoPointer& cellPointer )
107 {
108   switch (dimension)
109     {
110     case 0: 
111 IND ****{
112 IND ****VertexAutoPointer vertexPointer;
113 IND ****if( this->GetVertex(featureId,vertexPointer) )
114 IND ******{
115 IND ******TransferAutoPointer(cellPointer,vertexPointer);
116 IND ******return true;
117 IND ******}
118 IND ****else
119 IND ******{
120 IND ******cellPointer.Reset();
121 IND ******return false;
122 IND ******}
123 IND ****break;
124 IND ****}
125     case 1: 
126 IND ****{
127 IND ****EdgeAutoPointer edgePointer;
128 IND ****if( this->GetEdge(featureId,edgePointer) )
129 IND ******{
130 IND ******TransferAutoPointer(cellPointer,edgePointer);
131 IND ******return true;
132 IND ******}
133 IND ****else
134 IND ******{
135 IND ******cellPointer.Reset();
136 IND ******return false;
137 IND ******}
138 IND ****break;
139 IND ****}
140
141     default: 
142 IND ****{
143 IND ****cellPointer.Reset();
144 IND ****return false;
145 IND ****}
146     }
147   return false;
148 }
149
150
151 EML
152 /**
153  * Standard CellInterface:
154  * Set the point id list used by the cell.  It is assumed that the given
155  * iterator can be incremented and safely de-referenced enough times to 
156  * get all the point ids needed by the cell.
157  */ 
158 template <typename TCellInterface>
159 void
160 PolygonCell< TCellInterface >
161 ::SetPointIds(int itkNotUsed(dummy), int num, PointIdConstIterator first)
162 {
163   PointIdConstIterator ii(first);
164   m_PointIds.clear();
165 SEM   for(int i=0; i < num ; ++i)
166     {
167     m_PointIds.push_back(*ii++);
168     }
169   this->BuildEdges();
170 }
171
172 /**
173  * after input the points in order, generate the edge connections
174  */
175 template <typename TCellInterface>
176 void
177 PolygonCell< TCellInterface >
178 ::BuildEdges(void)
179 {
180   if( m_PointIds.size() > 0 )
181     {
182     m_Edges.resize(m_PointIds.size());
183 LEN     const unsigned int numberOfPoints = static_cast<unsigned int>( m_PointIds.size() );
184     for(unsigned int i = 1; i < numberOfPoints; i++)
185       {
186       m_Edges[i-1][0]=i-1;
187       m_Edges[i-1][1]=i;
188       }
189     m_Edges[ numberOfPoints-1][0]= numberOfPoints-1;
190     m_Edges[ numberOfPoints-1][1]=0;
191     }
192   else
193     {
194     m_Edges.clear();
195     }
196 }
197
198 /**
199  * Standard CellInterface:
200  * Set the point id list used by the cell.  It is assumed that the given
201  * iterator can be incremented and safely de-referenced enough times to 
202  * get all the point ids needed by the cell.
203  */ 
204 template <typename TCellInterface>
205 void
206 PolygonCell< TCellInterface >
207 ::SetPointIds(PointIdConstIterator)
208 {
209 }
210
211 /** 
212  * Add one points to the points list
213  */
214 template <typename TCellInterface>
215 void
216 PolygonCell< TCellInterface >
217 ::AddPointId(PointIdentifier ptID)
218 {
219   m_PointIds.push_back(ptID);
220 }
221
222 /** 
223  * Remove one points from the points list
224  */
225 template <typename TCellInterface>
226 void
227 PolygonCell< TCellInterface >
228 ::RemovePointId(PointIdentifier ptID)
229 {
230   typename std::vector<PointIdentifier>::iterator position = 
231 IND ****std::find(m_PointIds.begin(),m_PointIds.end(),ptID);
232   if( position != m_PointIds.end() )
233     {
234     m_PointIds.erase(position);
235     }
236 }
237
238 /**
239  * clear all the point and edge informations
240  */
241 template <typename TCellInterface>
242 void
243 PolygonCell< TCellInterface >
244 ::ClearPoints(void)
245 {
246   m_PointIds.clear();
247   m_Edges.clear();
248 }
249
250 /**
251  * Standard CellInterface:
252  * Set the point id list used by the cell.  It is assumed that the range
253  * of iterators [first, last) contains the correct number of points needed to
254  * define the cell.  The position *last is NOT referenced, so it can safely
255  * be one beyond the end of an array or other container.
256  */ 
257 template <typename TCellInterface>
258 void
259 PolygonCell< TCellInterface >
260 ::SetPointIds(PointIdConstIterator first, PointIdConstIterator last)
261 {
262   m_PointIds.erase(m_PointIds.begin(), m_PointIds.end());
263   m_PointIds.insert(m_PointIds.begin(), first, last);
264   this->BuildEdges();
265 }
266
267 /**
268  * Standard CellInterface:
269  * Set an individual point identifier in the cell.
270  */ 
271 template <typename TCellInterface>
272 void
273 PolygonCell< TCellInterface >
274 ::SetPointId(int localId, PointIdentifier ptId)
275 {
276   if(m_PointIds.size() < (unsigned int)(localId + 1)) {
277   m_PointIds.resize( localId + 1 );
278   }
279   m_PointIds[localId] = ptId;
280 }
281
282
283 /**
284  * Standard CellInterface:
285  * Get a begin iterator to the list of point identifiers used by the cell.
286  */
287 template <typename TCellInterface>
288 typename PolygonCell< TCellInterface >::PointIdIterator
289 PolygonCell< TCellInterface >
290 ::PointIdsBegin(void)
291 {
292   return &*(m_PointIds.begin());
293 }
294
295
296 /**
297  * Standard CellInterface:
298  * Get a const begin iterator to the list of point identifiers used
299  * by the cell.
300  */ 
301 template <typename TCellInterface>
302 typename PolygonCell< TCellInterface >::PointIdConstIterator
303 PolygonCell< TCellInterface >
304 ::PointIdsBegin(void) const
305 {
306   return &*(m_PointIds.begin());
307 }
308
309
310 /**
311  * Standard CellInterface:
312  * Get an end iterator to the list of point identifiers used by the cell.
313  */ 
314 template <typename TCellInterface>
315 typename PolygonCell< TCellInterface >::PointIdIterator
316 PolygonCell< TCellInterface >
317 ::PointIdsEnd(void)
318 {
319   return &*(m_PointIds.end());
320 }
321
322
323 /**
324  * Standard CellInterface:
325  * Get a const end iterator to the list of point identifiers used
326  * by the cell.
327  */ 
328 template <typename TCellInterface>
329 typename PolygonCell< TCellInterface >::PointIdConstIterator
330 PolygonCell< TCellInterface >
331 ::PointIdsEnd(void) const
332 {
333   return &*(m_PointIds.end());
334 }
335
336
337 /**
338  * Polygon-specific:
339  * Get the number of vertices defining the Polygon.
340  */
341 template <typename TCellInterface>
342 typename PolygonCell< TCellInterface >::CellFeatureCount
343 PolygonCell< TCellInterface >
344 ::GetNumberOfVertices(void) const
345 {
346   return static_cast<CellFeatureCount>( m_PointIds.size() );
347 }
348
349 /**
350  * Polygon-specific:
351  * Get the number of edges defined for the Polygon.
352  */
353 template <typename TCellInterface>
354 typename PolygonCell< TCellInterface >::CellFeatureCount
355 PolygonCell< TCellInterface >
356 ::GetNumberOfEdges(void) const
357 {
358   return static_cast<CellFeatureCount>( m_Edges.size() );
359 }
360
361 /**
362  * Polygon-specific:
363  * Get the vertex specified by the given cell feature Id.
364  * The Id can range from 0 to GetNumberOfVertices()-1.
365  */ 
366 template <typename TCellInterface>
367 bool
368 PolygonCell< TCellInterface >
369 ::GetVertex(CellFeatureIdentifier vertexId,VertexAutoPointer & vertexPointer )
370 {
371   VertexType * vert = new VertexType;
372   vert->SetPointId(0, m_PointIds[vertexId]);
373   vertexPointer.TakeOwnership( vert );
374   return true;  
375 }
376
377 /**
378  * Polygon-specific:
379  * Get the edge specified by the given cell feature Id.
380  * The Id can range from 0 to GetNumberOfEdges()-1.
381  */ 
382 template <typename TCellInterface>
383 bool
384 PolygonCell< TCellInterface >
385 ::GetEdge(CellFeatureIdentifier edgeId, EdgeAutoPointer & edgePointer )
386 {
387   EdgeType * edge = new EdgeType;
388   unsigned int max_pointId = this->GetNumberOfPoints() - 1;
389   if( edgeId < max_pointId ){
390   edge->SetPointId(0, m_PointIds[edgeId]);
391 IND **edge->SetPointId(1, m_PointIds[edgeId+1]);
392 IND **}
393   else if( edgeId == max_pointId ) {
394 IND **edge->SetPointId(0, m_PointIds[max_pointId] );
395 IND **edge->SetPointId(1, m_PointIds[0] );
396 IND **}
397   edgePointer.TakeOwnership( edge ); 
398   return true;
399 }
400
401 // end namespace itk
402
403 #endif
404

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:39PM
© Kitware Inc.