1 /*---------------------------------------------------------------------------*\
2 * OpenSG NURBS Library *
5 * Copyright (C) 2001-2006 by the University of Bonn, Computer Graphics Group*
7 * http://cg.cs.uni-bonn.de/ *
9 * contact: edhellon@cs.uni-bonn.de, guthe@cs.uni-bonn.de, rk@cs.uni-bonn.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
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. *
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. *
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. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
38 #ifndef _OSG_NurbsPatchSurface_h
39 #define _OSG_NurbsPatchSurface_h
44 #include "OSGDrawableDef.h"
45 #include "OSGConfig.h"
48 #include "OSGBaseTypes.h"
49 #include "OSGVector.h"
52 #include "OSGdctptypes.h"
53 #include "OSGBezierCurve2D.h"
54 #include "OSGBSplineTrimmedSurface.h"
55 #include "OSGDCTPMesh.h"
58 #include "OSGGraphTraverser.h"
59 #include "OSGErrorQuadTree.h" // needed due to arbitrary split -> new tree generation stuff
60 #include "OSGQuadTreeCreator.h" // needed due to quadtree moved back to class variable
61 #include "OSGParSpaceTrimmer.h" // needed due to triangle reduction at trimming curves
65 #define OSG_TIMING_FUNCS
67 static const unsigned char BEZIER_SURFACES_VALID
= 0x01;
68 static const unsigned char QUAD_TREE_VALID
= 0x02;
69 static const unsigned char TRIMMING_VALID
= 0x04;
70 static const unsigned char TRIANGULATION_VALID
= 0x08;
71 static const unsigned char INTERVALS_VALID
= 0x10;
72 static const unsigned char TRIM_SEGS_VALID
= 0x20;
74 static const unsigned char QUAD_TREE_ERROR
= 0x80;
76 static const unsigned char QUAD_TREE_INVALID_MASK
= BEZIER_SURFACES_VALID
| TRIM_SEGS_VALID
;
78 // Activate the OpenSG namespace
87 SCone(void) : clDirection(), dThreshold() {}
95 unsigned char ucStatus
;
96 bezier2ddequevector vvclBezierCurves
;
97 bezier3ddequevector vvcl3DCurves
;
98 std::vector
<std::vector
<Vec2d
> > vvclEdgeLoops
;
99 std::vector
<std::vector
<Vec3d
> > vvclEdgeLoops3D
;
100 // added to comply with ParSpaceTrimmer when using FORCE_NO_T_VERTICES
101 std::vector
<std::vector
<Vec3d
> > vvclEdgeLoopsNorm
;
102 std::vector
<std::vector
<Vec2d
> > vvclEdgeLoopsTex
;
105 CErrorQuadTree
*pclErrorTree
;
106 unsigned int uiTriangleCnt
;
107 std::vector
<bool> vbReversed
;
108 std::vector
<bool> vbUsed
;
110 #ifdef OSG_ARBITRARY_SPLIT
120 vvclBezierCurves ( ),
124 // added to comply with ParSpaceTrimmer when using FORCE_NO_T_VERTICES
125 vvclEdgeLoopsNorm( ),
126 vvclEdgeLoopsTex ( ),
134 #ifdef OSG_ARBITRARY_SPLIT
141 SSurface(const SSurface
&source
):
142 dError (source
.dError
),
143 fMinError (source
.fMinError
),
144 fMaxError (source
.fMaxError
),
145 ucStatus (source
.ucStatus
),
146 vvclBezierCurves (source
.vvclBezierCurves
),
147 vvcl3DCurves (source
.vvcl3DCurves
),
148 vvclEdgeLoops (source
.vvclEdgeLoops
),
149 vvclEdgeLoops3D (source
.vvclEdgeLoops3D
),
150 // added to comply with ParSpaceTrimmer when using FORCE_NO_T_VERTICES
151 vvclEdgeLoopsNorm(source
.vvclEdgeLoopsNorm
),
152 vvclEdgeLoopsTex (source
.vvclEdgeLoopsTex
),
153 clMin (source
.clMin
),
154 clMax (source
.clMax
),
155 pclErrorTree (source
.pclErrorTree
),
156 uiTriangleCnt (source
.uiTriangleCnt
),
157 vbReversed (source
.vbReversed
),
158 vbUsed (source
.vbUsed
),
159 tNormalCone (source
.tNormalCone
),
160 #ifdef OSG_ARBITRARY_SPLIT
161 clMinParam (source
.clMinParam
),
162 clMaxParam (source
.clMaxParam
)
167 SSurface
&operator=(const SSurface
&rhs
)
170 fMinError
= rhs
.fMinError
;
171 fMaxError
= rhs
.fMaxError
;
172 ucStatus
= rhs
.ucStatus
;
173 vvclBezierCurves
= rhs
.vvclBezierCurves
;
174 vvcl3DCurves
= rhs
.vvcl3DCurves
;
175 vvclEdgeLoops
= rhs
.vvclEdgeLoops
;
176 vvclEdgeLoops3D
= rhs
.vvclEdgeLoops3D
;
177 // added to comply with ParSpaceTrimmer when using FORCE_NO_T_VERTICES
178 vvclEdgeLoopsNorm
= rhs
.vvclEdgeLoopsNorm
;
179 vvclEdgeLoopsTex
= rhs
.vvclEdgeLoopsTex
;
182 pclErrorTree
= rhs
.pclErrorTree
;
183 uiTriangleCnt
= rhs
.uiTriangleCnt
;
184 vbReversed
= rhs
.vbReversed
;
186 tNormalCone
= rhs
.tNormalCone
;
187 #ifdef OSG_ARBITRARY_SPLIT
188 clMinParam
= rhs
.clMinParam
;
189 clMaxParam
= rhs
.clMaxParam
;
196 class OSG_DRAWABLE_DLLMAPPING CNurbsPatchSurface
201 CNurbsPatchSurface();
203 ~CNurbsPatchSurface();
206 void AddSurface(BSplineTrimmedSurface
*clSurface
);
208 // set error for given surface patch
209 void SetError(const unsigned int cuiSurface
, double dError
);
212 // return pointer to meshes and recalculate what is needed
213 // std::vector< NodePtr >* GetNodes( std::ofstream &meshout, std::ofstream &rclLinesOut, std::ofstream &rclLinesOut2 );
215 // std::vector< NodePtr >* GetNodes( void );
217 // returns the number of surfaces
218 unsigned int GetSurfaceNumber() const
220 return UInt32( m_vtSurfaces
.size());
223 // returns if node is valid
224 bool IsNodeValid(unsigned int uiNode
) const
226 return (m_vtSurfaces
[uiNode
].ucStatus
& TRIANGULATION_VALID
) ? true : false;
231 void setSurface(BSplineTrimmedSurface
*clSurface
, std::vector
<Pnt2f
> &texturecps
, bool bUseTextures
= false);
233 void setError(double dError
);
234 // get tessellated geometry
235 void getTessellation(std::vector
<Pnt3f
> & gverts
,
236 std::vector
<Vec3f
> & norms
,
237 std::vector
<SimplePolygon
> &tris
,
239 void getTessellation(std::vector
<Pnt3f
> & gverts
,
240 std::vector
<Vec3f
> & norms
,
241 std::vector
<Pnt2f
> & texturecoords
,
242 std::vector
<SimplePolygon
> &tris
,
244 void getTessellation(std::vector
<Pnt3f
> & gverts
,
245 std::vector
<Pnt2f
> & texturecoords
,
246 std::vector
<SimplePolygon
> &tris
,
248 void calculateNormals(std::vector
<Vec3f
> &norms
);
249 void calculatePointsAndNormals(
250 std::vector
<Pnt3f
> & gverts
,
251 std::vector
<SimplePolygon
> &tris
,
252 std::vector
<Vec3f
> & norms
);
253 void calculatePointsNormalsAndTextureCoords(
254 std::vector
<Pnt3f
> & gverts
,
255 std::vector
<SimplePolygon
> &tris
,
256 std::vector
<Vec3f
> & norms
,
257 std::vector
<Pnt2f
> & texturecoords
);
258 void calculatePointsAndTextureCoords(
259 std::vector
<Pnt3f
> & gverts
,
260 std::vector
<SimplePolygon
> &tris
,
261 std::vector
<Pnt2f
> & texturecoords
);
264 // get internal representation (Surface + additional data)
265 inline SSurface
* getSurfaceData()
267 return &m_vtSurfaces
[0];
270 #ifdef OSG_TIMING_FUNCS
271 unsigned int GetTotalTriangleCnt() const
273 return m_uiTotalTriangleCnt
;
275 unsigned int GetNewTriangleCnt() const
277 return m_uiNewTriangleCnt
;
281 void setupErrorTree(double dError
);
283 void clearEdgeloopNormals()
285 m_vtSurfaces
[0].vvclEdgeLoopsNorm
.clear();
290 // convert surface to piecewise bezier form
291 void ConvertToBezier(unsigned int uiSurface
);
293 // set up quad tree with saved error
294 void CalculateQuadTree(unsigned int uiSurface
, bool bForEdges
);
296 // calculate finest trimming curve
297 void CalculateTrimmingLoops(unsigned int uiSurface
);
299 // calculate actual trimming curve
300 void CalculateActualTrimming(unsigned int uiSurface
);
302 // perform graph traversal
303 void CalculateGraph(unsigned int uiSurface
, bool usedelaunay
);
305 // convert points from parameter to object space
306 void ConvertPoints(unsigned int uiSurface
);
307 void convertPoints(std::vector
<Pnt3f
> & gverts
,
308 std::vector
<SimplePolygon
> &tris
);
310 // compute the normalcone (needed for backface culling)
311 void ComputeNormalCone(const unsigned int cuiSurface
,
312 std::vector
<Vec3f
>& normals
);
314 void Gen3DLoops(const unsigned int cuiSurface
);
315 void CutCurve(const unsigned int cuiSurface
, BezierCurve2D
&rclCurve
, bezier2ddeque
&rclCut
, std::vector
<unsigned int> &rvuiUSeg
, std::vector
<unsigned int> &rvuiVSeg
);
317 std::vector
<BSplineTrimmedSurface
> m_vclBSplineSurfaces
;
318 std::vector
<beziersurfacematrix
> m_vvvclBezierSurfaces
;
319 std::vector
<std::vector
<double> > m_vvdUParams
;
320 std::vector
<std::vector
<double> > m_vvdVParams
;
322 std::vector
<SSurface
> m_vtSurfaces
;
323 std::vector
<Vec2d
> m_vclParameterVertices
;
324 std::vector
<Vec3d
> m_vclGlobalVertices
;
325 // std::vector< Vec3d > m_vclNormal;
326 DirectedGraph
<Vec2d
, unsigned char> *m_pclGraph
;
327 simplepolygonvector m_vclTriangles
;
328 QuadTreeCreator
*m_pclQuadTree
;
329 bool m_bErrorTreeValid
;
331 std::vector
<std::vector
<Vec2d
> > m_vvTextureControlPoints
;
333 #ifdef OSG_TIMING_FUNCS
334 unsigned int m_uiTotalTriangleCnt
;
335 unsigned int m_uiNewTriangleCnt
;
338 #ifdef OSG_KEEP_2D_POINTS
339 std::vector
<unsigned int> m_vuiIndex
;
344 CNurbsPatchSurface(const CNurbsPatchSurface
&other
);
345 void operator=(const CNurbsPatchSurface
&rhs
);