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 >
Wrap
C/C++ Source or Header
|
1992-07-28
|
9KB
|
395 lines
/*
* Khoros: $Id$
*/
#if !defined(lint) && !defined(SABER)
static char rcsid[] = "Khoros: $Id$";
#endif
/*
* $Log$
*/
/*
*----------------------------------------------------------------------
*
* Copyright 1992, University of New Mexico. All rights reserved.
* Permission to copy and modify this software and its documen-
* tation only for internal use in your organization is hereby
* granted, provided that this notice is retained thereon and
* on all copies. UNM makes no representations as to the sui-
* tability and operability of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*
* UNM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
* NESS. IN NO EVENT SHALL UNM BE LIABLE FOR ANY SPECIAL,
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY OTHER DAMAGES WHAT-
* SOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PER-
* FORMANCE OF THIS SOFTWARE.
*
* No other rights, including, for example, the right to redis-
* tribute this software and its documentation or the right to
* prepare derivative works, are granted unless specifically
* provided in a separate license agreement.
*---------------------------------------------------------------------
*/
#include "unmcopyright.h" /* Copyright 1992 by UNM */
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>>>>
>>>> File Name: vgmtophat.c
>>>>
>>>> Program Name: vgmtophat
>>>>
>>>> Program Desc:
>>>>
>>>> Perform a tophat transform on image X, using structuring
>>>> element B.
>>>>
>>>>
>>>> Author: Greg DONOHOE and Pascal ADAM
>>>>
>>>> Date Last Updated: Mon Jul 27 16:52:00 1992
>>>>
>>>> Routines: main- the main program for vgmtophat
>>>> gw_usage - gives usage of the program
>>>> gw_args - gets arguments of program from command line
>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
#include "vgmtophat.h"
/****************************************************************
*
* Routine Name: main program for vgmtophat
*
* Input:
* -i input image
* -k input kernel
* -o output image
* -s proportion to subtract (0.000 < value < 1.000)
* -normal normalize output
*
*
*
*
*
****************************************************************/
main(argc, argv)
int argc;
char *argv[];
{
/* -main_variable_list */
struct xvimage *image1, *kernel, *readimage();
/* -main_variable_list_end */
program = VStrcpy(argv[0]);
ac = argc;
av = argv;
khoros_init();
gw_get_args();
/* -main_before_lib_call */
if (check_args()) exit(1);
READINPUT (image1, kernel);
CHECKINPUT (program, image1, kernel);
/* -main_before_lib_call_end */
/* -main_library_call */
if(! lvgmtophat(image1, kernel,vgmtophat->s_float,
vgmtophat->normal_logic))
{
(void) fprintf(stderr, "vgmtophat: lvgmtophat Failed\n");
exit(1);
}
/* -main_library_call_end */
/* -main_after_lib_call */
writeimage(vgmtophat->o_file,image1);
/* -main_after_lib_call_end */
khoros_close();
}
/****************************************************************
*
* Routine Name: gw_usage
*
*
* Purpose: prints out the usage for vgmtophat
*
* Input: none
*
* Output: none
*
* Written By: automatically generated by ghostwriter
*
****************************************************************/
gw_usage()
{
fprintf(stderr, "vgmtophat :\n");
fprintf(stderr, "\t\n");
fprintf(stderr, "\tPerform a tophat transform on image X, using structuring\n");
fprintf(stderr, "\telement B.\n");
fprintf(stderr, "\t\n");
fprintf(stderr, "\t\n");
/* -usage_additions */
/* -usage_additions_end */
fprintf(stderr,"\t-i input image (infile)\n");
fprintf(stderr,"\t-k input kernel (infile)\n");
fprintf(stderr,"\t-o output image (outfile)\n");
fprintf(stderr,"\t-s proportion to subtract (float, 0.000 to 1.000)\n");
fprintf(stderr,"\t-normal normalize output (boolean)\n");
fprintf(stderr, "\n");
fprintf(stderr, "\n");
fprintf(stderr, " \n");
fprintf(stderr, "\n");
fprintf(stderr, "\t[-V] Gives the version for vgmtophat\n");
fprintf(stderr, "\t[-U] Gives the usage for vgmtophat\n");
fprintf(stderr, "\t[-P] Prompts for command line options\n");
fprintf(stderr, "\t[-A [file1]] Creates the answer file called vgmtophat.ans or file1 \n");
fprintf(stderr, "\t[-a [file1]] Uses vgmtophat.ans or file1 as the answer file \n\n\n");
}
/****************************************************************
*
* Routine Name: gw_getargs
*
*
* Purpose: gets arguments off command line for vgmtophat
*
* Input: none
*
* Output: none
*
* Written By: automatically generated by ghostwriter
*
****************************************************************/
gw_get_args()
{
char *i_pstr =
"\nEnter: (i) input image \n {infile}: ";
char *k_pstr =
"\nEnter: (k) input kernel \n {infile}: ";
char *o_pstr =
"\nEnter: (o) output image \n {outfile}: ";
char *s_pstr =
"\nEnter: (s) proportion to subtract \n {float, 0.000 to 1.000}: ";
char *normal_pstr =
"\nEnter: (normal) normalize output \n {boolean, (y/n) }: ";
char answer_file[512], temp[512];
int fid = -1,
error, query, ok, count;
int prompt_flag = FALSE;
/*
* print version if necessary
*/
vgparml(fid, "-V", "noprompt", &query, 0, 0, &error);
if (error == 0)
{
printf ("\n%s: %s: Version %d.%d\n\n",
"vgmtophat", RELEASE_NAME, RELEASE_MAJOR, RELEASE_MINOR);
exit(1);
}
/*
* print usage if necessary
*/
vgparml(fid, "-U", "noprompt", &query, 0, 0, &error);
if (error == 0)
{
gw_usage();
exit(1);
}
/*
* see if interactive prompting is desired
*/
vgparml(fid, "-P", "noprompt", &query, 0, 0, &error);
if (error == 0)
prompt_flag = TRUE;
/*
* see if answer file is to be used
*/
vgparms(fid, "-a", "noprompt", answer_file, 0, 0, &error);
if (error == 0)
{
if (VStrlen(answer_file) == 0)
sprintf(answer_file, "vgmtophat.ans");
while (fid < 0)
{
if ((fid = open(answer_file, O_RDONLY, 0666))== -1)
{
fprintf(stderr, "vgmtophat: can't open answer file \"%s\"",
answer_file);
fprintf(stderr, "please re-enter: ");
(void) gets(answer_file);
if (VStrlen(answer_file) == 0)
sprintf(answer_file, "vgmtophat.ans");
}
}
}
/*
* allocate the vgmtophat structure
*/
vgmtophat = (vgmtophat_struct *)
calloc((unsigned)1, (unsigned) sizeof (vgmtophat_struct));
/*
* get required arguments for vgmtophat
*/
if (prompt_flag == TRUE)
fprintf(stderr,"\nRequired Arguments:\n\n");
if (!(vgmtophat->i_flag = vget_infile(fid, prompt_flag,
"-i", i_pstr, &(vgmtophat->i_file))
))
{
if (prompt_flag == TRUE)
{
while(!(vgmtophat->i_flag))
{
fprintf(stderr, "\t\ti is required, please re-enter: \n");
vgmtophat->i_flag = vget_infile(fid, prompt_flag,
"-i", i_pstr, &(vgmtophat->i_file))
;
}
}
else
{
fprintf(stderr, "Error: '-i' is a required argument\n");
gw_usage();
exit(1);
}
}
if (!(vgmtophat->k_flag = vget_infile(fid, prompt_flag,
"-k", k_pstr, &(vgmtophat->k_file))
))
{
if (prompt_flag == TRUE)
{
while(!(vgmtophat->k_flag))
{
fprintf(stderr, "\t\tk is required, please re-enter: \n");
vgmtophat->k_flag = vget_infile(fid, prompt_flag,
"-k", k_pstr, &(vgmtophat->k_file))
;
}
}
else
{
fprintf(stderr, "Error: '-k' is a required argument\n");
gw_usage();
exit(1);
}
}
if (!(vgmtophat->o_flag = vget_outfile(fid, prompt_flag,
"-o", o_pstr, &(vgmtophat->o_file))
))
{
if (prompt_flag == TRUE)
{
while(!(vgmtophat->o_flag))
{
fprintf(stderr, "\t\to is required, please re-enter: \n");
vgmtophat->o_flag = vget_outfile(fid, prompt_flag,
"-o", o_pstr, &(vgmtophat->o_file))
;
}
}
else
{
fprintf(stderr, "Error: '-o' is a required argument\n");
gw_usage();
exit(1);
}
}
if (!(vgmtophat->s_flag = vget_float(fid, prompt_flag,
"-s", s_pstr, &(vgmtophat->s_float),
0.500000, 0.000000, 1.000000)))
{
if (prompt_flag == TRUE)
{
while(!(vgmtophat->s_flag))
{
fprintf(stderr, "\t\ts is required, please re-enter: \n");
vgmtophat->s_flag = vget_float(fid, prompt_flag,
"-s", s_pstr, &(vgmtophat->s_float),
0.500000, 0.000000, 1.000000);
}
}
else
{
fprintf(stderr, "Error: '-s' is a required argument\n");
gw_usage();
exit(1);
}
}
if (!(vgmtophat->normal_flag = vget_logic(fid, prompt_flag,
"-normal", normal_pstr, &(vgmtophat->normal_logic), 0)))
{
if (prompt_flag == TRUE)
{
while(!(vgmtophat->normal_flag))
{
fprintf(stderr, "\t\tnormal is required, please re-enter: \n");
vgmtophat->normal_flag = vget_logic(fid, prompt_flag,
"-normal", normal_pstr, &(vgmtophat->normal_logic), 0);
}
}
else
{
fprintf(stderr, "Error: '-normal' is a required argument\n");
gw_usage();
exit(1);
}
}
}