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