1 // SMESH OBJECT : interactive object for SMESH visualization
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESH_Actor.cxx
25 // Author : Nicolas REJNERI
30 #include "SMESH_ActorDef.h"
31 #include "SMESH_ActorUtils.h"
32 #include "SMESH_DeviceActor.h"
33 #include "SMESH_ControlsDef.hxx"
34 #include <VTKViewer_ExtractUnstructuredGrid.h>
36 #include "SUIT_Session.h"
37 #include "SUIT_ResourceMgr.h"
39 #include <qstringlist.h>
41 #include <vtkTimeStamp.h>
42 #include <vtkObjectFactory.h>
43 #include <vtkShrinkPolyData.h>
44 #include <vtkMergeFilter.h>
46 #include <vtkMatrix4x4.h>
47 #include <vtkUnstructuredGrid.h>
48 #include <vtkPointData.h>
49 #include <vtkCellData.h>
51 #include <vtkMapper.h>
52 #include <vtkRenderer.h>
55 #include <vtkIdList.h>
56 #include <vtkIntArray.h>
58 #include <vtkActor2D.h>
59 #include <vtkProperty2D.h>
60 #include <vtkPolyData.h>
61 #include <vtkMaskPoints.h>
62 #include <vtkCellCenters.h>
63 #include <vtkTextProperty.h>
64 #include <vtkLabeledDataMapper.h>
65 #include <vtkSelectVisiblePoints.h>
67 #include <vtkScalarBarActor.h>
68 #include <vtkLookupTable.h>
72 #include <vtkImplicitBoolean.h>
73 #include <vtkImplicitFunctionCollection.h>
75 #include "utilities.h"
78 static int MYDEBUG = 1;
80 static int MYDEBUG = 0;
83 static int aLineWidthInc = 2;
84 static int aPointSizeInc = 2;
87 SMESH_ActorDef* SMESH_ActorDef::New(){
88 return new SMESH_ActorDef();
92 SMESH_Actor* SMESH_Actor::New(TVisualObjPtr theVisualObj,
97 SMESH_ActorDef* anActor = SMESH_ActorDef::New();
98 if(!anActor->Init(theVisualObj,theEntry,theName,theIsClear)){
103 anActor->UpdateScalarBar();
108 SMESH_ActorDef::SMESH_ActorDef()
110 if(MYDEBUG) MESSAGE("SMESH_ActorDef - "<<this);
112 myTimeStamp = vtkTimeStamp::New();
114 myIsPointsVisible = false;
116 myIsShrinkable = false;
119 myControlsPrecision = (long)SMESH::GetFloat( "SMESH:controls_precision", -1 );
121 float aPointSize = SMESH::GetFloat("SMESH:node_size",3);
122 float aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
124 vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
125 VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
127 //Definition 2D and 3D divices of the actor
128 //-----------------------------------------
129 float anRGB[3] = {1,1,1};
130 mySurfaceProp = vtkProperty::New();
131 SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
132 mySurfaceProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
134 myBackSurfaceProp = vtkProperty::New();
135 SMESH::GetColor( "SMESH", "backface_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 0, 255 ) );
136 myBackSurfaceProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
138 my2DActor = SMESH_DeviceActor::New();
139 my2DActor->SetUserMatrix(aMatrix);
140 my2DActor->PickableOff();
141 my2DActor->SetProperty(mySurfaceProp);
142 my2DActor->SetBackfaceProperty(myBackSurfaceProp);
143 my2DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
144 aFilter = my2DActor->GetExtractUnstructuredGrid();
145 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
146 aFilter->RegisterCellsWithType(VTK_TRIANGLE);
147 aFilter->RegisterCellsWithType(VTK_POLYGON);
148 aFilter->RegisterCellsWithType(VTK_QUAD);
150 my3DActor = SMESH_DeviceActor::New();
151 my3DActor->SetUserMatrix(aMatrix);
152 my3DActor->PickableOff();
153 my3DActor->SetProperty(mySurfaceProp);
154 my3DActor->SetBackfaceProperty(myBackSurfaceProp);
155 my3DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
156 aFilter = my3DActor->GetExtractUnstructuredGrid();
157 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
158 aFilter->RegisterCellsWithType(VTK_TETRA);
159 aFilter->RegisterCellsWithType(VTK_VOXEL);
160 aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
161 aFilter->RegisterCellsWithType(VTK_WEDGE);
162 aFilter->RegisterCellsWithType(VTK_PYRAMID);
163 aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
165 //Definition 1D divice of the actor
166 //---------------------------------
167 myEdgeProp = vtkProperty::New();
168 myEdgeProp->SetAmbient(1.0);
169 myEdgeProp->SetDiffuse(0.0);
170 myEdgeProp->SetSpecular(0.0);
171 SMESH::GetColor( "SMESH", "outline_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
172 myEdgeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
173 myEdgeProp->SetLineWidth(aLineWidth);
175 my1DActor = SMESH_DeviceActor::New();
176 my1DActor->SetUserMatrix(aMatrix);
177 my1DActor->PickableOff();
178 my1DActor->SetHighlited(true);
179 my1DActor->SetProperty(myEdgeProp);
180 my1DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
181 aFilter = my1DActor->GetExtractUnstructuredGrid();
182 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
183 aFilter->RegisterCellsWithType(VTK_LINE);
185 my1DProp = vtkProperty::New();
186 my1DProp->DeepCopy(myEdgeProp);
187 my1DProp->SetLineWidth(aLineWidth + aLineWidthInc);
188 my1DProp->SetPointSize(aPointSize);
190 my1DExtProp = vtkProperty::New();
191 my1DExtProp->DeepCopy(myEdgeProp);
192 anRGB[0] = 1 - anRGB[0];
193 anRGB[1] = 1 - anRGB[1];
194 anRGB[2] = 1 - anRGB[2];
195 my1DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
196 my1DExtProp->SetLineWidth(aLineWidth + aLineWidthInc);
197 my1DExtProp->SetPointSize(aPointSize + aPointSizeInc);
199 my1DExtActor = SMESH_DeviceActor::New();
200 my1DExtActor->SetUserMatrix(aMatrix);
201 my1DExtActor->PickableOff();
202 my1DExtActor->SetHighlited(true);
203 my1DExtActor->SetVisibility(false);
204 my1DExtActor->SetProperty(my1DExtProp);
205 my1DExtActor->SetRepresentation(SMESH_DeviceActor::eInsideframe);
206 aFilter = my1DExtActor->GetExtractUnstructuredGrid();
207 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
208 aFilter->RegisterCellsWithType(VTK_LINE);
211 //Definition 0D divice of the actor
212 //---------------------------------
213 myNodeProp = vtkProperty::New();
214 SMESH::GetColor( "SMESH", "node_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 0, 0 ) );
215 myNodeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
216 myNodeProp->SetPointSize(aPointSize);
218 myNodeActor = SMESH_DeviceActor::New();
219 myNodeActor->SetUserMatrix(aMatrix);
220 myNodeActor->SetStoreClippingMapping(true);
221 myNodeActor->PickableOff();
222 myNodeActor->SetVisibility(false);
223 myNodeActor->SetProperty(myNodeProp);
224 myNodeActor->SetRepresentation(SMESH_DeviceActor::ePoint);
225 aFilter = myNodeActor->GetExtractUnstructuredGrid();
226 aFilter->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
229 //Definition of Pickable and Highlitable engines
230 //----------------------------------------------
232 myBaseActor = SMESH_DeviceActor::New();
233 myBaseActor->SetUserMatrix(aMatrix);
234 myBaseActor->SetStoreGemetryMapping(true);
235 myBaseActor->GetProperty()->SetOpacity(0.0);
237 myPickableActor = myBaseActor;
239 myHighlightProp = vtkProperty::New();
240 myHighlightProp->SetAmbient(1.0);
241 myHighlightProp->SetDiffuse(0.0);
242 myHighlightProp->SetSpecular(0.0);
243 SMESH::GetColor( "SMESH", "selection_object_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
244 myHighlightProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
245 myHighlightProp->SetPointSize(aPointSize);
246 myHighlightProp->SetRepresentation(1);
248 myPreselectProp = vtkProperty::New();
249 myPreselectProp->SetAmbient(1.0);
250 myPreselectProp->SetDiffuse(0.0);
251 myPreselectProp->SetSpecular(0.0);
252 SMESH::GetColor( "SMESH", "highlight_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 255, 255 ) );
253 myPreselectProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
254 myPreselectProp->SetPointSize(aPointSize);
255 myPreselectProp->SetRepresentation(1);
257 myHighlitableActor = SMESH_DeviceActor::New();
258 myHighlitableActor->SetUserMatrix(aMatrix);
259 myHighlitableActor->PickableOff();
260 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
262 SetShrinkFactor( SMESH::GetFloat( "SMESH", "shrink_coeff", 0.75 ) );
267 myControlMode = eNone;
268 myControlActor = my2DActor;
270 //Definition of myScalarBarActor
271 //------------------------------
272 myLookupTable = vtkLookupTable::New();
273 //Fix for Bug PAL5195 - SMESH764:
274 //Controls - Aspect Ratio: incorrect colors of the best and worst values
275 myLookupTable->SetHueRange(0.667,0.0);
277 myScalarBarActor = vtkScalarBarActor::New();
278 myScalarBarActor->SetVisibility(false);
279 myScalarBarActor->SetLookupTable(myLookupTable);
281 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
285 //Definition of points numbering pipeline
286 //---------------------------------------
287 myPointsNumDataSet = vtkUnstructuredGrid::New();
289 myPtsMaskPoints = vtkMaskPoints::New();
290 myPtsMaskPoints->SetInput(myPointsNumDataSet);
291 myPtsMaskPoints->SetOnRatio(1);
293 myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
294 myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
295 myPtsSelectVisiblePoints->SelectInvisibleOff();
296 myPtsSelectVisiblePoints->SetTolerance(0.1);
298 myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
299 myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
300 myPtsLabeledDataMapper->SetLabelFormat("%g");
301 myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
303 vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
304 aPtsTextProp->SetFontFamilyToTimes();
305 static int aPointsFontSize = 10;
306 aPtsTextProp->SetFontSize(aPointsFontSize);
307 aPtsTextProp->SetBold(1);
308 aPtsTextProp->SetItalic(0);
309 aPtsTextProp->SetShadow(0);
310 myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
311 aPtsTextProp->Delete();
313 myEntityMode = eAllEntity;
315 myIsPointsLabeled = false;
317 myPointLabels = vtkActor2D::New();
318 myPointLabels->SetMapper(myPtsLabeledDataMapper);
319 myPointLabels->GetProperty()->SetColor(1,1,1);
320 myPointLabels->SetVisibility(myIsPointsLabeled);
323 //Definition of cells numbering pipeline
324 //---------------------------------------
325 myCellsNumDataSet = vtkUnstructuredGrid::New();
327 myCellCenters = vtkCellCenters::New();
328 myCellCenters->SetInput(myCellsNumDataSet);
330 myClsMaskPoints = vtkMaskPoints::New();
331 myClsMaskPoints->SetInput(myCellCenters->GetOutput());
332 myClsMaskPoints->SetOnRatio(1);
334 myClsSelectVisiblePoints = vtkSelectVisiblePoints::New();
335 myClsSelectVisiblePoints->SetInput(myClsMaskPoints->GetOutput());
336 myClsSelectVisiblePoints->SelectInvisibleOff();
337 myClsSelectVisiblePoints->SetTolerance(0.1);
339 myClsLabeledDataMapper = vtkLabeledDataMapper::New();
340 myClsLabeledDataMapper->SetInput(myClsSelectVisiblePoints->GetOutput());
341 myClsLabeledDataMapper->SetLabelFormat("%g");
342 myClsLabeledDataMapper->SetLabelModeToLabelScalars();
344 vtkTextProperty* aClsTextProp = vtkTextProperty::New();
345 aClsTextProp->SetFontFamilyToTimes();
346 static int aCellsFontSize = 12;
347 aClsTextProp->SetFontSize(aCellsFontSize);
348 aClsTextProp->SetBold(1);
349 aClsTextProp->SetItalic(0);
350 aClsTextProp->SetShadow(0);
351 myClsLabeledDataMapper->SetLabelTextProperty(aClsTextProp);
352 aClsTextProp->Delete();
354 myIsCellsLabeled = false;
356 myCellsLabels = vtkActor2D::New();
357 myCellsLabels->SetMapper(myClsLabeledDataMapper);
358 myCellsLabels->GetProperty()->SetColor(0,1,0);
359 myCellsLabels->SetVisibility(myIsCellsLabeled);
362 myImplicitBoolean = vtkImplicitBoolean::New();
363 myImplicitBoolean->SetOperationTypeToIntersection();
367 SMESH_ActorDef::~SMESH_ActorDef()
369 if(MYDEBUG) MESSAGE("~SMESH_ActorDef - "<<this);
371 myScalarBarActor->Delete();
372 myLookupTable->Delete();
374 mySurfaceProp->Delete();
375 myBackSurfaceProp->Delete();
377 myEdgeProp->Delete();
378 myHighlightProp->Delete();
379 myPreselectProp->Delete();
381 myNodeProp->Delete();
386 my1DExtProp->Delete();
387 my1DExtActor->Delete();
392 myNodeActor->Delete();
393 myBaseActor->Delete();
395 myHighlitableActor->Delete();
397 //Deleting of pints numbering pipeline
398 //---------------------------------------
399 myPointsNumDataSet->Delete();
401 myPtsLabeledDataMapper->RemoveAllInputs();
402 myPtsLabeledDataMapper->Delete();
404 myPtsSelectVisiblePoints->UnRegisterAllOutputs();
405 myPtsSelectVisiblePoints->Delete();
407 myPtsMaskPoints->UnRegisterAllOutputs();
408 myPtsMaskPoints->Delete();
410 myPointLabels->Delete();
413 //Deleting of cells numbering pipeline
414 //---------------------------------------
415 myCellsNumDataSet->Delete();
417 myClsLabeledDataMapper->RemoveAllInputs();
418 myClsLabeledDataMapper->Delete();
420 myClsSelectVisiblePoints->UnRegisterAllOutputs();
421 myClsSelectVisiblePoints->Delete();
423 myClsMaskPoints->UnRegisterAllOutputs();
424 myClsMaskPoints->Delete();
426 myCellCenters->UnRegisterAllOutputs();
427 myCellCenters->Delete();
429 myCellsLabels->Delete();
431 myImplicitBoolean->Delete();
433 myTimeStamp->Delete();
437 void SMESH_ActorDef::SetPointsLabeled( bool theIsPointsLabeled )
439 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
440 myIsPointsLabeled = theIsPointsLabeled && aGrid->GetNumberOfPoints();
442 if ( myIsPointsLabeled )
444 myPointsNumDataSet->ShallowCopy(aGrid);
445 vtkDataSet *aDataSet = myPointsNumDataSet;
447 int aNbElem = aDataSet->GetNumberOfPoints();
449 vtkIntArray *anArray = vtkIntArray::New();
450 anArray->SetNumberOfValues( aNbElem );
452 for ( int anId = 0; anId < aNbElem; anId++ )
454 int aSMDSId = myVisualObj->GetNodeObjId( anId );
455 anArray->SetValue( anId, aSMDSId );
458 aDataSet->GetPointData()->SetScalars( anArray );
460 myPtsMaskPoints->SetInput( aDataSet );
461 myPointLabels->SetVisibility( GetVisibility() );
465 myPointLabels->SetVisibility( false );
467 SetRepresentation(GetRepresentation());
468 myTimeStamp->Modified();
472 void SMESH_ActorDef::SetCellsLabeled(bool theIsCellsLabeled)
474 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
475 myIsCellsLabeled = theIsCellsLabeled && aGrid->GetNumberOfPoints();
476 if(myIsCellsLabeled){
477 myCellsNumDataSet->ShallowCopy(aGrid);
478 vtkDataSet *aDataSet = myCellsNumDataSet;
479 int aNbElem = aDataSet->GetNumberOfCells();
480 vtkIntArray *anArray = vtkIntArray::New();
481 anArray->SetNumberOfValues(aNbElem);
482 for(int anId = 0; anId < aNbElem; anId++){
483 int aSMDSId = myVisualObj->GetElemObjId(anId);
484 anArray->SetValue(anId,aSMDSId);
486 aDataSet->GetCellData()->SetScalars(anArray);
487 myCellCenters->SetInput(aDataSet);
488 myCellsLabels->SetVisibility(GetVisibility());
490 myCellsLabels->SetVisibility(false);
492 myTimeStamp->Modified();
498 SetControlMode(eControl theMode)
500 SetControlMode(theMode,true);
506 SetControlMode(eControl theMode,
507 bool theCheckEntityMode)
509 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
513 myControlMode = eNone;
514 theCheckEntityMode &= mgr->booleanValue( "SMESH", "display_entity", false );
516 my1DActor->GetMapper()->SetScalarVisibility(false);
517 my2DActor->GetMapper()->SetScalarVisibility(false);
518 my3DActor->GetMapper()->SetScalarVisibility(false);
519 myScalarBarActor->SetVisibility(false);
521 bool anIsScalarVisible = theMode > eNone;
523 if(anIsScalarVisible){
524 SMESH::Controls::FunctorPtr aFunctor;
528 SMESH::Controls::Length* aControl = new SMESH::Controls::Length();
529 aControl->SetPrecision( myControlsPrecision );
530 aFunctor.reset( aControl );
531 myControlActor = my1DActor;
536 aFunctor.reset(new SMESH::Controls::Length2D());
537 myControlActor = my2DActor;
541 aFunctor.reset(new SMESH::Controls::FreeBorders());
542 myControlActor = my1DActor;
545 aFunctor.reset(new SMESH::Controls::FreeEdges());
546 myControlActor = my2DActor;
548 case eMultiConnection:
549 aFunctor.reset(new SMESH::Controls::MultiConnection());
550 myControlActor = my1DActor;
552 case eMultiConnection2D:
553 aFunctor.reset(new SMESH::Controls::MultiConnection2D());
554 myControlActor = my2DActor;
558 SMESH::Controls::Area* aControl = new SMESH::Controls::Area();
559 aControl->SetPrecision( myControlsPrecision );
560 aFunctor.reset( aControl );
561 myControlActor = my2DActor;
566 SMESH::Controls::Taper* aControl = new SMESH::Controls::Taper();
567 aControl->SetPrecision( myControlsPrecision );
568 aFunctor.reset( aControl );
569 myControlActor = my2DActor;
574 SMESH::Controls::AspectRatio* aControl = new SMESH::Controls::AspectRatio();
575 aControl->SetPrecision( myControlsPrecision );
576 aFunctor.reset( aControl );
577 myControlActor = my2DActor;
582 SMESH::Controls::AspectRatio3D* aControl = new SMESH::Controls::AspectRatio3D();
583 aControl->SetPrecision( myControlsPrecision );
584 aFunctor.reset( aControl );
585 myControlActor = my3DActor;
590 SMESH::Controls::MinimumAngle* aControl = new SMESH::Controls::MinimumAngle();
591 aControl->SetPrecision( myControlsPrecision );
592 aFunctor.reset( aControl );
593 myControlActor = my2DActor;
598 SMESH::Controls::Warping* aControl = new SMESH::Controls::Warping();
599 aControl->SetPrecision( myControlsPrecision );
600 aFunctor.reset( aControl );
601 myControlActor = my2DActor;
606 SMESH::Controls::Skew* aControl = new SMESH::Controls::Skew();
607 aControl->SetPrecision( myControlsPrecision );
608 aFunctor.reset( aControl );
609 myControlActor = my2DActor;
616 vtkUnstructuredGrid* aGrid = myControlActor->GetUnstructuredGrid();
617 vtkIdType aNbCells = aGrid->GetNumberOfCells();
619 myControlMode = theMode;
620 switch(myControlMode){
623 my1DExtActor->SetExtControlMode(aFunctor);
626 case eMultiConnection2D:
627 my1DExtActor->SetExtControlMode(aFunctor,myScalarBarActor,myLookupTable);
630 myControlActor->SetControlMode(aFunctor,myScalarBarActor,myLookupTable);
634 if(theCheckEntityMode){
635 if(myControlActor == my1DActor)
636 SetEntityMode(eEdges);
637 else if(myControlActor == my2DActor){
638 switch(myControlMode){
641 case eMultiConnection2D:
642 //SetEntityMode(eEdges);
643 SetEntityMode(eFaces);
646 SetEntityMode(eFaces);
648 }else if(myControlActor == my3DActor)
649 SetEntityMode(eVolumes);
652 }else if(theCheckEntityMode){
653 myEntityMode = eAllEntity;
656 SetRepresentation(GetRepresentation());
658 myTimeStamp->Modified();
663 void SMESH_ActorDef::AddToRender(vtkRenderer* theRenderer){
664 SALOME_Actor::AddToRender(theRenderer);
666 theRenderer->AddActor(myNodeActor);
667 theRenderer->AddActor(myBaseActor);
669 theRenderer->AddActor(my3DActor);
670 theRenderer->AddActor(my2DActor);
672 theRenderer->AddActor(my1DActor);
673 theRenderer->AddActor(my1DExtActor);
675 theRenderer->AddActor(myHighlitableActor);
677 theRenderer->AddActor2D(myScalarBarActor);
679 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
680 myClsSelectVisiblePoints->SetRenderer(theRenderer);
682 theRenderer->AddActor2D(myPointLabels);
683 theRenderer->AddActor2D(myCellsLabels);
686 void SMESH_ActorDef::RemoveFromRender(vtkRenderer* theRenderer){
687 SALOME_Actor::RemoveFromRender(theRenderer);
689 theRenderer->RemoveActor(myNodeActor);
690 theRenderer->RemoveActor(myBaseActor);
692 theRenderer->RemoveActor(myHighlitableActor);
694 theRenderer->RemoveActor(my1DActor);
695 theRenderer->RemoveActor(my1DExtActor);
697 theRenderer->RemoveActor(my2DActor);
698 theRenderer->RemoveActor(my3DActor);
700 theRenderer->RemoveActor(myScalarBarActor);
701 theRenderer->RemoveActor(myPointLabels);
702 theRenderer->RemoveActor(myCellsLabels);
706 bool SMESH_ActorDef::Init(TVisualObjPtr theVisualObj,
707 const char* theEntry,
711 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry,"SMESH",theName);
715 myVisualObj = theVisualObj;
716 myVisualObj->Update(theIsClear);
718 myNodeActor->Init(myVisualObj,myImplicitBoolean);
719 myBaseActor->Init(myVisualObj,myImplicitBoolean);
721 myHighlitableActor->Init(myVisualObj,myImplicitBoolean);
723 my1DActor->Init(myVisualObj,myImplicitBoolean);
724 my1DExtActor->Init(myVisualObj,myImplicitBoolean);
726 my2DActor->Init(myVisualObj,myImplicitBoolean);
727 my3DActor->Init(myVisualObj,myImplicitBoolean);
729 my1DActor->GetMapper()->SetLookupTable(myLookupTable);
730 my1DExtActor->GetMapper()->SetLookupTable(myLookupTable);
732 my2DActor->GetMapper()->SetLookupTable(myLookupTable);
733 my3DActor->GetMapper()->SetLookupTable(myLookupTable);
735 float aFactor, aUnits;
736 my2DActor->GetPolygonOffsetParameters(aFactor,aUnits);
737 my2DActor->SetPolygonOffsetParameters(aFactor,aUnits*0.75);
739 //SetIsShrunkable(theGrid->GetNumberOfCells() > 10);
740 SetIsShrunkable(true);
742 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
746 QString aMode = mgr->stringValue( "SMESH", "display_mode" );
747 SetRepresentation(-1);
749 if(aMode.compare("Wireframe") == 0){
750 SetRepresentation(eEdge);
751 }else if(aMode.compare("Shading") == 0){
752 SetRepresentation(eSurface);
753 }else if(aMode.compare("Nodes") == 0){
754 SetRepresentation(ePoint);
757 if(aMode == "Shrink"){
761 myTimeStamp->Modified();
767 float* SMESH_ActorDef::GetBounds(){
768 return myNodeActor->GetBounds();
772 vtkDataSet* SMESH_ActorDef::GetInput(){
773 return GetUnstructuredGrid();
777 void SMESH_ActorDef::SetTransform(VTKViewer_Transform* theTransform){
778 myNodeActor->SetTransform(theTransform);
779 myBaseActor->SetTransform(theTransform);
781 myHighlitableActor->SetTransform(theTransform);
783 my1DActor->SetTransform(theTransform);
784 my1DExtActor->SetTransform(theTransform);
786 my2DActor->SetTransform(theTransform);
787 my3DActor->SetTransform(theTransform);
793 void SMESH_ActorDef::SetMapper(vtkMapper* theMapper){
794 vtkLODActor::SetMapper(theMapper);
798 void SMESH_ActorDef::ShallowCopy(vtkProp *prop){
799 SALOME_Actor::ShallowCopy(prop);
803 vtkMapper* SMESH_ActorDef::GetMapper(){
804 return myPickableActor->GetMapper();
808 vtkUnstructuredGrid* SMESH_ActorDef::GetUnstructuredGrid(){
809 return myVisualObj->GetUnstructuredGrid();
813 bool SMESH_ActorDef::IsInfinitive(){
814 vtkDataSet *aDataSet = myPickableActor->GetUnstructuredGrid();
816 myIsInfinite = aDataSet->GetNumberOfCells() == 0 ||
817 aDataSet->GetNumberOfCells() == 1 &&
818 aDataSet->GetCell(0)->GetCellType() == VTK_VERTEX;
819 return SALOME_Actor::IsInfinitive();
823 void SMESH_ActorDef::SetIsShrunkable(bool theShrunkable){
824 myIsShrinkable = theShrunkable;
828 float SMESH_ActorDef::GetShrinkFactor(){
829 return myBaseActor->GetShrinkFactor();
832 void SMESH_ActorDef::SetShrinkFactor(float theValue){
833 myBaseActor->SetShrinkFactor(theValue);
835 my1DActor->SetShrinkFactor(theValue);
836 my1DExtActor->SetShrinkFactor(theValue);
838 my2DActor->SetShrinkFactor(theValue);
839 my3DActor->SetShrinkFactor(theValue);
844 void SMESH_ActorDef::SetShrink(){
845 if(!myIsShrinkable) return;
847 myBaseActor->SetShrink();
849 my1DActor->SetShrink();
850 my1DExtActor->SetShrink();
852 my2DActor->SetShrink();
853 my3DActor->SetShrink();
859 void SMESH_ActorDef::UnShrink(){
860 if(!myIsShrunk) return;
862 myBaseActor->UnShrink();
864 my1DActor->UnShrink();
865 my1DExtActor->UnShrink();
867 my2DActor->UnShrink();
868 my3DActor->UnShrink();
875 int SMESH_ActorDef::GetNodeObjId(int theVtkID){
876 return myPickableActor->GetNodeObjId(theVtkID);
879 float* SMESH_ActorDef::GetNodeCoord(int theObjID){
880 return myPickableActor->GetNodeCoord(theObjID);
884 int SMESH_ActorDef::GetElemObjId(int theVtkID){
885 return myPickableActor->GetElemObjId(theVtkID);
888 vtkCell* SMESH_ActorDef::GetElemCell(int theObjID){
889 return myPickableActor->GetElemCell(theObjID);
893 void SMESH_ActorDef::SetVisibility(int theMode){
894 SetVisibility(theMode,true);
898 void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation){
899 SALOME_Actor::SetVisibility(theMode);
901 myNodeActor->VisibilityOff();
902 myBaseActor->VisibilityOff();
904 my1DActor->VisibilityOff();
905 my1DExtActor->VisibilityOff();
907 my2DActor->VisibilityOff();
908 my3DActor->VisibilityOff();
910 myScalarBarActor->VisibilityOff();
911 myPointLabels->VisibilityOff();
912 myCellsLabels->VisibilityOff();
915 if(theIsUpdateRepersentation)
916 SetRepresentation(GetRepresentation());
918 if(myControlMode != eNone){
919 switch(myControlMode){
922 my1DExtActor->VisibilityOn();
925 case eMultiConnection2D:
926 my1DExtActor->VisibilityOn();
928 if(myControlActor->GetUnstructuredGrid()->GetNumberOfCells())
929 myScalarBarActor->VisibilityOn();
933 if(myRepresentation != ePoint)
934 myPickableActor->VisibilityOn();
936 myNodeActor->VisibilityOn();
939 if(myEntityMode & eEdges){
940 my1DActor->VisibilityOn();
943 if(myEntityMode & eFaces){
944 my2DActor->VisibilityOn();
947 if(myEntityMode & eVolumes){
948 my3DActor->VisibilityOn();
951 if(myIsPointsLabeled){
952 myPointLabels->VisibilityOn();
953 myNodeActor->VisibilityOn();
957 myCellsLabels->VisibilityOn();
964 void SMESH_ActorDef::SetEntityMode(unsigned int theMode){
965 myEntityState = eAllEntity;
967 if(!myVisualObj->GetNbEntities(SMDSAbs_Edge)){
968 myEntityState &= ~eEdges;
972 if(!myVisualObj->GetNbEntities(SMDSAbs_Face)){
973 myEntityState &= ~eFaces;
977 if(!myVisualObj->GetNbEntities(SMDSAbs_Volume)){
978 myEntityState &= ~eVolumes;
979 theMode &= ~eVolumes;
983 if(myVisualObj->GetNbEntities(SMDSAbs_Edge))
986 if(myVisualObj->GetNbEntities(SMDSAbs_Face))
989 if(myVisualObj->GetNbEntities(SMDSAbs_Volume))
993 myBaseActor->myGeomFilter->SetInside(myEntityMode != myEntityState);
995 myEntityMode = theMode;
996 VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
997 aFilter = myBaseActor->GetExtractUnstructuredGrid();
998 aFilter->ClearRegisteredCellsWithType();
999 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
1001 if(myEntityMode & eEdges){
1002 if (MYDEBUG) MESSAGE("EDGES");
1003 aFilter->RegisterCellsWithType(VTK_LINE);
1006 if(myEntityMode & eFaces){
1007 if (MYDEBUG) MESSAGE("FACES");
1008 aFilter->RegisterCellsWithType(VTK_TRIANGLE);
1009 aFilter->RegisterCellsWithType(VTK_POLYGON);
1010 aFilter->RegisterCellsWithType(VTK_QUAD);
1013 if(myEntityMode & eVolumes){
1014 if (MYDEBUG) MESSAGE("VOLUMES");
1015 aFilter->RegisterCellsWithType(VTK_TETRA);
1016 aFilter->RegisterCellsWithType(VTK_VOXEL);
1017 aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1018 aFilter->RegisterCellsWithType(VTK_WEDGE);
1019 aFilter->RegisterCellsWithType(VTK_PYRAMID);
1020 aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1023 if (MYDEBUG) MESSAGE(aFilter->GetOutput()->GetNumberOfCells());
1024 SetVisibility(GetVisibility(),false);
1027 void SMESH_ActorDef::SetRepresentation(int theMode){
1028 int aNbEdges = myVisualObj->GetNbEntities(SMDSAbs_Edge);
1029 int aNbFaces = myVisualObj->GetNbEntities(SMDSAbs_Face);
1030 int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume);
1032 myRepresentation = eSurface;
1033 if(!aNbFaces && !aNbVolumes && aNbEdges){
1034 myRepresentation = eEdge;
1035 }else if(!aNbFaces && !aNbVolumes && !aNbEdges){
1036 myRepresentation = ePoint;
1041 if(!aNbFaces && !aNbVolumes && !aNbEdges) return;
1044 if(!aNbFaces && !aNbVolumes) return;
1047 myRepresentation = theMode;
1050 if(!GetUnstructuredGrid()->GetNumberOfCells())
1051 myRepresentation = ePoint;
1054 if(myRepresentation == ePoint){
1062 myPickableActor = myBaseActor;
1063 myNodeActor->SetVisibility(false);
1064 vtkProperty *aProp = NULL, *aBackProp = NULL;
1065 SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1);
1066 switch(myRepresentation){
1068 myPickableActor = myNodeActor;
1069 myNodeActor->SetVisibility(true);
1071 aProp = aBackProp = myNodeProp;
1072 aReperesent = SMESH_DeviceActor::ePoint;
1075 aProp = aBackProp = myEdgeProp;
1076 aReperesent = SMESH_DeviceActor::eInsideframe;
1079 aProp = mySurfaceProp;
1080 aBackProp = myBackSurfaceProp;
1081 aReperesent = SMESH_DeviceActor::eSurface;
1085 my2DActor->SetProperty(aProp);
1086 my2DActor->SetBackfaceProperty(aBackProp);
1087 my2DActor->SetRepresentation(aReperesent);
1089 my3DActor->SetProperty(aProp);
1090 my3DActor->SetBackfaceProperty(aBackProp);
1091 my3DActor->SetRepresentation(aReperesent);
1093 my1DExtActor->SetVisibility(false);
1095 switch(myControlMode){
1097 case eMultiConnection:
1098 aProp = aBackProp = my1DProp;
1099 if(myRepresentation != ePoint)
1100 aReperesent = SMESH_DeviceActor::eInsideframe;
1104 my1DActor->SetProperty(aProp);
1105 my1DActor->SetBackfaceProperty(aBackProp);
1106 my1DActor->SetRepresentation(aReperesent);
1108 my1DExtActor->SetRepresentation(aReperesent);
1110 if(myIsPointsVisible)
1111 myPickableActor = myNodeActor;
1112 if(GetPointRepresentation())
1113 myNodeActor->SetVisibility(true);
1115 SetMapper(myPickableActor->GetMapper());
1117 SetVisibility(GetVisibility(),false);
1123 void SMESH_ActorDef::SetPointRepresentation(bool theIsPointsVisible){
1124 myIsPointsVisible = theIsPointsVisible;
1125 SetRepresentation(GetRepresentation());
1128 bool SMESH_ActorDef::GetPointRepresentation(){
1129 return myIsPointsVisible || myIsPointsLabeled;
1133 void SMESH_ActorDef::UpdateHighlight(){
1134 myHighlitableActor->SetVisibility(false);
1135 myHighlitableActor->SetHighlited(false);
1137 if(myIsHighlighted){
1138 myHighlitableActor->SetProperty(myHighlightProp);
1139 }else if(myIsPreselected){
1140 myHighlitableActor->SetProperty(myPreselectProp);
1143 bool anIsVisible = GetVisibility();
1145 if(myIsHighlighted || myIsPreselected){
1146 if(GetUnstructuredGrid()->GetNumberOfCells()){
1147 myHighlitableActor->SetHighlited(anIsVisible);
1148 myHighlitableActor->SetVisibility(anIsVisible);
1149 myHighlitableActor->GetExtractUnstructuredGrid()->
1150 SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::eCells);
1151 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
1152 }else if(myRepresentation == ePoint || GetPointRepresentation()){
1153 myHighlitableActor->SetHighlited(anIsVisible);
1154 myHighlitableActor->SetVisibility(anIsVisible);
1155 myHighlitableActor->GetExtractUnstructuredGrid()->
1156 SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
1157 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::ePoint);
1163 void SMESH_ActorDef::highlight(bool theHighlight){
1164 myIsHighlighted = theHighlight;
1169 void SMESH_ActorDef::SetPreSelected(bool thePreselect){
1170 myIsPreselected = thePreselect;
1176 int SMESH_ActorDef::RenderOpaqueGeometry(vtkViewport *vp)
1178 if (myPickableActor->GetIsOpaque())
1180 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1188 int SMESH_ActorDef::RenderTranslucentGeometry(vtkViewport *vp)
1190 if (!myPickableActor->GetIsOpaque())
1192 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1200 void SMESH_ActorDef::Render(vtkRenderer *ren){
1201 unsigned long aTime = myTimeStamp->GetMTime();
1202 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1203 unsigned long aClippingTime = myImplicitBoolean->GetMTime();
1204 if(anObjTime > aTime || aClippingTime > aTime)
1209 void SMESH_ActorDef::Update(){
1210 if(MYDEBUG) MESSAGE("SMESH_ActorDef::Update");
1212 if(GetControlMode() != eNone) {
1213 unsigned long aTime = myTimeStamp->GetMTime();
1214 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1215 if (anObjTime > aTime)
1216 SetControlMode(GetControlMode(),false);
1218 if(myIsPointsLabeled){
1219 SetPointsLabeled(myIsPointsLabeled);
1221 if(myIsCellsLabeled){
1222 SetCellsLabeled(myIsCellsLabeled);
1224 SetEntityMode(GetEntityMode());
1225 SetVisibility(GetVisibility());
1227 myTimeStamp->Modified();
1232 void SMESH_ActorDef::ReleaseGraphicsResources(vtkWindow *renWin){
1233 SALOME_Actor::ReleaseGraphicsResources(renWin);
1235 myPickableActor->ReleaseGraphicsResources(renWin);
1239 static void GetColor(vtkProperty *theProperty, float& r,float& g,float& b){
1240 float* aColor = theProperty->GetColor();
1247 void SMESH_ActorDef::SetOpacity(float theValue){
1248 mySurfaceProp->SetOpacity(theValue);
1249 myBackSurfaceProp->SetOpacity(theValue);
1250 myEdgeProp->SetOpacity(theValue);
1251 myNodeProp->SetOpacity(theValue);
1253 my1DProp->SetOpacity(theValue);
1257 float SMESH_ActorDef::GetOpacity(){
1258 return mySurfaceProp->GetOpacity();
1262 void SMESH_ActorDef::SetSufaceColor(float r,float g,float b){
1263 mySurfaceProp->SetColor(r,g,b);
1267 void SMESH_ActorDef::GetSufaceColor(float& r,float& g,float& b){
1268 ::GetColor(mySurfaceProp,r,g,b);
1271 void SMESH_ActorDef::SetBackSufaceColor(float r,float g,float b){
1272 myBackSurfaceProp->SetColor(r,g,b);
1276 void SMESH_ActorDef::GetBackSufaceColor(float& r,float& g,float& b){
1277 ::GetColor(myBackSurfaceProp,r,g,b);
1280 void SMESH_ActorDef::SetEdgeColor(float r,float g,float b){
1281 myEdgeProp->SetColor(r,g,b);
1282 my1DProp->SetColor(r,g,b);
1283 my1DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1287 void SMESH_ActorDef::GetEdgeColor(float& r,float& g,float& b){
1288 ::GetColor(myEdgeProp,r,g,b);
1291 void SMESH_ActorDef::SetNodeColor(float r,float g,float b){
1292 myNodeProp->SetColor(r,g,b);
1296 void SMESH_ActorDef::GetNodeColor(float& r,float& g,float& b){
1297 ::GetColor(myNodeProp,r,g,b);
1300 void SMESH_ActorDef::SetHighlightColor(float r,float g,float b){
1301 myHighlightProp->SetColor(r,g,b);
1305 void SMESH_ActorDef::GetHighlightColor(float& r,float& g,float& b){
1306 ::GetColor(myHighlightProp,r,g,b);
1309 void SMESH_ActorDef::SetPreHighlightColor(float r,float g,float b){
1310 myPreselectProp->SetColor(r,g,b);
1314 void SMESH_ActorDef::GetPreHighlightColor(float& r,float& g,float& b){
1315 ::GetColor(myPreselectProp,r,g,b);
1319 float SMESH_ActorDef::GetLineWidth(){
1320 return myEdgeProp->GetLineWidth();
1324 void SMESH_ActorDef::SetLineWidth(float theVal){
1325 myEdgeProp->SetLineWidth(theVal);
1327 my1DProp->SetLineWidth(theVal + aLineWidthInc);
1328 my1DExtProp->SetLineWidth(theVal + aLineWidthInc);
1334 void SMESH_ActorDef::SetNodeSize(float theVal){
1335 myNodeProp->SetPointSize(theVal);
1336 myHighlightProp->SetPointSize(theVal);
1337 myPreselectProp->SetPointSize(theVal);
1339 my1DProp->SetPointSize(theVal + aPointSizeInc);
1340 my1DExtProp->SetPointSize(theVal + aPointSizeInc);
1345 float SMESH_ActorDef::GetNodeSize(){
1346 return myNodeProp->GetPointSize();
1349 int SMESH_ActorDef::GetObjDimension( const int theObjId )
1351 return myVisualObj->GetElemDimension( theObjId );
1356 IsImplicitFunctionUsed() const
1358 return myBaseActor->IsImplicitFunctionUsed();
1363 SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
1365 myNodeActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1366 myBaseActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1368 myHighlitableActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1370 my1DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1371 my1DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1373 my2DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1374 my3DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1379 AddClippingPlane(vtkPlane* thePlane)
1382 myImplicitBoolean->GetFunction()->AddItem(thePlane);
1383 myCippingPlaneCont.push_back(thePlane);
1384 if(!IsImplicitFunctionUsed())
1385 SetImplicitFunctionUsed(true);
1387 return myCippingPlaneCont.size();
1392 RemoveAllClippingPlanes()
1394 myImplicitBoolean->GetFunction()->RemoveAllItems();
1395 myImplicitBoolean->GetFunction()->Modified(); // VTK bug
1396 myCippingPlaneCont.clear();
1397 SetImplicitFunctionUsed(false);
1402 GetNumberOfClippingPlanes()
1404 return myCippingPlaneCont.size();
1409 GetClippingPlane(vtkIdType theID)
1411 if(theID >= myCippingPlaneCont.size())
1413 return myCippingPlaneCont[theID].Get();
1417 static void ComputeBoundsParam(vtkDataSet* theDataSet,
1418 float theDirection[3], float theMinPnt[3],
1419 float& theMaxBoundPrj, float& theMinBoundPrj)
1422 theDataSet->GetBounds(aBounds);
1424 //Enlarge bounds in order to avoid conflicts of precision
1425 for(int i = 0; i < 6; i += 2){
1426 static double EPS = 1.0E-3;
1427 float aDelta = (aBounds[i+1] - aBounds[i])*EPS;
1428 aBounds[i] -= aDelta;
1429 aBounds[i+1] += aDelta;
1432 float aBoundPoints[8][3] = { {aBounds[0],aBounds[2],aBounds[4]},
1433 {aBounds[1],aBounds[2],aBounds[4]},
1434 {aBounds[0],aBounds[3],aBounds[4]},
1435 {aBounds[1],aBounds[3],aBounds[4]},
1436 {aBounds[0],aBounds[2],aBounds[5]},
1437 {aBounds[1],aBounds[2],aBounds[5]},
1438 {aBounds[0],aBounds[3],aBounds[5]},
1439 {aBounds[1],aBounds[3],aBounds[5]}};
1441 int aMaxId = 0, aMinId = aMaxId;
1442 theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
1443 theMinBoundPrj = theMaxBoundPrj;
1444 for(int i = 1; i < 8; i++){
1445 float aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
1446 if(theMaxBoundPrj < aTmp){
1447 theMaxBoundPrj = aTmp;
1450 if(theMinBoundPrj > aTmp){
1451 theMinBoundPrj = aTmp;
1455 float *aMinPnt = aBoundPoints[aMaxId];
1456 theMinPnt[0] = aMinPnt[0];
1457 theMinPnt[1] = aMinPnt[1];
1458 theMinPnt[2] = aMinPnt[2];
1462 static void DistanceToPosition(vtkDataSet* theDataSet,
1463 float theDirection[3], float theDist, float thePos[3])
1465 float aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1466 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1467 float aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
1468 thePos[0] = aMinPnt[0]-theDirection[0]*aLength;
1469 thePos[1] = aMinPnt[1]-theDirection[1]*aLength;
1470 thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
1474 static void PositionToDistance(vtkDataSet* theDataSet,
1475 float theDirection[3], float thePos[3], float& theDist)
1477 float aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1478 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1479 float aPrj = vtkMath::Dot(theDirection,thePos);
1480 theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
1484 void SMESH_ActorDef::SetPlaneParam(float theDir[3], float theDist, vtkPlane* thePlane)
1486 thePlane->SetNormal(theDir);
1488 ::DistanceToPosition(GetUnstructuredGrid(),theDir,theDist,anOrigin);
1489 thePlane->SetOrigin(anOrigin);
1493 void SMESH_ActorDef::GetPlaneParam(float theDir[3], float& theDist, vtkPlane* thePlane)
1495 thePlane->GetNormal(theDir);
1498 thePlane->GetOrigin(anOrigin);
1499 ::PositionToDistance(GetUnstructuredGrid(),theDir,anOrigin,theDist);
1502 void SMESH_ActorDef::UpdateScalarBar()
1504 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
1508 vtkTextProperty* aScalarBarTitleProp = vtkTextProperty::New();
1510 QColor aTColor = mgr->colorValue( "SMESH", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
1511 aScalarBarTitleProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1513 aScalarBarTitleProp->SetFontFamilyToArial();
1515 if ( mgr->hasValue( "SMESH", "scalar_bar_title_font" ) )
1517 QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
1518 if ( f.family() == "Arial" )
1519 aScalarBarTitleProp->SetFontFamilyToArial();
1520 else if ( f.family() == "Courier" )
1521 aScalarBarTitleProp->SetFontFamilyToCourier();
1522 else if ( f.family() == "Times" )
1523 aScalarBarTitleProp->SetFontFamilyToTimes();
1526 aScalarBarTitleProp->BoldOn();
1528 aScalarBarTitleProp->BoldOff();
1531 aScalarBarTitleProp->ItalicOn();
1533 aScalarBarTitleProp->ItalicOff();
1535 if ( f.underline() )
1536 aScalarBarTitleProp->ShadowOn();
1538 aScalarBarTitleProp->ShadowOff();
1541 myScalarBarActor->SetTitleTextProperty( aScalarBarTitleProp );
1542 aScalarBarTitleProp->Delete();
1544 vtkTextProperty* aScalarBarLabelProp = vtkTextProperty::New();
1546 aTColor = mgr->colorValue( "SMESH", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
1547 aScalarBarLabelProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1549 aScalarBarLabelProp->SetFontFamilyToArial();
1550 if( mgr->hasValue( "SMESH", "scalar_bar_label_font" ) )
1552 QFont f = mgr->stringValue( "SMESH", "scalar_bar_label_font" );
1553 if( f.family() == "Arial" )
1554 aScalarBarLabelProp->SetFontFamilyToArial();
1555 else if( f.family() == "Courier" )
1556 aScalarBarLabelProp->SetFontFamilyToCourier();
1557 else if( f.family() == "Times" )
1558 aScalarBarLabelProp->SetFontFamilyToTimes();
1561 aScalarBarLabelProp->BoldOn();
1563 aScalarBarLabelProp->BoldOff();
1566 aScalarBarLabelProp->ItalicOn();
1568 aScalarBarLabelProp->ItalicOff();
1571 aScalarBarLabelProp->ShadowOn();
1573 aScalarBarLabelProp->ShadowOff();
1576 myScalarBarActor->SetLabelTextProperty( aScalarBarLabelProp );
1577 aScalarBarLabelProp->Delete();
1579 bool horiz = ( mgr->integerValue( "SMESH", "scalar_bar_orientation" ) == 1 );
1580 QString name = QString( "scalar_bar_%1_" ).arg( horiz ? "horizontal" : "vertical" );
1582 myScalarBarActor->SetOrientationToHorizontal();
1584 myScalarBarActor->SetOrientationToVertical();
1587 float aXVal = horiz ? 0.20 : 0.01;
1588 if( mgr->hasValue( "SMESH", name + "x" ) )
1589 aXVal = mgr->doubleValue( "SMESH", name + "x", aXVal );
1591 float aYVal = horiz ? 0.01 : 0.1;
1592 if( mgr->hasValue( "SMESH", name + "y" ) )
1593 aYVal = mgr->doubleValue( "SMESH", name + "y", aYVal );
1594 myScalarBarActor->SetPosition( aXVal, aYVal );
1596 float aWVal = horiz ? 0.60 : 0.10;
1597 if( mgr->hasValue( "SMESH", name + "width" ) )
1598 aWVal = mgr->doubleValue( "SMESH", name + "width", aWVal );
1599 myScalarBarActor->SetWidth( aWVal );
1601 float aHVal = horiz ? 0.12 : 0.80;
1602 if( mgr->hasValue( "SMESH", name + "height" ) )
1603 aHVal = mgr->doubleValue( "SMESH", name + "height", aHVal );
1604 myScalarBarActor->SetHeight( aHVal );
1607 if( mgr->hasValue( "SMESH", "scalar_bar_num_labels" ) )
1608 anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_labels", anIntVal );
1609 myScalarBarActor->SetNumberOfLabels( anIntVal == 0 ? 5: anIntVal );
1612 if( mgr->hasValue( "SMESH", "scalar_bar_num_colors" ) )
1613 anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_colors", anIntVal );
1614 myScalarBarActor->SetMaximumNumberOfColors( anIntVal == 0 ? 64 : anIntVal );