]> OCCT Git - occt-copy.git/commitdiff
Removed unnecessary computation of base OpenGl_Structure for main presentation;
authorvpa <vpa@opencascade.com>
Thu, 31 Mar 2016 11:13:13 +0000 (14:13 +0300)
committervpa <vpa@opencascade.com>
Fri, 8 Apr 2016 17:20:00 +0000 (20:20 +0300)
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.

src/Graphic3d/Graphic3d_CStructure.hxx
src/Graphic3d/Graphic3d_LODManager.cxx
src/Graphic3d/Graphic3d_LODManager.hxx
src/Graphic3d/Graphic3d_Structure.cxx
src/MeshVS/MeshVS_LODBuilder.cxx
src/MeshVS/MeshVS_Mesh.cxx
src/MeshVS/MeshVS_Mesh.hxx
src/OpenGl/OpenGl_Structure.cxx
src/PrsMgr/PrsMgr_PresentableObject.cxx
src/PrsMgr/PrsMgr_PresentableObject.hxx
tests/bugs/vis/bug26812

index 963f326fdf75db44ca34e9bca60faa429a24f5ad..83f9b9701774d43f66dba76e72f8fdba5e000ebb 100644 (file)
@@ -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
index 1bdc02bb700074be8095230dd4b9bcdeeef6653e..7b38cd17bd1422963e682c55682b42268e92b6e6 100644 (file)
@@ -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());
+     }
+   }
+ }
index 7efbb09a59a45b13de3aa41043052b95bf41632e..cabb925ddbbf1ad0c6b6e0a8f88bb7b44e39ff04 100644 (file)
@@ -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:
index 40117bba469bf2f39707cd8ec6e5f7592b6b76e2..a3c95b838c9b1d66d7965bb723458ff59a7beef1 100644 (file)
@@ -24,6 +24,7 @@
 #include <Graphic3d_DataStructureManager.hxx>
 #include <Graphic3d_GraphicDriver.hxx>
 #include <Graphic3d_Group.hxx>
+#include <Graphic3d_LODManager.hxx>
 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
 #include <Graphic3d_MapOfStructure.hxx>
 #include <Graphic3d_MaterialAspect.hxx>
@@ -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;
 }
index 4bce494d02653846eb7b0898a861292e7c4e8014..2a885a08f2bc2ddc99b3079b27b5d7b668e77937 100644 (file)
@@ -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 <Prs3d_Root.hxx>
+
 //================================================================
 // 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();
 
index a66b9482525b4573cb11d26024c6faf8eddf2d47..4727e48f2d8d1e27bbad8ef303059f8ebbe8af8f 100644 (file)
@@ -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 )
index dabba4cc415c701de36c5fc981150ca4668b53f8..b5c914392e2b65f0b06c5d7740e089be2eef7b08 100644 (file)
@@ -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
index fc9c7ec42e624ec9e93376040b547fdad5f145c4..70504e8da19a669f44bd852775f66c7af3052acf 100644 (file)
@@ -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);
index f8deec61fece6e14fa1391928bde05a23486145e..3998044d32fd96d917b9436cb9960f70b97903ae 100644 (file)
@@ -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;
+}
index 14af43ad609f8dde8488e5d92c9cfd88799d0bf5..17f06f9fabed3e91c98d57b445b76eff005bd0ce 100644 (file)
@@ -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;
index cb93e21b9d65510a0c990790bad0e1e6fc12b27b..b570294305ee938e6882ba4e566bb3b036084563 100644 (file)
@@ -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