2011-02-23 10:52:22 +00:00
/*
2009-06-30 22:07:42 +00:00
* * * * * * BEGIN GPL LICENSE BLOCK * * * * *
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
* of the License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software Foundation ,
2010-02-12 13:34:04 +00:00
* Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
2009-06-30 22:07:42 +00:00
*
* The Original Code is Copyright ( C ) 2009 Blender Foundation .
* All rights reserved .
*
* The Original Code is : all of this file .
*
* Contributor ( s ) : André Pinto .
*
* * * * * * END GPL LICENSE BLOCK * * * * *
*/
2011-02-27 19:31:27 +00:00
/** \file blender/render/intern/raytrace/rayobject_rtbuild.h
* \ ingroup render
*/
2012-02-17 18:59:41 +00:00
# ifndef __RAYOBJECT_RTBUILD_H__
# define __RAYOBJECT_RTBUILD_H__
2009-06-30 22:07:42 +00:00
2009-07-12 18:04:10 +00:00
# ifdef __cplusplus
extern " C " {
# endif
2009-06-30 22:07:42 +00:00
# include "rayobject.h"
2009-07-12 18:04:10 +00:00
2009-06-30 22:07:42 +00:00
/*
* Ray Tree Builder
* this structs helps building any type of tree
* it contains several methods to organiza / split nodes
* allowing to create a given tree on the fly .
*
* Idea is that other trees BVH , BIH can use this code to
* generate with simple calls , and then convert to the theirs
* specific structure on the fly .
*/
2009-07-02 15:45:15 +00:00
# define RTBUILD_MAX_CHILDS 32
2009-08-03 17:56:38 +00:00
2009-06-30 22:07:42 +00:00
typedef struct RTBuilder
{
2009-08-03 17:56:38 +00:00
struct Object
{
RayObject * obj ;
float cost ;
float bb [ 6 ] ;
int selected ;
} ;
/* list to all primitives added in this tree */
struct
{
Object * begin , * end ;
int maxsize ;
} primitives ;
2009-06-30 22:07:42 +00:00
2009-08-03 17:56:38 +00:00
/* sorted list of rayobjects */
struct Object * * sorted_begin [ 3 ] , * * sorted_end [ 3 ] ;
2009-06-30 22:07:42 +00:00
/* axis used (if any) on the split method */
int split_axis ;
2009-07-01 11:27:43 +00:00
/* child partitions calculated during splitting */
2009-07-02 15:45:15 +00:00
int child_offset [ RTBUILD_MAX_CHILDS + 1 ] ;
2009-07-07 19:07:53 +00:00
2009-08-03 17:56:38 +00:00
// int child_sorted_axis; /* -1 if not sorted */
2009-07-10 16:42:51 +00:00
float bb [ 6 ] ;
2009-06-30 22:07:42 +00:00
} RTBuilder ;
/* used during creation */
RTBuilder * rtbuild_create ( int size ) ;
void rtbuild_free ( RTBuilder * b ) ;
void rtbuild_add ( RTBuilder * b , RayObject * o ) ;
2009-10-04 16:56:00 +00:00
void rtbuild_done ( RTBuilder * b , RayObjectControl * c ) ;
2009-07-10 16:42:51 +00:00
void rtbuild_merge_bb ( RTBuilder * b , float * min , float * max ) ;
2009-06-30 22:07:42 +00:00
int rtbuild_size ( RTBuilder * b ) ;
2009-08-03 17:56:38 +00:00
RayObject * rtbuild_get_primitive ( RTBuilder * b , int offset ) ;
2009-06-30 22:07:42 +00:00
/* used during tree reorganization */
RTBuilder * rtbuild_get_child ( RTBuilder * b , int child , RTBuilder * tmp ) ;
2009-07-01 11:27:43 +00:00
/* Calculates child partitions and returns number of efectively needed partitions */
2009-07-06 19:45:00 +00:00
int rtbuild_get_largest_axis ( RTBuilder * b ) ;
2009-07-07 15:42:08 +00:00
//Object partition
2009-07-01 11:27:43 +00:00
int rtbuild_mean_split ( RTBuilder * b , int nchilds , int axis ) ;
int rtbuild_mean_split_largest_axis ( RTBuilder * b , int nchilds ) ;
2009-07-06 19:45:00 +00:00
2009-07-07 15:42:08 +00:00
int rtbuild_heuristic_object_split ( RTBuilder * b , int nchilds ) ;
//Space partition
2009-07-06 19:45:00 +00:00
int rtbuild_median_split ( RTBuilder * b , float * separators , int nchilds , int axis ) ;
int rtbuild_median_split_largest_axis ( RTBuilder * b , int nchilds ) ;
2009-06-30 22:07:42 +00:00
2009-07-07 15:42:08 +00:00
2009-07-08 20:04:40 +00:00
/* bb utils */
float bb_area ( float * min , float * max ) ;
2009-07-10 16:42:51 +00:00
float bb_volume ( float * min , float * max ) ;
int bb_largest_axis ( float * min , float * max ) ;
2009-07-14 23:08:55 +00:00
int bb_fits_inside ( float * outer_min , float * outer_max , float * inner_min , float * inner_max ) ; /* only returns 0 if merging inner and outerbox would create a box larger than outer box */
2009-07-08 20:04:40 +00:00
2009-07-12 18:04:10 +00:00
# ifdef __cplusplus
}
# endif
2009-06-30 22:07:42 +00:00
# endif