75 newtree->
buildKdTree(acts, max_depth, minimum_volume);
97 for(
int i=0; i<(int)acts.
size(); ++i)
100 mAABB += acts[i]->boundingBox();
108 compileTree_internal(acts, counter, max_depth, minimum_volume);
118 void ActorKdTree::compileTree_internal(
ActorCollection& acts,
int& counter,
int max_depth,
float minimum_volume)
126 if (acts.
size() == 0)
129 computeLocalAABB(acts);
131 if (acts.
size() == 1 || max_depth == 0 ||
mAABB.
volume() < minimum_volume)
137 if ( !findBestPlane(
mPlane, counter, acts) )
148 for(
int i=0; i<(int)acts.
size(); ++i)
154 case -1: actorsN. push_back(acts[i].
get());
break;
155 case +1: actorsP. push_back(acts[i].
get());
break;
159 int counter1 = counter;
160 int counter2 = counter;
164 childN()->compileTree_internal(actorsN, counter1, max_depth-1, minimum_volume);
170 childP()->compileTree_internal(actorsP, counter2, max_depth-1, minimum_volume);
177 int cN=0, cC=0, cP=0;
178 for(
int i=0; i<(int)acts.
size(); ++i)
181 switch( plane.
classify(acts[i]->boundingBox()) )
183 case -1: cN++;
break;
185 case +1: cP++;
break;
188 return cC +
::abs(cN-cP);
194 int median = (int)acts.
size() / 2;
197 std::sort(acts.
vector().begin(), acts.
vector().end(), sortX);
199 plane =
Plane(acts[median]->boundingBox().minCorner().x(),
vec3(1,0,0));
201 if (scorePlane(plane, acts) == (
int)acts.
size())
203 std::sort(acts.
vector().begin(), acts.
vector().end(), sortY);
205 plane =
Plane(acts[median]->boundingBox().minCorner().y(),
vec3(0,1,0));
207 if (scorePlane(plane, acts) == (
int)acts.
size())
209 std::sort(acts.
vector().begin(), acts.
vector().end(), sortZ);
211 plane =
Plane(acts[median]->boundingBox().minCorner().z(),
vec3(0,0,1));
213 if (scorePlane(plane, acts) == (
int)acts.
size())
221 std::sort(acts.
vector().begin(), acts.
vector().end(), sortY);
223 plane =
Plane(acts[median]->boundingBox().minCorner().y(),
vec3(0,1,0));
225 if (scorePlane(plane, acts) == (
int)acts.
size())
227 std::sort(acts.
vector().begin(), acts.
vector().end(), sortZ);
229 plane =
Plane(acts[median]->boundingBox().minCorner().z(),
vec3(0,0,1));
231 if (scorePlane(plane, acts) == (
int)acts.
size())
233 std::sort(acts.
vector().begin(), acts.
vector().end(), sortX);
235 plane =
Plane(acts[median]->boundingBox().minCorner().x(),
vec3(1,0,0));
237 if (scorePlane(plane, acts) == (
int)acts.
size())
245 std::sort(acts.
vector().begin(), acts.
vector().end(), sortZ);
247 plane =
Plane(acts[median]->boundingBox().minCorner().z(),
vec3(0,0,1));
249 if (scorePlane(plane, acts) == (
int)acts.
size())
251 std::sort(acts.
vector().begin(), acts.
vector().end(), sortX);
253 plane =
Plane(acts[median]->boundingBox().minCorner().x(),
vec3(1,0,0));
255 if (scorePlane(plane, acts) == (
int)acts.
size())
257 std::sort(acts.
vector().begin(), acts.
vector().end(), sortY);
259 plane =
Plane(acts[median]->boundingBox().minCorner().y(),
vec3(0,1,0));
261 if (scorePlane(plane, acts) == (
int)acts.
size())
306 vl::Log::error(
"ActorKdTree::child(int): bad child node requested, a ActorKdTree can have only 2 child nodes.\n" );
320 vl::Log::error(
"ActorKdTree::child(int): bad child node requested, a ActorKdTree can have only 2 child nodes.\n" );
Associates a Renderable object to an Effect and Transform.
const Renderable * lod(int lod_index) const
Returns the Renderable object representing the LOD level specifed by lod_index.
ref< ActorKdTree > mChildP
void rebuildKdTree(int max_depth=100, float minimum_volume=0)
Builds a ActorKdTree with the Actors contained in the tree.
ActorKdTree * childP()
Returns the child node that lies in the positive space defined by the splitting plane.
const Plane & plane() const
Returns the splitting plane used to divide its two child nodes.
The Plane class defines a plane using a normal and an origin.
virtual int childrenCount() const
Returns the number of child nodes of an ActorTreeAbstract node.
const T_Scalar & z() const
ActorKdTree * insertActor(Actor *actor)
Inserts an Actor in the ActorKdTree node hierarchy.
static void error(const String &message)
Use this function to provide information about run-time errors: file not found, out of memory...
void setNull()
Sets ths AABB as null, that is, empty.
static void prepareActors(ActorCollection &actors)
Updates the Transform and the bounds of the given Actors.
Visualization Library main namespace.
int classify(const AABB &) const
returns 0 if the AABB intersects the plane, 1 if it's in the positive side, -1 if it's in the negativ...
virtual ActorTreeAbstract * child(int i)
Returns the i-th child node of an ActorTreeAbstract node.
const ActorCollection * actors() const
Returns the actors contained in a ActorTree node.
const std::vector< ref< T > > & vector() const
ActorKdTree * childN()
Returns the child node that lies in the negative space defined by the splitting plane.
void harvestNonLeafActors(ActorCollection &actors)
Removes the Actors in the internal nodes of the ActorKdTree and appends them in the given ActorCollec...
void reserve(int capacity)
The ActorTreeAbstract class implements the interface of a generic tree containing Actors in its nodes...
void buildKdTree(ActorCollection &actors, int max_depth=100, float minimum_volume=0)
Builds a ActorKdTree with the given list of Actors.
const T_Scalar & y() const
const AABB & boundingBox() const
Returns the bounding box (not guaranteed to be up to date) that contains this Actor.
const vec3 & minCorner() const
Returns the corner of the AABB with the minimum x y z coordinates.
ActorKdTree class extends the ActorTreeAbstract class implementing a space partitioning scheme based ...
Defined as a simple subclass of Collection<Actor>, see Collection for more information.
fvec3 vec3
Defined as: 'typedef fvec3 vec3'. See also VL_PIPELINE_PRECISION.
const T_Scalar & x() const
real volume() const
Returns the volume of the AABB.
ref< ActorKdTree > kdtreeFromNonLeafyActors(int max_depth=100, float minimum_volume=0)
Removes the Actors in the internal nodes of the ActorKdTree and uses them to create a new ActorKdTree...
void extractActors(ActorCollection &list)
Extracts all the Actors contained in th ActorTree hierarchy and appends them to the given ActorCollec...
ref< ActorKdTree > mChildN