/*========================================================================= 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. =========================================================================*/ /** * @class vtkPixelTransfer * pixel extents * * * Class to handle non-contiguous data transfers of data described * by pixel extents within a process. For transferring data between * processes see vtkPPixelTransfer. * * @sa * vtkPixelExtent vtkPPixelTransfer */ #ifndef vtkPixelTransfer_h #define vtkPixelTransfer_h #include "vtkCommonDataModelModule.h" // for export #include "vtkSetGet.h" // for macros #include "vtkPixelExtent.h" // for pixel extent #include // for memcpy class VTKCOMMONDATAMODEL_EXPORT vtkPixelTransfer { public: vtkPixelTransfer(){} /** * 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); /** * 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); /** * for local memory to memory transfers */ template 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 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 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 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 == nullptr) || (destData == nullptr) ) { return -1; } if ( (srcWholeExt == srcSubset) && (destWholeExt == destSubset) && (nSrcComps == nDestComps) ) { // buffers are contiguous size_t n = srcWholeExt.Size()*nSrcComps; for (size_t i=0; i(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(srcData[sidx+p]); } // ensure all dest comps are initialized for (int p=nCopyComps; p(0); } } } } return 0; } #endif // VTK-HeaderTest-Exclude: vtkPixelTransfer.h