From c3968d49558df721702b1af4506670907c909c38 Mon Sep 17 00:00:00 2001 From: asl Date: Tue, 20 Oct 2015 11:35:39 +0300 Subject: [PATCH] #662: custom mesh for presentation --- src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx | 119 +++++++++++----------- src/HYDROGUI/HYDROGUI_LandCoverMapPrs.h | 6 +- 2 files changed, 64 insertions(+), 61 deletions(-) diff --git a/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx b/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx index f74fb1a5..a71d556c 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx @@ -20,26 +20,22 @@ #include #include #include -#include -#include -#include -#include +#include +#include #include +#include +#include #include -#include -#include -#include #include -#include #include #include #include -IMPLEMENT_STANDARD_HANDLE( HYDROGUI_LandCoverMapPrs, AIS_Shape ) -IMPLEMENT_STANDARD_RTTIEXT( HYDROGUI_LandCoverMapPrs, AIS_Shape ) +IMPLEMENT_STANDARD_HANDLE( HYDROGUI_LandCoverMapPrs, AIS_InteractiveObject ) +IMPLEMENT_STANDARD_RTTIEXT( HYDROGUI_LandCoverMapPrs, AIS_InteractiveObject ) HYDROGUI_LandCoverMapPrs::HYDROGUI_LandCoverMapPrs( const Handle(HYDROData_LandCoverMap)& theMap ) - : AIS_Shape( TopoDS_Shape() ) + : AIS_InteractiveObject() { SetLandCoverMap( theMap ); } @@ -56,7 +52,6 @@ Handle(HYDROData_LandCoverMap) HYDROGUI_LandCoverMapPrs::GetLandCoverMap() const void HYDROGUI_LandCoverMapPrs::SetLandCoverMap( const Handle(HYDROData_LandCoverMap)& theMap ) { myLCMap = theMap; - Set( theMap->GetShape() ); } Handle(Aspect_ColorScale) HYDROGUI_LandCoverMapPrs::GetColorScale() const @@ -113,6 +108,47 @@ Quantity_Color HYDROGUI_LandCoverMapPrs::GetColor( const QString& theStricklerTy return Quantity_Color(); } +void DrawTriangulation( const Handle(Prs3d_Presentation)& thePresentation, + const Handle(Poly_Triangulation)& theTriangulation, + const Quantity_Color& theColor ) +{ + const TColgp_Array1OfPnt& aNodesArray = theTriangulation->Nodes(); + int aNbNodes = aNodesArray.Length(); + + const Poly_Array1OfTriangle& aTrianglesArray = theTriangulation->Triangles(); + int aNbTriangles = aTrianglesArray.Length(); + + Handle( Graphic3d_ArrayOfTriangles ) anArray = new Graphic3d_ArrayOfTriangles + ( aNbNodes, aNbTriangles * 3, Standard_True, Standard_True, Standard_False ); + + Prs3d_Root::NewGroup( thePresentation ); + Handle( Graphic3d_Group ) aGroup = Prs3d_Root::CurrentGroup( thePresentation ); + Handle( Graphic3d_AspectFillArea3d ) anAspect = new Graphic3d_AspectFillArea3d(); + Graphic3d_MaterialAspect aMaterialAspect( Graphic3d_NOM_PLASTIC ); + aMaterialAspect.SetColor( theColor ); + anAspect->SetFrontMaterial( aMaterialAspect ); + anAspect->SetBackMaterial( aMaterialAspect ); + + Standard_Integer i; + + for( i = aNodesArray.Lower(); i <= aNodesArray.Upper(); i++ ) + { + anArray->AddVertex( aNodesArray( i ), theColor ); + anArray->SetVertexNormal( i, 0, 0, 1 ); + } + + Standard_Integer anIndexTriangle[3] = { 0, 0, 0 }; + for( i = aTrianglesArray.Lower(); i<= aTrianglesArray.Upper(); i++ ) + { + aTrianglesArray( i ).Get( anIndexTriangle[0], anIndexTriangle[1], anIndexTriangle[2] ); + anArray->AddEdge( anIndexTriangle[0] ); + anArray->AddEdge( anIndexTriangle[1] ); + anArray->AddEdge( anIndexTriangle[2] ); + } + aGroup->AddPrimitiveArray( anArray ); + //aGroup->SetGroupPrimitivesAspect( anAspect ); +} + void HYDROGUI_LandCoverMapPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode ) @@ -121,46 +157,25 @@ void HYDROGUI_LandCoverMapPrs::Compute( const Handle(PrsMgr_PresentationManager3 return; thePresentation->Clear(); - SetMaterial( Graphic3d_NOM_PLASTIC ); - - Quantity_Color anEdgeColor = Quantity_NOC_WHITE; - myDrawer->LineAspect()->SetColor( anEdgeColor ); - myDrawer->FaceBoundaryAspect()->SetColor( anEdgeColor ); - myDrawer->FreeBoundaryAspect()->SetColor( anEdgeColor ); - myDrawer->UIsoAspect()->SetNumber( 0 ); - myDrawer->VIsoAspect()->SetNumber( 0 ); + const double aLinearDeflection = 1E-2; + BRepMesh_IncrementalMesh aMesh( myLCMap->GetShape(), aLinearDeflection ); + aMesh.Perform(); + bool isOK = aMesh.IsDone(); switch( theMode ) { - case AIS_WireFrame: case AIS_Shaded: { - bool isShaded = theMode==AIS_Shaded; HYDROData_LandCoverMap::Iterator anIt( myLCMap ); for( ; anIt.More(); anIt.Next() ) { TopoDS_Face aFace = anIt.Face(); - if( isShaded ) - { - QString aStricklerType = anIt.StricklerType(); - Quantity_Color aColor = GetColor( aStricklerType ); - Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d(); - Graphic3d_MaterialAspect aMaterialAspect( Graphic3d_NOM_PLASTIC ); - aMaterialAspect.SetColor( aColor ); - anAspect->SetFrontMaterial( aMaterialAspect ); - anAspect->SetBackMaterial( aMaterialAspect ); - - Handle(Graphic3d_AspectFillArea3d) aGlobalAspect = myDrawer->ShadingAspect()->Aspect(); - myDrawer->ShadingAspect()->SetAspect( anAspect ); - StdPrs_ShadedShape::Add( thePresentation, aFace, myDrawer ); - myDrawer->ShadingAspect()->SetAspect( aGlobalAspect ); - - StdPrs_WFShape::Add( thePresentation, aFace, myDrawer ); - } - else - { - StdPrs_WFShape::Add( thePresentation, aFace, myDrawer ); - } + QString aStricklerType = anIt.StricklerType(); + Quantity_Color aColor = GetColor( aStricklerType ); + + TopLoc_Location aLocation; + Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation( aFace, aLocation ); + DrawTriangulation( thePresentation, aTriangulation, aColor ); } } break; @@ -177,26 +192,14 @@ void HYDROGUI_LandCoverMapPrs::ComputeSelection( const Handle(SelectMgr_Selectio if( theMode==0 ) { - theSelection->Clear(); + /*theSelection->Clear(); Bnd_Box B = BoundingBox(); Handle(StdSelect_BRepOwner) anOwner = new StdSelect_BRepOwner( myLCMap->GetShape(), this ); Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox( anOwner, B ); - theSelection->Add( aSensitiveBox ); + theSelection->Add( aSensitiveBox );*/ } else { - Standard_Real aDeflection = Prs3d::GetDeflection( myLCMap->GetShape(), myDrawer ); - HYDROData_LandCoverMap::Iterator anIt( myLCMap ); - for( ; anIt.More(); anIt.Next() ) - { - StdSelect_BRepSelectionTool::Load( theSelection, - this, - anIt.Face(), - TopAbs_FACE, - aDeflection, - myDrawer->HLRAngle(), - myDrawer->IsAutoTriangulation()); - } - StdSelect::SetDrawerForBRepOwner( theSelection, myDrawer ); + //TODO } } diff --git a/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.h b/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.h index 1900f2ab..7a930bc0 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.h +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.h @@ -21,12 +21,12 @@ #include #include -#include +#include #include -DEFINE_STANDARD_HANDLE( HYDROGUI_LandCoverMapPrs, AIS_Shape ) +DEFINE_STANDARD_HANDLE( HYDROGUI_LandCoverMapPrs, AIS_InteractiveObject ) -class HYDROGUI_LandCoverMapPrs : public AIS_Shape +class HYDROGUI_LandCoverMapPrs : public AIS_InteractiveObject { public: DEFINE_STANDARD_RTTI( HYDROGUI_LandCoverMapPrs ); -- 2.39.2