X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSVTK%2FSVTK_DeviceActor.cxx;h=d1cb768435325e97c28e7ddce359b46338281763;hb=e6caa123c65e3c4a3017364ec5bb4225fd898465;hp=a3bb037730cf4a8d353b54196fd75b41c5ec9c0c;hpb=f830c97c748d8f8a6a7eccc8e3a58e19066a1181;p=modules%2Fgui.git diff --git a/src/SVTK/SVTK_DeviceActor.cxx b/src/SVTK/SVTK_DeviceActor.cxx index a3bb03773..d1cb76843 100644 --- a/src/SVTK/SVTK_DeviceActor.cxx +++ b/src/SVTK/SVTK_DeviceActor.cxx @@ -1,31 +1,28 @@ -// SVTK OBJECT : interactive object for SVTK visualization +// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE // -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// 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. -// -// 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 +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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, or (at your option) any later version. // +// 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 // + +// SVTK OBJECT : interactive object for SVTK visualization // File : SVTK_DeviceActor.cxx // Author : -// Module : -// $Header$ - #include "SVTK_DeviceActor.h" @@ -36,17 +33,16 @@ // VTK Includes #include #include +#include #include #include -#include -#include +#include +#include #include -using namespace std; - vtkStandardNewMacro(SVTK_DeviceActor); /*! @@ -58,18 +54,23 @@ SVTK_DeviceActor myIsShrunk = false; myIsShrinkable = true; + myIsFeatureEdgesAllowed = false; + myIsFeatureEdgesEnabled = false; + myIsShaded = true; myProperty = vtkProperty::New(); - myRepresentation = SVTK::Representation::Surface; + myRepresentation = VTKViewer::Representation::Surface; myIsResolveCoincidentTopology = true; vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor, - myPolygonOffsetUnits); + myPolygonOffsetUnits); - myMapper = vtkDataSetMapper::New(); + myMapper = VTKViewer_DataSetMapper::New(); myShrinkFilter = vtkShrinkFilter::New(); + myFeatureEdges = vtkFeatureEdges::New(); + myGeomFilter = VTKViewer_GeometryFilter::New(); myTransformFilter = VTKViewer_TransformFilter::New(); @@ -94,6 +95,8 @@ SVTK_DeviceActor myShrinkFilter->Delete(); + myFeatureEdges->Delete(); + for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++) myPassFilter[i]->Delete(); } @@ -117,29 +120,25 @@ SVTK_DeviceActor { if(theMapper){ int anId = 0; - myPassFilter[ anId ]->SetInput( theMapper->GetInput() ); - myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() ); + myPassFilter[ anId ]->SetInputConnection( theMapper->GetInputConnection( 0, 0 ) ); + myPassFilter[ anId + 1]->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() ); anId++; // 1 - myGeomFilter->SetInput( myPassFilter[ anId ]->GetOutput() ); + myGeomFilter->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() ); anId++; // 2 - myPassFilter[ anId ]->SetInput( myGeomFilter->GetOutput() ); - myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() ); + myPassFilter[ anId ]->SetInputConnection( myGeomFilter->GetOutputPort() ); + myPassFilter[ anId + 1 ]->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() ); anId++; // 3 - myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() ); + myTransformFilter->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() ); anId++; // 4 - myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() ); - myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() ); + myPassFilter[ anId ]->SetInputConnection( myTransformFilter->GetOutputPort() ); + myPassFilter[ anId + 1 ]->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() ); anId++; // 5 - if(vtkDataSetMapper* aMapper = dynamic_cast(theMapper)){ - aMapper->SetInput(myPassFilter[anId]->GetOutput()); - }else if(vtkPolyDataMapper* aMapper = dynamic_cast(theMapper)){ - aMapper->SetInput(myPassFilter[anId]->GetPolyDataOutput()); - } + theMapper->SetInputConnection(myPassFilter[anId]->GetOutputPort()); } Superclass::SetMapper(theMapper); } @@ -159,9 +158,20 @@ SVTK_DeviceActor */ void SVTK_DeviceActor -::SetInput(vtkDataSet* theDataSet) +::SetInputData(vtkDataSet* theDataSet) { - myMapper->SetInput(theDataSet); + myMapper->SetInputData(theDataSet); + InitPipeLine(myMapper); +} + +/*! + Allows to set initial vtkDataSet +*/ +void +SVTK_DeviceActor +::SetInputConnection(vtkAlgorithmOutput* theAlgorithmOutput) +{ + myMapper->SetInputConnection(theAlgorithmOutput); InitPipeLine(myMapper); } @@ -185,15 +195,18 @@ SVTK_DeviceActor { unsigned long mTime = this->Superclass::GetMTime(); - mTime = max(mTime,myGeomFilter->GetMTime()); + mTime = std::max(mTime,myGeomFilter->GetMTime()); - mTime = max(mTime,myTransformFilter->GetMTime()); + mTime = std::max(mTime,myTransformFilter->GetMTime()); if(myIsShrunk) - mTime = max(mTime,myShrinkFilter->GetMTime()); + mTime = std::max(mTime,myShrinkFilter->GetMTime()); + + if(myIsFeatureEdgesEnabled) + mTime = std::max(mTime,myFeatureEdges->GetMTime()); for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++) - max(mTime,myPassFilter[i]->GetMTime()); + std::max(mTime,myPassFilter[i]->GetMTime()); return mTime; } @@ -250,16 +263,19 @@ SVTK_DeviceActor if ( !myIsShrinkable ) return; - if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() ) + if ( vtkAlgorithmOutput* anOutput = myPassFilter[ 0 ]->GetOutputPort() ) { - aDataSet->Update(); - int numCells=aDataSet->GetNumberOfCells(); - int numPts = aDataSet->GetNumberOfPoints(); - //It's impossible to use to apply "shrink" for "empty" dataset - if (numCells < 1 || numPts < 1) - return; - myShrinkFilter->SetInput( aDataSet ); - myPassFilter[ 1 ]->SetInput( myShrinkFilter->GetOutput() ); + myPassFilter[ 0 ]->Update(); + if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() ) + { + int numCells=aDataSet->GetNumberOfCells(); + int numPts = aDataSet->GetNumberOfPoints(); + //It's impossible to use to apply "shrink" for "empty" dataset + if (numCells < 1 || numPts < 1) + return; + } + myShrinkFilter->SetInputConnection( anOutput ); + myPassFilter[ 1 ]->SetInputConnection( myShrinkFilter->GetOutputPort() ); myIsShrunk = true; } } @@ -272,9 +288,9 @@ SVTK_DeviceActor ::UnShrink() { if ( !myIsShrunk ) return; - if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() ) + if ( vtkAlgorithmOutput* anOutput = myPassFilter[ 0 ]->GetOutputPort() ) { - myPassFilter[ 1 ]->SetInput( aDataSet ); + myPassFilter[ 1 ]->SetInputConnection( anOutput ); myIsShrunk = false; } } @@ -282,7 +298,7 @@ SVTK_DeviceActor /*! \return shrink factor */ -vtkFloatingPointType +double SVTK_DeviceActor ::GetShrinkFactor() { @@ -295,24 +311,167 @@ SVTK_DeviceActor */ void SVTK_DeviceActor -::SetShrinkFactor(vtkFloatingPointType theValue) +::SetShrinkFactor(double theValue) { myShrinkFilter->SetShrinkFactor(theValue); } +/*! + \return true if feature edges are allowed for this actor +*/ +bool +SVTK_DeviceActor +::IsFeatureEdgesAllowed() +{ + return myIsFeatureEdgesAllowed; +} + +/*! + Allows feature edges for this actor on or off + \param theIsFeatureEdgesAllowed - flag which allows feature edges for this actor on or off +*/ +void +SVTK_DeviceActor +::SetFeatureEdgesAllowed(bool theIsFeatureEdgesAllowed) +{ + myIsFeatureEdgesAllowed = theIsFeatureEdgesAllowed; +} + +/*! + \return true if feature edges are enabled +*/ +bool +SVTK_DeviceActor +::IsFeatureEdgesEnabled() +{ + return myIsFeatureEdgesEnabled; +} + +/*! + Enables feature edges on or off + \param theIsFeatureEdgesEnabled - flag which enables feature edges on or off +*/ +void +SVTK_DeviceActor +::SetFeatureEdgesEnabled(bool theIsFeatureEdgesEnabled) +{ + if ( !myIsFeatureEdgesAllowed || myIsFeatureEdgesEnabled == theIsFeatureEdgesEnabled ) + return; + + if ( vtkAlgorithmOutput* aPolyData = myPassFilter[ 2 ]->GetOutputPort() ) + { + if( theIsFeatureEdgesEnabled ) + { + myPassFilter[ 2 ]->Update(); + myFeatureEdges->SetInputConnection( aPolyData ); + myPassFilter[ 3 ]->SetInputConnection( myFeatureEdges->GetOutputPort() ); + myIsFeatureEdgesEnabled = true; + } + else + { + myPassFilter[3]->SetInputConnection( aPolyData ); + myIsFeatureEdgesEnabled = false; + } + myIsFeatureEdgesEnabled = theIsFeatureEdgesEnabled; + } +} + +/*! + \return angle of feature edges' filter +*/ +double +SVTK_DeviceActor +::GetFeatureEdgesAngle() +{ + return myFeatureEdges->GetFeatureAngle(); +} + +/*! + Sets angle of feature edges' filter + \param theAngle angle of feature edges' filter +*/ +void +SVTK_DeviceActor +::SetFeatureEdgesAngle(double theAngle) +{ + myFeatureEdges->SetFeatureAngle(theAngle); +} + +/*! + Gets information about kinds of edges which are displayed by feature edges' filter + \param theIsFeatureEdges flag which shows whether feature edges are displayed + \param theIsBoundaryEdges flag which shows whether boundary edges are displayed + \param theIsManifoldEdges flag which shows whether manifold edges are displayed + \param theIsNonManifoldEdges flag which shows whether non-manifold edges are displayed +*/ +void +SVTK_DeviceActor +::GetFeatureEdgesFlags(bool& theIsFeatureEdges, + bool& theIsBoundaryEdges, + bool& theIsManifoldEdges, + bool& theIsNonManifoldEdges) +{ + theIsFeatureEdges = myFeatureEdges->GetFeatureEdges(); + theIsBoundaryEdges = myFeatureEdges->GetBoundaryEdges(); + theIsManifoldEdges = myFeatureEdges->GetManifoldEdges(); + theIsNonManifoldEdges = myFeatureEdges->GetNonManifoldEdges(); +} + +/*! + Sets different kinds of edges to be displayed by feature edges' filter + \param theIsFeatureEdges flag which displays feature edges + \param theIsBoundaryEdges flag which displays boundary edges + \param theIsManifoldEdges flag which displays manifold edges + \param theIsNonManifoldEdges flag which displays non-manifold edges +*/ +void +SVTK_DeviceActor +::SetFeatureEdgesFlags(bool theIsFeatureEdges, + bool theIsBoundaryEdges, + bool theIsManifoldEdges, + bool theIsNonManifoldEdges) +{ + myFeatureEdges->SetFeatureEdges(theIsFeatureEdges); + myFeatureEdges->SetBoundaryEdges(theIsBoundaryEdges); + myFeatureEdges->SetManifoldEdges(theIsManifoldEdges); + myFeatureEdges->SetNonManifoldEdges(theIsNonManifoldEdges); +} + +/*! + \return feature edges' coloring flag +*/ +bool +SVTK_DeviceActor +::GetFeatureEdgesColoring() +{ + return myFeatureEdges->GetColoring(); +} + +/*! + Sets feature edges' coloring flag + \param theIsColoring feature edges' coloring flag +*/ +void +SVTK_DeviceActor +::SetFeatureEdgesColoring(bool theIsColoring) +{ + myFeatureEdges->SetColoring(theIsColoring); +} + /*! Set representation (VTK_SURFACE, VTK_POINTS, VTK_WIREFRAME and so on) param theMode - new mode */ void SVTK_DeviceActor -::SetRepresentation(SVTK::Representation::Type theMode) +::SetRepresentation(VTKViewer::Representation::Type theMode) { - using namespace SVTK::Representation; + using namespace VTKViewer::Representation; if(IsShaded()){ switch(myRepresentation){ case Points : case Surface : + case SurfaceWithEdges : myProperty->SetAmbient(GetProperty()->GetAmbient()); myProperty->SetDiffuse(GetProperty()->GetDiffuse()); myProperty->SetSpecular(GetProperty()->GetSpecular()); @@ -321,6 +480,7 @@ SVTK_DeviceActor switch(theMode){ case Points : case Surface : + case SurfaceWithEdges : GetProperty()->SetAmbient(myProperty->GetAmbient()); GetProperty()->SetDiffuse(myProperty->GetDiffuse()); GetProperty()->SetSpecular(myProperty->GetSpecular()); @@ -350,19 +510,22 @@ SVTK_DeviceActor myGeomFilter->SetInside(false); break; case Surface : + case SurfaceWithEdges : GetProperty()->SetRepresentation(VTK_SURFACE); myGeomFilter->SetWireframeMode(false); myGeomFilter->SetInside(false); break; } + SetMarkerEnabled( theMode == Points ); + myRepresentation = theMode; } /*! \return current representation mode */ -SVTK::Representation::Type +VTKViewer::Representation::Type SVTK_DeviceActor ::GetRepresentation() { @@ -372,7 +535,7 @@ SVTK_DeviceActor /*! \return default point size */ -vtkFloatingPointType +double SVTK_DeviceActor ::GetDefaultPointSize() { @@ -382,7 +545,7 @@ SVTK_DeviceActor /*! \return default line width */ -vtkFloatingPointType +double SVTK_DeviceActor ::GetDefaultLineWidth() { @@ -423,7 +586,7 @@ SVTK_DeviceActor /*! Get coordinates of a node for given object index */ -vtkFloatingPointType* +double* SVTK_DeviceActor ::GetNodeCoord(int theObjID) { @@ -458,21 +621,22 @@ void SVTK_DeviceActor ::Render(vtkRenderer *ren, vtkMapper* m) { + int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology(); if(myIsResolveCoincidentTopology){ - int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology(); - vtkFloatingPointType aFactor, aUnit; + double aFactor, aUnit; vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit); vtkMapper::SetResolveCoincidentTopologyToPolygonOffset(); vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor, - myPolygonOffsetUnits); + myPolygonOffsetUnits); Superclass::Render(ren,m); vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit); - vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology); }else{ + vtkMapper::SetResolveCoincidentTopologyToOff(); Superclass::Render(ren,m); } + vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology); } /*! @@ -481,8 +645,8 @@ SVTK_DeviceActor */ void SVTK_DeviceActor -::SetPolygonOffsetParameters(vtkFloatingPointType factor, - vtkFloatingPointType units) +::SetPolygonOffsetParameters(double factor, + double units) { myPolygonOffsetFactor = factor; myPolygonOffsetUnits = units; @@ -494,14 +658,120 @@ SVTK_DeviceActor */ void SVTK_DeviceActor -::GetPolygonOffsetParameters(vtkFloatingPointType& factor, - vtkFloatingPointType& units) +::GetPolygonOffsetParameters(double& factor, + double& units) { factor = myPolygonOffsetFactor; units = myPolygonOffsetUnits; } -vtkDataSetMapper* SVTK_DeviceActor::GetDataSetMapper() +VTKViewer_DataSetMapper* SVTK_DeviceActor::GetDataSetMapper() { return myMapper; } + +/*! + * On/Off representation 2D quadratic element as arked polygon + */ +void SVTK_DeviceActor::SetQuadraticArcMode(bool theFlag){ + myGeomFilter->SetQuadraticArcMode(theFlag); +} + +/*! + * Return true if 2D quadratic element displayed as arked polygon + */ +bool SVTK_DeviceActor::GetQuadraticArcMode(){ + return myGeomFilter->GetQuadraticArcMode(); +} +/*! + * Set Max angle for representation 2D quadratic element as arked polygon + */ +void SVTK_DeviceActor::SetQuadraticArcAngle(double theMaxAngle){ + myGeomFilter->SetQuadraticArcAngle(theMaxAngle); +} + +/*! + * Return Max angle of the representation 2D quadratic element as arked polygon + */ +double SVTK_DeviceActor::GetQuadraticArcAngle(){ + return myGeomFilter->GetQuadraticArcAngle(); +} + +/*! + * Set ball drawing enabled + * \param theBallEnabled flag to enable/disable balls + */ +void SVTK_DeviceActor::SetBallEnabled( bool theBallEnabled ) { + myMapper->SetBallEnabled( theBallEnabled ); +} + +/*! + * Set point marker enabled + * \param theMarkerEnabled flag to enable/disable point marker + */ +void SVTK_DeviceActor::SetMarkerEnabled( bool theMarkerEnabled ) +{ + myMapper->SetMarkerEnabled( theMarkerEnabled ); +} + +/*! + * Set standard point marker + * \param theMarkerType type of the marker + * \param theMarkerScale scale of the marker + */ +void SVTK_DeviceActor::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale ) +{ + myMapper->SetMarkerStd( theMarkerType, theMarkerScale ); +} + +/*! + * Set custom point marker + * \param theMarkerId id of the marker texture + * \param theMarkerTexture marker texture + */ +void SVTK_DeviceActor::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture ) +{ + myMapper->SetMarkerTexture( theMarkerId, theMarkerTexture ); +} + +/*! + * Get type of the point marker + * \return type of the point marker + */ +VTK::MarkerType SVTK_DeviceActor::GetMarkerType() +{ + return myMapper->GetMarkerType(); +} + +/*! + Get scale of the point marker + \return scale of the point marker +*/ +VTK::MarkerScale SVTK_DeviceActor::GetMarkerScale() +{ + return myMapper->GetMarkerScale(); +} + +/*! + * Get texture identifier of the point marker + * \return texture identifier of the point marker + */ +int SVTK_DeviceActor::GetMarkerTexture() +{ + return myMapper->GetMarkerTexture(); +} + +void SVTK_DeviceActor::SetCoincident3DAllowed(bool theFlag) { + myGeomFilter->SetAppendCoincident3D(theFlag); +} + +bool SVTK_DeviceActor::IsCoincident3DAllowed() const { + return myGeomFilter->GetAppendCoincident3D(); +} + +void +SVTK_DeviceActor +::SetResolveCoincidentTopology(bool theIsResolve) +{ + myIsResolveCoincidentTopology = theIsResolve; +}