cuiktriangulateatlas.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 
10 #include <stdlib.h>
11 
69 int main(int argc, char **arg)
70 {
71  TAtlasBase world; /* The set of mechanism and obstacles. */
72  Tparameters parameters; /* Parameters used in the Cuik process. */
73  Tatlas atlas; /* The atlas to plot. */
74 
75  unsigned int nx,ny,nz;
76  unsigned int xID,yID,zID;
77  FILE *fc;
78  unsigned int i,s,nv,nvs;
79  boolean *systemVars;
80 
81  Tfilename fparam;
82  Tfilename fplot;
83  Tfilename fatlas;
84  Tfilename fcost;
85 
86 
87  if (argc>4)
88  {
89  /*Init parameters*/
90  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
91  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
92  fprintf(stderr,"Reading parameters from : %s\n",GetFileFullName(&fparam));
93 
94  /*Read the world from file*/
95  CS_WD_INIT(&parameters,arg[1],&world);
96  nv=CS_WD_GET_SYSTEM_VARS(&systemVars,&world);
97 
98  CreateFileName(NULL,arg[1],NULL,ATLAS_EXT,&fatlas);
99  fprintf(stderr,"Reading atlas from : %s\n",GetFileFullName(&fatlas));
100  LoadAtlas(&parameters,&fatlas,&world,&atlas);
101 
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  nvs=0;
122  s=0;
123  for(i=0;i<nv;i++)
124  {
125  if (systemVars[i])
126  {
127  /* Transform index from system variables only to
128  all variables (in the original system in both cases!!) */
129  if (nx==nvs) {xID=i; s++;}
130  if (ny==nvs) {yID=i; s++;}
131  if (nz==nvs) {zID=i; s++;}
132  nvs++;
133  }
134  }
135 
136  if (s!=3)
137  Error("Projection dimensions are beyond the ambient space dimensionality");
138 
139  CreateFileName(NULL,arg[1],"_atlas_triang",PLOT3D_EXT,&fplot);
140  fprintf(stderr,"Generating triangulation to : %s\n",GetFileFullName(&fplot));
141 
142  TriangulateAtlas(GetFileFullName(&fplot),argc,arg,&parameters,fc,xID,yID,zID,&atlas);
143 
144  if (fc!=NULL)
145  fclose(fc);
146 
147  DeleteParameters(&parameters);
148 
149  free(systemVars);
150 
151  CS_WD_DELETE(&world);
152 
153  DeleteAtlas(&atlas);
154 
155  DeleteFileName(&fplot);
156  DeleteFileName(&fatlas);
157  DeleteFileName(&fparam);
158  }
159  else
160  {
161  fprintf(stderr," Wrong number of parameters.\n");
162  fprintf(stderr," Use:\n");
163  fprintf(stderr," cuiktriangulateatlas <problem filename> <cost file> <xID> <yID> <zID>\n");
164  fprintf(stderr," where <problem filename> is the atlas to plot.\n");
165  fprintf(stderr," <cost file> [optional] file with associated costs for each chart.\n");
166  fprintf(stderr," <xID> <yID> <zID> are the 3 projection dimensions.\n");
167  fprintf(stderr," (indices of system variables numbered from 0)\n");
168 
169  }
170  return(EXIT_SUCCESS);
171 }
172