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 <vtkProperty.h>
42 #include <vtkTimeStamp.h>
43 #include <vtkObjectFactory.h>
44 #include <vtkShrinkPolyData.h>
45 #include <vtkMergeFilter.h>
47 #include <vtkMatrix4x4.h>
48 #include <vtkUnstructuredGrid.h>
49 #include <vtkPointData.h>
50 #include <vtkCellData.h>
52 #include <vtkMapper.h>
53 #include <vtkRenderer.h>
56 #include <vtkIdList.h>
57 #include <vtkIntArray.h>
59 #include <vtkActor2D.h>
60 #include <vtkProperty2D.h>
61 #include <vtkPolyData.h>
62 #include <vtkMaskPoints.h>
63 #include <vtkCellCenters.h>
64 #include <vtkTextProperty.h>
65 #include <vtkLabeledDataMapper.h>
66 #include <vtkSelectVisiblePoints.h>
68 #include <vtkScalarBarActor.h>
69 #include <vtkLookupTable.h>
73 #include <vtkImplicitBoolean.h>
74 #include <vtkImplicitFunctionCollection.h>
76 #include "utilities.h"
79 static int MYDEBUG = 1;
81 static int MYDEBUG = 0;
84 static int aLineWidthInc = 2;
85 static int aPointSizeInc = 2;
88 SMESH_ActorDef* SMESH_ActorDef::New(){
89 return new SMESH_ActorDef();
93 SMESH_Actor* SMESH_Actor::New(TVisualObjPtr theVisualObj,
98 SMESH_ActorDef* anActor = SMESH_ActorDef::New();
99 if(!anActor->Init(theVisualObj,theEntry,theName,theIsClear)){
104 anActor->UpdateScalarBar();
109 SMESH_ActorDef::SMESH_ActorDef()
111 if(MYDEBUG) MESSAGE("SMESH_ActorDef - "<<this);
113 myTimeStamp = vtkTimeStamp::New();
115 myIsPointsVisible = false;
117 myIsShrinkable = false;
120 myControlsPrecision = -1;
121 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
122 if ( mgr && mgr->booleanValue( "SMESH", "use_precision", false ) )
123 myControlsPrecision = (long)SMESH::GetFloat( "SMESH", "controls_precision", -1 );
125 float aPointSize = SMESH::GetFloat("SMESH:node_size",3);
126 float aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
128 vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
129 VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
131 //Definition 2D and 3D divices of the actor
132 //-----------------------------------------
133 float anRGB[3] = {1,1,1};
134 mySurfaceProp = vtkProperty::New();
135 SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
136 mySurfaceProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
138 myBackSurfaceProp = vtkProperty::New();
139 SMESH::GetColor( "SMESH", "backface_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 0, 255 ) );
140 myBackSurfaceProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
142 my2DActor = SMESH_DeviceActor::New();
143 my2DActor->SetUserMatrix(aMatrix);
144 my2DActor->PickableOff();
145 my2DActor->SetProperty(mySurfaceProp);
146 my2DActor->SetBackfaceProperty(myBackSurfaceProp);
147 my2DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
148 aFilter = my2DActor->GetExtractUnstructuredGrid();
149 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
150 aFilter->RegisterCellsWithType(VTK_TRIANGLE);
151 aFilter->RegisterCellsWithType(VTK_POLYGON);
152 aFilter->RegisterCellsWithType(VTK_QUAD);
154 my3DActor = SMESH_DeviceActor::New();
155 my3DActor->SetUserMatrix(aMatrix);
156 my3DActor->PickableOff();
157 my3DActor->SetProperty(mySurfaceProp);
158 my3DActor->SetBackfaceProperty(myBackSurfaceProp);
159 my3DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
160 aFilter = my3DActor->GetExtractUnstructuredGrid();
161 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
162 aFilter->RegisterCellsWithType(VTK_TETRA);
163 aFilter->RegisterCellsWithType(VTK_VOXEL);
164 aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
165 aFilter->RegisterCellsWithType(VTK_WEDGE);
166 aFilter->RegisterCellsWithType(VTK_PYRAMID);
167 aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
169 //Definition 1D divice of the actor
170 //---------------------------------
171 myEdgeProp = vtkProperty::New();
172 myEdgeProp->SetAmbient(1.0);
173 myEdgeProp->SetDiffuse(0.0);
174 myEdgeProp->SetSpecular(0.0);
175 SMESH::GetColor( "SMESH", "outline_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
176 myEdgeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
177 myEdgeProp->SetLineWidth(aLineWidth);
179 my1DActor = SMESH_DeviceActor::New();
180 my1DActor->SetUserMatrix(aMatrix);
181 my1DActor->PickableOff();
182 my1DActor->SetHighlited(true);
183 my1DActor->SetProperty(myEdgeProp);
184 my1DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
185 aFilter = my1DActor->GetExtractUnstructuredGrid();
186 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
187 aFilter->RegisterCellsWithType(VTK_LINE);
189 my1DProp = vtkProperty::New();
190 my1DProp->DeepCopy(myEdgeProp);
191 my1DProp->SetLineWidth(aLineWidth + aLineWidthInc);
192 my1DProp->SetPointSize(aPointSize);
194 my1DExtProp = vtkProperty::New();
195 my1DExtProp->DeepCopy(myEdgeProp);
196 anRGB[0] = 1 - anRGB[0];
197 anRGB[1] = 1 - anRGB[1];
198 anRGB[2] = 1 - anRGB[2];
199 my1DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
200 my1DExtProp->SetLineWidth(aLineWidth + aLineWidthInc);
201 my1DExtProp->SetPointSize(aPointSize + aPointSizeInc);
203 my1DExtActor = SMESH_DeviceActor::New();
204 my1DExtActor->SetUserMatrix(aMatrix);
205 my1DExtActor->PickableOff();
206 my1DExtActor->SetHighlited(true);
207 my1DExtActor->SetVisibility(false);
208 my1DExtActor->SetProperty(my1DExtProp);
209 my1DExtActor->SetRepresentation(SMESH_DeviceActor::eInsideframe);
210 aFilter = my1DExtActor->GetExtractUnstructuredGrid();
211 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
212 aFilter->RegisterCellsWithType(VTK_LINE);
215 //Definition 0D divice of the actor
216 //---------------------------------
217 myNodeProp = vtkProperty::New();
218 SMESH::GetColor( "SMESH", "node_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 0, 0 ) );
219 myNodeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
220 myNodeProp->SetPointSize(aPointSize);
222 myNodeActor = SMESH_DeviceActor::New();
223 myNodeActor->SetUserMatrix(aMatrix);
224 myNodeActor->SetStoreClippingMapping(true);
225 myNodeActor->PickableOff();
226 myNodeActor->SetVisibility(false);
227 myNodeActor->SetProperty(myNodeProp);
228 myNodeActor->SetRepresentation(SMESH_DeviceActor::ePoint);
229 aFilter = myNodeActor->GetExtractUnstructuredGrid();
230 aFilter->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
233 //Definition of Pickable and Highlitable engines
234 //----------------------------------------------
236 myBaseActor = SMESH_DeviceActor::New();
237 myBaseActor->SetUserMatrix(aMatrix);
238 myBaseActor->SetStoreGemetryMapping(true);
239 myBaseActor->GetProperty()->SetOpacity(0.0);
241 myPickableActor = myBaseActor;
243 myHighlightProp = vtkProperty::New();
244 myHighlightProp->SetAmbient(1.0);
245 myHighlightProp->SetDiffuse(0.0);
246 myHighlightProp->SetSpecular(0.0);
247 SMESH::GetColor( "SMESH", "selection_object_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
248 myHighlightProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
249 myHighlightProp->SetPointSize(aPointSize);
250 myHighlightProp->SetRepresentation(1);
252 myPreselectProp = vtkProperty::New();
253 myPreselectProp->SetAmbient(1.0);
254 myPreselectProp->SetDiffuse(0.0);
255 myPreselectProp->SetSpecular(0.0);
256 SMESH::GetColor( "SMESH", "highlight_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 255, 255 ) );
257 myPreselectProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
258 myPreselectProp->SetPointSize(aPointSize);
259 myPreselectProp->SetRepresentation(1);
261 myHighlitableActor = SMESH_DeviceActor::New();
262 myHighlitableActor->SetUserMatrix(aMatrix);
263 myHighlitableActor->PickableOff();
264 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
266 SetShrinkFactor( SMESH::GetFloat( "SMESH:shrink_coeff", 0.75 ) );
271 myControlMode = eNone;
272 myControlActor = my2DActor;
274 //Definition of myScalarBarActor
275 //------------------------------
276 myLookupTable = vtkLookupTable::New();
277 //Fix for Bug PAL5195 - SMESH764:
278 //Controls - Aspect Ratio: incorrect colors of the best and worst values
279 myLookupTable->SetHueRange(0.667,0.0);
281 myScalarBarActor = vtkScalarBarActor::New();
282 myScalarBarActor->SetVisibility(false);
283 myScalarBarActor->SetLookupTable(myLookupTable);
285 mgr = SUIT_Session::session()->resourceMgr();
289 //Definition of points numbering pipeline
290 //---------------------------------------
291 myPointsNumDataSet = vtkUnstructuredGrid::New();
293 myPtsMaskPoints = vtkMaskPoints::New();
294 myPtsMaskPoints->SetInput(myPointsNumDataSet);
295 myPtsMaskPoints->SetOnRatio(1);
297 myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
298 myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
299 myPtsSelectVisiblePoints->SelectInvisibleOff();
300 myPtsSelectVisiblePoints->SetTolerance(0.1);
302 myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
303 myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
304 myPtsLabeledDataMapper->SetLabelFormat("%g");
305 myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
307 vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
308 aPtsTextProp->SetFontFamilyToTimes();
309 static int aPointsFontSize = 10;
310 aPtsTextProp->SetFontSize(aPointsFontSize);
311 aPtsTextProp->SetBold(1);
312 aPtsTextProp->SetItalic(0);
313 aPtsTextProp->SetShadow(0);
314 myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
315 aPtsTextProp->Delete();
317 myEntityMode = eAllEntity;
319 myIsPointsLabeled = false;
321 myPointLabels = vtkActor2D::New();
322 myPointLabels->SetMapper(myPtsLabeledDataMapper);
323 myPointLabels->GetProperty()->SetColor(1,1,1);
324 myPointLabels->SetVisibility(myIsPointsLabeled);
327 //Definition of cells numbering pipeline
328 //---------------------------------------
329 myCellsNumDataSet = vtkUnstructuredGrid::New();
331 myCellCenters = vtkCellCenters::New();
332 myCellCenters->SetInput(myCellsNumDataSet);
334 myClsMaskPoints = vtkMaskPoints::New();
335 myClsMaskPoints->SetInput(myCellCenters->GetOutput());
336 myClsMaskPoints->SetOnRatio(1);
338 myClsSelectVisiblePoints = vtkSelectVisiblePoints::New();
339 myClsSelectVisiblePoints->SetInput(myClsMaskPoints->GetOutput());
340 myClsSelectVisiblePoints->SelectInvisibleOff();
341 myClsSelectVisiblePoints->SetTolerance(0.1);
343 myClsLabeledDataMapper = vtkLabeledDataMapper::New();
344 myClsLabeledDataMapper->SetInput(myClsSelectVisiblePoints->GetOutput());
345 myClsLabeledDataMapper->SetLabelFormat("%g");
346 myClsLabeledDataMapper->SetLabelModeToLabelScalars();
348 vtkTextProperty* aClsTextProp = vtkTextProperty::New();
349 aClsTextProp->SetFontFamilyToTimes();
350 static int aCellsFontSize = 12;
351 aClsTextProp->SetFontSize(aCellsFontSize);
352 aClsTextProp->SetBold(1);
353 aClsTextProp->SetItalic(0);
354 aClsTextProp->SetShadow(0);
355 myClsLabeledDataMapper->SetLabelTextProperty(aClsTextProp);
356 aClsTextProp->Delete();
358 myIsCellsLabeled = false;
360 myCellsLabels = vtkActor2D::New();
361 myCellsLabels->SetMapper(myClsLabeledDataMapper);
362 myCellsLabels->GetProperty()->SetColor(0,1,0);
363 myCellsLabels->SetVisibility(myIsCellsLabeled);
366 myImplicitBoolean = vtkImplicitBoolean::New();
367 myImplicitBoolean->SetOperationTypeToIntersection();
371 SMESH_ActorDef::~SMESH_ActorDef()
373 if(MYDEBUG) MESSAGE("~SMESH_ActorDef - "<<this);
375 myScalarBarActor->Delete();
376 myLookupTable->Delete();
378 mySurfaceProp->Delete();
379 myBackSurfaceProp->Delete();
381 myEdgeProp->Delete();
382 myHighlightProp->Delete();
383 myPreselectProp->Delete();
385 myNodeProp->Delete();
390 my1DExtProp->Delete();
391 my1DExtActor->Delete();
396 myNodeActor->Delete();
397 myBaseActor->Delete();
399 myHighlitableActor->Delete();
401 //Deleting of pints numbering pipeline
402 //---------------------------------------
403 myPointsNumDataSet->Delete();
405 myPtsLabeledDataMapper->RemoveAllInputs();
406 myPtsLabeledDataMapper->Delete();
408 myPtsSelectVisiblePoints->UnRegisterAllOutputs();
409 myPtsSelectVisiblePoints->Delete();
411 myPtsMaskPoints->UnRegisterAllOutputs();
412 myPtsMaskPoints->Delete();
414 myPointLabels->Delete();
417 //Deleting of cells numbering pipeline
418 //---------------------------------------
419 myCellsNumDataSet->Delete();
421 myClsLabeledDataMapper->RemoveAllInputs();
422 myClsLabeledDataMapper->Delete();
424 myClsSelectVisiblePoints->UnRegisterAllOutputs();
425 myClsSelectVisiblePoints->Delete();
427 myClsMaskPoints->UnRegisterAllOutputs();
428 myClsMaskPoints->Delete();
430 myCellCenters->UnRegisterAllOutputs();
431 myCellCenters->Delete();
433 myCellsLabels->Delete();
435 myImplicitBoolean->Delete();
437 myTimeStamp->Delete();
441 void SMESH_ActorDef::SetPointsLabeled( bool theIsPointsLabeled )
443 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
444 myIsPointsLabeled = theIsPointsLabeled && aGrid->GetNumberOfPoints();
446 if ( myIsPointsLabeled )
448 myPointsNumDataSet->ShallowCopy(aGrid);
449 vtkDataSet *aDataSet = myPointsNumDataSet;
451 int aNbElem = aDataSet->GetNumberOfPoints();
453 vtkIntArray *anArray = vtkIntArray::New();
454 anArray->SetNumberOfValues( aNbElem );
456 for ( int anId = 0; anId < aNbElem; anId++ )
458 int aSMDSId = myVisualObj->GetNodeObjId( anId );
459 anArray->SetValue( anId, aSMDSId );
462 aDataSet->GetPointData()->SetScalars( anArray );
464 myPtsMaskPoints->SetInput( aDataSet );
465 myPointLabels->SetVisibility( GetVisibility() );
469 myPointLabels->SetVisibility( false );
471 SetRepresentation(GetRepresentation());
472 myTimeStamp->Modified();
476 void SMESH_ActorDef::SetCellsLabeled(bool theIsCellsLabeled)
478 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
479 myIsCellsLabeled = theIsCellsLabeled && aGrid->GetNumberOfPoints();
480 if(myIsCellsLabeled){
481 myCellsNumDataSet->ShallowCopy(aGrid);
482 vtkDataSet *aDataSet = myCellsNumDataSet;
483 int aNbElem = aDataSet->GetNumberOfCells();
484 vtkIntArray *anArray = vtkIntArray::New();
485 anArray->SetNumberOfValues(aNbElem);
486 for(int anId = 0; anId < aNbElem; anId++){
487 int aSMDSId = myVisualObj->GetElemObjId(anId);
488 anArray->SetValue(anId,aSMDSId);
490 aDataSet->GetCellData()->SetScalars(anArray);
491 myCellCenters->SetInput(aDataSet);
492 myCellsLabels->SetVisibility(GetVisibility());
494 myCellsLabels->SetVisibility(false);
496 myTimeStamp->Modified();
502 SetControlMode(eControl theMode)
504 SetControlMode(theMode,true);
510 SetControlMode(eControl theMode,
511 bool theCheckEntityMode)
513 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
517 myControlMode = eNone;
518 theCheckEntityMode &= mgr->booleanValue( "SMESH", "display_entity", false );
520 my1DActor->GetMapper()->SetScalarVisibility(false);
521 my2DActor->GetMapper()->SetScalarVisibility(false);
522 my3DActor->GetMapper()->SetScalarVisibility(false);
523 myScalarBarActor->SetVisibility(false);
525 bool anIsScalarVisible = theMode > eNone;
527 if(anIsScalarVisible){
528 SMESH::Controls::FunctorPtr aFunctor;
532 SMESH::Controls::Length* aControl = new SMESH::Controls::Length();
533 aControl->SetPrecision( myControlsPrecision );
534 aFunctor.reset( aControl );
535 myControlActor = my1DActor;
540 aFunctor.reset(new SMESH::Controls::Length2D());
541 myControlActor = my2DActor;
545 aFunctor.reset(new SMESH::Controls::FreeBorders());
546 myControlActor = my1DActor;
549 aFunctor.reset(new SMESH::Controls::FreeEdges());
550 myControlActor = my2DActor;
552 case eMultiConnection:
553 aFunctor.reset(new SMESH::Controls::MultiConnection());
554 myControlActor = my1DActor;
556 case eMultiConnection2D:
557 aFunctor.reset(new SMESH::Controls::MultiConnection2D());
558 myControlActor = my2DActor;
562 SMESH::Controls::Area* aControl = new SMESH::Controls::Area();
563 aControl->SetPrecision( myControlsPrecision );
564 aFunctor.reset( aControl );
565 myControlActor = my2DActor;
570 SMESH::Controls::Taper* aControl = new SMESH::Controls::Taper();
571 aControl->SetPrecision( myControlsPrecision );
572 aFunctor.reset( aControl );
573 myControlActor = my2DActor;
578 SMESH::Controls::AspectRatio* aControl = new SMESH::Controls::AspectRatio();
579 aControl->SetPrecision( myControlsPrecision );
580 aFunctor.reset( aControl );
581 myControlActor = my2DActor;
586 SMESH::Controls::AspectRatio3D* aControl = new SMESH::Controls::AspectRatio3D();
587 aControl->SetPrecision( myControlsPrecision );
588 aFunctor.reset( aControl );
589 myControlActor = my3DActor;
594 SMESH::Controls::Volume* aControl = new SMESH::Controls::Volume();
595 aControl->SetPrecision( myControlsPrecision );
596 aFunctor.reset( aControl );
597 myControlActor = my3DActor;
602 SMESH::Controls::MinimumAngle* aControl = new SMESH::Controls::MinimumAngle();
603 aControl->SetPrecision( myControlsPrecision );
604 aFunctor.reset( aControl );
605 myControlActor = my2DActor;
610 SMESH::Controls::Warping* aControl = new SMESH::Controls::Warping();
611 aControl->SetPrecision( myControlsPrecision );
612 aFunctor.reset( aControl );
613 myControlActor = my2DActor;
618 SMESH::Controls::Skew* aControl = new SMESH::Controls::Skew();
619 aControl->SetPrecision( myControlsPrecision );
620 aFunctor.reset( aControl );
621 myControlActor = my2DActor;
628 vtkUnstructuredGrid* aGrid = myControlActor->GetUnstructuredGrid();
629 vtkIdType aNbCells = aGrid->GetNumberOfCells();
631 myControlMode = theMode;
632 switch(myControlMode){
635 my1DExtActor->SetExtControlMode(aFunctor);
638 case eMultiConnection2D:
639 my1DExtActor->SetExtControlMode(aFunctor,myScalarBarActor,myLookupTable);
642 myControlActor->SetControlMode(aFunctor,myScalarBarActor,myLookupTable);
646 if(theCheckEntityMode){
647 if(myControlActor == my1DActor)
648 SetEntityMode(eEdges);
649 else if(myControlActor == my2DActor){
650 switch(myControlMode){
653 case eMultiConnection2D:
654 //SetEntityMode(eEdges);
655 SetEntityMode(eFaces);
658 SetEntityMode(eFaces);
660 }else if(myControlActor == my3DActor)
661 SetEntityMode(eVolumes);
664 }else if(theCheckEntityMode){
665 myEntityMode = eAllEntity;
668 SetRepresentation(GetRepresentation());
670 myTimeStamp->Modified();
675 void SMESH_ActorDef::AddToRender(vtkRenderer* theRenderer){
676 SALOME_Actor::AddToRender(theRenderer);
678 theRenderer->AddActor(myNodeActor);
679 theRenderer->AddActor(myBaseActor);
681 theRenderer->AddActor(my3DActor);
682 theRenderer->AddActor(my2DActor);
684 theRenderer->AddActor(my1DActor);
685 theRenderer->AddActor(my1DExtActor);
687 theRenderer->AddActor(myHighlitableActor);
689 theRenderer->AddActor2D(myScalarBarActor);
691 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
692 myClsSelectVisiblePoints->SetRenderer(theRenderer);
694 theRenderer->AddActor2D(myPointLabels);
695 theRenderer->AddActor2D(myCellsLabels);
698 void SMESH_ActorDef::RemoveFromRender(vtkRenderer* theRenderer){
699 SALOME_Actor::RemoveFromRender(theRenderer);
701 theRenderer->RemoveActor(myNodeActor);
702 theRenderer->RemoveActor(myBaseActor);
704 theRenderer->RemoveActor(myHighlitableActor);
706 theRenderer->RemoveActor(my1DActor);
707 theRenderer->RemoveActor(my1DExtActor);
709 theRenderer->RemoveActor(my2DActor);
710 theRenderer->RemoveActor(my3DActor);
712 theRenderer->RemoveActor(myScalarBarActor);
713 theRenderer->RemoveActor(myPointLabels);
714 theRenderer->RemoveActor(myCellsLabels);
718 bool SMESH_ActorDef::Init(TVisualObjPtr theVisualObj,
719 const char* theEntry,
723 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry,"SMESH",theName);
727 myVisualObj = theVisualObj;
728 myVisualObj->Update(theIsClear);
730 myNodeActor->Init(myVisualObj,myImplicitBoolean);
731 myBaseActor->Init(myVisualObj,myImplicitBoolean);
733 myHighlitableActor->Init(myVisualObj,myImplicitBoolean);
735 my1DActor->Init(myVisualObj,myImplicitBoolean);
736 my1DExtActor->Init(myVisualObj,myImplicitBoolean);
738 my2DActor->Init(myVisualObj,myImplicitBoolean);
739 my3DActor->Init(myVisualObj,myImplicitBoolean);
741 my1DActor->GetMapper()->SetLookupTable(myLookupTable);
742 my1DExtActor->GetMapper()->SetLookupTable(myLookupTable);
744 my2DActor->GetMapper()->SetLookupTable(myLookupTable);
745 my3DActor->GetMapper()->SetLookupTable(myLookupTable);
747 float aFactor, aUnits;
748 my2DActor->GetPolygonOffsetParameters(aFactor,aUnits);
749 my2DActor->SetPolygonOffsetParameters(aFactor,aUnits*0.75);
751 //SetIsShrunkable(theGrid->GetNumberOfCells() > 10);
752 SetIsShrunkable(true);
754 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
758 int aMode = mgr->integerValue( "SMESH", "display_mode" );
759 SetRepresentation(-1);
762 SetRepresentation(eEdge);
763 }else if(aMode == 1){
764 SetRepresentation(eSurface);
765 }else if(aMode == 2){
766 SetRepresentation(ePoint);
773 myTimeStamp->Modified();
779 float* SMESH_ActorDef::GetBounds(){
780 return myNodeActor->GetBounds();
784 vtkDataSet* SMESH_ActorDef::GetInput(){
785 return GetUnstructuredGrid();
789 void SMESH_ActorDef::SetTransform(VTKViewer_Transform* theTransform){
790 Superclass::SetTransform(theTransform);
792 myNodeActor->SetTransform(theTransform);
793 myBaseActor->SetTransform(theTransform);
795 myHighlitableActor->SetTransform(theTransform);
797 my1DActor->SetTransform(theTransform);
798 my1DExtActor->SetTransform(theTransform);
800 my2DActor->SetTransform(theTransform);
801 my3DActor->SetTransform(theTransform);
807 void SMESH_ActorDef::SetMapper(vtkMapper* theMapper){
808 vtkLODActor::SetMapper(theMapper);
812 void SMESH_ActorDef::ShallowCopy(vtkProp *prop){
813 SALOME_Actor::ShallowCopy(prop);
817 vtkMapper* SMESH_ActorDef::GetMapper(){
818 return myPickableActor->GetMapper();
822 vtkUnstructuredGrid* SMESH_ActorDef::GetUnstructuredGrid(){
823 return myVisualObj->GetUnstructuredGrid();
827 bool SMESH_ActorDef::IsInfinitive(){
828 vtkDataSet *aDataSet = myPickableActor->GetUnstructuredGrid();
830 myIsInfinite = aDataSet->GetNumberOfCells() == 0 ||
831 aDataSet->GetNumberOfCells() == 1 &&
832 aDataSet->GetCell(0)->GetCellType() == VTK_VERTEX;
833 return SALOME_Actor::IsInfinitive();
837 void SMESH_ActorDef::SetIsShrunkable(bool theShrunkable){
838 myIsShrinkable = theShrunkable;
842 float SMESH_ActorDef::GetShrinkFactor(){
843 return myBaseActor->GetShrinkFactor();
846 void SMESH_ActorDef::SetShrinkFactor(float theValue){
847 myBaseActor->SetShrinkFactor(theValue);
849 my1DActor->SetShrinkFactor(theValue);
850 my1DExtActor->SetShrinkFactor(theValue);
852 my2DActor->SetShrinkFactor(theValue);
853 my3DActor->SetShrinkFactor(theValue);
858 void SMESH_ActorDef::SetShrink(){
859 if(!myIsShrinkable) return;
861 myBaseActor->SetShrink();
863 my1DActor->SetShrink();
864 my1DExtActor->SetShrink();
866 my2DActor->SetShrink();
867 my3DActor->SetShrink();
873 void SMESH_ActorDef::UnShrink(){
874 if(!myIsShrunk) return;
876 myBaseActor->UnShrink();
878 my1DActor->UnShrink();
879 my1DExtActor->UnShrink();
881 my2DActor->UnShrink();
882 my3DActor->UnShrink();
889 int SMESH_ActorDef::GetNodeObjId(int theVtkID){
890 return myPickableActor->GetNodeObjId(theVtkID);
893 float* SMESH_ActorDef::GetNodeCoord(int theObjID){
894 return myPickableActor->GetNodeCoord(theObjID);
898 int SMESH_ActorDef::GetElemObjId(int theVtkID){
899 return myPickableActor->GetElemObjId(theVtkID);
902 vtkCell* SMESH_ActorDef::GetElemCell(int theObjID){
903 return myPickableActor->GetElemCell(theObjID);
907 void SMESH_ActorDef::SetVisibility(int theMode){
908 SetVisibility(theMode,true);
912 void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation){
913 SALOME_Actor::SetVisibility(theMode);
915 myNodeActor->VisibilityOff();
916 myBaseActor->VisibilityOff();
918 my1DActor->VisibilityOff();
919 my1DExtActor->VisibilityOff();
921 my2DActor->VisibilityOff();
922 my3DActor->VisibilityOff();
924 myScalarBarActor->VisibilityOff();
925 myPointLabels->VisibilityOff();
926 myCellsLabels->VisibilityOff();
929 if(theIsUpdateRepersentation)
930 SetRepresentation(GetRepresentation());
932 if(myControlMode != eNone){
933 switch(myControlMode){
936 my1DExtActor->VisibilityOn();
939 case eMultiConnection2D:
940 my1DExtActor->VisibilityOn();
942 if(myControlActor->GetUnstructuredGrid()->GetNumberOfCells())
943 myScalarBarActor->VisibilityOn();
947 if(myRepresentation != ePoint)
948 myPickableActor->VisibilityOn();
950 myNodeActor->VisibilityOn();
953 if(myEntityMode & eEdges){
954 my1DActor->VisibilityOn();
957 if(myEntityMode & eFaces){
958 my2DActor->VisibilityOn();
961 if(myEntityMode & eVolumes){
962 my3DActor->VisibilityOn();
965 if(myIsPointsLabeled){
966 myPointLabels->VisibilityOn();
967 myNodeActor->VisibilityOn();
971 myCellsLabels->VisibilityOn();
978 void SMESH_ActorDef::SetEntityMode(unsigned int theMode){
979 myEntityState = eAllEntity;
981 if(!myVisualObj->GetNbEntities(SMDSAbs_Edge)){
982 myEntityState &= ~eEdges;
986 if(!myVisualObj->GetNbEntities(SMDSAbs_Face)){
987 myEntityState &= ~eFaces;
991 if(!myVisualObj->GetNbEntities(SMDSAbs_Volume)){
992 myEntityState &= ~eVolumes;
993 theMode &= ~eVolumes;
997 if(myVisualObj->GetNbEntities(SMDSAbs_Edge))
1000 if(myVisualObj->GetNbEntities(SMDSAbs_Face))
1003 if(myVisualObj->GetNbEntities(SMDSAbs_Volume))
1004 theMode |= eVolumes;
1007 myBaseActor->myGeomFilter->SetInside(myEntityMode != myEntityState);
1009 myEntityMode = theMode;
1010 VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
1011 aFilter = myBaseActor->GetExtractUnstructuredGrid();
1012 aFilter->ClearRegisteredCellsWithType();
1013 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
1015 if(myEntityMode & eEdges){
1016 if (MYDEBUG) MESSAGE("EDGES");
1017 aFilter->RegisterCellsWithType(VTK_LINE);
1020 if(myEntityMode & eFaces){
1021 if (MYDEBUG) MESSAGE("FACES");
1022 aFilter->RegisterCellsWithType(VTK_TRIANGLE);
1023 aFilter->RegisterCellsWithType(VTK_POLYGON);
1024 aFilter->RegisterCellsWithType(VTK_QUAD);
1027 if(myEntityMode & eVolumes){
1028 if (MYDEBUG) MESSAGE("VOLUMES");
1029 aFilter->RegisterCellsWithType(VTK_TETRA);
1030 aFilter->RegisterCellsWithType(VTK_VOXEL);
1031 aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1032 aFilter->RegisterCellsWithType(VTK_WEDGE);
1033 aFilter->RegisterCellsWithType(VTK_PYRAMID);
1034 aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1037 if (MYDEBUG) MESSAGE(aFilter->GetOutput()->GetNumberOfCells());
1038 SetVisibility(GetVisibility(),false);
1041 void SMESH_ActorDef::SetRepresentation(int theMode){
1042 int aNbEdges = myVisualObj->GetNbEntities(SMDSAbs_Edge);
1043 int aNbFaces = myVisualObj->GetNbEntities(SMDSAbs_Face);
1044 int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume);
1046 myRepresentation = eSurface;
1047 if(!aNbFaces && !aNbVolumes && aNbEdges){
1048 myRepresentation = eEdge;
1049 }else if(!aNbFaces && !aNbVolumes && !aNbEdges){
1050 myRepresentation = ePoint;
1055 if(!aNbFaces && !aNbVolumes && !aNbEdges) return;
1058 if(!aNbFaces && !aNbVolumes) return;
1061 myRepresentation = theMode;
1064 if(!GetUnstructuredGrid()->GetNumberOfCells())
1065 myRepresentation = ePoint;
1068 if(myRepresentation == ePoint){
1076 myPickableActor = myBaseActor;
1077 myNodeActor->SetVisibility(false);
1078 vtkProperty *aProp = NULL, *aBackProp = NULL;
1079 SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1);
1080 switch(myRepresentation){
1082 myPickableActor = myNodeActor;
1083 myNodeActor->SetVisibility(true);
1085 aProp = aBackProp = myNodeProp;
1086 aReperesent = SMESH_DeviceActor::ePoint;
1089 aProp = aBackProp = myEdgeProp;
1090 aReperesent = SMESH_DeviceActor::eInsideframe;
1093 aProp = mySurfaceProp;
1094 aBackProp = myBackSurfaceProp;
1095 aReperesent = SMESH_DeviceActor::eSurface;
1099 my2DActor->SetProperty(aProp);
1100 my2DActor->SetBackfaceProperty(aBackProp);
1101 my2DActor->SetRepresentation(aReperesent);
1103 my3DActor->SetProperty(aProp);
1104 my3DActor->SetBackfaceProperty(aBackProp);
1105 my3DActor->SetRepresentation(aReperesent);
1107 my1DExtActor->SetVisibility(false);
1109 switch(myControlMode){
1111 case eMultiConnection:
1112 aProp = aBackProp = my1DProp;
1113 if(myRepresentation != ePoint)
1114 aReperesent = SMESH_DeviceActor::eInsideframe;
1118 my1DActor->SetProperty(aProp);
1119 my1DActor->SetBackfaceProperty(aBackProp);
1120 my1DActor->SetRepresentation(aReperesent);
1122 my1DExtActor->SetRepresentation(aReperesent);
1124 if(myIsPointsVisible)
1125 myPickableActor = myNodeActor;
1126 if(GetPointRepresentation())
1127 myNodeActor->SetVisibility(true);
1129 SetMapper(myPickableActor->GetMapper());
1131 SetVisibility(GetVisibility(),false);
1137 void SMESH_ActorDef::SetPointRepresentation(bool theIsPointsVisible){
1138 myIsPointsVisible = theIsPointsVisible;
1139 SetRepresentation(GetRepresentation());
1142 bool SMESH_ActorDef::GetPointRepresentation(){
1143 return myIsPointsVisible || myIsPointsLabeled;
1147 void SMESH_ActorDef::UpdateHighlight(){
1148 myHighlitableActor->SetVisibility(false);
1149 myHighlitableActor->SetHighlited(false);
1151 if(myIsHighlighted){
1152 myHighlitableActor->SetProperty(myHighlightProp);
1153 }else if(myIsPreselected){
1154 myHighlitableActor->SetProperty(myPreselectProp);
1157 bool anIsVisible = GetVisibility();
1159 if(myIsHighlighted || myIsPreselected){
1160 if(GetUnstructuredGrid()->GetNumberOfCells()){
1161 myHighlitableActor->SetHighlited(anIsVisible);
1162 myHighlitableActor->SetVisibility(anIsVisible);
1163 myHighlitableActor->GetExtractUnstructuredGrid()->
1164 SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::eCells);
1165 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
1166 }else if(myRepresentation == ePoint || GetPointRepresentation()){
1167 myHighlitableActor->SetHighlited(anIsVisible);
1168 myHighlitableActor->SetVisibility(anIsVisible);
1169 myHighlitableActor->GetExtractUnstructuredGrid()->
1170 SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
1171 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::ePoint);
1177 void SMESH_ActorDef::highlight(bool theHighlight){
1178 myIsHighlighted = theHighlight;
1183 void SMESH_ActorDef::SetPreSelected(bool thePreselect){
1184 myIsPreselected = thePreselect;
1190 int SMESH_ActorDef::RenderOpaqueGeometry(vtkViewport *vp)
1192 if (myPickableActor->GetIsOpaque())
1194 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1202 int SMESH_ActorDef::RenderTranslucentGeometry(vtkViewport *vp)
1204 if (!myPickableActor->GetIsOpaque())
1206 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1214 void SMESH_ActorDef::Render(vtkRenderer *ren){
1215 unsigned long aTime = myTimeStamp->GetMTime();
1216 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1217 unsigned long aClippingTime = myImplicitBoolean->GetMTime();
1218 if(anObjTime > aTime || aClippingTime > aTime)
1223 void SMESH_ActorDef::Update(){
1224 if(MYDEBUG) MESSAGE("SMESH_ActorDef::Update");
1226 if(GetControlMode() != eNone) {
1227 unsigned long aTime = myTimeStamp->GetMTime();
1228 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1229 if (anObjTime > aTime)
1230 SetControlMode(GetControlMode(),false);
1232 if(myIsPointsLabeled){
1233 SetPointsLabeled(myIsPointsLabeled);
1235 if(myIsCellsLabeled){
1236 SetCellsLabeled(myIsCellsLabeled);
1238 SetEntityMode(GetEntityMode());
1239 SetVisibility(GetVisibility());
1241 myTimeStamp->Modified();
1246 void SMESH_ActorDef::ReleaseGraphicsResources(vtkWindow *renWin){
1247 SALOME_Actor::ReleaseGraphicsResources(renWin);
1249 myPickableActor->ReleaseGraphicsResources(renWin);
1253 static void GetColor(vtkProperty *theProperty, float& r,float& g,float& b){
1254 float* aColor = theProperty->GetColor();
1261 void SMESH_ActorDef::SetOpacity(float theValue){
1262 mySurfaceProp->SetOpacity(theValue);
1263 myBackSurfaceProp->SetOpacity(theValue);
1264 myEdgeProp->SetOpacity(theValue);
1265 myNodeProp->SetOpacity(theValue);
1267 my1DProp->SetOpacity(theValue);
1271 float SMESH_ActorDef::GetOpacity(){
1272 return mySurfaceProp->GetOpacity();
1276 void SMESH_ActorDef::SetSufaceColor(float r,float g,float b){
1277 mySurfaceProp->SetColor(r,g,b);
1281 void SMESH_ActorDef::GetSufaceColor(float& r,float& g,float& b){
1282 ::GetColor(mySurfaceProp,r,g,b);
1285 void SMESH_ActorDef::SetBackSufaceColor(float r,float g,float b){
1286 myBackSurfaceProp->SetColor(r,g,b);
1290 void SMESH_ActorDef::GetBackSufaceColor(float& r,float& g,float& b){
1291 ::GetColor(myBackSurfaceProp,r,g,b);
1294 void SMESH_ActorDef::SetEdgeColor(float r,float g,float b){
1295 myEdgeProp->SetColor(r,g,b);
1296 my1DProp->SetColor(r,g,b);
1297 my1DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1301 void SMESH_ActorDef::GetEdgeColor(float& r,float& g,float& b){
1302 ::GetColor(myEdgeProp,r,g,b);
1305 void SMESH_ActorDef::SetNodeColor(float r,float g,float b){
1306 myNodeProp->SetColor(r,g,b);
1310 void SMESH_ActorDef::GetNodeColor(float& r,float& g,float& b){
1311 ::GetColor(myNodeProp,r,g,b);
1314 void SMESH_ActorDef::SetHighlightColor(float r,float g,float b){
1315 myHighlightProp->SetColor(r,g,b);
1319 void SMESH_ActorDef::GetHighlightColor(float& r,float& g,float& b){
1320 ::GetColor(myHighlightProp,r,g,b);
1323 void SMESH_ActorDef::SetPreHighlightColor(float r,float g,float b){
1324 myPreselectProp->SetColor(r,g,b);
1328 void SMESH_ActorDef::GetPreHighlightColor(float& r,float& g,float& b){
1329 ::GetColor(myPreselectProp,r,g,b);
1333 float SMESH_ActorDef::GetLineWidth(){
1334 return myEdgeProp->GetLineWidth();
1338 void SMESH_ActorDef::SetLineWidth(float theVal){
1339 myEdgeProp->SetLineWidth(theVal);
1341 my1DProp->SetLineWidth(theVal + aLineWidthInc);
1342 my1DExtProp->SetLineWidth(theVal + aLineWidthInc);
1348 void SMESH_ActorDef::SetNodeSize(float theVal){
1349 myNodeProp->SetPointSize(theVal);
1350 myHighlightProp->SetPointSize(theVal);
1351 myPreselectProp->SetPointSize(theVal);
1353 my1DProp->SetPointSize(theVal + aPointSizeInc);
1354 my1DExtProp->SetPointSize(theVal + aPointSizeInc);
1359 float SMESH_ActorDef::GetNodeSize(){
1360 return myNodeProp->GetPointSize();
1363 int SMESH_ActorDef::GetObjDimension( const int theObjId )
1365 return myVisualObj->GetElemDimension( theObjId );
1370 IsImplicitFunctionUsed() const
1372 return myBaseActor->IsImplicitFunctionUsed();
1377 SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
1379 myNodeActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1380 myBaseActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1382 myHighlitableActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1384 my1DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1385 my1DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1387 my2DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1388 my3DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1393 AddClippingPlane(vtkPlane* thePlane)
1396 myImplicitBoolean->GetFunction()->AddItem(thePlane);
1397 myCippingPlaneCont.push_back(thePlane);
1398 if(!IsImplicitFunctionUsed())
1399 SetImplicitFunctionUsed(true);
1401 return myCippingPlaneCont.size();
1406 RemoveAllClippingPlanes()
1408 myImplicitBoolean->GetFunction()->RemoveAllItems();
1409 myImplicitBoolean->GetFunction()->Modified(); // VTK bug
1410 myCippingPlaneCont.clear();
1411 SetImplicitFunctionUsed(false);
1416 GetNumberOfClippingPlanes()
1418 return myCippingPlaneCont.size();
1423 GetClippingPlane(vtkIdType theID)
1425 if(theID >= myCippingPlaneCont.size())
1427 return myCippingPlaneCont[theID].Get();
1431 static void ComputeBoundsParam(vtkDataSet* theDataSet,
1432 float theDirection[3], float theMinPnt[3],
1433 float& theMaxBoundPrj, float& theMinBoundPrj)
1436 theDataSet->GetBounds(aBounds);
1438 //Enlarge bounds in order to avoid conflicts of precision
1439 for(int i = 0; i < 6; i += 2){
1440 static double EPS = 1.0E-3;
1441 float aDelta = (aBounds[i+1] - aBounds[i])*EPS;
1442 aBounds[i] -= aDelta;
1443 aBounds[i+1] += aDelta;
1446 float aBoundPoints[8][3] = { {aBounds[0],aBounds[2],aBounds[4]},
1447 {aBounds[1],aBounds[2],aBounds[4]},
1448 {aBounds[0],aBounds[3],aBounds[4]},
1449 {aBounds[1],aBounds[3],aBounds[4]},
1450 {aBounds[0],aBounds[2],aBounds[5]},
1451 {aBounds[1],aBounds[2],aBounds[5]},
1452 {aBounds[0],aBounds[3],aBounds[5]},
1453 {aBounds[1],aBounds[3],aBounds[5]}};
1455 int aMaxId = 0, aMinId = aMaxId;
1456 theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
1457 theMinBoundPrj = theMaxBoundPrj;
1458 for(int i = 1; i < 8; i++){
1459 float aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
1460 if(theMaxBoundPrj < aTmp){
1461 theMaxBoundPrj = aTmp;
1464 if(theMinBoundPrj > aTmp){
1465 theMinBoundPrj = aTmp;
1469 float *aMinPnt = aBoundPoints[aMaxId];
1470 theMinPnt[0] = aMinPnt[0];
1471 theMinPnt[1] = aMinPnt[1];
1472 theMinPnt[2] = aMinPnt[2];
1476 static void DistanceToPosition(vtkDataSet* theDataSet,
1477 float theDirection[3], float theDist, float thePos[3])
1479 float aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1480 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1481 float aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
1482 thePos[0] = aMinPnt[0]-theDirection[0]*aLength;
1483 thePos[1] = aMinPnt[1]-theDirection[1]*aLength;
1484 thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
1488 static void PositionToDistance(vtkDataSet* theDataSet,
1489 float theDirection[3], float thePos[3], float& theDist)
1491 float aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1492 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1493 float aPrj = vtkMath::Dot(theDirection,thePos);
1494 theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
1498 void SMESH_ActorDef::SetPlaneParam(float theDir[3], float theDist, vtkPlane* thePlane)
1500 thePlane->SetNormal(theDir);
1502 ::DistanceToPosition(GetUnstructuredGrid(),theDir,theDist,anOrigin);
1503 thePlane->SetOrigin(anOrigin);
1507 void SMESH_ActorDef::GetPlaneParam(float theDir[3], float& theDist, vtkPlane* thePlane)
1509 thePlane->GetNormal(theDir);
1512 thePlane->GetOrigin(anOrigin);
1513 ::PositionToDistance(GetUnstructuredGrid(),theDir,anOrigin,theDist);
1516 void SMESH_ActorDef::UpdateScalarBar()
1518 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
1522 vtkTextProperty* aScalarBarTitleProp = vtkTextProperty::New();
1524 QColor aTColor = mgr->colorValue( "SMESH", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
1525 aScalarBarTitleProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1527 aScalarBarTitleProp->SetFontFamilyToArial();
1529 if ( mgr->hasValue( "SMESH", "scalar_bar_title_font" ) )
1531 QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
1532 if ( f.family() == "Arial" )
1533 aScalarBarTitleProp->SetFontFamilyToArial();
1534 else if ( f.family() == "Courier" )
1535 aScalarBarTitleProp->SetFontFamilyToCourier();
1536 else if ( f.family() == "Times" )
1537 aScalarBarTitleProp->SetFontFamilyToTimes();
1540 aScalarBarTitleProp->BoldOn();
1542 aScalarBarTitleProp->BoldOff();
1545 aScalarBarTitleProp->ItalicOn();
1547 aScalarBarTitleProp->ItalicOff();
1549 if ( f.underline() )
1550 aScalarBarTitleProp->ShadowOn();
1552 aScalarBarTitleProp->ShadowOff();
1555 myScalarBarActor->SetTitleTextProperty( aScalarBarTitleProp );
1556 aScalarBarTitleProp->Delete();
1558 vtkTextProperty* aScalarBarLabelProp = vtkTextProperty::New();
1560 aTColor = mgr->colorValue( "SMESH", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
1561 aScalarBarLabelProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1563 aScalarBarLabelProp->SetFontFamilyToArial();
1564 if( mgr->hasValue( "SMESH", "scalar_bar_label_font" ) )
1566 QFont f = mgr->stringValue( "SMESH", "scalar_bar_label_font" );
1567 if( f.family() == "Arial" )
1568 aScalarBarLabelProp->SetFontFamilyToArial();
1569 else if( f.family() == "Courier" )
1570 aScalarBarLabelProp->SetFontFamilyToCourier();
1571 else if( f.family() == "Times" )
1572 aScalarBarLabelProp->SetFontFamilyToTimes();
1575 aScalarBarLabelProp->BoldOn();
1577 aScalarBarLabelProp->BoldOff();
1580 aScalarBarLabelProp->ItalicOn();
1582 aScalarBarLabelProp->ItalicOff();
1585 aScalarBarLabelProp->ShadowOn();
1587 aScalarBarLabelProp->ShadowOff();
1590 myScalarBarActor->SetLabelTextProperty( aScalarBarLabelProp );
1591 aScalarBarLabelProp->Delete();
1593 bool horiz = ( mgr->integerValue( "SMESH", "scalar_bar_orientation" ) == 1 );
1594 QString name = QString( "scalar_bar_%1_" ).arg( horiz ? "horizontal" : "vertical" );
1596 myScalarBarActor->SetOrientationToHorizontal();
1598 myScalarBarActor->SetOrientationToVertical();
1601 float aXVal = horiz ? 0.20 : 0.01;
1602 if( mgr->hasValue( "SMESH", name + "x" ) )
1603 aXVal = mgr->doubleValue( "SMESH", name + "x", aXVal );
1605 float aYVal = horiz ? 0.01 : 0.1;
1606 if( mgr->hasValue( "SMESH", name + "y" ) )
1607 aYVal = mgr->doubleValue( "SMESH", name + "y", aYVal );
1608 myScalarBarActor->SetPosition( aXVal, aYVal );
1610 float aWVal = horiz ? 0.60 : 0.10;
1611 if( mgr->hasValue( "SMESH", name + "width" ) )
1612 aWVal = mgr->doubleValue( "SMESH", name + "width", aWVal );
1613 myScalarBarActor->SetWidth( aWVal );
1615 float aHVal = horiz ? 0.12 : 0.80;
1616 if( mgr->hasValue( "SMESH", name + "height" ) )
1617 aHVal = mgr->doubleValue( "SMESH", name + "height", aHVal );
1618 myScalarBarActor->SetHeight( aHVal );
1621 if( mgr->hasValue( "SMESH", "scalar_bar_num_labels" ) )
1622 anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_labels", anIntVal );
1623 myScalarBarActor->SetNumberOfLabels( anIntVal == 0 ? 5: anIntVal );
1626 if( mgr->hasValue( "SMESH", "scalar_bar_num_colors" ) )
1627 anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_colors", anIntVal );
1628 myScalarBarActor->SetMaximumNumberOfColors( anIntVal == 0 ? 64 : anIntVal );