swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

problem with raster


From: Kevin Crowston
Subject: problem with raster
Date: Thu, 6 Mar 1997 16:49:10 -0500

I'm trying to draw a network on a Raster widget.  I'm running into a few
problems.

First, some code:

I create the Raster in the buildObjects method of the observer swarm, as
follows (copied from Heatbugs):

  // Next, create a 2d window for display, set its size, zoom factor, title.
  bestRaster = [ZoomRaster create: [self getZone]];
  [bestRaster setColormap: colormap];
  [bestRaster setZoomFactor: 1];
  [bestRaster setWindowTitle: "Best solution"];
  [bestRaster pack];                              // draw the window.

In buildActions, I schedule some updates for it, again copied from HB:

  // and of the various GUI items
  [displayActions createActionTo: averageGraph message: M(step)] ;
  [displayActions createActionTo: bestGraph message: M(step)] ;
  [displayActions createActionTo: self message: M(drawBest)] ;
  [displayActions createActionTo: bestRaster message: M(drawSelf)] ;

Method drawBest just asks the model for the best solution seen so far and
tells that solution to display itself:

-drawBest {
  [[tspModelSwarm getBestSolution] displayOn: bestRaster] ;
  return self ;
}

Each "bestSolution" is returned as expected and method displayOn does get
called when I expect, as shown by traces.  To draw, the displayOn method
tries to scale the X,Y coordinates of each node to the actual size of the
Raster available, as shown in this fragment (AMOUNT_TO_USE is 0.95):


-displayOn: (Raster *) aRaster {
  int i ;
  float scale, scaleX, offsetX, offsetY ;

#ifdef DEBUG
  printf("Raster has height %d width %d\n", [aRaster getHeight],
         [aRaster getWidth]) ;
  printf("Y max = %f, min = %f\n", maxY, minY) ;
  printf("X max = %f, min = %f\n", maxX, minX) ;
#endif

  // start by calculating a scaling factor so we'll fit
  scale = AMOUNT_TO_USE * [aRaster getHeight] / (maxY - minY) ;
  scaleX = AMOUNT_TO_USE * [aRaster getWidth] / (maxX - minX) ;
  if ( scaleX < scale ) scale = scaleX ;
...

The major problem is the getHeight and getWidth always return 3 instead of
the actual height and width of the Raster.  I tried intercepting these
calls using gdb to return 300 instead of 3 and it worked okay.  Clearly
this isn't a problem for Heatbug, but I'm not sure what I'm doing
differently or not doing right.

The second problem might be minor:  I tried writing a test program that
just drew some stuff on a Raster, aka the testRaster program, but it was
odd:  it drew the points, then immediately erased them.  This seems not to
be a problem in the fully swarmy version.

Kevin




reply via email to

[Prev in Thread] Current Thread [Next in Thread]