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