From: akz Date: Thu, 8 Sep 2016 11:34:59 +0000 (+0300) Subject: 0025936: Reusable data structure for 2D tesselation (3- and 4-nodal mesh) X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=d359cc102ad99c3854e18c9d639f46992f04776c;p=occt-copy.git 0025936: Reusable data structure for 2D tesselation (3- and 4-nodal mesh) * Replaced all arrays in Poly_Triangulation to NCollection_Vector. * Poly_Triangulation now does not provide access to whole arrays stored inside it. Only by one element. * New classes Poly_Element, Poly_Mesh. * New classes BinMDataStd_MeshDriver, XmlMDataStd_MeshDriver, TDataStd_Mesh - Mesh attribute for OCAF * Test cases on CAD mesh attribute --- diff --git a/dox/dev_guides/upgrade/upgrade.md b/dox/dev_guides/upgrade/upgrade.md index 58db74b63e..d3979d965f 100644 --- a/dox/dev_guides/upgrade/upgrade.md +++ b/dox/dev_guides/upgrade/upgrade.md @@ -1054,3 +1054,12 @@ The following obsolete features have been removed: @subsection upgrade_occt710_correction_of_TObj_Model Correction in TObj_Model class Methods *TObj_Model::SaveAs* and *TObj_Model::Load* receive *TCollection_ExtendedString* filename arguments instead of char*. This shows that the filename may be not-ASCII explicitly. Also it makes OCAF API related to this functionality more conform. + +@subsection upgrade_occt710_poly Changes in *Poly* package and *Poly_Triangulation* class: + +* Poly_Triangulation: Replaced all arrays with NCollection_Vector. +* Poly_Triangulation: Old fashion of data access via getting collection reference is not more allowed for safety reasons. + Instead of old API, data access is organized via getters of single element by index. +* New class Poly_Element that allows to store triangles or quads (quad consists of two triangles). +* New class Poly_Mesh is extension of Poly_Triangulation that allows to store mesh with quad polygons as table of Poly_Element. +* New OCAF attribute TDataStd_Mesh that allows to store Poly_Mesh in OCAF documents. \ No newline at end of file diff --git a/src/AIS/AIS_Manipulator.cxx b/src/AIS/AIS_Manipulator.cxx index 370ec76a44..3f31dacff4 100644 --- a/src/AIS/AIS_Manipulator.cxx +++ b/src/AIS/AIS_Manipulator.cxx @@ -1112,11 +1112,11 @@ void AIS_Manipulator::Cube::addTriangle (const Standard_Integer theIndex, const gp_Pnt& theP1, const gp_Pnt& theP2, const gp_Pnt& theP3, const gp_Dir& theNormal) { - myTriangulation->ChangeNodes().SetValue (theIndex * 3 + 1, theP1); - myTriangulation->ChangeNodes().SetValue (theIndex * 3 + 2, theP2); - myTriangulation->ChangeNodes().SetValue (theIndex * 3 + 3, theP3); + myTriangulation->ChangeNode (theIndex * 3 + 1) = theP1; + myTriangulation->ChangeNode (theIndex * 3 + 2) = theP2; + myTriangulation->ChangeNode (theIndex * 3 + 3) = theP3; - myTriangulation->ChangeTriangles().SetValue (theIndex + 1, Poly_Triangle (theIndex * 3 + 1, theIndex * 3 + 2, theIndex * 3 + 3)); + myTriangulation->ChangeTriangle (theIndex + 1) = Poly_Triangle (theIndex * 3 + 1, theIndex * 3 + 2, theIndex * 3 + 3); myArray->AddVertex (theP1, theNormal); myArray->AddVertex (theP2, theNormal); myArray->AddVertex (theP3, theNormal); diff --git a/src/AIS/AIS_Triangulation.cxx b/src/AIS/AIS_Triangulation.cxx index 189518fcc0..30bb62ed15 100644 --- a/src/AIS/AIS_Triangulation.cxx +++ b/src/AIS/AIS_Triangulation.cxx @@ -141,9 +141,6 @@ void AIS_Triangulation::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aP switch (aMode) { case 0: - const TColgp_Array1OfPnt& nodes = myTriangulation->Nodes(); //Nodes - const Poly_Array1OfTriangle& triangles = myTriangulation->Triangles(); //Triangle - Standard_Boolean hasVNormals = myTriangulation->HasNormals(); Standard_Boolean hasVColors = HasVertexColors(); @@ -153,29 +150,25 @@ void AIS_Triangulation::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aP Handle(Graphic3d_AspectFillArea3d) aspect = myDrawer->ShadingAspect()->Aspect(); Standard_Integer i; - Standard_Integer j; Standard_Real ambient = aspect->FrontMaterial().Ambient(); if (hasVNormals) { - const TShort_Array1OfShortReal& normals = myTriangulation->Normals(); if (hasVColors) { const TColStd_Array1OfInteger& colors = myColor->Array1(); - for ( i = nodes.Lower(); i <= nodes.Upper(); i++ ) + for ( i = 1; i <= myTriangulation->NbNodes(); i++ ) { - j = (i - nodes.Lower()) * 3; - anArray->AddVertex(nodes(i), attenuateColor(colors(i), ambient)); - anArray->SetVertexNormal(i, normals(j+1), normals(j+2), normals(j+3)); + anArray->AddVertex(myTriangulation->Node (i), attenuateColor(colors(i), ambient)); + anArray->SetVertexNormal(i, myTriangulation->Normal (i)); } } else // !hasVColors { - for ( i = nodes.Lower(); i <= nodes.Upper(); i++ ) + for ( i = 1; i <= myTriangulation->NbNodes(); i++ ) { - j = (i - nodes.Lower()) * 3; - anArray->AddVertex(nodes(i)); - anArray->SetVertexNormal(i, normals(j+1), normals(j+2), normals(j+3)); + anArray->AddVertex(myTriangulation->Node (i)); + anArray->SetVertexNormal(i, myTriangulation->Normal (i)); } } } @@ -184,23 +177,23 @@ void AIS_Triangulation::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aP if (hasVColors) { const TColStd_Array1OfInteger& colors = myColor->Array1(); - for ( i = nodes.Lower(); i <= nodes.Upper(); i++ ) + for ( i = 1; i <= myTriangulation->NbNodes(); i++ ) { - anArray->AddVertex(nodes(i), attenuateColor(colors(i), ambient)); + anArray->AddVertex(myTriangulation->Node (i), attenuateColor(colors(i), ambient)); } } else // !hasVColors { - for ( i = nodes.Lower(); i <= nodes.Upper(); i++ ) + for ( i = 1; i <= myTriangulation->NbNodes(); i++ ) { - anArray->AddVertex(nodes(i)); + anArray->AddVertex(myTriangulation->Node (i)); } } } Standard_Integer indexTriangle[3] = {0,0,0}; - for ( i = triangles.Lower(); i<= triangles.Upper(); i++ ) { - triangles(i).Get(indexTriangle[0], indexTriangle[1], indexTriangle[2]); + for ( i = 1; i<= myTriangulation->NbTriangles(); i++ ) { + myTriangulation->Triangle (i).Get(indexTriangle[0], indexTriangle[1], indexTriangle[2]); anArray->AddEdge(indexTriangle[0]); anArray->AddEdge(indexTriangle[1]); anArray->AddEdge(indexTriangle[2]); diff --git a/src/BRepBndLib/BRepBndLib.cxx b/src/BRepBndLib/BRepBndLib.cxx index 6e3f6e28a8..9fc485cb95 100644 --- a/src/BRepBndLib/BRepBndLib.cxx +++ b/src/BRepBndLib/BRepBndLib.cxx @@ -92,10 +92,9 @@ void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B, Standard_Boolean useTria if (useTriangulation && !T.IsNull()) { nbNodes = T->NbNodes(); - const TColgp_Array1OfPnt& Nodes = T->Nodes(); for (i = 1; i <= nbNodes; i++) { - if (l.IsIdentity()) B.Add(Nodes(i)); - else B.Add(Nodes(i).Transformed(l)); + if (l.IsIdentity()) B.Add(T->Node (i)); + else B.Add(T->Node (i).Transformed(l)); } // B.Enlarge(T->Deflection()); B.Enlarge(T->Deflection() + BRep_Tool::Tolerance(F)); @@ -153,12 +152,11 @@ void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B, Standard_Boolean useTria if (useTriangulation && !Poly.IsNull()) { const TColStd_Array1OfInteger& Indices = Poly->Nodes(); - const TColgp_Array1OfPnt& Nodes = T->Nodes(); nbNodes = Indices.Length(); for (i = 1; i <= nbNodes; i++) { - if (l.IsIdentity()) B.Add(Nodes(Indices(i))); - else B.Add(Nodes(Indices(i)).Transformed(l)); + if (l.IsIdentity()) B.Add(T->Node (Indices(i))); + else B.Add(T->Node (Indices(i)).Transformed(l)); } // B.Enlarge(T->Deflection()); B.Enlarge(Poly->Deflection() + BRep_Tool::Tolerance(E)); @@ -233,11 +231,9 @@ void BRepBndLib::AddOptimal(const TopoDS_Shape& S, Bnd_Box& B, Bnd_Box aLocBox; if (useTriangulation && !T.IsNull()) { - nbNodes = T->NbNodes(); - const TColgp_Array1OfPnt& Nodes = T->Nodes(); - for (i = 1; i <= nbNodes; i++) { - if (l.IsIdentity()) aLocBox.Add(Nodes(i)); - else aLocBox.Add(Nodes(i).Transformed(l)); + for (i = 1; i <= T->NbNodes(); i++) { + if (l.IsIdentity()) aLocBox.Add(T->Node(i)); + else aLocBox.Add(T->Node(i).Transformed(l)); } // B.Enlarge(T->Deflection()); aLocBox.Enlarge(T->Deflection() + BRep_Tool::Tolerance(F)); @@ -338,12 +334,11 @@ void BRepBndLib::AddOptimal(const TopoDS_Shape& S, Bnd_Box& B, if (useTriangulation && !Poly.IsNull()) { const TColStd_Array1OfInteger& Indices = Poly->Nodes(); - const TColgp_Array1OfPnt& Nodes = T->Nodes(); nbNodes = Indices.Length(); for (i = 1; i <= nbNodes; i++) { - if (l.IsIdentity()) aLocBox.Add(Nodes(Indices(i))); - else aLocBox.Add(Nodes(Indices(i)).Transformed(l)); + if (l.IsIdentity()) aLocBox.Add(T->Node(Indices(i))); + else aLocBox.Add(T->Node(Indices(i)).Transformed(l)); } Standard_Real Tol = useShapeTolerance? BRep_Tool::Tolerance(E) : 0.; aLocBox.Enlarge(Poly->Deflection() + Tol); diff --git a/src/BRepBuilderAPI/BRepBuilderAPI_Copy.cxx b/src/BRepBuilderAPI/BRepBuilderAPI_Copy.cxx index 6d370387b6..1b6c55cd33 100644 --- a/src/BRepBuilderAPI/BRepBuilderAPI_Copy.cxx +++ b/src/BRepBuilderAPI/BRepBuilderAPI_Copy.cxx @@ -22,18 +22,14 @@ #include #include #include -#include -#include #include -namespace { - //! Tool class implementing necessary functionality for copying geometry class BRepBuilderAPI_Copy_Modification : public BRepTools_Modification { public: BRepBuilderAPI_Copy_Modification (const Standard_Boolean copyGeom, - const Standard_Boolean copyMesh) + const Standard_Boolean copyMesh = Standard_False) : myCopyGeom(copyGeom), myCopyMesh(copyMesh) { @@ -59,19 +55,16 @@ public: //! copies it if required Standard_Boolean NewTriangulation(const TopoDS_Face& F, Handle(Poly_Triangulation)& T) Standard_OVERRIDE { - if (!myCopyMesh) - return Standard_False; - TopLoc_Location L; T = BRep_Tool::Triangulation(F, L); - if (T.IsNull()) - return Standard_False; - - // mesh is copied if and only if the geometry need to be copied too - if (myCopyGeom) + if (!T.IsNull() && myCopyMesh) + { T = T->Copy(); - return Standard_True; + return Standard_True; + } + + return Standard_False; } //! Returns true to indicate the need to copy edge; @@ -187,8 +180,6 @@ private: DEFINE_STANDARD_HANDLE(BRepBuilderAPI_Copy_Modification, BRepTools_Modification) -} // anonymous namespace - //======================================================================= //function : BRepBuilderAPI_Copy //purpose : diff --git a/src/BRepCheck/BRepCheck_Edge.cxx b/src/BRepCheck/BRepCheck_Edge.cxx index 0c192748a7..b905353c16 100644 --- a/src/BRepCheck/BRepCheck_Edge.cxx +++ b/src/BRepCheck/BRepCheck_Edge.cxx @@ -605,7 +605,6 @@ BRepCheck_Status BRepCheck_Edge:: aCR->PolygonOnTriangulation2() : aCR->PolygonOnTriangulation(); const TColStd_Array1OfInteger& anIndices = aPOnTriag->Nodes(); - const TColgp_Array1OfPnt& Nodes = aTriang->Nodes(); const Standard_Integer aNbNodes = anIndices.Length(); const Standard_Real aTol = aPOnTriag->Deflection() + @@ -618,9 +617,9 @@ BRepCheck_Status BRepCheck_Edge:: { const Standard_Real aParam = aPOnTriag->Parameters()->Value(i); const gp_Pnt aPE(aBC.Value(aParam)), - aPnt(Nodes(anIndices(i)).Transformed(aLL)); + aPT(aTriang->Node (anIndices(i)).Transformed(aLL)); - const Standard_Real aSQDist = aPE.SquareDistance(aPnt); + const Standard_Real aSQDist = aPE.SquareDistance(aPT); if(aSQDist > aTol*aTol) { return BRepCheck_InvalidPolygonOnTriangulation; @@ -637,9 +636,9 @@ BRepCheck_Status BRepCheck_Edge:: for (Standard_Integer i = 1; i <= aNbNodes; i++) { if (aLL.IsIdentity()) - aB.Add(Nodes(anIndices(i))); + aB.Add(aTriang->Node (anIndices(i))); else - aB.Add(Nodes(anIndices(i)).Transformed(aLL)); + aB.Add(aTriang->Node (anIndices(i)).Transformed(aLL)); } aB.Enlarge(aTol); diff --git a/src/BRepExtrema/BRepExtrema_Poly.cxx b/src/BRepExtrema/BRepExtrema_Poly.cxx index ff9a0a04ae..ec17a2653c 100644 --- a/src/BRepExtrema/BRepExtrema_Poly.cxx +++ b/src/BRepExtrema/BRepExtrema_Poly.cxx @@ -75,12 +75,11 @@ Standard_Boolean BRepExtrema_Poly::Distance (const TopoDS_Shape& S1, const TopoD Tr = BRep_Tool::Triangulation(F,L); if (!Tr.IsNull()) { - const TColgp_Array1OfPnt& Nod = Tr->Nodes(); n = Tr->NbNodes(); for (i = 1; i <= n; i++) { nbn1++; - TP1.SetValue(nbn1,Nod(i).Transformed(L)); + TP1.SetValue(nbn1,Tr->Node (i).Transformed(L)); } } } @@ -96,12 +95,11 @@ Standard_Boolean BRepExtrema_Poly::Distance (const TopoDS_Shape& S1, const TopoD Tr = BRep_Tool::Triangulation(F,L); if (!Tr.IsNull()) { - const TColgp_Array1OfPnt& Nod = Tr->Nodes(); n = Tr->NbNodes(); for (i = 1; i <= n; i++) { nbn2++; - TP2.SetValue(nbn2,Nod(i).Transformed(L)); + TP2.SetValue(nbn2,Tr->Node (i).Transformed(L)); } } } diff --git a/src/BRepExtrema/BRepExtrema_TriangleSet.cxx b/src/BRepExtrema/BRepExtrema_TriangleSet.cxx index ff4b5382a1..83dc472e80 100644 --- a/src/BRepExtrema/BRepExtrema_TriangleSet.cxx +++ b/src/BRepExtrema/BRepExtrema_TriangleSet.cxx @@ -189,7 +189,7 @@ Standard_Boolean BRepExtrema_TriangleSet::Init (const BRepExtrema_ShapeList& the for (Standard_Integer aVertIdx = 1; aVertIdx <= aTriangulation->NbNodes(); ++aVertIdx) { - gp_Pnt aVertex = aTriangulation->Nodes().Value (aVertIdx); + gp_Pnt aVertex = aTriangulation->Node (aVertIdx); aVertex.Transform (aLocation.Transformation()); @@ -197,8 +197,8 @@ Standard_Boolean BRepExtrema_TriangleSet::Init (const BRepExtrema_ShapeList& the aVertex.Y(), aVertex.Z())); - const Standard_Real aU = aTriangulation->UVNodes().Value (aVertIdx).X(); - const Standard_Real aV = aTriangulation->UVNodes().Value (aVertIdx).Y(); + const Standard_Real aU = aTriangulation->UVNode (aVertIdx).X(); + const Standard_Real aV = aTriangulation->UVNode (aVertIdx).Y(); myVertUVArray.push_back (BVH_Vec2d (aU, aV)); } @@ -209,9 +209,9 @@ Standard_Boolean BRepExtrema_TriangleSet::Init (const BRepExtrema_ShapeList& the Standard_Integer aVertex2; Standard_Integer aVertex3; - aTriangulation->Triangles().Value (aTriIdx).Get (aVertex1, - aVertex2, - aVertex3); + aTriangulation->Triangle (aTriIdx).Get (aVertex1, + aVertex2, + aVertex3); myTriangles.push_back (BVH_Vec4i (aVertex1 + aVertOffset, aVertex2 + aVertOffset, diff --git a/src/BRepLib/BRepLib.cxx b/src/BRepLib/BRepLib.cxx index aced41ccb7..b9d835d357 100644 --- a/src/BRepLib/BRepLib.cxx +++ b/src/BRepLib/BRepLib.cxx @@ -1857,9 +1857,9 @@ Standard_Boolean BRepLib:: const Standard_Integer anArrDim = 3*aPT->NbNodes(); Handle(TShort_HArray1OfShortReal) aNormArr = new TShort_HArray1OfShortReal(1, anArrDim); Standard_Integer anNormInd = aNormArr->Lower(); - for(Standard_Integer i = aPT->UVNodes().Lower(); i <= aPT->UVNodes().Upper(); i++) + for(Standard_Integer i = 1; i <= aPT->NbNodes(); i++) { - const gp_Pnt2d &aP2d = aPT->UVNodes().Value(i); + const gp_Pnt2d &aP2d = aPT->UVNode(i); aSLP.SetParameters(aP2d.X(), aP2d.Y()); gp_XYZ aNorm(0.,0.,0.); @@ -1918,9 +1918,6 @@ Standard_Boolean BRepLib:: const Handle(Poly_PolygonOnTriangulation)& aPTEF2 = BRep_Tool::PolygonOnTriangulation(anEdg, aPT2, aLoc2); - TShort_Array1OfShortReal& aNormArr1 = aPT1->ChangeNormals(); - TShort_Array1OfShortReal& aNormArr2 = aPT2->ChangeNormals(); - if (aPTEF1->Nodes().Lower() != aPTEF2->Nodes().Lower() || aPTEF1->Nodes().Upper() != aPTEF2->Nodes().Upper()) continue; @@ -1932,31 +1929,15 @@ Standard_Boolean BRepLib:: const Standard_Integer aFNodF1 = aPTEF1->Nodes().Value(anEdgNode); const Standard_Integer aFNodF2 = aPTEF2->Nodes().Value(anEdgNode); - const Standard_Integer aFNorm1FirstIndex = aNormArr1.Lower() + 3* - (aFNodF1 - aPT1->Nodes().Lower()); - const Standard_Integer aFNorm2FirstIndex = aNormArr2.Lower() + 3* - (aFNodF2 - aPT2->Nodes().Lower()); - - gp_XYZ aNorm1(aNormArr1.Value(aFNorm1FirstIndex), - aNormArr1.Value(aFNorm1FirstIndex+1), - aNormArr1.Value(aFNorm1FirstIndex+2)); - gp_XYZ aNorm2(aNormArr2.Value(aFNorm2FirstIndex), - aNormArr2.Value(aFNorm2FirstIndex+1), - aNormArr2.Value(aFNorm2FirstIndex+2)); + gp_XYZ aNorm1(aPT1->Normal(aFNodF1).XYZ()); + gp_XYZ aNorm2(aPT2->Normal(aFNodF2).XYZ()); const Standard_Real aDot = aNorm1 * aNorm2; if(aDot > aThresDot) { gp_XYZ aNewNorm = (aNorm1 + aNorm2).Normalized(); - aNormArr1.ChangeValue(aFNorm1FirstIndex) = - aNormArr2.ChangeValue(aFNorm2FirstIndex) = - static_cast(aNewNorm.X()); - aNormArr1.ChangeValue(aFNorm1FirstIndex+1) = - aNormArr2.ChangeValue(aFNorm2FirstIndex+1) = - static_cast(aNewNorm.Y()); - aNormArr1.ChangeValue(aFNorm1FirstIndex+2) = - aNormArr2.ChangeValue(aFNorm2FirstIndex+2) = - static_cast(aNewNorm.Z()); + aPT1->SetNormal(aFNodF1, aNewNorm); + aPT2->SetNormal(aFNodF2, aNewNorm); aRetVal = Standard_True; } } diff --git a/src/BRepMesh/BRepMesh.hxx b/src/BRepMesh/BRepMesh.hxx index 8d503f6770..d601334651 100644 --- a/src/BRepMesh/BRepMesh.hxx +++ b/src/BRepMesh/BRepMesh.hxx @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -51,7 +52,6 @@ class BRepMesh_FaceAttribute; class BRepMesh_VertexInspector; class BRepMesh_CircleInspector; class BRepMesh_Classifier; -class Poly_Triangulation; class BRepMesh_VertexTool; namespace BRepMesh diff --git a/src/BRepMesh/BRepMesh_EdgeTessellationExtractor.cxx b/src/BRepMesh/BRepMesh_EdgeTessellationExtractor.cxx index 5fbb1bba33..99252f217c 100644 --- a/src/BRepMesh/BRepMesh_EdgeTessellationExtractor.cxx +++ b/src/BRepMesh/BRepMesh_EdgeTessellationExtractor.cxx @@ -35,7 +35,7 @@ BRepMesh_EdgeTessellationExtractor::BRepMesh_EdgeTessellationExtractor( const TopLoc_Location& theLocation) : myProvider(theEdge, theFace, thePolygon->Parameters()), myPCurve(thePCurve), - myNodes(theTriangulation->Nodes()), + myTriangulation(theTriangulation), myIndices(thePolygon->Nodes()), myLoc(theLocation) { @@ -51,7 +51,7 @@ Standard_Boolean BRepMesh_EdgeTessellationExtractor::Value( gp_Pnt& thePoint, gp_Pnt2d& theUV) { - const gp_Pnt& theRefPnt = myNodes(myIndices(theIndex)); + const gp_Pnt& theRefPnt = myTriangulation->Node (myIndices(theIndex)); thePoint = BRepMesh_ShapeTool::UseLocation(theRefPnt, myLoc); theParameter = myProvider.Parameter(theIndex, thePoint); diff --git a/src/BRepMesh/BRepMesh_EdgeTessellationExtractor.hxx b/src/BRepMesh/BRepMesh_EdgeTessellationExtractor.hxx index d7f20a6146..31f9165be7 100644 --- a/src/BRepMesh/BRepMesh_EdgeTessellationExtractor.hxx +++ b/src/BRepMesh/BRepMesh_EdgeTessellationExtractor.hxx @@ -20,11 +20,13 @@ #include #include #include +#include +#include +#include #include #include #include -class Poly_Triangulation; class Poly_PolygonOnTriangulation; class TopoDS_Edge; class TopoDS_Face; @@ -77,7 +79,7 @@ private: BRepMesh_EdgeParameterProvider myProvider; Handle(Geom2dAdaptor_HCurve) myPCurve; - const TColgp_Array1OfPnt& myNodes; + Handle(Poly_Triangulation) myTriangulation; const TColStd_Array1OfInteger& myIndices; const TopLoc_Location myLoc; }; diff --git a/src/BRepMesh/BRepMesh_FastDiscret.cxx b/src/BRepMesh/BRepMesh_FastDiscret.cxx index 1d453897ff..9abf588f30 100644 --- a/src/BRepMesh/BRepMesh_FastDiscret.cxx +++ b/src/BRepMesh/BRepMesh_FastDiscret.cxx @@ -803,15 +803,14 @@ void BRepMesh_FastDiscret::update( if (aPolygon->Deflection() > 1.1 * theDefEdge) continue; - const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes(); const TColStd_Array1OfInteger& aIndices = aPolygon->Nodes(); Handle(TColStd_HArray1OfReal) aParams = aPolygon->Parameters(); aEAttr.FirstVExtractor = new PolyVExplorer(aEAttr.FirstVertex, - aEAttr.IsSameUV, aEAttr.LastVertex, aIndices(1), aNodes, aLoc); + aEAttr.IsSameUV, aEAttr.LastVertex, aIndices(1), aTriangulation, aLoc); aEAttr.LastVExtractor = new PolyVExplorer(aEAttr.LastVertex, - aEAttr.IsSameUV, aEAttr.FirstVertex, aIndices(aIndices.Length()), aNodes, aLoc); + aEAttr.IsSameUV, aEAttr.FirstVertex, aIndices(aIndices.Length()), aTriangulation, aLoc); aEdgeTool = new BRepMesh_EdgeTessellationExtractor(theEdge, theC2d, aFace, aTriangulation, aPolygon, aLoc); diff --git a/src/BRepMesh/BRepMesh_FastDiscret.hxx b/src/BRepMesh/BRepMesh_FastDiscret.hxx index 3db6feeae2..443fcc270b 100644 --- a/src/BRepMesh/BRepMesh_FastDiscret.hxx +++ b/src/BRepMesh/BRepMesh_FastDiscret.hxx @@ -234,18 +234,18 @@ private: const Standard_Boolean isSameUV, const TopoDS_Vertex& theSameVertex, const Standard_Integer theVertexIndex, - const TColgp_Array1OfPnt& thePolygon, + const Handle(Poly_Triangulation)& theTriangulation, const TopLoc_Location& theLoc) : TopoDSVExplorer(theVertex, isSameUV, theSameVertex), myVertexIndex(theVertexIndex), - myPolygon(thePolygon), + myTriangulation(theTriangulation), myLoc(theLoc) { } virtual gp_Pnt Point() const { - return BRepMesh_ShapeTool::UseLocation(myPolygon(myVertexIndex), myLoc); + return BRepMesh_ShapeTool::UseLocation(myTriangulation->Node (myVertexIndex), myLoc); } private: @@ -255,9 +255,9 @@ private: } private: - Standard_Integer myVertexIndex; - const TColgp_Array1OfPnt& myPolygon; - const TopLoc_Location myLoc; + Standard_Integer myVertexIndex; + Handle(Poly_Triangulation) myTriangulation; + const TopLoc_Location myLoc; }; //! Structure keeps common parameters of edge diff --git a/src/BRepMesh/BRepMesh_FastDiscretFace.cxx b/src/BRepMesh/BRepMesh_FastDiscretFace.cxx index 80df07b20f..7535dac834 100644 --- a/src/BRepMesh/BRepMesh_FastDiscretFace.cxx +++ b/src/BRepMesh/BRepMesh_FastDiscretFace.cxx @@ -1482,8 +1482,6 @@ void BRepMesh_FastDiscretFace::commitSurfaceTriangulation() Handle(Poly_Triangulation) aNewTriangulation = new Poly_Triangulation(aVerticesNb, aTrianglesNb, Standard_True); - Poly_Array1OfTriangle& aPolyTrianges = aNewTriangulation->ChangeTriangles(); - Standard_Integer aTriangeId = 1; BRepMesh::MapOfInteger::Iterator aTriIt(aTriangles); for (; aTriIt.More(); aTriIt.Next()) @@ -1497,12 +1495,10 @@ void BRepMesh_FastDiscretFace::commitSurfaceTriangulation() for (Standard_Integer i = 0; i < 3; ++i) aNodeId[i] = aVetrexEdgeMap->FindIndex(aNode[i]); - aPolyTrianges(aTriangeId++).Set(aNodeId[0], aNodeId[1], aNodeId[2]); + aNewTriangulation->ChangeTriangle (aTriangeId++).Set(aNodeId[0], aNodeId[1], aNodeId[2]); } // Store mesh nodes - TColgp_Array1OfPnt& aNodes = aNewTriangulation->ChangeNodes(); - TColgp_Array1OfPnt2d& aNodes2d = aNewTriangulation->ChangeUVNodes(); for (Standard_Integer i = 1; i <= aVerticesNb; ++i) { @@ -1510,8 +1506,8 @@ void BRepMesh_FastDiscretFace::commitSurfaceTriangulation() const BRepMesh_Vertex& aVertex = aStructure->GetNode(aVertexId); const gp_Pnt& aPoint = myAttribute->GetPoint(aVertex); - aNodes(i) = aPoint; - aNodes2d(i) = aVertex.Coord(); + aNewTriangulation->ChangeNode (i) = aPoint; + aNewTriangulation->ChangeUVNode (i) = aVertex.Coord(); } aNewTriangulation->Deflection(myAttribute->GetDefFace()); diff --git a/src/BRepMesh/BRepMesh_FastDiscretFace.hxx b/src/BRepMesh/BRepMesh_FastDiscretFace.hxx index 76b00e1914..db0459f6f1 100644 --- a/src/BRepMesh/BRepMesh_FastDiscretFace.hxx +++ b/src/BRepMesh/BRepMesh_FastDiscretFace.hxx @@ -22,7 +22,8 @@ #include #include #include -#include +#include +#include #include #include #include @@ -32,9 +33,7 @@ class BRepMesh_DataStructureOfDelaun; class BRepMesh_FaceAttribute; class TopoDS_Face; class TopoDS_Vertex; -class BRepAdaptor_HSurface; class TopoDS_Edge; -class Poly_Triangulation; class TopLoc_Location; class gp_XY; class gp_Pnt2d; diff --git a/src/BRepMesh/BRepMesh_IncrementalMesh.cxx b/src/BRepMesh/BRepMesh_IncrementalMesh.cxx index 70278be259..3a91e7b70a 100644 --- a/src/BRepMesh/BRepMesh_IncrementalMesh.cxx +++ b/src/BRepMesh/BRepMesh_IncrementalMesh.cxx @@ -415,11 +415,10 @@ Standard_Boolean BRepMesh_IncrementalMesh::toBeMeshed( // #25080: check that indices of links forming triangles are in range. Standard_Boolean isTriangulationConsistent = Standard_True; const Standard_Integer aNodesNb = aTriangulation->NbNodes(); - const Poly_Array1OfTriangle& aTriangles = aTriangulation->Triangles(); - Standard_Integer i = aTriangles.Lower(); - for (; i <= aTriangles.Upper() && isTriangulationConsistent; ++i) + Standard_Integer i = 1; + for (; i <= aTriangulation->NbTriangles() && isTriangulationConsistent; ++i) { - const Poly_Triangle& aTriangle = aTriangles(i); + const Poly_Triangle& aTriangle = aTriangulation->Triangle (i); Standard_Integer n[3]; aTriangle.Get(n[0], n[1], n[2]); for (Standard_Integer j = 0; j < 3 && isTriangulationConsistent; ++j) diff --git a/src/BRepMesh/BRepMesh_IncrementalMesh.hxx b/src/BRepMesh/BRepMesh_IncrementalMesh.hxx index 5e7d4f3bdc..f3d647810b 100644 --- a/src/BRepMesh/BRepMesh_IncrementalMesh.hxx +++ b/src/BRepMesh/BRepMesh_IncrementalMesh.hxx @@ -21,11 +21,11 @@ #include #include #include +#include #include #include -class Poly_Triangulation; class TopoDS_Shape; class TopoDS_Edge; class TopoDS_Face; diff --git a/src/BRepMesh/BRepMesh_ShapeTool.cxx b/src/BRepMesh/BRepMesh_ShapeTool.cxx index ebd837bd7a..d9e4e6c165 100644 --- a/src/BRepMesh/BRepMesh_ShapeTool.cxx +++ b/src/BRepMesh/BRepMesh_ShapeTool.cxx @@ -203,9 +203,8 @@ void BRepMesh_ShapeTool::AddInFace( gp_Trsf aTrsf = aLoc.Transformation(); aTrsf.Invert(); - TColgp_Array1OfPnt& aNodes = theTriangulation->ChangeNodes(); - for (Standard_Integer i = aNodes.Lower(); i <= aNodes.Upper(); ++i) - aNodes(i).Transform(aTrsf); + for (Standard_Integer i = 1; i <= theTriangulation->NbNodes(); ++i) + theTriangulation->ChangeNode (i).Transform(aTrsf); } BRep_Builder aBuilder; diff --git a/src/BRepMesh/BRepMesh_ShapeTool.hxx b/src/BRepMesh/BRepMesh_ShapeTool.hxx index e1883d7746..7ced7514d7 100644 --- a/src/BRepMesh/BRepMesh_ShapeTool.hxx +++ b/src/BRepMesh/BRepMesh_ShapeTool.hxx @@ -21,6 +21,7 @@ #include #include #include +#include class Poly_Triangulation; class TopoDS_Face; diff --git a/src/BRepTools/BRepTools_Modification.cxx b/src/BRepTools/BRepTools_Modification.cxx index 012035a8b2..282d7da365 100644 --- a/src/BRepTools/BRepTools_Modification.cxx +++ b/src/BRepTools/BRepTools_Modification.cxx @@ -14,21 +14,11 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. - #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include +#include -IMPLEMENT_STANDARD_RTTIEXT(BRepTools_Modification,MMgt_TShared) +IMPLEMENT_STANDARD_RTTIEXT (BRepTools_Modification, MMgt_TShared) Standard_Boolean BRepTools_Modification::NewTriangulation(const TopoDS_Face&, Handle(Poly_Triangulation)&) { diff --git a/src/BRepTools/BRepTools_ShapeSet.cxx b/src/BRepTools/BRepTools_ShapeSet.cxx index a89ebf538a..ccd0e62efd 100644 --- a/src/BRepTools/BRepTools_ShapeSet.cxx +++ b/src/BRepTools/BRepTools_ShapeSet.cxx @@ -55,6 +55,7 @@ #include #include #include +#include #ifdef MacOS #define strcasecmp(p,q) strcmp(p,q) @@ -1475,7 +1476,7 @@ void BRepTools_ShapeSet::ReadPolygon3D(Standard_IStream& IS) //======================================================================= void BRepTools_ShapeSet::WriteTriangulation(Standard_OStream& OS, - const Standard_Boolean Compact)const + const Standard_Boolean Compact) const { Standard_Integer i, j, nbNodes, nbtri = myTriangulations.Extent(); Standard_Integer nbTriangles = 0, n1, n2, n3; @@ -1516,28 +1517,26 @@ void BRepTools_ShapeSet::WriteTriangulation(Standard_OStream& OS, if (!Compact) OS << "\n3D Nodes :\n"; nbNodes = T->NbNodes(); - const TColgp_Array1OfPnt& Nodes = T->Nodes(); for (j = 1; j <= nbNodes; j++) { if (!Compact) OS << setw(10) << j << " : "; if (!Compact) OS << setw(17); - OS << Nodes(j).X() << " "; + OS << T->Node (j).X() << " "; if (!Compact) OS << setw(17); - OS << Nodes(j).Y() << " "; + OS << T->Node (j).Y() << " "; if (!Compact) OS << setw(17); - OS << Nodes(j).Z(); + OS << T->Node (j).Z(); if (!Compact) OS << "\n"; else OS << " "; } if (T->HasUVNodes()) { if (!Compact) OS << "\nUV Nodes :\n"; - const TColgp_Array1OfPnt2d& UVNodes = T->UVNodes(); for (j = 1; j <= nbNodes; j++) { if (!Compact) OS << setw(10) << j << " : "; if (!Compact) OS << setw(17); - OS << UVNodes(j).X() << " "; + OS << T->UVNode (j).X() << " "; if (!Compact) OS << setw(17); - OS << UVNodes(j).Y(); + OS << T->UVNode (j).Y(); if (!Compact) OS << "\n"; else OS << " "; } @@ -1545,10 +1544,9 @@ void BRepTools_ShapeSet::WriteTriangulation(Standard_OStream& OS, if (!Compact) OS << "\nTriangles :\n"; nbTriangles = T->NbTriangles(); - const Poly_Array1OfTriangle& Triangles = T->Triangles(); for (j = 1; j <= nbTriangles; j++) { if (!Compact) OS << setw(10) << j << " : "; - Triangles(j).Get(n1, n2, n3); + T->Triangle (j).Get(n1, n2, n3); if (!Compact) OS << setw(10); OS << n1 << " "; if (!Compact) OS << setw(10); @@ -1618,7 +1616,7 @@ void BRepTools_ShapeSet::ReadTriangulation(Standard_IStream& IS) UVNodes(j).SetCoord(x,y); } } - + // read the triangles Standard_Integer n1,n2,n3; Poly_Array1OfTriangle Triangles(1, nbTriangles); @@ -1626,12 +1624,185 @@ void BRepTools_ShapeSet::ReadTriangulation(Standard_IStream& IS) IS >> n1 >> n2 >> n3; Triangles(j).Set(n1,n2,n3); } - + if (hasUV) T = new Poly_Triangulation(Nodes,UVNodes,Triangles); else T = new Poly_Triangulation(Nodes,Triangles); - + T->Deflection(d); - + myTriangulations.Add(T); } } + +// Writes meshes (Poly_Mesh). +void BRepTools_ShapeSet::WriteMeshes(Standard_OStream& OS, + const TColStd_IndexedMapOfTransient& Meshes, + const Standard_Boolean Compact) +{ + const Standard_Integer nbMeshes = Meshes.Extent(); + + if (Compact) + OS << "Meshes " << nbMeshes << "\n"; + else { + OS << " -------\n"; + OS <<"Dump of " << nbMeshes << " meshes\n"; + OS << " -------\n"; + } + + Standard_Integer i = 1; + for (; i <= nbMeshes; i++) + { + const Handle(Poly_Mesh) M = Handle(Poly_Mesh)::DownCast(Meshes(i)); + const Standard_Integer nbNodes = M->NbNodes(); + const Standard_Integer nbElements = M->NbElements(); + const Standard_Boolean hasUVNodes = M->HasUVNodes(); + + if (Compact) + { + OS << nbNodes << " " << nbElements << " "; + OS << (hasUVNodes ? "1" : "0") << " "; + } + else + { + OS << " "<< i << " : Mesh with " << nbNodes << " Nodes, " << nbElements <<" Triangles and Quadrangles\n"; + OS << " "<<(hasUVNodes ? "with" : "without") << " UV nodes\n"; + } + + // write the deflection + if (!Compact) + OS << " Deflection : "; + OS <Deflection() << "\n"; + + // write the 3d nodes + if (!Compact) + OS << "\n3D Nodes :\n"; + + Standard_Integer j; + for (j = 1; j <= nbNodes; j++) + { + if (!Compact) OS << setw(10) << j << " : "; + if (!Compact) OS << setw(17); + OS << M->Node(j).X() << " "; + if (!Compact) OS << setw(17); + OS << M->Node(j).Y() << " "; + if (!Compact) OS << setw(17); + OS << M->Node(j).Z(); + if (!Compact) OS << "\n"; + else OS << " "; + } + + // write 2d nodes + if (hasUVNodes) + { + if (!Compact) OS << "\nUV Nodes :\n"; + for (j = 1; j <= nbNodes; j++) + { + if (!Compact) OS << setw(10) << j << " : "; + if (!Compact) OS << setw(17); + OS << M->UVNode(j).X() << " "; + if (!Compact) OS << setw(17); + OS << M->UVNode(j).Y(); + if (!Compact) OS << "\n"; + else OS << " "; + } + } + + // write triangles and quadrangles + if (!Compact) OS << "\nElements :\n"; + Standard_Integer n, n1, n2, n3, n4; + for (j = 1; j <= nbElements; j++) + { + if (!Compact) OS << setw(10) << j << " : "; + M->Element(j, n1, n2, n3, n4); + n = (n4 > 0) ? 4 : 3; + if (!Compact) OS << setw(10); + OS << n << " "; + if (!Compact) OS << setw(10); + OS << n1 << " "; + if (!Compact) OS << setw(10); + OS << n2 << " "; + if (!Compact) OS << setw(10); + OS << n3; + if (n4 > 0) + { + OS << " "; + if (!Compact) OS << setw(10); + OS << n4; + } + if (!Compact) OS << "\n"; + else OS << " "; + } + OS << "\n"; + } +} + +// Reads meshes (Poly_Mesh). +void BRepTools_ShapeSet::ReadMeshes(Standard_IStream& IS, + TColStd_IndexedMapOfTransient& Meshes) +{ + char buffer[255]; + Standard_Integer i, j; + Standard_Integer n, n1, n2, n3, n4; + Standard_Real deflection, x, y, z; + Standard_Integer nbMeshes(0), nbNodes(0), nbElements(0); + Standard_Boolean hasUV(Standard_False); + gp_Pnt p; + + // Read the "Meshes" head-line. + IS >> buffer; + if (strstr(buffer,"Meshes") == NULL) + return; + + // Read number of meshes. + IS >> nbMeshes; + + for (i = 1; i <= nbMeshes; i++) + { + IS >> nbNodes >> nbElements >> hasUV; + GeomTools::GetReal(IS, deflection); + + // Allocate the mesh. + Handle(Poly_Mesh) M = new Poly_Mesh(hasUV); + M->Deflection(deflection); + + // Read nodes. + for (j = 1; j <= nbNodes; j++) + { + GeomTools::GetReal(IS, x); + GeomTools::GetReal(IS, y); + GeomTools::GetReal(IS, z); + p.SetCoord(x, y, z); + M->AddNode(p); + } + + // Reads 2d-nodes. + if (hasUV) + { + for (j = 1; j <= nbNodes; j++) + { + GeomTools::GetReal(IS, x); + GeomTools::GetReal(IS, y); + M->ChangeUVNode(j).SetCoord(x,y); + } + } + + // Reads the triangles and quadrangles. + for (j = 1; j <= nbElements; j++) + { + // Read the element. + IS >> n; + if (n == 3) + IS >> n1 >> n2 >> n3; + else if (n == 4) + IS >> n1 >> n2 >> n3 >> n4; + + // Set the element to the mesh. + if (n == 3) + M->AddElement(n1, n2, n3); + else if (n == 4) + M->AddElement(n1, n2, n3, n4); + } + + Meshes.Add(M); + } +} diff --git a/src/BRepTools/BRepTools_ShapeSet.hxx b/src/BRepTools/BRepTools_ShapeSet.hxx index caf96de383..a35d99def6 100644 --- a/src/BRepTools/BRepTools_ShapeSet.hxx +++ b/src/BRepTools/BRepTools_ShapeSet.hxx @@ -127,7 +127,16 @@ public: //! on the stream . Standard_EXPORT void DumpPolygonOnTriangulation (Standard_OStream& OS) const; - + //! Writes meshes (Poly_Mesh). + //! TODO: Call this method when BRep_TFace refers to a list of meshes of type Poly_Mesh. + Standard_EXPORT static void WriteMeshes(Standard_OStream& OS, + const TColStd_IndexedMapOfTransient& Meshes, + const Standard_Boolean Compact = Standard_True); + + //! Reads meshes (Poly_Mesh). + //! TODO: Call this method when BRep_TFace refers to a list of meshes of type Poly_Mesh. + Standard_EXPORT static void ReadMeshes(Standard_IStream& IS, + TColStd_IndexedMapOfTransient& Meshes); protected: diff --git a/src/BinMDataStd/BinMDataStd.cxx b/src/BinMDataStd/BinMDataStd.cxx index 9885934ebe..147253c71e 100644 --- a/src/BinMDataStd/BinMDataStd.cxx +++ b/src/BinMDataStd/BinMDataStd.cxx @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -80,6 +81,7 @@ void BinMDataStd::AddDrivers (const Handle(BinMDF_ADriverTable)& theDriverTable, theDriverTable->AddDriver (new BinMDataStd_NamedDataDriver (theMsgDriver) ); theDriverTable->AddDriver (new BinMDataStd_AsciiStringDriver (theMsgDriver) ); theDriverTable->AddDriver (new BinMDataStd_IntPackedMapDriver (theMsgDriver) ); + theDriverTable->AddDriver (new BinMDataStd_MeshDriver (theMsgDriver) ); } //======================================================================= diff --git a/src/BinMDataStd/BinMDataStd_MeshDriver.cxx b/src/BinMDataStd/BinMDataStd_MeshDriver.cxx new file mode 100644 index 0000000000..f0757f1549 --- /dev/null +++ b/src/BinMDataStd/BinMDataStd_MeshDriver.cxx @@ -0,0 +1,169 @@ +// Created on: 2015-12-17 +// 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 + +IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_MeshDriver,BinMDF_ADriver) + +//======================================================================= +//function : BinMDataStd_MeshDriver +//purpose : Constructor +//======================================================================= +BinMDataStd_MeshDriver::BinMDataStd_MeshDriver(const Handle(CDM_MessageDriver)& theMsgDriver) + : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TDataStd_Mesh)->Name()) +{ + +} + +//======================================================================= +//function : NewEmpty +//purpose : +//======================================================================= +Handle(TDF_Attribute) BinMDataStd_MeshDriver::NewEmpty() const +{ + return new TDataStd_Mesh(); +} + +//======================================================================= +//function : Paste +//purpose : persistent -> transient (retrieve) +//======================================================================= +Standard_Boolean BinMDataStd_MeshDriver::Paste(const BinObjMgt_Persistent& theSource, + const Handle(TDF_Attribute)& theTarget, + BinObjMgt_RRelocationTable& ) const +{ + Handle(TDataStd_Mesh) mesh = Handle(TDataStd_Mesh)::DownCast(theTarget); + + Standard_Integer i; + Standard_Real deflection, x, y, z; + Standard_Integer n, n1, n2, n3, n4; + Standard_Integer nbNodes(0), nbElements(0); + Standard_Boolean hasUV(Standard_False); + gp_Pnt p; + + theSource >> nbNodes; + theSource >> nbElements; + theSource >> hasUV; + theSource >> deflection; + + // allocate the mesh + Handle(Poly_Mesh) M = new Poly_Mesh(hasUV); + + // deflection + M->Deflection(deflection); + + // read nodes + for (i = 1; i <= nbNodes; i++) + { + theSource >> x; + theSource >> y; + theSource >> z; + p.SetCoord(x, y, z); + M->AddNode(p); + } + + // read 2d nodes + if (hasUV) + { + for (i = 1; i <= nbNodes; i++) + { + theSource >> x; + theSource >> y; + M->ChangeUVNode(i).SetCoord(x,y); + } + } + + // read triangles and quadrangles + for (i = 1; i <= nbElements; i++) + { + theSource >> n; + theSource >> n1; + theSource >> n2; + theSource >> n3; + if (n == 3) + M->AddElement(n1, n2, n3); + else if (n == 4) + { + theSource >> n4; + M->AddElement(n1, n2, n3, n4); + } + } + + // set mesh to Ocaf attribute + mesh->Set(M); + return !M.IsNull(); +} + +//======================================================================= +//function : Paste +//purpose : transient -> persistent (store) +//======================================================================= +void BinMDataStd_MeshDriver::Paste(const Handle(TDF_Attribute)& theSource, + BinObjMgt_Persistent& theTarget, + BinObjMgt_SRelocationTable& ) const +{ + const Handle(TDataStd_Mesh) meshAttr = Handle(TDataStd_Mesh)::DownCast(theSource); + const Handle(Poly_Mesh)& M = meshAttr->Get(); + if (!M.IsNull()) + { + Standard_Integer nbNodes = M->NbNodes(); + Standard_Integer nbElements = M->NbElements(); + + // write number of elements + theTarget << nbNodes; + theTarget << nbElements; + theTarget << (M->HasUVNodes() ? 1 : 0); + // write the deflection + theTarget << M->Deflection(); + + // write 3d nodes + Standard_Integer i; + for (i = 1; i <= nbNodes; i++) + { + theTarget << M->Node(i).X(); + theTarget << M->Node(i).Y(); + theTarget << M->Node(i).Z(); + } + + // write 2d nodes + if (M->HasUVNodes()) + { + for (i = 1; i <= nbNodes; i++) + { + theTarget << M->UVNode(i).X(); + theTarget << M->UVNode(i).Y(); + } + } + + // write triangles and quadrangles + Standard_Integer n, n1, n2, n3, n4; + for (i = 1; i <= nbElements; i++) + { + M->Element(i, n1, n2, n3, n4); + n = (n4 > 0) ? 4 : 3; + theTarget << n; + theTarget << n1; + theTarget << n2; + theTarget << n3; + if (n4 > 0) + theTarget << n4; + } + } +} diff --git a/src/BinMDataStd/BinMDataStd_MeshDriver.hxx b/src/BinMDataStd/BinMDataStd_MeshDriver.hxx new file mode 100644 index 0000000000..67d1f082c8 --- /dev/null +++ b/src/BinMDataStd/BinMDataStd_MeshDriver.hxx @@ -0,0 +1,49 @@ +// Created on: 2015-12-17 +// 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 _BinMDataStd_MeshDriver_HeaderFile +#define _BinMDataStd_MeshDriver_HeaderFile + +#include +#include + +#include +#include +#include +#include +class CDM_MessageDriver; +class TDF_Attribute; +class BinObjMgt_Persistent; + +DEFINE_STANDARD_HANDLE(BinMDataStd_MeshDriver, BinMDF_ADriver) + +//! TDataStd_Mesh attribute bin Driver. +class BinMDataStd_MeshDriver : public BinMDF_ADriver +{ + +public: + + Standard_EXPORT BinMDataStd_MeshDriver(const Handle(CDM_MessageDriver)& theMessageDriver); + + Standard_EXPORT virtual Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE; + + Standard_EXPORT virtual Standard_Boolean Paste (const BinObjMgt_Persistent& Source, const Handle(TDF_Attribute)& Target, BinObjMgt_RRelocationTable& RelocTable) const Standard_OVERRIDE; + + Standard_EXPORT virtual void Paste (const Handle(TDF_Attribute)& Source, BinObjMgt_Persistent& Target, BinObjMgt_SRelocationTable& RelocTable) const Standard_OVERRIDE; + + DEFINE_STANDARD_RTTIEXT(BinMDataStd_MeshDriver,BinMDF_ADriver) +}; + +#endif // _BinMDataStd_MeshDriver_HeaderFile diff --git a/src/BinMDataStd/FILES b/src/BinMDataStd/FILES index 49f0d5daaf..da2cca0059 100644 --- a/src/BinMDataStd/FILES +++ b/src/BinMDataStd/FILES @@ -26,6 +26,8 @@ BinMDataStd_IntegerListDriver.cxx BinMDataStd_IntegerListDriver.hxx BinMDataStd_IntPackedMapDriver.cxx BinMDataStd_IntPackedMapDriver.hxx +BinMDataStd_MeshDriver.cxx +BinMDataStd_MeshDriver.hxx BinMDataStd_NamedDataDriver.cxx BinMDataStd_NamedDataDriver.hxx BinMDataStd_NameDriver.cxx diff --git a/src/BinTools/BinTools_ShapeSet.cxx b/src/BinTools/BinTools_ShapeSet.cxx index 3f0d45bf1b..48a113b348 100644 --- a/src/BinTools/BinTools_ShapeSet.cxx +++ b/src/BinTools/BinTools_ShapeSet.cxx @@ -1407,24 +1407,23 @@ void BinTools_ShapeSet::WriteTriangulation(Standard_OStream& OS) const // write the 3d nodes nbNodes = T->NbNodes(); - const TColgp_Array1OfPnt& Nodes = T->Nodes(); for (j = 1; j <= nbNodes; j++) { - BinTools::PutReal(OS, Nodes(j).X()); - BinTools::PutReal(OS, Nodes(j).Y()); - BinTools::PutReal(OS, Nodes(j).Z()); + const gp_Pnt& aNode = T->Node(j); + BinTools::PutReal(OS, aNode.X()); + BinTools::PutReal(OS, aNode.Y()); + BinTools::PutReal(OS, aNode.Z()); } if (T->HasUVNodes()) { - const TColgp_Array1OfPnt2d& UVNodes = T->UVNodes(); for (j = 1; j <= nbNodes; j++) { - BinTools::PutReal(OS, UVNodes(j).X()); - BinTools::PutReal(OS, UVNodes(j).Y()); + const gp_Pnt2d& anUVNode = T->UVNode(j); + BinTools::PutReal(OS, anUVNode.X()); + BinTools::PutReal(OS, anUVNode.Y()); } } nbTriangles = T->NbTriangles(); - const Poly_Array1OfTriangle& Triangles = T->Triangles(); for (j = 1; j <= nbTriangles; j++) { - Triangles(j).Get(n1, n2, n3); + T->Triangle (j).Get(n1, n2, n3); BinTools::PutInteger(OS, n1); BinTools::PutInteger(OS, n2); BinTools::PutInteger(OS, n3); diff --git a/src/DBRep/DBRep_DrawableShape.cxx b/src/DBRep/DBRep_DrawableShape.cxx index 3da810e721..45c2129243 100644 --- a/src/DBRep/DBRep_DrawableShape.cxx +++ b/src/DBRep/DBRep_DrawableShape.cxx @@ -778,10 +778,9 @@ void DBRep_DrawableShape::DrawOn(Draw_Display& dis) const BRep_Tool::PolygonOnTriangulation(E->Edge(), Poly, PolyTr, loc); if (!Poly.IsNull()) { const TColStd_Array1OfInteger& Indices = Poly->Nodes(); - const TColgp_Array1OfPnt& Nodes = PolyTr->Nodes(); for (i=Indices.Lower()+1; i<=Indices.Upper(); i++) { - dis.Draw(Nodes(Indices(i-1)).Transformed(loc), - Nodes(Indices(i)).Transformed(loc)); + dis.Draw(Tr->Node (Indices(i-1)).Transformed(loc), + Tr->Node (Indices(i)).Transformed(loc)); if (dis.HasPicked()) { pickshape = E->Edge(); upick = 0; @@ -1124,11 +1123,10 @@ void DBRep_DrawableShape::Display(const Handle(Poly_Triangulation)& T, TColStd_DataMapOfIntegerInteger Internal; Standard_Integer fr = 1, in = 1; - const Poly_Array1OfTriangle& triangles = T->Triangles(); Standard_Integer n[3]; for (i = 1; i <= nbTriangles; i++) { pc.Triangles(i,t[0],t[1],t[2]); - triangles(i).Get(n[0],n[1],n[2]); + T->Triangle (i).Get(n[0],n[1],n[2]); for (j = 0; j < 3; j++) { Standard_Integer k = (j+1) % 3; if (t[j] == 0) { @@ -1146,16 +1144,13 @@ void DBRep_DrawableShape::Display(const Handle(Poly_Triangulation)& T, } // Display the edges - const TColgp_Array1OfPnt& Nodes = T->Nodes(); -// cout<<"nb nodes = "<Node (Free(2*i-1)).Transformed(tr), + T->Node (Free(2*i)).Transformed(tr)); } // internal edges @@ -1167,8 +1162,8 @@ void DBRep_DrawableShape::Display(const Handle(Poly_Triangulation)& T, //alvays pair is put aIt.Next(); Standard_Integer n2 = aIt.Value(); - dis.Draw(Nodes(n1).Transformed(tr), - Nodes(n2).Transformed(tr)); + dis.Draw(T->Node (n1).Transformed(tr), + T->Node (n2).Transformed(tr)); } } diff --git a/src/DDataStd/DDataStd_BasicCommands.cxx b/src/DDataStd/DDataStd_BasicCommands.cxx index 88226d176d..dcbb8d9481 100644 --- a/src/DDataStd/DDataStd_BasicCommands.cxx +++ b/src/DDataStd/DDataStd_BasicCommands.cxx @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -52,6 +53,7 @@ // LES ATTRIBUTES #include +#include #include #include #include @@ -3733,6 +3735,98 @@ static Standard_Integer DDataStd_GetRefArrayValue (Draw_Interpretor& di, return 0; } +//======================================================================= +//function : DDataStd_SetMesh +//purpose : SetMesh (DF, entry, face) +//======================================================================= + +static Standard_Integer DDataStd_SetMesh (Draw_Interpretor& di, + Standard_Integer nb, + const char** arg) +{ + if (nb == 4) + { + Handle(TDF_Data) DF; + if (!DDF::GetDF(arg[1],DF)) + return 1; + + TDF_Label L; + if (!DDF::AddLabel(DF, arg[2], L)) + return 1; + + // Get face. + TopoDS_Shape face = DBRep::Get(arg[3]); + if (face.IsNull() || + face.ShapeType() != TopAbs_FACE) + { + di << "The face is null or not a face.\n"; + return 1; + } + + // Get triangulation of the face. + TopLoc_Location loc; + Handle(Poly_Triangulation) tris = BRep_Tool::Triangulation(TopoDS::Face(face), loc); + if (tris.IsNull()) + { + di << "No triangulation in the face.\n"; + return 1; + } + + // Make a mesh. + Handle(Poly_Mesh) mesh = new Poly_Mesh(tris); + + // Set the attribute. + TDataStd_Mesh::Set(L, mesh); + return 0; + } + di << "DDataStd_SetMesh : Error\n"; + return 1; +} + +//======================================================================= +//function : DDataStd_DumpMesh +//purpose : DumpMesh (DF, entry) +//======================================================================= + +static Standard_Integer DDataStd_DumpMesh (Draw_Interpretor& di, + Standard_Integer nb, + const char** arg) +{ + if (nb == 3) + { + Handle(TDF_Data) DF; + if (!DDF::GetDF(arg[1],DF)) + return 1; + + Handle(TDataStd_Mesh) M; + if (!DDF::Find(DF,arg[2],TDataStd_Mesh::GetID(),M)) + { + di << "The attribute mesh doesn't exist at the label.\n"; + return 1; + } + + // Dump of the mesh. + if (M->Get().IsNull()) + { + di << "No mesh in the attribute.\n"; + return 1; + } + + di << "Deflection " << M->Deflection() <<"\n"; + di << "Number of nodes " << M->NbNodes() << "\n"; + di << "Number of triangles " << M->NbTriangles() << "\n"; + di << "Number of quadrangles " << M->NbQuads() << "\n"; + if (M->HasUVNodes()) + di << "It has 2d-nodes\n"; + if (M->HasNormals()) + di << "It has normals\n"; + + return 0; + } + di << "DDataStd_DumpMesh : Error\n"; + return 1; +} + //======================================================================= //function : BasicCommands //purpose : @@ -3850,6 +3944,13 @@ void DDataStd::BasicCommands (Draw_Interpretor& theCommands) "SetReferenceList (DF, entry, elmt1, elmt2, ... )", __FILE__, DDataStd_SetReferenceList, g); + theCommands.Add ("SetMesh", + "SetMesh (DF, entry, face) - adds label with passed entry to \ + DF and put an attribute with the triangulation from passed face", + __FILE__, DDataStd_SetMesh, g); + + // Insert before and after (for lists) + theCommands.Add ("InsertBeforeExtStringList", "InsertBeforeExtStringList (DF, entry, index, value )", __FILE__, DDataStd_InsertBeforeExtStringList, g); @@ -4156,6 +4257,10 @@ void DDataStd::BasicCommands (Draw_Interpretor& theCommands) //========================================================= + theCommands.Add ("DumpMesh", + "DumpMesh (DF, entry) - dumps info about mesh that stored \ + in DF in mesh attribute of a label with the passed entry", + __FILE__, DDataStd_DumpMesh, g); //====================================================================== //======= for internal use diff --git a/src/DrawTrSurf/DrawTrSurf_Triangulation.cxx b/src/DrawTrSurf/DrawTrSurf_Triangulation.cxx index ddc1ad2696..49b0dc0b7e 100644 --- a/src/DrawTrSurf/DrawTrSurf_Triangulation.cxx +++ b/src/DrawTrSurf/DrawTrSurf_Triangulation.cxx @@ -64,11 +64,10 @@ DrawTrSurf_Triangulation::DrawTrSurf_Triangulation TColStd_Array1OfInteger& Internal = myInternals->ChangeArray1(); Standard_Integer fr = 1, in = 1; - const Poly_Array1OfTriangle& triangles = T->Triangles(); Standard_Integer n[3]; for (i = 1; i <= nbTriangles; i++) { pc.Triangles(i,t[0],t[1],t[2]); - triangles(i).Get(n[0],n[1],n[2]); + T->Triangle (i).Get(n[0],n[1],n[2]); for (j = 0; j < 3; j++) { Standard_Integer k = (j+1) % 3; if (t[j] == 0) { @@ -146,15 +145,13 @@ void DrawTrSurf_Triangulation::DrawOn(Draw_Display& dis) const // Display the edges Standard_Integer i,n; - const TColgp_Array1OfPnt& Nodes = myTriangulation->Nodes(); - // free edges dis.SetColor(Draw_rouge); const TColStd_Array1OfInteger& Free = myFree->Array1(); n = Free.Length() / 2; for (i = 1; i <= n; i++) { - dis.Draw(Nodes(Free(2*i-1)),Nodes(Free(2*i))); + dis.Draw(myTriangulation->Node (Free(2*i-1)),myTriangulation->Node (Free(2*i))); } // internal edges @@ -163,7 +160,7 @@ void DrawTrSurf_Triangulation::DrawOn(Draw_Display& dis) const const TColStd_Array1OfInteger& Internal = myInternals->Array1(); n = Internal.Length() / 2; for (i = 1; i <= n; i++) { - dis.Draw(Nodes(Internal(2*i-1)),Nodes(Internal(2*i))); + dis.Draw(myTriangulation->Node (Internal(2*i-1)),myTriangulation->Node (Internal(2*i))); } // texts @@ -173,7 +170,7 @@ void DrawTrSurf_Triangulation::DrawOn(Draw_Display& dis) const n = myTriangulation->NbNodes(); for (i = 1; i <= n; i++) { Sprintf(text,"%d",i); - dis.DrawString(Nodes(i),text); + dis.DrawString(myTriangulation->Node (i),text); } } @@ -181,13 +178,12 @@ void DrawTrSurf_Triangulation::DrawOn(Draw_Display& dis) const dis.SetColor(Draw_vert); n = myTriangulation->NbTriangles(); Standard_Integer t[3],j; - const Poly_Array1OfTriangle& triangle = myTriangulation->Triangles(); for (i = 1; i <= n; i++) { - triangle(i).Get(t[0],t[1],t[2]); + myTriangulation->Triangle (i).Get(t[0],t[1],t[2]); gp_Pnt P(0,0,0); gp_XYZ& bary = P.ChangeCoord(); for (j = 0; j < 3; j++) - bary.Add(Nodes(t[j]).Coord()); + bary.Add(myTriangulation->Node (t[j]).Coord()); bary.Multiply(1./3.); Sprintf(text,"%d",i); diff --git a/src/DrawTrSurf/DrawTrSurf_Triangulation2D.cxx b/src/DrawTrSurf/DrawTrSurf_Triangulation2D.cxx index 88ba30c3f8..c039024dfc 100644 --- a/src/DrawTrSurf/DrawTrSurf_Triangulation2D.cxx +++ b/src/DrawTrSurf/DrawTrSurf_Triangulation2D.cxx @@ -67,11 +67,10 @@ DrawTrSurf_Triangulation2D::DrawTrSurf_Triangulation2D TColStd_Array1OfInteger& Internal = myInternals->ChangeArray1(); Standard_Integer fr = 1, in = 1; - const Poly_Array1OfTriangle& triangles = T->Triangles(); Standard_Integer n[3]; for (i = 1; i <= nbTriangles; i++) { pc.Triangles(i,t[0],t[1],t[2]); - triangles(i).Get(n[0],n[1],n[2]); + T->Triangle(i).Get(n[0],n[1],n[2]); for (j = 0; j < 3; j++) { Standard_Integer k = (j+1) % 3; if (t[j] == 0) { @@ -109,16 +108,14 @@ void DrawTrSurf_Triangulation2D::DrawOn(Draw_Display& dis) const // Display the edges Standard_Integer i,n; if (myTriangulation->HasUVNodes()) { - - const TColgp_Array1OfPnt2d& Nodes = myTriangulation->UVNodes(); - + // free edges dis.SetColor(Draw_rouge); const TColStd_Array1OfInteger& Free = myFree->Array1(); n = Free.Length() / 2; for (i = 1; i <= n; i++) { - dis.Draw(Nodes(Free(2*i-1)),Nodes(Free(2*i))); + dis.Draw(myTriangulation->UVNode (Free(2*i-1)), myTriangulation->UVNode (Free(2*i))); } // internal edges @@ -127,7 +124,7 @@ void DrawTrSurf_Triangulation2D::DrawOn(Draw_Display& dis) const const TColStd_Array1OfInteger& Internal = myInternals->Array1(); n = Internal.Length() / 2; for (i = 1; i <= n; i++) { - dis.Draw(Nodes(Internal(2*i-1)),Nodes(Internal(2*i))); + dis.Draw(myTriangulation->UVNode (Internal(2*i-1)), myTriangulation->UVNode (Internal(2*i))); } } diff --git a/src/HLRBRep/HLRBRep_PolyAlgo.cxx b/src/HLRBRep/HLRBRep_PolyAlgo.cxx index 134b6c7451..d1a213262c 100644 --- a/src/HLRBRep/HLRBRep_PolyAlgo.cxx +++ b/src/HLRBRep/HLRBRep_PolyAlgo.cxx @@ -812,10 +812,8 @@ void HLRBRep_PolyAlgo::StoreShell (const TopoDS_Shape& Shape, TTMa[2][0] = ttma.Value(3,1); TTMa[2][1] = ttma.Value(3,2); TTMa[2][2] = ttma.Value(3,3); - Poly_Array1OfTriangle & Tri = Tr->ChangeTriangles(); - TColgp_Array1OfPnt & Nod = Tr->ChangeNodes(); - Standard_Integer nbN = Nod.Upper(); - Standard_Integer nbT = Tri.Upper(); + Standard_Integer nbN = Tr->NbNodes(); + Standard_Integer nbT = Tr->NbTriangles(); PD (f) = new HLRAlgo_PolyData(); psd->PolyData().ChangeValue(iFace) = PD(f); PID(f) = new HLRAlgo_PolyInternalData(nbN,nbT); @@ -829,24 +827,21 @@ void HLRBRep_PolyAlgo::StoreShell (const TopoDS_Shape& Shape, Standard_Address TData = &pid->TData(); Standard_Address PISeg = &pid->PISeg(); Standard_Address PINod = &pid->PINod(); - Poly_Triangle * OT = &(Tri.ChangeValue(1)); HLRAlgo_TriangleData* NT = &(((HLRAlgo_Array1OfTData*)TData)->ChangeValue(1)); for (i = 1; i <= nbT; i++) { Standard_Address Tri2Indices = NT->Indices(); - OT->Get(Tri2Node1,Tri2Node2,Tri2Node3); + Tr->Triangle (i).Get(Tri2Node1, Tri2Node2, Tri2Node3); Tri2Flags = 0; if (reversed) { j = Tri2Node1; Tri2Node1 = Tri2Node3; Tri2Node3 = j; } - OT++; NT++; } - gp_Pnt * ON = &(Nod.ChangeValue(1)); Handle(HLRAlgo_PolyInternalNode)* NN = &(((HLRAlgo_Array1OfPINod*)PINod)->ChangeValue(1)); @@ -855,26 +850,23 @@ void HLRBRep_PolyAlgo::StoreShell (const TopoDS_Shape& Shape, const Standard_Address Nod1Indices = (*NN)->Indices(); Nod1NdSg = 0; Nod1Flag = 0; - Nod1PntX = ON->X(); - Nod1PntY = ON->Y(); - Nod1PntZ = ON->Z(); + Nod1PntX = Tr->Node (i).X(); + Nod1PntY = Tr->Node(i).Y(); + Nod1PntZ = Tr->Node(i).Z(); TTMultiply(Nod1PntX,Nod1PntY,Nod1PntZ); - ON++; NN++; } pid->UpdateLinks(TData,PISeg,PINod); if (Tr->HasUVNodes()) { myBSurf.Initialize(F,Standard_False); - TColgp_Array1OfPnt2d & UVN = Tr->ChangeUVNodes(); - gp_Pnt2d* OUVN = &(UVN.ChangeValue(1)); NN = &(((HLRAlgo_Array1OfPINod*)PINod)-> ChangeValue(1)); for (i = 1; i <= nbN; i++) { const Standard_Address Nod1Indices = (*NN)->Indices(); const Standard_Address Nod1RValues = (*NN)->RValues(); - Nod1PntU = OUVN->X(); - Nod1PntV = OUVN->Y(); + Nod1PntU = Tr->UVNode (i).X(); + Nod1PntV = Tr->UVNode (i).Y(); if (Normal(i,Nod1Indices,Nod1RValues, TData,PISeg,PINod,Standard_False)) Nod1Flag |= NMskNorm; @@ -882,7 +874,6 @@ void HLRBRep_PolyAlgo::StoreShell (const TopoDS_Shape& Shape, Nod1Flag &= ~NMskNorm; Nod1Scal = 0; } - OUVN++; NN++; } } diff --git a/src/IVtkOCC/IVtkOCC_ShapeMesher.cxx b/src/IVtkOCC/IVtkOCC_ShapeMesher.cxx index 2adc977964..606006e425 100644 --- a/src/IVtkOCC/IVtkOCC_ShapeMesher.cxx +++ b/src/IVtkOCC/IVtkOCC_ShapeMesher.cxx @@ -379,7 +379,12 @@ void IVtkOCC_ShapeMesher::addEdge (const TopoDS_Edge& theEdge, { Standard_Integer aNbNodes = aPolyOnTriangulation->NbNodes(); const TColStd_Array1OfInteger& aPointIds = aPolyOnTriangulation->Nodes(); - const TColgp_Array1OfPnt& aPoints = aTriangulation->Nodes(); + + TColgp_Array1OfPnt aPoints(1, aTriangulation->NbNodes()); + for (Standard_Integer anI = 1; anI <= aTriangulation->NbNodes(); anI++) + { + aPoints.SetValue (anI, aTriangulation->Node(anI)); + } processPolyline (aNbNodes, aPoints, @@ -943,7 +948,6 @@ void IVtkOCC_ShapeMesher::addShadedFace (const TopoDS_Face& theFace, } // Get triangulation points. - const TColgp_Array1OfPnt& aPoints = anOcctTriangulation->Nodes(); Standard_Integer aNbPoints = anOcctTriangulation->NbNodes(); // Keep inserted points id's of triangulation in an array. @@ -953,7 +957,7 @@ void IVtkOCC_ShapeMesher::addShadedFace (const TopoDS_Face& theFace, Standard_Integer anI; for (anI = 1; anI <= aNbPoints; anI++) { - gp_Pnt aPoint = aPoints (anI); + gp_Pnt aPoint = anOcctTriangulation->Node(anI); if (!noTransform) { @@ -966,12 +970,11 @@ void IVtkOCC_ShapeMesher::addShadedFace (const TopoDS_Face& theFace, } // Create triangles on the created triangulation points. - const Poly_Array1OfTriangle& aTriangles = anOcctTriangulation->Triangles(); Standard_Integer aNbTriangles = anOcctTriangulation->NbTriangles(); Standard_Integer aN1, aN2, aN3; for (anI = 1; anI <= aNbTriangles; anI++) { - aTriangles(anI).Get (aN1, aN2, aN3); // get indexes of triangle's points + anOcctTriangulation->Triangle(anI).Get (aN1, aN2, aN3); // get indexes of triangle's points // Insert new triangle on these points into output shape data. myShapeData->InsertTriangle ( theShapeId, aPointIds(aN1), aPointIds(aN2), aPointIds(aN3), MT_ShadedFace); diff --git a/src/MeshTest/MeshTest.cxx b/src/MeshTest/MeshTest.cxx index fc6165f8f8..9ebe2b5049 100644 --- a/src/MeshTest/MeshTest.cxx +++ b/src/MeshTest/MeshTest.cxx @@ -304,7 +304,6 @@ static Standard_Integer tessellate (Draw_Interpretor& /*di*/, Standard_Integer n new Poly_Triangulation (aNbNodes, aNbTriangles, Standard_False); // fill nodes - TColgp_Array1OfPnt &aNodes = aTriangulation->ChangeNodes(); GeomAdaptor_Surface anAdSurf (aSurf); double aDU = (aUMax - aUMin) / aNbU; double aDV = (aVMax - aVMin) / aNbV; @@ -315,12 +314,11 @@ static Standard_Integer tessellate (Draw_Interpretor& /*di*/, Standard_Integer n { double aV = aVMin + iV * aDV; gp_Pnt aP = anAdSurf.Value (aU, aV); - aNodes.SetValue (iShift + iV, aP); + aTriangulation->ChangeNode(iShift + iV) = aP; } } // fill triangles - Poly_Array1OfTriangle &aTriangles = aTriangulation->ChangeTriangles(); for (int iU = 0, iShift = 1, iTri = 0; iU < aNbU; iU++, iShift += aNbV + 1) { for (int iV = 0; iV < aNbV; iV++) @@ -328,8 +326,8 @@ static Standard_Integer tessellate (Draw_Interpretor& /*di*/, Standard_Integer n int iBase = iShift + iV; Poly_Triangle aTri1 (iBase, iBase + aNbV + 2, iBase + 1); Poly_Triangle aTri2 (iBase, iBase + aNbV + 1, iBase + aNbV + 2); - aTriangles.SetValue (++iTri, aTri1); - aTriangles.SetValue (++iTri, aTri2); + aTriangulation->ChangeTriangle(++iTri) = aTri1; + aTriangulation->ChangeTriangle(++iTri) = aTri2; } } @@ -578,10 +576,9 @@ static void MeshStats(const TopoDS_Shape& theSape, BRepMesh_MapOfCouple aMap; //count number of links - Poly_Array1OfTriangle& Trian = T->ChangeTriangles(); - for(Standard_Integer i = 1; i<=Trian.Length();i++) { + for(Standard_Integer i = 1; i<=T->NbTriangles();i++) { Standard_Integer v1, v2, v3; - Trian(i).Get(v1,v2,v3); + T->Triangle (i).Get(v1,v2,v3); AddLink(aMap, v1, v2); AddLink(aMap, v2, v3); @@ -647,9 +644,8 @@ static Standard_Integer triangule(Draw_Interpretor& di, Standard_Integer nbarg, if (!aTriangulation.IsNull()) { const Standard_Integer aLength = aTriangulation->NbNodes(); - const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes(); for (Standard_Integer i = 1; i <= aLength; ++i) - aBox.Add(aNodes(i)); + aBox.Add(aTriangulation->Node (i)); } } @@ -1181,21 +1177,18 @@ static Standard_Integer veriftriangles(Draw_Interpretor& di, Standard_Integer n, Standard_Real deflemax = 0, deflemin = 1.e100; if (!T.IsNull()) { Standard_Real defstock = T->Deflection(); - const Poly_Array1OfTriangle& triangles = T->Triangles(); - const TColgp_Array1OfPnt2d& Nodes2d = T->UVNodes(); - const TColgp_Array1OfPnt& Nodes = T->Nodes(); S = BRep_Tool::Surface(F, L); - for(i = 1; i <= triangles.Length(); i++) { + for(i = 1; i <= T->NbTriangles(); i++) { if (F.Orientation() == TopAbs_REVERSED) - triangles(i).Get(n1,n3,n2); + T->Triangle (i).Get(n1,n3,n2); else - triangles(i).Get(n1,n2,n3); + T->Triangle (i).Get(n1,n2,n3); - const gp_XY& xy1 = Nodes2d(n1).XY(); - const gp_XY& xy2 = Nodes2d(n2).XY(); - const gp_XY& xy3 = Nodes2d(n3).XY(); + const gp_XY& xy1 = T->UVNode (n1).XY(); + const gp_XY& xy2 = T->UVNode (n2).XY(); + const gp_XY& xy3 = T->UVNode (n3).XY(); mi2d1.SetCoord((xy2.X()+xy3.X())*0.5, (xy2.Y()+xy3.Y())*0.5); @@ -1204,9 +1197,9 @@ static Standard_Integer veriftriangles(Draw_Interpretor& di, Standard_Integer n, mi2d3.SetCoord((xy1.X()+xy2.X())*0.5, (xy1.Y()+xy2.Y())*0.5); - gp_XYZ p1 = Nodes(n1).Transformed(L.Transformation()).XYZ(); - gp_XYZ p2 = Nodes(n2).Transformed(L.Transformation()).XYZ(); - gp_XYZ p3 = Nodes(n3).Transformed(L.Transformation()).XYZ(); + gp_XYZ p1 = T->Node (n1).Transformed (L.Transformation()).XYZ(); + gp_XYZ p2 = T->Node (n2).Transformed (L.Transformation()).XYZ(); + gp_XYZ p3 = T->Node (n3).Transformed (L.Transformation()).XYZ(); vecEd1=p2-p1; vecEd2=p3-p2; @@ -1332,11 +1325,10 @@ Standard_Integer tri2d(Draw_Interpretor&, Standard_Integer n, const char** a) TColStd_Array1OfInteger Internal(0,2*nInternal); Standard_Integer fr = 1, in = 1; - const Poly_Array1OfTriangle& triangles = T->Triangles(); Standard_Integer nodes[3]; for (i = 1; i <= nbTriangles; i++) { pc.Triangles(i,t[0],t[1],t[2]); - triangles(i).Get(nodes[0],nodes[1],nodes[2]); + T->Triangle (i).Get(nodes[0],nodes[1],nodes[2]); for (j = 0; j < 3; j++) { Standard_Integer k = (j+1) % 3; if (t[j] == 0) { @@ -1355,16 +1347,14 @@ Standard_Integer tri2d(Draw_Interpretor&, Standard_Integer n, const char** a) // Display the edges if (T->HasUVNodes()) { - const TColgp_Array1OfPnt2d& Nodes2d = T->UVNodes(); - Handle(Draw_Segment2D) Seg; // free edges Standard_Integer nn; nn = Free.Length() / 2; for (i = 1; i <= nn; i++) { - Seg = new Draw_Segment2D(Nodes2d(Free(2*i-1)), - Nodes2d(Free(2*i)), + Seg = new Draw_Segment2D(T->UVNode (Free(2*i-1)), + T->UVNode (Free(2*i)), Draw_rouge); dout << Seg; } @@ -1373,8 +1363,8 @@ Standard_Integer tri2d(Draw_Interpretor&, Standard_Integer n, const char** a) nn = nInternal; for (i = 1; i <= nn; i++) { - Seg = new Draw_Segment2D(Nodes2d(Internal(2*i-1)), - Nodes2d(Internal(2*i)), + Seg = new Draw_Segment2D(T->UVNode (Internal(2*i-1)), + T->UVNode (Internal(2*i)), Draw_bleu); dout << Seg; } @@ -1448,11 +1438,10 @@ static Standard_Integer wavefront(Draw_Interpretor&, Standard_Integer nbarg, con if (!Tr.IsNull()) { nbNodes = Tr->NbNodes(); - const TColgp_Array1OfPnt& Nodes = Tr->Nodes(); // les noeuds. for (i = 1; i <= nbNodes; i++) { - gp_Pnt Pnt = Nodes(i).Transformed(L.Transformation()); + gp_Pnt Pnt = Tr->Node (i).Transformed(L.Transformation()); x = Pnt.X(); y = Pnt.Y(); z = Pnt.Z(); @@ -1465,12 +1454,11 @@ static Standard_Integer wavefront(Draw_Interpretor&, Standard_Integer nbarg, con // les normales. if (Tr->HasUVNodes()) { - const TColgp_Array1OfPnt2d& UVNodes = Tr->UVNodes(); BRepAdaptor_Surface BS(F, Standard_False); for (i = 1; i <= nbNodes; i++) { - U = UVNodes(i).X(); - V = UVNodes(i).Y(); + U = Tr->UVNode (i).X(); + V = Tr->UVNode (i).Y(); BS.D1(U,V,P,D1U,D1V); CSLib::Normal(D1U,D1V,Precision::Angular(),Status,Nor); @@ -1490,14 +1478,12 @@ static Standard_Integer wavefront(Draw_Interpretor&, Standard_Integer nbarg, con // les triangles. Standard_Integer nbTriangles = Tr->NbTriangles(); - const Poly_Array1OfTriangle& triangles = Tr->Triangles(); - for (i = 1; i <= nbTriangles; i++) { if (F.Orientation() == TopAbs_REVERSED) - triangles(i).Get(n1, n3, n2); + Tr->Triangle (i).Get(n1, n3, n2); else - triangles(i).Get(n1, n2, n3); + Tr->Triangle (i).Get(n1, n2, n3); k1 = n1+totalnodes; k2 = n2+totalnodes; k3 = n3+totalnodes; @@ -1707,14 +1693,13 @@ Standard_Integer triedgepoints(Draw_Interpretor& di, Standard_Integer nbarg, con BRep_Tool::PolygonOnTriangulation(TopoDS::Edge(it.Key()), aPoly, aT, aLoc); if ( aT.IsNull() || aPoly.IsNull() ) continue; - - const TColgp_Array1OfPnt& Nodes = aT->Nodes(); + const TColStd_Array1OfInteger& Indices = aPoly->Nodes(); const Standard_Integer nbnodes = Indices.Length(); for( Standard_Integer j = 1; j <= nbnodes; j++ ) { - gp_Pnt P3d = Nodes(Indices(j)); + gp_Pnt P3d = aT->Node (Indices(j)); if( !aLoc.IsIdentity() ) P3d.Transform(aLoc.Transformation()); diff --git a/src/MeshTest/MeshTest_CheckTopology.cxx b/src/MeshTest/MeshTest_CheckTopology.cxx index c0887c65f1..eb785ca4d1 100644 --- a/src/MeshTest/MeshTest_CheckTopology.cxx +++ b/src/MeshTest/MeshTest_CheckTopology.cxx @@ -88,8 +88,6 @@ void MeshTest_CheckTopology::Perform (Draw_Interpretor& di) // check distances between corresponding points Standard_Real aDefle = Max(aT1->Deflection(), aT2->Deflection()); - const TColgp_Array1OfPnt& aPoints1 = aT1->Nodes(); - const TColgp_Array1OfPnt& aPoints2 = aT2->Nodes(); Standard_Integer iF1 = aMapF.FindIndex(aFace1); Standard_Integer iF2 = aMapF.FindIndex(aFace2); Standard_Integer i1 = aNodes1.Lower(); @@ -97,8 +95,8 @@ void MeshTest_CheckTopology::Perform (Draw_Interpretor& di) gp_Trsf aTrsf1 = aFace1.Location().Transformation(); gp_Trsf aTrsf2 = aFace2.Location().Transformation(); for (; i1 <= aNodes1.Upper(); i1++, i2++) { - gp_Pnt aP1 = aPoints1(aNodes1(i1)).Transformed(aTrsf1); - gp_Pnt aP2 = aPoints2(aNodes2(i2)).Transformed(aTrsf2); + gp_Pnt aP1 = aT1->Node (aNodes1(i1)).Transformed(aTrsf1); + gp_Pnt aP2 = aT2->Node (aNodes2(i2)).Transformed(aTrsf2); Standard_Real aDist = aP1.Distance(aP2); if (aDist > aDefle) { myErrors.Append(iF1); @@ -140,10 +138,9 @@ void MeshTest_CheckTopology::Perform (Draw_Interpretor& di) // check of free links and nodes Poly_Connect aConn(aT); - const Poly_Array1OfTriangle& aTriangles = aT->Triangles(); Standard_Integer nbTri = aT->NbTriangles(), i, j, n[3], t[3]; for (i = 1; i <= nbTri; i++) { - aTriangles(i).Get(n[0], n[1], n[2]); + aT->Triangle (i).Get(n[0], n[1], n[2]); aUsedNodes.Add (n[0]); aUsedNodes.Add (n[1]); diff --git a/src/MeshTest/MeshTest_DrawableMesh.cxx b/src/MeshTest/MeshTest_DrawableMesh.cxx index 5385c51e55..d6f4bdda58 100644 --- a/src/MeshTest/MeshTest_DrawableMesh.cxx +++ b/src/MeshTest/MeshTest_DrawableMesh.cxx @@ -253,10 +253,9 @@ void MeshTest_DrawableMesh::Whatis(Draw_Interpretor& theStream) const // Count number of links BRepMesh_MapOfLinks aMap; - const Poly_Array1OfTriangle& aTriangles = aTriangulation->Triangles(); - for (Standard_Integer i = 1, v[3]; i <= aTriangles.Length(); ++i) + for (Standard_Integer i = 1, v[3]; i <= aTriangulation->NbTriangles(); ++i) { - aTriangles(i).Get(v[0], v[1], v[2]); + aTriangulation->Triangle (i).Get(v[0], v[1], v[2]); addLink(v[0], v[1], aMap); addLink(v[1], v[2], aMap); diff --git a/src/MeshTest/MeshTest_PluginCommands.cxx b/src/MeshTest/MeshTest_PluginCommands.cxx index 0e8e509238..fad5a76b06 100644 --- a/src/MeshTest/MeshTest_PluginCommands.cxx +++ b/src/MeshTest/MeshTest_PluginCommands.cxx @@ -300,15 +300,13 @@ static Standard_Integer triarea (Draw_Interpretor& di, int n, const char ** a) cout << "face "<Triangles(); - const TColgp_Array1OfPnt& nodes = aPoly->Nodes(); - for (int j=triangles.Lower(); j <= triangles.Upper(); j++) { - const Poly_Triangle& tri = triangles(j); + for (int j = 1; j <= aPoly->NbTriangles(); j++) { + const Poly_Triangle& tri = aPoly->Triangle (j); int n1, n2, n3; tri.Get (n1, n2, n3); - const gp_Pnt& p1 = nodes(n1); - const gp_Pnt& p2 = nodes(n2); - const gp_Pnt& p3 = nodes(n3); + const gp_Pnt& p1 = aPoly->Node (n1); + const gp_Pnt& p2 = aPoly->Node (n2); + const gp_Pnt& p3 = aPoly->Node (n3); gp_Vec v1(p1, p2); gp_Vec v2(p1, p3); double ar = v1.CrossMagnitude(v2); @@ -365,7 +363,6 @@ static Standard_Integer tricheck (Draw_Interpretor& di, int n, const char ** a) const TopoDS_Face& aFace = TopoDS::Face(aShape); TopLoc_Location aLoc; Handle(Poly_Triangulation) aT = BRep_Tool::Triangulation(aFace, aLoc); - const TColgp_Array1OfPnt& aPoints = aT->Nodes(); const gp_Trsf& trsf = aLoc.Transformation(); TColgp_Array1OfPnt pnts(1,2); @@ -374,17 +371,16 @@ static Standard_Integer tricheck (Draw_Interpretor& di, int n, const char ** a) Standard_Integer n1, n2; aCheck.GetFreeLink(k, i, n1, n2); di << "{" << n1 << " " << n2 << "} "; - pnts(1) = aPoints(n1).Transformed(trsf); - pnts(2) = aPoints(n2).Transformed(trsf); + pnts(1) = aT->Node (n1).Transformed(trsf); + pnts(2) = aT->Node (n2).Transformed(trsf); Handle(Poly_Polygon3D) poly = new Poly_Polygon3D (pnts); DrawTrSurf::Set (name, poly); DrawTrSurf::Set (name, pnts(1)); DrawTrSurf::Set (name, pnts(2)); if (aT->HasUVNodes()) { - const TColgp_Array1OfPnt2d& aPoints2d = aT->UVNodes(); - pnts2d(1) = aPoints2d(n1); - pnts2d(2) = aPoints2d(n2); + pnts2d(1) = aT->UVNode (n1); + pnts2d(2) = aT->UVNode (n2); Handle(Poly_Polygon2D) poly2d = new Poly_Polygon2D (pnts2d); DrawTrSurf::Set (name, poly2d); DrawTrSurf::Set (name, pnts2d(1)); @@ -430,12 +426,11 @@ static Standard_Integer tricheck (Draw_Interpretor& di, int n, const char ** a) const TopoDS_Face& aFace = TopoDS::Face(aMapF.FindKey(iface)); TopLoc_Location aLoc; Handle(Poly_Triangulation) aT = BRep_Tool::Triangulation(aFace, aLoc); - const TColgp_Array1OfPnt& aPoints = aT->Nodes(); const gp_Trsf& trsf = aLoc.Transformation(); - DrawTrSurf::Set (name, aPoints(inode).Transformed(trsf)); + DrawTrSurf::Set (name, aT->Node(inode).Transformed(trsf)); if (aT->HasUVNodes()) { - DrawTrSurf::Set (name, aT->UVNodes()(inode)); + DrawTrSurf::Set (name, aT->UVNode(inode)); } di << "{" << iface << " " << inode << "} "; @@ -496,12 +491,11 @@ static Standard_Integer tricheck (Draw_Interpretor& di, int n, const char ** a) break; } - const Poly_Array1OfTriangle& aTris = aT->Triangles(); NCollection_Map aFreeEdgeMap; - Standard_Integer aTriNum = aTris.Length(); + Standard_Integer aTriNum = aT->NbTriangles(); for ( Standard_Integer aTriIndx = 1; aTriIndx <= aTriNum; aTriIndx++ ) { - const Poly_Triangle& aTri = aTris(aTriIndx); + const Poly_Triangle& aTri = aT->Triangle (aTriIndx); Standard_Integer aTriNodes[3] = { aTri.Value(1), aTri.Value(2), aTri.Value(3)}; for (Standard_Integer j = 1; j <= 3; ++j) @@ -524,7 +518,6 @@ static Standard_Integer tricheck (Draw_Interpretor& di, int n, const char ** a) { di << "Not connected mesh inside face " << aFaceId << "\n"; - const TColgp_Array1OfPnt& aPoints = aT->Nodes(); const gp_Trsf& trsf = aLoc.Transformation(); TColgp_Array1OfPnt pnts(1,2); @@ -534,17 +527,16 @@ static Standard_Integer tricheck (Draw_Interpretor& di, int n, const char ** a) { const BRepMesh_Edge& aLink = aMapIt.Key(); di << "{" << aLink.FirstNode() << " " << aLink.LastNode() << "} "; - pnts(1) = aPoints(aLink.FirstNode()).Transformed(trsf); - pnts(2) = aPoints(aLink.LastNode()).Transformed(trsf); + pnts(1) = aT->Node(aLink.FirstNode()).Transformed(trsf); + pnts(2) = aT->Node(aLink.LastNode()).Transformed(trsf); Handle(Poly_Polygon3D) poly = new Poly_Polygon3D (pnts); DrawTrSurf::Set (name, poly); DrawTrSurf::Set (name, pnts(1)); DrawTrSurf::Set (name, pnts(2)); if (aT->HasUVNodes()) { - const TColgp_Array1OfPnt2d& aPoints2d = aT->UVNodes(); - pnts2d(1) = aPoints2d(aLink.FirstNode()); - pnts2d(2) = aPoints2d(aLink.LastNode()); + pnts2d(1) = aT->UVNode(aLink.FirstNode()); + pnts2d(2) = aT->UVNode(aLink.LastNode()); Handle(Poly_Polygon2D) poly2d = new Poly_Polygon2D (pnts2d); DrawTrSurf::Set (name, poly2d); DrawTrSurf::Set (name, pnts2d(1)); diff --git a/src/Poly/FILES b/src/Poly/FILES index 641d172ec0..170352103c 100755 --- a/src/Poly/FILES +++ b/src/Poly/FILES @@ -14,22 +14,25 @@ Poly_CoherentTriPtr.hxx Poly_Connect.cxx Poly_Connect.hxx Poly_Connect.lxx +Poly_Element.cxx +Poly_Element.hxx Poly_HArray1OfTriangle.hxx Poly_ListOfTriangulation.hxx Poly_MakeLoops.cxx Poly_MakeLoops.hxx -Poly_Polygon2D.cxx +Poly_Mesh.cxx +Poly_Mesh.hxx Poly_Polygon2D.hxx +Poly_Polygon2D.cxx Poly_Polygon2D.lxx -Poly_Polygon3D.cxx Poly_Polygon3D.hxx +Poly_Polygon3D.cxx Poly_Polygon3D.lxx -Poly_PolygonOnTriangulation.cxx Poly_PolygonOnTriangulation.hxx +Poly_PolygonOnTriangulation.cxx Poly_PolygonOnTriangulation.lxx -Poly_Triangle.cxx Poly_Triangle.hxx +Poly_Triangle.cxx Poly_Triangle.lxx -Poly_Triangulation.cxx Poly_Triangulation.hxx -Poly_Triangulation.lxx +Poly_Triangulation.cxx \ No newline at end of file diff --git a/src/Poly/Poly.cxx b/src/Poly/Poly.cxx index 63db7243c9..ff375f6d31 100644 --- a/src/Poly/Poly.cxx +++ b/src/Poly/Poly.cxx @@ -57,23 +57,19 @@ Handle(Poly_Triangulation) Poly::Catenate (const Poly_ListOfTriangulation& lstTr Standard_Integer i, iNode[3]; nNodes = 0; nTrian = 0; - TColgp_Array1OfPnt& arrNode = aResult->ChangeNodes(); - Poly_Array1OfTriangle& arrTrian = aResult->ChangeTriangles(); for (anIter.Init(lstTri); anIter.More(); anIter.Next()) { const Handle(Poly_Triangulation)& aTri = anIter.Value(); if (aTri.IsNull() == Standard_False) { - const TColgp_Array1OfPnt& srcNode = aTri->Nodes(); - const Poly_Array1OfTriangle& srcTrian = aTri->Triangles(); const Standard_Integer nbNodes = aTri->NbNodes(); const Standard_Integer nbTrian = aTri->NbTriangles(); for (i = 1; i <= nbNodes; i++) { - arrNode.SetValue(i + nNodes, srcNode(i)); + aResult->ChangeNode (i + nNodes) = aTri->Node (i); } for (i = 1; i <= nbTrian; i++) { - srcTrian(i).Get(iNode[0], iNode[1], iNode[2]); - arrTrian.SetValue(i + nTrian, Poly_Triangle(iNode[0] + nNodes, + aTri->Triangle (i).Get(iNode[0], iNode[1], iNode[2]); + aResult->ChangeTriangle (i + nTrian) = Poly_Triangle(iNode[0] + nNodes, iNode[1] + nNodes, - iNode[2] + nNodes)); + iNode[2] + nNodes); } nNodes += nbNodes; nTrian += nbTrian; @@ -113,36 +109,33 @@ void Poly::Write(const Handle(Poly_Triangulation)& T, if (!Compact) OS << "\n3D Nodes :\n"; Standard_Integer i, nbNodes = T->NbNodes(); - const TColgp_Array1OfPnt& Nodes = T->Nodes(); for (i = 1; i <= nbNodes; i++) { if (!Compact) OS << setw(10) << i << " : "; if (!Compact) OS << setw(17); - OS << Nodes(i).X() << " "; + OS << T->Node (i).X() << " "; if (!Compact) OS << setw(17); - OS << Nodes(i).Y() << " "; + OS << T->Node (i).Y() << " "; if (!Compact) OS << setw(17); - OS << Nodes(i).Z() << "\n"; + OS << T->Node (i).Z() << "\n"; } if (T->HasUVNodes()) { if (!Compact) OS << "\nUV Nodes :\n"; - const TColgp_Array1OfPnt2d& UVNodes = T->UVNodes(); for (i = 1; i <= nbNodes; i++) { if (!Compact) OS << setw(10) << i << " : "; if (!Compact) OS << setw(17); - OS << UVNodes(i).X() << " "; + OS << T->UVNode (i).X() << " "; if (!Compact) OS << setw(17); - OS << UVNodes(i).Y() << "\n"; + OS << T->UVNode (i).Y() << "\n"; } } if (!Compact) OS << "\nTriangles :\n"; Standard_Integer nbTriangles = T->NbTriangles(); Standard_Integer n1, n2, n3; - const Poly_Array1OfTriangle& Triangles = T->Triangles(); for (i = 1; i <= nbTriangles; i++) { if (!Compact) OS << setw(10) << i << " : "; - Triangles(i).Get(n1, n2, n3); + T->Triangle(i).Get(n1, n2, n3); if (!Compact) OS << setw(10); OS << n1 << " "; if (!Compact) OS << setw(10); @@ -448,8 +441,6 @@ Handle(Poly_Polygon2D) Poly::ReadPolygon2D(Standard_IStream& IS) void Poly::ComputeNormals(const Handle(Poly_Triangulation)& Tri) { - const TColgp_Array1OfPnt& arrNodes = Tri->Nodes(); - const Poly_Array1OfTriangle & arrTri = Tri->Triangles(); Standard_Integer nbNormVal = Tri->NbNodes() * 3; const Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, nbNormVal); @@ -462,12 +453,12 @@ void Poly::ComputeNormals(const Handle(Poly_Triangulation)& Tri) Standard_Integer iN, iTri; const Standard_Real eps2 = gp::Resolution(); - for (iTri = 1; iTri <= arrTri.Length(); iTri++) { + for (iTri = 1; iTri <= Tri->NbTriangles(); iTri++) { // Get the nodes of the current triangle - arrTri(iTri).Get (iNode[0], iNode[1], iNode[2]); + Tri->Triangle (iTri).Get (iNode[0], iNode[1], iNode[2]); const gp_XYZ aVec[2] = { - arrNodes(iNode[1]).XYZ() - arrNodes(iNode[0]).XYZ(), - arrNodes(iNode[2]).XYZ() - arrNodes(iNode[0]).XYZ() + Tri->Node (iNode[1]).XYZ() - Tri->Node (iNode[0]).XYZ(), + Tri->Node (iNode[2]).XYZ() - Tri->Node (iNode[0]).XYZ() }; // Find the normal vector of the current triangle diff --git a/src/Poly/Poly_CoherentTriangulation.cxx b/src/Poly/Poly_CoherentTriangulation.cxx index 0c2f7617ae..f15a72aafa 100644 --- a/src/Poly/Poly_CoherentTriangulation.cxx +++ b/src/Poly/Poly_CoherentTriangulation.cxx @@ -51,44 +51,37 @@ Poly_CoherentTriangulation::Poly_CoherentTriangulation : theAlloc) { if (theTriangulation.IsNull() == Standard_False) { - const TColgp_Array1OfPnt& arrNodes = theTriangulation->Nodes(); - const Poly_Array1OfTriangle& arrTriangle = theTriangulation->Triangles(); const Standard_Integer nNodes = theTriangulation->NbNodes(); - const Standard_Integer nTri = theTriangulation->NbTriangles(); Standard_Integer i; // Copy the nodes for (i = 0; i < nNodes; i++) { - const Standard_Integer anOldInd = i + arrNodes.Lower(); - const Standard_Integer aNewInd = SetNode(arrNodes(anOldInd).XYZ(), i); + const Standard_Integer anOldInd = i + 1; + const Standard_Integer aNewInd = SetNode(theTriangulation->Node (anOldInd).XYZ(), i); Poly_CoherentNode& aCopiedNode = myNodes(aNewInd); aCopiedNode.SetIndex(anOldInd); } // Copy the triangles - for (i = 0; i < nTri; i++) { + for (i = 1; i <= theTriangulation->NbTriangles(); i++) { Standard_Integer iNode[3]; - arrTriangle(i + arrTriangle.Lower()).Get(iNode[0], iNode[1], iNode[2]); + theTriangulation->Triangle (i).Get(iNode[0], iNode[1], iNode[2]); if (iNode[0] != iNode[1] && iNode[1] != iNode[2] && iNode[2] != iNode[0]) AddTriangle (iNode[0]-1, iNode[1]-1, iNode[2]-1); } // Copy UV coordinates of nodes if (theTriangulation->HasUVNodes()) { - const TColgp_Array1OfPnt2d& arrNodes2d = theTriangulation->UVNodes(); for (i = 0; i < nNodes; i++) { - const gp_Pnt2d& anUV = arrNodes2d(i + arrNodes2d.Lower()); + const gp_Pnt2d& anUV = theTriangulation->UVNode (i + 1); myNodes(i).SetUV(anUV.X(), anUV.Y()); } } // Copy the normals at nodes if (theTriangulation->HasNormals()) { - const TShort_Array1OfShortReal& arrNorm = theTriangulation->Normals(); for (i = 0; i < nNodes; i++) { - const gp_XYZ aNormal (arrNorm(3 * i + 0 + arrNorm.Lower()), - arrNorm(3 * i + 1 + arrNorm.Lower()), - arrNorm(3 * i + 2 + arrNorm.Lower())); + const gp_XYZ aNormal = theTriangulation->Normal (i + 1).XYZ(); myNodes(i).SetNormal(aNormal); } } @@ -125,9 +118,6 @@ Handle(Poly_Triangulation) Poly_CoherentTriangulation::GetTriangulation() const new TShort_HArray1OfShortReal(1, 3 * nNodes); Standard_ShortReal * arrNormal = &harrNormal->ChangeValue(1); - TColgp_Array1OfPnt& arrNodes = aResult->ChangeNodes(); - TColgp_Array1OfPnt2d& arrNodesUV = aResult->ChangeUVNodes(); - Poly_Array1OfTriangle& arrTriangle = aResult->ChangeTriangles(); NCollection_Vector vecNodeId; Standard_Integer i, aCount(0); Standard_Boolean hasUV (Standard_False); @@ -145,9 +135,9 @@ Handle(Poly_Triangulation) Poly_CoherentTriangulation::GetTriangulation() const arrNormal[3 * aCount + 2] = static_cast(aNormal.Z()); vecNodeId.SetValue(i, ++aCount); - arrNodes.SetValue(aCount, aNode); + aResult->ChangeNode (aCount) = aNode; - arrNodesUV.SetValue(aCount, gp_Pnt2d(aNode.GetU(), aNode.GetV())); + aResult->ChangeUVNode (aCount) = gp_Pnt2d(aNode.GetU(), aNode.GetV()); if (aNode.GetU()*aNode.GetU() + aNode.GetV()*aNode.GetV() > Precision::Confusion()) hasUV = Standard_True; @@ -164,10 +154,9 @@ Handle(Poly_Triangulation) Poly_CoherentTriangulation::GetTriangulation() const for (; anIterT.More(); anIterT.Next()) { const Poly_CoherentTriangle& aTri = anIterT.Value(); if (aTri.IsEmpty() == Standard_False) { - const Poly_Triangle aPolyTriangle (vecNodeId(aTri.Node(0)), - vecNodeId(aTri.Node(1)), - vecNodeId(aTri.Node(2))); - arrTriangle.SetValue(++aCount, aPolyTriangle); + aResult->ChangeTriangle (++aCount) = Poly_Triangle (vecNodeId(aTri.Node(0)), + vecNodeId(aTri.Node(1)), + vecNodeId(aTri.Node(2)));; } } if (hasNormals) diff --git a/src/Poly/Poly_Connect.cxx b/src/Poly/Poly_Connect.cxx index 992053902a..b2571c698d 100644 --- a/src/Poly/Poly_Connect.cxx +++ b/src/Poly/Poly_Connect.cxx @@ -58,12 +58,11 @@ Poly_Connect::Poly_Connect(const Handle(Poly_Triangulation)& T) : // loop on the triangles Standard_Integer j,k,n[3],n1,n2; - const Poly_Array1OfTriangle& triangles = myTriangulation->Triangles(); for (i = 1; i <= nbTriangles; i++) { // get the nodes - triangles(i).Get(n[0],n[1],n[2]); + myTriangulation->Triangle (i).Get(n[0],n[1],n[2]); // Update the myTriangles array myTriangles(n[0]) = i; @@ -120,7 +119,7 @@ Poly_Connect::Poly_Connect(const Handle(Poly_Triangulation)& T) : for (i = 1; i <= nbTriangles; i++) { // get the nodes - triangles(i).Get(n[0],n[1],n[2]); + myTriangulation->Triangle (i).Get(n[0],n[1],n[2]); // fore each edge for (j = 0; j < 3; j++) { @@ -212,8 +211,7 @@ void Poly_Connect::Initialize(const Standard_Integer N) if (mymore) { Standard_Integer i, no[3]; - const Poly_Array1OfTriangle& triangles = myTriangulation->Triangles(); - triangles(myfirst).Get(no[0], no[1], no[2]); + myTriangulation->Triangle (myfirst).Get(no[0], no[1], no[2]); for (i = 0; i < 3; i++) if (no[i] == mynode) break; myothernode = no[(i+2)%3]; @@ -230,12 +228,11 @@ void Poly_Connect::Next() Standard_Integer i, j; Standard_Integer n[3]; Standard_Integer t[3]; - const Poly_Array1OfTriangle& triangles = myTriangulation->Triangles(); Triangles(mytr, t[0], t[1], t[2]); if (mysense) { for (i = 0; i < 3; i++) { if (t[i] != 0) { - triangles(t[i]).Get(n[0], n[1], n[2]); + myTriangulation->Triangle (t[i]).Get(n[0], n[1], n[2]); for (j = 0; j < 3; j++) { if ((n[j] == mynode) && (n[(j+1)%3] == myothernode)) { mytr = t[i]; @@ -247,7 +244,7 @@ void Poly_Connect::Next() } } // sinon, depart vers la gauche. - triangles(myfirst).Get(n[0], n[1], n[2]); + myTriangulation->Triangle (myfirst).Get(n[0], n[1], n[2]); for (i = 0; i < 3; i++) if (n[i] == mynode) break; myothernode = n[(i+1)%3]; @@ -258,7 +255,7 @@ void Poly_Connect::Next() if (!mysense) { for (i = 0; i < 3; i++) { if (t[i] != 0) { - triangles(t[i]).Get(n[0], n[1], n[2]); + myTriangulation->Triangle (t[i]).Get(n[0], n[1], n[2]); for (j = 0; j < 3; j++) { if ((n[j] == mynode) && (n[(j+2)%3] == myothernode)) { mytr = t[i]; diff --git a/src/Poly/Poly_Element.cxx b/src/Poly/Poly_Element.cxx new file mode 100644 index 0000000000..28011efce3 --- /dev/null +++ b/src/Poly/Poly_Element.cxx @@ -0,0 +1,60 @@ +// 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 + +//======================================================================= +//function : Poly_Element +//purpose : +//======================================================================= + +Poly_Element::Poly_Element() +{ + myTriangles[0] = myTriangles[1] = 0; +} + +//======================================================================= +//function : Poly_Element +//purpose : +//======================================================================= + +Poly_Element::Poly_Element (const Standard_Integer theTriangle1, + const Standard_Integer theTriangle2) +{ + myTriangles[0] = theTriangle1; + myTriangles[1] = theTriangle2; +} + +//======================================================================= +//function : Set +//purpose : +//======================================================================= + +void Poly_Element::Set (const Standard_Integer theTriangle1, + const Standard_Integer theTriangle2) +{ + myTriangles[0] = theTriangle1; + myTriangles[1] = theTriangle2; +} + +//======================================================================= +//function : Get +//purpose : +//======================================================================= + +void Poly_Element::Get (Standard_Integer& theTriangle1, + Standard_Integer& theTriangle2) const +{ + theTriangle1 = myTriangles[0]; + theTriangle2 = myTriangles[1]; +} diff --git a/src/Poly/Poly_Element.hxx b/src/Poly/Poly_Element.hxx new file mode 100644 index 0000000000..2374826dc5 --- /dev/null +++ b/src/Poly/Poly_Element.hxx @@ -0,0 +1,84 @@ +// 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 _Poly_Element_HeaderFile +#define _Poly_Element_HeaderFile + +#include +#include +#include + +//! Describes an element on mesh. +//! It can be defined as triangle index (in this case second index will be 0) +//! or as a pair of triangles indices that make up the quad. +class Poly_Element +{ + +public: + + DEFINE_STANDARD_ALLOC + + //! Constructs an element and sets all indices to zero. + Standard_EXPORT Poly_Element(); + + //! Constructs an element and sets it indices. + Standard_EXPORT Poly_Element (const Standard_Integer theTriangle1, + const Standard_Integer theTriangle2); + + //! Sets the value of triangles indices. + Standard_EXPORT void Set (const Standard_Integer theTriangle1, + const Standard_Integer theTriangle2); + + //! Returns the triangles indices of this element in theTriangle1, theTriangle2. + Standard_EXPORT void Get (Standard_Integer& theTriangle1, + Standard_Integer& theTriangle2) const; + + //! @return the triangle index of given element theIndex. + //! Raises OutOfRange from Standard if theIndex is not in 1,2. + Standard_Integer Value (const Standard_Integer theIndex) const + { + Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > 2, NULL); + return myTriangles[theIndex - 1]; + } + + Standard_Integer operator() (const Standard_Integer theIndex) const { return Value (theIndex); } + + //! @return the triangle index of given element theIndex. + //! Raises OutOfRange from Standard if theIndex is not in 1,2. + Standard_Integer& ChangeValue (const Standard_Integer theIndex) + { + Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > 2, NULL); + return myTriangles[theIndex - 1]; + } + + Standard_Integer& operator() (const Standard_Integer theIndex) { return ChangeValue (theIndex); } + + //! @return Standard_True if the first element index > 0 and the second index == 0. + Standard_Boolean IsTriangle() const + { + return (myTriangles[0] > 0 && myTriangles[1] == 0); + } + + //! @return Standard_True if the first and the second element indices > 0. + Standard_Boolean IsQuad() const + { + return (myTriangles[0] > 0 && myTriangles[1] > 0); + } + +private: + + Standard_Integer myTriangles[2]; + +}; + +#endif // _Poly_Element_HeaderFile diff --git a/src/Poly/Poly_Mesh.cxx b/src/Poly/Poly_Mesh.cxx new file mode 100644 index 0000000000..e4e9fcb149 --- /dev/null +++ b/src/Poly/Poly_Mesh.cxx @@ -0,0 +1,199 @@ +// 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 + +IMPLEMENT_STANDARD_RTTIEXT (Poly_Mesh, Poly_Triangulation) + +//======================================================================= +//function : Poly_Mesh +//purpose : +//======================================================================= + +Poly_Mesh::Poly_Mesh (const Standard_Boolean theHasUVNodes) +: Poly_Triangulation (0, 0, theHasUVNodes), + myNbQuads (0) +{} + +//======================================================================= +//function : Poly_Mesh +//purpose : +//======================================================================= + +Poly_Mesh::Poly_Mesh (const Handle(Poly_Triangulation)& theTriangulation) +: Poly_Triangulation ( theTriangulation ), + myNbQuads (0) +{ + const Standard_Integer aNbTris = theTriangulation->NbTriangles(); + + // Fill collection of elements + if ( aNbTris ) + myElements.SetValue( aNbTris - 1, Poly_Element() ); + + // Populate elements with triangles + for ( Standard_Integer i = 1; i <= aNbTris; ++i ) + { + myElements(i - 1).Set(i, 0); + } +} + +//======================================================================= +//function : Copy +//purpose : +//======================================================================= + +Handle(Poly_Triangulation) Poly_Mesh::Copy() const +{ + const Standard_Boolean hasUV = HasUVNodes(); + Handle(Poly_Mesh) aCopy = new Poly_Mesh(hasUV); + // Copy nodes + Standard_Integer aNbNodes = NbNodes(); + for ( Standard_Integer i = 1; i <= aNbNodes; ++i ) + { + aCopy->AddNode(Node(i)); + if ( hasUV ) + aCopy->ChangeUVNode(i) = UVNode(i); + } + // Copy triangles + Standard_Integer aNbTriangles = NbTriangles(); + const Standard_Boolean hasNormals = HasNormals(); + for ( Standard_Integer i = 1; i <= aNbTriangles; ++i ) + { + aCopy->AddTriangle(Triangle(i)); + // Pass normal vector (if any) + if ( hasNormals ) + aCopy->SetNormal(i, Normal(i)); + } + // Copy quads + aCopy->myNbQuads = myNbQuads; + aCopy->myElements = myElements; + return aCopy; +} + +//======================================================================= +//function : AddElement +//purpose : +//======================================================================= + +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) ); + return addElement( Poly_Element(anIndex, 0) ); +} + +//======================================================================= +//function : AddElement +//purpose : +//======================================================================= + +Standard_Integer Poly_Mesh::AddElement (const Standard_Integer theN1, + const Standard_Integer theN2, + 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) ); + return addElement( Poly_Element(anIndex1, anIndex2) ); +} + +//======================================================================= +//function : Element +//purpose : +//======================================================================= + +const Poly_Element& Poly_Mesh::Element (const Standard_Integer theIndex) const +{ + if ( theIndex < 1 || theIndex > myElements.Size() ) + { + Standard_OutOfRange::Raise("Poly_Mesh::Element : index out of range"); + } + + return myElements.Value(theIndex - 1); +} + +//======================================================================= +//function : Element +//purpose : +//======================================================================= + +void Poly_Mesh::Element (const Standard_Integer theIndex, + Standard_Integer& theN1, + Standard_Integer& theN2, + 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); + + // Get node indices for the first triangle + const Poly_Triangle& aTri1 = Poly_Triangulation::Triangle(aTriIdx1); + aTri1.Get(theN1, theN2, theN3); + + // If the second triangle exists, take its node indices for quad + if ( aTriIdx2 ) + { + const Poly_Triangle& aTri2 = Poly_Triangulation::Triangle(aTriIdx2); + aTri2.Get(theN1, theN3, theN4); + } + else + theN4 = 0; +} + +//======================================================================= +//function : SetElement +//purpose : +//======================================================================= + +void Poly_Mesh::SetElement (const Standard_Integer theIndex, const Poly_Element& theElement) +{ + 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 ) + { + myNbQuads++; + } + else if ( myElements.Value(theIndex - 1).Value(2) != 0 && theElement.Value(2) == 0 ) + { + myNbQuads--; + } + + myElements.SetValue(theIndex - 1, theElement); +} + +//======================================================================= +//function : addElement +//purpose : +//======================================================================= + +Standard_Integer Poly_Mesh::addElement(const Poly_Element& theElement) +{ + myElements.Append(theElement); + if ( theElement.Value(2) != 0 ) + { + myNbQuads++; + } + return myElements.Size(); +} diff --git a/src/Poly/Poly_Mesh.hxx b/src/Poly/Poly_Mesh.hxx new file mode 100644 index 0000000000..061967995d --- /dev/null +++ b/src/Poly/Poly_Mesh.hxx @@ -0,0 +1,104 @@ +// 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 _Poly_Mesh_HeaderFile +#define _Poly_Mesh_HeaderFile + +#include +#include + +//! This class is extension for Poly_Triangulation. +//! It allows to store mesh with quad polygons as table of Poly_Element. +//! Keep in mind that when you add a triangle, it is also added to the table of elements +//! as Poly_Element. And it will have first index set to triangle index from Poly_Triangulation +//! and second index will be set to 0. +class Poly_Mesh : public Poly_Triangulation +{ + +public: + + //! Constructs an empty mesh. + //! @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); + + //! Creates full copy of current mesh + Standard_EXPORT virtual Handle(Poly_Triangulation) Copy() const; + + //! Adds element to the mesh. + //! @param theN1 index of the first node. + //! @param theN2 index of the second node. + //! @param theN3 index of the third node. + //! @return index of the added element. + Standard_EXPORT Standard_Integer AddElement (const Standard_Integer theN1, + const Standard_Integer theN2, + const Standard_Integer theN3); + + //! Adds element to the mesh. + //! @param theN1 index of the first node. + //! @param theN2 index of the second node. + //! @param theN3 index of the third node. + //! @param theN4 index of the fourth node. + //! @return index of the added element. + Standard_EXPORT Standard_Integer AddElement (const Standard_Integer theN1, + const Standard_Integer theN2, + const Standard_Integer theN3, + const Standard_Integer theN4); + + //! @return the number of elements for this mesh. + Standard_Integer NbElements() const { return myElements.Size(); } + + //! @return the number of quads for this mesh. + Standard_Integer NbQuads() const { return myNbQuads; } + + //! @return element at the given index. + //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbElements. + Standard_EXPORT const Poly_Element& Element (const Standard_Integer theIndex) const; + + //! @return nodes of the element at the given index. + //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbElements. + Standard_EXPORT void Element (const Standard_Integer theIndex, + Standard_Integer& theN1, + Standard_Integer& theN2, + Standard_Integer& theN3, + Standard_Integer& theN4) const; + + //! Sets the element at the given index. + //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbElements. + Standard_EXPORT void SetElement (const Standard_Integer theIndex, const Poly_Element& theElement); + +protected: + + //! Adds element to the mesh. + //! @param theElement element to add. + //! @return index of the added element. + Standard_EXPORT Standard_Integer addElement (const Poly_Element& theElement); + +private: + + NCollection_Vector myElements; + Standard_Integer myNbQuads; + +public: + + DEFINE_STANDARD_RTTIEXT(Poly_Mesh, Poly_Triangulation) + +}; + +DEFINE_STANDARD_HANDLE(Poly_Mesh, Poly_Triangulation) + +#endif // _Poly_Mesh_HeaderFile diff --git a/src/Poly/Poly_PolygonOnTriangulation.cxx b/src/Poly/Poly_PolygonOnTriangulation.cxx index fa26b4365c..acaedbda80 100644 --- a/src/Poly/Poly_PolygonOnTriangulation.cxx +++ b/src/Poly/Poly_PolygonOnTriangulation.cxx @@ -95,6 +95,29 @@ const TColStd_Array1OfInteger& Poly_PolygonOnTriangulation::Nodes() const return myNodes; } +//======================================================================= +//function : Node +//purpose : +//======================================================================= + +Standard_Integer Poly_PolygonOnTriangulation::Node (const Standard_Integer theIndex) const +{ + Standard_OutOfRange_Raise_if ((theIndex < 1 || theIndex > myNodes.Length()), + "Poly_PolygonOnTriangulation::Node : index out of range"); + return myNodes.Value (theIndex); +} + +//======================================================================= +//function : SetNode +//purpose : +//======================================================================= + +void Poly_PolygonOnTriangulation::SetNode (const Standard_Integer theIndex, const Standard_Integer theNode) +{ + Standard_OutOfRange_Raise_if ((theIndex < 1 || theIndex > myNodes.Length()), + "Poly_PolygonOnTriangulation::SetNode : index out of range"); + myNodes.SetValue (theIndex, theNode); +} //======================================================================= //function : HasParameters @@ -116,3 +139,30 @@ Handle(TColStd_HArray1OfReal) Poly_PolygonOnTriangulation::Parameters() const return myParameters; } +//======================================================================= +//function : Parameter +//purpose : +//======================================================================= + +Standard_Real Poly_PolygonOnTriangulation::Parameter (const Standard_Integer theIndex) const +{ + Standard_NullObject_Raise_if (myParameters.IsNull(), + "Poly_PolygonOnTriangulation::Parameter : parameters is NULL"); + Standard_OutOfRange_Raise_if ((theIndex < 1 || theIndex > myParameters->Length()), + "Poly_PolygonOnTriangulation::Parameter : index out of range"); + return myParameters->Value (theIndex); +} + +//======================================================================= +//function : SetParameter +//purpose : +//======================================================================= + +void Poly_PolygonOnTriangulation::SetParameter (const Standard_Integer theIndex, const Standard_Real theValue) +{ + Standard_NullObject_Raise_if (myParameters.IsNull(), + "Poly_PolygonOnTriangulation::Parameter : parameters is NULL"); + Standard_OutOfRange_Raise_if ((theIndex < 1 || theIndex > myParameters->Length()), + "Poly_PolygonOnTriangulation::Parameter : index out of range"); + myParameters->SetValue (theIndex, theValue); +} diff --git a/src/Poly/Poly_PolygonOnTriangulation.hxx b/src/Poly/Poly_PolygonOnTriangulation.hxx index 87f99227fd..edd6cac2e0 100644 --- a/src/Poly/Poly_PolygonOnTriangulation.hxx +++ b/src/Poly/Poly_PolygonOnTriangulation.hxx @@ -90,7 +90,14 @@ public: //! is an index in the table of nodes specific to an existing //! triangulation of a shape. Standard_EXPORT const TColStd_Array1OfInteger& Nodes() const; - + + //! Return node at the given index. + //! Raises exception if theIndex is less than NodesLowerIndex or bigger than NodesUpperIndex. + Standard_EXPORT Standard_Integer Node(const Standard_Integer theIndex) const; + + //! Sets node at the given index. + //! Raises exception if theIndex is less than NodesLowerIndex or bigger than NodesUpperIndex. + Standard_EXPORT void SetNode(const Standard_Integer theIndex, const Standard_Integer theNode); //! Returns true if parameters are associated with the nodes in this polygon. Standard_EXPORT Standard_Boolean HasParameters() const; @@ -101,7 +108,15 @@ public: //! are associated with the nodes in this polygon. Standard_EXPORT Handle(TColStd_HArray1OfReal) Parameters() const; + //! Return parameter at the given index. + //! Raises Standard_NullObject exception if parameters has not been initialized. + //! Raises Standard_OutOfRange exception if theIndex is less than ParametersLowerIndex or bigger than ParametersUpperIndex. + Standard_EXPORT Standard_Real Parameter(const Standard_Integer theIndex) const; + //! Sets parameter at the given index. + //! Raises Standard_NullObject exception if parameters has not been initialized. + //! Raises Standard_OutOfRange exception if theIndex is less than ParametersLowerIndex or bigger than ParametersUpperIndex. + Standard_EXPORT void SetParameter(const Standard_Integer theIndex, const Standard_Real theValue); DEFINE_STANDARD_RTTIEXT(Poly_PolygonOnTriangulation,MMgt_TShared) diff --git a/src/Poly/Poly_Triangulation.cxx b/src/Poly/Poly_Triangulation.cxx index 5bd7944cdf..2475ac2bd6 100644 --- a/src/Poly/Poly_Triangulation.cxx +++ b/src/Poly/Poly_Triangulation.cxx @@ -14,30 +14,37 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. +#include #include -#include -#include -#include #include -#include +#include -IMPLEMENT_STANDARD_RTTIEXT(Poly_Triangulation,MMgt_TShared) +IMPLEMENT_STANDARD_RTTIEXT (Poly_Triangulation, MMgt_TShared) //======================================================================= //function : Poly_Triangulation //purpose : //======================================================================= -Poly_Triangulation::Poly_Triangulation(const Standard_Integer NbNodes, - const Standard_Integer NbTriangles, - const Standard_Boolean UVNodes) : - myDeflection(0), - myNbNodes(NbNodes), - myNbTriangles(NbTriangles), - myNodes(1, NbNodes), - myTriangles(1, NbTriangles) + +Poly_Triangulation::Poly_Triangulation (const Standard_Integer theNbNodes, + const Standard_Integer theNbTriangles, + const Standard_Boolean theHasUVNodes) +: myHasUVNodes (theHasUVNodes), + myDeflection (0) { - if (UVNodes) myUVNodes = new TColgp_HArray1OfPnt2d(1, myNbNodes); + if (theNbNodes > 0) + { + myNodes.SetValue (theNbNodes - 1, gp_Pnt()); + if (myHasUVNodes) + { + myUVNodes.SetValue (theNbNodes - 1, gp_Pnt2d()); + } + } + if (theNbTriangles > 0) + { + myTriangles.SetValue (theNbTriangles - 1, Poly_Triangle()); + } } //======================================================================= @@ -45,16 +52,19 @@ Poly_Triangulation::Poly_Triangulation(const Standard_Integer NbNodes, //purpose : //======================================================================= -Poly_Triangulation::Poly_Triangulation(const TColgp_Array1OfPnt& Nodes, - const Poly_Array1OfTriangle& Triangles) : - myDeflection(0), - myNbNodes(Nodes.Length()), - myNbTriangles(Triangles.Length()), - myNodes(1, Nodes.Length()), - myTriangles(1, Triangles.Length()) +Poly_Triangulation::Poly_Triangulation (const TColgp_Array1OfPnt& theNodes, + const Poly_Array1OfTriangle& theTriangles) +: myHasUVNodes (Standard_False), + myDeflection (0) { - myNodes = Nodes; - myTriangles = Triangles; + for (Standard_Integer anIndex = theNodes.Upper(); anIndex >= theNodes.Lower(); anIndex--) + { + myNodes.SetValue (anIndex - 1, theNodes (anIndex)); + } + for (Standard_Integer anIndex = theTriangles.Upper(); anIndex >= theTriangles.Lower(); anIndex--) + { + myTriangles.SetValue (anIndex - 1, theTriangles (anIndex)); + } } @@ -64,19 +74,27 @@ Poly_Triangulation::Poly_Triangulation(const TColgp_Array1OfPnt& Nodes, //purpose : //======================================================================= -Poly_Triangulation::Poly_Triangulation(const TColgp_Array1OfPnt& Nodes, - const TColgp_Array1OfPnt2d& UVNodes, - const Poly_Array1OfTriangle& Triangles) : - myDeflection(0), - myNbNodes(Nodes.Length()), - myNbTriangles(Triangles.Length()), - myNodes(1, Nodes.Length()), - myTriangles(1, Triangles.Length()) +Poly_Triangulation::Poly_Triangulation (const TColgp_Array1OfPnt& theNodes, + const TColgp_Array1OfPnt2d& theUVNodes, + const Poly_Array1OfTriangle& theTriangles) +: myHasUVNodes (theNodes.Length() == theUVNodes.Length()), + myDeflection (0) { - myNodes = Nodes; - myTriangles = Triangles; - myUVNodes = new TColgp_HArray1OfPnt2d(1, myNbNodes); - myUVNodes->ChangeArray1() = UVNodes; + for (Standard_Integer anIndex = theNodes.Upper(); anIndex >= theNodes.Lower(); anIndex--) + { + myNodes.SetValue (anIndex - 1, theNodes (anIndex)); + } + if (myHasUVNodes) + { + for (Standard_Integer anIndex = theUVNodes.Upper(); anIndex >= theUVNodes.Lower(); anIndex--) + { + myUVNodes.SetValue (anIndex - 1, theUVNodes (anIndex)); + } + } + for (Standard_Integer anIndex = theTriangles.Upper(); anIndex >= theTriangles.Lower(); anIndex--) + { + myTriangles.SetValue (anIndex - 1, theTriangles (anIndex)); + } } //======================================================================= @@ -86,24 +104,39 @@ Poly_Triangulation::Poly_Triangulation(const TColgp_Array1OfPnt& Nodes, Handle(Poly_Triangulation) Poly_Triangulation::Copy() const { - Handle(Poly_Triangulation) aCopy; - if (HasUVNodes()) - aCopy = new Poly_Triangulation(Nodes(), UVNodes(), Triangles()); - else - aCopy = new Poly_Triangulation(Nodes(), Triangles()); - aCopy->Deflection(myDeflection); - if (HasNormals()) - aCopy->myNormals = new TShort_HArray1OfShortReal(myNormals->Array1()); - + Handle(Poly_Triangulation) aCopy = new Poly_Triangulation(NbNodes(), NbTriangles(), HasUVNodes()); + aCopy->myNodes = myNodes; + aCopy->myTriangles = myTriangles; + aCopy->myUVNodes = myUVNodes; + aCopy->myDeflection = myDeflection; + aCopy->myNormals = myNormals; return aCopy; } +//======================================================================= +//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 : //======================================================================= -Standard_Real Poly_Triangulation::Deflection() const +Standard_Real Poly_Triangulation::Deflection() const { return myDeflection; } @@ -113,9 +146,9 @@ 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; } @@ -127,119 +160,164 @@ void Poly_Triangulation::Deflection(const Standard_Real D) void Poly_Triangulation::RemoveUVNodes() { - myUVNodes.Nullify(); + myUVNodes.Clear(); + myHasUVNodes = Standard_False; } //======================================================================= -//function : Nodes +//function : AddNode //purpose : //======================================================================= - -const TColgp_Array1OfPnt& Poly_Triangulation::Nodes() const +Standard_Integer Poly_Triangulation::AddNode (const gp_Pnt& theNode) { - return myNodes; + myNodes.Append (theNode); + + if (myHasUVNodes) + { + myUVNodes.Append (gp_Pnt2d()); + } + + if (!myNormals.IsEmpty()) + { + Standard_Integer aNbNormals = myNodes.Size(); + myNormals.SetValue (aNbNormals, gp_Dir()); + } + + return myNodes.Size(); } //======================================================================= -//function : ChangeNodes +//function : Node //purpose : //======================================================================= -TColgp_Array1OfPnt& Poly_Triangulation::ChangeNodes() +const gp_Pnt& Poly_Triangulation::Node (const Standard_Integer theIndex) const { - return myNodes; + if (theIndex < 1 || theIndex > myNodes.Size()) + { + Standard_OutOfRange::Raise ("Poly_Triangulation::Node : index out of range"); + } + return myNodes.Value (theIndex - 1); } //======================================================================= -//function : UVNodes +//function : ChangeNode //purpose : //======================================================================= -const TColgp_Array1OfPnt2d& Poly_Triangulation::UVNodes() const +gp_Pnt& Poly_Triangulation::ChangeNode (const Standard_Integer theIndex) { - return myUVNodes->Array1(); + if (theIndex < 1 || theIndex > myNodes.Size()) + { + Standard_OutOfRange::Raise ("Poly_Triangulation::ChangeNode : index out of range"); + } + return myNodes.ChangeValue (theIndex - 1); } //======================================================================= -//function : ChangeUVNodes +//function : UVNode //purpose : //======================================================================= -TColgp_Array1OfPnt2d& Poly_Triangulation::ChangeUVNodes() +const gp_Pnt2d& Poly_Triangulation::UVNode (const Standard_Integer theIndex) const { - return myUVNodes->ChangeArray1(); + if (myUVNodes.IsEmpty() || theIndex < 1 || theIndex > myUVNodes.Size()) + { + Standard_OutOfRange::Raise ("Poly_Triangulation::UVNode : index out of range"); + } + return myUVNodes.Value (theIndex - 1); } //======================================================================= -//function : Triangles +//function : ChangeUVNode //purpose : //======================================================================= -const Poly_Array1OfTriangle& Poly_Triangulation::Triangles() const +gp_Pnt2d& Poly_Triangulation::ChangeUVNode (const Standard_Integer theIndex) { - return myTriangles; + if (myUVNodes.IsEmpty() || theIndex < 1 || theIndex > myUVNodes.Size()) + { + Standard_OutOfRange::Raise ("Poly_Triangulation::ChangeUVNode : index out of range"); + } + return myUVNodes.ChangeValue (theIndex - 1); } //======================================================================= -//function : ChangeTriangles +//function : Triangle //purpose : //======================================================================= -Poly_Array1OfTriangle& Poly_Triangulation::ChangeTriangles() +Standard_Integer Poly_Triangulation::AddTriangle (const Poly_Triangle& theTriangle) { - return myTriangles; + myTriangles.Append (theTriangle); + return myTriangles.Size(); } - //======================================================================= -//function : SetNormals +//function : Triangle //purpose : //======================================================================= -void Poly_Triangulation::SetNormals - (const Handle(TShort_HArray1OfShortReal)& theNormals) +const Poly_Triangle& Poly_Triangulation::Triangle (const Standard_Integer theIndex) const { - - if(theNormals.IsNull() || theNormals->Length() != 3*myNbNodes) { - Standard_DomainError::Raise("Poly_Triangulation::SetNormals : wrong length"); + if (theIndex < 1 || theIndex > myTriangles.Size()) + { + Standard_OutOfRange::Raise ("Poly_Triangulation::Triangle : index out of range"); } + return myTriangles.Value (theIndex - 1); +} - myNormals = theNormals; +//======================================================================= +//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 - 1); } //======================================================================= -//function : Normals +//function : SetNormals //purpose : //======================================================================= -const TShort_Array1OfShortReal& Poly_Triangulation::Normals() const +void Poly_Triangulation::SetNormals (const Handle(TShort_HArray1OfShortReal)& theNormals) { - - if(myNormals.IsNull() || myNormals->Length() != 3*myNbNodes) { - Standard_NullObject::Raise("Poly_Triangulation::Normals : " - "wrong length or null array"); + if (theNormals.IsNull() || theNormals->Length() != 3 * NbNodes()) + { + Standard_DomainError::Raise("Poly_Triangulation::SetNormals : wrong length"); } - return myNormals->Array1(); - + Standard_Integer anArrayLower = theNormals->Lower(); + Standard_Integer anArrayInd; + for (Standard_Integer anIndex = NbNodes() - 1; anIndex >= 0; anIndex--) + { + anArrayInd = anArrayLower + anIndex * 3; + gp_Dir aNormal(theNormals->Value(anArrayInd), + theNormals->Value(anArrayInd), + theNormals->Value(anArrayInd)); + myNormals.SetValue (anIndex, aNormal); + } } //======================================================================= -//function : ChangeNormals +//function : SetNormal //purpose : //======================================================================= -TShort_Array1OfShortReal& Poly_Triangulation::ChangeNormals() +void Poly_Triangulation::SetNormal (const Standard_Integer theIndex, const gp_Dir& theNormal) { - - if(myNormals.IsNull() || myNormals->Length() != 3*myNbNodes) { - Standard_NullObject::Raise("Poly_Triangulation::ChangeNormals : " - "wrong length or null array"); + if (myNormals.IsEmpty() || theIndex < 1 || theIndex > myNodes.Size()) + { + Standard_NullObject::Raise("Poly_Triangulation::SetNormal : empty array or index out of range"); } - return myNormals->ChangeArray1(); - + myNormals.ChangeValue (theIndex - 1) = theNormal; } //======================================================================= @@ -249,12 +327,24 @@ TShort_Array1OfShortReal& Poly_Triangulation::ChangeNormals() Standard_Boolean Poly_Triangulation::HasNormals() const { - - if(myNormals.IsNull() || myNormals->Length() != 3*myNbNodes) { + if (myNormals.IsEmpty() || myNormals.Length() != NbNodes()) + { return Standard_False; } return Standard_True; } +//======================================================================= +//function : Normal +//purpose : +//======================================================================= +const gp_Dir Poly_Triangulation::Normal (const Standard_Integer theIndex) const +{ + if (myNormals.IsEmpty() || theIndex < 1 || theIndex > myNodes.Size()) + { + Standard_NullObject::Raise("Poly_Triangulation::Normal : empty array or index out of range"); + } + return myNormals (theIndex - 1); +} diff --git a/src/Poly/Poly_Triangulation.hxx b/src/Poly/Poly_Triangulation.hxx index b4857d28ec..febb46ec02 100644 --- a/src/Poly/Poly_Triangulation.hxx +++ b/src/Poly/Poly_Triangulation.hxx @@ -1,7 +1,4 @@ -// Created on: 1995-03-06 -// Created by: Laurent PAINNOT -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS +// Copyright (c) 2015 OPEN CASCADE SAS // // This file is part of Open CASCADE Technology software library. // @@ -17,178 +14,153 @@ #ifndef _Poly_Triangulation_HeaderFile #define _Poly_Triangulation_HeaderFile +#include #include -#include - +#include #include #include #include -#include -#include -#include +#include #include #include -#include -#include +#include +#include + +class TShort_HArray1OfShortReal; class Standard_DomainError; class Standard_NullObject; - -class Poly_Triangulation; -DEFINE_STANDARD_HANDLE(Poly_Triangulation, MMgt_TShared) - -//! Provides a triangulation for a surface, a set of surfaces, or -//! more generally a shape. -//! A triangulation consists of an approximate representation -//! of the actual shape, using a collection of points and -//! triangles. The points are located on the surface. The -//! edges of the triangles connect adjacent points with a +//! Provides a triangulation for a surface, a set of surfaces, or more generally a shape. +//! A triangulation consists of an approximate representation of the actual shape, using a collection of points and triangles. +//! The points are located on the surface. The edges of the triangles connect adjacent points with a //! straight line that approximates the true curve on the surface. //! A triangulation comprises: //! - A table of 3D nodes (3D points on the surface). -//! - A table of triangles. Each triangle (Poly_Triangle -//! object) comprises a triplet of indices in the table of 3D -//! nodes specific to the triangulation. -//! - A table of 2D nodes (2D points), parallel to the table of -//! 3D nodes. This table is optional. If it exists, the -//! coordinates of a 2D point are the (u, v) parameters -//! of the corresponding 3D point on the surface -//! approximated by the triangulation. -//! - A deflection (optional), which maximizes the distance -//! from a point on the surface to the corresponding point -//! on its approximate triangulation. -//! In many cases, algorithms do not need to work with the -//! exact representation of a surface. A triangular -//! representation induces simpler and more robust adjusting, -//! faster performances, and the results are as good. -//! This is a Transient class. +//! - A table of triangles. Each triangle (Poly_Triangle object) comprises a triplet of indices in the table of 3D +//! nodes specific to the triangulation. +//! - A table of 2D nodes (2D points), parallel to the table of 3D nodes. This table is optional. +//! If it exists, the coordinates of a 2D point are the (u, v) parameters of the corresponding 3D point on the surface approximated by the triangulation. +//! - A deflection (optional), which maximizes the distance from a point on the surface to the corresponding point on its approximate triangulation. +//! In many cases, algorithms do not need to work with the exact representation of a surface. +//! A triangular representation induces simpler and more robust adjusting, faster performances, and the results are as good. class Poly_Triangulation : public MMgt_TShared { public: - - //! 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 - //! triangles. Here the UVNodes flag indicates whether - //! 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 - //! coordinates of a 2D point from UVNodes are the - //! (u, v) parameters of the corresponding 3D point - //! 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); - + //! Constructs a triangulation from a set of triangles. + //! The triangulation is initialized without a triangle or a node, but capable of containing theNbNodes nodes, and theNbTriangles triangles. + //! Here theHasUVNodes flag indicates whether 2D nodes will be associated with 3D ones, (i.e. to enable a 2D representation). + Standard_EXPORT Poly_Triangulation (const Standard_Integer theNbNodes, + const Standard_Integer theNbTriangles, + const Standard_Boolean theHasUVNodes); + + //! 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& theNodes, + const Poly_Array1OfTriangle& theTriangles); + + //! Constructs a triangulation from a set of triangles. + //! The triangulation is initialized with 3D points from Nodes, 2D points from theUVNodes and triangles from theTriangles, + //! where coordinates of a 2D point from theUVNodes are the (u, v) parameters of the corresponding 3D point + //! from theNodes on the surface approximated by the constructed triangulation. If size of theUVNodes != size of theNodes + //! then triangulation will be created without theUVNodes. + Standard_EXPORT Poly_Triangulation (const TColgp_Array1OfPnt& theNodes, + const TColgp_Array1OfPnt2d& theUVNodes, + const Poly_Array1OfTriangle& theTriangles); + //! 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; - - //! 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; - - //! 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 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. - //! 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_Array1OfPnt2d& ChangeUVNodes(); - - //! 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(); - - //! Sets the table of node normals. - //! raises exception if length of theNormals != 3*NbNodes - Standard_EXPORT void SetNormals (const Handle(TShort_HArray1OfShortReal)& theNormals); - - Standard_EXPORT const TShort_Array1OfShortReal& Normals() const; - - Standard_EXPORT TShort_Array1OfShortReal& ChangeNormals(); - - Standard_EXPORT Standard_Boolean HasNormals() const; + //! @return the number of nodes for this triangulation. + Standard_Integer NbNodes() const { return myNodes.Size(); } + //! @return the number of triangles for this triangulation. + Standard_Integer NbTriangles() const { return myTriangles.Size(); } + //! @return Standard_True if 2D nodes are associated with 3D nodes for this triangulation. + Standard_Boolean HasUVNodes() const { return myHasUVNodes; } - DEFINE_STANDARD_RTTIEXT(Poly_Triangulation,MMgt_TShared) + //! Adds Node to the triangulation. If triangulation has UVNodes or Normals + //! they will be expanded and set to zero values to match the new number of nodes. + //! @return index of the added Node. + Standard_EXPORT Standard_Integer AddNode (const gp_Pnt& theNode); -protected: + //! @return 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); + //! @return 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); -private: + //! Adds triangle to the triangulation. + //! @return index of the added triangle. + Standard_EXPORT virtual Standard_Integer AddTriangle (const Poly_Triangle& theTriangle); + //! @return 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; - Standard_Real myDeflection; - Standard_Integer myNbNodes; - Standard_Integer myNbTriangles; - TColgp_Array1OfPnt myNodes; - Handle(TColgp_HArray1OfPnt2d) myUVNodes; - Poly_Array1OfTriangle myTriangles; - Handle(TShort_HArray1OfShortReal) myNormals; + //! 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_DEPRECATED("Deprecated method SetNormals() should be replaced \ + by method with array as object instead of handle. \ + Array of floats should be replaced by vector of normals") + Standard_EXPORT void SetNormals (const Handle(TShort_HArray1OfShortReal)& theNormals); -}; + //! Changes normal at the given index. + //! Raises Standard_OutOfRange exception. + Standard_EXPORT void SetNormal (const Standard_Integer theIndex, + const gp_Dir& theNormal); + //! 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; -#include +protected: + Standard_Boolean myHasUVNodes; + Standard_Real myDeflection; + NCollection_Vector myNodes; + NCollection_Vector myUVNodes; + NCollection_Vector myTriangles; + NCollection_Vector myNormals; +public: + DEFINE_STANDARD_RTTIEXT(Poly_Triangulation, MMgt_TShared) +}; + +DEFINE_STANDARD_HANDLE(Poly_Triangulation, MMgt_TShared) #endif // _Poly_Triangulation_HeaderFile diff --git a/src/Poly/Poly_Triangulation.lxx b/src/Poly/Poly_Triangulation.lxx deleted file mode 100644 index 63809e9660..0000000000 --- a/src/Poly/Poly_Triangulation.lxx +++ /dev/null @@ -1,46 +0,0 @@ -// Created on: 1995-03-06 -// Created by: Laurent PAINNOT -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 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. - -//======================================================================= -//function : NbNodes -//purpose : -//======================================================================= - -inline Standard_Integer Poly_Triangulation::NbNodes() const -{ - return myNbNodes; -} - -//======================================================================= -//function : NbTriangles -//purpose : -//======================================================================= - -inline Standard_Integer Poly_Triangulation::NbTriangles() const -{ - return myNbTriangles; -} - -//======================================================================= -//function : HasUVNodes -//purpose : -//======================================================================= - -inline Standard_Boolean Poly_Triangulation::HasUVNodes() const -{ - return !myUVNodes.IsNull(); -} - diff --git a/src/QABugs/QABugs_19.cxx b/src/QABugs/QABugs_19.cxx index 13bbade078..9a0f33df4e 100644 --- a/src/QABugs/QABugs_19.cxx +++ b/src/QABugs/QABugs_19.cxx @@ -3948,25 +3948,15 @@ static Standard_Integer OCC26485 (Draw_Interpretor& theDI, Standard_Integer theA continue; Poly::ComputeNormals(aT); - const TColgp_Array1OfPnt& aVertices = aT->Nodes(); - const TShort_Array1OfShortReal& aNormals = aT->Normals(); // Number of nodes in the triangulation - int aVertexNb = aT->Nodes().Length(); - if (aVertexNb*3 != aNormals.Length()) - { - theDI << "Failed. Different number of normals vs. vertices\n"; - return 1; - } + int aVertexNb = aT->NbNodes(); // Get each vertex index, checking common vertexes between shapes for( int i=0; i < aVertexNb; i++ ) { - gp_Pnt aPoint = aVertices.Value( i+1 ); - gp_Vec aNormal = gp_Vec( - aNormals.Value( i*3 + 1 ), - aNormals.Value( i*3 + 2 ), - aNormals.Value( i*3 + 3 ) ); + gp_Pnt aPoint = aT->Node( i+1 ); + gp_Dir aNormal = aT->Normal( i+1 ); if (aNormal.X() == 0 && aNormal.Y() == 0 && aNormal.Z() == 1) { diff --git a/src/Select3D/Select3D_SensitiveTriangulation.cxx b/src/Select3D/Select3D_SensitiveTriangulation.cxx index 88543d5ecd..f0511d95c5 100644 --- a/src/Select3D/Select3D_SensitiveTriangulation.cxx +++ b/src/Select3D/Select3D_SensitiveTriangulation.cxx @@ -57,8 +57,6 @@ Select3D_SensitiveTriangulation::Select3D_SensitiveTriangulation (const Handle(S { myInvInitLocation = myInitLocation.Transformation().Inverted(); mySensType = theIsInterior ? Select3D_TOS_INTERIOR : Select3D_TOS_BOUNDARY; - const Poly_Array1OfTriangle& aTriangles = myTriangul->Triangles(); - const TColgp_Array1OfPnt& aNodes = myTriangul->Nodes(); Standard_Integer aNbTriangles (myTriangul->NbTriangles()); gp_XYZ aCenter (0.0, 0.0, 0.0); @@ -77,8 +75,8 @@ Select3D_SensitiveTriangulation::Select3D_SensitiveTriangulation (const Handle(S for (Standard_Integer aTriangleIdx = 1; aTriangleIdx <= aNbTriangles; aTriangleIdx++) { aPoly.Triangles (aTriangleIdx, aTriangle[0], aTriangle[1], aTriangle[2]); - aTriangles (aTriangleIdx).Get (aTrNodeIdx[0], aTrNodeIdx[1], aTrNodeIdx[2]); - aCenter += (aNodes (aTrNodeIdx[0]).XYZ() + aNodes (aTrNodeIdx[1]).XYZ()+ aNodes (aTrNodeIdx[2]).XYZ()) / 3.0; + myTriangul->Triangle (aTriangleIdx).Get (aTrNodeIdx[0], aTrNodeIdx[1], aTrNodeIdx[2]); + aCenter += (myTriangul->Node (aTrNodeIdx[0]).XYZ() + myTriangul->Node (aTrNodeIdx[1]).XYZ()+ myTriangul->Node (aTrNodeIdx[2]).XYZ()) / 3.0; for (Standard_Integer aVertIdx = 0; aVertIdx < 3; aVertIdx++) { Standard_Integer aNextVert = (aVertIdx + 1) % 3; @@ -96,8 +94,8 @@ Select3D_SensitiveTriangulation::Select3D_SensitiveTriangulation (const Handle(S Standard_Integer aTrNodeIdx[3]; for (Standard_Integer aTrIdx = 1; aTrIdx <= aNbTriangles; aTrIdx++) { - aTriangles (aTrIdx).Get (aTrNodeIdx[0], aTrNodeIdx[1], aTrNodeIdx[2]); - aCenter += (aNodes (aTrNodeIdx[0]).XYZ() + aNodes (aTrNodeIdx[1]).XYZ()+ aNodes (aTrNodeIdx[2]).XYZ()) / 3.0; + myTriangul->Triangle (aTrIdx).Get (aTrNodeIdx[0], aTrNodeIdx[1], aTrNodeIdx[2]); + aCenter += (myTriangul->Node (aTrNodeIdx[0]).XYZ() + myTriangul->Node (aTrNodeIdx[1]).XYZ()+ myTriangul->Node (aTrNodeIdx[2]).XYZ()) / 3.0; } } if (aNbTriangles != 0) @@ -107,9 +105,9 @@ Select3D_SensitiveTriangulation::Select3D_SensitiveTriangulation (const Handle(S myBndBox.Clear(); for (Standard_Integer aNodeIdx = 1; aNodeIdx <= myTriangul->NbNodes(); ++aNodeIdx) { - myBndBox.Add (SelectMgr_Vec3 (aNodes (aNodeIdx).X(), - aNodes (aNodeIdx).Y(), - aNodes (aNodeIdx).Z())); + myBndBox.Add (SelectMgr_Vec3 (myTriangul->Node (aNodeIdx).X(), + myTriangul->Node (aNodeIdx).Y(), + myTriangul->Node (aNodeIdx).Z())); } if (theIsInterior) @@ -149,7 +147,7 @@ Select3D_SensitiveTriangulation::Select3D_SensitiveTriangulation (const Handle(S { myInvInitLocation = myInitLocation.Transformation().Inverted(); mySensType = theIsInterior ? Select3D_TOS_INTERIOR : Select3D_TOS_BOUNDARY; - myPrimitivesNb = theIsInterior ? theTrg->Triangles().Length() : theFreeEdges->Length() / 2; + myPrimitivesNb = theIsInterior ? theTrg->NbTriangles() : theFreeEdges->Length() / 2; myBVHPrimIndexes = new TColStd_HArray1OfInteger(0, myPrimitivesNb - 1); if (theIsInterior) { @@ -191,11 +189,11 @@ Select3D_BndBox3d Select3D_SensitiveTriangulation::Box (const Standard_Integer t if (mySensType == Select3D_TOS_INTERIOR) { Standard_Integer aNode1, aNode2, aNode3; - myTriangul->Triangles() (aPrimIdx + 1).Get (aNode1, aNode2, aNode3); + myTriangul->Triangle (aPrimIdx + 1).Get (aNode1, aNode2, aNode3); - gp_Pnt aPnt1 = myTriangul->Nodes().Value (aNode1); - gp_Pnt aPnt2 = myTriangul->Nodes().Value (aNode2); - gp_Pnt aPnt3 = myTriangul->Nodes().Value (aNode3); + gp_Pnt aPnt1 = myTriangul->Node(aNode1); + gp_Pnt aPnt2 = myTriangul->Node(aNode2); + gp_Pnt aPnt3 = myTriangul->Node(aNode3); aMinPnt = SelectMgr_Vec3 (Min (aPnt1.X(), Min (aPnt2.X(), aPnt3.X())), Min (aPnt1.Y(), Min (aPnt2.Y(), aPnt3.Y())), @@ -208,8 +206,8 @@ Select3D_BndBox3d Select3D_SensitiveTriangulation::Box (const Standard_Integer t { Standard_Integer aNodeIdx1 = myFreeEdges->Value (myFreeEdges->Lower() + aPrimIdx); Standard_Integer aNodeIdx2 = myFreeEdges->Value (myFreeEdges->Lower() + aPrimIdx + 1); - gp_Pnt aNode1 = myTriangul->Nodes().Value (aNodeIdx1); - gp_Pnt aNode2 = myTriangul->Nodes().Value (aNodeIdx2); + gp_Pnt aNode1 = myTriangul->Node(aNodeIdx1); + gp_Pnt aNode2 = myTriangul->Node(aNodeIdx2); aMinPnt = SelectMgr_Vec3 (Min (aNode1.X(), aNode2.X()), Min (aNode1.Y(), aNode2.Y()), @@ -266,8 +264,8 @@ Standard_Boolean Select3D_SensitiveTriangulation::overlapsElement (SelectBasics_ Standard_Integer aSegmStartIdx = myFreeEdges->Value (aPrimitiveIdx * 2 + 1); Standard_Integer aSegmEndIdx = myFreeEdges->Value (aPrimitiveIdx * 2 + 2); Handle(TColgp_HArray1OfPnt) anEdgePnts = new TColgp_HArray1OfPnt (1, 2); - gp_Pnt aSegmStart = myTriangul->Nodes().Value (aSegmStartIdx); - gp_Pnt aSegmEnd = myTriangul->Nodes().Value (aSegmEndIdx); + gp_Pnt aSegmStart = myTriangul->Node(aSegmStartIdx); + gp_Pnt aSegmEnd = myTriangul->Node(aSegmEndIdx); anEdgePnts->SetValue (1, aSegmStart); anEdgePnts->SetValue (2, aSegmEnd); Standard_Boolean isMatched = theMgr.Overlaps (anEdgePnts, Select3D_TOS_BOUNDARY, theMatchDepth); @@ -276,12 +274,11 @@ Standard_Boolean Select3D_SensitiveTriangulation::overlapsElement (SelectBasics_ } else { - const Poly_Array1OfTriangle& aTriangles = myTriangul->Triangles(); Standard_Integer aNode1, aNode2, aNode3; - aTriangles (aPrimitiveIdx + 1).Get (aNode1, aNode2, aNode3); - gp_Pnt aPnt1 = myTriangul->Nodes().Value (aNode1); - gp_Pnt aPnt2 = myTriangul->Nodes().Value (aNode2); - gp_Pnt aPnt3 = myTriangul->Nodes().Value (aNode3); + myTriangul->Triangle(aPrimitiveIdx + 1).Get (aNode1, aNode2, aNode3); + gp_Pnt aPnt1 = myTriangul->Node(aNode1); + gp_Pnt aPnt2 = myTriangul->Node(aNode2); + gp_Pnt aPnt3 = myTriangul->Node(aNode3); return theMgr.Overlaps (aPnt1, aPnt2, aPnt3, Select3D_TOS_INTERIOR, theMatchDepth); } } @@ -297,8 +294,8 @@ Standard_Boolean Select3D_SensitiveTriangulation::elementIsInside (SelectBasics_ if (mySensType == Select3D_TOS_BOUNDARY) { - gp_Pnt aSegmPnt1 = myTriangul->Nodes().Value (myFreeEdges->Value (aPrimitiveIdx * 2 + 1)); - gp_Pnt aSegmPnt2 = myTriangul->Nodes().Value (myFreeEdges->Value (aPrimitiveIdx * 2 + 2)); + gp_Pnt aSegmPnt1 = myTriangul->Node(myFreeEdges->Value (aPrimitiveIdx * 2 + 1)); + gp_Pnt aSegmPnt2 = myTriangul->Node(myFreeEdges->Value (aPrimitiveIdx * 2 + 2)); return theMgr.Overlaps (aSegmPnt1) && theMgr.Overlaps (aSegmPnt2); } @@ -308,11 +305,11 @@ Standard_Boolean Select3D_SensitiveTriangulation::elementIsInside (SelectBasics_ Standard_Integer aNode2; Standard_Integer aNode3; - myTriangul->Triangles() (aPrimitiveIdx + 1).Get (aNode1, aNode2, aNode3); + myTriangul->Triangle(aPrimitiveIdx + 1).Get (aNode1, aNode2, aNode3); - gp_Pnt aPnt1 = myTriangul->Nodes().Value (aNode1); - gp_Pnt aPnt2 = myTriangul->Nodes().Value (aNode2); - gp_Pnt aPnt3 = myTriangul->Nodes().Value (aNode3); + gp_Pnt aPnt1 = myTriangul->Node(aNode1); + gp_Pnt aPnt2 = myTriangul->Node(aNode2); + gp_Pnt aPnt3 = myTriangul->Node(aNode3); return theMgr.Overlaps (aPnt1) && theMgr.Overlaps (aPnt2) @@ -382,12 +379,10 @@ Select3D_BndBox3d Select3D_SensitiveTriangulation::BoundingBox() if (myBndBox.IsValid()) return applyTransformation(); - const Standard_Integer aLower = myTriangul->Nodes().Lower(); - const Standard_Integer anUpper = myTriangul->Nodes().Upper(); Select3D_BndBox3d aBndBox; - for (Standard_Integer aNodeIdx = aLower; aNodeIdx <= anUpper; ++aNodeIdx) + for (Standard_Integer aNodeIdx = 1; aNodeIdx <= myTriangul->NbNodes(); ++aNodeIdx) { - const gp_Pnt& aNode = myTriangul->Nodes().Value (aNodeIdx); + const gp_Pnt& aNode = myTriangul->Node (aNodeIdx); const SelectMgr_Vec3 aNodeTransf = SelectMgr_Vec3 (aNode.X(), aNode.Y(), aNode.Z()); aBndBox.Add (aNodeTransf); } @@ -413,7 +408,7 @@ gp_Pnt Select3D_SensitiveTriangulation::CenterOfGeometry() const //======================================================================= Standard_Integer Select3D_SensitiveTriangulation::NbSubElements() { - return myTriangul->Nodes().Length(); + return myTriangul->NbNodes(); } //======================================================================= diff --git a/src/Select3D/Select3D_SensitiveTriangulation.hxx b/src/Select3D/Select3D_SensitiveTriangulation.hxx index 5f212cdd54..fb9e9cb062 100644 --- a/src/Select3D/Select3D_SensitiveTriangulation.hxx +++ b/src/Select3D/Select3D_SensitiveTriangulation.hxx @@ -25,6 +25,7 @@ #include #include +#include #include #include #include diff --git a/src/StdPrs/StdPrs_Isolines.cxx b/src/StdPrs/StdPrs_Isolines.cxx index 15e7a4b6e5..1f3abfef50 100644 --- a/src/StdPrs/StdPrs_Isolines.cxx +++ b/src/StdPrs/StdPrs_Isolines.cxx @@ -236,25 +236,21 @@ void StdPrs_Isolines::addOnTriangulation (const Handle(Poly_Triangulation)& theT SeqOfVecOfSegments aUPolylines, aVPolylines; - const Poly_Array1OfTriangle& aTriangles = theTriangulation->Triangles(); - const TColgp_Array1OfPnt& aNodes = theTriangulation->Nodes(); - const TColgp_Array1OfPnt2d& aUVNodes = theTriangulation->UVNodes(); - TColStd_Array1OfInteger aUIsoIndexes (1, aNbIsoU); TColStd_Array1OfInteger aVIsoIndexes (1, aNbIsoV); aUIsoIndexes.Init (-1); aVIsoIndexes.Init (-1); - for (Standard_Integer anI = aTriangles.Lower(); anI <= aTriangles.Upper(); ++anI) + for (Standard_Integer anI = 1; anI <= theTriangulation->NbTriangles(); ++anI) { Standard_Integer aNodeIdxs[3]; - aTriangles.Value (anI).Get (aNodeIdxs[0], aNodeIdxs[1],aNodeIdxs[2]); - const gp_Pnt aNodesXYZ[3] = { aNodes.Value (aNodeIdxs[0]), - aNodes.Value (aNodeIdxs[1]), - aNodes.Value (aNodeIdxs[2]) }; - const gp_Pnt2d aNodesUV[3] = { aUVNodes.Value (aNodeIdxs[0]), - aUVNodes.Value (aNodeIdxs[1]), - aUVNodes.Value (aNodeIdxs[2]) }; + theTriangulation->Triangle(anI).Get (aNodeIdxs[0], aNodeIdxs[1],aNodeIdxs[2]); + const gp_Pnt aNodesXYZ[3] = { theTriangulation->Node(aNodeIdxs[0]), + theTriangulation->Node(aNodeIdxs[1]), + theTriangulation->Node(aNodeIdxs[2]) }; + const gp_Pnt2d aNodesUV[3] = { theTriangulation->UVNode(aNodeIdxs[0]), + theTriangulation->UVNode(aNodeIdxs[1]), + theTriangulation->UVNode(aNodeIdxs[2]) }; // Evaluate polyline points for u isolines. for (Standard_Integer anIsoIdx = 1; anIsoIdx <= aNbIsoU; ++anIsoIdx) diff --git a/src/StdPrs/StdPrs_ShadedShape.cxx b/src/StdPrs/StdPrs_ShadedShape.cxx index 243ee8e06f..bd76943041 100644 --- a/src/StdPrs/StdPrs_ShadedShape.cxx +++ b/src/StdPrs/StdPrs_ShadedShape.cxx @@ -190,9 +190,7 @@ namespace Poly_Connect aPolyConnect (aT); // Extracts vertices & normals from nodes - const TColgp_Array1OfPnt& aNodes = aT->Nodes(); - const TColgp_Array1OfPnt2d& aUVNodes = aT->UVNodes(); - TColgp_Array1OfDir aNormals (aNodes.Lower(), aNodes.Upper()); + TColgp_Array1OfDir aNormals (1, aT->NbNodes()); StdPrs_ToolTriangulatedShape::Normal (aFace, aPolyConnect, aNormals); if (theHasTexels) @@ -203,9 +201,9 @@ namespace } const Standard_Integer aDecal = anArray->VertexNumber(); - for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter) + for (Standard_Integer aNodeIter = 1; aNodeIter <= aT->NbNodes(); ++aNodeIter) { - aPoint = aNodes (aNodeIter); + aPoint = aT->Node (aNodeIter); if (!aLoc.IsIdentity()) { aPoint.Transform (aTrsf); @@ -213,10 +211,10 @@ namespace aNormals (aNodeIter) = aNormals (aNodeIter).Transformed (aTrsf); } - if (theHasTexels && aUVNodes.Upper() == aNodes.Upper()) + if (theHasTexels && aT->HasUVNodes()) { - const gp_Pnt2d aTexel = gp_Pnt2d ((-theUVOrigin.X() + (theUVRepeat.X() * (aUVNodes (aNodeIter).X() - aUmin)) / dUmax) / theUVScale.X(), - (-theUVOrigin.Y() + (theUVRepeat.Y() * (aUVNodes (aNodeIter).Y() - aVmin)) / dVmax) / theUVScale.Y()); + const gp_Pnt2d aTexel = gp_Pnt2d ((-theUVOrigin.X() + (theUVRepeat.X() * (aT->UVNode (aNodeIter).X() - aUmin)) / dUmax) / theUVScale.X(), + (-theUVOrigin.Y() + (theUVRepeat.Y() * (aT->UVNode (aNodeIter).Y() - aVmin)) / dVmax) / theUVScale.Y()); anArray->AddVertex (aPoint, aNormals (aNodeIter), aTexel); } else @@ -226,22 +224,21 @@ namespace } // Fill array with vertex and edge visibility info - const Poly_Array1OfTriangle& aTriangles = aT->Triangles(); Standard_Integer anIndex[3]; for (Standard_Integer aTriIter = 1; aTriIter <= aT->NbTriangles(); ++aTriIter) { if ((aFace.Orientation() == TopAbs_REVERSED) ^ isMirrored) { - aTriangles (aTriIter).Get (anIndex[0], anIndex[2], anIndex[1]); + aT->Triangle (aTriIter).Get (anIndex[0], anIndex[2], anIndex[1]); } else { - aTriangles (aTriIter).Get (anIndex[0], anIndex[1], anIndex[2]); + aT->Triangle (aTriIter).Get (anIndex[0], anIndex[1], anIndex[2]); } - gp_Pnt aP1 = aNodes (anIndex[0]); - gp_Pnt aP2 = aNodes (anIndex[1]); - gp_Pnt aP3 = aNodes (anIndex[2]); + gp_Pnt aP1 = aT->Node (anIndex[0]); + gp_Pnt aP2 = aT->Node (anIndex[1]); + gp_Pnt aP3 = aT->Node (anIndex[2]); gp_Vec aV1 (aP1, aP2); if (aV1.SquareMagnitude() <= aPreci) @@ -367,8 +364,10 @@ namespace } // get edge nodes indexes from face triangulation - const TColgp_Array1OfPnt& aTriNodes = aTriangulation->Nodes(); - const TColStd_Array1OfInteger& anEdgeNodes = anEdgePoly->Nodes(); + const TColStd_Array1OfInteger& anEdgeNodes = anEdgePoly->Nodes (); + + if (anEdgeNodes.Length () < 2) + continue; // collect the edge nodes Standard_Integer aSegmentEdge = aSegments->VertexNumber() + 1; @@ -377,8 +376,8 @@ namespace // node index in face triangulation // get node and apply location transformation to the node const Standard_Integer aTriIndex = anEdgeNodes.Value (aNodeIdx); - gp_Pnt aTriNode = aTriNodes.Value (aTriIndex); - if (!aTrsf.IsIdentity()) + gp_Pnt aTriNode = aTriangulation->Node (aTriIndex); + if (!aTrsf.IsIdentity ()) { aTriNode.Transform (aTrsf); } diff --git a/src/StdPrs/StdPrs_ToolTriangulatedShape.cxx b/src/StdPrs/StdPrs_ToolTriangulatedShape.cxx index e5ba469c55..09f23b78a5 100644 --- a/src/StdPrs/StdPrs_ToolTriangulatedShape.cxx +++ b/src/StdPrs/StdPrs_ToolTriangulatedShape.cxx @@ -139,24 +139,17 @@ void StdPrs_ToolTriangulatedShape::Normal (const TopoDS_Face& theFace, TColgp_Array1OfDir& theNormals) { const Handle(Poly_Triangulation)& aPolyTri = thePolyConnect.Triangulation(); - const TColgp_Array1OfPnt& aNodes = aPolyTri->Nodes(); if (aPolyTri->HasNormals()) { // normals pre-computed in triangulation structure - const TShort_Array1OfShortReal& aNormals = aPolyTri->Normals(); - const Standard_ShortReal* aNormArr = &(aNormals.Value (aNormals.Lower())); - for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter) + for (Standard_Integer aNodeIter = 1; aNodeIter <= aPolyTri->NbNodes(); ++aNodeIter) { - const Standard_Integer anId = 3 * (aNodeIter - aNodes.Lower()); - const gp_Dir aNorm (aNormArr[anId + 0], - aNormArr[anId + 1], - aNormArr[anId + 2]); - theNormals (aNodeIter) = aNorm; + theNormals (aNodeIter) = aPolyTri->Normal (aNodeIter); } if (theFace.Orientation() == TopAbs_REVERSED) { - for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter) + for (Standard_Integer aNodeIter = 1; aNodeIter <= aPolyTri->NbNodes(); ++aNodeIter) { theNormals.ChangeValue (aNodeIter).Reverse(); } @@ -169,24 +162,21 @@ void StdPrs_ToolTriangulatedShape::Normal (const TopoDS_Face& theFace, Handle(Geom_Surface) aSurf = BRep_Tool::Surface (aZeroFace); const Standard_Real aTol = Precision::Confusion(); Handle(TShort_HArray1OfShortReal) aNormals = new TShort_HArray1OfShortReal (1, aPolyTri->NbNodes() * 3); - const Poly_Array1OfTriangle& aTriangles = aPolyTri->Triangles(); - const TColgp_Array1OfPnt2d* aNodesUV = aPolyTri->HasUVNodes() && !aSurf.IsNull() - ? &aPolyTri->UVNodes() - : NULL; + Standard_Boolean hasUVNodes = aPolyTri->HasUVNodes() && !aSurf.IsNull(); Standard_Integer aTri[3]; - for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter) + for (Standard_Integer aNodeIter = 1; aNodeIter <= aPolyTri->NbNodes(); ++aNodeIter) { // try to retrieve normal from real surface first, when UV coordinates are available - if (aNodesUV == NULL - || GeomLib::NormEstim (aSurf, aNodesUV->Value (aNodeIter), aTol, theNormals (aNodeIter)) > 1) + if (hasUVNodes == Standard_False + || GeomLib::NormEstim (aSurf, aPolyTri->UVNode (aNodeIter), aTol, theNormals (aNodeIter)) > 1) { // compute flat normals gp_XYZ eqPlan (0.0, 0.0, 0.0); for (thePolyConnect.Initialize (aNodeIter); thePolyConnect.More(); thePolyConnect.Next()) { - aTriangles (thePolyConnect.Value()).Get (aTri[0], aTri[1], aTri[2]); - const gp_XYZ v1 (aNodes (aTri[1]).Coord() - aNodes (aTri[0]).Coord()); - const gp_XYZ v2 (aNodes (aTri[2]).Coord() - aNodes (aTri[1]).Coord()); + aPolyTri->Triangle (thePolyConnect.Value()).Get (aTri[0], aTri[1], aTri[2]); + const gp_XYZ v1 (aPolyTri->Node (aTri[1]).Coord() - aPolyTri->Node (aTri[0]).Coord()); + const gp_XYZ v2 (aPolyTri->Node (aTri[2]).Coord() - aPolyTri->Node (aTri[1]).Coord()); const gp_XYZ vv = v1 ^ v2; const Standard_Real aMod = vv.Modulus(); if (aMod >= aTol) @@ -198,7 +188,7 @@ void StdPrs_ToolTriangulatedShape::Normal (const TopoDS_Face& theFace, theNormals (aNodeIter) = (aModMax > aTol) ? gp_Dir (eqPlan) : gp::DZ(); } - const Standard_Integer anId = (aNodeIter - aNodes.Lower()) * 3; + const Standard_Integer anId = (aNodeIter - 1) * 3; aNormals->SetValue (anId + 1, (Standard_ShortReal )theNormals (aNodeIter).X()); aNormals->SetValue (anId + 2, (Standard_ShortReal )theNormals (aNodeIter).Y()); aNormals->SetValue (anId + 3, (Standard_ShortReal )theNormals (aNodeIter).Z()); @@ -207,7 +197,7 @@ void StdPrs_ToolTriangulatedShape::Normal (const TopoDS_Face& theFace, if (theFace.Orientation() == TopAbs_REVERSED) { - for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter) + for (Standard_Integer aNodeIter = 1; aNodeIter <= aPolyTri->NbNodes(); ++aNodeIter) { theNormals.ChangeValue (aNodeIter).Reverse(); } diff --git a/src/StdPrs/StdPrs_WFShape.cxx b/src/StdPrs/StdPrs_WFShape.cxx index 5522ea5fe1..0d740ede12 100644 --- a/src/StdPrs/StdPrs_WFShape.cxx +++ b/src/StdPrs/StdPrs_WFShape.cxx @@ -202,21 +202,20 @@ void StdPrs_WFShape::addEdges (const TopTools_ListOfShape& theEdges, { // Presentation based on triangulation of a face. const TColStd_Array1OfInteger& anIndices = anEdgeIndicies->Nodes(); - const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes(); Standard_Integer anIndex = anIndices.Lower(); if (aLocation.IsIdentity()) { for (; anIndex <= anIndices.Upper(); ++anIndex) { - aPoints->Append (aNodes (anIndices (anIndex))); + aPoints->Append (aTriangulation->Node(anIndices (anIndex))); } } else { for (; anIndex <= anIndices.Upper(); ++anIndex) { - aPoints->Append (aNodes (anIndices (anIndex)).Transformed (aLocation)); + aPoints->Append (aTriangulation->Node(anIndices (anIndex)).Transformed (aLocation)); } } } @@ -281,8 +280,6 @@ void StdPrs_WFShape::addEdgesOnTriangulation (const Handle(Prs3d_Presentation)& continue; } - const TColgp_Array1OfPnt& aNodes = T->Nodes(); - // Build the connect tool. Poly_Connect aPolyConnect (T); @@ -315,11 +312,10 @@ void StdPrs_WFShape::addEdgesOnTriangulation (const Handle(Prs3d_Presentation)& TColStd_Array1OfInteger anInternal (0, 2 * aNbInternal); Standard_Integer aFreeIndex = 1, anIntIndex = 1; - const Poly_Array1OfTriangle& aTriangles = T->Triangles(); for (Standard_Integer anI = 1; anI <= aNbTriangles; ++anI) { aPolyConnect.Triangles (anI, aT[0], aT[1], aT[2]); - aTriangles (anI).Get (aN[0], aN[1], aN[2]); + T->Triangle (anI).Get (aN[0], aN[1], aN[2]); for (Standard_Integer aJ = 0; aJ < 3; aJ++) { Standard_Integer k = (aJ + 1) % 3; @@ -343,8 +339,8 @@ void StdPrs_WFShape::addEdgesOnTriangulation (const Handle(Prs3d_Presentation)& Standard_Integer aFreeHalfNb = aFree.Length() / 2; for (Standard_Integer anI = 1; anI <= aFreeHalfNb; ++anI) { - gp_Pnt aPoint1 = aNodes (aFree (2 * anI - 1)).Transformed (aLocation); - gp_Pnt aPoint2 = aNodes (aFree (2 * anI )).Transformed (aLocation); + gp_Pnt aPoint1 = T->Node(aFree (2 * anI - 1)).Transformed (aLocation); + gp_Pnt aPoint2 = T->Node(aFree (2 * anI )).Transformed (aLocation); aSurfPoints.Append (aPoint1); aSurfPoints.Append (aPoint2); } diff --git a/src/StdSelect/StdSelect_BRepSelectionTool.cxx b/src/StdSelect/StdSelect_BRepSelectionTool.cxx index 9b83721973..8a034e9e41 100644 --- a/src/StdSelect/StdSelect_BRepSelectionTool.cxx +++ b/src/StdSelect/StdSelect_BRepSelectionTool.cxx @@ -356,7 +356,6 @@ static Handle(TColgp_HArray1OfPnt) GetPointsFromPolygon (const TopoDS_Edge& theE if (!anHIndices.IsNull()) { const TColStd_Array1OfInteger& anIndices = anHIndices->Nodes(); - const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes(); aResultPoints = new TColgp_HArray1OfPnt (1, anIndices.Length()); @@ -364,14 +363,14 @@ static Handle(TColgp_HArray1OfPnt) GetPointsFromPolygon (const TopoDS_Edge& theE { for (Standard_Integer anIndex (anIndices.Lower()), aPntId (1); anIndex <= anIndices.Upper(); ++anIndex, ++aPntId) { - aResultPoints->SetValue (aPntId, aNodes (anIndices (anIndex))); + aResultPoints->SetValue (aPntId, aTriangulation->Node(anIndices (anIndex))); } } else { for (Standard_Integer anIndex (anIndices.Lower()), aPntId (1); anIndex <= anIndices.Upper(); ++anIndex, ++aPntId) { - aResultPoints->SetValue (aPntId, aNodes (anIndices (anIndex)).Transformed (aLocation)); + aResultPoints->SetValue (aPntId, aTriangulation->Node(anIndices (anIndex)).Transformed (aLocation)); } } return aResultPoints; diff --git a/src/StdSelect/StdSelect_ViewerSelector3d.cxx b/src/StdSelect/StdSelect_ViewerSelector3d.cxx index d79356c955..8775016369 100644 --- a/src/StdSelect/StdSelect_ViewerSelector3d.cxx +++ b/src/StdSelect/StdSelect_ViewerSelector3d.cxx @@ -539,8 +539,6 @@ void StdSelect_ViewerSelector3d::computeSensitivePrs (const Handle(Graphic3d_Str { Handle(Poly_Triangulation) PT (Handle(Select3D_SensitiveTriangulation)::DownCast (Ent)->Triangulation()); - const Poly_Array1OfTriangle& triangles = PT->Triangles(); - const TColgp_Array1OfPnt& Nodes = PT->Nodes(); Standard_Integer n[3]; TopLoc_Location iloc, bidloc; @@ -555,10 +553,10 @@ void StdSelect_ViewerSelector3d::computeSensitivePrs (const Handle(Graphic3d_Str Standard_Integer i; for (i = 1; i <= PT->NbTriangles(); i++) { - triangles (i).Get (n[0], n[1], n[2]); - gp_Pnt P1 (Nodes (n[0]).Transformed (iloc)); - gp_Pnt P2 (Nodes (n[1]).Transformed (iloc)); - gp_Pnt P3 (Nodes (n[2]).Transformed (iloc)); + PT->Triangle (i).Get (n[0], n[1], n[2]); + gp_Pnt P1 (PT->Node (n[0]).Transformed (iloc)); + gp_Pnt P2 (PT->Node (n[1]).Transformed (iloc)); + gp_Pnt P3 (PT->Node (n[2]).Transformed (iloc)); gp_XYZ V1 (P1.XYZ()); gp_XYZ V2 (P2.XYZ()); gp_XYZ V3 (P3.XYZ()); @@ -585,7 +583,7 @@ void StdSelect_ViewerSelector3d::computeSensitivePrs (const Handle(Graphic3d_Str for (i = 1; i <= PT->NbTriangles(); i++) { pc.Triangles (i, t[0], t[1], t[2]); - triangles (i).Get (n[0], n[1], n[2]); + PT->Triangle (i).Get (n[0], n[1], n[2]); for (j = 0; j < 3; j++) { Standard_Integer k = (j + 1) % 3; @@ -599,7 +597,7 @@ void StdSelect_ViewerSelector3d::computeSensitivePrs (const Handle(Graphic3d_Str } for (Standard_Integer ifri = 1; ifri <= FreeE.Length(); ifri += 2) { - gp_Pnt pe1 (Nodes (FreeE (ifri)).Transformed (iloc)), pe2 (Nodes (FreeE (ifri + 1)).Transformed (iloc)); + gp_Pnt pe1 (PT->Node (FreeE (ifri)).Transformed (iloc)), pe2 (PT->Node (FreeE (ifri + 1)).Transformed (iloc)); aSeqFree.Append(pe1); aSeqFree.Append(pe2); } diff --git a/src/StlAPI/StlAPI_Writer.cxx b/src/StlAPI/StlAPI_Writer.cxx index 1b4c6fe5fa..efd5cc0bf7 100644 --- a/src/StlAPI/StlAPI_Writer.cxx +++ b/src/StlAPI/StlAPI_Writer.cxx @@ -50,7 +50,7 @@ namespace TopLoc_Location aLoc; myPoly = BRep_Tool::Triangulation (aFace, aLoc); myTrsf = aLoc.Transformation(); - myNbTriangles = (myPoly.IsNull() ? 0 : myPoly->Triangles().Length()); + myNbTriangles = (myPoly.IsNull() ? 0 : myPoly->NbTriangles()); myInvert = (aFace.Orientation() == TopAbs_REVERSED); if (myTrsf.IsNegative()) myInvert = ! myInvert; @@ -63,10 +63,10 @@ namespace { // get positions of nodes int iNode1, iNode2, iNode3; - myPoly->Triangles()(iTri).Get (iNode1, iNode2, iNode3); - thePnt1 = myPoly->Nodes()(iNode1); - thePnt2 = myPoly->Nodes()(myInvert ? iNode3 : iNode2); - thePnt3 = myPoly->Nodes()(myInvert ? iNode2 : iNode3); + myPoly->Triangle(iTri).Get (iNode1, iNode2, iNode3); + thePnt1 = myPoly->Node(iNode1); + thePnt2 = myPoly->Node(myInvert ? iNode3 : iNode2); + thePnt3 = myPoly->Node(myInvert ? iNode2 : iNode3); // apply transormation if not identity if (myTrsf.Form() != gp_Identity) diff --git a/src/StlTransfer/StlTransfer.cxx b/src/StlTransfer/StlTransfer.cxx index d8916120ba..717c506279 100644 --- a/src/StlTransfer/StlTransfer.cxx +++ b/src/StlTransfer/StlTransfer.cxx @@ -62,11 +62,10 @@ static void Normal(const TopoDS_Face& aFace, CSLib_DerivativeStatus Status; CSLib_NormalStatus NStat; S.Initialize(aFace, Standard_False); - const TColgp_Array1OfPnt2d& UVNodes = T->UVNodes(); if (S.GetType() != GeomAbs_Plane) { - for (i = UVNodes.Lower(); i <= UVNodes.Upper(); i++) { - U = UVNodes(i).X(); - V = UVNodes(i).Y(); + for (i = 1; i <= T->NbNodes(); i++) { + U = T->UVNode (i).X(); + V = T->UVNode (i).Y(); S.D1(U,V,P,D1U,D1V); CSLib::Normal(D1U,D1V,Precision::Angular(),Status,Nor(i)); if (Status != CSLib_Done) { @@ -78,8 +77,8 @@ static void Normal(const TopoDS_Face& aFace, } else { gp_Dir NPlane; - U = UVNodes(UVNodes.Lower()).X(); - V = UVNodes(UVNodes.Lower()).Y(); + U = T->UVNode (1).X(); + V = T->UVNode (1).Y(); S.D1(U,V,P,D1U,D1V); CSLib::Normal(D1U,D1V,Precision::Angular(),Status,NPlane); if (Status != CSLib_Done) { @@ -92,16 +91,14 @@ static void Normal(const TopoDS_Face& aFace, } } else { - const TColgp_Array1OfPnt& Nodes = T->Nodes(); Standard_Integer n[3]; - const Poly_Array1OfTriangle& triangles = T->Triangles(); - - for (i = Nodes.Lower(); i <= Nodes.Upper(); i++) { + + for (i = 1; i <= T->NbNodes(); i++) { gp_XYZ eqPlan(0, 0, 0); for (pc.Initialize(i); pc.More(); pc.Next()) { - triangles(pc.Value()).Get(n[0], n[1], n[2]); - gp_XYZ v1(Nodes(n[1]).Coord()-Nodes(n[0]).Coord()); - gp_XYZ v2(Nodes(n[2]).Coord()-Nodes(n[1]).Coord()); + T->Triangle (pc.Value()).Get(n[0], n[1], n[2]); + gp_XYZ v1(T->Node (n[1]).Coord() - T->Node (n[0]).Coord()); + gp_XYZ v2(T->Node (n[2]).Coord() - T->Node (n[1]).Coord()); eqPlan += (v1^v2).Normalized(); } Nor(i) = gp_Dir(eqPlan); @@ -118,30 +115,25 @@ void StlTransfer::RetrieveMesh (const TopoDS_Shape& Shape, TopLoc_Location Loc, loc; Handle(Poly_Triangulation) theTriangulation = BRep_Tool::Triangulation(face, Loc); if (theTriangulation.IsNull()) continue; //Meshing was not done for this face! - Poly_Array1OfTriangle theTriangles(1,theTriangulation->NbTriangles()); - theTriangles.Assign(theTriangulation->Triangles()); Mesh->AddDomain (theTriangulation->Deflection()); - - TColgp_Array1OfPnt thePoints(1, theTriangulation->NbNodes()); - thePoints.Assign(theTriangulation->Nodes()); + //compute normal of face - const TColgp_Array1OfPnt& Nodes = theTriangulation->Nodes(); - TColgp_Array1OfDir NORMAL(Nodes.Lower(), Nodes.Upper()); + TColgp_Array1OfDir NORMAL(1, theTriangulation->NbNodes()); Poly_Connect pc(theTriangulation); Normal(face, pc, NORMAL); Standard_Integer i; - for(i=1;i<=thePoints.Length();i++) { + for(i=1;i<=theTriangulation->NbNodes();i++) { Standard_Real X1, Y1, Z1; - gp_Pnt p = thePoints.Value(i); + gp_Pnt p = theTriangulation->Node (i); p.Transform(Loc.Transformation()); p.Coord (X1, Y1, Z1); Mesh->AddVertex (X1, Y1, Z1); } try { OCC_CATCH_SIGNALS - for (i=1;i<=theTriangles.Length();i++) { + for (i=1;i<=theTriangulation->NbTriangles();i++) { Standard_Integer V1, V2, V3; - Poly_Triangle triangle = theTriangles.Value(i); + Poly_Triangle triangle = theTriangulation->Triangle (i); triangle.Get(V1, V2, V3); gp_Pnt P1, P2, P3; P1 = Mesh->Vertices(Mesh->NbDomains()).Value(V1); diff --git a/src/TDataStd/FILES b/src/TDataStd/FILES index f9b707f64b..e72ac561eb 100644 --- a/src/TDataStd/FILES +++ b/src/TDataStd/FILES @@ -79,6 +79,8 @@ TDataStd_ListIteratorOfListOfByte.hxx TDataStd_ListIteratorOfListOfExtendedString.hxx TDataStd_ListOfByte.hxx TDataStd_ListOfExtendedString.hxx +TDataStd_Mesh.cxx +TDataStd_Mesh.hxx TDataStd_Name.cxx TDataStd_Name.hxx TDataStd_NamedData.cxx diff --git a/src/TDataStd/TDataStd_Mesh.cxx b/src/TDataStd/TDataStd_Mesh.cxx new file mode 100644 index 0000000000..67ae42affd --- /dev/null +++ b/src/TDataStd/TDataStd_Mesh.cxx @@ -0,0 +1,427 @@ +// 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 : Returns the ID of the mesh attribute. +//======================================================================= +const Standard_GUID& TDataStd_Mesh::GetID() +{ + static Standard_GUID TDataStd_MeshID ("D7E3F1CF-38A4-4DCA-94F4-51C31F3FCBA5"); + return TDataStd_MeshID; +} + +//======================================================================= +//function : Set +//purpose : Finds or creates a mesh attribute. +//======================================================================= +Handle(TDataStd_Mesh) TDataStd_Mesh::Set(const TDF_Label& label) +{ + Handle(TDataStd_Mesh) A; + if (!label.FindAttribute (TDataStd_Mesh::GetID(), A)) + { + A = new TDataStd_Mesh; + label.AddAttribute(A); + } + return A; +} + +//======================================================================= +//function : Set +//purpose : 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. +//======================================================================= +Handle(TDataStd_Mesh) TDataStd_Mesh::Set(const TDF_Label& label, const Handle(Poly_Mesh)& mesh) +{ + Handle(TDataStd_Mesh) M = TDataStd_Mesh::Set(label); + M->Set(mesh); + return M; +} + +//======================================================================= +//function : TDataStd_Mesh +//purpose : A constructor. +// Don't use it directly, +// use please the static method Set(), +// which returns the attribute attached to a label. +//======================================================================= +TDataStd_Mesh::TDataStd_Mesh() +{ + +} + +//======================================================================= +//function : TDataStd_Mesh +//purpose : Sets the mesh. +// If the mesh consists of only triangles, +// you may put Poly_Triangulation object. +//======================================================================= +void TDataStd_Mesh::Set(const Handle(Poly_Mesh)& mesh) +{ + Backup(); + myMesh = mesh; +} + +//======================================================================= +//function : TDataStd_Mesh +//purpose : Returns the underlying mesh. +//======================================================================= +const Handle(Poly_Mesh)& TDataStd_Mesh::Get() const +{ + return myMesh; +} + +// Poly_Mesh methods + +// The methods are "covered" by this attribute to prevent direct modification of the mesh. +// There is no performance problem to call Poly_Mesh method through this attribute. +// The most of the methods are considered as "inline" by the compiler in release mode. + +//======================================================================= +//function : Deflection +//purpose : Returns the deflection of this triangulation. +//======================================================================= +Standard_Real TDataStd_Mesh::Deflection() const +{ + return myMesh->Deflection(); +} + +//======================================================================= +//function : Deflection +//purpose : Sets the deflection of this triangulation to theDeflection. +// See more on deflection in Polygon2D +//======================================================================= +void TDataStd_Mesh::Deflection (const Standard_Real theDeflection) +{ + Backup(); + myMesh->Deflection(theDeflection); +} + +//======================================================================= +//function : RemoveUVNodes +//purpose : Deallocates the UV nodes. +//======================================================================= +void TDataStd_Mesh::RemoveUVNodes() +{ + Backup(); + myMesh->RemoveUVNodes(); +} + +//======================================================================= +//function : NbNodes +//purpose : return the number of nodes for this triangulation. +//======================================================================= +Standard_Integer TDataStd_Mesh::NbNodes() const +{ + return myMesh->NbNodes(); +} + +//======================================================================= +//function : NbTriangles +//purpose : return the number of triangles for this triangulation. +//======================================================================= +Standard_Integer TDataStd_Mesh::NbTriangles() const +{ + return myMesh->NbTriangles(); +} + +//======================================================================= +//function : HasUVNodes +//purpose : return Standard_True if 2D nodes are associated with 3D nodes for this triangulation. +//======================================================================= +Standard_Boolean TDataStd_Mesh::HasUVNodes() const +{ + return myMesh->HasUVNodes(); +} + +//======================================================================= +//function : AddNode +//purpose : Adds Node to the triangulation. If triangulation has UVNodes or Normals +// they will be expanded and set to zero values to match the new number of nodes. +// return index of the added Node. +//======================================================================= +Standard_Integer TDataStd_Mesh::AddNode (const gp_Pnt& theNode) +{ + Backup(); + return myMesh->AddNode(theNode); +} + +//======================================================================= +//function : Node +//purpose : return node at the given index. +// Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes. +//======================================================================= +const gp_Pnt& TDataStd_Mesh::Node (const Standard_Integer theIndex) const +{ + return myMesh->Node(theIndex); +} + +//======================================================================= +//function : SetNode +//purpose : The method differs from Poly_Mesh +// Sets a node at the given index. +// Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes. +//======================================================================= +void TDataStd_Mesh::SetNode (const Standard_Integer theIndex, const gp_Pnt& theNode) +{ + Backup(); + myMesh->ChangeNode(theIndex) = theNode; +} + +//======================================================================= +//function : UVNode +//purpose : return UVNode at the given index. +// Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes. +//======================================================================= +const gp_Pnt2d& TDataStd_Mesh::UVNode (const Standard_Integer theIndex) const +{ + return myMesh->UVNode(theIndex); +} + +//======================================================================= +//function : SetUVNode +//purpose : The method differs from Poly_Mesh +// Sets a UVNode at the given index. +// Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes. +//======================================================================= +void TDataStd_Mesh::SetUVNode (const Standard_Integer theIndex, const gp_Pnt2d& theUVNode) +{ + Backup(); + myMesh->ChangeUVNode(theIndex) = theUVNode; +} + +//======================================================================= +//function : AddTriangle +//purpose : Adds triangle to the triangulation. +// return index of the added triangle. +//======================================================================= +Standard_Integer TDataStd_Mesh::AddTriangle (const Poly_Triangle& theTriangle) +{ + Backup(); + return myMesh->AddTriangle(theTriangle); +} + +//======================================================================= +//function : Triangle +//purpose : return triangle at the given index. +// Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbTriangles. +//======================================================================= +const Poly_Triangle& TDataStd_Mesh::Triangle (const Standard_Integer theIndex) const +{ + return myMesh->Triangle(theIndex); +} + +//======================================================================= +//function : SetTriangle +//purpose : The method differs from Poly_Mesh +// Sets a triangle at the given index. +// Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbTriangles. +//======================================================================= +void TDataStd_Mesh::SetTriangle (const Standard_Integer theIndex, const Poly_Triangle& theTriangle) +{ + Backup(); + myMesh->ChangeTriangle(theIndex) = theTriangle; +} + +//======================================================================= +//function : SetNormals +//purpose : Sets the table of node normals. +// Raises exception if length of theNormals = 3 * NbNodes +//======================================================================= +void TDataStd_Mesh::SetNormals (const Handle(TShort_HArray1OfShortReal)& theNormals) +{ + Backup(); + myMesh->SetNormals(theNormals); +} + +//======================================================================= +//function : SetNormal +//purpose : Changes normal at the given index. +// Raises Standard_OutOfRange exception. +//======================================================================= +void TDataStd_Mesh::SetNormal (const Standard_Integer theIndex, + const gp_Dir& theNormal) +{ + Backup(); + myMesh->SetNormal(theIndex, theNormal); +} + +//======================================================================= +//function : HasNormals +//purpose : Returns Standard_True if nodal normals are defined. +//======================================================================= +Standard_Boolean TDataStd_Mesh::HasNormals() const +{ + return myMesh->HasNormals(); +} + +//======================================================================= +//function : Normal +//purpose : return normal at the given index. +// Raises Standard_OutOfRange exception. +//======================================================================= +const gp_Dir TDataStd_Mesh::Normal (const Standard_Integer theIndex) const +{ + return myMesh->Normal(theIndex); +} + +//======================================================================= +//function : AddElement +//purpose : +//======================================================================= +Standard_Integer TDataStd_Mesh::AddElement (const Standard_Integer theN1, + const Standard_Integer theN2, + const Standard_Integer theN3) +{ + Backup(); + return myMesh->AddElement(theN1, theN2, theN3); +} + +//======================================================================= +//function : AddElement +//purpose : +//======================================================================= +Standard_Integer TDataStd_Mesh::AddElement (const Standard_Integer theN1, + const Standard_Integer theN2, + const Standard_Integer theN3, + const Standard_Integer theN4) +{ + Backup(); + return myMesh->AddElement(theN1, theN2, theN3, theN4); +} + +//======================================================================= +//function : NbElements +//purpose : return the number of elements for this mesh. +//======================================================================= +Standard_Integer TDataStd_Mesh::NbElements() const +{ + return myMesh->NbElements(); +} + +//======================================================================= +//function : NbQuads +//purpose : return the number of quads for this mesh. +//======================================================================= +Standard_Integer TDataStd_Mesh::NbQuads() const +{ + return myMesh->NbQuads(); +} + +//======================================================================= +//function : Element +//purpose : return element at the given index. +// Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbElements. +//======================================================================= +const Poly_Element& TDataStd_Mesh::Element (const Standard_Integer theIndex) const +{ + return myMesh->Element(theIndex); +} + +//======================================================================= +//function : Element +//purpose : return nodes of the element at the given index. +// Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbElements. +//======================================================================= +void TDataStd_Mesh::Element (const Standard_Integer theIndex, + Standard_Integer& theN1, + Standard_Integer& theN2, + Standard_Integer& theN3, + Standard_Integer& theN4) const +{ + myMesh->Element(theIndex, theN1, theN2, theN3, theN4); +} + +//======================================================================= +//function : SetElement +//purpose : Sets an element at the given index. +// Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbElements. +//======================================================================= +void TDataStd_Mesh::SetElement (const Standard_Integer theIndex, const Poly_Element& theElement) +{ + Backup(); + myMesh->SetElement(theIndex, theElement); +} + +//======================================================================= +//function : ID +//purpose : +//======================================================================= +const Standard_GUID& TDataStd_Mesh::ID () const +{ + return GetID(); +} + +//======================================================================= +//function : NewEmpty +//purpose : +//======================================================================= +Handle(TDF_Attribute) TDataStd_Mesh::NewEmpty () const +{ + return new TDataStd_Mesh(); +} + +//======================================================================= +//function : Restore +//purpose : +//======================================================================= +void TDataStd_Mesh::Restore(const Handle(TDF_Attribute)& With) +{ + myMesh.Nullify(); + Handle(TDataStd_Mesh) M = Handle(TDataStd_Mesh)::DownCast(With); + if (!M->myMesh.IsNull()) + { + Handle(Poly_Triangulation) T = M->myMesh->Copy(); + if (!T.IsNull()) + myMesh = Handle(Poly_Mesh)::DownCast(T); + } +} + +//======================================================================= +//function : Paste +//purpose : +//======================================================================= +void TDataStd_Mesh::Paste (const Handle(TDF_Attribute)& Into, + const Handle(TDF_RelocationTable)& ) const +{ + Handle(TDataStd_Mesh) M = Handle(TDataStd_Mesh)::DownCast(Into); + M->myMesh.Nullify(); + if (!myMesh.IsNull()) + { + Handle(Poly_Triangulation) T = myMesh->Copy(); + if (!T.IsNull()) + M->myMesh = Handle(Poly_Mesh)::DownCast(T); + } +} + +//======================================================================= +//function : Dump +//purpose : +//======================================================================= +Standard_OStream& TDataStd_Mesh::Dump (Standard_OStream& anOS) const +{ + anOS << "Mesh"; + //TODO: Make a good dump. + return anOS; +} diff --git a/src/TDataStd/TDataStd_Mesh.hxx b/src/TDataStd/TDataStd_Mesh.hxx new file mode 100644 index 0000000000..d2681068af --- /dev/null +++ b/src/TDataStd/TDataStd_Mesh.hxx @@ -0,0 +1,218 @@ +// 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 _TDataStd_Mesh_HeaderFile +#define _TDataStd_Mesh_HeaderFile + +#include +#include + +#include +#include +#include +#include +#include +class Standard_GUID; +class TDF_Label; +class TDF_Attribute; +class TDF_RelocationTable; + +class TDataStd_Mesh; +DEFINE_STANDARD_HANDLE(TDataStd_Mesh, TDF_Attribute) + +//! An Ocaf attribute containing a mesh (Poly_Mesh). +//! It duplicates all methods from Poly_Mesh (and Poly_Triangulation). +//! It is highly recommended to modify the mesh through the methods of this attribute, +//! but not directly via the underlying Poly_Mesh object. +//! In this case Undo/Redo will work fine and robust. +class TDataStd_Mesh : 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(TDataStd_Mesh) Set(const TDF_Label& label); + + //! 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(TDataStd_Mesh) Set(const TDF_Label& label, const Handle(Poly_Mesh)& mesh); + + //! 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 TDataStd_Mesh(); + + //! Sets the mesh. + //! If the mesh consists of only triangles, + //! you may put Poly_Triangulation object. + Standard_EXPORT void Set(const Handle(Poly_Mesh)& mesh); + + //! 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. + //! There is no performance problem to call Poly_Mesh method through this attribute. + //! The most of the methods are considered as "inline" by the compiler in release mode. + + //! Returns the deflection of this triangulation. + Standard_EXPORT Standard_Real Deflection() const; + + //! Sets the deflection of this triangulation to theDeflection. + //! See more on deflection in Polygon2D + Standard_EXPORT void Deflection (const Standard_Real theDeflection); + + //! Deallocates the UV nodes. + Standard_EXPORT void RemoveUVNodes(); + + //! @return the number of nodes for this triangulation. + Standard_EXPORT Standard_Integer NbNodes() const; + + //! @return the number of triangles for this triangulation. + Standard_EXPORT Standard_Integer NbTriangles() const; + + //! @return Standard_True if 2D nodes are associated with 3D nodes for this triangulation. + Standard_EXPORT Standard_Boolean HasUVNodes() const; + + //! Adds Node to the triangulation. If triangulation has UVNodes or Normals + //! they will be expanded and set to zero values to match the new number of nodes. + //! @return index of the added Node. + Standard_EXPORT Standard_Integer AddNode (const gp_Pnt& theNode); + + //! @return 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; + + //! The method differs from Poly_Mesh! + //! Sets a node at the given index. + //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes. + Standard_EXPORT void SetNode (const Standard_Integer theIndex, const gp_Pnt& theNode); + + //! @return 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; + + //! The method differs from Poly_Mesh! + //! Sets a UVNode at the given index. + //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes. + Standard_EXPORT void SetUVNode (const Standard_Integer theIndex, const gp_Pnt2d& theUVNode); + + //! Adds triangle to the triangulation. + //! @return index of the added triangle. + Standard_EXPORT Standard_Integer AddTriangle (const Poly_Triangle& theTriangle); + + //! @return 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; + + //! The method differs from Poly_Mesh! + //! Sets a triangle at the given index. + //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbTriangles. + Standard_EXPORT void SetTriangle (const Standard_Integer theIndex, const Poly_Triangle& theTriangle); + + //! Sets the table of node normals. + //! Raises exception if length of theNormals != 3 * NbNodes + Standard_EXPORT void SetNormals (const Handle(TShort_HArray1OfShortReal)& theNormals); + + //! Changes normal at the given index. + //! Raises Standard_OutOfRange exception. + Standard_EXPORT void SetNormal (const Standard_Integer theIndex, + const gp_Dir& theNormal); + + //! 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; + + //! Adds element to the mesh. + //! @param theN1 index of the first node. + //! @param theN2 index of the second node. + //! @param theN3 index of the third node. + //! @return index of the added element. + Standard_EXPORT Standard_Integer AddElement (const Standard_Integer theN1, + const Standard_Integer theN2, + const Standard_Integer theN3); + + //! Adds element to the mesh. + //! @param theN1 index of the first node. + //! @param theN2 index of the second node. + //! @param theN3 index of the third node. + //! @param theN4 index of the fourth node. + //! @return index of the added element. + Standard_EXPORT Standard_Integer AddElement (const Standard_Integer theN1, + const Standard_Integer theN2, + const Standard_Integer theN3, + const Standard_Integer theN4); + + //! @return the number of elements for this mesh. + Standard_EXPORT Standard_Integer NbElements() const; + + //! @return the number of quads for this mesh. + Standard_EXPORT Standard_Integer NbQuads() const; + + //! @return element at the given index. + //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbElements. + Standard_EXPORT const Poly_Element& Element (const Standard_Integer theIndex) const; + + //! @return nodes of the element at the given index. + //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbElements. + Standard_EXPORT void Element (const Standard_Integer theIndex, + Standard_Integer& theN1, + Standard_Integer& theN2, + Standard_Integer& theN3, + Standard_Integer& theN4) const; + + //! Sets an element at the given index. + //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbElements. + Standard_EXPORT void SetElement (const Standard_Integer theIndex, const Poly_Element& theElement); + + + //! Inherited attribute methods + // =========================== + + Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE; + + Standard_EXPORT void Restore (const Handle(TDF_Attribute)& With) Standard_OVERRIDE; + + Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE; + + Standard_EXPORT void Paste (const Handle(TDF_Attribute)& Into, const Handle(TDF_RelocationTable)& RT) const Standard_OVERRIDE; + + Standard_EXPORT virtual Standard_OStream& Dump (Standard_OStream& anOS) const Standard_OVERRIDE; + + DEFINE_STANDARD_RTTI_INLINE(TDataStd_Mesh,TDF_Attribute) + +private: + + Handle(Poly_Mesh) myMesh; +}; + +#endif // _TDataStd_Mesh_HeaderFile diff --git a/src/TKLCAF/EXTERNLIB b/src/TKLCAF/EXTERNLIB index 590b3c0512..0294933908 100644 --- a/src/TKLCAF/EXTERNLIB +++ b/src/TKLCAF/EXTERNLIB @@ -1,2 +1,3 @@ TKCDF TKernel +TKMath diff --git a/src/TKXmlL/EXTERNLIB b/src/TKXmlL/EXTERNLIB index 1f4bc90e06..44abe60c02 100755 --- a/src/TKXmlL/EXTERNLIB +++ b/src/TKXmlL/EXTERNLIB @@ -2,3 +2,4 @@ TKCDF TKernel TKMath TKLCAF +TKBRep diff --git a/src/ViewerTest/ViewerTest_ObjectCommands.cxx b/src/ViewerTest/ViewerTest_ObjectCommands.cxx index 1cad752d8a..ba94e834f1 100644 --- a/src/ViewerTest/ViewerTest_ObjectCommands.cxx +++ b/src/ViewerTest/ViewerTest_ObjectCommands.cxx @@ -3009,14 +3009,12 @@ Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z } Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false); - TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes(); - Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles(); if ( mStartPhi <= 0.0 ){ x[0] = mCenter[0]; x[1] = mCenter[1]; x[2] = mCenter[2] + mRadius; - PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2])); + polyTriangulation->ChangeNode (1) = gp_Pnt(x[0],x[1],x[2]); } // Create south pole if needed @@ -3024,7 +3022,7 @@ Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z x[0] = mCenter[0]; x[1] = mCenter[1]; x[2] = mCenter[2] - mRadius; - PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2])); + polyTriangulation->ChangeNode (2) = gp_Pnt(x[0],x[1],x[2]); } number_point = 3; @@ -3039,7 +3037,7 @@ Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z x[0] = n[0] + mCenter[0]; x[1] = n[1] + mCenter[1]; x[2] = n[2] + mCenter[2]; - PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2])); + polyTriangulation->ChangeNode (number_point) = gp_Pnt(x[0],x[1],x[2]); number_point++; } } @@ -3051,7 +3049,7 @@ Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z pts[0] = phiResolution*i + numPoles; pts[1] = (phiResolution*(i+1) % base) + numPoles; pts[2] = 1; - pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2])); + polyTriangulation->ChangeTriangle (number_triangle) = Poly_Triangle(pts[0],pts[1],pts[2]); number_triangle++; } } @@ -3062,7 +3060,7 @@ Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z pts[0] = phiResolution*i + numOffset; pts[2] = ((phiResolution*(i+1)) % base) + numOffset; pts[1] = numPoles - 1; - pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2])); + polyTriangulation->ChangeTriangle (number_triangle) = Poly_Triangle(pts[0],pts[1],pts[2]); number_triangle++; } } @@ -3074,11 +3072,11 @@ Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z pts[0] = phiResolution*i + j + numPoles; pts[1] = pts[0] + 1; pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1; - pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2])); + polyTriangulation->ChangeTriangle (number_triangle) = Poly_Triangle(pts[0],pts[1],pts[2]); number_triangle++; pts[1] = pts[2]; pts[2] = pts[1] - 1; - pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2])); + polyTriangulation->ChangeTriangle (number_triangle) = Poly_Triangle(pts[0],pts[1],pts[2]); number_triangle++; } } @@ -3091,12 +3089,12 @@ Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z Standard_Real Tol = Precision::Confusion(); gp_Dir Nor; - for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) { + for (i = 1; i <= polyTriangulation->NbNodes(); i++) { gp_XYZ eqPlan(0, 0, 0); for ( pc->Initialize(i); pc->More(); pc->Next()) { - pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]); - gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord()); - gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord()); + polyTriangulation->Triangle (pc->Value()).Get(index[0], index[1], index[2]); + gp_XYZ v1(polyTriangulation->Node (index[1]).Coord() - polyTriangulation->Node (index[0]).Coord()); + gp_XYZ v2(polyTriangulation->Node (index[2]).Coord() - polyTriangulation->Node (index[1]).Coord()); gp_XYZ vv = v1^v2; Standard_Real mod = vv.Modulus(); if(mod < Tol) continue; @@ -3109,11 +3107,11 @@ Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z Nor = gp_Dir(eqPlan); else Nor = gp_Dir(0., 0., 1.); - - Standard_Integer k = (i - PointsOfArray.Lower()) * 3; - Normals->SetValue(k + 1, (Standard_ShortReal)Nor.X()); - Normals->SetValue(k + 2, (Standard_ShortReal)Nor.Y()); - Normals->SetValue(k + 3, (Standard_ShortReal)Nor.Z()); + + Standard_Integer j = (i - 1) * 3; + Normals->SetValue(j + 1, (Standard_ShortReal)Nor.X()); + Normals->SetValue(j + 2, (Standard_ShortReal)Nor.Y()); + Normals->SetValue(j + 3, (Standard_ShortReal)Nor.Z()); } delete pc; @@ -3162,8 +3160,8 @@ static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const c = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ, aResolution, aRadius)); - Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length(); - Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length(); + Standard_Integer aNumberPoints = aShape->GetTriangulation()->NbNodes(); + Standard_Integer aNumberTriangles = aShape->GetTriangulation()->NbTriangles(); // stupid initialization of Green color in RGBA space as integer // probably wrong for big-endian CPUs @@ -6125,20 +6123,19 @@ static Standard_Integer VPointCloud (Draw_Interpretor& theDI, continue; } - const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes(); const gp_Trsf& aTrsf = aLocation.Transformation(); // extract normals from nodes - TColgp_Array1OfDir aNormals (aNodes.Lower(), hasNormals ? aNodes.Upper() : aNodes.Lower()); + TColgp_Array1OfDir aNormals (1, hasNormals ? aTriangulation->NbNodes() : 1); if (hasNormals) { Poly_Connect aPolyConnect (aTriangulation); StdPrs_ToolTriangulatedShape::Normal (aFace, aPolyConnect, aNormals); } - for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter) + for (Standard_Integer aNodeIter = 1; aNodeIter <= aTriangulation->NbNodes(); ++aNodeIter) { - gp_Pnt aPoint = aNodes (aNodeIter); + gp_Pnt aPoint = aTriangulation->Node (aNodeIter); if (!aLocation.IsIdentity()) { aPoint.Transform (aTrsf); diff --git a/src/VrmlConverter/VrmlConverter_ShadedShape.cxx b/src/VrmlConverter/VrmlConverter_ShadedShape.cxx index fcfe879fff..90bb409bb7 100644 --- a/src/VrmlConverter/VrmlConverter_ShadedShape.cxx +++ b/src/VrmlConverter/VrmlConverter_ShadedShape.cxx @@ -85,22 +85,18 @@ void VrmlConverter_ShadedShape::Add( Standard_OStream& anOStream, // number of triangles: if (T.IsNull()) continue; //smh nnn = T->NbTriangles(); - - const TColgp_Array1OfPnt& Nodes = T->Nodes(); - // getting a triangle. It is a triplet of indices in the node table: - const Poly_Array1OfTriangle& triangles = T->Triangles(); - + // Taking the nodes of the triangle, taking into account the orientation // of the triangle. for (nt = 1; nt <= nnn; nt++) { if (F.Orientation() == TopAbs_REVERSED) - triangles(nt).Get(n1,n3,n2); + T->Triangle (nt).Get(n1,n3,n2); else - triangles(nt).Get(n1,n2,n3); + T->Triangle (nt).Get(n1,n2,n3); - const gp_Pnt& P1 = Nodes(n1); - const gp_Pnt& P2 = Nodes(n2); - const gp_Pnt& P3 = Nodes(n3); + const gp_Pnt& P1 = T->Node (n1); + const gp_Pnt& P2 = T->Node (n2); + const gp_Pnt& P3 = T->Node (n3); // controlling whether the triangle correct from a 3d point of // view: (the triangle may exist in the UV space but the // in the 3d space a dimension is null for example) @@ -161,13 +157,12 @@ void VrmlConverter_ShadedShape::Add( Standard_OStream& anOStream, // 1 - Building HAV1 - array of all XYZ of nodes for Vrml_Coordinate3 from the triangles // and HAV2 - array of all normals of nodes for Vrml_Normal - const TColgp_Array1OfPnt& Nodes = T->Nodes(); - TColgp_Array1OfDir NORMAL(Nodes.Lower(), Nodes.Upper()); + TColgp_Array1OfDir NORMAL(1, T->NbNodes()); decal = nnv-1; - for (j= Nodes.Lower(); j<= Nodes.Upper(); j++) { - p = Nodes(j).Transformed(theLocation.Transformation()); + for (j= 1; j<= T->NbNodes(); j++) { + p = T->Node (j).Transformed(theLocation.Transformation()); V.SetX(p.X()); V.SetY(p.Y()); V.SetZ(p.Z()); HAV1->SetValue(nnv,V); @@ -186,16 +181,15 @@ void VrmlConverter_ShadedShape::Add( Standard_OStream& anOStream, // 2 - Building HAI1 - array of indexes of all triangles and // HAI3 - array of indexes of all normales for Vrml_IndexedFaceSet nbTriangles = T->NbTriangles(); - const Poly_Array1OfTriangle& triangles = T->Triangles(); for (i = 1; i <= nbTriangles; i++) { pc.Triangles(i,t[0],t[1],t[2]); if (F.Orientation() == TopAbs_REVERSED) - triangles(i).Get(n[0],n[2],n[1]); + T->Triangle (i).Get(n[0],n[2],n[1]); else - triangles(i).Get(n[0],n[1],n[2]); - const gp_Pnt& P1 = Nodes(n[0]); - const gp_Pnt& P2 = Nodes(n[1]); - const gp_Pnt& P3 = Nodes(n[2]); + T->Triangle (i).Get(n[0],n[1],n[2]); + const gp_Pnt& P1 = T->Node (n[0]); + const gp_Pnt& P2 = T->Node (n[1]); + const gp_Pnt& P3 = T->Node (n[2]); gp_Vec V1(P1,P2); if (V1.SquareMagnitude() > 1.e-10) { gp_Vec V2(P2,P3); @@ -390,10 +384,9 @@ void VrmlConverter_ShadedShape::ComputeNormal(const TopoDS_Face& aFace, CSLib_DerivativeStatus Status; CSLib_NormalStatus NStat; S.Initialize(aFace); - const TColgp_Array1OfPnt2d& UVNodes = T->UVNodes(); - for (i = UVNodes.Lower(); i <= UVNodes.Upper(); i++) { - U = UVNodes(i).X(); - V = UVNodes(i).Y(); + for (i = 1; i <= T->NbNodes(); i++) { + U = T->UVNode (i).X(); + V = T->UVNode (i).Y(); S.D1(U,V,P,D1U,D1V); CSLib::Normal(D1U,D1V,Precision::Angular(),Status,Nor(i)); if (Status != CSLib_Done) { @@ -404,16 +397,14 @@ void VrmlConverter_ShadedShape::ComputeNormal(const TopoDS_Face& aFace, } } else { - const TColgp_Array1OfPnt& Nodes = T->Nodes(); Standard_Integer n[3]; - const Poly_Array1OfTriangle& triangles = T->Triangles(); - for (i = Nodes.Lower(); i <= Nodes.Upper(); i++) { + for (i = 1; i <= T->NbNodes(); i++) { gp_XYZ eqPlan(0, 0, 0); for (pc.Initialize(i); pc.More(); pc.Next()) { - triangles(pc.Value()).Get(n[0], n[1], n[2]); - gp_XYZ v1(Nodes(n[1]).Coord()-Nodes(n[0]).Coord()); - gp_XYZ v2(Nodes(n[2]).Coord()-Nodes(n[1]).Coord()); + T->Triangle (pc.Value()).Get(n[0], n[1], n[2]); + gp_XYZ v1(T->Node (n[1]).Coord() - T->Node (n[0]).Coord()); + gp_XYZ v2(T->Node (n[2]).Coord() - T->Node (n[1]).Coord()); eqPlan += (v1^v2).Normalized(); } Nor(i) = gp_Dir(eqPlan); diff --git a/src/VrmlData/VrmlData_IndexedFaceSet.cxx b/src/VrmlData/VrmlData_IndexedFaceSet.cxx index 0e5f8c4fe8..5c48b9e9d7 100644 --- a/src/VrmlData/VrmlData_IndexedFaceSet.cxx +++ b/src/VrmlData/VrmlData_IndexedFaceSet.cxx @@ -133,18 +133,16 @@ const Handle(TopoDS_TShape)& VrmlData_IndexedFaceSet::TShape () myTShape = aFace; // Copy the triangulation vertices - TColgp_Array1OfPnt& aNodes = aTriangulation->ChangeNodes(); NCollection_DataMap ::Iterator anIterN(mapNodeId); for (i = 1; anIterN.More(); anIterN.Next()) { const int aKey = anIterN.Key(); const gp_XYZ& aNodePnt = arrNodes[aKey]; - aNodes(i) = gp_Pnt (aNodePnt); + aTriangulation->ChangeNode (i) = gp_Pnt (aNodePnt); anIterN.ChangeValue() = i++; } // Copy the triangles. Only the triangle-type polygons are supported. // In this loop we also get rid of any possible degenerated triangles. - Poly_Array1OfTriangle& aTriangles = aTriangulation->ChangeTriangles(); nTri = 0; for (i = 0; i < (int)myNbPolygons; i++) { const Standard_Integer * arrIndice; @@ -153,9 +151,9 @@ const Handle(TopoDS_TShape)& VrmlData_IndexedFaceSet::TShape () arrIndice[0] < nNodes && arrIndice[1] < nNodes && arrIndice[2] < nNodes) // check to avoid previously skipped faces - aTriangles(++nTri).Set (mapNodeId(arrIndice[0]), - mapNodeId(arrIndice[1]), - mapNodeId(arrIndice[2])); + aTriangulation->ChangeTriangle (++nTri).Set (mapNodeId(arrIndice[0]), + mapNodeId(arrIndice[1]), + mapNodeId(arrIndice[2])); } // Normals should be defined; if they are not, compute them diff --git a/src/VrmlData/VrmlData_ShapeConvert.cxx b/src/VrmlData/VrmlData_ShapeConvert.cxx index 0f29c5462b..8472a0f980 100644 --- a/src/VrmlData/VrmlData_ShapeConvert.cxx +++ b/src/VrmlData/VrmlData_ShapeConvert.cxx @@ -309,8 +309,6 @@ Handle(VrmlData_Geometry) VrmlData_ShapeConvert::triToIndexedFaceSet Standard_Integer i; const Standard_Integer nNodes (theTri->NbNodes()); const Standard_Integer nTriangles (theTri->NbTriangles()); - const TColgp_Array1OfPnt& arrPolyNodes = theTri->Nodes(); - const Poly_Array1OfTriangle& arrTriangles = theTri->Triangles(); const Handle(VrmlData_IndexedFaceSet) aFaceSet = new VrmlData_IndexedFaceSet (myScene, @@ -331,7 +329,7 @@ Handle(VrmlData_Geometry) VrmlData_ShapeConvert::triToIndexedFaceSet Standard_Integer * aPolygon = static_cast (anAlloc->Allocate (4*sizeof(Standard_Integer))); aPolygon[0] = 3; - arrTriangles(i+1).Get (aPolygon[1],aPolygon[2],aPolygon[3]); + theTri->Triangle (i+1).Get (aPolygon[1],aPolygon[2],aPolygon[3]); aPolygon[1]--; if (isReverse) { const Standard_Integer aTmp = aPolygon[2]-1; @@ -351,7 +349,7 @@ Handle(VrmlData_Geometry) VrmlData_ShapeConvert::triToIndexedFaceSet gp_XYZ * arrNodes = static_cast (anAlloc->Allocate (nNodes * sizeof(gp_XYZ))); for (i = 0; i < nNodes; i++) - arrNodes[i] = arrPolyNodes(i+1).XYZ() * myScale; + arrNodes[i] = theTri->Node (i+1).XYZ() * myScale; const Handle(VrmlData_Coordinate) aCoordNode = new VrmlData_Coordinate (myScene, 0L, nNodes, arrNodes); @@ -363,13 +361,9 @@ Handle(VrmlData_Geometry) VrmlData_ShapeConvert::triToIndexedFaceSet if(theTri->HasNormals()) { gp_XYZ * arrVec = static_cast (anAlloc->Allocate (nNodes * sizeof(gp_XYZ))); - const TShort_Array1OfShortReal& Norm = theTri->Normals(); - Standard_Integer j; - for (i = 0, j = 1; i < nNodes; i++, j += 3) { - - gp_XYZ aNormal(Norm(j), Norm(j+1), Norm(j+2)); - arrVec[i] = aNormal; - + for (i = 0; i < nNodes; i++) + { + arrVec[i] = theTri->Normal (i + 1).XYZ(); } const Handle(VrmlData_Normal) aNormalNode = new VrmlData_Normal (myScene, 0L, nNodes, arrVec); @@ -390,14 +384,13 @@ Handle(VrmlData_Geometry) VrmlData_ShapeConvert::triToIndexedFaceSet Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, nbNormVal); - const TColgp_Array1OfPnt2d& arrUV = theTri->UVNodes(); gp_XYZ * arrVec = static_cast (anAlloc->Allocate (nNodes * sizeof(gp_XYZ))); // Compute the normal vectors Standard_Real Tol = Sqrt(aConf2); for (i = 0; i < nNodes; i++) { - const gp_Pnt2d& aUV = arrUV(i+1); + const gp_Pnt2d& aUV = theTri->UVNode (i+1); gp_Dir aNormal; @@ -407,9 +400,9 @@ Handle(VrmlData_Geometry) VrmlData_ShapeConvert::triToIndexedFaceSet gp_XYZ eqPlan(0., 0., 0.); for (PC.Initialize(i+1); PC.More(); PC.Next()) { - arrTriangles(PC.Value()).Get(n[0], n[1], n[2]); - gp_XYZ v1(arrPolyNodes(n[1]).Coord()-arrPolyNodes(n[0]).Coord()); - gp_XYZ v2(arrPolyNodes(n[2]).Coord()-arrPolyNodes(n[1]).Coord()); + theTri->Triangle (PC.Value()).Get(n[0], n[1], n[2]); + gp_XYZ v1(theTri->Node (n[1]).Coord() - theTri->Node (n[0]).Coord()); + gp_XYZ v2(theTri->Node (n[2]).Coord() - theTri->Node (n[1]).Coord()); gp_XYZ vv = v1^v2; Standard_Real mod = vv.Modulus(); diff --git a/src/XDEDRAW/XDEDRAW_Props.cxx b/src/XDEDRAW/XDEDRAW_Props.cxx index 64c818cea6..9236243759 100644 --- a/src/XDEDRAW/XDEDRAW_Props.cxx +++ b/src/XDEDRAW/XDEDRAW_Props.cxx @@ -146,24 +146,20 @@ static Standard_Real CalculVolume(const TopoDS_Shape& So, facing = BRep_Tool::Triangulation(F,L); } - TColgp_Array1OfPnt tab(1,(facing->NbNodes())); - tab = facing->Nodes(); - Poly_Array1OfTriangle tri(1,facing->NbTriangles()); - tri = facing->Triangles(); for (Standard_Integer i=1;i<=(facing->NbTriangles());i++) { - Poly_Triangle trian = tri.Value(i); + Poly_Triangle trian = facing->Triangle (i); Standard_Integer index1,index2,index3;//M,N; if( F.Orientation() == TopAbs_REVERSED ) trian.Get(index1,index3,index2); else trian.Get(index1,index2,index3); - curVolume = TetraVol(aRefPoint, tab.Value(index1), - tab.Value(index2), tab.Value(index3)); + curVolume = TetraVol(aRefPoint, facing->Node (index1), + facing->Node (index2), facing->Node (index3)); myVolume += curVolume; - curCentroid = TetraCen(aRefPoint, tab.Value(index1), - tab.Value(index2), tab.Value(index3)); + curCentroid = TetraCen(aRefPoint, facing->Node (index1), + facing->Node (index2), facing->Node (index3)); localCentroid = localCentroid + curCentroid*curVolume; } diff --git a/src/XmlMDataStd/FILES b/src/XmlMDataStd/FILES index 370f797a4d..b2bf55e06d 100644 --- a/src/XmlMDataStd/FILES +++ b/src/XmlMDataStd/FILES @@ -26,6 +26,8 @@ XmlMDataStd_IntegerListDriver.cxx XmlMDataStd_IntegerListDriver.hxx XmlMDataStd_IntPackedMapDriver.cxx XmlMDataStd_IntPackedMapDriver.hxx +XmlMDataStd_MeshDriver.cxx +XmlMDataStd_MeshDriver.hxx XmlMDataStd_NamedDataDriver.cxx XmlMDataStd_NamedDataDriver.hxx XmlMDataStd_NameDriver.cxx diff --git a/src/XmlMDataStd/XmlMDataStd.cxx b/src/XmlMDataStd/XmlMDataStd.cxx index 8a10e98f0b..0bfd088e3e 100644 --- a/src/XmlMDataStd/XmlMDataStd.cxx +++ b/src/XmlMDataStd/XmlMDataStd.cxx @@ -43,6 +43,7 @@ #include #include #include +#include #include static Standard_Integer myDocumentVersion = -1; @@ -80,6 +81,7 @@ void XmlMDataStd::AddDrivers (const Handle(XmlMDF_ADriverTable)& aDriverTable, aDriverTable-> AddDriver (new XmlMDataStd_NamedDataDriver (anMsgDrv)); aDriverTable-> AddDriver (new XmlMDataStd_AsciiStringDriver (anMsgDrv)); aDriverTable-> AddDriver (new XmlMDataStd_IntPackedMapDriver (anMsgDrv)); + aDriverTable-> AddDriver (new XmlMDataStd_MeshDriver (anMsgDrv)); } //======================================================================= diff --git a/src/XmlMDataStd/XmlMDataStd_MeshDriver.cxx b/src/XmlMDataStd/XmlMDataStd_MeshDriver.cxx new file mode 100644 index 0000000000..eefb03ae81 --- /dev/null +++ b/src/XmlMDataStd/XmlMDataStd_MeshDriver.cxx @@ -0,0 +1,133 @@ +// Created on: 2015-12-15 +// 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 +#include +#include +#include +#include + +IMPLEMENT_STANDARD_RTTIEXT(XmlMDataStd_MeshDriver,XmlMDF_ADriver) +IMPLEMENT_DOMSTRING (MeshString, "mesh") +IMPLEMENT_DOMSTRING (NullString, "null") +IMPLEMENT_DOMSTRING (ExistString, "exists") + +//======================================================================= +//function : XmlMDataStd_MeshDriver +//purpose : Constructor +//======================================================================= +XmlMDataStd_MeshDriver::XmlMDataStd_MeshDriver(const Handle(CDM_MessageDriver)& theMsgDriver) + : XmlMDF_ADriver (theMsgDriver, NULL) +{ + +} + +//======================================================================= +//function : NewEmpty +//purpose : +//======================================================================= +Handle(TDF_Attribute) XmlMDataStd_MeshDriver::NewEmpty() const +{ + return new TDataStd_Mesh(); +} + +//======================================================================= +//function : Paste +//purpose : persistent -> transient (retrieve) +//======================================================================= +Standard_Boolean XmlMDataStd_MeshDriver::Paste(const XmlObjMgt_Persistent& theSource, + const Handle(TDF_Attribute)& theTarget, + XmlObjMgt_RRelocationTable& ) const +{ + const XmlObjMgt_Element& element = theSource; + Handle(TDataStd_Mesh) mesh = Handle(TDataStd_Mesh)::DownCast(theTarget); + + // Read the FirstIndex; if the attribute is absent initialize to 1 + XmlObjMgt_DOMString meshStatus = element.getAttribute(::MeshString()); + if (meshStatus == NULL || + meshStatus.Type() != LDOMBasicString::LDOM_AsciiDoc || + strcmp(meshStatus.GetString(), ::ExistString().GetString())) + { + // No mesh. + return Standard_True; + } + + // Get mesh as a string. + const XmlObjMgt_DOMString& data = XmlObjMgt::GetStringValue(element); + std::stringstream stream(std::string(data.GetString())); + + // Read the mesh. + BRepTools_ShapeSet shapeSet; + TColStd_IndexedMapOfTransient meshes; + shapeSet.ReadMeshes(stream, meshes); + + // Set mesh. + if (!meshes.IsEmpty()) + { + // We expect only one mesh. + Handle(Poly_Mesh) M = Handle(Poly_Mesh)::DownCast(meshes(1)); + if (!M.IsNull()) + mesh->Set(M); + } + + return Standard_True; +} + +//======================================================================= +//function : Paste +//purpose : transient -> persistent (store) +//======================================================================= +void XmlMDataStd_MeshDriver::Paste(const Handle(TDF_Attribute)& theSource, + XmlObjMgt_Persistent& theTarget, + XmlObjMgt_SRelocationTable& ) const +{ + const Handle(TDataStd_Mesh) meshAttr = Handle(TDataStd_Mesh)::DownCast(theSource); + if (meshAttr->Get().IsNull()) + theTarget.Element().setAttribute(::MeshString(), ::NullString()); + else + { + theTarget.Element().setAttribute(::MeshString(), ::ExistString()); + + // Analyse the size of the mesh + // (to allocate properly the string array). + const Handle(Poly_Mesh)& mesh = meshAttr->Get(); + Standard_Integer size = mesh->NbNodes(); + size *= 3; // 3 coordinates for a node + size *= 8; // 8 characters are used to represent a coordinate (double) in XML + size += 4 * 5 * mesh->NbElements(); // space for elements (triangles and quadrangles) + size *= 2; // just in case :-) + if (!size) + size = 1; + + // Allocate a string stream. + LDOM_OSStream stream(size); + + // Write the mesh. + BRepTools_ShapeSet shapeSet; + TColStd_IndexedMapOfTransient meshes; + meshes.Add(mesh); + shapeSet.WriteMeshes(stream, meshes, Standard_True/*compact*/); + stream< +#include + +#include +#include +#include +#include +class CDM_MessageDriver; +class TDF_Attribute; +class XmlObjMgt_Persistent; + +DEFINE_STANDARD_HANDLE(XmlMDataStd_MeshDriver, XmlMDF_ADriver) + +//! TDataStd_Mesh attribute XML Driver. +class XmlMDataStd_MeshDriver : public XmlMDF_ADriver +{ + +public: + + Standard_EXPORT XmlMDataStd_MeshDriver(const Handle(CDM_MessageDriver)& theMessageDriver); + + Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE; + + Standard_EXPORT Standard_Boolean Paste (const XmlObjMgt_Persistent& Source, const Handle(TDF_Attribute)& Target, XmlObjMgt_RRelocationTable& RelocTable) const Standard_OVERRIDE; + + Standard_EXPORT void Paste (const Handle(TDF_Attribute)& Source, XmlObjMgt_Persistent& Target, XmlObjMgt_SRelocationTable& RelocTable) const Standard_OVERRIDE; + + DEFINE_STANDARD_RTTIEXT(XmlMDataStd_MeshDriver,XmlMDF_ADriver) +}; + +#endif // _XmlMDataStd_MeshDriver_HeaderFile diff --git a/tests/caf/basic/N1 b/tests/caf/basic/N1 new file mode 100644 index 0000000000..03b327b75a --- /dev/null +++ b/tests/caf/basic/N1 @@ -0,0 +1,41 @@ +#INTERFACE CAF +# Basic attributes +# +# Testing attribute: TDataStd_Mesh +# +# Testing command: SetMesh +# Testing command: DumpMesh +# + +puts "caf001-N1" + +# Make a sphere and produce triangulation +psphere s 100 +vdisplay s +explode s f + +# Create a XML document +NewDocument D XmlXCAF + +# Set mesh from the spherical face +SetMesh D 0:1 s_1 + +# Print the mesh data +set dump1 [DumpMesh D 0:1] + +# Save document on disk. +SaveAs D "test.xml" + +# Close and open the document again. +Close D +Open test.xml DD + +# Print mesh data +set dump2 [DumpMesh DD 0:1] + +# Check data +if { ${dump1}!=${dump2} } { + puts "TDataStd_Mesh(XML) attribute: Error" + return +} +puts "TDataStd_Mesh(XML) attribute: OK" diff --git a/tests/caf/basic/N2 b/tests/caf/basic/N2 new file mode 100644 index 0000000000..e2e91fa8f1 --- /dev/null +++ b/tests/caf/basic/N2 @@ -0,0 +1,42 @@ +#INTERFACE CAF +# Basic attributes +# +# Testing attribute: TDataStd_Mesh +# +# Testing command: SetMesh +# Testing command: DumpMesh +# Test : Binary file format +# + +puts "caf001-N2" + +# Make a sphere and produce triangulation +psphere s 100 +vdisplay s +explode s f + +# Create a binary document +NewDocument D BinXCAF + +# Set mesh from the spherical face +SetMesh D 0:1 s_1 + +# Print the mesh data +set dump1 [DumpMesh D 0:1] + +# Save document on disk. +SaveAs D "test.xbf" + +# Close and open the document again. +Close D +Open test.xbf DD + +# Print mesh data +set dump2 [DumpMesh DD 0:1] + +# Check data +if { ${dump1}!=${dump2} } { + puts "TDataStd_Mesh(BIN) attribute: Error" + return +} +puts "TDataStd_Mesh(BIN) attribute: OK"