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_Actor.h"
31 #include "SMESH_ActorUtils.h"
32 #include "SMESH_DeviceActor.h"
33 #include "SALOME_ExtractUnstructuredGrid.h"
35 #include "QAD_Config.h"
36 #include "utilities.h"
37 #include <qstringlist.h>
39 #include <vtkTimeStamp.h>
40 #include <vtkObjectFactory.h>
41 #include <vtkShrinkPolyData.h>
42 #include <vtkMergeFilter.h>
44 #include <vtkMatrix4x4.h>
45 #include <vtkUnstructuredGrid.h>
46 #include <vtkPointData.h>
47 #include <vtkCellData.h>
49 #include <vtkMapper.h>
50 #include <vtkRenderer.h>
53 #include <vtkIdList.h>
54 #include <vtkIntArray.h>
56 #include <vtkActor2D.h>
57 #include <vtkProperty2D.h>
58 #include <vtkPolyData.h>
59 #include <vtkMaskPoints.h>
60 #include <vtkCellCenters.h>
61 #include <vtkTextProperty.h>
62 #include <vtkLabeledDataMapper.h>
63 #include <vtkSelectVisiblePoints.h>
65 #include <vtkScalarBarActor.h>
66 #include <vtkLookupTable.h>
70 #include <vtkImplicitBoolean.h>
73 static int MYDEBUG = 0;
74 static int MYDEBUGWITHFILES = 0;
76 static int MYDEBUG = 0;
77 static int MYDEBUGWITHFILES = 0;
80 static int aLineWidthInc = 2;
81 static int aPointSizeInc = 2;
84 SMESH_Actor* SMESH_Actor::New(){
85 return new SMESH_Actor();
89 SMESH_Actor* SMESH_Actor::New(TVisualObjPtr theVisualObj,
94 SMESH_Actor* anActor = SMESH_Actor::New();
95 if(!anActor->Init(theVisualObj,theEntry,theName,theIsClear)){
103 SMESH_Actor::SMESH_Actor(){
104 if(MYDEBUG) MESSAGE("SMESH_Actor");
106 myTimeStamp = vtkTimeStamp::New();
108 myIsPointsVisible = false;
110 myIsShrinkable = false;
113 myControlsPrecision = (long)SMESH::GetFloat( "SMESH:ControlsPrecision", -1 );
115 float aPointSize = SMESH::GetFloat("SMESH:SettingsNodesSize",3);
116 float aLineWidth = SMESH::GetFloat("SMESH:SettingsWidth",1);
118 vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
119 SALOME_ExtractUnstructuredGrid* aFilter = NULL;
121 //Definition 2D and 3D divices of the actor
122 //-----------------------------------------
123 float anRGB[3] = {1,1,1};
124 mySurfaceProp = vtkProperty::New();
125 anRGB[0] = SMESH::GetFloat("SMESH:SettingsFillColorRed", 0)/255.;
126 anRGB[1] = SMESH::GetFloat("SMESH:SettingsFillColorGreen", 170)/255.;
127 anRGB[2] = SMESH::GetFloat("SMESH:SettingsFillColorBlue", 255)/255.;
128 mySurfaceProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
130 myBackSurfaceProp = vtkProperty::New();
131 anRGB[0] = SMESH::GetFloat("SMESH:SettingsBackFaceColorRed", 0)/255.;
132 anRGB[1] = SMESH::GetFloat("SMESH:SettingsBackFaceColorGreen", 0)/255.;
133 anRGB[2] = SMESH::GetFloat("SMESH:SettingsBackFaceColorBlue", 255)/255.;
134 myBackSurfaceProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
136 my2DActor = SMESH_DeviceActor::New();
137 my2DActor->SetUserMatrix(aMatrix);
138 my2DActor->SetStoreMapping(true);
139 my2DActor->PickableOff();
140 my2DActor->SetProperty(mySurfaceProp);
141 my2DActor->SetBackfaceProperty(myBackSurfaceProp);
142 my2DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
143 aFilter = my2DActor->GetExtractUnstructuredGrid();
144 aFilter->SetModeOfChanging(SALOME_ExtractUnstructuredGrid::eAdding);
145 aFilter->RegisterCellsWithType(VTK_TRIANGLE);
146 aFilter->RegisterCellsWithType(VTK_POLYGON);
147 aFilter->RegisterCellsWithType(VTK_QUAD);
149 my3DActor = SMESH_DeviceActor::New();
150 my3DActor->SetUserMatrix(aMatrix);
151 my3DActor->SetStoreMapping(true);
152 my3DActor->PickableOff();
153 my3DActor->SetProperty(mySurfaceProp);
154 my3DActor->SetBackfaceProperty(myBackSurfaceProp);
155 my3DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
156 aFilter = my3DActor->GetExtractUnstructuredGrid();
157 aFilter->SetModeOfChanging(SALOME_ExtractUnstructuredGrid::eAdding);
158 aFilter->RegisterCellsWithType(VTK_TETRA);
159 aFilter->RegisterCellsWithType(VTK_VOXEL);
160 aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
161 aFilter->RegisterCellsWithType(VTK_WEDGE);
162 aFilter->RegisterCellsWithType(VTK_PYRAMID);
165 //Definition 1D divice of the actor
166 //---------------------------------
167 myEdgeProp = vtkProperty::New();
168 myEdgeProp->SetAmbient(1.0);
169 myEdgeProp->SetDiffuse(0.0);
170 myEdgeProp->SetSpecular(0.0);
171 anRGB[0] = SMESH::GetFloat("SMESH:SettingsOutlineColorRed", 0)/255.;
172 anRGB[1] = SMESH::GetFloat("SMESH:SettingsOutlineColorGreen", 170)/255.;
173 anRGB[2] = SMESH::GetFloat("SMESH:SettingsOutlineColorBlue", 255)/255.;
174 myEdgeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
175 myEdgeProp->SetLineWidth(aLineWidth);
177 my1DActor = SMESH_DeviceActor::New();
178 my1DActor->SetUserMatrix(aMatrix);
179 my1DActor->SetStoreMapping(true);
180 my1DActor->PickableOff();
181 my1DActor->SetHighlited(true);
182 my1DActor->SetProperty(myEdgeProp);
183 my1DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
184 aFilter = my1DActor->GetExtractUnstructuredGrid();
185 aFilter->SetModeOfChanging(SALOME_ExtractUnstructuredGrid::eAdding);
186 aFilter->RegisterCellsWithType(VTK_LINE);
188 my1DProp = vtkProperty::New();
189 my1DProp->DeepCopy(myEdgeProp);
190 my1DProp->SetLineWidth(aLineWidth + aLineWidthInc);
191 my1DProp->SetPointSize(aPointSize);
193 my1DExtProp = vtkProperty::New();
194 my1DExtProp->DeepCopy(myEdgeProp);
195 anRGB[0] = 1 - anRGB[0];
196 anRGB[1] = 1 - anRGB[1];
197 anRGB[2] = 1 - anRGB[2];
198 my1DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
199 my1DExtProp->SetLineWidth(aLineWidth + aLineWidthInc);
200 my1DExtProp->SetPointSize(aPointSize + aPointSizeInc);
202 my1DExtActor = SMESH_DeviceActor::New();
203 my1DExtActor->SetUserMatrix(aMatrix);
204 my1DExtActor->SetStoreMapping(true);
205 my1DExtActor->PickableOff();
206 my1DExtActor->SetHighlited(true);
207 my1DExtActor->SetVisibility(false);
208 my1DExtActor->SetProperty(my1DExtProp);
209 my1DExtActor->SetRepresentation(SMESH_DeviceActor::eInsideframe);
210 aFilter = my1DExtActor->GetExtractUnstructuredGrid();
211 aFilter->SetModeOfChanging(SALOME_ExtractUnstructuredGrid::eAdding);
212 aFilter->RegisterCellsWithType(VTK_LINE);
215 //Definition 0D divice of the actor
216 //---------------------------------
217 myNodeProp = vtkProperty::New();
218 anRGB[0] = SMESH::GetFloat("SMESH:SettingsNodeColorRed",255)/255.;
219 anRGB[1] = SMESH::GetFloat("SMESH:SettingsNodeColorGreen",0)/255.;
220 anRGB[2] = SMESH::GetFloat("SMESH:SettingsNodeColorBlue",0)/255.;
221 myNodeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
222 myNodeProp->SetPointSize(aPointSize);
224 myNodeActor = SMESH_DeviceActor::New();
225 myNodeActor->SetUserMatrix(aMatrix);
226 myNodeActor->SetStoreMapping(true);
227 myNodeActor->PickableOff();
228 myNodeActor->SetVisibility(false);
229 myNodeActor->SetProperty(myNodeProp);
230 myNodeActor->SetRepresentation(SMESH_DeviceActor::ePoint);
231 aFilter = myNodeActor->GetExtractUnstructuredGrid();
232 aFilter->SetModeOfExtraction(SALOME_ExtractUnstructuredGrid::ePoints);
235 //Definition of Pickable and Highlitable engines
236 //----------------------------------------------
238 myBaseActor = SMESH_DeviceActor::New();
239 myBaseActor->SetUserMatrix(aMatrix);
240 myBaseActor->SetStoreMapping(true);
241 myBaseActor->GetProperty()->SetOpacity(0.0);
243 myPickableActor = myBaseActor;
245 myHighlightProp = vtkProperty::New();
246 myHighlightProp->SetAmbient(1.0);
247 myHighlightProp->SetDiffuse(0.0);
248 myHighlightProp->SetSpecular(0.0);
249 anRGB[0] = SMESH::GetFloat("SMESH:SettingsSelectColorRed", 255)/255.; // 1;
250 anRGB[1] = SMESH::GetFloat("SMESH:SettingsSelectColorGreen", 255)/255.; // 1;
251 anRGB[2] = SMESH::GetFloat("SMESH:SettingsSelectColorBlue", 255)/255.; // 1;
252 myHighlightProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
253 myHighlightProp->SetPointSize(aPointSize);
254 myHighlightProp->SetRepresentation(1);
256 myPreselectProp = vtkProperty::New();
257 myPreselectProp->SetAmbient(1.0);
258 myPreselectProp->SetDiffuse(0.0);
259 myPreselectProp->SetSpecular(0.0);
260 anRGB[0] = SMESH::GetFloat("SMESH:SettingsPreSelectColorRed", 0)/255.; // 0;
261 anRGB[1] = SMESH::GetFloat("SMESH:SettingsPreSelectColorGreen", 255)/255.; // 1;
262 anRGB[2] = SMESH::GetFloat("SMESH:SettingsPreSelectColorBlue", 255)/255.; // 1;
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->SetStoreMapping(false);
270 myHighlitableActor->PickableOff();
271 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
273 myNodeHighlitableActor = SMESH_DeviceActor::New();
274 myNodeHighlitableActor->SetUserMatrix(aMatrix);
275 myNodeHighlitableActor->SetStoreMapping(false);
276 myNodeHighlitableActor->PickableOff();
277 myNodeHighlitableActor->SetRepresentation(SMESH_DeviceActor::ePoint);
278 aFilter = myNodeHighlitableActor->GetExtractUnstructuredGrid();
279 aFilter->SetModeOfExtraction(SALOME_ExtractUnstructuredGrid::ePoints);
282 SetShrinkFactor(SMESH::GetFloat("SMESH:SettingsShrinkCoeff", 75)/100.);
288 my1DColorMode = e1DNone;
289 myControlActor = my2DActor;
291 //Definition of myScalarBarActor
292 //------------------------------
293 myLookupTable = vtkLookupTable::New();
294 //Fix for Bug PAL5195 - SMESH764:
295 //Controls - Aspect Ratio: incorrect colors of the best and worst values
296 myLookupTable->SetHueRange(0.667,0.0);
298 myScalarBarActor = vtkScalarBarActor::New();
299 myScalarBarActor->SetVisibility(false);
300 myScalarBarActor->SetLookupTable(myLookupTable);
302 vtkTextProperty* aScalarBarTitleProp = vtkTextProperty::New();
304 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarTitleColor" ) ) {
305 QStringList aTColor = QStringList::split( ":", QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleColor" ), false );
306 aScalarBarTitleProp->SetColor( ( aTColor.count() > 0 ? aTColor[0].toInt()/255. : 1.0 ),
307 ( aTColor.count() > 1 ? aTColor[1].toInt()/255. : 1.0 ),
308 ( aTColor.count() > 2 ? aTColor[2].toInt()/255. : 1.0 ) );
311 aScalarBarTitleProp->SetColor( 1.0, 1.0, 1.0 );
313 aScalarBarTitleProp->SetFontFamilyToArial();
314 if( QAD_CONFIG->hasSetting( "SMESH:ScalarBarTitleFont" ) ){
315 if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleFont" ) == "Arial" )
316 aScalarBarTitleProp->SetFontFamilyToArial();
317 else if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleFont" ) == "Courier" )
318 aScalarBarTitleProp->SetFontFamilyToCourier();
319 else if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleFont" ) == "Times" )
320 aScalarBarTitleProp->SetFontFamilyToTimes();
323 if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleBold" ) == "true" )
324 aScalarBarTitleProp->BoldOn();
326 aScalarBarTitleProp->BoldOff();
328 if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleItalic" ) == "true" )
329 aScalarBarTitleProp->ItalicOn();
331 aScalarBarTitleProp->ItalicOff();
333 if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleShadow" ) == "true" )
334 aScalarBarTitleProp->ShadowOn();
336 aScalarBarTitleProp->ShadowOff();
338 myScalarBarActor->SetTitleTextProperty( aScalarBarTitleProp );
339 aScalarBarTitleProp->Delete();
341 vtkTextProperty* aScalarBarLabelProp = vtkTextProperty::New();
343 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarLabelColor" ) ) {
344 QStringList aTColor = QStringList::split( ":", QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelColor" ), false );
345 aScalarBarLabelProp->SetColor( ( aTColor.count() > 0 ? aTColor[0].toInt()/255. : 1.0 ),
346 ( aTColor.count() > 1 ? aTColor[1].toInt()/255. : 1.0 ),
347 ( aTColor.count() > 2 ? aTColor[2].toInt()/255. : 1.0 ) );
350 aScalarBarLabelProp->SetColor( 1.0, 1.0, 1.0 );
352 aScalarBarLabelProp->SetFontFamilyToArial();
353 if( QAD_CONFIG->hasSetting( "SMESH:ScalarBarLabelFont" ) ){
354 if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelFont" ) == "Arial" )
355 aScalarBarLabelProp->SetFontFamilyToArial();
356 else if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelFont" ) == "Courier" )
357 aScalarBarLabelProp->SetFontFamilyToCourier();
358 else if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelFont" ) == "Times" )
359 aScalarBarLabelProp->SetFontFamilyToTimes();
362 if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelBold" ) == "true" )
363 aScalarBarLabelProp->BoldOn();
365 aScalarBarLabelProp->BoldOff();
367 if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelItalic" ) == "true" )
368 aScalarBarLabelProp->ItalicOn();
370 aScalarBarLabelProp->ItalicOff();
372 if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelShadow" ) == "true" )
373 aScalarBarLabelProp->ShadowOn();
375 aScalarBarLabelProp->ShadowOff();
377 myScalarBarActor->SetLabelTextProperty( aScalarBarLabelProp );
378 aScalarBarLabelProp->Delete();
380 if ( QAD_CONFIG->getSetting("SMESH:ScalarBarOrientation") == "Horizontal" )
381 myScalarBarActor->SetOrientationToHorizontal();
383 myScalarBarActor->SetOrientationToVertical();
385 float aXVal = QAD_CONFIG->getSetting("SMESH:ScalarBarOrientation") == "Horizontal" ? 0.20 : 0.01;
386 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarXPosition" ) )
387 aXVal = QAD_CONFIG->getSetting( "SMESH:ScalarBarXPosition" ).toFloat();
388 float aYVal = QAD_CONFIG->getSetting("SMESH:ScalarBarOrientation") == "Horizontal" ? 0.01 : 0.1;
389 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarYPosition" ) )
390 aYVal = QAD_CONFIG->getSetting( "SMESH:ScalarBarYPosition" ).toFloat();
391 myScalarBarActor->SetPosition( aXVal, aYVal );
393 float aWVal = QAD_CONFIG->getSetting("SMESH:ScalarBarOrientation") == "Horizontal" ? 0.60 : 0.10;
394 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarWidth" ) )
395 aWVal = QAD_CONFIG->getSetting( "SMESH:ScalarBarWidth" ).toFloat();
396 myScalarBarActor->SetWidth( aWVal );
398 float aHVal = QAD_CONFIG->getSetting("SMESH:ScalarBarOrientation") == "Horizontal" ? 0.12 : 0.80;
399 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarHeight" ) )
400 aHVal = QAD_CONFIG->getSetting( "SMESH:ScalarBarHeight" ).toFloat();
401 myScalarBarActor->SetHeight( aHVal );
404 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarNbOfLabels" ) )
405 anIntVal = QAD_CONFIG->getSetting("SMESH:ScalarBarNbOfLabels").toInt();
406 myScalarBarActor->SetNumberOfLabels(anIntVal == 0? 5: anIntVal);
409 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarNbOfColors" ) )
410 anIntVal = QAD_CONFIG->getSetting("SMESH:ScalarBarNbOfColors").toInt();
411 myScalarBarActor->SetMaximumNumberOfColors(anIntVal == 0? 64: anIntVal);
414 //Definition of points numbering pipeline
415 //---------------------------------------
416 myPointsNumDataSet = vtkUnstructuredGrid::New();
418 myPtsMaskPoints = vtkMaskPoints::New();
419 myPtsMaskPoints->SetInput(myPointsNumDataSet);
420 myPtsMaskPoints->SetOnRatio(1);
422 myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
423 myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
424 myPtsSelectVisiblePoints->SelectInvisibleOff();
425 myPtsSelectVisiblePoints->SetTolerance(0.1);
427 myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
428 myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
429 myPtsLabeledDataMapper->SetLabelFormat("%g");
430 myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
432 vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
433 aPtsTextProp->SetFontFamilyToTimes();
434 static int aPointsFontSize = 10;
435 aPtsTextProp->SetFontSize(aPointsFontSize);
436 aPtsTextProp->SetBold(1);
437 aPtsTextProp->SetItalic(0);
438 aPtsTextProp->SetShadow(0);
439 myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
440 aPtsTextProp->Delete();
442 myIsPointsLabeled = false;
444 myPointLabels = vtkActor2D::New();
445 myPointLabels->SetMapper(myPtsLabeledDataMapper);
446 myPointLabels->GetProperty()->SetColor(1,1,1);
447 myPointLabels->SetVisibility(myIsPointsLabeled);
450 //Definition of cells numbering pipeline
451 //---------------------------------------
452 myCellsNumDataSet = vtkUnstructuredGrid::New();
454 myCellCenters = vtkCellCenters::New();
455 myCellCenters->SetInput(myCellsNumDataSet);
457 myClsMaskPoints = vtkMaskPoints::New();
458 myClsMaskPoints->SetInput(myCellCenters->GetOutput());
459 myClsMaskPoints->SetOnRatio(1);
461 myClsSelectVisiblePoints = vtkSelectVisiblePoints::New();
462 myClsSelectVisiblePoints->SetInput(myClsMaskPoints->GetOutput());
463 myClsSelectVisiblePoints->SelectInvisibleOff();
464 myClsSelectVisiblePoints->SetTolerance(0.1);
466 myClsLabeledDataMapper = vtkLabeledDataMapper::New();
467 myClsLabeledDataMapper->SetInput(myClsSelectVisiblePoints->GetOutput());
468 myClsLabeledDataMapper->SetLabelFormat("%g");
469 myClsLabeledDataMapper->SetLabelModeToLabelScalars();
471 vtkTextProperty* aClsTextProp = vtkTextProperty::New();
472 aClsTextProp->SetFontFamilyToTimes();
473 static int aCellsFontSize = 12;
474 aClsTextProp->SetFontSize(aCellsFontSize);
475 aClsTextProp->SetBold(1);
476 aClsTextProp->SetItalic(0);
477 aClsTextProp->SetShadow(0);
478 myClsLabeledDataMapper->SetLabelTextProperty(aClsTextProp);
479 aClsTextProp->Delete();
481 myIsCellsLabeled = false;
483 myCellsLabels = vtkActor2D::New();
484 myCellsLabels->SetMapper(myClsLabeledDataMapper);
485 myCellsLabels->GetProperty()->SetColor(0,1,0);
486 myCellsLabels->SetVisibility(myIsCellsLabeled);
489 myImplicitBoolean = vtkImplicitBoolean::New();
490 myImplicitBoolean->SetOperationTypeToIntersection();
494 SMESH_Actor::~SMESH_Actor(){
495 if(MYDEBUG) MESSAGE("~SMESH_Actor");
497 myScalarBarActor->Delete();
498 myLookupTable->Delete();
500 mySurfaceProp->Delete();
501 myBackSurfaceProp->Delete();
503 myEdgeProp->Delete();
504 myHighlightProp->Delete();
505 myPreselectProp->Delete();
507 myNodeProp->Delete();
512 my1DExtProp->Delete();
513 my1DExtActor->Delete();
518 myNodeActor->Delete();
519 myBaseActor->Delete();
521 myHighlitableActor->Delete();
522 myNodeHighlitableActor->Delete();
525 //Deleting of pints numbering pipeline
526 //---------------------------------------
527 myPointsNumDataSet->Delete();
529 myPtsLabeledDataMapper->RemoveAllInputs();
530 myPtsLabeledDataMapper->Delete();
532 myPtsSelectVisiblePoints->UnRegisterAllOutputs();
533 myPtsSelectVisiblePoints->Delete();
535 myPtsMaskPoints->UnRegisterAllOutputs();
536 myPtsMaskPoints->Delete();
538 myPointLabels->Delete();
541 //Deleting of cells numbering pipeline
542 //---------------------------------------
543 myCellsNumDataSet->Delete();
545 myClsLabeledDataMapper->RemoveAllInputs();
546 myClsLabeledDataMapper->Delete();
548 myClsSelectVisiblePoints->UnRegisterAllOutputs();
549 myClsSelectVisiblePoints->Delete();
551 myClsMaskPoints->UnRegisterAllOutputs();
552 myClsMaskPoints->Delete();
554 myCellCenters->UnRegisterAllOutputs();
555 myCellCenters->Delete();
557 myCellsLabels->Delete();
559 myImplicitBoolean->Delete();
561 myTimeStamp->Delete();
565 void SMESH_Actor::SetPointsLabeled( bool theIsPointsLabeled )
567 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
568 myIsPointsLabeled = theIsPointsLabeled && aGrid->GetNumberOfPoints();
570 if ( myIsPointsLabeled )
572 myPointsNumDataSet->ShallowCopy(aGrid);
573 vtkDataSet *aDataSet = myPointsNumDataSet;
575 int aNbElem = aDataSet->GetNumberOfPoints();
577 vtkIntArray *anArray = vtkIntArray::New();
578 anArray->SetNumberOfValues( aNbElem );
580 for ( int anId = 0; anId < aNbElem; anId++ )
582 int aSMDSId = myVisualObj->GetNodeObjId( anId );
583 anArray->SetValue( anId, aSMDSId );
586 aDataSet->GetPointData()->SetScalars( anArray );
588 myPtsMaskPoints->SetInput( aDataSet );
589 myPointLabels->SetVisibility( GetVisibility() );
593 myPointLabels->SetVisibility( false );
595 SetRepresentation(GetRepresentation());
596 myTimeStamp->Modified();
600 void SMESH_Actor::SetCellsLabeled(bool theIsCellsLabeled){
601 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
602 myIsCellsLabeled = theIsCellsLabeled && aGrid->GetNumberOfPoints();
603 if(myIsCellsLabeled){
604 myCellsNumDataSet->ShallowCopy(aGrid);
605 vtkDataSet *aDataSet = myCellsNumDataSet;
606 int aNbElem = aDataSet->GetNumberOfCells();
607 vtkIntArray *anArray = vtkIntArray::New();
608 anArray->SetNumberOfValues(aNbElem);
609 for(int anId = 0; anId < aNbElem; anId++){
610 int aSMDSId = myVisualObj->GetElemObjId(anId);
611 anArray->SetValue(anId,aSMDSId);
613 aDataSet->GetCellData()->SetScalars(anArray);
614 myCellCenters->SetInput(aDataSet);
615 myCellsLabels->SetVisibility(GetVisibility());
617 myCellsLabels->SetVisibility(false);
619 myTimeStamp->Modified();
623 void SMESH_Actor::SetControlMode(eControl theMode){
625 my1DColorMode = e1DNone;
627 my1DActor->GetMapper()->SetScalarVisibility(false);
628 my2DActor->GetMapper()->SetScalarVisibility(false);
629 my3DActor->GetMapper()->SetScalarVisibility(false);
630 myScalarBarActor->SetVisibility(false);
632 bool anIsScalarVisible = theMode > eNone;
634 if(anIsScalarVisible){
635 SMESH::Controls::FunctorPtr aFunctor;
639 SMESH::Controls::Length* aControl = new SMESH::Controls::Length();
640 aControl->SetPrecision( myControlsPrecision );
641 aFunctor.reset( aControl );
642 myControlActor = my1DActor;
646 aFunctor.reset(new SMESH::Controls::FreeBorders());
647 myControlActor = my1DActor;
650 aFunctor.reset(new SMESH::Controls::FreeEdges());
651 myControlActor = my2DActor;
653 case eMultiConnection:
654 aFunctor.reset(new SMESH::Controls::MultiConnection());
655 myControlActor = my1DActor;
659 SMESH::Controls::Area* aControl = new SMESH::Controls::Area();
660 aControl->SetPrecision( myControlsPrecision );
661 aFunctor.reset( aControl );
662 myControlActor = my2DActor;
667 SMESH::Controls::Taper* aControl = new SMESH::Controls::Taper();
668 aControl->SetPrecision( myControlsPrecision );
669 aFunctor.reset( aControl );
670 myControlActor = my2DActor;
675 SMESH::Controls::AspectRatio* aControl = new SMESH::Controls::AspectRatio();
676 aControl->SetPrecision( myControlsPrecision );
677 aFunctor.reset( aControl );
678 myControlActor = my2DActor;
683 SMESH::Controls::MinimumAngle* aControl = new SMESH::Controls::MinimumAngle();
684 aControl->SetPrecision( myControlsPrecision );
685 aFunctor.reset( aControl );
686 myControlActor = my2DActor;
691 SMESH::Controls::Warping* aControl = new SMESH::Controls::Warping();
692 aControl->SetPrecision( myControlsPrecision );
693 aFunctor.reset( aControl );
694 myControlActor = my2DActor;
699 SMESH::Controls::Skew* aControl = new SMESH::Controls::Skew();
700 aControl->SetPrecision( myControlsPrecision );
701 aFunctor.reset( aControl );
702 myControlActor = my2DActor;
709 vtkUnstructuredGrid* aGrid = myControlActor->GetUnstructuredGrid();
710 vtkIdType aNbCells = aGrid->GetNumberOfCells();
712 myColorMode = theMode;
713 if(theMode == eFreeBorders || theMode == eFreeEdges){
714 my1DColorMode = e1DHighlited;
715 my1DExtActor->SetExtControlMode(aFunctor,myControlActor);
717 if(myControlActor == my1DActor)
718 my1DColorMode = e1DColored;
719 myControlActor->SetControlMode(aFunctor,myScalarBarActor,myLookupTable);
723 SetRepresentation(GetRepresentation());
725 myTimeStamp->Modified();
730 void SMESH_Actor::AddToRender(vtkRenderer* theRenderer){
731 SALOME_Actor::AddToRender(theRenderer);
733 theRenderer->AddActor(myNodeActor);
734 theRenderer->AddActor(myBaseActor);
736 theRenderer->AddActor(my3DActor);
737 theRenderer->AddActor(my2DActor);
739 theRenderer->AddActor(my1DActor);
740 theRenderer->AddActor(my1DExtActor);
742 theRenderer->AddActor(myHighlitableActor);
743 theRenderer->AddActor(myNodeHighlitableActor);
745 theRenderer->AddActor2D(myScalarBarActor);
747 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
748 myClsSelectVisiblePoints->SetRenderer(theRenderer);
750 theRenderer->AddActor2D(myPointLabels);
751 theRenderer->AddActor2D(myCellsLabels);
754 void SMESH_Actor::RemoveFromRender(vtkRenderer* theRenderer){
755 SALOME_Actor::RemoveFromRender(theRenderer);
757 theRenderer->RemoveActor(myNodeActor);
758 theRenderer->RemoveActor(myBaseActor);
760 theRenderer->RemoveActor(myHighlitableActor);
761 theRenderer->RemoveActor(myNodeHighlitableActor);
763 theRenderer->RemoveActor(my1DActor);
764 theRenderer->RemoveActor(my1DExtActor);
766 theRenderer->RemoveActor(my2DActor);
767 theRenderer->RemoveActor(my3DActor);
769 theRenderer->RemoveActor(myScalarBarActor);
770 theRenderer->RemoveActor(myPointLabels);
771 theRenderer->RemoveActor(myCellsLabels);
775 bool SMESH_Actor::Init(TVisualObjPtr theVisualObj,
776 const char* theEntry,
780 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry,"SMESH",theName);
784 myVisualObj = theVisualObj;
785 myNodeActor->myVisualObj = myVisualObj;
786 myBaseActor->myVisualObj = myVisualObj;
788 myHighlitableActor->myVisualObj = myVisualObj;
789 myNodeHighlitableActor->myVisualObj = myVisualObj;
791 my1DActor->myVisualObj = myVisualObj;
792 my1DExtActor->myVisualObj = myVisualObj;
794 my2DActor->myVisualObj = myVisualObj;
795 my3DActor->myVisualObj = myVisualObj;
797 myVisualObj->Update(theIsClear);
799 myNodeActor->Init(myVisualObj,myImplicitBoolean);
800 myBaseActor->Init(myVisualObj,myImplicitBoolean);
802 myHighlitableActor->Init(myVisualObj,myImplicitBoolean);
803 myNodeHighlitableActor->Init(myVisualObj,myImplicitBoolean);
805 my1DActor->Init(myVisualObj,myImplicitBoolean);
806 my1DExtActor->Init(myVisualObj,myImplicitBoolean);
808 my2DActor->Init(myVisualObj,myImplicitBoolean);
809 my3DActor->Init(myVisualObj,myImplicitBoolean);
811 my1DActor->GetMapper()->SetLookupTable(myLookupTable);
812 my2DActor->GetMapper()->SetLookupTable(myLookupTable);
813 my3DActor->GetMapper()->SetLookupTable(myLookupTable);
815 float aFactor, aUnits;
816 my2DActor->GetPolygonOffsetParameters(aFactor,aUnits);
817 my2DActor->SetPolygonOffsetParameters(aFactor,aUnits*0.75);
819 //SetIsShrunkable(theGrid->GetNumberOfCells() > 10);
820 SetIsShrunkable(true);
822 QString aMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
823 SetRepresentation(-1);
824 if(aMode.compare("Wireframe") == 0){
825 SetRepresentation(eEdge);
826 }else if(aMode.compare("Shading") == 0){
827 SetRepresentation(eSurface);
828 }else if(aMode.compare("Nodes") == 0){
829 SetRepresentation(ePoint);
832 aMode = QAD_CONFIG->getSetting("SMESH:Shrink");
837 myTimeStamp->Modified();
843 float* SMESH_Actor::GetBounds(){
844 return myNodeActor->GetBounds();
848 vtkDataSet* SMESH_Actor::GetInput(){
849 return GetUnstructuredGrid();
853 void SMESH_Actor::SetTransform(SALOME_Transform* theTransform){
854 myNodeActor->SetTransform(theTransform);
855 myBaseActor->SetTransform(theTransform);
857 myHighlitableActor->SetTransform(theTransform);
858 myNodeHighlitableActor->SetTransform(theTransform);
860 my1DActor->SetTransform(theTransform);
861 my1DExtActor->SetTransform(theTransform);
863 my2DActor->SetTransform(theTransform);
864 my3DActor->SetTransform(theTransform);
870 void SMESH_Actor::SetMapper(vtkMapper* theMapper){
871 vtkLODActor::SetMapper(theMapper);
875 void SMESH_Actor::ShallowCopy(vtkProp *prop){
876 SALOME_Actor::ShallowCopy(prop);
880 vtkMapper* SMESH_Actor::GetMapper(){
881 return myPickableActor->GetMapper();
885 vtkUnstructuredGrid* SMESH_Actor::GetUnstructuredGrid(){
886 return myVisualObj->GetUnstructuredGrid();
890 bool SMESH_Actor::IsInfinitive(){
891 vtkDataSet *aDataSet = myPickableActor->GetUnstructuredGrid();
893 myIsInfinite = aDataSet->GetNumberOfCells() == 0 ||
894 aDataSet->GetNumberOfCells() == 1 &&
895 aDataSet->GetCell(0)->GetCellType() == VTK_VERTEX;
896 return SALOME_Actor::IsInfinitive();
900 void SMESH_Actor::SetIsShrunkable(bool theShrunkable){
901 myIsShrinkable = theShrunkable;
905 float SMESH_Actor::GetShrinkFactor(){
906 return myBaseActor->GetShrinkFactor();
909 void SMESH_Actor::SetShrinkFactor(float theValue){
910 myBaseActor->SetShrinkFactor(theValue);
912 my1DActor->SetShrinkFactor(theValue);
913 my1DExtActor->SetShrinkFactor(theValue);
915 my2DActor->SetShrinkFactor(theValue);
916 my3DActor->SetShrinkFactor(theValue);
921 void SMESH_Actor::SetShrink(){
922 if(!myIsShrinkable) return;
924 myBaseActor->SetShrink();
926 my1DActor->SetShrink();
927 my1DExtActor->SetShrink();
929 my2DActor->SetShrink();
930 my3DActor->SetShrink();
936 void SMESH_Actor::UnShrink(){
937 if(!myIsShrunk) return;
939 myBaseActor->UnShrink();
941 my1DActor->UnShrink();
942 my1DExtActor->UnShrink();
944 my2DActor->UnShrink();
945 my3DActor->UnShrink();
952 int SMESH_Actor::GetNodeObjId(int theVtkID){
953 return myPickableActor->GetNodeObjId(theVtkID);
956 float* SMESH_Actor::GetNodeCoord(int theObjID){
957 return myPickableActor->GetNodeCoord(theObjID);
961 int SMESH_Actor::GetElemObjId(int theVtkID){
962 return myPickableActor->GetElemObjId(theVtkID);
965 vtkCell* SMESH_Actor::GetElemCell(int theObjID){
966 return myPickableActor->GetElemCell(theObjID);
970 void SMESH_Actor::SetVisibility(int theMode){
971 SetVisibility(theMode,true);
975 void SMESH_Actor::SetVisibility(int theMode, bool theIsUpdateRepersentation){
976 SALOME_Actor::SetVisibility(theMode);
978 if(theIsUpdateRepersentation)
979 SetRepresentation(GetRepresentation());
981 if(myColorMode != eNone){
982 if(my1DColorMode == e1DHighlited)
983 my1DExtActor->VisibilityOn();
984 else if(myControlActor->GetUnstructuredGrid()->GetNumberOfCells())
985 myScalarBarActor->VisibilityOn();
988 if(myRepresentation != ePoint)
989 myPickableActor->VisibilityOn();
991 my1DActor->VisibilityOn();
993 my2DActor->VisibilityOn();
994 my3DActor->VisibilityOn();
996 if(myIsPointsLabeled) myPointLabels->VisibilityOn();
997 if(myIsCellsLabeled) myCellsLabels->VisibilityOn();
999 myNodeActor->VisibilityOff();
1000 myBaseActor->VisibilityOff();
1002 my1DActor->VisibilityOff();
1003 my1DExtActor->VisibilityOff();
1005 my2DActor->VisibilityOff();
1006 my3DActor->VisibilityOff();
1008 myScalarBarActor->VisibilityOff();
1009 myPointLabels->VisibilityOff();
1010 myCellsLabels->VisibilityOff();
1016 void SMESH_Actor::SetRepresentation(int theMode){
1017 int aNbEdges = myVisualObj->GetNbEntities(SMESH::EDGE);
1018 int aNbFaces = myVisualObj->GetNbEntities(SMESH::FACE);
1019 int aNbVolumes = myVisualObj->GetNbEntities(SMESH::VOLUME);
1021 myRepresentation = eSurface;
1022 if(!aNbFaces && !aNbVolumes && aNbEdges){
1023 myRepresentation = eEdge;
1024 }else if(!aNbFaces && !aNbVolumes && !aNbEdges){
1025 myRepresentation = ePoint;
1030 if(!aNbFaces && !aNbVolumes && !aNbEdges) return;
1033 if(!aNbFaces && !aNbVolumes) return;
1036 myRepresentation = theMode;
1039 if(!GetUnstructuredGrid()->GetNumberOfCells())
1040 myRepresentation = ePoint;
1043 if(myRepresentation == ePoint){
1051 myPickableActor = myBaseActor;
1052 myNodeActor->SetVisibility(false);
1053 vtkProperty *aProp = NULL, *aBackProp = NULL;
1054 SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1);
1055 switch(myRepresentation){
1057 myPickableActor = myNodeActor;
1058 myNodeActor->SetVisibility(true);
1060 aProp = aBackProp = myNodeProp;
1061 aReperesent = SMESH_DeviceActor::ePoint;
1064 aProp = aBackProp = myEdgeProp;
1065 aReperesent = SMESH_DeviceActor::eInsideframe;
1068 aProp = mySurfaceProp;
1069 aBackProp = myBackSurfaceProp;
1070 aReperesent = SMESH_DeviceActor::eSurface;
1074 my2DActor->SetProperty(aProp);
1075 my2DActor->SetBackfaceProperty(aBackProp);
1076 my2DActor->SetRepresentation(aReperesent);
1078 my3DActor->SetProperty(aProp);
1079 my3DActor->SetBackfaceProperty(aBackProp);
1080 my3DActor->SetRepresentation(aReperesent);
1082 my1DExtActor->SetVisibility(false);
1083 switch(my1DColorMode){
1085 aProp = aBackProp = my1DProp;
1086 if(myRepresentation != ePoint)
1087 aReperesent = SMESH_DeviceActor::eInsideframe;
1090 my1DExtActor->SetVisibility(true);
1094 my1DActor->SetProperty(aProp);
1095 my1DActor->SetBackfaceProperty(aBackProp);
1096 my1DActor->SetRepresentation(aReperesent);
1098 my1DExtActor->SetRepresentation(aReperesent);
1100 if(myIsPointsVisible)
1101 myPickableActor = myNodeActor;
1103 if(GetPointRepresentation())
1104 myNodeActor->SetVisibility(true);
1106 SetMapper(myPickableActor->GetMapper());
1108 SetVisibility(GetVisibility(),false);
1114 void SMESH_Actor::SetPointRepresentation(bool theIsPointsVisible){
1115 myIsPointsVisible = theIsPointsVisible;
1116 SetRepresentation(GetRepresentation());
1119 bool SMESH_Actor::GetPointRepresentation(){
1120 return myIsPointsVisible || myIsPointsLabeled;
1124 void SMESH_Actor::UpdateHighlight(){
1125 myHighlitableActor->SetVisibility(false);
1126 myHighlitableActor->SetHighlited(false);
1128 myNodeHighlitableActor->SetVisibility(false);
1129 myNodeHighlitableActor->SetHighlited(false);
1131 if(myIsHighlighted){
1132 myHighlitableActor->SetProperty(myHighlightProp);
1133 }else if(myIsPreselected){
1134 myHighlitableActor->SetProperty(myPreselectProp);
1137 bool isVisible = GetVisibility();
1139 if(myIsHighlighted || myIsPreselected){
1140 if(GetUnstructuredGrid()->GetNumberOfCells()){
1141 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
1142 myHighlitableActor->SetVisibility(isVisible);
1143 myHighlitableActor->SetHighlited(isVisible);
1145 if(myRepresentation == ePoint || GetPointRepresentation()){
1146 myNodeHighlitableActor->SetProperty(myHighlitableActor->GetProperty());
1147 myNodeHighlitableActor->SetVisibility(isVisible);
1148 myNodeHighlitableActor->SetHighlited(isVisible);
1154 void SMESH_Actor::highlight(bool theHighlight){
1155 myIsHighlighted = theHighlight;
1160 void SMESH_Actor::SetPreSelected(bool thePreselect){
1161 myIsPreselected = thePreselect;
1167 int SMESH_Actor::RenderOpaqueGeometry(vtkViewport *vp)
1169 if (myPickableActor->GetIsOpaque())
1171 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1179 int SMESH_Actor::RenderTranslucentGeometry(vtkViewport *vp)
1181 if (!myPickableActor->GetIsOpaque())
1183 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1191 void SMESH_Actor::Render(vtkRenderer *ren){
1192 unsigned long mTime = myTimeStamp->GetMTime();
1193 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1194 if(anObjTime > mTime)
1199 void SMESH_Actor::Update(){
1200 SetVisibility(GetVisibility());
1201 unsigned long int anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1202 unsigned long int aClippingTime = myImplicitBoolean->GetMTime();
1203 unsigned long int aTime = myTimeStamp->GetMTime();
1204 if(MYDEBUG) MESSAGE("SMESH_Actor::Update");
1206 if(GetControlMode() != eNone) {
1207 if(anObjTime > aTime || aClippingTime > aTime){
1208 SetControlMode(GetControlMode());
1209 SetVisibility(GetVisibility());
1212 if(myIsPointsLabeled){
1213 if(anObjTime > aTime || aClippingTime > aTime)
1214 SetPointsLabeled(myIsPointsLabeled);
1216 if(myIsCellsLabeled){
1217 if(anObjTime > aTime || aClippingTime > aTime)
1218 SetCellsLabeled(myIsCellsLabeled);
1221 myTimeStamp->Modified();
1226 void SMESH_Actor::ReleaseGraphicsResources(vtkWindow *renWin){
1227 SALOME_Actor::ReleaseGraphicsResources(renWin);
1229 myPickableActor->ReleaseGraphicsResources(renWin);
1233 static void GetColor(vtkProperty *theProperty, float& r,float& g,float& b){
1234 float* aColor = theProperty->GetColor();
1241 void SMESH_Actor::SetOpacity(float theValue){
1242 mySurfaceProp->SetOpacity(theValue);
1243 myBackSurfaceProp->SetOpacity(theValue);
1244 myEdgeProp->SetOpacity(theValue);
1245 myNodeProp->SetOpacity(theValue);
1247 my1DProp->SetOpacity(theValue);
1251 float SMESH_Actor::GetOpacity(){
1252 return mySurfaceProp->GetOpacity();
1256 void SMESH_Actor::SetSufaceColor(float r,float g,float b){
1257 mySurfaceProp->SetColor(r,g,b);
1261 void SMESH_Actor::GetSufaceColor(float& r,float& g,float& b){
1262 ::GetColor(mySurfaceProp,r,g,b);
1265 void SMESH_Actor::SetBackSufaceColor(float r,float g,float b){
1266 myBackSurfaceProp->SetColor(r,g,b);
1270 void SMESH_Actor::GetBackSufaceColor(float& r,float& g,float& b){
1271 ::GetColor(myBackSurfaceProp,r,g,b);
1274 void SMESH_Actor::SetEdgeColor(float r,float g,float b){
1275 myEdgeProp->SetColor(r,g,b);
1276 my1DProp->SetColor(r,g,b);
1277 my1DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1281 void SMESH_Actor::GetEdgeColor(float& r,float& g,float& b){
1282 ::GetColor(myEdgeProp,r,g,b);
1285 void SMESH_Actor::SetNodeColor(float r,float g,float b){
1286 myNodeProp->SetColor(r,g,b);
1290 void SMESH_Actor::GetNodeColor(float& r,float& g,float& b){
1291 ::GetColor(myNodeProp,r,g,b);
1294 void SMESH_Actor::SetHighlightColor(float r,float g,float b){
1295 myHighlightProp->SetColor(r,g,b);
1299 void SMESH_Actor::GetHighlightColor(float& r,float& g,float& b){
1300 ::GetColor(myHighlightProp,r,g,b);
1303 void SMESH_Actor::SetPreHighlightColor(float r,float g,float b){
1304 myPreselectProp->SetColor(r,g,b);
1308 void SMESH_Actor::GetPreHighlightColor(float& r,float& g,float& b){
1309 ::GetColor(myPreselectProp,r,g,b);
1313 float SMESH_Actor::GetLineWidth(){
1314 return myEdgeProp->GetLineWidth();
1318 void SMESH_Actor::SetLineWidth(float theVal){
1319 myEdgeProp->SetLineWidth(theVal);
1321 my1DProp->SetLineWidth(theVal + aLineWidthInc);
1322 my1DExtProp->SetLineWidth(theVal + aLineWidthInc);
1328 void SMESH_Actor::SetNodeSize(float theVal){
1329 myNodeProp->SetPointSize(theVal);
1330 myHighlightProp->SetPointSize(theVal);
1331 myPreselectProp->SetPointSize(theVal);
1333 my1DProp->SetPointSize(theVal + aPointSizeInc);
1334 my1DExtProp->SetPointSize(theVal + aPointSizeInc);
1339 float SMESH_Actor::GetNodeSize(){
1340 return myNodeProp->GetPointSize();
1343 int SMESH_Actor::GetObjDimension( const int theObjId )
1345 return myVisualObj->GetElemDimension( theObjId );
1349 vtkImplicitBoolean* SMESH_Actor::GetPlaneContainer(){
1350 return myImplicitBoolean;
1354 static void ComputeBoundsParam(vtkDataSet* theDataSet,
1355 float theDirection[3], float theMinPnt[3],
1356 float& theMaxBoundPrj, float& theMinBoundPrj)
1359 theDataSet->GetBounds(aBounds);
1361 //Enlarge bounds in order to avoid conflicts of precision
1362 for(int i = 0; i < 6; i += 2){
1363 static double EPS = 1.0E-3;
1364 float aDelta = (aBounds[i+1] - aBounds[i])*EPS;
1365 aBounds[i] -= aDelta;
1366 aBounds[i+1] += aDelta;
1369 float aBoundPoints[8][3] = { {aBounds[0],aBounds[2],aBounds[4]},
1370 {aBounds[1],aBounds[2],aBounds[4]},
1371 {aBounds[0],aBounds[3],aBounds[4]},
1372 {aBounds[1],aBounds[3],aBounds[4]},
1373 {aBounds[0],aBounds[2],aBounds[5]},
1374 {aBounds[1],aBounds[2],aBounds[5]},
1375 {aBounds[0],aBounds[3],aBounds[5]},
1376 {aBounds[1],aBounds[3],aBounds[5]}};
1378 int aMaxId = 0, aMinId = aMaxId;
1379 theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
1380 theMinBoundPrj = theMaxBoundPrj;
1381 for(int i = 1; i < 8; i++){
1382 float aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
1383 if(theMaxBoundPrj < aTmp){
1384 theMaxBoundPrj = aTmp;
1387 if(theMinBoundPrj > aTmp){
1388 theMinBoundPrj = aTmp;
1392 float *aMinPnt = aBoundPoints[aMaxId];
1393 theMinPnt[0] = aMinPnt[0];
1394 theMinPnt[1] = aMinPnt[1];
1395 theMinPnt[2] = aMinPnt[2];
1399 static void DistanceToPosition(vtkDataSet* theDataSet,
1400 float theDirection[3], float theDist, float thePos[3])
1402 float aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1403 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1404 float aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
1405 thePos[0] = aMinPnt[0]-theDirection[0]*aLength;
1406 thePos[1] = aMinPnt[1]-theDirection[1]*aLength;
1407 thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
1411 static void PositionToDistance(vtkDataSet* theDataSet,
1412 float theDirection[3], float thePos[3], float& theDist)
1414 float aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1415 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1416 float aPrj = vtkMath::Dot(theDirection,thePos);
1417 theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
1421 void SMESH_Actor::SetPlaneParam(float theDir[3], float theDist, vtkPlane* thePlane)
1423 thePlane->SetNormal(theDir);
1425 ::DistanceToPosition(GetUnstructuredGrid(),theDir,theDist,anOrigin);
1426 thePlane->SetOrigin(anOrigin);
1431 void SMESH_Actor::GetPlaneParam(float theDir[3], float& theDist, vtkPlane* thePlane)
1433 thePlane->GetNormal(theDir);
1436 thePlane->GetOrigin(anOrigin);
1437 ::PositionToDistance(GetUnstructuredGrid(),theDir,anOrigin,theDist);