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 itkHexahedronCell_h
19 #define itkHexahedronCell_h
20 
21 #include "itkQuadrilateralCell.h"
22 #include "itkHexahedronCellTopology.h"
23 
24 namespace itk
25 {
26 /** \class HexahedronCell
27  *  \brief Represents a hexahedron (cuboid) for a Mesh.
28  *
29  * HexahedronCell represents a hexahedron, more precisely, a cuboid, for a Mesh.
30  *
31  * \tparam TPixelType The type associated with a point, cell, or boundary
32  * for use in storing its data.
33  *
34  * \tparam TCellTraits Type information of mesh containing cell.
35  *
36  * \todo When reviewing this class, the documentation of the  template
37  * parameters MUST be fixed.
38  *
39  * \ingroup MeshObjects
40  * \ingroup ITKCommon
41  */
42 
43 template< typename TCellInterface >
44 class ITK_TEMPLATE_EXPORT HexahedronCell:public TCellInterface, private HexahedronCellTopology
45 {
46 public:
47   ITK_DISALLOW_COPY_AND_ASSIGN(HexahedronCell);
48 
49   /** Standard class type aliases. */
50   itkCellCommonTypedefs(HexahedronCell);
51   itkCellInheritedTypedefs(TCellInterface);
52 
53   /** Standard part of every itk Object. */
54   itkTypeMacro(HexahedronCell, CellInterface);
55 
56   /** The type of boundary for this triangle's vertices. */
57   using VertexType = VertexCell< TCellInterface >;
58   using VertexAutoPointer = typename VertexType::SelfAutoPointer;
59 
60   /** The type of boundary for this triangle's edges. */
61   using EdgeType = LineCell< TCellInterface >;
62   using EdgeAutoPointer = typename EdgeType::SelfAutoPointer;
63 
64   /** The type of boundary for this hexahedron's faces. */
65   using FaceType = QuadrilateralCell< TCellInterface >;
66   using FaceAutoPointer = typename FaceType::SelfAutoPointer;
67 
68   /** Hexahedron-specific topology numbers. */
69   static constexpr unsigned int NumberOfPoints = 8;
70   static constexpr unsigned int NumberOfVertices = 8;
71   static constexpr unsigned int NumberOfEdges = 12;
72   static constexpr unsigned int NumberOfFaces = 6;
73   static constexpr unsigned int CellDimension = 3;
74 
75   /** Implement the standard CellInterface. */
GetType()76   CellGeometry GetType() const override
77   { return Superclass::HEXAHEDRON_CELL; }
78   void MakeCopy(CellAutoPointer &) const override;
79 
80   unsigned int GetDimension() const override;
81 
82   unsigned int GetNumberOfPoints() const override;
83 
84   CellFeatureCount GetNumberOfBoundaryFeatures(int dimension) const override;
85 
86   bool GetBoundaryFeature(int dimension, CellFeatureIdentifier, CellAutoPointer &) override;
87   void SetPointIds(PointIdConstIterator first) override;
88 
89   void SetPointIds(PointIdConstIterator first, PointIdConstIterator last) override;
90 
91   void SetPointId(int localId, PointIdentifier) override;
92   PointIdIterator      PointIdsBegin() override;
93 
94   PointIdConstIterator PointIdsBegin() const override;
95 
96   PointIdIterator      PointIdsEnd() override;
97 
98   PointIdConstIterator PointIdsEnd() const override;
99 
100   /** Hexahedron-specific interface. */
101   virtual CellFeatureCount GetNumberOfVertices() const;
102 
103   virtual CellFeatureCount GetNumberOfEdges() const;
104 
105   virtual CellFeatureCount GetNumberOfFaces() const;
106 
107   virtual bool GetVertex(CellFeatureIdentifier, VertexAutoPointer &);
108   virtual bool GetEdge(CellFeatureIdentifier, EdgeAutoPointer &);
109   virtual bool GetFace(CellFeatureIdentifier, FaceAutoPointer &);
110 
111   /** Evaluate the position inside the cell */
112   bool EvaluatePosition(CoordRepType *,
113                                 PointsContainer *,
114                                 CoordRepType *,
115                                 CoordRepType[],
116                                 double *,
117                                 InterpolationWeightType *) override;
118 
119   /** Visitor interface */
120   itkCellVisitMacro(Superclass::HEXAHEDRON_CELL);
121 
122 protected:
123   /** Store the number of points needed for a hexahedron. */
124   PointIdentifier m_PointIds[NumberOfPoints];
125 
126   void
127   InterpolationDerivs( CoordRepType pcoords[Self::CellDimension],
128                        CoordRepType derivs[Self::CellDimension * Self::NumberOfPoints] );
129   void
130   InterpolationFunctions( CoordRepType pcoords[Self::CellDimension], InterpolationWeightType sf[Self::NumberOfPoints] );
131   void
132   EvaluateLocation( int& itkNotUsed( subId ), PointsContainer* points, CoordRepType pcoords[Self::CellDimension],
133                     CoordRepType x[Self::CellDimension], InterpolationWeightType* weights );
134 
135 public:
HexahedronCell()136   HexahedronCell()
137   {
138     for ( unsigned int i = 0; i < Self::NumberOfPoints; i++ )
139       {
140       m_PointIds[i] = NumericTraits< PointIdentifier >::max();
141       }
142   }
143 
144   ~HexahedronCell() override = default;
145 };
146 } // end namespace itk
147 
148 #ifndef ITK_MANUAL_INSTANTIATION
149 #include "itkHexahedronCell.hxx"
150 #endif
151 
152 #endif
153