[SESI logo]

Prisms Development Toolkit Documentation

Side Effects Software Inc. 1997

Custom SOPs

Accepting Numeric Input

Numeric input can come singly, in twos (such as UV values) or in threes (such as (x,y,z) triplets). The SOP building code puts an input line of the kind you request, and these inputs work just as in other SOPs: the user can put expressions into them, single values, the names of channels, or just use the sliders - it's all handled for you.

Source Listing


#include <custom.h>			/* you must have this! */

/*
 * Define the amount of space used by the sop data and name the fields
 */
typedef struct sop_data 
{
    
    SOP_EXPR	Single;
    SOP_EXPR	Double[2];
    SOP_EXPR	Triple[3];
    
} SOP_DATA;

/*
 * Creata a structure that the sop library can use to figure out 
 * what is in your SOP_DATA struct. NOTE: This structure MUST
 * correspond to the one above.
 */
static SOP_PARMS	sopParms[] =
{
    
    { SOPPARM_EXPR,	"Single Label",	NULL,  {NULL} },
    { SOPPARM_DOUBLE,	"Double Label",	NULL , {NULL} },
    { SOPPARM_DOUBLE,	"Ignored",	NULL , {NULL} },
    { SOPPARM_TRIPLE,	"Triple Label",	NULL , {NULL} },
    { SOPPARM_TRIPLE,	"Ignored",	NULL , {NULL} },
    { SOPPARM_TRIPLE,	"Ignored",	NULL , {NULL} },
    
    { NULL },
};

/*
 * This function is used when creating a new sop. It sets up the
 * initial values of the sop.
 */
static void
sopDefaults(SOP *sop)		/* Put in default values */
{
    SOP_DATA	*sb;

    if (sop->special) free(sop->special);
    sb = (SOP_DATA *)Calloc(sizeof(SOP_DATA), "Sample sopDefaults");
    sop->special = (char *)sb;

    
    InitSopExpr(&sb->Single, "$COOK");
    InitSopExpr(&sb->Double[0], "2");
    InitSopExpr(&sb->Double[1], "3");
    InitSopExpr(&sb->Triple[0], "4");
    InitSopExpr(&sb->Triple[1], "5");
    InitSopExpr(&sb->Triple[2], "6");
    
}

/*
 * This function is used to read data into the sop.
 * You should make sure that its format matches that which is 
 * output by sopPrint
 */
static void
sopScan(SOP *sop, int argc, char *argv[])
{
    SOP_DATA	*sb;	

    sb = (SOP_DATA *) sop->special;	

    
    /* 
     * Arguments to SopScan... are:
     *		character to be used for option (see Note 1)
     *		Pointer to storage area	in SOP
     *		The SOP pointer
     * Note :   The following option characters are reserved 
     *		and shouldn't be used:
     *		a,s,H,I,J,K,L,M,N,Y,Z,o,f  
     */
    SopScanExpr    ('e', &sb->Single,   sop);
    SopScanDouble  ('d',  sb->Double,   sop);
    SopScanTriple  ('t',  sb->Triple,   sop);
    
}

/*
 * This function is used to output the sops data to a file.
 * The data will later be read back in by sopScan.
 */
static void
sopPrint(FILE *fp, SOP *sop)
{
    SOP_DATA	*sb;
    sb = (SOP_DATA *)sop->special;

    
    /*
     * Arguments to SopPrint... are:
     *		File Pointer
     *		Data Pointer
     *		Default values (NOTE: Double has 2, 
     *			and Triple has 3, Toggle 0)
     *		The string that precedes the data
     * 	Data is only printed if different from the default.
     */
    SopPrintExpr    (fp, &sb->Single,   "", "-e");
    SopPrintDouble  (fp,  sb->Double,   "", "", "-d");
    SopPrintTriple  (fp,  sb->Triple,   "", "", "", "-t");
    
}

static void
sopCook(SOP *sop)	/* This is where you build a PDP */
{
    SOP_DATA	*sb;

    sb = (SOP_DATA *)sop->special;

    if (sop->pdp) FreePolyDetail(sop->pdp);
    sop->pdp = 0;

    
    /*
     * calling EVALUATE scans the expression, evaluates variables, etc
     * and puts the resulting value in the Expression's .value.fval
     * field.
     * EVALUATELV should be called if the sop has local variables.
     * Since we have one defined, we use EVALUATELV in this example.
     */
    EVALUATELV(sop, sb->Single);
    printf("Single : %g\n", sb->Single.value.fval);

    EVALUATELV(sop, sb->Double[0]);
    EVALUATELV(sop, sb->Double[1]);
    printf("Double : (%g, %g)\n", sb->Double[0].value.fval,
				  sb->Double[1].value.fval);

    EVALUATELV(sop, sb->Triple[0]);
    EVALUATELV(sop, sb->Triple[1]);
    EVALUATELV(sop, sb->Triple[2]);
    printf("Triple : (%g, %g, %g)\n", sb->Triple[0].value.fval,
				      sb->Triple[1].value.fval,
				      sb->Triple[2].value.fval);
    
}

#define SOPUSAGE	\
"severything -S String -F File -e Single -d double1 double2 \
-t triple1 triple2 \
triple 3 -T -m menuItem -o Object -u UserMenu\n\
\t-s    Just a string\
\tetc\n"


SOP_FUNC	EverythingSopRef = {
	"everything",
	"S:F:e:d::t:::Tm:u:",
	sopScan, sopPrint, sopCook, sopDefaults, 
	sopClean, sopGPMake, sopGetParms,
	SOPUSAGE,
};

Notes:

1. The syntax of the second line in the SOP_FUNC structure, which in this example is "S:F:e:d::t:::TM:u:" has the following syntax:
First, the choice of letter to describe each argument can be any single letter, except for the action reserved ones, which are
a f o s H I J K L M N Y Z
Second, each letter is followed by one or more colons ( : ), which indicate how many arguments that parameter expects. So -T, which is a toggle, takes no arguments, and is followed by zero colons. -d, which takes two arguments, is followed by two colons, etc.

2. Obviously, one does not usually print out the values of numbers coming in; instead, we want to use them to do some arithmetic. Conventionally, this is done by assigning the EVALUATE'd sliders to local variables, and going on, eg
float	uval, vval, avg;
.
.	/* some other code */
.
EVALUATE(sop, sb->newuvs);
uval = sb->newuvs[0];
vval = sp->newuvs[1];

avg = (uval + vval) / 2.0;

For More Detailed Information:

The sopParms table and SOP_DATA structures
The sopDefault routine
The sopScan routine
The sopPrint routine
The SOP_FUNC reference structure

Tookit Overview
Expression Functions | User Functions | Custom SOPs
Prisms Internal Format | Programmer's Reference
Compiling SOPs | Using sopbuild | SOP Routine Reference
Dynamic SOPs | Prisms Types | Macros
Math Routines | Data Routines | Polygon Routines | Winged-edge Routines

Copyright © 1997 Side Effects Software Inc.
477 Richmond Street West, Toronto, Ontario, Canada M5V 3E7