1 // Copyright (C) 2007-2013 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());
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 ( vtkAlgorithmOutput* aPolyData = myPassFilter[ 2 ]->GetOutputPort() )
443 if( theIsFeatureEdgesEnabled )
445 myFeatureEdges->SetInputConnection( aPolyData );
446 myPassFilter[ 3 ]->SetInputConnection( myFeatureEdges->GetOutputPort() );
447 myIsFeatureEdgesEnabled = true;
451 myPassFilter[3]->SetInputConnection( aPolyData );
452 myPassFilter[3]->Modified();
453 myIsFeatureEdgesEnabled = false;
456 myIsFeatureEdgesEnabled = theIsFeatureEdgesEnabled;
462 ::GetFeatureEdgesAngle()
464 return myFeatureEdges->GetFeatureAngle();
469 ::SetFeatureEdgesAngle(double theValue)
471 myFeatureEdges->SetFeatureAngle(theValue);
477 ::GetFeatureEdgesFlags(bool& theIsFeatureEdges,
478 bool& theIsBoundaryEdges,
479 bool& theIsManifoldEdges,
480 bool& theIsNonManifoldEdges)
482 theIsFeatureEdges = myFeatureEdges->GetFeatureEdges();
483 theIsBoundaryEdges = myFeatureEdges->GetBoundaryEdges();
484 theIsManifoldEdges = myFeatureEdges->GetManifoldEdges();
485 theIsNonManifoldEdges = myFeatureEdges->GetNonManifoldEdges();
490 ::SetFeatureEdgesFlags(bool theIsFeatureEdges,
491 bool theIsBoundaryEdges,
492 bool theIsManifoldEdges,
493 bool theIsNonManifoldEdges)
495 myFeatureEdges->SetFeatureEdges(theIsFeatureEdges);
496 myFeatureEdges->SetBoundaryEdges(theIsBoundaryEdges);
497 myFeatureEdges->SetManifoldEdges(theIsManifoldEdges);
498 myFeatureEdges->SetNonManifoldEdges(theIsNonManifoldEdges);
504 ::GetFeatureEdgesColoring()
506 return myFeatureEdges->GetColoring();
511 ::SetFeatureEdgesColoring(bool theIsColoring)
513 myFeatureEdges->SetColoring(theIsColoring);
517 //----------------------------------------------------------------------------
520 ::SetOpacity(double theValue)
522 GetProperty()->SetOpacity(theValue);
529 return GetProperty()->GetOpacity();
534 ::SetLineWidth(double theLineWidth)
536 GetProperty()->SetLineWidth(theLineWidth);
543 return GetProperty()->GetLineWidth();
546 //==================================================================
547 // function: AddToRender
549 //==================================================================
552 ::AddToRender(vtkRenderer* theRenderer)
554 Superclass::AddToRender(theRenderer);
555 theRenderer->AddActor(myAnnotationActor.GetPointer());
556 theRenderer->AddActor(myTextActor.GetPointer());
558 myValSelectVisiblePoints->SetRenderer( theRenderer );
559 theRenderer->AddActor2D( myValLabels );
563 //==================================================================
564 // function: RemoveFromRender
566 //==================================================================
569 ::RemoveFromRender(vtkRenderer* theRenderer)
571 theRenderer->RemoveActor(myAnnotationActor.GetPointer());
572 theRenderer->RemoveActor(myTextActor.GetPointer());
573 theRenderer->RemoveActor(myValLabels);
574 Superclass::RemoveFromRender(theRenderer);
575 myDestroySignal(this);
578 //----------------------------------------------------------------------------
581 ::SetVisibility(int theMode)
583 Superclass::SetVisibility( theMode );
584 myValLabels->SetVisibility( myIsValLabeled && theMode );
586 // Moved from VISU_GaussPtsAct::SetVisibility() (due to IPAL21159)
587 Highlight(isHighlighted());
589 //----------------------------------------------------------------------------
590 //! Gets know whether the actor should be displayed or not
593 ::ShouldBeDisplayed()
595 return GetFactory()->GetActiveState();
598 //----------------------------------------------------------------------------
601 ::SetPosition( double thePosition[3] )
603 Superclass::SetPosition( thePosition );
604 if( vtkCoordinate* aCoord = myValLabels->GetPositionCoordinate()->GetReferenceCoordinate() )
605 aCoord->SetValue( thePosition );
606 myValSelectVisiblePoints->SetOffset( thePosition );
609 //----------------------------------------------------------------------------
612 ::SetPosition( double theX, double theY, double theZ )
614 Superclass::SetPosition( theX, theY, theZ );
615 if( vtkCoordinate* aCoord = myValLabels->GetPositionCoordinate()->GetReferenceCoordinate() )
616 aCoord->SetValue( theX, theY, theZ );
617 myValSelectVisiblePoints->SetOffset( theX, theY, theZ );
620 //----------------------------------------------------------------------------
623 ::SetVTKMapping(bool theIsVTKMapping)
625 myIsVTKMapping = theIsVTKMapping;
630 ::IsVTKMapping() const
632 return myIsVTKMapping;
635 //----------------------------------------------------------------------------
641 return Superclass::GetInput();
643 return GetCurrentPL()->GetOutput();
646 //----------------------------------------------------------------------------
651 static double ERR_SIZE_CALC = 1.00;
652 vtkDataSet* aDataSet = GetMapper()->GetInput();
653 unsigned long int aSize = size_t(aDataSet->GetActualMemorySize() * 1024 * ERR_SIZE_CALC);
655 aDataSet = myGeomFilter->GetOutput();
656 aSize += aDataSet->GetActualMemorySize() * 1024;
659 aDataSet = myShrinkFilter->GetOutput();
660 aSize += aDataSet->GetActualMemorySize() * 1024;
663 if(IsFeatureEdgesEnabled()){
664 vtkPolyData* aPolyData = myFeatureEdges->GetOutput();
665 aSize += aPolyData->GetActualMemorySize() * 1024;
671 //----------------------------------------------------------------------------
674 ::GetNodeObjId(vtkIdType theID)
677 return Superclass::GetNodeObjId(theID);
679 return VISU::GetNodeObjID(GetMapper()->GetInput(), theID);
684 ::GetNodeVTKID(vtkIdType theID)
689 return VISU::GetNodeVTKID(GetMapper()->GetInput(), theID);
694 ::GetNodeCoord(vtkIdType theObjID)
697 return Superclass::GetNodeCoord(theObjID);
699 return VISU::GetNodeCoord(GetInput(), theObjID);
703 //----------------------------------------------------------------------------
706 ::GetElemObjId(vtkIdType theID)
709 return Superclass::GetElemObjId(theID);
711 return VISU::GetElemObjID(GetMapper()->GetInput(), theID);
716 ::GetElemVTKID(vtkIdType theID)
721 return VISU::GetElemVTKID(GetMapper()->GetInput(), theID);
726 ::GetElemCell(vtkIdType theObjID)
729 return Superclass::GetElemCell(theObjID);
731 return VISU::GetElemCell(GetInput(), theObjID);
735 //----------------------------------------------------------------------------
738 ::isSubElementsHighlighted()
740 return myIsSubElementsHighlighted;
744 //----------------------------------------------------------------------------
747 ChangeZoom(double theZoomFactor,
748 vtkRenderer* theRenderer,
749 vtkIdType theInitialHasIndex,
750 vtkIdType theCurrentHasIndex)
752 //printf( "VISU_Actor::ChangeZoom( %d, %d )", theInitialHasIndex, theCurrentHasIndex );
753 if(theInitialHasIndex + theCurrentHasIndex == 1){
754 vtkCamera *aCamera = theRenderer->GetActiveCamera();
756 double aScale = aCamera->GetParallelScale();
757 if ( !theInitialHasIndex && theCurrentHasIndex ) {
758 //printf( " : +%f", theZoomFactor );
759 aCamera->SetParallelScale( aScale / theZoomFactor );
762 //printf( " : -%f", theZoomFactor );
763 aCamera->SetParallelScale( aScale * theZoomFactor );
770 Updates visibility of the highlight devices
774 ::highlight(bool theIsHighlight)
776 VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
778 bool aShowTextActor = aPickingSettings->GetInfoWindowEnabled();
779 if( theIsHighlight && mySelectionMode != myLastSelectionMode )
781 if( mySelectionMode == ActorSelection )
783 myLastSelectionMode = mySelectionMode;
786 myTextActor->SetVisibility( GetVisibility() && theIsHighlight && aShowTextActor &&
787 ( mySelectionMode == ActorSelection || isSubElementsHighlighted() ) );
789 bool anInitialHasIndex = isHighlighted();
790 bool aCurrentHasIndex = theIsHighlight;
792 if( !theIsHighlight && mySelectionMode == ActorSelection && isSubElementsHighlighted() )
794 myIsSubElementsHighlighted = false;
797 if( GetVisibility() && aPickingSettings->GetCameraMovementEnabled() )
799 double aZoomFactor = aPickingSettings->GetZoomFactor();
800 ChangeZoom(aZoomFactor,
807 Superclass::highlight(theIsHighlight);
811 To process prehighlight (called from SVTK_InteractorStyle)
815 ::PreHighlight(vtkInteractorStyle* theInteractorStyle,
816 SVTK_SelectionEvent* theSelectionEvent,
819 bool aRet = Superclass::PreHighlight(theInteractorStyle,
822 #ifndef ENABLE_ANNOTATION
826 myAnnotationActor->SetVisibility(0);
828 switch(mySelectionMode){
830 vtkRenderer* aRenderer = theInteractorStyle->GetCurrentRenderer();
831 myCellPicker->Pick(theSelectionEvent->myX,
832 theSelectionEvent->myY,
836 if(myCellPicker->GetActor() != this)
839 vtkIdType aVTKId = myCellPicker->GetCellId();
840 if(aVTKId >= 0 && mySelector->IsValid(this,aVTKId,true) && hasIO()){
841 vtkIdType anObjId = GetElemObjId(aVTKId);
842 if(vtkCell* aCell = GetElemCell(anObjId)){
843 vtkPoints* aPts = aCell->GetPoints();
844 if(int aNbPts = aCell->GetNumberOfPoints()){
845 double aCoord[3] = {0.0, 0.0, 0.0};
846 for(int i = 0; i < aNbPts; i++){
847 double *aPntCoord = aPts->GetPoint(i);
848 aCoord[0] += aPntCoord[0];
849 aCoord[1] += aPntCoord[1];
850 aCoord[2] += aPntCoord[2];
852 // Display coordinates
853 double aWorldCoord[4] = {aCoord[0]/aNbPts, aCoord[1]/aNbPts, aCoord[2]/aNbPts, 1.0};
854 aRenderer->SetWorldPoint(aWorldCoord);
855 aRenderer->WorldToDisplay();
856 double aSelectionPoint[3];
857 aRenderer->GetDisplayPoint(aSelectionPoint);
858 myAnnotationActor->SetPosition(aSelectionPoint);
860 // To prepare the annotation text
861 std::ostringstream aStr;
862 aStr<<"Cell ID: "<< anObjId;
863 std::string aString = aStr.str();
864 myAnnotationMapper->SetInput(aString.c_str());
866 myAnnotationActor->SetVisibility(1);
874 vtkRenderer* aRenderer = theInteractorStyle->GetCurrentRenderer();
875 myPointPicker->Pick(theSelectionEvent->myX,
876 theSelectionEvent->myY,
880 if(myPointPicker->GetActor() != this)
883 vtkIdType aVtkId = myPointPicker->GetPointId();
884 if(aVtkId >= 0 && mySelector->IsValid(this,aVtkId,true) && hasIO()){
885 vtkIdType anObjId = GetNodeObjId( aVtkId );
886 if(double* aCoord = GetNodeCoord(anObjId)){
887 // Display coordinates
888 double aWorldCoord[4] = {aCoord[0], aCoord[1], aCoord[2], 1.0};
889 aRenderer->SetWorldPoint(aWorldCoord);
890 aRenderer->WorldToDisplay();
891 double aSelectionPoint[3];
892 aRenderer->GetDisplayPoint(aSelectionPoint);
893 myAnnotationActor->SetPosition(aSelectionPoint);
895 // To prepare the annotation text
896 std::ostringstream aStr;
897 aStr<<"Node ID: "<< anObjId;
898 std::string aString = aStr.str();
899 myAnnotationMapper->SetInput(aString.c_str());
901 myAnnotationActor->SetVisibility(1);
907 case EdgeOfCellSelection:
917 void VISU_Actor::RemoveAllClippingPlanes()
921 vtkIdType VISU_Actor::GetNumberOfClippingPlanes()
926 bool VISU_Actor::AddClippingPlane(vtkPlane* thePlane)
931 vtkPlane* VISU_Actor::GetClippingPlane(vtkIdType theID)
936 vtkImplicitFunctionCollection* VISU_Actor::GetClippingPlanes()
941 //----------------------------------------------------------------------------
942 template<class TData> std::string getScalar(TData* theData, int theId)
944 std::ostringstream aStr;
945 if (vtkDataArray *aScalar = theData->GetScalars()){
946 double aVal = aScalar->GetTuple1(theId);
947 aStr << "\nScalar: " << aVal;
952 template<class TData> std::string getVector(TData* theData, int theId)
954 std::ostringstream aStr;
955 if (vtkDataArray *aVector = theData->GetVectors()) {
956 double *aVal = aVector->GetTuple3(theId);
957 aStr << "\nVector: " << "{" << aVal[0] << "; " << aVal[1] << "; " << aVal[2] << "}";
963 To process highlight (called from SVTK_InteractorStyle)
967 ::Highlight(vtkInteractorStyle* theInteractorStyle,
968 SVTK_SelectionEvent* theSelectionEvent,
971 return Superclass::Highlight(theInteractorStyle,
976 //-------------------------------------------------------------------------
979 ::Highlight(bool theIsHighlight)
981 Superclass::Highlight(theIsHighlight);
983 VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
985 bool anInitialHasIndex = isSubElementsHighlighted() && mySelectionMode != ActorSelection;
987 TColStd_IndexedMapOfInteger aMapIndex;
988 mySelector->GetIndex( getIO(), aMapIndex );
989 bool aCurrentHasIndex = aMapIndex.Extent() == 1;
991 myIsSubElementsHighlighted = aCurrentHasIndex;
994 double aFlyToCoord[3] = { 0.0, 0.0, 0.0 };
995 vtkRenderer *aRenderer = GetRenderer();
999 vtkDataSet* aDataSet = GetMapper()->GetInput();
1000 switch(mySelectionMode)
1002 case ActorSelection:
1009 if( !aCurrentHasIndex )
1011 myTextActor->SetVisibility(false);
1015 int anObjId = aMapIndex(1);
1016 vtkCellData* aCellData = aDataSet->GetCellData();
1017 if(vtkCell* aCell = GetElemCell(anObjId)){
1018 vtkPoints* aPts = aCell->GetPoints();
1019 if(int aNbPts = aCell->GetNumberOfPoints()){
1020 double aCoord[3] = {0.0, 0.0, 0.0};
1021 for(int i = 0; i < aNbPts; i++){
1022 double *aPntCoord = aPts->GetPoint(i);
1023 aCoord[0] += aPntCoord[0];
1024 aCoord[1] += aPntCoord[1];
1025 aCoord[2] += aPntCoord[2];
1029 aFlyToCoord[0] = aCoord[0] / aNbPts;
1030 aFlyToCoord[1] = aCoord[1] / aNbPts;
1031 aFlyToCoord[2] = aCoord[2] / aNbPts;
1033 double aWorldCoord[4] = {aCoord[0]/aNbPts, aCoord[1]/aNbPts, aCoord[2]/aNbPts, 1.0};
1034 aRenderer->SetWorldPoint(aWorldCoord);
1035 aRenderer->WorldToDisplay();
1036 double aSelectionPoint[3];
1037 aRenderer->GetDisplayPoint(aSelectionPoint);
1038 myTextActor->SetPosition(aSelectionPoint);
1039 myTextActor->SetModePosition(aPickingSettings->GetInfoWindowPosition());
1040 myTextActor->SetTransparency(aPickingSettings->GetInfoWindowTransparency());
1041 myTextActor->SetWorldPoint(aWorldCoord);
1043 std::ostringstream aStr;
1044 aStr << "Cell ID: " << anObjId;
1046 vtkCell* aCell = GetElemCell(anObjId);
1047 int aVTKID = GetElemVTKID(anObjId);
1049 int aNbOfPoints = aCell->GetNumberOfPoints();
1050 if ( aNbOfPoints > 0 ) {
1051 aStr << getScalar(aCellData, aVTKID);
1052 aStr << getVector(aCellData, aVTKID);
1056 std::string aString = aStr.str();
1057 myTextActor->SetText(aString.c_str());
1064 if( !aCurrentHasIndex )
1066 myTextActor->SetVisibility(false);
1070 int anObjId = aMapIndex(1);
1071 vtkPointData* aPntData = aDataSet->GetPointData();
1072 if(double* aCoord = GetNodeCoord(anObjId)){
1074 aFlyToCoord[0] = aCoord[0];
1075 aFlyToCoord[1] = aCoord[1];
1076 aFlyToCoord[2] = aCoord[2];
1078 double aWorldCoord[4] = {aCoord[0], aCoord[1], aCoord[2], 1.0};
1079 aRenderer->SetWorldPoint(aWorldCoord);
1080 aRenderer->WorldToDisplay();
1081 double aSelectionPoint[3];
1082 aRenderer->GetDisplayPoint(aSelectionPoint);
1083 myTextActor->SetPosition(aSelectionPoint);
1084 myTextActor->SetModePosition(aPickingSettings->GetInfoWindowPosition());
1085 myTextActor->SetTransparency(aPickingSettings->GetInfoWindowTransparency());
1086 myTextActor->SetWorldPoint(aWorldCoord);
1088 std::ostringstream aStr;
1089 aStr << "Point ID: " << anObjId;
1091 int aVTKID = GetNodeVTKID(anObjId);
1093 aStr << getScalar(aPntData, aVTKID);
1094 aStr << getVector(aPntData, aVTKID);
1097 const VISU::PIDMapper& aMapper = GetPipeLine()->GetIDMapper();
1098 //VISU::TIdTypeVector aVec = aMapper->GetIndexesOfNode(anObjId);
1099 VISU::TStructuredId aVec = aMapper->GetIndexesOfNode(anObjId);
1101 aStr << "\nCoordinates: " << "[";
1103 //if( aVec.size() > 0 )
1105 aStr << " (" << aVec[0] << ")";
1109 //if( aVec.size() > 1 )
1111 aStr << " (" << aVec[1] << ")";
1115 //if( aVec.size() > 2 )
1117 aStr << " (" << aVec[2] << ")";
1120 std::string aString = aStr.str();
1121 myTextActor->SetText(aString.c_str());
1125 case EdgeOfCellSelection:
1133 if( GetVisibility() && aPickingSettings->GetCameraMovementEnabled() )
1135 double aZoomFactor = aPickingSettings->GetZoomFactor();
1136 ChangeZoom(aZoomFactor,
1143 if( GetVisibility() && aPickingSettings->GetCameraMovementEnabled() && aFlyTo )
1145 vtkRenderWindowInteractor* anInteractor = myInteractor;
1146 double aDollyWas = anInteractor->GetDolly();
1147 int aNumberOfFlyFramesWas = anInteractor->GetNumberOfFlyFrames();
1149 double aPosition[3];
1150 GetPosition( aPosition );
1151 for( int i = 0; i < 3; i++ )
1152 aFlyToCoord[i] += aPosition[i];
1154 anInteractor->SetDolly(0.0);
1155 anInteractor->SetNumberOfFlyFrames(aPickingSettings->GetStepNumber());
1156 anInteractor->FlyTo(aRenderer, aFlyToCoord);
1157 aRenderer->ResetCameraClippingRange();
1158 anInteractor->SetDolly(aDollyWas);
1159 anInteractor->SetNumberOfFlyFrames(aNumberOfFlyFramesWas);
1160 anInteractor->InvokeEvent(SVTK::ChangeRotationPoint, aFlyToCoord);
1164 //-------------------------------------------------------------------------
1169 VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
1174 double aWorldCoord[4] = { ( aCoord[0] + aCoord[1] ) / 2,
1175 ( aCoord[2] + aCoord[3] ) / 2,
1176 ( aCoord[4] + aCoord[5] ) / 2, 1.0};
1177 vtkRenderer* aRenderer = GetRenderer();
1178 aRenderer->SetWorldPoint(aWorldCoord);
1179 aRenderer->WorldToDisplay();
1180 double aSelectionPoint[3];
1181 aRenderer->GetDisplayPoint(aSelectionPoint);
1182 myTextActor->SetPosition(aSelectionPoint);
1183 myTextActor->SetModePosition(aPickingSettings->GetInfoWindowPosition());
1184 myTextActor->SetTransparency(aPickingSettings->GetInfoWindowTransparency());
1185 myTextActor->SetWorldPoint(aWorldCoord);
1187 std::ostringstream aStr;
1189 if( const char* aName = getName() )
1190 aStr << aName << "\n";
1192 aStr << "Position: " << "[" << aCoord[0] << "; " << aCoord[2] << "; " << aCoord[4] << "]";
1193 aStr << "\nSize: " << "[" <<
1194 fabs(aCoord[1]-aCoord[0]) << "; " <<
1195 fabs(aCoord[3]-aCoord[2]) << "; " <<
1196 fabs(aCoord[5]-aCoord[4]) << "]";
1198 std::string aString = aStr.str();
1199 myTextActor->SetText(aString.c_str());
1202 //-------------------------------------------------------------------------
1205 ::ProcessEvents(vtkObject* vtkNotUsed(theObject),
1206 unsigned long theEvent,
1207 void* theClientData,
1208 void* vtkNotUsed(theCallData))
1210 if(vtkObject* anObject = reinterpret_cast<vtkObject*>(theClientData))
1211 if(VISU_Actor* self = dynamic_cast<VISU_Actor*>(anObject)) {
1212 if(theEvent == VISU::UpdatePickingSettingsEvent)
1213 self->UpdatePickingSettings();
1217 //----------------------------------------------------------------------------
1220 ::UpdatePickingSettings()
1222 //printf( "VISU_Actor::UpdatePickingSettings()\n" );
1223 VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
1224 if( !aPickingSettings )
1227 myTextActor->SetModePosition(aPickingSettings->GetInfoWindowPosition());
1228 myTextActor->SetTransparency(aPickingSettings->GetInfoWindowTransparency());
1230 Highlight(isHighlighted());
1235 // ---------------------------------------------------------------
1237 void VISU_Actor::SetValuesLabeled( const bool theIsValLabeled )
1239 vtkDataSet* aGrid = GetValLabelsInput();
1243 bool isOnPnt = VISU::IsDataOnPoints( aGrid );
1244 bool isOnCell = VISU::IsDataOnCells( aGrid );
1245 if ( !isOnPnt && !isOnCell )
1247 // try to specify location of scalars "manually"
1248 vtkCellData* aCData = aGrid->GetCellData();
1251 vtkDataArray* anArr = aCData->GetScalars();
1252 if ( anArr && anArr->GetNumberOfTuples() )
1258 vtkPointData* aPData = aGrid->GetPointData();
1261 vtkDataArray* anArr = aPData->GetScalars();
1262 if ( anArr && anArr->GetNumberOfTuples() )
1267 if ( !isOnPnt && !isOnCell )
1269 myValLabels->SetVisibility( false );
1274 myIsValLabeled = theIsValLabeled;
1276 if ( myIsValLabeled )
1278 vtkDataSet* aDataSet = aGrid;
1282 myValCellCenters->SetInputData( aDataSet );
1283 myValMaskPoints->SetInputConnection( myValCellCenters->GetOutputPort() );
1287 myValUsedPoints->SetInputData( aDataSet );
1288 myValMaskPoints->SetInputConnection( myValUsedPoints->GetOutputPort() );
1291 myValLabels->SetVisibility( GetVisibility() );
1294 myValLabels->SetVisibility( false );
1299 //----------------------------------------------------------------------------
1301 bool VISU_Actor::GetValuesLabeled() const
1303 return myIsValLabeled;
1306 //----------------------------------------------------------------------------
1308 vtkTextProperty* VISU_Actor::GetsValLabelsProps() const
1310 return myValLabeledDataMapper->GetLabelTextProperty();
1313 //----------------------------------------------------------------------------
1315 vtkDataSet* VISU_Actor::GetValLabelsInput()
1317 vtkDataSet* aDataSet = 0;
1318 VISU_PipeLine* aPL = GetPipeLine();
1320 aDataSet = aPL->GetOutput();
1322 aDataSet = GetInput();
1327 VISU_Actor::EQuadratic2DRepresentation
1328 VISU_Actor::GetQuadratic2DRepresentation() const
1330 if(Superclass::GetQuadraticArcMode()){
1331 return VISU_Actor::eArcs;
1334 return VISU_Actor::eLines;
1337 void VISU_Actor::SetQuadratic2DRepresentation( EQuadratic2DRepresentation theMode )
1340 case VISU_Actor::eArcs:
1341 myPreHighlightActor->SetQuadraticArcMode(true);
1342 myHighlightActor->SetQuadraticArcMode(true);
1344 case VISU_Actor::eLines:
1345 myPreHighlightActor->SetQuadraticArcMode(false);
1346 myHighlightActor->SetQuadraticArcMode(false);