cuikplotatlas.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 
71 int main(int argc, char **arg)
72 {
73  TAtlasBase world; /* The set of mechanism and obstacles. */
74  Tparameters parameters; /* Parameters used in the Cuik process. */
75  Tatlas atlas; /* The atlas to plot. */
76 
77  unsigned int nx,ny,nz;
78  unsigned int xID,yID,zID;
79  FILE *fc;
80  unsigned int i,s,nv,nvs;
81  boolean *systemVars;
82 
83  Tfilename fparam;
84  Tfilename fplot;
85  Tfilename fatlas;
86  Tfilename fcost;
87 
88 
89  if ((argc==5)||(argc==6))
90  {
91  /*Init parameters*/
92  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
93  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
94  fprintf(stderr,"Reading parameters from : %s\n",GetFileFullName(&fparam));
95 
96  /*Read the world from file*/
97  CS_WD_INIT(&parameters,arg[1],&world);
98  nv=CS_WD_GET_SYSTEM_VARS(&systemVars,&world);
99 
100  CreateFileName(NULL,arg[1],NULL,ATLAS_EXT,&fatlas);
101  fprintf(stderr,"Reading atlas from : %s\n",GetFileFullName(&fatlas));
102  LoadAtlas(&parameters,&fatlas,&world,&atlas);
103 
104  if (argc>5)
105  {
106  CreateFileName(NULL,arg[2],NULL,COST_EXT,&fcost);
107  fprintf(stderr,"Reading cost from : %s\n",GetFileFullName(&fcost));
108  fc=fopen(GetFileFullName(&fcost),"r");
109  if (!fc)
110  Error("Can not open the cost file");
111 
112  nx=atoi(arg[3]);
113  ny=atoi(arg[4]);
114  nz=atoi(arg[5]);
115  }
116  else
117  {
118  fc=NULL;
119  nx=atoi(arg[2]);
120  ny=atoi(arg[3]);
121  nz=atoi(arg[4]);
122  }
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  nvs=0;
130  s=0;
131  for(i=0;i<nv;i++)
132  {
133  if (systemVars[i])
134  {
135  /* Transform index from system variables only to
136  all variables (in the original system in both cases!!) */
137  if (nx==nvs) {xID=i; s++;}
138  if (ny==nvs) {yID=i; s++;}
139  if (nz==nvs) {zID=i; s++;}
140  nvs++;
141  }
142  }
143 
144  if (s!=3)
145  Error("Projection dimensions are beyond the ambient space dimensionality");
146 
147  CreateFileName(NULL,arg[1],"_atlas",PLOT3D_EXT,&fplot);
148  fprintf(stderr,"Generating atlas plot to : %s\n",GetFileFullName(&fplot));
149 
150  PlotAtlas(GetFileFullName(&fplot),argc,arg,&parameters,fc,xID,yID,zID,&atlas);
151 
152  if (fc!=NULL)
153  fclose(fc);
154 
155  DeleteParameters(&parameters);
156 
157  free(systemVars);
158 
159  CS_WD_DELETE(&world);
160 
161  DeleteAtlas(&atlas);
162 
163  DeleteFileName(&fplot);
164  DeleteFileName(&fatlas);
165  DeleteFileName(&fparam);
166  }
167  else
168  {
169  fprintf(stderr," Wrong number of parameters.\n");
170  fprintf(stderr," Use:\n");
171  fprintf(stderr," cuikplotatlas <problem filename> <cost file> <xID> <yID> <zID>\n");
172  fprintf(stderr," where <problem filename> is the atlas to plot.\n");
173  fprintf(stderr," <cost file> [optional] file with associated costs for each chart.\n");
174  fprintf(stderr," <xID> <yID> <zID> are the 3 projection dimensions.\n");
175  fprintf(stderr," (indices of system variables as those in the _path.sol file from 0)\n");
176 
177  }
178  return(EXIT_SUCCESS);
179 }
180 
void LoadAtlas(Tparameters *pr, Tfilename *fname, TAtlasBase *w, Tatlas *a)
Defines an atlas from the information on a file.
Definition: atlas.c:3973
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.
#define COST_EXT
File extension for arrays of costs.
Definition: filename.h:156
void DeleteAtlas(Tatlas *a)
Destructor.
Definition: atlas.c:4634
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
#define ATLAS_EXT
File extension for files storing atlas.
Definition: filename.h:200
#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
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
A atlas on a manifold.
Definition: atlas.h:289
void DeleteParameters(Tparameters *p)
Destructor.
Definition: parameters.c:294
int main(int argc, char **arg)
Main body of the cuikplotatlas application.
Definition: cuikplotatlas.c:71
#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.
Definition of the Tparameters type and the associated functions.
void PlotAtlas(char *fname, int argc, char **arg, Tparameters *pr, FILE *fcost, unsigned int xID, unsigned int yID, unsigned int zID, Tatlas *a)
Pots a projection of an atlas.
Definition: atlas.c:4227