0026221: Visualization - use NCollection_IndexedMap instead of NCollection_Sequence...
authordbp <dbp@opencascade.com>
Mon, 25 May 2015 06:43:06 +0000 (09:43 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 28 May 2015 10:41:57 +0000 (13:41 +0300)
src/OpenGl/FILES
src/OpenGl/OpenGl_BVHClipPrimitiveSet.cxx
src/OpenGl/OpenGl_BVHClipPrimitiveSet.hxx
src/OpenGl/OpenGl_Layer.cxx
src/OpenGl/OpenGl_Layer.hxx
src/OpenGl/OpenGl_SequenceOfStructure.hxx [deleted file]
src/OpenGl/OpenGl_View.hxx
src/OpenGl/OpenGl_View_2.cxx
src/OpenGl/OpenGl_View_Raytrace.cxx
src/OpenGl/OpenGl_Workspace.cxx

index 37d3e63..963f2d7 100755 (executable)
@@ -141,7 +141,6 @@ OpenGl_ShaderManager.hxx
 OpenGl_ShaderManager.cxx
 OpenGl_ShaderStates.hxx
 OpenGl_ShaderStates.cxx
-OpenGl_SequenceOfStructure.hxx
 Handle_OpenGl_ShaderObject.hxx
 Handle_OpenGl_ShaderProgram.hxx
 Handle_OpenGl_ShaderManager.hxx
index e105ab3..5ed3007 100644 (file)
@@ -71,13 +71,13 @@ void OpenGl_BVHClipPrimitiveSet::Swap (const Standard_Integer theIdx1,
 // function : Assign
 // purpose  :
 // =======================================================================
-void OpenGl_BVHClipPrimitiveSet::Assign (const OpenGl_ArrayOfStructure& theStructs)
+void OpenGl_BVHClipPrimitiveSet::Assign (const OpenGl_ArrayOfIndexedMapOfStructure& theStructs)
 {
   myStructs.Clear();
 
   for (Standard_Integer aPriorityIdx = 0, aNbPriorities = theStructs.Length(); aPriorityIdx < aNbPriorities; ++aPriorityIdx)
   {
-    for (OpenGl_SequenceOfStructure::Iterator aStructIter (theStructs (aPriorityIdx)); aStructIter.More(); aStructIter.Next())
+    for (OpenGl_IndexedMapOfStructure::Iterator aStructIter (theStructs (aPriorityIdx)); aStructIter.More(); aStructIter.Next())
     {
       const OpenGl_Structure* aStruct = aStructIter.Value();
 
index 617a29c..4da06c6 100644 (file)
 #include <NCollection_IndexedMap.hxx>
 
 #include <OpenGl_Structure.hxx>
-#include <OpenGl_SequenceOfStructure.hxx>
 
-typedef NCollection_Array1<OpenGl_SequenceOfStructure> OpenGl_ArrayOfStructure;
+//! Defines index map of OpenGL structures.
+typedef NCollection_IndexedMap<const OpenGl_Structure*> OpenGl_IndexedMapOfStructure;
+
+//! Defines array of indexed maps of OpenGL structures.
+typedef NCollection_Array1<OpenGl_IndexedMapOfStructure> OpenGl_ArrayOfIndexedMapOfStructure;
 
 //! Set of OpenGl_Structures for building BVH tree.
 class OpenGl_BVHClipPrimitiveSet : public BVH_PrimitiveSet<Standard_ShortReal, 4>
@@ -53,7 +56,7 @@ public:
 
   //! Replaces the set by the given array taking into account
   //! if each structure is cullable or not.
-  void Assign (const OpenGl_ArrayOfStructure& theStructs);
+  void Assign (const OpenGl_ArrayOfIndexedMapOfStructure& theStructs);
 
   //! Adds structure to the set.
   void Add (const OpenGl_Structure* theStruct);
index 5ab137c..6b59d55 100644 (file)
@@ -56,7 +56,7 @@ void OpenGl_Layer::Add (const OpenGl_Structure* theStruct,
     return;
   }
 
-  myArray (anIndex).Append (theStruct);
+  myArray (anIndex).Add (theStruct);
   if (theStruct->IsAlwaysRendered())
   {
     theStruct->MarkAsNotCulled();
@@ -85,21 +85,22 @@ bool OpenGl_Layer::Remove (const OpenGl_Structure* theStruct,
   const Standard_Integer aNbPriorities = myArray.Length();
   for (Standard_Integer aPriorityIter = 0; aPriorityIter < aNbPriorities; ++aPriorityIter)
   {
-    OpenGl_SequenceOfStructure& aSeq = myArray (aPriorityIter);
-    for (OpenGl_SequenceOfStructure::Iterator aStructIter (aSeq); aStructIter.More(); aStructIter.Next())
+    OpenGl_IndexedMapOfStructure& aStructures = myArray (aPriorityIter);
+
+    const Standard_Integer anIndex = aStructures.FindIndex (theStruct);
+    if (anIndex != 0)
     {
-      if (aStructIter.Value() == theStruct)
+      aStructures.Swap (anIndex, aStructures.Size());
+      aStructures.RemoveLast();
+
+      if (!theStruct->IsAlwaysRendered()
+       && !isForChangePriority)
       {
-        aSeq.Remove (aStructIter);
-        if (!theStruct->IsAlwaysRendered()
-         && !isForChangePriority)
-        {
-          myBVHPrimitives.Remove (theStruct);
-        }
-        --myNbStructures;
-        thePriority = aPriorityIter;
-        return true;
+        myBVHPrimitives.Remove (theStruct);
       }
+      --myNbStructures;
+      thePriority = aPriorityIter;
+      return true;
     }
   }
 
@@ -126,9 +127,10 @@ void OpenGl_Layer::renderAll (const Handle(OpenGl_Workspace)& theWorkspace) cons
   const Standard_Integer aViewId       = theWorkspace->ActiveViewId();
   for (Standard_Integer aPriorityIter = 0; aPriorityIter < aNbPriorities; ++aPriorityIter)
   {
-    for (OpenGl_SequenceOfStructure::Iterator aStructIter (myArray (aPriorityIter)); aStructIter.More(); aStructIter.Next())
+    const OpenGl_IndexedMapOfStructure& aStructures = myArray (aPriorityIter);
+    for (Standard_Integer aStructIdx = 1; aStructIdx <= aStructures.Size(); ++aStructIdx)
     {
-      const OpenGl_Structure* aStruct = aStructIter.Value();
+      const OpenGl_Structure* aStruct = aStructures.FindKey (aStructIdx);
       if (!aStruct->IsVisible())
       {
         continue;
@@ -163,9 +165,10 @@ void OpenGl_Layer::renderTraverse (const Handle(OpenGl_Workspace)& theWorkspace)
   const Standard_Integer aViewId       = theWorkspace->ActiveViewId();
   for (Standard_Integer aPriorityIter = 0; aPriorityIter < aNbPriorities; ++aPriorityIter)
   {
-    for (OpenGl_SequenceOfStructure::Iterator aStructIter (myArray (aPriorityIter)); aStructIter.More(); aStructIter.Next())
+    const OpenGl_IndexedMapOfStructure& aStructures = myArray (aPriorityIter);
+    for (Standard_Integer aStructIdx = 1; aStructIdx <= aStructures.Size(); ++aStructIdx)
     {
-      const OpenGl_Structure* aStruct = aStructIter.Value();
+      const OpenGl_Structure* aStruct = aStructures.FindKey (aStructIdx);
       if (!aStruct->IsVisible()
         || aStruct->IsCulled())
       {
@@ -267,9 +270,10 @@ Standard_Boolean OpenGl_Layer::Append (const OpenGl_Layer& theOther)
   // add all structures to destination priority list
   for (Standard_Integer aPriorityIter = 0; aPriorityIter < aNbPriorities; ++aPriorityIter)
   {
-    for (OpenGl_SequenceOfStructure::Iterator aStructIter (theOther.myArray (aPriorityIter)); aStructIter.More(); aStructIter.Next())
+    const OpenGl_IndexedMapOfStructure& aStructures = theOther.myArray (aPriorityIter);
+    for (Standard_Integer aStructIdx = 1; aStructIdx <= aStructures.Size(); ++aStructIdx)
     {
-      Add (aStructIter.Value(), aPriorityIter);
+      Add (aStructures.FindKey (aStructIdx), aPriorityIter);
     }
   }
 
index cc1697e..ed45ed9 100644 (file)
@@ -82,7 +82,7 @@ public:
   Standard_Boolean Append (const OpenGl_Layer& theOther);
 
   //! Returns array of OpenGL structures.
-  const OpenGl_ArrayOfStructure& ArrayOfStructures() const { return myArray; }
+  const OpenGl_ArrayOfIndexedMapOfStructure& ArrayOfStructures() const { return myArray; }
 
   //! Marks BVH tree for given priority list as dirty and
   //! marks primitive set for rebuild.
@@ -105,12 +105,12 @@ protected:
 
 private:
 
-  OpenGl_ArrayOfStructure            myArray;
-  Standard_Integer                   myNbStructures;
-  Graphic3d_ZLayerSettings           myLayerSettings;             //!< Layer setting flags
-  mutable OpenGl_BVHClipPrimitiveSet myBVHPrimitives;             //<! Set of OpenGl_Structures for building BVH tree
-  mutable Standard_Boolean           myBVHIsLeftChildQueuedFirst; //<! Is needed for implementation of stochastic order of BVH traverse
-  mutable Standard_Boolean           myIsBVHPrimitivesNeedsReset; //<! Defines if the primitive set for BVH is outdated
+  OpenGl_ArrayOfIndexedMapOfStructure myArray;
+  Standard_Integer                    myNbStructures;
+  Graphic3d_ZLayerSettings            myLayerSettings;             //!< Layer setting flags
+  mutable OpenGl_BVHClipPrimitiveSet  myBVHPrimitives;             //!< Set of OpenGl_Structures for building BVH tree
+  mutable Standard_Boolean            myBVHIsLeftChildQueuedFirst; //!< Is needed for implementation of stochastic order of BVH traverse
+  mutable Standard_Boolean            myIsBVHPrimitivesNeedsReset; //!< Defines if the primitive set for BVH is outdated
 
 public:
 
diff --git a/src/OpenGl/OpenGl_SequenceOfStructure.hxx b/src/OpenGl/OpenGl_SequenceOfStructure.hxx
deleted file mode 100644 (file)
index 3f33832..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-// Created on: 2014-12-18
-// Created by: Kirill Gavrilov
-// Copyright (c) 2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#ifndef _OpenGl_SequenceOfStructure
-#define _OpenGl_SequenceOfStructure
-
-#include <NCollection_Sequence.hxx>
-
-class OpenGl_Structure;
-typedef NCollection_Sequence<const OpenGl_Structure*> OpenGl_SequenceOfStructure;
-
-#endif // _OpenGl_SequenceOfStructure
index 2a16e41..aa41691 100644 (file)
@@ -201,7 +201,7 @@ class OpenGl_View : public MMgt_TShared
   void InvalidateBVHData (const Standard_Integer theLayerId);
 
   //! Returns list of immediate structures rendered on top of main presentation
-  const OpenGl_SequenceOfStructure& ImmediateStructures() const
+  const OpenGl_IndexedMapOfStructure& ImmediateStructures() const
   {
     return myImmediateList;
   }
@@ -267,8 +267,8 @@ protected:
 
   //View_LABDepthCueing - fixed index used
 
-  OpenGl_LayerList           myZLayers;       //!< main list of displayed structure, sorted by layers
-  OpenGl_SequenceOfStructure myImmediateList; //!< list of immediate structures rendered on top of main presentation
+  OpenGl_LayerList             myZLayers;       //!< main list of displayed structure, sorted by layers
+  OpenGl_IndexedMapOfStructure myImmediateList; //!< list of immediate structures rendered on top of main presentation
 
   const TEL_TRANSFORM_PERSISTENCE *myTransPers;
   Standard_Boolean myIsTransPers;
index 3abea51..fe40d8d 100644 (file)
@@ -919,16 +919,7 @@ void OpenGl_View::DisplayStructure (const Handle(Graphic3d_Structure)& theStruct
 void OpenGl_View::DisplayImmediateStructure (const Handle(Graphic3d_Structure)& theStructure)
 {
   const OpenGl_Structure* aStruct = reinterpret_cast<const OpenGl_Structure*> (theStructure->CStructure().operator->());
-  for (OpenGl_SequenceOfStructure::Iterator anIter (myImmediateList);
-       anIter.More(); anIter.Next())
-  {
-    if (anIter.Value() == aStruct)
-    {
-      return;
-    }
-  }
-
-  myImmediateList.Append (aStruct);
+  myImmediateList.Add (aStruct);
 }
 
 //=======================================================================
@@ -948,14 +939,12 @@ void OpenGl_View::EraseStructure (const Handle(Graphic3d_Structure)& theStructur
 
 void OpenGl_View::EraseImmediateStructure (const OpenGl_Structure* theStructure)
 {
-  for (OpenGl_SequenceOfStructure::Iterator anIter (myImmediateList);
-       anIter.More(); anIter.Next())
+  const Standard_Integer anIndex = myImmediateList.FindIndex (theStructure);
+
+  if (anIndex != 0)
   {
-    if (anIter.Value() == theStructure)
-    {
-      myImmediateList.Remove (anIter);
-      return;
-    }
+    myImmediateList.Swap (myImmediateList.Size(), anIndex);
+    myImmediateList.RemoveLast();
   }
 }
 
index 15e9f9d..728c98c 100644 (file)
@@ -71,11 +71,11 @@ Standard_Boolean OpenGl_View::updateRaytraceGeometry (const RaytraceUpdateMode
 
   if (aLayer.NbStructures() != 0)
   {
-    const OpenGl_ArrayOfStructure& aStructArray = aLayer.ArrayOfStructures();
+    const OpenGl_ArrayOfIndexedMapOfStructure& aStructArray = aLayer.ArrayOfStructures();
 
     for (Standard_Integer anIndex = 0; anIndex < aStructArray.Length(); ++anIndex)
     {
-      for (OpenGl_SequenceOfStructure::Iterator aStructIt (aStructArray (anIndex)); aStructIt.More(); aStructIt.Next())
+      for (OpenGl_IndexedMapOfStructure::Iterator aStructIt (aStructArray (anIndex)); aStructIt.More(); aStructIt.Next())
       {
         const OpenGl_Structure* aStructure = aStructIt.Value();
 
index b93bd86..59264e6 100644 (file)
@@ -1429,8 +1429,7 @@ bool OpenGl_Workspace::redrawImmediate (const Graphic3d_CView& theCView,
   {
     glDisable (GL_DEPTH_TEST);
   }
-  for (OpenGl_SequenceOfStructure::Iterator anIter (myView->ImmediateStructures());
-       anIter.More(); anIter.Next())
+  for (OpenGl_IndexedMapOfStructure::Iterator anIter (myView->ImmediateStructures()); anIter.More(); anIter.Next())
   {
     const OpenGl_Structure* aStructure = anIter.Value();
     if (!aStructure->IsVisible())