]> SALOME platform Git repositories - modules/visu.git/blob - src/OBJECT/VISU_GaussPtsAct.cxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/visu.git] / src / OBJECT / VISU_GaussPtsAct.cxx
1 //  VISU OBJECT : interactive object for VISU entities implementation
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : VISU_MeshAct.hxx
25 //  Author : Laurent CORNABE with the help of Nicolas REJNERI
26 //  Module : VISU
27 //  $Header$
28
29 #include "VISU_GaussPtsAct.h"
30 #include "VISU_GaussPointsPL.hxx"
31 #include "VISU_GaussPtsSettings.h"
32 #include "VISU_GaussPtsDeviceActor.h"
33 #include "VISU_WidgetCtrl.hxx"
34 #include "VISU_SphereWidget.hxx"
35 #include "VISU_OpenGLPointSpriteMapper.hxx"
36 #include "VISU_ScalarBarCtrl.hxx"
37 #include "VISU_ScalarBarActor.hxx"
38
39 #include "VISU_Event.h" 
40 #include "SVTK_Actor.h"
41
42 #include <vtkCamera.h>
43 #include <vtkRenderer.h>
44 #include <vtkPointPicker.h>
45 #include <vtkScalarBarWidget.h>
46 #include <vtkTextMapper.h>
47 #include <vtkTextProperty.h>
48
49 #include <vtkPointData.h>
50 #include <vtkDataArray.h>
51
52 #include <vtkSphereSource.h>
53 #include <vtkPolyDataMapper.h>
54 #include <vtkPolyData.h>
55 #include <vtkActor.h>
56
57 #include <vtkObjectFactory.h>
58 #include <vtkCallbackCommand.h>
59 #include <vtkInteractorStyle.h>
60 #include <vtkRenderWindowInteractor.h>
61 #include <vtkOutlineSource.h>
62
63 #include <sstream>
64 #include <boost/bind.hpp>
65
66 #include <vtkUnstructuredGrid.h>
67 #include <vtkPolyDataMapper.h>
68 #include <vtkRenderWindow.h>
69 #include <vtkCellArray.h>
70 #include <vtkCell.h>
71 #include <vtkMath.h>
72
73 #include <vtkViewport.h>
74
75 #include "utilities.h"
76
77 #ifdef _DEBUG_
78 static int MYDEBUG = 0;
79 static int MYDEBUG1 = 0;
80 static int MYDEBUG2 = 0;
81 #else
82 static int MYDEBUG = 0;
83 static int MYDEBUG1 = 0;
84 static int MYDEBUG2 = 0;
85 #endif
86
87
88 namespace
89 {
90   bool
91   CheckIsSameValue(vtkFloatingPointType theTarget,
92                    vtkFloatingPointType theSource)
93   {
94     static vtkFloatingPointType TOL = 10.0 / VTK_LARGE_FLOAT;
95     return fabs(theTarget - theSource)  < TOL;
96   }
97
98   bool
99   CheckIsSameVector(vtkFloatingPointType* theTarget,
100                     vtkFloatingPointType* theSource,
101                     size_t theLength)
102   {
103     for ( size_t anId = 0; anId < theLength; anId++ ) {
104       if ( !CheckIsSameValue( theTarget[ anId ], theSource[ anId ] ) )
105         return false;
106     }
107
108     return true;
109   }
110   
111 }
112
113 //============================================================================
114 vtkStandardNewMacro(VISU_GaussPtsAct);
115
116 //----------------------------------------------------------------------------
117 VISU_GaussPtsAct
118 ::VISU_GaussPtsAct():
119   myEventCallbackCommand(vtkCallbackCommand::New()),
120   myPriority(0.0),
121   myDeviceActor(VISU_GaussPtsDeviceActor::New()),
122   myWidgetCtrl(NULL),
123   myGaussPointsPL(NULL),
124   myLastPreHighlightObjID(-1),
125   myTextActor(VISU_FramedTextActor::New()),
126   myCursorPyramid(VISU_CursorPyramid::New()),
127   myCursorPyramidSelected(VISU_CursorPyramid::New()),
128   myCellSource(vtkUnstructuredGrid::New()),
129   myCellActor(SVTK_Actor::New()),
130   myScalarBarCtrl(VISU_ScalarBarCtrl::New()),
131   myBarVisibility(true),
132   myPickingSettings(NULL),
133   myInsideCursorSettings(NULL),
134   myCurrentPL(NULL),
135   myMapper(vtkPolyDataMapper::New())
136 {
137   if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::VISU_GaussPtsAct - this = "<<this);
138
139   myEventCallbackCommand->Delete();
140   myDeviceActor->Delete();
141   myTextActor->Delete();
142
143   myCursorPyramid->Delete();
144   myCursorPyramid->SetPickable(0);
145   myCursorPyramid->SetVisibility(0);
146
147   myCursorPyramidSelected->Delete();
148   myCursorPyramidSelected->SetPickable(0);
149   myCursorPyramidSelected->SetVisibility(0);
150
151   myCellSource->Delete();
152   myCellActor->Delete();
153
154   myEventCallbackCommand->SetClientData(this); 
155   myEventCallbackCommand->SetCallback(VISU_GaussPtsAct::ProcessEvents);
156
157   myDeviceActor->SetProperty(GetProperty());
158   myDeviceActor->SetVisibility(true);
159   myDeviceActor->SetPickable(false);
160
161   myTextActor->SetVisibility(false);
162   myTextActor->SetPickable(false);
163
164   myCellSource->Allocate();
165   myCellActor->Initialize();
166   myCellActor->SetRepresentation(VTK_WIREFRAME);
167   myCellActor->SetSource(myCellSource.GetPointer());
168   
169   myCellActor->SetVisibility(0);
170   myCellActor->SetPickable(0);
171   myCellActor->GetProperty()->SetAmbient(1.0);
172   myCellActor->GetProperty()->SetDiffuse(0.0);
173
174   myScalarBarCtrl->Delete();
175
176   myMapper->Delete();
177 }
178
179 VISU_GaussPtsAct
180 ::~VISU_GaussPtsAct()
181 {
182   if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::~VISU_GaussPtsAct - this = "<<this);
183   SetWidgetCtrl(NULL);
184   SetInteractor(NULL);
185   SetPickingSettings(NULL);
186   SetInsideCursorSettings(NULL);
187 }
188
189
190 //----------------------------------------------------------------------------
191 void
192 VISU_GaussPtsAct
193 ::SetPipeLine(VISU_PipeLine* thePipeLine) 
194 {
195   if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::SetPipeLine - this = "<<this);
196
197   myGaussPointsPL = dynamic_cast<VISU_GaussPointsPL*>(thePipeLine);
198
199   Superclass::SetPipeLine(thePipeLine);
200 }
201
202 VISU_GaussPointsPL*
203 VISU_GaussPtsAct
204 ::GetGaussPointsPL()
205 {
206   return myGaussPointsPL.GetPointer();
207 }
208
209 //----------------------------------------------------------------------------
210 void
211 VISU_GaussPtsAct
212 ::DeepCopy(VISU_Actor *theActor)
213 {
214   if(VISU_GaussPtsAct* anActor = dynamic_cast<VISU_GaussPtsAct*>(theActor)){
215     Superclass::DeepCopy(theActor);
216     SetBarVisibility(anActor->GetBarVisibility());
217   }
218 }
219
220 //----------------------------------------------------------------------------
221 void
222 VISU_GaussPtsAct
223 ::ShallowCopyPL(VISU_PipeLine* thePipeLine)
224 {
225   if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::ShallowCopyPL - this = "<<this);
226   
227   Superclass::ShallowCopyPL(thePipeLine);
228   
229   UpdateInsideCursorSettings();
230   
231   Highlight(isHighlighted());
232 }
233
234
235 //----------------------------------------------------------------------------
236
237 vtkMapper* 
238 VISU_GaussPtsAct
239 ::GetMapper()
240 {
241   //vtkMapper* aMapper = myCurrentPL->GetPointSpriteMapper();
242   //aMapper->Update();
243   //return aMapper;
244   myMapper->Update();
245   return myMapper.GetPointer();
246 }
247
248 vtkFloatingPointType* 
249 VISU_GaussPtsAct
250 ::GetBounds()
251 {
252   return GetMapper()->GetBounds();
253 }
254
255 vtkDataSet* 
256 VISU_GaussPtsAct
257 ::GetInput()
258 {
259   return GetMapper()->GetInput();
260 }
261
262 VISU_PipeLine* 
263 VISU_GaussPtsAct
264 ::GetCurrentPL() 
265
266   return myCurrentPL;
267 }
268
269
270 //----------------------------------------------------------------------------
271 unsigned long int
272 VISU_GaussPtsAct
273 ::GetMemorySize()
274 {
275   vtkDataSet* aDataSet = myDeviceActor->GetMapper()->GetInput();
276   unsigned long int aSize = aDataSet->GetActualMemorySize() * 1024;
277
278   aSize += Superclass::GetMemorySize();
279
280   return aSize;
281 }
282
283 //----------------------------------------------------------------------------
284 void
285 VISU_GaussPtsAct
286 ::AddToRender(vtkRenderer* theRenderer)
287 {
288   if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::AddToRender - this = "<<this);
289
290   Superclass::AddToRender(theRenderer);
291
292   myDeviceActor->AddToRender(theRenderer);
293
294   theRenderer->AddActor(myTextActor.GetPointer());
295   theRenderer->AddActor(myCellActor.GetPointer());
296
297   myCursorPyramid->AddToRender(theRenderer);
298   myCursorPyramidSelected->AddToRender(theRenderer);
299   myScalarBarCtrl->AddToRender(theRenderer);
300 }
301
302 void 
303 VISU_GaussPtsAct
304 ::RemoveFromRender(vtkRenderer* theRenderer)
305 {
306   if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::RemoveFromRender - this = "<<this);
307
308   myDeviceActor->RemoveFromRender(theRenderer);
309   
310   theRenderer->RemoveActor(myTextActor.GetPointer());
311   theRenderer->RemoveActor(myCellActor.GetPointer());
312   
313   myCursorPyramid->RemoveFromRender(theRenderer);
314   myCursorPyramidSelected->RemoveFromRender(theRenderer);
315   myScalarBarCtrl->RemoveFromRender(theRenderer);
316
317   Superclass::RemoveFromRender(theRenderer);
318 }
319
320 void 
321 VISU_GaussPtsAct
322 ::SetTransform(VTKViewer_Transform* theTransform)
323 {
324   Superclass::SetTransform(theTransform);
325
326   myDeviceActor->SetTransform(theTransform);
327 }
328
329 int
330 VISU_GaussPtsAct
331 ::RenderOpaqueGeometry(vtkViewport *viewport)
332 {
333   return 1;
334 }
335
336 int
337 VISU_GaussPtsAct
338 ::RenderTranslucentGeometry(vtkViewport *viewport)
339 {
340   return 1;
341 }
342
343
344 //----------------------------------------------------------------------------
345 void
346 VISU_GaussPtsAct
347 ::SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl)
348 {
349   if(myWidgetCtrl == theWidgetCtrl)
350     return;
351
352   if(MYDEBUG) 
353     MESSAGE("VISU_GaussPtsAct::SetWidgetCtrl - this = "<<this<<"; theWidget = "<<theWidgetCtrl);
354
355   if(myWidgetCtrl)
356     myWidgetCtrl->RemoveObserver(myEventCallbackCommand.GetPointer());
357
358   if(theWidgetCtrl){
359     theWidgetCtrl->AddObserver(vtkCommand::EnableEvent, 
360                                myEventCallbackCommand.GetPointer(), 
361                                myPriority);
362     theWidgetCtrl->AddObserver(vtkCommand::DisableEvent, 
363                                myEventCallbackCommand.GetPointer(), 
364                                myPriority);
365     theWidgetCtrl->AddObserver(vtkCommand::StartInteractionEvent, 
366                                myEventCallbackCommand.GetPointer(), 
367                                myPriority);
368     theWidgetCtrl->AddObserver(vtkCommand::EndInteractionEvent, 
369                                myEventCallbackCommand.GetPointer(), 
370                                myPriority);
371   }
372
373   myWidgetCtrl = theWidgetCtrl;
374 }
375
376 bool
377 VISU_GaussPtsAct
378 ::GetChangeMagnification()
379 {
380   return myChangeMagnification;
381 }
382
383 void
384 VISU_GaussPtsAct
385 ::ChangeMagnification( bool up )
386 {
387   myEventCallbackCommand->SetAbortFlag(1);
388
389   vtkFloatingPointType aMagnification = myInsideCursorSettings->GetMagnification();
390   vtkFloatingPointType anIncrement = myInsideCursorSettings->GetIncrement();
391   vtkFloatingPointType coefficient = up ? anIncrement : 1 / anIncrement;
392
393   myInsideCursorSettings->SetMagnification( aMagnification * coefficient );
394   myInsideCursorSettings->InvokeEvent(VISU::UpdateFromSettingsEvent,NULL);
395
396   Update();
397 }
398
399 //----------------------------------------------------------------------------
400 namespace
401 {
402   VISU_GaussPointsPL*
403   CreatePipeLine(VISU_GaussPointsPL* thePipeLine)
404   {
405     VISU_GaussPointsPL* aPipeLine = VISU_GaussPointsPL::New();
406     aPipeLine->ShallowCopy(thePipeLine, true);
407     aPipeLine->Update();
408     return aPipeLine;
409   }
410 }
411
412 void
413 VISU_GaussPtsAct
414 ::SetMapperInput(vtkDataSet* theDataSet) 
415 {
416   if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::SetMapperInput - this = "<<this);
417
418   myDeviceActor->SetPipeLine(GetGaussPointsPL());
419   myCurrentPL = myDeviceActor->GetPipeLine();
420
421   //SetMapper(myCurrentPL->GetPointSpriteMapper());
422
423   myMapper->SetInput(myCurrentPL->GetPickableDataSet());
424   SetMapper(myMapper.GetPointer());
425 }
426
427
428 //----------------------------------------------------------------------------
429 namespace
430 {
431   inline  
432   vtkFloatingPointType 
433   GetRadius(vtkIdType theVTKID,
434             vtkDataArray *theScalarArray,
435             VISU_GaussPointsPL* theGaussPointsPL)
436   {
437     vtkFloatingPointType aRadius = 0.5;
438     if(theGaussPointsPL->GetPointSpriteMapper()->GetPointSpriteMode() == 1) // Geometry mode
439       aRadius *= theGaussPointsPL->GetSize() * theGaussPointsPL->GetAverageCellSize();
440     else if(theGaussPointsPL->GetBicolor()){
441       vtkFloatingPointType aVal = theScalarArray->GetTuple1(theVTKID);
442       if(aVal > 0.0)
443         aRadius *= theGaussPointsPL->GetMaxSize();
444       else
445         aRadius *= theGaussPointsPL->GetMinSize();
446       aRadius *= theGaussPointsPL->GetAverageCellSize();
447     }else
448       aRadius *= theGaussPointsPL->GetPointSize(theVTKID,theScalarArray);
449
450     return aRadius;
451   }
452 }
453
454 vtkFloatingPointType
455 VISU_GaussPtsAct
456 ::GetRadius(vtkIdType theObjID,
457             vtkIdType theVTKID,
458             vtkDataArray *theScalarArray)
459 {
460   return ::GetRadius(theVTKID,theScalarArray,myDeviceActor->GetPipeLine());
461 }
462
463 //----------------------------------------------------------------------------
464 vtkFloatingPointType 
465 VISU_GaussPtsAct
466 ::GetMagnification(vtkIdType theObjID)
467 {
468   return myDeviceActor->GetPipeLine()->GetMagnification();
469 }
470
471
472 //----------------------------------------------------------------------------
473 namespace
474 {
475   inline  
476   vtkFloatingPointType 
477   GetClamp(VISU_GaussPointsPL* theGaussPointsPL)
478   {
479     vtkFloatingPointType aClamp = theGaussPointsPL->GetClamp();
480     if(theGaussPointsPL->GetPrimitiveType() == VISU_OpenGLPointSpriteMapper::GeomSphere)
481       return -aClamp;
482     return aClamp;
483   }
484 }
485
486 vtkFloatingPointType 
487 VISU_GaussPtsAct
488 ::GetClamp(vtkIdType theObjID)
489 {
490   return ::GetClamp(myDeviceActor->GetPipeLine());
491 }
492
493
494 //----------------------------------------------------------------------------
495 void
496 VISU_GaussPtsAct
497 ::SetFactory(VISU::TActorFactory* theActorFactory)
498
499   using namespace VISU;
500   myGaussPtsActorFactory = dynamic_cast<TGaussPtsActorFactory*>(theActorFactory);
501   myUpdatePrs3dSignal.connect(boost::bind(&TGaussPtsActorFactory::UpdateFromActor,
502                                           myGaussPtsActorFactory,
503                                           _1));
504   Superclass::SetFactory(theActorFactory);
505 }
506
507 VISU::TGaussPtsActorFactory*
508 VISU_GaussPtsAct
509 ::GetGaussPtsFactory()
510 {
511   return myGaussPtsActorFactory;
512 }
513
514
515 //----------------------------------------------------------------------------
516 void
517 VISU_GaussPtsAct
518 ::SetVisibility(int theMode)
519 {
520   Superclass::SetVisibility(theMode);
521   myScalarBarCtrl->SetVisibility(theMode);
522   Highlight(isHighlighted());
523 }
524
525 int
526 VISU_GaussPtsAct
527 ::IsSegmentationEnabled()
528 {
529   return myWidgetCtrl  && myWidgetCtrl->GetEnabled();
530 }
531
532
533 //----------------------------------------------------------------------------
534 void
535 VISU_GaussPtsAct
536 ::SetBarVisibility(bool theMode)
537 {
538   myBarVisibility = theMode;
539   myScalarBarCtrl->SetCtrlVisibility(theMode); 
540   myScalarBarCtrl->SetVisibility(GetVisibility()); 
541 }
542
543 bool
544 VISU_GaussPtsAct
545 ::GetBarVisibility()
546
547   return myBarVisibility;
548 }
549
550 VISU_ScalarBarCtrl* 
551 VISU_GaussPtsAct
552 ::GetScalarBarCtrl()
553 {
554   return myScalarBarCtrl.GetPointer();
555 }
556
557 //----------------------------------------------------------------------------
558 void
559 VISU_GaussPtsAct
560 ::SetInteractor(vtkRenderWindowInteractor* theInteractor)
561 {
562   if(theInteractor == myInteractor)
563     return;
564
565   if(myInteractor)
566     myInteractor->RemoveObserver(myEventCallbackCommand.GetPointer());
567   
568   if(theInteractor){
569     theInteractor->AddObserver(vtkCommand::CharEvent, 
570                                myEventCallbackCommand.GetPointer(), 
571                                myPriority);
572     theInteractor->AddObserver(VISU::SetSMDecreaseMagnificationEvent, 
573                                myEventCallbackCommand.GetPointer(), 
574                                myPriority);
575     theInteractor->AddObserver(VISU::SetSMIncreaseMagnificationEvent, 
576                                myEventCallbackCommand.GetPointer(), 
577                                myPriority);
578   }
579   Superclass::SetInteractor(theInteractor);
580
581   Modified();
582 }
583 //-------------------------------------------------------------------------
584 void 
585 VISU_GaussPtsAct
586 ::ProcessEvents(vtkObject* vtkNotUsed(theObject), 
587                 unsigned long theEvent,
588                 void* theClientData, 
589                 void* vtkNotUsed(theCallData))
590 {
591   if(vtkObject* anObject = reinterpret_cast<vtkObject*>(theClientData))
592     if(VISU_GaussPtsAct* self = dynamic_cast<VISU_GaussPtsAct*>(anObject)) {
593       if(theEvent == VISU::UpdateInsideSettingsEvent)
594         self->UpdateInsideCursorSettings();
595       else
596         self->OnInteractorEvent(theEvent);
597     }
598 }
599
600 //-------------------------------------------------------------------------
601 void
602 VISU_GaussPtsAct
603 ::OnInteractorEvent(unsigned long theEvent)
604 {
605   switch(theEvent){
606   case vtkCommand::CharEvent: {
607     switch(myInteractor->GetKeyCode()) {
608     case 'M' :
609     case 'm' :
610     {
611       if( IsSegmentationEnabled() )
612       {
613         this->ChangeMagnification( myInteractor->GetShiftKey() );
614         return;
615       }
616
617       myChangeMagnification = myInteractor->GetShiftKey();
618       break;
619     }
620     case 'D' :
621     case 'd' :
622     {
623       if( IsSegmentationEnabled() && myWidgetCtrl->IsSphereActive() )
624       {
625         VISU_SphereWidget* aSphereWidget = myWidgetCtrl->GetSphereWidget();
626         aSphereWidget->ChangeRadius( myInteractor->GetShiftKey() );
627         myWidgetCtrl->InvokeEvent(vtkCommand::EndInteractionEvent,NULL);
628         myWidgetCtrl->GetInteractor()->Render();
629       }
630       return;
631     }
632     default:
633       return;
634     }
635     myUpdatePrs3dSignal(this);
636     break;
637   }
638   case VISU::SetSMDecreaseMagnificationEvent: 
639   case VISU::SetSMIncreaseMagnificationEvent: 
640     myChangeMagnification = theEvent == VISU::SetSMIncreaseMagnificationEvent;
641     myUpdatePrs3dSignal(this);
642     break;
643   case VISU::UpdatePickingSettingsEvent:
644     UpdatePickingSettings();
645     break;
646   case vtkCommand::EndInteractionEvent:
647   case vtkCommand::EnableEvent:
648   case vtkCommand::DisableEvent: 
649     myCurrentPL->GetMapper()->Update();
650     Highlight(isHighlighted());
651     break;
652   default:
653     break;
654   }
655 }
656
657 //----------------------------------------------------------------------------
658 bool
659 VISU_GaussPtsAct
660 ::IsInfinitive()
661 {
662   if(vtkMapper* aMapper = myDeviceActor->GetMapper()){
663     if(vtkDataSet* aDataSet= aMapper->GetInput()){
664       aDataSet->Update();
665       myIsInfinite = aDataSet->GetNumberOfCells() < 2;
666     }
667   }
668   return myIsInfinite;
669 }
670
671 //----------------------------------------------------------------------------
672 int
673 VISU_GaussPtsAct
674 ::GetPickable()
675 {
676   if(Superclass::GetPickable()){
677     if(vtkMapper* aMapper = GetMapper()){
678       if(vtkDataSet* aDataSet= aMapper->GetInput()){
679         aDataSet->Update();
680         return aDataSet->GetNumberOfCells() > 0;
681       }
682     }
683   }
684
685   return false;
686 }
687
688 //----------------------------------------------------------------------------
689 bool
690 VISU_GaussPtsAct
691 ::PreHighlight(vtkInteractorStyle* theInteractorStyle, 
692                SVTK_SelectionEvent* theSelectionEvent,
693                bool theIsHighlight)
694 {
695   if ( !GetPickable() )
696     return false;
697
698   myPreHighlightActor->SetVisibility(false);
699   myCursorPyramid->SetVisibility(false);  
700
701   if (!myBarVisibility)
702     return false;
703
704
705   if(!theIsHighlight)
706     myLastPreHighlightObjID = -1;
707
708   Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
709
710   if(aSelectionMode == ActorSelection || !theIsHighlight)
711     return Superclass::PreHighlight(theInteractorStyle,
712                                     theSelectionEvent,
713                                     theIsHighlight);  
714   
715   bool anIsChanged = (mySelectionMode != aSelectionMode);
716   bool anIsPreselected = myIsPreselected;
717   myIsPreselected = false;
718   
719   if(aSelectionMode == GaussPointSelection && theIsHighlight){
720     myPointPicker->Pick(theSelectionEvent->myX, 
721                         theSelectionEvent->myY, 
722                         0.0, 
723                         theInteractorStyle->GetCurrentRenderer());
724     
725     if(myPointPicker->GetActor() != this)
726       return (anIsPreselected != myIsPreselected);
727     
728     vtkIdType aVtkId = myPointPicker->GetPointId();
729     
730     if(aVtkId >= 0 && mySelector->IsValid(this,aVtkId,true) && hasIO()){
731       vtkIdType anObjId = GetNodeObjId( aVtkId );
732       myIsPreselected = (anObjId >= 0);
733       if(myIsPreselected){
734         anIsChanged = (myLastPreHighlightObjID != anObjId);
735         if(anIsChanged){
736           vtkFloatingPointType* aNodeCoord = GetNodeCoord(anObjId);
737           vtkDataSet* aDataSet = GetInput();
738           vtkPointData* aPointData = aDataSet->GetPointData();
739           if(vtkDataArray *aScalarArray = aPointData->GetScalars()){
740             vtkFloatingPointType aPyramidHeight = myPickingSettings->GetPyramidHeight();
741             aPyramidHeight = aPyramidHeight*myGaussPointsPL->GetMaxPointSize();
742             //vtkFloatingPointType aColor[3] = myPreHighlightActor->GetProperty()->GetColor();
743             vtkFloatingPointType aColor[3];
744             theInteractorStyle->GetCurrentRenderer()->GetBackground( aColor );
745             aColor[0] = 1. - aColor[0];
746             aColor[1] = 1. - aColor[1];
747             aColor[2] = 1. - aColor[2];
748
749             myCursorPyramid->Init(aPyramidHeight,
750                                   myPickingSettings->GetCursorSize(),
751                                   GetRadius(anObjId,aVtkId,aScalarArray),
752                                   GetMagnification(anObjId),
753                                   GetClamp(anObjId),
754                                   aNodeCoord,
755                                   aColor);
756           }
757           myLastPreHighlightObjID = anObjId;
758         }
759         myCursorPyramid->SetVisibility(true);
760       }
761     }
762   }
763   
764   mySelectionMode = aSelectionMode;
765   anIsChanged |= (anIsPreselected != myIsPreselected);
766
767   return anIsChanged;
768 }
769
770
771 //----------------------------------------------------------------------------
772 inline
773 void
774 ChangeZoom(VISU_PickingSettings *thePickingSettings,
775            vtkRenderer* theRenderer,
776            vtkIdType theInitialHasIndex,
777            vtkIdType theCurrentHasIndex)
778 {
779   if(theInitialHasIndex + theCurrentHasIndex == 1){
780     vtkCamera *aCamera = theRenderer->GetActiveCamera();
781
782     vtkFloatingPointType aZoomFactor = thePickingSettings->GetZoomFactor();
783     double aScale = aCamera->GetParallelScale();
784     if ( !theInitialHasIndex && theCurrentHasIndex ) {
785       aCamera->SetParallelScale( aScale/aZoomFactor );
786     }
787     else {
788       aCamera->SetParallelScale( aScale*aZoomFactor );
789     }
790   }
791   
792 }
793
794 bool
795 VISU_GaussPtsAct
796 ::Highlight(vtkInteractorStyle* theInteractorStyle, 
797             SVTK_SelectionEvent* theSelectionEvent,
798             bool theIsHighlight)
799
800   if ( !GetPickable() )
801     return false;
802
803   //  int anInitialHasIndex = myIsHighlighted && mySelectionMode == GaussPointSelection;
804   Handle(SALOME_InteractiveObject) anIO = getIO();
805   //  myIsHighlighted = false;
806
807   Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
808
809   if(!theIsHighlight && aSelectionMode == GaussPointSelection){
810     mySelector->RemoveIObject(anIO);
811
812     /*    ChangeZoom(myPickingSettings,
813                theInteractorStyle,
814                anInitialHasIndex,
815                false,
816                anIO);*/
817
818     return true;
819   }
820   
821   if (!myBarVisibility)
822     return false;
823
824
825   if(aSelectionMode == ActorSelection)
826     return Superclass::Highlight(theInteractorStyle,
827                                  theSelectionEvent,
828                                  theIsHighlight);
829
830   if(aSelectionMode == GaussPointSelection && !theSelectionEvent->myIsRectangle){
831
832     vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer();
833     myPointPicker->Pick(theSelectionEvent->myX, 
834                         theSelectionEvent->myY,
835                         0.0, 
836                         aRenderer);
837
838     if(myPointPicker->GetActor() != this) {
839       mySelector->ClearIObjects();
840
841       /*      ChangeZoom(myPickingSettings,
842                  theInteractorStyle,
843                  anInitialHasIndex,
844                  false,
845                  anIO);*/
846
847       return true;
848     }
849
850     vtkIdType aVtkId = myPointPicker->GetPointId();
851     if( aVtkId >= 0  && mySelector->IsValid( this, aVtkId, true ) && hasIO()) {
852       vtkIdType anObjId = GetNodeObjId( aVtkId );
853       if(anObjId >= 0){
854         //      myIsHighlighted = true;
855         // Update the Selector
856         if(mySelector->IsSelected(myIO))
857           mySelector->AddOrRemoveIndex(myIO,anObjId,theSelectionEvent->myIsShift);
858         else{
859           if(!theSelectionEvent->myIsShift){
860             mySelector->ClearIObjects();
861           }
862           mySelector->AddOrRemoveIndex(myIO,anObjId,theSelectionEvent->myIsShift);
863           mySelector->AddIObject(this);
864         }
865         /*
866         vtkFloatingPointType* aNodeCoord = GetNodeCoord(anObjId);
867         //
868         // FlyTo
869         vtkRenderWindowInteractor* anInteractor = theInteractorStyle->GetInteractor();
870         vtkFloatingPointType aDollyWas = anInteractor->GetDolly();
871         int aNumberOfFlyFramesWas = anInteractor->GetNumberOfFlyFrames();
872         
873         anInteractor->SetDolly(0.);
874         anInteractor->SetNumberOfFlyFrames(myPickingSettings->GetStepNumber());
875         anInteractor->FlyTo(aRenderer,aNodeCoord);
876         aRenderer->ResetCameraClippingRange();
877         anInteractor->SetDolly(aDollyWas);
878         anInteractor->SetNumberOfFlyFrames(aNumberOfFlyFramesWas);
879         
880         anInteractor->InvokeEvent(SVTK::ChangeRotationPoint, aNodeCoord);*/
881
882         mySelectionMode = aSelectionMode;
883
884         /*      ChangeZoom(myPickingSettings,
885                    theInteractorStyle,
886                    anInitialHasIndex,
887                    true,
888                    anIO);*/
889
890         return true;
891       }// if( anObjId >= 0 ) {
892     }//if( aVtkId >= 0  && mySelector->IsValid( this, aVtkId, true ) && hasIO()) 
893   }//if(!theSelectionEvent->myIsRectangle){
894
895   /* ChangeZoom(myPickingSettings,
896              theInteractorStyle,
897              anInitialHasIndex,
898              false,
899              anIO);*/
900   
901   return false;
902 }
903
904 //==================================================================
905 // function : Highlight
906 // purpose  :
907 //==================================================================
908 void
909 VISU_GaussPtsAct
910 ::Highlight(bool theIsHighlight)
911 {
912   if(!mySelector.GetPointer())
913     return;
914
915   Selection_Mode aSelectionMode = mySelector->SelectionMode();
916   
917   bool anInitialHasIndex = isHighlighted() && mySelectionMode == GaussPointSelection;
918   
919   TColStd_IndexedMapOfInteger aMapIndex;
920   mySelector->GetIndex( getIO(), aMapIndex );
921   bool aCurrentHasIndex = aMapIndex.Extent() == 1;
922   bool anIsVisible = GetVisibility() && aCurrentHasIndex && theIsHighlight;
923
924   myOutlineActor->SetVisibility(false);
925   myCursorPyramid->SetVisibility(false);
926
927   myTextActor->SetVisibility(anIsVisible);
928   myCellActor->SetVisibility(anIsVisible);
929   GetScalarBarCtrl()->SetIsMarked(anIsVisible);
930   myCursorPyramidSelected->SetVisibility(anIsVisible);
931 //GetScalarBarCtrl()->Update();
932
933   myIsHighlighted = aCurrentHasIndex;
934
935   // Zoom if necessary
936   ChangeZoom(myPickingSettings,
937              GetRenderer(),
938              anInitialHasIndex,
939              aCurrentHasIndex);
940
941   if(!theIsHighlight)
942     return;
943
944   if( aSelectionMode == ActorSelection ) {
945     Superclass::highlight(theIsHighlight);
946     return;
947   }
948
949   if( aSelectionMode != GaussPointSelection )
950     return;
951
952   if ( !aCurrentHasIndex || !myBarVisibility )
953     return;
954
955   //  TColStd_IndexedMapOfInteger aMapIndex;
956   mySelector->GetIndex( getIO(), aMapIndex );
957   if(aMapIndex.Extent() != 1 || !myBarVisibility) {
958     return;
959   }
960
961   vtkRenderer *aRenderer = GetRenderer();
962   vtkCamera* aCamera = aRenderer->GetActiveCamera();
963
964   int anObjId = aMapIndex(1);
965   vtkFloatingPointType* aNodeCoord = GetNodeCoord(anObjId);
966
967   vtkFloatingPointType aFocalPnt[3];
968   aCamera->GetFocalPoint(aFocalPnt);
969
970   if ( CheckIsSameVector( aNodeCoord, aFocalPnt, 3 ) ) 
971     return;
972
973   // FlyTo
974   vtkRenderWindowInteractor* anInteractor = myInteractor;
975   vtkFloatingPointType aDollyWas = anInteractor->GetDolly();
976   int aNumberOfFlyFramesWas = anInteractor->GetNumberOfFlyFrames();
977   
978   anInteractor->SetDolly(0.0);
979   anInteractor->SetNumberOfFlyFrames(myPickingSettings->GetStepNumber());
980   anInteractor->FlyTo(aRenderer, aNodeCoord);
981   aRenderer->ResetCameraClippingRange();
982   anInteractor->SetDolly(aDollyWas);
983   anInteractor->SetNumberOfFlyFrames(aNumberOfFlyFramesWas);
984   anInteractor->InvokeEvent(SVTK::ChangeRotationPoint, aNodeCoord);
985   //
986   std::ostringstream aStr;
987   //  int anObjId = aMapIndex(1);
988   aStr<<"Global ID: "<<anObjId;
989   //
990   vtkIdType aVtkId = GetNodeVTKID(anObjId);
991   if(aVtkId >= 0){
992     vtkFloatingPointType *aNodeCoord = GetNodeCoord(anObjId);
993     vtkFloatingPointType aWorldCoord[4] = {aNodeCoord[0], aNodeCoord[1], aNodeCoord[2], 1.};
994     //
995     vtkDataSet* aDataSet = GetInput();
996     vtkPointData* aDataSetAttributes = aDataSet->GetPointData();
997     //
998     if(vtkDataArray* aScalarArray = aDataSetAttributes->GetScalars()){
999       vtkFloatingPointType aVal = aScalarArray->GetTuple1(aVtkId);
1000       //
1001       //      GetScalarBarCtrl()->SetIsMarked(true);
1002       GetScalarBarCtrl()->SetMarkValue(aVal);
1003       GetScalarBarCtrl()->Update();
1004       //
1005       vtkFloatingPointType aPyramidHeight = myPickingSettings->GetPyramidHeight();
1006       aPyramidHeight = aPyramidHeight*myGaussPointsPL->GetMaxPointSize();
1007       myCursorPyramidSelected->Init(aPyramidHeight,
1008                                     myPickingSettings->GetCursorSize(),
1009                                     GetRadius(anObjId,aVtkId,aScalarArray),
1010                                     GetMagnification(anObjId),
1011                                     GetClamp(anObjId),
1012                                     aNodeCoord,
1013                                     myHighlightActor->GetProperty()->GetColor());
1014       myCursorPyramidSelected->SetVisibility(anIsVisible && theIsHighlight);
1015       //
1016       const VISU::PGaussPtsIDMapper& aGaussPtsIDMapper = 
1017         myGaussPointsPL->GetGaussPtsIDMapper();
1018       VISU::TNamedIDMapper* aParent = aGaussPtsIDMapper->GetParent();
1019       
1020       VISU::TGaussPointID aGaussPointID = myGaussPointsPL->GetObjID(anObjId);
1021       VISU::TCellID aCellID = aGaussPointID.first;
1022       VISU::TLocalPntID aLocalPntID = aGaussPointID.second;
1023       aStr<<"\nParentCellID: "<<aCellID;
1024       std::string aParentName = aParent->GetElemName(aCellID);
1025       if(aParentName != "") {
1026         aStr<<"\nParentCellName: '"<<aParentName<<"'";
1027       }
1028       aStr<<"\nLocalPntID: "<<aLocalPntID;
1029       aStr<<"\nScalar: "<<aVal;
1030     }
1031
1032     if(vtkDataArray* aFieldArray = aDataSetAttributes->GetArray("VISU_FIELD")){
1033       int aNbComp = aFieldArray->GetNumberOfComponents();
1034       std::vector<vtkFloatingPointType> aTuple(aNbComp);
1035       aFieldArray->GetTuple(aVtkId, &aTuple[0]);
1036       
1037       aStr<<"\nData: {";
1038       int anId = 0;
1039       while(anId < aNbComp){
1040         vtkFloatingPointType aComp = aTuple[anId++];
1041         aStr<<aComp;
1042         if(anId < aNbComp)
1043           aStr<<"; ";
1044       }
1045       aStr<<"}";
1046     }
1047     //
1048     // myTextActor
1049     std::string aString = aStr.str();
1050     myTextActor->SetModePosition(myPickingSettings->GetInfoWindowPosition());
1051     myTextActor->SetTransparency(myPickingSettings->GetInfoWindowTransparency());
1052     myTextActor->SetWorldPoint(aWorldCoord);
1053     myTextActor->SetText(aString.c_str());
1054     myTextActor->SetVisibility(anIsVisible && theIsHighlight);
1055     //
1056     // myCellActor
1057     if(myPickingSettings->GetDisplayParentMesh()){
1058       const VISU::PGaussPtsIDMapper& aGaussPtsIDMapper = 
1059         myGaussPointsPL->GetGaussPtsIDMapper();
1060       VISU::TNamedIDMapper* aParent = aGaussPtsIDMapper->GetParent();
1061       
1062       myCellSource->Reset();
1063       myCellSource->Modified(); // a VTK bug
1064       vtkUnstructuredGrid* aDataSet = aParent->GetUnstructuredGridOutput();
1065       myCellSource->SetPoints(aDataSet->GetPoints());
1066       
1067       VISU::TGaussPointID aGaussPointID = aGaussPtsIDMapper->GetObjID(anObjId);
1068       vtkIdType aCellID = aGaussPointID.first;
1069       vtkCell* aCell = aParent->GetElemCell(aCellID);
1070       myCellSource->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
1071       myCellActor->SetVisibility(anIsVisible && theIsHighlight);
1072       myCellActor->SetRepresentation(VTK_WIREFRAME);
1073     }
1074   }
1075 }
1076
1077
1078 //----------------------------------------------------------------
1079 void
1080 VISU_GaussPtsAct
1081 ::SetPickingSettings(VISU_PickingSettings* thePickingSettings)
1082 {
1083   if(myPickingSettings == thePickingSettings)
1084     return;
1085
1086   if(myPickingSettings)
1087     myPickingSettings->RemoveObserver(myEventCallbackCommand.GetPointer());
1088
1089   myPickingSettings = thePickingSettings;
1090
1091   if(thePickingSettings)
1092   {
1093     thePickingSettings->AddObserver(VISU::UpdatePickingSettingsEvent, 
1094                                     myEventCallbackCommand.GetPointer(), 
1095                                     myPriority);
1096     this->UpdatePickingSettings();
1097   }
1098 }
1099
1100 void
1101 VISU_GaussPtsAct
1102 ::UpdatePickingSettings()
1103 {
1104   if(!myPickingSettings || myPickingSettings->GetInitial())
1105     return;
1106
1107   myTextActor->SetModePosition(myPickingSettings->GetInfoWindowPosition());
1108   myTextActor->SetTransparency(myPickingSettings->GetInfoWindowTransparency());
1109
1110   vtkFloatingPointType aHeight = myGaussPointsPL->GetMaxPointSize()*myPickingSettings->GetPyramidHeight();
1111   vtkFloatingPointType aCursorSize = myPickingSettings->GetCursorSize();
1112   myCursorPyramid->SetPreferences(aHeight,aCursorSize);
1113   myCursorPyramidSelected->SetPreferences(aHeight,aCursorSize);
1114
1115   myHighlightActor->GetProperty()->SetColor( myPickingSettings->GetColor() );
1116   myPointPicker->SetTolerance( myPickingSettings->GetPointTolerance() );
1117
1118   Highlight(isHighlighted());
1119
1120   Update();
1121 }
1122
1123 //----------------------------------------------------------------
1124 void
1125 VISU_GaussPtsAct
1126 ::SetInsideCursorSettings(VISU_InsideCursorSettings* theInsideCursorSettings)
1127 {
1128   if(myInsideCursorSettings == theInsideCursorSettings)
1129     return;
1130
1131   if(myInsideCursorSettings)
1132     myInsideCursorSettings->RemoveObserver(myEventCallbackCommand.GetPointer());
1133
1134   myInsideCursorSettings = theInsideCursorSettings;
1135
1136   if(theInsideCursorSettings){
1137     theInsideCursorSettings->AddObserver(VISU::UpdateInsideSettingsEvent, 
1138                                          myEventCallbackCommand.GetPointer(), 
1139                                          myPriority);
1140     UpdateInsideCursorSettings();
1141   }
1142 }
1143
1144 void
1145 VISU_GaussPtsAct
1146 ::UpdateInsideCursorSettings()
1147 {
1148   UpdateInsideCursorSettings( myDeviceActor );
1149 }
1150
1151 void
1152 VISU_GaussPtsAct
1153 ::UpdateInsideCursorSettings( PDeviceActor theActor )
1154 {
1155   if(!myInsideCursorSettings || myInsideCursorSettings->GetInitial())
1156     return;
1157
1158   VISU_GaussPointsPL* aPipeline = theActor->GetPipeLine();
1159
1160   vtkImplicitFunction* anImplicitFunction = aPipeline->GetImplicitFunction();
1161
1162   aPipeline->ShallowCopy(GetGaussPointsPL(), true);
1163
1164   aPipeline->SetImplicitFunction(anImplicitFunction); // To restore
1165
1166   aPipeline->SetPrimitiveType( myInsideCursorSettings->GetPrimitiveType() );
1167   aPipeline->SetClamp( myInsideCursorSettings->GetClamp() );
1168   aPipeline->SetImageData( myInsideCursorSettings->GetTexture() );
1169   aPipeline->SetAlphaThreshold( myInsideCursorSettings->GetAlphaThreshold() );
1170   aPipeline->SetResolution( myInsideCursorSettings->GetResolution() );
1171   aPipeline->SetMinSize( myInsideCursorSettings->GetMinSize() );
1172   aPipeline->SetMaxSize( myInsideCursorSettings->GetMaxSize() );
1173   aPipeline->SetMagnification( myInsideCursorSettings->GetMagnification() );
1174   aPipeline->SetMagnificationIncrement( myInsideCursorSettings->GetIncrement() );
1175
1176   if( myInsideCursorSettings->GetPrimitiveType() != VISU_OpenGLPointSpriteMapper::GeomSphere )
1177     theActor->GetProperty()->SetRepresentation( VTK_POINTS );
1178   else
1179     theActor->GetProperty()->SetRepresentation( VTK_SURFACE );
1180
1181   aPipeline->Update();
1182
1183   Highlight(isHighlighted());
1184
1185   Update();
1186 }
1187
1188 //----------------------------------------------------------------------------
1189 unsigned long int 
1190 VISU_GaussPtsAct
1191 ::GetMTime()
1192 {
1193   unsigned long int aTime = Superclass::GetMTime();
1194   aTime = std::max(aTime, myGaussPointsPL->GetPointSpriteMapper()->GetMTime() );
1195   return aTime;
1196 }
1197
1198 //==============================================================================
1199 vtkStandardNewMacro(VISU_GaussPtsAct1);
1200
1201
1202 //----------------------------------------------------------------------------
1203 VISU_GaussPtsAct1
1204 ::VISU_GaussPtsAct1():
1205   myInsideDeviceActor(VISU_GaussPtsDeviceActor::New()),
1206   myOutsideDeviceActor(VISU_GaussPtsDeviceActor::New()),
1207   myOutsideCursorSettings(NULL)
1208 {
1209   if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::VISU_GaussPtsAct1 - this = "<<this);
1210
1211   myEventCallbackCommand->SetCallback(VISU_GaussPtsAct1::ProcessEvents);
1212
1213   myInsideDeviceActor->SetVisibility(false);
1214   myInsideDeviceActor->SetPickable(false);
1215   myInsideDeviceActor->Delete();
1216
1217   myOutsideDeviceActor->SetVisibility(false);
1218   myOutsideDeviceActor->SetPickable(false);
1219   myOutsideDeviceActor->Delete();
1220 }
1221
1222 VISU_GaussPtsAct1
1223 ::~VISU_GaussPtsAct1()
1224 {
1225   if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::~VISU_GaussPtsAct1 - this = "<<this);
1226
1227   SetOutsideCursorSettings(NULL);
1228 }
1229
1230
1231 //----------------------------------------------------------------------------
1232 void
1233 VISU_GaussPtsAct1
1234 ::ShallowCopyPL(VISU_PipeLine* thePipeLine)
1235 {
1236   if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::ShallowCopyPL - this = "<<this);
1237
1238   Superclass::ShallowCopyPL(thePipeLine);
1239
1240   UpdateOutsideCursorSettings();
1241 }
1242
1243
1244 //----------------------------------------------------------------------------
1245 void
1246 VISU_GaussPtsAct1
1247 ::AddToRender(vtkRenderer* theRenderer)
1248 {
1249   Superclass::AddToRender(theRenderer);
1250
1251   myInsideDeviceActor->AddToRender(theRenderer);
1252   myOutsideDeviceActor->AddToRender(theRenderer);
1253 }
1254
1255 void 
1256 VISU_GaussPtsAct1
1257 ::RemoveFromRender(vtkRenderer* theRenderer)
1258 {
1259   myInsideDeviceActor->RemoveFromRender(theRenderer);
1260   myOutsideDeviceActor->RemoveFromRender(theRenderer);
1261
1262   Superclass::RemoveFromRender(theRenderer);
1263 }
1264
1265 void 
1266 VISU_GaussPtsAct1
1267 ::SetTransform(VTKViewer_Transform* theTransform)
1268 {
1269   Superclass::SetTransform(theTransform);
1270
1271   myInsideDeviceActor->SetTransform(theTransform);
1272   myOutsideDeviceActor->SetTransform(theTransform);
1273 }
1274
1275
1276 //----------------------------------------------------------------------------
1277 void
1278 VISU_GaussPtsAct1
1279 ::SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl)
1280 {
1281   if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::SetWidgetCtrl - this = "<<this);
1282
1283   if(myWidgetCtrl == theWidgetCtrl){
1284     return;
1285   }
1286
1287   if(myWidgetCtrl){
1288     myInsideDeviceActor->GetPipeLine()->SetImplicitFunction(NULL);
1289     myInsideDeviceActor->SetVisibility(false);
1290
1291     myOutsideDeviceActor->GetPipeLine()->SetImplicitFunction(NULL);  
1292     myOutsideDeviceActor->SetVisibility(false);
1293   }
1294
1295   Superclass::SetWidgetCtrl(theWidgetCtrl);
1296
1297   if(theWidgetCtrl){
1298     myInsideDeviceActor->GetPipeLine()->SetImplicitFunction(theWidgetCtrl->ImplicitFunction());
1299     myInsideDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1300
1301     myOutsideDeviceActor->GetPipeLine()->SetImplicitFunction(theWidgetCtrl->ImplicitFunction());  
1302     myOutsideDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1303   }
1304 }
1305
1306
1307 //----------------------------------------------------------------------------
1308 void
1309 VISU_GaussPtsAct1
1310 ::SetMapperInput(vtkDataSet* theDataSet) 
1311 {
1312   if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::SetMapperInput - this = "<<this);
1313
1314   Superclass::SetMapperInput(theDataSet);
1315
1316   if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){
1317     myInsideDeviceActor->SetPipeLine(aPipeLine);
1318     aPipeLine->Delete();
1319   }
1320
1321   if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){
1322     myOutsideDeviceActor->SetPipeLine(aPipeLine);
1323     aPipeLine->Delete();
1324
1325     aPipeLine->SetExtractBoundaryCells(true);
1326     aPipeLine->SetExtractInside(true);
1327   }
1328 }
1329
1330
1331 //----------------------------------------------------------------------------
1332 vtkFloatingPointType
1333 VISU_GaussPtsAct1
1334 ::GetRadius(vtkIdType theObjID,
1335             vtkIdType theVTKID,
1336             vtkDataArray *theScalarArray)
1337 {
1338   VISU_GaussPointsPL* aPipeLine = myDeviceActor->GetPipeLine();
1339   if(IsSegmentationEnabled()){
1340     if(myInsideDeviceActor->GetPipeLine()->GetNodeVTKID(theObjID) < 0)
1341       aPipeLine = myOutsideDeviceActor->GetPipeLine();
1342     else
1343       aPipeLine = myInsideDeviceActor->GetPipeLine();
1344   }
1345   return ::GetRadius(theVTKID,theScalarArray,aPipeLine);
1346 }
1347
1348
1349 //----------------------------------------------------------------------------
1350 vtkFloatingPointType 
1351 VISU_GaussPtsAct1
1352 ::GetMagnification(vtkIdType theObjID)
1353 {
1354   VISU_GaussPointsPL* aPipeLine = myDeviceActor->GetPipeLine();
1355   if(IsSegmentationEnabled()){
1356     if(myInsideDeviceActor->GetPipeLine()->GetNodeVTKID(theObjID) < 0)
1357       aPipeLine = myOutsideDeviceActor->GetPipeLine();
1358     else
1359       aPipeLine = myInsideDeviceActor->GetPipeLine();
1360   }
1361   return aPipeLine->GetMagnification();
1362 }
1363
1364
1365 //----------------------------------------------------------------------------
1366 vtkFloatingPointType 
1367 VISU_GaussPtsAct1
1368 ::GetClamp(vtkIdType theObjID)
1369 {
1370   if(IsSegmentationEnabled()){
1371     if(myInsideDeviceActor->GetPipeLine()->GetNodeVTKID(theObjID) < 0)
1372       return ::GetClamp(myOutsideDeviceActor->GetPipeLine());
1373     else
1374       return ::GetClamp(myInsideDeviceActor->GetPipeLine());
1375   }
1376   return Superclass::GetClamp(theObjID);
1377 }
1378
1379
1380 //----------------------------------------------------------------
1381 void 
1382 VISU_GaussPtsAct1
1383 ::Connect(VISU_GaussPtsAct2* theActor)
1384 {
1385   mySetVisibilitySignal.connect(boost::bind(&VISU_GaussPtsAct2::SetVisibility,theActor,_1));
1386 }
1387
1388 void
1389 VISU_GaussPtsAct1
1390 ::SetVisibility(int theMode)
1391 {
1392   if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::SetVisibility - this = "<<this);
1393
1394   Superclass::SetVisibility(theMode);
1395
1396   bool aVisisbility = GetVisibility();
1397   bool anIsSegementation = IsSegmentationEnabled();
1398   myDeviceActor->SetVisibility(aVisisbility && !anIsSegementation);
1399   myInsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
1400   myOutsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
1401
1402   mySetVisibilitySignal(GetVisibility());
1403 }
1404
1405 //----------------------------------------------------------------
1406 void
1407 VISU_GaussPtsAct1
1408 ::UpdateInsideCursorSettings()
1409 {
1410   Superclass::UpdateInsideCursorSettings( myInsideDeviceActor );
1411 }
1412
1413 //----------------------------------------------------------------
1414 void
1415 VISU_GaussPtsAct1
1416 ::SetOutsideCursorSettings(VISU_OutsideCursorSettings* theOutsideCursorSettings)
1417 {
1418   if(myOutsideCursorSettings == theOutsideCursorSettings)
1419     return;
1420
1421   if(myOutsideCursorSettings)
1422     myOutsideCursorSettings->RemoveObserver(myEventCallbackCommand.GetPointer());
1423
1424   myOutsideCursorSettings = theOutsideCursorSettings;
1425
1426   if(theOutsideCursorSettings)
1427   {
1428     theOutsideCursorSettings->AddObserver(VISU::UpdateOutsideSettingsEvent, 
1429                                           myEventCallbackCommand.GetPointer(), 
1430                                           myPriority);
1431     UpdateOutsideCursorSettings();
1432   }
1433 }
1434
1435 void
1436 VISU_GaussPtsAct1
1437 ::UpdateOutsideCursorSettings()
1438 {
1439   if(!myOutsideCursorSettings || myOutsideCursorSettings->GetInitial())
1440     return;
1441
1442   VISU_GaussPointsPL* aPipeline = myOutsideDeviceActor->GetPipeLine();
1443
1444   vtkImplicitFunction* anImplicitFunction = aPipeline->GetImplicitFunction();
1445   vtkFloatingPointType aMagnification = aPipeline->GetMagnification();
1446
1447   aPipeline->ShallowCopy(GetGaussPointsPL(), true);
1448
1449   aPipeline->SetImplicitFunction(anImplicitFunction); // To restore
1450   aPipeline->SetExtractBoundaryCells(true);
1451   aPipeline->SetExtractInside(true);
1452   aPipeline->SetMagnification( aMagnification );
1453
1454   aPipeline->SetPrimitiveType( myOutsideCursorSettings->GetPrimitiveType() );
1455
1456   if( myOutsideCursorSettings->GetPrimitiveType() != VISU_OpenGLPointSpriteMapper::GeomSphere )
1457     myOutsideDeviceActor->GetProperty()->SetRepresentation( VTK_POINTS );
1458   else
1459     myOutsideDeviceActor->GetProperty()->SetRepresentation( VTK_SURFACE );
1460
1461   aPipeline->SetClamp( myOutsideCursorSettings->GetClamp() );
1462   aPipeline->SetImageData( myOutsideCursorSettings->GetTexture() );
1463   aPipeline->SetAlphaThreshold( myOutsideCursorSettings->GetAlphaThreshold() );
1464   aPipeline->SetResolution( myOutsideCursorSettings->GetResolution() );
1465   aPipeline->SetSize( myOutsideCursorSettings->GetSize() );
1466   aPipeline->SetMagnification( myOutsideCursorSettings->GetMagnification() );
1467   aPipeline->SetMagnificationIncrement( myOutsideCursorSettings->GetIncrement() );
1468
1469   if( myOutsideCursorSettings->GetUniform() )
1470   {
1471     myOutsideDeviceActor->GetPointSpriteMapper()->ScalarVisibilityOff();
1472     myOutsideDeviceActor->GetPointSpriteMapper()->SetPointSpriteMode( 1 ); // Geometry mode
1473     myOutsideDeviceActor->GetProperty()->SetColor( myOutsideCursorSettings->GetColor() );
1474   }
1475   else
1476   {
1477     myOutsideDeviceActor->GetPointSpriteMapper()->SetPointSpriteMode( 2 ); // Outside cursor mode
1478     myOutsideDeviceActor->GetPointSpriteMapper()->SetColorModeToMapScalars();
1479     myOutsideDeviceActor->GetPointSpriteMapper()->ScalarVisibilityOn();
1480   }
1481
1482   aPipeline->Update();
1483
1484   Highlight(isHighlighted());
1485
1486   Update();
1487 }
1488
1489
1490 //----------------------------------------------------------------
1491 void 
1492 VISU_GaussPtsAct1
1493 ::ProcessEvents(vtkObject* theObject, 
1494                 unsigned long theEvent,
1495                 void* theClientData, 
1496                 void* theCallData)
1497 {
1498   if(vtkObject* anObject = reinterpret_cast<vtkObject*>(theClientData))
1499     if(VISU_GaussPtsAct1* self = dynamic_cast<VISU_GaussPtsAct1*>(anObject))
1500       if(theEvent == VISU::UpdateOutsideSettingsEvent)
1501         self->UpdateOutsideCursorSettings();
1502
1503   Superclass::ProcessEvents(theObject,theEvent,theClientData,theCallData);
1504 }
1505
1506 void
1507 VISU_GaussPtsAct1
1508 ::OnInteractorEvent(unsigned long theEvent)
1509 {
1510   switch(theEvent){
1511   case vtkCommand::StartInteractionEvent: 
1512     myDeviceActor->SetVisibility(GetVisibility());
1513     myInsideDeviceActor->SetVisibility(false);
1514     myOutsideDeviceActor->SetVisibility(false);
1515     break;
1516   case vtkCommand::EnableEvent: 
1517   case vtkCommand::DisableEvent:
1518   case vtkCommand::EndInteractionEvent: {
1519     bool aVisisbility = GetVisibility();
1520     bool anIsSegementation = IsSegmentationEnabled();
1521     myDeviceActor->SetVisibility(aVisisbility && !anIsSegementation);
1522     myInsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
1523     myOutsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
1524     break;
1525   }
1526   default:
1527     break;
1528   }
1529   
1530   Superclass::OnInteractorEvent(theEvent);
1531 }
1532
1533 //----------------------------------------------------------------------------
1534 unsigned long int
1535 VISU_GaussPtsAct1
1536 ::GetMemorySize()
1537 {
1538   unsigned long int aSize = Superclass::GetMemorySize();
1539   if(IsSegmentationEnabled()){
1540     aSize += myInsideDeviceActor->GetMemorySize();
1541     aSize += myOutsideDeviceActor->GetMemorySize();
1542   }
1543   return aSize;
1544 }
1545
1546
1547
1548 //==============================================================================
1549 vtkStandardNewMacro(VISU_GaussPtsAct2);
1550
1551
1552 //----------------------------------------------------------------------------
1553 VISU_GaussPtsAct2
1554 ::VISU_GaussPtsAct2()
1555 {
1556   if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::VISU_GaussPtsAct2 - this = "<<this);
1557   myDeviceActor->SetVisibility(false);
1558 }
1559
1560 VISU_GaussPtsAct2
1561 ::~VISU_GaussPtsAct2()
1562 {
1563   if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::~VISU_GaussPtsAct2 - this = "<<this);
1564 }
1565
1566
1567 //----------------------------------------------------------------------------
1568 void
1569 VISU_GaussPtsAct2
1570 ::ShallowCopyPL(VISU_PipeLine* thePipeLine)
1571 {
1572   if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::ShallowCopyPL - this = "<<this);
1573
1574   Superclass::ShallowCopyPL(thePipeLine);
1575 }
1576
1577
1578 //----------------------------------------------------------------------------
1579 void
1580 VISU_GaussPtsAct2
1581 ::SetMapperInput(vtkDataSet* theDataSet) 
1582 {
1583   if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::SetMapperInput - this = "<<this);
1584
1585   if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){
1586     myDeviceActor->SetPipeLine(aPipeLine);
1587     myCurrentPL = aPipeLine;
1588     aPipeLine->Delete();
1589
1590     myMapper->SetInput(myCurrentPL->GetPickableDataSet());
1591     SetMapper(myMapper.GetPointer());
1592   }
1593 }
1594
1595 //----------------------------------------------------------------------------
1596 void
1597 VISU_GaussPtsAct2
1598 ::SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl)
1599 {
1600   if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::SetWidgetCtrl - this = "<<this);
1601
1602   if(myWidgetCtrl == theWidgetCtrl)
1603     return;
1604
1605   if(myWidgetCtrl){
1606     theWidgetCtrl->RemoveObserver(myEventCallbackCommand.GetPointer());
1607     myDeviceActor->GetPipeLine()->SetImplicitFunction(NULL);
1608     myDeviceActor->SetVisibility(false);
1609   }
1610
1611   Superclass::SetWidgetCtrl(theWidgetCtrl);
1612
1613   if(theWidgetCtrl){
1614     myDeviceActor->GetPipeLine()->SetImplicitFunction(theWidgetCtrl->ImplicitFunction());
1615     myDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1616   }
1617 }
1618
1619
1620 //----------------------------------------------------------------------------
1621 unsigned long int
1622 VISU_GaussPtsAct2
1623 ::GetMemorySize()
1624 {
1625   if(IsSegmentationEnabled())
1626     return Superclass::GetMemorySize();
1627   return 0;
1628 }
1629
1630
1631 //----------------------------------------------------------------------------
1632 void
1633 VISU_GaussPtsAct2
1634 ::SetVisibility(int theMode)
1635 {
1636   if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::SetVisibility - this = "<<this);
1637
1638   Superclass::SetVisibility(theMode);
1639
1640   myDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1641 }
1642
1643 void
1644 VISU_GaussPtsAct2
1645 ::OnInteractorEvent(unsigned long theEvent)
1646 {
1647   switch(theEvent){
1648   case vtkCommand::EnableEvent: 
1649   case vtkCommand::DisableEvent:
1650     myDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1651     if(theEvent == vtkCommand::EnableEvent)
1652       Update();
1653     break;
1654   case vtkCommand::EndInteractionEvent:
1655     Update();
1656     break;
1657   default:
1658     break;
1659   }
1660   Superclass::OnInteractorEvent(theEvent);
1661 }