From: ssv Date: Tue, 28 Jul 2015 09:36:34 +0000 (+0300) Subject: Added copy ctor in Poly_Triangulation, Poly_Mesh conversion ctor optimized X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=8acdc1a772f8d9d8275d522853ae7080bd39f9c6;p=occt-copy.git Added copy ctor in Poly_Triangulation, Poly_Mesh conversion ctor optimized --- diff --git a/src/Poly/Poly_Mesh.cxx b/src/Poly/Poly_Mesh.cxx index daa7c4d3f6..d75f81408e 100644 --- a/src/Poly/Poly_Mesh.cxx +++ b/src/Poly/Poly_Mesh.cxx @@ -34,43 +34,17 @@ Poly_Mesh::Poly_Mesh (const Standard_Boolean theHasUVNodes) //======================================================================= Poly_Mesh::Poly_Mesh (const Handle(Poly_Triangulation)& theTriangulation) -: Poly_Triangulation ( theTriangulation->NbNodes(), - theTriangulation->NbTriangles(), - theTriangulation->HasUVNodes() ), +: Poly_Triangulation ( theTriangulation ), 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); - } + // Fill collection of elements + myElements.SetValue( theTriangulation->NbTriangles(), Poly_Element() ); - // Populate elements - const Standard_Boolean hasNormals = theTriangulation->HasNormals(); - Standard_Integer aN1, aN2, aN3; + // Populate elements with triangles 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) ); + myElements(i - 1).Set(i, 0); } - - // Set deflection - Poly_Triangulation::Deflection( theTriangulation->Deflection() ); } //======================================================================= @@ -108,8 +82,11 @@ 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"); + if ( theIndex < 1 || theIndex > myElements.Size() ) + { + Standard_OutOfRange::Raise("Poly_Mesh::Element : index out of range"); + } + return myElements.Value(theIndex - 1); } @@ -124,6 +101,11 @@ void Poly_Mesh::Element (const Standard_Integer theIndex, Standard_Integer& theN3, Standard_Integer& theN4) const { + if ( theIndex < 1 || theIndex > myElements.Size() ) + { + Standard_OutOfRange::Raise("Poly_Mesh::Element : index out of range"); + } + const Poly_Element& anElem = Element(theIndex); Standard_Integer aTriIdx1, aTriIdx2; anElem.Get(aTriIdx1, aTriIdx2); @@ -133,7 +115,7 @@ void Poly_Mesh::Element (const Standard_Integer theIndex, aTri1.Get(theN1, theN2, theN3); // If the second triangle exists, take its node indices for quad - if (aTriIdx2) + if ( aTriIdx2 ) { const Poly_Triangle& aTri2 = Poly_Triangulation::Triangle(aTriIdx2); aTri2.Get(theN1, theN3, theN4); @@ -149,14 +131,16 @@ 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"); + if ( theIndex < 1 || theIndex > myElements.Size() ) + { + Standard_OutOfRange::Raise("Poly_Mesh::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--; } @@ -172,7 +156,7 @@ void Poly_Mesh::SetElement (const Standard_Integer theIndex, const Poly_Element& Standard_Integer Poly_Mesh::addElement(const Poly_Element& theElement) { myElements.Append(theElement); - if (theElement.Value(2) != 0) + if ( theElement.Value(2) != 0 ) { myNbQuads++; } diff --git a/src/Poly/Poly_Triangulation.cxx b/src/Poly/Poly_Triangulation.cxx index 1b811b0dfc..2c05c18157 100644 --- a/src/Poly/Poly_Triangulation.cxx +++ b/src/Poly/Poly_Triangulation.cxx @@ -99,6 +99,24 @@ Poly_Triangulation::Poly_Triangulation (const TColgp_Array1OfPnt& theNodes, } } +//======================================================================= +//function : Poly_Triangulation +//purpose : +//======================================================================= + +Poly_Triangulation::Poly_Triangulation (const Handle(Poly_Triangulation)& theTriangulation) +: myHasUVNodes ( theTriangulation->myHasUVNodes ), + myDeflection ( theTriangulation->myDeflection ) +{ + myNodes.Assign(theTriangulation->myNodes); + if (myHasUVNodes) + { + myUVNodes.Assign(theTriangulation->myUVNodes); + } + myTriangles.Assign(theTriangulation->myTriangles); + myNormals.Assign(theTriangulation->myNormals); +} + //======================================================================= //function : Deflection //purpose : diff --git a/src/Poly/Poly_Triangulation.hxx b/src/Poly/Poly_Triangulation.hxx index 62e734ac13..62792be253 100644 --- a/src/Poly/Poly_Triangulation.hxx +++ b/src/Poly/Poly_Triangulation.hxx @@ -75,6 +75,9 @@ public: const TColgp_Array1OfPnt2d& theUVNodes, const Poly_Array1OfTriangle& theTriangles); + //! 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; @@ -143,7 +146,7 @@ public: //! Raises Standard_OutOfRange exception. Standard_EXPORT const gp_Dir Normal (const Standard_Integer theIndex) const; -private: +protected: Standard_Boolean myHasUVNodes; Standard_Real myDeflection;