Version: 6.3.1

src/OBJECT/SMESH_DeviceActor.cxx

Go to the documentation of this file.
00001 // Copyright (C) 2007-2011  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     myGeomFilter->SetInput( myPassFilter[ anId ]->GetOutput() );
00244 
00245     anId++; // 2
00246     myPassFilter[ anId ]->SetInput( myGeomFilter->GetOutput() ); 
00247     myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
00248 
00249     anId++; // 3
00250     myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() );
00251 
00252     anId++; // 4
00253     myPassFilter[ anId ]->SetInput( myTransformFilter->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<OverConstrainedFace  *>(theFunctor.get()))
00493   {
00494     Predicate* aFreePredicate = dynamic_cast<Predicate*>(theFunctor.get());
00495     myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
00496     vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
00497     vtkIdType aNbCells = aGrid->GetNumberOfCells();
00498     for( vtkIdType i = 0; i < aNbCells; i++ ){
00499       vtkIdType anObjId = myVisualObj->GetElemObjId(i);
00500       if(aFreePredicate->IsSatisfy(anObjId))
00501         myExtractUnstructuredGrid->RegisterCell(i);
00502     }
00503     if(!myExtractUnstructuredGrid->IsCellsRegistered())
00504       myExtractUnstructuredGrid->RegisterCell(-1);
00505     SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
00506   }
00507   else if(FreeEdges* aFreeEdges = dynamic_cast<FreeEdges*>(theFunctor.get()))
00508   {
00509     SMESH::Controls::FreeEdges::TBorders aBorders;
00510     aFreeEdges->GetBoreders(aBorders);
00511     vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New();
00512     vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
00513     aDataSet->SetPoints(aGrid->GetPoints());
00514 
00515     vtkIdType aNbCells = aBorders.size();
00516     vtkIdType aCellsSize = 3*aNbCells;
00517     vtkCellArray* aConnectivity = vtkCellArray::New();
00518     aConnectivity->Allocate( aCellsSize, 0 );
00519     
00520     vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
00521     aCellTypesArray->SetNumberOfComponents( 1 );
00522     aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
00523     
00524     vtkIdList *anIdList = vtkIdList::New();
00525     anIdList->SetNumberOfIds(2);
00526     
00527     FreeEdges::TBorders::const_iterator anIter = aBorders.begin();
00528     for(; anIter != aBorders.end(); anIter++){
00529       const FreeEdges::Border& aBorder = *anIter;
00530       int aNode[2] = {
00531         myVisualObj->GetNodeVTKId(aBorder.myPntId[0]),
00532         myVisualObj->GetNodeVTKId(aBorder.myPntId[1])
00533       };
00534       //cout<<"aNode = "<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<endl;
00535       if(aNode[0] >= 0 && aNode[1] >= 0){
00536         anIdList->SetId( 0, aNode[0] );
00537         anIdList->SetId( 1, aNode[1] );
00538         aConnectivity->InsertNextCell( anIdList );
00539         aCellTypesArray->InsertNextValue( VTK_LINE );
00540       }
00541     }
00542     
00543     VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
00544     aCellLocationsArray->SetNumberOfComponents( 1 );
00545     aCellLocationsArray->SetNumberOfTuples( aNbCells );
00546     
00547     aConnectivity->InitTraversal();
00548     for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
00549       aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
00550     
00551     aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
00552 
00553     SetUnstructuredGrid(aDataSet);
00554     aDataSet->Delete();
00555   }
00556   else if(FreeNodes* aFreeNodes = dynamic_cast<FreeNodes*>(theFunctor.get()))
00557   {
00558     myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
00559     vtkIdType aNbNodes = myVisualObj->GetNbEntities(SMDSAbs_Node);
00560     for( vtkIdType i = 0; i < aNbNodes; i++ ){
00561       vtkIdType anObjId = myVisualObj->GetNodeObjId(i);
00562       if(aFreeNodes->IsSatisfy(anObjId))
00563         myExtractUnstructuredGrid->RegisterCell(i);
00564     }
00565     if(!myExtractUnstructuredGrid->IsCellsRegistered())
00566       myExtractUnstructuredGrid->RegisterCell(-1);
00567     SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
00568   }
00569 }
00570 
00571 
00572 
00573 
00574 unsigned long int 
00575 SMESH_DeviceActor
00576 ::GetMTime()
00577 {
00578   unsigned long mTime = this->Superclass::GetMTime();
00579   mTime = max(mTime,myExtractGeometry->GetMTime());
00580   mTime = max(mTime,myExtractUnstructuredGrid->GetMTime());
00581   mTime = max(mTime,myMergeFilter->GetMTime());
00582   mTime = max(mTime,myGeomFilter->GetMTime());
00583   mTime = max(mTime,myTransformFilter->GetMTime());
00584   mTime = max(mTime,myFaceOrientationFilter->GetMTime());
00585   return mTime;
00586 }
00587 
00588 
00589 void
00590 SMESH_DeviceActor
00591 ::SetTransform(VTKViewer_Transform* theTransform)
00592 {
00593   myTransformFilter->SetTransform(theTransform);
00594 }
00595 
00596 
00597 void
00598 SMESH_DeviceActor
00599 ::SetShrink() 
00600 {
00601   if ( !myIsShrinkable ) return;
00602   if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() )
00603   {
00604     myShrinkFilter->SetInput( aDataSet );
00605     myPassFilter[ 1 ]->SetInput( myShrinkFilter->GetOutput() );
00606     myIsShrunk = true;
00607   }
00608 }
00609 
00610 void
00611 SMESH_DeviceActor
00612 ::UnShrink() 
00613 {
00614   if ( !myIsShrunk ) return;
00615   if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() )
00616   {    
00617     myPassFilter[ 1 ]->SetInput( aDataSet );
00618     myPassFilter[ 1 ]->Modified();
00619     myIsShrunk = false;
00620     Modified();
00621   }
00622 }
00623 
00624 
00625 void
00626 SMESH_DeviceActor
00627 ::SetFacesOriented(bool theIsFacesOriented) 
00628 {
00629   if ( vtkDataSet* aDataSet = myPassFilter[ 1 ]->GetOutput() )
00630   {
00631     myIsFacesOriented = theIsFacesOriented;
00632     if( theIsFacesOriented )
00633       myFaceOrientationFilter->SetInput( aDataSet );
00634     UpdateFaceOrientation();
00635   }
00636 }
00637 
00638 void
00639 SMESH_DeviceActor
00640 ::SetFacesOrientationColor(vtkFloatingPointType theColor[3])
00641 {
00642   myFaceOrientation->GetProperty()->SetColor( theColor );
00643 }
00644 
00645 void
00646 SMESH_DeviceActor
00647 ::GetFacesOrientationColor(vtkFloatingPointType theColor[3])
00648 {
00649   myFaceOrientation->GetProperty()->GetColor( theColor );
00650 }
00651 
00652 void
00653 SMESH_DeviceActor
00654 ::SetFacesOrientationScale(vtkFloatingPointType theScale)
00655 {
00656   myFaceOrientationFilter->SetOrientationScale( theScale );
00657 }
00658 
00659 vtkFloatingPointType
00660 SMESH_DeviceActor
00661 ::GetFacesOrientationScale()
00662 {
00663   return myFaceOrientationFilter->GetOrientationScale();
00664 }
00665 
00666 void
00667 SMESH_DeviceActor
00668 ::SetFacesOrientation3DVectors(bool theState)
00669 {
00670   myFaceOrientationFilter->Set3dVectors( theState );
00671 }
00672 
00673 bool
00674 SMESH_DeviceActor
00675 ::GetFacesOrientation3DVectors()
00676 {
00677   return myFaceOrientationFilter->Get3dVectors();
00678 }
00679 
00680 void
00681 SMESH_DeviceActor
00682 ::UpdateFaceOrientation()
00683 {
00684   bool aShowFaceOrientation = myIsFacesOriented;
00685   aShowFaceOrientation &= GetVisibility();
00686   aShowFaceOrientation &= myRepresentation == eSurface;
00687   myFaceOrientation->SetVisibility(aShowFaceOrientation);
00688 }
00689 
00690 
00691 void
00692 SMESH_DeviceActor
00693 ::SetRepresentation(EReperesent theMode)
00694 {
00695   switch(theMode){
00696   case ePoint:
00697     myGeomFilter->SetInside(true);
00698     myGeomFilter->SetWireframeMode(false);
00699     GetProperty()->SetRepresentation(0);
00700     break;
00701   case eWireframe:
00702     myGeomFilter->SetInside(false);
00703     myGeomFilter->SetWireframeMode(true);
00704     GetProperty()->SetRepresentation(theMode);
00705     break;
00706   case eInsideframe:
00707     myGeomFilter->SetInside(true);
00708     myGeomFilter->SetWireframeMode(true);
00709     GetProperty()->SetRepresentation(1);
00710     break;
00711   case eSurface:
00712     myGeomFilter->SetInside(false);
00713     myGeomFilter->SetWireframeMode(false);
00714     GetProperty()->SetRepresentation(theMode);
00715   }
00716   SetMarkerEnabled(theMode == ePoint);
00717   myRepresentation = theMode;
00718   UpdateFaceOrientation();
00719   GetProperty()->Modified();
00720   myMapper->Modified();
00721   Modified();
00722 }
00723 
00724 
00725 void
00726 SMESH_DeviceActor
00727 ::SetVisibility(int theMode)
00728 {
00729   if(!myExtractUnstructuredGrid->GetInput() || 
00730      GetUnstructuredGrid()->GetNumberOfCells())
00731   {
00732     vtkLODActor::SetVisibility(theMode);
00733   }else{
00734     vtkLODActor::SetVisibility(false);
00735   }
00736   UpdateFaceOrientation();
00737 }
00738 
00739 
00740 int
00741 SMESH_DeviceActor
00742 ::GetVisibility()
00743 {
00744   if(!GetUnstructuredGrid()->GetNumberOfCells()){
00745     vtkLODActor::SetVisibility(false);
00746   }
00747   return vtkLODActor::GetVisibility();
00748 }
00749 
00750 
00751 void
00752 SMESH_DeviceActor
00753 ::AddToRender(vtkRenderer* theRenderer)
00754 {
00755   theRenderer->AddActor(this);
00756   theRenderer->AddActor(myFaceOrientation);
00757 }
00758 
00759 void
00760 SMESH_DeviceActor
00761 ::RemoveFromRender(vtkRenderer* theRenderer)
00762 {
00763   theRenderer->RemoveActor(this);
00764   theRenderer->RemoveActor(myFaceOrientation);
00765 }
00766 
00767 
00768 int
00769 SMESH_DeviceActor
00770 ::GetNodeObjId(int theVtkID)
00771 {
00772   vtkIdType anID = theVtkID;
00773 
00774   if(IsImplicitFunctionUsed())
00775     anID = myExtractGeometry->GetNodeObjId(theVtkID);
00776 
00777   vtkIdType aRetID = myVisualObj->GetNodeObjId(anID);
00778   if(MYDEBUG) MESSAGE("GetNodeObjId - theVtkID = "<<theVtkID<<"; anID = "<<anID<<"; aRetID = "<<aRetID);
00779   return aRetID;
00780 }
00781 
00782 vtkFloatingPointType* 
00783 SMESH_DeviceActor
00784 ::GetNodeCoord(int theObjID)
00785 {
00786   vtkDataSet* aDataSet = myMergeFilter->GetOutput();
00787   vtkIdType anID = myVisualObj->GetNodeVTKId(theObjID);
00788   vtkFloatingPointType* aCoord = (anID >=0) ? aDataSet->GetPoint(anID) : NULL;
00789   if(MYDEBUG) MESSAGE("GetNodeCoord - theObjID = "<<theObjID<<"; anID = "<<anID);
00790   return aCoord;
00791 }
00792 
00793 
00794 int
00795 SMESH_DeviceActor
00796 ::GetElemObjId(int theVtkID)
00797 {
00798   vtkIdType anId = myGeomFilter->GetElemObjId(theVtkID);
00799   if(anId < 0) 
00800     return -1;
00801 
00802   vtkIdType anId2 = anId;
00803   if(IsImplicitFunctionUsed())
00804     anId2 = myExtractGeometry->GetElemObjId(anId);
00805   if(anId2 < 0) 
00806     return -1;
00807 
00808   vtkIdType anId3 = myExtractUnstructuredGrid->GetInputId(anId2);
00809   if(anId3 < 0) 
00810     return -1;
00811 
00812   vtkIdType aRetID = myVisualObj->GetElemObjId(anId3);
00813   if(MYDEBUG) 
00814      MESSAGE("GetElemObjId - theVtkID = "<<theVtkID<<"; anId2 = "<<anId2<<"; anId3 = "<<anId3<<"; aRetID = "<<aRetID);
00815   return aRetID;
00816 }
00817 
00818 vtkCell* 
00819 SMESH_DeviceActor
00820 ::GetElemCell(int theObjID)
00821 {
00822   vtkDataSet* aDataSet = myVisualObj->GetUnstructuredGrid();
00823   vtkIdType aGridID = myVisualObj->GetElemVTKId(theObjID);
00824   vtkCell* aCell = (aGridID >= 0 ) ? aDataSet->GetCell(aGridID) : NULL;
00825   if(MYDEBUG) 
00826     MESSAGE("GetElemCell - theObjID = "<<theObjID<<"; aGridID = "<<aGridID);
00827   return aCell;
00828 }
00829 
00830 
00831 vtkFloatingPointType 
00832 SMESH_DeviceActor
00833 ::GetShrinkFactor()
00834 {
00835   return myShrinkFilter->GetShrinkFactor();
00836 }
00837 
00838 void
00839 SMESH_DeviceActor
00840 ::SetShrinkFactor(vtkFloatingPointType theValue)
00841 {
00842   theValue = theValue > 0.1? theValue: 0.8;
00843   myShrinkFilter->SetShrinkFactor(theValue);
00844   Modified();
00845 }
00846 
00847 
00848 void
00849 SMESH_DeviceActor
00850 ::SetHighlited(bool theIsHighlited)
00851 {
00852   if ( myIsHighlited == theIsHighlited )
00853     return;
00854   myIsHighlited = theIsHighlited;
00855   Modified();
00856 }
00857 
00858 void
00859 SMESH_DeviceActor
00860 ::Render(vtkRenderer *ren, vtkMapper* m)
00861 {
00862   int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology();
00863   vtkFloatingPointType aStoredFactor, aStoredUnit; 
00864   vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aStoredFactor,aStoredUnit);
00865 
00866   vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
00867   vtkFloatingPointType aFactor = myPolygonOffsetFactor, aUnits = myPolygonOffsetUnits;
00868   if(myIsHighlited){
00869     static vtkFloatingPointType EPS = .01;
00870     aUnits *= (1.0-EPS);
00871   }
00872   vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnits);
00873   vtkLODActor::Render(ren,m);
00874 
00875   vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aStoredFactor,aStoredUnit);
00876   vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology);
00877 }
00878 
00879 
00880 void
00881 SMESH_DeviceActor
00882 ::SetPolygonOffsetParameters(vtkFloatingPointType factor, 
00883                              vtkFloatingPointType units)
00884 {
00885   myPolygonOffsetFactor = factor;
00886   myPolygonOffsetUnits = units;
00887 }
00888 
00892 void SMESH_DeviceActor::SetQuadraticArcMode(bool theFlag){
00893   myGeomFilter->SetQuadraticArcMode(theFlag);
00894 }
00895 
00899 bool SMESH_DeviceActor::GetQuadraticArcMode(){
00900   return myGeomFilter->GetQuadraticArcMode();
00901 }
00905 void SMESH_DeviceActor::SetQuadraticArcAngle(vtkFloatingPointType theMaxAngle){
00906   myGeomFilter->SetQuadraticArcAngle(theMaxAngle);
00907 }
00908 
00912 vtkFloatingPointType SMESH_DeviceActor::GetQuadraticArcAngle(){
00913   return myGeomFilter->GetQuadraticArcAngle();
00914 }
00915 
00920 void SMESH_DeviceActor::SetMarkerEnabled( bool theMarkerEnabled )
00921 {
00922   myMapper->SetMarkerEnabled( theMarkerEnabled );
00923 }
00924 
00929 void SMESH_DeviceActor::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale )
00930 {
00931   myMapper->SetMarkerStd( theMarkerType, theMarkerScale );
00932 }
00933 
00939 void SMESH_DeviceActor::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
00940 {
00941   myMapper->SetMarkerTexture( theMarkerId, theMarkerTexture );
00942 }
00943 
00948 VTK::MarkerType SMESH_DeviceActor::GetMarkerType()
00949 {
00950   return myMapper->GetMarkerType();
00951 }
00952 
00957 VTK::MarkerScale SMESH_DeviceActor::GetMarkerScale()
00958 {
00959   return myMapper->GetMarkerScale();
00960 }
00961 
00966 int SMESH_DeviceActor::GetMarkerTexture()
00967 {
00968   return myMapper->GetMarkerTexture();
00969 }
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS