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 myControlsPrecision = -1;
120 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
121 if ( mgr && mgr->booleanValue( "SMESH", "use_precision", false ) )
122 myControlsPrecision = (long)SMESH::GetFloat( "SMESH", "controls_precision", -1 );
124 vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
125 vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
127 vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
128 VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
130 //Definition 2D and 3D divices of the actor
131 //-----------------------------------------
132 vtkFloatingPointType anRGB[3] = {1,1,1};
133 mySurfaceProp = vtkProperty::New();
134 SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
135 mySurfaceProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
137 myBackSurfaceProp = vtkProperty::New();
138 SMESH::GetColor( "SMESH", "backface_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 0, 255 ) );
139 myBackSurfaceProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
141 my2DActor = SMESH_DeviceActor::New();
142 my2DActor->SetUserMatrix(aMatrix);
143 my2DActor->PickableOff();
144 my2DActor->SetProperty(mySurfaceProp);
145 my2DActor->SetBackfaceProperty(myBackSurfaceProp);
146 my2DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
147 aFilter = my2DActor->GetExtractUnstructuredGrid();
148 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
149 aFilter->RegisterCellsWithType(VTK_TRIANGLE);
150 aFilter->RegisterCellsWithType(VTK_POLYGON);
151 aFilter->RegisterCellsWithType(VTK_QUAD);
152 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
153 aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
155 my3DActor = SMESH_DeviceActor::New();
156 my3DActor->SetUserMatrix(aMatrix);
157 my3DActor->PickableOff();
158 my3DActor->SetProperty(mySurfaceProp);
159 my3DActor->SetBackfaceProperty(myBackSurfaceProp);
160 my3DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
161 aFilter = my3DActor->GetExtractUnstructuredGrid();
162 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
163 aFilter->RegisterCellsWithType(VTK_TETRA);
164 aFilter->RegisterCellsWithType(VTK_VOXEL);
165 aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
166 aFilter->RegisterCellsWithType(VTK_WEDGE);
167 aFilter->RegisterCellsWithType(VTK_PYRAMID);
168 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
169 aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
170 aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
172 //Definition 1D divice of the actor
173 //---------------------------------
174 myEdgeProp = vtkProperty::New();
175 myEdgeProp->SetAmbient(1.0);
176 myEdgeProp->SetDiffuse(0.0);
177 myEdgeProp->SetSpecular(0.0);
178 SMESH::GetColor( "SMESH", "outline_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
179 myEdgeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
180 myEdgeProp->SetLineWidth(aLineWidth);
182 my1DActor = SMESH_DeviceActor::New();
183 my1DActor->SetUserMatrix(aMatrix);
184 my1DActor->PickableOff();
185 my1DActor->SetHighlited(true);
186 my1DActor->SetProperty(myEdgeProp);
187 my1DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
188 aFilter = my1DActor->GetExtractUnstructuredGrid();
189 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
190 aFilter->RegisterCellsWithType(VTK_LINE);
191 aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
193 my1DProp = vtkProperty::New();
194 my1DProp->DeepCopy(myEdgeProp);
195 my1DProp->SetLineWidth(aLineWidth + aLineWidthInc);
196 my1DProp->SetPointSize(aPointSize);
198 my1DExtProp = vtkProperty::New();
199 my1DExtProp->DeepCopy(myEdgeProp);
200 anRGB[0] = 1 - anRGB[0];
201 anRGB[1] = 1 - anRGB[1];
202 anRGB[2] = 1 - anRGB[2];
203 my1DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
204 my1DExtProp->SetLineWidth(aLineWidth + aLineWidthInc);
205 my1DExtProp->SetPointSize(aPointSize + aPointSizeInc);
207 my1DExtActor = SMESH_DeviceActor::New();
208 my1DExtActor->SetUserMatrix(aMatrix);
209 my1DExtActor->PickableOff();
210 my1DExtActor->SetHighlited(true);
211 my1DExtActor->SetVisibility(false);
212 my1DExtActor->SetProperty(my1DExtProp);
213 my1DExtActor->SetRepresentation(SMESH_DeviceActor::eInsideframe);
214 aFilter = my1DExtActor->GetExtractUnstructuredGrid();
215 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
216 aFilter->RegisterCellsWithType(VTK_LINE);
217 aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
220 //Definition 0D divice of the actor
221 //---------------------------------
222 myNodeProp = vtkProperty::New();
223 SMESH::GetColor( "SMESH", "node_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 0, 0 ) );
224 myNodeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
225 myNodeProp->SetPointSize(aPointSize);
227 myNodeActor = SMESH_DeviceActor::New();
228 myNodeActor->SetUserMatrix(aMatrix);
229 myNodeActor->SetStoreClippingMapping(true);
230 myNodeActor->PickableOff();
231 myNodeActor->SetVisibility(false);
232 myNodeActor->SetProperty(myNodeProp);
233 myNodeActor->SetRepresentation(SMESH_DeviceActor::ePoint);
234 aFilter = myNodeActor->GetExtractUnstructuredGrid();
235 aFilter->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
238 //Definition of Pickable and Highlitable engines
239 //----------------------------------------------
241 myBaseActor = SMESH_DeviceActor::New();
242 myBaseActor->SetUserMatrix(aMatrix);
243 myBaseActor->SetStoreGemetryMapping(true);
244 myBaseActor->GetProperty()->SetOpacity(0.0);
246 myPickableActor = myBaseActor;
248 myHighlightProp = vtkProperty::New();
249 myHighlightProp->SetAmbient(1.0);
250 myHighlightProp->SetDiffuse(0.0);
251 myHighlightProp->SetSpecular(0.0);
252 SMESH::GetColor( "SMESH", "selection_object_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
253 myHighlightProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
254 myHighlightProp->SetPointSize(aPointSize);
255 myHighlightProp->SetRepresentation(1);
257 myPreselectProp = vtkProperty::New();
258 myPreselectProp->SetAmbient(1.0);
259 myPreselectProp->SetDiffuse(0.0);
260 myPreselectProp->SetSpecular(0.0);
261 SMESH::GetColor( "SMESH", "highlight_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 255, 255 ) );
262 myPreselectProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
263 myPreselectProp->SetPointSize(aPointSize);
264 myPreselectProp->SetRepresentation(1);
266 myHighlitableActor = SMESH_DeviceActor::New();
267 myHighlitableActor->SetUserMatrix(aMatrix);
268 myHighlitableActor->PickableOff();
269 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
274 myControlMode = eNone;
275 myControlActor = my2DActor;
277 //Definition of myScalarBarActor
278 //------------------------------
279 myLookupTable = vtkLookupTable::New();
280 //Fix for Bug PAL5195 - SMESH764:
281 //Controls - Aspect Ratio: incorrect colors of the best and worst values
282 myLookupTable->SetHueRange(0.667,0.0);
284 myScalarBarActor = vtkScalarBarActor::New();
285 myScalarBarActor->SetVisibility(false);
286 myScalarBarActor->SetLookupTable(myLookupTable);
289 //Incorrect "Min value" in Scalar Bar in Mesh:
290 myScalarBarActor->SetLabelFormat("%.4g");
292 mgr = SUIT_Session::session()->resourceMgr();
296 //Definition of points numbering pipeline
297 //---------------------------------------
298 myPointsNumDataSet = vtkUnstructuredGrid::New();
300 myPtsMaskPoints = vtkMaskPoints::New();
301 myPtsMaskPoints->SetInput(myPointsNumDataSet);
302 myPtsMaskPoints->SetOnRatio(1);
304 myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
305 myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
306 myPtsSelectVisiblePoints->SelectInvisibleOff();
307 myPtsSelectVisiblePoints->SetTolerance(0.1);
309 myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
310 myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
311 myPtsLabeledDataMapper->SetLabelFormat("%g");
312 myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
314 vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
315 aPtsTextProp->SetFontFamilyToTimes();
316 static int aPointsFontSize = 10;
317 aPtsTextProp->SetFontSize(aPointsFontSize);
318 aPtsTextProp->SetBold(1);
319 aPtsTextProp->SetItalic(0);
320 aPtsTextProp->SetShadow(0);
321 myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
322 aPtsTextProp->Delete();
324 myEntityMode = eAllEntity;
326 myIsPointsLabeled = false;
328 myPointLabels = vtkActor2D::New();
329 myPointLabels->SetMapper(myPtsLabeledDataMapper);
330 myPointLabels->GetProperty()->SetColor(1,1,1);
331 myPointLabels->SetVisibility(myIsPointsLabeled);
334 //Definition of cells numbering pipeline
335 //---------------------------------------
336 myCellsNumDataSet = vtkUnstructuredGrid::New();
338 myCellCenters = vtkCellCenters::New();
339 myCellCenters->SetInput(myCellsNumDataSet);
341 myClsMaskPoints = vtkMaskPoints::New();
342 myClsMaskPoints->SetInput(myCellCenters->GetOutput());
343 myClsMaskPoints->SetOnRatio(1);
345 myClsSelectVisiblePoints = vtkSelectVisiblePoints::New();
346 myClsSelectVisiblePoints->SetInput(myClsMaskPoints->GetOutput());
347 myClsSelectVisiblePoints->SelectInvisibleOff();
348 myClsSelectVisiblePoints->SetTolerance(0.1);
350 myClsLabeledDataMapper = vtkLabeledDataMapper::New();
351 myClsLabeledDataMapper->SetInput(myClsSelectVisiblePoints->GetOutput());
352 myClsLabeledDataMapper->SetLabelFormat("%g");
353 myClsLabeledDataMapper->SetLabelModeToLabelScalars();
355 vtkTextProperty* aClsTextProp = vtkTextProperty::New();
356 aClsTextProp->SetFontFamilyToTimes();
357 static int aCellsFontSize = 12;
358 aClsTextProp->SetFontSize(aCellsFontSize);
359 aClsTextProp->SetBold(1);
360 aClsTextProp->SetItalic(0);
361 aClsTextProp->SetShadow(0);
362 myClsLabeledDataMapper->SetLabelTextProperty(aClsTextProp);
363 aClsTextProp->Delete();
365 myIsCellsLabeled = false;
367 myCellsLabels = vtkActor2D::New();
368 myCellsLabels->SetMapper(myClsLabeledDataMapper);
369 myCellsLabels->GetProperty()->SetColor(0,1,0);
370 myCellsLabels->SetVisibility(myIsCellsLabeled);
373 myImplicitBoolean = vtkImplicitBoolean::New();
374 myImplicitBoolean->SetOperationTypeToIntersection();
378 SMESH_ActorDef::~SMESH_ActorDef()
380 if(MYDEBUG) MESSAGE("~SMESH_ActorDef - "<<this);
382 myScalarBarActor->Delete();
383 myLookupTable->Delete();
385 mySurfaceProp->Delete();
386 myBackSurfaceProp->Delete();
388 myEdgeProp->Delete();
389 myHighlightProp->Delete();
390 myPreselectProp->Delete();
392 myNodeProp->Delete();
397 my1DExtProp->Delete();
398 my1DExtActor->Delete();
403 myNodeActor->Delete();
404 myBaseActor->Delete();
406 myHighlitableActor->Delete();
408 //Deleting of pints numbering pipeline
409 //---------------------------------------
410 myPointsNumDataSet->Delete();
412 // commented: porting to vtk 5.0
413 // myPtsLabeledDataMapper->RemoveAllInputs();
414 myPtsLabeledDataMapper->Delete();
416 // commented: porting to vtk 5.0
417 // myPtsSelectVisiblePoints->UnRegisterAllOutputs();
418 myPtsSelectVisiblePoints->Delete();
420 // commented: porting to vtk 5.0
421 // myPtsMaskPoints->UnRegisterAllOutputs();
422 myPtsMaskPoints->Delete();
424 myPointLabels->Delete();
427 //Deleting of cells numbering pipeline
428 //---------------------------------------
429 myCellsNumDataSet->Delete();
431 myClsLabeledDataMapper->RemoveAllInputs();
432 myClsLabeledDataMapper->Delete();
434 // commented: porting to vtk 5.0
435 // myClsSelectVisiblePoints->UnRegisterAllOutputs();
436 myClsSelectVisiblePoints->Delete();
438 // commented: porting to vtk 5.0
439 // myClsMaskPoints->UnRegisterAllOutputs();
440 myClsMaskPoints->Delete();
442 // commented: porting to vtk 5.0
443 // myCellCenters->UnRegisterAllOutputs();
444 myCellCenters->Delete();
446 myCellsLabels->Delete();
448 myImplicitBoolean->Delete();
450 myTimeStamp->Delete();
454 void SMESH_ActorDef::SetPointsLabeled( bool theIsPointsLabeled )
456 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
457 myIsPointsLabeled = theIsPointsLabeled && aGrid->GetNumberOfPoints();
459 if ( myIsPointsLabeled )
461 myPointsNumDataSet->ShallowCopy(aGrid);
462 vtkDataSet *aDataSet = myPointsNumDataSet;
464 int aNbElem = aDataSet->GetNumberOfPoints();
466 vtkIntArray *anArray = vtkIntArray::New();
467 anArray->SetNumberOfValues( aNbElem );
469 for ( int anId = 0; anId < aNbElem; anId++ )
471 int aSMDSId = myVisualObj->GetNodeObjId( anId );
472 anArray->SetValue( anId, aSMDSId );
475 aDataSet->GetPointData()->SetScalars( anArray );
477 myPtsMaskPoints->SetInput( aDataSet );
478 myPointLabels->SetVisibility( GetVisibility() );
482 myPointLabels->SetVisibility( false );
484 SetRepresentation(GetRepresentation());
485 myTimeStamp->Modified();
489 void SMESH_ActorDef::SetCellsLabeled(bool theIsCellsLabeled)
491 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
492 myIsCellsLabeled = theIsCellsLabeled && aGrid->GetNumberOfPoints();
493 if(myIsCellsLabeled){
494 myCellsNumDataSet->ShallowCopy(aGrid);
495 vtkDataSet *aDataSet = myCellsNumDataSet;
496 int aNbElem = aDataSet->GetNumberOfCells();
497 vtkIntArray *anArray = vtkIntArray::New();
498 anArray->SetNumberOfValues(aNbElem);
499 for(int anId = 0; anId < aNbElem; anId++){
500 int aSMDSId = myVisualObj->GetElemObjId(anId);
501 anArray->SetValue(anId,aSMDSId);
503 aDataSet->GetCellData()->SetScalars(anArray);
504 myCellCenters->SetInput(aDataSet);
505 myCellsLabels->SetVisibility(GetVisibility());
507 myCellsLabels->SetVisibility(false);
509 myTimeStamp->Modified();
515 SetControlMode(eControl theMode)
517 SetControlMode(theMode,true);
523 SetControlMode(eControl theMode,
524 bool theCheckEntityMode)
526 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
530 myControlMode = eNone;
531 theCheckEntityMode &= mgr->booleanValue( "SMESH", "display_entity", false );
533 my1DActor->GetMapper()->SetScalarVisibility(false);
534 my2DActor->GetMapper()->SetScalarVisibility(false);
535 my3DActor->GetMapper()->SetScalarVisibility(false);
536 myScalarBarActor->SetVisibility(false);
538 bool anIsScalarVisible = theMode > eNone;
540 if(anIsScalarVisible){
541 SMESH::Controls::FunctorPtr aFunctor;
545 SMESH::Controls::Length* aControl = new SMESH::Controls::Length();
546 aControl->SetPrecision( myControlsPrecision );
547 aFunctor.reset( aControl );
548 myControlActor = my1DActor;
553 aFunctor.reset(new SMESH::Controls::Length2D());
554 myControlActor = my2DActor;
558 aFunctor.reset(new SMESH::Controls::FreeBorders());
559 myControlActor = my1DActor;
562 aFunctor.reset(new SMESH::Controls::FreeEdges());
563 myControlActor = my2DActor;
565 case eMultiConnection:
566 aFunctor.reset(new SMESH::Controls::MultiConnection());
567 myControlActor = my1DActor;
569 case eMultiConnection2D:
570 aFunctor.reset(new SMESH::Controls::MultiConnection2D());
571 myControlActor = my2DActor;
575 SMESH::Controls::Area* aControl = new SMESH::Controls::Area();
576 aControl->SetPrecision( myControlsPrecision );
577 aFunctor.reset( aControl );
578 myControlActor = my2DActor;
583 SMESH::Controls::Taper* aControl = new SMESH::Controls::Taper();
584 aControl->SetPrecision( myControlsPrecision );
585 aFunctor.reset( aControl );
586 myControlActor = my2DActor;
591 SMESH::Controls::AspectRatio* aControl = new SMESH::Controls::AspectRatio();
592 aControl->SetPrecision( myControlsPrecision );
593 aFunctor.reset( aControl );
594 myControlActor = my2DActor;
599 SMESH::Controls::AspectRatio3D* aControl = new SMESH::Controls::AspectRatio3D();
600 aControl->SetPrecision( myControlsPrecision );
601 aFunctor.reset( aControl );
602 myControlActor = my3DActor;
607 SMESH::Controls::Volume* aControl = new SMESH::Controls::Volume();
608 aControl->SetPrecision( myControlsPrecision );
609 aFunctor.reset( aControl );
610 myControlActor = my3DActor;
615 SMESH::Controls::MinimumAngle* aControl = new SMESH::Controls::MinimumAngle();
616 aControl->SetPrecision( myControlsPrecision );
617 aFunctor.reset( aControl );
618 myControlActor = my2DActor;
623 SMESH::Controls::Warping* aControl = new SMESH::Controls::Warping();
624 aControl->SetPrecision( myControlsPrecision );
625 aFunctor.reset( aControl );
626 myControlActor = my2DActor;
631 SMESH::Controls::Skew* aControl = new SMESH::Controls::Skew();
632 aControl->SetPrecision( myControlsPrecision );
633 aFunctor.reset( aControl );
634 myControlActor = my2DActor;
641 vtkUnstructuredGrid* aGrid = myControlActor->GetUnstructuredGrid();
642 vtkIdType aNbCells = aGrid->GetNumberOfCells();
644 myControlMode = theMode;
645 switch(myControlMode){
648 my1DExtActor->SetExtControlMode(aFunctor);
651 case eMultiConnection2D:
652 my1DExtActor->SetExtControlMode(aFunctor,myScalarBarActor,myLookupTable);
655 myControlActor->SetControlMode(aFunctor,myScalarBarActor,myLookupTable);
659 if(theCheckEntityMode){
660 if(myControlActor == my1DActor)
661 SetEntityMode(eEdges);
662 else if(myControlActor == my2DActor){
663 switch(myControlMode){
666 case eMultiConnection2D:
667 //SetEntityMode(eEdges);
668 SetEntityMode(eFaces);
671 SetEntityMode(eFaces);
673 }else if(myControlActor == my3DActor)
674 SetEntityMode(eVolumes);
677 }else if(theCheckEntityMode){
678 myEntityMode = eAllEntity;
681 SetRepresentation(GetRepresentation());
683 myTimeStamp->Modified();
688 void SMESH_ActorDef::AddToRender(vtkRenderer* theRenderer){
689 SALOME_Actor::AddToRender(theRenderer);
691 theRenderer->AddActor(myNodeActor);
692 theRenderer->AddActor(myBaseActor);
694 theRenderer->AddActor(my3DActor);
695 theRenderer->AddActor(my2DActor);
697 theRenderer->AddActor(my1DActor);
698 theRenderer->AddActor(my1DExtActor);
700 theRenderer->AddActor(myHighlitableActor);
702 theRenderer->AddActor2D(myScalarBarActor);
704 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
705 myClsSelectVisiblePoints->SetRenderer(theRenderer);
707 theRenderer->AddActor2D(myPointLabels);
708 theRenderer->AddActor2D(myCellsLabels);
711 void SMESH_ActorDef::RemoveFromRender(vtkRenderer* theRenderer){
712 SALOME_Actor::RemoveFromRender(theRenderer);
714 theRenderer->RemoveActor(myNodeActor);
715 theRenderer->RemoveActor(myBaseActor);
717 theRenderer->RemoveActor(myHighlitableActor);
719 theRenderer->RemoveActor(my1DActor);
720 theRenderer->RemoveActor(my1DExtActor);
722 theRenderer->RemoveActor(my2DActor);
723 theRenderer->RemoveActor(my3DActor);
725 theRenderer->RemoveActor(myScalarBarActor);
726 theRenderer->RemoveActor(myPointLabels);
727 theRenderer->RemoveActor(myCellsLabels);
731 bool SMESH_ActorDef::Init(TVisualObjPtr theVisualObj,
732 const char* theEntry,
736 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry,"SMESH",theName);
740 myVisualObj = theVisualObj;
741 myVisualObj->Update(theIsClear);
743 myNodeActor->Init(myVisualObj,myImplicitBoolean);
744 myBaseActor->Init(myVisualObj,myImplicitBoolean);
746 myHighlitableActor->Init(myVisualObj,myImplicitBoolean);
748 my1DActor->Init(myVisualObj,myImplicitBoolean);
749 my1DExtActor->Init(myVisualObj,myImplicitBoolean);
751 my2DActor->Init(myVisualObj,myImplicitBoolean);
752 my3DActor->Init(myVisualObj,myImplicitBoolean);
754 my1DActor->GetMapper()->SetLookupTable(myLookupTable);
755 my1DExtActor->GetMapper()->SetLookupTable(myLookupTable);
757 my2DActor->GetMapper()->SetLookupTable(myLookupTable);
758 my3DActor->GetMapper()->SetLookupTable(myLookupTable);
760 vtkFloatingPointType aFactor, aUnits;
761 my2DActor->GetPolygonOffsetParameters(aFactor,aUnits);
762 my2DActor->SetPolygonOffsetParameters(aFactor,aUnits*0.75);
764 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
768 //SetIsShrunkable(theGrid->GetNumberOfCells() > 10);
769 SetIsShrunkable(true);
771 SetShrinkFactor( SMESH::GetFloat( "SMESH:shrink_coeff", 0.75 ) );
773 int aMode = mgr->integerValue( "SMESH", "display_mode" );
774 SetRepresentation(-1);
777 SetRepresentation(eEdge);
778 }else if(aMode == 1){
779 SetRepresentation(eSurface);
780 }else if(aMode == 2){
781 SetRepresentation(ePoint);
788 myTimeStamp->Modified();
794 vtkFloatingPointType* SMESH_ActorDef::GetBounds(){
795 return myNodeActor->GetBounds();
799 vtkDataSet* SMESH_ActorDef::GetInput(){
800 return GetUnstructuredGrid();
804 void SMESH_ActorDef::SetTransform(VTKViewer_Transform* theTransform){
805 Superclass::SetTransform(theTransform);
807 myNodeActor->SetTransform(theTransform);
808 myBaseActor->SetTransform(theTransform);
810 myHighlitableActor->SetTransform(theTransform);
812 my1DActor->SetTransform(theTransform);
813 my1DExtActor->SetTransform(theTransform);
815 my2DActor->SetTransform(theTransform);
816 my3DActor->SetTransform(theTransform);
822 void SMESH_ActorDef::SetMapper(vtkMapper* theMapper){
823 vtkLODActor::SetMapper(theMapper);
827 void SMESH_ActorDef::ShallowCopy(vtkProp *prop){
828 SALOME_Actor::ShallowCopy(prop);
832 vtkMapper* SMESH_ActorDef::GetMapper(){
833 return myPickableActor->GetMapper();
837 vtkUnstructuredGrid* SMESH_ActorDef::GetUnstructuredGrid(){
838 return myVisualObj->GetUnstructuredGrid();
842 bool SMESH_ActorDef::IsInfinitive(){
843 vtkDataSet *aDataSet = myPickableActor->GetUnstructuredGrid();
845 myIsInfinite = aDataSet->GetNumberOfCells() == 0 ||
846 aDataSet->GetNumberOfCells() == 1 &&
847 aDataSet->GetCell(0)->GetCellType() == VTK_VERTEX;
848 return SALOME_Actor::IsInfinitive();
852 void SMESH_ActorDef::SetIsShrunkable(bool theShrunkable){
853 if ( myIsShrinkable == theShrunkable )
855 myIsShrinkable = theShrunkable;
859 vtkFloatingPointType SMESH_ActorDef::GetShrinkFactor(){
860 return myBaseActor->GetShrinkFactor();
863 void SMESH_ActorDef::SetShrinkFactor(vtkFloatingPointType theValue){
864 myBaseActor->SetShrinkFactor(theValue);
866 my1DActor->SetShrinkFactor(theValue);
867 my1DExtActor->SetShrinkFactor(theValue);
869 my2DActor->SetShrinkFactor(theValue);
870 my3DActor->SetShrinkFactor(theValue);
875 void SMESH_ActorDef::SetShrink(){
876 if(!myIsShrinkable) return;
878 myBaseActor->SetShrink();
880 my1DActor->SetShrink();
881 my1DExtActor->SetShrink();
883 my2DActor->SetShrink();
884 my3DActor->SetShrink();
890 void SMESH_ActorDef::UnShrink(){
891 if(!myIsShrunk) return;
893 myBaseActor->UnShrink();
895 my1DActor->UnShrink();
896 my1DExtActor->UnShrink();
898 my2DActor->UnShrink();
899 my3DActor->UnShrink();
906 int SMESH_ActorDef::GetNodeObjId(int theVtkID){
907 return myPickableActor->GetNodeObjId(theVtkID);
910 vtkFloatingPointType* SMESH_ActorDef::GetNodeCoord(int theObjID){
911 return myPickableActor->GetNodeCoord(theObjID);
915 int SMESH_ActorDef::GetElemObjId(int theVtkID){
916 return myPickableActor->GetElemObjId(theVtkID);
919 vtkCell* SMESH_ActorDef::GetElemCell(int theObjID){
920 return myPickableActor->GetElemCell(theObjID);
924 void SMESH_ActorDef::SetVisibility(int theMode){
925 SetVisibility(theMode,true);
929 void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation){
930 SALOME_Actor::SetVisibility(theMode);
932 myNodeActor->VisibilityOff();
933 myBaseActor->VisibilityOff();
935 my1DActor->VisibilityOff();
936 my1DExtActor->VisibilityOff();
938 my2DActor->VisibilityOff();
939 my3DActor->VisibilityOff();
941 myScalarBarActor->VisibilityOff();
942 myPointLabels->VisibilityOff();
943 myCellsLabels->VisibilityOff();
946 if(theIsUpdateRepersentation)
947 SetRepresentation(GetRepresentation());
949 if(myControlMode != eNone){
950 switch(myControlMode){
953 my1DExtActor->VisibilityOn();
956 case eMultiConnection2D:
957 my1DExtActor->VisibilityOn();
959 if(myControlActor->GetUnstructuredGrid()->GetNumberOfCells())
960 myScalarBarActor->VisibilityOn();
964 if(myRepresentation != ePoint)
965 myPickableActor->VisibilityOn();
967 myNodeActor->VisibilityOn();
970 if(myEntityMode & eEdges){
971 my1DActor->VisibilityOn();
974 if(myEntityMode & eFaces){
975 my2DActor->VisibilityOn();
978 if(myEntityMode & eVolumes){
979 my3DActor->VisibilityOn();
982 if(myIsPointsLabeled){
983 myPointLabels->VisibilityOn();
984 myNodeActor->VisibilityOn();
988 myCellsLabels->VisibilityOn();
995 void SMESH_ActorDef::SetEntityMode(unsigned int theMode){
996 myEntityState = eAllEntity;
998 if(!myVisualObj->GetNbEntities(SMDSAbs_Edge)){
999 myEntityState &= ~eEdges;
1003 if(!myVisualObj->GetNbEntities(SMDSAbs_Face)){
1004 myEntityState &= ~eFaces;
1008 if(!myVisualObj->GetNbEntities(SMDSAbs_Volume)){
1009 myEntityState &= ~eVolumes;
1010 theMode &= ~eVolumes;
1014 if(myVisualObj->GetNbEntities(SMDSAbs_Edge))
1017 if(myVisualObj->GetNbEntities(SMDSAbs_Face))
1020 if(myVisualObj->GetNbEntities(SMDSAbs_Volume))
1021 theMode |= eVolumes;
1024 myBaseActor->myGeomFilter->SetInside(myEntityMode != myEntityState);
1026 myEntityMode = theMode;
1027 VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
1028 aFilter = myBaseActor->GetExtractUnstructuredGrid();
1029 aFilter->ClearRegisteredCellsWithType();
1030 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
1032 if(myEntityMode & eEdges){
1033 if (MYDEBUG) MESSAGE("EDGES");
1034 aFilter->RegisterCellsWithType(VTK_LINE);
1035 aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
1038 if(myEntityMode & eFaces){
1039 if (MYDEBUG) MESSAGE("FACES");
1040 aFilter->RegisterCellsWithType(VTK_TRIANGLE);
1041 aFilter->RegisterCellsWithType(VTK_POLYGON);
1042 aFilter->RegisterCellsWithType(VTK_QUAD);
1043 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
1044 aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
1047 if(myEntityMode & eVolumes){
1048 if (MYDEBUG) MESSAGE("VOLUMES");
1049 aFilter->RegisterCellsWithType(VTK_TETRA);
1050 aFilter->RegisterCellsWithType(VTK_VOXEL);
1051 aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1052 aFilter->RegisterCellsWithType(VTK_WEDGE);
1053 aFilter->RegisterCellsWithType(VTK_PYRAMID);
1054 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
1055 aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
1056 aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1059 if (MYDEBUG) MESSAGE(aFilter->GetOutput()->GetNumberOfCells());
1060 SetVisibility(GetVisibility(),false);
1063 void SMESH_ActorDef::SetRepresentation(int theMode){
1064 int aNbEdges = myVisualObj->GetNbEntities(SMDSAbs_Edge);
1065 int aNbFaces = myVisualObj->GetNbEntities(SMDSAbs_Face);
1066 int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume);
1068 myRepresentation = eSurface;
1069 if(!aNbFaces && !aNbVolumes && aNbEdges){
1070 myRepresentation = eEdge;
1071 }else if(!aNbFaces && !aNbVolumes && !aNbEdges){
1072 myRepresentation = ePoint;
1077 if(!aNbFaces && !aNbVolumes && !aNbEdges) return;
1080 if(!aNbFaces && !aNbVolumes) return;
1083 myRepresentation = theMode;
1086 if(!GetUnstructuredGrid()->GetNumberOfCells())
1087 myRepresentation = ePoint;
1090 if(myRepresentation == ePoint){
1098 myPickableActor = myBaseActor;
1099 myNodeActor->SetVisibility(false);
1100 vtkProperty *aProp = NULL, *aBackProp = NULL;
1101 SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1);
1102 switch(myRepresentation){
1104 myPickableActor = myNodeActor;
1105 myNodeActor->SetVisibility(true);
1107 aProp = aBackProp = myNodeProp;
1108 aReperesent = SMESH_DeviceActor::ePoint;
1111 aProp = aBackProp = myEdgeProp;
1112 aReperesent = SMESH_DeviceActor::eInsideframe;
1115 aProp = mySurfaceProp;
1116 aBackProp = myBackSurfaceProp;
1117 aReperesent = SMESH_DeviceActor::eSurface;
1121 my2DActor->SetProperty(aProp);
1122 my2DActor->SetBackfaceProperty(aBackProp);
1123 my2DActor->SetRepresentation(aReperesent);
1125 my3DActor->SetProperty(aProp);
1126 my3DActor->SetBackfaceProperty(aBackProp);
1127 my3DActor->SetRepresentation(aReperesent);
1129 my1DExtActor->SetVisibility(false);
1131 switch(myControlMode){
1133 case eMultiConnection:
1134 aProp = aBackProp = my1DProp;
1135 if(myRepresentation != ePoint)
1136 aReperesent = SMESH_DeviceActor::eInsideframe;
1140 my1DActor->SetProperty(aProp);
1141 my1DActor->SetBackfaceProperty(aBackProp);
1142 my1DActor->SetRepresentation(aReperesent);
1144 my1DExtActor->SetRepresentation(aReperesent);
1146 if(myIsPointsVisible)
1147 myPickableActor = myNodeActor;
1148 if(GetPointRepresentation())
1149 myNodeActor->SetVisibility(true);
1151 SetMapper(myPickableActor->GetMapper());
1153 SetVisibility(GetVisibility(),false);
1159 void SMESH_ActorDef::SetPointRepresentation(bool theIsPointsVisible){
1160 if ( myIsPointsVisible == theIsPointsVisible )
1162 myIsPointsVisible = theIsPointsVisible;
1163 SetRepresentation(GetRepresentation());
1166 bool SMESH_ActorDef::GetPointRepresentation(){
1167 return myIsPointsVisible || myIsPointsLabeled;
1171 void SMESH_ActorDef::UpdateHighlight(){
1172 myHighlitableActor->SetVisibility(false);
1173 myHighlitableActor->SetHighlited(false);
1175 if(myIsHighlighted){
1176 myHighlitableActor->SetProperty(myHighlightProp);
1177 }else if(myIsPreselected){
1178 myHighlitableActor->SetProperty(myPreselectProp);
1181 bool anIsVisible = GetVisibility();
1183 if(myIsHighlighted || myIsPreselected){
1184 if(GetUnstructuredGrid()->GetNumberOfCells()){
1185 myHighlitableActor->SetHighlited(anIsVisible);
1186 myHighlitableActor->SetVisibility(anIsVisible);
1187 myHighlitableActor->GetExtractUnstructuredGrid()->
1188 SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::eCells);
1189 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
1190 }else if(myRepresentation == ePoint || GetPointRepresentation()){
1191 myHighlitableActor->SetHighlited(anIsVisible);
1192 myHighlitableActor->GetExtractUnstructuredGrid()->
1193 SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
1194 myHighlitableActor->SetVisibility(anIsVisible);
1195 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::ePoint);
1201 void SMESH_ActorDef::highlight(bool theHighlight){
1202 if ( myIsHighlighted == theHighlight )
1204 myIsHighlighted = theHighlight;
1209 void SMESH_ActorDef::SetPreSelected(bool thePreselect){
1210 if ( myIsPreselected == thePreselect )
1212 myIsPreselected = thePreselect;
1218 int SMESH_ActorDef::RenderOpaqueGeometry(vtkViewport *vp)
1220 if (myPickableActor->GetIsOpaque())
1222 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1230 int SMESH_ActorDef::RenderTranslucentGeometry(vtkViewport *vp)
1232 if (!myPickableActor->GetIsOpaque())
1234 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1242 void SMESH_ActorDef::Render(vtkRenderer *ren){
1243 unsigned long aTime = myTimeStamp->GetMTime();
1244 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1245 unsigned long aClippingTime = myImplicitBoolean->GetMTime();
1246 if(anObjTime > aTime || aClippingTime > aTime)
1251 void SMESH_ActorDef::Update(){
1252 if(MYDEBUG) MESSAGE("SMESH_ActorDef::Update");
1254 if(GetControlMode() != eNone) {
1255 unsigned long aTime = myTimeStamp->GetMTime();
1256 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1257 if (anObjTime > aTime)
1258 SetControlMode(GetControlMode(),false);
1260 if(myIsPointsLabeled){
1261 SetPointsLabeled(myIsPointsLabeled);
1263 if(myIsCellsLabeled){
1264 SetCellsLabeled(myIsCellsLabeled);
1266 SetEntityMode(GetEntityMode());
1267 SetVisibility(GetVisibility());
1269 myTimeStamp->Modified();
1274 void SMESH_ActorDef::ReleaseGraphicsResources(vtkWindow *renWin){
1275 SALOME_Actor::ReleaseGraphicsResources(renWin);
1277 myPickableActor->ReleaseGraphicsResources(renWin);
1281 static void GetColor(vtkProperty *theProperty, vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1282 vtkFloatingPointType* aColor = theProperty->GetColor();
1289 void SMESH_ActorDef::SetOpacity(vtkFloatingPointType theValue){
1290 mySurfaceProp->SetOpacity(theValue);
1291 myBackSurfaceProp->SetOpacity(theValue);
1292 myEdgeProp->SetOpacity(theValue);
1293 myNodeProp->SetOpacity(theValue);
1295 my1DProp->SetOpacity(theValue);
1299 vtkFloatingPointType SMESH_ActorDef::GetOpacity(){
1300 return mySurfaceProp->GetOpacity();
1304 void SMESH_ActorDef::SetSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1305 mySurfaceProp->SetColor(r,g,b);
1309 void SMESH_ActorDef::GetSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1310 ::GetColor(mySurfaceProp,r,g,b);
1313 void SMESH_ActorDef::SetBackSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1314 myBackSurfaceProp->SetColor(r,g,b);
1318 void SMESH_ActorDef::GetBackSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1319 ::GetColor(myBackSurfaceProp,r,g,b);
1322 void SMESH_ActorDef::SetEdgeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1323 myEdgeProp->SetColor(r,g,b);
1324 my1DProp->SetColor(r,g,b);
1325 my1DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1329 void SMESH_ActorDef::GetEdgeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1330 ::GetColor(myEdgeProp,r,g,b);
1333 void SMESH_ActorDef::SetNodeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1334 myNodeProp->SetColor(r,g,b);
1338 void SMESH_ActorDef::GetNodeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1339 ::GetColor(myNodeProp,r,g,b);
1342 void SMESH_ActorDef::SetHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1343 myHighlightProp->SetColor(r,g,b);
1347 void SMESH_ActorDef::GetHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1348 ::GetColor(myHighlightProp,r,g,b);
1351 void SMESH_ActorDef::SetPreHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1352 myPreselectProp->SetColor(r,g,b);
1356 void SMESH_ActorDef::GetPreHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1357 ::GetColor(myPreselectProp,r,g,b);
1361 vtkFloatingPointType SMESH_ActorDef::GetLineWidth(){
1362 return myEdgeProp->GetLineWidth();
1366 void SMESH_ActorDef::SetLineWidth(vtkFloatingPointType theVal){
1367 myEdgeProp->SetLineWidth(theVal);
1369 my1DProp->SetLineWidth(theVal + aLineWidthInc);
1370 my1DExtProp->SetLineWidth(theVal + aLineWidthInc);
1376 void SMESH_ActorDef::SetNodeSize(vtkFloatingPointType theVal){
1377 myNodeProp->SetPointSize(theVal);
1378 myHighlightProp->SetPointSize(theVal);
1379 myPreselectProp->SetPointSize(theVal);
1381 my1DProp->SetPointSize(theVal + aPointSizeInc);
1382 my1DExtProp->SetPointSize(theVal + aPointSizeInc);
1387 vtkFloatingPointType SMESH_ActorDef::GetNodeSize(){
1388 return myNodeProp->GetPointSize();
1391 int SMESH_ActorDef::GetObjDimension( const int theObjId )
1393 return myVisualObj->GetElemDimension( theObjId );
1398 IsImplicitFunctionUsed() const
1400 return myBaseActor->IsImplicitFunctionUsed();
1405 SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
1407 myNodeActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1408 myBaseActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1410 myHighlitableActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1412 my1DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1413 my1DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1415 my2DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1416 my3DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1421 AddClippingPlane(vtkPlane* thePlane)
1424 myImplicitBoolean->GetFunction()->AddItem(thePlane);
1425 myCippingPlaneCont.push_back(thePlane);
1426 if(!IsImplicitFunctionUsed())
1427 SetImplicitFunctionUsed(true);
1429 return myCippingPlaneCont.size();
1434 RemoveAllClippingPlanes()
1436 myImplicitBoolean->GetFunction()->RemoveAllItems();
1437 myImplicitBoolean->GetFunction()->Modified(); // VTK bug
1438 myCippingPlaneCont.clear();
1439 SetImplicitFunctionUsed(false);
1444 GetNumberOfClippingPlanes()
1446 return myCippingPlaneCont.size();
1451 GetClippingPlane(vtkIdType theID)
1453 if(theID >= myCippingPlaneCont.size())
1455 return myCippingPlaneCont[theID].Get();
1459 static void ComputeBoundsParam(vtkDataSet* theDataSet,
1460 vtkFloatingPointType theDirection[3], vtkFloatingPointType theMinPnt[3],
1461 vtkFloatingPointType& theMaxBoundPrj, vtkFloatingPointType& theMinBoundPrj)
1463 vtkFloatingPointType aBounds[6];
1464 theDataSet->GetBounds(aBounds);
1466 //Enlarge bounds in order to avoid conflicts of precision
1467 for(int i = 0; i < 6; i += 2){
1468 static double EPS = 1.0E-3;
1469 vtkFloatingPointType aDelta = (aBounds[i+1] - aBounds[i])*EPS;
1470 aBounds[i] -= aDelta;
1471 aBounds[i+1] += aDelta;
1474 vtkFloatingPointType aBoundPoints[8][3] = { {aBounds[0],aBounds[2],aBounds[4]},
1475 {aBounds[1],aBounds[2],aBounds[4]},
1476 {aBounds[0],aBounds[3],aBounds[4]},
1477 {aBounds[1],aBounds[3],aBounds[4]},
1478 {aBounds[0],aBounds[2],aBounds[5]},
1479 {aBounds[1],aBounds[2],aBounds[5]},
1480 {aBounds[0],aBounds[3],aBounds[5]},
1481 {aBounds[1],aBounds[3],aBounds[5]}};
1483 int aMaxId = 0, aMinId = aMaxId;
1484 theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
1485 theMinBoundPrj = theMaxBoundPrj;
1486 for(int i = 1; i < 8; i++){
1487 vtkFloatingPointType aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
1488 if(theMaxBoundPrj < aTmp){
1489 theMaxBoundPrj = aTmp;
1492 if(theMinBoundPrj > aTmp){
1493 theMinBoundPrj = aTmp;
1497 vtkFloatingPointType *aMinPnt = aBoundPoints[aMaxId];
1498 theMinPnt[0] = aMinPnt[0];
1499 theMinPnt[1] = aMinPnt[1];
1500 theMinPnt[2] = aMinPnt[2];
1504 static void DistanceToPosition(vtkDataSet* theDataSet,
1505 vtkFloatingPointType theDirection[3], vtkFloatingPointType theDist, vtkFloatingPointType thePos[3])
1507 vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1508 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1509 vtkFloatingPointType aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
1510 thePos[0] = aMinPnt[0]-theDirection[0]*aLength;
1511 thePos[1] = aMinPnt[1]-theDirection[1]*aLength;
1512 thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
1516 static void PositionToDistance(vtkDataSet* theDataSet,
1517 vtkFloatingPointType theDirection[3], vtkFloatingPointType thePos[3], vtkFloatingPointType& theDist)
1519 vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1520 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1521 vtkFloatingPointType aPrj = vtkMath::Dot(theDirection,thePos);
1522 theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
1526 void SMESH_ActorDef::SetPlaneParam(vtkFloatingPointType theDir[3], vtkFloatingPointType theDist, vtkPlane* thePlane)
1528 thePlane->SetNormal(theDir);
1529 vtkFloatingPointType anOrigin[3];
1530 ::DistanceToPosition(GetUnstructuredGrid(),theDir,theDist,anOrigin);
1531 thePlane->SetOrigin(anOrigin);
1535 void SMESH_ActorDef::GetPlaneParam(vtkFloatingPointType theDir[3], vtkFloatingPointType& theDist, vtkPlane* thePlane)
1537 thePlane->GetNormal(theDir);
1539 vtkFloatingPointType anOrigin[3];
1540 thePlane->GetOrigin(anOrigin);
1541 ::PositionToDistance(GetUnstructuredGrid(),theDir,anOrigin,theDist);
1544 void SMESH_ActorDef::UpdateScalarBar()
1546 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
1550 vtkTextProperty* aScalarBarTitleProp = vtkTextProperty::New();
1552 QColor aTColor = mgr->colorValue( "SMESH", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
1553 aScalarBarTitleProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1555 aScalarBarTitleProp->SetFontFamilyToArial();
1557 if ( mgr->hasValue( "SMESH", "scalar_bar_title_font" ) )
1559 QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
1560 if ( f.family() == "Arial" )
1561 aScalarBarTitleProp->SetFontFamilyToArial();
1562 else if ( f.family() == "Courier" )
1563 aScalarBarTitleProp->SetFontFamilyToCourier();
1564 else if ( f.family() == "Times" )
1565 aScalarBarTitleProp->SetFontFamilyToTimes();
1568 aScalarBarTitleProp->BoldOn();
1570 aScalarBarTitleProp->BoldOff();
1573 aScalarBarTitleProp->ItalicOn();
1575 aScalarBarTitleProp->ItalicOff();
1577 if ( f.underline() )
1578 aScalarBarTitleProp->ShadowOn();
1580 aScalarBarTitleProp->ShadowOff();
1583 myScalarBarActor->SetTitleTextProperty( aScalarBarTitleProp );
1584 aScalarBarTitleProp->Delete();
1586 vtkTextProperty* aScalarBarLabelProp = vtkTextProperty::New();
1588 aTColor = mgr->colorValue( "SMESH", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
1589 aScalarBarLabelProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1591 aScalarBarLabelProp->SetFontFamilyToArial();
1592 if( mgr->hasValue( "SMESH", "scalar_bar_label_font" ) )
1594 QFont f = mgr->fontValue( "SMESH", "scalar_bar_label_font" );
1595 if( f.family() == "Arial" )
1596 aScalarBarLabelProp->SetFontFamilyToArial();
1597 else if( f.family() == "Courier" )
1598 aScalarBarLabelProp->SetFontFamilyToCourier();
1599 else if( f.family() == "Times" )
1600 aScalarBarLabelProp->SetFontFamilyToTimes();
1603 aScalarBarLabelProp->BoldOn();
1605 aScalarBarLabelProp->BoldOff();
1608 aScalarBarLabelProp->ItalicOn();
1610 aScalarBarLabelProp->ItalicOff();
1613 aScalarBarLabelProp->ShadowOn();
1615 aScalarBarLabelProp->ShadowOff();
1618 myScalarBarActor->SetLabelTextProperty( aScalarBarLabelProp );
1619 aScalarBarLabelProp->Delete();
1621 bool horiz = ( mgr->integerValue( "SMESH", "scalar_bar_orientation" ) == 1 );
1622 QString name = QString( "scalar_bar_%1_" ).arg( horiz ? "horizontal" : "vertical" );
1624 myScalarBarActor->SetOrientationToHorizontal();
1626 myScalarBarActor->SetOrientationToVertical();
1629 vtkFloatingPointType aXVal = horiz ? 0.20 : 0.01;
1630 if( mgr->hasValue( "SMESH", name + "x" ) )
1631 aXVal = mgr->doubleValue( "SMESH", name + "x", aXVal );
1633 vtkFloatingPointType aYVal = horiz ? 0.01 : 0.1;
1634 if( mgr->hasValue( "SMESH", name + "y" ) )
1635 aYVal = mgr->doubleValue( "SMESH", name + "y", aYVal );
1636 myScalarBarActor->SetPosition( aXVal, aYVal );
1638 vtkFloatingPointType aWVal = horiz ? 0.60 : 0.10;
1639 if( mgr->hasValue( "SMESH", name + "width" ) )
1640 aWVal = mgr->doubleValue( "SMESH", name + "width", aWVal );
1641 myScalarBarActor->SetWidth( aWVal );
1643 vtkFloatingPointType aHVal = horiz ? 0.12 : 0.80;
1644 if( mgr->hasValue( "SMESH", name + "height" ) )
1645 aHVal = mgr->doubleValue( "SMESH", name + "height", aHVal );
1646 myScalarBarActor->SetHeight( aHVal );
1649 if( mgr->hasValue( "SMESH", "scalar_bar_num_labels" ) )
1650 anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_labels", anIntVal );
1651 myScalarBarActor->SetNumberOfLabels( anIntVal == 0 ? 5: anIntVal );
1654 if( mgr->hasValue( "SMESH", "scalar_bar_num_colors" ) )
1655 anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_colors", anIntVal );
1656 myScalarBarActor->SetMaximumNumberOfColors( anIntVal == 0 ? 64 : anIntVal );