vtkVolumeRayCastFunction.cxx 5.18 KB
Newer Older
1 2 3 4 5
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkVolumeRayCastFunction.cxx

6
  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 8
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9

10 11
     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
     PURPOSE.  See the above copyright notice for more information.
13 14 15

=========================================================================*/
#include "vtkVolumeRayCastFunction.h"
16

17 18
#if !defined(VTK_LEGACY_REMOVE)

19 20
#include "vtkEncodedGradientEstimator.h"
#include "vtkEncodedGradientShader.h"
21
#include "vtkImageData.h"
22
#include "vtkVolume.h"
23
#include "vtkVolumeProperty.h"
24
#include "vtkVolumeRayCastMapper.h"
25

Brad King's avatar
Brad King committed
26

27
// Grab everything we need for rendering now. This procedure will be called
28
// during the initialization phase of ray casting. It is called once per
29 30 31
// image. All Gets are done here for both performance and multithreading
// reentrant requirements reasons. At the end, the SpecificFunctionInitialize
// is called to give the subclass a chance to do its thing.
32 33
void vtkVolumeRayCastFunction::FunctionInitialize(
                                vtkRenderer *ren,
34
                                vtkVolume *vol,
35
                                vtkVolumeRayCastStaticInfo *staticInfo )
36
{
37
  vtkVolumeRayCastMapper *mapper =
38
    vtkVolumeRayCastMapper::SafeDownCast( vol->GetMapper() );
39

40 41 42 43 44 45
  if ( !mapper )
    {
    vtkErrorMacro(
    "Function initialized called with a volume that does not use ray casting");
    return;
    }
46

47
  // Is shading on?
48
  staticInfo->Shading = vol->GetProperty()->GetShade();
49 50 51 52

  // How many color channels? Either 1 or 3. 1 means we have
  // to use the GrayTransferFunction, 3 means we use the
  // RGBTransferFunction
53
  staticInfo->ColorChannels = vol->GetProperty()->GetColorChannels();
54 55

  // What is the interpolation type? Nearest or linear.
56
  staticInfo->InterpolationType = vol->GetProperty()->GetInterpolationType();
57

58
  // Get the size, spacing and origin of the scalar data
59 60 61
  mapper->GetInput()->GetDimensions( staticInfo->DataSize );
  mapper->GetInput()->GetSpacing( staticInfo->DataSpacing );
  mapper->GetInput()->GetOrigin( staticInfo->DataOrigin );
62

63
  // What are the data increments?
64
  // (One voxel, one row, and one slice offsets)
65
  staticInfo->DataIncrement[0] = 1;
66 67 68
  staticInfo->DataIncrement[1] = static_cast<vtkIdType>(staticInfo->DataSize[0]);
  staticInfo->DataIncrement[2] = static_cast<vtkIdType>(staticInfo->DataSize[0])*
                                 static_cast<vtkIdType>(staticInfo->DataSize[1]);
69 70


71
  // Get the encoded normals from the normal encoder in the
72 73 74 75 76
  // volume ray cast mapper. We need to do this if shading is on
  // or if we are classifying scalar value into opacity based
  // on the magnitude of the gradient (since if we need to
  // calculate the magnitude we might as well just keep the
  // direction as well.
77
  if ( staticInfo->Shading )
78
    {
79
    staticInfo->EncodedNormals =
80 81 82 83
      mapper->GetGradientEstimator()->GetEncodedNormals();

    // Get the diffuse shading tables from the normal encoder
    // in the volume ray cast mapper
84
    staticInfo->RedDiffuseShadingTable =
85
      mapper->GetGradientShader()->GetRedDiffuseShadingTable(vol);
86
    staticInfo->GreenDiffuseShadingTable =
87
      mapper->GetGradientShader()->GetGreenDiffuseShadingTable(vol);
88
    staticInfo->BlueDiffuseShadingTable =
89
      mapper->GetGradientShader()->GetBlueDiffuseShadingTable(vol);
90

91 92
    // Get the specular shading tables from the normal encoder
    // in the volume ray cast mapper
93
    staticInfo->RedSpecularShadingTable =
94
      mapper->GetGradientShader()->GetRedSpecularShadingTable(vol);
95
    staticInfo->GreenSpecularShadingTable =
96
      mapper->GetGradientShader()->GetGreenSpecularShadingTable(vol);
97
    staticInfo->BlueSpecularShadingTable =
98
      mapper->GetGradientShader()->GetBlueSpecularShadingTable(vol);
99 100 101
    }
  else
    {
102 103 104 105 106 107 108
    staticInfo->EncodedNormals            = NULL;
    staticInfo->RedDiffuseShadingTable    = NULL;
    staticInfo->GreenDiffuseShadingTable  = NULL;
    staticInfo->BlueDiffuseShadingTable   = NULL;
    staticInfo->RedSpecularShadingTable   = NULL;
    staticInfo->GreenSpecularShadingTable = NULL;
    staticInfo->BlueSpecularShadingTable  = NULL;
109 110 111 112
    }

  // We need the gradient magnitudes only if we are classifying opacity
  // based on them. Otherwise we can just leave them NULL
113
  if ( vol->GetGradientOpacityArray() &&
114
       vol->GetGradientOpacityConstant() == -1.0 )
115
    {
116
    staticInfo->GradientMagnitudes =
117 118 119 120
      mapper->GetGradientEstimator()->GetGradientMagnitudes();
    }
  else
    {
121
    staticInfo->GradientMagnitudes = NULL;
122
    }
123

124 125 126
  // By default the blending is not MIP - the MIP function will turn this
  // on
  staticInfo->MIPFunction = 0;
127

128 129
  // Give the subclass a chance to do any initialization it needs
  // to do
130
  this->SpecificFunctionInitialize( ren, vol, staticInfo, mapper );
131 132
}

Andy Cedilnik's avatar
Andy Cedilnik committed
133 134 135 136 137
//----------------------------------------------------------------------------
void vtkVolumeRayCastFunction::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os,indent);
}
138 139

#endif // VTK_LEGACY_REMOVE