// Triangle mesh viewer + corner table + subdivision + smoothing // Written by Jarek Rossignac June 2006 //import processing.opengl.*; // uncomment for OpenGL // VERTICES int w=4; // size of initial Tmesh-grid made in setup int nv = w*w, maxnv = 4000;; // current and max number of vertices int nt = 2*(w-1)*(w-1), maxnt = maxnv*2; // current and max number of triangles pt[] G = new pt [maxnv]; // geometry table (vertices) vec[] Nv = new vec [maxnv]; // vertex normals or laplace vectors vec[] Nt = new vec [maxnt]; // vtriangles normals int [] valence = new int [maxnv]; // vertex valence (count of incident triangles) int[] Mv = new int[maxnv]; // vertex markers pt Cbox = new pt(0,0,0); // mini-max box center float Rbox; // box radius (half-diagonal) // CORNERS int nc = nt*3; // current number of corners (3 per triangle) int[] V = new int [3*maxnt]; // V table (triangle/vertex indices) int[] O = new int [3*maxnt]; // O table (opposite corner indices) int[] W = new int [3*maxnt]; // mid-edge vertex indices for subdivision (associated with corner opposite to edge) int c = 0; // current corner shown in image and manipulated with keys: n, p, o, l, r // TRIANGLES int[] Mt = new int[maxnt]; // triangle markers for distance and other things int[] SMt = new int[maxnt]; // sum of triangle markers for isolation boolean flipOrientation=false; // if set, save will flip all triangles int rings=1; // number of rings for colorcoding // GUI pt Mouse = new pt(0,0,0); // current mouse position float xr, yr = 0; // mouse coordinates relative to center of window int px=0, py=0; // coordinats of mouse when it was last pressed vec labelD=new vec(-10,-10, 2); // offset vector for drawing labels boolean showNormals=false, showVertices=false, showEdges=true, showLabels=false; // flags for rendering color grey = color(200, 200, 210), red = color(200, 10, 10), blue = color(10, 10, 200), lightblue = color(100, 100, 255), green = color(10, 200, 20), black = color(10, 10, 10), magenta = color(250, 150, 200), brown = color(150, 100, 50), yellow = color(255, 238, 70); String [] fn= new String[4]; int fni=0; // ** SETUP ** void setup() { size(800, 800, P3D); //for OpenGL use: void setup() { size(800, 800, OPENGL); PFont font = loadFont("Courier-14.vlw"); textFont(font, 12); // font for writing labels on screen for (int i=0; ig(c).disTo(g(o(c)))) {flip(c);}; }; } // assumes manifold void collapse(int c) { // collapse edge opposite to corner c int b=p(c), oc=o(c), vnc=v(n(c)); for (int a=b; a!=n(oc); a=p(r(a))) {V[a]=vnc;}; V[p(c)]=vnc; V[n(oc)]=vnc; O[l(c)]=r(c); O[r(c)]=l(c); O[l(oc)]=r(oc); O[r(oc)]=l(oc); } //********************************** //*** triangle mesh utilities //********************************** void shade(int i) { beginShape(TRIANGLES); G[V[3*i]].vert(); G[V[3*i+1]].vert(); G[V[3*i+2]].vert(); endShape(); }; // shade tris void showBorder() {for (int i=0; iMt[t(c)]) {c=3*i;};}; rings=255; for(int i=0; i