[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26879] branches/soc-2008-mxcurioni/source /blender/freestyle/intern: Added support for pixel-based density and Z depth information.

Tamito Kajiyama rd6t-kjym at asahi-net.or.jp
Sun Feb 14 04:18:04 CET 2010


Revision: 26879
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26879
Author:   kjym3
Date:     2010-02-14 04:17:52 +0100 (Sun, 14 Feb 2010)

Log Message:
-----------
Added support for pixel-based density and Z depth information.

Availability of pixel-based density and Z depth information depends
on passes of a render layer being rendered.

- Density information is available if the diffuse pass of the render
layer is enabled.  It is accessible through the DensityF0D and
DensityF1D functions provided by the Freestyle Python API.  These
functions return 0 if the diffuse pass is disabled.

- Z depth information is available if the Z pass is enabled.  It can
be accessed through LocalAverageDepthF0D and LocalAverageDepthF1D.
These functions return 0 if the Z pass is disabled.

Modified Paths:
--------------
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/AppCanvas.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/AppCanvas.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/AppCanvas.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/AppCanvas.cpp	2010-02-13 23:29:26 UTC (rev 26878)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/AppCanvas.cpp	2010-02-14 03:17:52 UTC (rev 26879)
@@ -109,20 +109,48 @@
 
 // Abstract
 
-#include "../image/GaussianFilter.h"
 void AppCanvas::readColorPixels(int x,int y,int w, int h, RGBImage& oImage) const
 {
-  //static unsigned number = 0;
   float *rgb = new float[3*w*h];
-  //_pViewer->readPixels(x,y,w,h,AppGLWidget::RGB,rgb);
+  memset(rgb, 0, sizeof(float) * 3 * w * h);
+  if (_pass_diffuse) {
+    int rectx = width(), recty = height();
+    int i, ii, j, jj;
+    for (j = 0; j < h; j++) {
+      jj = y + j;
+      if (jj < 0 || jj >= recty)
+        continue;
+      for (i = 0; i < w; i++) {
+        ii = x + i;
+        if (ii < 0 || ii >= rectx)
+          continue;
+        memcpy(rgb + (w * j + i) * 3, _pass_diffuse + (rectx * jj + ii) * 3, sizeof(float) * 3);
+      }
+    }
+  }
   oImage.setArray(rgb, width(), height(), w,h, x, y, false);
 }
 
 void AppCanvas::readDepthPixels(int x,int y,int w, int h, GrayImage& oImage) const
 {
-  float *rgb = new float[w*h];
-  //_pViewer->readPixels(x,y,w,h,AppGLWidget::DEPTH,rgb);
-  oImage.setArray(rgb, width(), height(), w,h, x, y, false);
+  float *z = new float[w*h];
+  memset(z, 0, sizeof(float) * w * h);
+  if (_pass_z) {
+    int rectx = width(), recty = height();
+    int i, ii, j, jj;
+    for (j = 0; j < h; j++) {
+      jj = y + j;
+      if (jj < 0 || jj >= recty)
+        continue;
+      for (i = 0; i < w; i++) {
+        ii = x + i;
+        if (ii < 0 || ii >= rectx)
+          continue;
+        z[w * j + i] = _pass_z[rectx * jj + ii];
+      }
+    }
+  }
+  oImage.setArray(z, width(), height(), w,h, x, y, false);
 }
 
 void AppCanvas::RenderStroke(Stroke *iStroke) {

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/AppCanvas.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/AppCanvas.h	2010-02-13 23:29:26 UTC (rev 26878)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/AppCanvas.h	2010-02-14 03:17:52 UTC (rev 26879)
@@ -46,6 +46,13 @@
 
   /*! modifiers */
   void setViewer(AppView *iViewer) ;
+
+  // soc
+  void setPassDiffuse(float *p) {_pass_diffuse = p;}
+  void setPassZ(float *p) {_pass_z = p;}
+private:
+  float *_pass_diffuse;
+  float *_pass_z;
 };
 
 

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.cpp	2010-02-13 23:29:26 UTC (rev 26878)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.cpp	2010-02-14 03:17:52 UTC (rev 26879)
@@ -176,6 +176,20 @@
   _Canvas->setViewer(_pView);
 }
 
+void Controller::setPassDiffuse(float *pass)
+{
+  AppCanvas *app_canvas = dynamic_cast<AppCanvas *>(_Canvas);
+  assert(app_canvas != 0);
+  app_canvas->setPassDiffuse(pass);
+}
+
+void Controller::setPassZ(float *pass)
+{
+  AppCanvas *app_canvas = dynamic_cast<AppCanvas *>(_Canvas);
+  assert(app_canvas != 0);
+  app_canvas->setPassZ(pass);
+}
+
 void Controller::setContext(bContext *C)
 {
   PythonInterpreter* py_inter = dynamic_cast<PythonInterpreter*>(_inter);

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.h	2010-02-13 23:29:26 UTC (rev 26878)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.h	2010-02-14 03:17:52 UTC (rev 26879)
@@ -70,6 +70,8 @@
   ~Controller() ;
   
   void setView(AppView *iView);
+  void setPassDiffuse(float *p);
+  void setPassZ(float *p);
   void setContext(bContext *C);
 
   //soc

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp	2010-02-13 23:29:26 UTC (rev 26878)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp	2010-02-14 03:17:52 UTC (rev 26879)
@@ -157,7 +157,18 @@
 		cout << "Redges and valleys : " << (controller->getComputeRidgesAndValleysFlag() ? "enabled" : "disabled") << endl;
 		cout << "Suggestive contours : " << (controller->getComputeSuggestiveContoursFlag() ? "enabled" : "disabled") << endl;
 		cout << "Suggestive contour dkr epsilon : " << controller->getSuggestiveContourKrDerivativeEpsilon() << endl;
+		cout << endl;
 
+        // set diffuse and z depth passes
+        RenderLayer *rl = RE_GetRenderLayer(re->result, srl->name);
+        float *diffuse = RE_RenderLayerGetPass(rl, SCE_PASS_DIFFUSE);
+        float *z = RE_RenderLayerGetPass(rl, SCE_PASS_Z);
+        controller->setPassDiffuse(diffuse);
+        controller->setPassZ(z);
+        cout << "Passes :" << endl;
+        cout << "  Diffuse = " << (diffuse ? "enabled" : "disabled") << endl;
+        cout << "  Z = " << (z ? "enabled" : "disabled") << endl;
+
 		// compute view map
         re->i.infostr= "Freestyle: View map creation";
 		re->stats_draw(re->sdh, &re->i);





More information about the Bf-blender-cvs mailing list