It is possible to get an instance of *vtkLookupTable class* with a default OCCT color scheme by means of the following method:
~~~~
-vtkLookupTable* Table = IVtkTools::InitLookupTable();
+vtkSmartPointer<vtkLookupTable> Table = IVtkTools::InitLookupTable();
~~~~
@subsubsection occt_vis_3_2_2 Custom color scheme
Standard_Integer Draw_Interpretor::Eval(const Standard_CString line)
{
- Standard_PCharacter pLine;
- //
- pLine=(Standard_PCharacter)line;
- //
- return Tcl_Eval(myInterp,pLine);
+ return Tcl_Eval(myInterp,line);
}
Standard_Integer Draw_Interpretor::RecordAndEval(const Standard_CString line,
const Standard_Integer flags)
{
- Standard_PCharacter pLine;
- //
- pLine=(Standard_PCharacter)line;
- return Tcl_RecordAndEval(myInterp,pLine,flags);
+ return Tcl_RecordAndEval(myInterp,line,flags);
}
//=======================================================================
Standard_Integer Draw_Interpretor::EvalFile(const Standard_CString fname)
{
- Standard_PCharacter pfname;
- //
- pfname=(Standard_PCharacter)fname;
- return Tcl_EvalFile(myInterp,pfname);
+ return Tcl_EvalFile(myInterp,fname);
}
//=======================================================================
}
return $mistake
}
+
+# Procedure to check if sequence of values in listval follows linear trend
+# adding the same delta on each step.
+#
+# The function does statistical estimation of the mean variation of the
+# values of the sequence, and dispersion, and returns true only if both
+# dispersion and deviation of the mean from expected delta are within
+# specified tolerance.
+#
+# If mean variation differs from expected delta on more than two dispersions,
+# the check fails and procedure raises error with specified message.
+#
+# Otherwise the procedure returns false meaning that more iterations are needed.
+# Note that false is returned in any case if length of listval is less than 3.
+#
+# See example of use to check memory leaks in bugs/caf/bug23489
+#
+proc checktrend {listval delta tolerance message} {
+ set nbval [llength $listval]
+ if { $nbval < 3} {
+ return 0
+ }
+
+ # calculate mean value
+ set mean 0.
+ set prev [lindex $listval 0]
+ foreach val [lrange $listval 1 end] {
+ set mean [expr $mean + ($val - $prev)]
+ set prev $val
+ }
+ set mean [expr $mean / ($nbval - 1)]
+
+ # calculate dispersion
+ set sigma 0.
+ set prev [lindex $listval 0]
+ foreach val [lrange $listval 1 end] {
+ set d [expr ($val - $prev) - $mean]
+ set sigma [expr $sigma + $d * $d]
+ set prev $val
+ }
+ set sigma [expr sqrt ($sigma / ($nbval - 2))]
+
+ puts "Checking trend: nb = $nbval, mean delta = $mean, sigma = $sigma"
+
+ # check if deviation is definitely too big
+ if { abs ($mean - $delta) > $tolerance + 2. * $sigma } {
+ puts "Checking trend failed: mean delta per step = $mean, sigma = $sigma, expected delta = $delta"
+ error "$message"
+ }
+
+ # check if deviation is clearly within a range
+ return [expr abs ($mean - $delta) <= $sigma && $sigma <= $tolerance]
+}
#endif
#ifdef _WIN32
-#define _WIN32_WINNT 0x0400 // for TrackMouseEvent support requires Win95 with IE 3.0 or greater.
#include <windows.h>
#include <WNT_WClass.hxx>
#include <WNT_Window.hxx>
TCollection_AsciiString aName;
TopoDS_Shape anOldShape, aNewShape;
- vtkSmartPointer<vtkRenderer> aRenderer = GetRenderer();
+ vtkSmartPointer<vtkRenderer>& aRenderer = GetRenderer();
for (Standard_Integer anIndex = 1; anIndex < theArgNum; ++anIndex)
{
// Get name of shape
{
if (aNewShape.IsNull()) continue;
// Create actor from DRAW shape
- vtkActor* anActor = CreateActor (GenerateId(), aNewShape);
+ Standard_Integer anId = GenerateId();
+ vtkSmartPointer<vtkActor> anActor = CreateActor (anId, aNewShape);
// Update maps
GetMapOfShapes().Bind (aNewShape, aName);
GetMapOfActors().Bind (anActor, aName);
// Display actor
- PipelineByActorName (aName)->AddToRenderer (aRenderer);
+ GetPipeline(anId)->AddToRenderer(aRenderer);
// Compute selection for displayed actors
GetPicker()->SetSelectionMode (SM_Shape, Standard_True);
return 0;
}
+//================================================================
+// Function : VtkRemove
+// Purpose : Remove the actor from memory.
+//================================================================
+static Standard_Integer VtkRemove(Draw_Interpretor& theDI,
+ Standard_Integer theArgNum,
+ const char** theArgs)
+{
+ // Check viewer
+ if (!GetInteractor()->IsEnabled())
+ {
+ theDI << theArgs[0] << " error : call ivtkinit before\n";
+ return 1; // TCL_ERROR
+ }
+
+ vtkSmartPointer<vtkRenderer> aRenderer = GetRenderer();
+
+ // Remove all objects
+ if (theArgNum == 1)
+ {
+ // Remove all actors from the renderer
+ DoubleMapOfActorsAndNames::Iterator anIterator(GetMapOfActors());
+ while (anIterator.More())
+ {
+ vtkSmartPointer<IVtkTools_ShapeDataSource> aSrc =
+ IVtkTools_ShapeObject::GetShapeSource(anIterator.Key1());
+ if (aSrc.GetPointer() != NULL && !(aSrc->GetShape().IsNull()))
+ {
+ GetPicker()->RemoveSelectableObject(aSrc->GetShape());
+ }
+ else
+ {
+ aRenderer->RemoveActor(anIterator.Key1());
+ }
+ anIterator.Next();
+ }
+ // Remove all pipelines from the renderer
+ for (ShapePipelineMap::Iterator anIt(*GetPipelines()); anIt.More(); anIt.Next())
+ {
+ anIt.Value()->RemoveFromRenderer(aRenderer);
+ }
+ // Clear maps and remove all TopoDS_Shapes, actors and pipelines
+ GetMapOfShapes().Clear();
+ GetMapOfActors().Clear();
+ GetPipelines()->Clear();
+ }
+ // Remove named objects
+ else
+ {
+ TCollection_AsciiString aName;
+ for (Standard_Integer anIndex = 1; anIndex < theArgNum; ++anIndex)
+ {
+ aName = theArgs[anIndex];
+ if (GetMapOfActors().IsBound2(aName))
+ {
+ // Remove the actor and its pipeline (if found) from the renderer
+ vtkSmartPointer<vtkActor> anActor = GetMapOfActors().Find2(aName);
+ vtkSmartPointer<IVtkTools_ShapeDataSource> aSrc =
+ IVtkTools_ShapeObject::GetShapeSource(anActor);
+ if (aSrc.GetPointer() != NULL && !(aSrc->GetShape().IsNull()))
+ {
+ IVtk_IdType aShapeID = aSrc->GetShape()->GetId();
+ GetPicker()->RemoveSelectableObject(aSrc->GetShape());
+ GetPipeline(aSrc->GetShape()->GetId())->RemoveFromRenderer(aRenderer);
+ GetPipelines()->UnBind(aShapeID); // Remove a pipepline
+ }
+ else
+ {
+ aRenderer->RemoveActor(anActor);
+ }
+ // Remove the TopoDS_Shape and the actor
+ GetMapOfShapes().UnBind2(aName); // Remove a TopoDS shape
+ GetMapOfActors().UnBind2(aName); // Remove an actor
+ }
+ }
+ }
+
+ // Redraw window
+ aRenderer->ResetCamera();
+ GetInteractor()->GetRenderWindow()->Render();
+ return 0;
+}
+
//================================================================
// Function : VtkSetDisplayMode
// Purpose :
return 1; // TCL_ERROR
}
- Standard_Integer anY = GetInteractor()->GetRenderWindow()->GetSize()[1] - atoi (theArgs[1]) - 1;
+ Standard_Integer anY = GetInteractor()->GetRenderWindow()->GetSize()[1] - atoi (theArgs[2]) - 1;
GetInteractor()->MoveTo (atoi (theArgs[1]), anY);
GetInteractor()->OnSelection();
return 0;
"\n\t\t: Removes from renderer named objects or all objects.",
__FILE__, VtkErase, group);
+ theCommands.Add("ivtkremove",
+ "ivtkremove usage:\n"
+ "ivtkremove [name1 name2 ...]"
+ "\n\t\t: Removes from renderer and from memory named objects or all objects.",
+ __FILE__, VtkRemove, group);
+
theCommands.Add("ivtksetdispmode",
"ivtksetdispmode usage:\n"
"ivtksetdispmode [name] mode (0,1)"
#include <vtkPolyData.h>
#include <vtkAppendPolyData.h>
#include <vtkProperty.h>
+#include <vtkRenderWindow.h>
#include <IVtkOCC_Shape.hxx>
#include <IVtkTools_DisplayModeFilter.hxx>
aDMFilter->SetDisplayMode (DM_Wireframe);
myMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
- myMapper->AddInputConnection (aDMFilter->GetOutputPort());
- myActor->SetMapper (myMapper);
+ myMapper->AddInputConnection(aDMFilter->GetOutputPort());
+ myActor->SetMapper(myMapper);
IVtkTools_ShapeObject::SetShapeSource (aDataSource, myActor);
myMapper->ScalarVisibilityOn();
// No highligthing exists initially
aSUBFilterH->SetInputConnection (aDataSource->GetOutputPort() );
- aDMFilterH->SetInputConnection (aSUBFilterH->GetOutputPort() );
+ aDMFilterH->SetInputConnection(aSUBFilterH->GetOutputPort());
myHiliMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
myHiliMapper->SetInputConnection (aDMFilterH->GetOutputPort() );
// No highligthing exists initially
aSUBFilterS->SetInputConnection (aDataSource->GetOutputPort() );
- aDMFilterS->SetInputConnection (aSUBFilterS->GetOutputPort() );
+ aDMFilterS->SetInputConnection(aSUBFilterS->GetOutputPort());
mySelMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mySelMapper->SetInputConnection (aDMFilterS->GetOutputPort() );
theRenderer->RemoveActor (myActor);
theRenderer->RemoveActor (myHiliActor);
theRenderer->RemoveActor (mySelActor);
+
+ vtkSmartPointer<vtkRenderWindow> aWin = theRenderer->GetRenderWindow();
+ if (aWin != NULL)
+ {
+ myActor->ReleaseGraphicsResources(aWin);
+ myHiliActor->ReleaseGraphicsResources(aWin);
+ mySelActor->ReleaseGraphicsResources(aWin);
+ }
}
//===========================================================
//===========================================================
IVtkTools_DisplayModeFilter* IVtkDraw_HighlightAndSelectionPipeline::GetDisplayModeFilter()
{
- return IVtkTools_DisplayModeFilter::SafeDownCast (myFilterMap.Find(Filter_DM_Shape) );
+ return IVtkTools_DisplayModeFilter::SafeDownCast(myFilterMap.Find(Filter_DM_Shape));
}
//===========================================================
//===========================================================
IVtkTools_SubPolyDataFilter* IVtkDraw_HighlightAndSelectionPipeline::GetHighlightFilter()
{
- return IVtkTools_SubPolyDataFilter::SafeDownCast (myFilterMap.Find (Filter_SUB_Hili) );
+ return IVtkTools_SubPolyDataFilter::SafeDownCast(myFilterMap.Find(Filter_SUB_Hili));
}
//===========================================================
//===========================================================
IVtkTools_SubPolyDataFilter* IVtkDraw_HighlightAndSelectionPipeline::GetSelectionFilter()
{
- return IVtkTools_SubPolyDataFilter::SafeDownCast (myFilterMap.Find (Filter_SUB_Sel) );
+ return IVtkTools_SubPolyDataFilter::SafeDownCast(myFilterMap.Find(Filter_SUB_Sel));
}
//===========================================================
//===========================================================
IVtkTools_DisplayModeFilter* IVtkDraw_HighlightAndSelectionPipeline::GetHighlightDMFilter()
{
- return IVtkTools_DisplayModeFilter::SafeDownCast (myFilterMap.Find (Filter_DM_Hili) );
+ return IVtkTools_DisplayModeFilter::SafeDownCast(myFilterMap.Find(Filter_DM_Hili));
}
//===========================================================
//===========================================================
IVtkTools_DisplayModeFilter* IVtkDraw_HighlightAndSelectionPipeline::GetSelectionDMFilter()
{
- return IVtkTools_DisplayModeFilter::SafeDownCast (myFilterMap.Find(Filter_DM_Sel));
+ return IVtkTools_DisplayModeFilter::SafeDownCast(myFilterMap.Find(Filter_DM_Sel));
}
//===========================================================
// commercial license or contractual agreement.
#ifdef _WIN32
-#define _WIN32_WINNT 0x0400 // for trackmouseevent support requires Win95 with IE 3.0 or greater.
#include <windows.h>
#include <vtkWin32RenderWindowInteractor.h>
#include <vtkWin32OpenGLRenderWindow.h>
{
// Processing highlighting
mySelector->Pick (theX, theY, 0.0);
- vtkActorCollection* anActorCollection = mySelector->GetPickedActors();
+ vtkSmartPointer<vtkActorCollection> anActorCollection = mySelector->GetPickedActors();
if (anActorCollection)
{
void IVtkDraw_Interactor::OnSelection()
{
// Processing selection
- vtkActorCollection* anActorCollection = mySelector->GetPickedActors();
+ vtkSmartPointer<vtkActorCollection> anActorCollection = mySelector->GetPickedActors();
if (anActorCollection)
{
myShape (0)
{ }
+//============================================================================
+// Method: Destructor
+// Purpose:
+//============================================================================
+IVtkOCC_SelectableObject::~IVtkOCC_SelectableObject()
+{ }
+
//============================================================================
// Method: SetShape
// Purpose: Sets the selectable shape
#include <SelectMgr_SelectableObject.hxx>
#include <SelectMgr_Selection.hxx>
+class IVtkOCC_SelectableObject;
+DEFINE_STANDARD_HANDLE(IVtkOCC_SelectableObject, SelectMgr_SelectableObject)
// -----------------------------------------------------------------------------
//! @class IVtkOCC_SelectableObject
//! @brief Class with selection primitives used by OCCT selection algorithm.
{
public:
+ typedef Handle(IVtkOCC_SelectableObject) Handle;
+
//! Constructs a selectable object initialized by the given shape
//! @param [in] theShape Selectable shape
IVtkOCC_SelectableObject (const IVtkOCC_Shape::Handle& theShape);
//! setShape() should be called later.
IVtkOCC_SelectableObject();
+ virtual ~IVtkOCC_SelectableObject();
+
//! Sets the selectable shape
//! @param [in] theShape Selectable shape
- void SetShape (const IVtkOCC_Shape::Handle& theShape);
+ Standard_EXPORT void SetShape (const IVtkOCC_Shape::Handle& theShape);
const IVtkOCC_Shape::Handle& GetShape() const { return myShape; };
Handle(Prs3d_Drawer) myOCCTDrawer;
};
-DEFINE_STANDARD_HANDLE( IVtkOCC_SelectableObject, SelectMgr_SelectableObject )
-
#endif // __IVTKOCC_SELECTABLEOBJECT_H__
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
-#include <Adaptor3d_HCurve.hxx>
#include <Adaptor3d_IsoCurve.hxx>
#include <Bnd_Box.hxx>
#include <BRep_Tool.hxx>
//================================================================
void IVtkOCC_ShapeMesher::meshShape()
{
- TopoDS_Shape anOcctShape = GetShapeObj()->GetShape();
+ const TopoDS_Shape& anOcctShape = GetShapeObj()->GetShape();
if (anOcctShape.IsNull())
{
return;
{
aType = MT_SharedVertex;
}
- TopoDS_Vertex aVertex = TopoDS::Vertex (aVertexMap.FindKey (anIt));
+ const TopoDS_Vertex& aVertex = TopoDS::Vertex (aVertexMap.FindKey (anIt));
addVertex (aVertex, GetShapeObj()->GetSubShapeId (aVertex), aType);
}
}
TopExp_Explorer anEdgeIter (GetShapeObj()->GetShape(), TopAbs_EDGE);
for (; anEdgeIter.More(); anEdgeIter.Next())
{
- TopoDS_Edge anOcctEdge = TopoDS::Edge (anEdgeIter.Current());
+ const TopoDS_Edge& anOcctEdge = TopoDS::Edge (anEdgeIter.Current());
aNbFaces = anEdgesMap.FindFromKey (anOcctEdge).Extent();
if (aNbFaces == 0)
{
TopExp_Explorer aFaceIter (GetShapeObj()->GetShape(), TopAbs_FACE);
for (; aFaceIter.More(); aFaceIter.Next())
{
- TopoDS_Face anOcctFace = TopoDS::Face (aFaceIter.Current());
+ const TopoDS_Face& anOcctFace = TopoDS::Face (aFaceIter.Current());
try
{
OCC_CATCH_SIGNALS
TopExp_Explorer aFaceIter (GetShapeObj()->GetShape(), TopAbs_FACE);
for (; aFaceIter.More(); aFaceIter.Next())
{
- TopoDS_Face anOcctFace = TopoDS::Face (aFaceIter.Current());
+ const TopoDS_Face& anOcctFace = TopoDS::Face (aFaceIter.Current());
addShadedFace (anOcctFace,
GetShapeObj()->GetSubShapeId (anOcctFace));
}
return;
}
- IVtk_PointIdList *aPolyPointIds = new IVtk_PointIdList();
+ IVtk_PointIdList aPolyPointIds;
IVtk_PointId anId;
for (Standard_Integer aJ = 0; aJ < theNbNodes; aJ++)
}
anId = myShapeData->InsertCoordinate (point.X(), point.Y(), point.Z());
- aPolyPointIds->Append (anId);
+ aPolyPointIds.Append (anId);
}
- myShapeData->InsertLine (theOcctId, aPolyPointIds, theMeshType);
-
- delete aPolyPointIds;
+ myShapeData->InsertLine (theOcctId, &aPolyPointIds, theMeshType);
}
//================================================================
TopExp_Explorer anEdgeIter (aFaceToMesh, TopAbs_EDGE );
for (; anEdgeIter.More(); anEdgeIter.Next())
{
- TopoDS_Edge anOcctEdge = TopoDS::Edge (anEdgeIter.Current());
+ const TopoDS_Edge& anOcctEdge = TopoDS::Edge (anEdgeIter.Current());
addEdge (anOcctEdge, theShapeId, myEdgesTypes (anOcctEdge));
}
{
if (mySubShapesPicked.IsBound (theId))
{
- // Need non-const this to call the map's operator[]
- IVtkOCC_ShapePickerAlgo* that = const_cast< IVtkOCC_ShapePickerAlgo* >(this);
- theShapeList = that->mySubShapesPicked (theId);
+ theShapeList = mySubShapesPicked (theId);
}
}
return !myShapesPicked.IsEmpty();
}
+
+//============================================================================
+// Method: RemoveSelectableActor
+// Purpose: Remove selectable object from the picker (from internal maps).
+//============================================================================
+void IVtkOCC_ShapePickerAlgo::RemoveSelectableObject(const IVtk_IShape::Handle& theShape)
+{
+ clearPicked();
+ // Get shape implementation from shape interface.
+ Handle(IVtkOCC_Shape) aShapeImpl =
+ Handle(IVtkOCC_Shape)::DownCast(theShape);
+
+ // Get selectable object from the shape implementation.
+ Handle(IVtkOCC_SelectableObject) aSelObj =
+ Handle(IVtkOCC_SelectableObject)::DownCast(aShapeImpl->GetSelectableObject());
+
+ myViewerSelector->RemoveSelectableObject(aSelObj);
+ myViewerSelector->Clear();
+ aShapeImpl->SetSelectableObject(NULL);
+}
\ No newline at end of file
Standard_EXPORT virtual void
SubShapesPicked (const IVtk_IdType theId, IVtk_ShapeIdList& theShapeList) const Standard_OVERRIDE;
+ //! Remove selectable object from the picker (from internal maps).
+ //! @param [in] theShape the selectable shape
+ Standard_EXPORT virtual void RemoveSelectableObject(const IVtk_IShape::Handle& theShape);
+
public:
DEFINE_STANDARD_RTTIEXT(IVtkOCC_ShapePickerAlgo,IVtk_IShapePickerAlgo)
IVtkOCC_ViewerSelector::IVtkOCC_ViewerSelector()
: SelectMgr_ViewerSelector(),
myPixTol(2),
-myToUpdateTol(Standard_True) {}
+myToUpdateTol(Standard_True)
+{
+}
+
+//============================================================================
+// Method: Destructor
+// Purpose:
+//============================================================================
+IVtkOCC_ViewerSelector::~IVtkOCC_ViewerSelector()
+{
+}
//============================================================================
// Method: Pick
public:
IVtkOCC_ViewerSelector();
+ virtual ~IVtkOCC_ViewerSelector();
+
//! Implements point picking
//! @param [in] theXPix, theYPix Display coordinates of the point
//! @param [in] theView ICamera interface to update the projection parameters.
// 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;
#define IVtkTOOLS_H
#include <IVtk_Types.hxx>
+#include <vtkSmartPointer.h>
#if defined(_WIN32) && !defined(HAVE_NO_DLL)
#ifdef __IVtkTools_DLL
//! 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.
#include <IVtkTools.hxx>
#include <IVtkTools_SubPolyDataFilter.hxx>
-#include <IVtk_Types.hxx>
#include <NCollection_DataMap.hxx>
//! @class IVtkTools_DisplayModeFilter
virtual int RequestData (vtkInformation *, vtkInformationVector **, vtkInformationVector *);
IVtkTools_DisplayModeFilter();
- ~IVtkTools_DisplayModeFilter();
+ virtual ~IVtkTools_DisplayModeFilter();
protected:
//! Display mode defining mesh types to pass through this filter.
// 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>
myIsFastTransformMode (Standard_False),
myIsTransformOnly (Standard_False)
{
- this->SetNumberOfInputPorts (0);
+ this->SetNumberOfInputPorts(0);
+ this->SetNumberOfOutputPorts(1);
}
//================================================================
// 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() )
- {
- aTransformedData = this->transform (aPrevData, aShapeLoc);
- }
- 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;
- }
+ aPolyData->Allocate();
+ vtkSmartPointer<vtkPoints> aPts = vtkSmartPointer<vtkPoints>::New();
+ aPolyData->SetPoints (aPts);
- myPolyData = new IVtkVTK_ShapeData;
- IVtkOCC_ShapeMesher::Handle aMesher = new IVtkOCC_ShapeMesher;
- aMesher->Build (aShapeWrapperCopy, myPolyData);
- vtkPolyData* aMeshData = myPolyData->getVtkPolyData();
+ vtkSmartPointer<vtkPolyData> aTransformedData;
+ TopoDS_Shape aShape = myOccShape->GetShape();
+ TopLoc_Location aShapeLoc = aShape.Location();
- if (myIsFastTransformMode && !aShapeLoc.IsIdentity() )
+ if (myIsTransformOnly)
{
- aTransformedData = this->transform (aMeshData, aShapeLoc);
+ vtkSmartPointer<vtkPolyData> aPrevData = myPolyData->getVtkPolyData();
+ if ( !aShapeLoc.IsIdentity() )
+ {
+ aTransformedData = this->transform (aPrevData, aShapeLoc);
+ }
+ else
+ {
+ aTransformedData = aPrevData;
+ }
}
else
{
- aTransformedData = aMeshData;
+ 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;
+ }
}
- }
- aPolyData->CopyStructure (aTransformedData); // Copy points and cells
- aPolyData->CopyAttributes (aTransformedData); // Copy data arrays (sub-shapes IDs)
+ 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() );
+ // 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;
}
//================================================================
//================================================================
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()) );
}
//================================================================
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)
#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;
protected:
IVtkTools_ShapeDataSource();
- ~IVtkTools_ShapeDataSource();
+ virtual ~IVtkTools_ShapeDataSource();
private:
#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;
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();
}
// 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();
}
}
{
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();
}
//============================================================================
{
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
// Method: GetShapeSource
// Purpose:
//============================================================================
-IVtkTools_ShapeDataSource* IVtkTools_ShapeObject::GetShapeSource () const
+IVtkTools_ShapeDataSource* IVtkTools_ShapeObject::GetShapeSource() const
{
return myShapeSource;
}
#include <IVtkOCC_Shape.hxx>
#include <vtkDataObject.h>
#include <vtkSetGet.h>
-#include <vtkSmartPointer.h>
+#include <vtkWeakPointer.h>
class vtkActor;
class vtkDataSet;
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);
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;
};
#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>
// 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();
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;
{
theWorldCoord[anI] = aCoords[anI] / aCoords[3];
}
+
return true;
}
// 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
//============================================================================
void IVtkTools_ShapePicker::SetRenderer (vtkRenderer* theRenderer)
{
- if (theRenderer == myRenderer)
+ if (theRenderer == myRenderer.GetPointer())
{
return;
// In this case we should not do anything.
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())
{
}
}
}
+ anActor = anActors->GetNextActor();
}
}
}
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.
IVtk_ShapeIdList aRes;
if (theIsAll)
{
- myOccPickerAlgo->SubShapesPicked (theId,aRes);
+ myOccPickerAlgo->SubShapesPicked (theId, aRes);
}
else
{
// 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())
{
}
}
}
+ anActor = anActors->GetNextActor();
}
}
return aRes;
#include <IVtk_Types.hxx>
#include <IVtkOCC_ShapePickerAlgo.hxx>
#include <vtkAbstractPropPicker.h>
+#include <vtkSmartPointer.h>
class vtkRenderer;
class vtkActorCollection;
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;
//! 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,
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
#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)
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));
+
+ // List of cell ids to be passed
+ vtkSmartPointer<vtkIdList> anIdList = vtkSmartPointer<vtkIdList>::New();
+ anIdList->Allocate(myIdsSet.Extent()); // Allocate the list of ids
- if(aDataArray != NULL)
+ if (aDataArray.GetPointer() != NULL)
{
aSize = aDataArray->GetNumberOfTuples();
anIdList->Allocate (aSize); // Allocate the list of ids
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());
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
{
#include <IVtkTools.hxx>
#include "vtkPolyDataAlgorithm.h"
-#include <IVtk_Types.hxx>
//! @class IVtkTools_SubPolyDataFilter
//! @brief Cells filter according to the given set of cells ids.
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
IVtkTools_SubPolyDataFilter();
- ~IVtkTools_SubPolyDataFilter();
+ virtual ~IVtkTools_SubPolyDataFilter();
protected:
//! Set of ids to be passed through this filter.
// commercial license or contractual agreement.
#include <IVtkVTK_ShapeData.hxx>
-#include <vtkCellArray.h>
#include <vtkCellData.h>
#include <vtkDoubleArray.h>
+#include <vtkIdList.h>
#include <vtkIdTypeArray.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>
{
myPolyData = vtkSmartPointer<vtkPolyData>::New();
myPolyData->Allocate();
- myPolyData->SetPoints (vtkPoints::New());
+ myPolyData->SetPoints (vtkSmartPointer<vtkPoints>::New());
mySubShapeIDs = vtkSmartPointer<vtkIdTypeArray>::New();
mySubShapeIDs->SetName (IVtkVTK_ShapeData::ARRNAME_SUBSHAPE_IDS);
{
if (!thePointIds->IsEmpty())
{
- vtkIdList* anIdList = vtkIdList::New();
+ vtkSmartPointer<vtkIdList> anIdList = vtkSmartPointer<vtkIdList>::New();
// Fill the vtk id list by ids from IVtk_PointIdList.
IVtk_PointIdList::Iterator anIterOfIds =
IVtk_PointIdList::Iterator(*thePointIds);
mySubShapeIDs->InsertNextTupleValue (&aShapeIDVTK);
const vtkIdType aType = theMeshType;
myMeshTypes->InsertNextTupleValue (&aType);
- anIdList->Delete();
}
}
#define __IVTKVTK_SHAPEDATA_H__
#include <IVtk_IShapeData.hxx>
-#include <vtkType.h>
+#include <vtkPolyData.h>
#include <vtkSmartPointer.h>
class vtkIdTypeArray;
-class vtkPolyData;
class IVtkVTK_ShapeData;
DEFINE_STANDARD_HANDLE( IVtkVTK_ShapeData, IVtk_IShapeData )
//! Get VTK PolyData.
//! @return VTK PolyData
- vtkSmartPointer< vtkPolyData > getVtkPolyData() const
+ vtkPolyData* getVtkPolyData() const
{ return myPolyData; }
private:
return false;
}
- theWorldPnt = gp_XYZ (aCoords[0] / aCoords[3], aCoords[1] / aCoords[3], aCoords[2] / aCoords[3]);
+ theWorldPnt = gp_XYZ (aCoords[0] / aCoords[3],
+ aCoords[1] / aCoords[3], aCoords[2] / aCoords[3]);
return true;
}
theIsOrtho = !IsPerspective();
vtkMatrix4x4* aCompositeProj =
- myRenderer->GetActiveCamera()->GetCompositeProjectionTransformMatrix (myRenderer->GetTiledAspectRatio(),
- 0,
- 1);
+ myRenderer->GetActiveCamera()->
+ GetCompositeProjectionTransformMatrix (myRenderer->GetTiledAspectRatio(),
+ 0,
+ 1);
for (Standard_Integer aRow = 0; aRow < 4; ++aRow)
{
for (Standard_Integer aCol = 0; aCol < 4; ++aCol)
#define __IVTKVTK_VIEW_H__
#include <IVtk_IView.hxx>
+#include <vtkSmartPointer.h>
class vtkRenderer;
DEFINE_STANDARD_RTTIEXT(IVtkVTK_View,IVtk_IView)
private:
- vtkRenderer* myRenderer;
+ vtkSmartPointer<vtkRenderer> myRenderer;
};
#endif // __IVTKVTK_VIEW_H__
checkreal "area of $shape" $area $area_expected $tol_abs $tol_rel
}
-# Procedure to check if sequence of values in listval follows linear trend
-# adding the same delta on each step.
-#
-# The function does statistical estimation of the mean variation of the
-# values of the sequence, and dispersion, and returns true only if both
-# dispersion and deviation of the mean from expected delta are within
-# specified tolerance.
-#
-# If mean variation differs from expected delta on more than two dispersions,
-# the check fails and procedure raises error with specified message.
-#
-# Otherwise the procedure returns false meaning that more iterations are needed.
-# Note that false is returned in any case if length of listval is less than 3.
-#
-# See example of use to check memory leaks in bugs/caf/bug23489
-#
-proc checktrend {listval delta tolerance message} {
- set nbval [llength $listval]
- if { $nbval < 3} {
- return 0
- }
-
- # calculate mean value
- set mean 0.
- set prev [lindex $listval 0]
- foreach val [lrange $listval 1 end] {
- set mean [expr $mean + ($val - $prev)]
- set prev $val
- }
- set mean [expr $mean / ($nbval - 1)]
-
- # calculate dispersion
- set sigma 0.
- set prev [lindex $listval 0]
- foreach val [lrange $listval 1 end] {
- set d [expr ($val - $prev) - $mean]
- set sigma [expr $sigma + $d * $d]
- set prev $val
- }
- set sigma [expr sqrt ($sigma / ($nbval - 2))]
-
- puts "Checking trend: nb = $nbval, mean delta = $mean, sigma = $sigma"
-
- # check if deviation is definitely too big
- if { abs ($mean - $delta) > $tolerance + 2. * $sigma } {
- puts "Checking trend failed: mean delta per step = $mean, sigma = $sigma, expected delta = $delta"
- error "$message"
- }
-
- # check if deviation is clearly within a range
- return [expr abs ($mean - $delta) <= $sigma && $sigma <= $tolerance]
-}
-
# Check if area of triangles is valid
proc CheckTriArea {shape {eps 0}} {
upvar #0 $shape result
--- /dev/null
+puts "For OCC27871: Possible memory leak in viewers in virtual windows mode"
+puts "For OCC27871: Use 120 kb tolerance for checktrend because of leak on Linux in virtual windows mode"
+puts "============"
+puts "OCC27567"
+puts "============"
+puts ""
+#######################################################################
+# Visualization - possible memory leaks due to use of plain pointers
+# in IVTK
+#######################################################################
+
+ivtkinit
+
+dlog off
+# Create i_max number of shapes
+set i_max 15
+
+set listmem {}
+for {set i 1} {${i} <= ${i_max}} {incr i} {
+
+ psphere s 10 15 80
+ box box1 5 5 -5
+ box box2 -5 -5 -5
+ ptorus t 10 3
+
+ compound s box1 box2 t b$i
+
+ unset s
+ unset box1
+ unset box2
+ unset t
+
+
+ # Display the j-th shape
+ ivtkdisplay b$i
+
+ # Display shaded
+ ivtksetdispmode 1
+
+ # Display wired
+ ivtksetdispmode 0
+
+ # Select the shape
+ ivtkselect 200 200
+
+ # Deselect the shape
+ ivtkselect 0 0
+
+ # Highlight the shape
+ ivtkmoveto 200 200
+
+ # Unhighlight the shape
+ ivtkmoveto 50 50
+
+ # Hide the shape
+ ivtkerase b$i
+
+ # Remove the shape presentation from memory
+ ivtkremove b$i
+
+ unset b$i
+
+ lappend listmem [meminfo h]
+ checktrend $listmem 0 120000 "Memory leak detected"
+}
+