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"
33 #include "VISU_PipeLine.hxx"
35 #include "SVTK_Actor.h"
36 #include "SVTK_Event.h"
38 #include "VTKViewer_FramedTextActor.h"
39 #include "VTKViewer_ShrinkFilter.h"
40 #include "VTKViewer_GeometryFilter.h"
42 #include "SALOME_InteractiveObject.hxx"
44 #include "SUIT_Session.h"
45 #include "SUIT_ResourceMgr.h"
51 #include <vtkProperty.h>
52 #include <vtkSmartPointer.h>
53 #include <vtkTextMapper.h>
54 #include <vtkTextActor.h>
55 #include <vtkProperty2D.h>
56 #include <vtkRenderer.h>
57 #include <vtkCellPicker.h>
59 #include <vtkPointPicker.h>
60 #include <vtkPoints.h>
61 #include <vtkInteractorStyle.h>
62 #include <vtkDataSet.h>
63 #include <vtkPolyData.h>
64 #include <vtkUnstructuredGrid.h>
65 #include <vtkPassThroughFilter.h>
66 #include <vtkFeatureEdges.h>
67 #include <vtkActor2D.h>
68 #include <vtkMaskPoints.h>
69 #include <vtkLabeledDataMapper.h>
70 #include <vtkSelectVisiblePoints.h>
71 #include <vtkTextProperty.h>
72 #include <vtkProperty2D.h>
74 #include <vtkShrinkFilter.h>
75 #include <vtkShrinkPolyData.h>
77 #include <vtkGeometryFilter.h>
78 #include <vtkObjectFactory.h>
80 #include <vtkCallbackCommand.h>
81 #include <vtkCamera.h>
82 #include <vtkRenderWindowInteractor.h>
84 #include <boost/bind.hpp>
86 #include "utilities.h"
88 #include "VISU_PipeLineUtils.hxx"
92 static int MYVTKDEBUG = 0;
95 static int MYDEBUG = 0;
97 static int MYDEBUG = 0;
100 //#define ENABLE_ANNOTATION
102 //----------------------------------------------------------------------------
103 //vtkStandardNewMacro(VISU_Actor);
105 //----------------------------------------------------------------------------
108 myEventCallbackCommand(vtkCallbackCommand::New()),
110 myIsVTKMapping(false),
113 myIsShrinkable(false),
114 myShrinkFilter(VTKViewer_ShrinkFilter::New()),
115 myAnnotationMapper(vtkTextMapper::New()),
116 #if (VTK_XVERSION < 0x050100)
117 myAnnotationActor(vtkTextActor::New()),
119 myAnnotationActor(vtkActor2D::New()),
121 myTextActor(VTKViewer_FramedTextActor::New()),
122 myIsFeatureEdgesAllowed(false),
123 myIsFeatureEdgesEnabled(false),
124 myFeatureEdges(vtkFeatureEdges::New()),
125 myLastSelectionMode(ActorSelection),
126 myIsSubElementsHighlighted(false)
128 if(MYDEBUG) MESSAGE("VISU_Actor::VISU_Actor - this = "<<this);
130 myShrinkFilter->Delete();
132 myStoreMapping = true;
134 myShrinkFilter->SetStoreMapping(true);
136 myAnnotationMapper->Delete();
137 myAnnotationActor->SetMapper(myAnnotationMapper.GetPointer());
139 myAnnotationActor->Delete();
140 myAnnotationActor->SetVisibility(0);
142 myTextActor->Delete();
143 myTextActor->SetVisibility(false);
144 myTextActor->SetPickable(false);
146 myFeatureEdges->Delete();
148 myEventCallbackCommand->Delete();
149 myEventCallbackCommand->SetClientData(this);
150 myEventCallbackCommand->SetCallback(VISU_Actor::ProcessEvents);
152 if( VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get() )
153 aPickingSettings->AddObserver(VISU::UpdatePickingSettingsEvent,
154 myEventCallbackCommand.GetPointer(),
157 //Definition of values labeling pipeline
159 myValLblDataSet = vtkUnstructuredGrid::New();
161 myValCellCenters = vtkCellCenters::New();
162 myValCellCenters->SetInput(myValLblDataSet);
164 myValMaskPoints = vtkMaskPoints::New();
165 myValMaskPoints->SetInput(myValCellCenters->GetOutput());
166 myValMaskPoints->SetOnRatio(1);
168 myValSelectVisiblePoints = vtkSelectVisiblePoints::New();
169 myValSelectVisiblePoints->SetInput(myValMaskPoints->GetOutput());
170 myValSelectVisiblePoints->SelectInvisibleOff();
171 myValSelectVisiblePoints->SetTolerance(0.1);
173 char aFormat[16] = "%g";
174 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
176 int aFloatingPrec = aResourceMgr->integerValue("VISU", "floating_point_precision", 6);
177 sprintf(aFormat, "%%.%dg", aFloatingPrec);
178 //cout << "$$$ aFormat = " << aFormat << endl;
181 myValLabeledDataMapper = vtkLabeledDataMapper::New();
182 myValLabeledDataMapper->SetInput(myValSelectVisiblePoints->GetOutput());
183 //myValLabeledDataMapper->SetLabelFormat("%g");
184 //myValLabeledDataMapper->SetLabelFormat("%.20g");
185 myValLabeledDataMapper->SetLabelFormat(aFormat);
186 myValLabeledDataMapper->SetLabelModeToLabelScalars();
188 vtkTextProperty* aClsTextProp = vtkTextProperty::New();
189 aClsTextProp->SetFontFamilyToTimes();
190 static int aCellsFontSize = 12;
191 aClsTextProp->SetFontSize(aCellsFontSize);
192 aClsTextProp->SetBold(1);
193 aClsTextProp->SetItalic(0);
194 aClsTextProp->SetShadow(0);
195 myValLabeledDataMapper->SetLabelTextProperty(aClsTextProp);
196 aClsTextProp->Delete();
198 myIsValLabeled = false;
200 myValLabels = vtkActor2D::New();
201 myValLabels->SetMapper(myValLabeledDataMapper);
202 myValLabels->GetProperty()->SetColor(0,1,0);
203 myValLabels->SetVisibility( myIsValLabeled );
206 //----------------------------------------------------------------------------
209 ::DeepCopy(VISU_Actor *theActor)
211 highlight(theActor->isHighlighted());
212 SetRepresentation(theActor->GetRepresentation());
213 SetShrinkable(theActor->IsShrunkable());
214 SetShrinkFactor(theActor->GetShrinkFactor());
215 if(theActor->IsShrunk())
220 SetFeatureEdgesAllowed(theActor->IsFeatureEdgesAllowed());
221 SetFeatureEdgesEnabled(theActor->IsFeatureEdgesEnabled());
222 SetFeatureEdgesAngle(theActor->GetFeatureEdgesAngle());
223 bool aFeatureEdges = false, aBoundaryEdges = false, aManifoldEdges = false, aNonManifoldEdges = false;
224 theActor->GetFeatureEdgesFlags( aFeatureEdges, aBoundaryEdges, aManifoldEdges, aNonManifoldEdges );
225 SetFeatureEdgesFlags( aFeatureEdges, aBoundaryEdges, aManifoldEdges, aNonManifoldEdges );
226 SetFeatureEdgesColoring(theActor->GetFeatureEdgesColoring());
228 SetOpacity(theActor->GetOpacity());
229 SetLineWidth(theActor->GetLineWidth());
230 SetPosition(theActor->GetPosition());
234 //----------------------------------------------------------------------------
237 ::ShallowCopyPL(VISU_PipeLine* thePipeLine)
239 myPipeLine->ShallowCopy(thePipeLine, true);
240 GetMapper()->Update();
243 //----------------------------------------------------------------------------
247 // Deleting of values labeling pipeline
248 myValLblDataSet->Delete();
249 myValLabeledDataMapper->RemoveAllInputs();
250 myValLabeledDataMapper->Delete();
251 myValSelectVisiblePoints->Delete();
252 myValMaskPoints->Delete();
253 myValCellCenters->Delete();
254 myValLabels->Delete();
256 if(MYDEBUG) MESSAGE("~VISU_Actor() - this = "<<this);
257 Superclass::SetProperty(NULL);
258 SetDebug(MYVTKDEBUG);
261 //----------------------------------------------------------------------------
264 ::setIO(const Handle(SALOME_InteractiveObject)& theIO)
266 Superclass::setIO(theIO);
267 myName = theIO->getName();
270 //----------------------------------------------------------------------------
273 ::SetPrs3d(VISU::Prs3d_i* thePrs3d)
285 //----------------------------------------------------------------------------
288 ::SetPipeLine(VISU_PipeLine* thePipeLine)
290 myPipeLine = thePipeLine;
292 if(vtkMapper *aMapper = myPipeLine->GetMapper()){
293 if(vtkDataSet *aDataSet = aMapper->GetInput()){
294 SetShrinkable(thePipeLine->IsShrinkable());
295 SetFeatureEdgesAllowed(thePipeLine->IsFeatureEdgesAllowed());
296 SetMapperInput(aDataSet);
307 return myPipeLine.GetPointer();
314 return GetPipeLine();
318 //----------------------------------------------------------------------------
321 ::SetRepresentation(int theMode)
323 Superclass::SetRepresentation(theMode);
324 if(myRepresentation == VTK_POINTS)
328 SetFeatureEdgesEnabled( theMode == SVTK::Representation::FeatureEdges );
332 //----------------------------------------------------------------------------
339 if(vtkDataSet* aDataSet = myPassFilter[0]->GetOutput()){
340 myShrinkFilter->SetInput(aDataSet);
341 myPassFilter[1]->SetInput(myShrinkFilter->GetOutput());
352 if(vtkDataSet* aDataSet = myPassFilter[0]->GetOutput()){
353 myPassFilter[1]->SetInput(aDataSet);
354 myPassFilter[1]->Modified();
369 ::SetShrinkable(bool theIsShrinkable)
371 myIsShrinkable = theIsShrinkable;
378 return myIsShrinkable;
383 ::SetShrinkFactor(vtkFloatingPointType theValue)
385 myShrinkFilter->SetShrinkFactor(theValue);
393 return myShrinkFilter->GetShrinkFactor();
397 //----------------------------------------------------------------------------
400 ::IsFeatureEdgesAllowed()
402 return myIsFeatureEdgesAllowed;
407 ::SetFeatureEdgesAllowed(bool theIsFeatureEdgesAllowed)
409 myIsFeatureEdgesAllowed = theIsFeatureEdgesAllowed;
414 ::IsFeatureEdgesEnabled()
416 return myIsFeatureEdgesEnabled;
421 ::SetFeatureEdgesEnabled(bool theIsFeatureEdgesEnabled)
423 if ( !myIsFeatureEdgesAllowed || myIsFeatureEdgesEnabled == theIsFeatureEdgesEnabled )
426 if ( vtkPolyData* aPolyData = myPassFilter[ 2 ]->GetPolyDataOutput() )
428 if( theIsFeatureEdgesEnabled )
430 myFeatureEdges->SetInput( aPolyData );
431 myPassFilter[ 3 ]->SetInput( myFeatureEdges->GetOutput() );
432 myIsFeatureEdgesEnabled = true;
436 myPassFilter[3]->SetInput( aPolyData );
437 myPassFilter[3]->Modified();
438 myIsFeatureEdgesEnabled = false;
441 myIsFeatureEdgesEnabled = theIsFeatureEdgesEnabled;
447 ::GetFeatureEdgesAngle()
449 return myFeatureEdges->GetFeatureAngle();
454 ::SetFeatureEdgesAngle(vtkFloatingPointType theValue)
456 myFeatureEdges->SetFeatureAngle(theValue);
462 ::GetFeatureEdgesFlags(bool& theIsFeatureEdges,
463 bool& theIsBoundaryEdges,
464 bool& theIsManifoldEdges,
465 bool& theIsNonManifoldEdges)
467 theIsFeatureEdges = myFeatureEdges->GetFeatureEdges();
468 theIsBoundaryEdges = myFeatureEdges->GetBoundaryEdges();
469 theIsManifoldEdges = myFeatureEdges->GetManifoldEdges();
470 theIsNonManifoldEdges = myFeatureEdges->GetNonManifoldEdges();
475 ::SetFeatureEdgesFlags(bool theIsFeatureEdges,
476 bool theIsBoundaryEdges,
477 bool theIsManifoldEdges,
478 bool theIsNonManifoldEdges)
480 myFeatureEdges->SetFeatureEdges(theIsFeatureEdges);
481 myFeatureEdges->SetBoundaryEdges(theIsBoundaryEdges);
482 myFeatureEdges->SetManifoldEdges(theIsManifoldEdges);
483 myFeatureEdges->SetNonManifoldEdges(theIsNonManifoldEdges);
489 ::GetFeatureEdgesColoring()
491 return myFeatureEdges->GetColoring();
496 ::SetFeatureEdgesColoring(bool theIsColoring)
498 myFeatureEdges->SetColoring(theIsColoring);
502 //----------------------------------------------------------------------------
505 ::SetOpacity(vtkFloatingPointType theValue)
507 GetProperty()->SetOpacity(theValue);
514 return GetProperty()->GetOpacity();
519 ::SetLineWidth(vtkFloatingPointType theLineWidth)
521 GetProperty()->SetLineWidth(theLineWidth);
528 return GetProperty()->GetLineWidth();
531 //==================================================================
532 // function: AddToRender
534 //==================================================================
537 ::AddToRender(vtkRenderer* theRenderer)
539 Superclass::AddToRender(theRenderer);
540 theRenderer->AddActor(myAnnotationActor.GetPointer());
541 theRenderer->AddActor(myTextActor.GetPointer());
543 myValSelectVisiblePoints->SetRenderer( theRenderer );
544 theRenderer->AddActor2D( myValLabels );
548 //==================================================================
549 // function: RemoveFromRender
551 //==================================================================
554 ::RemoveFromRender(vtkRenderer* theRenderer)
556 theRenderer->RemoveActor(myAnnotationActor.GetPointer());
557 theRenderer->RemoveActor(myTextActor.GetPointer());
558 theRenderer->RemoveActor(myValLabels);
559 Superclass::RemoveFromRender(theRenderer);
560 myDestroySignal(this);
563 //----------------------------------------------------------------------------
566 ::SetVisibility(int theMode)
568 Superclass::SetVisibility( theMode );
569 myValLabels->SetVisibility( myIsValLabeled && theMode );
571 // Moved from VISU_GaussPtsAct::SetVisibility() (due to IPAL21159)
572 Highlight(isHighlighted());
574 //----------------------------------------------------------------------------
575 //! Gets know whether the actor should be displayed or not
578 ::ShouldBeDisplayed()
580 return GetFactory()->GetActiveState();
582 //----------------------------------------------------------------------------
585 ::SetVTKMapping(bool theIsVTKMapping)
587 myIsVTKMapping = theIsVTKMapping;
592 ::IsVTKMapping() const
594 return myIsVTKMapping;
597 //----------------------------------------------------------------------------
603 return Superclass::GetInput();
605 return GetCurrentPL()->GetOutput();
608 //----------------------------------------------------------------------------
613 static vtkFloatingPointType ERR_SIZE_CALC = 1.00;
614 vtkDataSet* aDataSet = GetMapper()->GetInput();
615 unsigned long int aSize = size_t(aDataSet->GetActualMemorySize() * 1024 * ERR_SIZE_CALC);
617 aDataSet = myGeomFilter->GetOutput();
618 aSize += aDataSet->GetActualMemorySize() * 1024;
621 aDataSet = myShrinkFilter->GetOutput();
622 aSize += aDataSet->GetActualMemorySize() * 1024;
625 if(IsFeatureEdgesEnabled()){
626 vtkPolyData* aPolyData = myFeatureEdges->GetOutput();
627 aSize += aPolyData->GetActualMemorySize() * 1024;
633 //----------------------------------------------------------------------------
636 ::GetNodeObjId(vtkIdType theID)
639 return Superclass::GetNodeObjId(theID);
641 return VISU::GetNodeObjID(GetMapper()->GetInput(), theID);
646 ::GetNodeVTKID(vtkIdType theID)
651 return VISU::GetNodeVTKID(GetMapper()->GetInput(), theID);
654 vtkFloatingPointType*
656 ::GetNodeCoord(vtkIdType theObjID)
659 return Superclass::GetNodeCoord(theObjID);
661 return VISU::GetNodeCoord(GetInput(), theObjID);
665 //----------------------------------------------------------------------------
668 ::GetElemObjId(vtkIdType theID)
671 return Superclass::GetElemObjId(theID);
673 return VISU::GetElemObjID(GetMapper()->GetInput(), theID);
678 ::GetElemVTKID(vtkIdType theID)
683 return VISU::GetElemVTKID(GetMapper()->GetInput(), theID);
688 ::GetElemCell(vtkIdType theObjID)
691 return Superclass::GetElemCell(theObjID);
693 return VISU::GetElemCell(GetInput(), theObjID);
697 //----------------------------------------------------------------------------
700 ::isSubElementsHighlighted()
702 return myIsSubElementsHighlighted;
706 //----------------------------------------------------------------------------
709 ChangeZoom(vtkFloatingPointType theZoomFactor,
710 vtkRenderer* theRenderer,
711 vtkIdType theInitialHasIndex,
712 vtkIdType theCurrentHasIndex)
714 //printf( "VISU_Actor::ChangeZoom( %d, %d )", theInitialHasIndex, theCurrentHasIndex );
715 if(theInitialHasIndex + theCurrentHasIndex == 1){
716 vtkCamera *aCamera = theRenderer->GetActiveCamera();
718 double aScale = aCamera->GetParallelScale();
719 if ( !theInitialHasIndex && theCurrentHasIndex ) {
720 //printf( " : +%f", theZoomFactor );
721 aCamera->SetParallelScale( aScale / theZoomFactor );
724 //printf( " : -%f", theZoomFactor );
725 aCamera->SetParallelScale( aScale * theZoomFactor );
732 Updates visibility of the highlight devices
736 ::highlight(bool theIsHighlight)
738 VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
740 bool aShowTextActor = aPickingSettings->GetInfoWindowEnabled();
741 if( theIsHighlight && mySelectionMode != myLastSelectionMode )
743 if( mySelectionMode == ActorSelection )
746 aShowTextActor = false;
747 myLastSelectionMode = mySelectionMode;
750 myTextActor->SetVisibility( GetVisibility() && theIsHighlight && aShowTextActor );
752 bool anInitialHasIndex = isHighlighted();
753 bool aCurrentHasIndex = theIsHighlight;
755 if( !theIsHighlight && mySelectionMode == ActorSelection && isSubElementsHighlighted() )
757 myIsSubElementsHighlighted = false;
760 if( GetVisibility() && aPickingSettings->GetCameraMovementEnabled() )
762 vtkFloatingPointType aZoomFactor = aPickingSettings->GetZoomFactor();
763 ChangeZoom(aZoomFactor,
770 Superclass::highlight(theIsHighlight);
774 To process prehighlight (called from SVTK_InteractorStyle)
778 ::PreHighlight(vtkInteractorStyle* theInteractorStyle,
779 SVTK_SelectionEvent* theSelectionEvent,
782 bool aRet = Superclass::PreHighlight(theInteractorStyle,
785 #ifndef ENABLE_ANNOTATION
789 myAnnotationActor->SetVisibility(0);
791 switch(mySelectionMode){
793 vtkRenderer* aRenderer = theInteractorStyle->GetCurrentRenderer();
794 myCellPicker->Pick(theSelectionEvent->myX,
795 theSelectionEvent->myY,
799 if(myCellPicker->GetActor() != this)
802 vtkIdType aVTKId = myCellPicker->GetCellId();
803 if(aVTKId >= 0 && mySelector->IsValid(this,aVTKId,true) && hasIO()){
804 vtkIdType anObjId = GetElemObjId(aVTKId);
805 if(vtkCell* aCell = GetElemCell(anObjId)){
806 vtkPoints* aPts = aCell->GetPoints();
807 if(int aNbPts = aCell->GetNumberOfPoints()){
808 vtkFloatingPointType aCoord[3] = {0.0, 0.0, 0.0};
809 for(int i = 0; i < aNbPts; i++){
810 vtkFloatingPointType *aPntCoord = aPts->GetPoint(i);
811 aCoord[0] += aPntCoord[0];
812 aCoord[1] += aPntCoord[1];
813 aCoord[2] += aPntCoord[2];
815 // Display coordinates
816 vtkFloatingPointType aWorldCoord[4] = {aCoord[0]/aNbPts, aCoord[1]/aNbPts, aCoord[2]/aNbPts, 1.0};
817 aRenderer->SetWorldPoint(aWorldCoord);
818 aRenderer->WorldToDisplay();
819 vtkFloatingPointType aSelectionPoint[3];
820 aRenderer->GetDisplayPoint(aSelectionPoint);
821 myAnnotationActor->SetPosition(aSelectionPoint);
823 // To prepare the annotation text
824 std::ostringstream aStr;
825 aStr<<"Cell ID: "<< anObjId;
826 std::string aString = aStr.str();
827 myAnnotationMapper->SetInput(aString.c_str());
829 myAnnotationActor->SetVisibility(1);
837 vtkRenderer* aRenderer = theInteractorStyle->GetCurrentRenderer();
838 myPointPicker->Pick(theSelectionEvent->myX,
839 theSelectionEvent->myY,
843 if(myPointPicker->GetActor() != this)
846 vtkIdType aVtkId = myPointPicker->GetPointId();
847 if(aVtkId >= 0 && mySelector->IsValid(this,aVtkId,true) && hasIO()){
848 vtkIdType anObjId = GetNodeObjId( aVtkId );
849 if(vtkFloatingPointType* aCoord = GetNodeCoord(anObjId)){
850 // Display coordinates
851 vtkFloatingPointType aWorldCoord[4] = {aCoord[0], aCoord[1], aCoord[2], 1.0};
852 aRenderer->SetWorldPoint(aWorldCoord);
853 aRenderer->WorldToDisplay();
854 vtkFloatingPointType aSelectionPoint[3];
855 aRenderer->GetDisplayPoint(aSelectionPoint);
856 myAnnotationActor->SetPosition(aSelectionPoint);
858 // To prepare the annotation text
859 std::ostringstream aStr;
860 aStr<<"Node ID: "<< anObjId;
861 std::string aString = aStr.str();
862 myAnnotationMapper->SetInput(aString.c_str());
864 myAnnotationActor->SetVisibility(1);
870 case EdgeOfCellSelection:
880 void VISU_Actor::RemoveAllClippingPlanes()
884 vtkIdType VISU_Actor::GetNumberOfClippingPlanes()
889 bool VISU_Actor::AddClippingPlane(vtkPlane* thePlane)
894 vtkPlane* VISU_Actor::GetClippingPlane(vtkIdType theID)
899 vtkImplicitFunctionCollection* VISU_Actor::GetClippingPlanes()
904 //----------------------------------------------------------------------------
905 template<class TData> std::string getScalar(TData* theData, int theId)
907 std::ostringstream aStr;
908 if (vtkDataArray *aScalar = theData->GetScalars()){
909 vtkFloatingPointType aVal = aScalar->GetTuple1(theId);
910 aStr << "\nScalar: " << aVal;
915 template<class TData> std::string getVector(TData* theData, int theId)
917 std::ostringstream aStr;
918 if (vtkDataArray *aVector = theData->GetVectors()) {
919 vtkFloatingPointType *aVal = aVector->GetTuple3(theId);
920 aStr << "\nVector: " << "{" << aVal[0] << "; " << aVal[1] << "; " << aVal[2] << "}";
926 To process highlight (called from SVTK_InteractorStyle)
930 ::Highlight(vtkInteractorStyle* theInteractorStyle,
931 SVTK_SelectionEvent* theSelectionEvent,
934 return Superclass::Highlight(theInteractorStyle,
939 //-------------------------------------------------------------------------
942 ::Highlight(bool theIsHighlight)
944 Superclass::Highlight(theIsHighlight);
946 VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
948 bool anInitialHasIndex = isSubElementsHighlighted() && mySelectionMode != ActorSelection;
950 TColStd_IndexedMapOfInteger aMapIndex;
951 mySelector->GetIndex( getIO(), aMapIndex );
952 bool aCurrentHasIndex = aMapIndex.Extent() == 1;
954 myIsSubElementsHighlighted = aCurrentHasIndex;
957 vtkFloatingPointType aFlyToCoord[3] = { 0.0, 0.0, 0.0 };
958 vtkRenderer *aRenderer = GetRenderer();
962 vtkDataSet* aDataSet = GetMapper()->GetInput();
963 switch(mySelectionMode)
972 if( !aCurrentHasIndex )
974 myTextActor->SetVisibility(false);
978 int anObjId = aMapIndex(1);
979 vtkCellData* aCellData = aDataSet->GetCellData();
980 if(vtkCell* aCell = GetElemCell(anObjId)){
981 vtkPoints* aPts = aCell->GetPoints();
982 if(int aNbPts = aCell->GetNumberOfPoints()){
983 vtkFloatingPointType aCoord[3] = {0.0, 0.0, 0.0};
984 for(int i = 0; i < aNbPts; i++){
985 vtkFloatingPointType *aPntCoord = aPts->GetPoint(i);
986 aCoord[0] += aPntCoord[0];
987 aCoord[1] += aPntCoord[1];
988 aCoord[2] += aPntCoord[2];
992 aFlyToCoord[0] = aCoord[0] / aNbPts;
993 aFlyToCoord[1] = aCoord[1] / aNbPts;
994 aFlyToCoord[2] = aCoord[2] / aNbPts;
996 vtkFloatingPointType aWorldCoord[4] = {aCoord[0]/aNbPts, aCoord[1]/aNbPts, aCoord[2]/aNbPts, 1.0};
997 aRenderer->SetWorldPoint(aWorldCoord);
998 aRenderer->WorldToDisplay();
999 vtkFloatingPointType aSelectionPoint[3];
1000 aRenderer->GetDisplayPoint(aSelectionPoint);
1001 myTextActor->SetPosition(aSelectionPoint);
1002 myTextActor->SetModePosition(aPickingSettings->GetInfoWindowPosition());
1003 myTextActor->SetTransparency(aPickingSettings->GetInfoWindowTransparency());
1004 myTextActor->SetWorldPoint(aWorldCoord);
1006 std::ostringstream aStr;
1007 aStr << "Cell ID: " << anObjId;
1009 vtkCell* aCell = GetElemCell(anObjId);
1010 int aVTKID = GetElemVTKID(anObjId);
1012 int aNbOfPoints = aCell->GetNumberOfPoints();
1013 if ( aNbOfPoints > 0 ) {
1014 aStr << getScalar(aCellData, aVTKID);
1015 aStr << getVector(aCellData, aVTKID);
1019 std::string aString = aStr.str();
1020 myTextActor->SetText(aString.c_str());
1027 if( !aCurrentHasIndex )
1029 myTextActor->SetVisibility(false);
1033 int anObjId = aMapIndex(1);
1034 vtkPointData* aPntData = aDataSet->GetPointData();
1035 if(vtkFloatingPointType* aCoord = GetNodeCoord(anObjId)){
1037 aFlyToCoord[0] = aCoord[0];
1038 aFlyToCoord[1] = aCoord[1];
1039 aFlyToCoord[2] = aCoord[2];
1041 vtkFloatingPointType aWorldCoord[4] = {aCoord[0], aCoord[1], aCoord[2], 1.0};
1042 aRenderer->SetWorldPoint(aWorldCoord);
1043 aRenderer->WorldToDisplay();
1044 vtkFloatingPointType aSelectionPoint[3];
1045 aRenderer->GetDisplayPoint(aSelectionPoint);
1046 myTextActor->SetPosition(aSelectionPoint);
1047 myTextActor->SetModePosition(aPickingSettings->GetInfoWindowPosition());
1048 myTextActor->SetTransparency(aPickingSettings->GetInfoWindowTransparency());
1049 myTextActor->SetWorldPoint(aWorldCoord);
1051 std::ostringstream aStr;
1052 aStr << "Point ID: " << anObjId;
1054 int aVTKID = GetNodeVTKID(anObjId);
1056 aStr << getScalar(aPntData, aVTKID);
1057 aStr << getVector(aPntData, aVTKID);
1060 const VISU::PIDMapper& aMapper = GetPipeLine()->GetIDMapper();
1061 //VISU::TIdTypeVector aVec = aMapper->GetIndexesOfNode(anObjId);
1062 VISU::TStructuredId aVec = aMapper->GetIndexesOfNode(anObjId);
1064 aStr << "\nCoordinates: " << "[";
1066 //if( aVec.size() > 0 )
1068 aStr << " (" << aVec[0] << ")";
1072 //if( aVec.size() > 1 )
1074 aStr << " (" << aVec[1] << ")";
1078 //if( aVec.size() > 2 )
1080 aStr << " (" << aVec[2] << ")";
1083 std::string aString = aStr.str();
1084 myTextActor->SetText(aString.c_str());
1088 case EdgeOfCellSelection:
1096 if( GetVisibility() && aPickingSettings->GetCameraMovementEnabled() )
1098 vtkFloatingPointType aZoomFactor = aPickingSettings->GetZoomFactor();
1099 ChangeZoom(aZoomFactor,
1106 if( GetVisibility() && aPickingSettings->GetCameraMovementEnabled() && aFlyTo )
1108 vtkRenderWindowInteractor* anInteractor = myInteractor;
1109 vtkFloatingPointType aDollyWas = anInteractor->GetDolly();
1110 int aNumberOfFlyFramesWas = anInteractor->GetNumberOfFlyFrames();
1112 double aPosition[3];
1113 GetPosition( aPosition );
1114 for( int i = 0; i < 3; i++ )
1115 aFlyToCoord[i] += aPosition[i];
1117 anInteractor->SetDolly(0.0);
1118 anInteractor->SetNumberOfFlyFrames(aPickingSettings->GetStepNumber());
1119 anInteractor->FlyTo(aRenderer, aFlyToCoord);
1120 aRenderer->ResetCameraClippingRange();
1121 anInteractor->SetDolly(aDollyWas);
1122 anInteractor->SetNumberOfFlyFrames(aNumberOfFlyFramesWas);
1123 anInteractor->InvokeEvent(SVTK::ChangeRotationPoint, aFlyToCoord);
1127 //-------------------------------------------------------------------------
1132 VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
1134 vtkFloatingPointType aCoord[6];
1137 vtkFloatingPointType aWorldCoord[4] = { ( aCoord[0] + aCoord[1] ) / 2,
1138 ( aCoord[2] + aCoord[3] ) / 2,
1139 ( aCoord[4] + aCoord[5] ) / 2, 1.0};
1140 vtkRenderer* aRenderer = GetRenderer();
1141 aRenderer->SetWorldPoint(aWorldCoord);
1142 aRenderer->WorldToDisplay();
1143 vtkFloatingPointType aSelectionPoint[3];
1144 aRenderer->GetDisplayPoint(aSelectionPoint);
1145 myTextActor->SetPosition(aSelectionPoint);
1146 myTextActor->SetModePosition(aPickingSettings->GetInfoWindowPosition());
1147 myTextActor->SetTransparency(aPickingSettings->GetInfoWindowTransparency());
1148 myTextActor->SetWorldPoint(aWorldCoord);
1150 std::ostringstream aStr;
1152 if( const char* aName = getName() )
1153 aStr << aName << "\n";
1155 aStr << "Position: " << "[" << aCoord[0] << "; " << aCoord[2] << "; " << aCoord[4] << "]";
1156 aStr << "\nSize: " << "[" <<
1157 fabs(aCoord[1]-aCoord[0]) << "; " <<
1158 fabs(aCoord[3]-aCoord[2]) << "; " <<
1159 fabs(aCoord[5]-aCoord[4]) << "]";
1161 std::string aString = aStr.str();
1162 myTextActor->SetText(aString.c_str());
1165 //-------------------------------------------------------------------------
1168 ::ProcessEvents(vtkObject* vtkNotUsed(theObject),
1169 unsigned long theEvent,
1170 void* theClientData,
1171 void* vtkNotUsed(theCallData))
1173 if(vtkObject* anObject = reinterpret_cast<vtkObject*>(theClientData))
1174 if(VISU_Actor* self = dynamic_cast<VISU_Actor*>(anObject)) {
1175 if(theEvent == VISU::UpdatePickingSettingsEvent)
1176 self->UpdatePickingSettings();
1180 //----------------------------------------------------------------------------
1183 ::UpdatePickingSettings()
1185 //printf( "VISU_Actor::UpdatePickingSettings()\n" );
1186 VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
1187 if( !aPickingSettings )
1190 myTextActor->SetModePosition(aPickingSettings->GetInfoWindowPosition());
1191 myTextActor->SetTransparency(aPickingSettings->GetInfoWindowTransparency());
1193 Highlight(isHighlighted());
1198 // ---------------------------------------------------------------
1200 void VISU_Actor::SetValuesLabeled( const bool theIsValLabeled )
1202 vtkDataSet* aGrid = GetValLabelsInput();
1206 bool isOnPnt = VISU::IsDataOnPoints( aGrid );
1207 bool isOnCell = VISU::IsDataOnCells( aGrid );
1208 if ( !isOnPnt && !isOnCell )
1210 // try to specify location of scalars "manually"
1211 vtkCellData* aCData = aGrid->GetCellData();
1214 vtkDataArray* anArr = aCData->GetScalars();
1215 if ( anArr && anArr->GetNumberOfTuples() )
1221 vtkPointData* aPData = aGrid->GetPointData();
1224 vtkDataArray* anArr = aPData->GetScalars();
1225 if ( anArr && anArr->GetNumberOfTuples() )
1230 if ( !isOnPnt && !isOnCell )
1232 myValLabels->SetVisibility( false );
1237 myIsValLabeled = theIsValLabeled;
1239 if ( myIsValLabeled )
1241 vtkDataSet* aDataSet = aGrid;
1245 myValCellCenters->SetInput( aDataSet );
1246 myValMaskPoints->SetInput( myValCellCenters->GetOutput() );
1249 myValMaskPoints->SetInput( aDataSet );
1251 myValLabels->SetVisibility( GetVisibility() );
1254 myValLabels->SetVisibility( false );
1259 //----------------------------------------------------------------------------
1261 bool VISU_Actor::GetValuesLabeled() const
1263 return myIsValLabeled;
1266 //----------------------------------------------------------------------------
1268 vtkTextProperty* VISU_Actor::GetsValLabelsProps() const
1270 return myValLabeledDataMapper->GetLabelTextProperty();
1273 //----------------------------------------------------------------------------
1275 vtkDataSet* VISU_Actor::GetValLabelsInput()
1277 vtkDataSet* aDataSet = 0;
1278 VISU_PipeLine* aPL = GetPipeLine();
1280 aDataSet = aPL->GetOutput();
1282 aDataSet = GetInput();
1287 VISU_Actor::EQuadratic2DRepresentation
1288 VISU_Actor::GetQuadratic2DRepresentation() const
1290 if(Superclass::GetQuadraticArcMode()){
1291 return VISU_Actor::eArcs;
1294 return VISU_Actor::eLines;
1297 void VISU_Actor::SetQuadratic2DRepresentation( EQuadratic2DRepresentation theMode )
1300 case VISU_Actor::eArcs:
1301 myPreHighlightActor->SetQuadraticArcMode(true);
1302 myHighlightActor->SetQuadraticArcMode(true);
1304 case VISU_Actor::eLines:
1305 myPreHighlightActor->SetQuadraticArcMode(false);
1306 myHighlightActor->SetQuadraticArcMode(false);