cuikpathlength.c
Go to the documentation of this file.
1 #include "world.h"
2 #include "parameters.h"
3 
4 #include "defines.h"
5 #include "error.h"
6 #include "filename.h"
7 #include "atlas.h"
8 #include "samples.h"
9 #include "random.h"
10 
11 #include <stdlib.h>
12 
57 int main(int argc, char **arg)
58 {
59  TAtlasBase world; /* The set of mechanism and obstacles. */
60  Tparameters parameters; /* Parameters used in the Cuik process. */
61 
62  Tfilename fparam;
63  Tfilename fpath;
64 
65  unsigned int *tp; /* topology */
66 
67  /* input path */
68  unsigned int nvs,ns;
69  double **path;
70  boolean *sv; /* variables to use in the path length computation */
71 
72  if (argc>=2)
73  {
74  /*Init parameters*/
75  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
76  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
77  fprintf(stderr,"Reading parameters from : %s\n",GetFileFullName(&fparam));
78 
79  /*Read the world from file*/
80  CS_WD_INIT(&parameters,arg[1],&world);
81 
82  CS_WD_GET_TOPOLOGY(&parameters,&tp,&world);
83 
84  if (argc>2)
85  CreateFileName(NULL,arg[2],NULL,SOL_EXT,&fpath);
86  else
87  CreateFileName(NULL,arg[1],"_path",SOL_EXT,&fpath);
88 
89 
90  if ((!KINEMATIC_SUBSPACE)||(ON_CUIKSYSTEM(&world)))
91  sv=NULL;
92  else
93  WorldSimpKinematicVars(&parameters,&sv,GET_WORLD(&world)); /* Path length on kinematic variables only */
94 
95  if (LoadSamples(&fpath,&nvs,&ns,&path))
96  {
97  fprintf(stderr,"Path length : %g\n",PathLength(tp,sv,nvs,ns,path));
98  DeleteSamples(ns,path);
99  }
100  else
101  Error("Could not read the input path file");
102 
103  free(tp);
104  if (sv!=NULL)
105  free(sv);
106 
107  DeleteParameters(&parameters);
108  CS_WD_DELETE(&world);
109 
110  DeleteFileName(&fparam);
111  DeleteFileName(&fpath);
112  }
113  else
114  {
115  fprintf(stderr," Wrong number of parameters.\n");
116  fprintf(stderr," Use:\n");
117  fprintf(stderr," cuikpathlength <base filename> [<path file>]\n");
118  fprintf(stderr," where <base filename> is used for the parameters, world, and path files.\n");
119  fprintf(stderr," <path file> [optional] is the file with the path.\n");
120  }
121  return(EXIT_SUCCESS);
122 }
123