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 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkImageMapper.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 "vtkImageMapper.h"
#include "vtkActor2D.h"
#include "vtkExecutive.h"
#include "vtkImageData.h"
#include "vtkObjectFactory.h"
#include "vtkInformation.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkViewport.h"
#include "vtkWindow.h"
//----------------------------------------------------------------------------
// Return NULL if no override is supplied.
vtkAbstractObjectFactoryNewMacro(vtkImageMapper)
//----------------------------------------------------------------------------
vtkImageMapper::vtkImageMapper()
{
vtkDebugMacro(<< "vtkImageMapper::vtkImageMapper" );
this->ColorWindow = 2000;
this->ColorLevel = 1000;
this->DisplayExtent[0] = this->DisplayExtent[1] = 0;
this->DisplayExtent[2] = this->DisplayExtent[3] = 0;
this->DisplayExtent[4] = this->DisplayExtent[5] = 0;
this->ZSlice = 0;
this->RenderToRectangle = 0;
this->UseCustomExtents = 0;
this->CustomDisplayExtents[0] = this->CustomDisplayExtents[1] = 0;
this->CustomDisplayExtents[2] = this->CustomDisplayExtents[3] = 0;
}
vtkImageMapper::~vtkImageMapper()
{
}
//----------------------------------------------------------------------------
void vtkImageMapper::SetInputData(vtkImageData *input)
{
this->SetInputDataInternal(0, input);
}
//----------------------------------------------------------------------------
vtkImageData *vtkImageMapper::GetInput()
{
if (this->GetNumberOfInputConnections(0) < 1)
{
return 0;
}
return vtkImageData::SafeDownCast(
this->GetExecutive()->GetInputData(0, 0));
}
unsigned long int vtkImageMapper::GetMTime()
{
unsigned long mTime=this->vtkMapper2D::GetMTime();
return mTime;
}
void vtkImageMapper::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "Color Window: " << this->ColorWindow << "\n";
os << indent << "Color Level: " << this->ColorLevel << "\n";
os << indent << "ZSlice: " << this->ZSlice << "\n";
os << indent << "RenderToRectangle: " << this->RenderToRectangle << "\n";
os << indent << "UseCustomExtents: " << this->UseCustomExtents << "\n";
os << indent << "CustomDisplayExtents: " <<
this->CustomDisplayExtents[0] << " " <<
this->CustomDisplayExtents[1] << " " <<
this->CustomDisplayExtents[2] << " " <<
this->CustomDisplayExtents[3] << "\n";
//
}
double vtkImageMapper::GetColorShift()
{
return this->ColorWindow /2.0 - this->ColorLevel;
}
double vtkImageMapper::GetColorScale()
{
return 255.0 / this->ColorWindow;
}
void vtkImageMapper::RenderStart(vtkViewport* viewport, vtkActor2D* actor)
{
vtkDebugMacro(<< "vtkImageMapper::RenderOverlay");
vtkImageData *data;
if (!viewport)
{
vtkErrorMacro (<< "vtkImageMapper::Render - Null viewport argument");
return;
}
if (!actor)
{
vtkErrorMacro (<<"vtkImageMapper::Render - Null actor argument");
return;
}
if (!this->GetInputAlgorithm())
{
vtkDebugMacro(<< "vtkImageMapper::Render - Please Set the input.");
return;
}
this->GetInputAlgorithm()->UpdateInformation();
vtkInformation* inInfo = this->GetInputInformation();
if (!this->UseCustomExtents)
{
// start with the wholeExtent
int wholeExtent[6];
inInfo->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), wholeExtent);
inInfo->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), this->DisplayExtent);
// Set The z values to the zslice
this->DisplayExtent[4] = this->ZSlice;
this->DisplayExtent[5] = this->ZSlice;
// scale currently not handled
//double *scale = actor->GetScale();
// get the position
int *pos =
actor->GetActualPositionCoordinate()->GetComputedViewportValue(viewport);
// Get the viewport coordinates
double vCoords[4];
vCoords[0] = 0.0;
vCoords[1] = 0.0;
vCoords[2] = 1.0;
vCoords[3] = 1.0;
viewport->NormalizedViewportToViewport(vCoords[0],vCoords[1]);
viewport->NormalizedViewportToViewport(vCoords[2],vCoords[3]);
int *vSize = viewport->GetSize();
// the basic formula is that the draw pos equals
// the pos + extentPos + clippedAmount
// The concrete subclass will get the pos in display
// coordinates so we need to provide the extentPos plus
// clippedAmount in the PositionAdjustment variable
// Now clip to imager extents
if (pos[0] + wholeExtent[0] < 0)
{
this->DisplayExtent[0] = -pos[0];
}
if ((pos[0]+wholeExtent[1]) > vSize[0])
{
this->DisplayExtent[1] = vSize[0] - pos[0];
}
if (pos[1] + wholeExtent[2] < 0)
{
this->DisplayExtent[2] = -pos[1];
}
if ((pos[1]+wholeExtent[3]) > vSize[1])
{
this->DisplayExtent[3] = vSize[1] - pos[1];
}
// check for the condition where no pixels are visible.
if (this->DisplayExtent[0] > wholeExtent[1] ||
this->DisplayExtent[1] < wholeExtent[0] ||
this->DisplayExtent[2] > wholeExtent[3] ||
this->DisplayExtent[3] < wholeExtent[2] ||
this->DisplayExtent[4] > wholeExtent[5] ||
this->DisplayExtent[5] < wholeExtent[4])
{
return;
}
vtkStreamingDemandDrivenPipeline::SetUpdateExtent(
this->GetInputInformation(), this->DisplayExtent);
// set the position adjustment
this->PositionAdjustment[0] = this->DisplayExtent[0];
this->PositionAdjustment[1] = this->DisplayExtent[2];
}
else // UseCustomExtents
{
this->DisplayExtent[0] = this->CustomDisplayExtents[0];
this->DisplayExtent[1] = this->CustomDisplayExtents[1];
this->DisplayExtent[2] = this->CustomDisplayExtents[2];
this->DisplayExtent[3] = this->CustomDisplayExtents[3];
this->DisplayExtent[4] = this->ZSlice;
this->DisplayExtent[5] = this->ZSlice;
//
vtkStreamingDemandDrivenPipeline::SetUpdateExtentToWholeExtent(
this->GetInputInformation());
// clear the position adjustment
this->PositionAdjustment[0] = 0;
this->PositionAdjustment[1] = 0;
}
// Get the region from the input
this->GetInputAlgorithm()->Update();
data = this->GetInput();
if ( !data)
{
vtkErrorMacro(<< "Render: Could not get data from input.");
return;
}
this->RenderData(viewport, data, actor);
}
//----------------------------------------------------------------------------
int vtkImageMapper::GetWholeZMin()
{
int *extent;
if ( ! this->GetInput())
{
return 0;
}
this->GetInputAlgorithm()->UpdateInformation();
extent = this->GetInputInformation()->Get(
vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT());
return extent[4];
}
//----------------------------------------------------------------------------
int vtkImageMapper::GetWholeZMax()
{
int *extent;
if ( ! this->GetInput())
{
return 0;
}
this->GetInputAlgorithm()->UpdateInformation();
extent = this->GetInputInformation()->Get(
vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT());
return extent[5];
}
//----------------------------------------------------------------------------
int vtkImageMapper::FillInputPortInformation(
int vtkNotUsed( port ), vtkInformation* info)
{
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkImageData");
return 1;
}
|