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_ObjectDef.h"
32 #include "SMESH_ControlsDef.hxx"
33 #include "VTKViewer_ExtractUnstructuredGrid.h"
34 #include "VTKViewer_FramedTextActor.h"
35 #include "SALOME_InteractiveObject.hxx"
37 #include "SUIT_Session.h"
38 #include "SUIT_ResourceMgr.h"
40 #include <vtkProperty.h>
41 #include <vtkTimeStamp.h>
42 #include <vtkObjectFactory.h>
43 #include <vtkShrinkPolyData.h>
44 #include <vtkMergeFilter.h>
46 #include <vtkMatrix4x4.h>
47 #include <vtkUnstructuredGrid.h>
48 #include <vtkPointData.h>
49 #include <vtkCellData.h>
51 #include <vtkMapper.h>
52 #include <vtkRenderer.h>
55 #include <vtkIdList.h>
56 #include <vtkIntArray.h>
58 #include <vtkActor2D.h>
59 #include <vtkProperty2D.h>
60 #include <vtkPolyData.h>
61 #include <vtkMaskPoints.h>
62 #include <vtkCellCenters.h>
63 #include <vtkTextProperty.h>
64 #include <vtkLabeledDataMapper.h>
65 #include <vtkSelectVisiblePoints.h>
67 #include <vtkScalarBarActor.h>
68 #include <vtkLookupTable.h>
72 #include <vtkImplicitBoolean.h>
73 #include <vtkImplicitFunctionCollection.h>
75 #include "utilities.h"
78 static int MYDEBUG = 1;
80 static int MYDEBUG = 0;
83 static int aLineWidthInc = 2;
84 static int aPointSizeInc = 2;
87 SMESH_ActorDef* SMESH_ActorDef::New(){
88 return new SMESH_ActorDef();
92 SMESH_Actor* SMESH_Actor::New(TVisualObjPtr theVisualObj,
97 SMESH_ActorDef* anActor = SMESH_ActorDef::New();
98 if(!anActor->Init(theVisualObj,theEntry,theName,theIsClear)){
103 anActor->UpdateScalarBar();
108 SMESH_ActorDef::SMESH_ActorDef()
110 if(MYDEBUG) MESSAGE("SMESH_ActorDef - "<<this);
112 myTimeStamp = vtkTimeStamp::New();
114 myIsPointsVisible = false;
116 myIsShrinkable = false;
119 myIsFacesOriented = false;
121 myControlsPrecision = -1;
122 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
124 if ( mgr && mgr->booleanValue( "SMESH", "use_precision", false ) )
125 myControlsPrecision = mgr->integerValue( "SMESH", "controls_precision", -1);
127 vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
128 vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
130 vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
131 VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
133 //Definition 2D and 3D divices of the actor
134 //-----------------------------------------
135 vtkFloatingPointType anRGB[3] = {1,1,1};
136 mySurfaceProp = vtkProperty::New();
137 SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
138 mySurfaceProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
140 myBackSurfaceProp = vtkProperty::New();
141 SMESH::GetColor( "SMESH", "backface_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 0, 255 ) );
142 myBackSurfaceProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
144 my2DActor = SMESH_DeviceActor::New();
145 my2DActor->SetUserMatrix(aMatrix);
146 my2DActor->PickableOff();
147 my2DActor->SetProperty(mySurfaceProp);
148 my2DActor->SetBackfaceProperty(myBackSurfaceProp);
149 my2DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
150 aFilter = my2DActor->GetExtractUnstructuredGrid();
151 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
152 aFilter->RegisterCellsWithType(VTK_TRIANGLE);
153 aFilter->RegisterCellsWithType(VTK_POLYGON);
154 aFilter->RegisterCellsWithType(VTK_QUAD);
155 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
156 aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
158 my2DExtProp = vtkProperty::New();
159 my2DExtProp->DeepCopy(mySurfaceProp);
160 SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
161 anRGB[0] = 1 - anRGB[0];
162 anRGB[1] = 1 - anRGB[1];
163 anRGB[2] = 1 - anRGB[2];
164 my2DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
166 my2DExtActor = SMESH_DeviceActor::New();
167 my2DExtActor->SetUserMatrix(aMatrix);
168 my2DExtActor->PickableOff();
169 my2DExtActor->SetProperty(my2DExtProp);
170 my2DExtActor->SetBackfaceProperty(my2DExtProp);
171 my2DExtActor->SetRepresentation(SMESH_DeviceActor::eInsideframe);
172 aFilter = my2DExtActor->GetExtractUnstructuredGrid();
173 aFilter->RegisterCellsWithType(VTK_TRIANGLE);
174 aFilter->RegisterCellsWithType(VTK_POLYGON);
175 aFilter->RegisterCellsWithType(VTK_QUAD);
176 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
177 aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
179 my3DActor = SMESH_DeviceActor::New();
180 my3DActor->SetUserMatrix(aMatrix);
181 my3DActor->PickableOff();
182 my3DActor->SetProperty(mySurfaceProp);
183 my3DActor->SetBackfaceProperty(myBackSurfaceProp);
184 my3DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
185 aFilter = my3DActor->GetExtractUnstructuredGrid();
186 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
187 aFilter->RegisterCellsWithType(VTK_TETRA);
188 aFilter->RegisterCellsWithType(VTK_VOXEL);
189 aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
190 aFilter->RegisterCellsWithType(VTK_WEDGE);
191 aFilter->RegisterCellsWithType(VTK_PYRAMID);
192 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
193 aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
194 aFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
195 aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
197 //Definition 1D divice of the actor
198 //---------------------------------
199 myEdgeProp = vtkProperty::New();
200 myEdgeProp->SetAmbient(1.0);
201 myEdgeProp->SetDiffuse(0.0);
202 myEdgeProp->SetSpecular(0.0);
203 SMESH::GetColor( "SMESH", "outline_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
204 myEdgeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
205 myEdgeProp->SetLineWidth(aLineWidth);
207 my1DActor = SMESH_DeviceActor::New();
208 my1DActor->SetUserMatrix(aMatrix);
209 my1DActor->PickableOff();
210 my1DActor->SetHighlited(true);
211 my1DActor->SetProperty(myEdgeProp);
212 my1DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
213 aFilter = my1DActor->GetExtractUnstructuredGrid();
214 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
215 aFilter->RegisterCellsWithType(VTK_LINE);
216 aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
218 my1DProp = vtkProperty::New();
219 my1DProp->DeepCopy(myEdgeProp);
220 my1DProp->SetLineWidth(aLineWidth + aLineWidthInc);
221 my1DProp->SetPointSize(aPointSize);
223 my1DExtProp = vtkProperty::New();
224 my1DExtProp->DeepCopy(myEdgeProp);
225 anRGB[0] = 1 - anRGB[0];
226 anRGB[1] = 1 - anRGB[1];
227 anRGB[2] = 1 - anRGB[2];
228 my1DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
229 my1DExtProp->SetLineWidth(aLineWidth + aLineWidthInc);
230 my1DExtProp->SetPointSize(aPointSize + aPointSizeInc);
232 my1DExtActor = SMESH_DeviceActor::New();
233 my1DExtActor->SetUserMatrix(aMatrix);
234 my1DExtActor->PickableOff();
235 my1DExtActor->SetHighlited(true);
236 my1DExtActor->SetVisibility(false);
237 my1DExtActor->SetProperty(my1DExtProp);
238 my1DExtActor->SetRepresentation(SMESH_DeviceActor::eInsideframe);
239 aFilter = my1DExtActor->GetExtractUnstructuredGrid();
240 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
241 aFilter->RegisterCellsWithType(VTK_LINE);
242 aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
245 //Definition 0D divice of the actor
246 //---------------------------------
247 myNodeProp = vtkProperty::New();
248 SMESH::GetColor( "SMESH", "node_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 0, 0 ) );
249 myNodeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
250 myNodeProp->SetPointSize(aPointSize);
252 myNodeActor = SMESH_DeviceActor::New();
253 myNodeActor->SetUserMatrix(aMatrix);
254 myNodeActor->SetStoreClippingMapping(true);
255 myNodeActor->PickableOff();
256 myNodeActor->SetVisibility(false);
257 myNodeActor->SetProperty(myNodeProp);
258 myNodeActor->SetRepresentation(SMESH_DeviceActor::ePoint);
259 aFilter = myNodeActor->GetExtractUnstructuredGrid();
260 aFilter->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
262 myNodeExtProp = vtkProperty::New();
263 myNodeExtProp->DeepCopy(myNodeProp);
264 anRGB[0] = 1 - anRGB[0];
265 anRGB[1] = 1 - anRGB[1];
266 anRGB[2] = 1 - anRGB[2];
267 myNodeExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
268 myNodeExtProp->SetPointSize(aPointSize);
270 myNodeExtActor = SMESH_DeviceActor::New();
271 myNodeExtActor->SetUserMatrix(aMatrix);
272 myNodeExtActor->SetStoreClippingMapping(true);
273 myNodeExtActor->PickableOff();
274 myNodeExtActor->SetHighlited(true);
275 myNodeExtActor->SetVisibility(false);
276 myNodeExtActor->SetProperty(myNodeExtProp);
277 myNodeExtActor->SetRepresentation(SMESH_DeviceActor::ePoint);
278 aFilter = myNodeExtActor->GetExtractUnstructuredGrid();
279 aFilter->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
280 aFilter->RegisterCellsWithType(VTK_VERTEX);
282 //Definition of Pickable and Highlitable engines
283 //----------------------------------------------
285 myBaseActor = SMESH_DeviceActor::New();
286 myBaseActor->SetUserMatrix(aMatrix);
287 myBaseActor->SetStoreGemetryMapping(true);
288 myBaseActor->GetProperty()->SetOpacity(0.0);
290 myPickableActor = myBaseActor;
292 myHighlightProp = vtkProperty::New();
293 myHighlightProp->SetAmbient(1.0);
294 myHighlightProp->SetDiffuse(0.0);
295 myHighlightProp->SetSpecular(0.0);
296 SMESH::GetColor( "SMESH", "selection_object_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
297 myHighlightProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
298 myHighlightProp->SetPointSize(aPointSize);
299 myHighlightProp->SetRepresentation(1);
301 myPreselectProp = vtkProperty::New();
302 myPreselectProp->SetAmbient(1.0);
303 myPreselectProp->SetDiffuse(0.0);
304 myPreselectProp->SetSpecular(0.0);
305 SMESH::GetColor( "SMESH", "highlight_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 255, 255 ) );
306 myPreselectProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
307 myPreselectProp->SetPointSize(aPointSize);
308 myPreselectProp->SetRepresentation(1);
310 myHighlitableActor = SMESH_DeviceActor::New();
311 myHighlitableActor->SetUserMatrix(aMatrix);
312 myHighlitableActor->PickableOff();
313 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
318 myControlMode = eNone;
319 myControlActor = my2DActor;
321 //Definition of myScalarBarActor
322 //------------------------------
323 myLookupTable = vtkLookupTable::New();
324 //Fix for Bug PAL5195 - SMESH764:
325 //Controls - Aspect Ratio: incorrect colors of the best and worst values
326 myLookupTable->SetHueRange(0.667,0.0);
328 myScalarBarActor = vtkScalarBarActor::New();
329 myScalarBarActor->SetVisibility(false);
330 myScalarBarActor->SetLookupTable(myLookupTable);
333 //Incorrect "Min value" in Scalar Bar in Mesh:
334 // myScalarBarActor->SetLabelFormat("%.4g");
335 // changes was commented because of regression bug IPAL 19981
337 mgr = SUIT_Session::session()->resourceMgr();
341 //Definition of points numbering pipeline
342 //---------------------------------------
343 myPointsNumDataSet = vtkUnstructuredGrid::New();
345 myPtsMaskPoints = vtkMaskPoints::New();
346 myPtsMaskPoints->SetInput(myPointsNumDataSet);
347 myPtsMaskPoints->SetOnRatio(1);
349 myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
350 myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
351 myPtsSelectVisiblePoints->SelectInvisibleOff();
352 myPtsSelectVisiblePoints->SetTolerance(0.1);
354 myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
355 myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
356 myPtsLabeledDataMapper->SetLabelFormat("%g");
357 myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
359 vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
360 aPtsTextProp->SetFontFamilyToTimes();
361 static int aPointsFontSize = 10;
362 aPtsTextProp->SetFontSize(aPointsFontSize);
363 aPtsTextProp->SetBold(1);
364 aPtsTextProp->SetItalic(0);
365 aPtsTextProp->SetShadow(0);
366 myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
367 aPtsTextProp->Delete();
369 myEntityMode = eAllEntity;
371 myIsPointsLabeled = false;
373 myPointLabels = vtkActor2D::New();
374 myPointLabels->SetMapper(myPtsLabeledDataMapper);
375 myPointLabels->GetProperty()->SetColor(1,1,1);
376 myPointLabels->SetVisibility(myIsPointsLabeled);
379 //Definition of cells numbering pipeline
380 //---------------------------------------
381 myCellsNumDataSet = vtkUnstructuredGrid::New();
383 myCellCenters = vtkCellCenters::New();
384 myCellCenters->SetInput(myCellsNumDataSet);
386 myClsMaskPoints = vtkMaskPoints::New();
387 myClsMaskPoints->SetInput(myCellCenters->GetOutput());
388 myClsMaskPoints->SetOnRatio(1);
390 myClsSelectVisiblePoints = vtkSelectVisiblePoints::New();
391 myClsSelectVisiblePoints->SetInput(myClsMaskPoints->GetOutput());
392 myClsSelectVisiblePoints->SelectInvisibleOff();
393 myClsSelectVisiblePoints->SetTolerance(0.1);
395 myClsLabeledDataMapper = vtkLabeledDataMapper::New();
396 myClsLabeledDataMapper->SetInput(myClsSelectVisiblePoints->GetOutput());
397 myClsLabeledDataMapper->SetLabelFormat("%g");
398 myClsLabeledDataMapper->SetLabelModeToLabelScalars();
400 vtkTextProperty* aClsTextProp = vtkTextProperty::New();
401 aClsTextProp->SetFontFamilyToTimes();
402 static int aCellsFontSize = 12;
403 aClsTextProp->SetFontSize(aCellsFontSize);
404 aClsTextProp->SetBold(1);
405 aClsTextProp->SetItalic(0);
406 aClsTextProp->SetShadow(0);
407 myClsLabeledDataMapper->SetLabelTextProperty(aClsTextProp);
408 aClsTextProp->Delete();
410 myIsCellsLabeled = false;
412 myCellsLabels = vtkActor2D::New();
413 myCellsLabels->SetMapper(myClsLabeledDataMapper);
414 myCellsLabels->GetProperty()->SetColor(0,1,0);
415 myCellsLabels->SetVisibility(myIsCellsLabeled);
418 myImplicitBoolean = vtkImplicitBoolean::New();
419 myImplicitBoolean->SetOperationTypeToIntersection();
423 //Quadratic 2D elements representation
424 //-----------------------------------------------------------------------------
425 int aQuadratic2DMode = mgr->integerValue( "SMESH", "quadratic_mode", 0);
426 if(aQuadratic2DMode == 0){
427 myHighlitableActor->SetQuadraticArcMode(false);
428 my2DActor->SetQuadraticArcMode(false);
429 my1DActor->SetQuadraticArcMode(false);
431 else if(aQuadratic2DMode == 1){
432 myHighlitableActor->SetQuadraticArcMode(true);
433 my2DActor->SetQuadraticArcMode(true);
434 my1DActor->SetQuadraticArcMode(true);
437 int aQuadraticAngle = mgr->integerValue( "SMESH", "max_angle", 2);
438 myHighlitableActor->SetQuadraticArcAngle(aQuadraticAngle);
439 my2DActor->SetQuadraticArcAngle(aQuadraticAngle);
441 // Set color of the name actor
442 SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
443 myNameActor->SetBackgroundColor(anRGB[0], anRGB[1], anRGB[2]);
447 SMESH_ActorDef::~SMESH_ActorDef()
449 if(MYDEBUG) MESSAGE("~SMESH_ActorDef - "<<this);
451 myScalarBarActor->Delete();
452 myLookupTable->Delete();
454 mySurfaceProp->Delete();
455 myBackSurfaceProp->Delete();
457 myEdgeProp->Delete();
458 myHighlightProp->Delete();
459 myPreselectProp->Delete();
461 myNodeProp->Delete();
462 myNodeExtProp->Delete();
467 my1DExtProp->Delete();
468 my1DExtActor->Delete();
471 my2DExtProp->Delete();
472 my2DExtActor->Delete();
475 myNodeActor->Delete();
476 myBaseActor->Delete();
478 myNodeExtActor->Delete();
480 myHighlitableActor->Delete();
482 //Deleting of pints numbering pipeline
483 //---------------------------------------
484 myPointsNumDataSet->Delete();
486 // commented: porting to vtk 5.0
487 // myPtsLabeledDataMapper->RemoveAllInputs();
488 myPtsLabeledDataMapper->Delete();
490 // commented: porting to vtk 5.0
491 // myPtsSelectVisiblePoints->UnRegisterAllOutputs();
492 myPtsSelectVisiblePoints->Delete();
494 // commented: porting to vtk 5.0
495 // myPtsMaskPoints->UnRegisterAllOutputs();
496 myPtsMaskPoints->Delete();
498 myPointLabels->Delete();
501 //Deleting of cells numbering pipeline
502 //---------------------------------------
503 myCellsNumDataSet->Delete();
505 myClsLabeledDataMapper->RemoveAllInputs();
506 myClsLabeledDataMapper->Delete();
508 // commented: porting to vtk 5.0
509 // myClsSelectVisiblePoints->UnRegisterAllOutputs();
510 myClsSelectVisiblePoints->Delete();
512 // commented: porting to vtk 5.0
513 // myClsMaskPoints->UnRegisterAllOutputs();
514 myClsMaskPoints->Delete();
516 // commented: porting to vtk 5.0
517 // myCellCenters->UnRegisterAllOutputs();
518 myCellCenters->Delete();
520 myCellsLabels->Delete();
522 myImplicitBoolean->Delete();
524 myTimeStamp->Delete();
528 void SMESH_ActorDef::SetPointsLabeled( bool theIsPointsLabeled )
530 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
532 myIsPointsLabeled = theIsPointsLabeled && aGrid->GetNumberOfPoints();
534 if ( myIsPointsLabeled )
536 myPointsNumDataSet->ShallowCopy(aGrid);
537 vtkDataSet *aDataSet = myPointsNumDataSet;
539 int aNbElem = aDataSet->GetNumberOfPoints();
541 vtkIntArray *anArray = vtkIntArray::New();
542 anArray->SetNumberOfValues( aNbElem );
544 for ( int anId = 0; anId < aNbElem; anId++ )
546 int aSMDSId = myVisualObj->GetNodeObjId( anId );
547 anArray->SetValue( anId, aSMDSId );
550 aDataSet->GetPointData()->SetScalars( anArray );
552 myPtsMaskPoints->SetInput( aDataSet );
553 myPointLabels->SetVisibility( GetVisibility() );
557 myPointLabels->SetVisibility( false );
559 SetRepresentation(GetRepresentation());
560 myTimeStamp->Modified();
564 void SMESH_ActorDef::SetCellsLabeled(bool theIsCellsLabeled)
566 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
567 myIsCellsLabeled = theIsCellsLabeled && aGrid->GetNumberOfPoints();
568 if(myIsCellsLabeled){
569 myCellsNumDataSet->ShallowCopy(aGrid);
570 vtkDataSet *aDataSet = myCellsNumDataSet;
571 int aNbElem = aDataSet->GetNumberOfCells();
572 vtkIntArray *anArray = vtkIntArray::New();
573 anArray->SetNumberOfValues(aNbElem);
574 for(int anId = 0; anId < aNbElem; anId++){
575 int aSMDSId = myVisualObj->GetElemObjId(anId);
576 anArray->SetValue(anId,aSMDSId);
578 aDataSet->GetCellData()->SetScalars(anArray);
579 myCellCenters->SetInput(aDataSet);
580 myCellsLabels->SetVisibility(GetVisibility());
582 myCellsLabels->SetVisibility(false);
584 myTimeStamp->Modified();
588 void SMESH_ActorDef::SetFacesOriented(bool theIsFacesOriented)
590 myIsFacesOriented = theIsFacesOriented;
592 my2DActor->SetFacesOriented(theIsFacesOriented);
593 my3DActor->SetFacesOriented(theIsFacesOriented);
595 myTimeStamp->Modified();
598 bool SMESH_ActorDef::GetFacesOriented()
600 return myIsFacesOriented;
606 SetControlMode(eControl theMode)
608 SetControlMode(theMode,true);
614 SetControlMode(eControl theMode,
615 bool theCheckEntityMode)
617 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
621 myControlMode = eNone;
622 theCheckEntityMode &= mgr->booleanValue( "SMESH", "display_entity", false );
624 my1DActor->GetMapper()->SetScalarVisibility(false);
625 my2DActor->GetMapper()->SetScalarVisibility(false);
626 my3DActor->GetMapper()->SetScalarVisibility(false);
627 myScalarBarActor->SetVisibility(false);
629 bool anIsScalarVisible = theMode > eNone;
631 if(anIsScalarVisible){
632 SMESH::Controls::FunctorPtr aFunctor;
636 SMESH::Controls::Length* aControl = new SMESH::Controls::Length();
637 aControl->SetPrecision( myControlsPrecision );
638 aFunctor.reset( aControl );
639 myControlActor = my1DActor;
644 aFunctor.reset(new SMESH::Controls::Length2D());
645 myControlActor = my2DActor;
649 aFunctor.reset(new SMESH::Controls::FreeBorders());
650 myControlActor = my1DActor;
653 aFunctor.reset(new SMESH::Controls::FreeEdges());
654 myControlActor = my2DActor;
657 aFunctor.reset(new SMESH::Controls::FreeNodes());
658 myControlActor = myNodeActor;
661 aFunctor.reset(new SMESH::Controls::FreeFaces());
662 myControlActor = my2DActor;
664 case eMultiConnection:
665 aFunctor.reset(new SMESH::Controls::MultiConnection());
666 myControlActor = my1DActor;
668 case eMultiConnection2D:
669 aFunctor.reset(new SMESH::Controls::MultiConnection2D());
670 myControlActor = my2DActor;
674 SMESH::Controls::Area* aControl = new SMESH::Controls::Area();
675 aControl->SetPrecision( myControlsPrecision );
676 aFunctor.reset( aControl );
677 myControlActor = my2DActor;
682 SMESH::Controls::Taper* aControl = new SMESH::Controls::Taper();
683 aControl->SetPrecision( myControlsPrecision );
684 aFunctor.reset( aControl );
685 myControlActor = my2DActor;
690 SMESH::Controls::AspectRatio* aControl = new SMESH::Controls::AspectRatio();
691 aControl->SetPrecision( myControlsPrecision );
692 aFunctor.reset( aControl );
693 myControlActor = my2DActor;
698 SMESH::Controls::AspectRatio3D* aControl = new SMESH::Controls::AspectRatio3D();
699 aControl->SetPrecision( myControlsPrecision );
700 aFunctor.reset( aControl );
701 myControlActor = my3DActor;
706 SMESH::Controls::Volume* aControl = new SMESH::Controls::Volume();
707 aControl->SetPrecision( myControlsPrecision );
708 aFunctor.reset( aControl );
709 myControlActor = my3DActor;
714 SMESH::Controls::MinimumAngle* aControl = new SMESH::Controls::MinimumAngle();
715 aControl->SetPrecision( myControlsPrecision );
716 aFunctor.reset( aControl );
717 myControlActor = my2DActor;
722 SMESH::Controls::Warping* aControl = new SMESH::Controls::Warping();
723 aControl->SetPrecision( myControlsPrecision );
724 aFunctor.reset( aControl );
725 myControlActor = my2DActor;
730 SMESH::Controls::Skew* aControl = new SMESH::Controls::Skew();
731 aControl->SetPrecision( myControlsPrecision );
732 aFunctor.reset( aControl );
733 myControlActor = my2DActor;
740 vtkUnstructuredGrid* aGrid = myControlActor->GetUnstructuredGrid();
741 vtkIdType aNbCells = aGrid->GetNumberOfCells();
743 myControlMode = theMode;
744 switch(myControlMode){
746 myNodeExtActor->SetExtControlMode(aFunctor);
750 my1DExtActor->SetExtControlMode(aFunctor);
753 my2DExtActor->SetExtControlMode(aFunctor);
756 case eMultiConnection2D:
757 my1DExtActor->SetExtControlMode(aFunctor,myScalarBarActor,myLookupTable);
760 myControlActor->SetControlMode(aFunctor,myScalarBarActor,myLookupTable);
764 if(theCheckEntityMode){
765 if(myControlActor == my1DActor)
766 SetEntityMode(eEdges);
767 else if(myControlActor == my2DActor){
768 switch(myControlMode){
772 case eMultiConnection2D:
773 //SetEntityMode(eEdges);
774 SetEntityMode(eFaces);
777 SetEntityMode(eFaces);
779 }else if(myControlActor == my3DActor)
780 SetEntityMode(eVolumes);
783 }else if(theCheckEntityMode){
784 myEntityMode = eAllEntity;
787 SetRepresentation(GetRepresentation());
789 myTimeStamp->Modified();
794 void SMESH_ActorDef::AddToRender(vtkRenderer* theRenderer){
795 SALOME_Actor::AddToRender(theRenderer);
797 theRenderer->AddActor(myNodeActor);
798 theRenderer->AddActor(myBaseActor);
800 theRenderer->AddActor(myNodeExtActor);
802 my3DActor->AddToRender(theRenderer);
803 my2DActor->AddToRender(theRenderer);
804 my2DExtActor->AddToRender(theRenderer);
806 theRenderer->AddActor(my1DActor);
807 theRenderer->AddActor(my1DExtActor);
809 theRenderer->AddActor(myHighlitableActor);
811 theRenderer->AddActor2D(myScalarBarActor);
813 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
814 myClsSelectVisiblePoints->SetRenderer(theRenderer);
816 theRenderer->AddActor2D(myPointLabels);
817 theRenderer->AddActor2D(myCellsLabels);
820 void SMESH_ActorDef::RemoveFromRender(vtkRenderer* theRenderer){
821 SALOME_Actor::RemoveFromRender(theRenderer);
823 theRenderer->RemoveActor(myNodeActor);
824 theRenderer->RemoveActor(myBaseActor);
826 theRenderer->RemoveActor(myNodeExtActor);
828 theRenderer->RemoveActor(myHighlitableActor);
830 theRenderer->RemoveActor(my1DActor);
831 theRenderer->RemoveActor(my1DExtActor);
833 my2DActor->RemoveFromRender(theRenderer);
834 my2DExtActor->RemoveFromRender(theRenderer);
835 my3DActor->RemoveFromRender(theRenderer);
837 theRenderer->RemoveActor(myScalarBarActor);
838 theRenderer->RemoveActor(myPointLabels);
839 theRenderer->RemoveActor(myCellsLabels);
843 bool SMESH_ActorDef::Init(TVisualObjPtr theVisualObj,
844 const char* theEntry,
848 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry,"SMESH",theName);
852 myVisualObj = theVisualObj;
853 myVisualObj->Update(theIsClear);
855 myNodeActor->Init(myVisualObj,myImplicitBoolean);
856 myBaseActor->Init(myVisualObj,myImplicitBoolean);
858 myHighlitableActor->Init(myVisualObj,myImplicitBoolean);
860 myNodeExtActor->Init(myVisualObj,myImplicitBoolean);
862 my1DActor->Init(myVisualObj,myImplicitBoolean);
863 my1DExtActor->Init(myVisualObj,myImplicitBoolean);
865 my2DActor->Init(myVisualObj,myImplicitBoolean);
866 my2DExtActor->Init(myVisualObj,myImplicitBoolean);
867 my3DActor->Init(myVisualObj,myImplicitBoolean);
869 my1DActor->GetMapper()->SetLookupTable(myLookupTable);
870 my1DExtActor->GetMapper()->SetLookupTable(myLookupTable);
872 my2DActor->GetMapper()->SetLookupTable(myLookupTable);
873 my2DExtActor->GetMapper()->SetLookupTable(myLookupTable);
874 my3DActor->GetMapper()->SetLookupTable(myLookupTable);
876 vtkFloatingPointType aFactor, aUnits;
877 my2DActor->GetPolygonOffsetParameters(aFactor,aUnits);
878 my2DActor->SetPolygonOffsetParameters(aFactor,aUnits*0.75);
879 my2DExtActor->SetPolygonOffsetParameters(aFactor,aUnits*0.5);
881 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
885 //SetIsShrunkable(theGrid->GetNumberOfCells() > 10);
886 SetIsShrunkable(true);
888 SetShrinkFactor( SMESH::GetFloat( "SMESH:shrink_coeff", 75 ) / 100. );
890 int aMode = mgr->integerValue( "SMESH", "display_mode" );
891 SetRepresentation(-1);
894 SetRepresentation(eEdge);
895 }else if(aMode == 1){
896 SetRepresentation(eSurface);
897 }else if(aMode == 2){
898 SetRepresentation(ePoint);
905 if( dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
906 SetIsDisplayNameActor( true );
908 myTimeStamp->Modified();
914 vtkFloatingPointType* SMESH_ActorDef::GetBounds(){
915 return myNodeActor->GetBounds();
919 vtkDataSet* SMESH_ActorDef::GetInput(){
920 return GetUnstructuredGrid();
924 void SMESH_ActorDef::SetTransform(VTKViewer_Transform* theTransform){
925 Superclass::SetTransform(theTransform);
927 myNodeActor->SetTransform(theTransform);
928 myBaseActor->SetTransform(theTransform);
930 myHighlitableActor->SetTransform(theTransform);
932 myNodeExtActor->SetTransform(theTransform);
934 my1DActor->SetTransform(theTransform);
935 my1DExtActor->SetTransform(theTransform);
937 my2DActor->SetTransform(theTransform);
938 my2DExtActor->SetTransform(theTransform);
939 my3DActor->SetTransform(theTransform);
945 void SMESH_ActorDef::SetMapper(vtkMapper* theMapper){
946 vtkLODActor::SetMapper(theMapper);
950 void SMESH_ActorDef::ShallowCopy(vtkProp *prop){
951 SALOME_Actor::ShallowCopy(prop);
955 vtkMapper* SMESH_ActorDef::GetMapper(){
956 return myPickableActor->GetMapper();
960 vtkUnstructuredGrid* SMESH_ActorDef::GetUnstructuredGrid(){
961 return myVisualObj->GetUnstructuredGrid();
965 bool SMESH_ActorDef::IsInfinitive(){
966 vtkDataSet *aDataSet = myPickableActor->GetUnstructuredGrid();
968 myIsInfinite = aDataSet->GetNumberOfCells() == 0 ||
969 aDataSet->GetNumberOfCells() == 1 &&
970 aDataSet->GetCell(0)->GetCellType() == VTK_VERTEX;
971 return SALOME_Actor::IsInfinitive();
975 void SMESH_ActorDef::SetIsShrunkable(bool theShrunkable){
976 if ( myIsShrinkable == theShrunkable )
978 myIsShrinkable = theShrunkable;
982 vtkFloatingPointType SMESH_ActorDef::GetShrinkFactor(){
983 return myBaseActor->GetShrinkFactor();
986 void SMESH_ActorDef::SetShrinkFactor(vtkFloatingPointType theValue){
987 myBaseActor->SetShrinkFactor(theValue);
989 my1DActor->SetShrinkFactor(theValue);
990 my1DExtActor->SetShrinkFactor(theValue);
992 my2DActor->SetShrinkFactor(theValue);
993 my2DExtActor->SetShrinkFactor(theValue);
994 my3DActor->SetShrinkFactor(theValue);
999 void SMESH_ActorDef::SetShrink(){
1000 if(!myIsShrinkable) return;
1002 myBaseActor->SetShrink();
1004 my1DActor->SetShrink();
1005 my1DExtActor->SetShrink();
1007 my2DActor->SetShrink();
1008 my2DExtActor->SetShrink();
1009 my3DActor->SetShrink();
1015 void SMESH_ActorDef::UnShrink(){
1016 if(!myIsShrunk) return;
1018 myBaseActor->UnShrink();
1020 my1DActor->UnShrink();
1021 my1DExtActor->UnShrink();
1023 my2DActor->UnShrink();
1024 my2DExtActor->UnShrink();
1025 my3DActor->UnShrink();
1032 int SMESH_ActorDef::GetNodeObjId(int theVtkID){
1033 return myPickableActor->GetNodeObjId(theVtkID);
1036 vtkFloatingPointType* SMESH_ActorDef::GetNodeCoord(int theObjID){
1037 return myPickableActor->GetNodeCoord(theObjID);
1041 int SMESH_ActorDef::GetElemObjId(int theVtkID){
1042 return myPickableActor->GetElemObjId(theVtkID);
1045 vtkCell* SMESH_ActorDef::GetElemCell(int theObjID){
1046 return myPickableActor->GetElemCell(theObjID);
1050 void SMESH_ActorDef::SetVisibility(int theMode){
1051 SetVisibility(theMode,true);
1055 void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation){
1056 SALOME_Actor::SetVisibility(theMode);
1058 myNodeActor->VisibilityOff();
1059 myBaseActor->VisibilityOff();
1061 myNodeExtActor->VisibilityOff();
1063 my1DActor->VisibilityOff();
1064 my1DExtActor->VisibilityOff();
1066 my2DActor->VisibilityOff();
1067 my2DExtActor->VisibilityOff();
1068 my3DActor->VisibilityOff();
1070 myScalarBarActor->VisibilityOff();
1071 myPointLabels->VisibilityOff();
1072 myCellsLabels->VisibilityOff();
1074 if(GetVisibility()){
1075 if(theIsUpdateRepersentation)
1076 SetRepresentation(GetRepresentation());
1078 if(myControlMode != eNone){
1079 switch(myControlMode){
1081 myNodeExtActor->VisibilityOn();
1085 my1DExtActor->VisibilityOn();
1088 my2DExtActor->VisibilityOn();
1091 case eMultiConnection2D:
1092 my1DExtActor->VisibilityOn();
1094 if(myControlActor->GetUnstructuredGrid()->GetNumberOfCells())
1095 myScalarBarActor->VisibilityOn();
1099 if(myRepresentation != ePoint)
1100 myPickableActor->VisibilityOn();
1102 myNodeActor->VisibilityOn();
1105 if(myEntityMode & eEdges){
1106 my1DActor->VisibilityOn();
1109 if(myEntityMode & eFaces){
1110 my2DActor->VisibilityOn();
1113 if(myEntityMode & eVolumes){
1114 my3DActor->VisibilityOn();
1117 if(myIsPointsLabeled){
1118 myPointLabels->VisibilityOn();
1119 myNodeActor->VisibilityOn();
1122 if(myIsCellsLabeled)
1123 myCellsLabels->VisibilityOn();
1130 void SMESH_ActorDef::SetEntityMode(unsigned int theMode){
1131 myEntityState = eAllEntity;
1133 if(!myVisualObj->GetNbEntities(SMDSAbs_Edge)){
1134 myEntityState &= ~eEdges;
1138 if(!myVisualObj->GetNbEntities(SMDSAbs_Face)){
1139 myEntityState &= ~eFaces;
1143 if(!myVisualObj->GetNbEntities(SMDSAbs_Volume)){
1144 myEntityState &= ~eVolumes;
1145 theMode &= ~eVolumes;
1149 if(myVisualObj->GetNbEntities(SMDSAbs_Edge))
1152 if(myVisualObj->GetNbEntities(SMDSAbs_Face))
1155 if(myVisualObj->GetNbEntities(SMDSAbs_Volume))
1156 theMode |= eVolumes;
1159 myBaseActor->myGeomFilter->SetInside(myEntityMode != myEntityState);
1161 myEntityMode = theMode;
1162 VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
1163 aFilter = myBaseActor->GetExtractUnstructuredGrid();
1164 aFilter->ClearRegisteredCellsWithType();
1165 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
1167 if(myEntityMode & eEdges){
1168 if (MYDEBUG) MESSAGE("EDGES");
1169 aFilter->RegisterCellsWithType(VTK_LINE);
1170 aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
1173 if(myEntityMode & eFaces){
1174 if (MYDEBUG) MESSAGE("FACES");
1175 aFilter->RegisterCellsWithType(VTK_TRIANGLE);
1176 aFilter->RegisterCellsWithType(VTK_POLYGON);
1177 aFilter->RegisterCellsWithType(VTK_QUAD);
1178 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
1179 aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
1182 if(myEntityMode & eVolumes){
1183 if (MYDEBUG) MESSAGE("VOLUMES");
1184 aFilter->RegisterCellsWithType(VTK_TETRA);
1185 aFilter->RegisterCellsWithType(VTK_VOXEL);
1186 aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1187 aFilter->RegisterCellsWithType(VTK_WEDGE);
1188 aFilter->RegisterCellsWithType(VTK_PYRAMID);
1189 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
1190 aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
1191 aFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
1192 aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1195 if (MYDEBUG) MESSAGE(aFilter->GetOutput()->GetNumberOfCells());
1196 SetVisibility(GetVisibility(),false);
1199 void SMESH_ActorDef::SetRepresentation(int theMode){
1200 int aNbEdges = myVisualObj->GetNbEntities(SMDSAbs_Edge);
1201 int aNbFaces = myVisualObj->GetNbEntities(SMDSAbs_Face);
1202 int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume);
1204 myRepresentation = eSurface;
1205 if(!aNbFaces && !aNbVolumes && aNbEdges){
1206 myRepresentation = eEdge;
1207 }else if(!aNbFaces && !aNbVolumes && !aNbEdges){
1208 myRepresentation = ePoint;
1213 if(!aNbFaces && !aNbVolumes && !aNbEdges) return;
1216 if(!aNbFaces && !aNbVolumes) return;
1219 myRepresentation = theMode;
1222 if(!GetUnstructuredGrid()->GetNumberOfCells())
1223 myRepresentation = ePoint;
1226 if(myRepresentation == ePoint){
1234 myPickableActor = myBaseActor;
1235 myNodeActor->SetVisibility(false);
1236 myNodeExtActor->SetVisibility(false);
1237 vtkProperty *aProp = NULL, *aBackProp = NULL;
1238 SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1);
1239 SMESH_Actor::EQuadratic2DRepresentation aQuadraticMode = GetQuadratic2DRepresentation();
1240 switch(myRepresentation){
1242 myPickableActor = myNodeActor;
1243 myNodeActor->SetVisibility(true);
1244 aQuadraticMode = SMESH_Actor::eLines;
1245 aProp = aBackProp = myNodeProp;
1246 aReperesent = SMESH_DeviceActor::ePoint;
1249 aProp = aBackProp = myEdgeProp;
1250 aReperesent = SMESH_DeviceActor::eInsideframe;
1253 aProp = mySurfaceProp;
1254 aBackProp = myBackSurfaceProp;
1255 aReperesent = SMESH_DeviceActor::eSurface;
1259 my2DActor->SetProperty(aProp);
1260 my2DActor->SetBackfaceProperty(aBackProp);
1261 my2DActor->SetRepresentation(aReperesent);
1263 if(aQuadraticMode == SMESH_Actor::eLines)
1264 my2DActor->SetQuadraticArcMode(false);
1265 else if(aQuadraticMode == SMESH_Actor::eArcs)
1266 my2DActor->SetQuadraticArcMode(true);
1268 my2DExtActor->SetRepresentation(aReperesent);
1270 my3DActor->SetProperty(aProp);
1271 my3DActor->SetBackfaceProperty(aBackProp);
1272 my3DActor->SetRepresentation(aReperesent);
1274 my1DExtActor->SetVisibility(false);
1275 my2DExtActor->SetVisibility(false);
1277 switch(myControlMode){
1279 case eMultiConnection:
1280 aProp = aBackProp = my1DProp;
1281 if(myRepresentation != ePoint)
1282 aReperesent = SMESH_DeviceActor::eInsideframe;
1286 if(aQuadraticMode == SMESH_Actor::eLines)
1287 my1DActor->SetQuadraticArcMode(false);
1288 else if(aQuadraticMode == SMESH_Actor::eArcs)
1289 my1DActor->SetQuadraticArcMode(true);
1292 my1DActor->SetProperty(aProp);
1293 my1DActor->SetBackfaceProperty(aBackProp);
1294 my1DActor->SetRepresentation(aReperesent);
1296 my1DExtActor->SetRepresentation(aReperesent);
1298 if(myIsPointsVisible)
1299 myPickableActor = myNodeActor;
1300 if(GetPointRepresentation())
1301 myNodeActor->SetVisibility(true);
1303 SetMapper(myPickableActor->GetMapper());
1305 SetVisibility(GetVisibility(),false);
1311 void SMESH_ActorDef::SetPointRepresentation(bool theIsPointsVisible){
1312 if ( myIsPointsVisible == theIsPointsVisible )
1314 myIsPointsVisible = theIsPointsVisible;
1315 SetRepresentation(GetRepresentation());
1318 bool SMESH_ActorDef::GetPointRepresentation(){
1319 return myIsPointsVisible || myIsPointsLabeled;
1323 void SMESH_ActorDef::UpdateHighlight(){
1324 myHighlitableActor->SetVisibility(false);
1325 myHighlitableActor->SetHighlited(false);
1327 if(myIsHighlighted){
1328 myHighlitableActor->SetProperty(myHighlightProp);
1329 }else if(myIsPreselected){
1330 myHighlitableActor->SetProperty(myPreselectProp);
1333 bool anIsVisible = GetVisibility();
1335 if(myIsHighlighted || myIsPreselected){
1336 if(GetUnstructuredGrid()->GetNumberOfCells()){
1337 myHighlitableActor->SetHighlited(anIsVisible);
1338 myHighlitableActor->SetVisibility(anIsVisible);
1339 myHighlitableActor->GetExtractUnstructuredGrid()->
1340 SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::eCells);
1341 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
1342 }else if(myRepresentation == ePoint || GetPointRepresentation()){
1343 myHighlitableActor->SetHighlited(anIsVisible);
1344 myHighlitableActor->GetExtractUnstructuredGrid()->
1345 SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
1346 myHighlitableActor->SetVisibility(anIsVisible);
1347 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::ePoint);
1353 void SMESH_ActorDef::highlight(bool theHighlight){
1354 if ( myIsHighlighted == theHighlight )
1356 myIsHighlighted = theHighlight;
1361 void SMESH_ActorDef::SetPreSelected(bool thePreselect){
1362 if ( myIsPreselected == thePreselect )
1364 myIsPreselected = thePreselect;
1370 int SMESH_ActorDef::RenderOpaqueGeometry(vtkViewport *vp)
1372 if (myPickableActor->GetIsOpaque())
1374 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1382 int SMESH_ActorDef::RenderTranslucentGeometry(vtkViewport *vp)
1384 if (!myPickableActor->GetIsOpaque())
1386 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1394 void SMESH_ActorDef::Render(vtkRenderer *ren){
1395 unsigned long aTime = myTimeStamp->GetMTime();
1396 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1397 unsigned long aClippingTime = myImplicitBoolean->GetMTime();
1398 if(anObjTime > aTime || aClippingTime > aTime)
1403 void SMESH_ActorDef::Update(){
1404 if(MYDEBUG) MESSAGE("SMESH_ActorDef::Update");
1406 if(GetControlMode() != eNone) {
1407 unsigned long aTime = myTimeStamp->GetMTime();
1408 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1409 if (anObjTime > aTime)
1410 SetControlMode(GetControlMode(),false);
1412 if(myIsPointsLabeled){
1413 SetPointsLabeled(myIsPointsLabeled);
1415 if(myIsCellsLabeled){
1416 SetCellsLabeled(myIsCellsLabeled);
1418 if(myIsFacesOriented){
1419 SetFacesOriented(myIsFacesOriented);
1421 SetEntityMode(GetEntityMode());
1422 SetVisibility(GetVisibility());
1424 myTimeStamp->Modified();
1429 void SMESH_ActorDef::ReleaseGraphicsResources(vtkWindow *renWin){
1430 SALOME_Actor::ReleaseGraphicsResources(renWin);
1432 myPickableActor->ReleaseGraphicsResources(renWin);
1436 static void GetColor(vtkProperty *theProperty, vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1437 vtkFloatingPointType* aColor = theProperty->GetColor();
1444 void SMESH_ActorDef::SetOpacity(vtkFloatingPointType theValue){
1445 mySurfaceProp->SetOpacity(theValue);
1446 myBackSurfaceProp->SetOpacity(theValue);
1447 myEdgeProp->SetOpacity(theValue);
1448 myNodeProp->SetOpacity(theValue);
1450 my1DProp->SetOpacity(theValue);
1454 vtkFloatingPointType SMESH_ActorDef::GetOpacity(){
1455 return mySurfaceProp->GetOpacity();
1459 void SMESH_ActorDef::SetSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1460 mySurfaceProp->SetColor(r,g,b);
1461 myNameActor->SetBackgroundColor(r,g,b);
1465 void SMESH_ActorDef::GetSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1466 ::GetColor(mySurfaceProp,r,g,b);
1467 my2DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1470 void SMESH_ActorDef::SetBackSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1471 myBackSurfaceProp->SetColor(r,g,b);
1475 void SMESH_ActorDef::GetBackSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1476 ::GetColor(myBackSurfaceProp,r,g,b);
1479 void SMESH_ActorDef::SetEdgeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1480 myEdgeProp->SetColor(r,g,b);
1481 my1DProp->SetColor(r,g,b);
1482 my1DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1486 void SMESH_ActorDef::GetEdgeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1487 ::GetColor(myEdgeProp,r,g,b);
1490 void SMESH_ActorDef::SetNodeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1491 myNodeProp->SetColor(r,g,b);
1492 myNodeExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1496 void SMESH_ActorDef::GetNodeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1497 ::GetColor(myNodeProp,r,g,b);
1500 void SMESH_ActorDef::SetHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1501 myHighlightProp->SetColor(r,g,b);
1505 void SMESH_ActorDef::GetHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1506 ::GetColor(myHighlightProp,r,g,b);
1509 void SMESH_ActorDef::SetPreHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1510 myPreselectProp->SetColor(r,g,b);
1514 void SMESH_ActorDef::GetPreHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1515 ::GetColor(myPreselectProp,r,g,b);
1519 vtkFloatingPointType SMESH_ActorDef::GetLineWidth(){
1520 return myEdgeProp->GetLineWidth();
1524 void SMESH_ActorDef::SetLineWidth(vtkFloatingPointType theVal){
1525 myEdgeProp->SetLineWidth(theVal);
1527 my1DProp->SetLineWidth(theVal + aLineWidthInc);
1528 my1DExtProp->SetLineWidth(theVal + aLineWidthInc);
1534 void SMESH_ActorDef::SetNodeSize(vtkFloatingPointType theVal){
1535 myNodeProp->SetPointSize(theVal);
1536 myNodeExtProp->SetPointSize(theVal);
1537 myHighlightProp->SetPointSize(theVal);
1538 myPreselectProp->SetPointSize(theVal);
1540 my1DProp->SetPointSize(theVal + aPointSizeInc);
1541 my1DExtProp->SetPointSize(theVal + aPointSizeInc);
1546 vtkFloatingPointType SMESH_ActorDef::GetNodeSize(){
1547 return myNodeProp->GetPointSize();
1550 int SMESH_ActorDef::GetObjDimension( const int theObjId )
1552 return myVisualObj->GetElemDimension( theObjId );
1557 IsImplicitFunctionUsed() const
1559 return myBaseActor->IsImplicitFunctionUsed();
1564 SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
1566 myNodeActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1567 myBaseActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1569 myHighlitableActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1571 myNodeExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1573 my1DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1574 my1DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1576 my2DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1577 my2DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1578 my3DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1583 AddClippingPlane(vtkPlane* thePlane)
1586 myImplicitBoolean->GetFunction()->AddItem(thePlane);
1587 myCippingPlaneCont.push_back(thePlane);
1588 if(!IsImplicitFunctionUsed())
1589 SetImplicitFunctionUsed(true);
1591 return myCippingPlaneCont.size();
1596 RemoveAllClippingPlanes()
1598 myImplicitBoolean->GetFunction()->RemoveAllItems();
1599 myImplicitBoolean->GetFunction()->Modified(); // VTK bug
1600 myCippingPlaneCont.clear();
1601 SetImplicitFunctionUsed(false);
1606 GetNumberOfClippingPlanes()
1608 return myCippingPlaneCont.size();
1613 GetClippingPlane(vtkIdType theID)
1615 if(theID >= myCippingPlaneCont.size())
1617 return myCippingPlaneCont[theID].Get();
1621 static void ComputeBoundsParam(vtkDataSet* theDataSet,
1622 vtkFloatingPointType theDirection[3], vtkFloatingPointType theMinPnt[3],
1623 vtkFloatingPointType& theMaxBoundPrj, vtkFloatingPointType& theMinBoundPrj)
1625 vtkFloatingPointType aBounds[6];
1626 theDataSet->GetBounds(aBounds);
1628 //Enlarge bounds in order to avoid conflicts of precision
1629 for(int i = 0; i < 6; i += 2){
1630 static double EPS = 1.0E-3;
1631 vtkFloatingPointType aDelta = (aBounds[i+1] - aBounds[i])*EPS;
1632 aBounds[i] -= aDelta;
1633 aBounds[i+1] += aDelta;
1636 vtkFloatingPointType aBoundPoints[8][3] = { {aBounds[0],aBounds[2],aBounds[4]},
1637 {aBounds[1],aBounds[2],aBounds[4]},
1638 {aBounds[0],aBounds[3],aBounds[4]},
1639 {aBounds[1],aBounds[3],aBounds[4]},
1640 {aBounds[0],aBounds[2],aBounds[5]},
1641 {aBounds[1],aBounds[2],aBounds[5]},
1642 {aBounds[0],aBounds[3],aBounds[5]},
1643 {aBounds[1],aBounds[3],aBounds[5]}};
1645 int aMaxId = 0, aMinId = aMaxId;
1646 theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
1647 theMinBoundPrj = theMaxBoundPrj;
1648 for(int i = 1; i < 8; i++){
1649 vtkFloatingPointType aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
1650 if(theMaxBoundPrj < aTmp){
1651 theMaxBoundPrj = aTmp;
1654 if(theMinBoundPrj > aTmp){
1655 theMinBoundPrj = aTmp;
1659 vtkFloatingPointType *aMinPnt = aBoundPoints[aMaxId];
1660 theMinPnt[0] = aMinPnt[0];
1661 theMinPnt[1] = aMinPnt[1];
1662 theMinPnt[2] = aMinPnt[2];
1666 static void DistanceToPosition(vtkDataSet* theDataSet,
1667 vtkFloatingPointType theDirection[3], vtkFloatingPointType theDist, vtkFloatingPointType thePos[3])
1669 vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1670 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1671 vtkFloatingPointType aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
1672 thePos[0] = aMinPnt[0]-theDirection[0]*aLength;
1673 thePos[1] = aMinPnt[1]-theDirection[1]*aLength;
1674 thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
1678 static void PositionToDistance(vtkDataSet* theDataSet,
1679 vtkFloatingPointType theDirection[3], vtkFloatingPointType thePos[3], vtkFloatingPointType& theDist)
1681 vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1682 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1683 vtkFloatingPointType aPrj = vtkMath::Dot(theDirection,thePos);
1684 theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
1688 void SMESH_ActorDef::SetPlaneParam(vtkFloatingPointType theDir[3], vtkFloatingPointType theDist, vtkPlane* thePlane)
1690 thePlane->SetNormal(theDir);
1691 vtkFloatingPointType anOrigin[3];
1692 ::DistanceToPosition(GetUnstructuredGrid(),theDir,theDist,anOrigin);
1693 thePlane->SetOrigin(anOrigin);
1697 void SMESH_ActorDef::GetPlaneParam(vtkFloatingPointType theDir[3], vtkFloatingPointType& theDist, vtkPlane* thePlane)
1699 thePlane->GetNormal(theDir);
1701 vtkFloatingPointType anOrigin[3];
1702 thePlane->GetOrigin(anOrigin);
1703 ::PositionToDistance(GetUnstructuredGrid(),theDir,anOrigin,theDist);
1706 void SMESH_ActorDef::UpdateScalarBar()
1708 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
1712 vtkTextProperty* aScalarBarTitleProp = vtkTextProperty::New();
1714 QColor aTColor = mgr->colorValue( "SMESH", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
1715 aScalarBarTitleProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1717 aScalarBarTitleProp->SetFontFamilyToArial();
1719 if ( mgr->hasValue( "SMESH", "scalar_bar_title_font" ) )
1721 QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
1722 if ( f.family() == "Arial" )
1723 aScalarBarTitleProp->SetFontFamilyToArial();
1724 else if ( f.family() == "Courier" )
1725 aScalarBarTitleProp->SetFontFamilyToCourier();
1726 else if ( f.family() == "Times" )
1727 aScalarBarTitleProp->SetFontFamilyToTimes();
1730 aScalarBarTitleProp->BoldOn();
1732 aScalarBarTitleProp->BoldOff();
1735 aScalarBarTitleProp->ItalicOn();
1737 aScalarBarTitleProp->ItalicOff();
1740 aScalarBarTitleProp->ShadowOn();
1742 aScalarBarTitleProp->ShadowOff();
1745 myScalarBarActor->SetTitleTextProperty( aScalarBarTitleProp );
1746 aScalarBarTitleProp->Delete();
1748 vtkTextProperty* aScalarBarLabelProp = vtkTextProperty::New();
1750 aTColor = mgr->colorValue( "SMESH", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
1751 aScalarBarLabelProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1753 aScalarBarLabelProp->SetFontFamilyToArial();
1754 if( mgr->hasValue( "SMESH", "scalar_bar_label_font" ) )
1756 QFont f = mgr->fontValue( "SMESH", "scalar_bar_label_font" );
1757 if( f.family() == "Arial" )
1758 aScalarBarLabelProp->SetFontFamilyToArial();
1759 else if( f.family() == "Courier" )
1760 aScalarBarLabelProp->SetFontFamilyToCourier();
1761 else if( f.family() == "Times" )
1762 aScalarBarLabelProp->SetFontFamilyToTimes();
1765 aScalarBarLabelProp->BoldOn();
1767 aScalarBarLabelProp->BoldOff();
1770 aScalarBarLabelProp->ItalicOn();
1772 aScalarBarLabelProp->ItalicOff();
1775 aScalarBarLabelProp->ShadowOn();
1777 aScalarBarLabelProp->ShadowOff();
1780 myScalarBarActor->SetLabelTextProperty( aScalarBarLabelProp );
1781 aScalarBarLabelProp->Delete();
1783 bool horiz = ( mgr->integerValue( "SMESH", "scalar_bar_orientation" ) == 1 );
1784 QString name = QString( "scalar_bar_%1_" ).arg( horiz ? "horizontal" : "vertical" );
1786 myScalarBarActor->SetOrientationToHorizontal();
1788 myScalarBarActor->SetOrientationToVertical();
1791 vtkFloatingPointType aXVal = horiz ? 0.20 : 0.01;
1792 if( mgr->hasValue( "SMESH", name + "x" ) )
1793 aXVal = mgr->doubleValue( "SMESH", name + "x", aXVal );
1795 vtkFloatingPointType aYVal = horiz ? 0.01 : 0.1;
1796 if( mgr->hasValue( "SMESH", name + "y" ) )
1797 aYVal = mgr->doubleValue( "SMESH", name + "y", aYVal );
1798 myScalarBarActor->SetPosition( aXVal, aYVal );
1800 vtkFloatingPointType aWVal = horiz ? 0.60 : 0.10;
1801 if( mgr->hasValue( "SMESH", name + "width" ) )
1802 aWVal = mgr->doubleValue( "SMESH", name + "width", aWVal );
1803 myScalarBarActor->SetWidth( aWVal );
1805 vtkFloatingPointType aHVal = horiz ? 0.12 : 0.80;
1806 if( mgr->hasValue( "SMESH", name + "height" ) )
1807 aHVal = mgr->doubleValue( "SMESH", name + "height", aHVal );
1808 myScalarBarActor->SetHeight( aHVal );
1811 if( mgr->hasValue( "SMESH", "scalar_bar_num_labels" ) )
1812 anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_labels", anIntVal );
1813 myScalarBarActor->SetNumberOfLabels( anIntVal == 0 ? 5: anIntVal );
1816 if( mgr->hasValue( "SMESH", "scalar_bar_num_colors" ) )
1817 anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_colors", anIntVal );
1818 myScalarBarActor->SetMaximumNumberOfColors( anIntVal == 0 ? 64 : anIntVal );
1822 void SMESH_ActorDef::SetQuadratic2DRepresentation(EQuadratic2DRepresentation theMode)
1825 case SMESH_Actor::eLines :
1826 myHighlitableActor->SetQuadraticArcMode(false);
1827 my2DActor->SetQuadraticArcMode(false);
1828 my1DActor->SetQuadraticArcMode(false);
1830 case SMESH_Actor::eArcs :
1831 myHighlitableActor->SetQuadraticArcMode(true);
1832 if(GetRepresentation() != SMESH_Actor::ePoint) {
1833 my2DActor->SetQuadraticArcMode(true);
1834 my1DActor->SetQuadraticArcMode(true);
1843 SMESH_Actor::EQuadratic2DRepresentation SMESH_ActorDef::GetQuadratic2DRepresentation()
1845 if(myHighlitableActor->GetQuadraticArcMode())
1846 return SMESH_Actor::eArcs;
1848 return SMESH_Actor::eLines;