--- vtkVolumeProVP1000Mapper.cxx Wed May 19 10:47:51 2004 +++ vtkVolumeProVP1000Mapper.cxx.new Fri Aug 27 21:43:47 2004 @@ -33,7 +33,11 @@ #include "vtkVolumeProperty.h" #include +#include #include +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif vtkCxxRevisionMacro(vtkVolumeProVP1000Mapper, "$Revision: 1.27 $"); @@ -217,12 +221,6 @@ ren->GetActiveCamera()->GetFocalPoint( focalPointVTK ); ren->GetActiveCamera()->GetViewUp( viewUpVTK ); - // make sure we are in parallel mode - if (!ren->GetActiveCamera()->GetParallelProjection()) - { - vtkWarningMacro("The Volume Pro VP1000 does not support perspective projection and the camera is currently not in ParallelProjection mode."); - } - // Create the three vectors we need to do the lookat VLIVector3D positionVLI ( positionVTK ); VLIVector3D focalPointVLI ( focalPointVTK ); @@ -233,20 +231,61 @@ viewUpVLI ); status = this->Context->GetCamera().SetViewMatrix( viewMatrixVLI ); - double clippingRange[2], parallelScale; + int setupParallel = ren->GetActiveCamera()->GetParallelProjection(); + double clippingRange[2]; double aspect[2]; ren->GetActiveCamera()->GetClippingRange(clippingRange); ren->GetAspect(aspect); - parallelScale = ren->GetActiveCamera()->GetParallelScale(); - VLIMatrix projectionMatrixVLI = VLIMatrix::Ortho(-parallelScale*aspect[0], - parallelScale*aspect[0], - -parallelScale, - parallelScale, - clippingRange[0], - clippingRange[1]); + if (! setupParallel) + { + // VLI versions prior to 3.1.0 do not support perspective projection + // and later versions only do so if the library has advanced features + // enabled. Can test for whether or not advanced features are enabled + // by looking for an AF in the library version string. If the system + // does not support perspective projection, force parallel projection. + if (strstr(VLIConfiguration::GetVersionString(VLIConfiguration::kVLIVersion), "AF") == 0) + { + setupParallel = 1; + vtkWarningMacro("The Volume Pro VP1000 does not support perspective projection and the camera is currently not in ParallelProjection mode."); + } + } + + if (! setupParallel) + { + double viewAngleRadians = ren->GetActiveCamera()->GetViewAngle() * + M_PI / 180.0; + + // Manually construct the matrix to avoid using VLIMatrix::Perspective() + // which is not available in VLI versions prior to 3.1.0. + VLIMatrix projectionMatrixVLI; + double f = cos(0.5 * viewAngleRadians) / sin(0.5 * viewAngleRadians); + + projectionMatrixVLI[0][0] = f / aspect[0]; + projectionMatrixVLI[1][1] = f; + projectionMatrixVLI[2][2] = (clippingRange[1] + clippingRange[0]) / + (clippingRange[0] - clippingRange[1]); + projectionMatrixVLI[2][3] = 2.0 * clippingRange[1] * clippingRange[0] / + (clippingRange[0] - clippingRange[1]); + projectionMatrixVLI[3][2] = -1.0; + projectionMatrixVLI[3][3] = 0.0; + + status = this->Context->GetCamera().SetProjectionMatrix( projectionMatrixVLI ); + } + + if (setupParallel) + { + double parallelScale = ren->GetActiveCamera()->GetParallelScale(); + + VLIMatrix projectionMatrixVLI = VLIMatrix::Ortho(-parallelScale*aspect[0], + parallelScale*aspect[0], + -parallelScale, + parallelScale, + clippingRange[0], + clippingRange[1]); - status = this->Context->GetCamera().SetProjectionMatrix( projectionMatrixVLI ); + status = this->Context->GetCamera().SetProjectionMatrix( projectionMatrixVLI ); + } if ( status != kVLIOK ) {