예제 #1
0
	std::string print_points(const points_t& vals)
	{
		std::string ret;

		for(unsigned i=0;i<vals.size();i++)
		{
			char tmp[256];
			const npoint& p=vals[i];
			sprintf(tmp,"(%d,%d)",p.x,p.y);
			ret+=tmp;
			if(i+1!=vals.size())ret+=";";
		}
		return ret;
	}
예제 #2
0
파일: smooth.hpp 프로젝트: ybouret/yocto4
            inline void polynomial()
            {
                const size_t np = points.size();
                const size_t m  = min_of<size_t>(degree+1,np);

                //______________________________________________________________
                //
                // initialize parameters
                //______________________________________________________________
                mu.make(m);
                mu.ldz();
                coeff.make(m,0);
                typename points_t::iterator pp = points.begin();


                //______________________________________________________________
                //
                // accumulate
                //______________________________________________________________
                for(size_t i=np;i>0;--i,++pp)
                {
                    const point_t p = *pp;
                    for(size_t j=m,jm=m-1;j>0;--j,--jm)
                    {
                        const T   xjm  = ipower<T>(p.x,jm);
                        array<T> &mu_j = mu[j];

                        coeff[j]   += xjm * p.y;
                        for(size_t k=j,km=jm;k>0;--k,--km)
                        {
                            const T xkm = ipower<T>(p.x,km);
                            mu_j[k] += xkm*xjm;
                        }
                    }
                }

                //______________________________________________________________
                //
                // symetrisation
                //______________________________________________________________
                for(size_t j=m;j>0;--j)
                {
                    array<T> &mu_j = mu[j];
                    for(size_t k=j+1;k<=m;++k)
                    {
                        mu_j[k] = mu[k][j];
                    }
                }

                //______________________________________________________________
                //
                // compute parameters
                //______________________________________________________________
                if(!LU<T>::build(mu))
                {
                    throw libc::exception( EINVAL, "invalid data to smooth" );
                }
                LU<T>::solve(mu,coeff);
            }
	void points2bin(const points_t& pts,data_t& bin)
	{
		bin.resize(pts.size()*2);
		for(unsigned i=0;i<pts.size();i++)
		{
			const point& p=pts[i];
			if(p.x<=-128||p.x>127||p.y<=-128||p.y>127)
				throw std::runtime_error("points2bin(): invalid point: ("+
				boost::lexical_cast<std::string>(p.x)+","
				+boost::lexical_cast<std::string>(p.y)+")");

			char x=p.x;
			char y=p.y;

			bin[i*2]=*reinterpret_cast<const unsigned char*>(&x);
			bin[i*2+1]=*reinterpret_cast<const unsigned char*>(&y);
		}
	}
	void bin2points(const data_t& bin,points_t& pts)
	{
		if((bin.size()%2)!=0)
			throw std::runtime_error("bin2points(): (bin.size()%2)!=0");

		pts.resize(bin.size()/2);

		for(unsigned i=0;i<pts.size();i++)
		{
			point& p=pts[i];

			char x=*reinterpret_cast<const unsigned char*>(&bin[i*2]);
			char y=*reinterpret_cast<const unsigned char*>(&bin[i*2+1]);

			p.x=x;
			p.y=y;
		}
	}
예제 #5
0
파일: point.hpp 프로젝트: imclab/gladys
inline bool operator> (const points_t &v1, const points_t& v2) {
    return (v1.size() > v2.size() );
}