1 // Created on: 2016-02-04
2 // Created by: Anastasia BORISOVA
3 // Copyright (c) 2016 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <Prs3d_ToolQuadric.hxx>
18 #include <Graphic3d_ArrayOfTriangles.hxx>
19 #include <Poly_Array1OfTriangle.hxx>
21 //=======================================================================
22 //function : FIllArray
24 //=======================================================================
25 void Prs3d_ToolQuadric::FillArray (Handle(Graphic3d_ArrayOfTriangles)& theArray,
26 const gp_Trsf& theTrsf) const
28 if (theArray.IsNull())
30 theArray = new Graphic3d_ArrayOfTriangles (VerticesNb(), TrianglesNb() * 3, Graphic3d_ArrayFlags_VertexNormal);
33 const Standard_Real aStepU = 1.0f / mySlicesNb;
34 const Standard_Real aStepV = 1.0f / myStacksNb;
35 if (theArray->EdgeNumberAllocated() > 0)
38 for (Standard_Integer aU = 0; aU <= mySlicesNb; ++aU)
40 const Standard_Real aParamU = aU * aStepU;
41 for (Standard_Integer aV = 0; aV <= myStacksNb; ++aV)
43 const Standard_Real aParamV = aV * aStepV;
44 const gp_Pnt aVertex = Vertex (aParamU, aParamV).Transformed (theTrsf);
45 const gp_Dir aNormal = Normal (aParamU, aParamV).Transformed (theTrsf);
46 theArray->AddVertex (aVertex, aNormal);
48 if (aU != 0 && aV != 0)
50 const int aVertId = theArray->VertexNumber();
51 theArray->AddTriangleEdges (aVertId, aVertId - myStacksNb - 2, aVertId - 1);
52 theArray->AddTriangleEdges (aVertId - myStacksNb - 2, aVertId, aVertId - myStacksNb - 1);
60 for (Standard_Integer aU = 0; aU < mySlicesNb; ++aU)
62 const Standard_Real aParamU = aU * aStepU;
63 for (Standard_Integer aV = 0; aV < myStacksNb; ++aV)
65 const Standard_Real aParamV = aV * aStepV;
66 theArray->AddVertex (Vertex (aParamU, aParamV).Transformed (theTrsf),
67 Normal (aParamU, aParamV).Transformed (theTrsf));
68 theArray->AddVertex (Vertex (aParamU + aStepU, aParamV).Transformed (theTrsf),
69 Normal (aParamU + aStepU, aParamV).Transformed (theTrsf));
70 theArray->AddVertex (Vertex (aParamU + aStepU, aParamV + aStepV).Transformed (theTrsf),
71 Normal (aParamU + aStepU, aParamV + aStepV).Transformed (theTrsf));
72 theArray->AddVertex (Vertex (aParamU + aStepU, aParamV + aStepV).Transformed (theTrsf),
73 Normal (aParamU + aStepU, aParamV + aStepV).Transformed (theTrsf));
74 theArray->AddVertex (Vertex (aParamU, aParamV + aStepV).Transformed (theTrsf),
75 Normal (aParamU, aParamV + aStepV).Transformed (theTrsf));
76 theArray->AddVertex (Vertex (aParamU, aParamV).Transformed (theTrsf),
77 Normal (aParamU, aParamV).Transformed (theTrsf));
83 //=======================================================================
84 //function : CreateTriangulation
86 //=======================================================================
87 Handle(Graphic3d_ArrayOfTriangles) Prs3d_ToolQuadric::CreateTriangulation (const gp_Trsf& theTrsf) const
89 Handle(Graphic3d_ArrayOfTriangles) aTriangulation;
90 FillArray (aTriangulation, theTrsf);
91 return aTriangulation;
94 //=======================================================================
95 //function : CreatePolyTriangulation
97 //=======================================================================
98 Handle(Poly_Triangulation) Prs3d_ToolQuadric::CreatePolyTriangulation (const gp_Trsf& theTrsf) const
100 Handle(Poly_Triangulation) aTriangulation = new Poly_Triangulation (VerticesNb(), TrianglesNb(), Standard_False);
101 Standard_ShortReal aStepU = 1.0f / mySlicesNb;
102 Standard_ShortReal aStepV = 1.0f / myStacksNb;
105 for (Standard_Integer aU = 0, anIndex = 0; aU <= mySlicesNb; ++aU)
107 const Standard_Real aParamU = aU * aStepU;
108 for (Standard_Integer aV = 0; aV <= myStacksNb; ++aV)
110 const Standard_ShortReal aParamV = aV * aStepV;
111 const Standard_Integer aVertId = aU * (myStacksNb + 1) + (aV + 1);
112 gp_Pnt aVertex = Vertex (aParamU, aParamV).Transformed (theTrsf);
114 aTriangulation->SetNode (aVertId, aVertex);
115 if (aU != 0 && aV != 0)
117 aTriangulation->SetTriangle (++anIndex, Poly_Triangle (aVertId, aVertId - myStacksNb - 2, aVertId - 1));
118 aTriangulation->SetTriangle (++anIndex, Poly_Triangle (aVertId - myStacksNb - 2, aVertId, aVertId - myStacksNb - 1));
122 return aTriangulation;
125 //=======================================================================
126 //function : FillArray
128 //=======================================================================
129 void Prs3d_ToolQuadric::FillArray (Handle(Graphic3d_ArrayOfTriangles)& theArray,
130 Handle(Poly_Triangulation)& theTriangulation,
131 const gp_Trsf& theTrsf) const
133 theArray = CreateTriangulation (theTrsf);
134 theTriangulation = CreatePolyTriangulation (theTrsf);