1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
15 #include <Adaptor3d_Curve.hxx>
16 #include <gp_Circ.hxx>
20 #include <Precision.hxx>
21 #include <TColgp_HArray1OfVec.hxx>
22 #include <TColStd_HArray1OfInteger.hxx>
23 #include <Vrml_Coordinate3.hxx>
24 #include <Vrml_IndexedLineSet.hxx>
25 #include <Vrml_Material.hxx>
26 #include <Vrml_Separator.hxx>
27 #include <VrmlConverter_Curve.hxx>
28 #include <VrmlConverter_Drawer.hxx>
29 #include <VrmlConverter_LineAspect.hxx>
31 //==================================================================
32 // function: FindLimits
34 //==================================================================
35 static void FindLimits(const Adaptor3d_Curve& aCurve,
36 const Standard_Real aLimit,
40 First = aCurve.FirstParameter();
41 Last = aCurve.LastParameter();
42 Standard_Boolean firstInf = Precision::IsNegativeInfinite(First);
43 Standard_Boolean lastInf = Precision::IsPositiveInfinite(Last);
45 if (firstInf || lastInf) {
47 Standard_Real delta = 1;
48 if (firstInf && lastInf) {
55 } while (P1.Distance(P2) < aLimit);
63 } while (P1.Distance(P2) < aLimit);
71 } while (P1.Distance(P2) < aLimit);
77 //==================================================================
78 // function: DrawCurve
80 //==================================================================
81 static void DrawCurve (const Adaptor3d_Curve& aCurve,
82 const Standard_Integer NbP,
83 const Standard_Real U1,
84 const Standard_Real U2,
85 const Handle(VrmlConverter_Drawer)& aDrawer, // for passsing of LineAspect
86 Standard_OStream& anOStream)
88 Standard_Integer nbintervals = 1, i;
89 Handle(TColgp_HArray1OfVec) HAV1;
90 Handle(TColStd_HArray1OfInteger) HAI1;
92 if (aCurve.GetType() == GeomAbs_BSplineCurve) {
93 nbintervals = aCurve.NbKnots() - 1;
94 // std::cout << "NbKnots "<<aCurve.NbKnots() << std::endl;
95 nbintervals = Max(1, nbintervals/3);
99 switch (aCurve.GetType()) {
103 HAV1 = new TColgp_HArray1OfVec(1, 2);
104 // array of coordinates of line
105 gp_Pnt p = aCurve.Value(U1);
106 V.SetX(p.X()); V.SetY(p.Y()); V.SetZ(p.Z());
109 p = aCurve.Value(U2);
110 V.SetX(p.X()); V.SetY(p.Y()); V.SetZ(p.Z());
113 HAI1 = new TColStd_HArray1OfInteger(1,3);
114 // array of indexes of line
117 HAI1->SetValue(3,-1);
125 Standard_Integer N = Max(2, NbP*nbintervals);
127 // std::cout << "nbintervals " << nbintervals << std::endl;
128 // std::cout << "N " << N << std::endl;
131 HAV1 = new TColgp_HArray1OfVec(1, N);
132 // HAI1 = new TColStd_HArray1OfInteger(1,(N/2*3+N%2));
133 HAI1 = new TColStd_HArray1OfInteger(1,N+1);
134 Standard_Real DU = (U2-U1) / (N-1);
137 for (i = 1; i <= N;i++) {
141 V.SetX(p.X()); V.SetY(p.Y()); V.SetZ(p.Z());
145 // Standard_Integer j=1,k;
147 // for (i=HAI1->Lower(); i <= HAI1->Upper(); i++)
152 // HAI1->SetValue(i,-1);
157 // HAI1->SetValue(i,i-j);
161 for (i=HAI1->Lower(); i < HAI1->Upper(); i++)
163 HAI1->SetValue(i,i-1);
165 HAI1->SetValue(HAI1->Upper(),-1);
169 // std::cout << " Array HAI1 - coordIndex " << std::endl;
170 // for ( i=HAI1->Lower(); i <= HAI1->Upper(); i++ )
172 // std::cout << HAI1->Value(i) << std::endl;
175 // creation of Vrml objects
176 Handle(VrmlConverter_LineAspect) LA = new VrmlConverter_LineAspect;
177 LA = aDrawer->LineAspect();
179 // std::cout << "LA->HasMaterial() = " << LA->HasMaterial() << std::endl;
183 SE1.Print(anOStream);
186 if (LA->HasMaterial()){
188 Handle(Vrml_Material) M;
194 Handle(Vrml_Coordinate3) C3 = new Vrml_Coordinate3(HAV1);
195 C3->Print(anOStream);
197 Vrml_IndexedLineSet ILS;
198 ILS.SetCoordIndex(HAI1);
199 ILS.Print(anOStream);
201 SE1.Print(anOStream);
204 //==================================================================
207 //==================================================================
208 void VrmlConverter_Curve::Add(const Adaptor3d_Curve& aCurve,
209 const Handle(VrmlConverter_Drawer)& aDrawer,
210 Standard_OStream& anOStream)
214 Standard_Integer NbPoints = aDrawer->Discretisation();
215 Standard_Real V1, V2;
216 Standard_Real aLimit = aDrawer->MaximalParameterValue();
217 FindLimits(aCurve, aLimit, V1, V2);
219 // std::cout << "V1 = "<< V1 << std::endl;
220 // std::cout << "V2 = "<< V2 << std::endl;
221 // std::cout << "NbPoints = "<< NbPoints << std::endl;
222 // std::cout << "aLimit = "<< aLimit << std::endl;
226 V1 , V2, aDrawer, anOStream);
230 //==================================================================
233 //==================================================================
234 void VrmlConverter_Curve::Add(const Adaptor3d_Curve& aCurve,
235 const Standard_Real U1,
236 const Standard_Real U2,
237 const Handle(VrmlConverter_Drawer)& aDrawer,
238 Standard_OStream& anOStream)
241 Standard_Integer NbPoints = aDrawer->Discretisation();
242 Standard_Real V1 = U1;
243 Standard_Real V2 = U2;
245 if (Precision::IsNegativeInfinite(V1)) V1 = -aDrawer->MaximalParameterValue();
246 if (Precision::IsPositiveInfinite(V2)) V2 = aDrawer->MaximalParameterValue();
248 // std::cout << "V1 = "<< V1 << std::endl;
249 // std::cout << "V2 = "<< V2 << std::endl;
250 // std::cout << "NbPoints = "<< NbPoints << std::endl;
254 V1 , V2, aDrawer, anOStream);
258 //==================================================================
261 //==================================================================
262 void VrmlConverter_Curve::Add(const Adaptor3d_Curve& aCurve,
263 const Standard_Real U1,
264 const Standard_Real U2,
265 Standard_OStream& anOStream,
266 const Standard_Integer aNbPoints)
268 Handle(VrmlConverter_Drawer) aDrawer = new VrmlConverter_Drawer;
269 Handle(VrmlConverter_LineAspect) la = new VrmlConverter_LineAspect;
270 aDrawer->SetLineAspect(la);
273 Standard_Real V1 = U1;
274 Standard_Real V2 = U2;
276 if (Precision::IsNegativeInfinite(V1)) V1 = -aDrawer->MaximalParameterValue();
277 if (Precision::IsPositiveInfinite(V2)) V2 = aDrawer->MaximalParameterValue();
279 // std::cout << "V1 = "<< V1 << std::endl;
280 // std::cout << "V2 = "<< V2 << std::endl;
281 // std::cout << "NbPoints = "<< aNbPoints << std::endl;
285 V1 , V2, aDrawer, anOStream);