-
Notifications
You must be signed in to change notification settings - Fork 0
/
CartesianDataBlock.cxx
196 lines (175 loc) · 4.76 KB
/
CartesianDataBlock.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
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
192
193
194
195
196
/*
____ _ __ ____ __ ____
/ __/___(_) / ___ ____/ __ \__ _____ ___ / /_ / _/__ ____
_\ \/ __/ / _ \/ -_) __/ /_/ / // / -_|_-</ __/ _/ // _ \/ __/
/___/\__/_/_.__/\__/_/ \___\_\_,_/\__/___/\__/ /___/_//_/\__(_)
Copyright 2012 SciberQuest Inc.
*/
#include "CartesianDataBlock.h"
#include "vtkDataSet.h"
#include "Tuple.hxx"
//-----------------------------------------------------------------------------
CartesianDataBlock::CartesianDataBlock()
{
this->Id[0]=
this->Id[1]=
this->Id[2]=
this->Id[3]=0;
this->SetBounds(0,1,0,1,0,1);
this->SetExtent(0,1,0,1,0,1);
this->Data=0;
}
//-----------------------------------------------------------------------------
CartesianDataBlock::~CartesianDataBlock()
{
this->SetData(0);
}
//-----------------------------------------------------------------------------
void CartesianDataBlock::SetId(int i, int j, int k, int idx)
{
int I[4]={i,j,k,idx};
this->SetId(I);
}
//-----------------------------------------------------------------------------
void CartesianDataBlock::SetId(int *I)
{
this->Id[0]=I[0];
this->Id[1]=I[1];
this->Id[2]=I[2];
this->Id[3]=I[3];
}
//-----------------------------------------------------------------------------
void CartesianDataBlock::SetBounds(
double xlo,
double xhi,
double ylo,
double yhi,
double zlo,
double zhi)
{
this->Bounds.Set(xlo,xhi,ylo,yhi,zlo,zhi);
}
//-----------------------------------------------------------------------------
void CartesianDataBlock::SetBounds(double *bounds)
{
this->Bounds.Set(bounds);
}
//-----------------------------------------------------------------------------
void CartesianDataBlock::SetExtent(
int ilo,
int ihi,
int jlo,
int jhi,
int klo,
int khi)
{
this->Extent.Set(ilo,ihi,jlo,jhi,klo,khi);
}
//-----------------------------------------------------------------------------
void CartesianDataBlock::SetExtent(int *ext)
{
this->Extent.Set(ext);
}
//-----------------------------------------------------------------------------
void CartesianDataBlock::SetData(vtkDataSet *data)
{
if (this->Data==data) return;
if (this->Data) this->Data->Delete();
this->Data=data;
if (this->Data) this->Data->Register(0);
}
//-----------------------------------------------------------------------------
vtkDataSet *CartesianDataBlock::GetData()
{
return this->Data;
}
//*****************************************************************************
ostream &operator<<(ostream &os, CartesianDataBlock &b)
{
os
<< Tuple<int>(b.Id,4) << " "
<< b.Extent << " "
<< b.Bounds << " "
<< b.Data;
return os;
}
// //-----------------------------------------------------------------------------
// // There are 26 neighbor blocks surrounding this block that together
// // compose a cube. We can think of them as aranged in a ternary tree.
// // By passing planes coincident with the center blocks faces, first
// // in the x, then in the y then in the z. This arangement lest us
// // locate the block conatining a point (point is assumed to be insize
// // one of the 27 blocks) with in the worst case 6 comparisions, and
// // no storage overhead. something similar to a kd-tree.
// void CartesianDataBlock::GetNeighborId(double *pt, int *I)
// {
// // start at this block.
// I[0]=this->Id[0];
// I[1]=this->Id[1];
// I[2]=this->Id[2];
//
// // walk a ternary tree.
// for (int q=0; q<3; ++q)
// {
// if (pt[q]<this->BlockBounds[2*q])
// {
// // left branch
// --I[q];
// }
// else
// if (pt[q]>this->BlockBounds[2*q+1])
// {
// // right branch
// ++I[q];
// }
// }
// }
// note: the above is more efficient
// // these are the leaf nodes (13-39) in a ternary
// // tree constructed by cutting a 3x3x3 neighbor cube
// // first in twice x then in twice y then twice in z.
// // Each cut plane is defined by the center and normal
// // of one face of the center cube.
// static
// const
// int neighborIds[27]={
// 0 , 9 , 18,
// 3 , 12, 21,
// 6 , 15, 24,
//
// 1 , 10, 19,
// 4 , 13, 22,
// 7 , 16, 25,
//
// 2 , 11, 20,
// 5 , 14, 23,
// 8 , 17, 26
// };
//
// //-----------------------------------------------------------------------------
// int Block::GetNeighborId(float *pt)
// {
// // walk a ternary tree.
// idx=0;
// for (int q=0; q<3; ++q)
// {
// if (pt[q]<this->BlockBounds[2*q])
// {
// // left branch
// idx=3*idx+1;
// }
// else
// if (pt[q]>this->BlockBounds[2*q+1])
// {
// // right branch
// idx=3*idx+3;
// }
// else
// {
// // middle branch
// idx=3*idx+2;
// }
// }
//
// return neighborIds[idx-13];
// }