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