Salome HOME
Merge from V5_1_main 14/05/2010
[modules/smesh.git] / src / OBJECT / SMESH_DeviceActor.cxx
1 //  Copyright (C) 2007-2010  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_ExtractGeometry.h"
30 #include "SMESH_ControlsDef.hxx"
31 #include "SMESH_ActorUtils.h"
32 #include "SMESH_FaceOrientationFilter.h"
33 #include "VTKViewer_CellLocationsArray.h"
34 #include "VTKViewer_PolyDataMapper.h"
35
36 #include <VTKViewer_Transform.h>
37 #include <VTKViewer_TransformFilter.h>
38 #include <VTKViewer_ExtractUnstructuredGrid.h>
39
40 // VTK Includes
41 #include <vtkObjectFactory.h>
42 #include <vtkShrinkFilter.h>
43 #include <vtkShrinkPolyData.h>
44
45 #include <vtkProperty.h>
46 #include <vtkPolyData.h>
47 #include <vtkMergeFilter.h>
48 #include <vtkPolyDataMapper.h>
49 #include <vtkUnstructuredGrid.h>
50
51 #include <vtkScalarBarActor.h>
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                  vtkScalarBarActor* 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                     vtkScalarBarActor* 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     Predicate* aFreePredicate = dynamic_cast<Predicate*>(theFunctor.get());
490     myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
491     vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
492     vtkIdType aNbCells = aGrid->GetNumberOfCells();
493     for( vtkIdType i = 0; i < aNbCells; i++ ){
494       vtkIdType anObjId = myVisualObj->GetElemObjId(i);
495       if(aFreePredicate->IsSatisfy(anObjId))
496         myExtractUnstructuredGrid->RegisterCell(i);
497     }
498     if(!myExtractUnstructuredGrid->IsCellsRegistered())
499       myExtractUnstructuredGrid->RegisterCell(-1);
500     SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
501   }else if(FreeEdges* aFreeEdges = dynamic_cast<FreeEdges*>(theFunctor.get())){
502     SMESH::Controls::FreeEdges::TBorders aBorders;
503     aFreeEdges->GetBoreders(aBorders);
504     vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New();
505     vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
506     aDataSet->SetPoints(aGrid->GetPoints());
507
508     vtkIdType aNbCells = aBorders.size();
509     vtkIdType aCellsSize = 3*aNbCells;
510     vtkCellArray* aConnectivity = vtkCellArray::New();
511     aConnectivity->Allocate( aCellsSize, 0 );
512     
513     vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
514     aCellTypesArray->SetNumberOfComponents( 1 );
515     aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
516     
517     vtkIdList *anIdList = vtkIdList::New();
518     anIdList->SetNumberOfIds(2);
519     
520     FreeEdges::TBorders::const_iterator anIter = aBorders.begin();
521     for(; anIter != aBorders.end(); anIter++){
522       const FreeEdges::Border& aBorder = *anIter;
523       int aNode[2] = {
524         myVisualObj->GetNodeVTKId(aBorder.myPntId[0]),
525         myVisualObj->GetNodeVTKId(aBorder.myPntId[1])
526       };
527       //cout<<"aNode = "<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<endl;
528       if(aNode[0] >= 0 && aNode[1] >= 0){
529         anIdList->SetId( 0, aNode[0] );
530         anIdList->SetId( 1, aNode[1] );
531         aConnectivity->InsertNextCell( anIdList );
532         aCellTypesArray->InsertNextValue( VTK_LINE );
533       }
534     }
535     
536     VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
537     aCellLocationsArray->SetNumberOfComponents( 1 );
538     aCellLocationsArray->SetNumberOfTuples( aNbCells );
539     
540     aConnectivity->InitTraversal();
541     for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
542       aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
543     
544     aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
545
546     SetUnstructuredGrid(aDataSet);
547     aDataSet->Delete();
548   }else if(FreeNodes* aFreeNodes = dynamic_cast<FreeNodes*>(theFunctor.get())){
549     myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
550     vtkIdType aNbNodes = myVisualObj->GetNbEntities(SMDSAbs_Node);
551     for( vtkIdType i = 0; i < aNbNodes; i++ ){
552       vtkIdType anObjId = myVisualObj->GetNodeObjId(i);
553       if(aFreeNodes->IsSatisfy(anObjId))
554         myExtractUnstructuredGrid->RegisterCell(i);
555     }
556     if(!myExtractUnstructuredGrid->IsCellsRegistered())
557       myExtractUnstructuredGrid->RegisterCell(-1);
558     SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
559   }
560 }
561
562
563
564
565 unsigned long int 
566 SMESH_DeviceActor
567 ::GetMTime()
568 {
569   unsigned long mTime = this->Superclass::GetMTime();
570   mTime = max(mTime,myExtractGeometry->GetMTime());
571   mTime = max(mTime,myExtractUnstructuredGrid->GetMTime());
572   mTime = max(mTime,myMergeFilter->GetMTime());
573   mTime = max(mTime,myGeomFilter->GetMTime());
574   mTime = max(mTime,myTransformFilter->GetMTime());
575   mTime = max(mTime,myFaceOrientationFilter->GetMTime());
576   return mTime;
577 }
578
579
580 void
581 SMESH_DeviceActor
582 ::SetTransform(VTKViewer_Transform* theTransform)
583 {
584   myTransformFilter->SetTransform(theTransform);
585 }
586
587
588 void
589 SMESH_DeviceActor
590 ::SetShrink() 
591 {
592   if ( !myIsShrinkable ) return;
593   if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() )
594   {
595     myShrinkFilter->SetInput( aDataSet );
596     myPassFilter[ 1 ]->SetInput( myShrinkFilter->GetOutput() );
597     myIsShrunk = true;
598   }
599 }
600
601 void
602 SMESH_DeviceActor
603 ::UnShrink() 
604 {
605   if ( !myIsShrunk ) return;
606   if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() )
607   {    
608     myPassFilter[ 1 ]->SetInput( aDataSet );
609     myPassFilter[ 1 ]->Modified();
610     myIsShrunk = false;
611     Modified();
612   }
613 }
614
615
616 void
617 SMESH_DeviceActor
618 ::SetFacesOriented(bool theIsFacesOriented) 
619 {
620   if ( vtkDataSet* aDataSet = myPassFilter[ 1 ]->GetOutput() )
621   {
622     myIsFacesOriented = theIsFacesOriented;
623     if( theIsFacesOriented )
624       myFaceOrientationFilter->SetInput( aDataSet );
625     UpdateFaceOrientation();
626   }
627 }
628
629 void
630 SMESH_DeviceActor
631 ::SetFacesOrientationColor(vtkFloatingPointType theColor[3])
632 {
633   myFaceOrientation->GetProperty()->SetColor( theColor );
634 }
635
636 void
637 SMESH_DeviceActor
638 ::GetFacesOrientationColor(vtkFloatingPointType theColor[3])
639 {
640   myFaceOrientation->GetProperty()->GetColor( theColor );
641 }
642
643 void
644 SMESH_DeviceActor
645 ::SetFacesOrientationScale(vtkFloatingPointType theScale)
646 {
647   myFaceOrientationFilter->SetOrientationScale( theScale );
648 }
649
650 vtkFloatingPointType
651 SMESH_DeviceActor
652 ::GetFacesOrientationScale()
653 {
654   return myFaceOrientationFilter->GetOrientationScale();
655 }
656
657 void
658 SMESH_DeviceActor
659 ::SetFacesOrientation3DVectors(bool theState)
660 {
661   myFaceOrientationFilter->Set3dVectors( theState );
662 }
663
664 bool
665 SMESH_DeviceActor
666 ::GetFacesOrientation3DVectors()
667 {
668   return myFaceOrientationFilter->Get3dVectors();
669 }
670
671 void
672 SMESH_DeviceActor
673 ::UpdateFaceOrientation()
674 {
675   bool aShowFaceOrientation = myIsFacesOriented;
676   aShowFaceOrientation &= GetVisibility();
677   aShowFaceOrientation &= myRepresentation == eSurface;
678   myFaceOrientation->SetVisibility(aShowFaceOrientation);
679 }
680
681
682 void
683 SMESH_DeviceActor
684 ::SetRepresentation(EReperesent theMode)
685 {
686   switch(theMode){
687   case ePoint:
688     myGeomFilter->SetInside(true);
689     myGeomFilter->SetWireframeMode(false);
690     GetProperty()->SetRepresentation(0);
691     break;
692   case eWireframe:
693     myGeomFilter->SetInside(false);
694     myGeomFilter->SetWireframeMode(true);
695     GetProperty()->SetRepresentation(theMode);
696     break;
697   case eInsideframe:
698     myGeomFilter->SetInside(true);
699     myGeomFilter->SetWireframeMode(true);
700     GetProperty()->SetRepresentation(1);
701     break;
702   case eSurface:
703     myGeomFilter->SetInside(false);
704     myGeomFilter->SetWireframeMode(false);
705     GetProperty()->SetRepresentation(theMode);
706   }
707   SetMarkerEnabled(theMode == ePoint);
708   myRepresentation = theMode;
709   UpdateFaceOrientation();
710   GetProperty()->Modified();
711   myMapper->Modified();
712   Modified();
713 }
714
715
716 void
717 SMESH_DeviceActor
718 ::SetVisibility(int theMode)
719 {
720   if(!myExtractUnstructuredGrid->GetInput() || 
721      GetUnstructuredGrid()->GetNumberOfCells())
722   {
723     vtkLODActor::SetVisibility(theMode);
724   }else{
725     vtkLODActor::SetVisibility(false);
726   }
727   UpdateFaceOrientation();
728 }
729
730
731 int
732 SMESH_DeviceActor
733 ::GetVisibility()
734 {
735   if(!GetUnstructuredGrid()->GetNumberOfCells()){
736     vtkLODActor::SetVisibility(false);
737   }
738   return vtkLODActor::GetVisibility();
739 }
740
741
742 void
743 SMESH_DeviceActor
744 ::AddToRender(vtkRenderer* theRenderer)
745 {
746   theRenderer->AddActor(this);
747   theRenderer->AddActor(myFaceOrientation);
748 }
749
750 void
751 SMESH_DeviceActor
752 ::RemoveFromRender(vtkRenderer* theRenderer)
753 {
754   theRenderer->RemoveActor(this);
755   theRenderer->RemoveActor(myFaceOrientation);
756 }
757
758
759 int
760 SMESH_DeviceActor
761 ::GetNodeObjId(int theVtkID)
762 {
763   vtkIdType anID = theVtkID;
764
765   if(IsImplicitFunctionUsed())
766     anID = myExtractGeometry->GetNodeObjId(theVtkID);
767
768   vtkIdType aRetID = myVisualObj->GetNodeObjId(anID);
769   if(MYDEBUG) MESSAGE("GetNodeObjId - theVtkID = "<<theVtkID<<"; anID = "<<anID<<"; aRetID = "<<aRetID);
770   return aRetID;
771 }
772
773 vtkFloatingPointType* 
774 SMESH_DeviceActor
775 ::GetNodeCoord(int theObjID)
776 {
777   vtkDataSet* aDataSet = myMergeFilter->GetOutput();
778   vtkIdType anID = myVisualObj->GetNodeVTKId(theObjID);
779   vtkFloatingPointType* aCoord = (anID >=0) ? aDataSet->GetPoint(anID) : NULL;
780   if(MYDEBUG) MESSAGE("GetNodeCoord - theObjID = "<<theObjID<<"; anID = "<<anID);
781   return aCoord;
782 }
783
784
785 int
786 SMESH_DeviceActor
787 ::GetElemObjId(int theVtkID)
788 {
789   vtkIdType anId = myGeomFilter->GetElemObjId(theVtkID);
790   if(anId < 0) 
791     return -1;
792
793   vtkIdType anId2 = anId;
794   if(IsImplicitFunctionUsed())
795     anId2 = myExtractGeometry->GetElemObjId(anId);
796   if(anId2 < 0) 
797     return -1;
798
799   vtkIdType anId3 = myExtractUnstructuredGrid->GetInputId(anId2);
800   if(anId3 < 0) 
801     return -1;
802
803   vtkIdType aRetID = myVisualObj->GetElemObjId(anId3);
804   if(MYDEBUG) 
805      MESSAGE("GetElemObjId - theVtkID = "<<theVtkID<<"; anId2 = "<<anId2<<"; anId3 = "<<anId3<<"; aRetID = "<<aRetID);
806   return aRetID;
807 }
808
809 vtkCell* 
810 SMESH_DeviceActor
811 ::GetElemCell(int theObjID)
812 {
813   vtkDataSet* aDataSet = myVisualObj->GetUnstructuredGrid();
814   vtkIdType aGridID = myVisualObj->GetElemVTKId(theObjID);
815   vtkCell* aCell = (aGridID >= 0 ) ? aDataSet->GetCell(aGridID) : NULL;
816   if(MYDEBUG) 
817     MESSAGE("GetElemCell - theObjID = "<<theObjID<<"; aGridID = "<<aGridID);
818   return aCell;
819 }
820
821
822 vtkFloatingPointType 
823 SMESH_DeviceActor
824 ::GetShrinkFactor()
825 {
826   return myShrinkFilter->GetShrinkFactor();
827 }
828
829 void
830 SMESH_DeviceActor
831 ::SetShrinkFactor(vtkFloatingPointType theValue)
832 {
833   theValue = theValue > 0.1? theValue: 0.8;
834   myShrinkFilter->SetShrinkFactor(theValue);
835   Modified();
836 }
837
838
839 void
840 SMESH_DeviceActor
841 ::SetHighlited(bool theIsHighlited)
842 {
843   if ( myIsHighlited == theIsHighlited )
844     return;
845   myIsHighlited = theIsHighlited;
846   Modified();
847 }
848
849 void
850 SMESH_DeviceActor
851 ::Render(vtkRenderer *ren, vtkMapper* m)
852 {
853   int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology();
854   vtkFloatingPointType aStoredFactor, aStoredUnit; 
855   vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aStoredFactor,aStoredUnit);
856
857   vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
858   vtkFloatingPointType aFactor = myPolygonOffsetFactor, aUnits = myPolygonOffsetUnits;
859   if(myIsHighlited){
860     static vtkFloatingPointType EPS = .01;
861     aUnits *= (1.0-EPS);
862   }
863   vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnits);
864   vtkLODActor::Render(ren,m);
865
866   vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aStoredFactor,aStoredUnit);
867   vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology);
868 }
869
870
871 void
872 SMESH_DeviceActor
873 ::SetPolygonOffsetParameters(vtkFloatingPointType factor, 
874                              vtkFloatingPointType units)
875 {
876   myPolygonOffsetFactor = factor;
877   myPolygonOffsetUnits = units;
878 }
879
880 /*!
881  * On/Off representation 2D quadratic element as arked polygon
882  */
883 void SMESH_DeviceActor::SetQuadraticArcMode(bool theFlag){
884   myGeomFilter->SetQuadraticArcMode(theFlag);
885 }
886
887 /*!
888  * Return true if 2D quadratic element displayed as arked polygon
889  */
890 bool SMESH_DeviceActor::GetQuadraticArcMode(){
891   return myGeomFilter->GetQuadraticArcMode();
892 }
893 /*!
894  * Set Max angle for representation 2D quadratic element as arked polygon
895  */
896 void SMESH_DeviceActor::SetQuadraticArcAngle(vtkFloatingPointType theMaxAngle){
897   myGeomFilter->SetQuadraticArcAngle(theMaxAngle);
898 }
899
900 /*!
901  * Return Max angle of the representation 2D quadratic element as arked polygon
902  */
903 vtkFloatingPointType SMESH_DeviceActor::GetQuadraticArcAngle(){
904   return myGeomFilter->GetQuadraticArcAngle();
905 }
906
907 /*!
908  * Set point marker enabled
909  * \param theMarkerEnabled flag to enable/disable point marker
910  */
911 void SMESH_DeviceActor::SetMarkerEnabled( bool theMarkerEnabled )
912 {
913   myMapper->SetMarkerEnabled( theMarkerEnabled );
914 }
915
916 /*!
917  * Set standard point marker
918  * \param theMarkerType type of the marker
919  */
920 void SMESH_DeviceActor::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale )
921 {
922   myMapper->SetMarkerStd( theMarkerType, theMarkerScale );
923 }
924
925 /*!
926  * Set custom point marker
927  * \param theMarkerId id of the marker texture
928  * \param theMarkerTexture marker texture
929  */
930 void SMESH_DeviceActor::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
931 {
932   myMapper->SetMarkerTexture( theMarkerId, theMarkerTexture );
933 }
934
935 /*!
936  * Get type of the point marker
937  * \return type of the point marker
938  */
939 VTK::MarkerType SMESH_DeviceActor::GetMarkerType()
940 {
941   return myMapper->GetMarkerType();
942 }
943
944 /*!
945   Get scale of the point marker
946   \return scale of the point marker
947 */
948 VTK::MarkerScale SMESH_DeviceActor::GetMarkerScale()
949 {
950   return myMapper->GetMarkerScale();
951 }
952
953 /*!
954  * Get texture identifier of the point marker
955  * \return texture identifier of the point marker
956  */
957 int SMESH_DeviceActor::GetMarkerTexture()
958 {
959   return myMapper->GetMarkerTexture();
960 }