fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / NodeCores / Drawables / Nurbs / Internal / OSGParSpaceTrimmer.inl
blob54c8fae758ab3e68e86f8310d79259bb12318084
1 /*---------------------------------------------------------------------------*\
2  *                           OpenSG NURBS Library                            *
3  *                                                                           *
4  *                                                                           *
5  * Copyright (C) 2001-2006 by the University of Bonn, Computer Graphics Group*
6  *                                                                           *
7  *                         http://cg.cs.uni-bonn.de/                         *
8  *                                                                           *
9  * contact: edhellon@cs.uni-bonn.de, guthe@cs.uni-bonn.de, rk@cs.uni-bonn.de *
10  *                                                                           *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13  *                                License                                    *
14  *                                                                           *
15  * This library is free software; you can redistribute it and/or modify it   *
16  * under the terms of the GNU Library General Public License as published    *
17  * by the Free Software Foundation, version 2.                               *
18  *                                                                           *
19  * This library is distributed in the hope that it will be useful, but       *
20  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
22  * Library General Public License for more details.                          *
23  *                                                                           *
24  * You should have received a copy of the GNU Library General Public         *
25  * License along with this library; if not, write to the Free Software       *
26  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
27  *                                                                           *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30  *                                Changes                                    *
31  *                                                                           *
32  *                                                                           *
33  *                                                                           *
34  *                                                                           *
35  *                                                                           *
36  *                                                                           *
37 \*---------------------------------------------------------------------------*/
39 OSG_BEGIN_NAMESPACE
41 inline ParSpaceTrimmerError::ParSpaceTrimmerError(void) : 
42     errtype(0)
46 inline ParSpaceTrimmerError::ParSpaceTrimmerError(int t)
47     : errtype(t)
51 inline ParSpaceTrimmerError::~ParSpaceTrimmerError(void)
56 inline bool SScanLineEventLess::operator() (
57     const SScanLineEvent *ptEvent1, const SScanLineEvent *ptEvent2) const
59     const SScanLineEdge *cui_e1 = ptEvent1->ptEdge;
60     const SScanLineEdge *cui_e2 = ptEvent2->ptEdge;
62 //     std::cerr << cui_e1 << " " << cui_e2 << std::endl;
63     if( ( cui_e1 == cui_e2 ) && ( ptEvent1->bStart == ptEvent2->bStart ) )
64     {
65 //         the same event!
66 //         std::cerr << "same event!" << std::endl;
67 //         std::cerr << ptEvent1->ptEdge << " <-> " << ptEvent2->ptEdge << std::endl;
68 //         std::cerr << ptEvent1->bStart << " <-> " << ptEvent2->bStart << std::endl;
69         return false;
70     }
72     /*
73     if( osgAbs( ptEvent1->clPos[1] - ptEvent2->clPos[1] ) > 1e-15 )
74     {
75         return ptEvent1->clPos[1] < ptEvent2->clPos[1];
76     }
77     else
78     {
79         if( osgAbs( ptEvent1->clPos[0] - ptEvent2->clPos[0] ) > 1e-15 )
80         {
81             return ptEvent1->clPos[0] < ptEvent2->clPos[0];
82         }
83     }*/
84     if(DCTPVecIsNotEqual(ptEvent1->clPos, ptEvent2->clPos) )
85     {
86 //         return ( ptEvent1->clPos < ptEvent2->clPos );
87         return ( DCTPVecIsLesser(ptEvent1->clPos, ptEvent2->clPos) );
88     }
90     if( ( ptEvent1->bStart ) && !( ptEvent2->bStart ) )
91         return false;
92     if(!( ptEvent1->bStart ) && ( ptEvent2->bStart ) )
93         return true;
95 //     std::cerr << "start = " << ptEvent1->bStart << " " << ptEvent2->bStart;
96 //     std::cerr << " checking dirs..." << std::endl;
98     Vec2d dir1, dir2;
100     dir1 = ptEvent1->clOther - ptEvent1->clPos;
101     dir2 = ptEvent2->clOther - ptEvent2->clPos;
102     if(DCTPVecIsNotEqual(dir1, dir2) )
103     {
104         if(!ptEvent1->bStart)
105         {
106             dir1[1] = -dir1[1];
107             dir2[1] = -dir2[1];
108         }
110         if(osgAbs(dir1[1]) < DCTP_EPS)
111         {
112             if(osgAbs(dir2[1]) < DCTP_EPS)
113             {
114                 if(dir1[0] < 0.0)   // this can't be zero!
115                 {
116                     if(dir2[0] > 0.0)
117                         return true;                  // this can't be zero!
118                 }
119                 else
120                 {
121                     if(dir2[0] < 0.0)
122                         return false;                 // this can't be zero!
123                 }
124 //             return ( dir1[0] < dir2[0] );
125             }
126             else
127             {
128 //             std::cerr << "( dir1[0] < 0.0 )" << dir1[0];
129                 return ( dir1[0] < 0.0 ); // this can't be zero!
130             }
131         }
132         else if(osgAbs(dir2[1]) < DCTP_EPS)
133         {
134 //         std::cerr << "( dir2[0] > 0.0 )" << dir2[0];
135             return ( dir2[0] > 0.0 ); // this can't be zero!
136         }
137         else
138         {
139             const double r1 = dir1[0] / dir1[1];
140             const double r2 = dir2[0] / dir2[1];
142             if(osgAbs(r1 - r2) >= DCTP_EPS)
143             {
144                 return ( r1 < r2 );
145             }
146         }
147     }
149 //     this can only be false for both ways, if it is the same edge!
150     return( cui_e1 < cui_e2 );
155 inline bool SPolySimVertexLess::operator() (
156     const SPolySimVertex *ptVertex1, const SPolySimVertex *ptVertex2) const
158     if(ptVertex2->dSimplifyError - ptVertex1->dSimplifyError > 1e-20)
159         return true;
160     if(ptVertex1->dSimplifyError - ptVertex2->dSimplifyError > 1e-20)
161         return false;
162     return ( ptVertex1->uiIndex < ptVertex2->uiIndex );
166 inline ParSpaceTrimmer::ParSpaceTrimmer(void) :
167     mesh(NULL),
168     tcs(NULL),         //trimming curves
169     tcs3d(NULL),       // 3d trimming curves
170     terr(0),        // trimming error (used for 3d loops only!)
171     state(),
172     start_face(NULL),  //the face in which the curve starts (if it starts OVER_FACE)
173     ie(NULL),          //last intersected edge
174     ip(0.0),          //intersection parameter on bezier curve
175     vcel(),
176     pvccrd(NULL),
177     m_pvvclSewed(NULL),
178 #ifdef OSG_FORCE_NO_T_VERTICES
179 /* #ifndef OSG_CREATE_NORMAL_MAPS
180         std::vector< std::vector< Vec3d > >             *m_pvvclNormals;
181  #endif*/
182  #ifdef OSG_KEEP_2D_POINTS
183     m_uiPosCnt(0),
184  #endif
185 #endif
186     m_bDeleteVertexInfo(false),
187     m_clMin(),
188     m_clMax(),
189 #ifdef OSG_ADAPTIVE_QUAD_TREE
190     m_pclQuadTree(NULL),
191 #endif
192     m_pvbReversed(NULL),
193     m_pvbUsed(NULL),
195 #ifdef OSG_USE_SIMPLIFIER
196     m_pclNurbs(NULL)
197 #endif
199 //     std::cerr << "pst constr" << std::endl;
202 inline ParSpaceTrimmer::~ParSpaceTrimmer(void)
204 //     std::cerr << "pst destr" << std::endl;
205     if(m_bDeleteVertexInfo)
206         deleteVertexInfo();
209 OSG_END_NAMESPACE