0031313: Foundation Classes - Dump improvement for classes
[occt.git] / src / Prs3d / Prs3d_ToolQuadric.cxx
CommitLineData
625e1958 1// Created on: 2016-02-04
2// Created by: Anastasia BORISOVA
3// Copyright (c) 2016 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
62ef08df 16#include <Prs3d_ToolQuadric.hxx>
625e1958 17
18#include <gp_Quaternion.hxx>
19#include <Graphic3d_ArrayOfTriangles.hxx>
20#include <Poly_Array1OfTriangle.hxx>
21#include <TColgp_Array1OfPnt.hxx>
22
23//=======================================================================
24//function : fillArrays
25//purpose :
26//=======================================================================
62ef08df 27void Prs3d_ToolQuadric::fillArrays (const gp_Trsf& theTrsf, TColgp_Array1OfPnt& theArray, NCollection_Array1<gp_Dir>& theNormals)
625e1958 28{
29 Standard_ShortReal aStepU = 1.0f / mySlicesNb;
30 Standard_ShortReal aStepV = 1.0f / myStacksNb;
31
32 for (Standard_Integer aU = 0; aU <= mySlicesNb; aU++)
33 {
34 const Standard_Real aParamU = aU * aStepU;
35 for (Standard_Integer aV = 0; aV <= myStacksNb; aV++)
36 {
37 const Standard_ShortReal aParamV = aV * aStepV;
38 const Standard_Integer aVertId = aU * (myStacksNb + 1) + aV + 1;
39 gp_Pnt aVertex = Vertex(aParamU, aParamV);
40 gp_Dir aNormal = Normal(aParamU, aParamV);
41
42 aVertex.Transform (theTrsf);
43 aNormal.Transform (theTrsf);
44
45 theArray.SetValue (aVertId, aVertex);
46 theNormals.SetValue (aVertId, aNormal);
47 }
48 }
49}
50
51//=======================================================================
52//function : FIllArray
53//purpose :
54//=======================================================================
62ef08df 55void Prs3d_ToolQuadric::FillArray (Handle(Graphic3d_ArrayOfTriangles)& theArray, const gp_Trsf& theTrsf)
625e1958 56{
57 const Standard_Integer aTrianglesNb = TrianglesNb();
62ef08df 58 if (theArray.IsNull())
59 {
60 theArray = new Graphic3d_ArrayOfTriangles (aTrianglesNb * 3, 0, Standard_True);
61 }
625e1958 62
63 Poly_Array1OfTriangle aPolyTriangles (1, aTrianglesNb);
64 TColgp_Array1OfPnt anArray (1, aTrianglesNb * 3);
65 NCollection_Array1<gp_Dir> aNormals (1, aTrianglesNb * 3);
66 fillArrays (theTrsf, anArray, aNormals);
67
68 // Fill primitives
69 for (Standard_Integer aU = 0; aU < mySlicesNb; ++aU)
70 {
71 for (Standard_Integer aV = 1; aV <= myStacksNb; ++aV)
72 {
73 theArray->AddVertex (anArray.Value (aU * (myStacksNb + 1) + aV), aNormals.Value (aU * (myStacksNb + 1) + aV));
74 theArray->AddVertex (anArray.Value ((aU + 1) * (myStacksNb + 1) + aV), aNormals.Value ((aU + 1) * (myStacksNb + 1) + aV));
75 theArray->AddVertex (anArray.Value ((aU + 1) * (myStacksNb + 1) + (aV + 1)), aNormals.Value ((aU + 1) * (myStacksNb + 1) + (aV + 1)));
76 theArray->AddVertex (anArray.Value ((aU + 1) * (myStacksNb + 1) + (aV + 1)), aNormals.Value ((aU + 1) * (myStacksNb + 1) + (aV + 1)));
77 theArray->AddVertex (anArray.Value (aU * (myStacksNb + 1) + (aV + 1)), aNormals.Value (aU * (myStacksNb + 1) + (aV + 1)));
78 theArray->AddVertex (anArray.Value (aU * (myStacksNb + 1) + aV), aNormals.Value (aU * (myStacksNb + 1) + aV));
79 }
80 }
81}
82
83//=======================================================================
84//function : FillTriangulation
85//purpose :
86//=======================================================================
62ef08df 87void Prs3d_ToolQuadric::FillArray (Handle(Graphic3d_ArrayOfTriangles)& theArray,
88 Handle(Poly_Triangulation)& theTriangulation,
89 const gp_Trsf& theTrsf)
625e1958 90{
91 const Standard_Integer aTrianglesNb = TrianglesNb();
92 theArray = new Graphic3d_ArrayOfTriangles(aTrianglesNb * 3, 0, Standard_True);
93
94 Poly_Array1OfTriangle aPolyTriangles(1, aTrianglesNb);
95 TColgp_Array1OfPnt anArray(1, aTrianglesNb * 3);
96 NCollection_Array1<gp_Dir> aNormals(1, aTrianglesNb * 3);
97 fillArrays(theTrsf, anArray, aNormals);
98
99 // Fill triangles
100 for (Standard_Integer aU = 0, anIndex = 0; aU < mySlicesNb; ++aU)
101 {
102 for (Standard_Integer aV = 1; aV <= myStacksNb; ++aV)
103 {
104 theArray->AddVertex(anArray.Value(aU * (myStacksNb + 1) + aV), aNormals.Value(aU * (myStacksNb + 1) + aV));
105 theArray->AddVertex(anArray.Value((aU + 1) * (myStacksNb + 1) + aV), aNormals.Value((aU + 1) * (myStacksNb + 1) + aV));
106 theArray->AddVertex(anArray.Value((aU + 1) * (myStacksNb + 1) + (aV + 1)), aNormals.Value((aU + 1) * (myStacksNb + 1) + (aV + 1)));
107 theArray->AddVertex(anArray.Value((aU + 1) * (myStacksNb + 1) + (aV + 1)), aNormals.Value((aU + 1) * (myStacksNb + 1) + (aV + 1)));
108 theArray->AddVertex(anArray.Value(aU * (myStacksNb + 1) + (aV + 1)), aNormals.Value(aU * (myStacksNb + 1) + (aV + 1)));
109 theArray->AddVertex(anArray.Value(aU * (myStacksNb + 1) + aV), aNormals.Value(aU * (myStacksNb + 1) + aV));
110
111 aPolyTriangles.SetValue (++anIndex, Poly_Triangle(aU * (myStacksNb + 1) + aV,
112 (aU + 1) * (myStacksNb + 1) + aV,
113 (aU + 1) * (myStacksNb + 1) + (aV + 1)));
114 aPolyTriangles.SetValue (++anIndex, Poly_Triangle((aU + 1) * (myStacksNb + 1) + (aV + 1),
115 aU * (myStacksNb + 1) + (aV + 1),
116 aU * (myStacksNb + 1) + aV));
117 }
118 }
119
120 theTriangulation = new Poly_Triangulation (anArray, aPolyTriangles);
121}