1 /*=========================================================================
2  *
3  *  Copyright Insight Software Consortium
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *         http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkCellInterface_hxx
19 #define itkCellInterface_hxx
20 
21 #include "itkCellInterface.h"
22 
23 namespace itk
24 {
25 /**
26  * Get the interpolation order of the cell.  Usually linear.
27  */
28 template< typename TPixelType, typename TCellTraits >
29 unsigned int
30 CellInterface< TPixelType, TCellTraits >
GetInterpolationOrder() const31 ::GetInterpolationOrder() const
32 {
33   return 1;
34 }
35 
36 /**
37  * Get the point id list used by the cell in a form suitable to pass to
38  * SetPointIds(first) on another cell.  This is equivalent to
39  * PointIdsBegin() const.
40  */
41 template< typename TPixelType, typename TCellTraits >
42 typename CellInterface< TPixelType, TCellTraits >::PointIdConstIterator
43 CellInterface< TPixelType, TCellTraits >
GetPointIds() const44 ::GetPointIds() const
45 {
46   return this->PointIdsBegin();
47 }
48 
49 template< typename TPixelType, typename TCellTraits >
50 typename CellInterface< TPixelType, TCellTraits >::PointIdentifierContainerType
51 CellInterface< TPixelType, TCellTraits >
GetPointIdsContainer() const52 ::GetPointIdsContainer() const
53 {
54   PointIdentifierContainerType res;
55   res.SetSize( this->GetNumberOfPoints() );
56   int i = 0;
57   PointIdConstIterator it = this->PointIdsBegin();
58   PointIdConstIterator end = this->PointIdsEnd();
59   while( it != end )
60     {
61     res[i] = *it;
62     ++i;
63     ++it;
64     }
65   return res;
66 }
67 
68 template< typename TPixelType, typename TCellTraits >
69 void
70 CellInterface< TPixelType, TCellTraits >
SetPointIdsContainer(const PointIdentifierContainerType & container)71 ::SetPointIdsContainer( const PointIdentifierContainerType & container )
72 {
73   for( unsigned int i=0; i<container.Size(); i++ )
74     {
75     this->SetPointId( i, container[i] );
76     }
77 }
78 
79 /**
80  * Return true if the UsingCellsContainer m_UsingCells is nonempty,
81  * false otherwise.  The container m_UsingCells is meant to contain a
82  * list of all the cells that have this one as part of their boundary.
83  * Boundary data is not automatically recorded upon mesh creation.  If
84  * the boundary information has not been computed, this method always
85  * returns false.
86  */
87 template< typename TPixelType, typename TCellTraits >
88 bool
89 CellInterface< TPixelType, TCellTraits >
IsExplicitBoundary()90 ::IsExplicitBoundary()
91 {
92   return !m_UsingCells.empty();
93 }
94 
95 /**
96  * Register the fact that this cell is a part of the boundary of the
97  * cell \a cellId, by adding \a cellId to the UsingCellsContainer.
98  */
99 template< typename TPixelType, typename TCellTraits >
100 void
101 CellInterface< TPixelType, TCellTraits >
AddUsingCell(CellIdentifier cellId)102 ::AddUsingCell(CellIdentifier cellId)
103 {
104   m_UsingCells.insert(cellId);
105 }
106 
107 /**
108  * Remove a cell from the UsingCellsContainer.
109  */
110 template< typename TPixelType, typename TCellTraits >
111 void
112 CellInterface< TPixelType, TCellTraits >
RemoveUsingCell(CellIdentifier cellId)113 ::RemoveUsingCell(CellIdentifier cellId)
114 {
115   m_UsingCells.erase(cellId);
116 }
117 
118 /**
119  * Test if a cell is in the UsingCellsContainer.  A result of \c true
120  * indicates that this cell is part of the boundary of the cell \c
121  * cellId, assuming that boundary information has been recorded.
122  */
123 template< typename TPixelType, typename TCellTraits >
124 bool
125 CellInterface< TPixelType, TCellTraits >
IsUsingCell(CellIdentifier cellId)126 ::IsUsingCell(CellIdentifier cellId)
127 {
128   return ( m_UsingCells.count(cellId) > 0 );
129 }
130 
131 /**
132  * Get the number of cells in the UsingCellsContainer.
133  */
134 template< typename TPixelType, typename TCellTraits >
135 unsigned int
136 CellInterface< TPixelType, TCellTraits >
GetNumberOfUsingCells()137 ::GetNumberOfUsingCells()
138 {
139   return static_cast< unsigned int >( m_UsingCells.size() );
140 }
141 
142 #if !defined( ITK_WRAPPING_PARSER )
143 
144 /**
145  * Get a begin iterator for the UsingCellsContainer.
146  */
147 template< typename TPixelType, typename TCellTraits >
148 typename CellInterface< TPixelType, TCellTraits >::UsingCellsContainerIterator
149 CellInterface< TPixelType, TCellTraits >
UsingCellsBegin()150 ::UsingCellsBegin()
151 {
152   return m_UsingCells.begin();
153 }
154 
155 /**
156  * Get an end iterator for the UsingCellsContainer.
157  */
158 template< typename TPixelType, typename TCellTraits >
159 typename CellInterface< TPixelType, TCellTraits >::UsingCellsContainerIterator
160 CellInterface< TPixelType, TCellTraits >
UsingCellsEnd()161 ::UsingCellsEnd()
162 {
163   return m_UsingCells.end();
164 }
165 
166 #endif
167 } // end namespace itk
168 
169 #endif
170