cuikmove.c
Go to the documentation of this file.
1 #include "cuikmove.h"
2 
3 #include "world.h"
4 #include "interval.h"
5 #include "defines.h"
6 #include "error.h"
7 
8 #include "cuikmove_interface.h"
9 #include "cuikplay_support.h"
10 
11 #include <gtk/gtk.h>
12 
13 #include <string.h>
14 #include <unistd.h>
15 #include <time.h>
16 
79 int main(int argc, char **arg)
80 {
81 
82  if (argc>1)
83  {
84  Tworld world;
85  Tparameters parameters;
86 
87  Tfilename fparam;
88  Tfilename fworld;
89 
90  Tplot3d pt;
91  double axesLength;
92 
93  TCuikMoveControl status;
94  Tinterval range;
95  unsigned int i;
96 
97  unsigned int accuracy,rep;
98 
99  GtkWidget *window_cuikmove;
100 
101  FILE *initFile;
102 
103  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
104  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
105 
106  rep=(unsigned int)(GetParameter(CT_REPRESENTATION,&parameters));
107  if (rep!=REP_JOINTS)
108  ChangeParameter(CT_REPRESENTATION,(double)REP_JOINTS,&parameters);
109 
110  CreateFileName(NULL,arg[1],NULL,WORLD_EXT,&fworld);
111  InitWorldFromFile(&parameters,TRUE,arg[1],&world);
112 
113  if (argc>2)
114  {
115  Tfilename finput;
116 
117  CreateFileName(NULL,arg[2],NULL,JOINTS_EXT,&finput);
118  initFile=fopen(GetFileFullName(&finput),"r");
119  DeleteFileName(&finput);
120  }
121  else
122  initFile=NULL;
123 
124  if (argc>3)
125  axesLength=atof(arg[3]);
126  else
127  axesLength=0.0;
128 
129  if (argc>4)
130  accuracy=atoi(arg[4]);
131  else
132  accuracy=3; /* about one 10th of a degree */
133 
134 
135  status.ndof=GetWorldNDOF(&world);
136  status.accuracy=accuracy;
137  status.changed=TRUE;
138  status.end=FALSE;
139  NEW(status.min,status.ndof,double);
140  NEW(status.max,status.ndof,double);
141  NEW(status.dof,status.ndof,double);
142  NEW(status.shown,status.ndof,boolean);
143  status.nShown=0;
144  for(i=0;i<status.ndof;i++)
145  {
146  GetWorldRangeDOF(i,&range,&world);
147  status.min[i]=LowerLimit(&range);
148  if (initFile==NULL)
149  status.dof[i]=IntervalCenter(&range);
150  else
151  fscanf(initFile,"%lf",&(status.dof[i]));
152  status.max[i]=UpperLimit(&range);
153  status.shown[i]=(IntervalSize(&range)>ZERO);
154  if (status.shown[i]) status.nShown++;
155  DeleteInterval(&range);
156  }
157  status.p=&parameters;
158  status.w=&world;
159  status.fw=GetFileBaseName(&fworld);
160 
161  if (initFile!=NULL)
162  fclose(initFile);
163 
164  gtk_set_locale();
165  gtk_init(&argc,&arg);
166 
167  window_cuikmove=create_window_cuikmove((gpointer)(&status));
168  gtk_widget_show(window_cuikmove);
169 
170  InitPlot3d(NULL,FALSE,argc,arg,&pt);
171  PlotWorld(&parameters,&pt,axesLength,&world); /* This initializes collision detection */
172 
173  while(!status.end)
174  {
175  if (status.changed)
176  {
177  MoveWorldDOF(&parameters,&pt,status.dof,&world);
178  status.changed=FALSE;
179  }
180 
181  gtk_main_iteration_do(FALSE);
182  }
183 
184  ClosePlot3d(TRUE,0,0,0,&pt);
185 
186  free(status.min);
187  free(status.max);
188  free(status.dof);
189  free(status.shown);
190 
191  DeleteWorld(&world);
192  DeleteParameters(&parameters);
193 
194  DeleteFileName(&fworld);
195  DeleteFileName(&fparam);
196  }
197  else
198  {
199  fprintf(stdout," Wrong number of parameters.\n");
200  fprintf(stdout," Use:\n");
201  fprintf(stdout," cuikmove <world>.world [<initFile>.dof <axes> <accuracy>]\n");
202  fprintf(stdout," Where:\n");
203  fprintf(stdout," <world>: File describing the problem\n");
204  fprintf(stdout," <initFile>: Optional. File from where to read the initial joint values.\n");
205  fprintf(stdout," <axes>: Optional. Length for the axes for each link.\n");
206  fprintf(stdout," The default value is 0, i.e., not to display them.\n");
207  fprintf(stdout," <accurary>: Optional. Size of each step in each DOF");
208  fprintf(stdout," (in decimal digits).\n");
209  fprintf(stdout," The default value is 3.\n");
210  fprintf(stdout," File extensions are not required\n");
211  }
212 
213  return(EXIT_SUCCESS);
214 }
#define REP_JOINTS
One of the possible values of the REPRESENTATION parameter.
Definition: parameters.h:60
void MoveWorldDOF(Tparameters *pr, Tplot3d *pt, double *dof, Tworld *w)
Moves a mechanisms to a configuration given by the degrees of freedom.
Definition: world.c:3680
#define FALSE
FALSE.
Definition: boolean.h:30
void GetWorldRangeDOF(unsigned int ndof, Tinterval *r, Tworld *w)
Gets the range for a given degree of freedom.
Definition: world.c:2002
#define NEW(_var, _n, _type)
Allocates memory space.
Definition: defines.h:385
char * GetFileBaseName(Tfilename *fn)
Gets the file base name (paht+name) .
Definition: filename.c:166
Data structure to hold the information about the name of a file.
Definition: filename.h:271
Definition of the cuikmove control structure.
void InitPlot3d(char *name, boolean axes, int argc, char **arg, Tplot3d *p)
Constructor.
Definition: plot3d.c:41
#define TRUE
TRUE.
Definition: boolean.h:21
#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
double * min
Definition: cuikmove.h:28
boolean changed
Definition: cuikmove.h:25
#define ZERO
Floating point operations giving a value below this constant (in absolute value) are considered 0...
Definition: defines.h:37
unsigned int accuracy
Definition: cuikmove.h:26
Definition of the cuikmove control structure.
Definition: cuikmove.h:23
Definition of the Tworld type and the associated functions.
void DeleteWorld(Tworld *w)
Destructor.
Definition: world.c:3952
Error and warning functions.
void DeleteFileName(Tfilename *fn)
Destructor.
Definition: filename.c:205
A 3D plot.
Definition: plot3d.h:54
Headers of the GTK interface functions for cuikmove.
double LowerLimit(Tinterval *i)
Gets the lower limit.
Definition: interval.c:79
Definitions of constants and macros used in several parts of the cuik library.
void DeleteInterval(Tinterval *i)
Destructor.
Definition: interval.c:1021
A table of parameters.
int main(int argc, char **arg)
Main body of the cuikmove application.
Definition: cuikmove.c:79
void CreateFileName(char *path, char *name, char *suffix, char *ext, Tfilename *fn)
Constructor.
Definition: filename.c:22
Tparameters * p
Definition: cuikmove.h:34
double UpperLimit(Tinterval *i)
Gets the uppser limit.
Definition: interval.c:87
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.
Tworld * w
Definition: cuikmove.h:35
unsigned int nShown
Definition: cuikmove.h:33
#define WORLD_EXT
File extension for problem files.
Definition: filename.h:162
#define JOINTS_EXT
File extension for files with samples represented by the joint values.
Definition: filename.h:188
double IntervalCenter(Tinterval *i)
Gets the interval center.
Definition: interval.c:129
void DeleteParameters(Tparameters *p)
Destructor.
Definition: parameters.c:294
void PlotWorld(Tparameters *pr, Tplot3d *pt, double axesLength, Tworld *w)
Adds a world (environment plus mechanism) in a 3D scene.
Definition: world.c:3452
double * dof
Definition: cuikmove.h:30
double GetParameter(unsigned int n, Tparameters *p)
Gets the value for a particular parameter.
Definition: parameters.c:93
boolean * shown
Definition: cuikmove.h:31
unsigned int ndof
Definition: cuikmove.h:27
boolean end
Definition: cuikmove.h:24
unsigned int GetWorldNDOF(Tworld *w)
Gets the number of degrees of freedom in the world.
Definition: world.c:1997
Defines a interval.
Definition: interval.h:33
void ChangeParameter(unsigned int n, double v, Tparameters *p)
Sets the value for a particular parameter.
Definition: parameters.c:164
double IntervalSize(Tinterval *i)
Gets the uppser limit.
Definition: interval.c:96
double * max
Definition: cuikmove.h:29
void ClosePlot3d(boolean quit, double average_x, double average_y, double average_z, Tplot3d *p)
Destructor.
Definition: plot3d.c:473
Headers of the GTK support functions for cuikplay.
Definition of the Tinterval type and the associated functions.