swarm-support
[Top][All Lists]
Advanced

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

Re: Mapping float values to colors.


From: Fabio Mascelloni
Subject: Re: Mapping float values to colors.
Date: Tue, 27 Jul 1999 23:45:40 +0200

"Marcus G. Daniels" wrote:
>
>
> In the latter case, how about putting the setColormap: after you do
>  the color assignments?

It gives a STATUS_ACCESS_VIOLATION and gdb stops saying;

Program received signal SIGSEV ,Segmentation fault
0x421ab0 in dib_augmentPalette (dib=0x29bb4d8 , object=0x29b6fe0,
                                                     colormapSize=64 ,
colormap=0x29be158 )
                                  at
/src/swarm-1.4.1/src/tkobj/win32dib.c:277
                                    in
/src/swarm-1.4.1/src/tkobj/win32dib.c

   I insert some code snippets to help you understand more:

- buildObjects
{
        
        unsigned i,j,number=0;
        
        [super buildObjects];
        
        CREATE_ARCHIVED_PROBE_DISPLAY (self);
        
        //Stop the simulation to allow values initialization through
probes
        [controlPanel setStateStopped];
        
        //Opens the file to retrieve the matrices
        if ((dataFile=fopen(dataFileName,"r"))==NULL)
        {
                printf ("Error :could not open file %s\n",dataFileName);
                exit(1);
        }
        
        //Gets the matrix dimension:it's the firs line of the file
        fscanf(dataFile,"%u",&matrixDim);
        
        //Allocates the matrix and initializes it to 0
        data_sum= calloc(matrixDim*matrixDim,sizeof(unsigned));
        
        //Creates the initial ColorMap
        initialcmap = [Colormap create: self ];
        
        //Initializes the ColorMap
        for (i=0;i<matrixDim;i++)
                for (j=0;j<matrixDim;j++)
                {
                        [initialcmap setColor: number ToRed:0 Green:0 Blue:0];
                        number++;
                }
        
        //Creates the Raster to display values
        dsplRaster=[ZoomRaster createBegin: [self getZone]];
        SET_WINDOW_GEOMETRY_RECORD_NAME (dsplRaster);
        dsplRaster=[dsplRaster createEnd];
        [dsplRaster setColormap: initialcmap];
        [dsplRaster setZoomFactor:4];
        [dsplRaster setWidth: matrixDim Height:matrixDim];
        [dsplRaster setWindowTitle:"Coalitional Structure Over Time"];
        [dsplRaster pack];
        
        return self;
}

//Loads a new matrix from the file previously opened an adds it to the
partial sum
- loadData
{
        unsigned i,j;
        unsigned tempValue;
        
        for (i=0;i<matrixDim;i++)
                for (j=0;j<matrixDim;j++)
                {
                        fscanf(dataFile,"%u",&tempValue);
                        *(data_sum+matrixDim*i+j) +=tempValue;
                }
                iterations++;
                                
                return self;
}

- update
{
                unsigned i,j;
                unsigned currentColor=0;
                double red;
                id <Colormap>   cmap;
                id <Zone> newZone;

                //Creates the ColorMap in a separate memory Zone
                newZone=[Zone create:[self getZone]];
                cmap = [Colormap create: newZone ];

                for (i=0;i<matrixDim;i++)
                        for (j=0;j<matrixDim;j++)
                        {
                                
                                //Assigns to red variable the mean value
                                red=(double)
*(data_sum+matrixDim*i+j)/iterations;
                                
                                [cmap setColor: currentColor ToRed: red Green:0 
Blue:0];
                                
                                [dsplRaster drawPointX: i Y: j Color: 
currentColor];
                        
                          currentColor++;
                        }
                        
                        [dsplRaster setColormap: cmap];
                        [dsplRaster drawSelf];
                        [newZone drop];

                        return self;
}

- buildActions
{
        [super buildActions];
        
        dsplActions=[ActionGroup create: [self getZone]];
        
        [dsplActions createActionTo: self message: M(loadData)];
        [dsplActions createActionTo: self message: M(update)];
        
        [dsplActions createActionTo: probeDisplayManager message:
M(update)];

        [dsplActions createActionTo: actionCache message: M(doTkEvents)];
        
        
        dsplSchedule=[Schedule createBegin:[self getZone]];
        [dsplSchedule setRepeatInterval: displayFrequency];
        dsplSchedule = [dsplSchedule createEnd];
        [dsplSchedule at: 0 createAction: dsplActions];
  
  return self;
}

- activateIn: swarmContext
{
        
        [super activateIn: swarmContext];       
        
        [dsplSchedule activateIn:self];
        
        return [self getActivity];
}

Fabio.

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

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