1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH OBJECT : interactive object for SMESH visualization
23 // File : SMESH_Actor.cxx
24 // Author : Nicolas REJNERI
28 #include "SMESH_ActorDef.h"
29 #include "SMESH_ActorUtils.h"
30 #include "SMESH_DeviceActor.h"
31 #include "SMESH_ControlsDef.hxx"
32 #include "VTKViewer_ExtractUnstructuredGrid.h"
34 #include "SUIT_Session.h"
35 #include "SUIT_ResourceMgr.h"
37 #include <qstringlist.h>
39 #include <vtkProperty.h>
40 #include <vtkTimeStamp.h>
41 #include <vtkObjectFactory.h>
42 #include <vtkShrinkPolyData.h>
43 #include <vtkMergeFilter.h>
45 #include <vtkMatrix4x4.h>
46 #include <vtkUnstructuredGrid.h>
47 #include <vtkPointData.h>
48 #include <vtkCellData.h>
50 #include <vtkMapper.h>
51 #include <vtkRenderer.h>
54 #include <vtkIdList.h>
55 #include <vtkIntArray.h>
57 #include <vtkActor2D.h>
58 #include <vtkProperty2D.h>
59 #include <vtkPolyData.h>
60 #include <vtkMaskPoints.h>
61 #include <vtkCellCenters.h>
62 #include <vtkTextProperty.h>
63 #include <vtkLabeledDataMapper.h>
64 #include <vtkSelectVisiblePoints.h>
66 #include <vtkScalarBarActor.h>
67 #include <vtkLookupTable.h>
71 #include <vtkImplicitBoolean.h>
72 #include <vtkImplicitFunctionCollection.h>
74 #include "utilities.h"
77 static int MYDEBUG = 1;
79 static int MYDEBUG = 0;
82 static int aLineWidthInc = 2;
83 static int aPointSizeInc = 2;
86 SMESH_ActorDef* SMESH_ActorDef::New(){
87 return new SMESH_ActorDef();
91 SMESH_Actor* SMESH_Actor::New(TVisualObjPtr theVisualObj,
96 SMESH_ActorDef* anActor = SMESH_ActorDef::New();
97 if(!anActor->Init(theVisualObj,theEntry,theName,theIsClear)){
102 anActor->UpdateScalarBar();
107 SMESH_ActorDef::SMESH_ActorDef()
109 if(MYDEBUG) MESSAGE("SMESH_ActorDef - "<<this);
111 myTimeStamp = vtkTimeStamp::New();
113 myIsPointsVisible = false;
115 myIsShrinkable = false;
118 myControlsPrecision = -1;
119 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
120 if ( mgr && mgr->booleanValue( "SMESH", "use_precision", false ) )
121 myControlsPrecision = (long)SMESH::GetFloat( "SMESH", "controls_precision", -1 );
123 vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
124 vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
126 vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
127 VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
129 //Definition 2D and 3D divices of the actor
130 //-----------------------------------------
131 vtkFloatingPointType anRGB[3] = {1,1,1};
132 mySurfaceProp = vtkProperty::New();
133 SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
134 mySurfaceProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
136 myBackSurfaceProp = vtkProperty::New();
137 SMESH::GetColor( "SMESH", "backface_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 0, 255 ) );
138 myBackSurfaceProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
140 my2DActor = SMESH_DeviceActor::New();
141 my2DActor->SetUserMatrix(aMatrix);
142 my2DActor->PickableOff();
143 my2DActor->SetProperty(mySurfaceProp);
144 my2DActor->SetBackfaceProperty(myBackSurfaceProp);
145 my2DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
146 aFilter = my2DActor->GetExtractUnstructuredGrid();
147 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
148 aFilter->RegisterCellsWithType(VTK_TRIANGLE);
149 aFilter->RegisterCellsWithType(VTK_POLYGON);
150 aFilter->RegisterCellsWithType(VTK_QUAD);
151 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
152 aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
154 my3DActor = SMESH_DeviceActor::New();
155 my3DActor->SetUserMatrix(aMatrix);
156 my3DActor->PickableOff();
157 my3DActor->SetProperty(mySurfaceProp);
158 my3DActor->SetBackfaceProperty(myBackSurfaceProp);
159 my3DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
160 aFilter = my3DActor->GetExtractUnstructuredGrid();
161 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
162 aFilter->RegisterCellsWithType(VTK_TETRA);
163 aFilter->RegisterCellsWithType(VTK_VOXEL);
164 aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
165 aFilter->RegisterCellsWithType(VTK_WEDGE);
166 aFilter->RegisterCellsWithType(VTK_PYRAMID);
167 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
168 aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
169 aFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
170 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");
292 // changes was commented because of regression bug IPAL 19981
294 mgr = SUIT_Session::session()->resourceMgr();
298 //Definition of points numbering pipeline
299 //---------------------------------------
300 myPointsNumDataSet = vtkUnstructuredGrid::New();
302 myPtsMaskPoints = vtkMaskPoints::New();
303 myPtsMaskPoints->SetInput(myPointsNumDataSet);
304 myPtsMaskPoints->SetOnRatio(1);
306 myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
307 myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
308 myPtsSelectVisiblePoints->SelectInvisibleOff();
309 myPtsSelectVisiblePoints->SetTolerance(0.1);
311 myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
312 myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
313 myPtsLabeledDataMapper->SetLabelFormat("%g");
314 myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
316 vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
317 aPtsTextProp->SetFontFamilyToTimes();
318 static int aPointsFontSize = 10;
319 aPtsTextProp->SetFontSize(aPointsFontSize);
320 aPtsTextProp->SetBold(1);
321 aPtsTextProp->SetItalic(0);
322 aPtsTextProp->SetShadow(0);
323 myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
324 aPtsTextProp->Delete();
326 myEntityMode = eAllEntity;
328 myIsPointsLabeled = false;
330 myPointLabels = vtkActor2D::New();
331 myPointLabels->SetMapper(myPtsLabeledDataMapper);
332 myPointLabels->GetProperty()->SetColor(1,1,1);
333 myPointLabels->SetVisibility(myIsPointsLabeled);
336 //Definition of cells numbering pipeline
337 //---------------------------------------
338 myCellsNumDataSet = vtkUnstructuredGrid::New();
340 myCellCenters = vtkCellCenters::New();
341 myCellCenters->SetInput(myCellsNumDataSet);
343 myClsMaskPoints = vtkMaskPoints::New();
344 myClsMaskPoints->SetInput(myCellCenters->GetOutput());
345 myClsMaskPoints->SetOnRatio(1);
347 myClsSelectVisiblePoints = vtkSelectVisiblePoints::New();
348 myClsSelectVisiblePoints->SetInput(myClsMaskPoints->GetOutput());
349 myClsSelectVisiblePoints->SelectInvisibleOff();
350 myClsSelectVisiblePoints->SetTolerance(0.1);
352 myClsLabeledDataMapper = vtkLabeledDataMapper::New();
353 myClsLabeledDataMapper->SetInput(myClsSelectVisiblePoints->GetOutput());
354 myClsLabeledDataMapper->SetLabelFormat("%g");
355 myClsLabeledDataMapper->SetLabelModeToLabelScalars();
357 vtkTextProperty* aClsTextProp = vtkTextProperty::New();
358 aClsTextProp->SetFontFamilyToTimes();
359 static int aCellsFontSize = 12;
360 aClsTextProp->SetFontSize(aCellsFontSize);
361 aClsTextProp->SetBold(1);
362 aClsTextProp->SetItalic(0);
363 aClsTextProp->SetShadow(0);
364 myClsLabeledDataMapper->SetLabelTextProperty(aClsTextProp);
365 aClsTextProp->Delete();
367 myIsCellsLabeled = false;
369 myCellsLabels = vtkActor2D::New();
370 myCellsLabels->SetMapper(myClsLabeledDataMapper);
371 myCellsLabels->GetProperty()->SetColor(0,1,0);
372 myCellsLabels->SetVisibility(myIsCellsLabeled);
375 myImplicitBoolean = vtkImplicitBoolean::New();
376 myImplicitBoolean->SetOperationTypeToIntersection();
380 SMESH_ActorDef::~SMESH_ActorDef()
382 if(MYDEBUG) MESSAGE("~SMESH_ActorDef - "<<this);
384 myScalarBarActor->Delete();
385 myLookupTable->Delete();
387 mySurfaceProp->Delete();
388 myBackSurfaceProp->Delete();
390 myEdgeProp->Delete();
391 myHighlightProp->Delete();
392 myPreselectProp->Delete();
394 myNodeProp->Delete();
399 my1DExtProp->Delete();
400 my1DExtActor->Delete();
405 myNodeActor->Delete();
406 myBaseActor->Delete();
408 myHighlitableActor->Delete();
410 //Deleting of pints numbering pipeline
411 //---------------------------------------
412 myPointsNumDataSet->Delete();
414 // commented: porting to vtk 5.0
415 // myPtsLabeledDataMapper->RemoveAllInputs();
416 myPtsLabeledDataMapper->Delete();
418 // commented: porting to vtk 5.0
419 // myPtsSelectVisiblePoints->UnRegisterAllOutputs();
420 myPtsSelectVisiblePoints->Delete();
422 // commented: porting to vtk 5.0
423 // myPtsMaskPoints->UnRegisterAllOutputs();
424 myPtsMaskPoints->Delete();
426 myPointLabels->Delete();
429 //Deleting of cells numbering pipeline
430 //---------------------------------------
431 myCellsNumDataSet->Delete();
433 myClsLabeledDataMapper->RemoveAllInputs();
434 myClsLabeledDataMapper->Delete();
436 // commented: porting to vtk 5.0
437 // myClsSelectVisiblePoints->UnRegisterAllOutputs();
438 myClsSelectVisiblePoints->Delete();
440 // commented: porting to vtk 5.0
441 // myClsMaskPoints->UnRegisterAllOutputs();
442 myClsMaskPoints->Delete();
444 // commented: porting to vtk 5.0
445 // myCellCenters->UnRegisterAllOutputs();
446 myCellCenters->Delete();
448 myCellsLabels->Delete();
450 myImplicitBoolean->Delete();
452 myTimeStamp->Delete();
456 void SMESH_ActorDef::SetPointsLabeled( bool theIsPointsLabeled )
458 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
459 myIsPointsLabeled = theIsPointsLabeled && aGrid->GetNumberOfPoints();
461 if ( myIsPointsLabeled )
463 myPointsNumDataSet->ShallowCopy(aGrid);
464 vtkDataSet *aDataSet = myPointsNumDataSet;
466 int aNbElem = aDataSet->GetNumberOfPoints();
468 vtkIntArray *anArray = vtkIntArray::New();
469 anArray->SetNumberOfValues( aNbElem );
471 for ( int anId = 0; anId < aNbElem; anId++ )
473 int aSMDSId = myVisualObj->GetNodeObjId( anId );
474 anArray->SetValue( anId, aSMDSId );
477 aDataSet->GetPointData()->SetScalars( anArray );
479 myPtsMaskPoints->SetInput( aDataSet );
480 myPointLabels->SetVisibility( GetVisibility() );
484 myPointLabels->SetVisibility( false );
486 SetRepresentation(GetRepresentation());
487 myTimeStamp->Modified();
491 void SMESH_ActorDef::SetCellsLabeled(bool theIsCellsLabeled)
493 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
494 myIsCellsLabeled = theIsCellsLabeled && aGrid->GetNumberOfPoints();
495 if(myIsCellsLabeled){
496 myCellsNumDataSet->ShallowCopy(aGrid);
497 vtkDataSet *aDataSet = myCellsNumDataSet;
498 int aNbElem = aDataSet->GetNumberOfCells();
499 vtkIntArray *anArray = vtkIntArray::New();
500 anArray->SetNumberOfValues(aNbElem);
501 for(int anId = 0; anId < aNbElem; anId++){
502 int aSMDSId = myVisualObj->GetElemObjId(anId);
503 anArray->SetValue(anId,aSMDSId);
505 aDataSet->GetCellData()->SetScalars(anArray);
506 myCellCenters->SetInput(aDataSet);
507 myCellsLabels->SetVisibility(GetVisibility());
509 myCellsLabels->SetVisibility(false);
511 myTimeStamp->Modified();
517 SetControlMode(eControl theMode)
519 SetControlMode(theMode,true);
525 SetControlMode(eControl theMode,
526 bool theCheckEntityMode)
528 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
532 myControlMode = eNone;
533 theCheckEntityMode &= mgr->booleanValue( "SMESH", "display_entity", false );
535 my1DActor->GetMapper()->SetScalarVisibility(false);
536 my2DActor->GetMapper()->SetScalarVisibility(false);
537 my3DActor->GetMapper()->SetScalarVisibility(false);
538 myScalarBarActor->SetVisibility(false);
540 bool anIsScalarVisible = theMode > eNone;
542 if(anIsScalarVisible){
543 SMESH::Controls::FunctorPtr aFunctor;
547 SMESH::Controls::Length* aControl = new SMESH::Controls::Length();
548 aControl->SetPrecision( myControlsPrecision );
549 aFunctor.reset( aControl );
550 myControlActor = my1DActor;
555 aFunctor.reset(new SMESH::Controls::Length2D());
556 myControlActor = my2DActor;
560 aFunctor.reset(new SMESH::Controls::FreeBorders());
561 myControlActor = my1DActor;
564 aFunctor.reset(new SMESH::Controls::FreeEdges());
565 myControlActor = my2DActor;
567 case eMultiConnection:
568 aFunctor.reset(new SMESH::Controls::MultiConnection());
569 myControlActor = my1DActor;
571 case eMultiConnection2D:
572 aFunctor.reset(new SMESH::Controls::MultiConnection2D());
573 myControlActor = my2DActor;
577 SMESH::Controls::Area* aControl = new SMESH::Controls::Area();
578 aControl->SetPrecision( myControlsPrecision );
579 aFunctor.reset( aControl );
580 myControlActor = my2DActor;
585 SMESH::Controls::Taper* aControl = new SMESH::Controls::Taper();
586 aControl->SetPrecision( myControlsPrecision );
587 aFunctor.reset( aControl );
588 myControlActor = my2DActor;
593 SMESH::Controls::AspectRatio* aControl = new SMESH::Controls::AspectRatio();
594 aControl->SetPrecision( myControlsPrecision );
595 aFunctor.reset( aControl );
596 myControlActor = my2DActor;
601 SMESH::Controls::AspectRatio3D* aControl = new SMESH::Controls::AspectRatio3D();
602 aControl->SetPrecision( myControlsPrecision );
603 aFunctor.reset( aControl );
604 myControlActor = my3DActor;
609 SMESH::Controls::Volume* aControl = new SMESH::Controls::Volume();
610 aControl->SetPrecision( myControlsPrecision );
611 aFunctor.reset( aControl );
612 myControlActor = my3DActor;
617 SMESH::Controls::MinimumAngle* aControl = new SMESH::Controls::MinimumAngle();
618 aControl->SetPrecision( myControlsPrecision );
619 aFunctor.reset( aControl );
620 myControlActor = my2DActor;
625 SMESH::Controls::Warping* aControl = new SMESH::Controls::Warping();
626 aControl->SetPrecision( myControlsPrecision );
627 aFunctor.reset( aControl );
628 myControlActor = my2DActor;
633 SMESH::Controls::Skew* aControl = new SMESH::Controls::Skew();
634 aControl->SetPrecision( myControlsPrecision );
635 aFunctor.reset( aControl );
636 myControlActor = my2DActor;
643 vtkUnstructuredGrid* aGrid = myControlActor->GetUnstructuredGrid();
644 vtkIdType aNbCells = aGrid->GetNumberOfCells();
646 myControlMode = theMode;
647 switch(myControlMode){
650 my1DExtActor->SetExtControlMode(aFunctor);
653 case eMultiConnection2D:
654 my1DExtActor->SetExtControlMode(aFunctor,myScalarBarActor,myLookupTable);
657 myControlActor->SetControlMode(aFunctor,myScalarBarActor,myLookupTable);
661 if(theCheckEntityMode){
662 if(myControlActor == my1DActor)
663 SetEntityMode(eEdges);
664 else if(myControlActor == my2DActor){
665 switch(myControlMode){
668 case eMultiConnection2D:
669 //SetEntityMode(eEdges);
670 SetEntityMode(eFaces);
673 SetEntityMode(eFaces);
675 }else if(myControlActor == my3DActor)
676 SetEntityMode(eVolumes);
679 }else if(theCheckEntityMode){
680 myEntityMode = eAllEntity;
683 SetRepresentation(GetRepresentation());
685 myTimeStamp->Modified();
690 void SMESH_ActorDef::AddToRender(vtkRenderer* theRenderer){
691 SALOME_Actor::AddToRender(theRenderer);
693 theRenderer->AddActor(myNodeActor);
694 theRenderer->AddActor(myBaseActor);
696 theRenderer->AddActor(my3DActor);
697 theRenderer->AddActor(my2DActor);
699 theRenderer->AddActor(my1DActor);
700 theRenderer->AddActor(my1DExtActor);
702 theRenderer->AddActor(myHighlitableActor);
704 theRenderer->AddActor2D(myScalarBarActor);
706 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
707 myClsSelectVisiblePoints->SetRenderer(theRenderer);
709 theRenderer->AddActor2D(myPointLabels);
710 theRenderer->AddActor2D(myCellsLabels);
713 void SMESH_ActorDef::RemoveFromRender(vtkRenderer* theRenderer){
714 SALOME_Actor::RemoveFromRender(theRenderer);
716 theRenderer->RemoveActor(myNodeActor);
717 theRenderer->RemoveActor(myBaseActor);
719 theRenderer->RemoveActor(myHighlitableActor);
721 theRenderer->RemoveActor(my1DActor);
722 theRenderer->RemoveActor(my1DExtActor);
724 theRenderer->RemoveActor(my2DActor);
725 theRenderer->RemoveActor(my3DActor);
727 theRenderer->RemoveActor(myScalarBarActor);
728 theRenderer->RemoveActor(myPointLabels);
729 theRenderer->RemoveActor(myCellsLabels);
733 bool SMESH_ActorDef::Init(TVisualObjPtr theVisualObj,
734 const char* theEntry,
738 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry,"SMESH",theName);
742 myVisualObj = theVisualObj;
743 myVisualObj->Update(theIsClear);
745 myNodeActor->Init(myVisualObj,myImplicitBoolean);
746 myBaseActor->Init(myVisualObj,myImplicitBoolean);
748 myHighlitableActor->Init(myVisualObj,myImplicitBoolean);
750 my1DActor->Init(myVisualObj,myImplicitBoolean);
751 my1DExtActor->Init(myVisualObj,myImplicitBoolean);
753 my2DActor->Init(myVisualObj,myImplicitBoolean);
754 my3DActor->Init(myVisualObj,myImplicitBoolean);
756 my1DActor->GetMapper()->SetLookupTable(myLookupTable);
757 my1DExtActor->GetMapper()->SetLookupTable(myLookupTable);
759 my2DActor->GetMapper()->SetLookupTable(myLookupTable);
760 my3DActor->GetMapper()->SetLookupTable(myLookupTable);
762 vtkFloatingPointType aFactor, aUnits;
763 my2DActor->GetPolygonOffsetParameters(aFactor,aUnits);
764 my2DActor->SetPolygonOffsetParameters(aFactor,aUnits*0.75);
766 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
770 //SetIsShrunkable(theGrid->GetNumberOfCells() > 10);
771 SetIsShrunkable(true);
773 SetShrinkFactor( SMESH::GetFloat( "SMESH:shrink_coeff", 0.75 ) );
775 int aMode = mgr->integerValue( "SMESH", "display_mode" );
776 SetRepresentation(-1);
779 SetRepresentation(eEdge);
780 }else if(aMode == 1){
781 SetRepresentation(eSurface);
782 }else if(aMode == 2){
783 SetRepresentation(ePoint);
790 myTimeStamp->Modified();
796 vtkFloatingPointType* SMESH_ActorDef::GetBounds(){
797 return myNodeActor->GetBounds();
801 vtkDataSet* SMESH_ActorDef::GetInput(){
802 return GetUnstructuredGrid();
806 void SMESH_ActorDef::SetTransform(VTKViewer_Transform* theTransform){
807 Superclass::SetTransform(theTransform);
809 myNodeActor->SetTransform(theTransform);
810 myBaseActor->SetTransform(theTransform);
812 myHighlitableActor->SetTransform(theTransform);
814 my1DActor->SetTransform(theTransform);
815 my1DExtActor->SetTransform(theTransform);
817 my2DActor->SetTransform(theTransform);
818 my3DActor->SetTransform(theTransform);
824 void SMESH_ActorDef::SetMapper(vtkMapper* theMapper){
825 vtkLODActor::SetMapper(theMapper);
829 void SMESH_ActorDef::ShallowCopy(vtkProp *prop){
830 SALOME_Actor::ShallowCopy(prop);
834 vtkMapper* SMESH_ActorDef::GetMapper(){
835 return myPickableActor->GetMapper();
839 vtkUnstructuredGrid* SMESH_ActorDef::GetUnstructuredGrid(){
840 return myVisualObj->GetUnstructuredGrid();
844 bool SMESH_ActorDef::IsInfinitive(){
845 vtkDataSet *aDataSet = myPickableActor->GetUnstructuredGrid();
847 myIsInfinite = aDataSet->GetNumberOfCells() == 0 ||
848 aDataSet->GetNumberOfCells() == 1 &&
849 aDataSet->GetCell(0)->GetCellType() == VTK_VERTEX;
850 return SALOME_Actor::IsInfinitive();
854 void SMESH_ActorDef::SetIsShrunkable(bool theShrunkable){
855 if ( myIsShrinkable == theShrunkable )
857 myIsShrinkable = theShrunkable;
861 vtkFloatingPointType SMESH_ActorDef::GetShrinkFactor(){
862 return myBaseActor->GetShrinkFactor();
865 void SMESH_ActorDef::SetShrinkFactor(vtkFloatingPointType theValue){
866 myBaseActor->SetShrinkFactor(theValue);
868 my1DActor->SetShrinkFactor(theValue);
869 my1DExtActor->SetShrinkFactor(theValue);
871 my2DActor->SetShrinkFactor(theValue);
872 my3DActor->SetShrinkFactor(theValue);
877 void SMESH_ActorDef::SetShrink(){
878 if(!myIsShrinkable) return;
880 myBaseActor->SetShrink();
882 my1DActor->SetShrink();
883 my1DExtActor->SetShrink();
885 my2DActor->SetShrink();
886 my3DActor->SetShrink();
892 void SMESH_ActorDef::UnShrink(){
893 if(!myIsShrunk) return;
895 myBaseActor->UnShrink();
897 my1DActor->UnShrink();
898 my1DExtActor->UnShrink();
900 my2DActor->UnShrink();
901 my3DActor->UnShrink();
908 int SMESH_ActorDef::GetNodeObjId(int theVtkID){
909 return myPickableActor->GetNodeObjId(theVtkID);
912 vtkFloatingPointType* SMESH_ActorDef::GetNodeCoord(int theObjID){
913 return myPickableActor->GetNodeCoord(theObjID);
917 int SMESH_ActorDef::GetElemObjId(int theVtkID){
918 return myPickableActor->GetElemObjId(theVtkID);
921 vtkCell* SMESH_ActorDef::GetElemCell(int theObjID){
922 return myPickableActor->GetElemCell(theObjID);
926 void SMESH_ActorDef::SetVisibility(int theMode){
927 SetVisibility(theMode,true);
931 void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation){
932 SALOME_Actor::SetVisibility(theMode);
934 myNodeActor->VisibilityOff();
935 myBaseActor->VisibilityOff();
937 my1DActor->VisibilityOff();
938 my1DExtActor->VisibilityOff();
940 my2DActor->VisibilityOff();
941 my3DActor->VisibilityOff();
943 myScalarBarActor->VisibilityOff();
944 myPointLabels->VisibilityOff();
945 myCellsLabels->VisibilityOff();
948 if(theIsUpdateRepersentation)
949 SetRepresentation(GetRepresentation());
951 if(myControlMode != eNone){
952 switch(myControlMode){
955 my1DExtActor->VisibilityOn();
958 case eMultiConnection2D:
959 my1DExtActor->VisibilityOn();
961 if(myControlActor->GetUnstructuredGrid()->GetNumberOfCells())
962 myScalarBarActor->VisibilityOn();
966 if(myRepresentation != ePoint)
967 myPickableActor->VisibilityOn();
969 myNodeActor->VisibilityOn();
972 if(myEntityMode & eEdges){
973 my1DActor->VisibilityOn();
976 if(myEntityMode & eFaces){
977 my2DActor->VisibilityOn();
980 if(myEntityMode & eVolumes){
981 my3DActor->VisibilityOn();
984 if(myIsPointsLabeled){
985 myPointLabels->VisibilityOn();
986 myNodeActor->VisibilityOn();
990 myCellsLabels->VisibilityOn();
997 void SMESH_ActorDef::SetEntityMode(unsigned int theMode){
998 myEntityState = eAllEntity;
1000 if(!myVisualObj->GetNbEntities(SMDSAbs_Edge)){
1001 myEntityState &= ~eEdges;
1005 if(!myVisualObj->GetNbEntities(SMDSAbs_Face)){
1006 myEntityState &= ~eFaces;
1010 if(!myVisualObj->GetNbEntities(SMDSAbs_Volume)){
1011 myEntityState &= ~eVolumes;
1012 theMode &= ~eVolumes;
1016 if(myVisualObj->GetNbEntities(SMDSAbs_Edge))
1019 if(myVisualObj->GetNbEntities(SMDSAbs_Face))
1022 if(myVisualObj->GetNbEntities(SMDSAbs_Volume))
1023 theMode |= eVolumes;
1026 myBaseActor->myGeomFilter->SetInside(myEntityMode != myEntityState);
1028 myEntityMode = theMode;
1029 VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
1030 aFilter = myBaseActor->GetExtractUnstructuredGrid();
1031 aFilter->ClearRegisteredCellsWithType();
1032 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
1034 if(myEntityMode & eEdges){
1035 if (MYDEBUG) MESSAGE("EDGES");
1036 aFilter->RegisterCellsWithType(VTK_LINE);
1037 aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
1040 if(myEntityMode & eFaces){
1041 if (MYDEBUG) MESSAGE("FACES");
1042 aFilter->RegisterCellsWithType(VTK_TRIANGLE);
1043 aFilter->RegisterCellsWithType(VTK_POLYGON);
1044 aFilter->RegisterCellsWithType(VTK_QUAD);
1045 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
1046 aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
1049 if(myEntityMode & eVolumes){
1050 if (MYDEBUG) MESSAGE("VOLUMES");
1051 aFilter->RegisterCellsWithType(VTK_TETRA);
1052 aFilter->RegisterCellsWithType(VTK_VOXEL);
1053 aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1054 aFilter->RegisterCellsWithType(VTK_WEDGE);
1055 aFilter->RegisterCellsWithType(VTK_PYRAMID);
1056 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
1057 aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
1058 aFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
1059 aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1062 if (MYDEBUG) MESSAGE(aFilter->GetOutput()->GetNumberOfCells());
1063 SetVisibility(GetVisibility(),false);
1066 void SMESH_ActorDef::SetRepresentation(int theMode){
1067 int aNbEdges = myVisualObj->GetNbEntities(SMDSAbs_Edge);
1068 int aNbFaces = myVisualObj->GetNbEntities(SMDSAbs_Face);
1069 int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume);
1071 myRepresentation = eSurface;
1072 if(!aNbFaces && !aNbVolumes && aNbEdges){
1073 myRepresentation = eEdge;
1074 }else if(!aNbFaces && !aNbVolumes && !aNbEdges){
1075 myRepresentation = ePoint;
1080 if(!aNbFaces && !aNbVolumes && !aNbEdges) return;
1083 if(!aNbFaces && !aNbVolumes) return;
1086 myRepresentation = theMode;
1089 if(!GetUnstructuredGrid()->GetNumberOfCells())
1090 myRepresentation = ePoint;
1093 if(myRepresentation == ePoint){
1101 myPickableActor = myBaseActor;
1102 myNodeActor->SetVisibility(false);
1103 vtkProperty *aProp = NULL, *aBackProp = NULL;
1104 SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1);
1105 switch(myRepresentation){
1107 myPickableActor = myNodeActor;
1108 myNodeActor->SetVisibility(true);
1110 aProp = aBackProp = myNodeProp;
1111 aReperesent = SMESH_DeviceActor::ePoint;
1114 aProp = aBackProp = myEdgeProp;
1115 aReperesent = SMESH_DeviceActor::eInsideframe;
1118 aProp = mySurfaceProp;
1119 aBackProp = myBackSurfaceProp;
1120 aReperesent = SMESH_DeviceActor::eSurface;
1124 my2DActor->SetProperty(aProp);
1125 my2DActor->SetBackfaceProperty(aBackProp);
1126 my2DActor->SetRepresentation(aReperesent);
1128 my3DActor->SetProperty(aProp);
1129 my3DActor->SetBackfaceProperty(aBackProp);
1130 my3DActor->SetRepresentation(aReperesent);
1132 my1DExtActor->SetVisibility(false);
1134 switch(myControlMode){
1136 case eMultiConnection:
1137 aProp = aBackProp = my1DProp;
1138 if(myRepresentation != ePoint)
1139 aReperesent = SMESH_DeviceActor::eInsideframe;
1143 my1DActor->SetProperty(aProp);
1144 my1DActor->SetBackfaceProperty(aBackProp);
1145 my1DActor->SetRepresentation(aReperesent);
1147 my1DExtActor->SetRepresentation(aReperesent);
1149 if(myIsPointsVisible)
1150 myPickableActor = myNodeActor;
1151 if(GetPointRepresentation())
1152 myNodeActor->SetVisibility(true);
1154 SetMapper(myPickableActor->GetMapper());
1156 SetVisibility(GetVisibility(),false);
1162 void SMESH_ActorDef::SetPointRepresentation(bool theIsPointsVisible){
1163 if ( myIsPointsVisible == theIsPointsVisible )
1165 myIsPointsVisible = theIsPointsVisible;
1166 SetRepresentation(GetRepresentation());
1169 bool SMESH_ActorDef::GetPointRepresentation(){
1170 return myIsPointsVisible || myIsPointsLabeled;
1174 void SMESH_ActorDef::UpdateHighlight(){
1175 myHighlitableActor->SetVisibility(false);
1176 myHighlitableActor->SetHighlited(false);
1178 if(myIsHighlighted){
1179 myHighlitableActor->SetProperty(myHighlightProp);
1180 }else if(myIsPreselected){
1181 myHighlitableActor->SetProperty(myPreselectProp);
1184 bool anIsVisible = GetVisibility();
1186 if(myIsHighlighted || myIsPreselected){
1187 if(GetUnstructuredGrid()->GetNumberOfCells()){
1188 myHighlitableActor->SetHighlited(anIsVisible);
1189 myHighlitableActor->SetVisibility(anIsVisible);
1190 myHighlitableActor->GetExtractUnstructuredGrid()->
1191 SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::eCells);
1192 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
1193 }else if(myRepresentation == ePoint || GetPointRepresentation()){
1194 myHighlitableActor->SetHighlited(anIsVisible);
1195 myHighlitableActor->GetExtractUnstructuredGrid()->
1196 SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
1197 myHighlitableActor->SetVisibility(anIsVisible);
1198 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::ePoint);
1204 void SMESH_ActorDef::highlight(bool theHighlight){
1205 if ( myIsHighlighted == theHighlight )
1207 myIsHighlighted = theHighlight;
1212 void SMESH_ActorDef::SetPreSelected(bool thePreselect){
1213 if ( myIsPreselected == thePreselect )
1215 myIsPreselected = thePreselect;
1221 int SMESH_ActorDef::RenderOpaqueGeometry(vtkViewport *vp)
1223 if (myPickableActor->GetIsOpaque())
1225 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1233 int SMESH_ActorDef::RenderTranslucentGeometry(vtkViewport *vp)
1235 if (!myPickableActor->GetIsOpaque())
1237 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1245 void SMESH_ActorDef::Render(vtkRenderer *ren){
1246 unsigned long aTime = myTimeStamp->GetMTime();
1247 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1248 unsigned long aClippingTime = myImplicitBoolean->GetMTime();
1249 if(anObjTime > aTime || aClippingTime > aTime)
1254 void SMESH_ActorDef::Update(){
1255 if(MYDEBUG) MESSAGE("SMESH_ActorDef::Update");
1257 if(GetControlMode() != eNone) {
1258 unsigned long aTime = myTimeStamp->GetMTime();
1259 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1260 if (anObjTime > aTime)
1261 SetControlMode(GetControlMode(),false);
1263 if(myIsPointsLabeled){
1264 SetPointsLabeled(myIsPointsLabeled);
1266 if(myIsCellsLabeled){
1267 SetCellsLabeled(myIsCellsLabeled);
1269 SetEntityMode(GetEntityMode());
1270 SetVisibility(GetVisibility());
1272 myTimeStamp->Modified();
1277 void SMESH_ActorDef::ReleaseGraphicsResources(vtkWindow *renWin){
1278 SALOME_Actor::ReleaseGraphicsResources(renWin);
1280 myPickableActor->ReleaseGraphicsResources(renWin);
1284 static void GetColor(vtkProperty *theProperty, vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1285 vtkFloatingPointType* aColor = theProperty->GetColor();
1292 void SMESH_ActorDef::SetOpacity(vtkFloatingPointType theValue){
1293 mySurfaceProp->SetOpacity(theValue);
1294 myBackSurfaceProp->SetOpacity(theValue);
1295 myEdgeProp->SetOpacity(theValue);
1296 myNodeProp->SetOpacity(theValue);
1298 my1DProp->SetOpacity(theValue);
1302 vtkFloatingPointType SMESH_ActorDef::GetOpacity(){
1303 return mySurfaceProp->GetOpacity();
1307 void SMESH_ActorDef::SetSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1308 mySurfaceProp->SetColor(r,g,b);
1312 void SMESH_ActorDef::GetSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1313 ::GetColor(mySurfaceProp,r,g,b);
1316 void SMESH_ActorDef::SetBackSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1317 myBackSurfaceProp->SetColor(r,g,b);
1321 void SMESH_ActorDef::GetBackSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1322 ::GetColor(myBackSurfaceProp,r,g,b);
1325 void SMESH_ActorDef::SetEdgeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1326 myEdgeProp->SetColor(r,g,b);
1327 my1DProp->SetColor(r,g,b);
1328 my1DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1332 void SMESH_ActorDef::GetEdgeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1333 ::GetColor(myEdgeProp,r,g,b);
1336 void SMESH_ActorDef::SetNodeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1337 myNodeProp->SetColor(r,g,b);
1341 void SMESH_ActorDef::GetNodeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1342 ::GetColor(myNodeProp,r,g,b);
1345 void SMESH_ActorDef::SetHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1346 myHighlightProp->SetColor(r,g,b);
1350 void SMESH_ActorDef::GetHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1351 ::GetColor(myHighlightProp,r,g,b);
1354 void SMESH_ActorDef::SetPreHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1355 myPreselectProp->SetColor(r,g,b);
1359 void SMESH_ActorDef::GetPreHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1360 ::GetColor(myPreselectProp,r,g,b);
1364 vtkFloatingPointType SMESH_ActorDef::GetLineWidth(){
1365 return myEdgeProp->GetLineWidth();
1369 void SMESH_ActorDef::SetLineWidth(vtkFloatingPointType theVal){
1370 myEdgeProp->SetLineWidth(theVal);
1372 my1DProp->SetLineWidth(theVal + aLineWidthInc);
1373 my1DExtProp->SetLineWidth(theVal + aLineWidthInc);
1379 void SMESH_ActorDef::SetNodeSize(vtkFloatingPointType theVal){
1380 myNodeProp->SetPointSize(theVal);
1381 myHighlightProp->SetPointSize(theVal);
1382 myPreselectProp->SetPointSize(theVal);
1384 my1DProp->SetPointSize(theVal + aPointSizeInc);
1385 my1DExtProp->SetPointSize(theVal + aPointSizeInc);
1390 vtkFloatingPointType SMESH_ActorDef::GetNodeSize(){
1391 return myNodeProp->GetPointSize();
1394 int SMESH_ActorDef::GetObjDimension( const int theObjId )
1396 return myVisualObj->GetElemDimension( theObjId );
1401 IsImplicitFunctionUsed() const
1403 return myBaseActor->IsImplicitFunctionUsed();
1408 SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
1410 myNodeActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1411 myBaseActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1413 myHighlitableActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1415 my1DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1416 my1DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1418 my2DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1419 my3DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1424 AddClippingPlane(vtkPlane* thePlane)
1427 myImplicitBoolean->GetFunction()->AddItem(thePlane);
1428 myCippingPlaneCont.push_back(thePlane);
1429 if(!IsImplicitFunctionUsed())
1430 SetImplicitFunctionUsed(true);
1432 return myCippingPlaneCont.size();
1437 RemoveAllClippingPlanes()
1439 myImplicitBoolean->GetFunction()->RemoveAllItems();
1440 myImplicitBoolean->GetFunction()->Modified(); // VTK bug
1441 myCippingPlaneCont.clear();
1442 SetImplicitFunctionUsed(false);
1447 GetNumberOfClippingPlanes()
1449 return myCippingPlaneCont.size();
1454 GetClippingPlane(vtkIdType theID)
1456 if(theID >= myCippingPlaneCont.size())
1458 return myCippingPlaneCont[theID].Get();
1462 static void ComputeBoundsParam(vtkDataSet* theDataSet,
1463 vtkFloatingPointType theDirection[3], vtkFloatingPointType theMinPnt[3],
1464 vtkFloatingPointType& theMaxBoundPrj, vtkFloatingPointType& theMinBoundPrj)
1466 vtkFloatingPointType aBounds[6];
1467 theDataSet->GetBounds(aBounds);
1469 //Enlarge bounds in order to avoid conflicts of precision
1470 for(int i = 0; i < 6; i += 2){
1471 static double EPS = 1.0E-3;
1472 vtkFloatingPointType aDelta = (aBounds[i+1] - aBounds[i])*EPS;
1473 aBounds[i] -= aDelta;
1474 aBounds[i+1] += aDelta;
1477 vtkFloatingPointType aBoundPoints[8][3] = { {aBounds[0],aBounds[2],aBounds[4]},
1478 {aBounds[1],aBounds[2],aBounds[4]},
1479 {aBounds[0],aBounds[3],aBounds[4]},
1480 {aBounds[1],aBounds[3],aBounds[4]},
1481 {aBounds[0],aBounds[2],aBounds[5]},
1482 {aBounds[1],aBounds[2],aBounds[5]},
1483 {aBounds[0],aBounds[3],aBounds[5]},
1484 {aBounds[1],aBounds[3],aBounds[5]}};
1486 int aMaxId = 0, aMinId = aMaxId;
1487 theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
1488 theMinBoundPrj = theMaxBoundPrj;
1489 for(int i = 1; i < 8; i++){
1490 vtkFloatingPointType aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
1491 if(theMaxBoundPrj < aTmp){
1492 theMaxBoundPrj = aTmp;
1495 if(theMinBoundPrj > aTmp){
1496 theMinBoundPrj = aTmp;
1500 vtkFloatingPointType *aMinPnt = aBoundPoints[aMaxId];
1501 theMinPnt[0] = aMinPnt[0];
1502 theMinPnt[1] = aMinPnt[1];
1503 theMinPnt[2] = aMinPnt[2];
1507 static void DistanceToPosition(vtkDataSet* theDataSet,
1508 vtkFloatingPointType theDirection[3], vtkFloatingPointType theDist, vtkFloatingPointType thePos[3])
1510 vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1511 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1512 vtkFloatingPointType aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
1513 thePos[0] = aMinPnt[0]-theDirection[0]*aLength;
1514 thePos[1] = aMinPnt[1]-theDirection[1]*aLength;
1515 thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
1519 static void PositionToDistance(vtkDataSet* theDataSet,
1520 vtkFloatingPointType theDirection[3], vtkFloatingPointType thePos[3], vtkFloatingPointType& theDist)
1522 vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1523 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1524 vtkFloatingPointType aPrj = vtkMath::Dot(theDirection,thePos);
1525 theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
1529 void SMESH_ActorDef::SetPlaneParam(vtkFloatingPointType theDir[3], vtkFloatingPointType theDist, vtkPlane* thePlane)
1531 thePlane->SetNormal(theDir);
1532 vtkFloatingPointType anOrigin[3];
1533 ::DistanceToPosition(GetUnstructuredGrid(),theDir,theDist,anOrigin);
1534 thePlane->SetOrigin(anOrigin);
1538 void SMESH_ActorDef::GetPlaneParam(vtkFloatingPointType theDir[3], vtkFloatingPointType& theDist, vtkPlane* thePlane)
1540 thePlane->GetNormal(theDir);
1542 vtkFloatingPointType anOrigin[3];
1543 thePlane->GetOrigin(anOrigin);
1544 ::PositionToDistance(GetUnstructuredGrid(),theDir,anOrigin,theDist);
1547 void SMESH_ActorDef::UpdateScalarBar()
1549 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
1553 vtkTextProperty* aScalarBarTitleProp = vtkTextProperty::New();
1555 QColor aTColor = mgr->colorValue( "SMESH", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
1556 aScalarBarTitleProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1558 aScalarBarTitleProp->SetFontFamilyToArial();
1560 if ( mgr->hasValue( "SMESH", "scalar_bar_title_font" ) )
1562 QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
1563 if ( f.family() == "Arial" )
1564 aScalarBarTitleProp->SetFontFamilyToArial();
1565 else if ( f.family() == "Courier" )
1566 aScalarBarTitleProp->SetFontFamilyToCourier();
1567 else if ( f.family() == "Times" )
1568 aScalarBarTitleProp->SetFontFamilyToTimes();
1571 aScalarBarTitleProp->BoldOn();
1573 aScalarBarTitleProp->BoldOff();
1576 aScalarBarTitleProp->ItalicOn();
1578 aScalarBarTitleProp->ItalicOff();
1580 if ( f.underline() )
1581 aScalarBarTitleProp->ShadowOn();
1583 aScalarBarTitleProp->ShadowOff();
1586 myScalarBarActor->SetTitleTextProperty( aScalarBarTitleProp );
1587 aScalarBarTitleProp->Delete();
1589 vtkTextProperty* aScalarBarLabelProp = vtkTextProperty::New();
1591 aTColor = mgr->colorValue( "SMESH", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
1592 aScalarBarLabelProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1594 aScalarBarLabelProp->SetFontFamilyToArial();
1595 if( mgr->hasValue( "SMESH", "scalar_bar_label_font" ) )
1597 QFont f = mgr->fontValue( "SMESH", "scalar_bar_label_font" );
1598 if( f.family() == "Arial" )
1599 aScalarBarLabelProp->SetFontFamilyToArial();
1600 else if( f.family() == "Courier" )
1601 aScalarBarLabelProp->SetFontFamilyToCourier();
1602 else if( f.family() == "Times" )
1603 aScalarBarLabelProp->SetFontFamilyToTimes();
1606 aScalarBarLabelProp->BoldOn();
1608 aScalarBarLabelProp->BoldOff();
1611 aScalarBarLabelProp->ItalicOn();
1613 aScalarBarLabelProp->ItalicOff();
1616 aScalarBarLabelProp->ShadowOn();
1618 aScalarBarLabelProp->ShadowOff();
1621 myScalarBarActor->SetLabelTextProperty( aScalarBarLabelProp );
1622 aScalarBarLabelProp->Delete();
1624 bool horiz = ( mgr->integerValue( "SMESH", "scalar_bar_orientation" ) == 1 );
1625 QString name = QString( "scalar_bar_%1_" ).arg( horiz ? "horizontal" : "vertical" );
1627 myScalarBarActor->SetOrientationToHorizontal();
1629 myScalarBarActor->SetOrientationToVertical();
1632 vtkFloatingPointType aXVal = horiz ? 0.20 : 0.01;
1633 if( mgr->hasValue( "SMESH", name + "x" ) )
1634 aXVal = mgr->doubleValue( "SMESH", name + "x", aXVal );
1636 vtkFloatingPointType aYVal = horiz ? 0.01 : 0.1;
1637 if( mgr->hasValue( "SMESH", name + "y" ) )
1638 aYVal = mgr->doubleValue( "SMESH", name + "y", aYVal );
1639 myScalarBarActor->SetPosition( aXVal, aYVal );
1641 vtkFloatingPointType aWVal = horiz ? 0.60 : 0.10;
1642 if( mgr->hasValue( "SMESH", name + "width" ) )
1643 aWVal = mgr->doubleValue( "SMESH", name + "width", aWVal );
1644 myScalarBarActor->SetWidth( aWVal );
1646 vtkFloatingPointType aHVal = horiz ? 0.12 : 0.80;
1647 if( mgr->hasValue( "SMESH", name + "height" ) )
1648 aHVal = mgr->doubleValue( "SMESH", name + "height", aHVal );
1649 myScalarBarActor->SetHeight( aHVal );
1652 if( mgr->hasValue( "SMESH", "scalar_bar_num_labels" ) )
1653 anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_labels", anIntVal );
1654 myScalarBarActor->SetNumberOfLabels( anIntVal == 0 ? 5: anIntVal );
1657 if( mgr->hasValue( "SMESH", "scalar_bar_num_colors" ) )
1658 anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_colors", anIntVal );
1659 myScalarBarActor->SetMaximumNumberOfColors( anIntVal == 0 ? 64 : anIntVal );