tahoma2d/toonz/sources/include/ext/ExtUtil.h

158 lines
4.8 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef TNZ_EXTUTIL_H
#define TNZ_EXTUTIL_H
/**
* @author Fabrizio Morciano <fabrizio.morciano@gmail.com>
*/
#include "tcommon.h"
#include <tvectorimage.h>
#undef DVAPI
#undef DVVAR
#ifdef TNZEXT_EXPORTS
#define DVAPI DV_EXPORT_API
#define DVVAR DV_EXPORT_VAR
#else
#define DVAPI DV_IMPORT_API
#define DVVAR DV_IMPORT_VAR
#endif
#include "ext/Types.h"
2016-06-15 18:43:10 +12:00
namespace ToonzExt {
2016-03-19 06:57:51 +13:00
// Functions for straight corners management.
/**
* @brief Like cornersDetector but for straight corners.
*/
2016-06-15 18:43:10 +12:00
DVAPI bool straightCornersDetector(const TStroke *stroke,
std::vector<double> &corners);
2016-03-19 06:57:51 +13:00
/**
* @brief Find intervals where stroke is a straight line.
*
* These intervals are stored in an @c vector od Interval.
*/
2016-06-15 18:43:10 +12:00
DVAPI bool detectStraightIntervals(const TStroke *stroke,
ToonzExt::Intervals &intervals,
double tolerance = TConsts::epsilon);
2016-03-19 06:57:51 +13:00
/**
2016-06-15 18:43:10 +12:00
* @brief Retrieve parameters for straight intervals
2016-03-19 06:57:51 +13:00
* near actualW parameter.
*
2016-06-15 18:43:10 +12:00
* @return If not found return [-1,-1] interval, else
2016-03-19 06:57:51 +13:00
* the correct interval.
*/
2016-06-15 18:43:10 +12:00
DVAPI bool findNearestStraightCorners(const TStroke *s, double actualW,
Interval &out,
const ToonzExt::Intervals *const cl = 0,
double tolerance = TConsts::epsilon);
2016-03-19 06:57:51 +13:00
/**
*/
2016-06-15 18:43:10 +12:00
DVAPI bool isAStraightCorner(const TStroke *s, double actualW,
const ToonzExt::Intervals *const cl = 0,
double tolerance = TConsts::epsilon);
2016-03-19 06:57:51 +13:00
// Functions for spire corners management.
/**
* @brief Enhanced version of Toonz detect corners.
*/
2016-06-15 18:43:10 +12:00
DVAPI bool cornersDetector(const TStroke *stroke, int minDegree,
std::vector<double> &corners);
2016-03-19 06:57:51 +13:00
/**
* @brief Find intervals where stroke has limited from spire.
*
* These intervals are stored in an @c vector od Interval.
*/
2016-06-15 18:43:10 +12:00
DVAPI bool detectSpireIntervals(const TStroke *stroke,
ToonzExt::Intervals &intervals, int minDegree);
2016-03-19 06:57:51 +13:00
/**
* @brief Retrieve parameters for corners near actualW parameter.
*/
2016-06-15 18:43:10 +12:00
DVAPI bool findNearestSpireCorners(const TStroke *s, double actualW,
Interval &out, int cornerSize,
const ToonzExt::Intervals *const cl = 0,
double tolerance = TConsts::epsilon);
2016-03-19 06:57:51 +13:00
/**
*/
2016-06-15 18:43:10 +12:00
DVAPI bool isASpireCorner(const TStroke *s, double w, int cornerSize,
const ToonzExt::Intervals *const cl = 0,
double tolerance = TConsts::epsilon);
2016-03-19 06:57:51 +13:00
/**
* @brief Retrieve corners of a TStroke.
*/
2016-06-15 18:43:10 +12:00
DVAPI void findCorners(const TStroke *stroke, Intervals &corners,
Intervals &intervals, int angle, double tolerance);
2016-03-19 06:57:51 +13:00
/**
* @brief Retrieve corners of a TStroke.
*/
2016-06-15 18:43:10 +12:00
DVAPI bool findNearestCorners(const TStroke *stroke, double w, Interval &out,
const Intervals &values,
double tolerance = TConsts::epsilon);
2016-03-19 06:57:51 +13:00
// Stroke related functions.
/**
* @brief Rotate the control point at even position [0,2,4,...] in a
* new position along the close path of a selfLoop stroke.
*
2016-09-06 01:20:21 +12:00
* The new position is: @b atLength.
2016-03-19 06:57:51 +13:00
* @return 0 if some problem occurs, else the new stroke.
* @todo Some refactoring required, code duplication.
*/
2016-06-15 18:43:10 +12:00
DVAPI TStroke *rotateControlPoint(const TStroke *stroke,
const ToonzExt::EvenInt &even,
2016-09-06 01:20:21 +12:00
double atLength);
2016-03-19 06:57:51 +13:00
/**
* Retrieve all parameters where stroke has a minimum.
*/
2016-06-15 18:43:10 +12:00
DVAPI bool getAllW(const TStroke *stroke, const TPointD &pnt, double &dist2,
std::vector<double> &parameters);
2016-03-19 06:57:51 +13:00
/**
* @brief Replace a stroke in a vector image.
*/
2016-06-15 18:43:10 +12:00
DVAPI bool replaceStroke(TStroke *old_stroke, TStroke *new_stroke,
unsigned int n_, TVectorImageP &vi);
2016-03-19 06:57:51 +13:00
/**
2016-06-15 18:43:10 +12:00
* @brief Copy several parameters that are not
* copied with operator=
2016-03-19 06:57:51 +13:00
*/
2016-06-15 18:43:10 +12:00
void cloneStrokeStatus(const TStroke *from, TStroke *to);
2016-03-19 06:57:51 +13:00
//---------------------------------------------------------------------------
template <class T>
2016-06-15 18:43:10 +12:00
inline bool isValid(const T *s) {
assert(0 != s);
if (!s) return false;
return true;
2016-03-19 06:57:51 +13:00
}
//---------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
inline bool isValid(double w) {
assert(0.0 <= w && w <= 1.0);
if (w < 0.0 || w > 1.0) return false;
return true;
2016-03-19 06:57:51 +13:00
}
//---------------------------------------------------------------------------
}
#endif /* TNZ_EXTUTIL_H */
//-----------------------------------------------------------------------------
// End Of File
//-----------------------------------------------------------------------------