]> OCCT Git - occt-copy.git/commitdiff
Added one more constructor accepting Poly_Triangulation. Thus it is now possible...
authorssv <ssv@opencascade.com>
Thu, 9 Jul 2015 09:07:18 +0000 (12:07 +0300)
committerssv <ssv@opencascade.com>
Thu, 9 Jul 2015 09:07:18 +0000 (12:07 +0300)
src/Poly/Poly_Mesh.cxx
src/Poly/Poly_Mesh.hxx

index c8b1e6a235002a93dcd55b4f4709ff024a65a8c5..daa7c4d3f6948b21795bc0134a4badd53a194c56 100644 (file)
@@ -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++;
   }
index ffcab8f73d690531c8b7f7b59fb72e7df1e07a57..c533a3ec39809c84bf8a085c93aa4fddc33457de 100644 (file)
@@ -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.