cuikplot3d.c
Go to the documentation of this file.
1 #include "boolean.h"
2 #include "plot3d.h"
3 #include "box.h"
4 #include "defines.h"
5 #include "filename.h"
6 #include "color.h"
7 
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <string.h>
11 #include <math.h>
12 
64 int main(int argc, char **arg)
65 {
66  Tbox box;
67  int token;
68  Tplot3d plot;
69  FILE *PSin;
70  Tinterval *x,*y,*z;
71  unsigned int dim_x,dim_y,dim_z;
72  double min_x,max_x,min_y,max_y, min_z,max_z;
73  double minSize;
74  Tfilename fsols,fplot;
75  Tcolor plotColor;
76 
77  if (argc<7)
78  {
79  fprintf(stderr,"Use:\n");
80  fprintf(stderr," cuikplot3d <filename> dimx dimy dimz min_size <plotname> \n");
81  fprintf(stderr," <filename> the input .sol file\n");
82  fprintf(stderr," dimx dimy dimz -> the three dimensions to be plotted (numbered from 1)\n");
83  fprintf(stderr," min_size -> minimum size for the boxes\n");
84  fprintf(stderr," <plotname> the output .gcl file\n");
85  }
86  else
87  {
88  CreateFileName(NULL,arg[1],NULL,SOL_EXT,&fsols);
89 
90  /*"Parse" the input parameters*/
91 
92  /*Input file name*/
93  PSin=fopen(GetFileFullName(&fsols),"r");
94  if (!PSin)
95  Error("Input file can not be opened");
96  #if (_DEBUG>0)
97  printf("Reading solution file : %s\n",GetFileFullName(&fsols));
98  #endif
99 
100  /*Dimension on which to project*/
101  dim_x=(unsigned int)atoi(arg[2]);
102  dim_y=(unsigned int)atoi(arg[3]);
103  dim_z=(unsigned int)atoi(arg[4]);
104 
105  /*Check that the dimensions are ok (positive not repeated)*/
106  if ((dim_x==0)||(dim_y==0)||(dim_z==0))
107  Error("Dimensions are numbered from 1\n");
108  /*
109  if ((dim_x==dim_y)||(dim_x==dim_z)||(dim_y==dim_z))
110  Error("Plotting dimensions must be different\n");
111  */
112  dim_x=dim_x-1;
113  dim_y=dim_y-1;
114  dim_z=dim_z-1;
115 
116  /*Rewin the file*/
117  fclose(PSin);
118 
119  PSin=fopen(GetFileFullName(&fsols),"r");
120 
121  /*Get the minSize parameter*/
122  minSize=(double)atof(arg[5]);
123 
124  /*and now we plot in 3D*/
125  CreateFileName(NULL,arg[6],NULL,PLOT3D_EXT,&fplot);
126  InitPlot3d(GetFileFullName(&fplot),FALSE,argc,arg,&plot);
127  #if (_DEBUG>0)
128  printf("Creating plot file : %s\n",GetFileFullName(&fplot));
129  #endif
130  DeleteFileName(&fplot);
131 
132  NewColor(DCP3D_R,DCP3D_G,DCP3D_B,&plotColor);
133  StartNew3dObject(&plotColor,&plot);
134  DeleteColor(&plotColor);
135 
136  do {
137  token=ReadBox(PSin,&box);
138  if (token!=EOF)
139  {
140  /*Get the interval of the box in the projection dimentions*/
141  x=GetBoxInterval(dim_x,&box);
142  y=GetBoxInterval(dim_y,&box);
143  z=GetBoxInterval(dim_z,&box);
144 
145  /*and get the extreme of the intervals*/
146  min_x=LowerLimit(x);
147  max_x=UpperLimit(x);
148 
149  min_y=LowerLimit(y);
150  max_y=UpperLimit(y);
151 
152  min_z=LowerLimit(z);
153  max_z=UpperLimit(z);
154 
155  /* Hack to move the boxes*/
156  #if (0)
157  if (min_x>0.5)
158  {
159  min_x-=M_2PI;
160  max_x-=M_2PI;
161  }
162  #endif
163 
164  /*if the box is too small we enlarge it (otherwise we have "invisible" boxes*/
165  if (((max_x-min_x)<minSize)&&
166  ((max_y-min_y)<minSize)&&
167  ((max_z-min_z)<minSize))
168  {
169  double r;
170 
171  r=minSize/2;
172 
173  max_x+=r; min_x-=r;
174  max_y+=r; min_y-=r;
175  max_z+=r; min_z-=r;
176  }
177 
178  /*and add the box to the plot*/
179 
180  PlotBox3d(min_x,max_x,min_y,max_y,min_z,max_z,&plot);
181 
182  //if (isolated)
183  // StartNew3dObject(0,0,1,&plot);
184 
185  DeleteBox(&box);
186  }
187  } while (token!=EOF);
188 
189  ClosePlot3d(FALSE,0,0,0,&plot);
190 
191  DeleteFileName(&fsols);
192  fclose(PSin);
193  }
194 
195  return(EXIT_SUCCESS);
196 }
Definition of the boolean type.
Tinterval * GetBoxInterval(unsigned int n, Tbox *b)
Returns a pointer to one of the intervals defining the box.
Definition: box.c:270
void PlotBox3d(double min_x, double max_x, double min_y, double max_y, double min_z, double max_z, Tplot3d *p)
Adds an axis aligned box to the current object.
Definition: plot3d.c:224
#define FALSE
FALSE.
Definition: boolean.h:30
Data structure to hold the information about the name of a file.
Definition: filename.h:248
int main(int argc, char **arg)
Main body of the cuikplot3d application.
Definition: cuikplot3d.c:64
Definition of the Tfilename type and the associated functions.
Definition of the Tplot3d type and the associated functions.
void InitPlot3d(char *name, boolean axes, int argc, char **arg, Tplot3d *p)
Constructor.
Definition: plot3d.c:41
void Error(const char *s)
General error function.
Definition: error.c:80
A color.
Definition: color.h:23
void DeleteFileName(Tfilename *fn)
Destructor.
Definition: filename.c:205
int ReadBox(FILE *f, Tbox *b)
Reads a box from a file.
Definition: box.c:1172
A 3D plot.
Definition: plot3d.h:54
double LowerLimit(Tinterval *i)
Gets the lower limit.
Definition: interval.c:79
Definition of the Tbox type and the associated functions.
Definitions of constants and macros used in several parts of the cuik library.
void CreateFileName(char *path, char *name, char *suffix, char *ext, Tfilename *fn)
Constructor.
Definition: filename.c:22
double UpperLimit(Tinterval *i)
Gets the uppser limit.
Definition: interval.c:87
char * GetFileFullName(Tfilename *fn)
Gets the file full name (paht+name+extension).
Definition: filename.c:151
#define M_2PI
2*Pi.
Definition: defines.h:100
#define SOL_EXT
File extension for solution files.
Definition: filename.h:137
A box.
Definition: box.h:83
Definition of the Tcolor type and the associated functions.
void DeleteBox(void *b)
Destructor.
Definition: box.c:1259
#define PLOT3D_EXT
File extension for 3D plot files.
Definition: filename.h:167
#define DCP3D_G
Green component of the default color of 3d objects.
Definition: plot3d.h:38
void DeleteColor(Tcolor *c)
Destructor.
Definition: color.c:93
#define DCP3D_R
Red component of the default color of 3d objects.
Definition: plot3d.h:30
void NewColor(double r, double g, double b, Tcolor *c)
Constructor.
Definition: color.c:14
Defines a interval.
Definition: interval.h:33
#define DCP3D_B
Blue component of the default color of 3d objects.
Definition: plot3d.h:46
unsigned int StartNew3dObject(Tcolor *c, Tplot3d *p)
Start a composed object.
Definition: plot3d.c:157
void ClosePlot3d(boolean quit, double average_x, double average_y, double average_z, Tplot3d *p)
Destructor.
Definition: plot3d.c:473