mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-09-03 14:10:33 +03:00
0028010: Visualization, Prs3d_Arrow - add Shading presentation builder
StdPrs_ToolCylinder, StdPrs_ToolDisk, StdPrs_ToolQuadric and StdPrs_ToolSphere have been moved from StdPrs package to Prs3d.
This commit is contained in:
@@ -46,6 +46,14 @@ Prs3d_Text.cxx
|
||||
Prs3d_Text.hxx
|
||||
Prs3d_TextAspect.cxx
|
||||
Prs3d_TextAspect.hxx
|
||||
Prs3d_ToolDisk.hxx
|
||||
Prs3d_ToolDisk.cxx
|
||||
Prs3d_ToolCylinder.hxx
|
||||
Prs3d_ToolCylinder.cxx
|
||||
Prs3d_ToolQuadric.hxx
|
||||
Prs3d_ToolQuadric.cxx
|
||||
Prs3d_ToolSphere.hxx
|
||||
Prs3d_ToolSphere.cxx
|
||||
Prs3d_TypeOfHLR.hxx
|
||||
Prs3d_TypeOfLinePicking.hxx
|
||||
Prs3d_VertexDrawMode.hxx
|
||||
|
@@ -14,12 +14,17 @@
|
||||
|
||||
#include <Prs3d_Arrow.hxx>
|
||||
|
||||
#include <gp_Ax3.hxx>
|
||||
#include <gp_Dir.hxx>
|
||||
#include <gp_Pnt.hxx>
|
||||
#include <gp_Trsf.hxx>
|
||||
#include <Graphic3d_ArrayOfPolylines.hxx>
|
||||
#include <Graphic3d_ArrayOfSegments.hxx>
|
||||
#include <Graphic3d_Group.hxx>
|
||||
#include <Prs3d_Presentation.hxx>
|
||||
#include <Prs3d_ToolCylinder.hxx>
|
||||
#include <Prs3d_ToolDisk.hxx>
|
||||
#include <Prs3d_ToolSphere.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : Draw
|
||||
@@ -85,3 +90,61 @@ void Prs3d_Arrow::Draw(const Handle(Graphic3d_Group)& theGroup,
|
||||
theGroup->AddPrimitiveArray (aPrims1);
|
||||
theGroup->AddPrimitiveArray (aPrims2);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// function : DrawShaded
|
||||
// purpose :
|
||||
// ============================================================================
|
||||
Handle(Graphic3d_ArrayOfTriangles) Prs3d_Arrow::DrawShaded (const gp_Ax1& theAxis,
|
||||
const Standard_Real theTubeRadius,
|
||||
const Standard_Real theAxisLength,
|
||||
const Standard_Real theConeRadius,
|
||||
const Standard_Real theConeLength,
|
||||
const Standard_Integer theNbFacettes)
|
||||
{
|
||||
const Standard_Real aTubeLength = Max (0.0, theAxisLength - theConeLength);
|
||||
const Standard_Integer aNbTrisTube = (theTubeRadius > 0.0 && aTubeLength > 0.0)
|
||||
? Prs3d_ToolCylinder::TrianglesNb (theNbFacettes, 1)
|
||||
: 0;
|
||||
const Standard_Integer aNbTrisCone = (theConeRadius > 0.0 && theConeLength > 0.0)
|
||||
? (Prs3d_ToolDisk ::TrianglesNb (theNbFacettes, 1)
|
||||
+ Prs3d_ToolCylinder::TrianglesNb (theNbFacettes, 1))
|
||||
: 0;
|
||||
|
||||
const Standard_Integer aNbTris = aNbTrisTube + aNbTrisCone;
|
||||
if (aNbTris == 0)
|
||||
{
|
||||
return Handle(Graphic3d_ArrayOfTriangles)();
|
||||
}
|
||||
|
||||
Handle(Graphic3d_ArrayOfTriangles) anArray = new Graphic3d_ArrayOfTriangles (aNbTris * 3, 0, Standard_True);
|
||||
if (aNbTrisTube != 0)
|
||||
{
|
||||
gp_Ax3 aSystem (theAxis.Location(), theAxis.Direction());
|
||||
gp_Trsf aTrsf;
|
||||
aTrsf.SetTransformation (aSystem, gp_Ax3());
|
||||
|
||||
Prs3d_ToolCylinder aTool (theTubeRadius, theTubeRadius, aTubeLength, theNbFacettes, 1);
|
||||
aTool.FillArray (anArray, aTrsf);
|
||||
}
|
||||
|
||||
if (aNbTrisCone != 0)
|
||||
{
|
||||
gp_Pnt aConeOrigin = theAxis.Location().Translated (gp_Vec (theAxis.Direction().X() * aTubeLength,
|
||||
theAxis.Direction().Y() * aTubeLength,
|
||||
theAxis.Direction().Z() * aTubeLength));
|
||||
gp_Ax3 aSystem (aConeOrigin, theAxis.Direction());
|
||||
gp_Trsf aTrsf;
|
||||
aTrsf.SetTransformation (aSystem, gp_Ax3());
|
||||
{
|
||||
Prs3d_ToolDisk aTool (0.0, theConeRadius, theNbFacettes, 1);
|
||||
aTool.FillArray (anArray, aTrsf);
|
||||
}
|
||||
{
|
||||
Prs3d_ToolCylinder aTool (theConeRadius, 0.0, theConeLength, theNbFacettes, 1);
|
||||
aTool.FillArray (anArray, aTrsf);
|
||||
}
|
||||
}
|
||||
|
||||
return anArray;
|
||||
}
|
||||
|
@@ -18,9 +18,12 @@
|
||||
#define _Prs3d_Arrow_HeaderFile
|
||||
|
||||
#include <Prs3d_Root.hxx>
|
||||
|
||||
#include <Graphic3d_ArrayOfTriangles.hxx>
|
||||
#include <Quantity_PlaneAngle.hxx>
|
||||
#include <Quantity_Length.hxx>
|
||||
|
||||
class gp_Ax1;
|
||||
class gp_Pnt;
|
||||
class gp_Dir;
|
||||
|
||||
@@ -29,7 +32,19 @@ class Prs3d_Arrow : public Prs3d_Root
|
||||
{
|
||||
public:
|
||||
|
||||
DEFINE_STANDARD_ALLOC
|
||||
//! Defines the representation of the arrow as shaded triangulation.
|
||||
//! @param theAxis axis definition (arrow origin and direction)
|
||||
//! @param theTubeRadius tube (cylinder) radius
|
||||
//! @param theAxisLength overall arrow length (cylinder + cone)
|
||||
//! @param theConeRadius cone radius (arrow tip)
|
||||
//! @param theConeLength cone length (arrow tip)
|
||||
//! @param theNbFacettes tessellation quality for each part
|
||||
Standard_EXPORT static Handle(Graphic3d_ArrayOfTriangles) DrawShaded (const gp_Ax1& theAxis,
|
||||
const Standard_Real theTubeRadius,
|
||||
const Standard_Real theAxisLength,
|
||||
const Standard_Real theConeRadius,
|
||||
const Standard_Real theConeLength,
|
||||
const Standard_Integer theNbFacettes);
|
||||
|
||||
//! Defines the representation of the arrow.
|
||||
//! Note that this method does NOT assign any presentation aspects to the primitives group!
|
||||
|
80
src/Prs3d/Prs3d_ToolCylinder.cxx
Normal file
80
src/Prs3d/Prs3d_ToolCylinder.cxx
Normal file
@@ -0,0 +1,80 @@
|
||||
// Created on: 1995-07-27
|
||||
// Created by: Modelistation
|
||||
// Copyright (c) 1995-1999 Matra Datavision
|
||||
// Copyright (c) 1999-2014 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_ToolCylinder.hxx>
|
||||
|
||||
#include <Graphic3d_ArrayOfTriangles.hxx>
|
||||
#include <Poly_Array1OfTriangle.hxx>
|
||||
#include <Prs3d_ToolQuadric.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : Constructor
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Prs3d_ToolCylinder::Prs3d_ToolCylinder (const Standard_Real theBottomRad,
|
||||
const Standard_Real theTopRad,
|
||||
const Standard_Real theHeight,
|
||||
const Standard_Integer theNbSlices,
|
||||
const Standard_Integer theNbStacks)
|
||||
: myBottomRadius (theBottomRad),
|
||||
myTopRadius (theTopRad),
|
||||
myHeight (theHeight)
|
||||
{
|
||||
myStacksNb = theNbStacks;
|
||||
mySlicesNb = theNbSlices;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Vertex
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
gp_Pnt Prs3d_ToolCylinder::Vertex (const Standard_Real theU, const Standard_Real theV)
|
||||
{
|
||||
const Standard_Real aU = theU * M_PI * 2.0;
|
||||
const Standard_Real aRadius = myBottomRadius + (myTopRadius - myBottomRadius) * theV;
|
||||
return gp_Pnt (Cos (aU) * aRadius,
|
||||
Sin (aU) * aRadius,
|
||||
theV * myHeight);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Add
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
gp_Dir Prs3d_ToolCylinder::Normal (const Standard_Real theU, const Standard_Real /*theV*/)
|
||||
{
|
||||
const Standard_Real aU = theU * M_PI * 2.0;
|
||||
return gp_Dir (Cos (aU) * myHeight,
|
||||
Sin (aU) * myHeight,
|
||||
myBottomRadius - myTopRadius);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Perform
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Handle(Graphic3d_ArrayOfTriangles) Prs3d_ToolCylinder::Create (const Standard_Real theBottomRad,
|
||||
const Standard_Real theTopRad,
|
||||
const Standard_Real theHeight,
|
||||
const Standard_Integer theNbSlices,
|
||||
const Standard_Integer theNbStacks,
|
||||
const gp_Trsf& theTrsf)
|
||||
{
|
||||
Handle(Graphic3d_ArrayOfTriangles) anArray;
|
||||
Prs3d_ToolCylinder aTool (theBottomRad, theTopRad, theHeight, theNbSlices, theNbStacks);
|
||||
aTool.FillArray (anArray, theTrsf);
|
||||
return anArray;
|
||||
}
|
59
src/Prs3d/Prs3d_ToolCylinder.hxx
Normal file
59
src/Prs3d/Prs3d_ToolCylinder.hxx
Normal file
@@ -0,0 +1,59 @@
|
||||
// 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.
|
||||
|
||||
#ifndef _Prs3d_ToolCylinder_HeaderFile
|
||||
#define _Prs3d_ToolCylinder_HeaderFile
|
||||
|
||||
#include <Standard.hxx>
|
||||
#include <Prs3d_ToolQuadric.hxx>
|
||||
|
||||
//! Standard presentation algorithm that outputs graphical primitives for cylindrical surface.
|
||||
class Prs3d_ToolCylinder : public Prs3d_ToolQuadric
|
||||
{
|
||||
public:
|
||||
|
||||
//! Generate primitives for 3D quadric surface and return a filled array.
|
||||
Standard_EXPORT static Handle(Graphic3d_ArrayOfTriangles) Create (const Standard_Real theBottomRad,
|
||||
const Standard_Real theTopRad,
|
||||
const Standard_Real theHeight,
|
||||
const Standard_Integer theNbSlices,
|
||||
const Standard_Integer theNbStacks,
|
||||
const gp_Trsf& theTrsf);
|
||||
public:
|
||||
|
||||
//! Initializes the algorithm.
|
||||
Standard_EXPORT Prs3d_ToolCylinder (const Standard_Real theBottomRad,
|
||||
const Standard_Real theTopRad,
|
||||
const Standard_Real theHeight,
|
||||
const Standard_Integer theNbSlices,
|
||||
const Standard_Integer theNbStacks);
|
||||
|
||||
protected:
|
||||
|
||||
//! Computes vertex at given parameter location of the surface.
|
||||
Standard_EXPORT virtual gp_Pnt Vertex (const Standard_Real theU, const Standard_Real theV) Standard_OVERRIDE;
|
||||
|
||||
//! Computes normal at given parameter location of the surface.
|
||||
Standard_EXPORT virtual gp_Dir Normal (const Standard_Real theU, const Standard_Real theV) Standard_OVERRIDE;
|
||||
|
||||
protected:
|
||||
|
||||
Standard_Real myBottomRadius;
|
||||
Standard_Real myTopRadius;
|
||||
Standard_Real myHeight;
|
||||
|
||||
};
|
||||
|
||||
#endif // _Prs3d_ToolCylinder_HeaderFile
|
73
src/Prs3d/Prs3d_ToolDisk.cxx
Normal file
73
src/Prs3d/Prs3d_ToolDisk.cxx
Normal file
@@ -0,0 +1,73 @@
|
||||
// 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_ToolDisk.hxx>
|
||||
|
||||
#include <Graphic3d_ArrayOfTriangles.hxx>
|
||||
#include <Poly_Array1OfTriangle.hxx>
|
||||
#include <Prs3d_ToolQuadric.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : Constructor
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Prs3d_ToolDisk::Prs3d_ToolDisk (const Standard_Real theInnerRadius,
|
||||
const Standard_Real theOuterRadius,
|
||||
const Standard_Integer theNbSlices,
|
||||
const Standard_Integer theNbStacks)
|
||||
: myInnerRadius (theInnerRadius),
|
||||
myOuterRadius (theOuterRadius)
|
||||
{
|
||||
mySlicesNb = theNbSlices;
|
||||
myStacksNb = theNbStacks;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Vertex
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
gp_Pnt Prs3d_ToolDisk::Vertex (const Standard_Real theU, const Standard_Real theV)
|
||||
{
|
||||
const Standard_Real aU = theU * M_PI * 2.0;
|
||||
const Standard_Real aRadius = myInnerRadius + (myOuterRadius - myInnerRadius) * theV;
|
||||
return gp_Pnt (Cos (aU) * aRadius,
|
||||
Sin (aU) * aRadius,
|
||||
0.0);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Add
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
gp_Dir Prs3d_ToolDisk::Normal (const Standard_Real /*theU*/, const Standard_Real /*theV*/)
|
||||
{
|
||||
return gp_Dir (0.0, 0.0, -1.0);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Perform
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Handle(Graphic3d_ArrayOfTriangles) Prs3d_ToolDisk::Create (const Standard_Real theInnerRadius,
|
||||
const Standard_Real theOuterRadius,
|
||||
const Standard_Integer theNbSlices,
|
||||
const Standard_Integer theNbStacks,
|
||||
const gp_Trsf& theTrsf)
|
||||
{
|
||||
Handle(Graphic3d_ArrayOfTriangles) anArray;
|
||||
Prs3d_ToolDisk aTool (theInnerRadius, theOuterRadius, theNbSlices, theNbStacks);
|
||||
aTool.FillArray (anArray, theTrsf);
|
||||
return anArray;
|
||||
}
|
55
src/Prs3d/Prs3d_ToolDisk.hxx
Normal file
55
src/Prs3d/Prs3d_ToolDisk.hxx
Normal file
@@ -0,0 +1,55 @@
|
||||
// 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.
|
||||
|
||||
#ifndef _Prs3d_ToolDisk_HeaderFile
|
||||
#define _Prs3d_ToolDisk_HeaderFile
|
||||
|
||||
#include <Standard.hxx>
|
||||
#include <Prs3d_ToolQuadric.hxx>
|
||||
|
||||
//! Standard presentation algorithm that outputs graphical primitives for disk surface.
|
||||
class Prs3d_ToolDisk : public Prs3d_ToolQuadric
|
||||
{
|
||||
public:
|
||||
|
||||
//! Generate primitives for 3D quadric surface and return a filled array.
|
||||
Standard_EXPORT static Handle(Graphic3d_ArrayOfTriangles) Create (const Standard_Real theInnerRadius,
|
||||
const Standard_Real theOuterRadius,
|
||||
const Standard_Integer theNbSlices,
|
||||
const Standard_Integer theNbStacks,
|
||||
const gp_Trsf& theTrsf);
|
||||
public:
|
||||
|
||||
//! Initializes the algorithm.
|
||||
Standard_EXPORT Prs3d_ToolDisk (const Standard_Real theInnerRadius,
|
||||
const Standard_Real theOuterRadius,
|
||||
const Standard_Integer theNbSlices,
|
||||
const Standard_Integer theNbStacks);
|
||||
protected:
|
||||
|
||||
//! Computes vertex at given parameter location of the surface.
|
||||
Standard_EXPORT virtual gp_Pnt Vertex (const Standard_Real theU, const Standard_Real theV) Standard_OVERRIDE;
|
||||
|
||||
//! Computes normal at given parameter location of the surface.
|
||||
Standard_EXPORT virtual gp_Dir Normal (const Standard_Real theU, const Standard_Real theV) Standard_OVERRIDE;
|
||||
|
||||
protected:
|
||||
|
||||
Standard_Real myInnerRadius;
|
||||
Standard_Real myOuterRadius;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
121
src/Prs3d/Prs3d_ToolQuadric.cxx
Normal file
121
src/Prs3d/Prs3d_ToolQuadric.cxx
Normal file
@@ -0,0 +1,121 @@
|
||||
// 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 : fillArrays
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void Prs3d_ToolQuadric::fillArrays (const gp_Trsf& theTrsf, TColgp_Array1OfPnt& theArray, NCollection_Array1<gp_Dir>& theNormals)
|
||||
{
|
||||
Standard_ShortReal aStepU = 1.0f / mySlicesNb;
|
||||
Standard_ShortReal aStepV = 1.0f / myStacksNb;
|
||||
|
||||
for (Standard_Integer aU = 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);
|
||||
gp_Dir aNormal = Normal(aParamU, aParamV);
|
||||
|
||||
aVertex.Transform (theTrsf);
|
||||
aNormal.Transform (theTrsf);
|
||||
|
||||
theArray.SetValue (aVertId, aVertex);
|
||||
theNormals.SetValue (aVertId, aNormal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : FIllArray
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void Prs3d_ToolQuadric::FillArray (Handle(Graphic3d_ArrayOfTriangles)& theArray, const gp_Trsf& theTrsf)
|
||||
{
|
||||
const Standard_Integer aTrianglesNb = TrianglesNb();
|
||||
if (theArray.IsNull())
|
||||
{
|
||||
theArray = new Graphic3d_ArrayOfTriangles (aTrianglesNb * 3, 0, Standard_True);
|
||||
}
|
||||
|
||||
Poly_Array1OfTriangle aPolyTriangles (1, aTrianglesNb);
|
||||
TColgp_Array1OfPnt anArray (1, aTrianglesNb * 3);
|
||||
NCollection_Array1<gp_Dir> aNormals (1, aTrianglesNb * 3);
|
||||
fillArrays (theTrsf, anArray, aNormals);
|
||||
|
||||
// Fill primitives
|
||||
for (Standard_Integer aU = 0; aU < mySlicesNb; ++aU)
|
||||
{
|
||||
for (Standard_Integer aV = 1; aV <= myStacksNb; ++aV)
|
||||
{
|
||||
theArray->AddVertex (anArray.Value (aU * (myStacksNb + 1) + aV), aNormals.Value (aU * (myStacksNb + 1) + aV));
|
||||
theArray->AddVertex (anArray.Value ((aU + 1) * (myStacksNb + 1) + aV), aNormals.Value ((aU + 1) * (myStacksNb + 1) + aV));
|
||||
theArray->AddVertex (anArray.Value ((aU + 1) * (myStacksNb + 1) + (aV + 1)), aNormals.Value ((aU + 1) * (myStacksNb + 1) + (aV + 1)));
|
||||
theArray->AddVertex (anArray.Value ((aU + 1) * (myStacksNb + 1) + (aV + 1)), aNormals.Value ((aU + 1) * (myStacksNb + 1) + (aV + 1)));
|
||||
theArray->AddVertex (anArray.Value (aU * (myStacksNb + 1) + (aV + 1)), aNormals.Value (aU * (myStacksNb + 1) + (aV + 1)));
|
||||
theArray->AddVertex (anArray.Value (aU * (myStacksNb + 1) + aV), aNormals.Value (aU * (myStacksNb + 1) + aV));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : FillTriangulation
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void Prs3d_ToolQuadric::FillArray (Handle(Graphic3d_ArrayOfTriangles)& theArray,
|
||||
Handle(Poly_Triangulation)& theTriangulation,
|
||||
const gp_Trsf& theTrsf)
|
||||
{
|
||||
const Standard_Integer aTrianglesNb = TrianglesNb();
|
||||
theArray = new Graphic3d_ArrayOfTriangles(aTrianglesNb * 3, 0, Standard_True);
|
||||
|
||||
Poly_Array1OfTriangle aPolyTriangles(1, aTrianglesNb);
|
||||
TColgp_Array1OfPnt anArray(1, aTrianglesNb * 3);
|
||||
NCollection_Array1<gp_Dir> aNormals(1, aTrianglesNb * 3);
|
||||
fillArrays(theTrsf, anArray, aNormals);
|
||||
|
||||
// Fill triangles
|
||||
for (Standard_Integer aU = 0, anIndex = 0; aU < mySlicesNb; ++aU)
|
||||
{
|
||||
for (Standard_Integer aV = 1; aV <= myStacksNb; ++aV)
|
||||
{
|
||||
theArray->AddVertex(anArray.Value(aU * (myStacksNb + 1) + aV), aNormals.Value(aU * (myStacksNb + 1) + aV));
|
||||
theArray->AddVertex(anArray.Value((aU + 1) * (myStacksNb + 1) + aV), aNormals.Value((aU + 1) * (myStacksNb + 1) + aV));
|
||||
theArray->AddVertex(anArray.Value((aU + 1) * (myStacksNb + 1) + (aV + 1)), aNormals.Value((aU + 1) * (myStacksNb + 1) + (aV + 1)));
|
||||
theArray->AddVertex(anArray.Value((aU + 1) * (myStacksNb + 1) + (aV + 1)), aNormals.Value((aU + 1) * (myStacksNb + 1) + (aV + 1)));
|
||||
theArray->AddVertex(anArray.Value(aU * (myStacksNb + 1) + (aV + 1)), aNormals.Value(aU * (myStacksNb + 1) + (aV + 1)));
|
||||
theArray->AddVertex(anArray.Value(aU * (myStacksNb + 1) + aV), aNormals.Value(aU * (myStacksNb + 1) + aV));
|
||||
|
||||
aPolyTriangles.SetValue (++anIndex, Poly_Triangle(aU * (myStacksNb + 1) + aV,
|
||||
(aU + 1) * (myStacksNb + 1) + aV,
|
||||
(aU + 1) * (myStacksNb + 1) + (aV + 1)));
|
||||
aPolyTriangles.SetValue (++anIndex, Poly_Triangle((aU + 1) * (myStacksNb + 1) + (aV + 1),
|
||||
aU * (myStacksNb + 1) + (aV + 1),
|
||||
aU * (myStacksNb + 1) + aV));
|
||||
}
|
||||
}
|
||||
|
||||
theTriangulation = new Poly_Triangulation (anArray, aPolyTriangles);
|
||||
}
|
71
src/Prs3d/Prs3d_ToolQuadric.hxx
Normal file
71
src/Prs3d/Prs3d_ToolQuadric.hxx
Normal file
@@ -0,0 +1,71 @@
|
||||
// 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.
|
||||
|
||||
#ifndef _Prs3d_ToolQuadric_HeaderFile
|
||||
#define _Prs3d_ToolQuadric_HeaderFile
|
||||
|
||||
#include <gp_Ax1.hxx>
|
||||
#include <Graphic3d_ArrayOfPrimitives.hxx>
|
||||
#include <Graphic3d_ArrayOfTriangles.hxx>
|
||||
#include <Poly_Triangulation.hxx>
|
||||
#include <Prs3d_Root.hxx>
|
||||
#include <Prs3d_Drawer.hxx>
|
||||
#include <SelectMgr_Selection.hxx>
|
||||
#include <Standard.hxx>
|
||||
|
||||
//! Base class to build 3D surfaces presentation of quadric surfaces.
|
||||
class Prs3d_ToolQuadric
|
||||
{
|
||||
public:
|
||||
|
||||
DEFINE_STANDARD_ALLOC
|
||||
|
||||
//! Generate primitives for 3D quadric surface and fill the given array. Optional transformation is applied.
|
||||
Standard_EXPORT void FillArray (Handle(Graphic3d_ArrayOfTriangles)& theArray, const gp_Trsf& theTrsf);
|
||||
|
||||
//! Generate primitives for 3D quadric surface presentation and fill the given array and poly triangulation structure. Optional transformation is applied.
|
||||
Standard_EXPORT void FillArray (Handle(Graphic3d_ArrayOfTriangles)& theArray, Handle(Poly_Triangulation)& theTriangulation, const gp_Trsf& theTrsf);
|
||||
|
||||
//! Number of triangles for presentation with the given params.
|
||||
static Standard_Integer TrianglesNb (const Standard_Integer theSlicesNb,
|
||||
const Standard_Integer theStacksNb)
|
||||
{
|
||||
return theSlicesNb * theStacksNb * 2;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
//! Method implements an algorithm to generate arrays of vertices and normals for 3D surface.
|
||||
Standard_EXPORT void fillArrays (const gp_Trsf& theTrsf, TColgp_Array1OfPnt& theArray, NCollection_Array1<gp_Dir>& theNormals);
|
||||
|
||||
//! Number of triangles in generated presentation.
|
||||
Standard_Integer TrianglesNb() const
|
||||
{
|
||||
return mySlicesNb * myStacksNb * 2;
|
||||
}
|
||||
|
||||
//! Redefine this method to generate vertex at given parameters.
|
||||
virtual gp_Pnt Vertex (const Standard_Real theU, const Standard_Real theV) = 0;
|
||||
|
||||
//! Redefine this method to generate normal at given parameters.
|
||||
virtual gp_Dir Normal (const Standard_Real theU, const Standard_Real theV) = 0;
|
||||
|
||||
protected:
|
||||
|
||||
Standard_Integer mySlicesNb;
|
||||
Standard_Integer myStacksNb;
|
||||
};
|
||||
|
||||
#endif // _Prs3d_ToolQuadric_HeaderFile
|
74
src/Prs3d/Prs3d_ToolSphere.cxx
Normal file
74
src/Prs3d/Prs3d_ToolSphere.cxx
Normal file
@@ -0,0 +1,74 @@
|
||||
// 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_ToolSphere.hxx>
|
||||
|
||||
#include <Graphic3d_ArrayOfTriangles.hxx>
|
||||
#include <Poly_Array1OfTriangle.hxx>
|
||||
#include <Prs3d_ToolQuadric.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : Constructor
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Prs3d_ToolSphere::Prs3d_ToolSphere (const Standard_Real theRadius,
|
||||
const Standard_Integer theNbSlices,
|
||||
const Standard_Integer theNbStacks)
|
||||
: myRadius (theRadius)
|
||||
{
|
||||
mySlicesNb = theNbSlices;
|
||||
myStacksNb = theNbStacks;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Vertex
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
gp_Pnt Prs3d_ToolSphere::Vertex (const Standard_Real theU, const Standard_Real theV)
|
||||
{
|
||||
const Standard_Real aU = theU * M_PI * 2.0;
|
||||
const Standard_Real aV = theV * M_PI;
|
||||
return gp_Pnt (myRadius * Cos (aU) * Sin (aV),
|
||||
-myRadius * Sin (aU) * Sin (aV),
|
||||
myRadius * Cos (aV));
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Add
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
gp_Dir Prs3d_ToolSphere::Normal (const Standard_Real theU, const Standard_Real theV)
|
||||
{
|
||||
const Standard_Real aU = theU * M_PI * 2.0;
|
||||
const Standard_Real aV = theV * M_PI;
|
||||
return gp_Dir (Cos (aU) * Sin (aV),
|
||||
-Sin (aU) * Sin (aV),
|
||||
Cos (aV));
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Perform
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Handle(Graphic3d_ArrayOfTriangles) Prs3d_ToolSphere::Create (const Standard_Real theRadius,
|
||||
const Standard_Integer theNbSlices,
|
||||
const Standard_Integer theNbStacks,
|
||||
const gp_Trsf& theTrsf)
|
||||
{
|
||||
Handle(Graphic3d_ArrayOfTriangles) anArray;
|
||||
Prs3d_ToolSphere aTool (theRadius, theNbSlices, theNbStacks);
|
||||
aTool.FillArray (anArray, theTrsf);
|
||||
return anArray;
|
||||
}
|
60
src/Prs3d/Prs3d_ToolSphere.hxx
Normal file
60
src/Prs3d/Prs3d_ToolSphere.hxx
Normal file
@@ -0,0 +1,60 @@
|
||||
// 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.
|
||||
|
||||
#ifndef _Prs3d_ToolSphere_HeaderFile
|
||||
#define _Prs3d_ToolSphere_HeaderFile
|
||||
|
||||
#include <Graphic3d_ArrayOfPrimitives.hxx>
|
||||
#include <Graphic3d_ArrayOfTriangles.hxx>
|
||||
#include <Poly_Triangulation.hxx>
|
||||
#include <Prs3d_Root.hxx>
|
||||
#include <Prs3d_Drawer.hxx>
|
||||
#include <SelectMgr_Selection.hxx>
|
||||
#include <Standard.hxx>
|
||||
#include <Standard_Handle.hxx>
|
||||
#include <Prs3d_ToolQuadric.hxx>
|
||||
|
||||
//! Standard presentation algorithm that outputs graphical primitives for spherical surface.
|
||||
class Prs3d_ToolSphere : public Prs3d_ToolQuadric
|
||||
{
|
||||
public:
|
||||
|
||||
//! Generate primitives for 3D quadric surface and return a filled array.
|
||||
Standard_EXPORT static Handle(Graphic3d_ArrayOfTriangles) Create (const Standard_Real theRadius,
|
||||
const Standard_Integer theNbSlices,
|
||||
const Standard_Integer theNbStacks,
|
||||
const gp_Trsf& theTrsf);
|
||||
public:
|
||||
|
||||
//! Initializes the algorithm.
|
||||
Standard_EXPORT Prs3d_ToolSphere (const Standard_Real theRadius,
|
||||
const Standard_Integer theNbSlices,
|
||||
const Standard_Integer theNbStacks);
|
||||
|
||||
protected:
|
||||
|
||||
//! Computes vertex at given parameter location of the surface.
|
||||
Standard_EXPORT virtual gp_Pnt Vertex (const Standard_Real theU, const Standard_Real theV) Standard_OVERRIDE;
|
||||
|
||||
//! Computes normal at given parameter location of the surface.
|
||||
Standard_EXPORT virtual gp_Dir Normal (const Standard_Real theU, const Standard_Real theV) Standard_OVERRIDE;
|
||||
|
||||
protected:
|
||||
|
||||
Standard_Real myRadius;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user