Visualization Library 2.0.0-b3

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
ActorKdTree.hpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2017, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
32 #ifndef ActorKdTree_INCLUDE_ONCE
33 #define ActorKdTree_INCLUDE_ONCE
34 
35 #include <vlCore/AABB.hpp>
36 #include <vlGraphics/Actor.hpp>
37 #include <vlCore/math_utils.hpp>
38 #include <vlCore/Plane.hpp>
39 #include <vlCore/Collection.hpp>
41 
42 namespace vl
43 {
58  {
60 
61  public:
63  {
64  VL_DEBUG_SET_OBJECT_NAME()
65  }
66  virtual int childrenCount() const;
67  virtual ActorTreeAbstract* child(int i);
68  virtual const ActorTreeAbstract* child(int i) const;
69 
77  void buildKdTree(ActorCollection& actors, int max_depth=100, float minimum_volume=0);
78 
81  void rebuildKdTree(int max_depth=100, float minimum_volume=0);
82 
84  const Plane& plane() const { return mPlane; }
85 
87  ActorKdTree* childN() { return mChildN.get(); }
89  const ActorKdTree* childN() const { return mChildN.get(); }
90 
92  ActorKdTree* childP() { return mChildP.get(); }
94  const ActorKdTree* childP() const { return mChildP.get(); }
95 
109  ActorKdTree* insertActor(Actor* actor);
110 
114  ref<ActorKdTree> kdtreeFromNonLeafyActors(int max_depth=100, float minimum_volume=0);
115 
119  void harvestNonLeafActors(ActorCollection& actors);
120 
121  private:
122  void setChildN(ActorKdTree* child)
123  {
124  VL_CHECK(child);
125  if (mChildN)
126  mChildN->mParent = NULL;
127  child->mParent = this;
128  mChildN=child;
129  }
130  void setChildP(ActorKdTree* child)
131  {
132  VL_CHECK(child);
133  if (mChildP)
134  mChildP->mParent = NULL;
135  child->mParent = this;
136  mChildP=child;
137  }
139  int scorePlane(const Plane& plane, const ActorCollection& actors);
142  bool findBestPlane(Plane& plane, int& counter, ActorCollection& actors);
144  void compileTree_internal(ActorCollection& acts, int& counter, int max_depth=100, float minimum_volume=0);
146  void computeLocalAABB(const ActorCollection& actors);
147 
148  protected:
152  };
153 
154 }
155 
156 #endif
Associates a Renderable object to an Effect and Transform.
Definition: Actor.hpp:130
ref< ActorKdTree > mChildP
ActorKdTree * childP()
Returns the child node that lies in the positive space defined by the splitting plane.
Definition: ActorKdTree.hpp:92
const ActorKdTree * childP() const
Returns the child node that lies in the positive space defined by the splitting plane.
Definition: ActorKdTree.hpp:94
const Plane & plane() const
Returns the splitting plane used to divide its two child nodes.
Definition: ActorKdTree.hpp:84
ActorTreeAbstract * mParent
The Plane class defines a plane using a normal and an origin.
Definition: Plane.hpp:49
#define VL_INSTRUMENT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:122
Visualization Library main namespace.
ActorKdTree * childN()
Returns the child node that lies in the negative space defined by the splitting plane.
Definition: ActorKdTree.hpp:87
const ActorKdTree * childN() const
Returns the child node that lies in the negative space defined by the splitting plane.
Definition: ActorKdTree.hpp:89
The ActorTreeAbstract class implements the interface of a generic tree containing Actors in its nodes...
#define NULL
Definition: OpenGLDefs.hpp:81
ActorKdTree class extends the ActorTreeAbstract class implementing a space partitioning scheme based ...
Definition: ActorKdTree.hpp:57
Defined as a simple subclass of Collection<Actor>, see Collection for more information.
Definition: Actor.hpp:479
#define VL_CHECK(expr)
Definition: checks.hpp:73
ref< ActorKdTree > mChildN