Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

d.rast.num: Constrain rendering within the current display extent in the wx monitor #3489

Merged
merged 3 commits into from
Mar 14, 2024

Conversation

HuidaeCho
Copy link
Member

@HuidaeCho HuidaeCho commented Mar 12, 2024

This PR uses #3482 to allow displaying raster numbers for a smaller display extent (not computational region) than the suggested 200x200. Do we still want this limitation when d.rast.arrow doesn't have any or should we add the same limit to d.rast.arrow?

@github-actions github-actions bot added C Related code is in C module display labels Mar 12, 2024
@neteler neteler added this to the 8.4.0 milestone Mar 12, 2024
@HuidaeCho HuidaeCho self-assigned this Mar 12, 2024
@HuidaeCho HuidaeCho added GUI wxGUI related raster Related to raster data processing enhancement New feature or request labels Mar 12, 2024
@github-actions github-actions bot removed GUI wxGUI related raster Related to raster data processing labels Mar 12, 2024
echoix
echoix previously approved these changes Mar 13, 2024
Copy link
Member

@echoix echoix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the same pattern as #3491 and #3492 that I understood, but here the logic is done a bit earlier, but after calling the parser. I don't see an obvious reason why it should shouldn't work: it is shortcircuiting extra validation steps if it will be entered again in a second pass.

@wenzeslaus
Copy link
Member

Do we still want this limitation when d.rast.arrow doesn't have any or should we add the same limit to d.rast.arrow?

The limitation works very poorly in GUI and it does not makes sense in number of cells because what really matters is the size of a cell in rendered pixes. We probably don't what to go that direction and we don't want to keep increasing the limit based on available hardware. Overall, it would be great if you can remove it as part of this update.

@HuidaeCho
Copy link
Member Author

HuidaeCho commented Mar 14, 2024

It seems the same pattern as #3491 and #3492 that I understood, but here the logic is done a bit earlier, but after calling the parser. I don't see an obvious reason why it should work: it is shortcircuiting extra validation steps if it will be entered again in a second pass.

All three PRs have the same pattern: D_open_driver() after G_parser() and before G_get_window(), in d.rast.(arrow|num), to grab GRASS_REGION.

  1. d.* modules run from the terminal (no GRASS_REGION defined)
  2. D_open_driver() spawns render.py and exits if GRASS_RENDER_IMMEDIATE is not defined (not defined in the terminal) and either (not both) GRASS_RENDER_COMMAND or MONITOR is defined. In this case, MONITOR is defined so render.py will be spawned, which will run the same display module in its render().
  3. That same display module still cannot see GRASS_REGION because its parent render.py was spawned from the terminal, but this time, the monitor's render.py read in env file which contains GRASS_RENDER_IMMEDIATE. Now because GRASS_RENDER_IMMEDIATE and MONITOR are defined, D_open_driver() doesn't spawn render.py again and goes on to check GRASS_REGION and return -1 (GRASS_REGION not available in the terminal yet)
  4. In step 3, when render.py was called, it added the command line for the display module to the cmd file, which the monitor GUI (gui/wxpython/mapdisp/main.py) checks in its watcher every 0.5 second and triggers an event for rendering all layers in GetLayersFromCmdFile().
  5. GetLayersFromCmdFile() above executes all display commands in the cmd file, but now with the display extent defined in GRASS_REGION.
  6. Every display module calls D_open_driver(), which will now return 0 because GRASS_REGION is defined from the GUI.
  7. Rendering occurs happily and quickly only within GRASS_REGION.
  8. Any further changes to GRASS_REGION within the monitor GUI will move to step 5.

@echoix
Copy link
Member

echoix commented Mar 14, 2024

It seems the same pattern as #3491 and #3492 that I understood, but here the logic is done a bit earlier, but after calling the parser. I don't see an obvious reason why it should work: it is shortcircuiting extra validation steps if it will be entered again in a second pass.

I'm so sorry, I thought I wrote:

I don't see an obvious reason why it shouldn't work. Probably an autocorrect thing.

@HuidaeCho
Copy link
Member Author

It seems the same pattern as #3491 and #3492 that I understood, but here the logic is done a bit earlier, but after calling the parser. I don't see an obvious reason why it should work: it is shortcircuiting extra validation steps if it will be entered again in a second pass.

I'm so sorry, I thought I wrote:

I don't see an obvious reason why it shouldn't work. Probably an autocorrect thing.

No problem. Now we have more detail documentation about how D_open_driver() works. ;-).

@echoix
Copy link
Member

echoix commented Mar 14, 2024

Thanks for the very detailed and simple explanations! It'll take some time until I master a bit of every part of GRASS, but it's a good start, and way easier in words like this, I'm lucky for it!

My initial comment when "approving" was to highlight the way I thought it was ok, from the two previous, a bit like a proof by mathematical induction, since there was something that prevented me to say it's exactly the same.

@neteler
Copy link
Member

neteler commented Mar 14, 2024

Now we have more detail documentation about how D_open_driver() works. ;-).

Thanks for writing it up! Would it make sense to move it to the doxygen section as it is easily lost in a PR discussion?
Like here: https://grass.osgeo.org/programming8/displaylib.html

@HuidaeCho HuidaeCho changed the title d.rast.num: Use GRASS_REGION to constrain rendering within the current display extent d.rast.num: Constrain rendering within the current display extent in the wx monitor Mar 14, 2024
@HuidaeCho
Copy link
Member Author

Now we have more detail documentation about how D_open_driver() works. ;-).

Thanks for writing it up! Would it make sense to move it to the doxygen section as it is easily lost in a PR discussion? Like here: https://grass.osgeo.org/programming8/displaylib.html

Now with #3500, it's much simpler from the developer's perspective. No special consideration is necessary.

Copy link
Member

@wenzeslaus wenzeslaus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Opening the driver should happen right after the parser given the monitor architecture.

@HuidaeCho
Copy link
Member Author

HuidaeCho commented Mar 14, 2024

Do we still want this limitation when d.rast.arrow doesn't have any or should we add the same limit to d.rast.arrow?

The limitation works very poorly in GUI and it does not makes sense in number of cells because what really matters is the size of a cell in rendered pixes. We probably don't what to go that direction and we don't want to keep increasing the limit based on available hardware. Overall, it would be great if you can remove it as part of this update.

Actually, the -a flag uses the number of raster cells always and "Constrain display resolution to computational settings" does a similar thing with computational resolution without this flag. Based on my test, the only time it uses the number of pixels is without these two, but then you'll just see a black (or green) rectangle because d.rast.num (or d.rast.arrow) just draws numbers (or arrows) per pixel, which doesn't make sense.

Without

if ((nrows > 75) || (ncols > 75)) {
G_asprintf(&tmpstr1, n_("%d row", "%d rows", nrows), nrows);
G_asprintf(&tmpstr2, n_("%d col", "%d cols", ncols), ncols);
/* GTC %s will be replaced by strings "X rows" and "Y cols" */
G_warning(_("Current region size: %s X %s\n"
"Your current region setting may be too large. "
"Cells displayed on your graphics window may be too "
"small for cell category number to be visible."),
tmpstr1, tmpstr2);
G_free(tmpstr1);
G_free(tmpstr2);
}
if ((nrows > 200) || (ncols > 200)) {
G_fatal_error(_("Aborting (region larger then 200 rows X 200 cols is "
"not allowed)"));
}

# in NC sample dataset
d.mon wx0
g.region rast=elevation
d.rast elevation
d.rast.num elevation

produces
image
and is slow.

I think this limitation can be useful if it is customizable using either a module parameter or an environment variable. For example, if a raster map is large with a lot of cells, it will automatically not render at a scale closer to its full region and will start rendering when the map is zoomed in closely. Like min and max visibility scales. It'll help with accidental zoom out and this has happened a lot to me in g.gui with d.rast.arrow (I had to kill it manually from the terminal).

@HuidaeCho HuidaeCho merged commit 827f988 into OSGeo:main Mar 14, 2024
25 checks passed
@HuidaeCho HuidaeCho deleted the d_rast_num_use_grass_region branch March 14, 2024 20:30
@wenzeslaus
Copy link
Member

Some "smart" behavior (aka heuristic) as default combined with a way to pick behavior manually by parameter is a solution I have seen working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C Related code is in C display enhancement New feature or request module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants