|
Shinya Kitaoka |
810553 |
#pragma once
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TSTROKE_UTIL_H
|
|
Toshihiro Shimizu |
890ddd |
#define TSTROKE_UTIL_H
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzCore includes
|
|
Toshihiro Shimizu |
890ddd |
#include "traster.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#undef DVAPI
|
|
Toshihiro Shimizu |
890ddd |
#undef DVVAR
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef TVRENDER_EXPORTS
|
|
Toshihiro Shimizu |
890ddd |
#define DVAPI DV_EXPORT_API
|
|
Toshihiro Shimizu |
890ddd |
#define DVVAR DV_EXPORT_VAR
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
#define DVAPI DV_IMPORT_API
|
|
Toshihiro Shimizu |
890ddd |
#define DVVAR DV_IMPORT_VAR
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Forward declarations
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class TStroke;
|
|
Toshihiro Shimizu |
890ddd |
class TStrokeDeformation;
|
|
Toshihiro Shimizu |
890ddd |
class TVectorRenderData;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*******************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// Utility stroke functions
|
|
Toshihiro Shimizu |
890ddd |
//*******************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
\brief Inserts control points in a stroke according to the input deformer.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
\details This function inserts redundant control points to use in the
|
|
Toshihiro Shimizu |
890ddd |
specified deformation.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
\par Unverified documentation
|
|
Shinya Kitaoka |
120a6e |
The "increaser" studies the gradient (getDelta) of the input
|
|
Shinya Kitaoka |
120a6e |
deformer
|
|
Toshihiro Shimizu |
890ddd |
object, and insert control points if there is increment.\n
|
|
Toshihiro Shimizu |
890ddd |
In "extremes" there are the first point of not zero potential and
|
|
Toshihiro Shimizu |
890ddd |
the last.\n\n
|
|
Toshihiro Shimizu |
890ddd |
Special case (plane at same potential)
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DVAPI bool increaseControlPoints(
|
|
Shinya Kitaoka |
120a6e |
TStroke &stroke, //!< Stroke to be deformed.
|
|
Shinya Kitaoka |
120a6e |
const TStrokeDeformation &deformer, //!< Deformer to be applied.
|
|
Shinya Kitaoka |
120a6e |
double pixelSize = 1.0 //!< Resolution modifier.
|
|
Shinya Kitaoka |
120a6e |
);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
DVAPI void modifyControlPoints(TStroke &stroke,
|
|
Shinya Kitaoka |
120a6e |
const TStrokeDeformation &deformer);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
DVAPI void modifyControlPoints(TStroke &stroke,
|
|
Shinya Kitaoka |
120a6e |
const TStrokeDeformation &deformer,
|
|
Shinya Kitaoka |
120a6e |
std::vector<double> &controlPointLen);</double>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
DVAPI void modifyThickness(TStroke &stroke, const TStrokeDeformation &deformer,
|
|
Shinya Kitaoka |
120a6e |
std::vector<double> &controlPointLen,</double>
|
|
Shinya Kitaoka |
120a6e |
bool exponentially = false);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
\brief Transforms a stroke's thickness by a given polynomial function.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DVAPI void transform_thickness(
|
|
Shinya Kitaoka |
120a6e |
TStroke &stroke, //!< Stroke whose thickness will be transformed.
|
|
Shinya Kitaoka |
120a6e |
const double poly[], //!< Polynomial coefficients, by increasing degree.
|
|
Shinya Kitaoka |
120a6e |
int deg //!< Polynomial degree.
|
|
Shinya Kitaoka |
120a6e |
);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
\brief This function translates an input polyline to the control points
|
|
Toshihiro Shimizu |
890ddd |
of a sequence of quadratics.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
\details The conversion is actually a 2 step process. First, segment
|
|
Shinya Kitaoka |
120a6e |
midpoints
|
|
Toshihiro Shimizu |
890ddd |
are added to the sequence to be used as quadratic endpoints. Each
|
|
Toshihiro Shimizu |
890ddd |
"midpoint-vertex-midpoint" triplet is converted independently to
|
|
Toshihiro Shimizu |
890ddd |
quadratics, thus ensuring that tangent vectors at midpoints are
|
|
Toshihiro Shimizu |
890ddd |
preserved.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
The triplets conversion step allows the following control
|
|
Shinya Kitaoka |
120a6e |
parameters:
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
\a adherenceTol is the maximum distance allowed for
|
|
Shinya Kitaoka |
120a6e |
quadratics to approximate a
|
|
Toshihiro Shimizu |
890ddd |
polyline corner (\p 0 meaning full corner).
|
|
Shinya Kitaoka |
120a6e |
Polyline corners whose edges inner product is strictly above
|
|
Shinya Kitaoka |
120a6e |
\a angleTol are
|
|
Shinya Kitaoka |
120a6e |
transformed into full corners. The range for \a angleTol
|
|
Shinya Kitaoka |
120a6e |
should be <tt>[-1, 1]</tt>.
|
|
Shinya Kitaoka |
120a6e |
A quadratic approximating a polyline vertex triplet yields a
|
|
Shinya Kitaoka |
120a6e |
minimum curvature
|
|
Shinya Kitaoka |
120a6e |
radius in proximity of the triplet's corner. If the ratios
|
|
Shinya Kitaoka |
120a6e |
between such
|
|
Shinya Kitaoka |
120a6e |
radius and the edges extending from the corner are both below
|
|
Shinya Kitaoka |
120a6e |
\a relativeTol,
|
|
Shinya Kitaoka |
120a6e |
the triplet is transformed into a full corner. The edges are
|
|
Shinya Kitaoka |
120a6e |
calculated along
|
|
Shinya Kitaoka |
120a6e |
fat lines extending from the corner with \a relativeDist
|
|
Shinya Kitaoka |
120a6e |
half-thickness.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
Once this first approximating sequence has been produced, an optimal
|
|
Shinya Kitaoka |
120a6e |
quadratics
|
|
Toshihiro Shimizu |
890ddd |
merging step is employed to simplify the overall sequence.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
The \a mergeTol parameter specifies the allowed merging error that
|
|
Shinya Kitaoka |
120a6e |
can be employed
|
|
Toshihiro Shimizu |
890ddd |
in this step (\p 0 meaning no simplification).
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
\note The output cps are thick points with 0 thickness. In other words,
|
|
Shinya Kitaoka |
120a6e |
thickness
|
|
Shinya Kitaoka |
120a6e |
is not considered, but supplied in output as TStrokes require them
|
|
Shinya Kitaoka |
120a6e |
for construction.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
\sa The tcg::polyline_ops::toQuadratics template function.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DVAPI void polylineToQuadratics(
|
|
Shinya Kitaoka |
120a6e |
const std::vector<tpointd></tpointd>
|
|
Shinya Kitaoka |
120a6e |
&polyline, //!< Polyline to be translated to quadratics.
|
|
Shinya Kitaoka |
120a6e |
std::vector<tthickpoint></tthickpoint>
|
|
Shinya Kitaoka |
120a6e |
&cps, //!< Control points of the output quadratics sequence.
|
|
Shinya Kitaoka |
120a6e |
double adherenceTol =
|
|
Shinya Kitaoka |
120a6e |
1.0, //!< Maximum distance from quadratic to polyline corner.
|
|
Shinya Kitaoka |
120a6e |
double angleTol = 0.0, //!< Inner product threshold for polyline angles.
|
|
Shinya Kitaoka |
120a6e |
double relativeTol = 0.25,
|
|
Shinya Kitaoka |
120a6e |
double relativeDistTol = 0.25, double mergeTol = 1.0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Shinya Kitaoka |
120a6e |
\brief Draws a stroke on a raster, under the specified rendering
|
|
Shinya Kitaoka |
120a6e |
parameters.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DVAPI void renderStroke(
|
|
Shinya Kitaoka |
120a6e |
const TVectorRenderData
|
|
Shinya Kitaoka |
120a6e |
&rd, //!< Render parameters (clipping rect, affine transform, etc).
|
|
Shinya Kitaoka |
120a6e |
const TRaster32P &output, //!< Destination raster.
|
|
Shinya Kitaoka |
120a6e |
TStroke *stroke //!< Stroke to render.
|
|
Shinya Kitaoka |
120a6e |
);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
namespace Toonz {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
\brief Merge an array of stroke in a single stroke.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
\remark If two consecutive strokes don't touch at the endpoints,
|
|
Toshihiro Shimizu |
890ddd |
an additional joining segment is added between them.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DVAPI TStroke *merge(const std::vector<tstroke *=""> &strokes);</tstroke>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
} // namespace Toonz
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
#endif // TSTROKE_UTIL_H
|