Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2009-03-21 01:55:07 +0300
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2009-03-21 01:55:07 +0300
commita0682124459d870e53f1bc5d9b1d2930e5a907f3 (patch)
treea8bd700614557ceeea6a57d6a58306948292a5f9 /source/blender/freestyle/intern/view_map/Functions0D.cpp
parentac0918a1beb4c40dab17a914ca58042642a266d0 (diff)
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);
Diffstat (limited to 'source/blender/freestyle/intern/view_map/Functions0D.cpp')
-rwxr-xr-xsource/blender/freestyle/intern/view_map/Functions0D.cpp87
1 files changed, 48 insertions, 39 deletions
diff --git a/source/blender/freestyle/intern/view_map/Functions0D.cpp b/source/blender/freestyle/intern/view_map/Functions0D.cpp
index 1bd6d6f46f1..d6b820e3b18 100755
--- a/source/blender/freestyle/intern/view_map/Functions0D.cpp
+++ b/source/blender/freestyle/intern/view_map/Functions0D.cpp
@@ -146,7 +146,7 @@ namespace Functions0D {
}
//
- Vec2f VertexOrientation2DF0D::operator()(Interface0DIterator& iter) {
+ int VertexOrientation2DF0D::operator()(Interface0DIterator& iter) {
Vec2f A,C;
Vec2f B(iter->getProjectedX(), iter->getProjectedY());
if(iter.isBegin())
@@ -170,13 +170,13 @@ namespace Functions0D {
Vec2f BC(C-B);
if(BC.norm() != 0)
BC.normalize();
- Vec2f res (AB + BC);
- if(res.norm() != 0)
- res.normalize();
- return res;
+ result = AB + BC;
+ if(result.norm() != 0)
+ result.normalize();
+ return 0;
}
- Vec3f VertexOrientation3DF0D::operator()(Interface0DIterator& iter) {
+ int VertexOrientation3DF0D::operator()(Interface0DIterator& iter) {
Vec3r A,C;
Vec3r B(iter->getX(), iter->getY(), iter->getZ());
if(iter.isBegin())
@@ -200,13 +200,13 @@ namespace Functions0D {
Vec3r BC(C-B);
if(BC.norm() != 0)
BC.normalize();
- Vec3f res (AB + BC);
- if(res.norm() != 0)
- res.normalize();
- return res;
+ result = AB + BC;
+ if(result.norm() != 0)
+ result.normalize();
+ return 0;
}
- real Curvature2DAngleF0D::operator()(Interface0DIterator& iter) {
+ int Curvature2DAngleF0D::operator()(Interface0DIterator& iter) {
Interface0DIterator tmp1 = iter, tmp2 = iter;
++tmp2;
unsigned count = 1;
@@ -220,8 +220,11 @@ namespace Functions0D {
++tmp2;
++count;
}
- if(count < 3)
- return 0; // if we only have 2 vertices
+ if(count < 3) {
+ // if we only have 2 vertices
+ result = 0;
+ return -1;
+ }
Interface0DIterator v = iter;
if(iter.isBegin())
@@ -250,29 +253,30 @@ namespace Functions0D {
if((N1.norm() == 0) && (N2.norm() == 0))
{
Exception::raiseException();
- return 0;
+ result = 0;
+ return -1;
}
double cosin = N1*N2;
if(cosin > 1)
cosin = 1;
if(cosin < -1)
cosin = -1;
- return acos(cosin);
+ result = acos(cosin);
+ return 0;
}
- real ZDiscontinuityF0D::operator()(Interface0DIterator& iter) {
+ int ZDiscontinuityF0D::operator()(Interface0DIterator& iter) {
FEdge *fe1, *fe2;
getFEdges(iter, fe1, fe2);
- real result ;
result = fe1->z_discontinuity();
if(fe2!=0){
result += fe2->z_discontinuity();
result /= 2.f;
}
- return result;
+ return 0;
}
- Vec2f Normal2DF0D::operator()(Interface0DIterator& iter) {
+ int Normal2DF0D::operator()(Interface0DIterator& iter) {
FEdge *fe1, *fe2;
getFEdges(iter,fe1,fe2);
Vec3f e1(fe1->orientation2d());
@@ -285,31 +289,32 @@ namespace Functions0D {
n += n2;
}
n.normalize();
- return n;
+ result = n;
+ return 0;
}
- FrsMaterial MaterialF0D::operator()(Interface0DIterator& iter) {
+ int MaterialF0D::operator()(Interface0DIterator& iter) {
FEdge *fe1, *fe2;
getFEdges(iter,fe1,fe2);
if(fe1 == 0)
getFEdges(iter, fe1, fe2);
- FrsMaterial mat;
if(fe1->isSmooth())
- mat = ((FEdgeSmooth*)fe1)->frs_material();
+ result = ((FEdgeSmooth*)fe1)->frs_material();
else
- mat = ((FEdgeSharp*)fe1)->bFrsMaterial();
+ result = ((FEdgeSharp*)fe1)->bFrsMaterial();
// const SShape * sshape = getShapeF0D(iter);
// return sshape->material();
- return mat;
+ return 0;
}
- Id ShapeIdF0D::operator()(Interface0DIterator& iter) {
+ int ShapeIdF0D::operator()(Interface0DIterator& iter) {
ViewShape * vshape = getShapeF0D(iter);
- return vshape->getId();
+ result = vshape->getId();
+ return 0;
}
- unsigned int QuantitativeInvisibilityF0D::operator()(Interface0DIterator& iter) {
+ int QuantitativeInvisibilityF0D::operator()(Interface0DIterator& iter) {
ViewEdge * ve1, *ve2;
getViewEdges(iter,ve1,ve2);
unsigned int qi1, qi2;
@@ -319,38 +324,42 @@ namespace Functions0D {
if(qi2!=qi1)
cout << "QuantitativeInvisibilityF0D: ambiguous evaluation for point " << iter->getId() << endl;
}
- return qi1;
+ result = qi1;
+ return 0;
}
- Nature::EdgeNature CurveNatureF0D::operator()(Interface0DIterator& iter) {
+ int CurveNatureF0D::operator()(Interface0DIterator& iter) {
Nature::EdgeNature nat = 0;
ViewEdge * ve1, *ve2;
getViewEdges(iter, ve1, ve2);
nat |= ve1->getNature();
if(ve2!=0)
nat |= ve2->getNature();
- return nat;
+ result = nat;
+ return 0;
}
- vector<ViewShape*> GetOccludersF0D::operator()(Interface0DIterator& iter) {
+ int GetOccludersF0D::operator()(Interface0DIterator& iter) {
set<ViewShape*> occluders;
getOccludersF0D(iter,occluders);
- vector<ViewShape*> vsOccluders;
+ result.clear();
// vsOccluders.insert(vsOccluders.begin(), occluders.begin(), occluders.end());
for(set<ViewShape*>::iterator it=occluders.begin(), itend=occluders.end();
it!=itend;
++it){
- vsOccluders.push_back((*it));
+ result.push_back((*it));
}
- return vsOccluders;
+ return 0;
}
- ViewShape* GetShapeF0D::operator()(Interface0DIterator& iter) {
- return getShapeF0D(iter);
+ int GetShapeF0D::operator()(Interface0DIterator& iter) {
+ result = getShapeF0D(iter);
+ return 0;
}
- ViewShape* GetOccludeeF0D::operator()(Interface0DIterator& iter) {
- return getOccludeeF0D(iter);
+ int GetOccludeeF0D::operator()(Interface0DIterator& iter) {
+ result = getOccludeeF0D(iter);
+ return 0;
}
} // end of namespace Functions0D