1 // Copyright (C) 2007-2008 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
22 // VISU OBJECT : interactive object for VISU entities implementation
27 #include "VISU_Actor.h"
29 #include "VISU_ActorFactory.h"
30 #include "VISU_PickingSettings.h"
31 #include "VISU_GaussPtsDeviceActor.h"
32 #include "VISU_SelectVisiblePoints.h"
34 #include "VISU_PipeLine.hxx"
36 #include "SVTK_Actor.h"
37 #include "SVTK_Event.h"
39 #include "VTKViewer_FramedTextActor.h"
40 #include "VTKViewer_ShrinkFilter.h"
41 #include "VTKViewer_GeometryFilter.h"
43 #include "SALOME_InteractiveObject.hxx"
45 #include "SUIT_Session.h"
46 #include "SUIT_ResourceMgr.h"
52 #include <vtkProperty.h>
53 #include <vtkSmartPointer.h>
54 #include <vtkTextMapper.h>
55 #include <vtkTextActor.h>
56 #include <vtkProperty2D.h>
57 #include <vtkRenderer.h>
58 #include <vtkRenderWindow.h>
59 #include <vtkCellPicker.h>
61 #include <vtkPointPicker.h>
62 #include <vtkPoints.h>
63 #include <vtkInteractorStyle.h>
64 #include <vtkDataSet.h>
65 #include <vtkPolyData.h>
66 #include <vtkUnstructuredGrid.h>
67 #include <vtkPassThroughFilter.h>
68 #include <vtkFeatureEdges.h>
69 #include <vtkActor2D.h>
70 #include <vtkMaskPoints.h>
71 #include <vtkLabeledDataMapper.h>
72 #include <vtkTextProperty.h>
73 #include <vtkProperty2D.h>
75 #include <vtkShrinkFilter.h>
76 #include <vtkShrinkPolyData.h>
78 #include <vtkGeometryFilter.h>
79 #include <vtkObjectFactory.h>
81 #include <vtkCallbackCommand.h>
82 #include <vtkCamera.h>
83 #include <vtkRenderWindowInteractor.h>
85 #include <boost/bind.hpp>
87 #include "utilities.h"
89 #include "VISU_PipeLineUtils.hxx"
93 static int MYVTKDEBUG = 0;
96 static int MYDEBUG = 0;
98 static int MYDEBUG = 0;
101 //#define ENABLE_ANNOTATION
103 //----------------------------------------------------------------------------
104 //vtkStandardNewMacro(VISU_Actor);
106 //----------------------------------------------------------------------------
109 myEventCallbackCommand(vtkCallbackCommand::New()),
111 myIsVTKMapping(false),
114 myIsShrinkable(false),
115 myShrinkFilter(VTKViewer_ShrinkFilter::New()),
116 myAnnotationMapper(vtkTextMapper::New()),
117 #if (VTK_XVERSION < 0x050100)
118 myAnnotationActor(vtkTextActor::New()),
120 myAnnotationActor(vtkActor2D::New()),
122 myTextActor(VTKViewer_FramedTextActor::New()),
123 myIsFeatureEdgesAllowed(false),
124 myIsFeatureEdgesEnabled(false),
125 myFeatureEdges(vtkFeatureEdges::New()),
126 myLastSelectionMode(ActorSelection),
127 myIsSubElementsHighlighted(false)
129 if(MYDEBUG) MESSAGE("VISU_Actor::VISU_Actor - this = "<<this);
131 myShrinkFilter->Delete();
133 myStoreMapping = true;
135 myShrinkFilter->SetStoreMapping(true);
137 myAnnotationMapper->Delete();
138 myAnnotationActor->SetMapper(myAnnotationMapper.GetPointer());
140 myAnnotationActor->Delete();
141 myAnnotationActor->SetVisibility(0);
143 myTextActor->Delete();
144 myTextActor->SetVisibility(false);
145 myTextActor->SetPickable(false);
147 myFeatureEdges->Delete();
149 myEventCallbackCommand->Delete();
150 myEventCallbackCommand->SetClientData(this);
151 myEventCallbackCommand->SetCallback(VISU_Actor::ProcessEvents);
153 if( VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get() )
154 aPickingSettings->AddObserver(VISU::UpdatePickingSettingsEvent,
155 myEventCallbackCommand.GetPointer(),
158 //Definition of values labeling pipeline
160 myValLblDataSet = vtkUnstructuredGrid::New();
162 myValCellCenters = vtkCellCenters::New();
163 myValCellCenters->SetInput(myValLblDataSet);
165 myValMaskPoints = vtkMaskPoints::New();
166 myValMaskPoints->SetInput(myValCellCenters->GetOutput());
167 myValMaskPoints->SetOnRatio(1);
169 myValSelectVisiblePoints = VISU_SelectVisiblePoints::New();
170 myValSelectVisiblePoints->SetInput(myValMaskPoints->GetOutput());
171 myValSelectVisiblePoints->SelectInvisibleOff();
172 myValSelectVisiblePoints->SetTolerance(0.1);
174 char aFormat[16] = "%g";
175 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
177 int aFloatingPrec = aResourceMgr->integerValue("VISU", "floating_point_precision", 6);
178 sprintf(aFormat, "%%.%dg", aFloatingPrec);
179 //cout << "$$$ aFormat = " << aFormat << endl;
182 myValLabeledDataMapper = vtkLabeledDataMapper::New();
183 myValLabeledDataMapper->SetInput(myValSelectVisiblePoints->GetOutput());
184 //myValLabeledDataMapper->SetLabelFormat("%g");
185 //myValLabeledDataMapper->SetLabelFormat("%.20g");
186 myValLabeledDataMapper->SetLabelFormat(aFormat);
187 myValLabeledDataMapper->SetLabelModeToLabelScalars();
189 vtkTextProperty* aClsTextProp = vtkTextProperty::New();
190 aClsTextProp->SetFontFamilyToTimes();
191 static int aCellsFontSize = 12;
192 aClsTextProp->SetFontSize(aCellsFontSize);
193 aClsTextProp->SetBold(1);
194 aClsTextProp->SetItalic(0);
195 aClsTextProp->SetShadow(0);
196 myValLabeledDataMapper->SetLabelTextProperty(aClsTextProp);
197 aClsTextProp->Delete();
199 myIsValLabeled = false;
201 myValLabels = vtkActor2D::New();
202 myValLabels->SetMapper(myValLabeledDataMapper);
203 myValLabels->GetProperty()->SetColor(0,1,0);
204 myValLabels->SetVisibility( myIsValLabeled );
206 // to allow modification of the reference coordinate in redefined SetPosition() methods
207 vtkCoordinate* aValLabelsCoordinate = vtkCoordinate::New();
208 myValLabels->GetPositionCoordinate()->SetReferenceCoordinate( aValLabelsCoordinate );
209 aValLabelsCoordinate->Delete();
212 //----------------------------------------------------------------------------
215 ::DeepCopy(VISU_Actor *theActor)
217 highlight(theActor->isHighlighted());
218 SetRepresentation(theActor->GetRepresentation());
219 SetShrinkable(theActor->IsShrunkable());
220 SetShrinkFactor(theActor->GetShrinkFactor());
221 if(theActor->IsShrunk())
226 SetFeatureEdgesAllowed(theActor->IsFeatureEdgesAllowed());
227 SetFeatureEdgesEnabled(theActor->IsFeatureEdgesEnabled());
228 SetFeatureEdgesAngle(theActor->GetFeatureEdgesAngle());
229 bool aFeatureEdges = false, aBoundaryEdges = false, aManifoldEdges = false, aNonManifoldEdges = false;
230 theActor->GetFeatureEdgesFlags( aFeatureEdges, aBoundaryEdges, aManifoldEdges, aNonManifoldEdges );
231 SetFeatureEdgesFlags( aFeatureEdges, aBoundaryEdges, aManifoldEdges, aNonManifoldEdges );
232 SetFeatureEdgesColoring(theActor->GetFeatureEdgesColoring());
234 SetOpacity(theActor->GetOpacity());
235 SetLineWidth(theActor->GetLineWidth());
236 SetPosition(theActor->GetPosition());
240 //----------------------------------------------------------------------------
243 ::ShallowCopyPL(VISU_PipeLine* thePipeLine)
245 myPipeLine->ShallowCopy(thePipeLine, true);
246 GetMapper()->Update();
249 //----------------------------------------------------------------------------
253 // Deleting of values labeling pipeline
254 myValLblDataSet->Delete();
255 myValLabeledDataMapper->RemoveAllInputs();
256 myValLabeledDataMapper->Delete();
257 myValSelectVisiblePoints->Delete();
258 myValMaskPoints->Delete();
259 myValCellCenters->Delete();
260 myValLabels->Delete();
262 if(MYDEBUG) MESSAGE("~VISU_Actor() - this = "<<this);
263 Superclass::SetProperty(NULL);
264 SetDebug(MYVTKDEBUG);
267 //----------------------------------------------------------------------------
270 ::setIO(const Handle(SALOME_InteractiveObject)& theIO)
272 Superclass::setIO(theIO);
273 myName = theIO->getName();
276 //----------------------------------------------------------------------------
279 ::SetPrs3d(VISU::Prs3d_i* thePrs3d)
291 //----------------------------------------------------------------------------
294 ::SetPipeLine(VISU_PipeLine* thePipeLine)
296 myPipeLine = thePipeLine;
298 if(vtkMapper *aMapper = myPipeLine->GetMapper()){
299 if(vtkDataSet *aDataSet = aMapper->GetInput()){
300 SetShrinkable(thePipeLine->IsShrinkable());
301 SetFeatureEdgesAllowed(thePipeLine->IsFeatureEdgesAllowed());
302 SetMapperInput(aDataSet);
313 return myPipeLine.GetPointer();
320 return GetPipeLine();
324 //----------------------------------------------------------------------------
327 ::SetRepresentation(int theMode)
329 Superclass::SetRepresentation(theMode);
330 if(myRepresentation == VTK_POINTS)
334 SetFeatureEdgesEnabled( theMode == SVTK::Representation::FeatureEdges );
338 //----------------------------------------------------------------------------
345 if(vtkDataSet* aDataSet = myPassFilter[0]->GetOutput()){
346 myShrinkFilter->SetInput(aDataSet);
347 myPassFilter[1]->SetInput(myShrinkFilter->GetOutput());
358 if(vtkDataSet* aDataSet = myPassFilter[0]->GetOutput()){
359 myPassFilter[1]->SetInput(aDataSet);
360 myPassFilter[1]->Modified();
375 ::SetShrinkable(bool theIsShrinkable)
377 myIsShrinkable = theIsShrinkable;
384 return myIsShrinkable;
389 ::SetShrinkFactor(vtkFloatingPointType theValue)
391 myShrinkFilter->SetShrinkFactor(theValue);
399 return myShrinkFilter->GetShrinkFactor();
403 //----------------------------------------------------------------------------
406 ::IsFeatureEdgesAllowed()
408 return myIsFeatureEdgesAllowed;
413 ::SetFeatureEdgesAllowed(bool theIsFeatureEdgesAllowed)
415 myIsFeatureEdgesAllowed = theIsFeatureEdgesAllowed;
420 ::IsFeatureEdgesEnabled()
422 return myIsFeatureEdgesEnabled;
427 ::SetFeatureEdgesEnabled(bool theIsFeatureEdgesEnabled)
429 if ( !myIsFeatureEdgesAllowed || myIsFeatureEdgesEnabled == theIsFeatureEdgesEnabled )
432 if ( vtkPolyData* aPolyData = myPassFilter[ 2 ]->GetPolyDataOutput() )
434 if( theIsFeatureEdgesEnabled )
436 myFeatureEdges->SetInput( aPolyData );
437 myPassFilter[ 3 ]->SetInput( myFeatureEdges->GetOutput() );
438 myIsFeatureEdgesEnabled = true;
442 myPassFilter[3]->SetInput( aPolyData );
443 myPassFilter[3]->Modified();
444 myIsFeatureEdgesEnabled = false;
447 myIsFeatureEdgesEnabled = theIsFeatureEdgesEnabled;
453 ::GetFeatureEdgesAngle()
455 return myFeatureEdges->GetFeatureAngle();
460 ::SetFeatureEdgesAngle(vtkFloatingPointType theValue)
462 myFeatureEdges->SetFeatureAngle(theValue);
468 ::GetFeatureEdgesFlags(bool& theIsFeatureEdges,
469 bool& theIsBoundaryEdges,
470 bool& theIsManifoldEdges,
471 bool& theIsNonManifoldEdges)
473 theIsFeatureEdges = myFeatureEdges->GetFeatureEdges();
474 theIsBoundaryEdges = myFeatureEdges->GetBoundaryEdges();
475 theIsManifoldEdges = myFeatureEdges->GetManifoldEdges();
476 theIsNonManifoldEdges = myFeatureEdges->GetNonManifoldEdges();
481 ::SetFeatureEdgesFlags(bool theIsFeatureEdges,
482 bool theIsBoundaryEdges,
483 bool theIsManifoldEdges,
484 bool theIsNonManifoldEdges)
486 myFeatureEdges->SetFeatureEdges(theIsFeatureEdges);
487 myFeatureEdges->SetBoundaryEdges(theIsBoundaryEdges);
488 myFeatureEdges->SetManifoldEdges(theIsManifoldEdges);
489 myFeatureEdges->SetNonManifoldEdges(theIsNonManifoldEdges);
495 ::GetFeatureEdgesColoring()
497 return myFeatureEdges->GetColoring();
502 ::SetFeatureEdgesColoring(bool theIsColoring)
504 myFeatureEdges->SetColoring(theIsColoring);
508 //----------------------------------------------------------------------------
511 ::SetOpacity(vtkFloatingPointType theValue)
513 GetProperty()->SetOpacity(theValue);
520 return GetProperty()->GetOpacity();
525 ::SetLineWidth(vtkFloatingPointType theLineWidth)
527 GetProperty()->SetLineWidth(theLineWidth);
534 return GetProperty()->GetLineWidth();
537 //==================================================================
538 // function: AddToRender
540 //==================================================================
543 ::AddToRender(vtkRenderer* theRenderer)
545 Superclass::AddToRender(theRenderer);
546 theRenderer->AddActor(myAnnotationActor.GetPointer());
547 theRenderer->AddActor(myTextActor.GetPointer());
549 myValSelectVisiblePoints->SetRenderer( theRenderer );
550 theRenderer->AddActor2D( myValLabels );
554 //==================================================================
555 // function: RemoveFromRender
557 //==================================================================
560 ::RemoveFromRender(vtkRenderer* theRenderer)
562 theRenderer->RemoveActor(myAnnotationActor.GetPointer());
563 theRenderer->RemoveActor(myTextActor.GetPointer());
564 theRenderer->RemoveActor(myValLabels);
565 Superclass::RemoveFromRender(theRenderer);
566 myDestroySignal(this);
569 //----------------------------------------------------------------------------
572 ::SetVisibility(int theMode)
574 Superclass::SetVisibility( theMode );
575 myValLabels->SetVisibility( myIsValLabeled && theMode );
577 // Moved from VISU_GaussPtsAct::SetVisibility() (due to IPAL21159)
578 Highlight(isHighlighted());
580 //----------------------------------------------------------------------------
581 //! Gets know whether the actor should be displayed or not
584 ::ShouldBeDisplayed()
586 return GetFactory()->GetActiveState();
589 //----------------------------------------------------------------------------
592 ::SetPosition( double thePosition[3] )
594 Superclass::SetPosition( thePosition );
595 if( vtkCoordinate* aCoord = myValLabels->GetPositionCoordinate()->GetReferenceCoordinate() )
596 aCoord->SetValue( thePosition );
597 myValSelectVisiblePoints->SetOffset( thePosition );
600 //----------------------------------------------------------------------------
603 ::SetPosition( double theX, double theY, double theZ )
605 Superclass::SetPosition( theX, theY, theZ );
606 if( vtkCoordinate* aCoord = myValLabels->GetPositionCoordinate()->GetReferenceCoordinate() )
607 aCoord->SetValue( theX, theY, theZ );
608 myValSelectVisiblePoints->SetOffset( theX, theY, theZ );
611 //----------------------------------------------------------------------------
614 ::SetVTKMapping(bool theIsVTKMapping)
616 myIsVTKMapping = theIsVTKMapping;
621 ::IsVTKMapping() const
623 return myIsVTKMapping;
626 //----------------------------------------------------------------------------
632 return Superclass::GetInput();
634 return GetCurrentPL()->GetOutput();
637 //----------------------------------------------------------------------------
642 static vtkFloatingPointType ERR_SIZE_CALC = 1.00;
643 vtkDataSet* aDataSet = GetMapper()->GetInput();
644 unsigned long int aSize = size_t(aDataSet->GetActualMemorySize() * 1024 * ERR_SIZE_CALC);
646 aDataSet = myGeomFilter->GetOutput();
647 aSize += aDataSet->GetActualMemorySize() * 1024;
650 aDataSet = myShrinkFilter->GetOutput();
651 aSize += aDataSet->GetActualMemorySize() * 1024;
654 if(IsFeatureEdgesEnabled()){
655 vtkPolyData* aPolyData = myFeatureEdges->GetOutput();
656 aSize += aPolyData->GetActualMemorySize() * 1024;
662 //----------------------------------------------------------------------------
665 ::GetNodeObjId(vtkIdType theID)
668 return Superclass::GetNodeObjId(theID);
670 return VISU::GetNodeObjID(GetMapper()->GetInput(), theID);
675 ::GetNodeVTKID(vtkIdType theID)
680 return VISU::GetNodeVTKID(GetMapper()->GetInput(), theID);
683 vtkFloatingPointType*
685 ::GetNodeCoord(vtkIdType theObjID)
688 return Superclass::GetNodeCoord(theObjID);
690 return VISU::GetNodeCoord(GetInput(), theObjID);
694 //----------------------------------------------------------------------------
697 ::GetElemObjId(vtkIdType theID)
700 return Superclass::GetElemObjId(theID);
702 return VISU::GetElemObjID(GetMapper()->GetInput(), theID);
707 ::GetElemVTKID(vtkIdType theID)
712 return VISU::GetElemVTKID(GetMapper()->GetInput(), theID);
717 ::GetElemCell(vtkIdType theObjID)
720 return Superclass::GetElemCell(theObjID);
722 return VISU::GetElemCell(GetInput(), theObjID);
726 //----------------------------------------------------------------------------
729 ::isSubElementsHighlighted()
731 return myIsSubElementsHighlighted;
735 //----------------------------------------------------------------------------
738 ChangeZoom(vtkFloatingPointType theZoomFactor,
739 vtkRenderer* theRenderer,
740 vtkIdType theInitialHasIndex,
741 vtkIdType theCurrentHasIndex)
743 //printf( "VISU_Actor::ChangeZoom( %d, %d )", theInitialHasIndex, theCurrentHasIndex );
744 if(theInitialHasIndex + theCurrentHasIndex == 1){
745 vtkCamera *aCamera = theRenderer->GetActiveCamera();
747 double aScale = aCamera->GetParallelScale();
748 if ( !theInitialHasIndex && theCurrentHasIndex ) {
749 //printf( " : +%f", theZoomFactor );
750 aCamera->SetParallelScale( aScale / theZoomFactor );
753 //printf( " : -%f", theZoomFactor );
754 aCamera->SetParallelScale( aScale * theZoomFactor );
761 Updates visibility of the highlight devices
765 ::highlight(bool theIsHighlight)
767 VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
769 bool aShowTextActor = aPickingSettings->GetInfoWindowEnabled();
770 if( theIsHighlight && mySelectionMode != myLastSelectionMode )
772 if( mySelectionMode == ActorSelection )
774 myLastSelectionMode = mySelectionMode;
777 myTextActor->SetVisibility( GetVisibility() && theIsHighlight && aShowTextActor &&
778 ( mySelectionMode == ActorSelection || isSubElementsHighlighted() ) );
780 bool anInitialHasIndex = isHighlighted();
781 bool aCurrentHasIndex = theIsHighlight;
783 if( !theIsHighlight && mySelectionMode == ActorSelection && isSubElementsHighlighted() )
785 myIsSubElementsHighlighted = false;
788 if( GetVisibility() && aPickingSettings->GetCameraMovementEnabled() )
790 vtkFloatingPointType aZoomFactor = aPickingSettings->GetZoomFactor();
791 ChangeZoom(aZoomFactor,
798 Superclass::highlight(theIsHighlight);
802 To process prehighlight (called from SVTK_InteractorStyle)
806 ::PreHighlight(vtkInteractorStyle* theInteractorStyle,
807 SVTK_SelectionEvent* theSelectionEvent,
810 bool aRet = Superclass::PreHighlight(theInteractorStyle,
813 #ifndef ENABLE_ANNOTATION
817 myAnnotationActor->SetVisibility(0);
819 switch(mySelectionMode){
821 vtkRenderer* aRenderer = theInteractorStyle->GetCurrentRenderer();
822 myCellPicker->Pick(theSelectionEvent->myX,
823 theSelectionEvent->myY,
827 if(myCellPicker->GetActor() != this)
830 vtkIdType aVTKId = myCellPicker->GetCellId();
831 if(aVTKId >= 0 && mySelector->IsValid(this,aVTKId,true) && hasIO()){
832 vtkIdType anObjId = GetElemObjId(aVTKId);
833 if(vtkCell* aCell = GetElemCell(anObjId)){
834 vtkPoints* aPts = aCell->GetPoints();
835 if(int aNbPts = aCell->GetNumberOfPoints()){
836 vtkFloatingPointType aCoord[3] = {0.0, 0.0, 0.0};
837 for(int i = 0; i < aNbPts; i++){
838 vtkFloatingPointType *aPntCoord = aPts->GetPoint(i);
839 aCoord[0] += aPntCoord[0];
840 aCoord[1] += aPntCoord[1];
841 aCoord[2] += aPntCoord[2];
843 // Display coordinates
844 vtkFloatingPointType aWorldCoord[4] = {aCoord[0]/aNbPts, aCoord[1]/aNbPts, aCoord[2]/aNbPts, 1.0};
845 aRenderer->SetWorldPoint(aWorldCoord);
846 aRenderer->WorldToDisplay();
847 vtkFloatingPointType aSelectionPoint[3];
848 aRenderer->GetDisplayPoint(aSelectionPoint);
849 myAnnotationActor->SetPosition(aSelectionPoint);
851 // To prepare the annotation text
852 std::ostringstream aStr;
853 aStr<<"Cell ID: "<< anObjId;
854 std::string aString = aStr.str();
855 myAnnotationMapper->SetInput(aString.c_str());
857 myAnnotationActor->SetVisibility(1);
865 vtkRenderer* aRenderer = theInteractorStyle->GetCurrentRenderer();
866 myPointPicker->Pick(theSelectionEvent->myX,
867 theSelectionEvent->myY,
871 if(myPointPicker->GetActor() != this)
874 vtkIdType aVtkId = myPointPicker->GetPointId();
875 if(aVtkId >= 0 && mySelector->IsValid(this,aVtkId,true) && hasIO()){
876 vtkIdType anObjId = GetNodeObjId( aVtkId );
877 if(vtkFloatingPointType* aCoord = GetNodeCoord(anObjId)){
878 // Display coordinates
879 vtkFloatingPointType aWorldCoord[4] = {aCoord[0], aCoord[1], aCoord[2], 1.0};
880 aRenderer->SetWorldPoint(aWorldCoord);
881 aRenderer->WorldToDisplay();
882 vtkFloatingPointType aSelectionPoint[3];
883 aRenderer->GetDisplayPoint(aSelectionPoint);
884 myAnnotationActor->SetPosition(aSelectionPoint);
886 // To prepare the annotation text
887 std::ostringstream aStr;
888 aStr<<"Node ID: "<< anObjId;
889 std::string aString = aStr.str();
890 myAnnotationMapper->SetInput(aString.c_str());
892 myAnnotationActor->SetVisibility(1);
898 case EdgeOfCellSelection:
908 void VISU_Actor::RemoveAllClippingPlanes()
912 vtkIdType VISU_Actor::GetNumberOfClippingPlanes()
917 bool VISU_Actor::AddClippingPlane(vtkPlane* thePlane)
922 vtkPlane* VISU_Actor::GetClippingPlane(vtkIdType theID)
927 vtkImplicitFunctionCollection* VISU_Actor::GetClippingPlanes()
932 //----------------------------------------------------------------------------
933 template<class TData> std::string getScalar(TData* theData, int theId)
935 std::ostringstream aStr;
936 if (vtkDataArray *aScalar = theData->GetScalars()){
937 vtkFloatingPointType aVal = aScalar->GetTuple1(theId);
938 aStr << "\nScalar: " << aVal;
943 template<class TData> std::string getVector(TData* theData, int theId)
945 std::ostringstream aStr;
946 if (vtkDataArray *aVector = theData->GetVectors()) {
947 vtkFloatingPointType *aVal = aVector->GetTuple3(theId);
948 aStr << "\nVector: " << "{" << aVal[0] << "; " << aVal[1] << "; " << aVal[2] << "}";
954 To process highlight (called from SVTK_InteractorStyle)
958 ::Highlight(vtkInteractorStyle* theInteractorStyle,
959 SVTK_SelectionEvent* theSelectionEvent,
962 return Superclass::Highlight(theInteractorStyle,
967 //-------------------------------------------------------------------------
970 ::Highlight(bool theIsHighlight)
972 Superclass::Highlight(theIsHighlight);
974 VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
976 bool anInitialHasIndex = isSubElementsHighlighted() && mySelectionMode != ActorSelection;
978 TColStd_IndexedMapOfInteger aMapIndex;
979 mySelector->GetIndex( getIO(), aMapIndex );
980 bool aCurrentHasIndex = aMapIndex.Extent() == 1;
982 myIsSubElementsHighlighted = aCurrentHasIndex;
985 vtkFloatingPointType aFlyToCoord[3] = { 0.0, 0.0, 0.0 };
986 vtkRenderer *aRenderer = GetRenderer();
990 vtkDataSet* aDataSet = GetMapper()->GetInput();
991 switch(mySelectionMode)
1000 if( !aCurrentHasIndex )
1002 myTextActor->SetVisibility(false);
1006 int anObjId = aMapIndex(1);
1007 vtkCellData* aCellData = aDataSet->GetCellData();
1008 if(vtkCell* aCell = GetElemCell(anObjId)){
1009 vtkPoints* aPts = aCell->GetPoints();
1010 if(int aNbPts = aCell->GetNumberOfPoints()){
1011 vtkFloatingPointType aCoord[3] = {0.0, 0.0, 0.0};
1012 for(int i = 0; i < aNbPts; i++){
1013 vtkFloatingPointType *aPntCoord = aPts->GetPoint(i);
1014 aCoord[0] += aPntCoord[0];
1015 aCoord[1] += aPntCoord[1];
1016 aCoord[2] += aPntCoord[2];
1020 aFlyToCoord[0] = aCoord[0] / aNbPts;
1021 aFlyToCoord[1] = aCoord[1] / aNbPts;
1022 aFlyToCoord[2] = aCoord[2] / aNbPts;
1024 vtkFloatingPointType aWorldCoord[4] = {aCoord[0]/aNbPts, aCoord[1]/aNbPts, aCoord[2]/aNbPts, 1.0};
1025 aRenderer->SetWorldPoint(aWorldCoord);
1026 aRenderer->WorldToDisplay();
1027 vtkFloatingPointType aSelectionPoint[3];
1028 aRenderer->GetDisplayPoint(aSelectionPoint);
1029 myTextActor->SetPosition(aSelectionPoint);
1030 myTextActor->SetModePosition(aPickingSettings->GetInfoWindowPosition());
1031 myTextActor->SetTransparency(aPickingSettings->GetInfoWindowTransparency());
1032 myTextActor->SetWorldPoint(aWorldCoord);
1034 std::ostringstream aStr;
1035 aStr << "Cell ID: " << anObjId;
1037 vtkCell* aCell = GetElemCell(anObjId);
1038 int aVTKID = GetElemVTKID(anObjId);
1040 int aNbOfPoints = aCell->GetNumberOfPoints();
1041 if ( aNbOfPoints > 0 ) {
1042 aStr << getScalar(aCellData, aVTKID);
1043 aStr << getVector(aCellData, aVTKID);
1047 std::string aString = aStr.str();
1048 myTextActor->SetText(aString.c_str());
1055 if( !aCurrentHasIndex )
1057 myTextActor->SetVisibility(false);
1061 int anObjId = aMapIndex(1);
1062 vtkPointData* aPntData = aDataSet->GetPointData();
1063 if(vtkFloatingPointType* aCoord = GetNodeCoord(anObjId)){
1065 aFlyToCoord[0] = aCoord[0];
1066 aFlyToCoord[1] = aCoord[1];
1067 aFlyToCoord[2] = aCoord[2];
1069 vtkFloatingPointType aWorldCoord[4] = {aCoord[0], aCoord[1], aCoord[2], 1.0};
1070 aRenderer->SetWorldPoint(aWorldCoord);
1071 aRenderer->WorldToDisplay();
1072 vtkFloatingPointType aSelectionPoint[3];
1073 aRenderer->GetDisplayPoint(aSelectionPoint);
1074 myTextActor->SetPosition(aSelectionPoint);
1075 myTextActor->SetModePosition(aPickingSettings->GetInfoWindowPosition());
1076 myTextActor->SetTransparency(aPickingSettings->GetInfoWindowTransparency());
1077 myTextActor->SetWorldPoint(aWorldCoord);
1079 std::ostringstream aStr;
1080 aStr << "Point ID: " << anObjId;
1082 int aVTKID = GetNodeVTKID(anObjId);
1084 aStr << getScalar(aPntData, aVTKID);
1085 aStr << getVector(aPntData, aVTKID);
1088 const VISU::PIDMapper& aMapper = GetPipeLine()->GetIDMapper();
1089 //VISU::TIdTypeVector aVec = aMapper->GetIndexesOfNode(anObjId);
1090 VISU::TStructuredId aVec = aMapper->GetIndexesOfNode(anObjId);
1092 aStr << "\nCoordinates: " << "[";
1094 //if( aVec.size() > 0 )
1096 aStr << " (" << aVec[0] << ")";
1100 //if( aVec.size() > 1 )
1102 aStr << " (" << aVec[1] << ")";
1106 //if( aVec.size() > 2 )
1108 aStr << " (" << aVec[2] << ")";
1111 std::string aString = aStr.str();
1112 myTextActor->SetText(aString.c_str());
1116 case EdgeOfCellSelection:
1124 if( GetVisibility() && aPickingSettings->GetCameraMovementEnabled() )
1126 vtkFloatingPointType aZoomFactor = aPickingSettings->GetZoomFactor();
1127 ChangeZoom(aZoomFactor,
1134 if( GetVisibility() && aPickingSettings->GetCameraMovementEnabled() && aFlyTo )
1136 vtkRenderWindowInteractor* anInteractor = myInteractor;
1137 vtkFloatingPointType aDollyWas = anInteractor->GetDolly();
1138 int aNumberOfFlyFramesWas = anInteractor->GetNumberOfFlyFrames();
1140 double aPosition[3];
1141 GetPosition( aPosition );
1142 for( int i = 0; i < 3; i++ )
1143 aFlyToCoord[i] += aPosition[i];
1145 anInteractor->SetDolly(0.0);
1146 anInteractor->SetNumberOfFlyFrames(aPickingSettings->GetStepNumber());
1147 anInteractor->FlyTo(aRenderer, aFlyToCoord);
1148 aRenderer->ResetCameraClippingRange();
1149 anInteractor->SetDolly(aDollyWas);
1150 anInteractor->SetNumberOfFlyFrames(aNumberOfFlyFramesWas);
1151 anInteractor->InvokeEvent(SVTK::ChangeRotationPoint, aFlyToCoord);
1155 //-------------------------------------------------------------------------
1160 VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
1162 vtkFloatingPointType aCoord[6];
1165 vtkFloatingPointType aWorldCoord[4] = { ( aCoord[0] + aCoord[1] ) / 2,
1166 ( aCoord[2] + aCoord[3] ) / 2,
1167 ( aCoord[4] + aCoord[5] ) / 2, 1.0};
1168 vtkRenderer* aRenderer = GetRenderer();
1169 aRenderer->SetWorldPoint(aWorldCoord);
1170 aRenderer->WorldToDisplay();
1171 vtkFloatingPointType aSelectionPoint[3];
1172 aRenderer->GetDisplayPoint(aSelectionPoint);
1173 myTextActor->SetPosition(aSelectionPoint);
1174 myTextActor->SetModePosition(aPickingSettings->GetInfoWindowPosition());
1175 myTextActor->SetTransparency(aPickingSettings->GetInfoWindowTransparency());
1176 myTextActor->SetWorldPoint(aWorldCoord);
1178 std::ostringstream aStr;
1180 if( const char* aName = getName() )
1181 aStr << aName << "\n";
1183 aStr << "Position: " << "[" << aCoord[0] << "; " << aCoord[2] << "; " << aCoord[4] << "]";
1184 aStr << "\nSize: " << "[" <<
1185 fabs(aCoord[1]-aCoord[0]) << "; " <<
1186 fabs(aCoord[3]-aCoord[2]) << "; " <<
1187 fabs(aCoord[5]-aCoord[4]) << "]";
1189 std::string aString = aStr.str();
1190 myTextActor->SetText(aString.c_str());
1193 //-------------------------------------------------------------------------
1196 ::ProcessEvents(vtkObject* vtkNotUsed(theObject),
1197 unsigned long theEvent,
1198 void* theClientData,
1199 void* vtkNotUsed(theCallData))
1201 if(vtkObject* anObject = reinterpret_cast<vtkObject*>(theClientData))
1202 if(VISU_Actor* self = dynamic_cast<VISU_Actor*>(anObject)) {
1203 if(theEvent == VISU::UpdatePickingSettingsEvent)
1204 self->UpdatePickingSettings();
1208 //----------------------------------------------------------------------------
1211 ::UpdatePickingSettings()
1213 //printf( "VISU_Actor::UpdatePickingSettings()\n" );
1214 VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
1215 if( !aPickingSettings )
1218 myTextActor->SetModePosition(aPickingSettings->GetInfoWindowPosition());
1219 myTextActor->SetTransparency(aPickingSettings->GetInfoWindowTransparency());
1221 Highlight(isHighlighted());
1226 // ---------------------------------------------------------------
1228 void VISU_Actor::SetValuesLabeled( const bool theIsValLabeled )
1230 vtkDataSet* aGrid = GetValLabelsInput();
1234 bool isOnPnt = VISU::IsDataOnPoints( aGrid );
1235 bool isOnCell = VISU::IsDataOnCells( aGrid );
1236 if ( !isOnPnt && !isOnCell )
1238 // try to specify location of scalars "manually"
1239 vtkCellData* aCData = aGrid->GetCellData();
1242 vtkDataArray* anArr = aCData->GetScalars();
1243 if ( anArr && anArr->GetNumberOfTuples() )
1249 vtkPointData* aPData = aGrid->GetPointData();
1252 vtkDataArray* anArr = aPData->GetScalars();
1253 if ( anArr && anArr->GetNumberOfTuples() )
1258 if ( !isOnPnt && !isOnCell )
1260 myValLabels->SetVisibility( false );
1265 myIsValLabeled = theIsValLabeled;
1267 if ( myIsValLabeled )
1269 vtkDataSet* aDataSet = aGrid;
1273 myValCellCenters->SetInput( aDataSet );
1274 myValMaskPoints->SetInput( myValCellCenters->GetOutput() );
1277 myValMaskPoints->SetInput( aDataSet );
1279 myValLabels->SetVisibility( GetVisibility() );
1282 myValLabels->SetVisibility( false );
1287 //----------------------------------------------------------------------------
1289 bool VISU_Actor::GetValuesLabeled() const
1291 return myIsValLabeled;
1294 //----------------------------------------------------------------------------
1296 vtkTextProperty* VISU_Actor::GetsValLabelsProps() const
1298 return myValLabeledDataMapper->GetLabelTextProperty();
1301 //----------------------------------------------------------------------------
1303 vtkDataSet* VISU_Actor::GetValLabelsInput()
1305 vtkDataSet* aDataSet = 0;
1306 VISU_PipeLine* aPL = GetPipeLine();
1308 aDataSet = aPL->GetOutput();
1310 aDataSet = GetInput();
1315 VISU_Actor::EQuadratic2DRepresentation
1316 VISU_Actor::GetQuadratic2DRepresentation() const
1318 if(Superclass::GetQuadraticArcMode()){
1319 return VISU_Actor::eArcs;
1322 return VISU_Actor::eLines;
1325 void VISU_Actor::SetQuadratic2DRepresentation( EQuadratic2DRepresentation theMode )
1328 case VISU_Actor::eArcs:
1329 myPreHighlightActor->SetQuadraticArcMode(true);
1330 myHighlightActor->SetQuadraticArcMode(true);
1332 case VISU_Actor::eLines:
1333 myPreHighlightActor->SetQuadraticArcMode(false);
1334 myHighlightActor->SetQuadraticArcMode(false);