]> SALOME platform Git repositories - modules/visu.git/blobdiff - src/OBJECT/VISU_ScalarMapAct.cxx
Salome HOME
Note 0009977 of the issue 0013178: EDF243 VISU : post_processing for fields at nodes
[modules/visu.git] / src / OBJECT / VISU_ScalarMapAct.cxx
index 35673709de805e610be4ef5f79a751e59cf59274..d26381de01fee6fe9aaf2082bf05f4d7e5e95c80 100644 (file)
 #include <vtkImageData.h>
 
 
+//============================================================================
+class VISU_PointsDeviceActor: public VISU_GaussDeviceActorBase
+{
+ public:
+  vtkTypeMacro(VISU_PointsDeviceActor, VISU_GaussDeviceActorBase);
+
+  static 
+  VISU_PointsDeviceActor* 
+  New();
+
+  //----------------------------------------------------------------------------
+  virtual
+  void
+  SetInput(vtkDataSet* theDataSet)
+  {
+    myGeomFilter->SetInput( theDataSet );
+  }
+
+
+  //----------------------------------------------------------------------------
+  void
+  SetInteractor(vtkRenderWindowInteractor* theInteractor)
+  {
+    if(theInteractor == myInteractor)
+      return;
+
+    if(myInteractor)
+      myInteractor->RemoveObserver(myEventCallbackCommand);
+    
+    if(theInteractor)
+      theInteractor->AddObserver(vtkCommand::CharEvent, 
+                                 myEventCallbackCommand, 
+                                 0.0);
+
+    myInteractor = theInteractor;
+  }
+
+
+  //----------------------------------------------------------------------------
+  void
+  DoMapperShallowCopy( vtkMapper* theMapper,
+                       bool theIsCopyInput )
+  {
+    Superclass::DoMapperShallowCopy( theMapper, theIsCopyInput );
+
+    vtkDataSet* aDataSet = theMapper->GetInput();
+    vtkFloatingPointType aScaleFactor = VISU_DeformedShapePL::GetScaleFactor( aDataSet );
+
+    GetPointSpriteMapper()->SetAverageCellSize( aScaleFactor );
+  }
+
+
+  //----------------------------------------------------------------------------
+  void
+  DeepCopy( VISU_PointsDeviceActor *theActor )
+  {
+    VISU::CopyPointSpriteDataMapper( GetPointSpriteMapper(), theActor->GetPointSpriteMapper(), false );
+  }
+
+ protected:
+  //----------------------------------------------------------------------------
+  VISU_PointsDeviceActor():
+    myGeomFilter( VTKViewer_GeometryFilter::New() ),
+    myEventCallbackCommand( vtkCallbackCommand::New() ),
+    myInteractor( NULL )
+  {
+    myGeomFilter->SetInside(true);
+
+    VISU_OpenGLPointSpriteMapper* aMapper = VISU_OpenGLPointSpriteMapper::New();
+    aMapper->SetInput( myGeomFilter->GetOutput() );
+
+    std::string aRootDir( getenv( "VISU_ROOT_DIR") );
+    std::string aMainTexture = aRootDir + "/share/salome/resources/visu/sprite_texture.bmp";
+    std::string anAlphaTexture = aRootDir + "/share/salome/resources/visu/sprite_alpha.bmp";
+    VISU::TTextureValue aTextureValue = VISU::GetTexture( aMainTexture, anAlphaTexture );
+    aMapper->SetImageData( aTextureValue.GetPointer() );
+
+    aMapper->SetUseLookupTableScalarRange(true);
+    aMapper->SetColorModeToMapScalars();
+    aMapper->SetScalarVisibility(true);
+
+    SetPointSpriteMapper( aMapper );
+
+    aMapper->Delete();
+
+    myEventCallbackCommand->SetClientData( this );
+    myEventCallbackCommand->SetCallback( VISU_PointsDeviceActor::ProcessEvents );
+  }
+
+
+  //----------------------------------------------------------------------------
+  ~VISU_PointsDeviceActor()
+  {
+    SetInteractor( NULL );
+    myGeomFilter->Delete();
+    myEventCallbackCommand->Delete();
+  }
+
+
+  //----------------------------------------------------------------------------
+  static
+  void
+  ProcessEvents(vtkObject* theObject, 
+                unsigned long theEvent,
+                void* theClientData, 
+                void* theCallData)
+  {
+    if ( VISU_PointsDeviceActor* self = reinterpret_cast<VISU_PointsDeviceActor*>( theClientData ) )
+      self->OnInteractorEvent( theEvent );
+  }
+
+
+  //----------------------------------------------------------------------------
+  void
+  OnInteractorEvent(unsigned long theEvent)
+  {
+    switch ( theEvent ) {
+    case vtkCommand::CharEvent: {
+      switch( myInteractor->GetKeyCode() ) {
+      case 'M' :
+      case 'm' : {
+        if ( !GetVisibility() )
+          return;
+
+        static vtkFloatingPointType anIncrement = 2;
+        vtkFloatingPointType aMagnification = GetPointSpriteMapper()->GetPointSpriteMagnification();
+        vtkFloatingPointType coefficient = myInteractor->GetShiftKey() ? anIncrement : 1 / anIncrement;
+
+        GetPointSpriteMapper()->SetPointSpriteMagnification( aMagnification * coefficient );
+
+        myInteractor->CreateTimer(VTKI_TIMER_UPDATE);
+        break;
+      }
+      default:
+        return;
+      }
+      break;
+    }
+    default:
+      return;
+    }
+  }
+
+
+  //----------------------------------------------------------------------------
+  vtkCallbackCommand* myEventCallbackCommand;
+  vtkRenderWindowInteractor* myInteractor;
+  VTKViewer_GeometryFilter* myGeomFilter;
+
+ private:
+  VISU_PointsDeviceActor(const VISU_PointsDeviceActor&); // Not implemented
+  void operator=(const VISU_PointsDeviceActor&); // Not implemented
+};
+
+vtkStandardNewMacro(VISU_PointsDeviceActor);
+
 //----------------------------------------------------------------------------
 vtkStandardNewMacro(VISU_ScalarMapAct);
 static vtkFloatingPointType EPS = 1.0 / VTK_LARGE_FLOAT;
@@ -90,8 +247,14 @@ VISU_ScalarMapAct
   myPointsActor->SetProperty(aProperty);
   myPointsActor->SetUserMatrix(aMatrix);
 
+  myPointSpriteActor = VISU_PointsDeviceActor::New();
+  myPointSpriteActor->SetProperty(aProperty);
+  myPointSpriteActor->SetUserMatrix(aMatrix);
+
   aMatrix->Delete();
 
+  myIsPointSpriteMode = false;
+
   SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
   //Quadratic 2D elements representation
   if(aResourceMgr) {
@@ -112,6 +275,7 @@ VISU_ScalarMapAct
   myScalarBar->Delete();
 
   myPointsActor->Delete();
+  myPointSpriteActor->Delete();
 
   mySurfaceActor->Delete();
   myEdgeActor->Delete();
@@ -125,6 +289,8 @@ VISU_ScalarMapAct
 
   myEdgeActor->GetMapper()->ScalarVisibilityOff();
 
+  myPointSpriteActor->DoMapperShallowCopy( thePipeLine->GetMapper(), false );
+
   VISU::CopyMapper( myPointsActor->GetMapper(), thePipeLine->GetMapper(), false );
   VISU::CopyMapper( mySurfaceActor->GetMapper(), thePipeLine->GetMapper(), false );
 }
@@ -141,10 +307,12 @@ VISU_ScalarMapAct
 //    myEdgeActor->SetInput( theDataSet );
 
   if (theDataSet->IsA("vtkPolyData")) {
+    myPointSpriteActor->SetInput( myPolyDataExtractor->GetOutput() );
     myPointsActor->SetInput( myPolyDataExtractor->GetOutput() );
     mySurfaceActor->SetInput( myPolyDataExtractor->GetOutput() );
     myEdgeActor->SetInput( myPolyDataExtractor->GetOutput() );
   } else {
+    myPointSpriteActor->SetInput( myExtractor->GetOutput() );
     myPointsActor->SetInput( myExtractor->GetOutput() );
     mySurfaceActor->SetInput( myExtractor->GetOutput() );
     myEdgeActor->SetInput( myExtractor->GetOutput() );
@@ -159,6 +327,7 @@ VISU_ScalarMapAct
   Superclass::SetTransform(theTransform);
 
   myPointsActor->SetTransform(theTransform);
+  myPointSpriteActor->SetTransform(theTransform);
 
   mySurfaceActor->SetTransform(theTransform);
   myEdgeActor->SetTransform(theTransform);
@@ -278,6 +447,9 @@ VISU_ScalarMapAct
 ::SetOpacity(vtkFloatingPointType theValue)
 {
   mySurfaceActor->GetProperty()->SetOpacity(theValue);
+
+  vtkFloatingPointType aPointSpriteOpacity = theValue > 0.0 ? 1.0 : 0.0;
+  myPointSpriteActor->GetPointSpriteMapper()->SetPointSpriteOpacity(aPointSpriteOpacity);
 }
 
 vtkFloatingPointType
@@ -309,6 +481,7 @@ VISU_ScalarMapAct
   if(VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(theActor)){
     Superclass::DeepCopy(theActor);
     SetBarVisibility(anActor->GetBarVisibility());
+    myPointSpriteActor->DeepCopy( anActor->myPointSpriteActor );
     SetShading(anActor->IsShading());
   }
 }
@@ -321,6 +494,8 @@ VISU_ScalarMapAct
 {
   Superclass::AddToRender(theRenderer);
 
+  myPointSpriteActor->SetInteractor( myInteractor );
+
   if(myScalarBar)
     theRenderer->AddActor2D(myScalarBar);
 }
@@ -334,6 +509,7 @@ VISU_ScalarMapAct
     theRenderer->RemoveActor(myScalarBar);
 
   if ( vtkWindow* aWindow = theRenderer->GetRenderWindow() ) {
+    myPointSpriteActor->ReleaseGraphicsResources( aWindow );
     myPointsActor->ReleaseGraphicsResources( aWindow );
     mySurfaceActor->ReleaseGraphicsResources( aWindow );
     myEdgeActor->ReleaseGraphicsResources( aWindow );
@@ -349,6 +525,7 @@ VISU_ScalarMapAct
 {
   Superclass::SetVisibility( theMode );
 
+  myPointSpriteActor->SetVisibility( theMode );
   myPointsActor->SetVisibility( theMode );
 
   if(myScalarBar) 
@@ -396,6 +573,7 @@ VISU_ScalarMapAct
   else
     mySurfaceActor->SetRepresentation(theMode);
 
+  myPointSpriteActor->SetProperty( mySurfaceActor->GetProperty() );
   myPointsActor->SetProperty( mySurfaceActor->GetProperty() );
 
   SetShading(anIsShanding);
@@ -435,6 +613,7 @@ VISU_ScalarMapAct
   GetMatrix(myEdgeActor->GetUserMatrix());
   GetMatrix(mySurfaceActor->GetUserMatrix());
   GetMatrix(myPointsActor->GetUserMatrix());
+  GetMatrix(myPointSpriteActor->GetUserMatrix());
 
   using namespace SVTK::Representation;
   switch ( GetRepresentation() ) {
@@ -448,8 +627,13 @@ VISU_ScalarMapAct
     break;
 
   case Points:
-    myPointsActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
-    myPointsActor->RenderOpaqueGeometry(ren);
+    if( myIsPointSpriteMode ) {
+      myPointSpriteActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
+      myPointSpriteActor->RenderOpaqueGeometry(ren);
+    } else {
+      myPointsActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
+      myPointsActor->RenderOpaqueGeometry(ren);
+    }
     break;
 
   default:
@@ -462,7 +646,11 @@ VISU_ScalarMapAct
 
 int
 VISU_ScalarMapAct
+#if (VTK_XVERSION < 0x050100)
 ::RenderTranslucentGeometry(vtkViewport *ren)
+#else
+::RenderTranslucentPolygonalGeometry(vtkViewport *ren)
+#endif
 {
   GetMatrix(myEdgeActor->GetUserMatrix());
   GetMatrix(mySurfaceActor->GetUserMatrix());
@@ -487,12 +675,21 @@ VISU_ScalarMapAct
     break;
 
   case Points:
-    myPointsActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
+    if( myIsPointSpriteMode ) {
+      myPointSpriteActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
+#if (VTK_XVERSION < 0x050100)
+      myPointSpriteActor->RenderTranslucentGeometry(ren);
+#else
+      myPointSpriteActor->RenderTranslucentPolygonalGeometry(ren);
+#endif
+    } else {
+      myPointsActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
 #if (VTK_XVERSION < 0x050100)
-    myPointsActor->RenderTranslucentGeometry(ren);
+      myPointsActor->RenderTranslucentGeometry(ren);
 #else
-    myPointsActor->RenderTranslucentPolygonalGeometry(ren);
+      myPointsActor->RenderTranslucentPolygonalGeometry(ren);
 #endif
+    }
     break;
 
   default:
@@ -507,6 +704,46 @@ VISU_ScalarMapAct
   return 1;
 }
 
+//----------------------------------------------------------------------------
+#if (VTK_XVERSION >= 0x050100)
+int
+VISU_ScalarMapAct
+::HasTranslucentPolygonalGeometry()
+{
+  int result = 0; 
+
+  using namespace SVTK::Representation;
+  switch ( GetRepresentation() ) {
+  case Surfaceframe:
+    result |= mySurfaceActor->HasTranslucentPolygonalGeometry();
+    result |= myEdgeActor->HasTranslucentPolygonalGeometry();
+    break;
+  case Points:
+    if( myIsPointSpriteMode )
+      result |= myPointSpriteActor->HasTranslucentPolygonalGeometry();
+    else
+      result |= myPointsActor->HasTranslucentPolygonalGeometry();
+    break;
+  default:
+    result |= mySurfaceActor->HasTranslucentPolygonalGeometry();
+  }
+
+  return result;
+}
+#endif
+
+//----------------------------------------------------------------------------
+unsigned long int
+VISU_ScalarMapAct
+::GetMemorySize()
+{
+  unsigned long int aSize = Superclass::GetMemorySize();
+
+  aSize += myPointSpriteActor->GetMemorySize();
+
+  return aSize;
+}
+
 //----------------------------------------------------------------------------
 
 VISU_Actor::EQuadratic2DRepresentation 
@@ -542,12 +779,16 @@ void VISU_ScalarMapAct::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::Marker
 {
   Superclass::SetMarkerStd( theMarkerType, theMarkerScale );
   myPointsActor->SetMarkerStd( theMarkerType, theMarkerScale );
+
+  myIsPointSpriteMode = theMarkerType == VTK::MT_POINT_SPRITE;
 }
 
 void VISU_ScalarMapAct::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
 {
   Superclass::SetMarkerTexture( theMarkerId, theMarkerTexture );
   myPointsActor->SetMarkerTexture( theMarkerId, theMarkerTexture );
+
+  myIsPointSpriteMode = false;
 }
 
 /**