1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00
occt/src/Prs3d/Prs3d_ToolQuadric.cxx
mzernova 7d6be4672b 0031733: Visualization, Prs3d_ToolQuadric - create indexed arrays
Prs3d_ToolQuadric has been modified to return an indexed triangulation.
Added methods Prs3d_ToolQuadric::CreateTriangulation() and Prs3d_ToolQuadric::CreateTriangulation()
as more straightforward API returning generated triangulation.
Added missing const to constant methods.

Confusing method Prs3d_ToolQuadric::FillArray() filling both
Graphic3d_ArrayOfTriangles and Poly_Triangulation at once has been marked deprecated.

V3d_Trihedron and AIS_Manipulator
now set Closed flag to groups with shaded sphere and arrows.
2020-09-23 20:18:08 +03:00

145 lines
5.9 KiB
C++

// Created on: 2016-02-04
// Created by: Anastasia BORISOVA
// Copyright (c) 2016 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <Prs3d_ToolQuadric.hxx>
#include <gp_Quaternion.hxx>
#include <Graphic3d_ArrayOfTriangles.hxx>
#include <Poly_Array1OfTriangle.hxx>
#include <TColgp_Array1OfPnt.hxx>
//=======================================================================
//function : FIllArray
//purpose :
//=======================================================================
void Prs3d_ToolQuadric::FillArray (Handle(Graphic3d_ArrayOfTriangles)& theArray,
const gp_Trsf& theTrsf) const
{
if (theArray.IsNull())
{
theArray = new Graphic3d_ArrayOfTriangles (VerticesNb(), TrianglesNb() * 3, Standard_True);
}
const Standard_Real aStepU = 1.0f / mySlicesNb;
const Standard_Real aStepV = 1.0f / myStacksNb;
if (!theArray->Indices().IsNull())
{
// indexed array
for (Standard_Integer aU = 0; aU <= mySlicesNb; ++aU)
{
const Standard_Real aParamU = aU * aStepU;
for (Standard_Integer aV = 0; aV <= myStacksNb; ++aV)
{
const Standard_Real aParamV = aV * aStepV;
const gp_Pnt aVertex = Vertex (aParamU, aParamV).Transformed (theTrsf);
const gp_Dir aNormal = Normal (aParamU, aParamV).Transformed (theTrsf);
theArray->AddVertex (aVertex, aNormal);
if (aU != 0 && aV != 0)
{
const int aVertId = theArray->VertexNumber();
theArray->AddEdge (aVertId);
theArray->AddEdge (aVertId - myStacksNb - 2);
theArray->AddEdge (aVertId - 1);
theArray->AddEdge (aVertId - myStacksNb - 2);
theArray->AddEdge (aVertId);
theArray->AddEdge (aVertId - myStacksNb - 1);
}
}
}
}
else
{
// non-indexed array
for (Standard_Integer aU = 0; aU < mySlicesNb; ++aU)
{
const Standard_Real aParamU = aU * aStepU;
for (Standard_Integer aV = 0; aV < myStacksNb; ++aV)
{
const Standard_Real aParamV = aV * aStepV;
theArray->AddVertex (Vertex (aParamU, aParamV).Transformed (theTrsf),
Normal (aParamU, aParamV).Transformed (theTrsf));
theArray->AddVertex (Vertex (aParamU + aStepU, aParamV).Transformed (theTrsf),
Normal (aParamU + aStepU, aParamV).Transformed (theTrsf));
theArray->AddVertex (Vertex (aParamU + aStepU, aParamV + aStepV).Transformed (theTrsf),
Normal (aParamU + aStepU, aParamV + aStepV).Transformed (theTrsf));
theArray->AddVertex (Vertex (aParamU + aStepU, aParamV + aStepV).Transformed (theTrsf),
Normal (aParamU + aStepU, aParamV + aStepV).Transformed (theTrsf));
theArray->AddVertex (Vertex (aParamU, aParamV + aStepV).Transformed (theTrsf),
Normal (aParamU, aParamV + aStepV).Transformed (theTrsf));
theArray->AddVertex (Vertex (aParamU, aParamV).Transformed (theTrsf),
Normal (aParamU, aParamV).Transformed (theTrsf));
}
}
}
}
//=======================================================================
//function : CreateTriangulation
//purpose :
//=======================================================================
Handle(Graphic3d_ArrayOfTriangles) Prs3d_ToolQuadric::CreateTriangulation (const gp_Trsf& theTrsf) const
{
Handle(Graphic3d_ArrayOfTriangles) aTriangulation;
FillArray (aTriangulation, theTrsf);
return aTriangulation;
}
//=======================================================================
//function : CreatePolyTriangulation
//purpose :
//=======================================================================
Handle(Poly_Triangulation) Prs3d_ToolQuadric::CreatePolyTriangulation (const gp_Trsf& theTrsf) const
{
Handle(Poly_Triangulation) aTriangulation = new Poly_Triangulation (VerticesNb(), TrianglesNb(), Standard_False);
TColgp_Array1OfPnt& aNodes = aTriangulation->ChangeNodes();
Poly_Array1OfTriangle& aTriangles = aTriangulation->ChangeTriangles();
Standard_ShortReal aStepU = 1.0f / mySlicesNb;
Standard_ShortReal aStepV = 1.0f / myStacksNb;
// Fill triangles
for (Standard_Integer aU = 0, anIndex = 0; aU <= mySlicesNb; ++aU)
{
const Standard_Real aParamU = aU * aStepU;
for (Standard_Integer aV = 0; aV <= myStacksNb; ++aV)
{
const Standard_ShortReal aParamV = aV * aStepV;
const Standard_Integer aVertId = aU * (myStacksNb + 1) + (aV + 1);
gp_Pnt aVertex = Vertex (aParamU, aParamV).Transformed (theTrsf);
aNodes.SetValue (aVertId, aVertex);
if (aU != 0 && aV != 0)
{
aTriangles.SetValue (++anIndex, Poly_Triangle (aVertId, aVertId - myStacksNb - 2, aVertId - 1));
aTriangles.SetValue (++anIndex, Poly_Triangle (aVertId - myStacksNb - 2, aVertId, aVertId - myStacksNb - 1));
}
}
}
return aTriangulation;
}
//=======================================================================
//function : FillArray
//purpose :
//=======================================================================
void Prs3d_ToolQuadric::FillArray (Handle(Graphic3d_ArrayOfTriangles)& theArray,
Handle(Poly_Triangulation)& theTriangulation,
const gp_Trsf& theTrsf) const
{
theArray = CreateTriangulation (theTrsf);
theTriangulation = CreatePolyTriangulation (theTrsf);
}