Salome HOME
0021338: EDF 1926 SMESH: New controls and filters
[modules/smesh.git] / src / OBJECT / SMESH_DeviceActor.cxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SMESH OBJECT : interactive object for SMESH visualization
24 //  File   : SMESH_DeviceActor.cxx
25 //  Author : 
26 //  Module : SMESH
27 //
28 #include "SMESH_DeviceActor.h"
29 #include "SMESH_ScalarBarActor.h"
30 #include "SMESH_ExtractGeometry.h"
31 #include "SMESH_ControlsDef.hxx"
32 #include "SMESH_ActorUtils.h"
33 #include "SMESH_FaceOrientationFilter.h"
34 #include "VTKViewer_CellLocationsArray.h"
35 #include "VTKViewer_PolyDataMapper.h"
36
37 #include <VTKViewer_Transform.h>
38 #include <VTKViewer_TransformFilter.h>
39 #include <VTKViewer_ExtractUnstructuredGrid.h>
40
41 // VTK Includes
42 #include <vtkObjectFactory.h>
43 #include <vtkShrinkFilter.h>
44 #include <vtkShrinkPolyData.h>
45
46 #include <vtkProperty.h>
47 #include <vtkPolyData.h>
48 #include <vtkMergeFilter.h>
49 #include <vtkPolyDataMapper.h>
50 #include <vtkUnstructuredGrid.h>
51
52 #include <vtkLookupTable.h>
53 #include <vtkDoubleArray.h>
54 #include <vtkCellData.h>
55
56 #include <vtkCell.h>
57 #include <vtkIdList.h>
58 #include <vtkCellArray.h>
59 #include <vtkUnsignedCharArray.h>
60
61 #include <vtkImplicitBoolean.h>
62 #include <vtkPassThroughFilter.h>
63
64 #include <vtkRenderer.h>
65
66 #include "utilities.h"
67
68 #ifdef _DEBUG_
69 static int MYDEBUG = 0;
70 #else
71 static int MYDEBUG = 0;
72 #endif
73
74 using namespace std;
75
76
77 vtkStandardNewMacro(SMESH_DeviceActor);
78
79
80 SMESH_DeviceActor
81 ::SMESH_DeviceActor()
82 {
83   if(MYDEBUG) MESSAGE("SMESH_DeviceActor - "<<this);
84
85   myIsShrinkable = false;
86   myIsShrunk = false;
87   myIsHighlited = false;
88
89   myRepresentation = eSurface;
90
91   myProperty = vtkProperty::New();
92   myMapper = VTKViewer_PolyDataMapper::New();
93
94   vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
95                                                                  myPolygonOffsetUnits);
96
97   myMapper->UseLookupTableScalarRangeOn();
98   myMapper->SetColorModeToMapScalars();
99
100   myShrinkFilter = vtkShrinkFilter::New();
101
102   myStoreClippingMapping = false;
103
104   myExtractGeometry = SMESH_ExtractGeometry::New();
105   myExtractGeometry->SetReleaseDataFlag(true);
106   myIsImplicitFunctionUsed = false;
107
108   myExtractUnstructuredGrid = VTKViewer_ExtractUnstructuredGrid::New();
109     
110   myMergeFilter = vtkMergeFilter::New();
111
112   myGeomFilter = VTKViewer_GeometryFilter::New();
113
114   myTransformFilter = VTKViewer_TransformFilter::New();
115
116   for(int i = 0; i < 6; i++)
117     myPassFilter.push_back(vtkPassThroughFilter::New());
118
119   // Orientation of faces
120   myIsFacesOriented = false;
121
122   vtkFloatingPointType anRGB[3] = { 1, 1, 1 };
123   SMESH::GetColor( "SMESH", "orientation_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
124
125   myFaceOrientationFilter = SMESH_FaceOrientationFilter::New();
126
127   myFaceOrientationDataMapper = vtkPolyDataMapper::New();
128   myFaceOrientationDataMapper->SetInput(myFaceOrientationFilter->GetOutput());
129
130   myFaceOrientation = vtkActor::New();
131   myFaceOrientation->SetMapper(myFaceOrientationDataMapper);
132   myFaceOrientation->GetProperty()->SetColor(anRGB[0], anRGB[1], anRGB[2]);
133 }
134
135
136 SMESH_DeviceActor
137 ::~SMESH_DeviceActor()
138 {
139   if(MYDEBUG) MESSAGE("~SMESH_DeviceActor - "<<this);
140
141   myProperty->Delete();
142
143   myMapper->Delete();
144
145   myShrinkFilter->Delete();
146
147   myExtractUnstructuredGrid->Delete();
148
149   myMergeFilter->Delete();
150
151   myGeomFilter->Delete();
152
153   myExtractGeometry->Delete();
154
155   myTransformFilter->Delete();
156
157   for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++){
158     myPassFilter[i]->Delete();
159   }
160
161   // Orientation of faces
162   myFaceOrientationFilter->Delete();
163
164   myFaceOrientationDataMapper->RemoveAllInputs();
165   myFaceOrientationDataMapper->Delete();
166
167   myFaceOrientation->Delete();
168 }
169
170
171 void
172 SMESH_DeviceActor
173 ::SetStoreGemetryMapping(bool theStoreMapping)
174 {
175   myGeomFilter->SetStoreMapping(theStoreMapping);
176   SetStoreClippingMapping(theStoreMapping);
177 }
178
179
180 void
181 SMESH_DeviceActor
182 ::SetStoreClippingMapping(bool theStoreMapping)
183 {
184   myStoreClippingMapping = theStoreMapping;
185   myExtractGeometry->SetStoreMapping(theStoreMapping && myIsImplicitFunctionUsed);
186   SetStoreIDMapping(theStoreMapping);
187 }
188
189
190 void
191 SMESH_DeviceActor
192 ::SetStoreIDMapping(bool theStoreMapping)
193 {
194   myExtractUnstructuredGrid->SetStoreMapping(theStoreMapping);
195 }
196
197
198 void 
199 SMESH_DeviceActor
200 ::Init(TVisualObjPtr theVisualObj, 
201        vtkImplicitBoolean* theImplicitBoolean)
202 {
203   myVisualObj = theVisualObj;
204   myExtractGeometry->SetImplicitFunction(theImplicitBoolean);
205   SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
206 }
207
208
209 void
210 SMESH_DeviceActor
211 ::SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
212 {
213   int anId = 0;
214   if(theIsImplicitFunctionUsed)
215     myPassFilter[ anId ]->SetInput( myExtractGeometry->GetOutput() );
216   else
217     myPassFilter[ anId ]->SetInput( myMergeFilter->GetOutput() );
218     
219   myIsImplicitFunctionUsed = theIsImplicitFunctionUsed;
220   SetStoreClippingMapping(myStoreClippingMapping);
221 }
222
223
224 void
225 SMESH_DeviceActor
226 ::SetUnstructuredGrid(vtkUnstructuredGrid* theGrid)
227 {
228   if(theGrid){
229     //myIsShrinkable = theGrid->GetNumberOfCells() > 10;
230     myIsShrinkable = true;
231
232     myExtractUnstructuredGrid->SetInput(theGrid);
233
234     myMergeFilter->SetGeometry(myExtractUnstructuredGrid->GetOutput());
235
236     myExtractGeometry->SetInput(myMergeFilter->GetOutput());
237
238     int anId = 0;
239     SetImplicitFunctionUsed(myIsImplicitFunctionUsed);
240     myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() );
241     
242     anId++; // 1
243     myGeomFilter->SetInput( myPassFilter[ anId ]->GetOutput() );
244
245     anId++; // 2
246     myPassFilter[ anId ]->SetInput( myGeomFilter->GetOutput() ); 
247     myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
248
249     anId++; // 3
250     myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() );
251
252     anId++; // 4
253     myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() );
254     myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
255
256     anId++; // 5
257     myMapper->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() );
258
259     vtkLODActor::SetMapper( myMapper );
260     Modified();
261   }
262 }
263
264
265 VTKViewer_ExtractUnstructuredGrid* 
266 SMESH_DeviceActor
267 ::GetExtractUnstructuredGrid()
268 {
269   return myExtractUnstructuredGrid;
270 }
271
272
273 vtkUnstructuredGrid* 
274 SMESH_DeviceActor
275 ::GetUnstructuredGrid()
276 {
277   myExtractUnstructuredGrid->Update();
278   return myExtractUnstructuredGrid->GetOutput();
279 }
280
281
282 void
283 SMESH_DeviceActor
284 ::SetControlMode(SMESH::Controls::FunctorPtr theFunctor,
285                  SMESH_ScalarBarActor* theScalarBarActor,
286                  vtkLookupTable* theLookupTable)
287 {
288   bool anIsInitialized = theFunctor;
289   if(anIsInitialized){
290     vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New();
291
292     SetStoreIDMapping(true);
293     myExtractUnstructuredGrid->Update();
294     vtkUnstructuredGrid* aGrid = myExtractUnstructuredGrid->GetOutput();
295
296     aDataSet->ShallowCopy(aGrid);
297     
298     vtkDoubleArray *aScalars = vtkDoubleArray::New();
299     vtkIdType aNbCells = aGrid->GetNumberOfCells();
300     aScalars->SetNumberOfComponents(1);
301     aScalars->SetNumberOfTuples(aNbCells);
302     
303     myVisualObj->UpdateFunctor(theFunctor);
304
305     using namespace SMESH::Controls;
306     if(NumericalFunctor* aNumericalFunctor = dynamic_cast<NumericalFunctor*>(theFunctor.get())){
307       for(vtkIdType i = 0; i < aNbCells; i++){
308         vtkIdType anId = myExtractUnstructuredGrid->GetInputId(i);
309         vtkIdType anObjId = myVisualObj->GetElemObjId(anId);
310         double aValue = aNumericalFunctor->GetValue(anObjId);
311         aScalars->SetValue(i,aValue);
312       }
313     }else if(Predicate* aPredicate = dynamic_cast<Predicate*>(theFunctor.get())){
314       for(vtkIdType i = 0; i < aNbCells; i++){
315         vtkIdType anId = myExtractUnstructuredGrid->GetInputId(i);
316         vtkIdType anObjId = myVisualObj->GetElemObjId(anId);
317         bool aValue = aPredicate->IsSatisfy(anObjId);
318         aScalars->SetValue(i,aValue);
319       }
320     }
321
322     aDataSet->GetCellData()->SetScalars(aScalars);
323     aScalars->Delete();
324         
325     theLookupTable->SetRange(aScalars->GetRange());
326     theLookupTable->SetNumberOfTableValues(theScalarBarActor->GetMaximumNumberOfColors());
327     theLookupTable->Build();
328     
329     myMergeFilter->SetScalars(aDataSet);
330     aDataSet->Delete();
331   }
332   GetMapper()->SetScalarVisibility(anIsInitialized);
333   theScalarBarActor->SetVisibility(anIsInitialized);
334 }
335
336 void
337 SMESH_DeviceActor
338 ::SetExtControlMode(SMESH::Controls::FunctorPtr theFunctor,
339                     SMESH_ScalarBarActor* theScalarBarActor,
340                     vtkLookupTable* theLookupTable)
341 {
342   bool anIsInitialized = theFunctor;
343   myExtractUnstructuredGrid->ClearRegisteredCells();
344   myExtractUnstructuredGrid->ClearRegisteredCellsWithType();
345   myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::ePassAll);
346   myVisualObj->UpdateFunctor(theFunctor);
347
348   using namespace SMESH::Controls;
349   if (anIsInitialized){
350     if (Length2D* aLength2D = dynamic_cast<Length2D*>(theFunctor.get())){
351       SMESH::Controls::Length2D::TValues aValues;
352
353       aLength2D->GetValues(aValues);
354       vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New();
355       vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
356
357       aDataSet->SetPoints(aGrid->GetPoints());
358       
359       vtkIdType aNbCells = aValues.size();
360       
361       vtkDoubleArray *aScalars = vtkDoubleArray::New();
362       aScalars->SetNumberOfComponents(1);
363       aScalars->SetNumberOfTuples(aNbCells);
364
365       vtkIdType aCellsSize = 3*aNbCells;
366       vtkCellArray* aConnectivity = vtkCellArray::New();
367       aConnectivity->Allocate( aCellsSize, 0 );
368       
369       vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
370       aCellTypesArray->SetNumberOfComponents( 1 );
371       aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
372       
373       vtkIdList *anIdList = vtkIdList::New();
374       anIdList->SetNumberOfIds(2);
375       
376       Length2D::TValues::const_iterator anIter = aValues.begin();
377       for(vtkIdType aVtkId = 0; anIter != aValues.end(); anIter++,aVtkId++){
378         const Length2D::Value& aValue = *anIter;
379         int aNode[2] = {
380           myVisualObj->GetNodeVTKId(aValue.myPntId[0]),
381           myVisualObj->GetNodeVTKId(aValue.myPntId[1])
382         };
383         if(aNode[0] >= 0 && aNode[1] >= 0){
384           anIdList->SetId( 0, aNode[0] );
385           anIdList->SetId( 1, aNode[1] );
386           aConnectivity->InsertNextCell( anIdList );
387           aCellTypesArray->InsertNextValue( VTK_LINE );
388           aScalars->SetValue(aVtkId,aValue.myLength);
389         }
390       }
391       
392       VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
393       aCellLocationsArray->SetNumberOfComponents( 1 );
394       aCellLocationsArray->SetNumberOfTuples( aNbCells );
395       
396       aConnectivity->InitTraversal();
397       for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
398         aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
399       
400       aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
401       SetUnstructuredGrid(aDataSet);
402
403       aDataSet->GetCellData()->SetScalars(aScalars);
404       aScalars->Delete();
405       
406       theLookupTable->SetRange(aScalars->GetRange());
407       theLookupTable->Build();
408       
409       myMergeFilter->SetScalars(aDataSet);
410       aDataSet->Delete();
411     }
412     else if (MultiConnection2D* aMultiConnection2D = dynamic_cast<MultiConnection2D*>(theFunctor.get())){
413       SMESH::Controls::MultiConnection2D::MValues aValues;
414
415       aMultiConnection2D->GetValues(aValues);
416       vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New();
417       vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
418       aDataSet->SetPoints(aGrid->GetPoints());
419       
420       vtkIdType aNbCells = aValues.size();
421       vtkDoubleArray *aScalars = vtkDoubleArray::New();
422       aScalars->SetNumberOfComponents(1);
423       aScalars->SetNumberOfTuples(aNbCells);
424
425       vtkIdType aCellsSize = 3*aNbCells;
426       vtkCellArray* aConnectivity = vtkCellArray::New();
427       aConnectivity->Allocate( aCellsSize, 0 );
428       
429       vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
430       aCellTypesArray->SetNumberOfComponents( 1 );
431       aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
432       
433       vtkIdList *anIdList = vtkIdList::New();
434       anIdList->SetNumberOfIds(2);
435       
436       MultiConnection2D::MValues::const_iterator anIter = aValues.begin();
437       for(vtkIdType aVtkId = 0; anIter != aValues.end(); anIter++,aVtkId++){
438         const MultiConnection2D::Value& aValue = (*anIter).first;
439         int aNode[2] = {
440           myVisualObj->GetNodeVTKId(aValue.myPntId[0]),
441           myVisualObj->GetNodeVTKId(aValue.myPntId[1])
442         };
443         if(aNode[0] >= 0 && aNode[1] >= 0){
444           anIdList->SetId( 0, aNode[0] );
445           anIdList->SetId( 1, aNode[1] );
446           aConnectivity->InsertNextCell( anIdList );
447           aCellTypesArray->InsertNextValue( VTK_LINE );
448           aScalars->SetValue(aVtkId,(*anIter).second);
449         }
450       }
451       
452       VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
453       aCellLocationsArray->SetNumberOfComponents( 1 );
454       aCellLocationsArray->SetNumberOfTuples( aNbCells );
455       
456       aConnectivity->InitTraversal();
457       for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
458         aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
459       
460       aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
461       SetUnstructuredGrid(aDataSet);
462
463       aDataSet->GetCellData()->SetScalars(aScalars);
464       aScalars->Delete();
465       
466       theLookupTable->SetRange(aScalars->GetRange());
467       theLookupTable->Build();
468       
469       myMergeFilter->SetScalars(aDataSet);
470       aDataSet->Delete();
471     }
472   }
473   GetMapper()->SetScalarVisibility(anIsInitialized);
474   theScalarBarActor->SetVisibility(anIsInitialized);
475 }
476
477 void
478 SMESH_DeviceActor
479 ::SetExtControlMode(SMESH::Controls::FunctorPtr theFunctor)
480 {
481   myExtractUnstructuredGrid->ClearRegisteredCells();
482   myExtractUnstructuredGrid->ClearRegisteredCellsWithType();
483   myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::ePassAll);
484   myVisualObj->UpdateFunctor(theFunctor);
485
486   using namespace SMESH::Controls;
487   if ( dynamic_cast<FreeBorders          *>(theFunctor.get()) ||
488        dynamic_cast<FreeFaces            *>(theFunctor.get()) ||
489        dynamic_cast<BareBorderVolume     *>(theFunctor.get()) ||
490        dynamic_cast<BareBorderFace       *>(theFunctor.get()) ||
491        dynamic_cast<OverConstrainedVolume*>(theFunctor.get()) ||
492        dynamic_cast<CoincidentNodes      *>(theFunctor.get()) ||
493        dynamic_cast<CoincidentElements1D *>(theFunctor.get()) ||
494        dynamic_cast<CoincidentElements2D *>(theFunctor.get()) ||
495        dynamic_cast<CoincidentElements3D *>(theFunctor.get()) ||
496        dynamic_cast<OverConstrainedFace  *>(theFunctor.get()))
497   {
498     Predicate* aFreePredicate = dynamic_cast<Predicate*>(theFunctor.get());
499     myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
500     vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
501     vtkIdType aNbCells = aGrid->GetNumberOfCells();
502     for( vtkIdType i = 0; i < aNbCells; i++ ){
503       vtkIdType anObjId = myVisualObj->GetElemObjId(i);
504       if(aFreePredicate->IsSatisfy(anObjId))
505         myExtractUnstructuredGrid->RegisterCell(i);
506     }
507     if(!myExtractUnstructuredGrid->IsCellsRegistered())
508       myExtractUnstructuredGrid->RegisterCell(-1);
509     SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
510   }
511   else if(FreeEdges* aFreeEdges = dynamic_cast<FreeEdges*>(theFunctor.get()))
512   {
513     SMESH::Controls::FreeEdges::TBorders aBorders;
514     aFreeEdges->GetBoreders(aBorders);
515     vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New();
516     vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
517     aDataSet->SetPoints(aGrid->GetPoints());
518
519     vtkIdType aNbCells = aBorders.size();
520     vtkIdType aCellsSize = 3*aNbCells;
521     vtkCellArray* aConnectivity = vtkCellArray::New();
522     aConnectivity->Allocate( aCellsSize, 0 );
523     
524     vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
525     aCellTypesArray->SetNumberOfComponents( 1 );
526     aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
527     
528     vtkIdList *anIdList = vtkIdList::New();
529     anIdList->SetNumberOfIds(2);
530     
531     FreeEdges::TBorders::const_iterator anIter = aBorders.begin();
532     for(; anIter != aBorders.end(); anIter++){
533       const FreeEdges::Border& aBorder = *anIter;
534       int aNode[2] = {
535         myVisualObj->GetNodeVTKId(aBorder.myPntId[0]),
536         myVisualObj->GetNodeVTKId(aBorder.myPntId[1])
537       };
538       //cout<<"aNode = "<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<endl;
539       if(aNode[0] >= 0 && aNode[1] >= 0){
540         anIdList->SetId( 0, aNode[0] );
541         anIdList->SetId( 1, aNode[1] );
542         aConnectivity->InsertNextCell( anIdList );
543         aCellTypesArray->InsertNextValue( VTK_LINE );
544       }
545     }
546     
547     VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
548     aCellLocationsArray->SetNumberOfComponents( 1 );
549     aCellLocationsArray->SetNumberOfTuples( aNbCells );
550     
551     aConnectivity->InitTraversal();
552     for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
553       aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
554     
555     aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
556
557     SetUnstructuredGrid(aDataSet);
558     aDataSet->Delete();
559   }
560   else if(FreeNodes* aFreeNodes = dynamic_cast<FreeNodes*>(theFunctor.get()))
561   {
562     myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
563     vtkIdType aNbNodes = myVisualObj->GetNbEntities(SMDSAbs_Node);
564     for( vtkIdType i = 0; i < aNbNodes; i++ ){
565       vtkIdType anObjId = myVisualObj->GetNodeObjId(i);
566       if(aFreeNodes->IsSatisfy(anObjId))
567         myExtractUnstructuredGrid->RegisterCell(i);
568     }
569     if(!myExtractUnstructuredGrid->IsCellsRegistered())
570       myExtractUnstructuredGrid->RegisterCell(-1);
571     SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
572   }
573 }
574
575
576
577
578 unsigned long int 
579 SMESH_DeviceActor
580 ::GetMTime()
581 {
582   unsigned long mTime = this->Superclass::GetMTime();
583   mTime = max(mTime,myExtractGeometry->GetMTime());
584   mTime = max(mTime,myExtractUnstructuredGrid->GetMTime());
585   mTime = max(mTime,myMergeFilter->GetMTime());
586   mTime = max(mTime,myGeomFilter->GetMTime());
587   mTime = max(mTime,myTransformFilter->GetMTime());
588   mTime = max(mTime,myFaceOrientationFilter->GetMTime());
589   return mTime;
590 }
591
592
593 void
594 SMESH_DeviceActor
595 ::SetTransform(VTKViewer_Transform* theTransform)
596 {
597   myTransformFilter->SetTransform(theTransform);
598 }
599
600
601 void
602 SMESH_DeviceActor
603 ::SetShrink() 
604 {
605   if ( !myIsShrinkable ) return;
606   if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() )
607   {
608     myShrinkFilter->SetInput( aDataSet );
609     myPassFilter[ 1 ]->SetInput( myShrinkFilter->GetOutput() );
610     myIsShrunk = true;
611   }
612 }
613
614 void
615 SMESH_DeviceActor
616 ::UnShrink() 
617 {
618   if ( !myIsShrunk ) return;
619   if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() )
620   {    
621     myPassFilter[ 1 ]->SetInput( aDataSet );
622     myPassFilter[ 1 ]->Modified();
623     myIsShrunk = false;
624     Modified();
625   }
626 }
627
628
629 void
630 SMESH_DeviceActor
631 ::SetFacesOriented(bool theIsFacesOriented) 
632 {
633   if ( vtkDataSet* aDataSet = myTransformFilter->GetOutput() )
634   {
635     myIsFacesOriented = theIsFacesOriented;
636     if( theIsFacesOriented )
637       myFaceOrientationFilter->SetInput( aDataSet );
638     UpdateFaceOrientation();
639   }
640 }
641
642 void
643 SMESH_DeviceActor
644 ::SetFacesOrientationColor(vtkFloatingPointType theColor[3])
645 {
646   myFaceOrientation->GetProperty()->SetColor( theColor );
647 }
648
649 void
650 SMESH_DeviceActor
651 ::GetFacesOrientationColor(vtkFloatingPointType theColor[3])
652 {
653   myFaceOrientation->GetProperty()->GetColor( theColor );
654 }
655
656 void
657 SMESH_DeviceActor
658 ::SetFacesOrientationScale(vtkFloatingPointType theScale)
659 {
660   myFaceOrientationFilter->SetOrientationScale( theScale );
661 }
662
663 vtkFloatingPointType
664 SMESH_DeviceActor
665 ::GetFacesOrientationScale()
666 {
667   return myFaceOrientationFilter->GetOrientationScale();
668 }
669
670 void
671 SMESH_DeviceActor
672 ::SetFacesOrientation3DVectors(bool theState)
673 {
674   myFaceOrientationFilter->Set3dVectors( theState );
675 }
676
677 bool
678 SMESH_DeviceActor
679 ::GetFacesOrientation3DVectors()
680 {
681   return myFaceOrientationFilter->Get3dVectors();
682 }
683
684 void
685 SMESH_DeviceActor
686 ::UpdateFaceOrientation()
687 {
688   bool aShowFaceOrientation = myIsFacesOriented;
689   aShowFaceOrientation &= GetVisibility();
690   aShowFaceOrientation &= myRepresentation == eSurface;
691   myFaceOrientation->SetVisibility(aShowFaceOrientation);
692 }
693
694
695 void
696 SMESH_DeviceActor
697 ::SetRepresentation(EReperesent theMode)
698 {
699   switch(theMode){
700   case ePoint:
701     myGeomFilter->SetInside(true);
702     myGeomFilter->SetWireframeMode(false);
703     GetProperty()->SetRepresentation(0);
704     break;
705   case eWireframe:
706     myGeomFilter->SetInside(false);
707     myGeomFilter->SetWireframeMode(true);
708     GetProperty()->SetRepresentation(theMode);
709     break;
710   case eInsideframe:
711     myGeomFilter->SetInside(true);
712     myGeomFilter->SetWireframeMode(true);
713     GetProperty()->SetRepresentation(1);
714     break;
715   case eSurface:
716     myGeomFilter->SetInside(false);
717     myGeomFilter->SetWireframeMode(false);
718     GetProperty()->SetRepresentation(theMode);
719   }
720   SetMarkerEnabled(theMode == ePoint);
721   myRepresentation = theMode;
722   UpdateFaceOrientation();
723   GetProperty()->Modified();
724   myMapper->Modified();
725   Modified();
726 }
727
728
729 void
730 SMESH_DeviceActor
731 ::SetVisibility(int theMode)
732 {
733   if(!myExtractUnstructuredGrid->GetInput() || 
734      GetUnstructuredGrid()->GetNumberOfCells())
735   {
736     vtkLODActor::SetVisibility(theMode);
737   }else{
738     vtkLODActor::SetVisibility(false);
739   }
740   UpdateFaceOrientation();
741 }
742
743
744 int
745 SMESH_DeviceActor
746 ::GetVisibility()
747 {
748   if(!GetUnstructuredGrid()->GetNumberOfCells()){
749     vtkLODActor::SetVisibility(false);
750   }
751   return vtkLODActor::GetVisibility();
752 }
753
754
755 void
756 SMESH_DeviceActor
757 ::AddToRender(vtkRenderer* theRenderer)
758 {
759   theRenderer->AddActor(this);
760   theRenderer->AddActor(myFaceOrientation);
761 }
762
763 void
764 SMESH_DeviceActor
765 ::RemoveFromRender(vtkRenderer* theRenderer)
766 {
767   theRenderer->RemoveActor(this);
768   theRenderer->RemoveActor(myFaceOrientation);
769 }
770
771
772 int
773 SMESH_DeviceActor
774 ::GetNodeObjId(int theVtkID)
775 {
776   vtkIdType anID = theVtkID;
777
778   if(IsImplicitFunctionUsed())
779     anID = myExtractGeometry->GetNodeObjId(theVtkID);
780
781   vtkIdType aRetID = myVisualObj->GetNodeObjId(anID);
782   if(MYDEBUG) MESSAGE("GetNodeObjId - theVtkID = "<<theVtkID<<"; anID = "<<anID<<"; aRetID = "<<aRetID);
783   return aRetID;
784 }
785
786 vtkFloatingPointType* 
787 SMESH_DeviceActor
788 ::GetNodeCoord(int theObjID)
789 {
790   vtkDataSet* aDataSet = myMergeFilter->GetOutput();
791   vtkIdType anID = myVisualObj->GetNodeVTKId(theObjID);
792   vtkFloatingPointType* aCoord = (anID >=0) ? aDataSet->GetPoint(anID) : NULL;
793   if(MYDEBUG) MESSAGE("GetNodeCoord - theObjID = "<<theObjID<<"; anID = "<<anID);
794   return aCoord;
795 }
796
797
798 int
799 SMESH_DeviceActor
800 ::GetElemObjId(int theVtkID)
801 {
802   vtkIdType anId = myGeomFilter->GetElemObjId(theVtkID);
803   if(anId < 0) 
804     return -1;
805
806   vtkIdType anId2 = anId;
807   if(IsImplicitFunctionUsed())
808     anId2 = myExtractGeometry->GetElemObjId(anId);
809   if(anId2 < 0) 
810     return -1;
811
812   vtkIdType anId3 = myExtractUnstructuredGrid->GetInputId(anId2);
813   if(anId3 < 0) 
814     return -1;
815
816   vtkIdType aRetID = myVisualObj->GetElemObjId(anId3);
817   if(MYDEBUG) 
818      MESSAGE("GetElemObjId - theVtkID = "<<theVtkID<<"; anId2 = "<<anId2<<"; anId3 = "<<anId3<<"; aRetID = "<<aRetID);
819   return aRetID;
820 }
821
822 vtkCell* 
823 SMESH_DeviceActor
824 ::GetElemCell(int theObjID)
825 {
826   vtkDataSet* aDataSet = myVisualObj->GetUnstructuredGrid();
827   vtkIdType aGridID = myVisualObj->GetElemVTKId(theObjID);
828   vtkCell* aCell = (aGridID >= 0 ) ? aDataSet->GetCell(aGridID) : NULL;
829   if(MYDEBUG) 
830     MESSAGE("GetElemCell - theObjID = "<<theObjID<<"; aGridID = "<<aGridID);
831   return aCell;
832 }
833
834
835 vtkFloatingPointType 
836 SMESH_DeviceActor
837 ::GetShrinkFactor()
838 {
839   return myShrinkFilter->GetShrinkFactor();
840 }
841
842 void
843 SMESH_DeviceActor
844 ::SetShrinkFactor(vtkFloatingPointType theValue)
845 {
846   theValue = theValue > 0.1? theValue: 0.8;
847   myShrinkFilter->SetShrinkFactor(theValue);
848   Modified();
849 }
850
851
852 void
853 SMESH_DeviceActor
854 ::SetHighlited(bool theIsHighlited)
855 {
856   if ( myIsHighlited == theIsHighlited )
857     return;
858   myIsHighlited = theIsHighlited;
859   Modified();
860 }
861
862 void
863 SMESH_DeviceActor
864 ::Render(vtkRenderer *ren, vtkMapper* m)
865 {
866   int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology();
867   vtkFloatingPointType aStoredFactor, aStoredUnit; 
868   vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aStoredFactor,aStoredUnit);
869
870   vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
871   vtkFloatingPointType aFactor = myPolygonOffsetFactor, aUnits = myPolygonOffsetUnits;
872   if(myIsHighlited){
873     static vtkFloatingPointType EPS = .01;
874     aUnits *= (1.0-EPS);
875   }
876   vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnits);
877   vtkLODActor::Render(ren,m);
878
879   vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aStoredFactor,aStoredUnit);
880   vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology);
881 }
882
883
884 void
885 SMESH_DeviceActor
886 ::SetPolygonOffsetParameters(vtkFloatingPointType factor, 
887                              vtkFloatingPointType units)
888 {
889   myPolygonOffsetFactor = factor;
890   myPolygonOffsetUnits = units;
891 }
892
893 /*!
894  * On/Off representation 2D quadratic element as arked polygon
895  */
896 void SMESH_DeviceActor::SetQuadraticArcMode(bool theFlag){
897   myGeomFilter->SetQuadraticArcMode(theFlag);
898 }
899
900 /*!
901  * Return true if 2D quadratic element displayed as arked polygon
902  */
903 bool SMESH_DeviceActor::GetQuadraticArcMode(){
904   return myGeomFilter->GetQuadraticArcMode();
905 }
906 /*!
907  * Set Max angle for representation 2D quadratic element as arked polygon
908  */
909 void SMESH_DeviceActor::SetQuadraticArcAngle(vtkFloatingPointType theMaxAngle){
910   myGeomFilter->SetQuadraticArcAngle(theMaxAngle);
911 }
912
913 /*!
914  * Return Max angle of the representation 2D quadratic element as arked polygon
915  */
916 vtkFloatingPointType SMESH_DeviceActor::GetQuadraticArcAngle(){
917   return myGeomFilter->GetQuadraticArcAngle();
918 }
919
920 /*!
921  * Set point marker enabled
922  * \param theMarkerEnabled flag to enable/disable point marker
923  */
924 void SMESH_DeviceActor::SetMarkerEnabled( bool theMarkerEnabled )
925 {
926   myMapper->SetMarkerEnabled( theMarkerEnabled );
927 }
928
929 /*!
930  * Set standard point marker
931  * \param theMarkerType type of the marker
932  */
933 void SMESH_DeviceActor::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale )
934 {
935   myMapper->SetMarkerStd( theMarkerType, theMarkerScale );
936 }
937
938 /*!
939  * Set custom point marker
940  * \param theMarkerId id of the marker texture
941  * \param theMarkerTexture marker texture
942  */
943 void SMESH_DeviceActor::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
944 {
945   myMapper->SetMarkerTexture( theMarkerId, theMarkerTexture );
946 }
947
948 /*!
949  * Get type of the point marker
950  * \return type of the point marker
951  */
952 VTK::MarkerType SMESH_DeviceActor::GetMarkerType()
953 {
954   return myMapper->GetMarkerType();
955 }
956
957 /*!
958   Get scale of the point marker
959   \return scale of the point marker
960 */
961 VTK::MarkerScale SMESH_DeviceActor::GetMarkerScale()
962 {
963   return myMapper->GetMarkerScale();
964 }
965
966 /*!
967  * Get texture identifier of the point marker
968  * \return texture identifier of the point marker
969  */
970 int SMESH_DeviceActor::GetMarkerTexture()
971 {
972   return myMapper->GetMarkerTexture();
973 }