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 
#define GET_WORLD(wcs)
Returns the world from an TAtlasBase.
Definition: wcs.h:150
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.
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 ON_CUIKSYSTEM(wcs)
TRUE if the atlas is defined on a cuiksystem.
Definition: wcs.h:139
#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 KINEMATIC_SUBSPACE
Focus on the kinematic sub-space.
Definition: samples.h:117
boolean LoadSamples(Tfilename *fname, unsigned int *nvs, unsigned int *ns, double ***path)
Reads a set of samples from file.
Definition: samples.c:2913
Definitions of constants and macros used in several parts of the cuik library.
int main(int argc, char **arg)
Main body of the cuikpathlength application.
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.
char * GetFileFullName(Tfilename *fn)
Gets the file full name (paht+name+extension).
Definition: filename.c:151
#define SOL_EXT
File extension for solution files.
Definition: filename.h:138
void DeleteParameters(Tparameters *p)
Destructor.
Definition: parameters.c:294
#define CS_WD_GET_TOPOLOGY(pr, tp, wcs)
Gets the variable topology.
Definition: wcs.h:464
#define CS_WD_INIT(pr, name, wcs)
Initializes the equations from a file.
Definition: wcs.h:89
Auxiliary functions to deal with sets of samples.
Definition of basic randomization functions.
void DeleteSamples(unsigned int ns, double **path)
Deletes the space used by a set of samples.
Definition: samples.c:3159
unsigned int WorldSimpKinematicVars(Tparameters *p, boolean **kv, Tworld *w)
Creates a boolean array to identify kinematic variables.
Definition: world.c:2616
Definition of the Tparameters type and the associated functions.
double PathLength(unsigned int *tp, boolean *sv, unsigned int m, unsigned int np, double **point)
Length of a path formed by a set of samples.
Definition: samples.c:1096