コード例 #1
0
ファイル: convole.cpp プロジェクト: abrock/lib2geom
SBasisOf<double> toSBasisOfDouble(SBasis const &f){
    SBasisOf<double> result;
    for (unsigned i=0; i<f.size(); i++){
        result.push_back(LinearOf<double>(f[i][0],f[i][1]));
    }
    return result;
}
コード例 #2
0
ファイル: convole.cpp プロジェクト: abrock/lib2geom
SBasisOf<SBasisOf<double> > integral(SBasisOf<SBasisOf<double> > const &f, unsigned var){
    //variable of f = 1, variable of f's coefficients = 0. 
    if (var == 1) return integraaal(f);
    SBasisOf<SBasisOf<double> > result;
    for(unsigned i = 0; i< f.size(); i++) {
        //result.push_back(LinearOf<SBasisOf<double> >( integral(f[i][0]),integral(f[i][1])));
        result.push_back(LinearOf<SBasisOf<double> >( integraaal(f[i][0]),integraaal(f[i][1])));
    }
    return result;
}
コード例 #3
0
ファイル: convole.cpp プロジェクト: abrock/lib2geom
    void draw(cairo_t *cr,
	      std::ostringstream *notify,
	      int width, int height, bool save, std::ostringstream *timer_stream) {
    
        D2<SBasis> B1 = b1_handle.asBezier();
        D2<SBasis> B2 = b2_handle.asBezier();
        D2<Piecewise<SBasis> >B;
        B[X].concat(Piecewise<SBasis>(B1[X]));
        B[X].concat(Piecewise<SBasis>(B2[X]));
        B[Y].concat(Piecewise<SBasis>(B1[Y]));
        B[Y].concat(Piecewise<SBasis>(B2[Y]));

//-----------------------------------------------------
#if 0
        Frame frame;
        frame.O = Point(50,400);
        frame.x = Point(300,0);
        frame.y = Point(120,-75);
        frame.z = Point(0,-300); 
        SBasisOf<SBasisOf<double> > u,v,cst;
        cst.push_back(LinearOf<SBasisOf<double> >(SBasisOf<double>(LinearOf<double>(1,1))));
        u.push_back(LinearOf<SBasisOf<double> >(SBasisOf<double>(LinearOf<double>(0,1))));
        v.push_back(LinearOf<SBasisOf<double> >(SBasisOf<double>(LinearOf<double>(0,0)),
                                                SBasisOf<double>(LinearOf<double>(1,1))));
        plot3d(cr, integral(v,1) ,frame);
        plot3d(cr, v ,frame);
        cairo_set_source_rgba (cr, 0., 0.5, 0., 1);
        cairo_stroke(cr);
        plot3d(cr, Linear(0,1), Linear(0), Linear(0), frame);
        plot3d(cr, Linear(0), Linear(0,1), Linear(0), frame);
        plot3d(cr, Linear(0), Linear(0), Linear(0,1), frame);
        plot3d(cr, Linear(0,1), Linear(1), Linear(0), frame);
        plot3d(cr, Linear(1), Linear(0,1), Linear(0), frame);
        cairo_set_source_rgba (cr, 0., 0.0, 0.9, 1);
        cairo_stroke(cr);
#endif
//-----------------------------------------------------

        SBasisOf<double> smoother;
        smoother.push_back(LinearOf<double>(0.));
        smoother.push_back(LinearOf<double>(0.));
        smoother.push_back(LinearOf<double>(30.));//could be less degree hungry!

        adjuster.pos[X] = 400;
        if(adjuster.pos[Y]>400) adjuster.pos[Y] = 400;
        if(adjuster.pos[Y]<100) adjuster.pos[Y] = 100;
        double scale=(400.-adjuster.pos[Y])/300+.01;
        D2<Piecewise<SBasis> > smoothB1,smoothB2;
        smoothB1[X] = convole(toSBasisOfDouble(B1[X]),Interval(0,4),smoother/scale,Interval(-scale/2,scale/2));
        smoothB1[Y] = convole(toSBasisOfDouble(B1[Y]),Interval(0,4),smoother/scale,Interval(-scale/2,scale/2));
        smoothB1[X].push(Linear(0.), 8+scale/2);
        smoothB1[Y].push(Linear(0.), 8+scale/2);
        smoothB2[X] = Piecewise<SBasis>(Linear(0));
        smoothB2[X].setDomain(Interval(-scale/2,4-scale/2));
        smoothB2[Y] = smoothB2[X];
        smoothB2[X].concat(convole(toSBasisOfDouble(B2[X]),Interval(4,8),smoother/scale,Interval(-scale/2,scale/2)));
        smoothB2[Y].concat(convole(toSBasisOfDouble(B2[Y]),Interval(4,8),smoother/scale,Interval(-scale/2,scale/2)));

        Piecewise<D2<SBasis> > smoothB;
        smoothB = sectionize(smoothB1)+sectionize(smoothB2);
        //cairo_d2_sb(cr, B1);
        //cairo_d2_sb(cr, B2);
        cairo_pw_d2_sb(cr, smoothB);
        
        cairo_move_to(cr,100,400);
        cairo_line_to(cr,500,400);
        cairo_set_line_width (cr, .5);
        cairo_set_source_rgba (cr, 0., 0., 0., 1);
        cairo_stroke(cr);

        Piecewise<SBasis>bx = Piecewise<SBasis>(B1[X]);
        bx.setDomain(Interval(0,4));
        Piecewise<SBasis>smth = Piecewise<SBasis>(toSBasis(smoother));
        smth.setDomain(Interval(-scale/2,scale/2));
        cairo_d2_sb(cr, B1);
        plot_graph(cr, bx, 100, 1);
        plot_graph(cr, smth/scale, 100, 100);
        plot_graph(cr, smoothB1[X],100,1);
        
        //cairo_pw_d2_sb(cr, Piecewise<D2<SBasis> >(B1) );
        //cairo_pw_d2_sb(cr, sectionize(smoothB1));        

        cairo_set_line_width (cr, .5);
        cairo_set_source_rgba (cr, 0.7, 0.2, 0., 1);
        cairo_stroke(cr);


        Toy::draw(cr, notify, width, height, save,timer_stream);
    }