1 // VISU OBJECT : interactive object for VISU entities implementation
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : VISU_MeshAct.hxx
25 // Author : Laurent CORNABE with the help of Nicolas REJNERI
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"
39 #include "SALOME_ExtractGeometry.h"
41 #include "VISU_Event.h"
42 #include "SVTK_Actor.h"
44 #include <vtkCamera.h>
45 #include <vtkRenderer.h>
46 #include <vtkPointPicker.h>
47 #include <vtkScalarBarWidget.h>
48 #include <vtkScalarBarActor.h>
49 #include <vtkTextMapper.h>
50 #include <vtkTextProperty.h>
52 #include <vtkCellData.h>
53 #include <vtkPointData.h>
55 #include <vtkDataArray.h>
56 #include <vtkFloatArray.h>
58 #include <vtkSphereSource.h>
59 #include <vtkPolyDataMapper.h>
60 #include <vtkPolyData.h>
63 #include <vtkObjectFactory.h>
64 #include <vtkCallbackCommand.h>
65 #include <vtkInteractorStyle.h>
66 #include <vtkRenderWindowInteractor.h>
67 #include <vtkOutlineSource.h>
70 #include <boost/bind.hpp>
72 #include <vtkUnstructuredGrid.h>
73 #include <vtkDataSetMapper.h>
74 #include <vtkRenderWindow.h>
75 #include <vtkCellArray.h>
79 #include <vtkViewport.h>
81 #include "utilities.h"
84 static int MYDEBUG = 0;
85 static int MYDEBUG1 = 0;
86 static int MYDEBUG2 = 0;
88 static int MYDEBUG = 0;
89 static int MYDEBUG1 = 0;
90 static int MYDEBUG2 = 0;
94 //============================================================================
95 vtkStandardNewMacro(VISU_GaussPtsAct);
97 //----------------------------------------------------------------------------
100 myEventCallbackCommand(vtkCallbackCommand::New()),
102 myDeviceActor(VISU_GaussPtsDeviceActor::New()),
104 myGaussPointsPL(NULL),
105 myLastObjPointID(-1),
106 myTextActor(VISU_FramedTextActor::New()),
107 myCursorPyramid(VISU_CursorPyramid::New()),
108 myCursorPyramidSelected(VISU_CursorPyramid::New()),
109 myCellSource(vtkUnstructuredGrid::New()),
110 myCellActor(SVTK_Actor::New()),
111 myScalarBarCtrl(VISU_ScalarBarCtrl::New()),
112 myBarVisibility(true),
113 myPickingSettings(NULL),
114 myInsideCursorSettings(NULL),
117 if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::VISU_GaussPtsAct - this = "<<this);
119 myEventCallbackCommand->Delete();
120 myDeviceActor->Delete();
121 myTextActor->Delete();
123 myCursorPyramid->Delete();
124 myCursorPyramid->SetPickable(0);
125 myCursorPyramid->SetVisibility(0);
127 myCursorPyramidSelected->Delete();
128 myCursorPyramidSelected->SetPickable(0);
129 myCursorPyramidSelected->SetVisibility(0);
131 myCellSource->Delete();
132 myCellActor->Delete();
134 myEventCallbackCommand->SetClientData(this);
135 myEventCallbackCommand->SetCallback(VISU_GaussPtsAct::ProcessEvents);
137 myDeviceActor->SetProperty(GetProperty());
138 myDeviceActor->SetVisibility(true);
139 myDeviceActor->SetPickable(false);
141 myTextActor->SetVisibility(false);
142 myTextActor->SetPickable(false);
144 myCellSource->Allocate();
145 myCellActor->Initialize();
146 myCellActor->SetRepresentation(VTK_WIREFRAME);
147 myCellActor->SetSource(myCellSource.GetPointer());
149 myCellActor->SetVisibility(0);
150 myCellActor->SetPickable(0);
151 myCellActor->GetProperty()->SetAmbient(1.0);
152 myCellActor->GetProperty()->SetDiffuse(0.0);
154 myScalarBarCtrl->Delete();
158 ::~VISU_GaussPtsAct()
160 if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::~VISU_GaussPtsAct - this = "<<this);
163 SetPickingSettings(NULL);
164 SetInsideCursorSettings(NULL);
168 //----------------------------------------------------------------------------
171 ::SetPipeLine(VISU_PipeLine* thePipeLine)
173 if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::SetPipeLine - this = "<<this);
175 myGaussPointsPL = dynamic_cast<VISU_GaussPointsPL*>(thePipeLine);
177 Superclass::SetPipeLine(thePipeLine);
184 return myGaussPointsPL.GetPointer();
189 ::ShallowCopyPL(VISU_PipeLine* thePipeLine)
191 if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::ShallowCopyPL - this = "<<this);
193 Superclass::ShallowCopyPL(thePipeLine);
195 UpdateInsideCursorSettings();
197 Highlight(isHighlighted());
201 //----------------------------------------------------------------------------
207 return Superclass::GetMapper();
214 return GetMapper()->GetBounds();
221 return GetMapper()->GetInput();
232 //----------------------------------------------------------------------------
235 ::AddToRender(vtkRenderer* theRenderer)
237 if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::AddToRender - this = "<<this);
239 Superclass::AddToRender(theRenderer);
241 myDeviceActor->AddToRender(theRenderer);
243 theRenderer->AddActor(myTextActor.GetPointer());
244 theRenderer->AddActor(myCellActor.GetPointer());
246 myCursorPyramid->AddToRender(theRenderer);
247 myCursorPyramidSelected->AddToRender(theRenderer);
248 myScalarBarCtrl->AddToRender(theRenderer);
253 ::RemoveFromRender(vtkRenderer* theRenderer)
255 if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::RemoveFromRender - this = "<<this);
257 Superclass::RemoveFromRender(theRenderer);
259 myDeviceActor->RemoveFromRender(theRenderer);
261 theRenderer->RemoveActor(myTextActor.GetPointer());
262 theRenderer->RemoveActor(myCellActor.GetPointer());
264 myCursorPyramid->RemoveFromRender(theRenderer);
265 myCursorPyramidSelected->RemoveFromRender(theRenderer);
266 myScalarBarCtrl->RemoveFromRender(theRenderer);
271 ::SetTransform(VTKViewer_Transform* theTransform)
273 Superclass::SetTransform(theTransform);
275 myDeviceActor->SetTransform(theTransform);
280 ::RenderOpaqueGeometry(vtkViewport *viewport)
287 ::RenderTranslucentGeometry(vtkViewport *viewport)
293 //----------------------------------------------------------------------------
296 ::SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl)
298 if(myWidgetCtrl == theWidgetCtrl)
302 MESSAGE("VISU_GaussPtsAct::SetWidgetCtrl - this = "<<this<<"; theWidget = "<<theWidgetCtrl);
305 myWidgetCtrl->RemoveObserver(myEventCallbackCommand.GetPointer());
308 theWidgetCtrl->AddObserver(vtkCommand::EnableEvent,
309 myEventCallbackCommand.GetPointer(),
311 theWidgetCtrl->AddObserver(vtkCommand::DisableEvent,
312 myEventCallbackCommand.GetPointer(),
314 theWidgetCtrl->AddObserver(vtkCommand::StartInteractionEvent,
315 myEventCallbackCommand.GetPointer(),
317 theWidgetCtrl->AddObserver(vtkCommand::EndInteractionEvent,
318 myEventCallbackCommand.GetPointer(),
322 myWidgetCtrl = theWidgetCtrl;
327 ::GetChangeMagnification()
329 return myChangeMagnification;
334 ::ChangeMagnification( bool up )
336 myEventCallbackCommand->SetAbortFlag(1);
338 float aMagnification = myInsideCursorSettings->GetMagnification();
339 float anIncrement = myInsideCursorSettings->GetIncrement();
340 float coefficient = up ? anIncrement : 1 / anIncrement;
342 myInsideCursorSettings->SetMagnification( aMagnification * coefficient );
343 myInsideCursorSettings->InvokeEvent(VISU::UpdateFromSettingsEvent,NULL);
348 //----------------------------------------------------------------------------
352 CreatePipeLine(VISU_GaussPointsPL* thePipeLine)
354 VISU_GaussPointsPL* aPipeLine = VISU_GaussPointsPL::New();
355 aPipeLine->SetGaussPtsIDMapper(thePipeLine->GetGaussPtsIDMapper());
356 aPipeLine->ShallowCopy(thePipeLine);
364 ::SetMapperInput(vtkDataSet* theDataSet)
366 if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::SetMapperInput - this = "<<this);
368 myDeviceActor->SetPipeLine(GetGaussPointsPL());
369 myCurrentPL = myDeviceActor->GetPipeLine();
371 myMapper->SetInput(myCurrentPL->GetPickableDataSet());
372 SetMapper(myMapper.GetPointer());
376 //----------------------------------------------------------------------------
381 GetRadius(vtkIdType theVTKID,
382 vtkDataArray *theScalarArray,
383 VISU_GaussPointsPL* theGaussPointsPL)
386 if(theGaussPointsPL->GetPSMapper()->GetPointSpriteMode() == 1) // Geometry mode
387 aRadius *= theGaussPointsPL->GetSize() * theGaussPointsPL->GetAverageCellSize();
388 else if(theGaussPointsPL->GetBicolor()){
389 float aVal = theScalarArray->GetTuple1(theVTKID);
391 aRadius *= theGaussPointsPL->GetMaxSize();
393 aRadius *= theGaussPointsPL->GetMinSize();
394 aRadius *= theGaussPointsPL->GetAverageCellSize();
396 aRadius *= theGaussPointsPL->GetPointSize(theVTKID,theScalarArray);
404 ::GetRadius(vtkIdType theObjID,
406 vtkDataArray *theScalarArray)
408 return ::GetRadius(theVTKID,theScalarArray,myDeviceActor->GetPipeLine());
411 //----------------------------------------------------------------------------
414 ::GetMagnification(vtkIdType theObjID)
416 return myDeviceActor->GetPipeLine()->GetMagnification();
420 //----------------------------------------------------------------------------
425 GetClamp(VISU_GaussPointsPL* theGaussPointsPL)
427 float aClamp = theGaussPointsPL->GetClamp();
428 if(theGaussPointsPL->GetPrimitiveType() == VISU_OpenGLPointSpriteMapper::GeomSphere)
436 ::GetClamp(vtkIdType theObjID)
438 return ::GetClamp(myDeviceActor->GetPipeLine());
442 //----------------------------------------------------------------------------
445 ::SetFactory(VISU::TActorFactory* theActorFactory)
447 using namespace VISU;
448 myGaussPtsActorFactory = dynamic_cast<TGaussPtsActorFactory*>(theActorFactory);
449 myUpdatePrs3dSignal.connect(boost::bind(&TGaussPtsActorFactory::UpdateFromActor,
450 myGaussPtsActorFactory,
452 Superclass::SetFactory(theActorFactory);
455 VISU::TGaussPtsActorFactory*
457 ::GetGaussPtsFactory()
459 return myGaussPtsActorFactory;
463 //----------------------------------------------------------------------------
466 ::SetVisibility(int theMode)
468 Superclass::SetVisibility(theMode);
469 myScalarBarCtrl->SetVisibility(theMode);
470 Highlight(isHighlighted());
475 ::IsSegmentationEnabled()
477 return myWidgetCtrl && myWidgetCtrl->GetEnabled();
481 //----------------------------------------------------------------------------
484 ::SetBarVisibility(bool theMode)
486 myBarVisibility = theMode;
487 myScalarBarCtrl->SetCtrlVisibility(theMode);
488 myScalarBarCtrl->SetVisibility(GetVisibility());
495 return myBarVisibility;
502 return myScalarBarCtrl.GetPointer();
505 //----------------------------------------------------------------------------
508 ::SetInteractor(vtkRenderWindowInteractor* theInteractor)
510 if(theInteractor == myInteractor)
514 myInteractor->RemoveObserver(myEventCallbackCommand.GetPointer());
517 theInteractor->AddObserver(vtkCommand::CharEvent,
518 myEventCallbackCommand.GetPointer(),
520 theInteractor->AddObserver(VISU::SetSMDecreaseMagnificationEvent,
521 myEventCallbackCommand.GetPointer(),
523 theInteractor->AddObserver(VISU::SetSMIncreaseMagnificationEvent,
524 myEventCallbackCommand.GetPointer(),
527 Superclass::SetInteractor(theInteractor);
531 //-------------------------------------------------------------------------
534 ::ProcessEvents(vtkObject* vtkNotUsed(theObject),
535 unsigned long theEvent,
537 void* vtkNotUsed(theCallData))
539 if(vtkObject* anObject = reinterpret_cast<vtkObject*>(theClientData))
540 if(VISU_GaussPtsAct* self = dynamic_cast<VISU_GaussPtsAct*>(anObject)) {
541 if(theEvent == VISU::UpdateInsideSettingsEvent)
542 self->UpdateInsideCursorSettings();
544 self->OnInteractorEvent(theEvent);
548 //-------------------------------------------------------------------------
551 ::OnInteractorEvent(unsigned long theEvent)
554 case vtkCommand::CharEvent: {
555 switch(myInteractor->GetKeyCode()) {
559 if( IsSegmentationEnabled() )
561 this->ChangeMagnification( myInteractor->GetShiftKey() );
565 myChangeMagnification = myInteractor->GetShiftKey();
571 if( IsSegmentationEnabled() && myWidgetCtrl->IsSphereActive() )
573 VISU_SphereWidget* aSphereWidget = myWidgetCtrl->GetSphereWidget();
574 aSphereWidget->ChangeRadius( myInteractor->GetShiftKey() );
575 myWidgetCtrl->InvokeEvent(vtkCommand::EndInteractionEvent,NULL);
576 myWidgetCtrl->GetInteractor()->Render();
583 myUpdatePrs3dSignal(this);
586 case VISU::SetSMDecreaseMagnificationEvent:
587 case VISU::SetSMIncreaseMagnificationEvent:
588 myChangeMagnification = theEvent == VISU::SetSMIncreaseMagnificationEvent;
589 myUpdatePrs3dSignal(this);
591 case VISU::UpdatePickingSettingsEvent:
592 UpdatePickingSettings();
594 case vtkCommand::EndInteractionEvent:
595 case vtkCommand::EnableEvent:
596 case vtkCommand::DisableEvent:
597 myCurrentPL->GetMapper()->Update();
598 Highlight(isHighlighted());
605 //----------------------------------------------------------------------------
606 bool VISU_GaussPtsAct::IsInfinitive()
608 if(vtkMapper* aMapper = myDeviceActor->GetMapper()){
609 if(vtkDataSet* aDataSet= aMapper->GetInput()){
611 myIsInfinite = aDataSet->GetNumberOfCells() < 2;
617 //----------------------------------------------------------------------------
620 ::PreHighlight(vtkInteractorStyle* theInteractorStyle,
621 SVTK_SelectionEvent* theSelectionEvent,
624 myPreHighlightActor->SetVisibility(false);
625 myCursorPyramid->SetVisibility(false);
627 if (!myBarVisibility) {
632 myLastObjPointID = -1;
634 Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
636 if(aSelectionMode == ActorSelection || !theIsHighlight)
637 return Superclass::PreHighlight(theInteractorStyle,
641 bool anIsChanged = (mySelectionMode != aSelectionMode);
642 bool anIsPreselected = myIsPreselected;
643 myIsPreselected = false;
645 if(aSelectionMode == GaussPointSelection && theIsHighlight){
646 myPointPicker->Pick(theSelectionEvent->myX,
647 theSelectionEvent->myY,
649 theInteractorStyle->GetCurrentRenderer());
651 if(myPointPicker->GetActor() != this)
652 return (anIsPreselected != myIsPreselected);
654 vtkIdType aVtkId = myPointPicker->GetPointId();
656 if(aVtkId >= 0 && mySelector->IsValid(this,aVtkId,true) && hasIO()){
657 vtkIdType anObjId = GetNodeObjId( aVtkId );
658 myIsPreselected = (anObjId >= 0);
660 anIsChanged = (myLastObjPointID != anObjId);
662 float* aNodeCoord = GetNodeCoord(anObjId);
663 vtkDataSet* aDataSet = GetInput();
664 vtkCellData* aCellData = aDataSet->GetCellData();
665 if(vtkDataArray *aScalarArray = aCellData->GetScalars()){
666 float aPyramidHeight = myPickingSettings->GetPyramidHeight();
667 aPyramidHeight = aPyramidHeight*myGaussPointsPL->GetMaxPointSize();
668 //float aColor[3] = myPreHighlightActor->GetProperty()->GetColor();
670 theInteractorStyle->GetCurrentRenderer()->GetBackground( aColor );
671 aColor[0] = 1. - aColor[0];
672 aColor[1] = 1. - aColor[1];
673 aColor[2] = 1. - aColor[2];
675 myCursorPyramid->Init(aPyramidHeight,
676 myPickingSettings->GetCursorSize(),
677 GetRadius(anObjId,aVtkId,aScalarArray),
678 GetMagnification(anObjId),
683 myLastObjPointID = anObjId;
685 myCursorPyramid->SetVisibility(true);
690 mySelectionMode = aSelectionMode;
691 anIsChanged |= (anIsPreselected != myIsPreselected);
697 //----------------------------------------------------------------------------
700 ChangeZoom(VISU_PickingSettings *thePickingSettings,
701 vtkInteractorStyle* theInteractorStyle,
702 int theInitialHasIndex,
703 SVTK_Selector* theSelector,
704 const Handle(SALOME_InteractiveObject)& theIO)
706 int aCurrentHasIndex = theSelector->HasIndex(theIO);
708 if(theInitialHasIndex + aCurrentHasIndex == 1){
709 vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer();
710 vtkCamera *aCamera = aRenderer->GetActiveCamera();
711 float aZoomFactor = thePickingSettings->GetZoomFactor();
712 double aScale = aCamera->GetParallelScale();
713 if (!theInitialHasIndex && aCurrentHasIndex) {
714 aCamera->SetParallelScale(aScale/aZoomFactor);
717 aCamera->SetParallelScale(aScale*aZoomFactor);
725 ::Highlight(vtkInteractorStyle* theInteractorStyle,
726 SVTK_SelectionEvent* theSelectionEvent,
729 myIsHighlighted = false;
730 Handle(SALOME_InteractiveObject) anIO = getIO();
731 int anInitialHasIndex = mySelector->HasIndex(anIO);
733 Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
735 if(!theIsHighlight && aSelectionMode == GaussPointSelection){
736 mySelector->RemoveIObject(anIO);
738 ChangeZoom(myPickingSettings,
741 mySelector.GetPointer(),
747 if (!myBarVisibility) {
751 if(aSelectionMode == ActorSelection){
752 return Superclass::Highlight(theInteractorStyle,
757 if(aSelectionMode == GaussPointSelection && !theSelectionEvent->myIsRectangle){
759 vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer();
760 myPointPicker->Pick(theSelectionEvent->myX,
761 theSelectionEvent->myY,
765 if(myPointPicker->GetActor() != this) {
766 mySelector->ClearIObjects();
768 ChangeZoom(myPickingSettings,
771 mySelector.GetPointer(),
777 vtkIdType aVtkId = myPointPicker->GetPointId();
778 if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId, true ) && hasIO()) {
779 vtkIdType anObjId = GetNodeObjId( aVtkId );
781 myIsHighlighted = true;
782 // Update the Selector
783 if(mySelector->IsSelected(myIO))
784 mySelector->AddOrRemoveIndex(myIO,anObjId,theSelectionEvent->myIsShift);
786 if(!theSelectionEvent->myIsShift){
787 mySelector->ClearIObjects();
789 mySelector->AddOrRemoveIndex(myIO,anObjId,theSelectionEvent->myIsShift);
790 mySelector->AddIObject(this);
793 float* aNodeCoord = GetNodeCoord(anObjId);
796 vtkRenderWindowInteractor* anInteractor = theInteractorStyle->GetInteractor();
797 float aDollyWas = anInteractor->GetDolly();
798 int aNumberOfFlyFramesWas = anInteractor->GetNumberOfFlyFrames();
800 anInteractor->SetDolly(0.);
801 anInteractor->SetNumberOfFlyFrames(myPickingSettings->GetStepNumber());
802 anInteractor->FlyTo(aRenderer,aNodeCoord);
803 aRenderer->ResetCameraClippingRange();
804 anInteractor->SetDolly(aDollyWas);
805 anInteractor->SetNumberOfFlyFrames(aNumberOfFlyFramesWas);
807 mySelectionMode = aSelectionMode;
809 ChangeZoom(myPickingSettings,
812 mySelector.GetPointer(),
817 }// if( anObjId >= 0 ) {
818 }//if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId, true ) && hasIO())
819 }//if(!theSelectionEvent->myIsRectangle){
821 ChangeZoom(myPickingSettings,
824 mySelector.GetPointer(),
830 //==================================================================
831 // function : Highlight
833 //==================================================================
836 ::Highlight(bool theIsHighlight)
838 if(!mySelector.GetPointer())
841 myOutlineActor->SetVisibility(false);
842 myTextActor->SetVisibility(false);
843 myCursorPyramidSelected->SetVisibility(false);
844 myCursorPyramid->SetVisibility(false);
845 myCellActor->SetVisibility(false);
846 GetScalarBarCtrl()->SetIsMarked(false);
847 GetScalarBarCtrl()->Update();
852 bool anIsVisible = GetVisibility();
854 Selection_Mode aSelectionMode = mySelector->SelectionMode();
856 if(aSelectionMode == ActorSelection)
857 Superclass::highlight(theIsHighlight);
858 else if(aSelectionMode != GaussPointSelection)
861 TColStd_IndexedMapOfInteger aMapIndex;
862 mySelector->GetIndex( getIO(), aMapIndex );
863 if(aMapIndex.Extent() != 1 || !myBarVisibility) {
867 std::ostringstream aStr;
868 int anObjId = aMapIndex(1);
869 aStr<<"Global ID: "<<anObjId;
871 vtkIdType aVtkId = GetNodeVTKID(anObjId);
873 float *aNodeCoord = GetNodeCoord(anObjId);
874 float aWorldCoord[4] = {aNodeCoord[0], aNodeCoord[1], aNodeCoord[2], 1.};
876 vtkDataSet* aDataSet = GetInput();
877 vtkCellData* aDataSetAttributes = aDataSet->GetCellData();
879 if(vtkDataArray* aScalarArray = aDataSetAttributes->GetScalars()){
880 float aVal = aScalarArray->GetTuple1(aVtkId);
882 GetScalarBarCtrl()->SetIsMarked(true);
883 GetScalarBarCtrl()->SetMarkValue(aVal);
884 GetScalarBarCtrl()->Update();
886 float aPyramidHeight = myPickingSettings->GetPyramidHeight();
887 aPyramidHeight = aPyramidHeight*myGaussPointsPL->GetMaxPointSize();
888 myCursorPyramidSelected->Init(aPyramidHeight,
889 myPickingSettings->GetCursorSize(),
890 GetRadius(anObjId,aVtkId,aScalarArray),
891 GetMagnification(anObjId),
894 myHighlightActor->GetProperty()->GetColor());
895 myCursorPyramidSelected->SetVisibility(anIsVisible && theIsHighlight);
897 const VISU::PGaussPtsIDMapper& aGaussPtsIDMapper =
898 myGaussPointsPL->GetGaussPtsIDMapper();
899 VISU::TNamedIDMapper* aParent = aGaussPtsIDMapper->GetParent();
901 VISU::TGaussPointID aGaussPointID = myGaussPointsPL->GetObjID(anObjId);
902 VISU::TCellID aCellID = aGaussPointID.first;
903 VISU::TLocalPntID aLocalPntID = aGaussPointID.second;
904 aStr<<"\nParentCellID: "<<aCellID;
905 std::string aParentName = aParent->GetElemName(aCellID);
906 if(aParentName != "") {
907 aStr<<"\nParentCellName: '"<<aParentName<<"'";
909 aStr<<"\nLocalPntID: "<<aLocalPntID;
910 aStr<<"\nScalar: "<<aVal;
913 if(vtkDataArray* aFieldArray = aDataSetAttributes->GetArray("VISU_FIELD")){
914 if(vtkFloatArray *aFloatArray = dynamic_cast<vtkFloatArray*>(aFieldArray)){
915 int aNbComp = aFloatArray->GetNumberOfComponents();
918 while(anId < aNbComp){
919 float aComp = aFloatArray->GetComponent(aVtkId,anId++);
929 std::string aString = aStr.str();
930 myTextActor->SetModePosition(myPickingSettings->GetInfoWindowPosition());
931 myTextActor->SetTransparency(myPickingSettings->GetInfoWindowTransparency());
932 myTextActor->SetWorldPoint(aWorldCoord);
933 myTextActor->SetText(aString.c_str());
934 myTextActor->SetVisibility(anIsVisible && theIsHighlight);
937 if(myPickingSettings->GetDisplayParentMesh()){
938 const VISU::PGaussPtsIDMapper& aGaussPtsIDMapper =
939 myGaussPointsPL->GetGaussPtsIDMapper();
940 VISU::TNamedIDMapper* aParent = aGaussPtsIDMapper->GetParent();
942 myCellSource->Reset();
943 myCellSource->Modified(); // a VTK bug
944 myCellSource->SetPoints(aParent->GetVTKOutput()->GetPoints());
946 VISU::TGaussPointID aGaussPointID = aGaussPtsIDMapper->GetObjID(anObjId);
947 vtkIdType aCellID = aGaussPointID.first;
948 vtkCell* aCell = aParent->GetElemCell(aCellID);
949 myCellSource->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
950 myCellActor->SetVisibility(anIsVisible && theIsHighlight);
951 myCellActor->SetRepresentation(VTK_WIREFRAME);
957 //----------------------------------------------------------------
960 ::SetPickingSettings(VISU_PickingSettings* thePickingSettings)
962 if(myPickingSettings == thePickingSettings)
965 if(myPickingSettings)
966 myPickingSettings->RemoveObserver(myEventCallbackCommand.GetPointer());
968 myPickingSettings = thePickingSettings;
970 if(thePickingSettings)
972 thePickingSettings->AddObserver(VISU::UpdatePickingSettingsEvent,
973 myEventCallbackCommand.GetPointer(),
975 this->UpdatePickingSettings();
981 ::UpdatePickingSettings()
983 if(!myPickingSettings || myPickingSettings->GetInitial())
986 myTextActor->SetModePosition(myPickingSettings->GetInfoWindowPosition());
987 myTextActor->SetTransparency(myPickingSettings->GetInfoWindowTransparency());
989 float aHeight = myGaussPointsPL->GetMaxPointSize()*myPickingSettings->GetPyramidHeight();
990 float aCursorSize = myPickingSettings->GetCursorSize();
991 myCursorPyramid->SetPreferences(aHeight,aCursorSize);
992 myCursorPyramidSelected->SetPreferences(aHeight,aCursorSize);
994 myHighlightActor->GetProperty()->SetColor( myPickingSettings->GetColor() );
995 myPointPicker->SetTolerance( myPickingSettings->GetPointTolerance() );
997 Highlight(isHighlighted());
1002 //----------------------------------------------------------------
1005 ::SetInsideCursorSettings(VISU_InsideCursorSettings* theInsideCursorSettings)
1007 if(myInsideCursorSettings == theInsideCursorSettings)
1010 if(myInsideCursorSettings)
1011 myInsideCursorSettings->RemoveObserver(myEventCallbackCommand.GetPointer());
1013 myInsideCursorSettings = theInsideCursorSettings;
1015 if(theInsideCursorSettings){
1016 theInsideCursorSettings->AddObserver(VISU::UpdateInsideSettingsEvent,
1017 myEventCallbackCommand.GetPointer(),
1019 UpdateInsideCursorSettings();
1025 ::UpdateInsideCursorSettings()
1027 UpdateInsideCursorSettings( myDeviceActor );
1032 ::UpdateInsideCursorSettings( PDeviceActor theActor )
1034 if(!myInsideCursorSettings || myInsideCursorSettings->GetInitial())
1037 VISU_GaussPointsPL* aPipeline = theActor->GetPipeLine();
1039 SALOME_ExtractGeometry* anExtractGeometry = aPipeline->GetExtractGeometryFilter();
1040 vtkImplicitFunction* anImplicitFunction = anExtractGeometry->GetImplicitFunction();
1042 aPipeline->ShallowCopy(GetGaussPointsPL());
1044 aPipeline->SetImplicitFunction(anImplicitFunction); // To restore
1046 aPipeline->SetPrimitiveType( myInsideCursorSettings->GetPrimitiveType() );
1047 aPipeline->SetClamp( myInsideCursorSettings->GetClamp() );
1048 aPipeline->SetImageData( myInsideCursorSettings->GetTexture() );
1049 aPipeline->SetAlphaThreshold( myInsideCursorSettings->GetAlphaThreshold() );
1050 aPipeline->SetResolution( myInsideCursorSettings->GetResolution() );
1051 aPipeline->SetMinSize( myInsideCursorSettings->GetMinSize() );
1052 aPipeline->SetMaxSize( myInsideCursorSettings->GetMaxSize() );
1053 aPipeline->SetMagnification( myInsideCursorSettings->GetMagnification() );
1054 aPipeline->SetMagnificationIncrement( myInsideCursorSettings->GetIncrement() );
1056 if( myInsideCursorSettings->GetPrimitiveType() != VISU_OpenGLPointSpriteMapper::GeomSphere )
1057 theActor->GetProperty()->SetRepresentation( VTK_POINTS );
1059 theActor->GetProperty()->SetRepresentation( VTK_SURFACE );
1061 aPipeline->Update();
1063 Highlight(isHighlighted());
1068 //==============================================================================
1069 vtkStandardNewMacro(VISU_GaussPtsAct1);
1072 //----------------------------------------------------------------------------
1074 ::VISU_GaussPtsAct1():
1075 myInsideDeviceActor(VISU_GaussPtsDeviceActor::New()),
1076 myOutsideDeviceActor(VISU_GaussPtsDeviceActor::New()),
1077 myOutsideCursorSettings(NULL)
1079 if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::VISU_GaussPtsAct1 - this = "<<this);
1081 myEventCallbackCommand->SetCallback(VISU_GaussPtsAct1::ProcessEvents);
1083 myInsideDeviceActor->SetVisibility(false);
1084 myInsideDeviceActor->SetPickable(false);
1085 myInsideDeviceActor->Delete();
1087 myOutsideDeviceActor->SetVisibility(false);
1088 myOutsideDeviceActor->SetPickable(false);
1089 myOutsideDeviceActor->Delete();
1093 ::~VISU_GaussPtsAct1()
1095 if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::~VISU_GaussPtsAct1 - this = "<<this);
1097 SetOutsideCursorSettings(NULL);
1101 //----------------------------------------------------------------------------
1104 ::ShallowCopyPL(VISU_PipeLine* thePipeLine)
1106 if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::ShallowCopyPL - this = "<<this);
1108 Superclass::ShallowCopyPL(thePipeLine);
1110 UpdateOutsideCursorSettings();
1114 //----------------------------------------------------------------------------
1117 ::AddToRender(vtkRenderer* theRenderer)
1119 Superclass::AddToRender(theRenderer);
1121 myInsideDeviceActor->AddToRender(theRenderer);
1122 myOutsideDeviceActor->AddToRender(theRenderer);
1127 ::RemoveFromRender(vtkRenderer* theRenderer)
1129 Superclass::RemoveFromRender(theRenderer);
1131 myInsideDeviceActor->RemoveFromRender(theRenderer);
1132 myOutsideDeviceActor->RemoveFromRender(theRenderer);
1137 ::SetTransform(VTKViewer_Transform* theTransform)
1139 Superclass::SetTransform(theTransform);
1141 myInsideDeviceActor->SetTransform(theTransform);
1142 myOutsideDeviceActor->SetTransform(theTransform);
1146 //----------------------------------------------------------------------------
1149 ::SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl)
1151 if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::SetWidgetCtrl - this = "<<this);
1153 if(myWidgetCtrl == theWidgetCtrl){
1158 myInsideDeviceActor->GetPipeLine()->SetImplicitFunction(NULL);
1159 myInsideDeviceActor->SetVisibility(false);
1161 myOutsideDeviceActor->GetPipeLine()->SetImplicitFunction(NULL);
1162 myOutsideDeviceActor->SetVisibility(false);
1165 Superclass::SetWidgetCtrl(theWidgetCtrl);
1168 myInsideDeviceActor->GetPipeLine()->SetImplicitFunction(theWidgetCtrl->ImplicitFunction());
1169 myInsideDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1171 myOutsideDeviceActor->GetPipeLine()->SetImplicitFunction(theWidgetCtrl->ImplicitFunction());
1172 myOutsideDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1177 //----------------------------------------------------------------------------
1180 ::SetMapperInput(vtkDataSet* theDataSet)
1182 if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::SetMapperInput - this = "<<this);
1184 Superclass::SetMapperInput(theDataSet);
1186 if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){
1187 myInsideDeviceActor->SetPipeLine(aPipeLine);
1188 aPipeLine->Delete();
1191 if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){
1192 myOutsideDeviceActor->SetPipeLine(aPipeLine);
1193 aPipeLine->Delete();
1195 SALOME_ExtractGeometry* anExtractGeometry = aPipeLine->GetExtractGeometryFilter();
1196 anExtractGeometry->SetExtractBoundaryCells(true);
1197 anExtractGeometry->SetExtractInside(true);
1202 //----------------------------------------------------------------------------
1205 ::GetRadius(vtkIdType theObjID,
1207 vtkDataArray *theScalarArray)
1209 VISU_GaussPointsPL* aPipeLine = myDeviceActor->GetPipeLine();
1210 if(IsSegmentationEnabled()){
1211 if(myInsideDeviceActor->GetPipeLine()->GetNodeVTKID(theObjID) < 0)
1212 aPipeLine = myOutsideDeviceActor->GetPipeLine();
1214 aPipeLine = myInsideDeviceActor->GetPipeLine();
1216 return ::GetRadius(theVTKID,theScalarArray,aPipeLine);
1220 //----------------------------------------------------------------------------
1223 ::GetMagnification(vtkIdType theObjID)
1225 VISU_GaussPointsPL* aPipeLine = myDeviceActor->GetPipeLine();
1226 if(IsSegmentationEnabled()){
1227 if(myInsideDeviceActor->GetPipeLine()->GetNodeVTKID(theObjID) < 0)
1228 aPipeLine = myOutsideDeviceActor->GetPipeLine();
1230 aPipeLine = myInsideDeviceActor->GetPipeLine();
1232 return aPipeLine->GetMagnification();
1236 //----------------------------------------------------------------------------
1239 ::GetClamp(vtkIdType theObjID)
1241 if(IsSegmentationEnabled()){
1242 if(myInsideDeviceActor->GetPipeLine()->GetNodeVTKID(theObjID) < 0)
1243 return ::GetClamp(myOutsideDeviceActor->GetPipeLine());
1245 return ::GetClamp(myInsideDeviceActor->GetPipeLine());
1247 return Superclass::GetClamp(theObjID);
1251 //----------------------------------------------------------------
1254 ::Connect(VISU_GaussPtsAct2* theActor)
1256 mySetVisibilitySignal.connect(boost::bind(&VISU_GaussPtsAct2::SetVisibility,theActor,_1));
1261 ::SetVisibility(int theMode)
1263 if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::SetVisibility - this = "<<this);
1265 Superclass::SetVisibility(theMode);
1267 bool aVisisbility = GetVisibility();
1268 bool anIsSegementation = IsSegmentationEnabled();
1269 myDeviceActor->SetVisibility(aVisisbility && !anIsSegementation);
1270 myInsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
1271 myOutsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
1273 mySetVisibilitySignal(GetVisibility());
1276 //----------------------------------------------------------------
1279 ::UpdateInsideCursorSettings()
1281 Superclass::UpdateInsideCursorSettings( myInsideDeviceActor );
1284 //----------------------------------------------------------------
1287 ::SetOutsideCursorSettings(VISU_OutsideCursorSettings* theOutsideCursorSettings)
1289 if(myOutsideCursorSettings == theOutsideCursorSettings)
1292 if(myOutsideCursorSettings)
1293 myOutsideCursorSettings->RemoveObserver(myEventCallbackCommand.GetPointer());
1295 myOutsideCursorSettings = theOutsideCursorSettings;
1297 if(theOutsideCursorSettings)
1299 theOutsideCursorSettings->AddObserver(VISU::UpdateOutsideSettingsEvent,
1300 myEventCallbackCommand.GetPointer(),
1302 UpdateOutsideCursorSettings();
1308 ::UpdateOutsideCursorSettings()
1310 if(!myOutsideCursorSettings || myOutsideCursorSettings->GetInitial())
1313 VISU_GaussPointsPL* aPipeline = myOutsideDeviceActor->GetPipeLine();
1315 SALOME_ExtractGeometry* anExtractGeometry = aPipeline->GetExtractGeometryFilter();
1316 vtkImplicitFunction* anImplicitFunction = anExtractGeometry->GetImplicitFunction();
1317 float aMagnification = aPipeline->GetMagnification();
1319 aPipeline->ShallowCopy(GetGaussPointsPL());
1321 aPipeline->SetImplicitFunction(anImplicitFunction); // To restore
1322 anExtractGeometry->SetExtractBoundaryCells(true);
1323 anExtractGeometry->SetExtractInside(true);
1324 aPipeline->SetMagnification( aMagnification );
1326 aPipeline->SetPrimitiveType( myOutsideCursorSettings->GetPrimitiveType() );
1328 if( myOutsideCursorSettings->GetPrimitiveType() != VISU_OpenGLPointSpriteMapper::GeomSphere )
1329 myOutsideDeviceActor->GetProperty()->SetRepresentation( VTK_POINTS );
1331 myOutsideDeviceActor->GetProperty()->SetRepresentation( VTK_SURFACE );
1333 aPipeline->SetClamp( myOutsideCursorSettings->GetClamp() );
1334 aPipeline->SetImageData( myOutsideCursorSettings->GetTexture() );
1335 aPipeline->SetAlphaThreshold( myOutsideCursorSettings->GetAlphaThreshold() );
1336 aPipeline->SetResolution( myOutsideCursorSettings->GetResolution() );
1337 aPipeline->SetSize( myOutsideCursorSettings->GetSize() );
1338 aPipeline->SetMagnification( myOutsideCursorSettings->GetMagnification() );
1339 aPipeline->SetMagnificationIncrement( myOutsideCursorSettings->GetIncrement() );
1341 if( myOutsideCursorSettings->GetUniform() )
1343 myOutsideDeviceActor->GetPSMapper()->ScalarVisibilityOff();
1344 myOutsideDeviceActor->GetPSMapper()->SetPointSpriteMode( 1 ); // Geometry mode
1345 myOutsideDeviceActor->GetProperty()->SetColor( myOutsideCursorSettings->GetColor() );
1349 myOutsideDeviceActor->GetPSMapper()->SetPointSpriteMode( 2 ); // Outside cursor mode
1350 myOutsideDeviceActor->GetPSMapper()->SetColorModeToMapScalars();
1351 myOutsideDeviceActor->GetPSMapper()->ScalarVisibilityOn();
1354 aPipeline->Update();
1356 Highlight(isHighlighted());
1362 //----------------------------------------------------------------
1365 ::ProcessEvents(vtkObject* theObject,
1366 unsigned long theEvent,
1367 void* theClientData,
1370 if(vtkObject* anObject = reinterpret_cast<vtkObject*>(theClientData))
1371 if(VISU_GaussPtsAct1* self = dynamic_cast<VISU_GaussPtsAct1*>(anObject))
1372 if(theEvent == VISU::UpdateOutsideSettingsEvent)
1373 self->UpdateOutsideCursorSettings();
1375 Superclass::ProcessEvents(theObject,theEvent,theClientData,theCallData);
1380 ::OnInteractorEvent(unsigned long theEvent)
1383 case vtkCommand::StartInteractionEvent:
1384 myDeviceActor->SetVisibility(GetVisibility());
1385 myInsideDeviceActor->SetVisibility(false);
1386 myOutsideDeviceActor->SetVisibility(false);
1388 case vtkCommand::EnableEvent:
1389 case vtkCommand::DisableEvent:
1390 case vtkCommand::EndInteractionEvent: {
1391 bool aVisisbility = GetVisibility();
1392 bool anIsSegementation = IsSegmentationEnabled();
1393 myDeviceActor->SetVisibility(aVisisbility && !anIsSegementation);
1394 myInsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
1395 myOutsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
1402 Superclass::OnInteractorEvent(theEvent);
1406 //==============================================================================
1407 vtkStandardNewMacro(VISU_GaussPtsAct2);
1410 //----------------------------------------------------------------------------
1412 ::VISU_GaussPtsAct2()
1414 if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::VISU_GaussPtsAct2 - this = "<<this);
1415 myDeviceActor->SetVisibility(false);
1419 ::~VISU_GaussPtsAct2()
1421 if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::~VISU_GaussPtsAct2 - this = "<<this);
1425 //----------------------------------------------------------------------------
1428 ::ShallowCopyPL(VISU_PipeLine* thePipeLine)
1430 if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::ShallowCopyPL - this = "<<this);
1432 Superclass::ShallowCopyPL(thePipeLine);
1436 //----------------------------------------------------------------------------
1439 ::SetMapperInput(vtkDataSet* theDataSet)
1441 if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::SetMapperInput - this = "<<this);
1443 if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){
1444 myDeviceActor->SetPipeLine(aPipeLine);
1445 myCurrentPL = aPipeLine;
1446 aPipeLine->Delete();
1448 myMapper->SetInput(myCurrentPL->GetPickableDataSet());
1449 SetMapper(myMapper.GetPointer());
1453 //----------------------------------------------------------------------------
1456 ::SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl)
1458 if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::SetWidgetCtrl - this = "<<this);
1460 if(myWidgetCtrl == theWidgetCtrl)
1464 theWidgetCtrl->RemoveObserver(myEventCallbackCommand.GetPointer());
1465 myDeviceActor->GetPipeLine()->SetImplicitFunction(NULL);
1466 myDeviceActor->SetVisibility(false);
1469 Superclass::SetWidgetCtrl(theWidgetCtrl);
1472 myDeviceActor->GetPipeLine()->SetImplicitFunction(theWidgetCtrl->ImplicitFunction());
1473 myDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1478 //----------------------------------------------------------------------------
1481 ::SetVisibility(int theMode)
1483 if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::SetVisibility - this = "<<this);
1485 Superclass::SetVisibility(theMode);
1487 myDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1492 ::OnInteractorEvent(unsigned long theEvent)
1495 case vtkCommand::EnableEvent:
1496 case vtkCommand::DisableEvent:
1497 myDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1498 if(theEvent == vtkCommand::EnableEvent)
1501 case vtkCommand::EndInteractionEvent:
1507 Superclass::OnInteractorEvent(theEvent);