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
|
/*=========================================================================
Program: Visualization Toolkit
Module: $RCSfile: vtkImageInPlaceFilter.cxx,v $
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 "vtkImageInPlaceFilter.h"
#include "vtkImageData.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkLargeInteger.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkStreamingDemandDrivenPipeline.h"
vtkCxxRevisionMacro(vtkImageInPlaceFilter, "$Revision: 1.45 $");
//----------------------------------------------------------------------------
vtkImageInPlaceFilter::vtkImageInPlaceFilter()
{
}
//----------------------------------------------------------------------------
vtkImageInPlaceFilter::~vtkImageInPlaceFilter()
{
}
//----------------------------------------------------------------------------
int vtkImageInPlaceFilter::RequestData(
vtkInformation* vtkNotUsed( request ),
vtkInformationVector** inputVector,
vtkInformationVector* outputVector)
{
// get the data object
vtkInformation *outInfo = outputVector->GetInformationObject(0);
vtkImageData *output =
vtkImageData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
vtkImageData *input =
vtkImageData::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
int *inExt, *outExt;
inExt = inInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_EXTENT());
outExt = outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_EXTENT());
// if the total size of the data is the same then can be in place
vtkLargeInteger inSize;
vtkLargeInteger outSize;
inSize = (inExt[1] - inExt[0] + 1);
inSize = inSize * (inExt[3] - inExt[2] + 1);
inSize = inSize * (inExt[5] - inExt[4] + 1);
outSize = (outExt[1] - outExt[0] + 1);
outSize = outSize * (outExt[3] - outExt[2] + 1);
outSize = outSize * (outExt[5] - outExt[4] + 1);
if (inSize == outSize &&
this->GetInput()->ShouldIReleaseData())
{
// pass the data
output->GetPointData()->PassData(input->GetPointData());
output->SetExtent(outExt);
}
else
{
output->SetExtent(outExt);
output->AllocateScalars();
this->CopyData(input,output);
}
return 1;
}
void vtkImageInPlaceFilter::CopyData(vtkImageData *inData,
vtkImageData *outData)
{
int *outExt = this->GetOutput()->GetUpdateExtent();
char *inPtr = (char *) inData->GetScalarPointerForExtent(outExt);
char *outPtr = (char *) outData->GetScalarPointerForExtent(outExt);
int rowLength, size;
vtkIdType inIncX, inIncY, inIncZ;
vtkIdType outIncX, outIncY, outIncZ;
int idxY, idxZ, maxY, maxZ;
rowLength = (outExt[1] - outExt[0]+1)*inData->GetNumberOfScalarComponents();
size = inData->GetScalarSize();
rowLength *= size;
maxY = outExt[3] - outExt[2];
maxZ = outExt[5] - outExt[4];
// Get increments to march through data
inData->GetContinuousIncrements(outExt, inIncX, inIncY, inIncZ);
outData->GetContinuousIncrements(outExt, outIncX, outIncY, outIncZ);
// adjust increments for this loop
inIncY = inIncY*size + rowLength;
outIncY = outIncY*size + rowLength;
inIncZ *= size;
outIncZ *= size;
// Loop through ouput pixels
for (idxZ = 0; idxZ <= maxZ; idxZ++)
{
for (idxY = 0; idxY <= maxY; idxY++)
{
memcpy(outPtr,inPtr,rowLength);
outPtr += outIncY;
inPtr += inIncY;
}
outPtr += outIncZ;
inPtr += inIncZ;
}
}
//----------------------------------------------------------------------------
void vtkImageInPlaceFilter::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
}
|