1 // Created on: 1993-03-24
2 // Created by: Philippe DAUTRY
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _Geom2d_OffsetCurve_HeaderFile
18 #define _Geom2d_OffsetCurve_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
23 #include <Standard_Real.hxx>
24 #include <GeomAbs_Shape.hxx>
25 #include <Geom2d_Curve.hxx>
26 #include <Standard_Boolean.hxx>
27 #include <Standard_Integer.hxx>
28 #include <Geom2dEvaluator_OffsetCurve.hxx>
33 class Geom2d_Geometry;
36 class Geom2d_OffsetCurve;
37 DEFINE_STANDARD_HANDLE(Geom2d_OffsetCurve, Geom2d_Curve)
40 //! This class implements the basis services for the creation,
41 //! edition, modification and evaluation of planar offset curve.
42 //! The offset curve is obtained by offsetting by distance along
43 //! the normal to a basis curve defined in 2D space.
44 //! The offset curve in this package can be a self intersecting
45 //! curve even if the basis curve does not self-intersect.
46 //! The self intersecting portions are not deleted at the
47 //! construction time.
48 //! An offset curve is a curve at constant distance (Offset) from a
49 //! basis curve and the offset curve takes its parametrization from
50 //! the basis curve. The Offset curve is in the direction of the
51 //! normal to the basis curve N.
52 //! The distance offset may be positive or negative to indicate the
53 //! preferred side of the curve :
54 //! . distance offset >0 => the curve is in the direction of N
55 //! . distance offset >0 => the curve is in the direction of - N
56 //! On the Offset curve :
57 //! Value(u) = BasisCurve.Value(U) + (Offset * (T ^ Z)) / ||T ^ Z||
58 //! where T is the tangent vector to the basis curve and Z the
59 //! direction of the normal vector to the plane of the curve,
60 //! N = T ^ Z defines the offset direction and should not have
64 //! In this package we suppose that the continuity of the offset
65 //! curve is one degree less than the continuity of the
66 //! basis curve and we don't check that at any point ||T^Z|| != 0.0
68 //! So to evaluate the curve it is better to check that the offset
69 //! curve is well defined at any point because an exception could
70 //! be raised. The check is not done in this package at the creation
71 //! of the offset curve because the control needs the use of an
72 //! algorithm which cannot be implemented in this package.
73 //! The OffsetCurve is closed if the first point and the last point
74 //! are the same (The distance between these two points is lower or
75 //! equal to the Resolution sea package gp) . The OffsetCurve can be
76 //! closed even if the basis curve is not closed.
77 class Geom2d_OffsetCurve : public Geom2d_Curve
83 //! Constructs a curve offset from the basis curve C,
84 //! where Offset is the distance between the offset
85 //! curve and the basis curve at any point.
86 //! A point on the offset curve is built by measuring the
87 //! offset value along a normal vector at a point on C.
88 //! This normal vector is obtained by rotating the
89 //! vector tangential to C at 90 degrees in the
90 //! anti-trigonometric sense. The side of C on which
91 //! the offset value is measured is indicated by this
92 //! normal vector if Offset is positive, or in the inverse
93 //! sense if Offset is negative.
94 //! If isNotCheckC0 = TRUE checking if basis curve has C0-continuity
97 //! In this package the entities are not shared. The OffsetCurve is
98 //! built with a copy of the curve C. So when C is modified the
99 //! OffsetCurve is not modified
100 //! Warning! if isNotCheckC0 = false,
101 //! ConstructionError raised if the basis curve C is not at least C1.
102 //! No check is done to know if ||V^Z|| != 0.0 at any point.
103 Standard_EXPORT Geom2d_OffsetCurve(const Handle(Geom2d_Curve)& C, const Standard_Real Offset, const Standard_Boolean isNotCheckC0 = Standard_False);
105 //! Changes the direction of parametrization of <me>.
107 //! - the basis curve is reversed,
108 //! - the start point of the initial curve becomes the end
109 //! point of the reversed curve,
110 //! - the end point of the initial curve becomes the start
111 //! point of the reversed curve, and
112 //! - the first and last parameters are recomputed.
113 Standard_EXPORT void Reverse() Standard_OVERRIDE;
115 //! Computes the parameter on the reversed curve for
116 //! the point of parameter U on this offset curve.
117 Standard_EXPORT Standard_Real ReversedParameter (const Standard_Real U) const Standard_OVERRIDE;
119 //! Changes this offset curve by assigning C as the
120 //! basis curve from which it is built.
121 //! If isNotCheckC0 = TRUE checking if basis curve has C0-continuity
124 //! if isNotCheckC0 = false,
125 //! Standard_ConstructionError if the curve C is not at least "C1" continuous.
126 Standard_EXPORT void SetBasisCurve (const Handle(Geom2d_Curve)& C, const Standard_Boolean isNotCheckC0 = Standard_False);
128 //! Changes this offset curve by assigning D as the offset value.
129 Standard_EXPORT void SetOffsetValue (const Standard_Real D);
131 //! Returns the basis curve of this offset curve. The basis curve can be an offset curve.
132 Standard_EXPORT Handle(Geom2d_Curve) BasisCurve() const;
135 //! Continuity of the Offset curve :
136 //! C0 : only geometric continuity,
137 //! C1 : continuity of the first derivative all along the Curve,
138 //! C2 : continuity of the second derivative all along the Curve,
139 //! C3 : continuity of the third derivative all along the Curve,
140 //! G1 : tangency continuity all along the Curve,
141 //! G2 : curvature continuity all along the Curve,
142 //! CN : the order of continuity is infinite.
144 //! Returns the continuity of the basis curve - 1.
145 //! The offset curve must have a unique normal direction defined
147 //! Value and derivatives
150 //! The exception UndefinedValue or UndefinedDerivative is
151 //! raised if it is not possible to compute a unique offset
153 //! If T is the first derivative with not null length and
154 //! Z the direction normal to the plane of the curve, the
155 //! relation ||T(U) ^ Z|| != 0 must be satisfied to evaluate
156 //! the offset curve.
157 //! No check is done at the creation time and we suppose
158 //! in this package that the offset curve is well defined.
159 Standard_EXPORT GeomAbs_Shape Continuity() const Standard_OVERRIDE;
161 //! Warning! this should not be called
162 //! if the basis curve is not at least C1. Nevertheless
163 //! if used on portion where the curve is C1, it is OK
164 Standard_EXPORT void D0 (const Standard_Real U, gp_Pnt2d& P) const Standard_OVERRIDE;
166 //! Warning! this should not be called
167 //! if the continuity of the basis curve is not C2.
168 //! Nevertheless, it's OK to use it on portion
169 //! where the curve is C2
170 Standard_EXPORT void D1 (const Standard_Real U, gp_Pnt2d& P, gp_Vec2d& V1) const Standard_OVERRIDE;
172 //! Warning! This should not be called
173 //! if the continuity of the basis curve is not C3.
174 //! Nevertheless, it's OK to use it on portion
175 //! where the curve is C3
176 Standard_EXPORT void D2 (const Standard_Real U, gp_Pnt2d& P, gp_Vec2d& V1, gp_Vec2d& V2) const Standard_OVERRIDE;
178 //! Warning! This should not be called
179 //! if the continuity of the basis curve is not C4.
180 //! Nevertheless, it's OK to use it on portion
181 //! where the curve is C4
182 Standard_EXPORT void D3 (const Standard_Real U, gp_Pnt2d& P, gp_Vec2d& V1, gp_Vec2d& V2, gp_Vec2d& V3) const Standard_OVERRIDE;
184 //! The returned vector gives the value of the derivative
185 //! for the order of derivation N.
186 //! Warning! this should not be called
187 //! raises UndefunedDerivative if the continuity of the basis curve is not CN+1.
188 //! Nevertheless, it's OK to use it on portion
189 //! where the curve is CN+1
190 //! raises RangeError if N < 1.
191 //! raises NotImplemented if N > 3.
192 //! The following functions compute the value and derivatives
193 //! on the offset curve and returns the derivatives on the
195 //! The computation of the value and derivatives on the basis
196 //! curve are used to evaluate the offset curve
198 //! The exception UndefinedValue or UndefinedDerivative is
199 //! raised if it is not possible to compute a unique offset direction.
200 Standard_EXPORT gp_Vec2d DN (const Standard_Real U, const Standard_Integer N) const Standard_OVERRIDE;
202 //! Returns the value of the first parameter of this
203 //! offset curve. The first parameter corresponds to the
204 //! start point of the curve.
205 //! Note: the first and last parameters of this offset curve
206 //! are also the ones of its basis curve.
207 Standard_EXPORT Standard_Real FirstParameter() const Standard_OVERRIDE;
209 //! Returns the value of the last parameter of this
210 //! offset curve. The last parameter
211 //! corresponds to the end point.
212 //! Note: the first and last parameters of this offset curve
213 //! are also the ones of its basis curve.
214 Standard_EXPORT Standard_Real LastParameter() const Standard_OVERRIDE;
216 //! Returns the offset value of this offset curve.
217 Standard_EXPORT Standard_Real Offset() const;
220 //! Returns True if the distance between the start point
221 //! and the end point of the curve is lower or equal to
222 //! Resolution from package gp.
223 Standard_EXPORT Standard_Boolean IsClosed() const Standard_OVERRIDE;
225 //! Is the order of continuity of the curve N ?
227 //! This method answer True if the continuity of the basis curve
228 //! is N + 1. We suppose in this class that a normal direction
229 //! to the basis curve (used to compute the offset curve) is
230 //! defined at any point on the basis curve.
232 Standard_EXPORT Standard_Boolean IsCN (const Standard_Integer N) const Standard_OVERRIDE;
234 //! Is the parametrization of a curve is periodic ?
235 //! If the basis curve is a circle or an ellipse the corresponding
236 //! OffsetCurve is periodic. If the basis curve can't be periodic
237 //! (for example BezierCurve) the OffsetCurve can't be periodic.
238 Standard_EXPORT Standard_Boolean IsPeriodic() const Standard_OVERRIDE;
240 //! Returns the period of this offset curve, i.e. the period
241 //! of the basis curve of this offset curve.
243 //! Standard_NoSuchObject if the basis curve is not periodic.
244 Standard_EXPORT virtual Standard_Real Period() const Standard_OVERRIDE;
246 //! Applies the transformation T to this offset curve.
247 //! Note: the basis curve is also modified.
248 Standard_EXPORT void Transform (const gp_Trsf2d& T) Standard_OVERRIDE;
250 //! Returns the parameter on the transformed curve for
251 //! the transform of the point of parameter U on <me>.
253 //! me->Transformed(T)->Value(me->TransformedParameter(U,T))
255 //! is the same point as
257 //! me->Value(U).Transformed(T)
259 //! This methods calls the basis curve method.
260 Standard_EXPORT virtual Standard_Real TransformedParameter (const Standard_Real U, const gp_Trsf2d& T) const Standard_OVERRIDE;
262 //! Returns a coefficient to compute the parameter on
263 //! the transformed curve for the transform of the
266 //! Transformed(T)->Value(U * ParametricTransformation(T))
268 //! is the same point as
270 //! Value(U).Transformed(T)
272 //! This methods calls the basis curve method.
273 Standard_EXPORT virtual Standard_Real ParametricTransformation (const gp_Trsf2d& T) const Standard_OVERRIDE;
275 //! Creates a new object, which is a copy of this offset curve.
276 Standard_EXPORT Handle(Geom2d_Geometry) Copy() const Standard_OVERRIDE;
278 //! Returns continuity of the basis curve.
279 Standard_EXPORT GeomAbs_Shape GetBasisCurveContinuity() const;
281 //! Dumps the content of me into the stream
282 Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
287 DEFINE_STANDARD_RTTIEXT(Geom2d_OffsetCurve,Geom2d_Curve)
297 Handle(Geom2d_Curve) basisCurve;
298 Standard_Real offsetValue;
299 GeomAbs_Shape myBasisCurveContinuity;
300 Handle(Geom2dEvaluator_OffsetCurve) myEvaluator;
310 #endif // _Geom2d_OffsetCurve_HeaderFile