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_BSPLINETENSORSURFACE_H_
39 #define _OSG_BSPLINETENSORSURFACE_H_
44 #include "OSGDrawableDef.h"
45 #include "OSGConfig.h"
46 #include "OSGVector.h"
49 #include "OSGdctptypes.h"
50 #include "OSGBSplineBasisFunction.h"
51 #include "OSGBezierTensorSurface.h"
55 class OSG_DRAWABLE_DLLMAPPING BSplineTensorSurface
58 DCTPVec4dmatrix control_points
; //control points of the surface
59 int dimension_u
, dimension_v
; //dimension of the surface in u and v directions
60 BSplineBasisFunction basis_function_u
; //placeholder for the u knots & facility to easily compute 'em
61 BSplineBasisFunction basis_function_v
; //placeholder for the v knots & facility to easily compute 'em
63 //file format constants
64 static const char ff_const_1
[];
65 static const char ff_const_2
[];
66 static const char ff_const_3
[];
67 static const char ff_const_4
[];
68 static const char ff_const_5
[];
70 int CheckKnotPoints(const DCTPdvector
& knots
, int dim
); //check whether knots has a right format
71 // delete a knot which is on a 'bezier' curve, i.e. [0 0 0 0 1 1 1 1 2 2 2 2 3 3 3 3] -> [0 0 0 0 1 1 1 2 2 2 3 3 3 3]
72 // must have a multiplicity of (at least) dimension + 1, and its associated control point also must have a multiplicity of (at least) 2.
73 int deleteBezierKnot_U(double k
);
74 int deleteBezierKnot_V(double k
);
76 void RatSurfaceDerivs(DCTPVec4dmatrix
&rclHomDerivs
, DCTPVec3dmatrix
&rclEuclidDerivs
);
79 inline BSplineTensorSurface(void);
80 inline ~BSplineTensorSurface(void);
83 // FIXME: the setup interface is very rigid, maybe it should allow knot & dimension setting alone, eg. to resize dimension, etc
84 // FIXME: and insertion of knots
85 int setKnotsAndDimension(const DCTPdvector
& knots_u
, int dim_u
, const DCTPdvector
& knots_v
, int dim_v
); //ok, acts like its name says
86 void setControlPointMatrix(const DCTPVec4dmatrix
&cps
); //set control point vector
89 inline DCTPdvector
&getKnotVector_U (void);
90 inline DCTPdvector
&getKnotVector_V (void);
91 inline DCTPVec4dmatrix
&getControlPointMatrix(void);
92 inline int getDimension_U (void);
93 inline int getDimension_V (void);
95 void getParameterInterval_U(double &minpar
, double &maxpar
); //returns minimal and maximal parameter value
96 void getParameterInterval_V(double &minpar
, double &maxpar
); //returns minimal and maximal parameter value
98 inline BSplineBasisFunction
&getBasisFunctionU(void);
99 inline BSplineBasisFunction
&getBasisFunctionV(void);
101 //I/O support - FIXME: read( char *fname ) outta be supported , etc
102 int read(std::istream
&infile
);
103 int write(std::ostream
&outfile
);
105 //some REAL functionality
106 Vec3d
compute(Vec2d uv
, int &error
); //compute curve at parameter value t
107 Vec4d
compute4D(Vec2d uv
, int &error
); //compute curve at parameter value t
108 Vec3d
computeNormal(Vec2d clUV
, int &riError
, Vec3d
&rclPos
); // compute normal at uv
109 Vec3f
computeNormal(Vec2d clUV
, int &riError
, Pnt3f
&rclPos
); // compute normal at uv
110 Vec3d
computeNormalTex(Vec2d
&rclUV
,
111 int &riError
, Vec3d
&rclPos
, Vec2d
&rclTexCoord
,
112 const std::vector
<std::vector
<Pnt2f
> > *cpvvclTexCP
); // compute normal at uv
113 void compute(std::vector
<Vec2d
> &rvclUV
, std::vector
<Pnt3f
> &rvclPos
); //compute curve at parameter value uv
114 void computeNormal(std::vector
<Vec2d
> &rvclUV
,
115 std::vector
<Pnt3f
> &rvclPos
,
116 std::vector
<Vec3f
> &rvclNorm
); // compute normal at uv
117 void computeNormalforTrimming(std::vector
<Vec2d
> &rvclUV
,
118 std::vector
<Vec3d
> &rvclNorm
,
119 std::vector
<Vec3d
> *pvclPos
= NULL
); // compute normal at uv
121 void computeNormalTex(std::vector
<Vec2d
> & rvclUV
,
122 std::vector
<Pnt3f
> & rvclPos
,
123 std::vector
<Vec3f
> & rvclNorm
,
124 std::vector
<Pnt2f
> & rvclTexCoord
,
125 const std::vector
<std::vector
<Pnt2f
> > *cpvvclTexCP
); // compute normal at uv
126 void computeTex(std::vector
<Vec2d
> & rvclUV
,
127 std::vector
<Pnt3f
> & rvclPos
,
128 std::vector
<Pnt2f
> & rvclTexCoord
,
129 const std::vector
<std::vector
<Vec2d
> > *cpvvclTexCP
);
130 void computeTexforTrimming(std::vector
<Vec2d
> & rvclUV
,
131 std::vector
<Vec2d
> & rvclTexCoord
,
132 const std::vector
<std::vector
<Vec2d
> > *cpvvclTexCP
);
134 int insertKnot_U(double k
); // insert a new knot into U (recalculates control points and u knotvector)
135 int insertKnot_V(double k
); // insert a new knot into V (recalculates control points and v knotvector)
137 // convert curve into Bezier form.
138 int makeBezier(beziersurfacematrix
&beziers
, DCTPdvector
&upars
, DCTPdvector
&vpars
);
139 int getSplitParams(DCTPdvector
&upars
, DCTPdvector
&vpars
);
141 //subdivide surface at midpoint into 4 bspline surfaces
142 int midPointSubDivision(std::vector
<std::vector
<BSplineTensorSurface
> > &rvvcl_newbspline
);
143 int midPointSubDivisionU(std::vector
<BSplineTensorSurface
> &rvcl_newbspline
);
144 int midPointSubDivisionV(std::vector
<BSplineTensorSurface
> &rvcl_newbspline
);
145 int subDivisionU(std::vector
<BSplineTensorSurface
> &rvcl_newbspline
, double dSplit
);
146 int subDivisionV(std::vector
<BSplineTensorSurface
> &rvcl_newbspline
, double dSplit
);
149 void correctDers(const Vec2d cclUV
, const Vec3d cclPos
, Vec3d
&rclDU
, Vec3d
&rclDV
);
155 #include "OSGBSplineTensorSurface.inl"
157 #endif //BSplineTensorSurface.h