mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-19 13:40:49 +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:
@@ -51,7 +51,6 @@
|
||||
#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>
|
||||
@@ -451,7 +450,7 @@ static Standard_Integer VtkDisplay (Draw_Interpretor& theDI,
|
||||
|
||||
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
|
||||
@@ -494,12 +493,13 @@ static Standard_Integer VtkDisplay (Draw_Interpretor& theDI,
|
||||
{
|
||||
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);
|
||||
@@ -559,6 +559,89 @@ static Standard_Integer VtkErase (Draw_Interpretor& theDI,
|
||||
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 :
|
||||
@@ -841,7 +924,7 @@ static Standard_Integer VtkSelect (Draw_Interpretor& theDI,
|
||||
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;
|
||||
@@ -1097,6 +1180,12 @@ void IVtkDraw::Commands (Draw_Interpretor& theCommands)
|
||||
"\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)"
|
||||
|
@@ -21,6 +21,7 @@
|
||||
#include <vtkPolyData.h>
|
||||
#include <vtkAppendPolyData.h>
|
||||
#include <vtkProperty.h>
|
||||
#include <vtkRenderWindow.h>
|
||||
|
||||
#include <IVtkOCC_Shape.hxx>
|
||||
#include <IVtkTools_DisplayModeFilter.hxx>
|
||||
@@ -66,8 +67,8 @@ IVtkDraw_HighlightAndSelectionPipeline::IVtkDraw_HighlightAndSelectionPipeline (
|
||||
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();
|
||||
@@ -86,7 +87,7 @@ IVtkDraw_HighlightAndSelectionPipeline::IVtkDraw_HighlightAndSelectionPipeline (
|
||||
|
||||
// No highligthing exists initially
|
||||
aSUBFilterH->SetInputConnection (aDataSource->GetOutputPort() );
|
||||
aDMFilterH->SetInputConnection (aSUBFilterH->GetOutputPort() );
|
||||
aDMFilterH->SetInputConnection(aSUBFilterH->GetOutputPort());
|
||||
|
||||
myHiliMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
myHiliMapper->SetInputConnection (aDMFilterH->GetOutputPort() );
|
||||
@@ -115,7 +116,7 @@ IVtkDraw_HighlightAndSelectionPipeline::IVtkDraw_HighlightAndSelectionPipeline (
|
||||
|
||||
// No highligthing exists initially
|
||||
aSUBFilterS->SetInputConnection (aDataSource->GetOutputPort() );
|
||||
aDMFilterS->SetInputConnection (aSUBFilterS->GetOutputPort() );
|
||||
aDMFilterS->SetInputConnection(aSUBFilterS->GetOutputPort());
|
||||
|
||||
mySelMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
mySelMapper->SetInputConnection (aDMFilterS->GetOutputPort() );
|
||||
@@ -154,6 +155,14 @@ void IVtkDraw_HighlightAndSelectionPipeline::RemoveFromRenderer (vtkRenderer* th
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
//===========================================================
|
||||
@@ -184,7 +193,7 @@ void IVtkDraw_HighlightAndSelectionPipeline::ClearSelectionFilters()
|
||||
//===========================================================
|
||||
IVtkTools_DisplayModeFilter* IVtkDraw_HighlightAndSelectionPipeline::GetDisplayModeFilter()
|
||||
{
|
||||
return IVtkTools_DisplayModeFilter::SafeDownCast (myFilterMap.Find(Filter_DM_Shape) );
|
||||
return IVtkTools_DisplayModeFilter::SafeDownCast(myFilterMap.Find(Filter_DM_Shape));
|
||||
}
|
||||
|
||||
//===========================================================
|
||||
@@ -193,7 +202,7 @@ IVtkTools_DisplayModeFilter* IVtkDraw_HighlightAndSelectionPipeline::GetDisplayM
|
||||
//===========================================================
|
||||
IVtkTools_SubPolyDataFilter* IVtkDraw_HighlightAndSelectionPipeline::GetHighlightFilter()
|
||||
{
|
||||
return IVtkTools_SubPolyDataFilter::SafeDownCast (myFilterMap.Find (Filter_SUB_Hili) );
|
||||
return IVtkTools_SubPolyDataFilter::SafeDownCast(myFilterMap.Find(Filter_SUB_Hili));
|
||||
}
|
||||
|
||||
//===========================================================
|
||||
@@ -202,7 +211,7 @@ IVtkTools_SubPolyDataFilter* IVtkDraw_HighlightAndSelectionPipeline::GetHighligh
|
||||
//===========================================================
|
||||
IVtkTools_SubPolyDataFilter* IVtkDraw_HighlightAndSelectionPipeline::GetSelectionFilter()
|
||||
{
|
||||
return IVtkTools_SubPolyDataFilter::SafeDownCast (myFilterMap.Find (Filter_SUB_Sel) );
|
||||
return IVtkTools_SubPolyDataFilter::SafeDownCast(myFilterMap.Find(Filter_SUB_Sel));
|
||||
}
|
||||
|
||||
//===========================================================
|
||||
@@ -211,7 +220,7 @@ IVtkTools_SubPolyDataFilter* IVtkDraw_HighlightAndSelectionPipeline::GetSelectio
|
||||
//===========================================================
|
||||
IVtkTools_DisplayModeFilter* IVtkDraw_HighlightAndSelectionPipeline::GetHighlightDMFilter()
|
||||
{
|
||||
return IVtkTools_DisplayModeFilter::SafeDownCast (myFilterMap.Find (Filter_DM_Hili) );
|
||||
return IVtkTools_DisplayModeFilter::SafeDownCast(myFilterMap.Find(Filter_DM_Hili));
|
||||
}
|
||||
|
||||
//===========================================================
|
||||
@@ -220,7 +229,7 @@ IVtkTools_DisplayModeFilter* IVtkDraw_HighlightAndSelectionPipeline::GetHighligh
|
||||
//===========================================================
|
||||
IVtkTools_DisplayModeFilter* IVtkDraw_HighlightAndSelectionPipeline::GetSelectionDMFilter()
|
||||
{
|
||||
return IVtkTools_DisplayModeFilter::SafeDownCast (myFilterMap.Find(Filter_DM_Sel));
|
||||
return IVtkTools_DisplayModeFilter::SafeDownCast(myFilterMap.Find(Filter_DM_Sel));
|
||||
}
|
||||
|
||||
//===========================================================
|
||||
|
@@ -14,7 +14,6 @@
|
||||
// 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>
|
||||
@@ -225,7 +224,7 @@ void IVtkDraw_Interactor::MoveTo (Standard_Integer theX, Standard_Integer theY)
|
||||
{
|
||||
// Processing highlighting
|
||||
mySelector->Pick (theX, theY, 0.0);
|
||||
vtkActorCollection* anActorCollection = mySelector->GetPickedActors();
|
||||
vtkSmartPointer<vtkActorCollection> anActorCollection = mySelector->GetPickedActors();
|
||||
|
||||
if (anActorCollection)
|
||||
{
|
||||
@@ -290,7 +289,7 @@ void IVtkDraw_Interactor::MoveTo (Standard_Integer theX, Standard_Integer theY)
|
||||
void IVtkDraw_Interactor::OnSelection()
|
||||
{
|
||||
// Processing selection
|
||||
vtkActorCollection* anActorCollection = mySelector->GetPickedActors();
|
||||
vtkSmartPointer<vtkActorCollection> anActorCollection = mySelector->GetPickedActors();
|
||||
|
||||
if (anActorCollection)
|
||||
{
|
||||
|
Reference in New Issue
Block a user