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 <SALOME_InteractiveObject.hxx>
38 #include "SUIT_Session.h"
39 #include "SUIT_ResourceMgr.h"
41 #include <qstringlist.h>
43 #include <vtkProperty.h>
44 #include <vtkTimeStamp.h>
45 #include <vtkObjectFactory.h>
46 #include <vtkShrinkPolyData.h>
47 #include <vtkMergeFilter.h>
49 #include <vtkMatrix4x4.h>
50 #include <vtkUnstructuredGrid.h>
51 #include <vtkPointData.h>
52 #include <vtkCellData.h>
54 #include <vtkMapper.h>
55 #include <vtkRenderer.h>
58 #include <vtkIdList.h>
59 #include <vtkIntArray.h>
61 #include <vtkActor2D.h>
62 #include <vtkProperty2D.h>
63 #include <vtkPolyData.h>
64 #include <vtkMaskPoints.h>
65 #include <vtkCellCenters.h>
66 #include <vtkTextProperty.h>
67 #include <vtkLabeledDataMapper.h>
68 #include <vtkSelectVisiblePoints.h>
70 #include <vtkScalarBarActor.h>
71 #include <vtkLookupTable.h>
75 #include <vtkImplicitBoolean.h>
76 #include <vtkImplicitFunctionCollection.h>
78 #include "utilities.h"
81 static int MYDEBUG = 1;
83 static int MYDEBUG = 0;
86 static int aLineWidthInc = 2;
87 static int aPointSizeInc = 2;
90 SMESH_ActorDef* SMESH_ActorDef::New(){
91 return new SMESH_ActorDef();
95 SMESH_Actor* SMESH_Actor::New(TVisualObjPtr theVisualObj,
100 SMESH_ActorDef* anActor = SMESH_ActorDef::New();
101 if(!anActor->Init(theVisualObj,theEntry,theName,theIsClear)){
106 anActor->UpdateScalarBar();
111 SMESH_ActorDef::SMESH_ActorDef()
113 if(MYDEBUG) MESSAGE("SMESH_ActorDef - "<<this);
115 myTimeStamp = vtkTimeStamp::New();
117 myIsPointsVisible = false;
119 myIsShrinkable = false;
122 myControlsPrecision = -1;
123 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
124 if ( mgr && mgr->booleanValue( "SMESH", "use_precision", false ) )
125 myControlsPrecision = (long)SMESH::GetFloat( "SMESH", "controls_precision", -1 );
127 vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
128 vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
130 vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
131 VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
133 //Definition 2D and 3D divices of the actor
134 //-----------------------------------------
135 vtkFloatingPointType anRGB[3] = {1,1,1};
136 mySurfaceProp = vtkProperty::New();
137 SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
138 mySurfaceProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
140 myBackSurfaceProp = vtkProperty::New();
141 SMESH::GetColor( "SMESH", "backface_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 0, 255 ) );
142 myBackSurfaceProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
144 my2DActor = SMESH_DeviceActor::New();
145 my2DActor->SetUserMatrix(aMatrix);
146 my2DActor->PickableOff();
147 my2DActor->SetProperty(mySurfaceProp);
148 my2DActor->SetBackfaceProperty(myBackSurfaceProp);
149 my2DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
150 aFilter = my2DActor->GetExtractUnstructuredGrid();
151 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
152 aFilter->RegisterCellsWithType(VTK_TRIANGLE);
153 aFilter->RegisterCellsWithType(VTK_POLYGON);
154 aFilter->RegisterCellsWithType(VTK_QUAD);
155 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
156 aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
158 my3DActor = SMESH_DeviceActor::New();
159 my3DActor->SetUserMatrix(aMatrix);
160 my3DActor->PickableOff();
161 my3DActor->SetProperty(mySurfaceProp);
162 my3DActor->SetBackfaceProperty(myBackSurfaceProp);
163 my3DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
164 aFilter = my3DActor->GetExtractUnstructuredGrid();
165 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
166 aFilter->RegisterCellsWithType(VTK_TETRA);
167 aFilter->RegisterCellsWithType(VTK_VOXEL);
168 aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
169 aFilter->RegisterCellsWithType(VTK_WEDGE);
170 aFilter->RegisterCellsWithType(VTK_PYRAMID);
171 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
172 aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
173 aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
175 //Definition 1D divice of the actor
176 //---------------------------------
177 myEdgeProp = vtkProperty::New();
178 myEdgeProp->SetAmbient(1.0);
179 myEdgeProp->SetDiffuse(0.0);
180 myEdgeProp->SetSpecular(0.0);
181 SMESH::GetColor( "SMESH", "outline_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
182 myEdgeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
183 myEdgeProp->SetLineWidth(aLineWidth);
185 my1DActor = SMESH_DeviceActor::New();
186 my1DActor->SetUserMatrix(aMatrix);
187 my1DActor->PickableOff();
188 my1DActor->SetHighlited(true);
189 my1DActor->SetProperty(myEdgeProp);
190 my1DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
191 aFilter = my1DActor->GetExtractUnstructuredGrid();
192 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
193 aFilter->RegisterCellsWithType(VTK_LINE);
194 aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
196 my1DProp = vtkProperty::New();
197 my1DProp->DeepCopy(myEdgeProp);
198 my1DProp->SetLineWidth(aLineWidth + aLineWidthInc);
199 my1DProp->SetPointSize(aPointSize);
201 my1DExtProp = vtkProperty::New();
202 my1DExtProp->DeepCopy(myEdgeProp);
203 anRGB[0] = 1 - anRGB[0];
204 anRGB[1] = 1 - anRGB[1];
205 anRGB[2] = 1 - anRGB[2];
206 my1DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
207 my1DExtProp->SetLineWidth(aLineWidth + aLineWidthInc);
208 my1DExtProp->SetPointSize(aPointSize + aPointSizeInc);
210 my1DExtActor = SMESH_DeviceActor::New();
211 my1DExtActor->SetUserMatrix(aMatrix);
212 my1DExtActor->PickableOff();
213 my1DExtActor->SetHighlited(true);
214 my1DExtActor->SetVisibility(false);
215 my1DExtActor->SetProperty(my1DExtProp);
216 my1DExtActor->SetRepresentation(SMESH_DeviceActor::eInsideframe);
217 aFilter = my1DExtActor->GetExtractUnstructuredGrid();
218 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
219 aFilter->RegisterCellsWithType(VTK_LINE);
220 aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
223 //Definition 0D divice of the actor
224 //---------------------------------
225 myNodeProp = vtkProperty::New();
226 SMESH::GetColor( "SMESH", "node_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 0, 0 ) );
227 myNodeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
228 myNodeProp->SetPointSize(aPointSize);
230 myNodeActor = SMESH_DeviceActor::New();
231 myNodeActor->SetUserMatrix(aMatrix);
232 myNodeActor->SetStoreClippingMapping(true);
233 myNodeActor->PickableOff();
234 myNodeActor->SetVisibility(false);
235 myNodeActor->SetProperty(myNodeProp);
236 myNodeActor->SetRepresentation(SMESH_DeviceActor::ePoint);
237 aFilter = myNodeActor->GetExtractUnstructuredGrid();
238 aFilter->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
241 //Definition of Pickable and Highlitable engines
242 //----------------------------------------------
244 myBaseActor = SMESH_DeviceActor::New();
245 myBaseActor->SetUserMatrix(aMatrix);
246 myBaseActor->SetStoreGemetryMapping(true);
247 myBaseActor->GetProperty()->SetOpacity(0.0);
249 myPickableActor = myBaseActor;
251 myHighlightProp = vtkProperty::New();
252 myHighlightProp->SetAmbient(1.0);
253 myHighlightProp->SetDiffuse(0.0);
254 myHighlightProp->SetSpecular(0.0);
255 SMESH::GetColor( "SMESH", "selection_object_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
256 myHighlightProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
257 myHighlightProp->SetPointSize(aPointSize);
258 myHighlightProp->SetRepresentation(1);
260 myPreselectProp = vtkProperty::New();
261 myPreselectProp->SetAmbient(1.0);
262 myPreselectProp->SetDiffuse(0.0);
263 myPreselectProp->SetSpecular(0.0);
264 SMESH::GetColor( "SMESH", "highlight_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 255, 255 ) );
265 myPreselectProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
266 myPreselectProp->SetPointSize(aPointSize);
267 myPreselectProp->SetRepresentation(1);
269 myHighlitableActor = SMESH_DeviceActor::New();
270 myHighlitableActor->SetUserMatrix(aMatrix);
271 myHighlitableActor->PickableOff();
272 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
277 myControlMode = eNone;
278 myControlActor = my2DActor;
280 //Definition of myScalarBarActor
281 //------------------------------
282 myLookupTable = vtkLookupTable::New();
283 //Fix for Bug PAL5195 - SMESH764:
284 //Controls - Aspect Ratio: incorrect colors of the best and worst values
285 myLookupTable->SetHueRange(0.667,0.0);
287 myScalarBarActor = vtkScalarBarActor::New();
288 myScalarBarActor->SetVisibility(false);
289 myScalarBarActor->SetLookupTable(myLookupTable);
292 //Incorrect "Min value" in Scalar Bar in Mesh:
293 myScalarBarActor->SetLabelFormat("%.4g");
295 mgr = SUIT_Session::session()->resourceMgr();
299 //Definition of points numbering pipeline
300 //---------------------------------------
301 myPointsNumDataSet = vtkUnstructuredGrid::New();
303 myPtsMaskPoints = vtkMaskPoints::New();
304 myPtsMaskPoints->SetInput(myPointsNumDataSet);
305 myPtsMaskPoints->SetOnRatio(1);
307 myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
308 myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
309 myPtsSelectVisiblePoints->SelectInvisibleOff();
310 myPtsSelectVisiblePoints->SetTolerance(0.1);
312 myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
313 myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
314 myPtsLabeledDataMapper->SetLabelFormat("%g");
315 myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
317 vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
318 aPtsTextProp->SetFontFamilyToTimes();
319 static int aPointsFontSize = 10;
320 aPtsTextProp->SetFontSize(aPointsFontSize);
321 aPtsTextProp->SetBold(1);
322 aPtsTextProp->SetItalic(0);
323 aPtsTextProp->SetShadow(0);
324 myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
325 aPtsTextProp->Delete();
327 myEntityMode = eAllEntity;
329 myIsPointsLabeled = false;
331 myPointLabels = vtkActor2D::New();
332 myPointLabels->SetMapper(myPtsLabeledDataMapper);
333 myPointLabels->GetProperty()->SetColor(1,1,1);
334 myPointLabels->SetVisibility(myIsPointsLabeled);
337 //Definition of cells numbering pipeline
338 //---------------------------------------
339 myCellsNumDataSet = vtkUnstructuredGrid::New();
341 myCellCenters = vtkCellCenters::New();
342 myCellCenters->SetInput(myCellsNumDataSet);
344 myClsMaskPoints = vtkMaskPoints::New();
345 myClsMaskPoints->SetInput(myCellCenters->GetOutput());
346 myClsMaskPoints->SetOnRatio(1);
348 myClsSelectVisiblePoints = vtkSelectVisiblePoints::New();
349 myClsSelectVisiblePoints->SetInput(myClsMaskPoints->GetOutput());
350 myClsSelectVisiblePoints->SelectInvisibleOff();
351 myClsSelectVisiblePoints->SetTolerance(0.1);
353 myClsLabeledDataMapper = vtkLabeledDataMapper::New();
354 myClsLabeledDataMapper->SetInput(myClsSelectVisiblePoints->GetOutput());
355 myClsLabeledDataMapper->SetLabelFormat("%g");
356 myClsLabeledDataMapper->SetLabelModeToLabelScalars();
358 vtkTextProperty* aClsTextProp = vtkTextProperty::New();
359 aClsTextProp->SetFontFamilyToTimes();
360 static int aCellsFontSize = 12;
361 aClsTextProp->SetFontSize(aCellsFontSize);
362 aClsTextProp->SetBold(1);
363 aClsTextProp->SetItalic(0);
364 aClsTextProp->SetShadow(0);
365 myClsLabeledDataMapper->SetLabelTextProperty(aClsTextProp);
366 aClsTextProp->Delete();
368 myIsCellsLabeled = false;
370 myCellsLabels = vtkActor2D::New();
371 myCellsLabels->SetMapper(myClsLabeledDataMapper);
372 myCellsLabels->GetProperty()->SetColor(0,1,0);
373 myCellsLabels->SetVisibility(myIsCellsLabeled);
376 myImplicitBoolean = vtkImplicitBoolean::New();
377 myImplicitBoolean->SetOperationTypeToIntersection();
381 SMESH_ActorDef::~SMESH_ActorDef()
383 if(MYDEBUG) MESSAGE("~SMESH_ActorDef - "<<this);
385 myScalarBarActor->Delete();
386 myLookupTable->Delete();
388 mySurfaceProp->Delete();
389 myBackSurfaceProp->Delete();
391 myEdgeProp->Delete();
392 myHighlightProp->Delete();
393 myPreselectProp->Delete();
395 myNodeProp->Delete();
400 my1DExtProp->Delete();
401 my1DExtActor->Delete();
406 myNodeActor->Delete();
407 myBaseActor->Delete();
409 myHighlitableActor->Delete();
411 //Deleting of pints numbering pipeline
412 //---------------------------------------
413 myPointsNumDataSet->Delete();
415 // commented: porting to vtk 5.0
416 // myPtsLabeledDataMapper->RemoveAllInputs();
417 myPtsLabeledDataMapper->Delete();
419 // commented: porting to vtk 5.0
420 // myPtsSelectVisiblePoints->UnRegisterAllOutputs();
421 myPtsSelectVisiblePoints->Delete();
423 // commented: porting to vtk 5.0
424 // myPtsMaskPoints->UnRegisterAllOutputs();
425 myPtsMaskPoints->Delete();
427 myPointLabels->Delete();
430 //Deleting of cells numbering pipeline
431 //---------------------------------------
432 myCellsNumDataSet->Delete();
434 myClsLabeledDataMapper->RemoveAllInputs();
435 myClsLabeledDataMapper->Delete();
437 // commented: porting to vtk 5.0
438 // myClsSelectVisiblePoints->UnRegisterAllOutputs();
439 myClsSelectVisiblePoints->Delete();
441 // commented: porting to vtk 5.0
442 // myClsMaskPoints->UnRegisterAllOutputs();
443 myClsMaskPoints->Delete();
445 // commented: porting to vtk 5.0
446 // myCellCenters->UnRegisterAllOutputs();
447 myCellCenters->Delete();
449 myCellsLabels->Delete();
451 myImplicitBoolean->Delete();
453 myTimeStamp->Delete();
457 void SMESH_ActorDef::SetPointsLabeled( bool theIsPointsLabeled )
459 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
460 myIsPointsLabeled = theIsPointsLabeled && aGrid->GetNumberOfPoints();
462 if ( myIsPointsLabeled )
464 myPointsNumDataSet->ShallowCopy(aGrid);
465 vtkDataSet *aDataSet = myPointsNumDataSet;
467 int aNbElem = aDataSet->GetNumberOfPoints();
469 vtkIntArray *anArray = vtkIntArray::New();
470 anArray->SetNumberOfValues( aNbElem );
472 for ( int anId = 0; anId < aNbElem; anId++ )
474 int aSMDSId = myVisualObj->GetNodeObjId( anId );
475 anArray->SetValue( anId, aSMDSId );
478 aDataSet->GetPointData()->SetScalars( anArray );
480 myPtsMaskPoints->SetInput( aDataSet );
481 myPointLabels->SetVisibility( GetVisibility() );
485 myPointLabels->SetVisibility( false );
487 SetRepresentation(GetRepresentation());
488 myTimeStamp->Modified();
492 void SMESH_ActorDef::SetCellsLabeled(bool theIsCellsLabeled)
494 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
495 myIsCellsLabeled = theIsCellsLabeled && aGrid->GetNumberOfPoints();
496 if(myIsCellsLabeled){
497 myCellsNumDataSet->ShallowCopy(aGrid);
498 vtkDataSet *aDataSet = myCellsNumDataSet;
499 int aNbElem = aDataSet->GetNumberOfCells();
500 vtkIntArray *anArray = vtkIntArray::New();
501 anArray->SetNumberOfValues(aNbElem);
502 for(int anId = 0; anId < aNbElem; anId++){
503 int aSMDSId = myVisualObj->GetElemObjId(anId);
504 anArray->SetValue(anId,aSMDSId);
506 aDataSet->GetCellData()->SetScalars(anArray);
507 myCellCenters->SetInput(aDataSet);
508 myCellsLabels->SetVisibility(GetVisibility());
510 myCellsLabels->SetVisibility(false);
512 myTimeStamp->Modified();
518 SetControlMode(eControl theMode)
520 SetControlMode(theMode,true);
526 SetControlMode(eControl theMode,
527 bool theCheckEntityMode)
529 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
533 myControlMode = eNone;
534 theCheckEntityMode &= mgr->booleanValue( "SMESH", "display_entity", false );
536 my1DActor->GetMapper()->SetScalarVisibility(false);
537 my2DActor->GetMapper()->SetScalarVisibility(false);
538 my3DActor->GetMapper()->SetScalarVisibility(false);
539 myScalarBarActor->SetVisibility(false);
541 bool anIsScalarVisible = theMode > eNone;
543 if(anIsScalarVisible){
544 SMESH::Controls::FunctorPtr aFunctor;
548 SMESH::Controls::Length* aControl = new SMESH::Controls::Length();
549 aControl->SetPrecision( myControlsPrecision );
550 aFunctor.reset( aControl );
551 myControlActor = my1DActor;
556 aFunctor.reset(new SMESH::Controls::Length2D());
557 myControlActor = my2DActor;
561 aFunctor.reset(new SMESH::Controls::FreeBorders());
562 myControlActor = my1DActor;
565 aFunctor.reset(new SMESH::Controls::FreeEdges());
566 myControlActor = my2DActor;
568 case eMultiConnection:
569 aFunctor.reset(new SMESH::Controls::MultiConnection());
570 myControlActor = my1DActor;
572 case eMultiConnection2D:
573 aFunctor.reset(new SMESH::Controls::MultiConnection2D());
574 myControlActor = my2DActor;
578 SMESH::Controls::Area* aControl = new SMESH::Controls::Area();
579 aControl->SetPrecision( myControlsPrecision );
580 aFunctor.reset( aControl );
581 myControlActor = my2DActor;
586 SMESH::Controls::Taper* aControl = new SMESH::Controls::Taper();
587 aControl->SetPrecision( myControlsPrecision );
588 aFunctor.reset( aControl );
589 myControlActor = my2DActor;
594 SMESH::Controls::AspectRatio* aControl = new SMESH::Controls::AspectRatio();
595 aControl->SetPrecision( myControlsPrecision );
596 aFunctor.reset( aControl );
597 myControlActor = my2DActor;
602 SMESH::Controls::AspectRatio3D* aControl = new SMESH::Controls::AspectRatio3D();
603 aControl->SetPrecision( myControlsPrecision );
604 aFunctor.reset( aControl );
605 myControlActor = my3DActor;
610 SMESH::Controls::Volume* aControl = new SMESH::Controls::Volume();
611 aControl->SetPrecision( myControlsPrecision );
612 aFunctor.reset( aControl );
613 myControlActor = my3DActor;
618 SMESH::Controls::MinimumAngle* aControl = new SMESH::Controls::MinimumAngle();
619 aControl->SetPrecision( myControlsPrecision );
620 aFunctor.reset( aControl );
621 myControlActor = my2DActor;
626 SMESH::Controls::Warping* aControl = new SMESH::Controls::Warping();
627 aControl->SetPrecision( myControlsPrecision );
628 aFunctor.reset( aControl );
629 myControlActor = my2DActor;
634 SMESH::Controls::Skew* aControl = new SMESH::Controls::Skew();
635 aControl->SetPrecision( myControlsPrecision );
636 aFunctor.reset( aControl );
637 myControlActor = my2DActor;
644 vtkUnstructuredGrid* aGrid = myControlActor->GetUnstructuredGrid();
645 vtkIdType aNbCells = aGrid->GetNumberOfCells();
647 myControlMode = theMode;
648 switch(myControlMode){
651 my1DExtActor->SetExtControlMode(aFunctor);
654 case eMultiConnection2D:
655 my1DExtActor->SetExtControlMode(aFunctor,myScalarBarActor,myLookupTable);
658 myControlActor->SetControlMode(aFunctor,myScalarBarActor,myLookupTable);
662 if(theCheckEntityMode){
663 if(myControlActor == my1DActor)
664 SetEntityMode(eEdges);
665 else if(myControlActor == my2DActor){
666 switch(myControlMode){
669 case eMultiConnection2D:
670 //SetEntityMode(eEdges);
671 SetEntityMode(eFaces);
674 SetEntityMode(eFaces);
676 }else if(myControlActor == my3DActor)
677 SetEntityMode(eVolumes);
680 }else if(theCheckEntityMode){
681 myEntityMode = eAllEntity;
684 SetRepresentation(GetRepresentation());
686 myTimeStamp->Modified();
691 void SMESH_ActorDef::AddToRender(vtkRenderer* theRenderer){
692 SALOME_Actor::AddToRender(theRenderer);
694 theRenderer->AddActor(myNodeActor);
695 theRenderer->AddActor(myBaseActor);
697 theRenderer->AddActor(my3DActor);
698 theRenderer->AddActor(my2DActor);
700 theRenderer->AddActor(my1DActor);
701 theRenderer->AddActor(my1DExtActor);
703 theRenderer->AddActor(myHighlitableActor);
705 theRenderer->AddActor2D(myScalarBarActor);
707 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
708 myClsSelectVisiblePoints->SetRenderer(theRenderer);
710 theRenderer->AddActor2D(myPointLabels);
711 theRenderer->AddActor2D(myCellsLabels);
714 void SMESH_ActorDef::RemoveFromRender(vtkRenderer* theRenderer){
715 SALOME_Actor::RemoveFromRender(theRenderer);
717 theRenderer->RemoveActor(myNodeActor);
718 theRenderer->RemoveActor(myBaseActor);
720 theRenderer->RemoveActor(myHighlitableActor);
722 theRenderer->RemoveActor(my1DActor);
723 theRenderer->RemoveActor(my1DExtActor);
725 theRenderer->RemoveActor(my2DActor);
726 theRenderer->RemoveActor(my3DActor);
728 theRenderer->RemoveActor(myScalarBarActor);
729 theRenderer->RemoveActor(myPointLabels);
730 theRenderer->RemoveActor(myCellsLabels);
734 bool SMESH_ActorDef::Init(TVisualObjPtr theVisualObj,
735 const char* theEntry,
739 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry,"SMESH",theName);
743 myVisualObj = theVisualObj;
744 myVisualObj->Update(theIsClear);
746 myNodeActor->Init(myVisualObj,myImplicitBoolean);
747 myBaseActor->Init(myVisualObj,myImplicitBoolean);
749 myHighlitableActor->Init(myVisualObj,myImplicitBoolean);
751 my1DActor->Init(myVisualObj,myImplicitBoolean);
752 my1DExtActor->Init(myVisualObj,myImplicitBoolean);
754 my2DActor->Init(myVisualObj,myImplicitBoolean);
755 my3DActor->Init(myVisualObj,myImplicitBoolean);
757 my1DActor->GetMapper()->SetLookupTable(myLookupTable);
758 my1DExtActor->GetMapper()->SetLookupTable(myLookupTable);
760 my2DActor->GetMapper()->SetLookupTable(myLookupTable);
761 my3DActor->GetMapper()->SetLookupTable(myLookupTable);
763 vtkFloatingPointType aFactor, aUnits;
764 my2DActor->GetPolygonOffsetParameters(aFactor,aUnits);
765 my2DActor->SetPolygonOffsetParameters(aFactor,aUnits*0.75);
767 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
771 //SetIsShrunkable(theGrid->GetNumberOfCells() > 10);
772 SetIsShrunkable(true);
774 SetShrinkFactor( SMESH::GetFloat( "SMESH:shrink_coeff", 0.75 ) );
776 int aMode = mgr->integerValue( "SMESH", "display_mode" );
777 SetRepresentation(-1);
780 SetRepresentation(eEdge);
781 }else if(aMode == 1){
782 SetRepresentation(eSurface);
783 }else if(aMode == 2){
784 SetRepresentation(ePoint);
791 myTimeStamp->Modified();
797 vtkFloatingPointType* SMESH_ActorDef::GetBounds(){
798 return myNodeActor->GetBounds();
802 vtkDataSet* SMESH_ActorDef::GetInput(){
803 return GetUnstructuredGrid();
807 void SMESH_ActorDef::SetTransform(VTKViewer_Transform* theTransform){
808 Superclass::SetTransform(theTransform);
810 myNodeActor->SetTransform(theTransform);
811 myBaseActor->SetTransform(theTransform);
813 myHighlitableActor->SetTransform(theTransform);
815 my1DActor->SetTransform(theTransform);
816 my1DExtActor->SetTransform(theTransform);
818 my2DActor->SetTransform(theTransform);
819 my3DActor->SetTransform(theTransform);
825 void SMESH_ActorDef::SetMapper(vtkMapper* theMapper){
826 vtkLODActor::SetMapper(theMapper);
830 void SMESH_ActorDef::ShallowCopy(vtkProp *prop){
831 SALOME_Actor::ShallowCopy(prop);
835 vtkMapper* SMESH_ActorDef::GetMapper(){
836 return myPickableActor->GetMapper();
840 vtkUnstructuredGrid* SMESH_ActorDef::GetUnstructuredGrid(){
841 return myVisualObj->GetUnstructuredGrid();
845 bool SMESH_ActorDef::IsInfinitive(){
846 vtkDataSet *aDataSet = myPickableActor->GetUnstructuredGrid();
848 myIsInfinite = aDataSet->GetNumberOfCells() == 0 ||
849 aDataSet->GetNumberOfCells() == 1 &&
850 aDataSet->GetCell(0)->GetCellType() == VTK_VERTEX;
851 return SALOME_Actor::IsInfinitive();
855 void SMESH_ActorDef::SetIsShrunkable(bool theShrunkable){
856 if ( myIsShrinkable == theShrunkable )
858 myIsShrinkable = theShrunkable;
862 vtkFloatingPointType SMESH_ActorDef::GetShrinkFactor(){
863 return myBaseActor->GetShrinkFactor();
866 void SMESH_ActorDef::SetShrinkFactor(vtkFloatingPointType theValue){
867 myBaseActor->SetShrinkFactor(theValue);
869 my1DActor->SetShrinkFactor(theValue);
870 my1DExtActor->SetShrinkFactor(theValue);
872 my2DActor->SetShrinkFactor(theValue);
873 my3DActor->SetShrinkFactor(theValue);
878 void SMESH_ActorDef::SetShrink(){
879 if(!myIsShrinkable) return;
881 myBaseActor->SetShrink();
883 my1DActor->SetShrink();
884 my1DExtActor->SetShrink();
886 my2DActor->SetShrink();
887 my3DActor->SetShrink();
893 void SMESH_ActorDef::UnShrink(){
894 if(!myIsShrunk) return;
896 myBaseActor->UnShrink();
898 my1DActor->UnShrink();
899 my1DExtActor->UnShrink();
901 my2DActor->UnShrink();
902 my3DActor->UnShrink();
909 int SMESH_ActorDef::GetNodeObjId(int theVtkID){
910 return myPickableActor->GetNodeObjId(theVtkID);
913 vtkFloatingPointType* SMESH_ActorDef::GetNodeCoord(int theObjID){
914 return myPickableActor->GetNodeCoord(theObjID);
918 int SMESH_ActorDef::GetElemObjId(int theVtkID){
919 return myPickableActor->GetElemObjId(theVtkID);
922 vtkCell* SMESH_ActorDef::GetElemCell(int theObjID){
923 return myPickableActor->GetElemCell(theObjID);
927 void SMESH_ActorDef::SetVisibility(int theMode){
928 SetVisibility(theMode,true);
932 void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation){
933 SALOME_Actor::SetVisibility(theMode);
935 myNodeActor->VisibilityOff();
936 myBaseActor->VisibilityOff();
938 my1DActor->VisibilityOff();
939 my1DExtActor->VisibilityOff();
941 my2DActor->VisibilityOff();
942 my3DActor->VisibilityOff();
944 myScalarBarActor->VisibilityOff();
945 myPointLabels->VisibilityOff();
946 myCellsLabels->VisibilityOff();
949 if(theIsUpdateRepersentation)
950 SetRepresentation(GetRepresentation());
952 if(myControlMode != eNone){
953 switch(myControlMode){
956 my1DExtActor->VisibilityOn();
959 case eMultiConnection2D:
960 my1DExtActor->VisibilityOn();
962 if(myControlActor->GetUnstructuredGrid()->GetNumberOfCells())
963 myScalarBarActor->VisibilityOn();
967 if(myRepresentation != ePoint)
968 myPickableActor->VisibilityOn();
970 myNodeActor->VisibilityOn();
973 if(myEntityMode & eEdges){
974 my1DActor->VisibilityOn();
977 if(myEntityMode & eFaces){
978 my2DActor->VisibilityOn();
981 if(myEntityMode & eVolumes){
982 my3DActor->VisibilityOn();
985 if(myIsPointsLabeled){
986 myPointLabels->VisibilityOn();
987 myNodeActor->VisibilityOn();
991 myCellsLabels->VisibilityOn();
998 void SMESH_ActorDef::SetEntityMode(unsigned int theMode){
999 myEntityState = eAllEntity;
1001 if(!myVisualObj->GetNbEntities(SMDSAbs_Edge)){
1002 myEntityState &= ~eEdges;
1006 if(!myVisualObj->GetNbEntities(SMDSAbs_Face)){
1007 myEntityState &= ~eFaces;
1011 if(!myVisualObj->GetNbEntities(SMDSAbs_Volume)){
1012 myEntityState &= ~eVolumes;
1013 theMode &= ~eVolumes;
1017 if(myVisualObj->GetNbEntities(SMDSAbs_Edge))
1020 if(myVisualObj->GetNbEntities(SMDSAbs_Face))
1023 if(myVisualObj->GetNbEntities(SMDSAbs_Volume))
1024 theMode |= eVolumes;
1027 myBaseActor->myGeomFilter->SetInside(myEntityMode != myEntityState);
1029 myEntityMode = theMode;
1030 VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
1031 aFilter = myBaseActor->GetExtractUnstructuredGrid();
1032 aFilter->ClearRegisteredCellsWithType();
1033 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
1035 if(myEntityMode & eEdges){
1036 if (MYDEBUG) MESSAGE("EDGES");
1037 aFilter->RegisterCellsWithType(VTK_LINE);
1038 aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
1041 if(myEntityMode & eFaces){
1042 if (MYDEBUG) MESSAGE("FACES");
1043 aFilter->RegisterCellsWithType(VTK_TRIANGLE);
1044 aFilter->RegisterCellsWithType(VTK_POLYGON);
1045 aFilter->RegisterCellsWithType(VTK_QUAD);
1046 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
1047 aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
1050 if(myEntityMode & eVolumes){
1051 if (MYDEBUG) MESSAGE("VOLUMES");
1052 aFilter->RegisterCellsWithType(VTK_TETRA);
1053 aFilter->RegisterCellsWithType(VTK_VOXEL);
1054 aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1055 aFilter->RegisterCellsWithType(VTK_WEDGE);
1056 aFilter->RegisterCellsWithType(VTK_PYRAMID);
1057 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
1058 aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
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 );