vtkOpenGLImageSliceMapper.h 4.65 KB
Newer Older
1 2 3
/*=========================================================================

  Program:   Visualization Toolkit
4
  Module:    vtkOpenGLImageSliceMapper.h
5 6 7 8 9 10 11 12 13 14

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

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

=========================================================================*/
15
// .NAME vtkOpenGLImageSliceMapper - OpenGL mapper for image slice display
16
// .SECTION Description
17
// vtkOpenGLImageSliceMapper is a concrete implementation of the abstract
18 19 20 21 22
// class vtkImageSliceMapper that interfaces to the OpenGL library.
// .SECTION Thanks
// Thanks to David Gobbi at the Seaman Family MR Centre and Dept. of Clinical
// Neurosciences, Foothills Medical Centre, Calgary, for providing this class.

23 24
#ifndef vtkOpenGLImageSliceMapper_h
#define vtkOpenGLImageSliceMapper_h
25 26 27 28 29

#include "vtkRenderingOpenGL2Module.h" // For export macro
#include "vtkImageSliceMapper.h"

class vtkRenderWindow;
30
class vtkOpenGLRenderWindow;
31
class vtkActor;
32

33
class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLImageSliceMapper :
34 35 36
  public vtkImageSliceMapper
{
public:
37 38
  static vtkOpenGLImageSliceMapper *New();
  vtkTypeMacro(vtkOpenGLImageSliceMapper, vtkImageSliceMapper);
39 40 41 42 43 44 45 46 47 48 49 50 51
  virtual void PrintSelf(ostream& os, vtkIndent indent);

  // Description:
  // Implement base class method.  Perform the render.
  void Render(vtkRenderer *ren, vtkImageSlice *prop);

  // Description:
  // Release any graphics resources that are being consumed by this
  // mapper, the image texture in particular. Using the same texture
  // in multiple render windows is NOT currently supported.
  void ReleaseGraphicsResources(vtkWindow *);

protected:
52 53
  vtkOpenGLImageSliceMapper();
  ~vtkOpenGLImageSliceMapper();
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72

  // Description:
  // Recursive internal method, will call the non-recursive method
  // as many times as necessary if the texture must be broken up into
  // pieces that are small enough for the GPU to render
  void RecursiveRenderTexturedPolygon(
    vtkRenderer *ren, vtkImageProperty *property,
    vtkImageData *image, int extent[6], bool recursive);

  // Description:
  // Non-recursive internal method, generate a single texture
  // and its corresponding geometry.
  void RenderTexturedPolygon(
    vtkRenderer *ren, vtkImageProperty *property,
    vtkImageData *image, int extent[6], bool recursive);

  // Description:
  // Basic polygon rendering, if the textured parameter is set the tcoords
  // are included, otherwise they aren't.
73
  void RenderPolygon(vtkActor *actor, vtkPoints *points, const int extent[6], vtkRenderer *ren);
74 75 76 77 78

  // Description:
  // Render the background, which means rendering everything within the
  // plane of the image except for the polygon that displays the image data.
  void RenderBackground(
79
    vtkActor *actor, vtkPoints *points, const int extent[6], vtkRenderer *ren);
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105

  // Description:
  // Bind the fragment program, and generate it first if necessary.
  void BindFragmentProgram(vtkRenderer *ren, vtkImageProperty *property);

  // Description:
  // Build the fragment program to use with the texture.
  vtkStdString BuildFragmentProgram(vtkImageProperty *property);

  // Description:
  // Given an extent that describes a slice (it must have unit thickness
  // in one of the three directions), return the dimension indices that
  // correspond to the texture "x" and "y", provide the x, y image size,
  // and provide the texture size (padded to a power of two if the hardware
  // requires).
  void ComputeTextureSize(
    const int extent[6], int &xdim, int &ydim,
    int imageSize[2], int textureSize[2]);

  // Description:
  // Test whether a given texture size is supported.  This includes a
  // check of whether the texture will fit into texture memory.
  bool TextureSizeOK(const int size[2]);

  // Description:
  // Check various OpenGL capabilities
106
  void CheckOpenGLCapabilities(vtkOpenGLRenderWindow *renWin);
107 108 109 110 111 112 113 114

  long FragmentShaderIndex; // OpenGL ID for fragment shader
  vtkRenderWindow *RenderWindow; // RenderWindow used for previous render
  int TextureSize[2];
  int TextureBytesPerPixel;
  int LastOrientation;
  int LastSliceNumber;

115 116 117 118
  vtkActor *PolyDataActor;
  vtkActor *BackingPolyDataActor;
  vtkActor *BackgroundPolyDataActor;

119 120 121 122 123 124 125
  vtkTimeStamp LoadTime;
  int LoadCount;

  bool UseClampToEdge;
  bool UseFragmentProgram;

private:
126 127
  vtkOpenGLImageSliceMapper(const vtkOpenGLImageSliceMapper&);  // Not implemented.
  void operator=(const vtkOpenGLImageSliceMapper&);  // Not implemented.
128 129 130
};

#endif