Changeset 953
- Timestamp:
- Mar 12, 2008, 3:48:06 PM (16 years ago)
- Location:
- trunk/vizservers/nanovis
- Files:
-
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/vizservers/nanovis/BucketSort.cpp
r821 r953 3 3 using namespace PCA; 4 4 5 void BucketSort::init() 5 void 6 BucketSort::init() 6 7 { 7 8 8 _count = 0; 9 memset(_buffer, 0, sizeof(ClusterList*) * _size); 9 10 } 10 11 11 void BucketSort::sort(ClusterAccel* clusterAccel, const Mat4x4& cameraMat, int level) 12 void 13 BucketSort::sort(ClusterAccel* clusterAccel, const Mat4x4& cameraMat, int level) 12 14 { 13 if (clusterAccel == 0) return; 15 if (clusterAccel == 0) { 16 return; 17 } 18 Cluster* cluster = clusterAccel->startPointerCluster[level - 1]; 19 Cluster* c = &(cluster[0]); 20 Cluster* end = &(cluster[clusterAccel->numOfClusters[level - 1] - 1]); 14 21 15 Cluster* cluster = clusterAccel->startPointerCluster[level - 1]; 16 Cluster* c = &(cluster[0]); 17 Cluster* end = &(cluster[clusterAccel->numOfClusters[level - 1] - 1]); 22 Vector3 pos; 23 for (; c <= end; c = (Cluster*) ((int) c + sizeof(Cluster))) { 24 pos.transform(c->centroid, cameraMat); 25 addBucket(c, pos.length()*_invMaxLength); 26 } 27 } 18 28 19 Vector3 pos; 20 int count = clusterAccel->numOfClusters[level - 1]; 21 22 for (; c <= end; c = (Cluster*) ((int) c + sizeof(Cluster))) 23 { 24 pos.transform(c->centroid, cameraMat); 25 addBucket(c, pos.length()*_invMaxLength); 26 } 27 } 28 29 void BucketSort::addBucket(Cluster* cluster, float ratio) 29 void 30 BucketSort::addBucket(Cluster* cluster, float ratio) 30 31 { 31 32 33 34 35 32 int index = (int) (ratio * _size); 33 ClusterList* c = &(_memChunck[_count++]); 34 c->data = cluster; 35 c->next =_buffer[index]; 36 _buffer[index] = c; 36 37 } 37 38 -
trunk/vizservers/nanovis/ContourLineFilter.cpp
r780 r953 13 13 14 14 ContourLineFilter::ContourLineFilter() 15 : _colorMap(0) 16 { 17 } 18 19 void ContourLineFilter::clear() 20 { 21 22 ContourLineFilter::ContourLineList::iterator iter; 23 for (iter = _lines.begin(); iter != _lines.end(); ++iter) 24 { 25 delete (*iter); 26 } 27 28 _lines.clear(); 29 } 30 31 R2Geometry* ContourLineFilter::create(float min, float max, int linecount, Vector3* vertices, int width, int height) 32 { 33 _lines.clear(); 34 35 float transtion = (max - min) / (linecount + 1); 36 37 float val; 38 int totalNumOfPoints = 0, numOfPoints; 39 for (int i = 1; i <= linecount; ++i) 40 { 41 val = min + i * transtion; 42 43 ContourLine* c = new ContourLine(val); 44 if(numOfPoints = c->createLine(width, height, vertices)) 45 { 46 totalNumOfPoints += numOfPoints; 47 _lines.push_back(c); 48 } 49 else 50 delete c; 51 } 52 53 Vector3* vertexSet = (Vector3*) malloc(sizeof(Vector3) * totalNumOfPoints); 54 Vector3* colorSet = 0; 55 if (_colorMap) 56 { 57 colorSet = (Vector3*) malloc(sizeof(Vector3) * totalNumOfPoints); 58 } 59 60 ContourLineFilter::ContourLineList::iterator iter; 61 int index = 0, colorIndex = 0; 62 for (iter = _lines.begin(); iter != _lines.end(); ++iter, ++colorIndex) 63 { 64 std::list<Vector3>& lines = (*iter)->_points; 65 std::list<Vector3>::iterator iter2; 66 for (iter2 = lines.begin(); iter2 != lines.end(); ++iter2, ++index) 67 { 68 if (_colorMap && (colorIndex < _colorMap->size())) 69 { 70 colorSet[index] = _colorMap->at(colorIndex); 71 } 72 else 73 { 74 //colorSet[index].set((*iter)->_value, (*iter)->_value, (*iter)->_value); 75 } 76 vertexSet[index] = (*iter2); 77 } 78 } 79 80 R2VertexBuffer* vertexBuffer = new R2VertexBuffer(R2VertexBuffer::POSITION3, totalNumOfPoints, 81 totalNumOfPoints * sizeof(Vector3), vertexSet, false); 82 R2VertexBuffer* colorBuffer = 0; 83 R2Geometry* geometry = 0; 84 if (_colorMap) 85 { 86 colorBuffer = new R2VertexBuffer(R2VertexBuffer::COLOR4, totalNumOfPoints, 87 totalNumOfPoints * sizeof(Vector3), colorSet, false); 88 } 89 90 geometry = new R2Geometry(R2Geometry::LINES, vertexBuffer, colorBuffer, 0); 91 92 clear(); 93 94 return geometry; 95 } 96 97 R2Geometry* ContourLineFilter::create(float min, float max, int linecount, Vector4* vertices, int width, int height) 98 { 99 _lines.clear(); 100 101 float transtion = (max - min) / (linecount + 1); 102 103 float val; 104 int totalNumOfPoints = 0, numOfPoints; 105 for (int i = 1; i <= linecount; ++i) 106 { 107 val = min + i * transtion; 108 109 ContourLine* c = new ContourLine(val); 110 if(numOfPoints = c->createLine(width, height, vertices)) 111 { 112 totalNumOfPoints += numOfPoints; 113 _lines.push_back(c); 114 } 115 else 116 delete c; 117 } 118 119 Vector3* vertexSet = (Vector3*) malloc(sizeof(Vector3) * totalNumOfPoints); 120 Vector3* colorSet = (Vector3*) malloc(sizeof(Vector3) * totalNumOfPoints); 121 122 ContourLineFilter::ContourLineList::iterator iter; 123 int index = 0, colorIndex = 0; 124 for (iter = _lines.begin(); iter != _lines.end(); ++iter, ++colorIndex) 125 { 126 std::list<Vector3>& lines = (*iter)->_points; 127 std::list<Vector3>::iterator iter2; 128 for (iter2 = lines.begin(); iter2 != lines.end(); ++iter2, ++index) 129 { 130 if (_colorMap && (colorIndex < _colorMap->size())) 131 { 132 colorSet[index] = _colorMap->at(colorIndex); 133 } 134 else 135 { 136 colorSet[index].set((*iter)->_value, (*iter)->_value, (*iter)->_value); 137 } 138 vertexSet[index] = (*iter2); 139 } 140 } 141 142 R2VertexBuffer* vertexBuffer = new R2VertexBuffer(R2VertexBuffer::POSITION3, totalNumOfPoints, 143 totalNumOfPoints * sizeof(Vector3), vertexSet, false); 144 R2VertexBuffer* colorBuffer = new R2VertexBuffer(R2VertexBuffer::COLOR4, totalNumOfPoints, 145 totalNumOfPoints * sizeof(Vector3), colorSet, false); 146 R2Geometry* geometry = new R2Geometry(R2Geometry::LINES, vertexBuffer, colorBuffer, 0); 147 148 clear(); 149 150 return geometry; 15 : _colorMap(0) 16 { 17 } 18 19 void 20 ContourLineFilter::clear() 21 { 22 23 ContourLineFilter::ContourLineList::iterator iter; 24 for (iter = _lines.begin(); iter != _lines.end(); ++iter) { 25 delete (*iter); 26 } 27 _lines.clear(); 28 } 29 30 R2Geometry* 31 ContourLineFilter::create(float min, float max, int linecount, 32 Vector3* vertices, int width, int height) 33 { 34 _lines.clear(); 35 36 float transtion = (max - min) / (linecount + 1); 37 38 float val; 39 int totalNumOfPoints = 0, numOfPoints; 40 for (int i = 1; i <= linecount; ++i) { 41 val = min + i * transtion; 42 43 ContourLine* c = new ContourLine(val); 44 numOfPoints = c->createLine(width, height, vertices); 45 if (numOfPoints != 0) { 46 totalNumOfPoints += numOfPoints; 47 _lines.push_back(c); 48 } else { 49 delete c; 50 } 51 } 52 53 Vector3* vertexSet = (Vector3*) malloc(sizeof(Vector3) * totalNumOfPoints); 54 Vector3* colorSet = 0; 55 if (_colorMap) { 56 colorSet = (Vector3*) malloc(sizeof(Vector3) * totalNumOfPoints); 57 } 58 59 ContourLineFilter::ContourLineList::iterator iter; 60 unsigned int index = 0, colorIndex = 0; 61 for (iter = _lines.begin(); iter != _lines.end(); ++iter, ++colorIndex) { 62 std::list<Vector3>& lines = (*iter)->_points; 63 std::list<Vector3>::iterator iter2; 64 for (iter2 = lines.begin(); iter2 != lines.end(); ++iter2, ++index) { 65 if (_colorMap && (colorIndex < _colorMap->size())) { 66 colorSet[index] = _colorMap->at(colorIndex); 67 } else { 68 //colorSet[index].set((*iter)->_value, (*iter)->_value, (*iter)->_value); 69 } 70 vertexSet[index] = (*iter2); 71 } 72 } 73 74 R2VertexBuffer* vertexBuffer; 75 vertexBuffer = new R2VertexBuffer(R2VertexBuffer::POSITION3, 76 totalNumOfPoints, 77 totalNumOfPoints * sizeof(Vector3), 78 vertexSet, false); 79 R2VertexBuffer* colorBuffer = 0; 80 R2Geometry* geometry = 0; 81 if (_colorMap) { 82 colorBuffer = new R2VertexBuffer(R2VertexBuffer::COLOR4, 83 totalNumOfPoints, 84 totalNumOfPoints * sizeof(Vector3), 85 colorSet, false); 86 } 87 88 geometry = new R2Geometry(R2Geometry::LINES, vertexBuffer, colorBuffer, 0); 89 clear(); 90 return geometry; 91 } 92 93 R2Geometry* 94 ContourLineFilter::create(float min, float max, int linecount, 95 Vector4* vertices, int width, int height) 96 { 97 _lines.clear(); 98 99 float transtion = (max - min) / (linecount + 1); 100 101 float val; 102 int totalNumOfPoints = 0, numOfPoints; 103 for (int i = 1; i <= linecount; ++i) { 104 val = min + i * transtion; 105 106 ContourLine* c = new ContourLine(val); 107 numOfPoints = c->createLine(width, height, vertices); 108 if (numOfPoints != 0) { 109 totalNumOfPoints += numOfPoints; 110 _lines.push_back(c); 111 } else { 112 delete c; 113 } 114 } 115 Vector3* vertexSet = (Vector3*) malloc(sizeof(Vector3) * totalNumOfPoints); 116 Vector3* colorSet = (Vector3*) malloc(sizeof(Vector3) * totalNumOfPoints); 117 118 ContourLineFilter::ContourLineList::iterator iter; 119 unsigned int index = 0, colorIndex = 0; 120 for (iter = _lines.begin(); iter != _lines.end(); ++iter, ++colorIndex) { 121 std::list<Vector3>& lines = (*iter)->_points; 122 std::list<Vector3>::iterator iter2; 123 for (iter2 = lines.begin(); iter2 != lines.end(); ++iter2, ++index) { 124 if (_colorMap && (colorIndex < _colorMap->size())) { 125 colorSet[index] = _colorMap->at(colorIndex); 126 } else { 127 colorSet[index].set((*iter)->_value, (*iter)->_value, 128 (*iter)->_value); 129 } 130 vertexSet[index] = (*iter2); 131 } 132 } 133 R2VertexBuffer* vertexBuffer; 134 vertexBuffer = new R2VertexBuffer(R2VertexBuffer::POSITION3, 135 totalNumOfPoints, 136 totalNumOfPoints * sizeof(Vector3), 137 vertexSet, false); 138 R2VertexBuffer* colorBuffer; 139 colorBuffer = new R2VertexBuffer(R2VertexBuffer::COLOR4, totalNumOfPoints, 140 totalNumOfPoints * sizeof(Vector3), 141 colorSet, false); 142 R2Geometry* geometry; 143 geometry = new R2Geometry(R2Geometry::LINES, vertexBuffer, colorBuffer, 0); 144 clear(); 145 return geometry; 151 146 } 152 147 153 148 154 149 ContourLineFilter::ContourLine::ContourLine(float value) 155 : _value(value) 156 { 157 } 158 159 160 int ContourLineFilter::ContourLine::createLine(int width, int height, Vector3* vertices) 161 { 162 _points.clear(); 163 164 int hl = height - 1; 165 int wl = width - 1; 166 int index1, index2, index3, index4; 167 for (int i = 0; i < hl; ++i) 168 { 169 for (int j = 0; j < wl; ++j) 170 { 171 index1 = j + i * width; 172 index2 = j + 1 + i * width; 173 index3 = j + 1 + (i + 1) * width; 174 index4 = j + (i + 1) * width; 175 176 if (isValueWithIn(vertices[index1].y, vertices[index2].y)) getContourPoint(index1, index2, vertices, width); 177 if (isValueWithIn(vertices[index2].y, vertices[index3].y)) getContourPoint(index2, index3, vertices, width); 178 if (isValueWithIn(vertices[index3].y, vertices[index1].y)) getContourPoint(index3, index1, vertices, width); 179 180 if (isValueWithIn(vertices[index1].y, vertices[index3].y)) getContourPoint(index1, index3, vertices, width); 181 if (isValueWithIn(vertices[index3].y, vertices[index4].y)) getContourPoint(index3, index4, vertices, width); 182 if (isValueWithIn(vertices[index4].y, vertices[index1].y)) getContourPoint(index4, index1, vertices, width); 183 } 184 } 185 186 return _points.size(); 187 } 188 189 190 int ContourLineFilter::ContourLine::createLine(int width, int height, Vector4* vertices) 191 { 192 _points.clear(); 193 194 int hl = height - 1; 195 int wl = width - 1; 196 int index1, index2, index3, index4; 197 for (int i = 0; i < hl; ++i) 198 { 199 for (int j = 0; j < wl; ++j) 200 { 201 index1 = j + i * width; 202 index2 = j + 1 + i * width; 203 index3 = j + 1 + (i + 1) * width; 204 index4 = j + (i + 1) * width; 205 206 if (isValueWithIn(vertices[index1].y, vertices[index2].y)) getContourPoint(index1, index2, vertices, width); 207 if (isValueWithIn(vertices[index2].y, vertices[index3].y)) getContourPoint(index2, index3, vertices, width); 208 if (isValueWithIn(vertices[index3].y, vertices[index1].y)) getContourPoint(index3, index1, vertices, width); 209 210 if (isValueWithIn(vertices[index1].y, vertices[index3].y)) getContourPoint(index1, index3, vertices, width); 211 if (isValueWithIn(vertices[index3].y, vertices[index4].y)) getContourPoint(index3, index4, vertices, width); 212 if (isValueWithIn(vertices[index4].y, vertices[index1].y)) getContourPoint(index4, index1, vertices, width); 213 } 214 } 215 216 return _points.size(); 217 } 218 219 bool ContourLineFilter::ContourLine::isValueWithIn(float val1, float Val2) 220 { 221 return (_value >= val1 && _value <= Val2) || (_value >= Val2 && _value <= val1); 222 } 223 224 void ContourLineFilter::ContourLine::getContourPoint(int vertexIndex1, int vertexIndex2, Vector3* vertices, int width) 225 { 226 float diff = vertices[vertexIndex2].y - vertices[vertexIndex1].y; 227 float t = 0.0; 228 if (diff != 0) 229 { 230 t = (_value - vertices[vertexIndex1].y) / diff; 231 } 232 233 Vector3 p; 234 p.x = vertices[vertexIndex1].x + t * (vertices[vertexIndex2].x - vertices[vertexIndex1].x); 235 p.y = vertices[vertexIndex1].y + t * (vertices[vertexIndex2].y - vertices[vertexIndex1].y); 236 p.z = vertices[vertexIndex1].z + t * (vertices[vertexIndex2].z - vertices[vertexIndex1].z); 237 238 _points.push_back(p); 239 } 240 241 void ContourLineFilter::ContourLine::getContourPoint(int vertexIndex1, int vertexIndex2, Vector4* vertices, int width) 242 { 243 float diff = vertices[vertexIndex2].y - vertices[vertexIndex1].y; 244 float t = 0.0; 245 if (diff != 0) 246 { 247 t = (_value - vertices[vertexIndex1].y) / diff; 248 } 249 250 Vector3 p; 251 p.x = vertices[vertexIndex1].x + t * (vertices[vertexIndex2].x - vertices[vertexIndex1].x); 252 p.y = vertices[vertexIndex1].y + t * (vertices[vertexIndex2].y - vertices[vertexIndex1].y); 253 p.z = vertices[vertexIndex1].z + t * (vertices[vertexIndex2].z - vertices[vertexIndex1].z); 254 255 _points.push_back(p); 256 } 257 258 259 void ContourLineFilter::setColorMap(Vector3Array* colorMap) 260 { 261 if (colorMap == _colorMap) return; 262 263 if (colorMap && _colorMap) 264 { 265 if (colorMap->size() != _colorMap->size()) 266 { 267 _colorMap->resize(_colorMap->size()); 268 } 269 _colorMap->assign(colorMap->begin(), colorMap->end()); 270 } 271 else 272 { 273 delete _colorMap; 274 275 if (colorMap && colorMap->size()) 276 { 277 _colorMap = new Vector3Array(colorMap->size()); 278 _colorMap->assign(colorMap->begin(), colorMap->end()); 279 } 280 else 281 { 282 _colorMap = 0; 283 } 284 } 285 } 150 : _value(value) 151 { 152 } 153 154 155 int 156 ContourLineFilter::ContourLine::createLine(int width, int height, 157 Vector3* vertices) 158 { 159 _points.clear(); 160 161 int hl = height - 1; 162 int wl = width - 1; 163 int index1, index2, index3, index4; 164 for (int i = 0; i < hl; ++i) { 165 for (int j = 0; j < wl; ++j) { 166 index1 = j + i * width; 167 index2 = j + 1 + i * width; 168 index3 = j + 1 + (i + 1) * width; 169 index4 = j + (i + 1) * width; 170 171 if (isValueWithIn(vertices[index1].y, vertices[index2].y)) 172 getContourPoint(index1, index2, vertices, width); 173 if (isValueWithIn(vertices[index2].y, vertices[index3].y)) 174 getContourPoint(index2, index3, vertices, width); 175 if (isValueWithIn(vertices[index3].y, vertices[index1].y)) 176 getContourPoint(index3, index1, vertices, width); 177 178 if (isValueWithIn(vertices[index1].y, vertices[index3].y)) 179 getContourPoint(index1, index3, vertices, width); 180 if (isValueWithIn(vertices[index3].y, vertices[index4].y)) 181 getContourPoint(index3, index4, vertices, width); 182 if (isValueWithIn(vertices[index4].y, vertices[index1].y)) 183 getContourPoint(index4, index1, vertices, width); 184 } 185 } 186 return _points.size(); 187 } 188 189 190 int 191 ContourLineFilter::ContourLine::createLine(int width, int height, 192 Vector4* vertices) 193 { 194 _points.clear(); 195 196 int hl = height - 1; 197 int wl = width - 1; 198 int index1, index2, index3, index4; 199 for (int i = 0; i < hl; ++i) { 200 for (int j = 0; j < wl; ++j) { 201 index1 = j + i * width; 202 index2 = j + 1 + i * width; 203 index3 = j + 1 + (i + 1) * width; 204 index4 = j + (i + 1) * width; 205 206 if (isValueWithIn(vertices[index1].y, vertices[index2].y)) 207 getContourPoint(index1, index2, vertices, width); 208 if (isValueWithIn(vertices[index2].y, vertices[index3].y)) 209 getContourPoint(index2, index3, vertices, width); 210 if (isValueWithIn(vertices[index3].y, vertices[index1].y)) 211 getContourPoint(index3, index1, vertices, width); 212 213 if (isValueWithIn(vertices[index1].y, vertices[index3].y)) 214 getContourPoint(index1, index3, vertices, width); 215 if (isValueWithIn(vertices[index3].y, vertices[index4].y)) 216 getContourPoint(index3, index4, vertices, width); 217 if (isValueWithIn(vertices[index4].y, vertices[index1].y)) 218 getContourPoint(index4, index1, vertices, width); 219 } 220 } 221 222 return _points.size(); 223 } 224 225 bool 226 ContourLineFilter::ContourLine::isValueWithIn(float val1, float Val2) 227 { 228 return ((_value >= val1 && _value <= Val2) || 229 (_value >= Val2 && _value <= val1)); 230 } 231 232 void 233 ContourLineFilter::ContourLine::getContourPoint(int vertexIndex1, 234 int vertexIndex2, Vector3* vertices, int width) 235 { 236 float diff = vertices[vertexIndex2].y - vertices[vertexIndex1].y; 237 float t = 0.0; 238 if (diff != 0) { 239 t = (_value - vertices[vertexIndex1].y) / diff; 240 } 241 242 Vector3 p; 243 p.x = vertices[vertexIndex1].x + t * 244 (vertices[vertexIndex2].x - vertices[vertexIndex1].x); 245 p.y = vertices[vertexIndex1].y + t * 246 (vertices[vertexIndex2].y - vertices[vertexIndex1].y); 247 p.z = vertices[vertexIndex1].z + t * 248 (vertices[vertexIndex2].z - vertices[vertexIndex1].z); 249 _points.push_back(p); 250 } 251 252 void 253 ContourLineFilter::ContourLine::getContourPoint(int vertexIndex1, 254 int vertexIndex2, Vector4* vertices, int width) 255 { 256 float diff = vertices[vertexIndex2].y - vertices[vertexIndex1].y; 257 float t = 0.0; 258 if (diff != 0) { 259 t = (_value - vertices[vertexIndex1].y) / diff; 260 } 261 262 Vector3 p; 263 p.x = vertices[vertexIndex1].x + 264 t * (vertices[vertexIndex2].x - vertices[vertexIndex1].x); 265 p.y = vertices[vertexIndex1].y + 266 t * (vertices[vertexIndex2].y - vertices[vertexIndex1].y); 267 p.z = vertices[vertexIndex1].z + 268 t * (vertices[vertexIndex2].z - vertices[vertexIndex1].z); 269 _points.push_back(p); 270 } 271 272 273 void 274 ContourLineFilter::setColorMap(Vector3Array* colorMap) 275 { 276 if (colorMap == _colorMap) { 277 return; 278 } 279 if (colorMap && _colorMap) { 280 if (colorMap->size() != _colorMap->size()) { 281 _colorMap->resize(_colorMap->size()); 282 } 283 _colorMap->assign(colorMap->begin(), colorMap->end()); 284 } else { 285 delete _colorMap; 286 287 if (colorMap && colorMap->size()) { 288 _colorMap = new Vector3Array(colorMap->size()); 289 _colorMap->assign(colorMap->begin(), colorMap->end()); 290 } else { 291 _colorMap = 0; 292 } 293 } 294 } -
trunk/vizservers/nanovis/GradientFilter.cpp
r931 r953 51 51 52 52 53 static void saveFloatGradients(float *gradients, int *sizes) 53 #ifdef notused 54 static void 55 saveFloatGradients(float *gradients, int *sizes) 54 56 { 55 57 char *filename; … … 61 63 exit(1); 62 64 } 63 64 65 if (fwrite(gradients, 3 * sizes[0] * sizes[1] * sizes[2] * sizeof(float), 65 66 1, fp) != 1) { … … 67 68 exit(1); 68 69 } 69 70 70 fclose(fp); 71 71 } 72 73 74 int getNextPowerOfTwo(int n) 72 #endif 73 74 int 75 getNextPowerOfTwo(int n) 75 76 { 76 77 int i; -
trunk/vizservers/nanovis/Grid.cpp
r932 r953 22 22 glPushMatrix(); 23 23 glEnable(GL_DEPTH_TEST); 24 glDisable(GL_TEXTURE_2D); 25 glEnable(GL_BLEND); 26 24 27 #ifdef notdef 25 28 glEnable(GL_LINE_SMOOTH); … … 48 51 glEnd(); 49 52 50 glDisable(GL_TEXTURE_2D);51 53 glLineWidth(1.0f); 52 glEnable(GL_BLEND);53 54 glColor4f(_majorColor.red, _majorColor.green, _majorColor.blue, 54 55 _majorColor.alpha); -
trunk/vizservers/nanovis/NvCamera.cpp
r881 r953 1 1 2 /* 2 3 * ---------------------------------------------------------------------- … … 15 16 16 17 #include <stdio.h> 18 #include <GL/glu.h> 17 19 #include "NvCamera.h" 18 20 19 21 NvCamera::NvCamera(int startx, int starty, int w, int h, 20 double loc_x, double loc_y, double loc_z, 21 double target_x, double target_y, double target_z, 22 int angle_x, int angle_y, int angle_z): 23 startX(startx), 24 startY(starty), 25 width(w), 26 height(h), 27 location(Vector3(loc_x, loc_y, loc_z)), 28 target(Vector3(target_x, target_y, target_z)), 29 angle(Vector3(angle_x, angle_y, angle_z)) { } 30 31 NvCamera::~NvCamera(){} 32 33 void NvCamera::move(double loc_x, double loc_y, double loc_z) 22 double loc_x, double loc_y, double loc_z, 23 double target_x, double target_y, double target_z, 24 int angle_x, int angle_y, int angle_z): 25 location(Vector3(loc_x, loc_y, loc_z)), 26 target(Vector3(target_x, target_y, target_z)), 27 angle(Vector3(angle_x, angle_y, angle_z)), 28 width(w), 29 height(h), 30 startX(startx), 31 startY(starty) 34 32 { 35 location = Vector3(loc_x, loc_y, loc_z);33 /*empty*/ 36 34 } 37 35 38 void NvCamera::aim(double target_x, double target_y, double target_z) 36 NvCamera::~NvCamera() 37 { 38 /*empty*/ 39 } 40 41 void 42 NvCamera::move(double loc_x, double loc_y, double loc_z) 39 43 { 40 target = Vector3(target_x, target_y, target_z);44 location = Vector3(loc_x, loc_y, loc_z); 41 45 } 42 46 43 void NvCamera::rotate(double angle_x, double angle_y, double angle_z) 47 void 48 NvCamera::aim(double target_x, double target_y, double target_z) 44 49 { 45 angle = Vector3(angle_x, angle_y, angle_z);50 target = Vector3(target_x, target_y, target_z); 46 51 } 47 52 48 void NvCamera::activate(){ 49 //fprintf(stderr, "camera: %d, %d\n", width, height); 50 glViewport(startX, startY, width, height); 51 glMatrixMode(GL_PROJECTION); 52 glLoadIdentity(); 53 gluPerspective(30, (GLdouble)(width - startX)/(GLdouble)(height - startY), 0.1, 50.0); 54 55 glMatrixMode(GL_MODELVIEW); 56 glLoadIdentity(); 57 58 gluLookAt(location.x, location.y, location.z, 59 target.x, target.y, target.z, 60 0., 1., 0.); 61 62 glRotated(angle.x, 1., 0., 0.); 63 glRotated(angle.y, 0., 1., 0.); 64 glRotated(angle.z, 0., 0., 1.); 53 void 54 NvCamera::rotate(double angle_x, double angle_y, double angle_z) 55 { 56 angle = Vector3(angle_x, angle_y, angle_z); 65 57 } 66 58 67 void NvCamera::set_screen_size(int sx, int sy, int w, int h){ 68 width = w; height = h; 69 startX = sx; startY = sy; 59 void 60 NvCamera::activate() 61 { 62 //fprintf(stderr, "camera: %d, %d\n", width, height); 63 glViewport(startX, startY, width, height); 64 glMatrixMode(GL_PROJECTION); 65 glLoadIdentity(); 66 gluPerspective(30, (GLdouble)(width - startX)/(GLdouble)(height - startY), 67 0.1, 50.0); 68 69 glMatrixMode(GL_MODELVIEW); 70 glLoadIdentity(); 71 72 gluLookAt(location.x, location.y, location.z, 73 target.x, target.y, target.z, 74 0., 1., 0.); 75 76 glRotated(angle.x, 1., 0., 0.); 77 glRotated(angle.y, 0., 1., 0.); 78 glRotated(angle.z, 0., 0., 1.); 70 79 } 80 81 void 82 NvCamera::set_screen_size(int sx, int sy, int w, int h) 83 { 84 width = w, height = h; 85 startX = sx, startY = sy; 86 } -
trunk/vizservers/nanovis/NvCamera.h
r881 r953 1 1 2 /* 2 3 * ---------------------------------------------------------------------- … … 17 18 #define _CAMERA_H_ 18 19 19 20 #include <GL/glu.h>21 20 #include "Vector3.h" 22 21 23 class NvCamera {22 class NvCamera { 24 23 25 24 public: 26 Vector3 location; //Location of the camera in the scene 27 Vector3 target; //Location the camera is looking at. 28 //location and target: two points define the line-of-sight 29 Vector3 angle; //rotation angles of camera along x, y, z 30 int width; //screen size 31 int height; //screen size 25 Vector3 location; //Location of the camera in the scene 26 Vector3 target; //Location the camera is looking at. 27 //location and target: two points define the 28 //line-of-sight 29 Vector3 angle; //rotation angles of camera along x, y, z 30 int width; //screen size 31 int height; //screen size 32 32 int startX; 33 33 int startY; 34 34 35 ~NvCamera(); 36 NvCamera(int startx, int starty, int w, int h, 37 double loc_x, double loc_y, double loc_z, 38 double target_x, double target_y, double target_z, 39 int angle_x, int angle_y, int angle_z); 40 void move(double loc_x, double loc_y, double loc_z); //move location of camera 41 void aim(double target_x, double target_y, double target_z); //change target point 42 void rotate(double angle_x, double angle_y, double angle_z); //change target point 43 void activate();//make the camera setting active, this has to be called before drawing things. 44 void set_screen_size(int startx, int starty, int w, int h); 35 ~NvCamera(); 36 NvCamera(int startx, int starty, int w, int h, 37 double loc_x, double loc_y, double loc_z, 38 double target_x, double target_y, double target_z, 39 int angle_x, int angle_y, int angle_z); 40 void move(double loc_x, double loc_y, double loc_z); //move location of camera 41 void aim(double target_x, double target_y, double target_z); //change target point 42 void rotate(double angle_x, double angle_y, double angle_z); //change target point 43 void activate(); //make the camera setting active, this has to be called 44 //before drawing things. 45 void set_screen_size(int startx, int starty, int w, int h); 45 46 }; 46 47 -
trunk/vizservers/nanovis/NvParticleAdvectionShader.cpp
r851 r953 3 3 #include "NvParticleAdvectionShader.h" 4 4 5 NvParticleAdvectionShader::NvParticleAdvectionShader() 6 : _scale(1.0f, 1.0f, 1.0f), _velocityVolumeID(0), _max(1.0f), _timeStep(0.005f) 5 NvParticleAdvectionShader::NvParticleAdvectionShader() : 6 _velocityVolumeID(0), 7 _scale(1.0f, 1.0f, 1.0f), 8 _max(1.0f), 9 _timeStep(0.005f) 7 10 { 8 11 init(); -
trunk/vizservers/nanovis/NvZincBlendeReconstructor.cpp
r806 r953 30 30 { 31 31 Vector3 origin, delta; 32 double temp;33 int width = 0, height = 0, depth = 0;34 void* data = NULL;35 36 32 37 33 std::ifstream stream; … … 49 45 ZincBlendeVolume* volume = 0; 50 46 Vector3 origin, delta; 51 double temp;52 47 int width = 0, height = 0, depth = 0; 53 48 void* data = NULL; … … 82 77 83 78 84 if (version == 1) 85 { 79 if (version == 1) { 80 float dummy; 81 86 82 sscanf(buff, "%s%s%s%s%s%d%d%d", str[0], str[1], str[2], str[3], str[4],&width, &height, &depth); 87 83 getLine(stream); 88 84 sscanf(buff, "%s%f%f%f", str[0], &(origin.x), &(origin.y), &(origin.z)); 89 85 getLine(stream); 90 sscanf(buff, "%s%f%f%f", str[0], &(delta.x), & temp, &temp);91 getLine(stream); 92 sscanf(buff, "%s%f%f%f", str[0], & temp, &(delta.y), &temp);93 getLine(stream); 94 sscanf(buff, "%s%f%f%f", str[0], & temp, &temp, &(delta.z));86 sscanf(buff, "%s%f%f%f", str[0], &(delta.x), &dummy, &dummy); 87 getLine(stream); 88 sscanf(buff, "%s%f%f%f", str[0], &dummy, &(delta.y), &dummy); 89 getLine(stream); 90 sscanf(buff, "%s%f%f%f", str[0], &dummy, &dummy, &(delta.z)); 95 91 do { 96 92 getLine(stream); … … 224 220 225 221 226 ZincBlendeVolume* NvZincBlendeReconstructor::buildUp(const Vector3& origin, const Vector3& delta, int width, int height, int depth, void* data) 222 ZincBlendeVolume* 223 NvZincBlendeReconstructor::buildUp(const Vector3& origin, const Vector3& delta, 224 int width, int height, int depth, void* data) 227 225 { 228 226 ZincBlendeVolume* zincBlendeVolume = NULL; … … 239 237 int index; 240 238 239 nzero_min = 0.0f; /* Suppress compiler warning. */ 241 240 vmin = vmax = srcPtr->atom; 242 241 … … 407 406 ZincBlendeVolume* volume = 0; 408 407 Vector3 origin, delta; 409 double temp;410 408 int width = 0, height = 0, depth = 0; 411 409 void* data = NULL; … … 439 437 if (version == 1) 440 438 { 439 float dummy; 440 441 441 sscanf(buff, "%s%s%s%s%s%d%d%d", str[0], str[1], str[2], str[3], str[4],&width, &height, &depth); 442 442 getLine(stream); 443 443 sscanf(buff, "%s%f%f%f", str[0], &(origin.x), &(origin.y), &(origin.z)); 444 444 getLine(stream); 445 sscanf(buff, "%s%f%f%f", str[0], &(delta.x), & temp, &temp);446 getLine(stream); 447 sscanf(buff, "%s%f%f%f", str[0], & temp, &(delta.y), &temp);448 getLine(stream); 449 sscanf(buff, "%s%f%f%f", str[0], & temp, &temp, &(delta.z));445 sscanf(buff, "%s%f%f%f", str[0], &(delta.x), &dummy, &dummy); 446 getLine(stream); 447 sscanf(buff, "%s%f%f%f", str[0], &dummy, &(delta.y), &dummy); 448 getLine(stream); 449 sscanf(buff, "%s%f%f%f", str[0], &dummy, &dummy, &(delta.z)); 450 450 do { 451 451 getLine(stream); -
trunk/vizservers/nanovis/PlaneRenderer.cpp
r755 r953 1 1 2 /* 2 3 * ---------------------------------------------------------------------- … … 18 19 19 20 PlaneRenderer::PlaneRenderer(CGcontext _context, int _width, int _height): 20 n_planes(0),21 g_context(_context),22 render_width(_width),23 render_height(_height),24 active_plane(-1)21 active_plane(-1), 22 n_planes(0), 23 render_width(_width), 24 render_height(_height), 25 g_context(_context) 25 26 { 26 plane.clear(); 27 tf.clear(); 28 init_shaders(); 27 plane.clear(); 28 tf.clear(); 29 init_shaders(); 30 } 31 32 PlaneRenderer::~PlaneRenderer() 33 { 34 /*empty*/ 35 } 36 37 //initialize the render shader 38 void 39 PlaneRenderer::init_shaders() 40 { 41 //plane rendering shader 42 R2string path = R2FilePath::getInstance()->getPath("one_plane.cg"); 43 m_fprog = loadProgram(g_context, CG_PROFILE_FP30, CG_SOURCE, path); 44 m_data_param = cgGetNamedParameter(m_fprog, "data"); 45 m_tf_param = cgGetNamedParameter(m_fprog, "tf"); 46 m_render_param = cgGetNamedParameter(m_fprog, "render_param"); 29 47 } 30 48 31 49 32 PlaneRenderer::~PlaneRenderer(){} 50 int 51 PlaneRenderer::add_plane(Texture2D* _p, TransferFunction* _tf) 52 { 53 int ret = n_planes; 33 54 34 //initialize the render shader 35 void PlaneRenderer::init_shaders(){ 36 37 //plane rendering shader 38 R2string path = R2FilePath::getInstance()->getPath("one_plane.cg"); 39 m_fprog = loadProgram(g_context, CG_PROFILE_FP30, CG_SOURCE, path); 40 m_data_param = cgGetNamedParameter(m_fprog, "data"); 41 m_tf_param = cgGetNamedParameter(m_fprog, "tf"); 42 m_render_param = cgGetNamedParameter(m_fprog, "render_param"); 43 } 55 plane.push_back(_p); 56 tf.push_back(_tf); 44 57 58 if(ret==0) 59 active_plane = ret; 45 60 46 int PlaneRenderer::add_plane(Texture2D* _p, TransferFunction* _tf){ 47 48 int ret = n_planes; 49 50 plane.push_back(_p); 51 tf.push_back(_tf); 52 53 if(ret==0) 54 active_plane = ret; 55 56 n_planes++; 57 return ret; 61 n_planes++; 62 return ret; 58 63 } 59 64 60 65 void 61 66 PlaneRenderer::remove_plane(int index) { 62 vector<Texture2D*>::iterator piter = plane.begin()+index;63 vector<TransferFunction*>::iterator tfiter = tf.begin()+index;67 vector<Texture2D*>::iterator piter = plane.begin()+index; 68 vector<TransferFunction*>::iterator tfiter = tf.begin()+index; 64 69 65 plane.erase(piter);66 tf.erase(tfiter);70 plane.erase(piter); 71 tf.erase(tfiter); 67 72 68 n_planes--;73 n_planes--; 69 74 } 70 75 71 76 72 void PlaneRenderer::render(){ 73 if (n_planes == 0) 74 return; 77 void 78 PlaneRenderer::render() 79 { 80 if (n_planes == 0) 81 return; 75 82 76 glEnable(GL_TEXTURE_2D);77 glEnable(GL_BLEND);83 glEnable(GL_TEXTURE_2D); 84 glEnable(GL_BLEND); 78 85 79 glViewport(0, 0, render_width, render_height);80 glMatrixMode(GL_PROJECTION);81 glLoadIdentity();82 gluOrtho2D(0, render_width, 0, render_height);83 glMatrixMode(GL_MODELVIEW);84 glLoadIdentity();86 glViewport(0, 0, render_width, render_height); 87 glMatrixMode(GL_PROJECTION); 88 glLoadIdentity(); 89 gluOrtho2D(0, render_width, 0, render_height); 90 glMatrixMode(GL_MODELVIEW); 91 glLoadIdentity(); 85 92 86 //glColor3f(1.,1.,1.); //MUST HAVE THIS LINE!!!93 //glColor3f(1.,1.,1.); //MUST HAVE THIS LINE!!! 87 94 88 //if no active plane89 if(active_plane == -1)90 return;95 //if no active plane 96 if(active_plane == -1) 97 return; 91 98 92 activate_shader(active_plane);93 glBegin(GL_QUADS);94 glTexCoord2f(0, 0); glVertex2f(0, 0);95 glTexCoord2f(1, 0); glVertex2f(render_width, 0);96 glTexCoord2f(1, 1); glVertex2f(render_width, render_height);97 glTexCoord2f(0, 1); glVertex2f(0, render_height);98 glEnd();99 deactivate_shader();99 activate_shader(active_plane); 100 glBegin(GL_QUADS); 101 glTexCoord2f(0, 0); glVertex2f(0, 0); 102 glTexCoord2f(1, 0); glVertex2f(render_width, 0); 103 glTexCoord2f(1, 1); glVertex2f(render_width, render_height); 104 glTexCoord2f(0, 1); glVertex2f(0, render_height); 105 glEnd(); 106 deactivate_shader(); 100 107 101 108 } 102 109 103 void PlaneRenderer::activate_shader(int index){ 110 void 111 PlaneRenderer::activate_shader(int index) 112 { 104 113 105 cgGLSetTextureParameter(m_data_param, plane[index]->id);106 cgGLSetTextureParameter(m_tf_param, tf[index]->id);107 cgGLEnableTextureParameter(m_data_param);108 cgGLEnableTextureParameter(m_tf_param);114 cgGLSetTextureParameter(m_data_param, plane[index]->id); 115 cgGLSetTextureParameter(m_tf_param, tf[index]->id); 116 cgGLEnableTextureParameter(m_data_param); 117 cgGLEnableTextureParameter(m_tf_param); 109 118 110 cgGLSetParameter4f(m_render_param, 0., 0., 0., 0.);119 cgGLSetParameter4f(m_render_param, 0., 0., 0., 0.); 111 120 112 cgGLBindProgram(m_fprog);113 cgGLEnableProfile(CG_PROFILE_FP30);121 cgGLBindProgram(m_fprog); 122 cgGLEnableProfile(CG_PROFILE_FP30); 114 123 } 115 124 116 125 117 void PlaneRenderer::deactivate_shader(){ 118 cgGLDisableProfile(CG_PROFILE_FP30); 119 cgGLDisableTextureParameter(m_data_param); 120 cgGLDisableTextureParameter(m_tf_param); 126 void 127 PlaneRenderer::deactivate_shader() 128 { 129 cgGLDisableProfile(CG_PROFILE_FP30); 130 cgGLDisableTextureParameter(m_data_param); 131 cgGLDisableTextureParameter(m_tf_param); 121 132 } 122 133 123 134 void 124 PlaneRenderer::set_active_plane(int index) { 125 active_plane = index; 135 PlaneRenderer::set_active_plane(int index) 136 { 137 active_plane = index; 126 138 } 127 139 128 140 void 129 PlaneRenderer::set_screen_size(int w, int h) { 130 render_width = w; 131 render_height = h; 141 PlaneRenderer::set_screen_size(int w, int h) 142 { 143 render_width = w; 144 render_height = h; 132 145 } -
trunk/vizservers/nanovis/PlaneRenderer.h
r455 r953 1 1 2 /* 2 3 * ---------------------------------------------------------------------- … … 36 37 37 38 private: 38 vector <Texture2D*> plane; //array of volumes39 vector <TransferFunction*> tf; //array of corresponding transfer functions40 int active_plane; //the active plane, only one is rendered41 int n_planes;39 vector <Texture2D*> plane; // Array of volumes 40 vector <TransferFunction*> tf; // Array of corresponding transfer functions 41 int active_plane; // The active plane, only one is rendered 42 int n_planes; 42 43 43 int render_width;//render size44 int render_height;44 int render_width; //render size 45 int render_height; 45 46 46 //cg related47 CGcontext g_context; //the Nvidia cg context48 CGprogram m_fprog;49 CGparameter m_data_param;50 CGparameter m_tf_param;51 CGparameter m_render_param;47 //cg related 48 CGcontext g_context; // The Nvidia cg context 49 CGprogram m_fprog; 50 CGparameter m_data_param; 51 CGparameter m_tf_param; 52 CGparameter m_render_param; 52 53 53 void init_shaders();54 void activate_shader(int plane_index);55 void deactivate_shader();54 void init_shaders(); 55 void activate_shader(int plane_index); 56 void deactivate_shader(); 56 57 57 58 public: 58 PlaneRenderer(CGcontext _context, int width, int height);59 ~PlaneRenderer();59 PlaneRenderer(CGcontext _context, int width, int height); 60 ~PlaneRenderer(); 60 61 61 int add_plane(Texture2D* _p, TransferFunction* _tf); 62 //add a plane and its transfer function 63 //we require a transfer function when a 64 //plane is added. 65 void remove_plane(int index); 66 void set_active_plane(int index); //set the active plane to be rendered 67 void set_screen_size(int w, int h); //change the rendering size 68 void render(); 62 int add_plane(Texture2D* _p, TransferFunction* _tf); 63 // Add a plane and its transfer function. We require a transfer function 64 // when a plane is added. 65 void remove_plane(int index); 66 void set_active_plane(int index); //set the active plane to be rendered 67 void set_screen_size(int w, int h); //change the rendering size 68 void render(); 69 69 }; 70 70 -
trunk/vizservers/nanovis/PointSet.cpp
r827 r953 4 4 #include <stdio.h> 5 5 6 PointSet::PointSet() 7 : _visible(false), _cluster(0), _sortLevel(4), _min(0.0f), _max(1.0f) 6 PointSet::PointSet() : 7 _sortLevel(4), 8 _cluster(0), 9 _max(1.0f), 10 _min(0.0f), 11 _visible(false) 8 12 { 13 /*empty*/ 9 14 } 10 15 -
trunk/vizservers/nanovis/PointSet.h
r827 r953 1 1 2 #ifndef __POINT_SET_H__ 2 3 #define __POINT_SET_H__ -
trunk/vizservers/nanovis/PointSetRenderer.cpp
r915 r953 1 1 2 #include "Nv.h" 2 3 #include <GL/gl.h> … … 17 18 _shader = new PointShader(); 18 19 R2string path = R2FilePath::getInstance()->getPath("particle2.bmp"); 19 if (path.getLength() == 0) 20 { 20 if (path.getLength() == 0) { 21 21 printf("ERROR : pointset file not found - %s\n", (const char*) path); 22 22 fflush(stdout); … … 28 28 29 29 unsigned char* bytes = (unsigned char*) image->getImageBuffer(); 30 if (bytes) 31 { 32 for (int y = 0; y < image->getHeight(); ++y) 33 for (int x = 0; x < image->getWidth(); ++x, bytes +=4) 34 { 30 if (bytes) { 31 for (unsigned int y = 0; y < image->getHeight(); ++y) { 32 for (unsigned int x = 0; x < image->getWidth(); ++x, bytes +=4) { 35 33 bytes[3] = (bytes[0] == 0)? 0 : 255; 36 } 34 } 35 } 37 36 } 38 37 39 if (image) 40 { 41 _pointTexture = new Texture2D(image->getWidth(), image->getHeight(), GL_UNSIGNED_BYTE, GL_LINEAR, 42 4, (float*) image->getImageBuffer()); 43 } 44 else 45 { 38 if (image) { 39 _pointTexture = new Texture2D(image->getWidth(), image->getHeight(), 40 GL_UNSIGNED_BYTE, GL_LINEAR, 41 4, (float*) image->getImageBuffer()); 42 } else { 46 43 printf("fail to load image [%s]\n", "particles2.bmp"); 47 44 } 48 45 49 46 delete loader; 50 51 47 _bucketSort = new PCA::BucketSort(1024); 52 48 } -
trunk/vizservers/nanovis/R2/include/R2/R2Fonts.h
r603 r953 9 9 class R2Fonts : public R2Object { 10 10 11 struct R2FontAttributes { 12 R2string _fontName; 13 R2int32 _textureWidth; 14 R2int32 _textureHeight; 15 R2int32 _fontHeight; 16 R2uint32 _fontTextureID; 17 R2uint32 _displayLists; 18 19 struct R2CharInfo { 20 R2float _left; 21 R2float _right; 22 R2float _top; 23 R2float _bottom; 24 R2bool _valid; 25 R2float _width; 26 27 }; 11 struct R2FontAttributes { 12 R2string _fontName; 13 R2int32 _textureWidth; 14 R2int32 _textureHeight; 15 R2int32 _fontHeight; 16 R2uint32 _fontTextureID; 17 R2uint32 _displayLists; 18 19 struct R2CharInfo { 20 R2float _left; 21 R2float _right; 22 R2float _top; 23 R2float _bottom; 24 R2bool _valid; 25 R2float _width; 26 27 }; 28 R2CharInfo _chars[256]; 29 }; 30 31 typedef std::vector<R2FontAttributes> R2FontVector; 28 32 29 R2CharInfo _chars[256]; 30 }; 31 32 typedef std::vector<R2FontAttributes> R2FontVector; 33 34 R2FontVector _fonts; 35 36 /** 37 * @brief current font index 38 */ 39 R2int32 _fontIndex; 40 41 /** 42 * @brief screen width 43 */ 44 R2int32 _screenWidth; 45 46 /** 47 * @brief screen height 48 */ 49 R2int32 _screenHeight; 50 33 R2FontVector _fonts; 34 35 /** 36 * @brief current font index 37 */ 38 R2int32 _fontIndex; 39 40 /** 41 * @brief screen width 42 */ 43 R2int32 _screenWidth; 44 45 /** 46 * @brief screen height 47 */ 48 R2int32 _screenHeight; 49 51 50 private : 52 51 ~R2Fonts(); 53 54 //private :52 53 //private : 55 54 public : 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 55 /** 56 * @brief set projection to orthographic 57 */ 58 void begin(); 59 60 /** 61 * @brief reset projection matrix 62 */ 63 void end(); 64 65 /** 66 * @brief initialize R2FontAttributes 67 */ 68 void initializeFont(R2FontAttributes& attr); 69 70 /** 71 * @brief load font data 72 */ 73 R2bool loadFont(const char* fontName, const char* fontFileName, R2FontAttributes& sFont); 74 76 75 public : 77 /** 78 * @brief constructor 79 */ 80 R2Fonts(); 81 82 /** 83 * @brief 84 */ 85 void addFont(const char* fontName, const char* fontFileName); 86 87 /** 88 * @brief 89 */ 90 void setFont(const char* fontName); 91 92 93 94 /** 95 * 96 */ 97 void draw(const char* pString, ...) const; 98 99 /** 100 * 101 */ 102 void resize(R2int32 width, R2int32 height); 103 104 /** 105 * @brief return font height 106 */ 107 R2int32 getFontHeight() const; 108 76 /** 77 * @brief constructor 78 */ 79 R2Fonts(); 80 81 /** 82 * @brief 83 */ 84 void addFont(const char* fontName, const char* fontFileName); 85 86 /** 87 * @brief 88 */ 89 void setFont(const char* fontName); 90 91 /** 92 * 93 */ 94 void draw(const char* pString, ...) const; 95 96 /** 97 * 98 */ 99 void resize(R2int32 width, R2int32 height); 100 101 /** 102 * @brief return font height 103 */ 104 R2int32 getFontHeight() const; 105 109 106 }; 110 107 111 108 inline R2int32 R2Fonts::getFontHeight() const 112 109 { 113 110 return _fonts[_fontIndex]._fontHeight; 114 111 } 115 112 -
trunk/vizservers/nanovis/R2/src/R2Fonts.cpp
r929 r953 7 7 const int c_nFileMagicHeader = 6666; 8 8 9 R2Fonts::R2Fonts() : _fontIndex(-1), _screenWidth(512), _screenHeight(512) 9 R2Fonts::R2Fonts() : 10 _fontIndex(-1), 11 _screenWidth(512), 12 _screenHeight(512) 10 13 { 11 14 } … … 23 26 { 24 27 for (unsigned index = 0; index < _fonts.size(); ++index) { 25 26 27 28 28 if (_fonts[index]._fontName == fontName) { 29 _fontIndex = index; 30 break; 31 } 29 32 } 30 33 } … … 52 55 if (_fontIndex != -1) { 53 56 int length = strlen(szVargsBuffer); 54 57 55 58 glListBase(_fonts[_fontIndex]._displayLists); 56 59 glCallLists(length, GL_UNSIGNED_BYTE, 57 reinterpret_cast<const GLvoid*>(szVargsBuffer)); 58 } 59 } 60 61 void R2Fonts::begin() 60 reinterpret_cast<const GLvoid*>(szVargsBuffer)); 61 } 62 } 63 64 void 65 R2Fonts::begin() 62 66 { 63 67 glEnable(GL_TEXTURE_2D); … … 80 84 } 81 85 82 void R2Fonts::end() 86 void 87 R2Fonts::end() 83 88 { 84 89 glBindTexture(GL_TEXTURE_2D, 0); … … 93 98 } 94 99 95 void R2Fonts::initializeFont(R2FontAttributes& attr) 100 void 101 R2Fonts::initializeFont(R2FontAttributes& attr) 96 102 { 97 103 attr._displayLists = glGenLists(256); … … 99 105 R2int32 index; 100 106 for (index = 0; index < 256; ++index) { 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 107 R2FontAttributes::R2CharInfo& charInfo = attr._chars[index]; 108 glNewList(attr._displayLists + index, GL_COMPILE); 109 if (charInfo._valid) { 110 glBegin(GL_TRIANGLE_STRIP); 111 112 glTexCoord2f(charInfo._left, charInfo._top ); 113 glVertex2i(0.0f, 0.0f); 114 115 glTexCoord2f(charInfo._left, charInfo._bottom); 116 glVertex2i(0.0f, attr._fontHeight); 117 118 glTexCoord2f(charInfo._right, charInfo._top); 119 glVertex2i(charInfo._width, 0.0f); 120 121 glTexCoord2f(charInfo._right, charInfo._bottom); 122 glVertex2i(charInfo._width, attr._fontHeight); 123 124 glEnd( ); 119 125 glTranslatef(charInfo._width, 0.0f, 0.0f); 120 121 126 } 127 glEndList(); 122 128 } 123 129 } … … 125 131 R2bool 126 132 R2Fonts::loadFont(const char* fontName, const char* fontFileName, 127 133 R2FontAttributes& sFont) 128 134 { 129 135 R2bool bSuccess = false; 130 131 136 R2string path = R2FilePath::getInstance()->getPath(fontFileName); 132 137 133 138 std::ifstream fsInput((const char*) path, std::ios::binary); 134 139 if (fsInput) { 135 136 140 sFont._fontName = fontName; 141 137 142 // make sure this file is the correct type by checking the header 138 143 unsigned int uiFileId = 0; … … 143 148 uiTextureWidth = uiTextureHeight = uiFontHeight = 0; 144 149 fsInput.read(reinterpret_cast<char*>(&sFont._textureWidth), 145 150 sizeof(unsigned int)); 146 151 fsInput.read(reinterpret_cast<char*>(&sFont._textureHeight), 147 152 sizeof(unsigned int)); 148 153 fsInput.read(reinterpret_cast<char*>(&sFont._fontHeight), 149 154 sizeof(unsigned int)); 150 155 151 156 // read dimensions for each charactor in 256-char ASCII chart … … 155 160 // top 156 161 fsInput.read(reinterpret_cast<char*>(&uiSize), 157 162 sizeof(unsigned int)); 158 163 sFont._chars[i]._top = static_cast<float>(uiSize) / sFont._textureHeight; 159 164 // left … … 198 203 glBindTexture(GL_TEXTURE_2D, sFont._fontTextureID); 199 204 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 200 201 205 sFont._textureWidth, sFont._textureHeight, 0, 206 GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, pTexMap); 202 207 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 203 208 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); -
trunk/vizservers/nanovis/R2/src/R2string.cpp
r835 r953 2 2 #include <string.h> 3 3 4 R2string::R2string() : _string(NULL), _length(0) 4 R2string::R2string() : 5 _string(NULL), 6 _length(0) 5 7 { 6 8 } … … 8 10 R2string::R2string(const char* str) : _string(NULL), _length(0) 9 11 { 10 if (str != NULL) 11 { 12 set(str, (R2int32) strlen(str)); 13 } 12 if (str != NULL) { 13 set(str, (R2int32) strlen(str)); 14 } 14 15 } 15 16 16 17 R2string::R2string(const R2string& string) : _string(NULL) 17 18 { 18 19 set(string._string, string._length); 19 20 } 20 21 … … 26 27 R2string& R2string::operator=(const R2string& string) 27 28 { 28 29 set(string._string, string._length); 29 30 30 31 return *this; 31 32 } 32 33 33 34 R2string& R2string::operator=(const char* string) 34 35 { 35 36 set(string, strlen(string)); 36 37 37 38 return *this; 38 39 } 39 40 40 41 R2string operator+(const R2string& string1, const R2string& string2) 41 42 { 42 43 44 45 46 47 48 49 43 R2string ret; 44 ret._length = string1._length + string2._length; 45 ret._string = new R2char[ret._length + 1]; 46 47 strcpy(ret._string, string1._string); 48 strcpy(ret._string + string1._length, string2._string); 49 50 return ret; 50 51 } 51 52 … … 53 54 R2string operator+(const R2string& string1, const char* string2) 54 55 { 55 56 57 58 59 60 61 62 56 R2string ret; 57 ret._length = string1._length + strlen(string2); 58 ret._string = new R2char[ret._length + 1]; 59 60 strcpy(ret._string, string1._string); 61 strcpy(ret._string + string1._length, string2); 62 63 return ret; 63 64 } -
trunk/vizservers/nanovis/RenderVertexArray.cpp
r850 r953 1 1 2 /* 2 3 * ---------------------------------------------------------------------- … … 41 42 42 43 RenderVertexArray::RenderVertexArray(int nverts, GLint size, GLenum type) : 43 m_nverts(nverts), m_size(size), m_usage(GL_STREAM_COPY), m_type(type) 44 m_usage(GL_STREAM_COPY), 45 m_nverts(nverts), 46 m_size(size), 47 m_type(type) 44 48 { 45 49 switch(m_type) { 46 47 48 49 50 51 52 50 case GL_HALF_FLOAT_NV: 51 m_bytes_per_component = 2; break; 52 case GL_FLOAT: 53 m_bytes_per_component = sizeof(float); break; 54 default: 55 fprintf(stderr, "Error: unsupported RenderVertexArray type\n"); 56 return; 53 57 } 54 58 … … 56 60 glGenBuffersARB(1, &m_buffer); 57 61 glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, m_buffer); 58 glBufferDataARB(GL_PIXEL_PACK_BUFFER_EXT, m_nverts*m_size*m_bytes_per_component, 0, m_usage); // undefined data 62 glBufferDataARB(GL_PIXEL_PACK_BUFFER_EXT, 63 m_nverts*m_size*m_bytes_per_component, 0, m_usage); // undefined data 59 64 glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, 0); 60 65 61 66 // set equivalent image format 62 67 switch(m_size) { 63 64 65 66 67 68 69 70 71 68 case 1: 69 m_format = GL_LUMINANCE; break; 70 case 3: 71 m_format = GL_RGB; break; 72 case 4: 73 m_format = GL_RGBA; break; 74 default: 75 fprintf(stderr, "Error: unsupported RenderVertexArray size\n"); 76 return; 72 77 } 73 78 } … … 83 88 // load data to buffer object 84 89 glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, m_buffer); 85 glBufferDataARB(GL_PIXEL_PACK_BUFFER_EXT, m_nverts*m_size*m_bytes_per_component, data, m_usage); 90 glBufferDataARB(GL_PIXEL_PACK_BUFFER_EXT, 91 m_nverts*m_size*m_bytes_per_component, data, m_usage); 86 92 glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, 0); 87 93 } … … 104 110 // bind buffer object to vertex array 105 111 glBindBufferARB(GL_ARRAY_BUFFER, m_buffer); 106 //glVertexAttribPointerARB(index, m_size, m_type, GL_FALSE, 0, 0); 112 //glVertexAttribPointerARB(index, m_size, m_type, GL_FALSE, 0, 0); //doesn't work 107 113 glVertexPointer(m_size, m_type, 0, 0); 108 114 -
trunk/vizservers/nanovis/RenderVertexArray.h
r226 r953 1 1 2 /* 2 3 * ---------------------------------------------------------------------- … … 20 21 21 22 class RenderVertexArray { 22 public:23 RenderVertexArray(int nverts, GLint size, GLenum type = GL_FLOAT);24 ~RenderVertexArray();25 26 void LoadData(void *data); // load vertex data from memory27 void Read(/*GLenum buffer,*/ int w, int h); // read vertex data from frame buffer28 void SetPointer(GLuint index);29 30 private:31 23 GLenum m_usage; // vbo usage flag 32 24 GLuint m_buffer; … … 37 29 GLenum m_type; // FLOAT or HALF_FLOAT 38 30 int m_bytes_per_component; 31 32 public: 33 RenderVertexArray(int nverts, GLint size, GLenum type = GL_FLOAT); 34 ~RenderVertexArray(); 35 36 void LoadData(void *data); // load vertex data from memory 37 void Read(/*GLenum buffer,*/ int w, int h); // read vertex data from 38 // frame buffer 39 void SetPointer(GLuint index); 39 40 }; 40 41 -
trunk/vizservers/nanovis/ScreenSnapper.cpp
r406 r953 1 1 2 /* 2 3 * ---------------------------------------------------------------------- 3 4 * ScreenSnapper.h: ScreenSnapper class. It captures the render result 4 * 5 * 5 * and stores it in an array of chars or floats 6 * depending on chosen format. 6 7 * 7 8 * ====================================================================== … … 20 21 #include "ScreenSnapper.h" 21 22 22 ScreenSnapper::ScreenSnapper(int w, int h, NVISdatatype type, int channel_per_pixel){ 23 width = w; 24 height = h; 23 ScreenSnapper::ScreenSnapper(int w, int h, NVISdatatype type, 24 int channel_per_pixel) 25 { 26 width = w; 27 height = h; 25 28 26 assert(type == NVIS_FLOAT || type == NVIS_UNSIGNED_BYTE); //only allow two types 27 data_type = type; 29 //only allow two types 30 assert(type == NVIS_FLOAT || type == NVIS_UNSIGNED_BYTE); 31 data_type = type; 28 32 29 assert(channel_per_pixel == 3 || channel_per_pixel == 4); //only allow RGB or RGBA 30 n_channels_per_pixel = channel_per_pixel; 33 //only allow RGB or RGBA 34 assert(channel_per_pixel == 3 || channel_per_pixel == 4); 35 n_channels_per_pixel = channel_per_pixel; 31 36 32 if(type == NVIS_FLOAT)33 data = new float[w*h*channel_per_pixel];34 else if(type == NVIS_UNSIGNED_BYTE)35 data = new unsigned char[w*h*channel_per_pixel];37 if(type == NVIS_FLOAT) 38 data = new float[w*h*channel_per_pixel]; 39 else if(type == NVIS_UNSIGNED_BYTE) 40 data = new unsigned char[w*h*channel_per_pixel]; 36 41 37 assert(data!=0);38 reset(0);//reset data42 assert(data!=0); 43 reset(0); //reset data 39 44 } 40 45 41 ScreenSnapper::~ScreenSnapper(){ 42 if(data_type == NVIS_FLOAT) 43 delete[] (float*)data; 44 else if(data_type == NVIS_UNSIGNED_BYTE) 45 delete[] (unsigned char*)data; 46 ScreenSnapper::~ScreenSnapper() 47 { 48 if(data_type == NVIS_FLOAT) 49 delete[] (float*)data; 50 else if(data_type == NVIS_UNSIGNED_BYTE) 51 delete[] (unsigned char*)data; 46 52 } 47 53 48 void ScreenSnapper::reset(char c){ 49 int size; 50 if(data_type == NVIS_FLOAT) 51 size = sizeof(float)*width*height*n_channels_per_pixel; 52 else if(data_type == NVIS_UNSIGNED_BYTE) 53 size = sizeof(unsigned char)*width*height*n_channels_per_pixel; 54 void 55 ScreenSnapper::reset(char c) 56 { 57 unsigned int elemSize; 58 switch (data_type) { 59 case NVIS_FLOAT: 60 elemSize = sizeof(float); 61 break; 54 62 55 memset(data, size, c); 63 case NVIS_UNSIGNED_BYTE: 64 elemSize = sizeof(unsigned char); 65 break; 66 67 default: 68 assert(0); 69 break; 70 } 71 unsigned int size; 72 size = elemSize * width * height * n_channels_per_pixel; 73 memset(data, size, c); 56 74 } 57 75 58 void ScreenSnapper::capture(){59 60 if(data_type == NVIS_FLOAT){61 if( n_channels_per_pixel==3)62 glReadPixels(0, 0, width, height, GL_RGB, GL_FLOAT, data);63 else if(n_channels_per_pixel==4)64 glReadPixels(0, 0, width, height, GL_RGBA, GL_FLOAT, data);65 }66 else if(data_type == NVIS_UNSIGNED_BYTE){67 if(n_channels_per_pixel==3)68 glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, data);69 else if(n_channels_per_pixel==4)70 glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);71 }72 73 assert(glGetError()==0);76 void 77 ScreenSnapper::capture() 78 { 79 if(data_type == NVIS_FLOAT){ 80 if(n_channels_per_pixel==3) 81 glReadPixels(0, 0, width, height, GL_RGB, GL_FLOAT, data); 82 else if(n_channels_per_pixel==4) 83 glReadPixels(0, 0, width, height, GL_RGBA, GL_FLOAT, data); 84 } 85 else if(data_type == NVIS_UNSIGNED_BYTE){ 86 if(n_channels_per_pixel==3) 87 glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, data); 88 else if(n_channels_per_pixel==4) 89 glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); 90 } 91 assert(glGetError()==0); 74 92 } 75 93 76 void ScreenSnapper::print(){ 77 for(int i=0; i<width*height; i++){ 78 if(data_type == NVIS_FLOAT){ 79 if(n_channels_per_pixel==3) 80 fprintf(stderr, "(%f %f %f) ", 81 ((float*)data)[3*i], 82 ((float*)data)[3*i+1], 83 ((float*)data)[3*i+2]); 84 else if(n_channels_per_pixel==4) 85 fprintf(stderr, "(%f %f %f %f) ", 86 ((float*)data)[4*i], 87 ((float*)data)[4*i+1], 88 ((float*)data)[4*i+2], 89 ((float*)data)[4*i+3]); 90 } 91 else if(data_type == NVIS_UNSIGNED_BYTE){ 92 if(n_channels_per_pixel==3) 93 fprintf(stderr, "(%d %d %d) ", 94 ((unsigned char*)data)[3*i], 95 ((unsigned char*)data)[3*i+1], 96 ((unsigned char*)data)[3*i+2]); 97 else if(n_channels_per_pixel==4) 98 fprintf(stderr, "(%d %d %d %d) ", 99 ((unsigned char*)data)[4*i], 100 ((unsigned char*)data)[4*i+1], 101 ((unsigned char*)data)[4*i+2], 102 ((unsigned char*)data)[4*i+3]); 103 } 104 } 94 void 95 ScreenSnapper::print() 96 { 97 for(int i=0; i<width*height; i++){ 98 if(data_type == NVIS_FLOAT){ 99 if(n_channels_per_pixel==3) 100 fprintf(stderr, "(%f %f %f) ", 101 ((float*)data)[3*i], 102 ((float*)data)[3*i+1], 103 ((float*)data)[3*i+2]); 104 else if(n_channels_per_pixel==4) 105 fprintf(stderr, "(%f %f %f %f) ", 106 ((float*)data)[4*i], 107 ((float*)data)[4*i+1], 108 ((float*)data)[4*i+2], 109 ((float*)data)[4*i+3]); 110 } 111 else if(data_type == NVIS_UNSIGNED_BYTE){ 112 if(n_channels_per_pixel==3) 113 fprintf(stderr, "(%d %d %d) ", 114 ((unsigned char*)data)[3*i], 115 ((unsigned char*)data)[3*i+1], 116 ((unsigned char*)data)[3*i+2]); 117 else if(n_channels_per_pixel==4) 118 fprintf(stderr, "(%d %d %d %d) ", 119 ((unsigned char*)data)[4*i], 120 ((unsigned char*)data)[4*i+1], 121 ((unsigned char*)data)[4*i+2], 122 ((unsigned char*)data)[4*i+3]); 123 } 124 } 105 125 } 106 126 -
trunk/vizservers/nanovis/Sphere.cpp
r406 r953 1 1 2 /* 2 3 * ---------------------------------------------------------------------- … … 18 19 19 20 Sphere::Sphere(float x, float y, float z, 20 21 22 23 24 25 26 stack(_stack),27 slice(_slice),28 color(Color(r,g,b))21 float r, float g, float b, 22 float _radius, 23 int _stack, 24 int _slice): 25 Renderable(Vector3(x, y, z)), 26 radius(_radius), 27 color(Color(r,g,b)), 28 stack(_stack), 29 slice(_slice) 29 30 { 30 boundary = BoundBox(x-r, y-r, z-r, x+r, y+r, z+r);31 boundary = BoundBox(x-r, y-r, z-r, x+r, y+r, z+r); 31 32 } 32 33 33 Sphere::~Sphere(){} 34 35 void Sphere::render(){} 36 37 void Sphere::draw(GLUquadric* quad){ 38 glColor3f(color.R, color.G, color.B); 39 40 glMatrixMode(GL_MODELVIEW); 41 glPushMatrix(); 42 glTranslatef(location.x, location.y, location.z); 43 44 //draw it 45 gluSphere(quad, radius, stack, slice); 46 47 glPopMatrix(); 34 Sphere::~Sphere() { 35 /*empty*/ 48 36 } 49 37 50 void Sphere::set_horizontal_res(int _slice) {slice=_slice;} 51 void Sphere::set_vertical_res(int _stack) {stack=_stack;} 38 void 39 Sphere::render() 40 { 41 /*empty*/ 42 } 52 43 44 void 45 Sphere::draw(GLUquadric* quad) 46 { 47 glColor3f(color.R, color.G, color.B); 48 49 glMatrixMode(GL_MODELVIEW); 50 glPushMatrix(); 51 glTranslatef(location.x, location.y, location.z); 52 53 //draw it 54 gluSphere(quad, radius, stack, slice); 55 56 glPopMatrix(); 57 } 58 59 void 60 Sphere::set_horizontal_res(int _slice) { 61 slice=_slice; 62 } 63 64 void 65 Sphere::set_vertical_res(int _stack) { 66 stack=_stack; 67 } 68 -
trunk/vizservers/nanovis/Sphere.h
r401 r953 1 1 2 /* 2 3 * ---------------------------------------------------------------------- … … 25 26 26 27 public: 27 28 29 30 28 float radius; 29 Color color; 30 int stack; 31 int slice; 31 32 32 ~Sphere(); 33 Sphere(float x, float y, float z, float r, float g, float b, float _radius, int _stack, int _slice); 34 void set_vertical_res(int _stack); 35 void set_horizontal_res(int _slice); 36 37 //display the sphere 38 void draw(GLUquadric* q); 39 void render(); 33 ~Sphere(); 34 Sphere(float x, float y, float z, float r, float g, float b, float _radius, 35 int _stack, int _slice); 36 void set_vertical_res(int _stack); 37 void set_horizontal_res(int _slice); 38 39 //display the sphere 40 void draw(GLUquadric* q); 41 void render(); 40 42 }; 41 43 -
trunk/vizservers/nanovis/Texture2D.cpp
r825 r953 1 1 2 /* 2 3 * ---------------------------------------------------------------------- … … 23 24 Texture2D::Texture2D(){} 24 25 25 Texture2D::Texture2D(int width, int height, GLuint type=GL_FLOAT, GLuint interp=GL_LINEAR, int n=4, float* data = 0) 26 Texture2D::Texture2D(int width, int height, GLuint type=GL_FLOAT, 27 GLuint interp=GL_LINEAR, int n=4, float* data = 0) 26 28 { 27 assert(type == GL_UNSIGNED_BYTE || type == GL_FLOAT|| type ==GL_UNSIGNED_INT); 28 assert(interp == GL_LINEAR || interp == GL_NEAREST); 29 30 this->width = width; 31 this->height = height; 32 this->type = type; 33 this->interp_type = interp; 34 this->n_components = n; 29 assert(type == GL_UNSIGNED_BYTE || 30 type == GL_FLOAT || 31 type ==GL_UNSIGNED_INT); 32 assert(interp == GL_LINEAR || interp == GL_NEAREST); 33 34 this->width = width; 35 this->height = height; 36 this->type = type; 37 this->interp_type = interp; 38 this->n_components = n; 35 39 36 40 this->id = 0; 37 41 38 39 42 if(data != 0) 43 initialize(data); 40 44 } 41 45 42 GLuint Texture2D::initialize(float *data) 46 GLuint 47 Texture2D::initialize(float *data) 43 48 { 44 49 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 45 50 46 47 48 51 glGenTextures(1, &id); 52 glBindTexture(GL_TEXTURE_2D, id); 53 assert(id!=-1); 49 54 50 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 51 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 52 53 if(interp_type == GL_LINEAR){ 54 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 55 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 56 } 57 else{ 58 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 59 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 60 } 61 62 //to do: add handling to more formats 63 if(type==GL_FLOAT){ 64 switch(n_components){ 65 #ifdef NV40 66 case 1: 67 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE16F_ARB, width, height, 0, GL_LUMINANCE, GL_FLOAT, data); 68 break; 69 case 2: 70 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA16F_ARB, width, height, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, data); 71 break; 72 case 3: 73 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F_ARB, width, height, 0, GL_RGB, GL_FLOAT, data); 74 break; 75 case 4: 76 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, width, height, 0, GL_RGBA, GL_FLOAT, data); 77 break; 78 #else 79 case 1: 80 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0, GL_LUMINANCE, GL_FLOAT, data); 81 break; 82 case 2: 83 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, width, height, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, data); 84 break; 85 case 3: 86 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_FLOAT, data); 87 break; 88 case 4: 89 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_FLOAT, data); 90 break; 91 #endif 92 default: 93 break; 94 } 95 } 96 else 97 { 98 int comp[5] = { -1, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA }; 99 glTexImage2D(GL_TEXTURE_2D, 0, comp[n_components], width, height, 0, GL_RGBA, type, data); 55 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 56 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 57 58 if(interp_type == GL_LINEAR){ 59 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 60 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 61 } else { 62 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 63 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 100 64 } 101 65 102 assert(glGetError()==0); 103 return id; 66 //to do: add handling to more formats 67 if (type==GL_FLOAT) { 68 switch(n_components){ 69 #ifdef NV40 70 case 1: 71 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE16F_ARB, width, height, 72 0, GL_LUMINANCE, GL_FLOAT, data); 73 break; 74 case 2: 75 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA16F_ARB, width, 76 height, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, data); 77 break; 78 case 3: 79 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F_ARB, width, height, 0, 80 GL_RGB, GL_FLOAT, data); 81 break; 82 case 4: 83 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, width, height, 0, 84 GL_RGBA, GL_FLOAT, data); 85 break; 86 #else 87 case 1: 88 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0, 89 GL_LUMINANCE, GL_FLOAT, data); 90 break; 91 case 2: 92 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, width, height, 93 0, GL_LUMINANCE_ALPHA, GL_FLOAT, data); 94 break; 95 case 3: 96 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, 97 GL_FLOAT, data); 98 break; 99 case 4: 100 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, 101 GL_FLOAT, data); 102 break; 103 #endif 104 default: 105 break; 106 } 107 } else { 108 int comp[5] = { -1, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA }; 109 glTexImage2D(GL_TEXTURE_2D, 0, comp[n_components], width, height, 0, 110 GL_RGBA, type, data); 111 } 112 assert(glGetError()==0); 113 return id; 104 114 } 105 115 106 116 107 void Texture2D::activate() 117 void 118 Texture2D::activate() 108 119 { 109 glBindTexture(GL_TEXTURE_2D, id);110 glEnable(GL_TEXTURE_2D);120 glBindTexture(GL_TEXTURE_2D, id); 121 glEnable(GL_TEXTURE_2D); 111 122 } 112 123 113 124 114 void Texture2D::deactivate() 125 void 126 Texture2D::deactivate() 115 127 { 116 glDisable(GL_TEXTURE_2D);128 glDisable(GL_TEXTURE_2D); 117 129 } 118 130 … … 120 132 Texture2D::~Texture2D() 121 133 { 122 glDeleteTextures(1, &id);134 glDeleteTextures(1, &id); 123 135 } 124 136 125 137 126 void Texture2D::check_max_size(){ 127 GLint max = 0; 128 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max); 129 130 fprintf(stderr, "max texture size: %d\n", max); 138 void 139 Texture2D::check_max_size(){ 140 GLint max = 0; 141 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max); 142 143 fprintf(stderr, "max texture size: %d\n", max); 131 144 } 132 145 133 void Texture2D::check_max_unit(){ 134 int max; 135 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &max); 146 void 147 Texture2D::check_max_unit(){ 148 int max; 149 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &max); 136 150 137 fprintf(stderr, "max texture units: %d.\n", max);151 fprintf(stderr, "max texture units: %d.\n", max); 138 152 } 139 153 -
trunk/vizservers/nanovis/transfer-function/ColorGradientGLUTWindow.cpp
r383 r953 1 1 2 /* 2 3 * ---------------------------------------------------------------------- … … 33 34 int cm_editState; 34 35 35 namespace ColorGradientWindow 36 { 37 int cm_numOfPoints; 38 39 bool cm_gvIsDragging=false; 40 bool cm_gvScaleDragging=false; 41 42 double distanceThreshold; 43 double gv_X, gv_Y; 44 double gv_DX, gv_DY; 45 double gv_lastX, gv_lastY; 36 namespace ColorGradientWindow { 37 int cm_numOfPoints; 38 39 bool cm_gvIsDragging=false; 40 bool cm_gvScaleDragging=false; 41 42 double distanceThreshold; 43 double gv_X, gv_Y; 44 double gv_DX, gv_DY; 45 double gv_lastX, gv_lastY; 46 46 }; 47 47 48 48 using namespace ColorGradientWindow; 49 49 50 51 52 50 //extern UnstructuredVolumeRenderer *uvol; 53 51 54 52 ColorGradientGLUTWindow::ColorGradientGLUTWindow() 55 53 { 56 map = new ColorGradient(); 57 } 58 59 60 ColorGradientGLUTWindow::~ColorGradientGLUTWindow(){ } 61 62 63 void ColorGradientGLUTWindow::cmInit(int main_win_x, int main_win_y) 64 { 65 mapOutput=(float*)malloc(3*sizeof(float)*mapNumOfOutput); 66 cm_winx=main_win_x; 67 //cm_winy=main_win_y/3; 68 cm_winy=100; 69 cm_unitWidth=tf_winx*0.95; 70 map=new ColorGradient(); 71 cm_editState=0; 72 cm_gvIsDragging=false; 73 cm_gvScaleDragging=false; 74 cm_gvSelectedPoint=0; 75 cm_numOfPoints=2; 76 gv_X=0; 77 gv_Y=0; 78 gv_DX=0; 79 gv_DY=0; 80 gv_lastX=0; 81 gv_lastY=0; 82 distanceThreshold=64; 83 84 if(mapOutput==0) 85 fprintf(stderr, "NULL"); 86 87 //initialize mapOutput 88 int i=0; 89 for (i=0; i<mapNumOfOutput; i++){ 90 color_table[i][0]=0; 91 } 92 } 93 94 95 96 void ColorGradientGLUTWindow::createGLUIWidgets(){ 97 cm_glui = GLUI_Master.create_glui_subwindow(colorMapWindow, GLUI_SUBWINDOW_BOTTOM); 98 pan=cm_glui->add_panel("buttons", GLUI_PANEL_NONE); 99 cm_glui->set_main_gfx_window(colorMapWindow); 100 cm_glui->add_column_to_panel(pan, false ); 101 cm_glui->add_statictext_to_panel(pan,"Color Controls:"); 102 cm_glui->add_column_to_panel(pan,false ); 103 cm_glui->add_button_to_panel(pan,"Add", 1, changeState); 104 cm_glui->add_column_to_panel(pan, false ); 105 cm_glui->add_button_to_panel(pan, "Edit", 2, changeState); 106 cm_glui->add_column_to_panel(pan, false ); 107 cm_glui->add_button_to_panel(pan, "Remove", 3, changeState); 54 map = new ColorGradient(); 55 } 56 57 58 ColorGradientGLUTWindow::~ColorGradientGLUTWindow() 59 { 60 } 61 62 void 63 ColorGradientGLUTWindow::cmInit(int main_win_x, int main_win_y) 64 { 65 mapOutput=(float*)malloc(3*sizeof(float)*mapNumOfOutput); 66 cm_winx=main_win_x; 67 //cm_winy=main_win_y/3; 68 cm_winy=100; 69 cm_unitWidth=tf_winx*0.95; 70 map=new ColorGradient(); 71 cm_editState=0; 72 cm_gvIsDragging=false; 73 cm_gvScaleDragging=false; 74 cm_gvSelectedPoint=0; 75 cm_numOfPoints=2; 76 gv_X=0; 77 gv_Y=0; 78 gv_DX=0; 79 gv_DY=0; 80 gv_lastX=0; 81 gv_lastY=0; 82 distanceThreshold=64; 83 84 if(mapOutput==0) 85 fprintf(stderr, "NULL"); 86 87 //initialize mapOutput 88 int i=0; 89 for (i=0; i<mapNumOfOutput; i++){ 90 color_table[i][0]=0; 91 } 92 } 93 94 95 96 void 97 ColorGradientGLUTWindow::createGLUIWidgets() 98 { 99 cm_glui = GLUI_Master.create_glui_subwindow(colorMapWindow, 100 GLUI_SUBWINDOW_BOTTOM); 101 pan=cm_glui->add_panel("buttons", GLUI_PANEL_NONE); 102 cm_glui->set_main_gfx_window(colorMapWindow); 103 cm_glui->add_column_to_panel(pan, false ); 104 cm_glui->add_statictext_to_panel(pan,"Color Controls:"); 105 cm_glui->add_column_to_panel(pan,false ); 106 cm_glui->add_button_to_panel(pan,"Add", 1, changeState); 107 cm_glui->add_column_to_panel(pan, false ); 108 cm_glui->add_button_to_panel(pan, "Edit", 2, changeState); 109 cm_glui->add_column_to_panel(pan, false ); 110 cm_glui->add_button_to_panel(pan, "Remove", 3, changeState); 108 111 } 109 112 … … 111 114 void update_tf_texture(); 112 115 113 void ColorGradientGLUTWindow::changeState(int arg){ 114 switch (arg){ 115 case 1: //add color 116 cm_editState=1; 117 break; 118 case 2: 119 //cm_editState=2; 120 ColorPalette::cpInit(); 121 update_tf_texture(); 122 break; 123 case 3: 124 cm_editState=3; 125 if (cm_gvSelectedPoint!=0) 126 map->removeKey(cm_gvSelectedPoint->x); 127 cm_editState=0; 128 update_tf_texture(); 129 break; 130 case 4: 131 cm_editState=4; 132 break; 133 134 default: 135 break; 136 } 137 } 138 139 140 141 void ColorGradientGLUTWindow::cmDisplay() 142 { 143 glClearColor( 1.0f, 1.0f, 1.0f, 1.0f ); 144 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 145 146 147 int i; 148 149 if(map == NULL){ 150 fprintf(stderr, "ColorGradient Window : forgot to bind the colorMap\n"); 151 return; 152 } 153 154 155 Color* leftColor=map->keyColors; 156 Color* rightColor; 157 ControlPoint* leftPoint=map->keyList; 158 ControlPoint* rightPoint; 159 double left_x, right_x; 160 GLfloat left_color[3]; 161 GLfloat right_color[3]; 162 163 164 //draw "rainbow" 165 glShadeModel(GL_SMOOTH); 166 glDisable(GL_DEPTH_TEST); 167 168 glBegin(GL_QUADS); 169 for(i=0; i<map->numOfKeys-1; i++){ 170 left_x=leftPoint->x; 171 leftColor->GetRGB(left_color); 172 173 rightColor=leftColor->next; 174 rightPoint=leftPoint->next; 175 right_x=rightPoint->x; 176 rightColor->GetRGB(right_color); 177 178 //printf("right=(%g, %g, %g)\n", right_color[0], right_color[1], right_color[2]); 179 glColor3f(left_color[0], left_color[1], left_color[2]); 180 glVertex2d(left_x, 0); 181 glVertex2d(left_x, cm_winy-10); 182 183 //printf("left=(%g, %g, %g)\n", left_color[0], left_color[1], left_color[2]); 184 glColor3f(right_color[0], right_color[1], right_color[2]); 185 glVertex2d(right_x, cm_winy-10); 186 glVertex2d(right_x, 0); 187 188 leftColor=leftColor->next; 189 leftPoint=leftPoint->next; 190 191 } 192 glEnd(); 193 glColor3f(0, 0, 0); 194 195 196 //draw bar 197 glLineWidth(1.0); 198 glBegin(GL_LINES); 199 glVertex2d(15, cm_winy-1); 200 glVertex2d(15+tf_unitWidth, cm_winy-1); 201 glEnd(); 202 203 204 i=0; 205 Color* curColor=map->keyColors; 206 ControlPoint* curKey=map->keyList; 207 for (i=0; i<map->numOfKeys ; i++){ 208 //glColor3d(curColor->R, curColor->G, curColor->B); 209 glColor3d(0.0, 0.0, 0.0); 210 curKey->glDraw_2(); 211 curColor=curColor->next; 212 curKey=curKey->next; 213 } 214 215 216 glColor3d(0.0, 0.0, 0.0); 217 glutSwapBuffers(); 218 } 219 220 221 222 223 void ColorGradientGLUTWindow::cmReshape(int x, int y) 224 { 225 //printf("cmReshape"); 226 cm_winx=x; 227 cm_winy=100; 228 229 230 double scale=((double)tf_winx*0.95)/((double)cm_unitWidth); 231 cm_unitWidth=tf_winx*0.95; 232 map->scaleKeys(scale, cm_unitWidth); 233 234 glViewport( 0, 0, x, y ); 235 236 glMatrixMode( GL_PROJECTION ); 237 glLoadIdentity(); 238 239 glMatrixMode(GL_MODELVIEW); 240 glLoadIdentity(); 241 242 //Set up most convenient projection 243 gluOrtho2D(0, x, 0, y); 244 glutPostRedisplay(); 245 } 246 247 248 249 250 void ColorGradientGLUTWindow::cmDestroy(){} 251 252 253 254 void ColorGradientGLUTWindow::cmKeyboard(unsigned char key, int x, int y){ 255 switch(key) 256 { 257 case 'p': 258 //printPoints(); 259 break; 260 case 'c': 261 printInterpolation(); 262 break; 263 default: 264 break; 265 } 266 } 267 268 269 270 void ColorGradientGLUTWindow::cmIdle(){ } 271 272 273 274 void ColorGradientGLUTWindow::cmMouse(int button, int state, int x, int y) 275 { 276 //printf("cm mouse\n"); 277 116 void 117 ColorGradientGLUTWindow::changeState(int arg) 118 { 119 switch (arg){ 120 case 1: //add color 121 cm_editState=1; 122 break; 123 case 2: 124 //cm_editState=2; 125 ColorPalette::cpInit(); 126 update_tf_texture(); 127 break; 128 case 3: 129 cm_editState=3; 130 if (cm_gvSelectedPoint!=0) 131 map->removeKey(cm_gvSelectedPoint->x); 132 cm_editState=0; 133 update_tf_texture(); 134 break; 135 case 4: 136 cm_editState=4; 137 break; 138 139 default: 140 break; 141 } 142 } 143 144 void 145 ColorGradientGLUTWindow::cmDisplay() 146 { 147 glClearColor( 1.0f, 1.0f, 1.0f, 1.0f ); 148 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 149 150 151 int i; 152 153 if(map == NULL){ 154 fprintf(stderr, "ColorGradient Window : forgot to bind the colorMap\n"); 155 return; 156 } 157 158 159 Color* leftColor=map->keyColors; 160 Color* rightColor; 161 ControlPoint* leftPoint=map->keyList; 162 ControlPoint* rightPoint; 163 double left_x, right_x; 164 GLfloat left_color[3]; 165 GLfloat right_color[3]; 166 167 168 //draw "rainbow" 169 glShadeModel(GL_SMOOTH); 170 glDisable(GL_DEPTH_TEST); 171 172 glBegin(GL_QUADS); 173 for(i=0; i<map->numOfKeys-1; i++){ 174 left_x=leftPoint->x; 175 leftColor->GetRGB(left_color); 176 177 rightColor=leftColor->next; 178 rightPoint=leftPoint->next; 179 right_x=rightPoint->x; 180 rightColor->GetRGB(right_color); 181 182 //printf("right=(%g, %g, %g)\n", right_color[0], right_color[1], right_color[2]); 183 glColor3f(left_color[0], left_color[1], left_color[2]); 184 glVertex2d(left_x, 0); 185 glVertex2d(left_x, cm_winy-10); 186 187 //printf("left=(%g, %g, %g)\n", left_color[0], left_color[1], left_color[2]); 188 glColor3f(right_color[0], right_color[1], right_color[2]); 189 glVertex2d(right_x, cm_winy-10); 190 glVertex2d(right_x, 0); 191 192 leftColor=leftColor->next; 193 leftPoint=leftPoint->next; 194 195 } 196 glEnd(); 197 glColor3f(0, 0, 0); 198 199 200 //draw bar 201 glLineWidth(1.0); 202 glBegin(GL_LINES); 203 glVertex2d(15, cm_winy-1); 204 glVertex2d(15+tf_unitWidth, cm_winy-1); 205 glEnd(); 206 207 208 i=0; 209 Color* curColor=map->keyColors; 210 ControlPoint* curKey=map->keyList; 211 for (i=0; i<map->numOfKeys ; i++){ 212 //glColor3d(curColor->R, curColor->G, curColor->B); 213 glColor3d(0.0, 0.0, 0.0); 214 curKey->glDraw_2(); 215 curColor=curColor->next; 216 curKey=curKey->next; 217 } 218 219 220 glColor3d(0.0, 0.0, 0.0); 221 glutSwapBuffers(); 222 } 223 224 225 226 227 void 228 ColorGradientGLUTWindow::cmReshape(int x, int y) 229 { 230 //printf("cmReshape"); 231 cm_winx=x; 232 cm_winy=100; 233 234 235 double scale=((double)tf_winx*0.95)/((double)cm_unitWidth); 236 cm_unitWidth=tf_winx*0.95; 237 map->scaleKeys(scale, cm_unitWidth); 238 239 glViewport( 0, 0, x, y ); 240 241 glMatrixMode( GL_PROJECTION ); 242 glLoadIdentity(); 243 244 glMatrixMode(GL_MODELVIEW); 245 glLoadIdentity(); 246 247 //Set up most convenient projection 248 gluOrtho2D(0, x, 0, y); 249 glutPostRedisplay(); 250 } 251 252 253 254 255 void 256 ColorGradientGLUTWindow::cmDestroy() 257 { 258 } 259 260 void 261 ColorGradientGLUTWindow::cmKeyboard(unsigned char key, int x, int y) 262 { 263 switch(key) { 264 case 'p': 265 //printPoints(); 266 break; 267 case 'c': 268 printInterpolation(); 269 break; 270 default: 271 break; 272 } 273 } 274 275 void 276 ColorGradientGLUTWindow::cmIdle() 277 { 278 } 279 280 void 281 ColorGradientGLUTWindow::cmMouse(int button, int state, int x, int y) 282 { 283 //printf("cm mouse\n"); 284 285 GLint viewportVector[4]; 286 double scX, scY; 287 288 glGetIntegerv(GL_VIEWPORT, viewportVector); 289 290 gv_X = scX = x; 291 gv_Y = scY = viewportVector[3] - (GLint) y - 1; 292 293 gv_lastY = scY; 294 295 //Selecting point, begin dragging 296 bool gvIsSelected = SelectPoint(scX, scY); 297 298 if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){ 299 300 if (gvIsSelected && cm_editState==0){ 301 //assert(cm_gvSelectedPoint!=NULL); 302 gv_DX = scX - cm_gvSelectedPoint->x; //Offset from current point to selected point, for dragging corrections 303 304 cm_gvSelectedPoint->dragged = true; 305 cm_gvIsDragging = true; 306 } 307 /*else if ((!gvIsSelected) && cm_editState==1){ 308 GLint viewportVector[4]; 309 double scX, scY; 310 311 glGetIntegerv(GL_VIEWPORT, viewportVector); 312 313 gv_X = scX = x; 314 gv_Y = scY = viewportVector[3] - (GLint) y - 1; 315 cm_gvSelectedPoint=map->addKey(scX - gv_DX, new Color(1,1,1)); 316 cm_editState=0; 317 WriteControlPoints(); 318 }*/ 319 } else if (button == GLUT_LEFT_BUTTON && state == GLUT_UP) { 320 //" End dragging" code. 321 cm_gvIsDragging = false; 322 if (cm_gvSelectedPoint) 323 cm_gvSelectedPoint->dragged = false; 324 } 325 if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) { 278 326 GLint viewportVector[4]; 279 327 double scX, scY; 280 328 281 329 glGetIntegerv(GL_VIEWPORT, viewportVector); 282 330 283 331 gv_X = scX = x; 284 332 gv_Y = scY = viewportVector[3] - (GLint) y - 1; 285 286 gv_lastY = scY; 287 288 //Selecting point, begin dragging 289 bool gvIsSelected = SelectPoint(scX, scY); 290 291 if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){ 292 293 if (gvIsSelected && cm_editState==0){ 294 //assert(cm_gvSelectedPoint!=NULL); 295 gv_DX = scX - cm_gvSelectedPoint->x; //Offset from current point to selected point, for dragging corrections 296 297 cm_gvSelectedPoint->dragged = true; 298 cm_gvIsDragging = true; 299 } 300 /*else if ((!gvIsSelected) && cm_editState==1){ 301 GLint viewportVector[4]; 302 double scX, scY; 303 304 glGetIntegerv(GL_VIEWPORT, viewportVector); 305 306 gv_X = scX = x; 307 gv_Y = scY = viewportVector[3] - (GLint) y - 1; 308 cm_gvSelectedPoint=map->addKey(scX - gv_DX, new Color(1,1,1)); 309 cm_editState=0; 310 WriteControlPoints(); 311 }*/ 312 } 313 314 315 316 317 else if (button == GLUT_LEFT_BUTTON && state == GLUT_UP){ 318 //" End dragging" code. 319 cm_gvIsDragging = false; 320 if (cm_gvSelectedPoint) 321 cm_gvSelectedPoint->dragged = false; 322 } 323 324 if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) 325 { 326 GLint viewportVector[4]; 327 double scX, scY; 328 329 glGetIntegerv(GL_VIEWPORT, viewportVector); 330 331 gv_X = scX = x; 332 gv_Y = scY = viewportVector[3] - (GLint) y - 1; 333 cm_gvSelectedPoint=map->addKey(scX - gv_DX, new Color(1,1,1)); 334 cm_editState=0; 335 WriteControlPoints(); 336 } 337 338 339 if (button == GLUT_MIDDLE_BUTTON && state == GLUT_DOWN) 340 cm_gvScaleDragging = true; 341 342 if (button == GLUT_MIDDLE_BUTTON && state == GLUT_UP) 343 cm_gvScaleDragging = false; 344 345 /////////////////////////// 346 glutSetWindow(colorMapWindow); 347 //////////////////////// 348 glutPostRedisplay(); 349 } 350 351 352 353 void ColorGradientGLUTWindow::cmMotion(int x, int y) 354 { 355 GLint viewportVector[4]; 356 double scX, scY; 357 358 glGetIntegerv(GL_VIEWPORT, viewportVector); 359 360 gv_X = scX = x; 361 gv_Y = scY = viewportVector[3] - (GLint) y - 1; 362 363 if (cm_gvIsDragging == true && cm_gvSelectedPoint!=NULL){ 364 //Dragging handling code. 365 cm_gvSelectedPoint->dragged = true; 366 367 368 ControlPoint* cur=map->keyList; 369 while (cur->next!=0){ 370 cur=cur->next; 371 } 372 373 //update x, y values for selected point 374 if (cm_gvSelectedPoint!=map->keyList && cm_gvSelectedPoint!=cur){ 375 376 cm_gvSelectedPoint->x = scX - gv_DX; 377 //not the first one, not the last one 378 cm_gvSelectedPoint->x = scX - gv_DX; 379 if (cm_gvSelectedPoint->x<=15){ 380 cm_gvSelectedPoint->x=16; 381 } 382 else if(cm_gvSelectedPoint->x>=15+cm_unitWidth){ 383 cm_gvSelectedPoint->x=15+cm_unitWidth-1; 384 } 385 386 boundaryChecking(); 387 WriteControlPoints(); 388 } 389 } 390 391 glutPostRedisplay(); 392 } 393 394 395 396 397 bool ColorGradientGLUTWindow::SelectPoint(double x, double y){ 398 399 //Reset selected/dragged flags 400 ControlPoint* cur=map->keyList; 401 while(cur!=0){ 402 cur->dragged=false; 403 cur->selected=false; 404 cur=cur->next; 405 } 406 407 cm_gvSelectedPoint = NULL; 408 409 //Traverse the points and find the one that seems close 410 cur=map->keyList; 411 while(cur!=0){ 412 double distanceSq; 413 distanceSq = (cur->x - x)*(cur->x - x) + (cur->y - y)*(cur->y - y); 414 if (distanceSq < distanceThreshold){ 415 cur->selected = true; 416 cm_gvSelectedPoint = cur; 417 return true; 418 } 419 cur=cur->next; 420 } 421 422 return false; 333 cm_gvSelectedPoint=map->addKey(scX - gv_DX, new Color(1,1,1)); 334 cm_editState=0; 335 WriteControlPoints(); 336 } 337 338 339 if (button == GLUT_MIDDLE_BUTTON && state == GLUT_DOWN) 340 cm_gvScaleDragging = true; 341 342 if (button == GLUT_MIDDLE_BUTTON && state == GLUT_UP) 343 cm_gvScaleDragging = false; 344 345 /////////////////////////// 346 glutSetWindow(colorMapWindow); 347 //////////////////////// 348 glutPostRedisplay(); 349 } 350 351 352 353 void 354 ColorGradientGLUTWindow::cmMotion(int x, int y) 355 { 356 GLint viewportVector[4]; 357 double scX, scY; 358 359 glGetIntegerv(GL_VIEWPORT, viewportVector); 360 361 gv_X = scX = x; 362 gv_Y = scY = viewportVector[3] - (GLint) y - 1; 363 364 if (cm_gvIsDragging == true && cm_gvSelectedPoint!=NULL){ 365 //Dragging handling code. 366 cm_gvSelectedPoint->dragged = true; 367 368 369 ControlPoint* cur=map->keyList; 370 while (cur->next!=0){ 371 cur=cur->next; 372 } 373 374 //update x, y values for selected point 375 if (cm_gvSelectedPoint!=map->keyList && cm_gvSelectedPoint!=cur){ 376 377 cm_gvSelectedPoint->x = scX - gv_DX; 378 //not the first one, not the last one 379 cm_gvSelectedPoint->x = scX - gv_DX; 380 if (cm_gvSelectedPoint->x<=15){ 381 cm_gvSelectedPoint->x=16; 382 } 383 else if(cm_gvSelectedPoint->x>=15+cm_unitWidth){ 384 cm_gvSelectedPoint->x=15+cm_unitWidth-1; 385 } 386 387 boundaryChecking(); 388 WriteControlPoints(); 389 } 390 } 391 392 glutPostRedisplay(); 393 } 394 395 bool 396 ColorGradientGLUTWindow::SelectPoint(double x, double y) 397 { 398 //Reset selected/dragged flags 399 ControlPoint* cur=map->keyList; 400 while(cur!=0){ 401 cur->dragged=false; 402 cur->selected=false; 403 cur=cur->next; 404 } 405 406 cm_gvSelectedPoint = NULL; 407 408 //Traverse the points and find the one that seems close 409 cur=map->keyList; 410 while(cur!=0){ 411 double distanceSq; 412 distanceSq = (cur->x - x)*(cur->x - x) + (cur->y - y)*(cur->y - y); 413 if (distanceSq < distanceThreshold){ 414 cur->selected = true; 415 cm_gvSelectedPoint = cur; 416 return true; 417 } 418 cur=cur->next; 419 } 420 421 return false; 423 422 } 424 423 … … 426 425 void update_tf_texture(); 427 426 428 void ColorGradientGLUTWindow::WriteControlPoints() 429 { 430 431 //special case: all points have the same color 432 Color* curColor=map->keyColors; 433 int allSameY=1; 434 int R=map->keyColors->R; 435 int G=map->keyColors->G; 436 int B=map->keyColors->B; 437 while (curColor!=0){ 438 if (curColor->R!=R || curColor->G!=G || curColor->B!=B){ 439 allSameY=0; 440 break; 441 } 442 curColor=curColor->next; 443 } 444 445 if (allSameY==1){ 446 int i=0; 447 448 for(i=0;i<mapNumOfOutput;i++){ 449 color_table[i][0]=R; 450 color_table[i][1]=G; 451 color_table[i][2]=B; 452 } 453 return; 454 } 455 456 float unit=(float)cm_unitWidth/(float)mapNumOfOutput; 457 458 curColor=map->keyColors; 459 Color* nextColor=curColor->next; 460 461 double r1=curColor->R*255; 462 double g1=curColor->G*255; 463 double b1=curColor->B*255; 464 465 double r2=nextColor->R*255; 466 double g2=nextColor->G*255; 467 double b2=nextColor->B*255; 468 469 ControlPoint* curPoint=map->keyList; 470 ControlPoint* nextPoint=curPoint->next; 471 472 double x1=curPoint->x; 473 double x2=nextPoint->x; 474 475 float t=0; 476 477 int i=0; 478 for(i=0;i<numOfOutput;i++){ 479 480 if (unit*i+15>x2){ 481 //go to next line segment 482 curColor=nextColor; 483 nextColor=nextColor->next; 484 485 curPoint=nextPoint; 486 nextPoint=nextPoint->next; 487 488 if (nextColor==0 || nextPoint==0){ 489 return; 490 } 491 492 x1=curPoint->x; 493 x2=nextPoint->x; 494 495 r1=curColor->R*255; 496 g1=curColor->G*255; 497 b1=curColor->B*255; 498 499 r2=nextColor->R*255; 500 g2=nextColor->G*255; 501 b2=nextColor->B*255; 502 503 } 504 t=((float)(unit*i+15-x1))/((float)(x2-x1)); 505 506 color_table[i][0]=(float)(r1+t*(r2-r1))/(float)255; 507 color_table[i][1]=(float)(g1+t*(g2-g1))/(float)255; 508 color_table[i][2]=(float)(b1+t*(b2-b1))/(float)255; 509 } 510 511 update_tf_texture(); 512 glutSetWindow(colorMapWindow); 513 } 514 515 516 ControlPoint* ColorGradientGLUTWindow::boundaryChecking(){ 517 //find left and right neighbor in the list 518 //If point is dragged passing the neighbor, the points are reordered. 519 520 ControlPoint* left=map->keyList; 521 ControlPoint* right=map->keyList; 522 523 while (right!=cm_gvSelectedPoint){ 524 left=right; 525 right=right->next; 526 } 527 528 //selected point is not the right-end point 529 if (right->next!=0){ 530 right=right->next; 531 if (cm_gvSelectedPoint->x>right->x){ 532 sortPoints(); 533 } 534 } 535 536 //selected point is not the left-end point 537 if (left!=cm_gvSelectedPoint) { 538 if (cm_gvSelectedPoint->x<left->x){ 539 sortPoints(); 540 } 541 } 542 543 return cm_gvSelectedPoint; 427 void 428 ColorGradientGLUTWindow::WriteControlPoints() 429 { 430 431 //special case: all points have the same color 432 Color* curColor=map->keyColors; 433 int allSameY=1; 434 int R=map->keyColors->R; 435 int G=map->keyColors->G; 436 int B=map->keyColors->B; 437 while (curColor!=0){ 438 if (curColor->R!=R || curColor->G!=G || curColor->B!=B){ 439 allSameY=0; 440 break; 441 } 442 curColor=curColor->next; 443 } 444 445 if (allSameY==1){ 446 int i=0; 447 448 for(i=0;i<mapNumOfOutput;i++){ 449 color_table[i][0]=R; 450 color_table[i][1]=G; 451 color_table[i][2]=B; 452 } 453 return; 454 } 455 456 float unit=(float)cm_unitWidth/(float)mapNumOfOutput; 457 458 curColor=map->keyColors; 459 Color* nextColor=curColor->next; 460 461 double r1=curColor->R*255; 462 double g1=curColor->G*255; 463 double b1=curColor->B*255; 464 465 double r2=nextColor->R*255; 466 double g2=nextColor->G*255; 467 double b2=nextColor->B*255; 468 469 ControlPoint* curPoint=map->keyList; 470 ControlPoint* nextPoint=curPoint->next; 471 472 double x1=curPoint->x; 473 double x2=nextPoint->x; 474 475 float t=0; 476 477 int i=0; 478 for(i=0;i<numOfOutput;i++){ 479 480 if (unit*i+15>x2){ 481 //go to next line segment 482 curColor=nextColor; 483 nextColor=nextColor->next; 484 485 curPoint=nextPoint; 486 nextPoint=nextPoint->next; 487 488 if (nextColor==0 || nextPoint==0){ 489 return; 490 } 491 492 x1=curPoint->x; 493 x2=nextPoint->x; 494 495 r1=curColor->R*255; 496 g1=curColor->G*255; 497 b1=curColor->B*255; 498 499 r2=nextColor->R*255; 500 g2=nextColor->G*255; 501 b2=nextColor->B*255; 502 503 } 504 t=((float)(unit*i+15-x1))/((float)(x2-x1)); 505 506 color_table[i][0]=(float)(r1+t*(r2-r1))/(float)255; 507 color_table[i][1]=(float)(g1+t*(g2-g1))/(float)255; 508 color_table[i][2]=(float)(b1+t*(b2-b1))/(float)255; 509 } 510 511 update_tf_texture(); 512 glutSetWindow(colorMapWindow); 513 } 514 515 516 ControlPoint* 517 ColorGradientGLUTWindow::boundaryChecking() 518 { 519 //find left and right neighbor in the list 520 //If point is dragged passing the neighbor, the points are reordered. 521 522 ControlPoint* left=map->keyList; 523 ControlPoint* right=map->keyList; 524 525 while (right!=cm_gvSelectedPoint){ 526 left=right; 527 right=right->next; 528 } 529 530 //selected point is not the right-end point 531 if (right->next!=0){ 532 right=right->next; 533 if (cm_gvSelectedPoint->x>right->x){ 534 sortPoints(); 535 } 536 } 537 538 //selected point is not the left-end point 539 if (left!=cm_gvSelectedPoint) { 540 if (cm_gvSelectedPoint->x<left->x){ 541 sortPoints(); 542 } 543 } 544 545 return cm_gvSelectedPoint; 544 546 } 545 547 546 548 547 549 //sort all controlpoints by bubble sort 548 void ColorGradientGLUTWindow::sortPoints(){ 549 if (map->numOfKeys==0) 550 return; 551 552 //bubble-sort list in ascending order by X 553 ControlPoint* cur; 554 ControlPoint* pre; 555 ControlPoint* a; 556 ControlPoint* b; 557 cur=map->keyList; 558 559 Color* curColor; 560 Color* preColor; 561 Color* c; 562 Color* d; 563 curColor=map->keyColors; 564 565 int i; 566 for(i=0;i<map->numOfKeys-1;i++){ 567 while (cur->next!=NULL){ 568 if (cur->x > cur->next->x){ 569 if (cur==map->keyList){ 570 //first node 571 a=map->keyList; 572 b=map->keyList->next; 573 a->next=b->next; 574 b->next=a; 575 map->keyList=b; 576 cur=map->keyList; 577 578 c=map->keyColors; 579 d=map->keyColors->next; 580 c->next=d->next; 581 d->next=c; 582 map->keyColors=d; 583 curColor=map->keyColors; 584 } 585 else { 586 a=cur; 587 b=cur->next; 588 a->next=b->next; 589 b->next=a; 590 pre->next=b; 591 cur=b; 592 593 c=curColor; 594 d=curColor->next; 595 c->next=d->next; 596 d->next=c; 597 preColor->next=d; 598 curColor=d; 599 } 600 } 601 pre=cur; 602 cur=cur->next; 603 604 preColor=curColor; 605 curColor=curColor->next; 606 } 607 cur=map->keyList; 608 curColor=map->keyColors; 609 } 610 WriteControlPoints(); 611 } 612 613 614 615 void ColorGradientGLUTWindow::printInterpolation(){ 616 int i=0; 617 for(i=0;i<numOfOutput;i++){ 618 //printf("(%g,%g,%g) ", mapOutput[3*i], mapOutput[3*i+1], mapOutput[3*i+2]); 619 fprintf(stderr, "(%g,%g,%g) ", color_table[i][0], color_table[i][1], color_table[i][2]); 620 } 621 } 622 623 550 void 551 ColorGradientGLUTWindow::sortPoints() 552 { 553 if (map->numOfKeys==0) 554 return; 555 556 //bubble-sort list in ascending order by X 557 ControlPoint* cur; 558 ControlPoint* pre; 559 ControlPoint* a; 560 ControlPoint* b; 561 cur=map->keyList; 562 563 Color* curColor; 564 Color* preColor; 565 Color* c; 566 Color* d; 567 curColor=map->keyColors; 568 569 preColor = NULL; /* Suppress compiler warning. */ 570 pre = NULL; 571 572 int i; 573 for(i=0;i<map->numOfKeys-1;i++){ 574 while (cur->next!=NULL){ 575 if (cur->x > cur->next->x){ 576 if (cur==map->keyList){ 577 //first node 578 a=map->keyList; 579 b=map->keyList->next; 580 a->next=b->next; 581 b->next=a; 582 map->keyList=b; 583 cur=map->keyList; 584 585 c=map->keyColors; 586 d=map->keyColors->next; 587 c->next=d->next; 588 d->next=c; 589 map->keyColors=d; 590 curColor=map->keyColors; 591 } 592 else { 593 a=cur; 594 b=cur->next; 595 a->next=b->next; 596 b->next=a; 597 pre->next=b; 598 cur=b; 599 600 c=curColor; 601 d=curColor->next; 602 c->next=d->next; 603 d->next=c; 604 preColor->next=d; 605 curColor=d; 606 } 607 } 608 pre=cur; 609 cur=cur->next; 610 611 preColor=curColor; 612 curColor=curColor->next; 613 } 614 cur=map->keyList; 615 curColor=map->keyColors; 616 } 617 WriteControlPoints(); 618 } 619 620 621 622 void 623 ColorGradientGLUTWindow::printInterpolation() 624 { 625 int i=0; 626 for(i=0;i<numOfOutput;i++){ 627 //printf("(%g,%g,%g) ", mapOutput[3*i], mapOutput[3*i+1], mapOutput[3*i+2]); 628 fprintf(stderr, "(%g,%g,%g) ", color_table[i][0], color_table[i][1], color_table[i][2]); 629 } 630 } -
trunk/vizservers/nanovis/transfer-function/ColorPaletteWindow.cpp
r380 r953 1 1 2 /* 2 3 * ---------------------------------------------------------------------- … … 24 25 int cpWinId; 25 26 int cp_winx, cp_winy; 26 int cp_color_r, cp_color_g, cp_color_b; 27 int cp_color_r, cp_color_g, cp_color_b; //the RGB model 27 28 int cp_color_H, cp_color_S, cp_color_B; //the HSB model 28 29 int color_model; … … 33 34 34 35 35 namespace ColorPaletteWindow 36 { 37 int cpwin_pos_x = 100; 38 int cpwin_pos_y = 425; 39 enum colorMode{RGB, GRAY, HSB}; 40 Color* hue_color; 41 ControlPoint* color_point_1; 42 ControlPoint* color_point_2; 43 44 //char fileName[255]; 45 static char* fileName= new char[255];// (char*) malloc(sizeof(char)*256); 46 47 36 namespace ColorPaletteWindow { 37 int cpwin_pos_x = 100; 38 int cpwin_pos_y = 425; 39 enum colorMode{RGB, GRAY, HSB}; 40 Color* hue_color; 41 ControlPoint* color_point_1; 42 ControlPoint* color_point_2; 43 44 //char fileName[255]; 45 static char* fileName= new char[255];// (char*) malloc(sizeof(char)*256); 48 46 }; 49 47 … … 60 58 } 61 59 62 void ColorPalette::cpSyncLive(){ 63 if (cp_glui!=0){ 64 cp_glui->sync_live(); 65 } 60 void ColorPalette::cpSyncLive() 61 { 62 if (cp_glui!=0){ 63 cp_glui->sync_live(); 64 } 66 65 } 67 66 68 67 void ColorPalette::cpInit() 69 68 { 70 color_model = 0; 71 72 //fileName=(char*) malloc(sizeof(char)*30); 73 for(int i=0;i<200;i++){ 74 fileName[i]=0; 75 } 76 77 cp_winx = 430; 78 cp_winy = 350; 79 80 hue_color=new Color(1,0,0); 81 color_point_1=new ControlPoint(0,cp_winy); 82 color_point_2=new ControlPoint(0,2*cp_winy/3-15); 83 84 glutInitWindowPosition( cpwin_pos_x, cpwin_pos_y); 85 glutInitWindowSize( cp_winx, cp_winy ); 69 color_model = 0; 70 71 //fileName=(char*) malloc(sizeof(char)*30); 72 for(int i=0;i<200;i++){ 73 fileName[i]=0; 74 } 75 cp_winx = 430; 76 cp_winy = 350; 77 78 hue_color=new Color(1,0,0); 79 color_point_1=new ControlPoint(0,cp_winy); 80 color_point_2=new ControlPoint(0,2*cp_winy/3-15); 81 82 glutInitWindowPosition( cpwin_pos_x, cpwin_pos_y); 83 glutInitWindowSize( cp_winx, cp_winy ); 86 84 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 85 colorPaletteWindow = glutCreateWindow("Color Palette"); 86 87 glutDisplayFunc( cpDisplay ); 88 glutReshapeFunc( cpReshape ); 89 glutKeyboardFunc ( cpKeyboard ); 90 glutIdleFunc (cpIdle); 91 glutMouseFunc (cpMouse); 92 glutMotionFunc (cpMotion); 93 94 95 GLUI_Master.set_glutReshapeFunc(cpReshape); 96 GLUI_Master.set_glutDisplayFunc( cpDisplay ); 97 GLUI_Master.set_glutKeyboardFunc(cpKeyboard); 98 GLUI_Master.set_glutSpecialFunc(NULL); 99 GLUI_Master.set_glutMouseFunc(cpMouse); 100 GLUI_Master.set_glutIdleFunc(cpIdle); 101 102 createGLUIWidgets(); 105 103 } 106 104 … … 109 107 110 108 void ColorPalette::cmdHandler(int arg){ 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 TransferFunctionGLUTWindow::cleanUpPoints(); 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 color_B->disable(); 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 color_B->enable(); 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 109 switch (arg){ 110 case 1: //add color 111 cm_editState=1; 112 break; 113 case 2: 114 if (cm_gvSelectedPoint!=0) 115 map->changeColor((double)cp_color_r/255, (double)cp_color_g/255, (double)cp_color_b/255); 116 update_tf_texture(); 117 break; 118 case 3: 119 if (cm_gvSelectedPoint!=0) 120 map->removeKey(cm_gvSelectedPoint->x); 121 update_tf_texture(); 122 break; 123 case 4: 124 MainTransferFunctionWindow::loadFile(fileName); 125 break; 126 case 5: 127 MainTransferFunctionWindow::saveFile(fileName); 128 break; 129 case 6: 130 map->cleanUp(); 131 update_tf_texture(); 132 break; 133 case 7: 134 TransferFunctionGLUTWindow::cleanUpPoints(); 135 //map->cleanUp(); 136 update_tf_texture(); 137 break; 138 case 8: 139 if (color_model==0){ 140 color_r->enable(); 141 color_g->enable(); 142 color_b->enable(); 143 144 cp_color_r=255; 145 cp_color_g=0; 146 cp_color_b=0; 147 148 color_H->disable(); 149 color_S->disable(); 150 color_B->disable(); 151 152 cp_color_H=0; 153 cp_color_S=0; 154 cp_color_B=0; 155 156 color_point_1->x=0; 157 color_point_1->y=cp_winy; 158 159 cp_glui->sync_live(); 160 } 161 else if (color_model==1){ 162 color_r->enable(); 163 color_g->enable(); 164 color_b->enable(); 165 166 cp_color_r=0; 167 cp_color_g=0; 168 cp_color_b=0; 169 170 color_H->disable(); 171 color_S->disable(); 172 color_B->disable(); 173 174 cp_color_H=0; 175 cp_color_S=0; 176 cp_color_B=0; 177 178 color_point_1->x=0; 179 color_point_1->y=cp_winy; 180 181 cp_glui->sync_live(); 182 } 183 else if (color_model==2){ 184 color_r->enable(); 185 color_g->enable(); 186 color_b->enable(); 187 188 cp_color_r=255; 189 cp_color_g=255; 190 cp_color_b=255; 191 192 color_H->enable(); 193 color_S->enable(); 194 color_B->enable(); 195 196 cp_color_H=0; 197 cp_color_S=100; 198 cp_color_B=100; 199 200 color_point_1->x=0; 201 color_point_1->y=cp_winy; 202 203 color_point_2->x=0; 204 205 cp_glui->sync_live(); 206 } 207 208 glutSetWindow(colorPaletteWindow); 209 glutPostRedisplay(); 210 break; 211 case 9: 212 break; 213 case 10: 214 break; 215 216 default: 217 break; 218 } 221 219 } 222 220 223 221 224 222 void ColorPalette::openFile(){ 225 223 226 224 } 227 225 … … 230 228 231 229 void ColorPalette::createGLUIWidgets(){ 232 233 234 235 236 color_r= cp_glui->add_spinner("R:", GLUI_SPINNER_INT, &cp_color_r); 237 238 239 240 241 242 243 244 245 246 247 color_H= cp_glui->add_spinner("H:Deg.", GLUI_SPINNER_INT, &cp_color_H); 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 230 cp_glui = GLUI_Master.create_glui_subwindow(colorPaletteWindow, GLUI_SUBWINDOW_BOTTOM); 231 cp_glui->set_main_gfx_window(colorPaletteWindow); 232 //cp_glui->add_column( false ); 233 cp_glui->add_statictext("RGB Color:"); 234 color_r= cp_glui->add_spinner("R:", GLUI_SPINNER_INT, &cp_color_r); 235 color_r->set_int_limits(0, 255, GLUI_LIMIT_CLAMP); 236 color_r->set_alignment(GLUI_ALIGN_CENTER); 237 color_g= cp_glui->add_spinner("G:", GLUI_SPINNER_INT, &cp_color_g); 238 color_g->set_int_limits(0, 255, GLUI_LIMIT_CLAMP); 239 color_g->set_alignment(GLUI_ALIGN_CENTER); 240 color_b = cp_glui->add_spinner("B:", GLUI_SPINNER_INT, &cp_color_b); 241 color_b->set_int_limits(0, 255, GLUI_LIMIT_CLAMP); 242 color_b->set_alignment(GLUI_ALIGN_CENTER); 243 244 cp_glui->add_statictext("HSB Color:"); 245 color_H= cp_glui->add_spinner("H:Deg.", GLUI_SPINNER_INT, &cp_color_H); 246 color_H->set_int_limits(0, 360, GLUI_LIMIT_CLAMP); 247 color_H->set_alignment(GLUI_ALIGN_CENTER); 248 color_H->disable(); 249 color_S= cp_glui->add_spinner("S:%", GLUI_SPINNER_INT, &cp_color_S); 250 color_S->set_int_limits(0, 100, GLUI_LIMIT_CLAMP); 251 color_S->set_alignment(GLUI_ALIGN_CENTER); 252 color_S->disable(); 253 color_B = cp_glui->add_spinner("B:%", GLUI_SPINNER_INT, &cp_color_B); 254 color_B->set_int_limits(0, 100, GLUI_LIMIT_CLAMP); 255 color_B->set_alignment(GLUI_ALIGN_CENTER); 256 color_B->disable(); 257 258 259 cp_glui->add_column(true); 260 261 GLUI_Panel* model_panel=cp_glui->add_panel("Color Model", GLUI_PANEL_EMBOSSED); 262 GLUI_RadioGroup* model=cp_glui->add_radiogroup_to_panel(model_panel,&color_model, 8, cmdHandler); 263 cp_glui->add_radiobutton_to_group(model, "RGB"); 264 cp_glui->add_radiobutton_to_group(model, "Grayscale"); 265 cp_glui->add_radiobutton_to_group(model, "HSB"); 266 267 cp_glui->add_statictext("Color Controls:"); 268 //cp_glui->add_button("Add Color", 1, cmdHandler); 269 cp_glui->add_button("Set Color", 2, cmdHandler); 270 cp_glui->add_button("Remove Color", 3, cmdHandler); 271 272 cp_glui->add_separator(); 273 274 cp_glui->add_button("Reset Colormap", 6, cmdHandler); 275 cp_glui->add_button("Reset TF", 7, cmdHandler); 276 277 278 cp_glui->add_column(true); 279 cp_glui->add_statictext("File:"); 280 cp_glui->add_edittext("Name: ",GLUI_EDITTEXT_TEXT, fileName); 281 cp_glui->add_button("Load", 4, cmdHandler); 282 cp_glui->add_button("Save", 5, cmdHandler); 283 284 cp_glui->add_separator(); 285 cp_glui->add_spinner("Scale:", GLUI_SPINNER_FLOAT, &control_point_scale); 286 eye_distance_label = cp_glui->add_statictext("Eye Distance: "); 287 fps_label = cp_glui->add_statictext("FPS: "); 290 288 } 291 289 292 290 293 291 void ColorPalette::cpIdle(){ 294 295 292 //glutSetWindow(mainWindow); 293 //glutPostRedisplay(); 296 294 } 297 295 … … 300 298 301 299 void ColorPalette::confirm(int arg){ 302 303 304 305 306 307 308 309 300 if (cm_gvSelectedPoint!=0) 301 map->changeColor((double)cp_color_r/255, (double)cp_color_g/255, (double)cp_color_b/255); 302 /* 303 glutSetWindow(mainWindow); 304 glutDestroyWindow(colorPaletteWindow); 305 glutPostRedisplay(); 306 colorPaletteWindow=-1; 307 */ 310 308 } 311 309 … … 314 312 void ColorPalette::cpDisplay() 315 313 { 316 //draw selectPoint 317 //drawSelectPoint(); 318 319 glClearColor( 1.0f, 1.0f, 1.0f, 1.0f ); 320 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 321 322 323 glColor3d(0.0, 0.0, 0.0); 324 glShadeModel(GL_SMOOTH); 325 glDisable(GL_DEPTH_TEST); 326 327 328 if (color_model==RGB){ 329 330 Color* leftColor = new Color(1, 0, 0); 331 Color* rightColor = new Color(0, 0, 1); 332 333 GLfloat left_color[3]; 334 GLfloat right_color[3]; 335 336 leftColor->GetRGB(left_color); 337 rightColor->GetRGB(right_color); 338 339 //predifined 7 rainbow colors 340 GLfloat color_red[3] = {1, 0, 0}; 341 GLfloat color_yelo[3] = {1, 1, 0}; 342 GLfloat color_green[3] = {0, 1, 0}; 343 GLfloat color_aqua[3] = {0, 1, 1}; 344 GLfloat color_blue[3] = {0, 0, 1}; 345 GLfloat color_magen[3] = {1, 0, 1}; 346 347 348 GLfloat rainbowColor[18] = {1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1}; 349 350 int i=0; 351 float unitWidth = cp_winx/6; 352 353 glBegin(GL_QUADS); 354 for (i=0; i<6; i++){ 355 356 glColor3f(rainbowColor[3*i], rainbowColor[3*i+1], rainbowColor[3*i+2]); 357 glVertex2d(unitWidth*i, 0); 358 glVertex2d(unitWidth*i, cp_winy); 359 360 if (i==5){ 361 glColor3f(rainbowColor[0], rainbowColor[1], rainbowColor[2]); 362 glVertex2d(cp_winx, cp_winy); 363 glVertex2d(cp_winx, 0); 364 } 365 else { 366 glColor3f(rainbowColor[3*i+3], rainbowColor[3*i+4], rainbowColor[3*i+5]); 367 glVertex2d(unitWidth*(i+1), cp_winy); 368 glVertex2d(unitWidth*(i+1), 0); 369 } 370 } 371 glEnd(); 372 373 //draw color point 374 glColor3d(0,0,0); 375 color_point_1->glDraw_3(); 376 } 377 378 else if (color_model==GRAY){ 379 glBegin(GL_QUADS); 380 glColor3f(0, 0, 0); 381 glVertex2d(0, 0); 382 glVertex2d(0, cp_winy); 383 384 glColor3f(1, 1, 1); 385 glVertex2d(cp_winx, cp_winy); 386 glVertex2d(cp_winx, 0); 387 glEnd(); 388 389 glColor3d(1,0,0); 390 color_point_1->glDraw_3(); 391 } 392 393 else if(color_model==HSB){ 394 395 glBegin(GL_QUADS); 396 glColor3f(0, 0, 0); 397 glVertex2d(0, 2*cp_winy/3); 398 glColor3f(1, 1, 1); 399 glVertex2d(0, cp_winy); 400 401 glColor3f(hue_color->R, hue_color->G, hue_color->B); 402 glVertex2d(cp_winx, cp_winy); 403 glColor3f(0, 0, 0); 404 glVertex2d(cp_winx, 2*cp_winy/3); 405 glEnd(); 406 407 //draw rainbow 408 Color* leftColor = new Color(1, 0, 0); 409 Color* rightColor = new Color(0, 0, 1); 410 411 GLfloat left_color[3]; 412 GLfloat right_color[3]; 413 414 leftColor->GetRGB(left_color); 415 rightColor->GetRGB(right_color); 416 417 //predifined 7 rainbow colors 418 GLfloat color_red[3] = {1, 0, 0}; 419 GLfloat color_yelo[3] = {1, 1, 0}; 420 GLfloat color_green[3] = {0, 1, 0}; 421 GLfloat color_aqua[3] = {0, 1, 1}; 422 GLfloat color_blue[3] = {0, 0, 1}; 423 GLfloat color_magen[3] = {1, 0, 1}; 424 425 426 GLfloat rainbowColor[18] = {1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1}; 427 428 int i=0; 429 float unitWidth = cp_winx/6; 430 431 glBegin(GL_QUADS); 432 for (i=0; i<6; i++){ 433 434 glColor3f(rainbowColor[3*i], rainbowColor[3*i+1], rainbowColor[3*i+2]); 435 glVertex2d(unitWidth*i, 2*cp_winy/3-15); 436 glVertex2d(unitWidth*i, 2*cp_winy/3); 437 438 if (i==5){ 439 glColor3f(rainbowColor[0], rainbowColor[1], rainbowColor[2]); 440 glVertex2d(cp_winx, 2*cp_winy/3); 441 glVertex2d(cp_winx, 2*cp_winy/3-15); 442 } 443 else { 444 glColor3f(rainbowColor[3*i+3], rainbowColor[3*i+4], rainbowColor[3*i+5]); 445 glVertex2d(unitWidth*(i+1), 2*cp_winy/3); 446 glVertex2d(unitWidth*(i+1), 2*cp_winy/3-15); 447 } 448 } 449 glEnd(); 450 451 glColor3d(1-hue_color->R, 1-hue_color->G, 1-hue_color->B); 452 color_point_1->glDraw_3(); 453 454 glColor3d(0,0,0); 455 color_point_2->glDraw_2(); 456 /* 457 //draw bar 458 glLineWidth(1.0); 459 glBegin(GL_LINES); 460 glVertex2d(0, cp_winy/2-1); 461 glVertex2d(cp_winx, cp_winy/2-1); 462 glEnd(); 463 */ 464 465 /* 466 i=0; 467 Color* curColor=map->keyColors; 468 ControlPoint* curKey=map->keyList; 469 for (i=0; i<map->numOfKeys ; i++){ 470 //glColor3d(curColor->R, curColor->G, curColor->B); 471 glColor3d(0.0, 0.0, 0.0); 472 curKey->glDraw_2(); 473 curColor=curColor->next; 474 curKey=curKey->next; 475 } 476 */ 477 478 } 479 480 glColor3f(0, 0, 0); 481 glutSwapBuffers(); 314 //draw selectPoint 315 //drawSelectPoint(); 316 317 glClearColor( 1.0f, 1.0f, 1.0f, 1.0f ); 318 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 319 320 321 glColor3d(0.0, 0.0, 0.0); 322 glShadeModel(GL_SMOOTH); 323 glDisable(GL_DEPTH_TEST); 324 325 326 if (color_model==RGB){ 327 328 Color* leftColor = new Color(1, 0, 0); 329 Color* rightColor = new Color(0, 0, 1); 330 331 GLfloat left_color[3]; 332 GLfloat right_color[3]; 333 334 leftColor->GetRGB(left_color); 335 rightColor->GetRGB(right_color); 336 337 GLfloat rainbowColor[18] = { 338 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1 339 }; 340 341 int i=0; 342 float unitWidth = cp_winx/6; 343 344 glBegin(GL_QUADS); 345 for (i=0; i<6; i++){ 346 347 glColor3f(rainbowColor[3*i], rainbowColor[3*i+1], rainbowColor[3*i+2]); 348 glVertex2d(unitWidth*i, 0); 349 glVertex2d(unitWidth*i, cp_winy); 350 351 if (i==5){ 352 glColor3f(rainbowColor[0], rainbowColor[1], rainbowColor[2]); 353 glVertex2d(cp_winx, cp_winy); 354 glVertex2d(cp_winx, 0); 355 } 356 else { 357 glColor3f(rainbowColor[3*i+3], rainbowColor[3*i+4], rainbowColor[3*i+5]); 358 glVertex2d(unitWidth*(i+1), cp_winy); 359 glVertex2d(unitWidth*(i+1), 0); 360 } 361 } 362 glEnd(); 363 364 //draw color point 365 glColor3d(0,0,0); 366 color_point_1->glDraw_3(); 367 } 368 369 else if (color_model==GRAY){ 370 glBegin(GL_QUADS); 371 glColor3f(0, 0, 0); 372 glVertex2d(0, 0); 373 glVertex2d(0, cp_winy); 374 375 glColor3f(1, 1, 1); 376 glVertex2d(cp_winx, cp_winy); 377 glVertex2d(cp_winx, 0); 378 glEnd(); 379 380 glColor3d(1,0,0); 381 color_point_1->glDraw_3(); 382 } 383 384 else if(color_model==HSB){ 385 386 glBegin(GL_QUADS); 387 glColor3f(0, 0, 0); 388 glVertex2d(0, 2*cp_winy/3); 389 glColor3f(1, 1, 1); 390 glVertex2d(0, cp_winy); 391 392 glColor3f(hue_color->R, hue_color->G, hue_color->B); 393 glVertex2d(cp_winx, cp_winy); 394 glColor3f(0, 0, 0); 395 glVertex2d(cp_winx, 2*cp_winy/3); 396 glEnd(); 397 398 //draw rainbow 399 Color* leftColor = new Color(1, 0, 0); 400 Color* rightColor = new Color(0, 0, 1); 401 402 GLfloat left_color[3]; 403 GLfloat right_color[3]; 404 405 leftColor->GetRGB(left_color); 406 rightColor->GetRGB(right_color); 407 408 GLfloat rainbowColor[18] = { 409 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1 410 }; 411 412 int i=0; 413 float unitWidth = cp_winx/6; 414 415 glBegin(GL_QUADS); 416 for (i=0; i<6; i++){ 417 418 glColor3f(rainbowColor[3*i], rainbowColor[3*i+1], rainbowColor[3*i+2]); 419 glVertex2d(unitWidth*i, 2*cp_winy/3-15); 420 glVertex2d(unitWidth*i, 2*cp_winy/3); 421 422 if (i==5){ 423 glColor3f(rainbowColor[0], rainbowColor[1], rainbowColor[2]); 424 glVertex2d(cp_winx, 2*cp_winy/3); 425 glVertex2d(cp_winx, 2*cp_winy/3-15); 426 } 427 else { 428 glColor3f(rainbowColor[3*i+3], rainbowColor[3*i+4], rainbowColor[3*i+5]); 429 glVertex2d(unitWidth*(i+1), 2*cp_winy/3); 430 glVertex2d(unitWidth*(i+1), 2*cp_winy/3-15); 431 } 432 } 433 glEnd(); 434 435 glColor3d(1-hue_color->R, 1-hue_color->G, 1-hue_color->B); 436 color_point_1->glDraw_3(); 437 438 glColor3d(0,0,0); 439 color_point_2->glDraw_2(); 440 /* 441 //draw bar 442 glLineWidth(1.0); 443 glBegin(GL_LINES); 444 glVertex2d(0, cp_winy/2-1); 445 glVertex2d(cp_winx, cp_winy/2-1); 446 glEnd(); 447 */ 448 449 /* 450 i=0; 451 Color* curColor=map->keyColors; 452 ControlPoint* curKey=map->keyList; 453 for (i=0; i<map->numOfKeys ; i++){ 454 //glColor3d(curColor->R, curColor->G, curColor->B); 455 glColor3d(0.0, 0.0, 0.0); 456 curKey->glDraw_2(); 457 curColor=curColor->next; 458 curKey=curKey->next; 459 } 460 */ 461 462 } 463 464 glColor3f(0, 0, 0); 465 glutSwapBuffers(); 482 466 } 483 467 … … 486 470 487 471 void ColorPalette::cpReshape(int x, int y){ 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 472 //printf("cpreshape=%d",x); 473 474 if (x==0 || y==0) 475 return; 476 477 cp_winx=x; 478 cp_winy=y; 479 glViewport( 0, 0, x, y ); 480 481 glMatrixMode( GL_PROJECTION ); 482 glLoadIdentity(); 483 484 glMatrixMode(GL_MODELVIEW); 485 glLoadIdentity(); 486 487 //Set up most convenient projection 488 gluOrtho2D(0, x, 0, y); 489 glutPostRedisplay(); 506 490 } 507 491 … … 509 493 void ColorPalette::cpKeyboard(unsigned char key, int x, int y) 510 494 { 511 495 //glutPostRedisplay(); 512 496 } 513 497 … … 516 500 void ColorPalette::cpMouse(int button, int state, int x, int y){ 517 501 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 502 GLint viewportVector[4]; 503 GLdouble scX, scY; //the coordinates of selection point on rainbow 504 505 glGetIntegerv(GL_VIEWPORT, viewportVector); 506 507 scX = x; 508 scY = viewportVector[3] - (GLint) y - 1; 509 510 511 if (color_model!=HSB){ 512 color_point_1->x=scX; 513 color_point_1->y=scY; 514 } 515 else{ //HSB 516 if (scY>=2*cp_winy/3){ 517 color_point_1->x=scX; 518 color_point_1->y=scY; 519 getColor(scX, scY); 520 } 521 if (scY<2*cp_winy/3){ 522 color_point_2->x=scX; 523 //color_point_1->x=0; 524 //color_point_1->y=cp_winy; 525 getColor(scX, color_point_2->y); 526 } 527 } 528 //printf("(%g, %g)\n", scX, scY); 529 530 531 if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){ 532 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){} 537 538 cp_glui->sync_live(); 539 glutPostRedisplay(); 556 540 557 541 } … … 565 549 //interpolate GRB color 566 550 Color ColorPalette::getColor(int x, int y){ 567 568 float unitWidth = cp_winx/6; 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 float unitWidth = cp_winx/6; 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 //printf("(%d,%d,%d)", cp_color_r, cp_color_g, cp_color_b);665 666 667 668 669 670 671 672 } 551 if (color_model==RGB){ 552 float unitWidth = cp_winx/6; 553 GLfloat rainbowColor[21] = {1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0}; 554 555 int pos = floor(x/unitWidth); 556 int red_left = rainbowColor[3*pos]; 557 int red_right = rainbowColor[3*(pos+1)]; 558 559 int green_left = rainbowColor[3*pos+1]; 560 int green_right = rainbowColor[3*(pos+1)+1]; 561 562 int blue_left = rainbowColor[3*pos+2]; 563 int blue_right = rainbowColor[3*(pos+1)+2]; 564 565 double r, g, b; 566 r = (red_left+((float)x/(float)unitWidth-pos)*(red_right-red_left)); 567 g = (green_left+((float)x/(float)unitWidth-pos)*(green_right-green_left)); 568 b = (blue_left+((float)x/(float)unitWidth-pos)*(blue_right-blue_left)); 569 570 cp_color_r=255*r; 571 cp_color_g=255*g; 572 cp_color_b=255*b; 573 574 575 cp_glui->sync_live(); 576 return Color(r,g,b); 577 } 578 579 else if (color_model==GRAY){ 580 float t=((float)x)/((float)cp_winx); 581 double r, g, b; 582 r = t; 583 g = t; 584 b = t; 585 586 cp_color_r=255*r; 587 cp_color_g=255*g; 588 cp_color_b=255*b; 589 590 cp_glui->sync_live(); 591 return Color(r,g,b); 592 } 593 594 else if (color_model==HSB){ 595 double r, g, b; 596 if (y==color_point_2->y){ 597 float unitWidth = cp_winx/6; 598 GLfloat rainbowColor[21] = {1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0}; 599 600 int pos = floor(x/unitWidth); 601 int red_left = rainbowColor[3*pos]; 602 int red_right = rainbowColor[3*(pos+1)]; 603 604 int green_left = rainbowColor[3*pos+1]; 605 int green_right = rainbowColor[3*(pos+1)+1]; 606 607 int blue_left = rainbowColor[3*pos+2]; 608 int blue_right = rainbowColor[3*(pos+1)+2]; 609 610 611 r = (red_left+((float)x/(float)unitWidth-pos)*(red_right-red_left)); 612 g = (green_left+((float)x/(float)unitWidth-pos)*(green_right-green_left)); 613 b = (blue_left+((float)x/(float)unitWidth-pos)*(blue_right-blue_left)); 614 615 cp_color_H=360*((double)x/(double)cp_winx); 616 617 hue_color->R=r; 618 hue_color->G=g; 619 hue_color->B=b; 620 621 } 622 else{ 623 cp_color_S=100*(1-(double)color_point_1->x/(double)cp_winx); 624 cp_color_B=100*((double)(color_point_1->y-(double)(2*cp_winy/3))/((double)cp_winy/3)); 625 } 626 627 //convert HSB to RGB 628 629 //1. horizontal interpolation: 630 //upper left: (1,1,1) 631 //upper right: hue color 632 r=(double)1+(double)color_point_1->x/((double)cp_winx)*(double)(hue_color->R-1); 633 g=(double)1+(double)color_point_1->x/((double)cp_winx)*(double)(hue_color->G-1); 634 b=(double)1+(double)color_point_1->x/((double)cp_winx)*(double)(hue_color->B-1); 635 636 //2. vertical interpolation: 637 //buttom (0,0,0) 638 r=(double)r+((double)cp_winy-(double)color_point_1->y)/((double)cp_winy/3)*((double)(0-r)); 639 g=(double)g+((double)cp_winy-(double)color_point_1->y)/((double)cp_winy/3)*((double)(0-g)); 640 b=(double)b+((double)cp_winy-(double)color_point_1->y)/((double)cp_winy/3)*((double)(0-b)); 641 642 cp_color_r=255*r; 643 cp_color_g=255*g; 644 cp_color_b=255*b; 645 646 647 648 //printf("(%d,%d,%d) ", cp_color_r, cp_color_g, cp_color_b); 649 650 cp_glui->sync_live(); 651 652 return Color(r,g,b); 653 } 654 655 return Color(0,0,0); 656 } -
trunk/vizservers/nanovis/transfer-function/TransferFunctionGLUTWindow.cpp
r383 r953 1 1 2 /* 2 3 * ---------------------------------------------------------------------- … … 49 50 { 50 51 51 int winx = 600;52 int winy = 150;53 54 int unitHeight;55 56 double gv_X, gv_Y;57 double gv_lastY;58 59 bool gvScaleDragging=false;60 61 double gv_DX, gv_DY;62 63 float lv_tf_height_scale = 2.0;64 float last_lv_tf_height_scale= 2.0;65 66 float lv_tf_width_scale = 1.0;67 float last_lv_tf_width_scale= 1.0;52 int winx = 600; 53 int winy = 150; 54 55 int unitHeight; 56 57 double gv_X, gv_Y; 58 double gv_lastY; 59 60 bool gvScaleDragging=false; 61 62 double gv_DX, gv_DY; 63 64 float lv_tf_height_scale = 2.0; 65 float last_lv_tf_height_scale= 2.0; 66 67 float lv_tf_width_scale = 1.0; 68 float last_lv_tf_width_scale= 1.0; 68 69 69 70 }; … … 88 89 { 89 90 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 } 109 110 111 112 113 114 91 //initialize the global list of contorlPoint "tf_pointList" 92 tf_winx=main_window_x; 93 tf_winy=main_window_y*2/3; 94 95 unitHeight = 0.8*tf_winy; 96 tf_unitWidth = 0.95*tf_winx; 97 98 99 //printf("tf_unitWidth=%d\n", tf_unitWidth); 100 101 102 tf_pointList = new ControlPoint(15,15); 103 tf_pointList->next = new ControlPoint(15+tf_unitWidth,15); 104 105 int i=0; 106 for(i=0;i<numOfOutput;i++){ 107 //output[i]=0; 108 color_table[i][3]=0; 109 } 110 tf_numOfPoints=2; 111 tf_pointEditState=0; 112 113 tf_gvSelectedPoint = new ControlPoint(0,0); 114 115 fprintf(stderr, "Transferfunction Init...\n"); 115 116 } 116 117 … … 121 122 { 122 123 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 char label[3]; 168 169 /* 170 while (15+k*unitHeight/lv_tf_height_scale < winy){171 172 173 174 175 176 177 178 179 180 181 182 183 */ 184 185 //printf("tf_unitWidth=%d\n", tf_unitWidth); 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 glVertex2d(winx, 15); 213 214 215 216 217 218 219 glutSwapBuffers();124 glClearColor( 1.0f, 1.0f, 1.0f, 1.0f ); 125 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 126 127 128 glColor3d(0, 0, 0); 129 130 //draw x and y axis 131 glBegin(GL_LINES); 132 glVertex2d(15, 15); 133 glVertex2d(15, winy); 134 135 glVertex2d(15, 15); 136 glVertex2d(winx, 15); 137 glEnd(); 138 139 //printf("tf_unitWidth=%d\n", tf_unitWidth); 140 141 //draw label for X 142 glRasterPos2f(2, 2); 143 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, '0'); 144 145 glRasterPos2f(18+tf_unitWidth, 2); 146 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, '1'); 147 148 149 //draw marker on axis 150 glLineWidth(2.0); 151 glBegin(GL_LINES); 152 glVertex2d(15+tf_unitWidth, 20); 153 glVertex2d(15+tf_unitWidth, 15); 154 155 int k; 156 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 } 163 glEnd(); 164 glLineWidth(1.0); 165 166 //draw label for Y 167 k = 1; 168 169 #ifdef notdef 170 char label[3]; 171 while (15+k*unitHeight/lv_tf_height_scale < winy) { 172 glRasterPos2f(2,15+k*unitHeight/lv_tf_height_scale); 173 label[0]=0; 174 label[1]=0; 175 label[2]=0; 176 itoa(k, label, 10); 177 int i=0; 178 while (label[i]!=0){ 179 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, label[i]); 180 i++; 181 } 182 k++; 183 } 184 printf("tf_unitWidth=%d\n", tf_unitWidth); 185 #endif 186 187 188 //draw all points 189 ControlPoint* cur=tf_pointList; 190 while(cur!=0){ 191 cur->glDraw(); 192 cur=cur->next; 193 } 194 195 glEnable(GL_LINE_SMOOTH); 196 glLineWidth(2.0); 197 198 199 //connect all points 200 cur=tf_pointList; 201 glBegin(GL_LINES); 202 glVertex2d(cur->x, cur->y); 203 204 while (cur!=0){ 205 if (cur->next!=0){ 206 glVertex2d(cur->x, cur->y); 207 glVertex2d(cur->x, cur->y); 208 } 209 else 210 glVertex2d(cur->x, cur->y); 211 cur=cur->next; 212 } 213 glVertex2d(winx, 15); 214 glEnd(); 215 216 glLineWidth(1.0); 217 glDisable(GL_LINE_SMOOTH); 218 plotHist(); 219 220 glutSwapBuffers(); 220 221 221 222 } … … 225 226 bool TransferFunctionGLUTWindow::SelectPoint(double x, double y) 226 227 { 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 228 //printf("select point\n"); 229 230 if (tf_numOfPoints==0) 231 return false; 232 233 //Reset selected/dragged flags 234 ControlPoint* cur=tf_pointList; 235 while(cur!=0){ 236 cur->dragged=false; 237 cur->selected=false; 238 cur=cur->next; 239 } 240 241 tf_gvSelectedPoint = NULL; 242 243 //Traverse the points and find the one that seems close 244 cur=tf_pointList; 245 while(cur!=0){ 246 double distanceSq; 247 distanceSq = (cur->x - x)*(cur->x - x) + (cur->y - y)*(cur->y - y); 248 249 if (distanceSq < distanceThreshold){ 250 cur->selected = true; 251 tf_gvSelectedPoint = cur; 252 return true; 253 } 254 cur=cur->next; 255 } 256 257 return false; 257 258 } 258 259 … … 260 261 void TransferFunctionGLUTWindow::tfMouse(int button, int state, int x, int y) 261 262 { 262 263 264 265 266 267 268 269 270 271 272 273 274 275 bool gvIsSelected = SelectPoint(scX, scY); 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 //"End dragging" code.302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 263 //printf("tf mouse\n"); 264 //printf("(%d,%d)\n", x, y); 265 GLint viewportVector[4]; 266 double scX, scY; 267 268 glGetIntegerv(GL_VIEWPORT, viewportVector); 269 270 gv_X = scX = x; 271 gv_Y = scY = viewportVector[3] - (GLint) y - 1; 272 273 gv_lastY = scY; 274 275 //Selecting point, begin dragging 276 bool gvIsSelected = SelectPoint(scX, scY); 277 278 if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){ 279 280 if (gvIsSelected && tf_pointEditState==0){ 281 assert(tf_gvSelectedPoint!=NULL); 282 gv_DX = scX - tf_gvSelectedPoint->x; //Offset from current point to selected point, for dragging corrections 283 gv_DY = scY - tf_gvSelectedPoint->y; 284 285 tf_gvSelectedPoint->dragged = true; 286 tf_gvIsDragging = true; 287 } 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 { 310 GLint viewportVector[4]; 311 double scX, scY; 312 313 glGetIntegerv(GL_VIEWPORT, viewportVector); 314 315 gv_X = scX = x; 316 gv_Y = scY = viewportVector[3] - (GLint) y - 1; 317 tf_gvSelectedPoint=addPoint(scX - gv_DX,scY - gv_DY); 318 tf_pointEditState=0; 319 WriteControlPoints(); 320 } 321 322 323 324 if (button == GLUT_MIDDLE_BUTTON && state == GLUT_DOWN) 325 gvScaleDragging = true; 326 327 if (button == GLUT_MIDDLE_BUTTON && state == GLUT_UP) 328 gvScaleDragging = false; 329 330 glutPostRedisplay(); 330 331 } 331 332 … … 334 335 { 335 336 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 boundaryChecking(); 377 378 379 380 381 382 383 384 } 385 386 387 388 337 GLint viewportVector[4]; 338 double scX, scY; 339 340 glGetIntegerv(GL_VIEWPORT, viewportVector); 341 342 gv_X = scX = x; 343 gv_Y = scY = viewportVector[3] - (GLint) y - 1; 344 345 if (tf_gvIsDragging == true && tf_gvSelectedPoint!=NULL){ 346 //Dragging handling code. 347 tf_gvSelectedPoint->dragged = true; 348 349 350 ControlPoint* cur=tf_pointList; 351 while (cur->next!=0){ 352 cur=cur->next; 353 } 354 355 //update x, y values for selected point 356 if (tf_gvSelectedPoint!=tf_pointList && tf_gvSelectedPoint!=cur){ 357 //not the first one, not the last one 358 tf_gvSelectedPoint->x = scX - gv_DX; 359 if (tf_gvSelectedPoint->x<=15){ 360 tf_gvSelectedPoint->x=16; 361 } 362 else if(tf_gvSelectedPoint->x>=15+tf_unitWidth){ 363 tf_gvSelectedPoint->x=15+tf_unitWidth-1; 364 } 365 } 366 tf_gvSelectedPoint->y = scY - gv_DY; 367 368 369 //Boundary conditions, so we can't drag point away from the screen. 370 if (scY - gv_DY > viewportVector[3]) 371 tf_gvSelectedPoint->y = viewportVector[3] - 1; 372 //points can't be dragged below x axis 373 if (scY - gv_DY < 15) 374 tf_gvSelectedPoint->y = 15; 375 376 377 boundaryChecking(); 378 } 379 380 if (gvScaleDragging == true){ 381 last_lv_tf_height_scale=lv_tf_height_scale; 382 lv_tf_height_scale += (scY - gv_lastY)*0.007; 383 gv_lastY = scY; 384 scalePointsY(scY - gv_lastY); 385 } 386 387 WriteControlPoints(); 388 389 glutPostRedisplay(); 389 390 } 390 391 391 392 void TransferFunctionGLUTWindow::tfIdle(){ 392 393 394 395 396 397 398 399 400 401 393 /* 394 glutSetWindow(tfWinId); 395 glutPostRedisplay(); 396 397 glutSetWindow(cmWinId); 398 glutPostRedisplay(); 399 400 glutSetWindow(cpWinId); 401 glutPostRedisplay(); 402 */ 402 403 } 403 404 404 405 void TransferFunctionGLUTWindow::tfKeyboard(unsigned char key, int x, int y){ 405 406 407 case 'q':408 409 410 case 'a':411 412 413 case 'd':414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 }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 } 442 443 } 443 444 … … 445 446 void TransferFunctionGLUTWindow::tfReshape(int x, int y){ 446 447 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 448 //do not accept 0 value!!! 449 if (x==0 || y==0) 450 return; 451 452 453 last_lv_tf_height_scale=lv_tf_height_scale; 454 lv_tf_height_scale=lv_tf_height_scale*y/winy; 455 456 last_lv_tf_width_scale= lv_tf_width_scale; 457 lv_tf_width_scale=lv_tf_width_scale*x/winx; 458 scalePointsX(); 459 460 float xy_aspect; 461 462 //lastWinx= winx; 463 //lastWiny= winy; 464 465 winx = x; 466 winy = y; 467 468 unitHeight = 0.8*y; 469 tf_unitWidth = 0.95*x; 470 471 xy_aspect = (float)x / (float)y; 472 glViewport( 0, 0, x, y ); 473 474 glMatrixMode( GL_PROJECTION ); 475 glLoadIdentity(); 476 477 //Set up most convenient projection 478 gluOrtho2D(0, x, 0, y); 479 glutPostRedisplay(); 479 480 } 480 481 … … 485 486 void TransferFunctionGLUTWindow::ReadControlPoints() 486 487 { 487 488 //read the live variables and update the points. 488 489 } 489 490 … … 493 494 void TransferFunctionGLUTWindow::WriteControlPoints() 494 495 { 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 } 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 } 496 497 //special case: all points have the same y coordinates 498 double rangeY=0; 499 float unitY=0; 500 float unitX=0; 501 double maxY=tf_pointList->y; 502 double maxX=tf_pointList->x; 503 504 //special case: all points have the same y coordinates,generate an error 505 ControlPoint* cur=tf_pointList; 506 int allSameY=1; 507 int y=tf_pointList->y; 508 while (cur!=0){ 509 if (cur->y!=y){ 510 allSameY=0; 511 break; 512 } 513 cur=cur->next; 514 } 515 516 517 if (allSameY==1){ 518 int i=0; 519 for(i=0;i<numOfOutput;i++){ 520 //output[i]=0; 521 color_table[i][3]=0; 522 } 523 return; 524 } 525 526 //get max Y 527 cur=tf_pointList; 528 while (cur!=0){ 529 if (cur->y>maxY){ 530 maxY=cur->y; 531 } 532 if (cur->x>maxX){ 533 maxX=cur->x; 534 } 535 cur=cur->next; 536 } 537 538 539 //get min Y 540 cur=tf_pointList; 541 double minY=maxY; 542 while (cur!=0){ 543 if (cur->y<minY){ 544 minY=cur->y; 545 } 546 cur=cur->next; 547 } 548 549 //range of Y 550 rangeY=maxY-minY; 551 552 tfMaximum = ((float) rangeY) / (unitHeight/lv_tf_height_scale); 553 554 //unit to map [0,1] to [0, rangeY] 555 unitY=1/(float)rangeY; 556 unitX=(float)(maxX-15)/(float)numOfOutput; 557 558 cur=tf_pointList; 559 ControlPoint* next=cur->next; 560 double x1=cur->x; 561 double y1=(cur->y)-minY; 562 double x2=next->x; 563 double y2=(next->y)-minY; 564 float slope=((float)(y2-y1))/((float)(x2-x1)); 565 float t; //t=(x-a)/(b-a) 566 567 int i=0; 568 for(i=0;i<numOfOutput;i++){ 569 570 if (unitX*i+15>x2){ 571 //go to next line segment 572 cur=next; 573 next=next->next; 574 if (next==0){ 575 return; 576 } 577 x1=cur->x; 578 y1=cur->y-minY; 579 x2=next->x; 580 y2=next->y-minY; 581 582 slope=((float)(y2-y1))/((float)(x2-x1)); 583 } 584 t=((float)(unitX*i+15-x1))/((float)(x2-x1)); 585 //output[i] = (y1+t*(y2-y1))/rangeY; 586 color_table[i][3]=control_point_scale*(y1+t*(y2-y1))/rangeY; 587 } 588 589 update_tf_texture(); 590 glutSetWindow(transferFunctionWindow); 591 } 591 592 592 593 … … 594 595 595 596 void TransferFunctionGLUTWindow::printInterpolation(){ 596 597 598 599 600 601 602 597 WriteControlPoints(); 598 int i=0; 599 for(i=0;i<numOfOutput;i++){ 600 //printf("%f, ",output[i]); 601 fprintf(stderr, "%f, ",color_table[i][3]); 602 } 603 fprintf(stderr, "\n"); 603 604 } 604 605 … … 606 607 607 608 //sort all controlpoints by bubble sort 608 void TransferFunctionGLUTWindow::sortPoints(){ 609 if (tf_numOfPoints==0) 610 return; 611 612 //bubble-sort list in ascending order by X 613 ControlPoint* cur; 614 ControlPoint* pre; 615 ControlPoint* a; 616 ControlPoint* b; 617 cur=tf_pointList; 618 619 int i; 620 for(i=0;i<tf_numOfPoints-1;i++){ 621 while (cur->next!=NULL){ 622 if (cur->x > cur->next->x){ 623 if (cur==tf_pointList){ 624 //first node 625 a=tf_pointList; 626 b=tf_pointList->next; 627 a->next=b->next; 628 b->next=a; 629 tf_pointList=b; 630 cur=tf_pointList; 631 } 632 else { 633 a=cur; 634 b=cur->next; 635 a->next=b->next; 636 b->next=a; 637 pre->next=b; 638 cur=b; 639 } 640 } 641 pre=cur; 642 cur=cur->next; 643 } 644 cur=tf_pointList; 645 } 646 WriteControlPoints(); 647 } 648 649 650 ControlPoint* TransferFunctionGLUTWindow::addPoint(double x, double y){ 651 //check if x is between first and last point 652 //if not return without adding point 653 ControlPoint* last=tf_pointList; 654 while (last->next!=0){ 655 last=last->next; 656 } 657 if (x<15 || x>last->x || y<15){ 658 return tf_pointList; 659 } 660 661 662 663 664 ControlPoint* cur=tf_pointList; 665 ControlPoint* pre=cur; 666 667 668 //if x is the first or last. Don't add, but update. 669 if(x==cur->x){ 670 cur->y=y; 671 return tf_pointList; 672 } 673 else if(x==last->x){ 674 last->y=y; 675 return last; 676 } 677 678 679 while (cur->next!=0){ 680 if (x<=cur->x){ 681 ControlPoint* newPoint=new ControlPoint(x,y); 682 if (cur==tf_pointList){ 683 newPoint->next=tf_pointList; 684 tf_pointList=newPoint; 685 } 686 else{ 687 newPoint->next=pre->next; 688 pre->next=newPoint; 689 } 690 tf_numOfPoints++; 691 //map->addKey(x, new Color(0,0,0)); 692 return newPoint; 693 } 694 pre=cur; 695 cur=cur->next; 696 } 697 698 if (x<=cur->x){ 699 ControlPoint* newPoint=new ControlPoint(x,y); 700 newPoint->next=pre->next; 701 pre->next=newPoint; 702 tf_numOfPoints++; 703 //map->addKey(x, new Color(0,0,0)); 704 return newPoint; 705 } 706 else { 707 cur->next=new ControlPoint(x,y); 708 tf_numOfPoints++; 709 //map->addKey(x, new Color(0,0,0)); 710 return cur->next; 711 } 712 } 713 714 715 716 void TransferFunctionGLUTWindow::removePoint(void* ptr){ 717 if (tf_numOfPoints==0) 718 return; 719 720 ControlPoint* last=tf_pointList; 721 while (last->next!=0){ 722 last=last->next; 723 } 724 725 if (ptr==tf_pointList || ptr==last){ 726 /* 727 if (tf_numOfPoints=1){ 728 delete(ptr); 729 tf_pointList=0; 730 } 731 else{ 732 tf_pointList=tf_pointList->next; 733 delete(ptr); 734 } 735 */ 736 return; 737 } 738 else { 739 //find the previous point 740 ControlPoint* cur=tf_pointList; 741 ControlPoint* pre=cur; 742 while (cur->next!=0){ 743 if (cur==ptr){ 744 break; 745 } 746 pre=cur; 747 cur=cur->next; 748 } 749 pre->next=cur->next; 750 map->removeKey(cur->x); 751 delete(cur); 752 } 753 tf_numOfPoints--; 609 void 610 TransferFunctionGLUTWindow::sortPoints() 611 { 612 if (tf_numOfPoints==0) 613 return; 614 615 //bubble-sort list in ascending order by X 616 ControlPoint* cur; 617 ControlPoint* pre; 618 ControlPoint* a; 619 ControlPoint* b; 620 cur=tf_pointList; 621 622 int i; 623 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){ 628 //first node 629 a=tf_pointList; 630 b=tf_pointList->next; 631 a->next=b->next; 632 b->next=a; 633 tf_pointList=b; 634 cur=tf_pointList; 635 } else { 636 a=cur; 637 b=cur->next; 638 a->next=b->next; 639 b->next=a; 640 pre->next=b; 641 cur=b; 642 } 643 } 644 pre=cur; 645 cur=cur->next; 646 } 647 cur=tf_pointList; 648 } 649 WriteControlPoints(); 650 } 651 652 653 ControlPoint* 654 TransferFunctionGLUTWindow::addPoint(double x, double y) 655 { 656 //check if x is between first and last point 657 //if not return without adding point 658 ControlPoint* last=tf_pointList; 659 while (last->next!=0){ 660 last=last->next; 661 } 662 if (x<15 || x>last->x || y<15){ 663 return tf_pointList; 664 } 665 666 ControlPoint* cur=tf_pointList; 667 ControlPoint* pre=cur; 668 669 //if x is the first or last. Don't add, but update. 670 if(x==cur->x) { 671 cur->y=y; 672 return tf_pointList; 673 } else if(x==last->x) { 674 last->y=y; 675 return last; 676 } 677 678 while (cur->next!=0) { 679 if (x<=cur->x){ 680 ControlPoint* newPoint=new ControlPoint(x,y); 681 if (cur==tf_pointList) { 682 newPoint->next=tf_pointList; 683 tf_pointList=newPoint; 684 } else { 685 newPoint->next=pre->next; 686 pre->next=newPoint; 687 } 688 tf_numOfPoints++; 689 //map->addKey(x, new Color(0,0,0)); 690 return newPoint; 691 } 692 pre=cur; 693 cur=cur->next; 694 } 695 696 if (x<=cur->x) { 697 ControlPoint* newPoint=new ControlPoint(x,y); 698 newPoint->next=pre->next; 699 pre->next=newPoint; 700 tf_numOfPoints++; 701 //map->addKey(x, new Color(0,0,0)); 702 return newPoint; 703 } else { 704 cur->next=new ControlPoint(x,y); 705 tf_numOfPoints++; 706 //map->addKey(x, new Color(0,0,0)); 707 return cur->next; 708 } 709 } 710 711 712 713 void 714 TransferFunctionGLUTWindow::removePoint(void* ptr) 715 { 716 if (tf_numOfPoints==0) 717 return; 718 719 ControlPoint* last=tf_pointList; 720 while (last->next!=0){ 721 last=last->next; 722 } 723 724 if (ptr==tf_pointList || ptr==last){ 725 /* 726 if (tf_numOfPoints=1){ 727 delete(ptr); 728 tf_pointList=0; 729 } 730 else{ 731 tf_pointList=tf_pointList->next; 732 delete(ptr); 733 } 734 */ 735 return; 736 } else { 737 //find the previous point 738 ControlPoint* cur=tf_pointList; 739 ControlPoint* pre=cur; 740 while (cur->next!=0){ 741 if (cur==ptr) { 742 break; 743 } 744 pre=cur; 745 cur=cur->next; 746 } 747 pre->next=cur->next; 748 map->removeKey(cur->x); 749 delete(cur); 750 } 751 tf_numOfPoints--; 754 752 } 755 753 … … 757 755 //remove all points but the two initial points 758 756 void TransferFunctionGLUTWindow::cleanUpPoints(){ 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 757 if (tf_numOfPoints<2) 758 return; 759 760 ControlPoint* cur=tf_pointList; 761 762 if (tf_numOfPoints==2){ 763 cur->x=15; 764 cur->y=15; 765 766 cur->next->x=15+tf_unitWidth; 767 cur->next->y=15; 768 return; 769 } 770 771 772 cur=tf_pointList->next; 773 ControlPoint* pre=tf_pointList; 774 775 while (cur->next!=0){ 776 if(pre!=tf_pointList) 777 delete(pre); 778 pre=cur; 779 cur=cur->next; 780 } 781 782 delete(pre); 783 tf_pointList->next=cur; 784 785 786 tf_pointList->x=15; 787 tf_pointList->y=15; 788 789 tf_pointList->next->x=15+tf_unitWidth; 790 tf_pointList->next->y=15; 791 792 tf_numOfPoints=2; 793 TransferFunctionGLUTWindow::WriteControlPoints(); 796 794 } 797 795 … … 801 799 802 800 //debugging: print out all points 803 void TransferFunctionGLUTWindow::printPoints(){ 804 ControlPoint* cur=tf_pointList; 805 fprintf(stderr, "********************\n"); 806 fprintf(stderr, "Total points %d \n", tf_numOfPoints); 807 808 if (tf_numOfPoints==0) 809 return; 810 811 while (cur->next!=0){ 812 fprintf(stderr, "(%g,%g)\n", cur->x, cur->y); 813 cur=cur->next; 814 } 815 fprintf(stderr, "(%g,%g)\n", cur->x, cur->y); 816 fprintf(stderr, "********************\n"); 817 } 818 819 820 ControlPoint* TransferFunctionGLUTWindow::boundaryChecking(){ 821 assert(tf_gvSelectedPoint!=0); 822 assert(tf_pointList!=0); 823 //find left and right neighbor in the list 824 //If point is dragged passing the neighbor, the points are reordered. 825 826 ControlPoint* left=tf_pointList; 827 ControlPoint* right=tf_pointList; 828 829 while (right!=tf_gvSelectedPoint){ 830 left=right; 831 right=right->next; 832 } 833 834 //selected point is not the right-end point 835 if (right->next!=0){ 836 right=right->next; 837 if (tf_gvSelectedPoint->x>right->x){ 838 sortPoints(); 839 } 840 } 841 842 //selected point is not the left-end point 843 if (left!=tf_gvSelectedPoint) { 844 if (tf_gvSelectedPoint->x<left->x){ 845 sortPoints(); 846 } 847 } 848 849 return tf_gvSelectedPoint; 850 } 851 852 853 void TransferFunctionGLUTWindow::scalePointsY(int offset){ 854 if (tf_numOfPoints<2) 855 return; 856 857 ControlPoint* cur=tf_pointList; 858 while (cur!=0){ 859 cur->y=((cur->y)-offset-15)*((float)last_lv_tf_height_scale/(float)lv_tf_height_scale)+15; 860 cur=cur->next; 861 } 862 WriteControlPoints(); 863 } 864 865 void TransferFunctionGLUTWindow::scalePointsX(){ 866 ControlPoint* cur=tf_pointList; 867 while (cur!=0){ 868 cur->x=(cur->x-15)*((float)lv_tf_width_scale/(float)last_lv_tf_width_scale)+15; 869 cur=cur->next; 870 } 871 WriteControlPoints(); 872 } 873 874 875 void TransferFunctionGLUTWindow::dumpHist(){ 876 /* 877 FILE* fp = fopen("HistFile", "wt"); 878 879 if(!fp) 880 return; //error 881 882 int i=0; 883 for (i=0; i<Hist.range; i++){ 884 fprintf(fp, "%d\n", Hist.count[i]); 885 } 886 printf("Histogram dumped.\n"); 887 fclose(fp); 888 */ 889 } 890 891 892 void TransferFunctionGLUTWindow::readHist(){ 893 /* 894 FILE* fp = fopen("HistFile", "rt"); 895 896 if(!fp) 897 return; //error 898 899 char buf[100]; //buffer to store one line from file 900 char* token; //pointer to token in the buffer 901 char seps[]="\n"; 902 903 unsigned long value; 904 905 int counter=0; 906 907 while(true){ 908 //read file 909 if (fgets(buf, 100, fp)==NULL) 910 break; 911 token=strtok(buf, seps); 912 value=atof(token); 913 Hist.count[counter]=value; 914 counter++; 915 } 916 printf("Histgram loaded. Total number of values:%d\n", counter); 917 tfDisplay(); 918 fclose(fp); 919 */ 801 void 802 TransferFunctionGLUTWindow::printPoints() 803 { 804 ControlPoint* cur=tf_pointList; 805 fprintf(stderr, "********************\n"); 806 fprintf(stderr, "Total points %d \n", tf_numOfPoints); 807 808 if (tf_numOfPoints==0) 809 return; 810 811 while (cur->next!=0){ 812 fprintf(stderr, "(%g,%g)\n", cur->x, cur->y); 813 cur=cur->next; 814 } 815 fprintf(stderr, "(%g,%g)\n", cur->x, cur->y); 816 fprintf(stderr, "********************\n"); 817 } 818 819 820 ControlPoint* 821 TransferFunctionGLUTWindow::boundaryChecking() 822 { 823 assert(tf_gvSelectedPoint!=0); 824 assert(tf_pointList!=0); 825 //find left and right neighbor in the list 826 //If point is dragged passing the neighbor, the points are reordered. 827 828 ControlPoint* left=tf_pointList; 829 ControlPoint* right=tf_pointList; 830 831 while (right!=tf_gvSelectedPoint){ 832 left=right; 833 right=right->next; 834 } 835 836 //selected point is not the right-end point 837 if (right->next!=0){ 838 right=right->next; 839 if (tf_gvSelectedPoint->x>right->x){ 840 sortPoints(); 841 } 842 } 843 844 //selected point is not the left-end point 845 if (left!=tf_gvSelectedPoint) { 846 if (tf_gvSelectedPoint->x<left->x){ 847 sortPoints(); 848 } 849 } 850 851 return tf_gvSelectedPoint; 852 } 853 854 855 void 856 TransferFunctionGLUTWindow::scalePointsY(int offset) 857 { 858 if (tf_numOfPoints<2) 859 return; 860 861 ControlPoint* cur=tf_pointList; 862 while (cur!=0){ 863 cur->y=((cur->y)-offset-15)*((float)last_lv_tf_height_scale/(float)lv_tf_height_scale)+15; 864 cur=cur->next; 865 } 866 WriteControlPoints(); 867 } 868 869 void 870 TransferFunctionGLUTWindow::scalePointsX() 871 { 872 ControlPoint* cur=tf_pointList; 873 while (cur!=0){ 874 cur->x=(cur->x-15)*((float)lv_tf_width_scale/(float)last_lv_tf_width_scale)+15; 875 cur=cur->next; 876 } 877 WriteControlPoints(); 878 } 879 880 881 void 882 TransferFunctionGLUTWindow::dumpHist() 883 { 884 /* 885 FILE* fp = fopen("HistFile", "wt"); 886 887 if(!fp) 888 return; //error 889 890 int i=0; 891 for (i=0; i<Hist.range; i++){ 892 fprintf(fp, "%d\n", Hist.count[i]); 893 } 894 printf("Histogram dumped.\n"); 895 fclose(fp); 896 */ 897 } 898 899 900 void 901 TransferFunctionGLUTWindow::readHist() 902 { 903 /* 904 FILE* fp = fopen("HistFile", "rt"); 905 906 if(!fp) 907 return; //error 908 909 char buf[100]; //buffer to store one line from file 910 char* token; //pointer to token in the buffer 911 char seps[]="\n"; 912 913 unsigned long value; 914 915 int counter=0; 916 917 while(true){ 918 //read file 919 if (fgets(buf, 100, fp)==NULL) 920 break; 921 token=strtok(buf, seps); 922 value=atof(token); 923 Hist.count[counter]=value; 924 counter++; 925 } 926 printf("Histgram loaded. Total number of values:%d\n", counter); 927 tfDisplay(); 928 fclose(fp); 929 */ 920 930 } 921 931 922 932 //output histogram to console 923 void TransferFunctionGLUTWindow::printHist(){ 924 int i=0; 925 926 for(int j=0; j<4; j++){ 927 for (i=0; i<Hist[j].range; i++){ 928 fprintf(stderr, "%ld\t", Hist[j].count[i]); 929 } 930 fprintf(stderr, "\n\n"); 931 } 932 933 /* 934 for (i=0; i<Hist_p.range; i++){ 935 printf("%ld\t", Hist_p.count[i]); 936 } 937 printf("\n\n"); 938 939 for (i=0; i<Hist_d.range; i++){ 940 printf("%ld\t", Hist_d.count[i]); 941 } 942 printf("\n\n"); 943 944 for (i=0; i<Hist_ss.range; i++){ 945 printf("%ld\t", Hist_ss.count[i]); 946 } 947 printf("\n\n"); 948 */ 949 } 950 951 952 void TransferFunctionGLUTWindow::plotHist(){ 953 954 for(int j=0; j<4; j++){ 955 Histogram cur = Hist[j]; 956 957 float unitX=(float)tf_unitWidth/(float)(cur.range-1); 958 float unitY; 959 unsigned long maxY; 960 unsigned long minY; 961 double rangeY; 962 963 float result[256]; 964 965 //get max Y 966 maxY=0; 967 int i=0; 968 for (i=0; i<cur.range; i++){ 969 if (cur.count[i]>maxY) 970 maxY=cur.count[i]; 971 } 972 //printf("maxY=%d\n", maxY); 973 974 975 //get min Y 976 minY=maxY; 977 for (i=0; i<cur.range; i++){ 978 if (cur.count[i]<minY) 979 minY=cur.count[i]; 980 } 981 //printf("minY=%d\n", minY); 982 983 //rangeY=(double)log(maxY-minY); 984 //rangeY=(double)(maxY-minY); 985 rangeY=(float)log(float(maxY - minY)); 986 unitY=(float)(winy-20)/(float)rangeY; 987 988 //reduce all values with log then by minY 989 for (i=0; i<cur.range; i++){ 990 if (cur.count[i]==0) 991 result[i]=0; 992 else 993 //result[i]=log((double)(cur.count[i])); 994 //result[i]=double(cur.count[i]); 995 //result[i]=log((float)(cur.count[i]))-log((float)minY); 996 result[i]=log((float)(cur.count[i])-(float)minY); 997 } 998 999 1000 //draw points 1001 glColor3d(0, 0, 1); 1002 glBegin(GL_LINES); 1003 for (i=0; i<cur.range-1; i++){ 1004 glVertex2f(15+i*unitX, 15+result[i]*unitY); 1005 glVertex2f(15+(i+1)*unitX, 15+result[i+1]*unitY); 1006 } 1007 glEnd(); 1008 glColor3d(0, 0, 0); 1009 1010 } 1011 } 933 void TransferFunctionGLUTWindow::printHist() 934 { 935 int i=0; 936 937 for(int j=0; j<4; j++){ 938 for (i=0; i<Hist[j].range; i++){ 939 fprintf(stderr, "%ld\t", Hist[j].count[i]); 940 } 941 fprintf(stderr, "\n\n"); 942 } 943 944 /* 945 for (i=0; i<Hist_p.range; i++){ 946 printf("%ld\t", Hist_p.count[i]); 947 } 948 printf("\n\n"); 949 950 for (i=0; i<Hist_d.range; i++){ 951 printf("%ld\t", Hist_d.count[i]); 952 } 953 printf("\n\n"); 954 955 for (i=0; i<Hist_ss.range; i++){ 956 printf("%ld\t", Hist_ss.count[i]); 957 } 958 printf("\n\n"); 959 */ 960 } 961 962 963 void 964 TransferFunctionGLUTWindow::plotHist() 965 { 966 for(int j=0; j<4; j++){ 967 Histogram cur = Hist[j]; 968 969 float unitX=(float)tf_unitWidth/(float)(cur.range-1); 970 float unitY; 971 unsigned long maxY; 972 unsigned long minY; 973 double rangeY; 974 975 float result[256]; 976 977 //get max Y 978 maxY=0; 979 int i=0; 980 for (i=0; i<cur.range; i++){ 981 if (cur.count[i]>maxY) 982 maxY=cur.count[i]; 983 } 984 //printf("maxY=%d\n", maxY); 985 986 987 //get min Y 988 minY=maxY; 989 for (i=0; i<cur.range; i++){ 990 if (cur.count[i]<minY) 991 minY=cur.count[i]; 992 } 993 //printf("minY=%d\n", minY); 994 995 //rangeY=(double)log(maxY-minY); 996 //rangeY=(double)(maxY-minY); 997 rangeY=(float)log(float(maxY - minY)); 998 unitY=(float)(winy-20)/(float)rangeY; 999 1000 //reduce all values with log then by minY 1001 for (i=0; i<cur.range; i++){ 1002 if (cur.count[i]==0) 1003 result[i]=0; 1004 else 1005 //result[i]=log((double)(cur.count[i])); 1006 //result[i]=double(cur.count[i]); 1007 //result[i]=log((float)(cur.count[i]))-log((float)minY); 1008 result[i]=log((float)(cur.count[i])-(float)minY); 1009 } 1010 1011 1012 //draw points 1013 glColor3d(0, 0, 1); 1014 glBegin(GL_LINES); 1015 for (i=0; i<cur.range-1; i++){ 1016 glVertex2f(15+i*unitX, 15+result[i]*unitY); 1017 glVertex2f(15+(i+1)*unitX, 15+result[i+1]*unitY); 1018 } 1019 glEnd(); 1020 glColor3d(0, 0, 0); 1021 1022 } 1023 }
Note: See TracChangeset
for help on using the changeset viewer.