Code

hatches lpe: parameters renamed + tips, knot-lpe: can use 'unit of stroke width'.
authorjfbarraud <jfbarraud@users.sourceforge.net>
Sun, 25 Jan 2009 00:45:24 +0000 (00:45 +0000)
committerjfbarraud <jfbarraud@users.sourceforge.net>
Sun, 25 Jan 2009 00:45:24 +0000 (00:45 +0000)
src/live_effects/lpe-knot.cpp
src/live_effects/lpe-knot.h
src/live_effects/lpe-rough-hatches.cpp
src/live_effects/lpe-rough-hatches.h

index 1802135d72c0791ea17a365a7b32dceb1cfa9d6e..e369dcd95f6a7155db49cee75efd55a23291a82e 100644 (file)
@@ -13,6 +13,7 @@
 #include "display/curve.h"
 #include "live_effects/lpe-knot.h"
 #include "svg/svg.h"
+#include "style.h"
 
 #include <2geom/sbasis-to-bezier.h>
 #include <2geom/sbasis.h>
@@ -354,12 +355,14 @@ CrossingPoints::inherit_signs(CrossingPoints const &other, int default_value)
 LPEKnot::LPEKnot(LivePathEffectObject *lpeobject) :
     Effect(lpeobject),
     // initialise your parameters here:
-    interruption_width(_("Gap width"), _("The width of the gap in the path where it self-intersects"), "interruption_width", &wr, this, 10),
+    interruption_width(_("Interruption width"), _("Size of hidden region of lower string"), "interruption_width", &wr, this, 3),
+    prop_to_stroke_width(_("unit of stroke width"), _("Consider 'Gap width' as a ratio of stroke width."), "prop_to_stroke_width", &wr, this, true),
     switcher_size(_("Switcher size"), _("Orientation indicator/switcher size"), "switcher_size", &wr, this, 15),
     crossing_points_vector(_("Crossing Signs"), _("Crossings signs"), "crossing_points_vector", &wr, this)
 {
     // register all your parameters here, so Inkscape knows which parameters this effect has:
     registerParameter( dynamic_cast<Parameter *>(&interruption_width) );
+    registerParameter( dynamic_cast<Parameter *>(&prop_to_stroke_width) );
     registerParameter( dynamic_cast<Parameter *>(&switcher_size) );
     registerParameter( dynamic_cast<Parameter *>(&crossing_points_vector) );
 
@@ -404,7 +407,11 @@ LPEKnot::doEffect_path (std::vector<Geom::Path> const &input_path)
 {
     using namespace Geom;
     std::vector<Geom::Path> path_out;
+    //double width = interruption_width;
     double width = interruption_width;
+    if ( prop_to_stroke_width.get_value() ) {
+        width *= stroke_width;
+    }
 
     LPEKnotNS::CrossingPoints old_crdata(crossing_points_vector.data());
 
@@ -459,6 +466,16 @@ LPEKnot::doEffect_path (std::vector<Geom::Path> const &input_path)
 }
 
 
+
+void
+LPEKnot::doBeforeEffect (SPLPEItem *lpeitem)
+{
+    using namespace Geom;
+    //FIXME: do we have to be more carefull to access stroke width?
+    stroke_width = lpeitem->style->stroke_width.computed;
+}
+
+
 static LPEKnot *
 get_effect(SPItem *item)
 {
index cbd33466d80e5ef3de890e0c42b074c7ff51207c..5ece6d6fb053027af65615802de99ea7893b644b 100644 (file)
@@ -16,7 +16,8 @@
 #include "live_effects/effect.h"
 #include "live_effects/parameter/parameter.h"
 #include "live_effects/parameter/array.h"
-#include "live_effects/parameter/path.h"
+//#include "live_effects/parameter/path.h"
+#include "live_effects/parameter/bool.h"
 #include "2geom/crossing.h"
 
 namespace Inkscape {
@@ -56,6 +57,7 @@ public:
   virtual ~LPEKnot();
   
   virtual void doOnApply (SPLPEItem *lpeitem);
+  virtual void doBeforeEffect (SPLPEItem *lpeitem);
   virtual std::vector<Geom::Path> doEffect_path (std::vector<Geom::Path> const & input_path);
   
   /* the knotholder entity classes must be declared friends */
@@ -68,7 +70,9 @@ private:
   void updateSwitcher();
   // add the parameters for your effect here:
   ScalarParam interruption_width;
+  BoolParam  prop_to_stroke_width;
   ScalarParam switcher_size;
+  double stroke_width;
   ArrayParam<double> crossing_points_vector;
   LPEKnotNS::CrossingPoints crossing_points;
   
index 94d9669aa883ae92ee22b6cedb5d619e30d7a692..1bac02ec488cc343c3f4fdb197db98df6c838592 100644 (file)
@@ -141,22 +141,6 @@ public:
                 (*this)[next.first][next.second].prev_on_curve = std::pair<unsigned,unsigned>(i,j);\r
             }\r
         }\r
-#if 0\r
-        std::cout<<"\n";\r
-        for (unsigned i=0; i<temp.size()-1; i++){\r
-            std::cout<<temp[i].level<<","<<temp[i].idx<<" -> ";\r
-        }\r
-        std::cout<<"\n";\r
-        for (unsigned i=0; i<size(); i++){\r
-            for (unsigned j=0; j<(*this)[i].size(); j++){\r
-                std::cout<<"level:"<<i<<", idx:"<<j<<" -  ";\r
-                std::cout<<"next:"<<(*this)[i][j].next_on_curve.first<<",";\r
-                std::cout<<(*this)[i][j].next_on_curve.second<<" - ";\r
-                std::cout<<"prev:"<<(*this)[i][j].prev_on_curve.first<<",";\r
-                std::cout<<(*this)[i][j].prev_on_curve.second<<"\n";\r
-            }\r
-        }\r
-#endif\r
     }\r
 \r
     void findFirstUnused(unsigned &level, unsigned &idx){\r
@@ -267,32 +251,37 @@ Piecewise<D2<SBasis> > bend(Piecewise<D2<SBasis> > const &f, Piecewise<SBasis> b
 //--------------------------------------------------------\r
 LPERoughHatches::LPERoughHatches(LivePathEffectObject *lpeobject) :\r
     Effect(lpeobject),\r
-    dist_rdm(_("Dist randomness"), _("Variation of dist between hatches, in %."), "dist_rdm", &wr, this, 75),\r
+    direction(_("Hatches width and dir"), _("Defines hatches frequency and direction"), "direction", &wr, this, Geom::Point(50,0)),\r
+    dist_rdm(_("Frequency randomness"), _("Variation of dist between hatches, in %."), "dist_rdm", &wr, this, 75),\r
     growth(_("Growth"), _("Growth of distance between hatches."), "growth", &wr, this, 0.),\r
-    scale_tf(_("Start smothness (front side)"), _("MISSING DESCRIPTION"), "scale_tf", &wr, this, 1.),\r
-    scale_tb(_("Start smothness (back side)"), _("MISSING DESCRIPTION"), "scale_tb", &wr, this, 1.),\r
-    scale_bf(_("End smothness (front side)"), _("MISSING DESCRIPTION"), "scale_bf", &wr, this, 1.),\r
-    scale_bb(_("End smothness (back side)"), _("MISSING DESCRIPTION"), "scale_bb", &wr, this, 1.),\r
-    top_edge_variation(_("Start edge variance"), _("The amount of random jitter to move the hatches start"), "top_edge_variation", &wr, this, 0),\r
-    bot_edge_variation(_("End edge variance"), _("The amount of random jitter to move the hatches end"), "bot_edge_variation", &wr, this, 0),\r
-    top_tgt_variation(_("Start tangential variance"), _("The amount of random jitter to move the hatches start along the boundary"), "top_tgt_variation", &wr, this, 0),\r
-    bot_tgt_variation(_("End tangential variance"), _("The amount of random jitter to move the hatches end along the boundary"), "bot_tgt_variation", &wr, this, 0),\r
-    top_smth_variation(_("Start smoothness variance"), _("Randomness of the smoothness of the U turn at hatches start"), "top_smth_variation", &wr, this, 0),\r
-    bot_smth_variation(_("End spacing variance"), _("Randomness of the smoothness of the U turn at hatches end"), "bot_smth_variation", &wr, this, 0),\r
-    fat_output(_("Generate thick/thin path"), _("Simulate a stroke of varrying width"), "fat_output", &wr, this, true),\r
+//FIXME: top/bottom names are inverted in the UI/svg and in the code!!\r
+    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.),\r
+    scale_tb(_("1st side, out"), _("Set smoothness/sharpness of path when leaving a 'bottom' halfturn. 0=sharp, 1=default"), "scale_bb", &wr, this, 1.),\r
+    scale_bf(_("2nd side, in "), _("Set smoothness/sharpness of path when reaching a 'top' halfturn. 0=sharp, 1=default"), "scale_tf", &wr, this, 1.),\r
+    scale_bb(_("2nd side, out"), _("Set smoothness/sharpness of path when leaving a 'top' halfturn. 0=sharp, 1=default"), "scale_tb", &wr, this, 1.),\r
+    top_smth_variation(_("variance: 1st side"), _("Randomness of 'bottom' halfturns smoothness"), "bottom_smth_variation", &wr, this, 0),\r
+    bot_smth_variation(_("2nd side"), _("Randomness of 'top' halfturns smoothness"), "bottom_smth_variation", &wr, this, 0),\r
+//\r
+    top_edge_variation(_("Magnitude jitter: 1st side"), _("Randomly moves 'bottom' halfsturns to produce magnitude variations."), "bottom_edge_variation", &wr, this, 0),\r
+    bot_edge_variation(_("2nd side"), _("Randomly moves 'top' halfsturns to produce magnitude variations."), "top_edge_variation", &wr, this, 0),\r
+    top_tgt_variation(_("Parallelism jitter: 1st side"), _("Add direction randomness by moving 'bottom' halfsturns tangentially to the boundary."), "bottom_tgt_variation", &wr, this, 0),\r
+    bot_tgt_variation(_("2nd side"), _("Add direction randomness by randomly moving 'top' halfsturns tangentially to the boundary."), "top_tgt_variation", &wr, this, 0),\r
+//\r
     do_bend(_("Bend hatches"), _("Add a global bend to the hatches (slower)"), "do_bend", &wr, this, true),\r
-    stroke_width_top(_("Stroke width (start side)"), _("Width at hatches 'start'"), "stroke_width_top", &wr, this, 1.),\r
-    stroke_width_bot(_("Stroke width (end side)"), _("Width at hatches 'end'"), "stroke_width_bot", &wr, this, 1.),\r
-    front_thickness(_("Front thickness (%)"), _("MISSING DESCRIPTION"), "front_thickness", &wr, this, 1.),\r
-    back_thickness(_("Back thickness (%)"), _("MISSING DESCRIPTION"), "back_thickness", &wr, this, .25),\r
-    bender(_("Global bending"), _("Relative position to ref point defines global bending direction and amount"), "bender", &wr, this, NULL, Geom::Point(-5,0)),\r
-    direction(_("Hatches width and dir"), _("Defines hatches frequency and direction"), "direction", &wr, this, Geom::Point(50,0))\r
+    //bender(_("Global bending"), _("Relative position to ref point defines global bending direction and amount"), "bender", &wr, this, NULL, Geom::Point(-5,0)),\r
+    bender(_("Global bending"), _("Relative position to ref point defines global bending direction and amount"), "bender", &wr, this, Geom::Point(-5,0)),\r
+//\r
+    fat_output(_("Generate thick/thin path"), _("Simulate a stroke of varrying width"), "fat_output", &wr, this, true),\r
+    stroke_width_top(_("Thikness: at 1st side"), _("Width at 'bottom' half turns"), "stroke_width_bottom", &wr, this, 1.),\r
+    stroke_width_bot(_("at 2nd side"), _("Width at 'top' halfturns"), "stroke_width_bottom", &wr, this, 1.),\r
+    front_thickness(_("from 2nd to 1st side"), _("Width of paths from 'top' to 'bottom' halfturns"), "front_thickness", &wr, this, 1.),\r
+    back_thickness(_("from 1st to 2nd side"), _("Width of paths from 'top' to 'bottom' halfturns"), "back_thickness", &wr, this, .25)\r
 {\r
     registerParameter( dynamic_cast<Parameter *>(&direction) );\r
-    registerParameter( dynamic_cast<Parameter *>(&do_bend) );\r
-    registerParameter( dynamic_cast<Parameter *>(&bender) );\r
     registerParameter( dynamic_cast<Parameter *>(&dist_rdm) );\r
     registerParameter( dynamic_cast<Parameter *>(&growth) );\r
+    registerParameter( dynamic_cast<Parameter *>(&do_bend) );\r
+    registerParameter( dynamic_cast<Parameter *>(&bender) );\r
     registerParameter( dynamic_cast<Parameter *>(&top_edge_variation) );\r
     registerParameter( dynamic_cast<Parameter *>(&bot_edge_variation) );\r
     registerParameter( dynamic_cast<Parameter *>(&top_tgt_variation) );\r
@@ -332,12 +321,15 @@ LPERoughHatches::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const &
     Piecewise<D2<SBasis> > result;\r
     \r
     Piecewise<D2<SBasis> > transformed_pwd2_in = pwd2_in;\r
+    Point transformed_org = direction.getOrigin();\r
     Piecewise<SBasis> tilter;//used to bend the hatches\r
     Matrix bend_mat;//used to bend the hatches\r
 \r
     if (do_bend.get_value()){\r
-        Point bend_dir = -rot90(unit_vector(direction.getOrigin() - bender));\r
-        double bend_amount = L2(direction.getOrigin() - bender);\r
+        //Point bend_dir = -rot90(unit_vector(direction.getOrigin() - bender));\r
+        //double bend_amount = L2(direction.getOrigin() - bender);\r
+        Point bend_dir = -rot90(unit_vector(direction.getVector()));\r
+        double bend_amount = L2(direction.getVector());\r
         bend_mat = Matrix(-bend_dir[Y], bend_dir[X], bend_dir[X], bend_dir[Y],0,0);\r
         transformed_pwd2_in = pwd2_in * bend_mat;\r
         tilter = Piecewise<SBasis>(shift(Linear(bend_amount),1));\r
@@ -351,9 +343,10 @@ LPERoughHatches::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const &
     Point hatches_dir = rot90(unit_vector(direction.getVector()));\r
     Matrix mat(-hatches_dir[Y], hatches_dir[X], hatches_dir[X], hatches_dir[Y],0,0);\r
     transformed_pwd2_in = transformed_pwd2_in * mat;\r
+    transformed_org *= mat;\r
         \r
     std::vector<std::vector<Point> > snakePoints;\r
-    snakePoints = linearSnake(transformed_pwd2_in);\r
+    snakePoints = linearSnake(transformed_pwd2_in, transformed_org);\r
     if ( snakePoints.size() > 0 ){\r
         Piecewise<D2<SBasis> >smthSnake = smoothSnake(snakePoints); \r
         smthSnake = smthSnake*mat.inverse();\r
@@ -371,9 +364,11 @@ LPERoughHatches::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const &
 // Generate the levels with random, growth...\r
 //------------------------------------------------\r
 std::vector<double>\r
-LPERoughHatches::generateLevels(Interval const &domain){\r
+LPERoughHatches::generateLevels(Interval const &domain, double x_org){\r
     std::vector<double> result;\r
-    double x = domain.min() + double(hatch_dist)/2.;\r
+    int n = int((domain.min()-x_org)/hatch_dist);\r
+    double x = x_org +  n * hatch_dist;\r
+    //double x = domain.min() + double(hatch_dist)/2.;\r
     double step = double(hatch_dist);\r
     double scale = 1+(hatch_dist*growth/domain.extent());\r
     while (x < domain.max()){\r
@@ -392,17 +387,17 @@ LPERoughHatches::generateLevels(Interval const &domain){
 // Walk through the intersections to create linear hatches\r
 //-------------------------------------------------------\r
 std::vector<std::vector<Point> > \r
-LPERoughHatches::linearSnake(Piecewise<D2<SBasis> > const &f){\r
+LPERoughHatches::linearSnake(Piecewise<D2<SBasis> > const &f, Point const &org){\r
 \r
     std::vector<std::vector<Point> > result;\r
 \r
     Piecewise<SBasis> x = make_cuts_independent(f)[X];\r
-    //Rque: derivative is computed twice in the 2 lines below!!\r
+    //Remark: derivative is computed twice in the 2 lines below!!\r
     Piecewise<SBasis> dx = derivative(x);\r
     OptInterval range = bounds_exact(x);\r
 \r
     if (not range) return result;\r
-    std::vector<double> levels = generateLevels(*range);\r
+    std::vector<double> levels = generateLevels(*range, org[X]);\r
     std::vector<std::vector<double> > times;\r
     times = multi_roots(x,levels);\r
 \r
@@ -432,9 +427,16 @@ LPERoughHatches::linearSnake(Piecewise<D2<SBasis> > const &f){
     LevelsCrossings lscs(times,f,dx);\r
     unsigned i,j;\r
     lscs.findFirstUnused(i,j);\r
+    \r
     std::vector<Point> result_component;\r
+    int n = int((range->min()-org[X])/hatch_dist);\r
     while ( i < lscs.size() ){ \r
         int dir = 0;\r
+        //switch orientation of first segment according to org position.\r
+        if (n % 2 == 0){\r
+            j = lscs[i].size()-1;\r
+            dir = 2;\r
+        }\r
         while ( i < lscs.size() ){\r
             result_component.push_back(lscs[i][j].pt);\r
             lscs[i][j].used = true;\r
@@ -572,9 +574,11 @@ LPERoughHatches::resetDefaults(SPItem * item)
         top_edge_variation.param_set_value( (*bbox)[Y].extent()/10, 0 );\r
         bot_edge_variation.param_set_value( (*bbox)[Y].extent()/10, 0 );\r
     }\r
-    direction.set_and_write_new_values(origin, vector);\r
-    bender.param_set_and_write_new_value( origin + Geom::Point(5,0) );\r
-    hatch_dist = Geom::L2(vector)/5;\r
+    //direction.set_and_write_new_values(origin, vector);\r
+    //bender.param_set_and_write_new_value( origin + Geom::Point(5,0) );\r
+    direction.set_and_write_new_values(origin + Geom::Point(0,-5), vector);\r
+    bender.set_and_write_new_values( origin, Geom::Point(5,0) );\r
+    hatch_dist = Geom::L2(vector)/2;\r
 }\r
 \r
 \r
index 23b2a0966e76b8132ea03815e0c7ab9916374eda..816955e4d1050b4164efbf7b85cc205d0e334bdd 100644 (file)
@@ -37,10 +37,10 @@ public:
     virtual void doBeforeEffect(SPLPEItem * item);\r
 \r
   std::vector<double>\r
-  generateLevels(Geom::Interval const &domain);\r
+    generateLevels(Geom::Interval const &domain, double x_org);\r
 \r
   std::vector<std::vector<Geom::Point> >\r
-  linearSnake(Geom::Piecewise<Geom::D2<Geom::SBasis> > const &f);\r
+    linearSnake(Geom::Piecewise<Geom::D2<Geom::SBasis> > const &f, Geom::Point const &org);\r
 \r
   Geom::Piecewise<Geom::D2<Geom::SBasis> > \r
   smoothSnake(std::vector<std::vector<Geom::Point> > const &linearSnake);\r
@@ -64,8 +64,9 @@ private:
   ScalarParam stroke_width_bot;\r
   ScalarParam front_thickness, back_thickness;\r
 \r
-  PointParam  bender;\r
+  //PointParam  bender;\r
   VectorParam direction;\r
+  VectorParam bender;\r
 \r
   LPERoughHatches(const LPERoughHatches&);\r
   LPERoughHatches& operator=(const LPERoughHatches&);\r