Welcome to mirror list, hosted at ThFree Co, Russian Federation.

rayobject_rtbuild.h « raytrace « intern « render « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 83042ef3d7ed43b76c06c5c17948d29a4fecc83c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
 * ***** 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,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * 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 *****
 */

/** \file blender/render/intern/raytrace/rayobject_rtbuild.h
 *  \ingroup render
 */

#ifndef __RAYOBJECT_RTBUILD_H__
#define __RAYOBJECT_RTBUILD_H__

#ifdef __cplusplus
extern "C" {
#endif

#include "rayobject.h"


/*
 * 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.
 */
#define RTBUILD_MAX_CHILDS     32
#define RTBUILD_MAX_SAH_DEPTH  256


typedef struct RTBuilder {
	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;
	
	/* sorted list of rayobjects */
	struct Object **sorted_begin[3], **sorted_end[3];

	/* axis used (if any) on the split method */
	int split_axis;
	
	/* child partitions calculated during splitting */
	int child_offset[RTBUILD_MAX_CHILDS + 1];
	
//	int child_sorted_axis; /* -1 if not sorted */
	
	float bb[6];

	/* current depth */
	int depth;
} RTBuilder;

/* used during creation */
RTBuilder *rtbuild_create(int size);
void rtbuild_free(RTBuilder *b);
void rtbuild_add(RTBuilder *b, RayObject *o);
void rtbuild_done(RTBuilder *b, RayObjectControl *c);
void rtbuild_merge_bb(RTBuilder *b, float min[3], float max[3]);
int rtbuild_size(RTBuilder *b);

RayObject *rtbuild_get_primitive(RTBuilder *b, int offset);

/* used during tree reorganization */
RTBuilder *rtbuild_get_child(RTBuilder *b, int child, RTBuilder *tmp);

/* Calculates child partitions and returns number of efectively needed partitions */
int rtbuild_get_largest_axis(RTBuilder *b);

//Object partition
int rtbuild_mean_split(RTBuilder *b, int nchilds, int axis);
int rtbuild_mean_split_largest_axis(RTBuilder *b, int nchilds);

int rtbuild_heuristic_object_split(RTBuilder *b, int nchilds);

//Space partition
int rtbuild_median_split(RTBuilder *b, float *separators, int nchilds, int axis);
int rtbuild_median_split_largest_axis(RTBuilder *b, int nchilds);


/* bb utils */
float bb_area(const float min[3], const float max[3]);
float bb_volume(const float min[3], const float max[3]);
int bb_largest_axis(const float min[3], const float max[3]);
int bb_fits_inside(const float  outer_min[3], const float  outer_max[3],
                   const float  inner_min[3], const float  inner_max[3]);

#ifdef __cplusplus
}
#endif

#endif  /* __RAYOBJECT_RTBUILD_H__ */