Exemplo n.º 1
0
//--------------------------------------------------------------
void testApp::draw(){
    ofPushMatrix();
    ofTranslate(50, 50);
    // a - zigzag
    for (int i=0; i<10; i++) {

        zigzag(60*i);
    }
    ofPopMatrix();
    
    
    // circle
    float posX = ofGetWidth()/2;
    float posY = ofGetHeight()/2;
    
    float newX1 = posX + cos(ofGetElapsedTimef()) * 150;
    float newY1 = posY + sin(ofGetElapsedTimef()) * 150;
    float newX2 = posX + cos(angle) * 350;
    float newY2 = posY + sin(angle) * 350;

    
    ofSetColor(130, 150, 50, 50);
    ofLine(newX1, newY1, newX2, newY2);
    
}
Exemplo n.º 2
0
void splay(node *p)
{
    while (p->p != NULL) {
        reverse(p->p->p);
        reverse(p->p);
        reverse(p);
        if (p->p->p == NULL) {
            if (p == p->p->l) {
                zig(p);
            }
            else {
                zag(p);
            }
        }
        else if (p->p == p->p->p->l) {
            if (p == p->p->l) {
                zigzig(p);
            }
            else {
                zagzig(p);
            }
        }
        else {
            if (p == p->p->l) {
                zigzag(p);
            }
            else {
                zagzag(p);
            }
        }
    }
}
Exemplo n.º 3
0
int main(){
	struct node *root = NULL;
	add(&root,4);
	add(&root,1);
	add(&root,3);
	add(&root,7);
	add(&root,9);
	add(&root,5);
	add(&root,8);
	add(&root,2);
	add(&root,6);
 
        struct node *b = NULL;
	add(&b,1);
	add(&b,2);
	add(&b,3);
	add(&b,4);
	add(&b,5);
	add(&b,6);
	add(&b,7);
	add(&b,8);
	add(&b,9);

	printf("\n\n Compare trees for similarity: %s \n\n", isSimilar(root,b) ? "true": "false");
	
        printf("\n\ninorder:");
        inorder(root);
//        printf("\nPREORDER: \n");
//	preorderStack(root);
	printf("\nPOSTORDER: \n");
	postOrderStack(root);
	struct node *lca_6_8 = commonAncestor(root,find(root,8),find(root,6));
	printf("\n\nleast common ancestor: 6,8: %d\n", lca_6_8->data);

	struct node *lca_2_8 = commonAncestor(root,find(root,8),find(root,2));
	printf("\n\nleast common ancestor: 2,8: %d\n", lca_2_8->data);

	struct node *lca_6_7 = commonAncestor(root,find(root,7),find(root,6));
	printf("\n\nleast common ancestor: 6,7: %d\n", lca_6_7->data);
        
        int distance_6_8 = distance(root,find(root,8),find(root,6));
	printf("\n\ndistance: 6,8: %d\n", distance_6_8);

	int distance_2_8 = distance(root,find(root,8),find(root,2));
	printf("\n\ndistance: 2,8: %d\n", distance_2_8);

	int distance_6_7 = distance(root,find(root,7),find(root,6));
	printf("\n\ndistance: 6,7: %d\n", distance_6_7);
        
        printf("\n\nzigazag:");
        zigzag(root);  
        printf("\n\n");
}
Exemplo n.º 4
0
Arquivo: varint.c Projeto: 01BTC10/pbc
int 
main()
{
	encode(300);
	uint8_t buffer[10] = { 0xac, 0x2 };
	decode(buffer);
	encode(0xfffffffffLL);
	uint8_t buffer2[10] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0x1 };
	decode(buffer2);

	zigzag(-0x1234567890LL);

	return 0;
}
Exemplo n.º 5
0
void CArea::MakePocketToolpath(std::list<CCurve> &curve_list, const CAreaPocketParams &params)const
{
	double radians_angle = params.zig_angle * PI / 180;
	sin_angle_for_zigs = sin(-radians_angle);
	cos_angle_for_zigs = cos(-radians_angle);
	sin_minus_angle_for_zigs = sin(radians_angle);
	cos_minus_angle_for_zigs = cos(radians_angle);
	stepover_for_pocket = params.stepover;

	CArea a_offset = *this;
	double current_offset = params.tool_radius + params.extra_offset;

	a_offset.Offset(current_offset);

	if(params.mode == ZigZagPocketMode || params.mode == ZigZagThenSingleOffsetPocketMode)
	{
		curve_list_for_zigs = &curve_list;
		zigzag(a_offset);
	}
	else if(params.mode == SpiralPocketMode)
	{
		std::list<CArea> m_areas;
		a_offset.Split(m_areas);
		if(CArea::m_please_abort)return;
		if(m_areas.size() == 0)
		{
			CArea::m_processing_done += CArea::m_single_area_processing_length;
			return;
		}

		CArea::m_single_area_processing_length /= m_areas.size();

		for(std::list<CArea>::iterator It = m_areas.begin(); It != m_areas.end(); It++)
		{
			CArea &a2 = *It;
			a2.MakeOnePocketCurve(curve_list, params);
		}
	}

	if(params.mode == SingleOffsetPocketMode || params.mode == ZigZagThenSingleOffsetPocketMode)
	{
		// add the single offset too
		for(std::list<CCurve>::iterator It = a_offset.m_curves.begin(); It != a_offset.m_curves.end(); It++)
		{
			CCurve& curve = *It;
			curve_list.push_back(curve);
		}
	}
}
Exemplo n.º 6
0
//Assumes *handp_loc is not NULL
void splay(struct hand **handp_loc, int needle)
{

    struct hand *hand = *handp_loc;
    while (needle != hand->card.rank)
    {
        struct hand *side;
        int factor = 1;
        if (needle < hand->card.rank)
        {
            side = hand->left;
        }
        else
        {
            side = hand->right;
            factor = -1;
        }
        if (!side)
        {
            //target does not exist, stop
            break;
        }
        else if (factor * (needle - side->card.rank)>0)
        {
            //Target is an inner node
            if(zigzag(&hand, side))
            {
                continue;
            }
            else
            {
                //could not complete a zigzag, target does not exist
                break;
            }
        }
        else
        {
            //Target is on the outside
            zig(&hand, side);
            continue;
        }
    }
    *handp_loc = hand;
}
Exemplo n.º 7
0
main()
    {
    
        struct BT *rt=nn(4);
        rt->l=nn(5);
        rt->r=nn(89);
        rt->l->r=nn(77);
        rt->l->l=nn(55);
        rt->r->r=nn(44);
        rt->r->l=nn(22);
        rt->l->l->l=nn(30);
        rt->l->l->r=nn(43);
        int i,b=0;
        for(i=0;i<4;i++)
            {
             zigzagr(rt,i,b); 
             printf("\n\n");
             b=~b;
            }
            
       printf("\n\n\n\n");
       
       zigzag(rt);  
       
       printf("\n\n");
       
       if(hassumproperty(rt))
            printf("it has children sum property\n\n");
        else
            printf("it has no childeren sum  property\n\n");  
            
      // convert(rt);   
       
            if(hassumproperty(rt))
            printf("it has children sum property\n\n");
        else
            printf("it has no childeren sum  property\n\n"); 
           int p=0; 
           int d= diameter(rt,&p);
           printf("Diameter %d\n",d);
                  
    }      
Exemplo n.º 8
0
static void test_8x8(void)
{
    int vector[8*8];
    int matrix[8][8] =
    {
        {  1,  2,  6,  7, 15, 16, 28, 29 },
        {  3,  5,  8, 14, 17, 27, 30, 43 },
        {  4,  9, 13, 18, 26, 31, 42, 44 },
        { 10, 12, 19, 25, 32, 41, 45, 54 },
        { 11, 20, 24, 33, 40, 46, 53, 55 },
        { 21, 23, 34, 39, 47, 52, 56, 61 },
        { 22, 35, 38, 48, 51, 57, 60, 62 },
        { 36, 37, 49, 50, 58, 59, 63, 64 },
    };

    printf("\nTest 8x8\n\n");
    print_info(8, 8);
    dump_matrix("Matrix", 8, 8, matrix);
    zigzag(8, 8, matrix, vector);
    dump_vector("Vector", 8, 8, vector);
}
Exemplo n.º 9
0
/*
 * Segment needs to bend
 */
void StraightConstraint::satisfy() {
    FILE_LOG(logDEBUG)<<"StraightConstraint::satisfy():";
    Edge* e = segment->edge;
    EdgePoint* start = segment->start,
             * end = segment->end,
             * bend = new EdgePoint(node,ri);
    FILE_LOG(logDEBUG1)<<"  u=("<<start->node->id<<":"<<start->rectIntersect<<"), v=("<<node->id<<":"<<ri<<"), w=("<<end->node->id<<":"<<end->rectIntersect<<")";
    COLA_ASSERT(!zigzag(bend,end->outSegment));
    COLA_ASSERT(!zagzig(bend,start->inSegment));
    // shouldn't have straight constraints between end segments and the
    // nodes to which they are connected.
    COLA_ASSERT(!segment->connectedToNode(node));
    
    Segment* s1 = new Segment(e,start,bend);
    Segment* s2 = new Segment(e,bend,end);
    if(e->firstSegment==segment) {
        e->firstSegment=s1;
    }
    if(e->lastSegment==segment) {
        e->lastSegment=s2;
    }
    // create BendConstraint to replace this StraightConstraint
    bend->createBendConstraint(scanDim);

    // transfer other StraightConstraint constraints 
    // from s to s1 or s2 depending on which side of p they are on.
    transferStraightConstraintChoose transfer(s1,s2,this);
    segment->forEachStraightConstraint(transfer);
    // BendConstraint constraints associated with segment->end and 
    // segment->start need to be updated
    start->createBendConstraint(scanDim);
    end->createBendConstraint(scanDim);
             
    e->nSegments++;
    delete segment;
}
Exemplo n.º 10
0
static void test_9x6(void)
{
    enum { rows = 9 };
    enum { cols = 6 };
    int vector[rows * cols];
    int matrix[rows][cols] =
    {
        {  1,  2,  6,  7, 15, 16, },
        {  3,  5,  8, 14, 17, 27, },
        {  4,  9, 13, 18, 26, 28, },
        { 10, 12, 19, 25, 29, 39, },
        { 11, 20, 24, 30, 38, 40, },
        { 21, 23, 31, 37, 41, 48, },
        { 22, 32, 36, 42, 47, 49, },
        { 33, 35, 43, 46, 50, 53, },
        { 34, 44, 45, 51, 52, 54, },
    };

    printf("\nTest 9x6\n\n");
    print_info(rows, cols);
    dump_matrix("Matrix", rows, cols, matrix);
    zigzag(rows, cols, matrix, vector);
    dump_vector("Vector", rows, cols, vector);
}
Exemplo n.º 11
0
int main() {
	unsigned int iter;
	int dctin[64];
	int dctout[64];
	int quantizeout[64];
	int zigzagout[64];

        // preallocate memory for global variable
        unsigned char ScanBuffer[IMG_HEIGHT_MDU*8][IMG_WIDTH_MDU*8];


	ReadBmp(ScanBuffer);

	for (iter = 0; iter < IMG_BLOCKS; iter++)
	{
		readblock(ScanBuffer, dctin);
		dct(dctin, dctout);
		quantize(dctout,quantizeout);
		zigzag(quantizeout, zigzagout);
		huffencode(zigzagout);
	}

	return 0;
}
    string convert(string s, int numRows) {
        vector<string> zigzag(numRows);
        int k = 0;
        if (numRows>2)
            k = numRows + numRows - 2;
        else
            k = numRows;

        for (int i = 0; i<s.length(); i++) {
            // map the index to output
            // we have a diagonal
            int index = i%k;
            if (index >= numRows)
                zigzag[k - index] += s[i];
            // we don't have a diagonal
            else
                zigzag[index] += s[i];
        }

        string zigzag_final;
        for (int i = 0; i<numRows; i++)
            zigzag_final += zigzag[i];
        return zigzag_final;
    }
Exemplo n.º 13
0
int main()
{
        struct body_s *bod, *out;
        struct buf_s *buf;
        int n = 0,i=0;
        ssize_t len = 0;
        uint16_t cmdid = 0;
        int32_t num=-16;
        struct darray_s *da;
        struct head_s *head;
        
        bod = (struct body_s*)calloc(PACKET_SIZE, sizeof(struct body_s));
        out = (struct body_s*)calloc(1, sizeof(struct body_s));

        printf("boy size:%d\n", sizeof(struct body_s));
        
        printf("num:%lld, zigzag:%lld\n", (int64_t)num, zigzag((int64_t)num));

        head = (struct head_s*)calloc(1, sizeof(struct head_s)); 
        if (head == NULL) return 0;
        
        head->cmdid = 0xF001;
        head->seq = 0x10001;
        head->uid = 0x1000;
        head->aid = 0x0001;

        buf = buf_calloc(1024);
        len = enpacket(head, (u_char*)NULL, 0, 0, NULL, 0, buf);
        printf("packet buf:%p, len:%d\n", buf->buf_pos, (int)buf->buf_len); 
        hexdump((u_char *)buf->buf_pos, buf->buf_len);        
        
        memset(head, 0, sizeof(struct head_s));
        len = dehead(buf, head);
        if (len==-1) {
                printf("errno:%d, errstr:%s\n", errno, strerror(errno));
                exit(1);
        }
        printf("cmdid:%x\n", head->cmdid); 
        switch (head->cmdid){
        case 0xF001:
                //out->a17 = (u_char*)calloc(1,10);
                da = darray_calloc(1, sizeof(*bod));
                
                if (depacket_da(buf, NULL, 0, da) == -1)
                        perror("ERR DEBODY\n");

                printf("da used %d\n",da->da_used);
                body_handler(head, (struct body_s*)da->da_values);

                darray_free(da);
                break;
        default:
                break;
        }
        
        free(bod);
        free(out);

        free(head);
        buf_free(buf);
        
        


}
Exemplo n.º 14
0
int main(int /*argc*/, char** /*argv*/) {

	std::cout.setf(std::ios_base::fixed, std::ios_base::floatfield);
	std::cout.precision(2);

    try {
        const std::vector<std::string> vsTestImagePaths = {
            {"data/airplane.png"},
            {"data/baboon.png"},
			{ "data/cameraman.tif" },
			{ "data/lena.png" },
            {"data/logo.tif"},
			{ "data/logo_noise.tif" },
            {"data/peppers.png"},
        };
        for(const std::string& sTestImagePath : vsTestImagePaths) {
            const cv::Mat oInput = cv::imread(sTestImagePath);
            if(oInput.empty() || oInput.type()!=CV_8UC3)
                CV_Error_(-1,("Could not load image at '%s', check local paths",sTestImagePath.c_str()));

			std::cout << "\n ***************************************** \n\n";

            // COMPRESSION
            cv::Mat_<uchar> Y,Cb,Cr;
            conv_rgb2ycbcr(oInput,USE_SUBSAMPLING,Y,Cb,Cr);
            const std::vector<cv::Mat_<uchar>> vBlocks_Y = decoup(Y);
            const std::vector<cv::Mat_<uchar>> vBlocks_Cb = decoup(Cb);
            const std::vector<cv::Mat_<uchar>> vBlocks_Cr = decoup(Cr);

			/* Test de-conversion */
			cv::Mat image_unconvert;
			conv_ycbcr2rgb(Y, Cb, Cr, USE_SUBSAMPLING, image_unconvert);
			cv::Mat diff;
			cv::absdiff(oInput, image_unconvert, diff);


            std::vector<cv::Mat_<uchar>> vBlocks;
            vBlocks.insert(vBlocks.end(),vBlocks_Y.begin(),vBlocks_Y.end());
            vBlocks.insert(vBlocks.end(),vBlocks_Cb.begin(),vBlocks_Cb.end());
            vBlocks.insert(vBlocks.end(),vBlocks_Cr.begin(),vBlocks_Cr.end());
            std::vector<cv::Mat_<float>> vDCTBlocks(vBlocks.size());

			/* Test block - unblock*/
			//const cv::Mat_<uchar> test = decoup_inv(vBlocks, Y.size());

			for (size_t b = 0; b < vBlocks.size(); ++b)
			{
				vDCTBlocks[b] = dct(vBlocks[b]);

				/* Test i_dct*/
				cv::Mat_<uchar> original = vBlocks[b];
				cv::Mat_<float> dct = vDCTBlocks[b];
				cv::Mat_<uchar> inverse = dct_inv(vDCTBlocks[b]);			
			}
			
			// Quantification
            std::vector<cv::Mat_<short>> vQuantifDCTBlocks(vDCTBlocks.size());
            for(size_t b=0; b<vDCTBlocks.size(); ++b)
                vQuantifDCTBlocks[b] = quantif(vDCTBlocks[b],USE_QUANT_QUALITY);

            std::vector<std::array<short,8*8>> vInlinedBlocks(vQuantifDCTBlocks.size());
			for (size_t b = 0; b < vQuantifDCTBlocks.size(); ++b)
			{
				vInlinedBlocks[b] = zigzag(vQuantifDCTBlocks[b]);

				// Test zigzag ...
				/*
				cv::Mat_<short> original = vQuantifDCTBlocks[b];
				std::array<short, 8 * 8> arr = vInlinedBlocks[b];
				cv::Mat_<short> inverse = zigzag_inv(vInlinedBlocks[b]);
				*/
			}
                
            const HuffOutput<short> oCode = huff(vInlinedBlocks);

            // @@@@ TODO: check compression rate here...
			cv::Size s = oInput.size();
			int nbPixel = s.height * s.width;

			// Size in bits

			double size_before = 8 * nbPixel * oInput.channels();
			double size_after_color = 8 * (Y.size().area() + Cb.size().area() + Cr.size().area());
			double size_after_dct = 8 * 8 * 8 * vInlinedBlocks.size();
			double size_after_pipeline= oCode.string.size();

			double compressionRate_after_color = 1 - (size_after_color / size_before);
			double compressionRate_after_dct = 1 - (size_after_dct / size_after_color);
			double compressionRate_afer_pipeline = 1 - (size_after_pipeline / size_before);

			/*
			double compressionRate_after_color = size_before / size_after_color;
			double compressionRate_after_dct = size_after_color / size_after_dct;
			double compressionRate_afer_pipeline = size_before /size_after_pipeline;
			*/

			std::cout << "Images: " << sTestImagePath << "\n";

			std::cout << "Size before color   : " << size_before/ (1000.0 * 8.0) << " ko\n";
			std::cout << "Size after color    : " << size_after_color/ (1000.0 * 8.0) << " ko\n";
			std::cout << "Size after dct      : " << size_after_dct/ (1000.0 * 8.0) << " ko\n";
			std::cout << "Size after pipeline : " << size_after_pipeline/ (1000.0 * 8.0) << " ko\n";
			
			std::cout << "Compression rate couleur seulement   : " << compressionRate_after_color << "%\n";
			std::cout << "Compression rate dct(+q+z) seulement : " << compressionRate_after_dct << "%\n";
			std::cout << "Compression rate fin pipeline        : " << compressionRate_afer_pipeline << "%\n";

            // DECOMPRESSION
            const std::vector<std::array<short,8*8>> vInlinedBlocks_decompr = huff_inv<8*8>(oCode);


			// Comment to test dct
            std::vector<cv::Mat_<short>> vQuantifDCTBlocks_decompr(vInlinedBlocks_decompr.size());
            for(size_t b=0; b<vInlinedBlocks_decompr.size(); ++b)
                vQuantifDCTBlocks_decompr[b] = zigzag_inv(vInlinedBlocks_decompr[b]);

			// Uncomment to test dct
			//std::vector<cv::Mat_<short>> vQuantifDCTBlocks_decompr(vInlinedBlocks.size());
			//for (size_t b = 0; b<vInlinedBlocks.size(); ++b)
			//	vQuantifDCTBlocks_decompr[b] = zigzag_inv(vInlinedBlocks[b]);
			
			// Comment to test dct
            std::vector<cv::Mat_<float>> vDCTBlocks_decompr(vQuantifDCTBlocks_decompr.size());
            for(size_t b=0; b<vQuantifDCTBlocks_decompr.size(); ++b)
                vDCTBlocks_decompr[b] = quantif_inv(vQuantifDCTBlocks_decompr[b],USE_QUANT_QUALITY);

			// Uncomment to test dct
			//std::vector<cv::Mat_<float>> vDCTBlocks_decompr(vQuantifDCTBlocks_decompr.size());
			//for (size_t b = 0; b<vQuantifDCTBlocks_decompr.size(); ++b)
			//	vDCTBlocks_decompr[b] = quantif_inv(vQuantifDCTBlocks_decompr[b], USE_QUANT_QUALITY);

			// Commment to test quantification
            std::vector<cv::Mat_<uchar>> vBlocks_decompr(vDCTBlocks_decompr.size());
			for (size_t b = 0; b<vDCTBlocks_decompr.size(); ++b)
				vBlocks_decompr[b] = dct_inv(vDCTBlocks_decompr[b]);

			// Uncomment to test quantification inverse
			//std::vector<cv::Mat_<uchar>> vBlocks_decompr(vDCTBlocks.size());
   //         for(size_t b=0; b<vDCTBlocks.size(); ++b)
   //             vBlocks_decompr[b] = dct_inv(vDCTBlocks[b]);

            const std::vector<cv::Mat_<uchar>> vBlocks_Y_decompr(vBlocks_decompr.begin(),vBlocks_decompr.begin()+vBlocks_Y.size());
            const std::vector<cv::Mat_<uchar>> vBlocks_Cb_decompr(vBlocks_decompr.begin()+vBlocks_Y.size(),vBlocks_decompr.begin()+vBlocks_Y.size()+vBlocks_Cb.size());
            const std::vector<cv::Mat_<uchar>> vBlocks_Cr_decompr(vBlocks_decompr.begin()+vBlocks_Y.size()+vBlocks_Cb.size(),vBlocks_decompr.end());
            const cv::Mat_<uchar> Y_decompr = decoup_inv(vBlocks_Y_decompr,Y.size());
            const cv::Mat_<uchar> Cb_decompr = decoup_inv(vBlocks_Cb_decompr,Cb.size());
            const cv::Mat_<uchar> Cr_decompr = decoup_inv(vBlocks_Cr_decompr,Cr.size());
            cv::Mat oInput_decompr;
            conv_ycbcr2rgb(Y_decompr,Cb_decompr,Cr_decompr,USE_SUBSAMPLING,oInput_decompr);

            cv::Mat oDisplay;
            cv::hconcat(oInput,oInput_decompr,oDisplay);
            cv::Mat oDiff;
            cv::absdiff(oInput,oInput_decompr,oDiff);
            cv::hconcat(oDisplay,oDiff,oDisplay);
            cv::imshow(sTestImagePath.substr(sTestImagePath.find_last_of("/\\")+1),oDisplay);
            cv::waitKey(1);
        }
        std::cout << "all done; press any key on a window to quit..." << std::endl;
        cv::waitKey(0);
        return 0;
    }
    catch(const cv::Exception& e) {
        std::cerr << "Caught cv::Exceptions: " << e.what() << std::endl;
    }
    catch(const std::runtime_error& e) {
        std::cerr << "Caught std::runtime_error: " << e.what() << std::endl;
    }
    catch(...) {
        std::cerr << "Caught unhandled exception." << std::endl;
    }
    return 1;
}