1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkFixedPointRayCastImage.cxx
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.
=========================================================================*/
#include "vtkFixedPointRayCastImage.h"
#include "vtkObjectFactory.h"
vtkStandardNewMacro(vtkFixedPointRayCastImage);
// Construct a new vtkFixedPointRayCastImage with default values
vtkFixedPointRayCastImage::vtkFixedPointRayCastImage()
{
this->ImageViewportSize[0] = 0;
this->ImageViewportSize[1] = 0;
this->ImageMemorySize[0] = 0;
this->ImageMemorySize[1] = 0;
this->ImageInUseSize[0] = 0;
this->ImageInUseSize[1] = 0;
this->ImageOrigin[0] = 0;
this->ImageOrigin[1] = 0;
this->ImageSampleDistance = 0;
this->ZBufferMemorySize = 0;
this->ZBufferSize[0] = 0;
this->ZBufferSize[1] = 0;
this->ZBufferOrigin[0] = 0;
this->ZBufferOrigin[1] = 0;
this->UseZBuffer = 0;
this->Image = NULL;
this->ZBuffer = NULL;
}
// Destruct a vtkFixedPointRayCastImage - clean up any memory used
vtkFixedPointRayCastImage::~vtkFixedPointRayCastImage()
{
delete [] this->Image;
delete [] this->ZBuffer;
}
// Allocate memory
void vtkFixedPointRayCastImage::AllocateImage()
{
delete [] this->Image;
this->Image = NULL;
if ( this->ImageMemorySize[0] > 0 &&
this->ImageMemorySize[1] > 0 )
{
this->Image = new unsigned short [ ( 4 *
this->ImageMemorySize[0] *
this->ImageMemorySize[1] )];
}
}
// Clear image to 0
void vtkFixedPointRayCastImage::ClearImage()
{
unsigned short *ucptr = this->Image;
for ( int i = 0; i < this->ImageMemorySize[0]*this->ImageMemorySize[1]; i++ )
{
*(ucptr++) = 0;
*(ucptr++) = 0;
*(ucptr++) = 0;
*(ucptr++) = 0;
}
}
void vtkFixedPointRayCastImage::AllocateZBuffer()
{
// If we already have a buffer big enough, don't
// bother to do anything
if ( this->ZBufferSize[0]*this->ZBufferSize[1] >
this->ZBufferMemorySize )
{
// If our current buffer is not large enough, delete it
delete [] this->ZBuffer;
this->ZBuffer = NULL;
// Try out a size equal to the viewport in pixels
this->ZBufferMemorySize =
this->ImageViewportSize[0] * this->ImageViewportSize[1];
// This shouldn't ever happen, but just in case....
// If this happens it means that somehow our viewport
// size in pixels is smaller than the zbuffer we are
// requesting - which will probably not make OpenGL
// very happy.
if ( this->ZBufferMemorySize <
this->ZBufferSize[0]*this->ZBufferSize[1] )
{
this->ZBufferMemorySize =
this->ZBufferSize[0] * this->ZBufferSize[1];
}
// Allocate the memory
this->ZBuffer = new float [this->ZBufferMemorySize];
}
}
float vtkFixedPointRayCastImage::GetZBufferValue(int x, int y)
{
if ( !this->UseZBuffer )
{
return 1.0;
}
int xPos, yPos;
xPos = static_cast<int>(static_cast<float>(x) * this->ImageSampleDistance);
yPos = static_cast<int>(static_cast<float>(y) * this->ImageSampleDistance);
xPos = (xPos >= this->ZBufferSize[0])?(this->ZBufferSize[0]-1):(xPos);
yPos = (yPos >= this->ZBufferSize[1])?(this->ZBufferSize[1]-1):(yPos);
return *(this->ZBuffer + yPos*this->ZBufferSize[0] + xPos);
}
void vtkFixedPointRayCastImage::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "Image Viewport Size: "
<< this->ImageViewportSize[0] << " "
<< this->ImageViewportSize[1] << endl;
os << indent << "Image Memory Size: "
<< this->ImageMemorySize[0] << " "
<< this->ImageMemorySize[1] << endl;
os << indent << "Image In Use Size: "
<< this->ImageInUseSize[0] << " "
<< this->ImageInUseSize[1] << endl;
os << indent << "Image Origin: "
<< this->ImageOrigin[0] << " "
<< this->ImageOrigin[1] << endl;
os << indent << "Image Sample Distance: "
<< this->ImageSampleDistance << endl;
os << indent << "Use ZBuffer: "
<< (this->UseZBuffer ? "On" : "Off") << endl;
os << indent << "ZBuffer Origin: "
<< this->ZBufferOrigin[0] << " "
<< this->ZBufferOrigin[1] << endl;
os << indent << "ZBuffer Size: "
<< this->ZBufferSize[0] << " "
<< this->ZBufferSize[1] << endl;
}
|