[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Swarm-Support] Problems with ObserverSwarm
From: |
Crile Doscher |
Subject: |
[Swarm-Support] Problems with ObserverSwarm |
Date: |
Sun, 02 Oct 2005 22:22:39 -0400 |
I could use a bit of help on an ObserverSwarm problem. I recently set up an
ObserverSwarm that would read the values from a Discrete2d and display them
as a ramp of colours (as Heatbugs does with HeatSpace and SugarSwarm does
with SugarSpace). Initially, the values (elevation in this case) in my
Discrete2d were read in from an ascii file and then a putValue method was
used to set the value in cell objects. I based my ObserverSwarm/Build
Objects on Heatbugs, specifically the setDiscrete2dToDisplay method:
[elevDisplay setDiscrete2dToDisplay: [modelSwarm getElevSpace]];
elevDisplay is my Value2dDisplay and ElevSpace is my Discrete2d, populated
with cell objects to hold the elevation values. (This is also how it was
done in the userbook, chapter 11 I think - more ObserverSwarm code included
below.) This was working fine until I changed the method that adds the
elevation value to each cell, opting instead for -set and -get methods to a
declared variable (elevLevel). I know that the elevLevel's are being set
correctly through printf statements but now my Value2dDisplay has gone
haywire. The error messages during a run show that ObserverSwarm is using
values that are way too high (e.g 727.60852 [correct] versus 24679175 [not
correct]). Using getValueAtX: Y: in a printf I can see that these high
values are the ones that ObserverSwarm is using while [[elevSpace
getCellAtX: Y: ] getElevLevel]; returns the correct value. I'd like to
use -get/-set if possible as there are likely to be more variables I'd like
to assign to the cells later on.
SO, my question is, is there an better syntax to get ObserverSwarm to pull
in the correct values? I've played around with something like:
[elevDisplay setDiscrete2dToDisplay: [[modelSwarm getElevSpace]] getCellAtX:
Y:] getElevLevel];
but to no avail. I'll include some relevant code below. My thanks in
advance.
Crile
DataFile.m/-inputData method - reads in data from an ascii file -based on
Paul Box's Biox model. NZMG is a local coordinate system in New Zealand:
-inputData: (int) f {
int incx, incy, x, y;
int data1, result; //for debugging
float data2;
float nzmgX, nzmgY;
float elevLevel;
fileID = f;
printf ("Importing data from fileID:%d %s..\n", fileID, fileName);
// first put nodatavalues in all the cells. Can be overwritten in
//the next steps if a cell contains information
printf("Putting nodata values in all the cells. fileID = %d\n", fileID);
//printf("bedSpace = %s\n",[bedSpace getInstanceName]);
for (incy = 0; incy < ysize; incy++){
for (incx = 0; incx < xsize; incx++) {
if (fileID == 0)
[[elev getCellAtX: incx Y: incy] setElevLevel: (float) noDataValue];
//defined in Cell
//xprint([elev getCellAtX: incx Y: incy]); //this works
//[elev putValue: (float) noDataValue atX: incx Y: incy];
//elevLevel = [elev getValueAtX: incx Y: incy];
//elevLevel = (float) noDataValue;
//printf("Elevation here (%d, %d) = %f\n", x, y, elevLevel);
data1 = [elev getValueAtX: incx Y: incy];
//data1 = [[elev getCellAtX: incx Y: incy] getElevLevel];
//printf("Elevation here (data1) = %d\n", data1);
//printf("noDataValue = %d\n", noDataValue);
}
}
//set the file's origin and end points
xOriginNZMG = xllCorner;
//printf ("xOriginNZMG = %f\n", xOriginNZMG);
//printf ("inputs: numRows = %d, numCols = %d, cellSize = %d\n", numRows,
numCols, cellSize);
//result = numRows * cellSize;
//printf("result = %d, yllCorner = %f\n", result, yllCorner);
//yOriginNZMG = yllCorner + result;
yOriginNZMG = yllCorner + (numRows*cellSize);
//printf("yOriginNZMG = %f\n", yOriginNZMG);
xEndNZMG = xllCorner + (numCols*cellSize);
//printf("xEndNZMG = %f\n", xEndNZMG);
yEndNZMG = yllCorner;
//printf ("yEndNZMG = %f\n", yEndNZMG);
//make sure the data set is overlapping the data set that defines the space
if ((xOriginNZMG>xEndM) || (xEndNZMG<xOriginM) ||
(yOriginNZMG<yEndM) || (yEndNZMG>yOriginM))
printf("Error! data set does not overlap the main data space!!!\n\n");
else {
// scan through the values until they overlap the main space,
// then input them into the corresponding cells.
nzmgX = xOriginNZMG; //start at the file's origin
nzmgY = yOriginNZMG;
//printf("nzmgX = %f, nzmgY = %f\n", nzmgX, nzmgY);
printf ("Scanning through file for data points\n");
for (incy=0; incy <numRows; incy++) {
//printf ("incy = %d, ", incy);
for (incx=0; incx < numCols; incx++) {
//printf("incx = %d\n", incx);
//scan the datapoint
//[self getDataPoint];
float datapoint;
int datapoint2;
datapoint = [self getDataPoint];
//printf("datapoint = %f\n", datapoint);
datapoint2 = (int) datapoint;
//printf("datapoint2 = %d\n", datapoint2);
//if its within the space, convert the coords to swarm
//and input the data
if ((nzmgX >= xOriginM && nzmgX <= xEndM) &&
(nzmgY <= yOriginM && nzmgY >=yEndM)) {
x = [self convertNZMGX: nzmgX];
y = [self convertNZMGY: nzmgY];
//printf("(%d, %d)\n", x, y);
if (fileID == 0)
//printf("xprint getCellAtX: here\n");
//xprint([elev getCellAtX: x Y: y]);
[[elev getCellAtX: x Y: y] setElevLevel: dataPoint];
//data2 = [elev getValueAtX: x Y: y];
data2 = [[elev getCellAtX: x Y: y] getElevLevel];
printf("Elevation here (data2) = %f\n", data2);
//[elev putValue: datapoint atX: x Y: y];
//elevLevel = [elev getValueAtX: x Y: y];
//elevLevel = datapoint;
//xprint([elev getCellAtX: x Y: y]);
//printf("Elevation @ (%d, %d) = %f\n", x, y, elevLevel);
}
//else if not within space, do nothing but scan the
//next datapoint
// move ahead one cell
//printf ("Still in the inputData method...");
nzmgX = nzmgX + cellSize;
//printf("x = %f, y = %f\n", nzmgX, nzmgY);
}
nzmgX = xOriginNZMG;
nzmgY = nzmgY - cellSize;
//printf("x = %f, y = %f\n", nzmgX, nzmgY);
}
} //end else (data overlaps main data set)
printf ("successfully scanned data file\n\n");
return self;
}
ObserverSwarm.m/buildObjects excerpt; cumecs are my agents moving about on
the elevation grid. cumecDisplay works fine:
(some code not incluced here)
[modelSwarm buildObjects];
// Create a colormap: this is a global resource, the information
// here is used by lots of different objects.
printf ("colormap here\n");
colormap = [Colormap create: [self getZone]];
//colours [0,90) are assigned to the gray range - darker means lower
//code based on HeatbugObserverSwarm.m
for (i = 0; i < 90; i++)
[colormap setColor: i ToRed: (double)i / 89.0 Green: (double) i / 89.0
Blue: (double) i / 89.0];
//colour 90 is set to blue for cumec display
[colormap setColor: 91 ToName: "blue"];
[[modelSwarm getCumecList] forEach: M(setCumecColor:) : (id) 91];
// create the 2d window
worldRaster = [ZoomRaster create: [self getZone]];
[worldRaster setColormap: colormap];
[[[worldRaster setWidth: [[modelSwarm getBed] getSizeX]
Height: [[modelSwarm getBed] getSizeY]]
setZoomFactor: zoomFactor]
setWindowTitle: "MultiGridDrop"];
// draw the window.
[worldRaster pack];
//create a Value2dDisplay for the elevation values
elevDisplay = [Value2dDisplay createBegin: self];
[elevDisplay setDisplayWidget: worldRaster colormap: colormap];
[elevDisplay setDiscrete2dToDisplay: [modelSwarm getElevSpace]];
[elevDisplay setDisplayMappingM: 11 C: 0];
cumecDisplay = [Object2dDisplay createBegin: self];
[cumecDisplay setDisplayWidget: worldRaster];
[cumecDisplay setDiscrete2dToDisplay: [modelSwarm getBed]];
[cumecDisplay setDisplayMessage: M(drawSelfOn:)];
[cumecDisplay setObjectCollection: [modelSwarm getCumecList]];
- [Swarm-Support] Problems with ObserverSwarm,
Crile Doscher <=