From: vro Date: Sun, 14 Feb 2021 06:07:54 +0000 (+0300) Subject: 0025936: Modeling Data - reusable data structure for 2D tesselation (3- and 4-nodal... X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=b0b103c05ce940f2bf64e3cc3623046c3b1369e1;p=occt-copy.git 0025936: Modeling Data - reusable data structure for 2D tesselation (3- and 4-nodal mesh) // Added TDataXtd_SurfacicMesh.hxx and cxx to the git. --- diff --git a/src/TDataXtd/TDataXtd_SurfacicMesh.cxx b/src/TDataXtd/TDataXtd_SurfacicMesh.cxx new file mode 100644 index 0000000000..6c3bb758ff --- /dev/null +++ b/src/TDataXtd/TDataXtd_SurfacicMesh.cxx @@ -0,0 +1,419 @@ +// Created on: 2015-12-10 +// Created by: Vlad Romashko +// Copyright (c) 2015 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 +#include +#include +#include +#include +#include + +//======================================================================= +//function : GetID +//purpose : +//======================================================================= +const Standard_GUID& TDataXtd_SurfacicMesh::GetID() +{ + static Standard_GUID TDataXtd_SurfacicMeshID ("D7E3F1CF-38A4-4DCA-94F4-51C31F3FCBA5"); + return TDataXtd_SurfacicMeshID; +} + +//======================================================================= +//function : SetAttr +//purpose : +//======================================================================= +static Handle(TDataXtd_SurfacicMesh) SetAttr (const TDF_Label& theLabel, + const Standard_GUID& theID) +{ + Handle(TDataXtd_SurfacicMesh) hMesh; + if (!theLabel.FindAttribute (theID, hMesh)) { + hMesh = new TDataXtd_SurfacicMesh(); + hMesh->SetID (theID); + theLabel.AddAttribute (hMesh); + } + return hMesh; +} + +//======================================================================= +//function : Set +//purpose : +//======================================================================= +Handle(TDataXtd_SurfacicMesh) TDataXtd_SurfacicMesh::Set (const TDF_Label& theLabel) +{ + return SetAttr (theLabel, GetID()); +} + +//======================================================================= +//function : Set +//purpose : +//======================================================================= +Handle(TDataXtd_SurfacicMesh) TDataXtd_SurfacicMesh::Set (const TDF_Label& theLabel, + const Standard_GUID& theID) +{ + return SetAttr (theLabel, theID); +} + +//======================================================================= +//function : Set +//purpose : +//======================================================================= +Handle(TDataXtd_SurfacicMesh) TDataXtd_SurfacicMesh::Set (const TDF_Label& theLabel, + const Handle(Poly_Mesh)& theMesh) +{ + Handle(TDataXtd_SurfacicMesh) hMesh = Set (theLabel); + hMesh->Set (theMesh); + return hMesh; +} + +//======================================================================= +//function : Set +//purpose : +//======================================================================= +Handle(TDataXtd_SurfacicMesh) TDataXtd_SurfacicMesh::Set (const TDF_Label& theLabel, + const Standard_GUID& theID, + const Handle(Poly_Mesh)& theMesh) +{ + Handle(TDataXtd_SurfacicMesh) hMesh = Set (theLabel, theID); + hMesh->Set (theMesh); + return hMesh; +} + +//======================================================================= +//function : TDataXtd_SurfacicMesh +//purpose : +//======================================================================= +TDataXtd_SurfacicMesh::TDataXtd_SurfacicMesh():myID (GetID()) +{ + +} + +//======================================================================= +//function : TDataXtd_SurfacicMesh +//purpose : +//======================================================================= +void TDataXtd_SurfacicMesh::Set (const Handle(Poly_Mesh)& theMesh) +{ + Backup(); + myMesh = theMesh; +} + +//======================================================================= +//function : TDataXtd_SurfacicMesh +//purpose : +//======================================================================= +const Handle(Poly_Mesh)& TDataXtd_SurfacicMesh::Get() const +{ + return myMesh; +} + +// Poly_Mesh methods + +//======================================================================= +//function : Deflection +//purpose : +//======================================================================= +Standard_Real TDataXtd_SurfacicMesh::Deflection() const +{ + return myMesh->Deflection(); +} + +//======================================================================= +//function : Deflection +//purpose : +//======================================================================= +void TDataXtd_SurfacicMesh::Deflection (const Standard_Real theDeflection) +{ + Backup(); + myMesh->Deflection (theDeflection); +} + +//======================================================================= +//function : RemoveUVNodes +//purpose : +//======================================================================= +void TDataXtd_SurfacicMesh::RemoveUVNodes() +{ + Backup(); + myMesh->RemoveUVNodes(); +} + +//======================================================================= +//function : NbNodes +//purpose : +//======================================================================= +Standard_Integer TDataXtd_SurfacicMesh::NbNodes() const +{ + return myMesh->NbNodes(); +} + +//======================================================================= +//function : NbTriangles +//purpose : +//======================================================================= +Standard_Integer TDataXtd_SurfacicMesh::NbTriangles() const +{ + return myMesh->NbTriangles(); +} + +//======================================================================= +//function : NbQuads +//purpose : +//======================================================================= +Standard_Integer TDataXtd_SurfacicMesh::NbQuads() const +{ + return myMesh->NbQuads(); +} + +//======================================================================= +//function : HasUVNodes +//purpose : +//======================================================================= +Standard_Boolean TDataXtd_SurfacicMesh::HasUVNodes() const +{ + return myMesh->HasUVNodes(); +} + +//======================================================================= +//function : SetNode +//purpose : +//======================================================================= +void TDataXtd_SurfacicMesh::SetNode (const Standard_Integer& theIndex, const gp_Pnt& theNode) +{ + Backup(); + myMesh->ChangeNode (theIndex) = theNode; +} + +//======================================================================= +//function : Node +//purpose : +//======================================================================= +const gp_Pnt& TDataXtd_SurfacicMesh::Node (const Standard_Integer theIndex) const +{ + return myMesh->Node (theIndex); +} + +//======================================================================= +//function : SetUVNode +//purpose : +//======================================================================= +void TDataXtd_SurfacicMesh::SetUVNode(const Standard_Integer theIndex, const gp_Pnt2d& theUVNode) +{ + Backup(); + myMesh->ChangeUVNode (theIndex) = theUVNode; +} + +//======================================================================= +//function : UVNode +//purpose : +//======================================================================= +const gp_Pnt2d& TDataXtd_SurfacicMesh::UVNode (const Standard_Integer theIndex) const +{ + return myMesh->UVNode (theIndex); +} + +//======================================================================= +//function : SetTriangle +//purpose : +//======================================================================= +void TDataXtd_SurfacicMesh::SetTriangle (const Standard_Integer theIndex, const Poly_Triangle& theTriangle) +{ + Backup(); + myMesh->ChangeTriangle (theIndex) = theTriangle; +} + +//======================================================================= +//function : Triangle +//purpose : +//======================================================================= +const Poly_Triangle& TDataXtd_SurfacicMesh::Triangle(const Standard_Integer theIndex) const +{ + return myMesh->Triangle (theIndex); +} + +//======================================================================= +//function : SetQuad +//purpose : +//======================================================================= +void TDataXtd_SurfacicMesh::SetQuad (const Standard_Integer theIndex, const Poly_Quad& theQuad) +{ + Backup(); + myMesh->ChangeQuad (theIndex) = theQuad; +} + +//======================================================================= +//function : Quad +//purpose : +//======================================================================= +const Poly_Quad& TDataXtd_SurfacicMesh::Quad (const Standard_Integer theIndex) const +{ + return myMesh->Quad (theIndex); +} + +//======================================================================= +//function : HasNormals +//purpose : +//======================================================================= +Standard_Boolean TDataXtd_SurfacicMesh::HasNormals() const +{ + return myMesh->HasNormals(); +} + +//======================================================================= +//function : SetNormal +//purpose : +//======================================================================= +void TDataXtd_SurfacicMesh::SetNormal (const Standard_Integer theIndex, + const gp_XYZ& theNormal) +{ + Backup(); + myMesh->SetNormal (theIndex, theNormal); +} + +//======================================================================= +//function : SetNormal +//purpose : +//======================================================================= +void TDataXtd_SurfacicMesh::SetNormal (const Standard_Integer theIndex, + const Standard_ShortReal theNormalX, + const Standard_ShortReal theNormalY, + const Standard_ShortReal theNormalZ) +{ + Backup(); + myMesh->SetNormal (theIndex, theNormalX, theNormalY, theNormalZ); +} + +//======================================================================= +//function : Normal +//purpose : +//======================================================================= +const Vec3f& TDataXtd_SurfacicMesh::Normal (const Standard_Integer theIndex) const +{ + return myMesh->Normal (theIndex); +} + +//======================================================================= +//function : SetID +//purpose : +//======================================================================= +void TDataXtd_SurfacicMesh::SetID (const Standard_GUID& theID) +{ + if (myID != theID) { + Backup(); + myID = theID; + } +} + +//======================================================================= +//function : SetID +//purpose : +//======================================================================= +void TDataXtd_SurfacicMesh::SetID() +{ + Backup(); + myID = GetID(); +} + +//======================================================================= +//function : ID +//purpose : +//======================================================================= +const Standard_GUID& TDataXtd_SurfacicMesh::ID () const +{ + return myID; +} + +//======================================================================= +//function : NewEmpty +//purpose : +//======================================================================= +Handle(TDF_Attribute) TDataXtd_SurfacicMesh::NewEmpty () const +{ + return new TDataXtd_SurfacicMesh(); +} + +//======================================================================= +//function : Restore +//purpose : +//======================================================================= +void TDataXtd_SurfacicMesh::Restore (const Handle(TDF_Attribute)& theWithMesh) +{ + myMesh.Nullify(); + Handle(TDataXtd_SurfacicMesh) withMesh = Handle(TDataXtd_SurfacicMesh)::DownCast (theWithMesh); + if (!withMesh->myMesh.IsNull()) { + Handle(Poly_Triangulation) withTris = withMesh->myMesh->Copy(); + if (!withTris.IsNull()) + myMesh = Handle(Poly_Mesh)::DownCast (withTris); + } +} + +//======================================================================= +//function : Paste +//purpose : +//======================================================================= +void TDataXtd_SurfacicMesh::Paste (const Handle(TDF_Attribute)& theIntoMesh, + const Handle(TDF_RelocationTable)& ) const +{ + Handle(TDataXtd_SurfacicMesh) intoMesh = Handle(TDataXtd_SurfacicMesh)::DownCast (theIntoMesh); + intoMesh->myMesh.Nullify(); + if (!myMesh.IsNull()) { + Handle(Poly_Triangulation) aTris = myMesh->Copy(); + if (!aTris.IsNull()) + intoMesh->myMesh = Handle(Poly_Mesh)::DownCast (aTris); + } +} + +//======================================================================= +//function : Dump +//purpose : +//======================================================================= +Standard_OStream& TDataXtd_SurfacicMesh::Dump (Standard_OStream& theOS) const +{ + theOS << "Mesh: "; + + Standard_Character aStrID[Standard_GUID_SIZE_ALLOC]; + myID.ToCString (aStrID); + theOS << aStrID; + + if (!myMesh.IsNull()) { + theOS << "\n\tDeflection: " << myMesh->Deflection(); + theOS << "\n\tNodes: " << myMesh->NbNodes(); + theOS << "\n\tTriangles: " << myMesh->NbTriangles(); + theOS << "\n\tQuadrangles: " << myMesh->NbQuads(); + if (myMesh->HasUVNodes()) + theOS << "\n\tHas UV-Nodes"; + else + theOS << "\n\tNo UV-Nodes"; + if (myMesh->HasNormals()) + theOS << "\n\tHas normals"; + else + theOS << "\n\tNo normals"; + } + + theOS << "\nAttribute fields: "; + TDF_Attribute::Dump (theOS); + return theOS; +} + +//======================================================================= +//function : DumpJson +//purpose : +//======================================================================= +void TDataXtd_SurfacicMesh::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const +{ + OCCT_DUMP_TRANSIENT_CLASS_BEGIN(theOStream) + OCCT_DUMP_BASE_CLASS(theOStream, theDepth, TDF_Attribute) + if (!myMesh.IsNull()) + myMesh->DumpJson (theOStream, theDepth); +} diff --git a/src/TDataXtd/TDataXtd_SurfacicMesh.hxx b/src/TDataXtd/TDataXtd_SurfacicMesh.hxx new file mode 100644 index 0000000000..f8a1d7c220 --- /dev/null +++ b/src/TDataXtd/TDataXtd_SurfacicMesh.hxx @@ -0,0 +1,186 @@ +// Created on: 2015-12-10 +// Created by: Vlad Romashko +// Copyright (c) 2015 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 _TDataXtd_SurfacicMesh_HeaderFile +#define _TDataXtd_SurfacicMesh_HeaderFile + +#include +#include + +#include +#include +#include +#include +#include +#include + +class TDF_Label; +class TDF_RelocationTable; + +class TDataXtd_SurfacicMesh; +DEFINE_STANDARD_HANDLE(TDataXtd_SurfacicMesh, TDF_Attribute) + +//! An Ocaf attribute containing a mesh (Poly_Mesh). +//! It includes all methods of Poly_Mesh (and Poly_Triangulation). +class TDataXtd_SurfacicMesh : public TDF_Attribute +{ +public: + + //! Static methods + // ============== + + //! Returns the ID of the mesh attribute. + Standard_EXPORT static const Standard_GUID& GetID(); + + //! Finds or creates a mesh attribute. + Standard_EXPORT static Handle(TDataXtd_SurfacicMesh) Set (const TDF_Label& theLabel); + + //! Finds or creates a mesh attribute with specified ID. + //! It allows setting several mesh-attributes at the same label. + Standard_EXPORT static Handle(TDataXtd_SurfacicMesh) Set (const TDF_Label& theLabel, + const Standard_GUID& theID); + + //! Finds or creates a mesh attribute. + //! Initializes the attribute by a mesh (Poly_Mesh) object. + //! If the mesh consists of only triangles, + //! you may put Poly_Triangulation object as a 2nd parameter of this method. + Standard_EXPORT static Handle(TDataXtd_SurfacicMesh) Set (const TDF_Label& theLabel, + const Handle(Poly_Mesh)& theMesh); + + //! Finds or creates a mesh attribute (the same method as above). + //! Additionally, it allows setting several mesh-attributes at the same label. + Standard_EXPORT static Handle(TDataXtd_SurfacicMesh) Set (const TDF_Label& theLabel, + const Standard_GUID& theID, + const Handle(Poly_Mesh)& theMesh); + + //! Object methods + // ============== + + //! A constructor. + //! Don't use it directly, + //! use please the static method Set(), + //! which returns the attribute attached to a label. + Standard_EXPORT TDataXtd_SurfacicMesh(); + + //! Sets the explicit ID (user defined) for the attribute. + Standard_EXPORT void SetID (const Standard_GUID& theID) Standard_OVERRIDE; + + //! Sets default ID for the attribute. + Standard_EXPORT void SetID() Standard_OVERRIDE; + + //! Sets the mesh. + //! If the mesh consists of only triangles, + //! you may put Poly_Triangulation object. + Standard_EXPORT void Set (const Handle(Poly_Mesh)& theMesh); + + //! Returns the underlying mesh. + Standard_EXPORT const Handle(Poly_Mesh)& Get() const; + + + //! Poly_Mesh methods + // ================= + + //! The methods are "covered" by this attribute to prevent direct modification of the mesh. + + //! Returns the deflection of this triangulation. + Standard_EXPORT Standard_Real Deflection() const; + + //! Sets the deflection of this mesh to theDeflection. + Standard_EXPORT void Deflection (const Standard_Real theDeflection); + + //! Deallocates the UV nodes. + Standard_EXPORT void RemoveUVNodes(); + + //! @return the number of nodes for this mesh. + Standard_EXPORT Standard_Integer NbNodes() const; + + //! @return the number of triangles for this mesh. + Standard_EXPORT Standard_Integer NbTriangles() const; + + //! @return the number of quadrangles for this mesh. + Standard_EXPORT Standard_Integer NbQuads() const; + + //! @return Standard_True if 2D nodes are associated with 3D nodes for this mesh. + Standard_EXPORT Standard_Boolean HasUVNodes() const; + + //! Sets a node by index. + Standard_EXPORT void SetNode (const Standard_Integer& theIndex, const gp_Pnt& theNode); + + //! Returns a node by index. + Standard_EXPORT const gp_Pnt& Node (const Standard_Integer theIndex) const; + + //! Sets a UV-node by index. + Standard_EXPORT void SetUVNode (const Standard_Integer theIndex, const gp_Pnt2d& theUVNode); + + //! Returns an UV-node by index. + Standard_EXPORT const gp_Pnt2d& UVNode (const Standard_Integer theIndex) const; + + //! Sets a triangle by index. + Standard_EXPORT void SetTriangle (const Standard_Integer theIndex, const Poly_Triangle& theTriangle); + + //! Returns a triangle by index. + Standard_EXPORT const Poly_Triangle& Triangle (const Standard_Integer theIndex) const; + + //! Sets a quadrangle by index. + Standard_EXPORT void SetQuad (const Standard_Integer theIndex, const Poly_Quad& theQuad); + + //! Returns a quadrangle by index. + Standard_EXPORT const Poly_Quad& Quad (const Standard_Integer theIndex) const; + + //! Returns Standard_True if nodal normals are defined. + Standard_EXPORT Standard_Boolean HasNormals() const; + + //! Sets normal by index. + Standard_EXPORT void SetNormal (const Standard_Integer theIndex, + const gp_XYZ& theNormal); + + //! Sets normal by index. + Standard_EXPORT void SetNormal (const Standard_Integer theIndex, + const Standard_ShortReal theNormalX, + const Standard_ShortReal theNormalY, + const Standard_ShortReal theNormalZ); + + //! Returns normal by index. + Standard_EXPORT const Vec3f& Normal(const Standard_Integer theIndex) const; + + //! Returns normal by index. + Standard_EXPORT void Normal(const Standard_Integer theIndex, gp_XYZ& theNormal) const; + + //! Dumps the content of me into the stream + Standard_EXPORT virtual void DumpJson(Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE; + + + //! Inherited attribute methods + // =========================== + + Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE; + + Standard_EXPORT void Restore (const Handle(TDF_Attribute)& theWithMesh) Standard_OVERRIDE; + + Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE; + + Standard_EXPORT void Paste (const Handle(TDF_Attribute)& theIntoMesh, const Handle(TDF_RelocationTable)& theRT) const Standard_OVERRIDE; + + Standard_EXPORT virtual Standard_OStream& Dump (Standard_OStream& theOS) const Standard_OVERRIDE; + + DEFINE_STANDARD_RTTI_INLINE(TDataXtd_SurfacicMesh,TDF_Attribute) + +private: + + Handle(Poly_Mesh) myMesh; + Standard_GUID myID; +}; + +#endif // _TDataXtd_SurfacicMesh_HeaderFile