[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20365] branches/soc-2009-yukishiro/source /blender: clean up compute.c.

Jingyuan Huang jingyuan.huang at gmail.com
Sat May 23 21:47:48 CEST 2009


Revision: 20365
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20365
Author:   yukishiro
Date:     2009-05-23 21:47:47 +0200 (Sat, 23 May 2009)

Log Message:
-----------
clean up compute.c. fix some comments in other files.

Modified Paths:
--------------
    branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c
    branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_light.c
    branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c

Modified: branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c	2009-05-23 19:36:11 UTC (rev 20364)
+++ branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c	2009-05-23 19:47:47 UTC (rev 20365)
@@ -1,7 +1,6 @@
-/*  lightenv.c
- *
+/*  
  * 
- * $Id: material.c 18559 2009-01-18 10:41:45Z aligorith $
+ * $Id: lightenv.c 18559 2009-01-18 10:41:45Z yukishiro $
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
@@ -49,6 +48,7 @@
 
 LightEnv deflightenv;
 
+// TODO: simple function to return value for 3 channels. needs improvement
 void def_synthetic(float theta, float phi, float *val)
 {
         if (theta < M_PI / 3) {

Modified: branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_light.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_light.c	2009-05-23 19:36:11 UTC (rev 20364)
+++ branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_light.c	2009-05-23 19:47:47 UTC (rev 20365)
@@ -1,9 +1,6 @@
 /**
- * $Id: paint_image.c 19820 2009-04-20 15:06:46Z blendix $
- * imagepaint.c
+ * $Id: paint_light.c 19820 2009-04-20 15:06:46Z blendix $
  *
- * Functions to paint images in 2D and 3D.
- * 
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -37,29 +34,15 @@
 
 #include "MEM_guardedalloc.h"
 
-#ifdef WIN32
-#include "BLI_winstuff.h"
-#endif
-#include "BLI_arithb.h"
-#include "BLI_blenlib.h"
-#include "BLI_dynstr.h"
-#include "BLI_linklist.h"
-#include "BLI_memarena.h"
 #include "PIL_time.h"
 #include "BLI_threads.h"
 
-#include "IMB_imbuf.h"
-#include "IMB_imbuf_types.h"
-
 #include "DNA_brush_types.h"
 #include "DNA_lightenv_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
-#include "DNA_node_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
-#include "DNA_screen_types.h"
-#include "DNA_space_types.h"
 #include "DNA_view3d_types.h"
 #include "DNA_windowmanager_types.h"
 #include "DNA_world_types.h"
@@ -67,14 +50,9 @@
 #include "BKE_context.h"
 #include "BKE_brush.h"
 #include "BKE_global.h"
-#include "BKE_image.h"
 #include "BKE_main.h"
 #include "BKE_mesh.h"
-#include "BKE_node.h"
-#include "BKE_utildefines.h"
 #include "BKE_DerivedMesh.h"
-#include "BKE_report.h"
-#include "BKE_depsgraph.h"
 
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
@@ -82,7 +60,6 @@
 #include "UI_interface.h"
 #include "UI_view2d.h"
 
-#include "ED_image.h"
 #include "ED_object.h"
 #include "ED_screen.h"
 #include "ED_view3d.h"
@@ -125,6 +102,7 @@
 
 static void toggle_paint_cursor(bContext *C, int enable)
 {
+        // TODO
 	//ToolSettings *settings= CTX_data_scene(C)->toolsettings;
 
 	//if(settings->imapaint.paintcursor && !enable) {
@@ -135,6 +113,7 @@
 	//	settings->imapaint.paintcursor= WM_paint_cursor_activate(CTX_wm_manager(C), image_paint_poll, brush_drawcursor, NULL);
 }
 
+
 // TODO: problem with using a job for the scene is that info header would display a render button....
 static void initial_computation(bContext *C)
 {
@@ -159,8 +138,8 @@
 	WM_jobs_timer(job, 0.2, NC_SCENE|ND_SH_RESULT, 0);
 	WM_jobs_callbacks(job, sh_startjob, NULL, NULL);
 
+        /* start job */
 	WM_jobs_start(job);
-
 	WM_cursor_wait(0);
 }
 

Modified: branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c	2009-05-23 19:36:11 UTC (rev 20364)
+++ branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c	2009-05-23 19:47:47 UTC (rev 20365)
@@ -33,11 +33,6 @@
 
 #include "MEM_guardedalloc.h"
 
-#include "BLI_arithb.h"
-#include "BLI_blenlib.h"
-#include "BLI_dynstr.h"
-#include "BLI_linklist.h"
-#include "BLI_memarena.h"
 #include "PIL_time.h"
 #include "BLI_threads.h"
 
@@ -47,30 +42,32 @@
 #include "DNA_node_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
-#include "DNA_screen_types.h"
-#include "DNA_space_types.h"
-#include "DNA_userdef_types.h"
-#include "DNA_view3d_types.h"
-#include "DNA_windowmanager_types.h"
 
 #include "BKE_lightenv.h"
 #include "BKE_mesh.h"
 #include "BKE_customdata.h"
 
 #define v3_new_vec(a, b, c, u) { u[0] = a; u[1] = b; u[2] = c; }
+#define L 4
 #define NUM_SAMPLES 100
 #define SQRT_SAMPLES 10
 
 typedef float Vec3[3];
 typedef float** ShCoeffs;
 
-// TODO: clean up static variables when exiting
+
+/* aan and bbn are values to help computation*/
 static ShCoeffs aan;
 static ShCoeffs bbn;
+
+/* random ray samples in (x, y, z) and (phi, theta, r) coordinates */
 static Vec3 *samples;
 static Vec3 *sample_angles;
+
+/* SH value for ray samples */
 static ShCoeffs *samples_Y;
 
+
 static void free_ShCoeffs(ShCoeffs sh_coeffs)
 {
         if (sh_coeffs == NULL) return;
@@ -80,70 +77,77 @@
 
 static ShCoeffs allocate_ShCoeffs()
 {
-        float **a;
-        float  *x;
+        float **coeffs;
+        float  *vals;
         int l;
 
-        a = MEM_mallocN(5 * sizeof(float*), "SH coeffs");
-        if (a==NULL) return NULL;
+        coeffs = MEM_mallocN ((L+1) * sizeof(float*), "SH coeffs");
+        if (coeffs==NULL) return NULL;
         
-        x = MEM_mallocN(5 * 5 * sizeof(float), "SH coeffs data");
-        if (x==NULL) {
-                free(a);
+        vals = MEM_mallocN ((L+1) * (L+1) * sizeof(float), "SH coeffs data");
+        if (vals==NULL) {
+                free(vals);
                 return NULL;
         }
         
-        /* OK, got all the memory we need, now initialise pointers... */
-        for (l=0; l<=4; l++) a[l] = &(x[l*l+l]);
-        return a;
+        // realign pointers so that we can index negative values 
+        for (l=0; l<=L; l++) 
+                coeffs[l] = &(vals[l*l+l]);
+
+        return coeffs;
 }
 
-static void free_ShCoeffs_array(ShCoeffs * a)
+static void free_ShCoeffs_array(ShCoeffs * coeffs_array)
 {
-        if (a == NULL) return;
-        MEM_freeN(**a);
-        MEM_freeN(*a);
-        MEM_freeN(a);
+        if (coeffs_array == NULL) return;
+
+        MEM_freeN(**coeffs_array);
+        MEM_freeN(*coeffs_array);
+        MEM_freeN(coeffs_array);
 }
 
-static ShCoeffs* allocate_ShCoeffs_array(int n)
+static ShCoeffs* allocate_ShCoeffs_array(int array_size)
 {
-        ShCoeffs *a;
-        float **b;
-        float *x;
-        int j, l;
+        ShCoeffs *coeffs_array;
+        float **coeffs;
+        float *vals;
+        int i, l;
 
-        a = MEM_mallocN(n * sizeof(ShCoeffs), "SH coeffs array");
-        b = MEM_mallocN(n * 5 * sizeof(float*), "SH coeffs");
-        x = MEM_mallocN(n * 5 * 5 * sizeof(float), "SH coeffs data");
+        coeffs_array = MEM_mallocN (array_size * sizeof(ShCoeffs), "SH coeffs array");
+        coeffs = MEM_mallocN (array_size * (L+1) * sizeof(float*), "SH coeffs");
+        vals = MEM_mallocN (array_size * (L+1) * (L+1) * sizeof(float), "SH coeffs data");
 
-        if (a == NULL || b == NULL || x == NULL) {
-                MEM_freeN(a);
-                MEM_freeN(b);
-                MEM_freeN(x);
+        if (coeffs_array == NULL || coeffs == NULL || vals == NULL) {
+                MEM_freeN(coeffs_array);
+                MEM_freeN(coeffs);
+                MEM_freeN(vals);
                 return NULL;
         }
 
-        for (j=0; j<n; j++) {
-                a[j] = &(b[j*5]);
-                for (l=0; l<=4; l++) a[j][l] = &(x[j*5*5 + l*l+l]);
+        // realign pointers so that we can index negative values 
+        for (i = 0; i < array_size; i++) {
+                coeffs_array[i] = &(coeffs[i*(L+1)]);
+                for (l = 0; l <= L; l++) 
+                        coeffs_array[i][l] = &(vals[i*(L+1)*(L+1) + l*l+l]);
         }
-        return a;
+
+        return coeffs_array;
 }
 
+/* compute SH values for a vector in (x, y, z) */
 static void compute_Y(Vec3 u, ShCoeffs *Y)
 {
         int l, m;
         
         (*Y)[0][0] = aan[0][0];
         
-        // work out the degree 1 case immediately...
+        // work out the degree 1 case immediately
         (*Y)[1][0]  = aan[1][0] * u[2];
         (*Y)[1][-1] = aan[1][1] * u[1];
         (*Y)[1][1]  = aan[1][1] * u[0];
         
-        // And then do DEGREES 2..L via the recurrences...
-        for (l = 2; l <= 4; l++) {
+        // And then do DEGREES 2..L via the recurrences
+        for (l = 2; l <= L; l++) {
                 (*Y)[l][l]    = aan[l][l] * (u[0] * (*Y)[l-1][l-1] - u[1] * (*Y)[l-1][-l+1]);
                 (*Y)[l][-l]   = aan[l][l] * (u[1] * (*Y)[l-1][l-1] + u[0] * (*Y)[l-1][-l+1]);
                 (*Y)[l][l-1]  = aan[l][l-1] * u[2] * (*Y)[l-1][l-1];
@@ -157,7 +161,7 @@
         }
 }
 
-static void aan_bbn_update()
+static void init_aan_bbn()
 {
         int l, m;
 
@@ -168,7 +172,7 @@
         aan[1][0] = aan[0][0] *sqrt(3.0);
         aan[1][1] = -aan[1][0];
 
-        for (l=2; l<=4; l++) {
+        for (l=2; l <= L; l++) {
                 aan[l][l] =  -sqrt((2.0*l+1)/(2.0*l));
                 aan[l][l-1] = sqrt(2.0*l+1.0);
                 aan[l][0]   = sqrt(4*l*l-1.0) / l;
@@ -184,16 +188,16 @@
 
 static void generate_ray_samples(int num_sqrt_samples)
 {
-        double a, b, x, y, theta, phi;
-        double inv_MAX = 1.0 / (double)RAND_MAX;
+        float a, b, x, y, theta, phi;
+        float inv_MAX = 1.0 / (float)RAND_MAX;
         
         int i, j;
         for (i = 0; i < num_sqrt_samples; i++) {
                 for (j = 0; j < num_sqrt_samples; j++) {
                         a = rand() * inv_MAX;
                         b = rand() * inv_MAX;
-                        x = (i + a) / (double)num_sqrt_samples;
-                        y = (j + b) / (double)num_sqrt_samples;
+                        x = (i + a) / (float)num_sqrt_samples;
+                        y = (j + b) / (float)num_sqrt_samples;
                         
                         phi = 2.0 * M_PI * x;
                         theta = 2.0 * acos(sqrt(1.0 - y));
@@ -216,9 +220,9 @@
 void SH_init()
 {
         // set up aan, bbn,
-        aan_bbn_update();
+        init_aan_bbn();
 
-        // compute samples
+        // init and compute samples
         samples = MEM_mallocN(NUM_SAMPLES * sizeof(Vec3), "sh_samples");
         sample_angles = MEM_mallocN(NUM_SAMPLES * sizeof(Vec3), "sh_sample_angles");

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list