Another big code clean-up patch by Bastien Montagne (GPL headers, indentation,
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>
Tue, 18 Dec 2012 00:51:25 +0000 (00:51 +0000)
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>
Tue, 18 Dec 2012 00:51:25 +0000 (00:51 +0000)
spaces around operators, and so forth).  Many thanks!

21 files changed:
source/blender/SConscript
source/blender/freestyle/CMakeLists.txt
source/blender/freestyle/FRS_freestyle.h
source/blender/freestyle/FRS_freestyle_config.h
source/blender/freestyle/SConscript
source/blender/freestyle/intern/application/AppCanvas.cpp
source/blender/freestyle/intern/application/AppCanvas.h
source/blender/freestyle/intern/application/AppConfig.cpp
source/blender/freestyle/intern/application/AppConfig.h
source/blender/freestyle/intern/application/AppView.cpp
source/blender/freestyle/intern/application/AppView.h
source/blender/freestyle/intern/application/Controller.cpp
source/blender/freestyle/intern/application/Controller.h
source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h
source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.h
source/blender/freestyle/intern/blender_interface/BlenderStyleModule.h
source/blender/freestyle/intern/blender_interface/BlenderTextureManager.cpp
source/blender/freestyle/intern/blender_interface/BlenderTextureManager.h
source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp

index 8fb160ba09ae19e2cccf1084074468fe4aef3c18..2b6db32f00a14337a28a4704510e584d9a344b42 100644 (file)
@@ -9,7 +9,7 @@ SConscript(['avi/SConscript',
             'blenloader/SConscript',
             'gpu/SConscript',
             'editors/SConscript',
-                       'freestyle/SConscript',
+            'freestyle/SConscript',
             'imbuf/SConscript',
             'makesdna/SConscript',
             'render/SConscript',
index a32583a2d2244105d3ff7a78bba0e6feaf65763c..27fd9f5d98e71adbf9f2363ce631141c5650da3b 100644 (file)
@@ -12,7 +12,7 @@
 #
 # 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.
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 #
 # The Original Code is Copyright (C) 2006, Blender Foundation
 # All rights reserved.
@@ -27,8 +27,7 @@ file(GLOB_RECURSE SRC *.cpp *.h)
 
 set(INC 
   ../blenkernel ../blenloader ../blenlib ../imbuf ../makesdna ../makesrna
-  ../python ../python/intern
-  ../render/extern/include ../render/intern/include
+  ../python ../python/intern ../render/extern/include ../render/intern/include
   ../../../extern/glew/include ../../../intern/guardedalloc ../freestyle
 )
 
index 4fff1615e18b88b68cdb731592619a86d9f78c00..ece51d2004827dc5b0684b68849ae1f18d18bc6b 100644 (file)
@@ -1,5 +1,4 @@
-/* FRS_freestyle.h
- *
+/*
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
  * ***** END GPL LICENSE BLOCK *****
  */
 
-#ifndef FRS_FREESTYLE_H
-#define FRS_FREESTYLE_H
+#ifndef __FRS_FREESTYLE_H__
+#define __FRS_FREESTYLE_H__
+
+/** \file blender/freestyle/FRS_freestyle.h
+ *  \ingroup freestyle
+ */
 
 #ifdef __cplusplus
 extern "C" {
-#endif 
-       
-       #include "DNA_listBase.h"
-       #include "DNA_scene_types.h"
-       
-       #include "BKE_context.h"
-       #include "BKE_object.h"
-       
-       struct Render;
-       
-       extern Scene *freestyle_scene;
-       extern float freestyle_viewpoint[3];
-       extern float freestyle_mv[4][4];
-       extern float freestyle_proj[4][4];
-       extern int freestyle_viewport[4];
+#endif
+
+#include "DNA_listBase.h"
+#include "DNA_scene_types.h"
+
+#include "BKE_context.h"
+#include "BKE_object.h"
 
-       // Rendering
-       void FRS_initialize(void);
-       void FRS_set_context(bContext* C);
-       void FRS_read_file(bContext* C);
-       int FRS_is_freestyle_enabled(struct SceneRenderLayer* srl);
-       void FRS_init_stroke_rendering(struct Render* re);
-       struct Render* FRS_do_stroke_rendering(struct Render* re, struct SceneRenderLayer* srl);
-       void FRS_finish_stroke_rendering(struct Render* re);
-       void FRS_composite_result(struct Render* re, struct SceneRenderLayer* srl, struct Render* freestyle_render);
-       void FRS_exit(void);
-       
-       // Panel configuration
-       void FRS_add_module(FreestyleConfig *config);
-       void FRS_delete_module(FreestyleConfig *config, FreestyleModuleConfig *module_conf);
-       void FRS_move_module_up(FreestyleConfig *config, FreestyleModuleConfig *module_conf);
-       void FRS_move_module_down(FreestyleConfig *config, FreestyleModuleConfig *module_conf);
-       
-       FreestyleLineSet *FRS_add_lineset(FreestyleConfig *config);
-       void FRS_copy_active_lineset(FreestyleConfig *config);
-       void FRS_paste_active_lineset(FreestyleConfig *config);
-       void FRS_delete_active_lineset(FreestyleConfig *config);
-       void FRS_move_active_lineset_up(FreestyleConfig *config);
-       void FRS_move_active_lineset_down(FreestyleConfig *config);
+struct Render;
 
-       FreestyleLineSet *FRS_get_active_lineset(FreestyleConfig *config);
-       short FRS_get_active_lineset_index(FreestyleConfig *config);
-       void FRS_set_active_lineset_index(FreestyleConfig *config, short index);
+extern Scene *freestyle_scene;
+extern float freestyle_viewpoint[3];
+extern float freestyle_mv[4][4];
+extern float freestyle_proj[4][4];
+extern int freestyle_viewport[4];
 
-       void FRS_unlink_target_object(FreestyleConfig *config, struct Object *ob);
+/* Rendering */
+void FRS_initialize(void);
+void FRS_set_context(bContext* C);
+void FRS_read_file(bContext* C);
+int FRS_is_freestyle_enabled(struct SceneRenderLayer* srl);
+void FRS_init_stroke_rendering(struct Render* re);
+struct Render* FRS_do_stroke_rendering(struct Render* re, struct SceneRenderLayer* srl);
+void FRS_finish_stroke_rendering(struct Render* re);
+void FRS_composite_result(struct Render* re, struct SceneRenderLayer* srl, struct Render* freestyle_render);
+void FRS_exit(void);
+
+/* Panel configuration */
+void FRS_add_module(FreestyleConfig *config);
+void FRS_delete_module(FreestyleConfig *config, FreestyleModuleConfig *module_conf);
+void FRS_move_module_up(FreestyleConfig *config, FreestyleModuleConfig *module_conf);
+void FRS_move_module_down(FreestyleConfig *config, FreestyleModuleConfig *module_conf);
+
+FreestyleLineSet *FRS_add_lineset(FreestyleConfig *config);
+void FRS_copy_active_lineset(FreestyleConfig *config);
+void FRS_paste_active_lineset(FreestyleConfig *config);
+void FRS_delete_active_lineset(FreestyleConfig *config);
+void FRS_move_active_lineset_up(FreestyleConfig *config);
+void FRS_move_active_lineset_down(FreestyleConfig *config);
+
+FreestyleLineSet *FRS_get_active_lineset(FreestyleConfig *config);
+short FRS_get_active_lineset_index(FreestyleConfig *config);
+void FRS_set_active_lineset_index(FreestyleConfig *config, short index);
+
+void FRS_unlink_target_object(FreestyleConfig *config, struct Object *ob);
 
 #ifdef __cplusplus
 }
 #endif
 
-#endif
+#endif // __FRS_FREESTYLE_H__
index 86a05d1aa223604361d74c3a0aaea47d0b6d2131..0aceffcee1dfecc7ebb5e7e851692caad374468c 100644 (file)
@@ -1,17 +1,48 @@
-#ifndef FRS_FREESTYLE_CONFIG_H
-#define FRS_FREESTYLE_CONFIG_H
+/*
+ * ***** 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) 2010 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __FRS_FREESTYLE_CONFIG_H__
+#define __FRS_FREESTYLE_CONFIG_H__
+
+/** \file FRS_freestyle_config.h
+ *  \ingroup freestyle
+ */
 
 #ifdef __cplusplus
 extern "C" {
-#endif 
-       
-       #include "DNA_scene_types.h"
+#endif
 
-       void FRS_add_freestyle_config( SceneRenderLayer* srl );
-       void FRS_free_freestyle_config( SceneRenderLayer* srl );
+#include "DNA_scene_types.h"
+
+void FRS_add_freestyle_config(SceneRenderLayer* srl);
+void FRS_free_freestyle_config(SceneRenderLayer* srl);
 
 #ifdef __cplusplus
 }
 #endif
 
-#endif
+#endif // __FRS_FREESTYLE_CONFIG_H__
index 281accc76290873049baa37366589ff66415b2cc..11b45acafaf241bf8b5649c12474d336c329f2d2 100644 (file)
@@ -7,76 +7,69 @@ defs = []
 incs = ''
 
 incs += '../blenkernel ../blenloader ../blenlib ../imbuf ../makesdna ../makesrna'
-incs += ' ../python ../python/intern'
-incs += ' ../render/extern/include ../render/intern/include'
+incs += ' ../python ../python/intern ../render/extern/include ../render/intern/include'
 incs += ' #/extern/glew/include #/intern/guardedalloc ../freestyle'
-incs += ' ' + env['BF_PYTHON_INC']     
+incs += ' ' + env['BF_PYTHON_INC']
 incs += ' ' + env['BF_PNG_INC']
 
-
 if env['OURPLATFORM'] == 'linux2':
-       cflags='-pthread'
-       incs += ' ../../../extern/binreloc/include'
+    cflags='-pthread'
+    incs += ' ../../../extern/binreloc/include'
 
 if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'):
-       incs += ' ' + env['BF_PTHREADS_INC']
+    incs += ' ' + env['BF_PTHREADS_INC']
 
 ########################################################
-#      folders sources 
+#   folders sources
 ########################################################
 
-#      system
+#   system
 prefix = 'intern/system'
 system_sources = env.Glob(prefix + '/*.cpp')
 
-#      image
+#   image
 prefix = 'intern/image'
 image_sources = env.Glob(prefix + '/*.cpp')
 
-#      geometry
+#   geometry
 prefix = 'intern/geometry'
 geometry_sources = env.Glob(prefix + '/*.cpp')
 
-#      scene_graph
+#   scene_graph
 prefix = 'intern/scene_graph'
 scene_graph_sources = env.Glob(prefix + '/*.cpp')
 
-#      winged_edge
+#   winged_edge
 prefix = 'intern/winged_edge'
 winged_edge_sources = env.Glob(prefix + '/*.cpp')
 
-#      view_map
+#   view_map
 prefix = 'intern/view_map'
 view_map_sources = env.Glob(prefix + '/*.cpp')
 
-#      stroke
+#   stroke
 prefix = 'intern/stroke'
 stroke_sources = env.Glob(prefix + '/*.cpp')
 
-#      application
+#   application
 prefix = 'intern/application'
 application_sources = env.Glob(prefix + '/*.cpp')
 
-#      blender_interface
+#   blender_interface
 prefix = 'intern/blender_interface'
 interface_sources = env.Glob(prefix + '/*.cpp')
 
-#      Python
+#   Python
 prefix = 'intern/python'
-python_sources =  env.Glob(prefix + '/*.cpp') \
-                               + env.Glob(prefix + '/*/*.cpp') \
-                               + env.Glob(prefix + '/*/*/*.cpp') \
-                               + env.Glob(prefix + '/*/*/*/*.cpp')
-
-sources =      system_sources + image_sources + geometry_sources + scene_graph_sources \
-                 + winged_edge_sources + view_map_sources + stroke_sources \
-                 + application_sources + interface_sources + python_sources
-
-env.BlenderLib (libname="bf_freestyle",
-                               sources=sources,
-                includes=Split(incs),
-                defines=defs,
-                               libtype=['core'],
-                priority = [370] # bf_python is 361
- )
-
+python_sources = env.Glob(prefix + '/*.cpp') + \
+                 env.Glob(prefix + '/*/*.cpp') + \
+                 env.Glob(prefix + '/*/*/*.cpp') + \
+                 env.Glob(prefix + '/*/*/*/*.cpp')
+
+sources = system_sources + image_sources + geometry_sources + scene_graph_sources + \
+          winged_edge_sources + view_map_sources + stroke_sources + \
+          application_sources + interface_sources + python_sources
+
+env.BlenderLib(libname="bf_freestyle", sources=sources, includes=Split(incs),
+               defines=defs, libtype=['core'], priority = [370] # bf_python is 361
+)
index ec83d2d9ff85e76c38aaaf652693fbb8ad080b3d..6e47a52b76fa7c2131b6880f92d209f1ad08ee2e 100644 (file)
@@ -1,23 +1,33 @@
-
-//
-//  Copyright (C) : Please refer to the COPYRIGHT file distributed 
-//   with this source distribution. 
-//
-//  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.
-//
-///////////////////////////////////////////////////////////////////////////////
+/*
+ * ***** 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) 2010 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/freestyle/intern/application/AppCanvas.cpp
+ *  \ingroup freestyle
+ */
 
 #include "Controller.h"
 #include "AppView.h"
 AppCanvas::AppCanvas()
 :Canvas()
 {
-  _pViewer = 0;
-       _MapsPath = StringUtils::toAscii( Config::Path::getInstance()->getMapsDir() ).c_str();
+       _pViewer = 0;
+       _MapsPath = StringUtils::toAscii(Config::Path::getInstance()->getMapsDir()).c_str();
 }
 
 AppCanvas::AppCanvas(AppView* iViewer)
 :Canvas()
 {
-  _pViewer = iViewer;
+       _pViewer = iViewer;
 }
 
 AppCanvas::AppCanvas(const AppCanvas& iBrother)
 :Canvas(iBrother)
 {
-  _pViewer = iBrother._pViewer;
+       _pViewer = iBrother._pViewer;
 }
 
 AppCanvas::~AppCanvas()
 {
-  _pViewer = 0;
+       _pViewer = 0;
 }
 
 void AppCanvas::setViewer(AppView *iViewer)
 {
-  _pViewer = iViewer;
-}  
+       _pViewer = iViewer;
+}
 
 int AppCanvas::width() const 
 {
-  return _pViewer->width();
+       return _pViewer->width();
 }
 
 int AppCanvas::height() const
 {
-  return _pViewer->height();
+       return _pViewer->height();
 }
 
 BBox<Vec2i> AppCanvas::border() const
 {
-  return _pViewer->border();
+       return _pViewer->border();
 }
 
 float AppCanvas::thickness() const
 {
-  return _pViewer->thickness();
+       return _pViewer->thickness();
 }
 
 BBox<Vec3r> AppCanvas::scene3DBBox() const 
 {
-  return _pViewer->scene3DBBox();
+       return _pViewer->scene3DBBox();
 }
 
 void AppCanvas::preDraw()
 {
-  Canvas::preDraw();
+       Canvas::preDraw();
 }
 
-void AppCanvas::init() 
+void AppCanvas::init()
 {
-
-       //   static bool firsttime = true;
-       //   if (firsttime) {
-       // 
-       //   _Renderer = new BlenderStrokeRenderer;
-       //   if(!StrokeRenderer::loadTextures())
-       //     {
-       //       cerr << "unable to load stroke textures" << endl;
-       //       return;
-       //     }
-       //      }
+#if 0
+       static bool firsttime = true;
+       if (firsttime) {
+               _Renderer = new BlenderStrokeRenderer;
+               if(!StrokeRenderer::loadTextures()) {
+                       cerr << "unable to load stroke textures" << endl;
+                       return;
+               }
+       }
+#endif
 }
 
 void AppCanvas::postDraw()
 {
-  for (unsigned i = 0; i < _StyleModules.size(); i++) {
-    if(!_StyleModules[i]->getDisplayed() || !_Layers[i])
-      continue;
-    _Layers[i]->ScaleThickness(thickness());
-  }
-  Canvas::postDraw();
+       for (unsigned int i = 0; i < _StyleModules.size(); i++) {
+               if(!_StyleModules[i]->getDisplayed() || !_Layers[i])
+                       continue;
+               _Layers[i]->ScaleThickness(thickness());
+       }
+       Canvas::postDraw();
 }
 
 void AppCanvas::Erase()
 {
-  Canvas::Erase();
+       Canvas::Erase();
 }
 
 // Abstract
@@ -136,7 +145,8 @@ void AppCanvas::readColorPixels(int x,int y,int w, int h, RGBImage& oImage) cons
                int recty = _pass_z.height;
                float xfac = ((float)rectx) / ((float)(xmax - xmin));
                float yfac = ((float)recty) / ((float)(ymax - ymin));
-               //printf("readColorPixels %d x %d @ (%d, %d) in %d x %d [%d x %d] -- %d x %d @ %d%%\n", w, h, x, y, xsch, ysch, xmax - xmin, ymax - ymin, rectx, recty, (int)(xfac * 100.0f));
+               //printf("readColorPixels %d x %d @ (%d, %d) in %d x %d [%d x %d] -- %d x %d @ %d%%\n", w, h, x, y, xsch, ysch,
+               //       xmax - xmin, ymax - ymin, rectx, recty, (int)(xfac * 100.0f));
                int ii, jj;
                for (int j = 0; j < h; j++) {
                        jj = (int)((y - ymin + j) * yfac);
@@ -168,7 +178,8 @@ void AppCanvas::readDepthPixels(int x,int y,int w, int h, GrayImage& oImage) con
                int recty = _pass_z.height;
                float xfac = ((float)rectx) / ((float)(xmax - xmin));
                float yfac = ((float)recty) / ((float)(ymax - ymin));
-               //printf("readDepthPixels %d x %d @ (%d, %d) in %d x %d [%d x %d] -- %d x %d @ %d%%\n", w, h, x, y, xsch, ysch, xmax - xmin, ymax - ymin, rectx, recty, (int)(xfac * 100.0f));
+               //printf("readDepthPixels %d x %d @ (%d, %d) in %d x %d [%d x %d] -- %d x %d @ %d%%\n", w, h, x, y, xsch, ysch,
+               //       xmax - xmin, ymax - ymin, rectx, recty, (int)(xfac * 100.0f));
                int ii, jj;
                for (int j = 0; j < h; j++) {
                        jj = (int)((y - ymin + j) * yfac);
@@ -185,8 +196,8 @@ void AppCanvas::readDepthPixels(int x,int y,int w, int h, GrayImage& oImage) con
        oImage.setArray(z, xsch, ysch, w, h, x, y, false);
 }
 
-void AppCanvas::RenderStroke(Stroke *iStroke) {
-
+void AppCanvas::RenderStroke(Stroke *iStroke)
+{
        if(_basic)
                iStroke->RenderBasic(_Renderer);
        else
@@ -194,5 +205,6 @@ void AppCanvas::RenderStroke(Stroke *iStroke) {
 }
 
 
-void AppCanvas::update() {}
-
+void AppCanvas::update()
+{
+}
index 59ed2af3bdd7bb08e024e9d4625682cf84371698..3a65020463c84a4a790c5f7e1aafc57adbfe9b20 100644 (file)
-#ifndef ARTCANVAS_H
-#define ARTCANVAS_H
+/*
+ * ***** 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) 2010 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __APPCANVAS_H__
+#define __APPCANVAS_H__
+
+/** \file blender/freestyle/intern/application/AppCanvas.h
+ *  \ingroup freestyle
+ */
 
 #include "../stroke/Canvas.h"
 #include "AppView.h"
 
 class AppCanvas : public Canvas
 {
-       
 public:
-  AppCanvas();
-  AppCanvas(AppView *iViewer);
-  AppCanvas(const AppCanvas& iBrother);
-  virtual ~AppCanvas();
-
-  /*! operations that need to be done before a draw */
-  virtual void preDraw();
-  
-  /*! operations that need to be done after a draw */
-  virtual void postDraw();
-  
-  /*! Erases the layers and clears the canvas */
-  virtual void Erase(); 
-  
-  /* init the canvas */
-  virtual void init();
-  
-  /*! Reads a pixel area from the canvas */
-  virtual void readColorPixels(int x,int y,int w, int h, RGBImage& oImage) const;
-  /*! Reads a depth pixel area from the canvas */
-  virtual void readDepthPixels(int x,int y,int w, int h, GrayImage& oImage) const;
-
-  virtual BBox<Vec3r> scene3DBBox() const ;
-
-       // abstract
+       AppCanvas();
+       AppCanvas(AppView *iViewer);
+       AppCanvas(const AppCanvas& iBrother);
+       virtual ~AppCanvas();
+
+       /*! operations that need to be done before a draw */
+       virtual void preDraw();
+
+       /*! operations that need to be done after a draw */
+       virtual void postDraw();
+
+       /*! Erases the layers and clears the canvas */
+       virtual void Erase();
+
+       /* init the canvas */
+       virtual void init();
+
+       /*! Reads a pixel area from the canvas */
+       virtual void readColorPixels(int x,int y,int w, int h, RGBImage& oImage) const;
+       /*! Reads a depth pixel area from the canvas */
+       virtual void readDepthPixels(int x,int y,int w, int h, GrayImage& oImage) const;
+
+       virtual BBox<Vec3r> scene3DBBox() const;
+
+       /* abstract */
        virtual void RenderStroke(Stroke*);
        virtual void update();
 
 
-  /*! accessors */
-  virtual int width() const ;
-  virtual int height() const ;
-  virtual BBox<Vec2i> border() const ;
-  virtual float thickness() const ;
+       /*! accessors */
+       virtual int width() const;
+       virtual int height() const;
+       virtual BBox<Vec2i> border() const;
+       virtual float thickness() const;
 
        AppView *_pViewer;
-  inline const AppView * viewer() const {return _pViewer;}
-
-  /*! modifiers */
-  void setViewer(AppView *iViewer) ;
-
-  // soc
-  void setPassDiffuse(float *buf, int width, int height) {
-      _pass_diffuse.buf = buf;
-      _pass_diffuse.width = width;
-      _pass_diffuse.height = height;
-  }
-  void setPassZ(float *buf, int width, int height) {
-      _pass_z.buf = buf;
-      _pass_z.width = width;
-      _pass_z.height = height;
-  }
+       inline const AppView * viewer() const {return _pViewer;}
+
+       /*! modifiers */
+       void setViewer(AppView *iViewer);
+
+       /* soc */
+       void setPassDiffuse(float *buf, int width, int height) {
+               _pass_diffuse.buf = buf;
+               _pass_diffuse.width = width;
+               _pass_diffuse.height = height;
+       }
+       void setPassZ(float *buf, int width, int height) {
+               _pass_z.buf = buf;
+               _pass_z.width = width;
+               _pass_z.height = height;
+       }
+
 private:
-    struct {
-        float *buf;
-        int width, height;
-    } _pass_diffuse, _pass_z;
+       struct {
+               float *buf;
+               int width, height;
+       } _pass_diffuse, _pass_z;
 };
 
-
-#endif
+#endif // __APPCANVAS_H__
index fe6a8fb5e53b473bade62636b12240b4a3aa7edb..f687117c76285e367547d8530aeedc25bb299a93 100644 (file)
@@ -1,53 +1,66 @@
-//
-//  Copyright (C) : Please refer to the COPYRIGHT file distributed 
-//   with this source distribution. 
-//
-//  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.
-//
-///////////////////////////////////////////////////////////////////////////////
+/*
+ * ***** 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) 2010 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/freestyle/intern/application/AppConfig.cpp
+ *  \ingroup freestyle
+ */
 
 #include "AppConfig.h"
 #include <iostream>
 
 #include "../system/StringUtils.h"
+
 using namespace std;
 
 extern "C" {
-       #include "BLI_path_util.h"
+#include "BLI_path_util.h"
 }
 
 namespace Config {
+
 Path* Path::_pInstance = 0;
-Path::Path() {
+Path::Path()
+{
        // get the root directory
-       //soc
-       setRootDir( BLI_get_folder(BLENDER_SYSTEM_SCRIPTS, NULL) );
+       // soc
+       setRootDir(BLI_get_folder(BLENDER_SYSTEM_SCRIPTS, NULL));
 
        _pInstance = this;
 }
-void Path::setRootDir(const string& iRootDir) {
+
+void Path::setRootDir(const string& iRootDir)
+{
        _ProjectDir = iRootDir + string(DIR_SEP.c_str()) + "freestyle";
        _ModelsPath = "";
-       _PatternsPath = _ProjectDir + string(DIR_SEP.c_str()) + "data"
-                       + string(DIR_SEP.c_str()) + "textures" + string(DIR_SEP.c_str())
-                       + "variation_patterns" + string(DIR_SEP.c_str());
-       _BrushesPath = _ProjectDir + string(DIR_SEP.c_str()) + "data"
-                       + string(DIR_SEP.c_str()) + "textures" + string(DIR_SEP.c_str())
-                       + "brushes" + string(DIR_SEP.c_str());
-       _PythonPath = _ProjectDir + string(DIR_SEP.c_str())
-+ "style_modules" + string(DIR_SEP.c_str()) ;
+       _PatternsPath = _ProjectDir + string(DIR_SEP.c_str()) + "data" + string(DIR_SEP.c_str()) + "textures" +
+                       string(DIR_SEP.c_str()) + "variation_patterns" + string(DIR_SEP.c_str());
+       _BrushesPath = _ProjectDir + string(DIR_SEP.c_str()) + "data" + string(DIR_SEP.c_str()) + "textures" +
+                      string(DIR_SEP.c_str()) + "brushes" + string(DIR_SEP.c_str());
+       _PythonPath = _ProjectDir + string(DIR_SEP.c_str()) + "style_modules" + string(DIR_SEP.c_str());
        if (getenv("PYTHONPATH")) {
                _PythonPath += string(PATH_SEP.c_str()) + string(getenv("PYTHONPATH"));
        }
@@ -56,37 +69,44 @@ void Path::setRootDir(const string& iRootDir) {
 #else
        _BrowserCmd = "mozilla %s";
 #endif
-       _HelpIndexPath = _ProjectDir + string(DIR_SEP.c_str()) + "doc"
-                       + string(DIR_SEP.c_str()) + "html" + string(DIR_SEP.c_str())
-                       + "index.html";
-       _EnvMapDir = _ProjectDir + string(DIR_SEP.c_str()) + "data"
-                       + string(DIR_SEP.c_str()) + "env_map" + string(DIR_SEP.c_str());
-       _MapsDir = _ProjectDir + string(DIR_SEP.c_str()) + "data"
-                       + string(DIR_SEP.c_str()) + "maps" + string(DIR_SEP.c_str());
+       _HelpIndexPath = _ProjectDir + string(DIR_SEP.c_str()) + "doc" + string(DIR_SEP.c_str()) + "html" +
+                        string(DIR_SEP.c_str()) + "index.html";
+       _EnvMapDir = _ProjectDir + string(DIR_SEP.c_str()) + "data" + string(DIR_SEP.c_str()) + "env_map" +
+                    string(DIR_SEP.c_str());
+       _MapsDir = _ProjectDir + string(DIR_SEP.c_str()) + "data" + string(DIR_SEP.c_str()) + "maps" +
+                  string(DIR_SEP.c_str());
 }
-void Path::setHomeDir(const string& iHomeDir) {
+
+void Path::setHomeDir(const string& iHomeDir)
+{
        _HomeDir = iHomeDir;
 }
-Path::~Path() {
+
+Path::~Path()
+{
        _pInstance = 0;
 }
-Path* Path::getInstance() {
+
+Path* Path::getInstance()
+{
        return _pInstance;
 }
-string Path::getEnvVar(const string& iEnvVarName) {
+
+string Path::getEnvVar(const string& iEnvVarName)
+{
        string value;
-       if (!getenv(StringUtils::toAscii(iEnvVarName).c_str() ) ) {
+       if (!getenv(StringUtils::toAscii(iEnvVarName).c_str())) {
                cerr << "Warning: You may want to set the $"
-                               << StringUtils::toAscii(iEnvVarName)
-                               << " environment variable to use Freestyle." << endl
-                               << "         Otherwise, the current directory will be used instead."
-                               << endl;
+                    << StringUtils::toAscii(iEnvVarName)
+                    << " environment variable to use Freestyle." << endl
+                    << "         Otherwise, the current directory will be used instead."
+                    << endl;
                value = ".";
-       } else {
-               value = getenv(StringUtils::toAscii(iEnvVarName).c_str() );
+       }
+       else {
+               value = getenv(StringUtils::toAscii(iEnvVarName).c_str());
        }
        return value;
 }
 
 } // End of namepace Config
-
index 59e85ca2e17b79793424aad22e0485c6cfc13e3f..ebd6f85db7078f2324ab6dd3babfb098b7e306fe 100644 (file)
+/*
+ * ***** 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) 2010 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __APP_CONFIG_H__
+#define __APP_CONFIG_H__
+
+/** \file blender/freestyle/intern/application/AppConfig.h
+ *  \ingroup freestyle
+ *  \brief Configuration file
+ *  \author Emmanuel Turquin
+ *  \date 26/02/2003
+ */
+
+#include <string>
+#include "../system/FreestyleConfig.h"
+#include "../system/Precision.h"
+
+using namespace std;
+
+namespace Config {
+
+class Path{
+protected:
+       static Path * _pInstance;
+       string _ProjectDir;
+       string _ModelsPath;
+       string _PatternsPath;
+       string _BrushesPath;
+       string _PythonPath;
+       string _BrowserCmd;
+       string _HelpIndexPath;
+       string _EnvMapDir;
+       string _MapsDir;
+       string _HomeDir;
+
+public:
+       Path();
+       virtual ~Path();
+       static Path* getInstance();
+
+       void setRootDir(const string& iRootDir);
+       void setHomeDir(const string& iHomeDir);
+
+       const string& getProjectDir() const {return _ProjectDir;}
+       const string& getModelsPath() const {return _ModelsPath;}
+       const string& getPatternsPath() const {return _PatternsPath;}
+       const string& getBrushesPath() const {return _BrushesPath;}
+       const string& getPythonPath() const {return _PythonPath;}
+       const string& getBrowserCmd() const {return _BrowserCmd;}
+       const string& getHelpIndexpath() const {return _HelpIndexPath;}
+       const string& getEnvMapDir() const {return _EnvMapDir;}
+       const string& getMapsDir() const {return _MapsDir;}
+       const string& getHomeDir() const {return _HomeDir;}
+
+       static string getEnvVar(const string& iEnvVarName);
+};
+
 //
-//  Filename         : AppConfig.h
-//  Author           : Emmanuel Turquin
-//  Purpose          : Configuration file
-//  Date of creation : 26/02/2003
-//
-///////////////////////////////////////////////////////////////////////////////
-//
-//  Copyright (C) : Please refer to the COPYRIGHT file distributed 
-//   with this source distribution. 
-//
-//  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.
+// Configuration, default values
 //
-///////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////
 
-#ifndef  APP_CONFIG_H
-# define APP_CONFIG_H
+// Application
+static const string APPLICATION_NAME("APPNAME");
+static const string APPLICATION_VERSION("APPVERSION");
 
-# include <string>
-# include "../system/FreestyleConfig.h"
-# include "../system/Precision.h"
+// ViewMap
+static const string VIEWMAP_EXTENSION("vm");
+static const string VIEWMAP_MAGIC("ViewMap File");
+static const string VIEWMAP_VERSION("1.9");
 
-using namespace std;
+// Style modules
+static const string STYLE_MODULE_EXTENSION("py");
+static const string STYLE_MODULES_LIST_EXTENSION("sml");
 
-namespace Config {
+// Options
+static const string OPTIONS_DIR("." + APPLICATION_NAME);
+static const string OPTIONS_FILE("options.xml");
+static const string OPTIONS_CURRENT_DIRS_FILE("current_dirs.xml");
+static const string OPTIONS_QGLVIEWER_FILE("qglviewer.xml");
 
-  class Path{
-  protected:
-    static Path * _pInstance;
-    string _ProjectDir;
-    string _ModelsPath;
-    string _PatternsPath;
-    string _BrushesPath;
-    string _PythonPath;
-    string _BrowserCmd;
-    string _HelpIndexPath;
-    string _EnvMapDir;
-    string _MapsDir;
-    string _HomeDir;
-  public:
-    Path();
-    virtual ~Path();
-    static Path* getInstance();
-
-    void setRootDir(const string& iRootDir) ;
-    void setHomeDir(const string& iHomeDir) ;
-
-    const string& getProjectDir() const {return _ProjectDir;}
-    const string& getModelsPath() const {return _ModelsPath;}
-    const string& getPatternsPath() const {return _PatternsPath;}
-    const string& getBrushesPath() const {return _BrushesPath;}
-    const string& getPythonPath() const {return _PythonPath;}
-    const string& getBrowserCmd() const {return _BrowserCmd;}
-    const string& getHelpIndexpath() const {return _HelpIndexPath;}
-    const string& getEnvMapDir() const {return _EnvMapDir;}
-    const string& getMapsDir() const {return _MapsDir;}
-    const string& getHomeDir() const {return _HomeDir;}
-
-    static string getEnvVar(const string& iEnvVarName);
-    
-  };
-
-  //
-  // Configuration, default values
-  //
-  //////////////////////////////////////////////////////////////
-
-  // Application
-  static const string APPLICATION_NAME("APPNAME");
-  static const string APPLICATION_VERSION("APPVERSION");
-
-  // ViewMap
-  static const string VIEWMAP_EXTENSION("vm");
-  static const string VIEWMAP_MAGIC("ViewMap File");
-  static const string VIEWMAP_VERSION("1.9");
-
-  // Style modules
-  static const string STYLE_MODULE_EXTENSION("py");
-  static const string STYLE_MODULES_LIST_EXTENSION("sml");
-
-  // Options
-  static const string OPTIONS_DIR("." + APPLICATION_NAME);
-  static const string OPTIONS_FILE("options.xml");
-  static const string OPTIONS_CURRENT_DIRS_FILE("current_dirs.xml");
-  static const string OPTIONS_QGLVIEWER_FILE("qglviewer.xml");
-
-  // Default options
-  static const real DEFAULT_SPHERE_RADIUS = 1.0;
-  static const real DEFAULT_DKR_EPSILON = 0.0;
+// Default options
+static const real DEFAULT_SPHERE_RADIUS = 1.0;
+static const real DEFAULT_DKR_EPSILON = 0.0;
 
 } // End of namepace Config
 
-#endif // APP_CONFIG_H
+#endif // __APP_CONFIG_H__
index 8541122ef0d928458b7a4a79490acea9cd96132c..98601bbb3597b904dfcedb5f00499cfa47e0d7c5 100644 (file)
+/*
+ * ***** 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) 2010 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/freestyle/intern/application/AppView.cpp
+ *  \ingroup freestyle
+ */
 
-//
-//  Copyright (C) : Please refer to the COPYRIGHT file distributed 
-//   with this source distribution. 
-//
-//  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.
-//
-///////////////////////////////////////////////////////////////////////////////
-
-extern "C" {
-#include "BLI_jitter.h"
-}
+#include <iostream>
 
 #include "Controller.h"
-#include <iostream>
-#include "../stroke/Canvas.h"
+#include "AppConfig.h"
 #include "AppView.h"
-#include "../scene_graph/NodeLight.h"
 #include "../view_map/Silhouette.h"
 #include "../view_map/ViewMap.h"
 #include "../scene_graph/LineRep.h"
+#include "../scene_graph/NodeLight.h"
 #include "../scene_graph/NodeShape.h"
 #include "../scene_graph/VertexRep.h"
-#include "AppConfig.h"
-
+#include "../stroke/Canvas.h"
 #include "../system/StringUtils.h"
 
 extern "C" {
 #include "BLI_blenlib.h"
+#include "BLI_jitter.h"
+
 #include "IMB_imbuf.h"
 #include "IMB_imbuf_types.h"
+
 #if 1 // FRS_antialiasing
-#include "BKE_global.h"
-#include "DNA_scene_types.h"
+#  include "BKE_global.h"
+#  include "DNA_scene_types.h"
 #endif
 
-#include "../../FRS_freestyle.h"
-
+#include "FRS_freestyle.h"
 }
 
 AppView::AppView(const char *iName)
 {
-  _Fovy        = 30.f * M_PI / 180.0;
-  _ModelRootNode = new NodeDrawingStyle;
-  _SilhouetteRootNode = new NodeDrawingStyle;
-  _DebugRootNode = new NodeDrawingStyle;
-  
-  _RootNode.AddChild(_ModelRootNode);
-  _SilhouetteRootNode->setStyle(DrawingStyle::LINES);
-  _SilhouetteRootNode->setLightingEnabled(false);
-  _SilhouetteRootNode->setLineWidth(2.f);
-  _SilhouetteRootNode->setPointSize(3.f);
-
-  _RootNode.AddChild(_SilhouetteRootNode);
-
-  _DebugRootNode->setStyle(DrawingStyle::LINES);
-  _DebugRootNode->setLightingEnabled(false);
-  _DebugRootNode->setLineWidth(1.f);
-  
-  _RootNode.AddChild(_DebugRootNode);
-
-  _minBBox = __min(__min(_ModelRootNode->bbox().getMin()[0], 
-                            _ModelRootNode->bbox().getMin()[1]),
-                      _ModelRootNode->bbox().getMin()[2]);
-  _maxBBox = __max(__max(_ModelRootNode->bbox().getMax()[0], 
-                            _ModelRootNode->bbox().getMax()[1]),
-                      _ModelRootNode->bbox().getMax()[2]);
-
-  _maxAbs = __max(rabs(_minBBox), rabs(_maxBBox));
-  _minAbs = __min(rabs(_minBBox), rabs(_maxBBox));
-
-  _p2DSelectionNode = new NodeDrawingStyle;
-  _p2DSelectionNode->setLightingEnabled(false);
-  _p2DSelectionNode->setStyle(DrawingStyle::LINES);
-  _p2DSelectionNode->setLineWidth(5.f);
-  
-  _p2DNode.AddChild(_p2DSelectionNode);
-
-       
+       _Fovy = DEG2RADF(30.0f);
+       _ModelRootNode = new NodeDrawingStyle;
+       _SilhouetteRootNode = new NodeDrawingStyle;
+       _DebugRootNode = new NodeDrawingStyle;
+
+       _RootNode.AddChild(_ModelRootNode);
+       _SilhouetteRootNode->setStyle(DrawingStyle::LINES);
+       _SilhouetteRootNode->setLightingEnabled(false);
+       _SilhouetteRootNode->setLineWidth(2.0f);
+       _SilhouetteRootNode->setPointSize(3.0f);
+
+       _RootNode.AddChild(_SilhouetteRootNode);
+
+       _DebugRootNode->setStyle(DrawingStyle::LINES);
+       _DebugRootNode->setLightingEnabled(false);
+       _DebugRootNode->setLineWidth(1.0f);
+
+       _RootNode.AddChild(_DebugRootNode);
+
+       _minBBox = __min(__min(_ModelRootNode->bbox().getMin()[0], _ModelRootNode->bbox().getMin()[1]),
+                        _ModelRootNode->bbox().getMin()[2]);
+       _maxBBox = __max(__max(_ModelRootNode->bbox().getMax()[0], _ModelRootNode->bbox().getMax()[1]),
+                        _ModelRootNode->bbox().getMax()[2]);
+
+       _maxAbs = __max(rabs(_minBBox), rabs(_maxBBox));
+       _minAbs = __min(rabs(_minBBox), rabs(_maxBBox));
+
+       _p2DSelectionNode = new NodeDrawingStyle;
+       _p2DSelectionNode->setLightingEnabled(false);
+       _p2DSelectionNode->setStyle(DrawingStyle::LINES);
+       _p2DSelectionNode->setLineWidth(5.0f);
+
+       _p2DNode.AddChild(_p2DSelectionNode);
+
        NodeLight *light = new NodeLight;
        _Light.AddChild(light);
 }
 
 AppView::~AppView()
 {
-  int ref = _RootNode.destroy();
-  
-  _Light.destroy();
-  ref = _p2DNode.destroy();
-  
+       int ref = _RootNode.destroy();
+
+       _Light.destroy();
+       ref = _p2DNode.destroy();
 }
 
-real AppView::distanceToSceneCenter() {
+real AppView::distanceToSceneCenter()
+{
        BBox<Vec3r> bbox = _ModelRootNode->bbox();
-       
-       Vec3r v( freestyle_viewpoint[0], freestyle_viewpoint[1], freestyle_viewpoint[2]);
-       v -=  0.5 * (bbox.getMin() + bbox.getMax());
+
+       Vec3r v(freestyle_viewpoint[0], freestyle_viewpoint[1], freestyle_viewpoint[2]);
+       v -= 0.5 * (bbox.getMin() + bbox.getMax());
 
        return v.norm();
 }
 
-
-real AppView::znear() {
-       
+real AppView::znear()
+{
        BBox<Vec3r> bbox = _ModelRootNode->bbox();
        Vec3r u = bbox.getMin();
        Vec3r v = bbox.getMax();
-       Vec3r cameraCenter( freestyle_viewpoint[0], freestyle_viewpoint[1], freestyle_viewpoint[2]);
-
-       Vec3r w1( u[0], u[1], u[2] );
-       Vec3r w2( v[0], u[1], u[2] );
-       Vec3r w3( u[0], v[1], u[2] );
-       Vec3r w4( v[0], v[1], u[2] );
-       Vec3r w5( u[0], u[1], v[2] );
-       Vec3r w6( v[0], u[1], v[2] );
-       Vec3r w7( u[0], v[1], v[2] );
-       Vec3r w8( v[0], v[1], v[2] );
-
-       real _znear =   __min(  (w1-cameraCenter).norm(),
-                                       __min(  (w2-cameraCenter).norm(),
-                                       __min(  (w3-cameraCenter).norm(),
-                                       __min(  (w4-cameraCenter).norm(),
-                                       __min(  (w5-cameraCenter).norm(),
-                                       __min(  (w6-cameraCenter).norm(),
-                                       __min(  (w7-cameraCenter).norm(),
-                                                       (w8-cameraCenter).norm()        )))))));
-       
-       return __max(_znear, 0.001);
+       Vec3r cameraCenter(freestyle_viewpoint[0], freestyle_viewpoint[1], freestyle_viewpoint[2]);
+
+       Vec3r w1(u[0], u[1], u[2]);
+       Vec3r w2(v[0], u[1], u[2]);
+       Vec3r w3(u[0], v[1], u[2]);
+       Vec3r w4(v[0], v[1], u[2]);
+       Vec3r w5(u[0], u[1], v[2]);
+       Vec3r w6(v[0], u[1], v[2]);
+       Vec3r w7(u[0], v[1], v[2]);
+       Vec3r w8(v[0], v[1], v[2]);
+
+       real _znear = __min((w1 - cameraCenter).norm(),
+                           __min((w2 - cameraCenter).norm(),
+                                 __min((w3 - cameraCenter).norm(),
+                                       __min((w4 - cameraCenter).norm(),
+                                             __min((w5 - cameraCenter).norm(),
+                                                   __min((w6 - cameraCenter).norm(),
+                                                         __min((w7 - cameraCenter).norm(),
+                                                               (w8 - cameraCenter).norm()
+                                                              )
+                                                        )
+                                                  )
+                                            )
+                                      )
+                                )
+                          );
 
-       }
-  
-  real AppView::zfar() {
+       return __max(_znear, 0.001);
+}
 
+real AppView::zfar()
+{
        BBox<Vec3r> bbox = _ModelRootNode->bbox();
        Vec3r u = bbox.getMin();
        Vec3r v = bbox.getMax();
-       Vec3r cameraCenter( freestyle_viewpoint[0], freestyle_viewpoint[1], freestyle_viewpoint[2]);
-
-       Vec3r w1( u[0], u[1], u[2] );
-       Vec3r w2( v[0], u[1], u[2] );
-       Vec3r w3( u[0], v[1], u[2] );
-       Vec3r w4( v[0], v[1], u[2] );
-       Vec3r w5( u[0], u[1], v[2] );
-       Vec3r w6( v[0], u[1], v[2] );
-       Vec3r w7( u[0], v[1], v[2] );
-       Vec3r w8( v[0], v[1], v[2] );
-
-       real _zfar =    __max(  (w1-cameraCenter).norm(),
-                                       __max(  (w2-cameraCenter).norm(),
-                                       __max(  (w3-cameraCenter).norm(),
-                                       __max(  (w4-cameraCenter).norm(),
-                                       __max(  (w5-cameraCenter).norm(),
-                                       __max(  (w6-cameraCenter).norm(),
-                                       __max(  (w7-cameraCenter).norm(),
-                                                       (w8-cameraCenter).norm()        )))))));
+       Vec3r cameraCenter(freestyle_viewpoint[0], freestyle_viewpoint[1], freestyle_viewpoint[2]);
+
+       Vec3r w1(u[0], u[1], u[2]);
+       Vec3r w2(v[0], u[1], u[2]);
+       Vec3r w3(u[0], v[1], u[2]);
+       Vec3r w4(v[0], v[1], u[2]);
+       Vec3r w5(u[0], u[1], v[2]);
+       Vec3r w6(v[0], u[1], v[2]);
+       Vec3r w7(u[0], v[1], v[2]);
+       Vec3r w8(v[0], v[1], v[2]);
+
+       real _zfar = __max((w1 - cameraCenter).norm(),
+                          __max((w2 - cameraCenter).norm(),
+                                __max((w3 - cameraCenter).norm(),
+                                      __max((w4 - cameraCenter).norm(),
+                                            __max((w5 - cameraCenter).norm(),
+                                                  __max((w6 - cameraCenter).norm(),
+                                                        __max((w7 - cameraCenter).norm(),
+                                                              (w8 - cameraCenter).norm()
+                                                             )
+                                                       )
+                                                 )
+                                           )
+                                     )
+                               )
+                         );
 
        return _zfar;
+}
 
-       }
-
-  real AppView::GetFocalLength()
-  {
-    real Near =  __max(0.1,(real)(-2.f*_maxAbs+ distanceToSceneCenter() ));
-    return Near;
-  }
-
-
+real AppView::GetFocalLength()
+{
+       real Near = __max(0.1, (real)(-2.0f * _maxAbs + distanceToSceneCenter()));
+       return Near;
+}
index d9b53019a936ac3e868f41e4ee63399cbe80aba7..0763a33a21291926822a2ff03e69d83dd7d24d22 100644 (file)
-#ifndef  APPVIEW_H
-# define APPVIEW_H
-
-# if !defined(WIN32) || defined(__GNUC__)
+/*
+ * ***** 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) 2010 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __APPVIEW_H__
+#define __APPVIEW_H__
+
+/** \file blender/freestyle/intern/application/AppView.h
+ *  \ingroup freestyle
+ */
+
+#if !defined(WIN32) || defined(__GNUC__)
 #  include <algorithm>
-using namespace std;
 #  define __min(x,y) (min(x,y))
 #  define __max(x,y) (max(x,y))
-# endif // WIN32
+   using namespace std;
+#endif // WIN32
 
-# include "../geometry/Geom.h"
-# include "../geometry/BBox.h"
-# include "../scene_graph/NodeDrawingStyle.h"
-# include "../system/Precision.h"
-# include "AppConfig.h"
+#include "AppConfig.h"
+#include "../geometry/Geom.h"
+#include "../geometry/BBox.h"
+#include "../scene_graph/NodeDrawingStyle.h"
+#include "../system/Precision.h"
 
 using namespace Geometry;
+
 class AppView
 {
-
 public:
+       AppView(const char *iName = 0);
+       virtual ~AppView();
 
-  AppView(const char *iName = 0);
-  virtual ~AppView();
-  
 public:
-
        //inherited
-               inline unsigned int width() { return _width; }
-               inline unsigned int height() { return _height; }
-               inline BBox<Vec2i> border() { return _border; }
-               inline float thickness() { return _thickness; }
-               inline void setWidth( unsigned int width ) { _width = width; }
-               inline void setHeight( unsigned int height ) { _height = height; }
-               inline void setBorder( int xmin, int ymin, int xmax, int ymax ) {
-                       _border = BBox<Vec2i>(Vec2i(xmin, ymin), Vec2i(xmax, ymax));
-               }
-               inline void setThickness( float thickness ) { _thickness = thickness; }
-               
+       inline unsigned int width() {return _width;}
+       inline unsigned int height() {return _height;}
+       inline BBox<Vec2i> border() {return _border;}
+       inline float thickness() {return _thickness;}
+       inline void setWidth(unsigned int width) {_width = width;}
+       inline void setHeight(unsigned int height) {_height = height;}
+       inline void setBorder(int xmin, int ymin, int xmax, int ymax) {
+               _border = BBox<Vec2i>(Vec2i(xmin, ymin), Vec2i(xmax, ymax));
+       }
+       inline void setThickness(float thickness) {_thickness = thickness;}
+
 protected:
        unsigned int _width, _height;
        BBox<Vec2i> _border;
        float _thickness;
 
 public:
+       /*! Sets the model to draw in the viewer
+        *  iModel
+        *    The Root Node of the model
+        */
+       inline void setModel(NodeGroup *iModel)
+       {
+               if (0 != _ModelRootNode->numberOfChildren()) {
+                       _ModelRootNode->DetachChildren();
+                       _ModelRootNode->clearBBox();
+               }
 
-  /*! Sets the model to draw in the viewer 
-   *  iModel
-   *    The Root Node of the model 
-   */
-  inline void setModel(NodeGroup *iModel)
-  {
-    if(0 != _ModelRootNode->numberOfChildren())
-    {
-      _ModelRootNode->DetachChildren();
-      _ModelRootNode->clearBBox();
-    }
-      
-    AddModel(iModel);
-  }
-
-  /*! Adds a model for displaying in the viewer */
-  inline void AddModel(NodeGroup *iModel) 
-  {
-    _ModelRootNode->AddChild(iModel);
-    
-    _ModelRootNode->UpdateBBox();
-
-    _minBBox = __min(__min(_ModelRootNode->bbox().getMin()[0], 
-                            _ModelRootNode->bbox().getMin()[1]),
-                      _ModelRootNode->bbox().getMin()[2]);
-    _maxBBox = __max(__max(_ModelRootNode->bbox().getMax()[0], 
-                            _ModelRootNode->bbox().getMax()[1]),
-                      _ModelRootNode->bbox().getMax()[2]);
-    
-     _maxAbs = __max(rabs(_minBBox), rabs(_maxBBox));
-
-     _minAbs = __min(rabs(_minBBox), rabs(_maxBBox));
-  }
-
-  inline void AddSilhouette(NodeGroup* iSilhouette)
-  {
-    _SilhouetteRootNode->AddChild(iSilhouette);
-  }
-
-  inline void Add2DSilhouette(NodeGroup *iSilhouette)
-  {
-    //_pFENode->AddChild(iSilhouette);
-  }
-
-  inline void Add2DVisibleSilhouette(NodeGroup *iVSilhouette)
-  {
-    //_pVisibleSilhouetteNode->AddChild(iVSilhouette);
-  }
-
-  inline void setDebug(NodeGroup* iDebug)
-  {
-    if(0 != _DebugRootNode->numberOfChildren())
-    {
-      _DebugRootNode->DetachChildren();
-      _DebugRootNode->clearBBox();
-    }
-      
-    AddDebug(iDebug);
-  }
-
-  inline void AddDebug(NodeGroup* iDebug)
-  {
-    _DebugRootNode->AddChild(iDebug);
-  }
-
-  inline void DetachModel(Node *iModel)
-  {
-    _ModelRootNode->DetachChild(iModel);
-    _ModelRootNode->UpdateBBox();
-    
-    _minBBox = __min(__min(_ModelRootNode->bbox().getMin()[0], 
-                            _ModelRootNode->bbox().getMin()[1]),
-                      _ModelRootNode->bbox().getMin()[2]);
-    _maxBBox = __max(__max(_ModelRootNode->bbox().getMax()[0], 
-                            _ModelRootNode->bbox().getMax()[1]),
-                      _ModelRootNode->bbox().getMax()[2]);
-    
-     _maxAbs = __max(rabs(_minBBox), rabs(_maxBBox));
-     _minAbs = __min(rabs(_minBBox), rabs(_maxBBox));
-  } 
-
-  inline void DetachModel() 
-  {
-    _ModelRootNode->DetachChildren();
-    _ModelRootNode->clearBBox();
-    
-    // 2D Scene
-    //_p2DNode.DetachChildren();
-    //_pFENode->DetachChildren();
-    //_pVisibleSilhouetteNode->DetachChildren();
-    
-  }
-
-  inline void DetachSilhouette()
-  {
-    _SilhouetteRootNode->DetachChildren();
-    //_pFENode->DetachChildren();
-    //_pVisibleSilhouetteNode->DetachChildren();
-    _p2DSelectionNode->destroy();
-  }
-
-  inline void DetachVisibleSilhouette()
-  {
-    //_pVisibleSilhouetteNode->DetachChildren();
-    _p2DSelectionNode->destroy();
-  }
-
-  inline void DetachDebug()
-  {
-    _DebugRootNode->DetachChildren();
-  }
-
-       
+               AddModel(iModel);
+       }
+
+       /*! Adds a model for displaying in the viewer */
+       inline void AddModel(NodeGroup *iModel)
+       {
+               _ModelRootNode->AddChild(iModel);
+               _ModelRootNode->UpdateBBox();
+
+               _minBBox = __min(__min(_ModelRootNode->bbox().getMin()[0], _ModelRootNode->bbox().getMin()[1]),
+                                _ModelRootNode->bbox().getMin()[2]);
+               _maxBBox = __max(__max(_ModelRootNode->bbox().getMax()[0], _ModelRootNode->bbox().getMax()[1]),
+                                _ModelRootNode->bbox().getMax()[2]);
+
+               _maxAbs = __max(rabs(_minBBox), rabs(_maxBBox));
+               _minAbs = __min(rabs(_minBBox), rabs(_maxBBox));
+       }
+
+       inline void AddSilhouette(NodeGroup* iSilhouette)
+       {
+               _SilhouetteRootNode->AddChild(iSilhouette);
+       }
+
+       inline void Add2DSilhouette(NodeGroup *iSilhouette)
+       {
+               //_pFENode->AddChild(iSilhouette);
+       }
+
+       inline void Add2DVisibleSilhouette(NodeGroup *iVSilhouette)
+       {
+               //_pVisibleSilhouetteNode->AddChild(iVSilhouette);
+       }
+
+       inline void setDebug(NodeGroup* iDebug)
+       {
+               if (0 != _DebugRootNode->numberOfChildren()) {
+                       _DebugRootNode->DetachChildren();
+                       _DebugRootNode->clearBBox();
+               }
+
+               AddDebug(iDebug);
+       }
+
+       inline void AddDebug(NodeGroup* iDebug)
+       {
+               _DebugRootNode->AddChild(iDebug);
+       }
+
+       inline void DetachModel(Node *iModel)
+       {
+               _ModelRootNode->DetachChild(iModel);
+               _ModelRootNode->UpdateBBox();
+
+               _minBBox = __min(__min(_ModelRootNode->bbox().getMin()[0], _ModelRootNode->bbox().getMin()[1]),
+                                _ModelRootNode->bbox().getMin()[2]);
+               _maxBBox = __max(__max(_ModelRootNode->bbox().getMax()[0], _ModelRootNode->bbox().getMax()[1]),
+                                _ModelRootNode->bbox().getMax()[2]);
+
+               _maxAbs = __max(rabs(_minBBox), rabs(_maxBBox));
+               _minAbs = __min(rabs(_minBBox), rabs(_maxBBox));
+       }
+
+       inline void DetachModel()
+       {
+               _ModelRootNode->DetachChildren();
+               _ModelRootNode->clearBBox();
+
+#if 0
+               // 2D Scene
+               _p2DNode.DetachChildren();
+               _pFENode->DetachChildren();
+               _pVisibleSilhouetteNode->DetachChildren();
+#endif
+       }
+
+       inline void DetachSilhouette()
+       {
+               _SilhouetteRootNode->DetachChildren();
+#if 0
+               _pFENode->DetachChildren();
+               _pVisibleSilhouetteNode->DetachChildren();
+#endif
+               _p2DSelectionNode->destroy();
+       }
+
+       inline void DetachVisibleSilhouette()
+       {
+               //_pVisibleSilhouetteNode->DetachChildren();
+               _p2DSelectionNode->destroy();
+       }
+
+       inline void DetachDebug()
+       {
+               _DebugRootNode->DetachChildren();
+       }
 
        real distanceToSceneCenter();
        real GetFocalLength();
 
-  inline real GetAspect() const
-  {
-    return ((real) _width/(real) _height);
-  }
+       inline real GetAspect() const
+       {
+               return ((real)_width / (real)_height);
+       }
 
-  void setHorizontalFov( float hfov ) 
-{
-       _Fovy = 2.0 * atan (tan(hfov / 2.0) / GetAspect());
-}
-  inline real GetFovyRadian() const
-  {
-    return _Fovy;
-  }
+       void setHorizontalFov(float hfov)
+       {
+               _Fovy = 2.0 * atan (tan(hfov / 2.0) / GetAspect());
+       }
+
+       inline real GetFovyRadian() const
+       {
+               return _Fovy;
+       }
 
-  inline real GetFovyDegrees() const
-  {
-    return _Fovy * 180.0 / M_PI;
-  }
+       inline real GetFovyDegrees() const
+       {
+               return _Fovy * 180.0 / M_PI;  // TODO Use RAD2DEG here too?
+       }
 
-  BBox<Vec3r> scene3DBBox() const { return _ModelRootNode->bbox(); }
+       BBox<Vec3r> scene3DBBox() const {return _ModelRootNode->bbox();}
 
        real znear();
        real zfar();
 
-
 public:
-  /*! Core scene drawing */
-  void            DrawScene(SceneVisitor *iRenderer);
+       /*! Core scene drawing */
+       void DrawScene(SceneVisitor *iRenderer);
 
-  /*! 2D Scene Drawing */
-  void            Draw2DScene(SceneVisitor *iRenderer);
+       /*! 2D Scene Drawing */
+       void Draw2DScene(SceneVisitor *iRenderer);
 
-  
 protected:
+       /*! fabs or abs */
+       inline int rabs(int x) {return abs(x);}
+       inline real rabs(real x) {return fabs(x);}
 
-  /*! fabs or abs */
-  inline int rabs(int x) {return abs(x);}
-  inline real rabs(real x) {return fabs(x);}
-
-  
 protected:
-  float _Fovy;
-
-  //The root node container
-  NodeGroup        _RootNode;
-  NodeDrawingStyle *_ModelRootNode;
-  NodeDrawingStyle *_SilhouetteRootNode;
-  NodeDrawingStyle *_DebugRootNode;
-  NodeGroup _Light;
-
-  real _minBBox;
-  real _maxBBox;
-  real _maxAbs;
-  real _minAbs;
-
-  // 2D Scene
-  bool _Draw2DScene;
-  bool _Draw3DScene;  NodeGroup _p2DNode;
-  NodeDrawingStyle *_p2DSelectionNode;
-
+       float _Fovy;
+
+       //The root node container
+       NodeGroup         _RootNode;
+       NodeDrawingStyle *_ModelRootNode;
+       NodeDrawingStyle *_SilhouetteRootNode;
+       NodeDrawingStyle *_DebugRootNode;
+
+       NodeGroup _Light;
+
+       real _minBBox;
+       real _maxBBox;
+       real _maxAbs;
+       real _minAbs;
+
+       // 2D Scene
+       bool _Draw2DScene;
+       bool _Draw3DScene;
+       NodeGroup _p2DNode;
+       NodeDrawingStyle *_p2DSelectionNode;
 };
 
-#endif // APPVIEW_H
+#endif // __APPVIEW_H__
index e9961602f03ae064b8431e34f32b25d0f088f865..a8bc4cf2987bf27e4b9d7395a231b8581c25651e 100644 (file)
@@ -1,26 +1,33 @@
-
-//
-//  Copyright (C) : Please refer to the COPYRIGHT file distributed 
-//   with this source distribution. 
-//
-//  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.
-//
-///////////////////////////////////////////////////////////////////////////////
-
-// Must be included before any QT header, because of moc
-#include "../system/PythonInterpreter.h"
+/*
+ * ***** 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) 2010 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/freestyle/intern/application/Controller.cpp
+ *  \ingroup freestyle
+ */
 
 #include <string>
 #include <fstream>
 #include "AppView.h"
 #include "AppCanvas.h"
 #include "AppConfig.h"
+#include "Controller.h"
 
+#include "../image/Image.h"
 
-#include "../system/StringUtils.h"
+#include "../scene_graph/NodeDrawingStyle.h"
 #include "../scene_graph/NodeShape.h"
 #include "../scene_graph/NodeTransform.h"
-#include "../scene_graph/NodeDrawingStyle.h"
-#include "../winged_edge/WingedEdgeBuilder.h"
-#include "../winged_edge/WEdge.h"
-#include "../scene_graph/VertexRep.h"
-#include "../winged_edge/WXEdgeBuilder.h"
 #include "../scene_graph/ScenePrettyPrinter.h"
+#include "../scene_graph/VertexRep.h"
 
-#include "../view_map/ViewMapTesselator.h"
-#include "../stroke/StrokeTesselator.h"
-#include "../view_map/ViewMapIO.h"
-#include "Controller.h"
-#include "../view_map/ViewMap.h"
-#include "../winged_edge/Curvature.h"
-#include "../image/Image.h"
-#include "../view_map/SteerableViewMap.h"
 #include "../stroke/PSStrokeRenderer.h"
 #include "../stroke/TextStrokeRenderer.h"
+#include "../stroke/StrokeTesselator.h"
 #include "../stroke/StyleModule.h"
 
 #include "../system/StringUtils.h"
+#include "../system/PythonInterpreter.h"
+
+#include "../view_map/SteerableViewMap.h"
+#include "../view_map/ViewMap.h"
+#include "../view_map/ViewMapIO.h"
+#include "../view_map/ViewMapTesselator.h"
+
+#include "../winged_edge/Curvature.h"
+#include "../winged_edge/WEdge.h"
+#include "../winged_edge/WingedEdgeBuilder.h"
+#include "../winged_edge/WXEdgeBuilder.h"
 
 #include "../blender_interface/BlenderFileLoader.h"
 #include "../blender_interface/BlenderStrokeRenderer.h"
 #include "../blender_interface/BlenderStyleModule.h"
 
+// XXX Not inside an "extern C" block???
 #include "DNA_freestyle_types.h"
 
+// XXX Are those "ifdef __cplusplus" useful here?
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-       #include "../../FRS_freestyle.h"
+#include "FRS_freestyle.h"
 
 #ifdef __cplusplus
 }
 #endif
 
-
-
 Controller::Controller()
 {
-       
-  const string sep(Config::DIR_SEP.c_str());
-  //const string filename = Config::Path::getInstance()->getHomeDir() + sep + Config::OPTIONS_DIR + sep + Config::OPTIONS_CURRENT_DIRS_FILE;
-  //_current_dirs = new ConfigIO(filename, Config::APPLICATION_NAME + "CurrentDirs", true);
-
-  _RootNode = new NodeGroup;
-  _RootNode->addRef();
-  
-  _SilhouetteNode = NULL;
-  //_ProjectedSilhouette = NULL;
-  //_VisibleProjectedSilhouette = NULL;
-  
-  _DebugNode = new NodeGroup;
-  _DebugNode->addRef();
-
-  _winged_edge = NULL;
-  
-  _pView = NULL;
-  _pRenderMonitor = NULL;
-
-  _edgeTesselationNature = (Nature::SILHOUETTE | Nature::BORDER | Nature::CREASE);
-
-  _ProgressBar = new ProgressBar;
-  _SceneNumFaces = 0;
-  _minEdgeSize = DBL_MAX;
-  _EPSILON = 1e-6;
-  _bboxDiag = 0;
-  
-  _ViewMap = 0;
-
-  _Canvas = 0;
-
-  _VisibilityAlgo = ViewMapBuilder::ray_casting_adaptive_traditional;
-  //_VisibilityAlgo = ViewMapBuilder::ray_casting;
-
-  _Canvas = new AppCanvas;
-
-  _inter = new PythonInterpreter();
-  _EnableQI = true;
-  _EnableFaceSmoothness = false;
-  _ComputeRidges = true;
-  _ComputeSteerableViewMap = false;
-  _ComputeSuggestive = true;
-  _ComputeMaterialBoundaries = true;
-  _sphereRadius = 1.0;
-  _creaseAngle = 134.43;
+       const string sep(Config::DIR_SEP.c_str());
+#if 0
+       const string filename = Config::Path::getInstance()->getHomeDir() + sep + Config::OPTIONS_DIR + sep +
+                               Config::OPTIONS_CURRENT_DIRS_FILE;
+       _current_dirs = new ConfigIO(filename, Config::APPLICATION_NAME + "CurrentDirs", true);
+#endif
+
+       _RootNode = new NodeGroup;
+       _RootNode->addRef();
+
+       _SilhouetteNode = NULL;
+#if 0
+       _ProjectedSilhouette = NULL;
+       _VisibleProjectedSilhouette = NULL;
+#endif
+
+       _DebugNode = new NodeGroup;
+       _DebugNode->addRef();
+
+       _winged_edge = NULL;
+
+       _pView = NULL;
+       _pRenderMonitor = NULL;
+
+       _edgeTesselationNature = (Nature::SILHOUETTE | Nature::BORDER | Nature::CREASE);
+
+       _ProgressBar = new ProgressBar;
+       _SceneNumFaces = 0;
+       _minEdgeSize = DBL_MAX;
+       _EPSILON = 1.0e-6;
+       _bboxDiag = 0;
+
+       _ViewMap = 0;
+
+       _Canvas = 0;
+
+       _VisibilityAlgo = ViewMapBuilder::ray_casting_adaptive_traditional;
+       //_VisibilityAlgo = ViewMapBuilder::ray_casting;
+
+       _Canvas = new AppCanvas;
+
+       _inter = new PythonInterpreter();
+       _EnableQI = true;
+       _EnableFaceSmoothness = false;
+       _ComputeRidges = true;
+       _ComputeSteerableViewMap = false;
+       _ComputeSuggestive = true;
+       _ComputeMaterialBoundaries = true;
+       _sphereRadius = 1.0;
+       _creaseAngle = 134.43;
 
        init_options();
 }
 
 Controller::~Controller()
 {
-  if(NULL != _RootNode)
-    {
-      int ref = _RootNode->destroy();
-      if(0 == ref)
-       delete _RootNode;
-    }
-  
-  if(NULL != _SilhouetteNode)
-    {
-      int ref = _SilhouetteNode->destroy();
-      if(0 == ref)
-       delete _SilhouetteNode;
-    }
-  
-  if(NULL != _DebugNode)
-    {
-      int ref = _DebugNode->destroy();
-      if(0 == ref)
-       delete _DebugNode;
-    }
-
-  if(_winged_edge) {
-    delete _winged_edge;
-    _winged_edge = NULL;
-  }
-
-  if(0 != _ViewMap)
-    {
-      delete _ViewMap;
-      _ViewMap = 0;
-    }
-
-  if(0 != _Canvas)
-    {
-      delete _Canvas;
-      _Canvas = 0;
-    }
-
-  if (_inter) {
-    delete _inter;
-    _inter = NULL;
-  }
-
-  //delete _current_dirs;
+       if (NULL != _RootNode) {
+               int ref = _RootNode->destroy();
+               if (0 == ref)
+                       delete _RootNode;
+       }
+
+       if (NULL != _SilhouetteNode) {
+               int ref = _SilhouetteNode->destroy();
+               if (0 == ref)
+                       delete _SilhouetteNode;
+       }
+
+       if (NULL != _DebugNode) {
+               int ref = _DebugNode->destroy();
+               if (0 == ref)
+                       delete _DebugNode;
+       }
+
+       if (_winged_edge) {
+               delete _winged_edge;
+               _winged_edge = NULL;
+       }
+
+       if (0 != _ViewMap) {
+               delete _ViewMap;
+               _ViewMap = 0;
+       }
+
+       if (0 != _Canvas) {
+               delete _Canvas;
+               _Canvas = 0;
+       }
+
+       if (_inter) {
+               delete _inter;
+               _inter = NULL;
+       }
+
+       //delete _current_dirs;
 }
 
 void Controller::setView(AppView *iView)
 {
-  if(NULL == iView)
-    return;
-  
-  _pView = iView;
-  _Canvas->setViewer(_pView);
+       if(NULL == iView)
+               return;
+
+       _pView = iView;
+       _Canvas->setViewer(_pView);
 }
 
 void Controller::setRenderMonitor(RenderMonitor *iRenderMonitor)
 {
-  _pRenderMonitor = iRenderMonitor;
+       _pRenderMonitor = iRenderMonitor;
 }
 
 void Controller::setPassDiffuse(float *buf, int width, int height)
 {
-  AppCanvas *app_canvas = dynamic_cast<AppCanvas *>(_Canvas);
-  assert(app_canvas != 0);
-  app_canvas->setPassDiffuse(buf, width, height);
+       AppCanvas *app_canvas = dynamic_cast<AppCanvas *>(_Canvas);
+       assert(app_canvas != 0);
+       app_canvas->setPassDiffuse(buf, width, height);
 }
 
 void Controller::setPassZ(float *buf, int width, int height)
 {
-  AppCanvas *app_canvas = dynamic_cast<AppCanvas *>(_Canvas);
-  assert(app_canvas != 0);
-  app_canvas->setPassZ(buf, width, height);
+       AppCanvas *app_canvas = dynamic_cast<AppCanvas *>(_Canvas);
+       assert(app_canvas != 0);
+       app_canvas->setPassZ(buf, width, height);
 }
 
 void Controller::setContext(bContext *C)
 {
-  PythonInterpreter* py_inter = dynamic_cast<PythonInterpreter*>(_inter);
-  assert(py_inter != 0);
-  py_inter->setContext(C);
+       PythonInterpreter* py_inter = dynamic_cast<PythonInterpreter*>(_inter);
+       assert(py_inter != 0);
+       py_inter->setContext(C);
 }
 
 int Controller::LoadMesh(Render *re, SceneRenderLayer* srl)
 {
-  
-  BlenderFileLoader loader(re, srl);
+       BlenderFileLoader loader(re, srl);
+
+       loader.setRenderMonitor(_pRenderMonitor);
 
-  loader.setRenderMonitor(_pRenderMonitor);
-  
-  _Chrono.start();
-  
-  NodeGroup *blenderScene = loader.Load();
+       _Chrono.start();
+
+       NodeGroup *blenderScene = loader.Load();
 
-  if (blenderScene == NULL) {
-       cout << "Cannot load scene" << endl;
-    return 1;
-  }
+       if (blenderScene == NULL) {
+               cout << "Cannot load scene" << endl;
+               return 1;
+       }
 
-       ifblenderScene->numberOfChildren() < 1) {
+       if (blenderScene->numberOfChildren() < 1) {
                cout << "Empty scene" << endl;
                blenderScene->destroy();
                delete blenderScene;
                return 1;
        }
 
-         cout << "Scene loaded" << endl;
-  printf("Mesh cleaning    : %lf\n", _Chrono.stop());
-  _SceneNumFaces += loader.numFacesRead();
+       cout << "Scene loaded" << endl;
+       printf("Mesh cleaning    : %lf\n", _Chrono.stop());
+       _SceneNumFaces += loader.numFacesRead();
 
-  if(loader.minEdgeSize() < _minEdgeSize)
-    {
-      _minEdgeSize = loader.minEdgeSize();
-    }
+       if (loader.minEdgeSize() < _minEdgeSize) {
+               _minEdgeSize = loader.minEdgeSize();
+       }
 
-  // DEBUG
-  // ScenePrettyPrinter spp;
-  // blenderScene->accept(spp);
-       
-  _RootNode->AddChild(blenderScene);
-  _RootNode->UpdateBBox(); // FIXME: Correct that by making a Renderer to compute the bbox
+#if 0  // DEBUG
+       ScenePrettyPrinter spp;
+       blenderScene->accept(spp);
+#endif
 
-  _pView->setModel(_RootNode);
-  //_pView->FitBBox();
+       _RootNode->AddChild(blenderScene);
+       _RootNode->UpdateBBox(); // FIXME: Correct that by making a Renderer to compute the bbox
 
-  if (_pRenderMonitor->testBreak())
-    return 0;
+       _pView->setModel(_RootNode);
+       //_pView->FitBBox();
 
+       if (_pRenderMonitor->testBreak())
+               return 0;
 
-  _Chrono.start();
+       _Chrono.start();
 
-  
-  WXEdgeBuilder wx_builder;
-  wx_builder.setRenderMonitor(_pRenderMonitor);
-  blenderScene->accept(wx_builder);
-  _winged_edge = wx_builder.getWingedEdge();
+       WXEdgeBuilder wx_builder;
+       wx_builder.setRenderMonitor(_pRenderMonitor);
+       blenderScene->accept(wx_builder);
+       _winged_edge = wx_builder.getWingedEdge();
 
-  printf("WEdge building   : %lf\n", _Chrono.stop());
+       printf("WEdge building   : %lf\n", _Chrono.stop());
 
-  //  
-  // _pView->setDebug(_DebugNode);
+#if 0
+       _pView->setDebug(_DebugNode);
 
-  //delete stuff
-  //  if(0 != ws_builder)
-  //    {
-  //      delete ws_builder;
-  //      ws_builder = 0;
-  //    }
+       // delete stuff
+       if (0 != ws_builder) {
+               delete ws_builder;
+               ws_builder = 0;
+       }
 
-       //soc QFileInfo qfi(iFileName);
-       //soc string basename((const char*)qfi.fileName().toAscii().data());
-       // char cleaned[FILE_MAX];
-       // BLI_strncpy(cleaned, iFileName, FILE_MAX);
-       // BLI_cleanup_file(NULL, cleaned);
-       // string basename = StringUtils::toAscii( string(cleaned) );
+       soc QFileInfo qfi(iFileName);
+       soc string basename((const char*)qfi.fileName().toAscii().data());
+       char cleaned[FILE_MAX];
+       BLI_strncpy(cleaned, iFileName, FILE_MAX);
+       BLI_cleanup_file(NULL, cleaned);
+       string basename = StringUtils::toAscii(string(cleaned));
+#endif
 
-  _ListOfModels.push_back("Blender_models");
+       _ListOfModels.push_back("Blender_models");
 
-  cout << "Triangles nb     : " << _SceneNumFaces << endl;
-  _bboxDiag = (_RootNode->bbox().getMax()-_RootNode->bbox().getMin()).norm();
-  cout << "Bounding Box     : " << _bboxDiag << endl;
+       cout << "Triangles nb     : " << _SceneNumFaces << endl;
+       _bboxDiag = (_RootNode->bbox().getMax()-_RootNode->bbox().getMin()).norm();
+       cout << "Bounding Box     : " << _bboxDiag << endl;
 
-  ClearRootNode();
+       ClearRootNode();
 
-  return 0;
+       return 0;
 }
 
 void Controller::CloseFile()
 {
-  WShape::setCurrentId(0);
-  _ListOfModels.clear();
+       WShape::setCurrentId(0);
+       _ListOfModels.clear();
 
-  // We deallocate the memory:
-  ClearRootNode();
-  DeleteWingedEdge();
-  DeleteViewMap();
+       // We deallocate the memory:
+       ClearRootNode();
+       DeleteWingedEdge();
+       DeleteViewMap();
 
-  // clears the canvas
-  _Canvas->Clear();
+       // clears the canvas
+       _Canvas->Clear();
 
-  // soc: reset passes
-  setPassDiffuse(NULL, 0, 0);
-  setPassZ(NULL, 0, 0);
+       // soc: reset passes
+       setPassDiffuse(NULL, 0, 0);
+       setPassZ(NULL, 0, 0);
 }
 
 void Controller::ClearRootNode()
 {
        _pView->DetachModel();
-       if(NULL != _RootNode)
-       {
+       if (NULL != _RootNode) {
                int ref = _RootNode->destroy();
-               if(0 == ref)
+               if (0 == ref)
                        _RootNode->addRef();
                _RootNode->clearBBox();
        }
@@ -324,8 +328,7 @@ void Controller::ClearRootNode()
 
 void Controller::DeleteWingedEdge()
 {
-       if(_winged_edge)
-       {
+       if (_winged_edge) {
                delete _winged_edge;
                _winged_edge = NULL;
        }
@@ -339,115 +342,108 @@ void Controller::DeleteWingedEdge()
 void Controller::DeleteViewMap()
 {
        _pView->DetachSilhouette();
-       if (NULL != _SilhouetteNode)
-       {
+       if (NULL != _SilhouetteNode) {
                int ref = _SilhouetteNode->destroy();
-               if(0 == ref) {
+               if (0 == ref) {
                        delete _SilhouetteNode;
                        _SilhouetteNode = NULL;
                }
        }
 
-  //  if(NULL != _ProjectedSilhouette)
-  //    {
-  //      int ref = _ProjectedSilhouette->destroy();
-  //      if(0 == ref)
-  //   {
-  //     delete _ProjectedSilhouette;
-  //     _ProjectedSilhouette = NULL;
-  //   }
-  //    }
-  //  if(NULL != _VisibleProjectedSilhouette)
-  //    {
-  //      int ref = _VisibleProjectedSilhouette->destroy();
-  //      if(0 == ref)
-  //   {
-  //     delete _VisibleProjectedSilhouette;
-  //     _VisibleProjectedSilhouette = NULL;
-  //   }
-  //  }  
+#if 0
+       if (NULL != _ProjectedSilhouette) {
+               int ref = _ProjectedSilhouette->destroy();
+               if (0 == ref) {
+                       delete _ProjectedSilhouette;
+                       _ProjectedSilhouette = NULL;
+               }
+       }
+       if (NULL != _VisibleProjectedSilhouette) {
+               int ref = _VisibleProjectedSilhouette->destroy();
+               if (0 == ref) {
+                       delete _VisibleProjectedSilhouette;
+                       _VisibleProjectedSilhouette = NULL;
+               }
+       }
+#endif
 
        _pView->DetachDebug();
-       if(NULL != _DebugNode) {
-      int ref = _DebugNode->destroy();
-      if(0 == ref)
-                 _DebugNode->addRef();
-    }
+       if (NULL != _DebugNode) {
+       int ref = _DebugNode->destroy();
+               if (0 == ref)
+                       _DebugNode->addRef();
+       }
 
-       if(NULL != _ViewMap) {
-      delete _ViewMap;
-      _ViewMap = 0;
-    }
+       if (NULL != _ViewMap) {
+               delete _ViewMap;
+               _ViewMap = NULL;
+       }
 }
 
 void Controller::ComputeViewMap()
 {
+       if (!_ListOfModels.size())
+               return;
 
-  if (!_ListOfModels.size())
-    return;
-  
-  if(NULL != _ViewMap)
-    {
-      delete _ViewMap;
-      _ViewMap = 0;
-    }
-
-  _pView->DetachDebug();
-  if(NULL != _DebugNode)
-    {
-      int ref = _DebugNode->destroy();
-      if(0 == ref)
-       _DebugNode->addRef();
-    }
-  
-
-  _pView->DetachSilhouette();
-  if (NULL != _SilhouetteNode)
-    {
-      int ref = _SilhouetteNode->destroy();
-      if(0 == ref)
-       delete _SilhouetteNode;
-    }
-  //  if(NULL != _ProjectedSilhouette)
-  //    {
-  //      int ref = _ProjectedSilhouette->destroy();
-  //      if(0 == ref)
-  //   delete _ProjectedSilhouette;
-  //    }
-  //  if(NULL != _VisibleProjectedSilhouette)
-  //    {
-  //      int ref = _VisibleProjectedSilhouette->destroy();
-  //      if(0 == ref)
-  //   {
-  //     delete _VisibleProjectedSilhouette;
-  //     _VisibleProjectedSilhouette = 0;
-  //   }
-  //  }
-  
-  // retrieve the 3D viewpoint and transformations information
-  //----------------------------------------------------------
-  // Save the viewpoint context at the view level in order 
-  // to be able to restore it later:
-
-  // Restore the context of view:
-  // we need to perform all these operations while the 
-  // 3D context is on.
-  Vec3r vp( freestyle_viewpoint[0], freestyle_viewpoint[1], freestyle_viewpoint[2]);
+       if (NULL != _ViewMap) {
+               delete _ViewMap;
+               _ViewMap = NULL;
+       }
+
+       _pView->DetachDebug();
+       if (NULL != _DebugNode) {
+               int ref = _DebugNode->destroy();
+               if (0 == ref)
+                       _DebugNode->addRef();
+       }
+
+       _pView->DetachSilhouette();
+       if (NULL != _SilhouetteNode) {
+               int ref = _SilhouetteNode->destroy();
+               if (0 == ref)
+                       delete _SilhouetteNode;
+       }
+
+#if 0
+       if (NULL != _ProjectedSilhouette) {
+               int ref = _ProjectedSilhouette->destroy();
+               if (0 == ref)
+                       delete _ProjectedSilhouette;
+       }
+
+       if (NULL != _VisibleProjectedSilhouette) {
+               int ref = _VisibleProjectedSilhouette->destroy();
+               if (0 == ref) {
+                       delete _VisibleProjectedSilhouette;
+                       _VisibleProjectedSilhouette = NULL;
+               }
+       }
+#endif
+
+       // retrieve the 3D viewpoint and transformations information
+       //----------------------------------------------------------
+       // Save the viewpoint context at the view level in order 
+       // to be able to restore it later:
+
+       // Restore the context of view:
+       // we need to perform all these operations while the 
+       // 3D context is on.
+       Vec3r vp(freestyle_viewpoint[0], freestyle_viewpoint[1], freestyle_viewpoint[2]);
 
        //cout << "mv" << endl;
-       real mv[4][4];
-       for( int i= 0; i < 4; i++) {
-               for( int j= 0; j < 4; j++) {
+       real mv[4][4];
+       for (int i = 0; i < 4; i++) {
+               for (int j = 0; j < 4; j++) {
                        mv[i][j] = freestyle_mv[i][j];
                        //cout << mv[i][j] << " ";
                }
-       //      cout << endl;
+               //cout << endl;
        }
-       
+
        //cout << "\nproj" << endl;
        real proj[4][4];
-       for( int i= 0; i < 4; i++) {
-               for( int j= 0; j < 4; j++) {
+       for (int i = 0; i < 4; i++) {
+               for (int j = 0; j < 4; j++) {
                        proj[i][j] = freestyle_proj[i][j];
                        //cout << proj[i][j] << " ";
                }
@@ -455,195 +451,207 @@ void Controller::ComputeViewMap()
        }
 
        int viewport[4];
-       for( int i= 0; i < 4; i++)
+       for (int i = 0; i < 4; i++)
                viewport[i] = freestyle_viewport[i];
-       
-       //cout << "\nfocal:" << _pView->GetFocalLength() << endl << endl;
 
+       //cout << "\nfocal:" << _pView->GetFocalLength() << endl << endl;
 
 
-  // Flag the WXEdge structure for silhouette edge detection:
-  //----------------------------------------------------------
+       // Flag the WXEdge structure for silhouette edge detection:
+       //----------------------------------------------------------
 
        cout << "\n===  Detecting silhouette edges  ===" << endl;
-  _Chrono.start();
-  edgeDetector.setViewpoint(Vec3r(vp));
-  edgeDetector.enableOrthographicProjection(proj[3][3] != 0.0);
-  edgeDetector.enableRidgesAndValleysFlag(_ComputeRidges);
-  edgeDetector.enableSuggestiveContours(_ComputeSuggestive);
-  edgeDetector.enableMaterialBoundaries(_ComputeMaterialBoundaries);
-  edgeDetector.enableFaceSmoothness(_EnableFaceSmoothness);
-  edgeDetector.setCreaseAngle(_creaseAngle);
-  edgeDetector.setSphereRadius(_sphereRadius);
-  edgeDetector.setSuggestiveContourKrDerivativeEpsilon(_suggestiveContourKrDerivativeEpsilon);
-  edgeDetector.setRenderMonitor(_pRenderMonitor);
-  edgeDetector.processShapes(*_winged_edge);
-
-  real duration = _Chrono.stop();
-  printf("Feature lines    : %lf\n", duration);
-
-  if (_pRenderMonitor->testBreak())
-    return;
-
-  // Builds the view map structure from the flagged WSEdge structure:
-  //----------------------------------------------------------
-  ViewMapBuilder vmBuilder;
-  vmBuilder.setEnableQI(_EnableQI);
-  vmBuilder.setViewpoint(Vec3r(vp));
-  vmBuilder.setTransform( mv, proj,viewport, _pView->GetFocalLength(), _pView->GetAspect(), _pView->GetFovyRadian());
-  vmBuilder.setFrustum(_pView->znear(), _pView->zfar());  
-  vmBuilder.setGrid(&_Grid);
-  vmBuilder.setRenderMonitor(_pRenderMonitor);
-  
-  // Builds a tesselated form of the silhouette for display purpose:
-  //---------------------------------------------------------------
-  ViewMapTesselator3D sTesselator3d;
-  //ViewMapTesselator2D sTesselator2d;
-  //sTesselator2d.setNature(_edgeTesselationNature);
-  sTesselator3d.setNature(_edgeTesselationNature);
-    
+       _Chrono.start();
+
+       edgeDetector.setViewpoint(Vec3r(vp));
+       edgeDetector.enableOrthographicProjection(proj[3][3] != 0.0);
+       edgeDetector.enableRidgesAndValleysFlag(_ComputeRidges);
+       edgeDetector.enableSuggestiveContours(_ComputeSuggestive);
+       edgeDetector.enableMaterialBoundaries(_ComputeMaterialBoundaries);
+       edgeDetector.enableFaceSmoothness(_EnableFaceSmoothness);
+       edgeDetector.setCreaseAngle(_creaseAngle);
+       edgeDetector.setSphereRadius(_sphereRadius);
+       edgeDetector.setSuggestiveContourKrDerivativeEpsilon(_suggestiveContourKrDerivativeEpsilon);
+       edgeDetector.setRenderMonitor(_pRenderMonitor);
+       edgeDetector.processShapes(*_winged_edge);
+
+       real duration = _Chrono.stop();
+       printf("Feature lines    : %lf\n", duration);
+
+       if (_pRenderMonitor->testBreak())
+               return;
+
+       // Builds the view map structure from the flagged WSEdge structure:
+       //----------------------------------------------------------
+       ViewMapBuilder vmBuilder;
+       vmBuilder.setEnableQI(_EnableQI);
+       vmBuilder.setViewpoint(Vec3r(vp));
+       vmBuilder.setTransform( mv, proj,viewport, _pView->GetFocalLength(), _pView->GetAspect(), _pView->GetFovyRadian());
+       vmBuilder.setFrustum(_pView->znear(), _pView->zfar());
+       vmBuilder.setGrid(&_Grid);
+       vmBuilder.setRenderMonitor(_pRenderMonitor);
+
+       // Builds a tesselated form of the silhouette for display purpose:
+       //---------------------------------------------------------------
+       ViewMapTesselator3D sTesselator3d;
+#if 0
+       ViewMapTesselator2D sTesselator2d;
+       sTesselator2d.setNature(_edgeTesselationNature);
+#endif
+       sTesselator3d.setNature(_edgeTesselationNature);
+
        cout << "\n===  Building the view map  ===" << endl;
-  _Chrono.start();
-  // Build View Map
-  _ViewMap = vmBuilder.BuildViewMap(*_winged_edge, _VisibilityAlgo, _EPSILON, _RootNode->bbox(), _SceneNumFaces);
-  _ViewMap->setScene3dBBox(_RootNode->bbox());
-  
-       printf("ViewMap edge count : %i\n", _ViewMap->viewedges_size() );
-
-  //Tesselate the 3D edges:
-  _SilhouetteNode = sTesselator3d.Tesselate(_ViewMap);
-  _SilhouetteNode->addRef();
-  
-  // Tesselate 2D edges
-  //  _ProjectedSilhouette = sTesselator2d.Tesselate(_ViewMap);
-  //  _ProjectedSilhouette->addRef();
-  
-  duration = _Chrono.stop();
-  printf("ViewMap building : %lf\n", duration);
-
-  
-  _pView->AddSilhouette(_SilhouetteNode);
-  //_pView->AddSilhouette(_WRoot);
-  //_pView->Add2DSilhouette(_ProjectedSilhouette);
-  //_pView->Add2DVisibleSilhouette(_VisibleProjectedSilhouette);  
-  _pView->AddDebug(_DebugNode);
-
-  // Draw the steerable density map:
-  //--------------------------------
-  if(_ComputeSteerableViewMap){
-    ComputeSteerableViewMap();
-  }
-  // Reset Style modules modification flags
-  resetModified(true);
-
-  DeleteWingedEdge();
-}
-
-void Controller::ComputeSteerableViewMap(){
-//soc
-  // if((!_Canvas) || (!_ViewMap))
-  //   return;
-  //   
-  // // Build 4 nodes containing the edges in the 4 directions
-  // NodeGroup *ng[Canvas::NB_STEERABLE_VIEWMAP];
-  // unsigned i;
-  // real c = 32.f/255.f; // see SteerableViewMap::readSteerableViewMapPixel() for information about this 32.
-  // for(i=0; i<Canvas::NB_STEERABLE_VIEWMAP; ++i){
-  //   ng[i] = new NodeGroup;
-  // }
-  // NodeShape *completeNS = new NodeShape;
-  // completeNS->material().setDiffuse(c,c,c,1);
-  // ng[Canvas::NB_STEERABLE_VIEWMAP-1]->AddChild(completeNS);
-  // SteerableViewMap * svm = _Canvas->getSteerableViewMap();
-  // svm->Reset();
-  // 
-  // ViewMap::fedges_container& fedges = _ViewMap->FEdges();
-  // LineRep * fRep;
-  // NodeShape *ns;
-  // for(ViewMap::fedges_container::iterator f=fedges.begin(), fend=fedges.end();
-  // f!=fend;
-  // ++f){
-  //   if((*f)->viewedge()->qi() != 0)
-  //     continue;
-  //   fRep = new LineRep((*f)->vertexA()->point2d(),(*f)->vertexB()->point2d()) ;
-  //   completeNS->AddRep(fRep); // add to the complete map anyway
-  //   double *oweights = svm->AddFEdge(*f);
-  //   for(i=0; i<Canvas::NB_STEERABLE_VIEWMAP-1; ++i){
-  //     ns = new NodeShape;
-  //     double wc = oweights[i]*c;
-  //     if(oweights[i] == 0)
-  //       continue;
-  //     ns->material().setDiffuse(wc, wc, wc, 1);
-  //     ns->AddRep(fRep);
-  //     ng[i]->AddChild(ns);
-  //   }
-  // }
-  // 
-  // GrayImage *img[Canvas::NB_STEERABLE_VIEWMAP];
-  // //#ifdef WIN32
-  // QGLBasicWidget offscreenBuffer(_pView, "SteerableViewMap", _pView->width(), _pView->height()); 
-  // QPixmap pm;
-  // QImage qimg;
-  // for(i=0; i<Canvas::NB_STEERABLE_VIEWMAP; ++i){
-  //   offscreenBuffer.AddNode(ng[i]);
-  //   //img[i] = new GrayImage(_pView->width(), _pView->height());
-  //   //offscreenBuffer.readPixels(0,0,_pView->width(), _pView->height(), img[i]->getArray());
-  //   pm = offscreenBuffer.renderPixmap(_pView->width(), _pView->height());
-  // 
-  //   if(pm.isNull())
-  //     cout << "BuildViewMap Warning: couldn't render the steerable ViewMap" << endl;
-  //   //pm.save(QString("steerable")+QString::number(i)+QString(".bmp"), "BMP");
-  //   // FIXME!! Lost of time !
-  //   qimg = pm.toImage();
-  //   // FIXME !! again!
-  //   img[i] = new GrayImage(_pView->width(), _pView->height());
-  //   for(unsigned y=0;y<img[i]->height();++y){
-  //     for(unsigned x=0;x<img[i]->width();++x){
-  //       //img[i]->setPixel(x,y,(float)qGray(qimg.pixel(x,y))/255.f);
-  //       img[i]->setPixel(x,y,(float)qGray(qimg.pixel(x,y)));
-  //       //        float c = qGray(qimg.pixel(x,y));
-  //       //        img[i]->setPixel(x,y,qGray(qimg.pixel(x,y)));
-  //     }
-  //   }
-  //   offscreenBuffer.DetachNode(ng[i]);
-  //   ng[i]->destroy();
-  //   delete ng[i];
-  //   // check
-  //   //    qimg = QImage(_pView->width(), _pView->height(), 32);
-  //   //    for(y=0;y<img[i]->height();++y){
-  //   //      for(unsigned x=0;x<img[i]->width();++x){
-  //   //        float v = img[i]->pixel(x,y);
-  //   //        qimg.setPixel(x,y,qRgb(v,v,v));
-  //   //      }
-  //   //    }
-  //   //    qimg.save(QString("newsteerable")+QString::number(i)+QString(".bmp"), "BMP");
-  // }
-  // 
-  // 
-  // svm->buildImagesPyramids(img,false,0,1.f);
-}
-
-void Controller::saveSteerableViewMapImages(){
-  SteerableViewMap * svm = _Canvas->getSteerableViewMap();
-  if(!svm){
-    cerr << "the Steerable ViewMap has not been computed yet" << endl;
-    return;
-  }
-  svm->saveSteerableViewMap();
-}
-
-void Controller::toggleVisibilityAlgo() 
-{
-  if(_VisibilityAlgo == ViewMapBuilder::ray_casting) {
-    _VisibilityAlgo = ViewMapBuilder::ray_casting_fast;
-  }
-  else if (_VisibilityAlgo == ViewMapBuilder::ray_casting_fast) {
-    _VisibilityAlgo = ViewMapBuilder::ray_casting_very_fast;
-  }
-  else {
-    _VisibilityAlgo = ViewMapBuilder::ray_casting;
-  }
+       _Chrono.start();
+       // Build View Map
+       _ViewMap = vmBuilder.BuildViewMap(*_winged_edge, _VisibilityAlgo, _EPSILON, _RootNode->bbox(), _SceneNumFaces);
+       _ViewMap->setScene3dBBox(_RootNode->bbox());
+
+       printf("ViewMap edge count : %i\n", _ViewMap->viewedges_size());
+
+       // Tesselate the 3D edges:
+       _SilhouetteNode = sTesselator3d.Tesselate(_ViewMap);
+       _SilhouetteNode->addRef();
+
+       // Tesselate 2D edges
+#if 0
+       _ProjectedSilhouette = sTesselator2d.Tesselate(_ViewMap);
+       _ProjectedSilhouette->addRef();
+#endif
+
+       duration = _Chrono.stop();
+       printf("ViewMap building : %lf\n", duration);
+
+       _pView->AddSilhouette(_SilhouetteNode);
+#if 0
+       _pView->AddSilhouette(_WRoot);
+       _pView->Add2DSilhouette(_ProjectedSilhouette);
+       _pView->Add2DVisibleSilhouette(_VisibleProjectedSilhouette);
+#endif
+       _pView->AddDebug(_DebugNode);
+
+       // Draw the steerable density map:
+       //--------------------------------
+       if (_ComputeSteerableViewMap) {
+               ComputeSteerableViewMap();
+       }
+       // Reset Style modules modification flags
+       resetModified(true);
+
+       DeleteWingedEdge();
+}
+
+void Controller::ComputeSteerableViewMap()
+{
+#if 0  //soc
+       if ((!_Canvas) || (!_ViewMap))
+               return;
+
+       // Build 4 nodes containing the edges in the 4 directions
+       NodeGroup *ng[Canvas::NB_STEERABLE_VIEWMAP];
+       unsigned i;
+       real c = 32.0f/255.0f; // see SteerableViewMap::readSteerableViewMapPixel() for information about this 32.
+       for (i = 0; i < Canvas::NB_STEERABLE_VIEWMAP; ++i) {
+               ng[i] = new NodeGroup;
+       }
+       NodeShape *completeNS = new NodeShape;
+       completeNS->material().setDiffuse(c,c,c,1);
+       ng[Canvas::NB_STEERABLE_VIEWMAP-1]->AddChild(completeNS);
+       SteerableViewMap * svm = _Canvas->getSteerableViewMap();
+       svm->Reset();
+
+       ViewMap::fedges_container& fedges = _ViewMap->FEdges();
+       LineRep * fRep;
+       NodeShape *ns;
+       for (ViewMap::fedges_container::iterator f = fedges.begin(), fend = fedges.end();
+            f != fend;
+            ++f)
+       {
+               if ((*f)->viewedge()->qi() != 0)
+                       continue;
+               fRep = new LineRep((*f)->vertexA()->point2d(), (*f)->vertexB()->point2d());
+               completeNS->AddRep(fRep); // add to the complete map anyway
+               double *oweights = svm->AddFEdge(*f);
+               for (i = 0; i < (Canvas::NB_STEERABLE_VIEWMAP - 1); ++i) {
+                       ns = new NodeShape;
+                       double wc = oweights[i]*c;
+                       if (oweights[i] == 0)
+                               continue;
+                       ns->material().setDiffuse(wc, wc, wc, 1);
+                       ns->AddRep(fRep);
+                       ng[i]->AddChild(ns);
+               }
+       }
+
+       GrayImage *img[Canvas::NB_STEERABLE_VIEWMAP];
+       //#ifdef WIN32
+       QGLBasicWidget offscreenBuffer(_pView, "SteerableViewMap", _pView->width(), _pView->height());
+       QPixmap pm;
+       QImage qimg;
+       for (i = 0; i < Canvas::NB_STEERABLE_VIEWMAP; ++i) {
+               offscreenBuffer.AddNode(ng[i]);
+#if 0
+               img[i] = new GrayImage(_pView->width(), _pView->height());
+               offscreenBuffer.readPixels(0,0,_pView->width(), _pView->height(), img[i]->getArray());
+#endif
+               pm = offscreenBuffer.renderPixmap(_pView->width(), _pView->height());
+
+               if (pm.isNull())
+                       cout << "BuildViewMap Warning: couldn't render the steerable ViewMap" << endl;
+               //pm.save(QString("steerable") + QString::number(i) + QString(".bmp"), "BMP");
+               // FIXME!! Lost of time !
+               qimg = pm.toImage();
+               // FIXME !! again!
+               img[i] = new GrayImage(_pView->width(), _pView->height());
+               for (unsigned int y = 0; y < img[i]->height(); ++y) {
+                       for(unsigned int x = 0; x < img[i]->width(); ++x) {
+                               //img[i]->setPixel(x, y, (float)qGray(qimg.pixel(x, y)) / 255.0f);
+                               img[i]->setPixel(x, y, (float)qGray(qimg.pixel(x, y)));
+                               //float c = qGray(qimg.pixel(x, y));
+                               //img[i]->setPixel(x, y, qGray(qimg.pixel(x, y)));
+                       }
+               }
+               offscreenBuffer.DetachNode(ng[i]);
+               ng[i]->destroy();
+               delete ng[i];
+               // check
+#if 0
+               qimg = QImage(_pView->width(), _pView->height(), 32);
+               for (unsigned int y = 0; y < img[i]->height(); ++y) {
+                       for(unsigned int x = 0; x < img[i]->width(); ++x) {
+                               float v = img[i]->pixel(x, y);
+                               qimg.setPixel(x, y, qRgb(v, v, v));
+                       }
+               }
+               qimg.save(QString("newsteerable") + QString::number(i) + QString(".bmp"), "BMP");
+#endif
+       }
+
+
+       svm->buildImagesPyramids(img, false, 0, 1.0f);
+#endif
+}
+
+void Controller::saveSteerableViewMapImages()
+{
+       SteerableViewMap * svm = _Canvas->getSteerableViewMap();
+       if (!svm) {
+               cerr << "the Steerable ViewMap has not been computed yet" << endl;
+               return;
+       }
+       svm->saveSteerableViewMap();
+}
+
+void Controller::toggleVisibilityAlgo()
+{
+       if (_VisibilityAlgo == ViewMapBuilder::ray_casting) {
+               _VisibilityAlgo = ViewMapBuilder::ray_casting_fast;
+       }
+       else if (_VisibilityAlgo == ViewMapBuilder::ray_casting_fast) {
+               _VisibilityAlgo = ViewMapBuilder::ray_casting_very_fast;
+       }
+       else {
+               _VisibilityAlgo = ViewMapBuilder::ray_casting;
+       }
 }
 
 void Controller::setVisibilityAlgo(int algo)
@@ -699,69 +707,77 @@ int Controller::getVisibilityAlgo()
 
 void Controller::setQuantitativeInvisibility(bool iBool)
 {
-  _EnableQI = iBool;
+       _EnableQI = iBool;
 }
 
 bool Controller::getQuantitativeInvisibility() const
 {
-  return _EnableQI;
+       return _EnableQI;
 }
 
 void Controller::setFaceSmoothness(bool iBool)
 {
-  _EnableFaceSmoothness = iBool;
+       _EnableFaceSmoothness = iBool;
 }
 
 bool Controller::getFaceSmoothness() const
 {
-  return _EnableFaceSmoothness;
+       return _EnableFaceSmoothness;
 }
 
-void Controller::setComputeRidgesAndValleysFlag(bool iBool){
-  _ComputeRidges = iBool;
+void Controller::setComputeRidgesAndValleysFlag(bool iBool)
+{
+       _ComputeRidges = iBool;
 }
 
-bool Controller::getComputeRidgesAndValleysFlag() const {
-  return _ComputeRidges;
+bool Controller::getComputeRidgesAndValleysFlag() const
+{
+       return _ComputeRidges;
 }
 
-void Controller::setComputeSuggestiveContoursFlag(bool b){
-  _ComputeSuggestive = b;
+void Controller::setComputeSuggestiveContoursFlag(bool b)
+{
+       _ComputeSuggestive = b;
 }
-  
-bool Controller::getComputeSuggestiveContoursFlag() const {
-  return _ComputeSuggestive;
+
+bool Controller::getComputeSuggestiveContoursFlag() const
+{
+       return _ComputeSuggestive;
 }
 
-void Controller::setComputeMaterialBoundariesFlag(bool b){
-  _ComputeMaterialBoundaries = b;
+void Controller::setComputeMaterialBoundariesFlag(bool b)
+{
+       _ComputeMaterialBoundaries = b;
 }
-  
-bool Controller::getComputeMaterialBoundariesFlag() const {
-  return _ComputeMaterialBoundaries;
+
+bool Controller::getComputeMaterialBoundariesFlag() const
+{
+       return _ComputeMaterialBoundaries;
 }
 
-void Controller::setComputeSteerableViewMapFlag(bool iBool){
-  _ComputeSteerableViewMap = iBool;
+void Controller::setComputeSteerableViewMapFlag(bool iBool)
+{
+       _ComputeSteerableViewMap = iBool;
 }
 
-bool Controller::getComputeSteerableViewMapFlag() const {
-  return _ComputeSteerableViewMap;
+bool Controller::getComputeSteerableViewMapFlag() const
+{
+       return _ComputeSteerableViewMap;
 }
 
 void Controller::DrawStrokes()
 {
-  if(_ViewMap == 0)
-    return;
+       if (_ViewMap == 0)
+               return;
 
-  cout << "\n===  Stroke drawing  ===" << endl;
-  _Chrono.start();
-  _Canvas->Draw();
-  real d = _Chrono.stop();
-  cout << "Strokes generation  : " << d << endl;
-  cout << "Stroke count  : " << _Canvas->stroke_count << endl;
-  resetModified();
-  DeleteViewMap();
+       cout << "\n===  Stroke drawing  ===" << endl;
+       _Chrono.start();
+       _Canvas->Draw();
+       real d = _Chrono.stop();
+       cout << "Strokes generation  : " << d << endl;
+       cout << "Stroke count  : " << _Canvas->stroke_count << endl;
+       resetModified();
+       DeleteViewMap();
 }
 
 void Controller::ResetRenderCount()
@@ -769,206 +785,219 @@ void Controller::ResetRenderCount()
        _render_count = 0;
 }
 
-Render* Controller::RenderStrokes(Render *re) {
+Render* Controller::RenderStrokes(Render *re)
+{
        _Chrono.start();
        BlenderStrokeRenderer* blenderRenderer = new BlenderStrokeRenderer(re, ++_render_count);
-       _Canvas->Render( blenderRenderer );
+       _Canvas->Render(blenderRenderer);
        real d = _Chrono.stop();
-    cout << "Temporary scene generation: " << d << endl;
+       cout << "Temporary scene generation: " << d << endl;
        _Chrono.start();
        Render* freestyle_render = blenderRenderer->RenderScene(re);
        d = _Chrono.stop();
-    cout << "Stroke rendering  : " << d << endl;
+       cout << "Stroke rendering  : " << d << endl;
        delete blenderRenderer;
-       
+
        return freestyle_render;
 }
 
 void Controller::InsertStyleModule(unsigned index, const char *iFileName)
 {
-       if( !BLI_testextensie(iFileName, ".py") ) {
-               cerr << "Error: Cannot load \"" << StringUtils::toAscii( string(iFileName) )
-                 << "\", unknown extension" << endl;
-                 return;
+       if (!BLI_testextensie(iFileName, ".py")) {
+               cerr << "Error: Cannot load \"" << StringUtils::toAscii(string(iFileName))
+                    << "\", unknown extension" << endl;
+               return;
        }
 
-  StyleModule* sm = new StyleModule(iFileName, _inter);
-  _Canvas->InsertStyleModule(index, sm);
-  
+       StyleModule* sm = new StyleModule(iFileName, _inter);
+       _Canvas->InsertStyleModule(index, sm);
 }
 
 void Controller::InsertStyleModule(unsigned index, const char *iName, struct Text *iText)
 {
        StyleModule* sm = new BlenderStyleModule(iText, iName, _inter);
-  _Canvas->InsertStyleModule(index, sm);
+       _Canvas->InsertStyleModule(index, sm);
 }
 
 void Controller::AddStyleModule(const char *iFileName)
 {
-  //_pStyleWindow->Add(iFileName);
+       //_pStyleWindow->Add(iFileName);
 }
 
 void Controller::RemoveStyleModule(unsigned index)
 {
-  _Canvas->RemoveStyleModule(index);
+       _Canvas->RemoveStyleModule(index);
 }
 
 void Controller::Clear()
 {
-  _Canvas->Clear();
+       _Canvas->Clear();
 }
 
 void Controller::ReloadStyleModule(unsigned index, const char * iFileName)
 {
-  StyleModule* sm = new StyleModule(iFileName, _inter);
-  _Canvas->ReplaceStyleModule(index, sm);
+       StyleModule* sm = new StyleModule(iFileName, _inter);
+       _Canvas->ReplaceStyleModule(index, sm);
 }
 
 void Controller::SwapStyleModules(unsigned i1, unsigned i2)
 {
-  _Canvas->SwapStyleModules(i1, i2);
+       _Canvas->SwapStyleModules(i1, i2);
 }
 
-
 void Controller::toggleLayer(unsigned index, bool iDisplay)
 {
-  _Canvas->setVisible(index, iDisplay);
+       _Canvas->setVisible(index, iDisplay);
 }
 
 void Controller::setModified(unsigned index, bool iMod)
 {
-  //_pStyleWindow->setModified(index, iMod);
-  _Canvas->setModified(index, iMod);
-  updateCausalStyleModules(index + 1);
+       //_pStyleWindow->setModified(index, iMod);
+       _Canvas->setModified(index, iMod);
+       updateCausalStyleModules(index + 1);
 }
 
-void Controller::updateCausalStyleModules(unsigned index) {
-  vector<unsigned> vec;
-  _Canvas->causalStyleModules(vec, index);
-  for (vector<unsigned>::const_iterator it = vec.begin(); it != vec.end(); it++) {
-    //_pStyleWindow->setModified(*it, true);
-    _Canvas->setModified(*it, true);
-  }
+void Controller::updateCausalStyleModules(unsigned index)
+{
+       vector<unsigned> vec;
+       _Canvas->causalStyleModules(vec, index);
+       for (vector<unsigned>::const_iterator it = vec.begin(); it != vec.end(); it++) {
+               //_pStyleWindow->setModified(*it, true);
+               _Canvas->setModified(*it, true);
+       }
 }
 
 void Controller::resetModified(bool iMod)
 {
-  //_pStyleWindow->resetModified(iMod);
-  _Canvas->resetModified(iMod);
+       //_pStyleWindow->resetModified(iMod);
+       _Canvas->resetModified(iMod);
 }
 
-NodeGroup * Controller::BuildRep(vector<ViewEdge*>::iterator vedges_begin, 
-                                       vector<ViewEdge*>::iterator vedges_end)
+NodeGroup * Controller::BuildRep(vector<ViewEdge*>::iterator vedges_begin, vector<ViewEdge*>::iterator vedges_end)
 {
-  ViewMapTesselator2D tesselator2D;
-  FrsMaterial mat;
-  mat.setDiffuse(1,1,0.3,1);
-  tesselator2D.setFrsMaterial(mat);
+       ViewMapTesselator2D tesselator2D;
+       FrsMaterial mat;
+       mat.setDiffuse(1, 1, 0.3, 1);
+       tesselator2D.setFrsMaterial(mat);
 
-  return (tesselator2D.Tesselate(vedges_begin, vedges_end));
+       return (tesselator2D.Tesselate(vedges_begin, vedges_end));
 }
 
 void Controller::toggleEdgeTesselationNature(Nature::EdgeNature iNature)
 {
-  _edgeTesselationNature ^= (iNature);
-  ComputeViewMap();
+       _edgeTesselationNature ^= (iNature);
+       ComputeViewMap();
 }
 
-void           Controller::setModelsDir(const string& dir) {
-  //_current_dirs->setValue("models/dir", dir);
+void Controller::setModelsDir(const string& dir)
+{
+       //_current_dirs->setValue("models/dir", dir);
 }
 
-string         Controller::getModelsDir() const {
-  string dir = ".";
-  //_current_dirs->getValue("models/dir", dir);
-  return dir;
+string Controller::getModelsDir() const
+{
+       string dir = ".";
+       //_current_dirs->getValue("models/dir", dir);
+       return dir;
 }
 
-void           Controller::setModulesDir(const string& dir) {
-  //_current_dirs->setValue("modules/dir", dir);
+void Controller::setModulesDir(const string& dir)
+{
+       //_current_dirs->setValue("modules/dir", dir);
 }
 
-string         Controller::getModulesDir() const {
-  string dir = ".";
-  //_current_dirs->getValue("modules/dir", dir);
-  return dir;
+string Controller::getModulesDir() const
+{
+       string dir = ".";
+       //_current_dirs->getValue("modules/dir", dir);
+       return dir;
 }
 
-void           Controller::setHelpIndex(const string& index) {
-  _help_index = index;
+void Controller::setHelpIndex(const string& index)
+{
+       _help_index = index;
 }
 
-string         Controller::getHelpIndex() const {
-  return _help_index;
+string Controller::getHelpIndex() const
+{
+       return _help_index;
 }
 
-void           Controller::setBrowserCmd(const string& cmd) {
-  _browser_cmd = cmd;
+void Controller::setBrowserCmd(const string& cmd)
+{
+       _browser_cmd = cmd;
 }
 
-string         Controller::getBrowserCmd() const {
-  return _browser_cmd;
+string Controller::getBrowserCmd() const
+{
+       return _browser_cmd;
 }
 
-void           Controller::resetInterpreter() {
-  if (_inter)
-    _inter->reset();
+void Controller::resetInterpreter()
+{
+       if (_inter)
+               _inter->reset();
 }
 
 
-void Controller::displayDensityCurves(int x, int y){
-  SteerableViewMap * svm = _Canvas->getSteerableViewMap();
-  if(!svm)
-    return;
+void Controller::displayDensityCurves(int x, int y)
+{
+       SteerableViewMap * svm = _Canvas->getSteerableViewMap();
+       if (!svm)
+               return;
 
-  unsigned i,j;
-  typedef vector<Vec3r> densityCurve;
-  vector<densityCurve> curves(svm->getNumberOfOrientations()+1);
-  vector<densityCurve> curvesDirection(svm->getNumberOfPyramidLevels());
+       unsigned int i, j;
+       typedef vector<Vec3r> densityCurve;
+       vector<densityCurve> curves(svm->getNumberOfOrientations() + 1);
+       vector<densityCurve> curvesDirection(svm->getNumberOfPyramidLevels());
 
-  // collect the curves values
-  unsigned nbCurves = svm->getNumberOfOrientations()+1;
-  unsigned nbPoints = svm->getNumberOfPyramidLevels();
-  if(!nbPoints)
-    return;
+       // collect the curves values
+       unsigned nbCurves = svm->getNumberOfOrientations() + 1;
+       unsigned nbPoints = svm->getNumberOfPyramidLevels();
+       if (!nbPoints)
+               return;
 
-  // build the density/nbLevels curves for each orientation
-  for(i=0;i<nbCurves; ++i){
-    for(j=0; j<nbPoints; ++j){
-      curves[i].push_back(Vec3r(j, svm->readSteerableViewMapPixel(i, j, x, y), 0));
-    }
-  }
-  // build the density/nbOrientations curves for each level
-  for(i=0;i<nbPoints; ++i){
-    for(j=0; j<nbCurves; ++j){
-      curvesDirection[i].push_back(Vec3r(j, svm->readSteerableViewMapPixel(j, i, x, y), 0));
-    }
-  }
+       // build the density/nbLevels curves for each orientation
+       for (i = 0; i < nbCurves; ++i) {
+               for (j = 0; j < nbPoints; ++j) {
+                       curves[i].push_back(Vec3r(j, svm->readSteerableViewMapPixel(i, j, x, y), 0));
+               }
+       }
+       // build the density/nbOrientations curves for each level
+       for (i = 0; i < nbPoints; ++i) {
+               for (j = 0; j < nbCurves; ++j) {
+                       curvesDirection[i].push_back(Vec3r(j, svm->readSteerableViewMapPixel(j, i, x, y), 0));
+               }
+       }
 
-  // display the curves
-  // for(i=0; i<nbCurves; ++i)
-  //     _pDensityCurvesWindow->setOrientationCurve(i, Vec2d(0,0), Vec2d(nbPoints, 1), curves[i], "scale", "density");
-  //   for(i=1; i<=8; ++i)
-  //     _pDensityCurvesWindow->setLevelCurve(i, Vec2d(0,0), Vec2d(nbCurves, 1), curvesDirection[i], "orientation", "density");
-  //   _pDensityCurvesWindow->show();
+       // display the curves
+#if 0
+       for (i = 0; i < nbCurves; ++i)
+               _pDensityCurvesWindow->setOrientationCurve(i, Vec2d(0, 0), Vec2d(nbPoints, 1), curves[i], "scale", "density");
+       for (i = 1; i <= 8; ++i)
+               _pDensityCurvesWindow->setLevelCurve(i, Vec2d(0, 0), Vec2d(nbCurves, 1), curvesDirection[i],
+                                                    "orientation", "density");
+       _pDensityCurvesWindow->show();
+#endif
 }
 
-void Controller::init_options(){
-//     from AppOptionsWindow.cpp
-//     Default init options
+void Controller::init_options()
+{
+       // from AppOptionsWindow.cpp
+       // Default init options
 
        Config::Path * cpath = Config::Path::getInstance();
-       
+
        // Directories
-       ViewMapIO::Options::setModelsPath( StringUtils::toAscii( cpath->getModelsPath() ) ); 
-       PythonInterpreter::Options::setPythonPath( StringUtils::toAscii( cpath->getPythonPath() ) );
-       TextureManager::Options::setPatternsPath( StringUtils::toAscii( cpath->getPatternsPath() ) );
-       TextureManager::Options::setBrushesPath( StringUtils::toAscii( cpath->getModelsPath() ) );
+       ViewMapIO::Options::setModelsPath(StringUtils::toAscii(cpath->getModelsPath()));
+       PythonInterpreter::Options::setPythonPath(StringUtils::toAscii(cpath->getPythonPath()));
+       TextureManager::Options::setPatternsPath(StringUtils::toAscii(cpath->getPatternsPath()));
+       TextureManager::Options::setBrushesPath(StringUtils::toAscii(cpath->getModelsPath()));
 
        // ViewMap Format
        ViewMapIO::Options::rmFlags(ViewMapIO::Options::FLOAT_VECTORS);
        ViewMapIO::Options::rmFlags(ViewMapIO::Options::NO_OCCLUDERS);
-       setComputeSteerableViewMapFlag( false );
+       setComputeSteerableViewMapFlag(false);
 
        // Visibility
        setQuantitativeInvisibility(true);
index 6119e14f7b733d6e387a0458257a54e4ebd7926e..475d9c6efd39dcd2b81b7d6232249612697de260 100644 (file)
@@ -1,45 +1,51 @@
-//
-//  Filename         : Controller.h
-//  Author           : Stephane Grabli
-//  Purpose          : The spinal tap of the system
-//  Date of creation : 01/07/2002
-//
-///////////////////////////////////////////////////////////////////////////////
-
-
-//
-//  Copyright (C) : Please refer to the COPYRIGHT file distributed 
-//   with this source distribution. 
-//
-//  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.
-//
-///////////////////////////////////////////////////////////////////////////////
-
-#ifndef  CONTROLLER_H
-# define CONTROLLER_H
-
-# include "../view_map/ViewMapBuilder.h"
-# include <string>
-//# include "ConfigIO.h"
-# include "../geometry/FastGrid.h"
-# include "../system/TimeUtils.h"
-# include "../system/ProgressBar.h"
-# include "../system/Precision.h"
-# include "../system/Interpreter.h"
-# include "../system/RenderMonitor.h"
-# include "../view_map/FEdgeXDetector.h"
+/*
+ * ***** 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) 2010 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __CONTROLLER_H__
+#define __CONTROLLER_H__
+
+/** \file blender/freestyle/intern/application/Controller.h
+ *  \ingroup freestyle
+ *  \brief The spinal tap of the system.
+ *  \author Stephane Grabli
+ *  \date 01/07/2002
+ */
+
+#include <string>
+
+//#include "ConfigIO.h"
+#include "../geometry/FastGrid.h"
+#include "../system/Interpreter.h"
+#include "../system/ProgressBar.h"
+#include "../system/Precision.h"
+#include "../system/RenderMonitor.h"
+#include "../system/TimeUtils.h"
+#include "../view_map/FEdgeXDetector.h"
+#include "../view_map/ViewMapBuilder.h"
 
 class AppView;
 class NodeGroup;
@@ -52,12 +58,13 @@ class InteractiveShader;
 class Shader;
 class StrokeRenderer;
 
+// XXX Are those "ifdef __cplusplus" useful here?
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-       #include "render_types.h"
-       #include "DNA_scene_types.h"
+#include "render_types.h"
+#include "DNA_scene_types.h"
 
 #ifdef __cplusplus
 }
@@ -66,188 +73,189 @@ extern "C" {
 class Controller
 {
 public:
-  Controller() ;
-  ~Controller() ;
-  
-  void setView(AppView *iView);
-  void setRenderMonitor(RenderMonitor *iRenderMonitor);
-  void setPassDiffuse(float *buf, int width, int height);
-  void setPassZ(float *buf, int width, int height);
-  void setContext(bContext *C);
-
-  //soc
+       Controller();
+       ~Controller();
+
+       void setView(AppView *iView);
+       void setRenderMonitor(RenderMonitor *iRenderMonitor);
+       void setPassDiffuse(float *buf, int width, int height);
+       void setPassZ(float *buf, int width, int height);
+       void setContext(bContext *C);
+
+       //soc
        void init_options();
 
-  int  LoadMesh( Render *re, SceneRenderLayer* srl );
-  int  Load3DSFile(const char *iFileName);
-  void CloseFile();
-  void ComputeViewMap();
-  void ComputeSteerableViewMap();
-  void saveSteerableViewMapImages();
-  void toggleEdgeTesselationNature(Nature::EdgeNature iNature);
-  void DrawStrokes();
-  void ResetRenderCount();
-  Render* RenderStrokes(Render *re);
-  void SwapStyleModules(unsigned i1, unsigned i2);
-  void InsertStyleModule(unsigned index, const char *iFileName);
-  void InsertStyleModule(unsigned index, const char *iName, struct Text *iText);
-  void AddStyleModule(const char *iFileName);
-  void RemoveStyleModule(unsigned index);
-  void ReloadStyleModule(unsigned index, const char * iFileName);
-  void Clear();
-  void ClearRootNode();
-  void DeleteWingedEdge();
-  void DeleteViewMap();
-  void toggleLayer(unsigned index, bool iDisplay);
-  void setModified(unsigned index, bool iMod);
-  void resetModified(bool iMod=false);
-  void updateCausalStyleModules(unsigned index);
-  void displayDensityCurves(int x, int y);
-  
-  ViewEdge * SelectViewEdge(real x, real y);
-  FEdge * SelectFEdge(real x, real y);
-  NodeGroup* BuildRep(vector<ViewEdge*>::iterator vedges_begin, 
-                     vector<ViewEdge*>::iterator vedges_end) ;
-  
-  //NodeGroup* debugNode() {return _DebugNode;}
-  //AppView * view() {return _pView;}
-  //NodeGroup* debugScene() {return _DebugNode;}
-  //Grid& grid() {return _Grid;}
-  
-  void toggleVisibilityAlgo();
-  void setVisibilityAlgo(int algo);
-  int getVisibilityAlgo();
-
-  void setQuantitativeInvisibility(bool iBool); // if true, we compute quantitativeInvisibility
-  bool getQuantitativeInvisibility() const;
-  void setFaceSmoothness(bool iBool);
-  bool getFaceSmoothness() const;
-
-  void setComputeRidgesAndValleysFlag(bool b);
-  bool getComputeRidgesAndValleysFlag() const ;
-  void setComputeSuggestiveContoursFlag(bool b);
-  bool getComputeSuggestiveContoursFlag() const ;
-  void setComputeMaterialBoundariesFlag(bool b);
-  bool getComputeMaterialBoundariesFlag() const ;
-
-  void setComputeSteerableViewMapFlag(bool iBool);
-  bool getComputeSteerableViewMapFlag() const;
-  void setCreaseAngle(real angle){_creaseAngle=angle;}
-  real getCreaseAngle() const {return _creaseAngle;}
-  void setSphereRadius(real s){_sphereRadius=s;}
-  real getSphereRadius() const {return _sphereRadius;}
-  void setSuggestiveContourKrDerivativeEpsilon(real dkr){_suggestiveContourKrDerivativeEpsilon=dkr;}
-  real getSuggestiveContourKrDerivativeEpsilon() const {return _suggestiveContourKrDerivativeEpsilon;}
-
-  void         setModelsDir(const string& dir);
-  string       getModelsDir() const;
-  void         setModulesDir(const string& dir);
-  string       getModulesDir() const;
-  void         setHelpIndex(const string& dir);
-  string       getHelpIndex() const;
-  void         setBrowserCmd(const string& cmd);
-  string       getBrowserCmd() const;
-
-  void resetInterpreter();
+       int  LoadMesh(Render *re, SceneRenderLayer *srl);
+       int  Load3DSFile(const char *iFileName);
+       void CloseFile();
+       void ComputeViewMap();
+       void ComputeSteerableViewMap();
+       void saveSteerableViewMapImages();
+       void toggleEdgeTesselationNature(Nature::EdgeNature iNature);
+       void DrawStrokes();
+       void ResetRenderCount();
+       Render *RenderStrokes(Render *re);
+       void SwapStyleModules(unsigned i1, unsigned i2);
+       void InsertStyleModule(unsigned index, const char *iFileName);
+       void InsertStyleModule(unsigned index, const char *iName, struct Text *iText);
+       void AddStyleModule(const char *iFileName);
+       void RemoveStyleModule(unsigned index);
+       void ReloadStyleModule(unsigned index, const char * iFileName);
+       void Clear();
+       void ClearRootNode();
+       void DeleteWingedEdge();
+       void DeleteViewMap();
+       void toggleLayer(unsigned index, bool iDisplay);
+       void setModified(unsigned index, bool iMod);
+       void resetModified(bool iMod=false);
+       void updateCausalStyleModules(unsigned index);
+       void displayDensityCurves(int x, int y);
+
+       ViewEdge *SelectViewEdge(real x, real y);
+       FEdge *SelectFEdge(real x, real y);
+       NodeGroup *BuildRep(vector<ViewEdge*>::iterator vedges_begin, vector<ViewEdge*>::iterator vedges_end) ;
+
+#if 0
+       NodeGroup *debugNode() {return _DebugNode;}
+       AppView *view() {return _pView;}
+       NodeGroup *debugScene() {return _DebugNode;}
+       Grid& grid() {return _Grid;}
+#endif
+
+       void toggleVisibilityAlgo();
+       void setVisibilityAlgo(int algo);
+       int getVisibilityAlgo();
+
+       void setQuantitativeInvisibility(bool iBool); // if true, we compute quantitativeInvisibility
+       bool getQuantitativeInvisibility() const;
+       void setFaceSmoothness(bool iBool);
+       bool getFaceSmoothness() const;
+
+       void setComputeRidgesAndValleysFlag(bool b);
+       bool getComputeRidgesAndValleysFlag() const;
+       void setComputeSuggestiveContoursFlag(bool b);
+       bool getComputeSuggestiveContoursFlag() const;
+       void setComputeMaterialBoundariesFlag(bool b);
+       bool getComputeMaterialBoundariesFlag() const;
+
+       void setComputeSteerableViewMapFlag(bool iBool);
+       bool getComputeSteerableViewMapFlag() const;
+       void setCreaseAngle(real angle) {_creaseAngle = angle;}
+       real getCreaseAngle() const {return _creaseAngle;}
+       void setSphereRadius(real s) {_sphereRadius = s;}
+       real getSphereRadius() const {return _sphereRadius;}
+       void setSuggestiveContourKrDerivativeEpsilon(real dkr) {_suggestiveContourKrDerivativeEpsilon = dkr;}
+       real getSuggestiveContourKrDerivativeEpsilon() const {return _suggestiveContourKrDerivativeEpsilon;}
+
+       void setModelsDir(const string& dir);
+       string getModelsDir() const;
+       void setModulesDir(const string& dir);
+       string getModulesDir() const;
+       void setHelpIndex(const string& dir);
+       string getHelpIndex() const;
+       void setBrowserCmd(const string& cmd);
+       string getBrowserCmd() const;
+
+       void resetInterpreter();
 
 public:
        // Viewmap data structure
-       ViewMap * _ViewMap;
+       ViewMap *_ViewMap;
 
        // Canvas
-  AppCanvas *_Canvas;
+       AppCanvas *_Canvas;
 
 private:
+       // Main Window:
+       //AppMainWindow *_pMainWindow;
 
-  // Main Window:
-  //AppMainWindow *_pMainWindow;
+       // List of models currently loaded
+       vector<string> _ListOfModels;
 
-  // List of models currently loaded
-  vector<string> _ListOfModels;
+       // Current directories
+       //ConfigIO* _current_dirs;
 
-  // Current directories
-  //ConfigIO* _current_dirs;
+       //View
+       // 3D
+       AppView *_pView;
 
+       // 2D
+#if 0
+       Viewer2DWindow *_pView2DWindow;
+       Viewer2D *_pView2D;
+#endif
 
+       RenderMonitor *_pRenderMonitor;
 
-  //View
-  // 3D
-  AppView *_pView;
-  
-  // 2D
-  //Viewer2DWindow *_pView2DWindow;
-  //Viewer2D *_pView2D;
-  
-  RenderMonitor *_pRenderMonitor;
+       //Model
+       // Drawing Structure
+       NodeGroup *_RootNode;
 
-  //Model
-  // Drawing Structure
-  NodeGroup *_RootNode;
+       // Winged-Edge structure
+       WingedEdge *_winged_edge;
 
-  // Winged-Edge structure
-  WingedEdge* _winged_edge;
+       // Silhouette structure:
+#if 0
+       std::vector<SShape*> _SShapes;
+       NodeGroup *_SRoot;
+#endif
+
+       // Silhouette
+       NodeGroup *_SilhouetteNode;
+       NodeGroup *_ProjectedSilhouette;
+       NodeGroup *_VisibleProjectedSilhouette;
 
-  // Silhouette structure:
-  //std::vector<SShape*> _SShapes;
-  //NodeGroup *_SRoot;
-  
-  // Silhouette
-  NodeGroup *_SilhouetteNode;
-  NodeGroup *_ProjectedSilhouette;
-  NodeGroup *_VisibleProjectedSilhouette;
-  
-  // more Debug info
-  NodeGroup *_DebugNode;
+       // more Debug info
+       NodeGroup *_DebugNode;
 
-  // debug
-  //  NodeUser<ViewMap> *_ViewMapNode; // FIXME
+       // debug
+       //NodeUser<ViewMap> *_ViewMapNode; // FIXME
 
-  // Chronometer:
-  Chronometer _Chrono;
+       // Chronometer:
+       Chronometer _Chrono;
 
        // Progress Bar
-  ProgressBar *_ProgressBar;
+       ProgressBar *_ProgressBar;
+
+       // edges tesselation nature
+       int _edgeTesselationNature;
+
+       FastGrid _Grid;
+       //HashGrid _Grid;
 
-  // edges tesselation nature
-  int _edgeTesselationNature;
+       unsigned int _SceneNumFaces;
+       real _minEdgeSize;
+       real _EPSILON;
+       real _bboxDiag;
 
-  FastGrid _Grid;
-  //HashGrid _Grid;
-  
-  unsigned int _SceneNumFaces;
-  real _minEdgeSize;
-  real _EPSILON;
-  real _bboxDiag;
+       int _render_count;
 
-  int _render_count;
+       //AppStyleWindow *_pStyleWindow;
+       //AppOptionsWindow *_pOptionsWindow;
+       //AppDensityCurvesWindow *_pDensityCurvesWindow;
 
-  //AppStyleWindow *_pStyleWindow;
-  //AppOptionsWindow *_pOptionsWindow;
-  //AppDensityCurvesWindow *_pDensityCurvesWindow;
+       ViewMapBuilder::visibility_algo _VisibilityAlgo;
 
-  ViewMapBuilder::visibility_algo      _VisibilityAlgo;
-  
-  // Script Interpreter
-  Interpreter* _inter;
+       // Script Interpreter
+       Interpreter *_inter;
 
-  string       _help_index;
-  string       _browser_cmd;
+       string _help_index;
+       string _browser_cmd;
 
-  bool _EnableQI;
-  bool _EnableFaceSmoothness;
-  bool _ComputeRidges;
-  bool _ComputeSuggestive;
-  bool _ComputeMaterialBoundaries;
-  real _creaseAngle;
-  real _sphereRadius;
-  real _suggestiveContourKrDerivativeEpsilon;
+       bool _EnableQI;
+       bool _EnableFaceSmoothness;
+       bool _ComputeRidges;
+       bool _ComputeSuggestive;
+       bool _ComputeMaterialBoundaries;
+       real _creaseAngle;
+       real _sphereRadius;
+       real _suggestiveContourKrDerivativeEpsilon;
 
-  bool _ComputeSteerableViewMap;
+       bool _ComputeSteerableViewMap;
 
-  FEdgeXDetector edgeDetector;
+       FEdgeXDetector edgeDetector;
 };
 
-extern Controller      *g_pController;
+extern Controller *g_pController;
 
-#endif // CONTROLLER_H
+#endif // __CONTROLLER_H__
index 8f2c00bf0f72203f5715392b698a1c9735091c87..ea20f8255b12f10f68febf3750b6730aaefc3774 100644 (file)
@@ -1,7 +1,38 @@
-#include "BlenderFileLoader.h"
+/*
+ * ***** 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) 2010 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
+ *  \ingroup freestyle
+ */
 
 #include <assert.h>
 
+#include "BlenderFileLoader.h"
+
 BlenderFileLoader::BlenderFileLoader(Render *re, SceneRenderLayer* srl)
 {
        _re = re;
@@ -26,20 +57,20 @@ NodeGroup* BlenderFileLoader::Load()
        // creation of the scene root node
        _Scene = new NodeGroup;
 
-       _viewplane_left=   _re->viewplane.xmin;
-       _viewplane_right=  _re->viewplane.xmax;
-       _viewplane_bottom= _re->viewplane.ymin;
-       _viewplane_top=    _re->viewplane.ymax;
-       _z_near= -_re->clipsta;
-       _z_far=  -_re->clipend;
+       _viewplane_left =   _re->viewplane.xmin;
+       _viewplane_right =  _re->viewplane.xmax;
+       _viewplane_bottom = _re->viewplane.ymin;
+       _viewplane_top =    _re->viewplane.ymax;
+       _z_near = -_re->clipsta;
+       _z_far =  -_re->clipend;
 #if 0
        cout << "Frustum: l " << _viewplane_left << " r " << _viewplane_right
-               << " b " << _viewplane_bottom << " t " << _viewplane_top
-               << " n " << _z_near << " f " << _z_far << endl;
+            << " b " << _viewplane_bottom << " t " << _viewplane_top
+            << " n " << _z_near << " f " << _z_far << endl;
 #endif
 
        int id = 0;
-       for(obi= (ObjectInstanceRen *) _re->instancetable.first; obi; obi=obi->next) {
+       for (obi = (ObjectInstanceRen *)_re->instancetable.first; obi; obi = obi->next) {
                if (_pRenderMonitor && _pRenderMonitor->testBreak())
                        break;
                if (!(obi->lay & _srl->lay))
@@ -48,13 +79,13 @@ NodeGroup* BlenderFileLoader::Load()
                //cout << name[0] << name[1] << ":" << (name+2) <<;
                //print_m4("obi->mat", obi->mat);
 
-               ifobi->obr->totvlak > 0)
+               if (obi->obr->totvlak > 0)
                        insertShapeNode(obi, ++id);
                else
                        cout << "Warning: " << (name+2) << " is not a vlak-based object (ignored)" << endl;
        }
 
-       //Returns the built scene.
+       // Return the built scene.
        return _Scene;
 }
 
@@ -77,13 +108,15 @@ int BlenderFileLoader::countClippedFaces(float v1[3], float v2[3], float v3[3],
                if (v[i][2] > _z_near) {
                        clip[i] = CLIPPED_BY_NEAR;
                        numClipped++;
-               } else if (v[i][2] < _z_far) {
+               }
+               else if (v[i][2] < _z_far) {
                        clip[i] = CLIPPED_BY_FAR;
                        numClipped++;
-               } else {
+               }
+               else {
                        clip[i] = NOT_CLIPPED;
                }
-//             printf("%d %s\n", i, (clip[i] == NOT_CLIPPED) ? "not" : (clip[i] == CLIPPED_BY_NEAR) ? "near" : "far");
+               //printf("%d %s\n", i, (clip[i] == NOT_CLIPPED) ? "not" : (clip[i] == CLIPPED_BY_NEAR) ? "near" : "far");
                sum += clip[i];
        }
        switch (numClipped) {
@@ -120,7 +153,8 @@ void BlenderFileLoader::clipLine(float v1[3], float v2[3], float c[3], float z)
        if (v1[2] < v2[2]) {
                p = v1;
                q = v2;
-       } else {
+       }
+       else {
                p = v2;
                q = v1;
        }
@@ -137,8 +171,8 @@ void BlenderFileLoader::clipLine(float v1[3], float v2[3], float c[3], float z)
 // obtain a set of vertices after the clipping.  The number of vertices
 // is at most 5.
 void BlenderFileLoader::clipTriangle(int numTris, float triCoords[][3], float v1[3], float v2[3], float v3[3],
-                                                                        float triNormals[][3], float n1[3], float n2[3], float n3[3],
-                                                                        bool edgeMarks[], bool em1, bool em2, bool em3, int clip[3])
+                                     float triNormals[][3], float n1[3], float n2[3], float n3[3],
+                                     bool edgeMarks[], bool em1, bool em2, bool em3, int clip[3])
 {
        float *v[3], *n[3];
        bool em[3];
@@ -164,13 +198,15 @@ void BlenderFileLoader::clipTriangle(int numTris, float triCoords[][3], float v1
                                edgeMarks[k] = false;
                                k++;
                        }
-               } else if (clip[i] != clip[j]) {
+               }
+               else if (clip[i] != clip[j]) {
                        if (clip[j] == NOT_CLIPPED) {
                                clipLine(v[i], v[j], triCoords[k], (clip[i] == CLIPPED_BY_NEAR) ? _z_near : _z_far);
                                copy_v3_v3(triNormals[k], n[i]);
                                edgeMarks[k] = em[i];
                                k++;
-                       } else {
+                       }
+                       else {
                                clipLine(v[i], v[j], triCoords[k], (clip[i] == CLIPPED_BY_NEAR) ? _z_near : _z_far);
                                copy_v3_v3(triNormals[k], n[i]);
                                edgeMarks[k] = em[i];
@@ -182,15 +218,15 @@ void BlenderFileLoader::clipTriangle(int numTris, float triCoords[][3], float v1
                        }
                }
        }
-       assert (k == 2 + numTris);
+       assert(k == 2 + numTris);
 }
 
 void BlenderFileLoader::addTriangle(struct LoaderState *ls, float v1[3], float v2[3], float v3[3],
-                                                                       float n1[3], float n2[3], float n3[3],
-                                                                       bool fm, bool em1, bool em2, bool em3)
+                                    float n1[3], float n2[3], float n3[3],
+                                    bool fm, bool em1, bool em2, bool em3)
 {
        float *fv[3], *fn[3], len;
-       unsigned i, j;
+       unsigned int i, j;
        IndexedFaceSet::FaceEdgeMark marks = 0;
 
        // initialize the bounding box by the first vertex
@@ -208,24 +244,23 @@ void BlenderFileLoader::addTriangle(struct LoaderState *ls, float v1[3], float v
                copy_v3_v3(ls->pn, fn[i]);
 
                // update the bounding box
-               for (j = 0; j < 3; j++)
-               {
-                       if (ls->minBBox[j] > ls->pv[j])
-                       ls->minBBox[j] = ls->pv[j];
+               for (j = 0; j < 3; j++) {
+                       if (ls->minBBox[j] > ls->pv[j])
+                               ls->minBBox[j] = ls->pv[j];
 
-                       if (ls->maxBBox[j] < ls->pv[j])
-                       ls->maxBBox[j] = ls->pv[j];
+                       if (ls->maxBBox[j] < ls->pv[j])
+                               ls->maxBBox[j] = ls->pv[j];
                }
 
                len = len_v3v3(fv[i], fv[(i + 1) % 3]);
                if (_minEdgeSize > len)
-                       _minEdgeSize = len;
-               
+                       _minEdgeSize = len;
+
                *ls->pvi = ls->currentIndex;
                *ls->pni = ls->currentIndex;
                *ls->pmi = ls->currentMIndex;
 
-               ls->currentIndex +=3;
+               ls->currentIndex += 3;
                ls->pv += 3;
                ls->pn += 3;
 
@@ -233,11 +268,16 @@ void BlenderFileLoader::addTriangle(struct LoaderState *ls, float v1[3], float v
                ls->pni++;
                ls->pmi++;
        }
-       if (fm) marks |= IndexedFaceSet::FACE_MARK;
-       if (em1) marks |= IndexedFaceSet::EDGE_MARK_V1V2;
-       if (em2) marks |= IndexedFaceSet::EDGE_MARK_V2V3;
-       if (em3) marks |= IndexedFaceSet::EDGE_MARK_V3V1;
-       *ls->pm++ = marks;
+
+       if (fm)
+               marks |= IndexedFaceSet::FACE_MARK;
+       if (em1)
+               marks |= IndexedFaceSet::EDGE_MARK_V1V2;
+       if (em2)
+               marks |= IndexedFaceSet::EDGE_MARK_V2V3;
+       if (em3)
+               marks |= IndexedFaceSet::EDGE_MARK_V3V1;
+       *(ls->pm++) = marks;
 }
 
 // With A, B and P indicating the three vertices of a given triangle, returns:
@@ -246,20 +286,32 @@ void BlenderFileLoader::addTriangle(struct LoaderState *ls, float v1[3], float v
 // zero otherwise.
 int BlenderFileLoader::testDegenerateTriangle(float v1[3], float v2[3], float v3[3])
 {
-       //float area = area_tri_v3(v1, v2, v3);
-       //bool verbose = (area < 1e-6);
+#if 0
+       float area = area_tri_v3(v1, v2, v3);
+       bool verbose = (area < 1.0e-6);
+#endif
 
        if (equals_v3v3(v1, v2) || equals_v3v3(v2, v3) || equals_v3v3(v1, v3)) {
-               //if (verbose) printf("BlenderFileLoader::testDegenerateTriangle = 1\n");
+#if 0
+               if (verbose)
+                       printf("BlenderFileLoader::testDegenerateTriangle = 1\n");
+#endif
                return 1;
        }
-       if (dist_to_line_segment_v3(v1, v2, v3) < 1e-6 ||
-               dist_to_line_segment_v3(v2, v1, v3) < 1e-6 ||
-               dist_to_line_segment_v3(v3, v1, v2) < 1e-6) {
-               //if (verbose) printf("BlenderFileLoader::testDegenerateTriangle = 2\n");
+       if (dist_to_line_segment_v3(v1, v2, v3) < 1.0e-6 ||
+           dist_to_line_segment_v3(v2, v1, v3) < 1.0e-6 ||
+           dist_to_line_segment_v3(v3, v1, v2) < 1.0e-6)
+       {
+#if 0
+               if (verbose)
+                       printf("BlenderFileLoader::testDegenerateTriangle = 2\n");
+#endif
                return 2;
        }
-       //if (verbose) printf("BlenderFileLoader::testDegenerateTriangle = 0\n");
+#if 0
+       if (verbose)
+               printf("BlenderFileLoader::testDegenerateTriangle = 0\n");
+#endif
        return 0;
 }
 
@@ -280,7 +332,7 @@ bool BlenderFileLoader::testEdgeRotation(float v1[3], float v2[3], float v3[3],
 void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id)
 {
        ObjectRen *obr = obi->obr;
-       char *name = obi->ob->id.name+2;
+       char *name = obi->ob->id.name + 2;
 
        // We parse vlak nodes and count the number of faces after the clipping by
        // the near and far view planes is applied (Note: mesh vertices are in the
@@ -291,9 +343,11 @@ void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id)
        float n1[3], n2[3], n3[3], n4[3], facenormal[3];
        int clip_1[3], clip_2[3];
        int wire_material = 0;
-       for(int a=0; a < obr->totvlak; a++) {
-               if((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak;
-               else vlr++;
+       for (int a = 0; a < obr->totvlak; a++) {
+               if ((a & 255) == 0)
+                       vlr = obr->vlaknodes[a>>8].vlak;
+               else
+                       vlr++;
                if (vlr->mat->material_type == MA_TYPE_WIRE) {
                        wire_material = 1;
                        continue;
@@ -301,58 +355,64 @@ void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id)
                copy_v3_v3(v1, vlr->v1->co);
                copy_v3_v3(v2, vlr->v2->co);
                copy_v3_v3(v3, vlr->v3->co);
-               if (vlr->v4) copy_v3_v3(v4, vlr->v4->co);
+               if (vlr->v4)
+                       copy_v3_v3(v4, vlr->v4->co);
                if (obi->flag & R_TRANSFORMED) {
                        mul_m4_v3(obi->mat, v1);
                        mul_m4_v3(obi->mat, v2);
                        mul_m4_v3(obi->mat, v3);
-                       if (vlr->v4) mul_m4_v3(obi->mat, v4);
+                       if (vlr->v4)
+                               mul_m4_v3(obi->mat, v4);
                }
-//             print_v3("v1", v1);
-//             print_v3("v2", v2);
-//             print_v3("v3", v3);
-//             if (vlr->v4) print_v3("v4", v4);
+#if 0
+               print_v3("v1", v1);
+               print_v3("v2", v2);
+               print_v3("v3", v3);
+               if (vlr->v4)
+                       print_v3("v4", v4);
+#endif
                if (!vlr->v4 || !testEdgeRotation(v1, v2, v3, v4)) {
                        numFaces += countClippedFaces(v1, v2, v3, clip_1);
                        if (vlr->v4)
                                numFaces += countClippedFaces(v1, v3, v4, clip_2);
-               } else {
+               }
+               else {
                        numFaces += countClippedFaces(v1, v2, v4, clip_1);
                        numFaces += countClippedFaces(v2, v3, v4, clip_2);
                }
        }
        if (wire_material)
                printf("Warning: Object %s has wire materials (ignored)\n", name);
-//     cout <<"numFaces " <<numFaces<<endl;
+//     cout << "numFaces " << numFaces << endl;
        if (numFaces == 0)
                return;
 
        // We allocate memory for the meshes to be imported
        NodeTransform *currentMesh = new NodeTransform;
-       NodeShape * shape = new NodeShape;
+       NodeShape *shape = new NodeShape;
 
-       unsigned vSize = 3*3*numFaces;
+       unsigned vSize = 3 * 3 * numFaces;
        float *vertices = new float[vSize];
        unsigned nSize = vSize;
        float *normals = new float[nSize];
        unsigned *numVertexPerFaces = new unsigned[numFaces];
        vector<FrsMaterial> meshFrsMaterials;
-       
+
        IndexedFaceSet::TRIANGLES_STYLE *faceStyle = new IndexedFaceSet::TRIANGLES_STYLE[numFaces];
        unsigned i;
        for (i = 0; i <numFaces; i++) {
-         faceStyle[i] = IndexedFaceSet::TRIANGLES;
-         numVertexPerFaces[i] = 3;
+               faceStyle[i] = IndexedFaceSet::TRIANGLES;
+               numVertexPerFaces[i] = 3;
        }
 
        IndexedFaceSet::FaceEdgeMark *faceEdgeMarks = new IndexedFaceSet::FaceEdgeMark[numFaces];
-       
-       unsigned viSize = 3*numFaces;
+
+       unsigned viSize = 3 * numFaces;
        unsigned *VIndices = new unsigned[viSize];
        unsigned niSize = viSize;
        unsigned *NIndices = new unsigned[niSize];
        unsigned *MIndices = new unsigned[viSize]; // Material Indices
-       
+
        struct LoaderState ls;
        ls.pv = vertices;
        ls.pn = normals;
@@ -362,185 +422,190 @@ void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id)
        ls.pmi = MIndices;
        ls.currentIndex = 0;
        ls.currentMIndex = 0;
-       
+
        FrsMaterial tmpMat;
 
        // We parse the vlak nodes again and import meshes while applying the clipping
        // by the near and far view planes.
        int p;
-       for(p=0; p < obr->totvlak; ++p) // we parse the faces of the mesh
-       {
-                       // Lib3dsFace *f=&mesh->faceL[p];
-                       // Lib3dsMaterial *mat=0;
-                       if((p & 255)==0) vlr = obr->vlaknodes[p>>8].vlak;
-                       else vlr++;
-                       copy_v3_v3(v1, vlr->v1->co);
-                       copy_v3_v3(v2, vlr->v2->co);
-                       copy_v3_v3(v3, vlr->v3->co);
-                       if (vlr->v4) copy_v3_v3(v4, vlr->v4->co);
+       for (p = 0; p < obr->totvlak; ++p) { // we parse the faces of the mesh
+#if 0
+               Lib3dsFace *f = &mesh->faceL[p];
+               Lib3dsMaterial *mat = NULL;
+#endif
+               if ((p & 255) == 0)
+                       vlr = obr->vlaknodes[p>>8].vlak;
+               else
+                       vlr++;
+               copy_v3_v3(v1, vlr->v1->co);
+               copy_v3_v3(v2, vlr->v2->co);
+               copy_v3_v3(v3, vlr->v3->co);
+               if (vlr->v4)
+                       copy_v3_v3(v4, vlr->v4->co);
+               if (obi->flag & R_TRANSFORMED) {
+                       mul_m4_v3(obi->mat, v1);
+                       mul_m4_v3(obi->mat, v2);
+                       mul_m4_v3(obi->mat, v3);
+                       if (vlr->v4)
+                               mul_m4_v3(obi->mat, v4);
+               }
+               if (_smooth && (vlr->flag & R_SMOOTH)) {
+                       copy_v3_v3(n1, vlr->v1->n);
+                       copy_v3_v3(n2, vlr->v2->n);
+                       copy_v3_v3(n3, vlr->v3->n);
+                       if (vlr->v4)
+                               copy_v3_v3(n4, vlr->v4->n);
                        if (obi->flag & R_TRANSFORMED) {
-                               mul_m4_v3(obi->mat, v1);
-                               mul_m4_v3(obi->mat, v2);
-                               mul_m4_v3(obi->mat, v3);
-                               if (vlr->v4) mul_m4_v3(obi->mat, v4);
-                       }
-                       if (_smooth && (vlr->flag & R_SMOOTH)) {
-                               copy_v3_v3(n1, vlr->v1->n);
-                               copy_v3_v3(n2, vlr->v2->n);
-                               copy_v3_v3(n3, vlr->v3->n);
-                               if (vlr->v4) copy_v3_v3(n4, vlr->v4->n);
-                               if (obi->flag & R_TRANSFORMED) {
-                                       mul_m3_v3(obi->nmat, n1);
-                                       mul_m3_v3(obi->nmat, n2);
-                                       mul_m3_v3(obi->nmat, n3);
-                                       normalize_v3(n1);
-                                       normalize_v3(n2);
-                                       normalize_v3(n3);
-                                       if (vlr->v4) {
-                                               mul_m3_v3(obi->nmat, n4);
-                                               normalize_v3(n4);
-                                       }
+                               mul_m3_v3(obi->nmat, n1);
+                               mul_m3_v3(obi->nmat, n2);
+                               mul_m3_v3(obi->nmat, n3);
+                               normalize_v3(n1);
+                               normalize_v3(n2);
+                               normalize_v3(n3);
+                               if (vlr->v4) {
+                                       mul_m3_v3(obi->nmat, n4);
+                                       normalize_v3(n4);
                                }
-                       } else {
-                               RE_vlakren_get_normal(_re, obi, vlr, facenormal);
-                               copy_v3_v3(n1, facenormal);
-                               copy_v3_v3(n2, facenormal);
-                               copy_v3_v3(n3, facenormal);
-                               if (vlr->v4) copy_v3_v3(n4, facenormal);
                        }
+               }
+               else {
+                       RE_vlakren_get_normal(_re, obi, vlr, facenormal);
+                       copy_v3_v3(n1, facenormal);
+                       copy_v3_v3(n2, facenormal);
+                       copy_v3_v3(n3, facenormal);
+                       if (vlr->v4)
+                               copy_v3_v3(n4, facenormal);
+               }
 
-                       unsigned numTris_1, numTris_2;
-                       bool edge_rotation;
-                       if (!vlr->v4 || !testEdgeRotation(v1, v2, v3, v4)) {
-                               numTris_1 = countClippedFaces(v1, v2, v3, clip_1);
-                               numTris_2 = (!vlr->v4) ? 0 : countClippedFaces(v1, v3, v4, clip_2);
-                               edge_rotation = false;
-                       } else {
-                               numTris_1 = countClippedFaces(v1, v2, v4, clip_1);
-                               numTris_2 = countClippedFaces(v2, v3, v4, clip_2);
-                               edge_rotation = true;
-                               printf("BlenderFileLoader::insertShapeNode: edge rotation is performed.\n");
-                       }
-                       if (numTris_1 == 0 && numTris_2 == 0)
-                               continue;
-                       bool fm, em1, em2, em3, em4;
-                       fm = (vlr->flag & ME_FREESTYLE_FACE) != 0;
-                       em1= (vlr->freestyle_edge_mark & R_EDGE_V1V2) != 0;
-                       em2= (vlr->freestyle_edge_mark & R_EDGE_V2V3) != 0;
-                       if (!vlr->v4) {
-                               em3= (vlr->freestyle_edge_mark & R_EDGE_V3V1) != 0;
-                               em4= false;
-                       } else {
-                               em3= (vlr->freestyle_edge_mark & R_EDGE_V3V4) != 0;
-                               em4= (vlr->freestyle_edge_mark & R_EDGE_V4V1) != 0;
-                       }
+               unsigned int numTris_1, numTris_2;
+               bool edge_rotation;
+               if (!vlr->v4 || !testEdgeRotation(v1, v2, v3, v4)) {
+                       numTris_1 = countClippedFaces(v1, v2, v3, clip_1);
+                       numTris_2 = (!vlr->v4) ? 0 : countClippedFaces(v1, v3, v4, clip_2);
+                       edge_rotation = false;
+               }
+               else {
+                       numTris_1 = countClippedFaces(v1, v2, v4, clip_1);
+                       numTris_2 = countClippedFaces(v2, v3, v4, clip_2);
+                       edge_rotation = true;
+                       printf("BlenderFileLoader::insertShapeNode: edge rotation is performed.\n");
+               }
+               if (numTris_1 == 0 && numTris_2 == 0)
+                       continue;
+               bool fm, em1, em2, em3, em4;
+               fm = (vlr->flag & ME_FREESTYLE_FACE) != 0;
+               em1 = (vlr->freestyle_edge_mark & R_EDGE_V1V2) != 0;
+               em2 = (vlr->freestyle_edge_mark & R_EDGE_V2V3) != 0;
+               if (!vlr->v4) {
+                       em3 = (vlr->freestyle_edge_mark & R_EDGE_V3V1) != 0;
+                       em4 = false;
+               }
+               else {
+                       em3 = (vlr->freestyle_edge_mark & R_EDGE_V3V4) != 0;
+                       em4 = (vlr->freestyle_edge_mark & R_EDGE_V4V1) != 0;
+               }
+
+               Material *mat = vlr->mat;
+               if (mat) {
+                       tmpMat.setDiffuse(mat->r, mat->g, mat->b, mat->alpha);
+                       tmpMat.setSpecular(mat->specr, mat->specg, mat->specb, mat->spectra);
+                       float s = 1.0 * (mat->har + 1) / 4 ; // in Blender: [1;511] => in OpenGL: [0;128]
+                       if (s > 128.f)
+                               s = 128.f;
+                       tmpMat.setShininess(s);
+               }
 
-                       Material *mat = vlr->mat;
-       
-                       if (mat) 
+               if (meshFrsMaterials.empty()) {
+                       meshFrsMaterials.push_back(tmpMat);
+                       shape->setFrsMaterial(tmpMat);
+               }
+               else {
+                       // find if the material is aleady in the list
+                       unsigned int i = 0;
+                       bool found = false;
+
+                       for (vector<FrsMaterial>::iterator it = meshFrsMaterials.begin(), itend = meshFrsMaterials.end();
+                            it != itend;
+                            it++, i++)
                        {
-                           tmpMat.setDiffuse( mat->r, mat->g, mat->b, mat->alpha );
-                           tmpMat.setSpecular( mat->specr, mat->specg, mat->specb, mat->spectra);
-                           float s = 1.0 * (mat->har + 1) / 4 ; // in Blender: [1;511] => in OpenGL: [0;128]
-                           if(s > 128.f)
-                             s = 128.f;
-                           tmpMat.setShininess(s);
+                               if (*it == tmpMat) {
+                                       ls.currentMIndex = i;
+                                       found = true;
+                                       break;
+                               }
                        }
-         
-                       if(meshFrsMaterials.empty())
-                       {
+
+                       if (!found) {
                                meshFrsMaterials.push_back(tmpMat);
-                       shape->setFrsMaterial(tmpMat);
-                       } else {
-                       // find if the material is aleady in the list
-                       unsigned i=0;
-                       bool found = false;
-               
-                       for(vector<FrsMaterial>::iterator it=meshFrsMaterials.begin(), itend=meshFrsMaterials.end();
-                               it!=itend;
-                               ++it){
-                                       if(*it == tmpMat){
-                                               ls.currentMIndex = i;
-                                               found = true;
-                                               break;
-                                       }
-                                       ++i;
-                       }
-               
-                       if(!found){
-                               meshFrsMaterials.push_back(tmpMat);
-                               ls.currentMIndex = meshFrsMaterials.size()-1;
-                       }
-                       }
-
-                       float triCoords[5][3], triNormals[5][3];
-                       bool edgeMarks[5]; // edgeMarks[i] is for the edge between i-th and (i+1)-th vertices
-
-                       if (numTris_1 > 0) {
-                               if (!edge_rotation)
-                                       clipTriangle(numTris_1, triCoords, v1, v2, v3, triNormals, n1, n2, n3,
-                                               edgeMarks, em1, em2, (!vlr->v4) ? em3 : false, clip_1);
-                               else
-                                       clipTriangle(numTris_1, triCoords, v1, v2, v4, triNormals, n1, n2, n4,
-                                               edgeMarks, em1, false, em4, clip_1);
-                               for (i = 0; i < numTris_1; i++) {
-                                       addTriangle(&ls, triCoords[0], triCoords[i+1], triCoords[i+2],
-                                               triNormals[0], triNormals[i+1], triNormals[i+2],
-                                               fm, (i == 0) ? edgeMarks[0] : false, edgeMarks[i+1],
-                                               (i == numTris_1 - 1) ? edgeMarks[i+2] : false);
-                                       _numFacesRead++;
-                               }
+                               ls.currentMIndex = meshFrsMaterials.size() - 1;
                        }
+               }
 
-                       if (numTris_2 > 0) {
-                               if (!edge_rotation)
-                                       clipTriangle(numTris_2, triCoords, v1, v3, v4, triNormals, n1, n3, n4,
-                                               edgeMarks, false, em3, em4, clip_2);
-                               else
-                                       clipTriangle(numTris_2, triCoords, v2, v3, v4, triNormals, n2, n3, n4,
-                                               edgeMarks, em2, em3, false, clip_2);
-                               for (i = 0; i < numTris_2; i++) {
-                                       addTriangle(&ls, triCoords[0], triCoords[i+1], triCoords[i+2],
-                                               triNormals[0], triNormals[i+1], triNormals[i+2],
-                                               fm, (i == 0) ? edgeMarks[0] : false, edgeMarks[i+1],
-                                               (i == numTris_2 - 1) ? edgeMarks[i+2] : false);
-                                       _numFacesRead++;
-                               }
+               float triCoords[5][3], triNormals[5][3];
+               bool edgeMarks[5]; // edgeMarks[i] is for the edge between i-th and (i+1)-th vertices
+
+               if (numTris_1 > 0) {
+                       if (!edge_rotation) {
+                               clipTriangle(numTris_1, triCoords, v1, v2, v3, triNormals, n1, n2, n3,
+                                            edgeMarks, em1, em2, (!vlr->v4) ? em3 : false, clip_1);
+                       }
+                       else {
+                               clipTriangle(numTris_1, triCoords, v1, v2, v4, triNormals, n1, n2, n4,
+                                            edgeMarks, em1, false, em4, clip_1);
+                       }
+                       for (i = 0; i < numTris_1; i++) {
+                               addTriangle(&ls, triCoords[0], triCoords[i+1], triCoords[i+2],
+                                           triNormals[0], triNormals[i+1], triNormals[i+2],
+                                           fm, (i == 0) ? edgeMarks[0] : false, edgeMarks[i+1],
+                                           (i == numTris_1 - 1) ? edgeMarks[i+2] : false);
+                               _numFacesRead++;
                        }
+               }
+
+               if (numTris_2 > 0) {
+                       if (!edge_rotation) {
+                               clipTriangle(numTris_2, triCoords, v1, v3, v4, triNormals, n1, n3, n4,
+                                            edgeMarks, false, em3, em4, clip_2);
+                       }
+                       else {
+                               clipTriangle(numTris_2, triCoords, v2, v3, v4, triNormals, n2, n3, n4,
+                                            edgeMarks, em2, em3, false, clip_2);
+                       }
+                       for (i = 0; i < numTris_2; i++) {
+                               addTriangle(&ls, triCoords[0], triCoords[i+1], triCoords[i+2],
+                                           triNormals[0], triNormals[i+1], triNormals[i+2],
+                                           fm, (i == 0) ? edgeMarks[0] : false, edgeMarks[i+1],
+                                           (i == numTris_2 - 1) ? edgeMarks[i+2] : false);
+                               _numFacesRead++;
+                       }
+               }
        }
-       
+
        // We might have several times the same vertex. We want a clean 
-       // shape with no real-vertex. Here, we are making a cleaning 
-       // pass.
+       // shape with no real-vertex. Here, we are making a cleaning pass.
        real *cleanVertices = NULL;
-       unsigned   cvSize;
-       unsigned   *cleanVIndices = NULL;
-       
-       GeomCleaner::CleanIndexedVertexArray(
-         vertices, vSize, 
-         VIndices, viSize,
-         &cleanVertices, &cvSize, 
-         &cleanVIndices);
-       
+       unsigned int cvSize;
+       unsigned int *cleanVIndices = NULL;
+
+       GeomCleaner::CleanIndexedVertexArray(vertices, vSize, VIndices, viSize, &cleanVertices, &cvSize, &cleanVIndices);
+
        real *cleanNormals = NULL;
-       unsigned   cnSize;
-       unsigned   *cleanNIndices = NULL;
-       
-       GeomCleaner::CleanIndexedVertexArray(
-         normals, nSize, 
-         NIndices, niSize,
-         &cleanNormals, &cnSize, 
-         &cleanNIndices);
-       
+       unsigned int cnSize;
+       unsigned int *cleanNIndices = NULL;
+
+       GeomCleaner::CleanIndexedVertexArray(normals, nSize, NIndices, niSize, &cleanNormals, &cnSize, &cleanNIndices);
+
        // format materials array
        FrsMaterial** marray = new FrsMaterial*[meshFrsMaterials.size()];
-       unsigned mindex=0;
-       for(vector<FrsMaterial>::iterator m=meshFrsMaterials.begin(), mend=meshFrsMaterials.end();
-           m!=mend;
-           ++m){
-         marray[mindex] = new FrsMaterial(*m);
-         ++mindex;
+       unsigned int mindex = 0;
+       for (vector<FrsMaterial>::iterator m = meshFrsMaterials.begin(), mend = meshFrsMaterials.end();
+            m!=mend;
+            ++m)
+       {
+               marray[mindex] = new FrsMaterial(*m);
+               ++mindex;
        }
+
        // deallocates memory:
        delete [] vertices;
        delete [] normals;
@@ -568,21 +633,28 @@ void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id)
                if (v0 == v1 || v0 == v2 || v1 == v2) {
                        continue; // do nothing for now
                }
-               else if (GeomUtils::distPointSegment<Vec3r>(v0, v1, v2) < 1e-6) {
-                       detri.viP = vi0; detri.viA = vi1; detri.viB = vi2;
+               else if (GeomUtils::distPointSegment<Vec3r>(v0, v1, v2) < 1.0e-6) {
+                       detri.viP = vi0;
+                       detri.viA = vi1;
+                       detri.viB = vi2;
                }
-               else if (GeomUtils::distPointSegment<Vec3r>(v1, v0, v2) < 1e-6) {
-                       detri.viP = vi1; detri.viA = vi0; detri.viB = vi2;
+               else if (GeomUtils::distPointSegment<Vec3r>(v1, v0, v2) < 1.0e-6) {
+                       detri.viP = vi1;
+                       detri.viA = vi0;
+                       detri.viB = vi2;
                }
-               else if (GeomUtils::distPointSegment<Vec3r>(v2, v0, v1) < 1e-6) {
-                       detri.viP = vi2; detri.viA = vi0; detri.viB = vi1;
+               else if (GeomUtils::distPointSegment<Vec3r>(v2, v0, v1) < 1.0e-6) {
+                       detri.viP = vi2;
+                       detri.viA = vi0;
+                       detri.viB = vi1;
                }
                else {
                        continue;
                }
+
                detri.v = zero;
                detri.n = 0;
-               for (unsigned j = 0; j < viSize; j += 3) {
+               for (unsigned int j = 0; j < viSize; j += 3) {
                        if (i == j)
                                continue;
                        vi0 = cleanVIndices[j];
@@ -594,19 +666,24 @@ void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id)
                        if (detri.viP == vi0 && (detri.viA == vi1 || detri.viB == vi1)) {
                                detri.v += (v2 - v0);
                                detri.n++;
-                       } else if (detri.viP == vi0 && (detri.viA == vi2 || detri.viB == vi2)) {
+                       }
+                       else if (detri.viP == vi0 && (detri.viA == vi2 || detri.viB == vi2)) {
                                detri.v += (v1 - v0);
                                detri.n++;
-                       } else if (detri.viP == vi1 && (detri.viA == vi0 || detri.viB == vi0)) {
+                       }
+                       else if (detri.viP == vi1 && (detri.viA == vi0 || detri.viB == vi0)) {
                                detri.v += (v2 - v1);
                                detri.n++;
-                       } else if (detri.viP == vi1 && (detri.viA == vi2 || detri.viB == vi2)) {
+                       }
+                       else if (detri.viP == vi1 && (detri.viA == vi2 || detri.viB == vi2)) {
                                detri.v += (v0 - v1);
                                detri.n++;
-                       } else if (detri.viP == vi2 && (detri.viA == vi0 || detri.viB == vi0)) {
+                       }
+                       else if (detri.viP == vi2 && (detri.viA == vi0 || detri.viB == vi0)) {
                                detri.v += (v1 - v2);
                                detri.n++;
-                       } else if (detri.viP == vi2 && (detri.viA == vi1 || detri.viB == vi1)) {
+                       }
+                       else if (detri.viP == vi2 && (detri.viA == vi1 || detri.viB == vi1)) {
                                detri.v += (v0 - v2);
                                detri.n++;
                        }
@@ -616,6 +693,7 @@ void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id)
                }
                detriList.push_back(detri);
        }
+
        if (detriList.size() > 0) {
                vector<detri_t>::iterator v;
                for (v = detriList.begin(); v != detriList.end(); v++) {
@@ -624,43 +702,35 @@ void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id)
                                cleanVertices[detri.viP]   = cleanVertices[detri.viA];
                                cleanVertices[detri.viP+1] = cleanVertices[detri.viA+1];
                                cleanVertices[detri.viP+2] = cleanVertices[detri.viA+2];
-                       } else if (detri.v.norm() > 0.0) {
-                               cleanVertices[detri.viP]   += 1e-5 * detri.v.x();
-                               cleanVertices[detri.viP+1] += 1e-5 * detri.v.y();
-                               cleanVertices[detri.viP+2] += 1e-5 * detri.v.z();
+                       }
+                       else if (detri.v.norm() > 0.0) {
+                               cleanVertices[detri.viP]   += 1.0e-5 * detri.v.x();
+                               cleanVertices[detri.viP+1] += 1.0e-5 * detri.v.y();
+                               cleanVertices[detri.viP+2] += 1.0e-5 * detri.v.z();
                        }
                }
                printf("Warning: Object %s contains %lu degenerated triangle%s (strokes may be incorrect)\n",
-                       name, detriList.size(), (detriList.size() > 1) ? "s" : "");
+                      name, detriList.size(), (detriList.size() > 1) ? "s" : "");
        }
 
        // Create the IndexedFaceSet with the retrieved attributes
        IndexedFaceSet *rep;
-       rep = new IndexedFaceSet(cleanVertices, cvSize, 
-                                cleanNormals, cnSize,
-                                marray, meshFrsMaterials.size(),
-                                0, 0,
-                                numFaces, numVertexPerFaces, faceStyle,
-                                                        faceEdgeMarks,
-                                cleanVIndices, viSize,
-                                cleanNIndices, niSize,
-                                MIndices, viSize,
-                                0,0,
-                                0);
+       rep = new IndexedFaceSet(cleanVertices, cvSize, cleanNormals, cnSize, marray, meshFrsMaterials.size(), 0, 0,
+                                numFaces, numVertexPerFaces, faceStyle, faceEdgeMarks, cleanVIndices, viSize,
+                                cleanNIndices, niSize, MIndices, viSize, 0, 0, 0);
        // sets the id of the rep
        rep->setId(Id(id, 0));
-       rep->setName(obi->ob->id.name+2);
-       
-       const BBox<Vec3r> bbox = BBox<Vec3r>(Vec3r(ls.minBBox[0], ls.minBBox[1], ls.minBBox[2]), 
+       rep->setName(obi->ob->id.name + 2);
+
+       const BBox<Vec3r> bbox = BBox<Vec3r>(Vec3r(ls.minBBox[0], ls.minBBox[1], ls.minBBox[2]),
                                             Vec3r(ls.maxBBox[0], ls.maxBBox[1], ls.maxBBox[2]));
        rep->setBBox(bbox);
        shape->AddRep(rep);
-       
+
        Matrix44r meshMat = Matrix44r::identity();
        currentMesh->setMatrix(meshMat);
-       currentMesh->Translate(0,0,0);
-       
+       currentMesh->Translate(0, 0, 0);
+
        currentMesh->AddChild(shape);
        _Scene->AddChild(currentMesh);
-       
 }
index c5c06567c4116f60ffdca4df335962067af24b01..316cf93a617e95d68390747122bf8f0e2d6af741 100644 (file)
@@ -1,34 +1,68 @@
-#ifndef  BLENDER_FILE_LOADER_H
-# define BLENDER_FILE_LOADER_H
-
-# include <string.h>              
-# include <float.h>
-
-# include "../system/FreestyleConfig.h"
-# include "../system/RenderMonitor.h"
-# include "../scene_graph/NodeGroup.h"
-# include "../scene_graph/NodeTransform.h"
-# include "../scene_graph/NodeShape.h"
-# include "../scene_graph/IndexedFaceSet.h"
-# include "../geometry/BBox.h"
-# include "../geometry/Geom.h"
-# include "../geometry/GeomCleaner.h"
-# include "../geometry/GeomUtils.h"
-
+/*
+ * ***** 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) 2010 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __BLENDER_FILE_LOADER_H__
+#define __BLENDER_FILE_LOADER_H__
+
+/** \file blender/freestyle/intern/blender_interface/BlenderFileLoader.h
+ *  \ingroup freestyle
+ */
+
+#include <string.h>
+#include <float.h>
+
+#include "../geometry/BBox.h"
+#include "../geometry/Geom.h"
+#include "../geometry/GeomCleaner.h"
+#include "../geometry/GeomUtils.h"
+#include "../scene_graph/IndexedFaceSet.h"
+#include "../scene_graph/NodeGroup.h"
+#include "../scene_graph/NodeTransform.h"
+#include "../scene_graph/NodeShape.h"
+#include "../system/FreestyleConfig.h"
+#include "../system/RenderMonitor.h"
+
+// XXX Are those "ifdef __cplusplus" useful here?
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-       #include "DNA_material_types.h"
-       #include "DNA_meshdata_types.h"
-       #include "DNA_scene_types.h"
-       #include "render_types.h"
-       #include "renderdatabase.h"
-       
-       #include "BKE_mesh.h"
-       #include "BKE_scene.h"
-       #include "BLI_math.h"
-       
+#include "DNA_material_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_scene_types.h"
+
+#include "renderdatabase.h"
+#include "render_types.h"
+
+#include "BKE_mesh.h"
+#include "BKE_scene.h"
+
+#include "BLI_math.h"
+
 #ifdef __cplusplus
 }
 #endif
@@ -52,21 +86,21 @@ struct LoaderState {
 class LIB_SCENE_GRAPH_EXPORT BlenderFileLoader
 {
 public:
-  /*! Builds a MaxFileLoader */
+       /*! Builds a MaxFileLoader */
        BlenderFileLoader(Render *re, SceneRenderLayer* srl);
-  virtual ~BlenderFileLoader();
+       virtual ~BlenderFileLoader();
 
-  /*! Loads the 3D scene and returns a pointer to the scene root node */
-  NodeGroup * Load();
+       /*! Loads the 3D scene and returns a pointer to the scene root node */
+       NodeGroup * Load();
 
-  /*! Gets the number of read faces */
-  inline unsigned int numFacesRead() {return _numFacesRead;}
+       /*! Gets the number of read faces */
+       inline unsigned int numFacesRead() {return _numFacesRead;}
 
-  /*! Gets the smallest edge size read */
-  inline real minEdgeSize() {return _minEdgeSize;}
+       /*! Gets the smallest edge size read */
+       inline real minEdgeSize() {return _minEdgeSize;}
 
-  /*! Modifiers */
-  inline void setRenderMonitor(RenderMonitor *iRenderMonitor) {_pRenderMonitor = iRenderMonitor;}
+       /*! Modifiers */
+       inline void setRenderMonitor(RenderMonitor *iRenderMonitor) {_pRenderMonitor = iRenderMonitor;}
 
 protected:
        void insertShapeNode(ObjectInstanceRen *obi, int id);
@@ -75,10 +109,10 @@ protected:
        int countClippedFaces(float v1[3], float v2[3], float v3[3], int clip[3]);
        void clipLine(float v1[3], float v2[3], float c[3], float z);
        void clipTriangle(int numTris, float triCoords[][3], float v1[3], float v2[3], float v3[3],
-               float triNormals[][3], float n1[3], float n2[3], float n3[3],
-               bool edgeMarks[5], bool em1, bool em2, bool em3, int clip[3]);
+                         float triNormals[][3], float n1[3], float n2[3], float n3[3],
+                         bool edgeMarks[5], bool em1, bool em2, bool em3, int clip[3]);
        void addTriangle(struct LoaderState *ls, float v1[3], float v2[3], float v3[3],
-               float n1[3], float n2[3], float n3[3], bool fm, bool em1, bool em2, bool em3);
+                        float n1[3], float n2[3], float n3[3], bool fm, bool em1, bool em2, bool em3);
 
 protected:
        struct detri_t {
@@ -86,9 +120,9 @@ protected:
                Vec3r v;
                unsigned n;
        };
-       Render_re;
-       SceneRenderLayer_srl;
-       NodeGroup_Scene;
+       Render *_re;
+       SceneRenderLayer *_srl;
+       NodeGroup *_Scene;
        unsigned _numFacesRead;
        real _minEdgeSize;
        bool _smooth; /* if true, face smoothness is taken into account */
@@ -101,4 +135,4 @@ protected:
        RenderMonitor *_pRenderMonitor;
 };
 
-#endif // BLENDER_FILE_LOADER_H
+#endif // __BLENDER_FILE_LOADER_H__
index 656d7a236597e84b2ae1501e5d7312a3d375e4c2..e7f974053907cdf16330a5a7b1bb81a316c71826 100644 (file)
@@ -1,9 +1,41 @@
-# include "BlenderStrokeRenderer.h"
-# include "../stroke/Canvas.h"
-# include "../application/AppConfig.h"
-
-# include "BlenderTextureManager.h"
-
+/*
+ * ***** 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) 2010 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
+ *  \ingroup freestyle
+ */
+
+#include "BlenderStrokeRenderer.h"
+#include "BlenderTextureManager.h"
+
+#include "../application/AppConfig.h"
+#include "../stroke/Canvas.h"
+
+// XXX Are those "ifdef __cplusplus" useful here?
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -13,16 +45,16 @@ extern "C" {
 #include "DNA_camera_types.h"
 #include "DNA_customdata_types.h"
 #include "DNA_listBase.h"
-#include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
+#include "DNA_mesh_types.h"
 #include "DNA_object_types.h"
 #include "DNA_screen_types.h"
 
 #include "BKE_customdata.h"
 #include "BKE_global.h"
 #include "BKE_library.h" /* free_libblock */
-#include "BKE_material.h"
 #include "BKE_main.h" /* struct Main */
+#include "BKE_material.h"
 #include "BKE_mesh.h"
 #include "BKE_object.h"
 #include "BKE_scene.h"
@@ -33,79 +65,79 @@ extern "C" {
 }
 #endif
 
-
-BlenderStrokeRenderer::BlenderStrokeRenderer(Render* re, int render_count)
-:StrokeRenderer(){
-       
+BlenderStrokeRenderer::BlenderStrokeRenderer(Render* re, int render_count) : StrokeRenderer()
+{
        // TEMPORARY - need a  texture manager
        _textureManager = new BlenderTextureManager;
        _textureManager->load();
 
-       _width = re->winx; _height = re->winy; // for stroke mesh generation
+       // for stroke mesh generation
+       _width = re->winx;
+       _height = re->winy;
 
-       // Scene.New("FreestyleStrokes")
+       //Scene.New("FreestyleStrokes")
        old_scene = re->scene;
 
        char name[22];
-       snprintf(name, sizeof(name), "FRS%d_%s", render_count, re->scene->id.name+2);
+       BLI_snprintf(name, sizeof(name), "FRS%d_%s", render_count, re->scene->id.name + 2);
        freestyle_scene = BKE_scene_add(name);
        freestyle_scene->r.cfra = old_scene->r.cfra;
-       freestyle_scene->r.mode= old_scene->r.mode &
-               ~( R_EDGE_FRS | R_SHADOW | R_SSS | R_PANORAMA | R_ENVMAP | R_MBLUR | R_BORDER );
-       freestyle_scene->r.xsch= re->rectx; // old_scene->r.xsch
-       freestyle_scene->r.ysch= re->recty; // old_scene->r.ysch
-       freestyle_scene->r.xasp= 1.f; // old_scene->r.xasp;
-       freestyle_scene->r.yasp= 1.f; // old_scene->r.yasp;
-       freestyle_scene->r.tilex= old_scene->r.tilex;
-       freestyle_scene->r.tiley= old_scene->r.tiley;
-       freestyle_scene->r.size= 100; // old_scene->r.size
-       freestyle_scene->r.maximsize= old_scene->r.maximsize;
+       freestyle_scene->r.mode = old_scene->r.mode &
+                                 ~(R_EDGE_FRS | R_SHADOW | R_SSS | R_PANORAMA | R_ENVMAP | R_MBLUR | R_BORDER);
+       freestyle_scene->r.xsch = re->rectx; // old_scene->r.xsch
+       freestyle_scene->r.ysch = re->recty; // old_scene->r.ysch
+       freestyle_scene->r.xasp = 1.0f; // old_scene->r.xasp;
+       freestyle_scene->r.yasp = 1.0f; // old_scene->r.yasp;
+       freestyle_scene->r.tilex = old_scene->r.tilex;
+       freestyle_scene->r.tiley = old_scene->r.tiley;
+       freestyle_scene->r.size = 100; // old_scene->r.size
+       freestyle_scene->r.maximsize = old_scene->r.maximsize;
        freestyle_scene->r.ocres = old_scene->r.ocres;
        freestyle_scene->r.color_mgt_flag = 0; // old_scene->r.color_mgt_flag;
-       freestyle_scene->r.scemode= old_scene->r.scemode & ~( R_SINGLE_LAYER );
-       freestyle_scene->r.flag= old_scene->r.flag;
-       freestyle_scene->r.threads= old_scene->r.threads;
-       freestyle_scene->r.border.xmin= old_scene->r.border.xmin;
-       freestyle_scene->r.border.ymin= old_scene->r.border.ymin;
-       freestyle_scene->r.border.xmax= old_scene->r.border.xmax;
-       freestyle_scene->r.border.ymax= old_scene->r.border.ymax;
+       freestyle_scene->r.scemode = old_scene->r.scemode & ~(R_SINGLE_LAYER);
+       freestyle_scene->r.flag = old_scene->r.flag;
+       freestyle_scene->r.threads = old_scene->r.threads;
+       freestyle_scene->r.border.xmin = old_scene->r.border.xmin;
+       freestyle_scene->r.border.ymin = old_scene->r.border.ymin;
+       freestyle_scene->r.border.xmax = old_scene->r.border.xmax;
+       freestyle_scene->r.border.ymax = old_scene->r.border.ymax;
        strcpy(freestyle_scene->r.pic, old_scene->r.pic);
-       freestyle_scene->r.safety.xmin= old_scene->r.safety.xmin;
-       freestyle_scene->r.safety.ymin= old_scene->r.safety.ymin;
-       freestyle_scene->r.safety.xmax= old_scene->r.safety.xmax;
-       freestyle_scene->r.safety.ymax= old_scene->r.safety.ymax;
-       freestyle_scene->r.osa= old_scene->r.osa;
-       freestyle_scene->r.filtertype= old_scene->r.filtertype;
-       freestyle_scene->r.gauss= old_scene->r.gauss;
-       freestyle_scene->r.dither_intensity= old_scene->r.dither_intensity;
+       freestyle_scene->r.safety.xmin = old_scene->r.safety.xmin;
+       freestyle_scene->r.safety.ymin = old_scene->r.safety.ymin;
+       freestyle_scene->r.safety.xmax = old_scene->r.safety.xmax;
+       freestyle_scene->r.safety.ymax = old_scene->r.safety.ymax;
+       freestyle_scene->r.osa = old_scene->r.osa;
+       freestyle_scene->r.filtertype = old_scene->r.filtertype;
+       freestyle_scene->r.gauss = old_scene->r.gauss;
+       freestyle_scene->r.dither_intensity = old_scene->r.dither_intensity;
        BLI_strncpy(freestyle_scene->r.engine, old_scene->r.engine, sizeof(freestyle_scene->r.engine));
        freestyle_scene->r.im_format.planes = R_IMF_PLANES_RGBA; 
        freestyle_scene->r.im_format.imtype = R_IMF_IMTYPE_PNG;
        BKE_scene_disable_color_management(freestyle_scene);
 
-       BKE_scene_set_background( G.main, freestyle_scene );
+       BKE_scene_set_background(G.main, freestyle_scene);
 
        // Camera
        Object* object_camera = BKE_object_add(freestyle_scene, OB_CAMERA);
-       
-       Camera* camera = (Camera *) object_camera->data;
+
+       Camera* camera = (Camera *)object_camera->data;
        camera->type = CAM_ORTHO;
        camera->ortho_scale = max(re->rectx, re->recty);
-    camera->clipsta = 0.1f;
-    camera->clipend = 100.0f;
+       camera->clipsta = 0.1f;
+       camera->clipend = 100.0f;
 
-    _z_delta = 0.00001f;
-    _z = camera->clipsta + _z_delta;
+       _z_delta = 0.00001f;
+       _z = camera->clipsta + _z_delta;
 
-    // test
-    //_z = 999.90f; _z_delta = 0.01f;
+       // test
+       //_z = 999.90f; _z_delta = 0.01f;
 
        object_camera->loc[0] = re->disprect.xmin + 0.5f * re->rectx;
        object_camera->loc[1] = re->disprect.ymin + 0.5f * re->recty;
-       object_camera->loc[2] = 1.f;
-       
+       object_camera->loc[2] = 1.0f;
+
        freestyle_scene->camera = object_camera;
-       
+
        // Material
        material = BKE_material_add("stroke_material");
        material->mode |= MA_VERTEXCOLP;
@@ -114,12 +146,11 @@ BlenderStrokeRenderer::BlenderStrokeRenderer(Render* re, int render_count)
        material->vcol_alpha = 1;
 }
 
-BlenderStrokeRenderer::~BlenderStrokeRenderer(){
-       
-       if(0 != _textureManager)
-       {
+BlenderStrokeRenderer::~BlenderStrokeRenderer()
+{
+       if (0 != _textureManager) {
                delete _textureManager;
-               _textureManager = 0;
+               _textureManager = NULL;
        }
 
        // The freestyle_scene object is not released here.  Instead,
@@ -128,8 +159,7 @@ BlenderStrokeRenderer::~BlenderStrokeRenderer(){
        // compositor has finished.
 
        // release objects and data blocks
-       Base *b = (Base *)freestyle_scene->base.first;
-       while(b) {
+       for (Base *b = (Base*)freestyle_scene->base.first; b; b = b->next) {
                Object *ob = b->object;
                void *data = ob->data;
                char name[24];
@@ -137,58 +167,58 @@ BlenderStrokeRenderer::~BlenderStrokeRenderer(){
                //cout << "removing " << name[0] << name[1] << ":" << (name+2) << endl;
                switch (ob->type) {
                case OB_MESH:
-                       BKE_libblock_free( &G.main->object, ob );
-                       BKE_libblock_free( &G.main->mesh, data );
+                       BKE_libblock_free(&G.main->object, ob);
+                       BKE_libblock_free(&G.main->mesh, data);
                        break;
                case OB_CAMERA:
-                       BKE_libblock_free( &G.main->object, ob );
-                       BKE_libblock_free( &G.main->camera, data );
+                       BKE_libblock_free(&G.main->object, ob);
+                       BKE_libblock_free(&G.main->camera, data);
                        freestyle_scene->camera = NULL;
                        break;
                default:
                        cerr << "Warning: unexpected object in the scene: " << name[0] << name[1] << ":" << (name+2) << endl;
                }
-               b = b->next;
        }
-       BLI_freelistN( &freestyle_scene->base );
+       BLI_freelistN(&freestyle_scene->base);
 
        // release material
-       BKE_libblock_free( &G.main->mat, material );
-       
-       BKE_scene_set_background( G.main, old_scene );
+       BKE_libblock_free(&G.main->mat, material);
+
+       BKE_scene_set_background(G.main, old_scene);
 }
 
-float BlenderStrokeRenderer::get_stroke_vertex_z(void) const {
-    float z = _z;
-    BlenderStrokeRenderer *self = const_cast<BlenderStrokeRenderer *>(this);
-    if (!(_z < _z_delta * 100000.0f))
-        self->_z_delta *= 10.0f;
-    self->_z += _z_delta;
-    return -z;
+float BlenderStrokeRenderer::get_stroke_vertex_z(void) const
+{
+       float z = _z;
+       BlenderStrokeRenderer *self = const_cast<BlenderStrokeRenderer *>(this);
+       if (!(_z < _z_delta * 100000.0f))
+               self->_z_delta *= 10.0f;
+       self->_z += _z_delta;
+       return -z;
 }
 
-void BlenderStrokeRenderer::RenderStrokeRep(StrokeRep *iStrokeRep) const{
-  RenderStrokeRepBasic(iStrokeRep);
+void BlenderStrokeRenderer::RenderStrokeRep(StrokeRep *iStrokeRep) const
+{
+       RenderStrokeRepBasic(iStrokeRep);
 }
 
-void BlenderStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const{
-       
+void BlenderStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const
+{
        ////////////////////
        //  Build up scene
        ////////////////////
-       
-         vector<Strip*>& strips = iStrokeRep->getStrips();
-         Strip::vertex_container::iterator v[3];
-         StrokeVertexRep *svRep[3];
-         Vec3r color[3];
-         unsigned int vertex_index, edge_index, loop_index;
-         Vec2r p;
-       
-         for(vector<Strip*>::iterator s=strips.begin(), send=strips.end();
-         s!=send;
-         ++s){         
-               
-           Strip::vertex_container& strip_vertices = (*s)->vertices();
+
+       vector<Strip*>& strips = iStrokeRep->getStrips();
+       Strip::vertex_container::iterator v[3];
+       StrokeVertexRep *svRep[3];
+       Vec3r color[3];
+       unsigned int vertex_index, edge_index, loop_index;
+       Vec2r p;
+
+       for (vector<Strip*>::iterator s = strips.begin(), send = strips.end();
+            s != send;
+            ++s){
+               Strip::vertex_container& strip_vertices = (*s)->vertices();
                int strip_vertex_count = (*s)->sizeStrip();
                int xl, xu, yl, yu, n, visible_faces, visible_segments;
                bool visible;
@@ -197,108 +227,120 @@ void BlenderStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const{
                // (note: a strip segment is a series of visible faces, while two strip
                // segments are separated by one or more invisible faces)
                v[0] = strip_vertices.begin();
-           v[1] = v[0]; ++(v[1]);
-           v[2] = v[1]; ++(v[2]);
+               v[1] = v[0] + 1;
+               v[2] = v[0] + 2;
                visible_faces = visible_segments = 0;
                visible = false;
-           for (n = 2; n < strip_vertex_count; n++)
-               {
+               for (n = 2; n < strip_vertex_count; n++, v[0]++, v[1]++, v[2]++) {
                        svRep[0] = *(v[0]);
                        svRep[1] = *(v[1]);
                        svRep[2] = *(v[2]);
                        xl = xu = yl = yu = 0;
                        for (int j = 0; j < 3; j++) {
                                p = svRep[j]->point2d();
-                               if (p[0] < 0.0) xl++; else if (p[0] > _width) xu++;
-                               if (p[1] < 0.0) yl++; else if (p[1] > _height) yu++;
+                               if (p[0] < 0.0)
+                                       xl++;
+                               else if (p[0] > _width)
+                                       xu++;
+                               if (p[1] < 0.0)
+                                       yl++;
+                               else if (p[1] > _height)
+                                       yu++;
                        }
                        if (xl == 3 || xu == 3 || yl == 3 || yu == 3) {
                                visible = false;
-                       } else {
+                       }
+                       else {
                                visible_faces++;
                                if (!visible)
                                        visible_segments++;
                                visible = true;
                        }
-                       ++v[0]; ++v[1]; ++v[2];
                }
                if (visible_faces == 0)
                        continue;
 
-               // me = Mesh.New()
+               //me = Mesh.New()
 #if 0
                Object* object_mesh = BKE_object_add(freestyle_scene, OB_MESH);
 #else
                Object* object_mesh = NewMesh();
 #endif
-               Mesh* mesh = (Mesh *) object_mesh->data;
-               // MEM_freeN(mesh->bb);
-               // mesh->bb= NULL;
-               // mesh->id.us = 0;
-               
+               Mesh* mesh = (Mesh*)object_mesh->data;
+#if 0
+               MEM_freeN(mesh->bb);
+               mesh->bb = NULL;
+               mesh->id.us = 0;
+#endif
 #if 1
-               // me.materials = [mat]
-               mesh->mat = ( Material ** ) MEM_mallocN( 1 * sizeof( Material * ), "MaterialList" );
+               //me.materials = [mat]
+               mesh->mat = (Material**)MEM_mallocN(1 * sizeof(Material*), "MaterialList");
                mesh->mat[0] = material;
                mesh->totcol = 1;
-               test_object_materials( (ID*) mesh );
+               test_object_materials((ID*)mesh);
 #else
-               assign_material(object_mesh, material, object_mesh->totcol+1);
-               object_mesh->actcol= object_mesh->totcol;
+               assign_material(object_mesh, material, object_mesh->totcol + 1);
+               object_mesh->actcol = object_mesh->totcol;
 #endif
 
                // vertices allocation
                mesh->totvert = visible_faces + visible_segments * 2;
-               mesh->mvert = (MVert*) CustomData_add_layer( &mesh->vdata, CD_MVERT, CD_CALLOC, NULL, mesh->totvert);
-                       
+               mesh->mvert = (MVert*)CustomData_add_layer(&mesh->vdata, CD_MVERT, CD_CALLOC, NULL, mesh->totvert);
+
                // edges allocation
                mesh->totedge = visible_faces * 2 + visible_segments;
-               mesh->medge = (MEdge*) CustomData_add_layer( &mesh->edata, CD_MEDGE, CD_CALLOC, NULL, mesh->totedge);
+               mesh->medge = (MEdge*)CustomData_add_layer(&mesh->edata, CD_MEDGE, CD_CALLOC, NULL, mesh->totedge);
 
                // faces allocation
                mesh->totpoly = visible_faces;
-               mesh->mpoly= (MPoly*) CustomData_add_layer( &mesh->pdata, CD_MPOLY, CD_CALLOC, NULL, mesh->totpoly);
+               mesh->mpoly = (MPoly*)CustomData_add_layer(&mesh->pdata, CD_MPOLY, CD_CALLOC, NULL, mesh->totpoly);
 
                // loops allocation
                mesh->totloop = visible_faces * 3;
-               mesh->mloop= (MLoop*) CustomData_add_layer( &mesh->ldata, CD_MLOOP, CD_CALLOC, NULL, mesh->totloop);
-               
+               mesh->mloop = (MLoop*)CustomData_add_layer(&mesh->ldata, CD_MLOOP, CD_CALLOC, NULL, mesh->totloop);
+
                // colors allocation
-               mesh->mloopcol = (MLoopCol *) CustomData_add_layer( &mesh->ldata, CD_MLOOPCOL, CD_CALLOC, NULL, mesh->totloop);
+               mesh->mloopcol = (MLoopCol*)CustomData_add_layer(&mesh->ldata, CD_MLOOPCOL, CD_CALLOC, NULL, mesh->totloop);
 
                ////////////////////
                //  Data copy
                ////////////////////
-               
-               MVertvertices = mesh->mvert;
-               MEdgeedges = mesh->medge;
-               MPolypolys = mesh->mpoly;
-               MLooploops = mesh->mloop;
-               MLoopColcolors = mesh->mloopcol;
+
+               MVert *vertices = mesh->mvert;
+               MEdge *edges = mesh->medge;
+               MPoly *polys = mesh->mpoly;
+               MLoop *loops = mesh->mloop;
+               MLoopCol *colors = mesh->mloopcol;
 
                v[0] = strip_vertices.begin();
-           v[1] = v[0]; ++(v[1]);
-           v[2] = v[1]; ++(v[2]);
+               v[1] = v[0] + 1;
+               v[2] = v[0] + 2;
 
                vertex_index = edge_index = loop_index = 0;
                visible = false;
 
                // Note: Mesh generation in the following loop assumes stroke strips
                // to be triangle strips.
-               for (n = 2; n < strip_vertex_count; n++)
-               {
+               for (n = 2; n < strip_vertex_count; n++, v[0]++, v[1]++, v[2]++) {
                        svRep[0] = *(v[0]);
                        svRep[1] = *(v[1]);
                        svRep[2] = *(v[2]);
                        xl = xu = yl = yu = 0;
                        for (int j = 0; j < 3; j++) {
                                p = svRep[j]->point2d();
-                               if (p[0] < 0.0) xl++; else if (p[0] > _width) xu++;
-                               if (p[1] < 0.0) yl++; else if (p[1] > _height) yu++;
+                               if (p[0] < 0.0)
+                                       xl++;
+                               else if (p[0] > _width)
+                                       xu++;
+                               if (p[1] < 0.0)
+                                       yl++;
+                               else if (p[1] > _height)
+                                       yu++;
                        }
                        if (xl == 3 || xu == 3 || yl == 3 || yu == 3) {
                                visible = false;
-                       } else {
+                       }
+                       else {
                                if (!visible) {
                                        // first vertex
                                        vertices->co[0] = svRep[0]->point2d()[0];
@@ -306,7 +348,7 @@ void BlenderStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const{
                                        vertices->co[2] = get_stroke_vertex_z();
                                        ++vertices;
                                        ++vertex_index;
-                                       
+
                                        // second vertex
                                        vertices->co[0] = svRep[1]->point2d()[0];
                                        vertices->co[1] = svRep[1]->point2d()[1];
@@ -355,7 +397,8 @@ void BlenderStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const{
 
                                        loops[2].v = vertex_index - 3;
                                        loops[2].e = edge_index - 2;
-                               } else {
+                               }
+                               else {
                                        loops[0].v = vertex_index - 1;
                                        loops[0].e = edge_index - 2;
 
@@ -370,52 +413,49 @@ void BlenderStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const{
 
                                // colors
                                if (n % 2 == 0) {
-                                       colors[0].r = (short)(255.0f*svRep[2]->color()[0]);
-                                       colors[0].g = (short)(255.0f*svRep[2]->color()[1]);
-                                       colors[0].b = (short)(255.0f*svRep[2]->color()[2]);
-                                       colors[0].a = (short)(255.0f*svRep[2]->alpha());
-                                       
-                                       colors[1].r = (short)(255.0f*svRep[1]->color()[0]);
-                                       colors[1].g = (short)(255.0f*svRep[1]->color()[1]);
-                                       colors[1].b = (short)(255.0f*svRep[1]->color()[2]);
-                                       colors[1].a = (short)(255.0f*svRep[1]->alpha());
-                                       
-                                       colors[2].r = (short)(255.0f*svRep[0]->color()[0]);
-                                       colors[2].g = (short)(255.0f*svRep[0]->color()[1]);
-                                       colors[2].b = (short)(255.0f*svRep[0]->color()[2]);
-                                       colors[2].a = (short)(255.0f*svRep[0]->alpha());
-                               } else {
-                                       colors[0].r = (short)(255.0f*svRep[2]->color()[0]);
-                                       colors[0].g = (short)(255.0f*svRep[2]->color()[1]);
-                                       colors[0].b = (short)(255.0f*svRep[2]->color()[2]);
-                                       colors[0].a = (short)(255.0f*svRep[2]->alpha());
-                                       
-                                       colors[1].r = (short)(255.0f*svRep[0]->color()[0]);
-                                       colors[1].g = (short)(255.0f*svRep[0]->color()[1]);
-                                       colors[1].b = (short)(255.0f*svRep[0]->color()[2]);
-                                       colors[1].a = (short)(255.0f*svRep[0]->alpha());
-                                       
-                                       colors[2].r = (short)(255.0f*svRep[1]->color()[0]);
-                                       colors[2].g = (short)(255.0f*svRep[1]->color()[1]);
-                                       colors[2].b = (short)(255.0f*svRep[1]->color()[2]);
-                                       colors[2].a = (short)(255.0f*svRep[1]->alpha());
+                                       colors[0].r = (short)(255.0f * svRep[2]->color()[0]);
+                                       colors[0].g = (short)(255.0f * svRep[2]->color()[1]);
+                                       colors[0].b = (short)(255.0f * svRep[2]->color()[2]);
+                                       colors[0].a = (short)(255.0f * svRep[2]->alpha());
+
+                                       colors[1].r = (short)(255.0f * svRep[1]->color()[0]);
+                                       colors[1].g = (short)(255.0f * svRep[1]->color()[1]);
+                                       colors[1].b = (short)(255.0f * svRep[1]->color()[2]);
+                                       colors[1].a = (short)(255.0f * svRep[1]->alpha());
+
+                                       colors[2].r = (short)(255.0f * svRep[0]->color()[0]);
+                                       colors[2].g = (short)(255.0f * svRep[0]->color()[1]);
+                                       colors[2].b = (short)(255.0f * svRep[0]->color()[2]);
+                                       colors[2].a = (short)(255.0f * svRep[0]->alpha());
+                               }
+                               else {
+                                       colors[0].r = (short)(255.0f * svRep[2]->color()[0]);
+                                       colors[0].g = (short)(255.0f * svRep[2]->color()[1]);
+                                       colors[0].b = (short)(255.0f * svRep[2]->color()[2]);
+                                       colors[0].a = (short)(255.0f * svRep[2]->alpha());
+
+                                       colors[1].r = (short)(255.0f * svRep[0]->color()[0]);
+                                       colors[1].g = (short)(255.0f * svRep[0]->color()[1]);
+                                       colors[1].b = (short)(255.0f * svRep[0]->color()[2]);
+                                       colors[1].a = (short)(255.0f * svRep[0]->alpha());
+
+                                       colors[2].r = (short)(255.0f * svRep[1]->color()[0]);
+                                       colors[2].g = (short)(255.0f * svRep[1]->color()[1]);
+                                       colors[2].b = (short)(255.0f * svRep[1]->color()[2]);
+                                       colors[2].a = (short)(255.0f * svRep[1]->alpha());
                                }
                                colors += 3;
-
                        }
-                       ++v[0]; ++v[1]; ++v[2];
-
-               } // loop over strip vertices 
+               } // loop over strip vertices
 #if 0
                BKE_mesh_validate(mesh, TRUE);
 #endif
-
-       } // loop over strips   
-
+       } // loop over strips
 }
 
 // A replacement of BKE_object_add() for better performance.
-Object* BlenderStrokeRenderer::NewMesh() const {
+Object *BlenderStrokeRenderer::NewMesh() const
+{
        Object *ob;
        Base *base;
        char name[MAX_ID_NAME];
@@ -428,8 +468,10 @@ Object* BlenderStrokeRenderer::NewMesh() const {
        ob->lay = 1;
 
        base = BKE_scene_base_add(freestyle_scene, ob);
-       //BKE_scene_base_deselect_all(scene);
-       //BKE_scene_base_select(scene, base);
+#if 0
+       BKE_scene_base_deselect_all(scene);
+       BKE_scene_base_select(scene, base);
+#endif
        ob->recalc |= OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME;
 
        --mesh_id;
@@ -437,11 +479,12 @@ Object* BlenderStrokeRenderer::NewMesh() const {
        return ob;
 }
 
-Render* BlenderStrokeRenderer::RenderScene( Render *re ) {
-    Camera *camera = (Camera *)freestyle_scene->camera->data;
-    if (camera->clipend < _z)
-        camera->clipend = _z + _z_delta * 100.0f;
-    //cout << "clipsta " << camera->clipsta << ", clipend " << camera->clipend << endl;
+Render* BlenderStrokeRenderer::RenderScene(Render *re)
+{
+       Camera *camera = (Camera*)freestyle_scene->camera->data;
+       if (camera->clipend < _z)
+               camera->clipend = _z + _z_delta * 100.0f;
+       //cout << "clipsta " << camera->clipsta << ", clipend " << camera->clipend << endl;
 
        Render *freestyle_render = RE_NewRender(freestyle_scene->id.name);
 
index 022a115456f3248080fdada31bc85e3060877c25..d1c82e7a3b478e69e0ddc439b63b2a0f05e00c98 100644 (file)
@@ -1,9 +1,41 @@
-#ifndef  BLENDERSTROKERENDERER_H
-# define BLENDERSTROKERENDERER_H
+/*
+ * ***** 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) 2010 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
 
-# include "../stroke/StrokeRenderer.h"
-# include "../system/FreestyleConfig.h"
+#ifndef __BLENDERSTROKERENDERER_H__
+#define __BLENDERSTROKERENDERER_H__
 
+/** \file blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.h
+ *  \ingroup freestyle
+ */
+
+#include "../stroke/StrokeRenderer.h"
+#include "../system/FreestyleConfig.h"
+
+// XXX Are those "ifdef __cplusplus" useful here?
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -17,31 +49,28 @@ extern "C" {
 }
 #endif
 
-
-
 class LIB_STROKE_EXPORT BlenderStrokeRenderer : public StrokeRenderer
 {
 public:
-  BlenderStrokeRenderer(Render *re, int render_count);
-  virtual ~BlenderStrokeRenderer();
+       BlenderStrokeRenderer(Render *re, int render_count);
+       virtual ~BlenderStrokeRenderer();
 
-  /*! Renders a stroke rep */
-  virtual void RenderStrokeRep(StrokeRep *iStrokeRep) const;
-  virtual void RenderStrokeRepBasic(StrokeRep *iStrokeRep) const;
+       /*! Renders a stroke rep */
+       virtual void RenderStrokeRep(StrokeRep *iStrokeRep) const;
+       virtual void RenderStrokeRepBasic(StrokeRep *iStrokeRep) const;
 
-  Object* NewMesh() const;
+       Object *NewMesh() const;
 
-       RenderRenderScene(Render *re);
+       Render *RenderScene(Render *re);
 
 protected:
-       Sceneold_scene;
-       Scenefreestyle_scene;
-       Materialmaterial;
+       Scene *old_scene;
+       Scene *freestyle_scene;
+       Material *material;
        float _width, _height;
        float _z, _z_delta;
 
        float get_stroke_vertex_z(void) const;
 };
 
-#endif // BLENDERSTROKERENDERER_H
-
+#endif // __BLENDERSTROKERENDERER_H__
index 93b5f694eb68cc0987db39b882dde0df6afe9c48..4c6f7e02722f1b866c2af5790644a60ca9bbe1e3 100644 (file)
@@ -1,5 +1,36 @@
-#ifndef BLENDERSTYLEMODULE_H
-#define BLENDERSTYLEMODULE_H
+/*
+ * ***** 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) 2010 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __BLENDERSTYLEMODULE_H__
+#define __BLENDERSTYLEMODULE_H__
+
+/** \file blender/freestyle/intern/blender_interface/BlenderStyleModule.h
+ *  \ingroup freestyle
+ */
 
 #include "../stroke/StyleModule.h"
 #include "../system/PythonInterpreter.h"
@@ -12,21 +43,21 @@ extern "C" {
 
 class BlenderStyleModule : public StyleModule
 {
-public:        
-
-       BlenderStyleModule(struct Text *text, const string &name,
-               Interpreter *inter) : StyleModule(name, inter) {
+public:
+       BlenderStyleModule(struct Text *text, const string &name, Interpreter *inter) : StyleModule(name, inter)
+       {
                _text = text;
        }
 
-       virtual ~BlenderStyleModule() {
+       virtual ~BlenderStyleModule()
+       {
                BKE_text_unlink(G.main, _text);
                BKE_libblock_free(&G.main->text, _text);
        }
 
 protected:
-
-       virtual int interpret() {
+       virtual int interpret()
+       {
                PythonInterpreter* py_inter = dynamic_cast<PythonInterpreter*>(_inter);
                assert(py_inter != 0);
                return py_inter->interpretText(_text, getFileName());
@@ -36,4 +67,4 @@ private:
        struct Text *_text;
 };
 
-#endif // BLENDERSTYLEMODULE_H
+#endif // __BLENDERSTYLEMODULE_H__
index d731af42d0ecc4c66eca7b9f1a607cfd26f758d8..053ad63683777aa13f7d6e05da542637afcd6f1f 100644 (file)
@@ -1,71 +1,98 @@
-#include "BlenderTextureManager.h"
+/*
+ * ***** 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) 2010 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/freestyle/intern/blender_interface/BlenderTextureManager.cpp
+ *  \ingroup freestyle
+ */
 
+#include "BlenderTextureManager.h"
 
-BlenderTextureManager::BlenderTextureManager ()
+BlenderTextureManager::BlenderTextureManager()
 : TextureManager()
 {
-  //_brushes_path = Config::getInstance()...
+       //_brushes_path = Config::getInstance()...
 }
 
-BlenderTextureManager::~BlenderTextureManager ()
+BlenderTextureManager::~BlenderTextureManager()
 {
 }
 
 void BlenderTextureManager::loadStandardBrushes()
 {
-  //  getBrushTextureIndex(TEXTURES_DIR "/brushes/charcoalAlpha.bmp", Stroke::HUMID_MEDIUM);
-  //  getBrushTextureIndex(TEXTURES_DIR "/brushes/washbrushAlpha.bmp", Stroke::HUMID_MEDIUM);
-  //  getBrushTextureIndex(TEXTURES_DIR "/brushes/oil.bmp", Stroke::HUMID_MEDIUM);
-  //  getBrushTextureIndex(TEXTURES_DIR "/brushes/oilnoblend.bmp", Stroke::HUMID_MEDIUM);
-  //  getBrushTextureIndex(TEXTURES_DIR "/brushes/charcoalAlpha.bmp", Stroke::DRY_MEDIUM);
-  //  getBrushTextureIndex(TEXTURES_DIR "/brushes/washbrushAlpha.bmp", Stroke::DRY_MEDIUM);
-  //  getBrushTextureIndex(TEXTURES_DIR "/brushes/opaqueDryBrushAlpha.bmp", Stroke::OPAQUE_MEDIUM);
-  //  getBrushTextureIndex(TEXTURES_DIR "/brushes/opaqueBrushAlpha.bmp", Stroke::OPAQUE_MEDIUM);
-  //_defaultTextureId = getBrushTextureIndex("smoothAlpha.bmp", Stroke::OPAQUE_MEDIUM);
+#if 0
+       getBrushTextureIndex(TEXTURES_DIR "/brushes/charcoalAlpha.bmp", Stroke::HUMID_MEDIUM);
+       getBrushTextureIndex(TEXTURES_DIR "/brushes/washbrushAlpha.bmp", Stroke::HUMID_MEDIUM);
+       getBrushTextureIndex(TEXTURES_DIR "/brushes/oil.bmp", Stroke::HUMID_MEDIUM);
+       getBrushTextureIndex(TEXTURES_DIR "/brushes/oilnoblend.bmp", Stroke::HUMID_MEDIUM);
+       getBrushTextureIndex(TEXTURES_DIR "/brushes/charcoalAlpha.bmp", Stroke::DRY_MEDIUM);
+       getBrushTextureIndex(TEXTURES_DIR "/brushes/washbrushAlpha.bmp", Stroke::DRY_MEDIUM);
+       getBrushTextureIndex(TEXTURES_DIR "/brushes/opaqueDryBrushAlpha.bmp", Stroke::OPAQUE_MEDIUM);
+       getBrushTextureIndex(TEXTURES_DIR "/brushes/opaqueBrushAlpha.bmp", Stroke::OPAQUE_MEDIUM);
+       _defaultTextureId = getBrushTextureIndex("smoothAlpha.bmp", Stroke::OPAQUE_MEDIUM);
+#endif
 }
 
-
-unsigned
-BlenderTextureManager::loadBrush(string sname, Stroke::MediumType mediumType)
+unsigned int BlenderTextureManager::loadBrush(string sname, Stroke::MediumType mediumType)
 {
-//   GLuint texId;
-//   glGenTextures(1, &texId);
-//   bool found = false;
-//   vector<string> pathnames;
-//   string path; //soc
-//   StringUtils::getPathName(TextureManager::Options::getBrushesPath(),
-//   sname,
-//   pathnames);
-//   for (vector<string>::const_iterator j = pathnames.begin(); j != pathnames.end(); j++) {
-//     path = j->c_str();
-//     //soc if(QFile::exists(path)){
-//     if( BLI_exists( const_cast<char *>(path.c_str()) ) ) {
-//       found = true;
-//       break;
-//     }
-//   }
-//   if(!found)
-//     return 0;
-//   // Brush texture
-//   cout << "Loading brush texture..." << endl;
-//   switch(mediumType){
-//   case Stroke::DRY_MEDIUM:
-//     //soc prepareTextureLuminance((const char*)path.toAscii(), texId);
-//     prepareTextureLuminance(StringUtils::toAscii(path), texId);
-//     break;
-//   case Stroke::HUMID_MEDIUM:
-//   case Stroke::OPAQUE_MEDIUM:
-//   default:
-//     //soc prepareTextureAlpha((const char*)path.toAscii(), texId);
-//     prepareTextureAlpha(StringUtils::toAscii(path), texId);
-//     break;
-//   }
-//   cout << "Done." << endl << endl;
-// 
-//   return texId;
-//
+#if 0
+       GLuint texId;
+       glGenTextures(1, &texId);
+       bool found = false;
+       vector<string> pathnames;
+       string path; //soc
+       StringUtils::getPathName(TextureManager::Options::getBrushesPath(), sname, pathnames);
+       for (vector<string>::const_iterator j = pathnames.begin(); j != pathnames.end(); j++) {
+               path = j->c_str();
+               //soc if (QFile::exists(path)) {
+               if (BLI_exists( const_cast<char *>(path.c_str()))) {
+                       found = true;
+                       break;
+               }
+       }
+       if (!found)
+               return 0;
+       // Brush texture
+       cout << "Loading brush texture..." << endl;
+       switch (mediumType) {
+       case Stroke::DRY_MEDIUM:
+               //soc prepareTextureLuminance((const char*)path.toAscii(), texId);
+               prepareTextureLuminance(StringUtils::toAscii(path), texId);
+               break;
+       case Stroke::HUMID_MEDIUM:
+       case Stroke::OPAQUE_MEDIUM:
+       default:
+               //soc prepareTextureAlpha((const char*)path.toAscii(), texId);
+               prepareTextureAlpha(StringUtils::toAscii(path), texId);
+               break;
+       }
+       cout << "Done." << endl << endl;
+
+       return texId;
+#else
        return 0;
+#endif
 }
-
-
-
index fac33c139e183f58acff91a963d7b66365484fad..bd6f377b1eba5835c792322fb990826121c4bd71 100644 (file)
@@ -1,23 +1,53 @@
-#ifndef  BLENDERTEXTUREMANAGER_H
-#define BLENDERTEXTUREMANAGER_H
+/*
+ * ***** 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) 2010 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __BLENDERTEXTUREMANAGER_H__
+#define __BLENDERTEXTUREMANAGER_H__
+
+/** \file blender/freestyle/intern/blender_interface/BlenderTextureManager.h
+ *  \ingroup freestyle
+ */
 
 # include "../stroke/StrokeRenderer.h"
 # include "../stroke/StrokeRep.h"
 # include "../system/FreestyleConfig.h"
 
-/*! Class to load textures
- */
+/*! Class to load textures */
 class LIB_RENDERING_EXPORT BlenderTextureManager : public TextureManager
 {
- public:
-  BlenderTextureManager ();
-  virtual ~BlenderTextureManager ();
+public:
+       BlenderTextureManager();
+       virtual ~BlenderTextureManager();
+
 protected:
-  virtual unsigned loadBrush(string fileName, Stroke::MediumType = Stroke::OPAQUE_MEDIUM);
-  
- protected:
-  virtual void loadStandardBrushes();
+       virtual unsigned int loadBrush(string fileName, Stroke::MediumType=Stroke::OPAQUE_MEDIUM);
 
+protected:
+       virtual void loadStandardBrushes();
 };
 
-#endif // BLENDERTEXTUREMANAGER_H
+#endif // __BLENDERTEXTUREMANAGER_H__
index e432815a30f5ebf9e0db1213695f2bcee8d255b0..759bf09380f29892d0f903698088de2ba8c3600e 100644 (file)
@@ -1,13 +1,46 @@
-#include "../application/Controller.h"
-#include "../application/AppView.h"
-#include "../application/AppConfig.h"
-#include "../application/AppCanvas.h"
+/*
+ * ***** 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) 2010 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
+ *  \ingroup freestyle
+ */
 
 #include <iostream>
 #include <map>
 #include <set>
+
+#include "../application/AppCanvas.h"
+#include "../application/AppConfig.h"
+#include "../application/AppView.h"
+#include "../application/Controller.h"
+
 using namespace std;
 
+// XXX Are those "ifdef __cplusplus" useful here?
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -15,725 +48,781 @@ extern "C" {
 #include "MEM_guardedalloc.h"
 
 #include "DNA_camera_types.h"
-#include "DNA_text_types.h"
-#include "DNA_group_types.h"
 #include "DNA_freestyle_types.h"
+#include "DNA_group_types.h"
+#include "DNA_text_types.h"
 
 #include "BKE_global.h"
 #include "BKE_library.h"
 #include "BKE_linestyle.h"
 #include "BKE_main.h"
 #include "BKE_text.h"
+
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
+
 #include "BPY_extern.h"
 
 #include "renderpipeline.h"
 #include "pixelblending.h"
 
-#include "../../FRS_freestyle.h"
-#include "../../FRS_freestyle_config.h"
-
-#define DEFAULT_SPHERE_RADIUS  1.0f
-#define DEFAULT_DKR_EPSILON    0.0f
-
-       // Freestyle configuration
-       static short freestyle_is_initialized = 0;
-       static Config::Path *pathconfig = NULL;
-       static Controller *controller = NULL;
-       static AppView *view = NULL;
-
-       // line set buffer for copy & paste
-       static FreestyleLineSet lineset_buffer;
-       static bool lineset_copied = false;
-
-       // camera information
-       float freestyle_viewpoint[3];
-       float freestyle_mv[4][4];
-       float freestyle_proj[4][4];
-       int freestyle_viewport[4];
-       
-       // current scene
-       Scene *freestyle_scene;
-
-       string default_module_path;
-
-       //=======================================================
-       //   Initialization 
-       //=======================================================
-
-       void FRS_initialize() {
-               
-               if( freestyle_is_initialized )
-                       return;
-
-               pathconfig = new Config::Path;
-               controller = new Controller();
-               view = new AppView;
-               controller->setView(view);
-               controller->Clear();
-               freestyle_scene = NULL;
-               lineset_copied = false;
-                       
-               default_module_path = pathconfig->getProjectDir() + Config::DIR_SEP + "style_modules" + Config::DIR_SEP + "contour.py";
-                       
-               freestyle_is_initialized = 1;
-       }
-       
-       void FRS_set_context(bContext* C) {
-               cout << "FRS_set_context: context 0x" << C << " scene 0x" << CTX_data_scene(C) << endl;
-               controller->setContext(C);
-       }
+#include "FRS_freestyle.h"
+#include "FRS_freestyle_config.h"
 
-       void FRS_read_file(bContext* C) {
-               lineset_copied = false;
-       }
+#define DEFAULT_SPHERE_RADIUS 1.0f
+#define DEFAULT_DKR_EPSILON   0.0f
 
-       void FRS_exit() {
-               delete pathconfig;
-               delete controller;
-               delete view;
-       }
+// Freestyle configuration
+static short freestyle_is_initialized = 0;
+static Config::Path *pathconfig = NULL;
+static Controller *controller = NULL;
+static AppView *view = NULL;
 
-       //=======================================================
-       //   Rendering 
-       //=======================================================
-
-       static void init_view(Render* re){
-               int width = re->winx;
-               int height = re->winy;
-               int xmin = re->disprect.xmin;
-               int ymin = re->disprect.ymin;
-               int xmax = re->disprect.xmax;
-               int ymax = re->disprect.ymax;
-               
-               float thickness = 1.f;
-               switch (re->r.line_thickness_mode) {
-               case R_LINE_THICKNESS_ABSOLUTE:
-                       thickness = re->r.unit_line_thickness * (re->r.size / 100.f);
-                       break;
-               case R_LINE_THICKNESS_RELATIVE:
-                       thickness = height / 480.f;
-                       break;
-               }
+// line set buffer for copy & paste
+static FreestyleLineSet lineset_buffer;
+static bool lineset_copied = false;
 
-               freestyle_viewport[0] = freestyle_viewport[1] = 0;
-               freestyle_viewport[2] = width;
-               freestyle_viewport[3] = height;
-               
-               view->setWidth( width );
-               view->setHeight( height );
-               view->setBorder( xmin, ymin, xmax, ymax );
-               view->setThickness( thickness );
-
-               cout << "\n===  Dimensions of the 2D image coordinate system  ===" << endl;
-               cout << "Width  : " << width << endl;
-               cout << "Height : " << height << endl;
-               if (re->r.mode & R_BORDER)
-                       cout << "Border : (" << xmin << ", " << ymin << ") - (" << xmax << ", " << ymax << ")" << endl;
-               cout << "Unit line thickness : " << thickness << " pixel(s)" << endl;
-       }
+// camera information
+float freestyle_viewpoint[3];
+float freestyle_mv[4][4];
+float freestyle_proj[4][4];
+int freestyle_viewport[4];
 
-       static void init_camera(Render* re){
-               // It is assumed that imported meshes are in the camera coordinate system.
-               // Therefore, the view point (i.e., camera position) is at the origin, and
-               // the the model-view matrix is simply the identity matrix.
-
-               freestyle_viewpoint[0] = 0.0;
-               freestyle_viewpoint[1] = 0.0;
-               freestyle_viewpoint[2] = 0.0;
-               
-               for( int i = 0; i < 4; i++ )
-                  for( int j = 0; j < 4; j++ )
-                       freestyle_mv[i][j] = (i == j) ? 1.0 : 0.0;
-               
-               for( int i = 0; i < 4; i++ )
-                  for( int j = 0; j < 4; j++ )
-                       freestyle_proj[i][j] = re->winmat[i][j];
+// current scene
+Scene *freestyle_scene;
 
-               //print_m4("mv", freestyle_mv);
-               //print_m4("proj", freestyle_proj);
-       }
+string default_module_path;
 
-       static char *escape_quotes(char *name)
-       {
-               char *s= (char *)MEM_mallocN(strlen(name) * 2 + 1, "escape_quotes");
-               char *p= s;
-               while (*name) {
-                       if (*name == '\'')
-                               *p++= '\\';
-                       *p++ = *name++;
-               }
-               *p = '\0';
-               return s;
+//=======================================================
+//   Initialization 
+//=======================================================
+
+void FRS_initialize()
+{
+       if (freestyle_is_initialized)
+               return;
+
+       pathconfig = new Config::Path;
+       controller = new Controller();
+       view = new AppView;
+       controller->setView(view);
+       controller->Clear();
+       freestyle_scene = NULL;
+       lineset_copied = false;
+
+       default_module_path = pathconfig->getProjectDir() + Config::DIR_SEP + "style_modules" +
+                             Config::DIR_SEP + "contour.py";
+
+       freestyle_is_initialized = 1;
+}
+
+void FRS_set_context(bContext *C)
+{
+       cout << "FRS_set_context: context 0x" << C << " scene 0x" << CTX_data_scene(C) << endl;
+       controller->setContext(C);
+}
+
+void FRS_read_file(bContext *C)
+{
+       lineset_copied = false;
+}
+
+void FRS_exit()
+{
+       delete pathconfig;
+       delete controller;
+       delete view;
+}
+
+//=======================================================
+//   Rendering 
+//=======================================================
+
+static void init_view(Render *re)
+{
+       int width = re->winx;
+       int height = re->winy;
+       int xmin = re->disprect.xmin;
+       int ymin = re->disprect.ymin;
+       int xmax = re->disprect.xmax;
+       int ymax = re->disprect.ymax;
+
+       float thickness = 1.0f;
+       switch (re->r.line_thickness_mode) {
+       case R_LINE_THICKNESS_ABSOLUTE:
+               thickness = re->r.unit_line_thickness * (re->r.size / 100.f);
+               break;
+       case R_LINE_THICKNESS_RELATIVE:
+               thickness = height / 480.f;
+               break;
+       }
+
+       freestyle_viewport[0] = freestyle_viewport[1] = 0;
+       freestyle_viewport[2] = width;
+       freestyle_viewport[3] = height;
+
+       view->setWidth(width);
+       view->setHeight(height);
+       view->setBorder(xmin, ymin, xmax, ymax);
+       view->setThickness(thickness);
+
+       cout << "\n===  Dimensions of the 2D image coordinate system  ===" << endl;
+       cout << "Width  : " << width << endl;
+       cout << "Height : " << height << endl;
+       if (re->r.mode & R_BORDER)
+               cout << "Border : (" << xmin << ", " << ymin << ") - (" << xmax << ", " << ymax << ")" << endl;
+       cout << "Unit line thickness : " << thickness << " pixel(s)" << endl;
+}
+
+static void init_camera(Render *re)
+{
+       // It is assumed that imported meshes are in the camera coordinate system.
+       // Therefore, the view point (i.e., camera position) is at the origin, and
+       // the the model-view matrix is simply the identity matrix.
+
+       freestyle_viewpoint[0] = 0.0;
+       freestyle_viewpoint[1] = 0.0;
+       freestyle_viewpoint[2] = 0.0;
+
+       for (int i = 0; i < 4; i++) {
+               for (int j = 0; j < 4; j++)
+                       freestyle_mv[i][j] = (i == j) ? 1.0 : 0.0;
        }
 
-       static Text *create_lineset_handler(char *layer_name, char *lineset_name)
-       {
-               char *s1= escape_quotes(layer_name);
-               char *s2= escape_quotes(lineset_name);
-               Text *text= BKE_text_add(lineset_name);
-               BKE_text_write(text, "import parameter_editor; parameter_editor.process('");
-               BKE_text_write(text, s1);
-               BKE_text_write(text, "', '");
-               BKE_text_write(text, s2);
-               BKE_text_write(text, "')\n");
-               MEM_freeN(s1);
-               MEM_freeN(s2);
-               return text;
+       for (int i = 0; i < 4; i++) {
+               for (int j = 0; j < 4; j++)
+                       freestyle_proj[i][j] = re->winmat[i][j];
        }
 
-       struct edge_type_condition {
-               int edge_type, value;
-       };
-
-       // examines the conditions and returns true if the target edge type needs to be computed
-       static bool test_edge_type_conditions(struct edge_type_condition *conditions,
-               int num_edge_types, bool logical_and, int target, bool distinct)
-       {
-               int target_condition = 0;
-               int num_non_target_positive_conditions = 0;
-               int num_non_target_negative_conditions = 0;
-
-               for (int i = 0; i < num_edge_types; i++) {
-                       if (conditions[i].edge_type == target)
-                               target_condition = conditions[i].value;
-                       else if (conditions[i].value > 0)
-                               ++num_non_target_positive_conditions;
-                       else if (conditions[i].value < 0)
-                               ++num_non_target_negative_conditions;
+#if 0
+       print_m4("mv", freestyle_mv);
+       print_m4("proj", freestyle_proj);
+#endif
+}
+
+static char *escape_quotes(char *name)
+{
+       char *s = (char*)MEM_mallocN(strlen(name) * 2 + 1, "escape_quotes");
+       char *p = s;
+       while (*name) {
+               if (*name == '\'')
+                       *(p++) = '\\';
+               *(p++) = *(name++);
+       }
+       *p = '\0';
+       return s;
+}
+
+static Text *create_lineset_handler(char *layer_name, char *lineset_name)
+{
+       char *s1 = escape_quotes(layer_name);
+       char *s2 = escape_quotes(lineset_name);
+       Text *text = BKE_text_add(lineset_name);
+       BKE_text_write(text, "import parameter_editor; parameter_editor.process('");
+       BKE_text_write(text, s1);
+       BKE_text_write(text, "', '");
+       BKE_text_write(text, s2);
+       BKE_text_write(text, "')\n");
+       MEM_freeN(s1);
+       MEM_freeN(s2);
+       return text;
+}
+
+struct edge_type_condition
+{
+       int edge_type, value;
+};
+
+// examines the conditions and returns true if the target edge type needs to be computed
+static bool test_edge_type_conditions(struct edge_type_condition *conditions,
+                                      int num_edge_types, bool logical_and, int target, bool distinct)
+{
+       int target_condition = 0;
+       int num_non_target_positive_conditions = 0;
+       int num_non_target_negative_conditions = 0;
+
+       for (int i = 0; i < num_edge_types; i++) {
+               if (conditions[i].edge_type == target)
+                       target_condition = conditions[i].value;
+               else if (conditions[i].value > 0)
+                       ++num_non_target_positive_conditions;
+               else if (conditions[i].value < 0)
+                       ++num_non_target_negative_conditions;
+       }
+       if (distinct) {
+               // In this case, the 'target' edge type is assumed to appear on distinct edge
+               // of its own and never together with other edge types.
+               if (logical_and) {
+                       if (num_non_target_positive_conditions > 0)
+                               return false;
+                       if (target_condition > 0)
+                               return true;
+                       if (target_condition < 0)
+                               return false;
+                       if (num_non_target_negative_conditions > 0)
+                               return true;
                }
-               if (distinct) {
-                       // In this case, the 'target' edge type is assumed to appear on distinct edge
-                       // of its own and never together with other edge types.
-                       if (logical_and) {
-                               if (num_non_target_positive_conditions > 0)
-                                       return false;
-                               if (target_condition > 0)
-                                       return true;
-                               if (target_condition < 0)
-                                       return false;
-                               if (num_non_target_negative_conditions > 0)
-                                       return true;
-                       } else {
-                               if (target_condition > 0)
-                                       return true;
-                               if (num_non_target_negative_conditions > 0)
-                                       return true;
-                               if (target_condition < 0)
-                                       return false;
-                               if (num_non_target_positive_conditions > 0)
-                                       return false;
-                       }
-               } else {
-                       // In this case, the 'target' edge type may appear together with other edge types.
+               else {
                        if (target_condition > 0)
                                return true;
+                       if (num_non_target_negative_conditions > 0)
+                               return true;
                        if (target_condition < 0)
+                               return false;
+                       if (num_non_target_positive_conditions > 0)
+                               return false;
+               }
+       }
+       else {
+               // In this case, the 'target' edge type may appear together with other edge types.
+               if (target_condition > 0)
+                       return true;
+               if (target_condition < 0)
+                       return true;
+               if (logical_and) {
+                       if (num_non_target_positive_conditions > 0)
+                               return false;
+                       if (num_non_target_negative_conditions > 0)
                                return true;
-                       if (logical_and) {
-                               if (num_non_target_positive_conditions > 0)
-                                       return false;
-                               if (num_non_target_negative_conditions > 0)
-                                       return true;
-                       } else {
-                               if (num_non_target_negative_conditions > 0)
-                                       return true;
-                               if (num_non_target_positive_conditions > 0)
-                                       return false;
-                       }
                }
-               return true;
+               else {
+                       if (num_non_target_negative_conditions > 0)
+                               return true;
+                       if (num_non_target_positive_conditions > 0)
+                               return false;
+               }
        }
+       return true;
+}
 
-       static void prepare(Render* re, SceneRenderLayer* srl ) {
-                               
-               // load mesh
-        re->i.infostr= "Freestyle: Mesh loading";
-               re->stats_draw(re->sdh, &re->i);
-        re->i.infostr= NULL;
-               if( controller->LoadMesh(re, srl) ) // returns if scene cannot be loaded or if empty
-                       return;
-        if( re->test_break(re->tbh) )
-            return;
-               
-               // add style modules
-               FreestyleConfig* config = &srl->freestyleConfig;
-               
-               cout << "\n===  Rendering options  ===" << endl;
-               int layer_count = 0;
-               
-               switch (config->mode) {
-               case FREESTYLE_CONTROL_SCRIPT_MODE:
-                       cout << "Modules :"<< endl;
-                       for (FreestyleModuleConfig* module_conf = (FreestyleModuleConfig *)config->modules.first; module_conf; module_conf = module_conf->next) {
-                               if( module_conf->is_displayed ) {
-                                       cout << "  " << layer_count+1 << ": " << module_conf->module_path << endl;
-                                       controller->InsertStyleModule( layer_count, module_conf->module_path );
-                                       controller->toggleLayer(layer_count, true);
-                                       layer_count++;
-                               }
+static void prepare(Render *re, SceneRenderLayer *srl)
+{
+       // load mesh
+       re->i.infostr = "Freestyle: Mesh loading";
+       re->stats_draw(re->sdh, &re->i);
+       re->i.infostr = NULL;
+       if (controller->LoadMesh(re, srl)) // returns if scene cannot be loaded or if empty
+               return;
+       if (re->test_break(re->tbh))
+               return;
+
+       // add style modules
+       FreestyleConfig *config = &srl->freestyleConfig;
+
+       cout << "\n===  Rendering options  ===" << endl;
+       int layer_count = 0;
+
+       switch (config->mode) {
+       case FREESTYLE_CONTROL_SCRIPT_MODE:
+               cout << "Modules :" << endl;
+               for (FreestyleModuleConfig *module_conf = (FreestyleModuleConfig*)config->modules.first;
+                    module_conf;
+                    module_conf = module_conf->next)
+               {
+                       if(module_conf->is_displayed) {
+                               cout << "  " << layer_count+1 << ": " << module_conf->module_path << endl;
+                               controller->InsertStyleModule(layer_count, module_conf->module_path);
+                               controller->toggleLayer(layer_count, true);
+                               layer_count++;
                        }
-                       cout << endl;
-                       controller->setComputeRidgesAndValleysFlag( (config->flags & FREESTYLE_RIDGES_AND_VALLEYS_FLAG) ? true : false);
-                       controller->setComputeSuggestiveContoursFlag( (config->flags & FREESTYLE_SUGGESTIVE_CONTOURS_FLAG) ? true : false);
-                       controller->setComputeMaterialBoundariesFlag( (config->flags & FREESTYLE_MATERIAL_BOUNDARIES_FLAG) ? true : false);
-                       break;
-               case FREESTYLE_CONTROL_EDITOR_MODE:
-                       int use_ridges_and_valleys = 0;
-                       int use_suggestive_contours = 0;
-                       int use_material_boundaries = 0;
-                       struct edge_type_condition conditions[] = {
-                               {FREESTYLE_FE_SILHOUETTE, 0},
-                               {FREESTYLE_FE_BORDER, 0},
-                               {FREESTYLE_FE_CREASE, 0},
-                               {FREESTYLE_FE_RIDGE_VALLEY, 0},
-                               {FREESTYLE_FE_SUGGESTIVE_CONTOUR, 0},
-                               {FREESTYLE_FE_MATERIAL_BOUNDARY, 0},
-                               {FREESTYLE_FE_CONTOUR, 0},
-                               {FREESTYLE_FE_EXTERNAL_CONTOUR, 0},
-                               {FREESTYLE_FE_EDGE_MARK, 0}};
-                       int num_edge_types = sizeof(conditions) / sizeof(struct edge_type_condition);
-                       cout << "Linesets:"<< endl;
-                       for (FreestyleLineSet *lineset = (FreestyleLineSet *)config->linesets.first; lineset; lineset = lineset->next) {
-                               if (lineset->flags & FREESTYLE_LINESET_ENABLED) {
-                                       cout << "  " << layer_count+1 << ": " << lineset->name << " - " << lineset->linestyle->id.name+2 << endl;
-                                       Text *text = create_lineset_handler(srl->name, lineset->name);
-                                       controller->InsertStyleModule( layer_count, lineset->name, text );
-                                       controller->toggleLayer(layer_count, true);
-                                       if (!(lineset->selection & FREESTYLE_SEL_EDGE_TYPES) || !lineset->edge_types) {
+               }
+               cout << endl;
+               controller->setComputeRidgesAndValleysFlag((config->flags & FREESTYLE_RIDGES_AND_VALLEYS_FLAG) ? true : false);
+               controller->setComputeSuggestiveContoursFlag((config->flags & FREESTYLE_SUGGESTIVE_CONTOURS_FLAG) ? true : false);
+               controller->setComputeMaterialBoundariesFlag((config->flags & FREESTYLE_MATERIAL_BOUNDARIES_FLAG) ? true : false);
+               break;
+       case FREESTYLE_CONTROL_EDITOR_MODE:
+               int use_ridges_and_valleys = 0;
+               int use_suggestive_contours = 0;
+               int use_material_boundaries = 0;
+               struct edge_type_condition conditions[] = {
+                       {FREESTYLE_FE_SILHOUETTE, 0},
+                       {FREESTYLE_FE_BORDER, 0},
+                       {FREESTYLE_FE_CREASE, 0},
+                       {FREESTYLE_FE_RIDGE_VALLEY, 0},
+                       {FREESTYLE_FE_SUGGESTIVE_CONTOUR, 0},
+                       {FREESTYLE_FE_MATERIAL_BOUNDARY, 0},
+                       {FREESTYLE_FE_CONTOUR, 0},
+                       {FREESTYLE_FE_EXTERNAL_CONTOUR, 0},
+                       {FREESTYLE_FE_EDGE_MARK, 0}
+               };
+               int num_edge_types = sizeof(conditions) / sizeof(struct edge_type_condition);
+               cout << "Linesets:" << endl;
+               for (FreestyleLineSet *lineset = (FreestyleLineSet*)config->linesets.first;
+                    lineset;
+                    lineset = lineset->next)
+               {
+                       if (lineset->flags & FREESTYLE_LINESET_ENABLED) {
+                               cout << "  " << layer_count+1 << ": " << lineset->name << " - "
+                                    << lineset->linestyle->id.name+2 << endl;
+                               Text *text = create_lineset_handler(srl->name, lineset->name);
+                               controller->InsertStyleModule(layer_count, lineset->name, text);
+                               controller->toggleLayer(layer_count, true);
+                               if (!(lineset->selection & FREESTYLE_SEL_EDGE_TYPES) || !lineset->edge_types) {
+                                       ++use_ridges_and_valleys;
+                                       ++use_suggestive_contours;
+                                       ++use_material_boundaries;
+                               }
+                               else {
+                                       // conditions for feature edge selection by edge types
+                                       for (int i = 0; i < num_edge_types; i++) {
+                                               if (!(lineset->edge_types & conditions[i].edge_type))
+                                                       conditions[i].value = 0; // no condition specified
+                                               else if (!(lineset->exclude_edge_types & conditions[i].edge_type))
+                                                       conditions[i].value = 1; // condition: X
+                                               else
+                                                       conditions[i].value = -1; // condition: NOT X
+                                       }
+                                       // logical operator for the selection conditions
+                                       bool logical_and = ((lineset->flags & FREESTYLE_LINESET_FE_AND) != 0);
+                                       // negation operator
+                                       if (lineset->flags & FREESTYLE_LINESET_FE_NOT) {
+                                               // convert an Exclusive condition into an Inclusive equivalent using De Morgan's laws:
+                                               //   NOT (X OR Y) --> (NOT X) AND (NOT Y)
+                                               //   NOT (X AND Y) --> (NOT X) OR (NOT Y)
+                                               for (int i = 0; i < num_edge_types; i++)
+                                                       conditions[i].value *= -1;
+                                               logical_and = !logical_and;
+                                       }
+                                       if (test_edge_type_conditions(conditions, num_edge_types, logical_and,
+                                                                     FREESTYLE_FE_RIDGE_VALLEY, true))
+                                       {
                                                ++use_ridges_and_valleys;
+                                       }
+                                       if (test_edge_type_conditions(conditions, num_edge_types, logical_and,
+                                                                     FREESTYLE_FE_SUGGESTIVE_CONTOUR, true))
+                                       {
                                                ++use_suggestive_contours;
+                                       }
+                                       if (test_edge_type_conditions(conditions, num_edge_types, logical_and,
+                                                                     FREESTYLE_FE_MATERIAL_BOUNDARY, true))
+                                       {
                                                ++use_material_boundaries;
-                                       } else {
-                                               // conditions for feature edge selection by edge types
-                                               for (int i = 0; i < num_edge_types; i++) {
-                                                       if (!(lineset->edge_types & conditions[i].edge_type))
-                                                               conditions[i].value = 0; // no condition specified
-                                                       else if (!(lineset->exclude_edge_types & conditions[i].edge_type))
-                                                               conditions[i].value = 1; // condition: X
-                                                       else
-                                                               conditions[i].value = -1; // condition: NOT X
-                                               }
-                                               // logical operator for the selection conditions
-                                               bool logical_and = ((lineset->flags & FREESTYLE_LINESET_FE_AND) != 0);
-                                               // negation operator
-                                               if (lineset->flags & FREESTYLE_LINESET_FE_NOT) {
-                                                       // convert an Exclusive condition into an Inclusive equivalent using De Morgan's laws:
-                                                       //   NOT (X OR Y) --> (NOT X) AND (NOT Y)
-                                                       //   NOT (X AND Y) --> (NOT X) OR (NOT Y)
-                                                       for (int i = 0; i < num_edge_types; i++)
-                                                               conditions[i].value *= -1;
-                                                       logical_and = !logical_and;
-                                               }
-                                               if (test_edge_type_conditions(conditions, num_edge_types, logical_and, FREESTYLE_FE_RIDGE_VALLEY, true))
-                                                       ++use_ridges_and_valleys;
-                                               if (test_edge_type_conditions(conditions, num_edge_types, logical_and, FREESTYLE_FE_SUGGESTIVE_CONTOUR, true))
-                                                       ++use_suggestive_contours;
-                                               if (test_edge_type_conditions(conditions, num_edge_types, logical_and, FREESTYLE_FE_MATERIAL_BOUNDARY, true))
-                                                       ++use_material_boundaries;
                                        }
-                                       layer_count++;
                                }
+                               layer_count++;
                        }
-                       controller->setComputeRidgesAndValleysFlag( use_ridges_and_valleys > 0 );
-                       controller->setComputeSuggestiveContoursFlag( use_suggestive_contours > 0 );
-                       controller->setComputeMaterialBoundariesFlag( use_material_boundaries > 0 );
-                       break;
                }
-               
-               // set parameters
-               if (config->flags & FREESTYLE_ADVANCED_OPTIONS_FLAG) {
-                       controller->setSphereRadius( config->sphere_radius );
-                       controller->setSuggestiveContourKrDerivativeEpsilon( config->dkr_epsilon );
-               } else {
-                       controller->setSphereRadius( DEFAULT_SPHERE_RADIUS );
-                       controller->setSuggestiveContourKrDerivativeEpsilon( DEFAULT_DKR_EPSILON );
+               controller->setComputeRidgesAndValleysFlag(use_ridges_and_valleys > 0);
+               controller->setComputeSuggestiveContoursFlag(use_suggestive_contours > 0);
+               controller->setComputeMaterialBoundariesFlag(use_material_boundaries > 0);
+               break;
+       }
+
+       // set parameters
+       if (config->flags & FREESTYLE_ADVANCED_OPTIONS_FLAG) {
+               controller->setSphereRadius(config->sphere_radius);
+               controller->setSuggestiveContourKrDerivativeEpsilon(config->dkr_epsilon);
+       }
+       else {
+               controller->setSphereRadius(DEFAULT_SPHERE_RADIUS);
+               controller->setSuggestiveContourKrDerivativeEpsilon(DEFAULT_DKR_EPSILON);
+       }
+       controller->setFaceSmoothness((config->flags & FREESTYLE_FACE_SMOOTHNESS_FLAG) ? true : false);
+       controller->setCreaseAngle(RAD2DEGF(config->crease_angle));
+       controller->setVisibilityAlgo((config->flags & FREESTYLE_CULLING) ?
+                                     FREESTYLE_ALGO_CULLED_ADAPTIVE_CUMULATIVE :
+                                     FREESTYLE_ALGO_ADAPTIVE_CUMULATIVE);
+
+       cout << "Crease angle : " << controller->getCreaseAngle() << endl;
+       cout << "Sphere radius : " << controller->getSphereRadius() << endl;
+       cout << "Face smoothness : " << (controller->getFaceSmoothness() ? "enabled" : "disabled") << endl;
+       cout << "Redges and valleys : " << (controller->getComputeRidgesAndValleysFlag() ? "enabled" : "disabled") << endl;
+       cout << "Suggestive contours : " << (controller->getComputeSuggestiveContoursFlag() ? "enabled" : "disabled")
+            << endl;
+       cout << "Suggestive contour Kr derivative epsilon : " << controller->getSuggestiveContourKrDerivativeEpsilon()
+            << endl;
+       cout << "Material boundaries : " << (controller->getComputeMaterialBoundariesFlag() ? "enabled" : "disabled")
+            << endl;
+       cout << endl;
+
+       // set diffuse and z depth passes
+       RenderLayer *rl = RE_GetRenderLayer(re->result, srl->name);
+       bool diffuse = false, z = false;
+       for (RenderPass *rpass = (RenderPass*)rl->passes.first; rpass; rpass = rpass->next) {
+               switch (rpass->passtype) {
+               case SCE_PASS_DIFFUSE:
+                       controller->setPassDiffuse(rpass->rect, rpass->rectx, rpass->recty);
+                       diffuse = true;
+                       break;
+               case SCE_PASS_Z:
+                       controller->setPassZ(rpass->rect, rpass->rectx, rpass->recty);
+                       z = true;
+                       break;
                }
-               controller->setFaceSmoothness( (config->flags & FREESTYLE_FACE_SMOOTHNESS_FLAG) ? true : false);
-               controller->setCreaseAngle( RAD2DEGF(config->crease_angle) );
-               controller->setVisibilityAlgo( (config->flags & FREESTYLE_CULLING) ?
-                       FREESTYLE_ALGO_CULLED_ADAPTIVE_CUMULATIVE : FREESTYLE_ALGO_ADAPTIVE_CUMULATIVE );
-
-               cout << "Crease angle : " << controller->getCreaseAngle() << endl;
-               cout << "Sphere radius : " << controller->getSphereRadius() << endl;
-               cout << "Face smoothness : " << (controller->getFaceSmoothness() ? "enabled" : "disabled") << endl;
-               cout << "Redges and valleys : " << (controller->getComputeRidgesAndValleysFlag() ? "enabled" : "disabled") << endl;
-               cout << "Suggestive contours : " << (controller->getComputeSuggestiveContoursFlag() ? "enabled" : "disabled") << endl;
-               cout << "Suggestive contour Kr derivative epsilon : " << controller->getSuggestiveContourKrDerivativeEpsilon() << endl;
-               cout << "Material boundaries : " << (controller->getComputeMaterialBoundariesFlag() ? "enabled" : "disabled") << endl;
-               cout << endl;
+       }
+       cout << "Passes :" << endl;
+       cout << "  Diffuse = " << (diffuse ? "enabled" : "disabled") << endl;
+       cout << "  Z = " << (z ? "enabled" : "disabled") << endl;
 
-        // set diffuse and z depth passes
-        RenderLayer *rl = RE_GetRenderLayer(re->result, srl->name);
-               bool diffuse = false, z = false;
-               for (RenderPass *rpass = (RenderPass *)rl->passes.first; rpass; rpass = rpass->next) {
-                       switch (rpass->passtype) {
-                       case SCE_PASS_DIFFUSE:
-                               controller->setPassDiffuse(rpass->rect, rpass->rectx, rpass->recty);
-                               diffuse = true;
-                               break;
-                       case SCE_PASS_Z:
-                               controller->setPassZ(rpass->rect, rpass->rectx, rpass->recty);
-                               z = true;
-                               break;
-                       }
-               }
-        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);
+       re->i.infostr = NULL;
+       controller->ComputeViewMap();
+}
 
-               // compute view map
-        re->i.infostr= "Freestyle: View map creation";
-               re->stats_draw(re->sdh, &re->i);
-        re->i.infostr= NULL;
-               controller->ComputeViewMap();
-       }
-       
-       void FRS_composite_result(Render* re, SceneRenderLayer* srl, Render* freestyle_render)
-       {
-               RenderLayer *rl;
-           float *src, *dest, *pixSrc, *pixDest;
-               int x, y, rectx, recty;
-               
-               if( freestyle_render == NULL || freestyle_render->result == NULL )
-                       return;
-
-               rl = render_get_active_layer( freestyle_render, freestyle_render->result );
-           if( !rl || rl->rectf == NULL) { cout << "Cannot find Freestyle result image" << endl; return; }
-               src  = rl->rectf;
-               //cout << "src: " << rl->rectx << " x " << rl->recty << endl;
-               
-               rl = RE_GetRenderLayer(re->result, srl->name);
-           if( !rl || rl->rectf == NULL) { cout << "No layer to composite to" << endl; return; }
-               dest  = rl->rectf;
-               //cout << "dest: " << rl->rectx << " x " << rl->recty << endl;
-
-               rectx = re->rectx;
-               recty = re->recty;
-               for( y = 0; y < recty; y++) {
-               for( x = 0; x < rectx; x++) {
-                   pixSrc = src + 4 * (rectx * y + x);
-                   if( pixSrc[3] > 0.0) {
-                                       pixDest = dest + 4 * (rectx * y + x);
-                                       addAlphaOverFloat(pixDest, pixSrc);
-                               }
+void FRS_composite_result(Render* re, SceneRenderLayer* srl, Render* freestyle_render)
+{
+       RenderLayer *rl;
+       float *src, *dest, *pixSrc, *pixDest;
+       int x, y, rectx, recty;
+
+       if (freestyle_render == NULL || freestyle_render->result == NULL)
+               return;
+
+       rl = render_get_active_layer( freestyle_render, freestyle_render->result );
+       if (!rl || rl->rectf == NULL) {
+               cout << "Cannot find Freestyle result image" << endl;
+               return;
+       }
+       src  = rl->rectf;
+       //cout << "src: " << rl->rectx << " x " << rl->recty << endl;
+
+       rl = RE_GetRenderLayer(re->result, srl->name);
+       if (!rl || rl->rectf == NULL) {
+               cout << "No layer to composite to" << endl;
+               return;
+       }
+       dest = rl->rectf;
+       //cout << "dest: " << rl->rectx << " x " << rl->recty << endl;
+
+       rectx = re->rectx;
+       recty = re->recty;
+       for (y = 0; y < recty; y++) {
+               for (x = 0; x < rectx; x++) {
+                       pixSrc = src + 4 * (rectx * y + x);
+                       if (pixSrc[3] > 0.0) {
+                               pixDest = dest + 4 * (rectx * y + x);
+                               addAlphaOverFloat(pixDest, pixSrc);
                        }
-           }
-       }
-       
-       static int displayed_layer_count( SceneRenderLayer* srl ) {
-               int count = 0;
-
-               switch (srl->freestyleConfig.mode) {
-               case FREESTYLE_CONTROL_SCRIPT_MODE:
-                       for (FreestyleModuleConfig* module = (FreestyleModuleConfig *)srl->freestyleConfig.modules.first; module; module = module->next) {
-                               if( module->is_displayed )
-                                       count++;
-                       }
-                       break;
-               case FREESTYLE_CONTROL_EDITOR_MODE:
-                       for (FreestyleLineSet *lineset = (FreestyleLineSet *)srl->freestyleConfig.linesets.first; lineset; lineset = lineset->next) {
-                               if (lineset->flags & FREESTYLE_LINESET_ENABLED)
-                                       count++;
-                       }
-                       break;
                }
-               return count;
        }
+}
 
-       int FRS_is_freestyle_enabled(SceneRenderLayer* srl) {
-               return (!(srl->layflag & SCE_LAY_DISABLE) &&
-                               srl->layflag & SCE_LAY_FRS &&
-                               displayed_layer_count(srl) > 0);
+static int displayed_layer_count(SceneRenderLayer *srl)
+{
+       int count = 0;
+
+       switch (srl->freestyleConfig.mode) {
+       case FREESTYLE_CONTROL_SCRIPT_MODE:
+               for (FreestyleModuleConfig *module = (FreestyleModuleConfig*)srl->freestyleConfig.modules.first;
+                    module;
+                    module = module->next)
+               {
+                       if (module->is_displayed)
+                               count++;
+               }
+               break;
+       case FREESTYLE_CONTROL_EDITOR_MODE:
+               for (FreestyleLineSet *lineset = (FreestyleLineSet*)srl->freestyleConfig.linesets.first;
+                    lineset;
+                    lineset = lineset->next)
+               {
+                       if (lineset->flags & FREESTYLE_LINESET_ENABLED)
+                               count++;
+               }
+               break;
        }
-       
-       void FRS_init_stroke_rendering(Render* re) {
+       return count;
+}
+
+int FRS_is_freestyle_enabled(SceneRenderLayer *srl)
+{
+       return (!(srl->layflag & SCE_LAY_DISABLE) && srl->layflag & SCE_LAY_FRS && displayed_layer_count(srl) > 0);
+}
 
-               cout << "\n#===============================================================" << endl;
-               cout << "#  Freestyle" << endl;
-               cout << "#===============================================================" << endl;
-               
-               init_view(re);
-               init_camera(re);
+void FRS_init_stroke_rendering(Render *re)
+{
+       cout << endl;
+       cout << "#===============================================================" << endl;
+       cout << "#  Freestyle" << endl;
+       cout << "#===============================================================" << endl;
 
-               controller->ResetRenderCount();
-       }
-       
-       Render* FRS_do_stroke_rendering(Render* re, SceneRenderLayer *srl) {
-               
-               Render* freestyle_render = NULL;
-
-               RenderMonitor monitor(re);
-               controller->setRenderMonitor(&monitor);
-               
-               cout << "\n----------------------------------------------------------" << endl;
-               cout << "|  " << (re->scene->id.name+2) << "|" << srl->name << endl;
-               cout << "----------------------------------------------------------" << endl;
-               
-               // prepare Freestyle:
-               //   - load mesh
-               //   - add style modules
-               //   - set parameters
-               //   - compute view map
-               prepare(re, srl);
-
-        if( re->test_break(re->tbh) ) {
-                       controller->CloseFile();
-                       cout << "Break" << endl;
-            return NULL;
-        }
-
-               // render and composite Freestyle result
-               if( controller->_ViewMap ) {
-                       
-                       // render strokes                                       
-            re->i.infostr= "Freestyle: Stroke rendering";
-            re->stats_draw(re->sdh, &re->i);
-               re->i.infostr= NULL;
-                       freestyle_scene = re->scene;
-                       controller->DrawStrokes();
-                       freestyle_render = controller->RenderStrokes(re);
-                       controller->CloseFile();
-                       freestyle_scene = NULL;
-                       
-                       // composite result
-                       FRS_composite_result(re, srl, freestyle_render);
-                       RE_FreeRenderResult(freestyle_render->result);
-                       freestyle_render->result = NULL;
-               }
+       init_view(re);
+       init_camera(re);
+
+       controller->ResetRenderCount();
+}
 
-               return freestyle_render;
+Render *FRS_do_stroke_rendering(Render *re, SceneRenderLayer *srl)
+{
+       Render *freestyle_render = NULL;
+
+       RenderMonitor monitor(re);
+       controller->setRenderMonitor(&monitor);
+
+       cout << endl;
+       cout << "----------------------------------------------------------" << endl;
+       cout << "|  " << (re->scene->id.name + 2) << "|" << srl->name << endl;
+       cout << "----------------------------------------------------------" << endl;
+
+       // prepare Freestyle:
+       //   - load mesh
+       //   - add style modules
+       //   - set parameters
+       //   - compute view map
+       prepare(re, srl);
+
+       if (re->test_break(re->tbh)) {
+               controller->CloseFile();
+               cout << "Break" << endl;
+               return NULL;
        }
 
-       void FRS_finish_stroke_rendering(Render* re) {
-               // clear canvas
-               controller->Clear();
+       // render and composite Freestyle result
+       if (controller->_ViewMap) {
+               // render strokes
+               re->i.infostr = "Freestyle: Stroke rendering";
+               re->stats_draw(re->sdh, &re->i);
+               re->i.infostr = NULL;
+               freestyle_scene = re->scene;
+               controller->DrawStrokes();
+               freestyle_render = controller->RenderStrokes(re);
+               controller->CloseFile();
+               freestyle_scene = NULL;
+
+               // composite result
+               FRS_composite_result(re, srl, freestyle_render);
+               RE_FreeRenderResult(freestyle_render->result);
+               freestyle_render->result = NULL;
        }
 
-       //=======================================================
-       //   Freestyle Panel Configuration
-       //=======================================================
+       return freestyle_render;
+}
+
+void FRS_finish_stroke_rendering(Render *re) {
+       // clear canvas
+       controller->Clear();
+}
 
-       void FRS_add_freestyle_config( SceneRenderLayer* srl )
-       {               
-               FreestyleConfig* config = &srl->freestyleConfig;
-               
-               config->mode = FREESTYLE_CONTROL_SCRIPT_MODE;
+//=======================================================
+//   Freestyle Panel Configuration
+//=======================================================
 
-               config->modules.first = config->modules.last = NULL;
-               config->flags = 0;
-               config->sphere_radius = DEFAULT_SPHERE_RADIUS;
-               config->dkr_epsilon = DEFAULT_DKR_EPSILON;
-               config->crease_angle = 134.43f;
+void FRS_add_freestyle_config(SceneRenderLayer *srl)
+{
+       FreestyleConfig *config = &srl->freestyleConfig;
 
-               config->linesets.first = config->linesets.last = NULL;
-       }
-       
-       void FRS_free_freestyle_config( SceneRenderLayer* srl )
-       {               
-               FreestyleLineSet *lineset;
-
-               for(lineset=(FreestyleLineSet *)srl->freestyleConfig.linesets.first; lineset; lineset=lineset->next) {
-                       if (lineset->group) {
-                               lineset->group->id.us--;
-                               lineset->group = NULL;
-                       }
-                       lineset->linestyle->id.us--;
-                       lineset->linestyle = NULL;
+       config->mode = FREESTYLE_CONTROL_SCRIPT_MODE;
+
+       config->modules.first = config->modules.last = NULL;
+       config->flags = 0;
+       config->sphere_radius = DEFAULT_SPHERE_RADIUS;
+       config->dkr_epsilon = DEFAULT_DKR_EPSILON;
+       config->crease_angle = DEG2RADF(120.0f);
+
+       config->linesets.first = config->linesets.last = NULL;
+}
+
+void FRS_free_freestyle_config(SceneRenderLayer *srl)
+{
+       FreestyleLineSet *lineset;
+
+       for (lineset = (FreestyleLineSet*)srl->freestyleConfig.linesets.first; lineset; lineset = lineset->next) {
+               if (lineset->group) {
+                       lineset->group->id.us--;
+                       lineset->group = NULL;
                }
-               BLI_freelistN( &srl->freestyleConfig.linesets );
-               BLI_freelistN( &srl->freestyleConfig.modules );
+               lineset->linestyle->id.us--;
+               lineset->linestyle = NULL;
        }
+       BLI_freelistN(&srl->freestyleConfig.linesets);
+       BLI_freelistN(&srl->freestyleConfig.modules);
+}
 
-       void FRS_add_module(FreestyleConfig *config)
-       {
-               FreestyleModuleConfig* module_conf = (FreestyleModuleConfig*) MEM_callocN( sizeof(FreestyleModuleConfig), "style module configuration");
-               BLI_addtail(&config->modules, (void*) module_conf);
-               
-               strcpy( module_conf->module_path, default_module_path.c_str() );
-               module_conf->is_displayed = 1;  
-       }
-       
-       void FRS_delete_module(FreestyleConfig *config, FreestyleModuleConfig *module_conf)
-       {
-               BLI_freelinkN(&config->modules, module_conf);
-       }
-       
-       void FRS_move_module_up(FreestyleConfig *config, FreestyleModuleConfig *module_conf)
-       {
-               BLI_remlink(&config->modules, module_conf);
-               BLI_insertlinkbefore(&config->modules, module_conf->prev, module_conf);
-       }
-       
-       void FRS_move_module_down(FreestyleConfig *config, FreestyleModuleConfig *module_conf)
-       {                       
-               BLI_remlink(&config->modules, module_conf);
-               BLI_insertlinkafter(&config->modules, module_conf->next, module_conf);
-       }
+void FRS_add_module(FreestyleConfig *config)
+{
+       FreestyleModuleConfig *module_conf = (FreestyleModuleConfig*)MEM_callocN(sizeof(FreestyleModuleConfig),
+                                                                                "style module configuration");
+       BLI_addtail(&config->modules, (void*)module_conf);
 
-       static void unique_lineset_name(FreestyleConfig *config, FreestyleLineSet *lineset)
-       {
-               BLI_uniquename(&config->linesets, lineset, "FreestyleLineSet", '.', offsetof(FreestyleLineSet, name), sizeof(lineset->name));
-       }
+       strcpy(module_conf->module_path, default_module_path.c_str());
+       module_conf->is_displayed = 1;
+}
 
-       FreestyleLineSet *FRS_add_lineset(FreestyleConfig *config)
-       {
-               int lineset_index = BLI_countlist(&config->linesets);
-
-               FreestyleLineSet *lineset = (FreestyleLineSet *) MEM_callocN( sizeof(FreestyleLineSet), "Freestyle line set");
-               BLI_addtail(&config->linesets, (void *) lineset);
-               FRS_set_active_lineset_index(config, lineset_index);
-
-               lineset->linestyle = FRS_new_linestyle("LineStyle", NULL);
-               lineset->flags |= FREESTYLE_LINESET_ENABLED;
-               lineset->selection = FREESTYLE_SEL_IMAGE_BORDER;
-               lineset->qi = FREESTYLE_QI_VISIBLE;
-               lineset->qi_start = 0;
-               lineset->qi_end = 100;
-               lineset->edge_types = FREESTYLE_FE_SILHOUETTE | FREESTYLE_FE_BORDER | FREESTYLE_FE_CREASE;
-               lineset->exclude_edge_types = 0;
-               lineset->group = NULL;
-               if (lineset_index > 0)
-                       sprintf(lineset->name, "LineSet %i", lineset_index+1);
-               else
-                       strcpy(lineset->name, "LineSet");
-               unique_lineset_name(config, lineset);
+void FRS_delete_module(FreestyleConfig *config, FreestyleModuleConfig *module_conf)
+{
+       BLI_freelinkN(&config->modules, module_conf);
+}
 
-               return lineset;
-       }
+void FRS_move_module_up(FreestyleConfig *config, FreestyleModuleConfig *module_conf)
+{
+       BLI_remlink(&config->modules, module_conf);
+       BLI_insertlinkbefore(&config->modules, module_conf->prev, module_conf);
+}
 
-       void FRS_copy_active_lineset(FreestyleConfig *config)
-       {
-               FreestyleLineSet *lineset = FRS_get_active_lineset(config);
-
-               if (lineset) {
-                       lineset_buffer.linestyle = lineset->linestyle;
-                       lineset_buffer.flags = lineset->flags;
-                       lineset_buffer.selection = lineset->selection;
-                       lineset_buffer.qi = lineset->qi;
-                       lineset_buffer.qi_start = lineset->qi_start;
-                       lineset_buffer.qi_end = lineset->qi_end;
-                       lineset_buffer.edge_types = lineset->edge_types;
-                       lineset_buffer.exclude_edge_types = lineset->exclude_edge_types;
-                       lineset_buffer.group = lineset->group;
-                       strcpy(lineset_buffer.name, lineset->name);
-                       lineset_copied = true;
-               }
+void FRS_move_module_down(FreestyleConfig *config, FreestyleModuleConfig *module_conf)
+{
+       BLI_remlink(&config->modules, module_conf);
+       BLI_insertlinkafter(&config->modules, module_conf->next, module_conf);
+}
+
+static void unique_lineset_name(FreestyleConfig *config, FreestyleLineSet *lineset)
+{
+       BLI_uniquename(&config->linesets, lineset, "FreestyleLineSet", '.', offsetof(FreestyleLineSet, name),
+                      sizeof(lineset->name));
+}
+
+FreestyleLineSet *FRS_add_lineset(FreestyleConfig *config)
+{
+       int lineset_index = BLI_countlist(&config->linesets);
+
+       FreestyleLineSet *lineset = (FreestyleLineSet*)MEM_callocN(sizeof(FreestyleLineSet), "Freestyle line set");
+       BLI_addtail(&config->linesets, (void*)lineset);
+       FRS_set_active_lineset_index(config, lineset_index);
+
+       lineset->linestyle = FRS_new_linestyle("LineStyle", NULL);
+       lineset->flags |= FREESTYLE_LINESET_ENABLED;
+       lineset->selection = FREESTYLE_SEL_IMAGE_BORDER;
+       lineset->qi = FREESTYLE_QI_VISIBLE;
+       lineset->qi_start = 0;
+       lineset->qi_end = 100;
+       lineset->edge_types = FREESTYLE_FE_SILHOUETTE | FREESTYLE_FE_BORDER | FREESTYLE_FE_CREASE;
+       lineset->exclude_edge_types = 0;
+       lineset->group = NULL;
+       if (lineset_index > 0)
+               sprintf(lineset->name, "LineSet %i", lineset_index + 1);
+       else
+               strcpy(lineset->name, "LineSet");
+       unique_lineset_name(config, lineset);
+
+       return lineset;
+}
+
+void FRS_copy_active_lineset(FreestyleConfig *config)
+{
+       FreestyleLineSet *lineset = FRS_get_active_lineset(config);
+
+       if (lineset) {
+               lineset_buffer.linestyle = lineset->linestyle;
+               lineset_buffer.flags = lineset->flags;
+               lineset_buffer.selection = lineset->selection;
+               lineset_buffer.qi = lineset->qi;
+               lineset_buffer.qi_start = lineset->qi_start;
+               lineset_buffer.qi_end = lineset->qi_end;
+               lineset_buffer.edge_types = lineset->edge_types;
+               lineset_buffer.exclude_edge_types = lineset->exclude_edge_types;
+               lineset_buffer.group = lineset->group;
+               strcpy(lineset_buffer.name, lineset->name);
+               lineset_copied = true;
        }
+}
 
-       void FRS_paste_active_lineset(FreestyleConfig *config)
-       {
-               if (!lineset_copied)
-                       return;
-
-               FreestyleLineSet *lineset = FRS_get_active_lineset(config);
-
-               if (lineset) {
-                       lineset->linestyle->id.us--;
-                       lineset->linestyle = lineset_buffer.linestyle;
-                       lineset->linestyle->id.us++;
-                       lineset->flags = lineset_buffer.flags;
-                       lineset->selection = lineset_buffer.selection;
-                       lineset->qi = lineset_buffer.qi;
-                       lineset->qi_start = lineset_buffer.qi_start;
-                       lineset->qi_end = lineset_buffer.qi_end;
-                       lineset->edge_types = lineset_buffer.edge_types;
-                       lineset->exclude_edge_types = lineset_buffer.exclude_edge_types;
-                       if (lineset->group) {
-                               lineset->group->id.us--;
-                               lineset->group = NULL;
-                       }
-                       if (lineset_buffer.group) {
-                               lineset->group = lineset_buffer.group;
-                               lineset->group->id.us++;
-                       }
-                       strcpy(lineset->name, lineset_buffer.name);
-                       unique_lineset_name(config, lineset);
-                       lineset->flags |= FREESTYLE_LINESET_CURRENT;
+void FRS_paste_active_lineset(FreestyleConfig *config)
+{
+       if (!lineset_copied)
+               return;
+
+       FreestyleLineSet *lineset = FRS_get_active_lineset(config);
+
+       if (lineset) {
+               lineset->linestyle->id.us--;
+               lineset->linestyle = lineset_buffer.linestyle;
+               lineset->linestyle->id.us++;
+               lineset->flags = lineset_buffer.flags;
+               lineset->selection = lineset_buffer.selection;
+               lineset->qi = lineset_buffer.qi;
+               lineset->qi_start = lineset_buffer.qi_start;
+               lineset->qi_end = lineset_buffer.qi_end;
+               lineset->edge_types = lineset_buffer.edge_types;
+               lineset->exclude_edge_types = lineset_buffer.exclude_edge_types;
+               if (lineset->group) {
+                       lineset->group->id.us--;
+                       lineset->group = NULL;
+               }
+               if (lineset_buffer.group) {
+                       lineset->group = lineset_buffer.group;
+                       lineset->group->id.us++;
                }
+               strcpy(lineset->name, lineset_buffer.name);
+               unique_lineset_name(config, lineset);
+               lineset->flags |= FREESTYLE_LINESET_CURRENT;
        }
+}
 
-       void FRS_delete_active_lineset(FreestyleConfig *config)
-       {
-               FreestyleLineSet *lineset = FRS_get_active_lineset(config);
+void FRS_delete_active_lineset(FreestyleConfig *config)
+{
+       FreestyleLineSet *lineset = FRS_get_active_lineset(config);
 
-               if (lineset) {
-                       if (lineset->group) {
-                               lineset->group->id.us--;
-                               lineset->group = NULL;
-                       }
-                       lineset->linestyle->id.us--;
-                       lineset->linestyle = NULL;
-                       BLI_remlink(&config->linesets, lineset);
-                       MEM_freeN(lineset);
-                       FRS_set_active_lineset_index(config, 0);
+       if (lineset) {
+               if (lineset->group) {
+                       lineset->group->id.us--;
+                       lineset->group = NULL;
                }
+               lineset->linestyle->id.us--;
+               lineset->linestyle = NULL;
+               BLI_remlink(&config->linesets, lineset);
+               MEM_freeN(lineset);
+               FRS_set_active_lineset_index(config, 0);
        }
+}
 
-       void FRS_move_active_lineset_up(FreestyleConfig *config)
-       {
-               FreestyleLineSet *lineset = FRS_get_active_lineset(config);
+void FRS_move_active_lineset_up(FreestyleConfig *config)
+{
+       FreestyleLineSet *lineset = FRS_get_active_lineset(config);
 
-               if (lineset) {
-                       BLI_remlink(&config->linesets, lineset);
-                       BLI_insertlinkbefore(&config->linesets, lineset->prev, lineset);
-               }
+       if (lineset) {
+               BLI_remlink(&config->linesets, lineset);
+               BLI_insertlinkbefore(&config->linesets, lineset->prev, lineset);
        }
+}
 
-       void FRS_move_active_lineset_down(FreestyleConfig *config)
-       {
-               FreestyleLineSet *lineset = FRS_get_active_lineset(config);
+void FRS_move_active_lineset_down(FreestyleConfig *config)
+{
+       FreestyleLineSet *lineset = FRS_get_active_lineset(config);
 
-               if (lineset) {
-                       BLI_remlink(&config->linesets, lineset);
-                       BLI_insertlinkafter(&config->linesets, lineset->next, lineset);
-               }
+       if (lineset) {
+               BLI_remlink(&config->linesets, lineset);
+               BLI_insertlinkafter(&config->linesets, lineset->next, lineset);
        }
+}
 
-       FreestyleLineSet *FRS_get_active_lineset(FreestyleConfig *config)
-       {
-               FreestyleLineSet *lineset;
+FreestyleLineSet *FRS_get_active_lineset(FreestyleConfig *config)
+{
+       FreestyleLineSet *lineset;
 
-               for(lineset=(FreestyleLineSet *)config->linesets.first; lineset; lineset=lineset->next)
-                       if(lineset->flags & FREESTYLE_LINESET_CURRENT)
-                               return lineset;
-               return NULL;
+       for (lineset = (FreestyleLineSet*)config->linesets.first; lineset; lineset = lineset->next) {
+               if (lineset->flags & FREESTYLE_LINESET_CURRENT)
+                       return lineset;
        }
+       return NULL;
+}
 
-       short FRS_get_active_lineset_index(FreestyleConfig *config)
-       {
-               FreestyleLineSet *lineset;
-               short i;
+short FRS_get_active_lineset_index(FreestyleConfig *config)
+{
+       FreestyleLineSet *lineset;
+       short i;
 
-               for(lineset=(FreestyleLineSet *)config->linesets.first, i=0; lineset; lineset=lineset->next, i++)
-                       if(lineset->flags & FREESTYLE_LINESET_CURRENT)
-                               return i;
-               return 0;
+       for (lineset = (FreestyleLineSet*)config->linesets.first, i = 0; lineset; lineset = lineset->next, i++) {
+               if (lineset->flags & FREESTYLE_LINESET_CURRENT)
+                       return i;
        }
+       return 0;
+}
 
-       void FRS_set_active_lineset_index(FreestyleConfig *config, short index)
-       {
-               FreestyleLineSet *lineset;
-               short i;
+void FRS_set_active_lineset_index(FreestyleConfig *config, short index)
+{
+       FreestyleLineSet *lineset;
+       short i;
 
-               for(lineset=(FreestyleLineSet *)config->linesets.first, i=0; lineset; lineset=lineset->next, i++) {
-                       if(i == index)
-                               lineset->flags |= FREESTYLE_LINESET_CURRENT;
-                       else
-                               lineset->flags &= ~FREESTYLE_LINESET_CURRENT;
-               }
+       for (lineset = (FreestyleLineSet*)config->linesets.first, i = 0; lineset; lineset = lineset->next, i++) {
+               if (i == index)
+                       lineset->flags |= FREESTYLE_LINESET_CURRENT;
+               else
+                       lineset->flags &= ~FREESTYLE_LINESET_CURRENT;
        }
+}
 
-       void FRS_unlink_target_object(FreestyleConfig *config, Object *ob)
-       {
-               FreestyleLineSet *lineset;
+void FRS_unlink_target_object(FreestyleConfig *config, Object *ob)
+{
+       FreestyleLineSet *lineset;
 
-               for(lineset=(FreestyleLineSet *)config->linesets.first; lineset; lineset=lineset->next) {
-                       FRS_unlink_linestyle_target_object(lineset->linestyle, ob);
-               }
+       for (lineset = (FreestyleLineSet*)config->linesets.first; lineset; lineset = lineset->next) {
+               FRS_unlink_linestyle_target_object(lineset->linestyle, ob);
        }
+}
 
 #ifdef __cplusplus
-}
+} // extern "C"
 #endif