diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-05-31 15:51:19 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-05-31 15:55:15 +0300 |
commit | d8dbd49a2f23b7637f05fc058f39bdf6ab706624 (patch) | |
tree | 0805b9372c82ae6505d87e879824efe1d3e32f8e /source/blender/freestyle/intern/stroke | |
parent | 8987f7987d8160e1f6e79e8c85d6ce65b885ab25 (diff) |
Cleanup: style, use braces in source/
Automated using clang-tidy.
Diffstat (limited to 'source/blender/freestyle/intern/stroke')
26 files changed, 618 insertions, 309 deletions
diff --git a/source/blender/freestyle/intern/stroke/AdvancedFunctions1D.cpp b/source/blender/freestyle/intern/stroke/AdvancedFunctions1D.cpp index fd97138c91b..ef151365fa0 100644 --- a/source/blender/freestyle/intern/stroke/AdvancedFunctions1D.cpp +++ b/source/blender/freestyle/intern/stroke/AdvancedFunctions1D.cpp @@ -69,8 +69,9 @@ int GetSteerableViewMapDensityF1D::operator()(Interface1D &inter) ++v; for (; v != vend; ++v) { res_tmp = *v; - if (res_tmp < res) + if (res_tmp < res) { res = res_tmp; + } } break; case MAX: @@ -78,8 +79,9 @@ int GetSteerableViewMapDensityF1D::operator()(Interface1D &inter) ++v; for (; v != vend; ++v) { res_tmp = *v; - if (res_tmp > res) + if (res_tmp > res) { res = res_tmp; + } } break; case FIRST: @@ -93,8 +95,9 @@ int GetSteerableViewMapDensityF1D::operator()(Interface1D &inter) default: res = *v; ++v; - for (; v != vend; ++v, ++size) + for (; v != vend; ++v, ++size) { res += *v; + } res /= (size ? size : 1); break; } diff --git a/source/blender/freestyle/intern/stroke/AdvancedPredicates1D.h b/source/blender/freestyle/intern/stroke/AdvancedPredicates1D.h index df66f82b868..05fcf7f356f 100644 --- a/source/blender/freestyle/intern/stroke/AdvancedPredicates1D.h +++ b/source/blender/freestyle/intern/stroke/AdvancedPredicates1D.h @@ -67,8 +67,9 @@ class DensityLowerThanUP1D : public UnaryPredicate1D { int operator()(Interface1D &inter) { Functions1D::DensityF1D fun(_sigma); - if (fun(inter) < 0) + if (fun(inter) < 0) { return -1; + } result = (fun.result < _threshold); return 0; } diff --git a/source/blender/freestyle/intern/stroke/AdvancedStrokeShaders.cpp b/source/blender/freestyle/intern/stroke/AdvancedStrokeShaders.cpp index 6a0d3b0b793..96375407256 100644 --- a/source/blender/freestyle/intern/stroke/AdvancedStrokeShaders.cpp +++ b/source/blender/freestyle/intern/stroke/AdvancedStrokeShaders.cpp @@ -53,8 +53,9 @@ int CalligraphicShader::shade(Stroke &ioStroke) const StrokeVertex *sv; for (v = ioStroke.verticesBegin(); !v.isEnd(); ++v) { real thickness; - if (fun(v) < 0) + if (fun(v) < 0) { return -1; + } Vec2f vertexOri(fun.result); Vec2r ori2d(-vertexOri[1], vertexOri[0]); @@ -70,8 +71,9 @@ int CalligraphicShader::shade(Stroke &ioStroke) const sv->attribute().setColor(0, 0, 0); } thickness = _minThickness + scal * (_maxThickness - _minThickness); - if (thickness < 0.0) + if (thickness < 0.0) { thickness = 0.0; + } sv->attribute().setThickness(thickness / 2.0, thickness / 2.0); } @@ -91,10 +93,12 @@ SpatialNoiseShader::SpatialNoiseShader( : StrokeShader() { _amount = ioamount; - if (ixScale == 0) + if (ixScale == 0) { _xScale = 0; - else + } + else { _xScale = 1.0 / ixScale / real(NB_VALUE_NOISE); + } _nbOctave = nbOctave; _smooth = smooth; _pureRandom = pureRandom; @@ -112,15 +116,17 @@ int SpatialNoiseShader::shade(Stroke &ioStroke) const StrokeVertex *sv; sv = dynamic_cast<StrokeVertex *>(&(*v)); real initU = sv->strokeLength() * real(NB_VALUE_NOISE); - if (_pureRandom) + if (_pureRandom) { initU += RandGen::drand48() * real(NB_VALUE_NOISE); + } Functions0D::VertexOrientation2DF0D fun; while (!v.isEnd()) { sv = dynamic_cast<StrokeVertex *>(&(*v)); Vec2r p(sv->getPoint()); - if (fun(v) < 0) + if (fun(v) < 0) { return -1; + } Vec2r vertexOri(fun.result); Vec2r ori2d(vertexOri[0], vertexOri[1]); ori2d = Vec2r(p - p0); @@ -129,10 +135,12 @@ int SpatialNoiseShader::shade(Stroke &ioStroke) const PseudoNoise mynoise; real bruit; - if (_smooth) + if (_smooth) { bruit = mynoise.turbulenceSmooth(_xScale * sv->curvilinearAbscissa() + initU, _nbOctave); - else + } + else { bruit = mynoise.turbulenceLinear(_xScale * sv->curvilinearAbscissa() + initU, _nbOctave); + } Vec2r noise(-ori2d[1] * _amount * bruit, ori2d[0] * _amount * bruit); @@ -236,15 +244,17 @@ void Smoother::smooth(int nbIteration, _factorPoint = iFactorPoint; _anisoPoint = iAnisoPoint; - for (int i = 0; i < nbIteration; ++i) + for (int i = 0; i < nbIteration; ++i) { iteration(); + } copyVertices(); } static real edgeStopping(real x, real sigma) { - if (sigma == 0.0) + if (sigma == 0.0) { return 1.0; + } return exp(-x * x / (sigma * sigma)); } @@ -262,8 +272,9 @@ void Smoother::iteration() diffC2; //_factorCurvatureDifference; motionCurvature *= _factorCurvatureDifference; // motionCurvature = _factorCurvatureDifference * (diffC1 + diffC2); - if (_safeTest) + if (_safeTest) { _vertex[i] = Vec2r(_vertex[i] + (motionNormal + motionCurvature) * _normal[i]); + } Vec2r v1(_vertex[i - 1] - _vertex[i]); Vec2r v2(_vertex[i + 1] - _vertex[i]); real d1 = v1.norm(); @@ -305,8 +316,9 @@ void Smoother::computeCurvature() _normal[i].normalizeSafe(); _curvature[i] = normalCurvature * _normal[i]; - if (lba + lbc > M_EPSILON) + if (lba + lbc > M_EPSILON) { _curvature[i] /= (0.5 * lba + lbc); + } } _curvature[0] = _curvature[1]; _curvature[_nbVertices - 1] = _curvature[_nbVertices - 2]; @@ -329,8 +341,9 @@ void Smoother::computeCurvature() _normal[i].normalizeSafe(); _curvature[i] = normalCurvature * _normal[i]; - if (lba + lbc > M_EPSILON) + if (lba + lbc > M_EPSILON) { _curvature[i] /= (0.5 * lba + lbc); + } _normal[_nbVertices - 1] = _normal[0]; _curvature[_nbVertices - 1] = _curvature[0]; diff --git a/source/blender/freestyle/intern/stroke/BasicStrokeShaders.cpp b/source/blender/freestyle/intern/stroke/BasicStrokeShaders.cpp index 9bdad9f1b32..befcaf7dc1d 100644 --- a/source/blender/freestyle/intern/stroke/BasicStrokeShaders.cpp +++ b/source/blender/freestyle/intern/stroke/BasicStrokeShaders.cpp @@ -59,10 +59,12 @@ int ConstantThicknessShader::shade(Stroke &stroke) const for (v = stroke.strokeVerticesBegin(), vend = stroke.strokeVerticesEnd(); v != vend; ++v) { // XXX What's the use of i here? And is not the thickness always overriden by the last line of // the loop? - if ((1 == i) || (size - 2 == i)) + if ((1 == i) || (size - 2 == i)) { v->attribute().setThickness(_thickness / 4.0, _thickness / 4.0); - if ((0 == i) || (size - 1 == i)) + } + if ((0 == i) || (size - 1 == i)) { v->attribute().setThickness(0, 0); + } v->attribute().setThickness(_thickness / 2.0, _thickness / 2.0); } @@ -77,10 +79,12 @@ int ConstantExternThicknessShader::shade(Stroke &stroke) const for (v = stroke.strokeVerticesBegin(), vend = stroke.strokeVerticesEnd(); v != vend; ++v) { // XXX What's the use of i here? And is not the thickness always overriden by the last line of // the loop? - if ((1 == i) || (size - 2 == i)) + if ((1 == i) || (size - 2 == i)) { v->attribute().setThickness(_thickness / 2.0, 0); - if ((0 == i) || (size - 1 == i)) + } + if ((0 == i) || (size - 1 == i)) { v->attribute().setThickness(0, 0); + } v->attribute().setThickness(_thickness, 0); } @@ -94,10 +98,12 @@ int IncreasingThicknessShader::shade(Stroke &stroke) const for (i = 0, v = stroke.strokeVerticesBegin(), vend = stroke.strokeVerticesEnd(); v != vend; ++v, ++i) { float t; - if (i < (float)n / 2.0f) + if (i < (float)n / 2.0f) { t = (1.0 - (float)i / (float)n) * _ThicknessMin + (float)i / (float)n * _ThicknessMax; - else + } + else { t = (1.0 - (float)i / (float)n) * _ThicknessMax + (float)i / (float)n * _ThicknessMin; + } v->attribute().setThickness(t / 2.0, t / 2.0); } return 0; @@ -114,13 +120,16 @@ int ConstrainedIncreasingThicknessShader::shade(Stroke &stroke) const // XXX Why not using an if/else here? Else, if last condition is true, everything else is // computed for nothing! float t; - if (i < (float)n / 2.0f) + if (i < (float)n / 2.0f) { t = (1.0 - (float)i / (float)n) * _ThicknessMin + (float)i / (float)n * maxT; - else + } + else { t = (1.0 - (float)i / (float)n) * maxT + (float)i / (float)n * _ThicknessMin; + } v->attribute().setThickness(t / 2.0, t / 2.0); - if (i == n - 1) + if (i == n - 1) { v->attribute().setThickness(_ThicknessMin / 2.0, _ThicknessMin / 2.0); + } } return 0; } @@ -130,14 +139,18 @@ int LengthDependingThicknessShader::shade(Stroke &stroke) const float step = (_maxThickness - _minThickness) / 3.0f; float l = stroke.getLength2D(); float thickness = 0.0f; - if (l > 300.0f) + if (l > 300.0f) { thickness = _minThickness + 3.0f * step; - else if ((l < 300.0f) && (l > 100.0f)) + } + else if ((l < 300.0f) && (l > 100.0f)) { thickness = _minThickness + 2.0f * step; - else if ((l < 100.0f) && (l > 50.0f)) + } + else if ((l < 100.0f) && (l > 50.0f)) { thickness = _minThickness + 1.0f * step; - else // else if (l < 50.0f), tsst... + } + else { // else if (l < 50.0f), tsst... thickness = _minThickness; + } StrokeInternal::StrokeVertexIterator v, vend; int i = 0; @@ -145,10 +158,12 @@ int LengthDependingThicknessShader::shade(Stroke &stroke) const for (v = stroke.strokeVerticesBegin(), vend = stroke.strokeVerticesEnd(); v != vend; ++v) { // XXX What's the use of i here? And is not the thickness always overriden by the last line of // the loop? - if ((1 == i) || (size - 2 == i)) + if ((1 == i) || (size - 2 == i)) { v->attribute().setThickness(thickness / 4.0, thickness / 4.0); - if ((0 == i) || (size - 1 == i)) + } + if ((0 == i) || (size - 1 == i)) { v->attribute().setThickness(0, 0); + } v->attribute().setThickness(thickness / 2.0, thickness / 2.0); } @@ -231,8 +246,9 @@ int MaterialColorShader::shade(Stroke &stroke) const Functions0D::MaterialF0D fun; StrokeVertex *sv; for (v = stroke.verticesBegin(), vend = stroke.verticesEnd(); v != vend; ++v) { - if (fun(v) < 0) + if (fun(v) < 0) { return -1; + } const float *diffuse = fun.result.diffuse(); sv = dynamic_cast<StrokeVertex *>(&(*v)); sv->attribute().setColor( @@ -281,8 +297,9 @@ int ColorNoiseShader::shade(Stroke &stroke) const int BlenderTextureShader::shade(Stroke &stroke) const { - if (_mtex) + if (_mtex) { return stroke.setMTex(_mtex); + } if (_nodeTree) { stroke.setNodeTree(_nodeTree); return 0; @@ -304,8 +321,9 @@ int StrokeTextureStepShader::shade(Stroke &stroke) const int BackboneStretcherShader::shade(Stroke &stroke) const { float l = stroke.getLength2D(); - if (l <= 1.0e-6) + if (l <= 1.0e-6) { return 0; + } StrokeInternal::StrokeVertexIterator v0 = stroke.strokeVerticesBegin(); StrokeInternal::StrokeVertexIterator v1 = v0; @@ -346,8 +364,9 @@ int ExternalContourStretcherShader::shade(Stroke &stroke) const Functions0D::Normal2DF0D fun; StrokeVertex *sv; for (it = stroke.verticesBegin(); !it.isEnd(); ++it) { - if (fun(it) < 0) + if (fun(it) < 0) { return -1; + } Vec2f n(fun.result); sv = dynamic_cast<StrokeVertex *>(&(*it)); Vec2d newPoint(sv->x() + _amount * n.x(), sv->y() + _amount * n.y()); @@ -360,8 +379,9 @@ int ExternalContourStretcherShader::shade(Stroke &stroke) const //!! Bezier curve stroke shader int BezierCurveShader::shade(Stroke &stroke) const { - if (stroke.strokeVerticesSize() < 4) + if (stroke.strokeVerticesSize() < 4) { return 0; + } // Build the Bezier curve from this set of data points: vector<Vec2d> data; @@ -371,8 +391,9 @@ int BezierCurveShader::shade(Stroke &stroke) const ++v; for (vend = stroke.strokeVerticesEnd(); v != vend; ++v) { if (!((fabs(v->x() - (previous)->x()) < M_EPSILON) && - ((fabs(v->y() - (previous)->y()) < M_EPSILON)))) + ((fabs(v->y() - (previous)->y()) < M_EPSILON)))) { data.push_back(Vec2d(v->x(), v->y())); + } previous = v; } @@ -435,8 +456,9 @@ int BezierCurveShader::shade(Stroke &stroke) const stroke.UpdateLength(); // Deal with extra vertices: - if (nExtraVertex == 0) + if (nExtraVertex == 0) { return 0; + } // nExtraVertex should stay unassigned vector<StrokeAttribute> attributes; @@ -504,8 +526,9 @@ class CurvePiece { for (StrokeInternal::StrokeVertexIterator it = _begin; it != _last; ++it) { Vec2d P(it->x(), it->y()); float d = GeomUtils::distPointSegment(P, A, B); - if (d > maxE) + if (d > maxE) { maxE = d; + } } _error = maxE; return maxE; @@ -520,8 +543,9 @@ class CurvePiece { int ns = size - 1; // number of segments (ns > 1) int ns1 = ns / 2; int ns2 = ns - ns1; - for (int i = 0; i < ns1; ++it, ++i) + for (int i = 0; i < ns1; ++it, ++i) { ; + } CurvePiece *second = new CurvePiece(it, _last, ns2 + 1); size = ns1 + 1; @@ -600,8 +624,9 @@ int GuidingLinesShader::shade(Stroke &stroke) const Vec2d u = piece.B - piece.A; Vec2f n(u[1], -u[0]); n.normalize(); - if (norm_fun(stroke) < 0) + if (norm_fun(stroke) < 0) { return -1; + } Vec2f strokeN(norm_fun.result); if (n * strokeN < 0) { n[0] = -n[0]; @@ -632,8 +657,9 @@ int TipRemoverShader::shade(Stroke &stroke) const { int originalSize = stroke.strokeVerticesSize(); - if (originalSize < 4) + if (originalSize < 4) { return 0; + } StrokeInternal::StrokeVertexIterator v, vend; vector<StrokeVertex *> verticesToRemove; @@ -646,8 +672,9 @@ int TipRemoverShader::shade(Stroke &stroke) const oldAttributes.push_back(v->attribute()); } - if (originalSize - verticesToRemove.size() < 2) + if (originalSize - verticesToRemove.size() < 2) { return 0; + } vector<StrokeVertex *>::iterator sv, svend; for (sv = verticesToRemove.begin(), svend = verticesToRemove.end(); sv != svend; ++sv) { @@ -657,8 +684,9 @@ int TipRemoverShader::shade(Stroke &stroke) const // Resample so that our new stroke have the same number of vertices than before stroke.Resample(originalSize); - if ((int)stroke.strokeVerticesSize() != originalSize) // soc + if ((int)stroke.strokeVerticesSize() != originalSize) { // soc cerr << "Warning: resampling problem" << endl; + } // assign old attributes to new stroke vertices: vector<StrokeAttribute>::iterator a = oldAttributes.begin(), aend = oldAttributes.end(); diff --git a/source/blender/freestyle/intern/stroke/Canvas.cpp b/source/blender/freestyle/intern/stroke/Canvas.cpp index 95bbafc0aa0..4cb00b18f60 100644 --- a/source/blender/freestyle/intern/stroke/Canvas.cpp +++ b/source/blender/freestyle/intern/stroke/Canvas.cpp @@ -92,8 +92,9 @@ Canvas::~Canvas() } _maps.clear(); } - if (_steerableViewMap) + if (_steerableViewMap) { delete _steerableViewMap; + } } void Canvas::preDraw() @@ -102,20 +103,23 @@ void Canvas::preDraw() void Canvas::Draw() { - if (_StyleModules.empty()) + if (_StyleModules.empty()) { return; + } preDraw(); TimeStamp *timestamp = TimeStamp::instance(); for (unsigned int i = 0; i < _StyleModules.size(); ++i) { _current_sm = _StyleModules[i]; - if (i < _Layers.size() && _Layers[i]) + if (i < _Layers.size() && _Layers[i]) { delete _Layers[i]; + } _Layers[i] = _StyleModules[i]->execute(); - if (!_Layers[i]) + if (!_Layers[i]) { continue; + } stroke_count += _Layers[i]->strokes_size(); @@ -134,8 +138,9 @@ void Canvas::Clear() if (!_Layers.empty()) { for (deque<StrokeLayer *>::iterator sl = _Layers.begin(), slend = _Layers.end(); sl != slend; ++sl) { - if (*sl) + if (*sl) { delete (*sl); + } } _Layers.clear(); } @@ -144,13 +149,15 @@ void Canvas::Clear() for (deque<StyleModule *>::iterator s = _StyleModules.begin(), send = _StyleModules.end(); s != send; ++s) { - if (*s) + if (*s) { delete (*s); + } } _StyleModules.clear(); } - if (_steerableViewMap) + if (_steerableViewMap) { _steerableViewMap->Reset(); + } stroke_count = 0; } @@ -160,12 +167,14 @@ void Canvas::Erase() if (!_Layers.empty()) { for (deque<StrokeLayer *>::iterator sl = _Layers.begin(), slend = _Layers.end(); sl != slend; ++sl) { - if (*sl) + if (*sl) { (*sl)->clear(); + } } } - if (_steerableViewMap) + if (_steerableViewMap) { _steerableViewMap->Reset(); + } update(); stroke_count = 0; @@ -200,8 +209,9 @@ void Canvas::RemoveStyleModule(unsigned index) ++s, ++i) { if (i == index) { // remove shader - if (*s) + if (*s) { delete *s; + } _StyleModules.erase(s); break; } @@ -214,8 +224,9 @@ void Canvas::RemoveStyleModule(unsigned index) ++sl, ++i) { if (i == index) { // remove layer - if (*sl) + if (*sl) { delete *sl; + } _Layers.erase(sl); break; } @@ -243,8 +254,9 @@ void Canvas::ReplaceStyleModule(unsigned index, StyleModule *iStyleModule) s != send; ++s, ++i) { if (i == index) { - if (*s) + if (*s) { delete *s; + } *s = iStyleModule; break; } @@ -264,8 +276,9 @@ void Canvas::setModified(unsigned index, bool iMod) void Canvas::resetModified(bool iMod /* = false */) { unsigned int size = _StyleModules.size(); - for (unsigned int i = 0; i < size; ++i) + for (unsigned int i = 0; i < size; ++i) { setModified(i, iMod); + } } void Canvas::causalStyleModules(vector<unsigned> &vec, unsigned index) @@ -273,16 +286,18 @@ void Canvas::causalStyleModules(vector<unsigned> &vec, unsigned index) unsigned int size = _StyleModules.size(); for (unsigned int i = index; i < size; ++i) { - if (_StyleModules[i]->getCausal()) + if (_StyleModules[i]->getCausal()) { vec.push_back(i); + } } } void Canvas::Render(const StrokeRenderer *iRenderer) { for (unsigned int i = 0; i < _StyleModules.size(); ++i) { - if (!_StyleModules[i]->getDisplayed() || !_Layers[i]) + if (!_StyleModules[i]->getDisplayed() || !_Layers[i]) { continue; + } _Layers[i]->Render(iRenderer); } } @@ -290,8 +305,9 @@ void Canvas::Render(const StrokeRenderer *iRenderer) void Canvas::RenderBasic(const StrokeRenderer *iRenderer) { for (unsigned int i = 0; i < _StyleModules.size(); ++i) { - if (!_StyleModules[i]->getDisplayed() || !_Layers[i]) + if (!_StyleModules[i]->getDisplayed() || !_Layers[i]) { continue; + } _Layers[i]->RenderBasic(iRenderer); } } @@ -462,8 +478,9 @@ float Canvas::readMapPixel(const char *iMapName, int level, int x, int y) return -1; } ImagePyramid *pyramid = (*m).second; - if ((x < 0) || (x >= pyramid->width()) || (y < 0) || (y >= pyramid->height())) + if ((x < 0) || (x >= pyramid->width()) || (y < 0) || (y >= pyramid->height())) { return 0; + } return pyramid->pixel(x, height() - 1 - y, level); } diff --git a/source/blender/freestyle/intern/stroke/Chain.cpp b/source/blender/freestyle/intern/stroke/Chain.cpp index d4cc4fd68c3..79d174d8117 100644 --- a/source/blender/freestyle/intern/stroke/Chain.cpp +++ b/source/blender/freestyle/intern/stroke/Chain.cpp @@ -45,10 +45,12 @@ void Chain::push_viewedge_back(ViewEdge *iViewEdge, bool orientation) if (!_Vertices.empty()) { previous = _Vertices.back()->point2d(); - if (orientation) + if (orientation) { ++v; - else + } + else { --v; + } // Ensure the continuity of underlying FEdges CurvePoint *cp = _Vertices.back(); // assumed to be instantiated as new CurvePoint(iSVertex, 0, 0.f); @@ -69,10 +71,12 @@ void Chain::push_viewedge_back(ViewEdge *iViewEdge, bool orientation) Curve::push_vertex_back(*v); //_Length += (current - previous).norm(); previous = current; - if (orientation) + if (orientation) { ++v; - else + } + else { --v; + } } while ((v != vend) && (v != vfirst)); if (v == vfirst) { @@ -105,10 +109,12 @@ void Chain::push_viewedge_front(ViewEdge *iViewEdge, bool orientation) if (!_Vertices.empty()) { previous = _Vertices.front()->point2d(); - if (orientation) + if (orientation) { ++v; - else + } + else { --v; + } // Ensure the continuity of underlying FEdges CurvePoint *cp = _Vertices.front(); // assumed to be instantiated as new CurvePoint(iSVertex, 0, 0.f); @@ -131,10 +137,12 @@ void Chain::push_viewedge_front(ViewEdge *iViewEdge, bool orientation) Curve::push_vertex_front((*v)); //_Length += (current - previous).norm(); previous = current; - if (orientation) + if (orientation) { ++v; - else + } + else { --v; + } } while ((v != vend) && (v != vfirst)); if (v == vfirst) { @@ -144,8 +152,9 @@ void Chain::push_viewedge_front(ViewEdge *iViewEdge, bool orientation) //_Length += (current - previous).norm(); } - if (!_fedgeB) + if (!_fedgeB) { _fedgeB = (orientation) ? iViewEdge->fedgeB() : iViewEdge->fedgeA(); + } } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/stroke/Chain.h b/source/blender/freestyle/intern/stroke/Chain.h index 547fed70953..2c19748771e 100644 --- a/source/blender/freestyle/intern/stroke/Chain.h +++ b/source/blender/freestyle/intern/stroke/Chain.h @@ -65,8 +65,9 @@ class Chain : public Curve { { // only the last splitted deletes this id if (_splittingId) { - if (*_splittingId == _Id) + if (*_splittingId == _Id) { delete _splittingId; + } } } diff --git a/source/blender/freestyle/intern/stroke/ChainingIterators.cpp b/source/blender/freestyle/intern/stroke/ChainingIterators.cpp index 551b9aa4043..271db48aabe 100644 --- a/source/blender/freestyle/intern/stroke/ChainingIterators.cpp +++ b/source/blender/freestyle/intern/stroke/ChainingIterators.cpp @@ -40,20 +40,23 @@ bool AdjacencyIterator::isIncoming() const int AdjacencyIterator::increment() { ++_internalIterator; - while ((!_internalIterator.isEnd()) && (!isValid((*_internalIterator).first))) + while ((!_internalIterator.isEnd()) && (!isValid((*_internalIterator).first))) { ++_internalIterator; + } return 0; } bool AdjacencyIterator::isValid(ViewEdge *edge) { if (_restrictToSelection) { - if (edge->getTimeStamp() != TimeStamp::instance()->getTimeStamp()) + if (edge->getTimeStamp() != TimeStamp::instance()->getTimeStamp()) { return false; + } } if (_restrictToUnvisited) { - if (edge->getChainingTimeStamp() > TimeStamp::instance()->getTimeStamp()) + if (edge->getChainingTimeStamp() > TimeStamp::instance()->getTimeStamp()) { return false; + } } return true; } @@ -81,15 +84,19 @@ int ChainingIterator::increment() _edge = 0; return 0; } - if (traverse(it) < 0) + if (traverse(it) < 0) { return -1; + } _edge = result; - if (_edge == 0) + if (_edge == 0) { return 0; - if (_edge->A() == vertex) + } + if (_edge->A() == vertex) { _orientation = true; - else + } + else { _orientation = false; + } return 0; } @@ -106,15 +113,19 @@ int ChainingIterator::decrement() _edge = 0; return 0; } - if (traverse(it) < 0) + if (traverse(it) < 0) { return -1; + } _edge = result; - if (_edge == 0) + if (_edge == 0) { return 0; - if (_edge->B() == vertex) + } + if (_edge->B() == vertex) { _orientation = true; - else + } + else { _orientation = false; + } return 0; } @@ -186,17 +197,20 @@ int ChainSilhouetteIterator::traverse(const AdjacencyIterator &ait) int ChainPredicateIterator::traverse(const AdjacencyIterator &ait) { - if (!_unary_predicate || !_binary_predicate) + if (!_unary_predicate || !_binary_predicate) { return -1; + } AdjacencyIterator it(ait); // Iterates over next edges to see if one of them respects the predicate: while (!it.isEnd()) { ViewEdge *ve = *it; - if (_unary_predicate->operator()(*ve) < 0) + if (_unary_predicate->operator()(*ve) < 0) { return -1; + } if (_unary_predicate->result) { - if (_binary_predicate->operator()(*(getCurrentEdge()), *(ve)) < 0) + if (_binary_predicate->operator()(*(getCurrentEdge()), *(ve)) < 0) { return -1; + } if (_binary_predicate->result) { result = ve; return 0; diff --git a/source/blender/freestyle/intern/stroke/ChainingIterators.h b/source/blender/freestyle/intern/stroke/ChainingIterators.h index 52da85ccc58..3cc322a2a4b 100644 --- a/source/blender/freestyle/intern/stroke/ChainingIterators.h +++ b/source/blender/freestyle/intern/stroke/ChainingIterators.h @@ -60,8 +60,9 @@ class AdjacencyIterator : public Iterator { _restrictToSelection = iRestrictToSelection; _restrictToUnvisited = iRestrictToUnvisited; _internalIterator = iVertex->edgesBegin(); - while ((!_internalIterator.isEnd()) && (!isValid((*_internalIterator).first))) + while ((!_internalIterator.isEnd()) && (!isValid((*_internalIterator).first))) { ++_internalIterator; + } } AdjacencyIterator(const AdjacencyIterator &iBrother) diff --git a/source/blender/freestyle/intern/stroke/Curve.cpp b/source/blender/freestyle/intern/stroke/Curve.cpp index fe617646442..e1970c7196c 100644 --- a/source/blender/freestyle/intern/stroke/Curve.cpp +++ b/source/blender/freestyle/intern/stroke/Curve.cpp @@ -194,8 +194,9 @@ CurvePoint &CurvePoint::operator=(const CurvePoint &iBrother) FEdge *CurvePoint::fedge() { - if (getNature() & Nature::T_VERTEX) + if (getNature() & Nature::T_VERTEX) { return 0; + } return __A->fedge(); } @@ -212,42 +213,55 @@ FEdge *CurvePoint::getFEdge(Interface0D &inter) return __A->getFEdge(*__B); } if (__B == 0) { - if (iVertexB->__B == 0) + if (iVertexB->__B == 0) { return __A->getFEdge(*(iVertexB->__A)); - else if (iVertexB->__A == __A) + } + else if (iVertexB->__A == __A) { return __A->getFEdge(*(iVertexB->__B)); - else if (iVertexB->__B == __A) + } + else if (iVertexB->__B == __A) { return __A->getFEdge(*(iVertexB->__A)); + } } if (iVertexB->__B == 0) { - if (iVertexB->__A == __A) + if (iVertexB->__A == __A) { return __B->getFEdge(*(iVertexB->__A)); - else if (iVertexB->__A == __B) + } + else if (iVertexB->__A == __B) { return __A->getFEdge(*(iVertexB->__A)); + } } if (__B == iVertexB->__A) { - if ((_t2d != 1) && (iVertexB->_t2d == 0)) + if ((_t2d != 1) && (iVertexB->_t2d == 0)) { return __A->getFEdge(*__B); - if ((_t2d == 1) && (iVertexB->_t2d != 0)) + } + if ((_t2d == 1) && (iVertexB->_t2d != 0)) { return iVertexB->__A->getFEdge(*(iVertexB->__B)); + } } if (__B == iVertexB->__B) { - if ((_t2d != 1) && (iVertexB->_t2d == 1)) + if ((_t2d != 1) && (iVertexB->_t2d == 1)) { return __A->getFEdge(*__B); - if ((_t2d == 1) && (iVertexB->_t2d != 1)) + } + if ((_t2d == 1) && (iVertexB->_t2d != 1)) { return iVertexB->__A->getFEdge(*(iVertexB->__B)); + } } if (__A == iVertexB->__A) { - if ((_t2d == 0) && (iVertexB->_t2d != 0)) + if ((_t2d == 0) && (iVertexB->_t2d != 0)) { return iVertexB->__A->getFEdge(*(iVertexB->__B)); - if ((_t2d != 0) && (iVertexB->_t2d == 0)) + } + if ((_t2d != 0) && (iVertexB->_t2d == 0)) { return __A->getFEdge(*__B); + } } if (__A == iVertexB->__B) { - if ((_t2d == 0) && (iVertexB->_t2d != 1)) + if ((_t2d == 0) && (iVertexB->_t2d != 1)) { return iVertexB->__A->getFEdge(*(iVertexB->__B)); - if ((_t2d != 0) && (iVertexB->_t2d == 1)) + } + if ((_t2d != 0) && (iVertexB->_t2d == 1)) { return __A->getFEdge(*__B); + } } #if 0 if (G.debug & G_DEBUG_FREESTYLE) { @@ -275,16 +289,20 @@ FEdge *CurvePoint::getFEdge(Interface0D &inter) Vec3r CurvePoint::normal() const { - if (__B == 0) + if (__B == 0) { return __A->normal(); - if (__A == 0) + } + if (__A == 0) { return __B->normal(); + } Vec3r Na = __A->normal(); - if (Exception::getException()) + if (Exception::getException()) { Na = Vec3r(0, 0, 0); + } Vec3r Nb = __B->normal(); - if (Exception::getException()) + if (Exception::getException()) { Nb = Vec3r(0, 0, 0); + } // compute t3d: real t3d = SilhouetteGeomEngine::ImageToWorldParameter(__A->getFEdge(*__B), _t2d); return ((1 - t3d) * Na + t3d * Nb); @@ -308,8 +326,9 @@ Id CurvePoint::shape_id() const const SShape *CurvePoint::shape() const { - if (__A == 0) + if (__A == 0) { return __B->shape(); + } return __A->shape(); } @@ -333,75 +352,92 @@ const unsigned CurvePoint::qi() const occluder_container::const_iterator CurvePoint::occluders_begin() const { - if (__A == 0) + if (__A == 0) { return __B->occluders_begin(); - if (__B == 0) + } + if (__B == 0) { return __A->occluders_begin(); + } return __A->getFEdge(*__B)->occluders_begin(); } occluder_container::const_iterator CurvePoint::occluders_end() const { - if (__A == 0) + if (__A == 0) { return __B->occluders_end(); - if (__B == 0) + } + if (__B == 0) { return __A->occluders_end(); + } return __A->getFEdge(*__B)->occluders_end(); } bool CurvePoint::occluders_empty() const { - if (__A == 0) + if (__A == 0) { return __B->occluders_empty(); - if (__B == 0) + } + if (__B == 0) { return __A->occluders_empty(); + } return __A->getFEdge(*__B)->occluders_empty(); } int CurvePoint::occluders_size() const { - if (__A == 0) + if (__A == 0) { return __B->occluders_size(); - if (__B == 0) + } + if (__B == 0) { return __A->occluders_size(); + } return __A->getFEdge(*__B)->occluders_size(); } const SShape *CurvePoint::occluded_shape() const { - if (__A == 0) + if (__A == 0) { return __B->occluded_shape(); - if (__B == 0) + } + if (__B == 0) { return __A->occluded_shape(); + } return __A->getFEdge(*__B)->occluded_shape(); } const Polygon3r &CurvePoint::occludee() const { - if (__A == 0) + if (__A == 0) { return __B->occludee(); - if (__B == 0) + } + if (__B == 0) { return __A->occludee(); + } return __A->getFEdge(*__B)->occludee(); } const bool CurvePoint::occludee_empty() const { - if (__A == 0) + if (__A == 0) { return __B->occludee_empty(); - if (__B == 0) + } + if (__B == 0) { return __A->occludee_empty(); + } return __A->getFEdge(*__B)->occludee_empty(); } real CurvePoint::z_discontinuity() const { - if (__A == 0) + if (__A == 0) { return __B->z_discontinuity(); - if (__B == 0) + } + if (__B == 0) { return __A->z_discontinuity(); - if (__A->getFEdge(*__B) == 0) + } + if (__A->getFEdge(*__B) == 0) { return 0.0; + } return __A->getFEdge(*__B)->z_discontinuity(); } diff --git a/source/blender/freestyle/intern/stroke/Curve.h b/source/blender/freestyle/intern/stroke/Curve.h index b84ce45fb6d..3e079256161 100644 --- a/source/blender/freestyle/intern/stroke/Curve.h +++ b/source/blender/freestyle/intern/stroke/Curve.h @@ -123,10 +123,12 @@ class CurvePoint : public Interface0D { virtual Id getId() const { Id id; - if (_t2d == 0) + if (_t2d == 0) { return __A->getId(); - else if (_t2d == 1) + } + else if (_t2d == 1) { return __B->getId(); + } return id; } @@ -134,50 +136,60 @@ class CurvePoint : public Interface0D { virtual Nature::VertexNature getNature() const { Nature::VertexNature nature = Nature::POINT; - if (_t2d == 0) + if (_t2d == 0) { nature |= __A->getNature(); - else if (_t2d == 1) + } + else if (_t2d == 1) { nature |= __B->getNature(); + } return nature; } /*! Cast the Interface0D in SVertex if it can be. */ virtual SVertex *castToSVertex() { - if (_t2d == 0) + if (_t2d == 0) { return __A; - else if (_t2d == 1) + } + else if (_t2d == 1) { return __B; + } return Interface0D::castToSVertex(); } /*! Cast the Interface0D in ViewVertex if it can be. */ virtual ViewVertex *castToViewVertex() { - if (_t2d == 0) + if (_t2d == 0) { return __A->castToViewVertex(); - else if (_t2d == 1) + } + else if (_t2d == 1) { return __B->castToViewVertex(); + } return Interface0D::castToViewVertex(); } /*! Cast the Interface0D in NonTVertex if it can be. */ virtual NonTVertex *castToNonTVertex() { - if (_t2d == 0) + if (_t2d == 0) { return __A->castToNonTVertex(); - else if (_t2d == 1) + } + else if (_t2d == 1) { return __B->castToNonTVertex(); + } return Interface0D::castToNonTVertex(); } /*! Cast the Interface0D in TVertex if it can be. */ virtual TVertex *castToTVertex() { - if (_t2d == 0) + if (_t2d == 0) { return __A->castToTVertex(); - else if (_t2d == 1) + } + else if (_t2d == 1) { return __B->castToTVertex(); + } return Interface0D::castToTVertex(); } diff --git a/source/blender/freestyle/intern/stroke/CurveAdvancedIterators.h b/source/blender/freestyle/intern/stroke/CurveAdvancedIterators.h index 5cbdd26be57..9999950e240 100644 --- a/source/blender/freestyle/intern/stroke/CurveAdvancedIterators.h +++ b/source/blender/freestyle/intern/stroke/CurveAdvancedIterators.h @@ -119,10 +119,12 @@ class __point_iterator : public IteratorBase<Traits, BidirectionalIteratorTag_Tr _CurvilinearLength = iBrother._CurvilinearLength; _step = iBrother._step; _t = iBrother._t; - if (iBrother._Point == 0) + if (iBrother._Point == 0) { _Point = 0; - else + } + else { _Point = new Point(*(iBrother._Point)); + } _n = iBrother._n; _currentn = iBrother._currentn; } @@ -136,10 +138,12 @@ class __point_iterator : public IteratorBase<Traits, BidirectionalIteratorTag_Tr _CurvilinearLength = iBrother._CurvilinearLength; _step = iBrother._step; _t = iBrother._t; - if (iBrother._Point == 0) + if (iBrother._Point == 0) { _Point = 0; - else + } + else { _Point = new Point(*(iBrother._Point)); + } _n = iBrother._n; _currentn = iBrother._currentn; } @@ -154,10 +158,12 @@ class __point_iterator : public IteratorBase<Traits, BidirectionalIteratorTag_Tr _CurvilinearLength = iBrother._CurvilinearLength; _step = iBrother._step; _t = iBrother._t; - if (iBrother._Point == 0) + if (iBrother._Point == 0) { _Point = 0; - else + } + else { _Point = new Point(*(iBrother._Point)); + } _n = iBrother._n; _currentn = iBrother._currentn; return *this; @@ -165,8 +171,9 @@ class __point_iterator : public IteratorBase<Traits, BidirectionalIteratorTag_Tr virtual ~__point_iterator() { - if (_Point != 0) + if (_Point != 0) { delete _Point; + } } // protected: //FIXME @@ -243,8 +250,9 @@ class __point_iterator : public IteratorBase<Traits, BidirectionalIteratorTag_Tr delete _Point; _Point = 0; } - if ((_currentn < 0) || (_currentn >= _n)) + if ((_currentn < 0) || (_currentn >= _n)) { return _Point; // 0 in this case + } return (_Point = new Point(*__A, *__B, _t)); } @@ -255,15 +263,17 @@ class __point_iterator : public IteratorBase<Traits, BidirectionalIteratorTag_Tr virtual bool begin() const { - if ((__A == _begin) && (_t < (float)M_EPSILON)) + if ((__A == _begin) && (_t < (float)M_EPSILON)) { return true; + } return false; } virtual bool end() const { - if ((__B == _end)) + if ((__B == _end)) { return true; + } return false; } @@ -334,8 +344,9 @@ class __point_iterator : public IteratorBase<Traits, BidirectionalIteratorTag_Tr --_currentn; --__A; --__B; - if (_currentn == _n - 1) + if (_currentn == _n - 1) { return; + } } if (0 == _step) { // means we iterate over initial vertices @@ -358,13 +369,16 @@ class __point_iterator : public IteratorBase<Traits, BidirectionalIteratorTag_Tr } // round value - if (fabs(_t) < (float)M_EPSILON) + if (fabs(_t) < (float)M_EPSILON) { _t = 0.0f; + } if (_t < 0) { - if (_currentn == 0) + if (_currentn == 0) { _CurvilinearLength = 0.0f; - else + } + else { _CurvilinearLength += normAB * (-_t); + } _t = 0.0f; } } diff --git a/source/blender/freestyle/intern/stroke/CurveIterators.h b/source/blender/freestyle/intern/stroke/CurveIterators.h index b05c9838a3b..0ebbd0509ca 100644 --- a/source/blender/freestyle/intern/stroke/CurveIterators.h +++ b/source/blender/freestyle/intern/stroke/CurveIterators.h @@ -157,8 +157,9 @@ class CurvePointIterator : public Interface0DIteratorNested { virtual bool operator==(const Interface0DIteratorNested &b) const { const CurvePointIterator *it_exact = dynamic_cast<const CurvePointIterator *>(&b); - if (!it_exact) + if (!it_exact) { return false; + } return ((__A == it_exact->__A) && (__B == it_exact->__B) && (_t == it_exact->_t)); } @@ -175,15 +176,17 @@ class CurvePointIterator : public Interface0DIteratorNested { virtual bool isBegin() const { - if ((__A == _begin) && (_t < (float)M_EPSILON)) + if ((__A == _begin) && (_t < (float)M_EPSILON)) { return true; + } return false; } virtual bool isEnd() const { - if (__B == _end) + if (__B == _end) { return true; + } return false; } @@ -246,8 +249,9 @@ class CurvePointIterator : public Interface0DIteratorNested { --_currentn; --__A; --__B; - if (_currentn == _n - 1) + if (_currentn == _n - 1) { return 0; + } } if (0 == _step) { // means we iterate over initial vertices @@ -270,13 +274,16 @@ class CurvePointIterator : public Interface0DIteratorNested { } // round value - if (fabs(_t) < (float)M_EPSILON) + if (fabs(_t) < (float)M_EPSILON) { _t = 0.0f; + } if (_t < 0) { - if (_currentn == 0) + if (_currentn == 0) { _CurvilinearLength = 0.0f; - else + } + else { _CurvilinearLength += normAB * (-_t); + } _t = 0.0f; } return 0; diff --git a/source/blender/freestyle/intern/stroke/Operators.cpp b/source/blender/freestyle/intern/stroke/Operators.cpp index 0374e605ff2..329b5440fed 100644 --- a/source/blender/freestyle/intern/stroke/Operators.cpp +++ b/source/blender/freestyle/intern/stroke/Operators.cpp @@ -39,10 +39,12 @@ Operators::StrokesContainer Operators::_current_strokes_set; int Operators::select(UnaryPredicate1D &pred) { - if (!_current_set) + if (!_current_set) { return 0; - if (_current_set->empty()) + } + if (_current_set->empty()) { return 0; + } I1DContainer new_set; I1DContainer rejected; Functions1D::ChainingTimeStampF1D cts; @@ -67,8 +69,9 @@ int Operators::select(UnaryPredicate1D &pred) ++it; } if ((*itbegin)->getExactTypeName() != "ViewEdge") { - for (it = rejected.begin(); it != rejected.end(); ++it) + for (it = rejected.begin(); it != rejected.end(); ++it) { delete *it; + } } rejected.clear(); _current_set->clear(); @@ -80,8 +83,9 @@ int Operators::chain(ViewEdgeInternal::ViewEdgeIterator &it, UnaryPredicate1D &pred, UnaryFunction1D_void &modifier) { - if (_current_view_edges_set.empty()) + if (_current_view_edges_set.empty()) { return 0; + } unsigned id = 0; ViewEdge *edge; @@ -90,10 +94,12 @@ int Operators::chain(ViewEdgeInternal::ViewEdgeIterator &it, for (I1DContainer::iterator it_edge = _current_view_edges_set.begin(); it_edge != _current_view_edges_set.end(); ++it_edge) { - if (pred(**it_edge) < 0) + if (pred(**it_edge) < 0) { goto error; - if (pred.result) + } + if (pred.result) { continue; + } edge = dynamic_cast<ViewEdge *>(*it_edge); it.setBegin(edge); @@ -108,14 +114,16 @@ int Operators::chain(ViewEdgeInternal::ViewEdgeIterator &it, goto error; } ++it; - if (it.isEnd()) + if (it.isEnd()) { break; + } if (pred(**it) < 0) { delete new_chain; goto error; } - if (pred.result) + if (pred.result) { break; + } } new_chains_set.push_back(new_chain); } @@ -139,8 +147,9 @@ error: int Operators::chain(ViewEdgeInternal::ViewEdgeIterator &it, UnaryPredicate1D &pred) { - if (_current_view_edges_set.empty()) + if (_current_view_edges_set.empty()) { return 0; + } unsigned id = 0; Functions1D::IncrementChainingTimeStampF1D ts; @@ -151,14 +160,18 @@ int Operators::chain(ViewEdgeInternal::ViewEdgeIterator &it, UnaryPredicate1D &p for (I1DContainer::iterator it_edge = _current_view_edges_set.begin(); it_edge != _current_view_edges_set.end(); ++it_edge) { - if (pred(**it_edge) < 0) + if (pred(**it_edge) < 0) { goto error; - if (pred.result) + } + if (pred.result) { continue; - if (pred_ts(**it_edge) < 0) + } + if (pred_ts(**it_edge) < 0) { goto error; - if (pred_ts.result) + } + if (pred_ts.result) { continue; + } edge = dynamic_cast<ViewEdge *>(*it_edge); it.setBegin(edge); @@ -170,20 +183,23 @@ int Operators::chain(ViewEdgeInternal::ViewEdgeIterator &it, UnaryPredicate1D &p new_chain->push_viewedge_back(*it, it.getOrientation()); ts(**it); ++it; - if (it.isEnd()) + if (it.isEnd()) { break; + } if (pred(**it) < 0) { delete new_chain; goto error; } - if (pred.result) + if (pred.result) { break; + } if (pred_ts(**it) < 0) { delete new_chain; goto error; } - if (pred_ts.result) + if (pred_ts.result) { break; + } } new_chains_set.push_back(new_chain); } @@ -306,8 +322,9 @@ void Operators::bidirectionalChain(ViewEdgeIterator &it, UnaryPredicate1D &pred) int Operators::bidirectionalChain(ChainingIterator &it, UnaryPredicate1D &pred) { - if (_current_view_edges_set.empty()) + if (_current_view_edges_set.empty()) { return 0; + } unsigned id = 0; Functions1D::IncrementChainingTimeStampF1D ts; @@ -318,22 +335,27 @@ int Operators::bidirectionalChain(ChainingIterator &it, UnaryPredicate1D &pred) for (I1DContainer::iterator it_edge = _current_view_edges_set.begin(); it_edge != _current_view_edges_set.end(); ++it_edge) { - if (pred(**it_edge) < 0) + if (pred(**it_edge) < 0) { goto error; - if (pred.result) + } + if (pred.result) { continue; - if (pred_ts(**it_edge) < 0) + } + if (pred_ts(**it_edge) < 0) { goto error; - if (pred_ts.result) + } + if (pred_ts.result) { continue; + } edge = dynamic_cast<ViewEdge *>(*it_edge); // re-init iterator it.setBegin(edge); it.setCurrentEdge(edge); it.setOrientation(true); - if (it.init() < 0) + if (it.init() < 0) { goto error; + } Chain *new_chain = new Chain(id); ++id; @@ -348,14 +370,16 @@ int Operators::bidirectionalChain(ChainingIterator &it, UnaryPredicate1D &pred) delete new_chain; goto error; } - if (it.isEnd()) + if (it.isEnd()) { break; + } if (pred(**it) < 0) { delete new_chain; goto error; } - if (pred.result) + if (pred.result) { break; + } } it.setBegin(edge); it.setCurrentEdge(edge); @@ -369,8 +393,9 @@ int Operators::bidirectionalChain(ChainingIterator &it, UnaryPredicate1D &pred) delete new_chain; goto error; } - if (pred.result) + if (pred.result) { break; + } new_chain->push_viewedge_front(*it, it.getOrientation()); ts(**it); if (it.decrement() < 0) { @@ -400,8 +425,9 @@ error: int Operators::bidirectionalChain(ChainingIterator &it) { - if (_current_view_edges_set.empty()) + if (_current_view_edges_set.empty()) { return 0; + } unsigned id = 0; Functions1D::IncrementChainingTimeStampF1D ts; @@ -412,18 +438,21 @@ int Operators::bidirectionalChain(ChainingIterator &it) for (I1DContainer::iterator it_edge = _current_view_edges_set.begin(); it_edge != _current_view_edges_set.end(); ++it_edge) { - if (pred_ts(**it_edge) < 0) + if (pred_ts(**it_edge) < 0) { goto error; - if (pred_ts.result) + } + if (pred_ts.result) { continue; + } edge = dynamic_cast<ViewEdge *>(*it_edge); // re-init iterator it.setBegin(edge); it.setCurrentEdge(edge); it.setOrientation(true); - if (it.init() < 0) + if (it.init() < 0) { goto error; + } Chain *new_chain = new Chain(id); ++id; @@ -541,8 +570,9 @@ int Operators::sequentialSplit(UnaryPredicate0D &pred, float sampling) #endif splitted_chains.clear(); - if (!_current_chains_set.empty()) + if (!_current_chains_set.empty()) { _current_set = &_current_chains_set; + } return 0; error: @@ -592,8 +622,9 @@ int Operators::sequentialSplit(UnaryPredicate0D &startingPred, point = dynamic_cast<CurvePoint *>(&(*itStop)); new_curve->push_vertex_back(point); ++itStop; - if (itStop == end) + if (itStop == end) { break; + } if (stoppingPred(itStop) < 0) { delete new_curve; goto error; @@ -612,10 +643,12 @@ int Operators::sequentialSplit(UnaryPredicate0D &startingPred, // find next start do { ++itStart; - if (itStart == end) + if (itStart == end) { break; - if (startingPred(itStart) < 0) + } + if (startingPred(itStart) < 0) { goto error; + } } while (!startingPred.result); } while ((itStart != end) && (itStart != last)); } @@ -639,8 +672,9 @@ int Operators::sequentialSplit(UnaryPredicate0D &startingPred, #endif splitted_chains.clear(); - if (!_current_chains_set.empty()) + if (!_current_chains_set.empty()) { _current_set = &_current_chains_set; + } return 0; error: @@ -681,8 +715,9 @@ static int __recursiveSplit(Chain *_curve, bool bsplit = false; for (; ((it != end) && (next != end)); ++it, ++next) { it0d = it.castToInterface0DIterator(); - if (func(it0d) < 0) + if (func(it0d) < 0) { return -1; + } if (func.result < _min) { _min = func.result; split = it; @@ -734,8 +769,9 @@ static int __recursiveSplit(Chain *_curve, new_curve_a->push_vertex_back(&(*split)); new_curve_b->push_vertex_back(&(*split)); - for (vit = vnext; vit != vitend; ++vit) + for (vit = vnext; vit != vitend; ++vit) { new_curve_b->push_vertex_back(&(*vit)); + } // let's check whether one or two of the two new curves satisfy the stopping condition or not. // (if one of them satisfies it, we don't split) @@ -774,11 +810,13 @@ int Operators::recursiveSplit(UnaryFunction0D<double> &func, I1DContainer::iterator cit = _current_chains_set.begin(), citend = _current_chains_set.end(); for (; cit != citend; ++cit) { currentChain = dynamic_cast<Chain *>(*cit); - if (!currentChain) + if (!currentChain) { continue; + } // let's check the first one: - if (pred(*currentChain) < 0) + if (pred(*currentChain) < 0) { return -1; + } if (!pred.result) { __recursiveSplit(currentChain, func, pred, sampling, newChains, splitted_chains); } @@ -808,8 +846,9 @@ int Operators::recursiveSplit(UnaryFunction0D<double> &func, #endif newChains.clear(); - if (!_current_chains_set.empty()) + if (!_current_chains_set.empty()) { _current_set = &_current_chains_set; + } return 0; } @@ -850,12 +889,15 @@ static int __recursiveSplit(Chain *_curve, for (; ((it != end) && (next != end)); ++it, ++next) { ++count; it0d = it.castToInterface0DIterator(); - if (pred0d(it0d) < 0) + if (pred0d(it0d) < 0) { return -1; - if (!pred0d.result) + } + if (!pred0d.result) { continue; - if (func(it0d) < 0) + } + if (func(it0d) < 0) { return -1; + } mean += func.result; if (func.result < _min) { _min = func.result; @@ -910,8 +952,9 @@ static int __recursiveSplit(Chain *_curve, new_curve_a->push_vertex_back(&(*split)); new_curve_b->push_vertex_back(&(*split)); - for (vit = vnext; vit != vitend; ++vit) + for (vit = vnext; vit != vitend; ++vit) { new_curve_b->push_vertex_back(&(*vit)); + } // let's check whether one or two of the two new curves satisfy the stopping condition or not. // (if one of them satisfies it, we don't split) @@ -951,11 +994,13 @@ int Operators::recursiveSplit(UnaryFunction0D<double> &func, I1DContainer::iterator cit = _current_chains_set.begin(), citend = _current_chains_set.end(); for (; cit != citend; ++cit) { currentChain = dynamic_cast<Chain *>(*cit); - if (!currentChain) + if (!currentChain) { continue; + } // let's check the first one: - if (pred(*currentChain) < 0) + if (pred(*currentChain) < 0) { return -1; + } if (!pred.result) { __recursiveSplit(currentChain, func, pred0d, pred, sampling, newChains, splitted_chains); } @@ -985,8 +1030,9 @@ int Operators::recursiveSplit(UnaryFunction0D<double> &func, #endif newChains.clear(); - if (!_current_chains_set.empty()) + if (!_current_chains_set.empty()) { _current_set = &_current_chains_set; + } return 0; } @@ -1000,10 +1046,12 @@ class PredicateWrapper { inline bool operator()(Interface1D *i1, Interface1D *i2) { - if (i1 == i2) + if (i1 == i2) { return false; - if ((*_pred)(*i1, *i2) < 0) + } + if ((*_pred)(*i1, *i2) < 0) { throw std::runtime_error("comparison failed"); + } return _pred->result; } @@ -1013,8 +1061,9 @@ class PredicateWrapper { int Operators::sort(BinaryPredicate1D &pred) { - if (!_current_set) + if (!_current_set) { return 0; + } PredicateWrapper wrapper(pred); try { std::sort(_current_set->begin(), _current_set->end(), wrapper); @@ -1059,8 +1108,9 @@ static Stroke *createStroke(Interface1D &inter) current = stroke_vertex->getPoint2D(); Vec2r vec_tmp(current - previous); real dist = vec_tmp.norm(); - if (dist < 1.0e-6) + if (dist < 1.0e-6) { hasSingularity = true; + } currentCurvilignAbscissa += dist; stroke_vertex->setCurvilinearAbscissa(currentCurvilignAbscissa); stroke->push_back(stroke_vertex); @@ -1073,10 +1123,12 @@ static Stroke *createStroke(Interface1D &inter) cp = dynamic_cast<CurvePoint *>(&(*it)); if (!cp) { sv = dynamic_cast<SVertex *>(&(*it)); - if (!sv) + if (!sv) { cerr << "Warning: unexpected Vertex type" << endl; - else + } + else { stroke_vertex = new StrokeVertex(sv); + } } else { stroke_vertex = new StrokeVertex(cp); @@ -1084,8 +1136,9 @@ static Stroke *createStroke(Interface1D &inter) current = stroke_vertex->getPoint2D(); Vec2r vec_tmp(current - previous); real dist = vec_tmp.norm(); - if (dist < 1.0e-6) + if (dist < 1.0e-6) { hasSingularity = true; + } currentCurvilignAbscissa += dist; stroke_vertex->setCurvilinearAbscissa(currentCurvilignAbscissa); stroke->push_back(stroke_vertex); @@ -1108,8 +1161,9 @@ static Stroke *createStroke(Interface1D &inter) next = (*vnext).getPoint(); if ((next - current).norm() < 1.0e-6) { StrokeInternal::StrokeVertexIterator vprevious = v; - if (!vprevious.isBegin()) + if (!vprevious.isBegin()) { --vprevious; + } // collect a set of overlapping vertices std::vector<StrokeVertex *> overlapping_vertices; @@ -1119,8 +1173,9 @@ static Stroke *createStroke(Interface1D &inter) current = next; ++v; ++vnext; - if (vnext.isEnd()) + if (vnext.isEnd()) { break; + } next = (*vnext).getPoint(); } while ((next - current).norm() < 1.0e-6); @@ -1167,8 +1222,9 @@ static Stroke *createStroke(Interface1D &inter) } } - if (vnext.isEnd()) + if (vnext.isEnd()) { break; + } } ++v; ++vnext; @@ -1218,10 +1274,12 @@ int Operators::create(UnaryPredicate1D &pred, vector<StrokeShader *> shaders) StrokesContainer new_strokes_set; for (Operators::I1DContainer::iterator it = _current_set->begin(); it != _current_set->end(); ++it) { - if (pred(**it) < 0) + if (pred(**it) < 0) { goto error; - if (!pred.result) + } + if (!pred.result) { continue; + } Stroke *stroke = createStroke(**it); if (stroke) { @@ -1259,20 +1317,23 @@ void Operators::reset(bool removeStrokes) } _current_view_edges_set.clear(); for (I1DContainer::iterator it = _current_chains_set.begin(); it != _current_chains_set.end(); - ++it) + ++it) { delete *it; + } _current_chains_set.clear(); ViewMap::viewedges_container &vedges = vm->ViewEdges(); ViewMap::viewedges_container::iterator ve = vedges.begin(), veend = vedges.end(); for (; ve != veend; ++ve) { - if ((*ve)->getLength2D() < M_EPSILON) + if ((*ve)->getLength2D() < M_EPSILON) { continue; + } _current_view_edges_set.push_back(*ve); } _current_set = &_current_view_edges_set; - if (removeStrokes) + if (removeStrokes) { _current_strokes_set.clear(); + } } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/stroke/PSStrokeRenderer.cpp b/source/blender/freestyle/intern/stroke/PSStrokeRenderer.cpp index e7428c795fc..670388f5d52 100644 --- a/source/blender/freestyle/intern/stroke/PSStrokeRenderer.cpp +++ b/source/blender/freestyle/intern/stroke/PSStrokeRenderer.cpp @@ -26,8 +26,9 @@ namespace Freestyle { PSStrokeRenderer::PSStrokeRenderer(const char *iFileName) : StrokeRenderer() { - if (!iFileName) + if (!iFileName) { iFileName = "freestyle.ps"; + } // open the stream: _ofstream.open(iFileName, ios::out); if (!_ofstream.is_open()) { @@ -91,8 +92,9 @@ void PSStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const void PSStrokeRenderer::Close() { - if (_ofstream.is_open()) + if (_ofstream.is_open()) { _ofstream.close(); + } } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/stroke/Predicates1D.h b/source/blender/freestyle/intern/stroke/Predicates1D.h index 3560f29ee36..fe3649111f5 100644 --- a/source/blender/freestyle/intern/stroke/Predicates1D.h +++ b/source/blender/freestyle/intern/stroke/Predicates1D.h @@ -206,8 +206,9 @@ class QuantitativeInvisibilityUP1D : public UnaryPredicate1D { int operator()(Interface1D &inter) { Functions1D::QuantitativeInvisibilityF1D func; - if (func(inter) < 0) + if (func(inter) < 0) { return -1; + } result = (func.result == _qi); return 0; } @@ -234,8 +235,9 @@ class ContourUP1D : public UnaryPredicate1D { /*! The () operator. */ int operator()(Interface1D &inter) { - if (_getNature(inter) < 0) + if (_getNature(inter) < 0) { return -1; + } if ((_getNature.result & Nature::SILHOUETTE) || (_getNature.result & Nature::BORDER)) { Interface0DIterator it = inter.verticesBegin(); for (; !it.isEnd(); ++it) { @@ -268,8 +270,9 @@ class ExternalContourUP1D : public UnaryPredicate1D { /*! The () operator. */ int operator()(Interface1D &inter) { - if (_getNature(inter) < 0) + if (_getNature(inter) < 0) { return -1; + } if ((_getNature.result & Nature::SILHOUETTE) || (_getNature.result & Nature::BORDER)) { set<ViewShape *> occluded; Functions1D::getOccludeeF1D(inter, occluded); @@ -561,11 +564,13 @@ class ViewMapGradientNormBP1D : public BinaryPredicate1D { /*! The () operator. */ int operator()(Interface1D &i1, Interface1D &i2) { - if (_func(i1) < 0) + if (_func(i1) < 0) { return -1; + } real n1 = _func.result; - if (_func(i2) < 0) + if (_func(i2) < 0) { return -1; + } real n2 = _func.result; result = (n1 > n2); return 0; diff --git a/source/blender/freestyle/intern/stroke/Stroke.cpp b/source/blender/freestyle/intern/stroke/Stroke.cpp index ff0cd64fdaa..13f8080552b 100644 --- a/source/blender/freestyle/intern/stroke/Stroke.cpp +++ b/source/blender/freestyle/intern/stroke/Stroke.cpp @@ -43,8 +43,9 @@ StrokeAttribute::StrokeAttribute() _alpha = 1.0f; _thickness[0] = 1.0f; _thickness[1] = 1.0f; - for (i = 0; i < 3; ++i) + for (i = 0; i < 3; ++i) { _color[i] = 0.2f; + } _color[0] = 0.8f; _userAttributesReal = NULL; _userAttributesVec2f = NULL; @@ -57,21 +58,28 @@ StrokeAttribute::StrokeAttribute(const StrokeAttribute &iBrother) _alpha = iBrother._alpha; _thickness[0] = iBrother._thickness[0]; _thickness[1] = iBrother._thickness[1]; - for (int i = 0; i < 3; ++i) + for (int i = 0; i < 3; ++i) { _color[i] = iBrother._color[i]; + } _visible = iBrother._visible; - if (iBrother._userAttributesReal) + if (iBrother._userAttributesReal) { _userAttributesReal = new realMap(*iBrother._userAttributesReal); - else + } + else { _userAttributesReal = NULL; - if (iBrother._userAttributesVec2f) + } + if (iBrother._userAttributesVec2f) { _userAttributesVec2f = new Vec2fMap(*iBrother._userAttributesVec2f); - else + } + else { _userAttributesVec2f = NULL; - if (iBrother._userAttributesVec3f) + } + if (iBrother._userAttributesVec3f) { _userAttributesVec3f = new Vec3fMap(*iBrother._userAttributesVec3f); - else + } + else { _userAttributesVec3f = NULL; + } } StrokeAttribute::StrokeAttribute(float iRColor, @@ -102,8 +110,9 @@ StrokeAttribute::StrokeAttribute(const StrokeAttribute &a1, const StrokeAttribut _alpha = (1 - t) * a1._alpha + t * a2._alpha; _thickness[0] = (1 - t) * a1._thickness[0] + t * a2._thickness[0]; _thickness[1] = (1 - t) * a1._thickness[1] + t * a2._thickness[1]; - for (int i = 0; i < 3; ++i) + for (int i = 0; i < 3; ++i) { _color[i] = (1 - t) * a1._color[i] + t * a2._color[i]; + } _visible = a1.isVisible(); @@ -174,28 +183,32 @@ StrokeAttribute &StrokeAttribute::operator=(const StrokeAttribute &iBrother) _alpha = iBrother._alpha; _thickness[0] = iBrother._thickness[0]; _thickness[1] = iBrother._thickness[1]; - for (i = 0; i < 3; ++i) + for (i = 0; i < 3; ++i) { _color[i] = iBrother._color[i]; + } _visible = iBrother._visible; if (iBrother._userAttributesReal) { - if (!_userAttributesReal) + if (!_userAttributesReal) { _userAttributesReal = new realMap; + } _userAttributesReal = new realMap(*(iBrother._userAttributesReal)); } else { _userAttributesReal = NULL; } if (iBrother._userAttributesVec2f) { - if (!_userAttributesVec2f) + if (!_userAttributesVec2f) { _userAttributesVec2f = new Vec2fMap; + } _userAttributesVec2f = new Vec2fMap(*(iBrother._userAttributesVec2f)); } else { _userAttributesVec2f = NULL; } if (iBrother._userAttributesVec3f) { - if (!_userAttributesVec3f) + if (!_userAttributesVec3f) { _userAttributesVec3f = new Vec3fMap; + } _userAttributesVec3f = new Vec3fMap(*(iBrother._userAttributesVec3f)); } else { @@ -299,22 +312,25 @@ bool StrokeAttribute::isAttributeAvailableVec3f(const char *iName) const void StrokeAttribute::setAttributeReal(const char *iName, float att) { - if (!_userAttributesReal) + if (!_userAttributesReal) { _userAttributesReal = new realMap; + } (*_userAttributesReal)[iName] = att; } void StrokeAttribute::setAttributeVec2f(const char *iName, const Vec2f &att) { - if (!_userAttributesVec2f) + if (!_userAttributesVec2f) { _userAttributesVec2f = new Vec2fMap; + } (*_userAttributesVec2f)[iName] = att; } void StrokeAttribute::setAttributeVec3f(const char *iName, const Vec3f &att) { - if (!_userAttributesVec3f) + if (!_userAttributesVec3f) { _userAttributesVec3f = new Vec3fMap; + } (*_userAttributesVec3f)[iName] = att; } @@ -427,10 +443,12 @@ Stroke::Stroke(const Stroke &iBrother) } _nodeTree = iBrother._nodeTree; _tips = iBrother._tips; - if (iBrother._rep) + if (iBrother._rep) { _rep = new StrokeRep(*(iBrother._rep)); - else + } + else { _rep = NULL; + } } Stroke::~Stroke() @@ -452,8 +470,9 @@ Stroke::~Stroke() Stroke &Stroke::operator=(const Stroke &iBrother) { - if (!_Vertices.empty()) + if (!_Vertices.empty()) { _Vertices.clear(); + } for (vertex_container::const_iterator v = iBrother._Vertices.begin(), vend = iBrother._Vertices.end(); @@ -465,12 +484,15 @@ Stroke &Stroke::operator=(const Stroke &iBrother) _id = iBrother._id; _ViewEdges = iBrother._ViewEdges; _sampling = iBrother._sampling; - if (_rep) + if (_rep) { delete _rep; - if (iBrother._rep) + } + if (iBrother._rep) { _rep = new StrokeRep(*(iBrother._rep)); - else + } + else { _rep = NULL; + } return *this; } @@ -484,8 +506,9 @@ void Stroke::setLength(float iLength) float Stroke::ComputeSampling(int iNVertices) { - if (iNVertices <= (int)_Vertices.size()) // soc + if (iNVertices <= (int)_Vertices.size()) { // soc return _sampling; + } float sampling = _Length / (float)(iNVertices - _Vertices.size() + 1); return sampling; @@ -518,8 +541,9 @@ class StrokeSegment { int Stroke::Resample(int iNPoints) { int NPointsToAdd = iNPoints - strokeVerticesSize(); - if (NPointsToAdd <= 0) + if (NPointsToAdd <= 0) { return 0; + } StrokeInternal::StrokeVertexIterator it = strokeVerticesBegin(); StrokeInternal::StrokeVertexIterator next = it; @@ -557,23 +581,27 @@ int Stroke::Resample(int iNPoints) for (vector<StrokeSegment>::iterator s = strokeSegments.begin(), send = strokeSegments.end(); s != send; ++s) { - if (s->_sampling == 0.0f) + if (s->_sampling == 0.0f) { continue; + } if (s->_resampled == false) { - if ((!checkEveryone) && (s->_length < meanlength)) + if ((!checkEveryone) && (s->_length < meanlength)) { continue; + } // resample s->_n = s->_n + 1; s->_sampling = s->_length / (float)(s->_n + 1); s->_resampled = resampled = true; N++; - if (N == NPointsToAdd) + if (N == NPointsToAdd) { break; + } } } - if (checkEveryone && !resampled) + if (checkEveryone && !resampled) { break; + } checkEveryone = true; } if (N < NPointsToAdd) { @@ -586,8 +614,9 @@ int Stroke::Resample(int iNPoints) s != send; ++s) { newVertices.push_back(&(*(s->_begin))); - if (s->_sampling < _sampling) + if (s->_sampling < _sampling) { _sampling = s->_sampling; + } t = s->_sampling / s->_length; for (int i = 0; i < s->_n; ++i) { @@ -602,12 +631,14 @@ int Stroke::Resample(int iNPoints) // add last: ++it; ++next; - if ((it != itend) && (next == itend) /* && (t == 0.0f)*/) + if ((it != itend) && (next == itend) /* && (t == 0.0f)*/) { newVertices.push_back(&(*it)); + } int newsize = newVertices.size(); - if (newsize != iNPoints) + if (newsize != iNPoints) { cerr << "Warning: incorrect points number" << endl; + } _Vertices.clear(); _Vertices = newVertices; @@ -619,10 +650,12 @@ int Stroke::Resample(int iNPoints) int Stroke::Resample(float iSampling) { // cerr << "old size :" << strokeVerticesSize() << endl; - if (iSampling == 0) + if (iSampling == 0) { return 0; - if (iSampling >= _sampling) + } + if (iSampling >= _sampling) { return 0; + } _sampling = iSampling; // Resample... @@ -660,8 +693,9 @@ int Stroke::Resample(float iSampling) ++next; } // add last: - if ((it != itend) && (next == itend) /* && (t == 0.f)*/) + if ((it != itend) && (next == itend) /* && (t == 0.f)*/) { newVertices.push_back(&(*it)); + } _Vertices.clear(); _Vertices = newVertices; @@ -673,8 +707,9 @@ int Stroke::Resample(float iSampling) void Stroke::RemoveAllVertices() { vertex_container::iterator it = _Vertices.begin(), itend = _Vertices.end(); - for (; it != itend; ++it) + for (; it != itend; ++it) { delete (*it); + } _Vertices.clear(); UpdateLength(); } @@ -734,8 +769,9 @@ Stroke::vertex_iterator Stroke::vertices_end() StrokeInternal::StrokeVertexIterator Stroke::strokeVerticesBegin(float t) { - if ((t != 0) && (t < _sampling)) + if ((t != 0) && (t < _sampling)) { Resample(t); + } return StrokeInternal::StrokeVertexIterator( this->_Vertices.begin(), this->_Vertices.begin(), this->_Vertices.end()); } @@ -781,23 +817,26 @@ void Stroke::ScaleThickness(float iFactor) void Stroke::Render(const StrokeRenderer *iRenderer) { - if (!_rep) + if (!_rep) { _rep = new StrokeRep(this); + } iRenderer->RenderStrokeRep(_rep); } void Stroke::RenderBasic(const StrokeRenderer *iRenderer) { - if (!_rep) + if (!_rep) { _rep = new StrokeRep(this); + } iRenderer->RenderStrokeRep(_rep); } Stroke::vertex_iterator Stroke::vertices_begin(float sampling) { // Resample if necessary - if ((sampling != 0) && (sampling < _sampling)) + if ((sampling != 0) && (sampling < _sampling)) { Resample(sampling); + } return vertex_iterator(_Vertices.begin(), _Vertices.begin(), _Vertices.end()); // return _Vertices.begin(); } diff --git a/source/blender/freestyle/intern/stroke/StrokeIterators.h b/source/blender/freestyle/intern/stroke/StrokeIterators.h index 624f2a03877..71932d8487a 100644 --- a/source/blender/freestyle/intern/stroke/StrokeIterators.h +++ b/source/blender/freestyle/intern/stroke/StrokeIterators.h @@ -170,8 +170,9 @@ class StrokeVertexIterator : public Interface0DIteratorNested { /*! Returns true if the pointed StrokeVertex is the final valid StrokeVertex of the Stroke. */ bool atLast() { - if (_it == _end) + if (_it == _end) { return false; + } ++_it; bool result = (_it == _end); @@ -189,8 +190,9 @@ class StrokeVertexIterator : public Interface0DIteratorNested { virtual bool operator==(const Interface0DIteratorNested &it) const { const StrokeVertexIterator *it_exact = dynamic_cast<const StrokeVertexIterator *>(&it); - if (!it_exact) + if (!it_exact) { return false; + } return (_it == it_exact->_it); } diff --git a/source/blender/freestyle/intern/stroke/StrokeLayer.cpp b/source/blender/freestyle/intern/stroke/StrokeLayer.cpp index f1680279889..c89e7143c89 100644 --- a/source/blender/freestyle/intern/stroke/StrokeLayer.cpp +++ b/source/blender/freestyle/intern/stroke/StrokeLayer.cpp @@ -59,8 +59,9 @@ void StrokeLayer::RenderBasic(const StrokeRenderer *iRenderer) void StrokeLayer::clear() { - for (stroke_container::iterator s = _strokes.begin(), send = _strokes.end(); s != send; ++s) + for (stroke_container::iterator s = _strokes.begin(), send = _strokes.end(); s != send; ++s) { delete *s; + } _strokes.clear(); } diff --git a/source/blender/freestyle/intern/stroke/StrokeRenderer.cpp b/source/blender/freestyle/intern/stroke/StrokeRenderer.cpp index 530a7644bfa..a76579c7c96 100644 --- a/source/blender/freestyle/intern/stroke/StrokeRenderer.cpp +++ b/source/blender/freestyle/intern/stroke/StrokeRenderer.cpp @@ -74,15 +74,17 @@ TextureManager::TextureManager() TextureManager::~TextureManager() { - if (!_brushesMap.empty()) + if (!_brushesMap.empty()) { _brushesMap.clear(); + } _pInstance = 0; } void TextureManager::load() { - if (_hasLoadedTextures) + if (_hasLoadedTextures) { return; + } loadStandardBrushes(); _hasLoadedTextures = true; } diff --git a/source/blender/freestyle/intern/stroke/StrokeRenderer.h b/source/blender/freestyle/intern/stroke/StrokeRenderer.h index 79767b48d83..e0eb0351a80 100644 --- a/source/blender/freestyle/intern/stroke/StrokeRenderer.h +++ b/source/blender/freestyle/intern/stroke/StrokeRenderer.h @@ -88,10 +88,12 @@ class TextureManager { bool operator()(const BrushTexture &bt1, const BrushTexture &bt2) const { int r = strcmp(bt1.first.c_str(), bt2.first.c_str()); - if (r != 0) + if (r != 0) { return (r < 0); - else + } + else { return (bt1.second < bt2.second); + } } }; typedef std::map<BrushTexture, unsigned, cmpBrushTexture> brushesMap; diff --git a/source/blender/freestyle/intern/stroke/StrokeRep.cpp b/source/blender/freestyle/intern/stroke/StrokeRep.cpp index a6c00f66056..3b309a9d249 100644 --- a/source/blender/freestyle/intern/stroke/StrokeRep.cpp +++ b/source/blender/freestyle/intern/stroke/StrokeRep.cpp @@ -142,8 +142,9 @@ void Strip::createStrip(const vector<StrokeVertex *> &iStrokeVertices) sv2 = *v2; Vec2r dir(sv2->getPoint() - sv->getPoint()); Vec2r orthDir(-dir[1], dir[0]); - if (orthDir.norm() > ZERO) + if (orthDir.norm() > ZERO) { orthDir.normalize(); + } Vec2r stripDir(orthDir); // check whether the orientation was user defined if (sv->attribute().isAttributeAvailableVec2f("orientation")) { @@ -151,8 +152,9 @@ void Strip::createStrip(const vector<StrokeVertex *> &iStrokeVertices) if (userDir.norm() > 1e-6) { userDir.normalize(); real dp = userDir * orthDir; - if (dp < 0) + if (dp < 0) { userDir = userDir * (-1.0f); + } stripDir = userDir; } else { @@ -206,8 +208,9 @@ void Strip::createStrip(const vector<StrokeVertex *> &iStrokeVertices) if (userDir.norm() > 1e-6) { userDir.normalize(); real dp = userDir * orthDir; - if (dp < 0) + if (dp < 0) { userDir = userDir * (-1.0f); + } stripDir = userDir; } else { @@ -226,8 +229,9 @@ void Strip::createStrip(const vector<StrokeVertex *> &iStrokeVertices) if (userDir.norm() > 1e-6) { userDir.normalize(); real dp = userDir * orthDir; - if (dp < 0) + if (dp < 0) { userDir = userDir * (-1.0f); + } stripDirPrev = userDir; } else { @@ -245,10 +249,12 @@ void Strip::createStrip(const vector<StrokeVertex *> &iStrokeVertices) Vec2r(p + thickness[1] * stripDir), Vec2r(p2 + thickness[1] * stripDir), pInter); - if (interResult == GeomUtils::DO_INTERSECT) + if (interResult == GeomUtils::DO_INTERSECT) { _vertices.push_back(new StrokeVertexRep(pInter)); - else + } + else { _vertices.push_back(new StrokeVertexRep(p + thickness[1] * stripDir)); + } ++i; interResult = GeomUtils::intersect2dLine2dLine(Vec2r(pPrev - thickness[0] * stripDirPrev), @@ -256,10 +262,12 @@ void Strip::createStrip(const vector<StrokeVertex *> &iStrokeVertices) Vec2r(p - thickness[0] * stripDir), Vec2r(p2 - thickness[0] * stripDir), pInter); - if (interResult == GeomUtils::DO_INTERSECT) + if (interResult == GeomUtils::DO_INTERSECT) { _vertices.push_back(new StrokeVertexRep(pInter)); - else + } + else { _vertices.push_back(new StrokeVertexRep(p - thickness[0] * stripDir)); + } ++i; // if the angle is obtuse, we simply average the directions to avoid the singularity @@ -292,8 +300,9 @@ void Strip::createStrip(const vector<StrokeVertex *> &iStrokeVertices) sv2 = *vPrev; dir = Vec2r(sv->getPoint() - sv2->getPoint()); orthDir = Vec2r(-dir[1], dir[0]); - if (orthDir.norm() > ZERO) + if (orthDir.norm() > ZERO) { orthDir.normalize(); + } Vec2r stripDirLast(orthDir); // check whether the orientation was user defined if (sv->attribute().isAttributeAvailableVec2f("orientation")) { @@ -301,8 +310,9 @@ void Strip::createStrip(const vector<StrokeVertex *> &iStrokeVertices) if (userDir.norm() > 1e-6) { userDir.normalize(); real dp = userDir * orthDir; - if (dp < 0) + if (dp < 0) { userDir = userDir * (-1.0f); + } stripDirLast = userDir; } else { @@ -343,8 +353,9 @@ void Strip::createStrip(const vector<StrokeVertex *> &iStrokeVertices) _averageThickness /= float(iStrokeVertices.size() - 2); // I did not use the first and last vertex for the average - if (iStrokeVertices.size() < 3) + if (iStrokeVertices.size() < 3) { _averageThickness = 0.5 * (thicknessLast[1] + thicknessLast[0] + thickness[0] + thickness[1]); + } if (orientationErrors > 0) { if (G.debug & G_DEBUG_FREESTYLE) { @@ -380,8 +391,9 @@ void Strip::cleanUpSingularities(const vector<StrokeVertex *> &iStrokeVertices) } // return; - if (iStrokeVertices.size() < 2) + if (iStrokeVertices.size() < 2) { return; + } int i = 0, j; vector<StrokeVertex *>::const_iterator v, vend, v2; StrokeVertex *sv, *sv2; @@ -394,15 +406,17 @@ void Strip::cleanUpSingularities(const vector<StrokeVertex *> &iStrokeVertices) for (vend = iStrokeVertices.end(); v != vend; v++) { v2 = v; ++v2; - if (v2 == vend) + if (v2 == vend) { break; + } sv = (*v); sv2 = (*v2); Vec2r p(sv->getPoint()), p2(sv2->getPoint()); Vec2r dir(p2 - p); - if (dir.norm() > ZERO) + if (dir.norm() > ZERO) { dir.normalize(); + } Vec2r dir1, dir2; dir1 = _vertices[2 * i + 2]->point2d() - _vertices[2 * i]->point2d(); dir2 = _vertices[2 * i + 3]->point2d() - _vertices[2 * i + 1]->point2d(); @@ -414,15 +428,18 @@ void Strip::cleanUpSingularities(const vector<StrokeVertex *> &iStrokeVertices) else { if (singu1) { int toto = i - timeSinceSingu1; - if (toto < 0) + if (toto < 0) { cerr << "Stephane dit \"Toto\"" << endl; + } // traverse all the vertices of the singularity and average them Vec2r avP(0.0, 0.0); - for (j = i - timeSinceSingu1; j <= i; j++) + for (j = i - timeSinceSingu1; j <= i; j++) { avP = Vec2r(avP + _vertices[2 * j]->point2d()); + } avP = Vec2r(1.0 / float(timeSinceSingu1 + 1) * avP); - for (j = i - timeSinceSingu1; j <= i; j++) + for (j = i - timeSinceSingu1; j <= i; j++) { _vertices[2 * j]->setPoint2d(avP); + } //_vertex[2 * j] = _vertex[2 * i]; singu1 = false; timeSinceSingu1 = 0; @@ -435,15 +452,18 @@ void Strip::cleanUpSingularities(const vector<StrokeVertex *> &iStrokeVertices) else { if (singu2) { int toto = i - timeSinceSingu2; - if (toto < 0) + if (toto < 0) { cerr << "Stephane dit \"Toto\"" << endl; + } // traverse all the vertices of the singularity and average them Vec2r avP(0.0, 0.0); - for (j = i - timeSinceSingu2; j <= i; j++) + for (j = i - timeSinceSingu2; j <= i; j++) { avP = Vec2r(avP + _vertices[2 * j + 1]->point2d()); + } avP = Vec2r(1.0 / float(timeSinceSingu2 + 1) * avP); - for (j = i - timeSinceSingu2; j <= i; j++) + for (j = i - timeSinceSingu2; j <= i; j++) { _vertices[2 * j + 1]->setPoint2d(avP); + } //_vertex[2 * j + 1] = _vertex[2 * i + 1]; singu2 = false; timeSinceSingu2 = 0; @@ -455,20 +475,24 @@ void Strip::cleanUpSingularities(const vector<StrokeVertex *> &iStrokeVertices) if (singu1) { // traverse all the vertices of the singularity and average them Vec2r avP(0.0, 0.0); - for (j = i - timeSinceSingu1; j < i; j++) + for (j = i - timeSinceSingu1; j < i; j++) { avP = Vec2r(avP + _vertices[2 * j]->point2d()); + } avP = Vec2r(1.0 / float(timeSinceSingu1) * avP); - for (j = i - timeSinceSingu1; j < i; j++) + for (j = i - timeSinceSingu1; j < i; j++) { _vertices[2 * j]->setPoint2d(avP); + } } if (singu2) { // traverse all the vertices of the singularity and average them Vec2r avP(0.0, 0.0); - for (j = i - timeSinceSingu2; j < i; j++) + for (j = i - timeSinceSingu2; j < i; j++) { avP = Vec2r(avP + _vertices[2 * j + 1]->point2d()); + } avP = Vec2r(1.0 / float(timeSinceSingu2) * avP); - for (j = i - timeSinceSingu2; j < i; j++) + for (j = i - timeSinceSingu2; j < i; j++) { _vertices[2 * j + 1]->setPoint2d(avP); + } } for (k = 0; k < sizeStrip; k++) { @@ -556,8 +580,9 @@ void Strip::computeTexCoordWithTips(const vector<StrokeVertex *> &iStrokeVertice sv = (*v); svRep = *currentSV; u = sv->curvilinearAbscissa() / spacedThickness * fact; - if (u > 0.25) + if (u > 0.25) { break; + } svRep->setTexCoord(Vec2r((real)u, -0.5), true); i++; @@ -572,10 +597,12 @@ void Strip::computeTexCoordWithTips(const vector<StrokeVertex *> &iStrokeVertice if (v != vend && i >= 2) { // first transition vertex - if (fabs(u - uPrev) > ZERO) + if (fabs(u - uPrev) > ZERO) { t = (0.25 - uPrev) / (u - uPrev); - else + } + else { t = 0; + } for (int k = 0; k < 2; k++) { tvRep[k] = new StrokeVertexRep((1 - t) * _vertices[i - 2]->point2d() + t * _vertices[i]->point2d()); @@ -613,8 +640,9 @@ void Strip::computeTexCoordWithTips(const vector<StrokeVertex *> &iStrokeVertice sv = (*v); svRep = *currentSV; u = sv->curvilinearAbscissa() / spacedThickness * fact - 0.25; - if (u > tiles) + if (u > tiles) { break; + } svRep->setTexCoord(Vec2r((real)u, 0), true); i++; @@ -631,10 +659,12 @@ void Strip::computeTexCoordWithTips(const vector<StrokeVertex *> &iStrokeVertice if (tipEnd) { if (v != vend && i >= 2) { // second transition vertex - if (fabs(u - uPrev) > ZERO) + if (fabs(u - uPrev) > ZERO) { t = (float(tiles) - uPrev) / (u - uPrev); - else + } + else { t = 0; + } for (int k = 0; k < 2; k++) { tvRep[k] = new StrokeVertexRep((1 - t) * _vertices[i - 2]->point2d() + t * _vertices[i]->point2d()); @@ -715,8 +745,9 @@ StrokeRep::StrokeRep() _mtex[a] = NULL; } TextureManager *ptm = TextureManager::getInstance(); - if (ptm) + if (ptm) { _textureId = ptm->getDefaultTextureId(); + } #if 0 _averageTextureAlpha = 0.5; //default value if (_strokeType == OIL_STROKE) @@ -744,8 +775,9 @@ StrokeRep::StrokeRep(Stroke *iStroke) } if (_textureId == 0) { TextureManager *ptm = TextureManager::getInstance(); - if (ptm) + if (ptm) { _textureId = ptm->getDefaultTextureId(); + } } #if 0 diff --git a/source/blender/freestyle/intern/stroke/StrokeRep.h b/source/blender/freestyle/intern/stroke/StrokeRep.h index a6d5c20624e..b2bfb805ee6 100644 --- a/source/blender/freestyle/intern/stroke/StrokeRep.h +++ b/source/blender/freestyle/intern/stroke/StrokeRep.h @@ -85,8 +85,9 @@ class StrokeVertexRep { if (tips) { return _texCoord_w_tips; } - else + else { return _texCoord; + } } inline Vec3r &color() diff --git a/source/blender/freestyle/intern/stroke/StrokeTesselator.cpp b/source/blender/freestyle/intern/stroke/StrokeTesselator.cpp index 8d2e554a67b..d4d184e2ce1 100644 --- a/source/blender/freestyle/intern/stroke/StrokeTesselator.cpp +++ b/source/blender/freestyle/intern/stroke/StrokeTesselator.cpp @@ -30,8 +30,9 @@ namespace Freestyle { LineRep *StrokeTesselator::Tesselate(Stroke *iStroke) { - if (0 == iStroke) + if (0 == iStroke) { return 0; + } LineRep *line; line = new OrientedLineRep(); @@ -49,8 +50,9 @@ LineRep *StrokeTesselator::Tesselate(Stroke *iStroke) line->AddVertex(B); } else { - if (_overloadFrsMaterial) + if (_overloadFrsMaterial) { line->setFrsMaterial(_FrsMaterial); + } line->setStyle(LineRep::LINE_STRIP); diff --git a/source/blender/freestyle/intern/stroke/StyleModule.h b/source/blender/freestyle/intern/stroke/StyleModule.h index 64095e971d6..6f03d903045 100644 --- a/source/blender/freestyle/intern/stroke/StyleModule.h +++ b/source/blender/freestyle/intern/stroke/StyleModule.h @@ -85,8 +85,9 @@ class StyleModule { StrokeLayer *sl = new StrokeLayer; for (Operators::StrokesContainer::iterator it = strokes_set->begin(); it != strokes_set->end(); - ++it) + ++it) { sl->AddStroke(*it); + } Operators::reset(); return sl; @@ -153,8 +154,9 @@ class StyleModule { void setModified(bool b = true) { - if (_always_refresh) + if (_always_refresh) { return; + } _modified = b; } diff --git a/source/blender/freestyle/intern/stroke/TextStrokeRenderer.cpp b/source/blender/freestyle/intern/stroke/TextStrokeRenderer.cpp index dc65871ef38..f579bd72038 100644 --- a/source/blender/freestyle/intern/stroke/TextStrokeRenderer.cpp +++ b/source/blender/freestyle/intern/stroke/TextStrokeRenderer.cpp @@ -22,8 +22,9 @@ namespace Freestyle { TextStrokeRenderer::TextStrokeRenderer(const char *iFileName) : StrokeRenderer() { - if (!iFileName) + if (!iFileName) { iFileName = "freestyle.txt"; + } // open the stream: _ofstream.open(iFileName, ios::out); if (!_ofstream.is_open()) { @@ -69,8 +70,9 @@ void TextStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const void TextStrokeRenderer::Close() { - if (_ofstream.is_open()) + if (_ofstream.is_open()) { _ofstream.close(); + } } } /* namespace Freestyle */ |