con1.c
Upload User: shhuayu888
Upload Date: 2013-03-28
Package Size: 1788k
Code Size: 5k
Category:

Windows Develop

Development Platform:

Unix_Linux

  1. /****************************************************************************
  2.  File Name  : con1.c
  3.  Purpose    : 1 Initializing of open and closed contour
  4.         2. Display of contour
  5.         3. Internal energy calculation
  6.  Date     : Aug 31,1995
  7. GSNAKE API is jointly developed by the Information Technology Institute (ITI), Singapore, and the School of Applied Science, Nanyang Technological
  8. University (NTU), Singapore. 
  9. These software programs are available to the user without any license or royalty fees. Permission is hereby granted to use, copy, modify, and distribute this software and its documentation for any purpose. ITI and NTU gives no warranty, express, implied, or statuary for the software and/or documentation provided, including, without limitation, waranty of merchantibility and warranty of fitness for a particular purpose. The software provided hereunder is on an "as is"  basis, and ITI and NTU has no obligation to provide maintenance, support, updates, enhancements, or modifications.
  10. GSNAKE API is available for any UNIX compatible system. User feedback, bugs, or software and manual suggestions should be sent via electronic mail to one of the following, who may or may not act on them as he/she desires :
  11. asschan@ntu.ac.sg
  12. kflai@iti.gov.sg
  13. ***************************************************************************/
  14. #include "gsnake.h"
  15. #include "xwindow.h"
  16. void testmain(SNAKEMODE , int , int , int , int,double, short, int  );
  17. void printhelp();
  18. void getparam(int ac, char** av, int *Mfactor,SNAKEMODE *smode,short *Numpt,
  19.       int *sx, int *sy, int *ex, int *ey, double *radius);
  20. main(int argc,char **argv)
  21. {
  22. int magnify = 1;
  23. SNAKEMODE mode = _CLOSED;
  24. short numpoint = 8;
  25. int sx,sy,ex,ey;
  26. double rad = 15.0;
  27.         sx=50;
  28.         sy = 50;
  29. ex = 80; 
  30. ey = 80;
  31. if (argc==1) printhelp();
  32. else {
  33. getparam(argc,argv,&magnify,&mode,&numpoint,&sx,&sy,
  34.  &ex,&ey, &rad);
  35. printf("%d %d %d",sx,sy,numpoint);
  36. testmain(mode, sx,sy,ex,ey,rad,numpoint,magnify);
  37. return(0);
  38. }
  39. }
  40. void testmain( SNAKEMODE smode, /* snake mode */
  41.        int Sx, int Sy,  /* starting point of a line */
  42.        int Ex, int Ey, /* ending point of a line */
  43.        double Radius, /* radius of circle */
  44.        short num_points, /* number of snaxels */
  45.        int mag ) /* magnification factor */
  46. {
  47. CONTOUR mycontour; /* CONTOUR object */
  48. SNAXEL *sptr; /* SNAXEL objcet */
  49. register short i = 0;
  50. /* Initialize an arbitrary close snake */
  51. if (smode == _CLOSED)
  52. mycontour.init(Sy, Sx, Radius, num_points);
  53. else
  54. mycontour.init(Sx, Sy, Ex, Ey, num_points);
  55. /* The average length of snaxel must be calculated first. */
  56. mycontour.computeAvgLength(); 
  57. printf("nContour information : n");
  58. mycontour.print();
  59. printf("nPress enter to display contour.");
  60. getchar();
  61. mycontour.display(mag); 
  62. /* Internal energy of snake without deformation should be 0 */
  63. printf("nInternal energy.");
  64. for(sptr=mycontour.getHead(); sptr; sptr=sptr->getNext(), i++)
  65. printf("nEmodel of snaxel %d = %f",
  66. i, mycontour.EInternal(sptr));
  67. printf("nPress enter to continue");
  68. getchar();
  69. printf("nEnd of test.n");
  70. }
  71. void getparam(int ac, char** av, int *Mfactor,SNAKEMODE *smode,short *Numpt,
  72.       int *sx, int *sy, int *ex, int *ey, double *radius)
  73. {   
  74. register int i;
  75. char *inputstr;
  76. for (i=1; i<ac; i++) 
  77. {
  78. if( *av[i] != '-' )
  79. continue; /* illegal input */
  80. inputstr = av[i]+2;
  81. switch( *(av[i]+1) ) {
  82.  
  83.    case 'm' :
  84. inputstr=av[i]+3;
  85. switch (*(av[i]+2)) {
  86.    case 'c': *smode = _CLOSED; break;
  87.    case 'o': *smode = _OPENED;break;
  88. }
  89. break;
  90.       case 'U' :
  91. inputstr=av[i]+3;
  92. switch (*(av[i]+2)) {
  93.    case 'x': *sx = atoi(inputstr); break;
  94.    case 'y': *sy = atoi(inputstr);break;
  95. }
  96. break;
  97.   case 'V' :
  98. inputstr=av[i]+3;
  99. switch (*(av[i]+2)) {
  100.    case 'x': *ex = atoi(inputstr); break;
  101.    case 'y': *ey = atoi(inputstr);break;
  102. }
  103. break;
  104.    case 'M' :
  105. *Mfactor=atoi(inputstr);
  106. break;
  107.    case 'N' :
  108.    *Numpt=atoi(inputstr);
  109. break;
  110.    case 'R' :
  111. *radius=atof(inputstr);
  112. break;   
  113.     default: break;
  114. }
  115. }
  116. }
  117. void printhelp()
  118. {
  119. printf("nnInitialization of arbitrary contour");
  120. printf("n Usage :OOcon1 [ option ]");
  121. printf("n [ option ]");
  122. printf("n -m/o/c :Gsnake mode ( o-opened / c-closed )");
  123. printf("n -M     :Magnification factor, default 1 ");
  124. printf("n -N     :Number of snaxels, default 8");
  125. printf("n -U     :Starting point of a line or centre of a circle,");
  126. printf("n        :Default x = 50, y = 50");
  127. printf("n -V     :Ending point of a line");
  128. printf("n        :Default x = 80, y = 80");
  129. printf("n -R     :Radius of a circle, default 15.0nn");
  130. }