/* This currently shows the 1,2,3 max bursters in a 3D representation for on 36th of the space (i.e. the last two dimensions are fixed, currently at (0,0) I'd like to extend this to handle more classes of bursters (say about 10) and also to have all 36 projections selectable one at a time. We could have a control panel that would allow one to specify which of the 36 projectsion to show and which of the 10-20 classes .. grand tour style ... This ought to take about 1-2 hours and should provide some interesting views. Also selecting the 6 ortho projection views would be nice as well.... Finally, modifying it so that you can select the permutation used for the projection would be nice! */ import java.awt.*; import java.awt.event.*; import java.io.StreamTokenizer; import java.io.BufferedReader; import java.io.FileReader; import net.java.games.jogl.*; import net.java.games.jogl.util.*; /** * Gears.java
* author: Brian Paul (converted to Java by Ron Cemer and Sven Goethel)

* * This version is equal to Brian Paul's version 1.2 1999/10/21 */ public class Neuron2 implements GLEventListener, MouseListener, MouseMotionListener, KeyListener { private static jscheme.JScheme js = new jscheme.JScheme(); public int show_i=0, show_j=0; public boolean[] showData={false,false,false,false,false,false,false,false,false,false,false}; public static void main(String[] args) { new Neuron2(); } public Neuron2() { Frame frame = new Frame("3D Neuron Demo"); GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities()); try{ js.load(new java.io.FileReader("neuron-control.scm"));} catch(Exception e) {System.out.println("loading error: "+e);} js.call("make-controller",this); canvas.addGLEventListener(this); canvas.addKeyListener(this); frame.add(canvas); frame.setSize(300, 300); final Animator animator = new Animator(canvas); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { // Run this on another thread than the AWT event queue to // make sure the call to Animator.stop() completes before // exiting new Thread(new Runnable() { public void run() { animator.stop(); System.exit(0); } }).start(); } }); frame.show(); animator.start(); } private float view_rotx = 0.0f, view_roty = 0.0f, view_rotz = 0.0f; private int[][][] neuronData = new int[6][6][10]; private float angle = 0.0f; private int prevMouseX, prevMouseY; private boolean mouseRButtonDown = false; float red[] = { 1.0f, 0.0f, 0.0f, 1.0f }; float pink[] = { 0.8f, 0.5f, 0.5f, 1.0f }; float yellow[] = { 1f, 1f, 0.0f, 1.0f }; float green[] = { 0.0f, 1f, 0f, 1.0f }; float bluegreen[] = { 0.0f, 0.5f, 0.5f, 1.0f }; float darkgreen[] = { 0.0f, 0.5f, 0.0f, 1.0f }; float blue[] = { 0.0f, 0.0f, 1.0f, 1.0f }; float lightblue[] = { 0.7f, 0.7f, 1.0f, 1.0f }; float gray[] = { 0.7f, 0.7f, .7f, 1.0f }; float darkblue[] = { 0.0f, 0.0f, 0.5f, 1.0f }; float[][] colorCode = {red,green,blue,pink,bluegreen,yellow,darkgreen,lightblue,darkblue,gray}; public void init(GLDrawable drawable) { // Use debug pipeline // drawable.setGL(new DebugGL(drawable.getGL())); GL gl = drawable.getGL(); System.err.println("INIT GL IS: " + gl.getClass().getName()); gl.setSwapInterval(1); float pos[] = { 5.0f, 5.0f, 10.0f, 0.0f }; gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, pos); gl.glEnable(GL.GL_CULL_FACE); gl.glEnable(GL.GL_LIGHTING); gl.glEnable(GL.GL_LIGHT0); gl.glEnable(GL.GL_DEPTH_TEST); /* make the neuron maps */ for(int i=0; i<6; i++) for(int j=0;j<6;j++) for(int k=0;k<10;k++) { System.out.println("Generating list i="+i+", j="+j+", k="+k); neuronData[i][j][k] = gl.glGenLists(1); gl.glNewList(neuronData[i][j][k], GL.GL_COMPILE); gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, colorCode[k]); neuron(gl,i,j,k); gl.glEndList(); } gl.glEnable(GL.GL_NORMALIZE); drawable.addMouseListener(this); drawable.addMouseMotionListener(this); drawable.addKeyListener(this); } float h; int filter = 0; public void reshape(GLDrawable drawable, int x, int y, int width, int height) { GL gl = drawable.getGL(); h = (float)height / (float)width; gl.glMatrixMode(GL.GL_PROJECTION); System.err.println("GL_VENDOR: " + gl.glGetString(GL.GL_VENDOR)); System.err.println("GL_RENDERER: " + gl.glGetString(GL.GL_RENDERER)); System.err.println("GL_VERSION: " + gl.glGetString(GL.GL_VERSION)); System.err.println(); System.err.println("glLoadTransposeMatrixfARB() supported: " + gl.isFunctionAvailable("glLoadTransposeMatrixfARB")); if (!gl.isFunctionAvailable("glLoadTransposeMatrixfARB")) { // --- not using extensions gl.glLoadIdentity(); } else { // --- using extensions final float[] identityTranspose = new float[] { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; gl.glLoadTransposeMatrixfARB(identityTranspose); } gl.glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 600.0f); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); gl.glTranslatef(0.0f, 0.0f, -200.0f); } public float xt=0,yt=0,zt=0; public void display(GLDrawable drawable) { // angle += 2.0f; GL gl = drawable.getGL(); GLUT glut = new GLUT(); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glPushMatrix(); processKeys(gl); // change the projection transformation based on what keys are pushed gl.glTranslatef(xt,yt,zt); gl.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f); gl.glRotatef(view_roty, 0.0f, 1.0f, 0.0f); gl.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f); gl.glPushMatrix(); gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, red); gl.glScalef(36f,0.1f,0.1f); glut.glutSolidCube(gl,1f); gl.glPopMatrix(); gl.glPushMatrix(); gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, green); gl.glScalef(0.1f,36f,0.1f); glut.glutSolidCube(gl,1f); gl.glPopMatrix(); gl.glPushMatrix(); gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, blue); gl.glScalef(0.1f,0.1f,36f); glut.glutSolidCube(gl,1f); gl.glPopMatrix(); gl.glPushMatrix(); gl.glScalef(36f,36f,36f); float[] clearblue={0f,0f,1f,0.3f}; gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, clearblue); glut.glutWireCube(gl,1f); gl.glPopMatrix(); gl.glTranslatef(-18f,-18f, -18f); for (int i=0;i<6;i++) for (int j=0;j<6;j++) if ((show_i==i) && (show_j==j)) for (int k=0;k<10;k++) { if (showData[k]) { // System.out.println("showing "+i+", "+j+", "+k); gl.glPushMatrix(); gl.glCallList(neuronData[i][j][k]); gl.glPopMatrix(); } } gl.glPopMatrix(); } public void displayChanged(GLDrawable drawable, boolean modeChanged, boolean deviceChanged) {} private void showError(int f, double n, String s) { System.out.println("f="+f+", n="+n+", s= '"+s+"'"); } private void neuron(GL gl,int i, int j, int k) { BufferedReader in = null; int ij = 6*i+j; try{ gl.glShadeModel(GL.GL_SMOOTH); in = new BufferedReader(new FileReader("db-burster.scm")); StreamTokenizer st = new StreamTokenizer(in); GLUT glut = new GLUT(); st.parseNumbers(); int f = st.nextToken(); if (f != StreamTokenizer.TT_NUMBER) showError(f,st.nval,st.sval); int count=0; int x,y,z,w,d,modelID,numMax; double period; while (f != StreamTokenizer.TT_EOF) { modelID=((int) st.nval) - 1; f = st.nextToken(); if (f != StreamTokenizer.TT_NUMBER) showError(f,st.nval,st.sval); numMax = (int) st.nval; f = st.nextToken(); if (f != StreamTokenizer.TT_NUMBER) showError(f,st.nval,st.sval); period = st.nval; f = st.nextToken(); if (f != StreamTokenizer.TT_NUMBER) showError(f,st.nval,st.sval); w = modelID/(216*216); d = modelID%(216*216); y = d/(6*216); d = d%(36*36); z=d/36; x=d%36; if ((w==ij) && ((numMax == k) || ((k==9) && (numMax >=9))) ) { count++; gl.glPushMatrix(); gl.glTranslatef((float)x,(float)y,(float)z); glut.glutSolidCube(gl,1f); gl.glPopMatrix(); if (count%1000==0) System.out.println("["+count+","+ modelID+","+x+","+y+","+z+","+numMax+"]"); } //; if (count > 200) break; } } catch(Exception e) {System.out.println("Caught an exception while reading ..."+e);} finally{ try{ in.close();} catch(Exception ee){System.out.println("Error when closing: "+ee);}} } // Methods required for the implementation of MouseListener public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void mousePressed(MouseEvent e) { prevMouseX = e.getX(); prevMouseY = e.getY(); if ((e.getModifiers() & e.BUTTON3_MASK) != 0) { mouseRButtonDown = true; } } public void mouseReleased(MouseEvent e) { if ((e.getModifiers() & e.BUTTON3_MASK) != 0) { mouseRButtonDown = false; } } public void mouseClicked(MouseEvent e) {} // Methods required for the implementation of MouseMotionListener public void mouseDragged(MouseEvent e) { int x = e.getX(); int y = e.getY(); Dimension size = e.getComponent().getSize(); float thetaY = 360.0f * ( (float)(x-prevMouseX)/(float)size.width); float thetaX = 360.0f * ( (float)(prevMouseY-y)/(float)size.height); prevMouseX = x; prevMouseY = y; view_rotx += thetaX; view_roty += thetaY; } public void mouseMoved(MouseEvent e) {} public void keyPressed(KeyEvent e) { } public void processKeys(GL gl) { if (moveZ) {gl.glLoadIdentity(); gl.glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 600.0f);moveZ=false;} } boolean moveB, moveF, moveL, moveR, moveU, moveD,moveQ,moveA,moveZ; public void keyTyped(KeyEvent e) { } int dt = 1; public void keyReleased(KeyEvent e) { // System.out.println(e); switch (e.getKeyCode()) { case KeyEvent.VK_B: zt -= dt; break; case KeyEvent.VK_F: zt += dt; break; case KeyEvent.VK_L: xt -= dt; break; case KeyEvent.VK_R: xt += dt; break; case KeyEvent.VK_U: yt += dt; break; case KeyEvent.VK_D: yt -= dt; break; case KeyEvent.VK_Q: dt *= 2; break; case KeyEvent.VK_A: dt /= 2; if (dt == 0) dt = 1; break; case KeyEvent.VK_Z: view_rotx=0; view_roty=0; view_rotz=0; break; case KeyEvent.VK_T: break; case KeyEvent.VK_0: break; case KeyEvent.VK_1: break; case KeyEvent.VK_2: break; case KeyEvent.VK_3: break; case KeyEvent.VK_4: break; case KeyEvent.VK_5: break; case KeyEvent.VK_6: break; default: } System.out.println("dt,xt,yt,zt = "+dt+","+ xt+","+yt+","+ zt); } }