Changeset 2897
- Timestamp:
- Mar 29, 2012, 10:55:56 PM (13 years ago)
- Location:
- trunk/packages/vizservers/nanovis/transfer-function
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/nanovis/transfer-function/ColorGradient.cpp
r2798 r2897 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * ---------------------------------------------------------------------- 4 * ColorGradient.cpp: ColorGradient class 5 * 6 * ====================================================================== 2 /* ====================================================================== 7 3 * AUTHOR: Wei Qiao <qiaow@purdue.edu> 8 4 * Purdue Rendering and Perceptualization Lab (PURPL) … … 14 10 * ====================================================================== 15 11 */ 16 17 12 #include <stdio.h> 18 13 #include <assert.h> … … 24 19 #include "TransferFunctionGLUTWindow.h" 25 20 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 } 21 ColorGradient::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 36 ColorGradient::~ColorGradient() 37 { 38 } 39 40 ControlPoint* 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 99 void 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 140 void 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 162 void 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 209 void 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); 173 243 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 273 void ColorGradient::SaveColorGradientFile(char *fileName) 274 { 275 /* 276 FILE *gradFile; 245 277 246 float *f1; 247 int NumberOfGradients; 248 int i; 278 int i; 249 279 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 295 void 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 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * ---------------------------------------------------------------------- 4 * ColorGradient.h: interface for the ColorGradient class 5 * 6 * ====================================================================== 2 /* ====================================================================== 7 3 * AUTHOR: Wei Qiao <qiaow@purdue.edu> 8 4 * Purdue Rendering and Perceptualization Lab (PURPL) … … 14 10 * ====================================================================== 15 11 */ 16 17 12 #ifndef COLOR_GRADIENT_H 18 13 #define COLOR_GRADIENT_H … … 24 19 { 25 20 public: 21 ColorGradient(); 22 virtual ~ColorGradient(); 26 23 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); 30 25 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 41 43 }; 42 44 -
trunk/packages/vizservers/nanovis/transfer-function/ColorGradientGLUTWindow.cpp
r2798 r2897 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * ---------------------------------------------------------------------- 4 * ColorGradientGLUTWindow.cpp 5 * 6 * ====================================================================== 2 /* ====================================================================== 7 3 * AUTHOR: Wei Qiao <qiaow@purdue.edu> 8 4 * Purdue Rendering and Perceptualization Lab (PURPL) … … 14 10 * ====================================================================== 15 11 */ 16 17 12 #include "TransferFunctionMain.h" 18 13 #include "ColorGradientGLUTWindow.h" 19 14 #include "ColorPaletteWindow.h" 20 15 #include "TransferFunctionGLUTWindow.h" 21 22 16 23 17 int mapNumOfOutput=MAP_NUM_OF_OUTPUT; … … 54 48 map = new ColorGradient(); 55 49 } 56 57 50 58 51 ColorGradientGLUTWindow::~ColorGradientGLUTWindow() … … 82 75 distanceThreshold=64; 83 76 84 if (mapOutput==0)77 if (mapOutput==0) 85 78 fprintf(stderr, "NULL"); 86 79 … … 92 85 } 93 86 94 95 96 87 void 97 88 ColorGradientGLUTWindow::createGLUIWidgets() 98 89 { 99 90 cm_glui = GLUI_Master.create_glui_subwindow(colorMapWindow, 100 91 GLUI_SUBWINDOW_BOTTOM); 101 92 pan=cm_glui->add_panel("buttons", GLUI_PANEL_NONE); 102 93 cm_glui->set_main_gfx_window(colorMapWindow); … … 111 102 } 112 103 113 114 104 void update_tf_texture(); 115 105 … … 148 138 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 149 139 150 151 140 int i; 152 141 153 if (map == NULL){142 if (map == NULL) { 154 143 fprintf(stderr, "ColorGradient Window : forgot to bind the colorMap\n"); 155 144 return; 156 145 } 157 158 146 159 147 Color* leftColor=map->keyColors; … … 169 157 glShadeModel(GL_SMOOTH); 170 158 glDisable(GL_DEPTH_TEST); 171 159 172 160 glBegin(GL_QUADS); 173 for (i=0; i<map->numOfKeys-1; i++){161 for (i=0; i<map->numOfKeys-1; i++) { 174 162 left_x=leftPoint->x; 175 163 leftColor->GetRGB(left_color); … … 189 177 glVertex2d(right_x, cm_winy-10); 190 178 glVertex2d(right_x, 0); 191 179 192 180 leftColor=leftColor->next; 193 181 leftPoint=leftPoint->next; 194 195 182 } 196 183 glEnd(); 197 184 glColor3f(0, 0, 0); 198 199 185 200 186 //draw bar … … 205 191 glEnd(); 206 192 207 208 193 i=0; 209 194 Color* curColor=map->keyColors; 210 195 ControlPoint* curKey=map->keyList; 211 for (i=0; i<map->numOfKeys ; i++) {196 for (i=0; i<map->numOfKeys ; i++) { 212 197 //glColor3d(curColor->R, curColor->G, curColor->B); 213 198 glColor3d(0.0, 0.0, 0.0); … … 217 202 } 218 203 219 220 204 glColor3d(0.0, 0.0, 0.0); 221 205 glutSwapBuffers(); 222 206 } 223 224 225 226 207 227 208 void … … 249 230 } 250 231 251 252 253 254 232 void 255 233 ColorGradientGLUTWindow::cmDestroy() … … 262 240 switch(key) { 263 241 case 'p': 264 265 242 //printPoints(); 243 break; 266 244 case 'c': 267 268 245 printInterpolation(); 246 break; 269 247 default: 270 248 break; 271 249 } 272 250 } … … 295 273 bool gvIsSelected = SelectPoint(scX, scY); 296 274 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) { 300 277 //assert(cm_gvSelectedPoint!=NULL); 301 278 gv_DX = scX - cm_gvSelectedPoint->x; //Offset from current point to selected point, for dragging corrections … … 304 281 cm_gvIsDragging = true; 305 282 } 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 }*/ 318 295 } else if (button == GLUT_LEFT_BUTTON && state == GLUT_UP) { 319 // " End dragging"code.296 // End dragging code. 320 297 cm_gvIsDragging = false; 321 if (cm_gvSelectedPoint) 298 if (cm_gvSelectedPoint) 322 299 cm_gvSelectedPoint->dragged = false; 323 300 } 324 301 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 } 337 313 338 314 if (button == GLUT_MIDDLE_BUTTON && state == GLUT_DOWN) 339 340 315 cm_gvScaleDragging = true; 316 341 317 if (button == GLUT_MIDDLE_BUTTON && state == GLUT_UP) 342 cm_gvScaleDragging = false; 343 344 /////////////////////////// 318 cm_gvScaleDragging = false; 319 345 320 glutSetWindow(colorMapWindow); 346 ////////////////////////347 321 glutPostRedisplay(); 348 322 } 349 350 351 323 352 324 void … … 361 333 gv_Y = scY = viewportVector[3] - (GLint) y - 1; 362 334 363 if (cm_gvIsDragging == true && cm_gvSelectedPoint!=NULL) {335 if (cm_gvIsDragging == true && cm_gvSelectedPoint!=NULL) { 364 336 //Dragging handling code. 365 337 cm_gvSelectedPoint->dragged = true; 366 367 338 368 339 ControlPoint* cur=map->keyList; … … 407 378 //Traverse the points and find the one that seems close 408 379 cur=map->keyList; 409 while (cur!=0){380 while (cur!=0) { 410 381 double distanceSq; 411 382 distanceSq = (cur->x - x)*(cur->x - x) + (cur->y - y)*(cur->y - y); … … 421 392 } 422 393 423 424 394 void update_tf_texture(); 425 395 … … 427 397 ColorGradientGLUTWindow::WriteControlPoints() 428 398 { 429 430 399 //special case: all points have the same color 431 400 Color* curColor=map->keyColors; … … 434 403 double G = map->keyColors->G; 435 404 double B = map->keyColors->B; 436 while (curColor!=0) {405 while (curColor!=0) { 437 406 if (curColor->R!=R || curColor->G!=G || curColor->B!=B){ 438 407 allSameY=false; … … 442 411 } 443 412 444 if (allSameY) {413 if (allSameY) { 445 414 int i=0; 446 447 for (i=0;i<mapNumOfOutput;i++){415 416 for (i=0;i<mapNumOfOutput;i++) { 448 417 color_table[i][0]=R; 449 418 color_table[i][1]=G; … … 475 444 476 445 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) { 480 448 //go to next line segment 481 449 curColor=nextColor; … … 499 467 g2=nextColor->G*255; 500 468 b2=nextColor->B*255; 501 502 469 } 503 470 t=((float)(unit*i+15-x1))/((float)(x2-x1)); … … 512 479 } 513 480 514 515 481 ControlPoint* 516 482 ColorGradientGLUTWindow::boundaryChecking() … … 522 488 ControlPoint* right=map->keyList; 523 489 524 while (right!=cm_gvSelectedPoint) {490 while (right!=cm_gvSelectedPoint) { 525 491 left=right; 526 492 right=right->next; … … 530 496 if (right->next!=0){ 531 497 right=right->next; 532 if (cm_gvSelectedPoint->x>right->x) {498 if (cm_gvSelectedPoint->x>right->x) { 533 499 sortPoints(); 534 500 } … … 537 503 //selected point is not the left-end point 538 504 if (left!=cm_gvSelectedPoint) { 539 if (cm_gvSelectedPoint->x<left->x) {505 if (cm_gvSelectedPoint->x<left->x) { 540 506 sortPoints(); 541 507 } … … 544 510 return cm_gvSelectedPoint; 545 511 } 546 547 512 548 513 //sort all controlpoints by bubble sort … … 566 531 curColor=map->keyColors; 567 532 568 preColor = NULL; /* Suppress compiler warning. */533 preColor = NULL; 569 534 pre = NULL; 570 535 571 536 int i; 572 for (i=0;i<map->numOfKeys-1;i++){537 for (i=0;i<map->numOfKeys-1;i++) { 573 538 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) { 576 541 //first node 577 542 a=map->keyList; … … 588 553 map->keyColors=d; 589 554 curColor=map->keyColors; 590 } 591 else { 555 } else { 592 556 a=cur; 593 557 b=cur->next; … … 617 581 } 618 582 619 620 621 583 void 622 584 ColorGradientGLUTWindow::printInterpolation() 623 585 { 624 586 int i=0; 625 for (i=0;i<numOfOutput;i++){587 for (i=0;i<numOfOutput;i++) { 626 588 //printf("(%g,%g,%g) ", mapOutput[3*i], mapOutput[3*i+1], mapOutput[3*i+2]); 627 589 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 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * ---------------------------------------------------------------------- 4 * ColorGradientGLUTWindow.h 5 * 6 * ====================================================================== 2 /* ====================================================================== 7 3 * AUTHOR: Wei Qiao <qiaow@purdue.edu> 8 4 * Purdue Rendering and Perceptualization Lab (PURPL) … … 14 10 * ====================================================================== 15 11 */ 16 17 18 12 #ifndef COLOR_GRADIENT_GLUT_WINDOW_H 19 13 #define COLOR_GRADIENT_GLUT_WINDOW_H 20 21 14 22 15 #include <glui.h> 23 16 #include "ColorGradient.h" 24 17 #include "ControlPoint.h" 25 26 18 27 19 extern int cm_winx, cm_winy; //size of the subwindow … … 31 23 32 24 extern ControlPoint* cm_gvSelectedPoint; //current selected color controlpoint 33 34 25 35 26 ///////Color Map Interpolation Result////////////////////////////// … … 41 32 extern GLUI *cm_glui; 42 33 43 44 34 class ColorGradientGLUTWindow 45 35 { 46 36 public: 37 ColorGradientGLUTWindow(); 38 virtual ~ColorGradientGLUTWindow(); 47 39 48 49 50 51 52 53 54 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(); 55 47 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(); 69 56 }; 70 57 -
trunk/packages/vizservers/nanovis/transfer-function/ColorPaletteWindow.cpp
r2798 r2897 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * ---------------------------------------------------------------------- 4 * ColorPaletteWindow.cpp: color palette window class 5 * 6 * ====================================================================== 2 /* ====================================================================== 7 3 * AUTHOR: Wei Qiao <qiaow@purdue.edu> 8 4 * Purdue Rendering and Perceptualization Lab (PURPL) … … 14 10 * ====================================================================== 15 11 */ 16 17 12 #include <math.h> 18 13 … … 33 28 GLUI_StaticText *eye_distance_label, *fps_label; 34 29 35 36 30 namespace ColorPaletteWindow { 37 31 int cpwin_pos_x = 100; … … 48 42 using namespace ColorPaletteWindow; 49 43 50 51 52 44 ColorPalette::ColorPalette() 53 45 { … … 60 52 void ColorPalette::cpSyncLive() 61 53 { 62 if (cp_glui!=0) {54 if (cp_glui!=0) { 63 55 cp_glui->sync_live(); 64 56 } … … 70 62 71 63 //fileName=(char*) malloc(sizeof(char)*30); 72 for (int i=0;i<200;i++){64 for (int i=0;i<200;i++) { 73 65 fileName[i]=0; 74 66 } … … 82 74 glutInitWindowPosition( cpwin_pos_x, cpwin_pos_y); 83 75 glutInitWindowSize( cp_winx, cp_winy ); 84 76 85 77 colorPaletteWindow = glutCreateWindow("Color Palette"); 86 78 … … 92 84 glutMotionFunc (cpMotion); 93 85 94 95 86 GLUI_Master.set_glutReshapeFunc(cpReshape); 96 87 GLUI_Master.set_glutDisplayFunc( cpDisplay ); … … 103 94 } 104 95 105 106 96 void update_tf_texture(); 107 97 108 void ColorPalette::cmdHandler(int arg){ 109 switch (arg){ 98 void ColorPalette::cmdHandler(int arg) 99 { 100 switch (arg) { 110 101 case 1: //add color 111 102 cm_editState=1; … … 137 128 break; 138 129 case 8: 139 if (color_model==0) {130 if (color_model==0) { 140 131 color_r->enable(); 141 132 color_g->enable(); … … 153 144 cp_color_S=0; 154 145 cp_color_B=0; 155 146 156 147 color_point_1->x=0; 157 148 color_point_1->y=cp_winy; 158 149 159 150 cp_glui->sync_live(); 160 } 161 else if (color_model==1){ 151 } else if (color_model==1) { 162 152 color_r->enable(); 163 153 color_g->enable(); … … 180 170 181 171 cp_glui->sync_live(); 182 } 183 else if (color_model==2){ 172 } else if (color_model==2) { 184 173 color_r->enable(); 185 174 color_g->enable(); … … 205 194 cp_glui->sync_live(); 206 195 } 207 196 208 197 glutSetWindow(colorPaletteWindow); 209 198 glutPostRedisplay(); … … 213 202 case 10: 214 203 break; 215 216 204 default: 217 205 break; … … 219 207 } 220 208 221 222 void ColorPalette::openFile(){ 223 224 } 225 226 227 228 229 void ColorPalette::createGLUIWidgets(){ 209 void ColorPalette::openFile() 210 { 211 } 212 213 void ColorPalette::createGLUIWidgets() 214 { 230 215 cp_glui = GLUI_Master.create_glui_subwindow(colorPaletteWindow, GLUI_SUBWINDOW_BOTTOM); 231 216 cp_glui->set_main_gfx_window(colorPaletteWindow); … … 256 241 color_B->disable(); 257 242 258 259 243 cp_glui->add_column(true); 260 244 … … 275 259 cp_glui->add_button("Reset TF", 7, cmdHandler); 276 260 277 278 261 cp_glui->add_column(true); 279 262 cp_glui->add_statictext("File:"); … … 288 271 } 289 272 290 291 void ColorPalette::cpIdle(){273 void ColorPalette::cpIdle() 274 { 292 275 //glutSetWindow(mainWindow); 293 276 //glutPostRedisplay(); 294 277 } 295 278 296 297 298 299 void ColorPalette::confirm(int arg){ 279 void ColorPalette::confirm(int arg) 280 { 300 281 if (cm_gvSelectedPoint!=0) 301 282 map->changeColor((double)cp_color_r/255, (double)cp_color_g/255, (double)cp_color_b/255); … … 308 289 } 309 290 310 311 312 291 void ColorPalette::cpDisplay() 313 292 { … … 317 296 glClearColor( 1.0f, 1.0f, 1.0f, 1.0f ); 318 297 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 319 320 298 321 299 glColor3d(0.0, 0.0, 0.0); … … 323 301 glDisable(GL_DEPTH_TEST); 324 302 325 326 if (color_model==RGB){ 327 303 if (color_model==RGB) { 328 304 Color* leftColor = new Color(1, 0, 0); 329 305 Color* rightColor = new Color(0, 0, 1); … … 336 312 337 313 GLfloat rainbowColor[18] = { 338 339 340 314 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1 315 }; 316 341 317 int i=0; 342 318 float unitWidth = cp_winx/6; 343 319 344 320 glBegin(GL_QUADS); 345 for (i=0; i<6; i++) {321 for (i=0; i<6; i++) { 346 322 347 323 glColor3f(rainbowColor[3*i], rainbowColor[3*i+1], rainbowColor[3*i+2]); … … 349 325 glVertex2d(unitWidth*i, cp_winy); 350 326 351 if (i==5) {327 if (i==5) { 352 328 glColor3f(rainbowColor[0], rainbowColor[1], rainbowColor[2]); 353 329 glVertex2d(cp_winx, cp_winy); 354 330 glVertex2d(cp_winx, 0); 355 } 356 else { 331 } else { 357 332 glColor3f(rainbowColor[3*i+3], rainbowColor[3*i+4], rainbowColor[3*i+5]); 358 333 glVertex2d(unitWidth*(i+1), cp_winy); … … 365 340 glColor3d(0,0,0); 366 341 color_point_1->glDraw_3(); 367 } 368 369 else if (color_model==GRAY){ 342 } else if (color_model==GRAY) { 370 343 glBegin(GL_QUADS); 371 344 glColor3f(0, 0, 0); … … 380 353 glColor3d(1,0,0); 381 354 color_point_1->glDraw_3(); 382 } 383 384 else if(color_model==HSB){ 385 355 } else if(color_model==HSB) { 386 356 glBegin(GL_QUADS); 387 357 glColor3f(0, 0, 0); … … 407 377 408 378 GLfloat rainbowColor[18] = { 409 410 411 379 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1 380 }; 381 412 382 int i=0; 413 383 float unitWidth = cp_winx/6; 414 384 415 385 glBegin(GL_QUADS); 416 for (i=0; i<6; i++){ 417 386 for (i=0; i<6; i++) { 418 387 glColor3f(rainbowColor[3*i], rainbowColor[3*i+1], rainbowColor[3*i+2]); 419 388 glVertex2d(unitWidth*i, 2*cp_winy/3-15); … … 424 393 glVertex2d(cp_winx, 2*cp_winy/3); 425 394 glVertex2d(cp_winx, 2*cp_winy/3-15); 426 } 427 else { 395 } else { 428 396 glColor3f(rainbowColor[3*i+3], rainbowColor[3*i+4], rainbowColor[3*i+5]); 429 397 glVertex2d(unitWidth*(i+1), 2*cp_winy/3); … … 459 427 } 460 428 */ 461 462 429 } 463 430 … … 466 433 } 467 434 468 469 470 471 void ColorPalette::cpReshape(int x, int y){ 435 void ColorPalette::cpReshape(int x, int y) 436 { 472 437 //printf("cpreshape=%d",x); 473 438 … … 490 455 } 491 456 492 493 457 void ColorPalette::cpKeyboard(unsigned char key, int x, int y) 494 458 { 495 459 //glutPostRedisplay(); 496 460 } 497 498 499 461 500 462 void ColorPalette::cpMouse(int button, int state, int x, int y){ … … 507 469 scX = x; 508 470 scY = viewportVector[3] - (GLint) y - 1; 509 510 471 511 472 if (color_model!=HSB){ 512 473 color_point_1->x=scX; 513 474 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) { 517 477 color_point_1->x=scX; 518 478 color_point_1->y=scY; 519 479 getColor(scX, scY); 520 480 } 521 if (scY<2*cp_winy/3) {481 if (scY<2*cp_winy/3) { 522 482 color_point_2->x=scX; 523 483 //color_point_1->x=0; … … 528 488 //printf("(%g, %g)\n", scX, scY); 529 489 530 531 if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){ 490 if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { 532 491 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 } 537 496 538 497 cp_glui->sync_live(); 539 498 glutPostRedisplay(); 540 541 } 542 543 544 545 void ColorPalette::cpMotion(int x, int y){ } 546 547 499 } 500 501 void ColorPalette::cpMotion(int x, int y) 502 { 503 } 548 504 549 505 //interpolate GRB color 550 Color ColorPalette::getColor(double x, double y){ 551 if (color_model==RGB){ 506 Color ColorPalette::getColor(double x, double y) 507 { 508 if (color_model==RGB) { 552 509 float unitWidth = cp_winx/6; 553 510 GLfloat rainbowColor[21] = {1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0}; … … 574 531 cp_glui->sync_live(); 575 532 return Color(r,g,b); 576 } 577 578 else if (color_model==GRAY){ 533 } else if (color_model==GRAY) { 579 534 float t=((float)x)/((float)cp_winx); 580 535 double r, g, b; … … 589 544 cp_glui->sync_live(); 590 545 return Color(r,g,b); 591 } 592 593 else if (color_model==HSB){ 546 } else if (color_model==HSB) { 594 547 double r, g, b; 595 if (y==color_point_2->y) {548 if (y==color_point_2->y) { 596 549 float unitWidth = cp_winx/6; 597 550 GLfloat rainbowColor[21] = {1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0}; … … 606 559 int blue_left = (int)rainbowColor[3*pos+2]; 607 560 int blue_right = (int)rainbowColor[3*(pos+1)+2]; 608 609 561 610 562 r = (red_left+(x/unitWidth-pos)*(red_right-red_left)); … … 617 569 hue_color->G=g; 618 570 hue_color->B=b; 619 620 } 621 else{ 571 } else { 622 572 cp_color_S=(int)(100.0*(1-(double)color_point_1->x/(double)cp_winx)); 623 573 cp_color_B=(int)(100.0*((double)(color_point_1->y-(double)(2*cp_winy/3))/((double)cp_winy/3))); … … 646 596 647 597 cp_glui->sync_live(); 648 598 649 599 return Color(r,g,b); 650 600 } -
trunk/packages/vizservers/nanovis/transfer-function/ColorPaletteWindow.h
r2798 r2897 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * ---------------------------------------------------------------------- 4 * ColorPaletteWindow.h: color palette window class 5 * 6 * ====================================================================== 2 /* ====================================================================== 7 3 * AUTHOR: Wei Qiao <qiaow@purdue.edu> 8 4 * Purdue Rendering and Perceptualization Lab (PURPL) … … 14 10 * ====================================================================== 15 11 */ 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 19 14 20 15 //ColorPalette Window to select color from … … 28 23 extern GLUI* cp_glui; //glui handler 29 24 30 class ColorPalette{ 25 class ColorPalette 26 { 27 public: 28 ColorPalette(); 29 virtual ~ColorPalette(); 31 30 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(); 42 40 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(); 51 46 }; 52 47 -
trunk/packages/vizservers/nanovis/transfer-function/ControlPoint.cpp
r2798 r2897 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * ---------------------------------------------------------------------- 4 * ControlPoint.h 5 * 6 * ====================================================================== 2 /* ====================================================================== 7 3 * AUTHOR: Wei Qiao <qiaow@purdue.edu> 8 4 * Purdue Rendering and Perceptualization Lab (PURPL) … … 14 10 * ====================================================================== 15 11 */ 16 17 12 #include <math.h> 18 13 #include "TransferFunctionMain.h" 19 14 #include "ControlPoint.h" 20 15 21 22 16 ControlPoint::ControlPoint(double _x, double _y) 23 17 { 24 25 18 x = _x; 19 y = _y; 26 20 27 28 29 30 21 selected = false; 22 dragged = false; 23 24 next = 0; 31 25 } 32 26 … … 38 32 void ControlPoint::glDraw() 39 33 { 40 41 34 //Here is the code for drawing a vertex 35 double size = 4; 42 36 43 44 45 37 glMatrixMode( GL_MODELVIEW ); 38 glPushMatrix(); 39 glTranslatef( x, y, 0 ); 46 40 47 41 glBegin(GL_LINES); 48 42 49 50 43 glVertex2d(-size, -size); 44 glVertex2d(+size, +size); 51 45 52 53 54 55 46 glVertex2d(-size, +size); 47 glVertex2d(+size, -size); 48 49 glEnd(); 56 50 57 51 //Special code for drawing selected vertex and dragged vertex. 58 52 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(); 71 64 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(); 84 75 85 86 76 } 77 glPopMatrix(); 87 78 88 79 } 89 80 90 91 92 81 void ControlPoint::glDraw_2() 93 82 { 94 95 83 //Here is the code for drawing a vertex 84 double size = 4; 96 85 97 98 99 86 glMatrixMode( GL_MODELVIEW ); 87 glPushMatrix(); 88 glTranslatef( x, y, 0 ); 100 89 101 102 103 104 105 glVertex2d(+size, 0); 106 90 glBegin(GL_POLYGON); 91 glVertex2d(-size, 0); 92 glVertex2d(-size, -size); 93 glVertex2d(+size, -size); 94 glVertex2d(+size, 0); 95 glEnd(); 107 96 108 97 //Special code for drawing selected vertex and dragged vertex. 109 98 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(); 138 122 139 123 } 140 124 141 142 125 void ControlPoint::glDraw_3() 143 126 { 144 145 127 //Here is the code for drawing a vertex 128 double size = 7; 146 129 147 148 149 130 glMatrixMode( GL_MODELVIEW ); 131 glPushMatrix(); 132 glTranslatef( x, y, 0 ); 150 133 151 134 glBegin(GL_LINES); 152 135 153 154 136 glVertex2d(-2, 0); 137 glVertex2d(-size, 0); 155 138 156 157 139 glVertex2d(2, 0); 140 glVertex2d(size, 0); 158 141 159 142 160 161 143 glVertex2d(0, -2); 144 glVertex2d(0, -size); 162 145 163 164 146 glVertex2d(0, 2); 147 glVertex2d(0, size); 165 148 166 149 glEnd(); 167 150 168 169 glPopMatrix(); 170 151 glPopMatrix(); 171 152 } 172 173 174 153 175 154 void ControlPoint::Set(double x, double y) 176 155 { 177 178 156 this->x = x; 157 this->y = y; 179 158 } -
trunk/packages/vizservers/nanovis/transfer-function/ControlPoint.h
r2798 r2897 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * ---------------------------------------------------------------------- 4 * ControlPoint.h 5 * 6 * ====================================================================== 2 /* ====================================================================== 7 3 * AUTHOR: Wei Qiao <qiaow@purdue.edu> 8 4 * Purdue Rendering and Perceptualization Lab (PURPL) … … 14 10 * ====================================================================== 15 11 */ 12 #ifndef CONTROL_POINT_H 13 #define CONTROL_POINT_H 16 14 17 #ifndef _CONTROL_POINT_H_ 18 #define _CONTROL_POINT_H_ 19 20 class ControlPoint 15 class ControlPoint 21 16 { 22 17 public: 23 24 double x; 25 double y; 18 ControlPoint(double _x, double _y); 19 virtual ~ControlPoint(); 26 20 27 bool selected; 28 bool dragged; 21 void Set(double x, double y); 29 22 30 ControlPoint * next; 23 void glDraw(); //draw a cross 31 24 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 39 26 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; 40 36 }; 41 37 -
trunk/packages/vizservers/nanovis/transfer-function/MainWindow.cpp
r2798 r2897 1 1 /* -*- 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 /* ====================================================================== 7 3 * AUTHOR: Wei Qiao <qiaow@purdue.edu> 8 4 * Purdue Rendering and Perceptualization Lab (PURPL) … … 35 31 MainTransferFunctionWindow::~MainTransferFunctionWindow(){} 36 32 37 38 33 //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 { 34 void 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 84 void MainTransferFunctionWindow::mainDisplay() 85 { 86 glutSetWindow(transferFunctionWindow); 87 glutPostRedisplay(); 88 glutSetWindow(colorMapWindow); 89 glutPostRedisplay(); 90 glutSetWindow(colorPaletteWindow); 91 glutPostRedisplay(); 92 } 93 94 void 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 105 void MainTransferFunctionWindow::mainMotion(int x, int y) 106 { 107 //////////////////////////////////////// 108 //glutSetWindow(transferFunctionWindow); 109 //TransferFunctionGLUTWindow::tfMotion(x, y); 110 ///////////////////////////////////// 111 } 112 113 void 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 127 void MainTransferFunctionWindow::mainKeyboard(unsigned char key, int x, int y) 128 { 129 switch(key) { 145 130 case 'q': 146 147 131 exit(0); 132 break; 148 133 case 'a': 149 150 151 134 glutSetWindow(transferFunctionWindow); 135 tf_pointEditState=1; 136 break; 152 137 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; 181 165 } 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 168 void MainTransferFunctionWindow::mainDestroy() 169 { 170 } 171 172 void 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 } 218 200 219 201 ////////////////////////////////////////////////////////// … … 238 220 //////////////////////////////////////////////////////////// 239 221 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 } 222 void 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 363 void 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 1 1 /* -*- 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 /* ====================================================================== 7 3 * AUTHOR: Wei Qiao <qiaow@purdue.edu> 8 4 * Purdue Rendering and Perceptualization Lab (PURPL) … … 14 10 * ====================================================================== 15 11 */ 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 20 14 21 15 #include "glui.h" … … 28 22 extern int unitWidth, unitHeight; 29 23 30 class MainTransferFunctionWindow{ 24 class MainTransferFunctionWindow 25 { 26 public: 27 MainTransferFunctionWindow(); 28 virtual ~MainTransferFunctionWindow(); 31 29 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(); 43 38 44 45 46 39 static void loadFile(char* fileName); 40 static void saveFile(char* fileName); 41 static void changeState(int arg); 47 42 48 MainTransferFunctionWindow(); 49 virtual ~MainTransferFunctionWindow(); 50 43 static ControlPoint* selectPoint; 51 44 }; 52 45 -
trunk/packages/vizservers/nanovis/transfer-function/TransferFunctionGLUTWindow.cpp
r2798 r2897 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * ---------------------------------------------------------------------- 4 * TransferFunctionGLUTWindow.cpp: implementation of the TransferFunctionGLUTWindow class. 5 * 6 * ====================================================================== 2 /* ====================================================================== 7 3 * AUTHOR: Wei Qiao <qiaow@purdue.edu> 8 4 * Purdue Rendering and Perceptualization Lab (PURPL) … … 14 10 * ====================================================================== 15 11 */ 16 17 12 #include <assert.h> 18 13 #include <stdio.h> … … 26 21 #include "TransferFunctionMain.h" 27 22 28 29 23 /****************Result Array******************/ 30 24 int numOfOutput=NUM_OF_OUTPUT; 31 25 float* output=(float*)malloc(sizeof(float)*numOfOutput); //result array 32 26 /**********************************************/ 33 34 27 35 28 //Histograms … … 49 42 namespace TransferFunctionWindow 50 43 { 51 52 44 int winx = 600; 53 45 int winy = 150; … … 67 59 float lv_tf_width_scale = 1.0; 68 60 float last_lv_tf_width_scale= 1.0; 69 70 61 }; 71 62 72 63 using namespace TransferFunctionWindow; 73 64 74 75 65 TransferFunctionGLUTWindow::TransferFunctionGLUTWindow() 76 66 { 77 78 67 } 79 68 80 69 TransferFunctionGLUTWindow::~TransferFunctionGLUTWindow() 81 70 { 82 83 } 84 85 86 71 } 87 72 88 73 void TransferFunctionGLUTWindow::tfInit(int main_window_x, int main_window_y) 89 74 { 90 91 75 //initialize the global list of contorlPoint "tf_pointList" 92 76 tf_winx=main_window_x; … … 96 80 tf_unitWidth = (int)(0.95*tf_winx); 97 81 98 99 82 //printf("tf_unitWidth=%d\n", tf_unitWidth); 100 101 83 102 84 tf_pointList = new ControlPoint(15,15); … … 104 86 105 87 int i=0; 106 for (i=0;i<numOfOutput;i++){88 for (i=0;i<numOfOutput;i++) { 107 89 //output[i]=0; 108 90 color_table[i][3]=0; 109 } 91 } 110 92 tf_numOfPoints=2; 111 93 tf_pointEditState=0; … … 116 98 } 117 99 118 119 120 121 100 void TransferFunctionGLUTWindow::tfDisplay() 122 101 { 123 124 102 glClearColor( 1.0f, 1.0f, 1.0f, 1.0f ); 125 103 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 126 127 104 128 105 glColor3d(0, 0, 0); … … 145 122 glRasterPos2f(18+tf_unitWidth, 2); 146 123 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, '1'); 147 148 124 149 125 //draw marker on axis … … 155 131 int k; 156 132 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 } 163 138 glEnd(); 164 139 glLineWidth(1.0); … … 176 151 itoa(k, label, 10); 177 152 int i=0; 178 while (label[i]!=0) {153 while (label[i]!=0) { 179 154 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, label[i]); 180 155 i++; … … 185 160 #endif 186 161 187 188 162 //draw all points 189 163 ControlPoint* cur=tf_pointList; 190 while (cur!=0){164 while (cur!=0) { 191 165 cur->glDraw(); 192 166 cur=cur->next; … … 195 169 glEnable(GL_LINE_SMOOTH); 196 170 glLineWidth(2.0); 197 198 171 199 172 //connect all points … … 202 175 glVertex2d(cur->x, cur->y); 203 176 204 while (cur!=0) {205 if (cur->next!=0) {177 while (cur!=0) { 178 if (cur->next!=0) { 206 179 glVertex2d(cur->x, cur->y); 207 180 glVertex2d(cur->x, cur->y); 208 } 209 else 181 } else { 210 182 glVertex2d(cur->x, cur->y); 211 cur=cur->next; 212 } 213 glVertex2d(winx, 15); 183 } 184 cur=cur->next; 185 } 186 glVertex2d(winx, 15); 214 187 glEnd(); 215 188 … … 218 191 plotHist(); 219 192 220 glutSwapBuffers(); 221 222 } 223 224 193 glutSwapBuffers(); 194 } 225 195 226 196 bool TransferFunctionGLUTWindow::SelectPoint(double x, double y) 227 197 { 228 198 //printf("select point\n"); 229 199 230 200 if (tf_numOfPoints==0) 231 201 return false; … … 233 203 //Reset selected/dragged flags 234 204 ControlPoint* cur=tf_pointList; 235 while (cur!=0){205 while (cur!=0) { 236 206 cur->dragged=false; 237 207 cur->selected=false; … … 243 213 //Traverse the points and find the one that seems close 244 214 cur=tf_pointList; 245 while (cur!=0){215 while (cur!=0) { 246 216 double distanceSq; 247 217 distanceSq = (cur->x - x)*(cur->x - x) + (cur->y - y)*(cur->y - y); 248 249 if (distanceSq < distanceThreshold) {218 219 if (distanceSq < distanceThreshold) { 250 220 cur->selected = true; 251 221 tf_gvSelectedPoint = cur; … … 257 227 return false; 258 228 } 259 260 229 261 230 void TransferFunctionGLUTWindow::tfMouse(int button, int state, int x, int y) … … 267 236 268 237 glGetIntegerv(GL_VIEWPORT, viewportVector); 269 238 270 239 gv_X = scX = x; 271 240 gv_Y = scY = viewportVector[3] - (GLint) y - 1; … … 276 245 bool gvIsSelected = SelectPoint(scX, scY); 277 246 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) { 281 249 assert(tf_gvSelectedPoint!=NULL); 282 250 gv_DX = scX - tf_gvSelectedPoint->x; //Offset from current point to selected point, for dragging corrections 283 251 gv_DY = scY - tf_gvSelectedPoint->y; 284 252 285 253 tf_gvSelectedPoint->dragged = true; 286 254 tf_gvIsDragging = true; 287 255 } 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) { 310 257 GLint viewportVector[4]; 311 258 double scX, scY; … … 318 265 tf_pointEditState=0; 319 266 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 } 323 287 324 288 if (button == GLUT_MIDDLE_BUTTON && state == GLUT_DOWN) … … 331 295 } 332 296 333 334 297 void TransferFunctionGLUTWindow::tfMotion(int x, int y) 335 298 { 336 337 299 GLint viewportVector[4]; 338 300 double scX, scY; … … 343 305 gv_Y = scY = viewportVector[3] - (GLint) y - 1; 344 306 345 if (tf_gvIsDragging == true && tf_gvSelectedPoint!=NULL) {307 if (tf_gvIsDragging == true && tf_gvSelectedPoint!=NULL) { 346 308 //Dragging handling code. 347 309 tf_gvSelectedPoint->dragged = true; 348 310 349 350 311 ControlPoint* cur=tf_pointList; 351 while (cur->next!=0) {312 while (cur->next!=0) { 352 313 cur=cur->next; 353 314 } 354 315 355 316 //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) { 357 318 //not the first one, not the last one 358 319 tf_gvSelectedPoint->x = scX - gv_DX; 359 if (tf_gvSelectedPoint->x<=15) {320 if (tf_gvSelectedPoint->x<=15) { 360 321 tf_gvSelectedPoint->x=16; 361 } 362 else if(tf_gvSelectedPoint->x>=15+tf_unitWidth){ 322 } else if (tf_gvSelectedPoint->x>=15+tf_unitWidth) { 363 323 tf_gvSelectedPoint->x=15+tf_unitWidth-1; 364 324 } 365 325 } 366 326 tf_gvSelectedPoint->y = scY - gv_DY; 367 368 327 369 328 //Boundary conditions, so we can't drag point away from the screen. … … 374 333 tf_gvSelectedPoint->y = 15; 375 334 376 377 boundaryChecking(); 378 } 379 380 if (gvScaleDragging == true){ 335 boundaryChecking(); 336 } 337 338 if (gvScaleDragging == true) { 381 339 last_lv_tf_height_scale=lv_tf_height_scale; 382 340 lv_tf_height_scale += (scY - gv_lastY)*0.007; 383 341 gv_lastY = scY; 384 342 scalePointsY((int)(scY - gv_lastY)); 385 } 343 } 386 344 387 345 WriteControlPoints(); 388 346 389 glutPostRedisplay(); 390 } 391 392 void TransferFunctionGLUTWindow::tfIdle(){ 347 glutPostRedisplay(); 348 } 349 350 void TransferFunctionGLUTWindow::tfIdle() 351 { 393 352 /* 394 353 glutSetWindow(tfWinId); … … 403 362 } 404 363 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 364 void 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 404 void TransferFunctionGLUTWindow::tfReshape(int x, int y) 405 { 448 406 //do not accept 0 value!!! 449 407 if (x==0 || y==0) 450 408 return; 451 409 452 453 410 last_lv_tf_height_scale=lv_tf_height_scale; 454 411 lv_tf_height_scale=lv_tf_height_scale*y/winy; … … 480 437 } 481 438 482 483 484 485 486 439 void TransferFunctionGLUTWindow::ReadControlPoints() 487 440 { … … 489 442 } 490 443 491 492 444 void update_tf_texture(); 493 445 494 446 void TransferFunctionGLUTWindow::WriteControlPoints() 495 447 { 496 497 448 //special case: all points have the same y coordinates 498 449 double rangeY=0; … … 506 457 int allSameY=1; 507 458 int y=(int)tf_pointList->y; 508 while (cur!=0) {509 if (cur->y!=y) {459 while (cur!=0) { 460 if (cur->y!=y) { 510 461 allSameY=0; 511 462 break; … … 514 465 } 515 466 516 517 if (allSameY==1){ 467 if (allSameY==1) { 518 468 int i=0; 519 for (i=0;i<numOfOutput;i++){469 for (i=0; i<numOfOutput; i++){ 520 470 //output[i]=0; 521 471 color_table[i][3]=0; … … 526 476 //get max Y 527 477 cur=tf_pointList; 528 while (cur!=0) {529 if (cur->y>maxY) {478 while (cur!=0) { 479 if (cur->y>maxY) { 530 480 maxY=cur->y; 531 481 } 532 if (cur->x>maxX) {482 if (cur->x>maxX) { 533 483 maxX=cur->x; 534 484 } 535 485 cur=cur->next; 536 486 } 537 538 487 539 488 //get min Y 540 489 cur=tf_pointList; 541 490 double minY=maxY; 542 while (cur!=0) {543 if (cur->y<minY) {491 while (cur!=0) { 492 if (cur->y<minY) { 544 493 minY=cur->y; 545 494 } … … 566 515 567 516 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) { 571 519 //go to next line segment 572 520 cur=next; 573 521 next=next->next; 574 if (next==0) {522 if (next==0) { 575 523 return; 576 524 } … … 589 537 update_tf_texture(); 590 538 glutSetWindow(transferFunctionWindow); 591 } 592 593 594 595 596 void TransferFunctionGLUTWindow::printInterpolation(){ 539 } 540 541 void TransferFunctionGLUTWindow::printInterpolation() 542 { 597 543 WriteControlPoints(); 598 544 int i=0; 599 for (i=0;i<numOfOutput;i++){545 for (i=0; i<numOfOutput; i++) { 600 546 //printf("%f, ",output[i]); 601 547 fprintf(stderr, "%f, ",color_table[i][3]); … … 603 549 fprintf(stderr, "\n"); 604 550 } 605 606 607 551 608 552 //sort all controlpoints by bubble sort … … 622 566 int i; 623 567 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) { 628 572 //first node 629 573 a=tf_pointList; … … 650 594 } 651 595 652 653 596 ControlPoint* 654 597 TransferFunctionGLUTWindow::addPoint(double x, double y) … … 660 603 last=last->next; 661 604 } 662 if (x<15 || x>last->x || y<15) {605 if (x<15 || x>last->x || y<15) { 663 606 return tf_pointList; 664 607 } … … 668 611 669 612 //if x is the first or last. Don't add, but update. 670 if (x==cur->x) {613 if (x==cur->x) { 671 614 cur->y=y; 672 615 return tf_pointList; … … 709 652 } 710 653 711 712 713 654 void 714 655 TransferFunctionGLUTWindow::removePoint(void* ptr) … … 718 659 719 660 ControlPoint* last=tf_pointList; 720 while (last->next!=0) {661 while (last->next!=0) { 721 662 last=last->next; 722 663 } 723 664 724 if (ptr==tf_pointList || ptr==last) {665 if (ptr==tf_pointList || ptr==last) { 725 666 /* 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); 733 673 } 734 674 */ … … 738 678 ControlPoint* cur=tf_pointList; 739 679 ControlPoint* pre=cur; 740 while (cur->next!=0) {680 while (cur->next!=0) { 741 681 if (cur==ptr) { 742 682 break; … … 752 692 } 753 693 754 755 694 //remove all points but the two initial points 756 void TransferFunctionGLUTWindow::cleanUpPoints(){ 695 void TransferFunctionGLUTWindow::cleanUpPoints() 696 { 757 697 if (tf_numOfPoints<2) 758 698 return; … … 760 700 ControlPoint* cur=tf_pointList; 761 701 762 if (tf_numOfPoints==2) {702 if (tf_numOfPoints==2) { 763 703 cur->x=15; 764 704 cur->y=15; … … 769 709 } 770 710 771 772 711 cur=tf_pointList->next; 773 712 ControlPoint* pre=tf_pointList; … … 783 722 tf_pointList->next=cur; 784 723 785 786 724 tf_pointList->x=15; 787 725 tf_pointList->y=15; 788 726 789 727 tf_pointList->next->x=15+tf_unitWidth; 790 728 tf_pointList->next->y=15; … … 793 731 TransferFunctionGLUTWindow::WriteControlPoints(); 794 732 } 795 796 797 798 799 733 800 734 //debugging: print out all points … … 809 743 return; 810 744 811 while (cur->next!=0) {745 while (cur->next!=0) { 812 746 fprintf(stderr, "(%g,%g)\n", cur->x, cur->y); 813 747 cur=cur->next; … … 816 750 fprintf(stderr, "********************\n"); 817 751 } 818 819 752 820 753 ControlPoint* … … 829 762 ControlPoint* right=tf_pointList; 830 763 831 while (right!=tf_gvSelectedPoint) {764 while (right!=tf_gvSelectedPoint) { 832 765 left=right; 833 766 right=right->next; … … 835 768 836 769 //selected point is not the right-end point 837 if (right->next!=0) {770 if (right->next!=0) { 838 771 right=right->next; 839 if (tf_gvSelectedPoint->x>right->x) {772 if (tf_gvSelectedPoint->x>right->x) { 840 773 sortPoints(); 841 774 } … … 852 785 } 853 786 854 855 787 void 856 788 TransferFunctionGLUTWindow::scalePointsY(int offset) … … 860 792 861 793 ControlPoint* cur=tf_pointList; 862 while (cur!=0) {794 while (cur!=0) { 863 795 cur->y=((cur->y)-offset-15)*((float)last_lv_tf_height_scale/(float)lv_tf_height_scale)+15; 864 796 cur=cur->next; 865 } 797 } 866 798 WriteControlPoints(); 867 799 } … … 871 803 { 872 804 ControlPoint* cur=tf_pointList; 873 while (cur!=0) {805 while (cur!=0) { 874 806 cur->x=(cur->x-15)*((float)lv_tf_width_scale/(float)last_lv_tf_width_scale)+15; 875 807 cur=cur->next; … … 877 809 WriteControlPoints(); 878 810 } 879 880 811 881 812 void … … 896 827 */ 897 828 } 898 899 829 900 830 void … … 960 890 } 961 891 962 963 892 void 964 893 TransferFunctionGLUTWindow::plotHist() 965 894 { 966 for (int j=0; j<4; j++){895 for (int j=0; j<4; j++) { 967 896 Histogram cur = Hist[j]; 968 897 … … 972 901 unsigned long minY; 973 902 double rangeY; 974 903 975 904 float result[256]; 976 905 977 906 //get max Y 978 907 maxY=0; 979 908 int i=0; 980 for (i=0; i<cur.range; i++) {909 for (i=0; i<cur.range; i++) { 981 910 if (cur.count[i]>maxY) 982 911 maxY=cur.count[i]; … … 984 913 //printf("maxY=%d\n", maxY); 985 914 986 987 915 //get min Y 988 916 minY=maxY; 989 for (i=0; i<cur.range; i++) {917 for (i=0; i<cur.range; i++) { 990 918 if (cur.count[i]<minY) 991 919 minY=cur.count[i]; … … 999 927 1000 928 //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) { 1003 931 result[i]=0; 1004 else932 } else { 1005 933 //result[i]=log((double)(cur.count[i])); 1006 934 //result[i]=double(cur.count[i]); 1007 935 //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 } 1011 939 1012 940 //draw points 1013 941 glColor3d(0, 0, 1); 1014 942 glBegin(GL_LINES); 1015 for (i=0; i<cur.range-1; i++) {943 for (i=0; i<cur.range-1; i++) { 1016 944 glVertex2f(15+i*unitX, 15+result[i]*unitY); 1017 945 glVertex2f(15+(i+1)*unitX, 15+result[i+1]*unitY); … … 1019 947 glEnd(); 1020 948 glColor3d(0, 0, 0); 1021 1022 } 1023 } 949 } 950 } -
trunk/packages/vizservers/nanovis/transfer-function/TransferFunctionGLUTWindow.h
r2798 r2897 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * ---------------------------------------------------------------------- 4 * TransferFunctionGLUTWindow.h: TransferFunctionGLUTWindow class. 5 * 6 * ====================================================================== 2 /* ====================================================================== 7 3 * AUTHOR: Wei Qiao <qiaow@purdue.edu> 8 4 * Purdue Rendering and Perceptualization Lab (PURPL) … … 14 10 * ====================================================================== 15 11 */ 16 12 #ifndef TRANSFER_FUNCTION_GLUT_WINDOW_H 13 #define TRANSFER_FUNCTION_GLUT_WINDOW_H 17 14 18 15 #include <stdlib.h> … … 21 18 22 19 #include "ControlPoint.h" 23 24 #ifndef TRANSFER_FUNCTION_GLUT_WINDOW_H25 #define TRANSFER_FUNCTION_GLUT_WINDOW_H26 27 20 28 21 ////////////////////Interpolation Result///////////////////////////////////////// … … 41 34 extern int transferFuctionWindow; //global winid 42 35 extern 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 38 struct 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)); 46 46 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 }; 51 52 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; 63 57 }; 64 58 65 59 extern Histogram Hist[4]; //s, p, d, ss histograms 66 60 67 68 61 class TransferFunctionGLUTWindow 69 62 { 63 public: 64 TransferFunctionGLUTWindow(); 65 virtual ~TransferFunctionGLUTWindow(); 70 66 67 void static tfInit(int main_window_x, int main_window_y); 68 void static WriteControlPoints(); 69 void static ReadControlPoints(); 71 70 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(); 73 77 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); 86 79 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 96 88 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(); 107 94 108 95 }; -
trunk/packages/vizservers/nanovis/transfer-function/TransferFunctionMain.h
r2798 r2897 3 3 #include <glui.h> 4 4 5 #ifndef __TF_MAIN_H__6 #define __TF_MAIN_H__5 #ifndef TF_MAIN_H 6 #define TF_MAIN_H 7 7 8 8 extern bool gvIsDragging; … … 15 15 extern float control_point_scale; 16 16 17 #endif // __TF_MAIN_H__17 #endif
Note: See TracChangeset
for help on using the changeset viewer.