1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0032247: VIS, IVtkOCC_ShapeMesher - allow disabling auto-triangulation behavior

IVtkOCC_Shape now stores Prs3d_Drawer object used by IVtkOCC_ShapeMesher and IVtkOCC_SelectableObject.
IVtkOCC_ShapeMesher::internalBuild() made more consistent to AIS_Shape::Compute() in cleaning/triangulating shape.

Added command ivtkdefaults similar to vdefaults managing triangulation default parameters.
This commit is contained in:
kgv
2021-03-26 12:37:10 +03:00
committed by bugmaster
parent bbc5899a8c
commit 3483c64453
22 changed files with 433 additions and 394 deletions

View File

@@ -18,6 +18,7 @@
#include <AIS_Shape.hxx>
#include <BRepBndLib.hxx>
#include <Message.hxx>
#include <StdPrs_ToolTriangulatedShape.hxx>
#include <Select3D_SensitiveBox.hxx>
#include <SelectMgr_Selection.hxx>
#include <Standard_ErrorHandler.hxx>
@@ -27,12 +28,9 @@
IMPLEMENT_STANDARD_RTTIEXT(IVtkOCC_SelectableObject,SelectMgr_SelectableObject)
// Handle implementation
//============================================================================
// Method: Constructor
// Purpose: Constructs a selectable object initialized by the given shape
// Purpose:
//============================================================================
IVtkOCC_SelectableObject::IVtkOCC_SelectableObject (const IVtkOCC_Shape::Handle& theShape)
: SelectMgr_SelectableObject (PrsMgr_TOP_AllView),
@@ -42,37 +40,35 @@ IVtkOCC_SelectableObject::IVtkOCC_SelectableObject (const IVtkOCC_Shape::Handle&
{
myShape->SetSelectableObject (this);
}
// Minor stuff - but it facilitates usage of OCCT selection
// classes dealing with deflection, see ComputeSelection() below
myOCCTDrawer = new Prs3d_Drawer();
}
//============================================================================
// Method: Constructor
// Purpose: Constructs uninitialized selectable object.
// setShape() should be called later.
// Purpose:
//============================================================================
IVtkOCC_SelectableObject::IVtkOCC_SelectableObject()
: SelectMgr_SelectableObject (PrsMgr_TOP_AllView),
myShape (0)
{ }
: SelectMgr_SelectableObject (PrsMgr_TOP_AllView)
{
//
}
//============================================================================
// Method: Destructor
// Purpose:
// Purpose:
//============================================================================
IVtkOCC_SelectableObject::~IVtkOCC_SelectableObject()
{ }
{
//
}
//============================================================================
// Method: SetShape
// Purpose: Sets the selectable shape
// Purpose:
//============================================================================
void IVtkOCC_SelectableObject::SetShape (const IVtkOCC_Shape::Handle& theShape)
{
myShape = theShape;
if (! myShape.IsNull())
if (!myShape.IsNull())
{
myShape->SetSelectableObject (this);
}
@@ -84,7 +80,7 @@ void IVtkOCC_SelectableObject::SetShape (const IVtkOCC_Shape::Handle& theShape)
//============================================================================
// Method: ComputeSelection
// Purpose: Internal method, computes selection data for viewer selector
// Purpose:
//============================================================================
void IVtkOCC_SelectableObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
const Standard_Integer theMode)
@@ -94,33 +90,17 @@ void IVtkOCC_SelectableObject::ComputeSelection (const Handle(SelectMgr_Selectio
return;
}
TopoDS_Shape anOcctShape = myShape->GetShape();
if (anOcctShape.ShapeType() == TopAbs_COMPOUND && anOcctShape.NbChildren() == 0)
const TopoDS_Shape& anOcctShape = myShape->GetShape();
if (anOcctShape.ShapeType() == TopAbs_COMPOUND
&& anOcctShape.NbChildren() == 0)
{
// Shape empty -> go away
return;
}
TopAbs_ShapeEnum aTypeOfSel = AIS_Shape::SelectionType (theMode);
Standard_Real aDeflection = myOCCTDrawer->MaximalChordialDeviation();
if (myOCCTDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE)
{
Bnd_Box aBndBox;
BRepBndLib::Add (anOcctShape, aBndBox);
if (!aBndBox.IsVoid())
{
Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
aBndBox.Get (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
aDeflection = Max (aXmax - aXmin, Max (aYmax - aYmin, aZmax - aZmin)) *
myOCCTDrawer->DeviationCoefficient();
}
}
// Assume the shape has been displayed already -> triangulation should exist
Standard_Boolean isAutoTriangulation = Standard_False;
const TopAbs_ShapeEnum aTypeOfSel = AIS_Shape::SelectionType (theMode);
const Handle(Prs3d_Drawer)& aDrawer = myShape->Attributes();
const Standard_Real aDeflection = StdPrs_ToolTriangulatedShape::GetDeflection (anOcctShape, aDrawer);
try
{
OCC_CATCH_SIGNALS
@@ -129,8 +109,8 @@ void IVtkOCC_SelectableObject::ComputeSelection (const Handle(SelectMgr_Selectio
anOcctShape,
aTypeOfSel,
aDeflection,
myOCCTDrawer->DeviationAngle(),
isAutoTriangulation);
aDrawer->DeviationAngle(),
aDrawer->IsAutoTriangulation());
}
catch (const Standard_Failure& anException)
{
@@ -158,8 +138,7 @@ const Bnd_Box& IVtkOCC_SelectableObject::BoundingBox()
return myBndBox;
}
TopoDS_Shape anOcctShape = myShape->GetShape();
const TopoDS_Shape& anOcctShape = myShape->GetShape();
if (anOcctShape.ShapeType() == TopAbs_COMPOUND && anOcctShape.NbChildren() == 0)
{
// Shape empty -> nothing to do

View File

@@ -73,7 +73,6 @@ private:
private:
IVtkOCC_Shape::Handle myShape;
Bnd_Box myBndBox;
Handle(Prs3d_Drawer) myOCCTDrawer;
};
#endif // __IVTKOCC_SELECTABLEOBJECT_H__

View File

@@ -14,20 +14,29 @@
// commercial license or contractual agreement.
#include <IVtkOCC_Shape.hxx>
#include <TopExp.hxx>
IMPLEMENT_STANDARD_RTTIEXT(IVtkOCC_Shape,IVtk_IShape)
// Handle implementation
//============================================================================
// Method: Constructor
// Purpose:
//============================================================================
IVtkOCC_Shape::IVtkOCC_Shape (const TopoDS_Shape& theShape)
: myTopoDSShape (theShape)
IVtkOCC_Shape::IVtkOCC_Shape (const TopoDS_Shape& theShape,
const Handle(Prs3d_Drawer)& theDrawerLink)
: myTopoDSShape (theShape),
myOCCTDrawer (new Prs3d_Drawer())
{
if (!theDrawerLink.IsNull())
{
myOCCTDrawer->SetLink (theDrawerLink);
}
else
{
// these old defaults have been moved from IVtkOCC_ShapeMesher constructor
myOCCTDrawer->SetDeviationCoefficient (0.0001); // Aspect_TOD_RELATIVE
}
buildSubShapeIdMap();
}
@@ -38,26 +47,24 @@ IVtkOCC_Shape::IVtkOCC_Shape (const TopoDS_Shape& theShape)
IVtkOCC_Shape::~IVtkOCC_Shape() { }
//============================================================================
// Method: getSubShapeId
// Purpose: Returns unique ID of the given sub-shape within the top-level shape.
// Method: GetSubShapeId
// Purpose:
//============================================================================
IVtk_IdType IVtkOCC_Shape::GetSubShapeId (const TopoDS_Shape& theSubShape) const
{
Standard_Integer anIndex = theSubShape.IsSame (myTopoDSShape) ?
-1 :
mySubShapeIds.FindIndex (theSubShape);
if (!anIndex) // Not found in the map
if (anIndex == 0) // Not found in the map
{
anIndex = -1;
return (IVtk_IdType )-1;
}
return (IVtk_IdType)anIndex;
}
//============================================================================
// Method: getSubIds
// Purpose: Get ids of sub-shapes composing a sub-shape with the given id.
// Purpose:
//============================================================================
IVtk_ShapeIdList IVtkOCC_Shape::GetSubIds (const IVtk_IdType theId) const
{
@@ -73,7 +80,7 @@ IVtk_ShapeIdList IVtkOCC_Shape::GetSubIds (const IVtk_IdType theId) const
}
else
{
// Find all composing vertices, edges and faces of the the found sub-shape
// Find all composing vertices, edges and faces of the found sub-shape
// and append their ids to the result.
TopTools_IndexedMapOfShape aSubShapes;
if (aShape.IsSame (myTopoDSShape))

View File

@@ -32,19 +32,23 @@ public:
typedef Handle(IVtkOCC_Shape) Handle;
//! Constructor for OCC IShape implementation
Standard_EXPORT IVtkOCC_Shape (const TopoDS_Shape& theShape);
//! Constructor for OCC IShape implementation.
//! @param theShape [in] shape to display
//! @param theDrawerLink [in] default attributes to link
Standard_EXPORT IVtkOCC_Shape (const TopoDS_Shape& theShape,
const Handle(Prs3d_Drawer)& theDrawerLink = Handle(Prs3d_Drawer)());
//! Destructor
Standard_EXPORT virtual ~IVtkOCC_Shape();
//! Returns unique ID of the given sub-shape within the top-level shape.
Standard_EXPORT IVtk_IdType GetSubShapeId (const IVtk_IShape::Handle&) const;
DEFINE_STANDARD_RTTIEXT(IVtkOCC_Shape,IVtk_IShape)
//! Get the wrapped original OCCT shape
//! @return TopoDS_Shape the wrapped original OCCT shape
TopoDS_Shape GetShape() const
const TopoDS_Shape& GetShape() const
{
return myTopoDSShape;
}
@@ -78,11 +82,17 @@ public:
}
//! @return Handle to the selectable object for this shape.
Handle(SelectMgr_SelectableObject) GetSelectableObject() const
const Handle(SelectMgr_SelectableObject)& GetSelectableObject() const
{
return mySelectable;
}
//! Return presentation attributes.
const Handle(Prs3d_Drawer)& Attributes() const { return myOCCTDrawer; }
//! Set presentation attributes.
void SetAttributes (const Handle(Prs3d_Drawer)& theDrawer) { myOCCTDrawer = theDrawer; }
private:
//! @brief Build a map of sub-shapes by their IDs
//!
@@ -94,6 +104,7 @@ private:
private:
TopTools_IndexedMapOfShape mySubShapeIds; //!< Map of sub-shapes by their IDs
TopoDS_Shape myTopoDSShape; //!< The wrapped main OCCT shape
Handle(Prs3d_Drawer) myOCCTDrawer; //!< presentation attributes
Handle(SelectMgr_SelectableObject) mySelectable; //!< Link to a holder of selection primitives
};

View File

@@ -15,54 +15,62 @@
#include <IVtkOCC_ShapeMesher.hxx>
#include <Adaptor3d_IsoCurve.hxx>
#include <Bnd_Box.hxx>
#include <BRep_Tool.hxx>
#include <BRepBndLib.hxx>
#include <BRepMesh_DiscretFactory.hxx>
#include <BRepMesh_DiscretRoot.hxx>
#include <BRepTools.hxx>
#include <Hatch_Hatcher.hxx>
#include <GCPnts_QuasiUniformDeflection.hxx>
#include <GCPnts_TangentialDeflection.hxx>
#include <Geom_BezierSurface.hxx>
#include <Geom_BSplineSurface.hxx>
#include <Geom2dAdaptor_Curve.hxx>
#include <GeomAdaptor_Curve.hxx>
#include <gp_Dir2d.hxx>
#include <gp_Pnt2d.hxx>
#include <Message.hxx>
#include <NCollection_Array1.hxx>
#include <Poly_Polygon3D.hxx>
#include <Poly_PolygonOnTriangulation.hxx>
#include <Poly_Triangulation.hxx>
#include <Precision.hxx>
#include <Prs3d.hxx>
#include <Prs3d_Drawer.hxx>
#include <Prs3d_IsoAspect.hxx>
#include <Standard_ErrorHandler.hxx>
#include <StdPrs_Isolines.hxx>
#include <StdPrs_ToolTriangulatedShape.hxx>
#include <TColgp_SequenceOfPnt2d.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
IMPLEMENT_STANDARD_RTTIEXT(IVtkOCC_ShapeMesher,IVtk_IShapeMesher)
// Handle implementation
//================================================================
// Function : IVtkOCC_ShapeMesher
// Purpose :
//================================================================
IVtkOCC_ShapeMesher::IVtkOCC_ShapeMesher()
{
//
}
//================================================================
// Function : ~IVtkOCC_ShapeMesher
// Purpose :
//================================================================
IVtkOCC_ShapeMesher::~IVtkOCC_ShapeMesher()
{
//
}
//================================================================
// Function : internalBuild
// Purpose :
// Purpose :
//================================================================
void IVtkOCC_ShapeMesher::internalBuild()
{
// TODO: do we need any protection here so as not to triangualte
// the shape twice??? This can be done e.g. by checking if
// triangulation exists for TopoDS_Shape..
meshShape();
const TopoDS_Shape& anOcctShape = GetShapeObj()->GetShape();
if (anOcctShape.IsNull())
{
return;
}
const Handle(Prs3d_Drawer)& anOcctDrawer = GetShapeObj()->Attributes();
const Standard_Real aShapeDeflection = StdPrs_ToolTriangulatedShape::GetDeflection (anOcctShape, anOcctDrawer);
if (anOcctDrawer->IsAutoTriangulation())
{
StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (anOcctShape, anOcctDrawer, true);
StdPrs_ToolTriangulatedShape::Tessellate (anOcctShape, anOcctDrawer);
}
// Free vertices and free edges should always be shown.
// Shared edges are needed in WF representation only.
@@ -71,83 +79,79 @@ void IVtkOCC_ShapeMesher::internalBuild()
addEdges();
// Build wireframe points and cells (lines for isolines)
addWireFrameFaces();
for (TopExp_Explorer aFaceIter (anOcctShape, TopAbs_FACE); aFaceIter.More(); aFaceIter.Next())
{
const TopoDS_Face& anOcctFace = TopoDS::Face (aFaceIter.Current());
try
{
OCC_CATCH_SIGNALS
addWFFace (anOcctFace, GetShapeObj()->GetSubShapeId (anOcctFace), aShapeDeflection);
}
catch (const Standard_Failure& anException)
{
Message::SendFail (TCollection_AsciiString("Error: addWireFrameFaces() wireframe presentation builder has failed (")
+ anException.GetMessageString() + ")");
}
}
// Build shaded representation (based on Poly_Triangulation)
addShadedFaces();
for (TopExp_Explorer aFaceIter (anOcctShape, TopAbs_FACE); aFaceIter.More(); aFaceIter.Next())
{
const TopoDS_Face& anOcctFace = TopoDS::Face (aFaceIter.Current());
addShadedFace (anOcctFace, GetShapeObj()->GetSubShapeId (anOcctFace));
}
}
//================================================================
// Function : GetShapeObj
// Purpose :
// Purpose :
//================================================================
const IVtkOCC_Shape::Handle IVtkOCC_ShapeMesher::GetShapeObj() const
{
return (IVtkOCC_Shape::Handle::DownCast(myShapeObj));
return IVtkOCC_Shape::Handle::DownCast(myShapeObj);
}
//================================================================
// Function : GetDeflection
// Purpose : Returns absolute deflection used by this algorithm.
// Purpose :
//================================================================
Standard_Real IVtkOCC_ShapeMesher::GetDeflection() const
{
if (myDeflection < Precision::Confusion()) // if not yet initialized
{
Handle(Prs3d_Drawer) aDefDrawer = new Prs3d_Drawer();
aDefDrawer->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
aDefDrawer->SetDeviationCoefficient (GetDeviationCoeff());
myDeflection = StdPrs_ToolTriangulatedShape::GetDeflection (GetShapeObj()->GetShape(), aDefDrawer);
}
return myDeflection;
const TopoDS_Shape& anOcctShape = GetShapeObj()->GetShape();
return !anOcctShape.IsNull()
? StdPrs_ToolTriangulatedShape::GetDeflection (anOcctShape, GetShapeObj()->Attributes())
: 0.0;
}
//================================================================
// Function : meshShape
// Purpose :
// Function : GetDeflection
// Purpose :
//================================================================
void IVtkOCC_ShapeMesher::meshShape()
Standard_Real IVtkOCC_ShapeMesher::GetDeviationCoeff() const
{
const TopoDS_Shape& anOcctShape = GetShapeObj()->GetShape();
if (anOcctShape.IsNull())
if (IVtkOCC_Shape::Handle aShape = GetShapeObj())
{
return;
return aShape->Attributes()->DeviationCoefficient();
}
return 0.0;
}
//Clean triangulation before compute incremental mesh
BRepTools::Clean (anOcctShape);
//Compute triangulation
Standard_Real aDeflection = GetDeflection();
if (aDeflection < Precision::Confusion())
//================================================================
// Function : GetDeviationAngle
// Purpose :
//================================================================
Standard_Real IVtkOCC_ShapeMesher::GetDeviationAngle() const
{
if (IVtkOCC_Shape::Handle aShape = GetShapeObj())
{
return;
}
try
{
OCC_CATCH_SIGNALS
Handle(BRepMesh_DiscretRoot) anAlgo;
anAlgo = BRepMesh_DiscretFactory::Get().Discret (anOcctShape,
aDeflection,
GetDeviationAngle());
if (!anAlgo.IsNull())
{
anAlgo->Perform();
}
}
catch (const Standard_Failure& anException)
{
Message::SendFail (TCollection_AsciiString("Error: IVtkOCC_ShapeMesher::meshShape() triangulation builder has failed (")
+ anException.GetMessageString() + ")");
return aShape->Attributes()->DeviationAngle();
}
return 0.0;
}
//================================================================
// Function : addFreeVertices
// Purpose :
// Purpose :
//================================================================
void IVtkOCC_ShapeMesher::addFreeVertices()
{
@@ -176,7 +180,7 @@ void IVtkOCC_ShapeMesher::addFreeVertices()
//================================================================
// Function : addEdges
// Purpose :
// Purpose :
//================================================================
void IVtkOCC_ShapeMesher::addEdges()
{
@@ -213,54 +217,9 @@ void IVtkOCC_ShapeMesher::addEdges()
}
}
//================================================================
// Function : addWireFrameFaces
// Purpose :
//================================================================
void IVtkOCC_ShapeMesher::addWireFrameFaces()
{
// Check the deflection value once for all faces
if (GetDeflection() < Precision::Confusion())
{
return;
}
TopExp_Explorer aFaceIter (GetShapeObj()->GetShape(), TopAbs_FACE);
for (; aFaceIter.More(); aFaceIter.Next())
{
const TopoDS_Face& anOcctFace = TopoDS::Face (aFaceIter.Current());
try
{
OCC_CATCH_SIGNALS
addWFFace (anOcctFace,
GetShapeObj()->GetSubShapeId (anOcctFace));
}
catch (const Standard_Failure& anException)
{
Message::SendFail (TCollection_AsciiString("Error: addWireFrameFaces() wireframe presentation builder has failed (")
+ anException.GetMessageString() + ")");
}
}
}
//================================================================
// Function : addShadedFaces
// Purpose :
//================================================================
void IVtkOCC_ShapeMesher::addShadedFaces()
{
TopExp_Explorer aFaceIter (GetShapeObj()->GetShape(), TopAbs_FACE);
for (; aFaceIter.More(); aFaceIter.Next())
{
const TopoDS_Face& anOcctFace = TopoDS::Face (aFaceIter.Current());
addShadedFace (anOcctFace,
GetShapeObj()->GetSubShapeId (anOcctFace));
}
}
//================================================================
// Function : addVertex
// Purpose :
// Purpose :
//================================================================
void IVtkOCC_ShapeMesher::addVertex (const TopoDS_Vertex& theVertex,
const IVtk_IdType theShapeId,
@@ -273,15 +232,14 @@ void IVtkOCC_ShapeMesher::addVertex (const TopoDS_Vertex& theVertex,
gp_Pnt aPnt3d = BRep_Tool::Pnt (theVertex);
IVtk_PointId anId =
myShapeData->InsertCoordinate (aPnt3d.X(), aPnt3d.Y(), aPnt3d.Z());
IVtk_PointId anId = myShapeData->InsertCoordinate (aPnt3d.X(), aPnt3d.Y(), aPnt3d.Z());
myShapeData->InsertVertex (theShapeId, anId, theMeshType);
}
//================================================================
// Function : processPolyline
// Purpose :
// Purpose :
//================================================================
void IVtkOCC_ShapeMesher::processPolyline (Standard_Integer theNbNodes,
const TColgp_Array1OfPnt& thePoints,
@@ -319,7 +277,7 @@ void IVtkOCC_ShapeMesher::processPolyline (Standard_Integer theNbNodes,
//================================================================
// Function : addEdge
// Purpose :
// Purpose :
//================================================================
void IVtkOCC_ShapeMesher::addEdge (const TopoDS_Edge& theEdge,
const IVtk_IdType theShapeId,
@@ -331,7 +289,7 @@ void IVtkOCC_ShapeMesher::addEdge (const TopoDS_Edge& theEdge,
}
// Two discrete representations of an OCCT edge are possible:
// 1. Polygon on trinagulation - holds Ids of points
// 1. Polygon on triangulation - holds Ids of points
// contained in Poly_Triangulation object
Handle(Poly_PolygonOnTriangulation) aPolyOnTriangulation;
Handle(Poly_Triangulation) aTriangulation;
@@ -354,7 +312,7 @@ void IVtkOCC_ShapeMesher::addEdge (const TopoDS_Edge& theEdge,
return;
}
// Handle a non-identity transofmation applied to the edge
// Handle a non-identity transformation applied to the edge
gp_Trsf anEdgeTransf;
bool noTransform = true;
if (!aLocation.IsIdentity())
@@ -401,10 +359,11 @@ void IVtkOCC_ShapeMesher::addEdge (const TopoDS_Edge& theEdge,
//================================================================
// Function : addWFFace
// Purpose :
// Purpose :
//================================================================
void IVtkOCC_ShapeMesher::addWFFace (const TopoDS_Face& theFace,
const IVtk_IdType theShapeId)
void IVtkOCC_ShapeMesher::addWFFace (const TopoDS_Face& theFace,
const IVtk_IdType theShapeId,
const Standard_Real theDeflection)
{
if (theFace.IsNull())
{
@@ -434,16 +393,8 @@ void IVtkOCC_ShapeMesher::addWFFace (const TopoDS_Face& theFace,
return;
}
const Standard_Real aDeflection = GetDeflection();
Handle(Prs3d_Drawer) aDrawer = new Prs3d_Drawer();
aDrawer->SetUIsoAspect (new Prs3d_IsoAspect (Quantity_NOC_WHITE, Aspect_TOL_SOLID, 1.0f, myNbIsos[0]));
aDrawer->SetVIsoAspect (new Prs3d_IsoAspect (Quantity_NOC_WHITE, Aspect_TOL_SOLID, 1.0f, myNbIsos[1]));
aDrawer->SetDeviationAngle (myDevAngle);
aDrawer->SetDeviationCoefficient (myDevCoeff);
aDrawer->SetMaximalChordialDeviation (aDeflection);
Prs3d_NListOfSequenceOfPnt aPolylines;
StdPrs_Isolines::Add (theFace, aDrawer, aDeflection, aPolylines, aPolylines);
StdPrs_Isolines::Add (theFace, GetShapeObj()->Attributes(), theDeflection, aPolylines, aPolylines);
for (Prs3d_NListOfSequenceOfPnt::Iterator aPolyIter (aPolylines); aPolyIter.More(); aPolyIter.Next())
{
const Handle(TColgp_HSequenceOfPnt)& aPoints = aPolyIter.Value();
@@ -467,7 +418,7 @@ void IVtkOCC_ShapeMesher::addWFFace (const TopoDS_Face& theFace,
//================================================================
// Function : addShadedFace
// Purpose :
// Purpose :
//================================================================
void IVtkOCC_ShapeMesher::addShadedFace (const TopoDS_Face& theFace,
const IVtk_IdType theShapeId)
@@ -479,7 +430,7 @@ void IVtkOCC_ShapeMesher::addShadedFace (const TopoDS_Face& theFace,
// Build triangulation of the face.
TopLoc_Location aLoc;
Handle(Poly_Triangulation) anOcctTriangulation = BRep_Tool::Triangulation (theFace, aLoc);
const Handle(Poly_Triangulation)& anOcctTriangulation = BRep_Tool::Triangulation (theFace, aLoc);
if (anOcctTriangulation.IsNull())
{
return;
@@ -499,9 +450,7 @@ void IVtkOCC_ShapeMesher::addShadedFace (const TopoDS_Face& theFace,
// Keep inserted points id's of triangulation in an array.
NCollection_Array1<IVtk_PointId> aPointIds (1, aNbPoints);
IVtk_PointId anId;
Standard_Integer anI;
for (anI = 1; anI <= aNbPoints; anI++)
for (Standard_Integer anI = 1; anI <= aNbPoints; anI++)
{
gp_Pnt aPoint = anOcctTriangulation->Node (anI);
@@ -516,9 +465,9 @@ void IVtkOCC_ShapeMesher::addShadedFace (const TopoDS_Face& theFace,
}
// Create triangles on the created triangulation points.
Standard_Integer aNbTriangles = anOcctTriangulation->NbTriangles();
const Standard_Integer aNbTriangles = anOcctTriangulation->NbTriangles();
Standard_Integer aN1, aN2, aN3;
for (anI = 1; anI <= aNbTriangles; anI++)
for (Standard_Integer anI = 1; anI <= aNbTriangles; anI++)
{
anOcctTriangulation->Triangle (anI).Get (aN1, aN2, aN3); // get indexes of triangle's points
// Insert new triangle on these points into output shape data.

View File

@@ -16,24 +16,22 @@
#ifndef __IVTKOCC_SHAPEMESHER_H__
#define __IVTKOCC_SHAPEMESHER_H__
#include <BRepAdaptor_Surface.hxx>
#include <IVtkOCC_Shape.hxx>
#include <IVtk_IShapeMesher.hxx>
#include <TColgp_Array1OfPnt.hxx>
#include <TColgp_SequenceOfPnt.hxx>
#include <TColStd_Array1OfInteger.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
#include <TopTools_ListOfShape.hxx>
#include <TopTools_ShapeMapHasher.hxx>
typedef NCollection_DataMap <TopoDS_Shape, IVtk_MeshType, TopTools_ShapeMapHasher> IVtk_ShapeTypeMap;
typedef NCollection_Sequence <gp_Pnt> IVtk_Polyline;
typedef NCollection_List <IVtk_Polyline> IVtk_PolylineList;
class Prs3d_Drawer;
class IVtkOCC_ShapeMesher;
DEFINE_STANDARD_HANDLE( IVtkOCC_ShapeMesher, IVtk_IShapeMesher )
@@ -47,19 +45,11 @@ DEFINE_STANDARD_HANDLE( IVtkOCC_ShapeMesher, IVtk_IShapeMesher )
class IVtkOCC_ShapeMesher : public IVtk_IShapeMesher
{
public:
IVtkOCC_ShapeMesher (const Standard_Real& theDevCoeff = 0.0001,
const Standard_Real& theDevAngle = 12.0 * M_PI / 180.0,
const Standard_Integer theNbUIsos = 1,
const Standard_Integer theNbVIsos = 1)
: myDevCoeff (theDevCoeff),
myDevAngle (theDevAngle),
myDeflection (0.0)
{
myNbIsos[0] = theNbUIsos;
myNbIsos[1] = theNbVIsos;
}
//! Main constructor.
Standard_EXPORT IVtkOCC_ShapeMesher();
virtual ~IVtkOCC_ShapeMesher() { }
//! Destructor.
Standard_EXPORT virtual ~IVtkOCC_ShapeMesher();
//! Returns absolute deflection used by this algorithm.
//! This value is calculated on the basis of the shape's bounding box.
@@ -71,28 +61,19 @@ public:
//! Returns relative deviation coefficient used by this algorithm.
//! @return relative deviation coefficient
Standard_Real GetDeviationCoeff() const
{
return myDevCoeff;
}
Standard_EXPORT Standard_Real GetDeviationCoeff() const;
//! Returns deviation angle used by this algorithm.
//! This is the maximum allowed angle between the normals to the
//! curve/surface and the normals to polyline/faceted representation.
//! @return deviation angle (in radians)
Standard_Real GetDeviationAngle() const
{
return myDevAngle;
}
Standard_EXPORT Standard_Real GetDeviationAngle() const;
protected:
//! Executes the mesh generation algorithms. To be defined in implementation class.
Standard_EXPORT virtual void internalBuild() Standard_OVERRIDE;
private:
//! Internal method, generates OCCT triangulation starting from TopoDS_Shape
//! @see IVtkOCC_ShapeMesher::addEdge, IVtkOCC_ShapeMesher::addShadedFace
void meshShape();
//! Extracts free vertices from the shape (i.e. those not belonging to any edge)
//! and passes the geometry to IPolyData.
@@ -102,12 +83,6 @@ private:
//! Adds all the edges (free and non-free) to IPolyData.
void addEdges();
//! Adds wireframe representations of all faces to IPolyData.
void addWireFrameFaces();
//! Adds shaded representations of all faces to IPolyData.
void addShadedFaces();
//! Adds the point coordinates, connectivity info and
//! sub-shape ID for the OCCT vertex.
//!
@@ -130,20 +105,22 @@ private:
//! Generates wireframe representation of the given TopoDS_Face object
//! with help of OCCT algorithms. The resulting polylines are passed to IPolyData
//! interface and associated with the given sub-shape ID.
//! @param [in] faceToMesh TopoDS_Face object to build wireframe representation for.
//! @param [in] shapeId The face' sub-shape ID
void addWFFace (const TopoDS_Face& theFace,
const IVtk_IdType theShapeId);
//! @param [in] theFace TopoDS_Face object to build wireframe representation for
//! @param [in] theShapeId The face' sub-shape ID
//! @param [in] theDeflection curve deflection
void addWFFace (const TopoDS_Face& theFace,
const IVtk_IdType theShapeId,
const Standard_Real theDeflection);
//! Creates shaded representation of the given TopoDS_Face object
//! starting from OCCT triangulation that should be created in advance.
//! The resulting triangles are passed to IPolyData
//! interface and associated with the given sub-shape ID.
//! @param [in] faceToMesh TopoDS_Face object to build shaded representation for.
//! @param [in] shapeId The face' sub-shape ID
//! @param [in] theFace TopoDS_Face object to build shaded representation for
//! @param [in] theShapeId the face' sub-shape ID
//! @see IVtkOCC_ShapeMesher::meshShape, IVtkOCC_ShapeMesher::addEdge
void addShadedFace (const TopoDS_Face& theFace,
const IVtk_IdType theShapeId);
void addShadedFace (const TopoDS_Face& theFace,
const IVtk_IdType theShapeId);
//! Internal helper method that unpacks the input arrays of points and
//! connectivity and creates the polyline using IPolyData interface.
@@ -164,11 +141,7 @@ private:
DEFINE_STANDARD_RTTIEXT(IVtkOCC_ShapeMesher,IVtk_IShapeMesher)
private:
IVtk_ShapeTypeMap myEdgesTypes;
Standard_Real myDevCoeff;
Standard_Real myDevAngle;
mutable Standard_Real myDeflection;
Standard_Integer myNbIsos[2];
IVtk_ShapeTypeMap myEdgesTypes;
};
#endif // __IVTKOCC_SHAPEMESHER_H__

View File

@@ -23,12 +23,9 @@
IMPLEMENT_STANDARD_RTTIEXT(IVtkOCC_ShapePickerAlgo,IVtk_IShapePickerAlgo)
// Handle implementation
//================================================================
// Function : Constructor
// Purpose :
// Purpose :
//================================================================
IVtkOCC_ShapePickerAlgo::IVtkOCC_ShapePickerAlgo() :
myViewerSelector (new IVtkOCC_ViewerSelector())
@@ -36,7 +33,7 @@ myViewerSelector (new IVtkOCC_ViewerSelector())
//================================================================
// Function : Destructor
// Purpose :
// Purpose :
//================================================================
IVtkOCC_ShapePickerAlgo::~IVtkOCC_ShapePickerAlgo()
{ }
@@ -57,30 +54,29 @@ void IVtkOCC_ShapePickerAlgo::SetView (const IVtk_IView::Handle& theView)
IVtk_SelectionModeList IVtkOCC_ShapePickerAlgo::GetSelectionModes (
const IVtk_IShape::Handle& theShape) const
{
IVtk_SelectionModeList aRes;
if (! theShape.IsNull())
if (theShape.IsNull())
{
// Get shape implementation from shape interface.
Handle(IVtkOCC_Shape) aShapeImpl = Handle(IVtkOCC_Shape)::DownCast(theShape);
// Get selectable object from the shape implementation.
Handle(IVtkOCC_SelectableObject) aSelObj =
Handle(IVtkOCC_SelectableObject)::DownCast(aShapeImpl->GetSelectableObject());
if (!aSelObj.IsNull())
{
IVtk_SelectionMode aSelMode;
for (aSelMode = SM_Shape; aSelMode <= SM_Compound; aSelMode = (IVtk_SelectionMode)(aSelMode + 1))
{
if (myViewerSelector->IsActive (aSelObj, aSelMode))
{
aRes.Append (aSelMode);
}
}
}
return IVtk_SelectionModeList();
}
// Get shape implementation from shape interface.
Handle(IVtkOCC_Shape) aShapeImpl = Handle(IVtkOCC_Shape)::DownCast(theShape);
// Get selectable object from the shape implementation.
Handle(IVtkOCC_SelectableObject) aSelObj = Handle(IVtkOCC_SelectableObject)::DownCast(aShapeImpl->GetSelectableObject());
if (aSelObj.IsNull())
{
return IVtk_SelectionModeList();
}
IVtk_SelectionModeList aRes;
for (IVtk_SelectionMode aSelMode = SM_Shape; aSelMode <= SM_Compound; aSelMode = (IVtk_SelectionMode)(aSelMode + 1))
{
if (myViewerSelector->IsActive (aSelObj, aSelMode))
{
aRes.Append (aSelMode);
}
}
return aRes;
}
@@ -102,8 +98,7 @@ void IVtkOCC_ShapePickerAlgo::SetSelectionMode (const IVtk_IShape::Handle& theSh
// are destroyed when shapes are deactivated...
// Get shape implementation from shape interface.
Handle(IVtkOCC_Shape) aShapeImpl =
Handle(IVtkOCC_Shape)::DownCast(theShape);
Handle(IVtkOCC_Shape) aShapeImpl = Handle(IVtkOCC_Shape)::DownCast(theShape);
// Get selectable object from the shape implementation.
Handle(IVtkOCC_SelectableObject) aSelObj =
@@ -180,11 +175,9 @@ void IVtkOCC_ShapePickerAlgo::SetSelectionMode (const IVtk_ShapePtrList& theShap
const IVtk_SelectionMode theMode,
const bool /*theIsTurnOn*/)
{
IVtk_IShape::Handle aShape;
IVtk_ShapePtrList::Iterator anIt (theShapes);
for (; anIt.More(); anIt.Next())
for (IVtk_ShapePtrList::Iterator anIt (theShapes); anIt.More(); anIt.Next())
{
aShape = anIt.Value();
IVtk_IShape::Handle aShape = anIt.Value();
SetSelectionMode (aShape, theMode);
}
}
@@ -371,8 +364,7 @@ void IVtkOCC_ShapePickerAlgo::RemoveSelectableObject(const IVtk_IShape::Handle&
{
clearPicked();
// Get shape implementation from shape interface.
Handle(IVtkOCC_Shape) aShapeImpl =
Handle(IVtkOCC_Shape)::DownCast(theShape);
Handle(IVtkOCC_Shape) aShapeImpl = Handle(IVtkOCC_Shape)::DownCast(theShape);
// Get selectable object from the shape implementation.
Handle(IVtkOCC_SelectableObject) aSelObj =
@@ -381,4 +373,4 @@ void IVtkOCC_ShapePickerAlgo::RemoveSelectableObject(const IVtk_IShape::Handle&
myViewerSelector->RemoveSelectableObject(aSelObj);
myViewerSelector->Clear();
aShapeImpl->SetSelectableObject(NULL);
}
}

View File

@@ -14,11 +14,11 @@
// commercial license or contractual agreement.
#include <IVtkOCC_ViewerSelector.hxx>
#include <Select3D_SensitiveBox.hxx>
#include <TColgp_Array1OfPnt2d.hxx>
#include <Graphic3d_Camera.hxx>
IMPLEMENT_STANDARD_RTTIEXT(IVtkOCC_ViewerSelector,SelectMgr_ViewerSelector)
//============================================================================
@@ -27,8 +27,8 @@ IMPLEMENT_STANDARD_RTTIEXT(IVtkOCC_ViewerSelector,SelectMgr_ViewerSelector)
//============================================================================
IVtkOCC_ViewerSelector::IVtkOCC_ViewerSelector()
: SelectMgr_ViewerSelector(),
myPixTol(2),
myToUpdateTol(Standard_True)
myPixTol(2),
myToUpdateTol(Standard_True)
{
}

View File

@@ -25,7 +25,6 @@
//! @brief Class that implements OCCT selection algorithm.
//!
//! Inspired by StdSelect_ViewerSelector3d class from OCCT 6.5.1
class IVtkOCC_ViewerSelector : public SelectMgr_ViewerSelector
{
public:
@@ -66,4 +65,5 @@ private:
};
DEFINE_STANDARD_HANDLE( IVtkOCC_ViewerSelector, SelectMgr_ViewerSelector )
#endif // __IVTKOCC_VIEWERSELECTOR_H__