Back to index

salome-gui  6.5.0
SVTK_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 //  SVTK OBJECT : interactive object for SVTK visualization
00024 //  File   : SVTK_DeviceActor.cxx
00025 //  Author : 
00026 
00027 #include "SVTK_DeviceActor.h"
00028 
00029 #include "VTKViewer_Transform.h"
00030 #include "VTKViewer_TransformFilter.h"
00031 #include "VTKViewer_GeometryFilter.h"
00032 
00033 // VTK Includes
00034 #include <vtkObjectFactory.h>
00035 #include <vtkShrinkFilter.h>
00036 #include <vtkFeatureEdges.h>
00037 
00038 #include <vtkPolyData.h>
00039 #include <vtkUnstructuredGrid.h>
00040 
00041 #include <VTKViewer_PolyDataMapper.h>
00042 #include <VTKViewer_DataSetMapper.h>
00043 
00044 #include <vtkPassThroughFilter.h>
00045 
00046 vtkStandardNewMacro(SVTK_DeviceActor);
00047 
00051 SVTK_DeviceActor
00052 ::SVTK_DeviceActor()
00053 {
00054   myIsShrunk = false;
00055   myIsShrinkable = true;
00056 
00057   myIsFeatureEdgesAllowed = false;
00058   myIsFeatureEdgesEnabled = false;
00059 
00060   myIsShaded = true;
00061   myProperty = vtkProperty::New();
00062   myRepresentation = VTKViewer::Representation::Surface;
00063 
00064   myIsResolveCoincidentTopology = true;
00065   vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
00066                                                                  myPolygonOffsetUnits);
00067 
00068   myMapper = VTKViewer_DataSetMapper::New();
00069 
00070   myShrinkFilter = vtkShrinkFilter::New();
00071 
00072   myFeatureEdges = vtkFeatureEdges::New();
00073 
00074   myGeomFilter = VTKViewer_GeometryFilter::New();
00075 
00076   myTransformFilter = VTKViewer_TransformFilter::New();
00077 
00078   for(int i = 0; i < 6; i++)
00079     myPassFilter.push_back(vtkPassThroughFilter::New());
00080 }
00081 
00085 SVTK_DeviceActor
00086 ::~SVTK_DeviceActor()
00087 {
00088   myMapper->Delete();
00089 
00090   myProperty->Delete();
00091 
00092   myGeomFilter->Delete();
00093 
00094   myTransformFilter->Delete();
00095 
00096   myShrinkFilter->Delete();
00097 
00098   myFeatureEdges->Delete();
00099 
00100   for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++)
00101     myPassFilter[i]->Delete();
00102 }
00103 
00107 void
00108 SVTK_DeviceActor
00109 ::SetMapper(vtkMapper* theMapper)
00110 {
00111   InitPipeLine(theMapper);
00112 }
00113 
00117 void
00118 SVTK_DeviceActor
00119 ::InitPipeLine(vtkMapper* theMapper)
00120 {
00121   if(theMapper){
00122     int anId = 0;
00123     myPassFilter[ anId ]->SetInput( theMapper->GetInput() );
00124     myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() );
00125     
00126     anId++; // 1
00127     myGeomFilter->SetInput( myPassFilter[ anId ]->GetOutput() );
00128 
00129     anId++; // 2
00130     myPassFilter[ anId ]->SetInput( myGeomFilter->GetOutput() ); 
00131     myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
00132 
00133     anId++; // 3
00134     myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() );
00135 
00136     anId++; // 4
00137     myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() );
00138     myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
00139 
00140     anId++; // 5
00141     if(VTKViewer_DataSetMapper* aMapper = dynamic_cast<VTKViewer_DataSetMapper*>(theMapper)){
00142       aMapper->SetInput(myPassFilter[anId]->GetOutput());
00143     }else if(VTKViewer_PolyDataMapper* aMapper = dynamic_cast<VTKViewer_PolyDataMapper*>(theMapper)){
00144       aMapper->SetInput(myPassFilter[anId]->GetPolyDataOutput());
00145     }
00146   }
00147   Superclass::SetMapper(theMapper);
00148 }
00149 
00153 vtkDataSet* 
00154 SVTK_DeviceActor
00155 ::GetInput()
00156 {
00157   return myPassFilter.front()->GetOutput();
00158 }
00159 
00163 void
00164 SVTK_DeviceActor
00165 ::SetInput(vtkDataSet* theDataSet)
00166 {
00167   myMapper->SetInput(theDataSet);
00168   InitPipeLine(myMapper);
00169 }
00170 
00174 void
00175 SVTK_DeviceActor::
00176 SetStoreMapping(bool theStoreMapping)
00177 {
00178   myGeomFilter->SetStoreMapping(theStoreMapping);
00179 }
00180 
00181 
00185 unsigned long int 
00186 SVTK_DeviceActor
00187 ::GetMTime()
00188 {
00189   unsigned long mTime = this->Superclass::GetMTime();
00190 
00191   mTime = std::max(mTime,myGeomFilter->GetMTime());
00192 
00193   mTime = std::max(mTime,myTransformFilter->GetMTime());
00194 
00195   if(myIsShrunk)
00196     mTime = std::max(mTime,myShrinkFilter->GetMTime());
00197 
00198   if(myIsFeatureEdgesEnabled)
00199     mTime = std::max(mTime,myFeatureEdges->GetMTime());
00200 
00201   for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++)
00202     std::max(mTime,myPassFilter[i]->GetMTime());
00203 
00204   return mTime;
00205 }
00206 
00211 void 
00212 SVTK_DeviceActor
00213 ::SetTransform(VTKViewer_Transform* theTransform)
00214 {
00215   myTransformFilter->SetTransform(theTransform);
00216 }
00217 
00221 bool
00222 SVTK_DeviceActor
00223 ::IsShrunkable() 
00224 { 
00225   return myIsShrinkable;
00226 }
00227 
00232 void
00233 SVTK_DeviceActor
00234 ::SetShrinkable(bool theIsShrinkable) 
00235 { 
00236   myIsShrinkable = theIsShrinkable;
00237 }
00238   
00242 bool
00243 SVTK_DeviceActor
00244 ::IsShrunk() 
00245 { 
00246   return myIsShrunk;
00247 }
00248 
00252 void
00253 SVTK_DeviceActor
00254 ::SetShrink() 
00255 {
00256   if ( !myIsShrinkable ) 
00257     return;
00258   
00259   if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() )
00260   {     
00261     aDataSet->Update();
00262     int numCells=aDataSet->GetNumberOfCells();
00263     int numPts = aDataSet->GetNumberOfPoints();
00264     //It's impossible to use to apply "shrink" for "empty" dataset
00265     if (numCells < 1 || numPts < 1)
00266             return;
00267     myShrinkFilter->SetInput( aDataSet );
00268     myPassFilter[ 1 ]->SetInput( myShrinkFilter->GetOutput() );
00269     myIsShrunk = true;
00270   }
00271 }
00272 
00276 void 
00277 SVTK_DeviceActor
00278 ::UnShrink() 
00279 {
00280   if ( !myIsShrunk ) return;
00281   if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() )
00282   {    
00283     myPassFilter[ 1 ]->SetInput( aDataSet );
00284     myIsShrunk = false;
00285   }
00286 }
00287 
00291 vtkFloatingPointType
00292 SVTK_DeviceActor
00293 ::GetShrinkFactor()
00294 {
00295   return myShrinkFilter->GetShrinkFactor();
00296 }
00297 
00302 void 
00303 SVTK_DeviceActor
00304 ::SetShrinkFactor(vtkFloatingPointType theValue)
00305 {
00306   myShrinkFilter->SetShrinkFactor(theValue);
00307 }
00308 
00312 bool
00313 SVTK_DeviceActor
00314 ::IsFeatureEdgesAllowed() 
00315 { 
00316   return myIsFeatureEdgesAllowed;
00317 }
00318 
00323 void
00324 SVTK_DeviceActor
00325 ::SetFeatureEdgesAllowed(bool theIsFeatureEdgesAllowed)
00326 {
00327   myIsFeatureEdgesAllowed = theIsFeatureEdgesAllowed;
00328 }
00329 
00333 bool
00334 SVTK_DeviceActor
00335 ::IsFeatureEdgesEnabled()
00336 {
00337   return myIsFeatureEdgesEnabled;
00338 }
00339 
00344 void
00345 SVTK_DeviceActor
00346 ::SetFeatureEdgesEnabled(bool theIsFeatureEdgesEnabled)
00347 {
00348   if ( !myIsFeatureEdgesAllowed || myIsFeatureEdgesEnabled == theIsFeatureEdgesEnabled ) 
00349     return;
00350 
00351   if ( vtkPolyData* aPolyData = myPassFilter[ 2 ]->GetPolyDataOutput() )
00352   {
00353     if( theIsFeatureEdgesEnabled )
00354     {
00355       aPolyData->Update();
00356       myFeatureEdges->SetInput( aPolyData );
00357       myPassFilter[ 3 ]->SetInput( myFeatureEdges->GetOutput() );
00358       myIsFeatureEdgesEnabled = true;
00359     }
00360     else
00361     {
00362       myPassFilter[3]->SetInput( aPolyData );
00363       myIsFeatureEdgesEnabled = false;
00364     }
00365     myIsFeatureEdgesEnabled = theIsFeatureEdgesEnabled;
00366   }
00367 }
00368 
00372 vtkFloatingPointType
00373 SVTK_DeviceActor
00374 ::GetFeatureEdgesAngle()
00375 {
00376   return myFeatureEdges->GetFeatureAngle();
00377 }
00378 
00383 void
00384 SVTK_DeviceActor
00385 ::SetFeatureEdgesAngle(vtkFloatingPointType theAngle)
00386 {
00387   myFeatureEdges->SetFeatureAngle(theAngle);
00388 }
00389 
00397 void
00398 SVTK_DeviceActor
00399 ::GetFeatureEdgesFlags(bool& theIsFeatureEdges,
00400                        bool& theIsBoundaryEdges,
00401                        bool& theIsManifoldEdges,
00402                        bool& theIsNonManifoldEdges)
00403 {
00404   theIsFeatureEdges = myFeatureEdges->GetFeatureEdges();
00405   theIsBoundaryEdges = myFeatureEdges->GetBoundaryEdges();
00406   theIsManifoldEdges = myFeatureEdges->GetManifoldEdges();
00407   theIsNonManifoldEdges = myFeatureEdges->GetNonManifoldEdges();
00408 }
00409 
00417 void
00418 SVTK_DeviceActor
00419 ::SetFeatureEdgesFlags(bool theIsFeatureEdges,
00420                        bool theIsBoundaryEdges,
00421                        bool theIsManifoldEdges,
00422                        bool theIsNonManifoldEdges)
00423 {
00424   myFeatureEdges->SetFeatureEdges(theIsFeatureEdges);
00425   myFeatureEdges->SetBoundaryEdges(theIsBoundaryEdges);
00426   myFeatureEdges->SetManifoldEdges(theIsManifoldEdges);
00427   myFeatureEdges->SetNonManifoldEdges(theIsNonManifoldEdges);
00428 }
00429 
00433 bool
00434 SVTK_DeviceActor
00435 ::GetFeatureEdgesColoring()
00436 {
00437   return myFeatureEdges->GetColoring();
00438 }
00439 
00444 void
00445 SVTK_DeviceActor
00446 ::SetFeatureEdgesColoring(bool theIsColoring)
00447 {
00448   myFeatureEdges->SetColoring(theIsColoring);
00449 }
00450 
00455 void
00456 SVTK_DeviceActor
00457 ::SetRepresentation(VTKViewer::Representation::Type theMode)
00458 { 
00459   using namespace VTKViewer::Representation;
00460   if(IsShaded()){
00461     switch(myRepresentation){
00462     case Points : 
00463     case Surface : 
00464     case SurfaceWithEdges :
00465       myProperty->SetAmbient(GetProperty()->GetAmbient());
00466       myProperty->SetDiffuse(GetProperty()->GetDiffuse());
00467       myProperty->SetSpecular(GetProperty()->GetSpecular());
00468     }
00469     
00470     switch(theMode){
00471     case Points : 
00472     case Surface : 
00473     case SurfaceWithEdges :
00474       GetProperty()->SetAmbient(myProperty->GetAmbient());
00475       GetProperty()->SetDiffuse(myProperty->GetDiffuse());
00476       GetProperty()->SetSpecular(myProperty->GetSpecular());
00477       break;
00478     default:
00479       GetProperty()->SetAmbient(1.0);
00480       GetProperty()->SetDiffuse(0.0);
00481       GetProperty()->SetSpecular(0.0);
00482     }
00483   }
00484 
00485   switch(theMode){
00486   case Insideframe : 
00487     myGeomFilter->SetInside(true);
00488     myGeomFilter->SetWireframeMode(true);
00489     GetProperty()->SetRepresentation(VTK_WIREFRAME);
00490     break;
00491   case Points : 
00492     GetProperty()->SetPointSize(GetDefaultPointSize());  
00493     GetProperty()->SetRepresentation(VTK_POINTS);
00494     myGeomFilter->SetWireframeMode(false);
00495     myGeomFilter->SetInside(false);
00496     break;
00497   case Wireframe : 
00498     GetProperty()->SetRepresentation(VTK_WIREFRAME);
00499     myGeomFilter->SetWireframeMode(true);
00500     myGeomFilter->SetInside(false);
00501     break;
00502   case Surface : 
00503   case SurfaceWithEdges :
00504     GetProperty()->SetRepresentation(VTK_SURFACE);
00505     myGeomFilter->SetWireframeMode(false);
00506     myGeomFilter->SetInside(false);
00507     break;
00508   }
00509 
00510   SetMarkerEnabled( theMode == Points );
00511 
00512   myRepresentation = theMode;
00513 }
00514 
00518 VTKViewer::Representation::Type 
00519 SVTK_DeviceActor
00520 ::GetRepresentation()
00521 {
00522   return myRepresentation;
00523 }
00524 
00528 vtkFloatingPointType
00529 SVTK_DeviceActor
00530 ::GetDefaultPointSize()
00531 {
00532   return 5;
00533 }
00534 
00538 vtkFloatingPointType
00539 SVTK_DeviceActor
00540 ::GetDefaultLineWidth()
00541 {
00542   return 3;
00543 }
00544 
00548 bool
00549 SVTK_DeviceActor
00550 ::IsShaded()
00551 {
00552   return myIsShaded;
00553 }
00554 
00559 void
00560 SVTK_DeviceActor
00561 ::SetShaded(bool theShaded)
00562 {
00563   myIsShaded = theShaded;
00564 }
00565 
00569 int
00570 SVTK_DeviceActor
00571 ::GetNodeObjId(int theVtkID)
00572 {
00573   return theVtkID;
00574 }
00575 
00579 vtkFloatingPointType* 
00580 SVTK_DeviceActor
00581 ::GetNodeCoord(int theObjID)
00582 {
00583   return GetInput()->GetPoint(theObjID);
00584 }
00585 
00586 
00590 vtkCell* 
00591 SVTK_DeviceActor
00592 ::GetElemCell(int theObjID)
00593 {
00594   return GetInput()->GetCell(theObjID);
00595 }
00596 
00600 int
00601 SVTK_DeviceActor
00602 ::GetElemObjId(int theVtkID) 
00603 { 
00604   return theVtkID;
00605 }
00606 
00610 void
00611 SVTK_DeviceActor
00612 ::Render(vtkRenderer *ren, vtkMapper* m)
00613 {
00614   if(myIsResolveCoincidentTopology){
00615     int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology();
00616     vtkFloatingPointType aFactor, aUnit; 
00617     vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
00618     
00619     vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
00620     vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
00621                                                                    myPolygonOffsetUnits);
00622     Superclass::Render(ren,m);
00623     
00624     vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
00625     vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology);
00626   }else{
00627     Superclass::Render(ren,m);
00628   }
00629 }
00630 
00635 void
00636 SVTK_DeviceActor
00637 ::SetPolygonOffsetParameters(vtkFloatingPointType factor, 
00638                              vtkFloatingPointType units)
00639 {
00640   myPolygonOffsetFactor = factor;
00641   myPolygonOffsetUnits = units;
00642 }
00643 
00648 void
00649 SVTK_DeviceActor
00650 ::GetPolygonOffsetParameters(vtkFloatingPointType& factor, 
00651                              vtkFloatingPointType& units)
00652 {
00653   factor = myPolygonOffsetFactor;
00654   units = myPolygonOffsetUnits;
00655 }
00656 
00657 VTKViewer_DataSetMapper* SVTK_DeviceActor::GetDataSetMapper()
00658 {
00659   return myMapper;
00660 }
00661 
00665 void SVTK_DeviceActor::SetQuadraticArcMode(bool theFlag){
00666   myGeomFilter->SetQuadraticArcMode(theFlag);
00667 }
00668 
00672 bool SVTK_DeviceActor::GetQuadraticArcMode(){
00673   return myGeomFilter->GetQuadraticArcMode();
00674 }
00678 void SVTK_DeviceActor::SetQuadraticArcAngle(vtkFloatingPointType theMaxAngle){
00679   myGeomFilter->SetQuadraticArcAngle(theMaxAngle);
00680 }
00681 
00685 vtkFloatingPointType SVTK_DeviceActor::GetQuadraticArcAngle(){
00686   return myGeomFilter->GetQuadraticArcAngle();
00687 }
00688 
00693 void SVTK_DeviceActor::SetMarkerEnabled( bool theMarkerEnabled )
00694 {
00695   myMapper->SetMarkerEnabled( theMarkerEnabled );
00696 }
00697 
00703 void SVTK_DeviceActor::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale )
00704 {
00705   myMapper->SetMarkerStd( theMarkerType, theMarkerScale );
00706 }
00707 
00713 void SVTK_DeviceActor::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
00714 {
00715   myMapper->SetMarkerTexture( theMarkerId, theMarkerTexture );
00716 }
00717 
00722 VTK::MarkerType SVTK_DeviceActor::GetMarkerType()
00723 {
00724   return myMapper->GetMarkerType();
00725 }
00726 
00731 VTK::MarkerScale SVTK_DeviceActor::GetMarkerScale()
00732 {
00733   return myMapper->GetMarkerScale();
00734 }
00735 
00740 int SVTK_DeviceActor::GetMarkerTexture()
00741 {
00742   return myMapper->GetMarkerTexture();
00743 }
00744 
00745 void SVTK_DeviceActor::SetCoincident3DAllowed(bool theFlag) {
00746   myGeomFilter->SetAppendCoincident3D(theFlag);
00747 }
00748 
00749 bool SVTK_DeviceActor::IsCoincident3DAllowed() const {
00750   return myGeomFilter->GetAppendCoincident3D();
00751 }