cuikplotrrt.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 "rrt.h"
9 #include "samples.h"
10 
11 #include <stdlib.h>
12 
67 int main(int argc, char **arg)
68 {
69  TAtlasBase world; /* The set of mechanism and obstacles. */
70  Tparameters parameters; /* Parameters used in the Cuik process. */
71  Trrt rrt; /* The rrt to plot. */
72 
73  unsigned int nx,ny,nz;
74  unsigned int xID,yID,zID;
75  unsigned int i,nv,nvs;
76  boolean *systemVars;
77 
78  double *s1,*s2;
79  double *p1,*p2;
80 
81  Tfilename fparam;
82  Tfilename fplot;
83  Tfilename frrt;
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  CS_WD_INIT(&parameters,arg[1],&world);
94 
95  /* Validate the input projection dimensions */
96  nv=CS_WD_GET_SYSTEM_VARS(&systemVars,&world);
97  nvs=CS_WD_GET_NUM_SYSTEM_VARS(&world);
98 
99  nx=atoi(arg[2]);
100  ny=atoi(arg[3]);
101  nz=atoi(arg[4]);
102 
103  if (nx>=nvs)
104  Error("First index out of range");
105  if (ny>=nvs)
106  Error("Second index out of range");
107  if (nz>=nvs)
108  Error("Third index out of range");
109 
110  fprintf(stderr,"Projecting on variables : ");
111  PRINT_VARIABLE_NAME(stderr,CS_WD_GET_SYSTEM_VAR_NAME(nx,&world));fprintf(stderr,",");
112  PRINT_VARIABLE_NAME(stderr,CS_WD_GET_SYSTEM_VAR_NAME(ny,&world));fprintf(stderr,",");
113  PRINT_VARIABLE_NAME(stderr,CS_WD_GET_SYSTEM_VAR_NAME(nz,&world));fprintf(stderr,"\n");
114 
115  NEW(p1,3,double);
116  if (EXPLORATION_RRT)
117  {
118  ReadOneSample(&parameters,arg[1],CS_WD_GET_NUM_SYSTEM_VARS(&world),&s1);
119  s2=NULL;
120  p2=NULL;
121  }
122  else
123  {
124  ReadTwoSamples(&parameters,arg[1],CS_WD_GET_NUM_SYSTEM_VARS(&world),&s1,&s2);
125  NEW(p2,3,double);
126  p2[0]=s2[nx];
127  p2[1]=s2[ny];
128  p2[2]=s2[nz];
129  }
130  p1[0]=s1[nx];
131  p1[1]=s1[ny];
132  p1[2]=s1[nz];
133 
134  nvs=0;
135  for(i=0;i<nv;i++)
136  {
137  if (systemVars[i])
138  {
139  /* Transform index from system variables only to
140  all variables (in the original system in both cases!!) */
141  if (nx==nvs) xID=i;
142  if (ny==nvs) yID=i;
143  if (nz==nvs) zID=i;
144  nvs++;
145  }
146  }
147 
148  /* Read the RRT */
149  CreateFileName(NULL,arg[1],NULL,RRT_EXT,&frrt);
150  fprintf(stderr,"Reading rrt from : %s\n",GetFileFullName(&frrt));
151  LoadRRT(&parameters,&frrt,&world,&rrt);
152 
153  {
154  Tfilename kk;
155 
156  CreateFileName(NULL,"kk.rrt",NULL,RRT_EXT,&kk);
157 
158  SaveRRT(&kk,&rrt);
159  }
160 
161  /* Create the plot */
162  CreateFileName(NULL,arg[1],"_rrt",PLOT3D_EXT,&fplot);
163  fprintf(stderr,"Generating rrt plot to : %s\n",GetFileFullName(&fplot));
164 
165  PlotRRT(GetFileFullName(&fplot),argc,arg,&parameters,xID,yID,zID,p1,p2,&rrt);
166 
167  /* Release memory */
168  free(s1); free(p1);
169  if (s2!=NULL) {free(s2);free(p2);}
170 
171  DeleteParameters(&parameters);
172 
173  free(systemVars);
174 
175  CS_WD_DELETE(&world);
176 
177  DeleteRRT(&rrt);
178 
179  DeleteFileName(&fplot);
180  DeleteFileName(&frrt);
181  DeleteFileName(&fparam);
182  }
183  else
184  {
185  fprintf(stderr," Wrong number of parameters.\n");
186  fprintf(stderr," Use:\n");
187  fprintf(stderr," cuikplotrrt <problem filename> <xID> <yID> <zID>\n");
188  fprintf(stderr," where <problem filename> is the rrt to plot\n");
189  fprintf(stderr," <xID> <yID> <zID> are the 3 projection dimensions\n");
190 
191  }
192  return(EXIT_SUCCESS);
193 }
194