From: vpa Date: Thu, 31 Mar 2016 11:13:13 +0000 (+0300) Subject: Removed unnecessary computation of base OpenGl_Structure for main presentation; X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=05286d68755de97c88b43a522796581a76760583;p=occt-copy.git Removed unnecessary computation of base OpenGl_Structure for main presentation; Bounding box of LOD Graphic3d_Structure is computed as combined box for all LOD graphic groups; Method HasLevelsOfDetail() was added to presentable objects to mark objects presented via LODs at the time of Compute() call; Redefineable method ComputeLods() was added to presentable object for customization. --- diff --git a/src/Graphic3d/Graphic3d_CStructure.hxx b/src/Graphic3d/Graphic3d_CStructure.hxx index 963f326fdf..83f9b97017 100644 --- a/src/Graphic3d/Graphic3d_CStructure.hxx +++ b/src/Graphic3d/Graphic3d_CStructure.hxx @@ -80,6 +80,11 @@ public: //! Get z layer ID Graphic3d_ZLayerId ZLayer() const { return myZLayer; } + const Handle(Graphic3d_LODManager)& GetLodManager() const + { + return myLODManager; + } + public: //! Update structure visibility state diff --git a/src/Graphic3d/Graphic3d_LODManager.cxx b/src/Graphic3d/Graphic3d_LODManager.cxx index 1bdc02bb70..7b38cd17bd 100644 --- a/src/Graphic3d/Graphic3d_LODManager.cxx +++ b/src/Graphic3d/Graphic3d_LODManager.cxx @@ -83,3 +83,19 @@ void Graphic3d_LODManager::SetRange (const Standard_Integer theLodIdx, { return myLODs.Value (myCurrentLODIdx)->GetDrawGroups(); } + + //======================================================================= +// function : GetCombinedBndBox +// purpose : +//======================================================================= + void Graphic3d_LODManager::GetCombinedBndBox (Graphic3d_BndBox4f& theBndBox) const + { + for (Standard_Integer aLodIdx = 0; aLodIdx < myLODs.Size(); ++aLodIdx) + { + const Graphic3d_SequenceOfGroup& aGroups = myLODs.Value (aLodIdx)->GetDrawGroups(); + for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (aGroups); aGroupIter.More(); aGroupIter.Next()) + { + theBndBox.Combine (aGroupIter.Value()->BoundingBox()); + } + } + } diff --git a/src/Graphic3d/Graphic3d_LODManager.hxx b/src/Graphic3d/Graphic3d_LODManager.hxx index 7efbb09a59..cabb925ddb 100644 --- a/src/Graphic3d/Graphic3d_LODManager.hxx +++ b/src/Graphic3d/Graphic3d_LODManager.hxx @@ -53,6 +53,8 @@ public: Standard_EXPORT virtual Handle(Graphic3d_LOD) AddNewLOD() = 0; + Standard_EXPORT void GetCombinedBndBox (Graphic3d_BndBox4f& theBndBox) const; + DEFINE_STANDARD_RTTIEXT (Graphic3d_LODManager, Standard_Transient) protected: diff --git a/src/Graphic3d/Graphic3d_Structure.cxx b/src/Graphic3d/Graphic3d_Structure.cxx index 40117bba46..a3c95b838c 100644 --- a/src/Graphic3d/Graphic3d_Structure.cxx +++ b/src/Graphic3d/Graphic3d_Structure.cxx @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -1768,9 +1769,17 @@ Handle(Graphic3d_StructureManager) Graphic3d_Structure::StructureManager() const Graphic3d_BndBox4f Graphic3d_Structure::minMaxCoord() const { Graphic3d_BndBox4f aBnd; - for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next()) + const Handle(Graphic3d_LODManager)& aLodMgr = myCStructure->GetLodManager(); + if (aLodMgr.IsNull()) + { + for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next()) + { + aBnd.Combine (aGroupIter.Value()->BoundingBox()); + } + } + else { - aBnd.Combine (aGroupIter.Value()->BoundingBox()); + aLodMgr->GetCombinedBndBox (aBnd); } return aBnd; } diff --git a/src/MeshVS/MeshVS_LODBuilder.cxx b/src/MeshVS/MeshVS_LODBuilder.cxx index 4bce494d02..2a885a08f2 100644 --- a/src/MeshVS/MeshVS_LODBuilder.cxx +++ b/src/MeshVS/MeshVS_LODBuilder.cxx @@ -53,50 +53,6 @@ void MeshVS_LODBuilder::Build (const Handle(Prs3d_Presentation)& theBasePrs, if (myParentMesh == NULL) return; - //if (!theIsElement) - //{ - // Standard_Boolean hasSelectFlag = ((aDispMode & MeshVS_DMF_SelectionPrs) != 0); - // Standard_Boolean hasHilightFlag = ((aDispMode & MeshVS_DMF_HilightPrs) != 0); - - // Standard_Real aCoordsBuf[3]; - // TColStd_Array1OfReal aCoords (*aCoordsBuf, 1, 3); - // Standard_Integer aNodesNb; - // MeshVS_EntityType aType; - - // TColStd_PackedMapOfInteger anIDs; - // anIDs.Assign (myNodeIdxs); - // if (!hasSelectFlag && !hasHilightFlag) - // { - // // subtract the hidden nodes and ids to exclude (to minimize allocated memory) - // Handle(TColStd_HPackedMapOfInteger) aHiddenNodes = aMesh->GetHiddenNodes(); - // if (!aHiddenNodes.IsNull()) - // anIDs.Subtract (aHiddenNodes->Map()); - // } - - // Standard_Integer aSize = anIDs.Extent(); - // if (aSize > 0) - // { - // Handle(Graphic3d_ArrayOfPoints) aNodePoints = new Graphic3d_ArrayOfPoints (aSize); - // Standard_Integer aPntsNb = 0; - // for (TColStd_MapIteratorOfPackedMapOfInteger aNodeIdxsIter (myNodeIdxs); aNodeIdxsIter.More(); aNodeIdxsIter.Next()) - // { - // const Standard_Integer aKey = aNodeIdxsIter.Key(); - // if (GetGeom (aKey, Standard_False, aCoords, aNodesNb, aType)) - // { - // aPntsNb++; - // aNodePoints->AddVertex (aCoords(1), aCoords(2), aCoords(3)); - // } - // } - - // if (aPntsNb > 0) - // { - // Handle(Graphic3d_LOD) aNewLod = Prs3d_Root::NewLOD (aMainPrs); - // Handle(Graphic3d_Group) aLODGroup = aNewLod->NewGroup(); - // aLODGroup->AddPrimitiveArray (aNodePoints); - // } - // return; - // } - //} if (theIsElement) { Standard_Integer aMaxNodesNb; @@ -424,6 +380,8 @@ void MeshVS_LODBuilder::Build (const Handle(Prs3d_Presentation)& theBasePrs, } } +#include + //================================================================ // Function : drawArrays // Purpose : @@ -459,6 +417,8 @@ void MeshVS_LODBuilder::drawArrays (const Handle(Prs3d_Presentation)& theBasePrs if (isPolygons && theFillAsp->FrontMaterial().Transparency() < 0.01) { Handle (Graphic3d_Group) aGroup = aNewLod->NewGroup (theBasePrs); + //Prs3d_Root::NewGroup ( theBasePrs ); + //Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup ( theBasePrs ); theFillAsp->SetEdgeOff(); @@ -489,6 +449,8 @@ void MeshVS_LODBuilder::drawArrays (const Handle(Prs3d_Presentation)& theBasePrs if (isPolylines && !theIsPolygonsEdgesOff) { Handle (Graphic3d_Group) aLGroup = aNewLod->NewGroup (theBasePrs); + //Prs3d_Root::NewGroup ( theBasePrs ); + //Handle (Graphic3d_Group) aLGroup = Prs3d_Root::CurrentGroup ( theBasePrs ); theFillAsp->SetEdgeOff(); if (theIsSelected) @@ -505,6 +467,8 @@ void MeshVS_LODBuilder::drawArrays (const Handle(Prs3d_Presentation)& theBasePrs if (isLinkPolylines) { Handle (Graphic3d_Group) aBeamGroup = aNewLod->NewGroup (theBasePrs); + //Prs3d_Root::NewGroup ( theBasePrs ); + //Handle (Graphic3d_Group) aBeamGroup = Prs3d_Root::CurrentGroup ( theBasePrs ); theFillAsp->SetEdgeOff(); if (!theIsSelected) @@ -517,6 +481,8 @@ void MeshVS_LODBuilder::drawArrays (const Handle(Prs3d_Presentation)& theBasePrs if (isPolygons && theFillAsp->FrontMaterial().Transparency() >= 0.01) { Handle (Graphic3d_Group) aGroup = aNewLod->NewGroup (theBasePrs); + //Prs3d_Root::NewGroup ( theBasePrs ); + //Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup ( theBasePrs ); theFillAsp->SetEdgeOff(); diff --git a/src/MeshVS/MeshVS_Mesh.cxx b/src/MeshVS/MeshVS_Mesh.cxx index a66b948252..4727e48f2d 100644 --- a/src/MeshVS/MeshVS_Mesh.cxx +++ b/src/MeshVS/MeshVS_Mesh.cxx @@ -138,6 +138,35 @@ MeshVS_Mesh::MeshVS_Mesh (const Standard_Boolean theIsAllowOverlapped ) myHilightDrawer->SetDouble ( MeshVS_DA_MarkerScale, 2.0 ); } +//================================================================ +// Function : HasLevelsOfDetail +// Purpose : +//================================================================ +Standard_Boolean MeshVS_Mesh::HasLevelsOfDetail() const +{ + return !myLODDataSources.IsEmpty(); +} + +//================================================================ +// Function : ComputeLods +// Purpose : +//================================================================ +void MeshVS_Mesh::ComputeLods (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr, + const Handle(Prs3d_Presentation)& thePrs, + const Standard_Integer theMode) +{ + for (Standard_Integer aLodBldrIdx = 1; aLodBldrIdx <= myBuilders.Length(); ++aLodBldrIdx) + { + const Handle(MeshVS_LODBuilder) aLodBldr = Handle(MeshVS_LODBuilder)::DownCast (myBuilders.Value (aLodBldrIdx)); + if (aLodBldr.IsNull()) + continue; + + const TColStd_PackedMapOfInteger aTrgIdxs = aLodBldr->GetDataSource()->GetAllElements(); + if (!aTrgIdxs.IsEmpty()) + aLodBldr->Build (thePrs, aTrgIdxs, TColStd_PackedMapOfInteger(), Standard_True, theMode); + } +} + //================================================================ // Function : Compute // Purpose : @@ -172,6 +201,7 @@ void MeshVS_Mesh::Compute ( const Handle(PrsMgr_PresentationManager3d)& thePrsMg thePresentation->Clear(); Standard_Integer len = myBuilders.Length(); if ( theMode > 0 ) + { for ( Standard_Integer i=1; i<=len; i++ ) { Handle (MeshVS_PrsBuilder) aCurrent = myBuilders.Value ( i ); @@ -188,22 +218,6 @@ void MeshVS_Mesh::Compute ( const Handle(PrsMgr_PresentationManager3d)& thePrsMg aCurrent->Build ( thePresentation, aElems, aElemsToExclude, Standard_True, theMode ); } } - - if (myLODDataSources.Size() > 0) - { - for (Standard_Integer aLodBldrIdx = 1; aLodBldrIdx <= myBuilders.Length(); ++aLodBldrIdx) - { - const Handle(MeshVS_LODBuilder) aLodBldr = Handle(MeshVS_LODBuilder)::DownCast (myBuilders.Value (aLodBldrIdx)); - if (aLodBldr.IsNull() || !aLodBldr->TestFlags (theMode)) - continue; - - const TColStd_PackedMapOfInteger aVertIdxs = aLodBldr->GetDataSource()->GetAllNodes(); - const TColStd_PackedMapOfInteger aTrgIdxs = aLodBldr->GetDataSource()->GetAllElements(); - if (HasNodes) - aLodBldr->Build (thePresentation, aVertIdxs, aNodesToExclude, Standard_False, theMode); - if (HasElements) - aLodBldr->Build (thePresentation, aTrgIdxs, aElemsToExclude, Standard_True, theMode); - } } if ( ShowComputeTime ) diff --git a/src/MeshVS/MeshVS_Mesh.hxx b/src/MeshVS/MeshVS_Mesh.hxx index dabba4cc41..b5c914392e 100644 --- a/src/MeshVS/MeshVS_Mesh.hxx +++ b/src/MeshVS/MeshVS_Mesh.hxx @@ -181,6 +181,8 @@ public: //! Returns True if the given owner represents a whole mesh. Standard_EXPORT virtual Standard_Boolean IsWholeMeshOwner (const Handle(SelectMgr_EntityOwner)& theOwner) const; + Standard_EXPORT virtual Standard_Boolean HasLevelsOfDetail() const Standard_OVERRIDE; + friend class MeshVS_PrsBuilder; @@ -188,6 +190,10 @@ friend class MeshVS_PrsBuilder; protected: + Standard_EXPORT virtual void ComputeLods (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr, + const Handle(Prs3d_Presentation)& thePrs, + const Standard_Integer theMode = 0) Standard_OVERRIDE; + //! Stores all vertices that belong to one of the faces to the given map //! @param theAllElements [in] the map of all mesh elements //! @param theNbMaxFaceNodes [in] the maximum amount of nodes per face, retrieved from drawer diff --git a/src/OpenGl/OpenGl_Structure.cxx b/src/OpenGl/OpenGl_Structure.cxx index fc9c7ec42e..70504e8da1 100644 --- a/src/OpenGl/OpenGl_Structure.cxx +++ b/src/OpenGl/OpenGl_Structure.cxx @@ -795,7 +795,7 @@ void OpenGl_Structure::SetDetailLevelRange (const Standard_Integer theIdOfLOD, Standard_ASSERT_RAISE (theFrom < theTo, "The upper boundary of the interval must be greater than lower one!"); - if (theIdOfLOD < 0 || theIdOfLOD > myLODManager->NbOfDetailLevels()) + if (myLODManager.IsNull() || theIdOfLOD < 0 || theIdOfLOD > myLODManager->NbOfDetailLevels()) return; myLODManager->SetRange (theIdOfLOD, theFrom, theTo); diff --git a/src/PrsMgr/PrsMgr_PresentableObject.cxx b/src/PrsMgr/PrsMgr_PresentableObject.cxx index f8deec61fe..3998044d32 100644 --- a/src/PrsMgr/PrsMgr_PresentableObject.cxx +++ b/src/PrsMgr/PrsMgr_PresentableObject.cxx @@ -71,7 +71,10 @@ void PrsMgr_PresentableObject::Fill (const Handle(PrsMgr_PresentationManager)& t const Standard_Integer theMode) { Handle(Prs3d_Presentation) aStruct3d = thePrs->Presentation(); - Compute (thePrsMgr, aStruct3d, theMode); + if (!HasLevelsOfDetail()) + Compute (thePrsMgr, aStruct3d, theMode); + else + ComputeLods (thePrsMgr, aStruct3d, theMode); UpdateTransformation (aStruct3d); aStruct3d->SetClipPlanes (myClipPlanes); aStruct3d->SetTransformPersistence (GetTransformPersistenceMode(), GetTransformPersistencePoint()); @@ -523,3 +526,26 @@ Standard_Boolean PrsMgr_PresentableObject::IsMutable() const { return myIsMutable; } + +// ======================================================================= +// function : ComputeLods +// purpose : +// ======================================================================= +void PrsMgr_PresentableObject::ComputeLods (const Handle(PrsMgr_PresentationManager3d)& /*thePrsMgr*/, + const Handle(Prs3d_Presentation)& /*thePrs*/, + const Standard_Integer /*theMode*/) +{ + if (HasLevelsOfDetail()) + { + Standard_NotImplemented::Raise ("cannot compute levels of detail"); + } +} + +// ======================================================================= +// function : HasLevelsOfDetail +// purpose : +// ======================================================================= +Standard_Boolean PrsMgr_PresentableObject::HasLevelsOfDetail() const +{ + return Standard_False; +} diff --git a/src/PrsMgr/PrsMgr_PresentableObject.hxx b/src/PrsMgr/PrsMgr_PresentableObject.hxx index 14af43ad60..17f06f9fab 100644 --- a/src/PrsMgr/PrsMgr_PresentableObject.hxx +++ b/src/PrsMgr/PrsMgr_PresentableObject.hxx @@ -199,6 +199,8 @@ public: //! Returns parent of current object in scene hierarchy. Standard_EXPORT PrsMgr_PresentableObjectPointer Parent() const; + Standard_EXPORT virtual Standard_Boolean HasLevelsOfDetail() const; + friend class PrsMgr_Presentation; friend class PrsMgr_PresentationManager; @@ -219,7 +221,11 @@ protected: Standard_EXPORT PrsMgr_PresentableObject(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d = PrsMgr_TOP_AllView); Standard_EXPORT virtual ~PrsMgr_PresentableObject(); - + + Standard_EXPORT virtual void ComputeLods (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr, + const Handle(Prs3d_Presentation)& thePrs, + const Standard_Integer theMode = 0); + //! Calculates the 3D view aPresentation and its //! updates. The latter are managed by aPresentationManager. //! aPresentableObject has the display mode aMode; diff --git a/tests/bugs/vis/bug26812 b/tests/bugs/vis/bug26812 index cb93e21b9d..b570294305 100644 --- a/tests/bugs/vis/bug26812 +++ b/tests/bugs/vis/bug26812 @@ -10,15 +10,15 @@ meshlod m $aTmpFolder/lod_data.txt # iges shapes. the following sequence of commands creates both # stl and brep files for the iges shape ########################################################################## -igesbrep $aPathToData/iges/bearing.iges res * -vdisplay res -# write created brep to file -save res $aTmpFolder/bearing.brep -trinfo res -# copy maximal deflection value, then re-mesh the shape with proper -# deflection -tclean res -incmesh res $maxDeflection -# save corresponding stl with the same triangulation as will be used -# for generaion of LODs -writestl res $aTmpFolder/bearing.stl +# igesbrep $aPathToData/iges/bearing.iges res * +# vdisplay res +# # write created brep to file +# save res $aTmpFolder/bearing.brep +# trinfo res +# # copy maximal deflection value, then re-mesh the shape with proper +# # deflection +# tclean res +# incmesh res $maxDeflection +# # save corresponding stl with the same triangulation as will be used +# # for generaion of LODs +# writestl res $aTmpFolder/bearing.stl