1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +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

@@ -60,7 +60,7 @@ public:
protected:
//! 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();
virtual ~IVtkTools_DisplayModeFilter();

View File

@@ -38,10 +38,10 @@ vtkStandardNewMacro(IVtkTools_ShapeDataSource)
//================================================================
// Function : Constructor
// Purpose :
// Purpose :
//================================================================
IVtkTools_ShapeDataSource::IVtkTools_ShapeDataSource()
: myPolyData (new IVtkVTK_ShapeData),
: myPolyData (new IVtkVTK_ShapeData()),
myIsFastTransformMode (Standard_False),
myIsTransformOnly (Standard_False)
{
@@ -51,130 +51,112 @@ IVtkTools_ShapeDataSource::IVtkTools_ShapeDataSource()
//================================================================
// Function : Destructor
// Purpose :
// Purpose :
//================================================================
IVtkTools_ShapeDataSource::~IVtkTools_ShapeDataSource()
{ }
{
//
}
//================================================================
// Function : SetShape
// Purpose :
// Purpose :
//================================================================
void IVtkTools_ShapeDataSource::SetShape (const IVtkOCC_Shape::Handle& theOccShape)
{
if (myIsFastTransformMode && !myOccShape.IsNull() &&
theOccShape->GetShape().IsPartner (myOccShape->GetShape() ) )
{
myIsTransformOnly = Standard_True;
}
else
{
myIsTransformOnly = Standard_False;
}
myIsTransformOnly = myIsFastTransformMode
&& !myOccShape.IsNull()
&& theOccShape->GetShape().IsPartner (myOccShape->GetShape());
myOccShape = theOccShape;
this->Modified();
}
//================================================================
// Function : GetShape
// Purpose :
//================================================================
IVtkOCC_Shape::Handle IVtkTools_ShapeDataSource::GetShape()
{
return myOccShape;
}
//================================================================
// Function : RequestData
// Purpose :
// Purpose :
//================================================================
int IVtkTools_ShapeDataSource::RequestData(vtkInformation *vtkNotUsed(theRequest),
vtkInformationVector **vtkNotUsed(theInputVector),
vtkInformationVector *theOutputVector)
{
vtkSmartPointer<vtkPolyData> aPolyData = vtkPolyData::GetData (theOutputVector);
if (aPolyData.GetPointer() != NULL)
if (aPolyData.GetPointer() == NULL)
{
aPolyData->Allocate();
vtkSmartPointer<vtkPoints> aPts = vtkSmartPointer<vtkPoints>::New();
aPolyData->SetPoints (aPts);
return 1;
}
vtkSmartPointer<vtkPolyData> aTransformedData;
TopoDS_Shape aShape = myOccShape->GetShape();
TopLoc_Location aShapeLoc = aShape.Location();
aPolyData->Allocate();
vtkSmartPointer<vtkPoints> aPts = vtkSmartPointer<vtkPoints>::New();
aPolyData->SetPoints (aPts);
if (myIsTransformOnly)
vtkSmartPointer<vtkPolyData> aTransformedData;
TopoDS_Shape aShape = myOccShape->GetShape();
const TopLoc_Location aShapeLoc = aShape.Location();
if (myIsTransformOnly)
{
vtkSmartPointer<vtkPolyData> aPrevData = myPolyData->getVtkPolyData();
if (!aShapeLoc.IsIdentity())
{
vtkSmartPointer<vtkPolyData> aPrevData = myPolyData->getVtkPolyData();
if ( !aShapeLoc.IsIdentity() )
{
aTransformedData = this->transform (aPrevData, aShapeLoc);
}
else
{
aTransformedData = aPrevData;
}
aTransformedData = this->transform (aPrevData, aShapeLoc);
}
else
{
IVtkOCC_Shape::Handle aShapeWrapperCopy;
if ( myIsFastTransformMode && !aShapeLoc.IsIdentity() )
{
// Reset location before meshing
aShape.Location (TopLoc_Location());
aShapeWrapperCopy = new IVtkOCC_Shape (aShape);
aShapeWrapperCopy->SetId (myOccShape->GetId());
}
else
{
aShapeWrapperCopy = myOccShape;
}
myPolyData = new IVtkVTK_ShapeData;
IVtkOCC_ShapeMesher::Handle aMesher = new IVtkOCC_ShapeMesher;
aMesher->Build (aShapeWrapperCopy, myPolyData);
vtkSmartPointer<vtkPolyData> aMeshData = myPolyData->getVtkPolyData();
if ( myIsFastTransformMode && !aShapeLoc.IsIdentity() )
{
aTransformedData = this->transform (aMeshData, aShapeLoc);
}
else
{
aTransformedData = aMeshData;
}
aTransformedData = aPrevData;
}
}
else
{
IVtkOCC_Shape::Handle aShapeWrapperCopy = myOccShape;
if (myIsFastTransformMode
&& !aShapeLoc.IsIdentity())
{
// Reset location before meshing
aShape.Location (TopLoc_Location());
aShapeWrapperCopy = new IVtkOCC_Shape (aShape);
aShapeWrapperCopy->SetAttributes (myOccShape->Attributes());
aShapeWrapperCopy->SetId (myOccShape->GetId());
}
aPolyData->CopyStructure (aTransformedData); // Copy points and cells
aPolyData->CopyAttributes (aTransformedData); // Copy data arrays (sub-shapes IDs)
// We store the OccShape instance in a IVtkTools_ShapeObject
// wrapper in vtkInformation object of vtkDataObject, then pass it
// to the actors through pipelines, so selection logic can access
// OccShape easily given the actor instance.
IVtkTools_ShapeObject::SetShapeSource (this, aPolyData);
aPolyData->GetAttributes (vtkDataObject::CELL)->SetPedigreeIds (SubShapeIDs());
myPolyData = new IVtkVTK_ShapeData();
IVtkOCC_ShapeMesher::Handle aMesher = new IVtkOCC_ShapeMesher();
aMesher->Build (aShapeWrapperCopy, myPolyData);
vtkSmartPointer<vtkPolyData> aMeshData = myPolyData->getVtkPolyData();
if (myIsFastTransformMode
&& !aShapeLoc.IsIdentity())
{
aTransformedData = this->transform (aMeshData, aShapeLoc);
}
else
{
aTransformedData = aMeshData;
}
}
aPolyData->CopyStructure (aTransformedData); // Copy points and cells
aPolyData->CopyAttributes (aTransformedData); // Copy data arrays (sub-shapes IDs)
// We store the OccShape instance in a IVtkTools_ShapeObject
// wrapper in vtkInformation object of vtkDataObject, then pass it
// to the actors through pipelines, so selection logic can access
// OccShape easily given the actor instance.
IVtkTools_ShapeObject::SetShapeSource (this, aPolyData);
aPolyData->GetAttributes (vtkDataObject::CELL)->SetPedigreeIds (SubShapeIDs());
return 1;
}
//================================================================
// Function : SubShapeIDs
// Purpose :
// Purpose :
//================================================================
vtkSmartPointer<vtkIdTypeArray> IVtkTools_ShapeDataSource::SubShapeIDs()
{
vtkSmartPointer<vtkDataArray> arr =
GetOutput()->GetCellData()->GetArray(IVtkVTK_ShapeData::ARRNAME_SUBSHAPE_IDS());
return vtkSmartPointer<vtkIdTypeArray>(
vtkIdTypeArray::SafeDownCast(arr.GetPointer()) );
vtkSmartPointer<vtkDataArray> anArr = GetOutput()->GetCellData()->GetArray(IVtkVTK_ShapeData::ARRNAME_SUBSHAPE_IDS());
return vtkSmartPointer<vtkIdTypeArray> (vtkIdTypeArray::SafeDownCast (anArr.GetPointer()));
}
//================================================================
// Function : GetId
// Purpose :
// Purpose :
//================================================================
IVtk_IdType IVtkTools_ShapeDataSource::GetId() const
{
@@ -183,16 +165,16 @@ IVtk_IdType IVtkTools_ShapeDataSource::GetId() const
//================================================================
// 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;
}
//================================================================
// Function : transform
// Purpose :
// Purpose :
//================================================================
vtkSmartPointer<vtkPolyData> IVtkTools_ShapeDataSource::transform (vtkPolyData* theSource,
const gp_Trsf& theTrsf) const
@@ -205,10 +187,12 @@ vtkSmartPointer<vtkPolyData> IVtkTools_ShapeDataSource::transform (vtkPolyData*
vtkSmartPointer<vtkTransform> aTransform = vtkSmartPointer<vtkTransform>::New();
vtkSmartPointer<vtkMatrix4x4> aMx = vtkSmartPointer<vtkMatrix4x4>::New();
for (Standard_Integer aRow = 0; aRow < 3; ++aRow)
{
for (Standard_Integer aCol = 0; aCol < 4; ++aCol)
{
aMx->SetElement (aRow, aCol, theTrsf.Value (aRow + 1, aCol + 1) );
}
}
aTransform->SetMatrix (aMx);
vtkSmartPointer<vtkTransformPolyDataFilter> aTrsfFilter

View File

@@ -51,7 +51,8 @@ public: //! @name Initialization
//! Get the source OCCT shape.
//! @return occShape OCCT shape wrapper.
IVtkOCC_Shape::Handle GetShape();
const IVtkOCC_Shape::Handle& GetShape() { return myOccShape; }
inline void FastTransformModeOn() { myIsFastTransformMode = true; }
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.
virtual int RequestData(vtkInformation* theRequest,
vtkInformationVector** theInputVector,
vtkInformationVector* theOutputVector);
vtkInformationVector* theOutputVector) Standard_OVERRIDE;
protected: //! @name Internals

View File

@@ -39,7 +39,7 @@ class IVtkTools_ShapeDataSource;
//! @class IVtkTools_ShapeObject
//! @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.
//! Then pass it to the actors through pipelines,
//! so selection logic can access OccShape easily given the actor instance.

View File

@@ -49,7 +49,7 @@ public:
//! Pick entities in the given point.
//! @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.
//! @return Number of detected entities.

View File

@@ -60,7 +60,7 @@ public:
protected:
//! @brief Filter cells according to the given set of ids.
//! 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();
virtual ~IVtkTools_SubPolyDataFilter();