fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / NodeCores / Drawables / Nurbs / Internal / OSGBezierCurve2D.h
blob37013763f7765502e70005f4d106a2bf6863ffab
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_BEZIERCURVE2D_H_
39 #define _OSG_BEZIERCURVE2D_H_
40 #ifdef __sgi
41 #pragma once
42 #endif
44 #include "OSGDrawableDef.h"
45 #include "OSGConfig.h"
46 #include "OSGBaseFunctions.h"
48 #include "OSGdctptypes.h"
49 #include <iostream>
50 #include <fstream>
51 #include <iomanip>
52 #include <vector>
53 #include <deque>
55 OSG_BEGIN_NAMESPACE
57 class BezierCurve2D;
58 typedef std::vector<BezierCurve2D> bezier2dvector;
59 typedef std::vector<bezier2dvector> bezier2dmatrix;
60 typedef std::deque<BezierCurve2D> bezier2ddeque;
61 typedef std::vector<bezier2ddeque> bezier2ddequevector;
63 class OSG_DRAWABLE_DLLMAPPING BezierCurve2D
65 protected:
66 DCTPVec3dvector control_points; //control points of the curve
68 double pointLineDistancewNormal(Vec3d p, Vec2d a, Vec2d n);
69 int minMaxIntersection(DCTPdvector &res, double s, double e);
70 int approximate_sub(DCTPVec2dvector &vertices, double delta);
71 // int approximateLength_sub( DCTPVec2dvector &vertices, double delta);
72 double homogeniousDistanceSquared(Vec3d v1, Vec3d v2);
74 void CalculateDerivativeCurve();
75 void CalculateNOverIVector(std::vector<double> &NOverI, const unsigned int n) const;
76 void CalculatePolyDerivCurve(BezierCurve2D &DerivativeCurve) const;
77 void CrossMultiply(BezierCurve2D &OtherCurve);
78 void SquareWeight(std::vector<double> &Squared) const;
79 double CalculateSupinumSquared() const;
80 void CalculateDifferenceCurve(const BezierCurve2D &Other, BezierCurve2D &Diff) const;
81 void DegreeElevate();
82 void AddNthHermitePoints(Vec3d d0, Vec3d d1);
84 public:
85 inline BezierCurve2D(void );
86 inline BezierCurve2D(const BezierCurve2D &b);
87 inline ~BezierCurve2D(void );
89 //setup functions
90 int setControlPointVector(const DCTPVec3dvector& cps); //ok, acts like its name says
92 //query functions
93 inline DCTPVec3dvector& getControlPointVector(void);
95 //some REAL functionality
96 Vec2d computewdeCasteljau(double t, int &error); //compute curve at parameter value t
97 Vec2d computeLinearApproximation(double t, int &error); //ok like its name sayz
98 int midPointSubDivision(bezier2dvector &newbeziers); //subdivide curve at midpoint into two new curves
99 int midPointSubDivision(BezierCurve2D &newcurve); //subdivide curve at midpoint into two new curves
100 int subDivision(double t, bezier2dvector &newbeziers); //subdivide curvee at t into two new curves
101 int subDivision(double t, BezierCurve2D &newcurve); //subdivide curvee at t into two new curves
102 int intersection(DCTPdvector &res, Vec2d a, Vec2d b); // calculate intersection of curve with polyline (a, b)
103 int intersection(DCTPdvector &res, double a, bool horiz); // calculate intersection of curve with line (a)
104 int approximate(DCTPVec2dvector &vertices, double delta); // approximate curve linearly with given maximum tolerance
105 // int approximateLength( DCTPVec2dvector &vertices, double delta); // approximate curve linearly with given maximum tolerance
106 bool reduceDegree(double tol = DCTP_EPS); //try to degree reduce the curve
107 // computing degree of a nonrational curve with eps. error
108 unsigned int computeNonratApproximationDegree(double eps) const;
110 inline void optimizeDegree(void);
113 OSG_END_NAMESPACE
115 #include "OSGBezierCurve2D.inl"
117 #endif //BezierCurve2D.h