[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19342] branches/soc-2008-mxcurioni/source /blender/freestyle/intern: Made changes to the C++ API in order to allow for proper error

Tamito Kajiyama rd6t-kjym at asahi-net.or.jp
Fri Mar 20 23:55:10 CET 2009


Revision: 19342
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19342
Author:   kjym3
Date:     2009-03-20 23:55:07 +0100 (Fri, 20 Mar 2009)

Log Message:
-----------
Made changes to the C++ API in order to allow for proper error
propagation up to the toplevel error handler in BPY_txt_do_python_Text().

Before these changes were made, the operator() methods of predicates
and functions, for example, returned a value of various types such as
bool, double and Vec2f.  These returned values were not capable to
represent an error state in many cases.

Now the operator() methods always return 0 on normal exit and -1 on
error.  The original returned values are stored in the "result" member
variables of the predicate/function classes.

This means that if we have a code fragment like below:

  UnaryPredicate1D& pred;
  Interface1D& inter;
  if (pred(inter)) {
    /* do something */
  }

then we have to rewrite it as follows:

  UnaryPredicate1D& pred;
  Interface1D& inter;
  if (pred(inter) < 0)
    return -1; /* an error in pred() is propagated */
  if (pred.result) {
    /* do something */
  }

Suppose that pred is a user-defined predicate in Python, i.e. the predicate
is likely error-prone (especially when debugging the predicate).  The first
code fragment shown above prevents the proper error propagation because
the boolean return value of UnaryPredicate1D::operator() cannot inform the
occurrence of an error to the caller; the second code fragment can.

In addition to the operator() methods of predicates and functions, similar
improvements have been made to all other C++ API functions and methods that
are involved in the execution of user-defined Python code snippets.  Changes
in the signatures of functions and methods are summarized as follows (note
that all subclasses of listed classes are also subject to the changes).

Old signatures:
virtual void Iterator::increment();
virtual void Iterator::decrement();
virtual void ChainingIterator::init();
virtual ViewEdge * ChainingIterator::traverse(const AdjacencyIterator &it);
static void Operators::select(UnaryPredicate1D& pred);
static void Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
	    UnaryPredicate1D& pred, UnaryFunction1D_void& modifier);
static void Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
	    UnaryPredicate1D& pred);  
static void Operators::bidirectionalChain(ChainingIterator& it,
	    UnaryPredicate1D& pred);
static void Operators::bidirectionalChain(ChainingIterator& it);
static void Operators::sequentialSplit(UnaryPredicate0D& startingPred,
	    UnaryPredicate0D& stoppingPred, float sampling = 0);
static void Operators::sequentialSplit(UnaryPredicate0D& pred, float sampling = 0);
static void Operators::recursiveSplit(UnaryFunction0D<double>& func,
	    UnaryPredicate1D& pred, float sampling = 0);
static void Operators::recursiveSplit(UnaryFunction0D<double>& func,
	    UnaryPredicate0D& pred0d, UnaryPredicate1D& pred, float sampling = 0);
static void Operators::sort(BinaryPredicate1D& pred);
static void Operators::create(UnaryPredicate1D& pred, vector<StrokeShader*> shaders);
virtual bool UnaryPredicate0D::operator()(Interface0DIterator& it);
virtual bool BinaryPredicate0D::operator()(Interface0D& inter1, Interface0D& inter2);
virtual bool UnaryPredicate1D::operator()(Interface1D& inter);
virtual bool BinaryPredicate1D::operator()(Interface1D& inter1, Interface1D& inter2);
virtual void StrokeShader::shade(Stroke& ioStroke) const;
virtual T UnaryFunction0D::operator()(Interface0DIterator& iter);
virtual T UnaryFunction1D::operator()(Interface1D& inter);

New signatures:
virtual int Iterator::increment();
virtual int Iterator::decrement();
virtual int ChainingIterator::init();
virtual int ChainingIterator::traverse(const AdjacencyIterator &it);
static int Operators::select(UnaryPredicate1D& pred);
static int Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
	   UnaryPredicate1D& pred, UnaryFunction1D_void& modifier);
static int Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
	   UnaryPredicate1D& pred);  
static int Operators::bidirectionalChain(ChainingIterator& it,
	   UnaryPredicate1D& pred);
static int Operators::bidirectionalChain(ChainingIterator& it);
static int Operators::sequentialSplit(UnaryPredicate0D& startingPred,
	   UnaryPredicate0D& stoppingPred, float sampling = 0);
static int Operators::sequentialSplit(UnaryPredicate0D& pred, float sampling = 0);
static int Operators::recursiveSplit(UnaryFunction0D<double>& func,
	   UnaryPredicate1D& pred, float sampling = 0);
static int Operators::recursiveSplit(UnaryFunction0D<double>& func,
	   UnaryPredicate0D& pred0d, UnaryPredicate1D& pred, float sampling = 0);
static int Operators::sort(BinaryPredicate1D& pred);
static int Operators::create(UnaryPredicate1D& pred, vector<StrokeShader*> shaders);
virtual int UnaryPredicate0D::operator()(Interface0DIterator& it);
virtual int BinaryPredicate0D::operator()(Interface0D& inter1, Interface0D& inter2);
virtual int UnaryPredicate1D::operator()(Interface1D& inter);
virtual int BinaryPredicate1D::operator()(Interface1D& inter1, Interface1D& inter2);
virtual int StrokeShader::shade(Stroke& ioStroke) const;
virtual int UnaryFunction0D::operator()(Interface0DIterator& iter);
virtual int UnaryFunction1D::operator()(Interface1D& inter);

Modified Paths:
--------------
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/AdvancedFunctions0D.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/AdvancedFunctions0D.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/AdvancedFunctions1D.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/AdvancedFunctions1D.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/AdvancedPredicates1D.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/AdvancedStrokeShaders.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/AdvancedStrokeShaders.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/BasicStrokeShaders.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/BasicStrokeShaders.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/ChainingIterators.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/ChainingIterators.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/CurveIterators.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Operators.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Operators.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Predicates0D.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Predicates1D.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/StrokeIterators.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/StrokeShader.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/system/Iterator.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/Functions0D.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/Functions0D.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/Functions1D.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/Functions1D.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/Interface0D.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/Interface1D.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/Silhouette.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/ViewMapIterators.h

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/AdvancedFunctions0D.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/AdvancedFunctions0D.cpp	2009-03-20 22:45:22 UTC (rev 19341)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/AdvancedFunctions0D.cpp	2009-03-20 22:55:07 UTC (rev 19342)
@@ -26,60 +26,67 @@
 
 namespace Functions0D {
 
-  double DensityF0D::operator()(Interface0DIterator& iter) {
+  int DensityF0D::operator()(Interface0DIterator& iter) {
     Canvas* canvas = Canvas::getInstance();
     int bound = _filter.getBound();
     if( (iter->getProjectedX()-bound < 0) || (iter->getProjectedX()+bound>canvas->width())
-	|| (iter->getProjectedY()-bound < 0) || (iter->getProjectedY()+bound>canvas->height()))
-      return 0.0;
+	 || (iter->getProjectedY()-bound < 0) || (iter->getProjectedY()+bound>canvas->height())) {
+      result = 0.0;
+	  return 0;
+	}
     RGBImage image;
     canvas->readColorPixels((int)iter->getProjectedX() - bound,
 			    (int)iter->getProjectedY() - bound,
 			    _filter.maskSize(),
 			    _filter.maskSize(),
 			    image);
-    return _filter.getSmoothedPixel<RGBImage>(&image, (int)iter->getProjectedX(),
+    result = _filter.getSmoothedPixel<RGBImage>(&image, (int)iter->getProjectedX(),
 					(int)iter->getProjectedY());
+	return 0;
   }
 
 
-  double LocalAverageDepthF0D::operator()(Interface0DIterator& iter) {
+  int LocalAverageDepthF0D::operator()(Interface0DIterator& iter) {
     Canvas * iViewer = Canvas::getInstance();
     int bound = _filter.getBound();
     
     if( (iter->getProjectedX()-bound < 0) || (iter->getProjectedX()+bound>iViewer->width())
-	|| (iter->getProjectedY()-bound < 0) || (iter->getProjectedY()+bound>iViewer->height()))
-      return 0.0;
+	 || (iter->getProjectedY()-bound < 0) || (iter->getProjectedY()+bound>iViewer->height())) {
+      result = 0.0;
+	  return 0;
+	}
     GrayImage image ;
     iViewer->readDepthPixels((int)iter->getProjectedX()-bound,(int)iter->getProjectedY()-bound,_filter.maskSize(),_filter.maskSize(),image);
-    return _filter.getSmoothedPixel(&image, (int)iter->getProjectedX(), (int)iter->getProjectedY());
+    result = _filter.getSmoothedPixel(&image, (int)iter->getProjectedX(), (int)iter->getProjectedY());
+	return 0;
   }
 
-  float ReadMapPixelF0D::operator()(Interface0DIterator& iter) {
+  int ReadMapPixelF0D::operator()(Interface0DIterator& iter) {
     Canvas * canvas = Canvas::getInstance();
-    return canvas->readMapPixel(_mapName, _level, (int)iter->getProjectedX(), (int)iter->getProjectedY());
+    result = canvas->readMapPixel(_mapName, _level, (int)iter->getProjectedX(), (int)iter->getProjectedY());
+	return 0;
   }
 
-  float ReadSteerableViewMapPixelF0D::operator()(Interface0DIterator& iter) {
+  int ReadSteerableViewMapPixelF0D::operator()(Interface0DIterator& iter) {
     SteerableViewMap *svm = Canvas::getInstance()->getSteerableViewMap();
-    float v = svm->readSteerableViewMapPixel(_orientation, _level,(int)iter->getProjectedX(), (int)iter->getProjectedY());
-    return v;
+    result = svm->readSteerableViewMapPixel(_orientation, _level,(int)iter->getProjectedX(), (int)iter->getProjectedY());
+    return 0;
   }
 
-  float ReadCompleteViewMapPixelF0D::operator()(Interface0DIterator& iter) {
+  int ReadCompleteViewMapPixelF0D::operator()(Interface0DIterator& iter) {
     SteerableViewMap *svm = Canvas::getInstance()->getSteerableViewMap();
-    float v = svm->readCompleteViewMapPixel(_level,(int)iter->getProjectedX(), (int)iter->getProjectedY());
-    return v;
+    result = svm->readCompleteViewMapPixel(_level,(int)iter->getProjectedX(), (int)iter->getProjectedY());
+    return 0;
   }
 
-  float GetViewMapGradientNormF0D::operator()(Interface0DIterator& iter){
+  int GetViewMapGradientNormF0D::operator()(Interface0DIterator& iter){
     SteerableViewMap *svm = Canvas::getInstance()->getSteerableViewMap();
     float pxy = svm->readCompleteViewMapPixel(_level,(int)iter->getProjectedX(), (int)iter->getProjectedY());
     float gx = svm->readCompleteViewMapPixel(_level,(int)iter->getProjectedX()+_step, (int)iter->getProjectedY())
       - pxy;
     float gy = svm->readCompleteViewMapPixel(_level,(int)iter->getProjectedX(), (int)iter->getProjectedY()+_step)
       - pxy;
-	float f = Vec2f(gx,gy).norm();
-    return f;
+	result = Vec2f(gx,gy).norm();
+    return 0;
   }
 } // end of namespace Functions0D

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/AdvancedFunctions0D.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/AdvancedFunctions0D.h	2009-03-20 22:45:22 UTC (rev 19341)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/AdvancedFunctions0D.h	2009-03-20 22:55:07 UTC (rev 19342)
@@ -66,7 +66,7 @@
       return "DensityF0D";
     }
     /*! The () operator. */
-    double operator()(Interface0DIterator& iter);
+    int operator()(Interface0DIterator& iter);
 
   private:
 
@@ -94,7 +94,7 @@
       return "LocalAverageDepthF0D";
     }
     /*! the () operator.*/
-    double operator()(Interface0DIterator& iter);
+    int operator()(Interface0DIterator& iter);
   };
 
   // ReadMapPixel
@@ -123,7 +123,7 @@
       return "ReadMapPixelF0D";
     }
     /*! the () operator.*/
-    float operator()(Interface0DIterator& iter);
+    int operator()(Interface0DIterator& iter);
   };
   
   // ReadSteerableViewMapPixel
@@ -152,7 +152,7 @@
       return "ReadSteerableViewMapPixelF0D";
     }
     /*! the () operator.*/
-    float operator()(Interface0DIterator& iter);
+    int operator()(Interface0DIterator& iter);
   };
 
   // ReadCompleteViewMapPixel
@@ -176,7 +176,7 @@
       return "ReadCompleteViewMapPixelF0D";
     }
     /*! the () operator.*/
-    float operator()(Interface0DIterator& iter);
+    int operator()(Interface0DIterator& iter);
   };
   
   // GetViewMapGradientNormF0D
@@ -202,7 +202,7 @@
       return "GetViewMapGradientNormF0D";
     }
     /*! the () operator.*/
-    float operator()(Interface0DIterator& iter);
+    int operator()(Interface0DIterator& iter);
   };
 } // end of namespace Functions0D
 

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/AdvancedFunctions1D.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/AdvancedFunctions1D.cpp	2009-03-20 22:45:22 UTC (rev 19341)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/AdvancedFunctions1D.cpp	2009-03-20 22:55:07 UTC (rev 19342)
@@ -26,7 +26,7 @@
 // FIXME
 namespace Functions1D {
 
-  real GetSteerableViewMapDensityF1D::operator()(Interface1D& inter) {
+  int GetSteerableViewMapDensityF1D::operator()(Interface1D& inter) {
     SteerableViewMap * svm = Canvas::getInstance()->getSteerableViewMap();
     Interface0DIterator it = inter.pointsBegin(_sampling);
     Interface0DIterator itnext = it;++itnext;
@@ -85,24 +85,26 @@
         res /= (size ? size : 1);
         break;
     } 
-  return res;
+	result = res;
+	return 0;
   }  
 
-  double GetDirectionalViewMapDensityF1D::operator()(Interface1D& inter) {
+  int GetDirectionalViewMapDensityF1D::operator()(Interface1D& inter) {
     //soc unsigned size;
-    double res =  integrate(_fun, inter.pointsBegin(_sampling), inter.pointsEnd(_sampling), _integration);
-    return res;
+    result = integrate(_fun, inter.pointsBegin(_sampling), inter.pointsEnd(_sampling), _integration);
+    return 0;
   } 
   
-  double GetCompleteViewMapDensityF1D::operator()(Interface1D& inter) {
+  int GetCompleteViewMapDensityF1D::operator()(Interface1D& inter) {
     //soc unsigned size;
     Id id = inter.getId();
-    double res =  integrate(_fun, inter.pointsBegin(_sampling), inter.pointsEnd(_sampling), _integration);
-    return res;
+    result = integrate(_fun, inter.pointsBegin(_sampling), inter.pointsEnd(_sampling), _integration);
+    return 0;
   } 
 
-  real GetViewMapGradientNormF1D::operator()(Interface1D& inter){
-	return integrate(_func, inter.pointsBegin(_sampling), inter.pointsEnd(_sampling), _integration);
+  int GetViewMapGradientNormF1D::operator()(Interface1D& inter){
+	result = integrate(_func, inter.pointsBegin(_sampling), inter.pointsEnd(_sampling), _integration);
+	return 0;
   }
 }
 

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/AdvancedFunctions1D.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/AdvancedFunctions1D.h	2009-03-20 22:45:22 UTC (rev 19341)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/AdvancedFunctions1D.h	2009-03-20 22:55:07 UTC (rev 19342)
@@ -78,8 +78,9 @@
       return "DensityF1D";
     }
     /*! the () operator.*/
-    double operator()(Interface1D& inter) {
-      return integrate(_fun, inter.pointsBegin(_sampling), inter.pointsEnd(_sampling), _integration);
+    int operator()(Interface1D& inter) {
+      result = integrate(_fun, inter.pointsBegin(_sampling), inter.pointsEnd(_sampling), _integration);
+	  return 0;
     }
   private:
     Functions0D::DensityF0D	_fun;
@@ -112,8 +113,9 @@
       return "LocalAverageDepthF1D";
     }
     /*! the () operator.*/
-    double operator()(Interface1D& inter) {
-      return integrate(_fun, inter.verticesBegin(), inter.verticesEnd(), _integration);
+    int operator()(Interface1D& inter) {
+      result = integrate(_fun, inter.verticesBegin(), inter.verticesEnd(), _integration);
+	  return 0;
     }
   private:
     Functions0D::LocalAverageDepthF0D	_fun;
@@ -150,7 +152,7 @@
       return "GetCompleteViewMapDensityF1D";
     }
     /*! the () operator.*/
-    double operator()(Interface1D& inter);
+    int operator()(Interface1D& inter);
     
   private:
     Functions0D::ReadCompleteViewMapPixelF0D _fun;
@@ -193,7 +195,7 @@
       return "GetDirectionalViewMapDensityF1D";
     }
     /*! the () operator.*/
-    double operator()(Interface1D& inter);
+    int operator()(Interface1D& inter);
     
   private:
     Functions0D::ReadSteerableViewMapPixelF0D _fun;
@@ -238,7 +240,7 @@
       return "GetSteerableViewMapDensityF1D";
     }
     /*! the () operator.*/
-    real operator()(Interface1D& inter);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list