Salome HOME
Merge with OCC_development_01
[modules/smesh.git] / src / OBJECT / SMESH_DeviceActor.cxx
index 79d20d81305011bed2749e846300d01dc4f6029a..16ead487f9ab8927d92b2ab06f8760ff1018caf6 100644 (file)
 //  File   : SMESH_Actor.cxx
 //  Author : Nicolas REJNERI
 //  Module : SMESH
-//  $Header$
+//  $Header$Header$
 
 
 #include "SMESH_DeviceActor.h"
 #include "SMESH_ExtractGeometry.h"
+#include "SMESH_ControlsDef.hxx"
+#include "SMESH_ActorUtils.h"
 
 #include "SALOME_Transform.h"
 #include "SALOME_TransformFilter.h"
 #include "SALOME_PassThroughFilter.h"
 #include "SALOME_ExtractUnstructuredGrid.h"
 
-#include "utilities.h"
-
 // VTK Includes
 #include <vtkObjectFactory.h>
 #include <vtkShrinkFilter.h>
 
 #include <vtkImplicitBoolean.h>
 
+#include "utilities.h"
+
 #ifdef _DEBUG_
 static int MYDEBUG = 0;
-static int MYDEBUGWITHFILES = 0;
 #else
 static int MYDEBUG = 0;
-static int MYDEBUGWITHFILES = 0;
 #endif
 
 using namespace std;
@@ -166,7 +166,7 @@ void SMESH_DeviceActor::SetUnstructuredGrid(vtkUnstructuredGrid* theGrid){
 
     myExtractUnstructuredGrid->SetInput(myExtractGeometry->GetOutput());
     myMergeFilter->SetGeometry(myExtractUnstructuredGrid->GetOutput());
-
+    
     theGrid = static_cast<vtkUnstructuredGrid*>(myMergeFilter->GetOutput());
 
     int anId = 0;
@@ -261,6 +261,146 @@ void SMESH_DeviceActor::SetControlMode(SMESH::Controls::FunctorPtr theFunctor,
   theScalarBarActor->SetVisibility(anIsInitialized);
 }
 
+void SMESH_DeviceActor::SetExtControlMode(SMESH::Controls::FunctorPtr theFunctor,
+                                         SMESH_DeviceActor* theDeviceActor,
+                                         vtkScalarBarActor* theScalarBarActor,
+                                         vtkLookupTable* theLookupTable)
+{
+  bool anIsInitialized = 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();
+
+      aDataSet->SetPoints(aGrid->GetPoints());
+      
+      vtkIdType aNbCells = aValues.size();
+      
+      vtkDoubleArray *aScalars = vtkDoubleArray::New();
+      aScalars->SetNumberOfComponents(1);
+      aScalars->SetNumberOfTuples(aNbCells);
+
+      vtkIdType aCellsSize = 3*aNbCells;
+      vtkCellArray* aConnectivity = vtkCellArray::New();
+      aConnectivity->Allocate( aCellsSize, 0 );
+      
+      vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
+      aCellTypesArray->SetNumberOfComponents( 1 );
+      aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
+      
+      vtkIdList *anIdList = vtkIdList::New();
+      anIdList->SetNumberOfIds(2);
+      
+      Length2D::TValues::const_iterator anIter = aValues.begin();
+      for(vtkIdType aVtkId = 0; anIter != aValues.end(); anIter++,aVtkId++){
+       const Length2D::Value& aValue = *anIter;
+       int aNode[2] = {
+         myVisualObj->GetNodeVTKId(aValue.myPntId[0]),
+         myVisualObj->GetNodeVTKId(aValue.myPntId[1])
+       };
+       if(aNode[0] >= 0 && aNode[1] >= 0){
+         anIdList->SetId( 0, aNode[0] );
+         anIdList->SetId( 1, aNode[1] );
+         aConnectivity->InsertNextCell( anIdList );
+         aCellTypesArray->InsertNextValue( VTK_LINE );
+         aScalars->SetValue(aVtkId,aValue.myLength);
+       }
+      }
+      
+      vtkIntArray* aCellLocationsArray = vtkIntArray::New();
+      aCellLocationsArray->SetNumberOfComponents( 1 );
+      aCellLocationsArray->SetNumberOfTuples( aNbCells );
+      
+      aConnectivity->InitTraversal();
+      for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
+       aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
+      
+      aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
+      SetUnstructuredGrid(aDataSet);
+
+      aDataSet->GetCellData()->SetScalars(aScalars);
+      aScalars->Delete();
+      
+      theLookupTable->SetRange(aScalars->GetRange());
+      theLookupTable->Build();
+      
+      myMergeFilter->SetScalars(aDataSet);
+      aDataSet->Delete();
+    }
+    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();
+      aDataSet->SetPoints(aGrid->GetPoints());
+      
+      vtkIdType aNbCells = aValues.size();
+      vtkDoubleArray *aScalars = vtkDoubleArray::New();
+      aScalars->SetNumberOfComponents(1);
+      aScalars->SetNumberOfTuples(aNbCells);
+
+      vtkIdType aCellsSize = 3*aNbCells;
+      vtkCellArray* aConnectivity = vtkCellArray::New();
+      aConnectivity->Allocate( aCellsSize, 0 );
+      
+      vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
+      aCellTypesArray->SetNumberOfComponents( 1 );
+      aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
+      
+      vtkIdList *anIdList = vtkIdList::New();
+      anIdList->SetNumberOfIds(2);
+      
+      MultiConnection2D::MValues::const_iterator anIter = aValues.begin();
+      int i = 0;
+      for(vtkIdType aVtkId; anIter != aValues.end(); anIter++,i++){
+       const MultiConnection2D::Value& aValue = (*anIter).first;
+       int aNode[2] = {
+         myVisualObj->GetNodeVTKId(aValue.myPntId[0]),
+         myVisualObj->GetNodeVTKId(aValue.myPntId[1])
+       };
+       if(aNode[0] >= 0 && aNode[1] >= 0){
+         anIdList->SetId( 0, aNode[0] );
+         anIdList->SetId( 1, aNode[1] );
+         aConnectivity->InsertNextCell( anIdList );
+         aCellTypesArray->InsertNextValue( VTK_LINE );
+         aScalars->SetValue(i,(*anIter).second);
+       }
+      }
+      
+      vtkIntArray* aCellLocationsArray = vtkIntArray::New();
+      aCellLocationsArray->SetNumberOfComponents( 1 );
+      aCellLocationsArray->SetNumberOfTuples( aNbCells );
+      
+      aConnectivity->InitTraversal();
+      for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
+       aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
+      
+      aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
+      SetUnstructuredGrid(aDataSet);
+
+      aDataSet->GetCellData()->SetScalars(aScalars);
+      aScalars->Delete();
+      
+      theLookupTable->SetRange(aScalars->GetRange());
+      theLookupTable->Build();
+      
+      myMergeFilter->SetScalars(aDataSet);
+      aDataSet->Delete();
+    }
+  }
+  GetMapper()->SetScalarVisibility(anIsInitialized);
+  theScalarBarActor->SetVisibility(anIsInitialized);
+}
 
 void SMESH_DeviceActor::SetExtControlMode(SMESH::Controls::FunctorPtr theFunctor,
                                          SMESH_DeviceActor* theDeviceActor)
@@ -304,7 +444,7 @@ void SMESH_DeviceActor::SetExtControlMode(SMESH::Controls::FunctorPtr theFunctor
     anIdList->SetNumberOfIds(2);
     
     FreeEdges::TBorders::const_iterator anIter = aBorders.begin();
-    for(vtkIdType aVtkId; anIter != aBorders.end(); anIter++){
+    for(; anIter != aBorders.end(); anIter++){
       const FreeEdges::Border& aBorder = *anIter;
       int aNode[2] = {
        myVisualObj->GetNodeVTKId(aBorder.myPntId[0]),
@@ -331,10 +471,12 @@ void SMESH_DeviceActor::SetExtControlMode(SMESH::Controls::FunctorPtr theFunctor
 
     SetUnstructuredGrid(aDataSet);
     aDataSet->Delete();
-  }    
+  }
 }
 
 
+
+
 unsigned long int SMESH_DeviceActor::GetMTime(){
   unsigned long mTime = this->Superclass::GetMTime();
   mTime = max(mTime,myExtractGeometry->GetMTime());