0023945: GeomAdaptor_Surface fails to compute the first derivatives on the surface...
[occt.git] / src / GeomAdaptor / GeomAdaptor.cxx
CommitLineData
b311480e 1// Created on: 1995-05-03
2// Created by: Bruno DUMORTIER
3// Copyright (c) 1995-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22#include <GeomAdaptor.ixx>
23
24#include <Geom_Line.hxx>
25#include <Geom_Circle.hxx>
26#include <Geom_Ellipse.hxx>
27#include <Geom_Parabola.hxx>
28#include <Geom_Hyperbola.hxx>
29#include <Geom_BezierCurve.hxx>
30#include <Geom_BSplineCurve.hxx>
31#include <Geom_TrimmedCurve.hxx>
32
33#include <Geom_Plane.hxx>
34#include <Geom_CylindricalSurface.hxx>
35#include <Geom_ConicalSurface.hxx>
36#include <Geom_SphericalSurface.hxx>
37#include <Geom_ToroidalSurface.hxx>
38#include <Geom_BezierSurface.hxx>
39#include <Geom_BSplineSurface.hxx>
40#include <Geom_SurfaceOfRevolution.hxx>
41#include <Geom_SurfaceOfLinearExtrusion.hxx>
42#include <Geom_RectangularTrimmedSurface.hxx>
43#include <Geom_OffsetSurface.hxx>
44
45#include <Adaptor3d_HCurve.hxx>
46#include <Adaptor3d_HSurface.hxx>
47
48//=======================================================================
49//function : MakeCurve
50//purpose :
51//=======================================================================
52
53Handle(Geom_Curve) GeomAdaptor::MakeCurve (const Adaptor3d_Curve& HC)
54{
55 Handle(Geom_Curve) C;
56
57 switch (HC.GetType())
58 {
59 case GeomAbs_Line:
60 C = new Geom_Line(HC.Line());
61 break;
62
63 case GeomAbs_Circle:
64 C = new Geom_Circle(HC.Circle());
65 break;
66
67 case GeomAbs_Ellipse:
68 C = new Geom_Ellipse(HC.Ellipse());
69 break;
70
71 case GeomAbs_Parabola:
72 C = new Geom_Parabola(HC.Parabola());
73 break;
74
75 case GeomAbs_Hyperbola:
76 C = new Geom_Hyperbola(HC.Hyperbola());
77 break;
78
79 case GeomAbs_BezierCurve:
80 C = Handle(Geom_BezierCurve)::DownCast(HC.Bezier()->Copy());
81 break;
82
83 case GeomAbs_BSplineCurve:
84 C = Handle(Geom_BSplineCurve)::DownCast(HC.BSpline()->Copy());
85 break;
86
87 case GeomAbs_OtherCurve:
88 Standard_DomainError::Raise("GeomAdaptor::MakeCurve : OtherCurve");
89
90 }
91
92 // trim the curve if necassary.
93 if (! C.IsNull() &&
94 (HC.FirstParameter() != C->FirstParameter()) ||
95 (HC.LastParameter() != C->LastParameter())) {
96
97 C = new Geom_TrimmedCurve(C,HC.FirstParameter(),HC.LastParameter());
98 }
99
100 return C;
101}
102
103
104//=======================================================================
105//function : MakeSurface
106//purpose :
107//=======================================================================
108
109Handle(Geom_Surface) GeomAdaptor::MakeSurface(const Adaptor3d_Surface& HS)
110{
111 Handle(Geom_Surface) S;
112
113 switch ( HS.GetType())
114 {
115 case GeomAbs_Plane:
116 S = new Geom_Plane(HS.Plane());
117 break;
118
119 case GeomAbs_Cylinder:
120 S = new Geom_CylindricalSurface(HS.Cylinder());
121 break;
122
123 case GeomAbs_Cone:
124 S = new Geom_ConicalSurface(HS.Cone());
125 break;
126
127 case GeomAbs_Sphere:
128 S = new Geom_SphericalSurface(HS.Sphere());
129 break;
130
131 case GeomAbs_Torus:
132 S = new Geom_ToroidalSurface(HS.Torus());
133 break;
134
135 case GeomAbs_BezierSurface:
136 S = Handle(Geom_BezierSurface)::DownCast(HS.Bezier()->Copy());
137 break;
138
139 case GeomAbs_BSplineSurface:
140 S = Handle(Geom_BSplineSurface)::DownCast(HS.BSpline()->Copy());
141 break;
142
143 case GeomAbs_SurfaceOfRevolution:
144 S = new Geom_SurfaceOfRevolution
145 (GeomAdaptor::MakeCurve(HS.BasisCurve()->Curve()),HS.AxeOfRevolution());
146 break;
147
148 case GeomAbs_SurfaceOfExtrusion:
149 S = new Geom_SurfaceOfLinearExtrusion
150 (GeomAdaptor::MakeCurve(HS.BasisCurve()->Curve()),HS.Direction());
151 break;
152
153 case GeomAbs_OffsetSurface:
154 S = new Geom_OffsetSurface(GeomAdaptor::MakeSurface(HS.BasisSurface()->Surface()),
155 HS.OffsetValue());
156 break;
157
158 case GeomAbs_OtherSurface:
159 Standard_DomainError::Raise("GeomAdaptor::MakeSurface : OtherSurface");
160 break;
161 }
162
163 if ( S.IsNull() )
164 return S;
165
166 // trim the surface if necassary.
167 Standard_Real U1, U2, V1, V2;
168 S->Bounds(U1, U2, V1, V2);
169 if ((HS.FirstUParameter() != U1 ) ||
170 (HS.LastUParameter () != U2 ) ||
171 (HS.FirstVParameter() != V1 ) ||
172 (HS.LastVParameter () != V2 ) ) {
173
174 S = new Geom_RectangularTrimmedSurface
175 (S,HS.FirstUParameter(),HS.LastUParameter(),
176 HS.FirstVParameter(),HS.LastVParameter());
177 }
178
179 return S;
180}