1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH OBJECT : interactive object for SMESH visualization
23 // File : SMESH_Actor.cxx
24 // Author : Nicolas REJNERI
28 #include "SMESH_ActorDef.h"
29 #include "SMESH_ActorUtils.h"
30 #include "SMESH_DeviceActor.h"
31 #include "SMESH_ControlsDef.hxx"
32 #include "VTKViewer_ExtractUnstructuredGrid.h"
33 #include "SALOME_InteractiveObject.hxx"
35 #include "SUIT_Session.h"
36 #include "SUIT_ResourceMgr.h"
38 #include <vtkProperty.h>
39 #include <vtkTimeStamp.h>
40 #include <vtkObjectFactory.h>
41 #include <vtkShrinkPolyData.h>
42 #include <vtkMergeFilter.h>
44 #include <vtkMatrix4x4.h>
45 #include <vtkUnstructuredGrid.h>
46 #include <vtkPointData.h>
47 #include <vtkCellData.h>
49 #include <vtkMapper.h>
50 #include <vtkRenderer.h>
53 #include <vtkIdList.h>
54 #include <vtkIntArray.h>
56 #include <vtkActor2D.h>
57 #include <vtkProperty2D.h>
58 #include <vtkPolyData.h>
59 #include <vtkMaskPoints.h>
60 #include <vtkCellCenters.h>
61 #include <vtkTextProperty.h>
62 #include <vtkLabeledDataMapper.h>
63 #include <vtkSelectVisiblePoints.h>
65 #include <vtkScalarBarActor.h>
66 #include <vtkLookupTable.h>
70 #include <vtkImplicitBoolean.h>
71 #include <vtkImplicitFunctionCollection.h>
73 #include "utilities.h"
76 static int MYDEBUG = 1;
78 static int MYDEBUG = 0;
81 static int aLineWidthInc = 2;
82 static int aPointSizeInc = 2;
85 SMESH_ActorDef* SMESH_ActorDef::New(){
86 return new SMESH_ActorDef();
90 SMESH_Actor* SMESH_Actor::New(TVisualObjPtr theVisualObj,
95 SMESH_ActorDef* anActor = SMESH_ActorDef::New();
96 if(!anActor->Init(theVisualObj,theEntry,theName,theIsClear)){
101 anActor->UpdateScalarBar();
106 SMESH_ActorDef::SMESH_ActorDef()
108 if(MYDEBUG) MESSAGE("SMESH_ActorDef - "<<this);
110 myTimeStamp = vtkTimeStamp::New();
112 myIsPointsVisible = false;
114 myIsShrinkable = false;
117 myIsFacesOriented = false;
119 myControlsPrecision = -1;
120 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
122 if ( mgr && mgr->booleanValue( "SMESH", "use_precision", false ) )
123 myControlsPrecision = mgr->integerValue( "SMESH", "controls_precision", -1);
125 vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
126 vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
128 vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
129 VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
131 //Definition 2D and 3D divices of the actor
132 //-----------------------------------------
133 vtkFloatingPointType anRGB[3] = {1,1,1};
134 mySurfaceProp = vtkProperty::New();
135 SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
136 mySurfaceProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
138 myBackSurfaceProp = vtkProperty::New();
139 SMESH::GetColor( "SMESH", "backface_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 0, 255 ) );
140 myBackSurfaceProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
142 my2DActor = SMESH_DeviceActor::New();
143 my2DActor->SetUserMatrix(aMatrix);
144 my2DActor->PickableOff();
145 my2DActor->SetProperty(mySurfaceProp);
146 my2DActor->SetBackfaceProperty(myBackSurfaceProp);
147 my2DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
148 aFilter = my2DActor->GetExtractUnstructuredGrid();
149 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
150 aFilter->RegisterCellsWithType(VTK_TRIANGLE);
151 aFilter->RegisterCellsWithType(VTK_POLYGON);
152 aFilter->RegisterCellsWithType(VTK_QUAD);
153 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
154 aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
156 my3DActor = SMESH_DeviceActor::New();
157 my3DActor->SetUserMatrix(aMatrix);
158 my3DActor->PickableOff();
159 my3DActor->SetProperty(mySurfaceProp);
160 my3DActor->SetBackfaceProperty(myBackSurfaceProp);
161 my3DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
162 aFilter = my3DActor->GetExtractUnstructuredGrid();
163 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
164 aFilter->RegisterCellsWithType(VTK_TETRA);
165 aFilter->RegisterCellsWithType(VTK_VOXEL);
166 aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
167 aFilter->RegisterCellsWithType(VTK_WEDGE);
168 aFilter->RegisterCellsWithType(VTK_PYRAMID);
169 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
170 aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
171 aFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
172 aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
174 //Definition 1D divice of the actor
175 //---------------------------------
176 myEdgeProp = vtkProperty::New();
177 myEdgeProp->SetAmbient(1.0);
178 myEdgeProp->SetDiffuse(0.0);
179 myEdgeProp->SetSpecular(0.0);
180 SMESH::GetColor( "SMESH", "outline_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
181 myEdgeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
182 myEdgeProp->SetLineWidth(aLineWidth);
184 my1DActor = SMESH_DeviceActor::New();
185 my1DActor->SetUserMatrix(aMatrix);
186 my1DActor->PickableOff();
187 my1DActor->SetHighlited(true);
188 my1DActor->SetProperty(myEdgeProp);
189 my1DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
190 aFilter = my1DActor->GetExtractUnstructuredGrid();
191 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
192 aFilter->RegisterCellsWithType(VTK_LINE);
193 aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
195 my1DProp = vtkProperty::New();
196 my1DProp->DeepCopy(myEdgeProp);
197 my1DProp->SetLineWidth(aLineWidth + aLineWidthInc);
198 my1DProp->SetPointSize(aPointSize);
200 my1DExtProp = vtkProperty::New();
201 my1DExtProp->DeepCopy(myEdgeProp);
202 anRGB[0] = 1 - anRGB[0];
203 anRGB[1] = 1 - anRGB[1];
204 anRGB[2] = 1 - anRGB[2];
205 my1DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
206 my1DExtProp->SetLineWidth(aLineWidth + aLineWidthInc);
207 my1DExtProp->SetPointSize(aPointSize + aPointSizeInc);
209 my1DExtActor = SMESH_DeviceActor::New();
210 my1DExtActor->SetUserMatrix(aMatrix);
211 my1DExtActor->PickableOff();
212 my1DExtActor->SetHighlited(true);
213 my1DExtActor->SetVisibility(false);
214 my1DExtActor->SetProperty(my1DExtProp);
215 my1DExtActor->SetRepresentation(SMESH_DeviceActor::eInsideframe);
216 aFilter = my1DExtActor->GetExtractUnstructuredGrid();
217 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
218 aFilter->RegisterCellsWithType(VTK_LINE);
219 aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
222 //Definition 0D divice of the actor
223 //---------------------------------
224 myNodeProp = vtkProperty::New();
225 SMESH::GetColor( "SMESH", "node_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 0, 0 ) );
226 myNodeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
227 myNodeProp->SetPointSize(aPointSize);
229 myNodeActor = SMESH_DeviceActor::New();
230 myNodeActor->SetUserMatrix(aMatrix);
231 myNodeActor->SetStoreClippingMapping(true);
232 myNodeActor->PickableOff();
233 myNodeActor->SetVisibility(false);
234 myNodeActor->SetProperty(myNodeProp);
235 myNodeActor->SetRepresentation(SMESH_DeviceActor::ePoint);
236 aFilter = myNodeActor->GetExtractUnstructuredGrid();
237 aFilter->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
240 //Definition of Pickable and Highlitable engines
241 //----------------------------------------------
243 myBaseActor = SMESH_DeviceActor::New();
244 myBaseActor->SetUserMatrix(aMatrix);
245 myBaseActor->SetStoreGemetryMapping(true);
246 myBaseActor->GetProperty()->SetOpacity(0.0);
248 myPickableActor = myBaseActor;
250 myHighlightProp = vtkProperty::New();
251 myHighlightProp->SetAmbient(1.0);
252 myHighlightProp->SetDiffuse(0.0);
253 myHighlightProp->SetSpecular(0.0);
254 SMESH::GetColor( "SMESH", "selection_object_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
255 myHighlightProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
256 myHighlightProp->SetPointSize(aPointSize);
257 myHighlightProp->SetRepresentation(1);
259 myPreselectProp = vtkProperty::New();
260 myPreselectProp->SetAmbient(1.0);
261 myPreselectProp->SetDiffuse(0.0);
262 myPreselectProp->SetSpecular(0.0);
263 SMESH::GetColor( "SMESH", "highlight_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 255, 255 ) );
264 myPreselectProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
265 myPreselectProp->SetPointSize(aPointSize);
266 myPreselectProp->SetRepresentation(1);
268 myHighlitableActor = SMESH_DeviceActor::New();
269 myHighlitableActor->SetUserMatrix(aMatrix);
270 myHighlitableActor->PickableOff();
271 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
276 myControlMode = eNone;
277 myControlActor = my2DActor;
279 //Definition of myScalarBarActor
280 //------------------------------
281 myLookupTable = vtkLookupTable::New();
282 //Fix for Bug PAL5195 - SMESH764:
283 //Controls - Aspect Ratio: incorrect colors of the best and worst values
284 myLookupTable->SetHueRange(0.667,0.0);
286 myScalarBarActor = vtkScalarBarActor::New();
287 myScalarBarActor->SetVisibility(false);
288 myScalarBarActor->SetLookupTable(myLookupTable);
291 //Incorrect "Min value" in Scalar Bar in Mesh:
292 // myScalarBarActor->SetLabelFormat("%.4g");
293 // changes was commented because of regression bug IPAL 19981
295 mgr = SUIT_Session::session()->resourceMgr();
299 //Definition of points numbering pipeline
300 //---------------------------------------
301 myPointsNumDataSet = vtkUnstructuredGrid::New();
303 myPtsMaskPoints = vtkMaskPoints::New();
304 myPtsMaskPoints->SetInput(myPointsNumDataSet);
305 myPtsMaskPoints->SetOnRatio(1);
307 myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
308 myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
309 myPtsSelectVisiblePoints->SelectInvisibleOff();
310 myPtsSelectVisiblePoints->SetTolerance(0.1);
312 myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
313 myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
314 myPtsLabeledDataMapper->SetLabelFormat("%g");
315 myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
317 vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
318 aPtsTextProp->SetFontFamilyToTimes();
319 static int aPointsFontSize = 10;
320 aPtsTextProp->SetFontSize(aPointsFontSize);
321 aPtsTextProp->SetBold(1);
322 aPtsTextProp->SetItalic(0);
323 aPtsTextProp->SetShadow(0);
324 myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
325 aPtsTextProp->Delete();
327 myEntityMode = eAllEntity;
329 myIsPointsLabeled = false;
331 myPointLabels = vtkActor2D::New();
332 myPointLabels->SetMapper(myPtsLabeledDataMapper);
333 myPointLabels->GetProperty()->SetColor(1,1,1);
334 myPointLabels->SetVisibility(myIsPointsLabeled);
337 //Definition of cells numbering pipeline
338 //---------------------------------------
339 myCellsNumDataSet = vtkUnstructuredGrid::New();
341 myCellCenters = vtkCellCenters::New();
342 myCellCenters->SetInput(myCellsNumDataSet);
344 myClsMaskPoints = vtkMaskPoints::New();
345 myClsMaskPoints->SetInput(myCellCenters->GetOutput());
346 myClsMaskPoints->SetOnRatio(1);
348 myClsSelectVisiblePoints = vtkSelectVisiblePoints::New();
349 myClsSelectVisiblePoints->SetInput(myClsMaskPoints->GetOutput());
350 myClsSelectVisiblePoints->SelectInvisibleOff();
351 myClsSelectVisiblePoints->SetTolerance(0.1);
353 myClsLabeledDataMapper = vtkLabeledDataMapper::New();
354 myClsLabeledDataMapper->SetInput(myClsSelectVisiblePoints->GetOutput());
355 myClsLabeledDataMapper->SetLabelFormat("%g");
356 myClsLabeledDataMapper->SetLabelModeToLabelScalars();
358 vtkTextProperty* aClsTextProp = vtkTextProperty::New();
359 aClsTextProp->SetFontFamilyToTimes();
360 static int aCellsFontSize = 12;
361 aClsTextProp->SetFontSize(aCellsFontSize);
362 aClsTextProp->SetBold(1);
363 aClsTextProp->SetItalic(0);
364 aClsTextProp->SetShadow(0);
365 myClsLabeledDataMapper->SetLabelTextProperty(aClsTextProp);
366 aClsTextProp->Delete();
368 myIsCellsLabeled = false;
370 myCellsLabels = vtkActor2D::New();
371 myCellsLabels->SetMapper(myClsLabeledDataMapper);
372 myCellsLabels->GetProperty()->SetColor(0,1,0);
373 myCellsLabels->SetVisibility(myIsCellsLabeled);
376 myImplicitBoolean = vtkImplicitBoolean::New();
377 myImplicitBoolean->SetOperationTypeToIntersection();
381 SMESH_ActorDef::~SMESH_ActorDef()
383 if(MYDEBUG) MESSAGE("~SMESH_ActorDef - "<<this);
385 myScalarBarActor->Delete();
386 myLookupTable->Delete();
388 mySurfaceProp->Delete();
389 myBackSurfaceProp->Delete();
391 myEdgeProp->Delete();
392 myHighlightProp->Delete();
393 myPreselectProp->Delete();
395 myNodeProp->Delete();
400 my1DExtProp->Delete();
401 my1DExtActor->Delete();
406 myNodeActor->Delete();
407 myBaseActor->Delete();
409 myHighlitableActor->Delete();
411 //Deleting of pints numbering pipeline
412 //---------------------------------------
413 myPointsNumDataSet->Delete();
415 // commented: porting to vtk 5.0
416 // myPtsLabeledDataMapper->RemoveAllInputs();
417 myPtsLabeledDataMapper->Delete();
419 // commented: porting to vtk 5.0
420 // myPtsSelectVisiblePoints->UnRegisterAllOutputs();
421 myPtsSelectVisiblePoints->Delete();
423 // commented: porting to vtk 5.0
424 // myPtsMaskPoints->UnRegisterAllOutputs();
425 myPtsMaskPoints->Delete();
427 myPointLabels->Delete();
430 //Deleting of cells numbering pipeline
431 //---------------------------------------
432 myCellsNumDataSet->Delete();
434 myClsLabeledDataMapper->RemoveAllInputs();
435 myClsLabeledDataMapper->Delete();
437 // commented: porting to vtk 5.0
438 // myClsSelectVisiblePoints->UnRegisterAllOutputs();
439 myClsSelectVisiblePoints->Delete();
441 // commented: porting to vtk 5.0
442 // myClsMaskPoints->UnRegisterAllOutputs();
443 myClsMaskPoints->Delete();
445 // commented: porting to vtk 5.0
446 // myCellCenters->UnRegisterAllOutputs();
447 myCellCenters->Delete();
449 myCellsLabels->Delete();
451 myImplicitBoolean->Delete();
453 myTimeStamp->Delete();
457 void SMESH_ActorDef::SetPointsLabeled( bool theIsPointsLabeled )
459 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
460 myIsPointsLabeled = theIsPointsLabeled && aGrid->GetNumberOfPoints();
462 if ( myIsPointsLabeled )
464 myPointsNumDataSet->ShallowCopy(aGrid);
465 vtkDataSet *aDataSet = myPointsNumDataSet;
467 int aNbElem = aDataSet->GetNumberOfPoints();
469 vtkIntArray *anArray = vtkIntArray::New();
470 anArray->SetNumberOfValues( aNbElem );
472 for ( int anId = 0; anId < aNbElem; anId++ )
474 int aSMDSId = myVisualObj->GetNodeObjId( anId );
475 anArray->SetValue( anId, aSMDSId );
478 aDataSet->GetPointData()->SetScalars( anArray );
480 myPtsMaskPoints->SetInput( aDataSet );
481 myPointLabels->SetVisibility( GetVisibility() );
485 myPointLabels->SetVisibility( false );
487 SetRepresentation(GetRepresentation());
488 myTimeStamp->Modified();
492 void SMESH_ActorDef::SetCellsLabeled(bool theIsCellsLabeled)
494 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
495 myIsCellsLabeled = theIsCellsLabeled && aGrid->GetNumberOfPoints();
496 if(myIsCellsLabeled){
497 myCellsNumDataSet->ShallowCopy(aGrid);
498 vtkDataSet *aDataSet = myCellsNumDataSet;
499 int aNbElem = aDataSet->GetNumberOfCells();
500 vtkIntArray *anArray = vtkIntArray::New();
501 anArray->SetNumberOfValues(aNbElem);
502 for(int anId = 0; anId < aNbElem; anId++){
503 int aSMDSId = myVisualObj->GetElemObjId(anId);
504 anArray->SetValue(anId,aSMDSId);
506 aDataSet->GetCellData()->SetScalars(anArray);
507 myCellCenters->SetInput(aDataSet);
508 myCellsLabels->SetVisibility(GetVisibility());
510 myCellsLabels->SetVisibility(false);
512 myTimeStamp->Modified();
516 void SMESH_ActorDef::SetFacesOriented(bool theIsFacesOriented)
518 myIsFacesOriented = theIsFacesOriented;
520 my2DActor->SetFacesOriented(theIsFacesOriented);
521 my3DActor->SetFacesOriented(theIsFacesOriented);
523 myTimeStamp->Modified();
526 bool SMESH_ActorDef::GetFacesOriented()
528 return myIsFacesOriented;
534 SetControlMode(eControl theMode)
536 SetControlMode(theMode,true);
542 SetControlMode(eControl theMode,
543 bool theCheckEntityMode)
545 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
549 myControlMode = eNone;
550 theCheckEntityMode &= mgr->booleanValue( "SMESH", "display_entity", false );
552 my1DActor->GetMapper()->SetScalarVisibility(false);
553 my2DActor->GetMapper()->SetScalarVisibility(false);
554 my3DActor->GetMapper()->SetScalarVisibility(false);
555 myScalarBarActor->SetVisibility(false);
557 bool anIsScalarVisible = theMode > eNone;
559 if(anIsScalarVisible){
560 SMESH::Controls::FunctorPtr aFunctor;
564 SMESH::Controls::Length* aControl = new SMESH::Controls::Length();
565 aControl->SetPrecision( myControlsPrecision );
566 aFunctor.reset( aControl );
567 myControlActor = my1DActor;
572 aFunctor.reset(new SMESH::Controls::Length2D());
573 myControlActor = my2DActor;
577 aFunctor.reset(new SMESH::Controls::FreeBorders());
578 myControlActor = my1DActor;
581 aFunctor.reset(new SMESH::Controls::FreeEdges());
582 myControlActor = my2DActor;
584 case eMultiConnection:
585 aFunctor.reset(new SMESH::Controls::MultiConnection());
586 myControlActor = my1DActor;
588 case eMultiConnection2D:
589 aFunctor.reset(new SMESH::Controls::MultiConnection2D());
590 myControlActor = my2DActor;
594 SMESH::Controls::Area* aControl = new SMESH::Controls::Area();
595 aControl->SetPrecision( myControlsPrecision );
596 aFunctor.reset( aControl );
597 myControlActor = my2DActor;
602 SMESH::Controls::Taper* aControl = new SMESH::Controls::Taper();
603 aControl->SetPrecision( myControlsPrecision );
604 aFunctor.reset( aControl );
605 myControlActor = my2DActor;
610 SMESH::Controls::AspectRatio* aControl = new SMESH::Controls::AspectRatio();
611 aControl->SetPrecision( myControlsPrecision );
612 aFunctor.reset( aControl );
613 myControlActor = my2DActor;
618 SMESH::Controls::AspectRatio3D* aControl = new SMESH::Controls::AspectRatio3D();
619 aControl->SetPrecision( myControlsPrecision );
620 aFunctor.reset( aControl );
621 myControlActor = my3DActor;
626 SMESH::Controls::Volume* aControl = new SMESH::Controls::Volume();
627 aControl->SetPrecision( myControlsPrecision );
628 aFunctor.reset( aControl );
629 myControlActor = my3DActor;
634 SMESH::Controls::MinimumAngle* aControl = new SMESH::Controls::MinimumAngle();
635 aControl->SetPrecision( myControlsPrecision );
636 aFunctor.reset( aControl );
637 myControlActor = my2DActor;
642 SMESH::Controls::Warping* aControl = new SMESH::Controls::Warping();
643 aControl->SetPrecision( myControlsPrecision );
644 aFunctor.reset( aControl );
645 myControlActor = my2DActor;
650 SMESH::Controls::Skew* aControl = new SMESH::Controls::Skew();
651 aControl->SetPrecision( myControlsPrecision );
652 aFunctor.reset( aControl );
653 myControlActor = my2DActor;
660 vtkUnstructuredGrid* aGrid = myControlActor->GetUnstructuredGrid();
661 vtkIdType aNbCells = aGrid->GetNumberOfCells();
663 myControlMode = theMode;
664 switch(myControlMode){
667 my1DExtActor->SetExtControlMode(aFunctor);
670 case eMultiConnection2D:
671 my1DExtActor->SetExtControlMode(aFunctor,myScalarBarActor,myLookupTable);
674 myControlActor->SetControlMode(aFunctor,myScalarBarActor,myLookupTable);
678 if(theCheckEntityMode){
679 if(myControlActor == my1DActor)
680 SetEntityMode(eEdges);
681 else if(myControlActor == my2DActor){
682 switch(myControlMode){
685 case eMultiConnection2D:
686 //SetEntityMode(eEdges);
687 SetEntityMode(eFaces);
690 SetEntityMode(eFaces);
692 }else if(myControlActor == my3DActor)
693 SetEntityMode(eVolumes);
696 }else if(theCheckEntityMode){
697 myEntityMode = eAllEntity;
700 SetRepresentation(GetRepresentation());
702 myTimeStamp->Modified();
707 void SMESH_ActorDef::AddToRender(vtkRenderer* theRenderer){
708 SALOME_Actor::AddToRender(theRenderer);
710 theRenderer->AddActor(myNodeActor);
711 theRenderer->AddActor(myBaseActor);
713 my3DActor->AddToRender(theRenderer);
714 my2DActor->AddToRender(theRenderer);
716 theRenderer->AddActor(my1DActor);
717 theRenderer->AddActor(my1DExtActor);
719 theRenderer->AddActor(myHighlitableActor);
721 theRenderer->AddActor2D(myScalarBarActor);
723 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
724 myClsSelectVisiblePoints->SetRenderer(theRenderer);
726 theRenderer->AddActor2D(myPointLabels);
727 theRenderer->AddActor2D(myCellsLabels);
730 void SMESH_ActorDef::RemoveFromRender(vtkRenderer* theRenderer){
731 SALOME_Actor::RemoveFromRender(theRenderer);
733 theRenderer->RemoveActor(myNodeActor);
734 theRenderer->RemoveActor(myBaseActor);
736 theRenderer->RemoveActor(myHighlitableActor);
738 theRenderer->RemoveActor(my1DActor);
739 theRenderer->RemoveActor(my1DExtActor);
741 my2DActor->RemoveFromRender(theRenderer);
742 my3DActor->RemoveFromRender(theRenderer);
744 theRenderer->RemoveActor(myScalarBarActor);
745 theRenderer->RemoveActor(myPointLabels);
746 theRenderer->RemoveActor(myCellsLabels);
750 bool SMESH_ActorDef::Init(TVisualObjPtr theVisualObj,
751 const char* theEntry,
755 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry,"SMESH",theName);
759 myVisualObj = theVisualObj;
760 myVisualObj->Update(theIsClear);
762 myNodeActor->Init(myVisualObj,myImplicitBoolean);
763 myBaseActor->Init(myVisualObj,myImplicitBoolean);
765 myHighlitableActor->Init(myVisualObj,myImplicitBoolean);
767 my1DActor->Init(myVisualObj,myImplicitBoolean);
768 my1DExtActor->Init(myVisualObj,myImplicitBoolean);
770 my2DActor->Init(myVisualObj,myImplicitBoolean);
771 my3DActor->Init(myVisualObj,myImplicitBoolean);
773 my1DActor->GetMapper()->SetLookupTable(myLookupTable);
774 my1DExtActor->GetMapper()->SetLookupTable(myLookupTable);
776 my2DActor->GetMapper()->SetLookupTable(myLookupTable);
777 my3DActor->GetMapper()->SetLookupTable(myLookupTable);
779 vtkFloatingPointType aFactor, aUnits;
780 my2DActor->GetPolygonOffsetParameters(aFactor,aUnits);
781 my2DActor->SetPolygonOffsetParameters(aFactor,aUnits*0.75);
783 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
787 //SetIsShrunkable(theGrid->GetNumberOfCells() > 10);
788 SetIsShrunkable(true);
790 SetShrinkFactor( SMESH::GetFloat( "SMESH:shrink_coeff", 75 ) / 100. );
792 int aMode = mgr->integerValue( "SMESH", "display_mode" );
793 SetRepresentation(-1);
796 SetRepresentation(eEdge);
797 }else if(aMode == 1){
798 SetRepresentation(eSurface);
799 }else if(aMode == 2){
800 SetRepresentation(ePoint);
807 myTimeStamp->Modified();
813 vtkFloatingPointType* SMESH_ActorDef::GetBounds(){
814 return myNodeActor->GetBounds();
818 vtkDataSet* SMESH_ActorDef::GetInput(){
819 return GetUnstructuredGrid();
823 void SMESH_ActorDef::SetTransform(VTKViewer_Transform* theTransform){
824 Superclass::SetTransform(theTransform);
826 myNodeActor->SetTransform(theTransform);
827 myBaseActor->SetTransform(theTransform);
829 myHighlitableActor->SetTransform(theTransform);
831 my1DActor->SetTransform(theTransform);
832 my1DExtActor->SetTransform(theTransform);
834 my2DActor->SetTransform(theTransform);
835 my3DActor->SetTransform(theTransform);
841 void SMESH_ActorDef::SetMapper(vtkMapper* theMapper){
842 vtkLODActor::SetMapper(theMapper);
846 void SMESH_ActorDef::ShallowCopy(vtkProp *prop){
847 SALOME_Actor::ShallowCopy(prop);
851 vtkMapper* SMESH_ActorDef::GetMapper(){
852 return myPickableActor->GetMapper();
856 vtkUnstructuredGrid* SMESH_ActorDef::GetUnstructuredGrid(){
857 return myVisualObj->GetUnstructuredGrid();
861 bool SMESH_ActorDef::IsInfinitive(){
862 vtkDataSet *aDataSet = myPickableActor->GetUnstructuredGrid();
864 myIsInfinite = aDataSet->GetNumberOfCells() == 0 ||
865 aDataSet->GetNumberOfCells() == 1 &&
866 aDataSet->GetCell(0)->GetCellType() == VTK_VERTEX;
867 return SALOME_Actor::IsInfinitive();
871 void SMESH_ActorDef::SetIsShrunkable(bool theShrunkable){
872 if ( myIsShrinkable == theShrunkable )
874 myIsShrinkable = theShrunkable;
878 vtkFloatingPointType SMESH_ActorDef::GetShrinkFactor(){
879 return myBaseActor->GetShrinkFactor();
882 void SMESH_ActorDef::SetShrinkFactor(vtkFloatingPointType theValue){
883 myBaseActor->SetShrinkFactor(theValue);
885 my1DActor->SetShrinkFactor(theValue);
886 my1DExtActor->SetShrinkFactor(theValue);
888 my2DActor->SetShrinkFactor(theValue);
889 my3DActor->SetShrinkFactor(theValue);
894 void SMESH_ActorDef::SetShrink(){
895 if(!myIsShrinkable) return;
897 myBaseActor->SetShrink();
899 my1DActor->SetShrink();
900 my1DExtActor->SetShrink();
902 my2DActor->SetShrink();
903 my3DActor->SetShrink();
909 void SMESH_ActorDef::UnShrink(){
910 if(!myIsShrunk) return;
912 myBaseActor->UnShrink();
914 my1DActor->UnShrink();
915 my1DExtActor->UnShrink();
917 my2DActor->UnShrink();
918 my3DActor->UnShrink();
925 int SMESH_ActorDef::GetNodeObjId(int theVtkID){
926 return myPickableActor->GetNodeObjId(theVtkID);
929 vtkFloatingPointType* SMESH_ActorDef::GetNodeCoord(int theObjID){
930 return myPickableActor->GetNodeCoord(theObjID);
934 int SMESH_ActorDef::GetElemObjId(int theVtkID){
935 return myPickableActor->GetElemObjId(theVtkID);
938 vtkCell* SMESH_ActorDef::GetElemCell(int theObjID){
939 return myPickableActor->GetElemCell(theObjID);
943 void SMESH_ActorDef::SetVisibility(int theMode){
944 SetVisibility(theMode,true);
948 void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation){
949 SALOME_Actor::SetVisibility(theMode);
951 myNodeActor->VisibilityOff();
952 myBaseActor->VisibilityOff();
954 my1DActor->VisibilityOff();
955 my1DExtActor->VisibilityOff();
957 my2DActor->VisibilityOff();
958 my3DActor->VisibilityOff();
960 myScalarBarActor->VisibilityOff();
961 myPointLabels->VisibilityOff();
962 myCellsLabels->VisibilityOff();
965 if(theIsUpdateRepersentation)
966 SetRepresentation(GetRepresentation());
968 if(myControlMode != eNone){
969 switch(myControlMode){
972 my1DExtActor->VisibilityOn();
975 case eMultiConnection2D:
976 my1DExtActor->VisibilityOn();
978 if(myControlActor->GetUnstructuredGrid()->GetNumberOfCells())
979 myScalarBarActor->VisibilityOn();
983 if(myRepresentation != ePoint)
984 myPickableActor->VisibilityOn();
986 myNodeActor->VisibilityOn();
989 if(myEntityMode & eEdges){
990 my1DActor->VisibilityOn();
993 if(myEntityMode & eFaces){
994 my2DActor->VisibilityOn();
997 if(myEntityMode & eVolumes){
998 my3DActor->VisibilityOn();
1001 if(myIsPointsLabeled){
1002 myPointLabels->VisibilityOn();
1003 myNodeActor->VisibilityOn();
1006 if(myIsCellsLabeled)
1007 myCellsLabels->VisibilityOn();
1014 void SMESH_ActorDef::SetEntityMode(unsigned int theMode){
1015 myEntityState = eAllEntity;
1017 if(!myVisualObj->GetNbEntities(SMDSAbs_Edge)){
1018 myEntityState &= ~eEdges;
1022 if(!myVisualObj->GetNbEntities(SMDSAbs_Face)){
1023 myEntityState &= ~eFaces;
1027 if(!myVisualObj->GetNbEntities(SMDSAbs_Volume)){
1028 myEntityState &= ~eVolumes;
1029 theMode &= ~eVolumes;
1033 if(myVisualObj->GetNbEntities(SMDSAbs_Edge))
1036 if(myVisualObj->GetNbEntities(SMDSAbs_Face))
1039 if(myVisualObj->GetNbEntities(SMDSAbs_Volume))
1040 theMode |= eVolumes;
1043 myBaseActor->myGeomFilter->SetInside(myEntityMode != myEntityState);
1045 myEntityMode = theMode;
1046 VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
1047 aFilter = myBaseActor->GetExtractUnstructuredGrid();
1048 aFilter->ClearRegisteredCellsWithType();
1049 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
1051 if(myEntityMode & eEdges){
1052 if (MYDEBUG) MESSAGE("EDGES");
1053 aFilter->RegisterCellsWithType(VTK_LINE);
1054 aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
1057 if(myEntityMode & eFaces){
1058 if (MYDEBUG) MESSAGE("FACES");
1059 aFilter->RegisterCellsWithType(VTK_TRIANGLE);
1060 aFilter->RegisterCellsWithType(VTK_POLYGON);
1061 aFilter->RegisterCellsWithType(VTK_QUAD);
1062 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
1063 aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
1066 if(myEntityMode & eVolumes){
1067 if (MYDEBUG) MESSAGE("VOLUMES");
1068 aFilter->RegisterCellsWithType(VTK_TETRA);
1069 aFilter->RegisterCellsWithType(VTK_VOXEL);
1070 aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1071 aFilter->RegisterCellsWithType(VTK_WEDGE);
1072 aFilter->RegisterCellsWithType(VTK_PYRAMID);
1073 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
1074 aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
1075 aFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
1076 aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1079 if (MYDEBUG) MESSAGE(aFilter->GetOutput()->GetNumberOfCells());
1080 SetVisibility(GetVisibility(),false);
1083 void SMESH_ActorDef::SetRepresentation(int theMode){
1084 int aNbEdges = myVisualObj->GetNbEntities(SMDSAbs_Edge);
1085 int aNbFaces = myVisualObj->GetNbEntities(SMDSAbs_Face);
1086 int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume);
1088 myRepresentation = eSurface;
1089 if(!aNbFaces && !aNbVolumes && aNbEdges){
1090 myRepresentation = eEdge;
1091 }else if(!aNbFaces && !aNbVolumes && !aNbEdges){
1092 myRepresentation = ePoint;
1097 if(!aNbFaces && !aNbVolumes && !aNbEdges) return;
1100 if(!aNbFaces && !aNbVolumes) return;
1103 myRepresentation = theMode;
1106 if(!GetUnstructuredGrid()->GetNumberOfCells())
1107 myRepresentation = ePoint;
1110 if(myRepresentation == ePoint){
1118 myPickableActor = myBaseActor;
1119 myNodeActor->SetVisibility(false);
1120 vtkProperty *aProp = NULL, *aBackProp = NULL;
1121 SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1);
1122 switch(myRepresentation){
1124 myPickableActor = myNodeActor;
1125 myNodeActor->SetVisibility(true);
1127 aProp = aBackProp = myNodeProp;
1128 aReperesent = SMESH_DeviceActor::ePoint;
1131 aProp = aBackProp = myEdgeProp;
1132 aReperesent = SMESH_DeviceActor::eInsideframe;
1135 aProp = mySurfaceProp;
1136 aBackProp = myBackSurfaceProp;
1137 aReperesent = SMESH_DeviceActor::eSurface;
1141 my2DActor->SetProperty(aProp);
1142 my2DActor->SetBackfaceProperty(aBackProp);
1143 my2DActor->SetRepresentation(aReperesent);
1145 my3DActor->SetProperty(aProp);
1146 my3DActor->SetBackfaceProperty(aBackProp);
1147 my3DActor->SetRepresentation(aReperesent);
1149 my1DExtActor->SetVisibility(false);
1151 switch(myControlMode){
1153 case eMultiConnection:
1154 aProp = aBackProp = my1DProp;
1155 if(myRepresentation != ePoint)
1156 aReperesent = SMESH_DeviceActor::eInsideframe;
1160 my1DActor->SetProperty(aProp);
1161 my1DActor->SetBackfaceProperty(aBackProp);
1162 my1DActor->SetRepresentation(aReperesent);
1164 my1DExtActor->SetRepresentation(aReperesent);
1166 if(myIsPointsVisible)
1167 myPickableActor = myNodeActor;
1168 if(GetPointRepresentation())
1169 myNodeActor->SetVisibility(true);
1171 SetMapper(myPickableActor->GetMapper());
1173 SetVisibility(GetVisibility(),false);
1179 void SMESH_ActorDef::SetPointRepresentation(bool theIsPointsVisible){
1180 if ( myIsPointsVisible == theIsPointsVisible )
1182 myIsPointsVisible = theIsPointsVisible;
1183 SetRepresentation(GetRepresentation());
1186 bool SMESH_ActorDef::GetPointRepresentation(){
1187 return myIsPointsVisible || myIsPointsLabeled;
1191 void SMESH_ActorDef::UpdateHighlight(){
1192 myHighlitableActor->SetVisibility(false);
1193 myHighlitableActor->SetHighlited(false);
1195 if(myIsHighlighted){
1196 myHighlitableActor->SetProperty(myHighlightProp);
1197 }else if(myIsPreselected){
1198 myHighlitableActor->SetProperty(myPreselectProp);
1201 bool anIsVisible = GetVisibility();
1203 if(myIsHighlighted || myIsPreselected){
1204 if(GetUnstructuredGrid()->GetNumberOfCells()){
1205 myHighlitableActor->SetHighlited(anIsVisible);
1206 myHighlitableActor->SetVisibility(anIsVisible);
1207 myHighlitableActor->GetExtractUnstructuredGrid()->
1208 SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::eCells);
1209 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
1210 }else if(myRepresentation == ePoint || GetPointRepresentation()){
1211 myHighlitableActor->SetHighlited(anIsVisible);
1212 myHighlitableActor->GetExtractUnstructuredGrid()->
1213 SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
1214 myHighlitableActor->SetVisibility(anIsVisible);
1215 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::ePoint);
1221 void SMESH_ActorDef::highlight(bool theHighlight){
1222 if ( myIsHighlighted == theHighlight )
1224 myIsHighlighted = theHighlight;
1229 void SMESH_ActorDef::SetPreSelected(bool thePreselect){
1230 if ( myIsPreselected == thePreselect )
1232 myIsPreselected = thePreselect;
1238 int SMESH_ActorDef::RenderOpaqueGeometry(vtkViewport *vp)
1240 if (myPickableActor->GetIsOpaque())
1242 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1250 int SMESH_ActorDef::RenderTranslucentGeometry(vtkViewport *vp)
1252 if (!myPickableActor->GetIsOpaque())
1254 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1262 void SMESH_ActorDef::Render(vtkRenderer *ren){
1263 unsigned long aTime = myTimeStamp->GetMTime();
1264 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1265 unsigned long aClippingTime = myImplicitBoolean->GetMTime();
1266 if(anObjTime > aTime || aClippingTime > aTime)
1271 void SMESH_ActorDef::Update(){
1272 if(MYDEBUG) MESSAGE("SMESH_ActorDef::Update");
1274 if(GetControlMode() != eNone) {
1275 unsigned long aTime = myTimeStamp->GetMTime();
1276 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1277 if (anObjTime > aTime)
1278 SetControlMode(GetControlMode(),false);
1280 if(myIsPointsLabeled){
1281 SetPointsLabeled(myIsPointsLabeled);
1283 if(myIsCellsLabeled){
1284 SetCellsLabeled(myIsCellsLabeled);
1286 if(myIsFacesOriented){
1287 SetFacesOriented(myIsFacesOriented);
1289 SetEntityMode(GetEntityMode());
1290 SetVisibility(GetVisibility());
1292 myTimeStamp->Modified();
1297 void SMESH_ActorDef::ReleaseGraphicsResources(vtkWindow *renWin){
1298 SALOME_Actor::ReleaseGraphicsResources(renWin);
1300 myPickableActor->ReleaseGraphicsResources(renWin);
1304 static void GetColor(vtkProperty *theProperty, vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1305 vtkFloatingPointType* aColor = theProperty->GetColor();
1312 void SMESH_ActorDef::SetOpacity(vtkFloatingPointType theValue){
1313 mySurfaceProp->SetOpacity(theValue);
1314 myBackSurfaceProp->SetOpacity(theValue);
1315 myEdgeProp->SetOpacity(theValue);
1316 myNodeProp->SetOpacity(theValue);
1318 my1DProp->SetOpacity(theValue);
1322 vtkFloatingPointType SMESH_ActorDef::GetOpacity(){
1323 return mySurfaceProp->GetOpacity();
1327 void SMESH_ActorDef::SetSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1328 mySurfaceProp->SetColor(r,g,b);
1332 void SMESH_ActorDef::GetSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1333 ::GetColor(mySurfaceProp,r,g,b);
1336 void SMESH_ActorDef::SetBackSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1337 myBackSurfaceProp->SetColor(r,g,b);
1341 void SMESH_ActorDef::GetBackSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1342 ::GetColor(myBackSurfaceProp,r,g,b);
1345 void SMESH_ActorDef::SetEdgeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1346 myEdgeProp->SetColor(r,g,b);
1347 my1DProp->SetColor(r,g,b);
1348 my1DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1352 void SMESH_ActorDef::GetEdgeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1353 ::GetColor(myEdgeProp,r,g,b);
1356 void SMESH_ActorDef::SetNodeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1357 myNodeProp->SetColor(r,g,b);
1361 void SMESH_ActorDef::GetNodeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1362 ::GetColor(myNodeProp,r,g,b);
1365 void SMESH_ActorDef::SetHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1366 myHighlightProp->SetColor(r,g,b);
1370 void SMESH_ActorDef::GetHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1371 ::GetColor(myHighlightProp,r,g,b);
1374 void SMESH_ActorDef::SetPreHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1375 myPreselectProp->SetColor(r,g,b);
1379 void SMESH_ActorDef::GetPreHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1380 ::GetColor(myPreselectProp,r,g,b);
1384 vtkFloatingPointType SMESH_ActorDef::GetLineWidth(){
1385 return myEdgeProp->GetLineWidth();
1389 void SMESH_ActorDef::SetLineWidth(vtkFloatingPointType theVal){
1390 myEdgeProp->SetLineWidth(theVal);
1392 my1DProp->SetLineWidth(theVal + aLineWidthInc);
1393 my1DExtProp->SetLineWidth(theVal + aLineWidthInc);
1399 void SMESH_ActorDef::SetNodeSize(vtkFloatingPointType theVal){
1400 myNodeProp->SetPointSize(theVal);
1401 myHighlightProp->SetPointSize(theVal);
1402 myPreselectProp->SetPointSize(theVal);
1404 my1DProp->SetPointSize(theVal + aPointSizeInc);
1405 my1DExtProp->SetPointSize(theVal + aPointSizeInc);
1410 vtkFloatingPointType SMESH_ActorDef::GetNodeSize(){
1411 return myNodeProp->GetPointSize();
1414 int SMESH_ActorDef::GetObjDimension( const int theObjId )
1416 return myVisualObj->GetElemDimension( theObjId );
1421 IsImplicitFunctionUsed() const
1423 return myBaseActor->IsImplicitFunctionUsed();
1428 SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
1430 myNodeActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1431 myBaseActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1433 myHighlitableActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1435 my1DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1436 my1DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1438 my2DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1439 my3DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1444 AddClippingPlane(vtkPlane* thePlane)
1447 myImplicitBoolean->GetFunction()->AddItem(thePlane);
1448 myCippingPlaneCont.push_back(thePlane);
1449 if(!IsImplicitFunctionUsed())
1450 SetImplicitFunctionUsed(true);
1452 return myCippingPlaneCont.size();
1457 RemoveAllClippingPlanes()
1459 myImplicitBoolean->GetFunction()->RemoveAllItems();
1460 myImplicitBoolean->GetFunction()->Modified(); // VTK bug
1461 myCippingPlaneCont.clear();
1462 SetImplicitFunctionUsed(false);
1467 GetNumberOfClippingPlanes()
1469 return myCippingPlaneCont.size();
1474 GetClippingPlane(vtkIdType theID)
1476 if(theID >= myCippingPlaneCont.size())
1478 return myCippingPlaneCont[theID].Get();
1482 static void ComputeBoundsParam(vtkDataSet* theDataSet,
1483 vtkFloatingPointType theDirection[3], vtkFloatingPointType theMinPnt[3],
1484 vtkFloatingPointType& theMaxBoundPrj, vtkFloatingPointType& theMinBoundPrj)
1486 vtkFloatingPointType aBounds[6];
1487 theDataSet->GetBounds(aBounds);
1489 //Enlarge bounds in order to avoid conflicts of precision
1490 for(int i = 0; i < 6; i += 2){
1491 static double EPS = 1.0E-3;
1492 vtkFloatingPointType aDelta = (aBounds[i+1] - aBounds[i])*EPS;
1493 aBounds[i] -= aDelta;
1494 aBounds[i+1] += aDelta;
1497 vtkFloatingPointType aBoundPoints[8][3] = { {aBounds[0],aBounds[2],aBounds[4]},
1498 {aBounds[1],aBounds[2],aBounds[4]},
1499 {aBounds[0],aBounds[3],aBounds[4]},
1500 {aBounds[1],aBounds[3],aBounds[4]},
1501 {aBounds[0],aBounds[2],aBounds[5]},
1502 {aBounds[1],aBounds[2],aBounds[5]},
1503 {aBounds[0],aBounds[3],aBounds[5]},
1504 {aBounds[1],aBounds[3],aBounds[5]}};
1506 int aMaxId = 0, aMinId = aMaxId;
1507 theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
1508 theMinBoundPrj = theMaxBoundPrj;
1509 for(int i = 1; i < 8; i++){
1510 vtkFloatingPointType aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
1511 if(theMaxBoundPrj < aTmp){
1512 theMaxBoundPrj = aTmp;
1515 if(theMinBoundPrj > aTmp){
1516 theMinBoundPrj = aTmp;
1520 vtkFloatingPointType *aMinPnt = aBoundPoints[aMaxId];
1521 theMinPnt[0] = aMinPnt[0];
1522 theMinPnt[1] = aMinPnt[1];
1523 theMinPnt[2] = aMinPnt[2];
1527 static void DistanceToPosition(vtkDataSet* theDataSet,
1528 vtkFloatingPointType theDirection[3], vtkFloatingPointType theDist, vtkFloatingPointType thePos[3])
1530 vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1531 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1532 vtkFloatingPointType aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
1533 thePos[0] = aMinPnt[0]-theDirection[0]*aLength;
1534 thePos[1] = aMinPnt[1]-theDirection[1]*aLength;
1535 thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
1539 static void PositionToDistance(vtkDataSet* theDataSet,
1540 vtkFloatingPointType theDirection[3], vtkFloatingPointType thePos[3], vtkFloatingPointType& theDist)
1542 vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1543 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1544 vtkFloatingPointType aPrj = vtkMath::Dot(theDirection,thePos);
1545 theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
1549 void SMESH_ActorDef::SetPlaneParam(vtkFloatingPointType theDir[3], vtkFloatingPointType theDist, vtkPlane* thePlane)
1551 thePlane->SetNormal(theDir);
1552 vtkFloatingPointType anOrigin[3];
1553 ::DistanceToPosition(GetUnstructuredGrid(),theDir,theDist,anOrigin);
1554 thePlane->SetOrigin(anOrigin);
1558 void SMESH_ActorDef::GetPlaneParam(vtkFloatingPointType theDir[3], vtkFloatingPointType& theDist, vtkPlane* thePlane)
1560 thePlane->GetNormal(theDir);
1562 vtkFloatingPointType anOrigin[3];
1563 thePlane->GetOrigin(anOrigin);
1564 ::PositionToDistance(GetUnstructuredGrid(),theDir,anOrigin,theDist);
1567 void SMESH_ActorDef::UpdateScalarBar()
1569 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
1573 vtkTextProperty* aScalarBarTitleProp = vtkTextProperty::New();
1575 QColor aTColor = mgr->colorValue( "SMESH", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
1576 aScalarBarTitleProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1578 aScalarBarTitleProp->SetFontFamilyToArial();
1580 if ( mgr->hasValue( "SMESH", "scalar_bar_title_font" ) )
1582 QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
1583 if ( f.family() == "Arial" )
1584 aScalarBarTitleProp->SetFontFamilyToArial();
1585 else if ( f.family() == "Courier" )
1586 aScalarBarTitleProp->SetFontFamilyToCourier();
1587 else if ( f.family() == "Times" )
1588 aScalarBarTitleProp->SetFontFamilyToTimes();
1591 aScalarBarTitleProp->BoldOn();
1593 aScalarBarTitleProp->BoldOff();
1596 aScalarBarTitleProp->ItalicOn();
1598 aScalarBarTitleProp->ItalicOff();
1600 if ( f.underline() )
1601 aScalarBarTitleProp->ShadowOn();
1603 aScalarBarTitleProp->ShadowOff();
1606 myScalarBarActor->SetTitleTextProperty( aScalarBarTitleProp );
1607 aScalarBarTitleProp->Delete();
1609 vtkTextProperty* aScalarBarLabelProp = vtkTextProperty::New();
1611 aTColor = mgr->colorValue( "SMESH", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
1612 aScalarBarLabelProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1614 aScalarBarLabelProp->SetFontFamilyToArial();
1615 if( mgr->hasValue( "SMESH", "scalar_bar_label_font" ) )
1617 QFont f = mgr->fontValue( "SMESH", "scalar_bar_label_font" );
1618 if( f.family() == "Arial" )
1619 aScalarBarLabelProp->SetFontFamilyToArial();
1620 else if( f.family() == "Courier" )
1621 aScalarBarLabelProp->SetFontFamilyToCourier();
1622 else if( f.family() == "Times" )
1623 aScalarBarLabelProp->SetFontFamilyToTimes();
1626 aScalarBarLabelProp->BoldOn();
1628 aScalarBarLabelProp->BoldOff();
1631 aScalarBarLabelProp->ItalicOn();
1633 aScalarBarLabelProp->ItalicOff();
1636 aScalarBarLabelProp->ShadowOn();
1638 aScalarBarLabelProp->ShadowOff();
1641 myScalarBarActor->SetLabelTextProperty( aScalarBarLabelProp );
1642 aScalarBarLabelProp->Delete();
1644 bool horiz = ( mgr->integerValue( "SMESH", "scalar_bar_orientation" ) == 1 );
1645 QString name = QString( "scalar_bar_%1_" ).arg( horiz ? "horizontal" : "vertical" );
1647 myScalarBarActor->SetOrientationToHorizontal();
1649 myScalarBarActor->SetOrientationToVertical();
1652 vtkFloatingPointType aXVal = horiz ? 0.20 : 0.01;
1653 if( mgr->hasValue( "SMESH", name + "x" ) )
1654 aXVal = mgr->doubleValue( "SMESH", name + "x", aXVal );
1656 vtkFloatingPointType aYVal = horiz ? 0.01 : 0.1;
1657 if( mgr->hasValue( "SMESH", name + "y" ) )
1658 aYVal = mgr->doubleValue( "SMESH", name + "y", aYVal );
1659 myScalarBarActor->SetPosition( aXVal, aYVal );
1661 vtkFloatingPointType aWVal = horiz ? 0.60 : 0.10;
1662 if( mgr->hasValue( "SMESH", name + "width" ) )
1663 aWVal = mgr->doubleValue( "SMESH", name + "width", aWVal );
1664 myScalarBarActor->SetWidth( aWVal );
1666 vtkFloatingPointType aHVal = horiz ? 0.12 : 0.80;
1667 if( mgr->hasValue( "SMESH", name + "height" ) )
1668 aHVal = mgr->doubleValue( "SMESH", name + "height", aHVal );
1669 myScalarBarActor->SetHeight( aHVal );
1672 if( mgr->hasValue( "SMESH", "scalar_bar_num_labels" ) )
1673 anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_labels", anIntVal );
1674 myScalarBarActor->SetNumberOfLabels( anIntVal == 0 ? 5: anIntVal );
1677 if( mgr->hasValue( "SMESH", "scalar_bar_num_colors" ) )
1678 anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_colors", anIntVal );
1679 myScalarBarActor->SetMaximumNumberOfColors( anIntVal == 0 ? 64 : anIntVal );