예제 #1
0
void CPMotion::OnLeftRight()
{
    short Velocity = 100;
    short Duration = 1;			//seconds
    short Iterations = 8;
    LeftRight(Velocity, Duration, Iterations);
}
예제 #2
0
파일: main.c 프로젝트: ISimion/DSA-lab
NodeT* insertNodeAVLtree(NodeT* root, int data)
{
    if(root==NULL)
        return createNodeT(data);
    else
    {
        if(root->data < data)
            root->right=insertNodeAVLtree(root->right, data);
        else
            root->left=insertNodeAVLtree(root->left, data);
    }

    root->height=maxx(height(root->left), height(root->right))+1;
    int aux=balanceFactor(root);

    if(aux>1)
    {
        if(root->left->data > data)//RR
            rightRotation(&root);
        else//LR
            LeftRight(&root);
    }
    else if(aux<-1)
    {
        if(root->right->data < data)//LL
            leftRotation(&root);
        else//RL
            RightLeft(&root);
    }
    //else
    return root;
}
예제 #3
0
int main(int argc, char* argv[]){
    if(argc != 3){
        printf("Useage: input_name output_name");
        exit(0);
    }
    
    char file_answer;
    
    printf("Select mode:\n"
           "1.bin to bmp\n"
           "2.bmp to bmp\n"
           "3.bin to bin\n");
    file_answer=getchar();
    fflush(stdin);
    
    char *Input=argv[1], *Output=argv[2];//retrive input/output name from commandline
    BmpHead *pBmpHeader = new BmpHead;
    unsigned char **pucImageData; 
    char *pcColorMap=NULL;
           
    if((file_answer == '1')||(file_answer == '3')){   //read bin file
        system("cls");
        
        //assign header information courtersy of Lena.bin
	    (*pBmpHeader).bfType=19778;
	    (*pBmpHeader).bfSize=54 + 1024+ 512*512 ; // raw data size = 512*512 = 262144 bytes, modify when necessary
	    (*pBmpHeader).bfReserved=0;
	    (*pBmpHeader).bfOffBits=1078;
	    (*pBmpHeader).biSize=40;
	    (*pBmpHeader).biWidth= 512;		//number of columns of the image
	    (*pBmpHeader).biHeight= 512;		//number of rows of the image
	    (*pBmpHeader).biPlanes=1;
	    (*pBmpHeader).biBitCount=8;
	    (*pBmpHeader).biCompression=0;
	    (*pBmpHeader).biSizeImage= 512*512;	//raw data size = 512*512 = 26144 bytes, modify when necessary, e.g., a 256x256 image: raw data size = 256*256
	    (*pBmpHeader).biXPelsPerMeter=2834;
	    (*pBmpHeader).biYpelsPerMeter=2834;
	    (*pBmpHeader).biClrUsed=0;
	    (*pBmpHeader).biClrImportant=0;
        
        //read provided colormap
        FILE *colormap=NULL;
        pcColorMap = new char [1024];
        if((colormap=fopen("colormap.bin", "rb")) == NULL){
            printf("Failed to find colormap.bin\n");
            exit(0);
        }
        fread(pcColorMap, sizeof(char), pBmpHeader->bfOffBits-64, colormap);
        fclose(colormap);
        
        //read raw data fron input
        pucImageData = ReadImage( Input, pBmpHeader->biWidth, 0);
        
        printf("successfully read raw data from %s.\n\n", Input);
    }
     
    else if(file_answer == '2'){  //read bmp file
        system("cls");
        
        //read input header infomation
        pBmpHeader=ReadBmpHeader(Input);
        printf("raw data size: %d\n", pBmpHeader->biSizeImage);
        printf("Image Width: %d\n", pBmpHeader->biWidth);
        printf("Image Height %d\n", pBmpHeader->biHeight);
	    printf("Header occupies 54 bytes\n");
        printf("Color map occupies 1024 bytes\n");	
        
        //read input colormap
        pcColorMap=ReadColorMap(Input, 1024);
        
        //read raw data from input
                                                    //set offset=1024+54
        pucImageData=ReadImage(Input, pBmpHeader->biWidth, 1078);
        printf("successfully read raw data from %s.\n\n", Input);
    }
    
    srand(time(NULL));//plant random seed
    
    //function menu
    char fx_answer;
    int width, cutoff;
    do{
        printf(
           "Select function:\n"
           "A.Turn Lena upside down\n"
           "B.Turn Lena around\n"
           "C.Rotate Lena by 45 deg clockwise\n"
           "D.Shrink Lena by half\n"
           "E.Invert Lena\n"
           "F.Add normal noise to Lena\n"
           "G.Add impluse noise to Lena\n"
           "H.Moving average filtering\n"
           "I.Midian filtering\n"
           "J.Differential flitering\n"
           "K.LPF\n"
           "L.HPF\n"
           "\n0.Exit\n");
        printf("Your choice: [_]\b\b");
        fx_answer = getchar();
        fx_answer = tolower(fx_answer);
        fflush(stdin);
        
        switch(fx_answer){//savefile(): ask user to save as picture or not
            case 'a':// selected: turn lena upside down
                UpsideDown(pucImageData, pBmpHeader->biWidth);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
            
            case 'b'://selected: turn lena around
                LeftRight(pucImageData, pBmpHeader->biWidth);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            case 'c'://selected: rotate lena
                ImgRotate(pucImageData, pBmpHeader->biWidth, 45);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
            
            case 'd'://selected: shrink lena
                Shrink(pucImageData, pBmpHeader->biWidth, pBmpHeader, 2);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            case 'e'://selected: invert lena
                Invert(pucImageData, pBmpHeader->biWidth);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            case 'f'://selected: add noise
                NormalNoise(pucImageData, pBmpHeader->biWidth);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            case 'g'://selected: add paper n salt noise
                ImpluseNoise(pucImageData, pBmpHeader->biWidth);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            case 'h'://selected: moving average filter
                //ask user to input sampling width
                printf("Enter sampling width:");
                scanf("%d", &width);
                fflush(stdin);
                MAF(pucImageData, pBmpHeader->biWidth, width);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            case 'i'://selected: moving midian filter
                //ask user to input sampling width
                printf("Enter sampling width:");
                scanf("%d", &width);
                fflush(stdin);
                MF(pucImageData, pBmpHeader->biWidth, width);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            case 'j'://selected: differential filter
                DIF(pucImageData, pBmpHeader->biWidth);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            case 'k'://selected: low-pass filter
                //ask user to input cutoff frequency
                printf("Enter cutoff frenquency(0~%d):", (int)pBmpHeader->biWidth/2);
                scanf("%d", &cutoff);
                fflush(stdin);
                LPF(pucImageData, pBmpHeader->biWidth, cutoff);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            case 'l'://selected: high-pass filter
                //ask user to input cutoff frequency
                printf("Enter cutoff frenquency(0~%d):", (int)pBmpHeader->biWidth/2);
                scanf("%d", &cutoff);
                fflush(stdin);
                HPF(pucImageData, pBmpHeader->biWidth, cutoff);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            case '0'://selected: exit
                //ask one last time whether user want to save or not
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            default:
                system("cls");
                printf("Your choice is not in the list!\n");
                break;
            
        }
        
        if(fx_answer == 0)
            break;//selected: exit. break the loop
        
        
    } while(fx_answer != '0');
    
    //returning dynamic allocated memory
    delete [] pcColorMap;
    delete [] pucImageData;
    delete pBmpHeader;
    pcColorMap=NULL;
    pucImageData=NULL;
    pBmpHeader=NULL;
    
    printf("EOP\n");
}
예제 #4
0
파일: avl.c 프로젝트: jarun/dslib
/*
 * Delete a node from AVL tree
 * Recursive method
 */
bool delete_avl_node(avl_pp head, int val)
{
	avl_p node;
	avl_p tmp;

	if (!head) {
		log(ERROR, "Initialize AVL tree first\n");
		return FALSE;
	}

	node = *head;
	if (!node) {
		log(ERROR, "No nodes to delete\n");
		return FALSE;
	}

	if (val > node->data) {
		if (!node->right)
			return FALSE;

		if (delete_avl_node(&(node->right), val) == FALSE)
			return FALSE;

		if (BalanceFactor(node) == 2) {
			if (BalanceFactor(node->left) >= 0)
				node = LeftLeft(node);
			else
				node = LeftRight(node);
		}
	} else if (val < node->data) {
		if (!node->left)
			return FALSE;

		if (delete_avl_node(&(node->left), val) == FALSE)
			return FALSE;

		if (BalanceFactor(node) == -2) {
			if (BalanceFactor(node->right) <= 0)
				node = RightRight(node);
			else
				node = RightLeft(node);
		}
	} else { /* Match found */
		if (node->right) {  /* Delete the inorder successor */
			tmp = node->right;
			while (tmp->left)
				tmp = tmp->left;

			node->data = tmp->data;
			if (delete_avl_node(&(node->right), tmp->data) == FALSE)
				return FALSE;

			if (BalanceFactor(node) == 2) {
				if (BalanceFactor(node->left) >= 0)
					node = LeftLeft(node);
				else
					node = LeftRight(node);
			}
		} else {
			*head = node->left;
			return TRUE;
		}
	}

	node->height = height(node);
	*head = node;
	return TRUE;
}
예제 #5
0
파일: avl.c 프로젝트: jarun/dslib
/*
 * Rebalance subtree tmp based on balance factor & skew
 */
bool rebalance(stack_p stack, avl_pp head, avl_p tmp, int data)
{
	nodedata_p p = NULL;
	int direction;
	avl_p parent = NULL;
	bool modified = TRUE;

	if (BalanceFactor(tmp) == -2) { /* Right subtree longer */
		p = pop(stack);
		if (p) {
			parent = p->node;
			direction = p->direction;
		}

		if (data >= tmp->right->data) { /* Right-right skewed subtree */
			if (p)
				direction == RIGHT
					?  (parent->right = RightRight(tmp))
					: (parent->left = RightRight(tmp));
			else /* If p is NULL, this is the topmost node, update *head */
				*head = RightRight(tmp);
		} else { /* Right-left skewed subtree */
			if (p)
				direction == RIGHT
					? (parent->right = RightLeft(tmp))
					: (parent->left = RightLeft(tmp));
			else
				*head = RightLeft(tmp);
		}
	} else if (BalanceFactor(tmp) == 2) { /* Left subtree longer */
		p = pop(stack);
		if (p) {
			parent = p->node;
			direction = p->direction;
		}
		/* If p is NULL, this is the topmost node, update *head */

		if (data < tmp->left->data) { /* Left-left skewed subtree */
			if (p)
				direction == RIGHT
					? (parent->right = LeftLeft(tmp))
					: (parent->left = LeftLeft(tmp));
			else
				*head = LeftLeft(tmp);
		} else { /* Left-right skewed subtree */
			if (p)
				direction == RIGHT
					? (parent->right = LeftRight(tmp))
					: (parent->left = LeftRight(tmp));
			else
				*head = LeftRight(tmp);
		}
	} else
		modified = FALSE;

	if (p)
		free(p);

	tmp->height = height(tmp);

	return modified;
}