Created
April 11, 2012 19:30
-
-
Save roxlu/2361733 to your computer and use it in GitHub Desktop.
GeometricTools Incremental Delaunay
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "testApp.h" | |
| //-------------------------------------------------------------- | |
| void testApp::setup(){ | |
| ofSetFrameRate(60); | |
| ofSetVerticalSync(true); | |
| ofBackground(22,33,44); | |
| nay = new roxlu::IncrementalDelaunay2D(0,0,ofGetWidth(), ofGetHeight()); | |
| for(int i = 0; i < 400; ++i) { | |
| nay->insert(ofRandom(0,ofGetWidth()), ofRandom(0, ofGetHeight())); | |
| } | |
| int s = ofGetElapsedTimeMillis(); | |
| nay->create(); | |
| int e = ofGetElapsedTimeMillis(); | |
| int d = e-s; | |
| ofSetCircleResolution(25); | |
| } | |
| //-------------------------------------------------------------- | |
| void testApp::update(){ | |
| ofSetWindowTitle(ofToString(ofGetFrameRate())); | |
| } | |
| //-------------------------------------------------------------- | |
| void testApp::draw(){ | |
| // Create a new delaunay each draw (no fps drop) | |
| // ---------------------------------------------------------------- | |
| roxlu::IncrementalDelaunay2D nn(0,0,ofGetWidth(), ofGetHeight()); | |
| for(int i = 0; i < 400; ++i) { | |
| nn.insert(ofRandom(0,ofGetWidth()), ofRandom(0, ofGetHeight())); | |
| } | |
| nn.insert(ofRandom(0,ofGetWidth()), ofRandom(0, ofGetHeight())); | |
| nn.create(); | |
| const vector<Wm5::Vector2f>& verts = nn.getVertices(); | |
| vector<Wm5::Vector2f>::const_iterator it = verts.begin(); | |
| glColor3f(1,1,1); | |
| glLineWidth(10); | |
| glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); | |
| glBegin(GL_TRIANGLES); | |
| int num_tris = nn.getNumTriangles(); | |
| const int* indices = nn.getIndices(); | |
| for(int i = 0; i < num_tris; ++i) { | |
| int dx = i * 3; | |
| glVertex2fv(&verts[indices[dx+0]][0]); | |
| glVertex2fv(&verts[indices[dx+1]][0]); | |
| glVertex2fv(&verts[indices[dx+2]][0]); | |
| } | |
| glEnd(); | |
| glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); | |
| glPointSize(8.0); | |
| glColor3f(0.8,0.3,0.0); | |
| while(it != verts.end()) { | |
| ofCircle((*it)[0], (*it)[1], 10); | |
| ++it; | |
| } | |
| return; | |
| // Use the same delaunay | |
| // ------------------------ | |
| // const vector<Wm5::Vector2f>& verts = nay->getVertices(); | |
| // vector<Wm5::Vector2f>::const_iterator it = verts.begin(); | |
| // | |
| // | |
| // glColor3f(1,1,1); | |
| // glLineWidth(10); | |
| // glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); | |
| // glBegin(GL_TRIANGLES); | |
| // int num_tris = nay->getNumTriangles(); | |
| // const int* indices = nay->getIndices(); | |
| // for(int i = 0; i < num_tris; ++i) { | |
| // int dx = i * 3; | |
| // glVertex2fv(&verts[indices[dx+0]][0]); | |
| // glVertex2fv(&verts[indices[dx+1]][0]); | |
| // glVertex2fv(&verts[indices[dx+2]][0]); | |
| // } | |
| // glEnd(); | |
| // | |
| // glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); | |
| // glPointSize(8.0); | |
| // glColor3f(0.8,0.3,0.0); | |
| // while(it != verts.end()) { | |
| // ofCircle((*it)[0], (*it)[1], 10); | |
| // ++it; | |
| // } | |
| } | |
| //-------------------------------------------------------------- | |
| void testApp::keyPressed(int key){ | |
| } | |
| //-------------------------------------------------------------- | |
| void testApp::keyReleased(int key){ | |
| } | |
| //-------------------------------------------------------------- | |
| void testApp::mouseMoved(int x, int y ){ | |
| } | |
| //-------------------------------------------------------------- | |
| void testApp::mouseDragged(int x, int y, int button){ | |
| } | |
| //-------------------------------------------------------------- | |
| void testApp::mousePressed(int x, int y, int button){ | |
| } | |
| //-------------------------------------------------------------- | |
| void testApp::mouseReleased(int x, int y, int button){ | |
| } | |
| //-------------------------------------------------------------- | |
| void testApp::windowResized(int w, int h){ | |
| } | |
| //-------------------------------------------------------------- | |
| void testApp::gotMessage(ofMessage msg){ | |
| } | |
| //-------------------------------------------------------------- | |
| void testApp::dragEvent(ofDragInfo dragInfo){ | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment