Back to index

salome-smesh  6.5.0
SMESH_DeviceActor.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SMESH OBJECT : interactive object for SMESH visualization
00024 //  File   : SMESH_DeviceActor.cxx
00025 //  Author : 
00026 //  Module : SMESH
00027 //
00028 #include "SMESH_DeviceActor.h"
00029 #include "SMESH_ScalarBarActor.h"
00030 #include "SMESH_ExtractGeometry.h"
00031 #include "SMESH_ControlsDef.hxx"
00032 #include "SMESH_ActorUtils.h"
00033 #include "SMESH_FaceOrientationFilter.h"
00034 #include "VTKViewer_CellLocationsArray.h"
00035 #include "VTKViewer_PolyDataMapper.h"
00036 
00037 #include <VTKViewer_Transform.h>
00038 #include <VTKViewer_TransformFilter.h>
00039 #include <VTKViewer_ExtractUnstructuredGrid.h>
00040 
00041 // VTK Includes
00042 #include <vtkObjectFactory.h>
00043 #include <vtkShrinkFilter.h>
00044 #include <vtkShrinkPolyData.h>
00045 
00046 #include <vtkProperty.h>
00047 #include <vtkPolyData.h>
00048 #include <vtkMergeFilter.h>
00049 #include <vtkPolyDataMapper.h>
00050 #include <vtkUnstructuredGrid.h>
00051 
00052 #include <vtkLookupTable.h>
00053 #include <vtkDoubleArray.h>
00054 #include <vtkCellData.h>
00055 
00056 #include <vtkCell.h>
00057 #include <vtkIdList.h>
00058 #include <vtkCellArray.h>
00059 #include <vtkUnsignedCharArray.h>
00060 
00061 #include <vtkImplicitBoolean.h>
00062 #include <vtkPassThroughFilter.h>
00063 
00064 #include <vtkRenderer.h>
00065 
00066 #include "utilities.h"
00067 
00068 #ifdef _DEBUG_
00069 static int MYDEBUG = 0;
00070 #else
00071 static int MYDEBUG = 0;
00072 #endif
00073 
00074 using namespace std;
00075 
00076 
00077 vtkStandardNewMacro(SMESH_DeviceActor);
00078 
00079 
00080 SMESH_DeviceActor
00081 ::SMESH_DeviceActor()
00082 {
00083   if(MYDEBUG) MESSAGE("SMESH_DeviceActor - "<<this);
00084 
00085   myIsShrinkable = false;
00086   myIsShrunk = false;
00087   myIsHighlited = false;
00088 
00089   myRepresentation = eSurface;
00090 
00091   myProperty = vtkProperty::New();
00092   myMapper = VTKViewer_PolyDataMapper::New();
00093 
00094   vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
00095                                                                  myPolygonOffsetUnits);
00096 
00097   myMapper->UseLookupTableScalarRangeOn();
00098   myMapper->SetColorModeToMapScalars();
00099 
00100   myShrinkFilter = vtkShrinkFilter::New();
00101 
00102   myStoreClippingMapping = false;
00103 
00104   myExtractGeometry = SMESH_ExtractGeometry::New();
00105   myExtractGeometry->SetReleaseDataFlag(true);
00106   myIsImplicitFunctionUsed = false;
00107 
00108   myExtractUnstructuredGrid = VTKViewer_ExtractUnstructuredGrid::New();
00109     
00110   myMergeFilter = vtkMergeFilter::New();
00111 
00112   myGeomFilter = VTKViewer_GeometryFilter::New();
00113 
00114   myTransformFilter = VTKViewer_TransformFilter::New();
00115 
00116   for(int i = 0; i < 6; i++)
00117     myPassFilter.push_back(vtkPassThroughFilter::New());
00118 
00119   // Orientation of faces
00120   myIsFacesOriented = false;
00121 
00122   vtkFloatingPointType anRGB[3] = { 1, 1, 1 };
00123   SMESH::GetColor( "SMESH", "orientation_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
00124 
00125   myFaceOrientationFilter = SMESH_FaceOrientationFilter::New();
00126 
00127   myFaceOrientationDataMapper = vtkPolyDataMapper::New();
00128   myFaceOrientationDataMapper->SetInput(myFaceOrientationFilter->GetOutput());
00129 
00130   myFaceOrientation = vtkActor::New();
00131   myFaceOrientation->SetMapper(myFaceOrientationDataMapper);
00132   myFaceOrientation->GetProperty()->SetColor(anRGB[0], anRGB[1], anRGB[2]);
00133 }
00134 
00135 
00136 SMESH_DeviceActor
00137 ::~SMESH_DeviceActor()
00138 {
00139   if(MYDEBUG) MESSAGE("~SMESH_DeviceActor - "<<this);
00140 
00141   myProperty->Delete();
00142 
00143   myMapper->Delete();
00144 
00145   myShrinkFilter->Delete();
00146 
00147   myExtractUnstructuredGrid->Delete();
00148 
00149   myMergeFilter->Delete();
00150 
00151   myGeomFilter->Delete();
00152 
00153   myExtractGeometry->Delete();
00154 
00155   myTransformFilter->Delete();
00156 
00157   for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++){
00158     myPassFilter[i]->Delete();
00159   }
00160 
00161   // Orientation of faces
00162   myFaceOrientationFilter->Delete();
00163 
00164   myFaceOrientationDataMapper->RemoveAllInputs();
00165   myFaceOrientationDataMapper->Delete();
00166 
00167   myFaceOrientation->Delete();
00168 }
00169 
00170 
00171 void
00172 SMESH_DeviceActor
00173 ::SetStoreGemetryMapping(bool theStoreMapping)
00174 {
00175   myGeomFilter->SetStoreMapping(theStoreMapping);
00176   SetStoreClippingMapping(theStoreMapping);
00177 }
00178 
00179 
00180 void
00181 SMESH_DeviceActor
00182 ::SetStoreClippingMapping(bool theStoreMapping)
00183 {
00184   myStoreClippingMapping = theStoreMapping;
00185   myExtractGeometry->SetStoreMapping(theStoreMapping && myIsImplicitFunctionUsed);
00186   SetStoreIDMapping(theStoreMapping);
00187 }
00188 
00189 
00190 void
00191 SMESH_DeviceActor
00192 ::SetStoreIDMapping(bool theStoreMapping)
00193 {
00194   myExtractUnstructuredGrid->SetStoreMapping(theStoreMapping);
00195 }
00196 
00197 
00198 void 
00199 SMESH_DeviceActor
00200 ::Init(TVisualObjPtr theVisualObj, 
00201        vtkImplicitBoolean* theImplicitBoolean)
00202 {
00203   myVisualObj = theVisualObj;
00204   myExtractGeometry->SetImplicitFunction(theImplicitBoolean);
00205   SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
00206 }
00207 
00208 
00209 void
00210 SMESH_DeviceActor
00211 ::SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
00212 {
00213   int anId = 0;
00214   if(theIsImplicitFunctionUsed)
00215     myPassFilter[ anId ]->SetInput( myExtractGeometry->GetOutput() );
00216   else
00217     myPassFilter[ anId ]->SetInput( myMergeFilter->GetOutput() );
00218     
00219   myIsImplicitFunctionUsed = theIsImplicitFunctionUsed;
00220   SetStoreClippingMapping(myStoreClippingMapping);
00221 }
00222 
00223 
00224 void
00225 SMESH_DeviceActor
00226 ::SetUnstructuredGrid(vtkUnstructuredGrid* theGrid)
00227 {
00228   if(theGrid){
00229     //myIsShrinkable = theGrid->GetNumberOfCells() > 10;
00230     myIsShrinkable = true;
00231 
00232     myExtractUnstructuredGrid->SetInput(theGrid);
00233 
00234     myMergeFilter->SetGeometry(myExtractUnstructuredGrid->GetOutput());
00235 
00236     myExtractGeometry->SetInput(myMergeFilter->GetOutput());
00237 
00238     int anId = 0;
00239     SetImplicitFunctionUsed(myIsImplicitFunctionUsed);
00240     myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() );
00241     
00242     anId++; // 1
00243     myTransformFilter->SetInput( myPassFilter[ anId ]->GetOutput() );
00244 
00245     anId++; // 2
00246     myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() );
00247     myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
00248 
00249     anId++; // 3
00250     myGeomFilter->SetInput( myPassFilter[ anId ]->GetOutput() );
00251 
00252     anId++; // 4
00253     myPassFilter[ anId ]->SetInput( myGeomFilter->GetOutput() ); 
00254     myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
00255 
00256     anId++; // 5
00257     myMapper->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() );
00258 
00259     vtkLODActor::SetMapper( myMapper );
00260     Modified();
00261   }
00262 }
00263 
00264 
00265 VTKViewer_ExtractUnstructuredGrid* 
00266 SMESH_DeviceActor
00267 ::GetExtractUnstructuredGrid()
00268 {
00269   return myExtractUnstructuredGrid;
00270 }
00271 
00272 
00273 vtkUnstructuredGrid* 
00274 SMESH_DeviceActor
00275 ::GetUnstructuredGrid()
00276 {
00277   myExtractUnstructuredGrid->Update();
00278   return myExtractUnstructuredGrid->GetOutput();
00279 }
00280 
00281 
00282 void
00283 SMESH_DeviceActor
00284 ::SetControlMode(SMESH::Controls::FunctorPtr theFunctor,
00285                  SMESH_ScalarBarActor* theScalarBarActor,
00286                  vtkLookupTable* theLookupTable)
00287 {
00288   bool anIsInitialized = theFunctor;
00289   if(anIsInitialized){
00290     vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New();
00291 
00292     SetStoreIDMapping(true);
00293     myExtractUnstructuredGrid->Update();
00294     vtkUnstructuredGrid* aGrid = myExtractUnstructuredGrid->GetOutput();
00295 
00296     aDataSet->ShallowCopy(aGrid);
00297     
00298     vtkDoubleArray *aScalars = vtkDoubleArray::New();
00299     vtkIdType aNbCells = aGrid->GetNumberOfCells();
00300     aScalars->SetNumberOfComponents(1);
00301     aScalars->SetNumberOfTuples(aNbCells);
00302     
00303     myVisualObj->UpdateFunctor(theFunctor);
00304 
00305     using namespace SMESH::Controls;
00306     if(NumericalFunctor* aNumericalFunctor = dynamic_cast<NumericalFunctor*>(theFunctor.get())){
00307       for(vtkIdType i = 0; i < aNbCells; i++){
00308         vtkIdType anId = myExtractUnstructuredGrid->GetInputId(i);
00309         vtkIdType anObjId = myVisualObj->GetElemObjId(anId);
00310         double aValue = aNumericalFunctor->GetValue(anObjId);
00311         aScalars->SetValue(i,aValue);
00312       }
00313     }else if(Predicate* aPredicate = dynamic_cast<Predicate*>(theFunctor.get())){
00314       for(vtkIdType i = 0; i < aNbCells; i++){
00315         vtkIdType anId = myExtractUnstructuredGrid->GetInputId(i);
00316         vtkIdType anObjId = myVisualObj->GetElemObjId(anId);
00317         bool aValue = aPredicate->IsSatisfy(anObjId);
00318         aScalars->SetValue(i,aValue);
00319       }
00320     }
00321 
00322     aDataSet->GetCellData()->SetScalars(aScalars);
00323     aScalars->Delete();
00324         
00325     theLookupTable->SetRange(aScalars->GetRange());
00326     theLookupTable->SetNumberOfTableValues(theScalarBarActor->GetMaximumNumberOfColors());
00327     theLookupTable->Build();
00328     
00329     myMergeFilter->SetScalars(aDataSet);
00330     aDataSet->Delete();
00331   }
00332   GetMapper()->SetScalarVisibility(anIsInitialized);
00333   theScalarBarActor->SetVisibility(anIsInitialized);
00334 }
00335 
00336 void
00337 SMESH_DeviceActor
00338 ::SetExtControlMode(SMESH::Controls::FunctorPtr theFunctor,
00339                     SMESH_ScalarBarActor* theScalarBarActor,
00340                     vtkLookupTable* theLookupTable)
00341 {
00342   bool anIsInitialized = theFunctor;
00343   myExtractUnstructuredGrid->ClearRegisteredCells();
00344   myExtractUnstructuredGrid->ClearRegisteredCellsWithType();
00345   myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::ePassAll);
00346   myVisualObj->UpdateFunctor(theFunctor);
00347 
00348   using namespace SMESH::Controls;
00349   if (anIsInitialized){
00350     if (Length2D* aLength2D = dynamic_cast<Length2D*>(theFunctor.get())){
00351       SMESH::Controls::Length2D::TValues aValues;
00352 
00353       aLength2D->GetValues(aValues);
00354       vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New();
00355       vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
00356 
00357       aDataSet->SetPoints(aGrid->GetPoints());
00358       
00359       vtkIdType aNbCells = aValues.size();
00360       
00361       vtkDoubleArray *aScalars = vtkDoubleArray::New();
00362       aScalars->SetNumberOfComponents(1);
00363       aScalars->SetNumberOfTuples(aNbCells);
00364 
00365       vtkIdType aCellsSize = 3*aNbCells;
00366       vtkCellArray* aConnectivity = vtkCellArray::New();
00367       aConnectivity->Allocate( aCellsSize, 0 );
00368       
00369       vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
00370       aCellTypesArray->SetNumberOfComponents( 1 );
00371       aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
00372       
00373       vtkIdList *anIdList = vtkIdList::New();
00374       anIdList->SetNumberOfIds(2);
00375       
00376       Length2D::TValues::const_iterator anIter = aValues.begin();
00377       for(vtkIdType aVtkId = 0; anIter != aValues.end(); anIter++,aVtkId++){
00378         const Length2D::Value& aValue = *anIter;
00379         int aNode[2] = {
00380           myVisualObj->GetNodeVTKId(aValue.myPntId[0]),
00381           myVisualObj->GetNodeVTKId(aValue.myPntId[1])
00382         };
00383         if(aNode[0] >= 0 && aNode[1] >= 0){
00384           anIdList->SetId( 0, aNode[0] );
00385           anIdList->SetId( 1, aNode[1] );
00386           aConnectivity->InsertNextCell( anIdList );
00387           aCellTypesArray->InsertNextValue( VTK_LINE );
00388           aScalars->SetValue(aVtkId,aValue.myLength);
00389         }
00390       }
00391       
00392       VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
00393       aCellLocationsArray->SetNumberOfComponents( 1 );
00394       aCellLocationsArray->SetNumberOfTuples( aNbCells );
00395       
00396       aConnectivity->InitTraversal();
00397       for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
00398         aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
00399       
00400       aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
00401       SetUnstructuredGrid(aDataSet);
00402 
00403       aDataSet->GetCellData()->SetScalars(aScalars);
00404       aScalars->Delete();
00405       
00406       theLookupTable->SetRange(aScalars->GetRange());
00407       theLookupTable->Build();
00408       
00409       myMergeFilter->SetScalars(aDataSet);
00410       aDataSet->Delete();
00411     }
00412     else if (MultiConnection2D* aMultiConnection2D = dynamic_cast<MultiConnection2D*>(theFunctor.get())){
00413       SMESH::Controls::MultiConnection2D::MValues aValues;
00414 
00415       aMultiConnection2D->GetValues(aValues);
00416       vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New();
00417       vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
00418       aDataSet->SetPoints(aGrid->GetPoints());
00419       
00420       vtkIdType aNbCells = aValues.size();
00421       vtkDoubleArray *aScalars = vtkDoubleArray::New();
00422       aScalars->SetNumberOfComponents(1);
00423       aScalars->SetNumberOfTuples(aNbCells);
00424 
00425       vtkIdType aCellsSize = 3*aNbCells;
00426       vtkCellArray* aConnectivity = vtkCellArray::New();
00427       aConnectivity->Allocate( aCellsSize, 0 );
00428       
00429       vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
00430       aCellTypesArray->SetNumberOfComponents( 1 );
00431       aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
00432       
00433       vtkIdList *anIdList = vtkIdList::New();
00434       anIdList->SetNumberOfIds(2);
00435       
00436       MultiConnection2D::MValues::const_iterator anIter = aValues.begin();
00437       for(vtkIdType aVtkId = 0; anIter != aValues.end(); anIter++,aVtkId++){
00438         const MultiConnection2D::Value& aValue = (*anIter).first;
00439         int aNode[2] = {
00440           myVisualObj->GetNodeVTKId(aValue.myPntId[0]),
00441           myVisualObj->GetNodeVTKId(aValue.myPntId[1])
00442         };
00443         if(aNode[0] >= 0 && aNode[1] >= 0){
00444           anIdList->SetId( 0, aNode[0] );
00445           anIdList->SetId( 1, aNode[1] );
00446           aConnectivity->InsertNextCell( anIdList );
00447           aCellTypesArray->InsertNextValue( VTK_LINE );
00448           aScalars->SetValue(aVtkId,(*anIter).second);
00449         }
00450       }
00451       
00452       VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
00453       aCellLocationsArray->SetNumberOfComponents( 1 );
00454       aCellLocationsArray->SetNumberOfTuples( aNbCells );
00455       
00456       aConnectivity->InitTraversal();
00457       for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
00458         aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
00459       
00460       aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
00461       SetUnstructuredGrid(aDataSet);
00462 
00463       aDataSet->GetCellData()->SetScalars(aScalars);
00464       aScalars->Delete();
00465       
00466       theLookupTable->SetRange(aScalars->GetRange());
00467       theLookupTable->Build();
00468       
00469       myMergeFilter->SetScalars(aDataSet);
00470       aDataSet->Delete();
00471     }
00472   }
00473   GetMapper()->SetScalarVisibility(anIsInitialized);
00474   theScalarBarActor->SetVisibility(anIsInitialized);
00475 }
00476 
00477 void
00478 SMESH_DeviceActor
00479 ::SetExtControlMode(SMESH::Controls::FunctorPtr theFunctor)
00480 {
00481   myExtractUnstructuredGrid->ClearRegisteredCells();
00482   myExtractUnstructuredGrid->ClearRegisteredCellsWithType();
00483   myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::ePassAll);
00484   myVisualObj->UpdateFunctor(theFunctor);
00485 
00486   using namespace SMESH::Controls;
00487   if ( dynamic_cast<FreeBorders          *>(theFunctor.get()) ||
00488        dynamic_cast<FreeFaces            *>(theFunctor.get()) ||
00489        dynamic_cast<BareBorderVolume     *>(theFunctor.get()) ||
00490        dynamic_cast<BareBorderFace       *>(theFunctor.get()) ||
00491        dynamic_cast<OverConstrainedVolume*>(theFunctor.get()) ||
00492        dynamic_cast<CoincidentElements1D *>(theFunctor.get()) ||
00493        dynamic_cast<CoincidentElements2D *>(theFunctor.get()) ||
00494        dynamic_cast<CoincidentElements3D *>(theFunctor.get()) ||
00495        dynamic_cast<OverConstrainedFace  *>(theFunctor.get()))
00496   {
00497     Predicate* aPredicate = dynamic_cast<Predicate*>(theFunctor.get());
00498     myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
00499     vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
00500     vtkIdType aNbCells = aGrid->GetNumberOfCells();
00501     for( vtkIdType i = 0; i < aNbCells; i++ ){
00502       vtkIdType anObjId = myVisualObj->GetElemObjId(i);
00503       if(aPredicate->IsSatisfy(anObjId))
00504         myExtractUnstructuredGrid->RegisterCell(i);
00505     }
00506     if(!myExtractUnstructuredGrid->IsCellsRegistered())
00507       myExtractUnstructuredGrid->RegisterCell(-1);
00508     SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
00509   }
00510   else if(FreeEdges* aFreeEdges = dynamic_cast<FreeEdges*>(theFunctor.get()))
00511   {
00512     SMESH::Controls::FreeEdges::TBorders aBorders;
00513     aFreeEdges->GetBoreders(aBorders);
00514     vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New();
00515     vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
00516     aDataSet->SetPoints(aGrid->GetPoints());
00517 
00518     vtkIdType aNbCells = aBorders.size();
00519     vtkIdType aCellsSize = 3*aNbCells;
00520     vtkCellArray* aConnectivity = vtkCellArray::New();
00521     aConnectivity->Allocate( aCellsSize, 0 );
00522     
00523     vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
00524     aCellTypesArray->SetNumberOfComponents( 1 );
00525     aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
00526     
00527     vtkIdList *anIdList = vtkIdList::New();
00528     anIdList->SetNumberOfIds(2);
00529     
00530     FreeEdges::TBorders::const_iterator anIter = aBorders.begin();
00531     for(; anIter != aBorders.end(); anIter++){
00532       const FreeEdges::Border& aBorder = *anIter;
00533       int aNode[2] = {
00534         myVisualObj->GetNodeVTKId(aBorder.myPntId[0]),
00535         myVisualObj->GetNodeVTKId(aBorder.myPntId[1])
00536       };
00537       //cout<<"aNode = "<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<endl;
00538       if(aNode[0] >= 0 && aNode[1] >= 0){
00539         anIdList->SetId( 0, aNode[0] );
00540         anIdList->SetId( 1, aNode[1] );
00541         aConnectivity->InsertNextCell( anIdList );
00542         aCellTypesArray->InsertNextValue( VTK_LINE );
00543       }
00544     }
00545     
00546     VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
00547     aCellLocationsArray->SetNumberOfComponents( 1 );
00548     aCellLocationsArray->SetNumberOfTuples( aNbCells );
00549     
00550     aConnectivity->InitTraversal();
00551     for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
00552       aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
00553     
00554     aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
00555 
00556     SetUnstructuredGrid(aDataSet);
00557     aDataSet->Delete();
00558   }
00559   else if(dynamic_cast<FreeNodes      *>(theFunctor.get()) ||
00560           dynamic_cast<CoincidentNodes*>(theFunctor.get()))
00561   {
00562     Predicate* aPredicate = dynamic_cast<Predicate*>(theFunctor.get());
00563     myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
00564     vtkIdType aNbNodes = myVisualObj->GetNbEntities(SMDSAbs_Node);
00565     for( vtkIdType i = 0; i < aNbNodes; i++ ){
00566       vtkIdType anObjId = myVisualObj->GetNodeObjId(i);
00567       if(aPredicate->IsSatisfy(anObjId))
00568         myExtractUnstructuredGrid->RegisterCell(i);
00569     }
00570     if(!myExtractUnstructuredGrid->IsCellsRegistered())
00571       myExtractUnstructuredGrid->RegisterCell(-1);
00572     SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
00573   }
00574 }
00575 
00576 
00577 
00578 
00579 unsigned long int 
00580 SMESH_DeviceActor
00581 ::GetMTime()
00582 {
00583   unsigned long mTime = this->Superclass::GetMTime();
00584   mTime = max(mTime,myExtractGeometry->GetMTime());
00585   mTime = max(mTime,myExtractUnstructuredGrid->GetMTime());
00586   mTime = max(mTime,myMergeFilter->GetMTime());
00587   mTime = max(mTime,myGeomFilter->GetMTime());
00588   mTime = max(mTime,myTransformFilter->GetMTime());
00589   mTime = max(mTime,myFaceOrientationFilter->GetMTime());
00590   return mTime;
00591 }
00592 
00593 
00594 void
00595 SMESH_DeviceActor
00596 ::SetTransform(VTKViewer_Transform* theTransform)
00597 {
00598   myTransformFilter->SetTransform(theTransform);
00599 }
00600 
00601 
00602 void
00603 SMESH_DeviceActor
00604 ::SetShrink() 
00605 {
00606   if ( !myIsShrinkable ) return;
00607   if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() )
00608   {
00609     myShrinkFilter->SetInput( aDataSet );
00610     myPassFilter[ 1 ]->SetInput( myShrinkFilter->GetOutput() );
00611     myIsShrunk = true;
00612   }
00613 }
00614 
00615 void
00616 SMESH_DeviceActor
00617 ::UnShrink() 
00618 {
00619   if ( !myIsShrunk ) return;
00620   if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() )
00621   {    
00622     myPassFilter[ 1 ]->SetInput( aDataSet );
00623     myPassFilter[ 1 ]->Modified();
00624     myIsShrunk = false;
00625     Modified();
00626   }
00627 }
00628 
00629 
00630 void
00631 SMESH_DeviceActor
00632 ::SetFacesOriented(bool theIsFacesOriented) 
00633 {
00634   if ( vtkDataSet* aDataSet = myTransformFilter->GetOutput() )
00635   {
00636     myIsFacesOriented = theIsFacesOriented;
00637     if( theIsFacesOriented )
00638       myFaceOrientationFilter->SetInput( aDataSet );
00639     UpdateFaceOrientation();
00640   }
00641 }
00642 
00643 void
00644 SMESH_DeviceActor
00645 ::SetFacesOrientationColor(vtkFloatingPointType theColor[3])
00646 {
00647   myFaceOrientation->GetProperty()->SetColor( theColor );
00648 }
00649 
00650 void
00651 SMESH_DeviceActor
00652 ::GetFacesOrientationColor(vtkFloatingPointType theColor[3])
00653 {
00654   myFaceOrientation->GetProperty()->GetColor( theColor );
00655 }
00656 
00657 void
00658 SMESH_DeviceActor
00659 ::SetFacesOrientationScale(vtkFloatingPointType theScale)
00660 {
00661   myFaceOrientationFilter->SetOrientationScale( theScale );
00662 }
00663 
00664 vtkFloatingPointType
00665 SMESH_DeviceActor
00666 ::GetFacesOrientationScale()
00667 {
00668   return myFaceOrientationFilter->GetOrientationScale();
00669 }
00670 
00671 void
00672 SMESH_DeviceActor
00673 ::SetFacesOrientation3DVectors(bool theState)
00674 {
00675   myFaceOrientationFilter->Set3dVectors( theState );
00676 }
00677 
00678 bool
00679 SMESH_DeviceActor
00680 ::GetFacesOrientation3DVectors()
00681 {
00682   return myFaceOrientationFilter->Get3dVectors();
00683 }
00684 
00685 void
00686 SMESH_DeviceActor
00687 ::UpdateFaceOrientation()
00688 {
00689   bool aShowFaceOrientation = myIsFacesOriented;
00690   aShowFaceOrientation &= GetVisibility();
00691   aShowFaceOrientation &= myRepresentation == eSurface;
00692   myFaceOrientation->SetVisibility(aShowFaceOrientation);
00693 }
00694 
00695 
00696 void
00697 SMESH_DeviceActor
00698 ::SetRepresentation(EReperesent theMode)
00699 {
00700   switch(theMode){
00701   case ePoint:
00702     myGeomFilter->SetInside(true);
00703     myGeomFilter->SetWireframeMode(false);
00704     GetProperty()->SetRepresentation(0);
00705     break;
00706   case eWireframe:
00707     myGeomFilter->SetInside(false);
00708     myGeomFilter->SetWireframeMode(true);
00709     GetProperty()->SetRepresentation(theMode);
00710     break;
00711   case eInsideframe:
00712     myGeomFilter->SetInside(true);
00713     myGeomFilter->SetWireframeMode(true);
00714     GetProperty()->SetRepresentation(1);
00715     break;
00716   case eSurface:
00717     myGeomFilter->SetInside(false);
00718     myGeomFilter->SetWireframeMode(false);
00719     GetProperty()->SetRepresentation(theMode);
00720   }
00721   SetMarkerEnabled(theMode == ePoint);
00722   myRepresentation = theMode;
00723   UpdateFaceOrientation();
00724   GetProperty()->Modified();
00725   myMapper->Modified();
00726   Modified();
00727 }
00728 
00729 
00730 void
00731 SMESH_DeviceActor
00732 ::SetVisibility(int theMode)
00733 {
00734   if(!myExtractUnstructuredGrid->GetInput() || 
00735      GetUnstructuredGrid()->GetNumberOfCells())
00736   {
00737     vtkLODActor::SetVisibility(theMode);
00738   }else{
00739     vtkLODActor::SetVisibility(false);
00740   }
00741   UpdateFaceOrientation();
00742 }
00743 
00744 
00745 int
00746 SMESH_DeviceActor
00747 ::GetVisibility()
00748 {
00749   if(!GetUnstructuredGrid()->GetNumberOfCells()){
00750     vtkLODActor::SetVisibility(false);
00751   }
00752   return vtkLODActor::GetVisibility();
00753 }
00754 
00755 
00756 void
00757 SMESH_DeviceActor
00758 ::AddToRender(vtkRenderer* theRenderer)
00759 {
00760   theRenderer->AddActor(this);
00761   theRenderer->AddActor(myFaceOrientation);
00762 }
00763 
00764 void
00765 SMESH_DeviceActor
00766 ::RemoveFromRender(vtkRenderer* theRenderer)
00767 {
00768   theRenderer->RemoveActor(this);
00769   theRenderer->RemoveActor(myFaceOrientation);
00770 }
00771 
00772 
00773 int
00774 SMESH_DeviceActor
00775 ::GetNodeObjId(int theVtkID)
00776 {
00777   vtkIdType anID = theVtkID;
00778 
00779   if(IsImplicitFunctionUsed())
00780     anID = myExtractGeometry->GetNodeObjId(theVtkID);
00781 
00782   vtkIdType aRetID = myVisualObj->GetNodeObjId(anID);
00783   if(MYDEBUG) MESSAGE("GetNodeObjId - theVtkID = "<<theVtkID<<"; anID = "<<anID<<"; aRetID = "<<aRetID);
00784   return aRetID;
00785 }
00786 
00787 vtkFloatingPointType* 
00788 SMESH_DeviceActor
00789 ::GetNodeCoord(int theObjID)
00790 {
00791   vtkDataSet* aDataSet = myMergeFilter->GetOutput();
00792   vtkIdType anID = myVisualObj->GetNodeVTKId(theObjID);
00793   vtkFloatingPointType* aCoord = (anID >=0) ? aDataSet->GetPoint(anID) : NULL;
00794   if(MYDEBUG) MESSAGE("GetNodeCoord - theObjID = "<<theObjID<<"; anID = "<<anID);
00795   return aCoord;
00796 }
00797 
00798 
00799 int
00800 SMESH_DeviceActor
00801 ::GetElemObjId(int theVtkID)
00802 {
00803   vtkIdType anId = myGeomFilter->GetElemObjId(theVtkID);
00804   if(anId < 0) 
00805     return -1;
00806 
00807   vtkIdType anId2 = anId;
00808   if(IsImplicitFunctionUsed())
00809     anId2 = myExtractGeometry->GetElemObjId(anId);
00810   if(anId2 < 0) 
00811     return -1;
00812 
00813   vtkIdType anId3 = myExtractUnstructuredGrid->GetInputId(anId2);
00814   if(anId3 < 0) 
00815     return -1;
00816 
00817   vtkIdType aRetID = myVisualObj->GetElemObjId(anId3);
00818   if(MYDEBUG) 
00819      MESSAGE("GetElemObjId - theVtkID = "<<theVtkID<<"; anId2 = "<<anId2<<"; anId3 = "<<anId3<<"; aRetID = "<<aRetID);
00820   return aRetID;
00821 }
00822 
00823 vtkCell* 
00824 SMESH_DeviceActor
00825 ::GetElemCell(int theObjID)
00826 {
00827   vtkDataSet* aDataSet = myVisualObj->GetUnstructuredGrid();
00828   vtkIdType aGridID = myVisualObj->GetElemVTKId(theObjID);
00829   vtkCell* aCell = (aGridID >= 0 ) ? aDataSet->GetCell(aGridID) : NULL;
00830   if(MYDEBUG) 
00831     MESSAGE("GetElemCell - theObjID = "<<theObjID<<"; aGridID = "<<aGridID);
00832   return aCell;
00833 }
00834 
00835 
00836 vtkFloatingPointType 
00837 SMESH_DeviceActor
00838 ::GetShrinkFactor()
00839 {
00840   return myShrinkFilter->GetShrinkFactor();
00841 }
00842 
00843 void
00844 SMESH_DeviceActor
00845 ::SetShrinkFactor(vtkFloatingPointType theValue)
00846 {
00847   theValue = theValue > 0.1? theValue: 0.8;
00848   myShrinkFilter->SetShrinkFactor(theValue);
00849   Modified();
00850 }
00851 
00852 
00853 void
00854 SMESH_DeviceActor
00855 ::SetHighlited(bool theIsHighlited)
00856 {
00857   if ( myIsHighlited == theIsHighlited )
00858     return;
00859   myIsHighlited = theIsHighlited;
00860   Modified();
00861 }
00862 
00863 void
00864 SMESH_DeviceActor
00865 ::Render(vtkRenderer *ren, vtkMapper* m)
00866 {
00867   int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology();
00868   vtkFloatingPointType aStoredFactor, aStoredUnit; 
00869   vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aStoredFactor,aStoredUnit);
00870 
00871   vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
00872   vtkFloatingPointType aFactor = myPolygonOffsetFactor, aUnits = myPolygonOffsetUnits;
00873   if(myIsHighlited){
00874     static vtkFloatingPointType EPS = .01;
00875     aUnits *= (1.0-EPS);
00876   }
00877   vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnits);
00878   vtkLODActor::Render(ren,m);
00879 
00880   vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aStoredFactor,aStoredUnit);
00881   vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology);
00882 }
00883 
00884 
00885 void
00886 SMESH_DeviceActor
00887 ::SetPolygonOffsetParameters(vtkFloatingPointType factor, 
00888                              vtkFloatingPointType units)
00889 {
00890   myPolygonOffsetFactor = factor;
00891   myPolygonOffsetUnits = units;
00892 }
00893 
00897 void SMESH_DeviceActor::SetQuadraticArcMode(bool theFlag){
00898   myGeomFilter->SetQuadraticArcMode(theFlag);
00899 }
00900 
00904 bool SMESH_DeviceActor::GetQuadraticArcMode(){
00905   return myGeomFilter->GetQuadraticArcMode();
00906 }
00910 void SMESH_DeviceActor::SetQuadraticArcAngle(vtkFloatingPointType theMaxAngle){
00911   myGeomFilter->SetQuadraticArcAngle(theMaxAngle);
00912 }
00913 
00917 vtkFloatingPointType SMESH_DeviceActor::GetQuadraticArcAngle(){
00918   return myGeomFilter->GetQuadraticArcAngle();
00919 }
00920 
00925 void SMESH_DeviceActor::SetMarkerEnabled( bool theMarkerEnabled )
00926 {
00927   myMapper->SetMarkerEnabled( theMarkerEnabled );
00928 }
00929 
00934 void SMESH_DeviceActor::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale )
00935 {
00936   myMapper->SetMarkerStd( theMarkerType, theMarkerScale );
00937 }
00938 
00944 void SMESH_DeviceActor::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
00945 {
00946   myMapper->SetMarkerTexture( theMarkerId, theMarkerTexture );
00947 }
00948 
00953 VTK::MarkerType SMESH_DeviceActor::GetMarkerType()
00954 {
00955   return myMapper->GetMarkerType();
00956 }
00957 
00962 VTK::MarkerScale SMESH_DeviceActor::GetMarkerScale()
00963 {
00964   return myMapper->GetMarkerScale();
00965 }
00966 
00971 int SMESH_DeviceActor::GetMarkerTexture()
00972 {
00973   return myMapper->GetMarkerTexture();
00974 }
00975 
00976 void SMESH_DeviceActor::SetCoincident3DAllowed(bool theFlag) {
00977   myGeomFilter->SetAppendCoincident3D(theFlag);
00978 }
00979 
00980 bool SMESH_DeviceActor::IsCoincident3DAllowed() const {
00981   return myGeomFilter->GetAppendCoincident3D();
00982 }