X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FSVTK%2FSVTK_Actor.cxx;h=1ee510e336112c109a6d41909d773c481365d3db;hb=244cdc6d07ed7f99115e0f723def096c818cf17c;hp=c958f2852bb760a1448229a2493ec67d333d5b5f;hpb=aacd3a638816ac9cb50dfa5284090d3270105e4a;p=modules%2Fgui.git diff --git a/src/SVTK/SVTK_Actor.cxx b/src/SVTK/SVTK_Actor.cxx index c958f2852..1ee510e33 100644 --- a/src/SVTK/SVTK_Actor.cxx +++ b/src/SVTK/SVTK_Actor.cxx @@ -1,25 +1,30 @@ -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE // -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org #include "SVTK_Actor.h" +#include "SALOME_Actor.h" +#include "SVTK_Utils.h" -#include "VTKViewer_PassThroughFilter.h" +#include "SALOME_InteractiveObject.hxx" // VTK Includes #include @@ -28,117 +33,107 @@ #include #include -#include -#include - -using namespace std; - -#ifdef _DEBUG_ -static int MYDEBUG = 0; -#else -static int MYDEBUG = 0; +#include +#define VTK_XVERSION (VTK_MAJOR_VERSION*10000+VTK_MINOR_VERSION*100+VTK_BUILD_VERSION) +#if VTK_XVERSION > 50700 +#include #endif +#include +#include "Utils_SALOME_Exception.hxx" +#include "utilities.h" -static void CopyPoints(vtkUnstructuredGrid* theGrid, vtkDataSet *theSourceDataSet){ - vtkPoints *aPoints = vtkPoints::New(); - vtkIdType iEnd = theSourceDataSet->GetNumberOfPoints(); - aPoints->SetNumberOfPoints(iEnd); - for(vtkIdType i = 0; i < iEnd; i++){ - aPoints->SetPoint(i,theSourceDataSet->GetPoint(i)); - } - theGrid->SetPoints(aPoints); - aPoints->Delete(); -} - -//======================================================================= vtkStandardNewMacro(SVTK_Actor); -SVTK_Actor::SVTK_Actor() +/*! + Constructor +*/ +SVTK_Actor +::SVTK_Actor(): + myUnstructuredGrid(vtkUnstructuredGrid::New()) { - myRenderer = NULL; - myIsInfinite = true; + myIsShaded = true; + myIsResolveCoincidentTopology = false; Visibility = Pickable = false; - myUnstructuredGrid = vtkUnstructuredGrid::New(); + myUnstructuredGrid->Delete(); myUnstructuredGrid->Allocate(); +} - myIsShrunk = false; - myIsShrinkable = true; - myShrinkFilter = vtkShrinkFilter::New(); - - myMapper = vtkDataSetMapper::New(); +void +SVTK_Actor +::Initialize() +{ + SetInputData(GetSource()); +} - myMapper->SetInput(myUnstructuredGrid); - Superclass::InitPipeLine(myMapper); +void +SVTK_Actor +::SetSource(vtkUnstructuredGrid* theUnstructuredGrid) +{ + if(GetSource() == theUnstructuredGrid) + return; - SetResolveCoincidentTopology(false); -} + myUnstructuredGrid = theUnstructuredGrid; -void SVTK_Actor::SetShrinkFactor(float theValue){ - myShrinkFilter->SetShrinkFactor(theValue); - Modified(); + SetInputData(theUnstructuredGrid); } -void SVTK_Actor::SetShrink() +vtkUnstructuredGrid* +SVTK_Actor +::GetSource() { - if ( !myIsShrinkable ) return; - if ( vtkDataSet* aDataSet = myPassFilter[0]->GetOutput() ) - { - myShrinkFilter->SetInput( aDataSet ); - myPassFilter[1]->SetInput( myShrinkFilter->GetOutput() ); - myIsShrunk = true; - } + return myUnstructuredGrid.GetPointer(); } -void SVTK_Actor::UnShrink() +/*! + Destructor +*/ +SVTK_Actor +::~SVTK_Actor() { - if ( !myIsShrunk ) return; - if ( vtkDataSet* aDataSet = myPassFilter[0]->GetOutput() ) - { - myPassFilter[1]->SetInput( aDataSet ); - myPassFilter[1]->Modified(); - myIsShrunk = false; - Modified(); - } } - -//---------------------------------------------------------------------------- -SVTK_Actor::~SVTK_Actor() +const TColStd_IndexedMapOfInteger& +SVTK_Actor +::GetMapIndex() const { - //if(MYDEBUG) INFOS("VTKViewer_Actor::~VTKViewer_Actor()"); - - myMapper->RemoveAllInputs(); - myMapper->Delete(); - - myShrinkFilter->UnRegisterAllOutputs(); - myShrinkFilter->Delete(); - - myUnstructuredGrid->Delete(); + return myMapIndex; } - -//---------------------------------------------------------------------------- -void SVTK_Actor::MapCells(SALOME_Actor* theMapActor, - const TColStd_IndexedMapOfInteger& theMapIndex) +void +SVTK_Actor +::MapCells(SALOME_Actor* theMapActor, + const TColStd_IndexedMapOfInteger& theMapIndex) { - myUnstructuredGrid->Reset(); + myUnstructuredGrid->Initialize(); + myUnstructuredGrid->Allocate(); vtkDataSet *aSourceDataSet = theMapActor->GetInput(); - CopyPoints(myUnstructuredGrid,aSourceDataSet); + SVTK::CopyPoints(GetSource(),aSourceDataSet); int aNbOfParts = theMapIndex.Extent(); for(int ind = 1; ind <= aNbOfParts; ind++){ int aPartId = theMapIndex( ind ); - vtkCell* aCell = theMapActor->GetElemCell(aPartId); - myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds()); - //for (int i = 0, iEnd = aCell->GetNumberOfEdges(); i < iEnd; i++){ - // vtkCell* anEdgeCell = aCell->GetEdge(i); - // myUnstructuredGrid->InsertNextCell(VTK_LINE,anEdgeCell->GetPointIds()); - //} + if(vtkCell* aCell = theMapActor->GetElemCell(aPartId)) + { +#if VTK_XVERSION > 50700 + if (aCell->GetCellType() != VTK_POLYHEDRON) +#endif + myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds()); +#if VTK_XVERSION > 50700 + else + { + vtkPolyhedron *polyhedron = dynamic_cast(aCell); + if (!polyhedron) + throw SALOME_Exception(LOCALIZED ("not a polyhedron")); + vtkIdType *pts = polyhedron->GetFaces(); + myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),pts[0], pts+1); + } +#endif + } } UnShrink(); @@ -146,74 +141,65 @@ void SVTK_Actor::MapCells(SALOME_Actor* theMapActor, SetShrinkFactor(theMapActor->GetShrinkFactor()); SetShrink(); } -} + myMapIndex = theMapIndex; +} -//---------------------------------------------------------------------------- -void SVTK_Actor::MapPoints(SALOME_Actor* theMapActor, - const TColStd_IndexedMapOfInteger& theMapIndex) +void +SVTK_Actor +::MapPoints(SALOME_Actor* theMapActor, + const TColStd_IndexedMapOfInteger& theMapIndex) { - myUnstructuredGrid->Reset(); + myUnstructuredGrid->Initialize(); + myUnstructuredGrid->Allocate(); + if(int aNbOfParts = theMapIndex.Extent()){ vtkPoints *aPoints = vtkPoints::New(); aPoints->SetNumberOfPoints(aNbOfParts); - for(int i = 0; i < aNbOfParts; i++){ + for(vtkIdType i = 0; i < aNbOfParts; i++){ int aPartId = theMapIndex( i+1 ); - float* aCoord = theMapActor->GetNodeCoord(aPartId); - aPoints->SetPoint(i,aCoord); - myUnstructuredGrid->InsertNextCell(VTK_VERTEX,1,&i); + if(double* aCoord = theMapActor->GetNodeCoord(aPartId)){ + aPoints->SetPoint(i,aCoord); + // Change the type from int to vtkIdType in order to avoid compilation errors while using VTK + // from ParaView-3.4.0 compiled on 64-bit Debian platform with VTK_USE_64BIT_IDS = ON + myUnstructuredGrid->InsertNextCell(VTK_VERTEX,(vtkIdType) 1,&i); + } } myUnstructuredGrid->SetPoints(aPoints); aPoints->Delete(); } UnShrink(); -} + myMapIndex = theMapIndex; +} -//---------------------------------------------------------------------------- -void SVTK_Actor::MapEdge(SALOME_Actor* theMapActor, - const TColStd_IndexedMapOfInteger& theMapIndex) +void +SVTK_Actor +::MapEdge(SALOME_Actor* theMapActor, + const TColStd_IndexedMapOfInteger& theMapIndex) { - myUnstructuredGrid->Reset(); + myUnstructuredGrid->Initialize(); + myUnstructuredGrid->Allocate(); vtkDataSet *aSourceDataSet = theMapActor->GetInput(); - CopyPoints(myUnstructuredGrid,aSourceDataSet); - - int iEnd = theMapIndex.Extent(); - int aCellId = -1, aCellCounter = 0; - for(int i = 1; i <= iEnd; i++){ - int anId = theMapIndex( i ); - if(anId > 0) { - aCellCounter++; - aCellId = anId; - } - } - - if(aCellCounter == 1){ - vtkCell* aCell = theMapActor->GetElemCell(aCellId); - if(aCell->GetCellType() <= VTK_LINE){ - myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds()); - }else{ - int aNbOfParts = aCell->GetNumberOfEdges(); - for(int i = 1; i <= iEnd; i++){ - int aPartId = theMapIndex(i); - if( aPartId < 0){ - aPartId = -aPartId-1; - if(0 > aPartId || aPartId >= aNbOfParts) break; - vtkCell* anEdgeCell = aCell->GetEdge(aPartId); - myUnstructuredGrid->InsertNextCell(VTK_LINE,anEdgeCell->GetPointIds()); - } - } - } - }else{ - int aNbOfParts = aSourceDataSet->GetNumberOfCells(); - for(int i = 1; i <= iEnd; i++){ - int aPartId = theMapIndex( i ); - if(aPartId > 0){ - if(aPartId >= aNbOfParts) break; - vtkCell* aCell = aSourceDataSet->GetCell(aPartId); - myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds()); + SVTK::CopyPoints(GetSource(),aSourceDataSet); + + + if(theMapIndex.Extent() == 2){ + int anEdgeId = theMapIndex(1) < 0 ? theMapIndex(1) : theMapIndex(2); + int aCellId = theMapIndex(1) < 0 ? theMapIndex(2) : theMapIndex(1); + + if(aCellId > 0){ + if(vtkCell* aCell = theMapActor->GetElemCell(aCellId)){ + if(anEdgeId < 0){ + anEdgeId = -anEdgeId - 1; + int aNbOfEdges = aCell->GetNumberOfEdges(); + if(0 <= anEdgeId || anEdgeId < aNbOfEdges){ + if(vtkCell* anEdge = aCell->GetEdge(anEdgeId)) + myUnstructuredGrid->InsertNextCell(VTK_LINE,anEdge->GetPointIds()); + } + } } } } @@ -223,6 +209,23 @@ void SVTK_Actor::MapEdge(SALOME_Actor* theMapActor, SetShrinkFactor(theMapActor->GetShrinkFactor()); SetShrink(); } + + myMapIndex = theMapIndex; } -//---------------------------------------------------------------------------- +/*! + To publish the actor an all its internal devices +*/ +void +SVTK_Actor +::AddToRender(vtkRenderer* theRenderer) +{ + theRenderer->AddActor(this); +} + +void +SVTK_Actor +::RemoveFromRender(vtkRenderer* theRenderer) +{ + theRenderer->RemoveActor(this); +}