]> OCCT Git - occt.git/commitdiff
0028101: Visualization, Select3D_SensitiveSet - fix NULL dereference on re-adding...
authorkgv <kgv@opencascade.com>
Thu, 17 Nov 2016 12:51:44 +0000 (15:51 +0300)
committerapn <apn@opencascade.com>
Thu, 17 Nov 2016 15:49:37 +0000 (18:49 +0300)
Select3D_SensitiveSet now stores BVH_PrimitiveSet as class field (no dynamic allocation),
and BVH_PrimitiveSet subclass now stores raw pointer to Select3D_SensitiveSet (no smart pointer).

Select3D_BVHPrimitiveContent definition has been moved into Select3D_SensitiveSet
class definition to avoid confusion.

Unused field Select3D_SensitiveSet::myIsLeftChildQueuedFirst has been removed.

src/Select3D/FILES
src/Select3D/Select3D_BVHPrimitiveContent.cxx [deleted file]
src/Select3D/Select3D_BVHPrimitiveContent.hxx [deleted file]
src/Select3D/Select3D_SensitiveSet.cxx
src/Select3D/Select3D_SensitiveSet.hxx

index ea12ef8249e592971b14b3b39852deebd666e2b3..3146054e3663a45a8dd470be2f23d8e60c39caf5 100755 (executable)
@@ -1,7 +1,5 @@
 Select3D_BndBox3d.hxx
 Select3D_BVHIndexBuffer.hxx
-Select3D_BVHPrimitiveContent.cxx
-Select3D_BVHPrimitiveContent.hxx
 Select3D_EntitySequence.hxx
 Select3D_InteriorSensitivePointSet.cxx
 Select3D_InteriorSensitivePointSet.hxx
diff --git a/src/Select3D/Select3D_BVHPrimitiveContent.cxx b/src/Select3D/Select3D_BVHPrimitiveContent.cxx
deleted file mode 100644 (file)
index 08cad7a..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-// Created on: 2014-05-30
-// Created by: Varvara POSKONINA
-// Copyright (c) 2005-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.
-
-#include <BVH_LinearBuilder.hxx>
-
-#include <Select3D_SensitiveSet.hxx>
-#include <Select3D_BVHPrimitiveContent.hxx>
-
-//=======================================================================
-// function : Select3D_BVHPrimitiveContent
-// purpose  : Initializes new linear BVH builder for the set of sensitives
-//            theSensitiveSet given
-//=======================================================================
-Select3D_BVHPrimitiveContent::Select3D_BVHPrimitiveContent (const Handle(Select3D_SensitiveSet)& theSensitiveSet)
-{
-  mySensitiveSet = theSensitiveSet;
-  myBuilder = new BVH_LinearBuilder<Standard_Real, 3> (myLeafNodeSize, 32);
-
-  MarkDirty();
-}
-
-//=======================================================================
-// function : Size
-// purpose  : Returns the length of set of sensitives
-//=======================================================================
-Standard_Integer Select3D_BVHPrimitiveContent::Size() const
-{
-  return mySensitiveSet->Size();
-}
-
-//=======================================================================
-// function : Box
-// purpose  : Returns bounding box of sensitive with index theIdx
-//=======================================================================
-Select3D_BndBox3d Select3D_BVHPrimitiveContent::Box (const Standard_Integer theIdx) const
-{
-  return mySensitiveSet->Box (theIdx);
-}
-
-//=======================================================================
-// function : Center
-// purpose  : Returns center of sensitive with index theIdx in the set
-//            along the given axis theAxis
-//=======================================================================
-Standard_Real Select3D_BVHPrimitiveContent::Center (const Standard_Integer theIdx,
-                                                    const Standard_Integer theAxis) const
-{
-  return mySensitiveSet->Center (theIdx, theAxis);
-}
-
-//=======================================================================
-// function : Swap
-// purpose  : Swaps items with indexes theIdx1 and theIdx2 in the set
-//=======================================================================
-void Select3D_BVHPrimitiveContent::Swap (const Standard_Integer theIdx1,
-                                         const Standard_Integer theIdx2)
-{
-  mySensitiveSet->Swap (theIdx1, theIdx2);
-}
-
-//=======================================================================
-// function : GetBVH
-// purpose  : Returns the tree built for set of sensitives
-//=======================================================================
-const NCollection_Handle<BVH_Tree<Standard_Real, 3> >& Select3D_BVHPrimitiveContent::GetBVH()
-{
-  return BVH();
-}
diff --git a/src/Select3D/Select3D_BVHPrimitiveContent.hxx b/src/Select3D/Select3D_BVHPrimitiveContent.hxx
deleted file mode 100644 (file)
index 14b3a5e..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-// Created on: 2014-05-30
-// Created by: Varvara POSKONINA
-// Copyright (c) 2005-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 _Select3D_BVHPrimitiveContent_Header
-#define _Select3D_BVHPrimitiveContent_Header
-
-#include <BVH_PrimitiveSet.hxx>
-
-class Select3D_SensitiveSet;
-
-//! The purpose of this class is to provide a link between BVH_PrimitiveSet
-//! and Select3D_SensitiveSet instance to build BVH tree for set of sensitives
-class Select3D_BVHPrimitiveContent : public BVH_PrimitiveSet<Standard_Real, 3>
-{
-public:
-
-  //! Initializes new linear BVH builder for the set of sensitives
-  //! theSensitiveSet given
-  Select3D_BVHPrimitiveContent (const Handle(Select3D_SensitiveSet)& theSensitiveSet);
-
-  ~Select3D_BVHPrimitiveContent() {};
-
-  //! Returns the length of set of sensitives
-  Standard_EXPORT virtual Standard_Integer Size() const Standard_OVERRIDE;
-
-  //! Returns bounding box of sensitive with index theIdx
-  Standard_EXPORT virtual Select3D_BndBox3d Box (const Standard_Integer theIdx) const Standard_OVERRIDE;
-
-  //! Make inherited method Box() visible to avoid CLang warning
-  using BVH_PrimitiveSet<Standard_Real, 3>::Box;
-
-  //! Returns center of sensitive with index theIdx in the set along the
-  //! given axis theAxis
-  Standard_EXPORT virtual Standard_Real Center (const Standard_Integer theIdx,
-                                                const Standard_Integer theAxis) const Standard_OVERRIDE;
-
-  //! Swaps items with indexes theIdx1 and theIdx2 in the set
-  Standard_EXPORT virtual void Swap (const Standard_Integer theIdx1,
-                                     const Standard_Integer theIdx2) Standard_OVERRIDE;
-
-  //! Returns the tree built for set of sensitives
-  Standard_EXPORT const NCollection_Handle<BVH_Tree<Standard_Real, 3> >& GetBVH();
-
-  //! Returns a number of nodes in 1 BVH leaf
-  Standard_Integer GetLeafNodeSize() const { return myLeafNodeSize; }
-
-protected:
-  Handle(Select3D_SensitiveSet) mySensitiveSet;     //!< Set of sensitive entities
-
-private:
-  static const Standard_Integer myLeafNodeSize = 8;     //!< Number of sub-elements in the leaf
-};
-
-#endif // _Select3D_BVHPrimitiveContent_Header
index fabd0238ec6fea32e98eeee763c1c75f599b6952..a6b8a8e146ac8d1fb0e088bc45b5b3c65328b963 100644 (file)
@@ -14,8 +14,8 @@
 // commercial license or contractual agreement.
 
 #include <Select3D_SensitiveSet.hxx>
-#include <Select3D_BVHPrimitiveContent.hxx>
 
+#include <BVH_LinearBuilder.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(Select3D_SensitiveSet,Select3D_SensitiveEntity)
 
@@ -24,11 +24,13 @@ IMPLEMENT_STANDARD_RTTIEXT(Select3D_SensitiveSet,Select3D_SensitiveEntity)
 // purpose  : Creates new empty sensitive set and its content
 //=======================================================================
 Select3D_SensitiveSet::Select3D_SensitiveSet (const Handle(SelectBasics_EntityOwner)& theOwnerId)
-: Select3D_SensitiveEntity (theOwnerId)
+: Select3D_SensitiveEntity (theOwnerId),
+  myDetectedIdx (-1)
 {
-  myDetectedIdx = -1;
-  myIsLeftChildQueuedFirst = Standard_False;
-  myContent = new Select3D_BVHPrimitiveContent (this);
+  NCollection_Handle< BVH_Builder<Standard_Real, 3> > aBuilder = new BVH_LinearBuilder<Standard_Real, 3> (myLeafNodeSize, 32);
+  myContent.SetSensitiveSet (this);
+  myContent.SetBuilder (aBuilder);
+  myContent.MarkDirty();
 }
 
 //=======================================================================
@@ -37,7 +39,7 @@ Select3D_SensitiveSet::Select3D_SensitiveSet (const Handle(SelectBasics_EntityOw
 //=======================================================================
 void Select3D_SensitiveSet::BVH()
 {
-  myContent->GetBVH();
+  myContent.GetBVH();
 }
 
 //=======================================================================
@@ -49,12 +51,12 @@ void Select3D_SensitiveSet::BVH()
 Standard_Boolean Select3D_SensitiveSet::Matches (SelectBasics_SelectingVolumeManager& theMgr,
                                                  SelectBasics_PickResult& thePickResult)
 {
-  const BVH_Tree<Standard_Real, 3, BVH_BinaryTree>* aBVH = myContent->GetBVH().get();
+  const BVH_Tree<Standard_Real, 3, BVH_BinaryTree>* aBVH = myContent.GetBVH().get();
 
   thePickResult = SelectBasics_PickResult (RealLast(), RealLast());
 
-  if (myContent->Size() < 1 || !theMgr.Overlaps (aBVH->MinPoint (0),
-                                                 aBVH->MaxPoint (0)))
+  if (myContent.Size() < 1 || !theMgr.Overlaps (aBVH->MinPoint (0),
+                                                aBVH->MaxPoint (0)))
   {
     return Standard_False;
   }
@@ -180,30 +182,11 @@ gp_Pnt Select3D_SensitiveSet::CenterOfGeometry() const
   return gp_Pnt (RealLast(), RealLast(), RealLast());
 }
 
-//=======================================================================
-// function : MarkDirty
-// purpose  : Marks BVH tree of the set as outdated. It will be rebuild
-//            at the next call of BVH()
-//=======================================================================
-void Select3D_SensitiveSet::MarkDirty()
-{
-  myContent->MarkDirty();
-}
-
 //=======================================================================
 // function : Clear
 // purpose  : Destroys cross-reference to avoid memory leak
 //=======================================================================
 void Select3D_SensitiveSet::Clear()
 {
-  myContent.Nullify();
-}
-
-//=======================================================================
-// function : GetLeafNodeSize
-// purpose  : Returns a number of nodes in 1 BVH leaf
-//=======================================================================
-Standard_Integer Select3D_SensitiveSet::GetLeafNodeSize() const
-{
-  return myContent->GetLeafNodeSize();
+  //
 }
index bf69aa67d9a5c3f89255d0b51c61d30a1c9b63a4..56c5cc82472bd8ba91a64faf6327cddfc972c242 100644 (file)
 #ifndef _Select3D_SensitiveSet_Header
 #define _Select3D_SensitiveSet_Header
 
+#include <BVH_PrimitiveSet.hxx>
 #include <Standard.hxx>
 #include <Standard_Type.hxx>
-#include <Standard_Type.hxx>
-
-#include <NCollection_Handle.hxx>
-
 #include <Select3D_BndBox3d.hxx>
-#include <SelectBasics_EntityOwner.hxx>
 #include <Select3D_SensitiveEntity.hxx>
-
-class Select3D_BVHPrimitiveContent;
+#include <SelectBasics_EntityOwner.hxx>
 
 //! This class is base class for handling overlap detection of complex sensitive
 //! entities. It provides an interface for building BVH tree for some set of entities.
@@ -38,12 +33,14 @@ class Select3D_BVHPrimitiveContent;
 //! For example of usage see Select3D_SensitiveTriangulation.
 class Select3D_SensitiveSet : public Select3D_SensitiveEntity
 {
+  static const Standard_Integer myLeafNodeSize = 8; //!< Number of sub-elements in the leaf
+  DEFINE_STANDARD_RTTIEXT(Select3D_SensitiveSet, Select3D_SensitiveEntity)
 public:
 
   //! Creates new empty sensitive set and its content
   Standard_EXPORT Select3D_SensitiveSet (const Handle(SelectBasics_EntityOwner)& theOwnerId);
 
-  ~Select3D_SensitiveSet() {};
+  ~Select3D_SensitiveSet() {}
 
 public:
 
@@ -70,11 +67,11 @@ public:
   //! Must be called manually to build BVH tree for any sensitive set
   //! in case if its content was initialized not in a constructor,
   //! but element by element
-  Standard_EXPORT void BVH() Standard_OVERRIDE;
+  Standard_EXPORT virtual void BVH() Standard_OVERRIDE;
 
   //! Marks BVH tree of the set as outdated. It will be rebuild
   //! at the next call of BVH()
-  Standard_EXPORT void MarkDirty();
+  void MarkDirty() { myContent.MarkDirty(); }
 
   //! Returns bounding box of the whole set.
   //! This method should be redefined in Select3D_SensitiveSet descendants
@@ -88,10 +85,7 @@ public:
   Standard_EXPORT virtual void Clear() Standard_OVERRIDE;
 
   //! Returns a number of nodes in 1 BVH leaf
-  Standard_EXPORT Standard_Integer GetLeafNodeSize() const;
-
-public:
-  DEFINE_STANDARD_RTTIEXT(Select3D_SensitiveSet,Select3D_SensitiveEntity)
+  Standard_Integer GetLeafNodeSize() const { return myLeafNodeSize; }
 
 protected:
 
@@ -109,12 +103,55 @@ protected:
   virtual Standard_Real distanceToCOG (SelectBasics_SelectingVolumeManager& theMgr) = 0;
 
 protected:
-  Standard_Integer myDetectedIdx;     //!< Index of detected primitive in BVH sorted primitive array
 
-private:
+  //! The purpose of this class is to provide a link between BVH_PrimitiveSet
+  //! and Select3D_SensitiveSet instance to build BVH tree for set of sensitives.
+  class BvhPrimitiveSet : public BVH_PrimitiveSet<Standard_Real, 3>
+  {
+  public:
+
+    //! Empty constructor.
+    BvhPrimitiveSet() {}
+
+    //! Destructor.
+    ~BvhPrimitiveSet() {}
+
+    //! Setup sensitivity set.
+    void SetSensitiveSet (Select3D_SensitiveSet* theSensitiveSet)
+    {
+      mySensitiveSet = theSensitiveSet;
+      MarkDirty();
+    }
+
+    //! Returns the length of set of sensitives
+    virtual Standard_Integer Size() const Standard_OVERRIDE { return mySensitiveSet->Size(); }
+
+    //! Returns bounding box of sensitive with index theIdx
+    virtual Select3D_BndBox3d Box (const Standard_Integer theIdx) const Standard_OVERRIDE { return mySensitiveSet->Box (theIdx); }
+
+    //! Make inherited method Box() visible to avoid CLang warning
+    using BVH_PrimitiveSet<Standard_Real, 3>::Box;
+
+    //! Returns center of sensitive with index theIdx in the set along the given axis theAxis
+    virtual Standard_Real Center (const Standard_Integer theIdx,
+                                  const Standard_Integer theAxis) const Standard_OVERRIDE { return mySensitiveSet->Center (theIdx, theAxis); }
+
+    //! Swaps items with indexes theIdx1 and theIdx2 in the set
+    virtual void Swap (const Standard_Integer theIdx1,
+                       const Standard_Integer theIdx2) Standard_OVERRIDE { mySensitiveSet->Swap (theIdx1, theIdx2); }
+
+    //! Returns the tree built for set of sensitives
+    const NCollection_Handle<BVH_Tree<Standard_Real, 3> >& GetBVH() { return BVH(); }
+
+  protected:
+    Select3D_SensitiveSet* mySensitiveSet; //!< Set of sensitive entities
+  };
+
+protected:
+
+  BvhPrimitiveSet  myContent;     //!< A link between sensitive entity and BVH_PrimitiveSet
+  Standard_Integer myDetectedIdx; //!< Index of detected primitive in BVH sorted primitive array
 
-  Standard_Boolean                                 myIsLeftChildQueuedFirst;     //!< Flag for slight randomization of BVH traverse
-  NCollection_Handle<Select3D_BVHPrimitiveContent> myContent;                    //!< A link between sensitive entity and BVH_PrimitiveSet
 };
 
 DEFINE_STANDARD_HANDLE(Select3D_SensitiveSet, Select3D_SensitiveEntity)