1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH OBJECT : interactive object for SMESH visualization
23 // File : SMESH_Actor.cxx
24 // Author : Nicolas REJNERI
28 #include "SMESH_ActorDef.h"
29 #include "SMESH_ActorUtils.h"
30 #include "SMESH_DeviceActor.h"
31 #include "SMESH_ControlsDef.hxx"
32 #include "VTKViewer_ExtractUnstructuredGrid.h"
33 #include "SALOME_InteractiveObject.hxx"
35 #include "SUIT_Session.h"
36 #include "SUIT_ResourceMgr.h"
38 #include <vtkProperty.h>
39 #include <vtkTimeStamp.h>
40 #include <vtkObjectFactory.h>
41 #include <vtkShrinkPolyData.h>
42 #include <vtkMergeFilter.h>
44 #include <vtkMatrix4x4.h>
45 #include <vtkUnstructuredGrid.h>
46 #include <vtkPointData.h>
47 #include <vtkCellData.h>
49 #include <vtkMapper.h>
50 #include <vtkRenderer.h>
53 #include <vtkIdList.h>
54 #include <vtkIntArray.h>
56 #include <vtkActor2D.h>
57 #include <vtkProperty2D.h>
58 #include <vtkPolyData.h>
59 #include <vtkMaskPoints.h>
60 #include <vtkCellCenters.h>
61 #include <vtkTextProperty.h>
62 #include <vtkLabeledDataMapper.h>
63 #include <vtkSelectVisiblePoints.h>
65 #include <vtkScalarBarActor.h>
66 #include <vtkLookupTable.h>
70 #include <vtkImplicitBoolean.h>
71 #include <vtkImplicitFunctionCollection.h>
73 #include "utilities.h"
76 static int MYDEBUG = 1;
78 static int MYDEBUG = 0;
81 static int aLineWidthInc = 2;
82 static int aPointSizeInc = 2;
85 SMESH_ActorDef* SMESH_ActorDef::New(){
86 return new SMESH_ActorDef();
90 SMESH_Actor* SMESH_Actor::New(TVisualObjPtr theVisualObj,
95 SMESH_ActorDef* anActor = SMESH_ActorDef::New();
96 if(!anActor->Init(theVisualObj,theEntry,theName,theIsClear)){
101 anActor->UpdateScalarBar();
106 SMESH_ActorDef::SMESH_ActorDef()
108 if(MYDEBUG) MESSAGE("SMESH_ActorDef - "<<this);
110 myTimeStamp = vtkTimeStamp::New();
112 myIsPointsVisible = false;
114 myIsShrinkable = false;
117 myIsFacesOriented = false;
119 myControlsPrecision = -1;
120 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
122 if ( mgr && mgr->booleanValue( "SMESH", "use_precision", false ) )
123 myControlsPrecision = mgr->integerValue( "SMESH", "controls_precision", -1);
125 vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
126 vtkFloatingPointType 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 vtkFloatingPointType 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);
153 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
154 aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
156 my2DExtProp = vtkProperty::New();
157 my2DExtProp->DeepCopy(mySurfaceProp);
158 SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
159 anRGB[0] = 1 - anRGB[0];
160 anRGB[1] = 1 - anRGB[1];
161 anRGB[2] = 1 - anRGB[2];
162 my2DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
164 my2DExtActor = SMESH_DeviceActor::New();
165 my2DExtActor->SetUserMatrix(aMatrix);
166 my2DExtActor->PickableOff();
167 my2DExtActor->SetProperty(my2DExtProp);
168 my2DExtActor->SetBackfaceProperty(my2DExtProp);
169 my2DExtActor->SetRepresentation(SMESH_DeviceActor::eInsideframe);
170 aFilter = my2DExtActor->GetExtractUnstructuredGrid();
171 aFilter->RegisterCellsWithType(VTK_TRIANGLE);
172 aFilter->RegisterCellsWithType(VTK_POLYGON);
173 aFilter->RegisterCellsWithType(VTK_QUAD);
174 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
175 aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
177 my3DActor = SMESH_DeviceActor::New();
178 my3DActor->SetUserMatrix(aMatrix);
179 my3DActor->PickableOff();
180 my3DActor->SetProperty(mySurfaceProp);
181 my3DActor->SetBackfaceProperty(myBackSurfaceProp);
182 my3DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
183 aFilter = my3DActor->GetExtractUnstructuredGrid();
184 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
185 aFilter->RegisterCellsWithType(VTK_TETRA);
186 aFilter->RegisterCellsWithType(VTK_VOXEL);
187 aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
188 aFilter->RegisterCellsWithType(VTK_WEDGE);
189 aFilter->RegisterCellsWithType(VTK_PYRAMID);
190 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
191 aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
192 aFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
193 aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
195 //Definition 1D divice of the actor
196 //---------------------------------
197 myEdgeProp = vtkProperty::New();
198 myEdgeProp->SetAmbient(1.0);
199 myEdgeProp->SetDiffuse(0.0);
200 myEdgeProp->SetSpecular(0.0);
201 SMESH::GetColor( "SMESH", "outline_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
202 myEdgeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
203 myEdgeProp->SetLineWidth(aLineWidth);
205 my1DActor = SMESH_DeviceActor::New();
206 my1DActor->SetUserMatrix(aMatrix);
207 my1DActor->PickableOff();
208 my1DActor->SetHighlited(true);
209 my1DActor->SetProperty(myEdgeProp);
210 my1DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
211 aFilter = my1DActor->GetExtractUnstructuredGrid();
212 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
213 aFilter->RegisterCellsWithType(VTK_LINE);
214 aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
216 my1DProp = vtkProperty::New();
217 my1DProp->DeepCopy(myEdgeProp);
218 my1DProp->SetLineWidth(aLineWidth + aLineWidthInc);
219 my1DProp->SetPointSize(aPointSize);
221 my1DExtProp = vtkProperty::New();
222 my1DExtProp->DeepCopy(myEdgeProp);
223 anRGB[0] = 1 - anRGB[0];
224 anRGB[1] = 1 - anRGB[1];
225 anRGB[2] = 1 - anRGB[2];
226 my1DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
227 my1DExtProp->SetLineWidth(aLineWidth + aLineWidthInc);
228 my1DExtProp->SetPointSize(aPointSize + aPointSizeInc);
230 my1DExtActor = SMESH_DeviceActor::New();
231 my1DExtActor->SetUserMatrix(aMatrix);
232 my1DExtActor->PickableOff();
233 my1DExtActor->SetHighlited(true);
234 my1DExtActor->SetVisibility(false);
235 my1DExtActor->SetProperty(my1DExtProp);
236 my1DExtActor->SetRepresentation(SMESH_DeviceActor::eInsideframe);
237 aFilter = my1DExtActor->GetExtractUnstructuredGrid();
238 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
239 aFilter->RegisterCellsWithType(VTK_LINE);
240 aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
243 //Definition 0D divice of the actor
244 //---------------------------------
245 myNodeProp = vtkProperty::New();
246 SMESH::GetColor( "SMESH", "node_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 0, 0 ) );
247 myNodeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
248 myNodeProp->SetPointSize(aPointSize);
250 myNodeActor = SMESH_DeviceActor::New();
251 myNodeActor->SetUserMatrix(aMatrix);
252 myNodeActor->SetStoreClippingMapping(true);
253 myNodeActor->PickableOff();
254 myNodeActor->SetVisibility(false);
255 myNodeActor->SetProperty(myNodeProp);
256 myNodeActor->SetRepresentation(SMESH_DeviceActor::ePoint);
257 aFilter = myNodeActor->GetExtractUnstructuredGrid();
258 aFilter->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
260 myNodeExtProp = vtkProperty::New();
261 myNodeExtProp->DeepCopy(myNodeProp);
262 anRGB[0] = 1 - anRGB[0];
263 anRGB[1] = 1 - anRGB[1];
264 anRGB[2] = 1 - anRGB[2];
265 myNodeExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
266 myNodeExtProp->SetPointSize(aPointSize);
268 myNodeExtActor = SMESH_DeviceActor::New();
269 myNodeExtActor->SetUserMatrix(aMatrix);
270 myNodeExtActor->SetStoreClippingMapping(true);
271 myNodeExtActor->PickableOff();
272 myNodeExtActor->SetHighlited(true);
273 myNodeExtActor->SetVisibility(false);
274 myNodeExtActor->SetProperty(myNodeExtProp);
275 myNodeExtActor->SetRepresentation(SMESH_DeviceActor::ePoint);
276 aFilter = myNodeExtActor->GetExtractUnstructuredGrid();
277 aFilter->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
278 aFilter->RegisterCellsWithType(VTK_VERTEX);
280 //Definition of Pickable and Highlitable engines
281 //----------------------------------------------
283 myBaseActor = SMESH_DeviceActor::New();
284 myBaseActor->SetUserMatrix(aMatrix);
285 myBaseActor->SetStoreGemetryMapping(true);
286 myBaseActor->GetProperty()->SetOpacity(0.0);
288 myPickableActor = myBaseActor;
290 myHighlightProp = vtkProperty::New();
291 myHighlightProp->SetAmbient(1.0);
292 myHighlightProp->SetDiffuse(0.0);
293 myHighlightProp->SetSpecular(0.0);
294 SMESH::GetColor( "SMESH", "selection_object_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
295 myHighlightProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
296 myHighlightProp->SetPointSize(aPointSize);
297 myHighlightProp->SetRepresentation(1);
299 myPreselectProp = vtkProperty::New();
300 myPreselectProp->SetAmbient(1.0);
301 myPreselectProp->SetDiffuse(0.0);
302 myPreselectProp->SetSpecular(0.0);
303 SMESH::GetColor( "SMESH", "highlight_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 255, 255 ) );
304 myPreselectProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
305 myPreselectProp->SetPointSize(aPointSize);
306 myPreselectProp->SetRepresentation(1);
308 myHighlitableActor = SMESH_DeviceActor::New();
309 myHighlitableActor->SetUserMatrix(aMatrix);
310 myHighlitableActor->PickableOff();
311 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
316 myControlMode = eNone;
317 myControlActor = my2DActor;
319 //Definition of myScalarBarActor
320 //------------------------------
321 myLookupTable = vtkLookupTable::New();
322 //Fix for Bug PAL5195 - SMESH764:
323 //Controls - Aspect Ratio: incorrect colors of the best and worst values
324 myLookupTable->SetHueRange(0.667,0.0);
326 myScalarBarActor = vtkScalarBarActor::New();
327 myScalarBarActor->SetVisibility(false);
328 myScalarBarActor->SetLookupTable(myLookupTable);
331 //Incorrect "Min value" in Scalar Bar in Mesh:
332 // myScalarBarActor->SetLabelFormat("%.4g");
333 // changes was commented because of regression bug IPAL 19981
335 mgr = SUIT_Session::session()->resourceMgr();
339 //Definition of points numbering pipeline
340 //---------------------------------------
341 myPointsNumDataSet = vtkUnstructuredGrid::New();
343 myPtsMaskPoints = vtkMaskPoints::New();
344 myPtsMaskPoints->SetInput(myPointsNumDataSet);
345 myPtsMaskPoints->SetOnRatio(1);
347 myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
348 myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
349 myPtsSelectVisiblePoints->SelectInvisibleOff();
350 myPtsSelectVisiblePoints->SetTolerance(0.1);
352 myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
353 myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
354 myPtsLabeledDataMapper->SetLabelFormat("%g");
355 myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
357 vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
358 aPtsTextProp->SetFontFamilyToTimes();
359 static int aPointsFontSize = 10;
360 aPtsTextProp->SetFontSize(aPointsFontSize);
361 aPtsTextProp->SetBold(1);
362 aPtsTextProp->SetItalic(0);
363 aPtsTextProp->SetShadow(0);
364 myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
365 aPtsTextProp->Delete();
367 myEntityMode = eAllEntity;
369 myIsPointsLabeled = false;
371 myPointLabels = vtkActor2D::New();
372 myPointLabels->SetMapper(myPtsLabeledDataMapper);
373 myPointLabels->GetProperty()->SetColor(1,1,1);
374 myPointLabels->SetVisibility(myIsPointsLabeled);
377 //Definition of cells numbering pipeline
378 //---------------------------------------
379 myCellsNumDataSet = vtkUnstructuredGrid::New();
381 myCellCenters = vtkCellCenters::New();
382 myCellCenters->SetInput(myCellsNumDataSet);
384 myClsMaskPoints = vtkMaskPoints::New();
385 myClsMaskPoints->SetInput(myCellCenters->GetOutput());
386 myClsMaskPoints->SetOnRatio(1);
388 myClsSelectVisiblePoints = vtkSelectVisiblePoints::New();
389 myClsSelectVisiblePoints->SetInput(myClsMaskPoints->GetOutput());
390 myClsSelectVisiblePoints->SelectInvisibleOff();
391 myClsSelectVisiblePoints->SetTolerance(0.1);
393 myClsLabeledDataMapper = vtkLabeledDataMapper::New();
394 myClsLabeledDataMapper->SetInput(myClsSelectVisiblePoints->GetOutput());
395 myClsLabeledDataMapper->SetLabelFormat("%g");
396 myClsLabeledDataMapper->SetLabelModeToLabelScalars();
398 vtkTextProperty* aClsTextProp = vtkTextProperty::New();
399 aClsTextProp->SetFontFamilyToTimes();
400 static int aCellsFontSize = 12;
401 aClsTextProp->SetFontSize(aCellsFontSize);
402 aClsTextProp->SetBold(1);
403 aClsTextProp->SetItalic(0);
404 aClsTextProp->SetShadow(0);
405 myClsLabeledDataMapper->SetLabelTextProperty(aClsTextProp);
406 aClsTextProp->Delete();
408 myIsCellsLabeled = false;
410 myCellsLabels = vtkActor2D::New();
411 myCellsLabels->SetMapper(myClsLabeledDataMapper);
412 myCellsLabels->GetProperty()->SetColor(0,1,0);
413 myCellsLabels->SetVisibility(myIsCellsLabeled);
416 myImplicitBoolean = vtkImplicitBoolean::New();
417 myImplicitBoolean->SetOperationTypeToIntersection();
421 SMESH_ActorDef::~SMESH_ActorDef()
423 if(MYDEBUG) MESSAGE("~SMESH_ActorDef - "<<this);
425 myScalarBarActor->Delete();
426 myLookupTable->Delete();
428 mySurfaceProp->Delete();
429 myBackSurfaceProp->Delete();
431 myEdgeProp->Delete();
432 myHighlightProp->Delete();
433 myPreselectProp->Delete();
435 myNodeProp->Delete();
436 myNodeExtProp->Delete();
441 my1DExtProp->Delete();
442 my1DExtActor->Delete();
445 my2DExtProp->Delete();
446 my2DExtActor->Delete();
449 myNodeActor->Delete();
450 myBaseActor->Delete();
452 myNodeExtActor->Delete();
454 myHighlitableActor->Delete();
456 //Deleting of pints numbering pipeline
457 //---------------------------------------
458 myPointsNumDataSet->Delete();
460 // commented: porting to vtk 5.0
461 // myPtsLabeledDataMapper->RemoveAllInputs();
462 myPtsLabeledDataMapper->Delete();
464 // commented: porting to vtk 5.0
465 // myPtsSelectVisiblePoints->UnRegisterAllOutputs();
466 myPtsSelectVisiblePoints->Delete();
468 // commented: porting to vtk 5.0
469 // myPtsMaskPoints->UnRegisterAllOutputs();
470 myPtsMaskPoints->Delete();
472 myPointLabels->Delete();
475 //Deleting of cells numbering pipeline
476 //---------------------------------------
477 myCellsNumDataSet->Delete();
479 myClsLabeledDataMapper->RemoveAllInputs();
480 myClsLabeledDataMapper->Delete();
482 // commented: porting to vtk 5.0
483 // myClsSelectVisiblePoints->UnRegisterAllOutputs();
484 myClsSelectVisiblePoints->Delete();
486 // commented: porting to vtk 5.0
487 // myClsMaskPoints->UnRegisterAllOutputs();
488 myClsMaskPoints->Delete();
490 // commented: porting to vtk 5.0
491 // myCellCenters->UnRegisterAllOutputs();
492 myCellCenters->Delete();
494 myCellsLabels->Delete();
496 myImplicitBoolean->Delete();
498 myTimeStamp->Delete();
502 void SMESH_ActorDef::SetPointsLabeled( bool theIsPointsLabeled )
504 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
505 myIsPointsLabeled = theIsPointsLabeled && aGrid->GetNumberOfPoints();
507 if ( myIsPointsLabeled )
509 myPointsNumDataSet->ShallowCopy(aGrid);
510 vtkDataSet *aDataSet = myPointsNumDataSet;
512 int aNbElem = aDataSet->GetNumberOfPoints();
514 vtkIntArray *anArray = vtkIntArray::New();
515 anArray->SetNumberOfValues( aNbElem );
517 for ( int anId = 0; anId < aNbElem; anId++ )
519 int aSMDSId = myVisualObj->GetNodeObjId( anId );
520 anArray->SetValue( anId, aSMDSId );
523 aDataSet->GetPointData()->SetScalars( anArray );
525 myPtsMaskPoints->SetInput( aDataSet );
526 myPointLabels->SetVisibility( GetVisibility() );
530 myPointLabels->SetVisibility( false );
532 SetRepresentation(GetRepresentation());
533 myTimeStamp->Modified();
537 void SMESH_ActorDef::SetCellsLabeled(bool theIsCellsLabeled)
539 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
540 myIsCellsLabeled = theIsCellsLabeled && aGrid->GetNumberOfPoints();
541 if(myIsCellsLabeled){
542 myCellsNumDataSet->ShallowCopy(aGrid);
543 vtkDataSet *aDataSet = myCellsNumDataSet;
544 int aNbElem = aDataSet->GetNumberOfCells();
545 vtkIntArray *anArray = vtkIntArray::New();
546 anArray->SetNumberOfValues(aNbElem);
547 for(int anId = 0; anId < aNbElem; anId++){
548 int aSMDSId = myVisualObj->GetElemObjId(anId);
549 anArray->SetValue(anId,aSMDSId);
551 aDataSet->GetCellData()->SetScalars(anArray);
552 myCellCenters->SetInput(aDataSet);
553 myCellsLabels->SetVisibility(GetVisibility());
555 myCellsLabels->SetVisibility(false);
557 myTimeStamp->Modified();
561 void SMESH_ActorDef::SetFacesOriented(bool theIsFacesOriented)
563 myIsFacesOriented = theIsFacesOriented;
565 my2DActor->SetFacesOriented(theIsFacesOriented);
566 my3DActor->SetFacesOriented(theIsFacesOriented);
568 myTimeStamp->Modified();
571 bool SMESH_ActorDef::GetFacesOriented()
573 return myIsFacesOriented;
579 SetControlMode(eControl theMode)
581 SetControlMode(theMode,true);
587 SetControlMode(eControl theMode,
588 bool theCheckEntityMode)
590 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
594 myControlMode = eNone;
595 theCheckEntityMode &= mgr->booleanValue( "SMESH", "display_entity", false );
597 my1DActor->GetMapper()->SetScalarVisibility(false);
598 my2DActor->GetMapper()->SetScalarVisibility(false);
599 my3DActor->GetMapper()->SetScalarVisibility(false);
600 myScalarBarActor->SetVisibility(false);
602 bool anIsScalarVisible = theMode > eNone;
604 if(anIsScalarVisible){
605 SMESH::Controls::FunctorPtr aFunctor;
609 SMESH::Controls::Length* aControl = new SMESH::Controls::Length();
610 aControl->SetPrecision( myControlsPrecision );
611 aFunctor.reset( aControl );
612 myControlActor = my1DActor;
617 aFunctor.reset(new SMESH::Controls::Length2D());
618 myControlActor = my2DActor;
622 aFunctor.reset(new SMESH::Controls::FreeBorders());
623 myControlActor = my1DActor;
626 aFunctor.reset(new SMESH::Controls::FreeEdges());
627 myControlActor = my2DActor;
630 aFunctor.reset(new SMESH::Controls::FreeNodes());
631 myControlActor = myNodeActor;
634 aFunctor.reset(new SMESH::Controls::FreeFaces());
635 myControlActor = my2DActor;
637 case eMultiConnection:
638 aFunctor.reset(new SMESH::Controls::MultiConnection());
639 myControlActor = my1DActor;
641 case eMultiConnection2D:
642 aFunctor.reset(new SMESH::Controls::MultiConnection2D());
643 myControlActor = my2DActor;
647 SMESH::Controls::Area* aControl = new SMESH::Controls::Area();
648 aControl->SetPrecision( myControlsPrecision );
649 aFunctor.reset( aControl );
650 myControlActor = my2DActor;
655 SMESH::Controls::Taper* aControl = new SMESH::Controls::Taper();
656 aControl->SetPrecision( myControlsPrecision );
657 aFunctor.reset( aControl );
658 myControlActor = my2DActor;
663 SMESH::Controls::AspectRatio* aControl = new SMESH::Controls::AspectRatio();
664 aControl->SetPrecision( myControlsPrecision );
665 aFunctor.reset( aControl );
666 myControlActor = my2DActor;
671 SMESH::Controls::AspectRatio3D* aControl = new SMESH::Controls::AspectRatio3D();
672 aControl->SetPrecision( myControlsPrecision );
673 aFunctor.reset( aControl );
674 myControlActor = my3DActor;
679 SMESH::Controls::Volume* aControl = new SMESH::Controls::Volume();
680 aControl->SetPrecision( myControlsPrecision );
681 aFunctor.reset( aControl );
682 myControlActor = my3DActor;
687 SMESH::Controls::MinimumAngle* aControl = new SMESH::Controls::MinimumAngle();
688 aControl->SetPrecision( myControlsPrecision );
689 aFunctor.reset( aControl );
690 myControlActor = my2DActor;
695 SMESH::Controls::Warping* aControl = new SMESH::Controls::Warping();
696 aControl->SetPrecision( myControlsPrecision );
697 aFunctor.reset( aControl );
698 myControlActor = my2DActor;
703 SMESH::Controls::Skew* aControl = new SMESH::Controls::Skew();
704 aControl->SetPrecision( myControlsPrecision );
705 aFunctor.reset( aControl );
706 myControlActor = my2DActor;
713 vtkUnstructuredGrid* aGrid = myControlActor->GetUnstructuredGrid();
714 vtkIdType aNbCells = aGrid->GetNumberOfCells();
716 myControlMode = theMode;
717 switch(myControlMode){
719 myNodeExtActor->SetExtControlMode(aFunctor);
723 my1DExtActor->SetExtControlMode(aFunctor);
726 my2DExtActor->SetExtControlMode(aFunctor);
729 case eMultiConnection2D:
730 my1DExtActor->SetExtControlMode(aFunctor,myScalarBarActor,myLookupTable);
733 myControlActor->SetControlMode(aFunctor,myScalarBarActor,myLookupTable);
737 if(theCheckEntityMode){
738 if(myControlActor == my1DActor)
739 SetEntityMode(eEdges);
740 else if(myControlActor == my2DActor){
741 switch(myControlMode){
745 case eMultiConnection2D:
746 //SetEntityMode(eEdges);
747 SetEntityMode(eFaces);
750 SetEntityMode(eFaces);
752 }else if(myControlActor == my3DActor)
753 SetEntityMode(eVolumes);
756 }else if(theCheckEntityMode){
757 myEntityMode = eAllEntity;
760 SetRepresentation(GetRepresentation());
762 myTimeStamp->Modified();
767 void SMESH_ActorDef::AddToRender(vtkRenderer* theRenderer){
768 SALOME_Actor::AddToRender(theRenderer);
770 theRenderer->AddActor(myNodeActor);
771 theRenderer->AddActor(myBaseActor);
773 theRenderer->AddActor(myNodeExtActor);
775 my3DActor->AddToRender(theRenderer);
776 my2DActor->AddToRender(theRenderer);
777 my2DExtActor->AddToRender(theRenderer);
779 theRenderer->AddActor(my1DActor);
780 theRenderer->AddActor(my1DExtActor);
782 theRenderer->AddActor(myHighlitableActor);
784 theRenderer->AddActor2D(myScalarBarActor);
786 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
787 myClsSelectVisiblePoints->SetRenderer(theRenderer);
789 theRenderer->AddActor2D(myPointLabels);
790 theRenderer->AddActor2D(myCellsLabels);
793 void SMESH_ActorDef::RemoveFromRender(vtkRenderer* theRenderer){
794 SALOME_Actor::RemoveFromRender(theRenderer);
796 theRenderer->RemoveActor(myNodeActor);
797 theRenderer->RemoveActor(myBaseActor);
799 theRenderer->RemoveActor(myNodeExtActor);
801 theRenderer->RemoveActor(myHighlitableActor);
803 theRenderer->RemoveActor(my1DActor);
804 theRenderer->RemoveActor(my1DExtActor);
806 my2DActor->RemoveFromRender(theRenderer);
807 my2DExtActor->RemoveFromRender(theRenderer);
808 my3DActor->RemoveFromRender(theRenderer);
810 theRenderer->RemoveActor(myScalarBarActor);
811 theRenderer->RemoveActor(myPointLabels);
812 theRenderer->RemoveActor(myCellsLabels);
816 bool SMESH_ActorDef::Init(TVisualObjPtr theVisualObj,
817 const char* theEntry,
821 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry,"SMESH",theName);
825 myVisualObj = theVisualObj;
826 myVisualObj->Update(theIsClear);
828 myNodeActor->Init(myVisualObj,myImplicitBoolean);
829 myBaseActor->Init(myVisualObj,myImplicitBoolean);
831 myHighlitableActor->Init(myVisualObj,myImplicitBoolean);
833 myNodeExtActor->Init(myVisualObj,myImplicitBoolean);
835 my1DActor->Init(myVisualObj,myImplicitBoolean);
836 my1DExtActor->Init(myVisualObj,myImplicitBoolean);
838 my2DActor->Init(myVisualObj,myImplicitBoolean);
839 my2DExtActor->Init(myVisualObj,myImplicitBoolean);
840 my3DActor->Init(myVisualObj,myImplicitBoolean);
842 my1DActor->GetMapper()->SetLookupTable(myLookupTable);
843 my1DExtActor->GetMapper()->SetLookupTable(myLookupTable);
845 my2DActor->GetMapper()->SetLookupTable(myLookupTable);
846 my2DExtActor->GetMapper()->SetLookupTable(myLookupTable);
847 my3DActor->GetMapper()->SetLookupTable(myLookupTable);
849 vtkFloatingPointType aFactor, aUnits;
850 my2DActor->GetPolygonOffsetParameters(aFactor,aUnits);
851 my2DActor->SetPolygonOffsetParameters(aFactor,aUnits*0.75);
852 my2DExtActor->SetPolygonOffsetParameters(aFactor,aUnits*0.5);
854 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
858 //SetIsShrunkable(theGrid->GetNumberOfCells() > 10);
859 SetIsShrunkable(true);
861 SetShrinkFactor( SMESH::GetFloat( "SMESH:shrink_coeff", 75 ) / 100. );
863 int aMode = mgr->integerValue( "SMESH", "display_mode" );
864 SetRepresentation(-1);
867 SetRepresentation(eEdge);
868 }else if(aMode == 1){
869 SetRepresentation(eSurface);
870 }else if(aMode == 2){
871 SetRepresentation(ePoint);
878 myTimeStamp->Modified();
884 vtkFloatingPointType* SMESH_ActorDef::GetBounds(){
885 return myNodeActor->GetBounds();
889 vtkDataSet* SMESH_ActorDef::GetInput(){
890 return GetUnstructuredGrid();
894 void SMESH_ActorDef::SetTransform(VTKViewer_Transform* theTransform){
895 Superclass::SetTransform(theTransform);
897 myNodeActor->SetTransform(theTransform);
898 myBaseActor->SetTransform(theTransform);
900 myHighlitableActor->SetTransform(theTransform);
902 myNodeExtActor->SetTransform(theTransform);
904 my1DActor->SetTransform(theTransform);
905 my1DExtActor->SetTransform(theTransform);
907 my2DActor->SetTransform(theTransform);
908 my2DExtActor->SetTransform(theTransform);
909 my3DActor->SetTransform(theTransform);
915 void SMESH_ActorDef::SetMapper(vtkMapper* theMapper){
916 vtkLODActor::SetMapper(theMapper);
920 void SMESH_ActorDef::ShallowCopy(vtkProp *prop){
921 SALOME_Actor::ShallowCopy(prop);
925 vtkMapper* SMESH_ActorDef::GetMapper(){
926 return myPickableActor->GetMapper();
930 vtkUnstructuredGrid* SMESH_ActorDef::GetUnstructuredGrid(){
931 return myVisualObj->GetUnstructuredGrid();
935 bool SMESH_ActorDef::IsInfinitive(){
936 vtkDataSet *aDataSet = myPickableActor->GetUnstructuredGrid();
938 myIsInfinite = aDataSet->GetNumberOfCells() == 0 ||
939 aDataSet->GetNumberOfCells() == 1 &&
940 aDataSet->GetCell(0)->GetCellType() == VTK_VERTEX;
941 return SALOME_Actor::IsInfinitive();
945 void SMESH_ActorDef::SetIsShrunkable(bool theShrunkable){
946 if ( myIsShrinkable == theShrunkable )
948 myIsShrinkable = theShrunkable;
952 vtkFloatingPointType SMESH_ActorDef::GetShrinkFactor(){
953 return myBaseActor->GetShrinkFactor();
956 void SMESH_ActorDef::SetShrinkFactor(vtkFloatingPointType theValue){
957 myBaseActor->SetShrinkFactor(theValue);
959 my1DActor->SetShrinkFactor(theValue);
960 my1DExtActor->SetShrinkFactor(theValue);
962 my2DActor->SetShrinkFactor(theValue);
963 my2DExtActor->SetShrinkFactor(theValue);
964 my3DActor->SetShrinkFactor(theValue);
969 void SMESH_ActorDef::SetShrink(){
970 if(!myIsShrinkable) return;
972 myBaseActor->SetShrink();
974 my1DActor->SetShrink();
975 my1DExtActor->SetShrink();
977 my2DActor->SetShrink();
978 my2DExtActor->SetShrink();
979 my3DActor->SetShrink();
985 void SMESH_ActorDef::UnShrink(){
986 if(!myIsShrunk) return;
988 myBaseActor->UnShrink();
990 my1DActor->UnShrink();
991 my1DExtActor->UnShrink();
993 my2DActor->UnShrink();
994 my2DExtActor->UnShrink();
995 my3DActor->UnShrink();
1002 int SMESH_ActorDef::GetNodeObjId(int theVtkID){
1003 return myPickableActor->GetNodeObjId(theVtkID);
1006 vtkFloatingPointType* SMESH_ActorDef::GetNodeCoord(int theObjID){
1007 return myPickableActor->GetNodeCoord(theObjID);
1011 int SMESH_ActorDef::GetElemObjId(int theVtkID){
1012 return myPickableActor->GetElemObjId(theVtkID);
1015 vtkCell* SMESH_ActorDef::GetElemCell(int theObjID){
1016 return myPickableActor->GetElemCell(theObjID);
1020 void SMESH_ActorDef::SetVisibility(int theMode){
1021 SetVisibility(theMode,true);
1025 void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation){
1026 SALOME_Actor::SetVisibility(theMode);
1028 myNodeActor->VisibilityOff();
1029 myBaseActor->VisibilityOff();
1031 myNodeExtActor->VisibilityOff();
1033 my1DActor->VisibilityOff();
1034 my1DExtActor->VisibilityOff();
1036 my2DActor->VisibilityOff();
1037 my2DExtActor->VisibilityOff();
1038 my3DActor->VisibilityOff();
1040 myScalarBarActor->VisibilityOff();
1041 myPointLabels->VisibilityOff();
1042 myCellsLabels->VisibilityOff();
1044 if(GetVisibility()){
1045 if(theIsUpdateRepersentation)
1046 SetRepresentation(GetRepresentation());
1048 if(myControlMode != eNone){
1049 switch(myControlMode){
1051 myNodeExtActor->VisibilityOn();
1055 my1DExtActor->VisibilityOn();
1058 my2DExtActor->VisibilityOn();
1061 case eMultiConnection2D:
1062 my1DExtActor->VisibilityOn();
1064 if(myControlActor->GetUnstructuredGrid()->GetNumberOfCells())
1065 myScalarBarActor->VisibilityOn();
1069 if(myRepresentation != ePoint)
1070 myPickableActor->VisibilityOn();
1072 myNodeActor->VisibilityOn();
1075 if(myEntityMode & eEdges){
1076 my1DActor->VisibilityOn();
1079 if(myEntityMode & eFaces){
1080 my2DActor->VisibilityOn();
1083 if(myEntityMode & eVolumes){
1084 my3DActor->VisibilityOn();
1087 if(myIsPointsLabeled){
1088 myPointLabels->VisibilityOn();
1089 myNodeActor->VisibilityOn();
1092 if(myIsCellsLabeled)
1093 myCellsLabels->VisibilityOn();
1100 void SMESH_ActorDef::SetEntityMode(unsigned int theMode){
1101 myEntityState = eAllEntity;
1103 if(!myVisualObj->GetNbEntities(SMDSAbs_Edge)){
1104 myEntityState &= ~eEdges;
1108 if(!myVisualObj->GetNbEntities(SMDSAbs_Face)){
1109 myEntityState &= ~eFaces;
1113 if(!myVisualObj->GetNbEntities(SMDSAbs_Volume)){
1114 myEntityState &= ~eVolumes;
1115 theMode &= ~eVolumes;
1119 if(myVisualObj->GetNbEntities(SMDSAbs_Edge))
1122 if(myVisualObj->GetNbEntities(SMDSAbs_Face))
1125 if(myVisualObj->GetNbEntities(SMDSAbs_Volume))
1126 theMode |= eVolumes;
1129 myBaseActor->myGeomFilter->SetInside(myEntityMode != myEntityState);
1131 myEntityMode = theMode;
1132 VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
1133 aFilter = myBaseActor->GetExtractUnstructuredGrid();
1134 aFilter->ClearRegisteredCellsWithType();
1135 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
1137 if(myEntityMode & eEdges){
1138 if (MYDEBUG) MESSAGE("EDGES");
1139 aFilter->RegisterCellsWithType(VTK_LINE);
1140 aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
1143 if(myEntityMode & eFaces){
1144 if (MYDEBUG) MESSAGE("FACES");
1145 aFilter->RegisterCellsWithType(VTK_TRIANGLE);
1146 aFilter->RegisterCellsWithType(VTK_POLYGON);
1147 aFilter->RegisterCellsWithType(VTK_QUAD);
1148 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
1149 aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
1152 if(myEntityMode & eVolumes){
1153 if (MYDEBUG) MESSAGE("VOLUMES");
1154 aFilter->RegisterCellsWithType(VTK_TETRA);
1155 aFilter->RegisterCellsWithType(VTK_VOXEL);
1156 aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1157 aFilter->RegisterCellsWithType(VTK_WEDGE);
1158 aFilter->RegisterCellsWithType(VTK_PYRAMID);
1159 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
1160 aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
1161 aFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
1162 aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1165 if (MYDEBUG) MESSAGE(aFilter->GetOutput()->GetNumberOfCells());
1166 SetVisibility(GetVisibility(),false);
1169 void SMESH_ActorDef::SetRepresentation(int theMode){
1170 int aNbEdges = myVisualObj->GetNbEntities(SMDSAbs_Edge);
1171 int aNbFaces = myVisualObj->GetNbEntities(SMDSAbs_Face);
1172 int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume);
1174 myRepresentation = eSurface;
1175 if(!aNbFaces && !aNbVolumes && aNbEdges){
1176 myRepresentation = eEdge;
1177 }else if(!aNbFaces && !aNbVolumes && !aNbEdges){
1178 myRepresentation = ePoint;
1183 if(!aNbFaces && !aNbVolumes && !aNbEdges) return;
1186 if(!aNbFaces && !aNbVolumes) return;
1189 myRepresentation = theMode;
1192 if(!GetUnstructuredGrid()->GetNumberOfCells())
1193 myRepresentation = ePoint;
1196 if(myRepresentation == ePoint){
1204 myPickableActor = myBaseActor;
1205 myNodeActor->SetVisibility(false);
1206 myNodeExtActor->SetVisibility(false);
1207 vtkProperty *aProp = NULL, *aBackProp = NULL;
1208 SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1);
1209 switch(myRepresentation){
1211 myPickableActor = myNodeActor;
1212 myNodeActor->SetVisibility(true);
1214 aProp = aBackProp = myNodeProp;
1215 aReperesent = SMESH_DeviceActor::ePoint;
1218 aProp = aBackProp = myEdgeProp;
1219 aReperesent = SMESH_DeviceActor::eInsideframe;
1222 aProp = mySurfaceProp;
1223 aBackProp = myBackSurfaceProp;
1224 aReperesent = SMESH_DeviceActor::eSurface;
1228 my2DActor->SetProperty(aProp);
1229 my2DActor->SetBackfaceProperty(aBackProp);
1230 my2DActor->SetRepresentation(aReperesent);
1232 my2DExtActor->SetRepresentation(aReperesent);
1234 my3DActor->SetProperty(aProp);
1235 my3DActor->SetBackfaceProperty(aBackProp);
1236 my3DActor->SetRepresentation(aReperesent);
1238 my1DExtActor->SetVisibility(false);
1239 my2DExtActor->SetVisibility(false);
1241 switch(myControlMode){
1243 case eMultiConnection:
1244 aProp = aBackProp = my1DProp;
1245 if(myRepresentation != ePoint)
1246 aReperesent = SMESH_DeviceActor::eInsideframe;
1250 my1DActor->SetProperty(aProp);
1251 my1DActor->SetBackfaceProperty(aBackProp);
1252 my1DActor->SetRepresentation(aReperesent);
1254 my1DExtActor->SetRepresentation(aReperesent);
1256 if(myIsPointsVisible)
1257 myPickableActor = myNodeActor;
1258 if(GetPointRepresentation())
1259 myNodeActor->SetVisibility(true);
1261 SetMapper(myPickableActor->GetMapper());
1263 SetVisibility(GetVisibility(),false);
1269 void SMESH_ActorDef::SetPointRepresentation(bool theIsPointsVisible){
1270 if ( myIsPointsVisible == theIsPointsVisible )
1272 myIsPointsVisible = theIsPointsVisible;
1273 SetRepresentation(GetRepresentation());
1276 bool SMESH_ActorDef::GetPointRepresentation(){
1277 return myIsPointsVisible || myIsPointsLabeled;
1281 void SMESH_ActorDef::UpdateHighlight(){
1282 myHighlitableActor->SetVisibility(false);
1283 myHighlitableActor->SetHighlited(false);
1285 if(myIsHighlighted){
1286 myHighlitableActor->SetProperty(myHighlightProp);
1287 }else if(myIsPreselected){
1288 myHighlitableActor->SetProperty(myPreselectProp);
1291 bool anIsVisible = GetVisibility();
1293 if(myIsHighlighted || myIsPreselected){
1294 if(GetUnstructuredGrid()->GetNumberOfCells()){
1295 myHighlitableActor->SetHighlited(anIsVisible);
1296 myHighlitableActor->SetVisibility(anIsVisible);
1297 myHighlitableActor->GetExtractUnstructuredGrid()->
1298 SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::eCells);
1299 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
1300 }else if(myRepresentation == ePoint || GetPointRepresentation()){
1301 myHighlitableActor->SetHighlited(anIsVisible);
1302 myHighlitableActor->GetExtractUnstructuredGrid()->
1303 SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
1304 myHighlitableActor->SetVisibility(anIsVisible);
1305 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::ePoint);
1311 void SMESH_ActorDef::highlight(bool theHighlight){
1312 if ( myIsHighlighted == theHighlight )
1314 myIsHighlighted = theHighlight;
1319 void SMESH_ActorDef::SetPreSelected(bool thePreselect){
1320 if ( myIsPreselected == thePreselect )
1322 myIsPreselected = thePreselect;
1328 int SMESH_ActorDef::RenderOpaqueGeometry(vtkViewport *vp)
1330 if (myPickableActor->GetIsOpaque())
1332 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1340 int SMESH_ActorDef::RenderTranslucentGeometry(vtkViewport *vp)
1342 if (!myPickableActor->GetIsOpaque())
1344 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1352 void SMESH_ActorDef::Render(vtkRenderer *ren){
1353 unsigned long aTime = myTimeStamp->GetMTime();
1354 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1355 unsigned long aClippingTime = myImplicitBoolean->GetMTime();
1356 if(anObjTime > aTime || aClippingTime > aTime)
1361 void SMESH_ActorDef::Update(){
1362 if(MYDEBUG) MESSAGE("SMESH_ActorDef::Update");
1364 if(GetControlMode() != eNone) {
1365 unsigned long aTime = myTimeStamp->GetMTime();
1366 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1367 if (anObjTime > aTime)
1368 SetControlMode(GetControlMode(),false);
1370 if(myIsPointsLabeled){
1371 SetPointsLabeled(myIsPointsLabeled);
1373 if(myIsCellsLabeled){
1374 SetCellsLabeled(myIsCellsLabeled);
1376 if(myIsFacesOriented){
1377 SetFacesOriented(myIsFacesOriented);
1379 SetEntityMode(GetEntityMode());
1380 SetVisibility(GetVisibility());
1382 myTimeStamp->Modified();
1387 void SMESH_ActorDef::ReleaseGraphicsResources(vtkWindow *renWin){
1388 SALOME_Actor::ReleaseGraphicsResources(renWin);
1390 myPickableActor->ReleaseGraphicsResources(renWin);
1394 static void GetColor(vtkProperty *theProperty, vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1395 vtkFloatingPointType* aColor = theProperty->GetColor();
1402 void SMESH_ActorDef::SetOpacity(vtkFloatingPointType theValue){
1403 mySurfaceProp->SetOpacity(theValue);
1404 myBackSurfaceProp->SetOpacity(theValue);
1405 myEdgeProp->SetOpacity(theValue);
1406 myNodeProp->SetOpacity(theValue);
1408 my1DProp->SetOpacity(theValue);
1412 vtkFloatingPointType SMESH_ActorDef::GetOpacity(){
1413 return mySurfaceProp->GetOpacity();
1417 void SMESH_ActorDef::SetSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1418 mySurfaceProp->SetColor(r,g,b);
1422 void SMESH_ActorDef::GetSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1423 ::GetColor(mySurfaceProp,r,g,b);
1424 my2DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1427 void SMESH_ActorDef::SetBackSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1428 myBackSurfaceProp->SetColor(r,g,b);
1432 void SMESH_ActorDef::GetBackSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1433 ::GetColor(myBackSurfaceProp,r,g,b);
1436 void SMESH_ActorDef::SetEdgeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1437 myEdgeProp->SetColor(r,g,b);
1438 my1DProp->SetColor(r,g,b);
1439 my1DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1443 void SMESH_ActorDef::GetEdgeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1444 ::GetColor(myEdgeProp,r,g,b);
1447 void SMESH_ActorDef::SetNodeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1448 myNodeProp->SetColor(r,g,b);
1449 myNodeExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1453 void SMESH_ActorDef::GetNodeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1454 ::GetColor(myNodeProp,r,g,b);
1457 void SMESH_ActorDef::SetHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1458 myHighlightProp->SetColor(r,g,b);
1462 void SMESH_ActorDef::GetHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1463 ::GetColor(myHighlightProp,r,g,b);
1466 void SMESH_ActorDef::SetPreHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1467 myPreselectProp->SetColor(r,g,b);
1471 void SMESH_ActorDef::GetPreHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1472 ::GetColor(myPreselectProp,r,g,b);
1476 vtkFloatingPointType SMESH_ActorDef::GetLineWidth(){
1477 return myEdgeProp->GetLineWidth();
1481 void SMESH_ActorDef::SetLineWidth(vtkFloatingPointType theVal){
1482 myEdgeProp->SetLineWidth(theVal);
1484 my1DProp->SetLineWidth(theVal + aLineWidthInc);
1485 my1DExtProp->SetLineWidth(theVal + aLineWidthInc);
1491 void SMESH_ActorDef::SetNodeSize(vtkFloatingPointType theVal){
1492 myNodeProp->SetPointSize(theVal);
1493 myNodeExtProp->SetPointSize(theVal);
1494 myHighlightProp->SetPointSize(theVal);
1495 myPreselectProp->SetPointSize(theVal);
1497 my1DProp->SetPointSize(theVal + aPointSizeInc);
1498 my1DExtProp->SetPointSize(theVal + aPointSizeInc);
1503 vtkFloatingPointType SMESH_ActorDef::GetNodeSize(){
1504 return myNodeProp->GetPointSize();
1507 int SMESH_ActorDef::GetObjDimension( const int theObjId )
1509 return myVisualObj->GetElemDimension( theObjId );
1514 IsImplicitFunctionUsed() const
1516 return myBaseActor->IsImplicitFunctionUsed();
1521 SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
1523 myNodeActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1524 myBaseActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1526 myHighlitableActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1528 myNodeExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1530 my1DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1531 my1DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1533 my2DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1534 my2DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1535 my3DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1540 AddClippingPlane(vtkPlane* thePlane)
1543 myImplicitBoolean->GetFunction()->AddItem(thePlane);
1544 myCippingPlaneCont.push_back(thePlane);
1545 if(!IsImplicitFunctionUsed())
1546 SetImplicitFunctionUsed(true);
1548 return myCippingPlaneCont.size();
1553 RemoveAllClippingPlanes()
1555 myImplicitBoolean->GetFunction()->RemoveAllItems();
1556 myImplicitBoolean->GetFunction()->Modified(); // VTK bug
1557 myCippingPlaneCont.clear();
1558 SetImplicitFunctionUsed(false);
1563 GetNumberOfClippingPlanes()
1565 return myCippingPlaneCont.size();
1570 GetClippingPlane(vtkIdType theID)
1572 if(theID >= myCippingPlaneCont.size())
1574 return myCippingPlaneCont[theID].Get();
1578 static void ComputeBoundsParam(vtkDataSet* theDataSet,
1579 vtkFloatingPointType theDirection[3], vtkFloatingPointType theMinPnt[3],
1580 vtkFloatingPointType& theMaxBoundPrj, vtkFloatingPointType& theMinBoundPrj)
1582 vtkFloatingPointType aBounds[6];
1583 theDataSet->GetBounds(aBounds);
1585 //Enlarge bounds in order to avoid conflicts of precision
1586 for(int i = 0; i < 6; i += 2){
1587 static double EPS = 1.0E-3;
1588 vtkFloatingPointType aDelta = (aBounds[i+1] - aBounds[i])*EPS;
1589 aBounds[i] -= aDelta;
1590 aBounds[i+1] += aDelta;
1593 vtkFloatingPointType aBoundPoints[8][3] = { {aBounds[0],aBounds[2],aBounds[4]},
1594 {aBounds[1],aBounds[2],aBounds[4]},
1595 {aBounds[0],aBounds[3],aBounds[4]},
1596 {aBounds[1],aBounds[3],aBounds[4]},
1597 {aBounds[0],aBounds[2],aBounds[5]},
1598 {aBounds[1],aBounds[2],aBounds[5]},
1599 {aBounds[0],aBounds[3],aBounds[5]},
1600 {aBounds[1],aBounds[3],aBounds[5]}};
1602 int aMaxId = 0, aMinId = aMaxId;
1603 theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
1604 theMinBoundPrj = theMaxBoundPrj;
1605 for(int i = 1; i < 8; i++){
1606 vtkFloatingPointType aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
1607 if(theMaxBoundPrj < aTmp){
1608 theMaxBoundPrj = aTmp;
1611 if(theMinBoundPrj > aTmp){
1612 theMinBoundPrj = aTmp;
1616 vtkFloatingPointType *aMinPnt = aBoundPoints[aMaxId];
1617 theMinPnt[0] = aMinPnt[0];
1618 theMinPnt[1] = aMinPnt[1];
1619 theMinPnt[2] = aMinPnt[2];
1623 static void DistanceToPosition(vtkDataSet* theDataSet,
1624 vtkFloatingPointType theDirection[3], vtkFloatingPointType theDist, vtkFloatingPointType thePos[3])
1626 vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1627 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1628 vtkFloatingPointType aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
1629 thePos[0] = aMinPnt[0]-theDirection[0]*aLength;
1630 thePos[1] = aMinPnt[1]-theDirection[1]*aLength;
1631 thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
1635 static void PositionToDistance(vtkDataSet* theDataSet,
1636 vtkFloatingPointType theDirection[3], vtkFloatingPointType thePos[3], vtkFloatingPointType& theDist)
1638 vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1639 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1640 vtkFloatingPointType aPrj = vtkMath::Dot(theDirection,thePos);
1641 theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
1645 void SMESH_ActorDef::SetPlaneParam(vtkFloatingPointType theDir[3], vtkFloatingPointType theDist, vtkPlane* thePlane)
1647 thePlane->SetNormal(theDir);
1648 vtkFloatingPointType anOrigin[3];
1649 ::DistanceToPosition(GetUnstructuredGrid(),theDir,theDist,anOrigin);
1650 thePlane->SetOrigin(anOrigin);
1654 void SMESH_ActorDef::GetPlaneParam(vtkFloatingPointType theDir[3], vtkFloatingPointType& theDist, vtkPlane* thePlane)
1656 thePlane->GetNormal(theDir);
1658 vtkFloatingPointType anOrigin[3];
1659 thePlane->GetOrigin(anOrigin);
1660 ::PositionToDistance(GetUnstructuredGrid(),theDir,anOrigin,theDist);
1663 void SMESH_ActorDef::UpdateScalarBar()
1665 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
1669 vtkTextProperty* aScalarBarTitleProp = vtkTextProperty::New();
1671 QColor aTColor = mgr->colorValue( "SMESH", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
1672 aScalarBarTitleProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1674 aScalarBarTitleProp->SetFontFamilyToArial();
1676 if ( mgr->hasValue( "SMESH", "scalar_bar_title_font" ) )
1678 QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
1679 if ( f.family() == "Arial" )
1680 aScalarBarTitleProp->SetFontFamilyToArial();
1681 else if ( f.family() == "Courier" )
1682 aScalarBarTitleProp->SetFontFamilyToCourier();
1683 else if ( f.family() == "Times" )
1684 aScalarBarTitleProp->SetFontFamilyToTimes();
1687 aScalarBarTitleProp->BoldOn();
1689 aScalarBarTitleProp->BoldOff();
1692 aScalarBarTitleProp->ItalicOn();
1694 aScalarBarTitleProp->ItalicOff();
1697 aScalarBarTitleProp->ShadowOn();
1699 aScalarBarTitleProp->ShadowOff();
1702 myScalarBarActor->SetTitleTextProperty( aScalarBarTitleProp );
1703 aScalarBarTitleProp->Delete();
1705 vtkTextProperty* aScalarBarLabelProp = vtkTextProperty::New();
1707 aTColor = mgr->colorValue( "SMESH", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
1708 aScalarBarLabelProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1710 aScalarBarLabelProp->SetFontFamilyToArial();
1711 if( mgr->hasValue( "SMESH", "scalar_bar_label_font" ) )
1713 QFont f = mgr->fontValue( "SMESH", "scalar_bar_label_font" );
1714 if( f.family() == "Arial" )
1715 aScalarBarLabelProp->SetFontFamilyToArial();
1716 else if( f.family() == "Courier" )
1717 aScalarBarLabelProp->SetFontFamilyToCourier();
1718 else if( f.family() == "Times" )
1719 aScalarBarLabelProp->SetFontFamilyToTimes();
1722 aScalarBarLabelProp->BoldOn();
1724 aScalarBarLabelProp->BoldOff();
1727 aScalarBarLabelProp->ItalicOn();
1729 aScalarBarLabelProp->ItalicOff();
1732 aScalarBarLabelProp->ShadowOn();
1734 aScalarBarLabelProp->ShadowOff();
1737 myScalarBarActor->SetLabelTextProperty( aScalarBarLabelProp );
1738 aScalarBarLabelProp->Delete();
1740 bool horiz = ( mgr->integerValue( "SMESH", "scalar_bar_orientation" ) == 1 );
1741 QString name = QString( "scalar_bar_%1_" ).arg( horiz ? "horizontal" : "vertical" );
1743 myScalarBarActor->SetOrientationToHorizontal();
1745 myScalarBarActor->SetOrientationToVertical();
1748 vtkFloatingPointType aXVal = horiz ? 0.20 : 0.01;
1749 if( mgr->hasValue( "SMESH", name + "x" ) )
1750 aXVal = mgr->doubleValue( "SMESH", name + "x", aXVal );
1752 vtkFloatingPointType aYVal = horiz ? 0.01 : 0.1;
1753 if( mgr->hasValue( "SMESH", name + "y" ) )
1754 aYVal = mgr->doubleValue( "SMESH", name + "y", aYVal );
1755 myScalarBarActor->SetPosition( aXVal, aYVal );
1757 vtkFloatingPointType aWVal = horiz ? 0.60 : 0.10;
1758 if( mgr->hasValue( "SMESH", name + "width" ) )
1759 aWVal = mgr->doubleValue( "SMESH", name + "width", aWVal );
1760 myScalarBarActor->SetWidth( aWVal );
1762 vtkFloatingPointType aHVal = horiz ? 0.12 : 0.80;
1763 if( mgr->hasValue( "SMESH", name + "height" ) )
1764 aHVal = mgr->doubleValue( "SMESH", name + "height", aHVal );
1765 myScalarBarActor->SetHeight( aHVal );
1768 if( mgr->hasValue( "SMESH", "scalar_bar_num_labels" ) )
1769 anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_labels", anIntVal );
1770 myScalarBarActor->SetNumberOfLabels( anIntVal == 0 ? 5: anIntVal );
1773 if( mgr->hasValue( "SMESH", "scalar_bar_num_colors" ) )
1774 anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_colors", anIntVal );
1775 myScalarBarActor->SetMaximumNumberOfColors( anIntVal == 0 ? 64 : anIntVal );