Skip to content
Snippets Groups Projects
Commit b0deaa4d authored by Sankhesh Jhaveri's avatar Sankhesh Jhaveri :speech_balloon:
Browse files

Make vtkPixelTransfer available to a broader range of modules

parent 1d7ae9e7
No related branches found
No related tags found
No related merge requests found
......@@ -116,6 +116,7 @@ set(Module_SRCS
vtkPiecewiseFunction.cxx
vtkPixel.cxx
vtkPixelExtent.cxx
vtkPixelTransfer.cxx
vtkPlaneCollection.cxx
vtkPlane.cxx
vtkPlanes.cxx
......@@ -268,6 +269,7 @@ set_source_files_properties(
vtkImageIterator
vtkImageProgressIterator
vtkPixelExtent.cxx
vtkPixelTransfer.cxx
vtkVector
vtkColor
vtkRect
......
......@@ -26,12 +26,12 @@
#ifndef vtkPixelTransfer_h
#define vtkPixelTransfer_h
#include "vtkRenderingLICModule.h" // for export
#include "vtkCommonDataModelModule.h" // for export
#include "vtkSetGet.h" // for macros
#include "vtkPixelExtent.h" // for pixel extent
#include <cstring> // for memcpy
class VTKRENDERINGLIC_EXPORT vtkPixelTransfer
class VTKCOMMONDATAMODEL_EXPORT vtkPixelTransfer
{
public:
vtkPixelTransfer(){}
......
set(Module_SRCS
vtkImageDataLIC2D.cxx
vtkLineIntegralConvolution2D.cxx
vtkPixelTransfer.cxx
vtkStructuredGridLIC2D.cxx
vtkSurfaceLICComposite.cxx
vtkSurfaceLICDefaultPainter.cxx
......@@ -12,7 +11,6 @@ set(Module_SRCS
set_source_files_properties(
vtkLineIntegralConvolution2D.cxx
vtkPainterCommunicator.cxx
vtkPixelTransfer.cxx
vtkSurfaceLICComposite.cxx
vtkTextureIO.cxx
WRAP_EXCLUDE
......
set(Module_SRCS
vtkImageDataLIC2D.cxx
vtkLineIntegralConvolution2D.cxx
vtkPixelTransfer.cxx
vtkStructuredGridLIC2D.cxx
vtkSurfaceLICComposite.cxx
vtkSurfaceLICMapper.cxx
......@@ -11,7 +10,6 @@ set(Module_SRCS
set_source_files_properties(
vtkLineIntegralConvolution2D.cxx
vtkPixelTransfer.cxx
vtkSurfaceLICComposite.cxx
vtkTextureIO.cxx
WRAP_EXCLUDE
......
#include "vtkPixelTransfer.h"
//-----------------------------------------------------------------------------
int vtkPixelTransfer::Blit(
const vtkPixelExtent &srcWholeExt,
const vtkPixelExtent &srcExt,
const vtkPixelExtent &destWholeExt,
const vtkPixelExtent &destExt,
int nSrcComps,
int srcType,
void *srcData,
int nDestComps,
int destType,
void *destData)
{
// first layer of dispatch
switch(srcType)
{
vtkTemplateMacro(
return vtkPixelTransfer::Blit(
srcWholeExt,
srcExt,
destWholeExt,
destExt,
nSrcComps,
(VTK_TT*)srcData,
nDestComps,
destType,
destData));
}
return 0;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPixelTransfer.h
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.
=========================================================================*/
// .NAME vtkPixelTransfer -- For movement of pixel data described by
// pixel extents
//
// .SECTION Description
// Class to handle non-contiguous data transfers of data described
// by pixel extents within a process. For transfering data between
// processes see vtkPPixelTransfer.
//
// .SECTION See also
// vtkPixelExtent vtkPPixelTransfer
#ifndef vtkPixelTransfer_h
#define vtkPixelTransfer_h
#include "vtkRenderingLICOpenGL2Module.h" // for export
#include "vtkSetGet.h" // for macros
#include "vtkPixelExtent.h" // for pixel extent
#include <cstring> // for memcpy
class VTKRENDERINGLICOPENGL2_EXPORT vtkPixelTransfer
{
public:
vtkPixelTransfer(){}
~vtkPixelTransfer(){}
// Description:
// for memory to memory transfers. Conveinience api for working
// with vtk type enum rather than c-data types and simple extents.
static
int Blit(
const vtkPixelExtent &ext,
int nComps,
int srcType,
void *srcData,
int destType,
void *destData);
// Description:
// for memory to memory transfers. Conveinience api for working
// with vtk type enum rather than c-data types.
static
int Blit(
const vtkPixelExtent &srcWhole,
const vtkPixelExtent &srcSubset,
const vtkPixelExtent &destWhole,
const vtkPixelExtent &destSubset,
int nSrcComps,
int srcType,
void *srcData,
int nDestComps,
int destType,
void *destData);
// Description:
// for local memory to memory transfers
template<typename SOURCE_TYPE, typename DEST_TYPE>
static
int Blit(
const vtkPixelExtent &srcWhole,
const vtkPixelExtent &srcSubset,
const vtkPixelExtent &destWhole,
const vtkPixelExtent &destSubset,
int nSrcComps,
SOURCE_TYPE *srcData,
int nDestComps,
DEST_TYPE *destData);
private:
// distpatch helper for vtk data type enum
template<typename SOURCE_TYPE>
static
int Blit(
const vtkPixelExtent &srcWhole,
const vtkPixelExtent &srcSubset,
const vtkPixelExtent &destWhole,
const vtkPixelExtent &destSubset,
int nSrcComps,
SOURCE_TYPE *srcData,
int nDestComps,
int destType,
void *destData);
};
//-----------------------------------------------------------------------------
inline
int vtkPixelTransfer::Blit(
const vtkPixelExtent &ext,
int nComps,
int srcType,
void *srcData,
int destType,
void *destData)
{
return vtkPixelTransfer::Blit(
ext,
ext,
ext,
ext,
nComps,
srcType,
srcData,
nComps,
destType,
destData);
}
//-----------------------------------------------------------------------------
template<typename SOURCE_TYPE>
int vtkPixelTransfer::Blit(
const vtkPixelExtent &srcWholeExt,
const vtkPixelExtent &srcExt,
const vtkPixelExtent &destWholeExt,
const vtkPixelExtent &destExt,
int nSrcComps,
SOURCE_TYPE *srcData,
int nDestComps,
int destType,
void *destData)
{
// second layer of dispatch
switch(destType)
{
vtkTemplateMacro(
return vtkPixelTransfer::Blit(
srcWholeExt,
srcExt,
destWholeExt,
destExt,
nSrcComps,
srcData,
nDestComps,
(VTK_TT*)destData););
}
return 0;
}
//-----------------------------------------------------------------------------
template<typename SOURCE_TYPE, typename DEST_TYPE>
int vtkPixelTransfer::Blit(
const vtkPixelExtent &srcWholeExt,
const vtkPixelExtent &srcSubset,
const vtkPixelExtent &destWholeExt,
const vtkPixelExtent &destSubset,
int nSrcComps,
SOURCE_TYPE *srcData,
int nDestComps,
DEST_TYPE *destData)
{
if ( (srcData == NULL) || (destData == NULL) )
{
return -1;
}
if ( (srcWholeExt == srcSubset)
&& (destWholeExt == destSubset)
&& (nSrcComps == nDestComps) )
{
// buffers are contiguous
size_t n = srcWholeExt.Size()*nSrcComps;
for (size_t i=0; i<n; ++i)
{
destData[i] = static_cast<DEST_TYPE>(srcData[i]);
}
}
else
{
// buffers are not contiguous
int tmp[2];
// get the dimensions of the arrays
srcWholeExt.Size(tmp);
int swnx = tmp[0];
destWholeExt.Size(tmp);
int dwnx = tmp[0];
// move from logical extent to memory extent
vtkPixelExtent srcExt(srcSubset);
srcExt.Shift(srcWholeExt);
vtkPixelExtent destExt(destSubset);
destExt.Shift(destWholeExt);
// get size of sub-set to copy (it's the same in src and dest)
int nxny[2];
srcExt.Size(nxny);
// use smaller ncomps for loop index to avoid reading/writing
// invalid mem
int nCopyComps = nSrcComps < nDestComps ? nSrcComps : nDestComps;
for (int j=0; j<nxny[1]; ++j)
{
int sjj = swnx*(srcExt[2]+j)+srcExt[0];
int djj = dwnx*(destExt[2]+j)+destExt[0];
for (int i=0; i<nxny[0]; ++i)
{
int sidx = nSrcComps*(sjj+i);
int didx = nDestComps*(djj+i);
// copy values from source
for (int p=0; p<nCopyComps; ++p)
{
destData[didx+p] = static_cast<DEST_TYPE>(srcData[sidx+p]);
}
// ensure all dest comps are initialized
for (int p=nCopyComps; p<nDestComps; ++p)
{
destData[didx+p] = static_cast<DEST_TYPE>(0);
}
}
}
}
return 0;
}
ostream &operator<<(ostream &os, const vtkPixelTransfer &gt);
#endif
// VTK-HeaderTest-Exclude: vtkPixelTransfer.h
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment