From 43a665e7af596db7923c377092ff8e5c795f7aca Mon Sep 17 00:00:00 2001 From: vpa Date: Fri, 8 Apr 2016 18:38:15 +0300 Subject: [PATCH] Full support of different display modes was added; Infinite loop on removal of LOD structures was eliminated. --- src/Graphic3d/Graphic3d_CStructure.hxx | 6 ++++++ src/Graphic3d/Graphic3d_LOD.cxx | 1 + src/Graphic3d/Graphic3d_LOD.hxx | 10 ++++++++++ src/Graphic3d/Graphic3d_LODManager.cxx | 16 ++++++++++++++++ src/Graphic3d/Graphic3d_LODManager.hxx | 6 ++++++ src/Graphic3d/Graphic3d_Structure.cxx | 13 +++++++++++-- src/Graphic3d/Graphic3d_Structure.hxx | 6 ++++++ src/MeshVS/MeshVS_Mesh.cxx | 14 ++++++++++++++ src/OpenGl/OpenGl_Structure.cxx | 14 ++++++++++++++ src/OpenGl/OpenGl_Structure.hxx | 12 ++++++++++++ src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx | 6 +++--- 11 files changed, 99 insertions(+), 5 deletions(-) diff --git a/src/Graphic3d/Graphic3d_CStructure.hxx b/src/Graphic3d/Graphic3d_CStructure.hxx index 4cfaed2f67..d7a9470c92 100644 --- a/src/Graphic3d/Graphic3d_CStructure.hxx +++ b/src/Graphic3d/Graphic3d_CStructure.hxx @@ -137,6 +137,12 @@ public: //! iteration number virtual void SetDetailLevelRange (const Standard_Integer theLODIdx, const Standard_Real theFrom, const Standard_Real theTo) = 0; + //! Returns range of LOD. + //! @param theLODIdx corresponds to the index of LOD in map of LOD manager. In case if no LOD was + //! removed, the LODs in map are located in order of addition and IDs are identical to the addition + //! iteration number + virtual void GetDetailLevelRange (const Standard_Integer theLODIdx, Standard_Real& theFrom, Standard_Real& theTo) const = 0; + public: int Id; diff --git a/src/Graphic3d/Graphic3d_LOD.cxx b/src/Graphic3d/Graphic3d_LOD.cxx index a78f9975b9..7386f3eaf6 100644 --- a/src/Graphic3d/Graphic3d_LOD.cxx +++ b/src/Graphic3d/Graphic3d_LOD.cxx @@ -59,5 +59,6 @@ void Graphic3d_LOD::Clear (const Standard_Boolean theWithDestruction) { Handle(Graphic3d_Group) aGroup = myGroups.First(); aGroup->Remove(); + myGroups.Remove (1); } } diff --git a/src/Graphic3d/Graphic3d_LOD.hxx b/src/Graphic3d/Graphic3d_LOD.hxx index 4e6fd00b92..50c5a75950 100644 --- a/src/Graphic3d/Graphic3d_LOD.hxx +++ b/src/Graphic3d/Graphic3d_LOD.hxx @@ -62,6 +62,16 @@ public: return myFrom < theOther.myFrom; } + const Standard_Real To() const + { + return myTo; + } + + const Standard_Real From() const + { + return myFrom; + } + private: Standard_Real myFrom; Standard_Real myTo; diff --git a/src/Graphic3d/Graphic3d_LODManager.cxx b/src/Graphic3d/Graphic3d_LODManager.cxx index c8e696ad67..1c1c52e62c 100644 --- a/src/Graphic3d/Graphic3d_LODManager.cxx +++ b/src/Graphic3d/Graphic3d_LODManager.cxx @@ -97,6 +97,22 @@ void Graphic3d_LODManager::SetRange (Standard_Integer theLODIdx, myIsToSortLODs = Standard_True; } +//======================================================================= +// function : GetRange +// purpose : +//======================================================================= +void Graphic3d_LODManager::GetRange (const Standard_Integer theLODIdx, + Standard_Real& theFrom, + Standard_Real& theTo) const +{ + if (theLODIdx < 1 || theLODIdx > myLODs.Extent()) + return; + + Graphic3d_RangeOfLOD aRange = myLODs.FindKey (theLODIdx)->GetRange(); + theFrom = aRange.From(); + theTo = aRange.To(); +} + //======================================================================= // function : GetCurrentGroups // purpose : diff --git a/src/Graphic3d/Graphic3d_LODManager.hxx b/src/Graphic3d/Graphic3d_LODManager.hxx index 2d1e6206c1..88f7fff816 100644 --- a/src/Graphic3d/Graphic3d_LODManager.hxx +++ b/src/Graphic3d/Graphic3d_LODManager.hxx @@ -67,6 +67,12 @@ public: const Standard_Real theFrom, const Standard_Real theTo); + //! For ranged LODs, returns the distance interval where the LOD will be visible. + //! @param theLODIdx the index of LOD in sorted list + Standard_EXPORT void GetRange (const Standard_Integer theLODIdx, + Standard_Real& theFrom, + Standard_Real& theTo) const; + //! Returns own index of the LOD that is displayed Standard_EXPORT Standard_Boolean HasLODToDisplay (const Handle(Graphic3d_Camera)& theCamera); diff --git a/src/Graphic3d/Graphic3d_Structure.cxx b/src/Graphic3d/Graphic3d_Structure.cxx index 848a33ca1c..3e13945c00 100644 --- a/src/Graphic3d/Graphic3d_Structure.cxx +++ b/src/Graphic3d/Graphic3d_Structure.cxx @@ -1751,9 +1751,18 @@ Standard_Integer Graphic3d_Structure::NbDetailLevels() const //function : SetDetailLevelRange //purpose : //============================================================================= -void Graphic3d_Structure::SetDetailLevelRange (const Standard_Integer theIdOfLOD, const Standard_Real theFrom, const Standard_Real theTo) +void Graphic3d_Structure::SetDetailLevelRange (const Standard_Integer theLODIdx, const Standard_Real theFrom, const Standard_Real theTo) { - myCStructure->SetDetailLevelRange (theIdOfLOD, theFrom, theTo); + myCStructure->SetDetailLevelRange (theLODIdx, theFrom, theTo); +} + +//============================================================================= +//function : GetDetailLevelRange +//purpose : +//============================================================================= +void Graphic3d_Structure::GetDetailLevelRange (const Standard_Integer theLODIdx, Standard_Real& theFrom, Standard_Real& theTo) const +{ + myCStructure->GetDetailLevelRange (theLODIdx, theFrom, theTo); } //============================================================================= diff --git a/src/Graphic3d/Graphic3d_Structure.hxx b/src/Graphic3d/Graphic3d_Structure.hxx index 932d547d54..0523c98b61 100644 --- a/src/Graphic3d/Graphic3d_Structure.hxx +++ b/src/Graphic3d/Graphic3d_Structure.hxx @@ -493,6 +493,12 @@ public: //! iteration number Standard_EXPORT void SetDetailLevelRange (const Standard_Integer theLODIdx, const Standard_Real theFrom, const Standard_Real theTo); + //! Returns range of LOD. + //! @param theLODIdx corresponds to the index of LOD in map of LOD manager. In case if no LOD was + //! removed, the LODs in map are located in order of addition and IDs are identical to the addition + //! iteration number + Standard_EXPORT void GetDetailLevelRange (const Standard_Integer theLODIdx, Standard_Real& theFrom, Standard_Real& theTo) const; + friend class Graphic3d_Group; diff --git a/src/MeshVS/MeshVS_Mesh.cxx b/src/MeshVS/MeshVS_Mesh.cxx index bc7f048e8c..0678b601c3 100644 --- a/src/MeshVS/MeshVS_Mesh.cxx +++ b/src/MeshVS/MeshVS_Mesh.cxx @@ -163,10 +163,24 @@ void MeshVS_Mesh::ComputeLODs (const Handle(PrsMgr_PresentationManager3d)& thePr continue; aLODBldr->SetPresentationManager (thePrsMgr); + SetDataSource (aLODBldr->GetDataSource()); const TColStd_PackedMapOfInteger aTrgIdxs = aLODBldr->GetDataSource()->GetAllElements(); if (!aTrgIdxs.IsEmpty()) aLODBldr->Build (thePrs, aTrgIdxs, aDummy, Standard_True, theMode); } + + // Set up default ranges for LODs in shading or other display modes + if (theMode > 1) + { + const Handle(Prs3d_Presentation)& aWireframePrs = thePrsMgr->Presentation (this, 1)->Presentation(); + for (Standard_Integer aLODIdx = 1; aLODIdx <= myBuilders.Length(); ++aLODIdx) + { + // Get range for wireframe mode + Standard_Real aFrom, aTo = std::numeric_limits::max(); + aWireframePrs->GetDetailLevelRange (aLODIdx, aFrom, aTo); + thePrs->SetDetailLevelRange (aLODIdx, aFrom, aTo); + } + } } //================================================================ diff --git a/src/OpenGl/OpenGl_Structure.cxx b/src/OpenGl/OpenGl_Structure.cxx index fda97d06c9..e2580301de 100644 --- a/src/OpenGl/OpenGl_Structure.cxx +++ b/src/OpenGl/OpenGl_Structure.cxx @@ -809,6 +809,20 @@ void OpenGl_Structure::SetDetailLevelRange (const Standard_Integer theLODIdx, myLODManager->SetRange (theLODIdx, theFrom, theTo); } +//======================================================================= +//function : GetDetailLevelRange +//purpose : +//======================================================================= +void OpenGl_Structure::GetDetailLevelRange (const Standard_Integer theLODIdx, + Standard_Real& theFrom, + Standard_Real& theTo) const +{ + if (myLODManager.IsNull() || theLODIdx < 1 || theLODIdx > myLODManager->NbOfDetailLevels()) + return; + + myLODManager->GetRange (theLODIdx, theFrom, theTo); +} + //======================================================================= //function : DrawGroups //purpose : diff --git a/src/OpenGl/OpenGl_Structure.hxx b/src/OpenGl/OpenGl_Structure.hxx index aee75dcd59..4b13e01351 100644 --- a/src/OpenGl/OpenGl_Structure.hxx +++ b/src/OpenGl/OpenGl_Structure.hxx @@ -106,10 +106,22 @@ public: //! Remove group from this structure Standard_EXPORT virtual void RemoveGroup (const Handle(Graphic3d_Group)& theGroup) Standard_OVERRIDE; + //! Sets range of LOD. + //! @param theLODIdx corresponds to the index of LOD in map of LOD manager. In case if no LOD was + //! removed, the LODs in map are located in order of addition and IDs are identical to the addition + //! iteration number Standard_EXPORT virtual void SetDetailLevelRange (const Standard_Integer theLODIdx, const Standard_Real theFrom, const Standard_Real theTo) Standard_OVERRIDE; + //! Returns range of LOD. + //! @param theLODIdx corresponds to the index of LOD in map of LOD manager. In case if no LOD was + //! removed, the LODs in map are located in order of addition and IDs are identical to the addition + //! iteration number + Standard_EXPORT virtual void GetDetailLevelRange (const Standard_Integer theLODIdx, + Standard_Real& theFrom, + Standard_Real& theTo) const Standard_OVERRIDE; + public: //! @return graphic groups diff --git a/src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx b/src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx index 2865f3bf4b..6ff0a98463 100644 --- a/src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx +++ b/src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx @@ -1292,7 +1292,7 @@ static int MeshGenLODs (Draw_Interpretor& theDI, aMeshParams.Deflection = aMaxDefl; aMeshParams.Angle = 0.5; aMeshParams.Relative = Standard_False; - aMeshParams.InParallel = Standard_False; + aMeshParams.InParallel = Standard_True; aMeshParams.MinSize = Precision::Confusion(); aMeshParams.InternalVerticesMode = Standard_True; aMeshParams.ControlSurfaceDeflection = Standard_True; @@ -1318,7 +1318,7 @@ static int MeshGenLODs (Draw_Interpretor& theDI, aParams.Deflection = aMaxDefl - aLODIdx * aDeflDecrFactor; aParams.Angle = 0.5; aParams.Relative = Standard_False; - aParams.InParallel = Standard_False; + aParams.InParallel = Standard_True; aParams.MinSize = Precision::Confusion(); aParams.InternalVerticesMode = Standard_True; aParams.ControlSurfaceDeflection = Standard_True; @@ -1393,7 +1393,7 @@ static int MeshGenLODs (Draw_Interpretor& theDI, } } - if (!aMesh.IsNull() && aSavePath != "") + if (aSavePath != "") { if (aSavePath.Value (aSavePath.Length()) != '/') { -- 2.39.5