Changeset 273 for trunk


Ignore:
Timestamp:
Mar 3, 2006, 12:28:54 PM (19 years ago)
Author:
qiaow
Message:

Added ParticleSystem? class.

Location:
trunk/gui/vizservers/nanovis
Files:
5 added
1 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/vizservers/nanovis/Makefile

    r259 r273  
    11OBJ_NANOVIS = nanovis.o Socket.o RenderVertexArray.o Plane.o ConvexPolygon.o Vector4.o Vector3.o Mat4x4.o \
    2                 Texture1D.o Texture3D.o ColorMap.o Volume.o
     2                Texture1D.o Texture3D.o ColorMap.o Volume.o Texture2D.o ParticleSystem.o
     3
     4AUXSRC = config.h define.h global.h
    35
    46SOCKETSRC = ./socket
     
    3234        gcc $(CFLAG) Texture1D.cpp
    3335
    34 Texture3D.o: Texture3D.cpp config.h
     36Texture2D.o: Texture2D.cpp $(AUXSRC)
     37        gcc $(CFLAG) Texture2D.cpp
     38
     39Texture3D.o: Texture3D.cpp $(AUXSRC)
    3540        gcc $(CFLAG) Texture3D.cpp
    3641
    37 Volume.o: Texture3D.o Volume.cpp define.h
     42ParticleSystem.o: ParticleSystem.cpp $(AUXSRC)
     43        gcc $(CFLAG) ParticleSystem.cpp
     44
     45Volume.o: Texture3D.o Volume.cpp $(AUXSRC)
    3846        gcc $(CFLAG) Volume.cpp
    3947
     
    5361        gcc $(CFLAG) ConvexPolygon.cpp
    5462
    55 nanovis.o: nanovis.h nanovis.cpp config.h define.h
     63nanovis.o: nanovis.h nanovis.cpp ParticleSystem.o $(AUXSRC)
    5664        gcc $(CFLAG) nanovis.cpp
    57 
  • trunk/gui/vizservers/nanovis/Texture1D.h

    r226 r273  
    11/*
    22 * ----------------------------------------------------------------------
    3  * texture1d.h: 1d texture class
     3 * Texture1D.h: 1d texture class
    44 *
    55 * ======================================================================
  • trunk/gui/vizservers/nanovis/Texture3D.cpp

    r259 r273  
    1414 */
    1515
    16 #ifdef WIN32
    17         #include <windows.h>
    18 #endif
    19 
    2016#include "Texture3D.h"
    2117#include <stdio.h>
     
    2521#include "config.h"
    2622
    27 Texture3D::Texture3D(){ id=-1; gl_resource_allocated = false; }
     23Texture3D::Texture3D(){ id=0; gl_resource_allocated = false; }
    2824
    29 Texture3D::Texture3D(int width, int height, int depth, int type, int interp, int components)
     25Texture3D::Texture3D(int width, int height, int depth, GLuint type=GL_FLOAT, GLuint interp=GL_LINEAR, int components=4)
    3026{
    3127        assert(type == GL_UNSIGNED_BYTE || type == GL_FLOAT|| type ==GL_UNSIGNED_INT);
     28        assert(interp == GL_LINEAR || interp == GL_NEAREST);
    3229       
    3330        this->width = width;
     
    4744        this->n_components = components;
    4845
    49         id = -1;
     46        this->id = 0;
    5047        gl_resource_allocated = false;
    5148}
     
    7572        }
    7673
     74        //to do: add handling to more formats
    7775        if(type==GL_FLOAT){
    7876          switch(n_components){
  • trunk/gui/vizservers/nanovis/Texture3D.h

    r259 r273  
    3434        GLuint interp_type;
    3535        int n_components;
    36         void* data;
    3736        bool gl_resource_allocated;
    3837
     
    4140
    4241        Texture3D();
    43         Texture3D(int width, int height, int depth, int type, int interp, int n_component);
     42        Texture3D(int width, int height, int depth, GLuint type, GLuint interp, int n);
    4443        ~Texture3D();
    4544       
  • trunk/gui/vizservers/nanovis/define.h

    r259 r273  
    2323
    2424#include <GL/glew.h>
     25#include <Cg/cgGL.h>
    2526
    2627#define NVIS_FLOAT GL_FLOAT
     
    3637
    3738
     39#define CHECK_FRAMEBUFFER_STATUS()                            \
     40  {                                                           \
     41    GLenum status;                                            \
     42    status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); \
     43    switch(status) {                                          \
     44      case GL_FRAMEBUFFER_COMPLETE_EXT:                       \
     45        break;                                                \
     46      case GL_FRAMEBUFFER_UNSUPPORTED_EXT:                    \
     47        /* choose different formats */                        \
     48        break;                                                \
     49      default:                                                \
     50        /* programming error; will fail on all hardware */    \
     51        fprintf(stderr, "programming error\n");               \
     52        assert(0);                                            \
     53     }                                                        \
     54   }
     55
    3856
    3957#endif
  • trunk/gui/vizservers/nanovis/nanovis.cpp

    r260 r273  
    1616#include "nanovis.h"
    1717
    18 #include "socket/Socket.h"
    19 #include "RenderVertexArray.h"
    20 #include "ConvexPolygon.h"
    21 #include "Texture3D.h"
    22 #include "ColorMap.h"
    23 #include "ConvexPolygon.h"
    24 #include "Mat4x4.h"
    25 #include "Volume.h"
    26 
    27 
    28 //variables for mouse events
    29 float live_rot_x = 0.;          //object rotation angles
    30 float live_rot_y = 0.;
    31 float live_rot_z = 0.;
    32 
    33 float live_obj_x = -0.5;        //object translation location from the origin
    34 float live_obj_y = -0.5;
    35 float live_obj_z = -2.5;
    36 
    37 int left_last_x, left_last_y, right_last_x, right_last_y;       //last locations mouse events
    38 bool left_down = false;                                         
    39 bool right_down = false;
    40 
    41 float slice_x=0, slice_y=0, slice_z=0.3;        //image based flow visualization slice location
    42 
    43 int win_width = NPIX;                   //size of the render window
    44 int win_height = NPIX;                  //size of the render window
     18ParticleSystem* psys;
     19
    4520
    4621//particle system related variables
     22NVISid psys_fbo[2];
     23NVISid psys_tex[2];
     24int psys_width = NMESH;                 //particle system size
     25int psys_height = NMESH;
    4726int psys_frame = 0;                     //count the frame number of particle system iteration
    4827float psys_x =0.4, psys_y=0, psys_z=0;  //particle initialization coordinates
     
    5130bool flip = true;                       //flip the source and destination render targets
    5231
    53 int psys_width = NMESH;                 //particle system size
    54 int psys_height = NMESH;
    55 NVISid psys_fbo[2];
    56 NVISid psys_tex[2];
    57 
    58 
    59 //image based flow visualization variables
    60 int    iframe = 0;
    61 int    Npat   = 64;
    62 int    alpha  = (0.12*255);
    63 float  sa;
    64 float  tmax   = NPIX/(SCALE*NPN);
    65 float  dmax   = SCALE/NPIX;
    66 
    6732
    6833char* screen_buffer = new char[4*NPIX*NPIX+1];          //buffer to store data read from the screen
     
    7035NVISid vel_fbo, slice_vector_tex;       //for projecting 3d vector to 2d vector on a plane
    7136
    72 NVISid vector_tex;                      //3d vector field texture       
    73 Volume* vector_filed;                   //3d vector field
    7437bool advect=false;
    7538float vert[NMESH*NMESH*3];              //particle positions in main memory
     
    8447CGcontext g_context;
    8548CGprogram m_pos_fprog;
     49CGparameter m_vel_tex_param, m_pos_tex_param;
    8650CGparameter m_pos_timestep_param, m_pos_spherePos_param;
    8751
    8852CGprogram m_vel_fprog;
    89 CGparameter m_vel_tex_param, m_pos_tex_param;
    9053CGparameter m_vel_timestep_param, m_vel_damping_param, m_vel_gravity_param;
    9154CGparameter m_vel_spherePos_param, m_vel_sphereVel_param, m_vel_sphereRadius_param;
     
    12992static int HelloCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]));
    13093static int LoadCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]));
    131 
    132 #define CHECK_FRAMEBUFFER_STATUS()                            \
    133   {                                                           \
    134     GLenum status;                                            \
    135     status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); \
    136     switch(status) {                                          \
    137       case GL_FRAMEBUFFER_COMPLETE_EXT:                       \
    138         break;                                                \
    139       case GL_FRAMEBUFFER_UNSUPPORTED_EXT:                    \
    140         /* choose different formats */                        \
    141         break;                                                \
    142       default:                                                \
    143         /* programming error; will fail on all hardware */    \
    144         fprintf(stderr, "programming error\n");               \
    145         assert(0);                                            \
    146      }                                                        \
    147    }
    14894
    14995
     
    294240void init_fbo(){
    295241
    296         //initialize fbo for projecting a 3d vector to 2d plane
    297         glGenFramebuffersEXT(1, &vel_fbo);
    298         glGenTextures(1, &slice_vector_tex);
    299 
    300         glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, vel_fbo);
    301 
    302         //initialize texture storing per slice vectors
    303         glBindTexture(GL_TEXTURE_RECTANGLE_NV, slice_vector_tex);
    304         glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    305         glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    306         glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_FLOAT_RGBA32_NV, NMESH, NMESH, 0, GL_RGBA, GL_FLOAT, NULL);
    307         glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_NV, slice_vector_tex, 0);
    308 
    309         //initialize final fbo for final display
    310         glGenFramebuffersEXT(1, &final_fbo);
    311         glGenTextures(1, &final_color_tex);
    312         glGenRenderbuffersEXT(1, &final_depth_rb);
    313 
    314         glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, final_fbo);
    315 
    316         //initialize final color texture
    317         glBindTexture(GL_TEXTURE_2D, final_color_tex);
    318         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    319         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    320         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, win_width, win_height, 0,
    321                      GL_RGB, GL_INT, NULL);
    322         glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
    323                                   GL_COLOR_ATTACHMENT0_EXT,
    324                                   GL_TEXTURE_2D, final_color_tex, 0);
     242  //initialize fbo for projecting a 3d vector to 2d plane
     243  glGenFramebuffersEXT(1, &vel_fbo);
     244  glGenTextures(1, &slice_vector_tex);
     245
     246  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, vel_fbo);
     247
     248  //initialize texture storing per slice vectors
     249  glBindTexture(GL_TEXTURE_RECTANGLE_NV, slice_vector_tex);
     250  glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
     251  glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     252  glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_FLOAT_RGBA32_NV, NMESH, NMESH, 0, GL_RGBA, GL_FLOAT, NULL);
     253  glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_NV, slice_vector_tex, 0);
     254
     255  //initialize final fbo for final display
     256  glGenFramebuffersEXT(1, &final_fbo);
     257  glGenTextures(1, &final_color_tex);
     258  glGenRenderbuffersEXT(1, &final_depth_rb);
     259
     260  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, final_fbo);
     261
     262  //initialize final color texture
     263  glBindTexture(GL_TEXTURE_2D, final_color_tex);
     264  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     265  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     266  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, win_width, win_height, 0,
     267               GL_RGB, GL_INT, NULL);
     268  glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
     269                            GL_COLOR_ATTACHMENT0_EXT,
     270                            GL_TEXTURE_2D, final_color_tex, 0);
    325271
    326272       
    327         // initialize final depth renderbuffer
    328         glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, final_depth_rb);
    329         glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,
    330                                  GL_DEPTH_COMPONENT24, win_width, win_height);
    331         glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
    332                                      GL_DEPTH_ATTACHMENT_EXT,
    333                                      GL_RENDERBUFFER_EXT, final_depth_rb);
    334 
    335 
    336         //initialize fbo for lic
    337         glGenFramebuffersEXT(1, &fbo);
    338         glGenTextures(1, &color_tex);
    339 
    340         glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
    341 
    342         //initialize color texture for lic
    343         glBindTexture(GL_TEXTURE_2D, color_tex);
    344         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    345         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    346         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, win_width, win_height, 0,
    347                      GL_RGB, GL_INT, NULL);
    348         glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
    349                                   GL_COLOR_ATTACHMENT0_EXT,
    350                                   GL_TEXTURE_2D, color_tex, 0);
    351 
    352         // Check framebuffer completeness at the end of initialization.
    353         CHECK_FRAMEBUFFER_STATUS();
    354         assert(glGetError()==0);
     273  // initialize final depth renderbuffer
     274  glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, final_depth_rb);
     275  glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,
     276                           GL_DEPTH_COMPONENT24, win_width, win_height);
     277  glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
     278                               GL_DEPTH_ATTACHMENT_EXT,
     279                               GL_RENDERBUFFER_EXT, final_depth_rb);
     280
     281  //initialize fbo for lic
     282  glGenFramebuffersEXT(1, &fbo);
     283  glGenTextures(1, &color_tex);
     284
     285  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
     286
     287  //initialize color texture for lic
     288  glBindTexture(GL_TEXTURE_2D, color_tex);
     289  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     290  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     291  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, win_width, win_height, 0,
     292               GL_RGB, GL_INT, NULL);
     293  glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
     294                            GL_COLOR_ATTACHMENT0_EXT,
     295                            GL_TEXTURE_2D, color_tex, 0);
     296
     297  // Check framebuffer completeness at the end of initialization.
     298  CHECK_FRAMEBUFFER_STATUS();
     299  assert(glGetError()==0);
    355300}
    356301
     
    398343}
    399344
    400 CGprogram loadProgram(CGcontext context, CGprofile profile, CGenum program_type, char *filename)
    401 {
    402     CGprogram program = cgCreateProgramFromFile(context, program_type, filename,
    403         profile, NULL, NULL);
    404     cgGLLoadProgram(program);
    405     return program;
    406 }
    407345
    408346void init_cg(){
     
    484422   }
    485423
     424  psys->initialize((Particle*)data);
     425
    486426  glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[0]);
    487427  glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_FLOAT_RGBA32_NV, psys_width, psys_height, 0, GL_RGBA, GL_FLOAT, data);
     
    543483   init_fbo();  //frame buffer objects
    544484   init_psys(); //particle system
    545    init_particles();    //fill initial particles
    546485   init_cg();           //init cg shaders
    547486   init_vbo();          //init vertex buffer object
    548487
     488   psys = new ParticleSystem(NMESH, NMESH, g_context, volume[0]->id);
     489
     490   init_particles();    //fill initial particles
    549491   get_slice_vectors();
    550492}
     
    731673
    732674
    733 void draw_quad(int w, int h, int tw, int th)
    734 {
    735     glBegin(GL_QUADS);
    736     glTexCoord2f(0,         0);         glVertex2f(0,        0);
    737     glTexCoord2f((float)tw, 0);         glVertex2f((float)w, 0);
    738     glTexCoord2f((float)tw, (float)th); glVertex2f((float)w, (float) h);
    739     glTexCoord2f(0,         (float)th); glVertex2f(0,        (float) h);
    740     glEnd();
    741 }
    742 
    743 
    744675//line integral convolution
    745676void lic(){
     
    849780
    850781
    851 typedef struct Particle{
    852   float x;
    853   float y;
    854   float z;
    855   float dis;
    856 
    857   Particle(float _x, float _y, float _z, float _dis):
    858           x(_x), y(_y), z(_z), dis(_dis){};
    859 };
    860 
    861782
    862783int particle_distance_sort(const void* a, const void* b){
    863   if((*((Particle*)a)).dis > (*((Particle*)b)).dis)
     784  if((*((Particle*)a)).aux > (*((Particle*)b)).aux)
    864785    return -1;
    865786  else
     
    883804    p[i].y = y;
    884805    p[i].z = z;
    885     p[i].dis = dis;
     806    p[i].aux = dis;
    886807  }
    887808
  • trunk/gui/vizservers/nanovis/nanovis.h

    r259 r273  
    2727#include <float.h>
    2828
     29#include "define.h"
     30#include "global.h"
     31#include "socket/Socket.h"
     32#include "RenderVertexArray.h"
     33#include "ConvexPolygon.h"
     34#include "Texture3D.h"
     35#include "Texture2D.h"
     36#include "Texture1D.h"
     37#include "ColorMap.h"
     38#include "ConvexPolygon.h"
     39#include "Mat4x4.h"
     40#include "Volume.h"
     41#include "ParticleSystem.h"
     42
    2943#include "config.h"
    3044
     
    3751#define SCALE 3.0       //scale for background pattern. small value -> fine texture
    3852#define MAX_N_VOLUMES 10 //maximum of volumes the application can handle
    39 
    4053
    4154
     
    6679  }
    6780};
     81
     82
     83//variables for mouse events
     84float live_rot_x = 0.;          //object rotation angles
     85float live_rot_y = 0.;
     86float live_rot_z = 0.;
     87
     88float live_obj_x = -0.5;        //object translation location from the origin
     89float live_obj_y = -0.5;
     90float live_obj_z = -2.5;
     91
     92int left_last_x, left_last_y, right_last_x, right_last_y;       //last locations mouse events
     93bool left_down = false;                                         
     94bool right_down = false;
     95
     96float slice_x=0, slice_y=0, slice_z=0.3;        //image based flow visualization slice location
     97
     98int win_width = NPIX;                   //size of the render window
     99int win_height = NPIX;                  //size of the render window
     100
     101
     102//image based flow visualization variables
     103int    iframe = 0;
     104int    Npat   = 64;
     105int    alpha  = (0.12*255);
     106float  sa;
     107float  tmax   = NPIX/(SCALE*NPN);
     108float  dmax   = SCALE/NPIX;
Note: See TracChangeset for help on using the changeset viewer.