[Bug PAL7444] display mesh takes a lot of more memory in 2.1.0 than in 2.0.0.

This commit is contained in:
apo 2005-03-22 10:32:59 +00:00
parent 7411bcf53c
commit 1eea5485d1
6 changed files with 162 additions and 54 deletions

View File

@ -68,6 +68,7 @@
#include <vtkMath.h> #include <vtkMath.h>
#include <vtkPlane.h> #include <vtkPlane.h>
#include <vtkImplicitBoolean.h> #include <vtkImplicitBoolean.h>
#include <vtkImplicitFunctionCollection.h>
#include "utilities.h" #include "utilities.h"
@ -599,7 +600,8 @@ void SMESH_ActorDef::SetPointsLabeled( bool theIsPointsLabeled )
} }
void SMESH_ActorDef::SetCellsLabeled(bool theIsCellsLabeled){ void SMESH_ActorDef::SetCellsLabeled(bool theIsCellsLabeled)
{
vtkUnstructuredGrid* aGrid = GetUnstructuredGrid(); vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
myIsCellsLabeled = theIsCellsLabeled && aGrid->GetNumberOfPoints(); myIsCellsLabeled = theIsCellsLabeled && aGrid->GetNumberOfPoints();
if(myIsCellsLabeled){ if(myIsCellsLabeled){
@ -818,18 +820,6 @@ bool SMESH_ActorDef::Init(TVisualObjPtr theVisualObj,
setName(theName); setName(theName);
myVisualObj = theVisualObj; myVisualObj = theVisualObj;
myNodeActor->myVisualObj = myVisualObj;
myBaseActor->myVisualObj = myVisualObj;
myHighlitableActor->myVisualObj = myVisualObj;
myNodeHighlitableActor->myVisualObj = myVisualObj;
my1DActor->myVisualObj = myVisualObj;
my1DExtActor->myVisualObj = myVisualObj;
my2DActor->myVisualObj = myVisualObj;
my3DActor->myVisualObj = myVisualObj;
myVisualObj->Update(theIsClear); myVisualObj->Update(theIsClear);
myNodeActor->Init(myVisualObj,myImplicitBoolean); myNodeActor->Init(myVisualObj,myImplicitBoolean);
@ -1456,9 +1446,67 @@ int SMESH_ActorDef::GetObjDimension( const int theObjId )
return myVisualObj->GetElemDimension( theObjId ); return myVisualObj->GetElemDimension( theObjId );
} }
bool
SMESH_ActorDef::
IsImplicitFunctionUsed() const
{
return myBaseActor->IsImplicitFunctionUsed();
}
vtkImplicitBoolean* SMESH_ActorDef::GetPlaneContainer(){ void
return myImplicitBoolean; SMESH_ActorDef::
SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
{
myNodeActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
myBaseActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
myHighlitableActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
myNodeHighlitableActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
my1DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
my1DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
my2DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
my3DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
}
vtkIdType
SMESH_ActorDef::
AddClippingPlane(vtkPlane* thePlane)
{
if(thePlane){
myImplicitBoolean->GetFunction()->AddItem(thePlane);
myCippingPlaneCont.push_back(thePlane);
if(!IsImplicitFunctionUsed())
SetImplicitFunctionUsed(true);
}
return myCippingPlaneCont.size();
}
void
SMESH_ActorDef::
RemoveAllClippingPlanes()
{
myImplicitBoolean->GetFunction()->RemoveAllItems();
myImplicitBoolean->GetFunction()->Modified(); // VTK bug
myCippingPlaneCont.clear();
SetImplicitFunctionUsed(false);
}
vtkIdType
SMESH_ActorDef::
GetNumberOfClippingPlanes()
{
return myCippingPlaneCont.size();
}
vtkPlane*
SMESH_ActorDef::
GetClippingPlane(vtkIdType theID)
{
if(theID >= myCippingPlaneCont.size())
return NULL;
return myCippingPlaneCont[theID].Get();
} }

View File

@ -104,7 +104,10 @@ class SMESH_Actor: public SALOME_Actor
virtual void SetPlaneParam(float theDir[3], float theDist, vtkPlane* thePlane) = 0; virtual void SetPlaneParam(float theDir[3], float theDist, vtkPlane* thePlane) = 0;
virtual void GetPlaneParam(float theDir[3], float& theDist, vtkPlane* thePlane) = 0; virtual void GetPlaneParam(float theDir[3], float& theDist, vtkPlane* thePlane) = 0;
virtual vtkImplicitBoolean* GetPlaneContainer() = 0; virtual void RemoveAllClippingPlanes() = 0;
virtual vtkIdType GetNumberOfClippingPlanes() = 0;
virtual vtkPlane* GetClippingPlane(vtkIdType theID) = 0;
virtual vtkIdType AddClippingPlane(vtkPlane* thePlane) = 0;
virtual TVisualObjPtr GetObject() = 0; virtual TVisualObjPtr GetObject() = 0;

View File

@ -32,6 +32,28 @@
#include "SMESH_Actor.h" #include "SMESH_Actor.h"
#include "SMESH_Object.h" #include "SMESH_Object.h"
#include <vtkSmartPointer.h>
template <class T>
class TVTKSmartPtr: public vtkSmartPointer<T>
{
public:
TVTKSmartPtr() {}
TVTKSmartPtr(T* r, bool theIsOwner = false): vtkSmartPointer<T>(r) {
if(r && theIsOwner)
r->Delete();
}
TVTKSmartPtr& operator()(T* r, bool theIsOwner = false){
vtkSmartPointer<T>::operator=(r);
if(r && theIsOwner)
r->Delete();
return *this;
}
TVTKSmartPtr& operator=(T* r){ vtkSmartPointer<T>::operator=(r); return *this;}
T* Get() const { return GetPointer();}
};
class vtkProperty; class vtkProperty;
class vtkShrinkFilter; class vtkShrinkFilter;
class vtkPolyDataMapper; class vtkPolyDataMapper;
@ -153,7 +175,10 @@ class SMESH_ActorDef : public SMESH_Actor{
virtual void SetPlaneParam(float theDir[3], float theDist, vtkPlane* thePlane); virtual void SetPlaneParam(float theDir[3], float theDist, vtkPlane* thePlane);
virtual void GetPlaneParam(float theDir[3], float& theDist, vtkPlane* thePlane); virtual void GetPlaneParam(float theDir[3], float& theDist, vtkPlane* thePlane);
virtual vtkImplicitBoolean* GetPlaneContainer(); virtual void RemoveAllClippingPlanes();
virtual vtkIdType GetNumberOfClippingPlanes();
virtual vtkPlane* GetClippingPlane(vtkIdType theID);
virtual vtkIdType AddClippingPlane(vtkPlane* thePlane);
virtual TVisualObjPtr GetObject() { return myVisualObj;} virtual TVisualObjPtr GetObject() { return myVisualObj;}
@ -161,6 +186,9 @@ class SMESH_ActorDef : public SMESH_Actor{
virtual long GetControlsPrecision() const { return myControlsPrecision; } virtual long GetControlsPrecision() const { return myControlsPrecision; }
protected: protected:
void SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed);
bool IsImplicitFunctionUsed() const;
TVisualObjPtr myVisualObj; TVisualObjPtr myVisualObj;
vtkTimeStamp* myTimeStamp; vtkTimeStamp* myTimeStamp;
@ -213,7 +241,9 @@ class SMESH_ActorDef : public SMESH_Actor{
vtkSelectVisiblePoints* myClsSelectVisiblePoints; vtkSelectVisiblePoints* myClsSelectVisiblePoints;
vtkImplicitBoolean* myImplicitBoolean; vtkImplicitBoolean* myImplicitBoolean;
typedef TVTKSmartPtr<vtkPlane> TPlanePtr;
typedef std::vector<TPlanePtr> TCippingPlaneCont;
TCippingPlaneCont myCippingPlaneCont;
long myControlsPrecision; long myControlsPrecision;
SMESH_ActorDef(); SMESH_ActorDef();

View File

@ -21,10 +21,10 @@
// //
// //
// //
// File : SMESH_Actor.cxx // File : SMESH_DeviceActor.cxx
// Author : Nicolas REJNERI // Author :
// Module : SMESH // Module : SMESH
// $Header$Header: /home/server/cvs/SMESH/SMESH_SRC/src/OBJECT/SMESH_DeviceActor.cxx,v 1.7 2005/02/02 12:17:51 apo Exp $ // $Header$
#include "SMESH_DeviceActor.h" #include "SMESH_DeviceActor.h"
@ -76,7 +76,6 @@ vtkStandardNewMacro(SMESH_DeviceActor);
SMESH_DeviceActor::SMESH_DeviceActor(){ SMESH_DeviceActor::SMESH_DeviceActor(){
if(MYDEBUG) MESSAGE("SMESH_DeviceActor");
myIsShrunk = false; myIsShrunk = false;
myIsShrinkable = false; myIsShrinkable = false;
myRepresentation = eSurface; myRepresentation = eSurface;
@ -93,7 +92,9 @@ SMESH_DeviceActor::SMESH_DeviceActor(){
myShrinkFilter = vtkShrinkFilter::New(); myShrinkFilter = vtkShrinkFilter::New();
myExtractGeometry = SMESH_ExtractGeometry::New(); myExtractGeometry = SMESH_ExtractGeometry::New();
myExtractGeometry->SetReleaseDataFlag(true);
myExtractGeometry->SetStoreMapping(true); myExtractGeometry->SetStoreMapping(true);
myIsImplicitFunctionUsed = false;
myExtractUnstructuredGrid = SALOME_ExtractUnstructuredGrid::New(); myExtractUnstructuredGrid = SALOME_ExtractUnstructuredGrid::New();
myExtractUnstructuredGrid->SetStoreMapping(true); myExtractUnstructuredGrid->SetStoreMapping(true);
@ -160,6 +161,23 @@ void SMESH_DeviceActor::Init(TVisualObjPtr theVisualObj,
} }
void
SMESH_DeviceActor::
SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
{
if(myIsImplicitFunctionUsed == theIsImplicitFunctionUsed)
return;
int anId = 0;
if(theIsImplicitFunctionUsed)
myPassFilter[ anId ]->SetInput( myExtractGeometry->GetOutput() );
else
myPassFilter[ anId ]->SetInput( myMergeFilter->GetOutput() );
myIsImplicitFunctionUsed = theIsImplicitFunctionUsed;
}
void SMESH_DeviceActor::SetUnstructuredGrid(vtkUnstructuredGrid* theGrid){ void SMESH_DeviceActor::SetUnstructuredGrid(vtkUnstructuredGrid* theGrid){
if(theGrid){ if(theGrid){
//myIsShrinkable = theGrid->GetNumberOfCells() > 10; //myIsShrinkable = theGrid->GetNumberOfCells() > 10;
@ -172,7 +190,7 @@ void SMESH_DeviceActor::SetUnstructuredGrid(vtkUnstructuredGrid* theGrid){
myExtractGeometry->SetInput(myMergeFilter->GetOutput()); myExtractGeometry->SetInput(myMergeFilter->GetOutput());
int anId = 0; int anId = 0;
myPassFilter[ anId ]->SetInput( myExtractGeometry->GetOutput() ); myPassFilter[ anId ]->SetInput( myMergeFilter->GetOutput() );
myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() ); myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() );
anId++; // 1 anId++; // 1
@ -524,8 +542,8 @@ void SMESH_DeviceActor::SetRepresentation(EReperesent theMode){
GetProperty()->SetRepresentation(1); GetProperty()->SetRepresentation(1);
break; break;
default : default :
GetProperty()->SetRepresentation(theMode);
myGeomFilter->SetInside(false); myGeomFilter->SetInside(false);
GetProperty()->SetRepresentation(theMode);
} }
myRepresentation = theMode; myRepresentation = theMode;
GetProperty()->Modified(); GetProperty()->Modified();
@ -552,14 +570,18 @@ int SMESH_DeviceActor::GetVisibility(){
int SMESH_DeviceActor::GetNodeObjId(int theVtkID){ int SMESH_DeviceActor::GetNodeObjId(int theVtkID){
vtkIdType anID = myExtractGeometry->GetNodeObjId(theVtkID); vtkIdType anID = theVtkID;
if(IsImplicitFunctionUsed())
anID = myExtractGeometry->GetNodeObjId(theVtkID);
vtkIdType aRetID = myVisualObj->GetNodeObjId(anID); vtkIdType aRetID = myVisualObj->GetNodeObjId(anID);
if(MYDEBUG) MESSAGE("GetNodeObjId - theVtkID = "<<theVtkID<<"; aRetID = "<<aRetID); if(MYDEBUG) MESSAGE("GetNodeObjId - theVtkID = "<<theVtkID<<"; aRetID = "<<aRetID);
return aRetID; return aRetID;
} }
float* SMESH_DeviceActor::GetNodeCoord(int theObjID){ float* SMESH_DeviceActor::GetNodeCoord(int theObjID){
vtkDataSet* aDataSet = myExtractGeometry->GetInput(); vtkDataSet* aDataSet = myMergeFilter->GetOutput();
vtkIdType anID = myVisualObj->GetNodeVTKId(theObjID); vtkIdType anID = myVisualObj->GetNodeVTKId(theObjID);
float* aCoord = aDataSet->GetPoint(anID); float* aCoord = aDataSet->GetPoint(anID);
if(MYDEBUG) MESSAGE("GetNodeCoord - theObjID = "<<theObjID<<"; anID = "<<anID); if(MYDEBUG) MESSAGE("GetNodeCoord - theObjID = "<<theObjID<<"; anID = "<<anID);
@ -571,12 +593,17 @@ int SMESH_DeviceActor::GetElemObjId(int theVtkID){
vtkIdType anId = myGeomFilter->GetElemObjId(theVtkID); vtkIdType anId = myGeomFilter->GetElemObjId(theVtkID);
if(anId < 0) if(anId < 0)
return -1; return -1;
vtkIdType anId2 = myExtractGeometry->GetElemObjId(anId);
vtkIdType anId2 = anId;
if(IsImplicitFunctionUsed())
anId2 = myExtractGeometry->GetElemObjId(anId);
if(anId2 < 0) if(anId2 < 0)
return -1; return -1;
vtkIdType anId3 = myExtractUnstructuredGrid->GetInputId(anId2); vtkIdType anId3 = myExtractUnstructuredGrid->GetInputId(anId2);
if(anId3 < 0) if(anId3 < 0)
return -1; return -1;
vtkIdType aRetID = myVisualObj->GetElemObjId(anId3); vtkIdType aRetID = myVisualObj->GetElemObjId(anId3);
if(MYDEBUG) if(MYDEBUG)
MESSAGE("GetElemObjId - theVtkID = "<<theVtkID<<"; anId2 = "<<anId2<<"; anId3 = "<<anId3<<"; aRetID = "<<aRetID); MESSAGE("GetElemObjId - theVtkID = "<<theVtkID<<"; anId2 = "<<anId2<<"; anId3 = "<<anId3<<"; aRetID = "<<aRetID);

View File

@ -106,6 +106,9 @@ class SMESH_DeviceActor: public vtkLODActor{
virtual void Render(vtkRenderer *, vtkMapper *); virtual void Render(vtkRenderer *, vtkMapper *);
void SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed);
bool IsImplicitFunctionUsed() const{ return myIsImplicitFunctionUsed;}
protected: protected:
void Init(TVisualObjPtr theVisualObj, vtkImplicitBoolean* theImplicitBoolean); void Init(TVisualObjPtr theVisualObj, vtkImplicitBoolean* theImplicitBoolean);
void SetUnstructuredGrid(vtkUnstructuredGrid* theGrid); void SetUnstructuredGrid(vtkUnstructuredGrid* theGrid);
@ -117,6 +120,7 @@ class SMESH_DeviceActor: public vtkLODActor{
EReperesent myRepresentation; EReperesent myRepresentation;
SMESH_ExtractGeometry* myExtractGeometry; SMESH_ExtractGeometry* myExtractGeometry;
bool myIsImplicitFunctionUsed;
vtkMergeFilter* myMergeFilter; vtkMergeFilter* myMergeFilter;
SALOME_ExtractUnstructuredGrid* myExtractUnstructuredGrid; SALOME_ExtractUnstructuredGrid* myExtractUnstructuredGrid;

View File

@ -383,10 +383,6 @@ SMESHGUI_ClippingDlg::~SMESHGUI_ClippingDlg()
} }
//=======================================================================
// function : ClickOnApply()
// purpose :
//=======================================================================
void SMESHGUI_ClippingDlg::ClickOnApply() void SMESHGUI_ClippingDlg::ClickOnApply()
{ {
if (!myActor) if (!myActor)
@ -395,17 +391,13 @@ void SMESHGUI_ClippingDlg::ClickOnApply()
if ( SMESHGUI::GetSMESHGUI()->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { if ( SMESHGUI::GetSMESHGUI()->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
QAD_WaitCursor wc; QAD_WaitCursor wc;
vtkImplicitBoolean* aBoolean = myActor->GetPlaneContainer(); myActor->RemoveAllClippingPlanes();
vtkImplicitFunctionCollection* aCollection = aBoolean->GetFunction();
aCollection->RemoveAllItems();
aBoolean->Modified(); // VTK bug
aCollection->InitTraversal();
SMESH::TPlanes::iterator anIter = myPlanes.begin(); SMESH::TPlanes::iterator anIter = myPlanes.begin();
for (;anIter != myPlanes.end();anIter++){ for (;anIter != myPlanes.end();anIter++){
OrientedPlane* anOrientedPlane = OrientedPlane::New(); OrientedPlane* anOrientedPlane = OrientedPlane::New();
anOrientedPlane->ShallowCopy(anIter->GetPointer()); anOrientedPlane->ShallowCopy(anIter->GetPointer());
aCollection->AddItem(anOrientedPlane); myActor->AddClippingPlane(anOrientedPlane);
anOrientedPlane->Delete(); anOrientedPlane->Delete();
} }
@ -446,20 +438,22 @@ void SMESHGUI_ClippingDlg::onSelectionChanged()
Handle(SALOME_InteractiveObject) IOS = mySelection->firstIObject(); Handle(SALOME_InteractiveObject) IOS = mySelection->firstIObject();
myActor = SMESH::FindActorByEntry(IOS->getEntry()); myActor = SMESH::FindActorByEntry(IOS->getEntry());
if ( myActor ){ if ( myActor ){
vtkImplicitBoolean* aBoolean = myActor->GetPlaneContainer();
vtkImplicitFunctionCollection* aCollection = aBoolean->GetFunction();
aCollection->InitTraversal();
std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(false)); std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(false));
myPlanes.clear(); myPlanes.clear();
while(vtkImplicitFunction* aFunction = aCollection->GetNextItem()){
if(OrientedPlane* aPlane = OrientedPlane::SafeDownCast(aFunction)){ vtkIdType anId = 0, anEnd = myActor->GetNumberOfClippingPlanes();
OrientedPlane* anOrientedPlane = OrientedPlane::New(SMESH::GetActiveStudy()); for(; anId < anEnd; anId++){
SMESH::TVTKPlane aTVTKPlane(anOrientedPlane); if(vtkImplicitFunction* aFunction = myActor->GetClippingPlane(anId)){
anOrientedPlane->Delete(); if(OrientedPlane* aPlane = OrientedPlane::SafeDownCast(aFunction)){
aTVTKPlane->ShallowCopy(aPlane); OrientedPlane* anOrientedPlane = OrientedPlane::New(SMESH::GetActiveStudy());
myPlanes.push_back(aTVTKPlane); SMESH::TVTKPlane aTVTKPlane(anOrientedPlane);
anOrientedPlane->Delete();
aTVTKPlane->ShallowCopy(aPlane);
myPlanes.push_back(aTVTKPlane);
}
} }
} }
std::for_each(myPlanes.begin(),myPlanes.end(), std::for_each(myPlanes.begin(),myPlanes.end(),
TSetVisiblity(PreviewCheckBox->isChecked())); TSetVisiblity(PreviewCheckBox->isChecked()));
} }
@ -634,7 +628,9 @@ void SMESHGUI_ClippingDlg::setRotation( const double theRot1, const double theRo
// function : SetCurrentPlaneParam // function : SetCurrentPlaneParam
// purpose : // purpose :
//======================================================================= //=======================================================================
void SMESHGUI_ClippingDlg::SetCurrentPlaneParam() void
SMESHGUI_ClippingDlg::
SetCurrentPlaneParam()
{ {
if(myPlanes.empty() || myIsSelectPlane) if(myPlanes.empty() || myIsSelectPlane)
return; return;