Salome HOME
Merge from V5_1_main 14/05/2010
[modules/visu.git] / src / OBJECT / VISU_GaussPtsAct.cxx
index ac8ca23961befa6ce8a222d79f576e2901a005c2..83840ebeebf74783f2cf57356b7d435b91fa41f1 100644 (file)
@@ -1,64 +1,67 @@
-//  VISU OBJECT : interactive object for VISU entities implementation
+//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
-// 
-//  This library is free software; you can redistribute it and/or 
-//  modify it under the terms of the GNU Lesser General Public 
-//  License as published by the Free Software Foundation; either 
-//  version 2.1 of the License. 
-// 
-//  This library is distributed in the hope that it will be useful, 
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-//  Lesser General Public License for more details. 
-// 
-//  You should have received a copy of the GNU Lesser General Public 
-//  License along with this library; if not, write to the Free Software 
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
-// 
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
 //
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
 //
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+//  VISU OBJECT : interactive object for VISU entities implementation
 //  File   : VISU_MeshAct.hxx
 //  Author : Laurent CORNABE with the help of Nicolas REJNERI
 //  Module : VISU
 //  $Header$
-
+//
 #include "VISU_GaussPtsAct.h"
 #include "VISU_GaussPointsPL.hxx"
 #include "VISU_GaussPtsSettings.h"
 #include "VISU_GaussPtsDeviceActor.h"
+#include "VISU_PickingSettings.h"
 #include "VISU_WidgetCtrl.hxx"
 #include "VISU_SphereWidget.hxx"
 #include "VISU_OpenGLPointSpriteMapper.hxx"
 #include "VISU_ScalarBarCtrl.hxx"
 #include "VISU_ScalarBarActor.hxx"
 
-#include "SALOME_ExtractGeometry.h"
-
 #include "VISU_Event.h" 
 #include "SVTK_Actor.h"
+#include "VTKViewer_FramedTextActor.h"
+#include <SALOME_ExtractPolyDataGeometry.h>
 
 #include <vtkCamera.h>
 #include <vtkRenderer.h>
 #include <vtkPointPicker.h>
+#include <vtkMatrix4x4.h>
 #include <vtkScalarBarWidget.h>
-#include <vtkScalarBarActor.h>
 #include <vtkTextMapper.h>
 #include <vtkTextProperty.h>
+#include <vtkImplicitBoolean.h>
+#include <vtkImplicitFunctionCollection.h>
+#include <vtkPlane.h>
 
-#include <vtkCellData.h>
 #include <vtkPointData.h>
-
+#include <vtkCellData.h>
 #include <vtkDataArray.h>
-#include <vtkFloatArray.h>
 
 #include <vtkSphereSource.h>
 #include <vtkPolyDataMapper.h>
 #include <vtkPolyData.h>
 #include <vtkActor.h>
+#include <vtkTransform.h>
 
 #include <vtkObjectFactory.h>
 #include <vtkCallbackCommand.h>
 #include <boost/bind.hpp>
 
 #include <vtkUnstructuredGrid.h>
-#include <vtkDataSetMapper.h>
+#include <vtkPolyDataMapper.h>
 #include <vtkRenderWindow.h>
 #include <vtkCellArray.h>
+#include <vtkWarpVector.h>
+#include <vtkCellDataToPointData.h>
 #include <vtkCell.h>
 #include <vtkMath.h>
 
@@ -91,6 +96,31 @@ static int MYDEBUG2 = 0;
 #endif
 
 
+namespace
+{
+  bool
+  CheckIsSameValue(vtkFloatingPointType theTarget,
+                   vtkFloatingPointType theSource)
+  {
+    static vtkFloatingPointType TOL = 10.0 / VTK_LARGE_FLOAT;
+    return fabs(theTarget - theSource)  < TOL;
+  }
+
+  bool
+  CheckIsSameVector(vtkFloatingPointType* theTarget,
+                    vtkFloatingPointType* theSource,
+                    size_t theLength)
+  {
+    for ( size_t anId = 0; anId < theLength; anId++ ) {
+      if ( !CheckIsSameValue( theTarget[ anId ], theSource[ anId ] ) )
+        return false;
+    }
+
+    return true;
+  }
+  
+}
+
 //============================================================================
 vtkStandardNewMacro(VISU_GaussPtsAct);
 
@@ -102,23 +132,25 @@ VISU_GaussPtsAct
   myDeviceActor(VISU_GaussPtsDeviceActor::New()),
   myWidgetCtrl(NULL),
   myGaussPointsPL(NULL),
-  myLastObjPointID(-1),
-  myTextActor(VISU_FramedTextActor::New()),
+  myLastPreHighlightObjID(-1),
   myCursorPyramid(VISU_CursorPyramid::New()),
   myCursorPyramidSelected(VISU_CursorPyramid::New()),
   myCellSource(vtkUnstructuredGrid::New()),
   myCellActor(SVTK_Actor::New()),
   myScalarBarCtrl(VISU_ScalarBarCtrl::New()),
   myBarVisibility(true),
-  myPickingSettings(NULL),
   myInsideCursorSettings(NULL),
-  myCurrentPL(NULL)
+  myCurrentPL(NULL),
+  myMapper(vtkPolyDataMapper::New()),
+  myPolyDataExtractor(SALOME_ExtractPolyDataGeometry::New()),
+  myFunction(vtkImplicitBoolean::New()),
+  myWarpVector(vtkWarpVector::New()),
+  myCellDataToPointData(vtkCellDataToPointData::New())
 {
   if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::VISU_GaussPtsAct - this = "<<this);
 
   myEventCallbackCommand->Delete();
   myDeviceActor->Delete();
-  myTextActor->Delete();
 
   myCursorPyramid->Delete();
   myCursorPyramid->SetPickable(0);
@@ -134,24 +166,42 @@ VISU_GaussPtsAct
   myEventCallbackCommand->SetClientData(this); 
   myEventCallbackCommand->SetCallback(VISU_GaussPtsAct::ProcessEvents);
 
+  vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
+
   myDeviceActor->SetProperty(GetProperty());
+  myDeviceActor->SetUserMatrix(aMatrix);
   myDeviceActor->SetVisibility(true);
   myDeviceActor->SetPickable(false);
 
-  myTextActor->SetVisibility(false);
-  myTextActor->SetPickable(false);
-
   myCellSource->Allocate();
   myCellActor->Initialize();
   myCellActor->SetRepresentation(VTK_WIREFRAME);
   myCellActor->SetSource(myCellSource.GetPointer());
-  
+
   myCellActor->SetVisibility(0);
   myCellActor->SetPickable(0);
   myCellActor->GetProperty()->SetAmbient(1.0);
   myCellActor->GetProperty()->SetDiffuse(0.0);
 
   myScalarBarCtrl->Delete();
+
+  myMapper->Delete();
+  aMatrix->Delete();
+
+  myWarpVector->Delete();
+  myCellDataToPointData->Delete();
+
+  myPolyDataExtractor->SetImplicitFunction(myFunction);
+  //myPolyDataExtractor->ExtractBoundaryCellsOn();
+
+  myFunction->SetOperationTypeToIntersection();
+  myPolyDataExtractor->Delete();
+  myFunction->Delete();
+
+  if( VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get() )
+    aPickingSettings->AddObserver(VISU::UpdatePickingSettingsEvent, 
+                                  myEventCallbackCommand.GetPointer(), 
+                                  myPriority);
 }
 
 VISU_GaussPtsAct
@@ -160,7 +210,6 @@ VISU_GaussPtsAct
   if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::~VISU_GaussPtsAct - this = "<<this);
   SetWidgetCtrl(NULL);
   SetInteractor(NULL);
-  SetPickingSettings(NULL);
   SetInsideCursorSettings(NULL);
 }
 
@@ -184,27 +233,43 @@ VISU_GaussPtsAct
   return myGaussPointsPL.GetPointer();
 }
 
+//----------------------------------------------------------------------------
+void
+VISU_GaussPtsAct
+::DeepCopy(VISU_Actor *theActor)
+{
+  if(VISU_GaussPtsAct* anActor = dynamic_cast<VISU_GaussPtsAct*>(theActor)){
+    Superclass::DeepCopy(theActor);
+    SetBarVisibility(anActor->GetBarVisibility());
+  }
+}
+
+//----------------------------------------------------------------------------
 void
 VISU_GaussPtsAct
 ::ShallowCopyPL(VISU_PipeLine* thePipeLine)
 {
   if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::ShallowCopyPL - this = "<<this);
-
+  
   Superclass::ShallowCopyPL(thePipeLine);
-
+  
   UpdateInsideCursorSettings();
-
+  
   Highlight(isHighlighted());
 }
 
 
 //----------------------------------------------------------------------------
+
 vtkMapper* 
 VISU_GaussPtsAct
 ::GetMapper()
 {
+  //vtkMapper* aMapper = myCurrentPL->GetPointSpriteMapper();
+  //aMapper->Update();
+  //return aMapper;
   myMapper->Update();
-  return Superclass::GetMapper();
+  return myMapper.GetPointer();
 }
 
 vtkFloatingPointType* 
@@ -229,6 +294,19 @@ VISU_GaussPtsAct
 }
 
 
+//----------------------------------------------------------------------------
+unsigned long int
+VISU_GaussPtsAct
+::GetMemorySize()
+{
+  vtkDataSet* aDataSet = myDeviceActor->GetMapper()->GetInput();
+  unsigned long int aSize = aDataSet->GetActualMemorySize() * 1024;
+
+  aSize += Superclass::GetMemorySize();
+
+  return aSize;
+}
+
 //----------------------------------------------------------------------------
 void
 VISU_GaussPtsAct
@@ -240,7 +318,6 @@ VISU_GaussPtsAct
 
   myDeviceActor->AddToRender(theRenderer);
 
-  theRenderer->AddActor(myTextActor.GetPointer());
   theRenderer->AddActor(myCellActor.GetPointer());
 
   myCursorPyramid->AddToRender(theRenderer);
@@ -254,16 +331,15 @@ VISU_GaussPtsAct
 {
   if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::RemoveFromRender - this = "<<this);
 
-  Superclass::RemoveFromRender(theRenderer);
-
   myDeviceActor->RemoveFromRender(theRenderer);
   
-  theRenderer->RemoveActor(myTextActor.GetPointer());
   theRenderer->RemoveActor(myCellActor.GetPointer());
   
   myCursorPyramid->RemoveFromRender(theRenderer);
   myCursorPyramidSelected->RemoveFromRender(theRenderer);
   myScalarBarCtrl->RemoveFromRender(theRenderer);
+
+  Superclass::RemoveFromRender(theRenderer);
 }
 
 void 
@@ -279,6 +355,7 @@ int
 VISU_GaussPtsAct
 ::RenderOpaqueGeometry(vtkViewport *viewport)
 {
+  GetMatrix(myDeviceActor->GetUserMatrix());
   return 1;
 }
 
@@ -286,6 +363,7 @@ int
 VISU_GaussPtsAct
 ::RenderTranslucentGeometry(vtkViewport *viewport)
 {
+  GetMatrix(myDeviceActor->GetUserMatrix());
   return 1;
 }
 
@@ -306,17 +384,17 @@ VISU_GaussPtsAct
 
   if(theWidgetCtrl){
     theWidgetCtrl->AddObserver(vtkCommand::EnableEvent, 
-                              myEventCallbackCommand.GetPointer(), 
-                              myPriority);
+                               myEventCallbackCommand.GetPointer(), 
+                               myPriority);
     theWidgetCtrl->AddObserver(vtkCommand::DisableEvent, 
-                              myEventCallbackCommand.GetPointer(), 
-                              myPriority);
+                               myEventCallbackCommand.GetPointer(), 
+                               myPriority);
     theWidgetCtrl->AddObserver(vtkCommand::StartInteractionEvent, 
-                              myEventCallbackCommand.GetPointer(), 
-                              myPriority);
+                               myEventCallbackCommand.GetPointer(), 
+                               myPriority);
     theWidgetCtrl->AddObserver(vtkCommand::EndInteractionEvent, 
-                              myEventCallbackCommand.GetPointer(), 
-                              myPriority);
+                               myEventCallbackCommand.GetPointer(), 
+                               myPriority);
   }
 
   myWidgetCtrl = theWidgetCtrl;
@@ -352,8 +430,7 @@ namespace
   CreatePipeLine(VISU_GaussPointsPL* thePipeLine)
   {
     VISU_GaussPointsPL* aPipeLine = VISU_GaussPointsPL::New();
-    aPipeLine->SetGaussPtsIDMapper(thePipeLine->GetGaussPtsIDMapper());
-    aPipeLine->ShallowCopy(thePipeLine);
+    aPipeLine->ShallowCopy(thePipeLine, true);
     aPipeLine->Update();
     return aPipeLine;
   }
@@ -365,9 +442,14 @@ VISU_GaussPtsAct
 {
   if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::SetMapperInput - this = "<<this);
 
+  myDeviceActor->SetExtractor(myPolyDataExtractor);
   myDeviceActor->SetPipeLine(GetGaussPointsPL());
   myCurrentPL = myDeviceActor->GetPipeLine();
 
+  //SetMapper(myCurrentPL->GetPointSpriteMapper());
+
+  //  myPolyDataExtractor->SetInput(myCurrentPL->GetPickableDataSet());
+  //myMapper->SetInput(myPolyDataExtractor->GetOutput());
   myMapper->SetInput(myCurrentPL->GetPickableDataSet());
   SetMapper(myMapper.GetPointer());
 }
@@ -379,18 +461,18 @@ namespace
   inline  
   vtkFloatingPointType 
   GetRadius(vtkIdType theVTKID,
-           vtkDataArray *theScalarArray,
-           VISU_GaussPointsPL* theGaussPointsPL)
+            vtkDataArray *theScalarArray,
+            VISU_GaussPointsPL* theGaussPointsPL)
   {
     vtkFloatingPointType aRadius = 0.5;
-    if(theGaussPointsPL->GetPSMapper()->GetPointSpriteMode() == 1) // Geometry mode
+    if(theGaussPointsPL->GetPointSpriteMapper()->GetPointSpriteMode() == 1) // Geometry mode
       aRadius *= theGaussPointsPL->GetSize() * theGaussPointsPL->GetAverageCellSize();
     else if(theGaussPointsPL->GetBicolor()){
       vtkFloatingPointType aVal = theScalarArray->GetTuple1(theVTKID);
       if(aVal > 0.0)
-       aRadius *= theGaussPointsPL->GetMaxSize();
+        aRadius *= theGaussPointsPL->GetMaxSize();
       else
-       aRadius *= theGaussPointsPL->GetMinSize();
+        aRadius *= theGaussPointsPL->GetMinSize();
       aRadius *= theGaussPointsPL->GetAverageCellSize();
     }else
       aRadius *= theGaussPointsPL->GetPointSize(theVTKID,theScalarArray);
@@ -402,8 +484,8 @@ namespace
 vtkFloatingPointType
 VISU_GaussPtsAct
 ::GetRadius(vtkIdType theObjID,
-           vtkIdType theVTKID,
-           vtkDataArray *theScalarArray)
+            vtkIdType theVTKID,
+            vtkDataArray *theScalarArray)
 {
   return ::GetRadius(theVTKID,theScalarArray,myDeviceActor->GetPipeLine());
 }
@@ -439,6 +521,16 @@ VISU_GaussPtsAct
 }
 
 
+//----------------------------------------------------------------------------
+void
+VISU_GaussPtsAct
+::SetOpacity(vtkFloatingPointType theValue)
+{
+  GetGaussPointsPL()->SetOpacity(theValue);
+  Superclass::SetOpacity(theValue);
+}
+
+
 //----------------------------------------------------------------------------
 void
 VISU_GaussPtsAct
@@ -447,8 +539,8 @@ VISU_GaussPtsAct
   using namespace VISU;
   myGaussPtsActorFactory = dynamic_cast<TGaussPtsActorFactory*>(theActorFactory);
   myUpdatePrs3dSignal.connect(boost::bind(&TGaussPtsActorFactory::UpdateFromActor,
-                                         myGaussPtsActorFactory,
-                                         _1));
+                                          myGaussPtsActorFactory,
+                                          _1));
   Superclass::SetFactory(theActorFactory);
 }
 
@@ -466,8 +558,8 @@ VISU_GaussPtsAct
 ::SetVisibility(int theMode)
 {
   Superclass::SetVisibility(theMode);
+  myDeviceActor->SetVisibility(GetVisibility()); // VSV
   myScalarBarCtrl->SetVisibility(theMode);
-  Highlight(isHighlighted());
 }
 
 int
@@ -515,14 +607,14 @@ VISU_GaussPtsAct
   
   if(theInteractor){
     theInteractor->AddObserver(vtkCommand::CharEvent, 
-                              myEventCallbackCommand.GetPointer(), 
-                              myPriority);
+                               myEventCallbackCommand.GetPointer(), 
+                               myPriority);
     theInteractor->AddObserver(VISU::SetSMDecreaseMagnificationEvent, 
-                              myEventCallbackCommand.GetPointer(), 
-                              myPriority);
+                               myEventCallbackCommand.GetPointer(), 
+                               myPriority);
     theInteractor->AddObserver(VISU::SetSMIncreaseMagnificationEvent, 
-                              myEventCallbackCommand.GetPointer(), 
-                              myPriority);
+                               myEventCallbackCommand.GetPointer(), 
+                               myPriority);
   }
   Superclass::SetInteractor(theInteractor);
 
@@ -532,16 +624,16 @@ VISU_GaussPtsAct
 void 
 VISU_GaussPtsAct
 ::ProcessEvents(vtkObject* vtkNotUsed(theObject), 
-               unsigned long theEvent,
-               void* theClientData, 
-               void* vtkNotUsed(theCallData))
+                unsigned long theEvent,
+                void* theClientData, 
+                void* vtkNotUsed(theCallData))
 {
   if(vtkObject* anObject = reinterpret_cast<vtkObject*>(theClientData))
     if(VISU_GaussPtsAct* self = dynamic_cast<VISU_GaussPtsAct*>(anObject)) {
       if(theEvent == VISU::UpdateInsideSettingsEvent)
-       self->UpdateInsideCursorSettings();
+        self->UpdateInsideCursorSettings();
       else
-       self->OnInteractorEvent(theEvent);
+        self->OnInteractorEvent(theEvent);
     }
 }
 
@@ -558,8 +650,8 @@ VISU_GaussPtsAct
     {
       if( IsSegmentationEnabled() )
       {
-       this->ChangeMagnification( myInteractor->GetShiftKey() );
-       return;
+        this->ChangeMagnification( myInteractor->GetShiftKey() );
+        return;
       }
 
       myChangeMagnification = myInteractor->GetShiftKey();
@@ -570,10 +662,10 @@ VISU_GaussPtsAct
     {
       if( IsSegmentationEnabled() && myWidgetCtrl->IsSphereActive() )
       {
-       VISU_SphereWidget* aSphereWidget = myWidgetCtrl->GetSphereWidget();
-       aSphereWidget->ChangeRadius( myInteractor->GetShiftKey() );
-       myWidgetCtrl->InvokeEvent(vtkCommand::EndInteractionEvent,NULL);
-       myWidgetCtrl->GetInteractor()->Render();
+        VISU_SphereWidget* aSphereWidget = myWidgetCtrl->GetSphereWidget();
+        aSphereWidget->ChangeRadius( myInteractor->GetShiftKey() );
+        myWidgetCtrl->InvokeEvent(vtkCommand::EndInteractionEvent,NULL);
+        myWidgetCtrl->GetInteractor()->Render();
       }
       return;
     }
@@ -624,8 +716,8 @@ VISU_GaussPtsAct
   if(Superclass::GetPickable()){
     if(vtkMapper* aMapper = GetMapper()){
       if(vtkDataSet* aDataSet= aMapper->GetInput()){
-       aDataSet->Update();
-       return aDataSet->GetNumberOfCells() > 0;
+        aDataSet->Update();
+        return aDataSet->GetNumberOfCells() > 0;
       }
     }
   }
@@ -637,8 +729,8 @@ VISU_GaussPtsAct
 bool
 VISU_GaussPtsAct
 ::PreHighlight(vtkInteractorStyle* theInteractorStyle, 
-              SVTK_SelectionEvent* theSelectionEvent,
-              bool theIsHighlight)
+               SVTK_SelectionEvent* theSelectionEvent,
+               bool theIsHighlight)
 {
   if ( !GetPickable() )
     return false;
@@ -646,29 +738,32 @@ VISU_GaussPtsAct
   myPreHighlightActor->SetVisibility(false);
   myCursorPyramid->SetVisibility(false);  
 
-  if (!myBarVisibility)
-    return false;
+/*  if (!myBarVisibility)
+    return false;*/
 
 
   if(!theIsHighlight)
-    myLastObjPointID = -1;
+    myLastPreHighlightObjID = -1;
 
   Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
 
   if(aSelectionMode == ActorSelection || !theIsHighlight)
     return Superclass::PreHighlight(theInteractorStyle,
-                                   theSelectionEvent,
-                                   theIsHighlight);  
+                                    theSelectionEvent,
+                                    theIsHighlight);  
   
   bool anIsChanged = (mySelectionMode != aSelectionMode);
   bool anIsPreselected = myIsPreselected;
   myIsPreselected = false;
+
+  VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
   
   if(aSelectionMode == GaussPointSelection && theIsHighlight){
+    SVTK::TPickLimiter aPickLimiter( myPointPicker, this );
     myPointPicker->Pick(theSelectionEvent->myX, 
-                       theSelectionEvent->myY, 
-                       0.0, 
-                       theInteractorStyle->GetCurrentRenderer());
+                        theSelectionEvent->myY, 
+                        0.0, 
+                        theInteractorStyle->GetCurrentRenderer());
     
     if(myPointPicker->GetActor() != this)
       return (anIsPreselected != myIsPreselected);
@@ -679,32 +774,49 @@ VISU_GaussPtsAct
       vtkIdType anObjId = GetNodeObjId( aVtkId );
       myIsPreselected = (anObjId >= 0);
       if(myIsPreselected){
-       anIsChanged = (myLastObjPointID != anObjId);
-       if(anIsChanged){
-         vtkFloatingPointType* aNodeCoord = GetNodeCoord(anObjId);
-         vtkDataSet* aDataSet = GetInput();
-         vtkCellData* aCellData = aDataSet->GetCellData();
-         if(vtkDataArray *aScalarArray = aCellData->GetScalars()){
-           vtkFloatingPointType aPyramidHeight = myPickingSettings->GetPyramidHeight();
-           aPyramidHeight = aPyramidHeight*myGaussPointsPL->GetMaxPointSize();
-           //vtkFloatingPointType aColor[3] = myPreHighlightActor->GetProperty()->GetColor();
-           vtkFloatingPointType aColor[3];
-           theInteractorStyle->GetCurrentRenderer()->GetBackground( aColor );
-           aColor[0] = 1. - aColor[0];
-           aColor[1] = 1. - aColor[1];
-           aColor[2] = 1. - aColor[2];
-
-           myCursorPyramid->Init(aPyramidHeight,
-                                 myPickingSettings->GetCursorSize(),
-                                 GetRadius(anObjId,aVtkId,aScalarArray),
-                                 GetMagnification(anObjId),
-                                 GetClamp(anObjId),
-                                 aNodeCoord,
-                                 aColor);
-         }
-         myLastObjPointID = anObjId;
-       }
-       myCursorPyramid->SetVisibility(true);
+        anIsChanged = (myLastPreHighlightObjID != anObjId);
+        if(anIsChanged){
+          vtkFloatingPointType* aNodeCoord = GetNodeCoord(anObjId);          
+          //Take into account translation
+          vtkFloatingPointType aLocalNodeCoord[3];
+          this->Transform->Push();
+          this->Transform->PostMultiply();
+          this->Transform->Identity();
+          
+          this->Transform->Translate(this->Position[0],
+                                     this->Position[1],
+                                     this->Position[2]);
+          double aPosition[3];
+          this->Transform->GetPosition(aPosition);
+
+          aLocalNodeCoord[0] = aNodeCoord[0] + aPosition[0]; 
+          aLocalNodeCoord[1] = aNodeCoord[1] + aPosition[1];
+          aLocalNodeCoord[2] = aNodeCoord[2] + aPosition[2];
+
+          vtkDataSet* aDataSet = GetInput();
+          vtkPointData* aPointData = aDataSet->GetPointData();
+          if(vtkDataArray *aScalarArray = aPointData->GetScalars()){
+            vtkFloatingPointType aPyramidHeight = aPickingSettings->GetPyramidHeight();
+            aPyramidHeight = aPyramidHeight*myGaussPointsPL->GetMaxPointSize();
+            //vtkFloatingPointType aColor[3] = myPreHighlightActor->GetProperty()->GetColor();
+            vtkFloatingPointType aColor[3];
+            theInteractorStyle->GetCurrentRenderer()->GetBackground( aColor );
+            aColor[0] = 1. - aColor[0];
+            aColor[1] = 1. - aColor[1];
+            aColor[2] = 1. - aColor[2];
+
+            myCursorPyramid->Init(aPyramidHeight,
+                                  aPickingSettings->GetCursorSize(),
+                                  GetRadius(anObjId,aVtkId,aScalarArray),
+                                  GetMagnification(anObjId),
+                                  GetClamp(anObjId),
+                                  aNodeCoord,
+                                  aColor);
+          }
+          this->Transform->Pop();
+          myLastPreHighlightObjID = anObjId;
+        }
+        myCursorPyramid->SetVisibility(true);
       }
     }
   }
@@ -720,21 +832,20 @@ VISU_GaussPtsAct
 inline
 void
 ChangeZoom(VISU_PickingSettings *thePickingSettings,
-          vtkInteractorStyle* theInteractorStyle,
-          int theInitialHasIndex,
-          int theCurrentHasIndex,
-          const Handle(SALOME_InteractiveObject)& theIO)
+           vtkRenderer* theRenderer,
+           vtkIdType theInitialHasIndex,
+           vtkIdType theCurrentHasIndex)
 {
-  if(theInitialHasIndex + theCurrentHasIndex == 1){
-    vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer();
-    vtkCamera *aCamera = aRenderer->GetActiveCamera();
+  if( (theInitialHasIndex + theCurrentHasIndex == 1) && thePickingSettings){
+    vtkCamera *aCamera = theRenderer->GetActiveCamera();
+
     vtkFloatingPointType aZoomFactor = thePickingSettings->GetZoomFactor();
     double aScale = aCamera->GetParallelScale();
-    if (!theInitialHasIndex && theCurrentHasIndex) {
-      aCamera->SetParallelScale(aScale/aZoomFactor);
+    if ( !theInitialHasIndex && theCurrentHasIndex ) {
+      aCamera->SetParallelScale( aScale/aZoomFactor );
     }
     else {
-      aCamera->SetParallelScale(aScale*aZoomFactor);
+      aCamera->SetParallelScale( aScale*aZoomFactor );
     }
   }
   
@@ -743,55 +854,56 @@ ChangeZoom(VISU_PickingSettings *thePickingSettings,
 bool
 VISU_GaussPtsAct
 ::Highlight(vtkInteractorStyle* theInteractorStyle, 
-           SVTK_SelectionEvent* theSelectionEvent,
-           bool theIsHighlight)
+            SVTK_SelectionEvent* theSelectionEvent,
+            bool theIsHighlight)
 { 
   if ( !GetPickable() )
     return false;
 
-  int anInitialHasIndex = myIsHighlighted && mySelectionMode == GaussPointSelection;
+  //  int anInitialHasIndex = myIsSubElementsHighlighted && mySelectionMode == GaussPointSelection;
   Handle(SALOME_InteractiveObject) anIO = getIO();
-  myIsHighlighted = false;
+  //  myIsSubElementsHighlighted = false;
 
   Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
 
   if(!theIsHighlight && aSelectionMode == GaussPointSelection){
     mySelector->RemoveIObject(anIO);
 
-    ChangeZoom(myPickingSettings,
-              theInteractorStyle,
-              anInitialHasIndex,
-              false,
-              anIO);
+    /*    ChangeZoom(myPickingSettings,
+               theInteractorStyle,
+               anInitialHasIndex,
+               false,
+               anIO);*/
 
     return true;
   }
   
-  if (!myBarVisibility)
-    return false;
+/*  if (!myBarVisibility)
+    return false;*/
 
 
   if(aSelectionMode == ActorSelection)
     return Superclass::Highlight(theInteractorStyle,
-                                theSelectionEvent,
-                                theIsHighlight);
+                                 theSelectionEvent,
+                                 theIsHighlight);
 
   if(aSelectionMode == GaussPointSelection && !theSelectionEvent->myIsRectangle){
-
     vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer();
+
+    SVTK::TPickLimiter aPickLimiter( myPointPicker, this );
     myPointPicker->Pick(theSelectionEvent->myX, 
-                       theSelectionEvent->myY,
-                       0.0, 
-                       aRenderer);
+                        theSelectionEvent->myY,
+                        0.0, 
+                        aRenderer);
 
     if(myPointPicker->GetActor() != this) {
       mySelector->ClearIObjects();
 
-      ChangeZoom(myPickingSettings,
-                theInteractorStyle,
-                anInitialHasIndex,
-                false,
-                anIO);
+      /*      ChangeZoom(myPickingSettings,
+                 theInteractorStyle,
+                 anInitialHasIndex,
+                 false,
+                 anIO);*/
 
       return true;
     }
@@ -800,55 +912,63 @@ VISU_GaussPtsAct
     if( aVtkId >= 0  && mySelector->IsValid( this, aVtkId, true ) && hasIO()) {
       vtkIdType anObjId = GetNodeObjId( aVtkId );
       if(anObjId >= 0){
-       myIsHighlighted = true;
-       // Update the Selector
-       if(mySelector->IsSelected(myIO))
-         mySelector->AddOrRemoveIndex(myIO,anObjId,theSelectionEvent->myIsShift);
-       else{
-         if(!theSelectionEvent->myIsShift){
-           mySelector->ClearIObjects();
-         }
-         mySelector->AddOrRemoveIndex(myIO,anObjId,theSelectionEvent->myIsShift);
-         mySelector->AddIObject(this);
-       }
-       //
-       vtkFloatingPointType* aNodeCoord = GetNodeCoord(anObjId);
-       //
-       // FlyTo
-       vtkRenderWindowInteractor* anInteractor = theInteractorStyle->GetInteractor();
-       vtkFloatingPointType aDollyWas = anInteractor->GetDolly();
-       int aNumberOfFlyFramesWas = anInteractor->GetNumberOfFlyFrames();
-       
-       anInteractor->SetDolly(0.);
-       anInteractor->SetNumberOfFlyFrames(myPickingSettings->GetStepNumber());
-       anInteractor->FlyTo(aRenderer,aNodeCoord);
-       aRenderer->ResetCameraClippingRange();
-       anInteractor->SetDolly(aDollyWas);
-       anInteractor->SetNumberOfFlyFrames(aNumberOfFlyFramesWas);
-       
-       mySelectionMode = aSelectionMode;
-
-       ChangeZoom(myPickingSettings,
-                  theInteractorStyle,
-                  anInitialHasIndex,
-                  true,
-                  anIO);
-
-       return true;
-       //
+        //      myIsHighlighted = true;
+        // Update the Selector
+        if(mySelector->IsSelected(myIO))
+          mySelector->AddOrRemoveIndex(myIO,anObjId,theSelectionEvent->myIsShift);
+        else{
+          if(!theSelectionEvent->myIsShift){
+            mySelector->ClearIObjects();
+          }
+          mySelector->AddOrRemoveIndex(myIO,anObjId,theSelectionEvent->myIsShift);
+          mySelector->AddIObject(this);
+        }
+        /*
+        vtkFloatingPointType* aNodeCoord = GetNodeCoord(anObjId);
+        //
+        // FlyTo
+        vtkRenderWindowInteractor* anInteractor = theInteractorStyle->GetInteractor();
+        vtkFloatingPointType aDollyWas = anInteractor->GetDolly();
+        int aNumberOfFlyFramesWas = anInteractor->GetNumberOfFlyFrames();
+        
+        anInteractor->SetDolly(0.);
+        anInteractor->SetNumberOfFlyFrames(myPickingSettings->GetStepNumber());
+        anInteractor->FlyTo(aRenderer,aNodeCoord);
+        aRenderer->ResetCameraClippingRange();
+        anInteractor->SetDolly(aDollyWas);
+        anInteractor->SetNumberOfFlyFrames(aNumberOfFlyFramesWas);
+        
+        anInteractor->InvokeEvent(SVTK::ChangeRotationPoint, aNodeCoord);*/
+
+        mySelectionMode = aSelectionMode;
+
+        /*      ChangeZoom(myPickingSettings,
+                   theInteractorStyle,
+                   anInitialHasIndex,
+                   true,
+                   anIO);*/
+
+        return true;
       }// if( anObjId >= 0 ) {
     }//if( aVtkId >= 0  && mySelector->IsValid( this, aVtkId, true ) && hasIO()) 
   }//if(!theSelectionEvent->myIsRectangle){
 
-  ChangeZoom(myPickingSettings,
-            theInteractorStyle,
-            anInitialHasIndex,
-            false,
-            anIO);
+  /* ChangeZoom(myPickingSettings,
+             theInteractorStyle,
+             anInitialHasIndex,
+             false,
+             anIO);*/
   
   return false;
 }
 
+
+
+void VISU_GaussPtsAct::SetPosition(double _arg[3]){
+  Superclass::SetPosition(_arg);
+  Highlight(isHighlighted());
+}
+
 //==================================================================
 // function : Highlight
 // purpose  :
@@ -860,64 +980,148 @@ VISU_GaussPtsAct
   if(!mySelector.GetPointer())
     return;
 
+  VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
+
+  Selection_Mode aSelectionMode = mySelector->SelectionMode();
+  
+  bool anInitialHasIndex = isSubElementsHighlighted() && mySelectionMode == GaussPointSelection;
+  
+  TColStd_IndexedMapOfInteger aMapIndex;
+  mySelector->GetIndex( getIO(), aMapIndex );
+  bool aCurrentHasIndex = aMapIndex.Extent() == 1;
+  bool anIsVisible = GetVisibility() && aCurrentHasIndex && theIsHighlight;
+  bool aShowTextActor = aPickingSettings->GetInfoWindowEnabled();
+  bool aShowCellActor = aPickingSettings->GetDisplayParentMesh();
+
   myOutlineActor->SetVisibility(false);
-  myTextActor->SetVisibility(false);
-  myCursorPyramidSelected->SetVisibility(false);
   myCursorPyramid->SetVisibility(false);
-  myCellActor->SetVisibility(false);
-  GetScalarBarCtrl()->SetIsMarked(false);
-  GetScalarBarCtrl()->Update();
+  myTextActor->SetVisibility(anIsVisible && aShowTextActor);
+  myCellActor->SetVisibility(anIsVisible && aShowCellActor);
+  GetScalarBarCtrl()->SetIsMarked(anIsVisible);
+  myCursorPyramidSelected->SetVisibility(anIsVisible);
+  //GetScalarBarCtrl()->Update();
 
-  if(!theIsHighlight)
+  myIsSubElementsHighlighted = aCurrentHasIndex;
+
+  // Zoom if necessary
+  if( GetVisibility() && aPickingSettings->GetCameraMovementEnabled() )
+  {
+    ChangeZoom(aPickingSettings,
+               GetRenderer(),
+               anInitialHasIndex,
+               aCurrentHasIndex);
+  }
+
+  if( aSelectionMode == ActorSelection ) {
+    Superclass::Highlight(theIsHighlight);
     return;
+  }
 
-  bool anIsVisible = GetVisibility();
+  if(!theIsHighlight)
+    return;
 
-  Selection_Mode aSelectionMode = mySelector->SelectionMode();
+  if( aSelectionMode != GaussPointSelection )
+    return;
 
-  if(aSelectionMode == ActorSelection)
-    Superclass::highlight(theIsHighlight);
-  else if(aSelectionMode != GaussPointSelection)
+  if ( !aCurrentHasIndex || !myBarVisibility )
     return;
 
-  TColStd_IndexedMapOfInteger aMapIndex;
+  //  myTextActor->SetVisibility(anIsVisible);
+  //  myCellActor->SetVisibility(anIsVisible && myPickingSettings->GetDisplayParentMesh());
+  //  GetScalarBarCtrl()->SetIsMarked(anIsVisible);
+  //  myCursorPyramidSelected->SetVisibility(anIsVisible);
+//GetScalarBarCtrl()->Update();
+
+  // to fix a bug with incorrect representation after the first highlight action
+  myIsHighlighted = aCurrentHasIndex;
+
+  // Zoom if necessary
+//   ChangeZoom(myPickingSettings,
+//           GetRenderer(),
+//           anInitialHasIndex,
+//           aCurrentHasIndex);
+
+  //  TColStd_IndexedMapOfInteger aMapIndex;
   mySelector->GetIndex( getIO(), aMapIndex );
   if(aMapIndex.Extent() != 1 || !myBarVisibility) {
     return;
   }
+
+  vtkRenderer *aRenderer = GetRenderer();
+  vtkCamera* aCamera = aRenderer->GetActiveCamera();
+
+  int anObjId = aMapIndex(1);
+  vtkFloatingPointType* aNodeCoord = GetNodeCoord(anObjId);
+  if ( !aNodeCoord )
+    return;
+  //Take into account translation
+  vtkFloatingPointType aLocalNodeCoord[3];
+  this->Transform->Push();
+  this->Transform->PostMultiply();
+  this->Transform->Identity();
+  this->Transform->Translate(this->Position[0],
+                             this->Position[1],
+                             this->Position[2]);
+  double aPosition[3];
+  this->Transform->GetPosition(aPosition);
+  aLocalNodeCoord[0] = aNodeCoord[0] + aPosition[0]; 
+  aLocalNodeCoord[1] = aNodeCoord[1] + aPosition[1];
+  aLocalNodeCoord[2] = aNodeCoord[2] + aPosition[2];
+  this->Transform->Pop();
+
+  vtkFloatingPointType aFocalPnt[3];
+  aCamera->GetFocalPoint(aFocalPnt);
+
+  if ( CheckIsSameVector(aLocalNodeCoord, aFocalPnt, 3 ) ) 
+    return;
+
+  // FlyTo
+  if( anIsVisible && aPickingSettings->GetCameraMovementEnabled() )
+  {
+    vtkRenderWindowInteractor* anInteractor = myInteractor;
+    vtkFloatingPointType aDollyWas = anInteractor->GetDolly();
+    int aNumberOfFlyFramesWas = anInteractor->GetNumberOfFlyFrames();
+  
+    anInteractor->SetDolly(0.0);
+    anInteractor->SetNumberOfFlyFrames(aPickingSettings->GetStepNumber());
+    anInteractor->FlyTo(aRenderer, aNodeCoord);
+    aRenderer->ResetCameraClippingRange();
+    anInteractor->SetDolly(aDollyWas);
+    anInteractor->SetNumberOfFlyFrames(aNumberOfFlyFramesWas);
+    anInteractor->InvokeEvent(SVTK::ChangeRotationPoint, aNodeCoord);
+  }
   //
   std::ostringstream aStr;
-  int anObjId = aMapIndex(1);
+  //  int anObjId = aMapIndex(1);
   aStr<<"Global ID: "<<anObjId;
   //
   vtkIdType aVtkId = GetNodeVTKID(anObjId);
   if(aVtkId >= 0){
-    vtkFloatingPointType *aNodeCoord = GetNodeCoord(anObjId);
-    vtkFloatingPointType aWorldCoord[4] = {aNodeCoord[0], aNodeCoord[1], aNodeCoord[2], 1.};
+    vtkFloatingPointType aWorldCoord[4] = {aLocalNodeCoord[0], aLocalNodeCoord[1], aLocalNodeCoord[2], 1.};
     //
     vtkDataSet* aDataSet = GetInput();
-    vtkCellData* aDataSetAttributes = aDataSet->GetCellData();
+    vtkPointData* aDataSetAttributes = aDataSet->GetPointData();
     //
     if(vtkDataArray* aScalarArray = aDataSetAttributes->GetScalars()){
       vtkFloatingPointType aVal = aScalarArray->GetTuple1(aVtkId);
       //
-      GetScalarBarCtrl()->SetIsMarked(true);
+      //      GetScalarBarCtrl()->SetIsMarked(true);
       GetScalarBarCtrl()->SetMarkValue(aVal);
       GetScalarBarCtrl()->Update();
       //
-      vtkFloatingPointType aPyramidHeight = myPickingSettings->GetPyramidHeight();
+      vtkFloatingPointType aPyramidHeight = aPickingSettings->GetPyramidHeight();
       aPyramidHeight = aPyramidHeight*myGaussPointsPL->GetMaxPointSize();
       myCursorPyramidSelected->Init(aPyramidHeight,
-                                   myPickingSettings->GetCursorSize(),
-                                   GetRadius(anObjId,aVtkId,aScalarArray),
-                                   GetMagnification(anObjId),
-                                   GetClamp(anObjId),
-                                   aNodeCoord,
-                                   myHighlightActor->GetProperty()->GetColor());
+                                    aPickingSettings->GetCursorSize(),
+                                    GetRadius(anObjId,aVtkId,aScalarArray),
+                                    GetMagnification(anObjId),
+                                    GetClamp(anObjId),
+                                    aLocalNodeCoord,
+                                    myHighlightActor->GetProperty()->GetColor());
       myCursorPyramidSelected->SetVisibility(anIsVisible && theIsHighlight);
       //
       const VISU::PGaussPtsIDMapper& aGaussPtsIDMapper = 
-       myGaussPointsPL->GetGaussPtsIDMapper();
+        myGaussPointsPL->GetGaussPtsIDMapper();
       VISU::TNamedIDMapper* aParent = aGaussPtsIDMapper->GetParent();
       
       VISU::TGaussPointID aGaussPointID = myGaussPointsPL->GetObjID(anObjId);
@@ -926,75 +1130,165 @@ VISU_GaussPtsAct
       aStr<<"\nParentCellID: "<<aCellID;
       std::string aParentName = aParent->GetElemName(aCellID);
       if(aParentName != "") {
-       aStr<<"\nParentCellName: '"<<aParentName<<"'";
+        aStr<<"\nParentCellName: '"<<aParentName<<"'";
       }
       aStr<<"\nLocalPntID: "<<aLocalPntID;
       aStr<<"\nScalar: "<<aVal;
     }
 
     if(vtkDataArray* aFieldArray = aDataSetAttributes->GetArray("VISU_FIELD")){
-      if(vtkFloatArray *aFloatArray = dynamic_cast<vtkFloatArray*>(aFieldArray)){
-       int aNbComp = aFloatArray->GetNumberOfComponents();
-       aStr<<"\nData: {";
-       int anId = 0;
-       while(anId < aNbComp){
-         vtkFloatingPointType aComp = aFloatArray->GetComponent(aVtkId,anId++);
-         aStr<<aComp;
-         if(anId < aNbComp)
-           aStr<<"; ";
-       }
-       aStr<<"}";
+      int aNbComp = aFieldArray->GetNumberOfComponents();
+      std::vector<vtkFloatingPointType> aTuple(aNbComp);
+      aFieldArray->GetTuple(aVtkId, &aTuple[0]);
+      
+      aStr<<"\nData: {";
+      int anId = 0;
+      while(anId < aNbComp){
+        vtkFloatingPointType aComp = aTuple[anId++];
+        aStr<<aComp;
+        if(anId < aNbComp)
+          aStr<<"; ";
       }
+      aStr<<"}";
     }
     //
     // myTextActor
     std::string aString = aStr.str();
-    myTextActor->SetModePosition(myPickingSettings->GetInfoWindowPosition());
-    myTextActor->SetTransparency(myPickingSettings->GetInfoWindowTransparency());
+    myTextActor->SetModePosition(aPickingSettings->GetInfoWindowPosition());
+    myTextActor->SetTransparency(aPickingSettings->GetInfoWindowTransparency());
     myTextActor->SetWorldPoint(aWorldCoord);
     myTextActor->SetText(aString.c_str());
-    myTextActor->SetVisibility(anIsVisible && theIsHighlight);
+    myTextActor->SetVisibility(anIsVisible && theIsHighlight && aShowTextActor);
     //
     // myCellActor
-    if(myPickingSettings->GetDisplayParentMesh()){
-      const VISU::PGaussPtsIDMapper& aGaussPtsIDMapper = 
-       myGaussPointsPL->GetGaussPtsIDMapper();
-      VISU::TNamedIDMapper* aParent = aGaussPtsIDMapper->GetParent();
+    const VISU::PGaussPtsIDMapper& aGaussPtsIDMapper = myGaussPointsPL->GetGaussPtsIDMapper();
+    VISU::TNamedIDMapper* aParent = aGaussPtsIDMapper->GetParent();
+    //
+    myCellSource->Reset();
+    myCellSource->Modified(); // a VTK bug
+    vtkUnstructuredGrid* aCellDataSet = aParent->GetUnstructuredGridOutput();
+    
+    // get parent cell and insert it to myCellSource
+    VISU::TGaussPointID aGaussPointID = aGaussPtsIDMapper->GetObjID(anObjId);
+    vtkIdType aCellID = aGaussPointID.first;
+    vtkCell* aCell = aParent->GetElemCell(aCellID);
+    myCellSource->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
+    
+    if (myGaussPointsPL->GetIsDeformed()) {
+      // find neighbour cells ids
+      vtkIdList* aNeighbourCells = vtkIdList::New();
+      aNeighbourCells->Allocate(VTK_CELL_SIZE);
       
-      myCellSource->Reset();
-      myCellSource->Modified(); // a VTK bug
-      myCellSource->SetPoints(aParent->GetVTKOutput()->GetPoints());
+      vtkIdList* aCellPoints = aCell->GetPointIds();
       
-      VISU::TGaussPointID aGaussPointID = aGaussPtsIDMapper->GetObjID(anObjId);
-      vtkIdType aCellID = aGaussPointID.first;
-      vtkCell* aCell = aParent->GetElemCell(aCellID);
-      myCellSource->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
-      myCellActor->SetVisibility(anIsVisible && theIsHighlight);
-      myCellActor->SetRepresentation(VTK_WIREFRAME);
-    }
-  }
-}
+      vtkIdList *aPointCells = vtkIdList::New();
+      aPointCells->Allocate(VTK_CELL_SIZE);
+      
+      vtkIdType aNbPoints = aCellPoints->GetNumberOfIds();
+      for (vtkIdType i = 0; i < aNbPoints; i++) {
+        aCellDataSet->GetPointCells(aCellPoints->GetId(i), aPointCells);
+
+        // add cell ids
+        vtkIdType aNbCells = aPointCells->GetNumberOfIds();
+        for (vtkIdType j = 0; j < aNbCells; j++)
+          aNeighbourCells->InsertUniqueId(aPointCells->GetId(j));
+      }
 
+      aPointCells->Delete();
 
-//----------------------------------------------------------------
-void
-VISU_GaussPtsAct
-::SetPickingSettings(VISU_PickingSettings* thePickingSettings)
-{
-  if(myPickingSettings == thePickingSettings)
-    return;
+      // get vector data
+      vtkDataArray* anInputVectors = aDataSetAttributes->GetVectors();
+      if (!anInputVectors)
+        return;
+      
+      // insert neighbour cells to the special dataset
+      vtkUnstructuredGrid *aCellsToWarp = vtkUnstructuredGrid::New();
+      aCellsToWarp->SetPoints(aCellDataSet->GetPoints());
 
-  if(myPickingSettings)
-    myPickingSettings->RemoveObserver(myEventCallbackCommand.GetPointer());
+      vtkIdType aNbNeighbourCells = aNeighbourCells->GetNumberOfIds();
 
-  myPickingSettings = thePickingSettings;
+      vtkDataArray *aVectorsToSet = vtkDataArray::CreateDataArray(anInputVectors->GetDataType());
+      aVectorsToSet->SetNumberOfComponents(3);
+      aVectorsToSet->SetNumberOfTuples(aNbNeighbourCells);
 
-  if(thePickingSettings)
-  {
-    thePickingSettings->AddObserver(VISU::UpdatePickingSettingsEvent, 
-                                   myEventCallbackCommand.GetPointer(), 
-                                   myPriority);
-    this->UpdatePickingSettings();
+      vtkDataArray *aCellVectors = vtkDataArray::CreateDataArray(anInputVectors->GetDataType());
+      aCellVectors->SetNumberOfComponents(3);
+      
+      int aNbComp = anInputVectors->GetNumberOfComponents();
+      std::vector<vtkFloatingPointType> aTuple(aNbComp);
+      
+      for (vtkIdType i = 0; i < aNbNeighbourCells; i++) {
+        vtkIdType aVTKCellId = aNeighbourCells->GetId(i);
+        vtkIdType anObjCellId = aParent->GetElemObjID(aVTKCellId);
+        
+        vtkCell* aCurCell = aParent->GetElemCell(anObjCellId);
+        
+        vtkIdType aNewCellId = aCellsToWarp->InsertNextCell(aCurCell->GetCellType(), aCurCell->GetPointIds());
+        
+        // get gauss points corresponding to the current cell
+        vtkIdType aPointVtkId = -1;
+        vtkIdType aLocalPntId = 0;
+        aPointVtkId = aGaussPtsIDMapper->GetVTKID(VISU::TGaussPointID(anObjCellId, aLocalPntId));
+        
+        if (aPointVtkId >= 0) {
+          // Compute average vector
+          aCellVectors->Reset();
+          while (aPointVtkId >= 0) {
+            anInputVectors->GetTuple(aPointVtkId, &aTuple[0]);
+
+            if (aNbComp >= 3)
+              aCellVectors->InsertNextTuple3(aTuple[0], aTuple[1], aTuple[2]);
+            else if (aNbComp == 2)
+              aCellVectors->InsertNextTuple3(aTuple[0], aTuple[1], 0);
+            else if (aNbComp == 1)
+              aCellVectors->InsertNextTuple3(aTuple[0], 0, 0);
+
+            aPointVtkId = aGaussPtsIDMapper->GetVTKID(VISU::TGaussPointID(anObjCellId, ++aLocalPntId));
+          }
+
+          double aXCoord = 0, anYCoord = 0, aZCoord = 0;
+
+          vtkIdType aNbVectors = aCellVectors->GetNumberOfTuples();
+          
+          for (vtkIdType aVecId = 0; aVecId < aNbVectors; aVecId++) {
+            aXCoord  += aCellVectors->GetComponent(aVecId, 0);
+            anYCoord += aCellVectors->GetComponent(aVecId, 1);
+            aZCoord  += aCellVectors->GetComponent(aVecId, 2);
+          }
+
+          aXCoord = aXCoord / aNbVectors;
+          anYCoord = anYCoord / aNbVectors;
+          aZCoord = aZCoord / aNbVectors;
+          
+          // set vector data for the cell
+          aVectorsToSet->SetTuple3(aNewCellId, aXCoord, anYCoord, aZCoord);
+        }
+        else
+          aVectorsToSet->SetTuple3(aNewCellId, 0, 0, 0);
+      }
+      
+      aCellsToWarp->GetCellData()->SetVectors(aVectorsToSet);
+      
+      aVectorsToSet->Delete();
+      aCellVectors->Delete();
+      aNeighbourCells->Delete();
+      
+      // warp
+      myWarpVector->SetScaleFactor(myGaussPointsPL->GetScale());
+      
+      myCellDataToPointData->SetInput(aCellsToWarp);
+      myCellDataToPointData->PassCellDataOn();
+      aCellsToWarp->Delete();
+             
+      myWarpVector->SetInput(myCellDataToPointData->GetUnstructuredGridOutput());
+      vtkUnstructuredGrid* aWarpedDataSet = myWarpVector->GetUnstructuredGridOutput();
+      aWarpedDataSet->Update();
+      myCellSource->SetPoints(aWarpedDataSet->GetPoints());
+    }
+    else
+      myCellSource->SetPoints(aCellDataSet->GetPoints());
+    
+    myCellActor->SetVisibility(anIsVisible && theIsHighlight && aShowCellActor);
   }
 }
 
@@ -1002,19 +1296,21 @@ void
 VISU_GaussPtsAct
 ::UpdatePickingSettings()
 {
-  if(!myPickingSettings || myPickingSettings->GetInitial())
+  //printf( "VISU_GaussPtsAct::UpdatePickingSettings()\n" );
+  VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
+  if(!aPickingSettings)
     return;
 
-  myTextActor->SetModePosition(myPickingSettings->GetInfoWindowPosition());
-  myTextActor->SetTransparency(myPickingSettings->GetInfoWindowTransparency());
+  myTextActor->SetModePosition(aPickingSettings->GetInfoWindowPosition());
+  myTextActor->SetTransparency(aPickingSettings->GetInfoWindowTransparency());
 
-  vtkFloatingPointType aHeight = myGaussPointsPL->GetMaxPointSize()*myPickingSettings->GetPyramidHeight();
-  vtkFloatingPointType aCursorSize = myPickingSettings->GetCursorSize();
+  vtkFloatingPointType aHeight = myGaussPointsPL->GetMaxPointSize()*aPickingSettings->GetPyramidHeight();
+  vtkFloatingPointType aCursorSize = aPickingSettings->GetCursorSize();
   myCursorPyramid->SetPreferences(aHeight,aCursorSize);
   myCursorPyramidSelected->SetPreferences(aHeight,aCursorSize);
 
-  myHighlightActor->GetProperty()->SetColor( myPickingSettings->GetColor() );
-  myPointPicker->SetTolerance( myPickingSettings->GetPointTolerance() );
+  myHighlightActor->GetProperty()->SetColor( aPickingSettings->GetColor() );
+  myPointPicker->SetTolerance( aPickingSettings->GetPointTolerance() );
 
   Highlight(isHighlighted());
 
@@ -1036,8 +1332,8 @@ VISU_GaussPtsAct
 
   if(theInsideCursorSettings){
     theInsideCursorSettings->AddObserver(VISU::UpdateInsideSettingsEvent, 
-                                        myEventCallbackCommand.GetPointer(), 
-                                        myPriority);
+                                         myEventCallbackCommand.GetPointer(), 
+                                         myPriority);
     UpdateInsideCursorSettings();
   }
 }
@@ -1058,10 +1354,9 @@ VISU_GaussPtsAct
 
   VISU_GaussPointsPL* aPipeline = theActor->GetPipeLine();
 
-  SALOME_ExtractGeometry* anExtractGeometry = aPipeline->GetExtractGeometryFilter();
-  vtkImplicitFunction* anImplicitFunction = anExtractGeometry->GetImplicitFunction();
+  vtkImplicitFunction* anImplicitFunction = aPipeline->GetImplicitFunction();
 
-  aPipeline->ShallowCopy(GetGaussPointsPL());
+  aPipeline->ShallowCopy(GetGaussPointsPL(), true);
 
   aPipeline->SetImplicitFunction(anImplicitFunction); // To restore
 
@@ -1087,6 +1382,67 @@ VISU_GaussPtsAct
   Update();
 }
 
+//----------------------------------------------------------------------------
+unsigned long int 
+VISU_GaussPtsAct
+::GetMTime()
+{
+  unsigned long int aTime = Superclass::GetMTime();
+  aTime = std::max(aTime, myGaussPointsPL->GetPointSpriteMapper()->GetMTime() );
+  return aTime;
+}
+
+void VISU_GaussPtsAct::RemoveAllClippingPlanes()
+{
+  myFunction->GetFunction()->RemoveAllItems();
+  myFunction->Modified();
+}
+
+vtkIdType VISU_GaussPtsAct::GetNumberOfClippingPlanes()
+{
+  return myFunction->GetFunction()->GetNumberOfItems();
+}
+
+bool VISU_GaussPtsAct::AddClippingPlane(vtkPlane* thePlane)
+{
+  vtkImplicitFunctionCollection* aFunctions = GetClippingPlanes();
+  aFunctions->InitTraversal();
+  vtkImplicitFunction* aItem;
+  while ((aItem = aFunctions->GetNextItem())) {
+    if (thePlane == aItem)
+      return false;
+  }
+  myFunction->AddFunction(thePlane);
+  return true;
+}
+
+vtkPlane* VISU_GaussPtsAct::GetClippingPlane(vtkIdType theID)
+{
+  vtkPlane* aPlane = NULL;
+  if ((theID >= 0) && (theID < GetNumberOfClippingPlanes())) {
+    vtkImplicitFunctionCollection* aFunction = myFunction->GetFunction();
+    vtkImplicitFunction* aFun = NULL;
+    aFunction->InitTraversal();
+    for (vtkIdType i = 0; i <= theID; i++)
+      aFun = aFunction->GetNextItem();
+    aPlane = dynamic_cast<vtkPlane*>(aFun);
+  }
+  return aPlane;
+}
+
+vtkImplicitFunctionCollection* VISU_GaussPtsAct::GetClippingPlanes()
+{
+  return myFunction->GetFunction();
+}
+
+//----------------------------------------------------------------------------
+vtkDataSet* VISU_GaussPtsAct::GetValLabelsInput()
+{
+  return GetInput();
+}
+
+
+
 //==============================================================================
 vtkStandardNewMacro(VISU_GaussPtsAct1);
 
@@ -1102,13 +1458,18 @@ VISU_GaussPtsAct1
 
   myEventCallbackCommand->SetCallback(VISU_GaussPtsAct1::ProcessEvents);
 
+  vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
+
   myInsideDeviceActor->SetVisibility(false);
   myInsideDeviceActor->SetPickable(false);
+  myInsideDeviceActor->SetUserMatrix(aMatrix);
   myInsideDeviceActor->Delete();
 
   myOutsideDeviceActor->SetVisibility(false);
   myOutsideDeviceActor->SetPickable(false);
+  myOutsideDeviceActor->SetUserMatrix(aMatrix);
   myOutsideDeviceActor->Delete();
+  aMatrix->Delete();
 }
 
 VISU_GaussPtsAct1
@@ -1140,18 +1501,18 @@ VISU_GaussPtsAct1
 {
   Superclass::AddToRender(theRenderer);
 
-  myInsideDeviceActor->AddToRender(theRenderer);
-  myOutsideDeviceActor->AddToRender(theRenderer);
+  //myInsideDeviceActor->AddToRender(theRenderer);
+  //myOutsideDeviceActor->AddToRender(theRenderer);
 }
 
 void 
 VISU_GaussPtsAct1
 ::RemoveFromRender(vtkRenderer* theRenderer)
 {
-  Superclass::RemoveFromRender(theRenderer);
+  //myInsideDeviceActor->RemoveFromRender(theRenderer);
+  //myOutsideDeviceActor->RemoveFromRender(theRenderer);
 
-  myInsideDeviceActor->RemoveFromRender(theRenderer);
-  myOutsideDeviceActor->RemoveFromRender(theRenderer);
+  Superclass::RemoveFromRender(theRenderer);
 }
 
 void 
@@ -1165,6 +1526,28 @@ VISU_GaussPtsAct1
 }
 
 
+int
+VISU_GaussPtsAct1
+::RenderOpaqueGeometry(vtkViewport *viewport)
+{
+
+  Superclass::RenderOpaqueGeometry(viewport);
+  GetMatrix(myInsideDeviceActor->GetUserMatrix());
+  GetMatrix(myOutsideDeviceActor->GetUserMatrix());
+  return 1;
+}
+
+int
+VISU_GaussPtsAct1
+::RenderTranslucentGeometry(vtkViewport *viewport)
+{ 
+  Superclass::RenderTranslucentGeometry(viewport);
+  GetMatrix(myInsideDeviceActor->GetUserMatrix());
+  GetMatrix(myOutsideDeviceActor->GetUserMatrix());
+
+  return 1;
+}
+
 //----------------------------------------------------------------------------
 void
 VISU_GaussPtsAct1
@@ -1205,19 +1588,18 @@ VISU_GaussPtsAct1
 
   Superclass::SetMapperInput(theDataSet);
 
-  if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){
-    myInsideDeviceActor->SetPipeLine(aPipeLine);
-    aPipeLine->Delete();
-  }
+//   if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){
+//     myInsideDeviceActor->SetPipeLine(aPipeLine);
+//     aPipeLine->Delete();
+//   }
 
-  if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){
-    myOutsideDeviceActor->SetPipeLine(aPipeLine);
-    aPipeLine->Delete();
+//   if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){
+//     myOutsideDeviceActor->SetPipeLine(aPipeLine);
+//     aPipeLine->Delete();
 
-    SALOME_ExtractGeometry* anExtractGeometry = aPipeLine->GetExtractGeometryFilter();
-    anExtractGeometry->SetExtractBoundaryCells(true);
-    anExtractGeometry->SetExtractInside(true);
-  }
+//     aPipeLine->SetExtractBoundaryCells(true);
+//     aPipeLine->SetExtractInside(true);
+//   }
 }
 
 
@@ -1225,8 +1607,8 @@ VISU_GaussPtsAct1
 vtkFloatingPointType
 VISU_GaussPtsAct1
 ::GetRadius(vtkIdType theObjID,
-           vtkIdType theVTKID,
-           vtkDataArray *theScalarArray)
+            vtkIdType theVTKID,
+            vtkDataArray *theScalarArray)
 {
   VISU_GaussPointsPL* aPipeLine = myDeviceActor->GetPipeLine();
   if(IsSegmentationEnabled()){
@@ -1271,11 +1653,20 @@ VISU_GaussPtsAct1
 
 
 //----------------------------------------------------------------
+
+void 
+VISU_GaussPtsAct1::SetPosition(double _arg[3]){
+  if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::SetPosition - this = "<<this);               
+  Superclass::SetPosition(_arg);
+  myUpdatePositionSignal(_arg);
+}
+
 void 
 VISU_GaussPtsAct1
 ::Connect(VISU_GaussPtsAct2* theActor)
 {
   mySetVisibilitySignal.connect(boost::bind(&VISU_GaussPtsAct2::SetVisibility,theActor,_1));
+  myUpdatePositionSignal.connect(boost::bind(&VISU_GaussPtsAct2::SetPosition, theActor,_1));
 }
 
 void
@@ -1288,7 +1679,7 @@ VISU_GaussPtsAct1
 
   bool aVisisbility = GetVisibility();
   bool anIsSegementation = IsSegmentationEnabled();
-  myDeviceActor->SetVisibility(aVisisbility && !anIsSegementation);
+  myDeviceActor->SetVisibility(aVisisbility/* && !anIsSegementation*/);
   myInsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
   myOutsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
 
@@ -1319,8 +1710,8 @@ VISU_GaussPtsAct1
   if(theOutsideCursorSettings)
   {
     theOutsideCursorSettings->AddObserver(VISU::UpdateOutsideSettingsEvent, 
-                                         myEventCallbackCommand.GetPointer(), 
-                                         myPriority);
+                                          myEventCallbackCommand.GetPointer(), 
+                                          myPriority);
     UpdateOutsideCursorSettings();
   }
 }
@@ -1334,15 +1725,14 @@ VISU_GaussPtsAct1
 
   VISU_GaussPointsPL* aPipeline = myOutsideDeviceActor->GetPipeLine();
 
-  SALOME_ExtractGeometry* anExtractGeometry = aPipeline->GetExtractGeometryFilter();
-  vtkImplicitFunction* anImplicitFunction = anExtractGeometry->GetImplicitFunction();
+  vtkImplicitFunction* anImplicitFunction = aPipeline->GetImplicitFunction();
   vtkFloatingPointType aMagnification = aPipeline->GetMagnification();
 
-  aPipeline->ShallowCopy(GetGaussPointsPL());
+  aPipeline->ShallowCopy(GetGaussPointsPL(), true);
 
   aPipeline->SetImplicitFunction(anImplicitFunction); // To restore
-  anExtractGeometry->SetExtractBoundaryCells(true);
-  anExtractGeometry->SetExtractInside(true);
+  aPipeline->SetExtractBoundaryCells(true);
+  //aPipeline->SetExtractInside(true);
   aPipeline->SetMagnification( aMagnification );
 
   aPipeline->SetPrimitiveType( myOutsideCursorSettings->GetPrimitiveType() );
@@ -1362,15 +1752,15 @@ VISU_GaussPtsAct1
 
   if( myOutsideCursorSettings->GetUniform() )
   {
-    myOutsideDeviceActor->GetPSMapper()->ScalarVisibilityOff();
-    myOutsideDeviceActor->GetPSMapper()->SetPointSpriteMode( 1 ); // Geometry mode
+    myOutsideDeviceActor->GetPointSpriteMapper()->ScalarVisibilityOff();
+    myOutsideDeviceActor->GetPointSpriteMapper()->SetPointSpriteMode( 1 ); // Geometry mode
     myOutsideDeviceActor->GetProperty()->SetColor( myOutsideCursorSettings->GetColor() );
   }
   else
   {
-    myOutsideDeviceActor->GetPSMapper()->SetPointSpriteMode( 2 ); // Outside cursor mode
-    myOutsideDeviceActor->GetPSMapper()->SetColorModeToMapScalars();
-    myOutsideDeviceActor->GetPSMapper()->ScalarVisibilityOn();
+    myOutsideDeviceActor->GetPointSpriteMapper()->SetPointSpriteMode( 2 ); // Outside cursor mode
+    myOutsideDeviceActor->GetPointSpriteMapper()->SetColorModeToMapScalars();
+    myOutsideDeviceActor->GetPointSpriteMapper()->ScalarVisibilityOn();
   }
 
   aPipeline->Update();
@@ -1385,14 +1775,14 @@ VISU_GaussPtsAct1
 void 
 VISU_GaussPtsAct1
 ::ProcessEvents(vtkObject* theObject, 
-               unsigned long theEvent,
-               void* theClientData, 
-               void* theCallData)
+                unsigned long theEvent,
+                void* theClientData, 
+                void* theCallData)
 {
   if(vtkObject* anObject = reinterpret_cast<vtkObject*>(theClientData))
     if(VISU_GaussPtsAct1* self = dynamic_cast<VISU_GaussPtsAct1*>(anObject))
       if(theEvent == VISU::UpdateOutsideSettingsEvent)
-       self->UpdateOutsideCursorSettings();
+        self->UpdateOutsideCursorSettings();
 
   Superclass::ProcessEvents(theObject,theEvent,theClientData,theCallData);
 }
@@ -1412,7 +1802,7 @@ VISU_GaussPtsAct1
   case vtkCommand::EndInteractionEvent: {
     bool aVisisbility = GetVisibility();
     bool anIsSegementation = IsSegmentationEnabled();
-    myDeviceActor->SetVisibility(aVisisbility && !anIsSegementation);
+    myDeviceActor->SetVisibility(aVisisbility/* && !anIsSegementation*/);
     myInsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
     myOutsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
     break;
@@ -1424,6 +1814,20 @@ VISU_GaussPtsAct1
   Superclass::OnInteractorEvent(theEvent);
 }
 
+//----------------------------------------------------------------------------
+unsigned long int
+VISU_GaussPtsAct1
+::GetMemorySize()
+{
+  unsigned long int aSize = Superclass::GetMemorySize();
+  if(IsSegmentationEnabled()){
+    aSize += myInsideDeviceActor->GetMemorySize();
+    aSize += myOutsideDeviceActor->GetMemorySize();
+  }
+  return aSize;
+}
+
+
 
 //==============================================================================
 vtkStandardNewMacro(VISU_GaussPtsAct2);
@@ -1454,6 +1858,12 @@ VISU_GaussPtsAct2
   Superclass::ShallowCopyPL(thePipeLine);
 }
 
+//----------------------------------------------------------------------------
+void
+VISU_GaussPtsAct2::SetPosition(double _arg[3]){
+  if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct2::SetPosition - this = "<<this);       
+  Superclass::SetPosition(_arg);
+}
 
 //----------------------------------------------------------------------------
 void
@@ -1461,15 +1871,15 @@ VISU_GaussPtsAct2
 ::SetMapperInput(vtkDataSet* theDataSet) 
 {
   if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::SetMapperInput - this = "<<this);
+  Superclass::SetMapperInput(theDataSet);
+//   if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){
+//     myDeviceActor->SetPipeLine(aPipeLine);
+//     myCurrentPL = aPipeLine;
+//     aPipeLine->Delete();
 
-  if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){
-    myDeviceActor->SetPipeLine(aPipeLine);
-    myCurrentPL = aPipeLine;
-    aPipeLine->Delete();
-
-    myMapper->SetInput(myCurrentPL->GetPickableDataSet());
-    SetMapper(myMapper.GetPointer());
-  }
+//     myMapper->SetInput(myCurrentPL->GetPickableDataSet());
+//     SetMapper(myMapper.GetPointer());
+//   }
 }
 
 //----------------------------------------------------------------------------
@@ -1497,6 +1907,17 @@ VISU_GaussPtsAct2
 }
 
 
+//----------------------------------------------------------------------------
+unsigned long int
+VISU_GaussPtsAct2
+::GetMemorySize()
+{
+  if(IsSegmentationEnabled())
+    return Superclass::GetMemorySize();
+  return 0;
+}
+
+
 //----------------------------------------------------------------------------
 void
 VISU_GaussPtsAct2