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  nvs=0;
100  s=0;
101  for(i=0;i<nv;i++)
102  {
103  if (systemVars[i])
104  {
105  /* Transform index from system variables only to
106  all variables (in the original system in both cases!!) */
107  if (nx==nvs) {xID=i; s++;}
108  if (ny==nvs) {yID=i; s++;}
109  if (nz==nvs) {zID=i; s++;}
110  nvs++;
111  }
112  }
113 
114  if (s!=3)
115  Error("Projection dimensions are beyond the ambient space dimensionality");
116 
117  /* Plot the atlas, the RRT and the information linking them */
118  PlotAtlasRRT(arg[1],argc,arg,&parameters,xID,yID,zID,&atlasRRT);
119 
120  CreateFileName(NULL,arg[1],"_path",SOL_EXT,&fpath);
121 
122  f=fopen(GetFileFullName(&fpath),"r");
123  if (f)
124  {
125  /*If the path was actually saved*/
126  unsigned int j,ns;
127  double *x,*y,*z;
128  double *step;
129  Tfilename fpathplot;
130  Tcolor red;
131  Tplot3d p3d;
132 
133  NEW(step,nvs,double);
134 
135  fscanf(f,"%u",&ns);
136 
137  NEW(x,ns,double);
138  NEW(y,ns,double);
139  NEW(z,ns,double);
140 
141  for(i=0;i<ns;i++)
142  {
143  for(j=0;j<nvs;j++)
144  fscanf(f,"%lf",&(step[j]));
145 
146  /* For the paths we only store system variables */
147  x[i]=step[nx];
148  y[i]=step[ny];
149  z[i]=step[nz];
150  }
151  fclose(f);
152 
153  CreateFileName(NULL,arg[1],"_path",PLOT3D_EXT,&fpathplot);
154  fprintf(stderr,"Generating path plot to : %s\n",GetFileFullName(&fpathplot));
155 
156  NewColor(1,0,0,&red);
157 
158  InitPlot3d(GetFileFullName(&fpathplot),TRUE,argc,arg,&p3d);
159  StartNew3dObject(&red,&p3d);
160  PlotVect3d(ns,x,y,z,&p3d);
161  Close3dObject(&p3d);
162  ClosePlot3d(FALSE,0,0,0,&p3d);
163 
164  DeleteColor(&red);
165 
166  DeleteFileName(&fpathplot);
167 
168  free(step);
169  free(x);
170  free(y);
171  free(z);
172  }
173 
174  DeleteParameters(&parameters);
175 
176  free(systemVars);
177 
178  CS_WD_DELETE(&world);
179 
180  DeleteAtlasRRT(&atlasRRT);
181 
182  DeleteFileName(&fpath);
183  DeleteFileName(&fparam);
184  }
185  else
186  {
187  fprintf(stderr," Wrong number of parameters.\n");
188  fprintf(stderr," Use:\n");
189  fprintf(stderr," cuikplotatlasrrt <problem filename> <xID> <yID> <zID>\n");
190  fprintf(stderr," where <problem filename> is the atlas to plot.\n");
191  fprintf(stderr," <xID> <yID> <zID> are the 3 projection dimensions.\n");
192  fprintf(stderr," (indices of system variables as those in the _path.sol file from 0)\n");
193 
194  }
195  return(EXIT_SUCCESS);
196 }
197 
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:248
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:4470
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:4817
#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:131
A color.
Definition: color.h:23
#define CS_WD_DELETE(wcs)
Destructor of the equation structure.
Definition: wcs.h:500
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
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:137
int main(int argc, char **arg)
Main body of the cuikplotatlasrrt application.
void DeleteParameters(Tparameters *p)
Destructor.
Definition: parameters.c:295
void LoadAtlasRRT(Tparameters *pr, char *prefix, TAtlasBase *w, Tatlasrrt *ar)
Defines an atlasRRT from the information on a file.
Definition: atlasrrt.c:4744
#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:167
RRT with an atlas for sampling.
Definition: atlasrrt.h:190
void DeleteColor(Tcolor *c)
Destructor.
Definition: color.c:93
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