-
Notifications
You must be signed in to change notification settings - Fork 0
/
CellCopier.cxx
167 lines (142 loc) · 3.96 KB
/
CellCopier.cxx
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
/*
____ _ __ ____ __ ____
/ __/___(_) / ___ ____/ __ \__ _____ ___ / /_ / _/__ ____
_\ \/ __/ / _ \/ -_) __/ /_/ / // / -_|_-</ __/ _/ // _ \/ __/
/___/\__/_/_.__/\__/_/ \___\_\_,_/\__/___/\__/ /___/_//_/\__(_)
Copyright 2012 SciberQuest Inc.
*/
#include "CellCopier.h"
#include "DataArrayCopierSpecializations.hxx"
#include "vtkPointData.h"
#include "vtkCellData.h"
#include "vtkDataSet.h"
typedef pair<map<vtkIdType,vtkIdType>::iterator,bool> MapInsert;
typedef pair<vtkIdType,vtkIdType> MapElement;
//*****************************************************************************
DataArrayCopier *NewDataArrayCopier(vtkDataArray *da)
{
DataArrayCopier *dac;
switch (da->GetDataType())
{
case VTK_INT:
dac=new IntDataArrayCopier;
break;
case VTK_ID_TYPE:
dac=new IdTypeDataArrayCopier;
break;
case VTK_FLOAT:
dac=new FloatDataArrayCopier;
break;
case VTK_DOUBLE:
dac=new DoubleDataArrayCopier;
break;
case VTK_UNSIGNED_CHAR:
dac=new UnsignedCharDataArrayCopier;
break;
default:
sqErrorMacro(cerr,"Unsupported array type.");
return 0;
}
return dac;
}
//-----------------------------------------------------------------------------
CellCopier::~CellCopier()
{
this->ClearDataCopier();
}
//-----------------------------------------------------------------------------
void CellCopier::ClearDataCopier()
{
int n;
n=this->PointDataCopier.size();
for (int i=0; i<n; ++i)
{
delete this->PointDataCopier[i];
}
this->PointDataCopier.clear();
n=this->CellDataCopier.size();
for (int i=0; i<n; ++i)
{
delete this->CellDataCopier[i];
}
this->CellDataCopier.clear();
}
//-----------------------------------------------------------------------------
void CellCopier::Initialize(vtkDataSet *in, vtkDataSet *out)
{
this->ClearDataCopier();
this->ClearPointIdMap();
int n;
vtkPointData *pdIn=in->GetPointData();
vtkPointData *pdOut=out->GetPointData();
n=pdIn->GetNumberOfArrays();
for (int i=0; i<n; ++i)
{
vtkDataArray *da=pdIn->GetArray(i);
DataArrayCopier *dac=NewDataArrayCopier(da);
dac->Initialize(da);
this->PointDataCopier.push_back(dac);
pdOut->AddArray(dac->GetOutput());
}
vtkCellData *cdIn=in->GetCellData();
vtkCellData *cdOut=out->GetCellData();
n=cdIn->GetNumberOfArrays();
for (int i=0; i<n; ++i)
{
vtkDataArray *da=cdIn->GetArray(i);
DataArrayCopier *dac=NewDataArrayCopier(da);
dac->Initialize(da);
this->CellDataCopier.push_back(dac);
cdOut->AddArray(dac->GetOutput());
}
}
//-----------------------------------------------------------------------------
int CellCopier::CopyPointData(IdBlock &block)
{
int n=this->PointDataCopier.size();
for (int i=0; i<n; ++i)
{
this->PointDataCopier[i]->Copy(block);
}
return 1;
}
//-----------------------------------------------------------------------------
int CellCopier::CopyCellData(IdBlock &block)
{
int n=this->CellDataCopier.size();
for (int i=0; i<n; ++i)
{
this->CellDataCopier[i]->Copy(block);
}
return 1;
}
//-----------------------------------------------------------------------------
int CellCopier::CopyPointData(vtkIdType id)
{
int n=this->PointDataCopier.size();
for (int i=0; i<n; ++i)
{
this->PointDataCopier[i]->Copy(id);
}
return 1;
}
//-----------------------------------------------------------------------------
int CellCopier::CopyCellData(vtkIdType id)
{
int n=this->CellDataCopier.size();
for (int i=0; i<n; ++i)
{
this->CellDataCopier[i]->Copy(id);
}
return 1;
}
//-----------------------------------------------------------------------------
bool CellCopier::GetUniquePointId(vtkIdType inputId, vtkIdType &outputId)
{
MapElement elem(inputId,outputId);
MapInsert ret=this->PointIdMap.insert(elem);
// existing or new point id
outputId=(*ret.first).second;
// true if insert succeded
return ret.second;
}