[GRASS-dev] Rast_add_d_colour

Hi,

I am working on beautifying the output of i.theilsen, a new addon.

For some reason, I cannot apply a grayscale palette.

···

Yann Chemin wrote:

Hi,

I am working on beautifying the output of i.theilsen, a new addon.

For some reason, I cannot apply a grayscale palette.
---------------
Rast_init_colors(&colors);
DCELL val1 = ts_min;
DCELL val2 = ceil(ts_max);
Rast_add_d_color_rule(&val1, 0, 0, 0, &val2, 255, 255, 255, &colors);
---------------

ts_min, ts_max are known from the data processed,
val1 and val2 are declared as DCELL instead of const DCELL as required,
but if I declare const DCELL val1, then I cannot write stats to it for
palette definition...

What I am doing wrong?

If you declare const DCELL val1, you can not pass a pointer to val1 to
another function, because this other function could then easily modify
to contents of that pointer. Rast_add_d_color_rule() requires const
DCELL *, not const DCELL.

Markus M

On Sat, Dec 6, 2014 at 3:59 PM, Markus Metz <markus.metz.giswork@gmail.com>
wrote:

Yann Chemin wrote:
> Hi,
>
> I am working on beautifying the output of i.theilsen, a new addon.
>
> For some reason, I cannot apply a grayscale palette.
> ---------------
> Rast_init_colors(&colors);
> DCELL val1 = ts_min;
> DCELL val2 = ceil(ts_max);
> Rast_add_d_color_rule(&val1, 0, 0, 0, &val2, 255, 255, 255, &colors);
> ---------------
>
> ts_min, ts_max are known from the data processed,
> val1 and val2 are declared as DCELL instead of const DCELL as required,
> but if I declare const DCELL val1, then I cannot write stats to it for
> palette definition...
>
> What I am doing wrong?

If you declare const DCELL val1, you can not pass a pointer to val1 to
another function, because this other function could then easily modify
to contents of that pointer.

This is of course true.

Rast_add_d_color_rule() requires const
DCELL *, not const DCELL.

Strange, (generated) documentation says const DCELL * [1] which fits with
the source code [2, 3].

I haven't tried compile anything now but isn't `const DCELL` constant
(value) and `const DCELL *` pointer to constant value. While `const DCELL *
const` would be constant pointer to constant value.

Also

const DCELL val;
const DCELL * pval = &val;

should work and carry on the constness which is exactly what should be
happening when calling the Rast_add_d_color_rule() function.

So, I don't understand.

Vaclav

[1]
http://grass.osgeo.org/programming7/color__rule_8c.html#a160535a46694589674f68c60eac23a05
[2] lib/raster/color_rule.c:35:void Rast_add_d_color_rule(const DCELL *
val1, int r1, int g1, int b1, ...
[3] include/defs/raster.h:198:void Rast_add_d_color_rule(const DCELL *,
int, int, int, ...

Markus M
_______________________________________________
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

Thanks,
Will try again today.

···

On Sat, Dec 6, 2014 at 3:59 PM, Markus Metz <markus.metz.giswork@gmail.com> wrote:

Yann Chemin wrote:

Hi,

I am working on beautifying the output of i.theilsen, a new addon.

For some reason, I cannot apply a grayscale palette.

Rast_init_colors(&colors);
DCELL val1 = ts_min;
DCELL val2 = ceil(ts_max);
Rast_add_d_color_rule(&val1, 0, 0, 0, &val2, 255, 255, 255, &colors);

ts_min, ts_max are known from the data processed,
val1 and val2 are declared as DCELL instead of const DCELL as required,
but if I declare const DCELL val1, then I cannot write stats to it for
palette definition…

What I am doing wrong?

If you declare const DCELL val1, you can not pass a pointer to val1 to
another function, because this other function could then easily modify
to contents of that pointer.

This is of course true.

Rast_add_d_color_rule() requires const
DCELL *, not const DCELL.

Strange, (generated) documentation says const DCELL * [1] which fits with the source code [2, 3].

I haven’t tried compile anything now but isn’t const DCELL constant (value) and const DCELL * pointer to constant value. While const DCELL * const would be constant pointer to constant value.

Also

const DCELL val;
const DCELL * pval = &val;

should work and carry on the constness which is exactly what should be happening when calling the Rast_add_d_color_rule() function.

So, I don’t understand.

Vaclav

[1] http://grass.osgeo.org/programming7/color__rule_8c.html#a160535a46694589674f68c60eac23a05
[2] lib/raster/color_rule.c:35:void Rast_add_d_color_rule(const DCELL * val1, int r1, int g1, int b1, …
[3] include/defs/raster.h:198:void Rast_add_d_color_rule(const DCELL *, int, int, int, …

Markus M


grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

OK, I found why I got lost in all that…

there is no file appearing in colr/ with the rules made in the code.

···

On 7 December 2014 at 06:51, Yann Chemin <ychemin@gmail.com> wrote:

Thanks,
Will try again today.

On Dec 7, 2014 3:36 AM, “Vaclav Petras” <wenzeslaus@gmail.com> wrote:

On Sat, Dec 6, 2014 at 3:59 PM, Markus Metz <markus.metz.giswork@gmail.com> wrote:

Yann Chemin wrote:

Hi,

I am working on beautifying the output of i.theilsen, a new addon.

For some reason, I cannot apply a grayscale palette.

Rast_init_colors(&colors);
DCELL val1 = ts_min;
DCELL val2 = ceil(ts_max);
Rast_add_d_color_rule(&val1, 0, 0, 0, &val2, 255, 255, 255, &colors);

ts_min, ts_max are known from the data processed,
val1 and val2 are declared as DCELL instead of const DCELL as required,
but if I declare const DCELL val1, then I cannot write stats to it for
palette definition…

What I am doing wrong?

If you declare const DCELL val1, you can not pass a pointer to val1 to
another function, because this other function could then easily modify
to contents of that pointer.

This is of course true.

Rast_add_d_color_rule() requires const
DCELL *, not const DCELL.

Strange, (generated) documentation says const DCELL * [1] which fits with the source code [2, 3].

I haven’t tried compile anything now but isn’t const DCELL constant (value) and const DCELL * pointer to constant value. While const DCELL * const would be constant pointer to constant value.

Also

const DCELL val;
const DCELL * pval = &val;

should work and carry on the constness which is exactly what should be happening when calling the Rast_add_d_color_rule() function.

So, I don’t understand.

Vaclav

[1] http://grass.osgeo.org/programming7/color__rule_8c.html#a160535a46694589674f68c60eac23a05
[2] lib/raster/color_rule.c:35:void Rast_add_d_color_rule(const DCELL * val1, int r1, int g1, int b1, …
[3] include/defs/raster.h:198:void Rast_add_d_color_rule(const DCELL *, int, int, int, …

Markus M


grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev


Yann Chemin wrote:

OK, I found why I got lost in all that...
there is no file appearing in colr/ with the rules made in the code.

Are you calling Rast_write_colors()?

Also, if the map isn't in the current mapset, the file will go into
<current mapset>/colr2/<mapset>/<map> rather than the mapset
containing the map.

--
Glynn Clements <glynn@gclements.plus.com>

Yes Glynns, that was my missing part, writing the file. … and sleep too. :slight_smile:

···

On 8 December 2014 at 10:37, Glynn Clements <glynn@gclements.plus.com> wrote:

Yann Chemin wrote:

OK, I found why I got lost in all that…
there is no file appearing in colr/ with the rules made in the code.

Are you calling Rast_write_colors()?

Also, if the map isn’t in the current mapset, the file will go into
/colr2// rather than the mapset
containing the map.


Glynn Clements <glynn@gclements.plus.com>