Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /branches/lamont/test/implicit-surface/main.c
ViewVC logotype

View of /branches/lamont/test/implicit-surface/main.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2231 - (download) (as text) (annotate)
Fri Mar 1 22:56:47 2013 UTC (7 years, 4 months ago) by glk
File size: 2899 byte(s)
GLK does not like trailing whitespace
#include <math.h>
#include <stdlib.h>
#include <stdio.h>


#define PI 3.1415926535897932384626433832795

#define WIDTH   800
#define HEIGHT  600
#define N 100
#define STEP_SIZE 1

CIRCLE_World_t * wrld;

bool isInitial = true;

// nrrd for getting computational state
Nrrd *nData;


void resizeWindow(int width, int height)
{
    glViewport(0, 0, WIDTH, HEIGHT);
}
void setUpView(void)
{
    glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-WIDTH/2.0,      // left
            WIDTH/2.0,  // right
            -HEIGHT/2.0, // bottom
            HEIGHT/2.0,      // top
            0,      // zNear
            1       // zFar
            );
}
void GetData (CIRCLE_World_t *wrld, Nrrd *nData)
{
  // get snapshot of state
    if (CIRCLE_Snapshot_outPos(wrld, nData)) {
      // error
        fprintf(stderr, "Error getting nrrd data\n");
        exit(1);
    }
}
void DrawPoints(Nrrd *positions)
{
    glMatrixMode(GL_MODELVIEW);

    glColor3f(0.0f, 0.0f, 1.0f);
    glLoadIdentity();
    glEnable (GL_POINT_SMOOTH);
#ifdef __APPLE__

#else
  glEnable (GL_PROGRAM_POINT_SIZE);
#endif

    glPointSize(3);
    glPushMatrix();
    glBegin (GL_POINTS);
    glColor3f (0.0, 0.0, 1.0);
    float * p = (float *)(positions->data);
    unsigned int nPoints = positions->axis[1].size;

    for (int i = 0;  i < nPoints;  i++) {
        float x = p[0];
        float y = p[1];
        p[0] *= ((WIDTH-25)/2.0);
        p[1] *= ((HEIGHT-25)/2.0);
        glVertex2fv(p);
        p[0] = x;
        p[1] = y;
        p += 2;
    }
    glEnd ();
    glPopMatrix();
}
void update (int value)
{
    glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);     // Clear The Screen And The Depth Buffer
    setUpView();

    // get and render initial state
    if(isInitial){
       // printf("Getting initial data\n");
        GetData (wrld, nData);
       // printf("Done getting initial data\n");
        DrawPoints(nData);
        isInitial = false;
        glutSwapBuffers();
    }else {
        if(CIRCLE_NumActive(wrld) > 0){
            // step the computation
            CIRCLE_Run(wrld, STEP_SIZE);
            // get and render the state
            GetData (wrld, nData);
            DrawPoints(nData);
            glutSwapBuffers();
        }
    }
    glutTimerFunc(50,update, 0);
}

int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
    glutInitWindowSize(WIDTH, HEIGHT);
    glutCreateWindow("Circle Implicit Diderot Program");
    glutDisplayFunc(&Display);

    // initialize the Diderot program
    CIRCLE_World_t * wrld;
    wrld = CIRCLE_Init();
    nData = nrrdNew();
    CIRCLE_Initially (wrld);


    // step the computation
    CIRCLE_Run(wrld, STEP_SIZE);
    // get and render the state
    GetData (wrld, nData);





    glutMainLoop();

    return 0;
}

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0