1 // Copyright (C) 2007-2010 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"
37 #include "SVTK_Actor.h"
38 #include "SVTK_Event.h"
40 #include "VTKViewer_FramedTextActor.h"
41 #include "VTKViewer_ShrinkFilter.h"
42 #include "VTKViewer_GeometryFilter.h"
44 #include "SALOME_InteractiveObject.hxx"
46 #include "SUIT_Session.h"
47 #include "SUIT_ResourceMgr.h"
51 #include <cmath> // to use std::abs( int )
54 #include <vtkProperty.h>
55 #include <vtkSmartPointer.h>
56 #include <vtkTextMapper.h>
57 #include <vtkTextActor.h>
58 #include <vtkProperty2D.h>
59 #include <vtkRenderer.h>
60 #include <vtkRenderWindow.h>
61 #include <vtkCellPicker.h>
63 #include <vtkPointPicker.h>
64 #include <vtkPoints.h>
65 #include <vtkInteractorStyle.h>
66 #include <vtkDataSet.h>
67 #include <vtkPolyData.h>
68 #include <vtkUnstructuredGrid.h>
69 #include <vtkPassThroughFilter.h>
70 #include <vtkFeatureEdges.h>
71 #include <vtkActor2D.h>
72 #include <vtkMaskPoints.h>
73 #include <vtkLabeledDataMapper.h>
74 #include <vtkTextProperty.h>
75 #include <vtkProperty2D.h>
77 #include <vtkShrinkFilter.h>
78 #include <vtkShrinkPolyData.h>
80 #include <vtkGeometryFilter.h>
81 #include <vtkObjectFactory.h>
83 #include <vtkCallbackCommand.h>
84 #include <vtkCamera.h>
85 #include <vtkRenderWindowInteractor.h>
87 #include <boost/bind.hpp>
89 #include "utilities.h"
91 #include "VISU_PipeLineUtils.hxx"
95 static int MYVTKDEBUG = 0;
98 static int MYDEBUG = 0;
100 static int MYDEBUG = 0;
103 //#define ENABLE_ANNOTATION
105 //----------------------------------------------------------------------------
106 //vtkStandardNewMacro(VISU_Actor);
108 //----------------------------------------------------------------------------
111 myEventCallbackCommand(vtkCallbackCommand::New()),
113 myIsVTKMapping(false),
116 myIsShrinkable(false),
117 myShrinkFilter(VTKViewer_ShrinkFilter::New()),
118 myAnnotationMapper(vtkTextMapper::New()),
119 #if (VTK_XVERSION < 0x050100)
120 myAnnotationActor(vtkTextActor::New()),
122 myAnnotationActor(vtkActor2D::New()),
124 myTextActor(VTKViewer_FramedTextActor::New()),
125 myIsFeatureEdgesAllowed(false),
126 myIsFeatureEdgesEnabled(false),
127 myFeatureEdges(vtkFeatureEdges::New()),
128 myLastSelectionMode(ActorSelection),
129 myIsSubElementsHighlighted(false)
131 if(MYDEBUG) MESSAGE("VISU_Actor::VISU_Actor - this = "<<this);
133 myShrinkFilter->Delete();
135 myStoreMapping = true;
137 myShrinkFilter->SetStoreMapping(true);
139 myAnnotationMapper->Delete();
140 myAnnotationActor->SetMapper(myAnnotationMapper.GetPointer());
142 myAnnotationActor->Delete();
143 myAnnotationActor->SetVisibility(0);
145 myTextActor->Delete();
146 myTextActor->SetVisibility(false);
147 myTextActor->SetPickable(false);
149 myFeatureEdges->Delete();
151 myEventCallbackCommand->Delete();
152 myEventCallbackCommand->SetClientData(this);
153 myEventCallbackCommand->SetCallback(VISU_Actor::ProcessEvents);
155 if( VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get() )
156 aPickingSettings->AddObserver(VISU::UpdatePickingSettingsEvent,
157 myEventCallbackCommand.GetPointer(),
160 //Definition of values labeling pipeline
162 myValLblDataSet = vtkUnstructuredGrid::New();
164 myValCellCenters = vtkCellCenters::New();
165 myValCellCenters->SetInput(myValLblDataSet);
167 myValMaskPoints = vtkMaskPoints::New();
168 myValMaskPoints->SetInput(myValCellCenters->GetOutput());
169 myValMaskPoints->SetOnRatio(1);
171 myValSelectVisiblePoints = VISU_SelectVisiblePoints::New();
172 myValSelectVisiblePoints->SetInput(myValMaskPoints->GetOutput());
173 myValSelectVisiblePoints->SelectInvisibleOff();
174 myValSelectVisiblePoints->SetTolerance(0.1);
176 char aFormat[16] = "%g";
177 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
179 // san: precision can be negative - this is used by double spin boxes
180 int aFloatingPrec = std::abs( aResourceMgr->integerValue("VISU", "visual_data_precision", 6) );
181 sprintf(aFormat, "%%.%dg", aFloatingPrec);
182 //cout << "$$$ aFormat = " << aFormat << endl;
185 myValLabeledDataMapper = vtkLabeledDataMapper::New();
186 myValLabeledDataMapper->SetInput(myValSelectVisiblePoints->GetOutput());
187 //myValLabeledDataMapper->SetLabelFormat("%g");
188 //myValLabeledDataMapper->SetLabelFormat("%.20g");
189 myValLabeledDataMapper->SetLabelFormat(aFormat);
190 myValLabeledDataMapper->SetLabelModeToLabelScalars();
192 vtkTextProperty* aClsTextProp = vtkTextProperty::New();
193 aClsTextProp->SetFontFamilyToTimes();
194 static int aCellsFontSize = 12;
195 aClsTextProp->SetFontSize(aCellsFontSize);
196 aClsTextProp->SetBold(1);
197 aClsTextProp->SetItalic(0);
198 aClsTextProp->SetShadow(0);
199 myValLabeledDataMapper->SetLabelTextProperty(aClsTextProp);
200 aClsTextProp->Delete();
202 myIsValLabeled = false;
204 myValLabels = vtkActor2D::New();
205 myValLabels->SetMapper(myValLabeledDataMapper);
206 myValLabels->GetProperty()->SetColor(0,1,0);
207 myValLabels->SetVisibility( myIsValLabeled );
209 // to allow modification of the reference coordinate in redefined SetPosition() methods
210 vtkCoordinate* aValLabelsCoordinate = vtkCoordinate::New();
211 myValLabels->GetPositionCoordinate()->SetReferenceCoordinate( aValLabelsCoordinate );
212 aValLabelsCoordinate->Delete();
215 //----------------------------------------------------------------------------
218 ::DeepCopy(VISU_Actor *theActor)
220 highlight(theActor->isHighlighted());
221 SetRepresentation(theActor->GetRepresentation());
222 SetShrinkable(theActor->IsShrunkable());
223 SetShrinkFactor(theActor->GetShrinkFactor());
224 if(theActor->IsShrunk())
229 SetFeatureEdgesAllowed(theActor->IsFeatureEdgesAllowed());
230 SetFeatureEdgesEnabled(theActor->IsFeatureEdgesEnabled());
231 SetFeatureEdgesAngle(theActor->GetFeatureEdgesAngle());
232 bool aFeatureEdges = false, aBoundaryEdges = false, aManifoldEdges = false, aNonManifoldEdges = false;
233 theActor->GetFeatureEdgesFlags( aFeatureEdges, aBoundaryEdges, aManifoldEdges, aNonManifoldEdges );
234 SetFeatureEdgesFlags( aFeatureEdges, aBoundaryEdges, aManifoldEdges, aNonManifoldEdges );
235 SetFeatureEdgesColoring(theActor->GetFeatureEdgesColoring());
237 SetOpacity(theActor->GetOpacity());
238 SetLineWidth(theActor->GetLineWidth());
239 SetPosition(theActor->GetPosition());
243 //----------------------------------------------------------------------------
246 ::ShallowCopyPL(VISU_PipeLine* thePipeLine)
248 myPipeLine->ShallowCopy(thePipeLine, true);
249 GetMapper()->Update();
252 //----------------------------------------------------------------------------
256 // Deleting of values labeling pipeline
257 myValLblDataSet->Delete();
258 myValLabeledDataMapper->RemoveAllInputs();
259 myValLabeledDataMapper->Delete();
260 myValSelectVisiblePoints->Delete();
261 myValMaskPoints->Delete();
262 myValCellCenters->Delete();
263 myValLabels->Delete();
265 if(MYDEBUG) MESSAGE("~VISU_Actor() - this = "<<this);
266 Superclass::SetProperty(NULL);
267 SetDebug(MYVTKDEBUG);
270 //----------------------------------------------------------------------------
273 ::setIO(const Handle(SALOME_InteractiveObject)& theIO)
275 Superclass::setIO(theIO);
276 myName = theIO->getName();
279 //----------------------------------------------------------------------------
282 ::SetPrs3d(VISU::Prs3d_i* thePrs3d)
294 //----------------------------------------------------------------------------
297 ::SetPipeLine(VISU_PipeLine* thePipeLine)
299 myPipeLine = thePipeLine;
301 if(vtkMapper *aMapper = myPipeLine->GetMapper()){
302 if(vtkDataSet *aDataSet = aMapper->GetInput()){
303 SetShrinkable(thePipeLine->IsShrinkable());
304 SetFeatureEdgesAllowed(thePipeLine->IsFeatureEdgesAllowed());
305 SetMapperInput(aDataSet);
316 return myPipeLine.GetPointer();
323 return GetPipeLine();
327 //----------------------------------------------------------------------------
330 ::SetRepresentation(int theMode)
332 Superclass::SetRepresentation(theMode);
333 if(myRepresentation == VTK_POINTS)
337 SetFeatureEdgesEnabled( theMode == SVTK::Representation::FeatureEdges );
341 //----------------------------------------------------------------------------
348 if(vtkDataSet* aDataSet = myPassFilter[0]->GetOutput()){
349 myShrinkFilter->SetInput(aDataSet);
350 myPassFilter[1]->SetInput(myShrinkFilter->GetOutput());
361 if(vtkDataSet* aDataSet = myPassFilter[0]->GetOutput()){
362 myPassFilter[1]->SetInput(aDataSet);
363 myPassFilter[1]->Modified();
378 ::SetShrinkable(bool theIsShrinkable)
380 myIsShrinkable = theIsShrinkable;
387 return myIsShrinkable;
392 ::SetShrinkFactor(vtkFloatingPointType theValue)
394 myShrinkFilter->SetShrinkFactor(theValue);
402 return myShrinkFilter->GetShrinkFactor();
406 //----------------------------------------------------------------------------
409 ::IsFeatureEdgesAllowed()
411 return myIsFeatureEdgesAllowed;
416 ::SetFeatureEdgesAllowed(bool theIsFeatureEdgesAllowed)
418 myIsFeatureEdgesAllowed = theIsFeatureEdgesAllowed;
423 ::IsFeatureEdgesEnabled()
425 return myIsFeatureEdgesEnabled;
430 ::SetFeatureEdgesEnabled(bool theIsFeatureEdgesEnabled)
432 if ( !myIsFeatureEdgesAllowed || myIsFeatureEdgesEnabled == theIsFeatureEdgesEnabled )
435 if ( vtkPolyData* aPolyData = myPassFilter[ 2 ]->GetPolyDataOutput() )
437 if( theIsFeatureEdgesEnabled )
439 myFeatureEdges->SetInput( aPolyData );
440 myPassFilter[ 3 ]->SetInput( myFeatureEdges->GetOutput() );
441 myIsFeatureEdgesEnabled = true;
445 myPassFilter[3]->SetInput( aPolyData );
446 myPassFilter[3]->Modified();
447 myIsFeatureEdgesEnabled = false;
450 myIsFeatureEdgesEnabled = theIsFeatureEdgesEnabled;
456 ::GetFeatureEdgesAngle()
458 return myFeatureEdges->GetFeatureAngle();
463 ::SetFeatureEdgesAngle(vtkFloatingPointType theValue)
465 myFeatureEdges->SetFeatureAngle(theValue);
471 ::GetFeatureEdgesFlags(bool& theIsFeatureEdges,
472 bool& theIsBoundaryEdges,
473 bool& theIsManifoldEdges,
474 bool& theIsNonManifoldEdges)
476 theIsFeatureEdges = myFeatureEdges->GetFeatureEdges();
477 theIsBoundaryEdges = myFeatureEdges->GetBoundaryEdges();
478 theIsManifoldEdges = myFeatureEdges->GetManifoldEdges();
479 theIsNonManifoldEdges = myFeatureEdges->GetNonManifoldEdges();
484 ::SetFeatureEdgesFlags(bool theIsFeatureEdges,
485 bool theIsBoundaryEdges,
486 bool theIsManifoldEdges,
487 bool theIsNonManifoldEdges)
489 myFeatureEdges->SetFeatureEdges(theIsFeatureEdges);
490 myFeatureEdges->SetBoundaryEdges(theIsBoundaryEdges);
491 myFeatureEdges->SetManifoldEdges(theIsManifoldEdges);
492 myFeatureEdges->SetNonManifoldEdges(theIsNonManifoldEdges);
498 ::GetFeatureEdgesColoring()
500 return myFeatureEdges->GetColoring();
505 ::SetFeatureEdgesColoring(bool theIsColoring)
507 myFeatureEdges->SetColoring(theIsColoring);
511 //----------------------------------------------------------------------------
514 ::SetOpacity(vtkFloatingPointType theValue)
516 GetProperty()->SetOpacity(theValue);
523 return GetProperty()->GetOpacity();
528 ::SetLineWidth(vtkFloatingPointType theLineWidth)
530 GetProperty()->SetLineWidth(theLineWidth);
537 return GetProperty()->GetLineWidth();
540 //==================================================================
541 // function: AddToRender
543 //==================================================================
546 ::AddToRender(vtkRenderer* theRenderer)
548 Superclass::AddToRender(theRenderer);
549 theRenderer->AddActor(myAnnotationActor.GetPointer());
550 theRenderer->AddActor(myTextActor.GetPointer());
552 myValSelectVisiblePoints->SetRenderer( theRenderer );
553 theRenderer->AddActor2D( myValLabels );
557 //==================================================================
558 // function: RemoveFromRender
560 //==================================================================
563 ::RemoveFromRender(vtkRenderer* theRenderer)
565 theRenderer->RemoveActor(myAnnotationActor.GetPointer());
566 theRenderer->RemoveActor(myTextActor.GetPointer());
567 theRenderer->RemoveActor(myValLabels);
568 Superclass::RemoveFromRender(theRenderer);
569 myDestroySignal(this);
572 //----------------------------------------------------------------------------
575 ::SetVisibility(int theMode)
577 Superclass::SetVisibility( theMode );
578 myValLabels->SetVisibility( myIsValLabeled && theMode );
580 // Moved from VISU_GaussPtsAct::SetVisibility() (due to IPAL21159)
581 Highlight(isHighlighted());
583 //----------------------------------------------------------------------------
584 //! Gets know whether the actor should be displayed or not
587 ::ShouldBeDisplayed()
589 return GetFactory()->GetActiveState();
592 //----------------------------------------------------------------------------
595 ::SetPosition( double thePosition[3] )
597 Superclass::SetPosition( thePosition );
598 if( vtkCoordinate* aCoord = myValLabels->GetPositionCoordinate()->GetReferenceCoordinate() )
599 aCoord->SetValue( thePosition );
600 myValSelectVisiblePoints->SetOffset( thePosition );
603 //----------------------------------------------------------------------------
606 ::SetPosition( double theX, double theY, double theZ )
608 Superclass::SetPosition( theX, theY, theZ );
609 if( vtkCoordinate* aCoord = myValLabels->GetPositionCoordinate()->GetReferenceCoordinate() )
610 aCoord->SetValue( theX, theY, theZ );
611 myValSelectVisiblePoints->SetOffset( theX, theY, theZ );
614 //----------------------------------------------------------------------------
617 ::SetVTKMapping(bool theIsVTKMapping)
619 myIsVTKMapping = theIsVTKMapping;
624 ::IsVTKMapping() const
626 return myIsVTKMapping;
629 //----------------------------------------------------------------------------
635 return Superclass::GetInput();
637 return GetCurrentPL()->GetOutput();
640 //----------------------------------------------------------------------------
645 static vtkFloatingPointType ERR_SIZE_CALC = 1.00;
646 vtkDataSet* aDataSet = GetMapper()->GetInput();
647 unsigned long int aSize = size_t(aDataSet->GetActualMemorySize() * 1024 * ERR_SIZE_CALC);
649 aDataSet = myGeomFilter->GetOutput();
650 aSize += aDataSet->GetActualMemorySize() * 1024;
653 aDataSet = myShrinkFilter->GetOutput();
654 aSize += aDataSet->GetActualMemorySize() * 1024;
657 if(IsFeatureEdgesEnabled()){
658 vtkPolyData* aPolyData = myFeatureEdges->GetOutput();
659 aSize += aPolyData->GetActualMemorySize() * 1024;
665 //----------------------------------------------------------------------------
668 ::GetNodeObjId(vtkIdType theID)
671 return Superclass::GetNodeObjId(theID);
673 return VISU::GetNodeObjID(GetMapper()->GetInput(), theID);
678 ::GetNodeVTKID(vtkIdType theID)
683 return VISU::GetNodeVTKID(GetMapper()->GetInput(), theID);
686 vtkFloatingPointType*
688 ::GetNodeCoord(vtkIdType theObjID)
691 return Superclass::GetNodeCoord(theObjID);
693 return VISU::GetNodeCoord(GetInput(), theObjID);
697 //----------------------------------------------------------------------------
700 ::GetElemObjId(vtkIdType theID)
703 return Superclass::GetElemObjId(theID);
705 return VISU::GetElemObjID(GetMapper()->GetInput(), theID);
710 ::GetElemVTKID(vtkIdType theID)
715 return VISU::GetElemVTKID(GetMapper()->GetInput(), theID);
720 ::GetElemCell(vtkIdType theObjID)
723 return Superclass::GetElemCell(theObjID);
725 return VISU::GetElemCell(GetInput(), theObjID);
729 //----------------------------------------------------------------------------
732 ::isSubElementsHighlighted()
734 return myIsSubElementsHighlighted;
738 //----------------------------------------------------------------------------
741 ChangeZoom(vtkFloatingPointType theZoomFactor,
742 vtkRenderer* theRenderer,
743 vtkIdType theInitialHasIndex,
744 vtkIdType theCurrentHasIndex)
746 //printf( "VISU_Actor::ChangeZoom( %d, %d )", theInitialHasIndex, theCurrentHasIndex );
747 if(theInitialHasIndex + theCurrentHasIndex == 1){
748 vtkCamera *aCamera = theRenderer->GetActiveCamera();
750 double aScale = aCamera->GetParallelScale();
751 if ( !theInitialHasIndex && theCurrentHasIndex ) {
752 //printf( " : +%f", theZoomFactor );
753 aCamera->SetParallelScale( aScale / theZoomFactor );
756 //printf( " : -%f", theZoomFactor );
757 aCamera->SetParallelScale( aScale * theZoomFactor );
764 Updates visibility of the highlight devices
768 ::highlight(bool theIsHighlight)
770 VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
772 bool aShowTextActor = aPickingSettings->GetInfoWindowEnabled();
773 if( theIsHighlight && mySelectionMode != myLastSelectionMode )
775 if( mySelectionMode == ActorSelection )
777 myLastSelectionMode = mySelectionMode;
780 myTextActor->SetVisibility( GetVisibility() && theIsHighlight && aShowTextActor &&
781 ( mySelectionMode == ActorSelection || isSubElementsHighlighted() ) );
783 bool anInitialHasIndex = isHighlighted();
784 bool aCurrentHasIndex = theIsHighlight;
786 if( !theIsHighlight && mySelectionMode == ActorSelection && isSubElementsHighlighted() )
788 myIsSubElementsHighlighted = false;
791 if( GetVisibility() && aPickingSettings->GetCameraMovementEnabled() )
793 vtkFloatingPointType aZoomFactor = aPickingSettings->GetZoomFactor();
794 ChangeZoom(aZoomFactor,
801 Superclass::highlight(theIsHighlight);
805 To process prehighlight (called from SVTK_InteractorStyle)
809 ::PreHighlight(vtkInteractorStyle* theInteractorStyle,
810 SVTK_SelectionEvent* theSelectionEvent,
813 bool aRet = Superclass::PreHighlight(theInteractorStyle,
816 #ifndef ENABLE_ANNOTATION
820 myAnnotationActor->SetVisibility(0);
822 switch(mySelectionMode){
824 vtkRenderer* aRenderer = theInteractorStyle->GetCurrentRenderer();
825 myCellPicker->Pick(theSelectionEvent->myX,
826 theSelectionEvent->myY,
830 if(myCellPicker->GetActor() != this)
833 vtkIdType aVTKId = myCellPicker->GetCellId();
834 if(aVTKId >= 0 && mySelector->IsValid(this,aVTKId,true) && hasIO()){
835 vtkIdType anObjId = GetElemObjId(aVTKId);
836 if(vtkCell* aCell = GetElemCell(anObjId)){
837 vtkPoints* aPts = aCell->GetPoints();
838 if(int aNbPts = aCell->GetNumberOfPoints()){
839 vtkFloatingPointType aCoord[3] = {0.0, 0.0, 0.0};
840 for(int i = 0; i < aNbPts; i++){
841 vtkFloatingPointType *aPntCoord = aPts->GetPoint(i);
842 aCoord[0] += aPntCoord[0];
843 aCoord[1] += aPntCoord[1];
844 aCoord[2] += aPntCoord[2];
846 // Display coordinates
847 vtkFloatingPointType aWorldCoord[4] = {aCoord[0]/aNbPts, aCoord[1]/aNbPts, aCoord[2]/aNbPts, 1.0};
848 aRenderer->SetWorldPoint(aWorldCoord);
849 aRenderer->WorldToDisplay();
850 vtkFloatingPointType aSelectionPoint[3];
851 aRenderer->GetDisplayPoint(aSelectionPoint);
852 myAnnotationActor->SetPosition(aSelectionPoint);
854 // To prepare the annotation text
855 std::ostringstream aStr;
856 aStr<<"Cell ID: "<< anObjId;
857 std::string aString = aStr.str();
858 myAnnotationMapper->SetInput(aString.c_str());
860 myAnnotationActor->SetVisibility(1);
868 vtkRenderer* aRenderer = theInteractorStyle->GetCurrentRenderer();
869 myPointPicker->Pick(theSelectionEvent->myX,
870 theSelectionEvent->myY,
874 if(myPointPicker->GetActor() != this)
877 vtkIdType aVtkId = myPointPicker->GetPointId();
878 if(aVtkId >= 0 && mySelector->IsValid(this,aVtkId,true) && hasIO()){
879 vtkIdType anObjId = GetNodeObjId( aVtkId );
880 if(vtkFloatingPointType* aCoord = GetNodeCoord(anObjId)){
881 // Display coordinates
882 vtkFloatingPointType aWorldCoord[4] = {aCoord[0], aCoord[1], aCoord[2], 1.0};
883 aRenderer->SetWorldPoint(aWorldCoord);
884 aRenderer->WorldToDisplay();
885 vtkFloatingPointType aSelectionPoint[3];
886 aRenderer->GetDisplayPoint(aSelectionPoint);
887 myAnnotationActor->SetPosition(aSelectionPoint);
889 // To prepare the annotation text
890 std::ostringstream aStr;
891 aStr<<"Node ID: "<< anObjId;
892 std::string aString = aStr.str();
893 myAnnotationMapper->SetInput(aString.c_str());
895 myAnnotationActor->SetVisibility(1);
901 case EdgeOfCellSelection:
911 void VISU_Actor::RemoveAllClippingPlanes()
915 vtkIdType VISU_Actor::GetNumberOfClippingPlanes()
920 bool VISU_Actor::AddClippingPlane(vtkPlane* thePlane)
925 vtkPlane* VISU_Actor::GetClippingPlane(vtkIdType theID)
930 vtkImplicitFunctionCollection* VISU_Actor::GetClippingPlanes()
935 //----------------------------------------------------------------------------
936 template<class TData> std::string getScalar(TData* theData, int theId)
938 std::ostringstream aStr;
939 if (vtkDataArray *aScalar = theData->GetScalars()){
940 vtkFloatingPointType aVal = aScalar->GetTuple1(theId);
941 aStr << "\nScalar: " << aVal;
946 template<class TData> std::string getVector(TData* theData, int theId)
948 std::ostringstream aStr;
949 if (vtkDataArray *aVector = theData->GetVectors()) {
950 vtkFloatingPointType *aVal = aVector->GetTuple3(theId);
951 aStr << "\nVector: " << "{" << aVal[0] << "; " << aVal[1] << "; " << aVal[2] << "}";
957 To process highlight (called from SVTK_InteractorStyle)
961 ::Highlight(vtkInteractorStyle* theInteractorStyle,
962 SVTK_SelectionEvent* theSelectionEvent,
965 return Superclass::Highlight(theInteractorStyle,
970 //-------------------------------------------------------------------------
973 ::Highlight(bool theIsHighlight)
975 Superclass::Highlight(theIsHighlight);
977 VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
979 bool anInitialHasIndex = isSubElementsHighlighted() && mySelectionMode != ActorSelection;
981 TColStd_IndexedMapOfInteger aMapIndex;
982 mySelector->GetIndex( getIO(), aMapIndex );
983 bool aCurrentHasIndex = aMapIndex.Extent() == 1;
985 myIsSubElementsHighlighted = aCurrentHasIndex;
988 vtkFloatingPointType aFlyToCoord[3] = { 0.0, 0.0, 0.0 };
989 vtkRenderer *aRenderer = GetRenderer();
993 vtkDataSet* aDataSet = GetMapper()->GetInput();
994 switch(mySelectionMode)
1003 if( !aCurrentHasIndex )
1005 myTextActor->SetVisibility(false);
1009 int anObjId = aMapIndex(1);
1010 vtkCellData* aCellData = aDataSet->GetCellData();
1011 if(vtkCell* aCell = GetElemCell(anObjId)){
1012 vtkPoints* aPts = aCell->GetPoints();
1013 if(int aNbPts = aCell->GetNumberOfPoints()){
1014 vtkFloatingPointType aCoord[3] = {0.0, 0.0, 0.0};
1015 for(int i = 0; i < aNbPts; i++){
1016 vtkFloatingPointType *aPntCoord = aPts->GetPoint(i);
1017 aCoord[0] += aPntCoord[0];
1018 aCoord[1] += aPntCoord[1];
1019 aCoord[2] += aPntCoord[2];
1023 aFlyToCoord[0] = aCoord[0] / aNbPts;
1024 aFlyToCoord[1] = aCoord[1] / aNbPts;
1025 aFlyToCoord[2] = aCoord[2] / aNbPts;
1027 vtkFloatingPointType aWorldCoord[4] = {aCoord[0]/aNbPts, aCoord[1]/aNbPts, aCoord[2]/aNbPts, 1.0};
1028 aRenderer->SetWorldPoint(aWorldCoord);
1029 aRenderer->WorldToDisplay();
1030 vtkFloatingPointType aSelectionPoint[3];
1031 aRenderer->GetDisplayPoint(aSelectionPoint);
1032 myTextActor->SetPosition(aSelectionPoint);
1033 myTextActor->SetModePosition(aPickingSettings->GetInfoWindowPosition());
1034 myTextActor->SetTransparency(aPickingSettings->GetInfoWindowTransparency());
1035 myTextActor->SetWorldPoint(aWorldCoord);
1037 std::ostringstream aStr;
1038 aStr << "Cell ID: " << anObjId;
1040 vtkCell* aCell = GetElemCell(anObjId);
1041 int aVTKID = GetElemVTKID(anObjId);
1043 int aNbOfPoints = aCell->GetNumberOfPoints();
1044 if ( aNbOfPoints > 0 ) {
1045 aStr << getScalar(aCellData, aVTKID);
1046 aStr << getVector(aCellData, aVTKID);
1050 std::string aString = aStr.str();
1051 myTextActor->SetText(aString.c_str());
1058 if( !aCurrentHasIndex )
1060 myTextActor->SetVisibility(false);
1064 int anObjId = aMapIndex(1);
1065 vtkPointData* aPntData = aDataSet->GetPointData();
1066 if(vtkFloatingPointType* aCoord = GetNodeCoord(anObjId)){
1068 aFlyToCoord[0] = aCoord[0];
1069 aFlyToCoord[1] = aCoord[1];
1070 aFlyToCoord[2] = aCoord[2];
1072 vtkFloatingPointType aWorldCoord[4] = {aCoord[0], aCoord[1], aCoord[2], 1.0};
1073 aRenderer->SetWorldPoint(aWorldCoord);
1074 aRenderer->WorldToDisplay();
1075 vtkFloatingPointType aSelectionPoint[3];
1076 aRenderer->GetDisplayPoint(aSelectionPoint);
1077 myTextActor->SetPosition(aSelectionPoint);
1078 myTextActor->SetModePosition(aPickingSettings->GetInfoWindowPosition());
1079 myTextActor->SetTransparency(aPickingSettings->GetInfoWindowTransparency());
1080 myTextActor->SetWorldPoint(aWorldCoord);
1082 std::ostringstream aStr;
1083 aStr << "Point ID: " << anObjId;
1085 int aVTKID = GetNodeVTKID(anObjId);
1087 aStr << getScalar(aPntData, aVTKID);
1088 aStr << getVector(aPntData, aVTKID);
1091 const VISU::PIDMapper& aMapper = GetPipeLine()->GetIDMapper();
1092 //VISU::TIdTypeVector aVec = aMapper->GetIndexesOfNode(anObjId);
1093 VISU::TStructuredId aVec = aMapper->GetIndexesOfNode(anObjId);
1095 aStr << "\nCoordinates: " << "[";
1097 //if( aVec.size() > 0 )
1099 aStr << " (" << aVec[0] << ")";
1103 //if( aVec.size() > 1 )
1105 aStr << " (" << aVec[1] << ")";
1109 //if( aVec.size() > 2 )
1111 aStr << " (" << aVec[2] << ")";
1114 std::string aString = aStr.str();
1115 myTextActor->SetText(aString.c_str());
1119 case EdgeOfCellSelection:
1127 if( GetVisibility() && aPickingSettings->GetCameraMovementEnabled() )
1129 vtkFloatingPointType aZoomFactor = aPickingSettings->GetZoomFactor();
1130 ChangeZoom(aZoomFactor,
1137 if( GetVisibility() && aPickingSettings->GetCameraMovementEnabled() && aFlyTo )
1139 vtkRenderWindowInteractor* anInteractor = myInteractor;
1140 vtkFloatingPointType aDollyWas = anInteractor->GetDolly();
1141 int aNumberOfFlyFramesWas = anInteractor->GetNumberOfFlyFrames();
1143 double aPosition[3];
1144 GetPosition( aPosition );
1145 for( int i = 0; i < 3; i++ )
1146 aFlyToCoord[i] += aPosition[i];
1148 anInteractor->SetDolly(0.0);
1149 anInteractor->SetNumberOfFlyFrames(aPickingSettings->GetStepNumber());
1150 anInteractor->FlyTo(aRenderer, aFlyToCoord);
1151 aRenderer->ResetCameraClippingRange();
1152 anInteractor->SetDolly(aDollyWas);
1153 anInteractor->SetNumberOfFlyFrames(aNumberOfFlyFramesWas);
1154 anInteractor->InvokeEvent(SVTK::ChangeRotationPoint, aFlyToCoord);
1158 //-------------------------------------------------------------------------
1163 VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
1165 vtkFloatingPointType aCoord[6];
1168 vtkFloatingPointType aWorldCoord[4] = { ( aCoord[0] + aCoord[1] ) / 2,
1169 ( aCoord[2] + aCoord[3] ) / 2,
1170 ( aCoord[4] + aCoord[5] ) / 2, 1.0};
1171 vtkRenderer* aRenderer = GetRenderer();
1172 aRenderer->SetWorldPoint(aWorldCoord);
1173 aRenderer->WorldToDisplay();
1174 vtkFloatingPointType aSelectionPoint[3];
1175 aRenderer->GetDisplayPoint(aSelectionPoint);
1176 myTextActor->SetPosition(aSelectionPoint);
1177 myTextActor->SetModePosition(aPickingSettings->GetInfoWindowPosition());
1178 myTextActor->SetTransparency(aPickingSettings->GetInfoWindowTransparency());
1179 myTextActor->SetWorldPoint(aWorldCoord);
1181 std::ostringstream aStr;
1183 if( const char* aName = getName() )
1184 aStr << aName << "\n";
1186 aStr << "Position: " << "[" << aCoord[0] << "; " << aCoord[2] << "; " << aCoord[4] << "]";
1187 aStr << "\nSize: " << "[" <<
1188 fabs(aCoord[1]-aCoord[0]) << "; " <<
1189 fabs(aCoord[3]-aCoord[2]) << "; " <<
1190 fabs(aCoord[5]-aCoord[4]) << "]";
1192 std::string aString = aStr.str();
1193 myTextActor->SetText(aString.c_str());
1196 //-------------------------------------------------------------------------
1199 ::ProcessEvents(vtkObject* vtkNotUsed(theObject),
1200 unsigned long theEvent,
1201 void* theClientData,
1202 void* vtkNotUsed(theCallData))
1204 if(vtkObject* anObject = reinterpret_cast<vtkObject*>(theClientData))
1205 if(VISU_Actor* self = dynamic_cast<VISU_Actor*>(anObject)) {
1206 if(theEvent == VISU::UpdatePickingSettingsEvent)
1207 self->UpdatePickingSettings();
1211 //----------------------------------------------------------------------------
1214 ::UpdatePickingSettings()
1216 //printf( "VISU_Actor::UpdatePickingSettings()\n" );
1217 VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
1218 if( !aPickingSettings )
1221 myTextActor->SetModePosition(aPickingSettings->GetInfoWindowPosition());
1222 myTextActor->SetTransparency(aPickingSettings->GetInfoWindowTransparency());
1224 Highlight(isHighlighted());
1229 // ---------------------------------------------------------------
1231 void VISU_Actor::SetValuesLabeled( const bool theIsValLabeled )
1233 vtkDataSet* aGrid = GetValLabelsInput();
1237 bool isOnPnt = VISU::IsDataOnPoints( aGrid );
1238 bool isOnCell = VISU::IsDataOnCells( aGrid );
1239 if ( !isOnPnt && !isOnCell )
1241 // try to specify location of scalars "manually"
1242 vtkCellData* aCData = aGrid->GetCellData();
1245 vtkDataArray* anArr = aCData->GetScalars();
1246 if ( anArr && anArr->GetNumberOfTuples() )
1252 vtkPointData* aPData = aGrid->GetPointData();
1255 vtkDataArray* anArr = aPData->GetScalars();
1256 if ( anArr && anArr->GetNumberOfTuples() )
1261 if ( !isOnPnt && !isOnCell )
1263 myValLabels->SetVisibility( false );
1268 myIsValLabeled = theIsValLabeled;
1270 if ( myIsValLabeled )
1272 vtkDataSet* aDataSet = aGrid;
1276 myValCellCenters->SetInput( aDataSet );
1277 myValMaskPoints->SetInput( myValCellCenters->GetOutput() );
1280 myValMaskPoints->SetInput( aDataSet );
1282 myValLabels->SetVisibility( GetVisibility() );
1285 myValLabels->SetVisibility( false );
1290 //----------------------------------------------------------------------------
1292 bool VISU_Actor::GetValuesLabeled() const
1294 return myIsValLabeled;
1297 //----------------------------------------------------------------------------
1299 vtkTextProperty* VISU_Actor::GetsValLabelsProps() const
1301 return myValLabeledDataMapper->GetLabelTextProperty();
1304 //----------------------------------------------------------------------------
1306 vtkDataSet* VISU_Actor::GetValLabelsInput()
1308 vtkDataSet* aDataSet = 0;
1309 VISU_PipeLine* aPL = GetPipeLine();
1311 aDataSet = aPL->GetOutput();
1313 aDataSet = GetInput();
1318 VISU_Actor::EQuadratic2DRepresentation
1319 VISU_Actor::GetQuadratic2DRepresentation() const
1321 if(Superclass::GetQuadraticArcMode()){
1322 return VISU_Actor::eArcs;
1325 return VISU_Actor::eLines;
1328 void VISU_Actor::SetQuadratic2DRepresentation( EQuadratic2DRepresentation theMode )
1331 case VISU_Actor::eArcs:
1332 myPreHighlightActor->SetQuadraticArcMode(true);
1333 myHighlightActor->SetQuadraticArcMode(true);
1335 case VISU_Actor::eLines:
1336 myPreHighlightActor->SetQuadraticArcMode(false);
1337 myHighlightActor->SetQuadraticArcMode(false);