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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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 <vtkTimeStamp.h>
42 #include <vtkObjectFactory.h>
43 #include <vtkShrinkPolyData.h>
44 #include <vtkMergeFilter.h>
46 #include <vtkMatrix4x4.h>
47 #include <vtkUnstructuredGrid.h>
48 #include <vtkPointData.h>
49 #include <vtkCellData.h>
51 #include <vtkMapper.h>
52 #include <vtkRenderer.h>
55 #include <vtkIdList.h>
56 #include <vtkIntArray.h>
58 #include <vtkActor2D.h>
59 #include <vtkProperty2D.h>
60 #include <vtkPolyData.h>
61 #include <vtkMaskPoints.h>
62 #include <vtkCellCenters.h>
63 #include <vtkTextProperty.h>
64 #include <vtkLabeledDataMapper.h>
65 #include <vtkSelectVisiblePoints.h>
67 #include <vtkScalarBarActor.h>
68 #include <vtkLookupTable.h>
72 #include <vtkImplicitBoolean.h>
73 #include <vtkImplicitFunctionCollection.h>
75 #include "utilities.h"
78 static int MYDEBUG = 1;
80 static int MYDEBUG = 0;
83 static int aLineWidthInc = 2;
84 static int aPointSizeInc = 2;
87 SMESH_ActorDef* SMESH_ActorDef::New(){
88 return new SMESH_ActorDef();
92 SMESH_Actor* SMESH_Actor::New(TVisualObjPtr theVisualObj,
97 SMESH_ActorDef* anActor = SMESH_ActorDef::New();
98 if(!anActor->Init(theVisualObj,theEntry,theName,theIsClear)){
106 SMESH_ActorDef::SMESH_ActorDef()
108 if(MYDEBUG) MESSAGE("SMESH_ActorDef - "<<this);
110 myTimeStamp = vtkTimeStamp::New();
112 myIsPointsVisible = false;
114 myIsShrinkable = false;
117 myControlsPrecision = (long)SMESH::GetFloat( "SMESH:controls_precision", -1 );
119 float aPointSize = SMESH::GetFloat("SMESH:node_size",3);
120 float aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
122 vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
123 VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
125 //Definition 2D and 3D divices of the actor
126 //-----------------------------------------
127 float anRGB[3] = {1,1,1};
128 mySurfaceProp = vtkProperty::New();
129 SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
130 mySurfaceProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
132 myBackSurfaceProp = vtkProperty::New();
133 SMESH::GetColor( "SMESH", "backface_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 0, 255 ) );
134 myBackSurfaceProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
136 my2DActor = SMESH_DeviceActor::New();
137 my2DActor->SetUserMatrix(aMatrix);
138 my2DActor->PickableOff();
139 my2DActor->SetProperty(mySurfaceProp);
140 my2DActor->SetBackfaceProperty(myBackSurfaceProp);
141 my2DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
142 aFilter = my2DActor->GetExtractUnstructuredGrid();
143 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
144 aFilter->RegisterCellsWithType(VTK_TRIANGLE);
145 aFilter->RegisterCellsWithType(VTK_POLYGON);
146 aFilter->RegisterCellsWithType(VTK_QUAD);
148 my3DActor = SMESH_DeviceActor::New();
149 my3DActor->SetUserMatrix(aMatrix);
150 my3DActor->PickableOff();
151 my3DActor->SetProperty(mySurfaceProp);
152 my3DActor->SetBackfaceProperty(myBackSurfaceProp);
153 my3DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
154 aFilter = my3DActor->GetExtractUnstructuredGrid();
155 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
156 aFilter->RegisterCellsWithType(VTK_TETRA);
157 aFilter->RegisterCellsWithType(VTK_VOXEL);
158 aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
159 aFilter->RegisterCellsWithType(VTK_WEDGE);
160 aFilter->RegisterCellsWithType(VTK_PYRAMID);
161 aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
163 //Definition 1D divice of the actor
164 //---------------------------------
165 myEdgeProp = vtkProperty::New();
166 myEdgeProp->SetAmbient(1.0);
167 myEdgeProp->SetDiffuse(0.0);
168 myEdgeProp->SetSpecular(0.0);
169 SMESH::GetColor( "SMESH", "outline_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
170 myEdgeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
171 myEdgeProp->SetLineWidth(aLineWidth);
173 my1DActor = SMESH_DeviceActor::New();
174 my1DActor->SetUserMatrix(aMatrix);
175 my1DActor->PickableOff();
176 my1DActor->SetHighlited(true);
177 my1DActor->SetProperty(myEdgeProp);
178 my1DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
179 aFilter = my1DActor->GetExtractUnstructuredGrid();
180 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
181 aFilter->RegisterCellsWithType(VTK_LINE);
183 my1DProp = vtkProperty::New();
184 my1DProp->DeepCopy(myEdgeProp);
185 my1DProp->SetLineWidth(aLineWidth + aLineWidthInc);
186 my1DProp->SetPointSize(aPointSize);
188 my1DExtProp = vtkProperty::New();
189 my1DExtProp->DeepCopy(myEdgeProp);
190 anRGB[0] = 1 - anRGB[0];
191 anRGB[1] = 1 - anRGB[1];
192 anRGB[2] = 1 - anRGB[2];
193 my1DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
194 my1DExtProp->SetLineWidth(aLineWidth + aLineWidthInc);
195 my1DExtProp->SetPointSize(aPointSize + aPointSizeInc);
197 my1DExtActor = SMESH_DeviceActor::New();
198 my1DExtActor->SetUserMatrix(aMatrix);
199 my1DExtActor->PickableOff();
200 my1DExtActor->SetHighlited(true);
201 my1DExtActor->SetVisibility(false);
202 my1DExtActor->SetProperty(my1DExtProp);
203 my1DExtActor->SetRepresentation(SMESH_DeviceActor::eInsideframe);
204 aFilter = my1DExtActor->GetExtractUnstructuredGrid();
205 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
206 aFilter->RegisterCellsWithType(VTK_LINE);
209 //Definition 0D divice of the actor
210 //---------------------------------
211 myNodeProp = vtkProperty::New();
212 SMESH::GetColor( "SMESH", "node_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 0, 0 ) );
213 myNodeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
214 myNodeProp->SetPointSize(aPointSize);
216 myNodeActor = SMESH_DeviceActor::New();
217 myNodeActor->SetUserMatrix(aMatrix);
218 myNodeActor->SetStoreClippingMapping(true);
219 myNodeActor->PickableOff();
220 myNodeActor->SetVisibility(false);
221 myNodeActor->SetProperty(myNodeProp);
222 myNodeActor->SetRepresentation(SMESH_DeviceActor::ePoint);
223 aFilter = myNodeActor->GetExtractUnstructuredGrid();
224 aFilter->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
227 //Definition of Pickable and Highlitable engines
228 //----------------------------------------------
230 myBaseActor = SMESH_DeviceActor::New();
231 myBaseActor->SetUserMatrix(aMatrix);
232 myBaseActor->SetStoreGemetryMapping(true);
233 myBaseActor->GetProperty()->SetOpacity(0.0);
235 myPickableActor = myBaseActor;
237 myHighlightProp = vtkProperty::New();
238 myHighlightProp->SetAmbient(1.0);
239 myHighlightProp->SetDiffuse(0.0);
240 myHighlightProp->SetSpecular(0.0);
241 SMESH::GetColor( "SMESH", "selection_object_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
242 myHighlightProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
243 myHighlightProp->SetPointSize(aPointSize);
244 myHighlightProp->SetRepresentation(1);
246 myPreselectProp = vtkProperty::New();
247 myPreselectProp->SetAmbient(1.0);
248 myPreselectProp->SetDiffuse(0.0);
249 myPreselectProp->SetSpecular(0.0);
250 SMESH::GetColor( "SMESH", "highlight_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 255, 255 ) );
251 myPreselectProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
252 myPreselectProp->SetPointSize(aPointSize);
253 myPreselectProp->SetRepresentation(1);
255 myHighlitableActor = SMESH_DeviceActor::New();
256 myHighlitableActor->SetUserMatrix(aMatrix);
257 myHighlitableActor->PickableOff();
258 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
260 SetShrinkFactor( SMESH::GetFloat( "SMESH", "shrink_coeff", 0.75 ) );
265 myControlMode = eNone;
266 myControlActor = my2DActor;
268 //Definition of myScalarBarActor
269 //------------------------------
270 myLookupTable = vtkLookupTable::New();
271 //Fix for Bug PAL5195 - SMESH764:
272 //Controls - Aspect Ratio: incorrect colors of the best and worst values
273 myLookupTable->SetHueRange(0.667,0.0);
275 myScalarBarActor = vtkScalarBarActor::New();
276 myScalarBarActor->SetVisibility(false);
277 myScalarBarActor->SetLookupTable(myLookupTable);
279 vtkTextProperty* aScalarBarTitleProp = vtkTextProperty::New();
281 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
285 QColor aTColor = mgr->colorValue( "SMESH", "ScalarBarTitleColor", QColor( 255, 255, 255 ) );
286 aScalarBarTitleProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
288 aScalarBarTitleProp->SetFontFamilyToArial();
290 if ( mgr->hasValue( "SMESH", "ScalarBarTitleFont" ) )
292 QString str = mgr->stringValue( "SMESH", "ScalarBarTitleFont" );
293 if ( str == "Arial" )
294 aScalarBarTitleProp->SetFontFamilyToArial();
295 else if ( str == "Courier" )
296 aScalarBarTitleProp->SetFontFamilyToCourier();
297 else if ( str == "Times" )
298 aScalarBarTitleProp->SetFontFamilyToTimes();
301 if ( mgr->booleanValue( "SMESH", "ScalarBarTitleBold" ) )
302 aScalarBarTitleProp->BoldOn();
304 aScalarBarTitleProp->BoldOff();
306 if ( mgr->booleanValue( "SMESH", "ScalarBarTitleItalic" ) )
307 aScalarBarTitleProp->ItalicOn();
309 aScalarBarTitleProp->ItalicOff();
311 if ( mgr->booleanValue( "SMESH", "ScalarBarTitleShadow" ) )
312 aScalarBarTitleProp->ShadowOn();
314 aScalarBarTitleProp->ShadowOff();
316 myScalarBarActor->SetTitleTextProperty( aScalarBarTitleProp );
317 aScalarBarTitleProp->Delete();
319 vtkTextProperty* aScalarBarLabelProp = vtkTextProperty::New();
321 aTColor = mgr->colorValue( "SMESH", "ScalarBarLabelColor", QColor( 255, 255, 255 ) );
322 aScalarBarLabelProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
324 aScalarBarLabelProp->SetFontFamilyToArial();
325 if( mgr->hasValue( "SMESH", "ScalarBarLabelFont" ) )
327 QString str = mgr->stringValue( "SMESH", "ScalarBarLabelFont" );
329 aScalarBarLabelProp->SetFontFamilyToArial();
330 else if( str == "Courier" )
331 aScalarBarLabelProp->SetFontFamilyToCourier();
332 else if( str == "Times" )
333 aScalarBarLabelProp->SetFontFamilyToTimes();
336 if ( mgr->booleanValue( "SMESH", "ScalarBarLabelBold" ) )
337 aScalarBarLabelProp->BoldOn();
339 aScalarBarLabelProp->BoldOff();
341 if ( mgr->booleanValue( "SMESH", "ScalarBarLabelItalic" ) )
342 aScalarBarLabelProp->ItalicOn();
344 aScalarBarLabelProp->ItalicOff();
346 if( mgr->booleanValue( "SMESH", "ScalarBarLabelShadow" ) )
347 aScalarBarLabelProp->ShadowOn();
349 aScalarBarLabelProp->ShadowOff();
351 myScalarBarActor->SetLabelTextProperty( aScalarBarLabelProp );
352 aScalarBarLabelProp->Delete();
354 if( mgr->stringValue( "SMESH", "ScalarBarOrientation" ) == "Horizontal" )
355 myScalarBarActor->SetOrientationToHorizontal();
357 myScalarBarActor->SetOrientationToVertical();
359 float aXVal = mgr->stringValue( "SMESH", "ScalarBarOrientation" ) == "Horizontal" ? 0.20 : 0.01;
360 if( mgr->hasValue( "SMESH", "ScalarBarXPosition" ) )
361 aXVal = mgr->doubleValue( "SMESH", "ScalarBarXPosition", aXVal );
362 float aYVal = mgr->stringValue( "SMESH", "ScalarBarOrientation" ) == "Horizontal" ? 0.01 : 0.1;
363 if( mgr->hasValue( "SMESH", "ScalarBarYPosition" ) )
364 aYVal = mgr->doubleValue( "SMESH", "ScalarBarYPosition", aYVal );
365 myScalarBarActor->SetPosition( aXVal, aYVal );
367 float aWVal = mgr->stringValue( "SMESH", "ScalarBarOrientation" ) == "Horizontal" ? 0.60 : 0.10;
368 if( mgr->hasValue( "SMESH", "ScalarBarWidth" ) )
369 aWVal = mgr->doubleValue( "SMESH", "ScalarBarWidth", aWVal );
370 myScalarBarActor->SetWidth( aWVal );
372 float aHVal = mgr->stringValue( "SMESH", "ScalarBarOrientation" ) == "Horizontal" ? 0.12 : 0.80;
373 if( mgr->hasValue( "SMESH", "ScalarBarHeight" ) )
374 aHVal = mgr->doubleValue( "SMESH", "ScalarBarHeight", aHVal );
375 myScalarBarActor->SetHeight( aHVal );
378 if( mgr->hasValue( "SMESH", "ScalarBarNbOfLabels" ) )
379 anIntVal = mgr->integerValue( "SMESH", "ScalarBarNbOfLabels", anIntVal );
380 myScalarBarActor->SetNumberOfLabels( anIntVal == 0 ? 5: anIntVal );
383 if( mgr->hasValue( "SMESH", "ScalarBarNbOfColors" ) )
384 anIntVal = mgr->integerValue( "SMESH", "ScalarBarNbOfColors", anIntVal );
385 myScalarBarActor->SetMaximumNumberOfColors( anIntVal == 0 ? 64 : anIntVal );
388 //Definition of points numbering pipeline
389 //---------------------------------------
390 myPointsNumDataSet = vtkUnstructuredGrid::New();
392 myPtsMaskPoints = vtkMaskPoints::New();
393 myPtsMaskPoints->SetInput(myPointsNumDataSet);
394 myPtsMaskPoints->SetOnRatio(1);
396 myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
397 myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
398 myPtsSelectVisiblePoints->SelectInvisibleOff();
399 myPtsSelectVisiblePoints->SetTolerance(0.1);
401 myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
402 myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
403 myPtsLabeledDataMapper->SetLabelFormat("%g");
404 myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
406 vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
407 aPtsTextProp->SetFontFamilyToTimes();
408 static int aPointsFontSize = 10;
409 aPtsTextProp->SetFontSize(aPointsFontSize);
410 aPtsTextProp->SetBold(1);
411 aPtsTextProp->SetItalic(0);
412 aPtsTextProp->SetShadow(0);
413 myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
414 aPtsTextProp->Delete();
416 myEntityMode = eAllEntity;
418 myIsPointsLabeled = false;
420 myPointLabels = vtkActor2D::New();
421 myPointLabels->SetMapper(myPtsLabeledDataMapper);
422 myPointLabels->GetProperty()->SetColor(1,1,1);
423 myPointLabels->SetVisibility(myIsPointsLabeled);
426 //Definition of cells numbering pipeline
427 //---------------------------------------
428 myCellsNumDataSet = vtkUnstructuredGrid::New();
430 myCellCenters = vtkCellCenters::New();
431 myCellCenters->SetInput(myCellsNumDataSet);
433 myClsMaskPoints = vtkMaskPoints::New();
434 myClsMaskPoints->SetInput(myCellCenters->GetOutput());
435 myClsMaskPoints->SetOnRatio(1);
437 myClsSelectVisiblePoints = vtkSelectVisiblePoints::New();
438 myClsSelectVisiblePoints->SetInput(myClsMaskPoints->GetOutput());
439 myClsSelectVisiblePoints->SelectInvisibleOff();
440 myClsSelectVisiblePoints->SetTolerance(0.1);
442 myClsLabeledDataMapper = vtkLabeledDataMapper::New();
443 myClsLabeledDataMapper->SetInput(myClsSelectVisiblePoints->GetOutput());
444 myClsLabeledDataMapper->SetLabelFormat("%g");
445 myClsLabeledDataMapper->SetLabelModeToLabelScalars();
447 vtkTextProperty* aClsTextProp = vtkTextProperty::New();
448 aClsTextProp->SetFontFamilyToTimes();
449 static int aCellsFontSize = 12;
450 aClsTextProp->SetFontSize(aCellsFontSize);
451 aClsTextProp->SetBold(1);
452 aClsTextProp->SetItalic(0);
453 aClsTextProp->SetShadow(0);
454 myClsLabeledDataMapper->SetLabelTextProperty(aClsTextProp);
455 aClsTextProp->Delete();
457 myIsCellsLabeled = false;
459 myCellsLabels = vtkActor2D::New();
460 myCellsLabels->SetMapper(myClsLabeledDataMapper);
461 myCellsLabels->GetProperty()->SetColor(0,1,0);
462 myCellsLabels->SetVisibility(myIsCellsLabeled);
465 myImplicitBoolean = vtkImplicitBoolean::New();
466 myImplicitBoolean->SetOperationTypeToIntersection();
470 SMESH_ActorDef::~SMESH_ActorDef()
472 if(MYDEBUG) MESSAGE("~SMESH_ActorDef - "<<this);
474 myScalarBarActor->Delete();
475 myLookupTable->Delete();
477 mySurfaceProp->Delete();
478 myBackSurfaceProp->Delete();
480 myEdgeProp->Delete();
481 myHighlightProp->Delete();
482 myPreselectProp->Delete();
484 myNodeProp->Delete();
489 my1DExtProp->Delete();
490 my1DExtActor->Delete();
495 myNodeActor->Delete();
496 myBaseActor->Delete();
498 myHighlitableActor->Delete();
500 //Deleting of pints numbering pipeline
501 //---------------------------------------
502 myPointsNumDataSet->Delete();
504 myPtsLabeledDataMapper->RemoveAllInputs();
505 myPtsLabeledDataMapper->Delete();
507 myPtsSelectVisiblePoints->UnRegisterAllOutputs();
508 myPtsSelectVisiblePoints->Delete();
510 myPtsMaskPoints->UnRegisterAllOutputs();
511 myPtsMaskPoints->Delete();
513 myPointLabels->Delete();
516 //Deleting of cells numbering pipeline
517 //---------------------------------------
518 myCellsNumDataSet->Delete();
520 myClsLabeledDataMapper->RemoveAllInputs();
521 myClsLabeledDataMapper->Delete();
523 myClsSelectVisiblePoints->UnRegisterAllOutputs();
524 myClsSelectVisiblePoints->Delete();
526 myClsMaskPoints->UnRegisterAllOutputs();
527 myClsMaskPoints->Delete();
529 myCellCenters->UnRegisterAllOutputs();
530 myCellCenters->Delete();
532 myCellsLabels->Delete();
534 myImplicitBoolean->Delete();
536 myTimeStamp->Delete();
540 void SMESH_ActorDef::SetPointsLabeled( bool theIsPointsLabeled )
542 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
543 myIsPointsLabeled = theIsPointsLabeled && aGrid->GetNumberOfPoints();
545 if ( myIsPointsLabeled )
547 myPointsNumDataSet->ShallowCopy(aGrid);
548 vtkDataSet *aDataSet = myPointsNumDataSet;
550 int aNbElem = aDataSet->GetNumberOfPoints();
552 vtkIntArray *anArray = vtkIntArray::New();
553 anArray->SetNumberOfValues( aNbElem );
555 for ( int anId = 0; anId < aNbElem; anId++ )
557 int aSMDSId = myVisualObj->GetNodeObjId( anId );
558 anArray->SetValue( anId, aSMDSId );
561 aDataSet->GetPointData()->SetScalars( anArray );
563 myPtsMaskPoints->SetInput( aDataSet );
564 myPointLabels->SetVisibility( GetVisibility() );
568 myPointLabels->SetVisibility( false );
570 SetRepresentation(GetRepresentation());
571 myTimeStamp->Modified();
575 void SMESH_ActorDef::SetCellsLabeled(bool theIsCellsLabeled)
577 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
578 myIsCellsLabeled = theIsCellsLabeled && aGrid->GetNumberOfPoints();
579 if(myIsCellsLabeled){
580 myCellsNumDataSet->ShallowCopy(aGrid);
581 vtkDataSet *aDataSet = myCellsNumDataSet;
582 int aNbElem = aDataSet->GetNumberOfCells();
583 vtkIntArray *anArray = vtkIntArray::New();
584 anArray->SetNumberOfValues(aNbElem);
585 for(int anId = 0; anId < aNbElem; anId++){
586 int aSMDSId = myVisualObj->GetElemObjId(anId);
587 anArray->SetValue(anId,aSMDSId);
589 aDataSet->GetCellData()->SetScalars(anArray);
590 myCellCenters->SetInput(aDataSet);
591 myCellsLabels->SetVisibility(GetVisibility());
593 myCellsLabels->SetVisibility(false);
595 myTimeStamp->Modified();
601 SetControlMode(eControl theMode)
603 SetControlMode(theMode,true);
609 SetControlMode(eControl theMode,
610 bool theCheckEntityMode)
612 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
616 myControlMode = eNone;
617 theCheckEntityMode &= mgr->booleanValue( "SMESH", "display_entity", false );
619 my1DActor->GetMapper()->SetScalarVisibility(false);
620 my2DActor->GetMapper()->SetScalarVisibility(false);
621 my3DActor->GetMapper()->SetScalarVisibility(false);
622 myScalarBarActor->SetVisibility(false);
624 bool anIsScalarVisible = theMode > eNone;
626 if(anIsScalarVisible){
627 SMESH::Controls::FunctorPtr aFunctor;
631 SMESH::Controls::Length* aControl = new SMESH::Controls::Length();
632 aControl->SetPrecision( myControlsPrecision );
633 aFunctor.reset( aControl );
634 myControlActor = my1DActor;
639 aFunctor.reset(new SMESH::Controls::Length2D());
640 myControlActor = my2DActor;
644 aFunctor.reset(new SMESH::Controls::FreeBorders());
645 myControlActor = my1DActor;
648 aFunctor.reset(new SMESH::Controls::FreeEdges());
649 myControlActor = my2DActor;
651 case eMultiConnection:
652 aFunctor.reset(new SMESH::Controls::MultiConnection());
653 myControlActor = my1DActor;
655 case eMultiConnection2D:
656 aFunctor.reset(new SMESH::Controls::MultiConnection2D());
657 myControlActor = my2DActor;
661 SMESH::Controls::Area* aControl = new SMESH::Controls::Area();
662 aControl->SetPrecision( myControlsPrecision );
663 aFunctor.reset( aControl );
664 myControlActor = my2DActor;
669 SMESH::Controls::Taper* aControl = new SMESH::Controls::Taper();
670 aControl->SetPrecision( myControlsPrecision );
671 aFunctor.reset( aControl );
672 myControlActor = my2DActor;
677 SMESH::Controls::AspectRatio* aControl = new SMESH::Controls::AspectRatio();
678 aControl->SetPrecision( myControlsPrecision );
679 aFunctor.reset( aControl );
680 myControlActor = my2DActor;
685 SMESH::Controls::AspectRatio3D* aControl = new SMESH::Controls::AspectRatio3D();
686 aControl->SetPrecision( myControlsPrecision );
687 aFunctor.reset( aControl );
688 myControlActor = my3DActor;
693 SMESH::Controls::MinimumAngle* aControl = new SMESH::Controls::MinimumAngle();
694 aControl->SetPrecision( myControlsPrecision );
695 aFunctor.reset( aControl );
696 myControlActor = my2DActor;
701 SMESH::Controls::Warping* aControl = new SMESH::Controls::Warping();
702 aControl->SetPrecision( myControlsPrecision );
703 aFunctor.reset( aControl );
704 myControlActor = my2DActor;
709 SMESH::Controls::Skew* aControl = new SMESH::Controls::Skew();
710 aControl->SetPrecision( myControlsPrecision );
711 aFunctor.reset( aControl );
712 myControlActor = my2DActor;
719 vtkUnstructuredGrid* aGrid = myControlActor->GetUnstructuredGrid();
720 vtkIdType aNbCells = aGrid->GetNumberOfCells();
722 myControlMode = theMode;
723 switch(myControlMode){
726 my1DExtActor->SetExtControlMode(aFunctor);
729 case eMultiConnection2D:
730 my1DExtActor->SetExtControlMode(aFunctor,myScalarBarActor,myLookupTable);
733 myControlActor->SetControlMode(aFunctor,myScalarBarActor,myLookupTable);
737 if(theCheckEntityMode){
738 if(myControlActor == my1DActor)
739 SetEntityMode(eEdges);
740 else if(myControlActor == my2DActor){
741 switch(myControlMode){
744 case eMultiConnection2D:
745 //SetEntityMode(eEdges);
746 SetEntityMode(eFaces);
749 SetEntityMode(eFaces);
751 }else if(myControlActor == my3DActor)
752 SetEntityMode(eVolumes);
755 }else if(theCheckEntityMode){
756 myEntityMode = eAllEntity;
759 SetRepresentation(GetRepresentation());
761 myTimeStamp->Modified();
766 void SMESH_ActorDef::AddToRender(vtkRenderer* theRenderer){
767 SALOME_Actor::AddToRender(theRenderer);
769 theRenderer->AddActor(myNodeActor);
770 theRenderer->AddActor(myBaseActor);
772 theRenderer->AddActor(my3DActor);
773 theRenderer->AddActor(my2DActor);
775 theRenderer->AddActor(my1DActor);
776 theRenderer->AddActor(my1DExtActor);
778 theRenderer->AddActor(myHighlitableActor);
780 theRenderer->AddActor2D(myScalarBarActor);
782 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
783 myClsSelectVisiblePoints->SetRenderer(theRenderer);
785 theRenderer->AddActor2D(myPointLabels);
786 theRenderer->AddActor2D(myCellsLabels);
789 void SMESH_ActorDef::RemoveFromRender(vtkRenderer* theRenderer){
790 SALOME_Actor::RemoveFromRender(theRenderer);
792 theRenderer->RemoveActor(myNodeActor);
793 theRenderer->RemoveActor(myBaseActor);
795 theRenderer->RemoveActor(myHighlitableActor);
797 theRenderer->RemoveActor(my1DActor);
798 theRenderer->RemoveActor(my1DExtActor);
800 theRenderer->RemoveActor(my2DActor);
801 theRenderer->RemoveActor(my3DActor);
803 theRenderer->RemoveActor(myScalarBarActor);
804 theRenderer->RemoveActor(myPointLabels);
805 theRenderer->RemoveActor(myCellsLabels);
809 bool SMESH_ActorDef::Init(TVisualObjPtr theVisualObj,
810 const char* theEntry,
814 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry,"SMESH",theName);
818 myVisualObj = theVisualObj;
819 myVisualObj->Update(theIsClear);
821 myNodeActor->Init(myVisualObj,myImplicitBoolean);
822 myBaseActor->Init(myVisualObj,myImplicitBoolean);
824 myHighlitableActor->Init(myVisualObj,myImplicitBoolean);
826 my1DActor->Init(myVisualObj,myImplicitBoolean);
827 my1DExtActor->Init(myVisualObj,myImplicitBoolean);
829 my2DActor->Init(myVisualObj,myImplicitBoolean);
830 my3DActor->Init(myVisualObj,myImplicitBoolean);
832 my1DActor->GetMapper()->SetLookupTable(myLookupTable);
833 my1DExtActor->GetMapper()->SetLookupTable(myLookupTable);
835 my2DActor->GetMapper()->SetLookupTable(myLookupTable);
836 my3DActor->GetMapper()->SetLookupTable(myLookupTable);
838 float aFactor, aUnits;
839 my2DActor->GetPolygonOffsetParameters(aFactor,aUnits);
840 my2DActor->SetPolygonOffsetParameters(aFactor,aUnits*0.75);
842 //SetIsShrunkable(theGrid->GetNumberOfCells() > 10);
843 SetIsShrunkable(true);
845 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
849 QString aMode = mgr->stringValue( "DisplayMode", "SMESH" );
850 SetRepresentation(-1);
852 if(aMode.compare("Wireframe") == 0){
853 SetRepresentation(eEdge);
854 }else if(aMode.compare("Shading") == 0){
855 SetRepresentation(eSurface);
856 }else if(aMode.compare("Nodes") == 0){
857 SetRepresentation(ePoint);
860 aMode = mgr->stringValue( "Shrink", "SMESH" );
865 myTimeStamp->Modified();
871 float* SMESH_ActorDef::GetBounds(){
872 return myNodeActor->GetBounds();
876 vtkDataSet* SMESH_ActorDef::GetInput(){
877 return GetUnstructuredGrid();
881 void SMESH_ActorDef::SetTransform(VTKViewer_Transform* theTransform){
882 myNodeActor->SetTransform(theTransform);
883 myBaseActor->SetTransform(theTransform);
885 myHighlitableActor->SetTransform(theTransform);
887 my1DActor->SetTransform(theTransform);
888 my1DExtActor->SetTransform(theTransform);
890 my2DActor->SetTransform(theTransform);
891 my3DActor->SetTransform(theTransform);
897 void SMESH_ActorDef::SetMapper(vtkMapper* theMapper){
898 vtkLODActor::SetMapper(theMapper);
902 void SMESH_ActorDef::ShallowCopy(vtkProp *prop){
903 SALOME_Actor::ShallowCopy(prop);
907 vtkMapper* SMESH_ActorDef::GetMapper(){
908 return myPickableActor->GetMapper();
912 vtkUnstructuredGrid* SMESH_ActorDef::GetUnstructuredGrid(){
913 return myVisualObj->GetUnstructuredGrid();
917 bool SMESH_ActorDef::IsInfinitive(){
918 vtkDataSet *aDataSet = myPickableActor->GetUnstructuredGrid();
920 myIsInfinite = aDataSet->GetNumberOfCells() == 0 ||
921 aDataSet->GetNumberOfCells() == 1 &&
922 aDataSet->GetCell(0)->GetCellType() == VTK_VERTEX;
923 return SALOME_Actor::IsInfinitive();
927 void SMESH_ActorDef::SetIsShrunkable(bool theShrunkable){
928 myIsShrinkable = theShrunkable;
932 float SMESH_ActorDef::GetShrinkFactor(){
933 return myBaseActor->GetShrinkFactor();
936 void SMESH_ActorDef::SetShrinkFactor(float theValue){
937 myBaseActor->SetShrinkFactor(theValue);
939 my1DActor->SetShrinkFactor(theValue);
940 my1DExtActor->SetShrinkFactor(theValue);
942 my2DActor->SetShrinkFactor(theValue);
943 my3DActor->SetShrinkFactor(theValue);
948 void SMESH_ActorDef::SetShrink(){
949 if(!myIsShrinkable) return;
951 myBaseActor->SetShrink();
953 my1DActor->SetShrink();
954 my1DExtActor->SetShrink();
956 my2DActor->SetShrink();
957 my3DActor->SetShrink();
963 void SMESH_ActorDef::UnShrink(){
964 if(!myIsShrunk) return;
966 myBaseActor->UnShrink();
968 my1DActor->UnShrink();
969 my1DExtActor->UnShrink();
971 my2DActor->UnShrink();
972 my3DActor->UnShrink();
979 int SMESH_ActorDef::GetNodeObjId(int theVtkID){
980 return myPickableActor->GetNodeObjId(theVtkID);
983 float* SMESH_ActorDef::GetNodeCoord(int theObjID){
984 return myPickableActor->GetNodeCoord(theObjID);
988 int SMESH_ActorDef::GetElemObjId(int theVtkID){
989 return myPickableActor->GetElemObjId(theVtkID);
992 vtkCell* SMESH_ActorDef::GetElemCell(int theObjID){
993 return myPickableActor->GetElemCell(theObjID);
997 void SMESH_ActorDef::SetVisibility(int theMode){
998 SetVisibility(theMode,true);
1002 void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation){
1003 SALOME_Actor::SetVisibility(theMode);
1005 myNodeActor->VisibilityOff();
1006 myBaseActor->VisibilityOff();
1008 my1DActor->VisibilityOff();
1009 my1DExtActor->VisibilityOff();
1011 my2DActor->VisibilityOff();
1012 my3DActor->VisibilityOff();
1014 myScalarBarActor->VisibilityOff();
1015 myPointLabels->VisibilityOff();
1016 myCellsLabels->VisibilityOff();
1018 if(GetVisibility()){
1019 if(theIsUpdateRepersentation)
1020 SetRepresentation(GetRepresentation());
1022 if(myControlMode != eNone){
1023 switch(myControlMode){
1026 my1DExtActor->VisibilityOn();
1029 case eMultiConnection2D:
1030 my1DExtActor->VisibilityOn();
1032 if(myControlActor->GetUnstructuredGrid()->GetNumberOfCells())
1033 myScalarBarActor->VisibilityOn();
1037 if(myRepresentation != ePoint)
1038 myPickableActor->VisibilityOn();
1040 myNodeActor->VisibilityOn();
1043 if(myEntityMode & eEdges){
1044 my1DActor->VisibilityOn();
1047 if(myEntityMode & eFaces){
1048 my2DActor->VisibilityOn();
1051 if(myEntityMode & eVolumes){
1052 my3DActor->VisibilityOn();
1055 if(myIsPointsLabeled){
1056 myPointLabels->VisibilityOn();
1057 myNodeActor->VisibilityOn();
1060 if(myIsCellsLabeled)
1061 myCellsLabels->VisibilityOn();
1068 void SMESH_ActorDef::SetEntityMode(unsigned int theMode){
1069 myEntityState = eAllEntity;
1071 if(!myVisualObj->GetNbEntities(SMDSAbs_Edge)){
1072 myEntityState &= ~eEdges;
1076 if(!myVisualObj->GetNbEntities(SMDSAbs_Face)){
1077 myEntityState &= ~eFaces;
1081 if(!myVisualObj->GetNbEntities(SMDSAbs_Volume)){
1082 myEntityState &= ~eVolumes;
1083 theMode &= ~eVolumes;
1087 if(myVisualObj->GetNbEntities(SMDSAbs_Edge))
1090 if(myVisualObj->GetNbEntities(SMDSAbs_Face))
1093 if(myVisualObj->GetNbEntities(SMDSAbs_Volume))
1094 theMode |= eVolumes;
1097 myBaseActor->myGeomFilter->SetInside(myEntityMode != myEntityState);
1099 myEntityMode = theMode;
1100 VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
1101 aFilter = myBaseActor->GetExtractUnstructuredGrid();
1102 aFilter->ClearRegisteredCellsWithType();
1103 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
1105 if(myEntityMode & eEdges){
1106 if (MYDEBUG) MESSAGE("EDGES");
1107 aFilter->RegisterCellsWithType(VTK_LINE);
1110 if(myEntityMode & eFaces){
1111 if (MYDEBUG) MESSAGE("FACES");
1112 aFilter->RegisterCellsWithType(VTK_TRIANGLE);
1113 aFilter->RegisterCellsWithType(VTK_POLYGON);
1114 aFilter->RegisterCellsWithType(VTK_QUAD);
1117 if(myEntityMode & eVolumes){
1118 if (MYDEBUG) MESSAGE("VOLUMES");
1119 aFilter->RegisterCellsWithType(VTK_TETRA);
1120 aFilter->RegisterCellsWithType(VTK_VOXEL);
1121 aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1122 aFilter->RegisterCellsWithType(VTK_WEDGE);
1123 aFilter->RegisterCellsWithType(VTK_PYRAMID);
1124 aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1127 if (MYDEBUG) MESSAGE(aFilter->GetOutput()->GetNumberOfCells());
1128 SetVisibility(GetVisibility(),false);
1131 void SMESH_ActorDef::SetRepresentation(int theMode){
1132 int aNbEdges = myVisualObj->GetNbEntities(SMDSAbs_Edge);
1133 int aNbFaces = myVisualObj->GetNbEntities(SMDSAbs_Face);
1134 int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume);
1136 myRepresentation = eSurface;
1137 if(!aNbFaces && !aNbVolumes && aNbEdges){
1138 myRepresentation = eEdge;
1139 }else if(!aNbFaces && !aNbVolumes && !aNbEdges){
1140 myRepresentation = ePoint;
1145 if(!aNbFaces && !aNbVolumes && !aNbEdges) return;
1148 if(!aNbFaces && !aNbVolumes) return;
1151 myRepresentation = theMode;
1154 if(!GetUnstructuredGrid()->GetNumberOfCells())
1155 myRepresentation = ePoint;
1158 if(myRepresentation == ePoint){
1166 myPickableActor = myBaseActor;
1167 myNodeActor->SetVisibility(false);
1168 vtkProperty *aProp = NULL, *aBackProp = NULL;
1169 SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1);
1170 switch(myRepresentation){
1172 myPickableActor = myNodeActor;
1173 myNodeActor->SetVisibility(true);
1175 aProp = aBackProp = myNodeProp;
1176 aReperesent = SMESH_DeviceActor::ePoint;
1179 aProp = aBackProp = myEdgeProp;
1180 aReperesent = SMESH_DeviceActor::eInsideframe;
1183 aProp = mySurfaceProp;
1184 aBackProp = myBackSurfaceProp;
1185 aReperesent = SMESH_DeviceActor::eSurface;
1189 my2DActor->SetProperty(aProp);
1190 my2DActor->SetBackfaceProperty(aBackProp);
1191 my2DActor->SetRepresentation(aReperesent);
1193 my3DActor->SetProperty(aProp);
1194 my3DActor->SetBackfaceProperty(aBackProp);
1195 my3DActor->SetRepresentation(aReperesent);
1197 my1DExtActor->SetVisibility(false);
1199 switch(myControlMode){
1201 case eMultiConnection:
1202 aProp = aBackProp = my1DProp;
1203 if(myRepresentation != ePoint)
1204 aReperesent = SMESH_DeviceActor::eInsideframe;
1208 my1DActor->SetProperty(aProp);
1209 my1DActor->SetBackfaceProperty(aBackProp);
1210 my1DActor->SetRepresentation(aReperesent);
1212 my1DExtActor->SetRepresentation(aReperesent);
1214 if(myIsPointsVisible)
1215 myPickableActor = myNodeActor;
1216 if(GetPointRepresentation())
1217 myNodeActor->SetVisibility(true);
1219 SetMapper(myPickableActor->GetMapper());
1221 SetVisibility(GetVisibility(),false);
1227 void SMESH_ActorDef::SetPointRepresentation(bool theIsPointsVisible){
1228 myIsPointsVisible = theIsPointsVisible;
1229 SetRepresentation(GetRepresentation());
1232 bool SMESH_ActorDef::GetPointRepresentation(){
1233 return myIsPointsVisible || myIsPointsLabeled;
1237 void SMESH_ActorDef::UpdateHighlight(){
1238 myHighlitableActor->SetVisibility(false);
1239 myHighlitableActor->SetHighlited(false);
1241 if(myIsHighlighted){
1242 myHighlitableActor->SetProperty(myHighlightProp);
1243 }else if(myIsPreselected){
1244 myHighlitableActor->SetProperty(myPreselectProp);
1247 bool anIsVisible = GetVisibility();
1249 if(myIsHighlighted || myIsPreselected){
1250 if(GetUnstructuredGrid()->GetNumberOfCells()){
1251 myHighlitableActor->SetHighlited(anIsVisible);
1252 myHighlitableActor->SetVisibility(anIsVisible);
1253 myHighlitableActor->GetExtractUnstructuredGrid()->
1254 SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::eCells);
1255 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
1256 }else if(myRepresentation == ePoint || GetPointRepresentation()){
1257 myHighlitableActor->SetHighlited(anIsVisible);
1258 myHighlitableActor->SetVisibility(anIsVisible);
1259 myHighlitableActor->GetExtractUnstructuredGrid()->
1260 SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
1261 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::ePoint);
1267 void SMESH_ActorDef::highlight(bool theHighlight){
1268 myIsHighlighted = theHighlight;
1273 void SMESH_ActorDef::SetPreSelected(bool thePreselect){
1274 myIsPreselected = thePreselect;
1280 int SMESH_ActorDef::RenderOpaqueGeometry(vtkViewport *vp)
1282 if (myPickableActor->GetIsOpaque())
1284 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1292 int SMESH_ActorDef::RenderTranslucentGeometry(vtkViewport *vp)
1294 if (!myPickableActor->GetIsOpaque())
1296 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1304 void SMESH_ActorDef::Render(vtkRenderer *ren){
1305 unsigned long aTime = myTimeStamp->GetMTime();
1306 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1307 unsigned long aClippingTime = myImplicitBoolean->GetMTime();
1308 if(anObjTime > aTime || aClippingTime > aTime)
1313 void SMESH_ActorDef::Update(){
1314 if(MYDEBUG) MESSAGE("SMESH_ActorDef::Update");
1316 if(GetControlMode() != eNone) {
1317 unsigned long aTime = myTimeStamp->GetMTime();
1318 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1319 if (anObjTime > aTime)
1320 SetControlMode(GetControlMode(),false);
1322 if(myIsPointsLabeled){
1323 SetPointsLabeled(myIsPointsLabeled);
1325 if(myIsCellsLabeled){
1326 SetCellsLabeled(myIsCellsLabeled);
1328 SetEntityMode(GetEntityMode());
1329 SetVisibility(GetVisibility());
1331 myTimeStamp->Modified();
1336 void SMESH_ActorDef::ReleaseGraphicsResources(vtkWindow *renWin){
1337 SALOME_Actor::ReleaseGraphicsResources(renWin);
1339 myPickableActor->ReleaseGraphicsResources(renWin);
1343 static void GetColor(vtkProperty *theProperty, float& r,float& g,float& b){
1344 float* aColor = theProperty->GetColor();
1351 void SMESH_ActorDef::SetOpacity(float theValue){
1352 mySurfaceProp->SetOpacity(theValue);
1353 myBackSurfaceProp->SetOpacity(theValue);
1354 myEdgeProp->SetOpacity(theValue);
1355 myNodeProp->SetOpacity(theValue);
1357 my1DProp->SetOpacity(theValue);
1361 float SMESH_ActorDef::GetOpacity(){
1362 return mySurfaceProp->GetOpacity();
1366 void SMESH_ActorDef::SetSufaceColor(float r,float g,float b){
1367 mySurfaceProp->SetColor(r,g,b);
1371 void SMESH_ActorDef::GetSufaceColor(float& r,float& g,float& b){
1372 ::GetColor(mySurfaceProp,r,g,b);
1375 void SMESH_ActorDef::SetBackSufaceColor(float r,float g,float b){
1376 myBackSurfaceProp->SetColor(r,g,b);
1380 void SMESH_ActorDef::GetBackSufaceColor(float& r,float& g,float& b){
1381 ::GetColor(myBackSurfaceProp,r,g,b);
1384 void SMESH_ActorDef::SetEdgeColor(float r,float g,float b){
1385 myEdgeProp->SetColor(r,g,b);
1386 my1DProp->SetColor(r,g,b);
1387 my1DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1391 void SMESH_ActorDef::GetEdgeColor(float& r,float& g,float& b){
1392 ::GetColor(myEdgeProp,r,g,b);
1395 void SMESH_ActorDef::SetNodeColor(float r,float g,float b){
1396 myNodeProp->SetColor(r,g,b);
1400 void SMESH_ActorDef::GetNodeColor(float& r,float& g,float& b){
1401 ::GetColor(myNodeProp,r,g,b);
1404 void SMESH_ActorDef::SetHighlightColor(float r,float g,float b){
1405 myHighlightProp->SetColor(r,g,b);
1409 void SMESH_ActorDef::GetHighlightColor(float& r,float& g,float& b){
1410 ::GetColor(myHighlightProp,r,g,b);
1413 void SMESH_ActorDef::SetPreHighlightColor(float r,float g,float b){
1414 myPreselectProp->SetColor(r,g,b);
1418 void SMESH_ActorDef::GetPreHighlightColor(float& r,float& g,float& b){
1419 ::GetColor(myPreselectProp,r,g,b);
1423 float SMESH_ActorDef::GetLineWidth(){
1424 return myEdgeProp->GetLineWidth();
1428 void SMESH_ActorDef::SetLineWidth(float theVal){
1429 myEdgeProp->SetLineWidth(theVal);
1431 my1DProp->SetLineWidth(theVal + aLineWidthInc);
1432 my1DExtProp->SetLineWidth(theVal + aLineWidthInc);
1438 void SMESH_ActorDef::SetNodeSize(float theVal){
1439 myNodeProp->SetPointSize(theVal);
1440 myHighlightProp->SetPointSize(theVal);
1441 myPreselectProp->SetPointSize(theVal);
1443 my1DProp->SetPointSize(theVal + aPointSizeInc);
1444 my1DExtProp->SetPointSize(theVal + aPointSizeInc);
1449 float SMESH_ActorDef::GetNodeSize(){
1450 return myNodeProp->GetPointSize();
1453 int SMESH_ActorDef::GetObjDimension( const int theObjId )
1455 return myVisualObj->GetElemDimension( theObjId );
1460 IsImplicitFunctionUsed() const
1462 return myBaseActor->IsImplicitFunctionUsed();
1467 SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
1469 myNodeActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1470 myBaseActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1472 myHighlitableActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1474 my1DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1475 my1DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1477 my2DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1478 my3DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1483 AddClippingPlane(vtkPlane* thePlane)
1486 myImplicitBoolean->GetFunction()->AddItem(thePlane);
1487 myCippingPlaneCont.push_back(thePlane);
1488 if(!IsImplicitFunctionUsed())
1489 SetImplicitFunctionUsed(true);
1491 return myCippingPlaneCont.size();
1496 RemoveAllClippingPlanes()
1498 myImplicitBoolean->GetFunction()->RemoveAllItems();
1499 myImplicitBoolean->GetFunction()->Modified(); // VTK bug
1500 myCippingPlaneCont.clear();
1501 SetImplicitFunctionUsed(false);
1506 GetNumberOfClippingPlanes()
1508 return myCippingPlaneCont.size();
1513 GetClippingPlane(vtkIdType theID)
1515 if(theID >= myCippingPlaneCont.size())
1517 return myCippingPlaneCont[theID].Get();
1521 static void ComputeBoundsParam(vtkDataSet* theDataSet,
1522 float theDirection[3], float theMinPnt[3],
1523 float& theMaxBoundPrj, float& theMinBoundPrj)
1526 theDataSet->GetBounds(aBounds);
1528 //Enlarge bounds in order to avoid conflicts of precision
1529 for(int i = 0; i < 6; i += 2){
1530 static double EPS = 1.0E-3;
1531 float aDelta = (aBounds[i+1] - aBounds[i])*EPS;
1532 aBounds[i] -= aDelta;
1533 aBounds[i+1] += aDelta;
1536 float aBoundPoints[8][3] = { {aBounds[0],aBounds[2],aBounds[4]},
1537 {aBounds[1],aBounds[2],aBounds[4]},
1538 {aBounds[0],aBounds[3],aBounds[4]},
1539 {aBounds[1],aBounds[3],aBounds[4]},
1540 {aBounds[0],aBounds[2],aBounds[5]},
1541 {aBounds[1],aBounds[2],aBounds[5]},
1542 {aBounds[0],aBounds[3],aBounds[5]},
1543 {aBounds[1],aBounds[3],aBounds[5]}};
1545 int aMaxId = 0, aMinId = aMaxId;
1546 theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
1547 theMinBoundPrj = theMaxBoundPrj;
1548 for(int i = 1; i < 8; i++){
1549 float aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
1550 if(theMaxBoundPrj < aTmp){
1551 theMaxBoundPrj = aTmp;
1554 if(theMinBoundPrj > aTmp){
1555 theMinBoundPrj = aTmp;
1559 float *aMinPnt = aBoundPoints[aMaxId];
1560 theMinPnt[0] = aMinPnt[0];
1561 theMinPnt[1] = aMinPnt[1];
1562 theMinPnt[2] = aMinPnt[2];
1566 static void DistanceToPosition(vtkDataSet* theDataSet,
1567 float theDirection[3], float theDist, float thePos[3])
1569 float aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1570 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1571 float aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
1572 thePos[0] = aMinPnt[0]-theDirection[0]*aLength;
1573 thePos[1] = aMinPnt[1]-theDirection[1]*aLength;
1574 thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
1578 static void PositionToDistance(vtkDataSet* theDataSet,
1579 float theDirection[3], float thePos[3], float& theDist)
1581 float aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1582 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1583 float aPrj = vtkMath::Dot(theDirection,thePos);
1584 theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
1588 void SMESH_ActorDef::SetPlaneParam(float theDir[3], float theDist, vtkPlane* thePlane)
1590 thePlane->SetNormal(theDir);
1592 ::DistanceToPosition(GetUnstructuredGrid(),theDir,theDist,anOrigin);
1593 thePlane->SetOrigin(anOrigin);
1597 void SMESH_ActorDef::GetPlaneParam(float theDir[3], float& theDist, vtkPlane* thePlane)
1599 thePlane->GetNormal(theDir);
1602 thePlane->GetOrigin(anOrigin);
1603 ::PositionToDistance(GetUnstructuredGrid(),theDir,anOrigin,theDist);