chiark / gitweb /
found in ijackson@chiark:things/moebius.old-before-cvs
[moebius.git] / main.cc~
1 /*
2  * Moebius main program.
3  */
4
5 #include <math.h>
6 #include <iostream.h>
7 #include <string.h>
8 #include <stdlib.h>
9 #include <stdio.h>
10
11 #include "output.hh"
12 #include "x11.hh"
13 #include "dualx11.hh"
14 #include "postscript.hh"
15 #include "library.hh"
16 #include "moebius.hh"
17 #include "transforms.hh"
18 #include "graphics.hh"
19 #include "parameter.hh"
20
21 template class Parameter<int>;
22 Parameter<int> tn("tn", "Number of sections around `strip'", 30, 1, 1, 500);
23 Parameter<int> un("un", "Number of sections across `strip'", 15, 1, 1, 500);
24 Parameter<double> theta("theta", "Angle of model rotation",
25                         /*-PI/2.*/0, PI/8., -PI*2., PI*2.);
26 Parameter<double> eta("eta", "Angle of model elevation", 0., PI/8., -PI*2., PI*2.);
27 Parameter<double> planedistance("plane", "Distance from projection plane to origin", 
28                                 4., .25, 0., 100.);
29 Parameter<double> eyedistance("eye", "Distance from projection eye to origin", 
30                               1.5, .25, 0., 100.);
31 Parameter<double> cutoffdistance("cutoff", "Distance from projection cutoff to origin", 
32                                  10., .25, -10., 100.);
33 Parameter<double> width("width", "Width of the `strip' before transformation", 
34                         .4, .1, 0., 1.);
35 Parameter<double> thickness("thick", "Thickness of the `pancake'", 1., .1, 0., 1.);
36 Parameter<double> bottomportion("bp", "Proportion in the bottom half", 
37                                 .7, .1, 0., 1.);
38 //Parameter<double> tear("tear", "Angle factor in tear-open", 0/*1.1*/, .1, -5., 5.);
39 //Parameter<double> teary("teary", "Axis y coord in tear-open", 1.3, .1, -10., 10.);
40 //Parameter<double> twist("twist", "Angle per length in twist", 0/*.8*/, .25, -5., 5.);
41 //Parameter<double> twisty("twisty", "Axis y coord in twist", .85, .1, -10., 10.);
42 //Parameter<double> bulge("bulge", "Amount of bulge", 0/*1.*/, .25, -15., 15.);
43 //Parameter<double> bulgesd("bulgesd", "S.D. of bulge", 1., .2, .000001, 20.);
44 //Parameter<double> bulgey("bulgey", "Axis y coord in bulge", .85, .1, -10., 10.);
45 //Parameter<double> shearx("shearx", "Amount of shear (x)", 0., .1, -15., 15.);
46 //Parameter<double> sheary("sheary", "Amount of shear (y)", 0/*1.*/, .1, -15., 15.);
47 //Parameter<double> shearsdx("shearsdx", "S.D. of shear (x)", .5, .1, -15., 15.);
48 //Parameter<double> shearsdy("shearsdy", "S.D. of shear (y)", .5, .1, -15., 15.);
49 //Parameter<double> shearey("shearey", "Centre of shear (y)", 1.3, .1, -10., 10.);
50
51 SortedCellList *list=0;
52 X11Output *x11= 0;
53 DualX11Output *dualx11= 0;
54
55 void generate() {
56   if (list) delete list;
57   // MoebiusStrip strip(width);
58   MoebiusEnfoldment strip(thickness,bottomportion);
59   list= new SortedCellList;
60   double t0= 0.0;
61   for (int ti=0; ti<tn; ti++) {
62     double t1= (double)(ti+1)/tn;
63     double u0= 0.0;
64     for (int ui=0; ui<un; ui++) {
65       double u1= (double)(ui+1)/un;
66       Cell *cell= new Cell;
67 //u0=u1=tear;
68       cell->p[0]= strip.middlepoint(t0,u0);
69 //fprintf(stderr,"t %7.4f u %7.4f  %7.4f,%7.4f,%7.4f\n",
70 //        t0,u0, cell->p[0][0], cell->p[0][1], cell->p[0][2]);
71       cell->p[1]= strip.middlepoint(t0,u1);
72       cell->p[2]= strip.middlepoint(t1,u1);
73       cell->p[3]= strip.middlepoint(t1,u0);
74       list->insert(cell);
75       u0= u1;
76     }
77     t0= t1;
78   }
79 }
80
81 int main(int argc, char **argv) {
82   char buf[100];
83
84   for (;;) {
85     Point::setobserver(theta,eta,planedistance,eyedistance,cutoffdistance);
86     Point::cleartransform();
87 //    if (tear != 0.0) Point::appendtransform(new TearOpenTransform(tear,teary));
88 //    if (twist != 0.0) Point::appendtransform(new TwistTransform(twist,twisty));
89 //    if (bulge != 0.0) Point::appendtransform(new BulgeTransform(bulge,bulgesd,bulgey));
90 //    if (shearx != 0.0 || sheary != 0.0)
91 //      Point::appendtransform(new ShearTransform(Point(0.0,shearey,0.0),
92 //                                                Point(shearx,sheary,0.0),
93 //                                                Point(shearsdx,shearsdy,1e20)));
94     generate();
95     if (x11) list->display(*x11);
96     if (dualx11) list->display(*dualx11);
97     for (;;) {
98       cin.get(buf,100,'\n');
99       char c;
100       if (!cin.get(c) || c!='\n') {
101         cerr << "error reading command input, giving up\n";
102         exit(1);
103       }
104       char *equals= strchr(buf,'=');
105       if (equals) {
106         *equals++= 0;
107         AnyParameter *param= AnyParameter::find(buf);
108         if (param) {
109           *param= atof(equals);
110           break;
111         } else {
112           cerr << "parameter `" << buf << "' not found\n";
113         }
114       } else if (!strncmp(buf,"postscript ",11)) {
115         const char *filename= buf+11;
116         ofstream file(filename);
117         if (file) {
118           PostScriptOutput psout(file);
119           list->display(psout);
120         } else {
121           cerr << "Failed to open `" << filename << "'\n";
122           continue;
123         }
124         cerr << "PostScript written to `" << filename <<"'\n";
125       } else if (!strcmp(buf,"x11")) {
126         if (x11) {
127           delete x11;
128           x11= 0;
129         } else {
130           x11= new X11Output;
131         }
132         break;
133       } else if (!strcmp(buf,"dualx11")) {
134         if (dualx11) {
135           delete dualx11;
136           dualx11= 0;
137         } else {
138           dualx11= new DualX11Output;
139         }
140         break;
141       } else if (!strcmp(buf,"quit")) {
142         exit(0);
143       } else if (!strcmp(buf,"list")) {
144         AnyParameter::list();
145       } else if (!*buf) {
146         break;
147       } else {
148         cerr << "command not understood\n";
149       }
150     }
151   }
152 }
153