-
-
Notifications
You must be signed in to change notification settings - Fork 363
man: Improve segment library documentation, provide examples #20
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
base: main
Are you sure you want to change the base?
Conversation
|
||
/* determine the input map type (CELL/FCELL/DCELL) */ | ||
map_type = Rast_map_type(input_name, ""); | ||
size_t cell_size = Rast_cell_size(map_type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move "size_t cell_size;" up, just after "RASTER_MAP_TYPE map_type;"
ncols = Rast_window_cols(); | ||
|
||
/* size of a segment */ | ||
int srows = 64; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move "int srows, scols, num_seg;" up
int num_seg = 4; | ||
|
||
/* segment structure */ | ||
SEGMENT raster_seg; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move "SEGMENT raster_seg;" up
|
||
/* pass the pointer, set the value */ | ||
Segment_put(raster_seg, values, row, col); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- G_free(values):
ncols = Rast_window_cols(); | ||
|
||
/* size of a segment */ | ||
int srows = 64; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as for r.example.segment, move int srows, sclos, nsegs; up
int nsegs = 4; | ||
|
||
map_type = DCELL_TYPE; | ||
size_t cell_size = Rast_cell_size(map_type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move "size_t cell_size, segment_cell_size;" up
output_fd = Rast_open_new(output_name, map_type); | ||
|
||
/* segment structure */ | ||
SEGMENT raster_seg; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move up
G_fatal_error(_("Unable to create temporary segment file")); | ||
|
||
/* array to store file descriptors */ | ||
int *input_fds = G_malloc(ninputs * sizeof(int)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move "int *input_fds;" up
} | ||
|
||
/* allocate input buffer */ | ||
DCELL *row_buffer = Rast_allocate_d_buf(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move "DCELL *row_buffer, *seg_buffer;" up
|
||
/* pass the pointer, set the value */ | ||
Segment_put(raster_seg, values, row, col); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- G_free(values);
|
||
<em> | ||
<a href="r.example.html">r.example</a> | ||
<a href="r.example.html">r.example.segment</a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r.example.segment.html
* <b>Buf</b> will be filled with <em>ncols*len</em> bytes of data | ||
* corresponding to the <b>row</b> in the data matrix. | ||
* \pre *buf* points to an allocated array of length <em>ncols*len</em> | ||
* where *len* is size of one stored value (cell). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.g. cell or a custom data structure
* Segment_init(), all-in-memory mode initialization, and temporary | ||
* file handling. | ||
* | ||
* The values are not guaranteed to be initialized to zero or NULL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not values, but bytes, they are indeed initialized to zero because of lseek and calloc
the raster you need to access: | ||
|
||
\code | ||
for (int row = 0; row < Rast_window_rows(); row++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (int row = 0; ...) is C++ style
|
||
\skip G_free | ||
\until Rast_close(output_fd); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Segment_close() ?
Please use standard C style in sample code.
See "man calloc". malloc does not initialize the memory while calloc does.
No.
Yes, that's the reason: Segment_get_row() bypasses the internal cache and reads directly from the temporary file. |
Considering examples on how to use the segment library, it is IMHO sufficient to mention current working modules like r.cost, r.walk, r.watershed, r.stream.extract. |
Jumping into this discussion a bit late, so just two short comments:
I don't think this has been done as such in the code doc, yet, but maybe we could just add specific references to the existing production modules directly into the doc ? |
Note to myself: It seems that it worth explicitly noting that functions such as |
@wenzeslaus would you mind to rebase this PR? |
@wenzeslaus I manually resolved the conflicts |
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wenzeslaus is this still relevant now? It is currently in a state where it up to date enough to pass CI, but there are still some very old (6 years) review comments.
Also, could you take a new look, to tell us if it still shows the patterns we want to show as an example?
It's kind of funny to still see the issue/pr number #20, that is still open. Probably the oldest we have open. Edit: it is the oldest open PR or issue we have
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is our oldest open PR, number 20. We have to port the docs changes in HTML to markdown. Also, since the last update of the PR, the folder structure changed (in early January 2025, in #4815)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember to apply the changes in a new markdown file when updating the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember to apply the changes in a new markdown file when updating the PR.
This PR adds two examples into
doc/examples
which can be compiled as GRASS modules and executed. It adds 3 new sections to the library dox file: about general use with raster, about use with list of rasters (includes portions of one of the examples, so the code is only at one place), and a complete example (here including whole files). Finally, it modifies documentation for two functions.Besides asking for general review of best practices in using this library, I'm asking these two questions:
Segment_get_row()
? DoesSegment_get()
need the same one?Segment_flush()
description suggests that only writing to disk andSegment_get_row()
need that andSegment_get_row()
does not call any page function if that has any influence.