|
Blender
V2.59
|
00001 /* 00002 * $Id: rayobject_rtbuild.h 35233 2011-02-27 19:31:27Z jesterking $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * The Original Code is Copyright (C) 2009 Blender Foundation. 00021 * All rights reserved. 00022 * 00023 * The Original Code is: all of this file. 00024 * 00025 * Contributor(s): André Pinto. 00026 * 00027 * ***** END GPL LICENSE BLOCK ***** 00028 */ 00029 00034 #ifndef RE_RAYOBJECT_RTBUILD_H 00035 #define RE_RAYOBJECT_RTBUILD_H 00036 00037 #ifdef __cplusplus 00038 extern "C" { 00039 #endif 00040 00041 #include "rayobject.h" 00042 00043 00044 /* 00045 * Ray Tree Builder 00046 * this structs helps building any type of tree 00047 * it contains several methods to organiza/split nodes 00048 * allowing to create a given tree on the fly. 00049 * 00050 * Idea is that other trees BVH, BIH can use this code to 00051 * generate with simple calls, and then convert to the theirs 00052 * specific structure on the fly. 00053 */ 00054 #define RTBUILD_MAX_CHILDS 32 00055 00056 00057 typedef struct RTBuilder 00058 { 00059 struct Object 00060 { 00061 RayObject *obj; 00062 float cost; 00063 float bb[6]; 00064 int selected; 00065 }; 00066 00067 /* list to all primitives added in this tree */ 00068 struct 00069 { 00070 Object *begin, *end; 00071 int maxsize; 00072 } primitives; 00073 00074 /* sorted list of rayobjects */ 00075 struct Object **sorted_begin[3], **sorted_end[3]; 00076 00077 /* axis used (if any) on the split method */ 00078 int split_axis; 00079 00080 /* child partitions calculated during splitting */ 00081 int child_offset[RTBUILD_MAX_CHILDS+1]; 00082 00083 // int child_sorted_axis; /* -1 if not sorted */ 00084 00085 float bb[6]; 00086 00087 } RTBuilder; 00088 00089 /* used during creation */ 00090 RTBuilder* rtbuild_create(int size); 00091 void rtbuild_free(RTBuilder *b); 00092 void rtbuild_add(RTBuilder *b, RayObject *o); 00093 void rtbuild_done(RTBuilder *b, RayObjectControl *c); 00094 void rtbuild_merge_bb(RTBuilder *b, float *min, float *max); 00095 int rtbuild_size(RTBuilder *b); 00096 00097 RayObject* rtbuild_get_primitive(RTBuilder *b, int offset); 00098 00099 /* used during tree reorganization */ 00100 RTBuilder* rtbuild_get_child(RTBuilder *b, int child, RTBuilder *tmp); 00101 00102 /* Calculates child partitions and returns number of efectively needed partitions */ 00103 int rtbuild_get_largest_axis(RTBuilder *b); 00104 00105 //Object partition 00106 int rtbuild_mean_split(RTBuilder *b, int nchilds, int axis); 00107 int rtbuild_mean_split_largest_axis(RTBuilder *b, int nchilds); 00108 00109 int rtbuild_heuristic_object_split(RTBuilder *b, int nchilds); 00110 00111 //Space partition 00112 int rtbuild_median_split(RTBuilder *b, float *separators, int nchilds, int axis); 00113 int rtbuild_median_split_largest_axis(RTBuilder *b, int nchilds); 00114 00115 00116 /* bb utils */ 00117 float bb_area(float *min, float *max); 00118 float bb_volume(float *min, float *max); 00119 int bb_largest_axis(float *min, float *max); 00120 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 */ 00121 00122 #ifdef __cplusplus 00123 } 00124 #endif 00125 00126 #endif