-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataArrayCopierImpl.hxx
191 lines (156 loc) · 4.15 KB
/
DataArrayCopierImpl.hxx
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
/*
____ _ __ ____ __ ____
/ __/___(_) / ___ ____/ __ \__ _____ ___ / /_ / _/__ ____
_\ \/ __/ / _ \/ -_) __/ /_/ / // / -_|_-</ __/ _/ // _ \/ __/
/___/\__/_/_.__/\__/_/ \___\_\_,_/\__/___/\__/ /___/_//_/\__(_)
Copyright 2012 SciberQuest Inc.
*/
#ifndef __DataArrayCopierImpl_h
#define __DataArrayCopierImpl_h
#include "DataArrayCopier.h"
#include "DataArrayTraits.hxx"
#include "SQMacros.h"
#include "vtkDataArray.h"
/// Templated inplementation of vtkDataArray copier.
/**
*/
template<typename T>
class DataArrayCopierImpl : public DataArrayCopier
{
public:
DataArrayCopierImpl()
:
NComps(0),
Input(0),
Output(0)
{}
virtual ~DataArrayCopierImpl();
/**
Initialize the copier for transfers from the given array
to a new array of the same type and name. Initializes
both input and output arrays.
*/
virtual void Initialize(vtkDataArray *in);
/**
Set the array to copy from.
*/
virtual void SetInput(vtkDataArray *in);
virtual vtkDataArray *GetInput();
/**
Set the array to copy to.
*/
virtual void SetOutput(vtkDataArray *out);
virtual vtkDataArray *GetOutput();
/**
Copy the range from the input array to the end of then
output array.
*/
virtual void Copy(IdBlock &ids);
virtual void Copy(vtkIdType id);
private:
int NComps;
T *Input;
T *Output;
private:
DataArrayCopierImpl(const DataArrayCopierImpl<T> &);
void operator=(const DataArrayCopierImpl<T> &);
};
//-----------------------------------------------------------------------------
template<typename T>
DataArrayCopierImpl<T>::~DataArrayCopierImpl()
{
this->SetInput(0);
this->SetOutput(0);
}
//-----------------------------------------------------------------------------
template<typename T>
void DataArrayCopierImpl<T>::Initialize(vtkDataArray *in)
{
if (in==0)
{
this->SetInput(0);
this->SetOutput(0);
sqErrorMacro(cerr,"Can't initialize from null pointer.");
return;
}
this->SetInput(in);
vtkDataArray *out=in->NewInstance();
out->SetNumberOfComponents(this->NComps);
out->SetName(in->GetName());
this->SetOutput(out);
out->Delete();
}
//-----------------------------------------------------------------------------
template<typename T>
void DataArrayCopierImpl<T>::SetInput(vtkDataArray *in)
{
if (in==this->Input)
{
return;
}
if (this->Input)
{
this->Input->Delete();
}
this->Input=dynamic_cast<T*>(in);
this->NComps=0;
if (this->Input)
{
this->Input->Register(0);
this->NComps=this->Input->GetNumberOfComponents();
}
}
//-----------------------------------------------------------------------------
template<typename T>
vtkDataArray *DataArrayCopierImpl<T>::GetInput()
{
return this->Input;
}
//-----------------------------------------------------------------------------
template<typename T>
void DataArrayCopierImpl<T>::SetOutput(vtkDataArray *out)
{
if (out==this->Output)
{
return;
}
if (this->Output)
{
this->Output->Delete();
}
this->Output=dynamic_cast<T*>(out);
if (this->Output)
{
this->Output->Register(0);
}
}
//-----------------------------------------------------------------------------
template<typename T>
vtkDataArray *DataArrayCopierImpl<T>::GetOutput()
{
return this->Output;
}
//-----------------------------------------------------------------------------
template<typename T>
void DataArrayCopierImpl<T>::Copy(vtkIdType id)
{
// expecting scalars, vectors, and tensors
typename DataArrayTraits<T>::InternalType val[9];
this->Input->GetTupleValue(id,val);
this->Output->InsertNextTupleValue(val);
}
//-----------------------------------------------------------------------------
template<typename T>
void DataArrayCopierImpl<T>::Copy(IdBlock &block)
{
vtkIdType inAt=this->NComps*block.first();
typename DataArrayTraits<T>::InternalType *pIn=this->Input->GetPointer(inAt);
vtkIdType outAt=this->NComps*this->Output->GetNumberOfTuples();
vtkIdType outN=this->NComps*block.size();
typename DataArrayTraits<T>::InternalType *pOut=this->Output->WritePointer(outAt,outN);
for (int i=0; i<outN; ++i,++pOut,++pIn)
{
*pOut=*pIn;
}
}
#endif