changed: gcc8 base update
[opensg.git] / Source / System / NodeCores / Drawables / Nurbs / Internal / OSGErrorQuadTree.h
blob8acafef1af20d63aa1bdc81d5f58b5edea4c16cb
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 \*---------------------------------------------------------------------------*/
38 #ifndef _OSG_ErrorQuadTree_h
39 #define _OSG_ErrorQuadTree_h
40 #ifdef __sgi
41 #pragma once
42 #endif
44 #include "OSGDrawableDef.h"
45 #include "OSGConfig.h"
47 #include "OSGdctptypes.h"
49 OSG_BEGIN_NAMESPACE
51 class DCTPMesh;
52 class BezierTensorSurface;
53 class BSplineTensorSurface;
54 class DCTPFace;
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
66 #endif
67 #endif
69 struct SErrorTreeCell
71 float fError;
72 #ifdef OSG_ONE_CHILD_PTR
73 SErrorTreeCell *ptChildren; // nw, ne, sw, se
74 #else
75 #ifdef OSG_USE_KD_TREE
76 SErrorTreeCell *aptChildren[2]; // n/w, s/e
77 #else
78 SErrorTreeCell *aptChildren[4]; // nw, ne, sw, se
79 #endif
80 #endif
81 #ifdef OSG_USE_KD_TREE
82 #ifdef OSG_ARBITRARY_SPLIT
83 float fSplitValue; // <0 => horizontal; >0 => vertikal
84 #else
85 bool bSplitHoriz;
86 #endif
87 #endif
90 #ifndef OSG_USE_NURBS_PATCH
91 struct SBPETreeCell
93 float fError;
94 float fPrevError;
95 SBPETreeCell *aptChildren[4]; // nw, ne, sw, se / n, -, s, - / w, e, -, -
96 unsigned int uiTop;
97 unsigned int uiBottom;
98 unsigned int uiLeft;
99 unsigned int uiRight;
101 #endif
103 struct SFaceTreeCell
105 #ifdef OSG_USE_NURBS_PATCH
106 BSplineTensorSurface *pclBSplineSurface;
107 SErrorTreeCell *ptErrorCell;
108 #else
109 BezierTensorSurface *pclBezierSurface;
110 SErrorTreeCell *ptErrorCell;
111 SBPETreeCell *ptBPCell;
112 #endif
113 bool bOwnSurface;
114 /*#ifdef OSG_ARBITRARY_SPLIT
115 Vec2d clMin;
116 Vec2d clMax;
117 #endif*/
120 class OSG_DRAWABLE_DLLMAPPING CErrorQuadTree
123 public:
125 CErrorQuadTree();
126 ~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 );
132 #else*/
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,
138 #endif
139 #else
140 std::vector<std::vector<BezierTensorSurface> > *pvvclPatches,
141 const std::vector<double> *cpvdIntervalsU,
142 const std::vector<double> *cpvdIntervalsV,
143 #endif
144 float fError, float & rfMinError, float & rfMaxError);
146 void WriteTree(std::ostream &rclFile);
148 void ReadTree(std::istream &rclFile);
150 private:
152 #ifdef OSG_ONE_CHILD_PTR
153 void DeleteNode(SErrorTreeCell *pclNode);
154 #else
155 void DeleteNode(SErrorTreeCell *&rpclNode);
156 #endif
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);
163 #else
164 BSplineTensorSurface * pclPatch);
165 #endif
166 #else
167 std::vector<std::vector<BezierTensorSurface> > *pvvclPatches,
168 const std::vector<double> *cpvdIntervalsU,
169 const std::vector<double> *cpvdIntervalsV);
170 #endif
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);
194 #endif
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);
200 #endif
202 double computeDistToLine(const Vec3d cclP, const Vec3d cclV1, const Vec3d cclV2);
204 float m_fMaxError;
205 #ifdef OSG_USE_NURBS_PATCH
206 SErrorTreeCell* m_ptRoot;
207 #else
208 std::vector<std::vector<SErrorTreeCell*> > m_vvptRoot;
209 SBPETreeCell *m_ptBPRoot;
210 #endif
212 float m_fErrorCutoff;
214 public:
215 static bool m_sbNormalApproximation;
217 private:
219 CErrorQuadTree(const CErrorQuadTree &other);
220 void operator=(const CErrorQuadTree &rhs);
223 OSG_END_NAMESPACE
225 #endif