1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +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

@ -17,10 +17,10 @@
IMPLEMENT_STANDARD_RTTIEXT(IVtk_IShapeMesher,IVtk_Interface) IMPLEMENT_STANDARD_RTTIEXT(IVtk_IShapeMesher,IVtk_Interface)
// Handle implementation // ================================================================
// Function : initialize
// Purpose :
//! Executes the mesh generation algorithms. To be defined in implementation class. // ================================================================
void IVtk_IShapeMesher::initialize (const IVtk_IShape::Handle& theShape, void IVtk_IShapeMesher::initialize (const IVtk_IShape::Handle& theShape,
const IVtk_IShapeData::Handle& theData) const IVtk_IShapeData::Handle& theData)
{ {
@ -28,9 +28,10 @@ void IVtk_IShapeMesher::initialize (const IVtk_IShape::Handle& theShape,
myShapeData = theData; myShapeData = theData;
} }
//! Main entry point for building shape representation // ================================================================
//! @param [in] shape IShape to be meshed // Function : Build
//! @param [in] data IShapeData interface visualization data is passed to. // Purpose :
// ================================================================
void IVtk_IShapeMesher::Build (const IVtk_IShape::Handle& theShape, void IVtk_IShapeMesher::Build (const IVtk_IShape::Handle& theShape,
const IVtk_IShapeData::Handle& theData) const IVtk_IShapeData::Handle& theData)
{ {

View File

@ -31,11 +31,15 @@ public:
typedef Handle(IVtk_IShapeMesher) Handle; typedef Handle(IVtk_IShapeMesher) Handle;
virtual ~IVtk_IShapeMesher() { } virtual ~IVtk_IShapeMesher() { }
//! Main entry point for building shape representation
//! @param [in] shape IShape to be meshed
//! @param [in] data IShapeData interface visualization data is passed to.
Standard_EXPORT void Build (const IVtk_IShape::Handle& theShape, const IVtk_IShapeData::Handle& theData); Standard_EXPORT void Build (const IVtk_IShape::Handle& theShape, const IVtk_IShapeData::Handle& theData);
DEFINE_STANDARD_RTTIEXT(IVtk_IShapeMesher,IVtk_Interface) DEFINE_STANDARD_RTTIEXT(IVtk_IShapeMesher,IVtk_Interface)
protected: protected:
//! Executes the mesh generation algorithms. To be defined in implementation class.
Standard_EXPORT virtual void initialize (const IVtk_IShape::Handle& theShapeObj, Standard_EXPORT virtual void initialize (const IVtk_IShape::Handle& theShapeObj,
const IVtk_IShapeData::Handle& theShapeData); const IVtk_IShapeData::Handle& theShapeData);
virtual void internalBuild() = 0; virtual void internalBuild() = 0;

View File

@ -167,6 +167,22 @@ static Handle(PipelinePtr) PipelineByActorName (const TCollection_AsciiString& t
return PipelineByActor (anActor); return PipelineByActor (anActor);
} }
//! Create global presentation attributes.
static Handle(Prs3d_Drawer) createDefaultDrawer()
{
Handle(Prs3d_Drawer) aGlobalDrawer = new Prs3d_Drawer();
aGlobalDrawer->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
aGlobalDrawer->SetDeviationCoefficient (0.0001);
return aGlobalDrawer;
}
//! Get global presentation attributes (analog of AIS_InteractiveContext::DefaultDrawer()).
static const Handle(Prs3d_Drawer)& GetDefaultDrawer()
{
static Handle(Prs3d_Drawer) aGlobalDrawer = createDefaultDrawer();
return aGlobalDrawer;
}
#ifdef _WIN32 #ifdef _WIN32
static Handle(WNT_Window)& GetWindow() static Handle(WNT_Window)& GetWindow()
@ -495,12 +511,105 @@ vtkActor* CreateActor (const Standard_Integer theId,
return NULL; return NULL;
} }
Handle(PipelinePtr) aPL = new PipelinePtr (theShape, theId); Handle(PipelinePtr) aPL = new PipelinePtr (theShape, theId, GetDefaultDrawer());
GetPipelines()->Bind (theId, aPL); GetPipelines()->Bind (theId, aPL);
return aPL->Actor(); return aPL->Actor();
} }
//===============================================================================================
//function : VtkDefaults
//purpose :
//===============================================================================================
static int VtkDefaults (Draw_Interpretor& theDi,
Standard_Integer theArgsNb,
const char** theArgVec)
{
const Handle(Prs3d_Drawer)& aDefParams = GetDefaultDrawer();
if (theArgsNb < 2)
{
if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
{
theDi << "DeflType: relative\n"
<< "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
}
else
{
theDi << "DeflType: absolute\n"
<< "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
}
theDi << "AngularDeflection: " << (180.0 * aDefParams->DeviationAngle() / M_PI) << "\n";
theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
return 0;
}
for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
{
TCollection_AsciiString anArg (theArgVec[anArgIter]);
anArg.UpperCase();
if (anArg == "-ABSDEFL"
|| anArg == "-ABSOLUTEDEFLECTION"
|| anArg == "-DEFL"
|| anArg == "-DEFLECTION")
{
if (++anArgIter >= theArgsNb)
{
theDi << "Syntax error at " << anArg;
return 1;
}
aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
}
else if (anArg == "-RELDEFL"
|| anArg == "-RELATIVEDEFLECTION"
|| anArg == "-DEVCOEFF"
|| anArg == "-DEVIATIONCOEFF"
|| anArg == "-DEVIATIONCOEFFICIENT")
{
if (++anArgIter >= theArgsNb)
{
theDi << "Syntax error at " << anArg;
return 1;
}
aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
}
else if (anArg == "-ANGDEFL"
|| anArg == "-ANGULARDEFL"
|| anArg == "-ANGULARDEFLECTION")
{
if (++anArgIter >= theArgsNb)
{
theDi << "Syntax error at " << anArg;
return 1;
}
aDefParams->SetDeviationAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
}
else if (anArg == "-AUTOTR"
|| anArg == "-AUTOTRIANG"
|| anArg == "-AUTOTRIANGULATION")
{
++anArgIter;
bool toTurnOn = true;
if (anArgIter >= theArgsNb
|| !Draw::ParseOnOff (theArgVec[anArgIter], toTurnOn))
{
theDi << "Syntax error at '" << anArg << "'";
return 1;
}
aDefParams->SetAutoTriangulation (toTurnOn);
}
else
{
theDi << "Syntax error: unknown argument '" << anArg << "'";
return 1;
}
}
return 0;
}
//================================================================ //================================================================
// Function : VtkDisplay // Function : VtkDisplay
// Purpose : // Purpose :
@ -1509,6 +1618,14 @@ void IVtkDraw::Commands (Draw_Interpretor& theCommands)
"ivtkclose : Closes the Vtk window.", "ivtkclose : Closes the Vtk window.",
__FILE__, VtkClose, group); __FILE__, VtkClose, group);
theCommands.Add("ivtkdefaults",
"ivtkdefaults [-absDefl value]"
"\n\t\t: [-devCoeff value]"
"\n\t\t: [-angDefl value]"
"\n\t\t: [-autoTriang {off/on | 0/1}]"
"\n\t\t: Sets default VTK meshing parameters."
, __FILE__, VtkDefaults, group);
theCommands.Add("ivtkrenderparams", theCommands.Add("ivtkrenderparams",
"ivtkrenderparams [-depthPeeling NbLayers] [-shadows {on|off}]" "ivtkrenderparams [-depthPeeling NbLayers] [-shadows {on|off}]"
"\n\t\t: Sets Vtk rendering parameters." "\n\t\t: Sets Vtk rendering parameters."

View File

@ -39,7 +39,8 @@ IMPLEMENT_STANDARD_RTTIEXT(IVtkDraw_HighlightAndSelectionPipeline,Standard_Trans
//=========================================================== //===========================================================
IVtkDraw_HighlightAndSelectionPipeline::IVtkDraw_HighlightAndSelectionPipeline (const TopoDS_Shape& theShape, IVtkDraw_HighlightAndSelectionPipeline::IVtkDraw_HighlightAndSelectionPipeline (const TopoDS_Shape& theShape,
const Standard_Integer theShapeID) const Standard_Integer theShapeID,
const Handle(Prs3d_Drawer)& theDrawerLink)
: Standard_Transient() : Standard_Transient()
{ {
/* =========================== /* ===========================
@ -57,7 +58,7 @@ IVtkDraw_HighlightAndSelectionPipeline::IVtkDraw_HighlightAndSelectionPipeline (
* ======================== */ * ======================== */
myActor = vtkSmartPointer<vtkActor>::New(); myActor = vtkSmartPointer<vtkActor>::New();
IVtkOCC_Shape::Handle anIVtkShape = new IVtkOCC_Shape (theShape); IVtkOCC_Shape::Handle anIVtkShape = new IVtkOCC_Shape (theShape, theDrawerLink);
anIVtkShape->SetId (theShapeID); anIVtkShape->SetId (theShapeID);
vtkSmartPointer<IVtkTools_ShapeDataSource> aDataSource = vtkSmartPointer<IVtkTools_ShapeDataSource>::New(); vtkSmartPointer<IVtkTools_ShapeDataSource> aDataSource = vtkSmartPointer<IVtkTools_ShapeDataSource>::New();
aDataSource->SetShape (anIVtkShape); aDataSource->SetShape (anIVtkShape);

View File

@ -37,6 +37,8 @@
typedef NCollection_DataMap <IVtk_IdType, vtkSmartPointer<IVtkTools_DisplayModeFilter> > DisplayModeFiltersMap; typedef NCollection_DataMap <IVtk_IdType, vtkSmartPointer<IVtkTools_DisplayModeFilter> > DisplayModeFiltersMap;
typedef NCollection_DataMap <IVtk_IdType, vtkSmartPointer<IVtkTools_SubPolyDataFilter> > SubShapesFiltersMap; typedef NCollection_DataMap <IVtk_IdType, vtkSmartPointer<IVtkTools_SubPolyDataFilter> > SubShapesFiltersMap;
class Prs3d_Drawer;
class IVtkDraw_HighlightAndSelectionPipeline; class IVtkDraw_HighlightAndSelectionPipeline;
DEFINE_STANDARD_HANDLE(IVtkDraw_HighlightAndSelectionPipeline, Standard_Transient) DEFINE_STANDARD_HANDLE(IVtkDraw_HighlightAndSelectionPipeline, Standard_Transient)
@ -61,7 +63,8 @@ public:
public: public:
IVtkDraw_HighlightAndSelectionPipeline (const TopoDS_Shape& theShape, IVtkDraw_HighlightAndSelectionPipeline (const TopoDS_Shape& theShape,
const Standard_Integer theShapeID); const Standard_Integer theShapeID,
const Handle(Prs3d_Drawer)& theDrawerLink);
~IVtkDraw_HighlightAndSelectionPipeline() {} ~IVtkDraw_HighlightAndSelectionPipeline() {}
public: public:

View File

@ -18,6 +18,7 @@
#include <AIS_Shape.hxx> #include <AIS_Shape.hxx>
#include <BRepBndLib.hxx> #include <BRepBndLib.hxx>
#include <Message.hxx> #include <Message.hxx>
#include <StdPrs_ToolTriangulatedShape.hxx>
#include <Select3D_SensitiveBox.hxx> #include <Select3D_SensitiveBox.hxx>
#include <SelectMgr_Selection.hxx> #include <SelectMgr_Selection.hxx>
#include <Standard_ErrorHandler.hxx> #include <Standard_ErrorHandler.hxx>
@ -27,12 +28,9 @@
IMPLEMENT_STANDARD_RTTIEXT(IVtkOCC_SelectableObject,SelectMgr_SelectableObject) IMPLEMENT_STANDARD_RTTIEXT(IVtkOCC_SelectableObject,SelectMgr_SelectableObject)
// Handle implementation
//============================================================================ //============================================================================
// Method: Constructor // Method: Constructor
// Purpose: Constructs a selectable object initialized by the given shape // Purpose:
//============================================================================ //============================================================================
IVtkOCC_SelectableObject::IVtkOCC_SelectableObject (const IVtkOCC_Shape::Handle& theShape) IVtkOCC_SelectableObject::IVtkOCC_SelectableObject (const IVtkOCC_Shape::Handle& theShape)
: SelectMgr_SelectableObject (PrsMgr_TOP_AllView), : SelectMgr_SelectableObject (PrsMgr_TOP_AllView),
@ -42,32 +40,30 @@ IVtkOCC_SelectableObject::IVtkOCC_SelectableObject (const IVtkOCC_Shape::Handle&
{ {
myShape->SetSelectableObject (this); 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 // Method: Constructor
// Purpose: Constructs uninitialized selectable object. // Purpose:
// setShape() should be called later.
//============================================================================ //============================================================================
IVtkOCC_SelectableObject::IVtkOCC_SelectableObject() IVtkOCC_SelectableObject::IVtkOCC_SelectableObject()
: SelectMgr_SelectableObject (PrsMgr_TOP_AllView), : SelectMgr_SelectableObject (PrsMgr_TOP_AllView)
myShape (0) {
{ } //
}
//============================================================================ //============================================================================
// Method: Destructor // Method: Destructor
// Purpose: // Purpose:
//============================================================================ //============================================================================
IVtkOCC_SelectableObject::~IVtkOCC_SelectableObject() IVtkOCC_SelectableObject::~IVtkOCC_SelectableObject()
{ } {
//
}
//============================================================================ //============================================================================
// Method: SetShape // Method: SetShape
// Purpose: Sets the selectable shape // Purpose:
//============================================================================ //============================================================================
void IVtkOCC_SelectableObject::SetShape (const IVtkOCC_Shape::Handle& theShape) void IVtkOCC_SelectableObject::SetShape (const IVtkOCC_Shape::Handle& theShape)
{ {
@ -84,7 +80,7 @@ void IVtkOCC_SelectableObject::SetShape (const IVtkOCC_Shape::Handle& theShape)
//============================================================================ //============================================================================
// Method: ComputeSelection // Method: ComputeSelection
// Purpose: Internal method, computes selection data for viewer selector // Purpose:
//============================================================================ //============================================================================
void IVtkOCC_SelectableObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, void IVtkOCC_SelectableObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
const Standard_Integer theMode) const Standard_Integer theMode)
@ -94,33 +90,17 @@ void IVtkOCC_SelectableObject::ComputeSelection (const Handle(SelectMgr_Selectio
return; return;
} }
TopoDS_Shape anOcctShape = myShape->GetShape(); const TopoDS_Shape& anOcctShape = myShape->GetShape();
if (anOcctShape.ShapeType() == TopAbs_COMPOUND
if (anOcctShape.ShapeType() == TopAbs_COMPOUND && anOcctShape.NbChildren() == 0) && anOcctShape.NbChildren() == 0)
{ {
// Shape empty -> go away // Shape empty -> go away
return; return;
} }
TopAbs_ShapeEnum aTypeOfSel = AIS_Shape::SelectionType (theMode); const TopAbs_ShapeEnum aTypeOfSel = AIS_Shape::SelectionType (theMode);
const Handle(Prs3d_Drawer)& aDrawer = myShape->Attributes();
Standard_Real aDeflection = myOCCTDrawer->MaximalChordialDeviation(); const Standard_Real aDeflection = StdPrs_ToolTriangulatedShape::GetDeflection (anOcctShape, aDrawer);
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;
try try
{ {
OCC_CATCH_SIGNALS OCC_CATCH_SIGNALS
@ -129,8 +109,8 @@ void IVtkOCC_SelectableObject::ComputeSelection (const Handle(SelectMgr_Selectio
anOcctShape, anOcctShape,
aTypeOfSel, aTypeOfSel,
aDeflection, aDeflection,
myOCCTDrawer->DeviationAngle(), aDrawer->DeviationAngle(),
isAutoTriangulation); aDrawer->IsAutoTriangulation());
} }
catch (const Standard_Failure& anException) catch (const Standard_Failure& anException)
{ {
@ -158,8 +138,7 @@ const Bnd_Box& IVtkOCC_SelectableObject::BoundingBox()
return myBndBox; return myBndBox;
} }
TopoDS_Shape anOcctShape = myShape->GetShape(); const TopoDS_Shape& anOcctShape = myShape->GetShape();
if (anOcctShape.ShapeType() == TopAbs_COMPOUND && anOcctShape.NbChildren() == 0) if (anOcctShape.ShapeType() == TopAbs_COMPOUND && anOcctShape.NbChildren() == 0)
{ {
// Shape empty -> nothing to do // Shape empty -> nothing to do

View File

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

View File

@ -14,20 +14,29 @@
// commercial license or contractual agreement. // commercial license or contractual agreement.
#include <IVtkOCC_Shape.hxx> #include <IVtkOCC_Shape.hxx>
#include <TopExp.hxx> #include <TopExp.hxx>
IMPLEMENT_STANDARD_RTTIEXT(IVtkOCC_Shape,IVtk_IShape) IMPLEMENT_STANDARD_RTTIEXT(IVtkOCC_Shape,IVtk_IShape)
// Handle implementation
//============================================================================ //============================================================================
// Method: Constructor // Method: Constructor
// Purpose: // Purpose:
//============================================================================ //============================================================================
IVtkOCC_Shape::IVtkOCC_Shape (const TopoDS_Shape& theShape) IVtkOCC_Shape::IVtkOCC_Shape (const TopoDS_Shape& theShape,
: myTopoDSShape (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(); buildSubShapeIdMap();
} }
@ -38,26 +47,24 @@ IVtkOCC_Shape::IVtkOCC_Shape (const TopoDS_Shape& theShape)
IVtkOCC_Shape::~IVtkOCC_Shape() { } IVtkOCC_Shape::~IVtkOCC_Shape() { }
//============================================================================ //============================================================================
// Method: getSubShapeId // Method: GetSubShapeId
// Purpose: Returns unique ID of the given sub-shape within the top-level shape. // Purpose:
//============================================================================ //============================================================================
IVtk_IdType IVtkOCC_Shape::GetSubShapeId (const TopoDS_Shape& theSubShape) const IVtk_IdType IVtkOCC_Shape::GetSubShapeId (const TopoDS_Shape& theSubShape) const
{ {
Standard_Integer anIndex = theSubShape.IsSame (myTopoDSShape) ? Standard_Integer anIndex = theSubShape.IsSame (myTopoDSShape) ?
-1 : -1 :
mySubShapeIds.FindIndex (theSubShape); mySubShapeIds.FindIndex (theSubShape);
if (anIndex == 0) // Not found in the map
if (!anIndex) // Not found in the map
{ {
anIndex = -1; return (IVtk_IdType )-1;
} }
return (IVtk_IdType)anIndex; return (IVtk_IdType)anIndex;
} }
//============================================================================ //============================================================================
// Method: getSubIds // 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 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 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. // and append their ids to the result.
TopTools_IndexedMapOfShape aSubShapes; TopTools_IndexedMapOfShape aSubShapes;
if (aShape.IsSame (myTopoDSShape)) if (aShape.IsSame (myTopoDSShape))

View File

@ -32,19 +32,23 @@ public:
typedef Handle(IVtkOCC_Shape) Handle; typedef Handle(IVtkOCC_Shape) Handle;
//! Constructor for OCC IShape implementation //! Constructor for OCC IShape implementation.
Standard_EXPORT IVtkOCC_Shape (const TopoDS_Shape& theShape); //! @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 //! Destructor
Standard_EXPORT virtual ~IVtkOCC_Shape(); 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; Standard_EXPORT IVtk_IdType GetSubShapeId (const IVtk_IShape::Handle&) const;
DEFINE_STANDARD_RTTIEXT(IVtkOCC_Shape,IVtk_IShape) DEFINE_STANDARD_RTTIEXT(IVtkOCC_Shape,IVtk_IShape)
//! Get the wrapped original OCCT shape //! Get the wrapped original OCCT shape
//! @return TopoDS_Shape the wrapped original OCCT shape //! @return TopoDS_Shape the wrapped original OCCT shape
TopoDS_Shape GetShape() const const TopoDS_Shape& GetShape() const
{ {
return myTopoDSShape; return myTopoDSShape;
} }
@ -78,11 +82,17 @@ public:
} }
//! @return Handle to the selectable object for this shape. //! @return Handle to the selectable object for this shape.
Handle(SelectMgr_SelectableObject) GetSelectableObject() const const Handle(SelectMgr_SelectableObject)& GetSelectableObject() const
{ {
return mySelectable; 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: private:
//! @brief Build a map of sub-shapes by their IDs //! @brief Build a map of sub-shapes by their IDs
//! //!
@ -94,6 +104,7 @@ private:
private: private:
TopTools_IndexedMapOfShape mySubShapeIds; //!< Map of sub-shapes by their IDs TopTools_IndexedMapOfShape mySubShapeIds; //!< Map of sub-shapes by their IDs
TopoDS_Shape myTopoDSShape; //!< The wrapped main OCCT shape 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 Handle(SelectMgr_SelectableObject) mySelectable; //!< Link to a holder of selection primitives
}; };

View File

@ -15,43 +15,42 @@
#include <IVtkOCC_ShapeMesher.hxx> #include <IVtkOCC_ShapeMesher.hxx>
#include <Adaptor3d_IsoCurve.hxx>
#include <Bnd_Box.hxx> #include <Bnd_Box.hxx>
#include <BRep_Tool.hxx> #include <BRep_Tool.hxx>
#include <BRepBndLib.hxx>
#include <BRepMesh_DiscretFactory.hxx>
#include <BRepMesh_DiscretRoot.hxx>
#include <BRepTools.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 <Message.hxx>
#include <NCollection_Array1.hxx> #include <NCollection_Array1.hxx>
#include <Poly_Polygon3D.hxx> #include <Poly_Polygon3D.hxx>
#include <Poly_PolygonOnTriangulation.hxx> #include <Poly_PolygonOnTriangulation.hxx>
#include <Poly_Triangulation.hxx> #include <Poly_Triangulation.hxx>
#include <Precision.hxx>
#include <Prs3d.hxx> #include <Prs3d.hxx>
#include <Prs3d_Drawer.hxx> #include <Prs3d_Drawer.hxx>
#include <Prs3d_IsoAspect.hxx>
#include <Standard_ErrorHandler.hxx> #include <Standard_ErrorHandler.hxx>
#include <StdPrs_Isolines.hxx> #include <StdPrs_Isolines.hxx>
#include <StdPrs_ToolTriangulatedShape.hxx> #include <StdPrs_ToolTriangulatedShape.hxx>
#include <TColgp_SequenceOfPnt2d.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <TopExp.hxx> #include <TopExp.hxx>
#include <TopExp_Explorer.hxx> #include <TopExp_Explorer.hxx>
#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
IMPLEMENT_STANDARD_RTTIEXT(IVtkOCC_ShapeMesher,IVtk_IShapeMesher) 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 // Function : internalBuild
@ -59,10 +58,19 @@ IMPLEMENT_STANDARD_RTTIEXT(IVtkOCC_ShapeMesher,IVtk_IShapeMesher)
//================================================================ //================================================================
void IVtkOCC_ShapeMesher::internalBuild() void IVtkOCC_ShapeMesher::internalBuild()
{ {
// TODO: do we need any protection here so as not to triangualte const TopoDS_Shape& anOcctShape = GetShapeObj()->GetShape();
// the shape twice??? This can be done e.g. by checking if if (anOcctShape.IsNull())
// triangulation exists for TopoDS_Shape.. {
meshShape(); 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. // Free vertices and free edges should always be shown.
// Shared edges are needed in WF representation only. // Shared edges are needed in WF representation only.
@ -71,10 +79,27 @@ void IVtkOCC_ShapeMesher::internalBuild()
addEdges(); addEdges();
// Build wireframe points and cells (lines for isolines) // 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) // 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));
}
} }
//================================================================ //================================================================
@ -83,66 +108,45 @@ void IVtkOCC_ShapeMesher::internalBuild()
//================================================================ //================================================================
const IVtkOCC_Shape::Handle IVtkOCC_ShapeMesher::GetShapeObj() const const IVtkOCC_Shape::Handle IVtkOCC_ShapeMesher::GetShapeObj() const
{ {
return (IVtkOCC_Shape::Handle::DownCast(myShapeObj)); return IVtkOCC_Shape::Handle::DownCast(myShapeObj);
} }
//================================================================ //================================================================
// Function : GetDeflection // Function : GetDeflection
// Purpose : Returns absolute deflection used by this algorithm. // Purpose :
//================================================================ //================================================================
Standard_Real IVtkOCC_ShapeMesher::GetDeflection() const Standard_Real IVtkOCC_ShapeMesher::GetDeflection() const
{ {
if (myDeflection < Precision::Confusion()) // if not yet initialized const TopoDS_Shape& anOcctShape = GetShapeObj()->GetShape();
{ return !anOcctShape.IsNull()
Handle(Prs3d_Drawer) aDefDrawer = new Prs3d_Drawer(); ? StdPrs_ToolTriangulatedShape::GetDeflection (anOcctShape, GetShapeObj()->Attributes())
aDefDrawer->SetTypeOfDeflection (Aspect_TOD_RELATIVE); : 0.0;
aDefDrawer->SetDeviationCoefficient (GetDeviationCoeff());
myDeflection = StdPrs_ToolTriangulatedShape::GetDeflection (GetShapeObj()->GetShape(), aDefDrawer);
}
return myDeflection;
} }
//================================================================ //================================================================
// Function : meshShape // Function : GetDeflection
// Purpose : // Purpose :
//================================================================ //================================================================
void IVtkOCC_ShapeMesher::meshShape() Standard_Real IVtkOCC_ShapeMesher::GetDeviationCoeff() const
{ {
const TopoDS_Shape& anOcctShape = GetShapeObj()->GetShape(); if (IVtkOCC_Shape::Handle aShape = GetShapeObj())
if (anOcctShape.IsNull())
{ {
return; return aShape->Attributes()->DeviationCoefficient();
}
return 0.0;
} }
//Clean triangulation before compute incremental mesh //================================================================
BRepTools::Clean (anOcctShape); // Function : GetDeviationAngle
// Purpose :
//Compute triangulation //================================================================
Standard_Real aDeflection = GetDeflection(); Standard_Real IVtkOCC_ShapeMesher::GetDeviationAngle() const
if (aDeflection < Precision::Confusion())
{ {
return; if (IVtkOCC_Shape::Handle aShape = GetShapeObj())
}
try
{ {
OCC_CATCH_SIGNALS return aShape->Attributes()->DeviationAngle();
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 0.0;
} }
//================================================================ //================================================================
@ -213,51 +217,6 @@ 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 // Function : addVertex
// Purpose : // Purpose :
@ -273,8 +232,7 @@ void IVtkOCC_ShapeMesher::addVertex (const TopoDS_Vertex& theVertex,
gp_Pnt aPnt3d = BRep_Tool::Pnt (theVertex); gp_Pnt aPnt3d = BRep_Tool::Pnt (theVertex);
IVtk_PointId anId = IVtk_PointId anId = myShapeData->InsertCoordinate (aPnt3d.X(), aPnt3d.Y(), aPnt3d.Z());
myShapeData->InsertCoordinate (aPnt3d.X(), aPnt3d.Y(), aPnt3d.Z());
myShapeData->InsertVertex (theShapeId, anId, theMeshType); myShapeData->InsertVertex (theShapeId, anId, theMeshType);
} }
@ -331,7 +289,7 @@ void IVtkOCC_ShapeMesher::addEdge (const TopoDS_Edge& theEdge,
} }
// Two discrete representations of an OCCT edge are possible: // 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 // contained in Poly_Triangulation object
Handle(Poly_PolygonOnTriangulation) aPolyOnTriangulation; Handle(Poly_PolygonOnTriangulation) aPolyOnTriangulation;
Handle(Poly_Triangulation) aTriangulation; Handle(Poly_Triangulation) aTriangulation;
@ -354,7 +312,7 @@ void IVtkOCC_ShapeMesher::addEdge (const TopoDS_Edge& theEdge,
return; return;
} }
// Handle a non-identity transofmation applied to the edge // Handle a non-identity transformation applied to the edge
gp_Trsf anEdgeTransf; gp_Trsf anEdgeTransf;
bool noTransform = true; bool noTransform = true;
if (!aLocation.IsIdentity()) if (!aLocation.IsIdentity())
@ -404,7 +362,8 @@ void IVtkOCC_ShapeMesher::addEdge (const TopoDS_Edge& theEdge,
// Purpose : // Purpose :
//================================================================ //================================================================
void IVtkOCC_ShapeMesher::addWFFace (const TopoDS_Face& theFace, void IVtkOCC_ShapeMesher::addWFFace (const TopoDS_Face& theFace,
const IVtk_IdType theShapeId) const IVtk_IdType theShapeId,
const Standard_Real theDeflection)
{ {
if (theFace.IsNull()) if (theFace.IsNull())
{ {
@ -434,16 +393,8 @@ void IVtkOCC_ShapeMesher::addWFFace (const TopoDS_Face& theFace,
return; 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; 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()) for (Prs3d_NListOfSequenceOfPnt::Iterator aPolyIter (aPolylines); aPolyIter.More(); aPolyIter.Next())
{ {
const Handle(TColgp_HSequenceOfPnt)& aPoints = aPolyIter.Value(); const Handle(TColgp_HSequenceOfPnt)& aPoints = aPolyIter.Value();
@ -479,7 +430,7 @@ void IVtkOCC_ShapeMesher::addShadedFace (const TopoDS_Face& theFace,
// Build triangulation of the face. // Build triangulation of the face.
TopLoc_Location aLoc; 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()) if (anOcctTriangulation.IsNull())
{ {
return; return;
@ -499,9 +450,7 @@ void IVtkOCC_ShapeMesher::addShadedFace (const TopoDS_Face& theFace,
// Keep inserted points id's of triangulation in an array. // Keep inserted points id's of triangulation in an array.
NCollection_Array1<IVtk_PointId> aPointIds (1, aNbPoints); NCollection_Array1<IVtk_PointId> aPointIds (1, aNbPoints);
IVtk_PointId anId; IVtk_PointId anId;
for (Standard_Integer anI = 1; anI <= aNbPoints; anI++)
Standard_Integer anI;
for (anI = 1; anI <= aNbPoints; anI++)
{ {
gp_Pnt aPoint = anOcctTriangulation->Node (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. // Create triangles on the created triangulation points.
Standard_Integer aNbTriangles = anOcctTriangulation->NbTriangles(); const Standard_Integer aNbTriangles = anOcctTriangulation->NbTriangles();
Standard_Integer aN1, aN2, aN3; 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 anOcctTriangulation->Triangle (anI).Get (aN1, aN2, aN3); // get indexes of triangle's points
// Insert new triangle on these points into output shape data. // Insert new triangle on these points into output shape data.

View File

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

View File

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

View File

@ -14,11 +14,11 @@
// commercial license or contractual agreement. // commercial license or contractual agreement.
#include <IVtkOCC_ViewerSelector.hxx> #include <IVtkOCC_ViewerSelector.hxx>
#include <Select3D_SensitiveBox.hxx> #include <Select3D_SensitiveBox.hxx>
#include <TColgp_Array1OfPnt2d.hxx> #include <TColgp_Array1OfPnt2d.hxx>
#include <Graphic3d_Camera.hxx> #include <Graphic3d_Camera.hxx>
IMPLEMENT_STANDARD_RTTIEXT(IVtkOCC_ViewerSelector,SelectMgr_ViewerSelector) IMPLEMENT_STANDARD_RTTIEXT(IVtkOCC_ViewerSelector,SelectMgr_ViewerSelector)
//============================================================================ //============================================================================

View File

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

View File

@ -60,7 +60,7 @@ public:
protected: protected:
//! Filter cells according to the given set of ids. //! Filter cells according to the given set of ids.
virtual int RequestData (vtkInformation *, vtkInformationVector **, vtkInformationVector *); virtual int RequestData (vtkInformation *, vtkInformationVector **, vtkInformationVector *) Standard_OVERRIDE;
IVtkTools_DisplayModeFilter(); IVtkTools_DisplayModeFilter();
virtual ~IVtkTools_DisplayModeFilter(); virtual ~IVtkTools_DisplayModeFilter();

View File

@ -41,7 +41,7 @@ vtkStandardNewMacro(IVtkTools_ShapeDataSource)
// Purpose : // Purpose :
//================================================================ //================================================================
IVtkTools_ShapeDataSource::IVtkTools_ShapeDataSource() IVtkTools_ShapeDataSource::IVtkTools_ShapeDataSource()
: myPolyData (new IVtkVTK_ShapeData), : myPolyData (new IVtkVTK_ShapeData()),
myIsFastTransformMode (Standard_False), myIsFastTransformMode (Standard_False),
myIsTransformOnly (Standard_False) myIsTransformOnly (Standard_False)
{ {
@ -54,7 +54,9 @@ IVtkTools_ShapeDataSource::IVtkTools_ShapeDataSource()
// Purpose : // Purpose :
//================================================================ //================================================================
IVtkTools_ShapeDataSource::~IVtkTools_ShapeDataSource() IVtkTools_ShapeDataSource::~IVtkTools_ShapeDataSource()
{ } {
//
}
//================================================================ //================================================================
// Function : SetShape // Function : SetShape
@ -62,29 +64,13 @@ IVtkTools_ShapeDataSource::~IVtkTools_ShapeDataSource()
//================================================================ //================================================================
void IVtkTools_ShapeDataSource::SetShape (const IVtkOCC_Shape::Handle& theOccShape) void IVtkTools_ShapeDataSource::SetShape (const IVtkOCC_Shape::Handle& theOccShape)
{ {
if (myIsFastTransformMode && !myOccShape.IsNull() && myIsTransformOnly = myIsFastTransformMode
theOccShape->GetShape().IsPartner (myOccShape->GetShape() ) ) && !myOccShape.IsNull()
{ && theOccShape->GetShape().IsPartner (myOccShape->GetShape());
myIsTransformOnly = Standard_True;
}
else
{
myIsTransformOnly = Standard_False;
}
myOccShape = theOccShape; myOccShape = theOccShape;
this->Modified(); this->Modified();
} }
//================================================================
// Function : GetShape
// Purpose :
//================================================================
IVtkOCC_Shape::Handle IVtkTools_ShapeDataSource::GetShape()
{
return myOccShape;
}
//================================================================ //================================================================
// Function : RequestData // Function : RequestData
// Purpose : // Purpose :
@ -94,16 +80,18 @@ int IVtkTools_ShapeDataSource::RequestData(vtkInformation *vtkNotUsed(the
vtkInformationVector *theOutputVector) vtkInformationVector *theOutputVector)
{ {
vtkSmartPointer<vtkPolyData> aPolyData = vtkPolyData::GetData (theOutputVector); vtkSmartPointer<vtkPolyData> aPolyData = vtkPolyData::GetData (theOutputVector);
if (aPolyData.GetPointer() != NULL) if (aPolyData.GetPointer() == NULL)
{ {
return 1;
}
aPolyData->Allocate(); aPolyData->Allocate();
vtkSmartPointer<vtkPoints> aPts = vtkSmartPointer<vtkPoints>::New(); vtkSmartPointer<vtkPoints> aPts = vtkSmartPointer<vtkPoints>::New();
aPolyData->SetPoints (aPts); aPolyData->SetPoints (aPts);
vtkSmartPointer<vtkPolyData> aTransformedData; vtkSmartPointer<vtkPolyData> aTransformedData;
TopoDS_Shape aShape = myOccShape->GetShape(); TopoDS_Shape aShape = myOccShape->GetShape();
TopLoc_Location aShapeLoc = aShape.Location(); const TopLoc_Location aShapeLoc = aShape.Location();
if (myIsTransformOnly) if (myIsTransformOnly)
{ {
vtkSmartPointer<vtkPolyData> aPrevData = myPolyData->getVtkPolyData(); vtkSmartPointer<vtkPolyData> aPrevData = myPolyData->getVtkPolyData();
@ -118,25 +106,23 @@ int IVtkTools_ShapeDataSource::RequestData(vtkInformation *vtkNotUsed(the
} }
else else
{ {
IVtkOCC_Shape::Handle aShapeWrapperCopy; IVtkOCC_Shape::Handle aShapeWrapperCopy = myOccShape;
if ( myIsFastTransformMode && !aShapeLoc.IsIdentity() ) if (myIsFastTransformMode
&& !aShapeLoc.IsIdentity())
{ {
// Reset location before meshing // Reset location before meshing
aShape.Location (TopLoc_Location()); aShape.Location (TopLoc_Location());
aShapeWrapperCopy = new IVtkOCC_Shape (aShape); aShapeWrapperCopy = new IVtkOCC_Shape (aShape);
aShapeWrapperCopy->SetAttributes (myOccShape->Attributes());
aShapeWrapperCopy->SetId (myOccShape->GetId()); aShapeWrapperCopy->SetId (myOccShape->GetId());
} }
else
{
aShapeWrapperCopy = myOccShape;
}
myPolyData = new IVtkVTK_ShapeData; myPolyData = new IVtkVTK_ShapeData();
IVtkOCC_ShapeMesher::Handle aMesher = new IVtkOCC_ShapeMesher; IVtkOCC_ShapeMesher::Handle aMesher = new IVtkOCC_ShapeMesher();
aMesher->Build (aShapeWrapperCopy, myPolyData); aMesher->Build (aShapeWrapperCopy, myPolyData);
vtkSmartPointer<vtkPolyData> aMeshData = myPolyData->getVtkPolyData(); vtkSmartPointer<vtkPolyData> aMeshData = myPolyData->getVtkPolyData();
if (myIsFastTransformMode
if ( myIsFastTransformMode && !aShapeLoc.IsIdentity() ) && !aShapeLoc.IsIdentity())
{ {
aTransformedData = this->transform (aMeshData, aShapeLoc); aTransformedData = this->transform (aMeshData, aShapeLoc);
} }
@ -155,8 +141,6 @@ int IVtkTools_ShapeDataSource::RequestData(vtkInformation *vtkNotUsed(the
// OccShape easily given the actor instance. // OccShape easily given the actor instance.
IVtkTools_ShapeObject::SetShapeSource (this, aPolyData); IVtkTools_ShapeObject::SetShapeSource (this, aPolyData);
aPolyData->GetAttributes (vtkDataObject::CELL)->SetPedigreeIds (SubShapeIDs()); aPolyData->GetAttributes (vtkDataObject::CELL)->SetPedigreeIds (SubShapeIDs());
}
return 1; return 1;
} }
@ -166,10 +150,8 @@ int IVtkTools_ShapeDataSource::RequestData(vtkInformation *vtkNotUsed(the
//================================================================ //================================================================
vtkSmartPointer<vtkIdTypeArray> IVtkTools_ShapeDataSource::SubShapeIDs() vtkSmartPointer<vtkIdTypeArray> IVtkTools_ShapeDataSource::SubShapeIDs()
{ {
vtkSmartPointer<vtkDataArray> arr = vtkSmartPointer<vtkDataArray> anArr = GetOutput()->GetCellData()->GetArray(IVtkVTK_ShapeData::ARRNAME_SUBSHAPE_IDS());
GetOutput()->GetCellData()->GetArray(IVtkVTK_ShapeData::ARRNAME_SUBSHAPE_IDS()); return vtkSmartPointer<vtkIdTypeArray> (vtkIdTypeArray::SafeDownCast (anArr.GetPointer()));
return vtkSmartPointer<vtkIdTypeArray>(
vtkIdTypeArray::SafeDownCast(arr.GetPointer()) );
} }
//================================================================ //================================================================
@ -185,9 +167,9 @@ IVtk_IdType IVtkTools_ShapeDataSource::GetId() const
// Function : Contains // Function : Contains
// Purpose : // Purpose :
//================================================================ //================================================================
Standard_Boolean IVtkTools_ShapeDataSource::Contains (const IVtkOCC_Shape::Handle& shape) const Standard_Boolean IVtkTools_ShapeDataSource::Contains (const IVtkOCC_Shape::Handle& theShape) const
{ {
return ((myOccShape == shape) ? Standard_True : Standard_False); return myOccShape == theShape;
} }
//================================================================ //================================================================
@ -205,10 +187,12 @@ vtkSmartPointer<vtkPolyData> IVtkTools_ShapeDataSource::transform (vtkPolyData*
vtkSmartPointer<vtkTransform> aTransform = vtkSmartPointer<vtkTransform>::New(); vtkSmartPointer<vtkTransform> aTransform = vtkSmartPointer<vtkTransform>::New();
vtkSmartPointer<vtkMatrix4x4> aMx = vtkSmartPointer<vtkMatrix4x4>::New(); vtkSmartPointer<vtkMatrix4x4> aMx = vtkSmartPointer<vtkMatrix4x4>::New();
for (Standard_Integer aRow = 0; aRow < 3; ++aRow) for (Standard_Integer aRow = 0; aRow < 3; ++aRow)
{
for (Standard_Integer aCol = 0; aCol < 4; ++aCol) for (Standard_Integer aCol = 0; aCol < 4; ++aCol)
{ {
aMx->SetElement (aRow, aCol, theTrsf.Value (aRow + 1, aCol + 1) ); aMx->SetElement (aRow, aCol, theTrsf.Value (aRow + 1, aCol + 1) );
} }
}
aTransform->SetMatrix (aMx); aTransform->SetMatrix (aMx);
vtkSmartPointer<vtkTransformPolyDataFilter> aTrsfFilter vtkSmartPointer<vtkTransformPolyDataFilter> aTrsfFilter

View File

@ -51,7 +51,8 @@ public: //! @name Initialization
//! Get the source OCCT shape. //! Get the source OCCT shape.
//! @return occShape OCCT shape wrapper. //! @return occShape OCCT shape wrapper.
IVtkOCC_Shape::Handle GetShape(); const IVtkOCC_Shape::Handle& GetShape() { return myOccShape; }
inline void FastTransformModeOn() { myIsFastTransformMode = true; } inline void FastTransformModeOn() { myIsFastTransformMode = true; }
inline void FastTransformModeOff() { myIsFastTransformMode = false; } inline void FastTransformModeOff() { myIsFastTransformMode = false; }
@ -82,7 +83,7 @@ protected: //! @name Interface to override
//! @param theOutputVector [in] the pointer to output data, that is filled in this method. //! @param theOutputVector [in] the pointer to output data, that is filled in this method.
virtual int RequestData(vtkInformation* theRequest, virtual int RequestData(vtkInformation* theRequest,
vtkInformationVector** theInputVector, vtkInformationVector** theInputVector,
vtkInformationVector* theOutputVector); vtkInformationVector* theOutputVector) Standard_OVERRIDE;
protected: //! @name Internals protected: //! @name Internals

View File

@ -39,7 +39,7 @@ class IVtkTools_ShapeDataSource;
//! @class IVtkTools_ShapeObject //! @class IVtkTools_ShapeObject
//! @brief VTK holder class for OCC shapes to pass them through pipelines. //! @brief VTK holder class for OCC shapes to pass them through pipelines.
//! //!
//! It is descendent of vtkObject (data). Logically it is a one of milestones of VTK pipeline. //! It is descendant of vtkObject (data). Logically it is a one of milestones of VTK pipeline.
//! It stores data of OCC shape (the OccShape instance) in vtkInformation object of vtkDataObject. //! It stores data of OCC shape (the OccShape instance) in vtkInformation object of vtkDataObject.
//! Then pass it to the actors through pipelines, //! Then pass it to the actors through pipelines,
//! so selection logic can access OccShape easily given the actor instance. //! so selection logic can access OccShape easily given the actor instance.

View File

@ -49,7 +49,7 @@ public:
//! Pick entities in the given point. //! Pick entities in the given point.
//! @return Number of detected entities. //! @return Number of detected entities.
int Pick (double theX, double theY, double theZ, vtkRenderer *theRenderer = NULL); virtual int Pick (double theX, double theY, double theZ, vtkRenderer *theRenderer = NULL) Standard_OVERRIDE;
//! Pick entities in the given rectangle area. //! Pick entities in the given rectangle area.
//! @return Number of detected entities. //! @return Number of detected entities.

View File

@ -60,7 +60,7 @@ public:
protected: protected:
//! @brief Filter cells according to the given set of ids. //! @brief Filter cells according to the given set of ids.
//! Note: Data arrays are not passed through if filtering is turned on. //! Note: Data arrays are not passed through if filtering is turned on.
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *); virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) Standard_OVERRIDE;
IVtkTools_SubPolyDataFilter(); IVtkTools_SubPolyDataFilter();
virtual ~IVtkTools_SubPolyDataFilter(); virtual ~IVtkTools_SubPolyDataFilter();

View File

@ -13,7 +13,6 @@
// Alternatively, this file may be used under the terms of Open CASCADE // Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement. // commercial license or contractual agreement.
#include <IVtkVTK_View.hxx> #include <IVtkVTK_View.hxx>
// prevent disabling some MSVC warning messages by VTK headers // prevent disabling some MSVC warning messages by VTK headers

19
tests/vtk/ivtk/autotriang Normal file
View File

@ -0,0 +1,19 @@
puts "============"
puts "0032247: VIS, IVtkOCC_ShapeMesher - allow disabling auto-triangulation behavior"
puts "============"
puts ""
pload MODELING VIS
psphere s 1
explode s F
tessellate r s_1 10 10
trinfo r
checktrinfo r -tri 200
ivtkinit
ivtkdefaults -autoTriang 0
ivtkdisplay r
ivtksetdispmode 1
checktrinfo r -tri 200
ivtkdump $imagedir/${casename}.png