cuiklinks2joints.c
Go to the documentation of this file.
1 #include "box.h"
2 #include "random.h"
3 #include "defines.h"
4 #include "filename.h"
5 #include "world.h"
6 
7 #include <stdlib.h>
8 
62 int main(int argc, char **arg)
63 {
64  if (argc>1)
65  {
66  Tparameters parameters;
67  Tworld world;
68 
69  Tfilename fparam;
70  Tfilename flinks;
71  Tfilename fjoints;
72 
73  unsigned int i,j;
74 
75  unsigned int ndof;
76  double *dof;
77  unsigned int nv,nvs;
78  boolean *sv;
79  double *sample;
80 
81  FILE *fd,*fs;
82 
83  boolean end;
84  int token;
85 
86  unsigned int r;
87 
88  /* Init parameters */
89  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
90  fprintf(stderr,"Reading parameters : %s\n",GetFileFullName(&fparam));
91  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
92 
93  r=(unsigned int)(GetParameter(CT_REPRESENTATION,&parameters));
94  if (r==REP_JOINTS)
95  Error("The system representation can not be JOINTS when converting to JOINTS");
96 
97  /* Read the problem file */
98  InitWorldFromFile(&parameters,TRUE,arg[1],&world);
99 
100  /* Open the file from where to read the samples */
101  CreateFileName(NULL,arg[1],NULL,LINKS_EXT,&flinks);
102  fprintf(stderr,"Reading link poses from : %s\n",GetFileFullName(&flinks));
103  fs=fopen(GetFileFullName(&flinks),"r");
104  if (!fs)
105  Error("Could not open the file to read the link poses");
106 
107  /* Open the file where to store the dof */
108  if (argc>2)
109  CreateFileName(NULL,arg[2],NULL,JOINTS_EXT,&fjoints);
110  else
111  CreateFileName(NULL,arg[1],NULL,JOINTS_EXT,&fjoints);
112  fprintf(stderr,"Writing dof to : %s\n",GetFileFullName(&fjoints));
113  fd=fopen(GetFileFullName(&fjoints),"w");
114  if (!fd)
115  Error("Could not open the file to store the dof");
116 
117  /* Allocate space for the sample and dof */
118  nv=GetWorldSystemVars(&sv,&world);
119  nvs=0;
120  for(i=0;i<nv;i++)
121  {
122  if (sv[i])
123  nvs++;
124  }
125  NEW(sample,nvs,double);
126 
127  ndof=GetWorldNDOF(&world);
128  NEW(dof,ndof,double);
129 
130  end=FALSE;
131  do {
132  for(i=0;((!end)&&(i<nvs));i++)
133  {
134  token=fscanf(fs,"%lf",&(sample[i]));
135  if ((token==EOF)||(token==0))
136  end=TRUE;
137  }
138  if (!end)
139  {
140  WorldSample2DOF(&parameters,sample,dof,&world);
141  for(j=0;j<ndof;j++)
142  fprintf(fd,"%.16f ",dof[j]);
143  fprintf(fd,"\n");
144  }
145  } while (!end);
146 
147  free(sv);
148  free(dof);
149  free(sample);
150 
151  fclose(fd);
152  fclose(fs);
153 
154  DeleteWorld(&world);
155  DeleteParameters(&parameters);
156 
157  DeleteFileName(&fparam);
158  DeleteFileName(&fjoints);
159  DeleteFileName(&flinks);
160  }
161  else
162  {
163  fprintf(stderr,"Use:\n");
164  fprintf(stderr," cuiklinks2joints <problem_name> <dof_name>\n");
165  fprintf(stderr," <problem_name> the prefix to define the .world and.\n");
166  fprintf(stderr," .links files.\n");
167  fprintf(stderr," <dof_name> [optional] The prefis to define the .dof.\n");
168  fprintf(stderr," file. If not given the <problem_name> is used.\n");
169  }
170 
171  return(EXIT_SUCCESS);
172 }
#define REP_JOINTS
One of the possible values of the REPRESENTATION parameter.
Definition: parameters.h:60
#define FALSE
FALSE.
Definition: boolean.h:30
#define NEW(_var, _n, _type)
Allocates memory space.
Definition: defines.h:385
Data structure to hold the information about the name of a file.
Definition: filename.h:271
void WorldSample2DOF(Tparameters *p, double *sample, double *dof, Tworld *w)
Transforms a sample degrees of freedom.
Definition: world.c:3800
Definition of the Tfilename type and the associated functions.
#define TRUE
TRUE.
Definition: boolean.h:21
void Error(const char *s)
General error function.
Definition: error.c:80
#define PARAM_EXT
File extension for parameter files.
Definition: filename.h:132
All the necessary information to generate equations for mechanisms.
Definition: world.h:229
Definition of the Tworld type and the associated functions.
void DeleteWorld(Tworld *w)
Destructor.
Definition: world.c:3952
void DeleteFileName(Tfilename *fn)
Destructor.
Definition: filename.c:205
Definition of the Tbox type and the associated functions.
Definitions of constants and macros used in several parts of the cuik library.
int main(int argc, char **arg)
Main body of the cuiklinks2joints 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
char * GetFileFullName(Tfilename *fn)
Gets the file full name (paht+name+extension).
Definition: filename.c:151
#define CT_REPRESENTATION
Representation.
Definition: parameters.h:215
boolean InitWorldFromFile(Tparameters *p, boolean error, char *fn, Tworld *w)
Constructor.
#define JOINTS_EXT
File extension for files with samples represented by the joint values.
Definition: filename.h:188
void DeleteParameters(Tparameters *p)
Destructor.
Definition: parameters.c:294
unsigned int GetWorldSystemVars(boolean **sv, Tworld *w)
Gets the system vars of the kinematic cuiksystem.
Definition: world.c:2383
double GetParameter(unsigned int n, Tparameters *p)
Gets the value for a particular parameter.
Definition: parameters.c:93
Definition of basic randomization functions.
unsigned int GetWorldNDOF(Tworld *w)
Gets the number of degrees of freedom in the world.
Definition: world.c:1997
#define LINKS_EXT
File extension for files with samples represented by the link poses.
Definition: filename.h:181