Chan-Vese Segmentation
Data Structures | Macros | Functions | Variables
cliio.h File Reference

Utilities for creating a command line interface. More...

#include "num.h"
#include "imageio.h"

Go to the source code of this file.

Data Structures

struct  image
 struct representing an image More...
 

Macros

#define IMAGEIO_NUM   (IMAGEIO_DOUBLE)
 

Functions

int AllocImageObj (image *f, int Width, int Height, int NumChannels)
 
void FreeImageObj (image f)
 
int ReadImageObj (image *f, const char *FileName)
 
int ReadImageObjGrayscale (image *f, const char *FileName)
 
int WriteImageObj (image f, const char *FileName, int JpegQuality)
 
int IsGrayscale (num *Data, int Width, int Height)
 Check whether all three channels in a color image are the same.
 
int GetStrToken (char *Token, const char *Start, int MaxLength, const char *Delim)
 Extract a token from a null-terminated string. More...
 
int ParseDouble (double *Num, const char *String)
 Read a floating-point number from a string. More...
 
int CliParseArglist (const char **Param, const char **Value, char *TokenBuf, int MaxLength, int k, const char *Start, int argc, const char *argv[], const char *Delimiters)
 Parse an arg list for param-value pairs. More...
 
int CliGetNum (num *Value, const char *String, const char *Param)
 Strictly read a num value.
 
int ReadMatrixFromTextFile (image *f, const char *FileName)
 Read a matrix from a text file.
 
int ReadMatrixFromFile (image *f, const char *FileName, int(*RescaleFun)(image *f))
 Read a matrix from a text or image file.
 

Variables

const image NullImage
 

Detailed Description

Utilities for creating a command line interface.

Author
Pascal Getreuer getre.nosp@m.uer@.nosp@m.gmail.nosp@m..com

Definition in file cliio.h.

Function Documentation

int CliParseArglist ( const char **  Param,
const char **  Value,
char *  TokenBuf,
int  MaxLength,
int  k,
const char *  Start,
int  argc,
const char *  argv[],
const char *  Delimiters 
)

Parse an arg list for param-value pairs.

Parameters
Paramwhere to store the parameter pointer
Valuewhere to store the value pointer
TokenBuftoken buffer with space for at least MaxLength+1 chars
MaxLengthtoken buffer size
kstarting arg
Startstarting character position in argv[k]
argc,argvthe arg list
Delimiterscharacters that delimit parameters from values
Returns
index of the arg containing the value

For example, with Delimiters = ":", the routine parses arg lists of the form {"param1:value1", "param2:value2", "param3:value3"}. It is flexible to allow argument breaks around the delimiter, including any of the following syntaxes: {"param", "value"}, {"param:", "value"}, {"param", ":", "value"}, {"param", ":", "", "value"}.

The routine can be used as

char TokenBuf[256];
int k = 1;
while(k < argc)
{
kread = CliParseArglist(&Param, &Value, TokenBuf, sizeof(TokenBuf),
k, argv[k], argc, argv, ":");
printf("Read parameter %s = value %s\n", Param, Value);
k = kread + 1;
}

Definition at line 248 of file cliio.c.

int GetStrToken ( char *  Token,
const char *  Start,
int  MaxLength,
const char *  Delim 
)

Extract a token from a null-terminated string.

Parameters
Tokendestination buffer (with space for at least MaxLength+1 chars)
Startpointer to the source string
MaxLengthmaximum length of the token, not including null terminator
Delimdelimiter characters
Returns
length of the token (greater than MaxLength indicates truncation).

Definition at line 118 of file cliio.c.

int ParseDouble ( double *  Num,
const char *  String 
)

Read a floating-point number from a string.

Parameters
Numis a pointer to where to store the result
Stringis a pointer to the source string to parse
Returns
the number of characters read (possibly 0).

The function strtod does not seem to work on some systems. We use the following routine instead.

The routine reads as many characters as possible to form a valid floating-point number in decimal or scientific notation. A return value of zero indicates that no valid number was found.

Definition at line 142 of file cliio.c.