help required wiht BSP tree

D1189cc75544eea31979c55b45fa72ef
0
broli86 101 Apr 01, 2008 at 09:37

I’ve decided to use BSP tree for my object which has been converted
into triangular mesh. The subdivision plane that i use builds the BSP
tree by subdividing along the center of x, y, or z bounds But the
biggest problem I’m facing right now is how to deal with situations
where a triangle is spanning across the plane ?? In this case part of
traingle is in one bounding volume and the other part is in the
sibling bounding volume. How to deal with this ??

Also, what happens is that when you have calculated geometry
preprocessing data structures like half edge data structure, then you
have to constantly change things which makes it even more complicated.
For eg. when a plane interesects a triangle, then it is split into two
polygons, you have to subdivide these polygons into n-2 triangles and
then change the half edge structure again and again. If someone can provide a link to a good BSP tree code it will be even more helpful

11 Replies

Please log in or register to post a reply.

B7568a7d781a2ebebe3fa176215ae667
0
Wernaeh 101 Apr 01, 2008 at 10:56

Hey there :)

Why exactly do you want to use a BSP tree ? These are quite oldfashioned these days…

Also, to me it sounds like you are building some kind of AB-Octree mixture if you are talking about dividing through the center of some boundary volume. With BSP trees, you use the planes your polygons are located on as subdivision hyperplanes.

For the spanning problem, this again depends on how you want to use your BSP tree:

If you intend to use the convex interior half-spaces formed by a true (see above!) bsp on a closed, polygonal surface, you need to split your triangles with the plane. Here, it becomes helpful if you use a data structure which allows for multi-point, convex polygons (i.e. quads, and so on). However, the splitting you described is the only solution there. With regards to additional data structures, depending on performance, it might be a good idea to issue a total rebuild after bsp tree generation.

However, if you are just using the bsp tree as a means to get a hierarchial representation of your polygon soup, you may very well get around splitting: Instead of splitting, just create two entries for the spanning element, one on each side of the node. This for instance works well with collision detection.

Hope this helps,

Cheers,
- Wernaeh

D1189cc75544eea31979c55b45fa72ef
0
broli86 101 Apr 01, 2008 at 11:46

Thank you very much for your help buddy.

@Wernaeh

Hey there :) Why exactly do you want to use a BSP tree ? These are quite oldfashioned these days…

I’m sorry I’m really a begginer in this area so my knowledge is really limited.
But can you please tell which data structure is the most recommended these days ? I was initially having a bounding sphere for the entire object but to me it seems you can’t have spatial subdivision with a sphere. Although, with sphere, determining intersection is too simple.
@Wernaeh

Also, to me it sounds like you are building some kind of AB-Octree mixture if you are talking about dividing through the center of some boundary volume. With BSP trees, you use the planes your polygons are located on as subdivision hyperplanes.

Yes you are right here. But what I’m talking about is a axis aligned BSP tree(as opposed to polygon aligned BSP tree which you were talking about) which is (as you rightly said) similar to octree. But unlike octree, I’m not going to have 8 children per node. There will be only 2. First I will divide the node along x axis, then the children along y axis, then grandchildren along z axis. Its cyclical.

http://tog.acm.org/GraphicsGems/gemsiii/bsp.c

\^\^ Something like this (look into subdivide function)
@Wernaeh

For the spanning problem, this again depends on how you want to use your BSP tree:

If you intend to use the convex interior half-spaces formed by a true (see above!) bsp on a closed, polygonal surface, you need to split your triangles with the plane. Here, it becomes helpful if you use a data structure which allows for multi-point, convex polygons (i.e. quads, and so on). However, the splitting you described is the only solution there. With regards to additional data structures, depending on performance, it might be a good idea to issue a total rebuild after bsp tree generation.

However, if you are just using the bsp tree as a means to get a hierarchial representation of your polygon soup, you may very well get around splitting: Instead of splitting, just create two entries for the spanning element, one on each side of the node. This for instance works well with collision detection.

Hope this helps,

Cheers,
- Wernaeh

I didn’t really get your point over here but what I want to do is accelerate my ray tracing software so that instead of checking all the triangles, I need to check only a few. I want to create a binary tree of bounding boxes like this and then traverse it to quickly determine the intersection (or collision detection as you put it).

When splitting a bounding box into left child and right child, it is easy to classify traingles which are totally on one side as they satisfy the following condition -

min.x > = vertex.x < = max.x
min.y > = vertex.y < = max.y
min. z > = vertex.z <= max.z

i = 0…3

These type of triangles can be straight away put into the appropriate buffer. But the problem, like i said, is for traingles which span the plane. When a triangle is cut by a plane, it is divided into two polygons.

Fd80f81596aa1cf809ceb1c2077e190b
0
rouncer 104 Apr 01, 2008 at 12:02

For spacial division I just use octrees or grids, they are the only 2 i learnt.
bsp’s confused me because they dont seem to split the world into even
groups.(do you find that an issue?)

Grids are just 3d arrays, and they waste tonnes of ram but they have the
quickest insert and delete of any spacial division technique.

Any form of tree based apon a heirarchy takes longer to build.

A grid will waste any other form of spacial division if your doing a proximity
weld of verts (welding them together due to their 3d proximity.)

I think this splitting of a triangle when it crosses over the boundary is only
for some specific algorythm - usually you just use id’s of your entities and you
just repeat the id’s across the boundaries, thats the only thing that makes
sense to me.

D1189cc75544eea31979c55b45fa72ef
0
broli86 101 Apr 01, 2008 at 12:24

@rouncer

For spacial division I just use octrees or grids, they are the only 2 i learnt.
bsp’s confused me because they dont seem to split the world into even
groups.(do you find that an issue?)

Do you know of any source codes for octree or grid ??

I think if you have implemented the octree, then you must have surely come across this same problem about traingle spanning across the plane ??
@rouncer

Grids are just 3d arrays, and they waste tonnes of ram but they have the
quickest insert and delete of any spacial division technique.

Any form of tree based apon a heirarchy takes longer to build.

A grid will waste any other form of spacial division if your doing a proximity
weld of verts (welding them together due to their 3d proximity.)

I think this splitting of a triangle when it crosses over the boundary is only
for some specific algorythm - usually you just use id’s of your entities and you
just repeat the id’s across the boundaries, thats the only thing that makes
sense to me.

Yes the id’s can be repeated across the boundaries, that’s one idea. I wonder about the efficiency in this approach though.

46407cc1bdfbd2db4f6e8876d74f990a
0
Kenneth_Gorking 101 Apr 01, 2008 at 12:31

@broli86

Yes you are right here. But what I’m talking about is a axis aligned BSP tree(as opposed to polygon aligned BSP tree which you were talking about) which is (as you rightly said) similar to octree. But unlike octree, I’m not going to have 8 children per node. There will be only 2. First I will divide the node along x axis, then the children along y axis, then grandchildren along z axis. Its cyclical.

What you are refering to is called a kd-tree. This ray-tracing tutorial has more details on how to use it.

Fd80f81596aa1cf809ceb1c2077e190b
0
rouncer 104 Apr 01, 2008 at 12:40

Theres no efficiency problem with repeating id’s, the object that gathers the
symbols could gather same symbol twice i guess, but its no biggy - it keeps
things simple.

if a triangle is right on the edge of a octree division - itll either go into one
side or the other, so I guess you should put it in both to be careful.

Spacial division is no big deal, you do it however you feel like its not that
difficult.

D1189cc75544eea31979c55b45fa72ef
0
broli86 101 Apr 01, 2008 at 12:44

@Kenneth Gorking

What you are refering to is called a kd-tree. This ray-tracing tutorial has more details on how to use it.

But in k-d tree the splitting plane is not passing through the mid points of x, y or z bounds. instead, geometric average of all centroids is taken and then the splitting plane is assumed to pass through it.

D1189cc75544eea31979c55b45fa72ef
0
broli86 101 Apr 01, 2008 at 12:57

@rouncer

Theres no efficiency problem with repeating id’s, the object that gathers the
symbols could gather same symbol twice i guess, but its no biggy - it keeps
things simple.

if a triangle is right on the edge of a octree division - itll either go into one
side or the other, so I guess you should put it in both to be careful.

Spacial division is no big deal, you do it however you feel like its not that
difficult.

Ok, can you also please tell me how you implemented octree ? In octree you are simulatenously cutting thorugh center of box with 3 planes coplanar to XY, YZ and ZX planes. How did you store the bounds for each of the 8 children ??

I tried octree with following data structure -

struct octree
{

struct octree *child[8];
vector minB, maxB;
Triangle *list;

};

typedef octree octree;

octree *root;

………….
………….

Now suppose we have a root bounding box, now how to subdivide this into 8 children ??

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Apr 01, 2008 at 15:52

@broli86

But in k-d tree the splitting plane is not passing through the mid points of x, y or z bounds. instead, geometric average of all centroids is taken and then the splitting plane is assumed to pass through it.

It’s still a kd-tree. You can determine the location of the splitting plane in any of a number of different ways, whether the midpoint, centroid, surface-area heuristic (SAH), etc…

In octree you are simulatenously cutting thorugh center of box with 3 planes coplanar to XY, YZ and ZX planes. How did you store the bounds for each of the 8 children ??

Typically you have a bounding box for each node (which at the root of the octree covers the whole scene) then it’s just split at the midpoint in each axis to form 8 smaller boxes. But you could use other schemes for finding the splitting plane positions too, if you wanted.

D1189cc75544eea31979c55b45fa72ef
0
broli86 101 Apr 01, 2008 at 16:21

@Reedbeta

Typically you have a bounding box for each node (which at the root of the octree covers the whole scene) then it’s just split at the midpoint in each axis to form 8 smaller boxes. But you could use other schemes for finding the splitting plane positions too, if you wanted.

Hello, one method I just though of is as follows..please critique

find the AABB for the object i.e. minB and maxB vectors.

Then determine the length(max.x-min.x), breadth(max.y - min.y) and height ( max.z - min.z). After this,

L = length/2, B = breadth/2, H = height/2

Then, since we know values of all the 8 corners, use these to find the corners for each of the cells..
For eg at corner (xmin, ymin, zmin) -

(xmin , ymin, zmin)
(xmin + L, ymin, zmin)
(xmin + L, ymin + B, zmin)
(xmin + L, ymin, zmin)

Then for the four corners above, simply add height to zmin in each of the above. It is easy to determine the minB and maxB vectors through this with simple comparisons. This gives one cell. Similarly traverse to 7 other corners and determine 7 cells.
To determine which triangles are inside a particular cell use simple test like

min.x > = vertex.x < = max.x
min.y > = vertex.y < = max.y
min. z > = vertex.z <= max.z

i = 0…3

For triangles which are coplanar with splitting plane, their id’s will be automatically repeated in other cell and the ones that are spanning across the plane must also be dealt with in the same way.

Make the routine a recursive one …

octree(BBox, length, width, height, number_of_triangles_in_list, tri *list)
{

if(length && width && heigth <= some tolerance value || number_of_triangles_in_list <= some tolerance value)
Make the 8 children of the box as NULL
return;
……..
……..

octree(BBox, length/2, width/2, height/2, number_of_triangles_in_list, list);

}

For traversal, start with the root node and check which of the 8 cells the ray is hitting. Find that cell and further traverse until you reach a leaf node for which children are all NULL.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Apr 01, 2008 at 16:48

Yes, that is the classic octree algorithm.