Changeset 5550
- Timestamp:
- May 18, 2015 7:42:02 PM (6 years ago)
- Location:
- nanovis/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
nanovis/trunk/HeightMap.cpp
r5478 r5550 24 24 double HeightMap::valueMax = 1.0; 25 25 26 HeightMap::HeightMap() : 26 HeightMap::HeightMap() : 27 27 _vertexBufferObjectID(0), 28 28 _texcoordBufferObjectID(0), … … 52 52 } 53 53 if (_heights != NULL) { 54 55 } 56 } 57 58 void 54 delete [] _heights; 55 } 56 } 57 58 void 59 59 HeightMap::render(RenderContext *renderContext) 60 60 { … … 86 86 glDepthRange(0.001, 1.0); 87 87 } 88 88 89 89 glEnable(GL_DEPTH_TEST); 90 90 … … 108 108 glEnable(GL_TEXTURE_1D); 109 109 _transferFunc->getTexture()->activate(); 110 110 111 111 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 112 112 } … … 120 120 #define _TRIANGLES_ 121 121 #ifdef _TRIANGLES_ 122 glDrawElements(GL_TRIANGLES, _indexCount, GL_UNSIGNED_INT, 122 glDrawElements(GL_TRIANGLES, _indexCount, GL_UNSIGNED_INT, 123 123 _indexBuffer); 124 124 #else 125 glDrawElements(GL_QUADS, _indexCount, GL_UNSIGNED_INT, 125 glDrawElements(GL_QUADS, _indexCount, GL_UNSIGNED_INT, 126 126 _indexBuffer); 127 127 #endif … … 145 145 glDisable(GL_BLEND); 146 146 glDisable(GL_TEXTURE_2D); 147 glColor4f(_contourColor.x, _contourColor.y, _contourColor.z, 147 glColor4f(_contourColor.x, _contourColor.y, _contourColor.z, 148 148 _opacity /*1.0f*/); 149 149 glDepthRange (0.0, 0.999); … … 158 158 } 159 159 160 void 160 void 161 161 HeightMap::createIndexBuffer(int xCount, int zCount, float* heights) 162 162 { 163 163 if (_indexBuffer != NULL) { 164 164 delete [] _indexBuffer; 165 165 _indexBuffer = NULL; 166 166 } 167 167 _indexCount = (xCount - 1) * (zCount - 1) * 6; 168 168 _indexBuffer = new int[_indexCount]; 169 169 170 170 int i, j; 171 171 int boundaryWidth = xCount - 1; … … 188 188 index4 = i * xCount + j + 1; 189 189 if (isnan(heights[index4])) index4Valid = false; 190 190 191 191 #ifdef _TRIANGLES_ 192 192 if (index1Valid && index2Valid && index3Valid) { … … 227 227 } 228 228 229 void 229 void 230 230 HeightMap::reset() 231 231 { 232 232 if (_vertexBufferObjectID) { 233 233 glDeleteBuffers(1, &_vertexBufferObjectID); 234 234 _vertexBufferObjectID = 0; 235 235 } 236 236 if (_texcoordBufferObjectID) { 237 237 glDeleteBuffers(1, &_texcoordBufferObjectID); 238 238 _texcoordBufferObjectID = 0; 239 239 } 240 240 if (_contour != NULL) { 241 241 delete _contour; 242 242 _contour = NULL; 243 243 } 244 244 if (_indexBuffer != NULL) { 245 245 delete [] _indexBuffer; 246 246 _indexBuffer = NULL; 247 247 } 248 248 } 249 249 #if 0 250 void 250 void 251 251 HeightMap::setHeight(int xCount, int yCount, Vector3f *heights) 252 252 { … … 262 262 if (min > heights[i].y) { 263 263 min = heights[i].y; 264 } 264 } 265 265 if (max < heights[i].y) { 266 266 max = heights[i].y; … … 284 284 texcoord[i].set(0, 0, heights[i].y); 285 285 } 286 286 287 287 glGenBuffers(1, &_vertexBufferObjectID); 288 288 glBindBuffer(GL_ARRAY_BUFFER, _vertexBufferObjectID); 289 glBufferData(GL_ARRAY_BUFFER, _vertexCount * sizeof( Vector3f ), heights, 290 289 glBufferData(GL_ARRAY_BUFFER, _vertexCount * sizeof( Vector3f ), heights, 290 GL_STATIC_DRAW); 291 291 glGenBuffers(1, &_texcoordBufferObjectID); 292 292 glBindBuffer(GL_ARRAY_BUFFER, _texcoordBufferObjectID); 293 glBufferData(GL_ARRAY_BUFFER, _vertexCount * sizeof(float) * 3, texcoord, 294 293 glBufferData(GL_ARRAY_BUFFER, _vertexCount * sizeof(float) * 3, texcoord, 294 GL_STATIC_DRAW); 295 295 glBindBuffer(GL_ARRAY_BUFFER, 0); 296 296 297 297 delete [] texcoord; 298 298 299 299 if (_contour != NULL) { 300 300 delete _contour; 301 301 _contour = NULL; 302 302 } 303 303 ContourLineFilter lineFilter; … … 315 315 } 316 316 #endif 317 void 318 HeightMap::setHeight(float xMin, float yMin, float xMax, float yMax, 317 void 318 HeightMap::setHeight(float xMin, float yMin, float xMax, float yMax, 319 319 int xNum, int yNum, float *heights) 320 320 { 321 321 _vertexCount = xNum * yNum; 322 322 _xNum = xNum, _yNum = yNum; 323 _heights = heights; 323 _heights = heights; 324 324 reset(); 325 325 326 326 // Get the min/max of the heights. */ 327 327 float min, max; … … 336 336 #ifdef notdef 337 337 if (retainScale_) { 338 339 340 341 // same. 342 343 344 345 338 // Check the units of each axis. If they are the same, we want to 339 // retain the surface's aspect ratio when transforming coordinates to 340 // the grid. Use the range of the longest axis when the units are the 341 // same. 342 if (xAxis.units() != NULL) && (xAxis.units() == yAxis.units()) { 343 } 344 if (yAxis.units() != NULL) && (yAxis.units() == zAxis.units()) { 345 } 346 346 } 347 347 #endif … … 353 353 354 354 min = 0.0, max = 1.0; 355 xMin = yMin = min = 0.0; 355 xMin = yMin = min = 0.0; 356 356 xMax = yMax = max = 1.0; 357 357 // Save the scales. … … 361 361 362 362 _centerPoint.set(0.5, 0.5, 0.5); 363 363 364 364 #ifndef notdef 365 365 Vector3f* texcoord = new Vector3f[_vertexCount]; … … 367 367 texcoord[i].set(0, 0, heights[i]); 368 368 } 369 370 Vector3f* map = createHeightVertices(xMin, yMin, xMax, yMax, xNum, yNum, 371 372 369 370 Vector3f* map = createHeightVertices(xMin, yMin, xMax, yMax, xNum, yNum, 371 heights); 372 373 373 glGenBuffers(1, &_vertexBufferObjectID); 374 374 glBindBuffer(GL_ARRAY_BUFFER, _vertexBufferObjectID); 375 glBufferData(GL_ARRAY_BUFFER, _vertexCount * sizeof(Vector3f), map, 375 glBufferData(GL_ARRAY_BUFFER, _vertexCount * sizeof(Vector3f), map, 376 376 GL_STATIC_DRAW); 377 377 glGenBuffers(1, &_texcoordBufferObjectID); 378 378 glBindBuffer(GL_ARRAY_BUFFER, _texcoordBufferObjectID); 379 glBufferData(GL_ARRAY_BUFFER, _vertexCount * sizeof(float) * 3, texcoord, 379 glBufferData(GL_ARRAY_BUFFER, _vertexCount * sizeof(float) * 3, texcoord, 380 380 GL_STATIC_DRAW); 381 381 glBindBuffer(GL_ARRAY_BUFFER, 0); 382 382 383 383 delete [] texcoord; 384 385 384 385 386 386 if (_contour != NULL) { 387 387 delete _contour; 388 388 _contour = NULL; 389 389 } 390 390 ContourLineFilter lineFilter; … … 398 398 399 399 Vector3f * 400 HeightMap::createHeightVertices(float xMin, float yMin, float xMax, 401 400 HeightMap::createHeightVertices(float xMin, float yMin, float xMax, 401 float yMax, int xNum, int yNum, float *height) 402 402 { 403 403 Vector3f* vertices = new Vector3f[xNum * yNum]; … … 405 405 Vector3f* dstData = vertices; 406 406 float* srcData = height; 407 407 408 408 for (int y = 0; y < yNum; ++y) { 409 409 float yCoord; 410 410 411 yCoord = yMin + ((yMax - yMin) * y) / (yNum - 1); 411 yCoord = yMin + ((yMax - yMin) * y) / (yNum - 1); 412 412 for (int x = 0; x < xNum; ++x) { 413 413 float xCoord; 414 414 415 xCoord = xMin + ((xMax - xMin) * x) / (xNum - 1); 415 xCoord = xMin + ((xMax - xMin) * x) / (xNum - 1); 416 416 dstData->set(xCoord, *srcData, yCoord); 417 417 … … 426 426 * \brief Maps the data coordinates of the surface into the grid's axes. 427 427 */ 428 void 428 void 429 429 HeightMap::mapToGrid(Grid *grid) 430 430 { … … 447 447 float *normHeights = new float[count]; 448 448 for (p = _heights, pend = p + count, q = normHeights; p < pend; p++, q++) { 449 449 *q = (*p - bbox.min.y) * yScale; 450 450 } 451 451 Vector3f *t, *texcoord; … … 465 465 466 466 Vector3f* vertices; 467 vertices = createHeightVertices(xMin, zMin, xMax, zMax, _xNum, _yNum, 468 469 467 vertices = createHeightVertices(xMin, zMin, xMax, zMax, _xNum, _yNum, 468 normHeights); 469 470 470 glGenBuffers(1, &_vertexBufferObjectID); 471 471 glBindBuffer(GL_ARRAY_BUFFER, _vertexBufferObjectID); 472 glBufferData(GL_ARRAY_BUFFER, _vertexCount * sizeof(Vector3f), vertices, 472 glBufferData(GL_ARRAY_BUFFER, _vertexCount * sizeof(Vector3f), vertices, 473 473 GL_STATIC_DRAW); 474 474 glGenBuffers(1, &_texcoordBufferObjectID); 475 475 glBindBuffer(GL_ARRAY_BUFFER, _texcoordBufferObjectID); 476 glBufferData(GL_ARRAY_BUFFER, _vertexCount * sizeof(float) * 3, texcoord, 476 glBufferData(GL_ARRAY_BUFFER, _vertexCount * sizeof(float) * 3, texcoord, 477 477 GL_STATIC_DRAW); 478 478 glBindBuffer(GL_ARRAY_BUFFER, 0); … … 481 481 if (_contour != NULL) { 482 482 delete _contour; 483 483 _contour = NULL; 484 484 } 485 485 ContourLineFilter lineFilter; 486 486 //lineFilter.transferFunction(_transferFunc); 487 487 _contour = lineFilter.create(0.0f, 1.0f, 10, vertices, _xNum, _yNum); 488 488 489 489 this->createIndexBuffer(_xNum, _yNum, normHeights); 490 490 delete [] normHeights; -
nanovis/trunk/HeightMap.h
r3630 r5550 41 41 *@param height a pointer value adrressing xCount * yCount values of heights 42 42 */ 43 void setHeight(float startX, float startY, float endX, float endY, 44 43 void setHeight(float startX, float startY, float endX, float endY, 44 int xCount, int yCount, float *height); 45 45 #if 0 46 46 /** … … 100 100 float opacity() 101 101 { 102 102 return _opacity; 103 103 } 104 104 … … 108 108 void setLineContourColor(float *rgb) 109 109 { 110 111 112 110 _contourColor.x = rgb[0]; 111 _contourColor.y = rgb[1]; 112 _contourColor.z = rgb[2]; 113 113 } 114 114 … … 142 142 vrmath::Vector3f _scale; 143 143 vrmath::Vector3f _centerPoint; 144 int _xNum, _yNum; 145 float *_heights; 146 144 int _xNum, _yNum; // Number of elements x and y axes in grid. 145 float *_heights; // Array of original (unscaled) heights 146 // (y-values) 147 147 }; 148 148
Note: See TracChangeset
for help on using the changeset viewer.