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  if (argc>4)
61  {
62  Tpolyhedron body;
63  THTransform transform;
64  Tfilename bodyIn;
65  Tfilename bodyOut;
66  Tcolor color;
67  char *transforms[10]={"Tx","Ty","Tz","Rx","Ry","Rz","Sc","Sx","Sy","Sz"};
68  unsigned int i;
69  boolean found;
70 
71  NewColor(1,1,1,&color);
72 
73  CreateFileName(NULL,arg[1],NULL,NULL,&bodyIn);
74  InitPolyhedronFromFile(&bodyIn,&color,1,NORMAL_SHAPE,&body);
75 
76  found=FALSE;
77  i=0;
78  while((!found)&&(i<10))
79  {
80  found=(strcasecmp(arg[2],transforms[i])==0);
81  if (!found)
82  i++;
83  }
84 
85  if (!found)
86  Error("Unknown transform in cuiktransform");
87 
88  switch(i)
89  {
90  case 0:
91  HTransformTx(atof(arg[3]),&transform);
92  break;
93  case 1:
94  HTransformTy(atof(arg[3]),&transform);
95  break;
96  case 2:
97  HTransformTz(atof(arg[3]),&transform);
98  break;
99  case 3:
100  HTransformRx(atof(arg[3])*DEG2RAD,&transform);
101  break;
102  case 4:
103  HTransformRy(atof(arg[3])*DEG2RAD,&transform);
104  break;
105  case 5:
106  HTransformRz(atof(arg[3])*DEG2RAD,&transform);
107  break;
108  case 6:
109  HTransformScale(atof(arg[3]),&transform);
110  break;
111  case 7:
112  HTransformScaleX(atof(arg[3]),&transform);
113  break;
114  case 8:
115  HTransformScaleY(atof(arg[3]),&transform);
116  break;
117  case 9:
118  HTransformScaleZ(atof(arg[3]),&transform);
119  break;
120  }
121 
122  TransformPolyhedron(&transform,&body);
123 
124  CreateFileName(NULL,arg[4],NULL,NULL,&bodyOut);
125  SavePolyhedron(GetFileFullName(&bodyOut),&body);
126 
127  HTransformDelete(&transform);
128  DeletePolyhedron(&body);
129  DeleteColor(&color);
130  DeleteFileName(&bodyIn);
131  DeleteFileName(&bodyOut);
132  }
133  else
134  {
135 
136  fprintf(stdout," Wrong number of parameters.\n");
137  fprintf(stdout," Use:\n");
138  fprintf(stdout," cuiktransform <body in> <transform> <value> <body out>\n");
139  fprintf(stdout," Where:\n");
140  fprintf(stdout," <body in>: File with the convex body to transform\n");
141  fprintf(stdout," <transform>: Transform to apply (Tx,Ty,Tz,Rx,Ry,Rz,Sc)\n");
142  fprintf(stdout," <value>: Parameter for the transform (angles in degrees!!).\n");
143  fprintf(stdout," <body out>: Name of output file with the transformed convex body.\n");
144  }
145 
146  return(EXIT_SUCCESS);
147 }
void HTransformScaleY(double s, THTransform *t)
Constructor.
Definition: htransform.c:251
#define FALSE
FALSE.
Definition: boolean.h:30
void HTransformRx(double rx, THTransform *t)
Constructor.
Definition: htransform.c:155
Data structure to hold the information about the name of a file.
Definition: filename.h:248
void HTransformTz(double tz, THTransform *t)
Constructor.
Definition: htransform.c:128
A homgeneous transform in R^3.
#define NORMAL_SHAPE
One of the possible type of shapes.
Definition: polyhedron.h:28
void Error(const char *s)
General error function.
Definition: error.c:80
A color.
Definition: color.h:23
Definition of the Tworld type and the associated functions.
A polyhedron.
Definition: polyhedron.h:124
Error and warning functions.
void DeleteFileName(Tfilename *fn)
Destructor.
Definition: filename.c:205
void HTransformScaleZ(double s, THTransform *t)
Constructor.
Definition: htransform.c:259
void HTransformRz(double rz, THTransform *t)
Constructor.
Definition: htransform.c:189
int main(int argc, char **arg)
Main body of the cuiktransform application.
Definition: cuiktransform.c:58
Definitions of constants and macros used in several parts of the cuik library.
void HTransformScaleX(double s, THTransform *t)
Constructor.
Definition: htransform.c:243
void CreateFileName(char *path, char *name, char *suffix, char *ext, Tfilename *fn)
Constructor.
Definition: filename.c:22
void InitPolyhedronFromFile(Tfilename *fname, Tcolor *c, unsigned int gr, unsigned int bs, Tpolyhedron *p)
Constructor.
Definition: polyhedron.c:727
char * GetFileFullName(Tfilename *fn)
Gets the file full name (paht+name+extension).
Definition: filename.c:151
#define DEG2RAD
Constant to transform from degrees to radiants.
Definition: defines.h:169
void SavePolyhedron(char *fileName, Tpolyhedron *p)
Stores the geometic information of a polyhedron into a file.
Definition: polyhedron.c:1315
void HTransformTx(double tx, THTransform *t)
Constructor.
Definition: htransform.c:106
void HTransformDelete(THTransform *t)
Destructor.
Definition: htransform.c:833
void DeletePolyhedron(Tpolyhedron *p)
Destructor.
Definition: polyhedron.c:1484
void DeleteColor(Tcolor *c)
Destructor.
Definition: color.c:93
void HTransformTy(double ty, THTransform *t)
Constructor.
Definition: htransform.c:117
void TransformPolyhedron(THTransform *t, Tpolyhedron *p)
Applies a homogenoeus transform to a polyhedron.
Definition: polyhedron.c:1113
void NewColor(double r, double g, double b, Tcolor *c)
Constructor.
Definition: color.c:14
void HTransformRy(double ry, THTransform *t)
Constructor.
Definition: htransform.c:172
void HTransformScale(double s, THTransform *t)
Constructor.
Definition: htransform.c:233