file: average.c
/*
* average.c - This file contains routines related to the displaying
* of brush average value operations.
*
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without fee
* is granted provided that the above copyright notice appears in all copies.
* It is provided "as is" without express or implied warranty.
*/
#include "XmdvTool.h"
#include "brush_oper.h"
#include "parcoord.h"
#include "glyph.h"
#include "util.h"
#include "scatterplot.h"
#include "hierarchy.h"
#include "average.h"
extern Widget appShell;
extern GC gc;
extern int dims, data_size;
extern char names[MAXDIM][MAXLABEL];
/* the operations */
extern Operation operations[MAXOPER];
extern int num_oper;
/*
* AverageUpdate() - For each average operation, calculate the
* average value and display it
*
* PARAMETERS
* void
*
* RETURNS
* void
*/
void AverageUpdate(void)
{
int op; /* the operation number */
char *str; /* the current toggle selection */
Widget canvas_w, choice; /* canvas and display toggle widget */
double average[MAXDIM]; /* the average */
if(!(canvas_w = WcFullNameToWidget(appShell,"*canvas")))
{
fprintf(stderr, "Error finding *canvas\n");
return;
}
if(!(choice = WcFullNameToWidget(appShell,"*togscat")))
{
fprintf(stderr, "Error finding *togscat\n");
return;
}
if(!(str = (char *)XawToggleGetCurrent(choice)))
return;
for(op=0; op<num_oper; op++)
{
/* check if this operation has OPER_AVERAGE set */
if(!(operations[op].oper & OPER_AVERAGE))
continue;
/* get the average value */
if(ComputeAverage(op, average))
continue;
/* set the correct color */
XSetForeground(XtDisplay(appShell), gc, operations[op].colors[0].pixel);
/* determine the correct display function to call */
if(!strcmp(str, "togpar"))
ParCoordDrawAverage(average);
else if(!strcmp(str, "togscat"))
ScatterDrawAverage(average);
else if(!strcmp(str, "toggly"))
GlyphDrawAverage(average);
else if(!strcmp(str, "toghier"))
HierDrawAverage(average);
}
}
/*
* ComputeAverage() - Given an operation number, computes the average
* of all the points contained by the operation and
* stores the result in aver.
*
* PARAMETERS
* op The operation number
* aver The location to store the computed average
*
* RETURNS
* FALSE Success - the result is stored in aver
* TRUE Failure - no points covered by the operation, so
* no average could be computed
*/
int ComputeAverage(int op, double *aver)
{
int i,j;
int num_av=0; /* number of points averaged */
double data[MAXDIM]; /* a data point */
for(i=0; i<dims; i++)
aver[i] = 0.0;
for(i=0; i<data_size; i++)
{
get_data(data, i);
if(OperationPoint(data, op))
{
for(j=0; j<dims; j++)
aver[j] += data[j];
num_av++;
}
}
/* check if any points were covered */
if(!num_av)
return(TRUE);
for(i=0; i<dims; i++)
aver[i] /= (double)num_av;
return(FALSE);
}
C++ to HTML Conversion by ctoohtml