cuikplotforcefield.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 #include "samples.h"
10 
11 #include <stdlib.h>
12 
70 int main(int argc, char **arg)
71 {
72  Tworld world; /* The set of mechanism and obstacles. */
73  Tparameters parameters; /* Parameters used in the Cuik process. */
74 
75  unsigned int nx,ny,nz;
76  unsigned int nvs;
77 
78  unsigned int ns;
79  double **sols;
80 
81  Tfilename fparam;
82  Tfilename fsols;
83 
84  //boolean smooth;
85 
86  if (argc>=5)
87  {
88  /*Init parameters*/
89  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
90  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
91  fprintf(stderr,"Reading parameters from : %s\n",GetFileFullName(&fparam));
92 
93  /*Read the world from file*/
94  InitWorldFromFile(&parameters,TRUE,arg[1],&world);
95 
96  if (argc>5)
97  {
98  CreateFileName(NULL,arg[2],NULL,SOL_EXT,&fsols);
99 
100  nx=atoi(arg[3]);
101  ny=atoi(arg[4]);
102  nz=atoi(arg[5]);
103  }
104  else
105  {
106  CreateFileName(NULL,arg[1],NULL,SOL_EXT,&fsols);
107 
108  nx=atoi(arg[2]);
109  ny=atoi(arg[3]);
110  nz=atoi(arg[4]);
111  }
112  fprintf(stderr,"Projecting on variables : ");
113  PRINT_VARIABLE_NAME(stderr,GetWorldSystemVarName(nx,&world));fprintf(stderr,",");
114  PRINT_VARIABLE_NAME(stderr,GetWorldSystemVarName(ny,&world));fprintf(stderr,",");
115  PRINT_VARIABLE_NAME(stderr,GetWorldSystemVarName(nz,&world));fprintf(stderr,"\n");
116 
117  if (LoadSamples(&fsols,&nvs,&ns,&sols))
118  {
119  /*If the solutions were actually loaded*/
120  Tfilename fffplot;
121  Tplot3d p3d;
122 
123  if (argc>5)
124  CreateFileName(NULL,arg[2],"_ff",PLOT3D_EXT,&fffplot);
125  else
126  CreateFileName(NULL,arg[1],"_ff",PLOT3D_EXT,&fffplot);
127 
128  fprintf(stderr,"Generating force field plot to : %s\n",GetFileFullName(&fffplot));
129 
130  InitPlot3d(GetFileFullName(&fffplot),FALSE,argc,arg,&p3d);
131 
132  PlotForceField(&parameters,&p3d,nx,ny,nz,&world,ns,sols);
133 
134  ClosePlot3d(FALSE,0,0,0,&p3d);
135 
136  DeleteFileName(&fffplot);
137  DeleteSamples(ns,sols);
138  }
139  else
140  Error("Can not read the file with the solution points");
141 
142  DeleteParameters(&parameters);
143  DeleteWorld(&world);
144 
145  DeleteFileName(&fsols);
146  DeleteFileName(&fparam);
147  }
148  else
149  {
150  fprintf(stderr," Wrong number of parameters.\n");
151  fprintf(stderr," Use:\n");
152  fprintf(stderr," cuikplotforcefield <problem filename> [<sol filename>.sol] <xID> <yID> <zID>\n");
153  fprintf(stderr," where <problem filename> is the description of the problem.\n");
154  fprintf(stderr," <sol filename> is the file with the solution points.\n");
155  fprintf(stderr," If not given we use <problem filename>.sol\n");
156  fprintf(stderr," <xID> <yID> <zID> are the 3 projection dimensions.\n");
157  fprintf(stderr," (indices of system variables as those in the _path.sol file from 0)\n");
158  }
159  return(EXIT_SUCCESS);
160 }
161 
int main(int argc, char **arg)
Main body of the cuikplotforcefield application.
#define FALSE
FALSE.
Definition: boolean.h:30
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 InitPlot3d(char *name, boolean axes, int argc, char **arg, Tplot3d *p)
Constructor.
Definition: plot3d.c:41
#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
char * GetWorldSystemVarName(unsigned int nv, Tworld *w)
Returns the name of a given system variable.
Definition: world.c:2423
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
boolean LoadSamples(Tfilename *fname, unsigned int *nvs, unsigned int *ns, double ***path)
Reads a set of samples from file.
Definition: samples.c:2913
#define PRINT_VARIABLE_NAME(f, name)
Prints a variable name into a file.
Definition: defines.h:427
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
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
boolean InitWorldFromFile(Tparameters *p, boolean error, char *fn, Tworld *w)
Constructor.
void DeleteParameters(Tparameters *p)
Destructor.
Definition: parameters.c:294
#define PLOT3D_EXT
File extension for 3D plot files.
Definition: filename.h:168
Auxiliary functions to deal with sets of samples.
void DeleteSamples(unsigned int ns, double **path)
Deletes the space used by a set of samples.
Definition: samples.c:3159
Definition of the Tparameters type and the associated functions.
void PlotForceField(Tparameters *p, Tplot3d *p3d, unsigned int xID, unsigned int yID, unsigned int zID, Tworld *w, unsigned int ns, double **sols)
Plots the force-field on a set of points.
Definition: samples.c:3056
void ClosePlot3d(boolean quit, double average_x, double average_y, double average_z, Tplot3d *p)
Destructor.
Definition: plot3d.c:473