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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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();
210 vtkFloatingPointType*
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 vtkFloatingPointType aMagnification = myInsideCursorSettings->GetMagnification();
339 vtkFloatingPointType anIncrement = myInsideCursorSettings->GetIncrement();
340 vtkFloatingPointType 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)
385 vtkFloatingPointType aRadius = 0.5;
386 if(theGaussPointsPL->GetPSMapper()->GetPointSpriteMode() == 1) // Geometry mode
387 aRadius *= theGaussPointsPL->GetSize() * theGaussPointsPL->GetAverageCellSize();
388 else if(theGaussPointsPL->GetBicolor()){
389 vtkFloatingPointType 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 vtkFloatingPointType 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 //----------------------------------------------------------------------------
610 if(vtkMapper* aMapper = myDeviceActor->GetMapper()){
611 if(vtkDataSet* aDataSet= aMapper->GetInput()){
613 myIsInfinite = aDataSet->GetNumberOfCells() < 2;
619 //----------------------------------------------------------------------------
624 if(Superclass::GetPickable()){
625 if(vtkMapper* aMapper = GetMapper()){
626 if(vtkDataSet* aDataSet= aMapper->GetInput()){
628 return aDataSet->GetNumberOfCells() > 0;
636 //----------------------------------------------------------------------------
639 ::PreHighlight(vtkInteractorStyle* theInteractorStyle,
640 SVTK_SelectionEvent* theSelectionEvent,
643 if ( !GetPickable() )
646 myPreHighlightActor->SetVisibility(false);
647 myCursorPyramid->SetVisibility(false);
649 if (!myBarVisibility)
654 myLastObjPointID = -1;
656 Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
658 if(aSelectionMode == ActorSelection || !theIsHighlight)
659 return Superclass::PreHighlight(theInteractorStyle,
663 bool anIsChanged = (mySelectionMode != aSelectionMode);
664 bool anIsPreselected = myIsPreselected;
665 myIsPreselected = false;
667 if(aSelectionMode == GaussPointSelection && theIsHighlight){
668 myPointPicker->Pick(theSelectionEvent->myX,
669 theSelectionEvent->myY,
671 theInteractorStyle->GetCurrentRenderer());
673 if(myPointPicker->GetActor() != this)
674 return (anIsPreselected != myIsPreselected);
676 vtkIdType aVtkId = myPointPicker->GetPointId();
678 if(aVtkId >= 0 && mySelector->IsValid(this,aVtkId,true) && hasIO()){
679 vtkIdType anObjId = GetNodeObjId( aVtkId );
680 myIsPreselected = (anObjId >= 0);
682 anIsChanged = (myLastObjPointID != anObjId);
684 vtkFloatingPointType* aNodeCoord = GetNodeCoord(anObjId);
685 vtkDataSet* aDataSet = GetInput();
686 vtkCellData* aCellData = aDataSet->GetCellData();
687 if(vtkDataArray *aScalarArray = aCellData->GetScalars()){
688 vtkFloatingPointType aPyramidHeight = myPickingSettings->GetPyramidHeight();
689 aPyramidHeight = aPyramidHeight*myGaussPointsPL->GetMaxPointSize();
690 //vtkFloatingPointType aColor[3] = myPreHighlightActor->GetProperty()->GetColor();
691 vtkFloatingPointType aColor[3];
692 theInteractorStyle->GetCurrentRenderer()->GetBackground( aColor );
693 aColor[0] = 1. - aColor[0];
694 aColor[1] = 1. - aColor[1];
695 aColor[2] = 1. - aColor[2];
697 myCursorPyramid->Init(aPyramidHeight,
698 myPickingSettings->GetCursorSize(),
699 GetRadius(anObjId,aVtkId,aScalarArray),
700 GetMagnification(anObjId),
705 myLastObjPointID = anObjId;
707 myCursorPyramid->SetVisibility(true);
712 mySelectionMode = aSelectionMode;
713 anIsChanged |= (anIsPreselected != myIsPreselected);
719 //----------------------------------------------------------------------------
722 ChangeZoom(VISU_PickingSettings *thePickingSettings,
723 vtkInteractorStyle* theInteractorStyle,
724 int theInitialHasIndex,
725 int theCurrentHasIndex,
726 const Handle(SALOME_InteractiveObject)& theIO)
728 if(theInitialHasIndex + theCurrentHasIndex == 1){
729 vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer();
730 vtkCamera *aCamera = aRenderer->GetActiveCamera();
731 vtkFloatingPointType aZoomFactor = thePickingSettings->GetZoomFactor();
732 double aScale = aCamera->GetParallelScale();
733 if (!theInitialHasIndex && theCurrentHasIndex) {
734 aCamera->SetParallelScale(aScale/aZoomFactor);
737 aCamera->SetParallelScale(aScale*aZoomFactor);
745 ::Highlight(vtkInteractorStyle* theInteractorStyle,
746 SVTK_SelectionEvent* theSelectionEvent,
749 if ( !GetPickable() )
752 int anInitialHasIndex = myIsHighlighted && mySelectionMode == GaussPointSelection;
753 Handle(SALOME_InteractiveObject) anIO = getIO();
754 myIsHighlighted = false;
756 Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
758 if(!theIsHighlight && aSelectionMode == GaussPointSelection){
759 mySelector->RemoveIObject(anIO);
761 ChangeZoom(myPickingSettings,
770 if (!myBarVisibility)
774 if(aSelectionMode == ActorSelection)
775 return Superclass::Highlight(theInteractorStyle,
779 if(aSelectionMode == GaussPointSelection && !theSelectionEvent->myIsRectangle){
781 vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer();
782 myPointPicker->Pick(theSelectionEvent->myX,
783 theSelectionEvent->myY,
787 if(myPointPicker->GetActor() != this) {
788 mySelector->ClearIObjects();
790 ChangeZoom(myPickingSettings,
799 vtkIdType aVtkId = myPointPicker->GetPointId();
800 if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId, true ) && hasIO()) {
801 vtkIdType anObjId = GetNodeObjId( aVtkId );
803 myIsHighlighted = true;
804 // Update the Selector
805 if(mySelector->IsSelected(myIO))
806 mySelector->AddOrRemoveIndex(myIO,anObjId,theSelectionEvent->myIsShift);
808 if(!theSelectionEvent->myIsShift){
809 mySelector->ClearIObjects();
811 mySelector->AddOrRemoveIndex(myIO,anObjId,theSelectionEvent->myIsShift);
812 mySelector->AddIObject(this);
815 vtkFloatingPointType* aNodeCoord = GetNodeCoord(anObjId);
818 vtkRenderWindowInteractor* anInteractor = theInteractorStyle->GetInteractor();
819 vtkFloatingPointType aDollyWas = anInteractor->GetDolly();
820 int aNumberOfFlyFramesWas = anInteractor->GetNumberOfFlyFrames();
822 anInteractor->SetDolly(0.);
823 anInteractor->SetNumberOfFlyFrames(myPickingSettings->GetStepNumber());
824 anInteractor->FlyTo(aRenderer,aNodeCoord);
825 aRenderer->ResetCameraClippingRange();
826 anInteractor->SetDolly(aDollyWas);
827 anInteractor->SetNumberOfFlyFrames(aNumberOfFlyFramesWas);
829 mySelectionMode = aSelectionMode;
831 ChangeZoom(myPickingSettings,
839 }// if( anObjId >= 0 ) {
840 }//if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId, true ) && hasIO())
841 }//if(!theSelectionEvent->myIsRectangle){
843 ChangeZoom(myPickingSettings,
852 //==================================================================
853 // function : Highlight
855 //==================================================================
858 ::Highlight(bool theIsHighlight)
860 if(!mySelector.GetPointer())
863 myOutlineActor->SetVisibility(false);
864 myTextActor->SetVisibility(false);
865 myCursorPyramidSelected->SetVisibility(false);
866 myCursorPyramid->SetVisibility(false);
867 myCellActor->SetVisibility(false);
868 GetScalarBarCtrl()->SetIsMarked(false);
869 GetScalarBarCtrl()->Update();
874 bool anIsVisible = GetVisibility();
876 Selection_Mode aSelectionMode = mySelector->SelectionMode();
878 if(aSelectionMode == ActorSelection)
879 Superclass::highlight(theIsHighlight);
880 else if(aSelectionMode != GaussPointSelection)
883 TColStd_IndexedMapOfInteger aMapIndex;
884 mySelector->GetIndex( getIO(), aMapIndex );
885 if(aMapIndex.Extent() != 1 || !myBarVisibility) {
889 std::ostringstream aStr;
890 int anObjId = aMapIndex(1);
891 aStr<<"Global ID: "<<anObjId;
893 vtkIdType aVtkId = GetNodeVTKID(anObjId);
895 vtkFloatingPointType *aNodeCoord = GetNodeCoord(anObjId);
896 vtkFloatingPointType aWorldCoord[4] = {aNodeCoord[0], aNodeCoord[1], aNodeCoord[2], 1.};
898 vtkDataSet* aDataSet = GetInput();
899 vtkCellData* aDataSetAttributes = aDataSet->GetCellData();
901 if(vtkDataArray* aScalarArray = aDataSetAttributes->GetScalars()){
902 vtkFloatingPointType aVal = aScalarArray->GetTuple1(aVtkId);
904 GetScalarBarCtrl()->SetIsMarked(true);
905 GetScalarBarCtrl()->SetMarkValue(aVal);
906 GetScalarBarCtrl()->Update();
908 vtkFloatingPointType aPyramidHeight = myPickingSettings->GetPyramidHeight();
909 aPyramidHeight = aPyramidHeight*myGaussPointsPL->GetMaxPointSize();
910 myCursorPyramidSelected->Init(aPyramidHeight,
911 myPickingSettings->GetCursorSize(),
912 GetRadius(anObjId,aVtkId,aScalarArray),
913 GetMagnification(anObjId),
916 myHighlightActor->GetProperty()->GetColor());
917 myCursorPyramidSelected->SetVisibility(anIsVisible && theIsHighlight);
919 const VISU::PGaussPtsIDMapper& aGaussPtsIDMapper =
920 myGaussPointsPL->GetGaussPtsIDMapper();
921 VISU::TNamedIDMapper* aParent = aGaussPtsIDMapper->GetParent();
923 VISU::TGaussPointID aGaussPointID = myGaussPointsPL->GetObjID(anObjId);
924 VISU::TCellID aCellID = aGaussPointID.first;
925 VISU::TLocalPntID aLocalPntID = aGaussPointID.second;
926 aStr<<"\nParentCellID: "<<aCellID;
927 std::string aParentName = aParent->GetElemName(aCellID);
928 if(aParentName != "") {
929 aStr<<"\nParentCellName: '"<<aParentName<<"'";
931 aStr<<"\nLocalPntID: "<<aLocalPntID;
932 aStr<<"\nScalar: "<<aVal;
935 if(vtkDataArray* aFieldArray = aDataSetAttributes->GetArray("VISU_FIELD")){
936 if(vtkFloatArray *aFloatArray = dynamic_cast<vtkFloatArray*>(aFieldArray)){
937 int aNbComp = aFloatArray->GetNumberOfComponents();
940 while(anId < aNbComp){
941 vtkFloatingPointType aComp = aFloatArray->GetComponent(aVtkId,anId++);
951 std::string aString = aStr.str();
952 myTextActor->SetModePosition(myPickingSettings->GetInfoWindowPosition());
953 myTextActor->SetTransparency(myPickingSettings->GetInfoWindowTransparency());
954 myTextActor->SetWorldPoint(aWorldCoord);
955 myTextActor->SetText(aString.c_str());
956 myTextActor->SetVisibility(anIsVisible && theIsHighlight);
959 if(myPickingSettings->GetDisplayParentMesh()){
960 const VISU::PGaussPtsIDMapper& aGaussPtsIDMapper =
961 myGaussPointsPL->GetGaussPtsIDMapper();
962 VISU::TNamedIDMapper* aParent = aGaussPtsIDMapper->GetParent();
964 myCellSource->Reset();
965 myCellSource->Modified(); // a VTK bug
966 myCellSource->SetPoints(aParent->GetVTKOutput()->GetPoints());
968 VISU::TGaussPointID aGaussPointID = aGaussPtsIDMapper->GetObjID(anObjId);
969 vtkIdType aCellID = aGaussPointID.first;
970 vtkCell* aCell = aParent->GetElemCell(aCellID);
971 myCellSource->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
972 myCellActor->SetVisibility(anIsVisible && theIsHighlight);
973 myCellActor->SetRepresentation(VTK_WIREFRAME);
979 //----------------------------------------------------------------
982 ::SetPickingSettings(VISU_PickingSettings* thePickingSettings)
984 if(myPickingSettings == thePickingSettings)
987 if(myPickingSettings)
988 myPickingSettings->RemoveObserver(myEventCallbackCommand.GetPointer());
990 myPickingSettings = thePickingSettings;
992 if(thePickingSettings)
994 thePickingSettings->AddObserver(VISU::UpdatePickingSettingsEvent,
995 myEventCallbackCommand.GetPointer(),
997 this->UpdatePickingSettings();
1003 ::UpdatePickingSettings()
1005 if(!myPickingSettings || myPickingSettings->GetInitial())
1008 myTextActor->SetModePosition(myPickingSettings->GetInfoWindowPosition());
1009 myTextActor->SetTransparency(myPickingSettings->GetInfoWindowTransparency());
1011 vtkFloatingPointType aHeight = myGaussPointsPL->GetMaxPointSize()*myPickingSettings->GetPyramidHeight();
1012 vtkFloatingPointType aCursorSize = myPickingSettings->GetCursorSize();
1013 myCursorPyramid->SetPreferences(aHeight,aCursorSize);
1014 myCursorPyramidSelected->SetPreferences(aHeight,aCursorSize);
1016 myHighlightActor->GetProperty()->SetColor( myPickingSettings->GetColor() );
1017 myPointPicker->SetTolerance( myPickingSettings->GetPointTolerance() );
1019 Highlight(isHighlighted());
1024 //----------------------------------------------------------------
1027 ::SetInsideCursorSettings(VISU_InsideCursorSettings* theInsideCursorSettings)
1029 if(myInsideCursorSettings == theInsideCursorSettings)
1032 if(myInsideCursorSettings)
1033 myInsideCursorSettings->RemoveObserver(myEventCallbackCommand.GetPointer());
1035 myInsideCursorSettings = theInsideCursorSettings;
1037 if(theInsideCursorSettings){
1038 theInsideCursorSettings->AddObserver(VISU::UpdateInsideSettingsEvent,
1039 myEventCallbackCommand.GetPointer(),
1041 UpdateInsideCursorSettings();
1047 ::UpdateInsideCursorSettings()
1049 UpdateInsideCursorSettings( myDeviceActor );
1054 ::UpdateInsideCursorSettings( PDeviceActor theActor )
1056 if(!myInsideCursorSettings || myInsideCursorSettings->GetInitial())
1059 VISU_GaussPointsPL* aPipeline = theActor->GetPipeLine();
1061 SALOME_ExtractGeometry* anExtractGeometry = aPipeline->GetExtractGeometryFilter();
1062 vtkImplicitFunction* anImplicitFunction = anExtractGeometry->GetImplicitFunction();
1064 aPipeline->ShallowCopy(GetGaussPointsPL());
1066 aPipeline->SetImplicitFunction(anImplicitFunction); // To restore
1068 aPipeline->SetPrimitiveType( myInsideCursorSettings->GetPrimitiveType() );
1069 aPipeline->SetClamp( myInsideCursorSettings->GetClamp() );
1070 aPipeline->SetImageData( myInsideCursorSettings->GetTexture() );
1071 aPipeline->SetAlphaThreshold( myInsideCursorSettings->GetAlphaThreshold() );
1072 aPipeline->SetResolution( myInsideCursorSettings->GetResolution() );
1073 aPipeline->SetMinSize( myInsideCursorSettings->GetMinSize() );
1074 aPipeline->SetMaxSize( myInsideCursorSettings->GetMaxSize() );
1075 aPipeline->SetMagnification( myInsideCursorSettings->GetMagnification() );
1076 aPipeline->SetMagnificationIncrement( myInsideCursorSettings->GetIncrement() );
1078 if( myInsideCursorSettings->GetPrimitiveType() != VISU_OpenGLPointSpriteMapper::GeomSphere )
1079 theActor->GetProperty()->SetRepresentation( VTK_POINTS );
1081 theActor->GetProperty()->SetRepresentation( VTK_SURFACE );
1083 aPipeline->Update();
1085 Highlight(isHighlighted());
1090 //==============================================================================
1091 vtkStandardNewMacro(VISU_GaussPtsAct1);
1094 //----------------------------------------------------------------------------
1096 ::VISU_GaussPtsAct1():
1097 myInsideDeviceActor(VISU_GaussPtsDeviceActor::New()),
1098 myOutsideDeviceActor(VISU_GaussPtsDeviceActor::New()),
1099 myOutsideCursorSettings(NULL)
1101 if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::VISU_GaussPtsAct1 - this = "<<this);
1103 myEventCallbackCommand->SetCallback(VISU_GaussPtsAct1::ProcessEvents);
1105 myInsideDeviceActor->SetVisibility(false);
1106 myInsideDeviceActor->SetPickable(false);
1107 myInsideDeviceActor->Delete();
1109 myOutsideDeviceActor->SetVisibility(false);
1110 myOutsideDeviceActor->SetPickable(false);
1111 myOutsideDeviceActor->Delete();
1115 ::~VISU_GaussPtsAct1()
1117 if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::~VISU_GaussPtsAct1 - this = "<<this);
1119 SetOutsideCursorSettings(NULL);
1123 //----------------------------------------------------------------------------
1126 ::ShallowCopyPL(VISU_PipeLine* thePipeLine)
1128 if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::ShallowCopyPL - this = "<<this);
1130 Superclass::ShallowCopyPL(thePipeLine);
1132 UpdateOutsideCursorSettings();
1136 //----------------------------------------------------------------------------
1139 ::AddToRender(vtkRenderer* theRenderer)
1141 Superclass::AddToRender(theRenderer);
1143 myInsideDeviceActor->AddToRender(theRenderer);
1144 myOutsideDeviceActor->AddToRender(theRenderer);
1149 ::RemoveFromRender(vtkRenderer* theRenderer)
1151 Superclass::RemoveFromRender(theRenderer);
1153 myInsideDeviceActor->RemoveFromRender(theRenderer);
1154 myOutsideDeviceActor->RemoveFromRender(theRenderer);
1159 ::SetTransform(VTKViewer_Transform* theTransform)
1161 Superclass::SetTransform(theTransform);
1163 myInsideDeviceActor->SetTransform(theTransform);
1164 myOutsideDeviceActor->SetTransform(theTransform);
1168 //----------------------------------------------------------------------------
1171 ::SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl)
1173 if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::SetWidgetCtrl - this = "<<this);
1175 if(myWidgetCtrl == theWidgetCtrl){
1180 myInsideDeviceActor->GetPipeLine()->SetImplicitFunction(NULL);
1181 myInsideDeviceActor->SetVisibility(false);
1183 myOutsideDeviceActor->GetPipeLine()->SetImplicitFunction(NULL);
1184 myOutsideDeviceActor->SetVisibility(false);
1187 Superclass::SetWidgetCtrl(theWidgetCtrl);
1190 myInsideDeviceActor->GetPipeLine()->SetImplicitFunction(theWidgetCtrl->ImplicitFunction());
1191 myInsideDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1193 myOutsideDeviceActor->GetPipeLine()->SetImplicitFunction(theWidgetCtrl->ImplicitFunction());
1194 myOutsideDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1199 //----------------------------------------------------------------------------
1202 ::SetMapperInput(vtkDataSet* theDataSet)
1204 if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::SetMapperInput - this = "<<this);
1206 Superclass::SetMapperInput(theDataSet);
1208 if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){
1209 myInsideDeviceActor->SetPipeLine(aPipeLine);
1210 aPipeLine->Delete();
1213 if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){
1214 myOutsideDeviceActor->SetPipeLine(aPipeLine);
1215 aPipeLine->Delete();
1217 SALOME_ExtractGeometry* anExtractGeometry = aPipeLine->GetExtractGeometryFilter();
1218 anExtractGeometry->SetExtractBoundaryCells(true);
1219 anExtractGeometry->SetExtractInside(true);
1224 //----------------------------------------------------------------------------
1225 vtkFloatingPointType
1227 ::GetRadius(vtkIdType theObjID,
1229 vtkDataArray *theScalarArray)
1231 VISU_GaussPointsPL* aPipeLine = myDeviceActor->GetPipeLine();
1232 if(IsSegmentationEnabled()){
1233 if(myInsideDeviceActor->GetPipeLine()->GetNodeVTKID(theObjID) < 0)
1234 aPipeLine = myOutsideDeviceActor->GetPipeLine();
1236 aPipeLine = myInsideDeviceActor->GetPipeLine();
1238 return ::GetRadius(theVTKID,theScalarArray,aPipeLine);
1242 //----------------------------------------------------------------------------
1243 vtkFloatingPointType
1245 ::GetMagnification(vtkIdType theObjID)
1247 VISU_GaussPointsPL* aPipeLine = myDeviceActor->GetPipeLine();
1248 if(IsSegmentationEnabled()){
1249 if(myInsideDeviceActor->GetPipeLine()->GetNodeVTKID(theObjID) < 0)
1250 aPipeLine = myOutsideDeviceActor->GetPipeLine();
1252 aPipeLine = myInsideDeviceActor->GetPipeLine();
1254 return aPipeLine->GetMagnification();
1258 //----------------------------------------------------------------------------
1259 vtkFloatingPointType
1261 ::GetClamp(vtkIdType theObjID)
1263 if(IsSegmentationEnabled()){
1264 if(myInsideDeviceActor->GetPipeLine()->GetNodeVTKID(theObjID) < 0)
1265 return ::GetClamp(myOutsideDeviceActor->GetPipeLine());
1267 return ::GetClamp(myInsideDeviceActor->GetPipeLine());
1269 return Superclass::GetClamp(theObjID);
1273 //----------------------------------------------------------------
1276 ::Connect(VISU_GaussPtsAct2* theActor)
1278 mySetVisibilitySignal.connect(boost::bind(&VISU_GaussPtsAct2::SetVisibility,theActor,_1));
1283 ::SetVisibility(int theMode)
1285 if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::SetVisibility - this = "<<this);
1287 Superclass::SetVisibility(theMode);
1289 bool aVisisbility = GetVisibility();
1290 bool anIsSegementation = IsSegmentationEnabled();
1291 myDeviceActor->SetVisibility(aVisisbility && !anIsSegementation);
1292 myInsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
1293 myOutsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
1295 mySetVisibilitySignal(GetVisibility());
1298 //----------------------------------------------------------------
1301 ::UpdateInsideCursorSettings()
1303 Superclass::UpdateInsideCursorSettings( myInsideDeviceActor );
1306 //----------------------------------------------------------------
1309 ::SetOutsideCursorSettings(VISU_OutsideCursorSettings* theOutsideCursorSettings)
1311 if(myOutsideCursorSettings == theOutsideCursorSettings)
1314 if(myOutsideCursorSettings)
1315 myOutsideCursorSettings->RemoveObserver(myEventCallbackCommand.GetPointer());
1317 myOutsideCursorSettings = theOutsideCursorSettings;
1319 if(theOutsideCursorSettings)
1321 theOutsideCursorSettings->AddObserver(VISU::UpdateOutsideSettingsEvent,
1322 myEventCallbackCommand.GetPointer(),
1324 UpdateOutsideCursorSettings();
1330 ::UpdateOutsideCursorSettings()
1332 if(!myOutsideCursorSettings || myOutsideCursorSettings->GetInitial())
1335 VISU_GaussPointsPL* aPipeline = myOutsideDeviceActor->GetPipeLine();
1337 SALOME_ExtractGeometry* anExtractGeometry = aPipeline->GetExtractGeometryFilter();
1338 vtkImplicitFunction* anImplicitFunction = anExtractGeometry->GetImplicitFunction();
1339 vtkFloatingPointType aMagnification = aPipeline->GetMagnification();
1341 aPipeline->ShallowCopy(GetGaussPointsPL());
1343 aPipeline->SetImplicitFunction(anImplicitFunction); // To restore
1344 anExtractGeometry->SetExtractBoundaryCells(true);
1345 anExtractGeometry->SetExtractInside(true);
1346 aPipeline->SetMagnification( aMagnification );
1348 aPipeline->SetPrimitiveType( myOutsideCursorSettings->GetPrimitiveType() );
1350 if( myOutsideCursorSettings->GetPrimitiveType() != VISU_OpenGLPointSpriteMapper::GeomSphere )
1351 myOutsideDeviceActor->GetProperty()->SetRepresentation( VTK_POINTS );
1353 myOutsideDeviceActor->GetProperty()->SetRepresentation( VTK_SURFACE );
1355 aPipeline->SetClamp( myOutsideCursorSettings->GetClamp() );
1356 aPipeline->SetImageData( myOutsideCursorSettings->GetTexture() );
1357 aPipeline->SetAlphaThreshold( myOutsideCursorSettings->GetAlphaThreshold() );
1358 aPipeline->SetResolution( myOutsideCursorSettings->GetResolution() );
1359 aPipeline->SetSize( myOutsideCursorSettings->GetSize() );
1360 aPipeline->SetMagnification( myOutsideCursorSettings->GetMagnification() );
1361 aPipeline->SetMagnificationIncrement( myOutsideCursorSettings->GetIncrement() );
1363 if( myOutsideCursorSettings->GetUniform() )
1365 myOutsideDeviceActor->GetPSMapper()->ScalarVisibilityOff();
1366 myOutsideDeviceActor->GetPSMapper()->SetPointSpriteMode( 1 ); // Geometry mode
1367 myOutsideDeviceActor->GetProperty()->SetColor( myOutsideCursorSettings->GetColor() );
1371 myOutsideDeviceActor->GetPSMapper()->SetPointSpriteMode( 2 ); // Outside cursor mode
1372 myOutsideDeviceActor->GetPSMapper()->SetColorModeToMapScalars();
1373 myOutsideDeviceActor->GetPSMapper()->ScalarVisibilityOn();
1376 aPipeline->Update();
1378 Highlight(isHighlighted());
1384 //----------------------------------------------------------------
1387 ::ProcessEvents(vtkObject* theObject,
1388 unsigned long theEvent,
1389 void* theClientData,
1392 if(vtkObject* anObject = reinterpret_cast<vtkObject*>(theClientData))
1393 if(VISU_GaussPtsAct1* self = dynamic_cast<VISU_GaussPtsAct1*>(anObject))
1394 if(theEvent == VISU::UpdateOutsideSettingsEvent)
1395 self->UpdateOutsideCursorSettings();
1397 Superclass::ProcessEvents(theObject,theEvent,theClientData,theCallData);
1402 ::OnInteractorEvent(unsigned long theEvent)
1405 case vtkCommand::StartInteractionEvent:
1406 myDeviceActor->SetVisibility(GetVisibility());
1407 myInsideDeviceActor->SetVisibility(false);
1408 myOutsideDeviceActor->SetVisibility(false);
1410 case vtkCommand::EnableEvent:
1411 case vtkCommand::DisableEvent:
1412 case vtkCommand::EndInteractionEvent: {
1413 bool aVisisbility = GetVisibility();
1414 bool anIsSegementation = IsSegmentationEnabled();
1415 myDeviceActor->SetVisibility(aVisisbility && !anIsSegementation);
1416 myInsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
1417 myOutsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
1424 Superclass::OnInteractorEvent(theEvent);
1428 //==============================================================================
1429 vtkStandardNewMacro(VISU_GaussPtsAct2);
1432 //----------------------------------------------------------------------------
1434 ::VISU_GaussPtsAct2()
1436 if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::VISU_GaussPtsAct2 - this = "<<this);
1437 myDeviceActor->SetVisibility(false);
1441 ::~VISU_GaussPtsAct2()
1443 if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::~VISU_GaussPtsAct2 - this = "<<this);
1447 //----------------------------------------------------------------------------
1450 ::ShallowCopyPL(VISU_PipeLine* thePipeLine)
1452 if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::ShallowCopyPL - this = "<<this);
1454 Superclass::ShallowCopyPL(thePipeLine);
1458 //----------------------------------------------------------------------------
1461 ::SetMapperInput(vtkDataSet* theDataSet)
1463 if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::SetMapperInput - this = "<<this);
1465 if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){
1466 myDeviceActor->SetPipeLine(aPipeLine);
1467 myCurrentPL = aPipeLine;
1468 aPipeLine->Delete();
1470 myMapper->SetInput(myCurrentPL->GetPickableDataSet());
1471 SetMapper(myMapper.GetPointer());
1475 //----------------------------------------------------------------------------
1478 ::SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl)
1480 if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::SetWidgetCtrl - this = "<<this);
1482 if(myWidgetCtrl == theWidgetCtrl)
1486 theWidgetCtrl->RemoveObserver(myEventCallbackCommand.GetPointer());
1487 myDeviceActor->GetPipeLine()->SetImplicitFunction(NULL);
1488 myDeviceActor->SetVisibility(false);
1491 Superclass::SetWidgetCtrl(theWidgetCtrl);
1494 myDeviceActor->GetPipeLine()->SetImplicitFunction(theWidgetCtrl->ImplicitFunction());
1495 myDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1500 //----------------------------------------------------------------------------
1503 ::SetVisibility(int theMode)
1505 if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::SetVisibility - this = "<<this);
1507 Superclass::SetVisibility(theMode);
1509 myDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1514 ::OnInteractorEvent(unsigned long theEvent)
1517 case vtkCommand::EnableEvent:
1518 case vtkCommand::DisableEvent:
1519 myDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1520 if(theEvent == vtkCommand::EnableEvent)
1523 case vtkCommand::EndInteractionEvent:
1529 Superclass::OnInteractorEvent(theEvent);