ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkQuadEdge.h
Go to the documentation of this file.
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 itkQuadEdge_h
19 #define itkQuadEdge_h
20 
22 #include "ITKQuadEdgeMeshExport.h"
23 
24 #include "itkMacro.h"
25 
26 // Debugging macros for classes that do not derive from the itkObject.
27 // FIXME: Maybe variations of these macros should be moved into
28 // itkMacro.h
29 //
30 #define itkQEDebugMacro(x) \
31  { \
32  std::ostringstream itkmsg; \
33  itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
34  << " (" << this << "): " x \
35  << "\n\n"; \
36  OutputWindowDisplayDebugText( itkmsg.str().c_str() ); \
37  }
38 #define itkQEWarningMacro(x) \
39  { \
40  std::ostringstream itkmsg; \
41  itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
42  << " (" << this << "): " x \
43  << "\n\n"; \
44  OutputWindowDisplayWarningText( itkmsg.str().c_str() ); \
45  }
46 
47 // -------------------------------------------------------------------------
57 #define itkQEAccessorsMacro(st, pt, dt) \
58  pt * GetOnext() \
59  { \
60  return ( dynamic_cast< pt * >( this->st::GetOnext() ) ); \
61  } \
62  \
63  dt *GetRot() \
64  { \
65  return ( dynamic_cast< dt * >( this->st::GetRot() ) ); \
66  } \
67  \
68  pt *GetSym() \
69  { \
70  return ( dynamic_cast< pt * >( this->st::GetSym() ) ); \
71  } \
72  \
73  pt *GetLnext() \
74  { \
75  return ( dynamic_cast< pt * >( this->st::GetLnext() ) ); \
76  } \
77  \
78  pt *GetRnext() \
79  { \
80  return ( dynamic_cast< pt * >( this->st::GetRnext() ) ); \
81  } \
82  \
83  pt *GetDnext() \
84  { \
85  return ( dynamic_cast< pt * >( this->st::GetDnext() ) ); \
86  } \
87  \
88  pt *GetOprev() \
89  { \
90  return ( dynamic_cast< pt * >( this->st::GetOprev() ) ); \
91  } \
92  \
93  pt *GetLprev() \
94  { \
95  return ( dynamic_cast< pt * >( this->st::GetLprev() ) ); \
96  } \
97  \
98  pt *GetRprev() \
99  { \
100  return ( dynamic_cast< pt * >( this->st::GetRprev() ) ); \
101  } \
102  \
103  pt *GetDprev() \
104  { \
105  return ( dynamic_cast< pt * >( this->st::GetDprev() ) ); \
106  } \
107  \
108  dt *GetInvRot() \
109  { \
110  return ( dynamic_cast< dt * >( this->st::GetInvRot() ) ); \
111  } \
112  \
113  pt *GetInvOnext() \
114  { \
115  return ( dynamic_cast< pt * >( this->st::GetInvOnext() ) ); \
116  } \
117  \
118  pt *GetInvLnext() \
119  { \
120  return ( dynamic_cast< pt * >( this->st::GetInvLnext() ) ); \
121  } \
122  \
123  pt *GetInvRnext() \
124  { \
125  return ( dynamic_cast< pt * >( this->st::GetInvRnext() ) ); \
126  } \
127  \
128  pt *GetInvDnext() \
129  { \
130  return ( dynamic_cast< pt * >( this->st::GetInvDnext() ) ); \
131  } \
132  const pt *GetOnext() const \
133  { \
134  return ( dynamic_cast< const pt * >( this->st::GetOnext() ) ); \
135  } \
136  \
137  const dt *GetRot() const \
138  { \
139  return ( dynamic_cast< const dt * >( this->st::GetRot() ) ); \
140  } \
141  \
142  const pt *GetSym() const \
143  { \
144  return ( dynamic_cast< const pt * >( this->st::GetSym() ) ); \
145  } \
146  \
147  const pt *GetLnext() const \
148  { \
149  return ( dynamic_cast< const pt * >( this->st::GetLnext() ) ); \
150  } \
151  \
152  const pt *GetRnext() const \
153  { \
154  return ( dynamic_cast< const pt * >( this->st::GetRnext() ) ); \
155  } \
156  \
157  const pt *GetDnext() const \
158  { \
159  return ( dynamic_cast< const pt * >( this->st::GetDnext() ) ); \
160  } \
161  \
162  const pt *GetOprev() const \
163  { \
164  return ( dynamic_cast< const pt * >( this->st::GetOprev() ) ); \
165  } \
166  \
167  const pt *GetLprev() const \
168  { \
169  return ( dynamic_cast< const pt * >( this->st::GetLprev() ) ); \
170  } \
171  \
172  const pt *GetRprev() const \
173  { \
174  return ( dynamic_cast< const pt * >( this->st::GetRprev() ) ); \
175  } \
176  \
177  const pt *GetDprev() const \
178  { \
179  return ( dynamic_cast< const pt * >( this->st::GetDprev() ) ); \
180  } \
181  \
182  const dt *GetInvRot() const \
183  { \
184  return ( dynamic_cast< const dt * >( this->st::GetInvRot() ) ); \
185  } \
186  \
187  const pt *GetInvOnext() const \
188  { \
189  return ( dynamic_cast< const pt * >( this->st::GetInvOnext() ) ); \
190  } \
191  \
192  const pt *GetInvLnext() const \
193  { \
194  return ( dynamic_cast< const pt * >( this->st::GetInvLnext() ) ); \
195  } \
196  \
197  const pt *GetInvRnext() const \
198  { \
199  return ( dynamic_cast< const pt * >( this->st::GetInvRnext() ) ); \
200  } \
201  \
202  const pt *GetInvDnext() const \
203  { \
204  return ( dynamic_cast< const pt * >( this->st::GetInvDnext() ) ); \
205  }
206 
207 
208 namespace itk
209 {
225 class ITKQuadEdgeMesh_EXPORT QuadEdge
226 {
227 public:
229  typedef QuadEdge Self;
230 
234 
236  inline itkQEDefineIteratorMethodsMacro(Onext);
237  // itkQEDefineIteratorMethodsMacro( Sym );
238  // itkQEDefineIteratorMethodsMacro( Lnext );
239  // itkQEDefineIteratorMethodsMacro( Rnext );
240  // itkQEDefineIteratorMethodsMacro( Dnext );
241  // itkQEDefineIteratorMethodsMacro( Oprev );
242  // itkQEDefineIteratorMethodsMacro( Lprev );
243  // itkQEDefineIteratorMethodsMacro( Rprev );
244  // itkQEDefineIteratorMethodsMacro( Dprev );
245  // itkQEDefineIteratorMethodsMacro( InvOnext );
246  // itkQEDefineIteratorMethodsMacro( InvLnext );
247  // itkQEDefineIteratorMethodsMacro( InvRnext );
248  // itkQEDefineIteratorMethodsMacro( InvDnext );
250 
252  QuadEdge();
253  virtual ~QuadEdge();
255 
257  inline void SetOnext(Self *onext) { this->m_Onext = onext; }
258  inline void SetRot(Self *rot) { this->m_Rot = rot; }
260 
264  inline Self * GetOnext() { return this->m_Onext; }
265  inline Self * GetRot() { return this->m_Rot; }
266  inline const Self * GetOnext() const { return this->m_Onext; }
267  inline const Self * GetRot() const { return this->m_Rot; }
269 
286 // TODO fix this ref
287 // * \sa \ref DoxySurgeryConnectivity
288  inline void Splice(Self *b)
289  {
290  Self *aNext = this->GetOnext();
291  Self *bNext = b->GetOnext();
292  Self *alpha = aNext->GetRot();
293  Self *beta = bNext->GetRot();
294  Self *alphaNext = alpha->GetOnext();
295  Self *betaNext = beta->GetOnext();
297 
298  this->SetOnext(bNext);
299  b->SetOnext(aNext);
300  alpha->SetOnext(betaNext);
301  beta->SetOnext(alphaNext);
302  }
303 
304  // Second order accessors.
305 
308  inline Self * GetSym()
309  {
310  if ( this->m_Rot )
311  {
312  return ( this->m_Rot->m_Rot );
313  }
314  return ( this->m_Rot );
315  }
317 
318  inline const Self * GetSym() const
319  {
320  if ( this->m_Rot )
321  {
322  return ( this->m_Rot->m_Rot );
323  }
324  return ( this->m_Rot );
325  }
326 
329  Self * GetLnext();
330 
331  const Self * GetLnext() const;
332 
336  Self * GetRnext();
337 
338  const Self * GetRnext() const;
339 
343  Self * GetDnext();
344 
345  const Self * GetDnext() const;
346 
349  Self * GetOprev();
350 
351  const Self * GetOprev() const;
352 
356  Self * GetLprev();
357 
358  const Self * GetLprev() const;
359 
363  Self * GetRprev();
364 
365  const Self * GetRprev() const;
366 
370  Self * GetDprev();
371 
372  const Self * GetDprev() const;
373 
375  inline Self * GetInvRot()
376  {
377 #ifdef NDEBUG
378  return ( this->GetRot()->GetRot()->GetRot() );
379 #else
380  Self *p1 = this->GetRot();
381  if ( !p1 ) { return ITK_NULLPTR; }
382  Self *p2 = p1->GetRot();
383  if ( !p2 ) { return ITK_NULLPTR; }
384  Self *p3 = p2->GetRot();
385  if ( !p3 ) { return ITK_NULLPTR; }
386  return p3;
387 #endif
388  }
390 
391  inline Self * GetInvOnext() { return this->GetOprev(); }
392  inline Self * GetInvLnext() { return this->GetLprev(); }
393  inline Self * GetInvRnext() { return this->GetRprev(); }
394  inline Self * GetInvDnext() { return this->GetDprev(); }
395  inline const Self * GetInvRot() const
396  {
397 #ifdef NDEBUG
398  return ( this->GetRot()->GetRot()->GetRot() );
399 #else
400  const Self *p1 = this->GetRot();
401  if ( !p1 ) { return ITK_NULLPTR; }
402  const Self *p2 = p1->GetRot();
403  if ( !p2 ) { return ITK_NULLPTR; }
404  const Self *p3 = p2->GetRot();
405  if ( !p3 ) { return ITK_NULLPTR; }
406  return p3;
407 #endif
408  }
409 
410  inline const Self * GetInvOnext() const { return this->GetOprev(); }
411  inline const Self * GetInvLnext() const { return this->GetLprev(); }
412  inline const Self * GetInvRnext() const { return this->GetRprev(); }
413  inline const Self * GetInvDnext() const { return this->GetDprev(); }
414 
416  inline bool IsHalfEdge() const { return ( ( m_Onext == this ) || ( m_Rot == ITK_NULLPTR ) ); }
417  inline bool IsIsolated() const { return ( this == this->GetOnext() ); }
418  bool IsEdgeInOnextRing(Self *testEdge) const;
420 
421  bool IsLnextGivenSizeCyclic(const int size) const;
422 
423  unsigned int GetOrder() const;
424 
425 private:
429 };
430 }
431 
432 #endif
Self * GetInvRot()
Definition: itkQuadEdge.h:375
bool IsHalfEdge() const
Definition: itkQuadEdge.h:416
const Self * GetInvOnext() const
Definition: itkQuadEdge.h:410
QuadEdge Self
Definition: itkQuadEdge.h:229
const Self * GetSym() const
Definition: itkQuadEdge.h:318
Self * GetSym()
Definition: itkQuadEdge.h:308
void SetRot(Self *rot)
Definition: itkQuadEdge.h:258
const Self * GetOnext() const
Definition: itkQuadEdge.h:266
Base class for the implementation of a quad-edge data structure as proposed in &quot;Guibas and Stolfi 198...
Definition: itkQuadEdge.h:225
Self * GetInvOnext()
Definition: itkQuadEdge.h:391
const Self * GetInvRnext() const
Definition: itkQuadEdge.h:412
QuadEdgeMeshIterator< Self > Iterator
Definition: itkQuadEdge.h:232
Self * GetOnext()
Definition: itkQuadEdge.h:264
void SetOnext(Self *onext)
Definition: itkQuadEdge.h:257
Non const iterator for QuadMesh.
Self * GetInvRnext()
Definition: itkQuadEdge.h:393
QuadEdgeMeshConstIterator< Self > ConstIterator
Definition: itkQuadEdge.h:233
#define itkQEDefineIteratorMethodsMacro(Op)
const Self * GetRot() const
Definition: itkQuadEdge.h:267
const Self * GetInvRot() const
Definition: itkQuadEdge.h:395
const Self * GetInvLnext() const
Definition: itkQuadEdge.h:411
Self * GetRot()
Definition: itkQuadEdge.h:265
Self * GetInvDnext()
Definition: itkQuadEdge.h:394
Const iterator for QuadEdgeMesh.
Self * GetInvLnext()
Definition: itkQuadEdge.h:392
bool IsIsolated() const
Definition: itkQuadEdge.h:417
void Splice(Self *b)
Basic quad-edge topological method.
Definition: itkQuadEdge.h:288
const Self * GetInvDnext() const
Definition: itkQuadEdge.h:413