Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
center-warp.cpp
Go to the documentation of this file.
2#include <2geom/d2.h>
3#include <2geom/path.h>
4#include <2geom/sbasis-2d.h>
6#include <2geom/sbasis.h>
7#include <2geom/sbasis-math.h>
9#include <2geom/transforms.h>
10
11#include <toys/path-cairo.h>
13
14#include <vector>
15using std::vector;
16using namespace Geom;
17
20
22 for(unsigned i = 0; i < p.size(); i++) {
23 D2<SBasis> B;
24 B[0] = Linear(p.cuts[i], p.cuts[i+1]);
25 B[1] = p[i];
26 cairo_d2_sb(cr, B);
27 }
28}
29
30class CentreWarp: public Toy {
31 Path path_a;
32 D2<SBasis2d> sb2;
33 Piecewise<D2<SBasis> > path_a_pw;
34 PointHandle brush_handle;
35 void draw(cairo_t *cr, std::ostringstream *notify, int width, int height, bool save, std::ostringstream *timer_stream) override {
36 Geom::Point dir(1,-2);
37
39
40 cairo_set_source_rgba (cr, 0., 0.125, 0, 1);
41
42 if(0) {
43 D2<Piecewise<SBasis> > tB(cos(B[0]*0.1)*(brush_handle.pos[0]/100) + B[0],
44 cos(B[1]*0.1)*(brush_handle.pos[1]/100) + B[1]);
45
46 cairo_d2_pw_sb(cr, tB);
47 } else {
48 Piecewise<SBasis> r2 = (dot(path_a_pw - brush_handle.pos, path_a_pw - brush_handle.pos));
50 rc.push_cut(0);
51 rc.push(SBasis(Linear(1, 1)), 2);
52 rc.push(SBasis(Linear(1, 0)), 4);
53 rc.push(SBasis(Linear(0, 0)), 30);
54 rc *= 10;
55 rc.scaleDomain(1000);
57 swr.push_cut(0);
58 swr.push(SBasis(Linear(0, 1)), 2);
59 swr.push(SBasis(Linear(1, 0)), 4);
60 swr.push(SBasis(Linear(0, 0)), 30);
61 swr *= 10;
62 swr.scaleDomain(1000);
63 cairo_pw(cr, swr);// + (height - 100));
64 D2<Piecewise<SBasis> > uB = make_cuts_independent(unitVector(path_a_pw - brush_handle.pos));
65
66 D2<Piecewise<SBasis> > tB(compose(rc, (r2))*uB[0] + B[0],
67 compose(rc, (r2))*uB[1] + B[1]);
68 cairo_d2_pw_sb(cr, tB);
69 //path_a_pw = sectionize(tB);
70 }
71 cairo_stroke(cr);
72
73 *notify << path_a_pw.size();
74
75 Toy::draw(cr, notify, width, height, save,timer_stream);
76 }
77 void first_time(int argc, char** argv) override {
78 const char *path_a_name="star.svgd";
79 if(argc > 1)
80 path_a_name = argv[1];
81 PathVector paths_a = read_svgd(path_a_name);
82 assert(!paths_a.empty());
83 path_a = paths_a[0];
84
85 path_a.close(true);
86 path_a_pw = path_a.toPwSb();
87 for(unsigned dim = 0; dim < 2; dim++) {
88 sb2[dim].us = 2;
89 sb2[dim].vs = 2;
90 const int depth = sb2[dim].us*sb2[dim].vs;
91 sb2[dim].resize(depth, Linear2d(0));
92 }
93
94 handles.push_back(&brush_handle);
95 brush_handle.pos = Point(100,100);
96 }
97};
98
99int main(int argc, char **argv) {
100 init(argc, argv, new CentreWarp);
101 return 0;
102}
103
104/*
105 Local Variables:
106 mode:c++
107 c-file-style:"stroustrup"
108 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
109 indent-tabs-mode:nil
110 fill-column:99
111 End:
112*/
113// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Path - a sequence of contiguous curves.
int main()
Conversion between Bezier control points and SBasis curves.
void cairo_pw(cairo_t *cr, Piecewise< SBasis > p)
unsigned total_pieces_inc
unsigned total_pieces_sub
Adaptor that creates 2D functions from 1D ones.
Definition d2.h:55
Function that interpolates linearly between two values.
Definition linear.h:55
Sequence of subpaths.
Definition pathvector.h:122
bool empty() const
Check whether the vector contains any paths.
Definition pathvector.h:145
Sequence of contiguous curves, aka spline.
Definition path.h:353
void close(bool closed=true)
Set whether the path is closed.
Definition path.cpp:322
Piecewise< D2< SBasis > > toPwSb() const
Definition path.cpp:388
Function defined as discrete pieces.
Definition piecewise.h:71
unsigned size() const
Definition piecewise.h:131
void push(const T &s, double to)
Convenience/implementation hiding function to add segment/cut pairs.
Definition piecewise.h:141
void scaleDomain(double s)
Definition piecewise.h:204
void push_cut(double c)
Definition piecewise.h:152
std::vector< double > cuts
Definition piecewise.h:75
Two-dimensional point that doubles as a vector.
Definition point.h:66
Polynomial in symmetric power basis.
Definition sbasis.h:70
Geom::Point pos
virtual void first_time(int, char **)
vector< Handle * > handles
virtual void save(FILE *f)
virtual void draw(cairo_t *cr, std::ostringstream *notify, int w, int h, bool save, std::ostringstream *timing_stream)
RectangularCluster rc
Lifts one dimensional objects into 2D.
PathVector read_svgd(char const *filename)
Create path vector from SVG path data stored in a file.
Various utility functions.
Definition affine.h:22
SBasisN< n > cos(LinearN< n > bo, int k)
D2< Piecewise< SBasis > > make_cuts_independent(Piecewise< D2< SBasis > > const &a)
Definition d2-sbasis.cpp:75
D2< T > compose(D2< T > const &a, T const &b)
Definition d2.h:405
T dot(D2< T > const &a, D2< T > const &b)
Definition d2.h:355
Piecewise< D2< SBasis > > unitVector(D2< SBasis > const &vect, double tol=.01, unsigned order=3)
struct _cairo cairo_t
Definition path-cairo.h:16
void cairo_d2_pw_sb(cairo_t *cr, Geom::D2< Geom::Piecewise< Geom::SBasis > > const &p)
void cairo_d2_sb(cairo_t *cr, Geom::D2< Geom::SBasis > const &p)
Obsolete 2D SBasis function class.
two-dimensional geometric operators.
some std functions to work with (pw)s-basis
Polynomial in symmetric power basis (S-basis)
parse SVG path specifications
double height
double width
void cairo_set_source_rgba(cairo_t *cr, colour c)
void init(int argc, char **argv, Toy *t, int width=600, int height=600)
Affine transformation classes.