From 8d91ebae2ace0c4fa55e2fde4f80dee2bafb41f5 Mon Sep 17 00:00:00 2001 From: rkv Date: Fri, 13 Dec 2013 13:04:17 +0000 Subject: [PATCH] Feature #229: Showing objects in VTK: (Images are not displayed for the moment) --- src/HYDROGUI/CMakeLists.txt | 4 + src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx | 11 +- src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.h | 1 + src/HYDROGUI/HYDROGUI_VTKPrsShape.cxx | 326 ++++++++++++++++++++ src/HYDROGUI/HYDROGUI_VTKPrsShape.h | 89 ++++++ src/HYDROGUI/HYDROGUI_VTKPrsShapeDriver.cxx | 55 ++++ src/HYDROGUI/HYDROGUI_VTKPrsShapeDriver.h | 61 ++++ 7 files changed, 546 insertions(+), 1 deletion(-) create mode 100644 src/HYDROGUI/HYDROGUI_VTKPrsShape.cxx create mode 100644 src/HYDROGUI/HYDROGUI_VTKPrsShape.h create mode 100644 src/HYDROGUI/HYDROGUI_VTKPrsShapeDriver.cxx create mode 100644 src/HYDROGUI/HYDROGUI_VTKPrsShapeDriver.h diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index 39ec2612..e7adb3cd 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -66,6 +66,8 @@ set(PROJECT_HEADERS HYDROGUI_VTKPrsBathymetryDriver.h HYDROGUI_VTKPrsDisplayer.h HYDROGUI_VTKPrsDriver.h + HYDROGUI_VTKPrsShape.h + HYDROGUI_VTKPrsShapeDriver.h HYDROGUI_Wizard.h HYDROGUI_Zone.h HYDROGUI_ImportGeomObjectOp.h @@ -144,6 +146,8 @@ set(PROJECT_SOURCES HYDROGUI_VTKPrsBathymetryDriver.cxx HYDROGUI_VTKPrsDisplayer.cxx HYDROGUI_VTKPrsDriver.cxx + HYDROGUI_VTKPrsShape.cxx + HYDROGUI_VTKPrsShapeDriver.cxx HYDROGUI_Wizard.cxx HYDROGUI_Zone.cxx HYDROGUI_ImportGeomObjectOp.cxx diff --git a/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx b/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx index 2b3e55f5..8b373317 100644 --- a/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx +++ b/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.cxx @@ -26,6 +26,7 @@ #include "HYDROGUI_Module.h" #include "HYDROGUI_VTKPrs.h" #include "HYDROGUI_VTKPrsBathymetryDriver.h" +#include "HYDROGUI_VTKPrsShapeDriver.h" #include "HYDROGUI_Tool.h" #include "HYDROData_Tool.h" @@ -59,7 +60,7 @@ #define SATURATION_END 1.0 HYDROGUI_VTKPrsDisplayer::HYDROGUI_VTKPrsDisplayer( HYDROGUI_Module* theModule ) -: HYDROGUI_AbstractDisplayer( theModule ), myDriver( NULL ) +: HYDROGUI_AbstractDisplayer( theModule ), myDriver( NULL ), myShapeDriver( NULL ) { } @@ -305,6 +306,14 @@ HYDROGUI_VTKPrsDriver* HYDROGUI_VTKPrsDisplayer::getDriver( const int theViewId, } aDriver = myDriver; } + else + { + if ( !myShapeDriver ) + { + myShapeDriver = new HYDROGUI_VTKPrsShapeDriver( myScalarBars[ theViewId ] ); + } + aDriver = myShapeDriver; + } return aDriver; } diff --git a/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.h b/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.h index 5db3e743..abcdfd46 100644 --- a/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.h +++ b/src/HYDROGUI/HYDROGUI_VTKPrsDisplayer.h @@ -126,6 +126,7 @@ private: HYDROGUI_VTKPrsDriver* getDriver( const int theViewId, const Handle(HYDROData_Entity)& theObj ); HYDROGUI_VTKPrsDriver* myDriver; + HYDROGUI_VTKPrsDriver* myShapeDriver; QMap > myScalarBars; //!< Colors legend presentations }; diff --git a/src/HYDROGUI/HYDROGUI_VTKPrsShape.cxx b/src/HYDROGUI/HYDROGUI_VTKPrsShape.cxx new file mode 100644 index 00000000..7512b0a3 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_VTKPrsShape.cxx @@ -0,0 +1,326 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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. +// +// 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 +// + +#include "HYDROGUI_VTKPrsShape.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include +#include + +#include +#include +#include + +#include + +#include + +#include + +#include +#include + +#include + +// Hard-coded value of shape deflection coefficient for VTK viewer +const double VTK_MIN_DEFLECTION = 0.001; + + +//======================================================================= +// name : HYDROGUI_VTKPrsShape +// Purpose : Constructor +//======================================================================= +HYDROGUI_VTKPrsShape::HYDROGUI_VTKPrsShape( const Handle(HYDROData_Entity)& theObject ) +: HYDROGUI_VTKPrs( theObject ) +{ +} + +//======================================================================= +// name : HYDROGUI_VTKPrsShape +// Purpose : Destructor +//======================================================================= +HYDROGUI_VTKPrsShape::~HYDROGUI_VTKPrsShape() +{ +} + +//================================================================ +// Function : compute +// Purpose : +//================================================================ +void HYDROGUI_VTKPrsShape::compute() +{ + if ( !getObject().IsNull() ) + { + buildShape(); + + if ( !myTopoShape.IsNull() ) + { + GEOM_Actor* anActor = GEOM_Actor::New(); + anActor->SetShape( myTopoShape, VTK_MIN_DEFLECTION ); + anActor->setIO( getIO() ); + AddObject( anActor ); + + anActor->Delete(); + } + } +} + + +void HYDROGUI_VTKPrsShape::buildShape() +{ + Handle(HYDROData_Entity) anObject = getObject(); + // Try to retrieve information from object + if ( !anObject.IsNull() ) + { + Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( anObject->Label() ); + + if ( anObject->IsKind( STANDARD_TYPE(HYDROData_ImmersibleZone) ) ) + { + Handle(HYDROData_ImmersibleZone) aZoneObj = + Handle(HYDROData_ImmersibleZone)::DownCast( anObject ); + + TopoDS_Shape aZoneShape = aZoneObj->GetTopShape(); + if ( !aZoneShape.IsNull() ) { + if ( aZoneShape.ShapeType() == TopAbs_FACE ) { + TopoDS_Face aZoneFace = TopoDS::Face( aZoneShape ); + setFace( aZoneFace, false, false ); + } else { + myTopoShape = aZoneShape; + } + } + + QColor aFillingColor = aZoneObj->GetFillingColor(); + QColor aBorderColor = aZoneObj->GetBorderColor(); + + //setFillingColor( aFillingColor, false, false ); + //setBorderColor( aBorderColor, false, false ); + } + else if ( anObject->IsKind( STANDARD_TYPE(HYDROData_PolylineXY) ) ) + { + Handle(HYDROData_PolylineXY) aPolyline = + Handle(HYDROData_PolylineXY)::DownCast( anObject ); + + TopoDS_Shape aPolylineShape = aPolyline->GetShape(); + + if ( !aPolylineShape.IsNull() ) { + if ( aPolylineShape.ShapeType() == TopAbs_WIRE ) { + TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolylineShape ); + setWire( aPolylineWire, false, false ); + } else { + myTopoShape = aPolylineShape; + } + } + + QColor aWireColor = aPolyline->GetWireColor(); + //setBorderColor( aWireColor, false, false ); + } + else if ( anObject->IsKind( STANDARD_TYPE(HYDROData_Polyline3D) ) ) + { + Handle(HYDROData_Polyline3D) aPolyline = + Handle(HYDROData_Polyline3D)::DownCast( anObject ); + + TopoDS_Shape aPolylineShape = aPolyline->GetShape3D(); + + if ( !aPolylineShape.IsNull() ) { + if ( aPolylineShape.ShapeType() == TopAbs_WIRE ) { + TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolylineShape ); + setWire( aPolylineWire, false, false ); + } else { + myTopoShape = aPolylineShape; + } + } + + QColor aWireColor = aPolyline->GetBorderColor(); + //setBorderColor( aWireColor, false, false ); + } + else if ( anObject->IsKind( STANDARD_TYPE(HYDROData_Zone) ) ) + { + Handle(HYDROData_Zone) aZone = + Handle(HYDROData_Zone)::DownCast( anObject ); + + TopoDS_Face aZoneFace = TopoDS::Face( aZone->GetShape() ); + + setFace( aZoneFace, false, false ); + if (aZone->IsMergingNeed() && aZone->GetMergeType() == HYDROData_Zone::Merge_UNKNOWN ) + { + // Red color for a zone with bathymetry conflict + //setFillingColor( Qt::red ); + } + else + { + // Generate the filling color for zone + QStringList aGeomObjectsNames; + + HYDROData_SequenceOfObjects aRefObjects = aZone->GetGeometryObjects(); + HYDROData_SequenceOfObjects::Iterator anIter( aRefObjects ); + for ( ; anIter.More(); anIter.Next() ) + { + Handle(HYDROData_Object) aRefbject = + Handle(HYDROData_Object)::DownCast( anIter.Value() ); + if ( aRefbject.IsNull() ) + continue; + + QString aRefObjectName = aRefbject->GetName(); + if ( aRefObjectName.isEmpty() ) + continue; + + aGeomObjectsNames.append( aRefObjectName ); + } + + //setFillingColor( HYDROGUI_Tool::GenerateFillingColor( aDocument, aGeomObjectsNames ) ); + } + } + else if ( anObject->IsKind( STANDARD_TYPE(HYDROData_Image) ) ) + { + } + else if ( anObject->IsKind( STANDARD_TYPE(HYDROData_Profile) ) ) + { + Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile)::DownCast( anObject ); + + TopoDS_Wire aProfileWire; + + if ( aProfile->IsValid() ) { + TopoDS_Shape aProfileShape = aProfile->GetShape3D(); + + if ( !aProfileShape.IsNull() && + aProfileShape.ShapeType() == TopAbs_WIRE ) { + aProfileWire = TopoDS::Wire( aProfileShape ); + } + } + + setWire( aProfileWire, false, false ); + + QColor aWireColor = aProfile->GetBorderColor(); + //setBorderColor( aWireColor, false, false ); + } + else if ( anObject->IsKind( STANDARD_TYPE(HYDROData_Stream) ) || + anObject->IsKind( STANDARD_TYPE(HYDROData_Channel) ) || + anObject->IsKind( STANDARD_TYPE(HYDROData_Obstacle) ) ) + { + Handle(HYDROData_Object) aGeomObject = + Handle(HYDROData_Object)::DownCast( anObject ); + + TopoDS_Shape anObjShape = aGeomObject->GetTopShape(); + + setShape( anObjShape, false, false ); + + QColor aFillingColor = aGeomObject->GetFillingColor(); + QColor aBorderColor = aGeomObject->GetBorderColor(); + + //setFillingColor( aFillingColor, false, false ); + //setBorderColor( aBorderColor, false, false ); + } + else if ( anObject->IsKind( STANDARD_TYPE(HYDROData_DummyObject3D) ) ) + { + Handle(HYDROData_DummyObject3D) anObject3D = + Handle(HYDROData_DummyObject3D)::DownCast( anObject ); + TopoDS_Shape aShape3D = anObject3D->GetShape(); + + setShape( aShape3D, false, false ); + + QColor aFillingColor = anObject3D->GetFillingColor(); + QColor aBorderColor = anObject3D->GetBorderColor(); + + //setFillingColor( aFillingColor, false, false ); + //setBorderColor( aBorderColor, false, false ); + } + } +} + +void HYDROGUI_VTKPrsShape::setWire( const TopoDS_Wire& theWire, + const bool theToDisplay, + const bool theIsUpdateViewer ) +{ + myTopoShape = theWire; +} + +void HYDROGUI_VTKPrsShape::setFaces( const TopoDS_Compound& theWires, + const bool theToDisplay, + const bool theIsUpdateViewer ) +{ + TopExp_Explorer anExp( theWires, TopAbs_WIRE ); + TopoDS_Compound aCompound; + BRep_Builder aBuilder; + aBuilder.MakeCompound( aCompound ); + + for ( ; anExp.More(); anExp.Next() ) { + TopoDS_Wire aWire = TopoDS::Wire( anExp.Current() ); + if ( aWire.IsNull() ) { + continue; + } + + BRepBuilderAPI_MakeFace aMakeFace( aWire, Standard_True ); + aMakeFace.Build(); + if( aMakeFace.IsDone() ) { + aBuilder.Add( aCompound, aMakeFace.Face() ); + } + } + + myTopoShape = aCompound; +} + +void HYDROGUI_VTKPrsShape::setFace( const TopoDS_Wire& theWire, + const bool theToDisplay, + const bool theIsUpdateViewer ) +{ + BRepBuilderAPI_MakeFace aFaceBuilder( theWire, Standard_True ); + aFaceBuilder.Build(); + if( aFaceBuilder.IsDone() ) + { + TopoDS_Face aFace = aFaceBuilder.Face(); + setFace( aFace, theToDisplay, theIsUpdateViewer ); + } +} + +void HYDROGUI_VTKPrsShape::setFace( const TopoDS_Face& theFace, + const bool theToDisplay, + const bool theIsUpdateViewer ) +{ + myTopoShape = theFace; +} + +void HYDROGUI_VTKPrsShape::setShape( const TopoDS_Shape& theShape, + const bool theToDisplay, + const bool theIsUpdateViewer ) +{ + myTopoShape = theShape; +} diff --git a/src/HYDROGUI/HYDROGUI_VTKPrsShape.h b/src/HYDROGUI/HYDROGUI_VTKPrsShape.h new file mode 100644 index 00000000..54d9e471 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_VTKPrsShape.h @@ -0,0 +1,89 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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. +// +// 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 +// + +#ifndef HYDROGUI_VTK_PRS_SHAPE_H +#define HYDROGUI_VTK_PRS_SHAPE_H + +#include "HYDROGUI_VTKPrs.h" + +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +class TopoDS_Shape; + +/* + Class : HYDROGUI_VTKPrsShape + Description : Presentation for HYDRO object on the base of OCC shape +*/ +class HYDROGUI_VTKPrsShape : public HYDROGUI_VTKPrs +{ +public: + HYDROGUI_VTKPrsShape( const Handle(HYDROData_Entity)& theObject ); + virtual ~HYDROGUI_VTKPrsShape(); + + virtual void compute(); + + //! Get the range of colored + void setLookupTable( vtkScalarsToColors* theTable ) { myLookupTable = theTable; } + +protected: + virtual vtkMapper* mapper() { return myMapper.GetPointer(); } + + void buildShape(); + + virtual void setWire( const TopoDS_Wire& theWire, + const bool theToDisplay = true, + const bool theIsUpdateViewer = true ); + + virtual void setFaces( const TopoDS_Compound& theWires, + const bool theToDisplay = true, + const bool theIsUpdateViewer = true ); + + virtual void setFace( const TopoDS_Wire& theWire, + const bool theToDisplay = true, + const bool theIsUpdateViewer = true ); + + virtual void setFace( const TopoDS_Face& theFace, + const bool theToDisplay = true, + const bool theIsUpdateViewer = true ); + + virtual void setShape( const TopoDS_Shape& theShape, + const bool theToDisplay = true, + const bool theIsUpdateViewer = true ); +private: + vtkWeakPointer< vtkScalarsToColors > myLookupTable; + vtkNew< vtkPolyDataMapper > myMapper; + TopoDS_Shape myTopoShape; +}; + +#endif diff --git a/src/HYDROGUI/HYDROGUI_VTKPrsShapeDriver.cxx b/src/HYDROGUI/HYDROGUI_VTKPrsShapeDriver.cxx new file mode 100644 index 00000000..cb8d03f9 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_VTKPrsShapeDriver.cxx @@ -0,0 +1,55 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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. +// +// 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 +// + +#include "HYDROGUI_VTKPrsShapeDriver.h" + +#include "HYDROGUI_VTKPrsShape.h" + +#include + +HYDROGUI_VTKPrsShapeDriver::HYDROGUI_VTKPrsShapeDriver( vtkScalarBarActor* theScalarBar ) +{ + myScalarBar = theScalarBar; +} + +HYDROGUI_VTKPrsShapeDriver::~HYDROGUI_VTKPrsShapeDriver() +{ +} + +bool HYDROGUI_VTKPrsShapeDriver::Update( const Handle(HYDROData_Entity)& theObj, + HYDROGUI_VTKPrs*& thePrs ) +{ + HYDROGUI_VTKPrsDriver::Update( theObj, thePrs ); + + if( theObj.IsNull() ) + return false; + + if( !thePrs ) + thePrs = new HYDROGUI_VTKPrsShape( theObj ); + + HYDROGUI_VTKPrsShape* aPrsShape = (HYDROGUI_VTKPrsShape*)thePrs; + // Update global colors table during compute if necessary + aPrsShape->setLookupTable( myScalarBar->GetLookupTable() ); + aPrsShape->compute(); + + return true; +} diff --git a/src/HYDROGUI/HYDROGUI_VTKPrsShapeDriver.h b/src/HYDROGUI/HYDROGUI_VTKPrsShapeDriver.h new file mode 100644 index 00000000..753df640 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_VTKPrsShapeDriver.h @@ -0,0 +1,61 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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. +// +// 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 +// + +#ifndef HYDROGUI_VTKPrsShapeDRIVER_H +#define HYDROGUI_VTKPrsShapeDRIVER_H + +#include "HYDROGUI_VTKPrsDriver.h" + +#include + +/** + * \class HYDROGUI_VTKPrsShapeDriver + * \brief Presentation driver for hydro objects on the base of OCC shapes. + */ +class HYDROGUI_VTKPrsShapeDriver : public HYDROGUI_VTKPrsDriver +{ +public: + /** + * \brief Constructor. + */ + HYDROGUI_VTKPrsShapeDriver( vtkScalarBarActor* theScalarBar ); + + /** + * \brief Destructor. + */ + virtual ~HYDROGUI_VTKPrsShapeDriver(); + +public: + /** + * \brief Update or create the presentation on a basis of data object. + * \param theObj data object + * \param thePrs presentation + * \return status of the operation + */ + virtual bool Update( const Handle(HYDROData_Entity)& theObj, + HYDROGUI_VTKPrs*& thePrs ); + +private: + vtkScalarBarActor* myScalarBar; +}; + +#endif -- 2.39.2