minimise
+primer
+initial
-TARGETS=minimise
+TARGETS= minimise primer initial
CWARNS= -Wall -Wwrite-strings -Wpointer-arith -Werror
CFLAGS= $(CWARNS) $(OPTIMISE) -g
CXXFLAGS= $(CWARNS) $(OPTIMISE) -g
+LIBGSL= -lgsl -lgslcblas
+
all: $(TARGETS)
minimise: energy.o bgl.o common.o mgraph.o
- $(CXX) $(CXXFLAGS) -o $@ $^ -lgsl -lgslcblas
+ $(CXX) $(CXXFLAGS) -o $@ $^ $(LIBGSL)
+
+primer: primer.o common.o
+ $(CC) $(CFLAGS) -o $@ $^ $(LIBGSL)
+
+initial: generator primer sgtatham/z.typescript
+ ./$^ -o$@
clean:
- rm -f *.o $(TARGETS) *.new
+ rm -f *.o $(TARGETS) *.new *.tmp
rm -f best initial
+
+%.o:: common.h mgraph.h bgl.h
r[1]= a[2]*b[0] - a[0]*b[2];
r[2]= a[0]*b[1] - a[1]*b[0];
}
+
+void diee(const char *what) { perror(what); exit(16); }
+void flushoutput(void) { if (fflush(stdout)||ferror(stdout)) diee("stdout"); }
double magnD(const double pq[D3]);
void xprod(double r[D3], const double a[D3], const double b[D3]);
+void flushoutput(void);
+void diee(const char *what);
+
#define FOR_COORD(k) \
for ((k)=0; (k)<D3; (k)++)
static void compute_vertex_areas(const Vertices vertices, double areas[N]);
static double best_energy= DBL_MAX;
-static void flushoutput(void);
-static void diee(const char *what) { perror(what); exit(16); }
static void cost(double *energy, double tweight, double tcost);
#define COST(weight, compute) cost(&energy, (weight), (compute))
*energy += tenergy;
}
-static void flushoutput(void) {
- if (fflush(stdout) || ferror(stdout)) diee("stdout");
-}
-
static void compute_vertex_areas(const Vertices vertices, double areas[N]) {
int v0,v1,v2, e1,e2, k;
static const double stop_epsilon= 1e-4;
-#define DIM (N*D3)
-
static double minfunc_f(const gsl_vector *x, void *params) {
assert(x->size == DIM);
assert(x->stride == 1);
--- /dev/null
+#!/usr/bin/perl
+die unless @ARGV==3;
+($primer,$ztype,$output) = @ARGV;
+$output =~ s/^\-o// or die "$output ?";
+
+$gnuplot= "$output.gnuplot.tmp";
+$initdata= "$output.initdata.tmp";
+
+open Z, "$ztype" or die "$ztype $!";
+open G, ">$gnuplot" or die $!;
+
+sub pg ($$) { printf G "%s(u,v) = %s\n", @_ or die $!; }
+
+for (;;) {
+ $!=0; defined($_= <Z>) or die "$ztype $!";
+ s/\r$//;
+ next unless m/^splot\s+([^,]+),([^,]+),([^,]+)\s*$/;
+ pg('x',$1); pg('y',$2); pg('z',$3);
+ last;
+}
+
+printf G "set print \"-\"\n" or die $!;
+close G or die $!;
+
+sub run ($) {
+ print " $_[0]\n";
+ $!=0; system($_[0]); die "$! $?" if $! or $?;
+}
+
+run("./$primer >>$gnuplot");
+run("gnuplot $gnuplot >$initdata");
+
+open I, "$initdata" or die "$initdata $!";
+open B, ">$output.new" or die "$output.new $!";
+
+$_= <I>;
+m/^(\d+) .*/ or die "$_ ?";
+
+$dim= $1;
+for ($i=0; $i<$dim; $i++) {
+ $!=0; defined($_= <I>) or die "$initdata $!";
+ print B pack "d", $_ or die $!;
+}
+
+close B or die $!;
+rename "$output.new",$output or die $!;
+
+print " wrote $output\n";
#define Y1 (1 << YSHIFT)
#define YMASK ((Y-1) << YSHIFT)
+#define DIM (N*D3)
+
#define V6 6
#define FOR_VERTEX(v) \
--- /dev/null
+/*
+ * Generates the repetitive part of the gnuplot input
+ * for generating the initial triangle vertices from SGT's
+ * model.
+ */
+
+#include "common.h"
+#include "mgraph.h"
+
+int main(int argc, const char **argv) {
+ int v, k;
+
+ if (argc>1) { fputs("no args please\n",stderr); exit(8); }
+
+ printf("print %d, %d, %d, %d, %d\n", DIM, N, X, Y, D3);
+
+ FOR_VERTEX(v) {
+ int x= v & XMASK; /* distance along strip */
+ int y= y >> YSHIFT; /* distance across strip */
+ double u= y * 1.0 / (Y-1);
+ double v= x * M_PI / (X-1); /* SGT's u runs 0..pi along the strip */
+ K printf("print %c(%.*g,%.*g)\n",
+ "xyz"[k],
+ DBL_DIG+2,u, DBL_DIG+2,v);
+ }
+ flushoutput();
+ return 0;
+}