1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
|
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 3//EN">
<HTML><HEAD>
<TITLE>IBM Visualization Data Explorer Programmer's Reference</TITLE>
<META HTTP-EQUIV="abstract" CONTENT="IBM Visualization Data Explorer
Programmer's Reference">
<META HTTP-EQUIV="contact" CONTENT="IBM Visualization Data Explorer
(ibmdx@watson.ibm.com)">
<META HTTP-EQUIV="owner" CONTENT="IBM Visualization Data Explorer
(ibmdx@watson.ibm.com)">
<META HTTP-EQUIV="updated" CONTENT="Tue, 16 Sep 1997 ">
<META HTTP-EQUIV="review" CONTENT="Fri, 14 Aug 1998 ">
<META HTTP-EQUIV="keywords" CONTENT="GRAPHICS VISUALIZATION VISUAL PROGRAM DATA
MINING">
<meta http-equiv="content-type" content="text/html;charset=ISO-8859-1">
</HEAD><BODY BGCOLOR="#FFFFFF">
<A NAME="Top_Of_Page"></A>
<H1>IBM Visualization Data Explorer Programmer's Reference</H1>
<B>[ <A HREF="#Bot_Of_Page">Bottom of Page</A> | <A
HREF="progu029.htm">Previous Page</A> | <A HREF="progu031.htm">Next
Page</A> | <A HREF="../proguide.htm#ToC">Table of Contents</A> | <A
HREF="progu028.htm#PToC8">Partial Table of Contents</A> | <A
HREF="progu344.htm#HDRINDEX_START">Index</A> ]</B><HR><P>
<HR>
<H1><A NAME="HDRCONNEC" HREF="../proguide.htm#ToC_63">Chapter 7. Working with
Connections</A></H1>
<P><A NAME="PToC9" HREF="../proguide.htm#ToC">Partial Table-of-Contents</A>
<MENU>
<LI><A NAME="PToC_64" HREF="#HDREXAVGC">7.1 AverageCell Module Example--Average
the Data Values of All Neighbors</A>
</MENU><HR><P>
<P>
The module in this example manipulates both the data and the
connections components of an input Field (the modules in
<A HREF="progu025.htm#HDRMODEXSC">Chapter 5. "Working with Data"</A> and <A
HREF="progu028.htm#HDRPOSIT">Chapter 6. "Working with Positions"</A>, did not
require a
connections component). Modules that perform interpolation need
information about the interpolation elements (connections). For
example, the Isosurface module uses different interpolation methods
according to the type of connection.
<HR>
<H2><A NAME="HDREXAVGC" HREF="#PToC_64">7.1 AverageCell Module Example--Average
the Data Values of All Neighbors</A></H2>
<A NAME="IDX242"></A>
<A NAME="IDX243"></A>
<A NAME="IDX244"></A>
<P>
The AverageCell module computes, for each cell, the average of the data
values of that cell and all its neighbors.
<TABLE><TR><TD ALIGN="LEFT" VALIGN="TOP"><B>Note:</B></TD><TD ALIGN="LEFT"
VALIGN="TOP">This module works only on data that is cell-centered (i.e.,
connection-dependent) and has connections of type
"quads."
</td></tr></table>
<P>
The AverageCell module takes one input: <TT><STRONG>input</STRONG></TT>,
of type <TT><STRONG>field</STRONG></TT>, which has no
default value.
The module has one output: <TT><STRONG>output</STRONG></TT>, of type
<TT><STRONG>field</STRONG></TT>.
<P>
<B><U>(1) Start the Module Builder</U></B> with the command:
<PRE>
dx -builder
</PRE>
<P>
The Module Builder dialog box appears.
Note that the dialog box carries no information, since no module
has been specified.
(For a simple example of creating a module with the Module Builder,
see <A HREF="progu017.htm#HDRTMODBLD">3.3 , "Using the Module Builder: A Quick
Walk Through"</A>).
<P>
<B><U>(2) Select <TT><STRONG>Open</STRONG></TT></U></B> from the
<TT><STRONG>File</STRONG></TT>
pull-down menu.
An <TT><STRONG>Open a Module Builder file...</STRONG></TT> dialog box appears.
<P>
<B><U>(3) Read in</U></B>
<TT>/usr/share/dx/samples/program_guide/averagecell.mb</TT> as follows:
<UL COMPACT>
<LI>Type the full path name in the <TT><STRONG>Filter</STRONG></TT> field of the
dialog box.
<LI>Click on (in sequence):
<UL COMPACT>
<LI>the <TT><STRONG>Filter</STRONG></TT> button
<LI>the name of the file in the <TT><STRONG>Files</STRONG></TT> field
<LI>the <TT><STRONG>OK</STRONG></TT> button.
</UL>
Information describing the inputs and output of the module (extracted
from the <TT>averagecell.mb</TT> file) appears in the
Module Builder dialog box.
</UL>
<P>
<B><U>(4) Save the .mb file</U></B> to a writable directory (use
<TT><STRONG>Save As...</STRONG></TT> in the <TT><STRONG>File</STRONG></TT>
pull-down menu).
<P>
<B><U>(5) Select</U></B> <TT><STRONG>Create All</STRONG></TT> from the
<TT><STRONG>Build</STRONG></TT> pull-down menu of the dialog box.
This option creates three files for the module: <TT>averagecell.c</TT>,
<TT>averagecell.mdf</TT>, and <TT>averagecell.make</TT>,
<P>
<B><U>(6) Implement the AverageCell function</U></B>.
<P>
Use an editor to add the following lines after "User's code goes
here" in the <TT>averagecell.c</TT> file:
<PRE>
int *itemcounts = NULL, i, neighbor;
/* make scratch space to hold the number of items added for each element */
itemcounts = DXAllocate(input_knt*sizeof(int));
if (!itemcounts)
goto error;
/*
* first initialize the output data component to zero, and itemcounts to
* zero.
*/
for (i=0; i<input_knt; i++) {
output_data[i] = 0;
itemcounts[i]=0;
}
</PRE>
<PRE>
/* for each data value, add that value to the appropriate items in the
* output data array. Also increment itemcounts for those cells.
*/
for (i=0; i<input_knt; i++) {
/* first do itself */
output_data[i]+=input_data[i];
itemcounts[i]++;
/* now do neighbors in fastest-varying dimension */
neighbor = i-1;
if (neighbor >= 0 && ((i % (c_counts[1]-1)) != 0)) {
output_data[neighbor]+=input_data[i];
itemcounts[neighbor]++;
}
</PRE>
<PRE>
neighbor = i+1;
if (neighbor < input_knt &&(((i+1)%(c_counts[1]-1)) != 0)) {
output_data[neighbor]+=input_data[i];
itemcounts[neighbor]++;
}
/* now do neighbors in the slowest-varying dimension */
neighbor = i - (c_counts[1]-1);
if (neighbor >= 0) {
output_data[neighbor]+=input_data[i];
itemcounts[neighbor]++;
}
neighbor = i + (c_counts[1]-1);
if (neighbor < input_knt) {
output_data[neighbor]+=input_data[i];
itemcounts[neighbor]++;
}
}
</PRE>
<PRE>
/* now divide by the number of items added for that cell */
for (i=0; i< input_knt; i++)
output_data[i] = output_data[i]/itemcounts[i];
DXFree((Pointer)itemcounts);
return OK;
error:
DXFree((Pointer)itemcounts);
return ERROR;
}
</PRE>
<P>
The file <TT>/usr/share/dx/samples/program_guide/averagecell.c</TT>
contains a completed version of this program.
<P>
<B><U>(7) To create a version of Data Explorer that includes</U></B> the
AverageCell module, enter the command:
<PRE>
make -f averagecell.make dxexec
</PRE>
<P>
(You have now created an executable that contains the
AverageCell module.)
<P>
<B><U>(8) To invoke this version, enter:</U></B>
<PRE>
dx -mdf ./averagecell.mdf -exec ./dxexec
</PRE>
<P>
This command starts Data Explorer (the <TT>averagecell.mdf</TT> file tells
the graphical user interface about AverageCell and its inputs
and outputs).
The executable dxexec invoked here is the one created in Step 6.
<P>
<B><U>(9) With this version of Data Explorer</U></B> you can now run any visual
program that uses the AverageCell module.
One such program is
<TT>/usr/share/dx/samples/program_guide/averagecell.net</TT>
<P><HR><B>[ <A HREF="#Top_Of_Page">Top of Page</A> | <A
HREF="progu029.htm">Previous Page</A> | <A HREF="progu031.htm">Next
Page</A> | <A HREF="../proguide.htm#ToC">Table of Contents</A> | <A
HREF="#PToC9">Partial Table of Contents</A> | <A
HREF="progu344.htm#HDRINDEX_START">Index</A> ]</B> <br><b>[<a
href="../allguide.htm">Data Explorer Documentation</a> | <a
href="../qikguide.htm">QuickStart Guide</a> | <a
href="../usrguide.htm">User's Guide</a> | <a
href="../refguide.htm">User's Reference</a> | <a
href="../proguide.htm">Programmer's Reference</a> | <a
href="../insguide.htm">Installation and Configuration
Guide</a> ]</b><br><p><b>[<a
href="http://www.research.ibm.com/dx">Data Explorer Home
Page</a>]</b><p><HR ALIGN=LEFT WIDTH=600><b>[<A
HREF="http://www.ibm.com/">IBM Home Page</A> | <A
HREF="http://www.ibm.com/Orders/">Order</A> | <A
HREF="http://www.ibm.com/Search/">Search</A> | <A
HREF="http://www.ibm.com/Assist/">Contact IBM</A> | <A
HREF="http://www.ibm.com/Legal/">Legal</A> ]</b><hr><p>
<A NAME="Bot_Of_Page"></A>
</BODY></HTML>
|