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_ErrorQuadTree_h
39 #define _OSG_ErrorQuadTree_h
44 #include "OSGDrawableDef.h"
45 #include "OSGConfig.h"
47 #include "OSGdctptypes.h"
52 class BezierTensorSurface
;
53 class BSplineTensorSurface
;
56 #define OSG_DIFF_TO_BILIN
57 #define OSG_ONE_CHILD_PTR
58 #define OSG_USE_NURBS_PATCH
59 //#define OSG_CONSERVATIVE_ERROR
60 #define OSG_USE_KD_TREE
61 #define OSG_ARBITRARY_SPLIT
63 #ifdef OSG_ARBITRARY_SPLIT
64 #ifndef OSG_USE_KD_TREE
65 #define OSG_USE_KD_TREE
72 #ifdef OSG_ONE_CHILD_PTR
73 SErrorTreeCell
*ptChildren
; // nw, ne, sw, se
75 #ifdef OSG_USE_KD_TREE
76 SErrorTreeCell
*aptChildren
[2]; // n/w, s/e
78 SErrorTreeCell
*aptChildren
[4]; // nw, ne, sw, se
81 #ifdef OSG_USE_KD_TREE
82 #ifdef OSG_ARBITRARY_SPLIT
83 float fSplitValue
; // <0 => horizontal; >0 => vertikal
90 #ifndef OSG_USE_NURBS_PATCH
95 SBPETreeCell
*aptChildren
[4]; // nw, ne, sw, se / n, -, s, - / w, e, -, -
97 unsigned int uiBottom
;
105 #ifdef OSG_USE_NURBS_PATCH
106 BSplineTensorSurface
*pclBSplineSurface
;
107 SErrorTreeCell
*ptErrorCell
;
109 BezierTensorSurface
*pclBezierSurface
;
110 SErrorTreeCell
*ptErrorCell
;
111 SBPETreeCell
*ptBPCell
;
114 /*#ifdef OSG_ARBITRARY_SPLIT
120 class OSG_DRAWABLE_DLLMAPPING CErrorQuadTree
128 /*#ifdef OSG_ARBITRARY_SPLIT
129 void CalculatePoints( std::vector< Vec2d > *pvclInsert, std::vector< Vec2d > *pvclDelete,
130 BSplineTensorSurface *pclPatch,
131 float fError, float &rfMinError, float &rfMaxError );
133 void BuildMesh(DCTPMesh
* pclMesh
,
134 #ifdef OSG_USE_NURBS_PATCH
135 BSplineTensorSurface
* pclPatch
,
136 #ifdef OSG_ARBITRARY_SPLIT
137 const Vec2d cclMinParam
, const Vec2d cclMaxParam
,
140 std::vector
<std::vector
<BezierTensorSurface
> > *pvvclPatches
,
141 const std::vector
<double> *cpvdIntervalsU
,
142 const std::vector
<double> *cpvdIntervalsV
,
144 float fError
, float & rfMinError
, float & rfMaxError
);
146 void WriteTree(std::ostream
&rclFile
);
148 void ReadTree(std::istream
&rclFile
);
152 #ifdef OSG_ONE_CHILD_PTR
153 void DeleteNode(SErrorTreeCell
*pclNode
);
155 void DeleteNode(SErrorTreeCell
*&rpclNode
);
158 void SetInitialCells(DCTPMesh
* pclMesh
, float fError
,
159 #ifdef OSG_USE_NURBS_PATCH
160 #ifdef OSG_ARBITRARY_SPLIT
161 BSplineTensorSurface
* pclPatch
,
162 const Vec2d cclMinParam
, const Vec2d cclMaxParam
);
164 BSplineTensorSurface
* pclPatch
);
167 std::vector
<std::vector
<BezierTensorSurface
> > *pvvclPatches
,
168 const std::vector
<double> *cpvdIntervalsU
,
169 const std::vector
<double> *cpvdIntervalsV
);
172 void SubdivideNode(DCTPMesh
*pclMesh
, DCTPFace
*pclFace
);
174 void SubdivideBuild(DCTPMesh
*pclMesh
, DCTPFace
*pclFace
);
176 void ComputeError(DCTPFace
*pclFace
);
178 #ifndef OSG_USE_NURBS_PATCH
179 void ComputeBPTree(std::vector
<std::vector
<BezierTensorSurface
> > *pvvclPatches
,
180 const std::vector
<double> * cpvdIntervalsU
,
181 const std::vector
<double> * cpvdIntervalsV
);
183 void ComputeBPError(SBPETreeCell
* pclBPNode
,
184 std::vector
<std::vector
<BezierTensorSurface
> > *pvvclPatches
,
185 const std::vector
<double> * cpvdIntervalsU
,
186 const std::vector
<double> * cpvdIntervalsV
);
188 void SubdivideBPTree(SBPETreeCell
* pclBPNode
,
189 std::vector
<std::vector
<BezierTensorSurface
> > *pvvclPatches
,
190 const std::vector
<double> * cpvdIntervalsU
,
191 const std::vector
<double> * cpvdIntervalsV
);
193 void DeleteBPNode(SBPETreeCell
*&rpclNode
);
196 #ifndef OSG_DIFF_TO_BILIN
197 double computeDistToPlane(const Vec3d cclP
, const Vec3d cclV1
, const Vec3d cclV2
, const Vec3d cclV3
);
199 double computeDistToTriangle(const Vec3d cclP
, const Vec3d cclV1
, const Vec3d cclV2
, const Vec3d cclV3
);
202 double computeDistToLine(const Vec3d cclP
, const Vec3d cclV1
, const Vec3d cclV2
);
205 #ifdef OSG_USE_NURBS_PATCH
206 SErrorTreeCell
* m_ptRoot
;
208 std::vector
<std::vector
<SErrorTreeCell
*> > m_vvptRoot
;
209 SBPETreeCell
*m_ptBPRoot
;
212 float m_fErrorCutoff
;
215 static bool m_sbNormalApproximation
;
219 CErrorQuadTree(const CErrorQuadTree
&other
);
220 void operator=(const CErrorQuadTree
&rhs
);