Images and Image Data

Phil Davis phildavis at attbi.com
Thu Jul 4 23:53:01 EDT 2002


Hi Michael,

----- Original Message ----- 
From: "Michael Crawford" <michael.crawford at stonebow.otago.ac.nz>
To: <metacard at lists.runrev.com>
Sent: Thursday, July 04, 2002 7:08 PM
Subject: Re: Images and Image Data


> 
> 
> Hello,
> 
> 
> I have modified my script to produce the appropriate image and it works
> perfectly apart from one thing...
> 
> 
> The script looks like this. Basically it loops across some tab delimited
> data (which is elevation data, that is a height measurement). If that point
> is above 0, ie above sealevel it makes it green (ie solid land). If it is 0
> or below zero it makes it blue (ie under water)
> 
> on mouseUp
>   ## get the data
>   put fld "data" into tOrigData
>   set the itemdelimiter to TAB
> 
>   put 571 into twidth -- data is 571 across
>   put 429 into tHeight -- data is 429 lines in height
> 
>   ## create the image
>   create image
>   put it into tID
> 
>   set the width of tID to tWidth
>   set the height of tID to tHeight
> 
>   put empty into iData
>   repeat with j = 1 to tHeight
>     repeat with i = 1 to tWidth
>       put item i of line j of tOrigData into tDataValue
>       if tDataValue > 0 then  -- above sea level
>         put binaryEncode("CCCC",0,0,255,0) after iData ---make green
>       else -- point is below sea level
>         put binaryEncode("CCCC",0,0,0,255) after iData  --- make blue
>       end if
>     end repeat
>   end repeat
>   set the imageData of tID to iData
> end mouseUp
> 
> 
> The only problem is the speed of execution. It is painfully slow. A bit of
> checking reveals that it is the line:
> 
> put item i of line j of tOrigData into tDataValue
> 
> 
> that is causing the bottleneck. There must be a better way to do this? In
> the past I have never really bothered optimising these sort of repeat loops
> as it has always been fast enough for me. With 571 x 429 data points though
> it is just too slow. Does any one have any suggestions?
> 

Change your repeat loop section to look like this:

  repeat for each line tCurrentLine in tOrigData
    repeat for each item tCurrentItem in tCurrentLine
      put tCurrentItem into tDataValue
      if tDataValue > 0 then  -- above sea level
        put binaryEncode("CCCC",0,0,255,0) after iData ---make green
      else -- point is below sea level
        put binaryEncode("CCCC",0,0,0,255) after iData  --- make blue
      end if
    end repeat
  end repeat


This should be a lot faster (though I didn't try it). It reduces MC's work significantly each pass through the loop.

Phil Davis

> 
> Thanks
> 
> 
> Michael Crawford
> 
> 
> _______________________________________________
> metacard mailing list
> metacard at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/metacard




More information about the metacard mailing list