Changeset 379 for trunk


Ignore:
Timestamp:
Mar 27, 2006 8:47:17 PM (18 years ago)
Author:
qiaow
Message:

Hooked a simple transfer function editor GUI to the render engine.

Location:
trunk/gui/vizservers/nanovis
Files:
17 added
2 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/vizservers/nanovis/Color.cpp

    r371 r379  
    1313 * ======================================================================
    1414 */
     15
    1516#include <stdio.h>
     17#include <assert.h>
     18
    1619#include "Color.h"
    1720
    18 Color::Color(float _r, float _g, float _b, float _a):
    19         r(_r),
    20         g(_g),
    21         b(_b),
    22         a(_a){}
     21Color::Color(){
     22        R=G=B=0.0;
     23        next=0;
     24}
     25
     26Color::Color(double r, double g, double b){
     27        R=r;
     28        G=g;
     29        B=b;
     30        next=0;
     31}
     32
     33void Color::LimitColors(){ //Limits the color to be in range of 0.0 and 1.0
     34        if (R>1.0) R=1.0;
     35        if (G>1.0) G=1.0;
     36        if (B>1.0) B=1.0;
     37
     38        if (R<0.0) R=0.0;
     39        if (G<0.0) G=0.0;
     40        if (B<0.0) B=0.0;
     41}
     42
     43Color Color::operator*(double k){
     44        return Color(R*k, G*k, B*k);
     45}
     46
     47
     48//This is NOT member operator. It's used so we can write (k*V), not only (V*k) (V-vector k-scalar)
     49Color operator*(double k, Color &other){
     50        return Color(other.R*k, other.G*k, other.B*k);
     51}
     52
     53Color::~Color(){}
     54
     55Color Color::operator +(Color &other){
     56        return Color(this->R+other.R,this->G+other.G,this->B+other.B);
     57}
     58
     59Color Color::operator *(Color &other){
     60        return Color(this->R*other.R,this->G*other.G,this->B*other.B);
     61}
     62
     63void Color::GetRGBA(double opacity, unsigned char *result){
     64        LimitColors();
     65
     66        assert(opacity>=0 && opacity <=1);
     67
     68        result[0] = (unsigned char) (R*255.0);
     69        result[1] = (unsigned char) (G*255.0);
     70        result[2] = (unsigned char) (B*255.0);
     71        result[3] = (unsigned char) (opacity*255.0);
     72}
     73
     74void Color::SetRGBA(unsigned char *color){
     75        R = color[0];
     76        G = color[1];
     77        B = color[2];
     78}
     79
     80void Color::GetRGB(unsigned char *result){
     81        result[0] = (unsigned char) (R*255.0);
     82        result[1] = (unsigned char) (G*255.0);
     83        result[2] = (unsigned char) (B*255.0);
     84}
     85
     86void Color::GetRGB(float *result){
     87        result[0] = (float) (R);
     88        result[1] = (float) (G);
     89        result[2] = (float) (B);
     90}
     91
  • trunk/gui/vizservers/nanovis/Color.h

    r373 r379  
    1313 * ======================================================================
    1414 */
     15
    1516#ifndef _COLOR_H_
    1617#define _COLOR_H_
     
    1920{
    2021public:
     22        double R;               // Red component
     23        double G;               // Green component
     24        double B;               // Blue component
    2125
     26        void GetRGB(unsigned char *result);
     27        void GetRGB(float *result);
     28
     29        void SetRGBA(unsigned char *color);
     30        void GetRGBA(double opacity, unsigned char *result);
     31        Color operator *(Color &other);
     32        Color* next;    //pointer to the next color
     33
     34        Color();
     35        Color(double r, double g, double b);
     36
     37        void LimitColors(); //Limits the color to be in range of 0.0 and 1.0
     38        Color operator*(double k);
     39        friend Color operator*(double k, Color &other);
     40        Color operator+(Color &other);
     41        ~Color();
    2242        float r, g, b, a;
    23 
    24         Color(){};
    25         Color(float _r, float _g, float _b, float _a);
    26         ~Color(){};
    2743};
    2844
  • trunk/gui/vizservers/nanovis/Makefile

    r377 r379  
    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 Texture2D.o ParticleSystem.o Sphere.o Color.o \
    3                 PerfQuery.o
     2                Texture1D.o Texture3D.o Volume.o Texture2D.o ParticleSystem.o Sphere.o Color.o \
     3                PerfQuery.o TransferFunction.o ControlPoint.o ColorGradient.o ColorPaletteWindow.o\
     4                ColorGradientGLUTWindow.o TransferFunctionGLUTWindow.o MainWindow.o
    45
    56AUXSRC = config.h define.h global.h
     
    78SOCKETSRC = ./socket
    89SORTSRC = ./sort
     10TFSRC = ./transfer-function
    911
    10 LIB_NANOVIS = -ltcl8.4 -lGL -lglut -lGLEW -lCg -lCgGL -pthread -lstdc++
     12LIB_NANOVIS = -ltcl8.4 -lGL -lglut -lglui -lGLEW -lCg -lCgGL -pthread -lstdc++
    1113LIB_CLIENT = -lGL -lglut -pthread
    1214CFLAG = -g -c -Wall -I../src2/core
     
    2022        gcc -g -o nanovis $(OBJ_NANOVIS) $(LIB_NANOVIS) ../src2/core/*.o
    2123
     24ColorGradient.o: Color.o $(TFSRC)/ColorGradient.cpp
     25        gcc $(CFLAG) $(TFSRC)/ColorGradient.cpp
     26
     27ColorPaletteWindow.o: Color.o ControlPoint.o $(TFSRC)/ColorPaletteWindow.cpp
     28        gcc $(CFLAG) $(TFSRC)/ColorPaletteWindow.cpp
     29
     30ColorGradientGLUTWindow.o: ControlPoint.o ColorGradient.o $(TFSRC)/ColorGradientGLUTWindow.cpp
     31        gcc $(CFLAG) $(TFSRC)/ColorGradientGLUTWindow.cpp
     32
     33TransferFunctionGLUTWindow.o: ColorGradientGLUTWindow.o $(TFSRC)/TransferFunctionGLUTWindow.cpp
     34        gcc $(CFLAG) $(TFSRC)/TransferFunctionGLUTWindow.cpp
     35
     36MainWindow.o: TransferFunctionGLUTWindow.o ColorGradientGLUTWindow.o ColorPaletteWindow.o $(TFSRC)/MainWindow.cpp
     37        gcc $(CFLAG) $(TFSRC)/MainWindow.cpp
     38       
    2239Socket.o: $(SOCKETSRC)/Socket.h $(SOCKETSRC)/Socket.cpp
    2340        gcc $(CFLAG) $(SOCKETSRC)/Socket.cpp
     
    3249        gcc $(CFLAG) Color.cpp
    3350
     51ControlPoint.o: $(TFSRC)/ControlPoint.cpp
     52        gcc $(CFLAG) $(TFSRC)/ControlPoint.cpp
     53
    3454Sphere.o: Vector3.o Color.o
    3555        gcc $(CFLAG) Sphere.cpp
    3656
    37 ColorMap.o: ColorMap.cpp
    38         gcc $(CFLAG) ColorMap.cpp
     57TransferFunction.o: TransferFunction.cpp
     58        gcc $(CFLAG) TransferFunction.cpp
    3959
    4060Texture1D.o: Texture1D.cpp
  • trunk/gui/vizservers/nanovis/ParticleSystem.cpp

    r378 r379  
    3333  reborn = true;
    3434  flip = true;
    35   max_life = 100;
     35  max_life = 500;
    3636
    3737  data = (Particle*) malloc(w*h*sizeof(Particle));
     
    206206
    207207  //glPointSize(0.5);
    208   glPointSize(1.5);
    209   glColor4f(.1,.0,.3,1.);
     208  glPointSize(1.0);
     209  glColor4f(.6,.6,.0,1.);
    210210
    211211  m_vertex_array->SetPointer(0);
  • trunk/gui/vizservers/nanovis/Sphere.cpp

    r373 r379  
    1818
    1919Sphere::Sphere(float x, float y, float z,
    20                 float r, float g, float b, float a,
     20                float r, float g, float b,
    2121                float _radius,
    2222                int _stack,
     
    2626        slice(_slice),
    2727        center(Vector3(x,y,z)),
    28         color(Color(r,g,b,a))
     28        color(Color(r,g,b))
    2929{ }
    3030
    3131
    3232void Sphere::draw(GLUquadric* quad){
    33   glColor4f(color.r, color.g, color.b, color.a);
     33  glColor3f(color.R, color.G, color.B);
    3434
    3535  glMatrixMode(GL_MODELVIEW);
  • trunk/gui/vizservers/nanovis/Sphere.h

    r373 r379  
    3131        Sphere(){};
    3232        ~Sphere(){};
    33         Sphere(float x, float y, float z, float r, float g, float b, float a, float r, int _stack, int _slice);
     33        Sphere(float x, float y, float z, float r, float g, float b, float _radius, int _stack, int _slice);
    3434        void set_vertical_res(int _stack);
    3535        void set_horizontal_res(int _slice);
  • trunk/gui/vizservers/nanovis/nanovis.cpp

    r378 r379  
    1313 * ======================================================================
    1414 */
     15
    1516#include <stdio.h>
    1617#include <math.h>
     
    2324#include "RpFieldPrism3D.h"
    2425
     26#include "transfer-function/TransferFunctionMain.h"
     27#include "transfer-function/ControlPoint.h"
     28#include "transfer-function/TransferFunctionGLUTWindow.h"
     29#include "transfer-function/ColorGradientGLUTWindow.h"
     30#include "transfer-function/ColorPaletteWindow.h"
     31#include "transfer-function/MainWindow.h"
     32
     33float color_table[256][4];
     34
    2535// forward declarations
    2636void init_particles();
     
    4151int n_volumes = 0;
    4252Volume* volume[MAX_N_VOLUMES];          //point to volumes, currently handle up to 10 volumes
    43 ColorMap* colormap[MAX_N_VOLUMES];      //transfer functions, currently handle up to 10 colormaps
     53TransferFunction* tf[MAX_N_VOLUMES];    //transfer functions, currently handle up to 10 colormaps
    4454
    4555PerfQuery* perf;                        //perfromance counter
     
    507517
    508518//load a colormap 1D texture
    509 void load_colormap(int index, int size, float* data){
    510 
    511   if(colormap[index]!=0){
    512     delete colormap[index];
    513     colormap[index]=0;
     519void load_transfer_function(int index, int size, float* data){
     520
     521  if(tf[index]!=0){
     522    delete tf[index];
     523    tf[index]=0;
    514524  }
    515525
    516   colormap[index] = new ColorMap(size, data);
     526  tf[index] = new TransferFunction(size, data);
    517527}
    518528
     
    702712      int index = i + psys->psys_height*j;
    703713      bool particle = rand() % 256 > 100;
    704       particle = true;
     714      //particle = true;
    705715      if(particle)
    706716      {
    707717        //assign any location (x,y,z) in range [0,1]
    708         data[4*index] = 0.5;
     718        data[4*index] = lic_slice_x;
    709719        data[4*index+1]= j/float(psys->psys_height);
    710         data[4*index+2]= lic_slice_z; //lic_slice_z; //i/float(psys->psys_width);
     720        data[4*index+2]= i/float(psys->psys_width);
    711721        data[4*index+3]= 30; //shorter life span, quicker iterations   
    712722      }
     
    766776   for(int i=0; i<MAX_N_VOLUMES; i++){
    767777     volume[i] = 0;
    768      colormap[i] = 0;
     778     tf[i] = 0;
    769779   }
    770780
     
    775785   }
    776786
    777    init_vector_field(); //3d vector field
     787   //init_vector_field();       //3d vector field
    778788   //load_volume_file(0, "./data/A-apbs-2-out-potential-PE0.dx");
    779789   //load_volume_file(0, "./data/nw-AB-Vg=0.000-Vd=1.000-potential.dx");
     
    17121722          volume[0]->aspect_ratio_depth);
    17131723
     1724   /*
    17141725   
    17151726   //draw line integral convolution quad
     
    17201731   glTexCoord2f(0, 1); glVertex3f(0, 1, lic_slice_z);
    17211732   glEnd();
    1722    
     1733   */
     1734
     1735
    17231736   glPopMatrix();
    17241737   
     
    17321745          volume[0]->aspect_ratio_depth);
    17331746
    1734    psys->display_vertices();
     1747   perf->enable();
     1748     psys->display_vertices();
     1749   perf->disable();
     1750   fprintf(stderr, "particle pixels: %d\n", perf->get_pixel_count());
     1751   perf->reset();
    17351752
    17361753   glPopMatrix();
    17371754
    1738    //render volume :0
    1739    //volume[0]->location =Vector3(0.,0.,0.);
    1740    //render_volume(0, 256);
    1741 
    1742    //render volume :1
    1743    volume[1]->location =Vector3(0., 0., 0.);
    1744    render_volume(1, 256);
    1745 
    17461755   perf->enable();
     1756     //render volume :0
     1757     //volume[0]->location =Vector3(0.,0.,0.);
     1758     //render_volume(0, 256);
     1759
     1760     //render volume :1
     1761     volume[1]->location =Vector3(0., 0., 0.);
     1762     render_volume(1, 256);
    17471763   perf->disable();
    1748    fprintf(stderr, "pixels: %d\n", perf->get_pixel_count());
     1764   fprintf(stderr, "volume pixels: %d\n", perf->get_pixel_count());
    17491765   perf->reset();
    17501766
    17511767   draw_axis();
    1752 
    1753    glDisable(GL_DEPTH_TEST);
    17541768#endif
    17551769
     
    18291843                lic_slice_z-=0.05;
    18301844                get_slice_vectors();
     1845                break;
     1846        case ',':
     1847                lic_slice_x+=0.05;
     1848                init_particles();
     1849                break;
     1850        case '.':
     1851                lic_slice_x-=0.05;
     1852                init_particles();
    18311853                break;
    18321854        case '1':
     
    18991921
    19001922
    1901 
    19021923/*----------------------------------------------------*/
    19031924int main(int argc, char** argv)
    19041925{
     1926
    19051927   glutInit(&argc, argv);
    19061928   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
     1929
     1930   MainTransferFunctionWindow * mainWin;
     1931   mainWin = new MainTransferFunctionWindow();
     1932   mainWin->mainInit();
     1933   
    19071934   glutInitWindowSize(NPIX, NPIX);
     1935   glutInitWindowPosition(10, 10);
    19081936   glutCreateWindow(argv[0]);
     1937
    19091938   glutDisplayFunc(display);
    19101939   glutMouseFunc(mouse);
     
    19121941   glutKeyboardFunc(keyboard);
    19131942   glutIdleFunc(idle);
     1943
    19141944   initGL();
    19151945   initTcl();
  • trunk/gui/vizservers/nanovis/nanovis.h

    r378 r379  
    1313 * ======================================================================
    1414 */
    15 
    1615
    1716#include <GL/glew.h>
     
    3534#include "Texture2D.h"
    3635#include "Texture1D.h"
    37 #include "ColorMap.h"
     36#include "TransferFunction.h"
    3837#include "ConvexPolygon.h"
    3938#include "Mat4x4.h"
     
    112111//currently active shader, default renders one volume only
    113112int cur_shader = 0;
     113
Note: See TracChangeset for help on using the changeset viewer.