home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / m / morpho.zip / morpho / src / vgmtophat / vgmtophat.c < prev    next >
C/C++ Source or Header  |  1992-07-28  |  9KB  |  395 lines

  1.  /*
  2.   * Khoros: $Id$
  3.   */
  4.  
  5. #if !defined(lint) && !defined(SABER)
  6. static char rcsid[] = "Khoros: $Id$";
  7. #endif
  8.  
  9.  /*
  10.   * $Log$
  11.   */
  12.  
  13. /*
  14.  *----------------------------------------------------------------------
  15.  *
  16.  * Copyright 1992, University of New Mexico.  All rights reserved.
  17.  * Permission to copy and modify this software and its documen-
  18.  * tation only for internal use in your organization is hereby
  19.  * granted, provided that this notice is retained thereon and
  20.  * on all copies.  UNM makes no representations as to the sui-
  21.  * tability and operability of this software for any purpose.
  22.  * It is provided "as is" without express or implied warranty.
  23.  * 
  24.  * UNM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  25.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
  26.  * NESS.  IN NO EVENT SHALL UNM BE LIABLE FOR ANY SPECIAL,
  27.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY OTHER DAMAGES WHAT-
  28.  * SOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  29.  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  30.  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PER-
  31.  * FORMANCE OF THIS SOFTWARE.
  32.  * 
  33.  * No other rights, including, for example, the right to redis-
  34.  * tribute this software and its documentation or the right to
  35.  * prepare derivative works, are granted unless specifically
  36.  * provided in a separate license agreement.
  37.  *---------------------------------------------------------------------
  38.  */
  39.  
  40. #include "unmcopyright.h"        /* Copyright 1992 by UNM */
  41.  
  42. /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  43.  >>>>
  44.  >>>>         File Name: vgmtophat.c
  45.  >>>>
  46.  >>>>      Program Name: vgmtophat
  47.  >>>>
  48.  >>>>      Program Desc: 
  49.  >>>>    
  50.  >>>>    Perform a tophat transform on image  X,   using  structuring
  51.  >>>>    element B.
  52.  >>>>    
  53.  >>>>    
  54.  
  55.  >>>>            Author: Greg DONOHOE and Pascal ADAM
  56.  >>>>
  57.  >>>> Date Last Updated: Mon Jul 27 16:52:00 1992
  58.  >>>>
  59.  >>>>          Routines: main- the main program for vgmtophat
  60.  >>>>          gw_usage - gives usage of the program
  61.  >>>>          gw_args  - gets arguments of program from command line
  62.  >>>>
  63.  >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
  64.  
  65.  
  66. #include "vgmtophat.h"
  67.  
  68.  
  69. /****************************************************************
  70.  *
  71.  * Routine Name:  main program for vgmtophat
  72.  *
  73.  *       Input:  
  74.  *           -i  input image 
  75.  *           -k  input kernel 
  76.  *           -o  output image 
  77.  *           -s  proportion to subtract   (0.000 < value < 1.000)
  78.  *           -normal  normalize  output 
  79.  *
  80.  *
  81.  *
  82.  *
  83.  *
  84.  ****************************************************************/
  85.  
  86.  
  87. main(argc, argv)
  88. int argc;
  89. char *argv[];
  90. {
  91.  
  92. /* -main_variable_list */
  93.     struct xvimage *image1, *kernel, *readimage();
  94. /* -main_variable_list_end */
  95.  
  96.     program = VStrcpy(argv[0]);
  97.     ac = argc;
  98.     av = argv;
  99.  
  100.     khoros_init();
  101.  
  102.     gw_get_args();
  103.  
  104. /* -main_before_lib_call */
  105.     if (check_args()) exit(1);
  106.  
  107.     READINPUT (image1, kernel);
  108.     CHECKINPUT (program, image1, kernel);
  109.  
  110. /* -main_before_lib_call_end */
  111.  
  112. /* -main_library_call */
  113.     if(! lvgmtophat(image1,  kernel,vgmtophat->s_float,
  114.           vgmtophat->normal_logic))
  115.     {
  116.         (void) fprintf(stderr, "vgmtophat: lvgmtophat Failed\n");
  117.         exit(1);
  118.     }
  119. /* -main_library_call_end */
  120.  
  121. /* -main_after_lib_call */
  122.     writeimage(vgmtophat->o_file,image1);
  123. /* -main_after_lib_call_end */
  124.  
  125.  
  126.     khoros_close();
  127. }
  128.  
  129.  
  130. /****************************************************************
  131. *
  132. * Routine Name:  gw_usage 
  133. *
  134. *
  135. * Purpose:  prints out the usage for vgmtophat 
  136. *
  137. * Input:  none 
  138. *
  139. * Output:  none 
  140. *
  141. * Written By:  automatically generated by ghostwriter
  142. *
  143. ****************************************************************/
  144.  
  145.  
  146. gw_usage()
  147. {
  148.     fprintf(stderr, "vgmtophat :\n");
  149.     fprintf(stderr, "\t\n");
  150.     fprintf(stderr, "\tPerform a tophat transform on image  X,   using  structuring\n");
  151.     fprintf(stderr, "\telement B.\n");
  152.     fprintf(stderr, "\t\n");
  153.     fprintf(stderr, "\t\n");
  154.  
  155. /* -usage_additions */
  156. /* -usage_additions_end */
  157.  
  158.     fprintf(stderr,"\t-i  input image  (infile)\n");
  159.     fprintf(stderr,"\t-k  input kernel  (infile)\n");
  160.     fprintf(stderr,"\t-o  output image  (outfile)\n");
  161.     fprintf(stderr,"\t-s  proportion to subtract  (float,  0.000 to 1.000)\n");
  162.     fprintf(stderr,"\t-normal  normalize  output  (boolean)\n");
  163.     fprintf(stderr, "\n");
  164.     fprintf(stderr, "\n");
  165.     fprintf(stderr, " \n");
  166.     fprintf(stderr, "\n");
  167.     fprintf(stderr, "\t[-V] Gives the version for vgmtophat\n");
  168.     fprintf(stderr, "\t[-U] Gives the usage for vgmtophat\n");
  169.     fprintf(stderr, "\t[-P] Prompts for command line options\n");
  170.     fprintf(stderr, "\t[-A [file1]] Creates the answer file called vgmtophat.ans or file1 \n");
  171.     fprintf(stderr, "\t[-a [file1]] Uses vgmtophat.ans or file1 as the answer file \n\n\n");
  172.  
  173. }
  174.  
  175.  
  176. /****************************************************************
  177. *
  178. * Routine Name:  gw_getargs 
  179. *
  180. *
  181. * Purpose:  gets arguments off command line for vgmtophat
  182. *
  183. * Input:  none 
  184. *
  185. * Output:  none 
  186. *
  187. * Written By:  automatically generated by ghostwriter
  188. *
  189. ****************************************************************/
  190.  
  191.  
  192. gw_get_args()
  193. {
  194.  
  195. char    *i_pstr = 
  196.     "\nEnter: (i) input image \n        {infile}: "; 
  197. char    *k_pstr = 
  198.     "\nEnter: (k) input kernel \n        {infile}: "; 
  199. char    *o_pstr = 
  200.     "\nEnter: (o) output image \n        {outfile}: "; 
  201. char    *s_pstr = 
  202.     "\nEnter: (s) proportion to subtract \n        {float,  0.000 to 1.000}: "; 
  203. char    *normal_pstr = 
  204.     "\nEnter: (normal) normalize  output \n        {boolean, (y/n) }: "; 
  205. char  answer_file[512], temp[512];
  206.  
  207.  
  208.  
  209. int    fid = -1,
  210.     error, query, ok, count;
  211.     int prompt_flag = FALSE;
  212.  
  213.     /*
  214.      * print version if necessary
  215.      */
  216.     vgparml(fid, "-V", "noprompt", &query, 0, 0, &error);
  217.     if (error == 0)
  218.     {
  219.         printf ("\n%s: %s: Version %d.%d\n\n",
  220.         "vgmtophat", RELEASE_NAME, RELEASE_MAJOR, RELEASE_MINOR);
  221.         exit(1);
  222.     }
  223.  
  224.     /*
  225.      * print usage if necessary
  226.      */
  227.     vgparml(fid, "-U", "noprompt", &query, 0, 0, &error);
  228.     if (error == 0)
  229.     {
  230.         gw_usage();
  231.         exit(1);
  232.     }
  233.  
  234.     /*
  235.      * see if interactive prompting is desired
  236.      */
  237.     vgparml(fid, "-P", "noprompt", &query, 0, 0, &error);
  238.     if (error == 0)
  239.         prompt_flag = TRUE;
  240.  
  241.     /*
  242.      * see if answer file is to be used
  243.      */
  244.     vgparms(fid, "-a", "noprompt", answer_file, 0, 0, &error);
  245.     if (error == 0)
  246.     {
  247.          if (VStrlen(answer_file) == 0)
  248.         sprintf(answer_file, "vgmtophat.ans");
  249.          while (fid < 0)
  250.          {
  251.         if ((fid = open(answer_file, O_RDONLY, 0666))== -1)
  252.         {
  253.             fprintf(stderr, "vgmtophat: can't open answer file \"%s\"",
  254.                 answer_file); 
  255.             fprintf(stderr, "please re-enter: ");
  256.             (void) gets(answer_file);
  257.             if (VStrlen(answer_file) == 0)
  258.             sprintf(answer_file, "vgmtophat.ans");
  259.         }
  260.  
  261.          }
  262.  
  263.     }
  264.  
  265.     /*
  266.      * allocate the vgmtophat structure
  267.      */
  268.     vgmtophat = (vgmtophat_struct *) 
  269.            calloc((unsigned)1, (unsigned) sizeof (vgmtophat_struct));
  270.  
  271.     /*
  272.      * get required arguments for vgmtophat
  273.      */
  274.     if (prompt_flag == TRUE)
  275.         fprintf(stderr,"\nRequired Arguments:\n\n");
  276.  
  277.     if (!(vgmtophat->i_flag = vget_infile(fid, prompt_flag,
  278.             "-i", i_pstr, &(vgmtophat->i_file))
  279. ))
  280.     {
  281.         if (prompt_flag == TRUE)
  282.         {
  283.         while(!(vgmtophat->i_flag))
  284.         {
  285.             fprintf(stderr, "\t\ti is required, please re-enter: \n");
  286.             vgmtophat->i_flag = vget_infile(fid, prompt_flag,
  287.             "-i", i_pstr, &(vgmtophat->i_file))
  288. ;
  289.  
  290.         }
  291.         }
  292.         else
  293.         {
  294.         fprintf(stderr, "Error: '-i' is a required argument\n");
  295.         gw_usage();
  296.         exit(1);
  297.         }
  298.     }
  299.  
  300.     if (!(vgmtophat->k_flag = vget_infile(fid, prompt_flag,
  301.             "-k", k_pstr, &(vgmtophat->k_file))
  302. ))
  303.     {
  304.         if (prompt_flag == TRUE)
  305.         {
  306.         while(!(vgmtophat->k_flag))
  307.         {
  308.             fprintf(stderr, "\t\tk is required, please re-enter: \n");
  309.             vgmtophat->k_flag = vget_infile(fid, prompt_flag,
  310.             "-k", k_pstr, &(vgmtophat->k_file))
  311. ;
  312.  
  313.         }
  314.         }
  315.         else
  316.         {
  317.         fprintf(stderr, "Error: '-k' is a required argument\n");
  318.         gw_usage();
  319.         exit(1);
  320.         }
  321.     }
  322.  
  323.     if (!(vgmtophat->o_flag = vget_outfile(fid, prompt_flag,
  324.             "-o", o_pstr, &(vgmtophat->o_file))
  325. ))
  326.     {
  327.         if (prompt_flag == TRUE)
  328.         {
  329.         while(!(vgmtophat->o_flag))
  330.         {
  331.             fprintf(stderr, "\t\to is required, please re-enter: \n");
  332.             vgmtophat->o_flag = vget_outfile(fid, prompt_flag,
  333.             "-o", o_pstr, &(vgmtophat->o_file))
  334. ;
  335.  
  336.         }
  337.         }
  338.         else
  339.         {
  340.         fprintf(stderr, "Error: '-o' is a required argument\n");
  341.         gw_usage();
  342.         exit(1);
  343.         }
  344.     }
  345.  
  346.     if (!(vgmtophat->s_flag = vget_float(fid, prompt_flag,
  347.             "-s", s_pstr, &(vgmtophat->s_float),
  348.             0.500000, 0.000000, 1.000000)))
  349.     {
  350.         if (prompt_flag == TRUE)
  351.         {
  352.         while(!(vgmtophat->s_flag))
  353.         {
  354.             fprintf(stderr, "\t\ts is required, please re-enter: \n");
  355.             vgmtophat->s_flag = vget_float(fid, prompt_flag,
  356.             "-s", s_pstr, &(vgmtophat->s_float),
  357.             0.500000, 0.000000, 1.000000);
  358.  
  359.         }
  360.         }
  361.         else
  362.         {
  363.         fprintf(stderr, "Error: '-s' is a required argument\n");
  364.         gw_usage();
  365.         exit(1);
  366.         }
  367.     }
  368.  
  369.     if (!(vgmtophat->normal_flag = vget_logic(fid, prompt_flag,
  370.             "-normal", normal_pstr, &(vgmtophat->normal_logic), 0)))
  371.     {
  372.         if (prompt_flag == TRUE)
  373.         {
  374.         while(!(vgmtophat->normal_flag))
  375.         {
  376.             fprintf(stderr, "\t\tnormal is required, please re-enter: \n");
  377.             vgmtophat->normal_flag = vget_logic(fid, prompt_flag,
  378.             "-normal", normal_pstr, &(vgmtophat->normal_logic), 0);
  379.  
  380.         }
  381.         }
  382.         else
  383.         {
  384.         fprintf(stderr, "Error: '-normal' is a required argument\n");
  385.         gw_usage();
  386.         exit(1);
  387.         }
  388.     }
  389.  
  390.  
  391. }
  392.  
  393.  
  394.  
  395.