mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-14 13:30:48 +03:00
0027567: VIS - possible memory leaks due to use of plain pointers: Fix also the VIS guide. Add the test v3d/ivtk/bug27567. Add a draw command "ivtkremove".
0027734: Configuration - TKIVtkDraw build fails with TBB: Remove unnecessary define statement (windows specific). Small correction of test case for issue CR27567
This commit is contained in:
@@ -24,9 +24,10 @@ namespace IVtkTools
|
||||
// Method: InitLookupTable
|
||||
// Purpose: Returns vtkLookupTable instance initialized by standrad OCCT colors.
|
||||
//============================================================================
|
||||
vtkLookupTable* InitLookupTable()
|
||||
vtkSmartPointer<vtkLookupTable> InitLookupTable()
|
||||
{
|
||||
vtkLookupTable* aColorTable = vtkLookupTable::New();
|
||||
vtkSmartPointer<vtkLookupTable> aColorTable =
|
||||
vtkSmartPointer<vtkLookupTable>::New();
|
||||
// Set colors table for 3D shapes
|
||||
double aRange[2];
|
||||
aRange[0] = MT_Undefined;
|
||||
|
@@ -17,6 +17,7 @@
|
||||
#define IVtkTOOLS_H
|
||||
|
||||
#include <IVtk_Types.hxx>
|
||||
#include <vtkSmartPointer.h>
|
||||
|
||||
#if defined(_WIN32) && !defined(HAVE_NO_DLL)
|
||||
#ifdef __IVtkTools_DLL
|
||||
@@ -38,7 +39,7 @@ namespace IVtkTools
|
||||
//! Returns vtkLookupTable instance initialized by standrad OCCT colors used
|
||||
//! in wireframe mode for different kinds of sub-shapes (free/boundary/shared
|
||||
//! edges, isolines,...)
|
||||
Standard_EXPORT vtkLookupTable* InitLookupTable();
|
||||
Standard_EXPORT vtkSmartPointer<vtkLookupTable> InitLookupTable();
|
||||
|
||||
//! Set a color for given type of sub-shapes.
|
||||
//! @param [in,out] theColorTable vtkLookupTable to set the color.
|
||||
|
@@ -18,7 +18,6 @@
|
||||
|
||||
#include <IVtkTools.hxx>
|
||||
#include <IVtkTools_SubPolyDataFilter.hxx>
|
||||
#include <IVtk_Types.hxx>
|
||||
#include <NCollection_DataMap.hxx>
|
||||
|
||||
//! @class IVtkTools_DisplayModeFilter
|
||||
@@ -47,7 +46,7 @@ protected:
|
||||
virtual int RequestData (vtkInformation *, vtkInformationVector **, vtkInformationVector *);
|
||||
|
||||
IVtkTools_DisplayModeFilter();
|
||||
~IVtkTools_DisplayModeFilter();
|
||||
virtual ~IVtkTools_DisplayModeFilter();
|
||||
|
||||
protected:
|
||||
//! Display mode defining mesh types to pass through this filter.
|
||||
|
@@ -14,20 +14,17 @@
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
// VIS includes
|
||||
#include <IVtkOCC_ShapeMesher.hxx>
|
||||
#include <IVtkTools_ShapeDataSource.hxx>
|
||||
#include <IVtkOCC_ShapeMesher.hxx>
|
||||
#include <IVtkTools_ShapeObject.hxx>
|
||||
|
||||
// VTK includes
|
||||
#include <vtkCellArray.h>
|
||||
#include <vtkObjectFactory.h>
|
||||
#include <vtkCellData.h>
|
||||
#include <vtkDoubleArray.h>
|
||||
#include <vtkIdTypeArray.h>
|
||||
#include <vtkInformation.h>
|
||||
#include <vtkObjectFactory.h>
|
||||
#include <vtkPoints.h>
|
||||
#include <vtkPolyData.h>
|
||||
#include <vtkStreamingDemandDrivenPipeline.h>
|
||||
#include <vtkTransform.h>
|
||||
#include <vtkTransformPolyDataFilter.h>
|
||||
|
||||
@@ -42,7 +39,8 @@ IVtkTools_ShapeDataSource::IVtkTools_ShapeDataSource()
|
||||
myIsFastTransformMode (Standard_False),
|
||||
myIsTransformOnly (Standard_False)
|
||||
{
|
||||
this->SetNumberOfInputPorts (0);
|
||||
this->SetNumberOfInputPorts(0);
|
||||
this->SetNumberOfOutputPorts(1);
|
||||
}
|
||||
|
||||
//================================================================
|
||||
@@ -85,73 +83,75 @@ IVtkOCC_Shape::Handle IVtkTools_ShapeDataSource::GetShape()
|
||||
// Function : RequestData
|
||||
// Purpose :
|
||||
//================================================================
|
||||
int IVtkTools_ShapeDataSource::RequestData (vtkInformation* theRequest,
|
||||
vtkInformationVector** theInputVector,
|
||||
vtkInformationVector* theOutputVector)
|
||||
int IVtkTools_ShapeDataSource::RequestData(vtkInformation *vtkNotUsed(theRequest),
|
||||
vtkInformationVector **vtkNotUsed(theInputVector),
|
||||
vtkInformationVector *theOutputVector)
|
||||
{
|
||||
vtkPolyData* aPolyData = vtkPolyData::GetData (theOutputVector);
|
||||
aPolyData->Allocate();
|
||||
vtkPoints* aPts = vtkPoints::New();
|
||||
aPolyData->SetPoints (aPts);
|
||||
aPts->Delete();
|
||||
|
||||
vtkSmartPointer<vtkPolyData> aTransformedData;
|
||||
TopoDS_Shape aShape = myOccShape->GetShape();
|
||||
TopLoc_Location aShapeLoc = aShape.Location();
|
||||
|
||||
if (myIsTransformOnly)
|
||||
vtkSmartPointer<vtkPolyData> aPolyData = vtkPolyData::GetData (theOutputVector);
|
||||
if (aPolyData.GetPointer() != NULL)
|
||||
{
|
||||
vtkPolyData* aPrevData = myPolyData->getVtkPolyData();
|
||||
if (!aShapeLoc.IsIdentity() )
|
||||
aPolyData->Allocate();
|
||||
vtkSmartPointer<vtkPoints> aPts = vtkSmartPointer<vtkPoints>::New();
|
||||
aPolyData->SetPoints (aPts);
|
||||
|
||||
vtkSmartPointer<vtkPolyData> aTransformedData;
|
||||
TopoDS_Shape aShape = myOccShape->GetShape();
|
||||
TopLoc_Location aShapeLoc = aShape.Location();
|
||||
|
||||
if (myIsTransformOnly)
|
||||
{
|
||||
aTransformedData = this->transform (aPrevData, aShapeLoc);
|
||||
vtkSmartPointer<vtkPolyData> aPrevData = myPolyData->getVtkPolyData();
|
||||
if ( !aShapeLoc.IsIdentity() )
|
||||
{
|
||||
aTransformedData = this->transform (aPrevData, aShapeLoc);
|
||||
}
|
||||
else
|
||||
{
|
||||
aTransformedData = aPrevData;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
aTransformedData = aPrevData;
|
||||
}
|
||||
}
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
myPolyData = new IVtkVTK_ShapeData;
|
||||
IVtkOCC_ShapeMesher::Handle aMesher = new IVtkOCC_ShapeMesher;
|
||||
aMesher->Build (aShapeWrapperCopy, myPolyData);
|
||||
vtkPolyData* aMeshData = myPolyData->getVtkPolyData();
|
||||
aPolyData->CopyStructure (aTransformedData); // Copy points and cells
|
||||
aPolyData->CopyAttributes (aTransformedData); // Copy data arrays (sub-shapes IDs)
|
||||
|
||||
if (myIsFastTransformMode && !aShapeLoc.IsIdentity() )
|
||||
{
|
||||
aTransformedData = this->transform (aMeshData, aShapeLoc);
|
||||
}
|
||||
else
|
||||
{
|
||||
aTransformedData = aMeshData;
|
||||
}
|
||||
// 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());
|
||||
}
|
||||
|
||||
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 Superclass::RequestData (theRequest, theInputVector, theOutputVector);
|
||||
return 1;
|
||||
}
|
||||
|
||||
//================================================================
|
||||
@@ -160,8 +160,10 @@ int IVtkTools_ShapeDataSource::RequestData (vtkInformation* theRequest,
|
||||
//================================================================
|
||||
vtkSmartPointer<vtkIdTypeArray> IVtkTools_ShapeDataSource::SubShapeIDs()
|
||||
{
|
||||
vtkDataArray* arr = GetOutput()->GetCellData()->GetArray(IVtkVTK_ShapeData::ARRNAME_SUBSHAPE_IDS);
|
||||
return vtkSmartPointer<vtkIdTypeArray>( vtkIdTypeArray::SafeDownCast(arr) );
|
||||
vtkSmartPointer<vtkDataArray> arr =
|
||||
GetOutput()->GetCellData()->GetArray(IVtkVTK_ShapeData::ARRNAME_SUBSHAPE_IDS);
|
||||
return vtkSmartPointer<vtkIdTypeArray>(
|
||||
vtkIdTypeArray::SafeDownCast(arr.GetPointer()) );
|
||||
}
|
||||
|
||||
//================================================================
|
||||
@@ -210,7 +212,7 @@ vtkSmartPointer<vtkPolyData> IVtkTools_ShapeDataSource::transform (vtkPolyData*
|
||||
aTrsfFilter->SetInputData (theSource);
|
||||
aTrsfFilter->Update();
|
||||
|
||||
vtkPolyData* aTransformed = aTrsfFilter->GetOutput();
|
||||
vtkSmartPointer<vtkPolyData> aTransformed = aTrsfFilter->GetOutput();
|
||||
aResult->CopyStructure (aTransformed); // Copy points and cells
|
||||
aResult->CopyAttributes (aTransformed); // Copy data arrays (sub-shapes ids)
|
||||
|
||||
|
@@ -19,10 +19,7 @@
|
||||
#include <IVtkTools.hxx>
|
||||
#include <IVtkOCC_Shape.hxx>
|
||||
#include <IVtkVTK_ShapeData.hxx>
|
||||
#include <vtkInformationIdTypeKey.h>
|
||||
#include <vtkPolyDataAlgorithm.h>
|
||||
#include <vtkType.h>
|
||||
#include <vtkSmartPointer.h>
|
||||
|
||||
class vtkIdTypeArray;
|
||||
class vtkPolyData;
|
||||
@@ -91,7 +88,7 @@ protected: //! @name Internals
|
||||
protected:
|
||||
|
||||
IVtkTools_ShapeDataSource();
|
||||
~IVtkTools_ShapeDataSource();
|
||||
virtual ~IVtkTools_ShapeDataSource();
|
||||
|
||||
private:
|
||||
|
||||
|
@@ -16,12 +16,10 @@
|
||||
#include <IVtkTools_ShapeObject.hxx>
|
||||
#include <IVtkTools_ShapeDataSource.hxx>
|
||||
#include <vtkActor.h>
|
||||
#include <vtkObjectBase.h>
|
||||
#include <vtkObjectFactory.h>
|
||||
#include <vtkDataSet.h>
|
||||
#include <vtkInformation.h>
|
||||
#include <vtkInformationObjectBaseKey.h>
|
||||
#include <vtkDebugLeaks.h>
|
||||
#include <vtkPolyData.h>
|
||||
|
||||
IVtkTools_ShapeObject::KeyPtr IVtkTools_ShapeObject::myKey = 0;
|
||||
@@ -49,8 +47,9 @@ IVtkTools_ShapeObject::KeyPtr IVtkTools_ShapeObject::getKey()
|
||||
IVtkOCC_Shape::Handle IVtkTools_ShapeObject::GetOccShape (vtkActor* theActor)
|
||||
{
|
||||
IVtkOCC_Shape::Handle anOccShape;
|
||||
IVtkTools_ShapeDataSource* aSrc = IVtkTools_ShapeObject::GetShapeSource (theActor);
|
||||
if (aSrc)
|
||||
vtkSmartPointer<IVtkTools_ShapeDataSource> aSrc =
|
||||
IVtkTools_ShapeObject::GetShapeSource (theActor);
|
||||
if (aSrc.GetPointer() != NULL)
|
||||
{
|
||||
anOccShape = aSrc->GetShape();
|
||||
}
|
||||
@@ -62,16 +61,18 @@ IVtkOCC_Shape::Handle IVtkTools_ShapeObject::GetOccShape (vtkActor* theActor)
|
||||
// Purpose: Static method to get OCC shape source from VTK actor's data from
|
||||
// information object by key.
|
||||
//============================================================================
|
||||
IVtkTools_ShapeDataSource* IVtkTools_ShapeObject::GetShapeSource (vtkActor* theActor)
|
||||
vtkSmartPointer<IVtkTools_ShapeDataSource> IVtkTools_ShapeObject
|
||||
::GetShapeSource (vtkActor* theActor)
|
||||
{
|
||||
IVtkTools_ShapeDataSource* anOccShapeSource = 0;
|
||||
vtkInformation* anInfo = theActor->GetPropertyKeys();
|
||||
if (anInfo)
|
||||
vtkSmartPointer<IVtkTools_ShapeDataSource> anOccShapeSource;
|
||||
vtkSmartPointer<vtkInformation> anInfo = theActor->GetPropertyKeys();
|
||||
if (anInfo.GetPointer() != NULL)
|
||||
{
|
||||
KeyPtr aKey = getKey();
|
||||
if (aKey->Has(anInfo))
|
||||
{
|
||||
IVtkTools_ShapeObject* aShapeObj = (IVtkTools_ShapeObject*)(aKey->Get (anInfo));
|
||||
vtkSmartPointer<IVtkTools_ShapeObject> aShapeObj =
|
||||
IVtkTools_ShapeObject::SafeDownCast(aKey->Get (anInfo));
|
||||
anOccShapeSource = aShapeObj->GetShapeSource();
|
||||
}
|
||||
}
|
||||
@@ -88,14 +89,14 @@ void IVtkTools_ShapeObject::SetShapeSource (IVtkTools_ShapeDataSource* theDataSo
|
||||
{
|
||||
if (!theDataSet->GetInformation() )
|
||||
{
|
||||
theDataSet->SetInformation (vtkInformation::New());
|
||||
theDataSet->SetInformation (vtkSmartPointer<vtkInformation>::New());
|
||||
}
|
||||
vtkInformation* aDatasetInfo = theDataSet->GetInformation();
|
||||
vtkSmartPointer<vtkInformation> aDatasetInfo = theDataSet->GetInformation();
|
||||
KeyPtr aKey = getKey();
|
||||
IVtkTools_ShapeObject* aShapeObj = IVtkTools_ShapeObject::New();
|
||||
vtkSmartPointer<IVtkTools_ShapeObject> aShapeObj =
|
||||
vtkSmartPointer<IVtkTools_ShapeObject>::New();
|
||||
aShapeObj->SetShapeSource (theDataSource);
|
||||
aKey->Set(aDatasetInfo, aShapeObj);
|
||||
aShapeObj->Delete();
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
@@ -108,15 +109,15 @@ void IVtkTools_ShapeObject::SetShapeSource (IVtkTools_ShapeDataSource* theDataSo
|
||||
{
|
||||
if ( !theActor->GetPropertyKeys() )
|
||||
{
|
||||
theActor->SetPropertyKeys (vtkInformation::New());
|
||||
theActor->SetPropertyKeys (vtkSmartPointer<vtkInformation>::New());
|
||||
}
|
||||
|
||||
vtkInformation* anInfo = theActor->GetPropertyKeys();
|
||||
vtkSmartPointer<vtkInformation> anInfo = theActor->GetPropertyKeys();
|
||||
KeyPtr aKey = getKey();
|
||||
IVtkTools_ShapeObject* aShapeObj = IVtkTools_ShapeObject::New();
|
||||
aShapeObj->SetShapeSource (theDataSource);
|
||||
vtkSmartPointer<IVtkTools_ShapeObject> aShapeObj =
|
||||
vtkSmartPointer<IVtkTools_ShapeObject>::New();
|
||||
aShapeObj->SetShapeSource(theDataSource);
|
||||
aKey->Set (anInfo, aShapeObj);
|
||||
aShapeObj->Delete();
|
||||
}
|
||||
|
||||
//! @class IVtkTools_ShapeObject
|
||||
@@ -150,7 +151,7 @@ void IVtkTools_ShapeObject::SetShapeSource (IVtkTools_ShapeDataSource* theDataSo
|
||||
// Method: GetShapeSource
|
||||
// Purpose:
|
||||
//============================================================================
|
||||
IVtkTools_ShapeDataSource* IVtkTools_ShapeObject::GetShapeSource () const
|
||||
IVtkTools_ShapeDataSource* IVtkTools_ShapeObject::GetShapeSource() const
|
||||
{
|
||||
return myShapeSource;
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@
|
||||
#include <IVtkOCC_Shape.hxx>
|
||||
#include <vtkDataObject.h>
|
||||
#include <vtkSetGet.h>
|
||||
#include <vtkSmartPointer.h>
|
||||
#include <vtkWeakPointer.h>
|
||||
|
||||
class vtkActor;
|
||||
class vtkDataSet;
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
static IVtkTools_ShapeObject* New();
|
||||
|
||||
//! Get OCC shape source from VTK data from actor's information object by key.
|
||||
static IVtkTools_ShapeDataSource* GetShapeSource (vtkActor* theActor);
|
||||
static vtkSmartPointer<IVtkTools_ShapeDataSource> GetShapeSource (vtkActor* theActor);
|
||||
|
||||
//! Get OCC shape from VTK data from actor's information object by key.
|
||||
static IVtkOCC_Shape::Handle GetOccShape (vtkActor* theActor);
|
||||
@@ -66,18 +66,18 @@ public:
|
||||
void SetShapeSource (IVtkTools_ShapeDataSource* theDataSource);
|
||||
|
||||
//! OCC shape source getter.
|
||||
IVtkTools_ShapeDataSource* GetShapeSource () const;
|
||||
IVtkTools_ShapeDataSource* GetShapeSource() const;
|
||||
|
||||
protected:
|
||||
IVtkTools_ShapeObject();
|
||||
~IVtkTools_ShapeObject();
|
||||
virtual ~IVtkTools_ShapeObject();
|
||||
|
||||
private: // not copyable
|
||||
IVtkTools_ShapeObject (const IVtkTools_ShapeObject&);
|
||||
IVtkTools_ShapeObject& operator= (const IVtkTools_ShapeObject&);
|
||||
|
||||
private: // OCC
|
||||
vtkSmartPointer<IVtkTools_ShapeDataSource> myShapeSource;
|
||||
vtkWeakPointer<IVtkTools_ShapeDataSource> myShapeSource;
|
||||
|
||||
static KeyPtr myKey;
|
||||
};
|
||||
|
@@ -16,7 +16,6 @@
|
||||
#include <IVtkTools_ShapePicker.hxx>
|
||||
#include <IVtkTools_ShapeObject.hxx>
|
||||
#include <IVtkVTK_View.hxx>
|
||||
#include <IVtkOCC_Shape.hxx>
|
||||
#include <vtkCommand.h>
|
||||
#include <vtkObjectFactory.h>
|
||||
#include <vtkRenderer.h>
|
||||
@@ -37,7 +36,7 @@ vtkStandardNewMacro(IVtkTools_ShapePicker)
|
||||
// Purpose: Constructs the picker with empty renderer and ready for point selection.
|
||||
//============================================================================
|
||||
IVtkTools_ShapePicker::IVtkTools_ShapePicker()
|
||||
: myRenderer (0),
|
||||
: myRenderer (NULL),
|
||||
myIsRectSelection (false)
|
||||
{
|
||||
myOccPickerAlgo = new IVtkOCC_ShapePickerAlgo();
|
||||
@@ -81,7 +80,8 @@ bool IVtkTools_ShapePicker::convertDisplayToWorld (vtkRenderer *theRenderer,
|
||||
theRenderer->SetDisplayPoint (theDisplayCoord[0], theDisplayCoord[1], theDisplayCoord[2]);
|
||||
theRenderer->DisplayToWorld();
|
||||
|
||||
double* const aCoords = theRenderer->GetWorldPoint();
|
||||
double aCoords[4];
|
||||
theRenderer->GetWorldPoint(aCoords);
|
||||
if (aCoords[3] == 0.0)
|
||||
{
|
||||
return false;
|
||||
@@ -91,6 +91,7 @@ bool IVtkTools_ShapePicker::convertDisplayToWorld (vtkRenderer *theRenderer,
|
||||
{
|
||||
theWorldCoord[anI] = aCoords[anI] / aCoords[3];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -144,7 +145,7 @@ int IVtkTools_ShapePicker::pick (double* thePos,
|
||||
// Emit StartPickEvent for observer callbacks (if any)
|
||||
InvokeEvent(vtkCommand::StartPickEvent, NULL);
|
||||
|
||||
vtkRenderer* aRenderer;
|
||||
vtkSmartPointer<vtkRenderer> aRenderer;
|
||||
if (theRenderer == NULL)
|
||||
{
|
||||
aRenderer = myRenderer; // by default use own renderer
|
||||
@@ -192,7 +193,7 @@ void IVtkTools_ShapePicker::doPickImpl (double* thePos,
|
||||
//============================================================================
|
||||
void IVtkTools_ShapePicker::SetRenderer (vtkRenderer* theRenderer)
|
||||
{
|
||||
if (theRenderer == myRenderer)
|
||||
if (theRenderer == myRenderer.GetPointer())
|
||||
{
|
||||
return;
|
||||
// In this case we should not do anything.
|
||||
@@ -273,12 +274,13 @@ void IVtkTools_ShapePicker::SetSelectionMode (vtkActor* theShapeA
|
||||
void IVtkTools_ShapePicker::SetSelectionMode (const IVtk_SelectionMode theMode,
|
||||
const bool theIsTurnOn) const
|
||||
{
|
||||
if (myRenderer)
|
||||
if (myRenderer.GetPointer() != NULL)
|
||||
{
|
||||
// Obtain all OccShapes displayed and activate the specified selection mode
|
||||
vtkActorCollection *anActors = myRenderer->GetActors();
|
||||
vtkSmartPointer<vtkActorCollection> anActors = myRenderer->GetActors();
|
||||
anActors->InitTraversal();
|
||||
while ( vtkActor* anActor = anActors->GetNextActor() )
|
||||
vtkSmartPointer<vtkActor> anActor = anActors->GetNextActor();
|
||||
while ( anActor.GetPointer() != NULL )
|
||||
{
|
||||
if (anActor->GetPickable() && anActor->GetVisibility())
|
||||
{
|
||||
@@ -291,6 +293,7 @@ void IVtkTools_ShapePicker::SetSelectionMode (const IVtk_SelectionMode theMode,
|
||||
}
|
||||
}
|
||||
}
|
||||
anActor = anActors->GetNextActor();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -315,6 +318,28 @@ IVtk_ShapeIdList IVtkTools_ShapePicker::GetPickedShapesIds (bool theIsAll) const
|
||||
return aRes;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
// Method: RemoveSelectableActor
|
||||
// Purpose: Remove selectable object from the picker (from internal maps).
|
||||
//============================================================================
|
||||
void IVtkTools_ShapePicker::RemoveSelectableObject(const IVtk_IShape::Handle& theShape)
|
||||
{
|
||||
myOccPickerAlgo->RemoveSelectableObject(theShape);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
// Method: RemoveSelectableActor
|
||||
// Purpose: Remove selectable object from the picker (from internal maps).
|
||||
//============================================================================
|
||||
void IVtkTools_ShapePicker::RemoveSelectableActor(vtkActor* theShapeActor)
|
||||
{
|
||||
IVtk_IShape::Handle aShape = IVtkTools_ShapeObject::GetOccShape(theShapeActor);
|
||||
if (!aShape.IsNull())
|
||||
{
|
||||
RemoveSelectableObject(aShape);
|
||||
}
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
// Method: GetPickedSubShapesIds
|
||||
// Purpose: Access to the list of sub-shapes ids picked.
|
||||
@@ -324,7 +349,7 @@ IVtk_ShapeIdList IVtkTools_ShapePicker::GetPickedSubShapesIds (const IVtk_IdType
|
||||
IVtk_ShapeIdList aRes;
|
||||
if (theIsAll)
|
||||
{
|
||||
myOccPickerAlgo->SubShapesPicked (theId,aRes);
|
||||
myOccPickerAlgo->SubShapesPicked (theId, aRes);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -342,16 +367,17 @@ IVtk_ShapeIdList IVtkTools_ShapePicker::GetPickedSubShapesIds (const IVtk_IdType
|
||||
// Method: GetPickedActors
|
||||
// Purpose: Access to the list of actors picked.
|
||||
//============================================================================
|
||||
vtkActorCollection* IVtkTools_ShapePicker::GetPickedActors (bool theIsAll) const
|
||||
vtkSmartPointer<vtkActorCollection> IVtkTools_ShapePicker::GetPickedActors (bool theIsAll) const
|
||||
{
|
||||
vtkActorCollection* aRes = vtkActorCollection::New();
|
||||
vtkSmartPointer<vtkActorCollection> aRes = vtkSmartPointer<vtkActorCollection>::New();
|
||||
IVtk_ShapeIdList anIds = GetPickedShapesIds (theIsAll);
|
||||
if (myRenderer)
|
||||
if (myRenderer.GetPointer() != NULL)
|
||||
{
|
||||
// Obtain all actors whose source shape ids are within selected ids.
|
||||
vtkActorCollection *anActors = myRenderer->GetActors();
|
||||
vtkSmartPointer<vtkActorCollection> anActors = myRenderer->GetActors();
|
||||
anActors->InitTraversal();
|
||||
while ( vtkActor* anActor = anActors->GetNextActor() )
|
||||
vtkSmartPointer<vtkActor> anActor = anActors->GetNextActor();
|
||||
while ( anActor.GetPointer() != NULL )
|
||||
{
|
||||
if (anActor->GetPickable() && anActor->GetVisibility())
|
||||
{
|
||||
@@ -370,6 +396,7 @@ vtkActorCollection* IVtkTools_ShapePicker::GetPickedActors (bool theIsAll) const
|
||||
}
|
||||
}
|
||||
}
|
||||
anActor = anActors->GetNextActor();
|
||||
}
|
||||
}
|
||||
return aRes;
|
||||
|
@@ -20,6 +20,7 @@
|
||||
#include <IVtk_Types.hxx>
|
||||
#include <IVtkOCC_ShapePickerAlgo.hxx>
|
||||
#include <vtkAbstractPropPicker.h>
|
||||
#include <vtkSmartPointer.h>
|
||||
|
||||
class vtkRenderer;
|
||||
class vtkActorCollection;
|
||||
@@ -79,9 +80,9 @@ public:
|
||||
const bool theIsTurnOn = true) const;
|
||||
|
||||
//! Turn on/off a selection mode for a shape actor.
|
||||
//! @param [in] shapeActor shape presentation actor to set a selection mode for
|
||||
//! @param [in] mode selection mode to be activated
|
||||
//! @param [in] turnOn Flag to turn on/off the selection mode
|
||||
//! @param [in] theShapeActor shape presentation actor to set a selection mode for
|
||||
//! @param [in] theMode selection mode to be activated
|
||||
//! @param [in] theIsTurnOn Flag to turn on/off the selection mode
|
||||
void SetSelectionMode (vtkActor* theShapeActor,
|
||||
const IVtk_SelectionMode theMode,
|
||||
const bool theIsTurnOn = true) const;
|
||||
@@ -99,29 +100,37 @@ public:
|
||||
//! all OccShape objects found by the picking algorithm. e.g. all
|
||||
//! shapes under the mouse cursor. Otherwise, ID of the shape closest to the eye
|
||||
//! is returned.
|
||||
//! @param [in] all Controls if all selected shapes or just the only
|
||||
//! @param [in] theIsAll Get all selected shapes or just the only
|
||||
//! top one is returned, has no effect during area selection.
|
||||
//! @return List of top-level shape IDs
|
||||
IVtk_ShapeIdList GetPickedShapesIds (bool theIsAll = false) const;
|
||||
|
||||
//! Access to the list of sub-shapes ids picked.
|
||||
//! @param [in] id top-level shape ID
|
||||
//! @param [in] all Controls if all selected sub-shapes or just the
|
||||
//! @param [in] theId top-level shape ID
|
||||
//! @param [in] theIsAll Get all selected sub-shapes or just the
|
||||
//! only top one is returned, has no effect during area selection.
|
||||
//! @return List of sub-shapes IDs
|
||||
IVtk_ShapeIdList GetPickedSubShapesIds (const IVtk_IdType theId, bool theIsAll = false) const;
|
||||
|
||||
//! Access to the list of actors picked.
|
||||
//! @param [in] all Controls if all selected actors or just the only
|
||||
//! @param [in] theIsAll Get all selected actors or just the only
|
||||
//! top one is returned, has no effect during area selection.
|
||||
//! @return List of actors IDs
|
||||
vtkActorCollection* GetPickedActors (bool theIsAll = false) const;
|
||||
vtkSmartPointer<vtkActorCollection> GetPickedActors (bool theIsAll = false) const;
|
||||
|
||||
//! Remove selectable object from the picker (from internal maps).
|
||||
//! @param [in] theShape the selectable shape
|
||||
void RemoveSelectableObject(const IVtk_IShape::Handle& theShape);
|
||||
|
||||
//! Remove selectable object from the picker (from internal maps).
|
||||
//! @param [in] theShapeActor the shape presentation actor to be removed from the picker
|
||||
void RemoveSelectableActor(vtkActor* theShapeActor);
|
||||
|
||||
protected:
|
||||
//! Constructs the picker with empty renderer and ready for point selection.
|
||||
IVtkTools_ShapePicker();
|
||||
//! Destructor
|
||||
~IVtkTools_ShapePicker();
|
||||
virtual ~IVtkTools_ShapePicker();
|
||||
|
||||
//! Convert display coordinates to world coordinates
|
||||
static bool convertDisplayToWorld (vtkRenderer *theRenderer,
|
||||
@@ -143,7 +152,7 @@ private: // not copyable
|
||||
|
||||
private:
|
||||
IVtkOCC_ShapePickerAlgo::Handle myOccPickerAlgo; //!< Picking algorithm implementation
|
||||
vtkRenderer* myRenderer; //!< VTK renderer
|
||||
vtkSmartPointer<vtkRenderer> myRenderer; //!< VTK renderer
|
||||
bool myIsRectSelection;//!< Rectangle selection mode flag
|
||||
bool myIsPolySelection;//!< Polyline selection mode flag
|
||||
float myTolerance; //!< Selectoin tolerance
|
||||
|
@@ -15,12 +15,12 @@
|
||||
|
||||
#include <IVtkTools_SubPolyDataFilter.hxx>
|
||||
#include <IVtkVTK_ShapeData.hxx>
|
||||
#include <vtkCellArray.h>
|
||||
#include <vtkCellData.h>
|
||||
#include <vtkIdList.h>
|
||||
#include <vtkIdTypeArray.h>
|
||||
#include <vtkInformation.h>
|
||||
#include <vtkInformationVector.h>
|
||||
#include <vtkObjectFactory.h>
|
||||
#include <vtkCellData.h>
|
||||
#include <vtkIdTypeArray.h>
|
||||
|
||||
|
||||
vtkStandardNewMacro(IVtkTools_SubPolyDataFilter)
|
||||
@@ -50,27 +50,29 @@ int IVtkTools_SubPolyDataFilter::RequestData (vtkInformation *vtkNotUsed(theRequ
|
||||
vtkInformationVector *theOutputVector)
|
||||
{
|
||||
// get the input and output
|
||||
vtkInformation *anInInfo = theInputVector[0]->GetInformationObject(0);
|
||||
vtkInformation *anOutInfo = theOutputVector->GetInformationObject(0);
|
||||
vtkSmartPointer<vtkInformation> anInInfo = theInputVector[0]->GetInformationObject(0);
|
||||
vtkSmartPointer<vtkInformation> anOutInfo = theOutputVector->GetInformationObject(0);
|
||||
|
||||
vtkPolyData *anInput = vtkPolyData::SafeDownCast(
|
||||
vtkSmartPointer<vtkPolyData> anInput = vtkPolyData::SafeDownCast(
|
||||
anInInfo->Get (vtkDataObject::DATA_OBJECT()));
|
||||
|
||||
vtkPolyData *anOutput = vtkPolyData::SafeDownCast(
|
||||
vtkSmartPointer<vtkPolyData> anOutput = vtkPolyData::SafeDownCast(
|
||||
anOutInfo->Get (vtkDataObject::DATA_OBJECT()));
|
||||
|
||||
vtkIdList *anIdList = vtkIdList::New(); // List of cell ids to be passed
|
||||
anIdList->Allocate(myIdsSet.Extent()); // Allocate the list of ids
|
||||
|
||||
anInput->Modified();
|
||||
|
||||
if (myDoFiltering)
|
||||
{
|
||||
vtkCellData* aCellData = anInput->GetCellData();
|
||||
vtkSmartPointer<vtkCellData> aCellData = anInput->GetCellData();
|
||||
int aSize = 0;
|
||||
vtkIdTypeArray* aDataArray = vtkIdTypeArray::SafeDownCast (aCellData->GetArray (myIdsArrayName));
|
||||
vtkSmartPointer<vtkIdTypeArray> aDataArray =
|
||||
vtkIdTypeArray::SafeDownCast (aCellData->GetArray (myIdsArrayName));
|
||||
|
||||
if(aDataArray != NULL)
|
||||
// List of cell ids to be passed
|
||||
vtkSmartPointer<vtkIdList> anIdList = vtkSmartPointer<vtkIdList>::New();
|
||||
anIdList->Allocate(myIdsSet.Extent()); // Allocate the list of ids
|
||||
|
||||
if (aDataArray.GetPointer() != NULL)
|
||||
{
|
||||
aSize = aDataArray->GetNumberOfTuples();
|
||||
anIdList->Allocate (aSize); // Allocate the list of ids
|
||||
@@ -95,14 +97,15 @@ int IVtkTools_SubPolyDataFilter::RequestData (vtkInformation *vtkNotUsed(theRequ
|
||||
anOutput->Allocate(anInput, anIdList->GetNumberOfIds()); // Allocate output cells
|
||||
// Pass data arrays.
|
||||
// Create new arrays for output data
|
||||
vtkCellData *const anInData = anInput->GetCellData();
|
||||
vtkCellData *const anOutData = anOutput->GetCellData();
|
||||
vtkDataArray *anOutArr, *anInArr;
|
||||
vtkSmartPointer<vtkCellData> anInData = anInput->GetCellData();
|
||||
vtkSmartPointer<vtkCellData> anOutData = anOutput->GetCellData();
|
||||
vtkSmartPointer<vtkDataArray> anInArr, anOutArr;
|
||||
|
||||
for (Standard_Integer anI = 0; anI < anInData->GetNumberOfArrays(); anI++)
|
||||
{
|
||||
anInArr = anInData->GetArray (anI);
|
||||
anOutArr = vtkDataArray::CreateDataArray(anInArr->GetDataType());
|
||||
anOutArr = vtkSmartPointer<vtkDataArray>::Take(
|
||||
vtkDataArray::CreateDataArray(anInArr->GetDataType()));
|
||||
anOutArr->SetName(anInArr->GetName());
|
||||
anOutArr->Allocate(anIdList->GetNumberOfIds() * anInArr->GetNumberOfComponents());
|
||||
anOutArr->SetNumberOfTuples (anIdList->GetNumberOfIds());
|
||||
@@ -119,16 +122,13 @@ int IVtkTools_SubPolyDataFilter::RequestData (vtkInformation *vtkNotUsed(theRequ
|
||||
for (Standard_Integer anI = 0; anI < anInData->GetNumberOfArrays(); anI++)
|
||||
{
|
||||
anInArr = anInData->GetArray (anI);
|
||||
anOutArr = anOutData->GetArray (anI);
|
||||
anOutArr = anOutData->GetArray(anI);
|
||||
for (anOutId = 0; anOutId < anIdList->GetNumberOfIds(); anOutId++)
|
||||
{
|
||||
anInId = anIdList->GetId (anOutId);
|
||||
anOutArr->SetTuple (anOutId, anInId, anInArr);
|
||||
}
|
||||
}
|
||||
|
||||
anIdList->Delete();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -19,7 +19,6 @@
|
||||
#include <IVtkTools.hxx>
|
||||
|
||||
#include "vtkPolyDataAlgorithm.h"
|
||||
#include <IVtk_Types.hxx>
|
||||
|
||||
//! @class IVtkTools_SubPolyDataFilter
|
||||
//! @brief Cells filter according to the given set of cells ids.
|
||||
@@ -57,7 +56,7 @@ protected:
|
||||
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
|
||||
|
||||
IVtkTools_SubPolyDataFilter();
|
||||
~IVtkTools_SubPolyDataFilter();
|
||||
virtual ~IVtkTools_SubPolyDataFilter();
|
||||
|
||||
protected:
|
||||
//! Set of ids to be passed through this filter.
|
||||
|
Reference in New Issue
Block a user