Add perspective projection for VolumePro VP1000
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
Recent versions (>= 3.1) of the VolumePro VP1000 SDK support perspective projection but the vtkVolumeProVP1000Mapper always forces parallel projection.
The following patch adds a runtime check to vtkVolumeProVP1000Mapper::UpdateCamera() and, if using the 3.1 or later library, sets up a perspective projection matrix.
The patch was computed with
diff -Naur vtkVolumeProVP1000Mapper.cxx vtkVolumeProVP1000Mapper.cxx.new
where vtkVolumeProVP1000Mapper.cxx is version 1.27 from CVS.
--- vtkVolumeProVP1000Mapper.cxx Tue May 18 17:35:37 2004 +++ vtkVolumeProVP1000Mapper.cxx.new Tue May 18 17:53:31 2004 @@ -34,6 +34,9 @@
#include <stdio.h> #include <math.h> +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif
vtkCxxRevisionMacro(vtkVolumeProVP1000Mapper, "$Revision: 1.27 $");
@@ -217,12 +220,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 +230,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 so
- // force parallel projection in that case.
- int vliMajorRevision = VLIConfiguration::GetVLIMajorVersion();
- if (vliMajorRevision < 3 ||
-
(vliMajorRevision == 3 && VLIConfiguration::GetVLIMinorVersion() < 1))
-
{
-
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 ) {