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 /*=========================================================================
19  *
20  *  Portions of this file are subject to the VTK Toolkit Version 3 copyright.
21  *
22  *  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
23  *
24  *  For complete copyright, license and disclaimer of warranty information
25  *  please refer to the NOTICE file at the top of the ITK source tree.
26  *
27  *=========================================================================*/
28 #ifndef itkPolygonCell_h
29 #define itkPolygonCell_h
30 
31 #include "itkLineCell.h"
32 #include "itkPoint.h"
33 #include <vector>
34 #include <deque>
35 
36 namespace itk
37 {
38 /** \class PolygonCell
39  *  \brief Represents a polygon in a Mesh.
40  *
41  * PolygonCell represents a polygon for a Mesh.
42  *  the points of the polygon can be dynamically changed.
43  *
44  * \tparam TPixelType The type associated with a point, cell, or boundary
45  * for use in storing its data.
46  *
47  * \tparam TCellTraits Type information of mesh containing cell.
48  *
49  * \ingroup MeshObjects
50  * \ingroup ITKCommon
51  */
52 template< typename TCellInterface >
53 class ITK_TEMPLATE_EXPORT PolygonCell:public TCellInterface
54 {
55 public:
56   ITK_DISALLOW_COPY_AND_ASSIGN(PolygonCell);
57 
58   /** Standard class type aliases. */
59   itkCellCommonTypedefs(PolygonCell);
60   itkCellInheritedTypedefs(TCellInterface);
61 
62   /** Standard part of every itk Object. */
63   itkTypeMacro(PolygonCell, CellInterface);
64 
65   /** Save some template parameter information. */
66   static constexpr unsigned int CellDimension = 2;
67 
68   /** The type of boundary for this triangle's vertices. */
69   using VertexType = VertexCell< TCellInterface >;
70   using VertexAutoPointer = typename VertexType::SelfAutoPointer;
71 
72   /** The type of boundary for this triangle's edges. */
73   using EdgeType = LineCell< TCellInterface >;
74   using EdgeAutoPointer = typename EdgeType::SelfAutoPointer;
75 
76   using EdgeInfo = FixedArray< int, 2 >;
77   using EdgeInfoDQ = std::deque< EdgeInfo >;
78 
79   /** Need to add POLYGON_CELL into CellInterface. */
80   itkCellVisitMacro(Superclass::POLYGON_CELL);
81 
82   /** Implement the standard CellInterface. */
GetType()83   CellGeometry GetType() const override
84   { return Superclass::POLYGON_CELL; }
85   void MakeCopy(CellAutoPointer &) const override;
86 
87   unsigned int GetDimension() const override;
88 
89   unsigned int GetNumberOfPoints() const override;
90 
91   CellFeatureCount GetNumberOfBoundaryFeatures(int dimension) const override;
92 
93   bool GetBoundaryFeature(int dimension, CellFeatureIdentifier, CellAutoPointer &) override;
94 
95   void SetPointIds(PointIdConstIterator first) override;
96 
97   void SetPointIds(PointIdConstIterator first,
98                            PointIdConstIterator last) override;
99 
100   void AddPointId(PointIdentifier);
101   void RemovePointId(PointIdentifier);
102   void SetPointIds(int dummy, int num, PointIdConstIterator first);
103 
104   void BuildEdges();
105 
106   void ClearPoints();
107 
108   void SetPointId(int localId, PointIdentifier) override;
109   PointIdIterator      PointIdsBegin() override;
110 
111   PointIdConstIterator PointIdsBegin() const override;
112 
113   PointIdIterator      PointIdsEnd() override;
114 
115   PointIdConstIterator PointIdsEnd() const override;
116 
117   /** Polygon-specific interface. */
118   virtual CellFeatureCount GetNumberOfVertices() const;
119 
120   virtual CellFeatureCount GetNumberOfEdges() const;
121 
122   virtual bool GetVertex(CellFeatureIdentifier, VertexAutoPointer &);
123   virtual bool GetEdge(CellFeatureIdentifier, EdgeAutoPointer &);
124 
125   /** Constructor and destructor */
126   PolygonCell() = default;
PolygonCell(PointIdentifier NumberOfPoints)127   PolygonCell(PointIdentifier NumberOfPoints)
128   {
129     for ( PointIdentifier i = 0; i < NumberOfPoints; i++ )
130       {
131       m_PointIds.push_back( NumericTraits< PointIdentifier >::max() );
132       }
133     this->BuildEdges();
134   }
135 
136   ~PolygonCell() override = default;
137 
138 protected:
139   std::vector< EdgeInfo >        m_Edges;
140   std::vector< PointIdentifier > m_PointIds;
141 };
142 } //end namespace
143 
144 #ifndef ITK_MANUAL_INSTANTIATION
145 #include "itkPolygonCell.hxx"
146 #endif
147 
148 #endif
149