Пример #1
0
Файл: ct.c Проект: EdKeith/core
static A jttayamp(J jt,A w,B nf,A x,A h){A y;B ng=!nf;I j,n;V*v=VAV(h);
 ASSERT(AR(x)<=(nf?v->lr:v->rr),EVRANK);
 switch(v->id){
  case CPLUS:  R tpoly(over(x,one));
  case CMINUS: R tpoly(nf?over(x,num[-1]):over(negate(x),one));
  case CSTAR:  R tpoly(over(zero,x));
  case CDIV:   ASSERT(ng,EVDOMAIN); R tpoly(over(zero,recip(x)));
  case CJDOT:  R tpoly(nf?over(x,a0j1):over(jdot1(x),one));
  case CPOLY:  ASSERT(nf,EVDOMAIN); R tpoly(BOX&AT(x)?poly1(x):x);
  case CHGEOM: ASSERT(nf,EVDOMAIN); RE(j=i0(x)); ASSERT(0<=j,EVDOMAIN);
               y=IX(j);
               R tpoly(divide(hgcoeff(y,h),fact(y)));
  case CBANG:  ASSERT(nf,EVDOMAIN); RE(j=i0(x)); ASSERT(0<=j,EVDOMAIN); 
               R tpoly(divide(poly1(box(iota(x))),fact(x)));
  case CEXP:   if(nf)R eva(x,"(^.x)&^ % !");
               RE(n=i0(x));   
               R 0<=n?tpoly(over(reshape(x,zero),one)):atop(ds(CDIV),amp(h,sc(-n))); 
  case CFIT:   ASSERT(nf&&CPOLY==ID(v->f),EVDOMAIN);
               y=over(x,IX(IC(x)));
               R tpoly(mdiv(df2(x,y,h),atab(CEXP,y,IX(IC(x)))));
  case CCIRCLE:
   switch(i0(x)){
    case 1:    R eval("{&0 1 0 _1@(4&|) % !");
    case -3:   R eval("{&0 1 0 _1@(4&|) % ]");
    case 2:    R eval("{&1 0 _1 0@(4&|) % !");
    case 5:    R eval("2&|    % !");
    case -7:   R eval("2&|    % ]");
    case 6:    R eval("2&|@>: % !");
    case -1:   R eval("(2&|              % ]) * ([: */ (1&+ % 2&+)@(i.@<.&.-:))\"0");
    case -5:   R eval("({&0 1 0 _1@(4&|) % ]) * ([: */ (1&+ % 2&+)@(i.@<.&.-:))\"0");
 }}
 ASSERT(0,EVDOMAIN);
}
Пример #2
0
void
Spring::paintEvent(QPaintEvent *ev)
{
    if (!designMode())
        return;

    QPainter p(this);
    p.setRenderHint(QPainter::Antialiasing, true);
//! @todo p.setPen(QPen(Qt::white, 1));
//! @todo p.setCompositionMode(QPainter::CompositionMode_Xor);
    if (m_orient == Qt::Vertical) {
        uint part = (height() + 16) / 16;
        if (part < 3)
            part = 3;
        uint w = width() - 1;
        uint offset = 0;
        for (uint i = 0; i < 4; i++, offset += (part * 4)) {
            QPolygon poly1(4);
            poly1.putPoints(0, 4,
                         w / 2, offset, w, offset + part, w, offset + part, w / 2, offset + part*2);
            QPainterPath ppath1;
            ppath1.addPolygon(poly1);
            p.strokePath(ppath1, p.pen());
            QPolygon poly2(4);
            poly2.putPoints(0, 4,
                         w / 2, offset + part*2, 0, offset + part*3, 0, offset + part*3, w / 2, offset + part*4);
            QPainterPath ppath2;
            ppath2.addPolygon(poly2);
            p.strokePath(ppath2, p.pen());
        }
    } else {
        uint part = (width() + 16) / 16;
        if (part < 3)
            part = 3;
        uint h = height() - 1;
        uint offset = 0;
        for (uint i = 0; i < 4; i++, offset += (part * 4)) {
            QPolygon poly1(4);
            poly1.putPoints(0, 4,
                         offset, h / 2, offset + part, 0, offset + part, 0, offset + part*2, h / 2);
            QPainterPath ppath1;
            ppath1.addPolygon(poly1);
            p.strokePath(ppath1, p.pen());
            QPolygon poly2(4);
            poly2.putPoints(0, 4,
                         offset + part*2, h / 2, offset + part*3, h, offset + part*3, h, offset + part*4, h / 2);
            QPainterPath ppath2;
            ppath2.addPolygon(poly2);
            p.strokePath(ppath2, p.pen());
        }
    }
}
int main()
{
	Poly<int> poly1(2);
	poly1[0] = 1;
	poly1[1] = 2;
	poly1[2] = 10;

	Poly<int> poly2(3);
	poly2[0] = 1;
	poly2[1] = 2;
	poly2[2] = 10;
	poly2[3] = 5;

	poly1.view();
	poly2.view();

	auto result1 = poly1 + poly2;
	auto result2 = poly1 * poly2;
	result1.view();
	result2.view();


	std::cout << std::endl << std::endl;
	return 0;
}
Пример #4
0
int main(int argc, char **argv){
	if(argc < 3){
		std::cout<<"Not enough arguments"<<std::endl;
		return -1;
	}
	int POLYTERMS = atoi(argv[2]);
	if(POLYTERMS < 2 || (POLYTERMS & (POLYTERMS - 1))){
		std::cout<<"Problem size must be a power of 2\n";
		return -1;
	}
	std::mt19937 rng(time(NULL));
	std::uniform_real_distribution<> dist(-1, 1);
	std::vector<float> times;
	for(int i = 0; i < 10; ++i){
		std::vector<float> poly1(POLYTERMS), poly2(POLYTERMS);
		std::generate(poly1.begin(), poly1.end(), [&](){return dist(rng);});
		std::generate(poly2.begin(), poly2.end(), [&](){return dist(rng);});
		std::vector<float> temp;
		auto start = std::chrono::steady_clock::now();
		switch(argv[1][1]){
			case 'd': temp = dumbMult(poly1, poly2); break;
			case '4': temp = fourMult(poly1, poly2); break;
			case '3': temp = threeMult(poly1, poly2); break;
			default: "Invalid algorithm argument\n"; return -1;
		}
		times.push_back(std::chrono::duration_cast<std::chrono::duration<float>>(std::chrono::steady_clock::now() - start).count());
		// std::cout<<"Ran in "<<(std::chrono::duration_cast<std::chrono::duration<float>>(std::chrono::steady_clock::now() - start).count())<<" seconds"<<std::endl;
	}
	std::cout<<"Mean time: "<<(std::accumulate(times.begin(), times.end(), 0.0) / times.size())<<" seconds"<<std::endl;
	// std::cout<<"Resulting coefficients: ";
	// for(auto &term : temp){
	// 	std::cout<<term<<" ";
	// }
	// std::cout<<std::endl;
}
Пример #5
0
BOOL CFrustum::CreateFromClipPoly(Fvector* p, int count, Fvector& vBase, CFrustum& clip)
{
	VERIFY(count<FRUSTUM_MAXPLANES);
	VERIFY(count>=3);

	sPoly	poly1	(p,count);
	sPoly	poly2;
	sPoly*	dest	= clip.ClipPoly(poly1,poly2);

	// here we end up with complete frustum-polygon in 'dest'
	if (0==dest)	return false;

	CreateFromPoints(dest->begin(),dest->size(),vBase);
	return	true;
}
Пример #6
0
  virtual void on_draw() {
    typedef agg::renderer_base<pixfmt> ren_base;

    pixfmt pixf(rbuf_window());
    ren_base renb(pixf);
    renb.clear(agg::rgba(1, 1, 1));

    agg::rasterizer_scanline_aa<> ras;
    agg::scanline_p8 sl;

    agg::path_storage path;

    path.move_to(m_x[0], m_y[0]);
    path.line_to((m_x[0] + m_x[1]) / 2,
                 (m_y[0] + m_y[1]) / 2);  // This point is added only to check
                                          // for numerical stability
    path.line_to(m_x[1], m_y[1]);
    path.line_to(m_x[2], m_y[2]);
    path.line_to(m_x[2], m_y[2]);  // This point is added only to check for
                                   // numerical stability

    path.move_to((m_x[0] + m_x[1]) / 2, (m_y[0] + m_y[1]) / 2);
    path.line_to((m_x[1] + m_x[2]) / 2, (m_y[1] + m_y[2]) / 2);
    path.line_to((m_x[2] + m_x[0]) / 2, (m_y[2] + m_y[0]) / 2);
    path.close_polygon();

    agg::line_cap_e cap = agg::butt_cap;
    if (m_cap.cur_item() == 1) cap = agg::square_cap;
    if (m_cap.cur_item() == 2) cap = agg::round_cap;

    agg::line_join_e join = agg::miter_join;
    if (m_join.cur_item() == 1) join = agg::miter_join_revert;
    if (m_join.cur_item() == 2) join = agg::round_join;
    if (m_join.cur_item() == 3) join = agg::bevel_join;

    // (1)
    agg::conv_stroke<agg::path_storage> stroke(path);
    stroke.line_join(join);
    stroke.line_cap(cap);
    stroke.miter_limit(m_miter_limit.value());
    stroke.width(m_width.value());
    ras.add_path(stroke);
    agg::render_scanlines_aa_solid(ras, sl, renb, agg::rgba(0.8, 0.7, 0.6));
    // (1)

    // (2)
    agg::conv_stroke<agg::path_storage> poly1(path);
    poly1.width(1.5);
    ras.add_path(poly1);
    agg::render_scanlines_aa_solid(ras, sl, renb, agg::rgba(0, 0, 0));
    // (2)

    // (3)
    agg::conv_dash<agg::conv_stroke<agg::path_storage> > poly2_dash(stroke);
    agg::conv_stroke<agg::conv_dash<agg::conv_stroke<agg::path_storage> > >
        poly2(poly2_dash);
    poly2.miter_limit(4.0);
    poly2.width(m_width.value() / 5.0);
    poly2.line_cap(cap);
    poly2.line_join(join);
    poly2_dash.add_dash(20.0, m_width.value() / 2.5);
    ras.add_path(poly2);
    agg::render_scanlines_aa_solid(ras, sl, renb, agg::rgba(0, 0, 0.3));
    // (3)

    // (4)
    ras.add_path(path);
    agg::render_scanlines_aa_solid(ras, sl, renb,
                                   agg::rgba(0.0, 0.0, 0.0, 0.2));
    // (4)

    agg::render_ctrl(ras, sl, renb, m_join);
    agg::render_ctrl(ras, sl, renb, m_cap);
    agg::render_ctrl(ras, sl, renb, m_width);
    agg::render_ctrl(ras, sl, renb, m_miter_limit);
  }
Пример #7
0
void skeleton_mul::smoothEachBranch() {
	smoothedBrchPts.clear() ;
	smoothedBrchPts.resize(brchPts.size()) ;
	for( int i=0; i<brchPts.size(); ++i ){
		if( brchPts[i].size()< 4 ){
			while( brchPts[i].size() < 4 ){
				std::vector<Point3f> tmp ;
				for( int j=0; j< brchPts[i].size()-1; ++j ){
					tmp.push_back( brchPts[i][j] ) ;
					tmp.push_back( (brchPts[i][j]+brchPts[i][j+1])/2 ) ;

				}
				tmp.push_back( brchPts[i].back() ) ;

				brchPts[i] = tmp ;
			}
		}

		std::vector<double> x, y, z, t ;
		for( int j=0; j<brchPts[i].size(); ++j){
			x.push_back(brchPts[i][j].X() );
			y.push_back(brchPts[i][j].Y() );
			z.push_back(brchPts[i][j].Z() );
			t.push_back( (double)j/(brchPts[i].size()-1) ) ;
		}

		Spline3Interp poly1( t, x);
		poly1.calcCoefs();
		std::vector<double> px,py, pz ;
		for( double t=0.0; t<1.0; t+=0.0005 )
			px.push_back(poly1.evaluate(t)) ;
		px.push_back(poly1.evaluate(1.0)) ;


		Spline3Interp poly2( t, y);
		poly2.calcCoefs();
		for( double t=0.0; t<1.0; t+=0.0005 )
			py.push_back(poly2.evaluate(t)) ;
		py.push_back(poly2.evaluate(1.0)) ;

		Spline3Interp poly3( t, z);
		poly3.calcCoefs();
		for( double t=0.0; t<1.0; t+=0.0005 )
			pz.push_back(poly3.evaluate(t)) ;
		pz.push_back(poly3.evaluate(1.0)) ;

		for( int id=0; id<px.size(); ++id )
			smoothedBrchPts[i].push_back( Point3f(px[id], py[id], pz[id]) ) ;

	}

	for( int i=0; i<smoothedBrchPts.size() ; ++i ){
		for( int j=1; j<smoothedBrchPts[i].size()-1; ++j ){
			if( (smoothedBrchPts[i][j-1] - smoothedBrchPts[i][j]).Norm() < ReconstructorPara::branchSampleStep ){
				smoothedBrchPts[i].erase( smoothedBrchPts[i].begin()+j) ;
				j-- ;
			}

			if( (smoothedBrchPts[i][smoothedBrchPts[i].size()-1] - smoothedBrchPts[i][smoothedBrchPts[i].size()-2]).Norm() <   ReconstructorPara::branchSampleStep * 0.5)
					smoothedBrchPts[i].erase( smoothedBrchPts[i].begin()+smoothedBrchPts[i].size()-2) ;
		}
	}
}