swarm-support
[Top][All Lists]
Advanced

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

Mapping float values to colors.


From: Fabio Mascelloni
Subject: Mapping float values to colors.
Date: Tue, 27 Jul 1999 21:25:29 +0200

Given the sum of  m  n*n matrices whose elements can assume the two values 0 or 1, I've to compute the mean of  every element of the resulting matrix ,that is  sum[i][j]/m  i,j:0..n , assign each mean value a color ,and display it on a Raster using a Colormap.The first problem is that only mappings from unsigned chars (Color typedef) to Red,Green,Blue values are permitted to build a Colormap,the second is that everytime a new matrix is addeded
the mean values obviously change,so a new Colormap should be created to replace the old one , and assigned to the Raster.
I thought I could remap values to colors in this way:

- updateRaster
{
   unsigned row,column;
   unsigned current_element=0;

  for (row=0 ; row <matrixDim ;row++)
        for (column=0 ; column <matrixDim ; column++)
            {
                [colMap setColor: currentelement  ToRed:  (double) new_mean[i][j]  Green:0  Blue:0];
                [dsplRaster drawPointX: i  Y:  j Color: currentelement];
               current_element++;
            }
   [dsplRaster drawSelf];
   return self;
}
But Colormap seems to dislike the re-assignement of the colors.

Then I thought to rebuild the Colormap each time,creating it in its own Zone,which was dropped after the raster
had been updated:
- updateRaster
{
   unsigned row,column;
   unsigned current_element=0;
   id <Colormap> colMap;
   id <Zone> newZone;

  newZone=[Zone create:[self getZOne]];
 colMap=[Colormap create: newZone];
 [dsplRaster setColorMap: colMap];

  for (row=0 ; row <matrixDim ;row++)
        for (column=0 ; column <matrixDim ; column++)
            {
                [colMap setColor: currentelement  ToRed:  (double) new_mean[i][j]  Green:0  Blue:0];
                [dsplRaster drawPointX: i  Y:  j Color: currentelement];
               current_element++;
            }
  [dsplRaster drawSelf];
  [newZone drop];
  return self;
}
This method doesn't work too.
So,can you tell me where did I go wrong and how can I could face this problem?
Thanks in advance,Fabio.
 
 
 
 
 
 
 


reply via email to

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