PGM Map - Visualization Error

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

PGM Map - Visualization Error

Gerardo Leo
​In my model I am using the PGM reader implemented in the SugarScape example to load the the environment map.
The problem is that RePast use to exchange the X dimension with the Y dimension in the 2D interface (drawn using the SugarSpace SurfaceStyle). 

Basically the map is supposed to be visualized like this:



But actually it is like this:



This is not such a big problem is if x and y are equal, like in that example (where both dimensions are 50), but if the x and y are different the loaded map is totally wrong, of course.

How can I fix this problem ? 

Thank you very much, best.
Gerardo 

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|

Re: PGM Map - Visualization Error

srcnick
Can you create a new PGM file where the x and y are swapped? The PGM will be reversed but the PGM reader should then reverse that again so its correct.

Nick

> On Nov 3, 2016, at 12:30 PM, Gerardo Leo <[hidden email]> wrote:
>
> ​In my model I am using the PGM reader implemented in the SugarScape example to load the the environment map.
> The problem is that RePast use to exchange the X dimension with the Y dimension in the 2D interface (drawn using the SugarSpace SurfaceStyle).
>
> Basically the map is supposed to be visualized like this:
> ​
> <map.png>
>
> But actually it is like this:
>
> <map2.png>
>
> This is not such a big problem is if x and y are equal, like in that example (where both dimensions are 50), but if the x and y are different the loaded map is totally wrong, of course.
>
> How can I fix this problem ?
>
> Thank you very much, best.
> Gerardo
> ------------------------------------------------------------------------------
> Developer Access Program for Intel Xeon Phi Processors
> Access to Intel Xeon Phi processor-based developer platforms.
> With one year of Intel Parallel Studio XE.
> Training and support from Colfax.
> Order your platform today. http://sdm.link/xeonphi_______________________________________________
> Repast-interest mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/repast-interest


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|

Re: PGM Map - Visualization Error

Gerardo Leo
Yes, I thought to this solution, but I'd prefer don't do it (if possible), because I already have a lot of very big maps and draw them again would take me forever.

Thanks,
Gerardo
Reply | Threaded
Open this post in threaded view
|

Re: PGM Map - Visualization Error

Gerardo Leo
In reply to this post by srcnick
I made a test, and actually i figured out that this is not the right solution because my problem is not the map orientation. Indeed even if I swap the x and y in my pgm file, repast will swap it again and if x and y are not equal it draws a wrong map.

If for example I draw a square, there is no problem because the only orientation would be changed, but I don't care about it.

Basically my pgm file is this:


But I visualize this (totally wrong):


Sorry, but I was not clear enough before.

Thanks,
Gerardo
Reply | Threaded
Open this post in threaded view
|

Re: PGM Map - Visualization Error

Tatara, Eric R.
In reply to this post by Gerardo Leo
Gerardo,

You need to make two changes in the code to get the Repast display to match the PGM file.  First, the PGMReader class in the Sugarscape example has a bug around line 70 where it assigns the x,y values to the matrix.  You need to swap the order of the matrix index assignment from

for (int i = 0; i < xSize; i++)
     for (int j = 0; j < ySize; j++)
          matrix[i][j] = Integer.valueOf(tok.nextToken());

to

for (int j = 0; j < ySize; j++)
     for (int i = 0; i < xSize; i++)
          matrix[i][j] = Integer.valueOf(tok.nextToken());

This will set the values in the matrix to match the order in the PGM file.

Second, the Repast 2D display has it's (0,0) coordinate in the lower left corner but PGM uses the top left corner for (0,0), so if you want the Repast display to match how the PGM file looks, you need to swap the y-axis order which can be done in the code, for example:

for (int x = 0; x < xdim; x++) {
     for (int y = 0; y < ydim; y++) {       
          currentSugar.set(matrix[x][y], x, ydim-y-1);
     }
}
 
Note the assignment to the value layer at "ydim-y-1".

Eric Tatara, PhD, PE
Software Engineer
Global Security Sciences Division
Argonne National Laboratory

From: Gerardo Leo [[hidden email]]
Sent: Thursday, November 03, 2016 11:30 AM
To: [hidden email]
Subject: [Repast-interest] PGM Map - Visualization Error

​In my model I am using the PGM reader implemented in the SugarScape example to load the the environment map.
The problem is that RePast use to exchange the X dimension with the Y dimension in the 2D interface (drawn using the SugarSpace SurfaceStyle). 

Basically the map is supposed to be visualized like this:



But actually it is like this:



This is not such a big problem is if x and y are equal, like in that example (where both dimensions are 50), but if the x and y are different the loaded map is totally wrong, of course.

How can I fix this problem ? 

Thank you very much, best.
Gerardo 

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|

Re: PGM Map - Visualization Error

Gerardo Leo
Hello Eric, thank you very much for your help, it has been definitely useful, now it works.
I didn't know about the different position of the (0,0) coordinate in repast and PGM, now it makes sense.

Thank you again,
Gerardo