]> Creatis software - cpMesh.git/blob - lib/cpm/Algorithms/QuadEdge/MeshZipFunction.hxx
First commit
[cpMesh.git] / lib / cpm / Algorithms / QuadEdge / MeshZipFunction.hxx
1 #ifndef __CPM__ALGORITHMS__QUADEDGE__MESHZIPFUNCTION__HXX__
2 #define __CPM__ALGORITHMS__QUADEDGE__MESHZIPFUNCTION__HXX__
3
4 // -------------------------------------------------------------------------
5 template< class M >
6 typename cpm::Algorithms::QuadEdge::MeshZipFunction< M >::
7 TOutput cpm::Algorithms::QuadEdge::MeshZipFunction< M >::
8 Evaluate( const TInput& e )
9 {
10   if( !this->m_Mesh )
11   {
12     itkDebugMacro( "No mesh present" );
13     return( TEdge::NoGeometry );
14
15   } // fi
16
17   if( e->IsLeftSet( ) )
18   {
19     itkDebugMacro( "Incoming edge must be adjacent to NOFACE" );
20     return( TEdge::NoGeometry );
21
22   } // fi
23
24   //     Initial state                          Final state        //
25   //                                                               //
26   //   |               |                         \       /         //
27   //   |               |                          \     /          //
28   //   |               |                           \   /           //
29   //   |               |                            \ /            //
30   //   VTrashed      Vkept                           V             //
31   //    \             /                              |             //
32   //     \           /                               |             //
33   //      \         ^                                |             //
34   //       \       /                                 |             //
35   //        \     e                                  |             //
36   //         \   /                                   |             //
37   //          \ /                                    |             //
38   //  ------- Org --------                --------- Org ---------  //
39   //         / | \                                 / | \           //
40   //        /  |  \                               /  |  \          //
41   //       /   |   \                             /   |   \         //
42   //
43   // This is the original situation:
44   //
45   //         \                        /                            //
46   //          \                      ^                             //
47   //           \                    a                              //
48   //            \                  /                               //
49   //    ------ VRite            VLeft --------                     //
50   //            / \             / \                                //
51   //           /   \           /   \                               //
52   //          /     b         ^     \                              //
53   //         /       \       /       \                             //
54   //        /         v     e   Rite  \                            //
55   //       /           \   /    Face   \                           //
56   //      /             \ /             \                          //
57   //     V ------------ Org ------------ VOpposite                 //
58   //                   / | \                                       //
59   //                  /  |  \                                      //
60   //
61   // Store for latter usage (since e and e->GetRight( ) will be deleted):
62   TEdge* a = e->GetLnext( );
63   TEdge* b = e->GetOnext( )->GetSym( );
64   TOutput VLeft = e->GetDestination( );
65   TOutput VRight = b->GetOrigin( );
66   bool wasFacePresent = e->IsRightSet( );
67   TOutput resultingPointId = TEdge::NoGeometry;
68
69   // We should be cautious and consider the case when the very
70   // initial situation was the following:
71   //                                                       //
72   //                   *                                   //
73   //        *                     *                        //
74   //                                                       //
75   //             VRight = VLeft                             //
76   //                  / \                                  //
77   //                 /   \                                 //
78   //                /     \                                //
79   //       *        |  *  |        *                       //
80   //                \     /                                //
81   //                 \   /                                 //
82   //                  \ /                                  //
83   //        --------- Org ---------                        //
84   //                 / | \                                 //
85   //                /  |  \                                //
86   //               /   |   \                               //
87   if( VRight == VLeft )
88   {
89     if( e->IsWire( ) && b->IsWire( ) )
90     {
91       /* TODO
92          this->m_Mesh->LightWeightDeleteEdge(e);
93          this->m_Mesh->LightWeightDeleteEdge(b);
94       */
95       return( resultingPointId );
96
97     } // fi
98
99   } // fi
100
101   // Delete the Edge e and it's right face:
102   /* TODO:
103      if( wasFacePresent )
104      this->m_Mesh->DeleteFace( e->GetRight( ) );
105      this->m_Mesh->LightWeightDeleteEdge(e);
106   */
107
108   // We should be cautious and consider the case when the very
109   // initial situation was the following:
110   //               \       /                               //
111   //                \     /                                //
112   //                 \   /                                 //
113   //                  \ /                                  //
114   //            VRight = VLeft ------- VOpposite           //
115   //                  / \            _/                    //
116   //                 /   \         _/                      //
117   //                /     \   *  _/                        //
118   //                |     |    _/                          //
119   //                \     /  _/                            //
120   //                 \   / _/                              //
121   //                  \ /_/                                //
122   //        --------- Org ---------                        //
123   //                 / | \                                 //
124   //                /  |  \                                //
125   //               /   |   \                               //
126   //
127   // in which case the current situation is the following:
128   //
129   //               \       /                               //
130   //                \     /                                //
131   //                 \   /                                 //
132   //                  \ /                                  //
133   //            VRight = VLeft ------- VOpposite           //
134   //                  /              _/                    //
135   //                 /             _/                      //
136   //                /            _/                        //
137   //                |          _/                          //
138   //                \        _/                            //
139   //                 \     _/                              //
140   //                  \  _/                                //
141   //        --------- Org ---------                        //
142   //                 / | \                                 //
143   //                /  |  \                                //
144   //               /   |   \                               //
145   //
146   // and hence the connectivity part of "Zip" job is already done.
147   // Check for that case:
148   //
149   if( VLeft != VRight )
150   {
151     // We are now left with the following situation
152     //
153     //         \                        /                  //
154     //          \                      ^                   //
155     //           \                    a                    //
156     //            \                  /                     //
157     //   ----- VRight              VLeft --------          //
158     //            / \               \                      //
159     //           /   \               \                     //
160     //          /     b               \                    //
161     //         /       \               \                   //
162     //        /         v               \                  //
163     //       /           \               \                 //
164     //      /             \               \                //
165     //     V ------------ Org ------------ VOpposite       //
166     //                   / | \                             //
167     //                  /  |  \                            //
168     //
169     // where we just miss a simple Mesh::Splice( ) to obtain::
170     //
171     //          \     /                                    //
172     //           \   /                                     //
173     //            \ /                                      //
174     // ---- VRight = VLeft ------ VOpposite                //
175     //            / \             /                        //
176     //           /   \           /                         //
177     //          /     b         /                          //
178     //         /       \       /                           //
179     //        /         v     /                            //
180     //       /           \   /                             //
181     //      /             \ /                              //
182     //     V ------------ Org ------------                 //
183     //                   / | \                             //
184     //                  /  |  \                            //
185     //
186     // TODO: resultingPointId = this->m_Mesh->Splice(a, b);
187
188   } // fi
189
190   // We restore the deleted face (when it was present):
191   /* TODO:
192      if( wasFacePresent )
193      this->m_Mesh->AddFace(b);
194   */
195   this->m_Mesh->Modified( );
196   return( resultingPointId );
197 }
198
199 // -------------------------------------------------------------------------
200 template< class M >
201 cpm::Algorithms::QuadEdge::MeshZipFunction< M >::
202 MeshZipFunction( )
203   : Superclass( )
204 {
205 }
206
207 // -------------------------------------------------------------------------
208 template< class M >
209 cpm::Algorithms::QuadEdge::MeshZipFunction< M >::
210 ~MeshZipFunction( )
211 {
212 }
213
214 #endif // __CPM__ALGORITHMS__QUADEDGE__MESHZIPFUNCTION__HXX__
215
216 // eof - $RCSfile$