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");
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_CONVEX_POINT_SET);
1061 if (MYDEBUG) MESSAGE(aFilter->GetOutput()->GetNumberOfCells());
1062 SetVisibility(GetVisibility(),false);
1065 void SMESH_ActorDef::SetRepresentation(int theMode){
1066 int aNbEdges = myVisualObj->GetNbEntities(SMDSAbs_Edge);
1067 int aNbFaces = myVisualObj->GetNbEntities(SMDSAbs_Face);
1068 int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume);
1070 myRepresentation = eSurface;
1071 if(!aNbFaces && !aNbVolumes && aNbEdges){
1072 myRepresentation = eEdge;
1073 }else if(!aNbFaces && !aNbVolumes && !aNbEdges){
1074 myRepresentation = ePoint;
1079 if(!aNbFaces && !aNbVolumes && !aNbEdges) return;
1082 if(!aNbFaces && !aNbVolumes) return;
1085 myRepresentation = theMode;
1088 if(!GetUnstructuredGrid()->GetNumberOfCells())
1089 myRepresentation = ePoint;
1092 if(myRepresentation == ePoint){
1100 myPickableActor = myBaseActor;
1101 myNodeActor->SetVisibility(false);
1102 vtkProperty *aProp = NULL, *aBackProp = NULL;
1103 SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1);
1104 switch(myRepresentation){
1106 myPickableActor = myNodeActor;
1107 myNodeActor->SetVisibility(true);
1109 aProp = aBackProp = myNodeProp;
1110 aReperesent = SMESH_DeviceActor::ePoint;
1113 aProp = aBackProp = myEdgeProp;
1114 aReperesent = SMESH_DeviceActor::eInsideframe;
1117 aProp = mySurfaceProp;
1118 aBackProp = myBackSurfaceProp;
1119 aReperesent = SMESH_DeviceActor::eSurface;
1123 my2DActor->SetProperty(aProp);
1124 my2DActor->SetBackfaceProperty(aBackProp);
1125 my2DActor->SetRepresentation(aReperesent);
1127 my3DActor->SetProperty(aProp);
1128 my3DActor->SetBackfaceProperty(aBackProp);
1129 my3DActor->SetRepresentation(aReperesent);
1131 my1DExtActor->SetVisibility(false);
1133 switch(myControlMode){
1135 case eMultiConnection:
1136 aProp = aBackProp = my1DProp;
1137 if(myRepresentation != ePoint)
1138 aReperesent = SMESH_DeviceActor::eInsideframe;
1142 my1DActor->SetProperty(aProp);
1143 my1DActor->SetBackfaceProperty(aBackProp);
1144 my1DActor->SetRepresentation(aReperesent);
1146 my1DExtActor->SetRepresentation(aReperesent);
1148 if(myIsPointsVisible)
1149 myPickableActor = myNodeActor;
1150 if(GetPointRepresentation())
1151 myNodeActor->SetVisibility(true);
1153 SetMapper(myPickableActor->GetMapper());
1155 SetVisibility(GetVisibility(),false);
1161 void SMESH_ActorDef::SetPointRepresentation(bool theIsPointsVisible){
1162 if ( myIsPointsVisible == theIsPointsVisible )
1164 myIsPointsVisible = theIsPointsVisible;
1165 SetRepresentation(GetRepresentation());
1168 bool SMESH_ActorDef::GetPointRepresentation(){
1169 return myIsPointsVisible || myIsPointsLabeled;
1173 void SMESH_ActorDef::UpdateHighlight(){
1174 myHighlitableActor->SetVisibility(false);
1175 myHighlitableActor->SetHighlited(false);
1177 if(myIsHighlighted){
1178 myHighlitableActor->SetProperty(myHighlightProp);
1179 }else if(myIsPreselected){
1180 myHighlitableActor->SetProperty(myPreselectProp);
1183 bool anIsVisible = GetVisibility();
1185 if(myIsHighlighted || myIsPreselected){
1186 if(GetUnstructuredGrid()->GetNumberOfCells()){
1187 myHighlitableActor->SetHighlited(anIsVisible);
1188 myHighlitableActor->SetVisibility(anIsVisible);
1189 myHighlitableActor->GetExtractUnstructuredGrid()->
1190 SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::eCells);
1191 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
1192 }else if(myRepresentation == ePoint || GetPointRepresentation()){
1193 myHighlitableActor->SetHighlited(anIsVisible);
1194 myHighlitableActor->GetExtractUnstructuredGrid()->
1195 SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
1196 myHighlitableActor->SetVisibility(anIsVisible);
1197 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::ePoint);
1203 void SMESH_ActorDef::highlight(bool theHighlight){
1204 if ( myIsHighlighted == theHighlight )
1206 myIsHighlighted = theHighlight;
1211 void SMESH_ActorDef::SetPreSelected(bool thePreselect){
1212 if ( myIsPreselected == thePreselect )
1214 myIsPreselected = thePreselect;
1220 int SMESH_ActorDef::RenderOpaqueGeometry(vtkViewport *vp)
1222 if (myPickableActor->GetIsOpaque())
1224 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1232 int SMESH_ActorDef::RenderTranslucentGeometry(vtkViewport *vp)
1234 if (!myPickableActor->GetIsOpaque())
1236 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1244 void SMESH_ActorDef::Render(vtkRenderer *ren){
1245 unsigned long aTime = myTimeStamp->GetMTime();
1246 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1247 unsigned long aClippingTime = myImplicitBoolean->GetMTime();
1248 if(anObjTime > aTime || aClippingTime > aTime)
1253 void SMESH_ActorDef::Update(){
1254 if(MYDEBUG) MESSAGE("SMESH_ActorDef::Update");
1256 if(GetControlMode() != eNone) {
1257 unsigned long aTime = myTimeStamp->GetMTime();
1258 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1259 if (anObjTime > aTime)
1260 SetControlMode(GetControlMode(),false);
1262 if(myIsPointsLabeled){
1263 SetPointsLabeled(myIsPointsLabeled);
1265 if(myIsCellsLabeled){
1266 SetCellsLabeled(myIsCellsLabeled);
1268 SetEntityMode(GetEntityMode());
1269 SetVisibility(GetVisibility());
1271 myTimeStamp->Modified();
1276 void SMESH_ActorDef::ReleaseGraphicsResources(vtkWindow *renWin){
1277 SALOME_Actor::ReleaseGraphicsResources(renWin);
1279 myPickableActor->ReleaseGraphicsResources(renWin);
1283 static void GetColor(vtkProperty *theProperty, vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1284 vtkFloatingPointType* aColor = theProperty->GetColor();
1291 void SMESH_ActorDef::SetOpacity(vtkFloatingPointType theValue){
1292 mySurfaceProp->SetOpacity(theValue);
1293 myBackSurfaceProp->SetOpacity(theValue);
1294 myEdgeProp->SetOpacity(theValue);
1295 myNodeProp->SetOpacity(theValue);
1297 my1DProp->SetOpacity(theValue);
1301 vtkFloatingPointType SMESH_ActorDef::GetOpacity(){
1302 return mySurfaceProp->GetOpacity();
1306 void SMESH_ActorDef::SetSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1307 mySurfaceProp->SetColor(r,g,b);
1311 void SMESH_ActorDef::GetSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1312 ::GetColor(mySurfaceProp,r,g,b);
1315 void SMESH_ActorDef::SetBackSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1316 myBackSurfaceProp->SetColor(r,g,b);
1320 void SMESH_ActorDef::GetBackSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1321 ::GetColor(myBackSurfaceProp,r,g,b);
1324 void SMESH_ActorDef::SetEdgeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1325 myEdgeProp->SetColor(r,g,b);
1326 my1DProp->SetColor(r,g,b);
1327 my1DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1331 void SMESH_ActorDef::GetEdgeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1332 ::GetColor(myEdgeProp,r,g,b);
1335 void SMESH_ActorDef::SetNodeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1336 myNodeProp->SetColor(r,g,b);
1340 void SMESH_ActorDef::GetNodeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1341 ::GetColor(myNodeProp,r,g,b);
1344 void SMESH_ActorDef::SetHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1345 myHighlightProp->SetColor(r,g,b);
1349 void SMESH_ActorDef::GetHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1350 ::GetColor(myHighlightProp,r,g,b);
1353 void SMESH_ActorDef::SetPreHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1354 myPreselectProp->SetColor(r,g,b);
1358 void SMESH_ActorDef::GetPreHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1359 ::GetColor(myPreselectProp,r,g,b);
1363 vtkFloatingPointType SMESH_ActorDef::GetLineWidth(){
1364 return myEdgeProp->GetLineWidth();
1368 void SMESH_ActorDef::SetLineWidth(vtkFloatingPointType theVal){
1369 myEdgeProp->SetLineWidth(theVal);
1371 my1DProp->SetLineWidth(theVal + aLineWidthInc);
1372 my1DExtProp->SetLineWidth(theVal + aLineWidthInc);
1378 void SMESH_ActorDef::SetNodeSize(vtkFloatingPointType theVal){
1379 myNodeProp->SetPointSize(theVal);
1380 myHighlightProp->SetPointSize(theVal);
1381 myPreselectProp->SetPointSize(theVal);
1383 my1DProp->SetPointSize(theVal + aPointSizeInc);
1384 my1DExtProp->SetPointSize(theVal + aPointSizeInc);
1389 vtkFloatingPointType SMESH_ActorDef::GetNodeSize(){
1390 return myNodeProp->GetPointSize();
1393 int SMESH_ActorDef::GetObjDimension( const int theObjId )
1395 return myVisualObj->GetElemDimension( theObjId );
1400 IsImplicitFunctionUsed() const
1402 return myBaseActor->IsImplicitFunctionUsed();
1407 SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
1409 myNodeActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1410 myBaseActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1412 myHighlitableActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1414 my1DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1415 my1DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1417 my2DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1418 my3DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1423 AddClippingPlane(vtkPlane* thePlane)
1426 myImplicitBoolean->GetFunction()->AddItem(thePlane);
1427 myCippingPlaneCont.push_back(thePlane);
1428 if(!IsImplicitFunctionUsed())
1429 SetImplicitFunctionUsed(true);
1431 return myCippingPlaneCont.size();
1436 RemoveAllClippingPlanes()
1438 myImplicitBoolean->GetFunction()->RemoveAllItems();
1439 myImplicitBoolean->GetFunction()->Modified(); // VTK bug
1440 myCippingPlaneCont.clear();
1441 SetImplicitFunctionUsed(false);
1446 GetNumberOfClippingPlanes()
1448 return myCippingPlaneCont.size();
1453 GetClippingPlane(vtkIdType theID)
1455 if(theID >= myCippingPlaneCont.size())
1457 return myCippingPlaneCont[theID].Get();
1461 static void ComputeBoundsParam(vtkDataSet* theDataSet,
1462 vtkFloatingPointType theDirection[3], vtkFloatingPointType theMinPnt[3],
1463 vtkFloatingPointType& theMaxBoundPrj, vtkFloatingPointType& theMinBoundPrj)
1465 vtkFloatingPointType aBounds[6];
1466 theDataSet->GetBounds(aBounds);
1468 //Enlarge bounds in order to avoid conflicts of precision
1469 for(int i = 0; i < 6; i += 2){
1470 static double EPS = 1.0E-3;
1471 vtkFloatingPointType aDelta = (aBounds[i+1] - aBounds[i])*EPS;
1472 aBounds[i] -= aDelta;
1473 aBounds[i+1] += aDelta;
1476 vtkFloatingPointType aBoundPoints[8][3] = { {aBounds[0],aBounds[2],aBounds[4]},
1477 {aBounds[1],aBounds[2],aBounds[4]},
1478 {aBounds[0],aBounds[3],aBounds[4]},
1479 {aBounds[1],aBounds[3],aBounds[4]},
1480 {aBounds[0],aBounds[2],aBounds[5]},
1481 {aBounds[1],aBounds[2],aBounds[5]},
1482 {aBounds[0],aBounds[3],aBounds[5]},
1483 {aBounds[1],aBounds[3],aBounds[5]}};
1485 int aMaxId = 0, aMinId = aMaxId;
1486 theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
1487 theMinBoundPrj = theMaxBoundPrj;
1488 for(int i = 1; i < 8; i++){
1489 vtkFloatingPointType aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
1490 if(theMaxBoundPrj < aTmp){
1491 theMaxBoundPrj = aTmp;
1494 if(theMinBoundPrj > aTmp){
1495 theMinBoundPrj = aTmp;
1499 vtkFloatingPointType *aMinPnt = aBoundPoints[aMaxId];
1500 theMinPnt[0] = aMinPnt[0];
1501 theMinPnt[1] = aMinPnt[1];
1502 theMinPnt[2] = aMinPnt[2];
1506 static void DistanceToPosition(vtkDataSet* theDataSet,
1507 vtkFloatingPointType theDirection[3], vtkFloatingPointType theDist, vtkFloatingPointType thePos[3])
1509 vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1510 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1511 vtkFloatingPointType aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
1512 thePos[0] = aMinPnt[0]-theDirection[0]*aLength;
1513 thePos[1] = aMinPnt[1]-theDirection[1]*aLength;
1514 thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
1518 static void PositionToDistance(vtkDataSet* theDataSet,
1519 vtkFloatingPointType theDirection[3], vtkFloatingPointType thePos[3], vtkFloatingPointType& theDist)
1521 vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1522 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1523 vtkFloatingPointType aPrj = vtkMath::Dot(theDirection,thePos);
1524 theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
1528 void SMESH_ActorDef::SetPlaneParam(vtkFloatingPointType theDir[3], vtkFloatingPointType theDist, vtkPlane* thePlane)
1530 thePlane->SetNormal(theDir);
1531 vtkFloatingPointType anOrigin[3];
1532 ::DistanceToPosition(GetUnstructuredGrid(),theDir,theDist,anOrigin);
1533 thePlane->SetOrigin(anOrigin);
1537 void SMESH_ActorDef::GetPlaneParam(vtkFloatingPointType theDir[3], vtkFloatingPointType& theDist, vtkPlane* thePlane)
1539 thePlane->GetNormal(theDir);
1541 vtkFloatingPointType anOrigin[3];
1542 thePlane->GetOrigin(anOrigin);
1543 ::PositionToDistance(GetUnstructuredGrid(),theDir,anOrigin,theDist);
1546 void SMESH_ActorDef::UpdateScalarBar()
1548 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
1552 vtkTextProperty* aScalarBarTitleProp = vtkTextProperty::New();
1554 QColor aTColor = mgr->colorValue( "SMESH", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
1555 aScalarBarTitleProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1557 aScalarBarTitleProp->SetFontFamilyToArial();
1559 if ( mgr->hasValue( "SMESH", "scalar_bar_title_font" ) )
1561 QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
1562 if ( f.family() == "Arial" )
1563 aScalarBarTitleProp->SetFontFamilyToArial();
1564 else if ( f.family() == "Courier" )
1565 aScalarBarTitleProp->SetFontFamilyToCourier();
1566 else if ( f.family() == "Times" )
1567 aScalarBarTitleProp->SetFontFamilyToTimes();
1570 aScalarBarTitleProp->BoldOn();
1572 aScalarBarTitleProp->BoldOff();
1575 aScalarBarTitleProp->ItalicOn();
1577 aScalarBarTitleProp->ItalicOff();
1579 if ( f.underline() )
1580 aScalarBarTitleProp->ShadowOn();
1582 aScalarBarTitleProp->ShadowOff();
1585 myScalarBarActor->SetTitleTextProperty( aScalarBarTitleProp );
1586 aScalarBarTitleProp->Delete();
1588 vtkTextProperty* aScalarBarLabelProp = vtkTextProperty::New();
1590 aTColor = mgr->colorValue( "SMESH", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
1591 aScalarBarLabelProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1593 aScalarBarLabelProp->SetFontFamilyToArial();
1594 if( mgr->hasValue( "SMESH", "scalar_bar_label_font" ) )
1596 QFont f = mgr->fontValue( "SMESH", "scalar_bar_label_font" );
1597 if( f.family() == "Arial" )
1598 aScalarBarLabelProp->SetFontFamilyToArial();
1599 else if( f.family() == "Courier" )
1600 aScalarBarLabelProp->SetFontFamilyToCourier();
1601 else if( f.family() == "Times" )
1602 aScalarBarLabelProp->SetFontFamilyToTimes();
1605 aScalarBarLabelProp->BoldOn();
1607 aScalarBarLabelProp->BoldOff();
1610 aScalarBarLabelProp->ItalicOn();
1612 aScalarBarLabelProp->ItalicOff();
1615 aScalarBarLabelProp->ShadowOn();
1617 aScalarBarLabelProp->ShadowOff();
1620 myScalarBarActor->SetLabelTextProperty( aScalarBarLabelProp );
1621 aScalarBarLabelProp->Delete();
1623 bool horiz = ( mgr->integerValue( "SMESH", "scalar_bar_orientation" ) == 1 );
1624 QString name = QString( "scalar_bar_%1_" ).arg( horiz ? "horizontal" : "vertical" );
1626 myScalarBarActor->SetOrientationToHorizontal();
1628 myScalarBarActor->SetOrientationToVertical();
1631 vtkFloatingPointType aXVal = horiz ? 0.20 : 0.01;
1632 if( mgr->hasValue( "SMESH", name + "x" ) )
1633 aXVal = mgr->doubleValue( "SMESH", name + "x", aXVal );
1635 vtkFloatingPointType aYVal = horiz ? 0.01 : 0.1;
1636 if( mgr->hasValue( "SMESH", name + "y" ) )
1637 aYVal = mgr->doubleValue( "SMESH", name + "y", aYVal );
1638 myScalarBarActor->SetPosition( aXVal, aYVal );
1640 vtkFloatingPointType aWVal = horiz ? 0.60 : 0.10;
1641 if( mgr->hasValue( "SMESH", name + "width" ) )
1642 aWVal = mgr->doubleValue( "SMESH", name + "width", aWVal );
1643 myScalarBarActor->SetWidth( aWVal );
1645 vtkFloatingPointType aHVal = horiz ? 0.12 : 0.80;
1646 if( mgr->hasValue( "SMESH", name + "height" ) )
1647 aHVal = mgr->doubleValue( "SMESH", name + "height", aHVal );
1648 myScalarBarActor->SetHeight( aHVal );
1651 if( mgr->hasValue( "SMESH", "scalar_bar_num_labels" ) )
1652 anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_labels", anIntVal );
1653 myScalarBarActor->SetNumberOfLabels( anIntVal == 0 ? 5: anIntVal );
1656 if( mgr->hasValue( "SMESH", "scalar_bar_num_colors" ) )
1657 anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_colors", anIntVal );
1658 myScalarBarActor->SetMaximumNumberOfColors( anIntVal == 0 ? 64 : anIntVal );