Revision: 21536
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21536
Author:   jaguarandi
Date:     2009-07-12 00:13:01 +0200 (Sun, 12 Jul 2009)

Log Message:
-----------
Added module bf_render_raytrace (source/blender/render/intern/raytrace)
to be able to use C++ at raytrace code
        C++ used in here is basicly C with templates and function overloads,
        to make it easier to reuse code between structures.

For now BVH was converted in C++ and moved to this module

Modified Paths:
--------------
    branches/soc-2009-jaguarandi/source/blender/render/SConscript

Added Paths:
-----------
    branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/
    branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/bvh.h
    
branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_bvh.cpp

Removed Paths:
-------------
    
branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_bvh.c

Modified: branches/soc-2009-jaguarandi/source/blender/render/SConscript
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/SConscript       
2009-07-11 19:45:46 UTC (rev 21535)
+++ branches/soc-2009-jaguarandi/source/blender/render/SConscript       
2009-07-11 22:13:01 UTC (rev 21536)
@@ -3,6 +3,7 @@
 
 cflags=''
 sources = env.Glob('intern/source/*.c')
+raysources = env.Glob('intern/raytrace/*.cpp')
 
 incs = 'intern/include #/intern/guardedalloc ../blenlib ../makesdna'
 incs += ' extern/include ../blenkernel ../radiosity/extern/include ../imbuf'
@@ -24,3 +25,4 @@
     cflags='-pthread'
 
 env.BlenderLib ( libname = 'bf_render', sources = sources, includes = 
Split(incs), defines=defs, libtype='core', priority=145, compileflags=cflags )
+env.BlenderLib ( libname = 'bf_render_raytrace', sources = raysources, 
includes = Split(incs), defines=defs, libtype='core', priority=145, 
compileflags=cflags )

Added: branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/bvh.h
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/bvh.h    
                        (rev 0)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/bvh.h    
2009-07-11 22:13:01 UTC (rev 21536)
@@ -0,0 +1,288 @@
+
+/* bvh tree generics */
+template<class Tree> static int bvh_intersect(Tree *obj, Isect *isec);
+
+template<class Tree> static void bvh_add(Tree *obj, RayObject *ob)
+{
+       rtbuild_add( obj->builder, ob );
+}
+
+template<class Tree> static void bvh_done(Tree *obj);
+
+template<class Tree>
+static void bvh_free(Tree *obj)
+{
+       if(obj->builder)
+               rtbuild_free(obj->builder);
+
+       if(obj->node_arena)
+               BLI_memarena_free(obj->node_arena);
+
+       MEM_freeN(obj);
+}
+
+template<class Tree>
+static void bvh_bb(Tree *obj, float *min, float *max)
+{
+       bvh_node_merge_bb(obj->root, min, max);
+}
+
+
+template<class Tree>
+static float bvh_cost(Tree *obj)
+{
+       assert(obj->cost >= 0.0);
+       return obj->cost;
+}
+
+
+
+/* bvh tree nodes generics */
+template<class Node> static inline int bvh_node_hit_test(Node *node, Isect 
*isec)
+{
+       return RE_rayobject_bb_intersect(isec, (const float*)node->bb) != 
FLT_MAX;
+}
+
+
+template<class Node>
+static void bvh_node_merge_bb(Node *node, float *min, float *max)
+{
+       if(RayObject_isAligned(node))
+       {
+               DO_MIN(node->bb  , min);
+               DO_MAX(node->bb+3, max);
+       }
+       else
+       {
+               RE_rayobject_merge_bb( (RayObject*)node, min, max);
+       }
+}
+
+
+
+/*
+ * recursivly transverse a BVH looking for a rayhit using a local stack
+ */
+template<class Node> static inline void bvh_node_push_childs(Node *node, Isect 
*isec, Node **stack, int &stack_pos);
+
+template<class Node,int MAX_STACK_SIZE>
+static int bvh_node_stack_raycast(Node *root, Isect *isec)
+{
+       Node *stack[MAX_STACK_SIZE];
+       int hit = 0, stack_pos = 0;
+               
+       stack[stack_pos++] = root;
+       while(stack_pos)
+       {
+               Node *node = stack[--stack_pos];
+               if(RayObject_isAligned(node))
+               {
+                       if(bvh_node_hit_test(node,isec))
+                       {
+                               bvh_node_push_childs(node, isec, stack, 
stack_pos);
+                               assert(stack_pos <= MAX_STACK_SIZE);
+                       }
+               }
+               else
+               {
+                       hit |= RE_rayobject_intersect( (RayObject*)node, isec);
+                       if(hit && isec->mode == RE_RAY_SHADOW) return hit;
+               }
+       }
+       return hit;
+
+}
+
+/*
+ * recursively transverse a BVH looking for a rayhit using system stack
+ */
+/*
+template<class Node>
+static int bvh_node_raycast(Node *node, Isect *isec)
+{
+       int hit = 0;
+       if(bvh_test_node(node, isec))
+       {
+               if(isec->idot_axis[node->split_axis] > 0.0f)
+               {
+                       int i;
+                       for(i=0; i<BVH_NCHILDS; i++)
+                               if(RayObject_isAligned(node->child[i]))
+                               {
+                                       if(node->child[i] == 0) break;
+                                       
+                                       hit |= bvh_node_raycast(node->child[i], 
isec);
+                                       if(hit && isec->mode == RE_RAY_SHADOW) 
return hit;
+                               }
+                               else
+                               {
+                                       hit |= RE_rayobject_intersect( 
(RayObject*)node->child[i], isec);
+                                       if(hit && isec->mode == RE_RAY_SHADOW) 
return hit;
+                               }
+               }
+               else
+               {
+                       int i;
+                       for(i=BVH_NCHILDS-1; i>=0; i--)
+                               if(RayObject_isAligned(node->child[i]))
+                               {
+                                       if(node->child[i])
+                                       {
+                                               hit |= 
dfs_raycast(node->child[i], isec);
+                                               if(hit && isec->mode == 
RE_RAY_SHADOW) return hit;
+                                       }
+                               }
+                               else
+                               {
+                                       hit |= RE_rayobject_intersect( 
(RayObject*)node->child[i], isec);
+                                       if(hit && isec->mode == RE_RAY_SHADOW) 
return hit;
+                               }
+               }
+       }
+       return hit;
+}
+*/
+
+/* bvh tree generics */
+template<class Tree> static int bvh_intersect(Tree *obj, Isect *isec);
+
+template<class Tree> static void bvh_add(Tree *obj, RayObject *ob)
+{
+       rtbuild_add( obj->builder, ob );
+}
+
+template<class Tree> static void bvh_done(Tree *obj);
+
+template<class Tree>
+static void bvh_free(Tree *obj)
+{
+       if(obj->builder)
+               rtbuild_free(obj->builder);
+
+       if(obj->node_arena)
+               BLI_memarena_free(obj->node_arena);
+
+       MEM_freeN(obj);
+}
+
+template<class Tree>
+static void bvh_bb(Tree *obj, float *min, float *max)
+{
+       bvh_node_merge_bb(obj->root, min, max);
+}
+
+
+template<class Tree>
+static float bvh_cost(Tree *obj)
+{
+       assert(obj->cost >= 0.0);
+       return obj->cost;
+}
+
+
+
+/* bvh tree nodes generics */
+template<class Node> static inline int bvh_node_hit_test(Node *node, Isect 
*isec)
+{
+       return RE_rayobject_bb_intersect(isec, (const float*)node->bb) != 
FLT_MAX;
+}
+
+
+template<class Node>
+static void bvh_node_merge_bb(Node *node, float *min, float *max)
+{
+       if(RayObject_isAligned(node))
+       {
+               DO_MIN(node->bb  , min);
+               DO_MAX(node->bb+3, max);
+       }
+       else
+       {
+               RE_rayobject_merge_bb( (RayObject*)node, min, max);
+       }
+}
+
+
+
+/*
+ * recursivly transverse a BVH looking for a rayhit using a local stack
+ */
+template<class Node> static inline void bvh_node_push_childs(Node *node, Isect 
*isec, Node **stack, int &stack_pos);
+
+template<class Node,int MAX_STACK_SIZE>
+static int bvh_node_stack_raycast(Node *root, Isect *isec)
+{
+       Node *stack[MAX_STACK_SIZE];
+       int hit = 0, stack_pos = 0;
+               
+       stack[stack_pos++] = root;
+       while(stack_pos)
+       {
+               Node *node = stack[--stack_pos];
+               if(RayObject_isAligned(node))
+               {
+                       if(bvh_node_hit_test(node,isec))
+                       {
+                               bvh_node_push_childs(node, isec, stack, 
stack_pos);
+                               assert(stack_pos <= MAX_STACK_SIZE);
+                       }
+               }
+               else
+               {
+                       hit |= RE_rayobject_intersect( (RayObject*)node, isec);
+                       if(hit && isec->mode == RE_RAY_SHADOW) return hit;
+               }
+       }
+       return hit;
+
+}
+
+/*
+ * recursively transverse a BVH looking for a rayhit using system stack
+ */
+/*
+template<class Node>
+static int bvh_node_raycast(Node *node, Isect *isec)
+{
+       int hit = 0;
+       if(bvh_test_node(node, isec))
+       {
+               if(isec->idot_axis[node->split_axis] > 0.0f)
+               {
+                       int i;
+                       for(i=0; i<BVH_NCHILDS; i++)
+                               if(RayObject_isAligned(node->child[i]))
+                               {
+                                       if(node->child[i] == 0) break;
+                                       
+                                       hit |= bvh_node_raycast(node->child[i], 
isec);
+                                       if(hit && isec->mode == RE_RAY_SHADOW) 
return hit;
+                               }
+                               else
+                               {
+                                       hit |= RE_rayobject_intersect( 
(RayObject*)node->child[i], isec);
+                                       if(hit && isec->mode == RE_RAY_SHADOW) 
return hit;
+                               }
+               }
+               else
+               {
+                       int i;
+                       for(i=BVH_NCHILDS-1; i>=0; i--)
+                               if(RayObject_isAligned(node->child[i]))
+                               {
+                                       if(node->child[i])
+                                       {
+                                               hit |= 
dfs_raycast(node->child[i], isec);
+                                               if(hit && isec->mode == 
RE_RAY_SHADOW) return hit;
+                                       }
+                               }
+                               else
+                               {
+                                       hit |= RE_rayobject_intersect( 
(RayObject*)node->child[i], isec);
+                                       if(hit && isec->mode == RE_RAY_SHADOW) 
return hit;
+                               }
+               }
+       }
+       return hit;
+}
+*/


Property changes on: 
branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/bvh.h
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: 
branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_bvh.cpp
===================================================================
--- 
branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_bvh.cpp
                                (rev 0)
+++ 
branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_bvh.cpp
        2009-07-11 22:13:01 UTC (rev 21536)
@@ -0,0 +1,470 @@
+/**
+ * $Id$
+ *
+ * ***** 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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 *****
+ */
+extern "C"
+{
+#include <assert.h>
+#include "MEM_guardedalloc.h"
+#include "BKE_utildefines.h"
+#include "BLI_arithb.h"
+#include "BLI_memarena.h"
+#include "RE_raytrace.h"
+#include "rayobject_rtbuild.h"
+#include "rayobject.h"
+};
+
+#include "bvh.h"
+
+#define BVH_NCHILDS 2
+#define RAY_BB_TEST_COST (0.2f)
+#define DFS_STACK_SIZE 64
+#define DYNAMIC_ALLOC
+
+//#define rtbuild_split        rtbuild_mean_split_largest_axis         /* 
objects mean split on the longest axis, childs BB are allowed to overlap */
+//#define rtbuild_split        rtbuild_median_split_largest_axis       /* 
space median split on the longest axis, childs BB are allowed to overlap */
+#define rtbuild_split  rtbuild_heuristic_object_split          /* split 
objects using heuristic */
+
+struct BVHNode
+{
+       BVHNode *child[BVH_NCHILDS];
+       float   bb[6];
+       int split_axis;
+};
+
+struct BVHTree
+{
+       RayObject rayobj;
+
+       BVHNode *root;
+
+       MemArena *node_arena;
+
+       float cost;
+       RTBuilder *builder;
+};
+
+
+/*
+ * Push nodes (used on dfs)
+ */
+template<class Node>
+inline static void bvh_node_push_childs(Node *node, Isect *isec, Node **stack, 
int &stack_pos)
+{
+       //push nodes in reverse visit order
+       if(isec->idot_axis[node->split_axis] < 0.0f)
+       {
+               int i;
+               for(i=0; i<BVH_NCHILDS; i++)
+                       if(node->child[i] == 0)
+                               break;
+                       else
+                               stack[stack_pos++] = node->child[i];
+       }
+       else
+       {
+               int i;  

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to