1 // SMESH OBJECT : interactive object for SMESH visualization
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SMESH_Actor.cxx
25 // Author : Nicolas REJNERI
30 #include "SMESH_ActorDef.h"
31 #include "SMESH_ActorUtils.h"
32 #include "SMESH_DeviceActor.h"
33 #include "SMESH_ControlsDef.hxx"
34 #include "VTKViewer_ExtractUnstructuredGrid.h"
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 my3DActor = SMESH_DeviceActor::New();
159 my3DActor->SetUserMatrix(aMatrix);
160 my3DActor->PickableOff();
161 my3DActor->SetProperty(mySurfaceProp);
162 my3DActor->SetBackfaceProperty(myBackSurfaceProp);
163 my3DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
164 aFilter = my3DActor->GetExtractUnstructuredGrid();
165 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
166 aFilter->RegisterCellsWithType(VTK_TETRA);
167 aFilter->RegisterCellsWithType(VTK_VOXEL);
168 aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
169 aFilter->RegisterCellsWithType(VTK_WEDGE);
170 aFilter->RegisterCellsWithType(VTK_PYRAMID);
171 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
172 aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
173 aFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
174 aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
176 //Definition 1D divice of the actor
177 //---------------------------------
178 myEdgeProp = vtkProperty::New();
179 myEdgeProp->SetAmbient(1.0);
180 myEdgeProp->SetDiffuse(0.0);
181 myEdgeProp->SetSpecular(0.0);
182 SMESH::GetColor( "SMESH", "outline_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
183 myEdgeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
184 myEdgeProp->SetLineWidth(aLineWidth);
186 my1DActor = SMESH_DeviceActor::New();
187 my1DActor->SetUserMatrix(aMatrix);
188 my1DActor->PickableOff();
189 my1DActor->SetHighlited(true);
190 my1DActor->SetProperty(myEdgeProp);
191 my1DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
192 aFilter = my1DActor->GetExtractUnstructuredGrid();
193 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
194 aFilter->RegisterCellsWithType(VTK_LINE);
195 aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
197 my1DProp = vtkProperty::New();
198 my1DProp->DeepCopy(myEdgeProp);
199 my1DProp->SetLineWidth(aLineWidth + aLineWidthInc);
200 my1DProp->SetPointSize(aPointSize);
202 my1DExtProp = vtkProperty::New();
203 my1DExtProp->DeepCopy(myEdgeProp);
204 anRGB[0] = 1 - anRGB[0];
205 anRGB[1] = 1 - anRGB[1];
206 anRGB[2] = 1 - anRGB[2];
207 my1DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
208 my1DExtProp->SetLineWidth(aLineWidth + aLineWidthInc);
209 my1DExtProp->SetPointSize(aPointSize + aPointSizeInc);
211 my1DExtActor = SMESH_DeviceActor::New();
212 my1DExtActor->SetUserMatrix(aMatrix);
213 my1DExtActor->PickableOff();
214 my1DExtActor->SetHighlited(true);
215 my1DExtActor->SetVisibility(false);
216 my1DExtActor->SetProperty(my1DExtProp);
217 my1DExtActor->SetRepresentation(SMESH_DeviceActor::eInsideframe);
218 aFilter = my1DExtActor->GetExtractUnstructuredGrid();
219 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
220 aFilter->RegisterCellsWithType(VTK_LINE);
221 aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
224 //Definition 0D divice of the actor
225 //---------------------------------
226 myNodeProp = vtkProperty::New();
227 SMESH::GetColor( "SMESH", "node_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 0, 0 ) );
228 myNodeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
229 myNodeProp->SetPointSize(aPointSize);
231 myNodeActor = SMESH_DeviceActor::New();
232 myNodeActor->SetUserMatrix(aMatrix);
233 myNodeActor->SetStoreClippingMapping(true);
234 myNodeActor->PickableOff();
235 myNodeActor->SetVisibility(false);
236 myNodeActor->SetProperty(myNodeProp);
237 myNodeActor->SetRepresentation(SMESH_DeviceActor::ePoint);
238 aFilter = myNodeActor->GetExtractUnstructuredGrid();
239 aFilter->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
242 //Definition of Pickable and Highlitable engines
243 //----------------------------------------------
245 myBaseActor = SMESH_DeviceActor::New();
246 myBaseActor->SetUserMatrix(aMatrix);
247 myBaseActor->SetStoreGemetryMapping(true);
248 myBaseActor->GetProperty()->SetOpacity(0.0);
250 myPickableActor = myBaseActor;
252 myHighlightProp = vtkProperty::New();
253 myHighlightProp->SetAmbient(1.0);
254 myHighlightProp->SetDiffuse(0.0);
255 myHighlightProp->SetSpecular(0.0);
256 SMESH::GetColor( "SMESH", "selection_object_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
257 myHighlightProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
258 myHighlightProp->SetPointSize(aPointSize);
259 myHighlightProp->SetRepresentation(1);
261 myPreselectProp = vtkProperty::New();
262 myPreselectProp->SetAmbient(1.0);
263 myPreselectProp->SetDiffuse(0.0);
264 myPreselectProp->SetSpecular(0.0);
265 SMESH::GetColor( "SMESH", "highlight_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 255, 255 ) );
266 myPreselectProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
267 myPreselectProp->SetPointSize(aPointSize);
268 myPreselectProp->SetRepresentation(1);
270 myHighlitableActor = SMESH_DeviceActor::New();
271 myHighlitableActor->SetUserMatrix(aMatrix);
272 myHighlitableActor->PickableOff();
273 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
278 myControlMode = eNone;
279 myControlActor = my2DActor;
281 //Definition of myScalarBarActor
282 //------------------------------
283 myLookupTable = vtkLookupTable::New();
284 //Fix for Bug PAL5195 - SMESH764:
285 //Controls - Aspect Ratio: incorrect colors of the best and worst values
286 myLookupTable->SetHueRange(0.667,0.0);
288 myScalarBarActor = vtkScalarBarActor::New();
289 myScalarBarActor->SetVisibility(false);
290 myScalarBarActor->SetLookupTable(myLookupTable);
293 //Incorrect "Min value" in Scalar Bar in Mesh:
294 // myScalarBarActor->SetLabelFormat("%.4g");
295 // changes was commented because of regression bug IPAL 19981
297 mgr = SUIT_Session::session()->resourceMgr();
301 //Definition of points numbering pipeline
302 //---------------------------------------
303 myPointsNumDataSet = vtkUnstructuredGrid::New();
305 myPtsMaskPoints = vtkMaskPoints::New();
306 myPtsMaskPoints->SetInput(myPointsNumDataSet);
307 myPtsMaskPoints->SetOnRatio(1);
309 myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
310 myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
311 myPtsSelectVisiblePoints->SelectInvisibleOff();
312 myPtsSelectVisiblePoints->SetTolerance(0.1);
314 myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
315 myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
316 myPtsLabeledDataMapper->SetLabelFormat("%g");
317 myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
319 vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
320 aPtsTextProp->SetFontFamilyToTimes();
321 static int aPointsFontSize = 10;
322 aPtsTextProp->SetFontSize(aPointsFontSize);
323 aPtsTextProp->SetBold(1);
324 aPtsTextProp->SetItalic(0);
325 aPtsTextProp->SetShadow(0);
326 myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
327 aPtsTextProp->Delete();
329 myEntityMode = eAllEntity;
331 myIsPointsLabeled = false;
333 myPointLabels = vtkActor2D::New();
334 myPointLabels->SetMapper(myPtsLabeledDataMapper);
335 myPointLabels->GetProperty()->SetColor(1,1,1);
336 myPointLabels->SetVisibility(myIsPointsLabeled);
339 //Definition of cells numbering pipeline
340 //---------------------------------------
341 myCellsNumDataSet = vtkUnstructuredGrid::New();
343 myCellCenters = vtkCellCenters::New();
344 myCellCenters->SetInput(myCellsNumDataSet);
346 myClsMaskPoints = vtkMaskPoints::New();
347 myClsMaskPoints->SetInput(myCellCenters->GetOutput());
348 myClsMaskPoints->SetOnRatio(1);
350 myClsSelectVisiblePoints = vtkSelectVisiblePoints::New();
351 myClsSelectVisiblePoints->SetInput(myClsMaskPoints->GetOutput());
352 myClsSelectVisiblePoints->SelectInvisibleOff();
353 myClsSelectVisiblePoints->SetTolerance(0.1);
355 myClsLabeledDataMapper = vtkLabeledDataMapper::New();
356 myClsLabeledDataMapper->SetInput(myClsSelectVisiblePoints->GetOutput());
357 myClsLabeledDataMapper->SetLabelFormat("%g");
358 myClsLabeledDataMapper->SetLabelModeToLabelScalars();
360 vtkTextProperty* aClsTextProp = vtkTextProperty::New();
361 aClsTextProp->SetFontFamilyToTimes();
362 static int aCellsFontSize = 12;
363 aClsTextProp->SetFontSize(aCellsFontSize);
364 aClsTextProp->SetBold(1);
365 aClsTextProp->SetItalic(0);
366 aClsTextProp->SetShadow(0);
367 myClsLabeledDataMapper->SetLabelTextProperty(aClsTextProp);
368 aClsTextProp->Delete();
370 myIsCellsLabeled = false;
372 myCellsLabels = vtkActor2D::New();
373 myCellsLabels->SetMapper(myClsLabeledDataMapper);
374 myCellsLabels->GetProperty()->SetColor(0,1,0);
375 myCellsLabels->SetVisibility(myIsCellsLabeled);
378 myImplicitBoolean = vtkImplicitBoolean::New();
379 myImplicitBoolean->SetOperationTypeToIntersection();
383 SMESH_ActorDef::~SMESH_ActorDef()
385 if(MYDEBUG) MESSAGE("~SMESH_ActorDef - "<<this);
387 myScalarBarActor->Delete();
388 myLookupTable->Delete();
390 mySurfaceProp->Delete();
391 myBackSurfaceProp->Delete();
393 myEdgeProp->Delete();
394 myHighlightProp->Delete();
395 myPreselectProp->Delete();
397 myNodeProp->Delete();
402 my1DExtProp->Delete();
403 my1DExtActor->Delete();
408 myNodeActor->Delete();
409 myBaseActor->Delete();
411 myHighlitableActor->Delete();
413 //Deleting of pints numbering pipeline
414 //---------------------------------------
415 myPointsNumDataSet->Delete();
417 // commented: porting to vtk 5.0
418 // myPtsLabeledDataMapper->RemoveAllInputs();
419 myPtsLabeledDataMapper->Delete();
421 // commented: porting to vtk 5.0
422 // myPtsSelectVisiblePoints->UnRegisterAllOutputs();
423 myPtsSelectVisiblePoints->Delete();
425 // commented: porting to vtk 5.0
426 // myPtsMaskPoints->UnRegisterAllOutputs();
427 myPtsMaskPoints->Delete();
429 myPointLabels->Delete();
432 //Deleting of cells numbering pipeline
433 //---------------------------------------
434 myCellsNumDataSet->Delete();
436 myClsLabeledDataMapper->RemoveAllInputs();
437 myClsLabeledDataMapper->Delete();
439 // commented: porting to vtk 5.0
440 // myClsSelectVisiblePoints->UnRegisterAllOutputs();
441 myClsSelectVisiblePoints->Delete();
443 // commented: porting to vtk 5.0
444 // myClsMaskPoints->UnRegisterAllOutputs();
445 myClsMaskPoints->Delete();
447 // commented: porting to vtk 5.0
448 // myCellCenters->UnRegisterAllOutputs();
449 myCellCenters->Delete();
451 myCellsLabels->Delete();
453 myImplicitBoolean->Delete();
455 myTimeStamp->Delete();
459 void SMESH_ActorDef::SetPointsLabeled( bool theIsPointsLabeled )
461 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
462 myIsPointsLabeled = theIsPointsLabeled && aGrid->GetNumberOfPoints();
464 if ( myIsPointsLabeled )
466 myPointsNumDataSet->ShallowCopy(aGrid);
467 vtkDataSet *aDataSet = myPointsNumDataSet;
469 int aNbElem = aDataSet->GetNumberOfPoints();
471 vtkIntArray *anArray = vtkIntArray::New();
472 anArray->SetNumberOfValues( aNbElem );
474 for ( int anId = 0; anId < aNbElem; anId++ )
476 int aSMDSId = myVisualObj->GetNodeObjId( anId );
477 anArray->SetValue( anId, aSMDSId );
480 aDataSet->GetPointData()->SetScalars( anArray );
482 myPtsMaskPoints->SetInput( aDataSet );
483 myPointLabels->SetVisibility( GetVisibility() );
487 myPointLabels->SetVisibility( false );
489 SetRepresentation(GetRepresentation());
490 myTimeStamp->Modified();
494 void SMESH_ActorDef::SetCellsLabeled(bool theIsCellsLabeled)
496 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
497 myIsCellsLabeled = theIsCellsLabeled && aGrid->GetNumberOfPoints();
498 if(myIsCellsLabeled){
499 myCellsNumDataSet->ShallowCopy(aGrid);
500 vtkDataSet *aDataSet = myCellsNumDataSet;
501 int aNbElem = aDataSet->GetNumberOfCells();
502 vtkIntArray *anArray = vtkIntArray::New();
503 anArray->SetNumberOfValues(aNbElem);
504 for(int anId = 0; anId < aNbElem; anId++){
505 int aSMDSId = myVisualObj->GetElemObjId(anId);
506 anArray->SetValue(anId,aSMDSId);
508 aDataSet->GetCellData()->SetScalars(anArray);
509 myCellCenters->SetInput(aDataSet);
510 myCellsLabels->SetVisibility(GetVisibility());
512 myCellsLabels->SetVisibility(false);
514 myTimeStamp->Modified();
518 void SMESH_ActorDef::SetFacesOriented(bool theIsFacesOriented)
520 myIsFacesOriented = theIsFacesOriented;
522 my2DActor->SetFacesOriented(theIsFacesOriented);
523 my3DActor->SetFacesOriented(theIsFacesOriented);
525 myTimeStamp->Modified();
528 bool SMESH_ActorDef::GetFacesOriented()
530 return myIsFacesOriented;
536 SetControlMode(eControl theMode)
538 SetControlMode(theMode,true);
544 SetControlMode(eControl theMode,
545 bool theCheckEntityMode)
547 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
551 myControlMode = eNone;
552 theCheckEntityMode &= mgr->booleanValue( "SMESH", "display_entity", false );
554 my1DActor->GetMapper()->SetScalarVisibility(false);
555 my2DActor->GetMapper()->SetScalarVisibility(false);
556 my3DActor->GetMapper()->SetScalarVisibility(false);
557 myScalarBarActor->SetVisibility(false);
559 bool anIsScalarVisible = theMode > eNone;
561 if(anIsScalarVisible){
562 SMESH::Controls::FunctorPtr aFunctor;
566 SMESH::Controls::Length* aControl = new SMESH::Controls::Length();
567 aControl->SetPrecision( myControlsPrecision );
568 aFunctor.reset( aControl );
569 myControlActor = my1DActor;
574 aFunctor.reset(new SMESH::Controls::Length2D());
575 myControlActor = my2DActor;
579 aFunctor.reset(new SMESH::Controls::FreeBorders());
580 myControlActor = my1DActor;
583 aFunctor.reset(new SMESH::Controls::FreeEdges());
584 myControlActor = my2DActor;
586 case eMultiConnection:
587 aFunctor.reset(new SMESH::Controls::MultiConnection());
588 myControlActor = my1DActor;
590 case eMultiConnection2D:
591 aFunctor.reset(new SMESH::Controls::MultiConnection2D());
592 myControlActor = my2DActor;
596 SMESH::Controls::Area* aControl = new SMESH::Controls::Area();
597 aControl->SetPrecision( myControlsPrecision );
598 aFunctor.reset( aControl );
599 myControlActor = my2DActor;
604 SMESH::Controls::Taper* aControl = new SMESH::Controls::Taper();
605 aControl->SetPrecision( myControlsPrecision );
606 aFunctor.reset( aControl );
607 myControlActor = my2DActor;
612 SMESH::Controls::AspectRatio* aControl = new SMESH::Controls::AspectRatio();
613 aControl->SetPrecision( myControlsPrecision );
614 aFunctor.reset( aControl );
615 myControlActor = my2DActor;
620 SMESH::Controls::AspectRatio3D* aControl = new SMESH::Controls::AspectRatio3D();
621 aControl->SetPrecision( myControlsPrecision );
622 aFunctor.reset( aControl );
623 myControlActor = my3DActor;
628 SMESH::Controls::Volume* aControl = new SMESH::Controls::Volume();
629 aControl->SetPrecision( myControlsPrecision );
630 aFunctor.reset( aControl );
631 myControlActor = my3DActor;
636 SMESH::Controls::MinimumAngle* aControl = new SMESH::Controls::MinimumAngle();
637 aControl->SetPrecision( myControlsPrecision );
638 aFunctor.reset( aControl );
639 myControlActor = my2DActor;
644 SMESH::Controls::Warping* aControl = new SMESH::Controls::Warping();
645 aControl->SetPrecision( myControlsPrecision );
646 aFunctor.reset( aControl );
647 myControlActor = my2DActor;
652 SMESH::Controls::Skew* aControl = new SMESH::Controls::Skew();
653 aControl->SetPrecision( myControlsPrecision );
654 aFunctor.reset( aControl );
655 myControlActor = my2DActor;
662 vtkUnstructuredGrid* aGrid = myControlActor->GetUnstructuredGrid();
663 vtkIdType aNbCells = aGrid->GetNumberOfCells();
665 myControlMode = theMode;
666 switch(myControlMode){
669 my1DExtActor->SetExtControlMode(aFunctor);
672 case eMultiConnection2D:
673 my1DExtActor->SetExtControlMode(aFunctor,myScalarBarActor,myLookupTable);
676 myControlActor->SetControlMode(aFunctor,myScalarBarActor,myLookupTable);
680 if(theCheckEntityMode){
681 if(myControlActor == my1DActor)
682 SetEntityMode(eEdges);
683 else if(myControlActor == my2DActor){
684 switch(myControlMode){
687 case eMultiConnection2D:
688 //SetEntityMode(eEdges);
689 SetEntityMode(eFaces);
692 SetEntityMode(eFaces);
694 }else if(myControlActor == my3DActor)
695 SetEntityMode(eVolumes);
698 }else if(theCheckEntityMode){
699 myEntityMode = eAllEntity;
702 SetRepresentation(GetRepresentation());
704 myTimeStamp->Modified();
709 void SMESH_ActorDef::AddToRender(vtkRenderer* theRenderer){
710 SALOME_Actor::AddToRender(theRenderer);
712 theRenderer->AddActor(myNodeActor);
713 theRenderer->AddActor(myBaseActor);
715 my3DActor->AddToRender(theRenderer);
716 my2DActor->AddToRender(theRenderer);
718 theRenderer->AddActor(my1DActor);
719 theRenderer->AddActor(my1DExtActor);
721 theRenderer->AddActor(myHighlitableActor);
723 theRenderer->AddActor2D(myScalarBarActor);
725 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
726 myClsSelectVisiblePoints->SetRenderer(theRenderer);
728 theRenderer->AddActor2D(myPointLabels);
729 theRenderer->AddActor2D(myCellsLabels);
732 void SMESH_ActorDef::RemoveFromRender(vtkRenderer* theRenderer){
733 SALOME_Actor::RemoveFromRender(theRenderer);
735 theRenderer->RemoveActor(myNodeActor);
736 theRenderer->RemoveActor(myBaseActor);
738 theRenderer->RemoveActor(myHighlitableActor);
740 theRenderer->RemoveActor(my1DActor);
741 theRenderer->RemoveActor(my1DExtActor);
743 my2DActor->RemoveFromRender(theRenderer);
744 my3DActor->RemoveFromRender(theRenderer);
746 theRenderer->RemoveActor(myScalarBarActor);
747 theRenderer->RemoveActor(myPointLabels);
748 theRenderer->RemoveActor(myCellsLabels);
752 bool SMESH_ActorDef::Init(TVisualObjPtr theVisualObj,
753 const char* theEntry,
757 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry,"SMESH",theName);
761 myVisualObj = theVisualObj;
762 myVisualObj->Update(theIsClear);
764 myNodeActor->Init(myVisualObj,myImplicitBoolean);
765 myBaseActor->Init(myVisualObj,myImplicitBoolean);
767 myHighlitableActor->Init(myVisualObj,myImplicitBoolean);
769 my1DActor->Init(myVisualObj,myImplicitBoolean);
770 my1DExtActor->Init(myVisualObj,myImplicitBoolean);
772 my2DActor->Init(myVisualObj,myImplicitBoolean);
773 my3DActor->Init(myVisualObj,myImplicitBoolean);
775 my1DActor->GetMapper()->SetLookupTable(myLookupTable);
776 my1DExtActor->GetMapper()->SetLookupTable(myLookupTable);
778 my2DActor->GetMapper()->SetLookupTable(myLookupTable);
779 my3DActor->GetMapper()->SetLookupTable(myLookupTable);
781 vtkFloatingPointType aFactor, aUnits;
782 my2DActor->GetPolygonOffsetParameters(aFactor,aUnits);
783 my2DActor->SetPolygonOffsetParameters(aFactor,aUnits*0.75);
785 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
789 //SetIsShrunkable(theGrid->GetNumberOfCells() > 10);
790 SetIsShrunkable(true);
792 SetShrinkFactor( SMESH::GetFloat( "SMESH:shrink_coeff", 75 ) / 100. );
794 int aMode = mgr->integerValue( "SMESH", "display_mode" );
795 SetRepresentation(-1);
798 SetRepresentation(eEdge);
799 }else if(aMode == 1){
800 SetRepresentation(eSurface);
801 }else if(aMode == 2){
802 SetRepresentation(ePoint);
809 myTimeStamp->Modified();
815 vtkFloatingPointType* SMESH_ActorDef::GetBounds(){
816 return myNodeActor->GetBounds();
820 vtkDataSet* SMESH_ActorDef::GetInput(){
821 return GetUnstructuredGrid();
825 void SMESH_ActorDef::SetTransform(VTKViewer_Transform* theTransform){
826 Superclass::SetTransform(theTransform);
828 myNodeActor->SetTransform(theTransform);
829 myBaseActor->SetTransform(theTransform);
831 myHighlitableActor->SetTransform(theTransform);
833 my1DActor->SetTransform(theTransform);
834 my1DExtActor->SetTransform(theTransform);
836 my2DActor->SetTransform(theTransform);
837 my3DActor->SetTransform(theTransform);
843 void SMESH_ActorDef::SetMapper(vtkMapper* theMapper){
844 vtkLODActor::SetMapper(theMapper);
848 void SMESH_ActorDef::ShallowCopy(vtkProp *prop){
849 SALOME_Actor::ShallowCopy(prop);
853 vtkMapper* SMESH_ActorDef::GetMapper(){
854 return myPickableActor->GetMapper();
858 vtkUnstructuredGrid* SMESH_ActorDef::GetUnstructuredGrid(){
859 return myVisualObj->GetUnstructuredGrid();
863 bool SMESH_ActorDef::IsInfinitive(){
864 vtkDataSet *aDataSet = myPickableActor->GetUnstructuredGrid();
866 myIsInfinite = aDataSet->GetNumberOfCells() == 0 ||
867 aDataSet->GetNumberOfCells() == 1 &&
868 aDataSet->GetCell(0)->GetCellType() == VTK_VERTEX;
869 return SALOME_Actor::IsInfinitive();
873 void SMESH_ActorDef::SetIsShrunkable(bool theShrunkable){
874 if ( myIsShrinkable == theShrunkable )
876 myIsShrinkable = theShrunkable;
880 vtkFloatingPointType SMESH_ActorDef::GetShrinkFactor(){
881 return myBaseActor->GetShrinkFactor();
884 void SMESH_ActorDef::SetShrinkFactor(vtkFloatingPointType theValue){
885 myBaseActor->SetShrinkFactor(theValue);
887 my1DActor->SetShrinkFactor(theValue);
888 my1DExtActor->SetShrinkFactor(theValue);
890 my2DActor->SetShrinkFactor(theValue);
891 my3DActor->SetShrinkFactor(theValue);
896 void SMESH_ActorDef::SetShrink(){
897 if(!myIsShrinkable) return;
899 myBaseActor->SetShrink();
901 my1DActor->SetShrink();
902 my1DExtActor->SetShrink();
904 my2DActor->SetShrink();
905 my3DActor->SetShrink();
911 void SMESH_ActorDef::UnShrink(){
912 if(!myIsShrunk) return;
914 myBaseActor->UnShrink();
916 my1DActor->UnShrink();
917 my1DExtActor->UnShrink();
919 my2DActor->UnShrink();
920 my3DActor->UnShrink();
927 int SMESH_ActorDef::GetNodeObjId(int theVtkID){
928 return myPickableActor->GetNodeObjId(theVtkID);
931 vtkFloatingPointType* SMESH_ActorDef::GetNodeCoord(int theObjID){
932 return myPickableActor->GetNodeCoord(theObjID);
936 int SMESH_ActorDef::GetElemObjId(int theVtkID){
937 return myPickableActor->GetElemObjId(theVtkID);
940 vtkCell* SMESH_ActorDef::GetElemCell(int theObjID){
941 return myPickableActor->GetElemCell(theObjID);
945 void SMESH_ActorDef::SetVisibility(int theMode){
946 SetVisibility(theMode,true);
950 void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation){
951 SALOME_Actor::SetVisibility(theMode);
953 myNodeActor->VisibilityOff();
954 myBaseActor->VisibilityOff();
956 my1DActor->VisibilityOff();
957 my1DExtActor->VisibilityOff();
959 my2DActor->VisibilityOff();
960 my3DActor->VisibilityOff();
962 myScalarBarActor->VisibilityOff();
963 myPointLabels->VisibilityOff();
964 myCellsLabels->VisibilityOff();
967 if(theIsUpdateRepersentation)
968 SetRepresentation(GetRepresentation());
970 if(myControlMode != eNone){
971 switch(myControlMode){
974 my1DExtActor->VisibilityOn();
977 case eMultiConnection2D:
978 my1DExtActor->VisibilityOn();
980 if(myControlActor->GetUnstructuredGrid()->GetNumberOfCells())
981 myScalarBarActor->VisibilityOn();
985 if(myRepresentation != ePoint)
986 myPickableActor->VisibilityOn();
988 myNodeActor->VisibilityOn();
991 if(myEntityMode & eEdges){
992 my1DActor->VisibilityOn();
995 if(myEntityMode & eFaces){
996 my2DActor->VisibilityOn();
999 if(myEntityMode & eVolumes){
1000 my3DActor->VisibilityOn();
1003 if(myIsPointsLabeled){
1004 myPointLabels->VisibilityOn();
1005 myNodeActor->VisibilityOn();
1008 if(myIsCellsLabeled)
1009 myCellsLabels->VisibilityOn();
1016 void SMESH_ActorDef::SetEntityMode(unsigned int theMode){
1017 myEntityState = eAllEntity;
1019 if(!myVisualObj->GetNbEntities(SMDSAbs_Edge)){
1020 myEntityState &= ~eEdges;
1024 if(!myVisualObj->GetNbEntities(SMDSAbs_Face)){
1025 myEntityState &= ~eFaces;
1029 if(!myVisualObj->GetNbEntities(SMDSAbs_Volume)){
1030 myEntityState &= ~eVolumes;
1031 theMode &= ~eVolumes;
1035 if(myVisualObj->GetNbEntities(SMDSAbs_Edge))
1038 if(myVisualObj->GetNbEntities(SMDSAbs_Face))
1041 if(myVisualObj->GetNbEntities(SMDSAbs_Volume))
1042 theMode |= eVolumes;
1045 myBaseActor->myGeomFilter->SetInside(myEntityMode != myEntityState);
1047 myEntityMode = theMode;
1048 VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
1049 aFilter = myBaseActor->GetExtractUnstructuredGrid();
1050 aFilter->ClearRegisteredCellsWithType();
1051 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
1053 if(myEntityMode & eEdges){
1054 if (MYDEBUG) MESSAGE("EDGES");
1055 aFilter->RegisterCellsWithType(VTK_LINE);
1056 aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
1059 if(myEntityMode & eFaces){
1060 if (MYDEBUG) MESSAGE("FACES");
1061 aFilter->RegisterCellsWithType(VTK_TRIANGLE);
1062 aFilter->RegisterCellsWithType(VTK_POLYGON);
1063 aFilter->RegisterCellsWithType(VTK_QUAD);
1064 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
1065 aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
1068 if(myEntityMode & eVolumes){
1069 if (MYDEBUG) MESSAGE("VOLUMES");
1070 aFilter->RegisterCellsWithType(VTK_TETRA);
1071 aFilter->RegisterCellsWithType(VTK_VOXEL);
1072 aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1073 aFilter->RegisterCellsWithType(VTK_WEDGE);
1074 aFilter->RegisterCellsWithType(VTK_PYRAMID);
1075 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
1076 aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
1077 aFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
1078 aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1081 if (MYDEBUG) MESSAGE(aFilter->GetOutput()->GetNumberOfCells());
1082 SetVisibility(GetVisibility(),false);
1085 void SMESH_ActorDef::SetRepresentation(int theMode){
1086 int aNbEdges = myVisualObj->GetNbEntities(SMDSAbs_Edge);
1087 int aNbFaces = myVisualObj->GetNbEntities(SMDSAbs_Face);
1088 int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume);
1090 myRepresentation = eSurface;
1091 if(!aNbFaces && !aNbVolumes && aNbEdges){
1092 myRepresentation = eEdge;
1093 }else if(!aNbFaces && !aNbVolumes && !aNbEdges){
1094 myRepresentation = ePoint;
1099 if(!aNbFaces && !aNbVolumes && !aNbEdges) return;
1102 if(!aNbFaces && !aNbVolumes) return;
1105 myRepresentation = theMode;
1108 if(!GetUnstructuredGrid()->GetNumberOfCells())
1109 myRepresentation = ePoint;
1112 if(myRepresentation == ePoint){
1120 myPickableActor = myBaseActor;
1121 myNodeActor->SetVisibility(false);
1122 vtkProperty *aProp = NULL, *aBackProp = NULL;
1123 SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1);
1124 switch(myRepresentation){
1126 myPickableActor = myNodeActor;
1127 myNodeActor->SetVisibility(true);
1129 aProp = aBackProp = myNodeProp;
1130 aReperesent = SMESH_DeviceActor::ePoint;
1133 aProp = aBackProp = myEdgeProp;
1134 aReperesent = SMESH_DeviceActor::eInsideframe;
1137 aProp = mySurfaceProp;
1138 aBackProp = myBackSurfaceProp;
1139 aReperesent = SMESH_DeviceActor::eSurface;
1143 my2DActor->SetProperty(aProp);
1144 my2DActor->SetBackfaceProperty(aBackProp);
1145 my2DActor->SetRepresentation(aReperesent);
1147 my3DActor->SetProperty(aProp);
1148 my3DActor->SetBackfaceProperty(aBackProp);
1149 my3DActor->SetRepresentation(aReperesent);
1151 my1DExtActor->SetVisibility(false);
1153 switch(myControlMode){
1155 case eMultiConnection:
1156 aProp = aBackProp = my1DProp;
1157 if(myRepresentation != ePoint)
1158 aReperesent = SMESH_DeviceActor::eInsideframe;
1162 my1DActor->SetProperty(aProp);
1163 my1DActor->SetBackfaceProperty(aBackProp);
1164 my1DActor->SetRepresentation(aReperesent);
1166 my1DExtActor->SetRepresentation(aReperesent);
1168 if(myIsPointsVisible)
1169 myPickableActor = myNodeActor;
1170 if(GetPointRepresentation())
1171 myNodeActor->SetVisibility(true);
1173 SetMapper(myPickableActor->GetMapper());
1175 SetVisibility(GetVisibility(),false);
1181 void SMESH_ActorDef::SetPointRepresentation(bool theIsPointsVisible){
1182 if ( myIsPointsVisible == theIsPointsVisible )
1184 myIsPointsVisible = theIsPointsVisible;
1185 SetRepresentation(GetRepresentation());
1188 bool SMESH_ActorDef::GetPointRepresentation(){
1189 return myIsPointsVisible || myIsPointsLabeled;
1193 void SMESH_ActorDef::UpdateHighlight(){
1194 myHighlitableActor->SetVisibility(false);
1195 myHighlitableActor->SetHighlited(false);
1197 if(myIsHighlighted){
1198 myHighlitableActor->SetProperty(myHighlightProp);
1199 }else if(myIsPreselected){
1200 myHighlitableActor->SetProperty(myPreselectProp);
1203 bool anIsVisible = GetVisibility();
1205 if(myIsHighlighted || myIsPreselected){
1206 if(GetUnstructuredGrid()->GetNumberOfCells()){
1207 myHighlitableActor->SetHighlited(anIsVisible);
1208 myHighlitableActor->SetVisibility(anIsVisible);
1209 myHighlitableActor->GetExtractUnstructuredGrid()->
1210 SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::eCells);
1211 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
1212 }else if(myRepresentation == ePoint || GetPointRepresentation()){
1213 myHighlitableActor->SetHighlited(anIsVisible);
1214 myHighlitableActor->GetExtractUnstructuredGrid()->
1215 SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
1216 myHighlitableActor->SetVisibility(anIsVisible);
1217 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::ePoint);
1223 void SMESH_ActorDef::highlight(bool theHighlight){
1224 if ( myIsHighlighted == theHighlight )
1226 myIsHighlighted = theHighlight;
1231 void SMESH_ActorDef::SetPreSelected(bool thePreselect){
1232 if ( myIsPreselected == thePreselect )
1234 myIsPreselected = thePreselect;
1240 int SMESH_ActorDef::RenderOpaqueGeometry(vtkViewport *vp)
1242 if (myPickableActor->GetIsOpaque())
1244 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1252 int SMESH_ActorDef::RenderTranslucentGeometry(vtkViewport *vp)
1254 if (!myPickableActor->GetIsOpaque())
1256 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1264 void SMESH_ActorDef::Render(vtkRenderer *ren){
1265 unsigned long aTime = myTimeStamp->GetMTime();
1266 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1267 unsigned long aClippingTime = myImplicitBoolean->GetMTime();
1268 if(anObjTime > aTime || aClippingTime > aTime)
1273 void SMESH_ActorDef::Update(){
1274 if(MYDEBUG) MESSAGE("SMESH_ActorDef::Update");
1276 if(GetControlMode() != eNone) {
1277 unsigned long aTime = myTimeStamp->GetMTime();
1278 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1279 if (anObjTime > aTime)
1280 SetControlMode(GetControlMode(),false);
1282 if(myIsPointsLabeled){
1283 SetPointsLabeled(myIsPointsLabeled);
1285 if(myIsCellsLabeled){
1286 SetCellsLabeled(myIsCellsLabeled);
1288 if(myIsFacesOriented){
1289 SetFacesOriented(myIsFacesOriented);
1291 SetEntityMode(GetEntityMode());
1292 SetVisibility(GetVisibility());
1294 myTimeStamp->Modified();
1299 void SMESH_ActorDef::ReleaseGraphicsResources(vtkWindow *renWin){
1300 SALOME_Actor::ReleaseGraphicsResources(renWin);
1302 myPickableActor->ReleaseGraphicsResources(renWin);
1306 static void GetColor(vtkProperty *theProperty, vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1307 vtkFloatingPointType* aColor = theProperty->GetColor();
1314 void SMESH_ActorDef::SetOpacity(vtkFloatingPointType theValue){
1315 mySurfaceProp->SetOpacity(theValue);
1316 myBackSurfaceProp->SetOpacity(theValue);
1317 myEdgeProp->SetOpacity(theValue);
1318 myNodeProp->SetOpacity(theValue);
1320 my1DProp->SetOpacity(theValue);
1324 vtkFloatingPointType SMESH_ActorDef::GetOpacity(){
1325 return mySurfaceProp->GetOpacity();
1329 void SMESH_ActorDef::SetSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1330 mySurfaceProp->SetColor(r,g,b);
1334 void SMESH_ActorDef::GetSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1335 ::GetColor(mySurfaceProp,r,g,b);
1338 void SMESH_ActorDef::SetBackSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1339 myBackSurfaceProp->SetColor(r,g,b);
1343 void SMESH_ActorDef::GetBackSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1344 ::GetColor(myBackSurfaceProp,r,g,b);
1347 void SMESH_ActorDef::SetEdgeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1348 myEdgeProp->SetColor(r,g,b);
1349 my1DProp->SetColor(r,g,b);
1350 my1DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1354 void SMESH_ActorDef::GetEdgeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1355 ::GetColor(myEdgeProp,r,g,b);
1358 void SMESH_ActorDef::SetNodeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1359 myNodeProp->SetColor(r,g,b);
1363 void SMESH_ActorDef::GetNodeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1364 ::GetColor(myNodeProp,r,g,b);
1367 void SMESH_ActorDef::SetHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1368 myHighlightProp->SetColor(r,g,b);
1372 void SMESH_ActorDef::GetHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1373 ::GetColor(myHighlightProp,r,g,b);
1376 void SMESH_ActorDef::SetPreHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1377 myPreselectProp->SetColor(r,g,b);
1381 void SMESH_ActorDef::GetPreHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1382 ::GetColor(myPreselectProp,r,g,b);
1386 vtkFloatingPointType SMESH_ActorDef::GetLineWidth(){
1387 return myEdgeProp->GetLineWidth();
1391 void SMESH_ActorDef::SetLineWidth(vtkFloatingPointType theVal){
1392 myEdgeProp->SetLineWidth(theVal);
1394 my1DProp->SetLineWidth(theVal + aLineWidthInc);
1395 my1DExtProp->SetLineWidth(theVal + aLineWidthInc);
1401 void SMESH_ActorDef::SetNodeSize(vtkFloatingPointType theVal){
1402 myNodeProp->SetPointSize(theVal);
1403 myHighlightProp->SetPointSize(theVal);
1404 myPreselectProp->SetPointSize(theVal);
1406 my1DProp->SetPointSize(theVal + aPointSizeInc);
1407 my1DExtProp->SetPointSize(theVal + aPointSizeInc);
1412 vtkFloatingPointType SMESH_ActorDef::GetNodeSize(){
1413 return myNodeProp->GetPointSize();
1416 int SMESH_ActorDef::GetObjDimension( const int theObjId )
1418 return myVisualObj->GetElemDimension( theObjId );
1423 IsImplicitFunctionUsed() const
1425 return myBaseActor->IsImplicitFunctionUsed();
1430 SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
1432 myNodeActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1433 myBaseActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1435 myHighlitableActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1437 my1DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1438 my1DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1440 my2DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1441 my3DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1446 AddClippingPlane(vtkPlane* thePlane)
1449 myImplicitBoolean->GetFunction()->AddItem(thePlane);
1450 myCippingPlaneCont.push_back(thePlane);
1451 if(!IsImplicitFunctionUsed())
1452 SetImplicitFunctionUsed(true);
1454 return myCippingPlaneCont.size();
1459 RemoveAllClippingPlanes()
1461 myImplicitBoolean->GetFunction()->RemoveAllItems();
1462 myImplicitBoolean->GetFunction()->Modified(); // VTK bug
1463 myCippingPlaneCont.clear();
1464 SetImplicitFunctionUsed(false);
1469 GetNumberOfClippingPlanes()
1471 return myCippingPlaneCont.size();
1476 GetClippingPlane(vtkIdType theID)
1478 if(theID >= myCippingPlaneCont.size())
1480 return myCippingPlaneCont[theID].Get();
1484 static void ComputeBoundsParam(vtkDataSet* theDataSet,
1485 vtkFloatingPointType theDirection[3], vtkFloatingPointType theMinPnt[3],
1486 vtkFloatingPointType& theMaxBoundPrj, vtkFloatingPointType& theMinBoundPrj)
1488 vtkFloatingPointType aBounds[6];
1489 theDataSet->GetBounds(aBounds);
1491 //Enlarge bounds in order to avoid conflicts of precision
1492 for(int i = 0; i < 6; i += 2){
1493 static double EPS = 1.0E-3;
1494 vtkFloatingPointType aDelta = (aBounds[i+1] - aBounds[i])*EPS;
1495 aBounds[i] -= aDelta;
1496 aBounds[i+1] += aDelta;
1499 vtkFloatingPointType aBoundPoints[8][3] = { {aBounds[0],aBounds[2],aBounds[4]},
1500 {aBounds[1],aBounds[2],aBounds[4]},
1501 {aBounds[0],aBounds[3],aBounds[4]},
1502 {aBounds[1],aBounds[3],aBounds[4]},
1503 {aBounds[0],aBounds[2],aBounds[5]},
1504 {aBounds[1],aBounds[2],aBounds[5]},
1505 {aBounds[0],aBounds[3],aBounds[5]},
1506 {aBounds[1],aBounds[3],aBounds[5]}};
1508 int aMaxId = 0, aMinId = aMaxId;
1509 theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
1510 theMinBoundPrj = theMaxBoundPrj;
1511 for(int i = 1; i < 8; i++){
1512 vtkFloatingPointType aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
1513 if(theMaxBoundPrj < aTmp){
1514 theMaxBoundPrj = aTmp;
1517 if(theMinBoundPrj > aTmp){
1518 theMinBoundPrj = aTmp;
1522 vtkFloatingPointType *aMinPnt = aBoundPoints[aMaxId];
1523 theMinPnt[0] = aMinPnt[0];
1524 theMinPnt[1] = aMinPnt[1];
1525 theMinPnt[2] = aMinPnt[2];
1529 static void DistanceToPosition(vtkDataSet* theDataSet,
1530 vtkFloatingPointType theDirection[3], vtkFloatingPointType theDist, vtkFloatingPointType thePos[3])
1532 vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1533 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1534 vtkFloatingPointType aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
1535 thePos[0] = aMinPnt[0]-theDirection[0]*aLength;
1536 thePos[1] = aMinPnt[1]-theDirection[1]*aLength;
1537 thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
1541 static void PositionToDistance(vtkDataSet* theDataSet,
1542 vtkFloatingPointType theDirection[3], vtkFloatingPointType thePos[3], vtkFloatingPointType& theDist)
1544 vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1545 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1546 vtkFloatingPointType aPrj = vtkMath::Dot(theDirection,thePos);
1547 theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
1551 void SMESH_ActorDef::SetPlaneParam(vtkFloatingPointType theDir[3], vtkFloatingPointType theDist, vtkPlane* thePlane)
1553 thePlane->SetNormal(theDir);
1554 vtkFloatingPointType anOrigin[3];
1555 ::DistanceToPosition(GetUnstructuredGrid(),theDir,theDist,anOrigin);
1556 thePlane->SetOrigin(anOrigin);
1560 void SMESH_ActorDef::GetPlaneParam(vtkFloatingPointType theDir[3], vtkFloatingPointType& theDist, vtkPlane* thePlane)
1562 thePlane->GetNormal(theDir);
1564 vtkFloatingPointType anOrigin[3];
1565 thePlane->GetOrigin(anOrigin);
1566 ::PositionToDistance(GetUnstructuredGrid(),theDir,anOrigin,theDist);
1569 void SMESH_ActorDef::UpdateScalarBar()
1571 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
1575 vtkTextProperty* aScalarBarTitleProp = vtkTextProperty::New();
1577 QColor aTColor = mgr->colorValue( "SMESH", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
1578 aScalarBarTitleProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1580 aScalarBarTitleProp->SetFontFamilyToArial();
1582 if ( mgr->hasValue( "SMESH", "scalar_bar_title_font" ) )
1584 QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
1585 if ( f.family() == "Arial" )
1586 aScalarBarTitleProp->SetFontFamilyToArial();
1587 else if ( f.family() == "Courier" )
1588 aScalarBarTitleProp->SetFontFamilyToCourier();
1589 else if ( f.family() == "Times" )
1590 aScalarBarTitleProp->SetFontFamilyToTimes();
1593 aScalarBarTitleProp->BoldOn();
1595 aScalarBarTitleProp->BoldOff();
1598 aScalarBarTitleProp->ItalicOn();
1600 aScalarBarTitleProp->ItalicOff();
1602 if ( f.underline() )
1603 aScalarBarTitleProp->ShadowOn();
1605 aScalarBarTitleProp->ShadowOff();
1608 myScalarBarActor->SetTitleTextProperty( aScalarBarTitleProp );
1609 aScalarBarTitleProp->Delete();
1611 vtkTextProperty* aScalarBarLabelProp = vtkTextProperty::New();
1613 aTColor = mgr->colorValue( "SMESH", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
1614 aScalarBarLabelProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1616 aScalarBarLabelProp->SetFontFamilyToArial();
1617 if( mgr->hasValue( "SMESH", "scalar_bar_label_font" ) )
1619 QFont f = mgr->fontValue( "SMESH", "scalar_bar_label_font" );
1620 if( f.family() == "Arial" )
1621 aScalarBarLabelProp->SetFontFamilyToArial();
1622 else if( f.family() == "Courier" )
1623 aScalarBarLabelProp->SetFontFamilyToCourier();
1624 else if( f.family() == "Times" )
1625 aScalarBarLabelProp->SetFontFamilyToTimes();
1628 aScalarBarLabelProp->BoldOn();
1630 aScalarBarLabelProp->BoldOff();
1633 aScalarBarLabelProp->ItalicOn();
1635 aScalarBarLabelProp->ItalicOff();
1638 aScalarBarLabelProp->ShadowOn();
1640 aScalarBarLabelProp->ShadowOff();
1643 myScalarBarActor->SetLabelTextProperty( aScalarBarLabelProp );
1644 aScalarBarLabelProp->Delete();
1646 bool horiz = ( mgr->integerValue( "SMESH", "scalar_bar_orientation" ) == 1 );
1647 QString name = QString( "scalar_bar_%1_" ).arg( horiz ? "horizontal" : "vertical" );
1649 myScalarBarActor->SetOrientationToHorizontal();
1651 myScalarBarActor->SetOrientationToVertical();
1654 vtkFloatingPointType aXVal = horiz ? 0.20 : 0.01;
1655 if( mgr->hasValue( "SMESH", name + "x" ) )
1656 aXVal = mgr->doubleValue( "SMESH", name + "x", aXVal );
1658 vtkFloatingPointType aYVal = horiz ? 0.01 : 0.1;
1659 if( mgr->hasValue( "SMESH", name + "y" ) )
1660 aYVal = mgr->doubleValue( "SMESH", name + "y", aYVal );
1661 myScalarBarActor->SetPosition( aXVal, aYVal );
1663 vtkFloatingPointType aWVal = horiz ? 0.60 : 0.10;
1664 if( mgr->hasValue( "SMESH", name + "width" ) )
1665 aWVal = mgr->doubleValue( "SMESH", name + "width", aWVal );
1666 myScalarBarActor->SetWidth( aWVal );
1668 vtkFloatingPointType aHVal = horiz ? 0.12 : 0.80;
1669 if( mgr->hasValue( "SMESH", name + "height" ) )
1670 aHVal = mgr->doubleValue( "SMESH", name + "height", aHVal );
1671 myScalarBarActor->SetHeight( aHVal );
1674 if( mgr->hasValue( "SMESH", "scalar_bar_num_labels" ) )
1675 anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_labels", anIntVal );
1676 myScalarBarActor->SetNumberOfLabels( anIntVal == 0 ? 5: anIntVal );
1679 if( mgr->hasValue( "SMESH", "scalar_bar_num_colors" ) )
1680 anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_colors", anIntVal );
1681 myScalarBarActor->SetMaximumNumberOfColors( anIntVal == 0 ? 64 : anIntVal );