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_CONVEX_POINT_SET);
173 //Definition 1D divice of the actor
174 //---------------------------------
175 myEdgeProp = vtkProperty::New();
176 myEdgeProp->SetAmbient(1.0);
177 myEdgeProp->SetDiffuse(0.0);
178 myEdgeProp->SetSpecular(0.0);
179 SMESH::GetColor( "SMESH", "outline_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
180 myEdgeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
181 myEdgeProp->SetLineWidth(aLineWidth);
183 my1DActor = SMESH_DeviceActor::New();
184 my1DActor->SetUserMatrix(aMatrix);
185 my1DActor->PickableOff();
186 my1DActor->SetHighlited(true);
187 my1DActor->SetProperty(myEdgeProp);
188 my1DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
189 aFilter = my1DActor->GetExtractUnstructuredGrid();
190 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
191 aFilter->RegisterCellsWithType(VTK_LINE);
192 aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
194 my1DProp = vtkProperty::New();
195 my1DProp->DeepCopy(myEdgeProp);
196 my1DProp->SetLineWidth(aLineWidth + aLineWidthInc);
197 my1DProp->SetPointSize(aPointSize);
199 my1DExtProp = vtkProperty::New();
200 my1DExtProp->DeepCopy(myEdgeProp);
201 anRGB[0] = 1 - anRGB[0];
202 anRGB[1] = 1 - anRGB[1];
203 anRGB[2] = 1 - anRGB[2];
204 my1DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
205 my1DExtProp->SetLineWidth(aLineWidth + aLineWidthInc);
206 my1DExtProp->SetPointSize(aPointSize + aPointSizeInc);
208 my1DExtActor = SMESH_DeviceActor::New();
209 my1DExtActor->SetUserMatrix(aMatrix);
210 my1DExtActor->PickableOff();
211 my1DExtActor->SetHighlited(true);
212 my1DExtActor->SetVisibility(false);
213 my1DExtActor->SetProperty(my1DExtProp);
214 my1DExtActor->SetRepresentation(SMESH_DeviceActor::eInsideframe);
215 aFilter = my1DExtActor->GetExtractUnstructuredGrid();
216 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
217 aFilter->RegisterCellsWithType(VTK_LINE);
218 aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
221 //Definition 0D divice of the actor
222 //---------------------------------
223 myNodeProp = vtkProperty::New();
224 SMESH::GetColor( "SMESH", "node_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 0, 0 ) );
225 myNodeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
226 myNodeProp->SetPointSize(aPointSize);
228 myNodeActor = SMESH_DeviceActor::New();
229 myNodeActor->SetUserMatrix(aMatrix);
230 myNodeActor->SetStoreClippingMapping(true);
231 myNodeActor->PickableOff();
232 myNodeActor->SetVisibility(false);
233 myNodeActor->SetProperty(myNodeProp);
234 myNodeActor->SetRepresentation(SMESH_DeviceActor::ePoint);
235 aFilter = myNodeActor->GetExtractUnstructuredGrid();
236 aFilter->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
239 //Definition of Pickable and Highlitable engines
240 //----------------------------------------------
242 myBaseActor = SMESH_DeviceActor::New();
243 myBaseActor->SetUserMatrix(aMatrix);
244 myBaseActor->SetStoreGemetryMapping(true);
245 myBaseActor->GetProperty()->SetOpacity(0.0);
247 myPickableActor = myBaseActor;
249 myHighlightProp = vtkProperty::New();
250 myHighlightProp->SetAmbient(1.0);
251 myHighlightProp->SetDiffuse(0.0);
252 myHighlightProp->SetSpecular(0.0);
253 SMESH::GetColor( "SMESH", "selection_object_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
254 myHighlightProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
255 myHighlightProp->SetPointSize(aPointSize);
256 myHighlightProp->SetRepresentation(1);
258 myPreselectProp = vtkProperty::New();
259 myPreselectProp->SetAmbient(1.0);
260 myPreselectProp->SetDiffuse(0.0);
261 myPreselectProp->SetSpecular(0.0);
262 SMESH::GetColor( "SMESH", "highlight_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 255, 255 ) );
263 myPreselectProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
264 myPreselectProp->SetPointSize(aPointSize);
265 myPreselectProp->SetRepresentation(1);
267 myHighlitableActor = SMESH_DeviceActor::New();
268 myHighlitableActor->SetUserMatrix(aMatrix);
269 myHighlitableActor->PickableOff();
270 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
275 myControlMode = eNone;
276 myControlActor = my2DActor;
278 //Definition of myScalarBarActor
279 //------------------------------
280 myLookupTable = vtkLookupTable::New();
281 //Fix for Bug PAL5195 - SMESH764:
282 //Controls - Aspect Ratio: incorrect colors of the best and worst values
283 myLookupTable->SetHueRange(0.667,0.0);
285 myScalarBarActor = vtkScalarBarActor::New();
286 myScalarBarActor->SetVisibility(false);
287 myScalarBarActor->SetLookupTable(myLookupTable);
290 //Incorrect "Min value" in Scalar Bar in Mesh:
291 myScalarBarActor->SetLabelFormat("%.4g");
293 mgr = SUIT_Session::session()->resourceMgr();
297 //Definition of points numbering pipeline
298 //---------------------------------------
299 myPointsNumDataSet = vtkUnstructuredGrid::New();
301 myPtsMaskPoints = vtkMaskPoints::New();
302 myPtsMaskPoints->SetInput(myPointsNumDataSet);
303 myPtsMaskPoints->SetOnRatio(1);
305 myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
306 myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
307 myPtsSelectVisiblePoints->SelectInvisibleOff();
308 myPtsSelectVisiblePoints->SetTolerance(0.1);
310 myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
311 myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
312 myPtsLabeledDataMapper->SetLabelFormat("%g");
313 myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
315 vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
316 aPtsTextProp->SetFontFamilyToTimes();
317 static int aPointsFontSize = 10;
318 aPtsTextProp->SetFontSize(aPointsFontSize);
319 aPtsTextProp->SetBold(1);
320 aPtsTextProp->SetItalic(0);
321 aPtsTextProp->SetShadow(0);
322 myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
323 aPtsTextProp->Delete();
325 myEntityMode = eAllEntity;
327 myIsPointsLabeled = false;
329 myPointLabels = vtkActor2D::New();
330 myPointLabels->SetMapper(myPtsLabeledDataMapper);
331 myPointLabels->GetProperty()->SetColor(1,1,1);
332 myPointLabels->SetVisibility(myIsPointsLabeled);
335 //Definition of cells numbering pipeline
336 //---------------------------------------
337 myCellsNumDataSet = vtkUnstructuredGrid::New();
339 myCellCenters = vtkCellCenters::New();
340 myCellCenters->SetInput(myCellsNumDataSet);
342 myClsMaskPoints = vtkMaskPoints::New();
343 myClsMaskPoints->SetInput(myCellCenters->GetOutput());
344 myClsMaskPoints->SetOnRatio(1);
346 myClsSelectVisiblePoints = vtkSelectVisiblePoints::New();
347 myClsSelectVisiblePoints->SetInput(myClsMaskPoints->GetOutput());
348 myClsSelectVisiblePoints->SelectInvisibleOff();
349 myClsSelectVisiblePoints->SetTolerance(0.1);
351 myClsLabeledDataMapper = vtkLabeledDataMapper::New();
352 myClsLabeledDataMapper->SetInput(myClsSelectVisiblePoints->GetOutput());
353 myClsLabeledDataMapper->SetLabelFormat("%g");
354 myClsLabeledDataMapper->SetLabelModeToLabelScalars();
356 vtkTextProperty* aClsTextProp = vtkTextProperty::New();
357 aClsTextProp->SetFontFamilyToTimes();
358 static int aCellsFontSize = 12;
359 aClsTextProp->SetFontSize(aCellsFontSize);
360 aClsTextProp->SetBold(1);
361 aClsTextProp->SetItalic(0);
362 aClsTextProp->SetShadow(0);
363 myClsLabeledDataMapper->SetLabelTextProperty(aClsTextProp);
364 aClsTextProp->Delete();
366 myIsCellsLabeled = false;
368 myCellsLabels = vtkActor2D::New();
369 myCellsLabels->SetMapper(myClsLabeledDataMapper);
370 myCellsLabels->GetProperty()->SetColor(0,1,0);
371 myCellsLabels->SetVisibility(myIsCellsLabeled);
374 myImplicitBoolean = vtkImplicitBoolean::New();
375 myImplicitBoolean->SetOperationTypeToIntersection();
379 SMESH_ActorDef::~SMESH_ActorDef()
381 if(MYDEBUG) MESSAGE("~SMESH_ActorDef - "<<this);
383 myScalarBarActor->Delete();
384 myLookupTable->Delete();
386 mySurfaceProp->Delete();
387 myBackSurfaceProp->Delete();
389 myEdgeProp->Delete();
390 myHighlightProp->Delete();
391 myPreselectProp->Delete();
393 myNodeProp->Delete();
398 my1DExtProp->Delete();
399 my1DExtActor->Delete();
404 myNodeActor->Delete();
405 myBaseActor->Delete();
407 myHighlitableActor->Delete();
409 //Deleting of pints numbering pipeline
410 //---------------------------------------
411 myPointsNumDataSet->Delete();
413 // commented: porting to vtk 5.0
414 // myPtsLabeledDataMapper->RemoveAllInputs();
415 myPtsLabeledDataMapper->Delete();
417 // commented: porting to vtk 5.0
418 // myPtsSelectVisiblePoints->UnRegisterAllOutputs();
419 myPtsSelectVisiblePoints->Delete();
421 // commented: porting to vtk 5.0
422 // myPtsMaskPoints->UnRegisterAllOutputs();
423 myPtsMaskPoints->Delete();
425 myPointLabels->Delete();
428 //Deleting of cells numbering pipeline
429 //---------------------------------------
430 myCellsNumDataSet->Delete();
432 myClsLabeledDataMapper->RemoveAllInputs();
433 myClsLabeledDataMapper->Delete();
435 // commented: porting to vtk 5.0
436 // myClsSelectVisiblePoints->UnRegisterAllOutputs();
437 myClsSelectVisiblePoints->Delete();
439 // commented: porting to vtk 5.0
440 // myClsMaskPoints->UnRegisterAllOutputs();
441 myClsMaskPoints->Delete();
443 // commented: porting to vtk 5.0
444 // myCellCenters->UnRegisterAllOutputs();
445 myCellCenters->Delete();
447 myCellsLabels->Delete();
449 myImplicitBoolean->Delete();
451 myTimeStamp->Delete();
455 void SMESH_ActorDef::SetPointsLabeled( bool theIsPointsLabeled )
457 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
458 myIsPointsLabeled = theIsPointsLabeled && aGrid->GetNumberOfPoints();
460 if ( myIsPointsLabeled )
462 myPointsNumDataSet->ShallowCopy(aGrid);
463 vtkDataSet *aDataSet = myPointsNumDataSet;
465 int aNbElem = aDataSet->GetNumberOfPoints();
467 vtkIntArray *anArray = vtkIntArray::New();
468 anArray->SetNumberOfValues( aNbElem );
470 for ( int anId = 0; anId < aNbElem; anId++ )
472 int aSMDSId = myVisualObj->GetNodeObjId( anId );
473 anArray->SetValue( anId, aSMDSId );
476 aDataSet->GetPointData()->SetScalars( anArray );
478 myPtsMaskPoints->SetInput( aDataSet );
479 myPointLabels->SetVisibility( GetVisibility() );
483 myPointLabels->SetVisibility( false );
485 SetRepresentation(GetRepresentation());
486 myTimeStamp->Modified();
490 void SMESH_ActorDef::SetCellsLabeled(bool theIsCellsLabeled)
492 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
493 myIsCellsLabeled = theIsCellsLabeled && aGrid->GetNumberOfPoints();
494 if(myIsCellsLabeled){
495 myCellsNumDataSet->ShallowCopy(aGrid);
496 vtkDataSet *aDataSet = myCellsNumDataSet;
497 int aNbElem = aDataSet->GetNumberOfCells();
498 vtkIntArray *anArray = vtkIntArray::New();
499 anArray->SetNumberOfValues(aNbElem);
500 for(int anId = 0; anId < aNbElem; anId++){
501 int aSMDSId = myVisualObj->GetElemObjId(anId);
502 anArray->SetValue(anId,aSMDSId);
504 aDataSet->GetCellData()->SetScalars(anArray);
505 myCellCenters->SetInput(aDataSet);
506 myCellsLabels->SetVisibility(GetVisibility());
508 myCellsLabels->SetVisibility(false);
510 myTimeStamp->Modified();
516 SetControlMode(eControl theMode)
518 SetControlMode(theMode,true);
524 SetControlMode(eControl theMode,
525 bool theCheckEntityMode)
527 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
531 myControlMode = eNone;
532 theCheckEntityMode &= mgr->booleanValue( "SMESH", "display_entity", false );
534 my1DActor->GetMapper()->SetScalarVisibility(false);
535 my2DActor->GetMapper()->SetScalarVisibility(false);
536 my3DActor->GetMapper()->SetScalarVisibility(false);
537 myScalarBarActor->SetVisibility(false);
539 bool anIsScalarVisible = theMode > eNone;
541 if(anIsScalarVisible){
542 SMESH::Controls::FunctorPtr aFunctor;
546 SMESH::Controls::Length* aControl = new SMESH::Controls::Length();
547 aControl->SetPrecision( myControlsPrecision );
548 aFunctor.reset( aControl );
549 myControlActor = my1DActor;
554 aFunctor.reset(new SMESH::Controls::Length2D());
555 myControlActor = my2DActor;
559 aFunctor.reset(new SMESH::Controls::FreeBorders());
560 myControlActor = my1DActor;
563 aFunctor.reset(new SMESH::Controls::FreeEdges());
564 myControlActor = my2DActor;
566 case eMultiConnection:
567 aFunctor.reset(new SMESH::Controls::MultiConnection());
568 myControlActor = my1DActor;
570 case eMultiConnection2D:
571 aFunctor.reset(new SMESH::Controls::MultiConnection2D());
572 myControlActor = my2DActor;
576 SMESH::Controls::Area* aControl = new SMESH::Controls::Area();
577 aControl->SetPrecision( myControlsPrecision );
578 aFunctor.reset( aControl );
579 myControlActor = my2DActor;
584 SMESH::Controls::Taper* aControl = new SMESH::Controls::Taper();
585 aControl->SetPrecision( myControlsPrecision );
586 aFunctor.reset( aControl );
587 myControlActor = my2DActor;
592 SMESH::Controls::AspectRatio* aControl = new SMESH::Controls::AspectRatio();
593 aControl->SetPrecision( myControlsPrecision );
594 aFunctor.reset( aControl );
595 myControlActor = my2DActor;
600 SMESH::Controls::AspectRatio3D* aControl = new SMESH::Controls::AspectRatio3D();
601 aControl->SetPrecision( myControlsPrecision );
602 aFunctor.reset( aControl );
603 myControlActor = my3DActor;
608 SMESH::Controls::Volume* aControl = new SMESH::Controls::Volume();
609 aControl->SetPrecision( myControlsPrecision );
610 aFunctor.reset( aControl );
611 myControlActor = my3DActor;
616 SMESH::Controls::MinimumAngle* aControl = new SMESH::Controls::MinimumAngle();
617 aControl->SetPrecision( myControlsPrecision );
618 aFunctor.reset( aControl );
619 myControlActor = my2DActor;
624 SMESH::Controls::Warping* aControl = new SMESH::Controls::Warping();
625 aControl->SetPrecision( myControlsPrecision );
626 aFunctor.reset( aControl );
627 myControlActor = my2DActor;
632 SMESH::Controls::Skew* aControl = new SMESH::Controls::Skew();
633 aControl->SetPrecision( myControlsPrecision );
634 aFunctor.reset( aControl );
635 myControlActor = my2DActor;
642 vtkUnstructuredGrid* aGrid = myControlActor->GetUnstructuredGrid();
643 vtkIdType aNbCells = aGrid->GetNumberOfCells();
645 myControlMode = theMode;
646 switch(myControlMode){
649 my1DExtActor->SetExtControlMode(aFunctor);
652 case eMultiConnection2D:
653 my1DExtActor->SetExtControlMode(aFunctor,myScalarBarActor,myLookupTable);
656 myControlActor->SetControlMode(aFunctor,myScalarBarActor,myLookupTable);
660 if(theCheckEntityMode){
661 if(myControlActor == my1DActor)
662 SetEntityMode(eEdges);
663 else if(myControlActor == my2DActor){
664 switch(myControlMode){
667 case eMultiConnection2D:
668 //SetEntityMode(eEdges);
669 SetEntityMode(eFaces);
672 SetEntityMode(eFaces);
674 }else if(myControlActor == my3DActor)
675 SetEntityMode(eVolumes);
678 }else if(theCheckEntityMode){
679 myEntityMode = eAllEntity;
682 SetRepresentation(GetRepresentation());
684 myTimeStamp->Modified();
689 void SMESH_ActorDef::AddToRender(vtkRenderer* theRenderer){
690 SALOME_Actor::AddToRender(theRenderer);
692 theRenderer->AddActor(myNodeActor);
693 theRenderer->AddActor(myBaseActor);
695 theRenderer->AddActor(my3DActor);
696 theRenderer->AddActor(my2DActor);
698 theRenderer->AddActor(my1DActor);
699 theRenderer->AddActor(my1DExtActor);
701 theRenderer->AddActor(myHighlitableActor);
703 theRenderer->AddActor2D(myScalarBarActor);
705 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
706 myClsSelectVisiblePoints->SetRenderer(theRenderer);
708 theRenderer->AddActor2D(myPointLabels);
709 theRenderer->AddActor2D(myCellsLabels);
712 void SMESH_ActorDef::RemoveFromRender(vtkRenderer* theRenderer){
713 SALOME_Actor::RemoveFromRender(theRenderer);
715 theRenderer->RemoveActor(myNodeActor);
716 theRenderer->RemoveActor(myBaseActor);
718 theRenderer->RemoveActor(myHighlitableActor);
720 theRenderer->RemoveActor(my1DActor);
721 theRenderer->RemoveActor(my1DExtActor);
723 theRenderer->RemoveActor(my2DActor);
724 theRenderer->RemoveActor(my3DActor);
726 theRenderer->RemoveActor(myScalarBarActor);
727 theRenderer->RemoveActor(myPointLabels);
728 theRenderer->RemoveActor(myCellsLabels);
732 bool SMESH_ActorDef::Init(TVisualObjPtr theVisualObj,
733 const char* theEntry,
737 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry,"SMESH",theName);
741 myVisualObj = theVisualObj;
742 myVisualObj->Update(theIsClear);
744 myNodeActor->Init(myVisualObj,myImplicitBoolean);
745 myBaseActor->Init(myVisualObj,myImplicitBoolean);
747 myHighlitableActor->Init(myVisualObj,myImplicitBoolean);
749 my1DActor->Init(myVisualObj,myImplicitBoolean);
750 my1DExtActor->Init(myVisualObj,myImplicitBoolean);
752 my2DActor->Init(myVisualObj,myImplicitBoolean);
753 my3DActor->Init(myVisualObj,myImplicitBoolean);
755 my1DActor->GetMapper()->SetLookupTable(myLookupTable);
756 my1DExtActor->GetMapper()->SetLookupTable(myLookupTable);
758 my2DActor->GetMapper()->SetLookupTable(myLookupTable);
759 my3DActor->GetMapper()->SetLookupTable(myLookupTable);
761 vtkFloatingPointType aFactor, aUnits;
762 my2DActor->GetPolygonOffsetParameters(aFactor,aUnits);
763 my2DActor->SetPolygonOffsetParameters(aFactor,aUnits*0.75);
765 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
769 //SetIsShrunkable(theGrid->GetNumberOfCells() > 10);
770 SetIsShrunkable(true);
772 SetShrinkFactor( SMESH::GetFloat( "SMESH:shrink_coeff", 0.75 ) );
774 int aMode = mgr->integerValue( "SMESH", "display_mode" );
775 SetRepresentation(-1);
778 SetRepresentation(eEdge);
779 }else if(aMode == 1){
780 SetRepresentation(eSurface);
781 }else if(aMode == 2){
782 SetRepresentation(ePoint);
789 myTimeStamp->Modified();
795 vtkFloatingPointType* SMESH_ActorDef::GetBounds(){
796 return myNodeActor->GetBounds();
800 vtkDataSet* SMESH_ActorDef::GetInput(){
801 return GetUnstructuredGrid();
805 void SMESH_ActorDef::SetTransform(VTKViewer_Transform* theTransform){
806 Superclass::SetTransform(theTransform);
808 myNodeActor->SetTransform(theTransform);
809 myBaseActor->SetTransform(theTransform);
811 myHighlitableActor->SetTransform(theTransform);
813 my1DActor->SetTransform(theTransform);
814 my1DExtActor->SetTransform(theTransform);
816 my2DActor->SetTransform(theTransform);
817 my3DActor->SetTransform(theTransform);
823 void SMESH_ActorDef::SetMapper(vtkMapper* theMapper){
824 vtkLODActor::SetMapper(theMapper);
828 void SMESH_ActorDef::ShallowCopy(vtkProp *prop){
829 SALOME_Actor::ShallowCopy(prop);
833 vtkMapper* SMESH_ActorDef::GetMapper(){
834 return myPickableActor->GetMapper();
838 vtkUnstructuredGrid* SMESH_ActorDef::GetUnstructuredGrid(){
839 return myVisualObj->GetUnstructuredGrid();
843 bool SMESH_ActorDef::IsInfinitive(){
844 vtkDataSet *aDataSet = myPickableActor->GetUnstructuredGrid();
846 myIsInfinite = aDataSet->GetNumberOfCells() == 0 ||
847 aDataSet->GetNumberOfCells() == 1 &&
848 aDataSet->GetCell(0)->GetCellType() == VTK_VERTEX;
849 return SALOME_Actor::IsInfinitive();
853 void SMESH_ActorDef::SetIsShrunkable(bool theShrunkable){
854 if ( myIsShrinkable == theShrunkable )
856 myIsShrinkable = theShrunkable;
860 vtkFloatingPointType SMESH_ActorDef::GetShrinkFactor(){
861 return myBaseActor->GetShrinkFactor();
864 void SMESH_ActorDef::SetShrinkFactor(vtkFloatingPointType theValue){
865 myBaseActor->SetShrinkFactor(theValue);
867 my1DActor->SetShrinkFactor(theValue);
868 my1DExtActor->SetShrinkFactor(theValue);
870 my2DActor->SetShrinkFactor(theValue);
871 my3DActor->SetShrinkFactor(theValue);
876 void SMESH_ActorDef::SetShrink(){
877 if(!myIsShrinkable) return;
879 myBaseActor->SetShrink();
881 my1DActor->SetShrink();
882 my1DExtActor->SetShrink();
884 my2DActor->SetShrink();
885 my3DActor->SetShrink();
891 void SMESH_ActorDef::UnShrink(){
892 if(!myIsShrunk) return;
894 myBaseActor->UnShrink();
896 my1DActor->UnShrink();
897 my1DExtActor->UnShrink();
899 my2DActor->UnShrink();
900 my3DActor->UnShrink();
907 int SMESH_ActorDef::GetNodeObjId(int theVtkID){
908 return myPickableActor->GetNodeObjId(theVtkID);
911 vtkFloatingPointType* SMESH_ActorDef::GetNodeCoord(int theObjID){
912 return myPickableActor->GetNodeCoord(theObjID);
916 int SMESH_ActorDef::GetElemObjId(int theVtkID){
917 return myPickableActor->GetElemObjId(theVtkID);
920 vtkCell* SMESH_ActorDef::GetElemCell(int theObjID){
921 return myPickableActor->GetElemCell(theObjID);
925 void SMESH_ActorDef::SetVisibility(int theMode){
926 SetVisibility(theMode,true);
930 void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation){
931 SALOME_Actor::SetVisibility(theMode);
933 myNodeActor->VisibilityOff();
934 myBaseActor->VisibilityOff();
936 my1DActor->VisibilityOff();
937 my1DExtActor->VisibilityOff();
939 my2DActor->VisibilityOff();
940 my3DActor->VisibilityOff();
942 myScalarBarActor->VisibilityOff();
943 myPointLabels->VisibilityOff();
944 myCellsLabels->VisibilityOff();
947 if(theIsUpdateRepersentation)
948 SetRepresentation(GetRepresentation());
950 if(myControlMode != eNone){
951 switch(myControlMode){
954 my1DExtActor->VisibilityOn();
957 case eMultiConnection2D:
958 my1DExtActor->VisibilityOn();
960 if(myControlActor->GetUnstructuredGrid()->GetNumberOfCells())
961 myScalarBarActor->VisibilityOn();
965 if(myRepresentation != ePoint)
966 myPickableActor->VisibilityOn();
968 myNodeActor->VisibilityOn();
971 if(myEntityMode & eEdges){
972 my1DActor->VisibilityOn();
975 if(myEntityMode & eFaces){
976 my2DActor->VisibilityOn();
979 if(myEntityMode & eVolumes){
980 my3DActor->VisibilityOn();
983 if(myIsPointsLabeled){
984 myPointLabels->VisibilityOn();
985 myNodeActor->VisibilityOn();
989 myCellsLabels->VisibilityOn();
996 void SMESH_ActorDef::SetEntityMode(unsigned int theMode){
997 myEntityState = eAllEntity;
999 if(!myVisualObj->GetNbEntities(SMDSAbs_Edge)){
1000 myEntityState &= ~eEdges;
1004 if(!myVisualObj->GetNbEntities(SMDSAbs_Face)){
1005 myEntityState &= ~eFaces;
1009 if(!myVisualObj->GetNbEntities(SMDSAbs_Volume)){
1010 myEntityState &= ~eVolumes;
1011 theMode &= ~eVolumes;
1015 if(myVisualObj->GetNbEntities(SMDSAbs_Edge))
1018 if(myVisualObj->GetNbEntities(SMDSAbs_Face))
1021 if(myVisualObj->GetNbEntities(SMDSAbs_Volume))
1022 theMode |= eVolumes;
1025 myBaseActor->myGeomFilter->SetInside(myEntityMode != myEntityState);
1027 myEntityMode = theMode;
1028 VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
1029 aFilter = myBaseActor->GetExtractUnstructuredGrid();
1030 aFilter->ClearRegisteredCellsWithType();
1031 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
1033 if(myEntityMode & eEdges){
1034 if (MYDEBUG) MESSAGE("EDGES");
1035 aFilter->RegisterCellsWithType(VTK_LINE);
1036 aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
1039 if(myEntityMode & eFaces){
1040 if (MYDEBUG) MESSAGE("FACES");
1041 aFilter->RegisterCellsWithType(VTK_TRIANGLE);
1042 aFilter->RegisterCellsWithType(VTK_POLYGON);
1043 aFilter->RegisterCellsWithType(VTK_QUAD);
1044 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
1045 aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
1048 if(myEntityMode & eVolumes){
1049 if (MYDEBUG) MESSAGE("VOLUMES");
1050 aFilter->RegisterCellsWithType(VTK_TETRA);
1051 aFilter->RegisterCellsWithType(VTK_VOXEL);
1052 aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1053 aFilter->RegisterCellsWithType(VTK_WEDGE);
1054 aFilter->RegisterCellsWithType(VTK_PYRAMID);
1055 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
1056 aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
1057 aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1060 if (MYDEBUG) MESSAGE(aFilter->GetOutput()->GetNumberOfCells());
1061 SetVisibility(GetVisibility(),false);
1064 void SMESH_ActorDef::SetRepresentation(int theMode){
1065 int aNbEdges = myVisualObj->GetNbEntities(SMDSAbs_Edge);
1066 int aNbFaces = myVisualObj->GetNbEntities(SMDSAbs_Face);
1067 int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume);
1069 myRepresentation = eSurface;
1070 if(!aNbFaces && !aNbVolumes && aNbEdges){
1071 myRepresentation = eEdge;
1072 }else if(!aNbFaces && !aNbVolumes && !aNbEdges){
1073 myRepresentation = ePoint;
1078 if(!aNbFaces && !aNbVolumes && !aNbEdges) return;
1081 if(!aNbFaces && !aNbVolumes) return;
1084 myRepresentation = theMode;
1087 if(!GetUnstructuredGrid()->GetNumberOfCells())
1088 myRepresentation = ePoint;
1091 if(myRepresentation == ePoint){
1099 myPickableActor = myBaseActor;
1100 myNodeActor->SetVisibility(false);
1101 vtkProperty *aProp = NULL, *aBackProp = NULL;
1102 SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1);
1103 switch(myRepresentation){
1105 myPickableActor = myNodeActor;
1106 myNodeActor->SetVisibility(true);
1108 aProp = aBackProp = myNodeProp;
1109 aReperesent = SMESH_DeviceActor::ePoint;
1112 aProp = aBackProp = myEdgeProp;
1113 aReperesent = SMESH_DeviceActor::eInsideframe;
1116 aProp = mySurfaceProp;
1117 aBackProp = myBackSurfaceProp;
1118 aReperesent = SMESH_DeviceActor::eSurface;
1122 my2DActor->SetProperty(aProp);
1123 my2DActor->SetBackfaceProperty(aBackProp);
1124 my2DActor->SetRepresentation(aReperesent);
1126 my3DActor->SetProperty(aProp);
1127 my3DActor->SetBackfaceProperty(aBackProp);
1128 my3DActor->SetRepresentation(aReperesent);
1130 my1DExtActor->SetVisibility(false);
1132 switch(myControlMode){
1134 case eMultiConnection:
1135 aProp = aBackProp = my1DProp;
1136 if(myRepresentation != ePoint)
1137 aReperesent = SMESH_DeviceActor::eInsideframe;
1141 my1DActor->SetProperty(aProp);
1142 my1DActor->SetBackfaceProperty(aBackProp);
1143 my1DActor->SetRepresentation(aReperesent);
1145 my1DExtActor->SetRepresentation(aReperesent);
1147 if(myIsPointsVisible)
1148 myPickableActor = myNodeActor;
1149 if(GetPointRepresentation())
1150 myNodeActor->SetVisibility(true);
1152 SetMapper(myPickableActor->GetMapper());
1154 SetVisibility(GetVisibility(),false);
1160 void SMESH_ActorDef::SetPointRepresentation(bool theIsPointsVisible){
1161 if ( myIsPointsVisible == theIsPointsVisible )
1163 myIsPointsVisible = theIsPointsVisible;
1164 SetRepresentation(GetRepresentation());
1167 bool SMESH_ActorDef::GetPointRepresentation(){
1168 return myIsPointsVisible || myIsPointsLabeled;
1172 void SMESH_ActorDef::UpdateHighlight(){
1173 myHighlitableActor->SetVisibility(false);
1174 myHighlitableActor->SetHighlited(false);
1176 if(myIsHighlighted){
1177 myHighlitableActor->SetProperty(myHighlightProp);
1178 }else if(myIsPreselected){
1179 myHighlitableActor->SetProperty(myPreselectProp);
1182 bool anIsVisible = GetVisibility();
1184 if(myIsHighlighted || myIsPreselected){
1185 if(GetUnstructuredGrid()->GetNumberOfCells()){
1186 myHighlitableActor->SetHighlited(anIsVisible);
1187 myHighlitableActor->SetVisibility(anIsVisible);
1188 myHighlitableActor->GetExtractUnstructuredGrid()->
1189 SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::eCells);
1190 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
1191 }else if(myRepresentation == ePoint || GetPointRepresentation()){
1192 myHighlitableActor->SetHighlited(anIsVisible);
1193 myHighlitableActor->GetExtractUnstructuredGrid()->
1194 SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
1195 myHighlitableActor->SetVisibility(anIsVisible);
1196 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::ePoint);
1202 void SMESH_ActorDef::highlight(bool theHighlight){
1203 if ( myIsHighlighted == theHighlight )
1205 myIsHighlighted = theHighlight;
1210 void SMESH_ActorDef::SetPreSelected(bool thePreselect){
1211 if ( myIsPreselected == thePreselect )
1213 myIsPreselected = thePreselect;
1219 int SMESH_ActorDef::RenderOpaqueGeometry(vtkViewport *vp)
1221 if (myPickableActor->GetIsOpaque())
1223 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1231 int SMESH_ActorDef::RenderTranslucentGeometry(vtkViewport *vp)
1233 if (!myPickableActor->GetIsOpaque())
1235 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1243 void SMESH_ActorDef::Render(vtkRenderer *ren){
1244 unsigned long aTime = myTimeStamp->GetMTime();
1245 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1246 unsigned long aClippingTime = myImplicitBoolean->GetMTime();
1247 if(anObjTime > aTime || aClippingTime > aTime)
1252 void SMESH_ActorDef::Update(){
1253 if(MYDEBUG) MESSAGE("SMESH_ActorDef::Update");
1255 if(GetControlMode() != eNone) {
1256 unsigned long aTime = myTimeStamp->GetMTime();
1257 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1258 if (anObjTime > aTime)
1259 SetControlMode(GetControlMode(),false);
1261 if(myIsPointsLabeled){
1262 SetPointsLabeled(myIsPointsLabeled);
1264 if(myIsCellsLabeled){
1265 SetCellsLabeled(myIsCellsLabeled);
1267 SetEntityMode(GetEntityMode());
1268 SetVisibility(GetVisibility());
1270 myTimeStamp->Modified();
1275 void SMESH_ActorDef::ReleaseGraphicsResources(vtkWindow *renWin){
1276 SALOME_Actor::ReleaseGraphicsResources(renWin);
1278 myPickableActor->ReleaseGraphicsResources(renWin);
1282 static void GetColor(vtkProperty *theProperty, vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1283 vtkFloatingPointType* aColor = theProperty->GetColor();
1290 void SMESH_ActorDef::SetOpacity(vtkFloatingPointType theValue){
1291 mySurfaceProp->SetOpacity(theValue);
1292 myBackSurfaceProp->SetOpacity(theValue);
1293 myEdgeProp->SetOpacity(theValue);
1294 myNodeProp->SetOpacity(theValue);
1296 my1DProp->SetOpacity(theValue);
1300 vtkFloatingPointType SMESH_ActorDef::GetOpacity(){
1301 return mySurfaceProp->GetOpacity();
1305 void SMESH_ActorDef::SetSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1306 mySurfaceProp->SetColor(r,g,b);
1310 void SMESH_ActorDef::GetSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1311 ::GetColor(mySurfaceProp,r,g,b);
1314 void SMESH_ActorDef::SetBackSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1315 myBackSurfaceProp->SetColor(r,g,b);
1319 void SMESH_ActorDef::GetBackSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1320 ::GetColor(myBackSurfaceProp,r,g,b);
1323 void SMESH_ActorDef::SetEdgeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1324 myEdgeProp->SetColor(r,g,b);
1325 my1DProp->SetColor(r,g,b);
1326 my1DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1330 void SMESH_ActorDef::GetEdgeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1331 ::GetColor(myEdgeProp,r,g,b);
1334 void SMESH_ActorDef::SetNodeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1335 myNodeProp->SetColor(r,g,b);
1339 void SMESH_ActorDef::GetNodeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1340 ::GetColor(myNodeProp,r,g,b);
1343 void SMESH_ActorDef::SetHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1344 myHighlightProp->SetColor(r,g,b);
1348 void SMESH_ActorDef::GetHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1349 ::GetColor(myHighlightProp,r,g,b);
1352 void SMESH_ActorDef::SetPreHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1353 myPreselectProp->SetColor(r,g,b);
1357 void SMESH_ActorDef::GetPreHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1358 ::GetColor(myPreselectProp,r,g,b);
1362 vtkFloatingPointType SMESH_ActorDef::GetLineWidth(){
1363 return myEdgeProp->GetLineWidth();
1367 void SMESH_ActorDef::SetLineWidth(vtkFloatingPointType theVal){
1368 myEdgeProp->SetLineWidth(theVal);
1370 my1DProp->SetLineWidth(theVal + aLineWidthInc);
1371 my1DExtProp->SetLineWidth(theVal + aLineWidthInc);
1377 void SMESH_ActorDef::SetNodeSize(vtkFloatingPointType theVal){
1378 myNodeProp->SetPointSize(theVal);
1379 myHighlightProp->SetPointSize(theVal);
1380 myPreselectProp->SetPointSize(theVal);
1382 my1DProp->SetPointSize(theVal + aPointSizeInc);
1383 my1DExtProp->SetPointSize(theVal + aPointSizeInc);
1388 vtkFloatingPointType SMESH_ActorDef::GetNodeSize(){
1389 return myNodeProp->GetPointSize();
1392 int SMESH_ActorDef::GetObjDimension( const int theObjId )
1394 return myVisualObj->GetElemDimension( theObjId );
1399 IsImplicitFunctionUsed() const
1401 return myBaseActor->IsImplicitFunctionUsed();
1406 SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
1408 myNodeActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1409 myBaseActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1411 myHighlitableActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1413 my1DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1414 my1DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1416 my2DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1417 my3DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1422 AddClippingPlane(vtkPlane* thePlane)
1425 myImplicitBoolean->GetFunction()->AddItem(thePlane);
1426 myCippingPlaneCont.push_back(thePlane);
1427 if(!IsImplicitFunctionUsed())
1428 SetImplicitFunctionUsed(true);
1430 return myCippingPlaneCont.size();
1435 RemoveAllClippingPlanes()
1437 myImplicitBoolean->GetFunction()->RemoveAllItems();
1438 myImplicitBoolean->GetFunction()->Modified(); // VTK bug
1439 myCippingPlaneCont.clear();
1440 SetImplicitFunctionUsed(false);
1445 GetNumberOfClippingPlanes()
1447 return myCippingPlaneCont.size();
1452 GetClippingPlane(vtkIdType theID)
1454 if(theID >= myCippingPlaneCont.size())
1456 return myCippingPlaneCont[theID].Get();
1460 static void ComputeBoundsParam(vtkDataSet* theDataSet,
1461 vtkFloatingPointType theDirection[3], vtkFloatingPointType theMinPnt[3],
1462 vtkFloatingPointType& theMaxBoundPrj, vtkFloatingPointType& theMinBoundPrj)
1464 vtkFloatingPointType aBounds[6];
1465 theDataSet->GetBounds(aBounds);
1467 //Enlarge bounds in order to avoid conflicts of precision
1468 for(int i = 0; i < 6; i += 2){
1469 static double EPS = 1.0E-3;
1470 vtkFloatingPointType aDelta = (aBounds[i+1] - aBounds[i])*EPS;
1471 aBounds[i] -= aDelta;
1472 aBounds[i+1] += aDelta;
1475 vtkFloatingPointType aBoundPoints[8][3] = { {aBounds[0],aBounds[2],aBounds[4]},
1476 {aBounds[1],aBounds[2],aBounds[4]},
1477 {aBounds[0],aBounds[3],aBounds[4]},
1478 {aBounds[1],aBounds[3],aBounds[4]},
1479 {aBounds[0],aBounds[2],aBounds[5]},
1480 {aBounds[1],aBounds[2],aBounds[5]},
1481 {aBounds[0],aBounds[3],aBounds[5]},
1482 {aBounds[1],aBounds[3],aBounds[5]}};
1484 int aMaxId = 0, aMinId = aMaxId;
1485 theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
1486 theMinBoundPrj = theMaxBoundPrj;
1487 for(int i = 1; i < 8; i++){
1488 vtkFloatingPointType aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
1489 if(theMaxBoundPrj < aTmp){
1490 theMaxBoundPrj = aTmp;
1493 if(theMinBoundPrj > aTmp){
1494 theMinBoundPrj = aTmp;
1498 vtkFloatingPointType *aMinPnt = aBoundPoints[aMaxId];
1499 theMinPnt[0] = aMinPnt[0];
1500 theMinPnt[1] = aMinPnt[1];
1501 theMinPnt[2] = aMinPnt[2];
1505 static void DistanceToPosition(vtkDataSet* theDataSet,
1506 vtkFloatingPointType theDirection[3], vtkFloatingPointType theDist, vtkFloatingPointType thePos[3])
1508 vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1509 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1510 vtkFloatingPointType aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
1511 thePos[0] = aMinPnt[0]-theDirection[0]*aLength;
1512 thePos[1] = aMinPnt[1]-theDirection[1]*aLength;
1513 thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
1517 static void PositionToDistance(vtkDataSet* theDataSet,
1518 vtkFloatingPointType theDirection[3], vtkFloatingPointType thePos[3], vtkFloatingPointType& theDist)
1520 vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1521 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1522 vtkFloatingPointType aPrj = vtkMath::Dot(theDirection,thePos);
1523 theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
1527 void SMESH_ActorDef::SetPlaneParam(vtkFloatingPointType theDir[3], vtkFloatingPointType theDist, vtkPlane* thePlane)
1529 thePlane->SetNormal(theDir);
1530 vtkFloatingPointType anOrigin[3];
1531 ::DistanceToPosition(GetUnstructuredGrid(),theDir,theDist,anOrigin);
1532 thePlane->SetOrigin(anOrigin);
1536 void SMESH_ActorDef::GetPlaneParam(vtkFloatingPointType theDir[3], vtkFloatingPointType& theDist, vtkPlane* thePlane)
1538 thePlane->GetNormal(theDir);
1540 vtkFloatingPointType anOrigin[3];
1541 thePlane->GetOrigin(anOrigin);
1542 ::PositionToDistance(GetUnstructuredGrid(),theDir,anOrigin,theDist);
1545 void SMESH_ActorDef::UpdateScalarBar()
1547 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
1551 vtkTextProperty* aScalarBarTitleProp = vtkTextProperty::New();
1553 QColor aTColor = mgr->colorValue( "SMESH", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
1554 aScalarBarTitleProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1556 aScalarBarTitleProp->SetFontFamilyToArial();
1558 if ( mgr->hasValue( "SMESH", "scalar_bar_title_font" ) )
1560 QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
1561 if ( f.family() == "Arial" )
1562 aScalarBarTitleProp->SetFontFamilyToArial();
1563 else if ( f.family() == "Courier" )
1564 aScalarBarTitleProp->SetFontFamilyToCourier();
1565 else if ( f.family() == "Times" )
1566 aScalarBarTitleProp->SetFontFamilyToTimes();
1569 aScalarBarTitleProp->BoldOn();
1571 aScalarBarTitleProp->BoldOff();
1574 aScalarBarTitleProp->ItalicOn();
1576 aScalarBarTitleProp->ItalicOff();
1578 if ( f.underline() )
1579 aScalarBarTitleProp->ShadowOn();
1581 aScalarBarTitleProp->ShadowOff();
1584 myScalarBarActor->SetTitleTextProperty( aScalarBarTitleProp );
1585 aScalarBarTitleProp->Delete();
1587 vtkTextProperty* aScalarBarLabelProp = vtkTextProperty::New();
1589 aTColor = mgr->colorValue( "SMESH", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
1590 aScalarBarLabelProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1592 aScalarBarLabelProp->SetFontFamilyToArial();
1593 if( mgr->hasValue( "SMESH", "scalar_bar_label_font" ) )
1595 QFont f = mgr->fontValue( "SMESH", "scalar_bar_label_font" );
1596 if( f.family() == "Arial" )
1597 aScalarBarLabelProp->SetFontFamilyToArial();
1598 else if( f.family() == "Courier" )
1599 aScalarBarLabelProp->SetFontFamilyToCourier();
1600 else if( f.family() == "Times" )
1601 aScalarBarLabelProp->SetFontFamilyToTimes();
1604 aScalarBarLabelProp->BoldOn();
1606 aScalarBarLabelProp->BoldOff();
1609 aScalarBarLabelProp->ItalicOn();
1611 aScalarBarLabelProp->ItalicOff();
1614 aScalarBarLabelProp->ShadowOn();
1616 aScalarBarLabelProp->ShadowOff();
1619 myScalarBarActor->SetLabelTextProperty( aScalarBarLabelProp );
1620 aScalarBarLabelProp->Delete();
1622 bool horiz = ( mgr->integerValue( "SMESH", "scalar_bar_orientation" ) == 1 );
1623 QString name = QString( "scalar_bar_%1_" ).arg( horiz ? "horizontal" : "vertical" );
1625 myScalarBarActor->SetOrientationToHorizontal();
1627 myScalarBarActor->SetOrientationToVertical();
1630 vtkFloatingPointType aXVal = horiz ? 0.20 : 0.01;
1631 if( mgr->hasValue( "SMESH", name + "x" ) )
1632 aXVal = mgr->doubleValue( "SMESH", name + "x", aXVal );
1634 vtkFloatingPointType aYVal = horiz ? 0.01 : 0.1;
1635 if( mgr->hasValue( "SMESH", name + "y" ) )
1636 aYVal = mgr->doubleValue( "SMESH", name + "y", aYVal );
1637 myScalarBarActor->SetPosition( aXVal, aYVal );
1639 vtkFloatingPointType aWVal = horiz ? 0.60 : 0.10;
1640 if( mgr->hasValue( "SMESH", name + "width" ) )
1641 aWVal = mgr->doubleValue( "SMESH", name + "width", aWVal );
1642 myScalarBarActor->SetWidth( aWVal );
1644 vtkFloatingPointType aHVal = horiz ? 0.12 : 0.80;
1645 if( mgr->hasValue( "SMESH", name + "height" ) )
1646 aHVal = mgr->doubleValue( "SMESH", name + "height", aHVal );
1647 myScalarBarActor->SetHeight( aHVal );
1650 if( mgr->hasValue( "SMESH", "scalar_bar_num_labels" ) )
1651 anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_labels", anIntVal );
1652 myScalarBarActor->SetNumberOfLabels( anIntVal == 0 ? 5: anIntVal );
1655 if( mgr->hasValue( "SMESH", "scalar_bar_num_colors" ) )
1656 anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_colors", anIntVal );
1657 myScalarBarActor->SetMaximumNumberOfColors( anIntVal == 0 ? 64 : anIntVal );