mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
0026007: Standard attribute for surface meshes in TDataStd
This commit is contained in:
@@ -14,15 +14,15 @@
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <Poly_Triangulation.hxx>
|
||||
|
||||
#include <gp_Pnt.hxx>
|
||||
#include <Poly_Triangle.hxx>
|
||||
#include <Poly_Triangulation.hxx>
|
||||
#include <Standard_DomainError.hxx>
|
||||
#include <Standard_NullObject.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Poly_Triangulation,MMgt_TShared)
|
||||
IMPLEMENT_STANDARD_RTTIEXT (Poly_Triangulation, MMgt_TShared)
|
||||
|
||||
//=======================================================================
|
||||
//function : Poly_Triangulation
|
||||
@@ -57,8 +57,6 @@ Poly_Triangulation::Poly_Triangulation(const TColgp_Array1OfPnt& Nodes,
|
||||
myTriangles = Triangles;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Poly_Triangulation
|
||||
//purpose :
|
||||
@@ -98,12 +96,32 @@ Handle(Poly_Triangulation) Poly_Triangulation::Copy() const
|
||||
return aCopy;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Poly_Triangulation
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Poly_Triangulation::Poly_Triangulation (const Handle(Poly_Triangulation)& theTriangulation)
|
||||
: myDeflection ( theTriangulation->myDeflection ),
|
||||
myNodes(theTriangulation->Nodes()),
|
||||
myTriangles(theTriangulation->Triangles())
|
||||
{
|
||||
if (theTriangulation->HasUVNodes())
|
||||
{
|
||||
myUVNodes = new TColgp_HArray1OfPnt2d(theTriangulation->myUVNodes->Array1());
|
||||
}
|
||||
if (theTriangulation->HasNormals())
|
||||
{
|
||||
myNormals = new TShort_HArray1OfShortReal(theTriangulation->myNormals->Array1());
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Deflection
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Real Poly_Triangulation::Deflection() const
|
||||
Standard_Real Poly_Triangulation::Deflection() const
|
||||
{
|
||||
return myDeflection;
|
||||
}
|
||||
@@ -113,13 +131,11 @@ Standard_Real Poly_Triangulation::Deflection() const
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Poly_Triangulation::Deflection(const Standard_Real D)
|
||||
void Poly_Triangulation::Deflection (const Standard_Real theDeflection)
|
||||
{
|
||||
myDeflection = D;
|
||||
myDeflection = theDeflection;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : RemoveUVNodes
|
||||
//purpose :
|
||||
@@ -135,7 +151,7 @@ void Poly_Triangulation::RemoveUVNodes()
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const TColgp_Array1OfPnt& Poly_Triangulation::Nodes() const
|
||||
const TColgp_Array1OfPnt& Poly_Triangulation::Nodes() const
|
||||
{
|
||||
return myNodes;
|
||||
}
|
||||
@@ -150,12 +166,40 @@ TColgp_Array1OfPnt& Poly_Triangulation::ChangeNodes()
|
||||
return myNodes;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Node
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const gp_Pnt& Poly_Triangulation::Node (const Standard_Integer theIndex) const
|
||||
{
|
||||
if (theIndex < 1 || theIndex > myNodes.Size())
|
||||
{
|
||||
Standard_OutOfRange::Raise ("Poly_Triangulation::Node : index out of range");
|
||||
}
|
||||
return myNodes.Value (theIndex);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ChangeNode
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
gp_Pnt& Poly_Triangulation::ChangeNode (const Standard_Integer theIndex)
|
||||
{
|
||||
if (theIndex < 1 || theIndex > myNodes.Size())
|
||||
{
|
||||
Standard_OutOfRange::Raise ("Poly_Triangulation::ChangeNode : index out of range");
|
||||
}
|
||||
return myNodes.ChangeValue (theIndex);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : UVNodes
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const TColgp_Array1OfPnt2d& Poly_Triangulation::UVNodes() const
|
||||
const TColgp_Array1OfPnt2d& Poly_Triangulation::UVNodes() const
|
||||
{
|
||||
return myUVNodes->Array1();
|
||||
}
|
||||
@@ -170,12 +214,40 @@ TColgp_Array1OfPnt2d& Poly_Triangulation::ChangeUVNodes()
|
||||
return myUVNodes->ChangeArray1();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : UVNode
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const gp_Pnt2d& Poly_Triangulation::UVNode (const Standard_Integer theIndex) const
|
||||
{
|
||||
if (myUVNodes.IsNull() || theIndex < 1 || theIndex > myUVNodes->Size())
|
||||
{
|
||||
Standard_OutOfRange::Raise ("Poly_Triangulation::UVNode : index out of range");
|
||||
}
|
||||
return myUVNodes->Value (theIndex);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ChangeUVNode
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
gp_Pnt2d& Poly_Triangulation::ChangeUVNode (const Standard_Integer theIndex)
|
||||
{
|
||||
if (myUVNodes.IsNull() || theIndex < 1 || theIndex > myUVNodes->Size())
|
||||
{
|
||||
Standard_OutOfRange::Raise ("Poly_Triangulation::ChangeUVNode : index out of range");
|
||||
}
|
||||
return myUVNodes->ChangeValue (theIndex);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Triangles
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const Poly_Array1OfTriangle& Poly_Triangulation::Triangles() const
|
||||
const Poly_Array1OfTriangle& Poly_Triangulation::Triangles() const
|
||||
{
|
||||
return myTriangles;
|
||||
}
|
||||
@@ -190,14 +262,40 @@ Poly_Array1OfTriangle& Poly_Triangulation::ChangeTriangles()
|
||||
return myTriangles;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Triangle
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const Poly_Triangle& Poly_Triangulation::Triangle (const Standard_Integer theIndex) const
|
||||
{
|
||||
if (theIndex < 1 || theIndex > myTriangles.Size())
|
||||
{
|
||||
Standard_OutOfRange::Raise ("Poly_Triangulation::Triangle : index out of range");
|
||||
}
|
||||
return myTriangles.Value (theIndex);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ChangeTriangle
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Poly_Triangle& Poly_Triangulation::ChangeTriangle (const Standard_Integer theIndex)
|
||||
{
|
||||
if (theIndex < 1 || theIndex > myTriangles.Size())
|
||||
{
|
||||
Standard_OutOfRange::Raise ("Poly_Triangulation::ChangeTriangle : index out of range");
|
||||
}
|
||||
return myTriangles.ChangeValue (theIndex);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetNormals
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Poly_Triangulation::SetNormals
|
||||
(const Handle(TShort_HArray1OfShortReal)& theNormals)
|
||||
void Poly_Triangulation::SetNormals (const Handle(TShort_HArray1OfShortReal)& theNormals)
|
||||
{
|
||||
|
||||
if(theNormals.IsNull() || theNormals->Length() != 3*myNbNodes) {
|
||||
@@ -205,7 +303,6 @@ void Poly_Triangulation::SetNormals
|
||||
}
|
||||
|
||||
myNormals = theNormals;
|
||||
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
@@ -222,7 +319,6 @@ const TShort_Array1OfShortReal& Poly_Triangulation::Normals() const
|
||||
}
|
||||
|
||||
return myNormals->Array1();
|
||||
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
@@ -230,7 +326,7 @@ const TShort_Array1OfShortReal& Poly_Triangulation::Normals() const
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TShort_Array1OfShortReal& Poly_Triangulation::ChangeNormals()
|
||||
TShort_Array1OfShortReal& Poly_Triangulation::ChangeNormals()
|
||||
{
|
||||
|
||||
if(myNormals.IsNull() || myNormals->Length() != 3*myNbNodes) {
|
||||
@@ -239,7 +335,6 @@ TShort_Array1OfShortReal& Poly_Triangulation::ChangeNormals()
|
||||
}
|
||||
|
||||
return myNormals->ChangeArray1();
|
||||
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
@@ -249,12 +344,45 @@ TShort_Array1OfShortReal& Poly_Triangulation::ChangeNormals()
|
||||
|
||||
Standard_Boolean Poly_Triangulation::HasNormals() const
|
||||
{
|
||||
|
||||
if(myNormals.IsNull() || myNormals->Length() != 3*myNbNodes) {
|
||||
return Standard_False;
|
||||
}
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetNormal
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Poly_Triangulation::SetNormal (const Standard_Integer theIndex, const gp_Dir& theNormal)
|
||||
{
|
||||
if (myNormals.IsNull() || theIndex < 1 || theIndex > myNodes.Size())
|
||||
{
|
||||
Standard_NullObject::Raise("Poly_Triangulation::SetNormal : empty array or index out of range");
|
||||
}
|
||||
|
||||
myNormals->ChangeValue (theIndex * 3 - 2) = (Standard_ShortReal) theNormal.X();
|
||||
myNormals->ChangeValue (theIndex * 3 - 1) = (Standard_ShortReal) theNormal.Y();
|
||||
myNormals->ChangeValue (theIndex * 3) = (Standard_ShortReal) theNormal.Z();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Normal
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const gp_Dir Poly_Triangulation::Normal (const Standard_Integer theIndex) const
|
||||
{
|
||||
if (myNormals.IsNull() || theIndex < 1 || theIndex > myNodes.Size())
|
||||
{
|
||||
Standard_NullObject::Raise("Poly_Triangulation::Normal : empty array or index out of range");
|
||||
}
|
||||
|
||||
gp_Dir N;
|
||||
N.SetX(myNormals->Value(theIndex * 3 - 2));
|
||||
N.SetY(myNormals->Value(theIndex * 3 - 1));
|
||||
N.SetZ(myNormals->Value(theIndex * 3));
|
||||
|
||||
return N;
|
||||
}
|
||||
|
@@ -18,8 +18,7 @@
|
||||
#define _Poly_Triangulation_HeaderFile
|
||||
|
||||
#include <Standard.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
|
||||
#include <Standard_DefineHandle.hxx>
|
||||
#include <Standard_Real.hxx>
|
||||
#include <Standard_Integer.hxx>
|
||||
#include <TColgp_Array1OfPnt.hxx>
|
||||
@@ -67,7 +66,8 @@ class Poly_Triangulation : public MMgt_TShared
|
||||
|
||||
public:
|
||||
|
||||
|
||||
DEFINE_STANDARD_RTTIEXT(Poly_Triangulation, MMgt_TShared)
|
||||
|
||||
//! Constructs a triangulation from a set of triangles. The
|
||||
//! triangulation is initialized without a triangle or a node, but capable of
|
||||
//! containing nbNodes nodes, and nbTriangles
|
||||
@@ -75,12 +75,12 @@ public:
|
||||
//! 2D nodes will be associated with 3D ones, (i.e. to
|
||||
//! enable a 2D representation).
|
||||
Standard_EXPORT Poly_Triangulation(const Standard_Integer nbNodes, const Standard_Integer nbTriangles, const Standard_Boolean UVNodes);
|
||||
|
||||
|
||||
//! Constructs a triangulation from a set of triangles. The
|
||||
//! triangulation is initialized with 3D points from Nodes and triangles
|
||||
//! from Triangles.
|
||||
Standard_EXPORT Poly_Triangulation(const TColgp_Array1OfPnt& Nodes, const Poly_Array1OfTriangle& Triangles);
|
||||
|
||||
|
||||
//! Constructs a triangulation from a set of triangles. The
|
||||
//! triangulation is initialized with 3D points from Nodes, 2D points from
|
||||
//! UVNodes and triangles from Triangles, where
|
||||
@@ -89,49 +89,57 @@ public:
|
||||
//! from Nodes on the surface approximated by the
|
||||
//! constructed triangulation.
|
||||
Standard_EXPORT Poly_Triangulation(const TColgp_Array1OfPnt& Nodes, const TColgp_Array1OfPnt2d& UVNodes, const Poly_Array1OfTriangle& Triangles);
|
||||
|
||||
|
||||
//! Creates full copy of current triangulation
|
||||
Standard_EXPORT virtual Handle(Poly_Triangulation) Copy() const;
|
||||
|
||||
|
||||
//! Copy constructor for triangulation.
|
||||
Standard_EXPORT Poly_Triangulation (const Handle(Poly_Triangulation)& theTriangulation);
|
||||
|
||||
//! Returns the deflection of this triangulation.
|
||||
Standard_EXPORT Standard_Real Deflection() const;
|
||||
|
||||
//! Sets the deflection of this triangulation to D.
|
||||
|
||||
//! Sets the deflection of this triangulation to theDeflection.
|
||||
//! See more on deflection in Polygon2D
|
||||
Standard_EXPORT void Deflection (const Standard_Real D);
|
||||
|
||||
Standard_EXPORT void Deflection (const Standard_Real theDeflection);
|
||||
|
||||
//! Deallocates the UV nodes.
|
||||
Standard_EXPORT void RemoveUVNodes();
|
||||
|
||||
|
||||
//! Returns the number of nodes for this triangulation.
|
||||
//! Null if the nodes are not yet defined.
|
||||
Standard_Integer NbNodes() const;
|
||||
|
||||
Standard_Integer NbNodes() const { return myNbNodes; }
|
||||
|
||||
//! Returns the number of triangles for this triangulation.
|
||||
//! Null if the Triangles are not yet defined.
|
||||
Standard_Integer NbTriangles() const;
|
||||
|
||||
//! Returns true if 2D nodes are associated with 3D nodes for
|
||||
//! this triangulation.
|
||||
Standard_Boolean HasUVNodes() const;
|
||||
|
||||
Standard_Integer NbTriangles() const { return myNbTriangles; }
|
||||
|
||||
//! Returns Standard_True if 2D nodes are associated with 3D nodes for this triangulation.
|
||||
Standard_Boolean HasUVNodes() const { return !myUVNodes.IsNull(); }
|
||||
|
||||
//! Returns the table of 3D nodes (3D points) for this triangulation.
|
||||
Standard_EXPORT const TColgp_Array1OfPnt& Nodes() const;
|
||||
|
||||
|
||||
//! Returns the table of 3D nodes (3D points) for this triangulation.
|
||||
//! The returned array is
|
||||
//! shared. Therefore if the table is selected by reference, you
|
||||
//! can, by simply modifying it, directly modify the data
|
||||
//! structure of this triangulation.
|
||||
Standard_EXPORT TColgp_Array1OfPnt& ChangeNodes();
|
||||
|
||||
|
||||
//! Returns node at the given index.
|
||||
//! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
|
||||
Standard_EXPORT const gp_Pnt& Node (const Standard_Integer theIndex) const;
|
||||
|
||||
//! Give access to the node at the given index.
|
||||
//! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
|
||||
Standard_EXPORT gp_Pnt& ChangeNode (const Standard_Integer theIndex);
|
||||
|
||||
//! Returns the table of 2D nodes (2D points) associated with
|
||||
//! each 3D node of this triangulation.
|
||||
//! The function HasUVNodes checks if 2D nodes
|
||||
//! are associated with the 3D nodes of this triangulation.
|
||||
//! Const reference on the 2d nodes values.
|
||||
Standard_EXPORT const TColgp_Array1OfPnt2d& UVNodes() const;
|
||||
|
||||
|
||||
//! Returns the table of 2D nodes (2D points) associated with
|
||||
//! each 3D node of this triangulation.
|
||||
//! Function ChangeUVNodes shares the returned array.
|
||||
@@ -139,56 +147,65 @@ public:
|
||||
//! you can, by simply modifying it, directly modify the data
|
||||
//! structure of this triangulation.
|
||||
Standard_EXPORT TColgp_Array1OfPnt2d& ChangeUVNodes();
|
||||
|
||||
|
||||
//! Returns UVNode at the given index.
|
||||
//! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
|
||||
Standard_EXPORT const gp_Pnt2d& UVNode (const Standard_Integer theIndex) const;
|
||||
|
||||
//! Give access to the UVNode at the given index.
|
||||
//! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
|
||||
Standard_EXPORT gp_Pnt2d& ChangeUVNode (const Standard_Integer theIndex);
|
||||
|
||||
//! Returns the table of triangles for this triangulation.
|
||||
Standard_EXPORT const Poly_Array1OfTriangle& Triangles() const;
|
||||
|
||||
|
||||
//! Returns the table of triangles for this triangulation.
|
||||
//! Function ChangeUVNodes shares the returned array.
|
||||
//! Therefore if the table is selected by reference,
|
||||
//! you can, by simply modifying it, directly modify the data
|
||||
//! structure of this triangulation.
|
||||
Standard_EXPORT Poly_Array1OfTriangle& ChangeTriangles();
|
||||
|
||||
|
||||
//! Returns triangle at the given index.
|
||||
//! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbTriangles.
|
||||
Standard_EXPORT const Poly_Triangle& Triangle (const Standard_Integer theIndex) const;
|
||||
|
||||
//! Give access to the triangle at the given index.
|
||||
//! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbTriangles.
|
||||
Standard_EXPORT Poly_Triangle& ChangeTriangle (const Standard_Integer theIndex);
|
||||
|
||||
//! Sets the table of node normals.
|
||||
//! raises exception if length of theNormals != 3*NbNodes
|
||||
Standard_EXPORT void SetNormals (const Handle(TShort_HArray1OfShortReal)& theNormals);
|
||||
|
||||
|
||||
//! Returns the table of node normals.
|
||||
Standard_EXPORT const TShort_Array1OfShortReal& Normals() const;
|
||||
|
||||
|
||||
//! Gives access to the table of node normals.
|
||||
Standard_EXPORT TShort_Array1OfShortReal& ChangeNormals();
|
||||
|
||||
|
||||
//! Returns Standard_True if nodal normals are defined.
|
||||
Standard_EXPORT Standard_Boolean HasNormals() const;
|
||||
|
||||
//! @return normal at the given index.
|
||||
//! Raises Standard_OutOfRange exception.
|
||||
Standard_EXPORT const gp_Dir Normal (const Standard_Integer theIndex) const;
|
||||
|
||||
|
||||
|
||||
DEFINE_STANDARD_RTTIEXT(Poly_Triangulation,MMgt_TShared)
|
||||
//! Changes normal at the given index.
|
||||
//! Raises Standard_OutOfRange exception.
|
||||
Standard_EXPORT void SetNormal (const Standard_Integer theIndex,
|
||||
const gp_Dir& theNormal);
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
Standard_Real myDeflection;
|
||||
Standard_Integer myNbNodes;
|
||||
Standard_Integer myNbTriangles;
|
||||
TColgp_Array1OfPnt myNodes;
|
||||
Handle(TColgp_HArray1OfPnt2d) myUVNodes;
|
||||
Poly_Array1OfTriangle myTriangles;
|
||||
Handle(TShort_HArray1OfShortReal) myNormals;
|
||||
|
||||
Standard_Real myDeflection;
|
||||
Standard_Integer myNbNodes;
|
||||
Standard_Integer myNbTriangles;
|
||||
TColgp_Array1OfPnt myNodes;
|
||||
Handle(TColgp_HArray1OfPnt2d) myUVNodes;
|
||||
Poly_Array1OfTriangle myTriangles;
|
||||
Handle(TShort_HArray1OfShortReal) myNormals;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#include <Poly_Triangulation.lxx>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // _Poly_Triangulation_HeaderFile
|
||||
|
Reference in New Issue
Block a user