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 
void LoadAtlas(Tparameters *pr, Tfilename *fname, TAtlasBase *w, Tatlas *a)
Defines an atlas from the information on a file.
Definition: atlas.c:3869
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.
#define COST_EXT
File extension for arrays of costs.
Definition: filename.h:155
void DeleteAtlas(Tatlas *a)
Destructor.
Definition: atlas.c:4561
void Error(const char *s)
General error function.
Definition: error.c:80
#define PARAM_EXT
File extension for parameter files.
Definition: filename.h:131
#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
#define ATLAS_EXT
File extension for files storing atlas.
Definition: filename.h:199
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:295
#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
int main(int argc, char **arg)
Main body of the cuiktriangulateatlas application.
void TriangulateAtlas(char *fname, int argc, char **arg, Tparameters *pr, FILE *fcost, unsigned int xID, unsigned int yID, unsigned int zID, Tatlas *a)
Pots the triangular mesh defined by the an atlas.
Definition: atlas.c:4314
Definition of the Tparameters type and the associated functions.