sciapp / gr

GR framework: a graphics library for visualisation applications
Other
328 stars 54 forks source link

[Question] 3D plot #114

Closed mantielero closed 4 years ago

mantielero commented 4 years ago

I am trying to run something like this example but using the pure C API.

I don't know how to make the full curve fit inside the view. Any example?

IngoMeyer441 commented 4 years ago

Hey, currently, we develop a new GR sub library called "GRM" which implements all high level plotting functions from Julia and Python. With this library you can rewrite the plot3 example as:

#include <grm.h>
#include <math.h>

int main(void)
{
  double x[1000];
  double y[1000];
  double z[1000];
  int n = sizeof(x) / sizeof(x[0]);
  grm_args_t *args;
  int i;

  printf("filling argument container...\n");

  for (i = 0; i < n; ++i)
    {
      x[i] = i * 30.0 / n;
      y[i] = cos(x[i]) * x[i];
      z[i] = sin(x[i]) * x[i];
    }

  args = grm_args_new();
  grm_args_push(args, "kind", "s", "plot3");
  grm_args_push(args, "x", "nD", n, x);
  grm_args_push(args, "y", "nD", n, y);
  grm_args_push(args, "z", "nD", n, z);

  printf("plotting data...\n");

  grm_plot(args);

  printf("Press any key to continue...\n");
  getchar();

  grm_args_delete(args);
  grm_finalize();

  return 0;
}

GRM is work in progress, so there is no documentation online and the api can still change.

mantielero commented 4 years ago

I have created bindings to grm and managed to make it work. Thanks a lot.

In any case, I would like to know how is done the fitting in the figure. Is there a place in the code that I might look at?

IngoMeyer441 commented 4 years ago

The axes (or gr window) is fitted in the function plot_store_coordinate_ranges of lib/grm/plot.c. This function simply finds minimum and maximum values of the input data and stores the results as pairs of type double with names xrange, yrange and zrange. These values are then used in the function plot_process_window for calls of gr_setwindow and gr_setspace.

IngoMeyer441 commented 4 years ago

The code of plot_process_window is quite complex because it is generic for all kinds of plots and is also used to implement panning and zooming for interactive graphics output (see calls of gr_panzoom).

mantielero commented 4 years ago

Could you describe gr_panzoom? It is undocumented.

IngoMeyer441 commented 4 years ago

It is a helper function to adjust the window for given panning or zooming parameters. It is mainly used in interactive GUI applications when GR is used as an embedded graphics widget.

This function has two modes:

In both modes the calculated window is not applied. Instead, the result is written to the out parameters xmin, xmax, ymin and ymax. The caller can use the result for further calculations or apply it with a call of gr_setwindow.

IngoMeyer441 commented 4 years ago

I have read in your other issue that you use Arch Linux. Have you seen that we provide GR packages on the AUR?

mantielero commented 4 years ago

Yes. Those packages are the ones that I am using. I wasn't aware they were also yours. (You do an amazing good job to be honest)