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"
36 #include "SUIT_Session.h"
37 #include "SUIT_ResourceMgr.h"
39 #include <qstringlist.h>
41 #include <vtkProperty.h>
42 #include <vtkTimeStamp.h>
43 #include <vtkObjectFactory.h>
44 #include <vtkShrinkPolyData.h>
45 #include <vtkMergeFilter.h>
47 #include <vtkMatrix4x4.h>
48 #include <vtkUnstructuredGrid.h>
49 #include <vtkPointData.h>
50 #include <vtkCellData.h>
52 #include <vtkMapper.h>
53 #include <vtkRenderer.h>
56 #include <vtkIdList.h>
57 #include <vtkIntArray.h>
59 #include <vtkActor2D.h>
60 #include <vtkProperty2D.h>
61 #include <vtkPolyData.h>
62 #include <vtkMaskPoints.h>
63 #include <vtkCellCenters.h>
64 #include <vtkTextProperty.h>
65 #include <vtkLabeledDataMapper.h>
66 #include <vtkSelectVisiblePoints.h>
68 #include <vtkScalarBarActor.h>
69 #include <vtkLookupTable.h>
73 #include <vtkImplicitBoolean.h>
74 #include <vtkImplicitFunctionCollection.h>
76 #include "utilities.h"
79 static int MYDEBUG = 1;
81 static int MYDEBUG = 0;
84 static int aLineWidthInc = 2;
85 static int aPointSizeInc = 2;
88 SMESH_ActorDef* SMESH_ActorDef::New(){
89 return new SMESH_ActorDef();
93 SMESH_Actor* SMESH_Actor::New(TVisualObjPtr theVisualObj,
98 SMESH_ActorDef* anActor = SMESH_ActorDef::New();
99 if(!anActor->Init(theVisualObj,theEntry,theName,theIsClear)){
104 anActor->UpdateScalarBar();
109 SMESH_ActorDef::SMESH_ActorDef()
111 if(MYDEBUG) MESSAGE("SMESH_ActorDef - "<<this);
113 myTimeStamp = vtkTimeStamp::New();
115 myIsPointsVisible = false;
117 myIsShrinkable = false;
120 myControlsPrecision = -1;
121 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
122 if ( mgr && mgr->booleanValue( "SMESH", "use_precision", false ) )
123 myControlsPrecision = (long)SMESH::GetFloat( "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);
175 //Definition 1D divice of the actor
176 //---------------------------------
177 myEdgeProp = vtkProperty::New();
178 myEdgeProp->SetAmbient(1.0);
179 myEdgeProp->SetDiffuse(0.0);
180 myEdgeProp->SetSpecular(0.0);
181 SMESH::GetColor( "SMESH", "outline_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
182 myEdgeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
183 myEdgeProp->SetLineWidth(aLineWidth);
185 my1DActor = SMESH_DeviceActor::New();
186 my1DActor->SetUserMatrix(aMatrix);
187 my1DActor->PickableOff();
188 my1DActor->SetHighlited(true);
189 my1DActor->SetProperty(myEdgeProp);
190 my1DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
191 aFilter = my1DActor->GetExtractUnstructuredGrid();
192 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
193 aFilter->RegisterCellsWithType(VTK_LINE);
194 aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
196 my1DProp = vtkProperty::New();
197 my1DProp->DeepCopy(myEdgeProp);
198 my1DProp->SetLineWidth(aLineWidth + aLineWidthInc);
199 my1DProp->SetPointSize(aPointSize);
201 my1DExtProp = vtkProperty::New();
202 my1DExtProp->DeepCopy(myEdgeProp);
203 anRGB[0] = 1 - anRGB[0];
204 anRGB[1] = 1 - anRGB[1];
205 anRGB[2] = 1 - anRGB[2];
206 my1DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
207 my1DExtProp->SetLineWidth(aLineWidth + aLineWidthInc);
208 my1DExtProp->SetPointSize(aPointSize + aPointSizeInc);
210 my1DExtActor = SMESH_DeviceActor::New();
211 my1DExtActor->SetUserMatrix(aMatrix);
212 my1DExtActor->PickableOff();
213 my1DExtActor->SetHighlited(true);
214 my1DExtActor->SetVisibility(false);
215 my1DExtActor->SetProperty(my1DExtProp);
216 my1DExtActor->SetRepresentation(SMESH_DeviceActor::eInsideframe);
217 aFilter = my1DExtActor->GetExtractUnstructuredGrid();
218 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
219 aFilter->RegisterCellsWithType(VTK_LINE);
220 aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
223 //Definition 0D divice of the actor
224 //---------------------------------
225 myNodeProp = vtkProperty::New();
226 SMESH::GetColor( "SMESH", "node_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 0, 0 ) );
227 myNodeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
228 myNodeProp->SetPointSize(aPointSize);
230 myNodeActor = SMESH_DeviceActor::New();
231 myNodeActor->SetUserMatrix(aMatrix);
232 myNodeActor->SetStoreClippingMapping(true);
233 myNodeActor->PickableOff();
234 myNodeActor->SetVisibility(false);
235 myNodeActor->SetProperty(myNodeProp);
236 myNodeActor->SetRepresentation(SMESH_DeviceActor::ePoint);
237 aFilter = myNodeActor->GetExtractUnstructuredGrid();
238 aFilter->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
241 //Definition of Pickable and Highlitable engines
242 //----------------------------------------------
244 myBaseActor = SMESH_DeviceActor::New();
245 myBaseActor->SetUserMatrix(aMatrix);
246 myBaseActor->SetStoreGemetryMapping(true);
247 myBaseActor->GetProperty()->SetOpacity(0.0);
249 myPickableActor = myBaseActor;
251 myHighlightProp = vtkProperty::New();
252 myHighlightProp->SetAmbient(1.0);
253 myHighlightProp->SetDiffuse(0.0);
254 myHighlightProp->SetSpecular(0.0);
255 SMESH::GetColor( "SMESH", "selection_object_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
256 myHighlightProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
257 myHighlightProp->SetPointSize(aPointSize);
258 myHighlightProp->SetRepresentation(1);
260 myPreselectProp = vtkProperty::New();
261 myPreselectProp->SetAmbient(1.0);
262 myPreselectProp->SetDiffuse(0.0);
263 myPreselectProp->SetSpecular(0.0);
264 SMESH::GetColor( "SMESH", "highlight_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 255, 255 ) );
265 myPreselectProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
266 myPreselectProp->SetPointSize(aPointSize);
267 myPreselectProp->SetRepresentation(1);
269 myHighlitableActor = SMESH_DeviceActor::New();
270 myHighlitableActor->SetUserMatrix(aMatrix);
271 myHighlitableActor->PickableOff();
272 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
277 myControlMode = eNone;
278 myControlActor = my2DActor;
280 //Definition of myScalarBarActor
281 //------------------------------
282 myLookupTable = vtkLookupTable::New();
283 //Fix for Bug PAL5195 - SMESH764:
284 //Controls - Aspect Ratio: incorrect colors of the best and worst values
285 myLookupTable->SetHueRange(0.667,0.0);
287 myScalarBarActor = vtkScalarBarActor::New();
288 myScalarBarActor->SetVisibility(false);
289 myScalarBarActor->SetLookupTable(myLookupTable);
292 //Incorrect "Min value" in Scalar Bar in Mesh:
293 // myScalarBarActor->SetLabelFormat("%.4g");
294 // changes was commented because of regression bug IPAL 19981
296 mgr = SUIT_Session::session()->resourceMgr();
300 //Definition of points numbering pipeline
301 //---------------------------------------
302 myPointsNumDataSet = vtkUnstructuredGrid::New();
304 myPtsMaskPoints = vtkMaskPoints::New();
305 myPtsMaskPoints->SetInput(myPointsNumDataSet);
306 myPtsMaskPoints->SetOnRatio(1);
308 myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
309 myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
310 myPtsSelectVisiblePoints->SelectInvisibleOff();
311 myPtsSelectVisiblePoints->SetTolerance(0.1);
313 myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
314 myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
315 myPtsLabeledDataMapper->SetLabelFormat("%g");
316 myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
318 vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
319 aPtsTextProp->SetFontFamilyToTimes();
320 static int aPointsFontSize = 10;
321 aPtsTextProp->SetFontSize(aPointsFontSize);
322 aPtsTextProp->SetBold(1);
323 aPtsTextProp->SetItalic(0);
324 aPtsTextProp->SetShadow(0);
325 myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
326 aPtsTextProp->Delete();
328 myEntityMode = eAllEntity;
330 myIsPointsLabeled = false;
332 myPointLabels = vtkActor2D::New();
333 myPointLabels->SetMapper(myPtsLabeledDataMapper);
334 myPointLabels->GetProperty()->SetColor(1,1,1);
335 myPointLabels->SetVisibility(myIsPointsLabeled);
338 //Definition of cells numbering pipeline
339 //---------------------------------------
340 myCellsNumDataSet = vtkUnstructuredGrid::New();
342 myCellCenters = vtkCellCenters::New();
343 myCellCenters->SetInput(myCellsNumDataSet);
345 myClsMaskPoints = vtkMaskPoints::New();
346 myClsMaskPoints->SetInput(myCellCenters->GetOutput());
347 myClsMaskPoints->SetOnRatio(1);
349 myClsSelectVisiblePoints = vtkSelectVisiblePoints::New();
350 myClsSelectVisiblePoints->SetInput(myClsMaskPoints->GetOutput());
351 myClsSelectVisiblePoints->SelectInvisibleOff();
352 myClsSelectVisiblePoints->SetTolerance(0.1);
354 myClsLabeledDataMapper = vtkLabeledDataMapper::New();
355 myClsLabeledDataMapper->SetInput(myClsSelectVisiblePoints->GetOutput());
356 myClsLabeledDataMapper->SetLabelFormat("%g");
357 myClsLabeledDataMapper->SetLabelModeToLabelScalars();
359 vtkTextProperty* aClsTextProp = vtkTextProperty::New();
360 aClsTextProp->SetFontFamilyToTimes();
361 static int aCellsFontSize = 12;
362 aClsTextProp->SetFontSize(aCellsFontSize);
363 aClsTextProp->SetBold(1);
364 aClsTextProp->SetItalic(0);
365 aClsTextProp->SetShadow(0);
366 myClsLabeledDataMapper->SetLabelTextProperty(aClsTextProp);
367 aClsTextProp->Delete();
369 myIsCellsLabeled = false;
371 myCellsLabels = vtkActor2D::New();
372 myCellsLabels->SetMapper(myClsLabeledDataMapper);
373 myCellsLabels->GetProperty()->SetColor(0,1,0);
374 myCellsLabels->SetVisibility(myIsCellsLabeled);
377 myImplicitBoolean = vtkImplicitBoolean::New();
378 myImplicitBoolean->SetOperationTypeToIntersection();
382 SMESH_ActorDef::~SMESH_ActorDef()
384 if(MYDEBUG) MESSAGE("~SMESH_ActorDef - "<<this);
386 myScalarBarActor->Delete();
387 myLookupTable->Delete();
389 mySurfaceProp->Delete();
390 myBackSurfaceProp->Delete();
392 myEdgeProp->Delete();
393 myHighlightProp->Delete();
394 myPreselectProp->Delete();
396 myNodeProp->Delete();
401 my1DExtProp->Delete();
402 my1DExtActor->Delete();
407 myNodeActor->Delete();
408 myBaseActor->Delete();
410 myHighlitableActor->Delete();
412 //Deleting of pints numbering pipeline
413 //---------------------------------------
414 myPointsNumDataSet->Delete();
416 // commented: porting to vtk 5.0
417 // myPtsLabeledDataMapper->RemoveAllInputs();
418 myPtsLabeledDataMapper->Delete();
420 // commented: porting to vtk 5.0
421 // myPtsSelectVisiblePoints->UnRegisterAllOutputs();
422 myPtsSelectVisiblePoints->Delete();
424 // commented: porting to vtk 5.0
425 // myPtsMaskPoints->UnRegisterAllOutputs();
426 myPtsMaskPoints->Delete();
428 myPointLabels->Delete();
431 //Deleting of cells numbering pipeline
432 //---------------------------------------
433 myCellsNumDataSet->Delete();
435 myClsLabeledDataMapper->RemoveAllInputs();
436 myClsLabeledDataMapper->Delete();
438 // commented: porting to vtk 5.0
439 // myClsSelectVisiblePoints->UnRegisterAllOutputs();
440 myClsSelectVisiblePoints->Delete();
442 // commented: porting to vtk 5.0
443 // myClsMaskPoints->UnRegisterAllOutputs();
444 myClsMaskPoints->Delete();
446 // commented: porting to vtk 5.0
447 // myCellCenters->UnRegisterAllOutputs();
448 myCellCenters->Delete();
450 myCellsLabels->Delete();
452 myImplicitBoolean->Delete();
454 myTimeStamp->Delete();
458 void SMESH_ActorDef::SetPointsLabeled( bool theIsPointsLabeled )
460 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
461 myIsPointsLabeled = theIsPointsLabeled && aGrid->GetNumberOfPoints();
463 if ( myIsPointsLabeled )
465 myPointsNumDataSet->ShallowCopy(aGrid);
466 vtkDataSet *aDataSet = myPointsNumDataSet;
468 int aNbElem = aDataSet->GetNumberOfPoints();
470 vtkIntArray *anArray = vtkIntArray::New();
471 anArray->SetNumberOfValues( aNbElem );
473 for ( int anId = 0; anId < aNbElem; anId++ )
475 int aSMDSId = myVisualObj->GetNodeObjId( anId );
476 anArray->SetValue( anId, aSMDSId );
479 aDataSet->GetPointData()->SetScalars( anArray );
481 myPtsMaskPoints->SetInput( aDataSet );
482 myPointLabels->SetVisibility( GetVisibility() );
486 myPointLabels->SetVisibility( false );
488 SetRepresentation(GetRepresentation());
489 myTimeStamp->Modified();
493 void SMESH_ActorDef::SetCellsLabeled(bool theIsCellsLabeled)
495 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
496 myIsCellsLabeled = theIsCellsLabeled && aGrid->GetNumberOfPoints();
497 if(myIsCellsLabeled){
498 myCellsNumDataSet->ShallowCopy(aGrid);
499 vtkDataSet *aDataSet = myCellsNumDataSet;
500 int aNbElem = aDataSet->GetNumberOfCells();
501 vtkIntArray *anArray = vtkIntArray::New();
502 anArray->SetNumberOfValues(aNbElem);
503 for(int anId = 0; anId < aNbElem; anId++){
504 int aSMDSId = myVisualObj->GetElemObjId(anId);
505 anArray->SetValue(anId,aSMDSId);
507 aDataSet->GetCellData()->SetScalars(anArray);
508 myCellCenters->SetInput(aDataSet);
509 myCellsLabels->SetVisibility(GetVisibility());
511 myCellsLabels->SetVisibility(false);
513 myTimeStamp->Modified();
519 SetControlMode(eControl theMode)
521 SetControlMode(theMode,true);
527 SetControlMode(eControl theMode,
528 bool theCheckEntityMode)
530 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
534 myControlMode = eNone;
535 theCheckEntityMode &= mgr->booleanValue( "SMESH", "display_entity", false );
537 my1DActor->GetMapper()->SetScalarVisibility(false);
538 my2DActor->GetMapper()->SetScalarVisibility(false);
539 my3DActor->GetMapper()->SetScalarVisibility(false);
540 myScalarBarActor->SetVisibility(false);
542 bool anIsScalarVisible = theMode > eNone;
544 if(anIsScalarVisible){
545 SMESH::Controls::FunctorPtr aFunctor;
549 SMESH::Controls::Length* aControl = new SMESH::Controls::Length();
550 aControl->SetPrecision( myControlsPrecision );
551 aFunctor.reset( aControl );
552 myControlActor = my1DActor;
557 aFunctor.reset(new SMESH::Controls::Length2D());
558 myControlActor = my2DActor;
562 aFunctor.reset(new SMESH::Controls::FreeBorders());
563 myControlActor = my1DActor;
566 aFunctor.reset(new SMESH::Controls::FreeEdges());
567 myControlActor = my2DActor;
569 case eMultiConnection:
570 aFunctor.reset(new SMESH::Controls::MultiConnection());
571 myControlActor = my1DActor;
573 case eMultiConnection2D:
574 aFunctor.reset(new SMESH::Controls::MultiConnection2D());
575 myControlActor = my2DActor;
579 SMESH::Controls::Area* aControl = new SMESH::Controls::Area();
580 aControl->SetPrecision( myControlsPrecision );
581 aFunctor.reset( aControl );
582 myControlActor = my2DActor;
587 SMESH::Controls::Taper* aControl = new SMESH::Controls::Taper();
588 aControl->SetPrecision( myControlsPrecision );
589 aFunctor.reset( aControl );
590 myControlActor = my2DActor;
595 SMESH::Controls::AspectRatio* aControl = new SMESH::Controls::AspectRatio();
596 aControl->SetPrecision( myControlsPrecision );
597 aFunctor.reset( aControl );
598 myControlActor = my2DActor;
603 SMESH::Controls::AspectRatio3D* aControl = new SMESH::Controls::AspectRatio3D();
604 aControl->SetPrecision( myControlsPrecision );
605 aFunctor.reset( aControl );
606 myControlActor = my3DActor;
611 SMESH::Controls::Volume* aControl = new SMESH::Controls::Volume();
612 aControl->SetPrecision( myControlsPrecision );
613 aFunctor.reset( aControl );
614 myControlActor = my3DActor;
619 SMESH::Controls::MinimumAngle* aControl = new SMESH::Controls::MinimumAngle();
620 aControl->SetPrecision( myControlsPrecision );
621 aFunctor.reset( aControl );
622 myControlActor = my2DActor;
627 SMESH::Controls::Warping* aControl = new SMESH::Controls::Warping();
628 aControl->SetPrecision( myControlsPrecision );
629 aFunctor.reset( aControl );
630 myControlActor = my2DActor;
635 SMESH::Controls::Skew* aControl = new SMESH::Controls::Skew();
636 aControl->SetPrecision( myControlsPrecision );
637 aFunctor.reset( aControl );
638 myControlActor = my2DActor;
645 vtkUnstructuredGrid* aGrid = myControlActor->GetUnstructuredGrid();
646 vtkIdType aNbCells = aGrid->GetNumberOfCells();
648 myControlMode = theMode;
649 switch(myControlMode){
652 my1DExtActor->SetExtControlMode(aFunctor);
655 case eMultiConnection2D:
656 my1DExtActor->SetExtControlMode(aFunctor,myScalarBarActor,myLookupTable);
659 myControlActor->SetControlMode(aFunctor,myScalarBarActor,myLookupTable);
663 if(theCheckEntityMode){
664 if(myControlActor == my1DActor)
665 SetEntityMode(eEdges);
666 else if(myControlActor == my2DActor){
667 switch(myControlMode){
670 case eMultiConnection2D:
671 //SetEntityMode(eEdges);
672 SetEntityMode(eFaces);
675 SetEntityMode(eFaces);
677 }else if(myControlActor == my3DActor)
678 SetEntityMode(eVolumes);
681 }else if(theCheckEntityMode){
682 myEntityMode = eAllEntity;
685 SetRepresentation(GetRepresentation());
687 myTimeStamp->Modified();
692 void SMESH_ActorDef::AddToRender(vtkRenderer* theRenderer){
693 SALOME_Actor::AddToRender(theRenderer);
695 theRenderer->AddActor(myNodeActor);
696 theRenderer->AddActor(myBaseActor);
698 theRenderer->AddActor(my3DActor);
699 theRenderer->AddActor(my2DActor);
701 theRenderer->AddActor(my1DActor);
702 theRenderer->AddActor(my1DExtActor);
704 theRenderer->AddActor(myHighlitableActor);
706 theRenderer->AddActor2D(myScalarBarActor);
708 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
709 myClsSelectVisiblePoints->SetRenderer(theRenderer);
711 theRenderer->AddActor2D(myPointLabels);
712 theRenderer->AddActor2D(myCellsLabels);
715 void SMESH_ActorDef::RemoveFromRender(vtkRenderer* theRenderer){
716 SALOME_Actor::RemoveFromRender(theRenderer);
718 theRenderer->RemoveActor(myNodeActor);
719 theRenderer->RemoveActor(myBaseActor);
721 theRenderer->RemoveActor(myHighlitableActor);
723 theRenderer->RemoveActor(my1DActor);
724 theRenderer->RemoveActor(my1DExtActor);
726 theRenderer->RemoveActor(my2DActor);
727 theRenderer->RemoveActor(my3DActor);
729 theRenderer->RemoveActor(myScalarBarActor);
730 theRenderer->RemoveActor(myPointLabels);
731 theRenderer->RemoveActor(myCellsLabels);
735 bool SMESH_ActorDef::Init(TVisualObjPtr theVisualObj,
736 const char* theEntry,
740 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry,"SMESH",theName);
744 myVisualObj = theVisualObj;
745 myVisualObj->Update(theIsClear);
747 myNodeActor->Init(myVisualObj,myImplicitBoolean);
748 myBaseActor->Init(myVisualObj,myImplicitBoolean);
750 myHighlitableActor->Init(myVisualObj,myImplicitBoolean);
752 my1DActor->Init(myVisualObj,myImplicitBoolean);
753 my1DExtActor->Init(myVisualObj,myImplicitBoolean);
755 my2DActor->Init(myVisualObj,myImplicitBoolean);
756 my3DActor->Init(myVisualObj,myImplicitBoolean);
758 my1DActor->GetMapper()->SetLookupTable(myLookupTable);
759 my1DExtActor->GetMapper()->SetLookupTable(myLookupTable);
761 my2DActor->GetMapper()->SetLookupTable(myLookupTable);
762 my3DActor->GetMapper()->SetLookupTable(myLookupTable);
764 vtkFloatingPointType aFactor, aUnits;
765 my2DActor->GetPolygonOffsetParameters(aFactor,aUnits);
766 my2DActor->SetPolygonOffsetParameters(aFactor,aUnits*0.75);
768 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
772 //SetIsShrunkable(theGrid->GetNumberOfCells() > 10);
773 SetIsShrunkable(true);
775 SetShrinkFactor( SMESH::GetFloat( "SMESH:shrink_coeff", 0.75 ) );
777 int aMode = mgr->integerValue( "SMESH", "display_mode" );
778 SetRepresentation(-1);
781 SetRepresentation(eEdge);
782 }else if(aMode == 1){
783 SetRepresentation(eSurface);
784 }else if(aMode == 2){
785 SetRepresentation(ePoint);
792 myTimeStamp->Modified();
798 vtkFloatingPointType* SMESH_ActorDef::GetBounds(){
799 return myNodeActor->GetBounds();
803 vtkDataSet* SMESH_ActorDef::GetInput(){
804 return GetUnstructuredGrid();
808 void SMESH_ActorDef::SetTransform(VTKViewer_Transform* theTransform){
809 Superclass::SetTransform(theTransform);
811 myNodeActor->SetTransform(theTransform);
812 myBaseActor->SetTransform(theTransform);
814 myHighlitableActor->SetTransform(theTransform);
816 my1DActor->SetTransform(theTransform);
817 my1DExtActor->SetTransform(theTransform);
819 my2DActor->SetTransform(theTransform);
820 my3DActor->SetTransform(theTransform);
826 void SMESH_ActorDef::SetMapper(vtkMapper* theMapper){
827 vtkLODActor::SetMapper(theMapper);
831 void SMESH_ActorDef::ShallowCopy(vtkProp *prop){
832 SALOME_Actor::ShallowCopy(prop);
836 vtkMapper* SMESH_ActorDef::GetMapper(){
837 return myPickableActor->GetMapper();
841 vtkUnstructuredGrid* SMESH_ActorDef::GetUnstructuredGrid(){
842 return myVisualObj->GetUnstructuredGrid();
846 bool SMESH_ActorDef::IsInfinitive(){
847 vtkDataSet *aDataSet = myPickableActor->GetUnstructuredGrid();
849 myIsInfinite = aDataSet->GetNumberOfCells() == 0 ||
850 aDataSet->GetNumberOfCells() == 1 &&
851 aDataSet->GetCell(0)->GetCellType() == VTK_VERTEX;
852 return SALOME_Actor::IsInfinitive();
856 void SMESH_ActorDef::SetIsShrunkable(bool theShrunkable){
857 if ( myIsShrinkable == theShrunkable )
859 myIsShrinkable = theShrunkable;
863 vtkFloatingPointType SMESH_ActorDef::GetShrinkFactor(){
864 return myBaseActor->GetShrinkFactor();
867 void SMESH_ActorDef::SetShrinkFactor(vtkFloatingPointType theValue){
868 myBaseActor->SetShrinkFactor(theValue);
870 my1DActor->SetShrinkFactor(theValue);
871 my1DExtActor->SetShrinkFactor(theValue);
873 my2DActor->SetShrinkFactor(theValue);
874 my3DActor->SetShrinkFactor(theValue);
879 void SMESH_ActorDef::SetShrink(){
880 if(!myIsShrinkable) return;
882 myBaseActor->SetShrink();
884 my1DActor->SetShrink();
885 my1DExtActor->SetShrink();
887 my2DActor->SetShrink();
888 my3DActor->SetShrink();
894 void SMESH_ActorDef::UnShrink(){
895 if(!myIsShrunk) return;
897 myBaseActor->UnShrink();
899 my1DActor->UnShrink();
900 my1DExtActor->UnShrink();
902 my2DActor->UnShrink();
903 my3DActor->UnShrink();
910 int SMESH_ActorDef::GetNodeObjId(int theVtkID){
911 return myPickableActor->GetNodeObjId(theVtkID);
914 vtkFloatingPointType* SMESH_ActorDef::GetNodeCoord(int theObjID){
915 return myPickableActor->GetNodeCoord(theObjID);
919 int SMESH_ActorDef::GetElemObjId(int theVtkID){
920 return myPickableActor->GetElemObjId(theVtkID);
923 vtkCell* SMESH_ActorDef::GetElemCell(int theObjID){
924 return myPickableActor->GetElemCell(theObjID);
928 void SMESH_ActorDef::SetVisibility(int theMode){
929 SetVisibility(theMode,true);
933 void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation){
934 SALOME_Actor::SetVisibility(theMode);
936 myNodeActor->VisibilityOff();
937 myBaseActor->VisibilityOff();
939 my1DActor->VisibilityOff();
940 my1DExtActor->VisibilityOff();
942 my2DActor->VisibilityOff();
943 my3DActor->VisibilityOff();
945 myScalarBarActor->VisibilityOff();
946 myPointLabels->VisibilityOff();
947 myCellsLabels->VisibilityOff();
950 if(theIsUpdateRepersentation)
951 SetRepresentation(GetRepresentation());
953 if(myControlMode != eNone){
954 switch(myControlMode){
957 my1DExtActor->VisibilityOn();
960 case eMultiConnection2D:
961 my1DExtActor->VisibilityOn();
963 if(myControlActor->GetUnstructuredGrid()->GetNumberOfCells())
964 myScalarBarActor->VisibilityOn();
968 if(myRepresentation != ePoint)
969 myPickableActor->VisibilityOn();
971 myNodeActor->VisibilityOn();
974 if(myEntityMode & eEdges){
975 my1DActor->VisibilityOn();
978 if(myEntityMode & eFaces){
979 my2DActor->VisibilityOn();
982 if(myEntityMode & eVolumes){
983 my3DActor->VisibilityOn();
986 if(myIsPointsLabeled){
987 myPointLabels->VisibilityOn();
988 myNodeActor->VisibilityOn();
992 myCellsLabels->VisibilityOn();
999 void SMESH_ActorDef::SetEntityMode(unsigned int theMode){
1000 myEntityState = eAllEntity;
1002 if(!myVisualObj->GetNbEntities(SMDSAbs_Edge)){
1003 myEntityState &= ~eEdges;
1007 if(!myVisualObj->GetNbEntities(SMDSAbs_Face)){
1008 myEntityState &= ~eFaces;
1012 if(!myVisualObj->GetNbEntities(SMDSAbs_Volume)){
1013 myEntityState &= ~eVolumes;
1014 theMode &= ~eVolumes;
1018 if(myVisualObj->GetNbEntities(SMDSAbs_Edge))
1021 if(myVisualObj->GetNbEntities(SMDSAbs_Face))
1024 if(myVisualObj->GetNbEntities(SMDSAbs_Volume))
1025 theMode |= eVolumes;
1028 myBaseActor->myGeomFilter->SetInside(myEntityMode != myEntityState);
1030 myEntityMode = theMode;
1031 VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
1032 aFilter = myBaseActor->GetExtractUnstructuredGrid();
1033 aFilter->ClearRegisteredCellsWithType();
1034 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
1036 if(myEntityMode & eEdges){
1037 if (MYDEBUG) MESSAGE("EDGES");
1038 aFilter->RegisterCellsWithType(VTK_LINE);
1039 aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
1042 if(myEntityMode & eFaces){
1043 if (MYDEBUG) MESSAGE("FACES");
1044 aFilter->RegisterCellsWithType(VTK_TRIANGLE);
1045 aFilter->RegisterCellsWithType(VTK_POLYGON);
1046 aFilter->RegisterCellsWithType(VTK_QUAD);
1047 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
1048 aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
1051 if(myEntityMode & eVolumes){
1052 if (MYDEBUG) MESSAGE("VOLUMES");
1053 aFilter->RegisterCellsWithType(VTK_TETRA);
1054 aFilter->RegisterCellsWithType(VTK_VOXEL);
1055 aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1056 aFilter->RegisterCellsWithType(VTK_WEDGE);
1057 aFilter->RegisterCellsWithType(VTK_PYRAMID);
1058 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
1059 aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
1060 aFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
1061 aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1064 if (MYDEBUG) MESSAGE(aFilter->GetOutput()->GetNumberOfCells());
1065 SetVisibility(GetVisibility(),false);
1068 void SMESH_ActorDef::SetRepresentation(int theMode){
1069 int aNbEdges = myVisualObj->GetNbEntities(SMDSAbs_Edge);
1070 int aNbFaces = myVisualObj->GetNbEntities(SMDSAbs_Face);
1071 int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume);
1073 myRepresentation = eSurface;
1074 if(!aNbFaces && !aNbVolumes && aNbEdges){
1075 myRepresentation = eEdge;
1076 }else if(!aNbFaces && !aNbVolumes && !aNbEdges){
1077 myRepresentation = ePoint;
1082 if(!aNbFaces && !aNbVolumes && !aNbEdges) return;
1085 if(!aNbFaces && !aNbVolumes) return;
1088 myRepresentation = theMode;
1091 if(!GetUnstructuredGrid()->GetNumberOfCells())
1092 myRepresentation = ePoint;
1095 if(myRepresentation == ePoint){
1103 myPickableActor = myBaseActor;
1104 myNodeActor->SetVisibility(false);
1105 vtkProperty *aProp = NULL, *aBackProp = NULL;
1106 SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1);
1107 switch(myRepresentation){
1109 myPickableActor = myNodeActor;
1110 myNodeActor->SetVisibility(true);
1112 aProp = aBackProp = myNodeProp;
1113 aReperesent = SMESH_DeviceActor::ePoint;
1116 aProp = aBackProp = myEdgeProp;
1117 aReperesent = SMESH_DeviceActor::eInsideframe;
1120 aProp = mySurfaceProp;
1121 aBackProp = myBackSurfaceProp;
1122 aReperesent = SMESH_DeviceActor::eSurface;
1126 my2DActor->SetProperty(aProp);
1127 my2DActor->SetBackfaceProperty(aBackProp);
1128 my2DActor->SetRepresentation(aReperesent);
1130 my3DActor->SetProperty(aProp);
1131 my3DActor->SetBackfaceProperty(aBackProp);
1132 my3DActor->SetRepresentation(aReperesent);
1134 my1DExtActor->SetVisibility(false);
1136 switch(myControlMode){
1138 case eMultiConnection:
1139 aProp = aBackProp = my1DProp;
1140 if(myRepresentation != ePoint)
1141 aReperesent = SMESH_DeviceActor::eInsideframe;
1145 my1DActor->SetProperty(aProp);
1146 my1DActor->SetBackfaceProperty(aBackProp);
1147 my1DActor->SetRepresentation(aReperesent);
1149 my1DExtActor->SetRepresentation(aReperesent);
1151 if(myIsPointsVisible)
1152 myPickableActor = myNodeActor;
1153 if(GetPointRepresentation())
1154 myNodeActor->SetVisibility(true);
1156 SetMapper(myPickableActor->GetMapper());
1158 SetVisibility(GetVisibility(),false);
1164 void SMESH_ActorDef::SetPointRepresentation(bool theIsPointsVisible){
1165 if ( myIsPointsVisible == theIsPointsVisible )
1167 myIsPointsVisible = theIsPointsVisible;
1168 SetRepresentation(GetRepresentation());
1171 bool SMESH_ActorDef::GetPointRepresentation(){
1172 return myIsPointsVisible || myIsPointsLabeled;
1176 void SMESH_ActorDef::UpdateHighlight(){
1177 myHighlitableActor->SetVisibility(false);
1178 myHighlitableActor->SetHighlited(false);
1180 if(myIsHighlighted){
1181 myHighlitableActor->SetProperty(myHighlightProp);
1182 }else if(myIsPreselected){
1183 myHighlitableActor->SetProperty(myPreselectProp);
1186 bool anIsVisible = GetVisibility();
1188 if(myIsHighlighted || myIsPreselected){
1189 if(GetUnstructuredGrid()->GetNumberOfCells()){
1190 myHighlitableActor->SetHighlited(anIsVisible);
1191 myHighlitableActor->SetVisibility(anIsVisible);
1192 myHighlitableActor->GetExtractUnstructuredGrid()->
1193 SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::eCells);
1194 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
1195 }else if(myRepresentation == ePoint || GetPointRepresentation()){
1196 myHighlitableActor->SetHighlited(anIsVisible);
1197 myHighlitableActor->GetExtractUnstructuredGrid()->
1198 SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
1199 myHighlitableActor->SetVisibility(anIsVisible);
1200 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::ePoint);
1206 void SMESH_ActorDef::highlight(bool theHighlight){
1207 if ( myIsHighlighted == theHighlight )
1209 myIsHighlighted = theHighlight;
1214 void SMESH_ActorDef::SetPreSelected(bool thePreselect){
1215 if ( myIsPreselected == thePreselect )
1217 myIsPreselected = thePreselect;
1223 int SMESH_ActorDef::RenderOpaqueGeometry(vtkViewport *vp)
1225 if (myPickableActor->GetIsOpaque())
1227 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1235 int SMESH_ActorDef::RenderTranslucentGeometry(vtkViewport *vp)
1237 if (!myPickableActor->GetIsOpaque())
1239 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1247 void SMESH_ActorDef::Render(vtkRenderer *ren){
1248 unsigned long aTime = myTimeStamp->GetMTime();
1249 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1250 unsigned long aClippingTime = myImplicitBoolean->GetMTime();
1251 if(anObjTime > aTime || aClippingTime > aTime)
1256 void SMESH_ActorDef::Update(){
1257 if(MYDEBUG) MESSAGE("SMESH_ActorDef::Update");
1259 if(GetControlMode() != eNone) {
1260 unsigned long aTime = myTimeStamp->GetMTime();
1261 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1262 if (anObjTime > aTime)
1263 SetControlMode(GetControlMode(),false);
1265 if(myIsPointsLabeled){
1266 SetPointsLabeled(myIsPointsLabeled);
1268 if(myIsCellsLabeled){
1269 SetCellsLabeled(myIsCellsLabeled);
1271 SetEntityMode(GetEntityMode());
1272 SetVisibility(GetVisibility());
1274 myTimeStamp->Modified();
1279 void SMESH_ActorDef::ReleaseGraphicsResources(vtkWindow *renWin){
1280 SALOME_Actor::ReleaseGraphicsResources(renWin);
1282 myPickableActor->ReleaseGraphicsResources(renWin);
1286 static void GetColor(vtkProperty *theProperty, vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1287 vtkFloatingPointType* aColor = theProperty->GetColor();
1294 void SMESH_ActorDef::SetOpacity(vtkFloatingPointType theValue){
1295 mySurfaceProp->SetOpacity(theValue);
1296 myBackSurfaceProp->SetOpacity(theValue);
1297 myEdgeProp->SetOpacity(theValue);
1298 myNodeProp->SetOpacity(theValue);
1300 my1DProp->SetOpacity(theValue);
1304 vtkFloatingPointType SMESH_ActorDef::GetOpacity(){
1305 return mySurfaceProp->GetOpacity();
1309 void SMESH_ActorDef::SetSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1310 mySurfaceProp->SetColor(r,g,b);
1314 void SMESH_ActorDef::GetSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1315 ::GetColor(mySurfaceProp,r,g,b);
1318 void SMESH_ActorDef::SetBackSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1319 myBackSurfaceProp->SetColor(r,g,b);
1323 void SMESH_ActorDef::GetBackSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1324 ::GetColor(myBackSurfaceProp,r,g,b);
1327 void SMESH_ActorDef::SetEdgeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1328 myEdgeProp->SetColor(r,g,b);
1329 my1DProp->SetColor(r,g,b);
1330 my1DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1334 void SMESH_ActorDef::GetEdgeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1335 ::GetColor(myEdgeProp,r,g,b);
1338 void SMESH_ActorDef::SetNodeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1339 myNodeProp->SetColor(r,g,b);
1343 void SMESH_ActorDef::GetNodeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1344 ::GetColor(myNodeProp,r,g,b);
1347 void SMESH_ActorDef::SetHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1348 myHighlightProp->SetColor(r,g,b);
1352 void SMESH_ActorDef::GetHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1353 ::GetColor(myHighlightProp,r,g,b);
1356 void SMESH_ActorDef::SetPreHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1357 myPreselectProp->SetColor(r,g,b);
1361 void SMESH_ActorDef::GetPreHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1362 ::GetColor(myPreselectProp,r,g,b);
1366 vtkFloatingPointType SMESH_ActorDef::GetLineWidth(){
1367 return myEdgeProp->GetLineWidth();
1371 void SMESH_ActorDef::SetLineWidth(vtkFloatingPointType theVal){
1372 myEdgeProp->SetLineWidth(theVal);
1374 my1DProp->SetLineWidth(theVal + aLineWidthInc);
1375 my1DExtProp->SetLineWidth(theVal + aLineWidthInc);
1381 void SMESH_ActorDef::SetNodeSize(vtkFloatingPointType theVal){
1382 myNodeProp->SetPointSize(theVal);
1383 myHighlightProp->SetPointSize(theVal);
1384 myPreselectProp->SetPointSize(theVal);
1386 my1DProp->SetPointSize(theVal + aPointSizeInc);
1387 my1DExtProp->SetPointSize(theVal + aPointSizeInc);
1392 vtkFloatingPointType SMESH_ActorDef::GetNodeSize(){
1393 return myNodeProp->GetPointSize();
1396 int SMESH_ActorDef::GetObjDimension( const int theObjId )
1398 return myVisualObj->GetElemDimension( theObjId );
1403 IsImplicitFunctionUsed() const
1405 return myBaseActor->IsImplicitFunctionUsed();
1410 SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
1412 myNodeActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1413 myBaseActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1415 myHighlitableActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1417 my1DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1418 my1DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1420 my2DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1421 my3DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1426 AddClippingPlane(vtkPlane* thePlane)
1429 myImplicitBoolean->GetFunction()->AddItem(thePlane);
1430 myCippingPlaneCont.push_back(thePlane);
1431 if(!IsImplicitFunctionUsed())
1432 SetImplicitFunctionUsed(true);
1434 return myCippingPlaneCont.size();
1439 RemoveAllClippingPlanes()
1441 myImplicitBoolean->GetFunction()->RemoveAllItems();
1442 myImplicitBoolean->GetFunction()->Modified(); // VTK bug
1443 myCippingPlaneCont.clear();
1444 SetImplicitFunctionUsed(false);
1449 GetNumberOfClippingPlanes()
1451 return myCippingPlaneCont.size();
1456 GetClippingPlane(vtkIdType theID)
1458 if(theID >= myCippingPlaneCont.size())
1460 return myCippingPlaneCont[theID].Get();
1464 static void ComputeBoundsParam(vtkDataSet* theDataSet,
1465 vtkFloatingPointType theDirection[3], vtkFloatingPointType theMinPnt[3],
1466 vtkFloatingPointType& theMaxBoundPrj, vtkFloatingPointType& theMinBoundPrj)
1468 vtkFloatingPointType aBounds[6];
1469 theDataSet->GetBounds(aBounds);
1471 //Enlarge bounds in order to avoid conflicts of precision
1472 for(int i = 0; i < 6; i += 2){
1473 static double EPS = 1.0E-3;
1474 vtkFloatingPointType aDelta = (aBounds[i+1] - aBounds[i])*EPS;
1475 aBounds[i] -= aDelta;
1476 aBounds[i+1] += aDelta;
1479 vtkFloatingPointType aBoundPoints[8][3] = { {aBounds[0],aBounds[2],aBounds[4]},
1480 {aBounds[1],aBounds[2],aBounds[4]},
1481 {aBounds[0],aBounds[3],aBounds[4]},
1482 {aBounds[1],aBounds[3],aBounds[4]},
1483 {aBounds[0],aBounds[2],aBounds[5]},
1484 {aBounds[1],aBounds[2],aBounds[5]},
1485 {aBounds[0],aBounds[3],aBounds[5]},
1486 {aBounds[1],aBounds[3],aBounds[5]}};
1488 int aMaxId = 0, aMinId = aMaxId;
1489 theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
1490 theMinBoundPrj = theMaxBoundPrj;
1491 for(int i = 1; i < 8; i++){
1492 vtkFloatingPointType aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
1493 if(theMaxBoundPrj < aTmp){
1494 theMaxBoundPrj = aTmp;
1497 if(theMinBoundPrj > aTmp){
1498 theMinBoundPrj = aTmp;
1502 vtkFloatingPointType *aMinPnt = aBoundPoints[aMaxId];
1503 theMinPnt[0] = aMinPnt[0];
1504 theMinPnt[1] = aMinPnt[1];
1505 theMinPnt[2] = aMinPnt[2];
1509 static void DistanceToPosition(vtkDataSet* theDataSet,
1510 vtkFloatingPointType theDirection[3], vtkFloatingPointType theDist, vtkFloatingPointType thePos[3])
1512 vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1513 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1514 vtkFloatingPointType aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
1515 thePos[0] = aMinPnt[0]-theDirection[0]*aLength;
1516 thePos[1] = aMinPnt[1]-theDirection[1]*aLength;
1517 thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
1521 static void PositionToDistance(vtkDataSet* theDataSet,
1522 vtkFloatingPointType theDirection[3], vtkFloatingPointType thePos[3], vtkFloatingPointType& theDist)
1524 vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1525 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1526 vtkFloatingPointType aPrj = vtkMath::Dot(theDirection,thePos);
1527 theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
1531 void SMESH_ActorDef::SetPlaneParam(vtkFloatingPointType theDir[3], vtkFloatingPointType theDist, vtkPlane* thePlane)
1533 thePlane->SetNormal(theDir);
1534 vtkFloatingPointType anOrigin[3];
1535 ::DistanceToPosition(GetUnstructuredGrid(),theDir,theDist,anOrigin);
1536 thePlane->SetOrigin(anOrigin);
1540 void SMESH_ActorDef::GetPlaneParam(vtkFloatingPointType theDir[3], vtkFloatingPointType& theDist, vtkPlane* thePlane)
1542 thePlane->GetNormal(theDir);
1544 vtkFloatingPointType anOrigin[3];
1545 thePlane->GetOrigin(anOrigin);
1546 ::PositionToDistance(GetUnstructuredGrid(),theDir,anOrigin,theDist);
1549 void SMESH_ActorDef::UpdateScalarBar()
1551 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
1555 vtkTextProperty* aScalarBarTitleProp = vtkTextProperty::New();
1557 QColor aTColor = mgr->colorValue( "SMESH", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
1558 aScalarBarTitleProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1560 aScalarBarTitleProp->SetFontFamilyToArial();
1562 if ( mgr->hasValue( "SMESH", "scalar_bar_title_font" ) )
1564 QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
1565 if ( f.family() == "Arial" )
1566 aScalarBarTitleProp->SetFontFamilyToArial();
1567 else if ( f.family() == "Courier" )
1568 aScalarBarTitleProp->SetFontFamilyToCourier();
1569 else if ( f.family() == "Times" )
1570 aScalarBarTitleProp->SetFontFamilyToTimes();
1573 aScalarBarTitleProp->BoldOn();
1575 aScalarBarTitleProp->BoldOff();
1578 aScalarBarTitleProp->ItalicOn();
1580 aScalarBarTitleProp->ItalicOff();
1582 if ( f.underline() )
1583 aScalarBarTitleProp->ShadowOn();
1585 aScalarBarTitleProp->ShadowOff();
1588 myScalarBarActor->SetTitleTextProperty( aScalarBarTitleProp );
1589 aScalarBarTitleProp->Delete();
1591 vtkTextProperty* aScalarBarLabelProp = vtkTextProperty::New();
1593 aTColor = mgr->colorValue( "SMESH", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
1594 aScalarBarLabelProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1596 aScalarBarLabelProp->SetFontFamilyToArial();
1597 if( mgr->hasValue( "SMESH", "scalar_bar_label_font" ) )
1599 QFont f = mgr->fontValue( "SMESH", "scalar_bar_label_font" );
1600 if( f.family() == "Arial" )
1601 aScalarBarLabelProp->SetFontFamilyToArial();
1602 else if( f.family() == "Courier" )
1603 aScalarBarLabelProp->SetFontFamilyToCourier();
1604 else if( f.family() == "Times" )
1605 aScalarBarLabelProp->SetFontFamilyToTimes();
1608 aScalarBarLabelProp->BoldOn();
1610 aScalarBarLabelProp->BoldOff();
1613 aScalarBarLabelProp->ItalicOn();
1615 aScalarBarLabelProp->ItalicOff();
1618 aScalarBarLabelProp->ShadowOn();
1620 aScalarBarLabelProp->ShadowOff();
1623 myScalarBarActor->SetLabelTextProperty( aScalarBarLabelProp );
1624 aScalarBarLabelProp->Delete();
1626 bool horiz = ( mgr->integerValue( "SMESH", "scalar_bar_orientation" ) == 1 );
1627 QString name = QString( "scalar_bar_%1_" ).arg( horiz ? "horizontal" : "vertical" );
1629 myScalarBarActor->SetOrientationToHorizontal();
1631 myScalarBarActor->SetOrientationToVertical();
1634 vtkFloatingPointType aXVal = horiz ? 0.20 : 0.01;
1635 if( mgr->hasValue( "SMESH", name + "x" ) )
1636 aXVal = mgr->doubleValue( "SMESH", name + "x", aXVal );
1638 vtkFloatingPointType aYVal = horiz ? 0.01 : 0.1;
1639 if( mgr->hasValue( "SMESH", name + "y" ) )
1640 aYVal = mgr->doubleValue( "SMESH", name + "y", aYVal );
1641 myScalarBarActor->SetPosition( aXVal, aYVal );
1643 vtkFloatingPointType aWVal = horiz ? 0.60 : 0.10;
1644 if( mgr->hasValue( "SMESH", name + "width" ) )
1645 aWVal = mgr->doubleValue( "SMESH", name + "width", aWVal );
1646 myScalarBarActor->SetWidth( aWVal );
1648 vtkFloatingPointType aHVal = horiz ? 0.12 : 0.80;
1649 if( mgr->hasValue( "SMESH", name + "height" ) )
1650 aHVal = mgr->doubleValue( "SMESH", name + "height", aHVal );
1651 myScalarBarActor->SetHeight( aHVal );
1654 if( mgr->hasValue( "SMESH", "scalar_bar_num_labels" ) )
1655 anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_labels", anIntVal );
1656 myScalarBarActor->SetNumberOfLabels( anIntVal == 0 ? 5: anIntVal );
1659 if( mgr->hasValue( "SMESH", "scalar_bar_num_colors" ) )
1660 anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_colors", anIntVal );
1661 myScalarBarActor->SetMaximumNumberOfColors( anIntVal == 0 ? 64 : anIntVal );