[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [35525] branches/soc-2008-mxcurioni: Optimized view map calculation by Alexander Beels.

Tamito Kajiyama rd6t-kjym at asahi-net.or.jp
Mon Mar 14 01:36:27 CET 2011


Revision: 35525
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=35525
Author:   kjym3
Date:     2011-03-14 00:36:27 +0000 (Mon, 14 Mar 2011)
Log Message:
-----------
Optimized view map calculation by Alexander Beels.

* View map calculation has been intensively optimized for speed by
means of:

1) new spatial grid data structures (SphericalGrid for perspective
cameras and BoxGrid for orthographic cameras; automatically switched
based on the camera type);

2) a heuristic grid density calculation algorithm; and

3) new line visibility computation algorithms: A "traditional"
algorithm for emulating old visibility algorithms, and a "cumulative"
algorithm for improved, more consistent line visibility, both exploiting
the new spatial grid data structures for fast ray casting.

A new option "Raycasting Algorithm" was added to allow users to choose
a ray casting (line visibility) algorithm.  Available choices are:

- Normal Ray Casting
- Fast Ray Casting
- Very Fast Ray Casting
- Culled Traditional Visibility Detection
- Unculled Traditional Visibility Detection
- Culled Cumulative Visibility Detection
- Unculled Cumulative Visibility Detection

The first three algorithms are those available in the original
Freestyle (the "normal" ray casting was used unconditionally, though).
The "fast" and "very fast" ray casting algorithms achieve a faster
calculation at the cost of less visibility accuracy.

The last four are newly introduced optimized options.  The culled
versions of the new algorithms will exclude from visibility
calculation those faces that lay outside the camera, which leads to a
faster view map construction.  The unculled counterparts will take all
faces into account.  The unculled visibility algorithms are useful
when culling affects stroke chaining.

The recommended options for users are the culled/unculled cumulative
visibility algorithms.  These options are meant to replace the old
algorithms in the future.

Performance improvements over the old algorithms depend on the scenes
to be rendered.

* Silhouette detection has also been considerably optimized for speed.

Performance gains by this optimization do not depend on scenes.

* Improper handling of error conditions in the view map construction
was fixed.

Modified Paths:
--------------
    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/freestyle/intern/geometry/GeomUtils.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/geometry/GeomUtils.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/geometry/Grid.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/geometry/Grid.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/geometry/Polygon.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/geometry/SweepLine.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/geometry/normal_cycle.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/geometry/normal_cycle.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/StyleModule.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/FEdgeXDetector.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/FEdgeXDetector.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/Silhouette.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/ViewMap.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/ViewMapBuilder.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/ViewMapBuilder.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/winged_edge/Curvature.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/winged_edge/WEdge.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/winged_edge/WEdge.h
    branches/soc-2008-mxcurioni/source/blender/makesdna/DNA_freestyle_types.h
    branches/soc-2008-mxcurioni/source/blender/makesrna/intern/rna_scene.c

Added Paths:
-----------
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/geometry/GridHelpers.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/geometry/GridHelpers.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/system/PointerSequence.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/ArbitraryGridDensityProvider.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/ArbitraryGridDensityProvider.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/AverageAreaGridDensityProvider.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/AverageAreaGridDensityProvider.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/BoxGrid.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/BoxGrid.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/CulledOccluderSource.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/CulledOccluderSource.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/GridDensityProvider.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/HeuristicGridDensityProviderFactory.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/HeuristicGridDensityProviderFactory.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/OccluderSource.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/OccluderSource.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/Pow23GridDensityProvider.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/Pow23GridDensityProvider.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/SphericalGrid.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/SphericalGrid.h

Modified: branches/soc-2008-mxcurioni/release/scripts/ui/properties_render.py
===================================================================
--- branches/soc-2008-mxcurioni/release/scripts/ui/properties_render.py	2011-03-13 23:54:03 UTC (rev 35524)
+++ branches/soc-2008-mxcurioni/release/scripts/ui/properties_render.py	2011-03-14 00:36:27 UTC (rev 35525)
@@ -193,6 +193,7 @@
         split = layout.split()
 
         col = split.column()
+        col.prop(freestyle, "raycasting_algorithm", text="Raycasting Algorithm")
         col.prop(freestyle, "mode", text="Control Mode")
 
         if freestyle.mode == "EDITOR":

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.cpp	2011-03-13 23:54:03 UTC (rev 35524)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.cpp	2011-03-14 00:36:27 UTC (rev 35525)
@@ -40,7 +40,6 @@
 #include "../scene_graph/VertexRep.h"
 #include "../winged_edge/WXEdgeBuilder.h"
 #include "../scene_graph/ScenePrettyPrinter.h"
-#include "../winged_edge/WFillGrid.h"
 
 #include "../view_map/ViewMapTesselator.h"
 #include "../stroke/StrokeTesselator.h"
@@ -60,6 +59,8 @@
 #include "../blender_interface/BlenderStrokeRenderer.h"
 #include "../blender_interface/BlenderStyleModule.h"
 
+#include "DNA_freestyle_types.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -105,8 +106,8 @@
 
   _Canvas = 0;
 
-  _VisibilityAlgo = ViewMapBuilder::ray_casting;
-  //_VisibilityAlgo = ViewMapBuilder::ray_casting_fast;
+  _VisibilityAlgo = ViewMapBuilder::ray_casting_adaptive_traditional;
+  //_VisibilityAlgo = ViewMapBuilder::ray_casting;
 
   _Canvas = new AppCanvas;
 
@@ -250,29 +251,6 @@
 
   printf("WEdge building   : %lf\n", _Chrono.stop());
 
- _Chrono.start();
-
-  _Grid.clear();
-  Vec3r size;
-  for(unsigned int i=0; i<3; i++)
-    {
-      size[i] = fabs(_RootNode->bbox().getMax()[i] - _RootNode->bbox().getMin()[i]);
-      size[i] += size[i]/10.0; // let make the grid 1/10 bigger to avoid numerical errors while computing triangles/cells intersections
-      if(size[i]==0){
-          cout << "Warning: the bbox size is 0 in dimension "<<i<<endl;
-      }
-    }
-  _Grid.configure(Vec3r(_RootNode->bbox().getMin() - size / 20.0), size,
-		  _SceneNumFaces);
-
-  // Fill in the grid:
-  WFillGrid fillGridRenderer(&_Grid, _winged_edge);
-  fillGridRenderer.fillGrid();
-
-  printf("Grid building    : %lf\n", _Chrono.stop());
-  
-  // DEBUG
-  _Grid.displayDebug();
   //  
   // _pView->setDebug(_DebugNode);
 
@@ -482,6 +460,7 @@
   edgeDetector.enableRidgesAndValleysFlag(_ComputeRidges);
   edgeDetector.enableSuggestiveContours(_ComputeSuggestive);
   edgeDetector.enableMaterialBoundaries(_ComputeMaterialBoundaries);
+  edgeDetector.enableFaceSmoothness(_EnableFaceSmoothness);
   edgeDetector.setCreaseAngle(_creaseAngle);
   edgeDetector.setSphereRadius(_sphereRadius);
   edgeDetector.setSuggestiveContourKrDerivativeEpsilon(_suggestiveContourKrDerivativeEpsilon);
@@ -509,7 +488,7 @@
 	cout << "\n===  Building the view map  ===" << endl;
   _Chrono.start();
   // Build View Map
-  _ViewMap = vmBuilder.BuildViewMap(*_winged_edge, _VisibilityAlgo, _EPSILON);
+  _ViewMap = vmBuilder.BuildViewMap(*_winged_edge, _VisibilityAlgo, _EPSILON, _RootNode->bbox(), _SceneNumFaces);
   _ViewMap->setScene3dBBox(_RootNode->bbox());
   
 	printf("ViewMap edge count : %i\n", _ViewMap->viewedges_size() );
@@ -649,6 +628,57 @@
   }
 }
 
+void Controller::setVisibilityAlgo(int algo)
+{
+	switch (algo) {
+		case FREESTYLE_ALGO_REGULAR:
+			_VisibilityAlgo = ViewMapBuilder::ray_casting;
+			break;
+		case FREESTYLE_ALGO_FAST:
+			_VisibilityAlgo = ViewMapBuilder::ray_casting_fast;
+			break;
+		case FREESTYLE_ALGO_VERYFAST:
+			_VisibilityAlgo = ViewMapBuilder::ray_casting_very_fast;
+			break;
+		case FREESTYLE_ALGO_CULLED_ADAPTIVE_TRADITIONAL:
+			_VisibilityAlgo = ViewMapBuilder::ray_casting_culled_adaptive_traditional;
+			break;
+		case FREESTYLE_ALGO_ADAPTIVE_TRADITIONAL:
+			_VisibilityAlgo = ViewMapBuilder::ray_casting_adaptive_traditional;
+			break;
+		case FREESTYLE_ALGO_CULLED_ADAPTIVE_CUMULATIVE:
+			_VisibilityAlgo = ViewMapBuilder::ray_casting_culled_adaptive_cumulative;
+			break;
+		case FREESTYLE_ALGO_ADAPTIVE_CUMULATIVE:
+			_VisibilityAlgo = ViewMapBuilder::ray_casting_adaptive_cumulative;
+			break;
+	}
+}
+
+int Controller::getVisibilityAlgo()
+{
+	switch (_VisibilityAlgo) {
+		case ViewMapBuilder::ray_casting:
+			return FREESTYLE_ALGO_REGULAR;
+		case ViewMapBuilder::ray_casting_fast:
+			return FREESTYLE_ALGO_FAST;
+		case ViewMapBuilder::ray_casting_very_fast:
+			return FREESTYLE_ALGO_VERYFAST;
+		case ViewMapBuilder::ray_casting_culled_adaptive_traditional:
+			return FREESTYLE_ALGO_CULLED_ADAPTIVE_TRADITIONAL;
+		case ViewMapBuilder::ray_casting_adaptive_traditional:
+			return FREESTYLE_ALGO_ADAPTIVE_TRADITIONAL;
+		case ViewMapBuilder::ray_casting_culled_adaptive_cumulative:
+			return FREESTYLE_ALGO_CULLED_ADAPTIVE_CUMULATIVE;
+		case ViewMapBuilder::ray_casting_adaptive_cumulative:
+			return FREESTYLE_ALGO_ADAPTIVE_CUMULATIVE;
+	}
+
+	// ray_casting_adaptive_traditional is the most exact replacement
+	// for legacy code
+	return FREESTYLE_ALGO_ADAPTIVE_TRADITIONAL;
+}
+
 void Controller::setQuantitativeInvisibility(bool iBool)
 {
   _EnableQI = iBool;
@@ -659,6 +689,16 @@
   return _EnableQI;
 }
 
+void Controller::setFaceSmoothness(bool iBool)
+{
+  _EnableFaceSmoothness = iBool;
+}
+
+bool Controller::getFaceSmoothness() const
+{
+  return _EnableFaceSmoothness;
+}
+
 void Controller::setComputeRidgesAndValleysFlag(bool iBool){
   _ComputeRidges = iBool;
 }

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.h	2011-03-13 23:54:03 UTC (rev 35524)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.h	2011-03-14 00:36:27 UTC (rev 35525)
@@ -34,7 +34,6 @@
 # include <string>
 //# include "ConfigIO.h"
 # include "../geometry/FastGrid.h"
-# include "../geometry/HashGrid.h"
 # include "../system/TimeUtils.h"
 # include "../system/ProgressBar.h"
 # include "../system/Precision.h"
@@ -115,9 +114,13 @@
   //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 ;
@@ -228,6 +231,7 @@
   string	_browser_cmd;
 
   bool _EnableQI;
+  bool _EnableFaceSmoothness;
   bool _ComputeRidges;
   bool _ComputeSuggestive;
   bool _ComputeMaterialBoundaries;

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	2011-03-13 23:54:03 UTC (rev 35524)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp	2011-03-14 00:36:27 UTC (rev 35525)
@@ -234,12 +234,15 @@
 		}
 		
 		// set parameters
+		controller->setFaceSmoothness( (config->flags & FREESTYLE_FACE_SMOOTHNESS_FLAG) ? true : false);
 		controller->setCreaseAngle( config->crease_angle );
 		controller->setSphereRadius( config->sphere_radius );
 		controller->setSuggestiveContourKrDerivativeEpsilon( config->dkr_epsilon ) ;
+		controller->setVisibilityAlgo( config->raycasting_algorithm );
 
 		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;
@@ -406,6 +409,8 @@
 		config->crease_angle = 134.43f;
 
 		config->linesets.first = config->linesets.last = NULL;
+
+		config->raycasting_algorithm = FREESTYLE_ALGO_REGULAR;
 	}
 	
 	void FRS_free_freestyle_config( SceneRenderLayer* srl )

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/geometry/GeomUtils.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/geometry/GeomUtils.cpp	2011-03-13 23:54:03 UTC (rev 35524)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/geometry/GeomUtils.cpp	2011-03-14 00:36:27 UTC (rev 35525)
@@ -370,9 +370,9 @@
   // Ithaca, New York
   // wbt at graphics.cornell.edu
 
-  bool intersectRayTriangle(Vec3r& orig, Vec3r& dir,
-			    Vec3r& v0, Vec3r& v1, Vec3r& v2,
-			    real& t, real& u, real& v, real epsilon) {
+  bool intersectRayTriangle(const Vec3r& orig, const Vec3r& dir,
+			    const Vec3r& v0, const Vec3r& v1, const Vec3r& v2,
+			    real& t, real& u, real& v, const real epsilon) {
     Vec3r edge1, edge2, tvec, pvec, qvec;
     real det, inv_det;
 
@@ -424,10 +424,10 @@
   }
 
   // Intersection between plane and ray, adapted from Graphics Gems, Didier Badouel
-  intersection_test intersectRayPlane(Vec3r& orig, Vec3r& dir,
-				      Vec3r& norm, real d,
+  intersection_test intersectRayPlane(const Vec3r& orig, const Vec3r& dir,
+				      const Vec3r& norm, const real d,
 				      real& t,
-				      real epsilon) { 
+				      const real epsilon) { 
     real denom = norm * dir;
 
     if(fabs(denom) <= epsilon) { // plane and ray are parallel
@@ -484,10 +484,10 @@
         }
 
   // Checks whether 3D points p lies inside or outside of the triangle ABC
-  bool includePointTriangle(Vec3r& P,
-			    Vec3r& A,
-			    Vec3r& B,
-			    Vec3r& C) {
+  bool includePointTriangle(const Vec3r& P,
+			    const Vec3r& A,

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list