Several methods in Selection classes have been moved to header files for better inlining.
BVH_Constants - added new enumeration defining common constant values used with BVH trees.
BVH - replaced NCollection_Handle with Standard_Transient handle
in classes BVH_Properties, BVH_Builder, BVH_Tree, BVH_Object.
Defined global BVH-builders instead of allocating a new one for each object set.
SelectMgr_ViewerSelector - added new method ::SetEntitySetBuilder() defining
default BVH Tree builder for SelectMgr_SensitiveEntitySet.
Added new method SelectMgr_SensitiveEntitySet::SetBuilder()
for overriding default BVH tree builder.
# Conflicts:
# dox/dev_guides/upgrade/upgrade.md
# src/Select3D/Select3D_SensitiveSet.hxx
# src/SelectBasics/SelectBasics_SensitiveEntity.cxx
# src/SelectBasics/SelectBasics_SensitiveEntity.hxx
BRepExtrema_StackItem aStack[96];
- const NCollection_Handle<BVH_Tree<Standard_Real, 3> >& aBVH1 = mySet1->BVH();
- const NCollection_Handle<BVH_Tree<Standard_Real, 3> >& aBVH2 = mySet2->BVH();
+ const opencascade::handle<BVH_Tree<Standard_Real, 3> >& aBVH1 = mySet1->BVH();
+ const opencascade::handle<BVH_Tree<Standard_Real, 3> >& aBVH2 = mySet2->BVH();
if (aBVH1.IsNull() || aBVH2.IsNull())
{
#include <Poly_Triangulation.hxx>
#include <TColgp_Array1OfPnt2d.hxx>
-
-IMPLEMENT_STANDARD_RTTIEXT(BRepExtrema_TriangleSet,Standard_Transient)
+IMPLEMENT_STANDARD_RTTIEXT(BRepExtrema_TriangleSet, BVH_PrimitiveSet3d)
//=======================================================================
//function : BRepExtrema_TriangleSet
//purpose : Creates empty triangle set
//=======================================================================
BRepExtrema_TriangleSet::BRepExtrema_TriangleSet()
-: BVH_PrimitiveSet<Standard_Real, 3>()
{
// Set default builder - linear BVH (LBVH)
- myBuilder = new BVH_LinearBuilder<Standard_Real, 3> (5, 32);
+ myBuilder = new BVH_LinearBuilder<Standard_Real, 3> (BVH_Constants_LeafNodeSizeDefault, BVH_Constants_MaxTreeDepth);
}
//=======================================================================
//purpose : Creates triangle set from the given face
//=======================================================================
BRepExtrema_TriangleSet::BRepExtrema_TriangleSet (const BRepExtrema_ShapeList& theFaces)
-: BVH_PrimitiveSet<Standard_Real, 3>()
{
// Set default builder - linear BVH (LBVH)
- myBuilder = new BVH_LinearBuilder<Standard_Real, 3> (5, 32);
+ myBuilder = new BVH_LinearBuilder<Standard_Real, 3> (BVH_Constants_LeafNodeSizeDefault, BVH_Constants_MaxTreeDepth);
Init (theFaces);
}
#define _BRepExtrema_TriangleSet_HeaderFile
#include <TopoDS_Face.hxx>
-#include <BVH_PrimitiveSet.hxx>
+#include <BVH_PrimitiveSet3d.hxx>
//! List of shapes and their IDs for collision detection.
typedef NCollection_Vector<TopoDS_Face> BRepExtrema_ShapeList;
//! Triangle set corresponding to specific face.
-class BRepExtrema_TriangleSet : public BVH_PrimitiveSet<Standard_Real, 3>, public Standard_Transient
+class BRepExtrema_TriangleSet : public BVH_PrimitiveSet3d
{
public:
BVH_Box<Standard_Real, 3> Box (const Standard_Integer theIndex) const Standard_OVERRIDE;
//! Make inherited method Box() visible to avoid CLang warning
- using BVH_PrimitiveSet<Standard_Real, 3>::Box;
+ using BVH_PrimitiveSet3d::Box;
//! Returns centroid position along specified axis.
Standard_Real Center (const Standard_Integer theIndex, const Standard_Integer theAxis) const Standard_OVERRIDE;
public:
- DEFINE_STANDARD_RTTIEXT(BRepExtrema_TriangleSet,Standard_Transient)
+ DEFINE_STANDARD_RTTIEXT(BRepExtrema_TriangleSet, BVH_PrimitiveSet3d)
};
-DEFINE_STANDARD_HANDLE (BRepExtrema_TriangleSet, Standard_Transient)
+DEFINE_STANDARD_HANDLE(BRepExtrema_TriangleSet, BVH_PrimitiveSet3d)
#endif // _BRepExtrema_TriangleSet_HeaderFile
#include <Standard_Real.hxx>
+IMPLEMENT_STANDARD_RTTIEXT(BVH_BuilderTransient, Standard_Transient)
+IMPLEMENT_STANDARD_RTTIEXT(BVH_TreeBaseTransient, Standard_Transient)
+IMPLEMENT_STANDARD_RTTIEXT(BVH_ObjectTransient, Standard_Transient)
+
// Specific instantiations of struct templates to avoid compilation warnings
template class NCollection_Vec2<Standard_Real>;
//! performance is provided even for 4 - 8 bins (it is only 10-20% lower
//! in comparison with optimal settings). Note that multiple threads can
//! be used only with thread safe BVH primitive sets.
-template<class T, int N, int Bins = 32>
+template<class T, int N, int Bins = BVH_Constants_NbBinsOptimal>
class BVH_BinnedBuilder : public BVH_QueueBuilder<T, N>
{
public:
public:
//! Creates binned SAH BVH builder.
- BVH_BinnedBuilder (const Standard_Integer theLeafNodeSize = 5,
- const Standard_Integer theMaxTreeDepth = 32,
- const Standard_Boolean theDoMainSplits = 0,
+ BVH_BinnedBuilder (const Standard_Integer theLeafNodeSize = BVH_Constants_LeafNodeSizeDefault,
+ const Standard_Integer theMaxTreeDepth = BVH_Constants_MaxTreeDepth,
+ const Standard_Boolean theDoMainSplits = Standard_False,
const Standard_Integer theNumOfThreads = 1)
: BVH_QueueBuilder<T, N> (theLeafNodeSize, theMaxTreeDepth, theNumOfThreads),
myUseMainAxis (theDoMainSplits)
#ifndef _BVH_Box_Header
#define _BVH_Box_Header
+#include <BVH_Constants.hxx>
#include <BVH_Types.hxx>
#include <Standard_ShortReal.hxx>
#include <BVH_Set.hxx>
#include <BVH_BinaryTree.hxx>
-namespace BVH
+//! A non-template class for using as base for BVH_Builder
+//! (just to have a named base class).
+class BVH_BuilderTransient : public Standard_Transient
{
- //! Minimum node size to split.
- const Standard_Real THE_NODE_MIN_SIZE = 1e-5;
-}
+ DEFINE_STANDARD_RTTIEXT(BVH_BuilderTransient, Standard_Transient)
+public:
+
+ //! Returns the maximum depth of constructed BVH.
+ Standard_Integer MaxTreeDepth() const { return myMaxTreeDepth; }
+
+ //! Returns the maximum number of sub-elements in the leaf.
+ Standard_Integer LeafNodeSize() const { return myLeafNodeSize; }
+
+protected:
+
+ //! Creates new abstract BVH builder.
+ BVH_BuilderTransient (const Standard_Integer theLeafNodeSize,
+ const Standard_Integer theMaxTreeDepth)
+ : myMaxTreeDepth (theMaxTreeDepth),
+ myLeafNodeSize (theLeafNodeSize) {}
+
+protected:
+
+ Standard_Integer myMaxTreeDepth; //!< Maximum depth of constructed BVH
+ Standard_Integer myLeafNodeSize; //!< Maximum number of objects per leaf
+
+};
//! Performs construction of BVH tree using bounding
//! boxes (AABBs) of abstract objects.
//! \tparam T Numeric data type
//! \tparam N Vector dimension
template<class T, int N>
-class BVH_Builder
+class BVH_Builder : public BVH_BuilderTransient
{
public:
- //! Creates new abstract BVH builder.
- BVH_Builder (const Standard_Integer theLeafNodeSize,
- const Standard_Integer theMaxTreeDepth)
- : myMaxTreeDepth (theMaxTreeDepth),
- myLeafNodeSize (theLeafNodeSize) {}
-
- //! Releases resources of BVH builder.
- virtual ~BVH_Builder() {}
-
//! Builds BVH using specific algorithm.
virtual void Build (BVH_Set<T, N>* theSet,
BVH_Tree<T, N>* theBVH,
protected:
+ //! Creates new abstract BVH builder.
+ BVH_Builder (const Standard_Integer theLeafNodeSize,
+ const Standard_Integer theMaxTreeDepth)
+ : BVH_BuilderTransient (theLeafNodeSize, theMaxTreeDepth) {}
+
//! Updates depth of constructed BVH tree.
void updateDepth (BVH_Tree<T, N>* theBVH,
const Standard_Integer theLevel) const
}
}
-protected:
-
- Standard_Integer myMaxTreeDepth; //!< Maximum depth of constructed BVH
- Standard_Integer myLeafNodeSize; //!< Maximum number of objects per leaf
-
};
#endif // _BVH_Builder_Header
--- /dev/null
+// Copyright (c) 2017 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 _BVH_Constants_Header
+#define _BVH_Constants_Header
+
+enum
+{
+ //! The optimal tree depth.
+ //! Should be in sync with maximum stack size while traversing the tree - don't pass the trees of greater depth to OCCT algorithms!
+ BVH_Constants_MaxTreeDepth = 32,
+
+ //! Leaf node size optimal for complex nodes,
+ //! e.g. for upper-level BVH trees within multi-level structure (nodes point to another BVH trees).
+ BVH_Constants_LeafNodeSizeSingle = 1,
+ //! Average leaf node size (4 primitive per leaf), optimal for average tree nodes.
+ BVH_Constants_LeafNodeSizeAverage = 4,
+ //! Default leaf node size (5 primitives per leaf).
+ BVH_Constants_LeafNodeSizeDefault = 5,
+ //! Leaf node size (8 primitives per leaf), optimal for small tree nodes (e.g. triangles).
+ BVH_Constants_LeafNodeSizeSmall = 8,
+
+ //! The optimal number of bins for binned builder.
+ BVH_Constants_NbBinsOptimal = 32,
+ //! The maximum number of bins for binned builder (giving the best traversal time at cost of longer tree construction time).
+ BVH_Constants_NbBinsBest = 48,
+};
+
+namespace BVH
+{
+ //! Minimum node size to split.
+ const double THE_NODE_MIN_SIZE = 1e-5;
+}
+
+#endif // _BVH_Constants_Header
Standard_ASSERT_RETURN (aTriangulation != NULL,
"Error: Unsupported BVH object (non triangulation)", aMinDistance);
- const NCollection_Handle<BVH_Tree<T, N> >& aBVH = aTriangulation->BVH();
-
+ const opencascade::handle<BVH_Tree<T, N> >& aBVH = aTriangulation->BVH();
if (aBVH.IsNull())
{
return Standard_False;
}
- std::pair<Standard_Integer, T> aStack[32];
+ std::pair<Standard_Integer, T> aStack[BVH_Constants_MaxTreeDepth];
Standard_Integer aHead = -1;
Standard_Integer aNode = 0; // root node
return Standard_False;
}
- std::pair<Standard_Integer, T> aStack[32];
+ std::pair<Standard_Integer, T> aStack[BVH_Constants_MaxTreeDepth];
Standard_Integer aHead = -1;
Standard_Integer aNode = 0; // root node
//! Creates uninitialized BVH geometry.
BVH_Geometry()
: myIsDirty (Standard_False),
- myBVH (new BVH_Tree<T, N>())
+ myBVH (new BVH_Tree<T, N>()),
+ // set default builder - binned SAH split
+ myBuilder (new BVH_BinnedBuilder<T, N, BVH_Constants_NbBinsOptimal> (BVH_Constants_LeafNodeSizeSingle))
{
- // Set default builder - binned SAH split
- myBuilder = new BVH_BinnedBuilder<T, N, 32> (1 /* primitive per leaf */);
+ //
+ }
+
+ //! Creates uninitialized BVH geometry.
+ BVH_Geometry (const opencascade::handle<BVH_Builder<T, N> >& theBuilder)
+ : myIsDirty (Standard_False),
+ myBVH (new BVH_Tree<T, N>()),
+ myBuilder (theBuilder)
+ {
+ //
}
//! Releases resources of BVH geometry.
}
//! Returns BVH tree (and builds it if necessary).
- virtual const NCollection_Handle<BVH_Tree<T, N> >& BVH()
+ virtual const opencascade::handle<BVH_Tree<T, N> >& BVH()
{
if (myIsDirty)
{
}
//! Returns the method (builder) used to construct BVH.
- virtual const NCollection_Handle<BVH_Builder<T, N> >& Builder() const { return myBuilder; }
+ virtual const opencascade::handle<BVH_Builder<T, N> >& Builder() const { return myBuilder; }
//! Sets the method (builder) used to construct BVH.
- virtual void SetBuilder (const NCollection_Handle<BVH_Builder<T, N> >& theBuilder) { myBuilder = theBuilder; }
+ virtual void SetBuilder (const opencascade::handle<BVH_Builder<T, N> >& theBuilder) { myBuilder = theBuilder; }
protected:
protected:
- Standard_Boolean myIsDirty; //!< Is geometry state outdated?
- NCollection_Handle<BVH_Tree<T, N> > myBVH; //!< Constructed hight-level BVH
- NCollection_Handle<BVH_Builder<T, N> > myBuilder; //!< Builder for hight-level BVH
+ Standard_Boolean myIsDirty; //!< Is geometry state outdated?
+ opencascade::handle<BVH_Tree<T, N> > myBVH; //!< Constructed hight-level BVH
+ opencascade::handle<BVH_Builder<T, N> > myBuilder; //!< Builder for hight-level BVH
mutable BVH_Box<T, N> myBox; //!< Cached bounding box of geometric objects
public:
//! Creates binned LBVH builder.
- BVH_LinearBuilder (const Standard_Integer theLeafNodeSize = 5,
- const Standard_Integer theMaxTreeDepth = 32);
+ BVH_LinearBuilder (const Standard_Integer theLeafNodeSize = BVH_Constants_LeafNodeSizeDefault,
+ const Standard_Integer theMaxTreeDepth = BVH_Constants_MaxTreeDepth);
//! Releases resources of LBVH builder.
virtual ~BVH_LinearBuilder();
#include <BVH_Box.hxx>
#include <BVH_Properties.hxx>
-#include <NCollection_Handle.hxx>
+//! A non-template class for using as base for BVH_Object
+//! (just to have a named base class).
+class BVH_ObjectTransient : public Standard_Transient
+{
+ DEFINE_STANDARD_RTTIEXT(BVH_ObjectTransient, Standard_Transient)
+public:
+
+ //! Returns properties of the geometric object.
+ virtual const Handle(BVH_Properties)& Properties() const { return myProperties; }
+
+ //! Sets properties of the geometric object.
+ virtual void SetProperties (const Handle(BVH_Properties)& theProperties) { myProperties = theProperties; }
+
+ //! Marks object state as outdated (needs BVH rebuilding).
+ virtual void MarkDirty() { myIsDirty = Standard_True; }
+
+protected:
+
+ //! Creates new abstract geometric object.
+ BVH_ObjectTransient() : myIsDirty (Standard_False) {}
+
+protected:
+
+ Standard_Boolean myIsDirty; //!< Marks internal object state as outdated
+ Handle(BVH_Properties) myProperties; //!< Generic properties assigned to the object
+
+};
//! Abstract geometric object bounded by BVH box.
//! \tparam T Numeric data type
//! \tparam N Vector dimension
template<class T, int N>
-class BVH_Object
+class BVH_Object : public BVH_ObjectTransient
{
public:
//! Creates new abstract geometric object.
- BVH_Object() : myIsDirty (Standard_False) {}
+ BVH_Object() {}
//! Releases resources of geometric object.
virtual ~BVH_Object() = 0;
//! Returns AABB of the geometric object.
virtual BVH_Box<T, N> Box() const = 0;
- //! Returns properties of the geometric object.
- virtual const NCollection_Handle<BVH_Properties>& Properties() const { return myProperties; }
-
- //! Sets properties of the geometric object.
- virtual void SetProperties (const NCollection_Handle<BVH_Properties>& theProperties) { myProperties = theProperties; }
-
- //! Marks object state as outdated (needs BVH rebuilding).
- virtual void MarkDirty() { myIsDirty = Standard_True; }
-
-protected:
-
- Standard_Boolean myIsDirty; //!< Marks internal object state as outdated
- NCollection_Handle<BVH_Properties> myProperties; //!< Generic properties assigned to the object
-
};
// =======================================================================
public:
//! Type of array of geometric objects.
- typedef NCollection_Vector<NCollection_Handle<BVH_Object<T, N> > > BVH_ObjectList;
+ typedef NCollection_Vector<opencascade::handle<BVH_Object<T, N> > > BVH_ObjectList;
public:
using BVH_Set<T, N>::Box;
public:
- static const Standard_Integer MaxTreeDepth = 32;
+ static const Standard_Integer MaxTreeDepth = BVH_Constants_MaxTreeDepth;
//! Creates set of abstract primitives.
BVH_PrimitiveSet()
- : myBVH (new BVH_Tree<T, N>())
+ : myBVH (new BVH_Tree<T, N>()),
+ // set default builder - binned SAH split
+ myBuilder (new BVH_BinnedBuilder<T, N, BVH_Constants_NbBinsBest> (BVH_Constants_LeafNodeSizeDefault, BVH_Constants_MaxTreeDepth))
{
- // Set default builder - binned SAH split
- myBuilder = new BVH_BinnedBuilder<T, N, 48> (5, MaxTreeDepth);
+ //
+ }
+
+ //! Creates set of abstract primitives.
+ BVH_PrimitiveSet (const opencascade::handle<BVH_Builder<T, N> >& theBuilder)
+ : myBVH (new BVH_Tree<T, N>()),
+ myBuilder (theBuilder)
+ {
+ //
}
//! Releases resources of set of abstract primitives.
}
//! Returns BVH tree (and builds it if necessary).
- virtual const NCollection_Handle<BVH_Tree<T, N> >& BVH()
+ virtual const opencascade::handle<BVH_Tree<T, N> >& BVH()
{
if (BVH_Object<T, N>::myIsDirty)
{
}
//! Returns the method (builder) used to construct BVH.
- virtual const NCollection_Handle<BVH_Builder<T, N> >& Builder() const { return myBuilder; }
+ virtual const opencascade::handle<BVH_Builder<T, N> >& Builder() const { return myBuilder; }
//! Sets the method (builder) used to construct BVH.
- virtual void SetBuilder (const NCollection_Handle<BVH_Builder<T, N> >& theBuilder) { myBuilder = theBuilder; }
+ virtual void SetBuilder (const opencascade::handle<BVH_Builder<T, N> >& theBuilder) { myBuilder = theBuilder; }
protected:
protected:
- NCollection_Handle<BVH_Tree<T, N> > myBVH; //!< Constructed bottom-level BVH
- NCollection_Handle<BVH_Builder<T, N> > myBuilder; //!< Builder for bottom-level BVH
+ opencascade::handle<BVH_Tree<T, N> > myBVH; //!< Constructed bottom-level BVH
+ opencascade::handle<BVH_Builder<T, N> > myBuilder; //!< Builder for bottom-level BVH
mutable BVH_Box<T, N> myBox; //!< Cached bounding box of geometric primitives
--- /dev/null
+// Copyright (c) 2017 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 _BVH_PrimitiveSet3d_Header
+#define _BVH_PrimitiveSet3d_Header
+
+#include <BVH_PrimitiveSet.hxx>
+
+typedef BVH_PrimitiveSet<Standard_Real, 3> BVH_PrimitiveSet3d;
+
+#endif // _BVH_PrimitiveSet3d_Header
#include <BVH_Properties.hxx>
-//! Abstract properties of geometric object.
+IMPLEMENT_STANDARD_RTTIEXT(BVH_Properties, Standard_Transient)
+
+// =======================================================================
+// function : ~BVH_Properties
+// purpose :
+// =======================================================================
BVH_Properties::~BVH_Properties()
{
//
-}
\ No newline at end of file
+}
#include <Standard_Macro.hxx>
//! Abstract properties of geometric object.
-class BVH_Properties
+class BVH_Properties : public Standard_Transient
{
+ DEFINE_STANDARD_RTTIEXT(BVH_Properties, Standard_Transient)
public:
//! Releases resources of object properties.
#include <BVH_Sorter.hxx>
#include <BVH_Builder.hxx>
-#include <NCollection_Handle.hxx>
#include <NCollection_Array1.hxx>
+#include <NCollection_Shared.hxx>
#include <algorithm>
BVH_Box<T, N> myBox;
//! Morton codes assigned to BVH primitives.
- NCollection_Handle<NCollection_Array1<BVH_EncodedLink> > myEncodedLinks;
+ Handle(NCollection_Shared<NCollection_Array1<BVH_EncodedLink> >) myEncodedLinks;
};
const T aReverseSizeY = static_cast<T> (aDimensionY) / Max (static_cast<T> (BVH::THE_NODE_MIN_SIZE), aSceneMax.y() - aSceneMin.y());
const T aReverseSizeZ = static_cast<T> (aDimensionZ) / Max (static_cast<T> (BVH::THE_NODE_MIN_SIZE), aSceneMax.z() - aSceneMin.z());
- myEncodedLinks = new NCollection_Array1<BVH_EncodedLink> (theStart, theFinal);
+ myEncodedLinks = new NCollection_Shared<NCollection_Array1<BVH_EncodedLink> >(theStart, theFinal);
// Step 1 -- Assign Morton code to each primitive
for (Standard_Integer aPrimIdx = theStart; aPrimIdx <= theFinal; ++aPrimIdx)
public:
//! Creates spatial median split builder.
- BVH_SpatialMedianBuilder (const Standard_Integer theLeafNodeSize = 5,
- const Standard_Integer theMaxTreeDepth = 32,
+ BVH_SpatialMedianBuilder (const Standard_Integer theLeafNodeSize = BVH_Constants_LeafNodeSizeDefault,
+ const Standard_Integer theMaxTreeDepth = BVH_Constants_MaxTreeDepth,
const Standard_Boolean theToUseMainAxis = Standard_False)
: BVH_BinnedBuilder<T, N, 2> (theLeafNodeSize,
theMaxTreeDepth,
public:
//! Creates sweep plane SAH BVH builder.
- BVH_SweepPlaneBuilder (const Standard_Integer theLeafNodeSize = 5,
- const Standard_Integer theMaxTreeDepth = 32,
+ BVH_SweepPlaneBuilder (const Standard_Integer theLeafNodeSize = BVH_Constants_LeafNodeSizeDefault,
+ const Standard_Integer theMaxTreeDepth = BVH_Constants_MaxTreeDepth,
const Standard_Integer theNumOfThreads = 1)
: BVH_QueueBuilder<T, N> (theLeafNodeSize,
theMaxTreeDepth,
template<class T, int N> class BVH_Builder;
+//! A non-template class for using as base for BVH_TreeBase
+//! (just to have a named base class).
+class BVH_TreeBaseTransient : public Standard_Transient
+{
+ DEFINE_STANDARD_RTTIEXT(BVH_TreeBaseTransient, Standard_Transient)
+protected:
+ BVH_TreeBaseTransient() {}
+};
+
//! Stores parameters of bounding volume hierarchy (BVH).
//! Bounding volume hierarchy (BVH) organizes geometric objects in
//! the tree based on spatial relationships. Each node in the tree
//! such as collision detection, ray-tracing, searching of nearest
//! objects, and view frustum culling.
template<class T, int N>
-class BVH_TreeBase
+class BVH_TreeBase : public BVH_TreeBaseTransient
{
friend class BVH_Builder<T, N>;
//! Creates empty triangulation.
BVH_Triangulation() {}
+ //! Creates empty triangulation.
+ BVH_Triangulation (const opencascade::handle<BVH_Builder<T, N> >& theBuilder)
+ : BVH_PrimitiveSet<T, N> (theBuilder)
+ {
+ //
+ }
+
//! Releases resources of triangulation.
virtual ~BVH_Triangulation() {}
#include <NCollection_Vec2.hxx>
#include <NCollection_Vec3.hxx>
#include <NCollection_Vector.hxx>
+#include <Standard_Type.hxx>
// GCC supports shrink function only in C++11 mode
#if defined(_BVH_USE_STD_VECTOR_) && defined(_MSC_VER) && !defined(__INTEL_COMPILER)
BVH_BuildQueue.cxx
BVH_BuildThread.hxx
BVH_BuildThread.cxx
+BVH_Constants.hxx
BVH_DistanceField.hxx
BVH_DistanceField.lxx
BVH_Geometry.hxx
BVH_Object.hxx
BVH_ObjectSet.hxx
BVH_PrimitiveSet.hxx
+BVH_PrimitiveSet3d.hxx
BVH_Properties.cxx
BVH_Properties.hxx
BVH_QueueBuilder.hxx
#include <BVH_BinnedBuilder.hxx>
#include <Graphic3d_GraphicDriver.hxx>
+IMPLEMENT_STANDARD_RTTIEXT(OpenGl_BVHClipPrimitiveSet, BVH_PrimitiveSet3d)
+
// =======================================================================
// function : OpenGl_BVHClipPrimitiveSet
// purpose :
// =======================================================================
OpenGl_BVHClipPrimitiveSet::OpenGl_BVHClipPrimitiveSet()
{
- myBuilder = new BVH_BinnedBuilder<Standard_Real, 3> (1, 32);
+ myBuilder = new BVH_BinnedBuilder<Standard_Real, 3> (BVH_Constants_LeafNodeSizeSingle, BVH_Constants_MaxTreeDepth);
}
// =======================================================================
#ifndef _OpenGl_BVHClipPrimitiveSet_HeaderFile
#define _OpenGl_BVHClipPrimitiveSet_HeaderFile
-#include <BVH_PrimitiveSet.hxx>
+#include <BVH_PrimitiveSet3d.hxx>
#include <NCollection_Array1.hxx>
#include <NCollection_IndexedMap.hxx>
#include <OpenGl_Structure.hxx>
//! Set of OpenGl_Structures for building BVH tree.
-class OpenGl_BVHClipPrimitiveSet : public BVH_PrimitiveSet<Standard_Real, 3>
+class OpenGl_BVHClipPrimitiveSet : public BVH_PrimitiveSet3d
{
+ DEFINE_STANDARD_RTTIEXT(OpenGl_BVHClipPrimitiveSet, BVH_PrimitiveSet3d)
protected:
- using BVH_PrimitiveSet<Standard_Real, 3>::Box;
+ using BVH_PrimitiveSet3d::Box;
public:
// commercial license or contractual agreement.
#include <OpenGl_BVHClipPrimitiveTrsfPersSet.hxx>
-#include <BVH_LinearBuilder.hxx>
// =======================================================================
// function : OpenGl_BVHClipPrimitiveTrsfPersSet
// purpose :
// =======================================================================
-OpenGl_BVHClipPrimitiveTrsfPersSet::OpenGl_BVHClipPrimitiveTrsfPersSet()
+OpenGl_BVHClipPrimitiveTrsfPersSet::OpenGl_BVHClipPrimitiveTrsfPersSet (const Handle(Select3D_BVHBuilder3d)& theBuilder)
: myIsDirty (Standard_False),
- myBVH (new BVH_Tree<Standard_Real, 3>())
+ myBVH (new BVH_Tree<Standard_Real, 3>()),
+ myBuilder (theBuilder)
{
- myBuilder = new BVH_LinearBuilder<Standard_Real, 3> (1, 32);
+ //
}
// =======================================================================
// function : BVH
// purpose :
//=======================================================================
-const NCollection_Handle<BVH_Tree<Standard_Real, 3> >&
+const opencascade::handle<BVH_Tree<Standard_Real, 3> >&
OpenGl_BVHClipPrimitiveTrsfPersSet::BVH (const Handle(Graphic3d_Camera)& theCamera,
const OpenGl_Mat4d& theProjectionMatrix,
const OpenGl_Mat4d& theWorldViewMatrix,
#ifndef _OpenGl_BVHClipPrimitiveTrsfPersSet_HeaderFile
#define _OpenGl_BVHClipPrimitiveTrsfPersSet_HeaderFile
-#include <BVH_Builder.hxx>
#include <BVH_Set.hxx>
#include <BVH_Tree.hxx>
#include <Graphic3d_BndBox4f.hxx>
#include <NCollection_IndexedMap.hxx>
#include <OpenGl_Structure.hxx>
#include <OpenGl_Vec.hxx>
+#include <Select3D_BVHBuilder3d.hxx>
//! Set of transformation persistent OpenGl_Structure for building BVH tree.
//! Provides built-in mechanism to invalidate tree when world view projection state changes.
public:
//! Creates an empty primitive set for BVH clipping.
- OpenGl_BVHClipPrimitiveTrsfPersSet();
+ OpenGl_BVHClipPrimitiveTrsfPersSet (const Handle(Select3D_BVHBuilder3d)& theBuilder);
//! Returns total number of structures.
virtual Standard_Integer Size() const Standard_OVERRIDE;
}
//! Returns BVH tree for the given world view projection (builds it if necessary).
- const NCollection_Handle<BVH_Tree<Standard_Real, 3> >& BVH (const Handle(Graphic3d_Camera)& theCamera,
- const OpenGl_Mat4d& theProjectionMatrix,
- const OpenGl_Mat4d& theWorldViewMatrix,
- const Standard_Integer theViewportWidth,
- const Standard_Integer theViewportHeight,
- const Graphic3d_WorldViewProjState& theWVPState);
+ const opencascade::handle<BVH_Tree<Standard_Real, 3> >& BVH (const Handle(Graphic3d_Camera)& theCamera,
+ const OpenGl_Mat4d& theProjectionMatrix,
+ const OpenGl_Mat4d& theWorldViewMatrix,
+ const Standard_Integer theViewportWidth,
+ const Standard_Integer theViewportHeight,
+ const Graphic3d_WorldViewProjState& theWVPState);
+
+ //! Returns builder for bottom-level BVH.
+ const Handle(Select3D_BVHBuilder3d)& Builder() const { return myBuilder; }
+
+ //! Assigns builder for bottom-level BVH.
+ void SetBuilder (const Handle(Select3D_BVHBuilder3d)& theBuilder) { myBuilder = theBuilder; }
private:
Standard_Boolean myIsDirty;
//! Constructed bottom-level BVH.
- NCollection_Handle<BVH_Tree<Standard_Real, 3> > myBVH;
+ opencascade::handle<BVH_Tree<Standard_Real, 3> > myBVH;
//! Builder for bottom-level BVH.
- NCollection_Handle<BVH_Builder<Standard_Real, 3> > myBuilder;
+ Handle(Select3D_BVHBuilder3d) myBuilder;
//! Indexed map of structures.
NCollection_IndexedMap<const OpenGl_Structure*> myStructs;
#include <OpenGl_Workspace.hxx>
#include <Graphic3d_GraphicDriver.hxx>
+IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Layer, Standard_Transient)
+
// =======================================================================
// function : OpenGl_Layer
// purpose :
// =======================================================================
-OpenGl_Layer::OpenGl_Layer (const Standard_Integer theNbPriorities)
+OpenGl_Layer::OpenGl_Layer (const Standard_Integer theNbPriorities,
+ const Handle(Select3D_BVHBuilder3d)& theBuilder)
: myArray (0, theNbPriorities - 1),
myNbStructures (0),
+ myBVHPrimitivesTrsfPers (theBuilder),
myBVHIsLeftChildQueuedFirst (Standard_True),
myIsBVHPrimitivesNeedsReset (Standard_False)
{
theSelector.CacheClipPtsProjections();
- NCollection_Handle<BVH_Tree<Standard_Real, 3> > aBVHTree;
-
+ opencascade::handle<BVH_Tree<Standard_Real, 3> > aBVHTree;
for (Standard_Integer aBVHTreeIdx = 0; aBVHTreeIdx < 2; ++aBVHTreeIdx)
{
const Standard_Boolean isTrsfPers = aBVHTreeIdx == 1;
continue;
}
- Standard_Integer aStack[32];
+ Standard_Integer aStack[BVH_Constants_MaxTreeDepth];
Standard_Integer aHead = -1;
for (;;)
{
typedef NCollection_Array1<OpenGl_IndexedMapOfStructure> OpenGl_ArrayOfIndexedMapOfStructure;
//! Presentations list sorted within priorities.
-class OpenGl_Layer
+class OpenGl_Layer : public Standard_Transient
{
+ DEFINE_STANDARD_RTTIEXT(OpenGl_Layer, Standard_Transient)
public:
//! Initializes associated priority list and layer properties
- OpenGl_Layer (const Standard_Integer theNbPriorities = 11);
+ OpenGl_Layer (const Standard_Integer theNbPriorities,
+ const Handle(Select3D_BVHBuilder3d)& theBuilder);
//! Destructor.
virtual ~OpenGl_Layer();
+ //! Returns BVH tree builder for frustom culling.
+ const Handle(Select3D_BVHBuilder3d)& FrustumCullingBVHBuilder() const { return myBVHPrimitivesTrsfPers.Builder(); }
+
+ //! Assigns BVH tree builder for frustom culling.
+ void SetFrustumCullingBVHBuilder (const Handle(Select3D_BVHBuilder3d)& theBuilder) { myBVHPrimitivesTrsfPers.SetBuilder (theBuilder); }
+
//! Return true if layer was marked with immediate flag.
Standard_Boolean IsImmediate() const { return myLayerSettings.IsImmediate(); }
#include <OpenGl_GlCore15.hxx>
+#include <BVH_LinearBuilder.hxx>
#include <OpenGl_FrameBuffer.hxx>
#include <OpenGl_LayerList.hxx>
#include <OpenGl_ShaderManager.hxx>
//=======================================================================
OpenGl_LayerList::OpenGl_LayerList (const Standard_Integer theNbPriorities)
-: myDefaultLayerIndex (0),
+: myBVHBuilder (new BVH_LinearBuilder<Standard_Real, 3> (BVH_Constants_LeafNodeSizeSingle, BVH_Constants_MaxTreeDepth)),
+ myDefaultLayerIndex (0),
myNbPriorities (theNbPriorities),
myNbStructures (0),
myImmediateNbStructures (0),
myRenderTranspFilter (new OpenGl_TransparentFilter())
{
// insert default priority layers
- myLayers.Append (OpenGl_Layer (myNbPriorities));
+ myLayers.Append (new OpenGl_Layer (myNbPriorities, myBVHBuilder));
myLayerIds.Bind (Graphic3d_ZLayerId_BotOSD, myLayers.Upper());
- myLayers.Append (OpenGl_Layer (myNbPriorities));
+ myLayers.Append (new OpenGl_Layer (myNbPriorities, myBVHBuilder));
myLayerIds.Bind (Graphic3d_ZLayerId_Default, myLayers.Upper());
- myLayers.Append (OpenGl_Layer (myNbPriorities));
+ myLayers.Append (new OpenGl_Layer (myNbPriorities, myBVHBuilder));
myLayerIds.Bind (Graphic3d_ZLayerId_Top, myLayers.Upper());
- myLayers.Append (OpenGl_Layer (myNbPriorities));
+ myLayers.Append (new OpenGl_Layer (myNbPriorities, myBVHBuilder));
myLayerIds.Bind (Graphic3d_ZLayerId_Topmost, myLayers.Upper());
- myLayers.Append (OpenGl_Layer (myNbPriorities));
+ myLayers.Append (new OpenGl_Layer (myNbPriorities, myBVHBuilder));
myLayerIds.Bind (Graphic3d_ZLayerId_TopOSD, myLayers.Upper());
myDefaultLayerIndex = myLayerIds.Find (Graphic3d_ZLayerId_Default);
{
}
+//=======================================================================
+//function : SetFrustumCullingBVHBuilder
+//purpose :
+//=======================================================================
+void OpenGl_LayerList::SetFrustumCullingBVHBuilder (const Handle(Select3D_BVHBuilder3d)& theBuilder)
+{
+ myBVHBuilder = theBuilder;
+ for (OpenGl_SequenceOfLayers::Iterator anIts (myLayers); anIts.More(); anIts.Next())
+ {
+ anIts.ChangeValue()->SetFrustumCullingBVHBuilder (theBuilder);
+ }
+}
+
//=======================================================================
//function : AddLayer
//purpose :
}
// add the new layer
- myLayers.Append (OpenGl_Layer (myNbPriorities));
+ myLayers.Append (new OpenGl_Layer (myNbPriorities, myBVHBuilder));
myLayerIds.Bind (theLayerId, myLayers.Length());
myTransparentToProcess.Allocate (myLayers.Length());
//=======================================================================
OpenGl_Layer& OpenGl_LayerList::Layer (const Graphic3d_ZLayerId theLayerId)
{
- return myLayers.ChangeValue (myLayerIds.Find (theLayerId));
+ return *myLayers.ChangeValue (myLayerIds.Find (theLayerId));
}
//=======================================================================
//=======================================================================
const OpenGl_Layer& OpenGl_LayerList::Layer (const Graphic3d_ZLayerId theLayerId) const
{
- return myLayers.Value (myLayerIds.Find (theLayerId));
+ return *myLayers.Value (myLayerIds.Find (theLayerId));
}
//=======================================================================
const Standard_Integer aRemovePos = myLayerIds.Find (theLayerId);
// move all displayed structures to first layer
- const OpenGl_Layer& aLayerToMove = myLayers.Value (aRemovePos);
- myLayers.ChangeFirst().Append (aLayerToMove);
+ {
+ const OpenGl_Layer& aLayerToMove = *myLayers.Value (aRemovePos);
+ myLayers.ChangeFirst()->Append (aLayerToMove);
+ }
// remove layer
myLayers.Remove (aRemovePos);
Standard_Integer aSeqPos = myLayers.Lower();
myLayerIds.Find (theLayerId, aSeqPos);
- OpenGl_Layer& aLayer = myLayers.ChangeValue (aSeqPos);
+ OpenGl_Layer& aLayer = *myLayers.ChangeValue (aSeqPos);
aLayer.Add (theStruct, thePriority, isForChangePriority);
++myNbStructures;
if (aLayer.IsImmediate())
Standard_Integer aSeqPos = myLayers.Lower();
myLayerIds.Find (aLayerId, aSeqPos);
- OpenGl_Layer& aLayer = myLayers.ChangeValue (aSeqPos);
+ OpenGl_Layer& aLayer = *myLayers.ChangeValue (aSeqPos);
Standard_Integer aPriority = -1;
// remove structure from associated list
Standard_Integer aSeqId = 1;
for (OpenGl_SequenceOfLayers::Iterator anIts (myLayers); anIts.More(); anIts.Next(), ++aSeqId)
{
- OpenGl_Layer& aLayerEx = anIts.ChangeValue();
+ OpenGl_Layer& aLayerEx = *anIts.ChangeValue();
if (aSeqPos == aSeqId)
{
continue;
{
Standard_Integer aSeqPos = myLayers.Lower();
myLayerIds.Find (theLayerId, aSeqPos);
- OpenGl_Layer& aLayer = myLayers.ChangeValue (aSeqPos);
+ OpenGl_Layer& aLayer = *myLayers.ChangeValue (aSeqPos);
aLayer.InvalidateBVHData();
}
{
Standard_Integer aSeqPos = myLayers.Lower();
myLayerIds.Find (theOldLayerId, aSeqPos);
- OpenGl_Layer& aLayer = myLayers.ChangeValue (aSeqPos);
+ OpenGl_Layer& aLayer = *myLayers.ChangeValue (aSeqPos);
Standard_Integer aPriority = -1;
// take priority and remove structure from list found by <theOldLayerId>
}
// try to remove structure and get priority value from this layer
- OpenGl_Layer& aLayerEx = anIts.ChangeValue();
+ OpenGl_Layer& aLayerEx = *anIts.ChangeValue();
if (aLayerEx.Remove (theStructure, aPriority, Standard_True))
{
if (aSeqId == myDefaultLayerIndex
{
Standard_Integer aSeqPos = myLayers.Lower();
myLayerIds.Find (theLayerId, aSeqPos);
- OpenGl_Layer& aLayer = myLayers.ChangeValue (aSeqPos);
+ OpenGl_Layer& aLayer = *myLayers.ChangeValue (aSeqPos);
Standard_Integer anOldPriority = -1;
if (aLayer.Remove (theStructure, anOldPriority, Standard_True))
continue;
}
- OpenGl_Layer& aLayerEx = anIts.ChangeValue();
+ OpenGl_Layer& aLayerEx = *anIts.ChangeValue();
if (aLayerEx.Remove (theStructure, anOldPriority, Standard_True))
{
--myNbStructures;
if (aSeqId != myDefaultLayerIndex) continue;
}
- const OpenGl_Layer& aLayer = aLayerIter.Value();
+ const OpenGl_Layer& aLayer = *aLayerIter.Value();
if (aLayer.IsImmediate() != theToDrawImmediate)
{
continue;
class OpenGl_Structure;
-typedef NCollection_Sequence<OpenGl_Layer> OpenGl_SequenceOfLayers;
+typedef NCollection_Sequence<Handle(OpenGl_Layer)> OpenGl_SequenceOfLayers;
typedef NCollection_DataMap<int, int> OpenGl_LayerSeqIds;
//! Class defining the list of layers.
public:
//! Constructor
- OpenGl_LayerList (const Standard_Integer theNbPriorities = 11);
+ OpenGl_LayerList (const Standard_Integer theNbPriorities);
//! Destructor
virtual ~OpenGl_LayerList();
//! Returns structure modification state (for ray-tracing).
Standard_Size ModificationStateOfRaytracable() const { return myModifStateOfRaytraceable; }
+ //! Returns BVH tree builder for frustom culling.
+ const Handle(Select3D_BVHBuilder3d)& FrustumCullingBVHBuilder() const { return myBVHBuilder; }
+
+ //! Assigns BVH tree builder for frustom culling.
+ void SetFrustumCullingBVHBuilder (const Handle(Select3D_BVHBuilder3d)& theBuilder);
+
protected:
//! Filter of TKOpenGl elements for processing only shading geometry and
// number of structures temporary put to default layer
OpenGl_SequenceOfLayers myLayers;
OpenGl_LayerSeqIds myLayerIds;
+ Handle(Select3D_BVHBuilder3d) myBVHBuilder; //!< BVH tree builder for frustom culling
Standard_Integer myDefaultLayerIndex; //!< index of Graphic3d_ZLayerId_Default layer in myLayers sequence
Standard_Integer myNbPriorities;
static const BVH_Vec4f ZERO_VEC_4F;
}
+IMPLEMENT_STANDARD_RTTIEXT(OpenGl_TriangleSet, OpenGl_BVHTriangulation3f)
+
// =======================================================================
// function : OpenGl_RaytraceMaterial
// purpose : Creates new default material
// =======================================================================
OpenGl_TriangleSet::BVH_BoxNt OpenGl_TriangleSet::Box() const
{
- const BVH_Transform<Standard_ShortReal, 4>* aTransform =
- dynamic_cast<const BVH_Transform<Standard_ShortReal, 4>* > (Properties().operator->());
-
BVH_BoxNt aBox = BVH_PrimitiveSet<Standard_ShortReal, 3>::Box();
-
- if (aTransform != NULL)
+ const BVH_Transform<Standard_ShortReal, 4>* aTransform = dynamic_cast<const BVH_Transform<Standard_ShortReal, 4>* > (Properties().get());
+ if (aTransform == NULL)
{
- BVH_BoxNt aTransformedBox;
+ return aBox;
+ }
- for (Standard_Integer aX = 0; aX <= 1; ++aX)
+ BVH_BoxNt aTransformedBox;
+ for (Standard_Integer aX = 0; aX <= 1; ++aX)
+ {
+ for (Standard_Integer aY = 0; aY <= 1; ++aY)
{
- for (Standard_Integer aY = 0; aY <= 1; ++aY)
+ for (Standard_Integer aZ = 0; aZ <= 1; ++aZ)
{
- for (Standard_Integer aZ = 0; aZ <= 1; ++aZ)
- {
- BVH_Vec4f aCorner = aTransform->Transform() * BVH_Vec4f (
- aX == 0 ? aBox.CornerMin().x() : aBox.CornerMax().x(),
- aY == 0 ? aBox.CornerMin().y() : aBox.CornerMax().y(),
- aZ == 0 ? aBox.CornerMin().z() : aBox.CornerMax().z(),
- 1.f);
-
- aTransformedBox.Add (aCorner.xyz());
- }
+ BVH_Vec4f aCorner = aTransform->Transform() * BVH_Vec4f (
+ aX == 0 ? aBox.CornerMin().x() : aBox.CornerMax().x(),
+ aY == 0 ? aBox.CornerMin().y() : aBox.CornerMax().y(),
+ aZ == 0 ? aBox.CornerMin().z() : aBox.CornerMax().z(),
+ 1.f);
+
+ aTransformedBox.Add (aCorner.xyz());
}
}
-
- return aTransformedBox;
}
-
- return aBox;
+ return aTransformedBox;
}
// =======================================================================
// function : OpenGl_TriangleSet
// purpose : Creates new OpenGL element triangulation
// =======================================================================
-OpenGl_TriangleSet::OpenGl_TriangleSet (const Standard_Size theArrayID)
-: BVH_Triangulation<Standard_ShortReal, 3>(),
+OpenGl_TriangleSet::OpenGl_TriangleSet (const Standard_Size theArrayID,
+ const opencascade::handle<BVH_Builder<Standard_ShortReal, 3> >& theBuilder)
+: BVH_Triangulation<Standard_ShortReal, 3> (theBuilder),
myArrayID (theArrayID)
{
- myBuilder = new BVH_BinnedBuilder<Standard_ShortReal, 3 /* dim */, 48 /* bins */>
- (4 /* leaf size */, 32 /* max height */, Standard_False, OSD_Parallel::NbLogicalProcessors() + 1 /* threads */);
+ //
}
// =======================================================================
};
//! Shared pointer to quad BVH (QBVH) tree.
-typedef NCollection_Handle<BVH_Tree<Standard_ShortReal, 3, BVH_QuadTree> > QuadBvhHandle;
+typedef opencascade::handle<BVH_Tree<Standard_ShortReal, 3, BVH_QuadTree> > QuadBvhHandle;
+typedef BVH_Triangulation<Standard_ShortReal, 3> OpenGl_BVHTriangulation3f;
//! Triangulation of single OpenGL primitive array.
-class OpenGl_TriangleSet : public BVH_Triangulation<Standard_ShortReal, 3>
+class OpenGl_TriangleSet : public OpenGl_BVHTriangulation3f
{
+ DEFINE_STANDARD_RTTIEXT(OpenGl_TriangleSet, OpenGl_BVHTriangulation3f)
public:
//! Value of invalid material index to return in case of errors.
public:
//! Creates new OpenGL element triangulation.
- OpenGl_TriangleSet (const Standard_Size theArrayID);
+ OpenGl_TriangleSet (const Standard_Size theArrayID,
+ const opencascade::handle<BVH_Builder<Standard_ShortReal, 3> >& theBuilder);
//! Returns ID of associated primitive array.
Standard_Size AssociatedPArrayID() const
}
//! Returns AABB of primitive set.
- BVH_BoxNt Box() const;
+ virtual BVH_BoxNt Box() const Standard_OVERRIDE;
//! Returns AABB of the given object.
using BVH_Triangulation<Standard_ShortReal, 3>::Box;
//! Returns centroid position along the given axis.
- Standard_ShortReal Center (const Standard_Integer theIndex, const Standard_Integer theAxis) const;
+ virtual Standard_ShortReal Center (const Standard_Integer theIndex, const Standard_Integer theAxis) const Standard_OVERRIDE;
//! Returns quad BVH (QBVH) tree produced from binary BVH.
const QuadBvhHandle& QuadBVH();
#include <OpenGl_Texture.hxx>
#include <OpenGl_Window.hxx>
#include <OpenGl_Workspace.hxx>
+#include <OSD_Parallel.hxx>
#include <Standard_CLocaleSentry.hxx>
+#include "../Graphic3d/Graphic3d_Structure.pxx"
+
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_View,Graphic3d_CView)
#ifdef HAVE_GL2PS
myBgColor (Quantity_NOC_BLACK),
myCamera (new Graphic3d_Camera()),
myToShowGradTrihedron (false),
+ myZLayers (Structure_MAX_PRIORITY - Structure_MIN_PRIORITY + 1),
myStateCounter (theCounter),
myLastLightSourceState (0, 0),
#if !defined(GL_ES_VERSION_2_0)
myRaytraceInitStatus (OpenGl_RT_NONE),
myIsRaytraceDataValid (Standard_False),
myIsRaytraceWarnTextures (Standard_False),
+ myRaytraceBVHBuilder (new BVH_BinnedBuilder<Standard_ShortReal, 3, BVH_Constants_NbBinsBest> (BVH_Constants_LeafNodeSizeAverage,
+ BVH_Constants_MaxTreeDepth,
+ Standard_False,
+ OSD_Parallel::NbLogicalProcessors() + 1)),
+ myRaytraceSceneRadius (0.0f),
+ myRaytraceSceneEpsilon (1.0e-6f),
myToUpdateEnvironmentMap (Standard_False),
myRaytraceLayerListState (0),
myPrevCameraApertureRadius(0.f),
const Handle(OpenGl_Context)& theGlContext);
//! Adds OpenGL primitive array to ray-traced scene geometry.
- OpenGl_TriangleSet* addRaytracePrimitiveArray (const OpenGl_PrimitiveArray* theArray,
- const Standard_Integer theMatID,
- const OpenGl_Mat4* theTrans);
+ Handle(OpenGl_TriangleSet) addRaytracePrimitiveArray (const OpenGl_PrimitiveArray* theArray,
+ const Standard_Integer theMatID,
+ const OpenGl_Mat4* theTrans);
//! Adds vertex indices from OpenGL primitive array to ray-traced scene geometry.
Standard_Boolean addRaytraceVertexIndices (OpenGl_TriangleSet& theSet,
//! 3D scene geometry data for ray-tracing.
OpenGl_RaytraceGeometry myRaytraceGeometry;
+ //! Builder for triangle set.
+ opencascade::handle<BVH_Builder<Standard_ShortReal, 3> > myRaytraceBVHBuilder;
+
//! Compile-time ray-tracing parameters.
RaytracingParams myRaytraceParameters;
if (aSetIter != myArrayToTrianglesMap.end())
{
OpenGl_TriangleSet* aSet = aSetIter->second;
-
- BVH_Transform<Standard_ShortReal, 4>* aTransform = new BVH_Transform<Standard_ShortReal, 4>();
-
+ opencascade::handle<BVH_Transform<Standard_ShortReal, 4> > aTransform = new BVH_Transform<Standard_ShortReal, 4>();
if (!theTrsf.IsNull())
{
theTrsf->Trsf().GetMat4 (aMat4);
}
aSet->SetProperties (aTransform);
-
if (aSet->MaterialIndex() != OpenGl_TriangleSet::INVALID_MATERIAL && aSet->MaterialIndex() != aMatID)
{
aSet->SetMaterialIndex (aMatID);
}
else
{
- NCollection_Handle<BVH_Object<Standard_ShortReal, 3> > aSet =
- addRaytracePrimitiveArray (aPrimArray, aMatID, 0);
-
- if (!aSet.IsNull())
+ if (Handle(OpenGl_TriangleSet) aSet = addRaytracePrimitiveArray (aPrimArray, aMatID, 0))
{
- BVH_Transform<Standard_ShortReal, 4>* aTransform = new BVH_Transform<Standard_ShortReal, 4>;
-
+ opencascade::handle<BVH_Transform<Standard_ShortReal, 4> > aTransform = new BVH_Transform<Standard_ShortReal, 4>();
if (!theTrsf.IsNull())
{
theTrsf->Trsf().GetMat4 (aMat4);
}
aSet->SetProperties (aTransform);
-
myRaytraceGeometry.Objects().Append (aSet);
}
}
// function : addRaytracePrimitiveArray
// purpose : Adds OpenGL primitive array to ray-traced scene geometry
// =======================================================================
-OpenGl_TriangleSet* OpenGl_View::addRaytracePrimitiveArray (const OpenGl_PrimitiveArray* theArray,
- const Standard_Integer theMaterial,
- const OpenGl_Mat4* theTransform)
+Handle(OpenGl_TriangleSet) OpenGl_View::addRaytracePrimitiveArray (const OpenGl_PrimitiveArray* theArray,
+ const Standard_Integer theMaterial,
+ const OpenGl_Mat4* theTransform)
{
const Handle(Graphic3d_BoundBuffer)& aBounds = theArray->Bounds();
const Handle(Graphic3d_IndexBuffer)& anIndices = theArray->Indices();
#endif
|| anAttribs.IsNull())
{
- return NULL;
+ return Handle(OpenGl_TriangleSet)();
}
OpenGl_Mat4 aNormalMatrix;
-
if (theTransform != NULL)
{
Standard_ASSERT_RETURN (theTransform->Inverted (aNormalMatrix),
aNormalMatrix.Transpose();
}
- OpenGl_TriangleSet* aSet = new OpenGl_TriangleSet (theArray->GetUID());
+ Handle(OpenGl_TriangleSet) aSet = new OpenGl_TriangleSet (theArray->GetUID(), myRaytraceBVHBuilder);
{
aSet->Vertices.reserve (anAttribs->NbElements);
aSet->Normals.reserve (anAttribs->NbElements);
aSet->TexCrds.reserve (anAttribs->NbElements);
const size_t aVertFrom = aSet->Vertices.size();
-
for (Standard_Integer anAttribIter = 0; anAttribIter < anAttribs->NbAttributes; ++anAttribIter)
{
const Graphic3d_Attribute& anAttrib = anAttribs->Attribute (anAttribIter);
if (!addRaytraceVertexIndices (*aSet, theMaterial, aVertNum, aBoundStart, *theArray))
{
- delete aSet;
- return NULL;
+ aSet.Nullify();
+ return Handle(OpenGl_TriangleSet)();
}
aBoundStart += aVertNum;
if (!addRaytraceVertexIndices (*aSet, theMaterial, aVertNum, 0, *theArray))
{
- delete aSet;
- return NULL;
+ aSet.Nullify();
+ return Handle(OpenGl_TriangleSet)();
}
}
}
OpenGl_TriangleSet* aTriangleSet = dynamic_cast<OpenGl_TriangleSet*> (
myRaytraceGeometry.Objects().ChangeValue (anElemIndex).operator->());
- const BVH_Transform<Standard_ShortReal, 4>* aTransform =
- dynamic_cast<const BVH_Transform<Standard_ShortReal, 4>* > (aTriangleSet->Properties().operator->());
-
+ const BVH_Transform<Standard_ShortReal, 4>* aTransform = dynamic_cast<const BVH_Transform<Standard_ShortReal, 4>* > (aTriangleSet->Properties().get());
Standard_ASSERT_RETURN (aTransform != NULL,
"OpenGl_TriangleSet does not contain transform", Standard_False);
Select3D_BndBox3d.hxx
+Select3D_BVHBuilder3d.hxx
Select3D_BVHIndexBuffer.hxx
Select3D_EntitySequence.hxx
Select3D_InteriorSensitivePointSet.cxx
--- /dev/null
+// Copyright (c) 2017 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_BVHBuilder3d_Header
+#define _Select3D_BVHBuilder3d_Header
+
+#include <BVH_Builder.hxx>
+#include <Standard_Real.hxx>
+
+typedef BVH_Builder<Standard_Real, 3> Select3D_BVHBuilder3d;
+
+#endif // _Select3D_BVHBuilder3d_Header
IMPLEMENT_STANDARD_RTTIEXT(Select3D_SensitiveSet,Select3D_SensitiveEntity)
+namespace
+{
+ //! Default BVH tree builder for sensitive set (optimal for large set of small primitives - for not too long construction time).
+ static Handle(Select3D_BVHBuilder3d) THE_SENS_SET_BUILDER = new BVH_LinearBuilder<Standard_Real, 3> (BVH_Constants_LeafNodeSizeSmall, BVH_Constants_MaxTreeDepth);
+}
+
+//=======================================================================
+// function : DefaultBVHBuilder
+// purpose :
+//=======================================================================
+const Handle(Select3D_BVHBuilder3d)& Select3D_SensitiveSet::DefaultBVHBuilder()
+{
+ return THE_SENS_SET_BUILDER;
+}
+
+//=======================================================================
+// function : SetDefaultBVHBuilder
+// purpose :
+//=======================================================================
+void Select3D_SensitiveSet::SetDefaultBVHBuilder (const Handle(Select3D_BVHBuilder3d)& theBuilder)
+{
+ THE_SENS_SET_BUILDER = theBuilder;
+}
+
//=======================================================================
// function : Select3D_SensitiveSet
// purpose : Creates new empty sensitive set and its content
: Select3D_SensitiveEntity (theOwnerId),
myDetectedIdx (-1)
{
- NCollection_Handle< BVH_Builder<Standard_Real, 3> > aBuilder = new BVH_LinearBuilder<Standard_Real, 3> (myLeafNodeSize, 32);
myContent.SetSensitiveSet (this);
- myContent.SetBuilder (aBuilder);
+ myContent.SetBuilder (THE_SENS_SET_BUILDER);
myContent.MarkDirty();
}
return Standard_False;
}
- Standard_Integer aStack[32];
+ Standard_Integer aStack[BVH_Constants_MaxTreeDepth];
Standard_Integer aNode = 0;
Standard_Integer aHead = -1;
#ifndef _Select3D_SensitiveSet_Header
#define _Select3D_SensitiveSet_Header
-#include <BVH_PrimitiveSet.hxx>
-#include <Standard.hxx>
-#include <Standard_Type.hxx>
+#include <BVH_PrimitiveSet3d.hxx>
#include <Select3D_BndBox3d.hxx>
+#include <Select3D_BVHBuilder3d.hxx>
#include <Select3D_SensitiveEntity.hxx>
#include <SelectBasics_EntityOwner.hxx>
//! 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:
+
+ //! Return global instance to default BVH builder.
+ Standard_EXPORT static const Handle(Select3D_BVHBuilder3d)& DefaultBVHBuilder();
+
+ //! Assign new BVH builder to be used by default for new sensitive sets (assigning is NOT thread-safe!).
+ Standard_EXPORT static void SetDefaultBVHBuilder (const Handle(Select3D_BVHBuilder3d)& theBuilder);
+
public:
//! Creates new empty sensitive set and its content
Standard_EXPORT Select3D_SensitiveSet (const Handle(SelectBasics_EntityOwner)& theOwnerId);
- ~Select3D_SensitiveSet() {}
-
public:
//! Returns the amount of sub-entities of the complex entity
//! but element by element
Standard_EXPORT virtual void BVH() Standard_OVERRIDE;
+ //! Sets the method (builder) used to construct BVH.
+ void SetBuilder (const Handle(Select3D_BVHBuilder3d)& theBuilder) { myContent.SetBuilder (theBuilder); }
+
//! Marks BVH tree of the set as outdated. It will be rebuild
//! at the next call of BVH()
void MarkDirty() { myContent.MarkDirty(); }
Standard_EXPORT virtual void Clear() Standard_OVERRIDE;
//! Returns a number of nodes in 1 BVH leaf
- Standard_Integer GetLeafNodeSize() const { return myLeafNodeSize; }
+ Standard_Integer GetLeafNodeSize() const { return myContent.Builder()->LeafNodeSize(); }
protected:
//! 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>
+ class BvhPrimitiveSet : public BVH_PrimitiveSet3d
{
public:
//! Empty constructor.
- BvhPrimitiveSet() {}
+ BvhPrimitiveSet() : BVH_PrimitiveSet3d (Handle(Select3D_BVHBuilder3d)()) {}
//! Destructor.
~BvhPrimitiveSet() {}
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;
+ using BVH_PrimitiveSet3d::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 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(); }
+ const opencascade::handle<BVH_Tree<Standard_Real, 3> >& GetBVH() { return BVH(); }
protected:
Select3D_SensitiveSet* mySensitiveSet; //!< Set of sensitive entities
return myOwnerId;
}
-//=======================================================================
-// function : SetSensitivityFactor
-// purpose : Allows to manage sensitivity of a particular entity
-//=======================================================================
-void SelectBasics_SensitiveEntity::SetSensitivityFactor (const Standard_Integer theNewSens)
-{
- Standard_ASSERT_RAISE (theNewSens > 0,
- "Error! Selection sensitivity have positive value.");
-
- mySFactor = theNewSens;
-}
Standard_Integer SensitivityFactor() const;
//! Allows to manage sensitivity of a particular sensitive entity
- Standard_EXPORT void SetSensitivityFactor (const Standard_Integer theNewSens);
-
+ void SetSensitivityFactor (const Standard_Integer theNewSens)
+ {
+ Standard_ASSERT_RAISE (theNewSens > 0, "Error! Selection sensitivity have positive value.");
+ mySFactor = theNewSens;
+ }
+
//! Returns the number of sub-entities or elements in
//! sensitive entity. Is used to determine if entity is
//! complex and needs to pre-build BVH at the creation of
myBVH[BVHSubset_3dPersistent] = new BVH_Tree<Standard_Real, 3>();
myBVH[BVHSubset_3d] = new BVH_Tree<Standard_Real, 3>();
- myBuilder[BVHSubset_2dPersistent] = new BVH_LinearBuilder<Standard_Real, 3> (1, 32);
- myBuilder[BVHSubset_3dPersistent] = new BVH_LinearBuilder<Standard_Real, 3> (1, 32);
- myBuilder[BVHSubset_3d] = new BVH_BinnedBuilder<Standard_Real, 3, 4> (1, 32, Standard_True);
+ myBuilder[BVHSubset_2dPersistent] = new BVH_LinearBuilder<Standard_Real, 3> (BVH_Constants_LeafNodeSizeSingle, BVH_Constants_MaxTreeDepth);
+ myBuilder[BVHSubset_3dPersistent] = new BVH_LinearBuilder<Standard_Real, 3> (BVH_Constants_LeafNodeSizeSingle, BVH_Constants_MaxTreeDepth);
+ myBuilder[BVHSubset_3d] = new BVH_BinnedBuilder<Standard_Real, 3, 4> (BVH_Constants_LeafNodeSizeSingle, BVH_Constants_MaxTreeDepth, Standard_True);
myIsDirty[BVHSubset_2dPersistent] = Standard_False;
myIsDirty[BVHSubset_3dPersistent] = Standard_False;
BVHBuilderAdaptorRegular anAdaptor (myObjects[BVHSubset_3d]);
// update corresponding BVH tree data structure
- myBuilder[BVHSubset_3d]->Build (&anAdaptor, myBVH[BVHSubset_3d].operator->(), anAdaptor.Box());
+ myBuilder[BVHSubset_3d]->Build (&anAdaptor, myBVH[BVHSubset_3d].get(), anAdaptor.Box());
// release dirty state
myIsDirty[BVHSubset_3d] = Standard_False;
theCamera, theProjectionMat, theWorldViewMat, theViewportWidth, theViewportHeight);
// update corresponding BVH tree data structure
- myBuilder[BVHSubset_3dPersistent]->Build (&anAdaptor, myBVH[BVHSubset_3dPersistent].operator->(), anAdaptor.Box());
+ myBuilder[BVHSubset_3dPersistent]->Build (&anAdaptor, myBVH[BVHSubset_3dPersistent].get(), anAdaptor.Box());
}
// -----------------------------------------------------
theCamera, theProjectionMat, THE_IDENTITY_MAT, theViewportWidth, theViewportHeight);
// update corresponding BVH tree data structure
- myBuilder[BVHSubset_2dPersistent]->Build (&anAdaptor, myBVH[BVHSubset_2dPersistent].operator->(), anAdaptor.Box());
+ myBuilder[BVHSubset_2dPersistent]->Build (&anAdaptor, myBVH[BVHSubset_2dPersistent].get(), anAdaptor.Box());
}
// release dirty state for every subset
#ifndef _SelectMgr_SelectableObjectSet_HeaderFile
#define _SelectMgr_SelectableObjectSet_HeaderFile
-#include <BVH_PrimitiveSet.hxx>
+#include <BVH_Builder.hxx>
#include <BVH_Tree.hxx>
#include <Graphic3d_Mat4d.hxx>
#include <Graphic3d_WorldViewProjState.hxx>
#include <NCollection_Handle.hxx>
#include <NCollection_IndexedMap.hxx>
+#include <Select3D_BVHBuilder3d.hxx>
#include <SelectMgr_SelectableObject.hxx>
//! The purpose of this class is to organize all selectable objects into data structure, allowing to build
}
//! Returns computed BVH for the theSubset given.
- const NCollection_Handle<BVH_Tree<Standard_Real, 3> >& BVH(const BVHSubset theSubset) const
+ const opencascade::handle<BVH_Tree<Standard_Real, 3> >& BVH(const BVHSubset theSubset) const
{
return myBVH[theSubset];
}
private:
NCollection_IndexedMap<Handle(SelectMgr_SelectableObject)> myObjects[BVHSubsetNb]; //!< Map of objects for each subset
- NCollection_Handle<BVH_Tree<Standard_Real, 3> > myBVH[BVHSubsetNb]; //!< BVH tree computed for each subset
- NCollection_Handle<BVH_Builder<Standard_Real, 3> > myBuilder[BVHSubsetNb]; //!< Builder allocated for each subset
+ opencascade::handle<BVH_Tree<Standard_Real, 3> > myBVH[BVHSubsetNb]; //!< BVH tree computed for each subset
+ Handle(Select3D_BVHBuilder3d) myBuilder[BVHSubsetNb]; //!< Builder allocated for each subset
Standard_Boolean myIsDirty[BVHSubsetNb]; //!< Dirty flag for each subset
Graphic3d_WorldViewProjState myLastViewState; //!< Last view-projection state used for construction of BVH
Standard_Integer myLastWidth; //!< Last viewport's (window's) width used for construction of BVH
//==================================================
void SelectMgr_Selection::Destroy()
{
- for (Standard_Integer anEntityIdx = 0; anEntityIdx < myEntities.Size(); ++anEntityIdx)
+ for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator anEntityIter (myEntities); anEntityIter.More(); anEntityIter.Next())
{
- Handle(SelectMgr_SensitiveEntity)& anEntity = myEntities.ChangeValue (anEntityIdx);
+ Handle(SelectMgr_SensitiveEntity)& anEntity = anEntityIter.ChangeValue();
anEntity->BaseSensitive()->Set (NULL);
}
mySensFactor = 2;
//==================================================
void SelectMgr_Selection::Clear()
{
- for (Standard_Integer anIdx = 0; anIdx < myEntities.Size(); ++anIdx)
+ for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator anEntityIter (myEntities); anEntityIter.More(); anEntityIter.Next())
{
- Handle(SelectMgr_SensitiveEntity)& anEntity = myEntities.ChangeValue (anIdx);
+ Handle(SelectMgr_SensitiveEntity)& anEntity = anEntityIter.ChangeValue();
anEntity->Clear();
}
{
mySensFactor = theNewSens;
myIsCustomSens = Standard_True;
- for (Standard_Integer anIdx = 0; anIdx < myEntities.Size(); ++anIdx)
+ for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator anEntityIter (myEntities); anEntityIter.More(); anEntityIter.Next())
{
- Handle(SelectMgr_SensitiveEntity)& anEntity = myEntities.ChangeValue (anIdx);
+ Handle(SelectMgr_SensitiveEntity)& anEntity = anEntityIter.ChangeValue();
anEntity->BaseSensitive()->SetSensitivityFactor (theNewSens);
}
}
// theEntity
//=======================================================================
SelectMgr_SensitiveEntity::SelectMgr_SensitiveEntity (const Handle(SelectBasics_SensitiveEntity)& theEntity)
+: mySensitive (theEntity),
+ myIsActiveForSelection (Standard_False)
{
- mySensitive = theEntity;
- myIsActiveForSelection = Standard_False;
+ //
}
//=======================================================================
mySensitive->Clear();
mySensitive.Nullify();
}
-
-//=======================================================================
-// function : BaseSensitive
-// purpose : Returns related instance of SelectBasics class
-//=======================================================================
-const Handle(SelectBasics_SensitiveEntity)& SelectMgr_SensitiveEntity::BaseSensitive() const
-{
- return mySensitive;
-}
-
-//=======================================================================
-// function : IsActiveForSelection
-// purpose : Returns true if this entity belongs to the active selection
-// mode of parent object
-//=======================================================================
-Standard_Boolean SelectMgr_SensitiveEntity::IsActiveForSelection() const
-{
- return myIsActiveForSelection;
-}
-
-//=======================================================================
-// function : ResetSelectionActiveStatus
-// purpose : Marks entity as inactive for selection
-//=======================================================================
-void SelectMgr_SensitiveEntity::ResetSelectionActiveStatus() const
-{
- myIsActiveForSelection = Standard_False;
-}
-
-//=======================================================================
-// function : SetActiveForSelection
-// purpose : Marks entity as active for selection
-//=======================================================================
-void SelectMgr_SensitiveEntity::SetActiveForSelection() const
-{
- myIsActiveForSelection = Standard_True;
-}
Standard_EXPORT void Clear();
//! Returns related instance of SelectBasics class
- Standard_EXPORT const Handle(SelectBasics_SensitiveEntity)& BaseSensitive() const;
+ const Handle(SelectBasics_SensitiveEntity)& BaseSensitive() const { return mySensitive; }
//! Returns true if this entity belongs to the active selection
//! mode of parent object
- Standard_EXPORT Standard_Boolean IsActiveForSelection() const;
+ Standard_Boolean IsActiveForSelection() const { return myIsActiveForSelection; }
//! Marks entity as inactive for selection
- Standard_EXPORT void ResetSelectionActiveStatus() const;
+ void ResetSelectionActiveStatus() const { myIsActiveForSelection = Standard_False; }
//! Marks entity as active for selection
- Standard_EXPORT void SetActiveForSelection() const;
+ void SetActiveForSelection() const { myIsActiveForSelection = Standard_True; }
DEFINE_STANDARD_RTTIEXT(SelectMgr_SensitiveEntity,Standard_Transient) // Type definition
#include <SelectMgr_SensitiveEntitySet.hxx>
-#include <BVH_BinnedBuilder.hxx>
-
#include <Select3D_SensitiveEntity.hxx>
#include <SelectMgr_SensitiveEntity.hxx>
+IMPLEMENT_STANDARD_RTTIEXT(SelectMgr_SensitiveEntitySet, BVH_PrimitiveSet3d)
+
//=======================================================================
// function : SelectMgr_SensitiveEntitySet
// purpose :
//=======================================================================
-SelectMgr_SensitiveEntitySet::SelectMgr_SensitiveEntitySet()
+SelectMgr_SensitiveEntitySet::SelectMgr_SensitiveEntitySet (const Handle(Select3D_BVHBuilder3d)& theBuilder)
+: BVH_PrimitiveSet3d (theBuilder)
{
- myBuilder = new BVH_BinnedBuilder<Standard_Real, 3, 4> (1, 32, Standard_True);
+ //
}
//=======================================================================
//=======================================================================
void SelectMgr_SensitiveEntitySet::Append (const Handle(SelectMgr_SensitiveEntity)& theEntity)
{
- if (!theEntity->BaseSensitive()->IsKind ("Select3D_SensitiveEntity"))
+ if (!theEntity->BaseSensitive()->IsKind (STANDARD_TYPE(Select3D_SensitiveEntity)))
{
theEntity->ResetSelectionActiveStatus();
return;
{
for (theSelection->Init(); theSelection->More(); theSelection->Next())
{
- if (!theSelection->Sensitive()->BaseSensitive()->IsKind ("Select3D_SensitiveEntity"))
+ if (!theSelection->Sensitive()->BaseSensitive()->IsKind (STANDARD_TYPE(Select3D_SensitiveEntity)))
{
theSelection->Sensitive()->ResetSelectionActiveStatus();
continue;
#ifndef _SelectMgr_SensitiveEntitySet_HeaderFile
#define _SelectMgr_SensitiveEntitySet_HeaderFile
-#include <BVH_PrimitiveSet.hxx>
-
+#include <BVH_PrimitiveSet3d.hxx>
#include <NCollection_IndexedMap.hxx>
-#include <NCollection_Handle.hxx>
-
#include <Select3D_BndBox3d.hxx>
-
+#include <Select3D_BVHBuilder3d.hxx>
#include <SelectMgr_SensitiveEntity.hxx>
#include <SelectMgr_Selection.hxx>
//! This class is used to store all calculated sensitive entites of one selectable
//! object. It provides an interface for building BVH tree which is used to speed-up
//! the performance of searching for overlap among sensitives of one selectable object
-class SelectMgr_SensitiveEntitySet : public BVH_PrimitiveSet<Standard_Real, 3>
+class SelectMgr_SensitiveEntitySet : public BVH_PrimitiveSet3d
{
+ DEFINE_STANDARD_RTTIEXT(SelectMgr_SensitiveEntitySet, BVH_PrimitiveSet3d)
public:
- Standard_EXPORT SelectMgr_SensitiveEntitySet();
+ //! Empty constructor.
+ Standard_EXPORT SelectMgr_SensitiveEntitySet (const Handle(Select3D_BVHBuilder3d)& theBuilder);
virtual ~SelectMgr_SensitiveEntitySet() {};
Standard_EXPORT virtual Select3D_BndBox3d Box (const Standard_Integer theIndex) const Standard_OVERRIDE;
//! Make inherited method Box() visible to avoid CLang warning
- using BVH_PrimitiveSet<Standard_Real, 3>::Box;
+ using BVH_PrimitiveSet3d::Box;
//! Returns geometry center of sensitive entity index theIdx
//! along the given axis theAxis
#include <algorithm>
-IMPLEMENT_STANDARD_RTTIEXT(SelectMgr_ViewerSelector,MMgt_TShared)
+IMPLEMENT_STANDARD_RTTIEXT(SelectMgr_ViewerSelector, Standard_Transient)
namespace {
// Comparison operator for sorting selection results
myIsLeftChildQueuedFirst (Standard_False),
myEntityIdx (0)
{
+ myEntitySetBuilder = new BVH_BinnedBuilder<Standard_Real, 3, 4> (BVH_Constants_LeafNodeSizeSingle, BVH_Constants_MaxTreeDepth, Standard_True);
}
//==================================================
const Standard_Integer theViewportWidth,
const Standard_Integer theViewportHeight)
{
- NCollection_Handle<SelectMgr_SensitiveEntitySet>& anEntitySet =
- myMapOfObjectSensitives.ChangeFind (theObject);
-
+ Handle(SelectMgr_SensitiveEntitySet)& anEntitySet = myMapOfObjectSensitives.ChangeFind (theObject);
if (anEntitySet->Size() == 0)
+ {
return;
+ }
- const NCollection_Handle<BVH_Tree<Standard_Real, 3> >& aSensitivesTree = anEntitySet->BVH();
-
+ const opencascade::handle<BVH_Tree<Standard_Real, 3> >& aSensitivesTree = anEntitySet->BVH();
gp_GTrsf aInversedTrsf;
-
if (theObject->HasTransformation() || !theObject->TransformPersistence().IsNull())
{
if (theObject->TransformPersistence().IsNull())
{
return;
}
- Standard_Integer aStack[32];
+ Standard_Integer aStack[BVH_Constants_MaxTreeDepth];
Standard_Integer aHead = -1;
for (;;)
{
? mySelectingVolumeMgr.WorldViewMatrix()
: THE_IDENTITY_MAT;
- const NCollection_Handle<BVH_Tree<Standard_Real, 3> >& aBVHTree = mySelectableObjects.BVH (aBVHSubset);
+ const opencascade::handle<BVH_Tree<Standard_Real, 3> >& aBVHTree = mySelectableObjects.BVH (aBVHSubset);
Standard_Integer aNode = 0;
if (!aMgr.Overlaps (aBVHTree->MinPoint (0), aBVHTree->MaxPoint (0)))
continue;
}
- Standard_Integer aStack[32];
+ Standard_Integer aStack[BVH_Constants_MaxTreeDepth];
Standard_Integer aHead = -1;
for (;;)
{
//
//==================================================
+//==================================================
+// Function: SetEntitySetBuilder
+// Purpose :
+//==================================================
+void SelectMgr_ViewerSelector::SetEntitySetBuilder (const Handle(Select3D_BVHBuilder3d)& theBuilder)
+{
+ myEntitySetBuilder = theBuilder;
+ for (SelectMgr_MapOfObjectSensitives::Iterator aSetIter (myMapOfObjectSensitives); aSetIter.More(); aSetIter.Next())
+ {
+ aSetIter.ChangeValue()->SetBuilder (myEntitySetBuilder);
+ }
+}
+
//==================================================
// Function: Contains
// Purpose :
if(myIndexes.IsNull() || anExtent != myIndexes->Length())
myIndexes = new TColStd_HArray1OfInteger (1, anExtent);
- // to work faster...
- TColStd_Array1OfInteger& thearr = myIndexes->ChangeArray1();
-
- // indices from 1 to N are loaded
- Standard_Integer I ;
- for (I=1; I <= anExtent; I++)
- thearr(I)=I;
-
- std::sort (thearr.begin(), thearr.end(), CompareResults (mystored));
-
+ TColStd_Array1OfInteger& anIndexArray = myIndexes->ChangeArray1();
+ for (Standard_Integer anIndexIter = 1; anIndexIter <= anExtent; ++anIndexIter)
+ {
+ anIndexArray.SetValue (anIndexIter, anIndexIter);
+ }
+ std::sort (anIndexArray.begin(), anIndexArray.end(), CompareResults (mystored));
}
//=======================================================================
if (!myMapOfObjectSensitives.IsBound (theObject))
{
mySelectableObjects.Append (theObject);
- NCollection_Handle<SelectMgr_SensitiveEntitySet> anEntitySet = new SelectMgr_SensitiveEntitySet();
+ Handle(SelectMgr_SensitiveEntitySet) anEntitySet = new SelectMgr_SensitiveEntitySet (myEntitySetBuilder);
myMapOfObjectSensitives.Bind (theObject, anEntitySet);
}
}
void SelectMgr_ViewerSelector::AddSelectionToObject (const Handle(SelectMgr_SelectableObject)& theObject,
const Handle(SelectMgr_Selection)& theSelection)
{
- if (myMapOfObjectSensitives.IsBound (theObject))
+ if (Handle(SelectMgr_SensitiveEntitySet)* anEntitySet = myMapOfObjectSensitives.ChangeSeek (theObject))
{
- NCollection_Handle<SelectMgr_SensitiveEntitySet>& anEntitySet =
- myMapOfObjectSensitives.ChangeFind (theObject);
- anEntitySet->Append (theSelection);
- anEntitySet->BVH();
+ (*anEntitySet)->Append (theSelection);
+ (*anEntitySet)->BVH();
}
else
{
//=======================================================================
void SelectMgr_ViewerSelector::RemoveSelectableObject (const Handle(SelectMgr_SelectableObject)& theObject)
{
- if (myMapOfObjectSensitives.IsBound (theObject))
+ Handle(SelectMgr_SelectableObject) anObj = theObject;
+ if (myMapOfObjectSensitives.UnBind (theObject))
{
mySelectableObjects.Remove (theObject);
- myMapOfObjectSensitives.UnBind (theObject);
}
}
void SelectMgr_ViewerSelector::RemoveSelectionOfObject (const Handle(SelectMgr_SelectableObject)& theObject,
const Handle(SelectMgr_Selection)& theSelection)
{
- if (myMapOfObjectSensitives.IsBound (theObject))
+ if (Handle(SelectMgr_SensitiveEntitySet)* anEntitySet = myMapOfObjectSensitives.ChangeSeek (theObject))
{
- NCollection_Handle<SelectMgr_SensitiveEntitySet>& anEntitySet =
- myMapOfObjectSensitives.ChangeFind (theObject);
- anEntitySet->Remove (theSelection);
+ (*anEntitySet)->Remove (theSelection);
}
}
if (!Contains (theObject))
return;
- NCollection_Handle<SelectMgr_SensitiveEntitySet>& anEntitySet = myMapOfObjectSensitives.ChangeFind (theObject);
+ Handle(SelectMgr_SensitiveEntitySet)& anEntitySet = myMapOfObjectSensitives.ChangeFind (theObject);
anEntitySet->MarkDirty();
if (theIsForce)
//=======================================================================
void SelectMgr_ViewerSelector::ResetSelectionActivationStatus()
{
- SelectMgr_MapOfObjectSensitivesIterator aSensitivesIter (myMapOfObjectSensitives);
- for ( ; aSensitivesIter.More(); aSensitivesIter.Next())
+ for (SelectMgr_MapOfObjectSensitivesIterator aSensitivesIter (myMapOfObjectSensitives); aSensitivesIter.More(); aSensitivesIter.Next())
{
- NCollection_Handle<SelectMgr_SensitiveEntitySet>& anEntitySet =
- aSensitivesIter.ChangeValue();
- Standard_Integer anEntitiesNb = anEntitySet->Size();
+ Handle(SelectMgr_SensitiveEntitySet)& anEntitySet = aSensitivesIter.ChangeValue();
+ const Standard_Integer anEntitiesNb = anEntitySet->Size();
for (Standard_Integer anIdx = 0; anIdx < anEntitiesNb; ++anIdx)
{
anEntitySet->GetSensitiveById (anIdx)->ResetSelectionActiveStatus();
{
for (SelectMgr_MapOfObjectSensitivesIterator anIter (myMapOfObjectSensitives); anIter.More(); anIter.Next())
{
- const NCollection_Handle<SelectMgr_SensitiveEntitySet>& anEntitySet = anIter.Value();
- Standard_Integer anEntitiesNb = anEntitySet->Size();
+ const Handle(SelectMgr_SensitiveEntitySet)& anEntitySet = anIter.Value();
+ const Standard_Integer anEntitiesNb = anEntitySet->Size();
for (Standard_Integer anIdx = 0; anIdx < anEntitiesNb; ++anIdx)
{
- if (anEntitySet->GetSensitiveById (anIdx)->IsActiveForSelection())
+ const Handle(SelectMgr_SensitiveEntity)& aSensitive = anEntitySet->GetSensitiveById (anIdx);
+ if (aSensitive->IsActiveForSelection())
{
- theOwners.Append (anEntitySet->GetSensitiveById (anIdx)->BaseSensitive()->OwnerId());
+ theOwners.Append (aSensitive->BaseSensitive()->OwnerId());
}
}
}
#ifndef _SelectMgr_ViewerSelector_HeaderFile
#define _SelectMgr_ViewerSelector_HeaderFile
-#include <MMgt_TShared.hxx>
-#include <NCollection_Handle.hxx>
+#include <Standard_Transient.hxx>
#include <NCollection_DataMap.hxx>
#include <OSD_Chronometer.hxx>
#include <TColStd_SequenceOfInteger.hxx>
#include <TColStd_HArray1OfInteger.hxx>
+#include <Select3D_BVHBuilder3d.hxx>
#include <SelectMgr_IndexedDataMapOfOwnerCriterion.hxx>
#include <SelectMgr_SelectingVolumeManager.hxx>
#include <SelectMgr_Selection.hxx>
class SelectMgr_EntityOwner;
class SelectBasics_SensitiveEntity;
-typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), NCollection_Handle<SelectMgr_SensitiveEntitySet> > SelectMgr_MapOfObjectSensitives;
-typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), NCollection_Handle<SelectMgr_SensitiveEntitySet> >::Iterator SelectMgr_MapOfObjectSensitivesIterator;
+typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_SensitiveEntitySet) > SelectMgr_MapOfObjectSensitives;
+typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_SensitiveEntitySet) >::Iterator SelectMgr_MapOfObjectSensitivesIterator;
typedef NCollection_DataMap<Standard_Integer, SelectMgr_SelectingVolumeManager> SelectMgr_FrustumCache;
Standard_EXPORT Standard_Boolean Contains (const Handle(SelectMgr_SelectableObject)& theObject) const;
+ //! Returns the default builder used to construct BVH of entity set.
+ const Handle(Select3D_BVHBuilder3d) EntitySetBuilder() { return myEntitySetBuilder; }
+
+ //! Sets the default builder used to construct BVH of entity set.
+ //! The new builder will be also assigned for already defined objects, but computed BVH trees will not be invalidated.
+ Standard_EXPORT void SetEntitySetBuilder (const Handle(Select3D_BVHBuilder3d)& theBuilder);
+
//! Returns the list of selection modes ModeList found in
//! this selector for the selectable object aSelectableObject.
//! Returns true if aSelectableObject is referenced inside
mutable SelectMgr_SelectableObjectSet mySelectableObjects;
SelectMgr_ToleranceMap myTolerances;
NCollection_DataMap<Graphic3d_ZLayerId, Standard_Integer> myZLayerOrderMap;
+ Handle(Select3D_BVHBuilder3d) myEntitySetBuilder;
private:
};
-DEFINE_STANDARD_HANDLE(SelectMgr_ViewerSelector, MMgt_TShared)
+DEFINE_STANDARD_HANDLE(SelectMgr_ViewerSelector, Standard_Transient)
#endif
aSensitive->BVH();
}
- if (aSensitive->IsInstance ("Select3D_SensitiveGroup"))
+ if (!aSensitive->IsInstance (STANDARD_TYPE(Select3D_SensitiveGroup)))
{
- Handle(Select3D_SensitiveGroup) aGroup (Handle(Select3D_SensitiveGroup)::DownCast (aSensitive));
- const Select3D_EntitySequence& aSubEntities = aGroup->GetEntities();
- for (Select3D_EntitySequenceIter aSubEntitiesIter (aSubEntities); aSubEntitiesIter.More(); aSubEntitiesIter.Next())
+ continue;
+ }
+
+ Handle(Select3D_SensitiveGroup) aGroup = Handle(Select3D_SensitiveGroup)::DownCast (aSensitive);
+ const Select3D_EntitySequence& aSubEntities = aGroup->GetEntities();
+ for (Select3D_EntitySequenceIter aSubEntitiesIter (aSubEntities); aSubEntitiesIter.More(); aSubEntitiesIter.Next())
+ {
+ const Handle(Select3D_SensitiveEntity)& aSubEntity = aSubEntitiesIter.Value();
+ if (aSubEntity->NbSubElements() >= BVH_PRIMITIVE_LIMIT)
{
- const Handle(Select3D_SensitiveEntity)& aSubEntity = aSubEntitiesIter.Value();
- if (aSubEntity->NbSubElements() >= BVH_PRIMITIVE_LIMIT)
- {
- aSubEntity->BVH();
- }
+ aSubEntity->BVH();
}
}
}