cuikplotpath.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 "atlas.h"
9 #include "samples.h"
10 
11 #include <stdlib.h>
12 
68 int main(int argc, char **arg)
69 {
70  TAtlasBase world; /* The set of mechanism and obstacles. */
71  Tparameters parameters; /* Parameters used in the Cuik process. */
72 
73  unsigned int nx,ny,nz;
74  unsigned int i,nv,nvs;
75  boolean *systemVars;
76 
77  unsigned int ns;
78  double **path;
79 
80  Tfilename fparam;
81  Tfilename fpath;
82 
83  //boolean smooth;
84 
85  if (argc>=5)
86  {
87  /*Init parameters*/
88  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
89  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
90  fprintf(stderr,"Reading parameters from : %s\n",GetFileFullName(&fparam));
91 
92  /*Read the world from file*/
93  CS_WD_INIT(&parameters,arg[1],&world);
94  nv=CS_WD_GET_SYSTEM_VARS(&systemVars,&world);
95 
96  if (argc>5)
97  {
98  CreateFileName(NULL,arg[2],NULL,SOL_EXT,&fpath);
99 
100  nx=atoi(arg[3]);
101  ny=atoi(arg[4]);
102  nz=atoi(arg[5]);
103  }
104  else
105  {
106  CreateFileName(NULL,arg[1],"_path",SOL_EXT,&fpath);
107 
108  nx=atoi(arg[2]);
109  ny=atoi(arg[3]);
110  nz=atoi(arg[4]);
111  }
112 
113  nvs=0;
114  for(i=0;i<nv;i++)
115  {
116  if (systemVars[i])
117  nvs++;
118  }
119  if ((nx>=nvs)||(ny>=nvs)||(nz>=nvs))
120  Error("Projection dimensions are beyond the ambient space dimensionality");
121 
122  free(systemVars);
123 
124  fprintf(stderr,"Projecting on variables : ");
125  PRINT_VARIABLE_NAME(stderr,CS_WD_GET_SYSTEM_VAR_NAME(nx,&world));fprintf(stderr,",");
126  PRINT_VARIABLE_NAME(stderr,CS_WD_GET_SYSTEM_VAR_NAME(ny,&world));fprintf(stderr,",");
127  PRINT_VARIABLE_NAME(stderr,CS_WD_GET_SYSTEM_VAR_NAME(nz,&world));fprintf(stderr,"\n");
128 
129  if (LoadSamples(&fpath,&nvs,&ns,&path))
130  {
131  /*If the path was actually loaded*/
132  Tfilename fpathplot;
133  Tplot3d p3d;
134 
135  if (argc>5)
136  CreateFileName(NULL,arg[2],NULL,PLOT3D_EXT,&fpathplot);
137  else
138  CreateFileName(NULL,arg[1],"_path",PLOT3D_EXT,&fpathplot);
139 
140  fprintf(stderr,"Generating path plot to : %s\n",GetFileFullName(&fpathplot));
141 
142  InitPlot3d(GetFileFullName(&fpathplot),FALSE,argc,arg,&p3d);
143 
144  PlotSamples(&parameters,&p3d,nx,ny,nz,ns,path);
145 
146  ClosePlot3d(FALSE,0,0,0,&p3d);
147 
148  DeleteFileName(&fpathplot);
149  DeleteSamples(ns,path);
150  }
151  else
152  Error("Can not read the file with the path");
153 
154  DeleteParameters(&parameters);
155  CS_WD_DELETE(&world);
156 
157  DeleteFileName(&fpath);
158  DeleteFileName(&fparam);
159  }
160  else
161  {
162  fprintf(stderr," Wrong number of parameters.\n");
163  fprintf(stderr," Use:\n");
164  fprintf(stderr," cuikplotpath <problem filename> [<path filename>] <xID> <yID> <zID>\n");
165  fprintf(stderr," where <problem filename> is the description of the problem.\n");
166  fprintf(stderr," <path filename> is the path to plot. If not given we use <problem filename>_path.sol\n");
167  fprintf(stderr," <xID> <yID> <zID> are the 3 projection dimensions.\n");
168  fprintf(stderr," (indices of system variables as those in the _path.sol file from 0)\n");
169  }
170  return(EXIT_SUCCESS);
171 }
172 
#define FALSE
FALSE.
Definition: boolean.h:30
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 InitPlot3d(char *name, boolean axes, int argc, char **arg, Tplot3d *p)
Constructor.
Definition: plot3d.c:41
void Error(const char *s)
General error function.
Definition: error.c:80
#define PARAM_EXT
File extension for parameter files.
Definition: filename.h:132
#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
boolean LoadSamples(Tfilename *fname, unsigned int *nvs, unsigned int *ns, double ***path)
Reads a set of samples from file.
Definition: samples.c:2913
#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.
void PlotSamples(Tparameters *p, Tplot3d *p3d, unsigned int xID, unsigned int yID, unsigned int zID, unsigned int ns, double **path)
Plots a 3D projection of a path.
Definition: samples.c:2960
int main(int argc, char **arg)
Main body of the cuikplotpath application.
Definition: cuikplotpath.c:68
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
Definition of an atlas on a manifold.
#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
void DeleteParameters(Tparameters *p)
Destructor.
Definition: parameters.c:294
#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
#define CS_WD_GET_SYSTEM_VAR_NAME(id, wcs)
Name of a particular system variables.
Definition: wcs.h:252
Auxiliary functions to deal with sets of samples.
void DeleteSamples(unsigned int ns, double **path)
Deletes the space used by a set of samples.
Definition: samples.c:3159
Definition of the Tparameters type and the associated functions.
void ClosePlot3d(boolean quit, double average_x, double average_y, double average_z, Tplot3d *p)
Destructor.
Definition: plot3d.c:473