Salome HOME
[Bug PAL7444] display mesh takes a lot of more memory in 2.1.0 than in 2.0.0.
authorapo <apo@opencascade.com>
Tue, 22 Mar 2005 10:32:59 +0000 (10:32 +0000)
committerapo <apo@opencascade.com>
Tue, 22 Mar 2005 10:32:59 +0000 (10:32 +0000)
src/OBJECT/SMESH_Actor.cxx
src/OBJECT/SMESH_Actor.h
src/OBJECT/SMESH_ActorDef.h
src/OBJECT/SMESH_DeviceActor.cxx
src/OBJECT/SMESH_DeviceActor.h
src/SMESHGUI/SMESHGUI_ClippingDlg.cxx

index d9e353c181cb00ecd3f7723857699270b409380d..f3794ec5e452b2a9a4d6209efc4c288feeede871 100644 (file)
@@ -68,6 +68,7 @@
 #include <vtkMath.h>
 #include <vtkPlane.h>
 #include <vtkImplicitBoolean.h>
+#include <vtkImplicitFunctionCollection.h>
 
 #include "utilities.h"
 
@@ -242,7 +243,7 @@ SMESH_ActorDef::SMESH_ActorDef(){
   myBaseActor->myGeomFilter->SetInside(true);
 
   myPickableActor = myBaseActor;
-
+  
   myHighlightProp = vtkProperty::New();
   myHighlightProp->SetAmbient(1.0);
   myHighlightProp->SetDiffuse(0.0);
@@ -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();
   myIsCellsLabeled = theIsCellsLabeled && aGrid->GetNumberOfPoints();
   if(myIsCellsLabeled){
@@ -818,18 +820,6 @@ bool SMESH_ActorDef::Init(TVisualObjPtr theVisualObj,
   setName(theName);
 
   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);
 
   myNodeActor->Init(myVisualObj,myImplicitBoolean);
@@ -1063,7 +1053,7 @@ void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation){
       my3DActor->VisibilityOn();
     }
     
-    if(myIsPointsLabeled){
+    if(myIsPointsLabeled){ 
       myPointLabels->VisibilityOn();
       myNodeActor->VisibilityOn();
     }
@@ -1172,7 +1162,7 @@ void SMESH_ActorDef::SetRepresentation(int theMode){
   case ePoint:
     myPickableActor = myNodeActor;
     myNodeActor->SetVisibility(true);
-
+    
     aProp = aBackProp = myNodeProp;
     aReperesent = SMESH_DeviceActor::ePoint;
     break;
@@ -1456,9 +1446,67 @@ int SMESH_ActorDef::GetObjDimension( const int theObjId )
   return myVisualObj->GetElemDimension( theObjId );
 }
 
+bool
+SMESH_ActorDef::
+IsImplicitFunctionUsed() const
+{
+  return myBaseActor->IsImplicitFunctionUsed();
+}
+
+void
+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);
+}
 
-vtkImplicitBoolean* SMESH_ActorDef::GetPlaneContainer(){
-  return myImplicitBoolean;
+vtkIdType
+SMESH_ActorDef::
+GetNumberOfClippingPlanes()
+{
+  return myCippingPlaneCont.size();
+}
+
+vtkPlane* 
+SMESH_ActorDef::
+GetClippingPlane(vtkIdType theID)
+{
+  if(theID >= myCippingPlaneCont.size())
+    return NULL;
+  return myCippingPlaneCont[theID].Get();
 }
 
 
index ad041c275d339ef0fa794d1bcbb336bcfd6bb256..dcb8d11e8b89ad029b78622179011aacad005e43 100644 (file)
@@ -104,7 +104,10 @@ class SMESH_Actor: public SALOME_Actor
   virtual void SetPlaneParam(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;
 
index 943fc5ee542ae5875c90f1f6d7bb3103f2b6b275..ea3f8d02963f86c0f3517e12a551d10002b99dd3 100644 (file)
 #include "SMESH_Actor.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 vtkShrinkFilter;
 class vtkPolyDataMapper;
@@ -153,7 +175,10 @@ class SMESH_ActorDef : public SMESH_Actor{
   virtual void SetPlaneParam(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;}
 
@@ -161,6 +186,9 @@ class SMESH_ActorDef : public SMESH_Actor{
   virtual long GetControlsPrecision() const { return myControlsPrecision; }
 
  protected:
+  void SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed);
+  bool IsImplicitFunctionUsed() const;
+
   TVisualObjPtr myVisualObj;
   vtkTimeStamp* myTimeStamp;
 
@@ -213,7 +241,9 @@ class SMESH_ActorDef : public SMESH_Actor{
   vtkSelectVisiblePoints* myClsSelectVisiblePoints;
 
   vtkImplicitBoolean* myImplicitBoolean;
-
+  typedef TVTKSmartPtr<vtkPlane> TPlanePtr;
+  typedef std::vector<TPlanePtr> TCippingPlaneCont;
+  TCippingPlaneCont myCippingPlaneCont;
   long myControlsPrecision;
 
   SMESH_ActorDef();
index 21bf977b2972ac1b3959137a08b72dd617d5e908..337aba6483d5bceb36398e573d1c371553a48bbc 100644 (file)
 //
 //
 //
-//  File   : SMESH_Actor.cxx
-//  Author : Nicolas REJNERI
+//  File   : SMESH_DeviceActor.cxx
+//  Author : 
 //  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"
@@ -76,7 +76,6 @@ vtkStandardNewMacro(SMESH_DeviceActor);
 
 
 SMESH_DeviceActor::SMESH_DeviceActor(){
-  if(MYDEBUG) MESSAGE("SMESH_DeviceActor");
   myIsShrunk = false;
   myIsShrinkable = false;
   myRepresentation = eSurface;
@@ -93,7 +92,9 @@ SMESH_DeviceActor::SMESH_DeviceActor(){
   myShrinkFilter = vtkShrinkFilter::New();
 
   myExtractGeometry = SMESH_ExtractGeometry::New();
+  myExtractGeometry->SetReleaseDataFlag(true);
   myExtractGeometry->SetStoreMapping(true);
+  myIsImplicitFunctionUsed = false;
 
   myExtractUnstructuredGrid = SALOME_ExtractUnstructuredGrid::New();
   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){
   if(theGrid){
     //myIsShrinkable = theGrid->GetNumberOfCells() > 10;
@@ -172,7 +190,7 @@ void SMESH_DeviceActor::SetUnstructuredGrid(vtkUnstructuredGrid* theGrid){
     myExtractGeometry->SetInput(myMergeFilter->GetOutput());
 
     int anId = 0;
-    myPassFilter[ anId ]->SetInput( myExtractGeometry->GetOutput() );
+    myPassFilter[ anId ]->SetInput( myMergeFilter->GetOutput() );
     myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() );
     
     anId++; // 1
@@ -513,9 +531,9 @@ void SMESH_DeviceActor::UnShrink() {
 }
 
 
-void SMESH_DeviceActor::SetRepresentation(EReperesent theMode){ 
+void SMESH_DeviceActor::SetRepresentation(EReperesent theMode){
   switch(theMode){
-  case ePoint: 
+  case ePoint:
     myGeomFilter->SetInside(true);
     GetProperty()->SetRepresentation(0);
     break;
@@ -524,8 +542,8 @@ void SMESH_DeviceActor::SetRepresentation(EReperesent theMode){
     GetProperty()->SetRepresentation(1);
     break;
   default :
-    GetProperty()->SetRepresentation(theMode);
     myGeomFilter->SetInside(false);
+    GetProperty()->SetRepresentation(theMode);
   }
   myRepresentation = theMode;
   GetProperty()->Modified();
@@ -552,14 +570,18 @@ int SMESH_DeviceActor::GetVisibility(){
 
 
 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);
   if(MYDEBUG) MESSAGE("GetNodeObjId - theVtkID = "<<theVtkID<<"; aRetID = "<<aRetID);
   return aRetID;
 }
 
 float* SMESH_DeviceActor::GetNodeCoord(int theObjID){
-  vtkDataSet* aDataSet = myExtractGeometry->GetInput();
+  vtkDataSet* aDataSet = myMergeFilter->GetOutput();
   vtkIdType anID = myVisualObj->GetNodeVTKId(theObjID);
   float* aCoord = aDataSet->GetPoint(anID);
   if(MYDEBUG) MESSAGE("GetNodeCoord - theObjID = "<<theObjID<<"; anID = "<<anID);
@@ -571,12 +593,17 @@ int SMESH_DeviceActor::GetElemObjId(int theVtkID){
   vtkIdType anId = myGeomFilter->GetElemObjId(theVtkID);
   if(anId < 0) 
     return -1;
-  vtkIdType anId2 = myExtractGeometry->GetElemObjId(anId);
+
+  vtkIdType anId2 = anId;
+  if(IsImplicitFunctionUsed())
+    anId2 = myExtractGeometry->GetElemObjId(anId);
   if(anId2 < 0) 
     return -1;
+
   vtkIdType anId3 = myExtractUnstructuredGrid->GetInputId(anId2);
   if(anId3 < 0) 
     return -1;
+
   vtkIdType aRetID = myVisualObj->GetElemObjId(anId3);
   if(MYDEBUG) 
      MESSAGE("GetElemObjId - theVtkID = "<<theVtkID<<"; anId2 = "<<anId2<<"; anId3 = "<<anId3<<"; aRetID = "<<aRetID);
index 90cd7894355db897a2153ce9d93d5b754c88e36f..897a2e585b826f582ded70e424b3b1c8bf1deffc 100644 (file)
@@ -106,6 +106,9 @@ class SMESH_DeviceActor: public vtkLODActor{
 
   virtual void Render(vtkRenderer *, vtkMapper *);
 
+  void SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed);
+  bool IsImplicitFunctionUsed() const{ return myIsImplicitFunctionUsed;}
+
  protected:
   void Init(TVisualObjPtr theVisualObj, vtkImplicitBoolean* theImplicitBoolean);
   void SetUnstructuredGrid(vtkUnstructuredGrid* theGrid);
@@ -117,6 +120,7 @@ class SMESH_DeviceActor: public vtkLODActor{
   EReperesent myRepresentation;
 
   SMESH_ExtractGeometry* myExtractGeometry;
+  bool myIsImplicitFunctionUsed;
 
   vtkMergeFilter* myMergeFilter;
   SALOME_ExtractUnstructuredGrid* myExtractUnstructuredGrid;
index 567d567f347acadad7fd1f2d3264df1b49d81106..2190ea2d545a1b4a6942f3ad93b581efb9cf10d1 100644 (file)
@@ -383,10 +383,6 @@ SMESHGUI_ClippingDlg::~SMESHGUI_ClippingDlg()
 }
 
 
-//=======================================================================
-// function : ClickOnApply()
-// purpose  :
-//=======================================================================
 void SMESHGUI_ClippingDlg::ClickOnApply()
 {
   if (!myActor)
@@ -395,17 +391,13 @@ void SMESHGUI_ClippingDlg::ClickOnApply()
   if ( SMESHGUI::GetSMESHGUI()->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
     QAD_WaitCursor wc;
     
-    vtkImplicitBoolean* aBoolean = myActor->GetPlaneContainer();
-    vtkImplicitFunctionCollection* aCollection = aBoolean->GetFunction();
-    aCollection->RemoveAllItems();
-    aBoolean->Modified(); // VTK bug
-    aCollection->InitTraversal();
-    
+    myActor->RemoveAllClippingPlanes();
+
     SMESH::TPlanes::iterator anIter = myPlanes.begin();
     for (;anIter != myPlanes.end();anIter++){
       OrientedPlane* anOrientedPlane = OrientedPlane::New();
       anOrientedPlane->ShallowCopy(anIter->GetPointer());
-      aCollection->AddItem(anOrientedPlane);
+      myActor->AddClippingPlane(anOrientedPlane);
       anOrientedPlane->Delete();
     }
 
@@ -446,20 +438,22 @@ void SMESHGUI_ClippingDlg::onSelectionChanged()
       Handle(SALOME_InteractiveObject) IOS = mySelection->firstIObject();
       myActor = SMESH::FindActorByEntry(IOS->getEntry());
       if ( myActor ){
-       vtkImplicitBoolean* aBoolean = myActor->GetPlaneContainer();
-       vtkImplicitFunctionCollection* aCollection = aBoolean->GetFunction();
-       aCollection->InitTraversal();
        std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(false));
        myPlanes.clear();
-       while(vtkImplicitFunction* aFunction = aCollection->GetNextItem()){
-         if(OrientedPlane* aPlane = OrientedPlane::SafeDownCast(aFunction)){
-           OrientedPlane* anOrientedPlane = OrientedPlane::New(SMESH::GetActiveStudy());
-           SMESH::TVTKPlane aTVTKPlane(anOrientedPlane);
-           anOrientedPlane->Delete();
-           aTVTKPlane->ShallowCopy(aPlane);
-           myPlanes.push_back(aTVTKPlane);
+
+       vtkIdType anId = 0, anEnd = myActor->GetNumberOfClippingPlanes();
+       for(; anId < anEnd; anId++){
+         if(vtkImplicitFunction* aFunction = myActor->GetClippingPlane(anId)){
+           if(OrientedPlane* aPlane = OrientedPlane::SafeDownCast(aFunction)){
+             OrientedPlane* anOrientedPlane = OrientedPlane::New(SMESH::GetActiveStudy());
+             SMESH::TVTKPlane aTVTKPlane(anOrientedPlane);
+             anOrientedPlane->Delete();
+             aTVTKPlane->ShallowCopy(aPlane);
+             myPlanes.push_back(aTVTKPlane);
+           }
          }
        }
+
        std::for_each(myPlanes.begin(),myPlanes.end(),
                      TSetVisiblity(PreviewCheckBox->isChecked()));
       }
@@ -634,7 +628,9 @@ void SMESHGUI_ClippingDlg::setRotation( const double theRot1, const double theRo
 // function : SetCurrentPlaneParam
 // purpose  :
 //=======================================================================
-void SMESHGUI_ClippingDlg::SetCurrentPlaneParam()
+void
+SMESHGUI_ClippingDlg::
+SetCurrentPlaneParam()
 {
   if(myPlanes.empty() || myIsSelectPlane)
     return;