|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*test*/
|
|
Toshihiro Shimizu |
890ddd |
#include "zigzagstyles.h"
|
|
Toshihiro Shimizu |
890ddd |
//#include "tstrokeoutline.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "trandom.h"
|
|
Toshihiro Shimizu |
890ddd |
//#include "tgl.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef POICIPENSO
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TZigzagStrokeStyle::TZigzagStrokeStyle(const TPixel32 &color)
|
|
Shinya Kitaoka |
120a6e |
: m_color(color), m_density(0.5) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TZigzagStrokeStyle::TZigzagStrokeStyle()
|
|
Shinya Kitaoka |
120a6e |
: m_color(TPixel32(0, 0, 0, 255)), m_density(0.5) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TZigzagStrokeStyle::draw(double pixelSize, const TColorFunction *) {
|
|
Shinya Kitaoka |
120a6e |
// Distance between sampling points
|
|
Shinya Kitaoka |
120a6e |
const double minDist = 0.5;
|
|
Shinya Kitaoka |
120a6e |
const double maxDist = 6.0;
|
|
Shinya Kitaoka |
120a6e |
// Rotation angle of tangent
|
|
Shinya Kitaoka |
120a6e |
const int minRotAngle = 0;
|
|
Shinya Kitaoka |
120a6e |
const int maxRotAngle = 10;
|
|
Shinya Kitaoka |
120a6e |
// e.g minimum translation length is the half of the thickness
|
|
Shinya Kitaoka |
120a6e |
const double minTranslLength = 0.7;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TStroke *stroke = getStroke();
|
|
Shinya Kitaoka |
120a6e |
if (!stroke) return;
|
|
Shinya Kitaoka |
120a6e |
double length = stroke->getLength();
|
|
Shinya Kitaoka |
120a6e |
if (length <= 0) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int count =
|
|
Shinya Kitaoka |
120a6e |
(int)(length / (minDist + (maxDist - minDist) * (1.0 - m_density)) + 1);
|
|
Shinya Kitaoka |
120a6e |
double dist = length / count;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TRandom rnd;
|
|
Shinya Kitaoka |
120a6e |
// glEnable(GL_BLEND);
|
|
Shinya Kitaoka |
120a6e |
tglColor(m_color);
|
|
Shinya Kitaoka |
120a6e |
glBegin(GL_LINE_STRIP);
|
|
Shinya Kitaoka |
120a6e |
int first = 1;
|
|
Shinya Kitaoka |
120a6e |
for (double s = 0; s < (length + dist); s += dist, first = -first) {
|
|
Shinya Kitaoka |
120a6e |
double w = stroke->getParameterAtLength(s);
|
|
Shinya Kitaoka |
120a6e |
TThickPoint pos = stroke->getThickPoint(w);
|
|
Shinya Kitaoka |
120a6e |
TPointD u = stroke->getSpeed(w);
|
|
Shinya Kitaoka |
120a6e |
if (norm2(u) < TConsts::epsilon) continue;
|
|
Shinya Kitaoka |
120a6e |
u = normalize(u);
|
|
Shinya Kitaoka |
120a6e |
int angle = rnd.getInt(minRotAngle, maxRotAngle);
|
|
Shinya Kitaoka |
120a6e |
TRotation rotM(angle);
|
|
Shinya Kitaoka |
120a6e |
u = rotM * u;
|
|
Shinya Kitaoka |
120a6e |
double maxTranslLength = angle == 90 ? 1.0 : 2.0;
|
|
Shinya Kitaoka |
120a6e |
if (angle > 30 && angle < 90) {
|
|
Shinya Kitaoka |
120a6e |
double rta = 1.0 / tan(degree2rad(angle));
|
|
Shinya Kitaoka |
120a6e |
maxTranslLength = sqrt(sq(rta) + 1.0);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
double r = (minTranslLength +
|
|
Shinya Kitaoka |
120a6e |
(maxTranslLength - minTranslLength) * rnd.getDouble()) *
|
|
Shinya Kitaoka |
120a6e |
pos.thick * first;
|
|
Shinya Kitaoka |
120a6e |
glVertex(pos + r * u);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
glEnd();
|
|
Shinya Kitaoka |
120a6e |
// glDisable(GL_BLEND);
|
|
Shinya Kitaoka |
120a6e |
// glColor4d(0,0,0,1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TZigzagStrokeStyle::changeParameter(double delta) {
|
|
Shinya Kitaoka |
120a6e |
m_density = tcrop(m_density + delta, 0.0, 1.0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TStrokeStyle *TZigzagStrokeStyle::clone() const {
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *cs = new TZigzagStrokeStyle(*this);
|
|
Shinya Kitaoka |
120a6e |
cs->assignNames(this);
|
|
Shinya Kitaoka |
120a6e |
return cs;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TImageBasedZigzagStrokeStyle::TImageBasedZigzagStrokeStyle(
|
|
Shinya Kitaoka |
120a6e |
const TPixel32 &color)
|
|
Shinya Kitaoka |
120a6e |
: m_color(color)
|
|
Shinya Kitaoka |
120a6e |
, m_textScale(1.0)
|
|
Shinya Kitaoka |
120a6e |
, m_texture(0)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
{}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageBasedZigzagStrokeStyle::TImageBasedZigzagStrokeStyle()
|
|
Shinya Kitaoka |
120a6e |
: m_color(TPixel32(0, 0, 0, 255)), m_textScale(1.0), m_texture(0) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TImageBasedZigzagStrokeStyle::TImageBasedZigzagStrokeStyle(
|
|
Shinya Kitaoka |
120a6e |
const TRaster32P texture)
|
|
Shinya Kitaoka |
120a6e |
: m_color(TPixel32(0, 0, 0, 255)), m_textScale(1.0), m_texture(texture) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
inline int TImageBasedZigzagStrokeStyle::realTextCoord(const int a,
|
|
Shinya Kitaoka |
120a6e |
const int l) const {
|
|
Shinya Kitaoka |
120a6e |
return a == 0 ? 0 : (a > 0 ? a % l : l - 1 - ((-a) % l));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TImageBasedZigzagStrokeStyle::draw(double pixelSize,
|
|
Shinya Kitaoka |
120a6e |
const TColorFunction *) {
|
|
Shinya Kitaoka |
120a6e |
// Distance between sampling points
|
|
Shinya Kitaoka |
120a6e |
const double dist = 1.0;
|
|
Shinya Kitaoka |
120a6e |
// Scaling of texture
|
|
Shinya Kitaoka |
120a6e |
double recScale =
|
|
Shinya Kitaoka |
120a6e |
fabs(m_textScale) < TConsts::epsilon ? 1.0 : 1.0 / m_textScale;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TStroke *stroke = getStroke();
|
|
Shinya Kitaoka |
120a6e |
if (!stroke) return;
|
|
Shinya Kitaoka |
120a6e |
double length = stroke->getLength();
|
|
Shinya Kitaoka |
120a6e |
if (length <= 0) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TRandom rnd;
|
|
Shinya Kitaoka |
120a6e |
// glEnable(GL_BLEND);
|
|
Shinya Kitaoka |
120a6e |
glColor(m_color);
|
|
Shinya Kitaoka |
120a6e |
glBegin(GL_LINE_STRIP);
|
|
Shinya Kitaoka |
120a6e |
TPointD textC = m_texture->getCenterD();
|
|
Shinya Kitaoka |
120a6e |
TRectD strokeBB = stroke->getBBox();
|
|
Shinya Kitaoka |
120a6e |
TPointD strokeC((strokeBB.x0 + strokeBB.x1) / 2,
|
|
Shinya Kitaoka |
120a6e |
(strokeBB.y0 + strokeBB.y1) / 2);
|
|
Shinya Kitaoka |
120a6e |
for (double s = 0; s < (length + dist); s += dist) {
|
|
Shinya Kitaoka |
120a6e |
double w = stroke->getParameterAtLength(s);
|
|
Shinya Kitaoka |
120a6e |
TThickPoint pos = stroke->getThickPoint(w);
|
|
Shinya Kitaoka |
120a6e |
TPointD textPos((pos.x - strokeC.x) * recScale + textC.x,
|
|
Shinya Kitaoka |
120a6e |
(pos.y - strokeC.y) * recScale + textC.y);
|
|
Shinya Kitaoka |
120a6e |
TPointD u = stroke->getSpeed(w);
|
|
Shinya Kitaoka |
120a6e |
if (norm2(u) == 0) continue;
|
|
Shinya Kitaoka |
120a6e |
u = normalize(u);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TPoint iTextPos(tround(textPos.x), tround(textPos.y));
|
|
Shinya Kitaoka |
120a6e |
iTextPos.x = realTextCoord(iTextPos.x, m_texture->getLx());
|
|
Shinya Kitaoka |
120a6e |
iTextPos.y = realTextCoord(iTextPos.y, m_texture->getLy());
|
|
Shinya Kitaoka |
120a6e |
TPixel32 color = m_texture->pixels(iTextPos.y)[iTextPos.x];
|
|
Shinya Kitaoka |
120a6e |
double ch, cl, cs;
|
|
Shinya Kitaoka |
120a6e |
RGB2HLS(color.r / 255.0, color.g / 255.0, color.b / 255.0, &ch, &cl, &cs);
|
|
Shinya Kitaoka |
120a6e |
TRotation rotM(tround(ch));
|
|
Shinya Kitaoka |
120a6e |
u = rotM * u;
|
|
Shinya Kitaoka |
120a6e |
double r = cl * pos.thick;
|
|
Shinya Kitaoka |
120a6e |
glVertex(pos + r * u);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
glEnd();
|
|
Shinya Kitaoka |
120a6e |
// glDisable(GL_BLEND);
|
|
Shinya Kitaoka |
120a6e |
// glColor4d(0,0,0,1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TImageBasedZigzagStrokeStyle::changeParameter(double delta) {
|
|
Shinya Kitaoka |
120a6e |
m_textScale = tcrop(m_textScale + delta, 0.1, 2.5);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TStrokeStyle *TImageBasedZigzagStrokeStyle::clone() const {
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *cs = new TImageBasedZigzagStrokeStyle(*this);
|
|
Shinya Kitaoka |
120a6e |
cs->assignNames(this);
|
|
Shinya Kitaoka |
120a6e |
return cs;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|