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