From 02850b48595d7ea3e80cee87cc5abbb45ce2c481 Mon Sep 17 00:00:00 2001 From: Ivan Mahonin Date: Aug 26 2023 14:51:24 +0000 Subject: #assistants: remove unused SmoothStroke class --- diff --git a/toonz/sources/tnztools/toonzrasterbrushtool.cpp b/toonz/sources/tnztools/toonzrasterbrushtool.cpp index 539368a..92f9dfc 100644 --- a/toonz/sources/tnztools/toonzrasterbrushtool.cpp +++ b/toonz/sources/tnztools/toonzrasterbrushtool.cpp @@ -720,124 +720,6 @@ static void Smooth(std::vector &points, const int radius, } } -//-------------------------------------------------------------------------------------------------- - -void SmoothStroke::beginStroke(int smooth) { - m_smooth = smooth; - m_outputIndex = 0; - m_readIndex = -1; - m_rawPoints.clear(); - m_outputPoints.clear(); - m_resampledIndex = 0; - m_resampledPoints.clear(); -} - -//-------------------------------------------------------------------------------------------------- - -void SmoothStroke::addPoint(const TThickPoint &point) { - if (m_rawPoints.size() > 0 && m_rawPoints.back().x == point.x && - m_rawPoints.back().y == point.y) { - return; - } - m_rawPoints.push_back(point); - generatePoints(); -} - -//-------------------------------------------------------------------------------------------------- - -void SmoothStroke::endStroke() { - generatePoints(); - // force enable the output all segments - m_outputIndex = m_outputPoints.size() - 1; -} - -//-------------------------------------------------------------------------------------------------- - -void SmoothStroke::clearPoints() { - m_outputIndex = 0; - m_readIndex = -1; - m_outputPoints.clear(); - m_rawPoints.clear(); - m_resampledIndex = 0; - m_resampledPoints.clear(); -} - -//-------------------------------------------------------------------------------------------------- - -void SmoothStroke::getSmoothPoints(std::vector &smoothPoints) { - int n = m_outputPoints.size(); - for (int i = m_readIndex + 1; i <= m_outputIndex && i < n; ++i) { - smoothPoints.push_back(m_outputPoints[i]); - } - m_readIndex = m_outputIndex; -} - -//-------------------------------------------------------------------------------------------------- - -void SmoothStroke::generatePoints() { - int n = (int)m_rawPoints.size(); - if (n == 0) { - return; - } - - // if m_smooth = 0, then skip whole smoothing process - if (m_smooth == 0) { - for (int i = m_outputIndex; i < (int)m_outputPoints.size(); ++i) { - if (m_outputPoints[i] != m_rawPoints[i]) { - break; - } - ++m_outputIndex; - } - m_outputPoints = m_rawPoints; - return; - } - - std::vector smoothedPoints = m_resampledPoints; - // Add more stroke samples before applying the smoothing - // This is because the raw inputs points are too few to support smooth result, - // especially on stroke ends - - int resampleStartId = m_resampledIndex; - for (int i = resampleStartId; i < n - 1; ++i) { - const TThickPoint &p1 = m_rawPoints[i]; - const TThickPoint &p2 = m_rawPoints[i + 1]; - const TThickPoint &p0 = i - 1 >= 0 ? m_rawPoints[i - 1] : p1; - const TThickPoint &p3 = i + 2 < n ? m_rawPoints[i + 2] : p2; - - std::vector tmpResampled; - tmpResampled.push_back(p1); - // define subsample amount according to distance between points - int samples = std::min((int)tdistance(p1, p2), 8); - if (samples >= 1) - CatmullRomInterpolate(p0, p1, p2, p3, samples, tmpResampled); - - if (i + 2 < n) { - m_resampledIndex = i + 1; - std::copy(tmpResampled.begin(), tmpResampled.end(), - std::back_inserter(m_resampledPoints)); - } - std::copy(tmpResampled.begin(), tmpResampled.end(), - std::back_inserter(smoothedPoints)); - } - smoothedPoints.push_back(m_rawPoints.back()); - // Apply the 1D box filter - // Multiple passes result in better quality and fix the stroke ends break - // issue - // level is passed to define range where the points are smoothed - for (int level = 2; level >= 0; --level) { - Smooth(smoothedPoints, m_smooth, m_readIndex, level); - } - // Compare the new smoothed stroke with old one - // Enable the output for unchanged parts - int outputNum = (int)m_outputPoints.size(); - for (int i = m_outputIndex; i < outputNum; ++i) { - if (m_outputPoints[i] != smoothedPoints[i]) { - break; - } - ++m_outputIndex; - } - m_outputPoints = smoothedPoints; -} //=================================================================== // diff --git a/toonz/sources/tnztools/toonzrasterbrushtool.h b/toonz/sources/tnztools/toonzrasterbrushtool.h index 681230c..370649e 100644 --- a/toonz/sources/tnztools/toonzrasterbrushtool.h +++ b/toonz/sources/tnztools/toonzrasterbrushtool.h @@ -92,42 +92,6 @@ public: }; //************************************************************************ -// Smooth Stroke declaration -// Brush stroke smoothing buffer. -//************************************************************************ -class SmoothStroke { -public: - SmoothStroke() {} - ~SmoothStroke() {} - - // begin stroke - // smooth is smooth strength, from 0 to 100 - void beginStroke(int smooth); - // add stroke point - void addPoint(const TThickPoint &point); - // end stroke - void endStroke(); - // Get generated stroke points which has been smoothed. - // Both addPoint() and endStroke() generate new smoothed points. - // This method will removed generated points - void getSmoothPoints(std::vector &smoothPoints); - // Remove all points - used for straight lines - void clearPoints(); - -private: - void generatePoints(); - -private: - int m_smooth; - int m_outputIndex; - int m_readIndex; - std::vector m_rawPoints; - std::vector m_outputPoints; - - int m_resampledIndex; - std::vector m_resampledPoints; -}; -//************************************************************************ // Toonz Raster Brush Tool declaration //************************************************************************ @@ -262,8 +226,6 @@ protected: TTileSaverCM32 *tileSaver = nullptr; TRect affectedRect; - SmoothStroke smoothStroke; - struct Pencil { bool isActive = false; bool realPencil = false; diff --git a/toonz/sources/tnztools/toonzvectorbrushtool.h b/toonz/sources/tnztools/toonzvectorbrushtool.h index 09084dc..c2d35f5 100644 --- a/toonz/sources/tnztools/toonzvectorbrushtool.h +++ b/toonz/sources/tnztools/toonzvectorbrushtool.h @@ -3,15 +3,15 @@ #ifndef TOONZVECTORBRUSHTOOL_H #define TOONZVECTORBRUSHTOOL_H -#include "tgeometry.h" -#include "tproperty.h" -#include "trasterimage.h" -#include "ttoonzimage.h" -#include "tstroke.h" -#include "toonz/strokegenerator.h" +#include +#include +#include +#include +#include +#include -#include "tools/tool.h" -#include "tools/cursors.h" +#include +#include #include #include @@ -24,8 +24,6 @@ #include #endif -#include "toonzrasterbrushtool.h" - #include #include