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