1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +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:
rkv 2016-08-23 15:52:11 +03:00 committed by bugmaster
parent fb0b05319f
commit a2f76b15f1
30 changed files with 492 additions and 260 deletions

View File

@ -121,7 +121,7 @@ IVtkTools::InitShapeMapper(Mapper);
It is possible to get an instance of *vtkLookupTable class* with a default OCCT color scheme by means of the following method: 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 @subsubsection occt_vis_3_2_2 Custom color scheme

View File

@ -473,11 +473,7 @@ void Draw_Interpretor::AppendElement(const Standard_CString s)
Standard_Integer Draw_Interpretor::Eval(const Standard_CString line) Standard_Integer Draw_Interpretor::Eval(const Standard_CString line)
{ {
Standard_PCharacter pLine; return Tcl_Eval(myInterp,line);
//
pLine=(Standard_PCharacter)line;
//
return Tcl_Eval(myInterp,pLine);
} }
@ -489,10 +485,7 @@ Standard_Integer Draw_Interpretor::Eval(const Standard_CString line)
Standard_Integer Draw_Interpretor::RecordAndEval(const Standard_CString line, Standard_Integer Draw_Interpretor::RecordAndEval(const Standard_CString line,
const Standard_Integer flags) const Standard_Integer flags)
{ {
Standard_PCharacter pLine; return Tcl_RecordAndEval(myInterp,line,flags);
//
pLine=(Standard_PCharacter)line;
return Tcl_RecordAndEval(myInterp,pLine,flags);
} }
//======================================================================= //=======================================================================
@ -502,10 +495,7 @@ Standard_Integer Draw_Interpretor::RecordAndEval(const Standard_CString line,
Standard_Integer Draw_Interpretor::EvalFile(const Standard_CString fname) Standard_Integer Draw_Interpretor::EvalFile(const Standard_CString fname)
{ {
Standard_PCharacter pfname; return Tcl_EvalFile(myInterp,fname);
//
pfname=(Standard_PCharacter)fname;
return Tcl_EvalFile(myInterp,pfname);
} }
//======================================================================= //=======================================================================

View File

@ -2489,3 +2489,56 @@ proc _checkpoint {coord_x coord_y rd_ch gr_ch bl_ch} {
} }
return $mistake 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]
}

View File

@ -51,7 +51,6 @@
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
#define _WIN32_WINNT 0x0400 // for TrackMouseEvent support requires Win95 with IE 3.0 or greater.
#include <windows.h> #include <windows.h>
#include <WNT_WClass.hxx> #include <WNT_WClass.hxx>
#include <WNT_Window.hxx> #include <WNT_Window.hxx>
@ -451,7 +450,7 @@ static Standard_Integer VtkDisplay (Draw_Interpretor& theDI,
TCollection_AsciiString aName; TCollection_AsciiString aName;
TopoDS_Shape anOldShape, aNewShape; TopoDS_Shape anOldShape, aNewShape;
vtkSmartPointer<vtkRenderer> aRenderer = GetRenderer(); vtkSmartPointer<vtkRenderer>& aRenderer = GetRenderer();
for (Standard_Integer anIndex = 1; anIndex < theArgNum; ++anIndex) for (Standard_Integer anIndex = 1; anIndex < theArgNum; ++anIndex)
{ {
// Get name of shape // Get name of shape
@ -494,12 +493,13 @@ static Standard_Integer VtkDisplay (Draw_Interpretor& theDI,
{ {
if (aNewShape.IsNull()) continue; if (aNewShape.IsNull()) continue;
// Create actor from DRAW shape // Create actor from DRAW shape
vtkActor* anActor = CreateActor (GenerateId(), aNewShape); Standard_Integer anId = GenerateId();
vtkSmartPointer<vtkActor> anActor = CreateActor (anId, aNewShape);
// Update maps // Update maps
GetMapOfShapes().Bind (aNewShape, aName); GetMapOfShapes().Bind (aNewShape, aName);
GetMapOfActors().Bind (anActor, aName); GetMapOfActors().Bind (anActor, aName);
// Display actor // Display actor
PipelineByActorName (aName)->AddToRenderer (aRenderer); GetPipeline(anId)->AddToRenderer(aRenderer);
// Compute selection for displayed actors // Compute selection for displayed actors
GetPicker()->SetSelectionMode (SM_Shape, Standard_True); GetPicker()->SetSelectionMode (SM_Shape, Standard_True);
@ -559,6 +559,89 @@ static Standard_Integer VtkErase (Draw_Interpretor& theDI,
return 0; 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 // Function : VtkSetDisplayMode
// Purpose : // Purpose :
@ -841,7 +924,7 @@ static Standard_Integer VtkSelect (Draw_Interpretor& theDI,
return 1; // TCL_ERROR 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()->MoveTo (atoi (theArgs[1]), anY);
GetInteractor()->OnSelection(); GetInteractor()->OnSelection();
return 0; return 0;
@ -1097,6 +1180,12 @@ void IVtkDraw::Commands (Draw_Interpretor& theCommands)
"\n\t\t: Removes from renderer named objects or all objects.", "\n\t\t: Removes from renderer named objects or all objects.",
__FILE__, VtkErase, group); __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", theCommands.Add("ivtksetdispmode",
"ivtksetdispmode usage:\n" "ivtksetdispmode usage:\n"
"ivtksetdispmode [name] mode (0,1)" "ivtksetdispmode [name] mode (0,1)"

View File

@ -21,6 +21,7 @@
#include <vtkPolyData.h> #include <vtkPolyData.h>
#include <vtkAppendPolyData.h> #include <vtkAppendPolyData.h>
#include <vtkProperty.h> #include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <IVtkOCC_Shape.hxx> #include <IVtkOCC_Shape.hxx>
#include <IVtkTools_DisplayModeFilter.hxx> #include <IVtkTools_DisplayModeFilter.hxx>
@ -66,8 +67,8 @@ IVtkDraw_HighlightAndSelectionPipeline::IVtkDraw_HighlightAndSelectionPipeline (
aDMFilter->SetDisplayMode (DM_Wireframe); aDMFilter->SetDisplayMode (DM_Wireframe);
myMapper = vtkSmartPointer<vtkPolyDataMapper>::New(); myMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
myMapper->AddInputConnection (aDMFilter->GetOutputPort()); myMapper->AddInputConnection(aDMFilter->GetOutputPort());
myActor->SetMapper (myMapper); myActor->SetMapper(myMapper);
IVtkTools_ShapeObject::SetShapeSource (aDataSource, myActor); IVtkTools_ShapeObject::SetShapeSource (aDataSource, myActor);
myMapper->ScalarVisibilityOn(); myMapper->ScalarVisibilityOn();
@ -86,7 +87,7 @@ IVtkDraw_HighlightAndSelectionPipeline::IVtkDraw_HighlightAndSelectionPipeline (
// No highligthing exists initially // No highligthing exists initially
aSUBFilterH->SetInputConnection (aDataSource->GetOutputPort() ); aSUBFilterH->SetInputConnection (aDataSource->GetOutputPort() );
aDMFilterH->SetInputConnection (aSUBFilterH->GetOutputPort() ); aDMFilterH->SetInputConnection(aSUBFilterH->GetOutputPort());
myHiliMapper = vtkSmartPointer<vtkPolyDataMapper>::New(); myHiliMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
myHiliMapper->SetInputConnection (aDMFilterH->GetOutputPort() ); myHiliMapper->SetInputConnection (aDMFilterH->GetOutputPort() );
@ -115,7 +116,7 @@ IVtkDraw_HighlightAndSelectionPipeline::IVtkDraw_HighlightAndSelectionPipeline (
// No highligthing exists initially // No highligthing exists initially
aSUBFilterS->SetInputConnection (aDataSource->GetOutputPort() ); aSUBFilterS->SetInputConnection (aDataSource->GetOutputPort() );
aDMFilterS->SetInputConnection (aSUBFilterS->GetOutputPort() ); aDMFilterS->SetInputConnection(aSUBFilterS->GetOutputPort());
mySelMapper = vtkSmartPointer<vtkPolyDataMapper>::New(); mySelMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mySelMapper->SetInputConnection (aDMFilterS->GetOutputPort() ); mySelMapper->SetInputConnection (aDMFilterS->GetOutputPort() );
@ -154,6 +155,14 @@ void IVtkDraw_HighlightAndSelectionPipeline::RemoveFromRenderer (vtkRenderer* th
theRenderer->RemoveActor (myActor); theRenderer->RemoveActor (myActor);
theRenderer->RemoveActor (myHiliActor); theRenderer->RemoveActor (myHiliActor);
theRenderer->RemoveActor (mySelActor); 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() 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() 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() 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() 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() IVtkTools_DisplayModeFilter* IVtkDraw_HighlightAndSelectionPipeline::GetSelectionDMFilter()
{ {
return IVtkTools_DisplayModeFilter::SafeDownCast (myFilterMap.Find(Filter_DM_Sel)); return IVtkTools_DisplayModeFilter::SafeDownCast(myFilterMap.Find(Filter_DM_Sel));
} }
//=========================================================== //===========================================================

View File

@ -14,7 +14,6 @@
// commercial license or contractual agreement. // commercial license or contractual agreement.
#ifdef _WIN32 #ifdef _WIN32
#define _WIN32_WINNT 0x0400 // for trackmouseevent support requires Win95 with IE 3.0 or greater.
#include <windows.h> #include <windows.h>
#include <vtkWin32RenderWindowInteractor.h> #include <vtkWin32RenderWindowInteractor.h>
#include <vtkWin32OpenGLRenderWindow.h> #include <vtkWin32OpenGLRenderWindow.h>
@ -225,7 +224,7 @@ void IVtkDraw_Interactor::MoveTo (Standard_Integer theX, Standard_Integer theY)
{ {
// Processing highlighting // Processing highlighting
mySelector->Pick (theX, theY, 0.0); mySelector->Pick (theX, theY, 0.0);
vtkActorCollection* anActorCollection = mySelector->GetPickedActors(); vtkSmartPointer<vtkActorCollection> anActorCollection = mySelector->GetPickedActors();
if (anActorCollection) if (anActorCollection)
{ {
@ -290,7 +289,7 @@ void IVtkDraw_Interactor::MoveTo (Standard_Integer theX, Standard_Integer theY)
void IVtkDraw_Interactor::OnSelection() void IVtkDraw_Interactor::OnSelection()
{ {
// Processing selection // Processing selection
vtkActorCollection* anActorCollection = mySelector->GetPickedActors(); vtkSmartPointer<vtkActorCollection> anActorCollection = mySelector->GetPickedActors();
if (anActorCollection) if (anActorCollection)
{ {

View File

@ -56,6 +56,13 @@ IVtkOCC_SelectableObject::IVtkOCC_SelectableObject()
myShape (0) myShape (0)
{ } { }
//============================================================================
// Method: Destructor
// Purpose:
//============================================================================
IVtkOCC_SelectableObject::~IVtkOCC_SelectableObject()
{ }
//============================================================================ //============================================================================
// Method: SetShape // Method: SetShape
// Purpose: Sets the selectable shape // Purpose: Sets the selectable shape

View File

@ -22,6 +22,8 @@
#include <SelectMgr_SelectableObject.hxx> #include <SelectMgr_SelectableObject.hxx>
#include <SelectMgr_Selection.hxx> #include <SelectMgr_Selection.hxx>
class IVtkOCC_SelectableObject;
DEFINE_STANDARD_HANDLE(IVtkOCC_SelectableObject, SelectMgr_SelectableObject)
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
//! @class IVtkOCC_SelectableObject //! @class IVtkOCC_SelectableObject
//! @brief Class with selection primitives used by OCCT selection algorithm. //! @brief Class with selection primitives used by OCCT selection algorithm.
@ -29,6 +31,8 @@ class IVtkOCC_SelectableObject : public SelectMgr_SelectableObject
{ {
public: public:
typedef Handle(IVtkOCC_SelectableObject) Handle;
//! Constructs a selectable object initialized by the given shape //! Constructs a selectable object initialized by the given shape
//! @param [in] theShape Selectable shape //! @param [in] theShape Selectable shape
IVtkOCC_SelectableObject (const IVtkOCC_Shape::Handle& theShape); IVtkOCC_SelectableObject (const IVtkOCC_Shape::Handle& theShape);
@ -37,9 +41,11 @@ public:
//! setShape() should be called later. //! setShape() should be called later.
IVtkOCC_SelectableObject(); IVtkOCC_SelectableObject();
virtual ~IVtkOCC_SelectableObject();
//! Sets the selectable shape //! Sets the selectable shape
//! @param [in] theShape 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; }; const IVtkOCC_Shape::Handle& GetShape() const { return myShape; };
@ -64,6 +70,4 @@ private:
Handle(Prs3d_Drawer) myOCCTDrawer; Handle(Prs3d_Drawer) myOCCTDrawer;
}; };
DEFINE_STANDARD_HANDLE( IVtkOCC_SelectableObject, SelectMgr_SelectableObject )
#endif // __IVTKOCC_SELECTABLEOBJECT_H__ #endif // __IVTKOCC_SELECTABLEOBJECT_H__

View File

@ -13,7 +13,6 @@
// Alternatively, this file may be used under the terms of Open CASCADE // Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement. // commercial license or contractual agreement.
#include <Adaptor3d_HCurve.hxx>
#include <Adaptor3d_IsoCurve.hxx> #include <Adaptor3d_IsoCurve.hxx>
#include <Bnd_Box.hxx> #include <Bnd_Box.hxx>
#include <BRep_Tool.hxx> #include <BRep_Tool.hxx>
@ -107,7 +106,7 @@ Standard_Real IVtkOCC_ShapeMesher::GetDeflection() const
//================================================================ //================================================================
void IVtkOCC_ShapeMesher::meshShape() void IVtkOCC_ShapeMesher::meshShape()
{ {
TopoDS_Shape anOcctShape = GetShapeObj()->GetShape(); const TopoDS_Shape& anOcctShape = GetShapeObj()->GetShape();
if (anOcctShape.IsNull()) if (anOcctShape.IsNull())
{ {
return; return;
@ -164,7 +163,7 @@ void IVtkOCC_ShapeMesher::addFreeVertices()
{ {
aType = MT_SharedVertex; 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); addVertex (aVertex, GetShapeObj()->GetSubShapeId (aVertex), aType);
} }
} }
@ -188,7 +187,7 @@ void IVtkOCC_ShapeMesher::addEdges()
TopExp_Explorer anEdgeIter (GetShapeObj()->GetShape(), TopAbs_EDGE); TopExp_Explorer anEdgeIter (GetShapeObj()->GetShape(), TopAbs_EDGE);
for (; anEdgeIter.More(); anEdgeIter.Next()) 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(); aNbFaces = anEdgesMap.FindFromKey (anOcctEdge).Extent();
if (aNbFaces == 0) if (aNbFaces == 0)
{ {
@ -222,7 +221,7 @@ void IVtkOCC_ShapeMesher::addWireFrameFaces()
TopExp_Explorer aFaceIter (GetShapeObj()->GetShape(), TopAbs_FACE); TopExp_Explorer aFaceIter (GetShapeObj()->GetShape(), TopAbs_FACE);
for (; aFaceIter.More(); aFaceIter.Next()) for (; aFaceIter.More(); aFaceIter.Next())
{ {
TopoDS_Face anOcctFace = TopoDS::Face (aFaceIter.Current()); const TopoDS_Face& anOcctFace = TopoDS::Face (aFaceIter.Current());
try try
{ {
OCC_CATCH_SIGNALS OCC_CATCH_SIGNALS
@ -243,7 +242,7 @@ void IVtkOCC_ShapeMesher::addShadedFaces()
TopExp_Explorer aFaceIter (GetShapeObj()->GetShape(), TopAbs_FACE); TopExp_Explorer aFaceIter (GetShapeObj()->GetShape(), TopAbs_FACE);
for (; aFaceIter.More(); aFaceIter.Next()) for (; aFaceIter.More(); aFaceIter.Next())
{ {
TopoDS_Face anOcctFace = TopoDS::Face (aFaceIter.Current()); const TopoDS_Face& anOcctFace = TopoDS::Face (aFaceIter.Current());
addShadedFace (anOcctFace, addShadedFace (anOcctFace,
GetShapeObj()->GetSubShapeId (anOcctFace)); GetShapeObj()->GetSubShapeId (anOcctFace));
} }
@ -287,7 +286,7 @@ void IVtkOCC_ShapeMesher::processPolyline (Standard_Integer theNbNodes,
return; return;
} }
IVtk_PointIdList *aPolyPointIds = new IVtk_PointIdList(); IVtk_PointIdList aPolyPointIds;
IVtk_PointId anId; IVtk_PointId anId;
for (Standard_Integer aJ = 0; aJ < theNbNodes; aJ++) for (Standard_Integer aJ = 0; aJ < theNbNodes; aJ++)
@ -302,12 +301,10 @@ void IVtkOCC_ShapeMesher::processPolyline (Standard_Integer theNbNodes,
} }
anId = myShapeData->InsertCoordinate (point.X(), point.Y(), point.Z()); anId = myShapeData->InsertCoordinate (point.X(), point.Y(), point.Z());
aPolyPointIds->Append (anId); aPolyPointIds.Append (anId);
} }
myShapeData->InsertLine (theOcctId, aPolyPointIds, theMeshType); myShapeData->InsertLine (theOcctId, &aPolyPointIds, theMeshType);
delete aPolyPointIds;
} }
//================================================================ //================================================================
@ -821,7 +818,7 @@ void IVtkOCC_ShapeMesher::addWFFace (const TopoDS_Face& theFace,
TopExp_Explorer anEdgeIter (aFaceToMesh, TopAbs_EDGE ); TopExp_Explorer anEdgeIter (aFaceToMesh, TopAbs_EDGE );
for (; anEdgeIter.More(); anEdgeIter.Next()) 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)); addEdge (anOcctEdge, theShapeId, myEdgesTypes (anOcctEdge));
} }

View File

@ -259,9 +259,7 @@ void IVtkOCC_ShapePickerAlgo::SubShapesPicked (const IVtk_IdType theId, IVtk_Sha
{ {
if (mySubShapesPicked.IsBound (theId)) if (mySubShapesPicked.IsBound (theId))
{ {
// Need non-const this to call the map's operator[] theShapeList = mySubShapesPicked (theId);
IVtkOCC_ShapePickerAlgo* that = const_cast< IVtkOCC_ShapePickerAlgo* >(this);
theShapeList = that->mySubShapesPicked (theId);
} }
} }
@ -354,3 +352,23 @@ bool IVtkOCC_ShapePickerAlgo::processPicked()
return !myShapesPicked.IsEmpty(); 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);
}

View File

@ -96,6 +96,10 @@ public: //! @name Obtain picking results
Standard_EXPORT virtual void Standard_EXPORT virtual void
SubShapesPicked (const IVtk_IdType theId, IVtk_ShapeIdList& theShapeList) const Standard_OVERRIDE; 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: public:
DEFINE_STANDARD_RTTIEXT(IVtkOCC_ShapePickerAlgo,IVtk_IShapePickerAlgo) DEFINE_STANDARD_RTTIEXT(IVtkOCC_ShapePickerAlgo,IVtk_IShapePickerAlgo)

View File

@ -28,7 +28,17 @@ IMPLEMENT_STANDARD_RTTIEXT(IVtkOCC_ViewerSelector,SelectMgr_ViewerSelector)
IVtkOCC_ViewerSelector::IVtkOCC_ViewerSelector() IVtkOCC_ViewerSelector::IVtkOCC_ViewerSelector()
: SelectMgr_ViewerSelector(), : SelectMgr_ViewerSelector(),
myPixTol(2), myPixTol(2),
myToUpdateTol(Standard_True) {} myToUpdateTol(Standard_True)
{
}
//============================================================================
// Method: Destructor
// Purpose:
//============================================================================
IVtkOCC_ViewerSelector::~IVtkOCC_ViewerSelector()
{
}
//============================================================================ //============================================================================
// Method: Pick // Method: Pick

View File

@ -31,6 +31,8 @@ class IVtkOCC_ViewerSelector : public SelectMgr_ViewerSelector
public: public:
IVtkOCC_ViewerSelector(); IVtkOCC_ViewerSelector();
virtual ~IVtkOCC_ViewerSelector();
//! Implements point picking //! Implements point picking
//! @param [in] theXPix, theYPix Display coordinates of the point //! @param [in] theXPix, theYPix Display coordinates of the point
//! @param [in] theView ICamera interface to update the projection parameters. //! @param [in] theView ICamera interface to update the projection parameters.

View File

@ -24,9 +24,10 @@ namespace IVtkTools
// Method: InitLookupTable // Method: InitLookupTable
// Purpose: Returns vtkLookupTable instance initialized by standrad OCCT colors. // 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 // Set colors table for 3D shapes
double aRange[2]; double aRange[2];
aRange[0] = MT_Undefined; aRange[0] = MT_Undefined;

View File

@ -17,6 +17,7 @@
#define IVtkTOOLS_H #define IVtkTOOLS_H
#include <IVtk_Types.hxx> #include <IVtk_Types.hxx>
#include <vtkSmartPointer.h>
#if defined(_WIN32) && !defined(HAVE_NO_DLL) #if defined(_WIN32) && !defined(HAVE_NO_DLL)
#ifdef __IVtkTools_DLL #ifdef __IVtkTools_DLL
@ -38,7 +39,7 @@ namespace IVtkTools
//! Returns vtkLookupTable instance initialized by standrad OCCT colors used //! Returns vtkLookupTable instance initialized by standrad OCCT colors used
//! in wireframe mode for different kinds of sub-shapes (free/boundary/shared //! in wireframe mode for different kinds of sub-shapes (free/boundary/shared
//! edges, isolines,...) //! edges, isolines,...)
Standard_EXPORT vtkLookupTable* InitLookupTable(); Standard_EXPORT vtkSmartPointer<vtkLookupTable> InitLookupTable();
//! Set a color for given type of sub-shapes. //! Set a color for given type of sub-shapes.
//! @param [in,out] theColorTable vtkLookupTable to set the color. //! @param [in,out] theColorTable vtkLookupTable to set the color.

View File

@ -18,7 +18,6 @@
#include <IVtkTools.hxx> #include <IVtkTools.hxx>
#include <IVtkTools_SubPolyDataFilter.hxx> #include <IVtkTools_SubPolyDataFilter.hxx>
#include <IVtk_Types.hxx>
#include <NCollection_DataMap.hxx> #include <NCollection_DataMap.hxx>
//! @class IVtkTools_DisplayModeFilter //! @class IVtkTools_DisplayModeFilter
@ -47,7 +46,7 @@ protected:
virtual int RequestData (vtkInformation *, vtkInformationVector **, vtkInformationVector *); virtual int RequestData (vtkInformation *, vtkInformationVector **, vtkInformationVector *);
IVtkTools_DisplayModeFilter(); IVtkTools_DisplayModeFilter();
~IVtkTools_DisplayModeFilter(); virtual ~IVtkTools_DisplayModeFilter();
protected: protected:
//! Display mode defining mesh types to pass through this filter. //! Display mode defining mesh types to pass through this filter.

View File

@ -14,20 +14,17 @@
// commercial license or contractual agreement. // commercial license or contractual agreement.
// VIS includes // VIS includes
#include <IVtkOCC_ShapeMesher.hxx>
#include <IVtkTools_ShapeDataSource.hxx> #include <IVtkTools_ShapeDataSource.hxx>
#include <IVtkOCC_ShapeMesher.hxx>
#include <IVtkTools_ShapeObject.hxx> #include <IVtkTools_ShapeObject.hxx>
// VTK includes // VTK includes
#include <vtkCellArray.h> #include <vtkObjectFactory.h>
#include <vtkCellData.h> #include <vtkCellData.h>
#include <vtkDoubleArray.h>
#include <vtkIdTypeArray.h> #include <vtkIdTypeArray.h>
#include <vtkInformation.h> #include <vtkInformation.h>
#include <vtkObjectFactory.h>
#include <vtkPoints.h> #include <vtkPoints.h>
#include <vtkPolyData.h> #include <vtkPolyData.h>
#include <vtkStreamingDemandDrivenPipeline.h>
#include <vtkTransform.h> #include <vtkTransform.h>
#include <vtkTransformPolyDataFilter.h> #include <vtkTransformPolyDataFilter.h>
@ -42,7 +39,8 @@ IVtkTools_ShapeDataSource::IVtkTools_ShapeDataSource()
myIsFastTransformMode (Standard_False), myIsFastTransformMode (Standard_False),
myIsTransformOnly (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 // Function : RequestData
// Purpose : // Purpose :
//================================================================ //================================================================
int IVtkTools_ShapeDataSource::RequestData (vtkInformation* theRequest, int IVtkTools_ShapeDataSource::RequestData(vtkInformation *vtkNotUsed(theRequest),
vtkInformationVector** theInputVector, vtkInformationVector **vtkNotUsed(theInputVector),
vtkInformationVector* theOutputVector) vtkInformationVector *theOutputVector)
{ {
vtkPolyData* aPolyData = vtkPolyData::GetData (theOutputVector); vtkSmartPointer<vtkPolyData> aPolyData = vtkPolyData::GetData (theOutputVector);
aPolyData->Allocate(); if (aPolyData.GetPointer() != NULL)
vtkPoints* aPts = vtkPoints::New();
aPolyData->SetPoints (aPts);
aPts->Delete();
vtkSmartPointer<vtkPolyData> aTransformedData;
TopoDS_Shape aShape = myOccShape->GetShape();
TopLoc_Location aShapeLoc = aShape.Location();
if (myIsTransformOnly)
{ {
vtkPolyData* aPrevData = myPolyData->getVtkPolyData(); aPolyData->Allocate();
if (!aShapeLoc.IsIdentity() ) 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 else
{ {
aTransformedData = aPrevData; IVtkOCC_Shape::Handle aShapeWrapperCopy;
} if ( myIsFastTransformMode && !aShapeLoc.IsIdentity() )
} {
else // Reset location before meshing
{ aShape.Location (TopLoc_Location());
IVtkOCC_Shape::Handle aShapeWrapperCopy; aShapeWrapperCopy = new IVtkOCC_Shape (aShape);
if (myIsFastTransformMode && !aShapeLoc.IsIdentity() ) aShapeWrapperCopy->SetId (myOccShape->GetId());
{ }
// Reset location before meshing else
aShape.Location (TopLoc_Location() ); {
aShapeWrapperCopy = new IVtkOCC_Shape (aShape); aShapeWrapperCopy = myOccShape;
aShapeWrapperCopy->SetId (myOccShape->GetId() ); }
}
else myPolyData = new IVtkVTK_ShapeData;
{ IVtkOCC_ShapeMesher::Handle aMesher = new IVtkOCC_ShapeMesher;
aShapeWrapperCopy = myOccShape; 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; aPolyData->CopyStructure (aTransformedData); // Copy points and cells
IVtkOCC_ShapeMesher::Handle aMesher = new IVtkOCC_ShapeMesher; aPolyData->CopyAttributes (aTransformedData); // Copy data arrays (sub-shapes IDs)
aMesher->Build (aShapeWrapperCopy, myPolyData);
vtkPolyData* aMeshData = myPolyData->getVtkPolyData();
if (myIsFastTransformMode && !aShapeLoc.IsIdentity() ) // We store the OccShape instance in a IVtkTools_ShapeObject
{ // wrapper in vtkInformation object of vtkDataObject, then pass it
aTransformedData = this->transform (aMeshData, aShapeLoc); // to the actors through pipelines, so selection logic can access
} // OccShape easily given the actor instance.
else IVtkTools_ShapeObject::SetShapeSource (this, aPolyData);
{ aPolyData->GetAttributes (vtkDataObject::CELL)->SetPedigreeIds (SubShapeIDs());
aTransformedData = aMeshData;
}
} }
aPolyData->CopyStructure (aTransformedData); // Copy points and cells return 1;
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);
} }
//================================================================ //================================================================
@ -160,8 +160,10 @@ int IVtkTools_ShapeDataSource::RequestData (vtkInformation* theRequest,
//================================================================ //================================================================
vtkSmartPointer<vtkIdTypeArray> IVtkTools_ShapeDataSource::SubShapeIDs() vtkSmartPointer<vtkIdTypeArray> IVtkTools_ShapeDataSource::SubShapeIDs()
{ {
vtkDataArray* arr = GetOutput()->GetCellData()->GetArray(IVtkVTK_ShapeData::ARRNAME_SUBSHAPE_IDS); vtkSmartPointer<vtkDataArray> arr =
return vtkSmartPointer<vtkIdTypeArray>( vtkIdTypeArray::SafeDownCast(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->SetInputData (theSource);
aTrsfFilter->Update(); aTrsfFilter->Update();
vtkPolyData* aTransformed = aTrsfFilter->GetOutput(); vtkSmartPointer<vtkPolyData> aTransformed = aTrsfFilter->GetOutput();
aResult->CopyStructure (aTransformed); // Copy points and cells aResult->CopyStructure (aTransformed); // Copy points and cells
aResult->CopyAttributes (aTransformed); // Copy data arrays (sub-shapes ids) aResult->CopyAttributes (aTransformed); // Copy data arrays (sub-shapes ids)

View File

@ -19,10 +19,7 @@
#include <IVtkTools.hxx> #include <IVtkTools.hxx>
#include <IVtkOCC_Shape.hxx> #include <IVtkOCC_Shape.hxx>
#include <IVtkVTK_ShapeData.hxx> #include <IVtkVTK_ShapeData.hxx>
#include <vtkInformationIdTypeKey.h>
#include <vtkPolyDataAlgorithm.h> #include <vtkPolyDataAlgorithm.h>
#include <vtkType.h>
#include <vtkSmartPointer.h>
class vtkIdTypeArray; class vtkIdTypeArray;
class vtkPolyData; class vtkPolyData;
@ -91,7 +88,7 @@ protected: //! @name Internals
protected: protected:
IVtkTools_ShapeDataSource(); IVtkTools_ShapeDataSource();
~IVtkTools_ShapeDataSource(); virtual ~IVtkTools_ShapeDataSource();
private: private:

View File

@ -16,12 +16,10 @@
#include <IVtkTools_ShapeObject.hxx> #include <IVtkTools_ShapeObject.hxx>
#include <IVtkTools_ShapeDataSource.hxx> #include <IVtkTools_ShapeDataSource.hxx>
#include <vtkActor.h> #include <vtkActor.h>
#include <vtkObjectBase.h>
#include <vtkObjectFactory.h> #include <vtkObjectFactory.h>
#include <vtkDataSet.h> #include <vtkDataSet.h>
#include <vtkInformation.h> #include <vtkInformation.h>
#include <vtkInformationObjectBaseKey.h> #include <vtkInformationObjectBaseKey.h>
#include <vtkDebugLeaks.h>
#include <vtkPolyData.h> #include <vtkPolyData.h>
IVtkTools_ShapeObject::KeyPtr IVtkTools_ShapeObject::myKey = 0; 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 IVtkTools_ShapeObject::GetOccShape (vtkActor* theActor)
{ {
IVtkOCC_Shape::Handle anOccShape; IVtkOCC_Shape::Handle anOccShape;
IVtkTools_ShapeDataSource* aSrc = IVtkTools_ShapeObject::GetShapeSource (theActor); vtkSmartPointer<IVtkTools_ShapeDataSource> aSrc =
if (aSrc) IVtkTools_ShapeObject::GetShapeSource (theActor);
if (aSrc.GetPointer() != NULL)
{ {
anOccShape = aSrc->GetShape(); 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 // Purpose: Static method to get OCC shape source from VTK actor's data from
// information object by key. // information object by key.
//============================================================================ //============================================================================
IVtkTools_ShapeDataSource* IVtkTools_ShapeObject::GetShapeSource (vtkActor* theActor) vtkSmartPointer<IVtkTools_ShapeDataSource> IVtkTools_ShapeObject
::GetShapeSource (vtkActor* theActor)
{ {
IVtkTools_ShapeDataSource* anOccShapeSource = 0; vtkSmartPointer<IVtkTools_ShapeDataSource> anOccShapeSource;
vtkInformation* anInfo = theActor->GetPropertyKeys(); vtkSmartPointer<vtkInformation> anInfo = theActor->GetPropertyKeys();
if (anInfo) if (anInfo.GetPointer() != NULL)
{ {
KeyPtr aKey = getKey(); KeyPtr aKey = getKey();
if (aKey->Has(anInfo)) 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(); anOccShapeSource = aShapeObj->GetShapeSource();
} }
} }
@ -88,14 +89,14 @@ void IVtkTools_ShapeObject::SetShapeSource (IVtkTools_ShapeDataSource* theDataSo
{ {
if (!theDataSet->GetInformation() ) if (!theDataSet->GetInformation() )
{ {
theDataSet->SetInformation (vtkInformation::New()); theDataSet->SetInformation (vtkSmartPointer<vtkInformation>::New());
} }
vtkInformation* aDatasetInfo = theDataSet->GetInformation(); vtkSmartPointer<vtkInformation> aDatasetInfo = theDataSet->GetInformation();
KeyPtr aKey = getKey(); KeyPtr aKey = getKey();
IVtkTools_ShapeObject* aShapeObj = IVtkTools_ShapeObject::New(); vtkSmartPointer<IVtkTools_ShapeObject> aShapeObj =
vtkSmartPointer<IVtkTools_ShapeObject>::New();
aShapeObj->SetShapeSource (theDataSource); aShapeObj->SetShapeSource (theDataSource);
aKey->Set(aDatasetInfo, aShapeObj); aKey->Set(aDatasetInfo, aShapeObj);
aShapeObj->Delete();
} }
//============================================================================ //============================================================================
@ -108,15 +109,15 @@ void IVtkTools_ShapeObject::SetShapeSource (IVtkTools_ShapeDataSource* theDataSo
{ {
if ( !theActor->GetPropertyKeys() ) if ( !theActor->GetPropertyKeys() )
{ {
theActor->SetPropertyKeys (vtkInformation::New()); theActor->SetPropertyKeys (vtkSmartPointer<vtkInformation>::New());
} }
vtkInformation* anInfo = theActor->GetPropertyKeys(); vtkSmartPointer<vtkInformation> anInfo = theActor->GetPropertyKeys();
KeyPtr aKey = getKey(); KeyPtr aKey = getKey();
IVtkTools_ShapeObject* aShapeObj = IVtkTools_ShapeObject::New(); vtkSmartPointer<IVtkTools_ShapeObject> aShapeObj =
aShapeObj->SetShapeSource (theDataSource); vtkSmartPointer<IVtkTools_ShapeObject>::New();
aShapeObj->SetShapeSource(theDataSource);
aKey->Set (anInfo, aShapeObj); aKey->Set (anInfo, aShapeObj);
aShapeObj->Delete();
} }
//! @class IVtkTools_ShapeObject //! @class IVtkTools_ShapeObject
@ -150,7 +151,7 @@ void IVtkTools_ShapeObject::SetShapeSource (IVtkTools_ShapeDataSource* theDataSo
// Method: GetShapeSource // Method: GetShapeSource
// Purpose: // Purpose:
//============================================================================ //============================================================================
IVtkTools_ShapeDataSource* IVtkTools_ShapeObject::GetShapeSource () const IVtkTools_ShapeDataSource* IVtkTools_ShapeObject::GetShapeSource() const
{ {
return myShapeSource; return myShapeSource;
} }

View File

@ -20,7 +20,7 @@
#include <IVtkOCC_Shape.hxx> #include <IVtkOCC_Shape.hxx>
#include <vtkDataObject.h> #include <vtkDataObject.h>
#include <vtkSetGet.h> #include <vtkSetGet.h>
#include <vtkSmartPointer.h> #include <vtkWeakPointer.h>
class vtkActor; class vtkActor;
class vtkDataSet; class vtkDataSet;
@ -42,7 +42,7 @@ public:
static IVtkTools_ShapeObject* New(); static IVtkTools_ShapeObject* New();
//! Get OCC shape source from VTK data from actor's information object by key. //! 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. //! Get OCC shape from VTK data from actor's information object by key.
static IVtkOCC_Shape::Handle GetOccShape (vtkActor* theActor); static IVtkOCC_Shape::Handle GetOccShape (vtkActor* theActor);
@ -66,18 +66,18 @@ public:
void SetShapeSource (IVtkTools_ShapeDataSource* theDataSource); void SetShapeSource (IVtkTools_ShapeDataSource* theDataSource);
//! OCC shape source getter. //! OCC shape source getter.
IVtkTools_ShapeDataSource* GetShapeSource () const; IVtkTools_ShapeDataSource* GetShapeSource() const;
protected: protected:
IVtkTools_ShapeObject(); IVtkTools_ShapeObject();
~IVtkTools_ShapeObject(); virtual ~IVtkTools_ShapeObject();
private: // not copyable private: // not copyable
IVtkTools_ShapeObject (const IVtkTools_ShapeObject&); IVtkTools_ShapeObject (const IVtkTools_ShapeObject&);
IVtkTools_ShapeObject& operator= (const IVtkTools_ShapeObject&); IVtkTools_ShapeObject& operator= (const IVtkTools_ShapeObject&);
private: // OCC private: // OCC
vtkSmartPointer<IVtkTools_ShapeDataSource> myShapeSource; vtkWeakPointer<IVtkTools_ShapeDataSource> myShapeSource;
static KeyPtr myKey; static KeyPtr myKey;
}; };

View File

@ -16,7 +16,6 @@
#include <IVtkTools_ShapePicker.hxx> #include <IVtkTools_ShapePicker.hxx>
#include <IVtkTools_ShapeObject.hxx> #include <IVtkTools_ShapeObject.hxx>
#include <IVtkVTK_View.hxx> #include <IVtkVTK_View.hxx>
#include <IVtkOCC_Shape.hxx>
#include <vtkCommand.h> #include <vtkCommand.h>
#include <vtkObjectFactory.h> #include <vtkObjectFactory.h>
#include <vtkRenderer.h> #include <vtkRenderer.h>
@ -37,7 +36,7 @@ vtkStandardNewMacro(IVtkTools_ShapePicker)
// Purpose: Constructs the picker with empty renderer and ready for point selection. // Purpose: Constructs the picker with empty renderer and ready for point selection.
//============================================================================ //============================================================================
IVtkTools_ShapePicker::IVtkTools_ShapePicker() IVtkTools_ShapePicker::IVtkTools_ShapePicker()
: myRenderer (0), : myRenderer (NULL),
myIsRectSelection (false) myIsRectSelection (false)
{ {
myOccPickerAlgo = new IVtkOCC_ShapePickerAlgo(); myOccPickerAlgo = new IVtkOCC_ShapePickerAlgo();
@ -81,7 +80,8 @@ bool IVtkTools_ShapePicker::convertDisplayToWorld (vtkRenderer *theRenderer,
theRenderer->SetDisplayPoint (theDisplayCoord[0], theDisplayCoord[1], theDisplayCoord[2]); theRenderer->SetDisplayPoint (theDisplayCoord[0], theDisplayCoord[1], theDisplayCoord[2]);
theRenderer->DisplayToWorld(); theRenderer->DisplayToWorld();
double* const aCoords = theRenderer->GetWorldPoint(); double aCoords[4];
theRenderer->GetWorldPoint(aCoords);
if (aCoords[3] == 0.0) if (aCoords[3] == 0.0)
{ {
return false; return false;
@ -91,6 +91,7 @@ bool IVtkTools_ShapePicker::convertDisplayToWorld (vtkRenderer *theRenderer,
{ {
theWorldCoord[anI] = aCoords[anI] / aCoords[3]; theWorldCoord[anI] = aCoords[anI] / aCoords[3];
} }
return true; return true;
} }
@ -144,7 +145,7 @@ int IVtkTools_ShapePicker::pick (double* thePos,
// Emit StartPickEvent for observer callbacks (if any) // Emit StartPickEvent for observer callbacks (if any)
InvokeEvent(vtkCommand::StartPickEvent, NULL); InvokeEvent(vtkCommand::StartPickEvent, NULL);
vtkRenderer* aRenderer; vtkSmartPointer<vtkRenderer> aRenderer;
if (theRenderer == NULL) if (theRenderer == NULL)
{ {
aRenderer = myRenderer; // by default use own renderer aRenderer = myRenderer; // by default use own renderer
@ -192,7 +193,7 @@ void IVtkTools_ShapePicker::doPickImpl (double* thePos,
//============================================================================ //============================================================================
void IVtkTools_ShapePicker::SetRenderer (vtkRenderer* theRenderer) void IVtkTools_ShapePicker::SetRenderer (vtkRenderer* theRenderer)
{ {
if (theRenderer == myRenderer) if (theRenderer == myRenderer.GetPointer())
{ {
return; return;
// In this case we should not do anything. // 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, void IVtkTools_ShapePicker::SetSelectionMode (const IVtk_SelectionMode theMode,
const bool theIsTurnOn) const const bool theIsTurnOn) const
{ {
if (myRenderer) if (myRenderer.GetPointer() != NULL)
{ {
// Obtain all OccShapes displayed and activate the specified selection mode // Obtain all OccShapes displayed and activate the specified selection mode
vtkActorCollection *anActors = myRenderer->GetActors(); vtkSmartPointer<vtkActorCollection> anActors = myRenderer->GetActors();
anActors->InitTraversal(); anActors->InitTraversal();
while ( vtkActor* anActor = anActors->GetNextActor() ) vtkSmartPointer<vtkActor> anActor = anActors->GetNextActor();
while ( anActor.GetPointer() != NULL )
{ {
if (anActor->GetPickable() && anActor->GetVisibility()) 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; 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 // Method: GetPickedSubShapesIds
// Purpose: Access to the list of sub-shapes ids picked. // 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; IVtk_ShapeIdList aRes;
if (theIsAll) if (theIsAll)
{ {
myOccPickerAlgo->SubShapesPicked (theId,aRes); myOccPickerAlgo->SubShapesPicked (theId, aRes);
} }
else else
{ {
@ -342,16 +367,17 @@ IVtk_ShapeIdList IVtkTools_ShapePicker::GetPickedSubShapesIds (const IVtk_IdType
// Method: GetPickedActors // Method: GetPickedActors
// Purpose: Access to the list of actors picked. // 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); IVtk_ShapeIdList anIds = GetPickedShapesIds (theIsAll);
if (myRenderer) if (myRenderer.GetPointer() != NULL)
{ {
// Obtain all actors whose source shape ids are within selected ids. // Obtain all actors whose source shape ids are within selected ids.
vtkActorCollection *anActors = myRenderer->GetActors(); vtkSmartPointer<vtkActorCollection> anActors = myRenderer->GetActors();
anActors->InitTraversal(); anActors->InitTraversal();
while ( vtkActor* anActor = anActors->GetNextActor() ) vtkSmartPointer<vtkActor> anActor = anActors->GetNextActor();
while ( anActor.GetPointer() != NULL )
{ {
if (anActor->GetPickable() && anActor->GetVisibility()) if (anActor->GetPickable() && anActor->GetVisibility())
{ {
@ -370,6 +396,7 @@ vtkActorCollection* IVtkTools_ShapePicker::GetPickedActors (bool theIsAll) const
} }
} }
} }
anActor = anActors->GetNextActor();
} }
} }
return aRes; return aRes;

View File

@ -20,6 +20,7 @@
#include <IVtk_Types.hxx> #include <IVtk_Types.hxx>
#include <IVtkOCC_ShapePickerAlgo.hxx> #include <IVtkOCC_ShapePickerAlgo.hxx>
#include <vtkAbstractPropPicker.h> #include <vtkAbstractPropPicker.h>
#include <vtkSmartPointer.h>
class vtkRenderer; class vtkRenderer;
class vtkActorCollection; class vtkActorCollection;
@ -79,9 +80,9 @@ public:
const bool theIsTurnOn = true) const; const bool theIsTurnOn = true) const;
//! Turn on/off a selection mode for a shape actor. //! Turn on/off a selection mode for a shape actor.
//! @param [in] shapeActor shape presentation actor to set a selection mode for //! @param [in] theShapeActor shape presentation actor to set a selection mode for
//! @param [in] mode selection mode to be activated //! @param [in] theMode selection mode to be activated
//! @param [in] turnOn Flag to turn on/off the selection mode //! @param [in] theIsTurnOn Flag to turn on/off the selection mode
void SetSelectionMode (vtkActor* theShapeActor, void SetSelectionMode (vtkActor* theShapeActor,
const IVtk_SelectionMode theMode, const IVtk_SelectionMode theMode,
const bool theIsTurnOn = true) const; const bool theIsTurnOn = true) const;
@ -99,29 +100,37 @@ public:
//! all OccShape objects found by the picking algorithm. e.g. all //! 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 //! shapes under the mouse cursor. Otherwise, ID of the shape closest to the eye
//! is returned. //! 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. //! top one is returned, has no effect during area selection.
//! @return List of top-level shape IDs //! @return List of top-level shape IDs
IVtk_ShapeIdList GetPickedShapesIds (bool theIsAll = false) const; IVtk_ShapeIdList GetPickedShapesIds (bool theIsAll = false) const;
//! Access to the list of sub-shapes ids picked. //! Access to the list of sub-shapes ids picked.
//! @param [in] id top-level shape ID //! @param [in] theId top-level shape ID
//! @param [in] all Controls if all selected sub-shapes or just the //! @param [in] theIsAll Get all selected sub-shapes or just the
//! only top one is returned, has no effect during area selection. //! only top one is returned, has no effect during area selection.
//! @return List of sub-shapes IDs //! @return List of sub-shapes IDs
IVtk_ShapeIdList GetPickedSubShapesIds (const IVtk_IdType theId, bool theIsAll = false) const; IVtk_ShapeIdList GetPickedSubShapesIds (const IVtk_IdType theId, bool theIsAll = false) const;
//! Access to the list of actors picked. //! 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. //! top one is returned, has no effect during area selection.
//! @return List of actors IDs //! @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: protected:
//! Constructs the picker with empty renderer and ready for point selection. //! Constructs the picker with empty renderer and ready for point selection.
IVtkTools_ShapePicker(); IVtkTools_ShapePicker();
//! Destructor //! Destructor
~IVtkTools_ShapePicker(); virtual ~IVtkTools_ShapePicker();
//! Convert display coordinates to world coordinates //! Convert display coordinates to world coordinates
static bool convertDisplayToWorld (vtkRenderer *theRenderer, static bool convertDisplayToWorld (vtkRenderer *theRenderer,
@ -143,7 +152,7 @@ private: // not copyable
private: private:
IVtkOCC_ShapePickerAlgo::Handle myOccPickerAlgo; //!< Picking algorithm implementation IVtkOCC_ShapePickerAlgo::Handle myOccPickerAlgo; //!< Picking algorithm implementation
vtkRenderer* myRenderer; //!< VTK renderer vtkSmartPointer<vtkRenderer> myRenderer; //!< VTK renderer
bool myIsRectSelection;//!< Rectangle selection mode flag bool myIsRectSelection;//!< Rectangle selection mode flag
bool myIsPolySelection;//!< Polyline selection mode flag bool myIsPolySelection;//!< Polyline selection mode flag
float myTolerance; //!< Selectoin tolerance float myTolerance; //!< Selectoin tolerance

View File

@ -15,12 +15,12 @@
#include <IVtkTools_SubPolyDataFilter.hxx> #include <IVtkTools_SubPolyDataFilter.hxx>
#include <IVtkVTK_ShapeData.hxx> #include <IVtkVTK_ShapeData.hxx>
#include <vtkCellArray.h> #include <vtkCellData.h>
#include <vtkIdList.h>
#include <vtkIdTypeArray.h>
#include <vtkInformation.h> #include <vtkInformation.h>
#include <vtkInformationVector.h> #include <vtkInformationVector.h>
#include <vtkObjectFactory.h> #include <vtkObjectFactory.h>
#include <vtkCellData.h>
#include <vtkIdTypeArray.h>
vtkStandardNewMacro(IVtkTools_SubPolyDataFilter) vtkStandardNewMacro(IVtkTools_SubPolyDataFilter)
@ -50,27 +50,29 @@ int IVtkTools_SubPolyDataFilter::RequestData (vtkInformation *vtkNotUsed(theRequ
vtkInformationVector *theOutputVector) vtkInformationVector *theOutputVector)
{ {
// get the input and output // get the input and output
vtkInformation *anInInfo = theInputVector[0]->GetInformationObject(0); vtkSmartPointer<vtkInformation> anInInfo = theInputVector[0]->GetInformationObject(0);
vtkInformation *anOutInfo = theOutputVector->GetInformationObject(0); vtkSmartPointer<vtkInformation> anOutInfo = theOutputVector->GetInformationObject(0);
vtkPolyData *anInput = vtkPolyData::SafeDownCast( vtkSmartPointer<vtkPolyData> anInput = vtkPolyData::SafeDownCast(
anInInfo->Get (vtkDataObject::DATA_OBJECT())); anInInfo->Get (vtkDataObject::DATA_OBJECT()));
vtkPolyData *anOutput = vtkPolyData::SafeDownCast( vtkSmartPointer<vtkPolyData> anOutput = vtkPolyData::SafeDownCast(
anOutInfo->Get (vtkDataObject::DATA_OBJECT())); 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(); anInput->Modified();
if (myDoFiltering) if (myDoFiltering)
{ {
vtkCellData* aCellData = anInput->GetCellData(); vtkSmartPointer<vtkCellData> aCellData = anInput->GetCellData();
int aSize = 0; 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(); aSize = aDataArray->GetNumberOfTuples();
anIdList->Allocate (aSize); // Allocate the list of ids 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 anOutput->Allocate(anInput, anIdList->GetNumberOfIds()); // Allocate output cells
// Pass data arrays. // Pass data arrays.
// Create new arrays for output data // Create new arrays for output data
vtkCellData *const anInData = anInput->GetCellData(); vtkSmartPointer<vtkCellData> anInData = anInput->GetCellData();
vtkCellData *const anOutData = anOutput->GetCellData(); vtkSmartPointer<vtkCellData> anOutData = anOutput->GetCellData();
vtkDataArray *anOutArr, *anInArr; vtkSmartPointer<vtkDataArray> anInArr, anOutArr;
for (Standard_Integer anI = 0; anI < anInData->GetNumberOfArrays(); anI++) for (Standard_Integer anI = 0; anI < anInData->GetNumberOfArrays(); anI++)
{ {
anInArr = anInData->GetArray (anI); anInArr = anInData->GetArray (anI);
anOutArr = vtkDataArray::CreateDataArray(anInArr->GetDataType()); anOutArr = vtkSmartPointer<vtkDataArray>::Take(
vtkDataArray::CreateDataArray(anInArr->GetDataType()));
anOutArr->SetName(anInArr->GetName()); anOutArr->SetName(anInArr->GetName());
anOutArr->Allocate(anIdList->GetNumberOfIds() * anInArr->GetNumberOfComponents()); anOutArr->Allocate(anIdList->GetNumberOfIds() * anInArr->GetNumberOfComponents());
anOutArr->SetNumberOfTuples (anIdList->GetNumberOfIds()); anOutArr->SetNumberOfTuples (anIdList->GetNumberOfIds());
@ -119,16 +122,13 @@ int IVtkTools_SubPolyDataFilter::RequestData (vtkInformation *vtkNotUsed(theRequ
for (Standard_Integer anI = 0; anI < anInData->GetNumberOfArrays(); anI++) for (Standard_Integer anI = 0; anI < anInData->GetNumberOfArrays(); anI++)
{ {
anInArr = anInData->GetArray (anI); anInArr = anInData->GetArray (anI);
anOutArr = anOutData->GetArray (anI); anOutArr = anOutData->GetArray(anI);
for (anOutId = 0; anOutId < anIdList->GetNumberOfIds(); anOutId++) for (anOutId = 0; anOutId < anIdList->GetNumberOfIds(); anOutId++)
{ {
anInId = anIdList->GetId (anOutId); anInId = anIdList->GetId (anOutId);
anOutArr->SetTuple (anOutId, anInId, anInArr); anOutArr->SetTuple (anOutId, anInId, anInArr);
} }
} }
anIdList->Delete();
} }
else else
{ {

View File

@ -19,7 +19,6 @@
#include <IVtkTools.hxx> #include <IVtkTools.hxx>
#include "vtkPolyDataAlgorithm.h" #include "vtkPolyDataAlgorithm.h"
#include <IVtk_Types.hxx>
//! @class IVtkTools_SubPolyDataFilter //! @class IVtkTools_SubPolyDataFilter
//! @brief Cells filter according to the given set of cells ids. //! @brief Cells filter according to the given set of cells ids.
@ -57,7 +56,7 @@ protected:
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *); virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
IVtkTools_SubPolyDataFilter(); IVtkTools_SubPolyDataFilter();
~IVtkTools_SubPolyDataFilter(); virtual ~IVtkTools_SubPolyDataFilter();
protected: protected:
//! Set of ids to be passed through this filter. //! Set of ids to be passed through this filter.

View File

@ -14,9 +14,9 @@
// commercial license or contractual agreement. // commercial license or contractual agreement.
#include <IVtkVTK_ShapeData.hxx> #include <IVtkVTK_ShapeData.hxx>
#include <vtkCellArray.h>
#include <vtkCellData.h> #include <vtkCellData.h>
#include <vtkDoubleArray.h> #include <vtkDoubleArray.h>
#include <vtkIdList.h>
#include <vtkIdTypeArray.h> #include <vtkIdTypeArray.h>
#include <vtkPoints.h> #include <vtkPoints.h>
#include <vtkPolyData.h> #include <vtkPolyData.h>
@ -38,7 +38,7 @@ IVtkVTK_ShapeData::IVtkVTK_ShapeData()
{ {
myPolyData = vtkSmartPointer<vtkPolyData>::New(); myPolyData = vtkSmartPointer<vtkPolyData>::New();
myPolyData->Allocate(); myPolyData->Allocate();
myPolyData->SetPoints (vtkPoints::New()); myPolyData->SetPoints (vtkSmartPointer<vtkPoints>::New());
mySubShapeIDs = vtkSmartPointer<vtkIdTypeArray>::New(); mySubShapeIDs = vtkSmartPointer<vtkIdTypeArray>::New();
mySubShapeIDs->SetName (IVtkVTK_ShapeData::ARRNAME_SUBSHAPE_IDS); mySubShapeIDs->SetName (IVtkVTK_ShapeData::ARRNAME_SUBSHAPE_IDS);
@ -112,7 +112,7 @@ void IVtkVTK_ShapeData::InsertLine (const IVtk_IdType theShapeID,
{ {
if (!thePointIds->IsEmpty()) if (!thePointIds->IsEmpty())
{ {
vtkIdList* anIdList = vtkIdList::New(); vtkSmartPointer<vtkIdList> anIdList = vtkSmartPointer<vtkIdList>::New();
// Fill the vtk id list by ids from IVtk_PointIdList. // Fill the vtk id list by ids from IVtk_PointIdList.
IVtk_PointIdList::Iterator anIterOfIds = IVtk_PointIdList::Iterator anIterOfIds =
IVtk_PointIdList::Iterator(*thePointIds); IVtk_PointIdList::Iterator(*thePointIds);
@ -127,7 +127,6 @@ void IVtkVTK_ShapeData::InsertLine (const IVtk_IdType theShapeID,
mySubShapeIDs->InsertNextTupleValue (&aShapeIDVTK); mySubShapeIDs->InsertNextTupleValue (&aShapeIDVTK);
const vtkIdType aType = theMeshType; const vtkIdType aType = theMeshType;
myMeshTypes->InsertNextTupleValue (&aType); myMeshTypes->InsertNextTupleValue (&aType);
anIdList->Delete();
} }
} }

View File

@ -17,11 +17,10 @@
#define __IVTKVTK_SHAPEDATA_H__ #define __IVTKVTK_SHAPEDATA_H__
#include <IVtk_IShapeData.hxx> #include <IVtk_IShapeData.hxx>
#include <vtkType.h> #include <vtkPolyData.h>
#include <vtkSmartPointer.h> #include <vtkSmartPointer.h>
class vtkIdTypeArray; class vtkIdTypeArray;
class vtkPolyData;
class IVtkVTK_ShapeData; class IVtkVTK_ShapeData;
DEFINE_STANDARD_HANDLE( IVtkVTK_ShapeData, IVtk_IShapeData ) DEFINE_STANDARD_HANDLE( IVtkVTK_ShapeData, IVtk_IShapeData )
@ -106,7 +105,7 @@ public: //! @name Specific methods
//! Get VTK PolyData. //! Get VTK PolyData.
//! @return VTK PolyData //! @return VTK PolyData
vtkSmartPointer< vtkPolyData > getVtkPolyData() const vtkPolyData* getVtkPolyData() const
{ return myPolyData; } { return myPolyData; }
private: private:

View File

@ -161,7 +161,8 @@ bool IVtkVTK_View::DisplayToWorld (const gp_XY& theDisplayPnt, gp_XYZ& theWorldP
return false; 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; return true;
} }
@ -188,9 +189,10 @@ void IVtkVTK_View::GetCamera (Graphic3d_Mat4d& theProj,
theIsOrtho = !IsPerspective(); theIsOrtho = !IsPerspective();
vtkMatrix4x4* aCompositeProj = vtkMatrix4x4* aCompositeProj =
myRenderer->GetActiveCamera()->GetCompositeProjectionTransformMatrix (myRenderer->GetTiledAspectRatio(), myRenderer->GetActiveCamera()->
0, GetCompositeProjectionTransformMatrix (myRenderer->GetTiledAspectRatio(),
1); 0,
1);
for (Standard_Integer aRow = 0; aRow < 4; ++aRow) for (Standard_Integer aRow = 0; aRow < 4; ++aRow)
{ {
for (Standard_Integer aCol = 0; aCol < 4; ++aCol) for (Standard_Integer aCol = 0; aCol < 4; ++aCol)

View File

@ -17,6 +17,7 @@
#define __IVTKVTK_VIEW_H__ #define __IVTKVTK_VIEW_H__
#include <IVtk_IView.hxx> #include <IVtk_IView.hxx>
#include <vtkSmartPointer.h>
class vtkRenderer; class vtkRenderer;
@ -92,7 +93,7 @@ public:
DEFINE_STANDARD_RTTIEXT(IVtkVTK_View,IVtk_IView) DEFINE_STANDARD_RTTIEXT(IVtkVTK_View,IVtk_IView)
private: private:
vtkRenderer* myRenderer; vtkSmartPointer<vtkRenderer> myRenderer;
}; };
#endif // __IVTKVTK_VIEW_H__ #endif // __IVTKVTK_VIEW_H__

View File

@ -43,59 +43,6 @@ proc checkarea {shape area_expected tol_abs tol_rel} {
checkreal "area of $shape" $area $area_expected $tol_abs $tol_rel 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 # Check if area of triangles is valid
proc CheckTriArea {shape {eps 0}} { proc CheckTriArea {shape {eps 0}} {
upvar #0 $shape result upvar #0 $shape result

66
tests/v3d/ivtk/bug27567 Normal file
View File

@ -0,0 +1,66 @@
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"
}