[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [33457] branches/soc-2008-mxcurioni: A few attempts to reduce the amount of memory consumption in Freestyle.

Tamito Kajiyama rd6t-kjym at asahi-net.or.jp
Sat Dec 4 00:17:49 CET 2010


Revision: 33457
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33457
Author:   kjym3
Date:     2010-12-04 00:17:49 +0100 (Sat, 04 Dec 2010)

Log Message:
-----------
A few attempts to reduce the amount of memory consumption in Freestyle.

* Made changes to the Controller so that dynamically allocated
memory areas (e.g. imported mesh data, winged edges, and a view map)
are released soon after they become unnecessary.

* Added a new feature edge selection criterion based on image border.

When the "Selection by Image Border" option is enabled, feature edges
are selected only if they are within the border of the image being
rendered.  The border is defined either by the frame size or a border
region (specified by the Shift-B key in a 3D View window).  When large
scenes are rendered, this clipping by the image border leads to less
memory consumption.

* Enabled the "Silhouette", "Border", and "Crease" edge types of
the Selection by Edge Types option by default.

When no edge types are specified, all feature edges including "Ridge",
"Valley" and "Suggestive Contour" are detected at the cost of extra
memory consumption.  Disabling these three edge types and enabling
some other edge type leads to less memory consumption.  This change
is intended to help new Freestyle users by providing a typical, low
memory consumption default setting.

* Slightly rearranged the UI controls for feature edge selection.

Modified Paths:
--------------
    branches/soc-2008-mxcurioni/release/scripts/freestyle/style_modules/parameter_editor.py
    branches/soc-2008-mxcurioni/release/scripts/ui/properties_render.py
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
    branches/soc-2008-mxcurioni/source/blender/makesdna/DNA_freestyle_types.h
    branches/soc-2008-mxcurioni/source/blender/makesrna/intern/rna_scene.c

Modified: branches/soc-2008-mxcurioni/release/scripts/freestyle/style_modules/parameter_editor.py
===================================================================
--- branches/soc-2008-mxcurioni/release/scripts/freestyle/style_modules/parameter_editor.py	2010-12-03 19:42:40 UTC (rev 33456)
+++ branches/soc-2008-mxcurioni/release/scripts/freestyle/style_modules/parameter_editor.py	2010-12-03 23:17:49 UTC (rev 33457)
@@ -312,6 +312,22 @@
             return not found
         return found
 
+class WithinImageBorderUP1D(UnaryPredicate1D):
+    def __init__(self, xmin, xmax, ymin, ymax):
+        UnaryPredicate1D.__init__(self)
+        self._xmin = xmin
+        self._xmax = xmax
+        self._ymin = ymin
+        self._ymax = ymax
+    def getName(self):
+        return "WithinImageBorderUP1D"
+    def __call__(self, inter):
+        return self.withinBorder(inter.A()) or self.withinBorder(inter.B())
+    def withinBorder(self, vert):
+        x = vert.getProjectedX()
+        y = vert.getProjectedY()
+        return self._xmin <= x <= self._xmax and self._ymin <= y <= self._ymax
+
 # Stroke caps
 
 def iter_stroke_vertices(stroke):
@@ -525,6 +541,20 @@
             names = dict((ob.name, True) for ob in lineset.group.objects)
             upred = ObjectNamesUP1D(names, lineset.group_negation == 'EXCLUSIVE')
             selection_criteria.append(upred)
+    # prepare selection criteria by image border
+    if lineset.select_by_image_border:
+        w = scene.render.resolution_x
+        h = scene.render.resolution_y
+        if scene.render.use_border:
+            xmin = scene.render.border_min_x * w
+            xmax = scene.render.border_max_x * w
+            ymin = scene.render.border_min_y * h
+            ymax = scene.render.border_max_y * h
+        else:
+            xmin, xmax = 0.0, float(w)
+            ymin, ymax = 0.0, float(h)
+        upred = WithinImageBorderUP1D(xmin, xmax, ymin, ymax)
+        selection_criteria.append(upred)
     # do feature edge selection
     upred = join_unary_predicates(selection_criteria, AndUP1D)
     if upred is None:

Modified: branches/soc-2008-mxcurioni/release/scripts/ui/properties_render.py
===================================================================
--- branches/soc-2008-mxcurioni/release/scripts/ui/properties_render.py	2010-12-03 19:42:40 UTC (rev 33456)
+++ branches/soc-2008-mxcurioni/release/scripts/ui/properties_render.py	2010-12-03 23:17:49 UTC (rev 33457)
@@ -257,7 +257,10 @@
                     col.prop(lineset, "group")
                     row = col.row()
                     row.prop(lineset, "group_negation", expand=True)
+                    col.separator() # XXX
 
+                col.prop(lineset, "select_by_image_border")
+
         else: # freestyle.mode == "SCRIPT"
 
             col.prop(freestyle, "use_smoothness")

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.cpp	2010-12-03 19:42:40 UTC (rev 33456)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.cpp	2010-12-03 23:17:49 UTC (rev 33457)
@@ -295,34 +295,68 @@
   cout << "Triangles nb     : " << _SceneNumFaces << endl;
   _bboxDiag = (_RootNode->bbox().getMax()-_RootNode->bbox().getMin()).norm();
   cout << "Bounding Box     : " << _bboxDiag << endl;
+
+  ClearRootNode();
+
   return 0;
 }
 
-
 void Controller::CloseFile()
 {
   WShape::setCurrentId(0);
-  _pView->DetachModel();
   _ListOfModels.clear();
-  if(NULL != _RootNode)
-    {
-      int ref = _RootNode->destroy();
-      if(0 == ref)
-	_RootNode->addRef();
-    
-      _RootNode->clearBBox();
-    }
-  
-  _pView->DetachSilhouette();
-  if (NULL != _SilhouetteNode)
-    {
-      int ref = _SilhouetteNode->destroy();
-      if(0 == ref)
+
+  // We deallocate the memory:
+  ClearRootNode();
+  DeleteWingedEdge();
+  DeleteViewMap();
+
+  // clears the canvas
+  _Canvas->Clear();
+
+  // soc: reset passes
+  setPassDiffuse(NULL, 0, 0);
+  setPassZ(NULL, 0, 0);
+}
+
+void Controller::ClearRootNode()
+{
+	_pView->DetachModel();
+	if(NULL != _RootNode)
 	{
-	  delete _SilhouetteNode;
-	  _SilhouetteNode = NULL;
+		int ref = _RootNode->destroy();
+		if(0 == ref)
+			_RootNode->addRef();
+		_RootNode->clearBBox();
 	}
-    }
+}
+
+void Controller::DeleteWingedEdge()
+{
+	if(_winged_edge)
+	{
+		delete _winged_edge;
+		_winged_edge = NULL;
+	}
+
+	// clears the grid
+	_Grid.clear();
+	_SceneNumFaces = 0;
+	_minEdgeSize = DBL_MAX;
+}
+
+void Controller::DeleteViewMap()
+{
+	_pView->DetachSilhouette();
+	if (NULL != _SilhouetteNode)
+	{
+		int ref = _SilhouetteNode->destroy();
+		if(0 == ref) {
+			delete _SilhouetteNode;
+			_SilhouetteNode = NULL;
+		}
+	}
+
   //  if(NULL != _ProjectedSilhouette)
   //    {
   //      int ref = _ProjectedSilhouette->destroy();
@@ -340,43 +374,21 @@
   //	  delete _VisibleProjectedSilhouette;
   //	  _VisibleProjectedSilhouette = NULL;
   //	}
-  //  }
-  
-  _pView->DetachDebug();
-  if(NULL != _DebugNode)
-    {
+  //  }  
+
+	_pView->DetachDebug();
+	if(NULL != _DebugNode) {
       int ref = _DebugNode->destroy();
       if(0 == ref)
-	_DebugNode->addRef();
+		  _DebugNode->addRef();
     }
-  
-  if(_winged_edge) {
-    delete _winged_edge;
-    _winged_edge = NULL;
-  }
 
-  // We deallocate the memory:
-  if(NULL != _ViewMap)
-    {
+	if(NULL != _ViewMap) {
       delete _ViewMap;
       _ViewMap = 0;
     }
-
-  // clears the canvas
-  _Canvas->Clear();
-
-  // clears the grid
-  _Grid.clear();
-  _SceneNumFaces = 0;
-  _minEdgeSize = DBL_MAX;
-
-  // soc: reset passes
-  setPassDiffuse(NULL, 0, 0);
-  setPassZ(NULL, 0, 0);
 }
 
-
-
 void Controller::ComputeViewMap()
 {
 
@@ -527,6 +539,8 @@
   }
   // Reset Style modules modification flags
   resetModified(true);
+
+  DeleteWingedEdge();
 }
 
 void Controller::ComputeSteerableViewMap(){
@@ -699,6 +713,7 @@
 Render* Controller::RenderStrokes(Render *re) {
 	BlenderStrokeRenderer* blenderRenderer = new BlenderStrokeRenderer(re, ++_render_count);
   	_Canvas->Render( blenderRenderer );
+	DeleteViewMap();
 	Render* freestyle_render = blenderRenderer->RenderScene(re);
 	delete blenderRenderer;
 	

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.h	2010-12-03 19:42:40 UTC (rev 33456)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.h	2010-12-03 23:17:49 UTC (rev 33457)
@@ -94,6 +94,9 @@
   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);
@@ -106,10 +109,10 @@
   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;}
+  //NodeGroup* debugNode() {return _DebugNode;}
+  //AppView * view() {return _pView;}
+  //NodeGroup* debugScene() {return _DebugNode;}
+  //Grid& grid() {return _Grid;}
   
   void toggleVisibilityAlgo();
 

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp	2010-12-03 19:42:40 UTC (rev 33456)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp	2010-12-03 23:17:49 UTC (rev 33457)
@@ -439,11 +439,11 @@
 
 		lineset->linestyle = FRS_new_linestyle("LineStyle", NULL);
 		lineset->flags |= FREESTYLE_LINESET_ENABLED;
-		lineset->selection = 0;
+		lineset->selection = FREESTYLE_SEL_IMAGE_BORDER;
 		lineset->qi = FREESTYLE_QI_VISIBLE;
 		lineset->qi_start = 0;
 		lineset->qi_end = 100;
-		lineset->edge_types = 0;
+		lineset->edge_types = FREESTYLE_FE_SILHOUETTE | FREESTYLE_FE_BORDER | FREESTYLE_FE_CREASE;
 		lineset->group = NULL;
 		if (lineset_index > 0)
 			sprintf(lineset->name, "LineSet %i", lineset_index+1);

Modified: branches/soc-2008-mxcurioni/source/blender/makesdna/DNA_freestyle_types.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/makesdna/DNA_freestyle_types.h	2010-12-03 19:42:40 UTC (rev 33456)
+++ branches/soc-2008-mxcurioni/source/blender/makesdna/DNA_freestyle_types.h	2010-12-03 23:17:49 UTC (rev 33457)
@@ -53,9 +53,10 @@
 #define FREESTYLE_LINESET_GR_NOT   16
 
 /* FreestyleLineSet::selection */
-#define FREESTYLE_SEL_VISIBILITY  1
-#define FREESTYLE_SEL_EDGE_TYPES  2
-#define FREESTYLE_SEL_GROUP       4
+#define FREESTYLE_SEL_VISIBILITY    1
+#define FREESTYLE_SEL_EDGE_TYPES    2
+#define FREESTYLE_SEL_GROUP         4
+#define FREESTYLE_SEL_IMAGE_BORDER  8
 
 /* FreestyleLineSet::fedge_types */
 #define FREESTYLE_FE_SILHOUETTE          1

Modified: branches/soc-2008-mxcurioni/source/blender/makesrna/intern/rna_scene.c
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/makesrna/intern/rna_scene.c	2010-12-03 19:42:40 UTC (rev 33456)
+++ branches/soc-2008-mxcurioni/source/blender/makesrna/intern/rna_scene.c	2010-12-03 23:17:49 UTC (rev 33457)
@@ -1707,6 +1707,11 @@
 	RNA_def_property_ui_text(prop, "Selection by Group", "Select feature edges based on a group of objects.");
 	RNA_def_property_update(prop, NC_SCENE, NULL);
 
+	prop= RNA_def_property(srna, "select_by_image_border", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "selection", FREESTYLE_SEL_IMAGE_BORDER);
+	RNA_def_property_ui_text(prop, "Selection by Image Border", "Select feature edges by image border (less memory consumption).");
+	RNA_def_property_update(prop, NC_SCENE, NULL);
+
 	prop= RNA_def_property(srna, "edge_type_negation", PROP_ENUM, PROP_NONE);
 	RNA_def_property_enum_bitflag_sdna(prop, NULL, "flags");
 	RNA_def_property_enum_items(prop, edge_type_negation_items);





More information about the Bf-blender-cvs mailing list