SurfaceMapper.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2016 Imperial College London
5  * Copyright 2016 Andreas Schuh
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 #ifndef MIRTK_SurfaceMapper_H
21 #define MIRTK_SurfaceMapper_H
22 
23 #include "mirtk/Object.h"
24 
25 #include "mirtk/Memory.h"
26 #include "mirtk/Point.h"
27 
28 #include "mirtk/EdgeTable.h"
29 #include "mirtk/SurfaceBoundary.h"
30 #include "mirtk/Mapping.h"
31 
32 #include "vtkSmartPointer.h"
33 #include "vtkPolyData.h"
34 
35 
36 namespace mirtk {
37 
38 
39 /**
40  * Base class of solvers for the computation of a surface map
41  *
42  * Solvers of this type compute a map value for each point on the surface
43  * of the input mesh embedded in 3D Euclidean space. The properties of the
44  * output map depend on the boundary conditions and the specific solver used to
45  * compute the surface map. Examples of surface maps are the assignment of 2D
46  * texture coordinates and a bijective mapping of a surface mesh to a disk,
47  * square, or sphere, respectively.
48  */
49 class SurfaceMapper : public Object
50 {
51  mirtkAbstractMacro(SurfaceMapper);
52 
53  // ---------------------------------------------------------------------------
54  // Attributes
55 
56  /// Polygonal representation of surface map domain
57  mirtkPublicAttributeMacro(vtkSmartPointer<vtkPolyData>, Surface);
58 
59  /// Pre-computed edge table of surface mesh
60  mirtkPublicAttributeMacro(SharedPtr<mirtk::EdgeTable>, EdgeTable);
61 
62  /// Extracted surface mesh boundary
63  mirtkPublicAttributeMacro(SharedPtr<SurfaceBoundary>, Boundary);
64 
65  /// Output surface map
66  ///
67  /// \note The output map is uninitialized! Mapping::Initialize must be
68  /// called before this map can be evaluated at map domain points.
69  mirtkReadOnlyAttributeMacro(SharedPtr<Mapping>, Output);
70 
71  /// Copy attributes of this class from another instance
72  void CopyAttributes(const SurfaceMapper &);
73 
74  // ---------------------------------------------------------------------------
75  // Construction/Destruction
76 
77 protected:
78 
79  /// Default constructor
80  SurfaceMapper();
81 
82  /// Copy constructor
84 
85  /// Assignment operator
87 
88 public:
89 
90  /// Destructor
91  virtual ~SurfaceMapper();
92 
93  // ---------------------------------------------------------------------------
94  // Execution
95 
96  /// Compute surface map
97  void Run();
98 
99 protected:
100 
101  /// Initialize filter after input and parameters are set
102  virtual void Initialize();
103 
104  /// Compute surface map
105  virtual void ComputeMap() = 0;
106 
107  /// Finalize filter execution
108  virtual void Finalize();
109 
110  // ---------------------------------------------------------------------------
111  // Auxiliaries
112 
113 protected:
114 
115  /// Number of surface points
116  int NumberOfPoints() const;
117 
118  /// Number of surface points minus the number of boundary points
119  int NumberOfInteriorPoints() const;
120 
121  /// Get surface point coordinates
122  ///
123  /// \param[in] ptId Surface point ID.
124  /// \param[out] p Point coordinates.
125  void GetPoint(int ptId, double p[3]) const;
126 
127  /// Get surface point coordinates
128  ///
129  /// \param[in] ptId Surface point ID.
130  ///
131  /// \returns Point point.
132  class Point Point(int ptId) const;
133 
134  /// Get IDs of surface points belong to the two triangles sharing an edge
135  ///
136  /// \param[in] i Edge start point.
137  /// \param[in] j Edge end point.
138  /// \param[out] k Other point of first adjacent triangle.
139  /// \param[out] l Other point of second adjacent triangle. When the edge is
140  /// on the surface boundary and therefore has only as single
141  /// adjacent triangle, -1 is returned.
142  ///
143  /// \returns Number of cells adjacent to the specified edge. When the surface
144  /// mesh is triangulated, the return value is 1 for a boundary edge,
145  /// and 2 for an interior edge.
146  int GetEdgeNeighborPoints(int i, int j, int &k, int &l) const;
147 };
148 
149 ////////////////////////////////////////////////////////////////////////////////
150 // Inline definitions
151 ////////////////////////////////////////////////////////////////////////////////
152 
153 // =============================================================================
154 // Auxiliaries
155 // =============================================================================
156 
157 // -----------------------------------------------------------------------------
159 {
160  return static_cast<int>(_Surface->GetNumberOfPoints());
161 }
162 
163 // -----------------------------------------------------------------------------
165 {
166  return NumberOfPoints() - _Boundary->NumberOfPoints();
167 }
168 
169 // -----------------------------------------------------------------------------
170 inline void SurfaceMapper::GetPoint(int ptId, double p[3]) const
171 {
172  _Surface->GetPoint(static_cast<vtkIdType>(ptId), p);
173 }
174 
175 // -----------------------------------------------------------------------------
176 inline Point SurfaceMapper::Point(int ptId) const
177 {
178  double p[3];
179  GetPoint(ptId, p);
180  return p;
181 }
182 
183 
184 } // namespace mirtk
185 
186 #endif // MIRTK_SurfaceMapper_H
int NumberOfPoints() const
Number of surface points.
SurfaceMapper()
Default constructor.
virtual void ComputeMap()=0
Compute surface map.
virtual void Finalize()
Finalize filter execution.
int GetEdgeNeighborPoints(int i, int j, int &k, int &l) const
int NumberOfInteriorPoints() const
Number of surface points minus the number of boundary points.
Definition: IOConfig.h:41
virtual void Initialize()
Initialize filter after input and parameters are set.
void GetPoint(int ptId, double p[3]) const
class Point Point(int ptId) const
SurfaceMapper & operator=(const SurfaceMapper &)
Assignment operator.
void Run()
Compute surface map.
virtual ~SurfaceMapper()
Destructor.