diff --git a/dox/dev_guides/debug/debug.md b/dox/dev_guides/debug/debug.md index de84bfb99a..4a1d423ac3 100644 --- a/dox/dev_guides/debug/debug.md +++ b/dox/dev_guides/debug/debug.md @@ -80,6 +80,16 @@ const char* BRepTools_DumpLoc (void* theShapePtr) Dumps shape or its location to cout. - *theShapePtr* - a pointer to *TopoDS_Shape* variable. +The following function is provided by *TKMesh* toolkit: + +~~~~~ +const char* BRepMesh_Dump (void* theMeshHandlePtr, const char* theFileNameStr) +~~~~~ + +Stores mesh produced in parametric space to BREP file. +- *theMeshHandlePtr* - a pointer to *Handle(BRepMesh_DataStructureOfDelaun)* variable. +- *theFileNameStr* - name of file the mesh sould be stored to. + The following additional function is provided by *TKGeomBase* toolkit: ~~~~~ @@ -119,6 +129,7 @@ For convenience it is possible to define aliases to commands in this window, for >alias saveshape ? ({,,TKBRep}BRepTools_Write) >alias dumpshape ? ({,,TKBRep}BRepTools_Dump) >alias dumploc ? ({,,TKBRep}BRepTools_DumpLoc) +>alias dumpmesh ? ({,,TKMesh}BRepMesh_Dump) >alias dumpgeom ? ({,,TKGeomBase}GeomTools_Dump) ~~~~~ diff --git a/src/BRepMesh/BRepMesh.cdl b/src/BRepMesh/BRepMesh.cdl index 7c55409293..e53dbc9601 100644 --- a/src/BRepMesh/BRepMesh.cdl +++ b/src/BRepMesh/BRepMesh.cdl @@ -44,147 +44,43 @@ uses Standard, SortTools, Plugin - -is enumeration DegreeOfFreedom is - Free, - InVolume, - OnSurface, - OnCurve, - Fixed, - Frontier, - Deleted; - +is + imported DegreeOfFreedom from BRepMesh; imported Status from BRepMesh; - - enumeration FactoryError is - FE_NOERROR, - FE_LIBRARYNOTFOUND, - FE_FUNCTIONNOTFOUND, - FE_CANNOTCREATEALGO - end FactoryError; - - class Vertex; - - class Edge; - - imported Triangle from BRepMesh; - - class ShapeTool; - - class Circ; - - deferred class DiscretRoot; - class DiscretFactory; + imported FactoryError from BRepMesh; + imported Vertex from BRepMesh; + imported Edge from BRepMesh; + imported Triangle from BRepMesh; + imported Circle from BRepMesh; + imported DiscretRoot from BRepMesh; + imported DiscretFactory from BRepMesh; -- pointer PDiscretRoot to DiscretRoot from BRepMesh; - -- + + imported ShapeTool from BRepMesh; + imported Collections from BRepMesh; imported Delaun from BRepMesh; - imported MapOfIntegerInteger from BRepMesh; - imported MapOfInteger from BRepMesh; - imported ListOfInteger from BRepMesh; - imported BaseAllocator from BRepMesh; imported PairOfIndex from BRepMesh; imported CircleInspector from BRepMesh; - imported CellFilter from BRepMesh; imported VertexInspector from BRepMesh; - imported VertexCellFilter from BRepMesh; - imported VectorOfVertex from BRepMesh; imported WireInterferenceChecker from BRepMesh; imported EdgeChecker from BRepMesh; imported FaceChecker from BRepMesh; primitive PluginEntryType; - class ComparatorOfVertexOfDelaun; - class ComparatorOfIndexedVertexOfDelaun; - class SelectorOfDataStructureOfDelaun; - class DataStructureOfDelaun; - class CircleTool; - class VertexTool; - - class Array1OfVertexOfDelaun instantiates Array1 from TCollection - (Vertex from BRepMesh); - - class HArray1OfVertexOfDelaun instantiates HArray1 from TCollection - (Vertex from BRepMesh, Array1OfVertexOfDelaun); - - class HeapSortVertexOfDelaun instantiates HeapSort from SortTools - (Vertex from BRepMesh, Array1OfVertexOfDelaun, - ComparatorOfVertexOfDelaun from BRepMesh); - - class HeapSortIndexedVertexOfDelaun instantiates HeapSort from SortTools - (Integer, Array1OfInteger from TColStd, - ComparatorOfIndexedVertexOfDelaun from BRepMesh); - - class LinkHasherOfDataStructureOfDelaun instantiates MapHasher from TCollection - (Edge from BRepMesh); - class ElemHasherOfDataStructureOfDelaun instantiates MapHasher from TCollection - (Triangle from BRepMesh); - - class DataMapOfIntegerListOfInteger instantiates DataMap from TCollection - (Integer from Standard, ListOfInteger from BRepMesh, MapIntegerHasher from TColStd); - - class IDMapOfLinkOfDataStructureOfDelaun instantiates IndexedDataMap from TCollection - (Edge from BRepMesh, - PairOfIndex from BRepMesh, - LinkHasherOfDataStructureOfDelaun); - - class IMapOfElementOfDataStructureOfDelaun instantiates IndexedMap from TCollection - (Triangle from BRepMesh, - ElemHasherOfDataStructureOfDelaun); - - class DataMapOfVertexInteger instantiates DataMap from TCollection - (Vertex from TopoDS, Integer from Standard, ShapeMapHasher from TopTools); - - class ListOfVertex instantiates List from TCollection - (Vertex from BRepMesh); - - class ListOfXY instantiates List from TCollection (XY from gp); - - class DataMapOfIntegerListOfXY instantiates DataMap from TCollection - (Integer from Standard, ListOfXY from BRepMesh, MapIntegerHasher from TColStd); - - - class VertexHasher instantiates MapHasher from TCollection(Vertex from BRepMesh); - - class IndexedMapOfVertex instantiates IndexedMap from TCollection - (Vertex from BRepMesh, VertexHasher from BRepMesh); - - private class FastDiscretFace; - - class FastDiscret; - - class FaceAttribute; - - class DataMapOfFaceAttribute instantiates DataMap from TCollection - (Face from TopoDS, - FaceAttribute from BRepMesh, - ShapeMapHasher from TopTools); - + imported SelectorOfDataStructureOfDelaun from BRepMesh; + imported DataStructureOfDelaun from BRepMesh; + imported CircleTool from BRepMesh; + imported VertexTool from BRepMesh; + imported BiPoint from BRepMesh; + imported FastDiscretFace from BRepMesh; + imported FastDiscret from BRepMesh; + imported FaceAttribute from BRepMesh; imported Classifier from BRepMesh; - imported ClassifierPtr; -- smart pointer on Classifier imported WireChecker from BRepMesh; - imported IncrementalMesh from BRepMesh; + imported GeomTool from BRepMesh; + imported PairOfPolygon from BRepMesh; - - ---- classes moved from MeshShape - class GeomTool; - - class DataMapOfIntegerPnt instantiates - DataMap from TCollection (Integer from Standard, - Pnt from gp, - MapIntegerHasher from TColStd); - - class PairOfPolygon; - - class DataMapOfShapePairOfPolygon instantiates - DataMap from TCollection(Shape from TopoDS, - PairOfPolygon from BRepMesh, - ShapeMapHasher from TopTools); - - Mesh(S: Shape from TopoDS; d: Real from Standard); - ---Purpose: call to incremental mesh. - - end BRepMesh; diff --git a/src/BRepMesh/BRepMesh.cxx b/src/BRepMesh/BRepMesh.cxx deleted file mode 100644 index 3013a4148c..0000000000 --- a/src/BRepMesh/BRepMesh.cxx +++ /dev/null @@ -1,27 +0,0 @@ -// Created on: 1996-08-07 -// Created by: Laurent PAINNOT -// Copyright (c) 1996-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. - -#include -#include -#include - - -void BRepMesh::Mesh(const TopoDS_Shape& S, - const Standard_Real d) -{ - BRepMesh_IncrementalMesh M(S, d); - -} diff --git a/src/BRepMesh/BRepMesh_CellFilter.hxx b/src/BRepMesh/BRepMesh_CellFilter.hxx deleted file mode 100644 index 82f1211da5..0000000000 --- a/src/BRepMesh/BRepMesh_CellFilter.hxx +++ /dev/null @@ -1,21 +0,0 @@ -// Created on: 2008-05-26 -// Created by: Ekaterina SMIRNOVA -// Copyright (c) 2008-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. - -#include -#include -#include -#include - -typedef NCollection_CellFilter BRepMesh_CellFilter; diff --git a/src/BRepMesh/BRepMesh_Circ.cdl b/src/BRepMesh/BRepMesh_Circ.cdl deleted file mode 100644 index fb48225879..0000000000 --- a/src/BRepMesh/BRepMesh_Circ.cdl +++ /dev/null @@ -1,54 +0,0 @@ --- Created on: 1993-08-09 --- Created by: Didier PIFFAULT --- Copyright (c) 1993-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. - -class Circ from BRepMesh - - ---Purpose: Describes a 2d circle with a size of only 3 - -- Standard Real numbers instead of gp who needs 7 - -- Standard Real numbers. - - uses Real from Standard, - XY from gp - - - is Create returns Circ from BRepMesh; - - Create (loc : XY from gp; rad : Real from Standard) - returns Circ from BRepMesh; - - SetLocation(me : in out; loc : XY from gp) - is static; - - SetRadius (me : in out; rad : Real from Standard) - is static; - - Location (me) - ---C++: return const & - ---C++: inline - returns XY from gp - is static; - - Radius (me) - ---C++: return const & - ---C++: inline - returns Real from Standard - is static; - - -fields location : XY from gp; - radius : Real from Standard; - -end Circ; diff --git a/src/BRepMesh/BRepMesh_Circ.cxx b/src/BRepMesh/BRepMesh_Circ.cxx deleted file mode 100644 index 96a185ba93..0000000000 --- a/src/BRepMesh/BRepMesh_Circ.cxx +++ /dev/null @@ -1,34 +0,0 @@ -// Created on: 1993-08-09 -// Created by: Didier PIFFAULT -// Copyright (c) 1993-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. - -#include - -BRepMesh_Circ::BRepMesh_Circ() -{} - -BRepMesh_Circ::BRepMesh_Circ(const gp_XY& loc, const Standard_Real rad) -: location(loc), radius(rad) -{} - -void BRepMesh_Circ::SetLocation(const gp_XY& loc) -{ - location=loc; -} - -void BRepMesh_Circ::SetRadius(const Standard_Real rad) -{ - radius=rad; -} diff --git a/src/BRepMesh/BRepMesh_Circ.lxx b/src/BRepMesh/BRepMesh_Circ.lxx deleted file mode 100644 index 07cab56ae1..0000000000 --- a/src/BRepMesh/BRepMesh_Circ.lxx +++ /dev/null @@ -1,21 +0,0 @@ -// Created on: 1993-08-09 -// Created by: Didier PIFFAULT -// Copyright (c) 1993-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. - -inline const gp_XY& BRepMesh_Circ::Location() const -{ return location;} - -inline const Standard_Real& BRepMesh_Circ::Radius() const -{ return radius;} diff --git a/src/BRepMesh/BRepMesh_Circle.hxx b/src/BRepMesh/BRepMesh_Circle.hxx new file mode 100644 index 0000000000..3f8f41952e --- /dev/null +++ b/src/BRepMesh/BRepMesh_Circle.hxx @@ -0,0 +1,77 @@ +// Copyright (c) 2013 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 _BRepMesh_Circle_HeaderFile +#define _BRepMesh_Circle_HeaderFile + +#include +#include +#include +#include + +//! Describes a 2d circle with a size of only 3 Standard_Real +//! numbers instead of gp who needs 7 Standard_Real numbers. +class BRepMesh_Circle +{ +public: + + DEFINE_STANDARD_ALLOC + + //! Default constructor. + Standard_EXPORT BRepMesh_Circle() + { + } + + //! Constructor. + //! \param theLocation location of a circle. + //! \param theRadius radius of a circle. + Standard_EXPORT BRepMesh_Circle(const gp_XY& theLocation, + const Standard_Real theRadius) + : myLocation(theLocation), + myRadius (theRadius) + { + } + + //! Sets location of a circle. + //! \param theLocation location of a circle. + inline void SetLocation(const gp_XY& theLocation) + { + myLocation = theLocation; + } + + //! Sets radius of a circle. + //! \param theRadius radius of a circle. + inline void SetRadius(const Standard_Real theRadius) + { + myRadius = theRadius; + } + + //! Returns location of a circle. + inline const gp_XY& Location() const + { + return myLocation; + } + + //! Returns radius of a circle. + inline const Standard_Real& Radius() const + { + return myRadius; + } + +private: + + gp_XY myLocation; + Standard_Real myRadius; +}; + +#endif diff --git a/src/BRepMesh/BRepMesh_CircleInspector.hxx b/src/BRepMesh/BRepMesh_CircleInspector.hxx index 5ae64ad843..311dfe7e2c 100644 --- a/src/BRepMesh/BRepMesh_CircleInspector.hxx +++ b/src/BRepMesh/BRepMesh_CircleInspector.hxx @@ -16,78 +16,89 @@ #ifndef BRepMesh_CircleInspector_Header #define BRepMesh_CircleInspector_Header -#include - -#include +#include +#include #include #include #include - #include -#include - -typedef NCollection_Vector CircVector; - -//======================================================================= -//! The class to find in the coincidence points -//======================================================================= +//! Auxilary class to find circles shot by the given point. class BRepMesh_CircleInspector : public NCollection_CellFilter_InspectorXY { public: typedef Standard_Integer Target; - //! Constructor; remembers tolerance and collector data structure. - //! All the found points are put in the map and excluded from further - //! consideration. - BRepMesh_CircleInspector (Standard_Real theTol, - Standard_Integer nbComp, - const BRepMesh_BaseAllocator& theAlloc); - void Add(Standard_Integer theInd,const BRepMesh_Circ& theCircle) + //! Constructor. + //! \param theTolerance tolerance to be used for identification of shot circles. + //! \param theReservedSize size to be reserved for vector of circles. + //! \param theAllocator memory allocator to be used by internal collections. + Standard_EXPORT BRepMesh_CircleInspector( + const Standard_Real theTolerance, + const Standard_Integer theReservedSize, + const BRepMeshCol::Allocator& theAllocator) + : myTolerance(theTolerance*theTolerance), + myResIndices(theAllocator), + myCircles(theReservedSize) { - myInitCircle.SetValue(theInd, theCircle); } - void ClerResList() + //! Adds the circle to vector of circles at the given position. + //! \param theIndex position of circle in the vector. + //! \param theCircle circle to be added. + inline void Bind(const Standard_Integer theIndex, + const BRepMesh_Circle& theCircle) { - myResInd.Clear(); + myCircles.SetValue(theIndex, theCircle); } - CircVector& MapOfCirc() + //! Resutns vector of registered circles. + inline BRepMeshCol::VectorOfCircle& Circles() { - return myInitCircle; + return myCircles; } - BRepMesh_Circ& GetCirc(Standard_Integer theInd) + //! Returns circle with the given index. + //! \param theIndex index of circle. + //! \return circle with the given index. + inline BRepMesh_Circle& Circle(const Standard_Integer theIndex) { - return myInitCircle(theInd); + return myCircles(theIndex); } - //! Set current node to be checked - void SetCurrent (const gp_XY& theCurCircle) - { - myCurrent = theCurCircle; + //! Set reference point to be checked. + //! \param thePoint bullet point. + inline void SetPoint(const gp_XY& thePoint) + { + myResIndices.Clear(); + myPoint = thePoint; } - //!Get result index of node - BRepMesh_ListOfInteger& GetCoincidentInd() + //! Returns list of circles shot by the reference point. + inline BRepMeshCol::ListOfInteger& GetShotCircles() { - return myResInd; + return myResIndices; } - //! Implementation of inspection method - NCollection_CellFilter_Action Inspect (const Standard_Integer theTarget); + //! Performs inspection of a circle with the given index. + //! \param theTargetIndex index of a circle to be checked. + //! \return status of the check. + Standard_EXPORT NCollection_CellFilter_Action Inspect( + const Standard_Integer theTargetIndex); - static Standard_Boolean IsEqual (Standard_Integer theIdx, const Standard_Integer theTarget) + //! Checks indices for equlity. + Standard_EXPORT static Standard_Boolean IsEqual( + const Standard_Integer theIndex, + const Standard_Integer theTargetIndex) { - return (theIdx == theTarget); + return (theIndex == theTargetIndex); } private: - Standard_Real myTol; - BRepMesh_ListOfInteger myResInd; - CircVector myInitCircle; - gp_XY myCurrent; + Standard_Real myTolerance; + BRepMeshCol::ListOfInteger myResIndices; + BRepMeshCol::VectorOfCircle myCircles; + gp_XY myPoint; }; #endif diff --git a/src/BRepMesh/BRepMesh_CircleTool.cdl b/src/BRepMesh/BRepMesh_CircleTool.cdl deleted file mode 100644 index 27b25e9fe8..0000000000 --- a/src/BRepMesh/BRepMesh_CircleTool.cdl +++ /dev/null @@ -1,102 +0,0 @@ --- Created on: 1993-05-12 --- Created by: Didier PIFFAULT --- Copyright (c) 1993-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. - -class CircleTool from BRepMesh - - ---Purpose: Create sort and destroy the circles used in - -- triangulation. - - uses Boolean from Standard, - Integer from Standard, - Real from Standard, - XY from gp, - Circ2d from gp, - ListOfInteger from BRepMesh, - CellFilter from BRepMesh, - CircleInspector from BRepMesh, - BaseAllocator from BRepMesh - - is Create (theAlloc : in BaseAllocator from BRepMesh) - returns CircleTool from BRepMesh; - - - Create (numberOfComponents : in Integer from Standard; - theAlloc : in BaseAllocator from BRepMesh) - ---Purpose: Constructs a CircleTool with the maximal dimension - -- of the occuped space and an evaluation of the - -- number of circles. - returns CircleTool from BRepMesh; - - Initialize (me : in out; - numberOfComponents : in Integer from Standard) - ---Purpose: Constructs a CircleTool with the maximal dimension - -- of the occuped space and an evaluation of the - -- number of circles. - is static; - - SetCellSize(me : in out; - theSize : in Real from Standard) - ---Purpose: Sets new size for cellfilter - is static; - - SetCellSize(me : in out; - theXSize : in Real from Standard; - theYSize : in Real from Standard) - ---Purpose: Sets new size for cellfilter - is static; - - SetMinMaxSize(me : in out; - theMin : in XY from gp; - theMax : in XY from gp) - ---Purpose: Sets min and max size for circle - is static; - - Add (me : in out; - theCirc : in Circ2d from gp; - theIndex : in Integer from Standard) - ---Purpose: Adds and binds circle to the tool. - is static; - - - Add (me : in out; - p1, p2, p3 : in XY from gp; - theIndex : in Integer from Standard) - ---Purpose: Computes adds and binds circle to the tool. - returns Boolean from Standard is static; - - MocAdd (me : in out; - theIndex : in Integer from Standard); - ---Purpose: Adds implicit zero circle - - - Delete (me : in out; theIndex : Integer from Standard) - ---Purpose: Deletes a circle from the tool. - is static; - - - Select (me : in out; thePnt : XY from gp) - ---Purpose: Select the circles which contains thePnt. - ---C++: return & - returns ListOfInteger from BRepMesh is static; - - fields Tolerance : Real from Standard; - Allocator : BaseAllocator from BRepMesh; - CellFilter : CellFilter from BRepMesh; - Selector : CircleInspector from BRepMesh; - FaceMax : XY from gp; - FaceMin : XY from gp; - -end CircleTool; diff --git a/src/BRepMesh/BRepMesh_CircleTool.cxx b/src/BRepMesh/BRepMesh_CircleTool.cxx index cf2c15aa70..3b106971f4 100644 --- a/src/BRepMesh/BRepMesh_CircleTool.cxx +++ b/src/BRepMesh/BRepMesh_CircleTool.cxx @@ -14,46 +14,30 @@ // 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 - - -//======================================================================= -//function : BRepMesh_CircleInspector -//purpose : Constructor -//======================================================================= - -BRepMesh_CircleInspector::BRepMesh_CircleInspector (Standard_Real theTol, - Standard_Integer nbComp, - const BRepMesh_BaseAllocator& theAlloc) - : myTol(theTol*theTol), - myResInd(theAlloc), - myInitCircle(nbComp) -{ - // myTol = theTol*theTol; -} //======================================================================= //function : Inspect //purpose : -// //======================================================================= -NCollection_CellFilter_Action BRepMesh_CircleInspector::Inspect (const Standard_Integer theTarget) +NCollection_CellFilter_Action BRepMesh_CircleInspector::Inspect( + const Standard_Integer theTargetIndex) { - const BRepMesh_Circ& Circ = myInitCircle(theTarget); - Standard_Real R = Circ.Radius(); - if(R < 0) + const BRepMesh_Circle& aCircle = myCircles(theTargetIndex); + Standard_Real aRadius = aCircle.Radius(); + if(aRadius < 0.) return CellFilter_Purge; - Standard_Real dx,dy; - const gp_XY& aLoc=Circ.Location(); - dx=myCurrent.X()-aLoc.X(); - dy=myCurrent.Y()-aLoc.Y(); - if ((dx*dx+dy*dy)-(R*R) <= myTol) - myResInd.Append(theTarget); + + const gp_XY& aLoc = aCircle.Location(); + + if ((myPoint - aLoc).SquareModulus() - (aRadius * aRadius) <= myTolerance) + myResIndices.Append(theTargetIndex); + return CellFilter_Keep; } @@ -62,188 +46,106 @@ NCollection_CellFilter_Action BRepMesh_CircleInspector::Inspect (const Standard_ //function : BRepMesh_CircleTool //purpose : //======================================================================= -BRepMesh_CircleTool::BRepMesh_CircleTool(const BRepMesh_BaseAllocator& theAlloc) -: Tolerance(Precision::PConfusion()), -Allocator(theAlloc), -CellFilter(10, theAlloc), -Selector(Tolerance,64,theAlloc) +BRepMesh_CircleTool::BRepMesh_CircleTool( + const BRepMeshCol::Allocator& theAllocator) +: myTolerance (Precision::PConfusion() * Precision::PConfusion()), + myAllocator (theAllocator), + myCellFilter(10, theAllocator), + mySelector (myTolerance, 64, theAllocator) { - Tolerance=Tolerance*Tolerance; } //======================================================================= //function : BRepMesh_CircleTool //purpose : //======================================================================= -BRepMesh_CircleTool::BRepMesh_CircleTool(const Standard_Integer nbComp, - const BRepMesh_BaseAllocator& theAlloc) - : Tolerance(Precision::PConfusion()), - Allocator(theAlloc), - CellFilter(10, theAlloc), - Selector(Tolerance,Max(nbComp,64),theAlloc) +BRepMesh_CircleTool::BRepMesh_CircleTool( + const Standard_Integer theReservedSize, + const BRepMeshCol::Allocator& theAllocator) +: myTolerance (Precision::PConfusion() * Precision::PConfusion()), + myAllocator (theAllocator), + myCellFilter(10, theAllocator), + mySelector (myTolerance, Max(theReservedSize, 64), theAllocator) { - Tolerance=Tolerance*Tolerance; } - //======================================================================= -//function : Initialize +//function : bind //purpose : //======================================================================= -void BRepMesh_CircleTool::Initialize(const Standard_Integer /*nbComp*/) +void BRepMesh_CircleTool::bind(const Standard_Integer theIndex, + const gp_XY& theLocation, + const Standard_Real theRadius) { - Tolerance=Precision::PConfusion(); - Tolerance=Tolerance*Tolerance; -} - -void BRepMesh_CircleTool::SetCellSize(const Standard_Real theSize) -{ - CellFilter.Reset(theSize, Allocator); -} - -void BRepMesh_CircleTool::SetCellSize(const Standard_Real theXSize, - const Standard_Real theYSize) -{ - Standard_Real aCellSize[2]; - aCellSize[0] = theXSize; - aCellSize[1] = theYSize; - - CellFilter.Reset(aCellSize, Allocator); -} - - -void BRepMesh_CircleTool::SetMinMaxSize(const gp_XY& theMin, - const gp_XY& theMax) -{ - FaceMin = theMin; - FaceMax = theMax; -} - -//======================================================================= -//function : Add -//purpose : -//======================================================================= -void BRepMesh_CircleTool::Add(const gp_Circ2d& theCirc, - const Standard_Integer theIndex) -{ - gp_XY aCoord(theCirc.Location().Coord()); - Standard_Real R = theCirc.Radius(); - BRepMesh_Circ aCir(aCoord, R); + BRepMesh_Circle aCirle(theLocation, theRadius); //compute coords - Standard_Real xMax=Min(aCoord.X()+R,FaceMax.X()); - Standard_Real xMin=Max(aCoord.X()-R,FaceMin.X()); - Standard_Real yMax=Min(aCoord.Y()+R,FaceMax.Y()); - Standard_Real yMin=Max(aCoord.Y()-R,FaceMin.Y()); + Standard_Real aMaxX = Min(theLocation.X() + theRadius, myFaceMax.X()); + Standard_Real aMinX = Max(theLocation.X() - theRadius, myFaceMin.X()); + Standard_Real aMaxY = Min(theLocation.Y() + theRadius, myFaceMax.Y()); + Standard_Real aMinY = Max(theLocation.Y() - theRadius, myFaceMin.Y()); - gp_XY MinPnt(xMin,yMin); - gp_XY MaxPnt(xMax,yMax); + gp_XY aMinPnt(aMinX, aMinY); + gp_XY aMaxPnt(aMaxX, aMaxY); - CellFilter.Add(theIndex, MinPnt, MaxPnt); - Selector.Add(theIndex, aCir); + myCellFilter.Add(theIndex, aMinPnt, aMaxPnt); + mySelector.Bind(theIndex, aCirle); } //======================================================================= -//function : Add +//function : Bind //purpose : //======================================================================= -Standard_Boolean BRepMesh_CircleTool::Add(const gp_XY& p1, - const gp_XY& p2, - const gp_XY& p3, - const Standard_Integer theIndex) +void BRepMesh_CircleTool::Bind(const Standard_Integer theIndex, + const gp_Circ2d& theCircle) { - gp_XY m1((p1.X()+p2.X())/2., (p1.Y()+p2.Y())/2.); - gp_XY m2((p2.X()+p3.X())/2., (p2.Y()+p3.Y())/2.); - gp_XY m3((p3.X()+p1.X())/2., (p3.Y()+p1.Y())/2.); - Standard_Real dx=m1.X()-m2.X(); - Standard_Real dy=m1.Y()-m2.Y(); - Standard_Real d12=(dx*dx)+(dy*dy); - dx=m2.X()-m3.X(); - dy=m2.Y()-m3.Y(); - Standard_Real d23=(dx*dx)+(dy*dy); - dx=m3.X()-m1.X(); - dy=m3.Y()-m1.Y(); - Standard_Real d31=(dx*dx)+(dy*dy); - gp_XY pl11, pl12, pl21, pl22; + gp_XY aCoord = theCircle.Location().Coord(); + Standard_Real aRadius = theCircle.Radius(); + bind(theIndex, aCoord, aRadius); +} - if (d12>d23 && d12>d31) { - dy=p2.Y()-p1.Y(); - dx=p1.X()-p2.X(); - if (dy!=0. || dx!=0.) { - pl11 = m1; - pl12 = gp_XY(dy, dx); - } - else return Standard_False; +//======================================================================= +//function : Bind +//purpose : +//======================================================================= +Standard_Boolean BRepMesh_CircleTool::Bind(const Standard_Integer theIndex, + const gp_XY& thePoint1, + const gp_XY& thePoint2, + const gp_XY& thePoint3) +{ + const Standard_Real aPrecision = Precision::PConfusion(); + const Standard_Real aSqPrecision = aPrecision * aPrecision; - dy=p3.Y()-p2.Y(); - dx=p2.X()-p3.X(); - if (dy!=0. || dx!=0.) { - pl21 = m2; - pl22 = gp_XY(dy, dx); - } - else return Standard_False; - } - else { - if (d23>d31) { - dy=p3.Y()-p2.Y(); - dx=p2.X()-p3.X(); - if (dy!=0. || dx!=0.) { - pl11 = m2; - pl12 = gp_XY(dy, dx); - } - else return Standard_False; + const gp_XY aPoints[3] = { thePoint1, thePoint2, thePoint3 }; - dy=p1.Y()-p3.Y(); - dx=p3.X()-p1.X(); - if (dy!=0. || dx!=0.) { - pl21 = m3; - pl22 = gp_XY(dy, dx); - } - else return Standard_False; - } - else { - dy=p1.Y()-p3.Y(); - dx=p3.X()-p1.X(); - if (dy!=0. || dx!=0.) { - pl11 = m3; - pl12 = gp_XY(dy, dx); - } - else return Standard_False; + gp_XY aNorm[3]; + gp_XY aMidPnt[3]; + for (Standard_Integer i = 0; i < 3; ++i) + { + const gp_XY& aPnt1 = aPoints[i]; + const gp_XY& aPnt2 = aPoints[(i + 1) % 3]; - dy=p2.Y()-p1.Y(); - dx=p1.X()-p2.X(); - if (dy!=0. || dx!=0.) { - pl21 = m1; - pl22 = gp_XY(dy, dx); - } - else return Standard_False; - } + aMidPnt[i] = (aPnt1 + aPnt2) / 2.; + + gp_XY aLink(aPnt2 - aPnt1); + if (aLink.SquareModulus() < aSqPrecision) + return Standard_False; + + aNorm[i] = gp_XY(aLink.Y(), -aLink.X()); + aNorm[i].Add(aMidPnt[i]); } - gp_XY aVecO1O2 = pl21 - pl11; - Standard_Real aCrossD1D2 = pl12 ^ pl22; - Standard_Real theSinAngle = Abs(aCrossD1D2); - if (theSinAngle < gp::Resolution()) + gp_XY aIntPnt; + Standard_Real aParam[2]; + BRepMesh_GeomTool::IntFlag aIntFlag = + BRepMesh_GeomTool::IntLinLin(aMidPnt[0], aNorm[0], + aMidPnt[1], aNorm[1], aIntPnt, aParam); + + if (aIntFlag != BRepMesh_GeomTool::Cross) return Standard_False; - Standard_Real theParam1 = (aVecO1O2 ^ pl22) / aCrossD1D2; - gp_XY pInt = pl11+pl12*theParam1; - dx=p1.X()-pInt.X(); - dy=p1.Y()-pInt.Y(); - Standard_Real R = Sqrt(dx*dx+dy*dy); - BRepMesh_Circ aCir(pInt, R); - //compute coords - Standard_Real xMax=Min(pInt.X()+R,FaceMax.X()); - Standard_Real xMin=Max(pInt.X()-R,FaceMin.X()); - Standard_Real yMax=Min(pInt.Y()+R,FaceMax.Y()); - Standard_Real yMin=Max(pInt.Y()-R,FaceMin.Y()); - - gp_XY MinPnt(xMin,yMin); - gp_XY MaxPnt(xMax,yMax); - - CellFilter.Add(theIndex, MinPnt, MaxPnt); - - Selector.Add(theIndex, aCir); + Standard_Real aRadius = (aPoints[0] - aIntPnt).Modulus(); + bind(theIndex, aIntPnt, aRadius); return Standard_True; } @@ -251,29 +153,30 @@ Standard_Boolean BRepMesh_CircleTool::Add(const gp_XY& p1, //function : Delete //purpose : //======================================================================= -void BRepMesh_CircleTool::Delete(const Standard_Integer theIndex) +void BRepMesh_CircleTool::Delete(const Standard_Integer theIndex) { - BRepMesh_Circ& Circ = Selector.GetCirc(theIndex); - if(Circ.Radius() > 0.) { - Circ.SetRadius(-1); - } + BRepMesh_Circle& aCircle = mySelector.Circle(theIndex); + if(aCircle.Radius() > 0.) + aCircle.SetRadius(-1); } //======================================================================= //function : Select //purpose : //======================================================================= -BRepMesh_ListOfInteger& BRepMesh_CircleTool::Select(const gp_XY& thePnt) +BRepMeshCol::ListOfInteger& BRepMesh_CircleTool::Select(const gp_XY& thePoint) { - Selector.ClerResList(); - Selector.SetCurrent(thePnt); - CellFilter.Inspect (thePnt, Selector); - return Selector.GetCoincidentInd(); + mySelector.SetPoint(thePoint); + myCellFilter.Inspect(thePoint, mySelector); + return mySelector.GetShotCircles(); } -void BRepMesh_CircleTool::MocAdd(const Standard_Integer theIndex) +//======================================================================= +//function : MocBind +//purpose : +//======================================================================= +void BRepMesh_CircleTool::MocBind(const Standard_Integer theIndex) { - gp_XY nullPnt(0.,0.); - BRepMesh_Circ theNullCir(nullPnt, -1.); - Selector.Add(theIndex, theNullCir); + BRepMesh_Circle aNullCir(gp::Origin2d().Coord(), -1.); + mySelector.Bind(theIndex, aNullCir); } diff --git a/src/BRepMesh/BRepMesh_CircleTool.hxx b/src/BRepMesh/BRepMesh_CircleTool.hxx new file mode 100644 index 0000000000..11433d1548 --- /dev/null +++ b/src/BRepMesh/BRepMesh_CircleTool.hxx @@ -0,0 +1,132 @@ +// Copyright (c) 2013 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 _BRepMesh_CircleTool_HeaderFile +#define _BRepMesh_CircleTool_HeaderFile + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +class gp_Circ2d; + +//! Create sort and destroy the circles used in triangulation.
+class BRepMesh_CircleTool +{ +public: + + DEFINE_STANDARD_ALLOC + + //! Constructor. + //! \param theAllocator memory allocator to be used by internal structures. + Standard_EXPORT BRepMesh_CircleTool(const BRepMeshCol::Allocator& theAllocator); + + //! Constructor. + //! \param theReservedSize size to be reserved for vector of circles. + //! \param theAllocator memory allocator to be used by internal structures. + Standard_EXPORT BRepMesh_CircleTool(const Standard_Integer theReservedSize, + const BRepMeshCol::Allocator& theAllocator); + + //! Initializes the tool. + //! \param theReservedSize size to be reserved for vector of circles. + inline void Init(const Standard_Integer /*theReservedSize*/) + { + myTolerance = Precision::PConfusion() * Precision::PConfusion(); + } + + //! Sets new size for cell filter. + //! \param theSize cell size to be set for X and Y dimensions. + inline void SetCellSize(const Standard_Real theSize) + { + myCellFilter.Reset(theSize, myAllocator); + } + + //! Sets new size for cell filter. + //! \param theSizeX cell size to be set for X dimension. + //! \param theSizeY cell size to be set for Y dimension. + inline void SetCellSize(const Standard_Real theSizeX, + const Standard_Real theSizeY) + { + Standard_Real aCellSize[2] = { theSizeX, theSizeY }; + myCellFilter.Reset(aCellSize, myAllocator); + } + + //! Sets limits of inspection area. + //! \param theMin bottom left corner of inspection area. + //! \param theMax top right corner of inspection area. + inline void SetMinMaxSize(const gp_XY& theMin, + const gp_XY& theMax) + { + myFaceMin = theMin; + myFaceMax = theMax; + } + + //! Binds the circle to the tool. + //! \param theIndex index a circle should be bound with. + //! \param theCircle circle to be bound. + Standard_EXPORT void Bind(const Standard_Integer theIndex, + const gp_Circ2d& theCircle); + + //! Computes circle on three points and bind it to the tool. + //! \param theIndex index a circle should be bound with. + //! \param thePoint1 first point. + //! \param thePoint2 second point. + //! \param thePoint3 third point. + //! \return FALSE in case of impossibility to build a circle + //! on the given points, TRUE elsewhere. + Standard_EXPORT Standard_Boolean Bind(const Standard_Integer theIndex, + const gp_XY& thePoint1, + const gp_XY& thePoint2, + const gp_XY& thePoint3); + + //! Binds implicit zero circle. + //! \param theIndex index a zero circle should be bound with. + Standard_EXPORT void MocBind(const Standard_Integer theIndex); + + //! Deletes a circle from the tool. + //! \param theIndex index of a circle to be removed. + Standard_EXPORT void Delete(const Standard_Integer theIndex); + + //! Select the circles shot by the given point. + //! \param thePoint bullet point. + Standard_EXPORT BRepMeshCol::ListOfInteger& Select(const gp_XY& thePoint); + +private: + + //! Creates circle with the given parameters and binds it to the tool. + //! \param theIndex index a circle should be bound with. + //! \param theLocation location of a circle. + //! \param theRadius radius of a circle. + void bind(const Standard_Integer theIndex, + const gp_XY& theLocation, + const Standard_Real theRadius); + +private: + + Standard_Real myTolerance; + BRepMeshCol::Allocator myAllocator; + BRepMeshCol::CircleCellFilter myCellFilter; + BRepMesh_CircleInspector mySelector; + gp_XY myFaceMax; + gp_XY myFaceMin; +}; + +#endif diff --git a/src/BRepMesh/BRepMesh_Collections.hxx b/src/BRepMesh/BRepMesh_Collections.hxx new file mode 100644 index 0000000000..eb613ca694 --- /dev/null +++ b/src/BRepMesh/BRepMesh_Collections.hxx @@ -0,0 +1,144 @@ +// 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. + +#ifndef _BRepMesh_Collections_HeaderFile +#define _BRepMesh_Collections_HeaderFile + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +class BRepMesh_Vertex; +class TopoDS_Shape; +class TopoDS_Face; +class TopoDS_Edge; +class TopoDS_Vertex; +class BRepMesh_FaceAttribute; +class Handle_BRepMesh_FaceAttribute; +class BRepMesh_VertexInspector; +class BRepMesh_CircleInspector; +class BRepMesh_Classifier; +class Poly_Triangulation; + +//! Short names for collections +#define N_SEQUENCE NCollection_Sequence +#define N_VECTOR NCollection_Vector +#define N_ARRAY1 NCollection_Array1 +#define N_LIST NCollection_List +#define N_MAP NCollection_Map +#define N_HANDLE NCollection_Handle +#define N_DATAMAP NCollection_DataMap +#define N_IMAP NCollection_IndexedMap +#define N_IDMAP NCollection_IndexedDataMap +#define N_CELLFILTER NCollection_CellFilter + +namespace BRepMeshCol +{ + //! Structure keeping parameters of segment. + struct Segment + { + gp_XY StartPnt; + gp_XY EndPnt; + }; + + //! Memory allocators + typedef Handle(NCollection_IncAllocator) Allocator; + + //! Short names for hashers + typedef TopTools_ShapeMapHasher ShapeMapHasher; + + //! Sequences + typedef N_SEQUENCE SequenceOfBndB2d; + typedef N_SEQUENCE SequenceOfInteger; + typedef N_SEQUENCE SequenceOfReal; + + //! Vectors + typedef N_VECTOR VectorOfVertex; + typedef N_VECTOR VectorOfInteger; + typedef N_VECTOR VectorOfCircle; + + //! Trees + typedef NCollection_EBTree BndBox2dTree; + typedef NCollection_UBTreeFiller BndBox2dTreeFiller; + + //! Arrays + typedef N_ARRAY1 Array1OfVertexOfDelaun; + typedef N_ARRAY1 Array1OfInteger; + typedef N_ARRAY1 Array1OfReal; + typedef std::vector Array1OfSegments; + + //! Lists + typedef N_LIST ListOfXY; + typedef N_LIST ListOfVertex; + typedef N_LIST ListOfInteger; + + //! Maps + typedef N_MAP MapOfInteger; + typedef N_MAP MapOfTriangulation; + typedef N_MAP MapOfShape; + + typedef N_DATAMAP MapOfIntegerInteger; + typedef N_DATAMAP DMapOfVertexInteger; + typedef N_DATAMAP DMapOfFaceAttribute; + typedef N_DATAMAP DMapOfShapePairOfPolygon; + typedef N_DATAMAP DMapOfIntegerPnt; + typedef N_DATAMAP DMapOfIntegerListOfXY; + typedef N_DATAMAP DMapOfIntegerListOfInteger; + typedef N_DATAMAP DMapOfEdgeListOfTriangulation; + + typedef N_IMAP IMapOfInteger; + typedef N_IMAP IMapOfReal; + typedef N_IMAP IMapOfElement; + typedef N_IDMAP IDMapOfLink; + + //! CellFilters + typedef N_CELLFILTER CircleCellFilter; + typedef N_CELLFILTER VertexCellFilter; + + //! Handles + typedef N_HANDLE HMapOfInteger; + typedef N_HANDLE HClassifier; + typedef N_HANDLE HBndBox2dTree; + typedef N_HANDLE HArray1OfSegments; + + //! Other data structures + typedef std::pair SegmentsTree; + typedef std::vector Array1OfSegmentsTree; +}; + +#endif diff --git a/src/BRepMesh/BRepMesh_ComparatorOfIndexedVertexOfDelaun.cdl b/src/BRepMesh/BRepMesh_ComparatorOfIndexedVertexOfDelaun.cdl deleted file mode 100644 index 8dc46a0dd8..0000000000 --- a/src/BRepMesh/BRepMesh_ComparatorOfIndexedVertexOfDelaun.cdl +++ /dev/null @@ -1,49 +0,0 @@ --- Created on: 1994-04-05 --- Created by: Didier PIFFAULT --- Copyright (c) 1994-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. - -class ComparatorOfIndexedVertexOfDelaun from BRepMesh - - ---Purpose: Sort two point in a given direction. - - - uses Boolean from Standard, - XY from gp, - DataStructureOfDelaun from BRepMesh - - is Create (theDir : XY from gp; - TheTol : Real from Standard; - HDS : DataStructureOfDelaun from BRepMesh) - returns ComparatorOfIndexedVertexOfDelaun; - - - IsLower (me; Left, Right: Integer) - ---Purpose: returns True if is lower than - returns Boolean from Standard; - - IsGreater (me; Left, Right: Integer) - ---Purpose: returns True if is greater than - returns Boolean from Standard; - - IsEqual(me; Left, Right: Integer) - ---Purpose: returns True when and are equal. - returns Boolean from Standard; - - - fields IndexedStructure : DataStructureOfDelaun from BRepMesh; - DirectionOfSort : XY from gp; - Tolerance : Real from Standard; - -end ComparatorOfIndexedVertexOfDelaun; diff --git a/src/BRepMesh/BRepMesh_ComparatorOfIndexedVertexOfDelaun.cxx b/src/BRepMesh/BRepMesh_ComparatorOfIndexedVertexOfDelaun.cxx deleted file mode 100644 index 4c0f05d9d8..0000000000 --- a/src/BRepMesh/BRepMesh_ComparatorOfIndexedVertexOfDelaun.cxx +++ /dev/null @@ -1,67 +0,0 @@ -// Created on: 1994-04-05 -// Created by: Didier PIFFAULT -// Copyright (c) 1994-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. - -#include -#include - -//======================================================================= -//function : BRepMesh_ComparatorOfIndexedVertexOfDelaun -//purpose : -//======================================================================= - -BRepMesh_ComparatorOfIndexedVertexOfDelaun::BRepMesh_ComparatorOfIndexedVertexOfDelaun -(const gp_XY& theDir, - const Standard_Real theTol, - const Handle(BRepMesh_DataStructureOfDelaun)& HDS) - : IndexedStructure(HDS),DirectionOfSort(theDir), Tolerance(theTol) -{} - -//======================================================================= -//function : IsLower -//purpose : -//======================================================================= - -Standard_Boolean BRepMesh_ComparatorOfIndexedVertexOfDelaun::IsLower -(const Standard_Integer Left, const Standard_Integer Right) const -{ - return ((IndexedStructure->GetNode(Left).Coord()*DirectionOfSort) < - (IndexedStructure->GetNode(Right).Coord()*DirectionOfSort)); -} - -//======================================================================= -//function : IsGreater -//purpose : -//======================================================================= - -Standard_Boolean BRepMesh_ComparatorOfIndexedVertexOfDelaun::IsGreater -(const Standard_Integer Left, const Standard_Integer Right) const -{ - return ((IndexedStructure->GetNode(Left).Coord()*DirectionOfSort) > - (IndexedStructure->GetNode(Right).Coord()*DirectionOfSort)); -} - -//======================================================================= -//function : IsEqual -//purpose : -//======================================================================= - -Standard_Boolean BRepMesh_ComparatorOfIndexedVertexOfDelaun::IsEqual -(const Standard_Integer Left, const Standard_Integer Right) const -{ - return (IndexedStructure->GetNode(Left).Coord().IsEqual - (IndexedStructure->GetNode(Right).Coord(), Tolerance)); -} - diff --git a/src/BRepMesh/BRepMesh_ComparatorOfVertexOfDelaun.cdl b/src/BRepMesh/BRepMesh_ComparatorOfVertexOfDelaun.cdl deleted file mode 100644 index 0df083f0d7..0000000000 --- a/src/BRepMesh/BRepMesh_ComparatorOfVertexOfDelaun.cdl +++ /dev/null @@ -1,46 +0,0 @@ --- Created on: 1993-06-18 --- Created by: Didier PIFFAULT --- Copyright (c) 1993-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. - -class ComparatorOfVertexOfDelaun from BRepMesh - - ---Purpose: Sort two point in a given direction. - - - uses Boolean from Standard, - Vertex from BRepMesh, - XY from gp - - - is Create (theDir : XY from gp) - returns ComparatorOfVertexOfDelaun; - - - IsLower (me; Left, Right: Vertex from BRepMesh) - ---Purpose: returns True if is lower than - returns Boolean from Standard; - - IsGreater (me; Left, Right: Vertex from BRepMesh) - ---Purpose: returns True if is greater than - returns Boolean from Standard; - - IsEqual(me; Left, Right: Vertex from BRepMesh) - ---Purpose: returns True when and are equal. - returns Boolean from Standard; - - -fields DirectionOfSort : XY from gp; - -end ComparatorOfVertexOfDelaun; diff --git a/src/BRepMesh/BRepMesh_ComparatorOfVertexOfDelaun.cxx b/src/BRepMesh/BRepMesh_ComparatorOfVertexOfDelaun.cxx deleted file mode 100644 index 022af7d785..0000000000 --- a/src/BRepMesh/BRepMesh_ComparatorOfVertexOfDelaun.cxx +++ /dev/null @@ -1,62 +0,0 @@ -// Created on: 1993-06-18 -// Created by: Didier PIFFAULT -// Copyright (c) 1993-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. - -#include - -//======================================================================= -//function : BRepMesh_ComparatorOfVertexOfDelaun -//purpose : -//======================================================================= - -BRepMesh_ComparatorOfVertexOfDelaun::BRepMesh_ComparatorOfVertexOfDelaun(const gp_XY& theDir) - : DirectionOfSort(theDir) -{} - -//======================================================================= -//function : IsLower -//purpose : -//======================================================================= - -Standard_Boolean BRepMesh_ComparatorOfVertexOfDelaun::IsLower(const BRepMesh_Vertex& Left, - const BRepMesh_Vertex& Right) const -{ - return (Left.Coord()*DirectionOfSort) < - (Right.Coord()*DirectionOfSort); -} - -//======================================================================= -//function : IsGreater -//purpose : -//======================================================================= - -Standard_Boolean BRepMesh_ComparatorOfVertexOfDelaun::IsGreater(const BRepMesh_Vertex& Left, - const BRepMesh_Vertex& Right) const -{ - return (Left.Coord()*DirectionOfSort) > - (Right.Coord()*DirectionOfSort); -} - -//======================================================================= -//function : IsEqual -//purpose : -//======================================================================= - -Standard_Boolean BRepMesh_ComparatorOfVertexOfDelaun::IsEqual(const BRepMesh_Vertex& Left, - const BRepMesh_Vertex& Right) const -{ - return Left.IsEqual(Right); -} - diff --git a/src/BRepMesh/BRepMesh_DataStructureOfDelaun.cdl b/src/BRepMesh/BRepMesh_DataStructureOfDelaun.cdl deleted file mode 100644 index 75edd90e2f..0000000000 --- a/src/BRepMesh/BRepMesh_DataStructureOfDelaun.cdl +++ /dev/null @@ -1,265 +0,0 @@ --- Created on: 1993-03-17 --- Created by: Didier PIFFAULT --- Copyright (c) 1993-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. - -class DataStructureOfDelaun from BRepMesh inherits TShared from MMgt - - ---Purpose: Describes the data structure necessary for the - -- mesh algorithms in two dimensions plane or on - -- surface by meshing in UV space. - - - uses Integer from Standard, - ListOfInteger from BRepMesh, - MapOfInteger from BRepMesh, - PairOfIndex from BRepMesh, - Box from Bnd, - BoundSortBox from Bnd, - BaseAllocator from BRepMesh, - VertexTool from BRepMesh, - IDMapOfLinkOfDataStructureOfDelaun from BRepMesh, - IMapOfElementOfDataStructureOfDelaun from BRepMesh, - SelectorOfDataStructureOfDelaun from BRepMesh, - Vertex from BRepMesh, - Edge from BRepMesh, - Triangle from BRepMesh - - is Create (theAllocator: BaseAllocator from BRepMesh; - NodeNumber : Integer from Standard = 100) - ---Purpose: is just an evaluation of the - -- presumed number of nodes in this mesh. The - -- Mesh data structure will be automatically - -- redimensioned if necessary. - returns DataStructureOfDelaun from BRepMesh ; - - AddNode (me : mutable ; - theNode : Vertex from BRepMesh) - returns Integer from Standard - ---Purpose: Adds a node to the mesh if the node is not - -- already in the Mesh. Returns the index of the - -- node in the structure. - is static; - - GetNode (me : mutable; - Index : Integer from Standard) - returns Vertex from BRepMesh - ---Purpose: Get the value of node . - ---C++: return const & - ---C++: alias operator () - is static; - - GetNodeList (me : mutable; - Index : Integer from Standard) - returns ListOfInteger from BRepMesh - ---Purpose: Get the list of node . - ---C++: return const & - is static; - - ForceRemoveNode (me : mutable; - Index : Integer from Standard) - ---Purpose: Removes the node of index from the mesh. - is static; - - ForceRemoveLink (me : mutable; - Index : Integer from Standard) - ---Purpose: Removes the link of index from the mesh. - is static; - - ReplaceNodes (me : mutable; - NewNodes : VertexTool from BRepMesh) - ---Purpose: Removes the all nodes and sets new map of - -- nodes from the mesh. - -- For internal use only. - is static; - - RemoveNode (me : mutable; - Index : Integer from Standard) - ---Purpose: Removes the node of index from the mesh. - is static; - - MoveNode (me : mutable ; - Index : Integer from Standard; - newNode : Vertex from BRepMesh) - ---Purpose: Changes the UV value of node of index by - -- . Returns false if is already in - -- the structure. - returns Boolean from Standard is static; - - NbNodes (me) - returns Integer from Standard - ---Purpose: Gives the number of nodes in this mesh. - is static; - - - AddLink (me : mutable; - theLink : Edge from BRepMesh) - returns Integer from Standard - ---Purpose: Adds a Link to the mesh if the Link is not - -- already in the structure. Returns the index of - -- the link in the structure. - is static; - - GetLink (me : mutable; - Index : Integer from Standard) - returns Edge from BRepMesh - ---Purpose: Get the value of Link . - ---C++: return const & - is static; - - RemoveLink (me : mutable; - Index : Integer from Standard) - ---Purpose: Removes the Link of index from the - -- mesh. - is static; - - SubstituteLink (me : mutable ; - Index : Integer from Standard; - newLink : Edge from BRepMesh) - ---Purpose: Substitutes the Link of index by - -- clear the connectivity. - returns Boolean from Standard is static; - - NbLinks (me) - returns Integer from Standard - ---Purpose: Gives the number of elements in this mesh. - is static; - - - AddElement (me : mutable; - theElement : Triangle from BRepMesh) - returns Integer from Standard - ---Purpose: Adds an element to the mesh if it is not - -- already in the Mesh. Returns the index of the - -- element in the structure. - is static; - - GetElement (me : mutable; - Index : Integer from Standard) - returns Triangle from BRepMesh - ---Purpose: Get the value of Element . - ---C++: return const & - is static; - - RemoveElement (me : mutable; - Index : Integer from Standard) - ---Purpose: Removes the element of index in the mesh. - is static; - - SubstituteElement (me : mutable ; - Index : Integer from Standard; - newElement : Triangle from BRepMesh) - ---Purpose: Substitutes the element of index by - -- . The links connectivity is updated. - returns Boolean from Standard is static; - - NbElements (me) - returns Integer from Standard - ---Purpose: Gives the number of elements in this mesh. - is static; - - ClearDomain (me : mutable) - ---Purpose: Removes all elements - is static; - - - IndexOf (me: mutable; - aNode : Vertex from BRepMesh) - ---Purpose: Finds the index of the node. Returns 0 if the - -- node is not in the mesh. - returns Integer from Standard; - - IndexOf (me; - aLink : Edge from BRepMesh) - ---Purpose: Finds the index of the Link. Returns 0 if the - -- Link is not in the mesh. - returns Integer from Standard; - - IndexOf (me; - anElement : Triangle from BRepMesh) - ---Purpose: Finds the index of the Element. Returns 0 if - -- the Element is not in the mesh. - returns Integer from Standard; - - LinkNeighboursOf (me; - theNode : in Integer from Standard) - returns ListOfInteger from BRepMesh - ---C++: return const & - ---Purpose: Gives the list of Link's indices handling the - -- node . - is static; - - - ElemConnectedTo (me; - theLink : in Integer from Standard) - returns PairOfIndex from BRepMesh - ---C++: return const & - ---Purpose: Gives the element's indices conected - -- to . - is static; - - ElemOfDomain (me) - returns MapOfInteger from BRepMesh - ---C++: return const & - ---Purpose: Gives the list of element's indices - is static; - - - LinkOfDomain (me) - returns MapOfInteger from BRepMesh - ---C++: return const & - ---Purpose: Gives the list of link's indices - is static; - - - ClearDeleted (me : mutable) - ---Purpose: This method substitute the deleted items by - -- the last in Indexed Data Maps to have only - -- non-deleted elements, links or nodes in the - -- structure. - is static; - - - -- Internal methods : - - ClearElement (me : mutable; - Index : Integer from Standard; - theElem : Triangle from BRepMesh) - ---Purpose: Deletes the element of index in - -- the mesh. Used by RemoveElement. - is static private; - - Statistics (me; - flot : in out OStream from Standard) - ---Purpose: Give informations on map. - is static; - - Allocator (me) returns BaseAllocator from BRepMesh; - ---C++: return const& - - Data (me: mutable) returns VertexTool from BRepMesh; - ---Purpose: Give the data structure for cell size and - -- tolerance initialization. - ---C++: return & - - - fields myNodes : VertexTool from BRepMesh; - myLinks : IDMapOfLinkOfDataStructureOfDelaun from BRepMesh; - myDelLinks : ListOfInteger from BRepMesh; - myElements : IMapOfElementOfDataStructureOfDelaun from BRepMesh; - --myDelElements : ListOfInteger from BRepMesh; - myElemOfDomain : MapOfInteger from BRepMesh; - myLinkOfDomain : MapOfInteger from BRepMesh; - myAllocator : BaseAllocator from BRepMesh; -end DataStructureOfDelaun; diff --git a/src/BRepMesh/BRepMesh_DataStructureOfDelaun.cxx b/src/BRepMesh/BRepMesh_DataStructureOfDelaun.cxx index 0f7aa71781..e34e47c332 100644 --- a/src/BRepMesh/BRepMesh_DataStructureOfDelaun.cxx +++ b/src/BRepMesh/BRepMesh_DataStructureOfDelaun.cxx @@ -14,622 +14,458 @@ // 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_HANDLE (BRepMesh_DataStructureOfDelaun, Standard_Transient) +IMPLEMENT_STANDARD_RTTIEXT(BRepMesh_DataStructureOfDelaun, Standard_Transient) //======================================================================= //function : BRepMesh_DataStructureOfDelaun //purpose : //======================================================================= -BRepMesh_DataStructureOfDelaun::BRepMesh_DataStructureOfDelaun(const BRepMesh_BaseAllocator& theAlloc, - const Standard_Integer NodeNumber) - : myNodes(NodeNumber, theAlloc), - myLinks(NodeNumber*3), - myDelLinks(theAlloc), - myElements(NodeNumber*2), - // Not_Debuged_Yet myDelElements(theAlloc), - myElemOfDomain(NodeNumber*2,theAlloc), - myLinkOfDomain(NodeNumber*2,theAlloc) +BRepMesh_DataStructureOfDelaun::BRepMesh_DataStructureOfDelaun( + const BRepMeshCol::Allocator& theAllocator, + const Standard_Integer theReservedNodeSize) + : myNodes (theReservedNodeSize, theAllocator), + myLinks (theReservedNodeSize * 3), + myDelLinks (theAllocator), + myElements (theReservedNodeSize * 2), + myElementsOfDomain(theReservedNodeSize * 2, theAllocator), + myLinksOfDomain (theReservedNodeSize * 2, theAllocator), + myAllocator (theAllocator) { - myAllocator = theAlloc; } //======================================================================= -//function : AddNode +//function : SubstituteNode //purpose : //======================================================================= -Standard_Integer BRepMesh_DataStructureOfDelaun::AddNode(const BRepMesh_Vertex& theNode) +Standard_Boolean BRepMesh_DataStructureOfDelaun::SubstituteNode( + const Standard_Integer theIndex, + const BRepMesh_Vertex& theNewNode) { - return myNodes.Add(theNode); -} + if (myNodes.FindIndex(theNewNode) != 0) + return Standard_False; -//======================================================================= -//function : GetNode -//purpose : -//======================================================================= -const BRepMesh_Vertex& BRepMesh_DataStructureOfDelaun::GetNode(const Standard_Integer Index) -{ - return myNodes.FindKey(Index); -} - -//======================================================================= -//function : GetNodeList -//purpose : -//======================================================================= -const BRepMesh_ListOfInteger& BRepMesh_DataStructureOfDelaun::GetNodeList(const Standard_Integer Index) -{ - return myNodes.FindFromIndex(Index); -} - -//======================================================================= -//function : ForceRemoveNode -//purpose : -//======================================================================= -void BRepMesh_DataStructureOfDelaun::ForceRemoveNode(const Standard_Integer Index) -{ - if ( myNodes.FindFromIndex(Index).Extent()==0) { - myNodes.Delete(Index); - } -} - -//======================================================================= -//function : ReplaceNodes -//purpose : -//======================================================================= -void BRepMesh_DataStructureOfDelaun::ReplaceNodes(const BRepMesh_VertexTool& NewNodes) -{ - if ( NewNodes.IsEmpty() ) - return; - - myNodes = NewNodes; -} - -//======================================================================= -//function : ForceRemoveLink -//purpose : -//======================================================================= -void BRepMesh_DataStructureOfDelaun::ForceRemoveLink(const Standard_Integer Index) -{ - //Warning, the static cast from const& to & is called for - //performance reasons. This is applicable only in case if later - //modification of element (field movability) does not influent on - //has calculation. - BRepMesh_Edge& lref=(BRepMesh_Edge&)myLinks.FindKey(Index); - if (lref.Movability()!=BRepMesh_Deleted) { - if (myLinks.FindFromIndex(Index).Extent()==0) { - BRepMesh_ListOfInteger::Iterator tit; - BRepMesh_ListOfInteger& aList1 = myNodes(lref.FirstNode()); - for(tit.Init(aList1); tit.More(); tit.Next()){ - if (tit.Value()==Index) { - aList1.Remove(tit); - break; - } - } - - BRepMesh_ListOfInteger& aList2 = myNodes(lref.LastNode()); - for(tit.Init(aList2); tit.More(); tit.Next()){ - if (tit.Value()==Index) { - aList2.Remove(tit); - break; - } - } - myLinkOfDomain.Remove(Index); - lref.SetMovability(BRepMesh_Deleted); - myDelLinks.Append(Index); - } - } -} - -//======================================================================= -//function : RemoveNode -//purpose : -//======================================================================= -void BRepMesh_DataStructureOfDelaun::RemoveNode(const Standard_Integer Index) -{ - if (myNodes.FindKey(Index).Movability() == BRepMesh_Free && - myNodes.FindFromIndex(Index).Extent() == 0) { - myNodes.Delete(Index); - } -} - -//======================================================================= -//function : MoveNode -//purpose : -//======================================================================= -Standard_Boolean BRepMesh_DataStructureOfDelaun::MoveNode(const Standard_Integer Index, - const BRepMesh_Vertex& newNode) -{ - if (myNodes.FindIndex(newNode) == 0) { - const BRepMesh_ListOfInteger& refLink = myNodes(Index); - myNodes.Substitute(Index, newNode, refLink); - return Standard_True; - } - return Standard_False; -} - -//======================================================================= -//function : NbNodes -//purpose : -//======================================================================= -Standard_Integer BRepMesh_DataStructureOfDelaun::NbNodes()const -{ - return myNodes.Extent(); + const BRepMeshCol::ListOfInteger& aLinks = myNodes(theIndex); + myNodes.Substitute(theIndex, theNewNode, aLinks); + return Standard_True; } //======================================================================= //function : AddLink //purpose : //======================================================================= -Standard_Integer BRepMesh_DataStructureOfDelaun::AddLink(const BRepMesh_Edge& theLink) +Standard_Integer BRepMesh_DataStructureOfDelaun::AddLink( + const BRepMesh_Edge& theLink) { - Standard_Integer LinkIndex=myLinks.FindIndex(theLink); - if (LinkIndex<=0) { - BRepMesh_PairOfIndex aPair; - if (!myDelLinks.IsEmpty()) { - LinkIndex=myDelLinks.First(); - myLinks.Substitute(LinkIndex, theLink, aPair); - myDelLinks.RemoveFirst(); - } - else { - LinkIndex=myLinks.Add(theLink, aPair); - } - myNodes(theLink.FirstNode()).Append(Abs(LinkIndex)); - myNodes(theLink.LastNode()).Append(Abs(LinkIndex)); - myLinkOfDomain.Add(LinkIndex); + Standard_Integer aLinkIndex = IndexOf(theLink); + if (aLinkIndex > 0) + { + return theLink.IsSameOrientation(GetLink(aLinkIndex)) ? + aLinkIndex : -aLinkIndex; } - else if (!theLink.SameOrientation(myLinks.FindKey(LinkIndex))) - LinkIndex=-LinkIndex; - return LinkIndex; -} - -//======================================================================= -//function : GetLink -//purpose : -//======================================================================= -const BRepMesh_Edge& BRepMesh_DataStructureOfDelaun::GetLink(const Standard_Integer Index) -{ - return myLinks.FindKey(Index); -} - -//======================================================================= -//function : RemoveLink -//purpose : -//======================================================================= -void BRepMesh_DataStructureOfDelaun::RemoveLink(const Standard_Integer Index) -{ - //Warning, the static cast from const& to & is called for - //performance reasons. This is applicable only in case if later - //modification of element (field movability) does not influent on - //has calculation. - BRepMesh_Edge& lref=(BRepMesh_Edge&)myLinks.FindKey(Index); - if (lref.Movability()!=BRepMesh_Deleted) { - if (lref.Movability()==BRepMesh_Free && - myLinks.FindFromIndex(Index).Extent()==0) { - BRepMesh_ListOfInteger::Iterator tit; - BRepMesh_ListOfInteger& aList1 = myNodes(lref.FirstNode()); - for(tit.Init(aList1); tit.More(); tit.Next()){ - if (tit.Value()==Index) { - aList1.Remove(tit); - break; - } - } - BRepMesh_ListOfInteger& aList2 = myNodes(lref.LastNode()); - for(tit.Init(aList2); tit.More(); tit.Next()){ - if (tit.Value()==Index) { - aList2.Remove(tit); - break; - } - } - myLinkOfDomain.Remove(Index); - lref.SetMovability(BRepMesh_Deleted); - myDelLinks.Append(Index); - } + BRepMesh_PairOfIndex aPair; + if (!myDelLinks.IsEmpty()) + { + aLinkIndex = myDelLinks.First(); + myLinks.Substitute(aLinkIndex, theLink, aPair); + myDelLinks.RemoveFirst(); } + else + aLinkIndex = myLinks.Add(theLink, aPair); + + const Standard_Integer aLinkId = Abs(aLinkIndex); + myNodes(theLink.FirstNode()).Append(aLinkId); + myNodes(theLink.LastNode() ).Append(aLinkId); + myLinksOfDomain.Add(aLinkIndex); + + return aLinkIndex; } //======================================================================= //function : SubstituteLink //purpose : //======================================================================= -Standard_Boolean BRepMesh_DataStructureOfDelaun::SubstituteLink(const Standard_Integer Index, - const BRepMesh_Edge& newLink) +Standard_Boolean BRepMesh_DataStructureOfDelaun::SubstituteLink( + const Standard_Integer theIndex, + const BRepMesh_Edge& theNewLink) { - //BRepMesh_ListOfInteger thelist(myAllocator); BRepMesh_PairOfIndex aPair; - BRepMesh_Edge lref=myLinks.FindKey(Index); - if (lref.Movability()==BRepMesh_Deleted) - myLinks.Substitute(Index, newLink, aPair); - else { - if (myLinks.FindIndex(newLink)!=0) - return Standard_False; - - lref.SetMovability(BRepMesh_Deleted); - myLinks.Substitute(Index, lref, aPair); - - BRepMesh_ListOfInteger::Iterator tit; - for(tit.Init(myNodes(lref.FirstNode())); tit.More(); tit.Next()){ - if (tit.Value()==Index) { - myNodes(lref.FirstNode()).Remove(tit); - break; - } - } - for(tit.Init(myNodes(lref.LastNode())); tit.More(); tit.Next()){ - if (tit.Value()==Index) { - myNodes(lref.LastNode()).Remove(tit); - break; - } - } - myLinks.Substitute(Index, newLink, aPair); - myNodes(newLink.FirstNode()).Append(Abs(Index)); - myNodes(newLink.LastNode()).Append(Abs(Index)); + BRepMesh_Edge aLink = GetLink(theIndex); + if (aLink.Movability() == BRepMesh_Deleted) + { + myLinks.Substitute(theIndex, theNewLink, aPair); + return Standard_True; } + + if (IndexOf(theNewLink) != 0) + return Standard_False; + + aLink.SetMovability(BRepMesh_Deleted); + myLinks.Substitute(theIndex, aLink, aPair); + cleanLink(theIndex, aLink); + + const Standard_Integer aLinkId = Abs(theIndex); + myNodes(theNewLink.FirstNode()).Append(aLinkId); + myNodes(theNewLink.LastNode() ).Append(aLinkId); + myLinks.Substitute(theIndex, theNewLink, aPair); + return Standard_True; } //======================================================================= -//function : NbLinks +//function : ForceRemoveLink //purpose : //======================================================================= -Standard_Integer BRepMesh_DataStructureOfDelaun::NbLinks()const +void BRepMesh_DataStructureOfDelaun::RemoveLink( + const Standard_Integer theIndex, + const Standard_Boolean isForce) { - return myLinks.Extent(); + BRepMesh_Edge& aLink = (BRepMesh_Edge&)GetLink(theIndex); + if (aLink.Movability() == BRepMesh_Deleted || + (!isForce && aLink.Movability() != BRepMesh_Free) || + ElementsConnectedTo(theIndex).Extent() != 0) + { + return; + } + + cleanLink(theIndex, aLink); + aLink.SetMovability(BRepMesh_Deleted); + + myLinksOfDomain.Remove(theIndex); + myDelLinks.Append (theIndex); +} + +//======================================================================= +//function : cleanLink +//purpose : +//======================================================================= +void BRepMesh_DataStructureOfDelaun::cleanLink( + const Standard_Integer theIndex, + const BRepMesh_Edge& theLink) +{ + for (Standard_Integer i = 0; i < 2; ++i) + { + const Standard_Integer aNodeId = (i == 0) ? + theLink.FirstNode() : theLink.LastNode(); + + BRepMeshCol::ListOfInteger& aLinkList = myNodes(aNodeId); + BRepMeshCol::ListOfInteger::Iterator aLinkIt(aLinkList); + for(; aLinkIt.More(); aLinkIt.Next()) + { + if (aLinkIt.Value() == theIndex) + { + aLinkList.Remove(aLinkIt); + break; + } + } + } } //======================================================================= //function : AddElement //purpose : //======================================================================= -Standard_Integer BRepMesh_DataStructureOfDelaun::AddElement(const BRepMesh_Triangle& theElement) +Standard_Integer BRepMesh_DataStructureOfDelaun::AddElement( + const BRepMesh_Triangle& theElement) { - Standard_Integer ElemIndex=myElements.FindIndex(theElement); + Standard_Integer aElementIndex = IndexOf(theElement); + if (aElementIndex > 0) + return aElementIndex; - if (ElemIndex<=0) { - /* Not_Debuged_Yet - if (!myDelElements.IsEmpty()) { - ElemIndex=myDelElements.First(); - myElements.Substitute(ElemIndex, theElement); - myDelElements.RemoveFirst(); - } - else */ - ElemIndex=myElements.Add(theElement); + aElementIndex = myElements.Add(theElement); + myElementsOfDomain.Add(aElementIndex); - myElemOfDomain.Add(ElemIndex); + Standard_Integer e[3]; + Standard_Boolean o[3]; + theElement.Edges(e, o); + for (Standard_Integer i = 0; i < 3; ++i) + myLinks(e[i]).Append(aElementIndex); - Standard_Integer ed1, ed2, ed3; - Standard_Boolean or1, or2, or3; - theElement.Edges(ed1, ed2, ed3, or1, or2, or3); - myLinks(ed1).Append(ElemIndex); - myLinks(ed2).Append(ElemIndex); - myLinks(ed3).Append(ElemIndex); - } - - return ElemIndex; -} - -//======================================================================= -//function : GetElement -//purpose : -//======================================================================= -const BRepMesh_Triangle& BRepMesh_DataStructureOfDelaun::GetElement(const Standard_Integer Index) -{ - return myElements.FindKey(Index); + return aElementIndex; } //======================================================================= //function : RemoveElement //purpose : //======================================================================= -void BRepMesh_DataStructureOfDelaun::RemoveElement(const Standard_Integer Index) +void BRepMesh_DataStructureOfDelaun::RemoveElement( + const Standard_Integer theIndex) { - //Warning, the static cast from const& to & is called for - //performance reasons. This is applicable only in case if later - //modification of element (field movability) does not influent on - //has calculation. - BRepMesh_Triangle& lelem=(BRepMesh_Triangle&)myElements.FindKey(Index); - if (lelem.Movability()!=BRepMesh_Deleted) { - ClearElement(Index, lelem); - lelem.SetMovability(BRepMesh_Deleted); - // Not_Debuged_Yet myDelElements.Append(Index); - myElemOfDomain.Remove(Index); - } + BRepMesh_Triangle& aElement = (BRepMesh_Triangle&)GetElement(theIndex); + if (aElement.Movability() == BRepMesh_Deleted) + return; + + cleanElement(theIndex, aElement); + aElement.SetMovability(BRepMesh_Deleted); + myElementsOfDomain.Remove(theIndex); } -static void removeElementIndex(BRepMesh_PairOfIndex& thePair, - const Standard_Integer Index) +//======================================================================= +//function : cleanElement +//purpose : +//======================================================================= +void BRepMesh_DataStructureOfDelaun::cleanElement( + const Standard_Integer theIndex, + const BRepMesh_Triangle& theElement) { - for(Standard_Integer i = 1, n = thePair.Extent(); i <= n; i++) { - if (thePair.Index(i)==Index) { + if (theElement.Movability() != BRepMesh_Free) + return; + + Standard_Integer e[3]; + Standard_Boolean o[3]; + theElement.Edges(e, o); + + for (Standard_Integer i = 0; i < 3; ++i) + removeElementIndex(theIndex, myLinks(e[i])); +} + +//======================================================================= +//function : removeElementIndex +//purpose : +//======================================================================= +void BRepMesh_DataStructureOfDelaun::removeElementIndex( + const Standard_Integer theIndex, + BRepMesh_PairOfIndex& thePair) +{ + for (Standard_Integer i = 1, n = thePair.Extent(); i <= n; ++i) + { + if (thePair.Index(i) == theIndex) + { thePair.RemoveIndex(i); - break; + return; } } } -void BRepMesh_DataStructureOfDelaun::ClearElement(const Standard_Integer Index, - const BRepMesh_Triangle& theElem) -{ - if (theElem.Movability()==BRepMesh_Free) { - Standard_Integer ed1, ed2, ed3; - Standard_Boolean or1, or2, or3; - theElem.Edges(ed1, ed2, ed3, or1, or2, or3); - removeElementIndex(myLinks(ed1),Index); - removeElementIndex(myLinks(ed2),Index); - removeElementIndex(myLinks(ed3),Index); - } -} - //======================================================================= //function : SubstituteElement //purpose : //======================================================================= -Standard_Boolean BRepMesh_DataStructureOfDelaun::SubstituteElement -(const Standard_Integer Index, const BRepMesh_Triangle& newElement) +Standard_Boolean BRepMesh_DataStructureOfDelaun::SubstituteElement( + const Standard_Integer theIndex, + const BRepMesh_Triangle& theNewElement) { - const BRepMesh_Triangle& lelem=myElements.FindKey(Index); - if (lelem.Movability()==BRepMesh_Deleted) - myElements.Substitute(Index, newElement); - else { - if (myElements.FindIndex(newElement)==0) { - ClearElement(Index, lelem); - // Warning: here new element and old element should have different Hash code - myElements.Substitute(Index, newElement); - - Standard_Integer ed1, ed2, ed3; - Standard_Boolean or1, or2, or3; - newElement.Edges(ed1, ed2, ed3, or1, or2, or3); - myLinks(ed1).Append(Index); - myLinks(ed2).Append(Index); - myLinks(ed3).Append(Index); - } - else return Standard_False; + const BRepMesh_Triangle& aElement = GetElement(theIndex); + if (aElement.Movability() == BRepMesh_Deleted) + { + myElements.Substitute(theIndex, theNewElement); + return Standard_True; } + + if (IndexOf(theNewElement) != 0) + return Standard_False; + + cleanElement(theIndex, aElement); + // Warning: here new element and old element should have different Hash code + myElements.Substitute(theIndex, theNewElement); + + Standard_Integer e[3]; + Standard_Boolean o[3]; + theNewElement.Edges(e, o); + for (Standard_Integer i = 0; i < 3; ++i) + myLinks(e[i]).Append(theIndex); + return Standard_True; } +//======================================================================= +//function : ElementNodes +//purpose : +//======================================================================= +void BRepMesh_DataStructureOfDelaun::ElementNodes( + const BRepMesh_Triangle& theElement, + Standard_Integer (&theNodes)[3]) +{ + Standard_Integer e[3]; + Standard_Boolean o[3]; + theElement.Edges(e, o); + + const BRepMesh_Edge& aLink1 = GetLink(e[0]); + if (o[0]) + { + theNodes[0] = aLink1.FirstNode(); + theNodes[1] = aLink1.LastNode(); + } + else + { + theNodes[1] = aLink1.FirstNode(); + theNodes[0] = aLink1.LastNode(); + } + + const BRepMesh_Edge& aLink2 = GetLink(e[2]); + if (o[2]) + theNodes[2] = aLink2.FirstNode(); + else + theNodes[2] = aLink2.LastNode(); +} + //======================================================================= //function : ClearDomain //purpose : //======================================================================= void BRepMesh_DataStructureOfDelaun::ClearDomain() { - BRepMesh_MapOfInteger freeEdges; - Standard_Integer ed1, ed2, ed3; - Standard_Boolean or1, or2, or3; - BRepMesh_MapOfInteger::Iterator itDom(myElemOfDomain); - //Warning, the static cast from const& to & is called for - //performance reasons. This is applicable only in case if later - //modification of element (field movability) does not influent on - //has calculation. - for (;itDom.More(); itDom.Next()) { - BRepMesh_Triangle& lelem=(BRepMesh_Triangle&)myElements.FindKey(itDom.Key()); - lelem.Edges(ed1, ed2, ed3, or1, or2, or3); - freeEdges.Add(ed1); - freeEdges.Add(ed2); - freeEdges.Add(ed3); - ClearElement(itDom.Key(), lelem); - lelem.SetMovability(BRepMesh_Deleted); - // Not_Debuged_Yet myDelElements.Append(itDom.Key()); + BRepMeshCol::MapOfInteger aFreeEdges; + BRepMeshCol::MapOfInteger::Iterator aElementIt(myElementsOfDomain); + for (; aElementIt.More(); aElementIt.Next()) + { + const Standard_Integer aElementId = aElementIt.Key(); + BRepMesh_Triangle& aElement = (BRepMesh_Triangle&)GetElement(aElementId); + + Standard_Integer e[3]; + Standard_Boolean o[3]; + aElement.Edges(e, o); + + for (Standard_Integer i = 0; i < 3; ++i) + aFreeEdges.Add(e[i]); + + cleanElement(aElementId, aElement); + aElement.SetMovability(BRepMesh_Deleted); } - myElemOfDomain.Clear(); - BRepMesh_MapOfInteger::Iterator edgeIt(freeEdges); - for (; edgeIt.More(); edgeIt.Next()) - RemoveLink(edgeIt.Key()); + myElementsOfDomain.Clear(); + + BRepMeshCol::MapOfInteger::Iterator aEdgeIt(aFreeEdges); + for (; aEdgeIt.More(); aEdgeIt.Next()) + RemoveLink(aEdgeIt.Key()); } //======================================================================= -//function : NbElements +//function : clearDeletedLinks //purpose : //======================================================================= -Standard_Integer BRepMesh_DataStructureOfDelaun::NbElements()const +void BRepMesh_DataStructureOfDelaun::clearDeletedLinks() { - return myElements.Extent(); -} - -//======================================================================= -//function : IndexOf -//purpose : -//======================================================================= -Standard_Integer BRepMesh_DataStructureOfDelaun::IndexOf(const BRepMesh_Vertex& aNode) -{ - return myNodes.FindIndex(aNode); -} - -//======================================================================= -//function : IndexOf -//purpose : -//======================================================================= -Standard_Integer BRepMesh_DataStructureOfDelaun::IndexOf(const BRepMesh_Edge& aLink)const -{ - return myLinks.FindIndex(aLink); -} - -//======================================================================= -//function : IndexOf -//purpose : -//======================================================================= -Standard_Integer BRepMesh_DataStructureOfDelaun::IndexOf(const BRepMesh_Triangle& anElement)const -{ - return myElements.FindIndex(anElement); -} - -//======================================================================= -//function : LinkNeighboursOf -//purpose : -//======================================================================= -const BRepMesh_ListOfInteger& BRepMesh_DataStructureOfDelaun::LinkNeighboursOf -(const Standard_Integer theNode)const -{ - return myNodes.FindFromIndex(theNode); -} - -//======================================================================= -//function : ElemConnectedTo -//purpose : -//======================================================================= -const BRepMesh_PairOfIndex& BRepMesh_DataStructureOfDelaun::ElemConnectedTo -(const Standard_Integer theLink)const -{ - return myLinks.FindFromIndex(theLink); -} - -//======================================================================= -//function : ElemOfDomain -//purpose : -//======================================================================= -const BRepMesh_MapOfInteger& BRepMesh_DataStructureOfDelaun::ElemOfDomain () const -{ - return myElemOfDomain; -} - -//======================================================================= -//function : LinkOfDomain -//purpose : -//======================================================================= -const BRepMesh_MapOfInteger& BRepMesh_DataStructureOfDelaun::LinkOfDomain () const -{ - return myLinkOfDomain; -} - -//======================================================================= -//function : ClearDeleted -//purpose : -//======================================================================= -void BRepMesh_DataStructureOfDelaun::ClearDeleted() -{ - - // Traitement des Elements - - Standard_Integer IndexDelItem; - - Standard_Integer lastNonDelItem=myElements.Extent(); - /* // Not_Debuged_Yet - while (!myDelElements.IsEmpty()) { - while (lastNonDelItem>0) { - if (myElements.FindKey(lastNonDelItem).Movability()!=BRepMesh_Deleted) - break; - myElements.RemoveLast(); - lastNonDelItem--; - } - - IndexDelItem=myDelElements.First(); - myDelElements.RemoveFirst(); - - if (IndexDelItem0) { - if (myLinks.FindKey(lastNonDelItem).Movability()!=BRepMesh_Deleted) + Standard_Integer aLastLiveItem = NbLinks(); + while (!myDelLinks.IsEmpty()) + { + while (aLastLiveItem > 0) + { + if (GetLink(aLastLiveItem).Movability() != BRepMesh_Deleted) break; + myLinks.RemoveLast(); - lastNonDelItem--; + --aLastLiveItem; } - IndexDelItem = myDelLinks.First(); + Standard_Integer aDelItem = myDelLinks.First(); myDelLinks.RemoveFirst(); - if (IndexDelItem < lastNonDelItem) { - BRepMesh_Edge lItem=myLinks.FindKey(lastNonDelItem); - BRepMesh_PairOfIndex Data(myLinks(lastNonDelItem)); - myLinks.RemoveLast(); - myLinks.Substitute(IndexDelItem, lItem, Data); - myLinkOfDomain.Remove(lastNonDelItem); - myLinkOfDomain.Add(IndexDelItem); - lastNonDelItem--; + if (aDelItem > aLastLiveItem) + continue; - Standard_Integer iv[2], ivx; - iv[0]=lItem.FirstNode(); - iv[1]=lItem.LastNode(); + BRepMesh_Edge aLink = GetLink(aLastLiveItem); + BRepMesh_PairOfIndex& aPair = myLinks(aLastLiveItem); - BRepMesh_ListOfInteger::Iterator itLis; - for (ivx=0; ivx<2; ivx++) { - for (itLis.Init(myNodes(iv[ivx])); - itLis.More(); itLis.Next()) { - if (itLis.Value()==(lastNonDelItem+1)) { - itLis.ChangeValue()=IndexDelItem; - break; - } + myLinks.RemoveLast(); + myLinks.Substitute(aDelItem, aLink, aPair); + + myLinksOfDomain.Remove(aLastLiveItem); + myLinksOfDomain.Add(aDelItem); + --aLastLiveItem; + + const Standard_Integer aLastLiveItemId = aLastLiveItem + 1; + BRepMeshCol::ListOfInteger::Iterator aLinkIt; + // update link references + for (Standard_Integer i = 0; i < 2; ++i) + { + const Standard_Integer aCurNodeId = (i == 0) ? + aLink.FirstNode() : aLink.LastNode(); + + for (aLinkIt.Init(myNodes(aCurNodeId)); aLinkIt.More(); aLinkIt.Next()) + { + Standard_Integer& aLinkId = aLinkIt.ChangeValue(); + if (aLinkId == aLastLiveItemId) + { + aLinkId = aDelItem; + break; } } - for(Standard_Integer j = 1, jn = Data.Extent(); j <= jn; j++) { - const BRepMesh_Triangle& Elem=myElements.FindKey(Data.Index(j)); + } - Standard_Integer el[3], iel; - Standard_Boolean orl[3]; - Elem.Edges(el[0], el[1], el[2], orl[0], orl[1], orl[2]); - for (iel=0; iel<3; iel++) { - if (el[iel]==lastNonDelItem+1) { - el[iel]=IndexDelItem; - break; - } + // update elements references + for(Standard_Integer j = 1, jn = aPair.Extent(); j <= jn; ++j) + { + const BRepMesh_Triangle& aElement = GetElement(aPair.Index(j)); + + Standard_Integer e[3]; + Standard_Boolean o[3]; + aElement.Edges(e, o); + for (Standard_Integer i = 0; i < 3; ++i) + { + if (e[i] == aLastLiveItemId) + { + e[i] = aDelItem; + break; } - myElements.Substitute(itLis.Value(), - BRepMesh_Triangle(el[0], el[1], el[2], - orl[0], orl[1], orl[2], - Elem.Movability() )); } + + myElements.Substitute(aLinkIt.Value(), + BRepMesh_Triangle(e, o, aElement.Movability())); } } +} +//======================================================================= +//function : clearDeletedNodes +//purpose : +//======================================================================= +void BRepMesh_DataStructureOfDelaun::clearDeletedNodes() +{ + BRepMeshCol::ListOfInteger& aDelNodes = + (BRepMeshCol::ListOfInteger&)myNodes.GetListOfDelNodes(); - // Process Nodes: - lastNonDelItem = myNodes.Extent(); - BRepMesh_ListOfInteger &aDelNodes = (BRepMesh_ListOfInteger &)myNodes.GetListOfDelNodes(); - - while (!aDelNodes.IsEmpty()) { - while (lastNonDelItem > 0) { - if (myNodes.FindKey(lastNonDelItem).Movability()!=BRepMesh_Deleted) + Standard_Integer aLastLiveItem = NbNodes(); + while (!aDelNodes.IsEmpty()) + { + while (aLastLiveItem > 0) + { + if (GetNode(aLastLiveItem).Movability() != BRepMesh_Deleted) break; + myNodes.RemoveLast(); - lastNonDelItem--; + --aLastLiveItem; } - IndexDelItem = aDelNodes.First(); + + Standard_Integer aDelItem = aDelNodes.First(); aDelNodes.RemoveFirst(); - if (IndexDelItem aLastLiveItem) + continue; - BRepMesh_ListOfInteger::Iterator itLi; - for (itLi.Init(Data); itLi.More(); itLi.Next()) { - const BRepMesh_Edge& li=myLinks.FindKey(itLi.Value()); - BRepMesh_PairOfIndex conx(myLinks(itLi.Value())); - Standard_Integer iv1=li.FirstNode(); - Standard_Integer iv2=li.LastNode(); - if (iv1==lastNonDelItem+1) iv1=IndexDelItem; - else if (iv2==lastNonDelItem+1) iv2=IndexDelItem; + BRepMesh_Vertex aNode = GetNode(aLastLiveItem); + BRepMeshCol::ListOfInteger& aLinkList = myNodes(aLastLiveItem); - myLinks.Substitute(itLi.Value(), - BRepMesh_Edge(iv1, iv2, li.Movability()), conx); - } + myNodes.RemoveLast(); + --aLastLiveItem; + + myNodes.Substitute(aDelItem, aNode, aLinkList); + + const Standard_Integer aLastLiveItemId = aLastLiveItem + 1; + BRepMeshCol::ListOfInteger::Iterator aLinkIt(aLinkList); + for (; aLinkIt.More(); aLinkIt.Next()) + { + const Standard_Integer aLinkId = aLinkIt.Value(); + const BRepMesh_Edge& aLink = GetLink(aLinkId); + BRepMesh_PairOfIndex& aPair = myLinks(aLinkId); + + Standard_Integer v[2] = { aLink.FirstNode(), aLink.LastNode() }; + if (v[0] == aLastLiveItemId) + v[0] = aDelItem; + else if (v[1] == aLastLiveItemId) + v[1] = aDelItem; + + myLinks.Substitute(aLinkId, + BRepMesh_Edge(v[0], v[1], aLink.Movability()), aPair); } } } @@ -638,35 +474,77 @@ void BRepMesh_DataStructureOfDelaun::ClearDeleted() //function : Statistics //purpose : //======================================================================= -void BRepMesh_DataStructureOfDelaun::Statistics(Standard_OStream& S) const +void BRepMesh_DataStructureOfDelaun::Statistics(Standard_OStream& theStream) const { - S << " Map de nodes : \n"; - myNodes.Statistics(S); - S << "\n Deleted nodes : " << myNodes.GetListOfDelNodes().Extent() << endl; + theStream << " Map of nodes : \n"; + myNodes.Statistics(theStream); + theStream << "\n Deleted nodes : " << myNodes.GetListOfDelNodes().Extent() << endl; - S << "\n\n Map de Links : \n"; - myLinks.Statistics(S); - S << "\n Deleted links : " << myDelLinks.Extent() << endl; + theStream << "\n\n Map of Links : \n"; + myLinks.Statistics(theStream); + theStream << "\n Deleted links : " << myDelLinks.Extent() << endl; - S << "\n\n Map d elements : \n"; - myElements.Statistics(S); - // Not_Debuged_Yet S << "\n Deleted elements : " << myDelElements.Extent() << endl; + theStream << "\n\n Map of elements : \n"; + myElements.Statistics(theStream); } //======================================================================= -//function : Allocator() +//function : BRepMesh_Write //purpose : +// Global function not declared in any public header, intended for use +// from debugger prompt (Command Window in Visual Studio). +// +// Stores the mesh data structure to BRep file with the given name. //======================================================================= -const BRepMesh_BaseAllocator& BRepMesh_DataStructureOfDelaun::Allocator() const +Standard_CString BRepMesh_Dump(void* theMeshHandlePtr, + Standard_CString theFileNameStr) { - return myAllocator; -} + if (theMeshHandlePtr == 0 || theFileNameStr == 0) + { + return "Error: file name or mesh data is null"; + } -//======================================================================= -//function : Data -//purpose : -//======================================================================= -BRepMesh_VertexTool& BRepMesh_DataStructureOfDelaun::Data() -{ - return myNodes; + Handle(BRepMesh_DataStructureOfDelaun) aMeshData = + *(Handle(BRepMesh_DataStructureOfDelaun)*)theMeshHandlePtr; + + if (aMeshData.IsNull()) + return "Error: mesh data is empty"; + + TopoDS_Compound aMesh; + BRep_Builder aBuilder; + aBuilder.MakeCompound(aMesh); + + try + { + OCC_CATCH_SIGNALS + + BRepMeshCol::MapOfInteger::Iterator aLinksIt(aMeshData->LinksOfDomain()); + for (; aLinksIt.More(); aLinksIt.Next()) + { + const BRepMesh_Edge& aLink = aMeshData->GetLink(aLinksIt.Value()); + gp_Pnt aPnt[2]; + for (Standard_Integer i = 0; i < 2; ++i) + { + const Standard_Integer aNodeId = + (i == 0) ? aLink.FirstNode() : aLink.LastNode(); + + const gp_XY& aNode = aMeshData->GetNode(aNodeId).Coord(); + aPnt[i] = gp_Pnt(aNode.X(), aNode.Y(), 0.); + } + + if (aPnt[0].SquareDistance(aPnt[1]) < Precision::SquareConfusion()) + continue; + + aBuilder.Add(aMesh, BRepBuilderAPI_MakeEdge(aPnt[0], aPnt[1])); + } + + if (!BRepTools::Write(aMesh, theFileNameStr)) + return "Error: write failed"; + } + catch (Standard_Failure) + { + return Standard_Failure::Caught()->GetMessageString(); + } + + return theFileNameStr; } diff --git a/src/BRepMesh/BRepMesh_DataStructureOfDelaun.hxx b/src/BRepMesh/BRepMesh_DataStructureOfDelaun.hxx new file mode 100644 index 0000000000..3b80b8a744 --- /dev/null +++ b/src/BRepMesh/BRepMesh_DataStructureOfDelaun.hxx @@ -0,0 +1,319 @@ +// Copyright (c) 2013 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 _BRepMesh_DataStructureOfDelaun_HeaderFile +#define _BRepMesh_DataStructureOfDelaun_HeaderFile + +#include +#include +#include +#include +#include +#include +#include +#include + +class BRepMesh_Vertex; +class BRepMesh_VertexTool; +class BRepMesh_Edge; + +//! Describes the data structure necessary for the mesh algorithms in +//! two dimensions plane or on surface by meshing in UV space. +class BRepMesh_DataStructureOfDelaun : public Standard_Transient +{ +public: + + //! Constructor. + //! \param theAllocator memory allocator to be used by internal structures. + //! \param theReservedNodeSize presumed number of nodes in this mesh. + Standard_EXPORT BRepMesh_DataStructureOfDelaun( + const BRepMeshCol::Allocator& theAllocator, + const Standard_Integer theReservedNodeSize = 100); + + + +public: //! \name API for accessing mesh nodes. + + //! Returns number of nodes. + inline Standard_Integer NbNodes() const + { + return myNodes.Extent(); + } + + + //! Adds node to the mesh if it is not already in the mesh. + //! \param theNode node to be added to the mesh. + //! \return index of the node in the structure. + inline Standard_Integer AddNode(const BRepMesh_Vertex& theNode) + { + return myNodes.Add(theNode); + } + + //! Finds the index of the given node. + //! \param theNode node to find. + //! \return index of the given element of zero if node is not in the mesh. + Standard_EXPORT Standard_Integer IndexOf(const BRepMesh_Vertex& theNode) + { + return myNodes.FindIndex(theNode); + } + + //! Get node by the index. + //! \param theIndex index of a node. + //! \return node with the given index. + inline const BRepMesh_Vertex& GetNode(const Standard_Integer theIndex) + { + return myNodes.FindKey(theIndex); + } + + //! Alias for GetNode. + const BRepMesh_Vertex& operator ()(const Standard_Integer theIndex) + { + return GetNode(theIndex); + } + + //! Replaces nodes of mesh by the given ones. + //! \param theNewNodes nodes to be set instead of existing ones. + Standard_EXPORT void ReplaceNodes(const BRepMesh_VertexTool& theNewNodes) + { + if (theNewNodes.IsEmpty()) + return; + + myNodes = theNewNodes; + } + + //! Substitutes the node with the given index by new one. + //! \param theIndex index of node to be substituted. + //! \param theNewNode substituting node. + //! \return FALSE in case if new node is already in the structure, TRUE elsewhere. + Standard_EXPORT Standard_Boolean SubstituteNode( + const Standard_Integer theIndex, + const BRepMesh_Vertex& theNewNode); + + //! Removes node from the mesh in case if it has no connected links + //! and its type is Free. + //! \param theIndex index of node to be removed. + //! \param isForce if TRUE node will be removed even if movability + //! is not Free. + Standard_EXPORT void RemoveNode(const Standard_Integer theIndex, + const Standard_Boolean isForce = Standard_False) + { + if (isForce || myNodes.FindKey(theIndex).Movability() == BRepMesh_Free) + { + if (myNodes.FindFromIndex(theIndex).Extent()==0) + myNodes.Delete(theIndex); + } + } + + //! Get list of links attached to the node with the given index. + //! \param theIndex index of node whose links should be retrieved. + //! \return list of links attached to the node. + inline const BRepMeshCol::ListOfInteger& LinksConnectedTo( + const Standard_Integer theIndex) const + { + return myNodes.FindFromIndex(theIndex); + } + + + +public: //! \name API for accessing mesh links. + + //! Returns number of links. + inline Standard_Integer NbLinks() const + { + return myLinks.Extent(); + } + + //! Adds link to the mesh if it is not already in the mesh. + //! \param theLink link to be added to the mesh. + //! \return index of the link in the structure. + Standard_EXPORT Standard_Integer AddLink(const BRepMesh_Edge& theLink); + + //! Finds the index of the given link. + //! \param theLink link to find. + //! \return index of the given element of zero if link is not in the mesh. + Standard_EXPORT Standard_Integer IndexOf(const BRepMesh_Edge& theLink) const + { + return myLinks.FindIndex(theLink); + } + + //! Get link by the index. + //! \param theIndex index of a link. + //! \return link with the given index. + Standard_EXPORT const BRepMesh_Edge& GetLink(const Standard_Integer theIndex) + { + return myLinks.FindKey(theIndex); + } + + //! Returns map of indices of links registered in mesh. + inline const BRepMeshCol::MapOfInteger& LinksOfDomain() const + { + return myLinksOfDomain; + } + + //! Substitutes the link with the given index by new one. + //! \param theIndex index of link to be substituted. + //! \param theNewLink substituting link. + //! \return FALSE in case if new link is already in the structure, TRUE elsewhere. + Standard_EXPORT Standard_Boolean SubstituteLink(const Standard_Integer theIndex, + const BRepMesh_Edge& theNewLink); + + //! Removes link from the mesh in case if it has no connected elements + //! and its type is Free. + //! \param theIndex index of link to be removed. + //! \param isForce if TRUE link will be removed even if movability + //! is not Free. + Standard_EXPORT void RemoveLink(const Standard_Integer theIndex, + const Standard_Boolean isForce = Standard_False); + + //! Returns indices of elements conected to the link with the given index. + //! \param theLinkIndex index of link whose data should be retrieved. + //! \return indices of elements conected to the link. + Standard_EXPORT const BRepMesh_PairOfIndex& ElementsConnectedTo( + const Standard_Integer theLinkIndex) const + { + return myLinks.FindFromIndex(theLinkIndex); + } + + + +public: //! \name API for accessing mesh elements. + + //! Returns number of links. + inline Standard_Integer NbElements() const + { + return myElements.Extent(); + } + + //! Adds element to the mesh if it is not already in the mesh. + //! \param theElement element to be added to the mesh. + //! \return index of the element in the structure. + Standard_EXPORT Standard_Integer AddElement(const BRepMesh_Triangle& theElement); + + //! Finds the index of the given element. + //! \param theElement element to find. + //! \return index of the given element of zero if element is not in the mesh. + Standard_EXPORT Standard_Integer IndexOf(const BRepMesh_Triangle& theElement) const + { + return myElements.FindIndex(theElement); + } + + //! Get element by the index. + //! \param theIndex index of an element. + //! \return element with the given index. + Standard_EXPORT const BRepMesh_Triangle& GetElement(const Standard_Integer theIndex) + { + return myElements.FindKey(theIndex); + } + + //! Returns map of indices of elements registered in mesh. + inline const BRepMeshCol::MapOfInteger& ElementsOfDomain() const + { + return myElementsOfDomain; + } + + //! Substitutes the element with the given index by new one. + //! \param theIndex index of element to be substituted. + //! \param theNewLink substituting element. + //! \return FALSE in case if new element is already in the structure, TRUE elsewhere. + Standard_EXPORT Standard_Boolean SubstituteElement(const Standard_Integer theIndex, + const BRepMesh_Triangle& theNewElement); + + //! Removes element from the mesh. + //! \param theIndex index of element to be removed. + Standard_EXPORT void RemoveElement(const Standard_Integer theIndex); + + //! Returns indices of nodes forming the given element. + //! \param theElement element which nodes should be retrieved. + //! \param[out] theNodes nodes of the given element. + Standard_EXPORT void ElementNodes( + const BRepMesh_Triangle& theElement, + Standard_Integer (&theNodes)[3]); + + + +public: //! \name Auxilary API + + //! Dumps information about this structure. + //! \param theStream stream to be used for dump. + Standard_EXPORT void Statistics(Standard_OStream& theStream) const; + + //! Returns memory allocator used by the structure. + inline const BRepMeshCol::Allocator& Allocator() const + { + return myAllocator; + } + + //! Gives the data structure for initialization of cell size and tolerance. + inline BRepMesh_VertexTool& Data() + { + return myNodes; + } + + //! Removes all elements. + Standard_EXPORT void ClearDomain(); + + //! Substitutes deleted items by the last one from corresponding map + //! to have only non-deleted elements, links or nodes in the structure. + Standard_EXPORT void ClearDeleted() + { + clearDeletedLinks(); + clearDeletedNodes(); + } + + DEFINE_STANDARD_RTTI(BRepMesh_DataStructureOfDelaun) + +private: + + //! Substitutes deleted links by the last one from corresponding map + //! to have only non-deleted links in the structure. + Standard_EXPORT void clearDeletedLinks(); + + //! Substitutes deleted nodes by the last one from corresponding map + //! to have only non-deleted nodes in the structure. + Standard_EXPORT void clearDeletedNodes(); + + //! Cleans dependent structures from the given link. + //! \param theIndex index of link in the data structure. + //! \param theLink reference to the link to avoid double accessing + //! to map of links. + void cleanLink(const Standard_Integer theIndex, + const BRepMesh_Edge& theLink); + + //! Cleans dependent structures from the given element. + //! \param theIndex index of element in the data structure. + //! \param theElement reference to the element to avoid double accessing + //! to map of elements. + void cleanElement(const Standard_Integer theIndex, + const BRepMesh_Triangle& theElement); + + //! Removes element index from the given pair. Used by cleanElement. + //! \param theIndex index of element to be removed. + //! \param thePair pair of elements to be cleaned. + void removeElementIndex(const Standard_Integer theIndex, + BRepMesh_PairOfIndex& thePair); + + +private: + + BRepMesh_VertexTool myNodes; + BRepMeshCol::IDMapOfLink myLinks; + BRepMeshCol::ListOfInteger myDelLinks; + BRepMeshCol::IMapOfElement myElements; + BRepMeshCol::MapOfInteger myElementsOfDomain; + BRepMeshCol::MapOfInteger myLinksOfDomain; + BRepMeshCol::Allocator myAllocator; +}; + +DEFINE_STANDARD_HANDLE(BRepMesh_DataStructureOfDelaun,Standard_Transient) + +#endif diff --git a/src/BRepMesh/BRepMesh_ClassifierPtr.hxx b/src/BRepMesh/BRepMesh_DegreeOfFreedom.hxx similarity index 65% rename from src/BRepMesh/BRepMesh_ClassifierPtr.hxx rename to src/BRepMesh/BRepMesh_DegreeOfFreedom.hxx index 6d8ec6f019..40844595b2 100644 --- a/src/BRepMesh/BRepMesh_ClassifierPtr.hxx +++ b/src/BRepMesh/BRepMesh_DegreeOfFreedom.hxx @@ -1,6 +1,4 @@ -// Created on: 2009-02-02 -// Created by: Pavel TELKOV -// Copyright (c) 2009-2014 OPEN CASCADE SAS +// Copyright (c) 2013 OPEN CASCADE SAS // // This file is part of Open CASCADE Technology software library. // @@ -13,12 +11,19 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#ifndef BRepMesh_ClassifierPtr_HeaderFile -#define BRepMesh_ClassifierPtr_HeaderFile -#include +#ifndef _BRepMesh_DegreeOfFreedom_HeaderFile +#define _BRepMesh_DegreeOfFreedom_HeaderFile -class BRepMesh_Classifier; -typedef NCollection_Handle BRepMesh_ClassifierPtr; +enum BRepMesh_DegreeOfFreedom +{ + BRepMesh_Free, + BRepMesh_InVolume, + BRepMesh_OnSurface, + BRepMesh_OnCurve, + BRepMesh_Fixed, + BRepMesh_Frontier, + BRepMesh_Deleted +}; #endif diff --git a/src/BRepMesh/BRepMesh_Delaun.cxx b/src/BRepMesh/BRepMesh_Delaun.cxx index a536814e2a..aa628f9f2d 100644 --- a/src/BRepMesh/BRepMesh_Delaun.cxx +++ b/src/BRepMesh/BRepMesh_Delaun.cxx @@ -25,23 +25,7 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include #include -#include -#include -#include #include #include @@ -49,23 +33,50 @@ #include -typedef TColStd_ListIteratorOfListOfInteger IteratorOnListOfInteger; -typedef TColStd_ListOfInteger ListOfInteger; +#include const Standard_Real AngDeviation1Deg = M_PI/180.; const Standard_Real AngDeviation90Deg = 90 * AngDeviation1Deg; const Standard_Real Angle2PI = 2 * M_PI; -const Standard_Real Precision = Precision::PConfusion(); -const Standard_Real Precision2 = Precision * Precision; -const gp_XY SortingDirection(M_SQRT1_2, M_SQRT1_2); +const Standard_Real Precision = Precision::PConfusion(); +const Standard_Real Precision2 = Precision * Precision; + +namespace { + //! Sort two points in projection on vector (1,1) + struct ComparatorOfVertexOfDelaun + { + bool operator() (const BRepMesh_Vertex& theLeft, const BRepMesh_Vertex& theRight) + { + return theLeft.Coord().X() + theLeft.Coord().Y() < theRight.Coord().X() + theRight.Coord().Y(); + } + }; + + //! Sort two points in projection on vector (1,1) + struct ComparatorOfIndexedVertexOfDelaun + { + public: + ComparatorOfIndexedVertexOfDelaun (const Handle(BRepMesh_DataStructureOfDelaun)& theDS) + : myStructure(theDS) {} + + bool operator() (Standard_Integer theLeft, Standard_Integer theRight) + { + const BRepMesh_Vertex& aLeft = myStructure->GetNode(theLeft); + const BRepMesh_Vertex& aRight = myStructure->GetNode(theRight); + return ComparatorOfVertexOfDelaun() (aLeft, aRight); + } + + private: + Handle(BRepMesh_DataStructureOfDelaun) myStructure; + }; +} // anonymous namespace //======================================================================= //function : BRepMesh_Delaun //purpose : Creates the triangulation with an empty Mesh data structure //======================================================================= -BRepMesh_Delaun::BRepMesh_Delaun( BRepMesh_Array1OfVertexOfDelaun& theVertices, - const Standard_Boolean isPositive ) +BRepMesh_Delaun::BRepMesh_Delaun( BRepMeshCol::Array1OfVertexOfDelaun& theVertices, + const Standard_Boolean isPositive ) : myIsPositiveOrientation( isPositive ), myCircles( theVertices.Length(), new NCollection_IncAllocator() ) { @@ -82,7 +93,7 @@ BRepMesh_Delaun::BRepMesh_Delaun( BRepMesh_Array1OfVertexOfDelaun& theVertices, //purpose : Creates the triangulation with and existent Mesh data structure //======================================================================= BRepMesh_Delaun::BRepMesh_Delaun( const Handle( BRepMesh_DataStructureOfDelaun )& theOldMesh, - BRepMesh_Array1OfVertexOfDelaun& theVertices, + BRepMeshCol::Array1OfVertexOfDelaun& theVertices, const Standard_Boolean isPositive ) : myIsPositiveOrientation( isPositive ), myCircles( theVertices.Length(), theOldMesh->Allocator() ) @@ -97,7 +108,7 @@ BRepMesh_Delaun::BRepMesh_Delaun( const Handle( BRepMesh_DataStructureOfDelaun ) //purpose : Creates the triangulation with and existent Mesh data structure //======================================================================= BRepMesh_Delaun::BRepMesh_Delaun( const Handle( BRepMesh_DataStructureOfDelaun )& theOldMesh, - TColStd_Array1OfInteger& theVertexIndices, + BRepMeshCol::Array1OfInteger& theVertexIndices, const Standard_Boolean isPositive ) : myIsPositiveOrientation( isPositive ), myCircles( theVertexIndices.Length(), theOldMesh->Allocator() ) @@ -119,12 +130,12 @@ BRepMesh_Delaun::BRepMesh_Delaun( const Handle( BRepMesh_DataStructureOfDelaun ) //function : Init //purpose : Initializes the triangulation with an Array of Vertex //======================================================================= -void BRepMesh_Delaun::Init( BRepMesh_Array1OfVertexOfDelaun& theVertices ) +void BRepMesh_Delaun::Init( BRepMeshCol::Array1OfVertexOfDelaun& theVertices ) { Bnd_Box2d aBox; Standard_Integer aLowerIdx = theVertices.Lower(); Standard_Integer anUpperIdx = theVertices.Upper(); - TColStd_Array1OfInteger aVertexIndexes( aLowerIdx, anUpperIdx ); + BRepMeshCol::Array1OfInteger aVertexIndexes( aLowerIdx, anUpperIdx ); Standard_Integer anIndex = aLowerIdx; for ( ; anIndex <= anUpperIdx; ++anIndex ) @@ -140,15 +151,15 @@ void BRepMesh_Delaun::Init( BRepMesh_Array1OfVertexOfDelaun& theVertices ) //function : perform //purpose : Create super mesh and run triangulation procedure //======================================================================= -void BRepMesh_Delaun::perform( Bnd_Box2d& theBndBox, - TColStd_Array1OfInteger& theVertexIndexes ) +void BRepMesh_Delaun::perform( Bnd_Box2d& theBndBox, + BRepMeshCol::Array1OfInteger& theVertexIndexes ) { theBndBox.Enlarge( Precision ); superMesh( theBndBox ); - BRepMesh_HeapSortIndexedVertexOfDelaun::Sort( theVertexIndexes, - BRepMesh_ComparatorOfIndexedVertexOfDelaun( SortingDirection, - Precision, myMeshData ) ); + ComparatorOfIndexedVertexOfDelaun aCmp(myMeshData); + std::make_heap(theVertexIndexes.begin(), theVertexIndexes.end(), aCmp); + std::sort_heap(theVertexIndexes.begin(), theVertexIndexes.end(), aCmp); compute( theVertexIndexes ); } @@ -196,20 +207,20 @@ void BRepMesh_Delaun::superMesh( const Bnd_Box2d& theBox ) mySupVert[2] = aTmp; } - Standard_Integer anEdgeId[3]; - + Standard_Integer e[3]; + Standard_Boolean o[3]; for (Standard_Integer aNodeId = 0; aNodeId < 3; ++aNodeId) { Standard_Integer aFirstNode = aNodeId; Standard_Integer aLastNode = (aNodeId + 1) % 3; - anEdgeId[aNodeId] = myMeshData->AddLink( BRepMesh_Edge( + Standard_Integer aLinkIndex = myMeshData->AddLink( BRepMesh_Edge( mySupVert[aFirstNode], mySupVert[aLastNode], BRepMesh_Free ) ); + + e[aNodeId] = Abs(aLinkIndex); + o[aNodeId] = (aLinkIndex > 0); } - mySupTrian = BRepMesh_Triangle( - Abs( anEdgeId[0] ), Abs( anEdgeId[1] ), Abs( anEdgeId[2] ), - ( anEdgeId[0] > 0 ), ( anEdgeId[1] > 0 ), ( anEdgeId[2] > 0), - BRepMesh_Free); + mySupTrian = BRepMesh_Triangle(e, o, BRepMesh_Free); } //======================================================================= @@ -218,15 +229,14 @@ void BRepMesh_Delaun::superMesh( const Bnd_Box2d& theBox ) // edges into the map. // When an edge is suppressed more than one time it is destroyed. //======================================================================= -void BRepMesh_Delaun::deleteTriangle( const Standard_Integer theIndex, - BRepMesh_MapOfIntegerInteger& theLoopEdges ) +void BRepMesh_Delaun::deleteTriangle( const Standard_Integer theIndex, + BRepMeshCol::MapOfIntegerInteger& theLoopEdges ) { myCircles.Delete( theIndex ); Standard_Integer e[3]; Standard_Boolean o[3]; - GetTriangle( theIndex ).Edges( e[0], e[1], e[2], - o[0], o[1], o[2] ); + GetTriangle( theIndex ).Edges( e, o ); myMeshData->RemoveElement( theIndex ); @@ -245,14 +255,13 @@ void BRepMesh_Delaun::deleteTriangle( const Standard_Integer theIndex, //purpose : Computes the triangulation and add the vertices edges and // triangles to the Mesh data structure //======================================================================= -void BRepMesh_Delaun::compute( TColStd_Array1OfInteger& theVertexIndexes ) +void BRepMesh_Delaun::compute( BRepMeshCol::Array1OfInteger& theVertexIndexes ) { // Insertion of edges of super triangles in the list of free edges: - BRepMesh_MapOfIntegerInteger aLoopEdges( 10, myMeshData->Allocator() ); + BRepMeshCol::MapOfIntegerInteger aLoopEdges( 10, myMeshData->Allocator() ); Standard_Integer e[3]; Standard_Boolean o[3]; - mySupTrian.Edges( e[0], e[1], e[2], - o[0], o[1], o[2] ); + mySupTrian.Edges( e, o ); aLoopEdges.Bind( e[0], Standard_True ); aLoopEdges.Bind( e[1], Standard_True ); @@ -274,16 +283,16 @@ void BRepMesh_Delaun::compute( TColStd_Array1OfInteger& theVertexIndexes ) aSelector.NeighboursOfNode( mySupVert[aSupVertId] ); aLoopEdges.Clear(); - BRepMesh_MapOfInteger::Iterator aFreeTriangles( aSelector.Elements() ); + BRepMeshCol::MapOfInteger::Iterator aFreeTriangles( aSelector.Elements() ); for ( ; aFreeTriangles.More(); aFreeTriangles.Next() ) deleteTriangle( aFreeTriangles.Key(), aLoopEdges ); // All edges that remain free are removed from aLoopEdges; // only the boundary edges of the triangulation remain there - BRepMesh_MapOfIntegerInteger::Iterator aFreeEdges( aLoopEdges ); + BRepMeshCol::MapOfIntegerInteger::Iterator aFreeEdges( aLoopEdges ); for ( ; aFreeEdges.More(); aFreeEdges.Next() ) { - if ( myMeshData->ElemConnectedTo( aFreeEdges.Key() ).IsEmpty() ) + if ( myMeshData->ElementsConnectedTo( aFreeEdges.Key() ).IsEmpty() ) myMeshData->RemoveLink( aFreeEdges.Key() ); } @@ -296,13 +305,13 @@ void BRepMesh_Delaun::compute( TColStd_Array1OfInteger& theVertexIndexes ) //function : createTriangles //purpose : Creates the triangles beetween the node and the polyline. //======================================================================= -void BRepMesh_Delaun::createTriangles ( const Standard_Integer theVertexIndex, - BRepMesh_MapOfIntegerInteger& thePoly ) +void BRepMesh_Delaun::createTriangles ( const Standard_Integer theVertexIndex, + BRepMeshCol::MapOfIntegerInteger& thePoly ) { - ListOfInteger aLoopEdges, anExternalEdges; + BRepMeshCol::ListOfInteger aLoopEdges, anExternalEdges; const gp_XY& aVertexCoord = myMeshData->GetNode( theVertexIndex ).Coord(); - BRepMesh_MapOfIntegerInteger::Iterator anEdges( thePoly ); + BRepMeshCol::MapOfIntegerInteger::Iterator anEdges( thePoly ); for ( ; anEdges.More(); anEdges.Next() ) { Standard_Integer anEdgeId = anEdges.Key(); @@ -391,7 +400,7 @@ void BRepMesh_Delaun::createTriangles ( const Standard_Integer theVertexI while ( !anExternalEdges.IsEmpty() ) { const BRepMesh_PairOfIndex& aPair = - myMeshData->ElemConnectedTo( Abs( anExternalEdges.First() ) ); + myMeshData->ElementsConnectedTo( Abs( anExternalEdges.First() ) ); if ( !aPair.IsEmpty() ) @@ -402,7 +411,7 @@ void BRepMesh_Delaun::createTriangles ( const Standard_Integer theVertexI for ( anEdges.Initialize( thePoly ); anEdges.More(); anEdges.Next() ) { - if ( myMeshData->ElemConnectedTo( anEdges.Key() ).IsEmpty() ) + if ( myMeshData->ElementsConnectedTo( anEdges.Key() ).IsEmpty() ) myMeshData->RemoveLink( anEdges.Key() ); } @@ -423,9 +432,9 @@ void BRepMesh_Delaun::createTriangles ( const Standard_Integer theVertexI //function : createTrianglesOnNewVertices //purpose : Creation of triangles from the new nodes //======================================================================= -void BRepMesh_Delaun::createTrianglesOnNewVertices( TColStd_Array1OfInteger& theVertexIndexes ) +void BRepMesh_Delaun::createTrianglesOnNewVertices( BRepMeshCol::Array1OfInteger& theVertexIndexes ) { - BRepMesh_MapOfIntegerInteger aLoopEdges( 10, myMeshData->Allocator() ); + BRepMeshCol::MapOfIntegerInteger aLoopEdges( 10, myMeshData->Allocator() ); // Insertion of nodes : Standard_Boolean isModify = Standard_True; @@ -440,10 +449,10 @@ void BRepMesh_Delaun::createTrianglesOnNewVertices( TColStd_Array1OfInteger& the const BRepMesh_Vertex& aVertex = GetVertex( aVertexIdx ); // Iterator in the list of indexes of circles containing the node - BRepMesh_ListOfInteger& aCirclesList = myCircles.Select( aVertex.Coord() ); + BRepMeshCol::ListOfInteger& aCirclesList = myCircles.Select( aVertex.Coord() ); Standard_Integer onEgdeId = 0, aTriangleId = 0; - BRepMesh_ListOfInteger::Iterator aCircleIt( aCirclesList ); + BRepMeshCol::ListOfInteger::Iterator aCircleIt( aCirclesList ); for ( ; aCircleIt.More(); aCircleIt.Next() ) { // To add a node in the mesh it is necessary to check conditions: @@ -474,13 +483,12 @@ void BRepMesh_Delaun::createTrianglesOnNewVertices( TColStd_Array1OfInteger& the while ( isModify && !aCirclesList.IsEmpty() ) { isModify = Standard_False; - BRepMesh_ListOfInteger::Iterator aCircleIt1( aCirclesList ); + BRepMeshCol::ListOfInteger::Iterator aCircleIt1( aCirclesList ); for ( ; aCircleIt1.More(); aCircleIt1.Next() ) { Standard_Integer e[3]; Standard_Boolean o[3]; - GetTriangle( aCircleIt1.Value() ).Edges( e[0], e[1], e[2], - o[0], o[1], o[2] ); + GetTriangle( aCircleIt1.Value() ).Edges( e, o ); if ( aLoopEdges.IsBound( e[0] ) || aLoopEdges.IsBound( e[1] ) || @@ -500,15 +508,15 @@ void BRepMesh_Delaun::createTrianglesOnNewVertices( TColStd_Array1OfInteger& the } } // Check that internal edges are not crossed by triangles - Handle(BRepMesh_MapOfInteger) anInternalEdges = InternalEdges(); + BRepMeshCol::HMapOfInteger anInternalEdges = InternalEdges(); // Destruction of triancles intersecting internal edges // and their replacement by makeshift triangles - BRepMesh_MapOfInteger::Iterator anInernalEdgesIt( *anInternalEdges ); + BRepMeshCol::MapOfInteger::Iterator anInernalEdgesIt( *anInternalEdges ); for ( ; anInernalEdgesIt.More(); anInernalEdgesIt.Next() ) { Standard_Integer aNbC; - aNbC = myMeshData->ElemConnectedTo( anInernalEdgesIt.Key() ).Extent(); + aNbC = myMeshData->ElementsConnectedTo( anInernalEdgesIt.Key() ).Extent(); if ( aNbC == 0 ) { meshLeftPolygonOf( anInernalEdgesIt.Key(), Standard_True ); @@ -535,7 +543,7 @@ Standard_Boolean BRepMesh_Delaun::isBoundToFrontier( const Standard_Integer thePrevElementId) { const BRepMesh_PairOfIndex& aPair = - myMeshData->ElemConnectedTo( theRefLinkId ); + myMeshData->ElementsConnectedTo( theRefLinkId ); if ( aPair.IsEmpty() ) return Standard_False; @@ -548,8 +556,7 @@ Standard_Boolean BRepMesh_Delaun::isBoundToFrontier( Standard_Integer anEdges[3]; Standard_Boolean anEdgesOri[3]; - GetTriangle( aTriId ).Edges( anEdges[0], anEdges[1], anEdges[2], - anEdgesOri[0], anEdgesOri[1], anEdgesOri[2] ); + GetTriangle( aTriId ).Edges( anEdges, anEdgesOri ); for ( Standard_Integer anEdgeIt = 0; anEdgeIt < 3; ++anEdgeIt ) { @@ -585,11 +592,11 @@ void BRepMesh_Delaun::cleanupMesh() { for(;;) { - BRepMesh_MapOfIntegerInteger aLoopEdges( 10, myMeshData->Allocator() ); - NCollection_Map aDelTriangles; + BRepMeshCol::MapOfIntegerInteger aLoopEdges( 10, myMeshData->Allocator() ); + BRepMeshCol::MapOfInteger aDelTriangles; - Handle(BRepMesh_MapOfInteger) aFreeEdges = FreeEdges(); - BRepMesh_MapOfInteger::Iterator aFreeEdgesIt( *aFreeEdges ); + BRepMeshCol::HMapOfInteger aFreeEdges = FreeEdges(); + BRepMeshCol::MapOfInteger::Iterator aFreeEdgesIt( *aFreeEdges ); for ( ; aFreeEdgesIt.More(); aFreeEdgesIt.Next() ) { const Standard_Integer& aFreeEdgeId = aFreeEdgesIt.Key(); @@ -598,7 +605,7 @@ void BRepMesh_Delaun::cleanupMesh() continue; const BRepMesh_PairOfIndex& aPair = - myMeshData->ElemConnectedTo( aFreeEdgeId ); + myMeshData->ElementsConnectedTo( aFreeEdgeId ); if ( aPair.IsEmpty() ) { aLoopEdges.Bind( aFreeEdgeId, Standard_True ); @@ -610,8 +617,7 @@ void BRepMesh_Delaun::cleanupMesh() // Check that the connected triangle is not surrounded by another triangles Standard_Integer anEdges[3]; Standard_Boolean anEdgesOri[3]; - GetTriangle( aTriId ).Edges( anEdges[0], anEdges[1], anEdges[2], - anEdgesOri[0], anEdgesOri[1], anEdgesOri[2] ); + GetTriangle( aTriId ).Edges( anEdges, anEdgesOri ); Standard_Boolean isCanNotBeRemoved = Standard_True; for ( Standard_Integer aCurEdgeIdx = 0; aCurEdgeIdx < 3; ++aCurEdgeIdx ) @@ -623,7 +629,7 @@ void BRepMesh_Delaun::cleanupMesh() { Standard_Integer anOtherEdgeId = ( aCurEdgeIdx + anOtherEdgeIt ) % 3; const BRepMesh_PairOfIndex& anOtherEdgePair = - myMeshData->ElemConnectedTo( anEdges[anOtherEdgeId] ); + myMeshData->ElementsConnectedTo( anEdges[anOtherEdgeId] ); if ( anOtherEdgePair.Extent() < 2 ) { @@ -652,7 +658,7 @@ void BRepMesh_Delaun::cleanupMesh() // Destruction of triangles : Standard_Integer aDeletedTrianglesNb = 0; - NCollection_Map::Iterator aDelTrianglesIt( aDelTriangles ); + BRepMeshCol::MapOfInteger::Iterator aDelTrianglesIt( aDelTriangles ); for ( ; aDelTrianglesIt.More(); aDelTrianglesIt.Next() ) { deleteTriangle( aDelTrianglesIt.Key(), aLoopEdges ); @@ -660,10 +666,10 @@ void BRepMesh_Delaun::cleanupMesh() } // Destruction of remaining hanging edges - BRepMesh_MapOfIntegerInteger::Iterator aLoopEdgesIt( aLoopEdges ); + BRepMeshCol::MapOfIntegerInteger::Iterator aLoopEdgesIt( aLoopEdges ); for ( ; aLoopEdgesIt.More(); aLoopEdgesIt.Next() ) { - if ( myMeshData->ElemConnectedTo( aLoopEdgesIt.Key() ).IsEmpty() ) + if ( myMeshData->ElementsConnectedTo( aLoopEdgesIt.Key() ).IsEmpty() ) myMeshData->RemoveLink( aLoopEdgesIt.Key() ); } @@ -678,21 +684,21 @@ void BRepMesh_Delaun::cleanupMesh() //======================================================================= void BRepMesh_Delaun::frontierAdjust() { - Handle(BRepMesh_MapOfInteger) aFrontier = Frontier(); - NCollection_Vector aFailedFrontiers; - BRepMesh_MapOfIntegerInteger aLoopEdges( 10, myMeshData->Allocator() ); - BRepMesh_Delaun::HandleOfMapOfInteger aIntFrontierEdges = new NCollection_Map(); + BRepMeshCol::HMapOfInteger aFrontier = Frontier(); + BRepMeshCol::VectorOfInteger aFailedFrontiers; + BRepMeshCol::MapOfIntegerInteger aLoopEdges( 10, myMeshData->Allocator() ); + BRepMeshCol::HMapOfInteger aIntFrontierEdges = new BRepMeshCol::MapOfInteger; for ( Standard_Integer aPass = 1; aPass <= 2; ++aPass ) { // 1 pass): find external triangles on boundary edges; // 2 pass): find external triangles on boundary edges appeared // during triangles replacement. - BRepMesh_MapOfInteger::Iterator aFrontierIt( *aFrontier ); + BRepMeshCol::MapOfInteger::Iterator aFrontierIt( *aFrontier ); for ( ; aFrontierIt.More(); aFrontierIt.Next() ) { Standard_Integer aFrontierId = aFrontierIt.Key(); - const BRepMesh_PairOfIndex& aPair = myMeshData->ElemConnectedTo( aFrontierId ); + const BRepMesh_PairOfIndex& aPair = myMeshData->ElementsConnectedTo( aFrontierId ); Standard_Integer aNbElem = aPair.Extent(); for( Standard_Integer aElemIt = 1; aElemIt <= aNbElem; ++aElemIt ) { @@ -702,8 +708,7 @@ void BRepMesh_Delaun::frontierAdjust() Standard_Integer e[3]; Standard_Boolean o[3]; - GetTriangle( aPriorElemId ).Edges( e[0], e[1], e[2], - o[0], o[1], o[2] ); + GetTriangle( aPriorElemId ).Edges( e, o ); Standard_Boolean isTriangleFound = Standard_False; for ( Standard_Integer n = 0; n < 3; ++n ) @@ -723,11 +728,11 @@ void BRepMesh_Delaun::frontierAdjust() } // destrucrion of remaining hanging edges : - BRepMesh_MapOfIntegerInteger::Iterator aLoopEdgesIt( aLoopEdges ); + BRepMeshCol::MapOfIntegerInteger::Iterator aLoopEdgesIt( aLoopEdges ); for ( ; aLoopEdgesIt.More(); aLoopEdgesIt.Next() ) { Standard_Integer aLoopEdgeId = aLoopEdgesIt.Key(); - if (myMeshData->ElemConnectedTo( aLoopEdgeId ).IsEmpty() ) + if (myMeshData->ElementsConnectedTo( aLoopEdgeId ).IsEmpty() ) myMeshData->RemoveLink( aLoopEdgeId ); } @@ -736,7 +741,7 @@ void BRepMesh_Delaun::frontierAdjust() for ( aFrontierIt.Reset(); aFrontierIt.More(); aFrontierIt.Next() ) { Standard_Integer aFrontierId = aFrontierIt.Key(); - if ( !myMeshData->ElemConnectedTo( aFrontierId ).IsEmpty() ) + if ( !myMeshData->ElementsConnectedTo( aFrontierId ).IsEmpty() ) continue; Standard_Boolean isSuccess = @@ -754,11 +759,11 @@ void BRepMesh_Delaun::frontierAdjust() // situation when frontier edge has a triangle at a right side, but its free // links cross another frontieres and meshLeftPolygonOf itself can't collect // a closed polygon. - NCollection_Vector::Iterator aFailedFrontiersIt( aFailedFrontiers ); + BRepMeshCol::VectorOfInteger::Iterator aFailedFrontiersIt( aFailedFrontiers ); for ( ; aFailedFrontiersIt.More(); aFailedFrontiersIt.Next() ) { Standard_Integer aFrontierId = aFailedFrontiersIt.Value(); - if ( !myMeshData->ElemConnectedTo( aFrontierId ).IsEmpty() ) + if ( !myMeshData->ElementsConnectedTo( aFrontierId ).IsEmpty() ) continue; meshLeftPolygonOf( aFrontierId, Standard_True, aIntFrontierEdges ); @@ -770,7 +775,7 @@ void BRepMesh_Delaun::frontierAdjust() //purpose : Add boundig box for edge defined by start & end point to // the given vector of bounding boxes for triangulation edges //======================================================================= -void BRepMesh_Delaun::fillBndBox( NCollection_Sequence& theBoxes, +void BRepMesh_Delaun::fillBndBox( BRepMeshCol::SequenceOfBndB2d& theBoxes, const BRepMesh_Vertex& theV1, const BRepMesh_Vertex& theV2 ) { @@ -787,14 +792,14 @@ void BRepMesh_Delaun::fillBndBox( NCollection_Sequence& theBoxes, Standard_Boolean BRepMesh_Delaun::meshLeftPolygonOf( const Standard_Integer theStartEdgeId, const Standard_Boolean isForward, - BRepMesh_Delaun::HandleOfMapOfInteger theSkipped ) + BRepMeshCol::HMapOfInteger theSkipped ) { if ( !theSkipped.IsNull() && theSkipped->Contains( theStartEdgeId ) ) return Standard_True; const BRepMesh_Edge& aRefEdge = GetEdge( theStartEdgeId ); - TColStd_SequenceOfInteger aPolygon; + BRepMeshCol::SequenceOfInteger aPolygon; Standard_Integer aStartNode, aPivotNode; if ( isForward ) { @@ -822,14 +827,14 @@ Standard_Boolean BRepMesh_Delaun::meshLeftPolygonOf( // Auxilary structures. // Bounding boxes of polygon links to be used for preliminary // analysis of intersections - NCollection_Sequence aBoxes; + BRepMeshCol::SequenceOfBndB2d aBoxes; fillBndBox( aBoxes, aStartEdgeVertexS, aPivotVertex ); // Hanging ends - NCollection_Map aDeadLinks; + BRepMeshCol::MapOfInteger aDeadLinks; // Links are temporarily excluded from consideration - NCollection_Map aLeprousLinks; + BRepMeshCol::MapOfInteger aLeprousLinks; aLeprousLinks.Add( theStartEdgeId ); Standard_Boolean isSkipLeprous = Standard_True; @@ -918,12 +923,12 @@ Standard_Integer BRepMesh_Delaun::findNextPolygonLink( const Standard_Integer& thePivotNode, const BRepMesh_Vertex& thePivotVertex, const gp_Vec2d& theRefLinkDir, - const NCollection_Sequence& theBoxes, - const TColStd_SequenceOfInteger& thePolygon, - const BRepMesh_Delaun::HandleOfMapOfInteger theSkipped, + const BRepMeshCol::SequenceOfBndB2d& theBoxes, + const BRepMeshCol::SequenceOfInteger& thePolygon, + const BRepMeshCol::HMapOfInteger theSkipped, const Standard_Boolean& isSkipLeprous, - NCollection_Map& theLeprousLinks, - NCollection_Map& theDeadLinks, + BRepMeshCol::MapOfInteger& theLeprousLinks, + BRepMeshCol::MapOfInteger& theDeadLinks, Standard_Integer& theNextPivotNode, gp_Vec2d& theNextLinkDir, Bnd_B2d& theNextLinkBndBox ) @@ -934,7 +939,7 @@ Standard_Integer BRepMesh_Delaun::findNextPolygonLink( RealFirst() : RealLast(); Standard_Integer aNextLinkId = 0; - BRepMesh_ListOfInteger::Iterator aLinkIt( myMeshData->LinkNeighboursOf( thePivotNode ) ); + BRepMeshCol::ListOfInteger::Iterator aLinkIt( myMeshData->LinksConnectedTo( thePivotNode ) ); for ( ; aLinkIt.More(); aLinkIt.Next() ) { const Standard_Integer& aNeighbourLinkInfo = aLinkIt.Value(); @@ -954,7 +959,7 @@ Standard_Integer BRepMesh_Delaun::findNextPolygonLink( // Determine whether the link belongs to the mesh if ( aNeighbourLink.Movability() == BRepMesh_Free && - myMeshData->ElemConnectedTo( aNeighbourLinkInfo ).IsEmpty() ) + myMeshData->ElementsConnectedTo( aNeighbourLinkInfo ).IsEmpty() ) { theDeadLinks.Add( aNeighbourLinkId ); continue; @@ -1027,13 +1032,13 @@ Standard_Integer BRepMesh_Delaun::findNextPolygonLink( // parameter. //======================================================================= Standard_Boolean BRepMesh_Delaun::checkIntersection( - const BRepMesh_Edge& theLink, - const TColStd_SequenceOfInteger& thePolygon, - const NCollection_Sequence& thePolyBoxes, - const Standard_Boolean isConsiderEndPointTouch, - const Standard_Boolean isConsiderPointOnEdge, - const Standard_Boolean isSkipLastEdge, - Bnd_B2d& theLinkBndBox ) const + const BRepMesh_Edge& theLink, + const BRepMeshCol::SequenceOfInteger& thePolygon, + const BRepMeshCol::SequenceOfBndB2d& thePolyBoxes, + const Standard_Boolean isConsiderEndPointTouch, + const Standard_Boolean isConsiderPointOnEdge, + const Standard_Boolean isSkipLastEdge, + Bnd_B2d& theLinkBndBox ) const { theLinkBndBox.Add( GetVertex( theLink.FirstNode() ).Coord() ); theLinkBndBox.Add( GetVertex( theLink.LastNode() ).Coord() ); @@ -1059,11 +1064,10 @@ Standard_Boolean BRepMesh_Delaun::checkIntersection( continue; gp_Pnt2d anIntPnt; - BRepMesh_WireInterferenceChecker::IntFlag aIntFlag = - intSegSeg( theLink, aPolyLink, isConsiderEndPointTouch, - isConsiderPointOnEdge, anIntPnt ); + BRepMesh_GeomTool::IntFlag aIntFlag = intSegSeg( theLink, aPolyLink, + isConsiderEndPointTouch, isConsiderPointOnEdge, anIntPnt ); - if ( aIntFlag != BRepMesh_WireInterferenceChecker::NoIntersection ) + if ( aIntFlag != BRepMesh_GeomTool::NoIntersection ) return Standard_False; } } @@ -1081,16 +1085,14 @@ inline void BRepMesh_Delaun::addTriangle( const Standard_Integer (&theEdgesId)[3 const Standard_Integer (&theNodesId)[3] ) { Standard_Integer aNewTriangleId = - myMeshData->AddElement( BRepMesh_Triangle( - theEdgesId[0], theEdgesId[1], theEdgesId[2], - theEdgesOri[0], theEdgesOri[1], theEdgesOri[2], - BRepMesh_Free ) ); + myMeshData->AddElement(BRepMesh_Triangle(theEdgesId, + theEdgesOri, BRepMesh_Free)); - Standard_Boolean isAdded = myCircles.Add( + Standard_Boolean isAdded = myCircles.Bind( + aNewTriangleId, GetVertex( theNodesId[0] ).Coord(), GetVertex( theNodesId[1] ).Coord(), - GetVertex( theNodesId[2] ).Coord(), - aNewTriangleId ); + GetVertex( theNodesId[2] ).Coord() ); if ( !isAdded ) myMeshData->RemoveElement( aNewTriangleId ); @@ -1100,17 +1102,17 @@ inline void BRepMesh_Delaun::addTriangle( const Standard_Integer (&theEdgesId)[3 //function : cleanupPolygon //purpose : Remove internal triangles from the given polygon //======================================================================= -void BRepMesh_Delaun::cleanupPolygon( const TColStd_SequenceOfInteger& thePolygon, - const NCollection_Sequence& thePolyBoxes ) +void BRepMesh_Delaun::cleanupPolygon( const BRepMeshCol::SequenceOfInteger& thePolygon, + const BRepMeshCol::SequenceOfBndB2d& thePolyBoxes ) { Standard_Integer aPolyLen = thePolygon.Length(); if ( aPolyLen < 3 ) return; - BRepMesh_MapOfIntegerInteger aLoopEdges( 10, myMeshData->Allocator() ); - NCollection_Map anIgnoredEdges; - NCollection_Map aPolyVerticesFindMap; - NCollection_Vector aPolyVertices; + BRepMeshCol::MapOfIntegerInteger aLoopEdges( 10, myMeshData->Allocator() ); + BRepMeshCol::MapOfInteger anIgnoredEdges; + BRepMeshCol::MapOfInteger aPolyVerticesFindMap; + BRepMeshCol::VectorOfInteger aPolyVertices; // Collect boundary vertices of the polygon for ( Standard_Integer aPolyIt = 1; aPolyIt <= aPolyLen; ++aPolyIt ) { @@ -1120,7 +1122,7 @@ void BRepMesh_Delaun::cleanupPolygon( const TColStd_SequenceOfInteger& thePo Standard_Boolean isForward = ( aPolyEdgeInfo > 0 ); const BRepMesh_PairOfIndex& aPair = - myMeshData->ElemConnectedTo( aPolyEdgeId ); + myMeshData->ElementsConnectedTo( aPolyEdgeId ); Standard_Integer anElemIt = 1; for ( ; anElemIt <= aPair.Extent(); ++anElemIt ) @@ -1131,8 +1133,7 @@ void BRepMesh_Delaun::cleanupPolygon( const TColStd_SequenceOfInteger& thePo Standard_Integer anEdges[3]; Standard_Boolean anEdgesOri[3]; - GetTriangle( anElemId ).Edges( anEdges[0], anEdges[1], anEdges[2], - anEdgesOri[0], anEdgesOri[1], anEdgesOri[2] ); + GetTriangle( anElemId ).Edges(anEdges, anEdgesOri); Standard_Integer isTriangleFound = Standard_False; for ( Standard_Integer anEdgeIt = 0; anEdgeIt < 3; ++anEdgeIt ) @@ -1177,7 +1178,7 @@ void BRepMesh_Delaun::cleanupPolygon( const TColStd_SequenceOfInteger& thePo if ( aPolyVertices.First() != aPolyVertices.Last() ) aPolyVertices.Append( aPolyVertices.First() ); - NCollection_Map aSurvivedLinks( anIgnoredEdges ); + BRepMeshCol::MapOfInteger aSurvivedLinks( anIgnoredEdges ); Standard_Integer aPolyVertIt = 0; Standard_Integer anUniqueVerticesNum = aPolyVertices.Length() - 1; @@ -1188,14 +1189,14 @@ void BRepMesh_Delaun::cleanupPolygon( const TColStd_SequenceOfInteger& thePo thePolyBoxes, aSurvivedLinks, aLoopEdges ); } - BRepMesh_MapOfIntegerInteger::Iterator aLoopEdgesIt( aLoopEdges ); + BRepMeshCol::MapOfIntegerInteger::Iterator aLoopEdgesIt( aLoopEdges ); for ( ; aLoopEdgesIt.More(); aLoopEdgesIt.Next() ) { const Standard_Integer& aLoopEdgeId = aLoopEdgesIt.Key(); if ( anIgnoredEdges.Contains( aLoopEdgeId ) ) continue; - if ( myMeshData->ElemConnectedTo( aLoopEdgeId ).IsEmpty() ) + if ( myMeshData->ElementsConnectedTo( aLoopEdgeId ).IsEmpty() ) myMeshData->RemoveLink( aLoopEdgesIt.Key() ); } } @@ -1206,19 +1207,19 @@ void BRepMesh_Delaun::cleanupPolygon( const TColStd_SequenceOfInteger& thePo // inside the polygon or crossed it. //======================================================================= void BRepMesh_Delaun::killTrianglesAroundVertex( - const Standard_Integer theZombieNodeId, - const NCollection_Vector& thePolyVertices, - const NCollection_Map& thePolyVerticesFindMap, - const TColStd_SequenceOfInteger& thePolygon, - const NCollection_Sequence& thePolyBoxes, - NCollection_Map& theSurvivedLinks, - BRepMesh_MapOfIntegerInteger& theLoopEdges ) + const Standard_Integer theZombieNodeId, + const BRepMeshCol::VectorOfInteger& thePolyVertices, + const BRepMeshCol::MapOfInteger& thePolyVerticesFindMap, + const BRepMeshCol::SequenceOfInteger& thePolygon, + const BRepMeshCol::SequenceOfBndB2d& thePolyBoxes, + BRepMeshCol::MapOfInteger& theSurvivedLinks, + BRepMeshCol::MapOfIntegerInteger& theLoopEdges ) { - BRepMesh_ListOfInteger::Iterator aNeighborsIt = - myMeshData->LinkNeighboursOf( theZombieNodeId ); + BRepMeshCol::ListOfInteger::Iterator aNeighborsIt = + myMeshData->LinksConnectedTo( theZombieNodeId ); // Try to infect neighbor nodes - NCollection_Vector aVictimNodes; + BRepMeshCol::VectorOfInteger aVictimNodes; for ( ; aNeighborsIt.More(); aNeighborsIt.Next() ) { const Standard_Integer& aNeighborLinkId = aNeighborsIt.Value(); @@ -1276,7 +1277,7 @@ void BRepMesh_Delaun::killTrianglesAroundVertex( } // Go and do your job! - NCollection_Vector::Iterator aVictimIt( aVictimNodes ); + BRepMeshCol::VectorOfInteger::Iterator aVictimIt( aVictimNodes ); for ( ; aVictimIt.More(); aVictimIt.Next() ) { killTrianglesAroundVertex( aVictimIt.Value(), thePolyVertices, @@ -1290,8 +1291,8 @@ void BRepMesh_Delaun::killTrianglesAroundVertex( //purpose : Checks is the given vertex lies inside the polygon //======================================================================= Standard_Boolean BRepMesh_Delaun::isVertexInsidePolygon( - const Standard_Integer& theVertexId, - const NCollection_Vector& thePolygonVertices ) const + const Standard_Integer& theVertexId, + const BRepMeshCol::VectorOfInteger& thePolygonVertices ) const { Standard_Integer aPolyLen = thePolygonVertices.Length(); if ( aPolyLen < 3 ) @@ -1334,10 +1335,10 @@ void BRepMesh_Delaun::killTrianglesOnIntersectingLinks( const Standard_Integer& theLinkToCheckId, const BRepMesh_Edge& theLinkToCheck, const Standard_Integer& theEndPoint, - const TColStd_SequenceOfInteger& thePolygon, - const NCollection_Sequence& thePolyBoxes, - NCollection_Map& theSurvivedLinks, - BRepMesh_MapOfIntegerInteger& theLoopEdges ) + const BRepMeshCol::SequenceOfInteger& thePolygon, + const BRepMeshCol::SequenceOfBndB2d& thePolyBoxes, + BRepMeshCol::MapOfInteger& theSurvivedLinks, + BRepMeshCol::MapOfIntegerInteger& theLoopEdges ) { if ( theSurvivedLinks.Contains( theLinkToCheckId ) ) return; @@ -1355,8 +1356,8 @@ void BRepMesh_Delaun::killTrianglesOnIntersectingLinks( killLinkTriangles( theLinkToCheckId, theLoopEdges ); - BRepMesh_ListOfInteger::Iterator aNeighborsIt = - myMeshData->LinkNeighboursOf( theEndPoint ); + BRepMeshCol::ListOfInteger::Iterator aNeighborsIt = + myMeshData->LinksConnectedTo( theEndPoint ); for ( ; aNeighborsIt.More(); aNeighborsIt.Next() ) { @@ -1377,11 +1378,11 @@ void BRepMesh_Delaun::killTrianglesOnIntersectingLinks( //purpose : Kill triangles bound to the given link. //======================================================================= void BRepMesh_Delaun::killLinkTriangles( - const Standard_Integer& theLinkId, - BRepMesh_MapOfIntegerInteger& theLoopEdges ) + const Standard_Integer& theLinkId, + BRepMeshCol::MapOfIntegerInteger& theLoopEdges ) { const BRepMesh_PairOfIndex& aPair = - myMeshData->ElemConnectedTo( theLinkId ); + myMeshData->ElementsConnectedTo( theLinkId ); Standard_Integer anElemNb = aPair.Extent(); for ( Standard_Integer aPairIt = 1; aPairIt <= anElemNb; ++aPairIt ) @@ -1420,17 +1421,17 @@ void BRepMesh_Delaun::getOrientedNodes(const BRepMesh_Edge& theEdge, //purpose : Processes loop within the given polygon formed by range of // its links specified by start and end link indices. //======================================================================= -void BRepMesh_Delaun::processLoop(const Standard_Integer theLinkFrom, - const Standard_Integer theLinkTo, - const TColStd_SequenceOfInteger& thePolygon, - const NCollection_Sequence& thePolyBoxes) +void BRepMesh_Delaun::processLoop(const Standard_Integer theLinkFrom, + const Standard_Integer theLinkTo, + const BRepMeshCol::SequenceOfInteger& thePolygon, + const BRepMeshCol::SequenceOfBndB2d& thePolyBoxes) { Standard_Integer aNbOfLinksInLoop = theLinkTo - theLinkFrom - 1; if ( aNbOfLinksInLoop < 3 ) return; - TColStd_SequenceOfInteger aPolygon; - NCollection_Sequence aPolyBoxes; + BRepMeshCol::SequenceOfInteger aPolygon; + BRepMeshCol::SequenceOfBndB2d aPolyBoxes; for ( ; aNbOfLinksInLoop > 0; --aNbOfLinksInLoop ) { Standard_Integer aLoopLinkIndex = theLinkFrom + aNbOfLinksInLoop; @@ -1446,12 +1447,12 @@ void BRepMesh_Delaun::processLoop(const Standard_Integer theLinkFr // given polygon. //======================================================================= Standard_Integer BRepMesh_Delaun::createAndReplacePolygonLink( - const Standard_Integer *theNodes, - const gp_Pnt2d *thePnts, - const Standard_Integer theRootIndex, - const ReplaceFlag theReplaceFlag, - TColStd_SequenceOfInteger& thePolygon, - NCollection_Sequence& thePolyBoxes ) + const Standard_Integer *theNodes, + const gp_Pnt2d *thePnts, + const Standard_Integer theRootIndex, + const ReplaceFlag theReplaceFlag, + BRepMeshCol::SequenceOfInteger& thePolygon, + BRepMeshCol::SequenceOfBndB2d& thePolyBoxes ) { Standard_Integer aNewEdgeId = myMeshData->AddLink( BRepMesh_Edge( @@ -1486,9 +1487,9 @@ Standard_Integer BRepMesh_Delaun::createAndReplacePolygonLink( //function : meshPolygon //purpose : //======================================================================= -void BRepMesh_Delaun::meshPolygon( TColStd_SequenceOfInteger& thePolygon, - NCollection_Sequence& thePolyBoxes, - BRepMesh_Delaun::HandleOfMapOfInteger theSkipped ) +void BRepMesh_Delaun::meshPolygon( BRepMeshCol::SequenceOfInteger& thePolygon, + BRepMeshCol::SequenceOfBndB2d& thePolyBoxes, + BRepMeshCol::HMapOfInteger theSkipped ) { // Check is the source polygon elementary if ( meshElementaryPolygon( thePolygon ) ) @@ -1535,16 +1536,16 @@ void BRepMesh_Delaun::meshPolygon( TColStd_SequenceOfInteger& thePoly }; gp_Pnt2d anIntPnt; - BRepMesh_WireInterferenceChecker::IntFlag aIntFlag = intSegSeg( *aCurEdge, - *aNextEdge, Standard_False, Standard_True, anIntPnt ); + BRepMesh_GeomTool::IntFlag aIntFlag = intSegSeg( *aCurEdge, *aNextEdge, + Standard_False, Standard_True, anIntPnt ); - if ( aIntFlag == BRepMesh_WireInterferenceChecker::NoIntersection ) + if ( aIntFlag == BRepMesh_GeomTool::NoIntersection ) continue; Standard_Boolean isRemoveFromFirst = Standard_False; Standard_Boolean isAddReplacingEdge = Standard_True; Standard_Integer aIndexToRemoveTo = aNextPolyIt; - if ( aIntFlag == BRepMesh_WireInterferenceChecker::Cross ) + if ( aIntFlag == BRepMesh_GeomTool::Cross ) { Standard_Real aLoopArea = polyArea( thePolygon, aPolyIt + 1, aNextPolyIt ); gp_Vec2d aVec1( anIntPnt, aCurPnts [1] ); @@ -1586,7 +1587,7 @@ void BRepMesh_Delaun::meshPolygon( TColStd_SequenceOfInteger& thePoly theSkipped->Add( Abs( thePolygon( aSkippedLinkIt ) ) ); } } - else if ( aIntFlag == BRepMesh_WireInterferenceChecker::PointOnSegment ) + else if ( aIntFlag == BRepMesh_GeomTool::PointOnSegment ) { // Indentify chopping link Standard_Boolean isFirstChopping = Standard_False; @@ -1657,7 +1658,7 @@ void BRepMesh_Delaun::meshPolygon( TColStd_SequenceOfInteger& thePoly thePolygon, thePolyBoxes ); } } - else if ( aIntFlag == BRepMesh_WireInterferenceChecker::Glued ) + else if ( aIntFlag == BRepMesh_GeomTool::Glued ) { if ( aCurNodes[1] == aNextNodes[0] ) { @@ -1666,7 +1667,7 @@ void BRepMesh_Delaun::meshPolygon( TColStd_SequenceOfInteger& thePoly } // TODO: Non-adjacent glued links within the polygon } - else if ( aIntFlag == BRepMesh_WireInterferenceChecker::Same ) + else if ( aIntFlag == BRepMesh_GeomTool::Same ) { processLoop( aPolyIt, aNextPolyIt, thePolygon, thePolyBoxes ); @@ -1710,7 +1711,7 @@ void BRepMesh_Delaun::meshPolygon( TColStd_SequenceOfInteger& thePoly //purpose : Triangulation of closed polygon containing only three edges. //======================================================================= inline Standard_Boolean BRepMesh_Delaun::meshElementaryPolygon( - const TColStd_SequenceOfInteger& thePolygon ) + const BRepMeshCol::SequenceOfInteger& thePolygon ) { Standard_Integer aPolyLen = thePolygon.Length(); if ( aPolyLen < 3 ) @@ -1728,7 +1729,7 @@ inline Standard_Boolean BRepMesh_Delaun::meshElementaryPolygon( anEdges[anEdgeIt] = Abs( anEdgeInfo ); anEdgesOri[anEdgeIt] = ( anEdgeInfo > 0 ); } - + const BRepMesh_Edge& anEdge1 = GetEdge( anEdges[0] ); const BRepMesh_Edge& anEdge2 = GetEdge( anEdges[1] ); @@ -1752,8 +1753,8 @@ inline Standard_Boolean BRepMesh_Delaun::meshElementaryPolygon( // its edges in the structure. // (negative index means reversed edge) //======================================================================= -void BRepMesh_Delaun::meshSimplePolygon( TColStd_SequenceOfInteger& thePolygon, - NCollection_Sequence& thePolyBoxes ) +void BRepMesh_Delaun::meshSimplePolygon( BRepMeshCol::SequenceOfInteger& thePolygon, + BRepMeshCol::SequenceOfBndB2d& thePolyBoxes ) { // Check is the given polygon elementary if ( meshElementaryPolygon( thePolygon ) ) @@ -1843,11 +1844,10 @@ void BRepMesh_Delaun::meshSimplePolygon( TColStd_SequenceOfInteger& thePolyg // intersection is possible... gp_Pnt2d anIntPnt; - BRepMesh_WireInterferenceChecker::IntFlag aIntFlag = - intSegSeg( aCheckLink, aPolyLink, Standard_False, - Standard_False, anIntPnt ); + BRepMesh_GeomTool::IntFlag aIntFlag = intSegSeg( aCheckLink, aPolyLink, + Standard_False, Standard_False, anIntPnt ); - if( aIntFlag != BRepMesh_WireInterferenceChecker::NoIntersection ) + if( aIntFlag != BRepMesh_GeomTool::NoIntersection ) { isIntersect = Standard_True; break; @@ -1899,11 +1899,11 @@ void BRepMesh_Delaun::meshSimplePolygon( TColStd_SequenceOfInteger& thePolyg // polygon. if ( aUsedLinkId < aPolyLen ) { - TColStd_SequenceOfInteger aRightPolygon; + BRepMeshCol::SequenceOfInteger aRightPolygon; thePolygon.Split( aUsedLinkId, aRightPolygon ); aRightPolygon.Prepend( -aNewEdgesInfo[2] ); - NCollection_Sequence aRightPolyBoxes; + BRepMeshCol::SequenceOfBndB2d aRightPolyBoxes; thePolyBoxes.Split( aUsedLinkId, aRightPolyBoxes ); Bnd_B2d aBox; @@ -1937,22 +1937,22 @@ void BRepMesh_Delaun::meshSimplePolygon( TColStd_SequenceOfInteger& thePolyg //function : RemoveVertex //purpose : Removes a vertex from the triangulation //======================================================================= -void BRepMesh_Delaun::RemoveVertex( const BRepMesh_Vertex& theVertex ) +void BRepMesh_Delaun::RemoveVertex( const BRepMesh_Vertex& theVertex ) { BRepMesh_SelectorOfDataStructureOfDelaun aSelector( myMeshData ); aSelector.NeighboursOf( theVertex ); - BRepMesh_MapOfIntegerInteger aLoopEdges( 10, myMeshData->Allocator() ); + BRepMeshCol::MapOfIntegerInteger aLoopEdges( 10, myMeshData->Allocator() ); // Loop on triangles to be destroyed : - BRepMesh_MapOfInteger::Iterator aTriangleIt( aSelector.Elements() ); + BRepMeshCol::MapOfInteger::Iterator aTriangleIt( aSelector.Elements() ); for ( ; aTriangleIt.More(); aTriangleIt.Next() ) deleteTriangle( aTriangleIt.Key(), aLoopEdges ); - NCollection_Sequence aBoxes; - TColStd_SequenceOfInteger aPolygon; + BRepMeshCol::SequenceOfBndB2d aBoxes; + BRepMeshCol::SequenceOfInteger aPolygon; Standard_Integer aLoopEdgesCount = aLoopEdges.Extent(); - BRepMesh_MapOfIntegerInteger::Iterator aLoopEdgesIt( aLoopEdges ); + BRepMeshCol::MapOfIntegerInteger::Iterator aLoopEdgesIt( aLoopEdges ); if ( aLoopEdgesIt.More() ) { @@ -1982,7 +1982,7 @@ void BRepMesh_Delaun::RemoveVertex( const BRepMesh_Vertex& theVertex ) aLastNode = aFirstNode; while ( aPivotNode != aLastNode ) { - BRepMesh_ListOfInteger::Iterator aLinkIt( myMeshData->LinkNeighboursOf( aPivotNode ) ); + BRepMeshCol::ListOfInteger::Iterator aLinkIt( myMeshData->LinksConnectedTo( aPivotNode ) ); for ( ; aLinkIt.More(); aLinkIt.Next() ) { if ( aLinkIt.Value() != anEdgeId && @@ -2023,15 +2023,15 @@ void BRepMesh_Delaun::RemoveVertex( const BRepMesh_Vertex& theVertex ) //function : AddVertices //purpose : Adds some vertices in the triangulation. //======================================================================= -void BRepMesh_Delaun::AddVertices( BRepMesh_Array1OfVertexOfDelaun& theVertices ) +void BRepMesh_Delaun::AddVertices( BRepMeshCol::Array1OfVertexOfDelaun& theVertices ) { - BRepMesh_HeapSortVertexOfDelaun::Sort( theVertices, - BRepMesh_ComparatorOfVertexOfDelaun( SortingDirection ) ); + std::make_heap(theVertices.begin(), theVertices.end(), ComparatorOfVertexOfDelaun()); + std::sort_heap(theVertices.begin(), theVertices.end(), ComparatorOfVertexOfDelaun()); Standard_Integer aLower = theVertices.Lower(); Standard_Integer anUpper = theVertices.Upper(); - TColStd_Array1OfInteger aVertexIndexes( aLower, anUpper ); + BRepMeshCol::Array1OfInteger aVertexIndexes( aLower, anUpper ); for ( Standard_Integer i = aLower; i <= anUpper; ++i ) aVertexIndexes(i) = myMeshData->AddNode( theVertices(i) ); @@ -2130,17 +2130,17 @@ Standard_Boolean BRepMesh_Delaun::UseEdge( const Standard_Integer /*theIndex*/ ) //function : getEdgesByType //purpose : Gives the list of edges with type defined by input parameter //======================================================================= -Handle(BRepMesh_MapOfInteger) BRepMesh_Delaun::getEdgesByType( +BRepMeshCol::HMapOfInteger BRepMesh_Delaun::getEdgesByType( const BRepMesh_DegreeOfFreedom theEdgeType ) const { - Handle(BRepMesh_MapOfInteger) aResult = new BRepMesh_MapOfInteger; - BRepMesh_MapOfInteger::Iterator anEdgeIt( myMeshData->LinkOfDomain() ); + BRepMeshCol::HMapOfInteger aResult = new BRepMeshCol::MapOfInteger; + BRepMeshCol::MapOfInteger::Iterator anEdgeIt( myMeshData->LinksOfDomain() ); for ( ; anEdgeIt.More(); anEdgeIt.Next() ) { Standard_Integer anEdge = anEdgeIt.Key(); Standard_Boolean isToAdd = (theEdgeType == BRepMesh_Free) ? - (myMeshData->ElemConnectedTo( anEdge ).Extent() <= 1) : + (myMeshData->ElementsConnectedTo( anEdge ).Extent() <= 1) : (GetEdge( anEdge ).Movability() == theEdgeType); if (isToAdd) @@ -2205,27 +2205,14 @@ Standard_Boolean BRepMesh_Delaun::Contains( const Standard_Integer theTriangleId Standard_Boolean o[3]; Standard_Integer p[3]; - GetTriangle( theTriangleId ).Edges( e[0], e[1], e[2], - o[0], o[1], o[2] ); - + const BRepMesh_Triangle& aElement = GetTriangle( theTriangleId ); + aElement.Edges(e, o); + const BRepMesh_Edge* anEdges[3] = { &GetEdge( e[0] ), &GetEdge( e[1] ), &GetEdge( e[2] ) }; - if ( o[0] ) - { - p[0] = anEdges[0]->FirstNode(); - p[1] = anEdges[0]->LastNode(); - } - else - { - p[1] = anEdges[0]->FirstNode(); - p[0] = anEdges[0]->LastNode(); - } - - if ( o[2] ) - p[2] = anEdges[2]->FirstNode(); - else - p[2] = anEdges[2]->LastNode(); + + myMeshData->ElementNodes(aElement, p); gp_XY aPoints[3]; aPoints[0] = GetVertex( p[0] ).Coord(); @@ -2279,7 +2266,7 @@ Standard_Boolean BRepMesh_Delaun::Contains( const Standard_Integer theTriangleId //function : intSegSeg //purpose : Checks intersection between the two segments. //============================================================================= -BRepMesh_WireInterferenceChecker::IntFlag BRepMesh_Delaun::intSegSeg( +BRepMesh_GeomTool::IntFlag BRepMesh_Delaun::intSegSeg( const BRepMesh_Edge& theEdg1, const BRepMesh_Edge& theEdg2, const Standard_Boolean isConsiderEndPointTouch, @@ -2292,7 +2279,7 @@ BRepMesh_WireInterferenceChecker::IntFlag BRepMesh_Delaun::intSegSeg( p3 = GetVertex( theEdg2.FirstNode() ).Coord(); p4 = GetVertex( theEdg2.LastNode() ).Coord(); - return BRepMesh_WireInterferenceChecker::Intersect(p1, p2, p3, p4, + return BRepMesh_GeomTool::IntSegSeg(p1, p2, p3, p4, isConsiderEndPointTouch, isConsiderPointOnEdge, theIntPnt); } @@ -2301,9 +2288,9 @@ BRepMesh_WireInterferenceChecker::IntFlag BRepMesh_Delaun::intSegSeg( //purpose : Returns area of the loop of the given polygon defined by indices // of its start and end links. //============================================================================= -Standard_Real BRepMesh_Delaun::polyArea( const TColStd_SequenceOfInteger& thePolygon, - const Standard_Integer theStartIndex, - const Standard_Integer theEndIndex ) const +Standard_Real BRepMesh_Delaun::polyArea( const BRepMeshCol::SequenceOfInteger& thePolygon, + const Standard_Integer theStartIndex, + const Standard_Integer theEndIndex ) const { Standard_Real aArea = 0.0; Standard_Integer aPolyLen = thePolygon.Length(); diff --git a/src/BRepMesh/BRepMesh_Delaun.hxx b/src/BRepMesh/BRepMesh_Delaun.hxx index 71c2faba11..ae6da815af 100755 --- a/src/BRepMesh/BRepMesh_Delaun.hxx +++ b/src/BRepMesh/BRepMesh_Delaun.hxx @@ -18,22 +18,19 @@ #include #include +#include +#include #include #include #include -#include -#include +#include #include -#include -#include +#include class Bnd_B2d; class Bnd_Box2d; class BRepMesh_Array1OfVertexOfDelaun; class BRepMesh_Vertex; -class TColStd_Array1OfInteger; -class TColStd_SequenceOfInteger; -class TColStd_MapOfInteger; //! Compute the Delaunay's triangulation with the algorithm of Watson. class BRepMesh_Delaun @@ -43,52 +40,52 @@ public: DEFINE_STANDARD_ALLOC //! Creates the triangulation with an empty Mesh data structure. - Standard_EXPORT BRepMesh_Delaun (BRepMesh_Array1OfVertexOfDelaun& theVertices, - const Standard_Boolean isPositive = Standard_True); + Standard_EXPORT BRepMesh_Delaun (BRepMeshCol::Array1OfVertexOfDelaun& theVertices, + const Standard_Boolean isPositive = Standard_True); //! Creates the triangulation with an existent Mesh data structure. Standard_EXPORT BRepMesh_Delaun (const Handle(BRepMesh_DataStructureOfDelaun)& theOldMesh, - BRepMesh_Array1OfVertexOfDelaun& theVertices, + BRepMeshCol::Array1OfVertexOfDelaun& theVertices, const Standard_Boolean isPositive = Standard_True); //! Creates the triangulation with an existant Mesh data structure. Standard_EXPORT BRepMesh_Delaun (const Handle(BRepMesh_DataStructureOfDelaun)& theOldMesh, - TColStd_Array1OfInteger& theVertexIndices, + BRepMeshCol::Array1OfInteger& theVertexIndices, const Standard_Boolean isPositive = Standard_True); //! Initializes the triangulation with an array of vertices. - Standard_EXPORT void Init (BRepMesh_Array1OfVertexOfDelaun& theVertices); + Standard_EXPORT void Init (BRepMeshCol::Array1OfVertexOfDelaun& theVertices); //! Removes a vertex from the triangulation. Standard_EXPORT void RemoveVertex (const BRepMesh_Vertex& theVertex); //! Adds some vertices into the triangulation. - Standard_EXPORT void AddVertices (BRepMesh_Array1OfVertexOfDelaun& theVertices); + Standard_EXPORT void AddVertices (BRepMeshCol::Array1OfVertexOfDelaun& theVertices); //! Modify mesh to use the edge. //! @return True if done Standard_EXPORT Standard_Boolean UseEdge (const Standard_Integer theEdge); //! Gives the Mesh data structure. - const Handle(BRepMesh_DataStructureOfDelaun)& Result() const + inline const Handle(BRepMesh_DataStructureOfDelaun)& Result() const { return myMeshData; } //! Gives the list of frontier edges. - inline Handle(BRepMesh_MapOfInteger) Frontier() const + inline BRepMeshCol::HMapOfInteger Frontier() const { return getEdgesByType (BRepMesh_Frontier); } //! Gives the list of internal edges. - inline Handle(BRepMesh_MapOfInteger) InternalEdges() const + inline BRepMeshCol::HMapOfInteger InternalEdges() const { return getEdgesByType (BRepMesh_Fixed); } //! Gives the list of free edges used only one time - inline Handle(BRepMesh_MapOfInteger) FreeEdges() const + inline BRepMeshCol::HMapOfInteger FreeEdges() const { return getEdgesByType (BRepMesh_Free); } @@ -127,31 +124,29 @@ private: InsertBefore }; - typedef NCollection_DataMap > DataMapOfMap; - - typedef NCollection_Handle > HandleOfMapOfInteger; + typedef NCollection_DataMap DataMapOfMap; //! Add boundig box for edge defined by start & end point to //! the given vector of bounding boxes for triangulation edges. - void fillBndBox (NCollection_Sequence& theBoxes, + void fillBndBox (BRepMeshCol::SequenceOfBndB2d& theBoxes, const BRepMesh_Vertex& theV1, const BRepMesh_Vertex& theV2); //! Gives the list of edges with type defined by the input parameter. //! If the given type is BRepMesh_Free returns list of edges //! that have number of connected elements less or equal 1. - Handle(BRepMesh_MapOfInteger) getEdgesByType (const BRepMesh_DegreeOfFreedom theEdgeType) const; + BRepMeshCol::HMapOfInteger getEdgesByType (const BRepMesh_DegreeOfFreedom theEdgeType) const; //! Create super mesh and run triangulation procedure. - void perform (Bnd_Box2d& theBndBox, - TColStd_Array1OfInteger& theVertexIndices); + void perform (Bnd_Box2d& theBndBox, + BRepMeshCol::Array1OfInteger& theVertexIndices); //! Build the super mesh. void superMesh (const Bnd_Box2d& theBox); //! Computes the triangulation and adds the vertices, //! edges and triangles to the Mesh data structure. - void compute (TColStd_Array1OfInteger& theVertexIndices); + void compute (BRepMeshCol::Array1OfInteger& theVertexIndices); //! Adjust the mesh on the frontier. void frontierAdjust(); @@ -159,56 +154,56 @@ private: //! Find left polygon of the given edge and call meshPolygon. Standard_Boolean meshLeftPolygonOf (const Standard_Integer theEdgeIndex, const Standard_Boolean isForward, - HandleOfMapOfInteger theSkipped = NULL); + BRepMeshCol::HMapOfInteger theSkipped = NULL); //! Find next link starting from the given node and has maximum //! angle respect the given reference link. //! Each time the next link is found other neighbor links at the pivot //! node are marked as leprous and will be excluded from consideration //! next time until a hanging end is occured. - Standard_Integer findNextPolygonLink (const Standard_Integer& theFirstNode, - const Standard_Integer& thePivotNode, - const BRepMesh_Vertex& thePivotVertex, - const gp_Vec2d& theRefLinkDir, - const NCollection_Sequence& theBoxes, - const TColStd_SequenceOfInteger& thePolygon, - const HandleOfMapOfInteger theSkipped, - const Standard_Boolean& isSkipLeprous, - NCollection_Map& theLeprousLinks, - NCollection_Map& theDeadLinks, - Standard_Integer& theNextPivotNode, - gp_Vec2d& theNextLinkDir, - Bnd_B2d& theNextLinkBndBox); + Standard_Integer findNextPolygonLink (const Standard_Integer& theFirstNode, + const Standard_Integer& thePivotNode, + const BRepMesh_Vertex& thePivotVertex, + const gp_Vec2d& theRefLinkDir, + const BRepMeshCol::SequenceOfBndB2d& theBoxes, + const BRepMeshCol::SequenceOfInteger& thePolygon, + const BRepMeshCol::HMapOfInteger theSkipped, + const Standard_Boolean& isSkipLeprous, + BRepMeshCol::MapOfInteger& theLeprousLinks, + BRepMeshCol::MapOfInteger& theDeadLinks, + Standard_Integer& theNextPivotNode, + gp_Vec2d& theNextLinkDir, + Bnd_B2d& theNextLinkBndBox); //! Check is the given link intersects the polygon boundaries. //! Returns bounding box for the given link trough the theLinkBndBox parameter. - Standard_Boolean checkIntersection (const BRepMesh_Edge& theLink, - const TColStd_SequenceOfInteger& thePolygon, - const NCollection_Sequence& thePolyBoxes, - const Standard_Boolean isConsiderEndPointTouch, - const Standard_Boolean isConsiderPointOnEdge, - const Standard_Boolean isSkipLastEdge, - Bnd_B2d& theLinkBndBox) const; + Standard_Boolean checkIntersection (const BRepMesh_Edge& theLink, + const BRepMeshCol::SequenceOfInteger& thePolygon, + const BRepMeshCol::SequenceOfBndB2d& thePolyBoxes, + const Standard_Boolean isConsiderEndPointTouch, + const Standard_Boolean isConsiderPointOnEdge, + const Standard_Boolean isSkipLastEdge, + Bnd_B2d& theLinkBndBox) const; //! Triangulatiion of a closed polygon described by the list //! of indexes of its edges in the structure. //! (negative index means reversed edge) - void meshPolygon (TColStd_SequenceOfInteger& thePolygon, - NCollection_Sequence& thePolyBoxes, - HandleOfMapOfInteger theSkipped = NULL); + void meshPolygon (BRepMeshCol::SequenceOfInteger& thePolygon, + BRepMeshCol::SequenceOfBndB2d& thePolyBoxes, + BRepMeshCol::HMapOfInteger theSkipped = NULL); //! Triangulatiion of a closed simple polygon (polygon without glued edges and loops) //! described by the list of indexes of its edges in the structure. //! (negative index means reversed edge) - void meshSimplePolygon (TColStd_SequenceOfInteger& thePolygon, - NCollection_Sequence& thePolyBoxes); + void meshSimplePolygon (BRepMeshCol::SequenceOfInteger& thePolygon, + BRepMeshCol::SequenceOfBndB2d& thePolyBoxes); //! Triangulation of closed polygon containing only three edges. - inline Standard_Boolean meshElementaryPolygon (const TColStd_SequenceOfInteger& thePolygon); + inline Standard_Boolean meshElementaryPolygon (const BRepMeshCol::SequenceOfInteger& thePolygon); //! Creates the triangles beetween the given node and the given polyline. - void createTriangles (const Standard_Integer theVertexIndex, - BRepMesh_MapOfIntegerInteger& thePoly); + void createTriangles (const Standard_Integer theVertexIndex, + BRepMeshCol::MapOfIntegerInteger& thePoly); //! Add a triangle based on the given oriented edges into mesh inline void addTriangle (const Standard_Integer (&theEdgesId)[3], @@ -217,8 +212,8 @@ private: //! Deletes the triangle with the given index and adds the free edges into the map. //! When an edge is suppressed more than one time it is destroyed. - void deleteTriangle (const Standard_Integer theIndex, - BRepMesh_MapOfIntegerInteger& theLoopEdges); + void deleteTriangle (const Standard_Integer theIndex, + BRepMeshCol::MapOfIntegerInteger& theLoopEdges); //! Returns start and end nodes of the given edge in respect to its orientation. void getOrientedNodes (const BRepMesh_Edge& theEdge, @@ -227,21 +222,21 @@ private: //! Processes loop within the given polygon formed by range of its //! links specified by start and end link indices. - void processLoop (const Standard_Integer theLinkFrom, - const Standard_Integer theLinkTo, - const TColStd_SequenceOfInteger& thePolygon, - const NCollection_Sequence& thePolyBoxes); + void processLoop (const Standard_Integer theLinkFrom, + const Standard_Integer theLinkTo, + const BRepMeshCol::SequenceOfInteger& thePolygon, + const BRepMeshCol::SequenceOfBndB2d& thePolyBoxes); //! Creates new link based on the given nodes and updates the given polygon. - Standard_Integer createAndReplacePolygonLink (const Standard_Integer theNodes[], - const gp_Pnt2d thePnts [], - const Standard_Integer theRootIndex, - const ReplaceFlag theReplaceFlag, - TColStd_SequenceOfInteger& thePolygon, - NCollection_Sequence& thePolyBoxes); + Standard_Integer createAndReplacePolygonLink (const Standard_Integer theNodes[], + const gp_Pnt2d thePnts [], + const Standard_Integer theRootIndex, + const ReplaceFlag theReplaceFlag, + BRepMeshCol::SequenceOfInteger& thePolygon, + BRepMeshCol::SequenceOfBndB2d& thePolyBoxes); //! Creates the triangles on new nodes. - void createTrianglesOnNewVertices (TColStd_Array1OfInteger& theVertexIndices); + void createTrianglesOnNewVertices (BRepMeshCol::Array1OfInteger& theVertexIndices); //! Cleanup mesh from the free triangles. void cleanupMesh(); @@ -257,35 +252,35 @@ private: const Standard_Integer thePrevElementId); //! Remove internal triangles from the given polygon. - void cleanupPolygon (const TColStd_SequenceOfInteger& thePolygon, - const NCollection_Sequence& thePolyBoxes); + void cleanupPolygon (const BRepMeshCol::SequenceOfInteger& thePolygon, + const BRepMeshCol::SequenceOfBndB2d& thePolyBoxes); //! Checks is the given vertex lies inside the polygon. - Standard_Boolean isVertexInsidePolygon (const Standard_Integer& theVertexId, - const NCollection_Vector& thePolygonVertices) const; + Standard_Boolean isVertexInsidePolygon (const Standard_Integer& theVertexId, + const BRepMeshCol::VectorOfInteger& thePolygonVertices) const; //! Remove all triangles and edges that are placed inside the polygon or crossed it. - void killTrianglesAroundVertex (const Standard_Integer theZombieNodeId, - const NCollection_Vector& thePolyVertices, - const NCollection_Map& thePolyVerticesFindMap, - const TColStd_SequenceOfInteger& thePolygon, - const NCollection_Sequence& thePolyBoxes, - NCollection_Map& theSurvivedLinks, - BRepMesh_MapOfIntegerInteger& theLoopEdges); + void killTrianglesAroundVertex (const Standard_Integer theZombieNodeId, + const BRepMeshCol::VectorOfInteger& thePolyVertices, + const BRepMeshCol::MapOfInteger& thePolyVerticesFindMap, + const BRepMeshCol::SequenceOfInteger& thePolygon, + const BRepMeshCol::SequenceOfBndB2d& thePolyBoxes, + BRepMeshCol::MapOfInteger& theSurvivedLinks, + BRepMeshCol::MapOfIntegerInteger& theLoopEdges); //! Checks is the given link crosses the polygon boundary. //! If yes, kills its triangles and checks neighbor links on boundary intersection. Does nothing elsewhere. - void killTrianglesOnIntersectingLinks (const Standard_Integer& theLinkToCheckId, - const BRepMesh_Edge& theLinkToCheck, - const Standard_Integer& theEndPoint, - const TColStd_SequenceOfInteger& thePolygon, - const NCollection_Sequence& thePolyBoxes, - NCollection_Map& theSurvivedLinks, - BRepMesh_MapOfIntegerInteger& theLoopEdges); + void killTrianglesOnIntersectingLinks (const Standard_Integer& theLinkToCheckId, + const BRepMesh_Edge& theLinkToCheck, + const Standard_Integer& theEndPoint, + const BRepMeshCol::SequenceOfInteger& thePolygon, + const BRepMeshCol::SequenceOfBndB2d& thePolyBoxes, + BRepMeshCol::MapOfInteger& theSurvivedLinks, + BRepMeshCol::MapOfIntegerInteger& theLoopEdges); //! Kill triangles bound to the given link. - void killLinkTriangles (const Standard_Integer& theLinkId, - BRepMesh_MapOfIntegerInteger& theLoopEdges); + void killLinkTriangles (const Standard_Integer& theLinkId, + BRepMeshCol::MapOfIntegerInteger& theLoopEdges); //! Calculates distances between the given point and edges of triangle. Standard_Real calculateDist (const gp_XY theVEdges[3], @@ -297,7 +292,7 @@ private: Standard_Integer& theEdgeOn) const; //! Checks intersection between the two segments. - BRepMesh_WireInterferenceChecker::IntFlag intSegSeg ( + BRepMesh_GeomTool::IntFlag intSegSeg( const BRepMesh_Edge& theEdge1, const BRepMesh_Edge& theEdge2, const Standard_Boolean isConsiderEndPointTouch, @@ -305,9 +300,9 @@ private: gp_Pnt2d& theIntPnt) const; //! Returns area of the loop of the given polygon defined by indices of its start and end links. - Standard_Real polyArea (const TColStd_SequenceOfInteger& thePolygon, - const Standard_Integer theStartIndex, - const Standard_Integer theEndIndex) const; + Standard_Real polyArea (const BRepMeshCol::SequenceOfInteger& thePolygon, + const Standard_Integer theStartIndex, + const Standard_Integer theEndIndex) const; private: diff --git a/src/BRepMesh/BRepMesh_DiscretFactory.cdl b/src/BRepMesh/BRepMesh_DiscretFactory.cdl deleted file mode 100644 index 2a841721d5..0000000000 --- a/src/BRepMesh/BRepMesh_DiscretFactory.cdl +++ /dev/null @@ -1,114 +0,0 @@ --- Created on: 2008-04-10 --- Created by: Peter KURNEV --- Copyright (c) 2008-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. - -class DiscretFactory from BRepMesh - - ---Purpose: - -- This class intended to setup / retrieve default triangulation algorithm. - -- Use BRepMesh_DiscretFactory::Get() static method to retrieve global Factory instance. - -- Use BRepMesh_DiscretFactory::Discret() method to retrieve meshing tool. - -uses - DiscretRoot from BRepMesh, - FactoryError from BRepMesh, - PluginEntryType from BRepMesh, - AsciiString from TCollection, - MapOfAsciiString from TColStd, - Shape from TopoDS, - MapOfFunctions from Plugin - ---raises - -is - Create - returns DiscretFactory from BRepMesh - is protected; - ---C++: alias "Standard_EXPORT virtual ~BRepMesh_DiscretFactory();" - - Get (myclass) - returns DiscretFactory from BRepMesh; - ---C++: return & - ---Purpose: - -- Returns the global factory instance. - - Names (me) - returns MapOfAsciiString from TColStd; - ---C++: return const & - ---Purpose: - -- Returns the list of registered meshing algorithms. - - SetDefaultName ( me : out; - theName : AsciiString from TCollection) - returns Boolean from Standard; - ---Purpose: - -- Setup meshing algorithm by name. - -- Returns true if requested tool is available. - -- On fail Factory will continue to use previous algo. - - DefaultName (me) - returns AsciiString from TCollection; - ---C++: return const & - ---Purpose: - -- Returns name for current meshing algorithm. - - SetFunctionName ( me : out; - theFuncName : AsciiString from TCollection) - returns Boolean from Standard; - ---Purpose: - -- Advanced function. Changes function name to retrieve from plugin. - -- Returns true if requested tool is available. - -- On fail Factory will continue to use previous algo. - - SetDefault ( me : out; - theName : AsciiString from TCollection; - theFuncName : AsciiString from TCollection = "DISCRETALGO") - returns Boolean from Standard; - ---Purpose: - -- Setup meshing algorithm that should be created by this Factory. - -- Returns true if requested tool is available. - -- On fail Factory will continue to use previous algo. - -- Call ::ErrorStatus() method to retrieve fault reason. - - FunctionName (me) - returns AsciiString from TCollection; - ---C++: return const & - ---Purpose: - -- Returns function name that should be exported by plugin. - - Discret (me : out; - theShape : Shape from TopoDS; - theDeflection : Real from Standard; - theAngle : Real from Standard) - returns DiscretRoot from BRepMesh; - ---Purpose: - -- Returns triangulation algorithm instance. - - ErrorStatus (me) - returns FactoryError from BRepMesh; - ---Purpose: - -- Returns error status for last meshing algorithm switch. - - Clear (me : out) - is protected; - -fields - myPluginEntry : PluginEntryType from BRepMesh is protected; - myErrorStatus : FactoryError from BRepMesh is protected; - myNames : MapOfAsciiString from TColStd is protected; - myDefaultName : AsciiString from TCollection is protected; - myFunctionName : AsciiString from TCollection is protected; - myFactoryMethods : MapOfFunctions from Plugin is protected; - -end DiscretFactory; diff --git a/src/BRepMesh/BRepMesh_DiscretFactory.cxx b/src/BRepMesh/BRepMesh_DiscretFactory.cxx index a366df134b..8e727bd6a4 100644 --- a/src/BRepMesh/BRepMesh_DiscretFactory.cxx +++ b/src/BRepMesh/BRepMesh_DiscretFactory.cxx @@ -13,7 +13,7 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include +#include #include #include @@ -52,13 +52,13 @@ namespace //purpose : //======================================================================= BRepMesh_DiscretFactory::BRepMesh_DiscretFactory() -: myPluginEntry (NULL), - myErrorStatus (BRepMesh_FE_NOERROR), - myDefaultName (THE_FAST_DISCRET_MESH), +: myPluginEntry (NULL), + myErrorStatus (BRepMesh_FE_NOERROR), + myDefaultName (THE_FAST_DISCRET_MESH), myFunctionName ("DISCRETALGO") { // register built-in meshing algorithms - myNames.Add (THE_FAST_DISCRET_MESH); + myNames.Add(THE_FAST_DISCRET_MESH); } //======================================================================= @@ -67,14 +67,14 @@ BRepMesh_DiscretFactory::BRepMesh_DiscretFactory() //======================================================================= BRepMesh_DiscretFactory::~BRepMesh_DiscretFactory() { - Clear(); + clear(); } //======================================================================= -//function : ~ +//function : clear //purpose : //======================================================================= -void BRepMesh_DiscretFactory::Clear() +void BRepMesh_DiscretFactory::clear() { // what should we do here? Unload dynamic libraries and reset plugins list? } @@ -90,66 +90,13 @@ BRepMesh_DiscretFactory& BRepMesh_DiscretFactory::Get() return THE_GLOBAL_FACTORY; } -//======================================================================= -//function : ErrorStatus -//purpose : -//======================================================================= -BRepMesh_FactoryError BRepMesh_DiscretFactory::ErrorStatus() const -{ - return myErrorStatus; -} - -//======================================================================= -//function : Names -//purpose : -//======================================================================= -const TColStd_MapOfAsciiString& BRepMesh_DiscretFactory::Names() const -{ - return myNames; -} - -//======================================================================= -//function : SetDefaultName -//purpose : -//======================================================================= -Standard_Boolean BRepMesh_DiscretFactory::SetDefaultName (const TCollection_AsciiString& theName) -{ - return SetDefault (theName, myFunctionName); -} - -//======================================================================= -//function : DefaultName -//purpose : -//======================================================================= -const TCollection_AsciiString& BRepMesh_DiscretFactory::DefaultName() const -{ - return myDefaultName; -} - -//======================================================================= -//function : SetFunctionName -//purpose : -//======================================================================= -Standard_Boolean BRepMesh_DiscretFactory::SetFunctionName (const TCollection_AsciiString& theFuncName) -{ - return SetDefault (myDefaultName, theFuncName); -} - -//======================================================================= -//function : FunctionName -//purpose : -//======================================================================= -const TCollection_AsciiString& BRepMesh_DiscretFactory::FunctionName() const -{ - return myFunctionName; -} - //======================================================================= //function : SetDefault //purpose : //======================================================================= -Standard_Boolean BRepMesh_DiscretFactory::SetDefault (const TCollection_AsciiString& theName, - const TCollection_AsciiString& theFuncName) +Standard_Boolean BRepMesh_DiscretFactory::SetDefault( + const TCollection_AsciiString& theName, + const TCollection_AsciiString& theFuncName) { myErrorStatus = BRepMesh_FE_NOERROR; if (theName == THE_FAST_DISCRET_MESH) @@ -221,17 +168,19 @@ Standard_Boolean BRepMesh_DiscretFactory::SetDefault (const TCollection_AsciiStr //function : Discret //purpose : //======================================================================= -Handle(BRepMesh_DiscretRoot) BRepMesh_DiscretFactory - ::Discret (const TopoDS_Shape& theShape, - const Standard_Real theDeflection, - const Standard_Real theAngle) +Handle(BRepMesh_DiscretRoot) BRepMesh_DiscretFactory::Discret( + const TopoDS_Shape& theShape, + const Standard_Real theDeflection, + const Standard_Real theAngle) { Handle(BRepMesh_DiscretRoot) aDiscretRoot; BRepMesh_PDiscretRoot anInstancePtr = NULL; if (myPluginEntry != NULL) { // use plugin - Standard_Integer anErr = myPluginEntry (theShape, theDeflection, theAngle, anInstancePtr); + Standard_Integer anErr = myPluginEntry (theShape, + theDeflection, theAngle, anInstancePtr); + if (anErr != 0 || anInstancePtr == NULL) { // can not create the algo specified - should never happens here @@ -242,7 +191,8 @@ Handle(BRepMesh_DiscretRoot) BRepMesh_DiscretFactory else //if (myDefaultName == THE_FAST_DISCRET_MESH) { // use built-in - BRepMesh_IncrementalMesh::Discret (theShape, theDeflection, theAngle, anInstancePtr); + BRepMesh_IncrementalMesh::Discret (theShape, + theDeflection, theAngle, anInstancePtr); } // cover with handle diff --git a/src/BRepMesh/BRepMesh_DiscretFactory.hxx b/src/BRepMesh/BRepMesh_DiscretFactory.hxx new file mode 100644 index 0000000000..6d3bac9f3a --- /dev/null +++ b/src/BRepMesh/BRepMesh_DiscretFactory.hxx @@ -0,0 +1,118 @@ +// Copyright (c) 2013 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 _BRepMesh_DiscretFactory_HeaderFile +#define _BRepMesh_DiscretFactory_HeaderFile + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class TColStd_MapOfAsciiString; +class TCollection_AsciiString; +class BRepMesh_DiscretRoot; +class TopoDS_Shape; + +//! This class intended to setup / retrieve default triangulation algorithm.
+//! Use BRepMesh_DiscretFactory::Get() static method to retrieve global Factory instance.
+//! Use BRepMesh_DiscretFactory::Discret() method to retrieve meshing tool.
+class BRepMesh_DiscretFactory +{ +public: + + DEFINE_STANDARD_ALLOC + + //! Returns the global factory instance. + Standard_EXPORT static BRepMesh_DiscretFactory& Get(); + + //! Returns the list of registered meshing algorithms. + inline const TColStd_MapOfAsciiString& Names() const + { + return myNames; + } + + //! Setup meshing algorithm by name.
+ //! Returns TRUE if requested tool is available.
+ //! On fail Factory will continue to use previous algo. + Standard_EXPORT Standard_Boolean SetDefaultName(const TCollection_AsciiString& theName) + { + return SetDefault(theName, myFunctionName); + } + + //! Returns name for current meshing algorithm. + inline const TCollection_AsciiString& DefaultName() const + { + return myDefaultName; + } + + //! Advanced function. Changes function name to retrieve from plugin.
+ //! Returns TRUE if requested tool is available.
+ //! On fail Factory will continue to use previous algo. + Standard_EXPORT Standard_Boolean SetFunctionName(const TCollection_AsciiString& theFuncName) + { + return SetDefault(myDefaultName, theFuncName); + } + + //! Returns function name that should be exported by plugin. + inline const TCollection_AsciiString& FunctionName() const + { + return myFunctionName; + } + + //! Returns error status for last meshing algorithm switch. + inline BRepMesh_FactoryError ErrorStatus() const + { + return myErrorStatus; + } + + //! Setup meshing algorithm that should be created by this Factory.
+ //! Returns TRUE if requested tool is available.
+ //! On fail Factory will continue to use previous algo.
+ //! Call ::ErrorStatus() method to retrieve fault reason. + Standard_EXPORT Standard_Boolean SetDefault(const TCollection_AsciiString& theName, + const TCollection_AsciiString& theFuncName = "DISCRETALGO"); + + //! Returns triangulation algorithm instance. + //! \param theShape shape to be meshed. + //! \param theLinDeflection linear deflection to be used for meshing. + //! \param theAngDeflection angular deflection to be used for meshing. + Standard_EXPORT Handle(BRepMesh_DiscretRoot) Discret(const TopoDS_Shape& theShape, + const Standard_Real theLinDeflection, + const Standard_Real theAngDeflection); + +protected: + + //! Constructor + Standard_EXPORT BRepMesh_DiscretFactory(); + + //! Destructor + Standard_EXPORT virtual ~BRepMesh_DiscretFactory(); + + //! Clears factory data. + Standard_EXPORT void clear(); + + BRepMesh_PluginEntryType myPluginEntry; + BRepMesh_FactoryError myErrorStatus; + TColStd_MapOfAsciiString myNames; + TCollection_AsciiString myDefaultName; + TCollection_AsciiString myFunctionName; + Plugin_MapOfFunctions myFactoryMethods; +}; + +#endif diff --git a/src/BRepMesh/BRepMesh_DiscretRoot.cdl b/src/BRepMesh/BRepMesh_DiscretRoot.cdl deleted file mode 100644 index a815e67d21..0000000000 --- a/src/BRepMesh/BRepMesh_DiscretRoot.cdl +++ /dev/null @@ -1,92 +0,0 @@ --- Created on: 2008-04-10 --- Created by: Peter KURNEV --- Copyright (c) 2008-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. - -deferred class DiscretRoot from BRepMesh - -inherits Transient from Standard - - ---Purpose: - -- This is a common interface for meshing algorithms - -- instantiated by Mesh Factory and implemented by plugins. - -uses - Shape from TopoDS - ---raises - -is - Initialize - returns DiscretRoot from BRepMesh; - - SetDeflection ( me : mutable; - theDeflection : Real from Standard); - ---Purpose: - -- Setup linear deflection. - - ---C++: alias "Standard_EXPORT virtual ~BRepMesh_DiscretRoot();" - - Deflection (me) - returns Real from Standard; - ---Purpose: - -- Returns linear deflection. - - SetAngle ( me : mutable; - theAngle : Real from Standard); - ---Purpose: - -- Setup angular deflection. - - Angle (me) - returns Real from Standard; - ---Purpose: - -- Returns angular deflection. - - SetShape ( me : mutable; - theShape : Shape from TopoDS); - ---Purpose: - -- Set the shape to triangulate. - - Shape (me) - returns Shape from TopoDS; - ---C++: return const & - - Perform (me : mutable) - is deferred; - ---Purpose: - -- Compute triangulation for set shape. - - IsDone (me) - returns Boolean from Standard; - ---Purpose: - -- Returns true if triangualtion was performed and has success. - - -- - -- Protected methods - -- - SetDone (me : mutable) - is protected; - - SetNotDone (me : mutable) - is protected; - - Init (me : mutable) - is virtual protected; - -fields - myDeflection : Real from Standard is protected; - myAngle : Real from Standard is protected; - myShape : Shape from TopoDS is protected; - myIsDone : Boolean from Standard is protected; - -end DiscretRoot; diff --git a/src/BRepMesh/BRepMesh_DiscretRoot.cxx b/src/BRepMesh/BRepMesh_DiscretRoot.cxx index 85f95f3304..1d7123aae1 100644 --- a/src/BRepMesh/BRepMesh_DiscretRoot.cxx +++ b/src/BRepMesh/BRepMesh_DiscretRoot.cxx @@ -13,7 +13,10 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include +#include + +IMPLEMENT_STANDARD_HANDLE (BRepMesh_DiscretRoot, Standard_Transient) +IMPLEMENT_STANDARD_RTTIEXT(BRepMesh_DiscretRoot, Standard_Transient) //======================================================================= //function : BRepMesh_DiscretRoot @@ -21,10 +24,9 @@ //======================================================================= BRepMesh_DiscretRoot::BRepMesh_DiscretRoot() : myDeflection (0.001), - myAngle (0.1), - myIsDone (Standard_False) + myAngle (0.1), + myIsDone (Standard_False) { - // } //======================================================================= @@ -36,91 +38,9 @@ BRepMesh_DiscretRoot::~BRepMesh_DiscretRoot() } //======================================================================= -//function : SetDeflection +//function : init //purpose : //======================================================================= -void BRepMesh_DiscretRoot::SetDeflection (const Standard_Real theDeflection) +void BRepMesh_DiscretRoot::init() { - myDeflection = theDeflection; -} - -//======================================================================= -//function : Deflection -//purpose : -//======================================================================= -Standard_Real BRepMesh_DiscretRoot::Deflection() const -{ - return myDeflection; -} - -//======================================================================= -//function : SetAngle -//purpose : -//======================================================================= -void BRepMesh_DiscretRoot::SetAngle (const Standard_Real theAngle) -{ - myAngle = theAngle; -} - -//======================================================================= -//function : Angle -//purpose : -//======================================================================= -Standard_Real BRepMesh_DiscretRoot::Angle() const -{ - return myAngle; -} - -//======================================================================= -//function : SetShape -//purpose : -//======================================================================= -void BRepMesh_DiscretRoot::SetShape (const TopoDS_Shape& theShape) -{ - myShape = theShape; -} - -//======================================================================= -//function : Shape -//purpose : -//======================================================================= -const TopoDS_Shape& BRepMesh_DiscretRoot::Shape() const -{ - return myShape; -} - -//======================================================================= -//function : IsDone -//purpose : -//======================================================================= -Standard_Boolean BRepMesh_DiscretRoot::IsDone() const -{ - return myIsDone; -} - -//======================================================================= -//function : SetDone -//purpose : -//======================================================================= -void BRepMesh_DiscretRoot::SetDone() -{ - myIsDone = Standard_True; -} - -//======================================================================= -//function : SetNotDone -//purpose : -//======================================================================= -void BRepMesh_DiscretRoot::SetNotDone() -{ - myIsDone = Standard_False; -} - -//======================================================================= -//function : Init -//purpose : -//======================================================================= -void BRepMesh_DiscretRoot::Init() -{ - // } diff --git a/src/BRepMesh/BRepMesh_DiscretRoot.hxx b/src/BRepMesh/BRepMesh_DiscretRoot.hxx new file mode 100644 index 0000000000..3d3c38e7ea --- /dev/null +++ b/src/BRepMesh/BRepMesh_DiscretRoot.hxx @@ -0,0 +1,105 @@ +// Copyright (c) 2013 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 _BRepMesh_DiscretRoot_HeaderFile +#define _BRepMesh_DiscretRoot_HeaderFile + +#include +#include +#include +#include + +//! This is a common interface for meshing algorithms +//! instantiated by Mesh Factory and implemented by plugins. +class BRepMesh_DiscretRoot : public Standard_Transient +{ +public: + + //! Destructor + Standard_EXPORT virtual ~BRepMesh_DiscretRoot(); + + //! Setup linear deflection. + inline void SetDeflection(const Standard_Real theDeflection) + { + myDeflection = theDeflection; + } + + //! Returns linear deflection. + inline Standard_Real Deflection() const + { + return myDeflection; + } + + //! Setup angular deflection. + inline void SetAngle(const Standard_Real theAngle) + { + myAngle = theAngle; + } + + //! Returns angular deflection. + inline Standard_Real Angle() const + { + return myAngle; + } + + //! Set the shape to triangulate. + inline void SetShape(const TopoDS_Shape& theShape) + { + myShape = theShape; + } + + inline const TopoDS_Shape& Shape() const + { + return myShape; + } + + //! Returns true if triangualtion was performed and has success. + inline Standard_Boolean IsDone() const + { + return myIsDone; + } + + //! Compute triangulation for set shape. + Standard_EXPORT virtual void Perform() = 0; + + + DEFINE_STANDARD_RTTI(BRepMesh_DiscretRoot) + +protected: + + //! Constructor + Standard_EXPORT BRepMesh_DiscretRoot(); + + //! Sets IsDone flag. + inline void setDone() + { + myIsDone = Standard_True; + } + + //! Clears IsDone flag. + inline void setNotDone() + { + myIsDone = Standard_False; + } + + Standard_EXPORT virtual void init(); + + Standard_Real myDeflection; + Standard_Real myAngle; + TopoDS_Shape myShape; + Standard_Boolean myIsDone; +}; + +DEFINE_STANDARD_HANDLE(BRepMesh_DiscretRoot, Standard_Transient) + +#endif diff --git a/src/BRepMesh/BRepMesh_Edge.cdl b/src/BRepMesh/BRepMesh_Edge.cdl deleted file mode 100644 index 36b6c46247..0000000000 --- a/src/BRepMesh/BRepMesh_Edge.cdl +++ /dev/null @@ -1,84 +0,0 @@ --- Created on: 1993-09-22 --- Created by: Didier PIFFAULT --- Copyright (c) 1993-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. - -class Edge from BRepMesh - - ---Purpose: - - -uses Boolean from Standard, - Integer from Standard, - DegreeOfFreedom from BRepMesh - - -is Create - returns Edge from BRepMesh; - ---C++: inline - - Create (vDebut : Integer from Standard; - vFin : Integer from Standard; - canMove : DegreeOfFreedom from BRepMesh) - ---Purpose: Contructs a link beetween to vertices. - returns Edge from BRepMesh; - - - FirstNode (me) - ---Purpose: Give the index of first node of the Link. - ---C++: inline - returns Integer from Standard - is static; - - - LastNode (me) - ---Purpose: Give the index of Last node of the Link. - ---C++: inline - returns Integer from Standard - is static; - - - Movability (me) - ---C++: inline - returns DegreeOfFreedom from BRepMesh - is static; - - - SetMovability (me : in out; - Move : DegreeOfFreedom from BRepMesh) - is static; - - HashCode (me; - Upper : Integer from Standard) - returns Integer from Standard - ---C++: function call - is static; - - - SameOrientation(me; Other : Edge from BRepMesh) - returns Boolean from Standard - is static; - - - IsEqual (me; Other : Edge from BRepMesh) - returns Boolean from Standard - ---C++: alias operator == - is static; - - - fields myFirstNode : Integer from Standard; - myLastNode : Integer from Standard; - myMovability : DegreeOfFreedom from BRepMesh; - - end Edge; diff --git a/src/BRepMesh/BRepMesh_Edge.cxx b/src/BRepMesh/BRepMesh_Edge.cxx deleted file mode 100644 index 0700058020..0000000000 --- a/src/BRepMesh/BRepMesh_Edge.cxx +++ /dev/null @@ -1,48 +0,0 @@ -// Created on: 1993-09-23 -// Created by: Didier PIFFAULT -// Copyright (c) 1993-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. - -#include - -BRepMesh_Edge::BRepMesh_Edge(const Standard_Integer vDebut, - const Standard_Integer vFin, - const BRepMesh_DegreeOfFreedom canMove) - : myFirstNode(vDebut), myLastNode(vFin), myMovability(canMove) -{} - -void BRepMesh_Edge::SetMovability(const BRepMesh_DegreeOfFreedom Move) -{ - myMovability =Move; -} - -Standard_Integer BRepMesh_Edge::HashCode(const Standard_Integer Upper)const -{ - return ::HashCode(myFirstNode+myLastNode, Upper); -} - -Standard_Boolean BRepMesh_Edge::IsEqual(const BRepMesh_Edge& Other)const -{ - if (myMovability==BRepMesh_Deleted || Other.myMovability==BRepMesh_Deleted) - return Standard_False; - return (myFirstNode==Other.myFirstNode && myLastNode==Other.myLastNode) || - (myFirstNode==Other.myLastNode && myLastNode==Other.myFirstNode); -} - - -Standard_Boolean BRepMesh_Edge::SameOrientation -(const BRepMesh_Edge& Other)const -{ - return (myFirstNode==Other.myFirstNode && myLastNode==Other.myLastNode); -} diff --git a/src/BRepMesh/BRepMesh_Edge.hxx b/src/BRepMesh/BRepMesh_Edge.hxx new file mode 100644 index 0000000000..603c4cc498 --- /dev/null +++ b/src/BRepMesh/BRepMesh_Edge.hxx @@ -0,0 +1,122 @@ +// Copyright (c) 2013 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 _BRepMesh_Edge_HeaderFile +#define _BRepMesh_Edge_HeaderFile + +#include +#include +#include +#include + +//! Light weighted structure representing link of the mesh. +class BRepMesh_Edge +{ +public: + + DEFINE_STANDARD_ALLOC + + //! Default constructor. + Standard_EXPORT BRepMesh_Edge() + : myFirstNode (-1), + myLastNode (-1), + myMovability(BRepMesh_Deleted) + { + } + + //! Contructs a link beetween two vertices. + Standard_EXPORT BRepMesh_Edge(const Standard_Integer theFirstNode, + const Standard_Integer theLastNode, + const BRepMesh_DegreeOfFreedom theMovability) + : myFirstNode (theFirstNode), + myLastNode (theLastNode), + myMovability(theMovability) + { + } + + //! Returns index of first node of the Link. + inline Standard_Integer FirstNode() const + { + return myFirstNode; + } + + //! Returns index of last node of the Link. + inline Standard_Integer LastNode() const + { + return myLastNode; + } + + //! Returns movability flag of the Link. + inline BRepMesh_DegreeOfFreedom Movability() const + { + return myMovability; + } + + //! Sets movability flag of the Link. + //! \param theMovability flag to be set. + inline void SetMovability(const BRepMesh_DegreeOfFreedom theMovability) + { + myMovability = theMovability; + } + + //! Returns hash code for this edge. + //! \param theUpper upper index in the container. + //! \return hash code. + Standard_EXPORT Standard_Integer HashCode(const Standard_Integer theUpper) const + { + return ::HashCode(myFirstNode + myLastNode, theUpper); + } + + //! Checks if the given edge and this one have the same orientation. + //! \param theOther edge to be checked against this one. + //! \retrun TRUE if edges have the same orientation, FALSE if not. + inline Standard_Boolean IsSameOrientation(const BRepMesh_Edge& theOther) const + { + return (myFirstNode == theOther.myFirstNode && myLastNode == theOther.myLastNode); + } + + //! Checks for equality with another edge. + //! \param theOther edge to be checked against this one. + //! \return TRUE if equal, FALSE if not. + inline Standard_Boolean IsEqual(const BRepMesh_Edge& theOther) const + { + if (myMovability == BRepMesh_Deleted || + theOther.myMovability == BRepMesh_Deleted) + { + return Standard_False; + } + + return IsSameOrientation(theOther) || + (myFirstNode == theOther.myLastNode && myLastNode == theOther.myFirstNode); + } + + //! Alias for IsEqual. + Standard_Boolean operator ==(const BRepMesh_Edge& Other) const + { + return IsEqual(Other); + } + +private: + + Standard_Integer myFirstNode; + Standard_Integer myLastNode; + BRepMesh_DegreeOfFreedom myMovability; +}; + +inline Standard_Integer HashCode(const BRepMesh_Edge& theEdge, + const Standard_Integer theUpper) +{ + return theEdge.HashCode(theUpper); +} + +#endif diff --git a/src/BRepMesh/BRepMesh_Edge.lxx b/src/BRepMesh/BRepMesh_Edge.lxx deleted file mode 100644 index 17731d392a..0000000000 --- a/src/BRepMesh/BRepMesh_Edge.lxx +++ /dev/null @@ -1,38 +0,0 @@ -// Created on: 1993-09-23 -// Created by: Didier PIFFAULT -// Copyright (c) 1993-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. - -inline BRepMesh_Edge::BRepMesh_Edge() -: myFirstNode(-1), - myLastNode(-1), - myMovability(BRepMesh_Deleted) -{ -} - -inline Standard_Integer BRepMesh_Edge::FirstNode()const -{ - return myFirstNode; -} - -inline Standard_Integer BRepMesh_Edge::LastNode()const -{ - return myLastNode; -} - -inline BRepMesh_DegreeOfFreedom BRepMesh_Edge::Movability()const -{ - return myMovability; -} - diff --git a/src/BRepMesh/BRepMesh_FaceAttribute.cdl b/src/BRepMesh/BRepMesh_FaceAttribute.cdl deleted file mode 100644 index c8775887c5..0000000000 --- a/src/BRepMesh/BRepMesh_FaceAttribute.cdl +++ /dev/null @@ -1,81 +0,0 @@ --- Created on: 2008-10-31 --- Created by: EPA --- Copyright (c) 2008-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. - -class FaceAttribute from BRepMesh inherits TShared from MMgt - - ---Purpose: auxiliary class for FastDiscret and FastDiscretFace classes - -uses - Real from Standard, - Address from Standard, - ClassifierPtr from BRepMesh - -is - - Create returns FaceAttribute from BRepMesh; - - GetDefFace(me:mutable) returns Real; - ---C++: return & - ---C++: inline - - GetUMin(me:mutable) returns Real; - ---C++: return & - ---C++: inline - - GetVMin(me:mutable) returns Real; - ---C++: return & - ---C++: inline - - GetUMax(me:mutable) returns Real; - ---C++: return & - ---C++: inline - - GetVMax(me:mutable) returns Real; - ---C++: return & - ---C++: inline - - GetDeltaX(me:mutable) returns Real; - ---C++: return & - ---C++: inline - - GetDeltaY(me:mutable) returns Real; - ---C++: return & - ---C++: inline - - GetMinX(me:mutable) returns Real; - ---C++: return & - ---C++: inline - - GetMinY(me:mutable) returns Real; - ---C++: return & - ---C++: inline - - GetClassifier(me:mutable) returns ClassifierPtr from BRepMesh; - ---C++: return & - ---C++: inline - -fields - mydefface : Real from Standard; - myumin : Real from Standard; - myumax : Real from Standard; - myvmin : Real from Standard; - myvmax : Real from Standard; - mydeltaX : Real from Standard; - mydeltaY : Real from Standard; - myminX : Real from Standard; - myminY : Real from Standard; - myclassifier: ClassifierPtr from BRepMesh; - -end FaceAttribute; diff --git a/src/BRepMesh/BRepMesh_FaceAttribute.cxx b/src/BRepMesh/BRepMesh_FaceAttribute.cxx index 121457f0d0..0ce1d9ce37 100644 --- a/src/BRepMesh/BRepMesh_FaceAttribute.cxx +++ b/src/BRepMesh/BRepMesh_FaceAttribute.cxx @@ -12,7 +12,10 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include +#include + +IMPLEMENT_STANDARD_HANDLE (BRepMesh_FaceAttribute, Standard_Transient) +IMPLEMENT_STANDARD_RTTIEXT(BRepMesh_FaceAttribute, Standard_Transient) //======================================================================= //function : BRepMesh_FaceAttribute diff --git a/src/BRepMesh/BRepMesh_FaceAttribute.hxx b/src/BRepMesh/BRepMesh_FaceAttribute.hxx new file mode 100644 index 0000000000..bd856b38d7 --- /dev/null +++ b/src/BRepMesh/BRepMesh_FaceAttribute.hxx @@ -0,0 +1,99 @@ +// Copyright (c) 2013 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 _BRepMesh_FaceAttribute_HeaderFile +#define _BRepMesh_FaceAttribute_HeaderFile + +#include +#include +#include +#include + + +//! auxiliary class for FastDiscret and FastDiscretFace classes
+class BRepMesh_FaceAttribute : public Standard_Transient +{ +public: + + Standard_EXPORT BRepMesh_FaceAttribute(); + + inline Standard_Real& GetDefFace() + { + return mydefface; + } + + inline Standard_Real& GetUMin() + { + return myumin; + } + + inline Standard_Real& GetVMin() + { + return myvmin; + } + + inline Standard_Real& GetUMax() + { + return myumax; + } + + inline Standard_Real& GetVMax() + { + return myvmax; + } + + inline Standard_Real& GetDeltaX() + { + return mydeltaX; + } + + inline Standard_Real& GetDeltaY() + { + return mydeltaY; + } + + inline Standard_Real& GetMinX() + { + return myminX; + } + + inline Standard_Real& GetMinY() + { + return myminY; + } + + inline BRepMeshCol::HClassifier& GetClassifier() + { + return myclassifier; + } + + + DEFINE_STANDARD_RTTI(BRepMesh_FaceAttribute) + +private: + + Standard_Real mydefface; + Standard_Real myumin; + Standard_Real myumax; + Standard_Real myvmin; + Standard_Real myvmax; + Standard_Real mydeltaX; + Standard_Real mydeltaY; + Standard_Real myminX; + Standard_Real myminY; + BRepMeshCol::HClassifier myclassifier; +}; + +DEFINE_STANDARD_HANDLE(BRepMesh_FaceAttribute, Standard_Transient) + +#endif diff --git a/src/BRepMesh/BRepMesh_FaceAttribute.lxx b/src/BRepMesh/BRepMesh_FaceAttribute.lxx deleted file mode 100644 index 5d71575a6d..0000000000 --- a/src/BRepMesh/BRepMesh_FaceAttribute.lxx +++ /dev/null @@ -1,63 +0,0 @@ -// Created by: Ekaterina SMIRNOVA -// Copyright (c) 2008-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. - -inline Standard_Real& BRepMesh_FaceAttribute::GetDefFace() -{ - return mydefface; -} - -inline Standard_Real& BRepMesh_FaceAttribute::GetUMin() -{ - return myumin; -} - -inline Standard_Real& BRepMesh_FaceAttribute::GetVMin() -{ - return myvmin; -} - -inline Standard_Real& BRepMesh_FaceAttribute::GetUMax() -{ - return myumax; -} - -inline Standard_Real& BRepMesh_FaceAttribute::GetVMax() -{ - return myvmax; -} - -inline Standard_Real& BRepMesh_FaceAttribute::GetDeltaX() -{ - return mydeltaX; -} - -inline Standard_Real& BRepMesh_FaceAttribute::GetDeltaY() -{ - return mydeltaY; -} - -inline Standard_Real& BRepMesh_FaceAttribute::GetMinX() -{ - return myminX; -} - -inline Standard_Real& BRepMesh_FaceAttribute::GetMinY() -{ - return myminY; -} - -inline BRepMesh_ClassifierPtr& BRepMesh_FaceAttribute::GetClassifier() -{ - return myclassifier; -} diff --git a/src/BRepMesh/BRepMesh_FaceChecker.hxx b/src/BRepMesh/BRepMesh_FaceChecker.hxx index 613ceb13c2..2085079a85 100644 --- a/src/BRepMesh/BRepMesh_FaceChecker.hxx +++ b/src/BRepMesh/BRepMesh_FaceChecker.hxx @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -66,22 +67,20 @@ public: aEdges.push_back(TopoDS::Edge(aEdgeIt.Current())); BRepMesh_EdgeChecker aEdgeChecker(aFaceT, aFaceLoc, myMutex, myIsFailed); +#ifdef HAVE_TBB if (myIsInParallel) { - #ifdef HAVE_TBB // check faces in parallel threads using TBB tbb::parallel_for_each(aEdges.begin(), aEdges.end(), aEdgeChecker); - #else - // alternative parallelization not yet available - for (std::vector::iterator it(aEdges.begin()); it != aEdges.end(); it++) - aEdgeChecker(*it); - #endif } else { +#endif for (std::vector::iterator it(aEdges.begin()); it != aEdges.end(); it++) aEdgeChecker(*it); +#ifdef HAVE_TBB } +#endif } //! Returns status of the check. diff --git a/src/BRepMesh/BRepMesh_BaseAllocator.hxx b/src/BRepMesh/BRepMesh_FactoryError.hxx similarity index 68% rename from src/BRepMesh/BRepMesh_BaseAllocator.hxx rename to src/BRepMesh/BRepMesh_FactoryError.hxx index 1fbdc5b178..0be62a2256 100644 --- a/src/BRepMesh/BRepMesh_BaseAllocator.hxx +++ b/src/BRepMesh/BRepMesh_FactoryError.hxx @@ -1,4 +1,4 @@ -// Copyright (c) 1999-2014 OPEN CASCADE SAS +// Copyright (c) 2013 OPEN CASCADE SAS // // This file is part of Open CASCADE Technology software library. // @@ -11,6 +11,16 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include -typedef Handle(NCollection_IncAllocator) BRepMesh_BaseAllocator; +#ifndef _BRepMesh_FactoryError_HeaderFile +#define _BRepMesh_FactoryError_HeaderFile + +enum BRepMesh_FactoryError +{ + BRepMesh_FE_NOERROR, + BRepMesh_FE_LIBRARYNOTFOUND, + BRepMesh_FE_FUNCTIONNOTFOUND, + BRepMesh_FE_CANNOTCREATEALGO +}; + +#endif diff --git a/src/BRepMesh/BRepMesh_FastDiscret.cdl b/src/BRepMesh/BRepMesh_FastDiscret.cdl deleted file mode 100644 index 340eddc242..0000000000 --- a/src/BRepMesh/BRepMesh_FastDiscret.cdl +++ /dev/null @@ -1,351 +0,0 @@ --- Created on: 1996-02-27 --- Created by: Laurent PAINNOT --- Copyright (c) 1996-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. - -class FastDiscret from BRepMesh inherits TShared from MMgt - - ---Purpose: Algorithm to mesh a shape with respect of the - -- frontier the deflection and by option the shared - -- components. - - -uses Boolean from Standard, - Integer from Standard, - Box from Bnd, - Real from Standard, - Shape from TopoDS, - Face from TopoDS, - Edge from TopoDS, - FaceAttribute from BRepMesh, - Vertex from TopoDS, - Triangle from BRepMesh, - Vertex from BRepMesh, - Edge from BRepMesh, - ListOfInteger from TColStd, - MapOfInteger from TColStd, - SequenceOfInteger from TColStd, - ListOfReal from TColStd, - IndexedMapOfInteger from TColStd, - SequenceOfPnt2d from TColgp, - Dir from gp, - Pnt from gp, - XY from gp, - Pnt2d from gp, - DataMapOfIntegerPnt from BRepMesh, - DataMapOfIntegerListOfXY from BRepMesh, - DataMapOfShapePairOfPolygon from BRepMesh, - Delaun from BRepMesh, - DataMapOfVertexInteger from BRepMesh, - DataStructureOfDelaun from BRepMesh, - ListOfVertex from BRepMesh, - MapOfShape from TopTools, - HSurface from BRepAdaptor, - ClassifierPtr from BRepMesh, - IndexedMapOfReal from TColStd, - Status from BRepMesh, - DataMapOfShapeReal from TopTools, - ListOfShape from TopTools, - Curve from Geom2d, - MapOfInteger from BRepMesh, - BaseAllocator from BRepMesh, - DataMapOfFaceAttribute from BRepMesh, - IndexedDataMapOfShapeListOfShape from TopTools, - MutexForShapeProvider from TopTools, - ShapeEnum from TopAbs - -is - - Create (defle : Real from Standard; - angle : Real from Standard; - B : Box from Bnd; - withShare : Boolean from Standard=Standard_True; - inshape : Boolean from Standard=Standard_False; - relative : Boolean from Standard=Standard_False; - shapetrigu : Boolean from Standard=Standard_False; - isInParallel: Boolean from Standard=Standard_False) - returns FastDiscret from BRepMesh; - - - Create (defle : Real from Standard; - shape : Shape from TopoDS; - B : Box from Bnd; - angle : Real from Standard; - withShare : Boolean from Standard=Standard_True; - inshape : Boolean from Standard=Standard_False; - relative : Boolean from Standard=Standard_False; - shapetrigu : Boolean from Standard=Standard_False; - isInParallel: Boolean from Standard=Standard_False) - ---Purpose: if the boolean is True, the - -- deflection used for the polygonalisation of - -- each edge will be * Size of Edge. - -- the deflection used for the faces will be the maximum - -- deflection of their edges. - -- - -- if is True, the triangulation, if exists - -- with a correct deflection, can be used to re-triangulate - -- the shape. - -- - -- if is True, the calculated - -- triangulation will be stored in the shape. - returns FastDiscret from BRepMesh; - - - Perform (me: mutable; shape: Shape from TopoDS) is static; - ---Purpose: Build triangulation on the whole shape - - Add (me: mutable; face: Face from TopoDS; - ancestor : IndexedDataMapOfShapeListOfShape from TopTools) is static; - ---Purpose: Record a face for further processing. - - Process (me; face: Face from TopoDS) is static; - ---Purpose: Triangulate a face previously recorded for - -- processing by call to Add(). Can be executed in - -- parallel threads. - ---C++: alias operator () - - CurrentFaceStatus(me) - returns Status from BRepMesh; - - Add (me : mutable; - edge : Edge from TopoDS; - face : Face from TopoDS; - S : HSurface from BRepAdaptor; - C : Curve from Geom2d; - ancestor : IndexedDataMapOfShapeListOfShape from TopTools; - defedge: Real from Standard; - first : Real from Standard; - last : Real from Standard) - is static private; - - Add (me : mutable; - theVert: Vertex from TopoDS; - face : Face from TopoDS; - S : HSurface from BRepAdaptor) is private; - - Update (me: mutable; - Edge : Edge from TopoDS; - Face : Face from TopoDS; - C : Curve from Geom2d; - defedge: Real from Standard; - first : Real from Standard; - last : Real from Standard) - returns Boolean is private; - - RelativeEdgeDeflection(myclass; - edge : Edge from TopoDS; - defle : Real from Standard; - dtotale : Real from Standard; - cdef : out Real from Standard) - ---Purpose: Returns computed relative deflection for edge - returns Real from Standard; - - BoxMaxDimension(myclass; - box : in Box from Bnd; - maxdim : out Real from Standard); - ---Purpose: Returns the maximal dimension of Bnd_Box - - InternalVertices - (me : mutable; - caro : HSurface from BRepAdaptor; - inter : in out ListOfVertex from BRepMesh; - defedge : Real from Standard; - classifier : ClassifierPtr from BRepMesh) - is static private; - - - Control (me : mutable; - caro : HSurface from BRepAdaptor; - defface : Real from Standard; - inter : in out ListOfVertex from BRepMesh; - badTri : in out ListOfInteger from TColStd; - nulTri : in out ListOfInteger from TColStd; - trigu : in out Delaun from BRepMesh; - isfirst : Boolean from Standard) - returns Real from Standard is static private; - - AddInShape(me: mutable; - face : Face from TopoDS; - defedge: Real from Standard) - is static private; - - SetParallel ( me : mutable; - theInParallel : Boolean from Standard); - ---Purpose: - -- Request algorithm to launch in multiple threads - -- to improve performance (should be supported by plugin). - - IsParallel (me) - returns Boolean from Standard; - ---Purpose: - -- Returns the multi-threading usage flag. - - CreateMutexesForSubShapes(me : mutable; - theShape : Shape from TopoDS; - theType : ShapeEnum from TopAbs); - ---Purpose: - -- Creates mutexes for each sub-shape of type theType in theShape. - -- Used to avoid data races. - - RemoveAllMutexes(me: mutable); - ---Purpose: - -- Removes all created mutexes - --- Output : - - - NbTriangles(me) - ---Purpose: Gives the number of built triangles. - returns Integer from Standard - is static; - - Triangle (me; - Index : Integer from Standard) - ---Purpose: Gives the triangle of . - ---C++: return const & - returns Triangle from BRepMesh - is static; - - - NbEdges (me) - ---Purpose: Gives the number of built Edges - returns Integer from Standard - is static; - - Edge (me; - Index : Integer from Standard) - ---Purpose: Gives the edge of index . - ---C++: return const & - returns Edge from BRepMesh - is static; - - NbVertices (me) - ---Purpose: Gives the number of built Vertices. - returns Integer from Standard - is static; - - Vertex (me; - Index : Integer from Standard) - ---Purpose: Gives the vertex of . - ---C++: return const & - returns Vertex from BRepMesh - is static; - - Pnt (me; - Index : Integer from Standard) - ---Purpose: Gives the location3d of the vertex of . - ---C++: return const & - returns Pnt from gp - is static; - - VerticesOfDomain - (me; Indices : in out MapOfInteger from BRepMesh) - ---Purpose: Gives the list of indices of the vertices - is static; - - - EdgesOfDomain - (me; Indices : in out MapOfInteger from BRepMesh) - ---Purpose: Gives the list of indices of the edges - ---C++: inline - is static; - - - TrianglesOfDomain(me; Indices: in out MapOfInteger from BRepMesh) - ---Purpose: Gives the list of indices of the triangles - ---C++: inline - is static; - - - NbPoint3d (me) - ---Purpose: Gives the number of different location in 3d - -- space. It is different of the number of - -- vertices if there is more than one surface. - -- Even for one surface, the number can be different - -- if an edge is shared. - ---C++: inline - returns Integer from Standard - is static; - - Point3d (me; - Index : Integer from Standard) - ---Purpose: Gives the 3d space location of the vertex . - ---C++: return const & - ---C++: inline - returns Pnt from gp - is static; - - - GetDeflection(me) - ---Purpose: returns the deflection value. - ---C++: inline - returns Real from Standard; - - GetAngle(me) - ---Purpose: returns the deflection value. - ---C++: inline - returns Real from Standard; - - WithShare(me) - ---C++: inline - returns Boolean from Standard; - - InShape(me) - ---C++: inline - returns Boolean from Standard; - - ShapeTrigu(me) - ---C++: inline - returns Boolean from Standard; - - GetFaceAttribute(me; - face : Face from TopoDS; - fattrib : in out FaceAttribute from BRepMesh) - ---Purpose: returns the face deflection value. - returns Boolean from Standard; - - RemoveFaceAttribute(me : mutable; - face : Face from TopoDS); - ---Purpose: remove face attribute as useless to free locate memory - - GetMapOfDefEdge(me) - ---C++: return const & - ---C++: inline - returns DataMapOfShapeReal from TopTools; - -fields - myAngle : Real from Standard; - myDeflection : Real from Standard; - myDtotale : Real from Standard; - myWithShare : Boolean from Standard; - myInParallel : Boolean from Standard; - myVertices : DataMapOfVertexInteger from BRepMesh; - myEdges : DataMapOfShapePairOfPolygon from BRepMesh; - myInternaledges: DataMapOfShapePairOfPolygon from BRepMesh; - myNbLocat : Integer from Standard; - myLocation3d : DataMapOfIntegerPnt from BRepMesh; - myStructure : DataStructureOfDelaun from BRepMesh; - myMapattrib : DataMapOfFaceAttribute from BRepMesh; - myVemap : IndexedMapOfInteger from TColStd; - myLocation2d : DataMapOfIntegerListOfXY from BRepMesh; - myRelative : Boolean from Standard; - myShapetrigu : Boolean from Standard; - myInshape : Boolean from Standard; - myFacestate : Status from BRepMesh; - myMapdefle : DataMapOfShapeReal from TopTools; - myNottriangulated : ListOfShape from TopTools; - myAllocator : BaseAllocator from BRepMesh; - myMutexProvider: MutexForShapeProvider from TopTools; - -end FastDiscret; diff --git a/src/BRepMesh/BRepMesh_FastDiscret.cxx b/src/BRepMesh/BRepMesh_FastDiscret.cxx index 9ef681817e..87ca40a802 100644 --- a/src/BRepMesh/BRepMesh_FastDiscret.cxx +++ b/src/BRepMesh/BRepMesh_FastDiscret.cxx @@ -14,79 +14,60 @@ // 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 -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include +#include +#include #include #include #include -#include -#include -#include + #include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include #include +#include #include #include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include #include #include -//#include -#include -#include #include #include #include -#include -#include -#include -#include - -#include -#include #include @@ -97,26 +78,8 @@ #define UVDEFLECTION 1.e-05 -inline Standard_Real MaxFaceTol (const TopoDS_Face& theFace) -{ - Standard_Real T, TMax = BRep_Tool::Tolerance(theFace); - TopExp_Explorer Ex; - - for (Ex.Init(theFace,TopAbs_EDGE); Ex.More(); Ex.Next()) - { - T = BRep_Tool::Tolerance(TopoDS::Edge(Ex.Current())); - if (T > TMax) TMax = T; - } - - for (Ex.Init(theFace,TopAbs_VERTEX); Ex.More(); Ex.Next()) - { - T = BRep_Tool::Tolerance(TopoDS::Vertex(Ex.Current())); - if (T > TMax) TMax = T; - } - - return TMax; -} - +IMPLEMENT_STANDARD_HANDLE (BRepMesh_FastDiscret, Standard_Transient) +IMPLEMENT_STANDARD_RTTIEXT(BRepMesh_FastDiscret, Standard_Transient) //======================================================================= //function : BRepMesh_FastDiscret @@ -141,7 +104,7 @@ BRepMesh_FastDiscret::BRepMesh_FastDiscret(const Standard_Real theDefle, { myAllocator = new NCollection_IncAllocator(64000); if(myRelative) - BoxMaxDimension(theBox, myDtotale); + BRepMesh_ShapeTool::BoxMaxDimension(theBox, myDtotale); } //======================================================================= @@ -149,10 +112,10 @@ BRepMesh_FastDiscret::BRepMesh_FastDiscret(const Standard_Real theDefle, //purpose : //======================================================================= -BRepMesh_FastDiscret::BRepMesh_FastDiscret(const Standard_Real theDefle, - const TopoDS_Shape& theShape, - const Bnd_Box& theBox, +BRepMesh_FastDiscret::BRepMesh_FastDiscret(const TopoDS_Shape& theShape, + const Standard_Real theDefle, const Standard_Real theAngl, + const Bnd_Box& theBox, const Standard_Boolean theWithShare, const Standard_Boolean theInshape, const Standard_Boolean theRelative, @@ -169,7 +132,7 @@ BRepMesh_FastDiscret::BRepMesh_FastDiscret(const Standard_Real theDefle, { myAllocator = new NCollection_IncAllocator(64000); if(myRelative) - BoxMaxDimension(theBox, myDtotale); + BRepMesh_ShapeTool::BoxMaxDimension(theBox, myDtotale); Perform(theShape); } @@ -191,52 +154,6 @@ Standard_Boolean BRepMesh_FastDiscret::IsParallel() const return myInParallel; } -//======================================================================= -//function : BoxMaxDimension -//purpose : -//======================================================================= - -void BRepMesh_FastDiscret::BoxMaxDimension(const Bnd_Box& theBox, Standard_Real& theMaxDim) -{ - if(theBox.IsVoid()) - return; - Standard_Real TXmin, TYmin, TZmin, TXmax, TYmax, TZmax; - theBox.Get(TXmin, TYmin, TZmin, TXmax, TYmax, TZmax); - theMaxDim = TXmax-TXmin; - const Standard_Real dy = TYmax-TYmin; - const Standard_Real dz = TZmax-TZmin; - if (dy > theMaxDim) theMaxDim = dy; - if (dz > theMaxDim) theMaxDim = dz; -} - -//======================================================================= -//function : RelativeEdgeDeflection -//purpose : -//======================================================================= - -Standard_Real BRepMesh_FastDiscret::RelativeEdgeDeflection(const TopoDS_Edge& theEdge, - const Standard_Real theDefle, - const Standard_Real theDTotale, - Standard_Real& theDefCoef) -{ - theDefCoef = 1.; - Standard_Real defedge = theDefle; - if(theEdge.IsNull()) - return defedge; - - Bnd_Box B; - BRepBndLib::Add(theEdge, B); - BoxMaxDimension(B, defedge); - - // adjusted in relation to the total size: - theDefCoef = theDTotale/(2*defedge); - if (theDefCoef < 0.5) theDefCoef = 0.5; - if (theDefCoef > 2.) theDefCoef = 2.; - defedge = theDefCoef * defedge * theDefle; - - return defedge; -} - //======================================================================= //function : Perform(shape) //purpose : @@ -253,24 +170,22 @@ void BRepMesh_FastDiscret::Perform(const TopoDS_Shape& theShape) aFaces.push_back(aF); } +#ifdef HAVE_TBB if (myInParallel) { - #ifdef HAVE_TBB CreateMutexesForSubShapes(theShape, TopAbs_EDGE); // mesh faces in parallel threads using TBB tbb::parallel_for_each (aFaces.begin(), aFaces.end(), *this); - #else - // alternative parallelization not yet available - for (std::vector::iterator it(aFaces.begin()); it != aFaces.end(); it++) - Process (*it); - #endif RemoveAllMutexes(); } else { +#endif for (std::vector::iterator it(aFaces.begin()); it != aFaces.end(); it++) Process (*it); +#ifdef HAVE_TBB } +#endif } @@ -353,12 +268,12 @@ void BRepMesh_FastDiscret::Add(const TopoDS_Face& theface, Standard_Integer nbEdge = 0; Standard_Real savangle = myAngle; Standard_Real cdef; - Standard_Real maxdef = 2.* MaxFaceTol(theface); + Standard_Real maxdef = 2.* BRepMesh_ShapeTool::MaxFaceTolerance(theface); defface = 0.; if (!myRelative) defface = Max(myDeflection, maxdef); - TColStd_SequenceOfReal aFSeq, aLSeq; + BRepMeshCol::SequenceOfReal aFSeq, aLSeq; TColGeom2d_SequenceOfCurve aCSeq; TopTools_SequenceOfShape aShSeq; @@ -380,7 +295,9 @@ void BRepMesh_FastDiscret::Add(const TopoDS_Face& theface, defedge = P->Deflection(); } else { - defedge = RelativeEdgeDeflection(edge, myDeflection, myDtotale, cdef); + defedge = BRepMesh_ShapeTool::RelativeEdgeDeflection(edge, + myDeflection, myDtotale, cdef); + myAngle = savangle * cdef; } defface = defface + defedge; @@ -497,7 +414,7 @@ void BRepMesh_FastDiscret::Add(const TopoDS_Face& theface, Standard_Integer nbVertices = myVemap.Extent(); const Standard_Real tolclass = Precision::PConfusion(); //0.03*Max(myumax-myumin, myvmax-myvmin); - BRepMesh_ClassifierPtr classifier = new BRepMesh_Classifier; + BRepMeshCol::HClassifier classifier = new BRepMesh_Classifier; { BRepMesh_WireChecker aDFaceChecker(face, tolclass, myInternaledges, myVemap, myStructure, @@ -694,28 +611,19 @@ void BRepMesh_FastDiscret::Add(const TopoDS_Face& theface, Nodes(i) = Pnt(index); Nodes2d(i).SetXY(Vertex(index).Coord()); } + BRepMesh_ShapeTool::AddInFace(face, T); - // storage of triangulation in the BRep. - //TopLoc_Location loc = face.Location(); - if (!loc.IsIdentity()) { - gp_Trsf tr = loc.Transformation(); - tr.Invert(); - for (i = Nodes.Lower(); i <= Nodes.Upper(); i++) - Nodes(i).Transform(tr); - } - - BRep_Builder B; - B.UpdateFace(face, T); - - BRepMesh_DataMapIteratorOfDataMapOfShapePairOfPolygon It(myInternaledges); - for (; It.More(); It.Next()) { + BRepMeshCol::DMapOfShapePairOfPolygon::Iterator It(myInternaledges); + for (; It.More(); It.Next()) + { + const TopoDS_Edge& aEdge = TopoDS::Edge(It.Key()); const BRepMesh_PairOfPolygon& pair = It.Value(); const Handle(Poly_PolygonOnTriangulation)& NOD1 = pair.First(); const Handle(Poly_PolygonOnTriangulation)& NOD2 = pair.Last(); if ( NOD1 == NOD2 ) - B.UpdateEdge(TopoDS::Edge(It.Key()), NOD1, T, loc); + BRepMesh_ShapeTool::UpdateEdge(aEdge, NOD1, T, loc); else - B.UpdateEdge(TopoDS::Edge(It.Key()), NOD1, NOD2, T, loc); + BRepMesh_ShapeTool::UpdateEdge(aEdge, NOD1, NOD2, T, loc); } } @@ -906,8 +814,8 @@ void BRepMesh_FastDiscret::Add( const TopoDS_Edge& theEdge, Handle(BRepMesh_FaceAttribute) aFaceAttribute; GetFaceAttribute ( theFace, aFaceAttribute ); - theUV = BRepMesh_FastDiscretFace::FindUV(pBegin, uvFirst, - ipf, theGFace, mindist, aFaceAttribute, myLocation2d); + theUV = BRepMesh_ShapeTool::FindUV(ipf, uvFirst, + pBegin, mindist, aFaceAttribute, theGFace, myLocation2d); BRepMesh_Vertex vf(theUV, ipf, BRepMesh_Frontier); Standard_Integer ivf = myStructure->AddNode(vf); @@ -940,8 +848,8 @@ void BRepMesh_FastDiscret::Add( const TopoDS_Edge& theEdge, } } - theUV = BRepMesh_FastDiscretFace::FindUV(pEnd, uvLast, ipl, - theGFace, mindist, aFaceAttribute, myLocation2d); + theUV = BRepMesh_ShapeTool::FindUV(ipl, uvLast, + pEnd, mindist, aFaceAttribute, theGFace, myLocation2d); BRepMesh_Vertex vl(theUV, ipl, BRepMesh_Frontier); Standard_Integer ivl= myStructure->AddNode(vl); @@ -1000,7 +908,7 @@ void BRepMesh_FastDiscret::Add( const TopoDS_Edge& theEdge, if ( aCurveType == GeomAbs_Circle ) nbpmin = 4; //OCC287 - BRepMesh_GeomTool GT(cons, wFirst, wLast, 0.5 * myAngle, otherdefedge, nbpmin); + BRepMesh_GeomTool GT(cons, wFirst, wLast, otherdefedge, 0.5 * myAngle, nbpmin); if ( aCurveType == GeomAbs_BSplineCurve ) { @@ -1015,7 +923,7 @@ void BRepMesh_FastDiscret::Add( const TopoDS_Edge& theEdge, const Standard_Real& anEndInt = anIntervals.Value( aIntIt + 1 ); BRepMesh_GeomTool aDetalizator( cons, aStartInt, anEndInt, - 0.5 * myAngle, otherdefedge, nbpmin ); + otherdefedge, 0.5 * myAngle, nbpmin ); Standard_Integer aNbAddNodes = aDetalizator.NbPoints(); for ( Standard_Integer aNodeIt = 1; aNodeIt <= aNbAddNodes; ++aNodeIt ) @@ -1023,7 +931,7 @@ void BRepMesh_FastDiscret::Add( const TopoDS_Edge& theEdge, Standard_Real aParam; gp_Pnt aPoint3d; gp_Pnt2d aPoint2d; - aDetalizator.Value( cons, theGFace, aNodeIt, aParam, aPoint3d, aPoint2d ); + aDetalizator.Value( aNodeIt, theGFace, aParam, aPoint3d, aPoint2d ); GT.AddPoint( aPoint3d, aParam, Standard_False ); } } @@ -1069,7 +977,7 @@ void BRepMesh_FastDiscret::Add( const TopoDS_Edge& theEdge, TColStd_Array1OfReal aParamArray(1, nbnodes); for (i = 1; i <= nbnodes; i++) { - GT.Value(cons, theGFace, i, parf, P3d, uvf); + GT.Value(i, theGFace, parf, P3d, uvf); aParamArray.SetValue(i, parf); } for (i = 1; i < nbnodes; i++) @@ -1103,7 +1011,7 @@ void BRepMesh_FastDiscret::Add( const TopoDS_Edge& theEdge, for (i = 2; i < GT.NbPoints(); i++) { // Record 3d point - GT.Value(cons, theGFace, i, puv, P3d, uv); + GT.Value(i, theGFace, puv, P3d, uv); myNbLocat++; myLocation3d.Bind(myNbLocat, P3d); NodInStruct(i) = myNbLocat; @@ -1304,7 +1212,7 @@ Standard_Boolean BRepMesh_FastDiscret::Update(const TopoDS_Edge& theEdg const Standard_Real theLast) { TopLoc_Location Loc; - Handle(Poly_Triangulation) T, TNull; + Handle(Poly_Triangulation) T; Handle(Poly_PolygonOnTriangulation) Poly, NullPoly; Standard_Integer i = 1; @@ -1404,8 +1312,8 @@ Standard_Boolean BRepMesh_FastDiscret::Update(const TopoDS_Edge& theEdg Handle(BRepMesh_FaceAttribute) aFaceAttribute; GetFaceAttribute ( theFace, aFaceAttribute ); - theUV = BRepMesh_FastDiscretFace::FindUV(pBegin, uvFirst, ipf, - gFace, mindist, aFaceAttribute, myLocation2d); + theUV = BRepMesh_ShapeTool::FindUV(ipf, uvFirst, + pBegin, mindist, aFaceAttribute, gFace, myLocation2d); BRepMesh_Vertex vf(theUV,ipf,BRepMesh_Frontier); iv1 = myStructure->AddNode(vf); @@ -1442,8 +1350,8 @@ Standard_Boolean BRepMesh_FastDiscret::Update(const TopoDS_Edge& theEdg } } NewNodInStruct(nbnodes) = ipl; - theUV = BRepMesh_FastDiscretFace::FindUV(pEnd, uvLast, ipl, - gFace, mindist, aFaceAttribute, myLocation2d); + theUV = BRepMesh_ShapeTool::FindUV(ipl, uvLast, + pEnd, mindist, aFaceAttribute, gFace, myLocation2d); BRepMesh_Vertex vl(theUV,ipl,BRepMesh_Frontier); @@ -1589,16 +1497,14 @@ Standard_Boolean BRepMesh_FastDiscret::Update(const TopoDS_Edge& theEdg } else { - BRep_Builder B; - B.UpdateEdge(theEdge,NullPoly,T,Loc); - B.UpdateFace(theFace,TNull); + BRepMesh_ShapeTool::NullifyEdge(theEdge, T, Loc); + BRepMesh_ShapeTool::NullifyFace(theFace); } } else if (!T.IsNull() && !T->HasUVNodes()) { - BRep_Builder B; - B.UpdateEdge(theEdge,NullPoly,T,Loc); - B.UpdateFace(theFace,TNull); + BRepMesh_ShapeTool::NullifyEdge(theEdge, T, Loc); + BRepMesh_ShapeTool::NullifyFace(theFace); } } while (!Poly.IsNull()); @@ -1682,15 +1588,15 @@ const gp_Pnt& BRepMesh_FastDiscret::Pnt(const Standard_Integer Index) const //purpose : //======================================================================= -void BRepMesh_FastDiscret::VerticesOfDomain(BRepMesh_MapOfInteger& Indices) const +void BRepMesh_FastDiscret::VerticesOfDomain(BRepMeshCol::MapOfInteger& Indices) const { Indices.Clear(); // recuperate from the map of edges. - const BRepMesh_MapOfInteger& edmap = myStructure->LinkOfDomain(); + const BRepMeshCol::MapOfInteger& edmap = myStructure->LinksOfDomain(); // iterator on edges. - BRepMesh_MapOfInteger::Iterator iter(edmap); + BRepMeshCol::MapOfInteger::Iterator iter(edmap); Standard_Integer ind_edge; for (iter.Reset(); iter.More(); iter.Next()) { diff --git a/src/BRepMesh/BRepMesh_FastDiscret.hxx b/src/BRepMesh/BRepMesh_FastDiscret.hxx new file mode 100644 index 0000000000..245fa604c0 --- /dev/null +++ b/src/BRepMesh/BRepMesh_FastDiscret.hxx @@ -0,0 +1,289 @@ +// Copyright (c) 2013 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 _BRepMesh_FastDiscret_HeaderFile +#define _BRepMesh_FastDiscret_HeaderFile + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class BRepMesh_DataStructureOfDelaun; +class Bnd_Box; +class TopoDS_Shape; +class TopoDS_Face; +class TopTools_IndexedDataMapOfShapeListOfShape; +class TopoDS_Edge; +class BRepAdaptor_HSurface; +class Geom2d_Curve; +class TopoDS_Vertex; +class BRepMesh_Edge; +class BRepMesh_Vertex; +class gp_Pnt; +class BRepMesh_FaceAttribute; +class TopTools_DataMapOfShapeReal; + + +//! Algorithm to mesh a shape with respect of the
+//! frontier the deflection and by option the shared
+//! components.
+class BRepMesh_FastDiscret : public Standard_Transient +{ +public: + + Standard_EXPORT BRepMesh_FastDiscret(const Standard_Real defle, + const Standard_Real angle, + const Bnd_Box& B, + const Standard_Boolean withShare = Standard_True, + const Standard_Boolean inshape = Standard_False, + const Standard_Boolean relative = Standard_False, + const Standard_Boolean shapetrigu = Standard_False, + const Standard_Boolean isInParallel = Standard_False); + + //! if the boolean is True, the
+ //! deflection used for the polygonalisation of
+ //! each edge will be * Size of Edge.
+ //! the deflection used for the faces will be the maximum
+ //! deflection of their edges.
+ //!
+ //! if is True, the triangulation, if exists
+ //! with a correct deflection, can be used to re-triangulate
+ //! the shape.
+ //!
+ //! if is True, the calculated
+ //! triangulation will be stored in the shape.
+ Standard_EXPORT BRepMesh_FastDiscret(const TopoDS_Shape& shape, + const Standard_Real defle, + const Standard_Real angle, + const Bnd_Box& B, + const Standard_Boolean withShare = Standard_True, + const Standard_Boolean inshape = Standard_False, + const Standard_Boolean relative = Standard_False, + const Standard_Boolean shapetrigu = Standard_False, + const Standard_Boolean isInParallel = Standard_False); + + //! Build triangulation on the whole shape
+ Standard_EXPORT void Perform(const TopoDS_Shape& shape); + + //! Record a face for further processing.
+ Standard_EXPORT void Add(const TopoDS_Face& face, + const TopTools_IndexedDataMapOfShapeListOfShape& ancestor) ; + + //! Triangulate a face previously recorded for
+ //! processing by call to Add(). Can be executed in
+ //! parallel threads.
+ Standard_EXPORT void Process(const TopoDS_Face& face) const; + + void operator ()(const TopoDS_Face& face) const + { + Process(face); + } + + Standard_EXPORT BRepMesh_Status CurrentFaceStatus() const; + + //! Request algorithm to launch in multiple threads
+ //! to improve performance (should be supported by plugin).
+ Standard_EXPORT void SetParallel(const Standard_Boolean theInParallel); + + //! Returns the multi-threading usage flag.
+ Standard_EXPORT Standard_Boolean IsParallel() const; + + //! Creates mutexes for each sub-shape of type theType in theShape.
+ //! Used to avoid data races.
+ Standard_EXPORT void CreateMutexesForSubShapes(const TopoDS_Shape& theShape, + const TopAbs_ShapeEnum theType); + + //! Removes all created mutexes
+ Standard_EXPORT void RemoveAllMutexes(); + + //! Gives the number of built triangles.
+ Standard_EXPORT Standard_Integer NbTriangles() const; + + //! Gives the triangle of .
+ Standard_EXPORT const BRepMesh_Triangle& Triangle(const Standard_Integer Index) const; + + //! Gives the number of built Edges
+ Standard_EXPORT Standard_Integer NbEdges() const; + + //! Gives the edge of index .
+ Standard_EXPORT const BRepMesh_Edge& Edge(const Standard_Integer Index) const; + + //! Gives the number of built Vertices.
+ Standard_EXPORT Standard_Integer NbVertices() const; + + //! Gives the vertex of .
+ Standard_EXPORT const BRepMesh_Vertex& Vertex(const Standard_Integer Index) const; + + //! Gives the nodes of triangle with the given index. + Standard_EXPORT void TriangleNodes(const Standard_Integer theIndex, + Standard_Integer (&theNodes)[3]) const + { + myStructure->ElementNodes(Triangle(theIndex), theNodes); + } + + //! Gives the location3d of the vertex of .
+ Standard_EXPORT const gp_Pnt& Pnt(const Standard_Integer Index) const; + + //! Gives the list of indices of the vertices
+ Standard_EXPORT void VerticesOfDomain(BRepMeshCol::MapOfInteger& Indices) const; + + //! Gives the list of indices of the edges
+ inline void EdgesOfDomain(BRepMeshCol::MapOfInteger& Indices) const + { + Indices = myStructure->LinksOfDomain(); + } + + //! Gives the list of indices of the triangles
+ inline void TrianglesOfDomain(BRepMeshCol::MapOfInteger& Indices) const + { + Indices = myStructure->ElementsOfDomain(); + } + + //! Gives the number of different location in 3d space. + //! It is different of the number of vertices if there + //! is more than one surface.
+ //! Even for one surface, the number can be different + //! if an edge is shared.
+ inline Standard_Integer NbPoint3d() const + { + return myNbLocat; + } + + //! Gives the 3d space location of the vertex .
+ inline const gp_Pnt& Point3d(const Standard_Integer Index) const + { + return myLocation3d(Index); + } + + //! returns the deflection value.
+ inline Standard_Real GetDeflection() const + { + return myDeflection; + } + + //! returns the deflection value.
+ inline Standard_Real GetAngle() const + { + return myAngle; + } + + inline Standard_Boolean WithShare() const + { + return myWithShare; + } + + inline Standard_Boolean InShape() const + { + return myInshape; + } + + inline Standard_Boolean ShapeTrigu() const + { + return myShapetrigu; + } + + //! returns the face deflection value.
+ Standard_EXPORT Standard_Boolean GetFaceAttribute(const TopoDS_Face& face,Handle(BRepMesh_FaceAttribute)& fattrib) const; + + //! remove face attribute as useless to free locate memory
+ Standard_EXPORT void RemoveFaceAttribute(const TopoDS_Face& face); + + inline const TopTools_DataMapOfShapeReal& GetMapOfDefEdge() const + { + return myMapdefle; + } + + + DEFINE_STANDARD_RTTI(BRepMesh_FastDiscret) + +private: + + void Add(const TopoDS_Edge& edge, + const TopoDS_Face& face, + const Handle(BRepAdaptor_HSurface)& S, + const Handle(Geom2d_Curve)& C, + const TopTools_IndexedDataMapOfShapeListOfShape& ancestor, + const Standard_Real defedge, + const Standard_Real first, + const Standard_Real last); + + void Add(const TopoDS_Vertex& theVert, + const TopoDS_Face& face, + const Handle(BRepAdaptor_HSurface)& S); + + Standard_Boolean Update(const TopoDS_Edge& Edge, + const TopoDS_Face& Face, + const Handle(Geom2d_Curve)& C, + const Standard_Real defedge, + const Standard_Real first, + const Standard_Real last); + + void InternalVertices(const Handle(BRepAdaptor_HSurface)& caro, + BRepMeshCol::ListOfVertex& inter, + const Standard_Real defedge, + const BRepMeshCol::HClassifier& classifier); + + Standard_Real Control(const Handle(BRepAdaptor_HSurface)& caro, + const Standard_Real defface, + BRepMeshCol::ListOfVertex& inter, + BRepMeshCol::ListOfInteger& badTri, + BRepMeshCol::ListOfInteger& nulTri, + BRepMesh_Delaun& trigu, + const Standard_Boolean isfirst); + + void AddInShape(const TopoDS_Face& face, + const Standard_Real defedge); + +private: + + Standard_Real myAngle; + Standard_Real myDeflection; + Standard_Real myDtotale; + Standard_Boolean myWithShare; + Standard_Boolean myInParallel; + BRepMeshCol::DMapOfVertexInteger myVertices; + BRepMeshCol::DMapOfShapePairOfPolygon myEdges; + BRepMeshCol::DMapOfShapePairOfPolygon myInternaledges; + Standard_Integer myNbLocat; + BRepMeshCol::DMapOfIntegerPnt myLocation3d; + Handle_BRepMesh_DataStructureOfDelaun myStructure; + BRepMeshCol::DMapOfFaceAttribute myMapattrib; + TColStd_IndexedMapOfInteger myVemap; + BRepMeshCol::DMapOfIntegerListOfXY myLocation2d; + Standard_Boolean myRelative; + Standard_Boolean myShapetrigu; + Standard_Boolean myInshape; + BRepMesh_Status myFacestate; + TopTools_DataMapOfShapeReal myMapdefle; + TopTools_ListOfShape myNottriangulated; + BRepMeshCol::Allocator myAllocator; + TopTools_MutexForShapeProvider myMutexProvider; +}; + +DEFINE_STANDARD_HANDLE(BRepMesh_FastDiscret, Standard_Transient) + +#endif diff --git a/src/BRepMesh/BRepMesh_FastDiscret.lxx b/src/BRepMesh/BRepMesh_FastDiscret.lxx deleted file mode 100644 index 76df6dfe5c..0000000000 --- a/src/BRepMesh/BRepMesh_FastDiscret.lxx +++ /dev/null @@ -1,116 +0,0 @@ -// Created on: 2003-09-26 -// Created by: Open CASCADE Support -// Copyright (c) 2003-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. - -#include - -//======================================================================= -//function : GetDeflection -//purpose : -//======================================================================= - -inline Standard_Real BRepMesh_FastDiscret::GetDeflection() const -{ - return myDeflection; -} - -//======================================================================= -//function : GetAngle -//purpose : -//======================================================================= - -inline Standard_Real BRepMesh_FastDiscret::GetAngle() const -{ - return myAngle; -} - -//======================================================================= -//function : GetMapOfDefEdge -//purpose : -//======================================================================= - -inline const TopTools_DataMapOfShapeReal& BRepMesh_FastDiscret::GetMapOfDefEdge() const -{ - return myMapdefle; -} - -//======================================================================= -//function : EdgesOfDomain -//purpose : -//======================================================================= - -inline void BRepMesh_FastDiscret::EdgesOfDomain(BRepMesh_MapOfInteger& Indices) const -{ - Indices = myStructure->LinkOfDomain(); -} - -//======================================================================= -//function : TrianglesOfDomain -//purpose : -//======================================================================= - -inline void BRepMesh_FastDiscret::TrianglesOfDomain(BRepMesh_MapOfInteger& Indices) const -{ - Indices = myStructure->ElemOfDomain(); -} - -//======================================================================= -//function : NbPoint3d -//purpose : -//======================================================================= - -inline Standard_Integer BRepMesh_FastDiscret::NbPoint3d() const -{ - return myNbLocat; -} - -//======================================================================= -//function : Point3d -//purpose : -//======================================================================= - -inline const gp_Pnt& BRepMesh_FastDiscret::Point3d(const Standard_Integer Index) const -{ - return myLocation3d(Index); -} - -//======================================================================= -//function : WithShare -//purpose : -//======================================================================= - -inline Standard_Boolean BRepMesh_FastDiscret::WithShare() const -{ - return myWithShare; -} - -//======================================================================= -//function : InShape -//purpose : -//======================================================================= - -inline Standard_Boolean BRepMesh_FastDiscret::InShape() const -{ - return myInshape; -} - -//======================================================================= -//function : ShapeTrigu -//purpose : -//======================================================================= - -inline Standard_Boolean BRepMesh_FastDiscret::ShapeTrigu() const -{ - return myShapetrigu; -} diff --git a/src/BRepMesh/BRepMesh_FastDiscretFace.cdl b/src/BRepMesh/BRepMesh_FastDiscretFace.cdl deleted file mode 100644 index 0196d509cc..0000000000 --- a/src/BRepMesh/BRepMesh_FastDiscretFace.cdl +++ /dev/null @@ -1,170 +0,0 @@ --- Created on: 2008-10-28 --- Copyright (c) 2008-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. - -private class FastDiscretFace from BRepMesh inherits TShared from MMgt - - ---Purpose: Algorithm to mesh a face with respect of the - -- frontier the deflection and by option the shared - -- components. - - -uses Boolean from Standard, - Integer from Standard, - Real from Standard, - Face from TopoDS, - Edge from TopoDS, - Vertex from TopoDS, - Pnt from gp, - Pnt2d from gp, - XY from gp, - HSurface from BRepAdaptor, - Delaun from BRepMesh, - DataStructureOfDelaun from BRepMesh, - DataMapOfVertexInteger from BRepMesh, - DataMapOfIntegerListOfXY from BRepMesh, - DataMapOfShapeReal from TopTools, - MutexForShapeProvider from TopTools, - ListOfVertex from BRepMesh, - ClassifierPtr from BRepMesh, - Triangle from BRepMesh, - Edge from BRepMesh, - Vertex from BRepMesh, - FaceAttribute from BRepMesh, - ListOfInteger from TColStd, - BaseAllocator from BRepMesh, - DataMapOfIntegerPnt from BRepMesh, - IndexedMapOfInteger from TColStd, - IndexedMapOfReal from TColStd, - DataMapOfShapePairOfPolygon from BRepMesh, - Triangulation from Poly, - Location from TopLoc - -is - - Create (theAngle : Real from Standard; - theWithShare : Boolean from Standard=Standard_True) - returns FastDiscretFace from BRepMesh; - - - - - Add (me : mutable; - theFace : Face from TopoDS; - theAttrib : FaceAttribute from BRepMesh; - theMapDefle : DataMapOfShapeReal from TopTools; - theMutexProvider : MutexForShapeProvider from TopTools) - is static; - - - Add (me : mutable; - theVert : Vertex from TopoDS; - theFace : Face from TopoDS; - theSFace : HSurface from BRepAdaptor) is private; - - RestoreStructureFromTriangulation - (me: mutable; - theEdge : Edge from TopoDS; - theFace : Face from TopoDS; - theSurf : HSurface from BRepAdaptor; - theTrigu : Triangulation from Poly; - theDefEdge : Real from Standard; - theLoc : Location from TopLoc; - theMutexProvider: MutexForShapeProvider from TopTools) - returns Boolean from Standard is protected; - - - InternalVertices (me : mutable; - theCaro : HSurface from BRepAdaptor; - theInternalV : in out ListOfVertex from BRepMesh; - theDefFace : Real from Standard; - theClassifier : ClassifierPtr from BRepMesh) - is static private; - - - Control (me : mutable; - theCaro : HSurface from BRepAdaptor; - theDefFace : Real from Standard; - theInternalV : in out ListOfVertex from BRepMesh; - theBadTriangles : in out ListOfInteger from TColStd; - theNulTriangles : in out ListOfInteger from TColStd; - theTrigu : in out Delaun from BRepMesh; - theIsFirst : Boolean from Standard) - returns Real from Standard is static; - - FindUV (myclass; - theV : Vertex from TopoDS; - theXY : Pnt2d from gp; - theIp : Integer from Standard; - theSFace : HSurface from BRepAdaptor; - theMinDist : Real from Standard; - theFaceAttribute: FaceAttribute from BRepMesh; - theLocation2dMap: in out DataMapOfIntegerListOfXY from BRepMesh) - returns XY from gp; - - AddInShape (me: mutable; - theFace : Face from TopoDS; - theDefFace: Real from Standard; - theMutexProvider: MutexForShapeProvider from TopTools) - is static private; - - --- Output : - - Triangle (me; - theIndex : Integer from Standard) - ---Purpose: Gives the triangle of . - ---C++: return const & - returns Triangle from BRepMesh - is static; - - Edge (me; - theIndex : Integer from Standard) - ---Purpose: Gives the edge of index . - ---C++: return const & - returns Edge from BRepMesh - is static; - - - Vertex (me; - theIndex : Integer from Standard) - ---Purpose: Gives the vertex of . - ---C++: return const & - returns Vertex from BRepMesh - is static; - - Pnt (me; - theIndex : Integer from Standard) - ---Purpose: Gives the location3d of the vertex of . - ---C++: return const & - returns Pnt from gp - is static; - -fields - myAngle : Real from Standard; - myWithShare : Boolean from Standard; - myVertices : DataMapOfVertexInteger from BRepMesh; - myInternaledges : DataMapOfShapePairOfPolygon from BRepMesh; - myNbLocat : Integer from Standard; - myLocation3d : DataMapOfIntegerPnt from BRepMesh; - myStructure : DataStructureOfDelaun from BRepMesh; - myListver : ListOfVertex from BRepMesh; - myVemap : IndexedMapOfInteger from TColStd; - myLocation2d : DataMapOfIntegerListOfXY from BRepMesh; - myAttrib : FaceAttribute from BRepMesh; - myInternalVerticesMode : Boolean from Standard; --mode to accounting internal vertices - myUParam : IndexedMapOfReal from TColStd; - myVParam : IndexedMapOfReal from TColStd; - myAllocator : BaseAllocator from BRepMesh; - -end FastDiscretFace; diff --git a/src/BRepMesh/BRepMesh_FastDiscretFace.cxx b/src/BRepMesh/BRepMesh_FastDiscretFace.cxx index f8890172e7..b2e5f208ff 100644 --- a/src/BRepMesh/BRepMesh_FastDiscretFace.cxx +++ b/src/BRepMesh/BRepMesh_FastDiscretFace.cxx @@ -12,47 +12,55 @@ // 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 #include -#include +#include +#include +#include + +#include +#include +#include +#include + +#include #include #include #include -#include + #include +#include +#include +#include +#include + #include #include #include -#include -#include #include #include +#include #include #include #include +#include +#include + #include #include +#include #include -#include + #include -#include -#include #include #define UVDEFLECTION 1.e-05 +IMPLEMENT_STANDARD_HANDLE (BRepMesh_FastDiscretFace, Standard_Transient) +IMPLEMENT_STANDARD_RTTIEXT(BRepMesh_FastDiscretFace, Standard_Transient) + static Standard_Real FUN_CalcAverageDUV(TColStd_Array1OfReal& P, const Standard_Integer PLen) { Standard_Integer i, j, n = 0; @@ -169,7 +177,8 @@ void BRepMesh_FastDiscretFace::Add(const TopoDS_Face& theFace const TopoDS_Edge& edge = TopoDS::Edge(ex.Value()); if(edge.IsNull()) continue; - RestoreStructureFromTriangulation(edge, face, gFace, aFaceTrigu, theMapDefle(edge), loc, theMutexProvider); + RestoreStructureFromTriangulation(edge, face, gFace, aFaceTrigu, + theMapDefle(edge), loc, theMutexProvider); } } @@ -195,7 +204,7 @@ void BRepMesh_FastDiscretFace::Add(const TopoDS_Face& theFace Standard_Real deltaX = myAttrib->GetDeltaX(); Standard_Real deltaY = myAttrib->GetDeltaY(); - TColStd_Array1OfInteger tabvert_corr(1, nbVertices); + BRepMeshCol::Array1OfInteger tabvert_corr(1, nbVertices); gp_Pnt2d p2d; // Check the necessity to fill the map of parameters @@ -222,7 +231,7 @@ void BRepMesh_FastDiscretFace::Add(const TopoDS_Face& theFace res.SetCoord((p2d.X() - umin ) / deltaX, (p2d.Y() - vmin ) / deltaY); BRepMesh_Vertex v_new(res,v.Location3d(),v.Movability()); - const BRepMesh_ListOfInteger& alist = myStructure->GetNodeList(i); + const BRepMeshCol::ListOfInteger& alist = myStructure->LinksConnectedTo(i); aMoveNodes.Add(v_new, alist); tabvert_corr(i) = i; } @@ -230,7 +239,7 @@ void BRepMesh_FastDiscretFace::Add(const TopoDS_Face& theFace Standard_Boolean rajout; - BRepMesh_ClassifierPtr& classifier = theAttrib->GetClassifier(); + BRepMeshCol::HClassifier& classifier = theAttrib->GetClassifier(); switch (thetype) { @@ -248,7 +257,7 @@ void BRepMesh_FastDiscretFace::Add(const TopoDS_Face& theFace Standard_Integer nbLinks = myStructure->NbLinks(); for( i = 1; i <= nbLinks; i++ ) { - if( myStructure->ElemConnectedTo(i).Extent() < 1 ) + if( myStructure->ElementsConnectedTo(i).Extent() < 1 ) { BRepMesh_Edge& anEdge = (BRepMesh_Edge&)trigu.GetEdge(i); if ( anEdge.Movability() == BRepMesh_Deleted ) @@ -263,8 +272,8 @@ void BRepMesh_FastDiscretFace::Add(const TopoDS_Face& theFace isaline = ((umax-umin) < UVDEFLECTION) || ((vmax-vmin) < UVDEFLECTION); Standard_Real aDef = -1; - if (!isaline && myStructure->ElemOfDomain().Extent() > 0) { - TColStd_ListOfInteger badTri, nulTri; + if (!isaline && myStructure->ElementsOfDomain().Extent() > 0) { + BRepMeshCol::ListOfInteger badTri, nulTri; if(!rajout) { @@ -292,15 +301,15 @@ void BRepMesh_FastDiscretFace::Add(const TopoDS_Face& theFace InternalVertices(gFace, myListver, theAttrib->GetDefFace(), classifier); if (myListver.Extent() > 0) { - BRepMesh_Array1OfVertexOfDelaun verttab(1, myListver.Extent()); - BRepMesh_ListIteratorOfListOfVertex itVer(myListver); + BRepMeshCol::Array1OfVertexOfDelaun verttab(1, myListver.Extent()); + BRepMeshCol::ListOfVertex::Iterator itVer(myListver); ipn = 1; for (; itVer.More(); itVer.Next()) verttab(ipn++) = itVer.Value(); trigu.AddVertices(verttab); } //control internal points - BRepMesh_ListOfVertex vvlist; + BRepMeshCol::ListOfVertex vvlist; aDef = Control(gFace, theAttrib->GetDefFace(), vvlist, badTri, nulTri, trigu, Standard_False); myListver.Append(vvlist); } @@ -316,7 +325,7 @@ void BRepMesh_FastDiscretFace::Add(const TopoDS_Face& theFace gp_XY res; res.SetCoord(p2d.X() * deltaX + umin, p2d.Y() * deltaY + vmin); BRepMesh_Vertex v_new(res,v.Location3d(),v.Movability()); - const BRepMesh_ListOfInteger& alist = myStructure->GetNodeList(i); + const BRepMeshCol::ListOfInteger& alist = myStructure->LinksConnectedTo(i); aMoveNodes.Add(v_new, alist); } myStructure->ReplaceNodes(aMoveNodes); @@ -326,9 +335,7 @@ void BRepMesh_FastDiscretFace::Add(const TopoDS_Face& theFace } catch(Standard_Failure) { - BRep_Builder B; - Handle(Poly_Triangulation) TNull; - B.UpdateFace(theFace,TNull); + BRepMesh_ShapeTool::NullifyFace(theFace); } #endif // DEB_MESH myStructure.Nullify(); @@ -418,7 +425,9 @@ Standard_Boolean BRepMesh_FastDiscretFace::RestoreStructureFromTriangulation if (mindist < BRep_Tool::Tolerance(pBegin) || mindist < BRep_Tool::Tolerance(pEnd) ) mindist = theDefEdge; - anUV = FindUV(pBegin, uvFirst, ipf, theSurf, mindist, myAttrib, myLocation2d); + anUV = BRepMesh_ShapeTool::FindUV(ipf, uvFirst, + pBegin, mindist, myAttrib, theSurf, myLocation2d); + Standard_Integer iv1, isv1; BRepMesh_Vertex vf(anUV, ipf, BRepMesh_Frontier); iv1 = myStructure->AddNode(vf); @@ -459,7 +468,9 @@ Standard_Boolean BRepMesh_FastDiscretFace::RestoreStructureFromTriangulation } } - anUV = FindUV(pEnd, uvLast, ipl, theSurf, mindist, myAttrib, myLocation2d); + anUV = BRepMesh_ShapeTool::FindUV(ipl, uvLast, + pEnd, mindist, myAttrib, theSurf, myLocation2d); + BRepMesh_Vertex vl(anUV, ipl, BRepMesh_Frontier); Standard_Integer isvl; @@ -538,13 +549,13 @@ Standard_Boolean BRepMesh_FastDiscretFace::RestoreStructureFromTriangulation //purpose : //======================================================================= -static void filterParameters(const TColStd_IndexedMapOfReal& theParams, - const Standard_Real theMinDist, - const Standard_Real theFilterDist, - TColStd_SequenceOfReal& theResult) +static void filterParameters(const BRepMeshCol::IMapOfReal& theParams, + const Standard_Real theMinDist, + const Standard_Real theFilterDist, + BRepMeshCol::SequenceOfReal& theResult) { // Sort sequence of parameters - TColStd_SequenceOfReal aParamTmp; + BRepMeshCol::SequenceOfReal aParamTmp; Standard_Integer aParamLength = 1; const Standard_Integer anInitLen = theParams.Extent(); @@ -633,9 +644,9 @@ static void filterParameters(const TColStd_IndexedMapOfReal& theParams, } void BRepMesh_FastDiscretFace::InternalVertices(const Handle(BRepAdaptor_HSurface)& theCaro, - BRepMesh_ListOfVertex& theInternalV, + BRepMeshCol::ListOfVertex& theInternalV, const Standard_Real theDefFace, - const BRepMesh_ClassifierPtr& theClassifier) + const BRepMeshCol::HClassifier& theClassifier) { BRepMesh_Vertex newV; gp_Pnt2d p2d; @@ -779,7 +790,7 @@ void BRepMesh_FastDiscretFace::InternalVertices(const Handle(BRepAdaptor_HSurfac Standard_Real pp, pasu, pasv; Standard_Real r = T.MinorRadius(), R = T.MajorRadius(); - TColStd_SequenceOfReal ParamU, ParamV; + BRepMeshCol::SequenceOfReal ParamU, ParamV; Standard_Real Du, Dv;//, pasu, pasv; Dv = Max(1.0e0 - (theDefFace/r),0.0e0) ; @@ -913,7 +924,7 @@ void BRepMesh_FastDiscretFace::InternalVertices(const Handle(BRepAdaptor_HSurfac Standard_Real aDuMaxLim = 0.1*(umax-umin); Standard_Real ddu = Min(aDuMaxLim,Max(0.005*(umax-umin),2.*uRes)); - TColStd_SequenceOfReal ParamU; + BRepMeshCol::SequenceOfReal ParamU; filterParameters(myUParam,aMinDu,ddu,ParamU); Standard_Integer ParamULength = ParamU.Length(); @@ -923,7 +934,7 @@ void BRepMesh_FastDiscretFace::InternalVertices(const Handle(BRepAdaptor_HSurfac Standard_Real aDvMaxLim = 0.1*(vmax-vmin); Standard_Real ddv = Min(aDvMaxLim,Max(0.005*(vmax-vmin),2.*vRes)); - TColStd_SequenceOfReal ParamV; + BRepMeshCol::SequenceOfReal ParamV; filterParameters(myVParam,aMinDv,ddv,ParamV); Standard_Integer ParamVLength = ParamV.Length(); @@ -1052,7 +1063,7 @@ void BRepMesh_FastDiscretFace::InternalVertices(const Handle(BRepAdaptor_HSurfac Standard_Integer i, j, nbpointsU = 10, nbpointsV = 10; Adaptor3d_IsoCurve tabu[11], tabv[11]; - TColStd_SequenceOfReal ParamU, ParamV; + BRepMeshCol::SequenceOfReal ParamU, ParamV; Standard_Real u, v, du, dv; Standard_Integer iu, iv; Standard_Real f, l; @@ -1123,7 +1134,7 @@ void BRepMesh_FastDiscretFace::InternalVertices(const Handle(BRepAdaptor_HSurfac ParamV.InsertAfter(1, (vmax+vmin)*0.5); } - TColStd_SequenceOfReal InsertV, InsertU; + BRepMeshCol::SequenceOfReal InsertV, InsertU; gp_Pnt P1; Adaptor3d_IsoCurve IsoV; @@ -1193,9 +1204,9 @@ typedef NCollection_Map BRepMesh_MapOfCouple; //======================================================================= Standard_Real BRepMesh_FastDiscretFace::Control(const Handle(BRepAdaptor_HSurface)& theCaro, const Standard_Real theDefFace, - BRepMesh_ListOfVertex& theInternalV, - TColStd_ListOfInteger& theBadTriangles, - TColStd_ListOfInteger& theNulTriangles, + BRepMeshCol::ListOfVertex& theInternalV, + BRepMeshCol::ListOfInteger& theBadTriangles, + BRepMeshCol::ListOfInteger& theNulTriangles, BRepMesh_Delaun& theTrigu, const Standard_Boolean theIsFirst) { @@ -1214,7 +1225,7 @@ Standard_Real BRepMesh_FastDiscretFace::Control(const Handle(BRepAdaptor_HSurfac // Create map of links to skip already processed Standard_Integer nbtriangles; - nbtriangles = myStructure->ElemOfDomain().Extent(); + nbtriangles = myStructure->ElementsOfDomain().Extent(); if (nbtriangles <= 0) return -1.0; BRepMesh_MapOfCouple theCouples(3*nbtriangles); @@ -1241,7 +1252,7 @@ Standard_Real BRepMesh_FastDiscretFace::Control(const Handle(BRepAdaptor_HSurfac } NCollection_DataMap aNorMap; - NCollection_DataMap aStatMap; + BRepMeshCol::MapOfIntegerInteger aStatMap; // Perform refinement passes for (; pass <= nbPasses && nbInserted && !allDegenerated; pass++) @@ -1258,12 +1269,12 @@ Standard_Real BRepMesh_FastDiscretFace::Control(const Handle(BRepAdaptor_HSurfac caninsert = (myWithShare || pass < nbPasses); // Read mesh size - nbtriangles = myStructure->ElemOfDomain().Extent(); + nbtriangles = myStructure->ElementsOfDomain().Extent(); if (nbtriangles <= 0) break; // Iterate on current triangles - BRepMesh_MapOfInteger::Iterator triDom; - const BRepMesh_MapOfInteger& TriMap = myStructure->ElemOfDomain(); + BRepMeshCol::MapOfInteger::Iterator triDom; + const BRepMeshCol::MapOfInteger& TriMap = myStructure->ElementsOfDomain(); triDom.Initialize(TriMap); Standard_Integer aNbPnt = 0; Standard_Real umin = myAttrib->GetUMin(); @@ -1276,33 +1287,20 @@ Standard_Real BRepMesh_FastDiscretFace::Control(const Handle(BRepAdaptor_HSurfac const BRepMesh_Triangle& curTri=Triangle(TriId); if (curTri.Movability()==BRepMesh_Deleted) continue; - Standard_Boolean o1, o2, o3; - Standard_Integer v1 = 0, v2 = 0, v3 = 0, e1 = 0, e2 = 0, e3 = 0; - curTri.Edges(e1, e2, e3, o1, o2, o3); - - const BRepMesh_Edge& edg1=Edge(e1); - const BRepMesh_Edge& edg2=Edge(e2); - const BRepMesh_Edge& edg3=Edge(e3); - - Standard_Boolean m1 = (edg1.Movability() == BRepMesh_Frontier); - Standard_Boolean m2 = (edg2.Movability() == BRepMesh_Frontier); - Standard_Boolean m3 = (edg3.Movability() == BRepMesh_Frontier); - if (o1) { - v1=edg1.FirstNode(); - v2=edg1.LastNode(); - } - else { - v1=edg1.LastNode(); - v2=edg1.FirstNode(); - } - if (o2) - v3=edg2.LastNode(); - else - v3=edg2.FirstNode(); + Standard_Integer v[3]; + myStructure->ElementNodes(curTri, v); - const BRepMesh_Vertex& vert1=Vertex(v1); - const BRepMesh_Vertex& vert2=Vertex(v2); - const BRepMesh_Vertex& vert3=Vertex(v3); + Standard_Integer e[3]; + Standard_Boolean o[3]; + curTri.Edges(e, o); + + Standard_Boolean m1 = (Edge(e[0]).Movability() == BRepMesh_Frontier); + Standard_Boolean m2 = (Edge(e[1]).Movability() == BRepMesh_Frontier); + Standard_Boolean m3 = (Edge(e[2]).Movability() == BRepMesh_Frontier); + + const BRepMesh_Vertex& vert1=Vertex(v[0]); + const BRepMesh_Vertex& vert2=Vertex(v[1]); + const BRepMesh_Vertex& vert3=Vertex(v[2]); const gp_XYZ& p1=myLocation3d(vert1.Location3d()).Coord(); const gp_XYZ& p2=myLocation3d(vert2.Location3d()).Coord(); @@ -1372,7 +1370,7 @@ Standard_Real BRepMesh_FastDiscretFace::Control(const Handle(BRepAdaptor_HSurfac if (!m2) // Not a boundary { // Check if this link was already processed - if (v2 < v3) { nf = v2; nl = v3; } else { nf = v3; nl = v2; } + if (v[1] < v[2]) { nf = v[1]; nl = v[2]; } else { nf = v[2]; nl = v[1]; } if (theCouples.Add(BRepMesh_Couple(nf,nl))) { // Check deflection on edge 1 @@ -1402,7 +1400,7 @@ Standard_Real BRepMesh_FastDiscretFace::Control(const Handle(BRepAdaptor_HSurfac if (!m3) // Not a boundary { // Check if this link was already processed - if (v1 < v3) { nf = v1; nl = v3; } else { nf = v3; nl = v1; } + if (v[0] < v[2]) { nf = v[0]; nl = v[2]; } else { nf = v[2]; nl = v[0]; } if (theCouples.Add(BRepMesh_Couple(nf,nl))) { // Check deflection on edge 2 @@ -1432,7 +1430,7 @@ Standard_Real BRepMesh_FastDiscretFace::Control(const Handle(BRepAdaptor_HSurfac if (!m1) // Not a boundary { // Check if this link was already processed - if (v1 < v2) { nf = v1; nl = v2; } else { nf = v2; nl = v1; } + if (v[0] < v[1]) { nf = v[0]; nl = v[1]; } else { nf = v[1]; nl = v[0]; } if (theCouples.Add(BRepMesh_Couple(nf,nl))) { // Check deflection on edge 3 @@ -1464,34 +1462,34 @@ Standard_Real BRepMesh_FastDiscretFace::Control(const Handle(BRepAdaptor_HSurfac { gp_Dir N1(0,0,1), N2(0,0,1), N3(0,0,1); Standard_Integer aSt1, aSt2, aSt3; - if(aNorMap.IsBound(v1)) { - aSt1 = aStatMap.Find(v1); - N1 =aNorMap.Find(v1); + if(aNorMap.IsBound(v[0])) { + aSt1 = aStatMap.Find(v[0]); + N1 =aNorMap.Find(v[0]); } else { aSt1 = GeomLib::NormEstim(BSpl, gp_Pnt2d(xy1), Precision::Confusion(), N1); - aStatMap.Bind(v1,aSt1); - aNorMap.Bind(v1,N1); + aStatMap.Bind(v[0],aSt1); + aNorMap.Bind(v[0],N1); } - if(aNorMap.IsBound(v2)) { - aSt2 = aStatMap.Find(v2); - N2 = aNorMap.Find(v2); + if(aNorMap.IsBound(v[1])) { + aSt2 = aStatMap.Find(v[1]); + N2 = aNorMap.Find(v[1]); } else { aSt2 = GeomLib::NormEstim(BSpl, gp_Pnt2d(xy2), Precision::Confusion(), N2); - aStatMap.Bind(v2,aSt2); - aNorMap.Bind(v2,N2); + aStatMap.Bind(v[1],aSt2); + aNorMap.Bind(v[1],N2); } - if(aNorMap.IsBound(v3)) { - aSt3 = aStatMap.Find(v3); - N3 = aNorMap.Find(v3); + if(aNorMap.IsBound(v[2])) { + aSt3 = aStatMap.Find(v[2]); + N3 = aNorMap.Find(v[2]); } else { aSt3 = GeomLib::NormEstim(BSpl, gp_Pnt2d(xy3), Precision::Confusion(), N3); - aStatMap.Bind(v3,aSt3); - aNorMap.Bind(v3,N3.XYZ()); + aStatMap.Bind(v[2],aSt3); + aNorMap.Bind(v[2],N3.XYZ()); } Standard_Real anAngle1 = N2.Angle(N1); @@ -1508,8 +1506,8 @@ Standard_Real BRepMesh_FastDiscretFace::Control(const Handle(BRepAdaptor_HSurfac if (!theIsFirst && theInternalV.Extent() > 0) { - BRepMesh_Array1OfVertexOfDelaun verttab(1, theInternalV.Extent()); - BRepMesh_ListIteratorOfListOfVertex itVer(theInternalV); + BRepMeshCol::Array1OfVertexOfDelaun verttab(1, theInternalV.Extent()); + BRepMeshCol::ListOfVertex::Iterator itVer(theInternalV); Standard_Integer ipn = 1; for (; itVer.More(); itVer.Next()) verttab(ipn++) = itVer.Value(); @@ -1532,63 +1530,42 @@ void BRepMesh_FastDiscretFace::AddInShape(const TopoDS_Face& theFace, const Standard_Real theDefFace, const TopTools_MutexForShapeProvider& theMutexProvider) { -// gp_Pnt Pt; - BRep_Builder B; TopLoc_Location loc = theFace.Location(); Handle(Poly_Triangulation) TOld = BRep_Tool::Triangulation(theFace, loc); - Handle(Poly_Triangulation) TNull; Handle(Poly_PolygonOnTriangulation) NullPoly; - B.UpdateFace(theFace,TNull); + + BRepMesh_ShapeTool::NullifyFace(theFace); try{ - BRepMesh_MapOfInteger::Iterator it; + BRepMeshCol::MapOfInteger::Iterator it; - Standard_Integer e1, e2, e3, nTri; - Standard_Integer v1, v2, v3, iv1, iv2, iv3; Standard_Integer i, index; - Standard_Boolean o1, o2, o3; TopAbs_Orientation orFace = theFace.Orientation(); - const BRepMesh_MapOfInteger& TriMap = myStructure->ElemOfDomain(); + const BRepMeshCol::MapOfInteger& TriMap = myStructure->ElementsOfDomain(); it.Initialize(TriMap); - nTri = TriMap.Extent(); - + Standard_Integer nTri = TriMap.Extent(); if (nTri != 0) { Poly_Array1OfTriangle Tri(1, nTri); i = 1; - for (; it.More(); it.Next()) { - myStructure->GetElement(it.Key()).Edges(e1, e2, e3, o1, o2, o3); + for (; it.More(); it.Next()) + { + const BRepMesh_Triangle& aCurElem = myStructure->GetElement(it.Key()); + + Standard_Integer v[3]; + myStructure->ElementNodes(aCurElem, v); - const BRepMesh_Edge& ve1=myStructure->GetLink(e1); - const BRepMesh_Edge& ve2=myStructure->GetLink(e2); - - if (o1) { - v1=ve1.FirstNode(); - } - else { - v1=ve1.LastNode(); - } - if (o2) - { - v2=ve2.FirstNode(); - v3=ve2.LastNode(); - } - else - { - v3=ve2.FirstNode(); - v2=ve2.LastNode(); - } - - iv1 = myVemap.FindIndex(v1); - if (iv1 == 0) iv1 = myVemap.Add(v1); - iv2 = myVemap.FindIndex(v2); - if (iv2 == 0) iv2 = myVemap.Add(v2); - iv3 = myVemap.FindIndex(v3); - if (iv3 == 0) iv3 = myVemap.Add(v3); + Standard_Integer iv1, iv2, iv3; + iv1 = myVemap.FindIndex(v[0]); + if (iv1 == 0) iv1 = myVemap.Add(v[0]); + iv2 = myVemap.FindIndex(v[1]); + if (iv2 == 0) iv2 = myVemap.Add(v[1]); + iv3 = myVemap.FindIndex(v[2]); + if (iv3 == 0) iv3 = myVemap.Add(v[2]); if (orFace == TopAbs_REVERSED) Tri(i++).Set(iv1, iv3, iv2); else Tri(i++).Set(iv1, iv2, iv3); @@ -1608,22 +1585,13 @@ void BRepMesh_FastDiscretFace::AddInShape(const TopoDS_Face& theFace, } T->Deflection(theDefFace); - - // storage of triangulation in BRep. - BRep_Builder B1; - //TopLoc_Location loc = theFace.Location(); - if (!loc.IsIdentity()) { - gp_Trsf tr = loc.Transformation(); - tr.Invert(); - for (i = Nodes.Lower(); i <= Nodes.Upper(); i++) - Nodes(i).Transform(tr); - } - B1.UpdateFace(theFace, T); + BRepMesh_ShapeTool::AddInFace(theFace, T); // implement polygons on triangulation in the face: - BRepMesh_DataMapIteratorOfDataMapOfShapePairOfPolygon It(myInternaledges); + BRepMeshCol::DMapOfShapePairOfPolygon::Iterator It(myInternaledges); for (; It.More(); It.Next()) { + const TopoDS_Edge& aEdge = TopoDS::Edge(It.Key()); const BRepMesh_PairOfPolygon& pair = It.Value(); const Handle(Poly_PolygonOnTriangulation)& NOD1 = pair.First(); const Handle(Poly_PolygonOnTriangulation)& NOD2 = pair.Last(); @@ -1633,12 +1601,12 @@ void BRepMesh_FastDiscretFace::AddInShape(const TopoDS_Face& theFace, Standard_Mutex::Sentry aSentry (aMutex); if ( NOD1 == NOD2 ) { - B.UpdateEdge(TopoDS::Edge(It.Key()), NullPoly, TOld,loc); - B.UpdateEdge(TopoDS::Edge(It.Key()), NOD1, T, loc); + BRepMesh_ShapeTool::NullifyEdge(aEdge, TOld, loc); + BRepMesh_ShapeTool::UpdateEdge(aEdge, NOD1, T, loc); } else { - B.UpdateEdge(TopoDS::Edge(It.Key()), NullPoly, TOld,loc); - B.UpdateEdge(TopoDS::Edge(It.Key()), NOD1, NOD2, T, loc); + BRepMesh_ShapeTool::NullifyEdge(aEdge, TOld, loc); + BRepMesh_ShapeTool::UpdateEdge(aEdge, NOD1, NOD2, T, loc); } } } @@ -1702,80 +1670,6 @@ const gp_Pnt& BRepMesh_FastDiscretFace::Pnt(const Standard_Integer Index) const return myLocation3d(myStructure->GetNode(Index).Location3d()); } -//======================================================================= -//function : FindUV -//purpose : -//======================================================================= - -gp_XY BRepMesh_FastDiscretFace::FindUV(const TopoDS_Vertex& theV, - const gp_Pnt2d& theXY, - const Standard_Integer theIp, - const Handle(BRepAdaptor_HSurface)& theSFace, - const Standard_Real theMinDist, - const Handle(BRepMesh_FaceAttribute)& theFaceAttribute, - BRepMesh_DataMapOfIntegerListOfXY& theLocation2dMap) -{ - gp_XY anUV; - if (theLocation2dMap.IsBound(theIp)) - { - BRepMesh_ListOfXY& L = theLocation2dMap.ChangeFind(theIp); - anUV = L.First(); - if (L.Extent() != 1) - { - BRepMesh_ListIteratorOfListOfXY it(L); - it.Next(); - Standard_Real dd, dmin = theXY.Distance(gp_Pnt2d(anUV)); - for (; it.More(); it.Next()) - { - dd = theXY.Distance(gp_Pnt2d(it.Value())); - if (dd < dmin) - { - anUV = it.Value(); - dmin = dd; - } - } - } - - const Standard_Real tol = Min(2. * BRep_Tool::Tolerance(theV), theMinDist); - - Standard_Real aDiffU, aDiffV; - - if ( theFaceAttribute.IsNull() ) - { - aDiffU = theSFace->LastUParameter() - theSFace->FirstUParameter(); - aDiffV = theSFace->LastVParameter() - theSFace->FirstVParameter(); - } - else - { - aDiffU = theFaceAttribute->GetUMax() - theFaceAttribute->GetUMin(); - aDiffV = theFaceAttribute->GetVMax() - theFaceAttribute->GetVMin(); - } - - const Standard_Real Utol2d = .5 * aDiffU; - const Standard_Real Vtol2d = .5 * aDiffV; - - const gp_Pnt p1 = theSFace->Value(anUV.X(), anUV.Y()); - const gp_Pnt p2 = theSFace->Value(theXY.X(), theXY.Y()); - - if (Abs(anUV.X() - theXY.X()) > Utol2d || - Abs(anUV.Y() - theXY.Y()) > Vtol2d || - !p1.IsEqual(p2, tol)) - { - anUV = theXY.Coord(); - L.Append(anUV); - } - } - else - { - anUV = theXY.Coord(); - BRepMesh_ListOfXY L; - L.Append(anUV); - theLocation2dMap.Bind(theIp, L); - } - return anUV; -} - - static Standard_Boolean GetVertexParameters(const TopoDS_Vertex& theVert, const TopoDS_Face& theFace, gp_Pnt2d& thePoint) @@ -1822,7 +1716,9 @@ void BRepMesh_FastDiscretFace::Add(const TopoDS_Vertex& theVert, } Standard_Real mindist = BRep_Tool::Tolerance(theVert); // gp_Pnt2d uvXY = BRep_Tool::Parameters(theVert,theFace); - gp_XY anUV = FindUV(theVert, uvXY, indVert, thegFace, mindist, myAttrib, myLocation2d); + gp_XY anUV = BRepMesh_ShapeTool::FindUV(indVert, uvXY, + theVert, mindist, myAttrib, thegFace, myLocation2d); + BRepMesh_Vertex vf(anUV, indVert, BRepMesh_Fixed); Standard_Integer ivff = myStructure->AddNode(vf); Standard_Integer isvf = myVemap.FindIndex(ivff); diff --git a/src/BRepMesh/BRepMesh_FastDiscretFace.hxx b/src/BRepMesh/BRepMesh_FastDiscretFace.hxx new file mode 100644 index 0000000000..bb42352bfc --- /dev/null +++ b/src/BRepMesh/BRepMesh_FastDiscretFace.hxx @@ -0,0 +1,127 @@ +// Copyright (c) 2013 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 _BRepMesh_FastDiscretFace_HeaderFile +#define _BRepMesh_FastDiscretFace_HeaderFile + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class BRepMesh_DataStructureOfDelaun; +class BRepMesh_FaceAttribute; +class TopoDS_Face; +class TopTools_DataMapOfShapeReal; +class TopoDS_Vertex; +class BRepAdaptor_HSurface; +class TopoDS_Edge; +class Poly_Triangulation; +class TopLoc_Location; +class gp_XY; +class gp_Pnt2d; +class BRepMesh_Edge; +class BRepMesh_Vertex; +class gp_Pnt; + +//! Algorithm to mesh a face with respect of the frontier +//! the deflection and by option the shared components.
+class BRepMesh_FastDiscretFace : public Standard_Transient +{ +public: + + + Standard_EXPORT BRepMesh_FastDiscretFace(const Standard_Real theAngle, + const Standard_Boolean theWithShare = Standard_True); + + Standard_EXPORT void Add(const TopoDS_Face& theFace, + const Handle(BRepMesh_FaceAttribute)& theAttrib, + const TopTools_DataMapOfShapeReal& theMapDefle, + const TopTools_MutexForShapeProvider& theMutexProvider); + + Standard_EXPORT Standard_Real Control(const Handle(BRepAdaptor_HSurface)& theCaro, + const Standard_Real theDefFace, + BRepMeshCol::ListOfVertex& theInternalV, + BRepMeshCol::ListOfInteger& theBadTriangles, + BRepMeshCol::ListOfInteger& theNulTriangles, + BRepMesh_Delaun& theTrigu, + const Standard_Boolean theIsFirst); + + //! Gives the triangle of .
+ Standard_EXPORT const BRepMesh_Triangle& Triangle(const Standard_Integer theIndex) const; + + //! Gives the edge of index .
+ Standard_EXPORT const BRepMesh_Edge& Edge(const Standard_Integer theIndex) const; + + //! Gives the vertex of .
+ Standard_EXPORT const BRepMesh_Vertex& Vertex(const Standard_Integer theIndex) const; + + //! Gives the location3d of the vertex of .
+ Standard_EXPORT const gp_Pnt& Pnt(const Standard_Integer theIndex) const; + + DEFINE_STANDARD_RTTI(BRepMesh_FastDiscretFace) + +protected: + + Standard_Boolean RestoreStructureFromTriangulation(const TopoDS_Edge& theEdge, + const TopoDS_Face& theFace, + const Handle(BRepAdaptor_HSurface)& theSurf, + const Handle(Poly_Triangulation)& theTrigu, + const Standard_Real theDefEdge, + const TopLoc_Location& theLoc, + const TopTools_MutexForShapeProvider& theMutexProvider); + +private: + + void Add(const TopoDS_Vertex& theVert, + const TopoDS_Face& theFace, + const Handle(BRepAdaptor_HSurface)& theSFace); + + void InternalVertices(const Handle(BRepAdaptor_HSurface)& theCaro, + BRepMeshCol::ListOfVertex& theInternalV, + const Standard_Real theDefFace, + const BRepMeshCol::HClassifier& theClassifier); + + void AddInShape(const TopoDS_Face& theFace, + const Standard_Real theDefFace, + const TopTools_MutexForShapeProvider& theMutexProvider); + +private: + Standard_Real myAngle; + Standard_Boolean myWithShare; + BRepMeshCol::DMapOfVertexInteger myVertices; + BRepMeshCol::DMapOfShapePairOfPolygon myInternaledges; + Standard_Integer myNbLocat; + BRepMeshCol::DMapOfIntegerPnt myLocation3d; + Handle_BRepMesh_DataStructureOfDelaun myStructure; + BRepMeshCol::ListOfVertex myListver; + BRepMeshCol::IMapOfInteger myVemap; + BRepMeshCol::DMapOfIntegerListOfXY myLocation2d; + Handle_BRepMesh_FaceAttribute myAttrib; + Standard_Boolean myInternalVerticesMode; + BRepMeshCol::IMapOfReal myUParam; + BRepMeshCol::IMapOfReal myVParam; + BRepMeshCol::Allocator myAllocator; +}; + +DEFINE_STANDARD_HANDLE (BRepMesh_FastDiscretFace, Standard_Transient) + +#endif diff --git a/src/BRepMesh/BRepMesh_GeomTool.cdl b/src/BRepMesh/BRepMesh_GeomTool.cdl deleted file mode 100644 index e476a5a96e..0000000000 --- a/src/BRepMesh/BRepMesh_GeomTool.cdl +++ /dev/null @@ -1,75 +0,0 @@ --- Created on: 1993-09-29 --- Created by: Isabelle GRIGNON --- Copyright (c) 1993-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. - -class GeomTool from BRepMesh - ---Purpose: - -uses - Pnt from gp, - Vec from gp, - Dir from gp, - Pnt2d from gp, - IsoType from GeomAbs, - TangentialDeflection from GCPnts, - Curve from BRepAdaptor, - HSurface from BRepAdaptor - - - -is - - Create (C : in out Curve from BRepAdaptor; - Ufirst,Ulast,AngDefl, Deflection : Real; - nbpointsmin: Integer = 2) - returns GeomTool; - - Create (S : HSurface from BRepAdaptor; - ParamIso : Real; - Type : IsoType from GeomAbs; - Ufirst,Ulast,AngDefl,Deflection : Real; - nbpointsmin: Integer = 2) returns GeomTool; - - AddPoint(me : in out; thePnt : in Pnt from gp; - theParam : in Real; - theIsReplace : in Boolean = Standard_True) - returns Integer from Standard; - ---Purpose: Add point to already calculated points (or replace existing) - -- Returns index of new added point - -- or founded with parametric tolerance (replaced if theIsReplace is true) - - NbPoints(me) returns Integer from Standard; - - Value(me; IsoParam : Real ; Index : Integer ; - W : out Real; P : out Pnt from gp; UV : out Pnt2d from gp); - - Value(me;C : Curve from BRepAdaptor; - S : HSurface from BRepAdaptor; - Index : Integer from Standard; - W : out Real; P : out Pnt from gp; UV : out Pnt2d from gp); - - D0(myclass; F : HSurface from BRepAdaptor;U,V : Real; P : out Pnt); - - Normal(myclass; F : HSurface from BRepAdaptor;U,V : Real ; P : out Pnt from gp; - Nor : out Dir from gp) - returns Boolean from Standard; - ---Purpose: return false if the normal can not be computed - -fields - -pnts : TangentialDeflection from GCPnts; -parametric : IsoType from GeomAbs; - -end GeomTool; diff --git a/src/BRepMesh/BRepMesh_GeomTool.cxx b/src/BRepMesh/BRepMesh_GeomTool.cxx index 53ccef5186..ba95397148 100644 --- a/src/BRepMesh/BRepMesh_GeomTool.cxx +++ b/src/BRepMesh/BRepMesh_GeomTool.cxx @@ -14,103 +14,323 @@ // 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 -BRepMesh_GeomTool::BRepMesh_GeomTool(BRepAdaptor_Curve& C, - const Standard_Real Ufirst, - const Standard_Real Ulast, - const Standard_Real AngDefl, - const Standard_Real Deflection, - const Standard_Integer nbpmin) : - pnts(C,Ufirst,Ulast,AngDefl,Deflection, nbpmin), -// pnts(C,Deflection,Ufirst,Ulast), - parametric(GeomAbs_NoneIso) +//======================================================================= +//function : Constructor +//purpose : +//======================================================================= +BRepMesh_GeomTool::BRepMesh_GeomTool( + const BRepAdaptor_Curve& theCurve, + const Standard_Real theFirstParam, + const Standard_Real theLastParam, + const Standard_Real theLinDeflection, + const Standard_Real theAngDeflection, + const Standard_Integer theMinPointsNb) + : myEdge(&theCurve.Edge()), + myIsoType(GeomAbs_NoneIso) { -} -// -BRepMesh_GeomTool::BRepMesh_GeomTool(const Handle(BRepAdaptor_HSurface)& S, - const Standard_Real ParamIso, - const GeomAbs_IsoType Type, - const Standard_Real Ufirst, - const Standard_Real Ulast, - const Standard_Real AngDefl, - const Standard_Real Deflection, - const Standard_Integer nbpmin) : - parametric(Type) -{ - Adaptor3d_IsoCurve Iso(S, Type,ParamIso,Ufirst,Ulast); - pnts.Initialize(Iso,Ufirst,Ulast,AngDefl,Deflection, nbpmin); -// pnts.Initialize(Iso,Deflection,Ufirst,Ulast); + myDiscretTool.Initialize(theCurve, theFirstParam, theLastParam, + theAngDeflection, theLinDeflection, theMinPointsNb); } -Standard_Integer BRepMesh_GeomTool::AddPoint(const gp_Pnt& thePnt, - const Standard_Real theParam, - const Standard_Boolean theIsReplace) +//======================================================================= +//function : Constructor +//purpose : +//======================================================================= +BRepMesh_GeomTool::BRepMesh_GeomTool( + const Handle(BRepAdaptor_HSurface)& theSurface, + const GeomAbs_IsoType theIsoType, + const Standard_Real theParamIso, + const Standard_Real theFirstParam, + const Standard_Real theLastParam, + const Standard_Real theLinDeflection, + const Standard_Real theAngDeflection, + const Standard_Integer theMinPointsNb) + : myEdge(NULL), + myIsoType(theIsoType) { - return pnts.AddPoint(thePnt, theParam, theIsReplace); + Adaptor3d_IsoCurve aIso(theSurface, theIsoType, theParamIso, + theFirstParam, theLastParam); + + myDiscretTool.Initialize(aIso, theFirstParam, theLastParam, + theAngDeflection, theLinDeflection, theMinPointsNb); } -Standard_Integer BRepMesh_GeomTool::NbPoints() const { - return pnts.NbPoints(); +//======================================================================= +//function : Value +//purpose : +//======================================================================= +Standard_Boolean BRepMesh_GeomTool::Value( + const Standard_Integer theIndex, + const Handle(BRepAdaptor_HSurface)& theSurface, + Standard_Real& theParam, + gp_Pnt& thePoint, + gp_Pnt2d& theUV) const +{ + if (theIndex < 1 || theIndex > NbPoints()) + return Standard_False; + + if (myEdge == NULL) + return Standard_False; + + thePoint = myDiscretTool.Value(theIndex); + theParam = myDiscretTool.Parameter(theIndex); + + const TopoDS_Face& aFace = ((BRepAdaptor_Surface*)&(theSurface->Surface()))->Face(); + + Standard_Real aFirst, aLast; + Handle(Geom2d_Curve) aCurve = + BRep_Tool::CurveOnSurface(*myEdge, aFace, aFirst, aLast); + + aCurve->D0(theParam, theUV); + + return Standard_True; } -void BRepMesh_GeomTool::Value(const Standard_Real IsoParam, - const Standard_Integer Index, - Standard_Real& W, gp_Pnt& P, gp_Pnt2d& UV) const +//======================================================================= +//function : Value +//purpose : +//======================================================================= +Standard_Boolean BRepMesh_GeomTool::Value(const Standard_Integer theIndex, + const Standard_Real theIsoParam, + Standard_Real& theParam, + gp_Pnt& thePoint, + gp_Pnt2d& theUV) const { - P = pnts.Value(Index); - W = pnts.Parameter(Index); - if (parametric == GeomAbs_IsoU) { - UV.SetCoord(IsoParam,W); - } - else { - UV.SetCoord(W,IsoParam); + if (theIndex < 1 || theIndex > NbPoints()) + return Standard_False; + + thePoint = myDiscretTool.Value(theIndex); + theParam = myDiscretTool.Parameter(theIndex); + + if (myIsoType == GeomAbs_IsoU) + theUV.SetCoord(theIsoParam, theParam); + else + theUV.SetCoord(theParam, theIsoParam); + + return Standard_True; +} + +//======================================================================= +//function : Normal +//purpose : +//======================================================================= +Standard_Boolean BRepMesh_GeomTool::Normal( + const Handle(BRepAdaptor_HSurface)& theSurface, + const Standard_Real theParamU, + const Standard_Real theParamV, + gp_Pnt& thePoint, + gp_Dir& theNormal) +{ + Standard_Boolean isOK = Standard_True; + gp_Vec aD1U, aD1V; + + theSurface->D1(theParamU, theParamV, thePoint, aD1U, aD1V); + + CSLib_DerivativeStatus aStatus; + CSLib::Normal(aD1U, aD1V, Precision::Angular(), aStatus, theNormal); + if (aStatus != CSLib_Done) + { + gp_Vec aD2U,aD2V,aD2UV; + theSurface->D2(theParamU, theParamV, thePoint, aD1U, aD1V, aD2U, aD2V, aD2UV); + CSLib_NormalStatus aNormalStatus; + CSLib::Normal(aD1U, aD1V, aD2U, aD2V, aD2UV, Precision::Angular(), + isOK, aNormalStatus, theNormal); } + + if (!isOK) + return Standard_False; + + const TopoDS_Face& aFace = ((BRepAdaptor_Surface*)&(theSurface->Surface()))->Face(); + TopAbs_Orientation aOri = aFace.Orientation(); + if (aOri == TopAbs_REVERSED) + theNormal.Reverse(); + + return Standard_True; } -void BRepMesh_GeomTool::Value(const BRepAdaptor_Curve& C, - const Handle(BRepAdaptor_HSurface)& S, - const Standard_Integer Index, - Standard_Real& W, gp_Pnt& P, gp_Pnt2d& UV) const +//============================================================================= +//function : IntLinLin +//purpose : +//============================================================================= +BRepMesh_GeomTool::IntFlag BRepMesh_GeomTool::IntLinLin( + const gp_XY& theStartPnt1, + const gp_XY& theEndPnt1, + const gp_XY& theStartPnt2, + const gp_XY& theEndPnt2, + gp_XY& theIntPnt, + Standard_Real (&theParamOnSegment)[2]) { - P = pnts.Value(Index); - W = pnts.Parameter(Index); - BRepMesh_ShapeTool::Parameters(C.Edge(), ((BRepAdaptor_Surface*)&(S->Surface()))->Face(), W, UV); + gp_XY aVec1 = theEndPnt1 - theStartPnt1; + gp_XY aVec2 = theEndPnt2 - theStartPnt2; + gp_XY aVecO1O2 = theStartPnt2 - theStartPnt1; + + Standard_Real aCrossD1D2 = aVec1 ^ aVec2; + Standard_Real aCrossD1D3 = aVecO1O2 ^ aVec2; + + const Standard_Real aPrec = gp::Resolution(); + // Are edgegs codirectional + if ( Abs( aCrossD1D2 ) < aPrec ) + { + // Just a parallel case? + if( Abs( aCrossD1D3 ) < aPrec ) + return BRepMesh_GeomTool::Same; + else + return BRepMesh_GeomTool::NoIntersection; + } + + theParamOnSegment[0] = aCrossD1D3 / aCrossD1D2; + theIntPnt = theStartPnt1 + theParamOnSegment[0] * aVec1; + + Standard_Real aCrossD2D3 = aVecO1O2 ^ aVec1; + theParamOnSegment[1] = aCrossD2D3 / aCrossD1D2; + + return BRepMesh_GeomTool::Cross; } -void BRepMesh_GeomTool::D0(const Handle(BRepAdaptor_HSurface)& S,const Standard_Real U, - const Standard_Real V,gp_Pnt& P) +//============================================================================= +//function : IntSegSeg +//purpose : +//============================================================================= +BRepMesh_GeomTool::IntFlag BRepMesh_GeomTool::IntSegSeg( + const gp_XY& theStartPnt1, + const gp_XY& theEndPnt1, + const gp_XY& theStartPnt2, + const gp_XY& theEndPnt2, + const Standard_Boolean isConsiderEndPointTouch, + const Standard_Boolean isConsiderPointOnSegment, + gp_Pnt2d& theIntPnt) { - S->D0(U,V,P); -} + Standard_Integer aPointHash[] = { + classifyPoint(theStartPnt1, theEndPnt1, theStartPnt2), + classifyPoint(theStartPnt1, theEndPnt1, theEndPnt2 ), + classifyPoint(theStartPnt2, theEndPnt2, theStartPnt1), + classifyPoint(theStartPnt2, theEndPnt2, theEndPnt1 ) + }; -Standard_Boolean BRepMesh_GeomTool::Normal(const Handle(BRepAdaptor_HSurface)& S, - const Standard_Real U, - const Standard_Real V, - gp_Pnt& P, - gp_Dir& Nor) -{ - Standard_Boolean OK = Standard_True; - gp_Vec D1U,D1V; - CSLib_DerivativeStatus Status; - S->D1(U,V,P,D1U,D1V); - CSLib::Normal(D1U,D1V,Standard_Real(Precision::Angular()),Status,Nor); - if (Status!= CSLib_Done) { - gp_Vec D2U,D2V,D2UV; - S->D2(U,V,P,D1U,D1V,D2U,D2V,D2UV); - CSLib_NormalStatus NStat; - CSLib::Normal(D1U,D1V,D2U,D2V,D2UV,Precision::Angular(),OK,NStat,Nor); + // Consider case when edges have shared vertex + if ( isConsiderEndPointTouch ) + { + if ( aPointHash[0] < 0 || aPointHash[1] < 0 ) + return BRepMesh_GeomTool::EndPointTouch; } - if (OK) { - if (BRepMesh_ShapeTool::Orientation(((BRepAdaptor_Surface*)&(S->Surface()))->Face()) == TopAbs_REVERSED) Nor.Reverse(); + + Standard_Integer aPosHash = + aPointHash[0] + aPointHash[1] + aPointHash[2] + aPointHash[3]; + + /*=========================================*/ + /* 1) hash code == 1: + + 0+ + / + 0 1/ 0 + +======+==========+ + + 2) hash code == 2: + + 0 1 1 0 + a) +----+========+---+ + + 0 1 1 0 + b) +-------+===+=====+ + + */ + /*=========================================*/ + if ( aPosHash == 1 ) + { + if (isConsiderPointOnSegment) + { + if (aPointHash[0] == 1) + theIntPnt = theStartPnt1; + else if (aPointHash[1] == 1) + theIntPnt = theEndPnt1; + else if (aPointHash[2] == 1) + theIntPnt = theStartPnt2; + else + theIntPnt = theEndPnt2; + + return BRepMesh_GeomTool::PointOnSegment; + } + + return BRepMesh_GeomTool::NoIntersection; } - return OK; + else if ( aPosHash == 2 ) + return BRepMesh_GeomTool::Glued; + + Standard_Real aParam[2]; + IntFlag aIntFlag = IntLinLin(theStartPnt1, theEndPnt1, + theStartPnt2, theEndPnt2, theIntPnt.ChangeCoord(), aParam); + + if (aIntFlag == BRepMesh_GeomTool::NoIntersection) + return BRepMesh_GeomTool::NoIntersection; + + if (aIntFlag == BRepMesh_GeomTool::Same) + { + if ( aPosHash < -2 ) + return BRepMesh_GeomTool::Same; + else if ( aPosHash == -1 ) + return BRepMesh_GeomTool::Glued; + + return BRepMesh_GeomTool::NoIntersection; + } + + // Cross + // Intersection is out of segments ranges + const Standard_Real aPrec = Precision::PConfusion(); + const Standard_Real aEndPrec = 1 - aPrec; + for (Standard_Integer i = 0; i < 2; ++i) + { + if( aParam[i] < aPrec || aParam[i] > aEndPrec ) + return BRepMesh_GeomTool::NoIntersection; + } + + return BRepMesh_GeomTool::Cross; +} + +//============================================================================= +//function : classifyPoint +//purpose : +//============================================================================= +Standard_Integer BRepMesh_GeomTool::classifyPoint( + const gp_XY& thePoint1, + const gp_XY& thePoint2, + const gp_XY& thePointToCheck) +{ + gp_XY aP1 = thePoint2 - thePoint1; + gp_XY aP2 = thePointToCheck - thePoint1; + + const Standard_Real aPrec = Precision::PConfusion(); + const Standard_Real aSqPrec = aPrec * aPrec; + Standard_Real aDist = Abs(aP1 ^ aP2); + if (aDist > aPrec) + { + aDist = (aDist * aDist) / aP1.SquareModulus(); + if (aDist > aSqPrec) + return 0; //out + } + + gp_XY aMult = aP1.Multiplied(aP2); + if ( aMult.X() < 0.0 || aMult.Y() < 0.0 ) + return 0; //out + + if (aP1.SquareModulus() < aP2.SquareModulus()) + return 0; //out + + if (thePointToCheck.IsEqual(thePoint1, aPrec) || + thePointToCheck.IsEqual(thePoint2, aPrec)) + { + return -1; //coinsides with an end point + } + + return 1; } diff --git a/src/BRepMesh/BRepMesh_GeomTool.hxx b/src/BRepMesh/BRepMesh_GeomTool.hxx new file mode 100644 index 0000000000..ba4e673721 --- /dev/null +++ b/src/BRepMesh/BRepMesh_GeomTool.hxx @@ -0,0 +1,203 @@ +// Copyright (c) 2013 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 _BRepMesh_GeomTool_HeaderFile +#define _BRepMesh_GeomTool_HeaderFile + +#include +#include +#include +#include +#include +#include +#include + +class BRepAdaptor_Curve; +class BRepAdaptor_HSurface; +class gp_Pnt; +class gp_Pnt2d; +class gp_Dir; + +//! Tool class intended to obtain parameters based on shape geometry. +class BRepMesh_GeomTool +{ +public: + + //! Enumerates states of segments intersection check. + enum IntFlag + { + NoIntersection, + Cross, + EndPointTouch, + PointOnSegment, + Glued, + Same + }; + +public: + + DEFINE_STANDARD_ALLOC + + //! Constructor. + //! Initiates discretization of the given geometric curve. + //! \param theCurve curve to be discretized. + //! \param theFirstParam first parameter of the curve. + //! \param theLastParam last parameter of the curve. + //! \param theLinDeflection linear deflection. + //! \param theAngDeflection angular deflection. + //! \param theMinPointsNb minimum nuber of points to be produced. + Standard_EXPORT BRepMesh_GeomTool(const BRepAdaptor_Curve& theCurve, + const Standard_Real theFirstParam, + const Standard_Real theLastParam, + const Standard_Real theLinDeflection, + const Standard_Real theAngDeflection, + const Standard_Integer theMinPointsNb = 2); + + //! Constructor. + //! Initiates discretization of geometric curve corresponding + //! to iso curve of the given surface. + //! \param theSurface surface the iso curve to be taken from. + //! \param theIsoType type of iso curve to be used, U or V. + //! \param theParamIso parameter on the surface specifying the iso curve. + //! \param theFirstParam first parameter of the curve. + //! \param theLastParam last parameter of the curve. + //! \param theLinDeflection linear deflection. + //! \param theAngDeflection angular deflection. + //! \param theMinPointsNb minimum nuber of points to be produced. + Standard_EXPORT BRepMesh_GeomTool(const Handle(BRepAdaptor_HSurface)& theSurface, + const GeomAbs_IsoType theIsoType, + const Standard_Real theParamIso, + const Standard_Real theFirstParam, + const Standard_Real theLastParam, + const Standard_Real theLinDeflection, + const Standard_Real theAngDeflection, + const Standard_Integer theMinPointsNb = 2); + + //! Adds point to already calculated points (or replaces existing). + //! \param thePoint point to be added. + //! \param theParam parameter on the curve corresponding to the given point. + //! \param theIsReplace if TRUE replaces existing point lying within + //! parameteric tolerance of the given point. + //! \return index of new added point or found with parametric tolerance + inline Standard_Integer AddPoint(const gp_Pnt& thePoint, + const Standard_Real theParam, + const Standard_Boolean theIsReplace = Standard_True) + { + return myDiscretTool.AddPoint(thePoint, theParam, theIsReplace); + } + + //! Returns number of discretization points. + inline Standard_Integer NbPoints() const + { + return myDiscretTool.NbPoints(); + } + + //! Gets parameters of discretization point with the given index. + //! \param theIndex index of discretization point. + //! \param theIsoParam parameter on surface to be used as second coordinate + //! of resulting 2d point. + //! \param theParam[out] parameter of the point on the iso curve. + //! \param thePoint[out] discretization point. + //! \param theUV[out] discretization point in parametric space of the surface. + //! \return TRUE on success, FALSE elsewhere. + Standard_EXPORT Standard_Boolean Value(const Standard_Integer theIndex, + const Standard_Real theIsoParam, + Standard_Real& theParam, + gp_Pnt& thePoint, + gp_Pnt2d& theUV) const; + + //! Gets parameters of discretization point with the given index. + //! \param theIndex index of discretization point. + //! \param theSurface surface the curve is lying onto. + //! \param theParam[out] parameter of the point on the curve. + //! \param thePoint[out] discretization point. + //! \param theUV[out] discretization point in parametric space of the surface. + //! \return TRUE on success, FALSE elsewhere. + Standard_EXPORT Standard_Boolean Value(const Standard_Integer theIndex, + const Handle(BRepAdaptor_HSurface)& theSurface, + Standard_Real& theParam, + gp_Pnt& thePoint, + gp_Pnt2d& theUV) const; + +public: //! \name static API + + //! \param theSurface surface the nomal should be found for. + //! \param theParamU U parameter in parametric space of the surface. + //! \param theParamV V parameter in parametric space of the surface. + //! \param[out] thePoint 3d point corresponding to the given parameters. + //! \param[out] theNormal normal vector at the point specified by the parameters. + //! \return FALSE if the normal can not be computed, TRUE elsewhere. + static Standard_Boolean Normal(const Handle(BRepAdaptor_HSurface)& theSurface, + const Standard_Real theParamU, + const Standard_Real theParamV, + gp_Pnt& thePoint, + gp_Dir& theNormal); + + //! Checks intersection between two lines defined by two points. + //! \param theStartPnt1 start point of first line. + //! \param theEndPnt1 end point of first line. + //! \param theStartPnt2 start point of second line. + //! \param theEndPnt2 end point of second line. + //! \param[out] theIntPnt point of intersection. + //! \param[out] theParamOnSegment parameters of intersection point + //! corresponding to first and second segment. + //! \return status of intersection check. + static IntFlag IntLinLin(const gp_XY& theStartPnt1, + const gp_XY& theEndPnt1, + const gp_XY& theStartPnt2, + const gp_XY& theEndPnt2, + gp_XY& theIntPnt, + Standard_Real (&theParamOnSegment)[2]); + + //! Checks intersection between the two segments. + //! Checks that intersection point lies within ranges of both segments. + //! \param theStartPnt1 start point of first segment. + //! \param theEndPnt1 end point of first segment. + //! \param theStartPnt2 start point of second segment. + //! \param theEndPnt2 end point of second segment. + //! \param isConsiderEndPointTouch if TRUE EndPointTouch status will be + //! returned in case if segments are touching by end points, if FALSE + //! returns NoIntersection flag. + //! \param isConsiderPointOnSegment if TRUE PointOnSegment status will be + //! returned in case if end point of one segment lies onto another one, + //! if FALSE returns NoIntersection flag. + //! \param[out] theIntPnt point of intersection. + //! \return status of intersection check. + static IntFlag IntSegSeg(const gp_XY& theStartPnt1, + const gp_XY& theEndPnt1, + const gp_XY& theStartPnt2, + const gp_XY& theEndPnt2, + const Standard_Boolean isConsiderEndPointTouch, + const Standard_Boolean isConsiderPointOnSegment, + gp_Pnt2d& theIntPnt); + +private: + + //! Classifies the point in case of coincidence of two vectors. + //! \param thePoint1 the start point of a segment (base point). + //! \param thePoint2 the end point of a segment. + //! \param thePointToCheck the point to classify. + //! \return zero value if point is out of segment and non zero value + //! if point is between the first and the second point of segment. + static Standard_Integer classifyPoint (const gp_XY& thePoint1, + const gp_XY& thePoint2, + const gp_XY& thePointToCheck); + +private: + + const TopoDS_Edge* myEdge; + GCPnts_TangentialDeflection myDiscretTool; + GeomAbs_IsoType myIsoType; +}; + +#endif diff --git a/src/BRepMesh/BRepMesh_IncrementalMesh.cxx b/src/BRepMesh/BRepMesh_IncrementalMesh.cxx index b08023c05e..51b68fb989 100644 --- a/src/BRepMesh/BRepMesh_IncrementalMesh.cxx +++ b/src/BRepMesh/BRepMesh_IncrementalMesh.cxx @@ -16,11 +16,12 @@ #include -#include +#include +#include + +#include +#include #include -#include -#include -#include #include #include @@ -30,25 +31,26 @@ #include #include #include -#include -#include + +#include +#include +#include + +#include +#include +#include +#include +#include #include #include -#include + #include #include #include #include -#include -#include -#include -#include #include -#include -#include -#include -#include -#include + +#include #ifdef HAVE_TBB // paralleling using Intel TBB @@ -65,6 +67,79 @@ namespace IMPLEMENT_STANDARD_HANDLE (BRepMesh_IncrementalMesh, BRepMesh_DiscretRoot) IMPLEMENT_STANDARD_RTTIEXT(BRepMesh_IncrementalMesh, BRepMesh_DiscretRoot) +//======================================================================= +//function : Default constructor +//purpose : +//======================================================================= +BRepMesh_IncrementalMesh::BRepMesh_IncrementalMesh() +: myRelative (Standard_False), + myInParallel (Standard_False) +{ +} + +//======================================================================= +//function : Constructor +//purpose : +//======================================================================= +BRepMesh_IncrementalMesh::BRepMesh_IncrementalMesh( + const TopoDS_Shape& theShape, + const Standard_Real theDeflection, + const Standard_Real theAngle, + const Standard_Boolean theRelative, + const Standard_Boolean theInParallel) +: myRelative (theRelative), + myInParallel(theInParallel) +{ + myDeflection = theDeflection; + myAngle = theAngle; + myShape = theShape; + + Perform(); +} + +//======================================================================= +//function : Destructor +//purpose : +//======================================================================= +BRepMesh_IncrementalMesh::~BRepMesh_IncrementalMesh() +{ +} + +//======================================================================= +//function : init +//purpose : +//======================================================================= +void BRepMesh_IncrementalMesh::init() +{ + myStatus = 0; + myModified = Standard_False; + + myEdgeDeflection.Clear(); + mySharedFaces.Clear(); + myFaces.clear(); + + setDone(); + + if (!isCorrectPolyData()) + BRepTools::Clean(myShape); + + Bnd_Box aBox; + BRepBndLib::Add(myShape, aBox, Standard_False); + + if (aBox.IsVoid()) + { + // Nothing to mesh. + myMesher.Nullify(); + return; + } + + BRepMesh_ShapeTool::BoxMaxDimension(aBox, myMaxShapeSize); + TopExp::MapShapesAndAncestors(myShape, TopAbs_EDGE, TopAbs_FACE, mySharedFaces); + + myMesher = new BRepMesh_FastDiscret(myDeflection, myAngle, aBox, + Standard_True, Standard_True, myRelative, Standard_True, myInParallel); +} + //======================================================================= //function : isCorrectPolyData //purpose : @@ -74,167 +149,26 @@ Standard_Boolean BRepMesh_IncrementalMesh::isCorrectPolyData() collectFaces(); BRepMesh_FaceChecker aFaceChecker(myInParallel); + +#ifdef HAVE_TBB if (myInParallel) { - #ifdef HAVE_TBB // check faces in parallel threads using TBB tbb::parallel_for_each(myFaces.begin(), myFaces.end(), aFaceChecker); - #else - // alternative parallelization not yet available - for (std::vector::iterator it(myFaces.begin()); it != myFaces.end(); it++) - aFaceChecker(*it); - #endif } else { - for (std::vector::iterator it(myFaces.begin()); it != myFaces.end(); it++) - aFaceChecker(*it); +#endif + std::vector::iterator aFaceIt = myFaces.begin(); + for (; aFaceIt != myFaces.end(); aFaceIt++) + aFaceChecker(*aFaceIt); +#ifdef HAVE_TBB } +#endif return aFaceChecker.IsValid(); } -//======================================================================= -//function : BRepMesh_IncrementalMesh -//purpose : -//======================================================================= -BRepMesh_IncrementalMesh::BRepMesh_IncrementalMesh() -: myRelative (Standard_False), - myInParallel (Standard_False) -{ - Init(); -} - -//======================================================================= -//function : BRepMesh_IncrementalMesh -//purpose : -//======================================================================= -BRepMesh_IncrementalMesh::BRepMesh_IncrementalMesh (const TopoDS_Shape& theShape, - const Standard_Real theDeflection, - const Standard_Boolean theRelative, - const Standard_Real theAngle, - const Standard_Boolean theInParallel) -: myRelative (theRelative), - myInParallel (theInParallel) -{ - Init(); - myDeflection = theDeflection; - myAngle = theAngle; - myShape = theShape; - - // - Perform(); -} - -//======================================================================= -//function : ~ -//purpose : -//======================================================================= -BRepMesh_IncrementalMesh::~BRepMesh_IncrementalMesh() -{ -} - -//======================================================================= -//function : SetParallel -//purpose : -//======================================================================= -void BRepMesh_IncrementalMesh::SetParallel (const Standard_Boolean theInParallel) -{ - myInParallel = theInParallel; -} - -//======================================================================= -//function : IsParallel -//purpose : -//======================================================================= -Standard_Boolean BRepMesh_IncrementalMesh::IsParallel() const -{ - return myInParallel; -} - -//======================================================================= -//function : Init -//purpose : -//======================================================================= -void BRepMesh_IncrementalMesh::Init() -{ - myStatus = 0; - myModified = Standard_False; - mymapedge.Clear(); - myancestors.Clear(); - myFaces.clear(); -} - -//======================================================================= -//function : SetRelative -//purpose : -//======================================================================= -void BRepMesh_IncrementalMesh::SetRelative(const Standard_Boolean theFlag) -{ - myRelative = theFlag; -} - -//======================================================================= -//function : Relative -//purpose : -//======================================================================= -Standard_Boolean BRepMesh_IncrementalMesh::Relative()const -{ - return myRelative; -} - -//======================================================================= -//function : IsModified -//purpose : -//======================================================================= -Standard_Boolean BRepMesh_IncrementalMesh::IsModified() const -{ - return myModified; -} - -//======================================================================= -//function : Perform -//purpose : -//======================================================================= -void BRepMesh_IncrementalMesh::Perform() -{ - Init(); - - if (!isCorrectPolyData()) - BRepTools::Clean(myShape); - - Bnd_Box aBox; - // - SetDone(); - // - BRepBndLib::Add(myShape, aBox); - myBox = aBox; - // - if (!myMesh.IsNull()) { - myMesh.Nullify(); - } - // - myMesh = new BRepMesh_FastDiscret(myDeflection, - myAngle, - aBox, - Standard_True, - Standard_True, - myRelative, - Standard_True, - myInParallel); - // - Update(myShape); -} - -//======================================================================= -//function : GetStatus -//purpose : -//======================================================================= -Standard_Integer BRepMesh_IncrementalMesh::GetStatusFlags() const -{ - return myStatus; -} - //======================================================================= //function : collectFaces //purpose : @@ -267,301 +201,288 @@ void BRepMesh_IncrementalMesh::collectFaces() } //======================================================================= -//function : Update(shape) -//purpose : Builds the incremental mesh of the shape +//function : Perform +//purpose : //======================================================================= -void BRepMesh_IncrementalMesh::Update(const TopoDS_Shape& S) +void BRepMesh_IncrementalMesh::Perform() { - myModified = Standard_False; - TopExp_Explorer ex; + init(); - //AGV 080407: Since version 6.2.0 there would be exception without this check - if (myBox.IsVoid()) + if (myMesher.IsNull()) return; - TopExp::MapShapesAndAncestors(myShape, TopAbs_EDGE, TopAbs_FACE, myancestors); - - BRepMesh_FastDiscret::BoxMaxDimension(myBox, mydtotale); - - for (ex.Init(S, TopAbs_EDGE); ex.More(); ex.Next()) { - if(BRep_Tool::IsGeometric(TopoDS::Edge(ex.Current()))) { - Update(TopoDS::Edge(ex.Current())); - } + update(); +} + +//======================================================================= +//function : update() +//purpose : +//======================================================================= +void BRepMesh_IncrementalMesh::update() +{ + // Update edges data + TopExp_Explorer aExplorer(myShape, TopAbs_EDGE); + for (; aExplorer.More(); aExplorer.Next()) + { + const TopoDS_Edge& aEdge = TopoDS::Edge(aExplorer.Current()); + if(!BRep_Tool::IsGeometric(aEdge)) + continue; + + update(aEdge); } - // get list of faces + // Update faces data std::vector::iterator aFaceIt(myFaces.begin()); for (; aFaceIt != myFaces.end(); aFaceIt++) - Update(*aFaceIt); + update(*aFaceIt); + // Mesh faces +#ifdef HAVE_TBB if (myInParallel) { - #ifdef HAVE_TBB - myMesh->CreateMutexesForSubShapes(S, TopAbs_EDGE); - // mesh faces in parallel threads using TBB - tbb::parallel_for_each (myFaces.begin(), myFaces.end(), *myMesh.operator->()); - #else - // alternative parallelization not yet available - for (std::vector::iterator it(myFaces.begin()); it != myFaces.end(); it++) - myMesh->Process (*it); - #endif - myMesh->RemoveAllMutexes(); + myMesher->CreateMutexesForSubShapes(myShape, TopAbs_EDGE); + tbb::parallel_for_each(myFaces.begin(), myFaces.end(), *myMesher); + myMesher->RemoveAllMutexes(); } else { - for (std::vector::iterator it(myFaces.begin()); it != myFaces.end(); it++) - myMesh->Process (*it); +#endif + for (aFaceIt = myFaces.begin(); aFaceIt != myFaces.end(); aFaceIt++) + myMesher->Process(*aFaceIt); +#ifdef HAVE_TBB } +#endif - // maillage des edges non contenues dans les faces : - Standard_Real f, l, defedge; - Standard_Integer i, nbNodes; - TopLoc_Location L; - Standard_Real cdef = 1.; - ex.Init(S ,TopAbs_EDGE, TopAbs_FACE); + discretizeFreeEdges(); +} - while (ex.More()) { - const TopoDS_Edge& E = TopoDS::Edge(ex.Current()); - - if(!BRep_Tool::IsGeometric(E)) { - ex.Next(); +//======================================================================= +//function : discretizeFreeEdges +//purpose : +//======================================================================= +void BRepMesh_IncrementalMesh::discretizeFreeEdges() +{ + TopExp_Explorer aExplorer(myShape ,TopAbs_EDGE, TopAbs_FACE); + for (; aExplorer.More(); aExplorer.Next()) + { + const TopoDS_Edge& aEdge = TopoDS::Edge(aExplorer.Current()); + if(!BRep_Tool::IsGeometric(aEdge)) continue; - } - - if (myRelative) - defedge = BRepMesh_FastDiscret::RelativeEdgeDeflection(E, myDeflection, - mydtotale, cdef); - else - defedge = myDeflection; - Handle(Poly_Polygon3D) P3D = BRep_Tool::Polygon3D(E, L); - Standard_Boolean maill = Standard_False; - if (P3D.IsNull()) { - maill = Standard_True; - } - else if (P3D->Deflection() > 1.1*defedge) { - maill = Standard_True; - } - if (maill) { - BRepAdaptor_Curve C(E); - f = C.FirstParameter(); - l = C.LastParameter(); - - GCPnts_TangentialDeflection TD(C, f, l, myAngle, defedge, 2); - nbNodes = TD.NbPoints(); - - TColgp_Array1OfPnt Nodes(1, nbNodes); - TColStd_Array1OfReal UVNodes(1, nbNodes); - for ( i = 1; i <= nbNodes; i++) { - Nodes(i) = TD.Value(i); - UVNodes(i) = TD.Parameter(i); - } - - BRep_Builder B; - Handle(Poly_Polygon3D) P = new Poly_Polygon3D(Nodes, UVNodes); - P->Deflection(myDeflection); - B.UpdateEdge(E, P); - } + TopLoc_Location aLoc; + Standard_Real aEdgeDeflection = edgeDeflection(aEdge); + Handle(Poly_Polygon3D) aPoly3D = BRep_Tool::Polygon3D(aEdge, aLoc); + if (!aPoly3D.IsNull() && aPoly3D->Deflection() < 1.1 * aEdgeDeflection) + continue; - ex.Next(); + BRepAdaptor_Curve aCurve(aEdge); + GCPnts_TangentialDeflection aDiscret(aCurve, aCurve.FirstParameter(), + aCurve.LastParameter(), myAngle, aEdgeDeflection, 2); + + Standard_Integer aNodesNb = aDiscret.NbPoints(); + TColgp_Array1OfPnt aNodes (1, aNodesNb); + TColStd_Array1OfReal aUVNodes(1, aNodesNb); + for (Standard_Integer i = 1; i <= aNodesNb; ++i) + { + aNodes (i) = aDiscret.Value(i); + aUVNodes(i) = aDiscret.Parameter(i); + } + + aPoly3D = new Poly_Polygon3D(aNodes, aUVNodes); + aPoly3D->Deflection(myDeflection); + + BRep_Builder aBuilder; + aBuilder.UpdateEdge(aEdge, aPoly3D); } } //======================================================================= -//function : Update(edge) -//purpose : Locate a correct discretisation if it exists -// Set no one otherwise +//function : edgeDeflection +//purpose : //======================================================================= -void BRepMesh_IncrementalMesh::Update(const TopoDS_Edge& E) +Standard_Real BRepMesh_IncrementalMesh::edgeDeflection( + const TopoDS_Edge& theEdge) { - TopLoc_Location l; - Standard_Integer i = 1; - Handle(Poly_Triangulation) T, TNull; - Handle(Poly_PolygonOnTriangulation) Poly, NullPoly; - Standard_Boolean found = Standard_False; - Standard_Real defedge = Precision::Confusion(); - Standard_Real cdef = 1.; - BRep_Builder B; - Standard_Boolean defined = Standard_False; - - do { - BRep_Tool::PolygonOnTriangulation(E, Poly, T, l, i); - i++; - if (!T.IsNull() && !Poly.IsNull()) - { - if (!defined) - { - if (myRelative) - defedge = BRepMesh_FastDiscret::RelativeEdgeDeflection(E, myDeflection, - mydtotale, cdef); - else - defedge = myDeflection; + if (myEdgeDeflection.IsBound(theEdge)) + return myEdgeDeflection(theEdge); - mymapedge.Bind(E, defedge); - defined = Standard_True; - } - if (Poly->Deflection() <= 1.1 * defedge) - { - found = Standard_True; - } - else - { - myModified = Standard_True; - B.UpdateEdge(E, NullPoly, T, l); - } - } - } while (!Poly.IsNull()); - - if (!found) myMap.Add(E); -} - - -//======================================================================= -//function : Update(face) -//purpose : If the face is not correctly triangulated, or if one of its -// edges is to be discretisated correctly, the triangulation -// of this face is built. -//======================================================================= -void BRepMesh_IncrementalMesh::Update(const TopoDS_Face& F) -{ - TopLoc_Location l; - Handle(Geom_Surface) SS = BRep_Tool::Surface(F, l); - if (SS.IsNull()) return; - - //Standard_Integer i; - Standard_Boolean WillBeTriangulated = Standard_False; - Handle(Poly_Triangulation) T, TNull; - T = BRep_Tool::Triangulation(F, l); - Handle(Poly_PolygonOnTriangulation) Poly, NullPoly; - - BRep_Builder B; - TopExp_Explorer ex; - - Standard_Real defedge, defface, cdef = 1.; - Standard_Integer nbEdge = 0; - if (myRelative) { - defface = 0.; - - for (ex.Init(F, TopAbs_EDGE); ex.More(); ex.Next()) { - const TopoDS_Edge& edge = TopoDS::Edge(ex.Current()); - nbEdge++; - if (mymapedge.IsBound(edge)) { - defedge = mymapedge(edge); - } - else - defedge = BRepMesh_FastDiscret::RelativeEdgeDeflection(edge, myDeflection, mydtotale, cdef); - defface = defface + defedge; - } - if (nbEdge != 0) defface = defface / nbEdge; - else defface = myDeflection; + Standard_Real aEdgeDeflection; + if (myRelative) + { + Standard_Real aScale; + aEdgeDeflection = BRepMesh_ShapeTool::RelativeEdgeDeflection(theEdge, + myDeflection, myMaxShapeSize, aScale); } else - defface = myDeflection; + aEdgeDeflection = myDeflection; - if (!T.IsNull()) + myEdgeDeflection.Bind(theEdge, aEdgeDeflection); + return aEdgeDeflection; +} + +//======================================================================= +//function : faceDeflection +//purpose : +//======================================================================= +Standard_Real BRepMesh_IncrementalMesh::faceDeflection( + const TopoDS_Face& theFace) +{ + if (!myRelative) + return myDeflection; + + Standard_Integer aEdgesNb = 0; + Standard_Real aFaceDeflection = 0.; + + TopExp_Explorer aEdgeIt(theFace, TopAbs_EDGE); + for (; aEdgeIt.More(); aEdgeIt.Next(), ++aEdgesNb) { - if (T->Deflection() <= 1.1 * defface) - { - for (ex.Init(F, TopAbs_EDGE); ex.More(); ex.Next()) - { - const TopoDS_Shape& anEdge = ex.Current(); - Poly = BRep_Tool::PolygonOnTriangulation(TopoDS::Edge(anEdge), T, l); + const TopoDS_Edge& aEdge = TopoDS::Edge(aEdgeIt.Current()); + aFaceDeflection += edgeDeflection(aEdge); + } - if (Poly.IsNull() || myMap.Contains(anEdge)) - { - // Triangulation is built but edge hasn't representation on it. - WillBeTriangulated = Standard_True; - break; - } - } - } - else + return (aEdgesNb == 0) ? myDeflection : (aFaceDeflection / aEdgesNb); +} + +//======================================================================= +//function : update(edge) +//purpose : +//======================================================================= +void BRepMesh_IncrementalMesh::update(const TopoDS_Edge& theEdge) +{ + Standard_Integer aPolyIndex = 1; + Standard_Real aEdgeDeflection = edgeDeflection(theEdge); + Handle(Poly_PolygonOnTriangulation) aPolygon; + do + { + TopLoc_Location aLoc; + Handle(Poly_Triangulation) aTriangulation; + BRep_Tool::PolygonOnTriangulation(theEdge, aPolygon, + aTriangulation, aLoc, aPolyIndex++); + + if (!aTriangulation.IsNull() && !aPolygon.IsNull()) { - WillBeTriangulated = Standard_True; + if (aPolygon->Deflection() < 1.1 * aEdgeDeflection) + continue; + + myModified = Standard_True; + BRepMesh_ShapeTool::NullifyEdge(theEdge, aTriangulation, aLoc); + } + + if (!myEmptyEdges.IsBound(theEdge)) + myEmptyEdges.Bind(theEdge, BRepMeshCol::MapOfTriangulation()); + + myEmptyEdges(theEdge).Add(aTriangulation); + } + while (!aPolygon.IsNull()); +} + +//======================================================================= +//function : isToBeMeshed +//purpose : +//======================================================================= +Standard_Boolean BRepMesh_IncrementalMesh::toBeMeshed( + const TopoDS_Face& theFace, + const Standard_Boolean isWithCheck) +{ + TopLoc_Location aLoc; + Handle(Poly_Triangulation) aTriangulation = + BRep_Tool::Triangulation(theFace, aLoc); + + if (aTriangulation.IsNull()) + return Standard_True; + + if (isWithCheck) + { + Standard_Real aFaceDeflection = faceDeflection(theFace); + if (aTriangulation->Deflection() < 1.1 * aFaceDeflection) + { + Standard_Boolean isEdgesConsistent = Standard_True; + TopExp_Explorer aEdgeIt(theFace, TopAbs_EDGE); + for (; aEdgeIt.More() && isEdgesConsistent; aEdgeIt.Next()) + { + const TopoDS_Edge& aEdge = TopoDS::Edge(aEdgeIt.Current()); + if (!myEmptyEdges.IsBound(aEdge)) + continue; + + isEdgesConsistent &= myEmptyEdges(aEdge).Contains(aTriangulation); + } + + if (isEdgesConsistent) + return Standard_False; } } - if (WillBeTriangulated || T.IsNull()) { - myModified = Standard_True; - if (!T.IsNull()) { - for (ex.Init(F, TopAbs_EDGE); ex.More(); ex.Next()) { - B.UpdateEdge(TopoDS::Edge(ex.Current()), NullPoly, T, l); - myMap.Remove(ex.Current()); - } - B.UpdateFace(F, TNull); - } - myMesh->Add(F, myancestors); - myStatus |= (Standard_Integer)(myMesh->CurrentFaceStatus()); - if (myMesh->CurrentFaceStatus() == BRepMesh_ReMesh) { -#ifdef DEB_MESH - cout << " face remaillee + finement que prevu."<< endl; -#endif + // Nullify edges + TopExp_Explorer aEdgeIt(theFace, TopAbs_EDGE); + for (; aEdgeIt.More(); aEdgeIt.Next()) + { + const TopoDS_Edge& aEdge = TopoDS::Edge(aEdgeIt.Current()); + BRepMesh_ShapeTool::NullifyEdge(aEdge, aTriangulation, aLoc); + } - Standard_Integer index; - - TopTools_MapOfShape MShape; - MShape.Add(F); + BRepMesh_ShapeTool::NullifyFace(theFace); + return Standard_True; +} - TopoDS_Iterator ex(F),ex2; - for (; ex.More(); ex.Next()) { - const TopoDS_Shape& aWire = ex.Value(); - if (aWire.ShapeType() != TopAbs_WIRE) - continue; - TopoDS_Iterator exW(aWire); - for(; exW.More(); exW.Next()) { - const TopoDS_Edge& edge = TopoDS::Edge(exW.Value()); - index = myancestors.FindIndex(edge); - if (index != 0) { - const TopTools_ListOfShape& L = myancestors.FindFromKey(edge); +//======================================================================= +//function : update(face) +//purpose : +//======================================================================= +void BRepMesh_IncrementalMesh::update(const TopoDS_Face& theFace) +{ + if (!toBeMeshed(theFace, Standard_True)) + return; - TopTools_ListIteratorOfListOfShape it(L); + myModified = Standard_True; + myMesher->Add(theFace, mySharedFaces); - for (; it.More(); it.Next()) { - TopoDS_Face F2 = TopoDS::Face(it.Value()); - if (!MShape.Contains(F2)) { - MShape.Add(F2); - T = BRep_Tool::Triangulation(F2, l); - if (!T.IsNull()) { -#ifdef DEB_MESH - cout <<"triangulation a refaire" <Add(F2, myancestors); - } - } - } - } - } - } + BRepMesh_Status aStatus = myMesher->CurrentFaceStatus(); + myStatus |= (Standard_Integer)aStatus; + if (aStatus != BRepMesh_ReMesh) + return; + + BRepMeshCol::MapOfShape aUsedFaces; + aUsedFaces.Add(theFace); + + TopExp_Explorer aEdgeIt(theFace, TopAbs_EDGE); + for (; aEdgeIt.More(); aEdgeIt.Next()) + { + const TopoDS_Edge& aEdge = TopoDS::Edge(aEdgeIt.Current()); + if (mySharedFaces.FindIndex(aEdge) == 0) + continue; + + const TopTools_ListOfShape& aSharedFaces = mySharedFaces.FindFromKey(aEdge); + TopTools_ListIteratorOfListOfShape aSharedFaceIt(aSharedFaces); + for (; aSharedFaceIt.More(); aSharedFaceIt.Next()) + { + const TopoDS_Face& aFace = TopoDS::Face(aSharedFaceIt.Value()); + if (aUsedFaces.Contains(aFace)) + continue; + + aUsedFaces.Add(aFace); + toBeMeshed(aFace, Standard_False); + + myMesher->Add(aFace, mySharedFaces); + myStatus |= (Standard_Integer)myMesher->CurrentFaceStatus(); } } } - //======================================================================= //function : Discret //purpose : //======================================================================= -Standard_Integer BRepMesh_IncrementalMesh::Discret (const TopoDS_Shape& theShape, - const Standard_Real theDeflection, - const Standard_Real theAngle, - BRepMesh_PDiscretRoot& theAlgo) +Standard_Integer BRepMesh_IncrementalMesh::Discret( + const TopoDS_Shape& theShape, + const Standard_Real theDeflection, + const Standard_Real theAngle, + BRepMesh_PDiscretRoot& theAlgo) { BRepMesh_IncrementalMesh* anAlgo = new BRepMesh_IncrementalMesh(); - anAlgo->SetDeflection (theDeflection); - anAlgo->SetAngle (theAngle); - anAlgo->SetShape (theShape); - anAlgo->SetParallel (IS_IN_PARALLEL); + anAlgo->SetDeflection(theDeflection); + anAlgo->SetAngle (theAngle); + anAlgo->SetShape (theShape); + anAlgo->SetParallel (IS_IN_PARALLEL); theAlgo = anAlgo; return 0; // no error } @@ -584,7 +505,8 @@ Standard_Boolean BRepMesh_IncrementalMesh::IsParallelDefault() //function : Discret //purpose : //======================================================================= -void BRepMesh_IncrementalMesh::SetParallelDefault (const Standard_Boolean theInParallel) +void BRepMesh_IncrementalMesh::SetParallelDefault( + const Standard_Boolean theInParallel) { IS_IN_PARALLEL = theInParallel; } diff --git a/src/BRepMesh/BRepMesh_IncrementalMesh.hxx b/src/BRepMesh/BRepMesh_IncrementalMesh.hxx index 2e3212fa4a..a5933728cf 100644 --- a/src/BRepMesh/BRepMesh_IncrementalMesh.hxx +++ b/src/BRepMesh/BRepMesh_IncrementalMesh.hxx @@ -17,119 +17,186 @@ #include #include -#include +#include #include #include #include -#include #include #include +#include +#include #include -class BRepMesh_FastDiscret; +class Poly_Triangulation; class TopoDS_Shape; class TopoDS_Edge; class TopoDS_Face; -//! Builds the mesh of a shape with respect of their
-//! correctly triangulated parts
-//!
-class BRepMesh_IncrementalMesh : public BRepMesh_DiscretRoot { +//! Builds the mesh of a shape with respect of their +//! correctly triangulated parts +class BRepMesh_IncrementalMesh : public BRepMesh_DiscretRoot +{ +public: //! \name mesher API -public: - - Standard_EXPORT BRepMesh_IncrementalMesh(); + //! Default constructor + Standard_EXPORT BRepMesh_IncrementalMesh(); + //! Destructor Standard_EXPORT virtual ~BRepMesh_IncrementalMesh(); - //! If the boolean flag is TRUE, the
- //! deflection used for the polygonalisation of
- //! each edge will be * Size of Edge.
- //! the deflection used for the faces will be the maximum
- //! deflection of their edges.
- Standard_EXPORT BRepMesh_IncrementalMesh(const TopoDS_Shape& theShape, - const Standard_Real theLinDeflection, - const Standard_Boolean isRelative = Standard_False, - const Standard_Real theAngDeflection = 0.5, - const Standard_Boolean isInParallel = Standard_False); - - Standard_EXPORT void SetRelative(const Standard_Boolean theFlag); - - Standard_EXPORT Standard_Boolean Relative() const; - - Standard_EXPORT virtual void Perform(); + //! Constructor. + //! Automatically calls method Perform. + //! \param theShape shape to be meshed. + //! \param theLinDeflection linear deflection. + //! \param theAngDeflection angular deflection. + //! \paarm isRelative if TRUE deflection used for discretization of + //! each edge will be * . Deflection + //! used for the faces will be the maximum deflection of their edges. + //! \param isInParallel if TRUE shape will be meshed in parallel. + Standard_EXPORT BRepMesh_IncrementalMesh( + const TopoDS_Shape& theShape, + const Standard_Real theLinDeflection, + const Standard_Real theAngDeflection = 0.5, + const Standard_Boolean isRelative = Standard_False, + const Standard_Boolean isInParallel = Standard_False); - //! Builds the incremental mesh of the shape
- Standard_EXPORT void Update(const TopoDS_Shape& theShape); + //! Performs meshing ot the shape. + Standard_EXPORT virtual void Perform(); - Standard_EXPORT Standard_Boolean IsModified() const; +public: //! \name accessing to parameters. + + //! Enables using relative deflection. + //! \param isRelative if TRUE deflection used for discretization of + //! each edge will be * . Deflection + //! used for the faces will be the maximum deflection of their edges. + inline void SetRelative(const Standard_Boolean isRelative) + { + myRelative = isRelative; + } - Standard_EXPORT Standard_Integer GetStatusFlags() const; + //! Returns relative deflection flag. + inline Standard_Boolean IsRelative() const + { + return myRelative; + } - //! Request algorithm to launch in multiple threads to improve performance.
- Standard_EXPORT void SetParallel(const Standard_Boolean isInParallel); + //! Returns modified flag. + inline Standard_Boolean IsModified() const + { + return myModified; + } - //! Returns the multi-threading usage flag.
- Standard_EXPORT Standard_Boolean IsParallel() const; + //! Returns accumulated status flags faced during meshing. + inline Standard_Integer GetStatusFlags() const + { + return myStatus; + } - //! Plugin interface for the Mesh Factories.
+ //! Request algorithm to launch in multiple threads to improve performance. + inline void SetParallel(const Standard_Boolean isInParallel) + { + myInParallel = isInParallel; + } + + //! Returns the multi-threading usage flag. + inline Standard_Boolean IsParallel() const + { + return myInParallel; + } + +public: //! \name plugin API + + //! Plugin interface for the Mesh Factories. + //! Initializes meshing algorithm with the given parameters. + //! \param theShape shape to be meshed. + //! \param theLinDeflection linear deflection. + //! \param theAngDeflection angular deflection. + //! \param[out] theAlgo pointer to initialized algorithm. Standard_EXPORT static Standard_Integer Discret(const TopoDS_Shape& theShape, const Standard_Real theLinDeflection, const Standard_Real theAngDeflection, BRepMesh_PDiscretRoot& theAlgo); - //! Returns multi-threading usage flag set by default in
- //! Discret() static method (thus applied only to Mesh Factories).
+ //! Returns multi-threading usage flag set by default in + //! Discret() static method (thus applied only to Mesh Factories). Standard_EXPORT static Standard_Boolean IsParallelDefault(); - //! Setup multi-threading usage flag set by default in
- //! Discret() static method (thus applied only to Mesh Factories).
- Standard_EXPORT static void SetParallelDefault(const Standard_Boolean isInParallel) ; + //! Setup multi-threading usage flag set by default in + //! Discret() static method (thus applied only to Mesh Factories). + Standard_EXPORT static void SetParallelDefault(const Standard_Boolean isInParallel); DEFINE_STANDARD_RTTI(BRepMesh_IncrementalMesh) protected: - Standard_EXPORT virtual void Init(); + Standard_EXPORT virtual void init(); + +private: + + //! Checks is the shape to be meshed has correct poly data, + //! i.e. PolygonOnTriangulation of particular edge connected + //! to the same Triangulation data structure as stored inside + //! a parent face. + //! \return TRUE on success, FALSE in case of inconsistencies. + Standard_Boolean isCorrectPolyData(); + + //! Builds the incremental mesh for the shape. + void update(); + + //! Checks triangulation of the given face for consistency + //! with the chosen tolerance. If some edge of face has no + //! discrete representation triangulation will be calculated. + //! \param theFace face to be checked. + void update(const TopoDS_Face& theFace); + + //! Checks discretization of the given edge for consistency + //! with the chosen tolerance. + //! \param theEdge edge to be checked. + void update(const TopoDS_Edge& theEdge); //! Collects faces suitable for meshing. - Standard_EXPORT void collectFaces(); + void collectFaces(); + + //! Discretizes edges that have no associations with faces. + void discretizeFreeEdges(); + + //! Returns deflection of the given edge. + //! \param theEdge edge which tolerance should be taken. + Standard_Real edgeDeflection(const TopoDS_Edge& theEdge); + + //! Returns deflection of the given face. + //! If relative flag is set, calculates relative deflection of the face + //! as an average value of relative deflection regarding face's edges. + //! Returns value of deflection set by user elsewhere. + Standard_Real faceDeflection(const TopoDS_Face& theFace); + + //! Prepares the given face for meshing. + //! Nullifies triangulation of face and polygons of face's edges. + //! \param theFace face to be checked. + //! \param isWithCheck if TRUE, checks parameters of triangulation + //! existing in face. If its deflection satisfies the given value and + //! each edge of face has polygon corresponded to this triangulation, + //! method return FALSE. + //! \return TRUE in case if the given face should be meshed. + Standard_Boolean toBeMeshed(const TopoDS_Face& theFace, + const Standard_Boolean isWithCheck); protected: - Standard_Boolean myRelative; - Standard_Boolean myInParallel; - TopTools_MapOfShape myMap; - Handle_BRepMesh_FastDiscret myMesh; - Standard_Boolean myModified; - TopTools_DataMapOfShapeReal mymapedge; - TopTools_IndexedDataMapOfShapeListOfShape myancestors; - Standard_Real mydtotale; - Bnd_Box myBox; - Standard_Integer myStatus; - std::vector myFaces; - -private: - //! Checks is the shape to be meshed has correct poly data,
- //! i.e. PolygonOnTriangulation of particular edge connected
- //! to the same Triangulation data structure as stored inside
- //! a parent face.
- Standard_Boolean isCorrectPolyData(); - - //! Locate a correct discretisation if it exists
- //! Set no one otherwise
- void Update(const TopoDS_Edge& theEdge); - - //! If the face is not correctly triangulated, or if one
- //! of its edges is to be discretisated correctly, the
- //! triangulation of this face is built.
- void Update(const TopoDS_Face& theFace); + Standard_Boolean myRelative; + Standard_Boolean myInParallel; + BRepMeshCol::DMapOfEdgeListOfTriangulation myEmptyEdges; + Handle(BRepMesh_FastDiscret) myMesher; + Standard_Boolean myModified; + TopTools_DataMapOfShapeReal myEdgeDeflection; + TopTools_IndexedDataMapOfShapeListOfShape mySharedFaces; + Standard_Real myMaxShapeSize; + Standard_Integer myStatus; + std::vector myFaces; }; DEFINE_STANDARD_HANDLE(BRepMesh_IncrementalMesh,BRepMesh_DiscretRoot) -// other Inline functions and methods (like "C++: function call" methods) - #endif diff --git a/src/BRepMesh/BRepMesh_ListOfInteger.hxx b/src/BRepMesh/BRepMesh_ListOfInteger.hxx deleted file mode 100644 index 04633d2f96..0000000000 --- a/src/BRepMesh/BRepMesh_ListOfInteger.hxx +++ /dev/null @@ -1,16 +0,0 @@ -// 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. - -#include - -typedef NCollection_List BRepMesh_ListOfInteger; diff --git a/src/BRepMesh/BRepMesh_MapOfInteger.hxx b/src/BRepMesh/BRepMesh_MapOfInteger.hxx deleted file mode 100644 index 0ed6acae9e..0000000000 --- a/src/BRepMesh/BRepMesh_MapOfInteger.hxx +++ /dev/null @@ -1,23 +0,0 @@ -// 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. - -#ifndef BRepMesh_MapOfInteger_HeaderFile -#define BRepMesh_MapOfInteger_HeaderFile - -#include -#include - -typedef NCollection_Map BRepMesh_MapOfInteger; -typedef NCollection_Handle Handle(BRepMesh_MapOfInteger); - -#endif diff --git a/src/BRepMesh/BRepMesh_MapOfIntegerInteger.hxx b/src/BRepMesh/BRepMesh_MapOfIntegerInteger.hxx deleted file mode 100644 index b70bd9134f..0000000000 --- a/src/BRepMesh/BRepMesh_MapOfIntegerInteger.hxx +++ /dev/null @@ -1,22 +0,0 @@ -// Created on: 2009-01-30 -// Created by: Pavel DURANDIN (pdn) -// Copyright (c) 2009-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. - -#ifndef BRepMesh_MapOfIntegerInteger_HeaderFile -#define BRepMesh_MapOfIntegerInteger_HeaderFile - -#include -typedef NCollection_DataMap BRepMesh_MapOfIntegerInteger; - -#endif diff --git a/src/BRepMesh/BRepMesh_PairOfIndex.hxx b/src/BRepMesh/BRepMesh_PairOfIndex.hxx index d9c36253f5..db5fd58c6b 100644 --- a/src/BRepMesh/BRepMesh_PairOfIndex.hxx +++ b/src/BRepMesh/BRepMesh_PairOfIndex.hxx @@ -13,103 +13,117 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -/* -* Purpose: This class represent pair of integer indices -* It is restricted to store more than two indices in it -* This pair uses to store element indices connected to link -*/ - #ifndef BRepMesh_PairOfIndex_HeaderFile #define BRepMesh_PairOfIndex_HeaderFile #include +//! This class represents a pair of integer indices to store +//! element indices connected to link. It is restricted to +//! store more than two indices in it. class BRepMesh_PairOfIndex { public: - BRepMesh_PairOfIndex() - { myIndx1 = myIndx2 = -1; } - BRepMesh_PairOfIndex(const BRepMesh_PairOfIndex& theOther) + //! Default constructor + Standard_EXPORT BRepMesh_PairOfIndex() { - myIndx1 = theOther.myIndx1; - myIndx2 = theOther.myIndx2; + Clear(); } - //! Clear indices + //! Clears indices. void Clear() { - myIndx1 = myIndx2 = -1; + myIndex[0] = myIndex[1] = -1; } - //! append index (store first of last index of pair) - void Append(const Standard_Integer theIndx) + //! Appends index to the pair. + inline void Append(const Standard_Integer theIndex) { - if ( myIndx1 < 0 ) - myIndx1 = theIndx; + if (myIndex[0] < 0) + myIndex[0] = theIndex; else { - if ( myIndx2 >= 0 ) - Standard_OutOfRange::Raise ("BRepMesh_PairOfIndex::Append, more than two index to store"); - myIndx2 = theIndx; + if (myIndex[1] >= 0) + Standard_OutOfRange::Raise("BRepMesh_PairOfIndex::Append, more than two index to store"); + + myIndex[1] = theIndex; } } - //! prepend index (store first index) - void Prepend(const Standard_Integer theIndx) + //! Prepends index to the pair. + inline void Prepend(const Standard_Integer theIndex) { - if ( myIndx2 >= 0 ) + if (myIndex[1] >= 0) Standard_OutOfRange::Raise ("BRepMesh_PairOfIndex::Append, more than two index to store"); - myIndx2 = myIndx1; - myIndx1 = theIndx; + + myIndex[1] = myIndex[0]; + myIndex[1] = theIndex; } - //! returns is pair not initialized by index - Standard_Boolean IsEmpty() const + //! Returns is pair is empty. + inline Standard_Boolean IsEmpty() const { - return (myIndx1 < 0 /*optimisation && myIndx2 < 0*/); + // Check only first index. It is impossible to update + // second index if the first one is empty. + return (myIndex[0] < 0); } - //! returns numner of initialized indeces - Standard_Integer Extent() const + //! Returns number of initialized indeces. + inline Standard_Integer Extent() const { - return (myIndx1 < 0 ? 0 : (myIndx2 < 0 ? 1 : 2)); + return (myIndex[0] < 0 ? 0 : (myIndex[1] < 0 ? 1 : 2)); } - //! returns first index from pair - Standard_Integer FirstIndex() const + //! Returns first index of pair. + inline Standard_Integer FirstIndex() const { - return myIndx1; + return myIndex[0]; } - //! returns last index - Standard_Integer LastIndex() const + //! Returns last index of pair + inline Standard_Integer LastIndex() const { - return (myIndx2 < 0 ? myIndx1 : myIndx2); + return (myIndex[1] < 0 ? myIndex[0] : myIndex[1]); } - Standard_Integer Index(const Standard_Integer theNum) const + //! Returns index corresponding to the given position in the pair. + //! \param thePairPos position of index in the pair (1 or 2). + inline Standard_Integer Index(const Standard_Integer thePairPos) const { - return (theNum == 1 ? myIndx1 : myIndx2 /*(theNum == 2 ? myIndx2 : -1 )*/); + if (thePairPos != 1 && thePairPos != 2) + Standard_OutOfRange::Raise ("BRepMesh_PairOfIndex::Index, requested index is out of range"); + + return myIndex[thePairPos - 1]; } - void SetIndex(const Standard_Integer theNum, - const Standard_Integer theIndex) + //! Sets index corresponding to the given position in the pair. + //! \param thePairPos position of index in the pair (1 or 2). + //! \param theIndex index to be stored. + inline void SetIndex(const Standard_Integer thePairPos, + const Standard_Integer theIndex) { - theNum == 1 ? myIndx1 = theIndex : myIndx2 = theIndex; + if (thePairPos != 1 && thePairPos != 2) + Standard_OutOfRange::Raise ("BRepMesh_PairOfIndex::SetIndex, requested index is out of range"); + + myIndex[thePairPos - 1] = theIndex; } - //! remove indicated - void RemoveIndex (const Standard_Integer theNum) + //! Remove index from the given position. + //! \param thePairPos position of index in the pair (1 or 2). + inline void RemoveIndex(const Standard_Integer thePairPos) { - if ( theNum == 1 ) - myIndx1 = myIndx2; - myIndx2 = -1; + if (thePairPos != 1 && thePairPos != 2) + Standard_OutOfRange::Raise ("BRepMesh_PairOfIndex::RemoveIndex, requested index is out of range"); + + if ( thePairPos == 1 ) + myIndex[0] = myIndex[1]; + + myIndex[1] = -1; } - //! fields + private: - Standard_Integer myIndx1; - Standard_Integer myIndx2; + Standard_Integer myIndex[2]; }; #endif diff --git a/src/BRepMesh/BRepMesh_PairOfPolygon.cdl b/src/BRepMesh/BRepMesh_PairOfPolygon.cdl deleted file mode 100644 index 7bb3b0664d..0000000000 --- a/src/BRepMesh/BRepMesh_PairOfPolygon.cdl +++ /dev/null @@ -1,53 +0,0 @@ --- Created on: 2009-01-26 --- Created by: Pavel TELKOV --- Copyright (c) 2009-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. - -class PairOfPolygon from BRepMesh - - ---Purpose: - -uses - PolygonOnTriangulation from Poly - -is - Create - ---Purpose: Create empty pair with null fileds - returns PairOfPolygon from BRepMesh; - - Clear(me: out); - ---Purpose: Clear pair handles - - Prepend (me: out; thePoly: PolygonOnTriangulation from Poly); - --- Initialise first polygon on triangulation - - Append (me: out; thePoly: PolygonOnTriangulation from Poly); - --- Initialise first or last polygon on triangulation - - First(me) - ---Purpose: Returns first polygon on triangulation - ---C++: return const & - ---C++: inline - returns PolygonOnTriangulation from Poly; - - Last(me) - ---Purpose: Returns last polygon on triangulation - ---C++: return const & - ---C++: inline - returns PolygonOnTriangulation from Poly; - -fields - myFirst : PolygonOnTriangulation from Poly; - myLast : PolygonOnTriangulation from Poly; - -end PairOfPolygon; diff --git a/src/BRepMesh/BRepMesh_PairOfPolygon.cxx b/src/BRepMesh/BRepMesh_PairOfPolygon.cxx deleted file mode 100644 index 0e8ec60b03..0000000000 --- a/src/BRepMesh/BRepMesh_PairOfPolygon.cxx +++ /dev/null @@ -1,62 +0,0 @@ -// Created on: 2009-01-26 -// Created by: Pavel TELKOV -// Copyright (c) 2009-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. - -#include - -//======================================================================= -//function : Constructor -//purpose : -//======================================================================= - -BRepMesh_PairOfPolygon::BRepMesh_PairOfPolygon() -{ -} - -//======================================================================= -//function : Clear -//purpose : -//======================================================================= - -void BRepMesh_PairOfPolygon::Clear() -{ - myFirst.Nullify(); - myLast.Nullify(); -} - -//======================================================================= -//function : Prepend -//purpose : -//======================================================================= - -void BRepMesh_PairOfPolygon::Prepend - ( const Handle(Poly_PolygonOnTriangulation)& theItem ) -{ - myFirst = theItem; - if (myLast.IsNull()) - myLast = theItem; -} - -//======================================================================= -//function : Append -//purpose : -//======================================================================= - -void BRepMesh_PairOfPolygon::Append - ( const Handle(Poly_PolygonOnTriangulation)& theItem ) -{ - if (myFirst.IsNull()) - myFirst = theItem; - myLast = theItem; -} diff --git a/src/BRepMesh/BRepMesh_PairOfPolygon.hxx b/src/BRepMesh/BRepMesh_PairOfPolygon.hxx new file mode 100644 index 0000000000..65978bb63d --- /dev/null +++ b/src/BRepMesh/BRepMesh_PairOfPolygon.hxx @@ -0,0 +1,82 @@ +// Copyright (c) 2013 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 _BRepMesh_PairOfPolygon_HeaderFile +#define _BRepMesh_PairOfPolygon_HeaderFile + +#include +#include +#include +#include + +class Poly_PolygonOnTriangulation; + +class BRepMesh_PairOfPolygon +{ +public: + + DEFINE_STANDARD_ALLOC + + //! Constructor. Creates empty pair with null fileds. + Standard_EXPORT BRepMesh_PairOfPolygon() + { + } + + //! Clears pair handles. + inline void Clear() + { + myFirst.Nullify(); + myLast.Nullify(); + } + + //! Sets the first element of the pair. + //! If last element is empty, also assignes the given polygon to it. + //! \param thePolygon plygon to be set. + inline void Prepend(const Handle(Poly_PolygonOnTriangulation)& thePolygon) + { + myFirst = thePolygon; + + if (myLast.IsNull()) + myLast = thePolygon; + } + + //! Sets the last element of the pair. + //! If first element is empty, also assignes the given polygon to it. + //! \param thePolygon plygon to be set. + inline void Append(const Handle(Poly_PolygonOnTriangulation)& thePolygon) + { + if (myFirst.IsNull()) + myFirst = thePolygon; + + myLast = thePolygon; + } + + //! Returns first polygon on triangulation. + inline const Handle_Poly_PolygonOnTriangulation& First() const + { + return myFirst; + } + + //! Returns last polygon on triangulation. + inline const Handle_Poly_PolygonOnTriangulation& Last() const + { + return myLast; + } + +private: + + Handle_Poly_PolygonOnTriangulation myFirst; + Handle_Poly_PolygonOnTriangulation myLast; +}; + +#endif diff --git a/src/BRepMesh/BRepMesh_PairOfPolygon.lxx b/src/BRepMesh/BRepMesh_PairOfPolygon.lxx deleted file mode 100644 index b57900313d..0000000000 --- a/src/BRepMesh/BRepMesh_PairOfPolygon.lxx +++ /dev/null @@ -1,34 +0,0 @@ -// Created on: 2009-01-26 -// Created by: Pavel TELKOV -// Copyright (c) 2009-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 : First -//purpose : -//======================================================================= - -inline const Handle(Poly_PolygonOnTriangulation)& BRepMesh_PairOfPolygon::First() const -{ - return myFirst; -} - -//======================================================================= -//function : Last -//purpose : -//======================================================================= - -inline const Handle(Poly_PolygonOnTriangulation)& BRepMesh_PairOfPolygon::Last() const -{ - return myLast; -} diff --git a/src/BRepMesh/BRepMesh_PluginEntryType.hxx b/src/BRepMesh/BRepMesh_PluginEntryType.hxx index ad7e873d0e..2233c30ca3 100644 --- a/src/BRepMesh/BRepMesh_PluginEntryType.hxx +++ b/src/BRepMesh/BRepMesh_PluginEntryType.hxx @@ -21,8 +21,8 @@ class BRepMesh_DiscretRoot; //! Type definition for plugin exported function typedef Standard_Integer (*BRepMesh_PluginEntryType) (const TopoDS_Shape& theShape, - const Standard_Real theDeflection, - const Standard_Real theAngle, + const Standard_Real theLinDeflection, + const Standard_Real theAngDeflection, BRepMesh_DiscretRoot*& theMeshAlgoInstance); -#endif //_BRepMesh_PluginEntryType_HeaderFile +#endif diff --git a/src/BRepMesh/BRepMesh_PluginMacro.hxx b/src/BRepMesh/BRepMesh_PluginMacro.hxx index 5b7b811cf2..4da575e46b 100644 --- a/src/BRepMesh/BRepMesh_PluginMacro.hxx +++ b/src/BRepMesh/BRepMesh_PluginMacro.hxx @@ -16,20 +16,22 @@ #ifndef BRepMesh_PluginMacro_HeaderFile #define BRepMesh_PluginMacro_HeaderFile -#define DISCRETPLUGIN(name) \ -extern "C" {Standard_EXPORT Standard_Integer DISCRETALGO(const TopoDS_Shape& ,\ - const Standard_Real,\ - const Standard_Real,\ - BRepMesh_PDiscretRoot& );} \ -Standard_Integer DISCRETALGO(const TopoDS_Shape& theShape,\ - const Standard_Real theDeflection,\ - const Standard_Real theAngle,\ - BRepMesh_PDiscretRoot& theAlgo) { \ - return name::Discret(theShape,\ - theDeflection,\ - theAngle,\ - theAlgo);} \ -\ - +#define DISCRETPLUGIN(name) \ +extern "C" { \ + Standard_EXPORT Standard_Integer DISCRETALGO(const TopoDS_Shape& , \ + const Standard_Real, \ + const Standard_Real, \ + BRepMesh_PDiscretRoot& ); \ +} \ + \ +Standard_Integer DISCRETALGO(const TopoDS_Shape& theShape, \ + const Standard_Real theLinDeflection, \ + const Standard_Real theAngDeflection, \ + BRepMesh_PDiscretRoot& theAlgo) \ +{ \ + return name::Discret(theShape, theLinDeflection, \ + theAngDeflection, theAlgo); \ +} \ + \ #endif diff --git a/src/BRepMesh/BRepMesh_SelectorOfDataStructureOfDelaun.cdl b/src/BRepMesh/BRepMesh_SelectorOfDataStructureOfDelaun.cdl deleted file mode 100644 index dd109dc5d0..0000000000 --- a/src/BRepMesh/BRepMesh_SelectorOfDataStructureOfDelaun.cdl +++ /dev/null @@ -1,110 +0,0 @@ --- 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. - -class SelectorOfDataStructureOfDelaun from BRepMesh - - ---Purpose: Describes a selector and an Iterator on a - -- selector of components of a Mesh. - - uses Integer from Standard, - Box from Bnd, - MapOfInteger from BRepMesh, - DataStructureOfDelaun from BRepMesh, - Vertex from BRepMesh, - Edge from BRepMesh, - Triangle from BRepMesh - -is Create returns SelectorOfDataStructureOfDelaun from BRepMesh; - - Create (theMesh : DataStructureOfDelaun from BRepMesh) - returns SelectorOfDataStructureOfDelaun from BRepMesh; - - Initialize (me : in out; - theMesh :DataStructureOfDelaun from BRepMesh) - is static; - - - NeighboursOf(me : in out; - theNode : in Vertex from BRepMesh) - is static; - - NeighboursOfNode(me : in out; - indexNode : in Integer from Standard) - is static; - - - NeighboursOf(me : in out; - theLink : in Edge from BRepMesh) - is static; - - NeighboursOfLink(me : in out; - indexLink : in Integer from Standard) - is static; - - - NeighboursOf(me : in out; - theElem : in Triangle from BRepMesh) - is static; - - NeighboursOfElement(me : in out; - indexElem : in Integer from Standard) - ---Purpose: All Neighbours Of the Element. By - -- edge or by vertices. - is static; - - - NeighboursByEdgeOf (me : in out; - theElem : in Triangle from BRepMesh) - ---Purpose: Neighbours by edge Of the Element. - is static; - - - NeighboursOf(me : in out; - theSelector : in SelectorOfDataStructureOfDelaun from BRepMesh) - ---Purpose: Adds a level of Neighbours by edge - -- to the selector . - is static; - - - AddNeighbours(me : in out) - ---Purpose: Adds a level of Neighbours by edge - -- to the selector . - is static; - - - Nodes (me) - ---C++: return const & - returns MapOfInteger from BRepMesh is static; - - Links (me) - ---C++: return const & - returns MapOfInteger from BRepMesh is static; - - Elements (me) - ---C++: return const & - returns MapOfInteger from BRepMesh is static; - - FrontierLinks(me) - ---Purpose: Gives the list of links incices - -- frontier of the selector . - ---C++: return const & - returns MapOfInteger from BRepMesh is static; - - - fields myMesh :DataStructureOfDelaun from BRepMesh; - myNodes : MapOfInteger from BRepMesh; - myLinks : MapOfInteger from BRepMesh; - myElements : MapOfInteger from BRepMesh; - myFrontier : MapOfInteger from BRepMesh; - -end SelectorOfDataStructureOfDelaun; diff --git a/src/BRepMesh/BRepMesh_SelectorOfDataStructureOfDelaun.cxx b/src/BRepMesh/BRepMesh_SelectorOfDataStructureOfDelaun.cxx index 360b773989..ae3037e334 100644 --- a/src/BRepMesh/BRepMesh_SelectorOfDataStructureOfDelaun.cxx +++ b/src/BRepMesh/BRepMesh_SelectorOfDataStructureOfDelaun.cxx @@ -14,32 +14,43 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include +#include #include //======================================================================= -//function : BRepMesh_SelectorOfDataStructureOfDelaun +//function : Default constructor //purpose : //======================================================================= BRepMesh_SelectorOfDataStructureOfDelaun::BRepMesh_SelectorOfDataStructureOfDelaun() -: myNodes(10, new NCollection_IncAllocator), -myLinks(10, new NCollection_IncAllocator), -myElements(10, new NCollection_IncAllocator), -myFrontier(10, new NCollection_IncAllocator) - -{} - -BRepMesh_SelectorOfDataStructureOfDelaun::BRepMesh_SelectorOfDataStructureOfDelaun(const Handle(BRepMesh_DataStructureOfDelaun)& theMesh) -: myMesh(theMesh), -myNodes(10, myMesh->Allocator()), -myLinks(10, myMesh->Allocator()), -myElements(10, myMesh->Allocator()), -myFrontier(10, myMesh->Allocator()) -{} - -void BRepMesh_SelectorOfDataStructureOfDelaun::Initialize(const Handle(BRepMesh_DataStructureOfDelaun)& theMesh) +: myNodes (10, new NCollection_IncAllocator), + myLinks (10, new NCollection_IncAllocator), + myElements(10, new NCollection_IncAllocator), + myFrontier(10, new NCollection_IncAllocator) { - myMesh=theMesh; +} + +//======================================================================= +//function : Constructor +//purpose : +//======================================================================= +BRepMesh_SelectorOfDataStructureOfDelaun::BRepMesh_SelectorOfDataStructureOfDelaun( + const Handle(BRepMesh_DataStructureOfDelaun)& theMesh) +: myMesh (theMesh), + myNodes (10, myMesh->Allocator()), + myLinks (10, myMesh->Allocator()), + myElements(10, myMesh->Allocator()), + myFrontier(10, myMesh->Allocator()) +{ +} + +//======================================================================= +//function : Initialize +//purpose : +//======================================================================= +void BRepMesh_SelectorOfDataStructureOfDelaun::Initialize( + const Handle(BRepMesh_DataStructureOfDelaun)& theMesh) +{ + myMesh = theMesh; myNodes.Clear(); myLinks.Clear(); myElements.Clear(); @@ -47,121 +58,97 @@ void BRepMesh_SelectorOfDataStructureOfDelaun::Initialize(const Handle(BRepMesh } //======================================================================= -//function : NeighboursOfNode +//function : NeighboursOf(Node) //purpose : //======================================================================= -void BRepMesh_SelectorOfDataStructureOfDelaun::NeighboursOf(const BRepMesh_Vertex& theNode) +void BRepMesh_SelectorOfDataStructureOfDelaun::NeighboursOf( + const BRepMesh_Vertex& theNode) { NeighboursOfNode(myMesh->IndexOf(theNode)); } -void BRepMesh_SelectorOfDataStructureOfDelaun::NeighboursOfNode(const Standard_Integer indexNode) +//======================================================================= +//function : NeighboursOfNode(NodeIndex) +//purpose : +//======================================================================= +void BRepMesh_SelectorOfDataStructureOfDelaun::NeighboursOfNode( + const Standard_Integer theNodeIndex) { - BRepMesh_ListOfInteger::Iterator itL(myMesh->LinkNeighboursOf(indexNode)); + BRepMeshCol::ListOfInteger::Iterator aLinkIt( + myMesh->LinksConnectedTo(theNodeIndex)); - for (; itL.More(); itL.Next()) { - const BRepMesh_PairOfIndex& aPair = myMesh->ElemConnectedTo(itL.Value()); - for(Standard_Integer j = 1, jn = aPair.Extent(); j <= jn; j++) - myElements.Add(aPair.Index(j)); - } + for (; aLinkIt.More(); aLinkIt.Next()) + elementsOfLink(aLinkIt.Value()); } //======================================================================= -//function : NeighboursOfLink +//function : NeighboursOf(Link) //purpose : //======================================================================= -void BRepMesh_SelectorOfDataStructureOfDelaun::NeighboursOf(const BRepMesh_Edge& theLink) +void BRepMesh_SelectorOfDataStructureOfDelaun::NeighboursOf( + const BRepMesh_Edge& theLink) { NeighboursOfNode(theLink.FirstNode()); NeighboursOfNode(theLink.LastNode()); } -void BRepMesh_SelectorOfDataStructureOfDelaun::NeighboursOfLink(const Standard_Integer indexLink) +//======================================================================= +//function : NeighboursOfLink(LinkIndex) +//purpose : +//======================================================================= +void BRepMesh_SelectorOfDataStructureOfDelaun::NeighboursOfLink( + const Standard_Integer theLinkIndex) { - NeighboursOf(myMesh->GetLink(indexLink)); + NeighboursOf(myMesh->GetLink(theLinkIndex)); } //======================================================================= -//function : NeighboursOfElement -//purpose : by edge and by vertices +//function : NeighboursOf(Element) +//purpose : //======================================================================= -void BRepMesh_SelectorOfDataStructureOfDelaun::NeighboursOf(const BRepMesh_Triangle& theElem) +void BRepMesh_SelectorOfDataStructureOfDelaun::NeighboursOf( + const BRepMesh_Triangle& theElement) { - Standard_Integer v1, v2, v3, ev; - Standard_Boolean o1, o2, o3; - theElem.Edges(v1, v3, ev, o1, o2, o3); - v2=myMesh->GetLink(v1).LastNode(); - v1=myMesh->GetLink(v1).FirstNode(); - ev=myMesh->GetLink(v3).LastNode(); - if (v1!=ev && v2!=ev) v3=ev; - else v3=myMesh->GetLink(v3).FirstNode(); - NeighboursOfNode(v1); - NeighboursOfNode(v2); - NeighboursOfNode(v3); -} + Standard_Integer v[3]; + myMesh->ElementNodes(theElement, v); -void BRepMesh_SelectorOfDataStructureOfDelaun::NeighboursOfElement(const Standard_Integer indexElem) -{ - NeighboursOf(myMesh->GetElement(indexElem)); + for (Standard_Integer i = 0; i < 3; ++i) + NeighboursOfNode(v[i]); } //======================================================================= -//function : NeighboursByEdgeOf -//purpose : Neighbours Of an element only by edge +//function : NeighboursOfElement(ElementIndex) +//purpose : //======================================================================= -void BRepMesh_SelectorOfDataStructureOfDelaun::NeighboursByEdgeOf(const BRepMesh_Triangle& theElem) +void BRepMesh_SelectorOfDataStructureOfDelaun::NeighboursOfElement( + const Standard_Integer theElementIndex) { - Standard_Integer e[3], iEd; - Standard_Boolean o1, o2, o3; - theElem.Edges(e[0], e[1], e[2], o1, o2, o3); - - for (iEd=0; iEd<3; iEd++) { - const BRepMesh_PairOfIndex& aPair = myMesh->ElemConnectedTo(e[iEd]); - for(Standard_Integer j = 1, jn = aPair.Extent(); j <= jn; j++) - myElements.Add(aPair.Index(j)); - } + NeighboursOf(myMesh->GetElement(theElementIndex)); } - //======================================================================= -//function : NeighboursOfSelector +//function : NeighboursByEdgeOf(Element) //purpose : //======================================================================= -void BRepMesh_SelectorOfDataStructureOfDelaun::NeighboursOf(const BRepMesh_SelectorOfDataStructureOfDelaun& /*theSelector*/) -{} +void BRepMesh_SelectorOfDataStructureOfDelaun::NeighboursByEdgeOf( + const BRepMesh_Triangle& theElement) +{ + Standard_Integer e[3]; + Standard_Boolean o[3]; + theElement.Edges(e, o); + + for (Standard_Integer i = 0; i < 3; ++i) + elementsOfLink(e[i]); +} //======================================================================= -//function : AddNeighbours +//function : elementsOfLink //purpose : //======================================================================= -void BRepMesh_SelectorOfDataStructureOfDelaun::AddNeighbours() -{} - -//======================================================================= -//function : Nodes -//purpose : -//======================================================================= -const BRepMesh_MapOfInteger& BRepMesh_SelectorOfDataStructureOfDelaun::Nodes()const -{return myNodes;} - -//======================================================================= -//function : Links -//purpose : -//======================================================================= -const BRepMesh_MapOfInteger& BRepMesh_SelectorOfDataStructureOfDelaun::Links()const -{return myLinks;} - -//======================================================================= -//function : Elements -//purpose : -//======================================================================= -const BRepMesh_MapOfInteger& BRepMesh_SelectorOfDataStructureOfDelaun::Elements()const -{return myElements;} - -//======================================================================= -//function : FrontierLinks -//purpose : -//======================================================================= -const BRepMesh_MapOfInteger& BRepMesh_SelectorOfDataStructureOfDelaun::FrontierLinks()const -{return myFrontier;} - +void BRepMesh_SelectorOfDataStructureOfDelaun::elementsOfLink( + const Standard_Integer theIndex) +{ + const BRepMesh_PairOfIndex& aPair = myMesh->ElementsConnectedTo(theIndex); + for(Standard_Integer j = 1, jn = aPair.Extent(); j <= jn; ++j) + myElements.Add(aPair.Index(j)); +} diff --git a/src/BRepMesh/BRepMesh_SelectorOfDataStructureOfDelaun.hxx b/src/BRepMesh/BRepMesh_SelectorOfDataStructureOfDelaun.hxx new file mode 100644 index 0000000000..57b9021447 --- /dev/null +++ b/src/BRepMesh/BRepMesh_SelectorOfDataStructureOfDelaun.hxx @@ -0,0 +1,114 @@ +// Copyright (c) 2013 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 _BRepMesh_SelectorOfDataStructureOfDelaun_HeaderFile +#define _BRepMesh_SelectorOfDataStructureOfDelaun_HeaderFile + +#include +#include +#include +#include +#include +#include +#include + +class BRepMesh_Vertex; +class BRepMesh_Edge; + +//! Describes a selector and an iterator on a +//! selector of components of a mesh. +class BRepMesh_SelectorOfDataStructureOfDelaun +{ +public: + + DEFINE_STANDARD_ALLOC + + //! Default constructor. + Standard_EXPORT BRepMesh_SelectorOfDataStructureOfDelaun(); + + //! Constructor. + //! Initializes selector by the mesh. + Standard_EXPORT BRepMesh_SelectorOfDataStructureOfDelaun(const Handle(BRepMesh_DataStructureOfDelaun)& theMesh); + + //! Initializes selector by the mesh. + Standard_EXPORT void Initialize(const Handle(BRepMesh_DataStructureOfDelaun)& theMesh); + + //! Selects all neighboring elements of the given node. + Standard_EXPORT void NeighboursOf(const BRepMesh_Vertex& theNode); + + //! Selects all neighboring elements of node with the given index. + Standard_EXPORT void NeighboursOfNode(const Standard_Integer theNodeIndex); + + //! Selects all neighboring elements of the given link. + Standard_EXPORT void NeighboursOf(const BRepMesh_Edge& theLink); + + //! Selects all neighboring elements of link with the given index. + Standard_EXPORT void NeighboursOfLink(const Standard_Integer theLinkIndex); + + //! Selects all neighboring elements of the given element. + Standard_EXPORT void NeighboursOf(const BRepMesh_Triangle& theElement); + + //! Selects all neighboring elements by nodes of the given element. + Standard_EXPORT void NeighboursOfElement(const Standard_Integer theElementIndex); + + //! Selects all neighboring elements by links of the given element. + Standard_EXPORT void NeighboursByEdgeOf(const BRepMesh_Triangle& theElement); + + //! Adds a level of neighbours by edge to the selector. + inline void NeighboursOf(const BRepMesh_SelectorOfDataStructureOfDelaun& /*theSelector*/) + { + } + + //! Adds a level of neighbours by edge the selector. + inline void AddNeighbours() + { + } + + //! Returns selected nodes. + inline const BRepMeshCol::MapOfInteger& Nodes() const + { + return myNodes; + } + + //! Returns selected links. + inline const BRepMeshCol::MapOfInteger& Links() const + { + return myLinks; + } + + //! Returns selected elements. + inline const BRepMeshCol::MapOfInteger& Elements() const + { + return myElements; + } + + //! Gives the list of incices of frontier links. + inline const BRepMeshCol::MapOfInteger& FrontierLinks() const + { + return myFrontier; + } + +private: + + //! Collects elements connected to link with the given index. + void elementsOfLink(const Standard_Integer theIndex); + +private: + Handle(BRepMesh_DataStructureOfDelaun) myMesh; + BRepMeshCol::MapOfInteger myNodes; + BRepMeshCol::MapOfInteger myLinks; + BRepMeshCol::MapOfInteger myElements; + BRepMeshCol::MapOfInteger myFrontier; +}; + +#endif diff --git a/src/BRepMesh/BRepMesh_ShapeTool.cdl b/src/BRepMesh/BRepMesh_ShapeTool.cdl deleted file mode 100644 index 9c24c3268b..0000000000 --- a/src/BRepMesh/BRepMesh_ShapeTool.cdl +++ /dev/null @@ -1,174 +0,0 @@ --- Created on: 1993-09-30 --- Created by: Isabelle GRIGNON --- Copyright (c) 1993-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. - -class ShapeTool from BRepMesh - - ---Purpose: - -uses Shape from TopoDS, - Face from TopoDS, - Edge from TopoDS, - Vertex from TopoDS, - Explorer from TopExp, - Pnt2d from gp, - Pnt from gp, - Box from Bnd, - Curve from BRepAdaptor, - Orientation from TopAbs, - Triangulation from Poly, - HArray1OfInteger from TColStd - -raises NoSuchObject from Standard - -is - Create returns ShapeTool ; - - Init(me : in out ; S : Shape from TopoDS) - ---C++: inline - is static; - - MoreFace(me: in out ) returns Boolean from Standard - ---C++: inline - is static; - - NextFace(me : in out) - ---C++: inline - is static; - - CurrentFace( me : in out) returns Face from TopoDS - ---C++:return const & - ---C++: inline - is static; - - Init(me : in out ; F: Face from TopoDS) - ---C++: inline - is static; - - MoreEdge(me: in out ) returns Boolean from Standard - ---C++: inline - is static; - - NextEdge(me : in out) - ---C++: inline - is static; - - CurrentEdge(me : in out) - ---C++: return const & - ---C++: inline - returns Edge from TopoDS - is static; - - Init(me : in out ; E : Edge from TopoDS) - ---C++: inline - is static; - - MoreInternalVertex(me: in out ) returns Boolean from Standard - - is static; - - NextInternalVertex(me : in out) - ---C++: inline - is static; - - CurrentInternalVertex( me : in out) returns Vertex from TopoDS - ---C++: return const & - ---C++: inline - is static; - - Orientation(myclass; F :Face from TopoDS ) - ---C++: inline - returns Orientation from TopAbs; - - Orientation(myclass; E : Edge from TopoDS ) - ---C++: inline - returns Orientation from TopAbs; - - Bound(myclass; F :Face from TopoDS ) - returns Box from Bnd; - - Bound(myclass; E : Edge from TopoDS ) - returns Box from Bnd; - - FirstVertex(myclass; E : Edge from TopoDS ) - returns Vertex from TopoDS - raises NoSuchObject; - --if there is not first vertex (semi-infinite edge) - - LastVertex(myclass; E : Edge from TopoDS) - returns Vertex from TopoDS - raises NoSuchObject; - --if there is not last vertex (semi-infinite edge) - - Vertices(myclass; E : Edge from TopoDS; - Vfirst, Vlast : out Vertex from TopoDS); - ---Purpose: If there is not First or Last vertex (infinite or - -- semi-infinite edge) return null shapes. - - Range(myclass; E : Edge from TopoDS; - F : Face from TopoDS; - wFirst, wLast : in out Real from Standard); - ---C++: inline - - UVPoints(myclass; E : Edge from TopoDS; - F : Face from TopoDS; - uvFirst, uvLast : out Pnt2d from gp); - ---C++: inline - - Degenerated(myclass; E : Edge from TopoDS) - ---C++: inline - returns Boolean from Standard; - - Tolerance(myclass; V : Vertex from TopoDS) - ---C++: inline - returns Real from Standard; - - Parameter(myclass; V : Vertex from TopoDS; - E : Edge from TopoDS; - F : Face from TopoDS) returns Real from Standard; - ---C++: inline - - Parameters (myclass; - E : Edge from TopoDS; - F : Face from TopoDS; - W : Real; - UV : out Pnt2d); - - Locate (myclass; - C : Curve from BRepAdaptor; - W : in Real; WFound : in out Real; - p3d : Pnt from gp; - UV : out Pnt2d); - - Pnt(myclass; V : Vertex from TopoDS) - ---C++: inline - returns Pnt from gp; - - - AddInFace(myclass; - F : Face from TopoDS; - T : in out Triangulation from Poly); - - - - -fields - - theFIterator : Explorer from TopExp; - theEIterator : Explorer from TopExp; - theVIterator : Explorer from TopExp; - -end ShapeTool; - diff --git a/src/BRepMesh/BRepMesh_ShapeTool.cxx b/src/BRepMesh/BRepMesh_ShapeTool.cxx index a821788fd8..9a70db7662 100644 --- a/src/BRepMesh/BRepMesh_ShapeTool.cxx +++ b/src/BRepMesh/BRepMesh_ShapeTool.cxx @@ -12,135 +12,263 @@ // 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 -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include -Standard_Integer debug=0; +namespace { + //! Auxilary struct to take a tolerance of edge. + struct EdgeTolerance + { + static Standard_Real Get(const TopoDS_Shape& theEdge) + { + return BRep_Tool::Tolerance(TopoDS::Edge(theEdge)); + } + }; -BRepMesh_ShapeTool::BRepMesh_ShapeTool() {} + //! Auxilary struct to take a tolerance of vertex. + struct VertexTolerance + { + static Standard_Real Get(const TopoDS_Shape& theVertex) + { + return BRep_Tool::Tolerance(TopoDS::Vertex(theVertex)); + } + }; -Standard_Boolean BRepMesh_ShapeTool::MoreInternalVertex() -{ - while (theVIterator.More()) { - if (theVIterator.Current().Orientation() == TopAbs_INTERNAL) - return Standard_True; - theVIterator.Next(); + //! Returns maximum tolerance of face element of the specified type. + template + Standard_Real MaxTolerance(const TopoDS_Face& theFace) + { + Standard_Real aMaxTolerance = RealFirst(); + TopExp_Explorer aExplorer(theFace, ShapeType); + for (; aExplorer.More(); aExplorer.Next()) + { + Standard_Real aTolerance = ToleranceExtractor::Get(aExplorer.Current()); + if (aTolerance > aMaxTolerance) + aMaxTolerance = aTolerance; + } + + return aMaxTolerance; } - return Standard_False; } - -TopoDS_Vertex BRepMesh_ShapeTool::FirstVertex(const TopoDS_Edge& E) +//======================================================================= +//function : BoxMaxDimension +//purpose : +//======================================================================= +Standard_Real BRepMesh_ShapeTool::MaxFaceTolerance(const TopoDS_Face& theFace) { - TopExp_Explorer Ex(E,TopAbs_VERTEX); - while (Ex.More()) { - if (Ex.Current().Orientation() == TopAbs_FORWARD) - return TopoDS::Vertex(Ex.Current()); - Ex.Next(); + Standard_Real aMaxTolerance = BRep_Tool::Tolerance(theFace); + + Standard_Real aTolerance = Max( + MaxTolerance(theFace), + MaxTolerance(theFace)); + + return Max(aMaxTolerance, aTolerance); +} + +//======================================================================= +//function : BoxMaxDimension +//purpose : +//======================================================================= +void BRepMesh_ShapeTool::BoxMaxDimension(const Bnd_Box& theBox, + Standard_Real& theMaxDimension) +{ + if(theBox.IsVoid()) + return; + + Standard_Real aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ; + theBox.Get(aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ); + + theMaxDimension = Max(aMaxX - aMinX, Max(aMaxY - aMinY, aMaxZ - aMinZ)); +} + +//======================================================================= +//function : RelativeEdgeDeflection +//purpose : +//======================================================================= +Standard_Real BRepMesh_ShapeTool::RelativeEdgeDeflection( + const TopoDS_Edge& theEdge, + const Standard_Real theDeflection, + const Standard_Real theMaxShapeSize, + Standard_Real& theAdjustmentCoefficient) +{ + theAdjustmentCoefficient = 1.; + Standard_Real aDefEdge = theDeflection; + if(theEdge.IsNull()) + return aDefEdge; + + Bnd_Box aBox; + BRepBndLib::Add(theEdge, aBox); + BoxMaxDimension(aBox, aDefEdge); + + // Adjust resulting value in relation to the total size + theAdjustmentCoefficient = theMaxShapeSize / (2 * aDefEdge); + if (theAdjustmentCoefficient < 0.5) + theAdjustmentCoefficient = 0.5; + else if (theAdjustmentCoefficient > 2.) + theAdjustmentCoefficient = 2.; + + return (theAdjustmentCoefficient * aDefEdge * theDeflection); +} + +//======================================================================= +//function : FindUV +//purpose : +//======================================================================= +gp_XY BRepMesh_ShapeTool::FindUV( + const Standard_Integer theIndexOfPnt3d, + const gp_Pnt2d& thePnt2d, + const TopoDS_Vertex& theVertex, + const Standard_Real theMinDistance, + const Handle(BRepMesh_FaceAttribute)& theFaceAttribute, + const Handle(BRepAdaptor_HSurface)& theSurface, + BRepMeshCol::DMapOfIntegerListOfXY& theLocation2dMap) +{ + const gp_XY& aPnt2d = thePnt2d.Coord(); + if (!theLocation2dMap.IsBound(theIndexOfPnt3d)) + { + BRepMeshCol::ListOfXY aPoints2d; + aPoints2d.Append(aPnt2d); + theLocation2dMap.Bind(theIndexOfPnt3d, aPoints2d); + return aPnt2d; } - Standard_NoSuchObject::Raise("non existent first vertex"); - return TopoDS_Vertex(); -} -TopoDS_Vertex BRepMesh_ShapeTool::LastVertex(const TopoDS_Edge& E) -{ - TopExp_Explorer Ex(E,TopAbs_VERTEX); - while (Ex.More()) { - if (Ex.Current().Orientation() == TopAbs_REVERSED) - return TopoDS::Vertex(Ex.Current()); - Ex.Next(); - } - Standard_NoSuchObject::Raise("non existent last vertex"); - return TopoDS_Vertex(); -} + BRepMeshCol::ListOfXY& aPoints2d = + theLocation2dMap.ChangeFind(theIndexOfPnt3d); -void BRepMesh_ShapeTool::Vertices(const TopoDS_Edge& E, - TopoDS_Vertex& Vfirst, - TopoDS_Vertex& Vlast) -{ - TopExp::Vertices(E, Vfirst, Vlast); -} + // Find the most closest 2d point to the given one. + gp_XY aUV; + Standard_Real aMinDist = RealLast(); + BRepMeshCol::ListOfXY::Iterator aPoint2dIt(aPoints2d); + for (; aPoint2dIt.More(); aPoint2dIt.Next()) + { + const gp_XY& aCurPnt2d = aPoint2dIt.Value(); -Bnd_Box BRepMesh_ShapeTool::Bound(const TopoDS_Face& F) -{ - Bnd_Box Bf; - BRepBndLib::Add(F, Bf); - return Bf; -} - -Bnd_Box BRepMesh_ShapeTool::Bound(const TopoDS_Edge& E) -{ - Bnd_Box Be; - BRepBndLib::Add(E, Be); - return Be; -} - -void BRepMesh_ShapeTool::Parameters(const TopoDS_Edge& E, - const TopoDS_Face& F, - const Standard_Real W, - gp_Pnt2d& UV) -{ - Standard_Real a,b; - Handle(Geom2d_Curve) C = BRep_Tool::CurveOnSurface(E,F,a,b); - C->D0(W,UV); -} - -void BRepMesh_ShapeTool::Locate(const BRepAdaptor_Curve& C, - const Standard_Real W, - Standard_Real& wFound, - const gp_Pnt& p3d, - gp_Pnt2d& UV) -{ - gp_Pnt plocal(p3d.Transformed(C.Trsf().Inverted())); - Extrema_LocateExtPC - pcos(plocal, C.CurveOnSurface(), W, Precision::PConfusion()); - if (pcos.IsDone()) { - wFound=pcos.Point().Parameter(); - C.CurveOnSurface().GetCurve()->D0(wFound, UV); - if (debug!=0) { - if (pcos.SquareDistance()>(4.* C.Tolerance()* C.Tolerance())) { - cout << " ShapeTool :LocateExtPCOnS Done but (Distance "<< - sqrt(pcos.SquareDistance()) << ")(Tolerance "<1) { - cout << " ShapeTool : LocateExtPCOnS OK ! "<D0(W, UV); + + const Standard_Real aTolerance = + Min(2. * BRep_Tool::Tolerance(theVertex), theMinDistance); + + // Get face limits + Standard_Real aDiffU, aDiffV; + if (theFaceAttribute.IsNull()) + { + aDiffU = theSurface->LastUParameter() - theSurface->FirstUParameter(); + aDiffV = theSurface->LastVParameter() - theSurface->FirstVParameter(); } + else + { + aDiffU = theFaceAttribute->GetUMax() - theFaceAttribute->GetUMin(); + aDiffV = theFaceAttribute->GetVMax() - theFaceAttribute->GetVMin(); + } + + const Standard_Real Utol2d = .5 * aDiffU; + const Standard_Real Vtol2d = .5 * aDiffV; + + const gp_Pnt aPnt1 = theSurface->Value( aUV.X(), aUV.Y()); + const gp_Pnt aPnt2 = theSurface->Value(aPnt2d.X(), aPnt2d.Y()); + + //! If selected point is too far from the given one in parametric space + //! or their positions in 3d are different, add the given point as unique. + if (Abs(aUV.X() - aPnt2d.X()) > Utol2d || + Abs(aUV.Y() - aPnt2d.Y()) > Vtol2d || + !aPnt1.IsEqual(aPnt2, aTolerance)) + { + aUV = aPnt2d; + aPoints2d.Append(aUV); + } + + return aUV; } - -void BRepMesh_ShapeTool::AddInFace(const TopoDS_Face& F, - Handle(Poly_Triangulation)& T) +//======================================================================= +//function : AddInFace +//purpose : +//======================================================================= +void BRepMesh_ShapeTool::AddInFace( + const TopoDS_Face& theFace, + Handle(Poly_Triangulation)& theTriangulation) { - static BRep_Builder B1; - TColgp_Array1OfPnt& Nodes = T->ChangeNodes(); - gp_Trsf tr = F.Location().Transformation(); - tr.Invert(); - for (Standard_Integer i = Nodes.Lower(); i <= Nodes.Upper(); i++) - Nodes(i).Transform(tr); - B1.UpdateFace(F, T); + const TopLoc_Location& aLoc = theFace.Location(); + if (!aLoc.IsIdentity()) + { + 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); + } + + BRep_Builder aBuilder; + aBuilder.UpdateFace(theFace, theTriangulation); +} + +//======================================================================= +//function : NullifyFace +//purpose : +//======================================================================= +void BRepMesh_ShapeTool::NullifyFace(const TopoDS_Face& theFace) +{ + BRep_Builder aBuilder; + aBuilder.UpdateFace(theFace, Handle(Poly_Triangulation)()); +} + +//======================================================================= +//function : NullifyEdge +//purpose : +//======================================================================= +void BRepMesh_ShapeTool::NullifyEdge( + const TopoDS_Edge& theEdge, + const Handle(Poly_Triangulation)& theTriangulation, + const TopLoc_Location& theLocation) +{ + UpdateEdge(theEdge, Handle(Poly_PolygonOnTriangulation)(), + theTriangulation, theLocation); +} + +//======================================================================= +//function : UpdateEdge +//purpose : +//======================================================================= +void BRepMesh_ShapeTool::UpdateEdge( + const TopoDS_Edge& theEdge, + const Handle(Poly_PolygonOnTriangulation)& thePolygon, + const Handle(Poly_Triangulation)& theTriangulation, + const TopLoc_Location& theLocation) +{ + BRep_Builder aBuilder; + aBuilder.UpdateEdge(theEdge, thePolygon, theTriangulation, theLocation); +} + +//======================================================================= +//function : UpdateEdge +//purpose : +//======================================================================= +void BRepMesh_ShapeTool::UpdateEdge( + const TopoDS_Edge& theEdge, + const Handle(Poly_PolygonOnTriangulation)& thePolygon1, + const Handle(Poly_PolygonOnTriangulation)& thePolygon2, + const Handle(Poly_Triangulation)& theTriangulation, + const TopLoc_Location& theLocation) +{ + BRep_Builder aBuilder; + aBuilder.UpdateEdge(theEdge, thePolygon1, thePolygon2, + theTriangulation, theLocation); } diff --git a/src/BRepMesh/BRepMesh_ShapeTool.hxx b/src/BRepMesh/BRepMesh_ShapeTool.hxx new file mode 100644 index 0000000000..5c94663d61 --- /dev/null +++ b/src/BRepMesh/BRepMesh_ShapeTool.hxx @@ -0,0 +1,142 @@ +// Copyright (c) 2013 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 _BRepMesh_ShapeTool_HeaderFile +#define _BRepMesh_ShapeTool_HeaderFile + +#include +#include +#include +#include +#include +#include +#include + +class TopoDS_Face; +class TopoDS_Edge; +class Bnd_Box; +class TopoDS_Vertex; +class gp_XY; +class gp_Pnt2d; + +class BRepMesh_ShapeTool +{ +public: + + DEFINE_STANDARD_ALLOC + + //! Returns maximum tolerance of the given face. + //! Considers tolerances of edges and vertices contained in the given face. + Standard_EXPORT static Standard_Real MaxFaceTolerance( + const TopoDS_Face& theFace); + + //! Gets the maximum dimension of the given bounding box. + //! If the given bounding box is void leaves the resulting value unchanged. + //! \param theBox bounding box to be processed. + //! \param theMaxDimension maximum dimension of the given box. + Standard_EXPORT static void BoxMaxDimension(const Bnd_Box& theBox, + Standard_Real& theMaxDimension); + + //! Returns relative deflection for edge with respect to shape size. + //! \param theEdge edge for which relative deflection should be computed. + //! \param theDeflection absolute deflection. + //! \param theMaxShapeSize maximum size of a shape. + //! \param theAdjustmentCoefficient coefficient of adjustment between maximum + //! size of shape and calculated relative deflection. + //! \return relative deflection for the edge. + Standard_EXPORT static Standard_Real RelativeEdgeDeflection( + const TopoDS_Edge& theEdge, + const Standard_Real theDeflection, + const Standard_Real theMaxShapeSize, + Standard_Real& theAdjustmentCoefficient); + + //! Checks 2d representations of 3d point with the + //! given index for equality to avoid duplications. + //! \param theIndexOfPnt3d index of 3d point with which 2d + //! representation should be associated. + //! \param thePnt2d 2d representation of the point with the + //! given index. + //! \param theVertex vertex corresponded to 3d point with the + //! given index. Used to extract vertex tolerance in 3d space. + //! \param theMinDistance minimum distance between vertices + //! regarding which they could be treated as distinct ones. + //! This value is defined by mesher using parameters given by + //! user in connection with shape metrics. + //! \param theFaceAttribute attributes contining data calculated + //! according to face geomtry and define limits of face in parametric + //! space. If defined, will be used instead of surface parameter. + //! \param theSurface surface within which parametric space + //! the 2d point is defined. Supposed to be used in case if face + //! attributes are not defined by the moment of method invocation. + //! \param theLocation2dMap map of 2d representations of 3d points. + //! \return given 2d point in case if 3d poind does not alredy have + //! the similar representation, otherwice 2d point corresponding to + //! existing representation will be returned. + Standard_EXPORT static gp_XY FindUV( + const Standard_Integer theIndexOfPnt3d, + const gp_Pnt2d& thePnt2d, + const TopoDS_Vertex& theVertex, + const Standard_Real theMinDistance, + const Handle(BRepMesh_FaceAttribute)& theFaceAttribute, + const Handle(BRepAdaptor_HSurface)& theSurface, + BRepMeshCol::DMapOfIntegerListOfXY& theLocation2dMap); + + //! Stores the given triangulation into the given face. + //! \param theFace face to be updated by triangulation. + //! \param theTriangulation triangulation to be stored into the face. + Standard_EXPORT static void AddInFace( + const TopoDS_Face& theFace, + Handle(Poly_Triangulation)& theTriangulation); + + //! Nullifies triangulation stored in the face. + //! \param theFace face to be updated by null triangulation. + Standard_EXPORT static void NullifyFace(const TopoDS_Face& theFace); + + //! Nullifies polygon on triangulation stored in the edge. + //! \param theEdge edge to be updated by null polygon. + //! \param theTriangulation triangulation the given edge is associated to. + //! \param theLocation face location. + Standard_EXPORT static void NullifyEdge( + const TopoDS_Edge& theEdge, + const Handle(Poly_Triangulation)& theTriangulation, + const TopLoc_Location& theLocation); + + //! Updates the given edge by the given tessellated representation. + //! \param theEdge edge to be updated. + //! \param thePolygon tessellated representation of the edge to be stored. + //! \param theTriangulation triangulation the given edge is associated to. + //! \param theLocation face location. + Standard_EXPORT static void UpdateEdge( + const TopoDS_Edge& theEdge, + const Handle(Poly_PolygonOnTriangulation)& thePolygon, + const Handle(Poly_Triangulation)& theTriangulation, + const TopLoc_Location& theLocation); + + //! Updates the given seam edge by the given tessellated representations. + //! \param theEdge edge to be updated. + //! \param thePolygon1 tessellated representation corresponding to + //! forward direction of the seam edge. + //! \param thePolygon2 tessellated representation corresponding to + //! reversed direction of the seam edge. + //! \param theTriangulation triangulation the given edge is associated to. + //! \param theLocation face location. + Standard_EXPORT static void UpdateEdge( + const TopoDS_Edge& theEdge, + const Handle(Poly_PolygonOnTriangulation)& thePolygon1, + const Handle(Poly_PolygonOnTriangulation)& thePolygon2, + const Handle(Poly_Triangulation)& theTriangulation, + const TopLoc_Location& theLocation); +}; + +#endif diff --git a/src/BRepMesh/BRepMesh_ShapeTool.lxx b/src/BRepMesh/BRepMesh_ShapeTool.lxx deleted file mode 100644 index 9a63b2fc2d..0000000000 --- a/src/BRepMesh/BRepMesh_ShapeTool.lxx +++ /dev/null @@ -1,131 +0,0 @@ -// 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. - -#include -#include -#include -#include -#include -#include -#include - -inline void BRepMesh_ShapeTool::Init(const TopoDS_Shape& S) -{ - theFIterator.Init(S, TopAbs_FACE); -} - -inline Standard_Boolean BRepMesh_ShapeTool::MoreFace() -{ - return theFIterator.More(); -} - -inline void BRepMesh_ShapeTool::NextFace() -{ - theFIterator.Next(); -} - -inline const TopoDS_Face& BRepMesh_ShapeTool:: CurrentFace() -{ - return TopoDS::Face(theFIterator.Current()); -} - - -inline void BRepMesh_ShapeTool::Init(const TopoDS_Face& F) -{ - theEIterator.Init(F,TopAbs_EDGE); -} - -inline Standard_Boolean BRepMesh_ShapeTool::MoreEdge() -{ - return theEIterator.More(); -} - -inline void BRepMesh_ShapeTool::NextEdge() -{ - theEIterator.Next(); -} - - -inline const TopoDS_Edge& BRepMesh_ShapeTool::CurrentEdge() -{ - return TopoDS::Edge(theEIterator.Current()); -} - -inline void BRepMesh_ShapeTool::Init(const TopoDS_Edge& E) -{ - theVIterator.Init(E,TopAbs_VERTEX); -} - - -inline void BRepMesh_ShapeTool::NextInternalVertex() -{ - theVIterator.Next(); -} - -inline const TopoDS_Vertex& BRepMesh_ShapeTool::CurrentInternalVertex() -{ - return TopoDS::Vertex(theVIterator.Current()); -} - -inline TopAbs_Orientation BRepMesh_ShapeTool::Orientation( - const TopoDS_Edge& E) -{ - return E.Orientation(); -} - -inline TopAbs_Orientation BRepMesh_ShapeTool::Orientation( - const TopoDS_Face& F) -{ - return F.Orientation(); -} - -inline void BRepMesh_ShapeTool::Range(const TopoDS_Edge& E, - const TopoDS_Face& F, - Standard_Real& wFirst, - Standard_Real& wLast) -{ - BRep_Tool::Range(E, F, wFirst, wLast); -} - -inline void BRepMesh_ShapeTool::UVPoints(const TopoDS_Edge& E, - const TopoDS_Face& F, - gp_Pnt2d& uvFirst, - gp_Pnt2d& uvLast) -{ - BRep_Tool::UVPoints(E, F, uvFirst, uvLast); -} - -inline Standard_Boolean BRepMesh_ShapeTool::Degenerated(const TopoDS_Edge& E) -{ - return BRep_Tool::Degenerated(E); -} - -inline Standard_Real BRepMesh_ShapeTool::Tolerance(const TopoDS_Vertex& V) -{ - return BRep_Tool::Tolerance(V); -} - -inline Standard_Real BRepMesh_ShapeTool::Parameter(const TopoDS_Vertex& V, - const TopoDS_Edge& E, - const TopoDS_Face& F) -{ - return BRep_Tool::Parameter(V,E,F); -} - -inline gp_Pnt BRepMesh_ShapeTool::Pnt(const TopoDS_Vertex& V) -{ - return BRep_Tool::Pnt(V); -} - - diff --git a/src/BRepMesh/BRepMesh_Triangle.cxx b/src/BRepMesh/BRepMesh_Triangle.cxx deleted file mode 100644 index c642aaedf3..0000000000 --- a/src/BRepMesh/BRepMesh_Triangle.cxx +++ /dev/null @@ -1,144 +0,0 @@ -// Created on: 1993-09-23 -// Created by: Didier PIFFAULT -// Copyright (c) 1993-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. - -#include - -//======================================================================= -//function : Constructor -//purpose : -//======================================================================= -BRepMesh_Triangle::BRepMesh_Triangle() -: myEdge1(0), - myEdge2(0), - myEdge3(0), - myOrientation1(Standard_False), - myOrientation2(Standard_False), - myOrientation3(Standard_False), - myMovability(BRepMesh_Free) -{ -} - -//======================================================================= -//function : Constructor -//purpose : -//======================================================================= -BRepMesh_Triangle::BRepMesh_Triangle (const Standard_Integer theEdge1, - const Standard_Integer theEdge2, - const Standard_Integer theEdge3, - const Standard_Boolean theOrientation1, - const Standard_Boolean theOrientation2, - const Standard_Boolean theOrientation3, - const BRepMesh_DegreeOfFreedom isCanMove) -: myEdge1(theEdge1), - myEdge2(theEdge2), - myEdge3(theEdge3), - myOrientation1(theOrientation1), - myOrientation2(theOrientation2), - myOrientation3(theOrientation3), - myMovability(isCanMove) -{ -} - -//======================================================================= -//function : Initialize -//purpose : -//======================================================================= -void BRepMesh_Triangle::Initialize(const Standard_Integer theEdge1, - const Standard_Integer theEdge2, - const Standard_Integer theEdge3, - const Standard_Boolean theOrientation1, - const Standard_Boolean theOrientation2, - const Standard_Boolean theOrientation3, - const BRepMesh_DegreeOfFreedom isCanMove) -{ - myEdge1 = theEdge1; - myEdge2 = theEdge2; - myEdge3 = theEdge3; - myOrientation1 = theOrientation1; - myOrientation2 = theOrientation2; - myOrientation3 = theOrientation3; - myMovability = isCanMove; -} - -//======================================================================= -//function : Edges -//purpose : -//======================================================================= -void BRepMesh_Triangle::Edges(Standard_Integer& theEdge1, - Standard_Integer& theEdge2, - Standard_Integer& theEdge3, - Standard_Boolean& theOrientation1, - Standard_Boolean& theOrientation2, - Standard_Boolean& theOrientation3) const -{ - theEdge1 = myEdge1; - theEdge2 = myEdge2; - theEdge3 = myEdge3; - theOrientation1 = myOrientation1; - theOrientation2 = myOrientation2; - theOrientation3 = myOrientation3; -} - -//======================================================================= -//function : SetMovability -//purpose : -//======================================================================= -void BRepMesh_Triangle::SetMovability(const BRepMesh_DegreeOfFreedom theMovability) -{ - myMovability = theMovability; -} - -//======================================================================= -//function : HashCode -//purpose : -//======================================================================= -Standard_Integer BRepMesh_Triangle::HashCode(const Standard_Integer theUpper)const -{ - return ::HashCode(myEdge1 + myEdge2 + myEdge3, theUpper); -} - -//======================================================================= -//function : IsEqual -//purpose : -//======================================================================= -Standard_Boolean BRepMesh_Triangle::IsEqual(const BRepMesh_Triangle& theOther) const -{ - if (myMovability == BRepMesh_Deleted || theOther.myMovability == BRepMesh_Deleted) - return Standard_False; - - if (myEdge1 == theOther.myEdge1 && - myEdge2 == theOther.myEdge2 && - myEdge3 == theOther.myEdge3) - { - return Standard_True; - } - - if (myEdge1 == theOther.myEdge2 && - myEdge2 == theOther.myEdge3 && - myEdge3 == theOther.myEdge1) - { - return Standard_True; - } - - if (myEdge1 == theOther.myEdge3 && - myEdge2 == theOther.myEdge1 && - myEdge3 == theOther.myEdge2) - { - return Standard_True; - } - - return Standard_False; -} diff --git a/src/BRepMesh/BRepMesh_Triangle.hxx b/src/BRepMesh/BRepMesh_Triangle.hxx index 3b9fa2a7a2..62dc16cd61 100644 --- a/src/BRepMesh/BRepMesh_Triangle.hxx +++ b/src/BRepMesh/BRepMesh_Triangle.hxx @@ -23,49 +23,125 @@ #include -class BRepMesh_Triangle { + +//! Light weighted structure representing triangle +//! of mesh consisting of oriented links. +class BRepMesh_Triangle +{ public: DEFINE_STANDARD_ALLOC + //! Default constructor. + Standard_EXPORT BRepMesh_Triangle() + : myEdge1(0), + myEdge2(0), + myEdge3(0), + myOrientation1(Standard_False), + myOrientation2(Standard_False), + myOrientation3(Standard_False), + myMovability (BRepMesh_Free) + { + } + + //! Constructor. + //! \param theEdges array of edges of triangle. + //! \param theOrientations array of edge's orientations. + //! \param theMovability movability of triangle. + Standard_EXPORT BRepMesh_Triangle( + const Standard_Integer (&theEdges)[3], + const Standard_Boolean (&theOrientations)[3], + const BRepMesh_DegreeOfFreedom theMovability) + { + Initialize(theEdges, theOrientations, theMovability); + } - Standard_EXPORT BRepMesh_Triangle(); + //! Initializes the triangle by the given parameters. + //! \param theEdges array of edges of triangle. + //! \param theOrientations array of edge's orientations. + //! \param theMovability movability of triangle. + inline void Initialize( + const Standard_Integer (&theEdges)[3], + const Standard_Boolean (&theOrientations)[3], + const BRepMesh_DegreeOfFreedom theMovability) + { + myEdge1 = theEdges[0]; + myEdge2 = theEdges[1]; + myEdge3 = theEdges[2]; + myOrientation1 = theOrientations[0]; + myOrientation2 = theOrientations[1]; + myOrientation3 = theOrientations[2]; + myMovability = theMovability; + } - Standard_EXPORT BRepMesh_Triangle(const Standard_Integer theEdge1, - const Standard_Integer theEdge2, - const Standard_Integer theEdge3, - const Standard_Boolean theOrientation1, - const Standard_Boolean theOrientation2, - const Standard_Boolean theOrientation3, - const BRepMesh_DegreeOfFreedom isCanMove); - - Standard_EXPORT void Initialize(const Standard_Integer theEdge1, - const Standard_Integer theEdge2, - const Standard_Integer theEdge3, - const Standard_Boolean theOrientation1, - const Standard_Boolean theOrientation2, - const Standard_Boolean theOrientation3, - const BRepMesh_DegreeOfFreedom isCanMove) ; - - Standard_EXPORT void Edges(Standard_Integer& theEdge1, - Standard_Integer& theEdge2, - Standard_Integer& theEdge3, - Standard_Boolean& theOrientation1, - Standard_Boolean& theOrientation2, - Standard_Boolean& theOrientation3) const; + //! Gets edges with orientations composing the triangle. + //! \param[out] theEdges array edges are stored to. + //! \param[out] theOrientations array orientations are stored to. + inline void Edges(Standard_Integer (&theEdges)[3], + Standard_Boolean (&theOrientations)[3]) const + { + theEdges[0] = myEdge1; + theEdges[1] = myEdge2; + theEdges[2] = myEdge3; + theOrientations[0] = myOrientation1; + theOrientations[1] = myOrientation2; + theOrientations[2] = myOrientation3; + } + //! Returns movability of the triangle. inline BRepMesh_DegreeOfFreedom Movability() const { return myMovability; } - Standard_EXPORT void SetMovability(const BRepMesh_DegreeOfFreedom theMovability) ; + //! Sets movability of the triangle. + inline void SetMovability(const BRepMesh_DegreeOfFreedom theMovability) + { + myMovability = theMovability; + } - Standard_EXPORT Standard_Integer HashCode(const Standard_Integer theUpper) const; + //! Returns hash code for this triangle. + //! \param theUpper upper index in the container. + //! \return hash code. + Standard_EXPORT Standard_Integer HashCode(const Standard_Integer theUpper) const + { + return ::HashCode(myEdge1 + myEdge2 + myEdge3, theUpper); + } - Standard_EXPORT Standard_Boolean IsEqual(const BRepMesh_Triangle& theOther) const; + //! Checks for equality with another triangle. + //! \param theOther triangle to be checked against this one. + //! \return TRUE if equal, FALSE if not. + Standard_EXPORT Standard_Boolean IsEqual(const BRepMesh_Triangle& theOther) const + { + if (myMovability == BRepMesh_Deleted || theOther.myMovability == BRepMesh_Deleted) + return Standard_False; + + if (myEdge1 == theOther.myEdge1 && + myEdge2 == theOther.myEdge2 && + myEdge3 == theOther.myEdge3) + { + return Standard_True; + } + + if (myEdge1 == theOther.myEdge2 && + myEdge2 == theOther.myEdge3 && + myEdge3 == theOther.myEdge1) + { + return Standard_True; + } + + if (myEdge1 == theOther.myEdge3 && + myEdge2 == theOther.myEdge1 && + myEdge3 == theOther.myEdge2) + { + return Standard_True; + } + + return Standard_False; + } - Standard_Boolean operator ==(const BRepMesh_Triangle& theOther) const + //! Alias for IsEqual. + Standard_EXPORT Standard_Boolean operator ==(const BRepMesh_Triangle& theOther) const { return IsEqual(theOther); } @@ -81,9 +157,8 @@ private: BRepMesh_DegreeOfFreedom myMovability; }; -// Inline functions inline Standard_Integer HashCode(const BRepMesh_Triangle& theTriangle, - const Standard_Integer theUpper) + const Standard_Integer theUpper) { return theTriangle.HashCode(theUpper); } diff --git a/src/BRepMesh/BRepMesh_VectorOfVertex.hxx b/src/BRepMesh/BRepMesh_VectorOfVertex.hxx deleted file mode 100644 index 00bc14b7e4..0000000000 --- a/src/BRepMesh/BRepMesh_VectorOfVertex.hxx +++ /dev/null @@ -1,24 +0,0 @@ -// Created on: 2011-06-01 -// Created by: Oleg AGASHIN -// Copyright (c) 2011-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. - -#ifndef _BRepMesh_VectorOfVertex_HeaderFile -#define _BRepMesh_VectorOfVertex_HeaderFile - -#include -#include - -typedef NCollection_Vector BRepMesh_VectorOfVertex; - -#endif diff --git a/src/BRepMesh/BRepMesh_Vertex.cdl b/src/BRepMesh/BRepMesh_Vertex.cdl deleted file mode 100644 index 90a5663435..0000000000 --- a/src/BRepMesh/BRepMesh_Vertex.cdl +++ /dev/null @@ -1,89 +0,0 @@ --- Created on: 1993-09-22 --- Created by: Didier PIFFAULT --- Copyright (c) 1993-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. - -class Vertex from BRepMesh - - ---Purpose: - - -uses Boolean from Standard, - Integer from Standard, - Real from Standard, - XY from gp, - DegreeOfFreedom from BRepMesh - - -is Create returns Vertex from BRepMesh; - - Create (UV : in XY from gp; - Locat3d : in Integer from Standard; - Move : in DegreeOfFreedom from BRepMesh) - returns Vertex from BRepMesh; - - - Create (U, V : Real from Standard; - Move : in DegreeOfFreedom from BRepMesh) - returns Vertex from BRepMesh; - - - Initialize (me : in out; - UV : in XY from gp; - Locat3d : in Integer from Standard; - Move : in DegreeOfFreedom from BRepMesh) - is static; - - - Coord (me) - returns XY from gp - ---C++: return const & - ---C++: inline - is static; - - - Location3d (me) - returns Integer from Standard - ---C++: inline - is static; - - - Movability (me) - returns DegreeOfFreedom from BRepMesh - ---C++: inline - is static; - - SetMovability (me : in out; - Move : DegreeOfFreedom from BRepMesh) - is static; - - - HashCode (me; - Upper : Integer from Standard) - returns Integer from Standard - ---C++: function call - is static; - - - IsEqual (me; Other : Vertex from BRepMesh) - returns Boolean from Standard - ---C++: alias operator == - is static; - - - fields myUV : XY from gp; - myLocation : Integer from Standard; - myMovability : DegreeOfFreedom from BRepMesh; - -end Vertex; diff --git a/src/BRepMesh/BRepMesh_Vertex.cxx b/src/BRepMesh/BRepMesh_Vertex.cxx deleted file mode 100644 index 7bcd1bfbb9..0000000000 --- a/src/BRepMesh/BRepMesh_Vertex.cxx +++ /dev/null @@ -1,66 +0,0 @@ -// Created on: 1993-09-23 -// Created by: Didier PIFFAULT -// Copyright (c) 1993-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. - -#include -#include - - -BRepMesh_Vertex::BRepMesh_Vertex() -: myLocation(0), myMovability(BRepMesh_Free) -{} - -BRepMesh_Vertex::BRepMesh_Vertex(const gp_XY& UV, - const Standard_Integer Locat3d, - const BRepMesh_DegreeOfFreedom Move) - : myUV(UV), myLocation(Locat3d), myMovability(Move) -{} - -BRepMesh_Vertex::BRepMesh_Vertex(const Standard_Real U, - const Standard_Real V, - const BRepMesh_DegreeOfFreedom Move) - : myUV(U, V), myLocation(0), myMovability(Move) -{} - -void BRepMesh_Vertex::Initialize(const gp_XY& UV, - const Standard_Integer Locat3d, - const BRepMesh_DegreeOfFreedom Move) -{ - myUV=UV; - myLocation=Locat3d; - myMovability=Move; -} - -void BRepMesh_Vertex::SetMovability(const BRepMesh_DegreeOfFreedom Move) -{ - myMovability=Move; -} - -//======================================================================= -//function : HashCode IsEqual -//purpose : Services for Map -//======================================================================= -Standard_Integer BRepMesh_Vertex::HashCode(const Standard_Integer Upper)const -{ - return ::HashCode (Floor(1e5*myUV.X())*Floor(1e5*myUV.Y()), Upper); -} - -Standard_Boolean BRepMesh_Vertex::IsEqual(const BRepMesh_Vertex& Other)const -{ - if (myMovability!=BRepMesh_Deleted && Other.myMovability!=BRepMesh_Deleted) - return (myUV.IsEqual(Other.myUV, Precision::PConfusion())); - return Standard_False; -} - diff --git a/src/BRepMesh/BRepMesh_Vertex.hxx b/src/BRepMesh/BRepMesh_Vertex.hxx new file mode 100644 index 0000000000..8fc140004a --- /dev/null +++ b/src/BRepMesh/BRepMesh_Vertex.hxx @@ -0,0 +1,140 @@ +// Copyright (c) 2013 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 _BRepMesh_Vertex_HeaderFile +#define _BRepMesh_Vertex_HeaderFile + +#include +#include +#include +#include +#include + +//! Light weighted structure representing vertex +//! of the mesh in parametric space. Vertex could be +//! associated with 3d point stored in external map. +class BRepMesh_Vertex +{ +public: + + DEFINE_STANDARD_ALLOC + + //! Default constructor + Standard_EXPORT BRepMesh_Vertex() + : myLocation3d(0), + myMovability(BRepMesh_Free) + { + } + + //! Creates vertex associated with point in 3d space. + //! \param theUV position of vertex in parametric space. + //! \param theLocation3d index of 3d point to be associated with vertex. + //! \param theMovability movability of the vertex. + Standard_EXPORT BRepMesh_Vertex(const gp_XY& theUV, + const Standard_Integer theLocation3d, + const BRepMesh_DegreeOfFreedom theMovability) + { + Initialize(theUV, theLocation3d, theMovability); + } + + //! Creates vertex without association with point in 3d space. + //! \param theU U position of vertex in parametric space. + //! \param theV V position of vertex in parametric space. + //! \param theMovability movability of the vertex. + Standard_EXPORT BRepMesh_Vertex(const Standard_Real theU, + const Standard_Real theV, + const BRepMesh_DegreeOfFreedom theMovability) + : myUV(theU, theV), + myLocation3d(0), + myMovability(theMovability) + {} + + //! Initializes vertex associated with point in 3d space. + //! \param theUV position of vertex in parametric space. + //! \param theLocation3d index of 3d point to be associated with vertex. + //! \param theMovability movability of the vertex. + inline void Initialize(const gp_XY& theUV, + const Standard_Integer theLocation3d, + const BRepMesh_DegreeOfFreedom theMovability) + { + myUV = theUV; + myLocation3d = theLocation3d; + myMovability = theMovability; + } + + //! Returns position of the vertex in parametric space. + inline const gp_XY& Coord() const + { + return myUV; + } + + //! Returns index of 3d point associated with the vertex. + inline Standard_Integer Location3d() const + { + return myLocation3d; + } + + //! Returns movability of the vertex. + inline BRepMesh_DegreeOfFreedom Movability() const + { + return myMovability; + } + + //! Sets movability of the vertex. + inline void SetMovability(const BRepMesh_DegreeOfFreedom theMovability) + { + myMovability = theMovability; + } + + //! Returns hash code for this vertex. + //! \param theUpper upper index in the container. + //! \return hash code. + Standard_EXPORT Standard_Integer HashCode(const Standard_Integer Upper) const + { + return ::HashCode(Floor(1e5 * myUV.X()) * Floor(1e5 * myUV.Y()), Upper); + } + + //! Checks for equality with another vertex. + //! \param theOther vertex to be checked against this one. + //! \return TRUE if equal, FALSE if not. + Standard_EXPORT Standard_Boolean IsEqual(const BRepMesh_Vertex& theOther) const + { + if (myMovability != BRepMesh_Deleted || + theOther.myMovability != BRepMesh_Deleted) + { + return Standard_False; + } + + return (myUV.IsEqual(theOther.myUV, Precision::PConfusion())); + } + + //! Alias for IsEqual. + Standard_EXPORT Standard_Boolean operator ==(const BRepMesh_Vertex& Other) const + { + return IsEqual(Other); + } + +private: + + gp_XY myUV; + Standard_Integer myLocation3d; + BRepMesh_DegreeOfFreedom myMovability; +}; + +inline Standard_Integer HashCode(const BRepMesh_Vertex& me, const Standard_Integer Upper) +{ + return me.HashCode(Upper); +} + +#endif diff --git a/src/BRepMesh/BRepMesh_Vertex.lxx b/src/BRepMesh/BRepMesh_Vertex.lxx deleted file mode 100644 index 81f9c460b6..0000000000 --- a/src/BRepMesh/BRepMesh_Vertex.lxx +++ /dev/null @@ -1,30 +0,0 @@ -// Created on: 1993-09-23 -// Created by: Didier PIFFAULT -// Copyright (c) 1993-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. - -inline const gp_XY& BRepMesh_Vertex::Coord()const -{ - return myUV; -} - -inline Standard_Integer BRepMesh_Vertex::Location3d()const -{ - return myLocation; -} - -inline BRepMesh_DegreeOfFreedom BRepMesh_Vertex::Movability()const -{ - return myMovability; -} diff --git a/src/BRepMesh/BRepMesh_VertexCellFilter.hxx b/src/BRepMesh/BRepMesh_VertexCellFilter.hxx deleted file mode 100644 index d0a87c33a8..0000000000 --- a/src/BRepMesh/BRepMesh_VertexCellFilter.hxx +++ /dev/null @@ -1,26 +0,0 @@ -// Created on: 2011-06-02 -// Created by: Oleg AGASHIN -// Copyright (c) 2011-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. - -#ifndef _BRepMesh_VertexCellFilter_HeaderFile -#define _BRepMesh_VertexCellFilter_HeaderFile - -#include -#include -#include -#include - -typedef NCollection_CellFilter BRepMesh_VertexCellFilter; - -#endif diff --git a/src/BRepMesh/BRepMesh_VertexInspector.cxx b/src/BRepMesh/BRepMesh_VertexInspector.cxx deleted file mode 100644 index e8fdc06bcb..0000000000 --- a/src/BRepMesh/BRepMesh_VertexInspector.cxx +++ /dev/null @@ -1,111 +0,0 @@ -// Created on: 2011-06-01 -// Created by: Oleg AGASHIN -// Copyright (c) 2011-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. - -#include -#include -#include -#include - - -//======================================================================= -//function : BRepMesh_VertexInspector -//purpose : Constructor -//======================================================================= - -BRepMesh_VertexInspector::BRepMesh_VertexInspector (const Standard_Integer nbComp, - const BRepMesh_BaseAllocator& theAlloc) - : myTol(0,1), - myResInd(theAlloc), - myVertices(nbComp), - myDelNodes(theAlloc) -{ - SetTolerance( Precision::Confusion() ); -} - -BRepMesh_VertexInspector::BRepMesh_VertexInspector (const Standard_Integer nbComp, - const Standard_Real aTol, - const BRepMesh_BaseAllocator& theAlloc) - : myTol(0,1), - myResInd(theAlloc), - myVertices(nbComp), - myDelNodes(theAlloc) -{ - SetTolerance( aTol ); -} - -BRepMesh_VertexInspector::BRepMesh_VertexInspector (const Standard_Integer nbComp, - const Standard_Real aTolX, - const Standard_Real aTolY, - const BRepMesh_BaseAllocator& theAlloc) - : myTol(0,1), - myResInd(theAlloc), - myVertices(nbComp), - myDelNodes(theAlloc) -{ - SetTolerance( aTolX, aTolY ); -} - -//======================================================================= -//function : Inspect -//purpose : -// -//======================================================================= -NCollection_CellFilter_Action BRepMesh_VertexInspector::Inspect (const Standard_Integer theTarget) -{ - const BRepMesh_Vertex& aVertex = myVertices(theTarget-1); - if( aVertex.Movability() == BRepMesh_Deleted ) - { - myDelNodes.Append(theTarget); - return CellFilter_Purge; - } - - const gp_XY& aPos = aVertex.Coord(); - Standard_Real dx,dy; - dx = myCurrent.X() - aPos.X(); - dy = myCurrent.Y() - aPos.Y(); - - Standard_Boolean inTol; - if ( myTol(1) == 0. ) - { - inTol = (dx*dx + dy*dy) <= myTol(0); - } - else - { - inTol = ( (dx*dx) <= myTol(0) ) && - ( (dy*dy) <= myTol(1) ); - } - if ( inTol ) - myResInd.Append(theTarget); - return CellFilter_Keep; -} - -//======================================================================= -//function : Add -//purpose : -// -//======================================================================= -Standard_Integer BRepMesh_VertexInspector::Add(const BRepMesh_Vertex& theVertex) -{ - if( myDelNodes.IsEmpty() ) - { - myVertices.Append(theVertex); - return myVertices.Length(); - } - - Standard_Integer aNodeIndex = myDelNodes.First(); - myVertices(aNodeIndex-1) = theVertex; - myDelNodes.RemoveFirst(); - return aNodeIndex; -} diff --git a/src/BRepMesh/BRepMesh_VertexInspector.hxx b/src/BRepMesh/BRepMesh_VertexInspector.hxx index be49d66739..4a78330728 100644 --- a/src/BRepMesh/BRepMesh_VertexInspector.hxx +++ b/src/BRepMesh/BRepMesh_VertexInspector.hxx @@ -16,111 +16,138 @@ #ifndef _BRepMesh_VertexInspector_HeaderFile #define _BRepMesh_VertexInspector_HeaderFile -#include #include #include #include +#include #include #include -#include -#include -#include - -//======================================================================= -//! The class to find in the coincidence points -//======================================================================= +//! Class intended for fast searching of the coincidence points. class BRepMesh_VertexInspector : public NCollection_CellFilter_InspectorXY { public: typedef Standard_Integer Target; - //! Constructor; remembers tolerance and collector data structure. - //! theTol can be Real or Array1OfReal with two elements which describe - //! tolerance for each dimension. - BRepMesh_VertexInspector (const Standard_Integer nbComp, - const BRepMesh_BaseAllocator& theAlloc); - - BRepMesh_VertexInspector (const Standard_Integer nbComp, - const Standard_Real theTol, - const BRepMesh_BaseAllocator& theAlloc); - - BRepMesh_VertexInspector (const Standard_Integer nbComp, - const Standard_Real aTolX, - const Standard_Real aTolY, - const BRepMesh_BaseAllocator& theAlloc); - Standard_Integer Add(const BRepMesh_Vertex& theVertex); - - void SetTolerance(const Standard_Real theTol) + //! Constructor. + //! \param theReservedSize size to be reserved for vector of vertices. + //! \param theAllocator memory allocator to be used by internal collections. + Standard_EXPORT BRepMesh_VertexInspector ( + const Standard_Integer theReservedSize, + const BRepMeshCol::Allocator& theAllocator) + : myResIndices(theAllocator), + myVertices (theReservedSize), + myDelNodes (theAllocator) { - myTol(0) = theTol*theTol; - myTol(1) = 0.; + SetTolerance( Precision::Confusion() ); + } + + //! Registers the given vertex. + //! \param theVertex vertex to be registered. + Standard_EXPORT Standard_Integer Add(const BRepMesh_Vertex& theVertex) + { + if( myDelNodes.IsEmpty() ) + { + myVertices.Append(theVertex); + return myVertices.Length(); + } + + Standard_Integer aNodeIndex = myDelNodes.First(); + myVertices(aNodeIndex - 1) = theVertex; + myDelNodes.RemoveFirst(); + return aNodeIndex; } - void SetTolerance(const Standard_Real theTolX, const Standard_Real theTolY) + + //! Sets the tolerance to be used for identification of + //! coincident vertices equal for both dimensions. + inline void SetTolerance(const Standard_Real theTolerance) { - myTol(0) = theTolX*theTolX; - myTol(1) = theTolY*theTolY; + myTolerance[0] = theTolerance * theTolerance; + myTolerance[1] = 0.; } - void Clear() + //! Sets the tolerance to be used for identification of + //! coincident vertices. + //! \param theToleranceX tolerance for X dimension. + //! \param theToleranceY tolerance for Y dimension. + inline void SetTolerance(const Standard_Real theToleranceX, + const Standard_Real theToleranceY) + { + myTolerance[0] = theToleranceX * theToleranceX; + myTolerance[1] = theToleranceY * theToleranceY; + } + + //! Clear inspector's internal data structures. + inline void Clear() { myVertices.Clear(); myDelNodes.Clear(); } - void Delete(const Standard_Integer theIndex) + //! Deletes vertex with the given index. + //! \param theIndex index of vertex to be removed. + inline void Delete(const Standard_Integer theIndex) { - myVertices(theIndex-1).SetMovability(BRepMesh_Deleted); + myVertices(theIndex - 1).SetMovability(BRepMesh_Deleted); myDelNodes.Append(theIndex); } - Standard_Integer GetNbVertices() const + //! Returns number of registered vertices. + inline Standard_Integer NbVertices() const { return myVertices.Length(); } - BRepMesh_Vertex& GetVertex(Standard_Integer theInd) + //! Returns vertex with the given index. + inline BRepMesh_Vertex& GetVertex(Standard_Integer theIndex) { - return myVertices(theInd-1); + return myVertices(theIndex - 1); } - //! Set current node to be checked - void SetCurrent (const gp_XY& theCurVertex, const Standard_Boolean) + //! Set reference point to be checked. + inline void SetPoint(const gp_XY& thePoint) { - myResInd.Clear(); - myCurrent = theCurVertex; + myResIndices.Clear(); + myPoint = thePoint; } - //!Get result index of node - const Standard_Integer GetCoincidentInd() const + //! Returns index of point coinciding with regerence one. + inline const Standard_Integer GetCoincidentPoint() const { - if ( myResInd.Size() > 0 ) + if ( myResIndices.Size() > 0 ) { - return myResInd.First(); + return myResIndices.First(); } return 0; } - const BRepMesh_ListOfInteger& GetListOfDelNodes() const + //! Returns list with indexes of vertices that have movability attribute + //! equal to BRepMesh_Deleted and can be replaced with another node. + inline const BRepMeshCol::ListOfInteger& GetListOfDelPoints() const { return myDelNodes; } - //! Implementation of inspection method - NCollection_CellFilter_Action Inspect (const Standard_Integer theTarget); + //! Performs inspection of a point with the given index. + //! \param theTargetIndex index of a circle to be checked. + //! \return status of the check. + Standard_EXPORT NCollection_CellFilter_Action Inspect(const Standard_Integer theTargetIndex); - static Standard_Boolean IsEqual (Standard_Integer theIdx, const Standard_Integer theTarget) + //! Checks indices for equlity. + Standard_EXPORT static Standard_Boolean IsEqual(const Standard_Integer theIndex, + const Standard_Integer theTargetIndex) { - return (theIdx == theTarget); + return (theIndex == theTargetIndex); } private: - TColStd_Array1OfReal myTol; - BRepMesh_ListOfInteger myResInd; - BRepMesh_VectorOfVertex myVertices; - BRepMesh_ListOfInteger myDelNodes; - gp_XY myCurrent; + + Standard_Real myTolerance[2]; + BRepMeshCol::ListOfInteger myResIndices; + BRepMeshCol::VectorOfVertex myVertices; + BRepMeshCol::ListOfInteger myDelNodes; + gp_XY myPoint; }; #endif diff --git a/src/BRepMesh/BRepMesh_VertexTool.cdl b/src/BRepMesh/BRepMesh_VertexTool.cdl deleted file mode 100644 index 59af321e12..0000000000 --- a/src/BRepMesh/BRepMesh_VertexTool.cdl +++ /dev/null @@ -1,140 +0,0 @@ --- Created on: 2011-06-02 --- Created by: Oleg AGASHIN --- Copyright (c) 2011-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. - -class VertexTool from BRepMesh - - ---Purpose: Describes the data structure necessary for the - -- mesh algorithm and contains the vertices in UV space. - - uses Boolean from Standard, - Integer from Standard, - Real from Standard, - XY from gp, - ListOfInteger from BRepMesh, - VertexCellFilter from BRepMesh, - VertexInspector from BRepMesh, - BaseAllocator from BRepMesh, - Vertex from BRepMesh, - DataMapOfIntegerListOfInteger from BRepMesh, - Array1OfReal from TColStd - - is Create (theAlloc : in BaseAllocator from BRepMesh) - returns VertexTool from BRepMesh; - - - Create (nbComp : in Integer from Standard; - theAlloc : in BaseAllocator from BRepMesh) - ---Purpose: Constructs a VertexTool with an evaluation of the - -- number of vertices. - returns VertexTool from BRepMesh; - - SetCellSize(me : in out; - theSize : in Real from Standard) - ---Purpose: Sets new size for cellfilter. - is static; - - SetCellSize(me : in out; - theXSize : in Real from Standard; - theYSize : in Real from Standard) - ---Purpose: Sets new size for cellfilter. - is static; - - SetTolerance(me : in out; - theTol : in Real from Standard) - ---Purpose: Sets new size for cellfilter. - is static; - - SetTolerance(me : in out; - theTolX : in Real from Standard; - theTolY : in Real from Standard) - ---Purpose: Sets new size for cellfilter. - is static; - - Add (me : in out; - theVertex: in Vertex from BRepMesh; - theParams: in ListOfInteger from BRepMesh) - ---Purpose: Adds a vertex to the tool. - returns Integer from Standard is static; - - Add (me : in out; - theVertex: in Vertex from BRepMesh) - ---Purpose: Adds a vertex to the tool. - returns Integer from Standard is static; - - Delete (me : in out; theIndex : Integer from Standard) - ---Purpose: Deletes a vertex from the tool. - is static; - - FindFromIndex (me; theIndex : Integer from Standard) - ---Purpose: Returns data assigned to theIndex. - ---C++: alias operator() - ---C++: return & - returns ListOfInteger from BRepMesh is static; - - FindKey (me: out; theIndex: Integer from Standard) - ---Purpose: Selects the vertex by theIndex. - ---C++: return const & - returns Vertex from BRepMesh is static; - - FindIndex (me: out; - theVertex: Vertex from BRepMesh) - ---Purpose: Returns an index of theVertex. - returns Integer from Standard is static; - - Extent (me) - ---Purpose: Returns a number of vertices. - returns Integer from Standard is static; - - IsEmpty (me) - ---Purpose: Returns True when the map contains no keys. - returns Boolean from Standard is static; - - Substitute(me: in out; Index: Integer from Standard; - theVertex: Vertex from BRepMesh; - theData : ListOfInteger from BRepMesh) - ---Purpose: Substitutes vertex with Index on - -- theVertex with attributes theData. - is static; - - RemoveLast(me: out) - ---Purpose: Remove last node from the structure. - is static; - - GetListOfDelNodes(me) - ---Purpose: Returns the list with indexes of - -- vertices that have Movability attribute - -- equal to BRepMesh_Deleted and can be - -- replaced with another node. - ---C++: return const & - returns ListOfInteger from BRepMesh - is static; - - ExpandPoint(me: in out; - thePnt: in XY from gp; - theMinPnt: out XY from gp; - theMaxPnt: out XY from gp) - is static private; - - Statistics(me; S: in out OStream from Standard) - ---Purpose: Prints statistics. - is static; - - fields myAllocator : BaseAllocator from BRepMesh; - myCellFilter : VertexCellFilter from BRepMesh; - mySelector : VertexInspector from BRepMesh; - myLinksMap : DataMapOfIntegerListOfInteger from BRepMesh; - myTol : Array1OfReal from TColStd; - -end CircleTool; diff --git a/src/BRepMesh/BRepMesh_VertexTool.cxx b/src/BRepMesh/BRepMesh_VertexTool.cxx index 2ef8d228f5..583c485a91 100644 --- a/src/BRepMesh/BRepMesh_VertexTool.cxx +++ b/src/BRepMesh/BRepMesh_VertexTool.cxx @@ -13,87 +13,58 @@ // 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 //======================================================================= -//function : BRepMesh_VertexTool +//function : Inspect //purpose : //======================================================================= -BRepMesh_VertexTool::BRepMesh_VertexTool(const BRepMesh_BaseAllocator& theAlloc) -: myAllocator(theAlloc), - myCellFilter(0., myAllocator), - mySelector(64,myAllocator), - myTol(0,1) +NCollection_CellFilter_Action BRepMesh_VertexInspector::Inspect( + const Standard_Integer theTarget) { - SetCellSize ( Precision::Confusion()+0.05*Precision::Confusion() ); - SetTolerance( Precision::Confusion(), Precision::Confusion() ); -} - -//======================================================================= -//function : BRepMesh_VertexTool -//purpose : -//======================================================================= -BRepMesh_VertexTool::BRepMesh_VertexTool(const Standard_Integer nbComp, - const BRepMesh_BaseAllocator& theAlloc) - : myAllocator(theAlloc), - myCellFilter(0., myAllocator), - mySelector(Max(nbComp,64),myAllocator), - myTol(0,1) -{ - SetCellSize ( Precision::Confusion()+0.05*Precision::Confusion() ); - SetTolerance( Precision::Confusion(), Precision::Confusion() ); -} - -//======================================================================= -//function : SetCellSize -//purpose : -//======================================================================= -void BRepMesh_VertexTool::SetCellSize(const Standard_Real theSize) -{ - myCellFilter.Reset(theSize, myAllocator); - mySelector.Clear(); -} - -//======================================================================= -//function : SetCellSize -//purpose : -//======================================================================= -void BRepMesh_VertexTool::SetCellSize(const Standard_Real theXSize, - const Standard_Real theYSize) -{ - Standard_Real aCellSize[2]; - aCellSize[0] = theXSize; - aCellSize[1] = theYSize; + const BRepMesh_Vertex& aVertex = myVertices(theTarget - 1); + if(aVertex.Movability() == BRepMesh_Deleted) + { + myDelNodes.Append(theTarget); + return CellFilter_Purge; + } - myCellFilter.Reset(aCellSize, myAllocator); - mySelector.Clear(); + gp_XY aVec = (myPoint - aVertex.Coord()); + Standard_Boolean inTol; + if (Abs(myTolerance[1]) < Precision::Confusion()) + { + inTol = aVec.SquareModulus() < myTolerance[0]; + } + else + { + inTol = ((aVec.X() * aVec.X()) < myTolerance[0]) && + ((aVec.Y() * aVec.Y()) < myTolerance[1]); + } + if (inTol) + myResIndices.Append(theTarget); + + return CellFilter_Keep; } //======================================================================= -//function : SetTolerance +//function : BRepMesh_VertexTool //purpose : //======================================================================= -void BRepMesh_VertexTool::SetTolerance(const Standard_Real theTol) +BRepMesh_VertexTool::BRepMesh_VertexTool( + const Standard_Integer theReservedSize, + const BRepMeshCol::Allocator& theAllocator) + : myAllocator (theAllocator), + myCellFilter(0., myAllocator), + mySelector (Max(theReservedSize, 64),myAllocator) { - mySelector.SetTolerance( theTol ); - myTol(0) = theTol; - myTol(1) = theTol; -} - -//======================================================================= -//function : SetTolerance -//purpose : -//======================================================================= -void BRepMesh_VertexTool::SetTolerance(const Standard_Real theTolX, const Standard_Real theTolY) -{ - mySelector.SetTolerance( theTolX, theTolY ); - myTol(0) = theTolX; - myTol(1) = theTolY; + const Standard_Real aTol = Precision::Confusion(); + SetCellSize ( aTol + 0.05 * aTol ); + SetTolerance( aTol, aTol ); } //======================================================================= @@ -102,145 +73,76 @@ void BRepMesh_VertexTool::SetTolerance(const Standard_Real theTolX, const Standa //======================================================================= Standard_Integer BRepMesh_VertexTool::Add(const BRepMesh_Vertex& theVertex) { - Standard_Integer anIndex = FindIndex(theVertex); - if ( anIndex == 0 ) + Standard_Integer aIndex = FindIndex(theVertex); + if (aIndex == 0) { - BRepMesh_ListOfInteger thelist(myAllocator); - anIndex = Add(theVertex, thelist); + BRepMeshCol::ListOfInteger aParams(myAllocator); + aIndex = Add(theVertex, aParams); } - return anIndex; + return aIndex; } //======================================================================= //function : Add //purpose : //======================================================================= -Standard_Integer BRepMesh_VertexTool::Add(const BRepMesh_Vertex& theVertex, - const BRepMesh_ListOfInteger& theParams) +Standard_Integer BRepMesh_VertexTool::Add( + const BRepMesh_Vertex& theVertex, + const BRepMeshCol::ListOfInteger& theParams) { - Standard_Integer anIndex = mySelector.Add(theVertex); - myLinksMap.Bind(anIndex, theParams); + Standard_Integer aIndex = mySelector.Add(theVertex); + myLinksMap.Bind(aIndex, theParams); + gp_XY aMinPnt, aMaxPnt; - ExpandPoint(theVertex.Coord(), aMinPnt, aMaxPnt); - myCellFilter.Add(anIndex, aMinPnt, aMaxPnt); - return anIndex; + expandPoint(theVertex.Coord(), aMinPnt, aMaxPnt); + myCellFilter.Add(aIndex, aMinPnt, aMaxPnt); + + return aIndex; } //======================================================================= //function : Delete //purpose : //======================================================================= -void BRepMesh_VertexTool::Delete(const Standard_Integer theIndex) +void BRepMesh_VertexTool::Delete(const Standard_Integer theIndex) { BRepMesh_Vertex& aV = mySelector.GetVertex(theIndex); + gp_XY aMinPnt, aMaxPnt; - ExpandPoint(aV.Coord(), aMinPnt, aMaxPnt); - myCellFilter.Remove (theIndex, aMinPnt, aMaxPnt); + expandPoint(aV.Coord(), aMinPnt, aMaxPnt); + + myCellFilter.Remove(theIndex, aMinPnt, aMaxPnt); mySelector.Delete(theIndex); } -//======================================================================= -//function : RemoveLast -//purpose : -//======================================================================= -void BRepMesh_VertexTool::RemoveLast() -{ - Standard_Integer aIndex = mySelector.GetNbVertices(); - Delete( aIndex ); -} - -//======================================================================= -//function : GetListOfDelNodes -//purpose : -//======================================================================= -const BRepMesh_ListOfInteger& BRepMesh_VertexTool::GetListOfDelNodes() const -{ - return mySelector.GetListOfDelNodes(); -} - -//======================================================================= -//function : FindIndex -//purpose : -//======================================================================= -Standard_Integer BRepMesh_VertexTool::FindIndex(const BRepMesh_Vertex& theVertex) -{ - mySelector.SetCurrent(theVertex.Coord(),Standard_False); - myCellFilter.Inspect (theVertex.Coord(), mySelector); - return mySelector.GetCoincidentInd(); -} - -//======================================================================= -//function : FindKey -//purpose : -//======================================================================= -const BRepMesh_Vertex& BRepMesh_VertexTool::FindKey(const Standard_Integer theIndex) -{ - return mySelector.GetVertex(theIndex); -} - //======================================================================= //function : Substitute //purpose : //======================================================================= -void BRepMesh_VertexTool::Substitute(const Standard_Integer Index, - const BRepMesh_Vertex& theVertex, - const BRepMesh_ListOfInteger& theData) +void BRepMesh_VertexTool::Substitute( + const Standard_Integer theIndex, + const BRepMesh_Vertex& theVertex, + const BRepMeshCol::ListOfInteger& theData) { - BRepMesh_Vertex& aV = mySelector.GetVertex(Index); + BRepMesh_Vertex& aV = mySelector.GetVertex(theIndex); + gp_XY aMinPnt, aMaxPnt; - ExpandPoint(aV.Coord(), aMinPnt, aMaxPnt); - myCellFilter.Remove (Index, aMinPnt, aMaxPnt); + expandPoint(aV.Coord(), aMinPnt, aMaxPnt); + + myCellFilter.Remove(theIndex, aMinPnt, aMaxPnt); + aV = theVertex; - ExpandPoint(aV.Coord(), aMinPnt, aMaxPnt); - myCellFilter.Add(Index, aMinPnt, aMaxPnt); - FindFromIndex(Index) = theData; -} - -//======================================================================= -//function : Extent -//purpose : -//======================================================================= -Standard_Integer BRepMesh_VertexTool::Extent() const -{ - return mySelector.GetNbVertices(); -} - -//======================================================================= -//function : IsEmpty -//purpose : -//======================================================================= -Standard_Boolean BRepMesh_VertexTool::IsEmpty() const -{ - return mySelector.GetNbVertices() == 0; -} - -//======================================================================= -//function : FindFromIndex -//purpose : -//======================================================================= -BRepMesh_ListOfInteger& BRepMesh_VertexTool::FindFromIndex(const Standard_Integer theIndex) const -{ - return (BRepMesh_ListOfInteger&) myLinksMap.Find(theIndex); -} - -//======================================================================= -//function : -//purpose : -//======================================================================= -void BRepMesh_VertexTool::ExpandPoint(const gp_XY& thePnt, gp_XY& theMinPnt, gp_XY& theMaxPnt) -{ - theMinPnt.SetX(thePnt.X() - myTol(0)); - theMinPnt.SetY(thePnt.Y() - myTol(1)); - theMaxPnt.SetX(thePnt.X() + myTol(0)); - theMaxPnt.SetY(thePnt.Y() + myTol(1)); + expandPoint(aV.Coord(), aMinPnt, aMaxPnt); + myCellFilter.Add(theIndex, aMinPnt, aMaxPnt); + FindFromIndex(theIndex) = theData; } //======================================================================= //function : Statistics //purpose : //======================================================================= -void BRepMesh_VertexTool::Statistics(Standard_OStream& S) const +void BRepMesh_VertexTool::Statistics(Standard_OStream& theStream) const { - S <<"\nStructure Statistics\n---------------\n\n"; - S <<"This structure has "< +#include +#include +#include +#include +#include +#include +#include + +class BRepMesh_Vertex; + +//! Describes data structure intended to keep mesh nodes +//! defined in UV space and implements functionality +//! providing their uniqueness regarding thir position. +class BRepMesh_VertexTool +{ +public: + + DEFINE_STANDARD_ALLOC + + //! Constructor. + //! \param theReservedSize size to be reserved for vector of vertices. + //! \param theAllocator memory allocator to be used by internal collections. + Standard_EXPORT BRepMesh_VertexTool(const Standard_Integer theReservedSize, + const BRepMeshCol::Allocator& theAllocator); + + //! Sets new size of cell for cellfilter equal in both directions. + Standard_EXPORT void SetCellSize(const Standard_Real theSize) + { + myCellFilter.Reset(theSize, myAllocator); + mySelector.Clear(); + } + + //! Sets new size of cell for cellfilter. + //! \param theSizeX size for X dimension. + //! \param theSizeY size for Y dimension. + Standard_EXPORT void SetCellSize(const Standard_Real theSizeX, + const Standard_Real theSizeY) + { + Standard_Real aCellSize[2] = { theSizeX, theSizeY }; + myCellFilter.Reset(aCellSize, myAllocator); + mySelector.Clear(); + } + + //! Sets the tolerance to be used for identification of + //! coincident vertices equal for both dimensions. + Standard_EXPORT void SetTolerance(const Standard_Real theTolerance) + { + mySelector.SetTolerance( theTolerance ); + myTolerance[0] = theTolerance; + myTolerance[1] = theTolerance; + } + + //! Sets the tolerance to be used for identification of + //! coincident vertices. + //! \param theToleranceX tolerance for X dimension. + //! \param theToleranceY tolerance for Y dimension. + Standard_EXPORT void SetTolerance(const Standard_Real theToleranceX, + const Standard_Real theToleranceY) + { + mySelector.SetTolerance( theToleranceX, theToleranceY ); + myTolerance[0] = theToleranceX; + myTolerance[1] = theToleranceY; + } + + //! Adds vertex with empty data to the tool. + Standard_EXPORT Standard_Integer Add(const BRepMesh_Vertex& theVertex); + + //! Adds vertex with associated data to the tool. + //! \param theVertex vertex to be added. + //! \param theParams data associated with the vertex. + Standard_EXPORT Standard_Integer Add(const BRepMesh_Vertex& theVertex, + const BRepMeshCol::ListOfInteger& theParams); + + //! Deletes vertex with the given index from the tool. + Standard_EXPORT void Delete(const Standard_Integer theIndex); + + //! Returns data assigned to link with the given index. + //! \param theIndex index of link which data should be returned. + //! \return attached data. + inline BRepMeshCol::ListOfInteger& FindFromIndex(const Standard_Integer theIndex) const + { + return (BRepMeshCol::ListOfInteger&)myLinksMap.Find(theIndex); + } + + //! Alias for FindFromIndex. + BRepMeshCol::ListOfInteger& operator()(const Standard_Integer theIndex) const + { + return FindFromIndex(theIndex); + } + + //! Returns vertex by the given index. + inline const BRepMesh_Vertex& FindKey(const Standard_Integer theIndex) + { + return mySelector.GetVertex(theIndex); + } + + //! Returns index of the given vertex. + Standard_EXPORT Standard_Integer FindIndex(const BRepMesh_Vertex& theVertex) + { + mySelector.SetPoint(theVertex.Coord()); + myCellFilter.Inspect (theVertex.Coord(), mySelector); + return mySelector.GetCoincidentPoint(); + } + + //! Returns a number of vertices. + inline Standard_Integer Extent() const + { + return mySelector.NbVertices(); + } + + //! Returns True when the map contains no keys.
+ inline Standard_Boolean IsEmpty() const + { + return (Extent() == 0); + } + + //! Substitutes vertex with the given by the given vertex with attributes. + //! \param theIndex index of vertex to be substituted. + //! \param theVertex replacement vertex. + //! \param theData data associated to the vertex. + Standard_EXPORT void Substitute(const Standard_Integer theIndex, + const BRepMesh_Vertex& theVertex, + const BRepMeshCol::ListOfInteger& theData); + + //! Remove last node from the structure. + inline void RemoveLast() + { + Delete(Extent()); + } + + //! Returns the list with indexes of vertices that have movability attribute + //! equal to BRepMesh_Deleted and can be replaced with another node. + inline const BRepMeshCol::ListOfInteger& GetListOfDelNodes() const + { + return mySelector.GetListOfDelPoints(); + } + + //! Prints statistics. + Standard_EXPORT void Statistics(Standard_OStream& theStream) const; + +private: + + //! Expands the given point according to specified tolerance. + //! \param thePoint point to be expanded. + //! \param[out] theMinPoint bottom left corner of area defined by expanded point. + //! \param[out] theMaxPoint top right corner of area defined by expanded point. + inline void expandPoint(const gp_XY& thePoint, + gp_XY& theMinPoint, + gp_XY& theMaxPoint) + { + theMinPoint.SetX(thePoint.X() - myTolerance[0]); + theMinPoint.SetY(thePoint.Y() - myTolerance[1]); + theMaxPoint.SetX(thePoint.X() + myTolerance[0]); + theMaxPoint.SetY(thePoint.Y() + myTolerance[1]); + } + +private: + + BRepMeshCol::Allocator myAllocator; + BRepMeshCol::VertexCellFilter myCellFilter; + BRepMesh_VertexInspector mySelector; + BRepMeshCol::DMapOfIntegerListOfInteger myLinksMap; + Standard_Real myTolerance[2]; +}; + +#endif diff --git a/src/BRepMesh/BRepMesh_WireChecker.cxx b/src/BRepMesh/BRepMesh_WireChecker.cxx index a2826fc0ae..7cd24346c2 100644 --- a/src/BRepMesh/BRepMesh_WireChecker.cxx +++ b/src/BRepMesh/BRepMesh_WireChecker.cxx @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -108,7 +107,7 @@ void BRepMesh_WireChecker::BndBox2dTreeSelector::SetSkippedIndex( //function : Indices //purpose : //======================================================================= -const BRepMesh_WireChecker::ArrayOfInteger& +const BRepMeshCol::Array1OfInteger& BRepMesh_WireChecker::BndBox2dTreeSelector::Indices() const { return myIndices; @@ -130,7 +129,7 @@ Standard_Integer BRepMesh_WireChecker::BndBox2dTreeSelector::IndicesNb() const BRepMesh_WireChecker::BRepMesh_WireChecker( const TopoDS_Face& theFace, const Standard_Real theTolUV, - const BRepMesh_DataMapOfShapePairOfPolygon& theEdges, + const BRepMeshCol::DMapOfShapePairOfPolygon& theEdges, const TColStd_IndexedMapOfInteger& theVertexMap, const Handle(BRepMesh_DataStructureOfDelaun)& theStructure, const Standard_Real theUmin, @@ -183,7 +182,7 @@ BRepMesh_WireChecker::BRepMesh_WireChecker( //function : ReCompute //purpose : //======================================================================= -void BRepMesh_WireChecker::ReCompute(BRepMesh_ClassifierPtr& theClassifier) +void BRepMesh_WireChecker::ReCompute(BRepMeshCol::HClassifier& theClassifier) { if (theClassifier.IsNull()) return; @@ -197,7 +196,7 @@ void BRepMesh_WireChecker::ReCompute(BRepMesh_ClassifierPtr& theClassifier) const Standard_Integer aNbWires = aDWires.size(); - std::vector aWiresBiPoints(aNbWires); + BRepMeshCol::Array1OfSegmentsTree aWiresBiPoints(aNbWires); fillSegmentsTree(aDWires, aWiresBiPoints); #ifdef HAVE_TBB @@ -360,8 +359,8 @@ Standard_Boolean BRepMesh_WireChecker::collectDiscretizedWires( //purpose : //======================================================================= void BRepMesh_WireChecker::fillSegmentsTree( - const SeqOfDWires& theDWires, - std::vector& theWiresSegmentsTree) + const SeqOfDWires& theDWires, + BRepMeshCol::Array1OfSegmentsTree& theWiresSegmentsTree) { const Standard_Integer aNbWires = theDWires.size(); for (Standard_Integer aWireIt = 0; aWireIt < aNbWires; ++aWireIt) @@ -369,9 +368,13 @@ void BRepMesh_WireChecker::fillSegmentsTree( const SeqOfPnt2d& aWire = theDWires[aWireIt]; const Standard_Integer aWireLen = aWire.Size(); - HArrayOfSegments aWireSegments = new ArrayOfSegments(aWireLen); - HBndBox2dTree aBndBoxTree = new BndBox2dTree; - BndBox2dTreeFiller aBndBoxTreeFiller(*aBndBoxTree); + BRepMeshCol::HArray1OfSegments aWireSegments = + new BRepMeshCol::Array1OfSegments(aWireLen); + + BRepMeshCol::HBndBox2dTree aBndBoxTree = + new BRepMeshCol::BndBox2dTree; + + BRepMeshCol::BndBox2dTreeFiller aBndBoxTreeFiller(*aBndBoxTree); Standard_Real x1 = 0., y1 = 0., aXstart = 0., aYstart = 0.; for (Standard_Integer aPntIt = 0; aPntIt <= aWireLen; ++aPntIt) @@ -402,7 +405,7 @@ void BRepMesh_WireChecker::fillSegmentsTree( gp_Pnt2d aEndPnt(x2, y2); const Standard_Integer aPointId = aPntIt - 1; - Segment& aSegment = aWireSegments->at(aPointId); + BRepMeshCol::Segment& aSegment = aWireSegments->at(aPointId); aSegment.StartPnt = aStartPnt.XY(); aSegment.EndPnt = aEndPnt.XY(); @@ -416,7 +419,7 @@ void BRepMesh_WireChecker::fillSegmentsTree( } aBndBoxTreeFiller.Fill(); - SegmentsTree& aSegmentsTree = theWiresSegmentsTree[aWireIt]; + BRepMeshCol::SegmentsTree& aSegmentsTree = theWiresSegmentsTree[aWireIt]; aSegmentsTree.first = aWireSegments; aSegmentsTree.second = aBndBoxTree; } diff --git a/src/BRepMesh/BRepMesh_WireChecker.hxx b/src/BRepMesh/BRepMesh_WireChecker.hxx index 57c4b8fe2a..417be93eec 100644 --- a/src/BRepMesh/BRepMesh_WireChecker.hxx +++ b/src/BRepMesh/BRepMesh_WireChecker.hxx @@ -20,15 +20,8 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include #include #include #include @@ -38,7 +31,6 @@ class BRepMesh_DataMapOfShapePairOfPolygon; class TColStd_IndexedMapOfInteger; -class BRepMesh_DataStructureOfDelaun; //! Auxilary class intended to check correctness of discretized face. //! In particular, checks boundaries of discretized face for self @@ -47,26 +39,11 @@ class BRepMesh_WireChecker { public: - //! Structure keeping parameters of segment. - struct Segment - { - gp_XY StartPnt; - gp_XY EndPnt; - }; - - typedef NCollection_EBTree BndBox2dTree; - typedef NCollection_UBTreeFiller BndBox2dTreeFiller; - typedef NCollection_Array1 ArrayOfInteger; - typedef std::vector ArrayOfSegments; - typedef NCollection_Handle HArrayOfSegments; - typedef NCollection_Handle HBndBox2dTree; - typedef std::pair SegmentsTree; - //! Selector. //! Used to identify segments with overlapped bounding boxes. //! Note that instance of selector can be used only once due to //! unextentable array of indices. - class BndBox2dTreeSelector : public BndBox2dTree::Selector + class BndBox2dTreeSelector : public BRepMeshCol::BndBox2dTree::Selector { public: Standard_EXPORT BndBox2dTreeSelector(const Standard_Integer theReservedSize); @@ -76,14 +53,14 @@ public: Standard_EXPORT void Clear(); Standard_EXPORT void SetBox(const Bnd_Box2d& theBox2D); Standard_EXPORT void SetSkippedIndex(const Standard_Integer theIndex); - Standard_EXPORT const ArrayOfInteger& Indices() const; + Standard_EXPORT const BRepMeshCol::Array1OfInteger& Indices() const; Standard_EXPORT Standard_Integer IndicesNb() const; protected: - Bnd_Box2d myBox2D; - Standard_Integer mySkippedIndex; - ArrayOfInteger myIndices; - Standard_Integer myIndicesNb; + Bnd_Box2d myBox2D; + Standard_Integer mySkippedIndex; + BRepMeshCol::Array1OfInteger myIndices; + Standard_Integer myIndicesNb; }; private: @@ -110,7 +87,7 @@ public: Standard_EXPORT BRepMesh_WireChecker( const TopoDS_Face& theFace, const Standard_Real theTolUV, - const BRepMesh_DataMapOfShapePairOfPolygon& theEdges, + const BRepMeshCol::DMapOfShapePairOfPolygon& theEdges, const TColStd_IndexedMapOfInteger& theVertexMap, const Handle(BRepMesh_DataStructureOfDelaun)& theStructure, const Standard_Real theUmin, @@ -121,7 +98,7 @@ public: //! Recompute data using parameters passed in constructor. //! \param[out] theClassifier Classifier to be updated using calculated data. - Standard_EXPORT void ReCompute(BRepMesh_ClassifierPtr& theClassifier); + Standard_EXPORT void ReCompute(BRepMeshCol::HClassifier& theClassifier); //! Returns status of the check. inline BRepMesh_Status Status() const @@ -141,8 +118,8 @@ private: //! \param theWiresSegmentsTree Array of segments with corresponding //! bounding boxes trees to be filled. void fillSegmentsTree( - const SeqOfDWires& theDWires, - std::vector& theWiresSegmentsTree); + const SeqOfDWires& theDWires, + BRepMeshCol::Array1OfSegmentsTree& theWiresSegmentsTree); //! Assignment operator. void operator =(BRepMesh_WireChecker& /*theOther*/) @@ -152,7 +129,7 @@ private: private: const Standard_Real myTolUV; - const BRepMesh_DataMapOfShapePairOfPolygon& myEdges; + const BRepMeshCol::DMapOfShapePairOfPolygon& myEdges; const TColStd_IndexedMapOfInteger& myVertexMap; const Handle(BRepMesh_DataStructureOfDelaun)& myStructure; const Standard_Real myUmin; diff --git a/src/BRepMesh/BRepMesh_WireInterferenceChecker.cxx b/src/BRepMesh/BRepMesh_WireInterferenceChecker.cxx index 78604a955b..3accbd570c 100644 --- a/src/BRepMesh/BRepMesh_WireInterferenceChecker.cxx +++ b/src/BRepMesh/BRepMesh_WireInterferenceChecker.cxx @@ -14,6 +14,7 @@ // commercial license or contractual agreement. #include +#include #include // TODO: remove this variable after implementation of LoopChecker2d. @@ -25,9 +26,9 @@ static const Standard_Real MIN_LOOP_S = 2 * M_PI * 2.E-5; //purpose : //======================================================================= BRepMesh_WireInterferenceChecker::BRepMesh_WireInterferenceChecker( - const std::vector& theWires, - BRepMesh_Status* theStatus, - Standard_Mutex* theMutex) + const std::vector& theWires, + BRepMesh_Status* theStatus, + Standard_Mutex* theMutex) : myWires(&theWires.front()), myWiresNb(theWires.size()), myStatus(theStatus), @@ -70,9 +71,9 @@ void BRepMesh_WireInterferenceChecker::operator ()( if (*myStatus == BRepMesh_SelfIntersectingWire) return; - const BRepMesh_WireChecker::SegmentsTree& aWireSegTree1 = myWires[theWireId]; - const BRepMesh_WireChecker::Segment* aWireSegments1 = &aWireSegTree1.first->front(); - const BRepMesh_WireChecker::HBndBox2dTree& aWireBoxTree1 = aWireSegTree1.second; + const BRepMeshCol::SegmentsTree& aWireSegTree1 = myWires[theWireId]; + const BRepMeshCol::Segment* aWireSegments1 = &aWireSegTree1.first->front(); + const BRepMeshCol::HBndBox2dTree& aWireBoxTree1 = aWireSegTree1.second; const Standard_Integer aWireLen1 = aWireSegTree1.first->size(); for (Standard_Integer aWireIt = theWireId; aWireIt < myWiresNb; ++aWireIt) @@ -84,11 +85,11 @@ void BRepMesh_WireInterferenceChecker::operator ()( #endif const Standard_Boolean isSelfIntCheck = (aWireIt == theWireId); - const BRepMesh_WireChecker::SegmentsTree& aWireSegTree2 = + const BRepMeshCol::SegmentsTree& aWireSegTree2 = isSelfIntCheck ? aWireSegTree1 : myWires[aWireIt]; - const BRepMesh_WireChecker::Segment* aWireSegments2 = &aWireSegTree2.first->front(); - const BRepMesh_WireChecker::HBndBox2dTree& aWireBoxTree2 = aWireSegTree2.second; + const BRepMeshCol::Segment* aWireSegments2 = &aWireSegTree2.first->front(); + const BRepMeshCol::HBndBox2dTree& aWireBoxTree2 = aWireSegTree2.second; BRepMesh_WireChecker::BndBox2dTreeSelector aSelector(aWireSegTree2.first->size()); for (Standard_Integer aSegmentId1 = 0; aSegmentId1 < aWireLen1; ++aSegmentId1) @@ -107,8 +108,8 @@ void BRepMesh_WireInterferenceChecker::operator ()( if (aWireBoxTree2->Select(aSelector) == 0) continue; - const BRepMesh_WireChecker::Segment& aSegment1 = aWireSegments1[aSegmentId1]; - const BRepMesh_WireChecker::ArrayOfInteger& aSelected = aSelector.Indices(); + const BRepMeshCol::Segment& aSegment1 = aWireSegments1[aSegmentId1]; + const BRepMeshCol::Array1OfInteger& aSelected = aSelector.Indices(); const Standard_Integer aSelectedNb = aSelector.IndicesNb(); for (Standard_Integer aBndIt = 0; aBndIt < aSelectedNb; ++aBndIt) { @@ -119,16 +120,16 @@ void BRepMesh_WireInterferenceChecker::operator ()( #endif const Standard_Integer aSegmentId2 = aSelected(aBndIt); - const BRepMesh_WireChecker::Segment& aSegment2 = aWireSegments2[aSegmentId2]; + const BRepMeshCol::Segment& aSegment2 = aWireSegments2[aSegmentId2]; gp_Pnt2d aIntPnt; - BRepMesh_WireInterferenceChecker::IntFlag aIntStatus = Intersect( + BRepMesh_GeomTool::IntFlag aIntStatus = BRepMesh_GeomTool::IntSegSeg( aSegment1.StartPnt, aSegment1.EndPnt, aSegment2.StartPnt, aSegment2.EndPnt, Standard_False, Standard_False, aIntPnt); - if (aIntStatus == Cross) + if (aIntStatus == BRepMesh_GeomTool::Cross) { // TODO: remove this block after implementation of LoopChecker2d. if (isSelfIntCheck) @@ -138,7 +139,7 @@ void BRepMesh_WireInterferenceChecker::operator ()( const gp_XY& aRefPnt = aIntPnt.Coord(); for (Standard_Integer i = aSegmentId1; i < aSegmentId2; ++i) { - const BRepMesh_WireChecker::Segment& aSeg = aWireSegments1[i]; + const BRepMeshCol::Segment& aSeg = aWireSegments1[i]; gp_XY aCurVec = aSeg.EndPnt - aRefPnt; if (aCurVec.SquareModulus() < gp::Resolution()) @@ -164,182 +165,3 @@ void BRepMesh_WireInterferenceChecker::operator ()( } } } - -//============================================================================= -//function : Intersect -//purpose : -//============================================================================= -BRepMesh_WireInterferenceChecker::IntFlag - BRepMesh_WireInterferenceChecker::Intersect( - const gp_XY& theStartPnt1, - const gp_XY& theEndPnt1, - const gp_XY& theStartPnt2, - const gp_XY& theEndPnt2, - const Standard_Boolean isConsiderEndPointTouch, - const Standard_Boolean isConsiderPointOnSegment, - gp_Pnt2d& theIntPnt) -{ - Standard_Integer aPointHash[] = { - classifyPoint(theStartPnt1, theEndPnt1, theStartPnt2), - classifyPoint(theStartPnt1, theEndPnt1, theEndPnt2 ), - classifyPoint(theStartPnt2, theEndPnt2, theStartPnt1), - classifyPoint(theStartPnt2, theEndPnt2, theEndPnt1 ) - }; - - // Consider case when edges have shared vertex - if ( isConsiderEndPointTouch ) - { - if ( aPointHash[0] < 0 || aPointHash[1] < 0 ) - return BRepMesh_WireInterferenceChecker::EndPointTouch; - } - - Standard_Integer aPosHash = - aPointHash[0] + aPointHash[1] + aPointHash[2] + aPointHash[3]; - - /*=========================================*/ - /* 1) hash code == 1: - - 0+ - / - 0 1/ 0 - +======+==========+ - - 2) hash code == 2: - - 0 1 1 0 - a) +----+========+---+ - - 0 1 1 0 - b) +-------+===+=====+ - - */ - /*=========================================*/ - if ( aPosHash == 1 ) - { - if (isConsiderPointOnSegment) - { - if (aPointHash[0] == 1) - theIntPnt = theStartPnt1; - else if (aPointHash[1] == 1) - theIntPnt = theEndPnt1; - else if (aPointHash[2] == 1) - theIntPnt = theStartPnt2; - else - theIntPnt = theEndPnt2; - - return BRepMesh_WireInterferenceChecker::PointOnSegment; - } - - return BRepMesh_WireInterferenceChecker::NoIntersection; - } - else if ( aPosHash == 2 ) - return BRepMesh_WireInterferenceChecker::Glued; - - gp_XY aVec1 = theEndPnt1 - theStartPnt1; - gp_XY aVec2 = theEndPnt2 - theStartPnt2; - gp_XY aVecStartPoints = theStartPnt2 - theStartPnt1; - - Standard_Real aCrossD1D2 = aVec1 ^ aVec2; - Standard_Real aCrossD1D3 = aVecStartPoints ^ aVec2; - - const Standard_Real aPrec = Precision::PConfusion(); - // Are edgegs codirectional - if ( Abs( aCrossD1D2 ) < aPrec ) - { - // Just a parallel case? - if( Abs( aCrossD1D3 ) < aPrec ) - { - /*=========================================*/ - /* Here the following cases are possible: - 1) hash code == -4: - - -1 -1 - +=================+ - -1 -1 - - 2) hash code == -2: - - 0 -1 0 - +--------+========+ - -1 - - 3) hash code == -1: - - 0 1 -1 - +--------+========+ - -1 - - 4) hash code == 0: - - 0 0 0 0 - +------+ +=======+ - 0 0 0 0 - */ - /*=========================================*/ - - if ( aPosHash < -2 ) - return BRepMesh_WireInterferenceChecker::Same; - else if ( aPosHash == -1 ) - return BRepMesh_WireInterferenceChecker::Glued; - - return BRepMesh_WireInterferenceChecker::NoIntersection; - } - else - return BRepMesh_WireInterferenceChecker::NoIntersection; - } - - Standard_Real aPar = aCrossD1D3 / aCrossD1D2; - const Standard_Real aEndPrec = 1 - aPrec; - - // Intersection is out of first segment range - if( aPar < aPrec || aPar > aEndPrec ) - return BRepMesh_WireInterferenceChecker::NoIntersection; - - Standard_Real aCrossD2D3 = aVecStartPoints.Reversed() ^ aVec1; - aPar = aCrossD2D3 / -aCrossD1D2; - - // Intersection is out of second segment range - if( aPar < aPrec || aPar > aEndPrec ) - return BRepMesh_WireInterferenceChecker::NoIntersection; - - theIntPnt = theStartPnt2 + aPar * aVec2; - return BRepMesh_WireInterferenceChecker::Cross; -} - -//============================================================================= -//function : classifyPoint -//purpose : -//============================================================================= -Standard_Integer BRepMesh_WireInterferenceChecker::classifyPoint( - const gp_XY& thePoint1, - const gp_XY& thePoint2, - const gp_XY& thePointToCheck) -{ - gp_XY aP1 = thePoint2 - thePoint1; - gp_XY aP2 = thePointToCheck - thePoint1; - - const Standard_Real aPrec = Precision::PConfusion(); - const Standard_Real aSqPrec = aPrec * aPrec; - Standard_Real aDist = Abs(aP1 ^ aP2); - if (aDist > aPrec) - { - aDist = (aDist * aDist) / aP1.SquareModulus(); - if (aDist > aSqPrec) - return 0; //out - } - - gp_XY aMult = aP1.Multiplied(aP2); - if ( aMult.X() < 0.0 || aMult.Y() < 0.0 ) - return 0; //out - - if (aP1.SquareModulus() < aP2.SquareModulus()) - return 0; //out - - if (thePointToCheck.IsEqual(thePoint1, aPrec) || - thePointToCheck.IsEqual(thePoint2, aPrec)) - { - return -1; //coinsides with an end point - } - - return 1; -} diff --git a/src/BRepMesh/BRepMesh_WireInterferenceChecker.hxx b/src/BRepMesh/BRepMesh_WireInterferenceChecker.hxx index 430e83c9b9..a4458480f9 100644 --- a/src/BRepMesh/BRepMesh_WireInterferenceChecker.hxx +++ b/src/BRepMesh/BRepMesh_WireInterferenceChecker.hxx @@ -49,9 +49,9 @@ public: //! \param theStatus shared flag to set status of the check. //! \param theMutex shared mutex for parallel processing. BRepMesh_WireInterferenceChecker( - const std::vector& theWires, - BRepMesh_Status* theStatus, - Standard_Mutex* theMutex); + const std::vector& theWires, + BRepMesh_Status* theStatus, + Standard_Mutex* theMutex); //! Checker's body. //! \param theWireRange range of wires to be checked. @@ -69,27 +69,6 @@ public: //! \param theWireId Id of discretized wire to be checked. void operator ()(const Standard_Integer& theWireId) const; - //! Checks intersection between the two segments. - //! \param theStartPnt1 start point of first segment. - //! \param theEndPnt1 end point of first segment. - //! \param theStartPnt2 start point of second segment. - //! \param theEndPnt2 end point of second segment. - //! \param isConsiderEndPointTouch if TRUE EndPointTouch status will be - //! returned in case if segments are touching by end points, if FALSE - //! returns NoIntersection flag. - //! \param isConsiderPointOnSegment if TRUE PointOnSegment status will be - //! returned in case if end point of one segment lies onto another one, - //! if FALSE returns NoIntersection flag. - //! \param[out] theIntPnt point of intersection. - //! \return status of intersection check. - static IntFlag Intersect(const gp_XY& theStartPnt1, - const gp_XY& theEndPnt1, - const gp_XY& theStartPnt2, - const gp_XY& theEndPnt2, - const Standard_Boolean isConsiderEndPointTouch, - const Standard_Boolean isConsiderPointOnSegment, - gp_Pnt2d& theIntPnt); - private: //! Classifies the point in case of coincidence of two vectors. @@ -102,12 +81,12 @@ private: const gp_XY& thePoint2, const gp_XY& thePointToCheck); private: - const BRepMesh_WireChecker::SegmentsTree* myWires; - Standard_Integer myWiresNb; - BRepMesh_Status* myStatus; + const BRepMeshCol::SegmentsTree* myWires; + Standard_Integer myWiresNb; + BRepMesh_Status* myStatus; #ifdef HAVE_TBB - Standard_Mutex* myMutex; + Standard_Mutex* myMutex; #endif }; diff --git a/src/BRepMesh/FILES b/src/BRepMesh/FILES index 43aeb4833b..7d36164fac 100755 --- a/src/BRepMesh/FILES +++ b/src/BRepMesh/FILES @@ -1,31 +1,50 @@ BRepMesh_PluginEntryType.hxx BRepMesh_PluginMacro.hxx +BRepMesh_DegreeOfFreedom.hxx +BRepMesh_FactoryError.hxx +BRepMesh_Vertex.hxx +BRepMesh_Edge.hxx BRepMesh_Triangle.hxx -BRepMesh_Triangle.cxx +BRepMesh_Circle.hxx BRepMesh_Classifier.hxx BRepMesh_Classifier.cxx -BRepMesh_ClassifierPtr.hxx BRepMesh_WireInterferenceChecker.hxx BRepMesh_WireInterferenceChecker.cxx BRepMesh_WireChecker.hxx BRepMesh_WireChecker.cxx -BRepMesh_CellFilter.hxx +BRepMesh_DiscretRoot.hxx +BRepMesh_DiscretRoot.cxx +BRepMesh_DiscretFactory.hxx +BRepMesh_DiscretFactory.cxx +BRepMesh_Collections.hxx +BRepMesh_DataStructureOfDelaun.hxx +BRepMesh_DataStructureOfDelaun.cxx +BRepMesh_CircleTool.hxx +BRepMesh_CircleTool.cxx +BRepMesh_VertexTool.hxx +BRepMesh_VertexTool.cxx +BRepMesh_ShapeTool.hxx +BRepMesh_ShapeTool.cxx BRepMesh_Delaun.hxx BRepMesh_Delaun.cxx BRepMesh_CircleInspector.hxx -BRepMesh_MapOfIntegerInteger.hxx -BRepMesh_MapOfInteger.hxx -BRepMesh_ListOfInteger.hxx -BRepMesh_BaseAllocator.hxx BRepMesh_PairOfIndex.hxx BRepMesh_Status.hxx BRepMesh_CMPLRS.edl -BRepMesh_VertexCellFilter.hxx BRepMesh_VertexInspector.hxx -BRepMesh_VertexInspector.cxx -BRepMesh_VectorOfVertex.hxx BRepMesh_EdgeChecker.hxx BRepMesh_FaceChecker.hxx +BRepMesh_SelectorOfDataStructureOfDelaun.hxx +BRepMesh_SelectorOfDataStructureOfDelaun.cxx +BRepMesh_FastDiscretFace.hxx +BRepMesh_FastDiscretFace.cxx +BRepMesh_FastDiscret.hxx +BRepMesh_FastDiscret.cxx +BRepMesh_FaceAttribute.hxx +BRepMesh_FaceAttribute.cxx BRepMesh_IncrementalMesh.hxx BRepMesh_IncrementalMesh.cxx +BRepMesh_GeomTool.hxx +BRepMesh_GeomTool.cxx +BRepMesh_PairOfPolygon.hxx EXTERNLIB diff --git a/src/DBRep/DBRep_DrawableShape.cxx b/src/DBRep/DBRep_DrawableShape.cxx index 39af8e678c..c4d08336f7 100644 --- a/src/DBRep/DBRep_DrawableShape.cxx +++ b/src/DBRep/DBRep_DrawableShape.cxx @@ -842,7 +842,7 @@ void DBRep_DrawableShape::DisplayHiddenLines(Draw_Display& dis) if (!strcmp(dout.GetType(id),"PERS")) focal = dout.Focal(id); Standard_Real Ang,Def; HLRBRep::PolyHLRAngleAndDeflection(myAng,Ang,Def); - BRepMesh_IncrementalMesh MESH(myShape,Def,Standard_True,Ang); + BRepMesh_IncrementalMesh MESH(myShape, Def, Ang, Standard_True); Standard_Boolean recompute = Standard_True; // find if the view must be recomputed DBRep_ListIteratorOfListOfHideData it(myHidData); diff --git a/src/MeshTest/FILES b/src/MeshTest/FILES index 59c2700e8e..8c508e83a0 100755 --- a/src/MeshTest/FILES +++ b/src/MeshTest/FILES @@ -1,3 +1,5 @@ MeshTest_PluginCommands.cxx MeshTest_CheckTopology.cxx MeshTest_CheckTopology.hxx +MeshTest_DrawableMesh.cxx +MeshTest_DrawableMesh.hxx diff --git a/src/MeshTest/MeshTest.cdl b/src/MeshTest/MeshTest.cdl index 350ce6d9ab..3cc524a783 100644 --- a/src/MeshTest/MeshTest.cdl +++ b/src/MeshTest/MeshTest.cdl @@ -26,9 +26,7 @@ uses is - class DrawableMesh; - ---Purpose: Provides a mesh object inherited from Drawable3d - -- to draw a triangulation. + imported DrawableMesh from MeshTest; Commands(DI : in out Interpretor from Draw); ---Purpose: Defines meshing commands diff --git a/src/MeshTest/MeshTest.cxx b/src/MeshTest/MeshTest.cxx index 37f0428997..2810bda2aa 100644 --- a/src/MeshTest/MeshTest.cxx +++ b/src/MeshTest/MeshTest.cxx @@ -42,7 +42,6 @@ #include #include #include -#include #include #include #include @@ -141,7 +140,7 @@ static Standard_Integer incrementalmesh(Draw_Interpretor& di, Standard_Integer n di << "Incremental Mesh, multi-threading " << (isInParallel ? "ON\n" : "OFF\n"); - BRepMesh_IncrementalMesh MESH(aShape, aDeflection, Standard_False, 0.5, isInParallel); + BRepMesh_IncrementalMesh MESH(aShape, aDeflection, 0.5, Standard_False, isInParallel); Standard_Integer statusFlags = MESH.GetStatusFlags(); di << "Meshing statuses: "; @@ -564,9 +563,9 @@ static Standard_Integer vertices (Draw_Interpretor&, Standard_Integer n, const c // the faces for (ex.Init(S,TopAbs_FACE);ex.More();ex.Next()) { - BRepMesh_MapOfInteger vtx; + BRepMeshCol::MapOfInteger vtx; M->VerticesOfDomain(vtx); - for (BRepMesh_MapOfInteger::Iterator it(vtx); it.More(); it.Next()) + for (BRepMeshCol::MapOfInteger::Iterator it(vtx); it.More(); it.Next()) vseq.Append(it.Key()); } diff --git a/src/MeshTest/MeshTest_DrawableMesh.cdl b/src/MeshTest/MeshTest_DrawableMesh.cdl deleted file mode 100644 index 75a1c30ce5..0000000000 --- a/src/MeshTest/MeshTest_DrawableMesh.cdl +++ /dev/null @@ -1,82 +0,0 @@ --- Created on: 1994-08-03 --- Created by: Modeling --- Copyright (c) 1994-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. - -class DrawableMesh from MeshTest inherits Drawable3D from Draw - - ---Purpose: A drawable mesh. It contains a sequence of - -- highlighted edges and highlighted vertices. - -uses - Display from Draw, - Interpretor from Draw, - Shape from TopoDS, - FastDiscret from BRepMesh, - SequenceOfInteger from TColStd - -is - - Create returns DrawableMesh from MeshTest; - - Create(S : Shape from TopoDS; Deflect : Real; - Partage : Boolean; InShape: Boolean from Standard= Standard_False) - returns DrawableMesh from MeshTest; - - - Create(Tr: FastDiscret from BRepMesh) - returns DrawableMesh from MeshTest; - - AddInShape(me: mutable; inshape: Boolean) - is static; - - Add(me : mutable; S : Shape from TopoDS) - is static; - - Edges(me : mutable) returns SequenceOfInteger from TColStd - ---C++: return & - is static; - - Vertices(me : mutable) returns SequenceOfInteger from TColStd - ---C++: return & - is static; - - Triangles(me : mutable) returns SequenceOfInteger from TColStd - ---C++: return & - is static; - - DrawOn(me; dis : in out Display from Draw); - - Copy(me) returns Drawable3D from Draw - is redefined; - - Dump(me; S : in out OStream) - is redefined; - - Whatis(me; S : in out Interpretor from Draw) - is redefined; - - Mesh(me) returns FastDiscret from BRepMesh - is static; - -fields - - myMesh : FastDiscret from BRepMesh; - myDeflection : Real; - myEdges : SequenceOfInteger from TColStd; - myVertices : SequenceOfInteger from TColStd; - myTriangles : SequenceOfInteger from TColStd; - myinshape : Boolean from Standard; - -end DrawableMesh; diff --git a/src/MeshTest/MeshTest_DrawableMesh.cxx b/src/MeshTest/MeshTest_DrawableMesh.cxx index 82d37ac508..75f7ad88f8 100644 --- a/src/MeshTest/MeshTest_DrawableMesh.cxx +++ b/src/MeshTest/MeshTest_DrawableMesh.cxx @@ -14,7 +14,7 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include +#include #include #include #include @@ -29,6 +29,9 @@ #include #include +IMPLEMENT_STANDARD_HANDLE (MeshTest_DrawableMesh, Draw_Drawable3D) +IMPLEMENT_STANDARD_RTTIEXT(MeshTest_DrawableMesh, Draw_Drawable3D) + //======================================================================= //function : MeshTest_DrawableMesh //purpose : @@ -53,7 +56,7 @@ myDeflection(Deflect), myinshape(inshape) Bnd_Box B; BRepBndLib::Add(S, B); - myMesh = new BRepMesh_FastDiscret(Deflect, S, B, 0.5, Partage, inshape); + myMesh = new BRepMesh_FastDiscret(S, Deflect, 0.5, B, Partage, inshape); } @@ -80,7 +83,7 @@ void MeshTest_DrawableMesh::Add(const TopoDS_Shape& S) BRepBndLib::Add(S, B); if (myMesh.IsNull()) - myMesh=new BRepMesh_FastDiscret(myDeflection, S, B, 0.5, myinshape); + myMesh=new BRepMesh_FastDiscret(S, myDeflection, 0.5, B, myinshape); else myMesh->Perform(S); } diff --git a/src/MeshTest/MeshTest_DrawableMesh.hxx b/src/MeshTest/MeshTest_DrawableMesh.hxx new file mode 100644 index 0000000000..85bb3ed6da --- /dev/null +++ b/src/MeshTest/MeshTest_DrawableMesh.hxx @@ -0,0 +1,78 @@ +// Copyright (c) 2013-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. + +#ifndef _MeshTest_DrawableMesh_HeaderFile +#define _MeshTest_DrawableMesh_HeaderFile + +#include +#include +#include +#include +#include +#include +#include +#include + +class TopoDS_Shape; +class TColStd_SequenceOfInteger; +class Draw_Display; +class Draw_Drawable3D; + +//! A drawable mesh. +//! Provides a mesh object inherited from Drawable3d to draw a triangulation. +//! It contains a sequence of highlighted edges and highlighted vertices.
+class MeshTest_DrawableMesh : public Draw_Drawable3D +{ +public: + + Standard_EXPORT MeshTest_DrawableMesh(); + + Standard_EXPORT MeshTest_DrawableMesh(const TopoDS_Shape& S,const Standard_Real Deflect,const Standard_Boolean Partage,const Standard_Boolean InShape = Standard_False); + + Standard_EXPORT MeshTest_DrawableMesh(const Handle(BRepMesh_FastDiscret)& Tr); + + Standard_EXPORT void AddInShape(const Standard_Boolean inshape) ; + + Standard_EXPORT void Add(const TopoDS_Shape& S) ; + + Standard_EXPORT TColStd_SequenceOfInteger& Edges() ; + + Standard_EXPORT TColStd_SequenceOfInteger& Vertices() ; + + Standard_EXPORT TColStd_SequenceOfInteger& Triangles() ; + + Standard_EXPORT void DrawOn(Draw_Display& dis) const; + + Standard_EXPORT virtual Handle_Draw_Drawable3D Copy() const; + + Standard_EXPORT virtual void Dump(Standard_OStream& S) const; + + Standard_EXPORT virtual void Whatis(Draw_Interpretor& S) const; + + Standard_EXPORT Handle(BRepMesh_FastDiscret) Mesh() const; + + DEFINE_STANDARD_RTTI(MeshTest_DrawableMesh) + +private: + + Handle(BRepMesh_FastDiscret) myMesh; + Standard_Real myDeflection; + TColStd_SequenceOfInteger myEdges; + TColStd_SequenceOfInteger myVertices; + TColStd_SequenceOfInteger myTriangles; + Standard_Boolean myinshape; +}; + +DEFINE_STANDARD_HANDLE(MeshTest_DrawableMesh, Draw_Drawable3D) + +#endif diff --git a/src/QABugs/QABugs_11.cxx b/src/QABugs/QABugs_11.cxx index f962a08d65..0be433d9ef 100644 --- a/src/QABugs/QABugs_11.cxx +++ b/src/QABugs/QABugs_11.cxx @@ -1348,7 +1348,7 @@ static Standard_Integer OCC369(Draw_Interpretor& di, Standard_Integer argc, cons if(aShape.IsNull()) {di << "OCC369 FAULTY. Entry shape is NULL \n"; return 0;} // 3. Build mesh - BRepMesh_IncrementalMesh aMesh(aShape, 0.2, Standard_True, M_PI/6); + BRepMesh_IncrementalMesh aMesh(aShape, 0.2, M_PI/6, Standard_True); } catch (Standard_Failure) {di << "OCC369 Exception \n" ;return 0;} @@ -3194,7 +3194,7 @@ Standard_Integer OCC14376(Draw_Interpretor& di, Standard_Integer argc, const cha } di<<"deflection="<< aDeflection << "\n"; - BRepMesh_IncrementalMesh aIMesh(aShape, aDeflection, Standard_False, M_PI/9.); + BRepMesh_IncrementalMesh aIMesh(aShape, aDeflection, M_PI/9., Standard_False); TopLoc_Location aLocation; Handle(Poly_Triangulation) aTriang = BRep_Tool::Triangulation(TopoDS::Face(aShape), aLocation); diff --git a/src/StdPrs/FILES b/src/StdPrs/FILES index abbc10bbd9..1d07877fc4 100644 --- a/src/StdPrs/FILES +++ b/src/StdPrs/FILES @@ -1,3 +1,5 @@ +StdPrs_ToolShadedShape.hxx +StdPrs_ToolShadedShape.cxx StdPrs_HLRShape.hxx StdPrs_HLRShape.cxx StdPrs_Point.hxx diff --git a/src/StdPrs/StdPrs.cdl b/src/StdPrs/StdPrs.cdl index dcbde7117b..7f11d3e77e 100644 --- a/src/StdPrs/StdPrs.cdl +++ b/src/StdPrs/StdPrs.cdl @@ -53,7 +53,7 @@ is class ToolVertex; class ToolRFace; class HLRToolShape; - class ToolShadedShape; + imported ToolShadedShape from StdPrs; class ShadedShape; class PoleCurve; diff --git a/src/StdPrs/StdPrs_HLRPolyShape.cxx b/src/StdPrs/StdPrs_HLRPolyShape.cxx index cddcff878a..e499af7c0a 100644 --- a/src/StdPrs/StdPrs_HLRPolyShape.cxx +++ b/src/StdPrs/StdPrs_HLRPolyShape.cxx @@ -66,7 +66,7 @@ void StdPrs_HLRPolyShape::Add(const Handle (Prs3d_Presentation)& aPresentation, const Standard_Boolean rel = aDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE; Standard_Real def = rel? aDrawer->HLRDeviationCoefficient() : aDrawer->MaximalChordialDeviation(); - BRepMesh_IncrementalMesh mesh(aShape, def, rel, aDrawer->HLRAngle()); + BRepMesh_IncrementalMesh mesh(aShape, def, aDrawer->HLRAngle(), rel); Handle(HLRBRep_PolyAlgo) hider = new HLRBRep_PolyAlgo(aShape); diff --git a/src/StdPrs/StdPrs_ShadedShape.cxx b/src/StdPrs/StdPrs_ShadedShape.cxx index 6834543791..64b29a4707 100644 --- a/src/StdPrs/StdPrs_ShadedShape.cxx +++ b/src/StdPrs/StdPrs_ShadedShape.cxx @@ -41,6 +41,8 @@ #include #include #include +#include +#include #include #include #include @@ -132,11 +134,11 @@ namespace // Precision for compare square distances const Standard_Real aPreci = Precision::SquareConfusion(); - StdPrs_ToolShadedShape aShapeTool; - for (aShapeTool.Init (theShape); aShapeTool.MoreFace(); aShapeTool.NextFace()) + TopExp_Explorer aFaceIt(theShape, TopAbs_FACE); + for (; aFaceIt.More(); aFaceIt.Next()) { - const TopoDS_Face& aFace = aShapeTool.CurrentFace(); - aT = aShapeTool.Triangulation (aFace, aLoc); + const TopoDS_Face& aFace = TopoDS::Face(aFaceIt.Current()); + aT = StdPrs_ToolShadedShape::Triangulation (aFace, aLoc); if (!aT.IsNull()) { aNbTriangles += aT->NbTriangles(); @@ -151,10 +153,10 @@ namespace Handle(Graphic3d_ArrayOfTriangles) anArray = new Graphic3d_ArrayOfTriangles (aNbVertices, 3 * aNbTriangles, Standard_True, Standard_False, theHasTexels); Standard_Real aUmin (0.0), aUmax (0.0), aVmin (0.0), aVmax (0.0), dUmax (0.0), dVmax (0.0); - for (aShapeTool.Init (theShape); aShapeTool.MoreFace(); aShapeTool.NextFace()) + for (aFaceIt.Init (theShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next()) { - const TopoDS_Face& aFace = aShapeTool.CurrentFace(); - aT = aShapeTool.Triangulation (aFace, aLoc); + const TopoDS_Face& aFace = TopoDS::Face(aFaceIt.Current()); + aT = StdPrs_ToolShadedShape::Triangulation (aFace, aLoc); if (aT.IsNull()) { continue; @@ -165,7 +167,7 @@ namespace const TColgp_Array1OfPnt& aNodes = aT->Nodes(); const TColgp_Array1OfPnt2d& aUVNodes = aT->UVNodes(); TColgp_Array1OfDir aNormals (aNodes.Lower(), aNodes.Upper()); - aShapeTool.Normal (aFace, aPolyConnect, aNormals); + StdPrs_ToolShadedShape::Normal (aFace, aPolyConnect, aNormals); if (theHasTexels) { @@ -201,7 +203,7 @@ namespace Standard_Integer anIndex[3]; for (Standard_Integer aTriIter = 1; aTriIter <= aT->NbTriangles(); ++aTriIter) { - if (aShapeTool.Orientation (aFace) == TopAbs_REVERSED) + if (aFace.Orientation() == TopAbs_REVERSED) { aTriangles (aTriIter).Get (anIndex[0], anIndex[2], anIndex[1]); } diff --git a/src/StdPrs/StdPrs_ToolShadedShape.cdl b/src/StdPrs/StdPrs_ToolShadedShape.cdl deleted file mode 100644 index c1f391d4a9..0000000000 --- a/src/StdPrs/StdPrs_ToolShadedShape.cdl +++ /dev/null @@ -1,40 +0,0 @@ --- Created on: 1993-10-27 --- Created by: Jean-Louis FRENKEL --- Copyright (c) 1993-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. - -class ToolShadedShape from StdPrs inherits ShapeTool from BRepMesh - -uses - Shape from TopoDS, - Face from TopoDS, - Array1OfDir from TColgp, - Connect from Poly, - Triangulation from Poly, - Location from TopLoc -is - - IsClosed (myclass; theShape : Shape from TopoDS) returns Boolean from Standard; - ---Purpose: Checks back faces visibility for specified shape (to activate back-face culling). - -- @return true if shape is closed Solid or compound of closed Solids. - - Triangulation(myclass; aFace: Face from TopoDS; - loc : out Location from TopLoc) - returns Triangulation from Poly; - - Normal(myclass; aFace: Face from TopoDS; - PC : in out Connect from Poly; - Nor : out Array1OfDir from TColgp); - -end ToolShadedShape from StdPrs; diff --git a/src/StdPrs/StdPrs_ToolShadedShape.cxx b/src/StdPrs/StdPrs_ToolShadedShape.cxx index c9c3a93123..b1179c2d11 100644 --- a/src/StdPrs/StdPrs_ToolShadedShape.cxx +++ b/src/StdPrs/StdPrs_ToolShadedShape.cxx @@ -14,7 +14,7 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include +#include #include #include @@ -31,6 +31,9 @@ #include #include #include +#include +#include +#include namespace { diff --git a/src/StdPrs/StdPrs_ToolShadedShape.hxx b/src/StdPrs/StdPrs_ToolShadedShape.hxx new file mode 100644 index 0000000000..be0ae3272f --- /dev/null +++ b/src/StdPrs/StdPrs_ToolShadedShape.hxx @@ -0,0 +1,47 @@ +// Copyright (c) 2013 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 _StdPrs_ToolShadedShape_HeaderFile +#define _StdPrs_ToolShadedShape_HeaderFile + +#include +#include +#include +#include + +class TopoDS_Shape; +class Poly_Triangulation; +class TopoDS_Face; +class TopLoc_Location; +class Poly_Connect; +class TColgp_Array1OfDir; + +class StdPrs_ToolShadedShape +{ +public: + + DEFINE_STANDARD_ALLOC + + //! Checks back faces visibility for specified shape (to activate back-face culling).
+ //! @return true if shape is closed Solid or compound of closed Solids.
+ static Standard_Boolean IsClosed(const TopoDS_Shape& theShape); + + static Handle_Poly_Triangulation Triangulation(const TopoDS_Face& aFace, + TopLoc_Location& loc); + + static void Normal(const TopoDS_Face& aFace, + Poly_Connect& PC, + TColgp_Array1OfDir& Nor); +}; + +#endif diff --git a/src/StdSelect/StdSelect_BRepSelectionTool.cxx b/src/StdSelect/StdSelect_BRepSelectionTool.cxx index c981be3e3f..e608e82f61 100644 --- a/src/StdSelect/StdSelect_BRepSelectionTool.cxx +++ b/src/StdSelect/StdSelect_BRepSelectionTool.cxx @@ -80,7 +80,7 @@ void StdSelect_BRepSelectionTool if( isAutoTriangulation && !BRepTools::Triangulation (theShape, Precision::Infinite()) ) { - BRepMesh_IncrementalMesh aMesher(theShape, theDeflection, Standard_False, theDeviationAngle); + BRepMesh_IncrementalMesh aMesher(theShape, theDeflection, theDeviationAngle, Standard_False); } Handle(StdSelect_BRepOwner) aBrepOwner; diff --git a/src/StlTransfer/StlTransfer.cxx b/src/StlTransfer/StlTransfer.cxx index bd1da2c240..131d2372f7 100644 --- a/src/StlTransfer/StlTransfer.cxx +++ b/src/StlTransfer/StlTransfer.cxx @@ -117,7 +117,7 @@ void StlTransfer::BuildIncrementalMesh (const TopoDS_Shape& Shape, Standard_ConstructionError::Raise ("StlTransfer::BuildIncrementalMesh"); } - BRepMesh_IncrementalMesh aMesher(Shape, Deflection, Standard_False, 0.5, InParallel); + BRepMesh_IncrementalMesh aMesher(Shape, Deflection, 0.5, Standard_False, InParallel); for (TopExp_Explorer itf(Shape,TopAbs_FACE); itf.More(); itf.Next()) { TopoDS_Face face = TopoDS::Face(itf.Current()); TopLoc_Location Loc, loc; diff --git a/src/Voxel/Voxel_FastConverter.cxx b/src/Voxel/Voxel_FastConverter.cxx index 0b71151ef8..2656072d5b 100644 --- a/src/Voxel/Voxel_FastConverter.cxx +++ b/src/Voxel/Voxel_FastConverter.cxx @@ -18,7 +18,6 @@ #include #include #include -#include #include #include @@ -31,6 +30,7 @@ #include #include #include +#include // Printing the progress in stdout. //#define CONV_DUMP @@ -141,7 +141,7 @@ void Voxel_FastConverter::Init() // Re-create the triangulation. if (triangulate) { - BRepMesh::Mesh(myShape, myDeflection); + BRepMesh_IncrementalMesh(myShape, myDeflection); } // Compute the number of triangles. diff --git a/src/VrmlConverter/VrmlConverter_ShadedShape.cxx b/src/VrmlConverter/VrmlConverter_ShadedShape.cxx index 9adce9e8d0..be90081174 100644 --- a/src/VrmlConverter/VrmlConverter_ShadedShape.cxx +++ b/src/VrmlConverter/VrmlConverter_ShadedShape.cxx @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -52,7 +51,7 @@ #include #include #include - +#include //========================================================================= // function: Add @@ -98,8 +97,11 @@ void VrmlConverter_ShadedShape::Add( Standard_OStream& anOStream, theRequestedDeflection = aDrawer->MaximalChordialDeviation(); } - if (!BRepTools::Triangulation(aShape,theRequestedDeflection)) - BRepMesh::Mesh(aShape,theRequestedDeflection); // computes and save the triangulation in the face. + if (!BRepTools::Triangulation(aShape,theRequestedDeflection)) + { + // computes and save the triangulation in the face. + BRepMesh_IncrementalMesh(aShape,theRequestedDeflection); + } Handle(Poly_Triangulation) T; diff --git a/src/VrmlData/VrmlData_ShapeConvert.cxx b/src/VrmlData/VrmlData_ShapeConvert.cxx index 94e7e50afb..a49e9838bc 100644 --- a/src/VrmlData/VrmlData_ShapeConvert.cxx +++ b/src/VrmlData/VrmlData_ShapeConvert.cxx @@ -165,7 +165,7 @@ void VrmlData_ShapeConvert::Convert (const Standard_Boolean theExtractFaces, isTessellate = Standard_True; if (isTessellate) { // Triangulate the face by the standard OCC mesher - BRepMesh_IncrementalMesh IM (aFace, aDeflection, Standard_False, theDeflAngle); + BRepMesh_IncrementalMesh IM (aFace, aDeflection, theDeflAngle, Standard_False); aTri = BRep_Tool::Triangulation (aFace, aLoc); } if (aTri.IsNull() == Standard_False) { diff --git a/src/XDEDRAW/XDEDRAW_Props.cxx b/src/XDEDRAW/XDEDRAW_Props.cxx index 5fbd9be9d2..ec0f5c3f07 100644 --- a/src/XDEDRAW/XDEDRAW_Props.cxx +++ b/src/XDEDRAW/XDEDRAW_Props.cxx @@ -46,7 +46,6 @@ #include #include #include -#include #include #include #include @@ -150,7 +149,6 @@ static Standard_Real CalculVolume(const TopoDS_Shape& So, Handle (Poly_Triangulation) facing = BRep_Tool::Triangulation(F,L); if(facing.IsNull() || withForce) { -// BRepMesh::Mesh(F, tol); BRepMesh_IncrementalMesh MESH(F, tol); facing = BRep_Tool::Triangulation(F,L); diff --git a/src/XSDRAWSTLVRML/XSDRAWSTLVRML_ToVRML.cxx b/src/XSDRAWSTLVRML/XSDRAWSTLVRML_ToVRML.cxx index b93d578994..0f775e6485 100644 --- a/src/XSDRAWSTLVRML/XSDRAWSTLVRML_ToVRML.cxx +++ b/src/XSDRAWSTLVRML/XSDRAWSTLVRML_ToVRML.cxx @@ -72,26 +72,26 @@ Standard_Boolean XSDRAWSTLVRML_ToVRML::Write { // Creates facets from the shape -// Create (defle : Real from Standard; -// shape : Shape from TopoDS; -// angl : Real from Standard= 0.17; -// withShare : Boolean from Standard=Standard_True; -// inshape : Boolean from Standard=Standard_False; -// relative : Boolean from Standard=Standard_False; -// shapetrigu: Boolean from Standard=Standard_False) -// returns mutable Discret from BRepMesh; +// Create (defle : Real from Standard; +// shape : Shape from TopoDS; +// angl : Real from Standard= 0.17; +// withShare : Boolean from Standard=Standard_True; +// inshape : Boolean from Standard=Standard_False; +// relative : Boolean from Standard=Standard_False; +// shapetrigu: Boolean from Standard=Standard_False) +// returns mutable Discret from BRepMesh; Bnd_Box B; BRepBndLib::Add(aShape, B); - Handle(BRepMesh_FastDiscret) TheDiscret = - new BRepMesh_FastDiscret(myDeflection, - aShape, - B, - 0.17, - Standard_True, - Standard_False, - Standard_True, - Standard_True); + Handle(BRepMesh_FastDiscret) TheDiscret = + new BRepMesh_FastDiscret(aShape, + myDeflection, + 0.17, + B, + Standard_True, + Standard_False, + Standard_True, + Standard_True); Standard_Integer i,j; @@ -111,7 +111,7 @@ Standard_Boolean XSDRAWSTLVRML_ToVRML::Write TheFileOut << " material Material { " << endl; TheFileOut << " diffuseColor " << myDiffuseColorRed << " " << myDiffuseColorGreen << " " << myDiffuseColorBlue << " " << endl; TheFileOut << " emissiveColor " << myEmissiveColorRed << " " - << myEmissiveColorGreen << " " << myEmissiveColorBlue << " " << endl; + << myEmissiveColorGreen << " " << myEmissiveColorBlue << " " << endl; TheFileOut << " transparency " << myTransparency << endl; TheFileOut << " ambientIntensity " << myAmbientIntensity << " " << endl; TheFileOut << " specularColor " << mySpecularColorRed << " " << mySpecularColorGreen << " " << mySpecularColorBlue << " " << endl; @@ -126,13 +126,13 @@ Standard_Boolean XSDRAWSTLVRML_ToVRML::Write // puts the coordinates of all the vertices using the order // given during the discretisation for (i=1;i<=TheDiscret->NbVertices();i++) - { - gp_Pnt TheVertex=TheDiscret->Pnt(i); - TheFileOut << " " - << TheVertex.Coord().X() << " " - << TheVertex.Coord().Y() << " " - << TheVertex.Coord().Z() << "," << endl; - } + { + gp_Pnt TheVertex=TheDiscret->Pnt(i); + TheFileOut << " " + << TheVertex.Coord().X() << " " + << TheVertex.Coord().Y() << " " + << TheVertex.Coord().Z() << "," << endl; + } TheFileOut << " ]" << endl; TheFileOut << " }" << endl; @@ -140,43 +140,20 @@ Standard_Boolean XSDRAWSTLVRML_ToVRML::Write // retrieves all the triangles in order to draw the facets for (j=1; j <= TheDiscret->NbTriangles(); j++) - { - BRepMesh_Triangle TheTri=TheDiscret->Triangle(j); - Standard_Integer e1,e2,e3,i1,i2,i3; - Standard_Boolean b1,b2,b3; - - TheTri.Edges(e1,e2,e3,b1,b2,b3); - - if (b1) - { - i1 = TheDiscret->Edge(e1).FirstNode()-1; - i2 = TheDiscret->Edge(e1).LastNode()-1; - } - else - { - i2 = TheDiscret->Edge(e1).FirstNode()-1; - i1 = TheDiscret->Edge(e1).LastNode()-1; - } - - if (b2) - { - i3 = TheDiscret->Edge(e2).LastNode()-1; - } - else - { - i3 = TheDiscret->Edge(e2).FirstNode()-1; - } - - TheFileOut << " " << i1 << ", " << i2 << ", " << i3 << ", -1, " << endl; - } + { + Standard_Integer v[3]; + TheDiscret->TriangleNodes(j, v); + + TheFileOut << " " << v[0]-1 << ", " << v[1]-1 << ", " << v[2]-1 << ", -1, " << endl; + } TheFileOut << " ]" << endl; TheFileOut << " solid FALSE" << endl; // it is not a closed solid TheFileOut << " creaseAngle " << myCreaseAngle << " " << endl; // for smooth shading TheFileOut << " }" << endl; TheFileOut << " }" << endl; - TheFileOut << " ]" << endl; - TheFileOut << "} " << endl; + TheFileOut << " ]" << endl; + TheFileOut << "} " << endl; } else return Standard_False; // failure when opening file diff --git a/tests/mesh/data/standard/V4 b/tests/mesh/data/standard/V4 index 93a64fd577..ee1e56fd58 100755 --- a/tests/mesh/data/standard/V4 +++ b/tests/mesh/data/standard/V4 @@ -1,5 +1,5 @@ set TheFileName shading_wrongshape_015.brep set bug_withouttri "OCC22687" -set bug_freenodes "OCC23105" -set nbfreenodes(ALL) 4 +###set bug_freenodes "OCC23105" +###set nbfreenodes(ALL) 4 set nbwithouttri(All) 5