2 * Moebius main program.
14 #include "postscript.hh"
17 #include "transforms.hh"
18 #include "graphics.hh"
19 #include "parameter.hh"
22 tn("tn", "Number of sections around `strip'", 30, 1, 1, 500);
25 un("un", "Number of sections across `strip'", 15, 1, 1, 500);
28 version("version", "Version to use: 0=original strip,"
29 " 1=reformulated, 2=reformulated again", 0, 1, 0, 2);
31 static Parameter<double>
32 theta("theta", "Angle of model rotation",
33 /*-PI/2.*/0, M_PI/8., -M_PI*2., M_PI*2.);
35 static Parameter<double>
36 eta("eta", "Angle of model elevation",
37 0., M_PI/8., -M_PI*2., M_PI*2.);
39 static Parameter<double>
40 scale("scale", "Scale factor for resulting object", 1.0, 0.25, 0.001, 1000.);
42 static Parameter<double>
43 planedistance("plane", "Distance from projection plane to origin",
46 static Parameter<double>
47 eyedistance("eye", "Distance from projection eye to origin",
50 static Parameter<double>
51 cutoffdistance("cutoff", "Distance from projection cutoff to origin",
52 10., .25, -10., 100.);
54 static Parameter<double>
55 width("width", "Width of the `strip' before transformation", .4, .1, 0., 1.);
57 static Parameter<double>
58 thickness("thick", "Thickness of the `pancake'", 1., .1, 0., 1.);
60 static Parameter<double>
61 bottomportion("bp", "Proportion in the bottom half", .7, .1, 0., 1.);
63 static Parameter<double>
64 tear("tear", "Angle factor in tear-open", 0/*1.1*/, .1, -5., 5.);
66 static Parameter<double>
67 teary("teary", "Axis y coord in tear-open", 1.3, .1, -10., 10.);
69 static Parameter<double>
70 twist("twist", "Angle per length in twist", 0/*.8*/, .25, -5., 5.);
72 static Parameter<double>
73 twisty("twisty", "Axis y coord in twist", .85, .1, -10., 10.);
75 static Parameter<double>
76 bulge("bulge", "Amount of bulge", 0/*1.*/, .25, -15., 15.);
78 static Parameter<double>
79 bulgesd("bulgesd", "S.D. of bulge", 1., .2, .000001, 20.);
81 static Parameter<double>
82 bulgey("bulgey", "Axis y coord in bulge", .85, .1, -10., 10.);
84 static Parameter<double>
85 shearx("shearx", "Amount of shear (x)", 0., .1, -15., 15.);
87 static Parameter<double>
88 sheary("sheary", "Amount of shear (y)", 0/*1.*/, .1, -15., 15.);
90 static Parameter<double>
91 shearsdx("shearsdx", "S.D. of shear (x)", .5, .1, -15., 15.);
93 static Parameter<double>
94 shearsdy("shearsdy", "S.D. of shear (y)", .5, .1, -15., 15.);
96 static Parameter<double>
97 shearey("shearey", "Centre of shear (y)", 1.3, .1, -10., 10.);
100 SortedCellList *list=0;
102 DualX11Output *dualx11= 0;
104 static Moebius *strip= 0;
107 if (list) delete list;
108 if (strip) { delete strip; strip= 0; }
110 case 0: strip= new MoebiusStrip(width); break;
111 case 1: strip= new MoebiusEnfoldment(thickness,bottomportion); break;
112 case 2: strip= new MoebiusEnfoldmentNew(); break;
115 list= new SortedCellList;
117 for (int ti=0; ti<tn; ti++) {
118 double t1= (double)(ti+1)/tn;
120 for (int ui=0; ui<un; ui++) {
121 double u1= (double)(ui+1)/un;
122 Cell *cell= new Cell;
124 cell->p[0]= strip->middlepoint(t0,u0);
125 //fprintf(stderr,"t %7.4f u %7.4f %7.4f,%7.4f,%7.4f\n",
126 // t0,u0, cell->p[0][0], cell->p[0][1], cell->p[0][2]);
127 cell->p[1]= strip->middlepoint(t0,u1);
128 cell->p[2]= strip->middlepoint(t1,u1);
129 cell->p[3]= strip->middlepoint(t1,u0);
137 int main(int argc, char **argv) {
138 static const char pointmap_cmd[]= "pointmap ";
140 double pointmap_t, pointmap_u;
143 Point::setobserver(theta,eta,planedistance,eyedistance,cutoffdistance);
144 Point::cleartransform();
145 if (tear != 0.0) Point::appendtransform(new TearOpenTransform(tear,teary));
146 if (twist != 0.0) Point::appendtransform(new TwistTransform(twist,twisty));
147 if (bulge != 0.0) Point::appendtransform(new BulgeTransform(bulge,bulgesd,bulgey));
148 if (shearx != 0.0 || sheary != 0.0)
149 Point::appendtransform(new ShearTransform(Point(0.0,shearey,0.0),
150 Point(shearx,sheary,0.0),
151 Point(shearsdx,shearsdy,1e20)));
152 Point::appendtransform(new ScaleTransform(scale));
154 if (x11) list->display(*x11);
155 if (dualx11) list->display(*dualx11);
158 cin.getline(buf,sizeof(buf),'\n');
160 cerr << "error reading command input, giving up\n";
163 char *equals= strchr(buf,'=');
166 AnyParameter *param= AnyParameter::find(buf);
168 *param= atof(equals);
171 cerr << "parameter `" << buf << "' not found\n";
173 } else if (!strncmp(buf,"postscript ",11)) {
174 const char *filename= buf+11;
175 ofstream file(filename);
177 PostScriptOutput psout(file);
178 list->display(psout);
180 cerr << "Failed to open `" << filename << "'\n";
183 cerr << "PostScript written to `" << filename <<"'\n";
184 } else if (!strcmp(buf,"x11")) {
192 } else if (!strcmp(buf,"dualx11")) {
197 dualx11= new DualX11Output;
200 } else if (!strcmp(buf,"quit")) {
202 } else if (!strcmp(buf,"list")) {
203 AnyParameter::help();
204 } else if (!strcmp(buf,"help")) {
205 AnyParameter::list();
206 } else if (!strncmp(buf,pointmap_cmd,sizeof(pointmap_cmd)-1)) {
207 if (sscanf(buf+sizeof(pointmap_cmd)-1, "%lf %lf",
208 &pointmap_t, &pointmap_u) != 2) {
209 cerr << "failed to parse pointmap args\n";
212 Point p= strip->middlepoint(pointmap_t,pointmap_u);
214 for (int i=0; i<3; i++) cout << p.halftransformed()[i] << "\n";
218 cerr << "command not understood\n";