Salome HOME
[Bug PAL7444] display mesh takes a lot of more memory in 2.1.0 than in 2.0.0.
[modules/smesh.git] / src / OBJECT / SMESH_DeviceActor.cxx
index 16ead487f9ab8927d92b2ab06f8760ff1018caf6..337aba6483d5bceb36398e573d1c371553a48bbc 100644 (file)
 //
 //
 //
-//  File   : SMESH_Actor.cxx
-//  Author : Nicolas REJNERI
+//  File   : SMESH_DeviceActor.cxx
+//  Author : 
 //  Module : SMESH
-//  $Header$Header$
+//  $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);
@@ -143,7 +144,10 @@ SMESH_DeviceActor::~SMESH_DeviceActor(){
 
 
 void SMESH_DeviceActor::SetStoreMapping(int theStoreMapping){
+  if (myStoreMapping == theStoreMapping)
+    return;
   myStoreMapping = theStoreMapping;
+  myGeomFilter->SetStoreMapping( myStoreMapping );
   Modified();
 }
 
@@ -157,20 +161,36 @@ 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;
     myIsShrinkable = true;
 
-    myExtractGeometry->SetInput(theGrid);
+    myExtractUnstructuredGrid->SetInput(theGrid);
 
-    myExtractUnstructuredGrid->SetInput(myExtractGeometry->GetOutput());
     myMergeFilter->SetGeometry(myExtractUnstructuredGrid->GetOutput());
-    
-    theGrid = static_cast<vtkUnstructuredGrid*>(myMergeFilter->GetOutput());
+
+    myExtractGeometry->SetInput(myMergeFilter->GetOutput());
 
     int anId = 0;
-    myPassFilter[ anId ]->SetInput( theGrid );
+    myPassFilter[ anId ]->SetInput( myMergeFilter->GetOutput() );
     myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() );
     
     anId++; // 1
@@ -233,16 +253,14 @@ void SMESH_DeviceActor::SetControlMode(SMESH::Controls::FunctorPtr theFunctor,
     if(NumericalFunctor* aNumericalFunctor = dynamic_cast<NumericalFunctor*>(theFunctor.get())){
       for(vtkIdType i = 0; i < aNbCells; i++){
        vtkIdType anId = myExtractUnstructuredGrid->GetInputId(i);
-       vtkIdType anId2 = myExtractGeometry->GetElemObjId(anId);
-       vtkIdType anObjId = myVisualObj->GetElemObjId(anId2);
+       vtkIdType anObjId = myVisualObj->GetElemObjId(anId);
        double aValue = aNumericalFunctor->GetValue(anObjId);
        aScalars->SetValue(i,aValue);
       }
     }else if(Predicate* aPredicate = dynamic_cast<Predicate*>(theFunctor.get())){
       for(vtkIdType i = 0; i < aNbCells; i++){
        vtkIdType anId = myExtractUnstructuredGrid->GetInputId(i);
-       vtkIdType anId2 = myExtractGeometry->GetElemObjId(anId);
-       vtkIdType anObjId = myVisualObj->GetElemObjId(anId2);
+       vtkIdType anObjId = myVisualObj->GetElemObjId(anId);
        bool aValue = aPredicate->IsSatisfy(anObjId);
        aScalars->SetValue(i,aValue);
       }
@@ -267,14 +285,16 @@ void SMESH_DeviceActor::SetExtControlMode(SMESH::Controls::FunctorPtr theFunctor
                                          vtkLookupTable* theLookupTable)
 {
   bool anIsInitialized = theFunctor;
+  myExtractUnstructuredGrid->ClearRegisteredCells();
+  myExtractUnstructuredGrid->ClearRegisteredCellsWithType();
+  myExtractUnstructuredGrid->SetModeOfChanging(SALOME_ExtractUnstructuredGrid::ePassAll);
+  myVisualObj->UpdateFunctor(theFunctor);
 
   using namespace SMESH::Controls;
   if (anIsInitialized){
     if (Length2D* aLength2D = dynamic_cast<Length2D*>(theFunctor.get())){
       SMESH::Controls::Length2D::TValues aValues;
 
-      myVisualObj->UpdateFunctor(theFunctor);
-
       aLength2D->GetValues(aValues);
       vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New();
       vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
@@ -337,8 +357,6 @@ void SMESH_DeviceActor::SetExtControlMode(SMESH::Controls::FunctorPtr theFunctor
     else if (MultiConnection2D* aMultiConnection2D = dynamic_cast<MultiConnection2D*>(theFunctor.get())){
       SMESH::Controls::MultiConnection2D::MValues aValues;
 
-      myVisualObj->UpdateFunctor(theFunctor);
-
       aMultiConnection2D->GetValues(aValues);
       vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New();
       vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
@@ -361,8 +379,7 @@ void SMESH_DeviceActor::SetExtControlMode(SMESH::Controls::FunctorPtr theFunctor
       anIdList->SetNumberOfIds(2);
       
       MultiConnection2D::MValues::const_iterator anIter = aValues.begin();
-      int i = 0;
-      for(vtkIdType aVtkId; anIter != aValues.end(); anIter++,i++){
+      for(vtkIdType aVtkId = 0; anIter != aValues.end(); anIter++,aVtkId++){
        const MultiConnection2D::Value& aValue = (*anIter).first;
        int aNode[2] = {
          myVisualObj->GetNodeVTKId(aValue.myPntId[0]),
@@ -373,7 +390,7 @@ void SMESH_DeviceActor::SetExtControlMode(SMESH::Controls::FunctorPtr theFunctor
          anIdList->SetId( 1, aNode[1] );
          aConnectivity->InsertNextCell( anIdList );
          aCellTypesArray->InsertNextValue( VTK_LINE );
-         aScalars->SetValue(i,(*anIter).second);
+         aScalars->SetValue(aVtkId,(*anIter).second);
        }
       }
       
@@ -413,11 +430,10 @@ void SMESH_DeviceActor::SetExtControlMode(SMESH::Controls::FunctorPtr theFunctor
   using namespace SMESH::Controls;
   if(FreeBorders* aFreeBorders = dynamic_cast<FreeBorders*>(theFunctor.get())){
     myExtractUnstructuredGrid->SetModeOfChanging(SALOME_ExtractUnstructuredGrid::eAdding);
-    myExtractUnstructuredGrid->ClearRegisteredCells();
-    vtkUnstructuredGrid* aGrid = theDeviceActor->GetUnstructuredGrid();
+    vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
     vtkIdType aNbCells = aGrid->GetNumberOfCells();
     for( vtkIdType i = 0; i < aNbCells; i++ ){
-      vtkIdType anObjId = theDeviceActor->GetElemObjId(i);
+      vtkIdType anObjId = myVisualObj->GetElemObjId(i);
       if(aFreeBorders->IsSatisfy(anObjId))
        myExtractUnstructuredGrid->RegisterCell(i);
     }
@@ -515,19 +531,19 @@ 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;
-  case eInsideframe: 
+  case eInsideframe:
     myGeomFilter->SetInside(true);
     GetProperty()->SetRepresentation(1);
     break;
   default :
-    GetProperty()->SetRepresentation(theMode);
     myGeomFilter->SetInside(false);
+    GetProperty()->SetRepresentation(theMode);
   }
   myRepresentation = theMode;
   GetProperty()->Modified();
@@ -554,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);
@@ -573,20 +593,25 @@ int SMESH_DeviceActor::GetElemObjId(int theVtkID){
   vtkIdType anId = myGeomFilter->GetElemObjId(theVtkID);
   if(anId < 0) 
     return -1;
-  vtkIdType anId2 = myExtractUnstructuredGrid->GetInputId(anId);
+
+  vtkIdType anId2 = anId;
+  if(IsImplicitFunctionUsed())
+    anId2 = myExtractGeometry->GetElemObjId(anId);
   if(anId2 < 0) 
     return -1;
-  vtkIdType anId3 = myExtractGeometry->GetElemObjId(anId2);
+
+  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);
+     MESSAGE("GetElemObjId - theVtkID = "<<theVtkID<<"; anId2 = "<<anId2<<"; anId3 = "<<anId3<<"; aRetID = "<<aRetID);
   return aRetID;
 }
 
 vtkCell* SMESH_DeviceActor::GetElemCell(int theObjID){
-  vtkDataSet* aDataSet = myExtractGeometry->GetInput();
+  vtkDataSet* aDataSet = myVisualObj->GetUnstructuredGrid();
   vtkIdType aGridID = myVisualObj->GetElemVTKId(theObjID);
   vtkCell* aCell = aDataSet->GetCell(aGridID);
   if(MYDEBUG)