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 VTKViewer_ExtractUnstructuredGrid* aHightFilter = myHighlitableActor->GetExtractUnstructuredGrid();
1168 aHightFilter->ClearRegisteredCellsWithType();
1169 aHightFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
1172 if(myEntityMode & eEdges){
1173 if (MYDEBUG) MESSAGE("EDGES");
1174 aFilter->RegisterCellsWithType(VTK_LINE);
1175 aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
1177 aHightFilter->RegisterCellsWithType(VTK_LINE);
1178 aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
1181 if(myEntityMode & eFaces){
1182 if (MYDEBUG) MESSAGE("FACES");
1183 aFilter->RegisterCellsWithType(VTK_TRIANGLE);
1184 aFilter->RegisterCellsWithType(VTK_POLYGON);
1185 aFilter->RegisterCellsWithType(VTK_QUAD);
1186 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
1187 aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
1189 aHightFilter->RegisterCellsWithType(VTK_TRIANGLE);
1190 aHightFilter->RegisterCellsWithType(VTK_POLYGON);
1191 aHightFilter->RegisterCellsWithType(VTK_QUAD);
1192 aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
1193 aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
1196 if(myEntityMode & eVolumes){
1197 if (MYDEBUG) MESSAGE("VOLUMES");
1198 aFilter->RegisterCellsWithType(VTK_TETRA);
1199 aFilter->RegisterCellsWithType(VTK_VOXEL);
1200 aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1201 aFilter->RegisterCellsWithType(VTK_WEDGE);
1202 aFilter->RegisterCellsWithType(VTK_PYRAMID);
1203 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
1204 aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
1205 aFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
1206 aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1208 aHightFilter->RegisterCellsWithType(VTK_TETRA);
1209 aHightFilter->RegisterCellsWithType(VTK_VOXEL);
1210 aHightFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1211 aHightFilter->RegisterCellsWithType(VTK_WEDGE);
1212 aHightFilter->RegisterCellsWithType(VTK_PYRAMID);
1213 aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
1214 aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
1215 aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
1216 aHightFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1219 if (MYDEBUG) MESSAGE(aFilter->GetOutput()->GetNumberOfCells());
1220 SetVisibility(GetVisibility(),false);
1223 void SMESH_ActorDef::SetRepresentation(int theMode){
1224 int aNbEdges = myVisualObj->GetNbEntities(SMDSAbs_Edge);
1225 int aNbFaces = myVisualObj->GetNbEntities(SMDSAbs_Face);
1226 int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume);
1228 myRepresentation = eSurface;
1229 if(!aNbFaces && !aNbVolumes && aNbEdges){
1230 myRepresentation = eEdge;
1231 }else if(!aNbFaces && !aNbVolumes && !aNbEdges){
1232 myRepresentation = ePoint;
1237 if(!aNbFaces && !aNbVolumes && !aNbEdges) return;
1240 if(!aNbFaces && !aNbVolumes) return;
1243 myRepresentation = theMode;
1246 if(!GetUnstructuredGrid()->GetNumberOfCells())
1247 myRepresentation = ePoint;
1250 if(myRepresentation == ePoint){
1258 myPickableActor = myBaseActor;
1259 myNodeActor->SetVisibility(false);
1260 myNodeExtActor->SetVisibility(false);
1261 vtkProperty *aProp = NULL, *aBackProp = NULL;
1262 SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1);
1263 SMESH_Actor::EQuadratic2DRepresentation aQuadraticMode = GetQuadratic2DRepresentation();
1264 switch(myRepresentation){
1266 myPickableActor = myNodeActor;
1267 myNodeActor->SetVisibility(true);
1268 aQuadraticMode = SMESH_Actor::eLines;
1269 aProp = aBackProp = myNodeProp;
1270 aReperesent = SMESH_DeviceActor::ePoint;
1273 aProp = aBackProp = myEdgeProp;
1274 aReperesent = SMESH_DeviceActor::eInsideframe;
1277 aProp = mySurfaceProp;
1278 aBackProp = myBackSurfaceProp;
1279 aReperesent = SMESH_DeviceActor::eSurface;
1283 my2DActor->SetProperty(aProp);
1284 my2DActor->SetBackfaceProperty(aBackProp);
1285 my2DActor->SetRepresentation(aReperesent);
1287 if(aQuadraticMode == SMESH_Actor::eLines)
1288 my2DActor->SetQuadraticArcMode(false);
1289 else if(aQuadraticMode == SMESH_Actor::eArcs)
1290 my2DActor->SetQuadraticArcMode(true);
1292 my2DExtActor->SetRepresentation(aReperesent);
1294 my3DActor->SetProperty(aProp);
1295 my3DActor->SetBackfaceProperty(aBackProp);
1296 my3DActor->SetRepresentation(aReperesent);
1298 my1DExtActor->SetVisibility(false);
1299 my2DExtActor->SetVisibility(false);
1301 switch(myControlMode){
1303 case eMultiConnection:
1304 aProp = aBackProp = my1DProp;
1305 if(myRepresentation != ePoint)
1306 aReperesent = SMESH_DeviceActor::eInsideframe;
1310 if(aQuadraticMode == SMESH_Actor::eLines)
1311 my1DActor->SetQuadraticArcMode(false);
1312 else if(aQuadraticMode == SMESH_Actor::eArcs)
1313 my1DActor->SetQuadraticArcMode(true);
1316 my1DActor->SetProperty(aProp);
1317 my1DActor->SetBackfaceProperty(aBackProp);
1318 my1DActor->SetRepresentation(aReperesent);
1320 my1DExtActor->SetRepresentation(aReperesent);
1322 if(myIsPointsVisible)
1323 myPickableActor = myNodeActor;
1324 if(GetPointRepresentation())
1325 myNodeActor->SetVisibility(true);
1327 SetMapper(myPickableActor->GetMapper());
1329 SetVisibility(GetVisibility(),false);
1335 void SMESH_ActorDef::SetPointRepresentation(bool theIsPointsVisible){
1336 if ( myIsPointsVisible == theIsPointsVisible )
1338 myIsPointsVisible = theIsPointsVisible;
1339 SetRepresentation(GetRepresentation());
1342 bool SMESH_ActorDef::GetPointRepresentation(){
1343 return myIsPointsVisible || myIsPointsLabeled;
1347 void SMESH_ActorDef::UpdateHighlight(){
1348 myHighlitableActor->SetVisibility(false);
1349 myHighlitableActor->SetHighlited(false);
1351 if(myIsHighlighted){
1352 myHighlitableActor->SetProperty(myHighlightProp);
1353 }else if(myIsPreselected){
1354 myHighlitableActor->SetProperty(myPreselectProp);
1357 bool anIsVisible = GetVisibility();
1359 if(myIsHighlighted || myIsPreselected){
1360 if(GetUnstructuredGrid()->GetNumberOfCells()){
1361 myHighlitableActor->SetHighlited(anIsVisible);
1362 myHighlitableActor->SetVisibility(anIsVisible);
1363 myHighlitableActor->GetExtractUnstructuredGrid()->
1364 SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::eCells);
1365 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
1366 }else if(myRepresentation == ePoint || GetPointRepresentation()){
1367 myHighlitableActor->SetHighlited(anIsVisible);
1368 myHighlitableActor->GetExtractUnstructuredGrid()->
1369 SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
1370 myHighlitableActor->SetVisibility(anIsVisible);
1371 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::ePoint);
1377 void SMESH_ActorDef::highlight(bool theHighlight){
1378 if ( myIsHighlighted == theHighlight )
1380 myIsHighlighted = theHighlight;
1385 void SMESH_ActorDef::SetPreSelected(bool thePreselect){
1386 if ( myIsPreselected == thePreselect )
1388 myIsPreselected = thePreselect;
1394 int SMESH_ActorDef::RenderOpaqueGeometry(vtkViewport *vp)
1396 if (myPickableActor->GetIsOpaque())
1398 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1406 int SMESH_ActorDef::RenderTranslucentGeometry(vtkViewport *vp)
1408 if (!myPickableActor->GetIsOpaque())
1410 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1418 void SMESH_ActorDef::Render(vtkRenderer *ren){
1419 unsigned long aTime = myTimeStamp->GetMTime();
1420 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1421 unsigned long aClippingTime = myImplicitBoolean->GetMTime();
1422 if(anObjTime > aTime || aClippingTime > aTime)
1427 void SMESH_ActorDef::Update(){
1428 if(MYDEBUG) MESSAGE("SMESH_ActorDef::Update");
1430 if(GetControlMode() != eNone) {
1431 unsigned long aTime = myTimeStamp->GetMTime();
1432 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1433 if (anObjTime > aTime)
1434 SetControlMode(GetControlMode(),false);
1436 if(myIsPointsLabeled){
1437 SetPointsLabeled(myIsPointsLabeled);
1439 if(myIsCellsLabeled){
1440 SetCellsLabeled(myIsCellsLabeled);
1442 if(myIsFacesOriented){
1443 SetFacesOriented(myIsFacesOriented);
1445 SetEntityMode(GetEntityMode());
1446 SetVisibility(GetVisibility());
1448 myTimeStamp->Modified();
1453 void SMESH_ActorDef::ReleaseGraphicsResources(vtkWindow *renWin){
1454 SALOME_Actor::ReleaseGraphicsResources(renWin);
1456 myPickableActor->ReleaseGraphicsResources(renWin);
1460 static void GetColor(vtkProperty *theProperty, vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1461 vtkFloatingPointType* aColor = theProperty->GetColor();
1468 void SMESH_ActorDef::SetOpacity(vtkFloatingPointType theValue){
1469 mySurfaceProp->SetOpacity(theValue);
1470 myBackSurfaceProp->SetOpacity(theValue);
1471 myEdgeProp->SetOpacity(theValue);
1472 myNodeProp->SetOpacity(theValue);
1474 my1DProp->SetOpacity(theValue);
1478 vtkFloatingPointType SMESH_ActorDef::GetOpacity(){
1479 return mySurfaceProp->GetOpacity();
1483 void SMESH_ActorDef::SetSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1484 mySurfaceProp->SetColor(r,g,b);
1485 if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1486 if( aGroupObj->GetElementType() == SMDSAbs_Face ||
1487 aGroupObj->GetElementType() == SMDSAbs_Volume )
1488 myNameActor->SetBackgroundColor(r,g,b);
1492 void SMESH_ActorDef::GetSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1493 ::GetColor(mySurfaceProp,r,g,b);
1494 my2DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1497 void SMESH_ActorDef::SetBackSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1498 myBackSurfaceProp->SetColor(r,g,b);
1502 void SMESH_ActorDef::GetBackSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1503 ::GetColor(myBackSurfaceProp,r,g,b);
1506 void SMESH_ActorDef::SetEdgeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1507 myEdgeProp->SetColor(r,g,b);
1508 my1DProp->SetColor(r,g,b);
1509 my1DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1510 if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1511 if( aGroupObj->GetElementType() == SMDSAbs_Edge )
1512 myNameActor->SetBackgroundColor(r,g,b);
1516 void SMESH_ActorDef::GetEdgeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1517 ::GetColor(myEdgeProp,r,g,b);
1520 void SMESH_ActorDef::SetNodeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1521 myNodeProp->SetColor(r,g,b);
1522 myNodeExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1523 if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1524 if( aGroupObj->GetElementType() == SMDSAbs_Node )
1525 myNameActor->SetBackgroundColor(r,g,b);
1529 void SMESH_ActorDef::GetNodeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1530 ::GetColor(myNodeProp,r,g,b);
1533 void SMESH_ActorDef::SetHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1534 myHighlightProp->SetColor(r,g,b);
1538 void SMESH_ActorDef::GetHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1539 ::GetColor(myHighlightProp,r,g,b);
1542 void SMESH_ActorDef::SetPreHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1543 myPreselectProp->SetColor(r,g,b);
1547 void SMESH_ActorDef::GetPreHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1548 ::GetColor(myPreselectProp,r,g,b);
1552 vtkFloatingPointType SMESH_ActorDef::GetLineWidth(){
1553 return myEdgeProp->GetLineWidth();
1557 void SMESH_ActorDef::SetLineWidth(vtkFloatingPointType theVal){
1558 myEdgeProp->SetLineWidth(theVal);
1560 my1DProp->SetLineWidth(theVal + aLineWidthInc);
1561 my1DExtProp->SetLineWidth(theVal + aLineWidthInc);
1567 void SMESH_ActorDef::SetNodeSize(vtkFloatingPointType theVal){
1568 myNodeProp->SetPointSize(theVal);
1569 myNodeExtProp->SetPointSize(theVal);
1570 myHighlightProp->SetPointSize(theVal);
1571 myPreselectProp->SetPointSize(theVal);
1573 my1DProp->SetPointSize(theVal + aPointSizeInc);
1574 my1DExtProp->SetPointSize(theVal + aPointSizeInc);
1579 vtkFloatingPointType SMESH_ActorDef::GetNodeSize(){
1580 return myNodeProp->GetPointSize();
1583 int SMESH_ActorDef::GetObjDimension( const int theObjId )
1585 return myVisualObj->GetElemDimension( theObjId );
1590 IsImplicitFunctionUsed() const
1592 return myBaseActor->IsImplicitFunctionUsed();
1597 SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
1599 myNodeActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1600 myBaseActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1602 myHighlitableActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1604 myNodeExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1606 my1DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1607 my1DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1609 my2DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1610 my2DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1611 my3DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1616 AddClippingPlane(vtkPlane* thePlane)
1619 myImplicitBoolean->GetFunction()->AddItem(thePlane);
1620 myCippingPlaneCont.push_back(thePlane);
1621 if(!IsImplicitFunctionUsed())
1622 SetImplicitFunctionUsed(true);
1624 return myCippingPlaneCont.size();
1629 RemoveAllClippingPlanes()
1631 myImplicitBoolean->GetFunction()->RemoveAllItems();
1632 myImplicitBoolean->GetFunction()->Modified(); // VTK bug
1633 myCippingPlaneCont.clear();
1634 SetImplicitFunctionUsed(false);
1639 GetNumberOfClippingPlanes()
1641 return myCippingPlaneCont.size();
1646 GetClippingPlane(vtkIdType theID)
1648 if(theID >= myCippingPlaneCont.size())
1650 return myCippingPlaneCont[theID].Get();
1654 static void ComputeBoundsParam(vtkDataSet* theDataSet,
1655 vtkFloatingPointType theDirection[3], vtkFloatingPointType theMinPnt[3],
1656 vtkFloatingPointType& theMaxBoundPrj, vtkFloatingPointType& theMinBoundPrj)
1658 vtkFloatingPointType aBounds[6];
1659 theDataSet->GetBounds(aBounds);
1661 //Enlarge bounds in order to avoid conflicts of precision
1662 for(int i = 0; i < 6; i += 2){
1663 static double EPS = 1.0E-3;
1664 vtkFloatingPointType aDelta = (aBounds[i+1] - aBounds[i])*EPS;
1665 aBounds[i] -= aDelta;
1666 aBounds[i+1] += aDelta;
1669 vtkFloatingPointType aBoundPoints[8][3] = { {aBounds[0],aBounds[2],aBounds[4]},
1670 {aBounds[1],aBounds[2],aBounds[4]},
1671 {aBounds[0],aBounds[3],aBounds[4]},
1672 {aBounds[1],aBounds[3],aBounds[4]},
1673 {aBounds[0],aBounds[2],aBounds[5]},
1674 {aBounds[1],aBounds[2],aBounds[5]},
1675 {aBounds[0],aBounds[3],aBounds[5]},
1676 {aBounds[1],aBounds[3],aBounds[5]}};
1678 int aMaxId = 0, aMinId = aMaxId;
1679 theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
1680 theMinBoundPrj = theMaxBoundPrj;
1681 for(int i = 1; i < 8; i++){
1682 vtkFloatingPointType aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
1683 if(theMaxBoundPrj < aTmp){
1684 theMaxBoundPrj = aTmp;
1687 if(theMinBoundPrj > aTmp){
1688 theMinBoundPrj = aTmp;
1692 vtkFloatingPointType *aMinPnt = aBoundPoints[aMaxId];
1693 theMinPnt[0] = aMinPnt[0];
1694 theMinPnt[1] = aMinPnt[1];
1695 theMinPnt[2] = aMinPnt[2];
1699 static void DistanceToPosition(vtkDataSet* theDataSet,
1700 vtkFloatingPointType theDirection[3], vtkFloatingPointType theDist, vtkFloatingPointType thePos[3])
1702 vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1703 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1704 vtkFloatingPointType aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
1705 thePos[0] = aMinPnt[0]-theDirection[0]*aLength;
1706 thePos[1] = aMinPnt[1]-theDirection[1]*aLength;
1707 thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
1711 static void PositionToDistance(vtkDataSet* theDataSet,
1712 vtkFloatingPointType theDirection[3], vtkFloatingPointType thePos[3], vtkFloatingPointType& theDist)
1714 vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1715 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1716 vtkFloatingPointType aPrj = vtkMath::Dot(theDirection,thePos);
1717 theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
1721 void SMESH_ActorDef::SetPlaneParam(vtkFloatingPointType theDir[3], vtkFloatingPointType theDist, vtkPlane* thePlane)
1723 thePlane->SetNormal(theDir);
1724 vtkFloatingPointType anOrigin[3];
1725 ::DistanceToPosition(GetUnstructuredGrid(),theDir,theDist,anOrigin);
1726 thePlane->SetOrigin(anOrigin);
1730 void SMESH_ActorDef::GetPlaneParam(vtkFloatingPointType theDir[3], vtkFloatingPointType& theDist, vtkPlane* thePlane)
1732 thePlane->GetNormal(theDir);
1734 vtkFloatingPointType anOrigin[3];
1735 thePlane->GetOrigin(anOrigin);
1736 ::PositionToDistance(GetUnstructuredGrid(),theDir,anOrigin,theDist);
1739 void SMESH_ActorDef::UpdateScalarBar()
1741 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
1745 vtkTextProperty* aScalarBarTitleProp = vtkTextProperty::New();
1747 QColor aTColor = mgr->colorValue( "SMESH", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
1748 aScalarBarTitleProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1750 aScalarBarTitleProp->SetFontFamilyToArial();
1752 if ( mgr->hasValue( "SMESH", "scalar_bar_title_font" ) )
1754 QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
1755 if ( f.family() == "Arial" )
1756 aScalarBarTitleProp->SetFontFamilyToArial();
1757 else if ( f.family() == "Courier" )
1758 aScalarBarTitleProp->SetFontFamilyToCourier();
1759 else if ( f.family() == "Times" )
1760 aScalarBarTitleProp->SetFontFamilyToTimes();
1763 aScalarBarTitleProp->BoldOn();
1765 aScalarBarTitleProp->BoldOff();
1768 aScalarBarTitleProp->ItalicOn();
1770 aScalarBarTitleProp->ItalicOff();
1773 aScalarBarTitleProp->ShadowOn();
1775 aScalarBarTitleProp->ShadowOff();
1778 myScalarBarActor->SetTitleTextProperty( aScalarBarTitleProp );
1779 aScalarBarTitleProp->Delete();
1781 vtkTextProperty* aScalarBarLabelProp = vtkTextProperty::New();
1783 aTColor = mgr->colorValue( "SMESH", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
1784 aScalarBarLabelProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1786 aScalarBarLabelProp->SetFontFamilyToArial();
1787 if( mgr->hasValue( "SMESH", "scalar_bar_label_font" ) )
1789 QFont f = mgr->fontValue( "SMESH", "scalar_bar_label_font" );
1790 if( f.family() == "Arial" )
1791 aScalarBarLabelProp->SetFontFamilyToArial();
1792 else if( f.family() == "Courier" )
1793 aScalarBarLabelProp->SetFontFamilyToCourier();
1794 else if( f.family() == "Times" )
1795 aScalarBarLabelProp->SetFontFamilyToTimes();
1798 aScalarBarLabelProp->BoldOn();
1800 aScalarBarLabelProp->BoldOff();
1803 aScalarBarLabelProp->ItalicOn();
1805 aScalarBarLabelProp->ItalicOff();
1808 aScalarBarLabelProp->ShadowOn();
1810 aScalarBarLabelProp->ShadowOff();
1813 myScalarBarActor->SetLabelTextProperty( aScalarBarLabelProp );
1814 aScalarBarLabelProp->Delete();
1816 bool horiz = ( mgr->integerValue( "SMESH", "scalar_bar_orientation" ) == 1 );
1817 QString name = QString( "scalar_bar_%1_" ).arg( horiz ? "horizontal" : "vertical" );
1819 myScalarBarActor->SetOrientationToHorizontal();
1821 myScalarBarActor->SetOrientationToVertical();
1824 vtkFloatingPointType aXVal = horiz ? 0.20 : 0.01;
1825 if( mgr->hasValue( "SMESH", name + "x" ) )
1826 aXVal = mgr->doubleValue( "SMESH", name + "x", aXVal );
1828 vtkFloatingPointType aYVal = horiz ? 0.01 : 0.1;
1829 if( mgr->hasValue( "SMESH", name + "y" ) )
1830 aYVal = mgr->doubleValue( "SMESH", name + "y", aYVal );
1831 myScalarBarActor->SetPosition( aXVal, aYVal );
1833 vtkFloatingPointType aWVal = horiz ? 0.60 : 0.10;
1834 if( mgr->hasValue( "SMESH", name + "width" ) )
1835 aWVal = mgr->doubleValue( "SMESH", name + "width", aWVal );
1836 myScalarBarActor->SetWidth( aWVal );
1838 vtkFloatingPointType aHVal = horiz ? 0.12 : 0.80;
1839 if( mgr->hasValue( "SMESH", name + "height" ) )
1840 aHVal = mgr->doubleValue( "SMESH", name + "height", aHVal );
1841 myScalarBarActor->SetHeight( aHVal );
1844 if( mgr->hasValue( "SMESH", "scalar_bar_num_labels" ) )
1845 anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_labels", anIntVal );
1846 myScalarBarActor->SetNumberOfLabels( anIntVal == 0 ? 5: anIntVal );
1849 if( mgr->hasValue( "SMESH", "scalar_bar_num_colors" ) )
1850 anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_colors", anIntVal );
1851 myScalarBarActor->SetMaximumNumberOfColors( anIntVal == 0 ? 64 : anIntVal );
1855 void SMESH_ActorDef::SetQuadratic2DRepresentation(EQuadratic2DRepresentation theMode)
1858 case SMESH_Actor::eLines :
1859 myHighlitableActor->SetQuadraticArcMode(false);
1860 my2DActor->SetQuadraticArcMode(false);
1861 my1DActor->SetQuadraticArcMode(false);
1863 case SMESH_Actor::eArcs :
1864 myHighlitableActor->SetQuadraticArcMode(true);
1865 if(GetRepresentation() != SMESH_Actor::ePoint) {
1866 my2DActor->SetQuadraticArcMode(true);
1867 my1DActor->SetQuadraticArcMode(true);
1876 SMESH_Actor::EQuadratic2DRepresentation SMESH_ActorDef::GetQuadratic2DRepresentation()
1878 if(myHighlitableActor->GetQuadraticArcMode())
1879 return SMESH_Actor::eArcs;
1881 return SMESH_Actor::eLines;