VTK
dox
opt
build
vtk6-6.3.0+dfsg2
Rendering
LIC
vtkPixelTransfer.h
Go to the documentation of this file.
1
/*=========================================================================
2
3
Program: Visualization Toolkit
4
Module: vtkPixelTransfer.h
5
6
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7
All rights reserved.
8
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10
This software is distributed WITHOUT ANY WARRANTY; without even
11
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
PURPOSE. See the above copyright notice for more information.
13
14
=========================================================================*/
27
#ifndef vtkPixelTransfer_h
28
#define vtkPixelTransfer_h
29
30
#include "
vtkRenderingLICModule.h
"
// for export
31
#include "
vtkSetGet.h
"
// for macros
32
#include "
vtkPixelExtent.h
"
// for pixel extent
33
#include <cstring>
// for memcpy
34
35
class
VTKRENDERINGLIC_EXPORT
vtkPixelTransfer
36
{
37
public
:
38
vtkPixelTransfer
(){}
39
~vtkPixelTransfer
(){}
40
42
44
static
45
int
Blit(
46
const
vtkPixelExtent
&ext,
47
int
nComps,
48
int
srcType,
49
void
*srcData,
50
int
destType,
51
void
*destData);
53
55
57
static
58
int
Blit
(
59
const
vtkPixelExtent
&srcWhole,
60
const
vtkPixelExtent
&srcSubset,
61
const
vtkPixelExtent
&destWhole,
62
const
vtkPixelExtent
&destSubset,
63
int
nSrcComps,
64
int
srcType,
65
void
*srcData,
66
int
nDestComps,
67
int
destType,
68
void
*destData);
70
72
73
template
<
typename
SOURCE_TYPE,
typename
DEST_TYPE>
74
static
75
int
Blit(
76
const
vtkPixelExtent
&srcWhole,
77
const
vtkPixelExtent
&srcSubset,
78
const
vtkPixelExtent
&destWhole,
79
const
vtkPixelExtent
&destSubset,
80
int
nSrcComps,
81
SOURCE_TYPE *srcData,
82
int
nDestComps,
83
DEST_TYPE *destData);
85
86
private
:
87
// distpatch helper for vtk data type enum
88
template
<
typename
SOURCE_TYPE>
89
static
90
int
Blit(
91
const
vtkPixelExtent
&srcWhole,
92
const
vtkPixelExtent
&srcSubset,
93
const
vtkPixelExtent
&destWhole,
94
const
vtkPixelExtent
&destSubset,
95
int
nSrcComps,
96
SOURCE_TYPE *srcData,
97
int
nDestComps,
98
int
destType,
99
void
*destData);
100
};
101
102
//-----------------------------------------------------------------------------
103
inline
104
int
vtkPixelTransfer::Blit
(
105
const
vtkPixelExtent
&ext,
106
int
nComps,
107
int
srcType,
108
void
*srcData,
109
int
destType,
110
void
*destData)
111
{
112
return
vtkPixelTransfer::Blit
(
113
ext,
114
ext,
115
ext,
116
ext,
117
nComps,
118
srcType,
119
srcData,
120
nComps,
121
destType,
122
destData);
123
}
124
125
126
//-----------------------------------------------------------------------------
127
template
<
typename
SOURCE_TYPE>
128
int
vtkPixelTransfer::Blit
(
129
const
vtkPixelExtent
&srcWholeExt,
130
const
vtkPixelExtent
&srcExt,
131
const
vtkPixelExtent
&destWholeExt,
132
const
vtkPixelExtent
&destExt,
133
int
nSrcComps,
134
SOURCE_TYPE *srcData,
135
int
nDestComps,
136
int
destType,
137
void
*destData)
138
{
139
// second layer of dispatch
140
switch
(destType)
141
{
142
vtkTemplateMacro
(
143
return
vtkPixelTransfer::Blit
(
144
srcWholeExt,
145
srcExt,
146
destWholeExt,
147
destExt,
148
nSrcComps,
149
srcData,
150
nDestComps,
151
(VTK_TT*)destData););
152
}
153
return
0;
154
}
155
156
//-----------------------------------------------------------------------------
157
template
<
typename
SOURCE_TYPE,
typename
DEST_TYPE>
158
int
vtkPixelTransfer::Blit
(
159
const
vtkPixelExtent
&srcWholeExt,
160
const
vtkPixelExtent
&srcSubset,
161
const
vtkPixelExtent
&destWholeExt,
162
const
vtkPixelExtent
&destSubset,
163
int
nSrcComps,
164
SOURCE_TYPE *srcData,
165
int
nDestComps,
166
DEST_TYPE *destData)
167
{
168
if
( (srcData == NULL) || (destData == NULL) )
169
{
170
return
-1;
171
}
172
if
( (srcWholeExt == srcSubset)
173
&& (destWholeExt == destSubset)
174
&& (nSrcComps == nDestComps) )
175
{
176
// buffers are contiguous
177
size_t
n
= srcWholeExt.
Size
()*nSrcComps;
178
for
(
size_t
i=0; i<
n
; ++i)
179
{
180
destData[i] =
static_cast<
DEST_TYPE
>
(srcData[i]);
181
}
182
}
183
else
184
{
185
// buffers are not contiguous
186
int
tmp[2];
187
188
// get the dimensions of the arrays
189
srcWholeExt.
Size
(tmp);
190
int
swnx = tmp[0];
191
192
destWholeExt.
Size
(tmp);
193
int
dwnx = tmp[0];
194
195
// move from logical extent to memory extent
196
vtkPixelExtent
srcExt(srcSubset);
197
srcExt.
Shift
(srcWholeExt);
198
199
vtkPixelExtent
destExt(destSubset);
200
destExt.
Shift
(destWholeExt);
201
202
// get size of sub-set to copy (it's the same in src and dest)
203
int
nxny[2];
204
srcExt.
Size
(nxny);
205
206
// use smaller ncomps for loop index to avoid reading/writing
207
// invalid mem
208
int
nCopyComps = nSrcComps < nDestComps ? nSrcComps : nDestComps;
209
210
for
(
int
j=0; j<nxny[1]; ++j)
211
{
212
int
sjj = swnx*(srcExt[2]+j)+srcExt[0];
213
int
djj = dwnx*(destExt[2]+j)+destExt[0];
214
for
(
int
i=0; i<nxny[0]; ++i)
215
{
216
int
sidx = nSrcComps*(sjj+i);
217
int
didx = nDestComps*(djj+i);
218
// copy values from source
219
for
(
int
p
=0;
p
<nCopyComps; ++
p
)
220
{
221
destData[didx+
p
] =
static_cast<
DEST_TYPE
>
(srcData[sidx+
p
]);
222
}
223
// ensure all dest comps are initialized
224
for
(
int
p
=nCopyComps;
p
<nDestComps; ++
p
)
225
{
226
destData[didx+
p
] =
static_cast<
DEST_TYPE
>
(0);
227
}
228
}
229
}
230
}
231
return
0;
232
}
233
234
ostream &
operator<<
(ostream &os,
const
vtkPixelTransfer
>);
235
236
#endif
237
// VTK-HeaderTest-Exclude: vtkPixelTransfer.h
vtkPixelTransfer::Blit
static int Blit(const vtkPixelExtent &ext, int nComps, int srcType, void *srcData, int destType, void *destData)
Definition:
vtkPixelTransfer.h:104
vtkgl::n
GLclampd n
Definition:
vtkgl.h:14370
vtkSetGet.h
vtkRenderingLICModule.h
vtkPixelExtent::Shift
void Shift()
Definition:
vtkPixelExtent.h:603
vtkPixelExtent
Definition:
vtkPixelExtent.h:41
vtkPixelTransfer::~vtkPixelTransfer
~vtkPixelTransfer()
Definition:
vtkPixelTransfer.h:39
vtkTemplateMacro
#define vtkTemplateMacro(call)
Definition:
vtkSetGet.h:673
vtkPixelExtent.h
VTKRENDERINGLIC_EXPORT
#define VTKRENDERINGLIC_EXPORT
Definition:
vtkRenderingLICModule.h:15
vtkPixelTransfer::vtkPixelTransfer
vtkPixelTransfer()
Definition:
vtkPixelTransfer.h:38
vtkPixelTransfer::Blit
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)
vtkPixelExtent::Size
void Size(T nCells[2]) const
Definition:
vtkPixelExtent.h:369
vtkgl::p
GLfloat GLfloat p
Definition:
vtkgl.h:15717
operator<<
ostream & operator<<(ostream &os, const vtkPixelTransfer >)
vtkPixelTransfer
Definition:
vtkPixelTransfer.h:36
Generated by
1.8.20