Changeset 2897


Ignore:
Timestamp:
Mar 29, 2012 10:55:56 PM (12 years ago)
Author:
ldelgass
Message:

janitorial

Location:
trunk/packages/vizservers/nanovis/transfer-function
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/nanovis/transfer-function/ColorGradient.cpp

    r2798 r2897  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 /*
    3  * ----------------------------------------------------------------------
    4  * ColorGradient.cpp: ColorGradient class
    5  *
    6  * ======================================================================
     2/* ======================================================================
    73 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
    84 *           Purdue Rendering and Perceptualization Lab (PURPL)
     
    1410 * ======================================================================
    1511 */
    16 
    1712#include <stdio.h>
    1813#include <assert.h>
     
    2419#include "TransferFunctionGLUTWindow.h"
    2520
    26 //////////////////////////////////////////////////////////////////////
    27 // Construction/Destruction
    28 //////////////////////////////////////////////////////////////////////
    29 
    30 
    31 ColorGradient::ColorGradient(){
    32 
    33         numOfKeys = 2;
    34         //keyColors = new Color[numOfKeys];
    35 
    36 
    37         //color list with two initial colors   
    38         keyColors = new Color(1,1,1);
    39         keyColors->next = new Color(1,1,1);
    40 
    41         //keyList with two initial points at 0 and 1
    42         keyList = new ControlPoint(15, main_winy/3);
    43         keyList->next= new ControlPoint(15+tf_winx*0.95, main_winy/3);
    44 }
    45 
    46 
    47 
    48 ColorGradient::~ColorGradient(){
    49 
    50 }
    51 
    52 
    53 
    54 
    55 ControlPoint* ColorGradient::addKey(double x, Color* color){
    56         if (color==0)
    57                 return 0;
    58 
    59         Color* curColor=keyColors;
    60         Color* preColor=curColor;
    61         ControlPoint* curKey=keyList;
    62         ControlPoint* preKey=curKey;
    63 
    64         if (x==15+cm_unitWidth){//only update color for the last point
    65                 while(curColor->next!=0){
    66                         preColor=curColor;
    67                         curKey=curKey->next;
    68                         curColor=curColor->next;
    69                 }
    70                 preColor->next=color;
    71                 delete(curColor);
    72                 return curKey;
    73         }
    74         else if(x==15){
    75                 //only update color for the first point
    76                 color->next=keyColors->next;
    77                 delete(keyColors);
    78                 keyColors=color;
    79                 return keyList;
    80         }
    81 
    82 
    83         curColor=keyColors;
    84         preColor=curColor;
    85         curKey=keyList;
    86         preKey=curKey;
    87 
    88         ControlPoint* newPoint=0;
    89         while (curKey!=0){
    90                 if (x<=curKey->x){
    91                         newPoint=new ControlPoint(x,100);
    92                         newPoint->next=preKey->next;
    93                         preKey->next=newPoint;
    94                         color->next=preColor->next;
    95                         preColor->next=color;
    96                         numOfKeys++;
    97                        
    98                         //printf("Key added");
    99                         break;
    100                 }
    101                 preKey=curKey;
    102                 curKey=curKey->next;
    103                 preColor=curColor;
    104                 curColor=curColor->next;
    105         }
    106 
    107         glutSetWindow(colorMapWindow);
    108         glutPostRedisplay();
    109         //cm_gvSelectedPoint=newPoint;
    110         //newPoint->selected=true;
    111         return newPoint;
    112 }
    113 
    114 
    115 
    116 
    117 
    118 void ColorGradient::removeKey(double x){
    119 
    120         ControlPoint* cur=keyList;
    121         ControlPoint* pre=cur;
    122         Color* curColor=keyColors;
    123         Color* preColor=curColor;
    124 
    125         //if x is the edge point, only reset the color to white
    126         if (x==15 ){
    127                 keyColors->R=1; keyColors->G=1; keyColors->B=1;
    128                 return;
    129         }
    130         else if (x==15+cm_unitWidth){
    131                 while(curColor->next!=0){
    132                         curColor=curColor->next;       
    133                 }
    134                 curColor->R=1; curColor->G=1; curColor->B=1;
    135         }
    136 
    137 
    138 
    139         curColor=keyColors;
    140         preColor=curColor;
    141         while (cur->next!=0){
    142                 if (cur->x==x){
    143                         pre->next=cur->next;
    144                         delete(cur);
    145                         preColor->next=curColor->next;
    146                         delete(curColor);
    147                         numOfKeys--;
    148                         break;
    149                 }
    150                 pre=cur;
    151                 cur=cur->next; 
    152                 preColor=curColor;
    153                 curColor=curColor->next;
    154         }
    155 
    156         //TransferFunctionGlutWindow::WriteControlPoints();
    157         ColorGradientGLUTWindow::WriteControlPoints();
    158         glutSetWindow(colorMapWindow);
    159         glutPostRedisplay();
    160 }
    161 
    162 
    163 void ColorGradient::changeColor(double r, double g, double b){
    164         if (cm_gvSelectedPoint==0)
    165                 return;
    166 
    167         Color* curColor=map->keyColors;
    168         ControlPoint* curPoint=map->keyList;
    169         while (curPoint!=cm_gvSelectedPoint){
    170                 curPoint=curPoint->next;
    171                 curColor=curColor->next;
    172         }
     21ColorGradient::ColorGradient()
     22{
     23    numOfKeys = 2;
     24    //keyColors = new Color[numOfKeys];
     25
     26
     27    //color list with two initial colors
     28    keyColors = new Color(1,1,1);
     29    keyColors->next = new Color(1,1,1);
     30
     31    //keyList with two initial points at 0 and 1
     32    keyList = new ControlPoint(15, main_winy/3);
     33    keyList->next= new ControlPoint(15+tf_winx*0.95, main_winy/3);
     34}
     35
     36ColorGradient::~ColorGradient()
     37{
     38}
     39
     40ControlPoint* ColorGradient::addKey(double x, Color* color)
     41{
     42    if (color==0)
     43        return 0;
     44
     45    Color* curColor=keyColors;
     46    Color* preColor=curColor;
     47    ControlPoint* curKey=keyList;
     48    ControlPoint* preKey=curKey;
     49
     50    if (x==15+cm_unitWidth) {//only update color for the last point
     51        while(curColor->next!=0){
     52            preColor=curColor;
     53            curKey=curKey->next;
     54            curColor=curColor->next;
     55        }
     56        preColor->next=color;
     57        delete(curColor);
     58        return curKey;
     59    } else if (x==15) {
     60        //only update color for the first point
     61        color->next=keyColors->next;
     62        delete(keyColors);
     63        keyColors=color;
     64        return keyList;
     65    }
     66
     67
     68    curColor=keyColors;
     69    preColor=curColor;
     70    curKey=keyList;
     71    preKey=curKey;
     72
     73    ControlPoint* newPoint=0;
     74    while (curKey!=0) {
     75        if (x<=curKey->x) {
     76            newPoint=new ControlPoint(x,100);
     77            newPoint->next=preKey->next;
     78            preKey->next=newPoint;
     79            color->next=preColor->next;
     80            preColor->next=color;
     81            numOfKeys++;
     82
     83            //printf("Key added");
     84            break;
     85        }
     86        preKey=curKey;
     87        curKey=curKey->next;
     88        preColor=curColor;
     89        curColor=curColor->next;
     90    }
     91
     92    glutSetWindow(colorMapWindow);
     93    glutPostRedisplay();
     94    //cm_gvSelectedPoint=newPoint;
     95    //newPoint->selected=true;
     96    return newPoint;
     97}
     98
     99void ColorGradient::removeKey(double x)
     100{
     101    ControlPoint* cur=keyList;
     102    ControlPoint* pre=cur;
     103    Color* curColor=keyColors;
     104    Color* preColor=curColor;
     105
     106    //if x is the edge point, only reset the color to white
     107    if (x==15) {
     108        keyColors->R=1; keyColors->G=1; keyColors->B=1;
     109        return;
     110    } else if (x==15+cm_unitWidth) {
     111        while (curColor->next!=0) {
     112            curColor=curColor->next;
     113        }
     114        curColor->R=1; curColor->G=1; curColor->B=1;
     115    }
     116
     117    curColor=keyColors;
     118    preColor=curColor;
     119    while (cur->next!=0) {
     120        if (cur->x==x) {
     121            pre->next=cur->next;
     122            delete(cur);
     123            preColor->next=curColor->next;
     124            delete(curColor);
     125            numOfKeys--;
     126            break;
     127        }
     128        pre=cur;
     129        cur=cur->next;
     130        preColor=curColor;
     131        curColor=curColor->next;
     132    }
     133
     134    //TransferFunctionGlutWindow::WriteControlPoints();
     135    ColorGradientGLUTWindow::WriteControlPoints();
     136    glutSetWindow(colorMapWindow);
     137    glutPostRedisplay();
     138}
     139
     140void ColorGradient::changeColor(double r, double g, double b)
     141{
     142    if (cm_gvSelectedPoint==0)
     143        return;
     144
     145    Color* curColor=map->keyColors;
     146    ControlPoint* curPoint=map->keyList;
     147    while (curPoint!=cm_gvSelectedPoint){
     148        curPoint=curPoint->next;
     149        curColor=curColor->next;
     150    }
     151
     152    curColor->R=r;
     153    curColor->G=g;
     154    curColor->B=b;
     155
     156    ColorGradientGLUTWindow::WriteControlPoints();
     157
     158    glutSetWindow(colorMapWindow);
     159    glutPostRedisplay();
     160}
     161
     162void ColorGradient::cleanUp()
     163{
     164    if (numOfKeys<2)
     165        return;
     166
     167    Color* curColor=keyColors->next;
     168    Color* preColor=keyColors;
     169
     170    if (numOfKeys==2){
     171        preColor->R=1; preColor->G=1; preColor->B=1;
     172        curColor->R=1; curColor->G=1; curColor->B=1;
     173        return;
     174    }
     175
     176    while (curColor->next!=0){
     177        if(preColor!=keyColors)
     178            delete(preColor);
     179        preColor=curColor;
     180        curColor=curColor->next;
     181    }
     182
     183    delete(preColor);
     184    keyColors->next=curColor;
     185
     186    keyColors->R=1; keyColors->B=1; keyColors->B=1;
     187    keyColors->next->R=1; keyColors->next->G=1; keyColors->next->B=1;
     188
     189    ControlPoint* cur=keyList->next;
     190    ControlPoint* pre=keyList;
     191
     192    while (cur->next!=0) {
     193        if(pre!=keyList)
     194            delete(pre);
     195        pre=cur;
     196        cur=cur->next;
     197    }
     198
     199    delete(pre);
     200    keyList->next=cur;
     201
     202    keyList->x=15;
     203    keyList->next->x=15+cm_unitWidth;
     204    numOfKeys=2;
     205
     206    ColorGradientGLUTWindow::WriteControlPoints();
     207}
     208
     209void ColorGradient::ReadColorGradientFile(char *fileName)
     210{
     211    /*
     212    FILE *gradFile;
     213
     214    float *f1;
     215    int  NumberOfGradients;
     216    int  i;
     217
     218    if( (gradFile = fopen(fileName, "rb") ) == NULL) {
     219        printf("Can't open color gradient file %s.\n", fileName);
     220        return;
     221    }
     222
     223    if( fscanf(gradFile, "%d", &NumberOfGradients) <= 0) {
     224        printf("Read color gradient file error (File: %s). \n", fileName);
     225            return;
     226    }
     227
     228    // if (keyColors!=NULL)
     229    //     delete keyColors;
     230
     231    // if (keyPoints!=NULL)
     232    //     delete keyPoints;
     233
     234    numOfKeys = NumberOfGradients;
     235    currentKeys = 0;
     236
     237
     238    keyColors = new Color[numOfKeys];
     239    keyPoints = new double[numOfKeys];
     240
     241
     242    assert(NumberOfGradients > 0);
    173243       
    174         curColor->R=r;
    175         curColor->G=g;
    176         curColor->B=b;
    177 
    178         ColorGradientGLUTWindow::WriteControlPoints();
    179 
    180         glutSetWindow(colorMapWindow);
    181         glutPostRedisplay();
    182 }
    183 
    184 
    185 
    186 
    187 void ColorGradient::cleanUp(){
    188         if (numOfKeys<2)
    189                 return;
    190 
    191 
    192         Color* curColor=keyColors->next;
    193         Color* preColor=keyColors;
    194 
    195         if (numOfKeys==2){
    196                 preColor->R=1; preColor->G=1; preColor->B=1;
    197                 curColor->R=1; curColor->G=1; curColor->B=1;
    198                 return;
    199         }
    200 
    201 
    202         while (curColor->next!=0){
    203                 if(preColor!=keyColors)
    204                         delete(preColor);
    205                 preColor=curColor;
    206                 curColor=curColor->next;
    207         }
    208 
    209         delete(preColor);
    210         keyColors->next=curColor;
    211 
    212         keyColors->R=1; keyColors->B=1; keyColors->B=1;
    213         keyColors->next->R=1; keyColors->next->G=1; keyColors->next->B=1;
    214 
    215 
    216 
    217 
    218         ControlPoint* cur=keyList->next;
    219         ControlPoint* pre=keyList;
    220 
    221         while (cur->next!=0){
    222                 if(pre!=keyList)
    223                         delete(pre);
    224                 pre=cur;
    225                 cur=cur->next;
    226         }
    227 
    228         delete(pre);
    229         keyList->next=cur;
    230 
    231         keyList->x=15;
    232         keyList->next->x=15+cm_unitWidth;
    233         numOfKeys=2;
    234 
    235         ColorGradientGLUTWindow::WriteControlPoints();
    236 }
    237 
    238 
    239 
    240 
    241 void ColorGradient::ReadColorGradientFile(char *fileName)
    242 {
    243 /*
    244         FILE *gradFile;
     244    float flag_f = -1.0;
     245    f1 = new float[NumberOfGradients * 4];
     246    for(i = 0; i <  NumberOfGradients; i++) {
     247        if( fscanf(gradFile, "%f%f%f%f", f1+i*4, f1+i*4+1, f1+i*4+2, f1+i*4+3)!= 4 ) {
     248            printf("Read color gradient file error (File: %s). \n", fileName);
     249            return;
     250        }
     251
     252        assert(f1[i*4] >= 0.0 && f1[i*4] <=1.0);
     253        assert(f1[i*4+1] >= 0.0 && f1[i*4+1] <=1.0);
     254        assert(f1[i*4+2] >= 0.0 && f1[i*4+2] <=1.0);
     255        assert(f1[i*4+3] >= 0.0 && f1[i*4+3] <=1.0);
     256
     257        //All of the addKey's must be in increasing order
     258        if (flag_f >= f1[i*4]) {
     259            printf("Color gradient should be in increasing order. \n");
     260            return;
     261        }
     262    }
     263
     264    for (i = 0; i <  NumberOfGradients; i++) {
     265        //this->addKey(f1[i*4], Color(f1[i*4+1], f1[i*4+2],f1[i*4+3]));
     266    }
     267
     268    if (gradFile)
     269        fclose(gradFile);
     270    */
     271}
     272
     273void ColorGradient::SaveColorGradientFile(char *fileName)
     274{
     275    /*
     276    FILE *gradFile;
    245277       
    246         float *f1;
    247         int  NumberOfGradients;
    248         int  i;
     278    int  i;
    249279       
    250         if( (gradFile = fopen(fileName, "rb") ) == NULL)
    251         {
    252                 printf("Can't open color gradient file %s.\n", fileName);
    253                 return;
    254     }
    255        
    256        
    257         if( fscanf(gradFile, "%d", &NumberOfGradients) <= 0)
    258         {
    259                 printf("Read color gradient file error (File: %s). \n", fileName);
    260                 return;
    261         }
    262        
    263 
    264 //      if (keyColors!=NULL)
    265 //              delete keyColors;
    266 
    267 //      if (keyPoints!=NULL)
    268 //              delete keyPoints;
    269 
    270         numOfKeys = NumberOfGradients;
    271         currentKeys = 0;
    272 
    273 
    274         keyColors = new Color[numOfKeys];
    275         keyPoints = new double[numOfKeys];
    276 
    277 
    278         assert(NumberOfGradients > 0);
    279        
    280         float flag_f = -1.0;
    281         f1 = new float[NumberOfGradients * 4];
    282         for(i = 0; i <  NumberOfGradients; i++)
    283         {
    284                 if( fscanf(gradFile, "%f%f%f%f", f1+i*4, f1+i*4+1, f1+i*4+2, f1+i*4+3)!= 4 )
    285                 {
    286                         printf("Read color gradient file error (File: %s). \n", fileName);
    287                         return;
    288                 }
    289                
    290                 assert(f1[i*4] >= 0.0 && f1[i*4] <=1.0);
    291                 assert(f1[i*4+1] >= 0.0 && f1[i*4+1] <=1.0);
    292                 assert(f1[i*4+2] >= 0.0 && f1[i*4+2] <=1.0);
    293                 assert(f1[i*4+3] >= 0.0 && f1[i*4+3] <=1.0);
    294                
    295                 //All of the addKey's must be in increasing order
    296                 if(flag_f >= f1[i*4])
    297                 {
    298                         printf("Color gradient should be in increasing order. \n");
    299                         return;
    300                 }
    301         }
    302        
    303         for(i = 0; i <  NumberOfGradients; i++)
    304         {
    305                 //this->addKey(f1[i*4], Color(f1[i*4+1], f1[i*4+2],f1[i*4+3]));
    306         }
    307        
    308         if(gradFile)
    309                 fclose(gradFile);
    310 
    311   */
    312        
    313 }
    314 
    315 
    316 
    317 void ColorGradient::SaveColorGradientFile(char *fileName)
    318 {
    319         /*
    320         FILE *gradFile;
    321        
    322         int  i;
    323        
    324         if( (gradFile = fopen(fileName, "wt") ) == NULL)
    325         {
    326                 printf("Can't open file for writing, this be some serious error.\n");
    327                 assert(false);
    328     }
    329 
    330 
    331         fprintf(gradFile, "%d\n", numOfKeys);
    332        
    333         for (i=0;i<numOfKeys;i++)
    334         {
    335                 fprintf(gradFile, "%.3lf %.3lf %.3lf %.3lf\n", keyPoints[i], keyColors[i].R, keyColors[i].G, keyColors[i].B);
    336         }
    337 
    338         fclose(gradFile);
    339         */
    340 
    341 }
    342 
    343 
    344 void ColorGradient::scaleKeys(double scaleX, int cm_unitWidth){
    345         ControlPoint* cur=keyList;
    346        
    347         while(cur->next!=0){
    348                 cur->x=(cur->x-15)*scaleX+15;
    349                 cur=cur->next;
    350         }
    351 
    352         cur->x=15+cm_unitWidth;
    353 }
     280    if( (gradFile = fopen(fileName, "wt") ) == NULL) {
     281        printf("Can't open file for writing, this be some serious error.\n");
     282        assert(false);
     283    }
     284
     285    fprintf(gradFile, "%d\n", numOfKeys);
     286
     287    for (i=0; i<numOfKeys; i++) {
     288        fprintf(gradFile, "%.3lf %.3lf %.3lf %.3lf\n", keyPoints[i], keyColors[i].R, keyColors[i].G, keyColors[i].B);
     289    }
     290
     291    fclose(gradFile);
     292    */
     293}
     294
     295void ColorGradient::scaleKeys(double scaleX, int cm_unitWidth)
     296{
     297    ControlPoint* cur=keyList;
     298
     299    while (cur->next!=0) {
     300        cur->x=(cur->x-15)*scaleX+15;
     301        cur=cur->next;
     302    }
     303
     304    cur->x=15+cm_unitWidth;
     305}
  • trunk/packages/vizservers/nanovis/transfer-function/ColorGradient.h

    r2798 r2897  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 /*
    3  * ----------------------------------------------------------------------
    4  * ColorGradient.h: interface for the ColorGradient class
    5  *
    6  * ======================================================================
     2/* ======================================================================
    73 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
    84 *           Purdue Rendering and Perceptualization Lab (PURPL)
     
    1410 * ======================================================================
    1511 */
    16 
    1712#ifndef COLOR_GRADIENT_H
    1813#define COLOR_GRADIENT_H
     
    2419{
    2520public:
     21    ColorGradient();
     22    virtual ~ColorGradient();
    2623
    27         int numOfKeys;  //number of points             
    28         ControlPoint* keyList;  //single linked list of control points
    29         Color *keyColors;               //list of key colors
     24    void SaveColorGradientFile(char *fileName);
    3025
    31         void SaveColorGradientFile(char *fileName);
    32         void ReadColorGradientFile(char *fileName);
    33         static void changeColor(double r, double g, double b);
    34         ControlPoint* addKey(double key, Color *color);
    35         void removeKey(double key);
    36         void cleanUp();
    37         void scaleKeys(double scaleX, int newUnitWidth);
    38         ColorGradient();
    39         virtual ~ColorGradient();
    40         friend class ColorGradientGLUTWindow;
     26    void ReadColorGradientFile(char *fileName);
     27
     28    static void changeColor(double r, double g, double b);
     29
     30    ControlPoint* addKey(double key, Color *color);
     31
     32    void removeKey(double key);
     33
     34    void cleanUp();
     35
     36    void scaleKeys(double scaleX, int newUnitWidth);
     37
     38    friend class ColorGradientGLUTWindow;
     39
     40    int numOfKeys;      //number of points             
     41    ControlPoint* keyList;      //single linked list of control points
     42    Color *keyColors;           //list of key colors
    4143};
    4244
  • trunk/packages/vizservers/nanovis/transfer-function/ColorGradientGLUTWindow.cpp

    r2798 r2897  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 /*
    3  * ----------------------------------------------------------------------
    4  * ColorGradientGLUTWindow.cpp
    5  *
    6  * ======================================================================
     2/* ======================================================================
    73 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
    84 *           Purdue Rendering and Perceptualization Lab (PURPL)
     
    1410 * ======================================================================
    1511 */
    16 
    1712#include "TransferFunctionMain.h"
    1813#include "ColorGradientGLUTWindow.h"
    1914#include "ColorPaletteWindow.h"
    2015#include "TransferFunctionGLUTWindow.h"
    21 
    2216
    2317int mapNumOfOutput=MAP_NUM_OF_OUTPUT;
     
    5448    map = new ColorGradient();
    5549}
    56 
    5750
    5851ColorGradientGLUTWindow::~ColorGradientGLUTWindow()
     
    8275    distanceThreshold=64;
    8376
    84     if(mapOutput==0)
     77    if (mapOutput==0)
    8578        fprintf(stderr, "NULL");
    8679
     
    9285}
    9386
    94 
    95 
    9687void
    9788ColorGradientGLUTWindow::createGLUIWidgets()
    9889{
    9990    cm_glui = GLUI_Master.create_glui_subwindow(colorMapWindow,
    100                                                 GLUI_SUBWINDOW_BOTTOM);
     91                                                GLUI_SUBWINDOW_BOTTOM);
    10192    pan=cm_glui->add_panel("buttons", GLUI_PANEL_NONE);
    10293    cm_glui->set_main_gfx_window(colorMapWindow);
     
    111102}
    112103
    113 
    114104void update_tf_texture();
    115105
     
    148138    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    149139
    150 
    151140    int i;
    152141
    153     if(map == NULL){
     142    if (map == NULL) {
    154143        fprintf(stderr, "ColorGradient Window : forgot to bind the colorMap\n");
    155144        return;
    156145    }
    157 
    158146
    159147    Color* leftColor=map->keyColors;
     
    169157    glShadeModel(GL_SMOOTH);
    170158    glDisable(GL_DEPTH_TEST);
    171        
     159
    172160    glBegin(GL_QUADS);
    173     for(i=0; i<map->numOfKeys-1; i++){
     161    for (i=0; i<map->numOfKeys-1; i++) {
    174162        left_x=leftPoint->x;
    175163        leftColor->GetRGB(left_color);
     
    189177        glVertex2d(right_x, cm_winy-10);
    190178        glVertex2d(right_x, 0);
    191                        
     179
    192180        leftColor=leftColor->next;
    193181        leftPoint=leftPoint->next;
    194 
    195182    }
    196183    glEnd();
    197184    glColor3f(0, 0, 0);
    198 
    199185
    200186    //draw bar
     
    205191    glEnd();
    206192
    207 
    208193    i=0;
    209194    Color* curColor=map->keyColors;
    210195    ControlPoint* curKey=map->keyList;
    211     for (i=0; i<map->numOfKeys ; i++){
     196    for (i=0; i<map->numOfKeys ; i++) {
    212197        //glColor3d(curColor->R, curColor->G, curColor->B);
    213198        glColor3d(0.0, 0.0, 0.0);
     
    217202    }
    218203
    219 
    220204    glColor3d(0.0, 0.0, 0.0);
    221205    glutSwapBuffers();
    222206}
    223 
    224 
    225 
    226207
    227208void
     
    249230}
    250231
    251 
    252 
    253 
    254232void
    255233ColorGradientGLUTWindow::cmDestroy()
     
    262240    switch(key) {   
    263241    case 'p':
    264         //printPoints();
    265         break;
     242        //printPoints();
     243        break;
    266244    case 'c':
    267         printInterpolation();
    268         break;
     245        printInterpolation();
     246        break;
    269247    default:
    270         break;
     248        break;
    271249    }
    272250}
     
    295273    bool gvIsSelected = SelectPoint(scX, scY);
    296274
    297     if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){
    298                
    299         if (gvIsSelected && cm_editState==0){
     275    if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
     276        if (gvIsSelected && cm_editState==0) {
    300277            //assert(cm_gvSelectedPoint!=NULL);
    301278            gv_DX = scX - cm_gvSelectedPoint->x; //Offset from current point to selected point, for dragging corrections
     
    304281            cm_gvIsDragging = true;
    305282        }
    306         /*else if ((!gvIsSelected) && cm_editState==1){
    307           GLint viewportVector[4];
    308           double scX, scY;
    309 
    310           glGetIntegerv(GL_VIEWPORT, viewportVector);
    311 
    312           gv_X = scX = x;
    313           gv_Y = scY = viewportVector[3] - (GLint) y - 1;
    314           cm_gvSelectedPoint=map->addKey(scX - gv_DX, new Color(1,1,1));
    315           cm_editState=0;
    316           WriteControlPoints();
    317           }*/
     283        /*else if ((!gvIsSelected) && cm_editState==1) {
     284            GLint viewportVector[4];
     285            double scX, scY;
     286
     287            glGetIntegerv(GL_VIEWPORT, viewportVector);
     288
     289            gv_X = scX = x;
     290            gv_Y = scY = viewportVector[3] - (GLint) y - 1;
     291            cm_gvSelectedPoint=map->addKey(scX - gv_DX, new Color(1,1,1));
     292            cm_editState=0;
     293            WriteControlPoints();
     294        }*/
    318295    } else if (button == GLUT_LEFT_BUTTON && state == GLUT_UP) {
    319         //"     End dragging" code.
     296        // End dragging code.
    320297        cm_gvIsDragging = false;
    321         if (cm_gvSelectedPoint) 
     298        if (cm_gvSelectedPoint)
    322299            cm_gvSelectedPoint->dragged = false;
    323300    }
    324301    if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) {
    325         GLint viewportVector[4];
    326         double scX, scY;
    327        
    328         glGetIntegerv(GL_VIEWPORT, viewportVector);
    329        
    330         gv_X = scX = x;
    331         gv_Y = scY = viewportVector[3] - (GLint) y - 1;
    332         cm_gvSelectedPoint=map->addKey(scX - gv_DX, new Color(1,1,1));
    333         cm_editState=0;
    334         WriteControlPoints();
    335     }
    336    
     302        GLint viewportVector[4];
     303        double scX, scY;
     304       
     305        glGetIntegerv(GL_VIEWPORT, viewportVector);
     306       
     307        gv_X = scX = x;
     308        gv_Y = scY = viewportVector[3] - (GLint) y - 1;
     309        cm_gvSelectedPoint=map->addKey(scX - gv_DX, new Color(1,1,1));
     310        cm_editState=0;
     311        WriteControlPoints();
     312    }
    337313
    338314    if (button == GLUT_MIDDLE_BUTTON && state == GLUT_DOWN)
    339         cm_gvScaleDragging = true;
    340    
     315        cm_gvScaleDragging = true;
     316
    341317    if (button == GLUT_MIDDLE_BUTTON && state == GLUT_UP)
    342         cm_gvScaleDragging = false;
    343 
    344     ///////////////////////////
     318        cm_gvScaleDragging = false;
     319
    345320    glutSetWindow(colorMapWindow);
    346     ////////////////////////
    347321    glutPostRedisplay();
    348322}
    349 
    350 
    351323
    352324void
     
    361333    gv_Y = scY = viewportVector[3] - (GLint) y - 1;
    362334
    363     if (cm_gvIsDragging == true && cm_gvSelectedPoint!=NULL){
     335    if (cm_gvIsDragging == true && cm_gvSelectedPoint!=NULL) {
    364336        //Dragging handling code.
    365337        cm_gvSelectedPoint->dragged = true;
    366 
    367338
    368339        ControlPoint* cur=map->keyList;
     
    407378    //Traverse the points and find the one that seems close
    408379    cur=map->keyList;
    409     while(cur!=0){
     380    while (cur!=0) {
    410381        double distanceSq;
    411382        distanceSq = (cur->x - x)*(cur->x - x) + (cur->y - y)*(cur->y - y);     
     
    421392}
    422393
    423 
    424394void update_tf_texture();
    425395
     
    427397ColorGradientGLUTWindow::WriteControlPoints()
    428398{
    429 
    430399    //special case: all points have the same color
    431400    Color* curColor=map->keyColors;
     
    434403    double G = map->keyColors->G;
    435404    double B = map->keyColors->B;
    436     while (curColor!=0){
     405    while (curColor!=0) {
    437406        if (curColor->R!=R || curColor->G!=G || curColor->B!=B){
    438407            allSameY=false;
     
    442411    }
    443412
    444     if (allSameY){
     413    if (allSameY) {
    445414        int i=0;
    446                
    447         for(i=0;i<mapNumOfOutput;i++){
     415
     416        for (i=0;i<mapNumOfOutput;i++) {
    448417            color_table[i][0]=R;
    449418            color_table[i][1]=G;
     
    475444
    476445    int i=0;
    477     for(i=0;i<numOfOutput;i++){
    478                
    479         if (unit*i+15>x2){
     446    for (i=0; i<numOfOutput; i++) {
     447        if (unit*i+15>x2) {
    480448            //go to next line segment
    481449            curColor=nextColor;
     
    499467            g2=nextColor->G*255;
    500468            b2=nextColor->B*255;
    501 
    502469        }
    503470        t=((float)(unit*i+15-x1))/((float)(x2-x1));
     
    512479}
    513480
    514 
    515481ControlPoint*
    516482ColorGradientGLUTWindow::boundaryChecking()
     
    522488    ControlPoint* right=map->keyList;
    523489
    524     while (right!=cm_gvSelectedPoint){
     490    while (right!=cm_gvSelectedPoint) {
    525491        left=right;
    526492        right=right->next;
     
    530496    if (right->next!=0){
    531497        right=right->next;
    532         if (cm_gvSelectedPoint->x>right->x){
     498        if (cm_gvSelectedPoint->x>right->x) {
    533499            sortPoints();
    534500        }
     
    537503    //selected point is not the left-end point
    538504    if (left!=cm_gvSelectedPoint) {
    539         if (cm_gvSelectedPoint->x<left->x){
     505        if (cm_gvSelectedPoint->x<left->x) {
    540506            sortPoints();
    541507        }
     
    544510    return cm_gvSelectedPoint;
    545511}
    546 
    547512
    548513//sort all controlpoints by bubble sort
     
    566531    curColor=map->keyColors;
    567532
    568     preColor = NULL;            /* Suppress compiler warning. */
     533    preColor = NULL;
    569534    pre = NULL;
    570535
    571536    int i;
    572     for(i=0;i<map->numOfKeys-1;i++){
     537    for (i=0;i<map->numOfKeys-1;i++) {
    573538        while (cur->next!=NULL){
    574             if (cur->x > cur->next->x){
    575                 if (cur==map->keyList){
     539            if (cur->x > cur->next->x) {
     540                if (cur==map->keyList) {
    576541                    //first node
    577542                    a=map->keyList;
     
    588553                    map->keyColors=d;
    589554                    curColor=map->keyColors;
    590                 }
    591                 else {
     555                } else {
    592556                    a=cur;
    593557                    b=cur->next;
     
    617581}
    618582
    619 
    620 
    621583void
    622584ColorGradientGLUTWindow::printInterpolation()
    623585{
    624586    int i=0;
    625     for(i=0;i<numOfOutput;i++){
     587    for (i=0;i<numOfOutput;i++) {
    626588        //printf("(%g,%g,%g) ", mapOutput[3*i], mapOutput[3*i+1], mapOutput[3*i+2]);
    627589        fprintf(stderr, "(%g,%g,%g) ", color_table[i][0], color_table[i][1], color_table[i][2]);
  • trunk/packages/vizservers/nanovis/transfer-function/ColorGradientGLUTWindow.h

    r2798 r2897  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 /*
    3  * ----------------------------------------------------------------------
    4  * ColorGradientGLUTWindow.h
    5  *
    6  * ======================================================================
     2/* ======================================================================
    73 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
    84 *           Purdue Rendering and Perceptualization Lab (PURPL)
     
    1410 * ======================================================================
    1511 */
    16 
    17 
    1812#ifndef COLOR_GRADIENT_GLUT_WINDOW_H
    1913#define COLOR_GRADIENT_GLUT_WINDOW_H
    20 
    2114
    2215#include <glui.h>
    2316#include "ColorGradient.h"
    2417#include "ControlPoint.h"
    25 
    2618
    2719extern int cm_winx, cm_winy;  //size of the subwindow
     
    3123       
    3224extern ControlPoint* cm_gvSelectedPoint; //current selected color controlpoint
    33 
    3425
    3526///////Color Map Interpolation Result//////////////////////////////
     
    4132extern GLUI *cm_glui;
    4233
    43 
    4434class ColorGradientGLUTWindow 
    4535{
    4636public:
     37    ColorGradientGLUTWindow();
     38    virtual ~ColorGradientGLUTWindow();
    4739
    48         static void cmMouse(int button, int state, int x, int y);
    49         static void cmMotion(int x, int y);
    50         static void cmIdle();
    51         static void cmKeyboard(unsigned char key, int x, int y);
    52         static void cmDestroy();
    53         static void cmReshape(int x, int y);
    54         static void cmDisplay();
     40    static void cmMouse(int button, int state, int x, int y);
     41    static void cmMotion(int x, int y);
     42    static void cmIdle();
     43    static void cmKeyboard(unsigned char key, int x, int y);
     44    static void cmDestroy();
     45    static void cmReshape(int x, int y);
     46    static void cmDisplay();
    5547
    56 
    57         static void cmInit(int main_win_x, int main_win_y);
    58         static bool SelectPoint(double x, double y);
    59         static void sortPoints();
    60         static ControlPoint* boundaryChecking();
    61         static void changeState(int arg);
    62         static void createGLUIWidgets();
    63         static void WriteControlPoints();
    64         static void printInterpolation();
    65 
    66         ColorGradientGLUTWindow();
    67         virtual ~ColorGradientGLUTWindow();
    68 
     48    static void cmInit(int main_win_x, int main_win_y);
     49    static bool SelectPoint(double x, double y);
     50    static void sortPoints();
     51    static ControlPoint* boundaryChecking();
     52    static void changeState(int arg);
     53    static void createGLUIWidgets();
     54    static void WriteControlPoints();
     55    static void printInterpolation();
    6956};
    7057
  • trunk/packages/vizservers/nanovis/transfer-function/ColorPaletteWindow.cpp

    r2798 r2897  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 /*
    3  * ----------------------------------------------------------------------
    4  * ColorPaletteWindow.cpp: color palette window class
    5  *
    6  * ======================================================================
     2/* ======================================================================
    73 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
    84 *           Purdue Rendering and Perceptualization Lab (PURPL)
     
    1410 * ======================================================================
    1511 */
    16 
    1712#include <math.h>
    1813
     
    3328GLUI_StaticText *eye_distance_label, *fps_label;
    3429
    35 
    3630namespace ColorPaletteWindow {
    3731    int  cpwin_pos_x = 100;
     
    4842using namespace ColorPaletteWindow;
    4943
    50 
    51 
    5244ColorPalette::ColorPalette()
    5345{
     
    6052void ColorPalette::cpSyncLive()
    6153{
    62     if (cp_glui!=0){
     54    if (cp_glui!=0) {
    6355        cp_glui->sync_live();
    6456    }
     
    7062
    7163    //fileName=(char*) malloc(sizeof(char)*30);
    72     for(int i=0;i<200;i++){
     64    for (int i=0;i<200;i++) {
    7365        fileName[i]=0;
    7466    }
     
    8274    glutInitWindowPosition( cpwin_pos_x, cpwin_pos_y);
    8375    glutInitWindowSize( cp_winx, cp_winy );
    84  
     76
    8577    colorPaletteWindow = glutCreateWindow("Color Palette");
    8678
     
    9284    glutMotionFunc (cpMotion);
    9385
    94 
    9586    GLUI_Master.set_glutReshapeFunc(cpReshape);
    9687    GLUI_Master.set_glutDisplayFunc( cpDisplay );
     
    10394}
    10495
    105 
    10696void update_tf_texture();
    10797
    108 void ColorPalette::cmdHandler(int arg){
    109     switch (arg){
     98void ColorPalette::cmdHandler(int arg)
     99{
     100    switch (arg) {
    110101    case 1: //add color
    111102        cm_editState=1;
     
    137128        break;
    138129    case 8:
    139         if (color_model==0){
     130        if (color_model==0) {
    140131            color_r->enable();
    141132            color_g->enable();
     
    153144            cp_color_S=0;
    154145            cp_color_B=0;
    155                                
     146
    156147            color_point_1->x=0;
    157148            color_point_1->y=cp_winy;
    158149
    159150            cp_glui->sync_live();
    160         }
    161         else if (color_model==1){
     151        } else if (color_model==1) {
    162152            color_r->enable();
    163153            color_g->enable();
     
    180170
    181171            cp_glui->sync_live();
    182         }
    183         else if (color_model==2){
     172        } else if (color_model==2) {
    184173            color_r->enable();
    185174            color_g->enable();
     
    205194            cp_glui->sync_live();
    206195        }
    207                
     196
    208197        glutSetWindow(colorPaletteWindow);
    209198        glutPostRedisplay();
     
    213202    case 10:
    214203        break;
    215 
    216204    default:
    217205        break;
     
    219207}
    220208
    221 
    222 void ColorPalette::openFile(){
    223        
    224 }
    225 
    226 
    227 
    228 
    229 void ColorPalette::createGLUIWidgets(){
     209void ColorPalette::openFile()
     210{
     211}
     212
     213void ColorPalette::createGLUIWidgets()
     214{
    230215    cp_glui = GLUI_Master.create_glui_subwindow(colorPaletteWindow, GLUI_SUBWINDOW_BOTTOM);
    231216    cp_glui->set_main_gfx_window(colorPaletteWindow);
     
    256241    color_B->disable();
    257242
    258 
    259243    cp_glui->add_column(true);
    260244
     
    275259    cp_glui->add_button("Reset TF", 7, cmdHandler);
    276260
    277 
    278261    cp_glui->add_column(true);
    279262    cp_glui->add_statictext("File:");
     
    288271}
    289272
    290 
    291 void ColorPalette::cpIdle(){
     273void ColorPalette::cpIdle()
     274{
    292275    //glutSetWindow(mainWindow);
    293276    //glutPostRedisplay();
    294277}
    295278
    296 
    297 
    298 
    299 void ColorPalette::confirm(int arg){
     279void ColorPalette::confirm(int arg)
     280{
    300281    if (cm_gvSelectedPoint!=0)
    301282        map->changeColor((double)cp_color_r/255, (double)cp_color_g/255, (double)cp_color_b/255);
     
    308289}
    309290
    310 
    311 
    312291void ColorPalette::cpDisplay()
    313292{
     
    317296    glClearColor( 1.0f, 1.0f, 1.0f, 1.0f );
    318297    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    319 
    320298
    321299    glColor3d(0.0, 0.0, 0.0);
     
    323301    glDisable(GL_DEPTH_TEST);
    324302
    325 
    326     if (color_model==RGB){
    327 
     303    if (color_model==RGB) {
    328304        Color* leftColor = new Color(1, 0, 0);
    329305        Color* rightColor = new Color(0, 0, 1);
     
    336312
    337313        GLfloat rainbowColor[18] = {
    338             1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1
    339         };
    340                
     314            1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1
     315        };
     316
    341317        int i=0;
    342318        float unitWidth = cp_winx/6;
    343319
    344320        glBegin(GL_QUADS);
    345         for (i=0; i<6; i++){           
     321        for (i=0; i<6; i++) {           
    346322
    347323            glColor3f(rainbowColor[3*i], rainbowColor[3*i+1], rainbowColor[3*i+2]);
     
    349325            glVertex2d(unitWidth*i, cp_winy);
    350326
    351             if (i==5){
     327            if (i==5) {
    352328                glColor3f(rainbowColor[0], rainbowColor[1], rainbowColor[2]);
    353329                glVertex2d(cp_winx, cp_winy);
    354330                glVertex2d(cp_winx, 0);
    355             }
    356             else {
     331            } else {
    357332                glColor3f(rainbowColor[3*i+3], rainbowColor[3*i+4], rainbowColor[3*i+5]);
    358333                glVertex2d(unitWidth*(i+1), cp_winy);
     
    365340        glColor3d(0,0,0);
    366341        color_point_1->glDraw_3();
    367     }
    368 
    369     else if (color_model==GRAY){
     342    } else if (color_model==GRAY) {
    370343        glBegin(GL_QUADS);             
    371344        glColor3f(0, 0, 0);
     
    380353        glColor3d(1,0,0);
    381354        color_point_1->glDraw_3();
    382     }
    383 
    384     else if(color_model==HSB){
    385                
     355    } else if(color_model==HSB) {
    386356        glBegin(GL_QUADS);             
    387357        glColor3f(0, 0, 0);
     
    407377
    408378        GLfloat rainbowColor[18] = {
    409             1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1
    410         };
    411                
     379            1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1
     380        };
     381
    412382        int i=0;
    413383        float unitWidth = cp_winx/6;
    414384
    415385        glBegin(GL_QUADS);
    416         for (i=0; i<6; i++){           
    417 
     386        for (i=0; i<6; i++) {           
    418387            glColor3f(rainbowColor[3*i], rainbowColor[3*i+1], rainbowColor[3*i+2]);
    419388            glVertex2d(unitWidth*i, 2*cp_winy/3-15);
     
    424393                glVertex2d(cp_winx, 2*cp_winy/3);
    425394                glVertex2d(cp_winx, 2*cp_winy/3-15);
    426             }
    427             else {
     395            } else {
    428396                glColor3f(rainbowColor[3*i+3], rainbowColor[3*i+4], rainbowColor[3*i+5]);
    429397                glVertex2d(unitWidth*(i+1), 2*cp_winy/3);
     
    459427          }
    460428        */
    461 
    462429    }
    463430
     
    466433}
    467434
    468 
    469 
    470 
    471 void ColorPalette::cpReshape(int x, int y){
     435void ColorPalette::cpReshape(int x, int y)
     436{
    472437    //printf("cpreshape=%d",x);
    473438
     
    490455}
    491456
    492 
    493457void ColorPalette::cpKeyboard(unsigned char key, int x, int y)
    494458{
    495459    //glutPostRedisplay();
    496460}
    497 
    498 
    499461
    500462void ColorPalette::cpMouse(int button, int state, int x, int y){
     
    507469    scX = x;
    508470    scY = viewportVector[3] - (GLint) y - 1;
    509 
    510471
    511472    if (color_model!=HSB){
    512473        color_point_1->x=scX;
    513474        color_point_1->y=scY;
    514     }
    515     else{ //HSB
    516         if (scY>=2*cp_winy/3){
     475    } else { //HSB
     476        if (scY>=2*cp_winy/3) {
    517477            color_point_1->x=scX;
    518478            color_point_1->y=scY;
    519479            getColor(scX, scY);
    520480        }
    521         if (scY<2*cp_winy/3){
     481        if (scY<2*cp_winy/3) {
    522482            color_point_2->x=scX;
    523483            //color_point_1->x=0;
     
    528488    //printf("(%g, %g)\n", scX, scY);
    529489
    530 
    531     if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){
     490    if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
    532491        getColor(scX, scY);
    533     }
    534     else if (button == GLUT_LEFT_BUTTON && state == GLUT_UP){}
    535     else if (button == GLUT_MIDDLE_BUTTON && state == GLUT_DOWN){}
    536     else if (button == GLUT_MIDDLE_BUTTON && state == GLUT_UP){}
     492    } else if (button == GLUT_LEFT_BUTTON && state == GLUT_UP) {
     493    } else if (button == GLUT_MIDDLE_BUTTON && state == GLUT_DOWN) {
     494    } else if (button == GLUT_MIDDLE_BUTTON && state == GLUT_UP){
     495    }
    537496
    538497    cp_glui->sync_live();
    539498    glutPostRedisplay();
    540 
    541 }
    542 
    543 
    544 
    545 void ColorPalette::cpMotion(int x, int y){ }
    546 
    547 
     499}
     500
     501void ColorPalette::cpMotion(int x, int y)
     502{
     503}
    548504
    549505//interpolate GRB color
    550 Color ColorPalette::getColor(double x, double y){
    551     if (color_model==RGB){
     506Color ColorPalette::getColor(double x, double y)
     507{
     508    if (color_model==RGB) {
    552509        float unitWidth = cp_winx/6;           
    553510        GLfloat rainbowColor[21] = {1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0};
     
    574531        cp_glui->sync_live();
    575532        return Color(r,g,b);
    576     }
    577 
    578     else if (color_model==GRAY){
     533    } else if (color_model==GRAY) {
    579534        float t=((float)x)/((float)cp_winx);
    580535        double r, g, b;
     
    589544        cp_glui->sync_live();
    590545        return Color(r,g,b);
    591     }
    592 
    593     else if (color_model==HSB){
     546    } else if (color_model==HSB) {
    594547        double r, g, b;
    595         if (y==color_point_2->y){
     548        if (y==color_point_2->y) {
    596549            float unitWidth = cp_winx/6;               
    597550            GLfloat rainbowColor[21] = {1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0};
     
    606559            int blue_left = (int)rainbowColor[3*pos+2];
    607560            int blue_right = (int)rainbowColor[3*(pos+1)+2];
    608 
    609561               
    610562            r = (red_left+(x/unitWidth-pos)*(red_right-red_left));
     
    617569            hue_color->G=g;
    618570            hue_color->B=b;
    619                        
    620         }
    621         else{
     571        } else {
    622572            cp_color_S=(int)(100.0*(1-(double)color_point_1->x/(double)cp_winx));
    623573            cp_color_B=(int)(100.0*((double)(color_point_1->y-(double)(2*cp_winy/3))/((double)cp_winy/3)));
     
    646596
    647597        cp_glui->sync_live();
    648                
     598
    649599        return Color(r,g,b);
    650600    }
  • trunk/packages/vizservers/nanovis/transfer-function/ColorPaletteWindow.h

    r2798 r2897  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 /*
    3  * ----------------------------------------------------------------------
    4  * ColorPaletteWindow.h: color palette window class
    5  *
    6  * ======================================================================
     2/* ======================================================================
    73 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
    84 *           Purdue Rendering and Perceptualization Lab (PURPL)
     
    1410 * ======================================================================
    1511 */
    16 
    17 #ifndef _COLOR_PALETTE_WINDOW_H_
    18 #define _COLOR_PALETTE_WINODW_H_
     12#ifndef COLOR_PALETTE_WINDOW_H
     13#define COLOR_PALETTE_WINODW_H
    1914
    2015//ColorPalette Window to select color from
     
    2823extern GLUI* cp_glui; //glui handler
    2924
    30 class ColorPalette{
     25class ColorPalette
     26{
     27public:
     28    ColorPalette();
     29    virtual ~ColorPalette();
    3130
    32 public:
    33         static void cpMouse(int button, int state, int x, int y);
    34         static void cpMotion(int x, int y);
    35         static void cpIdle();
    36         static void cpKeyboard(unsigned char key, int x, int y);
    37         static void cpDestroy();
    38         static void cpReshape(int x, int y);
    39         static void cpDisplay();
    40         static void cpInit();
    41         static void cpSyncLive();
     31    static void cpMouse(int button, int state, int x, int y);
     32    static void cpMotion(int x, int y);
     33    static void cpIdle();
     34    static void cpKeyboard(unsigned char key, int x, int y);
     35    static void cpDestroy();
     36    static void cpReshape(int x, int y);
     37    static void cpDisplay();
     38    static void cpInit();
     39    static void cpSyncLive();
    4240
    43         static void createGLUIWidgets();
    44         static Color getColor(double x, double y);
    45         static void confirm(int arg);
    46         static void cmdHandler(int arg);
    47         static void openFile();
    48 
    49         ColorPalette();
    50         virtual ~ColorPalette();       
     41    static void createGLUIWidgets();
     42    static Color getColor(double x, double y);
     43    static void confirm(int arg);
     44    static void cmdHandler(int arg);
     45    static void openFile();
    5146};
    5247
  • trunk/packages/vizservers/nanovis/transfer-function/ControlPoint.cpp

    r2798 r2897  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 /*
    3  * ----------------------------------------------------------------------
    4  * ControlPoint.h
    5  *
    6  * ======================================================================
     2/* ======================================================================
    73 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
    84 *           Purdue Rendering and Perceptualization Lab (PURPL)
     
    1410 * ======================================================================
    1511 */
    16 
    1712#include <math.h>
    1813#include "TransferFunctionMain.h"
    1914#include "ControlPoint.h"
    2015
    21 
    2216ControlPoint::ControlPoint(double _x, double _y)
    2317{
    24         x = _x;
    25         y = _y;
     18    x = _x;
     19    y = _y;
    2620
    27         selected = false;
    28         dragged = false;
    29        
    30         next = 0;
     21    selected = false;
     22    dragged = false;
     23       
     24    next = 0;
    3125}
    3226
     
    3832void ControlPoint::glDraw()
    3933{
    40         //Here is the code for drawing a vertex
    41         double size = 4;
     34    //Here is the code for drawing a vertex
     35    double size = 4;
    4236
    43         glMatrixMode( GL_MODELVIEW );
    44         glPushMatrix();
    45         glTranslatef( x, y, 0 );
     37    glMatrixMode( GL_MODELVIEW );
     38    glPushMatrix();
     39    glTranslatef( x, y, 0 );
    4640
    47         glBegin(GL_LINES);
     41    glBegin(GL_LINES);
    4842
    49         glVertex2d(-size, -size);
    50         glVertex2d(+size, +size);
     43    glVertex2d(-size, -size);
     44    glVertex2d(+size, +size);
    5145
    52         glVertex2d(-size, +size);
    53         glVertex2d(+size, -size);
    54        
    55         glEnd();
     46    glVertex2d(-size, +size);
     47    glVertex2d(+size, -size);
     48       
     49    glEnd();
    5650
    57         //Special code for drawing selected vertex and dragged vertex.
     51    //Special code for drawing selected vertex and dragged vertex.
    5852
    59         if (selected && !dragged)
    60         {
    61                 double square = size + 4;
    62                
    63                 glBegin(GL_LINE_LOOP);
    64                         glColor3d(1,0,0);                       
    65                         glVertex2d(-square, -square);
    66                         glVertex2d(-square, +square);
    67                         glVertex2d(+square, +square);
    68                         glVertex2d(+square, -square);
    69                         glColor3d(0,0,0);
    70                 glEnd();
     53    if (selected && !dragged) {
     54        double square = size + 4;
     55               
     56        glBegin(GL_LINE_LOOP);
     57        glColor3d(1,0,0);                       
     58        glVertex2d(-square, -square);
     59        glVertex2d(-square, +square);
     60        glVertex2d(+square, +square);
     61        glVertex2d(+square, -square);
     62        glColor3d(0,0,0);
     63        glEnd();
    7164
    72         }
    73         else if (selected && dragged)
    74         {
    75                 double square = 4*sqrt(size + 4);
    76                 glBegin(GL_LINE_LOOP);
    77                         glColor3d(1,0,0);
    78                         glVertex2d(-square, 0);
    79                         glVertex2d(0, +square);
    80                         glVertex2d(square, 0);
    81                         glVertex2d(0, -square);
    82                         glColor3d(0,0,0);
    83                 glEnd();
     65    } else if (selected && dragged) {
     66        double square = 4*sqrt(size + 4);
     67        glBegin(GL_LINE_LOOP);
     68        glColor3d(1,0,0);
     69        glVertex2d(-square, 0);
     70        glVertex2d(0, +square);
     71        glVertex2d(square, 0);
     72        glVertex2d(0, -square);
     73        glColor3d(0,0,0);
     74        glEnd();
    8475
    85         }
    86         glPopMatrix();
     76    }
     77    glPopMatrix();
    8778
    8879}
    8980
    90 
    91 
    9281void ControlPoint::glDraw_2()
    9382{
    94         //Here is the code for drawing a vertex
    95         double size = 4;
     83    //Here is the code for drawing a vertex
     84    double size = 4;
    9685
    97         glMatrixMode( GL_MODELVIEW );
    98         glPushMatrix();
    99         glTranslatef( x, y, 0 );
     86    glMatrixMode( GL_MODELVIEW );
     87    glPushMatrix();
     88    glTranslatef( x, y, 0 );
    10089
    101         glBegin(GL_POLYGON);
    102                 glVertex2d(-size, 0);
    103                 glVertex2d(-size, -size);
    104                 glVertex2d(+size, -size);
    105                 glVertex2d(+size, 0);   
    106         glEnd();
     90    glBegin(GL_POLYGON);
     91    glVertex2d(-size, 0);
     92    glVertex2d(-size, -size);
     93    glVertex2d(+size, -size);
     94    glVertex2d(+size, 0);       
     95    glEnd();
    10796
    108         //Special code for drawing selected vertex and dragged vertex.
     97    //Special code for drawing selected vertex and dragged vertex.
    10998
    110         if (selected && !dragged)
    111         {
    112                 double square = size + 4;
    113                
    114                 glBegin(GL_LINE_LOOP);
    115                         glColor3d(1,0,0);                       
    116                         glVertex2d(-square, -square);
    117                         glVertex2d(-square, +square);
    118                         glVertex2d(+square, +square);
    119                         glVertex2d(+square, -square);
    120                         glColor3d(0,0,0);
    121                 glEnd();
    122 
    123         }
    124         else if (selected && dragged)
    125         {
    126                 double square = 4*sqrt(size + 4);
    127                 glBegin(GL_LINE_LOOP);
    128                         glColor3d(1,0,0);
    129                         glVertex2d(-square, 0);
    130                         glVertex2d(0, +square);
    131                         glVertex2d(square, 0);
    132                         glVertex2d(0, -square);
    133                         glColor3d(0,0,0);
    134                 glEnd();
    135 
    136         }
    137         glPopMatrix();
     99    if (selected && !dragged) {
     100        double square = size + 4;
     101               
     102        glBegin(GL_LINE_LOOP);
     103        glColor3d(1,0,0);                       
     104        glVertex2d(-square, -square);
     105        glVertex2d(-square, +square);
     106        glVertex2d(+square, +square);
     107        glVertex2d(+square, -square);
     108        glColor3d(0,0,0);
     109        glEnd();
     110    } else if (selected && dragged) {
     111        double square = 4*sqrt(size + 4);
     112        glBegin(GL_LINE_LOOP);
     113        glColor3d(1,0,0);
     114        glVertex2d(-square, 0);
     115        glVertex2d(0, +square);
     116        glVertex2d(square, 0);
     117        glVertex2d(0, -square);
     118        glColor3d(0,0,0);
     119        glEnd();
     120    }
     121    glPopMatrix();
    138122
    139123}
    140124
    141 
    142125void ControlPoint::glDraw_3()
    143126{
    144         //Here is the code for drawing a vertex
    145         double size = 7;
     127    //Here is the code for drawing a vertex
     128    double size = 7;
    146129
    147         glMatrixMode( GL_MODELVIEW );
    148         glPushMatrix();
    149         glTranslatef( x, y, 0 );
     130    glMatrixMode( GL_MODELVIEW );
     131    glPushMatrix();
     132    glTranslatef( x, y, 0 );
    150133
    151         glBegin(GL_LINES);
     134    glBegin(GL_LINES);
    152135
    153         glVertex2d(-2, 0);
    154         glVertex2d(-size, 0);
     136    glVertex2d(-2, 0);
     137    glVertex2d(-size, 0);
    155138
    156         glVertex2d(2, 0);
    157         glVertex2d(size, 0);
     139    glVertex2d(2, 0);
     140    glVertex2d(size, 0);
    158141
    159142
    160         glVertex2d(0, -2);
    161         glVertex2d(0, -size);
     143    glVertex2d(0, -2);
     144    glVertex2d(0, -size);
    162145
    163         glVertex2d(0, 2);
    164         glVertex2d(0, size);
     146    glVertex2d(0, 2);
     147    glVertex2d(0, size);
    165148
    166         glEnd();
     149    glEnd();
    167150
    168 
    169         glPopMatrix();
    170 
     151    glPopMatrix();
    171152}
    172 
    173 
    174153
    175154void ControlPoint::Set(double x, double y)
    176155{
    177         this->x = x;
    178         this->y = y;
     156    this->x = x;
     157    this->y = y;
    179158}
  • trunk/packages/vizservers/nanovis/transfer-function/ControlPoint.h

    r2798 r2897  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 /*
    3  * ----------------------------------------------------------------------
    4  * ControlPoint.h
    5  *
    6  * ======================================================================
     2/* ======================================================================
    73 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
    84 *           Purdue Rendering and Perceptualization Lab (PURPL)
     
    1410 * ======================================================================
    1511 */
     12#ifndef CONTROL_POINT_H
     13#define CONTROL_POINT_H
    1614
    17 #ifndef _CONTROL_POINT_H_
    18 #define _CONTROL_POINT_H_
    19 
    20 class ControlPoint 
     15class ControlPoint
    2116{
    2217public:
    23        
    24         double x;
    25         double y;
     18    ControlPoint(double _x, double _y);
     19    virtual ~ControlPoint();
    2620
    27         bool selected;
    28         bool dragged;
     21    void Set(double x, double y);
    2922
    30         ControlPoint * next;
     23    void glDraw();    //draw a cross
    3124
    32 public:
    33         void Set(double x, double y);
    34         void glDraw();          //draw a cross
    35         void glDraw_2();        //draw a filled squre
    36         void glDraw_3();        //draw a circle
    37         ControlPoint(double _x, double _y);
    38         virtual ~ControlPoint();
     25    void glDraw_2();  //draw a filled squre
    3926
     27    void glDraw_3();  //draw a circle
     28
     29    double x;
     30    double y;
     31
     32    bool selected;
     33    bool dragged;
     34
     35    ControlPoint * next;
    4036};
    4137
  • trunk/packages/vizservers/nanovis/transfer-function/MainWindow.cpp

    r2798 r2897  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 /*
    3  * ----------------------------------------------------------------------
    4  * MainWindow.h: implementation of the main transfer function gui window
    5  *
    6  * ======================================================================
     2/* ======================================================================
    73 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
    84 *           Purdue Rendering and Perceptualization Lab (PURPL)
     
    3531MainTransferFunctionWindow::~MainTransferFunctionWindow(){}
    3632
    37 
    3833//initialize
    39 void MainTransferFunctionWindow::mainInit(){
    40        
    41         distanceThreshold=36;
    42 
    43         main_winx=600;
    44         main_winy=300;
    45        
    46         glutInitWindowPosition(100, 100);
    47         glutInitWindowSize(main_winx, main_winy );
    48  
    49         mainWindow=glutCreateWindow("Advanced Transfer Function");
    50 
    51         glutDisplayFunc(mainDisplay);
    52         glutReshapeFunc(mainReshape);
    53         glutKeyboardFunc (mainKeyboard);
    54         //glutIdleFunc (mainIdle);
    55 
    56 
    57         //glutMouseFunc (mainMouse);
    58         //glutMotionFunc (mainMotion);
    59 
    60         TransferFunctionGLUTWindow::tfInit(main_winx, main_winy);
    61         transferFunctionWindow=glutCreateSubWindow(mainWindow, 0, 0, tf_winx, tf_winy);
    62         glutDisplayFunc(TransferFunctionGLUTWindow::tfDisplay);
    63         glutReshapeFunc(TransferFunctionGLUTWindow::tfReshape);
    64         glutMouseFunc(TransferFunctionGLUTWindow::tfMouse);
    65         glutKeyboardFunc(TransferFunctionGLUTWindow::tfKeyboard);
    66         glutMotionFunc (TransferFunctionGLUTWindow::tfMotion);
    67 
    68         ColorGradientGLUTWindow::cmInit(main_winx, main_winy);
    69         colorMapWindow=glutCreateSubWindow(mainWindow, 0, main_winy-cm_winy, cm_winx, cm_winy);
    70         //ColorGradientGLUTWindow::createGLUIWidgets();
    71         glutDisplayFunc(ColorGradientGLUTWindow::cmDisplay);
    72         glutReshapeFunc(ColorGradientGLUTWindow::cmReshape);
    73         glutMouseFunc(ColorGradientGLUTWindow::cmMouse);
    74         glutMotionFunc(ColorGradientGLUTWindow::cmMotion);
    75         glutKeyboardFunc(ColorGradientGLUTWindow::cmKeyboard);
    76        
    77         GLUI_Master.set_glutIdleFunc(mainIdle);
    78        
    79         ColorPalette::cpInit();
    80 
    81         //int tmp= glutGetWindow();
    82        
    83         //load a initial trasfer function
    84         //for bluntfin dataset
    85         //MainTransferFunctionWindow::loadFile("bluntfin_tf_1");
    86         //glutSetWindow(tmp);
    87 }
    88 
    89 
    90 void MainTransferFunctionWindow::mainDisplay(){
    91         glutSetWindow(transferFunctionWindow);
    92         glutPostRedisplay();
    93         glutSetWindow(colorMapWindow);
    94         glutPostRedisplay();
    95         glutSetWindow(colorPaletteWindow);
    96         glutPostRedisplay();
    97 }
    98 
    99 
    100 
    101 void MainTransferFunctionWindow::mainMouse(int button, int state, int x, int y){
    102         fprintf(stderr, "main mouse\n");
    103         //find out what area received the event
    104         if (y<=main_winy-tf_winy){
    105                 //transfer function received the event
    106                 glutSetWindow(transferFunctionWindow);
    107                 TransferFunctionGLUTWindow::tfMouse(button, state, x, y);
    108         }
    109 }
    110 
    111 
    112 
    113 
    114 
    115 
    116 void MainTransferFunctionWindow::mainMotion(int x, int y){
    117 
    118         ////////////////////////////////////////
    119         //glutSetWindow(transferFunctionWindow);
    120         //TransferFunctionGLUTWindow::tfMotion(x, y);
    121         /////////////////////////////////////
    122 
    123 }
    124 
    125 
    126 
    127 void MainTransferFunctionWindow::mainIdle(){
    128 /*
    129         glutSetWindow(mainWindow);
    130         glutPostRedisplay();
    131         glutSetWindow(transferFunctionWindow);
    132         glutPostRedisplay();
    133         glutSetWindow(colorMapWindow);
    134         glutPostRedisplay();
    135         glutSetWindow(colorPaletteWindow);
    136         glutPostRedisplay();
    137 */
    138 }
    139 
    140 
    141 
    142 void MainTransferFunctionWindow::mainKeyboard(unsigned char key, int x, int y){
    143         switch(key)
    144         {   
     34void MainTransferFunctionWindow::mainInit()
     35{
     36    distanceThreshold=36;
     37
     38    main_winx=600;
     39    main_winy=300;
     40
     41    glutInitWindowPosition(100, 100);
     42    glutInitWindowSize(main_winx, main_winy );
     43
     44    mainWindow=glutCreateWindow("Advanced Transfer Function");
     45
     46    glutDisplayFunc(mainDisplay);
     47    glutReshapeFunc(mainReshape);
     48    glutKeyboardFunc (mainKeyboard);
     49    //glutIdleFunc (mainIdle);
     50
     51
     52    //glutMouseFunc (mainMouse);
     53    //glutMotionFunc (mainMotion);
     54
     55    TransferFunctionGLUTWindow::tfInit(main_winx, main_winy);
     56    transferFunctionWindow=glutCreateSubWindow(mainWindow, 0, 0, tf_winx, tf_winy);
     57    glutDisplayFunc(TransferFunctionGLUTWindow::tfDisplay);
     58    glutReshapeFunc(TransferFunctionGLUTWindow::tfReshape);
     59    glutMouseFunc(TransferFunctionGLUTWindow::tfMouse);
     60    glutKeyboardFunc(TransferFunctionGLUTWindow::tfKeyboard);
     61    glutMotionFunc (TransferFunctionGLUTWindow::tfMotion);
     62
     63    ColorGradientGLUTWindow::cmInit(main_winx, main_winy);
     64    colorMapWindow=glutCreateSubWindow(mainWindow, 0, main_winy-cm_winy, cm_winx, cm_winy);
     65    //ColorGradientGLUTWindow::createGLUIWidgets();       
     66    glutDisplayFunc(ColorGradientGLUTWindow::cmDisplay);
     67    glutReshapeFunc(ColorGradientGLUTWindow::cmReshape);
     68    glutMouseFunc(ColorGradientGLUTWindow::cmMouse);
     69    glutMotionFunc(ColorGradientGLUTWindow::cmMotion);
     70    glutKeyboardFunc(ColorGradientGLUTWindow::cmKeyboard);
     71
     72    GLUI_Master.set_glutIdleFunc(mainIdle);
     73
     74    ColorPalette::cpInit();
     75
     76    //int tmp= glutGetWindow();
     77
     78    //load a initial trasfer function
     79    //for bluntfin dataset
     80    //MainTransferFunctionWindow::loadFile("bluntfin_tf_1");
     81    //glutSetWindow(tmp);
     82}
     83
     84void MainTransferFunctionWindow::mainDisplay()
     85{
     86    glutSetWindow(transferFunctionWindow);
     87    glutPostRedisplay();
     88    glutSetWindow(colorMapWindow);
     89    glutPostRedisplay();
     90    glutSetWindow(colorPaletteWindow);
     91    glutPostRedisplay();
     92}
     93
     94void MainTransferFunctionWindow::mainMouse(int button, int state, int x, int y)
     95{
     96    fprintf(stderr, "main mouse\n");
     97    //find out what area received the event
     98    if (y<=main_winy-tf_winy){
     99        //transfer function received the event
     100        glutSetWindow(transferFunctionWindow);
     101        TransferFunctionGLUTWindow::tfMouse(button, state, x, y);
     102    }
     103}
     104
     105void MainTransferFunctionWindow::mainMotion(int x, int y)
     106{
     107    ////////////////////////////////////////
     108    //glutSetWindow(transferFunctionWindow);
     109    //TransferFunctionGLUTWindow::tfMotion(x, y);
     110    /////////////////////////////////////
     111}
     112
     113void MainTransferFunctionWindow::mainIdle()
     114{
     115    /*
     116      glutSetWindow(mainWindow);
     117      glutPostRedisplay();
     118      glutSetWindow(transferFunctionWindow);
     119      glutPostRedisplay();
     120      glutSetWindow(colorMapWindow);
     121      glutPostRedisplay();
     122      glutSetWindow(colorPaletteWindow);
     123      glutPostRedisplay();
     124    */
     125}
     126
     127void MainTransferFunctionWindow::mainKeyboard(unsigned char key, int x, int y)
     128{
     129    switch(key) {   
    145130    case 'q':
    146                 exit(0);
    147                 break;   
     131        exit(0);
     132        break;   
    148133    case 'a':
    149                 glutSetWindow(transferFunctionWindow);
    150                 tf_pointEditState=1;
    151                 break;
     134        glutSetWindow(transferFunctionWindow);
     135        tf_pointEditState=1;
     136        break;
    152137    case 'd':
    153                 glutSetWindow(transferFunctionWindow);
    154                 tf_pointEditState=2;
    155                 if (tf_gvSelectedPoint!=NULL){
    156                         TransferFunctionGLUTWindow::removePoint(tf_gvSelectedPoint);
    157                         tf_gvSelectedPoint=0;
    158                         TransferFunctionGLUTWindow::WriteControlPoints();
    159                         glutPostRedisplay();
    160                 }
    161                 tf_pointEditState=0;
    162                 break;   
    163         case 'p':
    164                 TransferFunctionGLUTWindow::printPoints();
    165                 break;
    166         case 'w':
    167                 TransferFunctionGLUTWindow::printInterpolation();
    168                 break;
    169         case 'r':
    170                 TransferFunctionGLUTWindow::readHist();
    171                 break;
    172         case 'u':
    173                 TransferFunctionGLUTWindow::dumpHist();
    174                 break;
    175         case 'i':
    176                 TransferFunctionGLUTWindow::printHist();
    177                 break;
    178 
    179         default:
    180                 break;
     138        glutSetWindow(transferFunctionWindow);
     139        tf_pointEditState=2;
     140        if (tf_gvSelectedPoint!=NULL) {
     141            TransferFunctionGLUTWindow::removePoint(tf_gvSelectedPoint);
     142            tf_gvSelectedPoint=0;
     143            TransferFunctionGLUTWindow::WriteControlPoints();
     144            glutPostRedisplay();
     145        }
     146        tf_pointEditState=0;
     147        break;   
     148    case 'p':
     149        TransferFunctionGLUTWindow::printPoints();
     150        break;
     151    case 'w':
     152        TransferFunctionGLUTWindow::printInterpolation();
     153        break;
     154    case 'r':
     155        TransferFunctionGLUTWindow::readHist();
     156        break;
     157    case 'u':
     158        TransferFunctionGLUTWindow::dumpHist();
     159        break;
     160    case 'i':
     161        TransferFunctionGLUTWindow::printHist();
     162        break;
     163    default:
     164        break;
    181165    } 
    182 
    183 }
    184 
    185 
    186 void MainTransferFunctionWindow::mainDestroy(){}
    187 
    188 
    189 void MainTransferFunctionWindow::mainReshape(int x, int y){
    190 
    191         if (x==0 || y==0)
    192                 return;
    193 
    194         main_winx=x;
    195         main_winy=y;
    196 
    197         //change size and location of the subwindow
    198         cm_winx=main_winx;
    199         //cm_winy=main_winy/3;
    200         cm_winy=100;
    201 
    202         glutSetWindow(colorMapWindow);
    203         glutPositionWindow(0, main_winy-cm_winy);
    204         glutReshapeWindow(cm_winx, cm_winy);
    205         glutPostRedisplay();
    206 
    207         //change size and location of the subwindow
    208         tf_winx=main_winx;
    209         //tf_winy=main_winy*2/3;
    210         tf_winy=main_winy-100;
    211 
    212         glutSetWindow(transferFunctionWindow);
    213         glutPositionWindow(0,0);
    214         glutReshapeWindow(tf_winx, tf_winy);
    215         glutPostRedisplay();
    216 }
    217 
     166}
     167
     168void MainTransferFunctionWindow::mainDestroy()
     169{
     170}
     171
     172void MainTransferFunctionWindow::mainReshape(int x, int y)
     173{
     174    if (x==0 || y==0)
     175        return;
     176
     177    main_winx=x;
     178    main_winy=y;
     179
     180    //change size and location of the subwindow
     181    cm_winx=main_winx;
     182    //cm_winy=main_winy/3;
     183    cm_winy=100;
     184
     185    glutSetWindow(colorMapWindow);
     186    glutPositionWindow(0, main_winy-cm_winy);
     187    glutReshapeWindow(cm_winx, cm_winy);
     188    glutPostRedisplay();
     189
     190    //change size and location of the subwindow
     191    tf_winx=main_winx;
     192    //tf_winy=main_winy*2/3;
     193    tf_winy=main_winy-100;
     194
     195    glutSetWindow(transferFunctionWindow);
     196    glutPositionWindow(0,0);
     197    glutReshapeWindow(tf_winx, tf_winy);
     198    glutPostRedisplay();
     199}
    218200
    219201//////////////////////////////////////////////////////////
     
    238220////////////////////////////////////////////////////////////
    239221
    240 
    241 void MainTransferFunctionWindow::loadFile(char* fileName){
    242 
    243        
    244         if (fileName==0 || strlen(fileName)<1){
    245                 fprintf(stderr, "Error: file name not supplied.\n");
    246                 return;
    247         }
    248 
    249         FILE* fp=fopen(fileName, "r");
    250 
    251         if(!fp){
    252                 fprintf(stderr, "Error: open file.\n");
    253                 return;
    254         }
    255 
    256         fprintf(stderr, "File \"%s\" opened.\n", fileName);
    257 
    258         char buf[300];                  //buffer to store one line from file
    259         char* token;                    //pointer to token in the buffer
    260         char seps[]=" \n";              //seperators
    261 
    262 
    263         int num_of_control_point;
    264         int num_of_color_point;
    265         double control_points[200];
    266         double color_points[100];
    267         double colors[300];
    268 
    269 
    270         //clean up old control points
    271         TransferFunctionGLUTWindow::cleanUpPoints();
    272 
    273         fgets(buf, 100, fp);
    274         token=strtok(buf, seps);
    275         num_of_control_point=(int)atof(token);
    276 
    277         //read control points
    278         for(int i=0; i<num_of_control_point; i++){
    279                 fgets(buf, 100, fp);
    280                 token=strtok(buf, seps);
    281                 control_points[2*i]=atof(token)*tf_unitWidth+15;
    282                
    283                 token=strtok(NULL, seps);
    284                 control_points[2*i+1]=(atof(token)*(tf_winy-15))+15;
    285                
    286                 //add points
    287                 TransferFunctionGLUTWindow::addPoint(control_points[2*i], control_points[2*i+1]);
    288         }
    289         //rewrite the interpolatoin
    290         TransferFunctionGLUTWindow::WriteControlPoints();
    291        
    292         fgets(buf, 100, fp); //empty line
    293 
    294 
    295         fgets(buf, 100, fp);
    296         token=strtok(buf, seps);
    297         num_of_color_point=(int)atof(token);
    298 
    299 
    300         //read color points
    301         for(int i=0; i<num_of_color_point; i++){
    302                 fgets(buf, 100, fp);
    303                 token=strtok(buf, seps);
    304                 color_points[i]=atof(token)*cm_unitWidth+15;
    305         }
    306 
    307 
    308         //clean map
    309         map->cleanUp();
    310 
    311         fgets(buf, 100, fp); //empty line
    312 
    313         //read colors
    314         for(int i=0; i<num_of_color_point; i++){
    315                 fgets(buf, 100, fp);
    316                 token=strtok(buf, seps);
    317                 colors[3*i]=atof(token);
    318                
    319                 token=strtok(NULL, seps);
    320                 colors[3*i+1]=atof(token);
    321 
    322                 token=strtok(NULL, seps);
    323                 colors[3*i+2]=atof(token);
    324 
    325                 map->addKey(color_points[i], new Color(colors[3*i], colors[3*i+1], colors[3*i+2]));
    326 
    327         }
    328         //rewrite the interpolatoin
    329         ColorGradientGLUTWindow::WriteControlPoints();
    330 
    331         glutSetWindow(transferFunctionWindow);
    332         TransferFunctionGLUTWindow::tfDisplay();
    333 
    334         //read modelview settings
    335         fgets(buf, 100, fp); //empty line
    336        
    337         //camero location
    338         fgets(buf, 100, fp);
    339         token=strtok(buf, seps);
    340         //eye_shift_x=atof(token);
    341        
    342         token=strtok(NULL, seps);
    343         //eye_shift_y=atof(token);
    344 
    345         token=strtok(NULL, seps);
    346         //eyedistance=atof(token);
    347 
    348        
    349         fgets(buf, 100, fp); //empty line
    350        
    351         //object center location
    352         fgets(buf, 100, fp);
    353         token=strtok(buf, seps);
    354         //obj_center[0]=atof(token);
    355        
    356         token=strtok(NULL, seps);
    357         //obj_center[1]=atof(token);
    358 
    359         token=strtok(NULL, seps);
    360         //obj_center[2]=atof(token);
    361 
    362 
    363         fgets(buf, 100, fp); //empty line
    364        
    365         //scale and field_of_view
    366         fgets(buf, 100, fp);
    367         token=strtok(buf, seps);
    368         control_point_scale=atof(token);
    369        
    370         token=strtok(NULL, seps);
    371         //fovy=atof(token);
    372        
    373         if (colorPaletteWindow!=-1){
    374                 glutSetWindow(colorPaletteWindow);
    375                 ColorPalette::cpSyncLive();
    376         }
    377                
    378         fclose(fp);
    379        
    380         //update transfer function values
    381         if(transferFunctionWindow!=-1){
    382                 TransferFunctionGLUTWindow::WriteControlPoints();
    383         }
    384 
    385         //render the volume again.
    386         //glutSetWindow(render_window);
    387         glutPostRedisplay();
    388 }
    389 
    390 
    391 
    392 
    393 void MainTransferFunctionWindow::saveFile(char* fileName){
    394 
    395         // Check for bad param
    396         if(fileName == NULL)
    397                 return;
    398         if(strlen(fileName) < 1)
    399                 return;
    400 
    401         FILE* fp = fopen(fileName, "w");
    402 
    403         if(!fp)
    404                 return; //error
    405 
    406         fprintf(fp, "%d\n", tf_numOfPoints);
    407 
    408         ControlPoint* cur=tf_pointList;
    409 
    410         for (int i=0; i<tf_numOfPoints; i++){
    411                 fprintf(fp, "%g %g\n", ((double)(cur->x-15))/((double)tf_unitWidth), ((double)(cur->y-15))/((double)tf_winy-15));       
    412                 cur=cur->next;
    413         }
    414         fprintf(fp, "\n");
    415 
    416 
    417         fprintf(fp, "%d\n", map->numOfKeys);
    418         cur=map->keyList;
    419         for(int i=0; i<map->numOfKeys; i++){
    420                 fprintf(fp, "%g\n", ((double)(cur->x-15))/((double)cm_unitWidth));
    421                 cur=cur->next;
    422         }
    423         fprintf(fp, "\n");
    424 
    425 
    426         Color* curColor=map->keyColors;
    427         for(int i=0; i<map->numOfKeys; i++){
    428                 fprintf(fp, "%g %g %g\n", curColor->R, curColor->G, curColor->B);
    429                 curColor=curColor->next;
    430         }
    431         fprintf(fp, "\n");
    432 
    433         //eye location
    434         //fprintf(fp, "%g %g %g\n\n", eye_shift_x, eye_shift_y, eyedistance);
    435 
    436         //object center
    437         //fprintf(fp, "%g %g %g\n\n", obj_center[0], obj_center[1], obj_center[2]);
    438 
    439         //bluntfin quater
    440         //fprintf(fp, "%g %g %g %g\n\n", bluntfin_quater.s, bluntfin_quater.x, bluntfin_quater.y, bluntfin_quater.z);
    441 
    442         //scale and field_of_view
    443         //fprintf(fp, "%g %g\n", control_point_scale, fovy);
    444 
    445         fprintf(fp, "END\n");
    446        
    447         fclose(fp);
    448 }
     222void MainTransferFunctionWindow::loadFile(char* fileName)
     223{
     224    if (fileName==0 || strlen(fileName)<1) {
     225        fprintf(stderr, "Error: file name not supplied.\n");
     226        return;
     227    }
     228
     229    FILE* fp=fopen(fileName, "r");
     230
     231    if (!fp) {
     232        fprintf(stderr, "Error: open file.\n");
     233        return;
     234    }
     235
     236    fprintf(stderr, "File \"%s\" opened.\n", fileName);
     237
     238    char buf[300];                        //buffer to store one line from file
     239    char* token;                        //pointer to token in the buffer
     240    char seps[]=" \n";                //seperators
     241
     242    int num_of_control_point;
     243    int num_of_color_point;
     244    double control_points[200];
     245    double color_points[100];
     246    double colors[300];
     247
     248    //clean up old control points
     249    TransferFunctionGLUTWindow::cleanUpPoints();
     250
     251    fgets(buf, 100, fp);
     252    token=strtok(buf, seps);
     253    num_of_control_point=(int)atof(token);
     254
     255    //read control points
     256    for(int i=0; i<num_of_control_point; i++){
     257        fgets(buf, 100, fp);
     258        token=strtok(buf, seps);
     259        control_points[2*i]=atof(token)*tf_unitWidth+15;
     260               
     261        token=strtok(NULL, seps);
     262        control_points[2*i+1]=(atof(token)*(tf_winy-15))+15;
     263               
     264        //add points
     265        TransferFunctionGLUTWindow::addPoint(control_points[2*i], control_points[2*i+1]);
     266    }
     267    //rewrite the interpolatoin
     268    TransferFunctionGLUTWindow::WriteControlPoints();
     269       
     270    fgets(buf, 100, fp); //empty line
     271
     272    fgets(buf, 100, fp);
     273    token=strtok(buf, seps);
     274    num_of_color_point=(int)atof(token);
     275
     276    //read color points
     277    for(int i=0; i<num_of_color_point; i++){
     278        fgets(buf, 100, fp);
     279        token=strtok(buf, seps);
     280        color_points[i]=atof(token)*cm_unitWidth+15;
     281    }
     282
     283    //clean map
     284    map->cleanUp();
     285
     286    fgets(buf, 100, fp); //empty line
     287
     288    //read colors
     289    for(int i=0; i<num_of_color_point; i++){
     290        fgets(buf, 100, fp);
     291        token=strtok(buf, seps);
     292        colors[3*i]=atof(token);
     293               
     294        token=strtok(NULL, seps);
     295        colors[3*i+1]=atof(token);
     296
     297        token=strtok(NULL, seps);
     298        colors[3*i+2]=atof(token);
     299
     300        map->addKey(color_points[i], new Color(colors[3*i], colors[3*i+1], colors[3*i+2]));
     301
     302    }
     303    //rewrite the interpolatoin
     304    ColorGradientGLUTWindow::WriteControlPoints();
     305
     306    glutSetWindow(transferFunctionWindow);
     307    TransferFunctionGLUTWindow::tfDisplay();
     308
     309    //read modelview settings
     310    fgets(buf, 100, fp); //empty line
     311       
     312    //camero location
     313    fgets(buf, 100, fp);
     314    token=strtok(buf, seps);
     315    //eye_shift_x=atof(token);
     316       
     317    token=strtok(NULL, seps);
     318    //eye_shift_y=atof(token);
     319
     320    token=strtok(NULL, seps);
     321    //eyedistance=atof(token);
     322       
     323    fgets(buf, 100, fp); //empty line
     324       
     325    //object center location
     326    fgets(buf, 100, fp);
     327    token=strtok(buf, seps);
     328    //obj_center[0]=atof(token);
     329       
     330    token=strtok(NULL, seps);
     331    //obj_center[1]=atof(token);
     332
     333    token=strtok(NULL, seps);
     334    //obj_center[2]=atof(token);
     335
     336    fgets(buf, 100, fp); //empty line
     337       
     338    //scale and field_of_view
     339    fgets(buf, 100, fp);
     340    token=strtok(buf, seps);
     341    control_point_scale=atof(token);
     342
     343    token=strtok(NULL, seps);
     344    //fovy=atof(token);
     345
     346    if (colorPaletteWindow!=-1) {
     347        glutSetWindow(colorPaletteWindow);
     348        ColorPalette::cpSyncLive();
     349    }
     350
     351    fclose(fp);
     352       
     353    //update transfer function values
     354    if (transferFunctionWindow!=-1) {
     355        TransferFunctionGLUTWindow::WriteControlPoints();
     356    }
     357
     358    //render the volume again.
     359    //glutSetWindow(render_window);
     360    glutPostRedisplay();
     361}
     362
     363void MainTransferFunctionWindow::saveFile(char* fileName)
     364{
     365    // Check for bad param
     366    if (fileName == NULL)
     367        return;
     368    if (strlen(fileName) < 1)
     369        return;
     370
     371    FILE* fp = fopen(fileName, "w");
     372
     373    if (!fp)
     374        return; //error
     375
     376    fprintf(fp, "%d\n", tf_numOfPoints);
     377
     378    ControlPoint* cur=tf_pointList;
     379
     380    for (int i=0; i<tf_numOfPoints; i++) {
     381        fprintf(fp, "%g %g\n", ((double)(cur->x-15))/((double)tf_unitWidth), ((double)(cur->y-15))/((double)tf_winy-15));       
     382        cur=cur->next;
     383    }
     384    fprintf(fp, "\n");
     385
     386    fprintf(fp, "%d\n", map->numOfKeys);
     387    cur=map->keyList;
     388    for (int i=0; i<map->numOfKeys; i++) {
     389        fprintf(fp, "%g\n", ((double)(cur->x-15))/((double)cm_unitWidth));
     390        cur=cur->next;
     391    }
     392    fprintf(fp, "\n");
     393
     394    Color* curColor=map->keyColors;
     395    for (int i=0; i<map->numOfKeys; i++) {
     396        fprintf(fp, "%g %g %g\n", curColor->R, curColor->G, curColor->B);
     397        curColor=curColor->next;
     398    }
     399    fprintf(fp, "\n");
     400
     401    //eye location
     402    //fprintf(fp, "%g %g %g\n\n", eye_shift_x, eye_shift_y, eyedistance);
     403
     404    //object center
     405    //fprintf(fp, "%g %g %g\n\n", obj_center[0], obj_center[1], obj_center[2]);
     406
     407    //bluntfin quater
     408    //fprintf(fp, "%g %g %g %g\n\n", bluntfin_quater.s, bluntfin_quater.x, bluntfin_quater.y, bluntfin_quater.z);
     409
     410    //scale and field_of_view
     411    //fprintf(fp, "%g %g\n", control_point_scale, fovy);
     412
     413    fprintf(fp, "END\n");
     414       
     415    fclose(fp);
     416}
  • trunk/packages/vizservers/nanovis/transfer-function/MainWindow.h

    r2798 r2897  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 /*
    3  * ----------------------------------------------------------------------
    4  * MainWindow.h: implementation of the main transfer function gui window
    5  *
    6  * ======================================================================
     2/* ======================================================================
    73 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
    84 *           Purdue Rendering and Perceptualization Lab (PURPL)
     
    1410 * ======================================================================
    1511 */
    16 
    17 
    18 #ifndef _MAIN_TF_WINDOW_H
    19 #define _MAIN_TF_WINDOW_H
     12#ifndef MAIN_TF_WINDOW_H
     13#define MAIN_TF_WINDOW_H
    2014
    2115#include "glui.h"
     
    2822extern int unitWidth, unitHeight;
    2923
    30 class MainTransferFunctionWindow{
     24class MainTransferFunctionWindow
     25{
     26public:
     27    MainTransferFunctionWindow();
     28    virtual ~MainTransferFunctionWindow();
    3129
    32 public:
    33         static ControlPoint* selectPoint;
    34        
    35         static void mainMouse(int button, int state, int x, int y);
    36         static void mainMotion(int x, int y);
    37         static void mainIdle();
    38         static void mainKeyboard(unsigned char key, int x, int y);
    39         static void mainDestroy();
    40         static void mainReshape(int x, int y);
    41         static void mainDisplay();
    42         static void mainInit();
     30    static void mainMouse(int button, int state, int x, int y);
     31    static void mainMotion(int x, int y);
     32    static void mainIdle();
     33    static void mainKeyboard(unsigned char key, int x, int y);
     34    static void mainDestroy();
     35    static void mainReshape(int x, int y);
     36    static void mainDisplay();
     37    static void mainInit();
    4338
    44         static void loadFile(char* fileName);
    45         static void saveFile(char* fileName);
    46         static void  changeState(int arg);
     39    static void loadFile(char* fileName);
     40    static void saveFile(char* fileName);
     41    static void  changeState(int arg);
    4742
    48         MainTransferFunctionWindow();
    49         virtual ~MainTransferFunctionWindow(); 
    50        
     43    static ControlPoint* selectPoint;
    5144};
    5245
  • trunk/packages/vizservers/nanovis/transfer-function/TransferFunctionGLUTWindow.cpp

    r2798 r2897  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 /*
    3  * ----------------------------------------------------------------------
    4  * TransferFunctionGLUTWindow.cpp: implementation of the TransferFunctionGLUTWindow class.
    5  *
    6  * ======================================================================
     2/* ======================================================================
    73 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
    84 *           Purdue Rendering and Perceptualization Lab (PURPL)
     
    1410 * ======================================================================
    1511 */
    16 
    1712#include <assert.h>
    1813#include <stdio.h>
     
    2621#include "TransferFunctionMain.h"
    2722
    28 
    2923/****************Result Array******************/
    3024int numOfOutput=NUM_OF_OUTPUT;
    3125float* output=(float*)malloc(sizeof(float)*numOfOutput); //result array
    3226/**********************************************/
    33 
    3427
    3528//Histograms
     
    4942namespace TransferFunctionWindow
    5043{
    51 
    5244    int winx = 600;
    5345    int winy = 150;
     
    6759    float lv_tf_width_scale = 1.0;
    6860    float last_lv_tf_width_scale= 1.0;
    69 
    7061};
    7162
    7263using namespace TransferFunctionWindow;
    7364
    74 
    7565TransferFunctionGLUTWindow::TransferFunctionGLUTWindow()
    7666{
    77 
    7867}
    7968
    8069TransferFunctionGLUTWindow::~TransferFunctionGLUTWindow()
    8170{
    82 
    83 }
    84 
    85 
    86 
     71}
    8772
    8873void TransferFunctionGLUTWindow::tfInit(int main_window_x, int main_window_y)
    8974{
    90 
    9175    //initialize the global list of contorlPoint "tf_pointList"
    9276    tf_winx=main_window_x;
     
    9680    tf_unitWidth = (int)(0.95*tf_winx);
    9781
    98 
    9982    //printf("tf_unitWidth=%d\n", tf_unitWidth);
    100 
    10183
    10284    tf_pointList = new ControlPoint(15,15);
     
    10486
    10587    int i=0;
    106     for(i=0;i<numOfOutput;i++){
     88    for (i=0;i<numOfOutput;i++) {
    10789        //output[i]=0;
    10890        color_table[i][3]=0;
    109     }   
     91    }
    11092    tf_numOfPoints=2;
    11193    tf_pointEditState=0;
     
    11698}
    11799
    118 
    119 
    120 
    121100void TransferFunctionGLUTWindow::tfDisplay()
    122101{
    123 
    124102    glClearColor( 1.0f, 1.0f, 1.0f, 1.0f );
    125103    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    126 
    127104
    128105    glColor3d(0, 0, 0);
     
    145122    glRasterPos2f(18+tf_unitWidth, 2);
    146123    glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, '1');
    147 
    148124
    149125    //draw marker on axis
     
    155131    int k;
    156132    k = 1;
    157     while (15+k*unitHeight/lv_tf_height_scale < winy)
    158         {
    159             glVertex2d(20, 15+k*unitHeight/lv_tf_height_scale);
    160             glVertex2d(15, 15+k*unitHeight/lv_tf_height_scale);
    161             k++;
    162         }
     133    while (15+k*unitHeight/lv_tf_height_scale < winy) {
     134        glVertex2d(20, 15+k*unitHeight/lv_tf_height_scale);
     135        glVertex2d(15, 15+k*unitHeight/lv_tf_height_scale);
     136        k++;
     137    }
    163138    glEnd();
    164139    glLineWidth(1.0);
     
    176151          itoa(k, label, 10);
    177152          int i=0;
    178           while (label[i]!=0){
     153          while (label[i]!=0) {
    179154              glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, label[i]);
    180155              i++;
     
    185160#endif
    186161
    187 
    188162    //draw all points
    189163    ControlPoint* cur=tf_pointList;
    190     while(cur!=0){
     164    while (cur!=0) {
    191165        cur->glDraw();
    192166        cur=cur->next;
     
    195169    glEnable(GL_LINE_SMOOTH);
    196170    glLineWidth(2.0);
    197 
    198171
    199172    //connect all points
     
    202175    glVertex2d(cur->x, cur->y);
    203176
    204     while (cur!=0){
    205         if (cur->next!=0){
     177    while (cur!=0) {
     178        if (cur->next!=0) {
    206179            glVertex2d(cur->x, cur->y);
    207180            glVertex2d(cur->x, cur->y);
    208         }
    209         else
     181        } else {
    210182            glVertex2d(cur->x, cur->y);
    211         cur=cur->next;
    212     }
    213     glVertex2d(winx, 15);       
     183        }
     184        cur=cur->next;
     185    }
     186    glVertex2d(winx, 15);
    214187    glEnd();
    215188
     
    218191    plotHist();
    219192
    220     glutSwapBuffers();
    221 
    222 }
    223 
    224 
     193    glutSwapBuffers();
     194}
    225195
    226196bool TransferFunctionGLUTWindow::SelectPoint(double x, double y)
    227197{
    228198    //printf("select point\n");
    229        
     199
    230200    if (tf_numOfPoints==0)
    231201        return false;
     
    233203    //Reset selected/dragged flags
    234204    ControlPoint* cur=tf_pointList;
    235     while(cur!=0){
     205    while (cur!=0) {
    236206        cur->dragged=false;
    237207        cur->selected=false;
     
    243213    //Traverse the points and find the one that seems close
    244214    cur=tf_pointList;
    245     while(cur!=0){
     215    while (cur!=0) {
    246216        double distanceSq;
    247217        distanceSq = (cur->x - x)*(cur->x - x) + (cur->y - y)*(cur->y - y);
    248                
    249         if (distanceSq < distanceThreshold){
     218
     219        if (distanceSq < distanceThreshold) {
    250220            cur->selected = true;
    251221            tf_gvSelectedPoint = cur;
     
    257227    return false;
    258228}
    259 
    260229
    261230void TransferFunctionGLUTWindow::tfMouse(int button, int state, int x, int y)
     
    267236
    268237    glGetIntegerv(GL_VIEWPORT, viewportVector);
    269        
     238
    270239    gv_X = scX = x;
    271240    gv_Y = scY = viewportVector[3] - (GLint) y - 1;
     
    276245    bool gvIsSelected = SelectPoint(scX, scY); 
    277246
    278     if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){
    279                
    280         if (gvIsSelected && tf_pointEditState==0){
     247    if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
     248        if (gvIsSelected && tf_pointEditState==0) {
    281249            assert(tf_gvSelectedPoint!=NULL);
    282250            gv_DX = scX - tf_gvSelectedPoint->x; //Offset from current point to selected point, for dragging corrections
    283251            gv_DY = scY - tf_gvSelectedPoint->y;
    284        
     252
    285253            tf_gvSelectedPoint->dragged = true;
    286254            tf_gvIsDragging = true;
    287255        }
    288         /*else if ((!gvIsSelected) && tf_pointEditState==1){
    289           GLint viewportVector[4];
    290           double scX, scY;
    291 
    292           glGetIntegerv(GL_VIEWPORT, viewportVector);
    293 
    294           gv_X = scX = x;
    295           gv_Y = scY = viewportVector[3] - (GLint) y - 1;
    296           tf_gvSelectedPoint=addPoint(scX - gv_DX,scY - gv_DY);
    297           tf_pointEditState=0;
    298           WriteControlPoints();
    299           }*/
    300     }
    301     else if (button == GLUT_LEFT_BUTTON && state == GLUT_UP){
    302         //"     End dragging" code.
    303         tf_gvIsDragging = false;
    304         if (tf_gvSelectedPoint)
    305             tf_gvSelectedPoint->dragged = false;
    306     }
    307 
    308     if (button == GLUT_RIGHT_BUTTON && state == GLUT_UP)
    309         {
     256        /*else if ((!gvIsSelected) && tf_pointEditState==1) {
    310257            GLint viewportVector[4];
    311258            double scX, scY;
     
    318265            tf_pointEditState=0;
    319266            WriteControlPoints();
    320         }
    321 
    322 
     267        }*/
     268    } else if (button == GLUT_LEFT_BUTTON && state == GLUT_UP) {
     269        // End dragging code.
     270        tf_gvIsDragging = false;
     271        if (tf_gvSelectedPoint)
     272            tf_gvSelectedPoint->dragged = false;
     273    }
     274
     275    if (button == GLUT_RIGHT_BUTTON && state == GLUT_UP) {
     276        GLint viewportVector[4];
     277        double scX, scY;
     278
     279        glGetIntegerv(GL_VIEWPORT, viewportVector);
     280
     281        gv_X = scX = x;
     282        gv_Y = scY = viewportVector[3] - (GLint) y - 1;
     283        tf_gvSelectedPoint=addPoint(scX - gv_DX,scY - gv_DY);
     284        tf_pointEditState=0;
     285        WriteControlPoints();
     286    }
    323287       
    324288    if (button == GLUT_MIDDLE_BUTTON && state == GLUT_DOWN)
     
    331295}
    332296
    333 
    334297void TransferFunctionGLUTWindow::tfMotion(int x, int y)
    335298{
    336 
    337299    GLint viewportVector[4];
    338300    double scX, scY;
     
    343305    gv_Y = scY = viewportVector[3] - (GLint) y - 1;
    344306
    345     if (tf_gvIsDragging == true && tf_gvSelectedPoint!=NULL){
     307    if (tf_gvIsDragging == true && tf_gvSelectedPoint!=NULL) {
    346308        //Dragging handling code.
    347309        tf_gvSelectedPoint->dragged = true;
    348310
    349 
    350311        ControlPoint* cur=tf_pointList;
    351         while (cur->next!=0){
     312        while (cur->next!=0) {
    352313            cur=cur->next;
    353314        }
    354315
    355316        //update x, y values for selected point
    356         if (tf_gvSelectedPoint!=tf_pointList && tf_gvSelectedPoint!=cur){
     317        if (tf_gvSelectedPoint!=tf_pointList && tf_gvSelectedPoint!=cur) {
    357318            //not the first one, not the last one
    358319            tf_gvSelectedPoint->x = scX - gv_DX;
    359             if (tf_gvSelectedPoint->x<=15){
     320            if (tf_gvSelectedPoint->x<=15) {
    360321                tf_gvSelectedPoint->x=16;
    361             }
    362             else if(tf_gvSelectedPoint->x>=15+tf_unitWidth){
     322            } else if (tf_gvSelectedPoint->x>=15+tf_unitWidth) {
    363323                tf_gvSelectedPoint->x=15+tf_unitWidth-1;
    364324            }
    365325        }
    366326        tf_gvSelectedPoint->y = scY - gv_DY;
    367 
    368327
    369328        //Boundary conditions, so we can't drag point away from the screen.
     
    374333            tf_gvSelectedPoint->y = 15;
    375334
    376 
    377         boundaryChecking();     
    378     }
    379 
    380     if (gvScaleDragging == true){
     335        boundaryChecking();
     336    }
     337
     338    if (gvScaleDragging == true) {
    381339        last_lv_tf_height_scale=lv_tf_height_scale;
    382340        lv_tf_height_scale += (scY - gv_lastY)*0.007;
    383341        gv_lastY = scY;
    384342        scalePointsY((int)(scY - gv_lastY));
    385     }   
     343    }
    386344
    387345    WriteControlPoints();
    388346
    389     glutPostRedisplay();
    390 }
    391 
    392 void TransferFunctionGLUTWindow::tfIdle(){
     347    glutPostRedisplay();
     348}
     349
     350void TransferFunctionGLUTWindow::tfIdle()
     351{
    393352    /*
    394353      glutSetWindow(tfWinId);
     
    403362}
    404363
    405 void TransferFunctionGLUTWindow::tfKeyboard(unsigned char key, int x, int y){
    406     switch(key)
    407         {   
    408         case 'q':
    409             exit(0);
    410             break;   
    411         case 'a':
    412             tf_pointEditState=1;
    413             break;
    414         case 'd':
    415             tf_pointEditState=2;
    416             if (tf_gvSelectedPoint!=NULL){
    417                 removePoint(tf_gvSelectedPoint);
    418                 tf_gvSelectedPoint=0;
    419                 WriteControlPoints();
    420                 glutPostRedisplay();
    421             }
    422             tf_pointEditState=0;
    423             break;   
    424         case 'p':
    425             printPoints();
    426             break;
    427         case 'w':
    428             printInterpolation();
    429             break;
    430         case 'r':
    431             readHist();
    432             break;
    433         case 'u':
    434             dumpHist();
    435             break;
    436         case 'i':
    437             printHist();
    438             break;
    439 
    440         default:
    441             break;
    442         }   
    443 }
    444 
    445 
    446 void  TransferFunctionGLUTWindow::tfReshape(int x, int y){
    447 
     364void TransferFunctionGLUTWindow::tfKeyboard(unsigned char key, int x, int y)
     365{
     366    switch (key) {   
     367    case 'q':
     368        exit(0);
     369        break;   
     370    case 'a':
     371        tf_pointEditState=1;
     372        break;
     373    case 'd':
     374        tf_pointEditState=2;
     375        if (tf_gvSelectedPoint!=NULL) {
     376            removePoint(tf_gvSelectedPoint);
     377            tf_gvSelectedPoint=0;
     378            WriteControlPoints();
     379            glutPostRedisplay();
     380        }
     381        tf_pointEditState=0;
     382        break;   
     383    case 'p':
     384        printPoints();
     385        break;
     386    case 'w':
     387        printInterpolation();
     388        break;
     389    case 'r':
     390        readHist();
     391        break;
     392    case 'u':
     393        dumpHist();
     394        break;
     395    case 'i':
     396        printHist();
     397        break;
     398
     399    default:
     400        break;
     401    }   
     402}
     403
     404void  TransferFunctionGLUTWindow::tfReshape(int x, int y)
     405{
    448406    //do not accept 0 value!!!
    449407    if (x==0 || y==0)
    450408        return;
    451409
    452 
    453410    last_lv_tf_height_scale=lv_tf_height_scale;
    454411    lv_tf_height_scale=lv_tf_height_scale*y/winy;
     
    480437}
    481438
    482 
    483 
    484 
    485 
    486439void  TransferFunctionGLUTWindow::ReadControlPoints()
    487440{
     
    489442}
    490443
    491 
    492444void update_tf_texture();
    493445
    494446void TransferFunctionGLUTWindow::WriteControlPoints()
    495447{
    496        
    497448    //special case: all points have the same y coordinates
    498449    double rangeY=0;
     
    506457    int allSameY=1;
    507458    int y=(int)tf_pointList->y;
    508     while (cur!=0){
    509         if (cur->y!=y){
     459    while (cur!=0) {
     460        if (cur->y!=y) {
    510461            allSameY=0;
    511462            break;
     
    514465    }
    515466
    516        
    517     if (allSameY==1){
     467    if (allSameY==1) {
    518468        int i=0;
    519         for(i=0;i<numOfOutput;i++){
     469        for (i=0; i<numOfOutput; i++){
    520470            //output[i]=0;
    521471            color_table[i][3]=0;
     
    526476    //get max Y
    527477    cur=tf_pointList;
    528     while (cur!=0){
    529         if (cur->y>maxY){
     478    while (cur!=0) {
     479        if (cur->y>maxY) {
    530480            maxY=cur->y;
    531481        }
    532         if (cur->x>maxX){
     482        if (cur->x>maxX) {
    533483            maxX=cur->x;
    534484        }
    535485        cur=cur->next;
    536486    }
    537 
    538487
    539488    //get min Y
    540489    cur=tf_pointList;
    541490    double minY=maxY;
    542     while (cur!=0){
    543         if (cur->y<minY){
     491    while (cur!=0) {
     492        if (cur->y<minY) {
    544493            minY=cur->y;
    545494        }
     
    566515
    567516    int i=0;
    568     for(i=0;i<numOfOutput;i++){
    569                
    570         if (unitX*i+15>x2){
     517    for (i=0; i<numOfOutput; i++) {
     518        if (unitX*i+15>x2) {
    571519            //go to next line segment
    572520            cur=next;
    573521            next=next->next;
    574             if (next==0){
     522            if (next==0) {
    575523                return;
    576524            }
     
    589537    update_tf_texture();
    590538    glutSetWindow(transferFunctionWindow);
    591 }       
    592 
    593 
    594 
    595 
    596 void TransferFunctionGLUTWindow::printInterpolation(){
     539}
     540
     541void TransferFunctionGLUTWindow::printInterpolation()
     542{
    597543    WriteControlPoints();
    598544    int i=0;
    599     for(i=0;i<numOfOutput;i++){
     545    for (i=0; i<numOfOutput; i++) {
    600546        //printf("%f, ",output[i]);
    601547        fprintf(stderr, "%f, ",color_table[i][3]);
     
    603549    fprintf(stderr, "\n");
    604550}
    605 
    606 
    607551
    608552//sort all controlpoints by bubble sort
     
    622566    int i;
    623567    pre = NULL;                 /* Suppress compiler warning */
    624     for(i=0;i<tf_numOfPoints-1;i++){
    625         while (cur->next!=NULL){
    626             if (cur->x > cur->next->x){
    627                 if (cur==tf_pointList){
     568    for (i=0; i<tf_numOfPoints-1; i++) {
     569        while (cur->next!=NULL) {
     570            if (cur->x > cur->next->x) {
     571                if (cur==tf_pointList) {
    628572                    //first node
    629573                    a=tf_pointList;
     
    650594}
    651595
    652 
    653596ControlPoint*
    654597TransferFunctionGLUTWindow::addPoint(double x, double y)
     
    660603        last=last->next;
    661604    }
    662     if (x<15 || x>last->x || y<15){
     605    if (x<15 || x>last->x || y<15) {
    663606        return tf_pointList;
    664607    }
     
    668611
    669612    //if x is the first or last. Don't add, but update.
    670     if(x==cur->x) {
     613    if (x==cur->x) {
    671614        cur->y=y;
    672615        return tf_pointList;
     
    709652}
    710653
    711 
    712 
    713654void
    714655TransferFunctionGLUTWindow::removePoint(void* ptr)
     
    718659
    719660    ControlPoint* last=tf_pointList;
    720     while (last->next!=0){
     661    while (last->next!=0) {
    721662        last=last->next;
    722663    }
    723664
    724     if (ptr==tf_pointList || ptr==last){
     665    if (ptr==tf_pointList || ptr==last) {
    725666        /*
    726           if (tf_numOfPoints=1){
    727           delete(ptr);
    728           tf_pointList=0;
    729           }
    730           else{
    731           tf_pointList=tf_pointList->next;
    732           delete(ptr);
     667          if (tf_numOfPoints=1) {
     668              delete(ptr);
     669              tf_pointList=0;
     670          } else {
     671              tf_pointList=tf_pointList->next;
     672              delete(ptr);
    733673          }
    734674        */
     
    738678        ControlPoint* cur=tf_pointList;
    739679        ControlPoint* pre=cur;
    740         while (cur->next!=0){
     680        while (cur->next!=0) {
    741681            if (cur==ptr) {
    742682                break;
     
    752692}
    753693
    754 
    755694//remove all points but the two initial points
    756 void TransferFunctionGLUTWindow::cleanUpPoints(){
     695void TransferFunctionGLUTWindow::cleanUpPoints()
     696{
    757697    if (tf_numOfPoints<2)
    758698        return;
     
    760700    ControlPoint* cur=tf_pointList;
    761701
    762     if (tf_numOfPoints==2){
     702    if (tf_numOfPoints==2) {
    763703        cur->x=15;
    764704        cur->y=15;
     
    769709    }
    770710
    771 
    772711    cur=tf_pointList->next;
    773712    ControlPoint* pre=tf_pointList;
     
    783722    tf_pointList->next=cur;
    784723
    785 
    786724    tf_pointList->x=15;
    787725    tf_pointList->y=15;
    788        
     726
    789727    tf_pointList->next->x=15+tf_unitWidth;
    790728    tf_pointList->next->y=15;
     
    793731    TransferFunctionGLUTWindow::WriteControlPoints();
    794732}
    795 
    796 
    797 
    798 
    799733
    800734//debugging: print out all points
     
    809743        return;
    810744
    811     while (cur->next!=0){
     745    while (cur->next!=0) {
    812746        fprintf(stderr, "(%g,%g)\n", cur->x, cur->y);
    813747        cur=cur->next;
     
    816750    fprintf(stderr, "********************\n");
    817751}
    818 
    819752
    820753ControlPoint*
     
    829762    ControlPoint* right=tf_pointList;
    830763
    831     while (right!=tf_gvSelectedPoint){
     764    while (right!=tf_gvSelectedPoint) {
    832765        left=right;
    833766        right=right->next;
     
    835768
    836769    //selected point is not the right-end point
    837     if (right->next!=0){
     770    if (right->next!=0) {
    838771        right=right->next;
    839         if (tf_gvSelectedPoint->x>right->x){
     772        if (tf_gvSelectedPoint->x>right->x) {
    840773            sortPoints();
    841774        }
     
    852785}
    853786
    854 
    855787void
    856788TransferFunctionGLUTWindow::scalePointsY(int offset)
     
    860792
    861793    ControlPoint* cur=tf_pointList;
    862     while (cur!=0){
     794    while (cur!=0) {
    863795        cur->y=((cur->y)-offset-15)*((float)last_lv_tf_height_scale/(float)lv_tf_height_scale)+15;
    864796        cur=cur->next;
    865     }           
     797    }
    866798    WriteControlPoints();
    867799}
     
    871803{
    872804    ControlPoint* cur=tf_pointList;
    873     while (cur!=0){
     805    while (cur!=0) {
    874806        cur->x=(cur->x-15)*((float)lv_tf_width_scale/(float)last_lv_tf_width_scale)+15;
    875807        cur=cur->next;
     
    877809    WriteControlPoints();
    878810}
    879 
    880811
    881812void
     
    896827    */
    897828}
    898 
    899829
    900830void
     
    960890}
    961891
    962 
    963892void
    964893TransferFunctionGLUTWindow::plotHist()
    965894{
    966     for(int j=0; j<4; j++){
     895    for (int j=0; j<4; j++) {
    967896        Histogram cur = Hist[j];
    968897
     
    972901        unsigned long minY;
    973902        double rangeY;
    974                
     903
    975904        float result[256];
    976                 
     905 
    977906        //get max Y
    978907        maxY=0;
    979908        int i=0;
    980         for (i=0; i<cur.range; i++){
     909        for (i=0; i<cur.range; i++) {
    981910            if (cur.count[i]>maxY)
    982911                maxY=cur.count[i];
     
    984913        //printf("maxY=%d\n", maxY);
    985914
    986 
    987915        //get min Y
    988916        minY=maxY;
    989         for (i=0; i<cur.range; i++){
     917        for (i=0; i<cur.range; i++) {
    990918            if (cur.count[i]<minY)
    991919                minY=cur.count[i];
     
    999927
    1000928        //reduce all values with log then by minY
    1001         for (i=0; i<cur.range; i++){
    1002             if (cur.count[i]==0)
     929        for (i=0; i<cur.range; i++) {
     930            if (cur.count[i]==0) {
    1003931                result[i]=0;
    1004             else
     932            } else {
    1005933                //result[i]=log((double)(cur.count[i]));
    1006934                //result[i]=double(cur.count[i]);
    1007935                //result[i]=log((float)(cur.count[i]))-log((float)minY);
    1008                 result[i]=log((float)(cur.count[i])-(float)minY);       
    1009         }
    1010 
     936                result[i]=log((float)(cur.count[i])-(float)minY);
     937            }   
     938        }
    1011939
    1012940        //draw points
    1013941        glColor3d(0, 0, 1);
    1014942        glBegin(GL_LINES);
    1015         for (i=0; i<cur.range-1; i++){
     943        for (i=0; i<cur.range-1; i++) {
    1016944            glVertex2f(15+i*unitX, 15+result[i]*unitY);
    1017945            glVertex2f(15+(i+1)*unitX, 15+result[i+1]*unitY);
     
    1019947        glEnd();
    1020948        glColor3d(0, 0, 0);     
    1021 
    1022     }
    1023 }
     949    }
     950}
  • trunk/packages/vizservers/nanovis/transfer-function/TransferFunctionGLUTWindow.h

    r2798 r2897  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 /*
    3  * ----------------------------------------------------------------------
    4  * TransferFunctionGLUTWindow.h: TransferFunctionGLUTWindow class.
    5  *
    6  * ======================================================================
     2/* ======================================================================
    73 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
    84 *           Purdue Rendering and Perceptualization Lab (PURPL)
     
    1410 * ======================================================================
    1511 */
    16 
     12#ifndef TRANSFER_FUNCTION_GLUT_WINDOW_H
     13#define TRANSFER_FUNCTION_GLUT_WINDOW_H
    1714
    1815#include <stdlib.h>
     
    2118
    2219#include "ControlPoint.h"
    23 
    24 #ifndef TRANSFER_FUNCTION_GLUT_WINDOW_H
    25 #define TRANSFER_FUNCTION_GLUT_WINDOW_H
    26 
    2720
    2821////////////////////Interpolation Result/////////////////////////////////////////
     
    4134extern int transferFuctionWindow;               //global winid
    4235extern int tf_pointEditState;                   //pointEditState
    43                                                                 //if ==1, add point
    44                                                                 //if ==2, remove point
    45 struct Histogram{
     36                                                  //if ==1, add point
     37                                                  //if ==2, remove point
     38struct Histogram
     39{
     40    Histogram()
     41    {
     42        range =256;
     43        min = FLT_MAX;
     44        max = FLT_MIN;
     45        count = (unsigned long*) malloc(sizeof(unsigned long)*(range));
    4646
    47         int range;
    48         unsigned long* count;
    49         float min;
    50         float max;
     47        int i=0;
     48        for (i=0; i<range; i++){
     49            count[i]=0;
     50        }
     51    };
    5152
    52         Histogram(){
    53                 range =256;
    54                 min = FLT_MAX;
    55                 max = FLT_MIN;
    56                 count = (unsigned long*) malloc(sizeof(unsigned long)*(range));
    57 
    58                 int i=0;
    59                 for (i=0; i<range; i++){
    60                         count[i]=0;
    61                 }
    62         };
     53    int range;
     54    unsigned long* count;
     55    float min;
     56    float max;
    6357};
    6458
    6559extern Histogram Hist[4]; //s, p, d, ss histograms
    6660
    67 
    6861class TransferFunctionGLUTWindow 
    6962{
     63public:
     64    TransferFunctionGLUTWindow();
     65    virtual ~TransferFunctionGLUTWindow();
    7066
     67    void static tfInit(int main_window_x, int main_window_y);
     68    void static WriteControlPoints();
     69    void static ReadControlPoints();
    7170
    72 public:
     71    void static tfReshape(int x, int y);
     72    void static tfKeyboard(unsigned char key, int x, int y);
     73    void static tfIdle();
     74    void static tfMouse(int button, int state, int x, int y);
     75    void static tfMotion(int x, int y);
     76    void static tfDisplay();   
    7377
    74         void static tfInit(int main_window_x, int main_window_y);
    75         void static WriteControlPoints();
    76         void static ReadControlPoints();
    77        
    78         void static tfReshape(int x, int y);
    79         void static tfKeyboard(unsigned char key, int x, int y);
    80         void static tfIdle();
    81         void static tfMouse(int button, int state, int x, int y);
    82         void static tfMotion(int x, int y);
    83         void static tfDisplay();       
    84        
    85         bool static SelectPoint(double x, double y);
     78    bool static SelectPoint(double x, double y);
    8679
    87        
    88         void static sortPoints();                                                       //sort all the points by there x coordinates
    89         static ControlPoint* addPoint(double x, double y);      //add control point
    90         void static removePoint(void* ptr);                                     //remove control point
    91         void static scalePointsY(int offset);                           //scale point X
    92         void static scalePointsX();                                                     //scale point Y
    93         static ControlPoint* boundaryChecking();                        //point boundary checking
    94         void static plotHist();                                                         //draw Histogram in transformation window
    95         static void cleanUpPoints();                                            //remove all points but the two initial points
     80    void static sortPoints();                           //sort all the points by there x coordinates
     81    static ControlPoint* addPoint(double x, double y);  //add control point
     82    void static removePoint(void* ptr);                 //remove control point
     83    void static scalePointsY(int offset);               //scale point X
     84    void static scalePointsX();                         //scale point Y
     85    static ControlPoint* boundaryChecking();            //point boundary checking
     86    void static plotHist();                             //draw Histogram in transformation window
     87    static void cleanUpPoints();                        //remove all points but the two initial points
    9688
    97         void static printPoints();                                                      //debugging: print out all points
    98         void static printInterpolation();                                       //debugging: print interpolation       
    99         void static dumpHist();                                                         //dump histogram
    100         void static readHist();                                                         //read histogram
    101         void static printHist();       
    102 
    103 
    104 
    105         TransferFunctionGLUTWindow();
    106         virtual ~TransferFunctionGLUTWindow();
     89    void static printPoints();                          //debugging: print out all points
     90    void static printInterpolation();                   //debugging: print interpolation       
     91    void static dumpHist();                             //dump histogram
     92    void static readHist();                             //read histogram
     93    void static printHist();
    10794
    10895};
  • trunk/packages/vizservers/nanovis/transfer-function/TransferFunctionMain.h

    r2798 r2897  
    33#include <glui.h>
    44
    5 #ifndef __TF_MAIN_H__
    6 #define __TF_MAIN_H__
     5#ifndef TF_MAIN_H
     6#define TF_MAIN_H
    77
    88extern bool gvIsDragging;
     
    1515extern float control_point_scale;
    1616
    17 #endif // __TF_MAIN_H__
     17#endif
Note: See TracChangeset for help on using the changeset viewer.