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);
163 aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
166 //Definition 1D divice of the actor
167 //---------------------------------
168 myEdgeProp = vtkProperty::New();
169 myEdgeProp->SetAmbient(1.0);
170 myEdgeProp->SetDiffuse(0.0);
171 myEdgeProp->SetSpecular(0.0);
172 anRGB[0] = SMESH::GetFloat("SMESH:SettingsOutlineColorRed", 0)/255.;
173 anRGB[1] = SMESH::GetFloat("SMESH:SettingsOutlineColorGreen", 170)/255.;
174 anRGB[2] = SMESH::GetFloat("SMESH:SettingsOutlineColorBlue", 255)/255.;
175 myEdgeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
176 myEdgeProp->SetLineWidth(aLineWidth);
178 my1DActor = SMESH_DeviceActor::New();
179 my1DActor->SetUserMatrix(aMatrix);
180 my1DActor->SetStoreMapping(true);
181 my1DActor->PickableOff();
182 my1DActor->SetHighlited(true);
183 my1DActor->SetProperty(myEdgeProp);
184 my1DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
185 aFilter = my1DActor->GetExtractUnstructuredGrid();
186 aFilter->SetModeOfChanging(SALOME_ExtractUnstructuredGrid::eAdding);
187 aFilter->RegisterCellsWithType(VTK_LINE);
189 my1DProp = vtkProperty::New();
190 my1DProp->DeepCopy(myEdgeProp);
191 my1DProp->SetLineWidth(aLineWidth + aLineWidthInc);
192 my1DProp->SetPointSize(aPointSize);
194 my1DExtProp = vtkProperty::New();
195 my1DExtProp->DeepCopy(myEdgeProp);
196 anRGB[0] = 1 - anRGB[0];
197 anRGB[1] = 1 - anRGB[1];
198 anRGB[2] = 1 - anRGB[2];
199 my1DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
200 my1DExtProp->SetLineWidth(aLineWidth + aLineWidthInc);
201 my1DExtProp->SetPointSize(aPointSize + aPointSizeInc);
203 my1DExtActor = SMESH_DeviceActor::New();
204 my1DExtActor->SetUserMatrix(aMatrix);
205 my1DExtActor->SetStoreMapping(true);
206 my1DExtActor->PickableOff();
207 my1DExtActor->SetHighlited(true);
208 my1DExtActor->SetVisibility(false);
209 my1DExtActor->SetProperty(my1DExtProp);
210 my1DExtActor->SetRepresentation(SMESH_DeviceActor::eInsideframe);
211 aFilter = my1DExtActor->GetExtractUnstructuredGrid();
212 aFilter->SetModeOfChanging(SALOME_ExtractUnstructuredGrid::eAdding);
213 aFilter->RegisterCellsWithType(VTK_LINE);
216 //Definition 0D divice of the actor
217 //---------------------------------
218 myNodeProp = vtkProperty::New();
219 anRGB[0] = SMESH::GetFloat("SMESH:SettingsNodeColorRed",255)/255.;
220 anRGB[1] = SMESH::GetFloat("SMESH:SettingsNodeColorGreen",0)/255.;
221 anRGB[2] = SMESH::GetFloat("SMESH:SettingsNodeColorBlue",0)/255.;
222 myNodeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
223 myNodeProp->SetPointSize(aPointSize);
225 myNodeActor = SMESH_DeviceActor::New();
226 myNodeActor->SetUserMatrix(aMatrix);
227 myNodeActor->SetStoreMapping(true);
228 myNodeActor->PickableOff();
229 myNodeActor->SetVisibility(false);
230 myNodeActor->SetProperty(myNodeProp);
231 myNodeActor->SetRepresentation(SMESH_DeviceActor::ePoint);
232 aFilter = myNodeActor->GetExtractUnstructuredGrid();
233 aFilter->SetModeOfExtraction(SALOME_ExtractUnstructuredGrid::ePoints);
236 //Definition of Pickable and Highlitable engines
237 //----------------------------------------------
239 myBaseActor = SMESH_DeviceActor::New();
240 myBaseActor->SetUserMatrix(aMatrix);
241 myBaseActor->SetStoreMapping(true);
242 myBaseActor->GetProperty()->SetOpacity(0.0);
243 myBaseActor->myGeomFilter->SetInside(true);
245 myPickableActor = myBaseActor;
247 myHighlightProp = vtkProperty::New();
248 myHighlightProp->SetAmbient(1.0);
249 myHighlightProp->SetDiffuse(0.0);
250 myHighlightProp->SetSpecular(0.0);
251 anRGB[0] = SMESH::GetFloat("SMESH:SettingsSelectColorRed", 255)/255.; // 1;
252 anRGB[1] = SMESH::GetFloat("SMESH:SettingsSelectColorGreen", 255)/255.; // 1;
253 anRGB[2] = SMESH::GetFloat("SMESH:SettingsSelectColorBlue", 255)/255.; // 1;
254 myHighlightProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
255 myHighlightProp->SetPointSize(aPointSize);
256 myHighlightProp->SetRepresentation(1);
258 myPreselectProp = vtkProperty::New();
259 myPreselectProp->SetAmbient(1.0);
260 myPreselectProp->SetDiffuse(0.0);
261 myPreselectProp->SetSpecular(0.0);
262 anRGB[0] = SMESH::GetFloat("SMESH:SettingsPreSelectColorRed", 0)/255.; // 0;
263 anRGB[1] = SMESH::GetFloat("SMESH:SettingsPreSelectColorGreen", 255)/255.; // 1;
264 anRGB[2] = SMESH::GetFloat("SMESH:SettingsPreSelectColorBlue", 255)/255.; // 1;
265 myPreselectProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
266 myPreselectProp->SetPointSize(aPointSize);
267 myPreselectProp->SetRepresentation(1);
269 myHighlitableActor = SMESH_DeviceActor::New();
270 myHighlitableActor->SetUserMatrix(aMatrix);
271 myHighlitableActor->SetStoreMapping(false);
272 myHighlitableActor->PickableOff();
273 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
275 myNodeHighlitableActor = SMESH_DeviceActor::New();
276 myNodeHighlitableActor->SetUserMatrix(aMatrix);
277 myNodeHighlitableActor->SetStoreMapping(false);
278 myNodeHighlitableActor->PickableOff();
279 myNodeHighlitableActor->SetRepresentation(SMESH_DeviceActor::ePoint);
280 aFilter = myNodeHighlitableActor->GetExtractUnstructuredGrid();
281 aFilter->SetModeOfExtraction(SALOME_ExtractUnstructuredGrid::ePoints);
284 SetShrinkFactor(SMESH::GetFloat("SMESH:SettingsShrinkCoeff", 75)/100.);
289 myControlMode = eNone;
290 myControlActor = my2DActor;
292 //Definition of myScalarBarActor
293 //------------------------------
294 myLookupTable = vtkLookupTable::New();
295 //Fix for Bug PAL5195 - SMESH764:
296 //Controls - Aspect Ratio: incorrect colors of the best and worst values
297 myLookupTable->SetHueRange(0.667,0.0);
299 myScalarBarActor = vtkScalarBarActor::New();
300 myScalarBarActor->SetVisibility(false);
301 myScalarBarActor->SetLookupTable(myLookupTable);
303 vtkTextProperty* aScalarBarTitleProp = vtkTextProperty::New();
305 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarTitleColor" ) ) {
306 QStringList aTColor = QStringList::split( ":", QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleColor" ), false );
307 aScalarBarTitleProp->SetColor( ( aTColor.count() > 0 ? aTColor[0].toInt()/255. : 1.0 ),
308 ( aTColor.count() > 1 ? aTColor[1].toInt()/255. : 1.0 ),
309 ( aTColor.count() > 2 ? aTColor[2].toInt()/255. : 1.0 ) );
312 aScalarBarTitleProp->SetColor( 1.0, 1.0, 1.0 );
314 aScalarBarTitleProp->SetFontFamilyToArial();
315 if( QAD_CONFIG->hasSetting( "SMESH:ScalarBarTitleFont" ) ){
316 if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleFont" ) == "Arial" )
317 aScalarBarTitleProp->SetFontFamilyToArial();
318 else if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleFont" ) == "Courier" )
319 aScalarBarTitleProp->SetFontFamilyToCourier();
320 else if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleFont" ) == "Times" )
321 aScalarBarTitleProp->SetFontFamilyToTimes();
324 if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleBold" ) == "true" )
325 aScalarBarTitleProp->BoldOn();
327 aScalarBarTitleProp->BoldOff();
329 if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleItalic" ) == "true" )
330 aScalarBarTitleProp->ItalicOn();
332 aScalarBarTitleProp->ItalicOff();
334 if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleShadow" ) == "true" )
335 aScalarBarTitleProp->ShadowOn();
337 aScalarBarTitleProp->ShadowOff();
339 myScalarBarActor->SetTitleTextProperty( aScalarBarTitleProp );
340 aScalarBarTitleProp->Delete();
342 vtkTextProperty* aScalarBarLabelProp = vtkTextProperty::New();
344 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarLabelColor" ) ) {
345 QStringList aTColor = QStringList::split( ":", QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelColor" ), false );
346 aScalarBarLabelProp->SetColor( ( aTColor.count() > 0 ? aTColor[0].toInt()/255. : 1.0 ),
347 ( aTColor.count() > 1 ? aTColor[1].toInt()/255. : 1.0 ),
348 ( aTColor.count() > 2 ? aTColor[2].toInt()/255. : 1.0 ) );
351 aScalarBarLabelProp->SetColor( 1.0, 1.0, 1.0 );
353 aScalarBarLabelProp->SetFontFamilyToArial();
354 if( QAD_CONFIG->hasSetting( "SMESH:ScalarBarLabelFont" ) ){
355 if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelFont" ) == "Arial" )
356 aScalarBarLabelProp->SetFontFamilyToArial();
357 else if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelFont" ) == "Courier" )
358 aScalarBarLabelProp->SetFontFamilyToCourier();
359 else if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelFont" ) == "Times" )
360 aScalarBarLabelProp->SetFontFamilyToTimes();
363 if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelBold" ) == "true" )
364 aScalarBarLabelProp->BoldOn();
366 aScalarBarLabelProp->BoldOff();
368 if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelItalic" ) == "true" )
369 aScalarBarLabelProp->ItalicOn();
371 aScalarBarLabelProp->ItalicOff();
373 if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelShadow" ) == "true" )
374 aScalarBarLabelProp->ShadowOn();
376 aScalarBarLabelProp->ShadowOff();
378 myScalarBarActor->SetLabelTextProperty( aScalarBarLabelProp );
379 aScalarBarLabelProp->Delete();
381 if ( QAD_CONFIG->getSetting("SMESH:ScalarBarOrientation") == "Horizontal" )
382 myScalarBarActor->SetOrientationToHorizontal();
384 myScalarBarActor->SetOrientationToVertical();
386 float aXVal = QAD_CONFIG->getSetting("SMESH:ScalarBarOrientation") == "Horizontal" ? 0.20 : 0.01;
387 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarXPosition" ) )
388 aXVal = QAD_CONFIG->getSetting( "SMESH:ScalarBarXPosition" ).toFloat();
389 float aYVal = QAD_CONFIG->getSetting("SMESH:ScalarBarOrientation") == "Horizontal" ? 0.01 : 0.1;
390 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarYPosition" ) )
391 aYVal = QAD_CONFIG->getSetting( "SMESH:ScalarBarYPosition" ).toFloat();
392 myScalarBarActor->SetPosition( aXVal, aYVal );
394 float aWVal = QAD_CONFIG->getSetting("SMESH:ScalarBarOrientation") == "Horizontal" ? 0.60 : 0.10;
395 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarWidth" ) )
396 aWVal = QAD_CONFIG->getSetting( "SMESH:ScalarBarWidth" ).toFloat();
397 myScalarBarActor->SetWidth( aWVal );
399 float aHVal = QAD_CONFIG->getSetting("SMESH:ScalarBarOrientation") == "Horizontal" ? 0.12 : 0.80;
400 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarHeight" ) )
401 aHVal = QAD_CONFIG->getSetting( "SMESH:ScalarBarHeight" ).toFloat();
402 myScalarBarActor->SetHeight( aHVal );
405 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarNbOfLabels" ) )
406 anIntVal = QAD_CONFIG->getSetting("SMESH:ScalarBarNbOfLabels").toInt();
407 myScalarBarActor->SetNumberOfLabels(anIntVal == 0? 5: anIntVal);
410 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarNbOfColors" ) )
411 anIntVal = QAD_CONFIG->getSetting("SMESH:ScalarBarNbOfColors").toInt();
412 myScalarBarActor->SetMaximumNumberOfColors(anIntVal == 0? 64: anIntVal);
415 //Definition of points numbering pipeline
416 //---------------------------------------
417 myPointsNumDataSet = vtkUnstructuredGrid::New();
419 myPtsMaskPoints = vtkMaskPoints::New();
420 myPtsMaskPoints->SetInput(myPointsNumDataSet);
421 myPtsMaskPoints->SetOnRatio(1);
423 myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
424 myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
425 myPtsSelectVisiblePoints->SelectInvisibleOff();
426 myPtsSelectVisiblePoints->SetTolerance(0.1);
428 myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
429 myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
430 myPtsLabeledDataMapper->SetLabelFormat("%g");
431 myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
433 vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
434 aPtsTextProp->SetFontFamilyToTimes();
435 static int aPointsFontSize = 10;
436 aPtsTextProp->SetFontSize(aPointsFontSize);
437 aPtsTextProp->SetBold(1);
438 aPtsTextProp->SetItalic(0);
439 aPtsTextProp->SetShadow(0);
440 myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
441 aPtsTextProp->Delete();
443 myEntityMode = eAllEntity;
445 myIsPointsLabeled = false;
447 myPointLabels = vtkActor2D::New();
448 myPointLabels->SetMapper(myPtsLabeledDataMapper);
449 myPointLabels->GetProperty()->SetColor(1,1,1);
450 myPointLabels->SetVisibility(myIsPointsLabeled);
453 //Definition of cells numbering pipeline
454 //---------------------------------------
455 myCellsNumDataSet = vtkUnstructuredGrid::New();
457 myCellCenters = vtkCellCenters::New();
458 myCellCenters->SetInput(myCellsNumDataSet);
460 myClsMaskPoints = vtkMaskPoints::New();
461 myClsMaskPoints->SetInput(myCellCenters->GetOutput());
462 myClsMaskPoints->SetOnRatio(1);
464 myClsSelectVisiblePoints = vtkSelectVisiblePoints::New();
465 myClsSelectVisiblePoints->SetInput(myClsMaskPoints->GetOutput());
466 myClsSelectVisiblePoints->SelectInvisibleOff();
467 myClsSelectVisiblePoints->SetTolerance(0.1);
469 myClsLabeledDataMapper = vtkLabeledDataMapper::New();
470 myClsLabeledDataMapper->SetInput(myClsSelectVisiblePoints->GetOutput());
471 myClsLabeledDataMapper->SetLabelFormat("%g");
472 myClsLabeledDataMapper->SetLabelModeToLabelScalars();
474 vtkTextProperty* aClsTextProp = vtkTextProperty::New();
475 aClsTextProp->SetFontFamilyToTimes();
476 static int aCellsFontSize = 12;
477 aClsTextProp->SetFontSize(aCellsFontSize);
478 aClsTextProp->SetBold(1);
479 aClsTextProp->SetItalic(0);
480 aClsTextProp->SetShadow(0);
481 myClsLabeledDataMapper->SetLabelTextProperty(aClsTextProp);
482 aClsTextProp->Delete();
484 myIsCellsLabeled = false;
486 myCellsLabels = vtkActor2D::New();
487 myCellsLabels->SetMapper(myClsLabeledDataMapper);
488 myCellsLabels->GetProperty()->SetColor(0,1,0);
489 myCellsLabels->SetVisibility(myIsCellsLabeled);
492 myImplicitBoolean = vtkImplicitBoolean::New();
493 myImplicitBoolean->SetOperationTypeToIntersection();
497 SMESH_ActorDef::~SMESH_ActorDef(){
498 if(MYDEBUG) MESSAGE("~SMESH_ActorDef");
500 myScalarBarActor->Delete();
501 myLookupTable->Delete();
503 mySurfaceProp->Delete();
504 myBackSurfaceProp->Delete();
506 myEdgeProp->Delete();
507 myHighlightProp->Delete();
508 myPreselectProp->Delete();
510 myNodeProp->Delete();
515 my1DExtProp->Delete();
516 my1DExtActor->Delete();
521 myNodeActor->Delete();
522 myBaseActor->Delete();
524 myHighlitableActor->Delete();
525 myNodeHighlitableActor->Delete();
528 //Deleting of pints numbering pipeline
529 //---------------------------------------
530 myPointsNumDataSet->Delete();
532 myPtsLabeledDataMapper->RemoveAllInputs();
533 myPtsLabeledDataMapper->Delete();
535 myPtsSelectVisiblePoints->UnRegisterAllOutputs();
536 myPtsSelectVisiblePoints->Delete();
538 myPtsMaskPoints->UnRegisterAllOutputs();
539 myPtsMaskPoints->Delete();
541 myPointLabels->Delete();
544 //Deleting of cells numbering pipeline
545 //---------------------------------------
546 myCellsNumDataSet->Delete();
548 myClsLabeledDataMapper->RemoveAllInputs();
549 myClsLabeledDataMapper->Delete();
551 myClsSelectVisiblePoints->UnRegisterAllOutputs();
552 myClsSelectVisiblePoints->Delete();
554 myClsMaskPoints->UnRegisterAllOutputs();
555 myClsMaskPoints->Delete();
557 myCellCenters->UnRegisterAllOutputs();
558 myCellCenters->Delete();
560 myCellsLabels->Delete();
562 myImplicitBoolean->Delete();
564 myTimeStamp->Delete();
568 void SMESH_ActorDef::SetPointsLabeled( bool theIsPointsLabeled )
570 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
571 myIsPointsLabeled = theIsPointsLabeled && aGrid->GetNumberOfPoints();
573 if ( myIsPointsLabeled )
575 myPointsNumDataSet->ShallowCopy(aGrid);
576 vtkDataSet *aDataSet = myPointsNumDataSet;
578 int aNbElem = aDataSet->GetNumberOfPoints();
580 vtkIntArray *anArray = vtkIntArray::New();
581 anArray->SetNumberOfValues( aNbElem );
583 for ( int anId = 0; anId < aNbElem; anId++ )
585 int aSMDSId = myVisualObj->GetNodeObjId( anId );
586 anArray->SetValue( anId, aSMDSId );
589 aDataSet->GetPointData()->SetScalars( anArray );
591 myPtsMaskPoints->SetInput( aDataSet );
592 myPointLabels->SetVisibility( GetVisibility() );
596 myPointLabels->SetVisibility( false );
598 SetRepresentation(GetRepresentation());
599 myTimeStamp->Modified();
603 void SMESH_ActorDef::SetCellsLabeled(bool theIsCellsLabeled){
604 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
605 myIsCellsLabeled = theIsCellsLabeled && aGrid->GetNumberOfPoints();
606 if(myIsCellsLabeled){
607 myCellsNumDataSet->ShallowCopy(aGrid);
608 vtkDataSet *aDataSet = myCellsNumDataSet;
609 int aNbElem = aDataSet->GetNumberOfCells();
610 vtkIntArray *anArray = vtkIntArray::New();
611 anArray->SetNumberOfValues(aNbElem);
612 for(int anId = 0; anId < aNbElem; anId++){
613 int aSMDSId = myVisualObj->GetElemObjId(anId);
614 anArray->SetValue(anId,aSMDSId);
616 aDataSet->GetCellData()->SetScalars(anArray);
617 myCellCenters->SetInput(aDataSet);
618 myCellsLabels->SetVisibility(GetVisibility());
620 myCellsLabels->SetVisibility(false);
622 myTimeStamp->Modified();
626 void SMESH_ActorDef::SetControlMode(eControl theMode){
627 myControlMode = eNone;
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;
665 case eMultiConnection2D:
666 aFunctor.reset(new SMESH::Controls::MultiConnection2D());
667 myControlActor = my2DActor;
671 SMESH::Controls::Area* aControl = new SMESH::Controls::Area();
672 aControl->SetPrecision( myControlsPrecision );
673 aFunctor.reset( aControl );
674 myControlActor = my2DActor;
679 SMESH::Controls::Taper* aControl = new SMESH::Controls::Taper();
680 aControl->SetPrecision( myControlsPrecision );
681 aFunctor.reset( aControl );
682 myControlActor = my2DActor;
687 SMESH::Controls::AspectRatio* aControl = new SMESH::Controls::AspectRatio();
688 aControl->SetPrecision( myControlsPrecision );
689 aFunctor.reset( aControl );
690 myControlActor = my2DActor;
695 SMESH::Controls::AspectRatio3D* aControl = new SMESH::Controls::AspectRatio3D();
696 aControl->SetPrecision( myControlsPrecision );
697 aFunctor.reset( aControl );
698 myControlActor = my3DActor;
703 SMESH::Controls::MinimumAngle* aControl = new SMESH::Controls::MinimumAngle();
704 aControl->SetPrecision( myControlsPrecision );
705 aFunctor.reset( aControl );
706 myControlActor = my2DActor;
711 SMESH::Controls::Warping* aControl = new SMESH::Controls::Warping();
712 aControl->SetPrecision( myControlsPrecision );
713 aFunctor.reset( aControl );
714 myControlActor = my2DActor;
719 SMESH::Controls::Skew* aControl = new SMESH::Controls::Skew();
720 aControl->SetPrecision( myControlsPrecision );
721 aFunctor.reset( aControl );
722 myControlActor = my2DActor;
729 vtkUnstructuredGrid* aGrid = myControlActor->GetUnstructuredGrid();
730 vtkIdType aNbCells = aGrid->GetNumberOfCells();
732 myControlMode = theMode;
733 switch(myControlMode){
736 my1DExtActor->SetExtControlMode(aFunctor,myControlActor);
739 case eMultiConnection2D:
740 my1DExtActor->SetExtControlMode(aFunctor,myControlActor,myScalarBarActor,myLookupTable);
743 myControlActor->SetControlMode(aFunctor,myScalarBarActor,myLookupTable);
747 if(QAD_CONFIG->getSetting("SMESH:DispayEntity") == "true"){
748 if(myControlActor == my1DActor)
749 myEntityMode = eEdges;
750 else if(myControlActor == my2DActor)
751 myEntityMode = eFaces;
752 else if(myControlActor == my3DActor)
753 myEntityMode = eVolumes;
756 }else if(QAD_CONFIG->getSetting("SMESH:DispayEntity") == "true"){
757 myEntityMode = eAllEntity;
760 SetRepresentation(GetRepresentation());
762 myTimeStamp->Modified();
767 void SMESH_ActorDef::AddToRender(vtkRenderer* theRenderer){
768 SALOME_Actor::AddToRender(theRenderer);
770 theRenderer->AddActor(myNodeActor);
771 theRenderer->AddActor(myBaseActor);
773 theRenderer->AddActor(my3DActor);
774 theRenderer->AddActor(my2DActor);
776 theRenderer->AddActor(my1DActor);
777 theRenderer->AddActor(my1DExtActor);
779 theRenderer->AddActor(myHighlitableActor);
780 theRenderer->AddActor(myNodeHighlitableActor);
782 theRenderer->AddActor2D(myScalarBarActor);
784 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
785 myClsSelectVisiblePoints->SetRenderer(theRenderer);
787 theRenderer->AddActor2D(myPointLabels);
788 theRenderer->AddActor2D(myCellsLabels);
791 void SMESH_ActorDef::RemoveFromRender(vtkRenderer* theRenderer){
792 SALOME_Actor::RemoveFromRender(theRenderer);
794 theRenderer->RemoveActor(myNodeActor);
795 theRenderer->RemoveActor(myBaseActor);
797 theRenderer->RemoveActor(myHighlitableActor);
798 theRenderer->RemoveActor(myNodeHighlitableActor);
800 theRenderer->RemoveActor(my1DActor);
801 theRenderer->RemoveActor(my1DExtActor);
803 theRenderer->RemoveActor(my2DActor);
804 theRenderer->RemoveActor(my3DActor);
806 theRenderer->RemoveActor(myScalarBarActor);
807 theRenderer->RemoveActor(myPointLabels);
808 theRenderer->RemoveActor(myCellsLabels);
812 bool SMESH_ActorDef::Init(TVisualObjPtr theVisualObj,
813 const char* theEntry,
817 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry,"SMESH",theName);
821 myVisualObj = theVisualObj;
822 myNodeActor->myVisualObj = myVisualObj;
823 myBaseActor->myVisualObj = myVisualObj;
825 myHighlitableActor->myVisualObj = myVisualObj;
826 myNodeHighlitableActor->myVisualObj = myVisualObj;
828 my1DActor->myVisualObj = myVisualObj;
829 my1DExtActor->myVisualObj = myVisualObj;
831 my2DActor->myVisualObj = myVisualObj;
832 my3DActor->myVisualObj = myVisualObj;
834 myVisualObj->Update(theIsClear);
836 myNodeActor->Init(myVisualObj,myImplicitBoolean);
837 myBaseActor->Init(myVisualObj,myImplicitBoolean);
839 myHighlitableActor->Init(myVisualObj,myImplicitBoolean);
840 myNodeHighlitableActor->Init(myVisualObj,myImplicitBoolean);
842 my1DActor->Init(myVisualObj,myImplicitBoolean);
843 my1DExtActor->Init(myVisualObj,myImplicitBoolean);
845 my2DActor->Init(myVisualObj,myImplicitBoolean);
846 my3DActor->Init(myVisualObj,myImplicitBoolean);
848 my1DActor->GetMapper()->SetLookupTable(myLookupTable);
849 my1DExtActor->GetMapper()->SetLookupTable(myLookupTable);
851 my2DActor->GetMapper()->SetLookupTable(myLookupTable);
852 my3DActor->GetMapper()->SetLookupTable(myLookupTable);
854 float aFactor, aUnits;
855 my2DActor->GetPolygonOffsetParameters(aFactor,aUnits);
856 my2DActor->SetPolygonOffsetParameters(aFactor,aUnits*0.75);
858 //SetIsShrunkable(theGrid->GetNumberOfCells() > 10);
859 SetIsShrunkable(true);
861 QString aMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
862 SetRepresentation(-1);
863 if(aMode.compare("Wireframe") == 0){
864 SetRepresentation(eEdge);
865 }else if(aMode.compare("Shading") == 0){
866 SetRepresentation(eSurface);
867 }else if(aMode.compare("Nodes") == 0){
868 SetRepresentation(ePoint);
871 aMode = QAD_CONFIG->getSetting("SMESH:Shrink");
876 myTimeStamp->Modified();
882 float* SMESH_ActorDef::GetBounds(){
883 return myNodeActor->GetBounds();
887 vtkDataSet* SMESH_ActorDef::GetInput(){
888 return GetUnstructuredGrid();
892 void SMESH_ActorDef::SetTransform(SALOME_Transform* theTransform){
893 myNodeActor->SetTransform(theTransform);
894 myBaseActor->SetTransform(theTransform);
896 myHighlitableActor->SetTransform(theTransform);
897 myNodeHighlitableActor->SetTransform(theTransform);
899 my1DActor->SetTransform(theTransform);
900 my1DExtActor->SetTransform(theTransform);
902 my2DActor->SetTransform(theTransform);
903 my3DActor->SetTransform(theTransform);
909 void SMESH_ActorDef::SetMapper(vtkMapper* theMapper){
910 vtkLODActor::SetMapper(theMapper);
914 void SMESH_ActorDef::ShallowCopy(vtkProp *prop){
915 SALOME_Actor::ShallowCopy(prop);
919 vtkMapper* SMESH_ActorDef::GetMapper(){
920 return myPickableActor->GetMapper();
924 vtkUnstructuredGrid* SMESH_ActorDef::GetUnstructuredGrid(){
925 return myVisualObj->GetUnstructuredGrid();
929 bool SMESH_ActorDef::IsInfinitive(){
930 vtkDataSet *aDataSet = myPickableActor->GetUnstructuredGrid();
932 myIsInfinite = aDataSet->GetNumberOfCells() == 0 ||
933 aDataSet->GetNumberOfCells() == 1 &&
934 aDataSet->GetCell(0)->GetCellType() == VTK_VERTEX;
935 return SALOME_Actor::IsInfinitive();
939 void SMESH_ActorDef::SetIsShrunkable(bool theShrunkable){
940 myIsShrinkable = theShrunkable;
944 float SMESH_ActorDef::GetShrinkFactor(){
945 return myBaseActor->GetShrinkFactor();
948 void SMESH_ActorDef::SetShrinkFactor(float theValue){
949 myBaseActor->SetShrinkFactor(theValue);
951 my1DActor->SetShrinkFactor(theValue);
952 my1DExtActor->SetShrinkFactor(theValue);
954 my2DActor->SetShrinkFactor(theValue);
955 my3DActor->SetShrinkFactor(theValue);
960 void SMESH_ActorDef::SetShrink(){
961 if(!myIsShrinkable) return;
963 myBaseActor->SetShrink();
965 my1DActor->SetShrink();
966 my1DExtActor->SetShrink();
968 my2DActor->SetShrink();
969 my3DActor->SetShrink();
975 void SMESH_ActorDef::UnShrink(){
976 if(!myIsShrunk) return;
978 myBaseActor->UnShrink();
980 my1DActor->UnShrink();
981 my1DExtActor->UnShrink();
983 my2DActor->UnShrink();
984 my3DActor->UnShrink();
991 int SMESH_ActorDef::GetNodeObjId(int theVtkID){
992 return myPickableActor->GetNodeObjId(theVtkID);
995 float* SMESH_ActorDef::GetNodeCoord(int theObjID){
996 return myPickableActor->GetNodeCoord(theObjID);
1000 int SMESH_ActorDef::GetElemObjId(int theVtkID){
1001 return myPickableActor->GetElemObjId(theVtkID);
1004 vtkCell* SMESH_ActorDef::GetElemCell(int theObjID){
1005 return myPickableActor->GetElemCell(theObjID);
1009 void SMESH_ActorDef::SetVisibility(int theMode){
1010 SetVisibility(theMode,true);
1014 void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation){
1015 SALOME_Actor::SetVisibility(theMode);
1017 myNodeActor->VisibilityOff();
1018 myBaseActor->VisibilityOff();
1020 my1DActor->VisibilityOff();
1021 my1DExtActor->VisibilityOff();
1023 my2DActor->VisibilityOff();
1024 my3DActor->VisibilityOff();
1026 myScalarBarActor->VisibilityOff();
1027 myPointLabels->VisibilityOff();
1028 myCellsLabels->VisibilityOff();
1030 if(GetVisibility()){
1031 if(theIsUpdateRepersentation)
1032 SetRepresentation(GetRepresentation());
1034 if(myControlMode != eNone){
1035 switch(myControlMode){
1038 my1DExtActor->VisibilityOn();
1041 case eMultiConnection2D:
1042 my1DExtActor->VisibilityOn();
1044 if(myControlActor->GetUnstructuredGrid()->GetNumberOfCells())
1045 myScalarBarActor->VisibilityOn();
1049 if(myRepresentation != ePoint)
1050 myPickableActor->VisibilityOn();
1052 myNodeActor->VisibilityOn();
1055 if(myEntityMode & eEdges){
1056 my1DActor->VisibilityOn();
1059 if(myEntityMode & eFaces){
1060 my2DActor->VisibilityOn();
1063 if(myEntityMode & eVolumes){
1064 my3DActor->VisibilityOn();
1067 if(myIsPointsLabeled){
1068 myPointLabels->VisibilityOn();
1069 myNodeActor->VisibilityOn();
1072 if(myIsCellsLabeled)
1073 myCellsLabels->VisibilityOn();
1080 void SMESH_ActorDef::SetEntityMode(unsigned int theMode){
1081 if(!myVisualObj->GetNbEntities(SMDSAbs_Edge))
1084 if(!myVisualObj->GetNbEntities(SMDSAbs_Face))
1087 if(!myVisualObj->GetNbEntities(SMDSAbs_Volume))
1088 theMode &= ~eVolumes;
1091 if(myVisualObj->GetNbEntities(SMDSAbs_Edge))
1094 if(myVisualObj->GetNbEntities(SMDSAbs_Face))
1097 if(myVisualObj->GetNbEntities(SMDSAbs_Volume))
1098 theMode |= eVolumes;
1101 myEntityMode = theMode;
1102 SALOME_ExtractUnstructuredGrid* aFilter = NULL;
1103 aFilter = myBaseActor->GetExtractUnstructuredGrid();
1104 aFilter->ClearRegisteredCellsWithType();
1105 aFilter->SetModeOfChanging(SALOME_ExtractUnstructuredGrid::eAdding);
1107 if(myEntityMode & eEdges){
1108 if (MYDEBUG) MESSAGE("EDGES");
1109 aFilter->RegisterCellsWithType(VTK_LINE);
1112 if(myEntityMode & eFaces){
1113 if (MYDEBUG) MESSAGE("FACES");
1114 aFilter->RegisterCellsWithType(VTK_TRIANGLE);
1115 aFilter->RegisterCellsWithType(VTK_POLYGON);
1116 aFilter->RegisterCellsWithType(VTK_QUAD);
1119 if(myEntityMode & eVolumes){
1120 if (MYDEBUG) MESSAGE("VOLUMES");
1121 aFilter->RegisterCellsWithType(VTK_TETRA);
1122 aFilter->RegisterCellsWithType(VTK_VOXEL);
1123 aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1124 aFilter->RegisterCellsWithType(VTK_WEDGE);
1125 aFilter->RegisterCellsWithType(VTK_PYRAMID);
1126 aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1129 if (MYDEBUG) MESSAGE(aFilter->GetOutput()->GetNumberOfCells());
1130 SetVisibility(GetVisibility(),false);
1133 void SMESH_ActorDef::SetRepresentation(int theMode){
1134 int aNbEdges = myVisualObj->GetNbEntities(SMDSAbs_Edge);
1135 int aNbFaces = myVisualObj->GetNbEntities(SMDSAbs_Face);
1136 int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume);
1138 myRepresentation = eSurface;
1139 if(!aNbFaces && !aNbVolumes && aNbEdges){
1140 myRepresentation = eEdge;
1141 }else if(!aNbFaces && !aNbVolumes && !aNbEdges){
1142 myRepresentation = ePoint;
1147 if(!aNbFaces && !aNbVolumes && !aNbEdges) return;
1150 if(!aNbFaces && !aNbVolumes) return;
1153 myRepresentation = theMode;
1156 if(!GetUnstructuredGrid()->GetNumberOfCells())
1157 myRepresentation = ePoint;
1160 if(myRepresentation == ePoint){
1168 myPickableActor = myBaseActor;
1169 myNodeActor->SetVisibility(false);
1170 vtkProperty *aProp = NULL, *aBackProp = NULL;
1171 SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1);
1172 switch(myRepresentation){
1174 myPickableActor = myNodeActor;
1175 myNodeActor->SetVisibility(true);
1177 aProp = aBackProp = myNodeProp;
1178 aReperesent = SMESH_DeviceActor::ePoint;
1181 aProp = aBackProp = myEdgeProp;
1182 aReperesent = SMESH_DeviceActor::eInsideframe;
1185 aProp = mySurfaceProp;
1186 aBackProp = myBackSurfaceProp;
1187 aReperesent = SMESH_DeviceActor::eSurface;
1191 my2DActor->SetProperty(aProp);
1192 my2DActor->SetBackfaceProperty(aBackProp);
1193 my2DActor->SetRepresentation(aReperesent);
1195 my3DActor->SetProperty(aProp);
1196 my3DActor->SetBackfaceProperty(aBackProp);
1197 my3DActor->SetRepresentation(aReperesent);
1199 my1DExtActor->SetVisibility(false);
1201 switch(myControlMode){
1203 case eMultiConnection:
1204 aProp = aBackProp = my1DProp;
1205 if(myRepresentation != ePoint)
1206 aReperesent = SMESH_DeviceActor::eInsideframe;
1210 my1DActor->SetProperty(aProp);
1211 my1DActor->SetBackfaceProperty(aBackProp);
1212 my1DActor->SetRepresentation(aReperesent);
1214 my1DExtActor->SetRepresentation(aReperesent);
1216 if(myIsPointsVisible)
1217 myPickableActor = myNodeActor;
1218 if(GetPointRepresentation())
1219 myNodeActor->SetVisibility(true);
1221 SetMapper(myPickableActor->GetMapper());
1223 SetVisibility(GetVisibility(),false);
1229 void SMESH_ActorDef::SetPointRepresentation(bool theIsPointsVisible){
1230 myIsPointsVisible = theIsPointsVisible;
1231 SetRepresentation(GetRepresentation());
1234 bool SMESH_ActorDef::GetPointRepresentation(){
1235 return myIsPointsVisible || myIsPointsLabeled;
1239 void SMESH_ActorDef::UpdateHighlight(){
1240 myHighlitableActor->SetVisibility(false);
1241 myHighlitableActor->SetHighlited(false);
1243 myNodeHighlitableActor->SetVisibility(false);
1244 myNodeHighlitableActor->SetHighlited(false);
1246 if(myIsHighlighted){
1247 myHighlitableActor->SetProperty(myHighlightProp);
1248 }else if(myIsPreselected){
1249 myHighlitableActor->SetProperty(myPreselectProp);
1252 bool isVisible = GetVisibility();
1254 if(myIsHighlighted || myIsPreselected){
1255 if(GetUnstructuredGrid()->GetNumberOfCells()){
1256 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
1257 myHighlitableActor->SetVisibility(isVisible);
1258 myHighlitableActor->SetHighlited(isVisible);
1260 if(myRepresentation == ePoint || GetPointRepresentation()){
1261 myNodeHighlitableActor->SetProperty(myHighlitableActor->GetProperty());
1262 myNodeHighlitableActor->SetVisibility(isVisible);
1263 myNodeHighlitableActor->SetHighlited(isVisible);
1269 void SMESH_ActorDef::highlight(bool theHighlight){
1270 myIsHighlighted = theHighlight;
1275 void SMESH_ActorDef::SetPreSelected(bool thePreselect){
1276 myIsPreselected = thePreselect;
1282 int SMESH_ActorDef::RenderOpaqueGeometry(vtkViewport *vp)
1284 if (myPickableActor->GetIsOpaque())
1286 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1294 int SMESH_ActorDef::RenderTranslucentGeometry(vtkViewport *vp)
1296 if (!myPickableActor->GetIsOpaque())
1298 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1306 void SMESH_ActorDef::Render(vtkRenderer *ren){
1307 unsigned long aTime = myTimeStamp->GetMTime();
1308 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1309 unsigned long aClippingTime = myImplicitBoolean->GetMTime();
1310 if(anObjTime > aTime || aClippingTime > aTime)
1315 void SMESH_ActorDef::Update(){
1316 if(MYDEBUG) MESSAGE("SMESH_ActorDef::Update");
1318 if(GetControlMode() != eNone) {
1319 unsigned long aTime = myTimeStamp->GetMTime();
1320 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1321 if (anObjTime > aTime)
1322 SetControlMode(GetControlMode());
1324 if(myIsPointsLabeled){
1325 SetPointsLabeled(myIsPointsLabeled);
1327 if(myIsCellsLabeled){
1328 SetCellsLabeled(myIsCellsLabeled);
1330 SetEntityMode(GetEntityMode());
1331 SetVisibility(GetVisibility());
1333 myTimeStamp->Modified();
1338 void SMESH_ActorDef::ReleaseGraphicsResources(vtkWindow *renWin){
1339 SALOME_Actor::ReleaseGraphicsResources(renWin);
1341 myPickableActor->ReleaseGraphicsResources(renWin);
1345 static void GetColor(vtkProperty *theProperty, float& r,float& g,float& b){
1346 float* aColor = theProperty->GetColor();
1353 void SMESH_ActorDef::SetOpacity(float theValue){
1354 mySurfaceProp->SetOpacity(theValue);
1355 myBackSurfaceProp->SetOpacity(theValue);
1356 myEdgeProp->SetOpacity(theValue);
1357 myNodeProp->SetOpacity(theValue);
1359 my1DProp->SetOpacity(theValue);
1363 float SMESH_ActorDef::GetOpacity(){
1364 return mySurfaceProp->GetOpacity();
1368 void SMESH_ActorDef::SetSufaceColor(float r,float g,float b){
1369 mySurfaceProp->SetColor(r,g,b);
1373 void SMESH_ActorDef::GetSufaceColor(float& r,float& g,float& b){
1374 ::GetColor(mySurfaceProp,r,g,b);
1377 void SMESH_ActorDef::SetBackSufaceColor(float r,float g,float b){
1378 myBackSurfaceProp->SetColor(r,g,b);
1382 void SMESH_ActorDef::GetBackSufaceColor(float& r,float& g,float& b){
1383 ::GetColor(myBackSurfaceProp,r,g,b);
1386 void SMESH_ActorDef::SetEdgeColor(float r,float g,float b){
1387 myEdgeProp->SetColor(r,g,b);
1388 my1DProp->SetColor(r,g,b);
1389 my1DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1393 void SMESH_ActorDef::GetEdgeColor(float& r,float& g,float& b){
1394 ::GetColor(myEdgeProp,r,g,b);
1397 void SMESH_ActorDef::SetNodeColor(float r,float g,float b){
1398 myNodeProp->SetColor(r,g,b);
1402 void SMESH_ActorDef::GetNodeColor(float& r,float& g,float& b){
1403 ::GetColor(myNodeProp,r,g,b);
1406 void SMESH_ActorDef::SetHighlightColor(float r,float g,float b){
1407 myHighlightProp->SetColor(r,g,b);
1411 void SMESH_ActorDef::GetHighlightColor(float& r,float& g,float& b){
1412 ::GetColor(myHighlightProp,r,g,b);
1415 void SMESH_ActorDef::SetPreHighlightColor(float r,float g,float b){
1416 myPreselectProp->SetColor(r,g,b);
1420 void SMESH_ActorDef::GetPreHighlightColor(float& r,float& g,float& b){
1421 ::GetColor(myPreselectProp,r,g,b);
1425 float SMESH_ActorDef::GetLineWidth(){
1426 return myEdgeProp->GetLineWidth();
1430 void SMESH_ActorDef::SetLineWidth(float theVal){
1431 myEdgeProp->SetLineWidth(theVal);
1433 my1DProp->SetLineWidth(theVal + aLineWidthInc);
1434 my1DExtProp->SetLineWidth(theVal + aLineWidthInc);
1440 void SMESH_ActorDef::SetNodeSize(float theVal){
1441 myNodeProp->SetPointSize(theVal);
1442 myHighlightProp->SetPointSize(theVal);
1443 myPreselectProp->SetPointSize(theVal);
1445 my1DProp->SetPointSize(theVal + aPointSizeInc);
1446 my1DExtProp->SetPointSize(theVal + aPointSizeInc);
1451 float SMESH_ActorDef::GetNodeSize(){
1452 return myNodeProp->GetPointSize();
1455 int SMESH_ActorDef::GetObjDimension( const int theObjId )
1457 return myVisualObj->GetElemDimension( theObjId );
1461 vtkImplicitBoolean* SMESH_ActorDef::GetPlaneContainer(){
1462 return myImplicitBoolean;
1466 static void ComputeBoundsParam(vtkDataSet* theDataSet,
1467 float theDirection[3], float theMinPnt[3],
1468 float& theMaxBoundPrj, float& theMinBoundPrj)
1471 theDataSet->GetBounds(aBounds);
1473 //Enlarge bounds in order to avoid conflicts of precision
1474 for(int i = 0; i < 6; i += 2){
1475 static double EPS = 1.0E-3;
1476 float aDelta = (aBounds[i+1] - aBounds[i])*EPS;
1477 aBounds[i] -= aDelta;
1478 aBounds[i+1] += aDelta;
1481 float aBoundPoints[8][3] = { {aBounds[0],aBounds[2],aBounds[4]},
1482 {aBounds[1],aBounds[2],aBounds[4]},
1483 {aBounds[0],aBounds[3],aBounds[4]},
1484 {aBounds[1],aBounds[3],aBounds[4]},
1485 {aBounds[0],aBounds[2],aBounds[5]},
1486 {aBounds[1],aBounds[2],aBounds[5]},
1487 {aBounds[0],aBounds[3],aBounds[5]},
1488 {aBounds[1],aBounds[3],aBounds[5]}};
1490 int aMaxId = 0, aMinId = aMaxId;
1491 theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
1492 theMinBoundPrj = theMaxBoundPrj;
1493 for(int i = 1; i < 8; i++){
1494 float aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
1495 if(theMaxBoundPrj < aTmp){
1496 theMaxBoundPrj = aTmp;
1499 if(theMinBoundPrj > aTmp){
1500 theMinBoundPrj = aTmp;
1504 float *aMinPnt = aBoundPoints[aMaxId];
1505 theMinPnt[0] = aMinPnt[0];
1506 theMinPnt[1] = aMinPnt[1];
1507 theMinPnt[2] = aMinPnt[2];
1511 static void DistanceToPosition(vtkDataSet* theDataSet,
1512 float theDirection[3], float theDist, float thePos[3])
1514 float aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1515 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1516 float aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
1517 thePos[0] = aMinPnt[0]-theDirection[0]*aLength;
1518 thePos[1] = aMinPnt[1]-theDirection[1]*aLength;
1519 thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
1523 static void PositionToDistance(vtkDataSet* theDataSet,
1524 float theDirection[3], float thePos[3], float& theDist)
1526 float aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1527 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1528 float aPrj = vtkMath::Dot(theDirection,thePos);
1529 theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
1533 void SMESH_ActorDef::SetPlaneParam(float theDir[3], float theDist, vtkPlane* thePlane)
1535 thePlane->SetNormal(theDir);
1537 ::DistanceToPosition(GetUnstructuredGrid(),theDir,theDist,anOrigin);
1538 thePlane->SetOrigin(anOrigin);
1542 void SMESH_ActorDef::GetPlaneParam(float theDir[3], float& theDist, vtkPlane* thePlane)
1544 thePlane->GetNormal(theDir);
1547 thePlane->GetOrigin(anOrigin);
1548 ::PositionToDistance(GetUnstructuredGrid(),theDir,anOrigin,theDist);