lpe-rough-hatches.cpp revision 68e1aedad4c8d7f3798c79a8c55c139803ae6d70
#define INKSCAPE_LPE_ROUGH_HATCHES_CPP
/** \file
* LPE Curve Stitching implementation, used as an example for a base starting class
* when implementing new LivePathEffects.
*
*/
/*
* Authors:
* JF Barraud.
*
* Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "live_effects/lpe-rough-hatches.h"
#include "sp-item.h"
#include "sp-path.h"
#include "libnr/nr-values.h"
namespace Inkscape {
namespace LivePathEffect {
using namespace Geom;
//------------------------------------------------
// Some goodies to navigate through curve's levels.
//------------------------------------------------
struct LevelCrossing{
double t;
bool sign;
bool used;
};
struct LevelCrossingOrder {
bool operator()(LevelCrossing a, LevelCrossing b) {
//return ( a.pt[X] < b.pt[X] || ( a.pt[X] == b.pt[X] && a.pt[Y] < b.pt[Y] ) );
}
};
struct LevelCrossingInfo{
double t;
unsigned level;
unsigned idx;
};
struct LevelCrossingInfoOrder {
bool operator()(LevelCrossingInfo a, LevelCrossingInfo b) {
return a.t < b.t;
}
};
//double old_t = f.cuts[0];
for(unsigned i=1; i<f.size(); i++){
//old_t = f.cuts[i];
//assert(f.segs[i-1].at1()==f.valueAt(old_t));
}
}
//assert(f.segs.back().at1()==f.valueAt(old_t));
return result;
}
public:
}
}
//Now create time ordering.
for (unsigned i=0; i<size(); i++){
for (unsigned j=0; j<(*this)[i].size(); j++){
elem.t = (*this)[i][j].t;
}
}
unsigned jump_idx = 0;
unsigned first_in_comp = 0;
first_in_comp = i+1;
jump_idx += 1;
}else{
}
}
for (unsigned i=0; i<size(); i++){
for (unsigned j=0; j<(*this)[i].size(); j++){
}
}
}
idx = 0;
for (unsigned i=0; i<size(); i++){
for (unsigned j=0; j<(*this)[i].size(); j++){
if (!(*this)[i][j].used){
level = i;
idx = j;
return;
}
}
}
}
//set indexes to point to the next point in the "snake walk"
//follow_level's meaning:
// 0=yes upward
// 1=no, last move was upward,
// 2=yes downward
// 3=no, last move was downward.
if ( direction % 2 == 0 ){
if (direction == 0) {
return;
}
idx += 1;
}else{
return;
}
idx -= 1;
}
direction += 1;
return;
}
//---double next_t = t;
//level += 1;
return;
}
if ( sign > 0 ){
}else{
}
return;
}
return;
}
};
//-------------------------------------------------------
// Bend a path...
//-------------------------------------------------------
return sectionize(ff);
}
//--------------------------------------------------------
// The RoughHatches lpe.
//--------------------------------------------------------
hatch_dist(0),
dist_rdm(_("Frequency randomness"), _("Variation of distance between hatches, in %."), "dist_rdm", &wr, this, 75),
scale_tf(_("Half turns smoothness: 1st side, in"), _("Set smoothness/sharpness of path when reaching a 'bottom' halfturn. 0=sharp, 1=default"), "scale_bf", &wr, this, 1.),
scale_tb(_("1st side, out"), _("Set smoothness/sharpness of path when leaving a 'bottom' halfturn. 0=sharp, 1=default"), "scale_bb", &wr, this, 1.),
scale_bf(_("2nd side, in"), _("Set smoothness/sharpness of path when reaching a 'top' halfturn. 0=sharp, 1=default"), "scale_tf", &wr, this, 1.),
scale_bb(_("2nd side, out"), _("Set smoothness/sharpness of path when leaving a 'top' halfturn. 0=sharp, 1=default"), "scale_tb", &wr, this, 1.),
top_edge_variation(_("Magnitude jitter: 1st side"), _("Randomly moves 'bottom' halfsturns to produce magnitude variations."), "bottom_edge_variation", &wr, this, 0),
bot_edge_variation(_("2nd side"), _("Randomly moves 'top' halfsturns to produce magnitude variations."), "top_edge_variation", &wr, this, 0),
top_tgt_variation(_("Parallelism jitter: 1st side"), _("Add direction randomness by moving 'bottom' halfsturns tangentially to the boundary."), "bottom_tgt_variation", &wr, this, 0),
bot_tgt_variation(_("2nd side"), _("Add direction randomness by randomly moving 'top' halfsturns tangentially to the boundary."), "top_tgt_variation", &wr, this, 0),
top_smth_variation(_("Variance: 1st side"), _("Randomness of 'bottom' halfturns smoothness"), "top_smth_variation", &wr, this, 0),
bot_smth_variation(_("2nd side"), _("Randomness of 'top' halfturns smoothness"), "bottom_smth_variation", &wr, this, 0),
//
fat_output(_("Generate thick/thin path"), _("Simulate a stroke of varrying width"), "fat_output", &wr, this, true),
do_bend(_("Bend hatches"), _("Add a global bend to the hatches (slower)"), "do_bend", &wr, this, true),
stroke_width_top(_("Thickness: at 1st side"), _("Width at 'bottom' half turns"), "stroke_width_top", &wr, this, 1.),
stroke_width_bot(_("at 2nd side"), _("Width at 'top' halfturns"), "stroke_width_bottom", &wr, this, 1.),
//
front_thickness(_("from 2nd to 1st side"), _("Width of paths from 'top' to 'bottom' halfturns"), "front_thickness", &wr, this, 1.),
back_thickness(_("from 1st to 2nd side"), _("Width of paths from 'top' to 'bottom' halfturns"), "back_thickness", &wr, this, .25),
direction(_("Hatches width and dir"), _("Defines hatches frequency and direction"), "direction", &wr, this, Geom::Point(50,0)),
//
//bender(_("Global bending"), _("Relative position to a reference point defines global bending direction and amount"), "bender", &wr, this, NULL, Geom::Point(-5,0)),
bender(_("Global bending"), _("Relative position to a reference point defines global bending direction and amount"), "bender", &wr, this, Geom::Point(-5,0))
{
//hatch_dist.param_set_range(0.1, NR_HUGE);
concatenate_before_pwd2 = false;
show_orig_path = true;
}
{
}
//std::cout<<"doEffect_pwd2:\n";
}
}
transformed_org *= mat;
if ( snakePoints.size() > 0 ){
}
return (smthSnake);
}
return pwd2_in;
}
//------------------------------------------------
// Generate the levels with random, growth...
//------------------------------------------------
double x = x_org + n * hatch_dist;
//double x = domain.min() + double(hatch_dist)/2.;
double step = double(hatch_dist);
double rdm = 1;
}
return result;
}
//-------------------------------------------------------
// Walk through the intersections to create linear hatches
//-------------------------------------------------------
//std::cout<<"linearSnake:\n";
//Remark: derivative is computed twice in the 2 lines below!!
//TODO: fix multi_roots!!!*****************************************
//remove doubles :-(
}
}
}
}
//*******************************************************************
unsigned i,j;
lscs.findFirstUnused(i,j);
int dir = 0;
//switch orientation of first segment according to starting point.
j += 1;
dir = 2;
}
}
lscs.findFirstUnused(i,j);
}
return result;
}
//-------------------------------------------------------
// Smooth the linear hatches according to params...
//-------------------------------------------------------
unsigned i=1;
//bool is_top = true;//Inversion here; due to downward y?
if (is_top){
if (top_edge_variation.get_value() != 0)
if (top_tgt_variation.get_value() != 0)
if (top_smth_variation.get_value() != 0) {
}
}else{
if (bot_edge_variation.get_value() != 0)
if (bot_tgt_variation.get_value() != 0)
if (bot_smth_variation.get_value() != 0) {
}
}
if ( fat_output.get_value() ){
//double scaled_width = double((is_top ? stroke_width_top : stroke_width_bot))/(pt1[X]-pt0[X]);
inside_hdle_in = inside + (new_hdle_in -new_pt);// + hdle_offset * double((is_top ? front_thickness : back_thickness));
inside_hdle_out = inside + (new_hdle_out-new_pt);// - hdle_offset * double((is_top ? back_thickness : front_thickness));
inside_hdle_in += (pt1-pt0)/2*( double((is_top ? front_thickness : back_thickness)) / (pt1[X]-pt0[X]) );
inside_hdle_out -= (pt1-pt0)/2*( double((is_top ? back_thickness : front_thickness)) / (pt1[X]-pt0[X]) );
new_hdle_in -= (pt1-pt0)/2*( double((is_top ? front_thickness : back_thickness)) / (pt1[X]-pt0[X]) );
new_hdle_out += (pt1-pt0)/2*( double((is_top ? back_thickness : front_thickness)) / (pt1[X]-pt0[X]) );
//TODO: find a good way to handle limit cases (small smthness, large stroke).
//if (inside_hdle_in[X] > inside[X]) inside_hdle_in = inside;
//if (inside_hdle_out[X] < inside[X]) inside_hdle_out = inside;
if (is_top){
}else{
}
}else{
}
i+=2;
}
if ( fat_output.get_value() ){
}else{
}
}
if ( fat_output.get_value() ){
}
}
}
return result;
}
void
{
using namespace Geom;
//original_bbox(lpeitem);
}
void
{
if (bbox) {
}
//direction.set_and_write_new_values(origin, vector);
//bender.param_set_and_write_new_value( origin + Geom::Point(5,0) );
}
} //namespace LivePathEffect
} /* namespace Inkscape */
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :