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( myWidgetCtrl->GetEnabled() )
561 this->ChangeMagnification( myInteractor->GetShiftKey() );
565 myChangeMagnification = myInteractor->GetShiftKey();
571 if( myWidgetCtrl->GetEnabled() && 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(0);
843 myCursorPyramidSelected->SetVisibility(0);
844 myCursorPyramid->SetVisibility(0);
845 myCellActor->SetVisibility(0);
846 GetScalarBarCtrl()->SetIsMarked(false);
847 GetScalarBarCtrl()->Update();
849 bool anIsVisible = GetVisibility();
851 Selection_Mode aSelectionMode = mySelector->SelectionMode();
853 if(aSelectionMode == ActorSelection)
854 Superclass::highlight(theIsHighlight);
855 else if(aSelectionMode != GaussPointSelection)
858 TColStd_IndexedMapOfInteger aMapIndex;
859 mySelector->GetIndex( getIO(), aMapIndex );
860 if(aMapIndex.Extent() != 1 || !myBarVisibility) {
864 std::ostringstream aStr;
865 int anObjId = aMapIndex(1);
866 aStr<<"Global ID: "<<anObjId;
868 vtkIdType aVtkId = GetNodeVTKID(anObjId);
870 float *aNodeCoord = GetNodeCoord(anObjId);
871 float aWorldCoord[4] = {aNodeCoord[0], aNodeCoord[1], aNodeCoord[2], 1.};
873 vtkDataSet* aDataSet = GetInput();
874 vtkCellData* aDataSetAttributes = aDataSet->GetCellData();
876 if(vtkDataArray* aScalarArray = aDataSetAttributes->GetScalars()){
877 float aVal = aScalarArray->GetTuple1(aVtkId);
879 GetScalarBarCtrl()->SetIsMarked(true);
880 GetScalarBarCtrl()->SetMarkValue(aVal);
881 GetScalarBarCtrl()->Update();
883 float aPyramidHeight = myPickingSettings->GetPyramidHeight();
884 aPyramidHeight = aPyramidHeight*myGaussPointsPL->GetMaxPointSize();
885 myCursorPyramidSelected->Init(aPyramidHeight,
886 myPickingSettings->GetCursorSize(),
887 GetRadius(anObjId,aVtkId,aScalarArray),
888 GetMagnification(anObjId),
891 myHighlightActor->GetProperty()->GetColor());
892 myCursorPyramidSelected->SetVisibility(anIsVisible && theIsHighlight);
894 const VISU::PGaussPtsIDMapper& aGaussPtsIDMapper =
895 myGaussPointsPL->GetGaussPtsIDMapper();
896 VISU::TNamedIDMapper* aParent = aGaussPtsIDMapper->GetParent();
898 VISU::TGaussPointID aGaussPointID = myGaussPointsPL->GetObjID(anObjId);
899 VISU::TCellID aCellID = aGaussPointID.first;
900 VISU::TLocalPntID aLocalPntID = aGaussPointID.second;
901 aStr<<"\nParentCellID: "<<aCellID;
902 std::string aParentName = aParent->GetElemName(aCellID);
903 if(aParentName != "") {
904 aStr<<"\nParentCellName: '"<<aParentName<<"'";
906 aStr<<"\nLocalPntID: "<<aLocalPntID;
907 aStr<<"\nScalar: "<<aVal;
910 if(vtkDataArray* aFieldArray = aDataSetAttributes->GetArray("VISU_FIELD")){
911 if(vtkFloatArray *aFloatArray = dynamic_cast<vtkFloatArray*>(aFieldArray)){
912 int aNbComp = aFloatArray->GetNumberOfComponents();
915 while(anId < aNbComp){
916 float aComp = aFloatArray->GetComponent(aVtkId,anId++);
926 std::string aString = aStr.str();
927 myTextActor->SetModePosition(myPickingSettings->GetInfoWindowPosition());
928 myTextActor->SetTransparency(myPickingSettings->GetInfoWindowTransparency());
929 myTextActor->SetWorldPoint(aWorldCoord);
930 myTextActor->SetText(aString.c_str());
931 myTextActor->SetVisibility(anIsVisible && theIsHighlight);
934 if(myPickingSettings->GetDisplayParentMesh()){
935 const VISU::PGaussPtsIDMapper& aGaussPtsIDMapper =
936 myGaussPointsPL->GetGaussPtsIDMapper();
937 VISU::TNamedIDMapper* aParent = aGaussPtsIDMapper->GetParent();
939 myCellSource->Reset();
940 myCellSource->Modified(); // a VTK bug
941 myCellSource->SetPoints(aParent->GetVTKOutput()->GetPoints());
943 VISU::TGaussPointID aGaussPointID = aGaussPtsIDMapper->GetObjID(anObjId);
944 vtkIdType aCellID = aGaussPointID.first;
945 vtkCell* aCell = aParent->GetElemCell(aCellID);
946 myCellSource->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
947 myCellActor->SetVisibility(anIsVisible && theIsHighlight);
948 myCellActor->SetRepresentation(VTK_WIREFRAME);
954 //----------------------------------------------------------------
957 ::SetPickingSettings(VISU_PickingSettings* thePickingSettings)
959 if(myPickingSettings == thePickingSettings)
962 if(myPickingSettings)
963 myPickingSettings->RemoveObserver(myEventCallbackCommand.GetPointer());
965 myPickingSettings = thePickingSettings;
967 if(thePickingSettings)
969 thePickingSettings->AddObserver(VISU::UpdatePickingSettingsEvent,
970 myEventCallbackCommand.GetPointer(),
972 this->UpdatePickingSettings();
978 ::UpdatePickingSettings()
980 if(!myPickingSettings || myPickingSettings->GetInitial())
983 myTextActor->SetModePosition(myPickingSettings->GetInfoWindowPosition());
984 myTextActor->SetTransparency(myPickingSettings->GetInfoWindowTransparency());
986 float aHeight = myGaussPointsPL->GetMaxPointSize()*myPickingSettings->GetPyramidHeight();
987 float aCursorSize = myPickingSettings->GetCursorSize();
988 myCursorPyramid->SetPreferences(aHeight,aCursorSize);
989 myCursorPyramidSelected->SetPreferences(aHeight,aCursorSize);
991 myHighlightActor->GetProperty()->SetColor( myPickingSettings->GetColor() );
992 myPointPicker->SetTolerance( myPickingSettings->GetPointTolerance() );
994 Highlight(isHighlighted());
999 //----------------------------------------------------------------
1002 ::SetInsideCursorSettings(VISU_InsideCursorSettings* theInsideCursorSettings)
1004 if(myInsideCursorSettings == theInsideCursorSettings)
1007 if(myInsideCursorSettings)
1008 myInsideCursorSettings->RemoveObserver(myEventCallbackCommand.GetPointer());
1010 myInsideCursorSettings = theInsideCursorSettings;
1012 if(theInsideCursorSettings){
1013 theInsideCursorSettings->AddObserver(VISU::UpdateInsideSettingsEvent,
1014 myEventCallbackCommand.GetPointer(),
1016 UpdateInsideCursorSettings();
1022 ::UpdateInsideCursorSettings()
1024 UpdateInsideCursorSettings( myDeviceActor );
1029 ::UpdateInsideCursorSettings( PDeviceActor theActor )
1031 if(!myInsideCursorSettings || myInsideCursorSettings->GetInitial())
1034 VISU_GaussPointsPL* aPipeline = theActor->GetPipeLine();
1036 SALOME_ExtractGeometry* anExtractGeometry = aPipeline->GetExtractGeometryFilter();
1037 vtkImplicitFunction* anImplicitFunction = anExtractGeometry->GetImplicitFunction();
1039 aPipeline->ShallowCopy(GetGaussPointsPL());
1041 aPipeline->SetImplicitFunction(anImplicitFunction); // To restore
1043 aPipeline->SetPrimitiveType( myInsideCursorSettings->GetPrimitiveType() );
1044 aPipeline->SetClamp( myInsideCursorSettings->GetClamp() );
1045 aPipeline->SetImageData( myInsideCursorSettings->GetTexture() );
1046 aPipeline->SetAlphaThreshold( myInsideCursorSettings->GetAlphaThreshold() );
1047 aPipeline->SetResolution( myInsideCursorSettings->GetResolution() );
1048 aPipeline->SetMinSize( myInsideCursorSettings->GetMinSize() );
1049 aPipeline->SetMaxSize( myInsideCursorSettings->GetMaxSize() );
1050 aPipeline->SetMagnification( myInsideCursorSettings->GetMagnification() );
1051 aPipeline->SetMagnificationIncrement( myInsideCursorSettings->GetIncrement() );
1053 if( myInsideCursorSettings->GetPrimitiveType() != VISU_OpenGLPointSpriteMapper::GeomSphere )
1054 theActor->GetProperty()->SetRepresentation( VTK_POINTS );
1056 theActor->GetProperty()->SetRepresentation( VTK_SURFACE );
1058 aPipeline->Update();
1060 Highlight(isHighlighted());
1065 //==============================================================================
1066 vtkStandardNewMacro(VISU_GaussPtsAct1);
1069 //----------------------------------------------------------------------------
1071 ::VISU_GaussPtsAct1():
1072 myInsideDeviceActor(VISU_GaussPtsDeviceActor::New()),
1073 myOutsideDeviceActor(VISU_GaussPtsDeviceActor::New()),
1074 myOutsideCursorSettings(NULL)
1076 if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::VISU_GaussPtsAct1 - this = "<<this);
1078 myEventCallbackCommand->SetCallback(VISU_GaussPtsAct1::ProcessEvents);
1080 myInsideDeviceActor->SetVisibility(false);
1081 myInsideDeviceActor->SetPickable(false);
1082 myInsideDeviceActor->Delete();
1084 myOutsideDeviceActor->SetVisibility(false);
1085 myOutsideDeviceActor->SetPickable(false);
1086 myOutsideDeviceActor->Delete();
1090 ::~VISU_GaussPtsAct1()
1092 if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::~VISU_GaussPtsAct1 - this = "<<this);
1094 SetOutsideCursorSettings(NULL);
1098 //----------------------------------------------------------------------------
1101 ::ShallowCopyPL(VISU_PipeLine* thePipeLine)
1103 if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::ShallowCopyPL - this = "<<this);
1105 Superclass::ShallowCopyPL(thePipeLine);
1107 UpdateOutsideCursorSettings();
1111 //----------------------------------------------------------------------------
1114 ::AddToRender(vtkRenderer* theRenderer)
1116 Superclass::AddToRender(theRenderer);
1118 myInsideDeviceActor->AddToRender(theRenderer);
1119 myOutsideDeviceActor->AddToRender(theRenderer);
1124 ::RemoveFromRender(vtkRenderer* theRenderer)
1126 Superclass::RemoveFromRender(theRenderer);
1128 myInsideDeviceActor->RemoveFromRender(theRenderer);
1129 myOutsideDeviceActor->RemoveFromRender(theRenderer);
1134 ::SetTransform(VTKViewer_Transform* theTransform)
1136 Superclass::SetTransform(theTransform);
1138 myInsideDeviceActor->SetTransform(theTransform);
1139 myOutsideDeviceActor->SetTransform(theTransform);
1143 //----------------------------------------------------------------------------
1146 ::SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl)
1148 if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::SetWidgetCtrl - this = "<<this);
1150 if(myWidgetCtrl == theWidgetCtrl){
1155 myInsideDeviceActor->GetPipeLine()->SetImplicitFunction(NULL);
1156 myInsideDeviceActor->SetVisibility(false);
1158 myOutsideDeviceActor->GetPipeLine()->SetImplicitFunction(NULL);
1159 myOutsideDeviceActor->SetVisibility(false);
1162 Superclass::SetWidgetCtrl(theWidgetCtrl);
1165 myInsideDeviceActor->GetPipeLine()->SetImplicitFunction(theWidgetCtrl->ImplicitFunction());
1166 myInsideDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1168 myOutsideDeviceActor->GetPipeLine()->SetImplicitFunction(theWidgetCtrl->ImplicitFunction());
1169 myOutsideDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1174 //----------------------------------------------------------------------------
1177 ::SetMapperInput(vtkDataSet* theDataSet)
1179 if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::SetMapperInput - this = "<<this);
1181 Superclass::SetMapperInput(theDataSet);
1183 if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){
1184 myInsideDeviceActor->SetPipeLine(aPipeLine);
1185 aPipeLine->Delete();
1188 if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){
1189 myOutsideDeviceActor->SetPipeLine(aPipeLine);
1190 aPipeLine->Delete();
1192 SALOME_ExtractGeometry* anExtractGeometry = aPipeLine->GetExtractGeometryFilter();
1193 anExtractGeometry->SetExtractBoundaryCells(true);
1194 anExtractGeometry->SetExtractInside(true);
1199 //----------------------------------------------------------------------------
1202 ::GetRadius(vtkIdType theObjID,
1204 vtkDataArray *theScalarArray)
1206 VISU_GaussPointsPL* aPipeLine = myDeviceActor->GetPipeLine();
1207 if(IsSegmentationEnabled()){
1208 if(myInsideDeviceActor->GetPipeLine()->GetNodeVTKID(theObjID) < 0)
1209 aPipeLine = myOutsideDeviceActor->GetPipeLine();
1211 aPipeLine = myInsideDeviceActor->GetPipeLine();
1213 return ::GetRadius(theVTKID,theScalarArray,aPipeLine);
1217 //----------------------------------------------------------------------------
1220 ::GetMagnification(vtkIdType theObjID)
1222 VISU_GaussPointsPL* aPipeLine = myDeviceActor->GetPipeLine();
1223 if(IsSegmentationEnabled()){
1224 if(myInsideDeviceActor->GetPipeLine()->GetNodeVTKID(theObjID) < 0)
1225 aPipeLine = myOutsideDeviceActor->GetPipeLine();
1227 aPipeLine = myInsideDeviceActor->GetPipeLine();
1229 return aPipeLine->GetMagnification();
1233 //----------------------------------------------------------------------------
1236 ::GetClamp(vtkIdType theObjID)
1238 if(IsSegmentationEnabled()){
1239 if(myInsideDeviceActor->GetPipeLine()->GetNodeVTKID(theObjID) < 0)
1240 return ::GetClamp(myOutsideDeviceActor->GetPipeLine());
1242 return ::GetClamp(myInsideDeviceActor->GetPipeLine());
1244 return Superclass::GetClamp(theObjID);
1248 //----------------------------------------------------------------
1251 ::Connect(VISU_GaussPtsAct2* theActor)
1253 mySetVisibilitySignal.connect(boost::bind(&VISU_GaussPtsAct2::SetVisibility,theActor,_1));
1258 ::SetVisibility(int theMode)
1260 if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::SetVisibility - this = "<<this);
1262 Superclass::SetVisibility(theMode);
1264 bool aVisisbility = GetVisibility();
1265 bool anIsSegementation = IsSegmentationEnabled();
1266 myDeviceActor->SetVisibility(aVisisbility && !anIsSegementation);
1267 myInsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
1268 myOutsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
1270 mySetVisibilitySignal(GetVisibility());
1273 //----------------------------------------------------------------
1276 ::UpdateInsideCursorSettings()
1278 Superclass::UpdateInsideCursorSettings( myInsideDeviceActor );
1281 //----------------------------------------------------------------
1284 ::SetOutsideCursorSettings(VISU_OutsideCursorSettings* theOutsideCursorSettings)
1286 if(myOutsideCursorSettings == theOutsideCursorSettings)
1289 if(myOutsideCursorSettings)
1290 myOutsideCursorSettings->RemoveObserver(myEventCallbackCommand.GetPointer());
1292 myOutsideCursorSettings = theOutsideCursorSettings;
1294 if(theOutsideCursorSettings)
1296 theOutsideCursorSettings->AddObserver(VISU::UpdateOutsideSettingsEvent,
1297 myEventCallbackCommand.GetPointer(),
1299 UpdateOutsideCursorSettings();
1305 ::UpdateOutsideCursorSettings()
1307 if(!myOutsideCursorSettings || myOutsideCursorSettings->GetInitial())
1310 VISU_GaussPointsPL* aPipeline = myOutsideDeviceActor->GetPipeLine();
1312 SALOME_ExtractGeometry* anExtractGeometry = aPipeline->GetExtractGeometryFilter();
1313 vtkImplicitFunction* anImplicitFunction = anExtractGeometry->GetImplicitFunction();
1314 float aMagnification = aPipeline->GetMagnification();
1316 aPipeline->ShallowCopy(GetGaussPointsPL());
1318 aPipeline->SetImplicitFunction(anImplicitFunction); // To restore
1319 anExtractGeometry->SetExtractBoundaryCells(true);
1320 anExtractGeometry->SetExtractInside(true);
1321 aPipeline->SetMagnification( aMagnification );
1323 aPipeline->SetPrimitiveType( myOutsideCursorSettings->GetPrimitiveType() );
1325 if( myOutsideCursorSettings->GetPrimitiveType() != VISU_OpenGLPointSpriteMapper::GeomSphere )
1326 myOutsideDeviceActor->GetProperty()->SetRepresentation( VTK_POINTS );
1328 myOutsideDeviceActor->GetProperty()->SetRepresentation( VTK_SURFACE );
1330 aPipeline->SetClamp( myOutsideCursorSettings->GetClamp() );
1331 aPipeline->SetImageData( myOutsideCursorSettings->GetTexture() );
1332 aPipeline->SetAlphaThreshold( myOutsideCursorSettings->GetAlphaThreshold() );
1333 aPipeline->SetResolution( myOutsideCursorSettings->GetResolution() );
1334 aPipeline->SetSize( myOutsideCursorSettings->GetSize() );
1335 aPipeline->SetMagnification( myOutsideCursorSettings->GetMagnification() );
1336 aPipeline->SetMagnificationIncrement( myOutsideCursorSettings->GetIncrement() );
1338 if( myOutsideCursorSettings->GetUniform() )
1340 myOutsideDeviceActor->GetPSMapper()->ScalarVisibilityOff();
1341 myOutsideDeviceActor->GetPSMapper()->SetPointSpriteMode( 1 ); // Geometry mode
1342 myOutsideDeviceActor->GetProperty()->SetColor( myOutsideCursorSettings->GetColor() );
1346 myOutsideDeviceActor->GetPSMapper()->SetPointSpriteMode( 2 ); // Outside cursor mode
1347 myOutsideDeviceActor->GetPSMapper()->SetColorModeToMapScalars();
1348 myOutsideDeviceActor->GetPSMapper()->ScalarVisibilityOn();
1351 aPipeline->Update();
1353 Highlight(isHighlighted());
1359 //----------------------------------------------------------------
1362 ::ProcessEvents(vtkObject* theObject,
1363 unsigned long theEvent,
1364 void* theClientData,
1367 if(vtkObject* anObject = reinterpret_cast<vtkObject*>(theClientData))
1368 if(VISU_GaussPtsAct1* self = dynamic_cast<VISU_GaussPtsAct1*>(anObject))
1369 if(theEvent == VISU::UpdateOutsideSettingsEvent)
1370 self->UpdateOutsideCursorSettings();
1372 Superclass::ProcessEvents(theObject,theEvent,theClientData,theCallData);
1377 ::OnInteractorEvent(unsigned long theEvent)
1380 case vtkCommand::StartInteractionEvent:
1381 myDeviceActor->SetVisibility(GetVisibility());
1382 myInsideDeviceActor->SetVisibility(false);
1383 myOutsideDeviceActor->SetVisibility(false);
1385 case vtkCommand::EnableEvent:
1386 case vtkCommand::DisableEvent:
1387 case vtkCommand::EndInteractionEvent: {
1388 bool aVisisbility = GetVisibility();
1389 bool anIsSegementation = IsSegmentationEnabled();
1390 myDeviceActor->SetVisibility(aVisisbility && !anIsSegementation);
1391 myInsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
1392 myOutsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
1399 Superclass::OnInteractorEvent(theEvent);
1403 //==============================================================================
1404 vtkStandardNewMacro(VISU_GaussPtsAct2);
1407 //----------------------------------------------------------------------------
1409 ::VISU_GaussPtsAct2()
1411 if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::VISU_GaussPtsAct2 - this = "<<this);
1412 myDeviceActor->SetVisibility(false);
1416 ::~VISU_GaussPtsAct2()
1418 if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::~VISU_GaussPtsAct2 - this = "<<this);
1422 //----------------------------------------------------------------------------
1425 ::ShallowCopyPL(VISU_PipeLine* thePipeLine)
1427 if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::ShallowCopyPL - this = "<<this);
1429 Superclass::ShallowCopyPL(thePipeLine);
1433 //----------------------------------------------------------------------------
1436 ::SetMapperInput(vtkDataSet* theDataSet)
1438 if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::SetMapperInput - this = "<<this);
1440 if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){
1441 myDeviceActor->SetPipeLine(aPipeLine);
1442 myCurrentPL = aPipeLine;
1443 aPipeLine->Delete();
1445 myMapper->SetInput(myCurrentPL->GetPickableDataSet());
1446 SetMapper(myMapper.GetPointer());
1450 //----------------------------------------------------------------------------
1453 ::SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl)
1455 if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::SetWidgetCtrl - this = "<<this);
1457 if(myWidgetCtrl == theWidgetCtrl)
1461 theWidgetCtrl->RemoveObserver(myEventCallbackCommand.GetPointer());
1462 myDeviceActor->GetPipeLine()->SetImplicitFunction(NULL);
1463 myDeviceActor->SetVisibility(false);
1466 Superclass::SetWidgetCtrl(theWidgetCtrl);
1469 myDeviceActor->GetPipeLine()->SetImplicitFunction(theWidgetCtrl->ImplicitFunction());
1470 myDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1475 //----------------------------------------------------------------------------
1478 ::SetVisibility(int theMode)
1480 if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::SetVisibility - this = "<<this);
1482 Superclass::SetVisibility(theMode);
1484 myDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1489 ::OnInteractorEvent(unsigned long theEvent)
1492 case vtkCommand::EnableEvent:
1493 case vtkCommand::DisableEvent:
1494 myDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1495 if(theEvent == vtkCommand::EnableEvent)
1498 case vtkCommand::EndInteractionEvent:
1504 Superclass::OnInteractorEvent(theEvent);