cuikplotatlasrrt.c
Go to the documentation of this file.
1 
2 #include "world.h"
3 #include "parameters.h"
4 
5 #include "defines.h"
6 #include "error.h"
7 #include "filename.h"
8 #include "atlasrrt.h"
9 
10 #include <stdlib.h>
11 
66 int main(int argc, char **arg)
67 {
68  TAtlasBase world; /* The set of mechanism and obstacles. */
69  Tparameters parameters; /* Parameters used in the Cuik process. */
70  Tatlasrrt atlasRRT; /* The atlas to plot. */
71 
72  unsigned int nx,ny,nz;
73  unsigned int xID,yID,zID;
74  FILE *f;
75  unsigned int i,s,nv,nvs;
76  boolean *systemVars;
77 
78  Tfilename fparam;
79  Tfilename fpath;
80 
81  if (argc==5)
82  {
83  /*Init parameters*/
84  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
85  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
86  fprintf(stderr,"Reading parameters from : %s\n",GetFileFullName(&fparam));
87 
88  /*Read the world from file*/
89  CS_WD_INIT(&parameters,arg[1],&world);
90  nv=CS_WD_GET_SYSTEM_VARS(&systemVars,&world);
91 
92  /* Read the Atlas, the RRT, and information linking them */
93  LoadAtlasRRT(&parameters,arg[1],&world,&atlasRRT);
94 
95  nx=atoi(arg[2]);
96  ny=atoi(arg[3]);
97  nz=atoi(arg[4]);
98 
99  fprintf(stderr,"Projecting on variables : ");
100  PRINT_VARIABLE_NAME(stderr,CS_WD_GET_SYSTEM_VAR_NAME(nx,&world));fprintf(stderr,",");
101  PRINT_VARIABLE_NAME(stderr,CS_WD_GET_SYSTEM_VAR_NAME(ny,&world));fprintf(stderr,",");
102  PRINT_VARIABLE_NAME(stderr,CS_WD_GET_SYSTEM_VAR_NAME(nz,&world));fprintf(stderr,"\n");
103 
104  nvs=0;
105  s=0;
106  for(i=0;i<nv;i++)
107  {
108  if (systemVars[i])
109  {
110  /* Transform index from system variables only to
111  all variables (in the original system in both cases!!) */
112  if (nx==nvs) {xID=i; s++;}
113  if (ny==nvs) {yID=i; s++;}
114  if (nz==nvs) {zID=i; s++;}
115  nvs++;
116  }
117  }
118 
119  if (s!=3)
120  Error("Projection dimensions are beyond the ambient space dimensionality");
121 
122  /* Plot the atlas, the RRT and the information linking them */
123  PlotAtlasRRT(arg[1],argc,arg,&parameters,xID,yID,zID,&atlasRRT);
124 
125  CreateFileName(NULL,arg[1],"_path",SOL_EXT,&fpath);
126 
127  f=fopen(GetFileFullName(&fpath),"r");
128  if (f)
129  {
130  /*If the path was actually saved*/
131  unsigned int j,ns;
132  double *x,*y,*z;
133  double *step;
134  Tfilename fpathplot;
135  Tcolor red;
136  Tplot3d p3d;
137 
138  NEW(step,nvs,double);
139 
140  fscanf(f,"%u",&ns);
141 
142  NEW(x,ns,double);
143  NEW(y,ns,double);
144  NEW(z,ns,double);
145 
146  for(i=0;i<ns;i++)
147  {
148  for(j=0;j<nvs;j++)
149  fscanf(f,"%lf",&(step[j]));
150 
151  /* For the paths we only store system variables */
152  x[i]=step[nx];
153  y[i]=step[ny];
154  z[i]=step[nz];
155  }
156  fclose(f);
157 
158  CreateFileName(NULL,arg[1],"_path",PLOT3D_EXT,&fpathplot);
159  fprintf(stderr,"Generating path plot to : %s\n",GetFileFullName(&fpathplot));
160 
161  NewColor(1,0,0,&red);
162 
163  InitPlot3d(GetFileFullName(&fpathplot),TRUE,argc,arg,&p3d);
164  StartNew3dObject(&red,&p3d);
165  PlotVect3d(ns,x,y,z,&p3d);
166  Close3dObject(&p3d);
167  ClosePlot3d(FALSE,0,0,0,&p3d);
168 
169  DeleteColor(&red);
170 
171  DeleteFileName(&fpathplot);
172 
173  free(step);
174  free(x);
175  free(y);
176  free(z);
177  }
178 
179  DeleteParameters(&parameters);
180 
181  free(systemVars);
182 
183  CS_WD_DELETE(&world);
184 
185  DeleteAtlasRRT(&atlasRRT);
186 
187  DeleteFileName(&fpath);
188  DeleteFileName(&fparam);
189  }
190  else
191  {
192  fprintf(stderr," Wrong number of parameters.\n");
193  fprintf(stderr," Use:\n");
194  fprintf(stderr," cuikplotatlasrrt <problem filename> <xID> <yID> <zID>\n");
195  fprintf(stderr," where <problem filename> is the atlas to plot.\n");
196  fprintf(stderr," <xID> <yID> <zID> are the 3 projection dimensions.\n");
197  fprintf(stderr," (indices of system variables as those in the _path.sol file from 0)\n");
198 
199  }
200  return(EXIT_SUCCESS);
201 }
202 
void PlotVect3d(unsigned int n, double *x, double *y, double *z, Tplot3d *p)
Adds a polyline to the current object.
Definition: plot3d.c:447
Definition of the combination of an atlas with a RRT.
#define FALSE
FALSE.
Definition: boolean.h:30
#define NEW(_var, _n, _type)
Allocates memory space.
Definition: defines.h:385
Data structure to hold the information about the name of a file.
Definition: filename.h:271
Definition of the Tfilename type and the associated functions.
void PlotAtlasRRT(char *prefix, int argc, char **arg, Tparameters *pr, unsigned int xID, unsigned int yID, unsigned int zID, Tatlasrrt *ar)
Pots a projection of an atlasRRT.
Definition: atlasrrt.c:5859
void InitPlot3d(char *name, boolean axes, int argc, char **arg, Tplot3d *p)
Constructor.
Definition: plot3d.c:41
void DeleteAtlasRRT(Tatlasrrt *ar)
Destructor.
Definition: atlasrrt.c:6206
#define TRUE
TRUE.
Definition: boolean.h:21
void Error(const char *s)
General error function.
Definition: error.c:80
#define PARAM_EXT
File extension for parameter files.
Definition: filename.h:132
A color.
Definition: color.h:86
#define CS_WD_DELETE(wcs)
Destructor of the equation structure.
Definition: wcs.h:592
Definition of the Tworld type and the associated functions.
Error and warning functions.
void DeleteFileName(Tfilename *fn)
Destructor.
Definition: filename.c:205
A 3D plot.
Definition: plot3d.h:54
#define PRINT_VARIABLE_NAME(f, name)
Prints a variable name into a file.
Definition: defines.h:427
Definitions of constants and macros used in several parts of the cuik library.
A table of parameters.
void CreateFileName(char *path, char *name, char *suffix, char *ext, Tfilename *fn)
Constructor.
Definition: filename.c:22
void InitParametersFromFile(char *file, Tparameters *p)
Constructor from a file.
Definition: parameters.c:51
Type defining the equations on which the atlas is defined.
Definition: wcs.h:30
#define CS_WD_GET_SYSTEM_VARS(sv, wcs)
Gets the system variables.
Definition: wcs.h:238
char * GetFileFullName(Tfilename *fn)
Gets the file full name (paht+name+extension).
Definition: filename.c:151
#define SOL_EXT
File extension for solution files.
Definition: filename.h:138
int main(int argc, char **arg)
Main body of the cuikplotatlasrrt application.
void DeleteParameters(Tparameters *p)
Destructor.
Definition: parameters.c:294
void LoadAtlasRRT(Tparameters *pr, char *prefix, TAtlasBase *w, Tatlasrrt *ar)
Defines an atlasRRT from the information on a file.
Definition: atlasrrt.c:6133
#define CS_WD_INIT(pr, name, wcs)
Initializes the equations from a file.
Definition: wcs.h:89
#define PLOT3D_EXT
File extension for 3D plot files.
Definition: filename.h:168
RRT with an atlas for sampling.
Definition: atlasrrt.h:203
#define CS_WD_GET_SYSTEM_VAR_NAME(id, wcs)
Name of a particular system variables.
Definition: wcs.h:252
void DeleteColor(Tcolor *c)
Destructor.
Definition: color.c:143
void NewColor(double r, double g, double b, Tcolor *c)
Constructor.
Definition: color.c:14
Definition of the Tparameters type and the associated functions.
unsigned int StartNew3dObject(Tcolor *c, Tplot3d *p)
Start a composed object.
Definition: plot3d.c:157
void Close3dObject(Tplot3d *p)
Closes a composed object.
Definition: plot3d.c:171
void ClosePlot3d(boolean quit, double average_x, double average_y, double average_z, Tplot3d *p)
Destructor.
Definition: plot3d.c:473