00001 package org.hfbk.vis.visnode;
00002
00003 import java.io.BufferedReader;
00004 import java.io.File;
00005 import java.io.FileNotFoundException;
00006 import java.io.FileReader;
00007 import java.io.IOException;
00008 import java.util.LinkedList;
00009 import java.util.List;
00010
00011 import org.dronus.graph.Node;
00012 import org.hfbk.vis.Prefs;
00013 import org.lwjgl.opengl.GL11;
00014 import org.lwjgl.util.vector.Vector3f;
00015
00016 public class VisStrip extends VisNode {
00017
00018 int dl;
00019
00020 float tx, ty, tz, maxx, maxz, minx, minz;
00021
00022 class Poly extends LinkedList<Vector3f> {
00023 };
00024
00025 class Frame extends LinkedList<Poly> {
00026 };
00027
00028 List<Frame> frames = new LinkedList<Frame>();
00029
00030 List<Vector3f> markers = new LinkedList<Vector3f>();
00031
00032 String mapfile = "misc/salon.coord";
00033
00034 public VisStrip(Node node, Vector3f dummy) {
00035 super(node, new Vector3f());
00036
00037
00038
00039
00040 loadWalls();
00041
00042 radius = 2000;
00043
00044
00045
00046
00047
00048
00049
00050
00051 }
00052
00053 private void loadWalls() {
00054 float off = 0;
00055 File f = null;
00056
00057 f = new File("misc/strip/");
00058
00059 int max = f.listFiles().length;
00060 for (int count = 0; count < max && count < 1200; count++) {
00061 try {
00062
00063 String fname = "misc/strip/so" + String.format("%1$04d", count)
00064 + ".coord";
00065
00066 if (Prefs.current.verbose)
00067 System.out.println(fname);
00068 BufferedReader r = new BufferedReader(new FileReader(new File(
00069 fname)));
00070
00071 String l;
00072 maxx = -100000;
00073 maxz = -100000;
00074 minx = 100000;
00075 minz = 100000;
00076
00077 Frame currentFrame = new Frame();
00078 frames.add(currentFrame);
00079
00080 do {
00081 off += .1;
00082 Poly currentWall = new Poly();
00083 currentFrame.add(currentWall);
00084
00085 while ((l = r.readLine()) != null) {
00086 if (l.equals(""))
00087 break;
00088 else {
00089 String[] coords = l.split(" ");
00090
00091 if (coords[0].equals("M")) {
00092 markers.add(new Vector3f(Float
00093 .parseFloat(coords[1]), Float
00094 .parseFloat(coords[2]), Float
00095 .parseFloat(coords[3])));
00096 } else {
00097 tx = Float.parseFloat(coords[0]);
00098 ty = off;
00099 tz = Float.parseFloat(coords[2]);
00100
00101 minx = Math.min(tx, minx);
00102
00103 maxx = Math.max(tx, maxx);
00104
00105 minz = Math.min(tz, minz);
00106 maxz = Math.max(tz, maxz);
00107
00108 currentWall.add(new Vector3f(tx, ty, tz));
00109
00110 }
00111 }
00112 }
00113 } while (l != null);
00114 if (Prefs.current.verbose)
00115 System.out.println(minz + " " + maxz + " " + minx + " "
00116 + maxx);
00117
00118
00119
00120
00121 } catch (FileNotFoundException e) {
00122
00123 } catch (NumberFormatException e) {
00124
00125 e.printStackTrace();
00126 } catch (IOException e) {
00127
00128 e.printStackTrace();
00129 }
00130
00131 }
00132
00133 }
00134
00135 @Override
00136 void transform() {
00137 super.transform();
00138 GL11.glTranslatef(0, 0, -1000);
00139 GL11.glRotatef(180, 0, 1, 0);
00140 GL11.glScalef(.4f, .4f, .4f);
00141 GL11.glRotatef(-90, 1, 0, 0);
00142 }
00143
00144 @Override
00145 void renderSelf() {
00146
00147 if (dl == 0) {
00148 dl = GL11.glGenLists(1);
00149 GL11.glNewList(dl, GL11.GL_COMPILE);
00150 GL11.glDisable(GL11.GL_TEXTURE_2D);
00151
00152 GL11.glColor4f(1, 1, 1, .5f);
00153
00154
00155
00156 Frame lastframe = null;
00157
00158 for (Frame frame : frames) {
00159 for (List<Vector3f> wall : frame) {
00160
00161
00162
00163
00164
00165
00166 if (wall.size() > 1) {
00167 GL11.glColor4f(1, 1, 1, .3f);
00168 GL11.glBegin(GL11.GL_LINE_STRIP);
00169 for (Vector3f segment : wall)
00170 GL11.glVertex3f(segment.x, segment.y, segment.z);
00171 GL11.glEnd();
00172
00173 double TOLERANCE = 20;
00174 GL11.glColor4f(1, 1, 1, .7f);
00175 GL11.glBegin(GL11.GL_LINES);
00176 if (lastframe != null)
00177 for (Vector3f segment : wall) {
00178 Vector3f match = null;
00179 double mindist = Double.MAX_VALUE;
00180 for (Poly pastwall : lastframe)
00181 for (Vector3f pastSegment : pastwall) {
00182 float dx = segment.x - pastSegment.x;
00183 float dz = segment.z - pastSegment.z;
00184 double dist = dx * dx + dz * dz;
00185 if (dist < mindist && dist < TOLERANCE) {
00186 mindist = dist;
00187 match = pastSegment;
00188 }
00189 }
00190 if (match != null) {
00191 GL11.glVertex3f(segment.x, segment.y,
00192 segment.z);
00193 GL11.glVertex3f(match.x, match.y, match.z);
00194 }
00195 }
00196 GL11.glEnd();
00197
00198 }
00199 }
00200
00201
00202
00203
00204
00205
00206
00207
00208 lastframe = frame;
00209
00210 }
00211
00212 GL11.glBegin(GL11.GL_LINES);
00213 for (Vector3f segment : markers) {
00214 GL11.glVertex3f(segment.x, segment.y, segment.z);
00215 GL11.glVertex3f(segment.x, segment.y + 50, segment.z);
00216 }
00217 GL11.glEnd();
00218
00219
00220 GL11.glDisable(GL11.GL_LIGHTING);
00221 GL11.glEndList();
00222 }
00223 GL11.glCallList(dl);
00224 }
00225 }