Main Page   Data Structures   File List   Data Fields   Globals  

chain_code.c

Go to the documentation of this file.
00001 /* General support for chain code boundary representations
00002  *
00003  * $Id: chain_code.c,v 1.2 2003/02/11 03:35:21 mmunro Exp $
00004  */
00005 
00006 #include  <stdio.h>
00007 #include  <malloc.h>
00008 #include  "sadie.h"
00009 #include  "mosaic.h"
00010 #include  "chain.h"
00011 
00012 /*----------------------------------------------------------------------------*/
00013 /*-General Information--------------------------------------------------------*/
00014 /*                                                                            */
00015 /*   This function frees the memory block allocated for storing a chainmap.   */
00016 /*                                                                            */
00017 /*                                                                            */
00018 /*----------------------------------------------------------------------------*/
00019 /*-Interface Information------------------------------------------------------*/
00020 void RELMEM_CHAIN (
00021 CHAIN *chainmap      /*  I   Pointer to the chain map.                        */
00022 /*----------------------------------------------------------------------------*/
00023 ) {
00024     free(chainmap);
00025     chainmap = NULL;
00026 
00027     return;
00028 }
00029 
00030 
00031 /*----------------------------------------------------------------------------*/
00032 /*-General Information--------------------------------------------------------*/
00033 /*                                                                            */
00034 /*   This function computes the co-ordinates of a pixel in a chain given      */
00035 /*   its chain code and co-ordinates of the preceeding pixel.                 */
00036 /*                                                                            */
00037 /*----------------------------------------------------------------------------*/
00038 /*-Interface Information------------------------------------------------------*/
00039 void CHAIN_COMPUTE_COORDINATES(
00040 int prevx,          /*  I   Column coordinate of previous pixel.              */
00041 int prevy,          /*  I   Row coordinate of previous pixel.                 */
00042 unsigned char code, /*  I   Chain code for the current pixel.                 */
00043 int *currx,         /*  O   Pointer to the column coordinate of current pixel.*/   
00044 int *curry          /*  O   Pointer to the row coordinate of current pixel.   */
00045 /*----------------------------------------------------------------------------*/
00046 ) {
00047 
00048     
00049     switch (code) {
00050     case 0 :
00051         *curry = prevy - 1;
00052         *currx = prevx;
00053         break;
00054         
00055     case 1 :
00056         *curry = prevy - 1;
00057         *currx = prevx + 1;
00058         break;
00059         
00060     case 2 :
00061         *curry = prevy;
00062         *currx = prevx + 1;
00063         break;
00064         
00065     case 3 :
00066         *curry = prevy + 1;
00067         *currx = prevx + 1;
00068         break;
00069         
00070     case 4 :
00071         *curry = prevy + 1;
00072         *currx = prevx;
00073         break;
00074         
00075     case 5 :
00076         *curry = prevy + 1;
00077         *currx = prevx - 1;
00078         break;
00079         
00080     case 6 :
00081         *curry = prevy;
00082         *currx = prevx - 1;
00083         break;
00084         
00085     case 7 :
00086         *curry = prevy - 1;
00087         *currx = prevx - 1;
00088         break;
00089     }
00090 
00091     return;
00092 }
00093 
00094 
00095 /*----------------------------------------------------------------------------*/
00096 /*-General Information--------------------------------------------------------*/
00097 /*                                                                            */
00098 /*   This function computes the chain code of a pixel in a chain given        */
00099 /*   its co-ordinates and that of the preceeding pixel.                       */
00100 /*                                                                            */
00101 /*----------------------------------------------------------------------------*/
00102 /*-Interface Information------------------------------------------------------*/
00103 void CHAIN_COMPUTE_CODE (
00104 int currx,           /*  I   Row coordinate of the current pixel.             */
00105 int curry,           /*  I   Column coordinate of the current pixel.          */
00106 int x,               /*  I   Row coordinate of the next pixel.                */
00107 int y,               /*  I   Column coordinate of the next pixel.             */
00108 unsigned char *code  /*  O   Pointer to thechain code.                        */
00109 /*----------------------------------------------------------------------------*/
00110 ) {
00111 
00112     if (x == currx - 1 && y == curry - 1) {
00113         *code = 7;
00114     }
00115     else if (x == currx - 1 && y == curry) {
00116         *code = 0;
00117     }
00118     else if (x == currx - 1 && y == curry + 1) {
00119         *code = 1;
00120     }
00121     else if (x == currx && y == curry - 1) {
00122         *code = 6;
00123     }
00124     else if (x == currx && y == curry + 1) {
00125         *code = 2;
00126     }
00127     else if (x == currx + 1 && y == curry - 1) {
00128         *code = 5;
00129     }
00130     else if (x == currx + 1 && y == curry) {
00131         *code = 4;
00132     }
00133     else if (x == currx + 1 && y == curry + 1) {
00134         *code = 3;
00135    }
00136 
00137     return;
00138 }

Generated on Wed Apr 9 08:56:03 2003 for TREES by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002