From 5065bfaaab947084a631e5db911f098c7ace8948 Mon Sep 17 00:00:00 2001 From: asl Date: Tue, 26 Aug 2014 07:01:34 +0000 Subject: [PATCH] refs #432: bathymetry in OCCT viewer --- src/HYDROGUI/HYDROGUI_Module.cxx | 17 +++ src/HYDROGUI/HYDROGUI_Module.h | 2 + src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx | 72 ++++++++++++- src/HYDROGUI/HYDROGUI_OCCDisplayer.h | 2 + src/HYDROGUI/HYDROGUI_Shape.cxx | 117 ++++++++++++++++----- src/HYDROGUI/HYDROGUI_Shape.h | 15 ++- src/HYDROGUI/HYDROGUI_ShowHideOp.cxx | 6 +- src/HYDROGUI/HYDROGUI_Tool.cxx | 3 +- src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.cxx | 2 +- 9 files changed, 201 insertions(+), 35 deletions(-) diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index bd3b1a16..6f2a8e0d 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -937,6 +937,23 @@ void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject, } /////////////////// OCC SHAPES PROCESSING +QList HYDROGUI_Module::getObjectShapes( const int theViewId, + ObjectKind theKind ) const +{ + QList aResult; + + if ( myShapesMap.contains( theViewId ) ) + { + const ListOfShapes& aViewShapes = myShapesMap.value( theViewId ); + foreach ( HYDROGUI_Shape* aShape, aViewShapes ) + { + if( aShape && aShape->getObject()->GetKind()==theKind ) + aResult.append( aShape ); + } + } + return aResult; +} + HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId, const Handle(HYDROData_Entity)& theObject ) const { diff --git a/src/HYDROGUI/HYDROGUI_Module.h b/src/HYDROGUI/HYDROGUI_Module.h index e2dee3ee..963a734e 100644 --- a/src/HYDROGUI/HYDROGUI_Module.h +++ b/src/HYDROGUI/HYDROGUI_Module.h @@ -135,6 +135,8 @@ public: */ void setIsToUpdate( const Handle(HYDROData_Entity)& theObject, const bool theState = true ); + QList getObjectShapes( const int theViewId, + ObjectKind theKind ) const; HYDROGUI_Shape* getObjectShape( const int theViewId, const Handle(HYDROData_Entity)& theObject ) const; void setObjectShape( const int theViewId, diff --git a/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx b/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx index 310e84de..43df0948 100644 --- a/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx +++ b/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx @@ -34,6 +34,8 @@ #include #include +#include + #include #include @@ -42,6 +44,7 @@ #include #include #include +#include HYDROGUI_OCCDisplayer::HYDROGUI_OCCDisplayer( HYDROGUI_Module* theModule ) : HYDROGUI_AbstractDisplayer( theModule ) @@ -120,6 +123,7 @@ void HYDROGUI_OCCDisplayer::EraseAll( const int theViewerId ) return; module()->removeViewShapes( (size_t)aViewer ); + UpdateColorScale( aViewer ); } void HYDROGUI_OCCDisplayer::Erase( const HYDROData_SequenceOfObjects& theObjs, @@ -138,6 +142,7 @@ void HYDROGUI_OCCDisplayer::Erase( const HYDROData_SequenceOfObjects& theObjs, module()->removeObjectShape( (size_t)aViewer, anObj ); } aViewer->update(); + UpdateColorScale( aViewer ); } HYDROGUI_Shape* HYDROGUI_OCCDisplayer::createShape( const int theViewerId, @@ -275,6 +280,8 @@ void HYDROGUI_OCCDisplayer::Display( const HYDROData_SequenceOfObjects& theObjs, else if ( !aCtx.IsNull() ) { // TODO: determine if this code is necessary (added as a fix for issue# 359) aCtx->UpdateSelected(); } + + UpdateColorScale( aViewer ); } void HYDROGUI_OCCDisplayer::purgeObjects( const int theViewerId ) @@ -352,6 +359,7 @@ bool HYDROGUI_OCCDisplayer::Display( const Handle(HYDROData_Entity)& theObject, aRes = true; } + UpdateColorScale( theViewer ); return aRes; } @@ -377,6 +385,66 @@ void HYDROGUI_OCCDisplayer::SetZLayer( const OCCViewer_Viewer* theViewer, // Set Z layer if ( anObjShape ) { - aCtx->SetZLayer( anObjShape->getAISShape(), theZLayerId ); + aCtx->SetZLayer( anObjShape->getAISObject(), theZLayerId ); + } +} + +void HYDROGUI_OCCDisplayer::UpdateColorScale( const OCCViewer_Viewer* theViewer ) +{ + OCCViewer_ViewWindow* aWnd = dynamic_cast( theViewer->getViewManager()->getActiveView() ); + Handle(V3d_View) aView = aWnd->getViewPort()->getView(); + + int aViewerId = (size_t)theViewer;//TODO: check if viewer id is correct + QList aBaths = module()->getObjectShapes( aViewerId, KIND_BATHYMETRY ); + + bool isDisplayColorScale = !aBaths.empty(); + Standard_Real anXPos = 0.05; //TODO + Standard_Real anYPos = 0.1; //TODO + Standard_Real aWidth = 0.2; //TODO + Standard_Real aHeight = 0.5; //TODO + Standard_Integer aTextHeight = 14; //TODO + Standard_Integer aNbIntervals = 20; //TODO + TCollection_ExtendedString aColorScaleTitle = "";//TODO + + Standard_Real aColorScaleMin = 0, aColorScaleMax = 1, aMin, aMax; + bool isFirst = true; + foreach( HYDROGUI_Shape* aBathShape, aBaths ) + { + aBathShape->GetRange( aMin, aMax ); + + if( isFirst || aMin < aColorScaleMin ) + aColorScaleMin = aMin; + if( isFirst || aMax > aColorScaleMax ) + aColorScaleMax = aMax; + + isFirst = false; + } + + if( isDisplayColorScale ) + { + Handle(Aspect_ColorScale) aColorScale = aView->ColorScale(); + if( !aColorScale.IsNull() ) + { + aColorScale->SetXPosition( anXPos ); + aColorScale->SetYPosition( anYPos ); + aColorScale->SetWidth( aWidth ); + aColorScale->SetHeight( aHeight ); + + aColorScale->SetTextHeight( aTextHeight ); + aColorScale->SetNumberOfIntervals( aNbIntervals ); + + aColorScale->SetTitle( aColorScaleTitle ); + aColorScale->SetRange( aColorScaleMin, aColorScaleMax ); + + foreach( HYDROGUI_Shape* aBathShape, aBaths ) + aBathShape->UpdateWithColorScale( aColorScale ); + } + if( !aView->ColorScaleIsDisplayed() ) + aView->ColorScaleDisplay(); + } + else + { + if( aView->ColorScaleIsDisplayed() ) + aView->ColorScaleErase(); } -} \ No newline at end of file +} diff --git a/src/HYDROGUI/HYDROGUI_OCCDisplayer.h b/src/HYDROGUI/HYDROGUI_OCCDisplayer.h index ffa2ef9f..95b391cf 100644 --- a/src/HYDROGUI/HYDROGUI_OCCDisplayer.h +++ b/src/HYDROGUI/HYDROGUI_OCCDisplayer.h @@ -110,6 +110,8 @@ protected: */ void purgeObjects( const int theViewerId ); + void UpdateColorScale( const OCCViewer_Viewer* ); + private: /** * \brief Creates new OCC shape. diff --git a/src/HYDROGUI/HYDROGUI_Shape.cxx b/src/HYDROGUI/HYDROGUI_Shape.cxx index eb05a9b4..f18e3870 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.cxx +++ b/src/HYDROGUI/HYDROGUI_Shape.cxx @@ -27,7 +27,7 @@ #include #include - +#include #include #include @@ -39,8 +39,11 @@ #include #include +#include + #include #include +#include #include #include #include @@ -66,7 +69,7 @@ #include #include #include - +#include #include #include @@ -397,6 +400,11 @@ void HYDROGUI_Shape::update( const bool theIsUpdateViewer ) setShape( aCompound, false, false ); } + else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Bathymetry) ) ) + { + buildShape(); + updateShape( false, false ); + } } if ( myShape.IsNull() || !isVisible() ) @@ -584,29 +592,48 @@ void HYDROGUI_Shape::setZLayer( const int theZLayer ) myContext->SetZLayer( myShape, myZLayer ); } +#include void HYDROGUI_Shape::buildShape() { // Erase previously created shape erase(); - if ( myTopoShape.IsNull() ) { + Handle_HYDROData_Bathymetry aBath = Handle_HYDROData_Bathymetry::DownCast( myObject ); + bool isBath = !aBath.IsNull(); + + if( !isBath && myTopoShape.IsNull() ) { myShape.Nullify(); return; } QString aTextureFileName = getTextureFileName(); bool anIsTexture = !aTextureFileName.isEmpty(); - if ( anIsTexture ) { myShape = new AIS_TexturedShape( myTopoShape ); } + else if( isBath ) + { + Handle_AIS_PointCloud aPntCloud = new AIS_PointCloud(); + aPntCloud->Attributes()->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_WHITE, 1.0)); + + myShape = aPntCloud; + const HYDROData_Bathymetry::AltitudePoints& aBathPoints = aBath->GetAltitudePoints(); + int aLower = aBathPoints.Lower(); + int anUpper = aBathPoints.Upper(); + myCoords = new TColgp_HArray1OfPnt( aLower, anUpper ); + myColors = new Quantity_HArray1OfColor( aLower, anUpper ); + for( int i=aLower; i<=anUpper; i++ ) + myCoords->SetValue( i, aBathPoints.Value( i ) ); + } else { myShape = new AIS_Shape( myTopoShape ); } - myShape->SetHLRAngleAndDeviation( 0.001 ); + Handle_AIS_Shape anAISShape = Handle_AIS_Shape::DownCast( myShape ); + if( !anAISShape.IsNull() ) + anAISShape ->SetHLRAngleAndDeviation( 0.001 ); if ( !myObject.IsNull() ) myShape->SetOwner( myObject ); @@ -733,38 +760,41 @@ void HYDROGUI_Shape::colorShapeBorder( const QColor& theColor ) getQuantityColorVal( theColor.green() ), getQuantityColorVal( theColor.blue() ), Quantity_TOC_RGB ); - - if ( myTopoShape.ShapeType() == TopAbs_WIRE ) // Note that we display polylines in shaded mode - { - myShape->SetColor( aBorderColor ); - } else if ( myDisplayMode == AIS_Shaded ) + if( !myTopoShape.IsNull() ) { - if ( theColor.alpha() == 0 ) + if ( myTopoShape.ShapeType() == TopAbs_WIRE ) // Note that we display polylines in shaded mode { - anAttributes->SetFaceBoundaryDraw( false ); + myShape->SetColor( aBorderColor ); } - else + else if ( myDisplayMode == AIS_Shaded ) { - anAttributes->SetFaceBoundaryDraw( true ); - - Handle(Prs3d_LineAspect) aBoundaryAspect = anAttributes->FaceBoundaryAspect(); - if ( !aBoundaryAspect.IsNull() ) + if ( theColor.alpha() == 0 ) { - aBoundaryAspect->SetColor( aBorderColor ); - anAttributes->SetFaceBoundaryAspect( aBoundaryAspect ); + anAttributes->SetFaceBoundaryDraw( false ); } - Handle(Prs3d_LineAspect) aWireAspect = anAttributes->WireAspect(); - if ( !aWireAspect.IsNull() ) + else { - aWireAspect->SetColor( aBorderColor ); - anAttributes->SetWireAspect( aWireAspect ); + anAttributes->SetFaceBoundaryDraw( true ); + + Handle(Prs3d_LineAspect) aBoundaryAspect = anAttributes->FaceBoundaryAspect(); + if ( !aBoundaryAspect.IsNull() ) + { + aBoundaryAspect->SetColor( aBorderColor ); + anAttributes->SetFaceBoundaryAspect( aBoundaryAspect ); + } + Handle(Prs3d_LineAspect) aWireAspect = anAttributes->WireAspect(); + if ( !aWireAspect.IsNull() ) + { + aWireAspect->SetColor( aBorderColor ); + anAttributes->SetWireAspect( aWireAspect ); + } } } - } - else if ( myDisplayMode == AIS_WireFrame ) - { - myShape->SetColor( aBorderColor ); + else if ( myDisplayMode == AIS_WireFrame ) + { + myShape->SetColor( aBorderColor ); + } } } @@ -815,3 +845,36 @@ QImage HYDROGUI_Shape::reduceTexture( const QImage& theImage, const int theSizeL } return theImage.scaled( aWidth, aHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation ); } + +void HYDROGUI_Shape::GetRange( double& theMin, double& theMax ) const +{ + theMin = 0; + theMax = 0; + if( myCoords.IsNull() ) + return; + + bool isFirst = true; + for( int i=myCoords->Lower(), n=myCoords->Upper(); i<=n; i++ ) + { + double aValue = myCoords->Value( i ).Z(); + if( isFirst || aValue < theMin ) + theMin = aValue; + if( isFirst || aValue > theMax ) + theMax = aValue; + isFirst = false; + } +} + +void HYDROGUI_Shape::UpdateWithColorScale( const Handle(Aspect_ColorScale)& theColorScale ) +{ + for( int i=myCoords->Lower(), n=myCoords->Upper(); i<=n; i++ ) + { + double z = myCoords->Value( i ).Z(); + Quantity_Color aColor; + theColorScale->FindColor( z, aColor ); + myColors->SetValue( i, aColor ); + } + Handle_AIS_PointCloud aPntCloud = Handle_AIS_PointCloud::DownCast( myShape ); + aPntCloud->SetPoints( myCoords, myColors ); + myContext->Redisplay( aPntCloud, Standard_False ); +} diff --git a/src/HYDROGUI/HYDROGUI_Shape.h b/src/HYDROGUI/HYDROGUI_Shape.h index 6226f542..c5b3b41f 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.h +++ b/src/HYDROGUI/HYDROGUI_Shape.h @@ -24,7 +24,10 @@ #define HYDROGUI_SHAPE_H #include -#include +#include +#include +#include +#include #include @@ -99,10 +102,13 @@ public: const bool theIsUpdateViewer = true ); virtual QString getTextureFileName() const; - virtual Handle(AIS_Shape) getAISShape() const { return myShape; } + virtual Handle(AIS_InteractiveObject) getAISObject() const { return myShape; } void setZLayer( const int theZLayer ); + void GetRange( double& theMin, double& theMax ) const; + void UpdateWithColorScale( const Handle(Aspect_ColorScale)& ); + protected: virtual void buildShape(); virtual void updateShape( const bool theToDisplay = true, @@ -123,7 +129,7 @@ private: private: Handle(AIS_InteractiveContext) myContext; Handle(HYDROData_Entity) myObject; - Handle(AIS_Shape) myShape; + Handle(AIS_InteractiveObject) myShape; int myZLayer; @@ -139,6 +145,9 @@ private: QColor myHighlightColor; QString myTextureFileName; + + Handle_TColgp_HArray1OfPnt myCoords; + Handle_Quantity_HArray1OfColor myColors; }; #endif diff --git a/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx b/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx index d754a33a..4dba86de 100644 --- a/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx @@ -147,7 +147,11 @@ void HYDROGUI_ShowHideOp::startOperation() } else if ( anObject->GetKind() == KIND_BATHYMETRY && aVisibility ) { - if ( !(anUpdateFlags & UF_VTKViewer) ) + if ( anUpdateFlags & UF_OCCViewer ) + { + aModule->setObjectVisible( aViewId, anObject, aVisibility ); + } + else if ( !(anUpdateFlags & UF_VTKViewer) ) { // Activate VTK viewer if show a bathymetry aVTKMgr = aModule->getApp()->viewManager( SVTK_Viewer::Type() ); diff --git a/src/HYDROGUI/HYDROGUI_Tool.cxx b/src/HYDROGUI/HYDROGUI_Tool.cxx index 51404eae..75526f52 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.cxx +++ b/src/HYDROGUI/HYDROGUI_Tool.cxx @@ -229,7 +229,8 @@ bool HYDROGUI_Tool::IsObjectHasPresentation( const Handle(HYDROData_Entity)& the anObjectKind == KIND_STREAM || anObjectKind == KIND_CHANNEL || anObjectKind == KIND_DIGUE || - anObjectKind == KIND_DUMMY_3D + anObjectKind == KIND_DUMMY_3D || + anObjectKind == KIND_BATHYMETRY #ifdef DEB_GROUPS || anObjectKind == KIND_SHAPES_GROUP || anObjectKind == KIND_SPLITTED_GROUP diff --git a/src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.cxx b/src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.cxx index 97d0d6c1..15006545 100644 --- a/src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.cxx +++ b/src/HYDROGUI/HYDROGUI_VTKPrsBathymetry.cxx @@ -26,7 +26,7 @@ #include #include -#include +#include #include #include #include -- 2.39.2