1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
23 // VISU OBJECT : interactive object for VISU entities implementation
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_PickingSettings.h"
34 #include "VISU_WidgetCtrl.hxx"
35 #include "VISU_SphereWidget.hxx"
36 #include "VISU_OpenGLPointSpriteMapper.hxx"
37 #include "VISU_ScalarBarCtrl.hxx"
38 #include "VISU_ScalarBarActor.hxx"
40 #include "VISU_Event.h"
41 #include "SVTK_Actor.h"
42 #include "VTKViewer_FramedTextActor.h"
43 #include <SALOME_ExtractPolyDataGeometry.h>
45 #include <vtkCamera.h>
46 #include <vtkRenderer.h>
47 #include <vtkPointPicker.h>
48 #include <vtkMatrix4x4.h>
49 #include <vtkScalarBarWidget.h>
50 #include <vtkTextMapper.h>
51 #include <vtkTextProperty.h>
52 #include <vtkImplicitBoolean.h>
53 #include <vtkImplicitFunctionCollection.h>
56 #include <vtkPointData.h>
57 #include <vtkCellData.h>
58 #include <vtkDataArray.h>
60 #include <vtkSphereSource.h>
61 #include <vtkPolyDataMapper.h>
62 #include <vtkPolyData.h>
64 #include <vtkTransform.h>
66 #include <vtkObjectFactory.h>
67 #include <vtkCallbackCommand.h>
68 #include <vtkInteractorStyle.h>
69 #include <vtkRenderWindowInteractor.h>
70 #include <vtkOutlineSource.h>
73 #include <boost/bind.hpp>
75 #include <vtkUnstructuredGrid.h>
76 #include <vtkPolyDataMapper.h>
77 #include <vtkRenderWindow.h>
78 #include <vtkCellArray.h>
79 #include <vtkWarpVector.h>
80 #include <vtkCellDataToPointData.h>
84 #include <vtkViewport.h>
86 #include "utilities.h"
89 static int MYDEBUG = 0;
90 static int MYDEBUG1 = 0;
91 static int MYDEBUG2 = 0;
93 static int MYDEBUG = 0;
94 static int MYDEBUG1 = 0;
95 static int MYDEBUG2 = 0;
102 CheckIsSameValue(vtkFloatingPointType theTarget,
103 vtkFloatingPointType theSource)
105 static vtkFloatingPointType TOL = 10.0 / VTK_LARGE_FLOAT;
106 return fabs(theTarget - theSource) < TOL;
110 CheckIsSameVector(vtkFloatingPointType* theTarget,
111 vtkFloatingPointType* theSource,
114 for ( size_t anId = 0; anId < theLength; anId++ ) {
115 if ( !CheckIsSameValue( theTarget[ anId ], theSource[ anId ] ) )
124 //============================================================================
125 vtkStandardNewMacro(VISU_GaussPtsAct);
127 //----------------------------------------------------------------------------
129 ::VISU_GaussPtsAct():
130 myEventCallbackCommand(vtkCallbackCommand::New()),
132 myDeviceActor(VISU_GaussPtsDeviceActor::New()),
134 myGaussPointsPL(NULL),
135 myLastPreHighlightObjID(-1),
136 myCursorPyramid(VISU_CursorPyramid::New()),
137 myCursorPyramidSelected(VISU_CursorPyramid::New()),
138 myCellSource(vtkUnstructuredGrid::New()),
139 myCellActor(SVTK_Actor::New()),
140 myScalarBarCtrl(VISU_ScalarBarCtrl::New()),
141 myBarVisibility(true),
142 myInsideCursorSettings(NULL),
144 myMapper(vtkPolyDataMapper::New()),
145 myPolyDataExtractor(SALOME_ExtractPolyDataGeometry::New()),
146 myFunction(vtkImplicitBoolean::New()),
147 myWarpVector(vtkWarpVector::New()),
148 myCellDataToPointData(vtkCellDataToPointData::New())
150 if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::VISU_GaussPtsAct - this = "<<this);
152 myEventCallbackCommand->Delete();
153 myDeviceActor->Delete();
155 myCursorPyramid->Delete();
156 myCursorPyramid->SetPickable(0);
157 myCursorPyramid->SetVisibility(0);
159 myCursorPyramidSelected->Delete();
160 myCursorPyramidSelected->SetPickable(0);
161 myCursorPyramidSelected->SetVisibility(0);
163 myCellSource->Delete();
164 myCellActor->Delete();
166 myEventCallbackCommand->SetClientData(this);
167 myEventCallbackCommand->SetCallback(VISU_GaussPtsAct::ProcessEvents);
169 vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
171 myDeviceActor->SetProperty(GetProperty());
172 myDeviceActor->SetUserMatrix(aMatrix);
173 myDeviceActor->SetVisibility(true);
174 myDeviceActor->SetPickable(false);
176 myCellSource->Allocate();
177 myCellActor->Initialize();
178 myCellActor->SetRepresentation(VTK_WIREFRAME);
179 myCellActor->SetSource(myCellSource.GetPointer());
181 myCellActor->SetVisibility(0);
182 myCellActor->SetPickable(0);
183 myCellActor->GetProperty()->SetAmbient(1.0);
184 myCellActor->GetProperty()->SetDiffuse(0.0);
186 myScalarBarCtrl->Delete();
191 myWarpVector->Delete();
192 myCellDataToPointData->Delete();
194 myPolyDataExtractor->SetImplicitFunction(myFunction);
195 //myPolyDataExtractor->ExtractBoundaryCellsOn();
197 myFunction->SetOperationTypeToIntersection();
198 myPolyDataExtractor->Delete();
199 myFunction->Delete();
201 if( VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get() )
202 aPickingSettings->AddObserver(VISU::UpdatePickingSettingsEvent,
203 myEventCallbackCommand.GetPointer(),
208 ::~VISU_GaussPtsAct()
210 if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::~VISU_GaussPtsAct - this = "<<this);
213 SetInsideCursorSettings(NULL);
217 //----------------------------------------------------------------------------
220 ::SetPipeLine(VISU_PipeLine* thePipeLine)
222 if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::SetPipeLine - this = "<<this);
224 myGaussPointsPL = dynamic_cast<VISU_GaussPointsPL*>(thePipeLine);
226 Superclass::SetPipeLine(thePipeLine);
233 return myGaussPointsPL.GetPointer();
236 //----------------------------------------------------------------------------
239 ::DeepCopy(VISU_Actor *theActor)
241 if(VISU_GaussPtsAct* anActor = dynamic_cast<VISU_GaussPtsAct*>(theActor)){
242 Superclass::DeepCopy(theActor);
243 SetBarVisibility(anActor->GetBarVisibility());
247 //----------------------------------------------------------------------------
250 ::ShallowCopyPL(VISU_PipeLine* thePipeLine)
252 if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::ShallowCopyPL - this = "<<this);
254 Superclass::ShallowCopyPL(thePipeLine);
256 UpdateInsideCursorSettings();
258 Highlight(isHighlighted());
262 //----------------------------------------------------------------------------
268 //vtkMapper* aMapper = myCurrentPL->GetPointSpriteMapper();
272 return myMapper.GetPointer();
275 vtkFloatingPointType*
279 return GetMapper()->GetBounds();
286 return GetMapper()->GetInput();
297 //----------------------------------------------------------------------------
302 vtkDataSet* aDataSet = myDeviceActor->GetMapper()->GetInput();
303 unsigned long int aSize = aDataSet->GetActualMemorySize() * 1024;
305 aSize += Superclass::GetMemorySize();
310 //----------------------------------------------------------------------------
313 ::AddToRender(vtkRenderer* theRenderer)
315 if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::AddToRender - this = "<<this);
317 Superclass::AddToRender(theRenderer);
319 myDeviceActor->AddToRender(theRenderer);
321 theRenderer->AddActor(myCellActor.GetPointer());
323 myCursorPyramid->AddToRender(theRenderer);
324 myCursorPyramidSelected->AddToRender(theRenderer);
325 myScalarBarCtrl->AddToRender(theRenderer);
330 ::RemoveFromRender(vtkRenderer* theRenderer)
332 if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::RemoveFromRender - this = "<<this);
334 myDeviceActor->RemoveFromRender(theRenderer);
336 theRenderer->RemoveActor(myCellActor.GetPointer());
338 myCursorPyramid->RemoveFromRender(theRenderer);
339 myCursorPyramidSelected->RemoveFromRender(theRenderer);
340 myScalarBarCtrl->RemoveFromRender(theRenderer);
342 Superclass::RemoveFromRender(theRenderer);
347 ::SetTransform(VTKViewer_Transform* theTransform)
349 Superclass::SetTransform(theTransform);
351 myDeviceActor->SetTransform(theTransform);
356 ::RenderOpaqueGeometry(vtkViewport *viewport)
358 GetMatrix(myDeviceActor->GetUserMatrix());
364 ::RenderTranslucentGeometry(vtkViewport *viewport)
366 GetMatrix(myDeviceActor->GetUserMatrix());
371 //----------------------------------------------------------------------------
374 ::SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl)
376 if(myWidgetCtrl == theWidgetCtrl)
380 MESSAGE("VISU_GaussPtsAct::SetWidgetCtrl - this = "<<this<<"; theWidget = "<<theWidgetCtrl);
383 myWidgetCtrl->RemoveObserver(myEventCallbackCommand.GetPointer());
386 theWidgetCtrl->AddObserver(vtkCommand::EnableEvent,
387 myEventCallbackCommand.GetPointer(),
389 theWidgetCtrl->AddObserver(vtkCommand::DisableEvent,
390 myEventCallbackCommand.GetPointer(),
392 theWidgetCtrl->AddObserver(vtkCommand::StartInteractionEvent,
393 myEventCallbackCommand.GetPointer(),
395 theWidgetCtrl->AddObserver(vtkCommand::EndInteractionEvent,
396 myEventCallbackCommand.GetPointer(),
400 myWidgetCtrl = theWidgetCtrl;
405 ::GetChangeMagnification()
407 return myChangeMagnification;
412 ::ChangeMagnification( bool up )
414 myEventCallbackCommand->SetAbortFlag(1);
416 vtkFloatingPointType aMagnification = myInsideCursorSettings->GetMagnification();
417 vtkFloatingPointType anIncrement = myInsideCursorSettings->GetIncrement();
418 vtkFloatingPointType coefficient = up ? anIncrement : 1 / anIncrement;
420 myInsideCursorSettings->SetMagnification( aMagnification * coefficient );
421 myInsideCursorSettings->InvokeEvent(VISU::UpdateFromSettingsEvent,NULL);
426 //----------------------------------------------------------------------------
430 CreatePipeLine(VISU_GaussPointsPL* thePipeLine)
432 VISU_GaussPointsPL* aPipeLine = VISU_GaussPointsPL::New();
433 aPipeLine->ShallowCopy(thePipeLine, true);
441 ::SetMapperInput(vtkDataSet* theDataSet)
443 if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::SetMapperInput - this = "<<this);
445 myDeviceActor->SetExtractor(myPolyDataExtractor);
446 myDeviceActor->SetPipeLine(GetGaussPointsPL());
447 myCurrentPL = myDeviceActor->GetPipeLine();
449 //SetMapper(myCurrentPL->GetPointSpriteMapper());
451 // myPolyDataExtractor->SetInput(myCurrentPL->GetPickableDataSet());
452 //myMapper->SetInput(myPolyDataExtractor->GetOutput());
453 myMapper->SetInput(myCurrentPL->GetPickableDataSet());
454 SetMapper(myMapper.GetPointer());
458 //----------------------------------------------------------------------------
463 GetRadius(vtkIdType theVTKID,
464 vtkDataArray *theScalarArray,
465 VISU_GaussPointsPL* theGaussPointsPL)
467 vtkFloatingPointType aRadius = 0.5;
468 if(theGaussPointsPL->GetPointSpriteMapper()->GetPointSpriteMode() == 1) // Geometry mode
469 aRadius *= theGaussPointsPL->GetSize() * theGaussPointsPL->GetAverageCellSize();
470 else if(theGaussPointsPL->GetBicolor()){
471 vtkFloatingPointType aVal = theScalarArray->GetTuple1(theVTKID);
473 aRadius *= theGaussPointsPL->GetMaxSize();
475 aRadius *= theGaussPointsPL->GetMinSize();
476 aRadius *= theGaussPointsPL->GetAverageCellSize();
478 aRadius *= theGaussPointsPL->GetPointSize(theVTKID,theScalarArray);
486 ::GetRadius(vtkIdType theObjID,
488 vtkDataArray *theScalarArray)
490 return ::GetRadius(theVTKID,theScalarArray,myDeviceActor->GetPipeLine());
493 //----------------------------------------------------------------------------
496 ::GetMagnification(vtkIdType theObjID)
498 return myDeviceActor->GetPipeLine()->GetMagnification();
502 //----------------------------------------------------------------------------
507 GetClamp(VISU_GaussPointsPL* theGaussPointsPL)
509 vtkFloatingPointType aClamp = theGaussPointsPL->GetClamp();
510 if(theGaussPointsPL->GetPrimitiveType() == VISU_OpenGLPointSpriteMapper::GeomSphere)
518 ::GetClamp(vtkIdType theObjID)
520 return ::GetClamp(myDeviceActor->GetPipeLine());
524 //----------------------------------------------------------------------------
527 ::SetOpacity(vtkFloatingPointType theValue)
529 GetGaussPointsPL()->SetOpacity(theValue);
530 Superclass::SetOpacity(theValue);
534 //----------------------------------------------------------------------------
537 ::SetFactory(VISU::TActorFactory* theActorFactory)
539 using namespace VISU;
540 myGaussPtsActorFactory = dynamic_cast<TGaussPtsActorFactory*>(theActorFactory);
541 myUpdatePrs3dSignal.connect(boost::bind(&TGaussPtsActorFactory::UpdateFromActor,
542 myGaussPtsActorFactory,
544 Superclass::SetFactory(theActorFactory);
547 VISU::TGaussPtsActorFactory*
549 ::GetGaussPtsFactory()
551 return myGaussPtsActorFactory;
555 //----------------------------------------------------------------------------
558 ::SetVisibility(int theMode)
560 Superclass::SetVisibility(theMode);
561 myDeviceActor->SetVisibility(GetVisibility()); // VSV
562 myScalarBarCtrl->SetVisibility(theMode);
567 ::IsSegmentationEnabled()
569 return myWidgetCtrl && myWidgetCtrl->GetEnabled();
573 //----------------------------------------------------------------------------
576 ::SetBarVisibility(bool theMode)
578 myBarVisibility = theMode;
579 myScalarBarCtrl->SetCtrlVisibility(theMode);
580 myScalarBarCtrl->SetVisibility(GetVisibility());
587 return myBarVisibility;
594 return myScalarBarCtrl.GetPointer();
597 //----------------------------------------------------------------------------
600 ::SetInteractor(vtkRenderWindowInteractor* theInteractor)
602 if(theInteractor == myInteractor)
606 myInteractor->RemoveObserver(myEventCallbackCommand.GetPointer());
609 theInteractor->AddObserver(vtkCommand::CharEvent,
610 myEventCallbackCommand.GetPointer(),
612 theInteractor->AddObserver(VISU::SetSMDecreaseMagnificationEvent,
613 myEventCallbackCommand.GetPointer(),
615 theInteractor->AddObserver(VISU::SetSMIncreaseMagnificationEvent,
616 myEventCallbackCommand.GetPointer(),
619 Superclass::SetInteractor(theInteractor);
623 //-------------------------------------------------------------------------
626 ::ProcessEvents(vtkObject* vtkNotUsed(theObject),
627 unsigned long theEvent,
629 void* vtkNotUsed(theCallData))
631 if(vtkObject* anObject = reinterpret_cast<vtkObject*>(theClientData))
632 if(VISU_GaussPtsAct* self = dynamic_cast<VISU_GaussPtsAct*>(anObject)) {
633 if(theEvent == VISU::UpdateInsideSettingsEvent)
634 self->UpdateInsideCursorSettings();
636 self->OnInteractorEvent(theEvent);
640 //-------------------------------------------------------------------------
643 ::OnInteractorEvent(unsigned long theEvent)
646 case vtkCommand::CharEvent: {
647 switch(myInteractor->GetKeyCode()) {
651 if( IsSegmentationEnabled() )
653 this->ChangeMagnification( myInteractor->GetShiftKey() );
657 myChangeMagnification = myInteractor->GetShiftKey();
663 if( IsSegmentationEnabled() && myWidgetCtrl->IsSphereActive() )
665 VISU_SphereWidget* aSphereWidget = myWidgetCtrl->GetSphereWidget();
666 aSphereWidget->ChangeRadius( myInteractor->GetShiftKey() );
667 myWidgetCtrl->InvokeEvent(vtkCommand::EndInteractionEvent,NULL);
668 myWidgetCtrl->GetInteractor()->Render();
675 myUpdatePrs3dSignal(this);
678 case VISU::SetSMDecreaseMagnificationEvent:
679 case VISU::SetSMIncreaseMagnificationEvent:
680 myChangeMagnification = theEvent == VISU::SetSMIncreaseMagnificationEvent;
681 myUpdatePrs3dSignal(this);
683 case VISU::UpdatePickingSettingsEvent:
684 UpdatePickingSettings();
686 case vtkCommand::EndInteractionEvent:
687 case vtkCommand::EnableEvent:
688 case vtkCommand::DisableEvent:
689 myCurrentPL->GetMapper()->Update();
690 Highlight(isHighlighted());
697 //----------------------------------------------------------------------------
702 if(vtkMapper* aMapper = myDeviceActor->GetMapper()){
703 if(vtkDataSet* aDataSet= aMapper->GetInput()){
705 myIsInfinite = aDataSet->GetNumberOfCells() < 2;
711 //----------------------------------------------------------------------------
716 if(Superclass::GetPickable()){
717 if(vtkMapper* aMapper = GetMapper()){
718 if(vtkDataSet* aDataSet= aMapper->GetInput()){
720 return aDataSet->GetNumberOfCells() > 0;
728 //----------------------------------------------------------------------------
731 ::PreHighlight(vtkInteractorStyle* theInteractorStyle,
732 SVTK_SelectionEvent* theSelectionEvent,
735 if ( !GetPickable() )
738 myPreHighlightActor->SetVisibility(false);
739 myCursorPyramid->SetVisibility(false);
741 /* if (!myBarVisibility)
746 myLastPreHighlightObjID = -1;
748 Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
750 if(aSelectionMode == ActorSelection || !theIsHighlight)
751 return Superclass::PreHighlight(theInteractorStyle,
755 bool anIsChanged = (mySelectionMode != aSelectionMode);
756 bool anIsPreselected = myIsPreselected;
757 myIsPreselected = false;
759 VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
761 if(aSelectionMode == GaussPointSelection && theIsHighlight){
762 SVTK::TPickLimiter aPickLimiter( myPointPicker, this );
763 myPointPicker->Pick(theSelectionEvent->myX,
764 theSelectionEvent->myY,
766 theInteractorStyle->GetCurrentRenderer());
768 if(myPointPicker->GetActor() != this)
769 return (anIsPreselected != myIsPreselected);
771 vtkIdType aVtkId = myPointPicker->GetPointId();
773 if(aVtkId >= 0 && mySelector->IsValid(this,aVtkId,true) && hasIO()){
774 vtkIdType anObjId = GetNodeObjId( aVtkId );
775 myIsPreselected = (anObjId >= 0);
777 anIsChanged = (myLastPreHighlightObjID != anObjId);
779 vtkFloatingPointType* aNodeCoord = GetNodeCoord(anObjId);
780 //Take into account translation
781 vtkFloatingPointType aLocalNodeCoord[3];
782 this->Transform->Push();
783 this->Transform->PostMultiply();
784 this->Transform->Identity();
786 this->Transform->Translate(this->Position[0],
790 this->Transform->GetPosition(aPosition);
792 aLocalNodeCoord[0] = aNodeCoord[0] + aPosition[0];
793 aLocalNodeCoord[1] = aNodeCoord[1] + aPosition[1];
794 aLocalNodeCoord[2] = aNodeCoord[2] + aPosition[2];
796 vtkDataSet* aDataSet = GetInput();
797 vtkPointData* aPointData = aDataSet->GetPointData();
798 if(vtkDataArray *aScalarArray = aPointData->GetScalars()){
799 vtkFloatingPointType aPyramidHeight = aPickingSettings->GetPyramidHeight();
800 aPyramidHeight = aPyramidHeight*myGaussPointsPL->GetMaxPointSize();
801 //vtkFloatingPointType aColor[3] = myPreHighlightActor->GetProperty()->GetColor();
802 vtkFloatingPointType aColor[3];
803 theInteractorStyle->GetCurrentRenderer()->GetBackground( aColor );
804 aColor[0] = 1. - aColor[0];
805 aColor[1] = 1. - aColor[1];
806 aColor[2] = 1. - aColor[2];
808 myCursorPyramid->Init(aPyramidHeight,
809 aPickingSettings->GetCursorSize(),
810 GetRadius(anObjId,aVtkId,aScalarArray),
811 GetMagnification(anObjId),
816 this->Transform->Pop();
817 myLastPreHighlightObjID = anObjId;
819 myCursorPyramid->SetVisibility(true);
824 mySelectionMode = aSelectionMode;
825 anIsChanged |= (anIsPreselected != myIsPreselected);
831 //----------------------------------------------------------------------------
834 ChangeZoom(VISU_PickingSettings *thePickingSettings,
835 vtkRenderer* theRenderer,
836 vtkIdType theInitialHasIndex,
837 vtkIdType theCurrentHasIndex)
839 if( (theInitialHasIndex + theCurrentHasIndex == 1) && thePickingSettings){
840 vtkCamera *aCamera = theRenderer->GetActiveCamera();
842 vtkFloatingPointType aZoomFactor = thePickingSettings->GetZoomFactor();
843 double aScale = aCamera->GetParallelScale();
844 if ( !theInitialHasIndex && theCurrentHasIndex ) {
845 aCamera->SetParallelScale( aScale/aZoomFactor );
848 aCamera->SetParallelScale( aScale*aZoomFactor );
856 ::Highlight(vtkInteractorStyle* theInteractorStyle,
857 SVTK_SelectionEvent* theSelectionEvent,
860 if ( !GetPickable() )
863 // int anInitialHasIndex = myIsSubElementsHighlighted && mySelectionMode == GaussPointSelection;
864 Handle(SALOME_InteractiveObject) anIO = getIO();
865 // myIsSubElementsHighlighted = false;
867 Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
869 if(!theIsHighlight && aSelectionMode == GaussPointSelection){
870 mySelector->RemoveIObject(anIO);
872 /* ChangeZoom(myPickingSettings,
881 /* if (!myBarVisibility)
885 if(aSelectionMode == ActorSelection)
886 return Superclass::Highlight(theInteractorStyle,
890 if(aSelectionMode == GaussPointSelection && !theSelectionEvent->myIsRectangle){
891 vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer();
893 SVTK::TPickLimiter aPickLimiter( myPointPicker, this );
894 myPointPicker->Pick(theSelectionEvent->myX,
895 theSelectionEvent->myY,
899 if(myPointPicker->GetActor() != this) {
900 mySelector->ClearIObjects();
902 /* ChangeZoom(myPickingSettings,
911 vtkIdType aVtkId = myPointPicker->GetPointId();
912 if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId, true ) && hasIO()) {
913 vtkIdType anObjId = GetNodeObjId( aVtkId );
915 // myIsHighlighted = true;
916 // Update the Selector
917 if(mySelector->IsSelected(myIO))
918 mySelector->AddOrRemoveIndex(myIO,anObjId,theSelectionEvent->myIsShift);
920 if(!theSelectionEvent->myIsShift){
921 mySelector->ClearIObjects();
923 mySelector->AddOrRemoveIndex(myIO,anObjId,theSelectionEvent->myIsShift);
924 mySelector->AddIObject(this);
927 vtkFloatingPointType* aNodeCoord = GetNodeCoord(anObjId);
930 vtkRenderWindowInteractor* anInteractor = theInteractorStyle->GetInteractor();
931 vtkFloatingPointType aDollyWas = anInteractor->GetDolly();
932 int aNumberOfFlyFramesWas = anInteractor->GetNumberOfFlyFrames();
934 anInteractor->SetDolly(0.);
935 anInteractor->SetNumberOfFlyFrames(myPickingSettings->GetStepNumber());
936 anInteractor->FlyTo(aRenderer,aNodeCoord);
937 aRenderer->ResetCameraClippingRange();
938 anInteractor->SetDolly(aDollyWas);
939 anInteractor->SetNumberOfFlyFrames(aNumberOfFlyFramesWas);
941 anInteractor->InvokeEvent(SVTK::ChangeRotationPoint, aNodeCoord);*/
943 mySelectionMode = aSelectionMode;
945 /* ChangeZoom(myPickingSettings,
952 }// if( anObjId >= 0 ) {
953 }//if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId, true ) && hasIO())
954 }//if(!theSelectionEvent->myIsRectangle){
956 /* ChangeZoom(myPickingSettings,
967 void VISU_GaussPtsAct::SetPosition(double _arg[3]){
968 Superclass::SetPosition(_arg);
969 Highlight(isHighlighted());
972 //==================================================================
973 // function : Highlight
975 //==================================================================
978 ::Highlight(bool theIsHighlight)
980 if(!mySelector.GetPointer())
983 VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
985 Selection_Mode aSelectionMode = mySelector->SelectionMode();
987 bool anInitialHasIndex = isSubElementsHighlighted() && mySelectionMode == GaussPointSelection;
989 TColStd_IndexedMapOfInteger aMapIndex;
990 mySelector->GetIndex( getIO(), aMapIndex );
991 bool aCurrentHasIndex = aMapIndex.Extent() == 1;
992 bool anIsVisible = GetVisibility() && aCurrentHasIndex && theIsHighlight;
993 bool aShowTextActor = aPickingSettings->GetInfoWindowEnabled();
994 bool aShowCellActor = aPickingSettings->GetDisplayParentMesh();
996 myOutlineActor->SetVisibility(false);
997 myCursorPyramid->SetVisibility(false);
998 myTextActor->SetVisibility(anIsVisible && aShowTextActor);
999 myCellActor->SetVisibility(anIsVisible && aShowCellActor);
1000 GetScalarBarCtrl()->SetIsMarked(anIsVisible);
1001 myCursorPyramidSelected->SetVisibility(anIsVisible);
1002 //GetScalarBarCtrl()->Update();
1004 myIsSubElementsHighlighted = aCurrentHasIndex;
1006 // Zoom if necessary
1007 if( GetVisibility() && aPickingSettings->GetCameraMovementEnabled() )
1009 ChangeZoom(aPickingSettings,
1015 if( aSelectionMode == ActorSelection ) {
1016 Superclass::Highlight(theIsHighlight);
1023 if( aSelectionMode != GaussPointSelection )
1026 if ( !aCurrentHasIndex || !myBarVisibility )
1029 // myTextActor->SetVisibility(anIsVisible);
1030 // myCellActor->SetVisibility(anIsVisible && myPickingSettings->GetDisplayParentMesh());
1031 // GetScalarBarCtrl()->SetIsMarked(anIsVisible);
1032 // myCursorPyramidSelected->SetVisibility(anIsVisible);
1033 //GetScalarBarCtrl()->Update();
1035 // to fix a bug with incorrect representation after the first highlight action
1036 myIsHighlighted = aCurrentHasIndex;
1038 // Zoom if necessary
1039 // ChangeZoom(myPickingSettings,
1041 // anInitialHasIndex,
1042 // aCurrentHasIndex);
1044 // TColStd_IndexedMapOfInteger aMapIndex;
1045 mySelector->GetIndex( getIO(), aMapIndex );
1046 if(aMapIndex.Extent() != 1 || !myBarVisibility) {
1050 vtkRenderer *aRenderer = GetRenderer();
1051 vtkCamera* aCamera = aRenderer->GetActiveCamera();
1053 int anObjId = aMapIndex(1);
1054 vtkFloatingPointType* aNodeCoord = GetNodeCoord(anObjId);
1057 //Take into account translation
1058 vtkFloatingPointType aLocalNodeCoord[3];
1059 this->Transform->Push();
1060 this->Transform->PostMultiply();
1061 this->Transform->Identity();
1062 this->Transform->Translate(this->Position[0],
1065 double aPosition[3];
1066 this->Transform->GetPosition(aPosition);
1067 aLocalNodeCoord[0] = aNodeCoord[0] + aPosition[0];
1068 aLocalNodeCoord[1] = aNodeCoord[1] + aPosition[1];
1069 aLocalNodeCoord[2] = aNodeCoord[2] + aPosition[2];
1070 this->Transform->Pop();
1072 vtkFloatingPointType aFocalPnt[3];
1073 aCamera->GetFocalPoint(aFocalPnt);
1075 if ( CheckIsSameVector(aLocalNodeCoord, aFocalPnt, 3 ) )
1079 if( anIsVisible && aPickingSettings->GetCameraMovementEnabled() )
1081 vtkRenderWindowInteractor* anInteractor = myInteractor;
1082 vtkFloatingPointType aDollyWas = anInteractor->GetDolly();
1083 int aNumberOfFlyFramesWas = anInteractor->GetNumberOfFlyFrames();
1085 anInteractor->SetDolly(0.0);
1086 anInteractor->SetNumberOfFlyFrames(aPickingSettings->GetStepNumber());
1087 anInteractor->FlyTo(aRenderer, aNodeCoord);
1088 aRenderer->ResetCameraClippingRange();
1089 anInteractor->SetDolly(aDollyWas);
1090 anInteractor->SetNumberOfFlyFrames(aNumberOfFlyFramesWas);
1091 anInteractor->InvokeEvent(SVTK::ChangeRotationPoint, aNodeCoord);
1094 std::ostringstream aStr;
1095 // int anObjId = aMapIndex(1);
1096 aStr<<"Global ID: "<<anObjId;
1098 vtkIdType aVtkId = GetNodeVTKID(anObjId);
1100 vtkFloatingPointType aWorldCoord[4] = {aLocalNodeCoord[0], aLocalNodeCoord[1], aLocalNodeCoord[2], 1.};
1102 vtkDataSet* aDataSet = GetInput();
1103 vtkPointData* aDataSetAttributes = aDataSet->GetPointData();
1105 if(vtkDataArray* aScalarArray = aDataSetAttributes->GetScalars()){
1106 vtkFloatingPointType aVal = aScalarArray->GetTuple1(aVtkId);
1108 // GetScalarBarCtrl()->SetIsMarked(true);
1109 GetScalarBarCtrl()->SetMarkValue(aVal);
1110 GetScalarBarCtrl()->Update();
1112 vtkFloatingPointType aPyramidHeight = aPickingSettings->GetPyramidHeight();
1113 aPyramidHeight = aPyramidHeight*myGaussPointsPL->GetMaxPointSize();
1114 myCursorPyramidSelected->Init(aPyramidHeight,
1115 aPickingSettings->GetCursorSize(),
1116 GetRadius(anObjId,aVtkId,aScalarArray),
1117 GetMagnification(anObjId),
1120 myHighlightActor->GetProperty()->GetColor());
1121 myCursorPyramidSelected->SetVisibility(anIsVisible && theIsHighlight);
1123 const VISU::PGaussPtsIDMapper& aGaussPtsIDMapper =
1124 myGaussPointsPL->GetGaussPtsIDMapper();
1125 VISU::TNamedIDMapper* aParent = aGaussPtsIDMapper->GetParent();
1127 VISU::TGaussPointID aGaussPointID = myGaussPointsPL->GetObjID(anObjId);
1128 VISU::TCellID aCellID = aGaussPointID.first;
1129 VISU::TLocalPntID aLocalPntID = aGaussPointID.second;
1130 aStr<<"\nParentCellID: "<<aCellID;
1131 std::string aParentName = aParent->GetElemName(aCellID);
1132 if(aParentName != "") {
1133 aStr<<"\nParentCellName: '"<<aParentName<<"'";
1135 aStr<<"\nLocalPntID: "<<aLocalPntID;
1136 aStr<<"\nScalar: "<<aVal;
1139 if(vtkDataArray* aFieldArray = aDataSetAttributes->GetArray("VISU_FIELD")){
1140 int aNbComp = aFieldArray->GetNumberOfComponents();
1141 std::vector<vtkFloatingPointType> aTuple(aNbComp);
1142 aFieldArray->GetTuple(aVtkId, &aTuple[0]);
1146 while(anId < aNbComp){
1147 vtkFloatingPointType aComp = aTuple[anId++];
1156 std::string aString = aStr.str();
1157 myTextActor->SetModePosition(aPickingSettings->GetInfoWindowPosition());
1158 myTextActor->SetTransparency(aPickingSettings->GetInfoWindowTransparency());
1159 myTextActor->SetWorldPoint(aWorldCoord);
1160 myTextActor->SetText(aString.c_str());
1161 myTextActor->SetMoveFrameFlag(1);
1162 myTextActor->SetVisibility(anIsVisible && theIsHighlight && aShowTextActor);
1165 const VISU::PGaussPtsIDMapper& aGaussPtsIDMapper = myGaussPointsPL->GetGaussPtsIDMapper();
1166 VISU::TNamedIDMapper* aParent = aGaussPtsIDMapper->GetParent();
1168 myCellSource->Reset();
1169 myCellSource->Modified(); // a VTK bug
1170 vtkUnstructuredGrid* aCellDataSet = aParent->GetUnstructuredGridOutput();
1172 // get parent cell and insert it to myCellSource
1173 VISU::TGaussPointID aGaussPointID = aGaussPtsIDMapper->GetObjID(anObjId);
1174 vtkIdType aCellID = aGaussPointID.first;
1175 vtkCell* aCell = aParent->GetElemCell(aCellID);
1176 myCellSource->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
1178 if (myGaussPointsPL->GetIsDeformed()) {
1179 // find neighbour cells ids
1180 vtkIdList* aNeighbourCells = vtkIdList::New();
1181 aNeighbourCells->Allocate(VTK_CELL_SIZE);
1183 vtkIdList* aCellPoints = aCell->GetPointIds();
1185 vtkIdList *aPointCells = vtkIdList::New();
1186 aPointCells->Allocate(VTK_CELL_SIZE);
1188 vtkIdType aNbPoints = aCellPoints->GetNumberOfIds();
1189 for (vtkIdType i = 0; i < aNbPoints; i++) {
1190 aCellDataSet->GetPointCells(aCellPoints->GetId(i), aPointCells);
1193 vtkIdType aNbCells = aPointCells->GetNumberOfIds();
1194 for (vtkIdType j = 0; j < aNbCells; j++)
1195 aNeighbourCells->InsertUniqueId(aPointCells->GetId(j));
1198 aPointCells->Delete();
1201 vtkDataArray* anInputVectors = aDataSetAttributes->GetVectors();
1202 if (!anInputVectors)
1205 // insert neighbour cells to the special dataset
1206 vtkUnstructuredGrid *aCellsToWarp = vtkUnstructuredGrid::New();
1207 aCellsToWarp->SetPoints(aCellDataSet->GetPoints());
1209 vtkIdType aNbNeighbourCells = aNeighbourCells->GetNumberOfIds();
1211 vtkDataArray *aVectorsToSet = vtkDataArray::CreateDataArray(anInputVectors->GetDataType());
1212 aVectorsToSet->SetNumberOfComponents(3);
1213 aVectorsToSet->SetNumberOfTuples(aNbNeighbourCells);
1215 vtkDataArray *aCellVectors = vtkDataArray::CreateDataArray(anInputVectors->GetDataType());
1216 aCellVectors->SetNumberOfComponents(3);
1218 int aNbComp = anInputVectors->GetNumberOfComponents();
1219 std::vector<vtkFloatingPointType> aTuple(aNbComp);
1221 for (vtkIdType i = 0; i < aNbNeighbourCells; i++) {
1222 vtkIdType aVTKCellId = aNeighbourCells->GetId(i);
1223 vtkIdType anObjCellId = aParent->GetElemObjID(aVTKCellId);
1225 vtkCell* aCurCell = aParent->GetElemCell(anObjCellId);
1227 vtkIdType aNewCellId = aCellsToWarp->InsertNextCell(aCurCell->GetCellType(), aCurCell->GetPointIds());
1229 // get gauss points corresponding to the current cell
1230 vtkIdType aPointVtkId = -1;
1231 vtkIdType aLocalPntId = 0;
1232 aPointVtkId = aGaussPtsIDMapper->GetVTKID(VISU::TGaussPointID(anObjCellId, aLocalPntId));
1234 if (aPointVtkId >= 0) {
1235 // Compute average vector
1236 aCellVectors->Reset();
1237 while (aPointVtkId >= 0) {
1238 anInputVectors->GetTuple(aPointVtkId, &aTuple[0]);
1241 aCellVectors->InsertNextTuple3(aTuple[0], aTuple[1], aTuple[2]);
1242 else if (aNbComp == 2)
1243 aCellVectors->InsertNextTuple3(aTuple[0], aTuple[1], 0);
1244 else if (aNbComp == 1)
1245 aCellVectors->InsertNextTuple3(aTuple[0], 0, 0);
1247 aPointVtkId = aGaussPtsIDMapper->GetVTKID(VISU::TGaussPointID(anObjCellId, ++aLocalPntId));
1250 double aXCoord = 0, anYCoord = 0, aZCoord = 0;
1252 vtkIdType aNbVectors = aCellVectors->GetNumberOfTuples();
1254 for (vtkIdType aVecId = 0; aVecId < aNbVectors; aVecId++) {
1255 aXCoord += aCellVectors->GetComponent(aVecId, 0);
1256 anYCoord += aCellVectors->GetComponent(aVecId, 1);
1257 aZCoord += aCellVectors->GetComponent(aVecId, 2);
1260 aXCoord = aXCoord / aNbVectors;
1261 anYCoord = anYCoord / aNbVectors;
1262 aZCoord = aZCoord / aNbVectors;
1264 // set vector data for the cell
1265 aVectorsToSet->SetTuple3(aNewCellId, aXCoord, anYCoord, aZCoord);
1268 aVectorsToSet->SetTuple3(aNewCellId, 0, 0, 0);
1271 aCellsToWarp->GetCellData()->SetVectors(aVectorsToSet);
1273 aVectorsToSet->Delete();
1274 aCellVectors->Delete();
1275 aNeighbourCells->Delete();
1278 myWarpVector->SetScaleFactor(myGaussPointsPL->GetScale());
1280 myCellDataToPointData->SetInput(aCellsToWarp);
1281 myCellDataToPointData->PassCellDataOn();
1282 aCellsToWarp->Delete();
1284 myWarpVector->SetInput(myCellDataToPointData->GetUnstructuredGridOutput());
1285 vtkUnstructuredGrid* aWarpedDataSet = myWarpVector->GetUnstructuredGridOutput();
1286 aWarpedDataSet->Update();
1287 myCellSource->SetPoints(aWarpedDataSet->GetPoints());
1290 myCellSource->SetPoints(aCellDataSet->GetPoints());
1292 myCellActor->SetVisibility(anIsVisible && theIsHighlight && aShowCellActor);
1298 ::UpdatePickingSettings()
1300 //printf( "VISU_GaussPtsAct::UpdatePickingSettings()\n" );
1301 VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
1302 if(!aPickingSettings)
1305 myTextActor->SetModePosition(aPickingSettings->GetInfoWindowPosition());
1306 myTextActor->SetTransparency(aPickingSettings->GetInfoWindowTransparency());
1308 vtkFloatingPointType aHeight = myGaussPointsPL->GetMaxPointSize()*aPickingSettings->GetPyramidHeight();
1309 vtkFloatingPointType aCursorSize = aPickingSettings->GetCursorSize();
1310 myCursorPyramid->SetPreferences(aHeight,aCursorSize);
1311 myCursorPyramidSelected->SetPreferences(aHeight,aCursorSize);
1313 myHighlightActor->GetProperty()->SetColor( aPickingSettings->GetColor() );
1314 myPointPicker->SetTolerance( aPickingSettings->GetPointTolerance() );
1316 Highlight(isHighlighted());
1321 //----------------------------------------------------------------
1324 ::SetInsideCursorSettings(VISU_InsideCursorSettings* theInsideCursorSettings)
1326 if(myInsideCursorSettings == theInsideCursorSettings)
1329 if(myInsideCursorSettings)
1330 myInsideCursorSettings->RemoveObserver(myEventCallbackCommand.GetPointer());
1332 myInsideCursorSettings = theInsideCursorSettings;
1334 if(theInsideCursorSettings){
1335 theInsideCursorSettings->AddObserver(VISU::UpdateInsideSettingsEvent,
1336 myEventCallbackCommand.GetPointer(),
1338 UpdateInsideCursorSettings();
1344 ::UpdateInsideCursorSettings()
1346 UpdateInsideCursorSettings( myDeviceActor );
1351 ::UpdateInsideCursorSettings( PDeviceActor theActor )
1353 if(!myInsideCursorSettings || myInsideCursorSettings->GetInitial())
1356 VISU_GaussPointsPL* aPipeline = theActor->GetPipeLine();
1358 vtkImplicitFunction* anImplicitFunction = aPipeline->GetImplicitFunction();
1360 aPipeline->ShallowCopy(GetGaussPointsPL(), true);
1362 aPipeline->SetImplicitFunction(anImplicitFunction); // To restore
1364 aPipeline->SetPrimitiveType( myInsideCursorSettings->GetPrimitiveType() );
1365 aPipeline->SetClamp( myInsideCursorSettings->GetClamp() );
1366 aPipeline->SetImageData( myInsideCursorSettings->GetTexture() );
1367 aPipeline->SetAlphaThreshold( myInsideCursorSettings->GetAlphaThreshold() );
1368 aPipeline->SetResolution( myInsideCursorSettings->GetResolution() );
1369 aPipeline->SetMinSize( myInsideCursorSettings->GetMinSize() );
1370 aPipeline->SetMaxSize( myInsideCursorSettings->GetMaxSize() );
1371 aPipeline->SetMagnification( myInsideCursorSettings->GetMagnification() );
1372 aPipeline->SetMagnificationIncrement( myInsideCursorSettings->GetIncrement() );
1374 if( myInsideCursorSettings->GetPrimitiveType() != VISU_OpenGLPointSpriteMapper::GeomSphere )
1375 theActor->GetProperty()->SetRepresentation( VTK_POINTS );
1377 theActor->GetProperty()->SetRepresentation( VTK_SURFACE );
1379 aPipeline->Update();
1381 Highlight(isHighlighted());
1386 //----------------------------------------------------------------------------
1391 unsigned long int aTime = Superclass::GetMTime();
1392 aTime = std::max(aTime, myGaussPointsPL->GetPointSpriteMapper()->GetMTime() );
1396 void VISU_GaussPtsAct::RemoveAllClippingPlanes()
1398 myFunction->GetFunction()->RemoveAllItems();
1399 myFunction->Modified();
1402 vtkIdType VISU_GaussPtsAct::GetNumberOfClippingPlanes()
1404 return myFunction->GetFunction()->GetNumberOfItems();
1407 bool VISU_GaussPtsAct::AddClippingPlane(vtkPlane* thePlane)
1409 vtkImplicitFunctionCollection* aFunctions = GetClippingPlanes();
1410 aFunctions->InitTraversal();
1411 vtkImplicitFunction* aItem;
1412 while ((aItem = aFunctions->GetNextItem())) {
1413 if (thePlane == aItem)
1416 myFunction->AddFunction(thePlane);
1420 vtkPlane* VISU_GaussPtsAct::GetClippingPlane(vtkIdType theID)
1422 vtkPlane* aPlane = NULL;
1423 if ((theID >= 0) && (theID < GetNumberOfClippingPlanes())) {
1424 vtkImplicitFunctionCollection* aFunction = myFunction->GetFunction();
1425 vtkImplicitFunction* aFun = NULL;
1426 aFunction->InitTraversal();
1427 for (vtkIdType i = 0; i <= theID; i++)
1428 aFun = aFunction->GetNextItem();
1429 aPlane = dynamic_cast<vtkPlane*>(aFun);
1434 vtkImplicitFunctionCollection* VISU_GaussPtsAct::GetClippingPlanes()
1436 return myFunction->GetFunction();
1439 //----------------------------------------------------------------------------
1440 vtkDataSet* VISU_GaussPtsAct::GetValLabelsInput()
1447 //==============================================================================
1448 vtkStandardNewMacro(VISU_GaussPtsAct1);
1451 //----------------------------------------------------------------------------
1453 ::VISU_GaussPtsAct1():
1454 myInsideDeviceActor(VISU_GaussPtsDeviceActor::New()),
1455 myOutsideDeviceActor(VISU_GaussPtsDeviceActor::New()),
1456 myOutsideCursorSettings(NULL)
1458 if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::VISU_GaussPtsAct1 - this = "<<this);
1460 myEventCallbackCommand->SetCallback(VISU_GaussPtsAct1::ProcessEvents);
1462 vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
1464 myInsideDeviceActor->SetVisibility(false);
1465 myInsideDeviceActor->SetPickable(false);
1466 myInsideDeviceActor->SetUserMatrix(aMatrix);
1467 myInsideDeviceActor->Delete();
1469 myOutsideDeviceActor->SetVisibility(false);
1470 myOutsideDeviceActor->SetPickable(false);
1471 myOutsideDeviceActor->SetUserMatrix(aMatrix);
1472 myOutsideDeviceActor->Delete();
1477 ::~VISU_GaussPtsAct1()
1479 if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::~VISU_GaussPtsAct1 - this = "<<this);
1481 SetOutsideCursorSettings(NULL);
1485 //----------------------------------------------------------------------------
1488 ::ShallowCopyPL(VISU_PipeLine* thePipeLine)
1490 if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::ShallowCopyPL - this = "<<this);
1492 Superclass::ShallowCopyPL(thePipeLine);
1494 UpdateOutsideCursorSettings();
1498 //----------------------------------------------------------------------------
1501 ::AddToRender(vtkRenderer* theRenderer)
1503 Superclass::AddToRender(theRenderer);
1505 //myInsideDeviceActor->AddToRender(theRenderer);
1506 //myOutsideDeviceActor->AddToRender(theRenderer);
1511 ::RemoveFromRender(vtkRenderer* theRenderer)
1513 //myInsideDeviceActor->RemoveFromRender(theRenderer);
1514 //myOutsideDeviceActor->RemoveFromRender(theRenderer);
1516 Superclass::RemoveFromRender(theRenderer);
1521 ::SetTransform(VTKViewer_Transform* theTransform)
1523 Superclass::SetTransform(theTransform);
1525 myInsideDeviceActor->SetTransform(theTransform);
1526 myOutsideDeviceActor->SetTransform(theTransform);
1532 ::RenderOpaqueGeometry(vtkViewport *viewport)
1535 Superclass::RenderOpaqueGeometry(viewport);
1536 GetMatrix(myInsideDeviceActor->GetUserMatrix());
1537 GetMatrix(myOutsideDeviceActor->GetUserMatrix());
1543 ::RenderTranslucentGeometry(vtkViewport *viewport)
1545 Superclass::RenderTranslucentGeometry(viewport);
1546 GetMatrix(myInsideDeviceActor->GetUserMatrix());
1547 GetMatrix(myOutsideDeviceActor->GetUserMatrix());
1552 //----------------------------------------------------------------------------
1555 ::SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl)
1557 if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::SetWidgetCtrl - this = "<<this);
1559 if(myWidgetCtrl == theWidgetCtrl){
1564 myInsideDeviceActor->GetPipeLine()->SetImplicitFunction(NULL);
1565 myInsideDeviceActor->SetVisibility(false);
1567 myOutsideDeviceActor->GetPipeLine()->SetImplicitFunction(NULL);
1568 myOutsideDeviceActor->SetVisibility(false);
1571 Superclass::SetWidgetCtrl(theWidgetCtrl);
1574 myInsideDeviceActor->GetPipeLine()->SetImplicitFunction(theWidgetCtrl->ImplicitFunction());
1575 myInsideDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1577 myOutsideDeviceActor->GetPipeLine()->SetImplicitFunction(theWidgetCtrl->ImplicitFunction());
1578 myOutsideDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1583 //----------------------------------------------------------------------------
1586 ::SetMapperInput(vtkDataSet* theDataSet)
1588 if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::SetMapperInput - this = "<<this);
1590 Superclass::SetMapperInput(theDataSet);
1592 // if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){
1593 // myInsideDeviceActor->SetPipeLine(aPipeLine);
1594 // aPipeLine->Delete();
1597 // if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){
1598 // myOutsideDeviceActor->SetPipeLine(aPipeLine);
1599 // aPipeLine->Delete();
1601 // aPipeLine->SetExtractBoundaryCells(true);
1602 // aPipeLine->SetExtractInside(true);
1607 //----------------------------------------------------------------------------
1608 vtkFloatingPointType
1610 ::GetRadius(vtkIdType theObjID,
1612 vtkDataArray *theScalarArray)
1614 VISU_GaussPointsPL* aPipeLine = myDeviceActor->GetPipeLine();
1615 if(IsSegmentationEnabled()){
1616 if(myInsideDeviceActor->GetPipeLine()->GetNodeVTKID(theObjID) < 0)
1617 aPipeLine = myOutsideDeviceActor->GetPipeLine();
1619 aPipeLine = myInsideDeviceActor->GetPipeLine();
1621 return ::GetRadius(theVTKID,theScalarArray,aPipeLine);
1625 //----------------------------------------------------------------------------
1626 vtkFloatingPointType
1628 ::GetMagnification(vtkIdType theObjID)
1630 VISU_GaussPointsPL* aPipeLine = myDeviceActor->GetPipeLine();
1631 if(IsSegmentationEnabled()){
1632 if(myInsideDeviceActor->GetPipeLine()->GetNodeVTKID(theObjID) < 0)
1633 aPipeLine = myOutsideDeviceActor->GetPipeLine();
1635 aPipeLine = myInsideDeviceActor->GetPipeLine();
1637 return aPipeLine->GetMagnification();
1641 //----------------------------------------------------------------------------
1642 vtkFloatingPointType
1644 ::GetClamp(vtkIdType theObjID)
1646 if(IsSegmentationEnabled()){
1647 if(myInsideDeviceActor->GetPipeLine()->GetNodeVTKID(theObjID) < 0)
1648 return ::GetClamp(myOutsideDeviceActor->GetPipeLine());
1650 return ::GetClamp(myInsideDeviceActor->GetPipeLine());
1652 return Superclass::GetClamp(theObjID);
1656 //----------------------------------------------------------------
1659 VISU_GaussPtsAct1::SetPosition(double _arg[3]){
1660 if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::SetPosition - this = "<<this);
1661 Superclass::SetPosition(_arg);
1662 myUpdatePositionSignal(_arg);
1667 ::Connect(VISU_GaussPtsAct2* theActor)
1669 mySetVisibilitySignal.connect(boost::bind(&VISU_GaussPtsAct2::SetVisibility,theActor,_1));
1670 myUpdatePositionSignal.connect(boost::bind(&VISU_GaussPtsAct2::SetPosition, theActor,_1));
1675 ::SetVisibility(int theMode)
1677 if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::SetVisibility - this = "<<this);
1679 Superclass::SetVisibility(theMode);
1681 bool aVisisbility = GetVisibility();
1682 bool anIsSegementation = IsSegmentationEnabled();
1683 myDeviceActor->SetVisibility(aVisisbility/* && !anIsSegementation*/);
1684 myInsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
1685 myOutsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
1687 mySetVisibilitySignal(GetVisibility());
1690 //----------------------------------------------------------------
1693 ::UpdateInsideCursorSettings()
1695 Superclass::UpdateInsideCursorSettings( myInsideDeviceActor );
1698 //----------------------------------------------------------------
1701 ::SetOutsideCursorSettings(VISU_OutsideCursorSettings* theOutsideCursorSettings)
1703 if(myOutsideCursorSettings == theOutsideCursorSettings)
1706 if(myOutsideCursorSettings)
1707 myOutsideCursorSettings->RemoveObserver(myEventCallbackCommand.GetPointer());
1709 myOutsideCursorSettings = theOutsideCursorSettings;
1711 if(theOutsideCursorSettings)
1713 theOutsideCursorSettings->AddObserver(VISU::UpdateOutsideSettingsEvent,
1714 myEventCallbackCommand.GetPointer(),
1716 UpdateOutsideCursorSettings();
1722 ::UpdateOutsideCursorSettings()
1724 if(!myOutsideCursorSettings || myOutsideCursorSettings->GetInitial())
1727 VISU_GaussPointsPL* aPipeline = myOutsideDeviceActor->GetPipeLine();
1729 vtkImplicitFunction* anImplicitFunction = aPipeline->GetImplicitFunction();
1730 vtkFloatingPointType aMagnification = aPipeline->GetMagnification();
1732 aPipeline->ShallowCopy(GetGaussPointsPL(), true);
1734 aPipeline->SetImplicitFunction(anImplicitFunction); // To restore
1735 aPipeline->SetExtractBoundaryCells(true);
1736 //aPipeline->SetExtractInside(true);
1737 aPipeline->SetMagnification( aMagnification );
1739 aPipeline->SetPrimitiveType( myOutsideCursorSettings->GetPrimitiveType() );
1741 if( myOutsideCursorSettings->GetPrimitiveType() != VISU_OpenGLPointSpriteMapper::GeomSphere )
1742 myOutsideDeviceActor->GetProperty()->SetRepresentation( VTK_POINTS );
1744 myOutsideDeviceActor->GetProperty()->SetRepresentation( VTK_SURFACE );
1746 aPipeline->SetClamp( myOutsideCursorSettings->GetClamp() );
1747 aPipeline->SetImageData( myOutsideCursorSettings->GetTexture() );
1748 aPipeline->SetAlphaThreshold( myOutsideCursorSettings->GetAlphaThreshold() );
1749 aPipeline->SetResolution( myOutsideCursorSettings->GetResolution() );
1750 aPipeline->SetSize( myOutsideCursorSettings->GetSize() );
1751 aPipeline->SetMagnification( myOutsideCursorSettings->GetMagnification() );
1752 aPipeline->SetMagnificationIncrement( myOutsideCursorSettings->GetIncrement() );
1754 if( myOutsideCursorSettings->GetUniform() )
1756 myOutsideDeviceActor->GetPointSpriteMapper()->ScalarVisibilityOff();
1757 myOutsideDeviceActor->GetPointSpriteMapper()->SetPointSpriteMode( 1 ); // Geometry mode
1758 myOutsideDeviceActor->GetProperty()->SetColor( myOutsideCursorSettings->GetColor() );
1762 myOutsideDeviceActor->GetPointSpriteMapper()->SetPointSpriteMode( 2 ); // Outside cursor mode
1763 myOutsideDeviceActor->GetPointSpriteMapper()->SetColorModeToMapScalars();
1764 myOutsideDeviceActor->GetPointSpriteMapper()->ScalarVisibilityOn();
1767 aPipeline->Update();
1769 Highlight(isHighlighted());
1775 //----------------------------------------------------------------
1778 ::ProcessEvents(vtkObject* theObject,
1779 unsigned long theEvent,
1780 void* theClientData,
1783 if(vtkObject* anObject = reinterpret_cast<vtkObject*>(theClientData))
1784 if(VISU_GaussPtsAct1* self = dynamic_cast<VISU_GaussPtsAct1*>(anObject))
1785 if(theEvent == VISU::UpdateOutsideSettingsEvent)
1786 self->UpdateOutsideCursorSettings();
1788 Superclass::ProcessEvents(theObject,theEvent,theClientData,theCallData);
1793 ::OnInteractorEvent(unsigned long theEvent)
1796 case vtkCommand::StartInteractionEvent:
1797 myDeviceActor->SetVisibility(GetVisibility());
1798 myInsideDeviceActor->SetVisibility(false);
1799 myOutsideDeviceActor->SetVisibility(false);
1801 case vtkCommand::EnableEvent:
1802 case vtkCommand::DisableEvent:
1803 case vtkCommand::EndInteractionEvent: {
1804 bool aVisisbility = GetVisibility();
1805 bool anIsSegementation = IsSegmentationEnabled();
1806 myDeviceActor->SetVisibility(aVisisbility/* && !anIsSegementation*/);
1807 myInsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
1808 myOutsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
1815 Superclass::OnInteractorEvent(theEvent);
1818 //----------------------------------------------------------------------------
1823 unsigned long int aSize = Superclass::GetMemorySize();
1824 if(IsSegmentationEnabled()){
1825 aSize += myInsideDeviceActor->GetMemorySize();
1826 aSize += myOutsideDeviceActor->GetMemorySize();
1833 //==============================================================================
1834 vtkStandardNewMacro(VISU_GaussPtsAct2);
1837 //----------------------------------------------------------------------------
1839 ::VISU_GaussPtsAct2()
1841 if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::VISU_GaussPtsAct2 - this = "<<this);
1842 myDeviceActor->SetVisibility(false);
1846 ::~VISU_GaussPtsAct2()
1848 if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::~VISU_GaussPtsAct2 - this = "<<this);
1852 //----------------------------------------------------------------------------
1855 ::ShallowCopyPL(VISU_PipeLine* thePipeLine)
1857 if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::ShallowCopyPL - this = "<<this);
1859 Superclass::ShallowCopyPL(thePipeLine);
1862 //----------------------------------------------------------------------------
1864 VISU_GaussPtsAct2::SetPosition(double _arg[3]){
1865 if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct2::SetPosition - this = "<<this);
1866 Superclass::SetPosition(_arg);
1869 //----------------------------------------------------------------------------
1872 ::SetMapperInput(vtkDataSet* theDataSet)
1874 if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::SetMapperInput - this = "<<this);
1875 Superclass::SetMapperInput(theDataSet);
1876 // if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){
1877 // myDeviceActor->SetPipeLine(aPipeLine);
1878 // myCurrentPL = aPipeLine;
1879 // aPipeLine->Delete();
1881 // myMapper->SetInput(myCurrentPL->GetPickableDataSet());
1882 // SetMapper(myMapper.GetPointer());
1886 //----------------------------------------------------------------------------
1889 ::SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl)
1891 if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::SetWidgetCtrl - this = "<<this);
1893 if(myWidgetCtrl == theWidgetCtrl)
1897 theWidgetCtrl->RemoveObserver(myEventCallbackCommand.GetPointer());
1898 myDeviceActor->GetPipeLine()->SetImplicitFunction(NULL);
1899 myDeviceActor->SetVisibility(false);
1902 Superclass::SetWidgetCtrl(theWidgetCtrl);
1905 myDeviceActor->GetPipeLine()->SetImplicitFunction(theWidgetCtrl->ImplicitFunction());
1906 myDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1911 //----------------------------------------------------------------------------
1916 if(IsSegmentationEnabled())
1917 return Superclass::GetMemorySize();
1922 //----------------------------------------------------------------------------
1925 ::SetVisibility(int theMode)
1927 if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::SetVisibility - this = "<<this);
1929 Superclass::SetVisibility(theMode);
1931 myDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1936 ::OnInteractorEvent(unsigned long theEvent)
1939 case vtkCommand::EnableEvent:
1940 case vtkCommand::DisableEvent:
1941 myDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1942 if(theEvent == vtkCommand::EnableEvent)
1945 case vtkCommand::EndInteractionEvent:
1951 Superclass::OnInteractorEvent(theEvent);