NonSelfIntersectionConstraint.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2013-2015 Imperial College London
5  * Copyright 2013-2015 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_NonSelfIntersectionConstraint_H
21 #define MIRTK_NonSelfIntersectionConstraint_H
22 
23 #include "mirtk/SurfaceConstraint.h"
24 #include "mirtk/SurfaceCollisions.h"
25 
26 #include "vtkSmartPointer.h"
27 #include "vtkPolyData.h"
28 #include "vtkDataArray.h"
29 
30 
31 namespace mirtk {
32 
33 
34 /**
35  * Non-self intersecting surface forces
36  *
37  * This internal force makes nearby non-adjacent faces to repel each other
38  * in order to avoid self-intersection of the surface.
39  *
40  * Park et al., A non-self-intersecting adaptive deformable surface for
41  * complex boundary extraction from volumetric images, 25, 421–440 (2001).
42  */
44 {
46 
47  // ---------------------------------------------------------------------------
48  // Attributes
49 
50 protected:
51 
52  /// Use fast approximate surface triangle collision test
53  mirtkPublicAttributeMacro(bool, FastCollisionTest);
54 
55  /// Minimum distance
56  /// Set to non-positive value to use average edge length.
57  mirtkPublicAttributeMacro(double, MinDistance);
58 
59  /// Maximum angle between face normal and center to closest point vector
60  /// required for collision to be detected
61  mirtkPublicAttributeMacro(double, MaxAngle);
62 
63  /// Detected surface collisions
64  mirtkAttributeMacro(SurfaceCollisions::CollisionsArray, Collisions);
65 
66  /// Number of found surface collisions
67  mirtkReadOnlyAttributeMacro(int, NumberOfCollisions);
68 
69  /// Copy attributes of this class from another instance
71 
72  // ---------------------------------------------------------------------------
73  // Construction/Destruction
74 
75 public:
76 
77  /// Constructor
78  NonSelfIntersectionConstraint(const char * = "", double = 1.0);
79 
80  /// Copy constructor
82 
83  /// Assignment operator
85 
86  /// Destructor
88 
89  // ---------------------------------------------------------------------------
90  // Configuration
91 
92 protected:
93 
94  /// Set parameter value from string
95  virtual bool SetWithoutPrefix(const char *, const char *);
96 
97 public:
98 
99  // Import other overloads
101 
102  /// Get parameter name/value pairs
103  virtual ParameterList Parameter() const;
104 
105  // ---------------------------------------------------------------------------
106  // Evaluation
107 
108  /// Initialize internal force term once input and parameters have been set
109  virtual void Initialize();
110 
111  /// Reinitialize internal force term after change of input topology
112  virtual void Reinitialize();
113 
114  /// Update internal state upon change of input
115  virtual void Update(bool = true);
116 
117 protected:
118 
119  /// Common (re-)initialization steps of this class (non-virtual function!)
120  void Init();
121 
122  /// Compute penalty for current transformation estimate
123  virtual double Evaluate();
124 
125  /// Compute internal force w.r.t. transformation parameters
126  virtual void EvaluateGradient(double *, double, double);
127 
128  // ---------------------------------------------------------------------------
129  // Debugging
130 public:
131 
132  /// Write input of force term
133  virtual void WriteDataSets(const char *, const char *, bool = true) const;
134 
135 };
136 
137 
138 } // namespace mirtk
139 
140 #endif // MIRTK_NonSelfIntersectionConstraint_H
virtual void Reinitialize()
Reinitialize internal force term after change of input topology.
virtual ~NonSelfIntersectionConstraint()
Destructor.
mirtkPublicAttributeMacro(bool, FastCollisionTest)
Use fast approximate surface triangle collision test.
virtual void Initialize()
Initialize internal force term once input and parameters have been set.
virtual double Evaluate()
Compute penalty for current transformation estimate.
Array< Pair< string, string > > ParameterList
Ordered list of parameter name/value pairs.
Definition: Object.h:38
Repels too close non-neighboring triangles.
Definition: EnergyMeasure.h:87
mirtkAttributeMacro(SurfaceCollisions::CollisionsArray, Collisions)
Detected surface collisions.
Definition: IOConfig.h:41
virtual void Update(bool=true)
Update internal state upon change of input.
virtual bool SetWithoutPrefix(const char *, const char *)
Set parameter value from string.
void Init()
Common (re-)initialization steps of this class (non-virtual function!)
virtual ParameterList Parameter() const
Get parameter name/value pairs.
virtual void WriteDataSets(const char *, const char *, bool=true) const
Write input of force term.
void CopyAttributes(const NonSelfIntersectionConstraint &)
Copy attributes of this class from another instance.
mirtkReadOnlyAttributeMacro(int, NumberOfCollisions)
Number of found surface collisions.
virtual ParameterList Parameter() const
Get parameter key/value as string map.
NonSelfIntersectionConstraint & operator=(const NonSelfIntersectionConstraint &)
Assignment operator.
virtual void EvaluateGradient(double *, double, double)
Compute internal force w.r.t. transformation parameters.
NonSelfIntersectionConstraint(const char *="", double=1.0)
Constructor.