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 "SALOME_ExtractUnstructuredGrid.h"
36 #include "QAD_Config.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>
72 #include "utilities.h"
75 static int MYDEBUG = 0;
77 static int MYDEBUG = 0;
80 static int aLineWidthInc = 2;
81 static int aPointSizeInc = 2;
84 SMESH_ActorDef* SMESH_ActorDef::New(){
85 return new SMESH_ActorDef();
89 SMESH_Actor* SMESH_Actor::New(TVisualObjPtr theVisualObj,
94 SMESH_ActorDef* anActor = SMESH_ActorDef::New();
95 if(!anActor->Init(theVisualObj,theEntry,theName,theIsClear)){
103 SMESH_ActorDef::SMESH_ActorDef(){
104 if(MYDEBUG) MESSAGE("SMESH_ActorDef");
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.);
287 myControlMode = eNone;
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 myEntityMode = eAllEntity;
444 myIsPointsLabeled = false;
446 myPointLabels = vtkActor2D::New();
447 myPointLabels->SetMapper(myPtsLabeledDataMapper);
448 myPointLabels->GetProperty()->SetColor(1,1,1);
449 myPointLabels->SetVisibility(myIsPointsLabeled);
452 //Definition of cells numbering pipeline
453 //---------------------------------------
454 myCellsNumDataSet = vtkUnstructuredGrid::New();
456 myCellCenters = vtkCellCenters::New();
457 myCellCenters->SetInput(myCellsNumDataSet);
459 myClsMaskPoints = vtkMaskPoints::New();
460 myClsMaskPoints->SetInput(myCellCenters->GetOutput());
461 myClsMaskPoints->SetOnRatio(1);
463 myClsSelectVisiblePoints = vtkSelectVisiblePoints::New();
464 myClsSelectVisiblePoints->SetInput(myClsMaskPoints->GetOutput());
465 myClsSelectVisiblePoints->SelectInvisibleOff();
466 myClsSelectVisiblePoints->SetTolerance(0.1);
468 myClsLabeledDataMapper = vtkLabeledDataMapper::New();
469 myClsLabeledDataMapper->SetInput(myClsSelectVisiblePoints->GetOutput());
470 myClsLabeledDataMapper->SetLabelFormat("%g");
471 myClsLabeledDataMapper->SetLabelModeToLabelScalars();
473 vtkTextProperty* aClsTextProp = vtkTextProperty::New();
474 aClsTextProp->SetFontFamilyToTimes();
475 static int aCellsFontSize = 12;
476 aClsTextProp->SetFontSize(aCellsFontSize);
477 aClsTextProp->SetBold(1);
478 aClsTextProp->SetItalic(0);
479 aClsTextProp->SetShadow(0);
480 myClsLabeledDataMapper->SetLabelTextProperty(aClsTextProp);
481 aClsTextProp->Delete();
483 myIsCellsLabeled = false;
485 myCellsLabels = vtkActor2D::New();
486 myCellsLabels->SetMapper(myClsLabeledDataMapper);
487 myCellsLabels->GetProperty()->SetColor(0,1,0);
488 myCellsLabels->SetVisibility(myIsCellsLabeled);
491 myImplicitBoolean = vtkImplicitBoolean::New();
492 myImplicitBoolean->SetOperationTypeToIntersection();
496 SMESH_ActorDef::~SMESH_ActorDef(){
497 if(MYDEBUG) MESSAGE("~SMESH_ActorDef");
499 myScalarBarActor->Delete();
500 myLookupTable->Delete();
502 mySurfaceProp->Delete();
503 myBackSurfaceProp->Delete();
505 myEdgeProp->Delete();
506 myHighlightProp->Delete();
507 myPreselectProp->Delete();
509 myNodeProp->Delete();
514 my1DExtProp->Delete();
515 my1DExtActor->Delete();
520 myNodeActor->Delete();
521 myBaseActor->Delete();
523 myHighlitableActor->Delete();
524 myNodeHighlitableActor->Delete();
527 //Deleting of pints numbering pipeline
528 //---------------------------------------
529 myPointsNumDataSet->Delete();
531 myPtsLabeledDataMapper->RemoveAllInputs();
532 myPtsLabeledDataMapper->Delete();
534 myPtsSelectVisiblePoints->UnRegisterAllOutputs();
535 myPtsSelectVisiblePoints->Delete();
537 myPtsMaskPoints->UnRegisterAllOutputs();
538 myPtsMaskPoints->Delete();
540 myPointLabels->Delete();
543 //Deleting of cells numbering pipeline
544 //---------------------------------------
545 myCellsNumDataSet->Delete();
547 myClsLabeledDataMapper->RemoveAllInputs();
548 myClsLabeledDataMapper->Delete();
550 myClsSelectVisiblePoints->UnRegisterAllOutputs();
551 myClsSelectVisiblePoints->Delete();
553 myClsMaskPoints->UnRegisterAllOutputs();
554 myClsMaskPoints->Delete();
556 myCellCenters->UnRegisterAllOutputs();
557 myCellCenters->Delete();
559 myCellsLabels->Delete();
561 myImplicitBoolean->Delete();
563 myTimeStamp->Delete();
567 void SMESH_ActorDef::SetPointsLabeled( bool theIsPointsLabeled )
569 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
570 myIsPointsLabeled = theIsPointsLabeled && aGrid->GetNumberOfPoints();
572 if ( myIsPointsLabeled )
574 myPointsNumDataSet->ShallowCopy(aGrid);
575 vtkDataSet *aDataSet = myPointsNumDataSet;
577 int aNbElem = aDataSet->GetNumberOfPoints();
579 vtkIntArray *anArray = vtkIntArray::New();
580 anArray->SetNumberOfValues( aNbElem );
582 for ( int anId = 0; anId < aNbElem; anId++ )
584 int aSMDSId = myVisualObj->GetNodeObjId( anId );
585 anArray->SetValue( anId, aSMDSId );
588 aDataSet->GetPointData()->SetScalars( anArray );
590 myPtsMaskPoints->SetInput( aDataSet );
591 myPointLabels->SetVisibility( GetVisibility() );
595 myPointLabels->SetVisibility( false );
597 SetRepresentation(GetRepresentation());
598 myTimeStamp->Modified();
602 void SMESH_ActorDef::SetCellsLabeled(bool theIsCellsLabeled){
603 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
604 myIsCellsLabeled = theIsCellsLabeled && aGrid->GetNumberOfPoints();
605 if(myIsCellsLabeled){
606 myCellsNumDataSet->ShallowCopy(aGrid);
607 vtkDataSet *aDataSet = myCellsNumDataSet;
608 int aNbElem = aDataSet->GetNumberOfCells();
609 vtkIntArray *anArray = vtkIntArray::New();
610 anArray->SetNumberOfValues(aNbElem);
611 for(int anId = 0; anId < aNbElem; anId++){
612 int aSMDSId = myVisualObj->GetElemObjId(anId);
613 anArray->SetValue(anId,aSMDSId);
615 aDataSet->GetCellData()->SetScalars(anArray);
616 myCellCenters->SetInput(aDataSet);
617 myCellsLabels->SetVisibility(GetVisibility());
619 myCellsLabels->SetVisibility(false);
621 myTimeStamp->Modified();
625 void SMESH_ActorDef::SetControlMode(eControl theMode){
626 myControlMode = eNone;
627 my1DColorMode = e1DNone;
629 my1DActor->GetMapper()->SetScalarVisibility(false);
630 my2DActor->GetMapper()->SetScalarVisibility(false);
631 my3DActor->GetMapper()->SetScalarVisibility(false);
632 myScalarBarActor->SetVisibility(false);
634 bool anIsScalarVisible = theMode > eNone;
636 if(anIsScalarVisible){
637 SMESH::Controls::FunctorPtr aFunctor;
641 SMESH::Controls::Length* aControl = new SMESH::Controls::Length();
642 aControl->SetPrecision( myControlsPrecision );
643 aFunctor.reset( aControl );
644 myControlActor = my1DActor;
649 aFunctor.reset(new SMESH::Controls::Length2D());
650 myControlActor = my2DActor;
654 aFunctor.reset(new SMESH::Controls::FreeBorders());
655 myControlActor = my1DActor;
658 aFunctor.reset(new SMESH::Controls::FreeEdges());
659 myControlActor = my2DActor;
661 case eMultiConnection:
662 aFunctor.reset(new SMESH::Controls::MultiConnection());
663 myControlActor = my1DActor;
667 SMESH::Controls::Area* aControl = new SMESH::Controls::Area();
668 aControl->SetPrecision( myControlsPrecision );
669 aFunctor.reset( aControl );
670 myControlActor = my2DActor;
675 SMESH::Controls::Taper* aControl = new SMESH::Controls::Taper();
676 aControl->SetPrecision( myControlsPrecision );
677 aFunctor.reset( aControl );
678 myControlActor = my2DActor;
683 SMESH::Controls::AspectRatio* aControl = new SMESH::Controls::AspectRatio();
684 aControl->SetPrecision( myControlsPrecision );
685 aFunctor.reset( aControl );
686 myControlActor = my2DActor;
691 SMESH::Controls::AspectRatio3D* aControl = new SMESH::Controls::AspectRatio3D();
692 aControl->SetPrecision( myControlsPrecision );
693 aFunctor.reset( aControl );
694 myControlActor = my3DActor;
699 SMESH::Controls::MinimumAngle* aControl = new SMESH::Controls::MinimumAngle();
700 aControl->SetPrecision( myControlsPrecision );
701 aFunctor.reset( aControl );
702 myControlActor = my2DActor;
707 SMESH::Controls::Warping* aControl = new SMESH::Controls::Warping();
708 aControl->SetPrecision( myControlsPrecision );
709 aFunctor.reset( aControl );
710 myControlActor = my2DActor;
715 SMESH::Controls::Skew* aControl = new SMESH::Controls::Skew();
716 aControl->SetPrecision( myControlsPrecision );
717 aFunctor.reset( aControl );
718 myControlActor = my2DActor;
725 vtkUnstructuredGrid* aGrid = myControlActor->GetUnstructuredGrid();
726 vtkIdType aNbCells = aGrid->GetNumberOfCells();
728 myControlMode = theMode;
729 if(theMode == eFreeBorders || theMode == eFreeEdges){
730 my1DColorMode = e1DHighlited;
731 my1DExtActor->SetExtControlMode(aFunctor,myControlActor);
732 } else if (theMode == eLength){
733 my1DColorMode = e1DColored;
734 my1DExtActor->SetLength2DControlMode(aFunctor,myControlActor,myScalarBarActor,myLookupTable);
736 if(myControlActor == my1DActor)
737 my1DColorMode = e1DColored;
738 myControlActor->SetControlMode(aFunctor,myScalarBarActor,myLookupTable);
742 SetRepresentation(GetRepresentation());
744 myTimeStamp->Modified();
749 void SMESH_ActorDef::AddToRender(vtkRenderer* theRenderer){
750 SALOME_Actor::AddToRender(theRenderer);
752 theRenderer->AddActor(myNodeActor);
753 theRenderer->AddActor(myBaseActor);
755 theRenderer->AddActor(my3DActor);
756 theRenderer->AddActor(my2DActor);
758 theRenderer->AddActor(my1DActor);
759 theRenderer->AddActor(my1DExtActor);
761 theRenderer->AddActor(myHighlitableActor);
762 theRenderer->AddActor(myNodeHighlitableActor);
764 theRenderer->AddActor2D(myScalarBarActor);
766 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
767 myClsSelectVisiblePoints->SetRenderer(theRenderer);
769 theRenderer->AddActor2D(myPointLabels);
770 theRenderer->AddActor2D(myCellsLabels);
773 void SMESH_ActorDef::RemoveFromRender(vtkRenderer* theRenderer){
774 SALOME_Actor::RemoveFromRender(theRenderer);
776 theRenderer->RemoveActor(myNodeActor);
777 theRenderer->RemoveActor(myBaseActor);
779 theRenderer->RemoveActor(myHighlitableActor);
780 theRenderer->RemoveActor(myNodeHighlitableActor);
782 theRenderer->RemoveActor(my1DActor);
783 theRenderer->RemoveActor(my1DExtActor);
785 theRenderer->RemoveActor(my2DActor);
786 theRenderer->RemoveActor(my3DActor);
788 theRenderer->RemoveActor(myScalarBarActor);
789 theRenderer->RemoveActor(myPointLabels);
790 theRenderer->RemoveActor(myCellsLabels);
794 bool SMESH_ActorDef::Init(TVisualObjPtr theVisualObj,
795 const char* theEntry,
799 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry,"SMESH",theName);
803 myVisualObj = theVisualObj;
804 myNodeActor->myVisualObj = myVisualObj;
805 myBaseActor->myVisualObj = myVisualObj;
807 myHighlitableActor->myVisualObj = myVisualObj;
808 myNodeHighlitableActor->myVisualObj = myVisualObj;
810 my1DActor->myVisualObj = myVisualObj;
811 my1DExtActor->myVisualObj = myVisualObj;
813 my2DActor->myVisualObj = myVisualObj;
814 my3DActor->myVisualObj = myVisualObj;
816 myVisualObj->Update(theIsClear);
818 myNodeActor->Init(myVisualObj,myImplicitBoolean);
819 myBaseActor->Init(myVisualObj,myImplicitBoolean);
821 myHighlitableActor->Init(myVisualObj,myImplicitBoolean);
822 myNodeHighlitableActor->Init(myVisualObj,myImplicitBoolean);
824 my1DActor->Init(myVisualObj,myImplicitBoolean);
825 my1DExtActor->Init(myVisualObj,myImplicitBoolean);
827 my2DActor->Init(myVisualObj,myImplicitBoolean);
828 my3DActor->Init(myVisualObj,myImplicitBoolean);
830 my1DActor->GetMapper()->SetLookupTable(myLookupTable);
831 my2DActor->GetMapper()->SetLookupTable(myLookupTable);
832 my3DActor->GetMapper()->SetLookupTable(myLookupTable);
834 float aFactor, aUnits;
835 my2DActor->GetPolygonOffsetParameters(aFactor,aUnits);
836 my2DActor->SetPolygonOffsetParameters(aFactor,aUnits*0.75);
838 //SetIsShrunkable(theGrid->GetNumberOfCells() > 10);
839 SetIsShrunkable(true);
841 QString aMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
842 SetRepresentation(-1);
843 if(aMode.compare("Wireframe") == 0){
844 SetRepresentation(eEdge);
845 }else if(aMode.compare("Shading") == 0){
846 SetRepresentation(eSurface);
847 }else if(aMode.compare("Nodes") == 0){
848 SetRepresentation(ePoint);
851 aMode = QAD_CONFIG->getSetting("SMESH:Shrink");
856 myTimeStamp->Modified();
862 float* SMESH_ActorDef::GetBounds(){
863 return myNodeActor->GetBounds();
867 vtkDataSet* SMESH_ActorDef::GetInput(){
868 return GetUnstructuredGrid();
872 void SMESH_ActorDef::SetTransform(SALOME_Transform* theTransform){
873 myNodeActor->SetTransform(theTransform);
874 myBaseActor->SetTransform(theTransform);
876 myHighlitableActor->SetTransform(theTransform);
877 myNodeHighlitableActor->SetTransform(theTransform);
879 my1DActor->SetTransform(theTransform);
880 my1DExtActor->SetTransform(theTransform);
882 my2DActor->SetTransform(theTransform);
883 my3DActor->SetTransform(theTransform);
889 void SMESH_ActorDef::SetMapper(vtkMapper* theMapper){
890 vtkLODActor::SetMapper(theMapper);
894 void SMESH_ActorDef::ShallowCopy(vtkProp *prop){
895 SALOME_Actor::ShallowCopy(prop);
899 vtkMapper* SMESH_ActorDef::GetMapper(){
900 return myPickableActor->GetMapper();
904 vtkUnstructuredGrid* SMESH_ActorDef::GetUnstructuredGrid(){
905 return myVisualObj->GetUnstructuredGrid();
909 bool SMESH_ActorDef::IsInfinitive(){
910 vtkDataSet *aDataSet = myPickableActor->GetUnstructuredGrid();
912 myIsInfinite = aDataSet->GetNumberOfCells() == 0 ||
913 aDataSet->GetNumberOfCells() == 1 &&
914 aDataSet->GetCell(0)->GetCellType() == VTK_VERTEX;
915 return SALOME_Actor::IsInfinitive();
919 void SMESH_ActorDef::SetIsShrunkable(bool theShrunkable){
920 myIsShrinkable = theShrunkable;
924 float SMESH_ActorDef::GetShrinkFactor(){
925 return myBaseActor->GetShrinkFactor();
928 void SMESH_ActorDef::SetShrinkFactor(float theValue){
929 myBaseActor->SetShrinkFactor(theValue);
931 my1DActor->SetShrinkFactor(theValue);
932 my1DExtActor->SetShrinkFactor(theValue);
934 my2DActor->SetShrinkFactor(theValue);
935 my3DActor->SetShrinkFactor(theValue);
940 void SMESH_ActorDef::SetShrink(){
941 if(!myIsShrinkable) return;
943 myBaseActor->SetShrink();
945 my1DActor->SetShrink();
946 my1DExtActor->SetShrink();
948 my2DActor->SetShrink();
949 my3DActor->SetShrink();
955 void SMESH_ActorDef::UnShrink(){
956 if(!myIsShrunk) return;
958 myBaseActor->UnShrink();
960 my1DActor->UnShrink();
961 my1DExtActor->UnShrink();
963 my2DActor->UnShrink();
964 my3DActor->UnShrink();
971 int SMESH_ActorDef::GetNodeObjId(int theVtkID){
972 return myPickableActor->GetNodeObjId(theVtkID);
975 float* SMESH_ActorDef::GetNodeCoord(int theObjID){
976 return myPickableActor->GetNodeCoord(theObjID);
980 int SMESH_ActorDef::GetElemObjId(int theVtkID){
981 return myPickableActor->GetElemObjId(theVtkID);
984 vtkCell* SMESH_ActorDef::GetElemCell(int theObjID){
985 return myPickableActor->GetElemCell(theObjID);
989 void SMESH_ActorDef::SetVisibility(int theMode){
990 SetVisibility(theMode,true);
994 void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation){
995 SALOME_Actor::SetVisibility(theMode);
997 if(theIsUpdateRepersentation)
998 SetRepresentation(GetRepresentation());
1000 if(myControlMode != eNone){
1001 if(my1DColorMode == e1DHighlited || myControlMode == eLength)
1002 my1DExtActor->VisibilityOn();
1003 else if(myControlActor->GetUnstructuredGrid()->GetNumberOfCells())
1004 myScalarBarActor->VisibilityOn();
1007 if(myRepresentation != ePoint)
1008 myPickableActor->VisibilityOn();
1010 my1DActor->VisibilityOn();
1012 my2DActor->VisibilityOn();
1013 my3DActor->VisibilityOn();
1015 if(myIsPointsLabeled) myPointLabels->VisibilityOn();
1016 if(myIsCellsLabeled) myCellsLabels->VisibilityOn();
1018 myNodeActor->VisibilityOff();
1019 myBaseActor->VisibilityOff();
1021 my1DActor->VisibilityOff();
1022 my1DExtActor->VisibilityOff();
1024 my2DActor->VisibilityOff();
1025 my3DActor->VisibilityOff();
1027 myScalarBarActor->VisibilityOff();
1028 myPointLabels->VisibilityOff();
1029 myCellsLabels->VisibilityOff();
1036 inline bool UpdateEntityMode(unsigned int& theOutputMode,
1037 unsigned int theInputMode,
1038 unsigned int theMode,
1042 theOutputMode &= ~theMode;
1044 return theOutputMode & theMode && theCondition;
1049 void SMESH_ActorDef::SetEntityMode(unsigned int theMode){
1050 if(!myVisualObj->GetNbEntities(SMDSAbs_Edge))
1053 if(!myVisualObj->GetNbEntities(SMDSAbs_Face))
1056 if(!myVisualObj->GetNbEntities(SMDSAbs_Volume))
1057 theMode &= ~eVolumes;
1062 myScalarBarActor->VisibilityOff();
1064 my1DExtActor->VisibilityOff();
1065 my1DActor->VisibilityOff();
1067 my2DActor->VisibilityOff();
1068 my3DActor->VisibilityOff();
1070 if(theMode & eEdges)
1071 my1DActor->VisibilityOn();
1073 if(theMode & eFaces)
1074 my2DActor->VisibilityOn();
1076 if(theMode & eVolumes)
1077 my3DActor->VisibilityOn();
1079 myEntityMode = theMode;
1082 void SMESH_ActorDef::SetRepresentation(int theMode){
1083 int aNbEdges = myVisualObj->GetNbEntities(SMDSAbs_Edge);
1084 int aNbFaces = myVisualObj->GetNbEntities(SMDSAbs_Face);
1085 int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume);
1087 myRepresentation = eSurface;
1088 if(!aNbFaces && !aNbVolumes && aNbEdges){
1089 myRepresentation = eEdge;
1090 }else if(!aNbFaces && !aNbVolumes && !aNbEdges){
1091 myRepresentation = ePoint;
1096 if(!aNbFaces && !aNbVolumes && !aNbEdges) return;
1099 if(!aNbFaces && !aNbVolumes) return;
1102 myRepresentation = theMode;
1105 if(!GetUnstructuredGrid()->GetNumberOfCells())
1106 myRepresentation = ePoint;
1109 if(myRepresentation == ePoint){
1117 myPickableActor = myBaseActor;
1118 myNodeActor->SetVisibility(false);
1119 vtkProperty *aProp = NULL, *aBackProp = NULL;
1120 SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1);
1121 switch(myRepresentation){
1123 myPickableActor = myNodeActor;
1124 myNodeActor->SetVisibility(true);
1126 aProp = aBackProp = myNodeProp;
1127 aReperesent = SMESH_DeviceActor::ePoint;
1130 aProp = aBackProp = myEdgeProp;
1131 aReperesent = SMESH_DeviceActor::eInsideframe;
1134 aProp = mySurfaceProp;
1135 aBackProp = myBackSurfaceProp;
1136 aReperesent = SMESH_DeviceActor::eSurface;
1140 my2DActor->SetProperty(aProp);
1141 my2DActor->SetBackfaceProperty(aBackProp);
1142 my2DActor->SetRepresentation(aReperesent);
1144 my3DActor->SetProperty(aProp);
1145 my3DActor->SetBackfaceProperty(aBackProp);
1146 my3DActor->SetRepresentation(aReperesent);
1148 my1DExtActor->SetVisibility(false);
1149 // switch(my1DColorMode){
1151 // aProp = aBackProp = my1DProp;
1152 // if(myRepresentation != ePoint)
1153 // aReperesent = SMESH_DeviceActor::eInsideframe;
1155 // case e1DHighlited:
1156 // my1DExtActor->SetVisibility(true);
1159 if (my1DColorMode == e1DColored){
1160 aProp = aBackProp = my1DProp;
1161 if(myRepresentation != ePoint)
1162 aReperesent = SMESH_DeviceActor::eInsideframe;
1163 } else if (my1DColorMode == e1DHighlited || myControlMode == eLength){
1164 my1DExtActor->SetVisibility(true);
1167 my1DActor->SetProperty(aProp);
1168 my1DActor->SetBackfaceProperty(aBackProp);
1169 my1DActor->SetRepresentation(aReperesent);
1171 my1DExtActor->SetRepresentation(aReperesent);
1173 if(myIsPointsVisible)
1174 myPickableActor = myNodeActor;
1176 if(GetPointRepresentation())
1177 myNodeActor->SetVisibility(true);
1179 SetMapper(myPickableActor->GetMapper());
1181 SetVisibility(GetVisibility(),false);
1187 void SMESH_ActorDef::SetPointRepresentation(bool theIsPointsVisible){
1188 myIsPointsVisible = theIsPointsVisible;
1189 SetRepresentation(GetRepresentation());
1192 bool SMESH_ActorDef::GetPointRepresentation(){
1193 return myIsPointsVisible || myIsPointsLabeled;
1197 void SMESH_ActorDef::UpdateHighlight(){
1198 myHighlitableActor->SetVisibility(false);
1199 myHighlitableActor->SetHighlited(false);
1201 myNodeHighlitableActor->SetVisibility(false);
1202 myNodeHighlitableActor->SetHighlited(false);
1204 if(myIsHighlighted){
1205 myHighlitableActor->SetProperty(myHighlightProp);
1206 }else if(myIsPreselected){
1207 myHighlitableActor->SetProperty(myPreselectProp);
1210 bool isVisible = GetVisibility();
1212 if(myIsHighlighted || myIsPreselected){
1213 if(GetUnstructuredGrid()->GetNumberOfCells()){
1214 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
1215 myHighlitableActor->SetVisibility(isVisible);
1216 myHighlitableActor->SetHighlited(isVisible);
1218 if(myRepresentation == ePoint || GetPointRepresentation()){
1219 myNodeHighlitableActor->SetProperty(myHighlitableActor->GetProperty());
1220 myNodeHighlitableActor->SetVisibility(isVisible);
1221 myNodeHighlitableActor->SetHighlited(isVisible);
1227 void SMESH_ActorDef::highlight(bool theHighlight){
1228 myIsHighlighted = theHighlight;
1233 void SMESH_ActorDef::SetPreSelected(bool thePreselect){
1234 myIsPreselected = thePreselect;
1240 int SMESH_ActorDef::RenderOpaqueGeometry(vtkViewport *vp)
1242 if (myPickableActor->GetIsOpaque())
1244 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1252 int SMESH_ActorDef::RenderTranslucentGeometry(vtkViewport *vp)
1254 if (!myPickableActor->GetIsOpaque())
1256 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1264 void SMESH_ActorDef::Render(vtkRenderer *ren){
1265 unsigned long mTime = myTimeStamp->GetMTime();
1266 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1267 if(anObjTime > mTime)
1272 void SMESH_ActorDef::Update(){
1273 SetVisibility(GetVisibility());
1274 unsigned long int anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1275 unsigned long int aClippingTime = myImplicitBoolean->GetMTime();
1276 unsigned long int aTime = myTimeStamp->GetMTime();
1277 if(MYDEBUG) MESSAGE("SMESH_ActorDef::Update");
1279 if(GetControlMode() != eNone) {
1280 if(anObjTime > aTime || aClippingTime > aTime){
1281 SetControlMode(GetControlMode());
1282 SetVisibility(GetVisibility());
1285 if(myIsPointsLabeled){
1286 if(anObjTime > aTime || aClippingTime > aTime)
1287 SetPointsLabeled(myIsPointsLabeled);
1289 if(myIsCellsLabeled){
1290 if(anObjTime > aTime || aClippingTime > aTime)
1291 SetCellsLabeled(myIsCellsLabeled);
1294 myTimeStamp->Modified();
1299 void SMESH_ActorDef::ReleaseGraphicsResources(vtkWindow *renWin){
1300 SALOME_Actor::ReleaseGraphicsResources(renWin);
1302 myPickableActor->ReleaseGraphicsResources(renWin);
1306 static void GetColor(vtkProperty *theProperty, float& r,float& g,float& b){
1307 float* aColor = theProperty->GetColor();
1314 void SMESH_ActorDef::SetOpacity(float theValue){
1315 mySurfaceProp->SetOpacity(theValue);
1316 myBackSurfaceProp->SetOpacity(theValue);
1317 myEdgeProp->SetOpacity(theValue);
1318 myNodeProp->SetOpacity(theValue);
1320 my1DProp->SetOpacity(theValue);
1324 float SMESH_ActorDef::GetOpacity(){
1325 return mySurfaceProp->GetOpacity();
1329 void SMESH_ActorDef::SetSufaceColor(float r,float g,float b){
1330 mySurfaceProp->SetColor(r,g,b);
1334 void SMESH_ActorDef::GetSufaceColor(float& r,float& g,float& b){
1335 ::GetColor(mySurfaceProp,r,g,b);
1338 void SMESH_ActorDef::SetBackSufaceColor(float r,float g,float b){
1339 myBackSurfaceProp->SetColor(r,g,b);
1343 void SMESH_ActorDef::GetBackSufaceColor(float& r,float& g,float& b){
1344 ::GetColor(myBackSurfaceProp,r,g,b);
1347 void SMESH_ActorDef::SetEdgeColor(float r,float g,float b){
1348 myEdgeProp->SetColor(r,g,b);
1349 my1DProp->SetColor(r,g,b);
1350 my1DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1354 void SMESH_ActorDef::GetEdgeColor(float& r,float& g,float& b){
1355 ::GetColor(myEdgeProp,r,g,b);
1358 void SMESH_ActorDef::SetNodeColor(float r,float g,float b){
1359 myNodeProp->SetColor(r,g,b);
1363 void SMESH_ActorDef::GetNodeColor(float& r,float& g,float& b){
1364 ::GetColor(myNodeProp,r,g,b);
1367 void SMESH_ActorDef::SetHighlightColor(float r,float g,float b){
1368 myHighlightProp->SetColor(r,g,b);
1372 void SMESH_ActorDef::GetHighlightColor(float& r,float& g,float& b){
1373 ::GetColor(myHighlightProp,r,g,b);
1376 void SMESH_ActorDef::SetPreHighlightColor(float r,float g,float b){
1377 myPreselectProp->SetColor(r,g,b);
1381 void SMESH_ActorDef::GetPreHighlightColor(float& r,float& g,float& b){
1382 ::GetColor(myPreselectProp,r,g,b);
1386 float SMESH_ActorDef::GetLineWidth(){
1387 return myEdgeProp->GetLineWidth();
1391 void SMESH_ActorDef::SetLineWidth(float theVal){
1392 myEdgeProp->SetLineWidth(theVal);
1394 my1DProp->SetLineWidth(theVal + aLineWidthInc);
1395 my1DExtProp->SetLineWidth(theVal + aLineWidthInc);
1401 void SMESH_ActorDef::SetNodeSize(float theVal){
1402 myNodeProp->SetPointSize(theVal);
1403 myHighlightProp->SetPointSize(theVal);
1404 myPreselectProp->SetPointSize(theVal);
1406 my1DProp->SetPointSize(theVal + aPointSizeInc);
1407 my1DExtProp->SetPointSize(theVal + aPointSizeInc);
1412 float SMESH_ActorDef::GetNodeSize(){
1413 return myNodeProp->GetPointSize();
1416 int SMESH_ActorDef::GetObjDimension( const int theObjId )
1418 return myVisualObj->GetElemDimension( theObjId );
1422 vtkImplicitBoolean* SMESH_ActorDef::GetPlaneContainer(){
1423 return myImplicitBoolean;
1427 static void ComputeBoundsParam(vtkDataSet* theDataSet,
1428 float theDirection[3], float theMinPnt[3],
1429 float& theMaxBoundPrj, float& theMinBoundPrj)
1432 theDataSet->GetBounds(aBounds);
1434 //Enlarge bounds in order to avoid conflicts of precision
1435 for(int i = 0; i < 6; i += 2){
1436 static double EPS = 1.0E-3;
1437 float aDelta = (aBounds[i+1] - aBounds[i])*EPS;
1438 aBounds[i] -= aDelta;
1439 aBounds[i+1] += aDelta;
1442 float aBoundPoints[8][3] = { {aBounds[0],aBounds[2],aBounds[4]},
1443 {aBounds[1],aBounds[2],aBounds[4]},
1444 {aBounds[0],aBounds[3],aBounds[4]},
1445 {aBounds[1],aBounds[3],aBounds[4]},
1446 {aBounds[0],aBounds[2],aBounds[5]},
1447 {aBounds[1],aBounds[2],aBounds[5]},
1448 {aBounds[0],aBounds[3],aBounds[5]},
1449 {aBounds[1],aBounds[3],aBounds[5]}};
1451 int aMaxId = 0, aMinId = aMaxId;
1452 theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
1453 theMinBoundPrj = theMaxBoundPrj;
1454 for(int i = 1; i < 8; i++){
1455 float aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
1456 if(theMaxBoundPrj < aTmp){
1457 theMaxBoundPrj = aTmp;
1460 if(theMinBoundPrj > aTmp){
1461 theMinBoundPrj = aTmp;
1465 float *aMinPnt = aBoundPoints[aMaxId];
1466 theMinPnt[0] = aMinPnt[0];
1467 theMinPnt[1] = aMinPnt[1];
1468 theMinPnt[2] = aMinPnt[2];
1472 static void DistanceToPosition(vtkDataSet* theDataSet,
1473 float theDirection[3], float theDist, float thePos[3])
1475 float aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1476 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1477 float aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
1478 thePos[0] = aMinPnt[0]-theDirection[0]*aLength;
1479 thePos[1] = aMinPnt[1]-theDirection[1]*aLength;
1480 thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
1484 static void PositionToDistance(vtkDataSet* theDataSet,
1485 float theDirection[3], float thePos[3], float& theDist)
1487 float aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1488 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1489 float aPrj = vtkMath::Dot(theDirection,thePos);
1490 theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
1494 void SMESH_ActorDef::SetPlaneParam(float theDir[3], float theDist, vtkPlane* thePlane)
1496 thePlane->SetNormal(theDir);
1498 ::DistanceToPosition(GetUnstructuredGrid(),theDir,theDist,anOrigin);
1499 thePlane->SetOrigin(anOrigin);
1504 void SMESH_ActorDef::GetPlaneParam(float theDir[3], float& theDist, vtkPlane* thePlane)
1506 thePlane->GetNormal(theDir);
1509 thePlane->GetOrigin(anOrigin);
1510 ::PositionToDistance(GetUnstructuredGrid(),theDir,anOrigin,theDist);