1 // Copyright (C) 2007-2012 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
28 #include "VISU_Actor.h"
30 #include "VISU_ActorFactory.h"
31 #include "VISU_PickingSettings.h"
32 #include "VISU_GaussPtsDeviceActor.h"
33 #include "VISU_SelectVisiblePoints.h"
35 #include "VISU_PipeLine.hxx"
36 #include "VISU_UsedPointsFilter.hxx"
38 #include "SVTK_Actor.h"
39 #include "SVTK_Event.h"
41 #include "VTKViewer_CellCenters.h"
42 #include "VTKViewer_FramedTextActor.h"
43 #include "VTKViewer_ShrinkFilter.h"
44 #include "VTKViewer_GeometryFilter.h"
46 #include "SALOME_InteractiveObject.hxx"
48 #include "SUIT_Session.h"
49 #include "SUIT_ResourceMgr.h"
53 #include <cmath> // to use std::abs( int )
56 #include <vtkProperty.h>
57 #include <vtkSmartPointer.h>
58 #include <vtkTextMapper.h>
59 #include <vtkTextActor.h>
60 #include <vtkProperty2D.h>
61 #include <vtkRenderer.h>
62 #include <vtkRenderWindow.h>
63 #include <vtkCellPicker.h>
65 #include <vtkPointPicker.h>
66 #include <vtkPoints.h>
67 #include <vtkInteractorStyle.h>
68 #include <vtkDataSet.h>
69 #include <vtkPolyData.h>
70 #include <vtkUnstructuredGrid.h>
71 #include <vtkPassThroughFilter.h>
72 #include <vtkFeatureEdges.h>
73 #include <vtkActor2D.h>
74 #include <vtkMaskPoints.h>
75 #include <vtkLabeledDataMapper.h>
76 #include <vtkTextProperty.h>
77 #include <vtkProperty2D.h>
79 #include <vtkShrinkFilter.h>
80 #include <vtkShrinkPolyData.h>
82 #include <vtkGeometryFilter.h>
83 #include <vtkObjectFactory.h>
85 #include <vtkCallbackCommand.h>
86 #include <vtkCamera.h>
87 #include <vtkRenderWindowInteractor.h>
89 #include <boost/bind.hpp>
91 #include "utilities.h"
93 #include "VISU_PipeLineUtils.hxx"
97 static int MYVTKDEBUG = 0;
100 static int MYDEBUG = 0;
102 static int MYDEBUG = 0;
105 //#define ENABLE_ANNOTATION
107 //----------------------------------------------------------------------------
108 //vtkStandardNewMacro(VISU_Actor);
110 //----------------------------------------------------------------------------
113 myEventCallbackCommand(vtkCallbackCommand::New()),
115 myIsVTKMapping(false),
118 myIsShrinkable(false),
119 myShrinkFilter(VTKViewer_ShrinkFilter::New()),
120 myAnnotationMapper(vtkTextMapper::New()),
121 #if (VTK_XVERSION < 0x050100)
122 myAnnotationActor(vtkTextActor::New()),
124 myAnnotationActor(vtkActor2D::New()),
126 myTextActor(VTKViewer_FramedTextActor::New()),
127 myIsFeatureEdgesAllowed(false),
128 myIsFeatureEdgesEnabled(false),
129 myFeatureEdges(vtkFeatureEdges::New()),
130 myLastSelectionMode(ActorSelection),
131 myIsSubElementsHighlighted(false)
133 if(MYDEBUG) MESSAGE("VISU_Actor::VISU_Actor - this = "<<this);
135 myShrinkFilter->Delete();
137 myStoreMapping = true;
139 myShrinkFilter->SetStoreMapping(true);
141 myAnnotationMapper->Delete();
142 myAnnotationActor->vtkActor2D::SetMapper(myAnnotationMapper.GetPointer()); // OUV_PORTING: to check
144 myAnnotationActor->Delete();
145 myAnnotationActor->SetVisibility(0);
147 myTextActor->Delete();
148 myTextActor->SetVisibility(false);
149 myTextActor->SetPickable(false);
151 myFeatureEdges->Delete();
153 myEventCallbackCommand->Delete();
154 myEventCallbackCommand->SetClientData(this);
155 myEventCallbackCommand->SetCallback(VISU_Actor::ProcessEvents);
157 if( VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get() )
158 aPickingSettings->AddObserver(VISU::UpdatePickingSettingsEvent,
159 myEventCallbackCommand.GetPointer(),
162 //Definition of values labeling pipeline
164 myValLblDataSet = vtkUnstructuredGrid::New();
166 myValCellCenters = VTKViewer_CellCenters::New();
167 myValCellCenters->SetInputData(myValLblDataSet);
169 myValUsedPoints = VISU_UsedPointsFilter::New();
170 myValUsedPoints->SetInputData(myValLblDataSet);
172 myValMaskPoints = vtkMaskPoints::New();
173 myValMaskPoints->SetInputConnection(myValCellCenters->GetOutputPort());
174 myValMaskPoints->SetOnRatio(1);
176 myValSelectVisiblePoints = VISU_SelectVisiblePoints::New();
177 myValSelectVisiblePoints->SetInputConnection(myValMaskPoints->GetOutputPort());
178 myValSelectVisiblePoints->SelectInvisibleOff();
179 myValSelectVisiblePoints->SetTolerance(0.1);
181 char aFormat[16] = "%g";
182 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
184 // san: precision can be negative - this is used by double spin boxes
185 int aFloatingPrec = std::abs( aResourceMgr->integerValue("VISU", "visual_data_precision", 6) );
186 sprintf(aFormat, "%%.%dg", aFloatingPrec);
187 //cout << "$$$ aFormat = " << aFormat << endl;
190 myValLabeledDataMapper = vtkLabeledDataMapper::New();
191 myValLabeledDataMapper->SetInputConnection(myValSelectVisiblePoints->GetOutputPort());
192 //myValLabeledDataMapper->SetLabelFormat("%g");
193 //myValLabeledDataMapper->SetLabelFormat("%.20g");
194 myValLabeledDataMapper->SetLabelFormat(aFormat);
195 myValLabeledDataMapper->SetLabelModeToLabelScalars();
197 vtkTextProperty* aClsTextProp = vtkTextProperty::New();
198 aClsTextProp->SetFontFamilyToTimes();
199 static int aCellsFontSize = 12;
200 aClsTextProp->SetFontSize(aCellsFontSize);
201 aClsTextProp->SetBold(1);
202 aClsTextProp->SetItalic(0);
203 aClsTextProp->SetShadow(0);
204 myValLabeledDataMapper->SetLabelTextProperty(aClsTextProp);
205 aClsTextProp->Delete();
207 myIsValLabeled = false;
209 myValLabels = vtkActor2D::New();
210 myValLabels->SetMapper(myValLabeledDataMapper);
211 myValLabels->GetProperty()->SetColor(0,1,0);
212 myValLabels->SetVisibility( myIsValLabeled );
214 // to allow modification of the reference coordinate in redefined SetPosition() methods
215 vtkCoordinate* aValLabelsCoordinate = vtkCoordinate::New();
216 myValLabels->GetPositionCoordinate()->SetReferenceCoordinate( aValLabelsCoordinate );
217 aValLabelsCoordinate->Delete();
220 //----------------------------------------------------------------------------
223 ::DeepCopy(VISU_Actor *theActor)
225 highlight(theActor->isHighlighted());
226 SetRepresentation(theActor->GetRepresentation());
227 SetShrinkable(theActor->IsShrunkable());
228 SetShrinkFactor(theActor->GetShrinkFactor());
229 if(theActor->IsShrunk())
234 SetFeatureEdgesAllowed(theActor->IsFeatureEdgesAllowed());
235 SetFeatureEdgesEnabled(theActor->IsFeatureEdgesEnabled());
236 SetFeatureEdgesAngle(theActor->GetFeatureEdgesAngle());
237 bool aFeatureEdges = false, aBoundaryEdges = false, aManifoldEdges = false, aNonManifoldEdges = false;
238 theActor->GetFeatureEdgesFlags( aFeatureEdges, aBoundaryEdges, aManifoldEdges, aNonManifoldEdges );
239 SetFeatureEdgesFlags( aFeatureEdges, aBoundaryEdges, aManifoldEdges, aNonManifoldEdges );
240 SetFeatureEdgesColoring(theActor->GetFeatureEdgesColoring());
242 SetOpacity(theActor->GetOpacity());
243 SetLineWidth(theActor->GetLineWidth());
244 SetPosition(theActor->GetPosition());
248 //----------------------------------------------------------------------------
251 ::ShallowCopyPL(VISU_PipeLine* thePipeLine)
253 myPipeLine->ShallowCopy(thePipeLine, true);
254 GetMapper()->Update();
257 //----------------------------------------------------------------------------
261 // Deleting of values labeling pipeline
262 myValLblDataSet->Delete();
263 myValLabeledDataMapper->RemoveAllInputs();
264 myValLabeledDataMapper->Delete();
265 myValSelectVisiblePoints->Delete();
266 myValMaskPoints->Delete();
267 myValUsedPoints->Delete();
268 myValCellCenters->Delete();
269 myValLabels->Delete();
271 if(MYDEBUG) MESSAGE("~VISU_Actor() - this = "<<this);
272 Superclass::SetProperty(NULL);
273 SetDebug(MYVTKDEBUG);
276 //----------------------------------------------------------------------------
279 ::setIO(const Handle(SALOME_InteractiveObject)& theIO)
281 Superclass::setIO(theIO);
282 myName = theIO->getName();
285 //----------------------------------------------------------------------------
288 ::SetPrs3d(VISU::Prs3d_i* thePrs3d)
300 //----------------------------------------------------------------------------
303 ::SetPipeLine(VISU_PipeLine* thePipeLine)
305 myPipeLine = thePipeLine;
307 if(vtkMapper *aMapper = myPipeLine->GetMapper()){
308 if(vtkDataSet *aDataSet = aMapper->GetInput()){
309 SetShrinkable(thePipeLine->IsShrinkable());
310 SetFeatureEdgesAllowed(thePipeLine->IsFeatureEdgesAllowed());
311 SetMapperInput(aDataSet);
322 return myPipeLine.GetPointer();
329 return GetPipeLine();
333 //----------------------------------------------------------------------------
336 ::SetRepresentation(int theMode)
338 Superclass::SetRepresentation(theMode);
339 if(myRepresentation == VTK_POINTS)
343 SetFeatureEdgesEnabled( theMode == VTKViewer::Representation::FeatureEdges );
347 //----------------------------------------------------------------------------
354 if(vtkAlgorithmOutput* aDataSet = myPassFilter[0]->GetOutputPort()){
355 myShrinkFilter->SetInputConnection(aDataSet);
356 myPassFilter[1]->SetInputConnection(myShrinkFilter->GetOutputPort());
367 if(vtkAlgorithmOutput* aDataSet = myPassFilter[0]->GetOutputPort()){
368 myPassFilter[1]->SetInputConnection(aDataSet);
369 myPassFilter[1]->Modified();
384 ::SetShrinkable(bool theIsShrinkable)
386 myIsShrinkable = theIsShrinkable;
393 return myIsShrinkable;
398 ::SetShrinkFactor(double theValue)
400 myShrinkFilter->SetShrinkFactor(theValue);
408 return myShrinkFilter->GetShrinkFactor();
412 //----------------------------------------------------------------------------
415 ::IsFeatureEdgesAllowed()
417 return myIsFeatureEdgesAllowed;
422 ::SetFeatureEdgesAllowed(bool theIsFeatureEdgesAllowed)
424 myIsFeatureEdgesAllowed = theIsFeatureEdgesAllowed;
429 ::IsFeatureEdgesEnabled()
431 return myIsFeatureEdgesEnabled;
436 ::SetFeatureEdgesEnabled(bool theIsFeatureEdgesEnabled)
438 if ( !myIsFeatureEdgesAllowed || myIsFeatureEdgesEnabled == theIsFeatureEdgesEnabled )
441 //if ( vtkPolyData* aPolyData = myPassFilter[ 2 ]->GetPolyDataOutput() )
442 if ( vtkAlgorithmOutput* aPolyData = myPassFilter[ 2 ]->GetOutputPort() ) // OUV_PORTING: to check
444 if( theIsFeatureEdgesEnabled )
446 myFeatureEdges->SetInputConnection( aPolyData );
447 myPassFilter[ 3 ]->SetInputConnection( myFeatureEdges->GetOutputPort() );
448 myIsFeatureEdgesEnabled = true;
452 myPassFilter[3]->SetInputConnection( aPolyData );
453 myPassFilter[3]->Modified();
454 myIsFeatureEdgesEnabled = false;
457 myIsFeatureEdgesEnabled = theIsFeatureEdgesEnabled;
463 ::GetFeatureEdgesAngle()
465 return myFeatureEdges->GetFeatureAngle();
470 ::SetFeatureEdgesAngle(double theValue)
472 myFeatureEdges->SetFeatureAngle(theValue);
478 ::GetFeatureEdgesFlags(bool& theIsFeatureEdges,
479 bool& theIsBoundaryEdges,
480 bool& theIsManifoldEdges,
481 bool& theIsNonManifoldEdges)
483 theIsFeatureEdges = myFeatureEdges->GetFeatureEdges();
484 theIsBoundaryEdges = myFeatureEdges->GetBoundaryEdges();
485 theIsManifoldEdges = myFeatureEdges->GetManifoldEdges();
486 theIsNonManifoldEdges = myFeatureEdges->GetNonManifoldEdges();
491 ::SetFeatureEdgesFlags(bool theIsFeatureEdges,
492 bool theIsBoundaryEdges,
493 bool theIsManifoldEdges,
494 bool theIsNonManifoldEdges)
496 myFeatureEdges->SetFeatureEdges(theIsFeatureEdges);
497 myFeatureEdges->SetBoundaryEdges(theIsBoundaryEdges);
498 myFeatureEdges->SetManifoldEdges(theIsManifoldEdges);
499 myFeatureEdges->SetNonManifoldEdges(theIsNonManifoldEdges);
505 ::GetFeatureEdgesColoring()
507 return myFeatureEdges->GetColoring();
512 ::SetFeatureEdgesColoring(bool theIsColoring)
514 myFeatureEdges->SetColoring(theIsColoring);
518 //----------------------------------------------------------------------------
521 ::SetOpacity(double theValue)
523 GetProperty()->SetOpacity(theValue);
530 return GetProperty()->GetOpacity();
535 ::SetLineWidth(double theLineWidth)
537 GetProperty()->SetLineWidth(theLineWidth);
544 return GetProperty()->GetLineWidth();
547 //==================================================================
548 // function: AddToRender
550 //==================================================================
553 ::AddToRender(vtkRenderer* theRenderer)
555 Superclass::AddToRender(theRenderer);
556 theRenderer->AddActor(myAnnotationActor.GetPointer());
557 theRenderer->AddActor(myTextActor.GetPointer());
559 myValSelectVisiblePoints->SetRenderer( theRenderer );
560 theRenderer->AddActor2D( myValLabels );
564 //==================================================================
565 // function: RemoveFromRender
567 //==================================================================
570 ::RemoveFromRender(vtkRenderer* theRenderer)
572 theRenderer->RemoveActor(myAnnotationActor.GetPointer());
573 theRenderer->RemoveActor(myTextActor.GetPointer());
574 theRenderer->RemoveActor(myValLabels);
575 Superclass::RemoveFromRender(theRenderer);
576 myDestroySignal(this);
579 //----------------------------------------------------------------------------
582 ::SetVisibility(int theMode)
584 Superclass::SetVisibility( theMode );
585 myValLabels->SetVisibility( myIsValLabeled && theMode );
587 // Moved from VISU_GaussPtsAct::SetVisibility() (due to IPAL21159)
588 Highlight(isHighlighted());
590 //----------------------------------------------------------------------------
591 //! Gets know whether the actor should be displayed or not
594 ::ShouldBeDisplayed()
596 return GetFactory()->GetActiveState();
599 //----------------------------------------------------------------------------
602 ::SetPosition( double thePosition[3] )
604 Superclass::SetPosition( thePosition );
605 if( vtkCoordinate* aCoord = myValLabels->GetPositionCoordinate()->GetReferenceCoordinate() )
606 aCoord->SetValue( thePosition );
607 myValSelectVisiblePoints->SetOffset( thePosition );
610 //----------------------------------------------------------------------------
613 ::SetPosition( double theX, double theY, double theZ )
615 Superclass::SetPosition( theX, theY, theZ );
616 if( vtkCoordinate* aCoord = myValLabels->GetPositionCoordinate()->GetReferenceCoordinate() )
617 aCoord->SetValue( theX, theY, theZ );
618 myValSelectVisiblePoints->SetOffset( theX, theY, theZ );
621 //----------------------------------------------------------------------------
624 ::SetVTKMapping(bool theIsVTKMapping)
626 myIsVTKMapping = theIsVTKMapping;
631 ::IsVTKMapping() const
633 return myIsVTKMapping;
636 //----------------------------------------------------------------------------
642 return Superclass::GetInput();
644 return GetCurrentPL()->GetOutput();
647 //----------------------------------------------------------------------------
652 static double ERR_SIZE_CALC = 1.00;
653 vtkDataSet* aDataSet = GetMapper()->GetInput();
654 unsigned long int aSize = size_t(aDataSet->GetActualMemorySize() * 1024 * ERR_SIZE_CALC);
656 aDataSet = myGeomFilter->GetOutput();
657 aSize += aDataSet->GetActualMemorySize() * 1024;
660 aDataSet = myShrinkFilter->GetOutput();
661 aSize += aDataSet->GetActualMemorySize() * 1024;
664 if(IsFeatureEdgesEnabled()){
665 vtkPolyData* aPolyData = myFeatureEdges->GetOutput();
666 aSize += aPolyData->GetActualMemorySize() * 1024;
672 //----------------------------------------------------------------------------
675 ::GetNodeObjId(vtkIdType theID)
678 return Superclass::GetNodeObjId(theID);
680 return VISU::GetNodeObjID(GetMapper()->GetInput(), theID);
685 ::GetNodeVTKID(vtkIdType theID)
690 return VISU::GetNodeVTKID(GetMapper()->GetInput(), theID);
695 ::GetNodeCoord(vtkIdType theObjID)
698 return Superclass::GetNodeCoord(theObjID);
700 return VISU::GetNodeCoord(GetInput(), theObjID);
704 //----------------------------------------------------------------------------
707 ::GetElemObjId(vtkIdType theID)
710 return Superclass::GetElemObjId(theID);
712 return VISU::GetElemObjID(GetMapper()->GetInput(), theID);
717 ::GetElemVTKID(vtkIdType theID)
722 return VISU::GetElemVTKID(GetMapper()->GetInput(), theID);
727 ::GetElemCell(vtkIdType theObjID)
730 return Superclass::GetElemCell(theObjID);
732 return VISU::GetElemCell(GetInput(), theObjID);
736 //----------------------------------------------------------------------------
739 ::isSubElementsHighlighted()
741 return myIsSubElementsHighlighted;
745 //----------------------------------------------------------------------------
748 ChangeZoom(double theZoomFactor,
749 vtkRenderer* theRenderer,
750 vtkIdType theInitialHasIndex,
751 vtkIdType theCurrentHasIndex)
753 //printf( "VISU_Actor::ChangeZoom( %d, %d )", theInitialHasIndex, theCurrentHasIndex );
754 if(theInitialHasIndex + theCurrentHasIndex == 1){
755 vtkCamera *aCamera = theRenderer->GetActiveCamera();
757 double aScale = aCamera->GetParallelScale();
758 if ( !theInitialHasIndex && theCurrentHasIndex ) {
759 //printf( " : +%f", theZoomFactor );
760 aCamera->SetParallelScale( aScale / theZoomFactor );
763 //printf( " : -%f", theZoomFactor );
764 aCamera->SetParallelScale( aScale * theZoomFactor );
771 Updates visibility of the highlight devices
775 ::highlight(bool theIsHighlight)
777 VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
779 bool aShowTextActor = aPickingSettings->GetInfoWindowEnabled();
780 if( theIsHighlight && mySelectionMode != myLastSelectionMode )
782 if( mySelectionMode == ActorSelection )
784 myLastSelectionMode = mySelectionMode;
787 myTextActor->SetVisibility( GetVisibility() && theIsHighlight && aShowTextActor &&
788 ( mySelectionMode == ActorSelection || isSubElementsHighlighted() ) );
790 bool anInitialHasIndex = isHighlighted();
791 bool aCurrentHasIndex = theIsHighlight;
793 if( !theIsHighlight && mySelectionMode == ActorSelection && isSubElementsHighlighted() )
795 myIsSubElementsHighlighted = false;
798 if( GetVisibility() && aPickingSettings->GetCameraMovementEnabled() )
800 double aZoomFactor = aPickingSettings->GetZoomFactor();
801 ChangeZoom(aZoomFactor,
808 Superclass::highlight(theIsHighlight);
812 To process prehighlight (called from SVTK_InteractorStyle)
816 ::PreHighlight(vtkInteractorStyle* theInteractorStyle,
817 SVTK_SelectionEvent* theSelectionEvent,
820 bool aRet = Superclass::PreHighlight(theInteractorStyle,
823 #ifndef ENABLE_ANNOTATION
827 myAnnotationActor->SetVisibility(0);
829 switch(mySelectionMode){
831 vtkRenderer* aRenderer = theInteractorStyle->GetCurrentRenderer();
832 myCellPicker->Pick(theSelectionEvent->myX,
833 theSelectionEvent->myY,
837 if(myCellPicker->GetActor() != this)
840 vtkIdType aVTKId = myCellPicker->GetCellId();
841 if(aVTKId >= 0 && mySelector->IsValid(this,aVTKId,true) && hasIO()){
842 vtkIdType anObjId = GetElemObjId(aVTKId);
843 if(vtkCell* aCell = GetElemCell(anObjId)){
844 vtkPoints* aPts = aCell->GetPoints();
845 if(int aNbPts = aCell->GetNumberOfPoints()){
846 double aCoord[3] = {0.0, 0.0, 0.0};
847 for(int i = 0; i < aNbPts; i++){
848 double *aPntCoord = aPts->GetPoint(i);
849 aCoord[0] += aPntCoord[0];
850 aCoord[1] += aPntCoord[1];
851 aCoord[2] += aPntCoord[2];
853 // Display coordinates
854 double aWorldCoord[4] = {aCoord[0]/aNbPts, aCoord[1]/aNbPts, aCoord[2]/aNbPts, 1.0};
855 aRenderer->SetWorldPoint(aWorldCoord);
856 aRenderer->WorldToDisplay();
857 double aSelectionPoint[3];
858 aRenderer->GetDisplayPoint(aSelectionPoint);
859 myAnnotationActor->SetPosition(aSelectionPoint);
861 // To prepare the annotation text
862 std::ostringstream aStr;
863 aStr<<"Cell ID: "<< anObjId;
864 std::string aString = aStr.str();
865 myAnnotationMapper->SetInput(aString.c_str());
867 myAnnotationActor->SetVisibility(1);
875 vtkRenderer* aRenderer = theInteractorStyle->GetCurrentRenderer();
876 myPointPicker->Pick(theSelectionEvent->myX,
877 theSelectionEvent->myY,
881 if(myPointPicker->GetActor() != this)
884 vtkIdType aVtkId = myPointPicker->GetPointId();
885 if(aVtkId >= 0 && mySelector->IsValid(this,aVtkId,true) && hasIO()){
886 vtkIdType anObjId = GetNodeObjId( aVtkId );
887 if(double* aCoord = GetNodeCoord(anObjId)){
888 // Display coordinates
889 double aWorldCoord[4] = {aCoord[0], aCoord[1], aCoord[2], 1.0};
890 aRenderer->SetWorldPoint(aWorldCoord);
891 aRenderer->WorldToDisplay();
892 double aSelectionPoint[3];
893 aRenderer->GetDisplayPoint(aSelectionPoint);
894 myAnnotationActor->SetPosition(aSelectionPoint);
896 // To prepare the annotation text
897 std::ostringstream aStr;
898 aStr<<"Node ID: "<< anObjId;
899 std::string aString = aStr.str();
900 myAnnotationMapper->SetInput(aString.c_str());
902 myAnnotationActor->SetVisibility(1);
908 case EdgeOfCellSelection:
918 void VISU_Actor::RemoveAllClippingPlanes()
922 vtkIdType VISU_Actor::GetNumberOfClippingPlanes()
927 bool VISU_Actor::AddClippingPlane(vtkPlane* thePlane)
932 vtkPlane* VISU_Actor::GetClippingPlane(vtkIdType theID)
937 vtkImplicitFunctionCollection* VISU_Actor::GetClippingPlanes()
942 //----------------------------------------------------------------------------
943 template<class TData> std::string getScalar(TData* theData, int theId)
945 std::ostringstream aStr;
946 if (vtkDataArray *aScalar = theData->GetScalars()){
947 double aVal = aScalar->GetTuple1(theId);
948 aStr << "\nScalar: " << aVal;
953 template<class TData> std::string getVector(TData* theData, int theId)
955 std::ostringstream aStr;
956 if (vtkDataArray *aVector = theData->GetVectors()) {
957 double *aVal = aVector->GetTuple3(theId);
958 aStr << "\nVector: " << "{" << aVal[0] << "; " << aVal[1] << "; " << aVal[2] << "}";
964 To process highlight (called from SVTK_InteractorStyle)
968 ::Highlight(vtkInteractorStyle* theInteractorStyle,
969 SVTK_SelectionEvent* theSelectionEvent,
972 return Superclass::Highlight(theInteractorStyle,
977 //-------------------------------------------------------------------------
980 ::Highlight(bool theIsHighlight)
982 Superclass::Highlight(theIsHighlight);
984 VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
986 bool anInitialHasIndex = isSubElementsHighlighted() && mySelectionMode != ActorSelection;
988 TColStd_IndexedMapOfInteger aMapIndex;
989 mySelector->GetIndex( getIO(), aMapIndex );
990 bool aCurrentHasIndex = aMapIndex.Extent() == 1;
992 myIsSubElementsHighlighted = aCurrentHasIndex;
995 double aFlyToCoord[3] = { 0.0, 0.0, 0.0 };
996 vtkRenderer *aRenderer = GetRenderer();
1000 vtkDataSet* aDataSet = GetMapper()->GetInput();
1001 switch(mySelectionMode)
1003 case ActorSelection:
1010 if( !aCurrentHasIndex )
1012 myTextActor->SetVisibility(false);
1016 int anObjId = aMapIndex(1);
1017 vtkCellData* aCellData = aDataSet->GetCellData();
1018 if(vtkCell* aCell = GetElemCell(anObjId)){
1019 vtkPoints* aPts = aCell->GetPoints();
1020 if(int aNbPts = aCell->GetNumberOfPoints()){
1021 double aCoord[3] = {0.0, 0.0, 0.0};
1022 for(int i = 0; i < aNbPts; i++){
1023 double *aPntCoord = aPts->GetPoint(i);
1024 aCoord[0] += aPntCoord[0];
1025 aCoord[1] += aPntCoord[1];
1026 aCoord[2] += aPntCoord[2];
1030 aFlyToCoord[0] = aCoord[0] / aNbPts;
1031 aFlyToCoord[1] = aCoord[1] / aNbPts;
1032 aFlyToCoord[2] = aCoord[2] / aNbPts;
1034 double aWorldCoord[4] = {aCoord[0]/aNbPts, aCoord[1]/aNbPts, aCoord[2]/aNbPts, 1.0};
1035 aRenderer->SetWorldPoint(aWorldCoord);
1036 aRenderer->WorldToDisplay();
1037 double aSelectionPoint[3];
1038 aRenderer->GetDisplayPoint(aSelectionPoint);
1039 myTextActor->SetPosition(aSelectionPoint);
1040 myTextActor->SetModePosition(aPickingSettings->GetInfoWindowPosition());
1041 myTextActor->SetTransparency(aPickingSettings->GetInfoWindowTransparency());
1042 myTextActor->SetWorldPoint(aWorldCoord);
1044 std::ostringstream aStr;
1045 aStr << "Cell ID: " << anObjId;
1047 vtkCell* aCell = GetElemCell(anObjId);
1048 int aVTKID = GetElemVTKID(anObjId);
1050 int aNbOfPoints = aCell->GetNumberOfPoints();
1051 if ( aNbOfPoints > 0 ) {
1052 aStr << getScalar(aCellData, aVTKID);
1053 aStr << getVector(aCellData, aVTKID);
1057 std::string aString = aStr.str();
1058 myTextActor->SetText(aString.c_str());
1065 if( !aCurrentHasIndex )
1067 myTextActor->SetVisibility(false);
1071 int anObjId = aMapIndex(1);
1072 vtkPointData* aPntData = aDataSet->GetPointData();
1073 if(double* aCoord = GetNodeCoord(anObjId)){
1075 aFlyToCoord[0] = aCoord[0];
1076 aFlyToCoord[1] = aCoord[1];
1077 aFlyToCoord[2] = aCoord[2];
1079 double aWorldCoord[4] = {aCoord[0], aCoord[1], aCoord[2], 1.0};
1080 aRenderer->SetWorldPoint(aWorldCoord);
1081 aRenderer->WorldToDisplay();
1082 double aSelectionPoint[3];
1083 aRenderer->GetDisplayPoint(aSelectionPoint);
1084 myTextActor->SetPosition(aSelectionPoint);
1085 myTextActor->SetModePosition(aPickingSettings->GetInfoWindowPosition());
1086 myTextActor->SetTransparency(aPickingSettings->GetInfoWindowTransparency());
1087 myTextActor->SetWorldPoint(aWorldCoord);
1089 std::ostringstream aStr;
1090 aStr << "Point ID: " << anObjId;
1092 int aVTKID = GetNodeVTKID(anObjId);
1094 aStr << getScalar(aPntData, aVTKID);
1095 aStr << getVector(aPntData, aVTKID);
1098 const VISU::PIDMapper& aMapper = GetPipeLine()->GetIDMapper();
1099 //VISU::TIdTypeVector aVec = aMapper->GetIndexesOfNode(anObjId);
1100 VISU::TStructuredId aVec = aMapper->GetIndexesOfNode(anObjId);
1102 aStr << "\nCoordinates: " << "[";
1104 //if( aVec.size() > 0 )
1106 aStr << " (" << aVec[0] << ")";
1110 //if( aVec.size() > 1 )
1112 aStr << " (" << aVec[1] << ")";
1116 //if( aVec.size() > 2 )
1118 aStr << " (" << aVec[2] << ")";
1121 std::string aString = aStr.str();
1122 myTextActor->SetText(aString.c_str());
1126 case EdgeOfCellSelection:
1134 if( GetVisibility() && aPickingSettings->GetCameraMovementEnabled() )
1136 double aZoomFactor = aPickingSettings->GetZoomFactor();
1137 ChangeZoom(aZoomFactor,
1144 if( GetVisibility() && aPickingSettings->GetCameraMovementEnabled() && aFlyTo )
1146 vtkRenderWindowInteractor* anInteractor = myInteractor;
1147 double aDollyWas = anInteractor->GetDolly();
1148 int aNumberOfFlyFramesWas = anInteractor->GetNumberOfFlyFrames();
1150 double aPosition[3];
1151 GetPosition( aPosition );
1152 for( int i = 0; i < 3; i++ )
1153 aFlyToCoord[i] += aPosition[i];
1155 anInteractor->SetDolly(0.0);
1156 anInteractor->SetNumberOfFlyFrames(aPickingSettings->GetStepNumber());
1157 anInteractor->FlyTo(aRenderer, aFlyToCoord);
1158 aRenderer->ResetCameraClippingRange();
1159 anInteractor->SetDolly(aDollyWas);
1160 anInteractor->SetNumberOfFlyFrames(aNumberOfFlyFramesWas);
1161 anInteractor->InvokeEvent(SVTK::ChangeRotationPoint, aFlyToCoord);
1165 //-------------------------------------------------------------------------
1170 VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
1175 double aWorldCoord[4] = { ( aCoord[0] + aCoord[1] ) / 2,
1176 ( aCoord[2] + aCoord[3] ) / 2,
1177 ( aCoord[4] + aCoord[5] ) / 2, 1.0};
1178 vtkRenderer* aRenderer = GetRenderer();
1179 aRenderer->SetWorldPoint(aWorldCoord);
1180 aRenderer->WorldToDisplay();
1181 double aSelectionPoint[3];
1182 aRenderer->GetDisplayPoint(aSelectionPoint);
1183 myTextActor->SetPosition(aSelectionPoint);
1184 myTextActor->SetModePosition(aPickingSettings->GetInfoWindowPosition());
1185 myTextActor->SetTransparency(aPickingSettings->GetInfoWindowTransparency());
1186 myTextActor->SetWorldPoint(aWorldCoord);
1188 std::ostringstream aStr;
1190 if( const char* aName = getName() )
1191 aStr << aName << "\n";
1193 aStr << "Position: " << "[" << aCoord[0] << "; " << aCoord[2] << "; " << aCoord[4] << "]";
1194 aStr << "\nSize: " << "[" <<
1195 fabs(aCoord[1]-aCoord[0]) << "; " <<
1196 fabs(aCoord[3]-aCoord[2]) << "; " <<
1197 fabs(aCoord[5]-aCoord[4]) << "]";
1199 std::string aString = aStr.str();
1200 myTextActor->SetText(aString.c_str());
1203 //-------------------------------------------------------------------------
1206 ::ProcessEvents(vtkObject* vtkNotUsed(theObject),
1207 unsigned long theEvent,
1208 void* theClientData,
1209 void* vtkNotUsed(theCallData))
1211 if(vtkObject* anObject = reinterpret_cast<vtkObject*>(theClientData))
1212 if(VISU_Actor* self = dynamic_cast<VISU_Actor*>(anObject)) {
1213 if(theEvent == VISU::UpdatePickingSettingsEvent)
1214 self->UpdatePickingSettings();
1218 //----------------------------------------------------------------------------
1221 ::UpdatePickingSettings()
1223 //printf( "VISU_Actor::UpdatePickingSettings()\n" );
1224 VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
1225 if( !aPickingSettings )
1228 myTextActor->SetModePosition(aPickingSettings->GetInfoWindowPosition());
1229 myTextActor->SetTransparency(aPickingSettings->GetInfoWindowTransparency());
1231 Highlight(isHighlighted());
1236 // ---------------------------------------------------------------
1238 void VISU_Actor::SetValuesLabeled( const bool theIsValLabeled )
1240 vtkDataSet* aGrid = GetValLabelsInput();
1244 bool isOnPnt = VISU::IsDataOnPoints( aGrid );
1245 bool isOnCell = VISU::IsDataOnCells( aGrid );
1246 if ( !isOnPnt && !isOnCell )
1248 // try to specify location of scalars "manually"
1249 vtkCellData* aCData = aGrid->GetCellData();
1252 vtkDataArray* anArr = aCData->GetScalars();
1253 if ( anArr && anArr->GetNumberOfTuples() )
1259 vtkPointData* aPData = aGrid->GetPointData();
1262 vtkDataArray* anArr = aPData->GetScalars();
1263 if ( anArr && anArr->GetNumberOfTuples() )
1268 if ( !isOnPnt && !isOnCell )
1270 myValLabels->SetVisibility( false );
1275 myIsValLabeled = theIsValLabeled;
1277 if ( myIsValLabeled )
1279 vtkDataSet* aDataSet = aGrid;
1283 myValCellCenters->SetInputData( aDataSet );
1284 myValMaskPoints->SetInputConnection( myValCellCenters->GetOutputPort() );
1288 myValUsedPoints->SetInputData( aDataSet );
1289 myValMaskPoints->SetInputConnection( myValUsedPoints->GetOutputPort() );
1292 myValLabels->SetVisibility( GetVisibility() );
1295 myValLabels->SetVisibility( false );
1300 //----------------------------------------------------------------------------
1302 bool VISU_Actor::GetValuesLabeled() const
1304 return myIsValLabeled;
1307 //----------------------------------------------------------------------------
1309 vtkTextProperty* VISU_Actor::GetsValLabelsProps() const
1311 return myValLabeledDataMapper->GetLabelTextProperty();
1314 //----------------------------------------------------------------------------
1316 vtkDataSet* VISU_Actor::GetValLabelsInput()
1318 vtkDataSet* aDataSet = 0;
1319 VISU_PipeLine* aPL = GetPipeLine();
1321 aDataSet = aPL->GetOutput();
1323 aDataSet = GetInput();
1328 VISU_Actor::EQuadratic2DRepresentation
1329 VISU_Actor::GetQuadratic2DRepresentation() const
1331 if(Superclass::GetQuadraticArcMode()){
1332 return VISU_Actor::eArcs;
1335 return VISU_Actor::eLines;
1338 void VISU_Actor::SetQuadratic2DRepresentation( EQuadratic2DRepresentation theMode )
1341 case VISU_Actor::eArcs:
1342 myPreHighlightActor->SetQuadraticArcMode(true);
1343 myHighlightActor->SetQuadraticArcMode(true);
1345 case VISU_Actor::eLines:
1346 myPreHighlightActor->SetQuadraticArcMode(false);
1347 myHighlightActor->SetQuadraticArcMode(false);