cuiktransform.c
Go to the documentation of this file.
1 #include "world.h"
2 #include "error.h"
3 #include "defines.h"
4 
5 #include <strings.h>
6 
58 int main(int argc, char **arg)
59 {
60  boolean wrongParameters=FALSE;
61 
62  if (argc>3)
63  {
64  Tpolyhedron body;
65  THTransform transform;
66  Tfilename bodyIn;
67  Tfilename bodyOut;
68  Tcolor color;
69  char *transforms[11]={"Tx","Ty","Tz","Rx","Ry","Rz","Sc","Sx","Sy","Sz","Sp"};
70  unsigned int i;
71  boolean found;
72 
73  found=FALSE;
74  i=0;
75  while((!found)&&(i<11))
76  {
77  found=(strcasecmp(arg[2],transforms[i])==0);
78  if (!found)
79  i++;
80  }
81 
82  if ((i<10)&&(argc==4))
83  wrongParameters=TRUE;
84  else
85  {
86  if (!found)
87  Error("Unknown transform in cuiktransform");
88 
89  NewColor(1,1,1,&color);
90 
91  CreateFileName(NULL,arg[1],NULL,NULL,&bodyIn);
92  InitPolyhedronFromFile(&bodyIn,&color,1,NORMAL_SHAPE,&body);
93 
94  switch(i)
95  {
96  case 0:
97  HTransformTx(atof(arg[3]),&transform);
98  break;
99  case 1:
100  HTransformTy(atof(arg[3]),&transform);
101  break;
102  case 2:
103  HTransformTz(atof(arg[3]),&transform);
104  break;
105  case 3:
106  HTransformRx(atof(arg[3])*DEG2RAD,&transform);
107  break;
108  case 4:
109  HTransformRy(atof(arg[3])*DEG2RAD,&transform);
110  break;
111  case 5:
112  HTransformRz(atof(arg[3])*DEG2RAD,&transform);
113  break;
114  case 6:
115  HTransformScale(atof(arg[3]),&transform);
116  break;
117  case 7:
118  HTransformScaleX(atof(arg[3]),&transform);
119  break;
120  case 8:
121  HTransformScaleY(atof(arg[3]),&transform);
122  break;
123  case 9:
124  HTransformScaleZ(atof(arg[3]),&transform);
125  break;
126  case 10:
127  SimplifyPolyhedron(&body);
128  break;
129  }
130  if (i<10)
131  {
132  TransformPolyhedron(&transform,&body);
133  CreateFileName(NULL,arg[4],NULL,NULL,&bodyOut);
134  }
135  else
136  CreateFileName(NULL,arg[3],NULL,NULL,&bodyOut);
137 
138  SavePolyhedron(GetFileFullName(&bodyOut),&body);
139 
140  HTransformDelete(&transform);
141  DeletePolyhedron(&body);
142  DeleteColor(&color);
143  DeleteFileName(&bodyIn);
144  DeleteFileName(&bodyOut);
145  }
146  }
147  else
148  wrongParameters=TRUE;
149 
150  if (wrongParameters)
151  {
152  fprintf(stdout," Wrong number of parameters.\n");
153  fprintf(stdout," Use:\n");
154  fprintf(stdout," cuiktransform <body in> <transform> <value> <body out>\n");
155  fprintf(stdout," Where:\n");
156  fprintf(stdout," <body in>: File with the convex body to transform\n");
157  fprintf(stdout," <transform>: Transform to apply (Tx,Ty,Tz,Rx,Ry,Rz,Sc,Sx,Sy,Sz,Sp)\n");
158  fprintf(stdout," <value>: Parameter for the transform (angles in degrees!!).\n");
159  fprintf(stdout," <body out>: Name of output file with the transformed convex body.\n");
160  }
161 
162  return(EXIT_SUCCESS);
163 }