1 // SMESH OBJECT : interactive object for SMESH visualization
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SMESH_Actor.cxx
25 // Author : Nicolas REJNERI
30 #include "SMESH_ActorDef.h"
31 #include "SMESH_ActorUtils.h"
32 #include "SMESH_DeviceActor.h"
33 #include "SMESH_ControlsDef.hxx"
34 #include "VTKViewer_ExtractUnstructuredGrid.h"
36 #include "SUIT_Session.h"
37 #include "SUIT_ResourceMgr.h"
39 #include <qstringlist.h>
41 #include <vtkProperty.h>
42 #include <vtkTimeStamp.h>
43 #include <vtkObjectFactory.h>
44 #include <vtkShrinkPolyData.h>
45 #include <vtkMergeFilter.h>
47 #include <vtkMatrix4x4.h>
48 #include <vtkUnstructuredGrid.h>
49 #include <vtkPointData.h>
50 #include <vtkCellData.h>
52 #include <vtkMapper.h>
53 #include <vtkRenderer.h>
56 #include <vtkIdList.h>
57 #include <vtkIntArray.h>
59 #include <vtkActor2D.h>
60 #include <vtkProperty2D.h>
61 #include <vtkPolyData.h>
62 #include <vtkMaskPoints.h>
63 #include <vtkCellCenters.h>
64 #include <vtkTextProperty.h>
65 #include <vtkLabeledDataMapper.h>
66 #include <vtkSelectVisiblePoints.h>
68 #include <vtkScalarBarActor.h>
69 #include <vtkLookupTable.h>
73 #include <vtkImplicitBoolean.h>
74 #include <vtkImplicitFunctionCollection.h>
76 #include "utilities.h"
79 static int MYDEBUG = 1;
81 static int MYDEBUG = 0;
84 static int aLineWidthInc = 2;
85 static int aPointSizeInc = 2;
88 SMESH_ActorDef* SMESH_ActorDef::New(){
89 return new SMESH_ActorDef();
93 SMESH_Actor* SMESH_Actor::New(TVisualObjPtr theVisualObj,
98 SMESH_ActorDef* anActor = SMESH_ActorDef::New();
99 if(!anActor->Init(theVisualObj,theEntry,theName,theIsClear)){
104 anActor->UpdateScalarBar();
109 SMESH_ActorDef::SMESH_ActorDef()
111 if(MYDEBUG) MESSAGE("SMESH_ActorDef - "<<this);
113 myTimeStamp = vtkTimeStamp::New();
115 myIsPointsVisible = false;
117 myIsShrinkable = false;
120 myControlsPrecision = -1;
121 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
122 if ( mgr && mgr->booleanValue( "SMESH", "use_precision", false ) )
123 myControlsPrecision = (long)SMESH::GetFloat( "SMESH", "controls_precision", -1 );
125 vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
126 vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
128 vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
129 VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
131 //Definition 2D and 3D divices of the actor
132 //-----------------------------------------
133 vtkFloatingPointType anRGB[3] = {1,1,1};
134 mySurfaceProp = vtkProperty::New();
135 SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
136 mySurfaceProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
138 myBackSurfaceProp = vtkProperty::New();
139 SMESH::GetColor( "SMESH", "backface_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 0, 255 ) );
140 myBackSurfaceProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
142 my2DActor = SMESH_DeviceActor::New();
143 my2DActor->SetUserMatrix(aMatrix);
144 my2DActor->PickableOff();
145 my2DActor->SetProperty(mySurfaceProp);
146 my2DActor->SetBackfaceProperty(myBackSurfaceProp);
147 my2DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
148 aFilter = my2DActor->GetExtractUnstructuredGrid();
149 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
150 aFilter->RegisterCellsWithType(VTK_TRIANGLE);
151 aFilter->RegisterCellsWithType(VTK_POLYGON);
152 aFilter->RegisterCellsWithType(VTK_QUAD);
153 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
154 aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
156 my3DActor = SMESH_DeviceActor::New();
157 my3DActor->SetUserMatrix(aMatrix);
158 my3DActor->PickableOff();
159 my3DActor->SetProperty(mySurfaceProp);
160 my3DActor->SetBackfaceProperty(myBackSurfaceProp);
161 my3DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
162 aFilter = my3DActor->GetExtractUnstructuredGrid();
163 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
164 aFilter->RegisterCellsWithType(VTK_TETRA);
165 aFilter->RegisterCellsWithType(VTK_VOXEL);
166 aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
167 aFilter->RegisterCellsWithType(VTK_WEDGE);
168 aFilter->RegisterCellsWithType(VTK_PYRAMID);
169 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
170 aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
171 aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
173 //Definition 1D divice of the actor
174 //---------------------------------
175 myEdgeProp = vtkProperty::New();
176 myEdgeProp->SetAmbient(1.0);
177 myEdgeProp->SetDiffuse(0.0);
178 myEdgeProp->SetSpecular(0.0);
179 SMESH::GetColor( "SMESH", "outline_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
180 myEdgeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
181 myEdgeProp->SetLineWidth(aLineWidth);
183 my1DActor = SMESH_DeviceActor::New();
184 my1DActor->SetUserMatrix(aMatrix);
185 my1DActor->PickableOff();
186 my1DActor->SetHighlited(true);
187 my1DActor->SetProperty(myEdgeProp);
188 my1DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
189 aFilter = my1DActor->GetExtractUnstructuredGrid();
190 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
191 aFilter->RegisterCellsWithType(VTK_LINE);
192 aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
194 my1DProp = vtkProperty::New();
195 my1DProp->DeepCopy(myEdgeProp);
196 my1DProp->SetLineWidth(aLineWidth + aLineWidthInc);
197 my1DProp->SetPointSize(aPointSize);
199 my1DExtProp = vtkProperty::New();
200 my1DExtProp->DeepCopy(myEdgeProp);
201 anRGB[0] = 1 - anRGB[0];
202 anRGB[1] = 1 - anRGB[1];
203 anRGB[2] = 1 - anRGB[2];
204 my1DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
205 my1DExtProp->SetLineWidth(aLineWidth + aLineWidthInc);
206 my1DExtProp->SetPointSize(aPointSize + aPointSizeInc);
208 my1DExtActor = SMESH_DeviceActor::New();
209 my1DExtActor->SetUserMatrix(aMatrix);
210 my1DExtActor->PickableOff();
211 my1DExtActor->SetHighlited(true);
212 my1DExtActor->SetVisibility(false);
213 my1DExtActor->SetProperty(my1DExtProp);
214 my1DExtActor->SetRepresentation(SMESH_DeviceActor::eInsideframe);
215 aFilter = my1DExtActor->GetExtractUnstructuredGrid();
216 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
217 aFilter->RegisterCellsWithType(VTK_LINE);
218 aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
221 //Definition 0D divice of the actor
222 //---------------------------------
223 myNodeProp = vtkProperty::New();
224 SMESH::GetColor( "SMESH", "node_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 0, 0 ) );
225 myNodeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
226 myNodeProp->SetPointSize(aPointSize);
228 myNodeActor = SMESH_DeviceActor::New();
229 myNodeActor->SetUserMatrix(aMatrix);
230 myNodeActor->SetStoreClippingMapping(true);
231 myNodeActor->PickableOff();
232 myNodeActor->SetVisibility(false);
233 myNodeActor->SetProperty(myNodeProp);
234 myNodeActor->SetRepresentation(SMESH_DeviceActor::ePoint);
235 aFilter = myNodeActor->GetExtractUnstructuredGrid();
236 aFilter->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
239 //Definition of Pickable and Highlitable engines
240 //----------------------------------------------
242 myBaseActor = SMESH_DeviceActor::New();
243 myBaseActor->SetUserMatrix(aMatrix);
244 myBaseActor->SetStoreGemetryMapping(true);
245 myBaseActor->GetProperty()->SetOpacity(0.0);
247 myPickableActor = myBaseActor;
249 myHighlightProp = vtkProperty::New();
250 myHighlightProp->SetAmbient(1.0);
251 myHighlightProp->SetDiffuse(0.0);
252 myHighlightProp->SetSpecular(0.0);
253 SMESH::GetColor( "SMESH", "selection_object_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
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 SMESH::GetColor( "SMESH", "highlight_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 255, 255 ) );
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->PickableOff();
270 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
275 myControlMode = eNone;
276 myControlActor = my2DActor;
278 //Definition of myScalarBarActor
279 //------------------------------
280 myLookupTable = vtkLookupTable::New();
281 //Fix for Bug PAL5195 - SMESH764:
282 //Controls - Aspect Ratio: incorrect colors of the best and worst values
283 myLookupTable->SetHueRange(0.667,0.0);
285 myScalarBarActor = vtkScalarBarActor::New();
286 myScalarBarActor->SetVisibility(false);
287 myScalarBarActor->SetLookupTable(myLookupTable);
290 //Incorrect "Min value" in Scalar Bar in Mesh:
291 myScalarBarActor->SetLabelFormat("%.4g");
293 mgr = SUIT_Session::session()->resourceMgr();
297 //Definition of points numbering pipeline
298 //---------------------------------------
299 myPointsNumDataSet = vtkUnstructuredGrid::New();
301 myPtsMaskPoints = vtkMaskPoints::New();
302 myPtsMaskPoints->SetInput(myPointsNumDataSet);
303 myPtsMaskPoints->SetOnRatio(1);
305 myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
306 myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
307 myPtsSelectVisiblePoints->SelectInvisibleOff();
308 myPtsSelectVisiblePoints->SetTolerance(0.1);
310 myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
311 myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
312 myPtsLabeledDataMapper->SetLabelFormat("%g");
313 myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
315 vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
316 aPtsTextProp->SetFontFamilyToTimes();
317 static int aPointsFontSize = 10;
318 aPtsTextProp->SetFontSize(aPointsFontSize);
319 aPtsTextProp->SetBold(1);
320 aPtsTextProp->SetItalic(0);
321 aPtsTextProp->SetShadow(0);
322 myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
323 aPtsTextProp->Delete();
325 myEntityMode = eAllEntity;
327 myIsPointsLabeled = false;
329 myPointLabels = vtkActor2D::New();
330 myPointLabels->SetMapper(myPtsLabeledDataMapper);
331 myPointLabels->GetProperty()->SetColor(1,1,1);
332 myPointLabels->SetVisibility(myIsPointsLabeled);
335 //Definition of cells numbering pipeline
336 //---------------------------------------
337 myCellsNumDataSet = vtkUnstructuredGrid::New();
339 myCellCenters = vtkCellCenters::New();
340 myCellCenters->SetInput(myCellsNumDataSet);
342 myClsMaskPoints = vtkMaskPoints::New();
343 myClsMaskPoints->SetInput(myCellCenters->GetOutput());
344 myClsMaskPoints->SetOnRatio(1);
346 myClsSelectVisiblePoints = vtkSelectVisiblePoints::New();
347 myClsSelectVisiblePoints->SetInput(myClsMaskPoints->GetOutput());
348 myClsSelectVisiblePoints->SelectInvisibleOff();
349 myClsSelectVisiblePoints->SetTolerance(0.1);
351 myClsLabeledDataMapper = vtkLabeledDataMapper::New();
352 myClsLabeledDataMapper->SetInput(myClsSelectVisiblePoints->GetOutput());
353 myClsLabeledDataMapper->SetLabelFormat("%g");
354 myClsLabeledDataMapper->SetLabelModeToLabelScalars();
356 vtkTextProperty* aClsTextProp = vtkTextProperty::New();
357 aClsTextProp->SetFontFamilyToTimes();
358 static int aCellsFontSize = 12;
359 aClsTextProp->SetFontSize(aCellsFontSize);
360 aClsTextProp->SetBold(1);
361 aClsTextProp->SetItalic(0);
362 aClsTextProp->SetShadow(0);
363 myClsLabeledDataMapper->SetLabelTextProperty(aClsTextProp);
364 aClsTextProp->Delete();
366 myIsCellsLabeled = false;
368 myCellsLabels = vtkActor2D::New();
369 myCellsLabels->SetMapper(myClsLabeledDataMapper);
370 myCellsLabels->GetProperty()->SetColor(0,1,0);
371 myCellsLabels->SetVisibility(myIsCellsLabeled);
374 myImplicitBoolean = vtkImplicitBoolean::New();
375 myImplicitBoolean->SetOperationTypeToIntersection();
379 SMESH_ActorDef::~SMESH_ActorDef()
381 if(MYDEBUG) MESSAGE("~SMESH_ActorDef - "<<this);
383 myScalarBarActor->Delete();
384 myLookupTable->Delete();
386 mySurfaceProp->Delete();
387 myBackSurfaceProp->Delete();
389 myEdgeProp->Delete();
390 myHighlightProp->Delete();
391 myPreselectProp->Delete();
393 myNodeProp->Delete();
398 my1DExtProp->Delete();
399 my1DExtActor->Delete();
404 myNodeActor->Delete();
405 myBaseActor->Delete();
407 myHighlitableActor->Delete();
409 //Deleting of pints numbering pipeline
410 //---------------------------------------
411 myPointsNumDataSet->Delete();
413 myPtsLabeledDataMapper->RemoveAllInputs();
414 myPtsLabeledDataMapper->Delete();
416 myPtsSelectVisiblePoints->UnRegisterAllOutputs();
417 myPtsSelectVisiblePoints->Delete();
419 myPtsMaskPoints->UnRegisterAllOutputs();
420 myPtsMaskPoints->Delete();
422 myPointLabels->Delete();
425 //Deleting of cells numbering pipeline
426 //---------------------------------------
427 myCellsNumDataSet->Delete();
429 myClsLabeledDataMapper->RemoveAllInputs();
430 myClsLabeledDataMapper->Delete();
432 myClsSelectVisiblePoints->UnRegisterAllOutputs();
433 myClsSelectVisiblePoints->Delete();
435 myClsMaskPoints->UnRegisterAllOutputs();
436 myClsMaskPoints->Delete();
438 myCellCenters->UnRegisterAllOutputs();
439 myCellCenters->Delete();
441 myCellsLabels->Delete();
443 myImplicitBoolean->Delete();
445 myTimeStamp->Delete();
449 void SMESH_ActorDef::SetPointsLabeled( bool theIsPointsLabeled )
451 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
452 myIsPointsLabeled = theIsPointsLabeled && aGrid->GetNumberOfPoints();
454 if ( myIsPointsLabeled )
456 myPointsNumDataSet->ShallowCopy(aGrid);
457 vtkDataSet *aDataSet = myPointsNumDataSet;
459 int aNbElem = aDataSet->GetNumberOfPoints();
461 vtkIntArray *anArray = vtkIntArray::New();
462 anArray->SetNumberOfValues( aNbElem );
464 for ( int anId = 0; anId < aNbElem; anId++ )
466 int aSMDSId = myVisualObj->GetNodeObjId( anId );
467 anArray->SetValue( anId, aSMDSId );
470 aDataSet->GetPointData()->SetScalars( anArray );
472 myPtsMaskPoints->SetInput( aDataSet );
473 myPointLabels->SetVisibility( GetVisibility() );
477 myPointLabels->SetVisibility( false );
479 SetRepresentation(GetRepresentation());
480 myTimeStamp->Modified();
484 void SMESH_ActorDef::SetCellsLabeled(bool theIsCellsLabeled)
486 vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
487 myIsCellsLabeled = theIsCellsLabeled && aGrid->GetNumberOfPoints();
488 if(myIsCellsLabeled){
489 myCellsNumDataSet->ShallowCopy(aGrid);
490 vtkDataSet *aDataSet = myCellsNumDataSet;
491 int aNbElem = aDataSet->GetNumberOfCells();
492 vtkIntArray *anArray = vtkIntArray::New();
493 anArray->SetNumberOfValues(aNbElem);
494 for(int anId = 0; anId < aNbElem; anId++){
495 int aSMDSId = myVisualObj->GetElemObjId(anId);
496 anArray->SetValue(anId,aSMDSId);
498 aDataSet->GetCellData()->SetScalars(anArray);
499 myCellCenters->SetInput(aDataSet);
500 myCellsLabels->SetVisibility(GetVisibility());
502 myCellsLabels->SetVisibility(false);
504 myTimeStamp->Modified();
510 SetControlMode(eControl theMode)
512 SetControlMode(theMode,true);
518 SetControlMode(eControl theMode,
519 bool theCheckEntityMode)
521 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
525 myControlMode = eNone;
526 theCheckEntityMode &= mgr->booleanValue( "SMESH", "display_entity", false );
528 my1DActor->GetMapper()->SetScalarVisibility(false);
529 my2DActor->GetMapper()->SetScalarVisibility(false);
530 my3DActor->GetMapper()->SetScalarVisibility(false);
531 myScalarBarActor->SetVisibility(false);
533 bool anIsScalarVisible = theMode > eNone;
535 if(anIsScalarVisible){
536 SMESH::Controls::FunctorPtr aFunctor;
540 SMESH::Controls::Length* aControl = new SMESH::Controls::Length();
541 aControl->SetPrecision( myControlsPrecision );
542 aFunctor.reset( aControl );
543 myControlActor = my1DActor;
548 aFunctor.reset(new SMESH::Controls::Length2D());
549 myControlActor = my2DActor;
553 aFunctor.reset(new SMESH::Controls::FreeBorders());
554 myControlActor = my1DActor;
557 aFunctor.reset(new SMESH::Controls::FreeEdges());
558 myControlActor = my2DActor;
560 case eMultiConnection:
561 aFunctor.reset(new SMESH::Controls::MultiConnection());
562 myControlActor = my1DActor;
564 case eMultiConnection2D:
565 aFunctor.reset(new SMESH::Controls::MultiConnection2D());
566 myControlActor = my2DActor;
570 SMESH::Controls::Area* aControl = new SMESH::Controls::Area();
571 aControl->SetPrecision( myControlsPrecision );
572 aFunctor.reset( aControl );
573 myControlActor = my2DActor;
578 SMESH::Controls::Taper* aControl = new SMESH::Controls::Taper();
579 aControl->SetPrecision( myControlsPrecision );
580 aFunctor.reset( aControl );
581 myControlActor = my2DActor;
586 SMESH::Controls::AspectRatio* aControl = new SMESH::Controls::AspectRatio();
587 aControl->SetPrecision( myControlsPrecision );
588 aFunctor.reset( aControl );
589 myControlActor = my2DActor;
594 SMESH::Controls::AspectRatio3D* aControl = new SMESH::Controls::AspectRatio3D();
595 aControl->SetPrecision( myControlsPrecision );
596 aFunctor.reset( aControl );
597 myControlActor = my3DActor;
602 SMESH::Controls::Volume* aControl = new SMESH::Controls::Volume();
603 aControl->SetPrecision( myControlsPrecision );
604 aFunctor.reset( aControl );
605 myControlActor = my3DActor;
610 SMESH::Controls::MinimumAngle* aControl = new SMESH::Controls::MinimumAngle();
611 aControl->SetPrecision( myControlsPrecision );
612 aFunctor.reset( aControl );
613 myControlActor = my2DActor;
618 SMESH::Controls::Warping* aControl = new SMESH::Controls::Warping();
619 aControl->SetPrecision( myControlsPrecision );
620 aFunctor.reset( aControl );
621 myControlActor = my2DActor;
626 SMESH::Controls::Skew* aControl = new SMESH::Controls::Skew();
627 aControl->SetPrecision( myControlsPrecision );
628 aFunctor.reset( aControl );
629 myControlActor = my2DActor;
636 vtkUnstructuredGrid* aGrid = myControlActor->GetUnstructuredGrid();
637 vtkIdType aNbCells = aGrid->GetNumberOfCells();
639 myControlMode = theMode;
640 switch(myControlMode){
643 my1DExtActor->SetExtControlMode(aFunctor);
646 case eMultiConnection2D:
647 my1DExtActor->SetExtControlMode(aFunctor,myScalarBarActor,myLookupTable);
650 myControlActor->SetControlMode(aFunctor,myScalarBarActor,myLookupTable);
654 if(theCheckEntityMode){
655 if(myControlActor == my1DActor)
656 SetEntityMode(eEdges);
657 else if(myControlActor == my2DActor){
658 switch(myControlMode){
661 case eMultiConnection2D:
662 //SetEntityMode(eEdges);
663 SetEntityMode(eFaces);
666 SetEntityMode(eFaces);
668 }else if(myControlActor == my3DActor)
669 SetEntityMode(eVolumes);
672 }else if(theCheckEntityMode){
673 myEntityMode = eAllEntity;
676 SetRepresentation(GetRepresentation());
678 myTimeStamp->Modified();
683 void SMESH_ActorDef::AddToRender(vtkRenderer* theRenderer){
684 SALOME_Actor::AddToRender(theRenderer);
686 theRenderer->AddActor(myNodeActor);
687 theRenderer->AddActor(myBaseActor);
689 theRenderer->AddActor(my3DActor);
690 theRenderer->AddActor(my2DActor);
692 theRenderer->AddActor(my1DActor);
693 theRenderer->AddActor(my1DExtActor);
695 theRenderer->AddActor(myHighlitableActor);
697 theRenderer->AddActor2D(myScalarBarActor);
699 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
700 myClsSelectVisiblePoints->SetRenderer(theRenderer);
702 theRenderer->AddActor2D(myPointLabels);
703 theRenderer->AddActor2D(myCellsLabels);
706 void SMESH_ActorDef::RemoveFromRender(vtkRenderer* theRenderer){
707 SALOME_Actor::RemoveFromRender(theRenderer);
709 theRenderer->RemoveActor(myNodeActor);
710 theRenderer->RemoveActor(myBaseActor);
712 theRenderer->RemoveActor(myHighlitableActor);
714 theRenderer->RemoveActor(my1DActor);
715 theRenderer->RemoveActor(my1DExtActor);
717 theRenderer->RemoveActor(my2DActor);
718 theRenderer->RemoveActor(my3DActor);
720 theRenderer->RemoveActor(myScalarBarActor);
721 theRenderer->RemoveActor(myPointLabels);
722 theRenderer->RemoveActor(myCellsLabels);
726 bool SMESH_ActorDef::Init(TVisualObjPtr theVisualObj,
727 const char* theEntry,
731 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry,"SMESH",theName);
735 myVisualObj = theVisualObj;
736 myVisualObj->Update(theIsClear);
738 myNodeActor->Init(myVisualObj,myImplicitBoolean);
739 myBaseActor->Init(myVisualObj,myImplicitBoolean);
741 myHighlitableActor->Init(myVisualObj,myImplicitBoolean);
743 my1DActor->Init(myVisualObj,myImplicitBoolean);
744 my1DExtActor->Init(myVisualObj,myImplicitBoolean);
746 my2DActor->Init(myVisualObj,myImplicitBoolean);
747 my3DActor->Init(myVisualObj,myImplicitBoolean);
749 my1DActor->GetMapper()->SetLookupTable(myLookupTable);
750 my1DExtActor->GetMapper()->SetLookupTable(myLookupTable);
752 my2DActor->GetMapper()->SetLookupTable(myLookupTable);
753 my3DActor->GetMapper()->SetLookupTable(myLookupTable);
755 vtkFloatingPointType aFactor, aUnits;
756 my2DActor->GetPolygonOffsetParameters(aFactor,aUnits);
757 my2DActor->SetPolygonOffsetParameters(aFactor,aUnits*0.75);
759 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
763 //SetIsShrunkable(theGrid->GetNumberOfCells() > 10);
764 SetIsShrunkable(true);
766 SetShrinkFactor( SMESH::GetFloat( "SMESH:shrink_coeff", 0.75 ) );
768 int aMode = mgr->integerValue( "SMESH", "display_mode" );
769 SetRepresentation(-1);
772 SetRepresentation(eEdge);
773 }else if(aMode == 1){
774 SetRepresentation(eSurface);
775 }else if(aMode == 2){
776 SetRepresentation(ePoint);
783 myTimeStamp->Modified();
789 vtkFloatingPointType* SMESH_ActorDef::GetBounds(){
790 return myNodeActor->GetBounds();
794 vtkDataSet* SMESH_ActorDef::GetInput(){
795 return GetUnstructuredGrid();
799 void SMESH_ActorDef::SetTransform(VTKViewer_Transform* theTransform){
800 Superclass::SetTransform(theTransform);
802 myNodeActor->SetTransform(theTransform);
803 myBaseActor->SetTransform(theTransform);
805 myHighlitableActor->SetTransform(theTransform);
807 my1DActor->SetTransform(theTransform);
808 my1DExtActor->SetTransform(theTransform);
810 my2DActor->SetTransform(theTransform);
811 my3DActor->SetTransform(theTransform);
817 void SMESH_ActorDef::SetMapper(vtkMapper* theMapper){
818 vtkLODActor::SetMapper(theMapper);
822 void SMESH_ActorDef::ShallowCopy(vtkProp *prop){
823 SALOME_Actor::ShallowCopy(prop);
827 vtkMapper* SMESH_ActorDef::GetMapper(){
828 return myPickableActor->GetMapper();
832 vtkUnstructuredGrid* SMESH_ActorDef::GetUnstructuredGrid(){
833 return myVisualObj->GetUnstructuredGrid();
837 bool SMESH_ActorDef::IsInfinitive(){
838 vtkDataSet *aDataSet = myPickableActor->GetUnstructuredGrid();
840 myIsInfinite = aDataSet->GetNumberOfCells() == 0 ||
841 aDataSet->GetNumberOfCells() == 1 &&
842 aDataSet->GetCell(0)->GetCellType() == VTK_VERTEX;
843 return SALOME_Actor::IsInfinitive();
847 void SMESH_ActorDef::SetIsShrunkable(bool theShrunkable){
848 if ( myIsShrinkable == theShrunkable )
850 myIsShrinkable = theShrunkable;
854 vtkFloatingPointType SMESH_ActorDef::GetShrinkFactor(){
855 return myBaseActor->GetShrinkFactor();
858 void SMESH_ActorDef::SetShrinkFactor(vtkFloatingPointType theValue){
859 myBaseActor->SetShrinkFactor(theValue);
861 my1DActor->SetShrinkFactor(theValue);
862 my1DExtActor->SetShrinkFactor(theValue);
864 my2DActor->SetShrinkFactor(theValue);
865 my3DActor->SetShrinkFactor(theValue);
870 void SMESH_ActorDef::SetShrink(){
871 if(!myIsShrinkable) return;
873 myBaseActor->SetShrink();
875 my1DActor->SetShrink();
876 my1DExtActor->SetShrink();
878 my2DActor->SetShrink();
879 my3DActor->SetShrink();
885 void SMESH_ActorDef::UnShrink(){
886 if(!myIsShrunk) return;
888 myBaseActor->UnShrink();
890 my1DActor->UnShrink();
891 my1DExtActor->UnShrink();
893 my2DActor->UnShrink();
894 my3DActor->UnShrink();
901 int SMESH_ActorDef::GetNodeObjId(int theVtkID){
902 return myPickableActor->GetNodeObjId(theVtkID);
905 vtkFloatingPointType* SMESH_ActorDef::GetNodeCoord(int theObjID){
906 return myPickableActor->GetNodeCoord(theObjID);
910 int SMESH_ActorDef::GetElemObjId(int theVtkID){
911 return myPickableActor->GetElemObjId(theVtkID);
914 vtkCell* SMESH_ActorDef::GetElemCell(int theObjID){
915 return myPickableActor->GetElemCell(theObjID);
919 void SMESH_ActorDef::SetVisibility(int theMode){
920 SetVisibility(theMode,true);
924 void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation){
925 SALOME_Actor::SetVisibility(theMode);
927 myNodeActor->VisibilityOff();
928 myBaseActor->VisibilityOff();
930 my1DActor->VisibilityOff();
931 my1DExtActor->VisibilityOff();
933 my2DActor->VisibilityOff();
934 my3DActor->VisibilityOff();
936 myScalarBarActor->VisibilityOff();
937 myPointLabels->VisibilityOff();
938 myCellsLabels->VisibilityOff();
941 if(theIsUpdateRepersentation)
942 SetRepresentation(GetRepresentation());
944 if(myControlMode != eNone){
945 switch(myControlMode){
948 my1DExtActor->VisibilityOn();
951 case eMultiConnection2D:
952 my1DExtActor->VisibilityOn();
954 if(myControlActor->GetUnstructuredGrid()->GetNumberOfCells())
955 myScalarBarActor->VisibilityOn();
959 if(myRepresentation != ePoint)
960 myPickableActor->VisibilityOn();
962 myNodeActor->VisibilityOn();
965 if(myEntityMode & eEdges){
966 my1DActor->VisibilityOn();
969 if(myEntityMode & eFaces){
970 my2DActor->VisibilityOn();
973 if(myEntityMode & eVolumes){
974 my3DActor->VisibilityOn();
977 if(myIsPointsLabeled){
978 myPointLabels->VisibilityOn();
979 myNodeActor->VisibilityOn();
983 myCellsLabels->VisibilityOn();
990 void SMESH_ActorDef::SetEntityMode(unsigned int theMode){
991 myEntityState = eAllEntity;
993 if(!myVisualObj->GetNbEntities(SMDSAbs_Edge)){
994 myEntityState &= ~eEdges;
998 if(!myVisualObj->GetNbEntities(SMDSAbs_Face)){
999 myEntityState &= ~eFaces;
1003 if(!myVisualObj->GetNbEntities(SMDSAbs_Volume)){
1004 myEntityState &= ~eVolumes;
1005 theMode &= ~eVolumes;
1009 if(myVisualObj->GetNbEntities(SMDSAbs_Edge))
1012 if(myVisualObj->GetNbEntities(SMDSAbs_Face))
1015 if(myVisualObj->GetNbEntities(SMDSAbs_Volume))
1016 theMode |= eVolumes;
1019 myBaseActor->myGeomFilter->SetInside(myEntityMode != myEntityState);
1021 myEntityMode = theMode;
1022 VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
1023 aFilter = myBaseActor->GetExtractUnstructuredGrid();
1024 aFilter->ClearRegisteredCellsWithType();
1025 aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
1027 if(myEntityMode & eEdges){
1028 if (MYDEBUG) MESSAGE("EDGES");
1029 aFilter->RegisterCellsWithType(VTK_LINE);
1030 aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
1033 if(myEntityMode & eFaces){
1034 if (MYDEBUG) MESSAGE("FACES");
1035 aFilter->RegisterCellsWithType(VTK_TRIANGLE);
1036 aFilter->RegisterCellsWithType(VTK_POLYGON);
1037 aFilter->RegisterCellsWithType(VTK_QUAD);
1038 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
1039 aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
1042 if(myEntityMode & eVolumes){
1043 if (MYDEBUG) MESSAGE("VOLUMES");
1044 aFilter->RegisterCellsWithType(VTK_TETRA);
1045 aFilter->RegisterCellsWithType(VTK_VOXEL);
1046 aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1047 aFilter->RegisterCellsWithType(VTK_WEDGE);
1048 aFilter->RegisterCellsWithType(VTK_PYRAMID);
1049 aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
1050 aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
1051 aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1054 if (MYDEBUG) MESSAGE(aFilter->GetOutput()->GetNumberOfCells());
1055 SetVisibility(GetVisibility(),false);
1058 void SMESH_ActorDef::SetRepresentation(int theMode){
1059 int aNbEdges = myVisualObj->GetNbEntities(SMDSAbs_Edge);
1060 int aNbFaces = myVisualObj->GetNbEntities(SMDSAbs_Face);
1061 int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume);
1063 myRepresentation = eSurface;
1064 if(!aNbFaces && !aNbVolumes && aNbEdges){
1065 myRepresentation = eEdge;
1066 }else if(!aNbFaces && !aNbVolumes && !aNbEdges){
1067 myRepresentation = ePoint;
1072 if(!aNbFaces && !aNbVolumes && !aNbEdges) return;
1075 if(!aNbFaces && !aNbVolumes) return;
1078 myRepresentation = theMode;
1081 if(!GetUnstructuredGrid()->GetNumberOfCells())
1082 myRepresentation = ePoint;
1085 if(myRepresentation == ePoint){
1093 myPickableActor = myBaseActor;
1094 myNodeActor->SetVisibility(false);
1095 vtkProperty *aProp = NULL, *aBackProp = NULL;
1096 SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1);
1097 switch(myRepresentation){
1099 myPickableActor = myNodeActor;
1100 myNodeActor->SetVisibility(true);
1102 aProp = aBackProp = myNodeProp;
1103 aReperesent = SMESH_DeviceActor::ePoint;
1106 aProp = aBackProp = myEdgeProp;
1107 aReperesent = SMESH_DeviceActor::eInsideframe;
1110 aProp = mySurfaceProp;
1111 aBackProp = myBackSurfaceProp;
1112 aReperesent = SMESH_DeviceActor::eSurface;
1116 my2DActor->SetProperty(aProp);
1117 my2DActor->SetBackfaceProperty(aBackProp);
1118 my2DActor->SetRepresentation(aReperesent);
1120 my3DActor->SetProperty(aProp);
1121 my3DActor->SetBackfaceProperty(aBackProp);
1122 my3DActor->SetRepresentation(aReperesent);
1124 my1DExtActor->SetVisibility(false);
1126 switch(myControlMode){
1128 case eMultiConnection:
1129 aProp = aBackProp = my1DProp;
1130 if(myRepresentation != ePoint)
1131 aReperesent = SMESH_DeviceActor::eInsideframe;
1135 my1DActor->SetProperty(aProp);
1136 my1DActor->SetBackfaceProperty(aBackProp);
1137 my1DActor->SetRepresentation(aReperesent);
1139 my1DExtActor->SetRepresentation(aReperesent);
1141 if(myIsPointsVisible)
1142 myPickableActor = myNodeActor;
1143 if(GetPointRepresentation())
1144 myNodeActor->SetVisibility(true);
1146 SetMapper(myPickableActor->GetMapper());
1148 SetVisibility(GetVisibility(),false);
1154 void SMESH_ActorDef::SetPointRepresentation(bool theIsPointsVisible){
1155 if ( myIsPointsVisible == theIsPointsVisible )
1157 myIsPointsVisible = theIsPointsVisible;
1158 SetRepresentation(GetRepresentation());
1161 bool SMESH_ActorDef::GetPointRepresentation(){
1162 return myIsPointsVisible || myIsPointsLabeled;
1166 void SMESH_ActorDef::UpdateHighlight(){
1167 myHighlitableActor->SetVisibility(false);
1168 myHighlitableActor->SetHighlited(false);
1170 if(myIsHighlighted){
1171 myHighlitableActor->SetProperty(myHighlightProp);
1172 }else if(myIsPreselected){
1173 myHighlitableActor->SetProperty(myPreselectProp);
1176 bool anIsVisible = GetVisibility();
1178 if(myIsHighlighted || myIsPreselected){
1179 if(GetUnstructuredGrid()->GetNumberOfCells()){
1180 myHighlitableActor->SetHighlited(anIsVisible);
1181 myHighlitableActor->SetVisibility(anIsVisible);
1182 myHighlitableActor->GetExtractUnstructuredGrid()->
1183 SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::eCells);
1184 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
1185 }else if(myRepresentation == ePoint || GetPointRepresentation()){
1186 myHighlitableActor->SetHighlited(anIsVisible);
1187 myHighlitableActor->SetVisibility(anIsVisible);
1188 myHighlitableActor->GetExtractUnstructuredGrid()->
1189 SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
1190 myHighlitableActor->SetRepresentation(SMESH_DeviceActor::ePoint);
1196 void SMESH_ActorDef::highlight(bool theHighlight){
1197 if ( myIsHighlighted == theHighlight )
1199 myIsHighlighted = theHighlight;
1204 void SMESH_ActorDef::SetPreSelected(bool thePreselect){
1205 if ( myIsPreselected == thePreselect )
1207 myIsPreselected = thePreselect;
1213 int SMESH_ActorDef::RenderOpaqueGeometry(vtkViewport *vp)
1215 if (myPickableActor->GetIsOpaque())
1217 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1225 int SMESH_ActorDef::RenderTranslucentGeometry(vtkViewport *vp)
1227 if (!myPickableActor->GetIsOpaque())
1229 vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1237 void SMESH_ActorDef::Render(vtkRenderer *ren){
1238 unsigned long aTime = myTimeStamp->GetMTime();
1239 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1240 unsigned long aClippingTime = myImplicitBoolean->GetMTime();
1241 if(anObjTime > aTime || aClippingTime > aTime)
1246 void SMESH_ActorDef::Update(){
1247 if(MYDEBUG) MESSAGE("SMESH_ActorDef::Update");
1249 if(GetControlMode() != eNone) {
1250 unsigned long aTime = myTimeStamp->GetMTime();
1251 unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1252 if (anObjTime > aTime)
1253 SetControlMode(GetControlMode(),false);
1255 if(myIsPointsLabeled){
1256 SetPointsLabeled(myIsPointsLabeled);
1258 if(myIsCellsLabeled){
1259 SetCellsLabeled(myIsCellsLabeled);
1261 SetEntityMode(GetEntityMode());
1262 SetVisibility(GetVisibility());
1264 myTimeStamp->Modified();
1269 void SMESH_ActorDef::ReleaseGraphicsResources(vtkWindow *renWin){
1270 SALOME_Actor::ReleaseGraphicsResources(renWin);
1272 myPickableActor->ReleaseGraphicsResources(renWin);
1276 static void GetColor(vtkProperty *theProperty, vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1277 vtkFloatingPointType* aColor = theProperty->GetColor();
1284 void SMESH_ActorDef::SetOpacity(vtkFloatingPointType theValue){
1285 mySurfaceProp->SetOpacity(theValue);
1286 myBackSurfaceProp->SetOpacity(theValue);
1287 myEdgeProp->SetOpacity(theValue);
1288 myNodeProp->SetOpacity(theValue);
1290 my1DProp->SetOpacity(theValue);
1294 vtkFloatingPointType SMESH_ActorDef::GetOpacity(){
1295 return mySurfaceProp->GetOpacity();
1299 void SMESH_ActorDef::SetSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1300 mySurfaceProp->SetColor(r,g,b);
1304 void SMESH_ActorDef::GetSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1305 ::GetColor(mySurfaceProp,r,g,b);
1308 void SMESH_ActorDef::SetBackSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1309 myBackSurfaceProp->SetColor(r,g,b);
1313 void SMESH_ActorDef::GetBackSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1314 ::GetColor(myBackSurfaceProp,r,g,b);
1317 void SMESH_ActorDef::SetEdgeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1318 myEdgeProp->SetColor(r,g,b);
1319 my1DProp->SetColor(r,g,b);
1320 my1DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1324 void SMESH_ActorDef::GetEdgeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1325 ::GetColor(myEdgeProp,r,g,b);
1328 void SMESH_ActorDef::SetNodeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1329 myNodeProp->SetColor(r,g,b);
1333 void SMESH_ActorDef::GetNodeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1334 ::GetColor(myNodeProp,r,g,b);
1337 void SMESH_ActorDef::SetHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1338 myHighlightProp->SetColor(r,g,b);
1342 void SMESH_ActorDef::GetHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1343 ::GetColor(myHighlightProp,r,g,b);
1346 void SMESH_ActorDef::SetPreHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1347 myPreselectProp->SetColor(r,g,b);
1351 void SMESH_ActorDef::GetPreHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1352 ::GetColor(myPreselectProp,r,g,b);
1356 vtkFloatingPointType SMESH_ActorDef::GetLineWidth(){
1357 return myEdgeProp->GetLineWidth();
1361 void SMESH_ActorDef::SetLineWidth(vtkFloatingPointType theVal){
1362 myEdgeProp->SetLineWidth(theVal);
1364 my1DProp->SetLineWidth(theVal + aLineWidthInc);
1365 my1DExtProp->SetLineWidth(theVal + aLineWidthInc);
1371 void SMESH_ActorDef::SetNodeSize(vtkFloatingPointType theVal){
1372 myNodeProp->SetPointSize(theVal);
1373 myHighlightProp->SetPointSize(theVal);
1374 myPreselectProp->SetPointSize(theVal);
1376 my1DProp->SetPointSize(theVal + aPointSizeInc);
1377 my1DExtProp->SetPointSize(theVal + aPointSizeInc);
1382 vtkFloatingPointType SMESH_ActorDef::GetNodeSize(){
1383 return myNodeProp->GetPointSize();
1386 int SMESH_ActorDef::GetObjDimension( const int theObjId )
1388 return myVisualObj->GetElemDimension( theObjId );
1393 IsImplicitFunctionUsed() const
1395 return myBaseActor->IsImplicitFunctionUsed();
1400 SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
1402 myNodeActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1403 myBaseActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1405 myHighlitableActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1407 my1DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1408 my1DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1410 my2DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1411 my3DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1416 AddClippingPlane(vtkPlane* thePlane)
1419 myImplicitBoolean->GetFunction()->AddItem(thePlane);
1420 myCippingPlaneCont.push_back(thePlane);
1421 if(!IsImplicitFunctionUsed())
1422 SetImplicitFunctionUsed(true);
1424 return myCippingPlaneCont.size();
1429 RemoveAllClippingPlanes()
1431 myImplicitBoolean->GetFunction()->RemoveAllItems();
1432 myImplicitBoolean->GetFunction()->Modified(); // VTK bug
1433 myCippingPlaneCont.clear();
1434 SetImplicitFunctionUsed(false);
1439 GetNumberOfClippingPlanes()
1441 return myCippingPlaneCont.size();
1446 GetClippingPlane(vtkIdType theID)
1448 if(theID >= myCippingPlaneCont.size())
1450 return myCippingPlaneCont[theID].Get();
1454 static void ComputeBoundsParam(vtkDataSet* theDataSet,
1455 vtkFloatingPointType theDirection[3], vtkFloatingPointType theMinPnt[3],
1456 vtkFloatingPointType& theMaxBoundPrj, vtkFloatingPointType& theMinBoundPrj)
1458 vtkFloatingPointType aBounds[6];
1459 theDataSet->GetBounds(aBounds);
1461 //Enlarge bounds in order to avoid conflicts of precision
1462 for(int i = 0; i < 6; i += 2){
1463 static double EPS = 1.0E-3;
1464 vtkFloatingPointType aDelta = (aBounds[i+1] - aBounds[i])*EPS;
1465 aBounds[i] -= aDelta;
1466 aBounds[i+1] += aDelta;
1469 vtkFloatingPointType aBoundPoints[8][3] = { {aBounds[0],aBounds[2],aBounds[4]},
1470 {aBounds[1],aBounds[2],aBounds[4]},
1471 {aBounds[0],aBounds[3],aBounds[4]},
1472 {aBounds[1],aBounds[3],aBounds[4]},
1473 {aBounds[0],aBounds[2],aBounds[5]},
1474 {aBounds[1],aBounds[2],aBounds[5]},
1475 {aBounds[0],aBounds[3],aBounds[5]},
1476 {aBounds[1],aBounds[3],aBounds[5]}};
1478 int aMaxId = 0, aMinId = aMaxId;
1479 theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
1480 theMinBoundPrj = theMaxBoundPrj;
1481 for(int i = 1; i < 8; i++){
1482 vtkFloatingPointType aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
1483 if(theMaxBoundPrj < aTmp){
1484 theMaxBoundPrj = aTmp;
1487 if(theMinBoundPrj > aTmp){
1488 theMinBoundPrj = aTmp;
1492 vtkFloatingPointType *aMinPnt = aBoundPoints[aMaxId];
1493 theMinPnt[0] = aMinPnt[0];
1494 theMinPnt[1] = aMinPnt[1];
1495 theMinPnt[2] = aMinPnt[2];
1499 static void DistanceToPosition(vtkDataSet* theDataSet,
1500 vtkFloatingPointType theDirection[3], vtkFloatingPointType theDist, vtkFloatingPointType thePos[3])
1502 vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1503 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1504 vtkFloatingPointType aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
1505 thePos[0] = aMinPnt[0]-theDirection[0]*aLength;
1506 thePos[1] = aMinPnt[1]-theDirection[1]*aLength;
1507 thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
1511 static void PositionToDistance(vtkDataSet* theDataSet,
1512 vtkFloatingPointType theDirection[3], vtkFloatingPointType thePos[3], vtkFloatingPointType& theDist)
1514 vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1515 ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1516 vtkFloatingPointType aPrj = vtkMath::Dot(theDirection,thePos);
1517 theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
1521 void SMESH_ActorDef::SetPlaneParam(vtkFloatingPointType theDir[3], vtkFloatingPointType theDist, vtkPlane* thePlane)
1523 thePlane->SetNormal(theDir);
1524 vtkFloatingPointType anOrigin[3];
1525 ::DistanceToPosition(GetUnstructuredGrid(),theDir,theDist,anOrigin);
1526 thePlane->SetOrigin(anOrigin);
1530 void SMESH_ActorDef::GetPlaneParam(vtkFloatingPointType theDir[3], vtkFloatingPointType& theDist, vtkPlane* thePlane)
1532 thePlane->GetNormal(theDir);
1534 vtkFloatingPointType anOrigin[3];
1535 thePlane->GetOrigin(anOrigin);
1536 ::PositionToDistance(GetUnstructuredGrid(),theDir,anOrigin,theDist);
1539 void SMESH_ActorDef::UpdateScalarBar()
1541 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
1545 vtkTextProperty* aScalarBarTitleProp = vtkTextProperty::New();
1547 QColor aTColor = mgr->colorValue( "SMESH", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
1548 aScalarBarTitleProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1550 aScalarBarTitleProp->SetFontFamilyToArial();
1552 if ( mgr->hasValue( "SMESH", "scalar_bar_title_font" ) )
1554 QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
1555 if ( f.family() == "Arial" )
1556 aScalarBarTitleProp->SetFontFamilyToArial();
1557 else if ( f.family() == "Courier" )
1558 aScalarBarTitleProp->SetFontFamilyToCourier();
1559 else if ( f.family() == "Times" )
1560 aScalarBarTitleProp->SetFontFamilyToTimes();
1563 aScalarBarTitleProp->BoldOn();
1565 aScalarBarTitleProp->BoldOff();
1568 aScalarBarTitleProp->ItalicOn();
1570 aScalarBarTitleProp->ItalicOff();
1572 if ( f.underline() )
1573 aScalarBarTitleProp->ShadowOn();
1575 aScalarBarTitleProp->ShadowOff();
1578 myScalarBarActor->SetTitleTextProperty( aScalarBarTitleProp );
1579 aScalarBarTitleProp->Delete();
1581 vtkTextProperty* aScalarBarLabelProp = vtkTextProperty::New();
1583 aTColor = mgr->colorValue( "SMESH", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
1584 aScalarBarLabelProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1586 aScalarBarLabelProp->SetFontFamilyToArial();
1587 if( mgr->hasValue( "SMESH", "scalar_bar_label_font" ) )
1589 QFont f = mgr->fontValue( "SMESH", "scalar_bar_label_font" );
1590 if( f.family() == "Arial" )
1591 aScalarBarLabelProp->SetFontFamilyToArial();
1592 else if( f.family() == "Courier" )
1593 aScalarBarLabelProp->SetFontFamilyToCourier();
1594 else if( f.family() == "Times" )
1595 aScalarBarLabelProp->SetFontFamilyToTimes();
1598 aScalarBarLabelProp->BoldOn();
1600 aScalarBarLabelProp->BoldOff();
1603 aScalarBarLabelProp->ItalicOn();
1605 aScalarBarLabelProp->ItalicOff();
1608 aScalarBarLabelProp->ShadowOn();
1610 aScalarBarLabelProp->ShadowOff();
1613 myScalarBarActor->SetLabelTextProperty( aScalarBarLabelProp );
1614 aScalarBarLabelProp->Delete();
1616 bool horiz = ( mgr->integerValue( "SMESH", "scalar_bar_orientation" ) == 1 );
1617 QString name = QString( "scalar_bar_%1_" ).arg( horiz ? "horizontal" : "vertical" );
1619 myScalarBarActor->SetOrientationToHorizontal();
1621 myScalarBarActor->SetOrientationToVertical();
1624 vtkFloatingPointType aXVal = horiz ? 0.20 : 0.01;
1625 if( mgr->hasValue( "SMESH", name + "x" ) )
1626 aXVal = mgr->doubleValue( "SMESH", name + "x", aXVal );
1628 vtkFloatingPointType aYVal = horiz ? 0.01 : 0.1;
1629 if( mgr->hasValue( "SMESH", name + "y" ) )
1630 aYVal = mgr->doubleValue( "SMESH", name + "y", aYVal );
1631 myScalarBarActor->SetPosition( aXVal, aYVal );
1633 vtkFloatingPointType aWVal = horiz ? 0.60 : 0.10;
1634 if( mgr->hasValue( "SMESH", name + "width" ) )
1635 aWVal = mgr->doubleValue( "SMESH", name + "width", aWVal );
1636 myScalarBarActor->SetWidth( aWVal );
1638 vtkFloatingPointType aHVal = horiz ? 0.12 : 0.80;
1639 if( mgr->hasValue( "SMESH", name + "height" ) )
1640 aHVal = mgr->doubleValue( "SMESH", name + "height", aHVal );
1641 myScalarBarActor->SetHeight( aHVal );
1644 if( mgr->hasValue( "SMESH", "scalar_bar_num_labels" ) )
1645 anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_labels", anIntVal );
1646 myScalarBarActor->SetNumberOfLabels( anIntVal == 0 ? 5: anIntVal );
1649 if( mgr->hasValue( "SMESH", "scalar_bar_num_colors" ) )
1650 anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_colors", anIntVal );
1651 myScalarBarActor->SetMaximumNumberOfColors( anIntVal == 0 ? 64 : anIntVal );