Changeset 3630
- Timestamp:
- Apr 16, 2013, 12:52:20 AM (11 years ago)
- Location:
- trunk/packages/vizservers/nanovis
- Files:
-
- 85 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/nanovis/Axis.h
r3613 r3630 399 399 * the data. */ 400 400 401 double _range; /**< Range of values on axis ( max_ - min_) */401 double _range; /**< Range of values on axis (_max - _min) */ 402 402 double _scale; /**< Scale factor for axis (1.0/_range) */ 403 403 -
trunk/packages/vizservers/nanovis/Camera.cpp
r3611 r3630 18 18 #include <vrmath/Vector3f.h> 19 19 #include <vrmath/Vector4f.h> 20 #include <vrmath/BBox.h> 20 21 21 22 #include "nanovis.h" … … 36 37 } 37 38 38 Camera::Camera(int startx, int starty, int w, int h, 39 float loc_x, float loc_y, float loc_z) : 40 _location(loc_x, loc_y, loc_z), 39 Camera::Camera(int x, int y, int width, int height) : 40 _updir(Y_POS), 41 _zoomRatio(1), 42 _position(0, 0, 2.5), 43 _focalPoint(0, 0, 0), 44 _mvDirty(true), 41 45 _fov(30.0), 42 46 _near(0.1), 43 _far(50.0), 44 _width(w), 45 _height(h), 46 _startX(startx), 47 _startY(starty) 48 { 47 _far(50.0) 48 { 49 _viewport[0] = x; 50 _viewport[1] = y; 51 _viewport[2] = width; 52 _viewport[3] = height; 53 _pan[0] = 0; 54 _pan[1] = 0; 49 55 } 50 56 51 57 void 52 Camera::getUpDirMatrix(Matrix4x4d& upMat) 53 { 54 switch (NanoVis::updir) { 55 case NanoVis::X_POS: { 56 upMat.makeRotation(0, 0, 1, deg2rad(90)); 58 Camera::pan(float x, float y, bool absolute) 59 { 60 y = -y; 61 if (absolute) { 62 double panAbs[2]; 63 panAbs[0] = x; 64 panAbs[1] = y; 65 x -= _pan[0]; 66 y -= _pan[1]; 67 _pan[0] = panAbs[0]; 68 _pan[1] = panAbs[1]; 69 } else { 70 _pan[0] += x; 71 _pan[1] += y; 72 } 73 74 if (x != 0.0 || y != 0.0) { 75 Vector3f worldFocalPoint; 76 worldToWindowCoords(_focalPoint.x, _focalPoint.y, _focalPoint.z, 77 worldFocalPoint); 78 float focalDepth = worldFocalPoint.z; 79 80 Vector3f newPickPoint, oldPickPoint, motionVector; 81 windowToWorldCoords((x * 2. + 1.) * (float)_viewport[2] / 2.0, 82 (y * 2. + 1.) * (float)_viewport[3] / 2.0, 83 focalDepth, 84 newPickPoint); 85 86 windowToWorldCoords((float)_viewport[2] / 2.0, 87 (float)_viewport[3] / 2.0, 88 focalDepth, 89 oldPickPoint); 90 91 // Camera motion is reversed 92 motionVector = oldPickPoint - newPickPoint; 93 94 _focalPoint += motionVector; 95 _position += motionVector; 96 97 _mvDirty = true; 98 } 99 } 100 101 void 102 Camera::zoom(float z, bool absolute) 103 { 104 if (absolute) { 105 // Compute relative zoom 106 float zAbs = z; 107 z *= 1.0/_zoomRatio; 108 _zoomRatio = zAbs; 109 } else { 110 _zoomRatio *= z; 111 } 112 float distance = getDistance() / z; 113 Vector3f dir = getViewPlaneNormal(); 114 dir = dir.scale(distance); 115 _position = _focalPoint + dir; 116 _mvDirty = true; 117 } 118 119 const Matrix4x4d& 120 Camera::getUpDirMatrix() const 121 { 122 return _updirMatrix; 123 } 124 125 void 126 Camera::setUpDirMatrix(AxisDirection dir) 127 { 128 _updir = dir; 129 130 switch (_updir) { 131 case X_POS: { 132 _updirMatrix.makeRotation(0, 0, 1, deg2rad(90)); 57 133 Matrix4x4d tmp; 58 134 tmp.makeRotation(1, 0, 0, deg2rad(90)); 59 upMat.multiply(tmp);60 } 61 break; 62 case NanoVis::Y_POS:63 upMat.makeIdentity();64 break; 65 case NanoVis::Z_POS: {66 upMat.makeRotation(1, 0, 0, deg2rad(-90));135 _updirMatrix.multiply(tmp); 136 } 137 break; 138 case Y_POS: 139 _updirMatrix.makeIdentity(); 140 break; 141 case Z_POS: { 142 _updirMatrix.makeRotation(1, 0, 0, deg2rad(-90)); 67 143 Matrix4x4d tmp; 68 144 tmp.makeRotation(0, 0, 1, deg2rad(-90)); 69 upMat.multiply(tmp);70 } 71 break; 72 case NanoVis::X_NEG:73 upMat.makeRotation(0, 0, 1, deg2rad(-90));74 break; 75 case NanoVis::Y_NEG: {76 upMat.makeRotation(0, 0, 1, deg2rad(180));145 _updirMatrix.multiply(tmp); 146 } 147 break; 148 case X_NEG: 149 _updirMatrix.makeRotation(0, 0, 1, deg2rad(-90)); 150 break; 151 case Y_NEG: { 152 _updirMatrix.makeRotation(0, 0, 1, deg2rad(180)); 77 153 Matrix4x4d tmp; 78 154 tmp.makeRotation(0, 1, 0, deg2rad(-90)); 79 upMat.multiply(tmp);80 } 81 break; 82 case NanoVis::Z_NEG:83 upMat.makeRotation(1, 0, 0, deg2rad(90));155 _updirMatrix.multiply(tmp); 156 } 157 break; 158 case Z_NEG: 159 _updirMatrix.makeRotation(1, 0, 0, deg2rad(90)); 84 160 break; 85 161 } … … 97 173 98 174 if (resetOrientation) { 99 _cameraMatrix.makeIdentity(); 100 } 101 102 Vector3f center(bboxMin + bboxMax); 103 center.scale(0.5); 104 105 Matrix4x4d mat, upMat; 106 getUpDirMatrix(upMat); 107 mat.makeTranslation(-center); 108 mat.multiply(_cameraMatrix, mat); 109 mat.multiply(upMat); 110 111 Vector3f emin(FLT_MAX, FLT_MAX, FLT_MAX), emax(-FLT_MAX, -FLT_MAX, -FLT_MAX); 112 113 // Transform bounds by camera matrix 114 Vector4f bboxEye[8]; 115 bboxEye[0] = Vector4f(bboxMin.x, bboxMin.y, bboxMin.z, 1); 116 bboxEye[1] = Vector4f(bboxMax.x, bboxMin.y, bboxMin.z, 1); 117 bboxEye[2] = Vector4f(bboxMin.x, bboxMax.y, bboxMin.z, 1); 118 bboxEye[3] = Vector4f(bboxMin.x, bboxMin.y, bboxMax.z, 1); 119 bboxEye[4] = Vector4f(bboxMax.x, bboxMax.y, bboxMin.z, 1); 120 bboxEye[5] = Vector4f(bboxMax.x, bboxMin.y, bboxMax.z, 1); 121 bboxEye[6] = Vector4f(bboxMin.x, bboxMax.y, bboxMax.z, 1); 122 bboxEye[7] = Vector4f(bboxMax.x, bboxMax.y, bboxMax.z, 1); 123 124 for (int i = 0; i < 8; i++) { 125 Vector4f eyeVert = mat.transform(bboxEye[i]); 126 if (eyeVert.x < emin.x) emin.x = eyeVert.x; 127 if (eyeVert.x > emax.x) emax.x = eyeVert.x; 128 if (eyeVert.y < emin.y) emin.y = eyeVert.y; 129 if (eyeVert.y > emax.y) emax.y = eyeVert.y; 130 if (eyeVert.z < emin.z) emin.z = eyeVert.z; 131 if (eyeVert.z > emax.z) emax.z = eyeVert.z; 132 } 175 _rotationMatrix.makeIdentity(); 176 } 177 178 BBox bbox(bboxMin, bboxMax); 179 Vector3f center = bbox.getCenter(); 180 _focalPoint.set(center.x, center.y, center.z); 181 182 Matrix4x4d mat; 183 mat.makeTranslation(-_focalPoint); 184 mat.multiply(_updirMatrix, mat); // premult 185 mat.multiply(_rotationMatrix, mat); // premult 186 187 bbox.transform(bbox, mat); 188 189 Vector3f emin = bbox.min; 190 Vector3f emax = bbox.max; 133 191 134 192 TRACE("Eye bounds: (%g,%g,%g) - (%g,%g,%g)", … … 146 204 147 205 // Deal with vertical aspect window 148 double winAspect = (double) (_width - _startX)/(double)(_height - _startY);206 double winAspect = (double)_viewport[2]/(double)_viewport[3]; 149 207 double sceneAspect = 1.0;; 150 208 if (bheight > 0.0) … … 161 219 _far = _near + bdepth; 162 220 163 _location.set(center.x, center.y, center.z + distance); 221 Vector3f viewPlaneNormal(0, 0, 1); 222 mat.transpose(); 223 viewPlaneNormal = mat.transformVec(viewPlaneNormal); 224 _position = _focalPoint + viewPlaneNormal * distance; 164 225 165 226 TRACE("win aspect: %g scene aspect: %g", winAspect, sceneAspect); 227 TRACE("vpn: %g, %g, %g", viewPlaneNormal.x, viewPlaneNormal.y, viewPlaneNormal.z); 166 228 TRACE("c: %g,%g,%g, d: %g", center.x, center.y, center.z, distance); 229 TRACE("pos: %g, %g, %g", _position.x, _position.y, _position.z); 167 230 TRACE("near: %g, far: %g", _near, _far); 231 232 _zoomRatio = 1.0; 233 _pan[0] = 0; 234 _pan[1] = 0; 235 _mvDirty = true; 168 236 169 237 initialize(); … … 171 239 } 172 240 241 /** 242 * \brief Reset near and far planes based on given world space 243 * bounding box 244 * 245 * This method is based on VTK's renderer class implementation 246 * The idea is to plug the bounding box corners into the view 247 * plane equation to find the min and max distance of the scene 248 * to the view plane. 249 */ 173 250 void 174 251 Camera::resetClippingRange(const Vector3f& bboxMin, const Vector3f& bboxMax) 175 252 { 176 Vector3f emin(bboxMin.x, bboxMin.y, bboxMin.z), emax(bboxMax.x, bboxMax.y, bboxMax.z); 177 178 Vector3f center(emin + emax); 179 center.scale(0.5); 180 181 // Compute the radius of the enclosing sphere, 182 // which is half the bounding box diagonal 183 Vector3f diagonal(emax - emin); 184 double radius = diagonal.length() * 0.5; 185 186 // If we have just a single point, pick a radius of 1.0 187 radius = (radius == 0) ? 1.0 : radius; 188 189 TRACE("c: %g,%g,%g, r: %g cam z: %g", center.x, center.y, center.z, radius, _location.z); 190 191 _near = _location.z - radius; 192 _far = _location.z + radius; 193 194 if (_near < 0.0) { 195 _near = 0.001; 196 } 197 if (_far < 0.0) { 198 _far = 1.0; 199 } 253 BBox bbox(bboxMin, bboxMax); 254 255 // Set up view plane equation at camera position 256 Vector3f vpn = getViewPlaneNormal(); 257 double a, b, c, d, dist; 258 a = -vpn.x; 259 b = -vpn.y; 260 c = -vpn.z; 261 d = -(a*_position.x + b*_position.y + c*_position.z); 262 263 // Now compute distance of bounding box corners to view plane 264 265 // Set starting limits 266 _near = a * bbox.min.x + b * bbox.min.y + c * bbox.min.z + d; 267 _far = 1e-18; 268 269 // Iterate over the 8 bbox corners 270 for (int k = 0; k < 2; k++) { 271 for (int j = 0; j < 2; j++) { 272 for (int i = 0; i < 2; i++) { 273 dist = 274 (a * ((i == 0) ? bbox.min.x : bbox.max.x)) + 275 (b * ((j == 0) ? bbox.min.y : bbox.max.y)) + 276 (c * ((k == 0) ? bbox.min.z : bbox.max.z)) + d; 277 _near = (dist < _near) ? dist : _near; 278 _far = (dist > _far) ? dist : _far; 279 } 280 } 281 } 282 283 // Check for near plane behind the camera 284 if (_near < 0) { 285 _near = 0; 286 } 287 288 // Extend the bounds a bit 289 _near = 0.99 * _near - (_far - _near) * 0.5; 290 _far = 1.01 * _far + (_far - _near) * 0.5; 291 292 // Ensure near is closer than far 293 _near = (_near >= _far) ? (0.01 * _far) : _near; 294 295 // Limit clip range to make best use of z buffer precision 296 if (_near < .001 * _far) 297 _near = .001 * _far; 200 298 201 299 TRACE("Resetting camera clipping range to: near: %g, far: %g", _near, _far); … … 204 302 glLoadIdentity(); 205 303 gluPerspective(_fov, 206 (GLdouble) (_width - _startX)/(GLdouble)(_height - _startY),304 (GLdouble)_viewport[2]/(GLdouble)_viewport[3], 207 305 _near, _far); 208 306 glMatrixMode(GL_MODELVIEW); … … 217 315 print(); 218 316 219 glViewport(_ startX, _startY, _width, _height);317 glViewport(_viewport[0], _viewport[1], _viewport[2], _viewport[3]); 220 318 glMatrixMode(GL_PROJECTION); 221 319 glLoadIdentity(); 222 320 gluPerspective(_fov, 223 (GLdouble) (_width - _startX)/(GLdouble)(_height - _startY),321 (GLdouble)_viewport[2]/(GLdouble)_viewport[3], 224 322 _near, _far); 225 323 226 324 glMatrixMode(GL_MODELVIEW); 325 326 computeModelViewMatrix(); 327 glLoadMatrixd((const GLdouble *)_modelViewMatrix.get()); 328 } 329 330 void Camera::windowToWorldCoords(double x, double y, double z, Vector3f& objPos) 331 { 332 Matrix4x4d proj; 333 getProjectionMatrix(proj); 334 GLdouble outX, outY, outZ; 335 gluUnProject(x, y, z, 336 (GLdouble *)getModelViewMatrix().get(), 337 (GLdouble *)proj.get(), 338 (GLint *)_viewport, 339 &outX, &outY, &outZ); 340 objPos.set(outX, outY, outZ); 341 } 342 343 void Camera::worldToWindowCoords(double x, double y, double z, Vector3f& winPos) 344 { 345 Matrix4x4d proj; 346 getProjectionMatrix(proj); 347 GLdouble outX, outY, outZ; 348 gluProject(x, y, z, 349 (GLdouble *)getModelViewMatrix().get(), 350 (GLdouble *)proj.get(), 351 (GLint *)_viewport, 352 &outX, &outY, &outZ); 353 winPos.set(outX, outY, outZ); 354 } 355 356 void Camera::computeModelViewMatrix() 357 { 358 if (_mvDirty) { 359 _modelViewMatrix.makeTranslation(0, 0, -getDistance()); 360 _modelViewMatrix.multiply(_rotationMatrix); 361 _modelViewMatrix.multiply(_updirMatrix); 362 Matrix4x4d mat; 363 mat.makeTranslation(-_focalPoint); 364 _modelViewMatrix.multiply(mat); 365 _mvDirty = false; 366 } 367 } 368 369 void Camera::getProjectionMatrix(Matrix4x4d& mat) 370 { 371 glMatrixMode(GL_PROJECTION); 372 glPushMatrix(); 227 373 glLoadIdentity(); 228 229 glTranslatef(-_location.x, -_location.y, -_location.z); 230 glMultMatrixd((const GLdouble *)_cameraMatrix.get()); 231 } 232 233 void Camera::rotate(double *quat) 374 gluPerspective(_fov, 375 (GLdouble)_viewport[2]/(GLdouble)_viewport[3], 376 _near, _far); 377 glGetDoublev(GL_PROJECTION_MATRIX, (GLdouble *)mat.get()); 378 glPopMatrix(); 379 glMatrixMode(GL_MODELVIEW); 380 } 381 382 void Camera::orient(double *quat) 234 383 { 235 384 Quaternion q(quat[0], quat[1], quat[2], quat[3]); 236 385 Rotation rot; 237 386 rot.set(q); 238 _cameraMatrix.makeRotation(rot); 239 _cameraMatrix.transpose(); 387 _rotationMatrix.makeRotation(rot); 388 _rotationMatrix.transpose(); 389 _mvDirty = true; 390 computeModelViewMatrix(); 391 392 Vector3f viewPlaneNormal(0, 0, 1); 393 Matrix4x4d mat = getModelViewMatrix(); 394 mat.transpose(); 395 viewPlaneNormal = mat.transformVec(viewPlaneNormal); 396 TRACE("vpn: %g %g %g", viewPlaneNormal.x, viewPlaneNormal.y, viewPlaneNormal.z); 397 _position = _focalPoint + viewPlaneNormal * getDistance(); 398 240 399 TRACE("Set rotation to quat: %g %g %g %g", 241 400 quat[0], quat[1], quat[2], quat[3]); 242 401 } 243 402 244 void Camera:: rotate(float angleX, float angleY, float angleZ)403 void Camera::orient(float angleX, float angleY, float angleZ) 245 404 { 246 405 angleX = -angleX; 247 406 angleY = angleY - 180.; 248 407 249 _ cameraMatrix.makeRotation(1, 0, 0, deg2rad(angleX));408 _rotationMatrix.makeRotation(1, 0, 0, deg2rad(angleX)); 250 409 Matrix4x4d mat; 251 410 mat.makeRotation(0, 1, 0, deg2rad(angleY)); 252 _ cameraMatrix.multiply(mat);411 _rotationMatrix.multiply(mat); 253 412 mat.makeRotation(0, 0, 1, deg2rad(angleZ)); 254 _cameraMatrix.multiply(mat); 255 //_cameraMatrix.transpose(); 413 _rotationMatrix.multiply(mat); 414 _mvDirty = true; 415 computeModelViewMatrix(); 416 417 Vector3f viewPlaneNormal(0, 0, 1); 418 mat = getModelViewMatrix(); 419 mat.transpose(); 420 viewPlaneNormal = mat.transformVec(viewPlaneNormal); 421 TRACE("vpn: %g %g %g", viewPlaneNormal.x, viewPlaneNormal.y, viewPlaneNormal.z); 422 _position = _focalPoint + viewPlaneNormal * getDistance(); 256 423 257 424 TRACE("Set rotation to angles: %g %g %g", … … 261 428 void Camera::print() const 262 429 { 263 TRACE("x: %d y: %d w: %d h: %d", _startX, _startY, _width, _height); 264 TRACE("loc: %g %g %g", 265 _location.x, _location.y, _location.z); 266 TRACE("Camera matrix: "); 267 _cameraMatrix.print(); 430 TRACE("x: %d y: %d w: %d h: %d", 431 _viewport[0], _viewport[1], _viewport[2], _viewport[3]); 268 432 TRACE("fov: %g near: %g far: %g", _fov, _near, _far); 269 } 433 TRACE("fp: %g, %g, %g", 434 _focalPoint.x, _focalPoint.y, _focalPoint.z); 435 TRACE("pos: %g, %g, %g", 436 _position.x, _position.y, _position.z); 437 TRACE("Rotation matrix: "); 438 _rotationMatrix.print(); 439 TRACE("Modelview matrix: "); 440 _modelViewMatrix.print(); 441 } -
trunk/packages/vizservers/nanovis/Camera.h
r3611 r3630 19 19 { 20 20 public: 21 Camera(int startx, int starty, int w, int h, 22 float loc_x, float loc_y, float loc_z); 21 enum AxisDirection { 22 X_POS = 1, 23 Y_POS = 2, 24 Z_POS = 3, 25 X_NEG = -1, 26 Y_NEG = -2, 27 Z_NEG = -3 28 }; 29 30 Camera(int x, int y, int width, int height); 23 31 24 32 ~Camera() 25 33 {} 26 34 27 //move location of camera 28 void x(float loc_x) 35 void setUpdir(AxisDirection dir) 29 36 { 30 _location.x = loc_x; 37 setUpDirMatrix(dir); 38 _mvDirty = true; 31 39 } 32 40 33 float x() const41 void setPosition(const vrmath::Vector3f& pos) 34 42 { 35 return _location.x; 43 _position = pos; 44 _mvDirty = true; 36 45 } 37 46 38 void y(float loc_y)47 const vrmath::Vector3f& getPosition() const 39 48 { 40 _location.y = loc_y;49 return _position; 41 50 } 42 51 43 float y() const52 const vrmath::Vector3f& getFocalPoint() const 44 53 { 45 return _ location.y;54 return _focalPoint; 46 55 } 47 56 48 void z(float loc_z)57 float getDistance() const 49 58 { 50 _location.z = loc_z;59 return vrmath::Vector3f(_focalPoint - _position).length(); 51 60 } 52 61 53 float z() const62 vrmath::Vector3f getDirectionOfProjection() const 54 63 { 55 return _location.z; 64 vrmath::Vector3f dir = _focalPoint - _position; 65 dir = dir.normalize(); 66 return dir; 56 67 } 57 68 58 void rotate(double *quat); 69 vrmath::Vector3f getViewPlaneNormal() const 70 { 71 vrmath::Vector3f dir = _position - _focalPoint; 72 dir = dir.normalize(); 73 return dir; 74 } 59 75 60 void rotate(float angle_x, float angle_y, float angle_z);76 void pan(float x, float y, bool absolute = true); 61 77 62 void fov(float fov) 78 void zoom(float z, bool absolute = true); 79 80 void orient(double *quat); 81 82 void orient(float angleX, float angleY, float angleZ); 83 84 void setFov(float fov) 63 85 { 64 86 _fov = fov; 65 87 } 66 88 67 float fov() const89 float getFov() const 68 90 { 69 91 return _fov; … … 74 96 bool resetOrientation = false); 75 97 76 void setClippingRange(float near, float far)77 {78 _near = near;79 _far = far;80 }81 82 98 void resetClippingRange(const vrmath::Vector3f& bboxMin, 83 99 const vrmath::Vector3f& bboxMax); 84 100 85 void set ScreenSize(int sx, int sy, int w, int h)101 void setViewport(int x, int y, int width, int height) 86 102 { 87 _ width = w;88 _ height = h;89 _ startX = sx;90 _ startY = sy;103 _viewport[0] = x; 104 _viewport[1] = y; 105 _viewport[2] = width; 106 _viewport[3] = height; 91 107 } 92 108 … … 99 115 void print() const; 100 116 117 vrmath::Matrix4x4d& getModelViewMatrix() 118 { 119 computeModelViewMatrix(); 120 return _modelViewMatrix; 121 } 122 123 void getProjectionMatrix(vrmath::Matrix4x4d& mat); 124 125 const vrmath::Matrix4x4d& getUpDirMatrix() const; 126 127 void windowToWorldCoords(double x, double y, double z, vrmath::Vector3f& objPos); 128 129 void worldToWindowCoords(double x, double y, double z, vrmath::Vector3f& winPos); 130 101 131 private: 102 void getUpDirMatrix(vrmath::Matrix4x4d& upMat);132 void computeModelViewMatrix(); 103 133 104 /// Location of the camera in the scene 105 vrmath::Vector3f _location; 106 /// Camera view matrix (orientation only, no translation) 107 vrmath::Matrix4x4d _cameraMatrix; 134 void setUpDirMatrix(AxisDirection dir); 135 136 AxisDirection _updir; 137 138 double _zoomRatio; 139 float _pan[2]; 140 /// Position of the camera in the scene 141 vrmath::Vector3f _position; 142 vrmath::Vector3f _focalPoint; 143 144 /// Model transform for z-up scene 145 vrmath::Matrix4x4d _updirMatrix; 146 /// Camera orientation 147 vrmath::Matrix4x4d _rotationMatrix; 148 /// Full camera matrix 149 bool _mvDirty; 150 vrmath::Matrix4x4d _modelViewMatrix; 151 108 152 /// Field of view (vertical angle in degrees) 109 153 float _fov; … … 111 155 float _near, _far; 112 156 113 /// screen width 114 int _width; 115 /// screen height 116 int _height; 117 int _startX; 118 int _startY; 119 }; 157 // x, y, width, height 158 int _viewport[4]; 159 }; 120 160 121 161 } -
trunk/packages/vizservers/nanovis/ColorTableShader.cpp
r3612 r3630 19 19 void ColorTableShader::init() 20 20 { 21 loadFragmentProgram("one_plane.cg" , "main");21 loadFragmentProgram("one_plane.cg"); 22 22 } 23 23 -
trunk/packages/vizservers/nanovis/Command.cpp
r3611 r3630 568 568 return TCL_ERROR; 569 569 } 570 NanoVis::cam->rotate(phi, theta, psi); 571 return TCL_OK; 570 //NanoVis::orientCamera(phi, theta, psi); 571 //return TCL_OK; 572 Tcl_AppendResult(interp, "The 'camera angle' command is deprecated, use 'camera orient'", (char*)NULL); 573 return TCL_ERROR; 572 574 } 573 575 … … 583 585 return TCL_ERROR; 584 586 } 585 NanoVis:: cam->rotate(quat);587 NanoVis::orientCamera(quat); 586 588 return TCL_OK; 587 589 } … … 596 598 return TCL_ERROR; 597 599 } 598 NanoVis::pan (x, y);600 NanoVis::panCamera(x, y); 599 601 return TCL_OK; 600 602 } … … 604 606 Tcl_Obj *const *objv) 605 607 { 606 float x, y, z; 607 if ((GetFloatFromObj(interp, objv[2], &x) != TCL_OK) || 608 (GetFloatFromObj(interp, objv[3], &y) != TCL_OK) || 609 (GetFloatFromObj(interp, objv[4], &z) != TCL_OK)) { 610 return TCL_ERROR; 611 } 612 NanoVis::cam->x(x); 613 NanoVis::cam->y(y); 614 NanoVis::cam->z(z); 608 Vector3f pos; 609 if ((GetFloatFromObj(interp, objv[2], &pos.x) != TCL_OK) || 610 (GetFloatFromObj(interp, objv[3], &pos.y) != TCL_OK) || 611 (GetFloatFromObj(interp, objv[4], &pos.z) != TCL_OK)) { 612 return TCL_ERROR; 613 } 614 615 NanoVis::setCameraPosition(pos); 615 616 return TCL_OK; 616 617 } … … 643 644 return TCL_ERROR; 644 645 } 645 NanoVis::zoom (z);646 NanoVis::zoomCamera(z); 646 647 return TCL_OK; 647 648 } … … 725 726 std::vector<Volume *>::iterator iter; 726 727 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 727 (*iter)->moveCutplane(axis, relval); 728 } 729 return TCL_OK; 730 } 731 732 /* 733 * cutplane state $bool $axis vol,,, 734 */ 728 (*iter)->setCutplanePosition(axis, relval); 729 } 730 return TCL_OK; 731 } 732 735 733 static int 736 734 CutplaneStateOp(ClientData clientData, Tcl_Interp *interp, int objc, … … 1123 1121 return TCL_ERROR; 1124 1122 } 1125 NanoVis:: updir = (axis+1)*sign;1123 NanoVis::setCameraUpdir(Camera::AxisDirection((axis+1)*sign)); 1126 1124 return TCL_OK; 1127 1125 } … … 1264 1262 } 1265 1263 TRACE("finish loading"); 1266 1267 Vector3f scale = volume->getPhysicalScaling();1268 Vector3f loc(scale);1269 loc *= -0.5;1270 volume->location(loc);1271 1264 1272 1265 NanoVis::VolumeHashmap::iterator itr = NanoVis::volumeTable.find(tag); -
trunk/packages/vizservers/nanovis/Flow.cpp
r3611 r3630 10 10 */ 11 11 12 #include <float.h> 13 12 14 #include <tcl.h> 13 15 16 #include <vrmath/BBox.h> 14 17 #include <vrmath/Vector3f.h> 15 18 … … 31 34 using namespace vrmath; 32 35 36 bool Flow::updatePending = false; 37 double Flow::magMin = DBL_MAX; 38 double Flow::magMax = -DBL_MAX; 39 33 40 Flow::Flow(Tcl_Interp *interp, const char *name) : 34 41 _interp(interp), … … 81 88 return; 82 89 83 #if 0 // Using volume bounds instead of these 90 BBox allBounds; 84 91 if (isDataLoaded()) { 85 Vector3f umin, umax; 86 Rappture::Unirect3d *unirect = data(); 87 unirect->getWorldSpaceBounds(umin, umax); 88 if (min.x > umin.x) { 89 min.x = umin.x; 90 } 91 if (max.x < umax.x) { 92 max.x = umax.x; 93 } 94 if (min.y > umin.y) { 95 min.y = umin.y; 96 } 97 if (max.y < umax.y) { 98 max.y = umax.y; 99 } 100 if (min.z > umin.z) { 101 min.z = umin.z; 102 } 103 if (max.z < umax.z) { 104 max.z = umax.z; 105 } 106 } 107 #endif 92 BBox bbox; 93 data()->getBounds(bbox.min, bbox.max); 94 allBounds.extend(bbox); 95 } 108 96 for (BoxHashmap::iterator itr = _boxTable.begin(); 109 97 itr != _boxTable.end(); ++itr) { 110 98 FlowBox *box = itr->second; 111 99 if (!onlyVisible || box->visible()) { 112 Vector3f fbmin, fbmax; 113 box->getWorldSpaceBounds(fbmin, fbmax, 114 getVolume()); 115 if (min.x > fbmin.x) { 116 min.x = fbmin.x; 117 } 118 if (max.x < fbmax.x) { 119 max.x = fbmax.x; 120 } 121 if (min.y > fbmin.y) { 122 min.y = fbmin.y; 123 } 124 if (max.y < fbmax.y) { 125 max.y = fbmax.y; 126 } 127 if (min.z > fbmin.z) { 128 min.z = fbmin.z; 129 } 130 if (max.z < fbmax.z) { 131 max.z = fbmax.z; 132 } 133 } 134 } 100 BBox bbox; 101 box->getBounds(bbox.min, bbox.max); 102 allBounds.extend(bbox); 103 } 104 } 105 min = allBounds.min; 106 max = allBounds.max; 135 107 } 136 108 … … 143 115 switch (position->axis) { 144 116 case AXIS_X: 145 return (position->value - NanoVis::xMin) /146 ( NanoVis::xMax - NanoVis::xMin);117 return (position->value - _data->xMin()) / 118 (_data->xMax() - _data->xMin()); 147 119 case AXIS_Y: 148 return (position->value - NanoVis::yMin) /149 ( NanoVis::yMax - NanoVis::yMin);120 return (position->value - _data->yMin()) / 121 (_data->yMax() - _data->yMin()); 150 122 case AXIS_Z: 151 return (position->value - NanoVis::zMin) /152 ( NanoVis::zMax - NanoVis::zMin);123 return (position->value - _data->zMin()) / 124 (_data->zMax() - _data->zMin()); 153 125 } 154 126 return 0.0; 155 }156 157 float158 Flow::getRelativePosition()159 {160 return getRelativePosition(&_sv.slicePos);161 127 } 162 128 … … 295 261 296 262 bool 263 Flow::configure() 264 { 265 bool needReset = false; 266 267 if (_volume != NULL) { 268 _volume->transferFunction(_sv.transferFunction); 269 _volume->dataEnabled(_sv.showVolume); 270 _volume->twoSidedLighting(_sv.twoSidedLighting); 271 _volume->outline(_sv.showOutline); 272 _volume->opacityScale(_sv.opacity); 273 _volume->ambient(_sv.ambient); 274 _volume->diffuse(_sv.diffuse); 275 _volume->specularLevel(_sv.specular); 276 _volume->specularExponent(_sv.specularExp); 277 } 278 279 float slicePos = getRelativePosition(&_sv.slicePos); 280 281 // FIXME: LIC and arrows should be per-flow 282 if (NanoVis::licRenderer != NULL) { 283 if (NanoVis::licRenderer->getSliceAxis() != _sv.slicePos.axis) { 284 needReset = true; 285 NanoVis::licRenderer->setSliceAxis(_sv.slicePos.axis); 286 } 287 if (NanoVis::licRenderer->getSlicePosition() != slicePos) { 288 needReset = true; 289 NanoVis::licRenderer->setSlicePosition(slicePos); 290 } 291 NanoVis::licRenderer->visible(_sv.sliceVisible); 292 } 293 if (NanoVis::velocityArrowsSlice != NULL) { 294 NanoVis::velocityArrowsSlice->setSliceAxis(_sv.slicePos.axis); 295 NanoVis::velocityArrowsSlice->setSlicePosition(slicePos); 296 NanoVis::velocityArrowsSlice->visible(_sv.showArrows); 297 } 298 299 return needReset; 300 } 301 302 bool 297 303 Flow::scaleVectorField() 298 304 { 305 float *vdata = getScaledVector(); 299 306 if (_volume != NULL) { 300 TRACE("Removing existing volume: %s", _volume->name()); 301 NanoVis::removeVolume(_volume); 302 _volume = NULL; 303 } 304 float *vdata = getScaledVector(); 305 if (vdata == NULL) { 306 return false; 307 } 308 Volume *volume = makeVolume(vdata); 307 TRACE("Updating existing volume: %s", _volume->name()); 308 _volume->setData(vdata, magMin, magMax, 0); 309 } else { 310 _volume = makeVolume(vdata); 311 if (_volume == NULL) { 312 return false; 313 } 314 } 309 315 delete [] vdata; 310 if (volume == NULL) { 311 return false; 312 } 313 _volume = volume; 314 315 Vector3f scale = volume->getPhysicalScaling(); 316 Vector3f location = _volume->location(); 317 316 // FIXME: LIC and arrows should be per-flow 318 317 if (NanoVis::licRenderer != NULL) { 319 NanoVis::licRenderer-> 320 setVectorField(_volume->textureID(), 321 location, 322 scale.x, 323 scale.y, 324 scale.z, 325 _volume->wAxis.max()); 326 setCurrentPosition(); 327 setAxis(); 328 setActive(); 329 } 330 318 NanoVis::licRenderer->setVectorField(_volume); 319 NanoVis::licRenderer->setSliceAxis(_sv.slicePos.axis); 320 NanoVis::licRenderer->setSlicePosition(getRelativePosition(&_sv.slicePos)); 321 NanoVis::licRenderer->visible(_sv.sliceVisible); 322 } 331 323 if (NanoVis::velocityArrowsSlice != NULL) { 332 NanoVis::velocityArrowsSlice-> 333 setVectorField(_volume->textureID(), 334 location, 335 scale.x, 336 scale.y, 337 scale.z, 338 _volume->wAxis.max()); 339 NanoVis::velocityArrowsSlice->axis(_sv.slicePos.axis); 340 NanoVis::velocityArrowsSlice->slicePos(_sv.slicePos.value); 341 NanoVis::velocityArrowsSlice->enabled(_sv.showArrows); 342 } 343 344 for (ParticlesHashmap::iterator itr = _particlesTable.begin(); 345 itr != _particlesTable.end(); ++itr) { 346 itr->second->setVectorField(_volume, 347 location, 348 scale.x, 349 scale.y, 350 scale.z, 351 _volume->wAxis.max()); 324 NanoVis::velocityArrowsSlice->setVectorField(_volume); 325 NanoVis::velocityArrowsSlice->setSliceAxis(_sv.slicePos.axis); 326 NanoVis::velocityArrowsSlice->setSlicePosition(getRelativePosition(&_sv.slicePos)); 327 NanoVis::velocityArrowsSlice->visible(_sv.showArrows); 328 } 329 for (ParticlesHashmap::iterator itr = _particlesTable.begin(); 330 itr != _particlesTable.end(); ++itr) { 331 itr->second->setVectorField(_volume); 352 332 } 353 333 return true; … … 371 351 size_t n = _data->nValues() / _data->nComponents() * 4; 372 352 float *data = new float[n]; 373 if (data == NULL) {374 return NULL;375 }376 353 memset(data, 0, sizeof(float) * n); 377 354 float *dest = data; … … 385 362 vz = values[2]; 386 363 vm = sqrt(vx*vx + vy*vy + vz*vz); 387 dest[0] = vm / NanoVis::magMax;388 dest[1] = vx /(2.0 *NanoVis::magMax) + 0.5;389 dest[2] = vy /(2.0 *NanoVis::magMax) + 0.5;390 dest[3] = vz /(2.0 *NanoVis::magMax) + 0.5;364 dest[0] = vm / magMax; 365 dest[1] = vx /(2.0 * magMax) + 0.5; 366 dest[2] = vy /(2.0 * magMax) + 0.5; 367 dest[3] = vz /(2.0 * magMax) + 0.5; 391 368 values += 3; 392 369 dest += 4; … … 406 383 _data->zNum(), 407 384 4, data, 408 NanoVis::magMin, NanoVis::magMax, 0);385 magMin, magMax, 0); 409 386 volume->xAxis.setRange(_data->xMin(), _data->xMax()); 410 387 volume->yAxis.setRange(_data->yMin(), _data->yMax()); 411 388 volume->zAxis.setRange(_data->zMin(), _data->zMax()); 412 389 413 TRACE("min=%g %g %g max=%g %g %g mag=%g %g", 414 NanoVis::xMin, NanoVis::yMin, NanoVis::zMin, 415 NanoVis::xMax, NanoVis::yMax, NanoVis::zMax, 416 NanoVis::magMin, NanoVis::magMax); 390 TRACE("mag=%g %g", magMin, magMax); 417 391 418 392 volume->disableCutplane(0); … … 430 404 volume->specularLevel(_sv.specular); 431 405 volume->specularExponent(_sv.specularExp); 432 volume->visible(_sv.showVolume);433 434 Vector3f volScaling = volume->getPhysicalScaling();435 Vector3f loc(volScaling);436 loc *= -0.5;437 volume->location(loc);438 406 439 407 Volume::updatePending = true; -
trunk/packages/vizservers/nanovis/Flow.h
r3613 r3630 25 25 #include "FlowBox.h" 26 26 #include "LIC.h" 27 #include "VelocityArrowsSlice.h" 27 28 #include "Unirect.h" 28 29 #include "Volume.h" … … 50 51 { 51 52 public: 52 enum SliceAxis { AXIS_X, AXIS_Y, AXIS_Z };53 54 53 Flow(Tcl_Interp *interp, const char *name); 55 54 … … 84 83 void getBoxNames(std::vector<std::string>& names); 85 84 86 float *getScaledVector();87 88 Volume *makeVolume(float *data);89 90 85 bool scaleVectorField(); 91 86 … … 117 112 _data = data; 118 113 } 114 115 FlowSliceAxis getAxis() 116 { 117 return _sv.slicePos.axis; 118 } 119 120 TransferFunction *getTransferFunction() 121 { 122 return _sv.transferFunction; 123 } 119 124 #if 0 120 void activateSlice() 121 { 122 /* Must set axis before offset or position goes to wrong axis. */ 123 NanoVis::licRenderer->setAxis(_sv.slicePos.axis); 124 NanoVis::licRenderer->setOffset(_sv.slicePos.value); 125 NanoVis::licRenderer->active(true); 126 } 127 128 void deactivateSlice() 129 { 130 NanoVis::licRenderer->active(false); 125 void setAxis(FlowSliceAxis axis) 126 { 127 _sv.slicePos.axis = axis; 128 if (NanoVis::licRenderer != NULL) { 129 NanoVis::licRenderer->setSliceAxis(_sv.slicePos.axis); 130 } 131 if (NanoVis::velocityArrowsSlice != NULL) { 132 NanoVis::velocityArrowsSlice->setSliceAxis(_sv.slicePos.axis); 133 } 134 } 135 136 void setCurrentPosition(float position) 137 { 138 _sv.slicePos.value = position; 139 if (NanoVis::licRenderer != NULL) { 140 NanoVis::licRenderer->setSlicePosition(_sv.slicePos.value); 141 } 142 if (NanoVis::velocityArrowsSlice != NULL) { 143 NanoVis::velocityArrowsSlice->setSlicePosition(_sv.slicePos.value); 144 } 145 } 146 147 void setLICActive(bool state) 148 { 149 _sv.sliceVisible = state; 150 if (NanoVis::licRenderer != NULL) { 151 NanoVis::licRenderer->setVectorField(_volume); 152 NanoVis::licRenderer->setSliceAxis(_sv.slicePos.axis); 153 NanoVis::licRenderer->setSlicePosition(_sv.slicePos.value); 154 NanoVis::licRenderer->visible(state); 155 } 156 } 157 158 void setArrowsActive(bool state) 159 _sv.showArrows = state; 160 if (NanoVis::velocityArrowsSlice != NULL) { 161 NanoVis::velocityArrowsSlice->setVectorField(_volume); 162 NanoVis::velocityArrowsSlice->setSliceAxis(_sv.slicePos.axis); 163 NanoVis::velocityArrowsSlice->setSlicePosition(_sv.slicePos.value); 164 NanoVis::velocityArrowsSlice->visible(_sv.showArrows); 165 } 131 166 } 132 167 #endif 133 SliceAxis getAxis()134 {135 return (SliceAxis)_sv.slicePos.axis;136 }137 138 TransferFunction *getTransferFunction()139 {140 return _sv.transferFunction;141 }142 143 float getRelativePosition();144 145 void setAxis()146 {147 NanoVis::licRenderer->setAxis(_sv.slicePos.axis);148 }149 150 void setAxis(Flow::SliceAxis axis)151 {152 _sv.slicePos.axis = axis;153 NanoVis::licRenderer->setAxis(_sv.slicePos.axis);154 }155 156 void setCurrentPosition(float position)157 {158 _sv.slicePos.value = position;159 NanoVis::licRenderer->setOffset(_sv.slicePos.value);160 }161 162 void setCurrentPosition()163 {164 NanoVis::licRenderer->setOffset(_sv.slicePos.value);165 }166 167 void setActive(bool state)168 {169 _sv.sliceVisible = state;170 NanoVis::licRenderer->active(state);171 }172 173 void setActive()174 {175 NanoVis::licRenderer->active(_sv.sliceVisible);176 }177 178 168 const Volume *getVolume() const 179 169 { … … 190 180 } 191 181 182 bool configure(); 183 192 184 Tcl_Command getCommandToken() 193 185 { … … 195 187 } 196 188 197 static float getRelativePosition(FlowPosition *pos); 189 float getRelativePosition(FlowPosition *pos); 190 191 static bool updatePending; 192 static double magMin, magMax; 198 193 199 194 private: … … 203 198 typedef std::tr1::unordered_map<BoxId, FlowBox *> BoxHashmap; 204 199 205 void configure(); 200 float *getScaledVector(); 201 202 Volume *makeVolume(float *data); 206 203 207 204 void renderBoxes(); -
trunk/packages/vizservers/nanovis/FlowBox.cpp
r3611 r3630 45 45 46 46 void 47 FlowBox::getWorldSpaceBounds(Vector3f& bboxMin, 48 Vector3f& bboxMax, 49 const Volume *vol) const 47 FlowBox::getBounds(Vector3f& bboxMin, 48 Vector3f& bboxMax) const 50 49 { 51 bboxMin.set(FLT_MAX, FLT_MAX, FLT_MAX); 52 bboxMax.set(-FLT_MAX, -FLT_MAX, -FLT_MAX); 53 54 Vector3f origin = vol->location(); 55 Vector3f scale = vol->getPhysicalScaling(); 56 57 Matrix4x4d mat; 58 mat.makeTranslation(origin); 59 Matrix4x4d mat2; 60 mat2.makeScale(scale); 61 62 mat.multiply(mat2); 63 64 Vector3f min, max; 65 min.x = vol->xAxis.min(); 66 min.y = vol->yAxis.min(); 67 min.z = vol->zAxis.min(); 68 max.x = vol->xAxis.max(); 69 max.y = vol->yAxis.max(); 70 max.z = vol->zAxis.max(); 71 72 float x0, y0, z0, x1, y1, z1; 73 x0 = y0 = z0 = 0.0f; 74 x1 = y1 = z1 = 0.0f; 75 if (max.x > min.x) { 76 x0 = (_sv.corner1.x - min.x) / (max.x - min.x); 77 x1 = (_sv.corner2.x - min.x) / (max.x - min.x); 78 } 79 if (max.y > min.y) { 80 y0 = (_sv.corner1.y - min.y) / (max.y - min.y); 81 y1 = (_sv.corner2.y - min.y) / (max.y - min.y); 82 } 83 if (max.z > min.z) { 84 z0 = (_sv.corner1.z - min.z) / (max.z - min.z); 85 z1 = (_sv.corner2.z - min.z) / (max.z - min.z); 86 } 87 88 TRACE("Box model bounds: (%g,%g,%g) - (%g,%g,%g)", 89 x0, y0, z0, x1, y1, z1); 90 91 Vector3f modelMin(x0, y0, z0); 92 Vector3f modelMax(x1, y1, z1); 93 94 Vector4f bvert[8]; 95 bvert[0] = Vector4f(modelMin.x, modelMin.y, modelMin.z, 1); 96 bvert[1] = Vector4f(modelMax.x, modelMin.y, modelMin.z, 1); 97 bvert[2] = Vector4f(modelMin.x, modelMax.y, modelMin.z, 1); 98 bvert[3] = Vector4f(modelMin.x, modelMin.y, modelMax.z, 1); 99 bvert[4] = Vector4f(modelMax.x, modelMax.y, modelMin.z, 1); 100 bvert[5] = Vector4f(modelMax.x, modelMin.y, modelMax.z, 1); 101 bvert[6] = Vector4f(modelMin.x, modelMax.y, modelMax.z, 1); 102 bvert[7] = Vector4f(modelMax.x, modelMax.y, modelMax.z, 1); 103 104 for (int i = 0; i < 8; i++) { 105 Vector4f worldVert = mat.transform(bvert[i]); 106 if (worldVert.x < bboxMin.x) bboxMin.x = worldVert.x; 107 if (worldVert.x > bboxMax.x) bboxMax.x = worldVert.x; 108 if (worldVert.y < bboxMin.y) bboxMin.y = worldVert.y; 109 if (worldVert.y > bboxMax.y) bboxMax.y = worldVert.y; 110 if (worldVert.z < bboxMin.z) bboxMin.z = worldVert.z; 111 if (worldVert.z > bboxMax.z) bboxMax.z = worldVert.z; 112 } 113 114 TRACE("Box world bounds: (%g,%g,%g) - (%g,%g,%g)", 115 bboxMin.x, bboxMin.y, bboxMin.z, 116 bboxMax.x, bboxMax.y, bboxMax.z); 50 bboxMin.set(_sv.corner1.x, _sv.corner1.y, _sv.corner1.z); 51 bboxMax.set(_sv.corner2.x, _sv.corner2.y, _sv.corner2.z); 117 52 } 118 53 … … 131 66 glPushMatrix(); 132 67 133 Vector3f origin = vol->location(); 134 glTranslatef(origin.x, origin.y, origin.z); 135 136 Vector3f scale = vol->getPhysicalScaling(); 137 glScalef(scale.x, scale.y, scale.z); 138 139 Vector3f min, max; 140 min.x = vol->xAxis.min(); 141 min.y = vol->yAxis.min(); 142 min.z = vol->zAxis.min(); 143 max.x = vol->xAxis.max(); 144 max.y = vol->yAxis.max(); 145 max.z = vol->zAxis.max(); 146 147 TRACE("box is %g,%g %g,%g %g,%g", 68 TRACE("box bounds %g,%g %g,%g %g,%g", 148 69 _sv.corner1.x, _sv.corner2.x, 149 70 _sv.corner1.y, _sv.corner2.y, 150 71 _sv.corner1.z, _sv.corner2.z); 151 TRACE("world is %g,%g %g,%g %g,%g",152 min.x, max.x, min.y, max.y, min.z, max.z);153 72 154 73 float x0, y0, z0, x1, y1, z1; 155 x0 = y0 = z0 = 0.0f; 156 x1 = y1 = z1 = 0.0f; 157 if (max.x > min.x) { 158 x0 = (_sv.corner1.x - min.x) / (max.x - min.x); 159 x1 = (_sv.corner2.x - min.x) / (max.x - min.x); 160 } 161 if (max.y > min.y) { 162 y0 = (_sv.corner1.y - min.y) / (max.y - min.y); 163 y1 = (_sv.corner2.y - min.y) / (max.y - min.y); 164 } 165 if (max.z > min.z) { 166 z0 = (_sv.corner1.z - min.z) / (max.z - min.z); 167 z1 = (_sv.corner2.z - min.z) / (max.z - min.z); 168 } 169 TRACE("box bounds: %g,%g %g,%g %g,%g", 170 x0, x1, y0, y1, z0, z1); 74 75 x0 = _sv.corner1.x; 76 x1 = _sv.corner2.x; 77 y0 = _sv.corner1.y; 78 y1 = _sv.corner2.y; 79 z0 = _sv.corner1.z; 80 z1 = _sv.corner2.z; 171 81 172 82 glColor4d(_sv.color.r, _sv.color.g, _sv.color.b, _sv.color.a); -
trunk/packages/vizservers/nanovis/FlowBox.h
r3613 r3630 63 63 } 64 64 65 void getWorldSpaceBounds(vrmath::Vector3f& min, 66 vrmath::Vector3f& max, 67 const Volume *volume) const; 65 void getBounds(vrmath::Vector3f& min, 66 vrmath::Vector3f& max) const; 68 67 69 68 private: -
trunk/packages/vizservers/nanovis/FlowCmd.cpp
r3611 r3630 104 104 105 105 Rappture::SwitchSpec FlowParticles::_switches[] = { 106 {Rappture::SWITCH_CUSTOM, "-axis", " string",106 {Rappture::SWITCH_CUSTOM, "-axis", "axis", 107 107 offsetof(FlowParticlesValues, position.axis), 0, 0, &axisSwitch}, 108 108 {Rappture::SWITCH_CUSTOM, "-color", "{r g b a}", … … 197 197 } 198 198 flow->data(dataPtr); 199 NanoVis::eventuallyRedraw(NanoVis::MAP_FLOWS); 199 Flow::updatePending = true; 200 NanoVis::eventuallyRedraw(); 200 201 return TCL_OK; 201 202 } … … 266 267 dataPtr->convert(u2dPtr); 267 268 delete u2dPtr; 269 #if 0 270 } else if ((length > 14) && (strncmp(bytes, "# vtk DataFile", 14) == 0)) { 271 TRACE("VTK loading..."); 272 std::stringstream fdata; 273 fdata.write(bytes, length); 274 if (length <= 0) { 275 ERROR("data buffer is empty"); 276 abort(); 277 } 278 Rappture::Outcome context; 279 volume = load_vtk_volume_stream(context, tag, fdata); 280 if (volume == NULL) { 281 Tcl_AppendResult(interp, context.remark(), (char*)NULL); 282 return TCL_ERROR; 283 } 284 #endif 268 285 } else { 269 286 TRACE("header is %.14s", buf.bytes()); … … 307 324 #endif 308 325 } 309 NanoVis::eventuallyRedraw(NanoVis::MAP_FLOWS); 326 Flow::updatePending = true; 327 NanoVis::eventuallyRedraw(); 310 328 return TCL_OK; 311 329 } … … 353 371 const char *string = Tcl_GetString(objPtr); 354 372 if (string[1] == '\0') { 355 Flow ::SliceAxis *axisPtr = (Flow::SliceAxis *)(record + offset);373 FlowSliceAxis *axisPtr = (FlowSliceAxis *)(record + offset); 356 374 char c; 357 375 c = tolower((unsigned char)string[0]); 358 376 if (c == 'x') { 359 *axisPtr = Flow::AXIS_X;377 *axisPtr = AXIS_X; 360 378 return TCL_OK; 361 379 } else if (c == 'y') { 362 *axisPtr = Flow::AXIS_Y;380 *axisPtr = AXIS_Y; 363 381 return TCL_OK; 364 382 } else if (c == 'z') { 365 *axisPtr = Flow::AXIS_Z;383 *axisPtr = AXIS_Z; 366 384 return TCL_OK; 367 385 } … … 564 582 return TCL_ERROR; 565 583 } 566 NanoVis::eventuallyRedraw(NanoVis::MAP_FLOWS); 584 if (flow->configure()) { 585 Flow::updatePending = true; 586 } 587 NanoVis::eventuallyRedraw(); 567 588 return TCL_OK; 568 589 } … … 587 608 } 588 609 particles->configure(); 610 Flow::updatePending = true; 589 611 NanoVis::eventuallyRedraw(); 590 612 Tcl_SetObjResult(interp, objv[3]); … … 608 630 return TCL_ERROR; 609 631 } 610 particles->configure(); 611 NanoVis::eventuallyRedraw(NanoVis::MAP_FLOWS); 632 if (particles->configure()) { 633 Flow::updatePending = true; 634 } 635 NanoVis::eventuallyRedraw(); 612 636 return TCL_OK; 613 637 } … … 815 839 return TCL_ERROR; 816 840 } 817 if ( NanoVis::flags & NanoVis::MAP_FLOWS) {841 if (Flow::updatePending) { 818 842 NanoVis::mapFlows(); 819 843 } 820 NanoVis::renderLegend(tf, NanoVis::magMin, NanoVis::magMax, w, h, label);844 NanoVis::renderLegend(tf, Flow::magMin, Flow::magMax, w, h, label); 821 845 return TCL_OK; 822 846 } … … 905 929 } 906 930 } 907 NanoVis::eventuallyRedraw(NanoVis::MAP_FLOWS); 931 Flow::updatePending = true; 932 NanoVis::eventuallyRedraw(); 908 933 return TCL_OK; 909 934 } … … 939 964 } 940 965 NanoVis::resetFlows(); 941 if ( NanoVis::flags & NanoVis::MAP_FLOWS) {966 if (Flow::updatePending) { 942 967 NanoVis::mapFlows(); 943 968 } 944 NanoVis::advectFlows();945 969 for (int i = 0; i < nSteps; i++) { 946 if (NanoVis::licRenderer->active()) { 947 NanoVis::licRenderer->convolve(); 948 } 970 NanoVis::licRenderer->convolve(); 949 971 NanoVis::advectFlows(); 950 972 } … … 974 996 { 975 997 assert(NanoVis::licRenderer != NULL); 976 if ( NanoVis::flags & NanoVis::MAP_FLOWS) {998 if (Flow::updatePending) { 977 999 NanoVis::mapFlows(); 978 1000 } 979 NanoVis::eventuallyRedraw();980 1001 NanoVis::licRenderer->convolve(); 981 1002 NanoVis::advectFlows(); 1003 NanoVis::eventuallyRedraw(); 982 1004 return TCL_OK; 983 1005 } … … 1101 1123 break; 1102 1124 } 1103 if (NanoVis::licRenderer->active()) { 1104 NanoVis::licRenderer->convolve(); 1105 } 1125 1126 NanoVis::licRenderer->convolve(); 1106 1127 NanoVis::advectFlows(); 1107 1128 -
trunk/packages/vizservers/nanovis/FlowParticles.cpp
r3627 r3630 28 28 _sv.position.value = 0.0f; 29 29 _sv.position.flags = RELPOS; 30 _sv.position.axis = 0; // X_AXIS30 _sv.position.axis = AXIS_Z; 31 31 _sv.color.r = _sv.color.g = _sv.color.b = _sv.color.a = 1.0f; 32 32 _sv.isHidden = false; … … 44 44 } 45 45 46 float 47 FlowParticles::getRelativePosition(FlowPosition *position) 48 { 49 if (position->flags == RELPOS) { 50 return position->value; 51 } 52 switch (position->axis) { 53 case AXIS_X: 54 return (position->value - _volume->xAxis.min()) / 55 (_volume->xAxis.max() - _volume->xAxis.min()); 56 case AXIS_Y: 57 return (position->value - _volume->yAxis.min()) / 58 (_volume->yAxis.max() - _volume->yAxis.min()); 59 case AXIS_Z: 60 return (position->value - _volume->zAxis.min()) / 61 (_volume->zAxis.max() - _volume->zAxis.min()); 62 } 63 return 0.0; 64 } 65 46 66 void 47 67 FlowParticles::render() … … 49 69 TRACE("Particles '%s' axis: %d pos: %g rel pos: %g", 50 70 _name.c_str(), _sv.position.axis, _sv.position.value, 51 Flow::getRelativePosition(&_sv.position));71 getRelativePosition(&_sv.position)); 52 72 53 _renderer->setPos( Flow::getRelativePosition(&_sv.position));73 _renderer->setPos(getRelativePosition(&_sv.position)); 54 74 _renderer->setAxis(_sv.position.axis); 55 75 assert(_renderer->active()); … … 57 77 } 58 78 59 void 79 bool 60 80 FlowParticles::configure() 61 81 { 62 _renderer->setPos(Flow::getRelativePosition(&_sv.position)); 82 bool needReset = false; 83 63 84 _renderer->setColor(Color4f(_sv.color.r, 64 85 _sv.color.g, … … 66 87 _sv.color.a)); 67 88 _renderer->particleSize(_sv.particleSize); 68 _renderer->setAxis(_sv.position.axis); 89 if (_renderer->getAxis() != _sv.position.axis) { 90 needReset = true; 91 _renderer->setAxis(_sv.position.axis); 92 } 93 float pos = getRelativePosition(&_sv.position); 94 if (_renderer->getPos() != pos) { 95 needReset = true; 96 _renderer->setPos(pos); 97 } 69 98 _renderer->active(!_sv.isHidden); 99 100 return needReset; 70 101 } -
trunk/packages/vizservers/nanovis/FlowParticles.h
r3613 r3630 77 77 } 78 78 79 void setVectorField(Volume *volume, const vrmath::Vector3f& location, 80 float scaleX, float scaleY, float scaleZ, 81 float max) 79 void setVectorField(Volume *volume) 82 80 { 83 _renderer-> 84 setVectorField(volume->textureID(), 85 location, 86 scaleX, 87 scaleY, 88 scaleZ, 89 max); 81 _volume = volume; 82 _renderer->setVectorField(volume); 90 83 } 91 84 92 void configure(); 85 float getRelativePosition(FlowPosition *position); 86 87 bool configure(); 93 88 94 89 private: … … 99 94 std::string _name; 100 95 nv::ParticleRenderer *_renderer; ///< Particle renderer 96 Volume *_volume; 101 97 FlowParticlesValues _sv; 102 98 -
trunk/packages/vizservers/nanovis/FlowTypes.h
r3613 r3630 14 14 namespace nv { 15 15 16 enum FlowSliceAxis { 17 AXIS_X, 18 AXIS_Y, 19 AXIS_Z 20 }; 21 16 22 struct FlowColor { 17 23 float r, g, b, a; … … 25 31 float value; 26 32 unsigned int flags; 27 intaxis;33 FlowSliceAxis axis; 28 34 }; 29 35 -
trunk/packages/vizservers/nanovis/Grid.cpp
r3627 r3630 38 38 } 39 39 40 void Grid::getBounds(vrmath::Vector3f& bboxMin, vrmath::Vector3f& bboxMax) const 41 { 42 bboxMin.set(xAxis.min(), yAxis.min(), zAxis.min()); 43 bboxMax.set(xAxis.min() + xAxis.range(), 44 yAxis.min() + yAxis.range(), 45 zAxis.min() + zAxis.range()); 46 } 47 40 48 void Grid::render() 41 49 { … … 55 63 glPushMatrix(); 56 64 57 double xDataRange = xAxis.dataMax() - xAxis.dataMin(); 58 double yDataRange = yAxis.dataMax() - yAxis.dataMin(); 59 double zDataRange = zAxis.dataMax() - zAxis.dataMin(); 60 61 double paspectX = 1.0f; 62 double paspectY = yDataRange / xDataRange; 63 double paspectZ = zDataRange / xDataRange; 64 65 double xscale = xAxis.range() / xDataRange; 66 double yscale = yAxis.range() / xDataRange; 67 double zscale = zAxis.range() / xDataRange; 68 69 double xoffset = (xAxis.min() - xAxis.dataMin()) * xAxis.scale(); 70 double yoffset = (yAxis.min() - yAxis.dataMin()) * yAxis.scale(); 71 double zoffset = (zAxis.min() - zAxis.dataMin()) * zAxis.scale(); 72 73 TRACE("Axis ranges: %g %g %g", xAxis.range(), yAxis.range(), zAxis.range()); 74 TRACE("Axis scales: %g %g %g", xAxis.scale(), yAxis.scale(), zAxis.scale()); 75 TRACE("Axis min/max: %g,%g %g,%g %g,%g", 76 xAxis.min(), xAxis.max(), 77 yAxis.min(), yAxis.max(), 78 zAxis.min(), zAxis.max()); 79 TRACE("Axis vmin/vmax: %g,%g %g,%g %g,%g", 80 xAxis.dataMin(), xAxis.dataMax(), 81 yAxis.dataMin(), yAxis.dataMax(), 82 zAxis.dataMin(), zAxis.dataMax()); 83 TRACE("paspect: %g %g %g", paspectX, paspectY, paspectZ); 84 TRACE("scale: %g %g %g", xscale, yscale, zscale); 85 86 glTranslatef(-0.5f * paspectX, -0.5f * paspectY, -0.5f * paspectZ); 87 glScalef(xscale, yscale, zscale); 88 glTranslatef(xoffset, yoffset, zoffset); 65 glTranslatef(xAxis.min(), yAxis.min(), zAxis.min()); 66 glScalef(xAxis.range(), yAxis.range(), zAxis.range()); 89 67 90 68 glLineWidth(2.0f); -
trunk/packages/vizservers/nanovis/Grid.h
r3627 r3630 7 7 #define NV_GRID_H 8 8 9 #include <vrmath/Vector3f.h> 9 10 #include <vrmath/Color4f.h> 10 11 … … 49 50 void setFont(nv::util::Fonts *font); 50 51 52 void getBounds(vrmath::Vector3f& bboxMin, 53 vrmath::Vector3f& bboxMax) const; 54 51 55 Axis xAxis; 52 56 Axis yAxis; -
trunk/packages/vizservers/nanovis/HeightMap.cpp
r3612 r3630 40 40 { 41 41 _shader = new Shader(); 42 _shader->loadFragmentProgram("heightcolor.cg" , "main");42 _shader->loadFragmentProgram("heightcolor.cg"); 43 43 } 44 44 … … 490 490 491 491 void 492 HeightMap::getWorldSpaceBounds(Vector3f& bboxMin, 493 Vector3f& bboxMax) const 494 { 495 bboxMin.set(FLT_MAX, FLT_MAX, FLT_MAX); 496 bboxMax.set(-FLT_MAX, -FLT_MAX, -FLT_MAX); 497 498 499 } 492 HeightMap::getBounds(Vector3f& bboxMin, 493 Vector3f& bboxMax) const 494 { 495 bboxMin.set(xAxis.min(), yAxis.min(), zAxis.min()); 496 bboxMax.set(xAxis.max(), yAxis.max(), zAxis.max()); 497 } -
trunk/packages/vizservers/nanovis/HeightMap.h
r3612 r3630 113 113 } 114 114 115 void get WorldSpaceBounds(vrmath::Vector3f& bboxMin, vrmath::Vector3f& bboxMax) const;115 void getBounds(vrmath::Vector3f& bboxMin, vrmath::Vector3f& bboxMax) const; 116 116 117 117 AxisRange xAxis, yAxis, zAxis, wAxis; -
trunk/packages/vizservers/nanovis/LIC.cpp
r3612 r3630 24 24 using namespace vrmath; 25 25 26 LIC::LIC( int size, int width, int height, intaxis,26 LIC::LIC(FlowSliceAxis axis, 27 27 float offset) : 28 _width( width),29 _height( height),30 _size( size),28 _width(NPIX), 29 _height(NPIX), 30 _size(NMESH), 31 31 _scale(1.0f, 1.0f, 1.0f), 32 32 _origin(0, 0, 0), … … 41 41 _disListID(0), 42 42 _vectorFieldId(0), 43 _ activate(false)44 { 45 _sliceVector = new float[_size *_size*4];43 _visible(false) 44 { 45 _sliceVector = new float[_size * _size * 4]; 46 46 memset(_sliceVector, 0, sizeof(float) * _size * _size * 4); 47 47 … … 104 104 105 105 _renderVelShader = new Shader(); 106 _renderVelShader->loadFragmentProgram("render_vel.cg" , "main");106 _renderVelShader->loadFragmentProgram("render_vel.cg"); 107 107 108 108 makePatterns(); … … 178 178 } 179 179 180 void LIC::makeMagnitudes() 180 void 181 LIC::makeMagnitudes() 181 182 { 182 183 GLubyte mag[NMESH][NMESH][4]; … … 246 247 247 248 switch (_axis) { 248 case 0:249 case AXIS_X: 249 250 _renderVelShader->setFPParameter3f("projection_vector", 0., 1., 1.); 250 251 break; 251 case 1:252 case AXIS_Y: 252 253 _renderVelShader->setFPParameter3f("projection_vector", 1., 0., 1.); 253 254 break; 254 255 default: 255 case 2:256 case AXIS_Z: 256 257 _renderVelShader->setFPParameter3f("projection_vector", 1., 1., 0.); 257 258 break; … … 261 262 { 262 263 switch (_axis) { 263 case 0:264 case AXIS_X: 264 265 glTexCoord3f(_offset, 0., 0.); glVertex2f(0., 0.); 265 266 glTexCoord3f(_offset, 1., 0.); glVertex2f(_size, 0.); … … 267 268 glTexCoord3f(_offset, 0., 1.); glVertex2f(0., _size); 268 269 break; 269 case 1:270 case AXIS_Y: 270 271 glTexCoord3f(0., _offset, 0.); glVertex2f(0., 0.); 271 272 glTexCoord3f(1., _offset, 0.); glVertex2f(_size, 0.); … … 273 274 glTexCoord3f(0., _offset, 1.); glVertex2f(0., _size); 274 275 break; 275 case 2:276 case AXIS_Z: 276 277 glTexCoord3f(0., 0., _offset); glVertex2f(0., 0.); 277 278 glTexCoord3f(1., 0., _offset); glVertex2f(_size, 0.); … … 428 429 LIC::render() 429 430 { 430 if (_vectorFieldId == 0 ) {431 if (_vectorFieldId == 0 || !_visible) { 431 432 return; 432 433 } … … 451 452 glBegin(GL_QUADS); 452 453 switch (_axis) { 453 case 0:454 case AXIS_X: 454 455 glNormal3f(1, 0, 0); 455 456 glTexCoord2f(0, 0); glVertex3f(_offset, 0, 0); … … 458 459 glTexCoord2f(0, 1); glVertex3f(_offset, 0, 1); 459 460 break; 460 case 1:461 case AXIS_Y: 461 462 glNormal3f(0, 1, 0); 462 463 glTexCoord2f(0, 0); glVertex3f(0, _offset, 0); … … 465 466 glTexCoord2f(0, 1); glVertex3f(0, _offset, 1); 466 467 break; 467 case 2:468 case AXIS_Z: 468 469 glNormal3f(0, 0, 1); 469 470 glTexCoord2f(0, 0); glVertex3f(0, 0, _offset); … … 483 484 484 485 void 485 LIC::setVectorField(unsigned int texID, const Vector3f& origin, 486 float scaleX, float scaleY, float scaleZ, float max) 487 { 488 TRACE("LIC: vector field is assigned [%d]", texID); 489 _vectorFieldId = texID; 490 _origin = origin; 491 _scale = Vector3f(scaleX, scaleY, scaleZ); 492 _max = max; 486 LIC::setVectorField(Volume *volume) 487 { 488 TRACE("LIC: vector field is assigned [%d]", volume->textureID()); 489 490 _vectorFieldId = volume->textureID(); 491 Vector3f bmin, bmax; 492 volume->getBounds(bmin, bmax); 493 _origin = bmin; 494 _scale.set(bmax.x-bmin.x, bmax.y-bmin.y, bmax.z-bmin.z); 495 _max = volume->wAxis.max(); 493 496 494 497 makePatterns(); … … 507 510 //TRACE("(xi yi) = (%d %d), ", xi, yi); 508 511 switch (_axis) { 509 case 0:512 case AXIS_X: 510 513 vx = _sliceVector[4 * (xi+yi*_size)+2]; 511 514 vy = _sliceVector[4 * (xi+yi*_size)+1]; 512 515 break; 513 case 1:516 case AXIS_Y: 514 517 vx = _sliceVector[4 * (xi+yi*_size)]; 515 518 vy = _sliceVector[4 * (xi+yi*_size)+2]; 516 519 break; 517 case 2:520 case AXIS_Z: 518 521 default: 519 522 vx = _sliceVector[4 * (xi+yi*_size)]; … … 537 540 538 541 void 539 LIC::set Offset(float offset)542 LIC::setSlicePosition(float offset) 540 543 { 541 544 _offset = offset; … … 543 546 } 544 547 545 void LIC::set Axis(intaxis)548 void LIC::setSliceAxis(FlowSliceAxis axis) 546 549 { 547 550 _axis = axis; -
trunk/packages/vizservers/nanovis/LIC.h
r3612 r3630 13 13 #include <vrmath/Vector3f.h> 14 14 15 #include "FlowTypes.h" 15 16 #include "Volume.h" 16 17 #include "Shader.h" … … 21 22 { 22 23 public: 23 LIC( int size, int width, int height, int axis, float offset);24 LIC(FlowSliceAxis axis = AXIS_Z, float offset = 0.f); 24 25 ~LIC(); 25 26 … … 30 31 void render(); 31 32 32 void makePatterns();33 void setSlicePosition(float pos); 33 34 34 void makeMagnitudes(); 35 36 void getVelocity(float x, float y, float *px, float *py); 37 38 void getSlice(); 39 40 void setOffset(float offset); 35 float getSlicePosition() const 36 { 37 return _offset; 38 } 41 39 42 40 /** 43 41 * @brief Specify the perpendicular axis 44 *45 * 0 : x axis<br>46 * 1 : y axis<br>47 * 2 : z axis<br>48 42 */ 49 void set Axis(intaxis);43 void setSliceAxis(FlowSliceAxis axis); 50 44 51 void setVectorField(unsigned int texID, const vrmath::Vector3f& origin, 52 float scaleX, float scaleY, float scaleZ, float max); 45 FlowSliceAxis getSliceAxis() const 46 { 47 return _axis; 48 } 49 50 void setVectorField(Volume *volume); 53 51 54 52 void reset(); … … 56 54 void visible(bool state) 57 55 { 58 _ isHidden = !state;56 _visible = state; 59 57 } 60 58 61 59 bool visible() const 62 60 { 63 return (!_isHidden); 64 } 65 66 void active(bool state) 67 { 68 _activate = state; 69 } 70 71 bool active() const 72 { 73 return _activate; 61 return _visible; 74 62 } 75 63 76 64 private: 65 void getVelocity(float x, float y, float *px, float *py); 66 67 void getSlice(); 68 69 void makePatterns(); 70 71 void makeMagnitudes(); 72 77 73 /** 78 74 * @brief the normal vector of the LIC plane, … … 89 85 plane to fit the actual dimensions */ 90 86 vrmath::Vector3f _origin; 91 float _offset; ///< [0,1] offset of slice plane92 int _axis;///< Axis normal to slice plane87 float _offset; ///< [0,1] offset of slice plane 88 FlowSliceAxis _axis; ///< Axis normal to slice plane 93 89 94 90 //some convolve variables. They can pretty much stay fixed … … 114 110 * flag for rendering 115 111 */ 116 bool _activate; 117 bool _isHidden; // Indicates if LIC plane is displayed. 112 bool _visible; // Indicates if LIC plane is displayed. 118 113 }; 119 114 -
trunk/packages/vizservers/nanovis/Makefile.in
r3627 r3630 287 287 ContourLineFilter.o: ContourLineFilter.cpp ContourLineFilter.h 288 288 ConvexPolygon.o: ConvexPolygon.cpp ConvexPolygon.h $(VRMATH_DIR)/include/vrmath/Vector4f.h $(VRMATH_DIR)/include/vrmath/Matrix4x4d.h Plane.h 289 Flow.o: Flow.cpp Flow.h FlowCmd.h FlowTypes.h FlowBox.h FlowParticles.h Switch.h Trace.h289 Flow.o: Flow.cpp Flow.h FlowCmd.h FlowTypes.h FlowBox.h FlowParticles.h LIC.h VelocityArrowsSlice.h Switch.h Unirect.h Volume.h TransferFunction.h Trace.h 290 290 FlowBox.o: FlowBox.cpp FlowBox.h FlowTypes.h Switch.h Trace.h Volume.h $(VRMATH_DIR)/include/vrmath/Vector3f.h $(VRMATH_DIR)/include/vrmath/Vector4f.h $(VRMATH_DIR)/include/vrmath/Matrix4x4d.h 291 291 FlowCmd.o: FlowCmd.cpp FlowCmd.h FlowParticles.h FlowBox.h FlowTypes.h Command.h PPMWriter.h Switch.h Trace.h TransferFunction.h nanovis.h CmdProc.h LIC.h Unirect.h Volume.h VelocityArrowsSlice.h $(VRMATH_DIR)/include/vrmath/Vector3f.h … … 313 313 RenderVertexArray.o: RenderVertexArray.cpp RenderVertexArray.h 314 314 Shader.o: Shader.cpp Shader.h 315 ShaderGL.o: ShaderGL.cpp ShaderGL.h 315 316 StdVertexShader.o: StdVertexShader.cpp StdVertexShader.h Shader.h 316 317 Switch.o: Switch.cpp Switch.h … … 321 322 TransferFunction.o: TransferFunction.cpp 322 323 Unirect.o: Unirect.cpp Unirect.h Command.h Trace.h 323 VelocityArrowsSlice.o: VelocityArrowsSlice.cpp VelocityArrowsSlice.h 324 VelocityArrowsSlice.o: VelocityArrowsSlice.cpp VelocityArrowsSlice.h nanovis.h Camera.h Volume.h Shader.h 324 325 Volume.o: Volume.cpp Volume.h config.h define.h 325 326 VolumeInterpolator.o: VolumeInterpolator.cpp VolumeInterpolator.h Volume.h -
trunk/packages/vizservers/nanovis/OrientationIndicator.cpp
r3605 r3630 10 10 #include <GL/glu.h> 11 11 12 #include <vrmath/Vector3f.h> 13 12 14 #include "OrientationIndicator.h" 13 15 16 using namespace vrmath; 14 17 using namespace nv; 15 18 … … 18 21 _visible(true), 19 22 _lineWidth(1.f), 20 _quadric(gluNewQuadric()) 23 _quadric(gluNewQuadric()), 24 _position(0,0,0), 25 _scale(1,1,1) 21 26 { 22 27 } … … 37 42 return; 38 43 44 glMatrixMode(GL_MODELVIEW); 45 glPushMatrix(); 46 glTranslatef(_position.x, _position.y, _position.z); 47 float scale = _scale.x; 48 if (scale == 0 || _scale.y < scale) scale = _scale.y; 49 if (scale == 0 || _scale.z < scale) scale = _scale.z; 50 glScalef(scale, scale, scale); 51 39 52 glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT); 40 53 … … 48 61 glLineWidth(_lineWidth); 49 62 glDisable(GL_LIGHTING); 50 glColor3f(1, 0, 0); 51 glBegin(GL_LINES); 52 glVertex3f(0, 0, 0); 53 glVertex3f(0.5f, 0, 0); 54 glEnd(); 55 glColor3f(0, 1, 0); 56 glBegin(GL_LINES); 57 glVertex3f(0, 0, 0); 58 glVertex3f(0, 0.5f, 0); 59 glEnd(); 60 glColor3f(0, 0, 1); 61 glBegin(GL_LINES); 62 glVertex3f(0, 0, 0); 63 glVertex3f(0, 0, 0.5f); 64 glEnd(); 63 if (_scale.x > 0) { 64 glColor3f(1, 0, 0); 65 glBegin(GL_LINES); 66 glVertex3f(0, 0, 0); 67 glVertex3f(0.5f, 0, 0); 68 glEnd(); 69 } 70 if (_scale.y > 0) { 71 glColor3f(0, 1, 0); 72 glBegin(GL_LINES); 73 glVertex3f(0, 0, 0); 74 glVertex3f(0, 0.5f, 0); 75 glEnd(); 76 } 77 if (_scale.z > 0) { 78 glColor3f(0, 0, 1); 79 glBegin(GL_LINES); 80 glVertex3f(0, 0, 0); 81 glVertex3f(0, 0, 0.5f); 82 glEnd(); 83 } 65 84 } 66 85 break; … … 72 91 glEnable(GL_LIGHTING); 73 92 glEnable(GL_LIGHT0); 93 glEnable(GL_NORMALIZE); 74 94 75 95 // X 76 glColor3f(1, 0, 0); 77 glPushMatrix(); 78 glRotatef(90, 0, 1, 0); 79 gluCylinder(qobj, 0.01, 0.01, 0.3, segments, 1); 80 glPopMatrix(); 96 if (_scale.x > 0) { 97 glColor3f(1, 0, 0); 98 glPushMatrix(); 99 glRotatef(90, 0, 1, 0); 100 gluCylinder(qobj, 0.01, 0.01, 0.3, segments, 1); 101 glPopMatrix(); 81 102 82 glPushMatrix(); 83 glTranslatef(0.3, 0., 0.); 84 glRotatef(90, 0, 1, 0); 85 gluCylinder(qobj, 0.02, 0.0, 0.06, segments, 1); 86 glPopMatrix(); 103 glPushMatrix(); 104 glTranslatef(0.3, 0., 0.); 105 glRotatef(90, 0, 1, 0); 106 gluCylinder(qobj, 0.02, 0.0, 0.06, segments, 1); 107 glPopMatrix(); 108 } 87 109 88 110 // Y 89 glColor3f(0, 1, 0); 90 glPushMatrix(); 91 glRotatef(-90, 1, 0, 0); 92 gluCylinder(qobj, 0.01, 0.01, 0.3, segments, 1); 93 glPopMatrix(); 111 if (_scale.y > 0) { 112 glColor3f(0, 1, 0); 113 glPushMatrix(); 114 glRotatef(-90, 1, 0, 0); 115 gluCylinder(qobj, 0.01, 0.01, 0.3, segments, 1); 116 glPopMatrix(); 94 117 95 glPushMatrix(); 96 glTranslatef(0., 0.3, 0.); 97 glRotatef(-90, 1, 0, 0); 98 gluCylinder(qobj, 0.02, 0.0, 0.06, segments, 1); 99 glPopMatrix(); 118 glPushMatrix(); 119 glTranslatef(0., 0.3, 0.); 120 glRotatef(-90, 1, 0, 0); 121 gluCylinder(qobj, 0.02, 0.0, 0.06, segments, 1); 122 glPopMatrix(); 123 } 100 124 101 125 // Z 102 glColor3f(0, 0, 1); 103 glPushMatrix(); 104 gluCylinder(qobj, 0.01, 0.01, 0.3, segments, 1); 105 glPopMatrix(); 126 if (_scale.z > 0) { 127 glColor3f(0, 0, 1); 128 glPushMatrix(); 129 gluCylinder(qobj, 0.01, 0.01, 0.3, segments, 1); 130 glPopMatrix(); 106 131 107 glPushMatrix(); 108 glTranslatef(0., 0., 0.3); 109 gluCylinder(qobj, 0.02, 0.0, 0.06, segments, 1); 110 glPopMatrix(); 132 glPushMatrix(); 133 glTranslatef(0., 0., 0.3); 134 gluCylinder(qobj, 0.02, 0.0, 0.06, segments, 1); 135 glPopMatrix(); 136 } 111 137 } 112 138 break; … … 116 142 117 143 glPopAttrib(); 144 glPopMatrix(); 118 145 } -
trunk/packages/vizservers/nanovis/OrientationIndicator.h
r3613 r3630 7 7 #ifndef NV_ORIENTATION_INDICATOR_H 8 8 #define NV_ORIENTATION_INDICATOR_H 9 10 #include <vrmath/Vector3f.h> 9 11 10 12 namespace nv { … … 35 37 } 36 38 39 void setPosition(const vrmath::Vector3f& pos) 40 { 41 _position = pos; 42 } 43 44 void setScale(const vrmath::Vector3f& scale) 45 { 46 _scale = scale; 47 } 48 37 49 private: 38 50 Representation _rep; … … 40 52 float _lineWidth; 41 53 void *_quadric; 54 55 vrmath::Vector3f _position; 56 vrmath::Vector3f _scale; 42 57 }; 43 58 -
trunk/packages/vizservers/nanovis/ParticleAdvectionShader.cpp
r3612 r3630 12 12 _scale(1.0f, 1.0f, 1.0f), 13 13 _max(1.0f), 14 _timeStep(0.0005f), 15 _mode(1) 14 _timeStep(0.0005f) 16 15 { 17 16 init(); … … 24 23 void ParticleAdvectionShader::init() 25 24 { 26 loadFragmentProgram("update_pos.cg" , "main");25 loadFragmentProgram("update_pos.cg"); 27 26 } 28 27 29 28 void 30 ParticleAdvectionShader::bind(unsigned int texID, unsigned int initPosTexID )29 ParticleAdvectionShader::bind(unsigned int texID, unsigned int initPosTexID, bool init) 31 30 { 32 31 setFPTextureParameter("pos_tex", texID); … … 35 34 36 35 setFPParameter1f("timestep", _timeStep); 37 setFPParameter1f("max", _max); 38 setFPParameter1f("mode", _mode); 36 setFPParameter1f("max", init ? 0 : _max); 39 37 setFPParameter3f("scale", _scale.x, _scale.y, _scale.z); 40 38 -
trunk/packages/vizservers/nanovis/ParticleAdvectionShader.h
r3613 r3630 20 20 virtual ~ParticleAdvectionShader(); 21 21 22 virtual void bind(unsigned int texID, unsigned int initPosTexID );22 virtual void bind(unsigned int texID, unsigned int initPosTexID, bool init); 23 23 24 24 virtual void unbind(); -
trunk/packages/vizservers/nanovis/ParticleRenderer.cpp
r3627 r3630 13 13 #include <GL/glew.h> 14 14 15 #include <vrmath/Vector3f.h> 15 16 #include <vrmath/Color4f.h> 16 17 17 18 #include "ParticleRenderer.h" 19 #include "Volume.h" 18 20 #include "define.h" 19 21 #include "Trace.h" 20 22 23 using namespace vrmath; 21 24 using namespace nv; 22 23 ParticleAdvectionShader *ParticleRenderer::_advectionShader = NULL;24 ParticleAdvectionShaderInstance shaderInstance;25 25 26 26 ParticleRenderer::ParticleRenderer(int w, int h) : … … 37 37 _activate(false), 38 38 _slicePos(0.0), 39 _sliceAxis( 0),39 _sliceAxis(AXIS_Z), 40 40 _color(0.2, 0.2, 1.0, 1.0), 41 41 _psysWidth(w), … … 43 43 { 44 44 _data = new Particle[w * h]; 45 memset(_data, 0, sizeof(Particle) * w * h);46 45 47 46 _vertexArray = new RenderVertexArray(_psysWidth * _psysHeight, 3, GL_FLOAT); … … 104 103 #endif 105 104 106 if (_advectionShader == NULL) { 107 _advectionShader = new ParticleAdvectionShader(); 108 } 105 _advectionShader = new ParticleAdvectionShader(); 109 106 } 110 107 … … 121 118 glDeleteFramebuffersEXT(2, _psysFbo); 122 119 120 delete _advectionShader; 123 121 delete _vertexArray; 124 122 delete [] _data; … … 128 126 ParticleRenderer::initializeDataArray() 129 127 { 130 size_t n = _psysWidth * _psysHeight * 4; 131 memset(_data, 0, sizeof(float)* n); 132 133 int index; 134 bool particle; 135 float *p = (float *)_data; 128 TRACE("Enter axis: %d pos: %g", _sliceAxis, _slicePos); 129 130 memset(_data, 0, sizeof(Particle) * _psysWidth * _psysHeight); 131 132 bool hasParticle; 136 133 for (int i = 0; i < _psysWidth; i++) { 137 134 for (int j = 0; j < _psysHeight; j++) { 138 index = i + _psysHeight*j;139 particle = (rand() % 256) > 150;140 if (particle) {135 Particle *p = &_data[i + _psysHeight*j]; 136 hasParticle = (rand() % 256) > 150; 137 if (hasParticle) { 141 138 //assign any location (x,y,z) in range [0,1] 142 139 switch (_sliceAxis) { 143 case 0:144 p [4*index]= _slicePos;145 p [4*index+1]= j/float(_psysHeight);146 p [4*index+2]= i/float(_psysWidth);140 case AXIS_X: 141 p->x = _slicePos; 142 p->y = j/float(_psysHeight); 143 p->z = i/float(_psysWidth); 147 144 break; 148 case 1:149 p [4*index]= j/float(_psysHeight);150 p [4*index+1]= _slicePos;151 p [4*index+2]= i/float(_psysWidth);145 case AXIS_Y: 146 p->x = j/float(_psysHeight); 147 p->y = _slicePos; 148 p->z = i/float(_psysWidth); 152 149 break; 153 case 2:154 p [4*index]= j/float(_psysHeight);155 p [4*index+1]= i/float(_psysWidth);156 p [4*index+2]= _slicePos;150 case AXIS_Z: 151 p->x = j/float(_psysHeight); 152 p->y = i/float(_psysWidth); 153 p->z = _slicePos; 157 154 break; 158 155 default: 159 p[4*index] = 0; 160 p[4*index+1] = 0; 161 p[4*index+2] = 0; 162 p[4*index+3] = 0; 156 ERROR("Unknown axis"); 163 157 } 164 165 158 //shorter life span, quicker iterations 166 p[4*index+3] = rand() / ((float) RAND_MAX) * 0.5 + 0.5f; 167 } else { 168 p[4*index] = 0; 169 p[4*index+1] = 0; 170 p[4*index+2] = 0; 171 p[4*index+3] = 0; 159 p->life = rand() / ((float) RAND_MAX) * 0.5 + 0.5f; 172 160 } 173 161 } … … 178 166 ParticleRenderer::initialize() 179 167 { 168 TRACE("Enter"); 169 180 170 initializeDataArray(); 181 171 … … 192 182 _flip = true; 193 183 _reborn = false; 184 _psysFrame = 0; 194 185 195 186 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, _initPosTex); … … 226 217 ParticleRenderer::advect() 227 218 { 219 TRACE("Enter"); 220 228 221 if (_reborn) 229 222 reset(); … … 256 249 glPushMatrix(); 257 250 glLoadIdentity(); 258 //gluOrtho2D(0, _psysWidth, 0, _psysHeight);259 251 glOrtho(0, _psysWidth, 0, _psysHeight, -10.0f, 10.0f); 260 252 glMatrixMode(GL_MODELVIEW); … … 262 254 glLoadIdentity(); 263 255 264 _advectionShader->bind(_psysTex[tex], _initPosTex );256 _advectionShader->bind(_psysTex[tex], _initPosTex, _psysFrame == 0); 265 257 266 258 draw_quad(_psysWidth, _psysHeight, _psysWidth, _psysHeight); … … 282 274 _psysFrame++; 283 275 if (_psysFrame == _maxLife) { 284 _psysFrame = 0;285 // 276 //_psysFrame = 0; 277 //_reborn = true; 286 278 } 287 279 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboOrig); … … 294 286 { 295 287 _vertexArray->read(_psysWidth, _psysHeight); 296 297 //_vertexArray->loadData(vert); //does not work??298 //assert(glGetError()==0);299 288 } 300 289 … … 302 291 ParticleRenderer::render() 303 292 { 293 if (_psysFrame == 0) { 294 TRACE("Initializing vertex array"); 295 advect(); 296 } 297 304 298 glPushAttrib(GL_ENABLE_BIT); 305 299 glDisable(GL_TEXTURE_2D); … … 328 322 329 323 void 330 ParticleRenderer::setVectorField(unsigned int texID, const vrmath::Vector3f& origin, 331 float scaleX, float scaleY, float scaleZ, 332 float max) 333 { 334 _origin = origin; 335 _scale.set(scaleX, scaleY, scaleZ); 324 ParticleRenderer::setVectorField(Volume *volume) 325 { 326 Vector3f bmin, bmax; 327 volume->getBounds(bmin, bmax); 328 _origin = bmin; 329 Vector3f scale(bmax.x-bmin.x, bmax.y-bmin.y, bmax.z-bmin.z); 330 _scale.set(scale.x, scale.y, scale.z); 336 331 _advectionShader->setScale(_scale); 337 _advectionShader->setVelocityVolume(texID, max); 338 } 339 340 void 341 ParticleRenderer::setAxis(int axis) 342 { 343 _sliceAxis = axis; 344 initializeDataArray(); 332 _advectionShader->setVelocityVolume(volume->textureID(), 333 volume->wAxis.max()); 334 } 335 336 void 337 ParticleRenderer::setAxis(FlowSliceAxis axis) 338 { 339 if (axis != _sliceAxis) { 340 _sliceAxis = axis; 341 initialize(); 342 } 345 343 } 346 344 … … 348 346 ParticleRenderer::setPos(float pos) 349 347 { 350 _slicePos = pos; 351 initializeDataArray(); 352 } 348 if (pos != _slicePos) { 349 _slicePos = pos; 350 initialize(); 351 } 352 } -
trunk/packages/vizservers/nanovis/ParticleRenderer.h
r3627 r3630 14 14 #include <vrmath/Color4f.h> 15 15 16 #include "FlowTypes.h" 17 #include "Volume.h" 16 18 #include "ParticleAdvectionShader.h" 17 19 #include "RenderVertexArray.h" … … 23 25 float y; 24 26 float z; 25 float aux;27 float life; 26 28 27 29 Particle() … … 29 31 30 32 Particle(float _x, float _y, float _z, float _life) : 31 x(_x), y(_y), z(_z), aux(_life) 33 x(_x), 34 y(_y), 35 z(_z), 36 life(_life) 32 37 {} 33 38 }; … … 40 45 ~ParticleRenderer(); 41 46 42 void setVectorField(unsigned int texID, const vrmath::Vector3f& origin, 43 float scaleX, float scaleY, float scaleZ, float max); 47 void setVectorField(Volume *volume); 44 48 45 49 void initialize(); 46 50 47 51 void advect(); 48 49 void updateVertexBuffer();50 52 51 53 void reset(); … … 68 70 } 69 71 70 void setAxis(int axis); 72 void setAxis(FlowSliceAxis axis); 73 74 FlowSliceAxis getAxis() const 75 { 76 return _sliceAxis; 77 } 71 78 72 79 void setPos(float pos); 73 80 74 void initializeDataArray(); 81 float getPos() const 82 { 83 return _slicePos; 84 } 75 85 76 86 void particleSize(float size) … … 84 94 } 85 95 86 static ParticleAdvectionShader *_advectionShader; 96 private: 97 void initializeDataArray(); 87 98 88 private: 99 void updateVertexBuffer(); 100 101 ParticleAdvectionShader *_advectionShader; 102 89 103 /// frame buffer objects: two are defined, flip them as input output every step 90 104 GLuint _psysFbo[2]; … … 96 110 97 111 /// Count the frame number of particle system iteration 98 int _psysFrame;112 unsigned int _psysFrame; 99 113 100 114 /// Reinitiate particles … … 120 134 121 135 float _slicePos; 122 int_sliceAxis;136 FlowSliceAxis _sliceAxis; 123 137 124 138 vrmath::Color4f _color; … … 129 143 }; 130 144 131 class ParticleAdvectionShaderInstance132 {133 public :134 ParticleAdvectionShaderInstance()135 {}136 137 ~ParticleAdvectionShaderInstance()138 {139 if (ParticleRenderer::_advectionShader) {140 delete ParticleRenderer::_advectionShader;141 }142 }143 };144 145 145 } 146 146 -
trunk/packages/vizservers/nanovis/PointShader.cpp
r3612 r3630 13 13 _normal(NULL) 14 14 { 15 loadVertexProgram("pointsvp.cg" , "main");15 loadVertexProgram("pointsvp.cg"); 16 16 } 17 17 … … 22 22 void PointShader::bind() 23 23 { 24 setGLStateMatrixVPParameter("model view", MODELVIEW_MATRIX, MATRIX_IDENTITY);25 setGLStateMatrixVPParameter(" projection",PROJECTION_MATRIX, MATRIX_IDENTITY);24 setGLStateMatrixVPParameter("modelView", MODELVIEW_MATRIX, MATRIX_IDENTITY); 25 setGLStateMatrixVPParameter("modelViewProj", MODELVIEW_PROJECTION_MATRIX, MATRIX_IDENTITY); 26 26 27 27 setVPParameter1f("atten", 1.0f); -
trunk/packages/vizservers/nanovis/RegularVolumeShader.cpp
r3612 r3630 19 19 void RegularVolumeShader::init() 20 20 { 21 loadFragmentProgram("one_volume.cg" , "main");21 loadFragmentProgram("one_volume.cg"); 22 22 } 23 23 24 24 void RegularVolumeShader::bind(unsigned int tfID, Volume *volume, 25 25 int sliceMode, float sampleRatio) 26 26 { 27 27 //regular cubic volume 28 setGLStateMatrixFPParameter("modelViewInv", MODELVIEW_MATRIX,29 MATRIX_INVERSE);30 setGLStateMatrixFPParameter("modelView", MODELVIEW_MATRIX,31 MATRIX_IDENTITY);32 33 28 setFPTextureParameter("volume", volume->textureID()); 34 29 setFPTextureParameter("tf", tfID); -
trunk/packages/vizservers/nanovis/RenderVertexArray.h
r3613 r3630 23 23 void loadData(void *data); // load vertex data from memory 24 24 25 void read( /*GLenum buffer,*/ int w, int h); // read vertex data from26 // frame buffer 25 void read(int w, int h); // read vertex data from frame buffer 26 27 27 void setPointer(GLuint index); 28 28 -
trunk/packages/vizservers/nanovis/Shader.cpp
r3612 r3630 22 22 CGcontext Shader::_cgContext = NULL; 23 23 24 void Shader::initCg(CGprofile defaultVertexProfile, 25 CGprofile defaultFragmentProfile) 24 void Shader::init() 26 25 { 27 _defaultVertexProfile = defaultVertexProfile;28 _defaultFragmentProfile = defaultFragmentProfile;29 26 _cgContext = cgCreateContext(); 30 27 } 31 28 32 void Shader::exit Cg()29 void Shader::exit() 33 30 { 34 31 setErrorCallback(NULL); … … 94 91 } 95 92 96 void Shader::loadVertexProgram(const char *fileName , const char *entryPoint)93 void Shader::loadVertexProgram(const char *fileName) 97 94 { 98 95 if (_cgVP != NULL) { … … 100 97 } 101 98 _cgVP = loadCgSourceProgram(_cgContext, fileName, 102 _vertexProfile, entryPoint);99 _vertexProfile, "main"); 103 100 _vpFile = fileName; 104 101 } 105 102 106 void Shader::loadFragmentProgram(const char *fileName , const char *entryPoint)103 void Shader::loadFragmentProgram(const char *fileName) 107 104 { 108 105 if (_cgFP != NULL) { … … 110 107 } 111 108 _cgFP = loadCgSourceProgram(_cgContext, fileName, 112 _fragmentProfile, entryPoint);109 _fragmentProfile, "main"); 113 110 _fpFile = fileName; 114 111 } … … 127 124 } 128 125 129 void Shader::setErrorCallback( CgCallbackFunction callback)126 void Shader::setErrorCallback(ShaderCallbackFunction callback) 130 127 { 131 128 TRACE("Shader setting error callback to: %p", callback); -
trunk/packages/vizservers/nanovis/Shader.h
r3612 r3630 31 31 }; 32 32 33 typedef void CgCallbackFunction(void);33 typedef void (*ShaderCallbackFunction)(void); 34 34 35 35 Shader(); … … 38 38 39 39 /** 40 * @brief create a Cg vertex program and load it 41 * @param fileName the name of Cg program file 42 * @param entryPoint a entry point of the Cg program 40 * \brief Load and compile a vertex shader 41 * \param fileName the name of the shader source file 43 42 */ 44 void loadVertexProgram(const char *fileName , const char *entryPoint);43 void loadVertexProgram(const char *fileName); 45 44 46 45 /** 47 * @brief create a Cg fragment program and load it 48 * @param fileName the name of Cg program file 49 * @param entryPoint a entry point of the Cg program 46 * \brief Load and compile a fragment shader 47 * \param fileName the name of the shader source file 50 48 */ 51 void loadFragmentProgram(const char *fileName, const char *entryPoint); 52 53 CGparameter getNamedParameterFromFP(const char *paramName) 54 { 55 if (_cgFP) { 56 return cgGetNamedParameter(_cgFP, paramName); 57 } 58 ERROR("Unknown fragment program parameter: %s", paramName); 59 return 0; 60 } 61 62 CGparameter getNamedParameterFromVP(const char *paramName) 63 { 64 if (_cgVP) { 65 return cgGetNamedParameter(_cgVP, paramName); 66 } 67 ERROR("Unknown vertex program parameter: %s", paramName); 68 return 0; 69 } 49 void loadFragmentProgram(const char *fileName); 70 50 71 51 void setVPParameter1f(const char *name, float val) 72 52 { 73 CGparameter param = getVPParam(name);53 Parameter param = getVPParam(name); 74 54 if (param == NULL) 75 55 return; … … 79 59 void setFPParameter1f(const char *name, float val) 80 60 { 81 CGparameter param = getFPParam(name);61 Parameter param = getFPParam(name); 82 62 if (param == NULL) 83 63 return; … … 87 67 void setVPParameter2f(const char *name, float val1, float val2) 88 68 { 89 CGparameter param = getVPParam(name);69 Parameter param = getVPParam(name); 90 70 if (param == NULL) 91 71 return; … … 95 75 void setFPParameter2f(const char *name, float val1, float val2) 96 76 { 97 CGparameter param = getFPParam(name);77 Parameter param = getFPParam(name); 98 78 if (param == NULL) 99 79 return; … … 103 83 void setVPParameter3f(const char *name, float val1, float val2, float val3) 104 84 { 105 CGparameter param = getVPParam(name);85 Parameter param = getVPParam(name); 106 86 if (param == NULL) 107 87 return; … … 111 91 void setFPParameter3f(const char *name, float val1, float val2, float val3) 112 92 { 113 CGparameter param = getFPParam(name);93 Parameter param = getFPParam(name); 114 94 if (param == NULL) 115 95 return; … … 119 99 void setVPParameter4f(const char *name, float val1, float val2, float val3, float val4) 120 100 { 121 CGparameter param = getVPParam(name);101 Parameter param = getVPParam(name); 122 102 if (param == NULL) 123 103 return; … … 127 107 void setFPParameter4f(const char *name, float val1, float val2, float val3, float val4) 128 108 { 129 CGparameter param = getFPParam(name);109 Parameter param = getFPParam(name); 130 110 if (param == NULL) 131 111 return; … … 135 115 void setVPMatrixParameterf(const char *name, float *mat) 136 116 { 137 CGparameter param = getVPParam(name);117 Parameter param = getVPParam(name); 138 118 if (param == NULL) 139 119 return; … … 143 123 void setFPMatrixParameterf(const char *name, float *mat) 144 124 { 145 CGparameter param = getFPParam(name);125 Parameter param = getFPParam(name); 146 126 if (param == NULL) 147 127 return; … … 151 131 void setVPTextureParameter(const char *name, GLuint texobj, bool enable = true) 152 132 { 153 CGparameter param = getVPParam(name);133 Parameter param = getVPParam(name); 154 134 if (param == NULL) 155 135 return; … … 161 141 void setFPTextureParameter(const char *name, GLuint texobj, bool enable = true) 162 142 { 163 CGparameter param = getFPParam(name);143 Parameter param = getFPParam(name); 164 144 if (param == NULL) 165 145 return; … … 171 151 void enableVPTextureParameter(const char *name) 172 152 { 173 CGparameter param = getVPParam(name);153 Parameter param = getVPParam(name); 174 154 if (param == NULL) 175 155 return; … … 179 159 void enaableFPTextureParameter(const char *name) 180 160 { 181 CGparameter param = getFPParam(name);161 Parameter param = getFPParam(name); 182 162 if (param == NULL) 183 163 return; … … 187 167 void disableVPTextureParameter(const char *name) 188 168 { 189 CGparameter param = getVPParam(name);169 Parameter param = getVPParam(name); 190 170 if (param == NULL) 191 171 return; … … 195 175 void disableFPTextureParameter(const char *name) 196 176 { 197 CGparameter param = getFPParam(name);177 Parameter param = getFPParam(name); 198 178 if (param == NULL) 199 179 return; … … 204 184 GLMatrixType type = MATRIX_IDENTITY) 205 185 { 206 CGparameter param = getVPParam(name);186 Parameter param = getVPParam(name); 207 187 if (param == NULL) 208 188 return; … … 213 193 GLMatrixType type = MATRIX_IDENTITY) 214 194 { 215 CGparameter param = getFPParam(name);195 Parameter param = getFPParam(name); 216 196 if (param == NULL) 217 197 return; … … 239 219 } 240 220 241 void enableVertexProfile() 242 { 243 cgGLEnableProfile(_vertexProfile); 244 } 245 246 void disableVertexProfile() 247 { 248 cgGLDisableProfile(_vertexProfile); 249 } 250 251 void enableFragmentProfile() 252 { 253 cgGLEnableProfile(_fragmentProfile); 254 } 255 256 void disableFragmentProfile() 257 { 258 cgGLDisableProfile(_fragmentProfile); 259 } 260 261 static void initCg(CGprofile defaultVertexProfile = CG_PROFILE_VP40, 262 CGprofile defaultFragmentProfile = CG_PROFILE_FP40); 263 264 static void exitCg(); 221 static void init(); 222 223 static void exit(); 265 224 266 225 static bool printErrorInfo(); 267 226 268 static void setErrorCallback(CgCallbackFunction callback); 269 270 static CGcontext getCgContext() 271 { 272 return _cgContext; 273 } 274 275 protected: 276 typedef std::tr1::unordered_map<std::string, CGparameter> ParameterHashmap; 277 278 CGprogram getVP() 279 { 280 return _cgVP; 281 } 282 283 CGprogram getFP() 284 { 285 return _cgFP; 286 } 287 288 CGparameter getVPParam(const char *name) 289 { 290 CGparameter param; 227 static void setErrorCallback(ShaderCallbackFunction callback); 228 229 private: 230 typedef CGparameter Parameter; 231 typedef std::tr1::unordered_map<std::string, Parameter> ParameterHashmap; 232 233 Parameter getNamedParameterFromFP(const char *paramName) 234 { 235 if (_cgFP) { 236 return cgGetNamedParameter(_cgFP, paramName); 237 } 238 ERROR("Unknown fragment program parameter: %s", paramName); 239 return 0; 240 } 241 242 Parameter getNamedParameterFromVP(const char *paramName) 243 { 244 if (_cgVP) { 245 return cgGetNamedParameter(_cgVP, paramName); 246 } 247 ERROR("Unknown vertex program parameter: %s", paramName); 248 return 0; 249 } 250 251 Parameter getVPParam(const char *name) 252 { 253 Parameter param; 291 254 ParameterHashmap::iterator itr = _vpParams.find(name); 292 255 if (itr == _vpParams.end()) { … … 302 265 } 303 266 304 CGparameter getFPParam(const char *name)305 { 306 CGparameter param;267 Parameter getFPParam(const char *name) 268 { 269 Parameter param; 307 270 ParameterHashmap::iterator itr = _fpParams.find(name); 308 271 if (itr == _fpParams.end()) { … … 318 281 } 319 282 283 320 284 void resetPrograms(); 285 286 287 CGprogram getVP() 288 { 289 return _cgVP; 290 } 291 292 CGprogram getFP() 293 { 294 return _cgFP; 295 } 296 297 void enableVertexProfile() 298 { 299 cgGLEnableProfile(_vertexProfile); 300 } 301 302 void disableVertexProfile() 303 { 304 cgGLDisableProfile(_vertexProfile); 305 } 306 307 void enableFragmentProfile() 308 { 309 cgGLEnableProfile(_fragmentProfile); 310 } 311 312 void disableFragmentProfile() 313 { 314 cgGLDisableProfile(_fragmentProfile); 315 } 316 317 static CGcontext getCgContext() 318 { 319 return _cgContext; 320 } 321 322 std::string _vpFile; 323 std::string _fpFile; 324 325 ParameterHashmap _vpParams; 326 ParameterHashmap _fpParams; 321 327 322 328 CGprofile _vertexProfile; 323 329 CGprofile _fragmentProfile; 324 std::string _vpFile; 330 325 331 CGprogram _cgVP; 326 std::string _fpFile;327 332 CGprogram _cgFP; 328 ParameterHashmap _vpParams;329 ParameterHashmap _fpParams;330 333 331 334 static CGprofile _defaultVertexProfile; … … 333 336 static CGcontext _cgContext; 334 337 335 private:336 338 static CGprogram 337 339 loadCgSourceProgram(CGcontext context, const char *filename, -
trunk/packages/vizservers/nanovis/StdVertexShader.cpp
r3612 r3630 4 4 * 5 5 */ 6 #include <vrmath/Vector4f.h> 7 6 8 #include "StdVertexShader.h" 7 9 10 using namespace vrmath; 8 11 using namespace nv; 9 12 … … 19 22 void StdVertexShader::init() 20 23 { 21 loadVertexProgram("vertex_std.cg" , "main");24 loadVertexProgram("vertex_std.cg"); 22 25 } 23 26 24 void StdVertexShader::bind(float *mvp, float *mvInv) 27 void StdVertexShader::bind(const Vector4f& objPlaneS, 28 const Vector4f& objPlaneT, 29 const Vector4f& objPlaneR, 30 float *mvp, float *mvInv) 25 31 { 26 32 if (mvp != NULL) { 27 33 setVPMatrixParameterf("modelViewProjMatrix", mvp); 28 34 } else { 29 setGLStateMatrixVPParameter("modelViewProjMatrix", MODELVIEW_PROJECTION_MATRIX); 35 setGLStateMatrixVPParameter("modelViewProjMatrix", 36 MODELVIEW_PROJECTION_MATRIX); 30 37 } 31 38 if (mvInv != NULL) { 32 39 setVPMatrixParameterf("modelViewInv", mvInv); 33 40 } else { 34 setGLStateMatrixVPParameter("modelViewInv", MODELVIEW_MATRIX, MATRIX_INVERSE); 41 setGLStateMatrixVPParameter("modelViewInv", 42 MODELVIEW_MATRIX, MATRIX_INVERSE); 35 43 } 44 45 setVPParameter4f("light0Position", 1, 1, 1, 1); 46 setVPParameter4f("objPlaneS", 47 objPlaneS.x, objPlaneS.y, objPlaneS.z, objPlaneS.w); 48 setVPParameter4f("objPlaneT", 49 objPlaneT.x, objPlaneT.y, objPlaneT.z, objPlaneT.w); 50 setVPParameter4f("objPlaneR", 51 objPlaneR.x, objPlaneR.y, objPlaneR.z, objPlaneR.w); 36 52 37 53 Shader::bind(); -
trunk/packages/vizservers/nanovis/StdVertexShader.h
r3612 r3630 6 6 #ifndef NV_STD_VERTEX_SHADER_H 7 7 #define NV_STD_VERTEX_SHADER_H 8 9 #include <vrmath/Vector4f.h> 8 10 9 11 #include "Shader.h" … … 18 20 virtual ~StdVertexShader(); 19 21 20 virtual void bind(float *mvp = NULL, float *mvInv = NULL); 22 virtual void bind(const vrmath::Vector4f& objPlaneS, 23 const vrmath::Vector4f& objPlaneT, 24 const vrmath::Vector4f& objPlaneR, 25 float *mvp = NULL, float *mvInv = NULL); 21 26 22 27 virtual void unbind() -
trunk/packages/vizservers/nanovis/Unirect.h
r3613 r3630 13 13 14 14 #include <rappture.h> 15 16 #include <vrmath/Vector3f.h> 15 17 16 18 #include "Trace.h" … … 197 199 } 198 200 201 void getBounds(vrmath::Vector3f& bboxMin, 202 vrmath::Vector3f& bboxMax) const 203 { 204 bboxMin.set(_xMin, _yMin, _zMin); 205 bboxMax.set(_xMax, _yMax, _zMax); 206 } 207 199 208 const float *SaveValues() 200 209 { … … 352 361 } 353 362 363 void getBounds(vrmath::Vector3f& bboxMin, 364 vrmath::Vector3f& bboxMax) const 365 { 366 bboxMin.set(_xMin, _yMin, 0); 367 bboxMax.set(_xMax, _yMax, 0); 368 } 369 354 370 float *transferValues() 355 371 { -
trunk/packages/vizservers/nanovis/VelocityArrowsSlice.cpp
r3612 r3630 19 19 #include "nanovis.h" 20 20 #include "VelocityArrowsSlice.h" 21 #include "Volume.h" 21 22 #include "Shader.h" 22 23 #include "Camera.h" … … 38 39 VelocityArrowsSlice::VelocityArrowsSlice() : 39 40 _vectorFieldGraphicsID(0), 40 _vfXscale(0),41 _vfYscale(0),42 _vfZscale(0),43 41 _slicePos(0.5f), 44 _axis( 2),42 _axis(AXIS_Z), 45 43 _fbo(0), 46 44 _tex(0), … … 57 55 _maxVelocityScale(1, 1, 1), 58 56 _arrowColor(1, 1, 0), 59 _ enabled(false),57 _visible(false), 60 58 _dirty(true), 61 59 _vertexBufferGraphicsID(0), … … 63 61 _renderMode(LINES) 64 62 { 65 axis(2);66 67 _queryVelocityFP.loadFragmentProgram("queryvelocity.cg" , "main");68 69 _particleShader.loadVertexProgram("velocityslicevp.cg" , "vpmain");70 _particleShader.loadFragmentProgram("velocityslicefp.cg" , "fpmain");63 setSliceAxis(AXIS_Z); 64 65 _queryVelocityFP.loadFragmentProgram("queryvelocity.cg"); 66 67 _particleShader.loadVertexProgram("velocityslicevp.cg"); 68 _particleShader.loadFragmentProgram("velocityslicefp.cg"); 71 69 72 70 createRenderTarget(); … … 175 173 } 176 174 177 void VelocityArrowsSlice:: axis(intaxis)175 void VelocityArrowsSlice::setSliceAxis(FlowSliceAxis axis) 178 176 { 179 177 _axis = axis; 180 178 switch (_axis) { 181 case 0:179 case AXIS_X: 182 180 _projectionVector.x = 0; 183 181 _projectionVector.y = 1; 184 182 _projectionVector.z = 1; 185 183 break; 186 case 1:184 case AXIS_Y: 187 185 _projectionVector.x = 1; 188 186 _projectionVector.y = 0; 189 187 _projectionVector.z = 1; 190 188 break; 191 case 2:189 case AXIS_Z: 192 190 _projectionVector.x = 1; 193 191 _projectionVector.y = 1; … … 200 198 void VelocityArrowsSlice::queryVelocity() 201 199 { 202 if (!_enabled) return;203 204 200 glPushAttrib(GL_VIEWPORT_BIT | GL_ENABLE_BIT); 205 201 int fboOrig; … … 301 297 void VelocityArrowsSlice::render() 302 298 { 303 if (!_ enabled)299 if (!_visible) 304 300 return; 305 301 … … 310 306 } 311 307 312 TRACE("_ vf: %g %g %g", _vfXscale,_vfYscale, _vfZscale);308 TRACE("_scale: %g %g %g", _scale.x, _scale.y, _scale.z); 313 309 TRACE("_maxVelocityScale: %g %g %g", 314 310 _maxVelocityScale.x, _maxVelocityScale.y, _maxVelocityScale.z); … … 319 315 glPushMatrix(); 320 316 321 gl Scalef(_vfXscale,_vfYscale, _vfZscale);322 gl Translatef(-0.5f, -0.5f, -0.5f);317 glTranslatef(_origin.x, _origin.y, _origin.z); 318 glScalef(_scale.x, _scale.y, _scale.z); 323 319 324 320 if (_renderMode == LINES) { … … 422 418 _particleShader.setFPTextureParameter("arrows", _arrowsTex->id()); 423 419 _particleShader.setVPParameter1f("tanHalfFOV", 424 tan(NanoVis::getCamera()-> fov() * 0.5) * NanoVis::winHeight * 0.5);420 tan(NanoVis::getCamera()->getFov() * 0.5) * NanoVis::winHeight * 0.5); 425 421 _particleShader.setGLStateMatrixVPParameter("modelview", 426 422 Shader::MODELVIEW_MATRIX, … … 457 453 458 454 void 459 VelocityArrowsSlice::setVectorField( unsigned int vfGraphicsID, const Vector3f& origin,460 float xScale, float yScale, float zScale, float max) 461 { 462 _vectorFieldGraphicsID = vfGraphicsID;463 _vfXscale = xScale;464 _ vfYscale = yScale;465 _ vfZscale = zScale;455 VelocityArrowsSlice::setVectorField(Volume *volume) 456 { 457 _vectorFieldGraphicsID = volume->textureID(); 458 Vector3f bmin, bmax; 459 volume->getBounds(bmin, bmax); 460 _origin = bmin; 461 _scale.set(bmax.x-bmin.x, bmax.y-bmin.y, bmax.z-bmin.z); 466 462 467 463 _dirty = true; … … 470 466 void VelocityArrowsSlice::computeSamplingTicks() 471 467 { 472 if (_ vfXscale < _vfYscale) {473 if (_ vfXscale < _vfZscale || _vfZscale== 0.0) {474 // vfXscale468 if (_scale.x < _scale.y) { 469 if (_scale.x < _scale.z || _scale.z == 0.0) { 470 // _scale.x 475 471 _tickCountX = _tickCountForMinSizeAxis; 476 472 477 float step = _vfXscale / (_tickCountX + 1); 478 479 _tickCountY = (int)(_vfYscale/step); 480 _tickCountZ = (int)(_vfZscale/step); 473 float step = _scale.x / (_tickCountX + 1); 474 _tickCountY = (int)(_scale.y/step); 475 _tickCountZ = (int)(_scale.z/step); 481 476 } else { 482 // vfZscale477 // _scale.z 483 478 _tickCountZ = _tickCountForMinSizeAxis; 484 479 485 float step = _ vfZscale/ (_tickCountZ + 1);486 _tickCountX = (int)(_ vfXscale/step);487 _tickCountY = (int)(_ vfYscale/step);480 float step = _scale.z / (_tickCountZ + 1); 481 _tickCountX = (int)(_scale.x/step); 482 _tickCountY = (int)(_scale.y/step); 488 483 } 489 484 } else { 490 if (_ vfYscale < _vfZscale || _vfZscale== 0.0) {491 // _ vfYscale485 if (_scale.y < _scale.z || _scale.z == 0.0) { 486 // _scale.y 492 487 _tickCountY = _tickCountForMinSizeAxis; 493 488 494 float step = _ vfYscale/ (_tickCountY + 1);495 _tickCountX = (int)(_ vfXscale/step);496 _tickCountZ = (int)(_ vfZscale/step);489 float step = _scale.y / (_tickCountY + 1); 490 _tickCountX = (int)(_scale.x/step); 491 _tickCountZ = (int)(_scale.z/step); 497 492 } else { 498 // vfZscale493 // _scale.z 499 494 _tickCountZ = _tickCountForMinSizeAxis; 500 495 501 float step = _ vfZscale/ (_tickCountZ + 1);502 _tickCountX = (int)(_ vfXscale/step);503 _tickCountY = (int)(_ vfYscale/step);496 float step = _scale.z / (_tickCountZ + 1); 497 _tickCountX = (int)(_scale.x/step); 498 _tickCountY = (int)(_scale.y/step); 504 499 } 505 500 } -
trunk/packages/vizservers/nanovis/VelocityArrowsSlice.h
r3613 r3630 11 11 #include <vrmath/Vector3f.h> 12 12 13 #include "FlowTypes.h" 14 #include "Volume.h" 13 15 #include "Texture2D.h" 14 16 #include "Shader.h" … … 28 30 ~VelocityArrowsSlice(); 29 31 30 void setVectorField(unsigned int vfGraphicsID, const vrmath::Vector3f& origin, 31 float xScale, float yScale, float zScale, float max); 32 void setVectorField(Volume *volume); 32 33 33 void axis(intaxis);34 void setSliceAxis(FlowSliceAxis axis); 34 35 35 int axis() const36 int getSliceAxis() const 36 37 { 37 38 return _axis; 38 39 } 39 40 40 void s licePos(float pos)41 void setSlicePosition(float pos) 41 42 { 42 43 _slicePos = pos; … … 44 45 } 45 46 46 float slicePos() const47 float getSlicePosition() const 47 48 { 48 49 return _slicePos; 49 50 } 50 51 51 void queryVelocity();52 53 52 void render(); 54 53 55 void enabled(bool enabled)54 void visible(bool visible) 56 55 { 57 _ enabled = enabled;56 _visible = visible; 58 57 } 59 58 60 bool enabled() const59 bool visible() const 61 60 { 62 return _ enabled;61 return _visible; 63 62 } 64 63 … … 90 89 91 90 private: 91 void queryVelocity(); 92 92 93 void createRenderTarget(); 93 94 … … 95 96 96 97 unsigned int _vectorFieldGraphicsID; 97 float _vfXscale;98 float _vfYscale;99 float _vfZscale; 98 vrmath::Vector3f _origin; 99 vrmath::Vector3f _scale; 100 100 101 float _slicePos; 101 int_axis;102 FlowSliceAxis _axis; 102 103 103 104 unsigned int _fbo; … … 124 125 vrmath::Vector3f _arrowColor; 125 126 126 bool _ enabled;127 bool _visible; 127 128 bool _dirty; 128 129 bool _dirtySamplingPosition; -
trunk/packages/vizservers/nanovis/Volume.cpp
r3611 r3630 31 31 double Volume::valueMax = 1.0; 32 32 33 Volume::Volume(float x, float y, float z, 34 int w, int h, int d, 33 Volume::Volume(int w, int h, int d, 35 34 int n, float *data, 36 35 double v0, double v1, double nonZeroMin) : … … 50 49 _nonZeroMin(nonZeroMin), 51 50 _tex(NULL), 52 _location(x, y, z), 51 _position(0,0,0), 52 _scale(1,1,1), 53 53 _numSlices(512), 54 54 _enabled(true), … … 65 65 int fcount = _width * _height * _depth * _numComponents; 66 66 _data = new float[fcount]; 67 if (data != NULL) { 68 TRACE("data is copied"); 69 memcpy(_data, data, fcount * sizeof(float)); 70 _tex->initialize(_data); 71 } else { 72 TRACE("data is null"); 73 memset(_data, 0, sizeof(_width * _height * _depth * _numComponents * 74 sizeof(float))); 75 _tex->initialize(_data); 76 } 67 memcpy(_data, data, fcount * sizeof(float)); 68 _tex->initialize(_data); 77 69 78 70 _id = _tex->id(); … … 83 75 //The default location of cut plane is in the middle of the data. 84 76 _plane.clear(); 85 addCutplane( 1, 0.5f);86 addCutplane( 2, 0.5f);87 addCutplane( 3, 0.5f);77 addCutplane(CutPlane::X_AXIS, 0.5f); 78 addCutplane(CutPlane::Y_AXIS, 0.5f); 79 addCutplane(CutPlane::Z_AXIS, 0.5f); 88 80 89 81 TRACE("Leave"); … … 98 90 } 99 91 100 void Volume:: getWorldSpaceBounds(Vector3f& bboxMin, Vector3f& bboxMax) const92 void Volume::setData(float *data, double v0, double v1, double nonZeroMin) 101 93 { 102 Vector3f scale = getPhysicalScaling(); 94 int fcount = _width * _height * _depth * _numComponents; 95 memcpy(_data, data, fcount * sizeof(float)); 96 _tex->update(_data); 97 wAxis.setRange(v0, v1); 98 _nonZeroMin = nonZeroMin; 99 updatePending = true; 100 } 103 101 104 Matrix4x4d mat; 105 mat.makeTranslation(_location); 106 Matrix4x4d mat2; 107 mat2.makeScale(scale); 108 109 mat.multiply(mat2); 110 111 bboxMin.set(FLT_MAX, FLT_MAX, FLT_MAX); 112 bboxMax.set(-FLT_MAX, -FLT_MAX, -FLT_MAX); 113 114 Vector3f modelMin(0, 0, 0); 115 Vector3f modelMax(1, 1, 1); 116 117 Vector4f bvert[8]; 118 bvert[0] = Vector4f(modelMin.x, modelMin.y, modelMin.z, 1); 119 bvert[1] = Vector4f(modelMax.x, modelMin.y, modelMin.z, 1); 120 bvert[2] = Vector4f(modelMin.x, modelMax.y, modelMin.z, 1); 121 bvert[3] = Vector4f(modelMin.x, modelMin.y, modelMax.z, 1); 122 bvert[4] = Vector4f(modelMax.x, modelMax.y, modelMin.z, 1); 123 bvert[5] = Vector4f(modelMax.x, modelMin.y, modelMax.z, 1); 124 bvert[6] = Vector4f(modelMin.x, modelMax.y, modelMax.z, 1); 125 bvert[7] = Vector4f(modelMax.x, modelMax.y, modelMax.z, 1); 126 127 for (int i = 0; i < 8; i++) { 128 Vector4f worldVert = mat.transform(bvert[i]); 129 if (worldVert.x < bboxMin.x) bboxMin.x = worldVert.x; 130 if (worldVert.x > bboxMax.x) bboxMax.x = worldVert.x; 131 if (worldVert.y < bboxMin.y) bboxMin.y = worldVert.y; 132 if (worldVert.y > bboxMax.y) bboxMax.y = worldVert.y; 133 if (worldVert.z < bboxMin.z) bboxMin.z = worldVert.z; 134 if (worldVert.z > bboxMax.z) bboxMax.z = worldVert.z; 135 } 102 void Volume::getBounds(Vector3f& bboxMin, Vector3f& bboxMax) const 103 { 104 bboxMin.set(xAxis.min(), yAxis.min(), zAxis.min()); 105 bboxMax.set(xAxis.max(), yAxis.max(), zAxis.max()); 136 106 } -
trunk/packages/vizservers/nanovis/Volume.h
r3613 r3630 21 21 namespace nv { 22 22 23 struct CutPlane { 24 /// orientation - 1: xy slice, 2: yz slice, 3: xz slice 25 int orient; 26 float offset; ///< normalized offset [0,1] in the volume 27 bool enabled; 28 29 CutPlane(int _orient, float _offset) : 23 class CutPlane { 24 public: 25 enum Axis { 26 X_AXIS = 1, 27 Y_AXIS = 2, 28 Z_AXIS = 3 29 }; 30 31 CutPlane(Axis _orient, float _offset) : 30 32 orient(_orient), 31 33 offset(_offset), … … 33 35 { 34 36 } 37 38 Axis orient; 39 float offset; ///< normalized offset [0,1] in the volume 40 bool enabled; 35 41 }; 36 42 … … 52 58 * each axis. Sample spacing may differ between X, Y and Z 53 59 * 54 * \param x X location55 * \param y Y location56 * \param z Z location57 60 * \param width Number of samples in X 58 61 * \param height Number of samples in Y … … 64 67 * \param nonZeroMin Scalar minimum which is greater than zero 65 68 */ 66 Volume(float x, float y, float z, 67 int width, int height, int depth, 69 Volume(int width, int height, int depth, 68 70 int numComponents, 69 71 float *data, … … 98 100 } 99 101 100 void location(const vrmath::Vector3f& loc)101 {102 _location = loc;103 }104 105 vrmath::Vector3f location() const106 {107 return _location;108 }109 110 102 int isosurface() const 111 103 { … … 132 124 return _volumeType; 133 125 } 126 127 void setData(float *data, double v0, double v1, double nonZeroMin); 134 128 135 129 const float *data() const … … 155 149 // methods related to cutplanes 156 150 /// add a plane and returns its index 157 int addCutplane( intorientation, float location);151 int addCutplane(CutPlane::Axis orientation, float location); 158 152 159 153 void enableCutplane(int index); … … 161 155 void disableCutplane(int index); 162 156 163 void moveCutplane(int index, float location);157 void setCutplanePosition(int index, float location); 164 158 165 159 CutPlane *getCutplane(int index); … … 282 276 283 277 void getOutlineColor(float *rgb); 284 285 vrmath::Vector3f getPhysicalScaling() const 286 { 287 vrmath::Vector3f scale; 288 scale.x = 1; 289 scale.y = yAxis.length() / xAxis.length(); 290 scale.z = zAxis.length() / xAxis.length(); 291 return scale; 292 } 293 294 void getWorldSpaceBounds(vrmath::Vector3f& bboxMin, 295 vrmath::Vector3f& bboxMax) const; 278 279 void setPosition(const vrmath::Vector3f& pos) 280 { 281 _position = pos; 282 } 283 284 const vrmath::Vector3f& getPosition() const 285 { 286 return _position; 287 } 288 289 void setScale(const vrmath::Vector3f& scale) 290 { 291 _scale = scale; 292 } 293 294 const vrmath::Vector3f& getScale() const 295 { 296 return _scale; 297 } 298 299 void getBounds(vrmath::Vector3f& bboxMin, 300 vrmath::Vector3f& bboxMax) const; 296 301 297 302 double sampleDistanceX() const … … 370 375 /** 371 376 * The scale multiplied to the opacity assigned by the 372 * transfer function. Rule of thumb: higher opacity_scale 373 * the object is to appear like plastic 377 * transfer function. 374 378 */ 375 379 float _opacityScale; … … 387 391 Texture3D *_tex; ///< OpenGL texture storing the volume 388 392 389 vrmath::Vector3f _location; 393 vrmath::Vector3f _position; 394 vrmath::Vector3f _scale; 390 395 391 396 /** … … 403 408 404 409 inline int 405 Volume::addCutplane( intorientation, float location)410 Volume::addCutplane(CutPlane::Axis orientation, float location) 406 411 { 407 412 _plane.push_back(CutPlane(orientation, location)); … … 424 429 425 430 inline void 426 Volume:: moveCutplane(int index, float location)431 Volume::setCutplanePosition(int index, float position) 427 432 { 428 433 //assert(index < plane.size()); 429 _plane[index].offset = location;434 _plane[index].offset = position; 430 435 } 431 436 -
trunk/packages/vizservers/nanovis/VolumeInterpolator.cpp
r3611 r3630 32 32 void VolumeInterpolator::start() 33 33 { 34 if ( _volumes.size() > 0) {34 if (!_volumes.empty()) { 35 35 TRACE("Volume Interpolation Started"); 36 36 _started = true; … … 128 128 VolumeInterpolator::addVolume(Volume *volume) 129 129 { 130 if ( _volumes.size() != 0) {130 if (!_volumes.empty()) { 131 131 if (_volumes[0]->width() != volume->width() || 132 132 _volumes[0]->height() != volume->height() || … … 140 140 _numComponents = volume->numComponents(); 141 141 _numBytes = _dataCount * _numComponents * sizeof(float); 142 Vector3f loc = volume->location(); 143 _volume = new Volume(loc.x, loc.y, loc.z, 144 volume->width(), 142 _volume = new Volume(volume->width(), 145 143 volume->height(), 146 144 volume->depth(), … … 151 149 volume->nonZeroMin()); 152 150 153 _volume->numSlices(256-1); 151 _volume->setPosition(volume->getPosition()); 152 _volume->setScale(volume->getScale()); 154 153 _volume->disableCutplane(0); 155 154 _volume->disableCutplane(1); … … 163 162 _volume->opacityScale(volume->opacityScale()); 164 163 _volume->isosurface(0); 165 TRACE("VOL : location %f %f %f\n\tid : %s", loc.x, loc.y, loc.z,166 volume->name());167 164 } 168 _volumes.push_back( _volume);169 TRACE(" a Volume[%s]is added to VolumeInterpolator", volume->name());165 _volumes.push_back(volume); 166 TRACE("Volume \"%s\" is added to VolumeInterpolator", volume->name()); 170 167 } 171 168 … … 173 170 { 174 171 return _volume; 175 //return _volumes[0];176 172 } -
trunk/packages/vizservers/nanovis/VolumeInterpolator.h
r3613 r3630 40 40 private: 41 41 Volume *_volume; 42 43 std::vector<Volume*> _volumes; 42 std::vector<Volume *> _volumes; 44 43 45 44 double _interval; -
trunk/packages/vizservers/nanovis/VolumeRenderer.cpp
r3612 r3630 22 22 23 23 #include <vrmath/Vector3f.h> 24 #include <vrmath/Vector4f.h> 24 25 #include <vrmath/Matrix4x4d.h> 26 #include <vrmath/BBox.h> 25 27 26 28 #include "nanovis.h" … … 54 56 { 55 57 _cutplaneShader = new Shader(); 56 _cutplaneShader->loadVertexProgram("cutplane_vp.cg" , "main");57 _cutplaneShader->loadFragmentProgram("cutplane_fp.cg" , "main");58 _cutplaneShader->loadVertexProgram("cutplane_vp.cg"); 59 _cutplaneShader->loadFragmentProgram("cutplane_fp.cg"); 58 60 59 61 //standard vertex program … … 67 69 //A sim has S, P, D, SS orbitals. thus a full rendering requires 4 zincblende orbital volumes. 68 70 //A zincblende orbital volume is decomposed into 2 "interlocking" cubic 4-component volumes and passed to the shader. 69 //We render each orbital with aindependent transfer functions then blend the result.71 //We render each orbital with independent transfer functions then blend the result. 70 72 // 71 73 //The engine is already capable of rendering multiple volumes and combine them. Thus, we just invoke this shader on … … 130 132 size_t *actual_slices = new size_t[volumes.size()]; 131 133 float *z_steps = new float[volumes.size()]; 134 float *sampleRatios = new float[volumes.size()]; 135 Vector4f *objPlaneS = new Vector4f[volumes.size()]; 136 Vector4f *objPlaneT = new Vector4f[volumes.size()]; 137 Vector4f *objPlaneR = new Vector4f[volumes.size()]; 132 138 133 139 TRACE("start loop %d", volumes.size()); … … 143 149 } 144 150 145 //volume start location 146 Vector3f volPos = volume->location(); 147 Vector3f volScaling = volume->getPhysicalScaling(); 151 // Get any additional transforms on Volume 152 Vector3f volPos = volume->getPosition(); 153 Vector3f volScale = volume->getScale(); 154 // Get world coords of volume bbox 155 double x0 = volume->xAxis.min(); 156 double y0 = volume->yAxis.min(); 157 double z0 = volume->zAxis.min(); 158 double x1 = volume->xAxis.max(); 159 double y1 = volume->yAxis.max(); 160 double z1 = volume->zAxis.max(); 161 Vector3f worldMin(x0, y0, z0); 162 Vector3f worldMax(x1, y1, z1); 163 164 float edgeLengthX = volume->xAxis.length(); 165 float edgeLengthY = volume->yAxis.length(); 166 float edgeLengthZ = volume->zAxis.length(); 167 // Texgen planes 168 objPlaneS[i].set(1./edgeLengthX, 0, 0, -volume->xAxis.min()/edgeLengthX); 169 objPlaneT[i].set(0, 1./edgeLengthY, 0, -volume->yAxis.min()/edgeLengthY); 170 objPlaneR[i].set(0, 0, 1./edgeLengthZ, -volume->zAxis.min()/edgeLengthZ); 171 172 Matrix4x4d model_view_no_trans, model_view_trans; 173 Matrix4x4d model_view_no_trans_inverse, model_view_trans_inverse; 174 175 //initialize volume plane with world coordinates 176 nv::Plane volume_planes[6]; 177 volume_planes[0].setCoeffs( 1, 0, 0, -x0); 178 volume_planes[1].setCoeffs(-1, 0, 0, x1); 179 volume_planes[2].setCoeffs( 0, 1, 0, -y0); 180 volume_planes[3].setCoeffs( 0, -1, 0, y1); 181 volume_planes[4].setCoeffs( 0, 0, 1, -z0); 182 volume_planes[5].setCoeffs( 0, 0, -1, z1); 148 183 149 184 TRACE("VOL POS: %g %g %g", 150 185 volPos.x, volPos.y, volPos.z); 151 186 TRACE("VOL SCALE: %g %g %g", 152 volScaling.x, volScaling.y, volScaling.z); 153 154 double x0 = 0; 155 double y0 = 0; 156 double z0 = 0; 157 158 Matrix4x4d model_view_no_trans, model_view_trans; 159 Matrix4x4d model_view_no_trans_inverse, model_view_trans_inverse; 160 161 //initialize volume plane with world coordinates 162 nv::Plane volume_planes[6]; 163 volume_planes[0].setCoeffs( 1, 0, 0, -x0); 164 volume_planes[1].setCoeffs(-1, 0, 0, x0+1); 165 volume_planes[2].setCoeffs( 0, 1, 0, -y0); 166 volume_planes[3].setCoeffs( 0, -1, 0, y0+1); 167 volume_planes[4].setCoeffs( 0, 0, 1, -z0); 168 volume_planes[5].setCoeffs( 0, 0, -1, z0+1); 187 volScale.x, volScale.y, volScale.z); 169 188 170 189 //get modelview matrix with no translation 171 190 glPushMatrix(); 172 glScalef(volScal ing.x, volScaling.y, volScaling.z);191 glScalef(volScale.x, volScale.y, volScale.z); 173 192 174 193 glEnable(GL_DEPTH_TEST); … … 185 204 glPushMatrix(); 186 205 glTranslatef(volPos.x, volPos.y, volPos.z); 187 glScalef(volScal ing.x, volScaling.y, volScaling.z);206 glScalef(volScale.x, volScale.y, volScale.z); 188 207 189 208 GLdouble mv_trans[16]; … … 200 219 float olcolor[3]; 201 220 volume->getOutlineColor(olcolor); 202 drawBoundingBox(x0, y0, z0, x 0+1, y0+1, z0+1,203 (double)olcolor[0], (double)olcolor[1], (double)olcolor[2],204 1.5);221 drawBoundingBox(x0, y0, z0, x1, y1, z1, 222 olcolor[0], olcolor[1], olcolor[2], 223 1.5); 205 224 } 206 225 glPopMatrix(); … … 212 231 volume_planes[j].transform(model_view_no_trans); 213 232 } 214 double eyeMinX, eyeMaxX, eyeMinY, eyeMaxY, zNear, zFar; 215 getEyeSpaceBounds(model_view_no_trans, 216 eyeMinX, eyeMaxX, 217 eyeMinY, eyeMaxY, 218 zNear, zFar); 233 Vector3f eyeMin, eyeMax; 234 double zNear, zFar; 235 getEyeSpaceBounds(worldMin, worldMax, 236 model_view_no_trans, 237 eyeMin, eyeMax); 238 zNear = eyeMax.z; 239 zFar = eyeMin.z; 219 240 220 241 //compute actual rendering slices … … 236 257 237 258 TRACE("near: %g far: %g eye space bounds: (%g,%g)-(%g,%g) z_step: %g slices: %d", 238 zNear, zFar, eyeMinX, eyeMaxX, eyeMinY, eyeMaxY, z_step, n_actual_slices); 259 zNear, zFar, eyeMin.x, eyeMax.x, eyeMin.y, eyeMax.y, z_step, n_actual_slices); 260 261 // Compute opacity correction sample ratios 262 float defDist = z_step == 0.0f ? 1.0 : z_step; 263 float sampleDistX = (volume->width() > 1) ? edgeLengthX / (volume->width()-1) : defDist; 264 float sampleDistY = (volume->height() > 1) ? edgeLengthY / (volume->height()-1) : defDist; 265 float sampleDistZ = (volume->depth() > 1) ? edgeLengthZ / (volume->depth()-1) : defDist; 266 sampleDistX *= volScale.x; 267 sampleDistY *= volScale.y; 268 sampleDistZ *= volScale.z; 269 BBox voxelIn, voxelOut; 270 voxelIn.min.set(0,0,0); 271 voxelIn.max.set(sampleDistX, sampleDistY, sampleDistZ); 272 getEyeSpaceBounds(voxelIn.min, voxelIn.max, model_view_no_trans, voxelOut.min, voxelOut.max); 273 sampleRatios[i] = z_step / (voxelOut.max.z - voxelOut.min.z); 239 274 240 275 Vector4f vert1, vert2, vert3, vert4; … … 249 284 continue; 250 285 } 286 Vector4f texcoord1, texcoord2, texcoord3, texcoord4; 251 287 float offset = volume->getCutplane(j)->offset; 252 288 int axis = volume->getCutplane(j)->orient; 253 289 254 290 switch (axis) { 255 case 1: 256 vert1 = Vector4f(offset, 0, 0, 1); 257 vert2 = Vector4f(offset, 1, 0, 1); 258 vert3 = Vector4f(offset, 1, 1, 1); 259 vert4 = Vector4f(offset, 0, 1, 1); 291 case CutPlane::X_AXIS: // YZ plane 292 vert1 = Vector4f(x0 + offset * (x1 - x0), y0, z0, 1); 293 vert2 = Vector4f(x0 + offset * (x1 - x0), y1, z0, 1); 294 vert3 = Vector4f(x0 + offset * (x1 - x0), y1, z1, 1); 295 vert4 = Vector4f(x0 + offset * (x1 - x0), y0, z1, 1); 296 texcoord1 = Vector4f(offset, 0, 0, 1); 297 texcoord2 = Vector4f(offset, 1, 0, 1); 298 texcoord3 = Vector4f(offset, 1, 1, 1); 299 texcoord4 = Vector4f(offset, 0, 1, 1); 260 300 break; 261 case 2: 262 vert1 = Vector4f(0, offset, 0, 1); 263 vert2 = Vector4f(1, offset, 0, 1); 264 vert3 = Vector4f(1, offset, 1, 1); 265 vert4 = Vector4f(0, offset, 1, 1); 301 case CutPlane::Y_AXIS: // XZ plane 302 vert1 = Vector4f(x0, y0 + offset * (y1 - y0), z0, 1); 303 vert2 = Vector4f(x1, y0 + offset * (y1 - y0), z0, 1); 304 vert3 = Vector4f(x1, y0 + offset * (y1 - y0), z1, 1); 305 vert4 = Vector4f(x0, y0 + offset * (y1 - y0), z1, 1); 306 texcoord1 = Vector4f(0, offset, 0, 1); 307 texcoord2 = Vector4f(1, offset, 0, 1); 308 texcoord3 = Vector4f(1, offset, 1, 1); 309 texcoord4 = Vector4f(0, offset, 1, 1); 266 310 break; 267 case 3:311 case CutPlane::Z_AXIS: // XY plane 268 312 default: 269 vert1 = Vector4f(0, 0, offset, 1); 270 vert2 = Vector4f(1, 0, offset, 1); 271 vert3 = Vector4f(1, 1, offset, 1); 272 vert4 = Vector4f(0, 1, offset, 1); 313 vert1 = Vector4f(x0, y0, z0 + offset * (z1 - z0), 1); 314 vert2 = Vector4f(x1, y0, z0 + offset * (z1 - z0), 1); 315 vert3 = Vector4f(x1, y1, z0 + offset * (z1 - z0), 1); 316 vert4 = Vector4f(x0, y1, z0 + offset * (z1 - z0), 1); 317 texcoord1 = Vector4f(0, 0, offset, 1); 318 texcoord2 = Vector4f(1, 0, offset, 1); 319 texcoord3 = Vector4f(1, 1, offset, 1); 320 texcoord4 = Vector4f(0, 1, offset, 1); 273 321 break; 274 322 } 275 276 Vector4f texcoord1 = vert1;277 Vector4f texcoord2 = vert2;278 Vector4f texcoord3 = vert3;279 Vector4f texcoord4 = vert4;280 323 281 324 _cutplaneShader->bind(); … … 285 328 glPushMatrix(); 286 329 glTranslatef(volPos.x, volPos.y, volPos.z); 287 glScalef(volScal ing.x, volScaling.y, volScaling.z);330 glScalef(volScale.x, volScale.y, volScale.z); 288 331 _cutplaneShader->setGLStateMatrixVPParameter("modelViewProjMatrix", 289 332 Shader::MODELVIEW_PROJECTION_MATRIX); … … 314 357 // Initialize view-aligned quads with eye space bounds of 315 358 // volume 316 vert1 = Vector4f(eyeMin X, eyeMinY, -0.5, 1);317 vert2 = Vector4f(eyeMax X, eyeMinY, -0.5, 1);318 vert3 = Vector4f(eyeMax X, eyeMaxY, -0.5, 1);319 vert4 = Vector4f(eyeMin X, eyeMaxY, -0.5, 1);359 vert1 = Vector4f(eyeMin.x, eyeMin.y, zFar, 1); 360 vert2 = Vector4f(eyeMax.x, eyeMin.y, zFar, 1); 361 vert3 = Vector4f(eyeMax.x, eyeMax.y, zFar, 1); 362 vert4 = Vector4f(eyeMin.x, eyeMax.y, zFar, 1); 320 363 321 364 size_t counter = 0; … … 345 388 346 389 for (size_t k = 0; k < 6; k++) { 347 if (!poly->clip(volume_planes[k], true))390 if (!poly->clip(volume_planes[k], false)) 348 391 break; 349 392 } … … 384 427 385 428 for (size_t i = 0; i < total_rendered_slices; i++) { 386 Volume *volume = NULL; 387 388 int volume_index = slices[i].volumeId; 389 int slice_index = slices[i].sliceId; 390 ConvexPolygon *currentSlice = polys[volume_index][slice_index]; 391 float z_step = z_steps[volume_index]; 392 393 volume = volumes[volume_index]; 394 395 Vector3f volScaling = volume->getPhysicalScaling(); 429 int volIdx = slices[i].volumeId; 430 int sliceIdx = slices[i].sliceId; 431 ConvexPolygon *currentSlice = polys[volIdx][sliceIdx]; 432 433 Volume *volume = volumes[volIdx]; 434 Vector3f volPos = volume->getPosition(); 435 Vector3f volScale = volume->getScale(); 396 436 397 437 glPushMatrix(); 398 glScalef(volScaling.x, volScaling.y, volScaling.z); 399 400 // FIXME: compute view-dependent volume sample distance 401 double avgSampleDistance = 1.0 / pow(volume->width() * volScaling.x * 402 volume->height() * volScaling.y * 403 volume->depth() * volScaling.z, 1.0/3.0); 404 float sampleRatio = z_step / avgSampleDistance; 438 glTranslatef(volPos.x, volPos.y, volPos.z); 439 glScalef(volScale.x, volScale.y, volScale.z); 405 440 406 441 #ifdef notdef 407 TRACE("shading slice: volume %s addr=%x slice=%d, volume=%d z_step=%g avgSD=%g", 408 volume->name(), volume, slice_index, volume_index, z_step, avgSampleDistance); 442 float z_step = z_steps[volIdx]; 443 TRACE("shading slice: volume %s addr=%x slice=%d, volume=%d z_step=%g sampleRatio=%g", 444 volume->name(), volume, sliceIdx, volIdx, z_step, sampleRatios[volIdx]); 409 445 #endif 410 activateVolumeShader(volume, false, sampleRatio);446 activateVolumeShader(volume, objPlaneS[volIdx], objPlaneT[volIdx], objPlaneR[volIdx], false, sampleRatios[volIdx]); 411 447 glPopMatrix(); 412 448 413 449 glBegin(GL_POLYGON); 414 currentSlice->emit( true);450 currentSlice->emit(false); 415 451 glEnd(); 416 452 … … 432 468 delete[] actual_slices; 433 469 delete[] z_steps; 470 delete[] objPlaneS; 471 delete[] objPlaneT; 472 delete[] objPlaneR; 473 delete[] sampleRatios; 434 474 free(slices); 435 475 } … … 439 479 float x1, float y1, float z1, 440 480 float r, float g, float b, 441 float line _width)481 float lineWidth) 442 482 { 443 483 glPushAttrib(GL_ENABLE_BIT); … … 451 491 452 492 glColor4d(r, g, b, 1.0); 453 glLineWidth(line _width);493 glLineWidth(lineWidth); 454 494 455 495 glBegin(GL_LINE_LOOP); … … 494 534 495 535 void 496 VolumeRenderer::activateVolumeShader(Volume *volume, bool sliceMode, 536 VolumeRenderer::activateVolumeShader(Volume *volume, 537 Vector4f& objPlaneS, 538 Vector4f& objPlaneT, 539 Vector4f& objPlaneR, 540 bool sliceMode, 497 541 float sampleRatio) 498 542 { 499 543 //vertex shader 500 _stdVertexShader->bind( );544 _stdVertexShader->bind(objPlaneS, objPlaneT, objPlaneR); 501 545 TransferFunction *transferFunc = volume->transferFunction(); 502 546 if (volume->volumeType() == Volume::CUBIC) { … … 514 558 } 515 559 516 void VolumeRenderer::getEyeSpaceBounds(const Matrix4x4d& mv, 517 double& xMin, double& xMax, 518 double& yMin, double& yMax, 519 double& zNear, double& zFar) 520 { 521 double x0 = 0; 522 double y0 = 0; 523 double z0 = 0; 524 double x1 = 1; 525 double y1 = 1; 526 double z1 = 1; 527 528 double zMin, zMax; 529 xMin = DBL_MAX; 530 xMax = -DBL_MAX; 531 yMin = DBL_MAX; 532 yMax = -DBL_MAX; 533 zMin = DBL_MAX; 534 zMax = -DBL_MAX; 535 536 double vertex[8][4]; 537 538 vertex[0][0]=x0; vertex[0][1]=y0; vertex[0][2]=z0; vertex[0][3]=1.0; 539 vertex[1][0]=x1; vertex[1][1]=y0; vertex[1][2]=z0; vertex[1][3]=1.0; 540 vertex[2][0]=x0; vertex[2][1]=y1; vertex[2][2]=z0; vertex[2][3]=1.0; 541 vertex[3][0]=x0; vertex[3][1]=y0; vertex[3][2]=z1; vertex[3][3]=1.0; 542 vertex[4][0]=x1; vertex[4][1]=y1; vertex[4][2]=z0; vertex[4][3]=1.0; 543 vertex[5][0]=x1; vertex[5][1]=y0; vertex[5][2]=z1; vertex[5][3]=1.0; 544 vertex[6][0]=x0; vertex[6][1]=y1; vertex[6][2]=z1; vertex[6][3]=1.0; 545 vertex[7][0]=x1; vertex[7][1]=y1; vertex[7][2]=z1; vertex[7][3]=1.0; 546 547 for (int i = 0; i < 8; i++) { 548 Vector4f eyeVert = mv.transform(Vector4f(vertex[i][0], 549 vertex[i][1], 550 vertex[i][2], 551 vertex[i][3])); 552 if (eyeVert.x < xMin) xMin = eyeVert.x; 553 if (eyeVert.x > xMax) xMax = eyeVert.x; 554 if (eyeVert.y < yMin) yMin = eyeVert.y; 555 if (eyeVert.y > yMax) yMax = eyeVert.y; 556 if (eyeVert.z < zMin) zMin = eyeVert.z; 557 if (eyeVert.z > zMax) zMax = eyeVert.z; 558 } 559 560 zNear = zMax; 561 zFar = zMin; 562 } 560 void VolumeRenderer::getEyeSpaceBounds(const Vector3f& worldMin, 561 const Vector3f& worldMax, 562 const Matrix4x4d& modelViewMatrix, 563 Vector3f& eyeMin, Vector3f& eyeMax) 564 { 565 BBox bbox(worldMin, worldMax); 566 567 bbox.transform(bbox, modelViewMatrix); 568 569 eyeMin = bbox.min; 570 eyeMax = bbox.max; 571 } -
trunk/packages/vizservers/nanovis/VolumeRenderer.h
r3613 r3630 9 9 #define NV_VOLUME_RENDERER_H 10 10 11 #include <vrmath/Vector3f.h> 12 #include <vrmath/Vector4f.h> 11 13 #include <vrmath/Matrix4x4d.h> 12 14 … … 61 63 void initShaders(); 62 64 63 void activateVolumeShader(Volume *vol, bool sliceMode, float sampleRatio); 65 void activateVolumeShader(Volume *vol, 66 vrmath::Vector4f& objPlaneS, 67 vrmath::Vector4f& objPlaneT, 68 vrmath::Vector4f& objPlaneR, 69 bool sliceMode, float sampleRatio); 64 70 65 71 void deactivateVolumeShader(); 66 72 67 void drawBoundingBox(float x0, float y0, float z0,68 float x1, float y1, float z1,69 float r, float g, float b, float line_width);73 static void drawBoundingBox(float x0, float y0, float z0, 74 float x1, float y1, float z1, 75 float r, float g, float b, float line_width); 70 76 71 void getEyeSpaceBounds(const vrmath::Matrix4x4d& mv, 72 double& xMin, double& xMax, 73 double& yMin, double& yMax, 74 double& zNear, double& zFar); 77 static void getEyeSpaceBounds(const vrmath::Vector3f& worldMin, 78 const vrmath::Vector3f& worldMax, 79 const vrmath::Matrix4x4d& mv, 80 vrmath::Vector3f& eyeMin, 81 vrmath::Vector3f& eyeMax); 75 82 76 83 VolumeInterpolator *_volumeInterpolator; -
trunk/packages/vizservers/nanovis/VtkReader.cpp
r3611 r3630 488 488 delete [] data; 489 489 490 //491 // Center this new volume on the origin.492 //493 float dx0 = -0.5;494 float dy0 = -0.5*ly/lx;495 float dz0 = -0.5*lz/lx;496 if (volume) {497 volume->location(vrmath::Vector3f(dx0, dy0, dz0));498 TRACE("Set volume location to %g %g %g", dx0, dy0, dz0);499 }500 490 return volume; 501 491 } -
trunk/packages/vizservers/nanovis/ZincBlendeReconstructor.cpp
r3611 r3630 264 264 cellSize.z = 0.25 / depth; 265 265 266 zincBlendeVolume = new ZincBlendeVolume(origin.x, origin.y, origin.z, 267 width, height, depth, 4, 266 zincBlendeVolume = new ZincBlendeVolume(width, height, depth, 4, 268 267 fourAnionVolume, fourCationVolume, 269 268 vmin, vmax, nzero_min, cellSize); 269 270 zincBlendeVolume->xAxis.setRange(origin.x, origin.x + delta.x * (width-1)); 271 zincBlendeVolume->yAxis.setRange(origin.y, origin.y + delta.y * (height-1)); 272 zincBlendeVolume->zAxis.setRange(origin.z, origin.z + delta.z * (depth-1)); 270 273 271 274 return zincBlendeVolume; … … 342 345 cellSize.z = 0.25 / depth; 343 346 344 zincBlendeVolume = new ZincBlendeVolume(origin.x, origin.y, origin.z, 345 width, height, depth, 4, 347 zincBlendeVolume = new ZincBlendeVolume(width, height, depth, 4, 346 348 fourAnionVolume, fourCationVolume, 347 349 vmin, vmax, nzero_min, cellSize); 350 351 zincBlendeVolume->xAxis.setRange(origin.x, origin.x + delta.x * (width-1)); 352 zincBlendeVolume->yAxis.setRange(origin.y, origin.y + delta.y * (height-1)); 353 zincBlendeVolume->zAxis.setRange(origin.z, origin.z + delta.z * (depth-1)); 348 354 349 355 return zincBlendeVolume; -
trunk/packages/vizservers/nanovis/ZincBlendeVolume.cpp
r3611 r3630 24 24 using namespace vrmath; 25 25 26 ZincBlendeVolume::ZincBlendeVolume(float x, float y, float z, 27 int w, int h, int d, int n, 26 ZincBlendeVolume::ZincBlendeVolume(int w, int h, int d, int n, 28 27 float *dataVolumeA, float *dataVolumeB, 29 28 double v0, double v1, double non_zeromin, 30 29 const Vector3f& cellSz) : 31 Volume( x, y, z,w, h, d, n, dataVolumeA, v0, v1, non_zeromin),30 Volume(w, h, d, n, dataVolumeA, v0, v1, non_zeromin), 32 31 cellSize(cellSz) 33 32 { … … 49 48 ZincBlendeVolume::~ZincBlendeVolume() 50 49 { 51 // This data will be deleted in a destrutor of Volume class 52 //if (zincblende_tex[0]) 53 // delete zincblende_tex[0]; 50 // First texture will be deleted in ~Volume() 54 51 if (zincblendeTex[1]) 55 52 delete zincblendeTex[1]; -
trunk/packages/vizservers/nanovis/ZincBlendeVolume.h
r3613 r3630 21 21 { 22 22 public: 23 ZincBlendeVolume(float x, float y, float z, 24 int width, int height, int depth, int numComponents, 23 ZincBlendeVolume(int width, int height, int depth, int numComponents, 25 24 float *dataVolumeA, float *dataVolumeB, 26 double vmin, double vmax, double non_zeromin, const vrmath::Vector3f& cellSize); 25 double vmin, double vmax, double non_zeromin, 26 const vrmath::Vector3f& cellSize); 27 27 28 28 virtual ~ZincBlendeVolume(); -
trunk/packages/vizservers/nanovis/ZincBlendeVolumeShader.cpp
r3612 r3630 21 21 void ZincBlendeVolumeShader::init() 22 22 { 23 loadFragmentProgram("zincblende_volume.cg" , "main");23 loadFragmentProgram("zincblende_volume.cg"); 24 24 } 25 25 -
trunk/packages/vizservers/nanovis/dxReader.cpp
r3611 r3630 488 488 delete [] data; 489 489 490 //491 // Center this new volume on the origin.492 //493 float dx0 = -0.5;494 float dy0 = -0.5*ly/lx;495 float dz0 = -0.5*lz/lx;496 if (volume) {497 volume->location(vrmath::Vector3f(dx0, dy0, dz0));498 TRACE("Set volume location to %g %g %g", dx0, dy0, dz0);499 }500 490 return volume; 501 491 } -
trunk/packages/vizservers/nanovis/graphics/Makefile.in
r3470 r3630 59 59 60 60 clean: 61 $(RM) $(NVGRAPHICSLIB) $(OBJS)61 $(RM) *.a *.o 62 62 63 63 distclean: clean -
trunk/packages/vizservers/nanovis/imgLoaders/Makefile.in
r3470 r3630 59 59 60 60 clean: 61 $(RM) $(IMGLIB) $(OBJS)61 $(RM) *.a *.o 62 62 63 63 distclean: clean -
trunk/packages/vizservers/nanovis/nanovis.cpp
r3612 r3630 24 24 25 25 #include <graphics/RenderContext.h> 26 #include <vrmath/BBox.h> 26 27 #include <vrmath/Vector3f.h> 27 28 … … 64 65 Tcl_Interp *NanoVis::interp = NULL; 65 66 66 unsigned int NanoVis::flags = 0;67 bool NanoVis::redrawPending = false; 67 68 bool NanoVis::debugFlag = false; 68 69 … … 73 74 Texture2D *NanoVis::legendTexture = NULL; 74 75 Fonts *NanoVis::fonts; 75 int NanoVis::updir = Y_POS; 76 Camera *NanoVis::cam = NULL; 76 Camera *NanoVis::_camera = NULL; 77 77 RenderContext *NanoVis::renderContext = NULL; 78 78 … … 82 82 NanoVis::HeightMapHashmap NanoVis::heightMapTable; 83 83 84 double NanoVis::magMin = DBL_MAX; 85 double NanoVis::magMax = -DBL_MAX; 86 float NanoVis::xMin = FLT_MAX; 87 float NanoVis::xMax = -FLT_MAX; 88 float NanoVis::yMin = FLT_MAX; 89 float NanoVis::yMax = -FLT_MAX; 90 float NanoVis::zMin = FLT_MAX; 91 float NanoVis::zMax = -FLT_MAX; 92 float NanoVis::wMin = FLT_MAX; 93 float NanoVis::wMax = -FLT_MAX; 94 Vector3f NanoVis::sceneMin, NanoVis::sceneMax; 84 BBox NanoVis::sceneBounds; 95 85 96 86 VolumeRenderer *NanoVis::volRenderer = NULL; … … 101 91 Grid *NanoVis::grid = NULL; 102 92 103 // Image based flow visualization slice location104 // FLOW105 float NanoVis::_licSlice = 0.5f;106 int NanoVis::_licAxis = 2; // z axis107 108 93 //frame buffer for final rendering 109 94 GLuint NanoVis::_finalFbo = 0; … … 111 96 GLuint NanoVis::_finalDepthRb = 0; 112 97 113 // Default camera location.114 float def_eye_x = 0.0f;115 float def_eye_y = 0.0f;116 float def_eye_z = 2.5f;117 118 98 void 119 99 NanoVis::removeAllData() 120 100 { 121 101 TRACE("Enter"); 102 122 103 if (grid != NULL) { 123 104 TRACE("Deleting grid"); 124 105 delete grid; 125 106 } 126 if ( cam!= NULL) {127 TRACE("Deleting cam ");128 delete cam;107 if (_camera != NULL) { 108 TRACE("Deleting camera"); 109 delete _camera; 129 110 } 130 111 if (volRenderer != NULL) { … … 167 148 168 149 void 169 NanoVis::eventuallyRedraw(unsigned int flag) 170 { 171 if (flag) { 172 flags |= flag; 173 } 174 if ((flags & REDRAW_PENDING) == 0) { 150 NanoVis::eventuallyRedraw() 151 { 152 if (!redrawPending) { 175 153 glutPostRedisplay(); 176 flags |= REDRAW_PENDING; 177 } 178 } 179 180 void 181 NanoVis::pan(float dx, float dy) 182 { 183 /* Move the camera and its target by equal amounts along the x and y 184 * axes. */ 185 TRACE("pan: x=%f, y=%f", dx, dy); 186 187 cam->x(def_eye_x - dx); 188 cam->y(def_eye_y + dy); 189 TRACE("set eye to %f %f", cam->x(), cam->y()); 190 } 191 192 void 193 NanoVis::zoom(float z) 194 { 195 /* Move the camera and its target by equal amounts along the x and y 196 * axes. */ 197 TRACE("zoom: z=%f", z); 198 199 cam->z(def_eye_z / z); 154 redrawPending = true; 155 } 156 } 157 158 void 159 NanoVis::panCamera(float dx, float dy) 160 { 161 _camera->pan(dx, dy); 200 162 201 163 collectBounds(); 202 cam->resetClippingRange(sceneMin, sceneMax); 203 204 TRACE("set cam z to %f", cam->z()); 164 _camera->resetClippingRange(sceneBounds.min, sceneBounds.max); 165 } 166 167 void 168 NanoVis::zoomCamera(float z) 169 { 170 _camera->zoom(z); 171 172 collectBounds(); 173 _camera->resetClippingRange(sceneBounds.min, sceneBounds.max); 174 } 175 176 void 177 NanoVis::orientCamera(double *quat) 178 { 179 _camera->orient(quat); 180 181 collectBounds(); 182 _camera->resetClippingRange(sceneBounds.min, sceneBounds.max); 183 } 184 185 void 186 NanoVis::setCameraPosition(Vector3f pos) 187 { 188 _camera->setPosition(pos); 189 190 collectBounds(); 191 _camera->resetClippingRange(sceneBounds.min, sceneBounds.max); 192 } 193 194 void 195 NanoVis::setCameraUpdir(Camera::AxisDirection dir) 196 { 197 _camera->setUpdir(dir); 198 199 collectBounds(); 200 _camera->resetClippingRange(sceneBounds.min, sceneBounds.max); 205 201 } 206 202 … … 211 207 212 208 collectBounds(); 213 cam->reset(sceneMin, sceneMax, resetOrientation); 214 215 def_eye_x = cam->x(); 216 def_eye_y = cam->y(); 217 def_eye_z = cam->z(); 209 _camera->reset(sceneBounds.min, sceneBounds.max, resetOrientation); 218 210 } 219 211 … … 244 236 } 245 237 246 Volume *volume = new Volume(0.f, 0.f, 0.f, 247 width, height, depth, 238 Volume *volume = new Volume(width, height, depth, 248 239 numComponents, 249 240 data, vmin, vmax, nonZeroMin); … … 451 442 TRACE("change camera"); 452 443 //change the camera setting 453 cam->setScreenSize(0, 0, winWidth, winHeight);444 _camera->setViewport(0, 0, winWidth, winHeight); 454 445 planeRenderer->setScreenSize(winWidth, winHeight); 455 446 456 447 TRACE("Leave (%d, %d)", w, h); 457 448 return true; 458 }459 460 static461 void cgErrorCallback(void)462 {463 if (!Shader::printErrorInfo()) {464 TRACE("Cg error, exiting...");465 exit(1);466 }467 449 } 468 450 … … 536 518 ImageLoaderFactory::getInstance()->addLoaderImpl("bmp", new BMPImageLoaderImpl()); 537 519 538 Shader::initCg();539 Shader::setErrorCallback(cgErrorCallback);540 541 fonts = new Fonts();542 fonts->addFont("verdana", "verdana.fnt");543 fonts->setFont("verdana");544 545 velocityArrowsSlice = new VelocityArrowsSlice;546 licRenderer = new LIC(NMESH, NPIX, NPIX, _licAxis, _licSlice);547 548 grid = new Grid();549 grid->setFont(fonts);550 520 return true; 551 521 } … … 564 534 565 535 //create the camera with default setting 566 cam = new Camera(0, 0, winWidth, winHeight, 567 def_eye_x, def_eye_y, def_eye_z); 536 _camera = new Camera(0, 0, winWidth, winHeight); 568 537 569 538 glEnable(GL_TEXTURE_2D); … … 577 546 GLfloat mat_shininess[] = {30.0}; 578 547 GLfloat white_light[] = {1.0, 1.0, 1.0, 1.0}; 579 GLfloat green_light[] = {0.1, 0.5, 0.1, 1.0};580 548 581 549 glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); … … 583 551 glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light); 584 552 glLightfv(GL_LIGHT0, GL_SPECULAR, white_light); 585 glLightfv(GL_LIGHT1, GL_DIFFUSE, green_light);553 glLightfv(GL_LIGHT1, GL_DIFFUSE, white_light); 586 554 glLightfv(GL_LIGHT1, GL_SPECULAR, white_light); 587 555 … … 591 559 } 592 560 561 fonts = new Fonts(); 562 fonts->addFont("verdana", "verdana.fnt"); 563 fonts->setFont("verdana"); 564 565 renderContext = new RenderContext(); 566 593 567 volRenderer = new VolumeRenderer(); 594 568 595 renderContext = new RenderContext();596 597 569 planeRenderer = new PlaneRenderer(winWidth, winHeight); 598 570 571 velocityArrowsSlice = new VelocityArrowsSlice(); 572 573 licRenderer = new LIC(); 574 599 575 orientationIndicator = new OrientationIndicator(); 576 577 grid = new Grid(); 578 grid->setFont(fonts); 600 579 601 580 //assert(glGetError()==0); … … 635 614 NanoVis::setVolumeRanges() 636 615 { 637 double xMin, xMax, yMin, yMax, zMin, zMax, wMin, wMax;638 639 616 TRACE("Enter"); 640 xMin = yMin = zMin = wMin = DBL_MAX; 641 xMax = yMax = zMax = wMax = -DBL_MAX;617 618 double valueMin = DBL_MAX, valueMax = -DBL_MAX; 642 619 VolumeHashmap::iterator itr; 643 620 for (itr = volumeTable.begin(); 644 621 itr != volumeTable.end(); ++itr) { 645 622 Volume *volume = itr->second; 646 if (xMin > volume->xAxis.min()) { 647 xMin = volume->xAxis.min(); 648 } 649 if (xMax < volume->xAxis.max()) { 650 xMax = volume->xAxis.max(); 651 } 652 if (yMin > volume->yAxis.min()) { 653 yMin = volume->yAxis.min(); 654 } 655 if (yMax < volume->yAxis.max()) { 656 yMax = volume->yAxis.max(); 657 } 658 if (zMin > volume->zAxis.min()) { 659 zMin = volume->zAxis.min(); 660 } 661 if (zMax < volume->zAxis.max()) { 662 zMax = volume->zAxis.max(); 663 } 664 if (wMin > volume->wAxis.min()) { 665 wMin = volume->wAxis.min(); 666 } 667 if (wMax < volume->wAxis.max()) { 668 wMax = volume->wAxis.max(); 669 } 670 } 671 if ((xMin < DBL_MAX) && (xMax > -DBL_MAX)) { 672 grid->xAxis.setScale(xMin, xMax); 673 } 674 if ((yMin < DBL_MAX) && (yMax > -DBL_MAX)) { 675 grid->yAxis.setScale(yMin, yMax); 676 } 677 if ((zMin < DBL_MAX) && (zMax > -DBL_MAX)) { 678 grid->zAxis.setScale(zMin, zMax); 679 } 680 if ((wMin < DBL_MAX) && (wMax > -DBL_MAX)) { 681 Volume::valueMin = wMin; 682 Volume::valueMax = wMax; 623 if (valueMin > volume->wAxis.min()) { 624 valueMin = volume->wAxis.min(); 625 } 626 if (valueMax < volume->wAxis.max()) { 627 valueMax = volume->wAxis.max(); 628 } 629 } 630 if ((valueMin < DBL_MAX) && (valueMax > -DBL_MAX)) { 631 Volume::valueMin = valueMin; 632 Volume::valueMax = valueMax; 683 633 } 684 634 Volume::updatePending = false; … … 689 639 NanoVis::setHeightmapRanges() 690 640 { 691 double xMin, xMax, yMin, yMax, zMin, zMax, wMin, wMax;692 693 641 TRACE("Enter"); 694 xMin = yMin = zMin = wMin = DBL_MAX; 695 xMax = yMax = zMax = wMax = -DBL_MAX;642 643 double valueMin = DBL_MAX, valueMax = -DBL_MAX; 696 644 HeightMapHashmap::iterator itr; 697 645 for (itr = heightMapTable.begin(); 698 646 itr != heightMapTable.end(); ++itr) { 699 647 HeightMap *heightMap = itr->second; 700 if (xMin > heightMap->xAxis.min()) { 701 xMin = heightMap->xAxis.min(); 702 } 703 if (xMax < heightMap->xAxis.max()) { 704 xMax = heightMap->xAxis.max(); 705 } 706 if (yMin > heightMap->yAxis.min()) { 707 yMin = heightMap->yAxis.min(); 708 } 709 if (yMax < heightMap->yAxis.max()) { 710 yMax = heightMap->yAxis.max(); 711 } 712 if (zMin > heightMap->zAxis.min()) { 713 zMin = heightMap->zAxis.min(); 714 } 715 if (zMax < heightMap->zAxis.max()) { 716 zMax = heightMap->zAxis.max(); 717 } 718 if (wMin > heightMap->wAxis.min()) { 719 wMin = heightMap->wAxis.min(); 720 } 721 if (wMax < heightMap->wAxis.max()) { 722 wMax = heightMap->wAxis.max(); 723 } 724 } 725 if ((xMin < DBL_MAX) && (xMax > -DBL_MAX)) { 726 grid->xAxis.setScale(xMin, xMax); 727 } 728 if ((yMin < DBL_MAX) && (yMax > -DBL_MAX)) { 729 grid->yAxis.setScale(yMin, yMax); 730 } 731 if ((zMin < DBL_MAX) && (zMax > -DBL_MAX)) { 732 grid->zAxis.setScale(zMin, zMax); 733 } 734 if ((wMin < DBL_MAX) && (wMax > -DBL_MAX)) { 735 HeightMap::valueMin = grid->yAxis.min(); 736 HeightMap::valueMax = grid->yAxis.max(); 648 if (valueMin > heightMap->wAxis.min()) { 649 valueMin = heightMap->wAxis.min(); 650 } 651 if (valueMax < heightMap->wAxis.max()) { 652 valueMax = heightMap->wAxis.max(); 653 } 654 } 655 if ((valueMin < DBL_MAX) && (valueMax > -DBL_MAX)) { 656 HeightMap::valueMin = valueMin; 657 HeightMap::valueMax = valueMax; 737 658 } 738 659 for (HeightMapHashmap::iterator itr = heightMapTable.begin(); … … 747 668 NanoVis::collectBounds(bool onlyVisible) 748 669 { 749 if ( flags & MAP_FLOWS) {670 if (Flow::updatePending) { 750 671 mapFlows(); 751 grid->xAxis.setScale(xMin, xMax); 752 grid->yAxis.setScale(yMin, yMax); 753 grid->zAxis.setScale(zMin, zMax); 754 } 755 756 sceneMin.set(FLT_MAX, FLT_MAX, FLT_MAX); 757 sceneMax.set(-FLT_MAX, -FLT_MAX, -FLT_MAX); 672 } 673 674 sceneBounds.makeEmpty(); 758 675 759 676 for (VolumeHashmap::iterator itr = volumeTable.begin(); … … 764 681 continue; 765 682 766 Vector3f bmin, bmax; 767 volume->getWorldSpaceBounds(bmin, bmax); 768 if (bmin.x > bmax.x) 769 continue; 770 771 if (sceneMin.x > bmin.x) { 772 sceneMin.x = bmin.x; 773 } 774 if (sceneMax.x < bmax.x) { 775 sceneMax.x = bmax.x; 776 } 777 if (sceneMin.y > bmin.y) { 778 sceneMin.y = bmin.y; 779 } 780 if (sceneMax.y < bmax.y) { 781 sceneMax.y = bmax.y; 782 } 783 if (sceneMin.z > bmin.z) { 784 sceneMin.z = bmin.z; 785 } 786 if (sceneMax.z < bmax.z) { 787 sceneMax.z = bmax.z; 788 } 683 BBox bbox; 684 volume->getBounds(bbox.min, bbox.max); 685 sceneBounds.extend(bbox); 789 686 } 790 687 … … 796 693 continue; 797 694 798 Vector3f bmin, bmax; 799 heightMap->getWorldSpaceBounds(bmin, bmax); 800 if (bmin.x > bmax.x) 801 continue; 802 803 if (sceneMin.x > bmin.x) { 804 sceneMin.x = bmin.x; 805 } 806 if (sceneMax.x < bmax.x) { 807 sceneMax.x = bmax.x; 808 } 809 if (sceneMin.y > bmin.y) { 810 sceneMin.y = bmin.y; 811 } 812 if (sceneMax.y < bmax.y) { 813 sceneMax.y = bmax.y; 814 } 815 if (sceneMin.z > bmin.z) { 816 sceneMin.z = bmin.z; 817 } 818 if (sceneMax.z < bmax.z) { 819 sceneMax.z = bmax.z; 820 } 821 } 822 823 Vector3f flowMin, flowMax; 824 getFlowBounds(flowMin, flowMax, onlyVisible); 825 if (flowMin.x < flowMax.x) { 826 if (sceneMin.x > flowMin.x) { 827 sceneMin.x = flowMin.x; 828 } 829 if (sceneMax.x < flowMax.x) { 830 sceneMax.x = flowMax.x; 831 } 832 if (sceneMin.y > flowMin.y) { 833 sceneMin.y = flowMin.y; 834 } 835 if (sceneMax.y < flowMax.y) { 836 sceneMax.y = flowMax.y; 837 } 838 if (sceneMin.z > flowMin.z) { 839 sceneMin.z = flowMin.z; 840 } 841 if (sceneMax.z < flowMax.z) { 842 sceneMax.z = flowMax.z; 843 } 844 } 845 846 // TODO: Get Grid bounds 847 848 if (sceneMin.x > sceneMax.x) { 849 sceneMin.set(-0.5, -0.5, -0.5); 850 sceneMax.set( 0.5, 0.5, 0.5); 695 BBox bbox; 696 heightMap->getBounds(bbox.min, bbox.max); 697 sceneBounds.extend(bbox); 698 } 699 700 { 701 BBox bbox; 702 getFlowBounds(bbox.min, bbox.max, onlyVisible); 703 sceneBounds.extend(bbox); 704 } 705 706 if (!sceneBounds.isEmptyX()) { 707 grid->xAxis.setScale(sceneBounds.min.x, sceneBounds.max.x); 708 } 709 if (!sceneBounds.isEmptyY()) { 710 grid->yAxis.setScale(sceneBounds.min.y, sceneBounds.max.y); 711 } 712 if (!sceneBounds.isEmptyZ()) { 713 grid->zAxis.setScale(sceneBounds.min.z, sceneBounds.max.z); 714 } 715 716 if (!onlyVisible || grid->isVisible()) { 717 BBox bbox; 718 grid->getBounds(bbox.min, bbox.max); 719 sceneBounds.extend(bbox); 720 } 721 722 if (sceneBounds.isEmpty()) { 723 sceneBounds.min.set(-0.5, -0.5, -0.5); 724 sceneBounds.max.set( 0.5, 0.5, 0.5); 851 725 } 852 726 853 727 TRACE("Scene bounds: (%g,%g,%g) - (%g,%g,%g)", 854 scene Min.x, sceneMin.y, sceneMin.z,855 scene Max.x, sceneMax.y, sceneMax.z);728 sceneBounds.min.x, sceneBounds.min.y, sceneBounds.min.z, 729 sceneBounds.max.x, sceneBounds.max.y, sceneBounds.max.z); 856 730 } 857 731 … … 933 807 TRACE("Enter"); 934 808 935 flags &= ~MAP_FLOWS;936 937 809 /* 938 810 * Step 1. Get the overall min and max magnitudes of all the 939 811 * flow vectors. 940 812 */ 941 magMin = DBL_MAX, magMax = -DBL_MAX; 813 Flow::magMin = DBL_MAX; 814 Flow::magMax = -DBL_MAX; 942 815 943 816 for (FlowHashmap::iterator itr = flowTable.begin(); … … 951 824 min = data->magMin(); 952 825 max = data->magMax(); 953 if (min < magMin) {954 magMin = min;826 if (min < Flow::magMin) { 827 Flow::magMin = min; 955 828 } 956 if (max > magMax) { 957 magMax = max; 958 } 959 if (data->xMin() < xMin) { 960 xMin = data->xMin(); 961 } 962 if (data->yMin() < yMin) { 963 yMin = data->yMin(); 964 } 965 if (data->zMin() < zMin) { 966 zMin = data->zMin(); 967 } 968 if (data->xMax() > xMax) { 969 xMax = data->xMax(); 970 } 971 if (data->yMax() > yMax) { 972 yMax = data->yMax(); 973 } 974 if (data->zMax() > zMax) { 975 zMax = data->zMax(); 976 } 977 } 978 979 TRACE("magMin=%g magMax=%g", NanoVis::magMin, NanoVis::magMax); 829 if (max > Flow::magMax) { 830 Flow::magMax = max; 831 } 832 } 833 834 TRACE("magMin=%g magMax=%g", Flow::magMin, Flow::magMax); 980 835 981 836 /* … … 994 849 return false; 995 850 } 996 // FIXME: This doesn't work when there is more than one flow. 997 licRenderer->setOffset(flow->getRelativePosition()); 998 velocityArrowsSlice->slicePos(flow->getRelativePosition()); 999 } 1000 advectFlows(); 851 } 852 853 Flow::updatePending = false; 1001 854 return true; 1002 855 } … … 1009 862 TRACE("Enter"); 1010 863 1011 min.set(FLT_MAX, FLT_MAX, FLT_MAX); 1012 max.set(-FLT_MAX, -FLT_MAX, -FLT_MAX); 1013 864 BBox allBounds; 1014 865 for (FlowHashmap::iterator itr = flowTable.begin(); 1015 866 itr != flowTable.end(); ++itr) { 1016 itr->second->getBounds(min, max, onlyVisible); 1017 } 867 BBox bbox; 868 itr->second->getBounds(bbox.min, bbox.max, onlyVisible); 869 allBounds.extend(bbox); 870 } 871 872 min = allBounds.min; 873 max = allBounds.max; 1018 874 } 1019 875 … … 1028 884 } 1029 885 } 1030 flags &= ~REDRAW_PENDING;1031 886 } 1032 887 … … 1034 889 NanoVis::resetFlows() 1035 890 { 1036 if (licRenderer->active()) { 1037 NanoVis::licRenderer->reset(); 1038 } 891 NanoVis::licRenderer->reset(); 1039 892 for (FlowHashmap::iterator itr = flowTable.begin(); 1040 893 itr != flowTable.end(); ++itr) { 1041 894 Flow *flow = itr->second; 1042 if (flow->isDataLoaded() && flow->visible()) {895 if (flow->isDataLoaded()) { 1043 896 flow->resetParticles(); 1044 897 } … … 1049 902 NanoVis::advectFlows() 1050 903 { 904 TRACE("Enter"); 1051 905 for (FlowHashmap::iterator itr = flowTable.begin(); 1052 906 itr != flowTable.end(); ++itr) { 1053 907 Flow *flow = itr->second; 1054 if (flow->isDataLoaded() && flow->visible()) {908 if (flow->isDataLoaded()) { 1055 909 flow->advect(); 1056 910 } … … 1063 917 TRACE("Enter"); 1064 918 1065 if (flags & MAP_FLOWS) { 1066 #ifdef notdef 1067 xMin = yMin = zMin = wMin = FLT_MAX, magMin = DBL_MAX; 1068 xMax = yMax = zMax = wMax = -FLT_MAX, magMax = -DBL_MAX; 1069 #endif 919 if (Flow::updatePending) { 1070 920 mapFlows(); 1071 grid->xAxis.setScale(xMin, xMax); 1072 grid->yAxis.setScale(yMin, yMax); 1073 grid->zAxis.setScale(zMin, zMax); 1074 } 1075 //assert(glGetError()==0); 921 } 1076 922 if (HeightMap::updatePending) { 1077 923 setHeightmapRanges(); … … 1081 927 } 1082 928 1083 //start final rendering 929 collectBounds(); 930 931 // Start final rendering 1084 932 1085 933 // Need to reset fbo since it may have been changed to default (0) … … 1092 940 glEnable(GL_COLOR_MATERIAL); 1093 941 1094 //camera setting activated 1095 cam->initialize(); 1096 1097 //set up the orientation of items in the scene. 1098 glPushMatrix(); 1099 1100 switch (updir) { 1101 case X_POS: 1102 glRotatef(90, 0, 0, 1); 1103 glRotatef(90, 1, 0, 0); 1104 break; 1105 case Y_POS: 1106 // this is the default 1107 break; 1108 case Z_POS: 1109 glRotatef(-90, 1, 0, 0); 1110 glRotatef(-90, 0, 0, 1); 1111 break; 1112 case X_NEG: 1113 glRotatef(-90, 0, 0, 1); 1114 break; 1115 case Y_NEG: 1116 glRotatef(180, 0, 0, 1); 1117 glRotatef(-90, 0, 1, 0); 1118 break; 1119 case Z_NEG: 1120 glRotatef(90, 1, 0, 0); 1121 break; 1122 } 1123 1124 //now render things in the scene 1125 942 // Emit modelview and projection matrices 943 _camera->initialize(); 944 945 // Now render things in the scene 946 947 orientationIndicator->setPosition(sceneBounds.getCenter()); 948 orientationIndicator->setScale(sceneBounds.getSize()); 1126 949 orientationIndicator->render(); 950 1127 951 grid->render(); 1128 if ((licRenderer != NULL) && (licRenderer->active())) { 1129 licRenderer->render(); 1130 } 1131 if ((velocityArrowsSlice != NULL) && (velocityArrowsSlice->enabled())) { 1132 velocityArrowsSlice->render(); 1133 } 952 953 licRenderer->render(); 954 955 velocityArrowsSlice->render(); 956 1134 957 renderFlows(); 958 1135 959 volRenderer->renderAll(); 1136 960 1137 HeightMapHashmap::iterator itr; 1138 for (itr = heightMapTable.begin(); 961 for (HeightMapHashmap::iterator itr = heightMapTable.begin(); 1139 962 itr != heightMapTable.end(); ++itr) { 1140 HeightMap *heightMap = itr->second; 1141 if (heightMap->isVisible()) { 1142 heightMap->render(renderContext); 1143 } 1144 } 1145 glPopMatrix(); 963 itr->second->render(renderContext); 964 } 1146 965 1147 966 CHECK_FRAMEBUFFER_STATUS(); 1148 967 TRACE("Leave"); 1149 } 968 redrawPending = false; 969 } -
trunk/packages/vizservers/nanovis/nanovis.h
r3626 r3630 31 31 #include <tr1/unordered_map> 32 32 33 #include <vrmath/BBox.h> 33 34 #include <vrmath/Vector3f.h> 34 35 35 36 #include "config.h" 37 #include "Camera.h" 38 #include "FlowTypes.h" 36 39 #include "md5.h" 37 40 … … 48 51 } 49 52 50 class Camera;51 53 class Flow; 52 54 class Grid; … … 64 66 { 65 67 public: 66 enum AxisDirections {67 X_POS = 1,68 Y_POS = 2,69 Z_POS = 3,70 X_NEG = -1,71 Y_NEG = -2,72 Z_NEG = -373 };74 75 enum NanoVisFlags {76 REDRAW_PENDING = (1 << 0),77 MAP_FLOWS = (1 << 1)78 };79 80 68 typedef std::string TransferFunctionId; 81 69 typedef std::string VolumeId; … … 98 86 static const Camera *getCamera() 99 87 { 100 return cam;88 return _camera; 101 89 } 102 static void pan(float dx, float dy); 103 static void zoom(float z); 90 static void panCamera(float dx, float dy); 91 static void zoomCamera(float z); 92 static void orientCamera(double *quat); 93 static void setCameraPosition(vrmath::Vector3f pos); 94 static void setCameraUpdir(Camera::AxisDirection dir); 104 95 static void resetCamera(bool resetOrientation = false); 105 96 106 static void eventuallyRedraw(unsigned int flag = 0); 107 108 static void setVolumeRanges(); 109 static void setHeightmapRanges(); 97 static void eventuallyRedraw(); 110 98 111 99 static TransferFunction *getTransferFunction(const TransferFunctionId& id); … … 133 121 } 134 122 123 static void setVolumeRanges(); 124 static void setHeightmapRanges(); 125 static bool mapFlows(); 126 135 127 static Flow *getFlow(const char *name); 136 128 static Flow *createFlow(Tcl_Interp *interp, const char *name); 137 129 static void deleteFlows(Tcl_Interp *interp); 138 130 static void deleteFlow(const char *name); 139 static bool mapFlows();140 131 static void getFlowBounds(vrmath::Vector3f& min, 141 132 vrmath::Vector3f& max, … … 148 139 static Tcl_Interp *interp; 149 140 150 static unsigned int flags;141 static bool redrawPending; 151 142 static bool debugFlag; 152 143 153 144 static int winWidth; ///< Width of the render window 154 145 static int winHeight; ///< Height of the render window 155 static int renderWindow; // < GLUT handle for the render window146 static int renderWindow; ///< GLUT handle for the render window 156 147 static unsigned char *screenBuffer; 157 148 static Texture2D *legendTexture; 158 149 static util::Fonts *fonts; 159 static int updir;160 static Camera *cam;161 150 static graphics::RenderContext *renderContext; 162 151 … … 166 155 static HeightMapHashmap heightMapTable; 167 156 168 static double magMin, magMax; 169 static float xMin, xMax, yMin, yMax, zMin, zMax, wMin, wMax; 170 static vrmath::Vector3f sceneMin, sceneMax; 157 static vrmath::BBox sceneBounds; 171 158 172 159 static VolumeRenderer *volRenderer; … … 180 167 static void collectBounds(bool onlyVisible = false); 181 168 182 static float _licSlice; ///< Slice position [0,1] 183 static int _licAxis; ///< Slice axis: 0:x, 1:y, 2:z 169 static Camera *_camera; 184 170 185 171 //frame buffer for final rendering -
trunk/packages/vizservers/nanovis/nanovisServer.cpp
r3614 r3630 352 352 NanoVis::removeAllData(); 353 353 354 Shader::exit Cg();354 Shader::exit(); 355 355 356 356 //close log file … … 434 434 435 435 static 436 void cgErrorCallback(void)436 void shaderErrorCallback(void) 437 437 { 438 438 if (!Shader::printErrorInfo()) { 439 TRACE(" Cgerror, exiting...");439 TRACE("Shader error, exiting..."); 440 440 exitService(1); 441 441 } … … 579 579 } 580 580 581 Shader::init(); 581 582 // Override callback with one that cleans up server on exit 582 Shader::setErrorCallback( cgErrorCallback);583 Shader::setErrorCallback(shaderErrorCallback); 583 584 584 585 if (!NanoVis::initGL()) { -
trunk/packages/vizservers/nanovis/newmat11/Makefile.in
r3470 r3630 73 73 74 74 clean: 75 $(RM) $(MATLIB) $(OBJS)75 $(RM) *.a *.o 76 76 77 77 distclean: clean -
trunk/packages/vizservers/nanovis/protocol-nanovis.txt
r3605 r3630 104 104 -outline <bool> 105 105 -position <val|%val> 106 val = [0,100], or %val = [0,1]106 val = world coordinate, or %val = [0,100] 107 107 -slice <bool> 108 108 -specularExp <val> -
trunk/packages/vizservers/nanovis/shaders/common.cg
r3177 r3630 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 2 /* 3 * ====================================================================== 4 * AUTHOR: Wei Qiao <qiaow@purdue.edu> 5 * Purdue Rendering and Perceptualization Lab (PURPL) 3 * Copyright (c) 2004-2013 HUBzero Foundation, LLC 6 4 * 7 * Copyright (c) 2004-2012 HUBzero Foundation, LLC 8 * 9 * See the file "license.terms" for information on usage and 10 * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. 11 * ====================================================================== 5 * Authors: 6 * Wei Qiao <qiaow@purdue.edu> 12 7 */ 13 8 -
trunk/packages/vizservers/nanovis/shaders/copy_texcoord.cg
r3177 r3630 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 2 /* 3 * ====================================================================== 4 * AUTHOR: Wei Qiao <qiaow@purdue.edu> 5 * Purdue Rendering and Perceptualization Lab (PURPL) 3 * Copyright (c) 2004-2013 HUBzero Foundation, LLC 6 4 * 7 * Copyright (c) 2004-2012 HUBzero Foundation, LLC 8 * 9 * See the file "license.terms" for information on usage and 10 * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. 11 * ====================================================================== 5 * Authors: 6 * Wei Qiao <qiaow@purdue.edu> 12 7 */ 13 8 -
trunk/packages/vizservers/nanovis/shaders/cutplane_fp.cg
r3362 r3630 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * Copyright (c) 2004-2013 HUBzero Foundation, LLC 4 * 5 * Authors: 6 * Wei Qiao <qiaow@purdue.edu> 7 */ 2 8 3 9 float4 main(in float4 texcoord : TEXCOORD0, -
trunk/packages/vizservers/nanovis/shaders/cutplane_vp.cg
r3362 r3630 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * Copyright (c) 2004-2013 HUBzero Foundation, LLC 4 * 5 * Authors: 6 * Wei Qiao <qiaow@purdue.edu> 7 */ 2 8 3 9 void main(in float4 position : POSITION, -
trunk/packages/vizservers/nanovis/shaders/heightcolor.cg
r2852 r3630 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * Copyright (c) 2004-2013 HUBzero Foundation, LLC 4 * 5 * Authors: 6 * Wei Qiao <qiaow@purdue.edu> 7 */ 2 8 3 9 float4 main(float4 texCoord : TEXCOORD0, -
trunk/packages/vizservers/nanovis/shaders/moveparticles.cg
r2852 r3630 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * Copyright (c) 2004-2013 HUBzero Foundation, LLC 4 * 5 * Authors: 6 * Wei Qiao <qiaow@purdue.edu> 7 */ 8 2 9 float4 main (float2 texCoord : TEXCOORD0, 3 10 uniform samplerRECT posTexture : register(s0), -
trunk/packages/vizservers/nanovis/shaders/one_plane.cg
r3177 r3630 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 2 /* 3 * ====================================================================== 4 * AUTHOR: Wei Qiao <qiaow@purdue.edu> 5 * Purdue Rendering and Perceptualization Lab (PURPL) 3 * Copyright (c) 2004-2013 HUBzero Foundation, LLC 6 4 * 7 * Copyright (c) 2004-2012 HUBzero Foundation, LLC 8 * 9 * See the file "license.terms" for information on usage and 10 * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. 11 * ====================================================================== 5 * Authors: 6 * Wei Qiao <qiaow@purdue.edu> 12 7 */ 13 14 8 15 9 float4 main(in float2 uv: TEXCOORD0, -
trunk/packages/vizservers/nanovis/shaders/one_volume.cg
r3362 r3630 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 2 /* 3 * ====================================================================== 4 * AUTHOR: Wei Qiao <qiaow@purdue.edu> 5 * Purdue Rendering and Perceptualization Lab (PURPL) 3 * Copyright (c) 2004-2013 HUBzero Foundation, LLC 6 4 * 7 * Copyright (c) 2004-2012 HUBzero Foundation, LLC 8 * 9 * See the file "license.terms" for information on usage and 10 * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. 11 * ====================================================================== 5 * Authors: 6 * Wei Qiao <qiaow@purdue.edu> 7 * Leif Delgass <ldelgass@purdue.edu> 12 8 */ 13 9 … … 33 29 uniform sampler3D volume, 34 30 uniform sampler1D tf, 35 uniform float4x4 modelViewInv,36 uniform float4x4 modelView,37 31 uniform float4 material, 38 32 uniform float4 renderParams) 39 33 { 40 34 PixelOut OUT; 41 float4 tex_coord = mul(modelViewInv, IN.TexCoord); 42 float4 sample = tex3D(volume, tex_coord.xyz); 35 float4 sample = tex3D(volume, IN.TexCoord.xyz); 43 36 44 37 //sample the transfer function texture -
trunk/packages/vizservers/nanovis/shaders/particle_common.cg
r2852 r3630 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * Copyright (c) 2004-2013 HUBzero Foundation, LLC 4 * 5 * Authors: 6 * Wei Qiao <qiaow@purdue.edu> 7 */ 8 2 9 #define SUBIMAGE_SIZE_X 32 3 10 #define SUBIMAGE_SIZE_Y 32 -
trunk/packages/vizservers/nanovis/shaders/particlefp.cg
r2877 r3630 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * Copyright (c) 2004-2013 HUBzero Foundation, LLC 4 * 5 * Authors: 6 * Wei Qiao <qiaow@purdue.edu> 7 */ 8 2 9 #include "particle_common.cg" 3 10 -
trunk/packages/vizservers/nanovis/shaders/particlevp.cg
r2852 r3630 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * Copyright (c) 2004-2013 HUBzero Foundation, LLC 4 * 5 * Authors: 6 * Wei Qiao <qiaow@purdue.edu> 7 */ 8 2 9 #include "particle_common.cg" 10 3 11 void vpmain(in float4 posin : POSITION, 4 12 in float4 colin : COLOR0, -
trunk/packages/vizservers/nanovis/shaders/passthrough.cg
r2852 r3630 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * Copyright (c) 2004-2013 HUBzero Foundation, LLC 4 * 5 * Authors: 6 * Wei Qiao <qiaow@purdue.edu> 7 */ 8 2 9 float4 main(float2 texCoord : TEXCOORD0, 3 10 uniform samplerRECT tex : register(s0), -
trunk/packages/vizservers/nanovis/shaders/passthru.cg
r3177 r3630 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 2 /* 3 * ====================================================================== 4 * AUTHOR: Wei Qiao <qiaow@purdue.edu> 5 * Purdue Rendering and Perceptualization Lab (PURPL) 3 * Copyright (c) 2004-2013 HUBzero Foundation, LLC 6 4 * 7 * Copyright (c) 2004-2012 HUBzero Foundation, LLC 8 * 9 * See the file "license.terms" for information on usage and 10 * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. 11 * ====================================================================== 5 * Authors: 6 * Wei Qiao <qiaow@purdue.edu> 12 7 */ 13 8 -
trunk/packages/vizservers/nanovis/shaders/pointsvp.cg
r2857 r3630 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * Copyright (c) 2004-2013 HUBzero Foundation, LLC 4 * 5 * Authors: 6 * Wei Qiao <qiaow@purdue.edu> 7 */ 2 8 3 9 void main(in float4 posin : POSITION, … … 11 17 uniform float4 basepos, 12 18 uniform float4 scale, 13 uniform float4x4 model view,14 uniform float4x4 projection)19 uniform float4x4 modelView, 20 uniform float4x4 modelViewProj) 15 21 { 16 22 float4 vec, homeye, eye; 17 23 vec.xyz = posin.xyz; 18 24 vec.w = 1.0; 19 homeye = mul(model view, vec);20 posout = mul( projection, homeye);25 homeye = mul(modelView, vec); 26 posout = mul(modelViewProj, posin); 21 27 22 float4 p = mul(model view, vec);28 float4 p = mul(modelView, vec); 23 29 //psize = scale.x *(p.w / -p.z) * 10; 24 30 … … 39 45 vec.w = 1.0; 40 46 41 homeye = mul(model view, vec);47 homeye = mul(modelView, vec); 42 48 posout = mul(projection, homeye); 43 49 -
trunk/packages/vizservers/nanovis/shaders/queryvelocity.cg
r2857 r3630 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * Copyright (c) 2004-2013 HUBzero Foundation, LLC 4 * 5 * Authors: 6 * Wei Qiao <qiaow@purdue.edu> 7 */ 2 8 3 9 float4 main(float3 pos : TEXCOORD0, -
trunk/packages/vizservers/nanovis/shaders/render_vel.cg
r3177 r3630 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 2 /* 3 * ====================================================================== 4 * AUTHOR: Wei Qiao <qiaow@purdue.edu> 5 * Purdue Rendering and Perceptualization Lab (PURPL) 3 * Copyright (c) 2004-2013 HUBzero Foundation, LLC 6 4 * 7 * Copyright (c) 2004-2012 HUBzero Foundation, LLC 8 * 9 * See the file "license.terms" for information on usage and 10 * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. 11 * ====================================================================== 5 * Authors: 6 * Wei Qiao <qiaow@purdue.edu> 12 7 */ 13 8 -
trunk/packages/vizservers/nanovis/shaders/renderparticle.cg
r2852 r3630 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * Copyright (c) 2004-2013 HUBzero Foundation, LLC 4 * 5 * Authors: 6 * Wei Qiao <qiaow@purdue.edu> 7 */ 2 8 3 /*4 9 void main(in float4 posin : POSITION, 5 10 in float4 colin : COLOR0, … … 34 39 colout = float4(colin.xyz, colin.w * 0.25); 35 40 } 36 */ -
trunk/packages/vizservers/nanovis/shaders/update_pos.cg
r3177 r3630 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 2 /* 3 * ====================================================================== 4 * AUTHOR: Wei Qiao <qiaow@purdue.edu> 5 * Purdue Rendering and Perceptualization Lab (PURPL) 3 * Copyright (c) 2004-2013 HUBzero Foundation, LLC 6 4 * 7 * Copyright (c) 2004-2012 HUBzero Foundation, LLC 8 * 9 * See the file "license.terms" for information on usage and 10 * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. 11 * ====================================================================== 5 * Authors: 6 * Wei Qiao <qiaow@purdue.edu> 12 7 */ 13 8 … … 20 15 uniform samplerRECT init_pos_tex, 21 16 uniform sampler3D vel_tex, 22 // uniform sampler1D tf_tex,23 17 uniform float timestep, 24 18 uniform float max, 25 uniform float mode,26 19 uniform float3 scale) : COLOR 27 20 { 28 21 float4 ret; 29 /*30 if (mode == 0) {31 float4 pos = texRECT(pos_tex, uv);32 float4 vel = tex3D(vel_tex, pos.xyz);33 ret.xyz = tex1D(tf_tex, vel.x).xyz;34 ret.w = 1;35 } else {36 */37 22 // get previous position 38 23 float4 pos = texRECT(pos_tex, uv); 39 24 float time = pos.w; 40 25 26 //reconstruct negative value 27 if (max > 0) { 41 28 #ifdef EXPIRE 42 time -= timestep;29 time -= timestep; 43 30 44 // Lifetime ended? 45 if (time < 0) { 46 return texRECT(init_pos_tex, uv); 31 // Lifetime ended? 32 if (time < 0) { 33 return texRECT(init_pos_tex, uv); 34 } 35 #endif 36 float4 vel = float4(tex3D(vel_tex, pos.xyz).yzw, 0.0) * 2.0 - float4(1.0, 1.0, 1.0, 0.0); 37 vel = vel * max; 38 //vel *= float4(scale, 1); 39 ret = pos + (vel * timestep); 40 } else { 41 ret = pos; 47 42 } 48 #endif49 50 //reconstruct negative value51 float4 vel = float4(tex3D(vel_tex, pos.xyz).yzw, 0.0) * 2.0 - float4(1.0, 1.0, 1.0, 0.0f);52 vel = vel * max;53 //vel *= float4(scale, 1);54 ret = pos + (vel * timestep);55 43 56 44 //not drawing if the particle is out of bound … … 60 48 ret.w = time; 61 49 } 62 // }63 50 64 51 return ret; -
trunk/packages/vizservers/nanovis/shaders/update_pos_vel.cg
r3177 r3630 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 2 /* 3 * ====================================================================== 4 * AUTHOR: Wei Qiao <qiaow@purdue.edu> 5 * Purdue Rendering and Perceptualization Lab (PURPL) 3 * Copyright (c) 2004-2013 HUBzero Foundation, LLC 6 4 * 7 * Copyright (c) 2004-2012 HUBzero Foundation, LLC 8 * 9 * See the file "license.terms" for information on usage and 10 * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. 11 * ====================================================================== 5 * Authors: 6 * Wei Qiao <qiaow@purdue.edu> 12 7 */ 13 8 -
trunk/packages/vizservers/nanovis/shaders/update_vel.cg
r3177 r3630 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 2 /* 3 * ====================================================================== 4 * AUTHOR: Wei Qiao <qiaow@purdue.edu> 5 * Purdue Rendering and Perceptualization Lab (PURPL) 3 * Copyright (c) 2004-2013 HUBzero Foundation, LLC 6 4 * 7 * Copyright (c) 2004-2012 HUBzero Foundation, LLC 8 * 9 * See the file "license.terms" for information on usage and 10 * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. 11 * ====================================================================== 5 * Authors: 6 * Wei Qiao <qiaow@purdue.edu> 12 7 */ 13 8 -
trunk/packages/vizservers/nanovis/shaders/velocityslicefp.cg
r2964 r3630 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * Copyright (c) 2004-2013 HUBzero Foundation, LLC 4 * 5 * Authors: 6 * Wei Qiao <qiaow@purdue.edu> 7 */ 2 8 3 9 #include "particle_common.cg" 4 10 5 float4 fpmain(float2 texCoord : TEXCOORD0,6 7 8 9 11 float4 main(float2 texCoord : TEXCOORD0, 12 float4 color : COLOR0, 13 float2 center : TEXCOORD2, 14 float4 rotation : TEXCOORD3, 15 uniform sampler2D arrows : TEXUNIT0) : COLOR 10 16 { 11 17 float2 newTexCoord = float2((texCoord.x - 0.5) / NUM_SUBIMAGE_X, (texCoord.y - 0.5) / NUM_SUBIMAGE_Y); -
trunk/packages/vizservers/nanovis/shaders/velocityslicevp.cg
r2964 r3630 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * Copyright (c) 2004-2013 HUBzero Foundation, LLC 4 * 5 * Authors: 6 * Wei Qiao <qiaow@purdue.edu> 7 */ 2 8 3 9 #include "particle_common.cg" 4 10 5 void vpmain(in float4 posin : POSITION,6 7 8 9 10 11 12 13 14 15 11 void main(in float4 posin : POSITION, 12 in float4 colin : COLOR0, 13 out float4 posout : POSITION, 14 out float4 colout : COLOR0, 15 out float2 center : TEXCOORD2, 16 out float4 rotation : TEXCOORD3, 17 out float4 pointSize : PSIZE, 18 uniform sampler3D vfield : TEXUNIT1, 19 uniform float tanHalfFOV, 20 uniform float4x4 modelview, 21 uniform float4x4 mvp) 16 22 { 17 23 float4 vec; -
trunk/packages/vizservers/nanovis/shaders/vertex_std.cg
r3177 r3630 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 2 /* 3 * ====================================================================== 4 * AUTHOR: Wei Qiao <qiaow@purdue.edu> 5 * Purdue Rendering and Perceptualization Lab (PURPL) 3 * Copyright (c) 2004-2013 HUBzero Foundation, LLC 6 4 * 7 * Copyright (c) 2004-2012 HUBzero Foundation, LLC 8 * 9 * See the file "license.terms" for information on usage and 10 * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. 11 * ====================================================================== 5 * Authors: 6 * Wei Qiao <qiaow@purdue.edu> 12 7 */ 13 8 … … 16 11 v2f main(a2v IN, 17 12 uniform float4x4 modelViewProjMatrix, 18 uniform float4x4 modelViewInv) 13 uniform float4x4 modelViewInv, 14 uniform float4 light0Position, 15 uniform float4 objPlaneS, 16 uniform float4 objPlaneT, 17 uniform float4 objPlaneR) 19 18 { 20 19 v2f OUT; … … 24 23 float4 eyePosObjSpace = mul(modelViewInv, float4(0,0,0,1)); 25 24 26 //clip space vertex position 27 //OUT.HPosition = mul(modelViewProjMatrix, mul(modelViewInv, IN.Position)); 25 // Clip space vertex position 28 26 OUT.HPosition = mul(modelViewProjMatrix, objPos); 29 27 30 //eye space texture coordinates 31 OUT.TexCoord = IN.TexCoord; 28 // Generate world space texture coordinates 29 OUT.TexCoord.x = dot(objPos, objPlaneS); 30 OUT.TexCoord.y = dot(objPos, objPlaneT); 31 OUT.TexCoord.z = dot(objPos, objPlaneR); 32 32 33 //world space eye position 34 //OUT.EyeVector = normalize(-IN.Position.xyz); 33 // World space eye position 35 34 OUT.EyeVector = normalize(eyePosObjSpace - objPos); 36 35 37 //world space light postion 38 //OUT.Light = normalize(float3(1,1,1)-IN.Position.xyz); 39 OUT.Light = normalize(mul(modelViewInv, float4(1,1,1,1))-objPos); 36 // World space light postion (light0Position is in eye coords) 37 OUT.Light = normalize(mul(modelViewInv, light0Position)-objPos); 40 38 41 39 return OUT; -
trunk/packages/vizservers/nanovis/shaders/volqd_volume.cg
r2852 r3630 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * Copyright (c) 2004-2013 HUBzero Foundation, LLC 4 * 5 * Authors: 6 * Wei Qiao <qiaow@purdue.edu> 7 */ 8 2 9 #include "common.cg" 3 10 … … 6 13 uniform sampler3D vol_grid_s, 7 14 uniform float4 cell_size, 8 uniform float4x4 ModelViewInv,9 15 uniform float4 renderParameters) 10 16 { … … 14 20 15 21 float4 twice_cell_size = cell_size*2.0; 16 float4 tex_coord = mul(ModelViewInv, IN.TexCoord);22 float4 tex_coord = IN.TexCoord; 17 23 float4 tex_coord_a = tex_coord - float4(twice_cell_size.x, twice_cell_size.y, 0, 0); 18 24 float4 tex_coord_b = tex_coord - float4(twice_cell_size.x, 0, twice_cell_size.z, 0); 19 25 float4 tex_coord_c = tex_coord - float4(0, twice_cell_size.y, twice_cell_size.z, 0); 20 26 21 float4 voxel_corner = f4tex3D(vol_grid_s, tex_coord);22 float4 voxel_face_center_a = f4tex3D(vol_grid_s, tex_coord_a);23 float4 voxel_face_center_b = f4tex3D(vol_grid_s, tex_coord_b);24 float4 voxel_face_center_c = f4tex3D(vol_grid_s, tex_coord_c);27 float4 voxel_corner = tex3D(vol_grid_s, tex_coord); 28 float4 voxel_face_center_a = tex3D(vol_grid_s, tex_coord_a); 29 float4 voxel_face_center_b = tex3D(vol_grid_s, tex_coord_b); 30 float4 voxel_face_center_c = tex3D(vol_grid_s, tex_coord_c); 25 31 float sample = (voxel_corner.x + voxel_face_center_a.y + voxel_face_center_b.z + voxel_face_center_c.w)*0.25; 26 32 -
trunk/packages/vizservers/nanovis/shaders/zincblende_volume.cg
r3362 r3630 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 2 /* 3 * ====================================================================== 4 * AUTHOR: Wei Qiao <qiaow@purdue.edu> 5 * Purdue Rendering and Perceptualization Lab (PURPL) 3 * Copyright (c) 2004-2013 HUBzero Foundation, LLC 6 4 * 7 * Copyright (c) 2004-2012 HUBzero Foundation, LLC 8 * 9 * See the file "license.terms" for information on usage and 10 * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. 11 * ====================================================================== 5 * Authors: 6 * Wei Qiao <qiaow@purdue.edu> 12 7 */ 13 8 … … 27 22 uniform sampler3D volumeB, 28 23 uniform float4 cellSize, 29 uniform float4x4 modelViewInv,30 24 uniform float4 renderParams) 31 25 … … 33 27 PixelOut OUT; 34 28 35 float4 tex _coord = mul(modelViewInv, IN.TexCoord);29 float4 texcoord = IN.TexCoord; 36 30 float4 twice_cell_size = cellSize * 2.0; 37 31 38 32 // volumeA : outer 39 33 // volumeB : inner 40 float4 tex _coord_2 = tex_coord + float4(twice_cell_size.x, 0, twice_cell_size.z, 0);41 float4 tex _coord_3 = tex_coord + float4(0, twice_cell_size.y, twice_cell_size.z, 0);42 float4 tex _coord_4 = tex_coord + float4(twice_cell_size.x, twice_cell_size.y, 0, 0);43 float4 voxel_corner = f4tex3D(volumeB, tex_coord) + f4tex3D(volumeA, tex_coord - cellSize);44 float4 voxel_face_center_2 = f4tex3D(volumeB, tex_coord_2) + f4tex3D(volumeA, tex_coord_2 - cellSize);45 float4 voxel_face_center_3 = f4tex3D(volumeB, tex_coord_3) + f4tex3D(volumeA, tex_coord_3 - cellSize);46 float4 voxel_face_center_4 = f4tex3D(volumeB, tex_coord_4) + f4tex3D(volumeA, tex_coord_4 - cellSize);34 float4 texcoord_2 = texcoord + float4(twice_cell_size.x, 0, twice_cell_size.z, 0); 35 float4 texcoord_3 = texcoord + float4(0, twice_cell_size.y, twice_cell_size.z, 0); 36 float4 texcoord_4 = texcoord + float4(twice_cell_size.x, twice_cell_size.y, 0, 0); 37 float4 voxel_corner = tex3D(volumeB, texcoord) + tex3D(volumeA, texcoord - cellSize); 38 float4 voxel_face_center_2 = tex3D(volumeB, texcoord_2) + tex3D(volumeA, texcoord_2 - cellSize); 39 float4 voxel_face_center_3 = tex3D(volumeB, texcoord_3) + tex3D(volumeA, texcoord_3 - cellSize); 40 float4 voxel_face_center_4 = tex3D(volumeB, texcoord_4) + tex3D(volumeA, texcoord_4 - cellSize); 47 41 48 42 float sample = (voxel_corner.x + voxel_face_center_2.y + voxel_face_center_3.z + voxel_face_center_4.w) * 0.125; 49 43 /* 50 float4 tex _coord_a = tex_coord - float4(twice_cell_size.x, twice_cell_size.y, 0, 0);51 float4 tex _coord_b = tex_coord - float4(twice_cell_size.x, 0, twice_cell_size.z, 0);52 float4 tex _coord_c = tex_coord - float4(0, twice_cell_size.y, twice_cell_size.z, 0);44 float4 texcoord_a = texcoord - float4(twice_cell_size.x, twice_cell_size.y, 0, 0); 45 float4 texcoord_b = texcoord - float4(twice_cell_size.x, 0, twice_cell_size.z, 0); 46 float4 texcoord_c = texcoord - float4(0, twice_cell_size.y, twice_cell_size.z, 0); 53 47 54 float4 voxel_corner = f4tex3D(volumeA, tex_coord) + f4tex3D(volumeB, tex_coord - cellSize);55 float4 voxel_face_center_a = f4tex3D(volumeA, tex_coord_a) + f4tex3D(volumeB, tex_coord_a - cellSize);56 float4 voxel_face_center_b = f4tex3D(volumeA, tex_coord_b) + f4tex3D(volumeB, tex_coord_b - cellSize);57 float4 voxel_face_center_c = f4tex3D(volumeA, tex_coord_c) + f4tex3D(volumeB, tex_coord_c - cellSize);48 float4 voxel_corner = tex3D(volumeA, texcoord) + tex3D(volumeB, texcoord - cellSize); 49 float4 voxel_face_center_a = tex3D(volumeA, texcoord_a) + tex3D(volumeB, texcoord_a - cellSize); 50 float4 voxel_face_center_b = tex3D(volumeA, texcoord_b) + tex3D(volumeB, texcoord_b - cellSize); 51 float4 voxel_face_center_c = tex3D(volumeA, texcoord_c) + tex3D(volumeB, texcoord_c - cellSize); 58 52 //combine 8 sampling results 59 53 float sample = (voxel_corner.x + voxel_face_center_a.y + voxel_face_center_b.z + voxel_face_center_c.w) * 0.125; … … 61 55 62 56 //sample transfer function texture 63 float4 color = f4tex1D(tf, sample);57 float4 color = tex1D(tf, sample); 64 58 65 59 if (renderParams.x == 0.0) { -
trunk/packages/vizservers/nanovis/util/Fonts.h
r3470 r3630 83 83 84 84 #endif 85 -
trunk/packages/vizservers/nanovis/util/Makefile.in
r3470 r3630 57 57 58 58 clean: 59 $(RM) $(NVUTILLIB) $(OBJS)59 $(RM) *.a *.o 60 60 61 61 distclean: clean -
trunk/packages/vizservers/nanovis/vrmath/Makefile.in
r3628 r3630 70 70 71 71 clean: 72 $(RM) $(VRMATHLIB) $(OBJS)72 $(RM) *.a *.o 73 73 74 74 distclean: clean -
trunk/packages/vizservers/nanovis/vrmath/Matrix4x4d.cpp
r3628 r3630 229 229 void Matrix4x4d::multiply(const Matrix4x4d& m1, const Matrix4x4d& m2) 230 230 { 231 double mat[16]; 232 const double *mat1 = m1._data; 233 const double *mat2 = m2._data; 234 235 // 1 row 236 mat[0] = mat1[0] * mat2[0] + mat1[4] * mat2[1] + 237 mat1[8] * mat2[2] + mat1[12] * mat2[3]; 238 mat[4] = mat1[0] * mat2[4] + mat1[4] * mat2[5] + 239 mat1[8] * mat2[6] + mat1[12] * mat2[7]; 240 mat[8] = mat1[0] * mat2[8] + mat1[4] * mat2[9] + 241 mat1[8] * mat2[10] + mat1[12] * mat2[11]; 242 mat[12] = mat1[0] * mat2[12] + mat1[4] * mat2[13] + 243 mat1[8] * mat2[14] + mat1[12] * mat2[15]; 244 245 // 2 row 246 mat[1] = mat1[1] * mat2[0] + mat1[5] * mat2[1] + 247 mat1[9] * mat2[2] + mat1[13] * mat2[3]; 248 mat[5] = mat1[1] * mat2[4] + mat1[5] * mat2[5] + 249 mat1[9] * mat2[6] + mat1[13] * mat2[7]; 250 mat[9] = mat1[1] * mat2[8] + mat1[5] * mat2[9] + 251 mat1[9] * mat2[10] + mat1[13] * mat2[11]; 252 mat[13] = mat1[1] * mat2[12] + mat1[5] * mat2[13] + 253 mat1[9] * mat2[14] + mat1[13] * mat2[15]; 254 255 // 3 row 256 mat[2] = mat1[2] * mat2[0] + mat1[6] * mat2[1] + 257 mat1[10] * mat2[2] + mat1[14] * mat2[3]; 258 mat[6] = mat1[2] * mat2[4] + mat1[6] * mat2[5] + 259 mat1[10] * mat2[6] + mat1[14] * mat2[7]; 260 mat[10] = mat1[2] * mat2[8] + mat1[6] * mat2[9] + 261 mat1[10] * mat2[10] + mat1[14] * mat2[11]; 262 mat[14] = mat1[2] * mat2[12] + mat1[6] * mat2[13] + 263 mat1[10] * mat2[14] + mat1[14] * mat2[15]; 264 265 // 4 row 266 mat[3] = mat1[3] * mat2[0] + mat1[7] * mat2[1] + 267 mat1[11] * mat2[2] + mat1[15] * mat2[3]; 268 mat[7] = mat1[3] * mat2[4] + mat1[7] * mat2[5] + 269 mat1[11] * mat2[6] + mat1[15] * mat2[7]; 270 mat[11] = mat1[3] * mat2[8] + mat1[7] * mat2[9] + 271 mat1[11] * mat2[10] + mat1[15] * mat2[11]; 272 mat[15] = mat1[3] * mat2[12] + mat1[7] * mat2[13] + 273 mat1[11] * mat2[14] + mat1[15] * mat2[15]; 274 275 // set matrix 276 set(mat); 231 if (&m1 == this && &m2 != this) { 232 multiply(m2); 233 } else if (&m1 != this && &m2 != this) { 234 multiplyFast(m1, m2); 235 } else { 236 double mat[16]; 237 const double *mat1 = m1._data; 238 const double *mat2 = m2._data; 239 240 // 1 row 241 mat[0] = mat1[0] * mat2[0] + mat1[4] * mat2[1] + 242 mat1[8] * mat2[2] + mat1[12] * mat2[3]; 243 mat[4] = mat1[0] * mat2[4] + mat1[4] * mat2[5] + 244 mat1[8] * mat2[6] + mat1[12] * mat2[7]; 245 mat[8] = mat1[0] * mat2[8] + mat1[4] * mat2[9] + 246 mat1[8] * mat2[10] + mat1[12] * mat2[11]; 247 mat[12] = mat1[0] * mat2[12] + mat1[4] * mat2[13] + 248 mat1[8] * mat2[14] + mat1[12] * mat2[15]; 249 250 // 2 row 251 mat[1] = mat1[1] * mat2[0] + mat1[5] * mat2[1] + 252 mat1[9] * mat2[2] + mat1[13] * mat2[3]; 253 mat[5] = mat1[1] * mat2[4] + mat1[5] * mat2[5] + 254 mat1[9] * mat2[6] + mat1[13] * mat2[7]; 255 mat[9] = mat1[1] * mat2[8] + mat1[5] * mat2[9] + 256 mat1[9] * mat2[10] + mat1[13] * mat2[11]; 257 mat[13] = mat1[1] * mat2[12] + mat1[5] * mat2[13] + 258 mat1[9] * mat2[14] + mat1[13] * mat2[15]; 259 260 // 3 row 261 mat[2] = mat1[2] * mat2[0] + mat1[6] * mat2[1] + 262 mat1[10] * mat2[2] + mat1[14] * mat2[3]; 263 mat[6] = mat1[2] * mat2[4] + mat1[6] * mat2[5] + 264 mat1[10] * mat2[6] + mat1[14] * mat2[7]; 265 mat[10] = mat1[2] * mat2[8] + mat1[6] * mat2[9] + 266 mat1[10] * mat2[10] + mat1[14] * mat2[11]; 267 mat[14] = mat1[2] * mat2[12] + mat1[6] * mat2[13] + 268 mat1[10] * mat2[14] + mat1[14] * mat2[15]; 269 270 // 4 row 271 mat[3] = mat1[3] * mat2[0] + mat1[7] * mat2[1] + 272 mat1[11] * mat2[2] + mat1[15] * mat2[3]; 273 mat[7] = mat1[3] * mat2[4] + mat1[7] * mat2[5] + 274 mat1[11] * mat2[6] + mat1[15] * mat2[7]; 275 mat[11] = mat1[3] * mat2[8] + mat1[7] * mat2[9] + 276 mat1[11] * mat2[10] + mat1[15] * mat2[11]; 277 mat[15] = mat1[3] * mat2[12] + mat1[7] * mat2[13] + 278 mat1[11] * mat2[14] + mat1[15] * mat2[15]; 279 280 // set matrix 281 set(mat); 282 } 277 283 } 278 284 … … 499 505 void Matrix4x4d::invert(const Matrix4x4d& mat) 500 506 { 501 const double *data = mat._data; 502 503 double det = 504 data[12] * data[9] * data[6] * data[3]- 505 data[8] * data[13] * data[6] * data[3]- 506 data[12] * data[5] * data[10] * data[3]+ 507 data[4] * data[13] * data[10] * data[3]+ 508 data[8] * data[5] * data[14] * data[3]- 509 data[4] * data[9] * data[14] * data[3]- 510 data[12] * data[9] * data[2] * data[7]+ 511 data[8] * data[13] * data[2] * data[7]+ 512 data[12] * data[1] * data[10] * data[7]- 513 data[0] * data[13] * data[10] * data[7]- 514 data[8] * data[1] * data[14] * data[7]+ 515 data[0] * data[9] * data[14] * data[7]+ 516 data[12] * data[5] * data[2] * data[11]- 517 data[4] * data[13] * data[2] * data[11]- 518 data[12] * data[1] * data[6] * data[11]+ 519 data[0] * data[13] * data[6] * data[11]+ 520 data[4] * data[1] * data[14] * data[11]- 521 data[0] * data[5] * data[14] * data[11]- 522 data[8] * data[5] * data[2] * data[15]+ 523 data[4] * data[9] * data[2] * data[15]+ 524 data[8] * data[1] * data[6] * data[15]- 525 data[0] * data[9] * data[6] * data[15]- 526 data[4] * data[1] * data[10] * data[15]+ 527 data[0] * data[5] * data[10] * data[15]; 528 529 if ( det == 0.0 ) return; 530 det = 1.0 / det; 531 532 double dstData[16]; 533 534 dstData[0] = (data[9]*data[14]*data[7] - 535 data[13]*data[10]*data[7] + 536 data[13]*data[6]*data[11] - 537 data[5]*data[14]*data[11] - 538 data[9]*data[6]*data[15] + 539 data[5]*data[10]*data[15]) * det; 540 541 dstData[4] = (data[12]*data[10]*data[7] - 542 data[8]*data[14]*data[7] - 543 data[12]*data[6]*data[11] + 544 data[4]*data[14]*data[11] + 545 data[8]*data[6]*data[15] - 546 data[4]*data[10]*data[15]) * det; 547 548 dstData[8] = (data[8]*data[13]*data[7] - 549 data[12]*data[9]*data[7] + 550 data[12]*data[5]*data[11] - 551 data[4]*data[13]*data[11] - 552 data[8]*data[5]*data[15] + 553 data[4]*data[9]*data[15]) * det; 554 555 dstData[12] = (data[12]*data[9]*data[6] - 556 data[8]*data[13]*data[6] - 557 data[12]*data[5]*data[10] + 558 data[4]*data[13]*data[10] + 559 data[8]*data[5]*data[14] - 560 data[4]*data[9]*data[14]) * det; 561 562 dstData[1] = (data[13]*data[10]*data[3] - 563 data[9]*data[14]*data[3] - 564 data[13]*data[2]*data[11] + 565 data[1]*data[14]*data[11] + 566 data[9]*data[2]*data[15] - 567 data[1]*data[10]*data[15]) * det; 568 569 dstData[5] = (data[8]*data[14]*data[3] - 570 data[12]*data[10]*data[3] + 571 data[12]*data[2]*data[11] - 572 data[0]*data[14]*data[11] - 573 data[8]*data[2]*data[15] + 574 data[0]*data[10]*data[15]) * det; 575 576 dstData[9] = (data[12]*data[9]*data[3] - 577 data[8]*data[13]*data[3] - 578 data[12]*data[1]*data[11] + 579 data[0]*data[13]*data[11] + 580 data[8]*data[1]*data[15] - 581 data[0]*data[9]*data[15]) * det; 582 583 dstData[13] = (data[8]*data[13]*data[2] - 584 data[12]*data[9]*data[2] + 585 data[12]*data[1]*data[10] - 586 data[0]*data[13]*data[10] - 587 data[8]*data[1]*data[14] + 588 data[0]*data[9]*data[14]) * det; 589 590 dstData[2] = (data[5]*data[14]*data[3] - 591 data[13]*data[6]*data[3] + 592 data[13]*data[2]*data[7] - 593 data[1]*data[14]*data[7] - 594 data[5]*data[2]*data[15] + 595 data[1]*data[6]*data[15]) * det; 596 597 dstData[6] = (data[12]*data[6]*data[3] - 598 data[4]*data[14]*data[3] - 599 data[12]*data[2]*data[7] + 600 data[0]*data[14]*data[7] + 601 data[4]*data[2]*data[15] - 602 data[0]*data[6]*data[15]) * det; 603 604 dstData[10] = (data[4]*data[13]*data[3] - 605 data[12]*data[5]*data[3] + 606 data[12]*data[1]*data[7] - 607 data[0]*data[13]*data[7] - 608 data[4]*data[1]*data[15] + 609 data[0]*data[5]*data[15]) * det; 610 611 dstData[14] = (data[12]*data[5]*data[2] - 612 data[4]*data[13]*data[2] - 613 data[12]*data[1]*data[6] + 614 data[0]*data[13]*data[6] + 615 data[4]*data[1]*data[14] - 616 data[0]*data[5]*data[14]) * det; 617 618 dstData[3] = (data[9]*data[6]*data[3] - 619 data[5]*data[10]*data[3] - 620 data[9]*data[2]*data[7] + 621 data[1]*data[10]*data[7] + 622 data[5]*data[2]*data[11] - 623 data[1]*data[6]*data[11]) * det; 624 625 dstData[7] = (data[4]*data[10]*data[3] - 626 data[8]*data[6]*data[3] + 627 data[8]*data[2]*data[7] - 628 data[0]*data[10]*data[7] - 629 data[4]*data[2]*data[11] + 630 data[0]*data[6]*data[11]) * det; 631 632 dstData[11] = (data[8]*data[5]*data[3] - 633 data[4]*data[9]*data[3] - 634 data[8]*data[1]*data[7] + 635 data[0]*data[9]*data[7] + 636 data[4]*data[1]*data[11] - 637 data[0]*data[5]*data[11]) * det; 638 639 dstData[15] = (data[4]*data[9]*data[2] - 640 data[8]*data[5]*data[2] + 641 data[8]*data[1]*data[6] - 642 data[0]*data[9]*data[6] - 643 data[4]*data[1]*data[10] + 644 data[0]*data[5]*data[10]) * det; 645 646 set(dstData); 507 if (&mat == this) { 508 invert(); 509 } else { 510 invertFast(mat); 511 } 647 512 } 648 513 … … 921 786 void Matrix4x4d::transpose(const Matrix4x4d& mat) 922 787 { 923 double m[16]; 924 925 m[0] = mat._data[0]; 926 m[1] = mat._data[4]; 927 m[2] = mat._data[8]; 928 m[3] = mat._data[12]; 929 930 m[4] = mat._data[1]; 931 m[5] = mat._data[5]; 932 m[6] = mat._data[9]; 933 m[7] = mat._data[13]; 934 935 m[8] = mat._data[2]; 936 m[9] = mat._data[6]; 937 m[10] = mat._data[10]; 938 m[11] = mat._data[14]; 939 940 m[12] = mat._data[3]; 941 m[13] = mat._data[7]; 942 m[14] = mat._data[11]; 943 m[15] = mat._data[15]; 944 945 set(m); 788 if (&mat == this) { 789 transpose(); 790 } else { 791 transposeFast(mat); 792 } 946 793 } 947 794 -
trunk/packages/vizservers/nanovis/vrmath/include/vrmath/BBox.h
r3628 r3630 111 111 } 112 112 113 inline Vector3f 113 inline Vector3f BBox::getSize() const 114 114 { 115 115 Vector3f temp;
Note: See TracChangeset
for help on using the changeset viewer.