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,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 
99  /* Validate the input projection dimensions */
100  nv=CS_WD_GET_SYSTEM_VARS(&systemVars,&world);
101  nvs=CS_WD_GET_NUM_SYSTEM_VARS(&world);
102  if (argc>5)
103  {
104  CreateFileName(NULL,arg[2],NULL,COST_EXT,&fcost);
105  fprintf(stderr,"Reading cost from : %s\n",GetFileFullName(&fcost));
106  fc=fopen(GetFileFullName(&fcost),"r");
107  if (!fc)
108  Error("Can not open the cost file");
109 
110  nx=atoi(arg[3]);
111  ny=atoi(arg[4]);
112  nz=atoi(arg[5]);
113  }
114  else
115  {
116  fc=NULL;
117  nx=atoi(arg[2]);
118  ny=atoi(arg[3]);
119  nz=atoi(arg[4]);
120  }
121 
122  if (nx>=nv)
123  Error("First index out of range");
124  if (ny>=nv)
125  Error("Second index out of range");
126  if (nz>=nv)
127  Error("Third index out of range");
128 
129  fprintf(stderr,"Projecting on variables : ");
130  PRINT_VARIABLE_NAME(stderr,CS_WD_GET_SYSTEM_VAR_NAME(nx,&world));fprintf(stderr,",");
131  PRINT_VARIABLE_NAME(stderr,CS_WD_GET_SYSTEM_VAR_NAME(ny,&world));fprintf(stderr,",");
132  PRINT_VARIABLE_NAME(stderr,CS_WD_GET_SYSTEM_VAR_NAME(nz,&world));fprintf(stderr,"\n");
133 
134  nvs=0;
135  for(i=0;i<nv;i++)
136  {
137  if (systemVars[i])
138  {
139  /* Transform index from system variables only to
140  all variables (in the original system in both cases!!) */
141  if (nx==nvs) xID=i;
142  if (ny==nvs) yID=i;
143  if (nz==nvs) zID=i;
144  nvs++;
145  }
146  }
147 
148  /*Read the atlas from file*/
149  CreateFileName(NULL,arg[1],NULL,ATLAS_EXT,&fatlas);
150  fprintf(stderr,"Reading atlas from : %s\n",GetFileFullName(&fatlas));
151  LoadAtlas(&parameters,&fatlas,&world,&atlas);
152 
153  /* Create the plot */
154  CreateFileName(NULL,arg[1],"_atlas",PLOT3D_EXT,&fplot);
155  fprintf(stderr,"Generating atlas plot to : %s\n",GetFileFullName(&fplot));
156 
157  PlotAtlas(GetFileFullName(&fplot),argc,arg,&parameters,fc,xID,yID,zID,&atlas);
158 
159  if (fc!=NULL)
160  fclose(fc);
161 
162  DeleteParameters(&parameters);
163 
164  free(systemVars);
165 
166  CS_WD_DELETE(&world);
167 
168  DeleteAtlas(&atlas);
169 
170  DeleteFileName(&fplot);
171  DeleteFileName(&fatlas);
172  DeleteFileName(&fparam);
173  }
174  else
175  {
176  fprintf(stderr," Wrong number of parameters.\n");
177  fprintf(stderr," Use:\n");
178  fprintf(stderr," cuikplotatlas <problem filename> <cost file> <xID> <yID> <zID>\n");
179  fprintf(stderr," where <problem filename> is the atlas to plot.\n");
180  fprintf(stderr," <cost file> [optional] file with associated costs for each chart.\n");
181  fprintf(stderr," <xID> <yID> <zID> are the 3 projection dimensions.\n");
182  fprintf(stderr," (indices of system variables as those in the _path.sol file from 0)\n");
183 
184  }
185  return(EXIT_SUCCESS);
186 }
187