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 
77  unsigned int ns,nvs;
78  double **sols;
79 
80  Tfilename fparam;
81  Tfilename fsols;
82 
83  //boolean smooth;
84 
85  if (argc>=5)
86  {
87  /*Init parameters*/
88  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
89  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
90  fprintf(stderr,"Reading parameters from : %s\n",GetFileFullName(&fparam));
91 
92  /*Read the world from file*/
93  InitWorldFromFile(&parameters,FALSE,TRUE,arg[1],&world);
94 
95  /* Validate the input projection dimensions */
96  nvs=GetWorldNumSystemVariables(&world);
97 
98  if (argc>5)
99  {
100  CreateFileName(NULL,arg[2],NULL,SOL_EXT,&fsols);
101 
102  nx=atoi(arg[3]);
103  ny=atoi(arg[4]);
104  nz=atoi(arg[5]);
105  }
106  else
107  {
108  CreateFileName(NULL,arg[1],NULL,SOL_EXT,&fsols);
109 
110  nx=atoi(arg[2]);
111  ny=atoi(arg[3]);
112  nz=atoi(arg[4]);
113  }
114 
115  if (nx>=nvs)
116  Error("First index out of range");
117  if (ny>=nvs)
118  Error("Second index out of range");
119  if (nz>=nvs)
120  Error("Third index out of range");
121 
122  fprintf(stderr,"Projecting on variables : ");
123  PRINT_VARIABLE_NAME(stderr,GetWorldSystemVarName(nx,&world));fprintf(stderr,",");
124  PRINT_VARIABLE_NAME(stderr,GetWorldSystemVarName(ny,&world));fprintf(stderr,",");
125  PRINT_VARIABLE_NAME(stderr,GetWorldSystemVarName(nz,&world));fprintf(stderr,"\n");
126 
127  /* Load the points */
128  if (LoadSamples(&fsols,&nvs,&ns,&sols))
129  {
130  /*If the solutions were actually loaded*/
131  Tfilename fffplot;
132  Tplot3d p3d;
133 
134  if (argc>5)
135  CreateFileName(NULL,arg[2],"_ff",PLOT3D_EXT,&fffplot);
136  else
137  CreateFileName(NULL,arg[1],"_ff",PLOT3D_EXT,&fffplot);
138 
139  /* and plot the force field at the ponts */
140  fprintf(stderr,"Generating force field plot to : %s\n",GetFileFullName(&fffplot));
141 
142  InitPlot3d(GetFileFullName(&fffplot),FALSE,argc,arg,&p3d);
143 
144  PlotForceField(&parameters,&p3d,nx,ny,nz,&world,ns,sols);
145 
146  ClosePlot3d(FALSE,&p3d);
147 
148  DeleteFileName(&fffplot);
149  DeleteSamples(ns,sols);
150  }
151  else
152  Error("Can not read the file with the solution points");
153 
154  DeleteParameters(&parameters);
155  DeleteWorld(&world);
156 
157  DeleteFileName(&fsols);
158  DeleteFileName(&fparam);
159  }
160  else
161  {
162  fprintf(stderr," Wrong number of parameters.\n");
163  fprintf(stderr," Use:\n");
164  fprintf(stderr," cuikplotforcefield <problem filename> [<sol filename>.sol] <xID> <yID> <zID>\n");
165  fprintf(stderr," where <problem filename> is the description of the problem.\n");
166  fprintf(stderr," <sol filename> is the file with the solution points.\n");
167  fprintf(stderr," If not given we use <problem filename>.sol\n");
168  fprintf(stderr," <xID> <yID> <zID> are the 3 projection dimensions.\n");
169  fprintf(stderr," (indices of system variables as those in the _path.sol file from 0)\n");
170  }
171  return(EXIT_SUCCESS);
172 }
173