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 = -1;
120 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
121 if ( mgr && mgr->booleanValue( "SMESH", "use_precision", false ) )
122 myControlsPrecision = (long)SMESH::GetFloat( "SMESH", "controls_precision", -1 );
124 float aPointSize = SMESH::GetFloat("SMESH:node_size",3);
125 float aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
127 vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
128 VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
130 //Definition 2D and 3D divices of the actor
131 //-----------------------------------------
132 float anRGB[3] = {1,1,1};
133 mySurfaceProp = vtkProperty::New();
134 SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
135 mySurfaceProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
137 myBackSurfaceProp = vtkProperty::New();
138 SMESH::GetColor( "SMESH", "backface_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 0, 255 ) );
139 myBackSurfaceProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
141 my2DActor = SMESH_DeviceActor::New();
142 my2DActor->SetUserMatrix(aMatrix);
143 my2DActor->PickableOff();
144 my2DActor->SetProperty(mySurfaceProp);
145 my2DActor->SetBackfaceProperty(myBackSurfaceProp);
146 my2DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
147 aFilter = my2DActor->GetExtractUnstructuredGrid();
148 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
149 aFilter->RegisterCellsWithType(VTK_TRIANGLE);
150 aFilter->RegisterCellsWithType(VTK_POLYGON);
151 aFilter->RegisterCellsWithType(VTK_QUAD);
153 my3DActor = SMESH_DeviceActor::New();
154 my3DActor->SetUserMatrix(aMatrix);
155 my3DActor->PickableOff();
156 my3DActor->SetProperty(mySurfaceProp);
157 my3DActor->SetBackfaceProperty(myBackSurfaceProp);
158 my3DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
159 aFilter = my3DActor->GetExtractUnstructuredGrid();
160 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
161 aFilter->RegisterCellsWithType(VTK_TETRA);
162 aFilter->RegisterCellsWithType(VTK_VOXEL);
163 aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
164 aFilter->RegisterCellsWithType(VTK_WEDGE);
165 aFilter->RegisterCellsWithType(VTK_PYRAMID);
166 aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
168 //Definition 1D divice of the actor
169 //---------------------------------
170 myEdgeProp = vtkProperty::New();
171 myEdgeProp->SetAmbient(1.0);
172 myEdgeProp->SetDiffuse(0.0);
173 myEdgeProp->SetSpecular(0.0);
174 SMESH::GetColor( "SMESH", "outline_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
175 myEdgeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
176 myEdgeProp->SetLineWidth(aLineWidth);
178 my1DActor = SMESH_DeviceActor::New();
179 my1DActor->SetUserMatrix(aMatrix);
180 my1DActor->PickableOff();
181 my1DActor->SetHighlited(true);
182 my1DActor->SetProperty(myEdgeProp);
183 my1DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
184 aFilter = my1DActor->GetExtractUnstructuredGrid();
185 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
186 aFilter->RegisterCellsWithType(VTK_LINE);
188 my1DProp = vtkProperty::New();
189 my1DProp->DeepCopy(myEdgeProp);
190 my1DProp->SetLineWidth(aLineWidth + aLineWidthInc);
191 my1DProp->SetPointSize(aPointSize);
193 my1DExtProp = vtkProperty::New();
194 my1DExtProp->DeepCopy(myEdgeProp);
195 anRGB[0] = 1 - anRGB[0];
196 anRGB[1] = 1 - anRGB[1];
197 anRGB[2] = 1 - anRGB[2];
198 my1DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
199 my1DExtProp->SetLineWidth(aLineWidth + aLineWidthInc);
200 my1DExtProp->SetPointSize(aPointSize + aPointSizeInc);
202 my1DExtActor = SMESH_DeviceActor::New();
203 my1DExtActor->SetUserMatrix(aMatrix);
204 my1DExtActor->PickableOff();
205 my1DExtActor->SetHighlited(true);
206 my1DExtActor->SetVisibility(false);
207 my1DExtActor->SetProperty(my1DExtProp);
208 my1DExtActor->SetRepresentation(SMESH_DeviceActor::eInsideframe);
209 aFilter = my1DExtActor->GetExtractUnstructuredGrid();
210 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
211 aFilter->RegisterCellsWithType(VTK_LINE);
214 //Definition 0D divice of the actor
215 //---------------------------------
216 myNodeProp = vtkProperty::New();
217 SMESH::GetColor( "SMESH", "node_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 0, 0 ) );
218 myNodeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
219 myNodeProp->SetPointSize(aPointSize);
221 myNodeActor = SMESH_DeviceActor::New();
222 myNodeActor->SetUserMatrix(aMatrix);
223 myNodeActor->SetStoreClippingMapping(true);
224 myNodeActor->PickableOff();
225 myNodeActor->SetVisibility(false);
226 myNodeActor->SetProperty(myNodeProp);
227 myNodeActor->SetRepresentation(SMESH_DeviceActor::ePoint);
228 aFilter = myNodeActor->GetExtractUnstructuredGrid();
229 aFilter->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
232 //Definition of Pickable and Highlitable engines
233 //----------------------------------------------
235 myBaseActor = SMESH_DeviceActor::New();
236 myBaseActor->SetUserMatrix(aMatrix);
237 myBaseActor->SetStoreGemetryMapping(true);
238 myBaseActor->GetProperty()->SetOpacity(0.0);
240 myPickableActor = myBaseActor;
242 myHighlightProp = vtkProperty::New();
243 myHighlightProp->SetAmbient(1.0);
244 myHighlightProp->SetDiffuse(0.0);
245 myHighlightProp->SetSpecular(0.0);
246 SMESH::GetColor( "SMESH", "selection_object_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
247 myHighlightProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
248 myHighlightProp->SetPointSize(aPointSize);
249 myHighlightProp->SetRepresentation(1);
251 myPreselectProp = vtkProperty::New();
252 myPreselectProp->SetAmbient(1.0);
253 myPreselectProp->SetDiffuse(0.0);
254 myPreselectProp->SetSpecular(0.0);
255 SMESH::GetColor( "SMESH", "highlight_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 255, 255 ) );
256 myPreselectProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
257 myPreselectProp->SetPointSize(aPointSize);
258 myPreselectProp->SetRepresentation(1);
260 myHighlitableActor = SMESH_DeviceActor::New();
261 myHighlitableActor->SetUserMatrix(aMatrix);
262 myHighlitableActor->PickableOff();
263 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
265 SetShrinkFactor( SMESH::GetFloat( "SMESH:shrink_coeff", 0.75 ) );
270 myControlMode = eNone;
271 myControlActor = my2DActor;
273 //Definition of myScalarBarActor
274 //------------------------------
275 myLookupTable = vtkLookupTable::New();
276 //Fix for Bug PAL5195 - SMESH764:
277 //Controls - Aspect Ratio: incorrect colors of the best and worst values
278 myLookupTable->SetHueRange(0.667,0.0);
280 myScalarBarActor = vtkScalarBarActor::New();
281 myScalarBarActor->SetVisibility(false);
282 myScalarBarActor->SetLookupTable(myLookupTable);
284 mgr = SUIT_Session::session()->resourceMgr();
288 //Definition of points numbering pipeline
289 //---------------------------------------
290 myPointsNumDataSet = vtkUnstructuredGrid::New();
292 myPtsMaskPoints = vtkMaskPoints::New();
293 myPtsMaskPoints->SetInput(myPointsNumDataSet);
294 myPtsMaskPoints->SetOnRatio(1);
296 myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
297 myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
298 myPtsSelectVisiblePoints->SelectInvisibleOff();
299 myPtsSelectVisiblePoints->SetTolerance(0.1);
301 myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
302 myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
303 myPtsLabeledDataMapper->SetLabelFormat("%g");
304 myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
306 vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
307 aPtsTextProp->SetFontFamilyToTimes();
308 static int aPointsFontSize = 10;
309 aPtsTextProp->SetFontSize(aPointsFontSize);
310 aPtsTextProp->SetBold(1);
311 aPtsTextProp->SetItalic(0);
312 aPtsTextProp->SetShadow(0);
313 myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
314 aPtsTextProp->Delete();
316 myEntityMode = eAllEntity;
318 myIsPointsLabeled = false;
320 myPointLabels = vtkActor2D::New();
321 myPointLabels->SetMapper(myPtsLabeledDataMapper);
322 myPointLabels->GetProperty()->SetColor(1,1,1);
323 myPointLabels->SetVisibility(myIsPointsLabeled);
326 //Definition of cells numbering pipeline
327 //---------------------------------------
328 myCellsNumDataSet = vtkUnstructuredGrid::New();
330 myCellCenters = vtkCellCenters::New();
331 myCellCenters->SetInput(myCellsNumDataSet);
333 myClsMaskPoints = vtkMaskPoints::New();
334 myClsMaskPoints->SetInput(myCellCenters->GetOutput());
335 myClsMaskPoints->SetOnRatio(1);
337 myClsSelectVisiblePoints = vtkSelectVisiblePoints::New();
338 myClsSelectVisiblePoints->SetInput(myClsMaskPoints->GetOutput());
339 myClsSelectVisiblePoints->SelectInvisibleOff();
340 myClsSelectVisiblePoints->SetTolerance(0.1);
342 myClsLabeledDataMapper = vtkLabeledDataMapper::New();
343 myClsLabeledDataMapper->SetInput(myClsSelectVisiblePoints->GetOutput());
344 myClsLabeledDataMapper->SetLabelFormat("%g");
345 myClsLabeledDataMapper->SetLabelModeToLabelScalars();
347 vtkTextProperty* aClsTextProp = vtkTextProperty::New();
348 aClsTextProp->SetFontFamilyToTimes();
349 static int aCellsFontSize = 12;
350 aClsTextProp->SetFontSize(aCellsFontSize);
351 aClsTextProp->SetBold(1);
352 aClsTextProp->SetItalic(0);
353 aClsTextProp->SetShadow(0);
354 myClsLabeledDataMapper->SetLabelTextProperty(aClsTextProp);
355 aClsTextProp->Delete();
357 myIsCellsLabeled = false;
359 myCellsLabels = vtkActor2D::New();
360 myCellsLabels->SetMapper(myClsLabeledDataMapper);
361 myCellsLabels->GetProperty()->SetColor(0,1,0);
362 myCellsLabels->SetVisibility(myIsCellsLabeled);
365 myImplicitBoolean = vtkImplicitBoolean::New();
366 myImplicitBoolean->SetOperationTypeToIntersection();
370 SMESH_ActorDef::~SMESH_ActorDef()
372 if(MYDEBUG) MESSAGE("~SMESH_ActorDef - "<<this);
374 myScalarBarActor->Delete();
375 myLookupTable->Delete();
377 mySurfaceProp->Delete();
378 myBackSurfaceProp->Delete();
380 myEdgeProp->Delete();
381 myHighlightProp->Delete();
382 myPreselectProp->Delete();
384 myNodeProp->Delete();
389 my1DExtProp->Delete();
390 my1DExtActor->Delete();
395 myNodeActor->Delete();
396 myBaseActor->Delete();
398 myHighlitableActor->Delete();
400 //Deleting of pints numbering pipeline
401 //---------------------------------------
402 myPointsNumDataSet->Delete();
404 myPtsLabeledDataMapper->RemoveAllInputs();
405 myPtsLabeledDataMapper->Delete();
407 myPtsSelectVisiblePoints->UnRegisterAllOutputs();
408 myPtsSelectVisiblePoints->Delete();
410 myPtsMaskPoints->UnRegisterAllOutputs();
411 myPtsMaskPoints->Delete();
413 myPointLabels->Delete();
416 //Deleting of cells numbering pipeline
417 //---------------------------------------
418 myCellsNumDataSet->Delete();
420 myClsLabeledDataMapper->RemoveAllInputs();
421 myClsLabeledDataMapper->Delete();
423 myClsSelectVisiblePoints->UnRegisterAllOutputs();
424 myClsSelectVisiblePoints->Delete();
426 myClsMaskPoints->UnRegisterAllOutputs();
427 myClsMaskPoints->Delete();
429 myCellCenters->UnRegisterAllOutputs();
430 myCellCenters->Delete();
432 myCellsLabels->Delete();
434 myImplicitBoolean->Delete();
436 myTimeStamp->Delete();
440 void SMESH_ActorDef::SetPointsLabeled( bool theIsPointsLabeled )
442 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
443 myIsPointsLabeled = theIsPointsLabeled && aGrid->GetNumberOfPoints();
445 if ( myIsPointsLabeled )
447 myPointsNumDataSet->ShallowCopy(aGrid);
448 vtkDataSet *aDataSet = myPointsNumDataSet;
450 int aNbElem = aDataSet->GetNumberOfPoints();
452 vtkIntArray *anArray = vtkIntArray::New();
453 anArray->SetNumberOfValues( aNbElem );
455 for ( int anId = 0; anId < aNbElem; anId++ )
457 int aSMDSId = myVisualObj->GetNodeObjId( anId );
458 anArray->SetValue( anId, aSMDSId );
461 aDataSet->GetPointData()->SetScalars( anArray );
463 myPtsMaskPoints->SetInput( aDataSet );
464 myPointLabels->SetVisibility( GetVisibility() );
468 myPointLabels->SetVisibility( false );
470 SetRepresentation(GetRepresentation());
471 myTimeStamp->Modified();
475 void SMESH_ActorDef::SetCellsLabeled(bool theIsCellsLabeled)
477 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
478 myIsCellsLabeled = theIsCellsLabeled && aGrid->GetNumberOfPoints();
479 if(myIsCellsLabeled){
480 myCellsNumDataSet->ShallowCopy(aGrid);
481 vtkDataSet *aDataSet = myCellsNumDataSet;
482 int aNbElem = aDataSet->GetNumberOfCells();
483 vtkIntArray *anArray = vtkIntArray::New();
484 anArray->SetNumberOfValues(aNbElem);
485 for(int anId = 0; anId < aNbElem; anId++){
486 int aSMDSId = myVisualObj->GetElemObjId(anId);
487 anArray->SetValue(anId,aSMDSId);
489 aDataSet->GetCellData()->SetScalars(anArray);
490 myCellCenters->SetInput(aDataSet);
491 myCellsLabels->SetVisibility(GetVisibility());
493 myCellsLabels->SetVisibility(false);
495 myTimeStamp->Modified();
501 SetControlMode(eControl theMode)
503 SetControlMode(theMode,true);
509 SetControlMode(eControl theMode,
510 bool theCheckEntityMode)
512 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
516 myControlMode = eNone;
517 theCheckEntityMode &= mgr->booleanValue( "SMESH", "display_entity", false );
519 my1DActor->GetMapper()->SetScalarVisibility(false);
520 my2DActor->GetMapper()->SetScalarVisibility(false);
521 my3DActor->GetMapper()->SetScalarVisibility(false);
522 myScalarBarActor->SetVisibility(false);
524 bool anIsScalarVisible = theMode > eNone;
526 if(anIsScalarVisible){
527 SMESH::Controls::FunctorPtr aFunctor;
531 SMESH::Controls::Length* aControl = new SMESH::Controls::Length();
532 aControl->SetPrecision( myControlsPrecision );
533 aFunctor.reset( aControl );
534 myControlActor = my1DActor;
539 aFunctor.reset(new SMESH::Controls::Length2D());
540 myControlActor = my2DActor;
544 aFunctor.reset(new SMESH::Controls::FreeBorders());
545 myControlActor = my1DActor;
548 aFunctor.reset(new SMESH::Controls::FreeEdges());
549 myControlActor = my2DActor;
551 case eMultiConnection:
552 aFunctor.reset(new SMESH::Controls::MultiConnection());
553 myControlActor = my1DActor;
555 case eMultiConnection2D:
556 aFunctor.reset(new SMESH::Controls::MultiConnection2D());
557 myControlActor = my2DActor;
561 SMESH::Controls::Area* aControl = new SMESH::Controls::Area();
562 aControl->SetPrecision( myControlsPrecision );
563 aFunctor.reset( aControl );
564 myControlActor = my2DActor;
569 SMESH::Controls::Taper* aControl = new SMESH::Controls::Taper();
570 aControl->SetPrecision( myControlsPrecision );
571 aFunctor.reset( aControl );
572 myControlActor = my2DActor;
577 SMESH::Controls::AspectRatio* aControl = new SMESH::Controls::AspectRatio();
578 aControl->SetPrecision( myControlsPrecision );
579 aFunctor.reset( aControl );
580 myControlActor = my2DActor;
585 SMESH::Controls::AspectRatio3D* aControl = new SMESH::Controls::AspectRatio3D();
586 aControl->SetPrecision( myControlsPrecision );
587 aFunctor.reset( aControl );
588 myControlActor = my3DActor;
593 SMESH::Controls::Volume* aControl = new SMESH::Controls::Volume();
594 aControl->SetPrecision( myControlsPrecision );
595 aFunctor.reset( aControl );
596 myControlActor = my3DActor;
601 SMESH::Controls::MinimumAngle* aControl = new SMESH::Controls::MinimumAngle();
602 aControl->SetPrecision( myControlsPrecision );
603 aFunctor.reset( aControl );
604 myControlActor = my2DActor;
609 SMESH::Controls::Warping* aControl = new SMESH::Controls::Warping();
610 aControl->SetPrecision( myControlsPrecision );
611 aFunctor.reset( aControl );
612 myControlActor = my2DActor;
617 SMESH::Controls::Skew* aControl = new SMESH::Controls::Skew();
618 aControl->SetPrecision( myControlsPrecision );
619 aFunctor.reset( aControl );
620 myControlActor = my2DActor;
627 vtkUnstructuredGrid* aGrid = myControlActor->GetUnstructuredGrid();
628 vtkIdType aNbCells = aGrid->GetNumberOfCells();
630 myControlMode = theMode;
631 switch(myControlMode){
634 my1DExtActor->SetExtControlMode(aFunctor);
637 case eMultiConnection2D:
638 my1DExtActor->SetExtControlMode(aFunctor,myScalarBarActor,myLookupTable);
641 myControlActor->SetControlMode(aFunctor,myScalarBarActor,myLookupTable);
645 if(theCheckEntityMode){
646 if(myControlActor == my1DActor)
647 SetEntityMode(eEdges);
648 else if(myControlActor == my2DActor){
649 switch(myControlMode){
652 case eMultiConnection2D:
653 //SetEntityMode(eEdges);
654 SetEntityMode(eFaces);
657 SetEntityMode(eFaces);
659 }else if(myControlActor == my3DActor)
660 SetEntityMode(eVolumes);
663 }else if(theCheckEntityMode){
664 myEntityMode = eAllEntity;
667 SetRepresentation(GetRepresentation());
669 myTimeStamp->Modified();
674 void SMESH_ActorDef::AddToRender(vtkRenderer* theRenderer){
675 SALOME_Actor::AddToRender(theRenderer);
677 theRenderer->AddActor(myNodeActor);
678 theRenderer->AddActor(myBaseActor);
680 theRenderer->AddActor(my3DActor);
681 theRenderer->AddActor(my2DActor);
683 theRenderer->AddActor(my1DActor);
684 theRenderer->AddActor(my1DExtActor);
686 theRenderer->AddActor(myHighlitableActor);
688 theRenderer->AddActor2D(myScalarBarActor);
690 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
691 myClsSelectVisiblePoints->SetRenderer(theRenderer);
693 theRenderer->AddActor2D(myPointLabels);
694 theRenderer->AddActor2D(myCellsLabels);
697 void SMESH_ActorDef::RemoveFromRender(vtkRenderer* theRenderer){
698 SALOME_Actor::RemoveFromRender(theRenderer);
700 theRenderer->RemoveActor(myNodeActor);
701 theRenderer->RemoveActor(myBaseActor);
703 theRenderer->RemoveActor(myHighlitableActor);
705 theRenderer->RemoveActor(my1DActor);
706 theRenderer->RemoveActor(my1DExtActor);
708 theRenderer->RemoveActor(my2DActor);
709 theRenderer->RemoveActor(my3DActor);
711 theRenderer->RemoveActor(myScalarBarActor);
712 theRenderer->RemoveActor(myPointLabels);
713 theRenderer->RemoveActor(myCellsLabels);
717 bool SMESH_ActorDef::Init(TVisualObjPtr theVisualObj,
718 const char* theEntry,
722 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry,"SMESH",theName);
726 myVisualObj = theVisualObj;
727 myVisualObj->Update(theIsClear);
729 myNodeActor->Init(myVisualObj,myImplicitBoolean);
730 myBaseActor->Init(myVisualObj,myImplicitBoolean);
732 myHighlitableActor->Init(myVisualObj,myImplicitBoolean);
734 my1DActor->Init(myVisualObj,myImplicitBoolean);
735 my1DExtActor->Init(myVisualObj,myImplicitBoolean);
737 my2DActor->Init(myVisualObj,myImplicitBoolean);
738 my3DActor->Init(myVisualObj,myImplicitBoolean);
740 my1DActor->GetMapper()->SetLookupTable(myLookupTable);
741 my1DExtActor->GetMapper()->SetLookupTable(myLookupTable);
743 my2DActor->GetMapper()->SetLookupTable(myLookupTable);
744 my3DActor->GetMapper()->SetLookupTable(myLookupTable);
746 float aFactor, aUnits;
747 my2DActor->GetPolygonOffsetParameters(aFactor,aUnits);
748 my2DActor->SetPolygonOffsetParameters(aFactor,aUnits*0.75);
750 //SetIsShrunkable(theGrid->GetNumberOfCells() > 10);
751 SetIsShrunkable(true);
753 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
757 int aMode = mgr->integerValue( "SMESH", "display_mode" );
758 SetRepresentation(-1);
761 SetRepresentation(eEdge);
762 }else if(aMode == 1){
763 SetRepresentation(eSurface);
764 }else if(aMode == 2){
765 SetRepresentation(ePoint);
772 myTimeStamp->Modified();
778 float* SMESH_ActorDef::GetBounds(){
779 return myNodeActor->GetBounds();
783 vtkDataSet* SMESH_ActorDef::GetInput(){
784 return GetUnstructuredGrid();
788 void SMESH_ActorDef::SetTransform(VTKViewer_Transform* theTransform){
789 Superclass::SetTransform(theTransform);
791 myNodeActor->SetTransform(theTransform);
792 myBaseActor->SetTransform(theTransform);
794 myHighlitableActor->SetTransform(theTransform);
796 my1DActor->SetTransform(theTransform);
797 my1DExtActor->SetTransform(theTransform);
799 my2DActor->SetTransform(theTransform);
800 my3DActor->SetTransform(theTransform);
806 void SMESH_ActorDef::SetMapper(vtkMapper* theMapper){
807 vtkLODActor::SetMapper(theMapper);
811 void SMESH_ActorDef::ShallowCopy(vtkProp *prop){
812 SALOME_Actor::ShallowCopy(prop);
816 vtkMapper* SMESH_ActorDef::GetMapper(){
817 return myPickableActor->GetMapper();
821 vtkUnstructuredGrid* SMESH_ActorDef::GetUnstructuredGrid(){
822 return myVisualObj->GetUnstructuredGrid();
826 bool SMESH_ActorDef::IsInfinitive(){
827 vtkDataSet *aDataSet = myPickableActor->GetUnstructuredGrid();
829 myIsInfinite = aDataSet->GetNumberOfCells() == 0 ||
830 aDataSet->GetNumberOfCells() == 1 &&
831 aDataSet->GetCell(0)->GetCellType() == VTK_VERTEX;
832 return SALOME_Actor::IsInfinitive();
836 void SMESH_ActorDef::SetIsShrunkable(bool theShrunkable){
837 myIsShrinkable = theShrunkable;
841 float SMESH_ActorDef::GetShrinkFactor(){
842 return myBaseActor->GetShrinkFactor();
845 void SMESH_ActorDef::SetShrinkFactor(float theValue){
846 myBaseActor->SetShrinkFactor(theValue);
848 my1DActor->SetShrinkFactor(theValue);
849 my1DExtActor->SetShrinkFactor(theValue);
851 my2DActor->SetShrinkFactor(theValue);
852 my3DActor->SetShrinkFactor(theValue);
857 void SMESH_ActorDef::SetShrink(){
858 if(!myIsShrinkable) return;
860 myBaseActor->SetShrink();
862 my1DActor->SetShrink();
863 my1DExtActor->SetShrink();
865 my2DActor->SetShrink();
866 my3DActor->SetShrink();
872 void SMESH_ActorDef::UnShrink(){
873 if(!myIsShrunk) return;
875 myBaseActor->UnShrink();
877 my1DActor->UnShrink();
878 my1DExtActor->UnShrink();
880 my2DActor->UnShrink();
881 my3DActor->UnShrink();
888 int SMESH_ActorDef::GetNodeObjId(int theVtkID){
889 return myPickableActor->GetNodeObjId(theVtkID);
892 float* SMESH_ActorDef::GetNodeCoord(int theObjID){
893 return myPickableActor->GetNodeCoord(theObjID);
897 int SMESH_ActorDef::GetElemObjId(int theVtkID){
898 return myPickableActor->GetElemObjId(theVtkID);
901 vtkCell* SMESH_ActorDef::GetElemCell(int theObjID){
902 return myPickableActor->GetElemCell(theObjID);
906 void SMESH_ActorDef::SetVisibility(int theMode){
907 SetVisibility(theMode,true);
911 void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation){
912 SALOME_Actor::SetVisibility(theMode);
914 myNodeActor->VisibilityOff();
915 myBaseActor->VisibilityOff();
917 my1DActor->VisibilityOff();
918 my1DExtActor->VisibilityOff();
920 my2DActor->VisibilityOff();
921 my3DActor->VisibilityOff();
923 myScalarBarActor->VisibilityOff();
924 myPointLabels->VisibilityOff();
925 myCellsLabels->VisibilityOff();
928 if(theIsUpdateRepersentation)
929 SetRepresentation(GetRepresentation());
931 if(myControlMode != eNone){
932 switch(myControlMode){
935 my1DExtActor->VisibilityOn();
938 case eMultiConnection2D:
939 my1DExtActor->VisibilityOn();
941 if(myControlActor->GetUnstructuredGrid()->GetNumberOfCells())
942 myScalarBarActor->VisibilityOn();
946 if(myRepresentation != ePoint)
947 myPickableActor->VisibilityOn();
949 myNodeActor->VisibilityOn();
952 if(myEntityMode & eEdges){
953 my1DActor->VisibilityOn();
956 if(myEntityMode & eFaces){
957 my2DActor->VisibilityOn();
960 if(myEntityMode & eVolumes){
961 my3DActor->VisibilityOn();
964 if(myIsPointsLabeled){
965 myPointLabels->VisibilityOn();
966 myNodeActor->VisibilityOn();
970 myCellsLabels->VisibilityOn();
977 void SMESH_ActorDef::SetEntityMode(unsigned int theMode){
978 myEntityState = eAllEntity;
980 if(!myVisualObj->GetNbEntities(SMDSAbs_Edge)){
981 myEntityState &= ~eEdges;
985 if(!myVisualObj->GetNbEntities(SMDSAbs_Face)){
986 myEntityState &= ~eFaces;
990 if(!myVisualObj->GetNbEntities(SMDSAbs_Volume)){
991 myEntityState &= ~eVolumes;
992 theMode &= ~eVolumes;
996 if(myVisualObj->GetNbEntities(SMDSAbs_Edge))
999 if(myVisualObj->GetNbEntities(SMDSAbs_Face))
1002 if(myVisualObj->GetNbEntities(SMDSAbs_Volume))
1003 theMode |= eVolumes;
1006 myBaseActor->myGeomFilter->SetInside(myEntityMode != myEntityState);
1008 myEntityMode = theMode;
1009 VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
1010 aFilter = myBaseActor->GetExtractUnstructuredGrid();
1011 aFilter->ClearRegisteredCellsWithType();
1012 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
1014 if(myEntityMode & eEdges){
1015 if (MYDEBUG) MESSAGE("EDGES");
1016 aFilter->RegisterCellsWithType(VTK_LINE);
1019 if(myEntityMode & eFaces){
1020 if (MYDEBUG) MESSAGE("FACES");
1021 aFilter->RegisterCellsWithType(VTK_TRIANGLE);
1022 aFilter->RegisterCellsWithType(VTK_POLYGON);
1023 aFilter->RegisterCellsWithType(VTK_QUAD);
1026 if(myEntityMode & eVolumes){
1027 if (MYDEBUG) MESSAGE("VOLUMES");
1028 aFilter->RegisterCellsWithType(VTK_TETRA);
1029 aFilter->RegisterCellsWithType(VTK_VOXEL);
1030 aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1031 aFilter->RegisterCellsWithType(VTK_WEDGE);
1032 aFilter->RegisterCellsWithType(VTK_PYRAMID);
1033 aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1036 if (MYDEBUG) MESSAGE(aFilter->GetOutput()->GetNumberOfCells());
1037 SetVisibility(GetVisibility(),false);
1040 void SMESH_ActorDef::SetRepresentation(int theMode){
1041 int aNbEdges = myVisualObj->GetNbEntities(SMDSAbs_Edge);
1042 int aNbFaces = myVisualObj->GetNbEntities(SMDSAbs_Face);
1043 int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume);
1045 myRepresentation = eSurface;
1046 if(!aNbFaces && !aNbVolumes && aNbEdges){
1047 myRepresentation = eEdge;
1048 }else if(!aNbFaces && !aNbVolumes && !aNbEdges){
1049 myRepresentation = ePoint;
1054 if(!aNbFaces && !aNbVolumes && !aNbEdges) return;
1057 if(!aNbFaces && !aNbVolumes) return;
1060 myRepresentation = theMode;
1063 if(!GetUnstructuredGrid()->GetNumberOfCells())
1064 myRepresentation = ePoint;
1067 if(myRepresentation == ePoint){
1075 myPickableActor = myBaseActor;
1076 myNodeActor->SetVisibility(false);
1077 vtkProperty *aProp = NULL, *aBackProp = NULL;
1078 SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1);
1079 switch(myRepresentation){
1081 myPickableActor = myNodeActor;
1082 myNodeActor->SetVisibility(true);
1084 aProp = aBackProp = myNodeProp;
1085 aReperesent = SMESH_DeviceActor::ePoint;
1088 aProp = aBackProp = myEdgeProp;
1089 aReperesent = SMESH_DeviceActor::eInsideframe;
1092 aProp = mySurfaceProp;
1093 aBackProp = myBackSurfaceProp;
1094 aReperesent = SMESH_DeviceActor::eSurface;
1098 my2DActor->SetProperty(aProp);
1099 my2DActor->SetBackfaceProperty(aBackProp);
1100 my2DActor->SetRepresentation(aReperesent);
1102 my3DActor->SetProperty(aProp);
1103 my3DActor->SetBackfaceProperty(aBackProp);
1104 my3DActor->SetRepresentation(aReperesent);
1106 my1DExtActor->SetVisibility(false);
1108 switch(myControlMode){
1110 case eMultiConnection:
1111 aProp = aBackProp = my1DProp;
1112 if(myRepresentation != ePoint)
1113 aReperesent = SMESH_DeviceActor::eInsideframe;
1117 my1DActor->SetProperty(aProp);
1118 my1DActor->SetBackfaceProperty(aBackProp);
1119 my1DActor->SetRepresentation(aReperesent);
1121 my1DExtActor->SetRepresentation(aReperesent);
1123 if(myIsPointsVisible)
1124 myPickableActor = myNodeActor;
1125 if(GetPointRepresentation())
1126 myNodeActor->SetVisibility(true);
1128 SetMapper(myPickableActor->GetMapper());
1130 SetVisibility(GetVisibility(),false);
1136 void SMESH_ActorDef::SetPointRepresentation(bool theIsPointsVisible){
1137 myIsPointsVisible = theIsPointsVisible;
1138 SetRepresentation(GetRepresentation());
1141 bool SMESH_ActorDef::GetPointRepresentation(){
1142 return myIsPointsVisible || myIsPointsLabeled;
1146 void SMESH_ActorDef::UpdateHighlight(){
1147 myHighlitableActor->SetVisibility(false);
1148 myHighlitableActor->SetHighlited(false);
1150 if(myIsHighlighted){
1151 myHighlitableActor->SetProperty(myHighlightProp);
1152 }else if(myIsPreselected){
1153 myHighlitableActor->SetProperty(myPreselectProp);
1156 bool anIsVisible = GetVisibility();
1158 if(myIsHighlighted || myIsPreselected){
1159 if(GetUnstructuredGrid()->GetNumberOfCells()){
1160 myHighlitableActor->SetHighlited(anIsVisible);
1161 myHighlitableActor->SetVisibility(anIsVisible);
1162 myHighlitableActor->GetExtractUnstructuredGrid()->
1163 SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::eCells);
1164 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
1165 }else if(myRepresentation == ePoint || GetPointRepresentation()){
1166 myHighlitableActor->SetHighlited(anIsVisible);
1167 myHighlitableActor->SetVisibility(anIsVisible);
1168 myHighlitableActor->GetExtractUnstructuredGrid()->
1169 SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
1170 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::ePoint);
1176 void SMESH_ActorDef::highlight(bool theHighlight){
1177 myIsHighlighted = theHighlight;
1182 void SMESH_ActorDef::SetPreSelected(bool thePreselect){
1183 myIsPreselected = thePreselect;
1189 int SMESH_ActorDef::RenderOpaqueGeometry(vtkViewport *vp)
1191 if (myPickableActor->GetIsOpaque())
1193 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1201 int SMESH_ActorDef::RenderTranslucentGeometry(vtkViewport *vp)
1203 if (!myPickableActor->GetIsOpaque())
1205 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1213 void SMESH_ActorDef::Render(vtkRenderer *ren){
1214 unsigned long aTime = myTimeStamp->GetMTime();
1215 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1216 unsigned long aClippingTime = myImplicitBoolean->GetMTime();
1217 if(anObjTime > aTime || aClippingTime > aTime)
1222 void SMESH_ActorDef::Update(){
1223 if(MYDEBUG) MESSAGE("SMESH_ActorDef::Update");
1225 if(GetControlMode() != eNone) {
1226 unsigned long aTime = myTimeStamp->GetMTime();
1227 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1228 if (anObjTime > aTime)
1229 SetControlMode(GetControlMode(),false);
1231 if(myIsPointsLabeled){
1232 SetPointsLabeled(myIsPointsLabeled);
1234 if(myIsCellsLabeled){
1235 SetCellsLabeled(myIsCellsLabeled);
1237 SetEntityMode(GetEntityMode());
1238 SetVisibility(GetVisibility());
1240 myTimeStamp->Modified();
1245 void SMESH_ActorDef::ReleaseGraphicsResources(vtkWindow *renWin){
1246 SALOME_Actor::ReleaseGraphicsResources(renWin);
1248 myPickableActor->ReleaseGraphicsResources(renWin);
1252 static void GetColor(vtkProperty *theProperty, float& r,float& g,float& b){
1253 float* aColor = theProperty->GetColor();
1260 void SMESH_ActorDef::SetOpacity(float theValue){
1261 mySurfaceProp->SetOpacity(theValue);
1262 myBackSurfaceProp->SetOpacity(theValue);
1263 myEdgeProp->SetOpacity(theValue);
1264 myNodeProp->SetOpacity(theValue);
1266 my1DProp->SetOpacity(theValue);
1270 float SMESH_ActorDef::GetOpacity(){
1271 return mySurfaceProp->GetOpacity();
1275 void SMESH_ActorDef::SetSufaceColor(float r,float g,float b){
1276 mySurfaceProp->SetColor(r,g,b);
1280 void SMESH_ActorDef::GetSufaceColor(float& r,float& g,float& b){
1281 ::GetColor(mySurfaceProp,r,g,b);
1284 void SMESH_ActorDef::SetBackSufaceColor(float r,float g,float b){
1285 myBackSurfaceProp->SetColor(r,g,b);
1289 void SMESH_ActorDef::GetBackSufaceColor(float& r,float& g,float& b){
1290 ::GetColor(myBackSurfaceProp,r,g,b);
1293 void SMESH_ActorDef::SetEdgeColor(float r,float g,float b){
1294 myEdgeProp->SetColor(r,g,b);
1295 my1DProp->SetColor(r,g,b);
1296 my1DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1300 void SMESH_ActorDef::GetEdgeColor(float& r,float& g,float& b){
1301 ::GetColor(myEdgeProp,r,g,b);
1304 void SMESH_ActorDef::SetNodeColor(float r,float g,float b){
1305 myNodeProp->SetColor(r,g,b);
1309 void SMESH_ActorDef::GetNodeColor(float& r,float& g,float& b){
1310 ::GetColor(myNodeProp,r,g,b);
1313 void SMESH_ActorDef::SetHighlightColor(float r,float g,float b){
1314 myHighlightProp->SetColor(r,g,b);
1318 void SMESH_ActorDef::GetHighlightColor(float& r,float& g,float& b){
1319 ::GetColor(myHighlightProp,r,g,b);
1322 void SMESH_ActorDef::SetPreHighlightColor(float r,float g,float b){
1323 myPreselectProp->SetColor(r,g,b);
1327 void SMESH_ActorDef::GetPreHighlightColor(float& r,float& g,float& b){
1328 ::GetColor(myPreselectProp,r,g,b);
1332 float SMESH_ActorDef::GetLineWidth(){
1333 return myEdgeProp->GetLineWidth();
1337 void SMESH_ActorDef::SetLineWidth(float theVal){
1338 myEdgeProp->SetLineWidth(theVal);
1340 my1DProp->SetLineWidth(theVal + aLineWidthInc);
1341 my1DExtProp->SetLineWidth(theVal + aLineWidthInc);
1347 void SMESH_ActorDef::SetNodeSize(float theVal){
1348 myNodeProp->SetPointSize(theVal);
1349 myHighlightProp->SetPointSize(theVal);
1350 myPreselectProp->SetPointSize(theVal);
1352 my1DProp->SetPointSize(theVal + aPointSizeInc);
1353 my1DExtProp->SetPointSize(theVal + aPointSizeInc);
1358 float SMESH_ActorDef::GetNodeSize(){
1359 return myNodeProp->GetPointSize();
1362 int SMESH_ActorDef::GetObjDimension( const int theObjId )
1364 return myVisualObj->GetElemDimension( theObjId );
1369 IsImplicitFunctionUsed() const
1371 return myBaseActor->IsImplicitFunctionUsed();
1376 SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
1378 myNodeActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1379 myBaseActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1381 myHighlitableActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1383 my1DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1384 my1DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1386 my2DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1387 my3DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1392 AddClippingPlane(vtkPlane* thePlane)
1395 myImplicitBoolean->GetFunction()->AddItem(thePlane);
1396 myCippingPlaneCont.push_back(thePlane);
1397 if(!IsImplicitFunctionUsed())
1398 SetImplicitFunctionUsed(true);
1400 return myCippingPlaneCont.size();
1405 RemoveAllClippingPlanes()
1407 myImplicitBoolean->GetFunction()->RemoveAllItems();
1408 myImplicitBoolean->GetFunction()->Modified(); // VTK bug
1409 myCippingPlaneCont.clear();
1410 SetImplicitFunctionUsed(false);
1415 GetNumberOfClippingPlanes()
1417 return myCippingPlaneCont.size();
1422 GetClippingPlane(vtkIdType theID)
1424 if(theID >= myCippingPlaneCont.size())
1426 return myCippingPlaneCont[theID].Get();
1430 static void ComputeBoundsParam(vtkDataSet* theDataSet,
1431 float theDirection[3], float theMinPnt[3],
1432 float& theMaxBoundPrj, float& theMinBoundPrj)
1435 theDataSet->GetBounds(aBounds);
1437 //Enlarge bounds in order to avoid conflicts of precision
1438 for(int i = 0; i < 6; i += 2){
1439 static double EPS = 1.0E-3;
1440 float aDelta = (aBounds[i+1] - aBounds[i])*EPS;
1441 aBounds[i] -= aDelta;
1442 aBounds[i+1] += aDelta;
1445 float aBoundPoints[8][3] = { {aBounds[0],aBounds[2],aBounds[4]},
1446 {aBounds[1],aBounds[2],aBounds[4]},
1447 {aBounds[0],aBounds[3],aBounds[4]},
1448 {aBounds[1],aBounds[3],aBounds[4]},
1449 {aBounds[0],aBounds[2],aBounds[5]},
1450 {aBounds[1],aBounds[2],aBounds[5]},
1451 {aBounds[0],aBounds[3],aBounds[5]},
1452 {aBounds[1],aBounds[3],aBounds[5]}};
1454 int aMaxId = 0, aMinId = aMaxId;
1455 theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
1456 theMinBoundPrj = theMaxBoundPrj;
1457 for(int i = 1; i < 8; i++){
1458 float aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
1459 if(theMaxBoundPrj < aTmp){
1460 theMaxBoundPrj = aTmp;
1463 if(theMinBoundPrj > aTmp){
1464 theMinBoundPrj = aTmp;
1468 float *aMinPnt = aBoundPoints[aMaxId];
1469 theMinPnt[0] = aMinPnt[0];
1470 theMinPnt[1] = aMinPnt[1];
1471 theMinPnt[2] = aMinPnt[2];
1475 static void DistanceToPosition(vtkDataSet* theDataSet,
1476 float theDirection[3], float theDist, float thePos[3])
1478 float aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1479 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1480 float aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
1481 thePos[0] = aMinPnt[0]-theDirection[0]*aLength;
1482 thePos[1] = aMinPnt[1]-theDirection[1]*aLength;
1483 thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
1487 static void PositionToDistance(vtkDataSet* theDataSet,
1488 float theDirection[3], float thePos[3], float& theDist)
1490 float aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1491 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1492 float aPrj = vtkMath::Dot(theDirection,thePos);
1493 theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
1497 void SMESH_ActorDef::SetPlaneParam(float theDir[3], float theDist, vtkPlane* thePlane)
1499 thePlane->SetNormal(theDir);
1501 ::DistanceToPosition(GetUnstructuredGrid(),theDir,theDist,anOrigin);
1502 thePlane->SetOrigin(anOrigin);
1506 void SMESH_ActorDef::GetPlaneParam(float theDir[3], float& theDist, vtkPlane* thePlane)
1508 thePlane->GetNormal(theDir);
1511 thePlane->GetOrigin(anOrigin);
1512 ::PositionToDistance(GetUnstructuredGrid(),theDir,anOrigin,theDist);
1515 void SMESH_ActorDef::UpdateScalarBar()
1517 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
1521 vtkTextProperty* aScalarBarTitleProp = vtkTextProperty::New();
1523 QColor aTColor = mgr->colorValue( "SMESH", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
1524 aScalarBarTitleProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1526 aScalarBarTitleProp->SetFontFamilyToArial();
1528 if ( mgr->hasValue( "SMESH", "scalar_bar_title_font" ) )
1530 QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
1531 if ( f.family() == "Arial" )
1532 aScalarBarTitleProp->SetFontFamilyToArial();
1533 else if ( f.family() == "Courier" )
1534 aScalarBarTitleProp->SetFontFamilyToCourier();
1535 else if ( f.family() == "Times" )
1536 aScalarBarTitleProp->SetFontFamilyToTimes();
1539 aScalarBarTitleProp->BoldOn();
1541 aScalarBarTitleProp->BoldOff();
1544 aScalarBarTitleProp->ItalicOn();
1546 aScalarBarTitleProp->ItalicOff();
1548 if ( f.underline() )
1549 aScalarBarTitleProp->ShadowOn();
1551 aScalarBarTitleProp->ShadowOff();
1554 myScalarBarActor->SetTitleTextProperty( aScalarBarTitleProp );
1555 aScalarBarTitleProp->Delete();
1557 vtkTextProperty* aScalarBarLabelProp = vtkTextProperty::New();
1559 aTColor = mgr->colorValue( "SMESH", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
1560 aScalarBarLabelProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1562 aScalarBarLabelProp->SetFontFamilyToArial();
1563 if( mgr->hasValue( "SMESH", "scalar_bar_label_font" ) )
1565 QFont f = mgr->stringValue( "SMESH", "scalar_bar_label_font" );
1566 if( f.family() == "Arial" )
1567 aScalarBarLabelProp->SetFontFamilyToArial();
1568 else if( f.family() == "Courier" )
1569 aScalarBarLabelProp->SetFontFamilyToCourier();
1570 else if( f.family() == "Times" )
1571 aScalarBarLabelProp->SetFontFamilyToTimes();
1574 aScalarBarLabelProp->BoldOn();
1576 aScalarBarLabelProp->BoldOff();
1579 aScalarBarLabelProp->ItalicOn();
1581 aScalarBarLabelProp->ItalicOff();
1584 aScalarBarLabelProp->ShadowOn();
1586 aScalarBarLabelProp->ShadowOff();
1589 myScalarBarActor->SetLabelTextProperty( aScalarBarLabelProp );
1590 aScalarBarLabelProp->Delete();
1592 bool horiz = ( mgr->integerValue( "SMESH", "scalar_bar_orientation" ) == 1 );
1593 QString name = QString( "scalar_bar_%1_" ).arg( horiz ? "horizontal" : "vertical" );
1595 myScalarBarActor->SetOrientationToHorizontal();
1597 myScalarBarActor->SetOrientationToVertical();
1600 float aXVal = horiz ? 0.20 : 0.01;
1601 if( mgr->hasValue( "SMESH", name + "x" ) )
1602 aXVal = mgr->doubleValue( "SMESH", name + "x", aXVal );
1604 float aYVal = horiz ? 0.01 : 0.1;
1605 if( mgr->hasValue( "SMESH", name + "y" ) )
1606 aYVal = mgr->doubleValue( "SMESH", name + "y", aYVal );
1607 myScalarBarActor->SetPosition( aXVal, aYVal );
1609 float aWVal = horiz ? 0.60 : 0.10;
1610 if( mgr->hasValue( "SMESH", name + "width" ) )
1611 aWVal = mgr->doubleValue( "SMESH", name + "width", aWVal );
1612 myScalarBarActor->SetWidth( aWVal );
1614 float aHVal = horiz ? 0.12 : 0.80;
1615 if( mgr->hasValue( "SMESH", name + "height" ) )
1616 aHVal = mgr->doubleValue( "SMESH", name + "height", aHVal );
1617 myScalarBarActor->SetHeight( aHVal );
1620 if( mgr->hasValue( "SMESH", "scalar_bar_num_labels" ) )
1621 anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_labels", anIntVal );
1622 myScalarBarActor->SetNumberOfLabels( anIntVal == 0 ? 5: anIntVal );
1625 if( mgr->hasValue( "SMESH", "scalar_bar_num_colors" ) )
1626 anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_colors", anIntVal );
1627 myScalarBarActor->SetMaximumNumberOfColors( anIntVal == 0 ? 64 : anIntVal );