From: ssv Date: Thu, 9 Jul 2015 09:07:18 +0000 (+0300) Subject: Added one more constructor accepting Poly_Triangulation. Thus it is now possible... X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=2967f26f6e392227811dac73c9d79f5f68746a96;p=occt-copy.git Added one more constructor accepting Poly_Triangulation. Thus it is now possible to create Poly_Mesh around Poly_Triangulation (copy of triangulation will be prepared). --- diff --git a/src/Poly/Poly_Mesh.cxx b/src/Poly/Poly_Mesh.cxx index c8b1e6a235..daa7c4d3f6 100644 --- a/src/Poly/Poly_Mesh.cxx +++ b/src/Poly/Poly_Mesh.cxx @@ -28,6 +28,51 @@ Poly_Mesh::Poly_Mesh (const Standard_Boolean theHasUVNodes) myNbQuads (0) {} +//======================================================================= +//function : Poly_Mesh +//purpose : +//======================================================================= + +Poly_Mesh::Poly_Mesh (const Handle(Poly_Triangulation)& theTriangulation) +: Poly_Triangulation ( theTriangulation->NbNodes(), + theTriangulation->NbTriangles(), + theTriangulation->HasUVNodes() ), + myNbQuads (0) +{ + // Copy nodes + const Standard_Boolean hasUV = theTriangulation->HasUVNodes(); + for ( Standard_Integer i = 1; i <= theTriangulation->NbNodes(); ++i ) + { + Poly_Triangulation::ChangeNode(i) = theTriangulation->Node(i); + + if ( hasUV ) + Poly_Triangulation::ChangeUVNode(i) = theTriangulation->UVNode(i); + } + + // Populate elements + const Standard_Boolean hasNormals = theTriangulation->HasNormals(); + Standard_Integer aN1, aN2, aN3; + for ( Standard_Integer i = 1; i <= theTriangulation->NbTriangles(); ++i ) + { + const Poly_Triangle& aNewTri = theTriangulation->Triangle(i); + Poly_Triangle& aTri = Poly_Triangulation::ChangeTriangle(i); + + // Copy node indices to the new triangle + aNewTri.Get(aN1, aN2, aN3); + aTri.Set(aN1, aN2, aN3); + + // Add element to mesh + addElement( Poly_Element(i, 0) ); + + // Pass normal vector (if any) + if ( hasNormals ) + Poly_Triangulation::SetNormal( i, theTriangulation->Normal(i) ); + } + + // Set deflection + Poly_Triangulation::Deflection( theTriangulation->Deflection() ); +} + //======================================================================= //function : AddElement //purpose : @@ -37,7 +82,7 @@ Standard_Integer Poly_Mesh::AddElement (const Standard_Integer theN1, const Standard_Integer theN2, const Standard_Integer theN3) { - Standard_Integer anIndex = Poly_Triangulation::AddTriangle ( Poly_Triangle(theN1, theN2, theN3) ); + Standard_Integer anIndex = Poly_Triangulation::AddTriangle( Poly_Triangle(theN1, theN2, theN3) ); return addElement( Poly_Element(anIndex, 0) ); } @@ -51,8 +96,8 @@ Standard_Integer Poly_Mesh::AddElement (const Standard_Integer theN1, const Standard_Integer theN3, const Standard_Integer theN4) { - Standard_Integer anIndex1 = Poly_Triangulation::AddTriangle ( Poly_Triangle(theN1, theN2, theN3) ); - Standard_Integer anIndex2 = Poly_Triangulation::AddTriangle ( Poly_Triangle(theN1, theN3, theN4) ); + Standard_Integer anIndex1 = Poly_Triangulation::AddTriangle( Poly_Triangle(theN1, theN2, theN3) ); + Standard_Integer anIndex2 = Poly_Triangulation::AddTriangle( Poly_Triangle(theN1, theN3, theN4) ); return addElement( Poly_Element(anIndex1, anIndex2) ); } @@ -63,9 +108,9 @@ Standard_Integer Poly_Mesh::AddElement (const Standard_Integer theN1, const Poly_Element& Poly_Mesh::Element (const Standard_Integer theIndex) const { - Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > myElements.Size(), - "Poly_Element::Element : index out of range"); - return myElements.Value (theIndex - 1); + Standard_OutOfRange_Raise_if(theIndex < 1 || theIndex > myElements.Size(), + "Poly_Element::Element : index out of range"); + return myElements.Value(theIndex - 1); } //======================================================================= @@ -104,19 +149,19 @@ void Poly_Mesh::Element (const Standard_Integer theIndex, void Poly_Mesh::SetElement (const Standard_Integer theIndex, const Poly_Element& theElement) { - Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > myElements.Size(), - "Poly_Element::SetElement : index out of range"); + Standard_OutOfRange_Raise_if(theIndex < 1 || theIndex > myElements.Size(), + "Poly_Element::SetElement : index out of range"); - if (myElements.Value (theIndex - 1).Value (2) == 0 && theElement.Value (2) != 0) + if (myElements.Value(theIndex - 1).Value(2) == 0 && theElement.Value(2) != 0) { myNbQuads++; } - else if (myElements.Value (theIndex - 1).Value (2) != 0 && theElement.Value (2) == 0) + else if (myElements.Value(theIndex - 1).Value(2) != 0 && theElement.Value(2) == 0) { myNbQuads--; } - myElements.SetValue (theIndex - 1, theElement); + myElements.SetValue(theIndex - 1, theElement); } //======================================================================= @@ -124,10 +169,10 @@ void Poly_Mesh::SetElement (const Standard_Integer theIndex, const Poly_Element& //purpose : //======================================================================= -Standard_Integer Poly_Mesh::addElement (const Poly_Element& theElement) +Standard_Integer Poly_Mesh::addElement(const Poly_Element& theElement) { - myElements.Append (theElement); - if (theElement.Value (2) != 0) + myElements.Append(theElement); + if (theElement.Value(2) != 0) { myNbQuads++; } diff --git a/src/Poly/Poly_Mesh.hxx b/src/Poly/Poly_Mesh.hxx index ffcab8f73d..c533a3ec39 100644 --- a/src/Poly/Poly_Mesh.hxx +++ b/src/Poly/Poly_Mesh.hxx @@ -28,9 +28,14 @@ class Poly_Mesh : public Poly_Triangulation public: //! Constructs an empty mesh. - //! theHasUVNodes flag indicates whether 2D nodes will be associated with 3D ones, (i.e. to enable a 2D representation). + //! @param theHasUVNodes indicates whether 2D nodes will be associated with + //! 3D ones, (i.e. to enable a 2D representation). Standard_EXPORT Poly_Mesh (const Standard_Boolean theHasUVNodes = Standard_False); + //! Constructs a mesh from existing triangulation. + //! @param theTriangulation source triangulation. + Standard_EXPORT Poly_Mesh (const Handle(Poly_Triangulation)& theTriangulation); + //! Adds element to the mesh. //! @param theN1 index of the first node. //! @param theN2 index of the second node.