TestAMRBox.cxx 6.83 KB
Newer Older
Burlen Loring's avatar
 
Burlen Loring committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    TestAMRBox.cxx

  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.

=========================================================================*/
Burlen Loring's avatar
   
Burlen Loring committed
15
#include "vtkAMRBox.h"
Burlen Loring's avatar
 
Burlen Loring committed
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279

int TestAMRBox(int , char *[])
{
  // Equality.
  {
  vtkAMRBox A(-8,-8,-8,-4,-4,-4);
  vtkAMRBox B(-8,-8,-8,-4,-4,-4);
  vtkAMRBox C(-8,-8,-8,-1,-1,-1);
  vtkAMRBox D;
  vtkAMRBox E(-8,-8,-4,-4);
  vtkAMRBox F(-8,-8,-4,-4);
  vtkAMRBox G(-12,-12,-4,-4);
  if ( !(A==A)
    || !(A==B)
    || A==C
    || A==D
    || D==A
    || A==E
    || E==A
    || !(E==E)
    || !(E==F)
    || E==G)
    {
    A.Print(cerr) << endl;
    B.Print(cerr) << endl;
    C.Print(cerr) << endl;
    D.Print(cerr) << endl;
    E.Print(cerr) << endl;
    F.Print(cerr) << endl;
    G.Print(cerr) << endl;
    cerr << "Failed testing operator===." << endl;
    return 1;
    }
  }
  // Coarsen then refine.
  {
  vtkAMRBox A0(-8,-8,-8,7,7,7);
  vtkAMRBox B0(-8,-8,-8,8,8,8); // can't coarsen
  vtkAMRBox C(-1,-1,-1,0,0,0);

  vtkAMRBox A1(A0);
  A1.Coarsen(8);      // ==C
  vtkAMRBox A2(A1);
  A2.Refine(8);       // ==A0

  vtkAMRBox B1(B0);
  B1.Coarsen(8);      // ==B0

  vtkAMRBox D0(-8,-8,7,7);
  vtkAMRBox E0(-8,-8,8,8); // can't coarsen
  vtkAMRBox F(-1,-1,0,0);

  vtkAMRBox D1(D0);
  D1.Coarsen(8);      // ==F
  vtkAMRBox D2(D1);
  D2.Refine(8);       // ==D0

  vtkAMRBox E1(E0);
  E1.Coarsen(8);      // ==E0

  if ( !(A1==C)
    || !(B1==B0)
    || !(A2==A0)
    || !(D1==F)
    || !(D2==D0)
    || !(E1==E0))
    {
    A0.Print(cerr) << endl;
    B0.Print(cerr) << endl;
    C.Print(cerr) << endl;
    A1.Print(cerr) << endl;
    A2.Print(cerr) << endl;
    B1.Print(cerr) << endl;
    D0.Print(cerr) << endl;
    E0.Print(cerr) << endl;
    F.Print(cerr) << endl;
    D1.Print(cerr) << endl;
    D2.Print(cerr) << endl;
    E1.Print(cerr) << endl;
    cerr << "Failed testing refine coarsened." << endl;
    return 1;
    }
  }
  // Refine then coarsen.
  {
  vtkAMRBox A0(-1,-1,-1,0,0,0);
  vtkAMRBox B(-8,-8,-8,7,7,7);

  vtkAMRBox A1(A0);
  A1.Refine(8);      // ==B
  vtkAMRBox A2(A1);
  A2.Coarsen(8);     // ==A0

  vtkAMRBox D0(-1,-1,0,0);
  vtkAMRBox E(-8,-8,7,7);

  vtkAMRBox D1(D0);
  D1.Refine(8);      // ==E
  vtkAMRBox D2(D1);
  D2.Coarsen(8);     // ==D0

  if ( !(A1==B)
    || !(A2==A0)
    || !(D1==E)
    || !(D2==D0))
    {
    A0.Print(cerr) << endl;
    B.Print(cerr) << endl;
    A1.Print(cerr) << endl;
    A2.Print(cerr) << endl;
    D0.Print(cerr) << endl;
    E.Print(cerr) << endl;
    D1.Print(cerr) << endl;
    D2.Print(cerr) << endl;
    cerr << "Failed testing coarsen refined." << endl;
    return 1;
    }
  }
  // Shift.
  {
  vtkAMRBox A(-2,-2,-2,2,2,2);
  vtkAMRBox B(A);
  B.Shift(100,0,0);
  B.Shift(0,100,0);
  B.Shift(0,0,100);
  B.Shift(-200,-200,-200);
  B.Shift(100,0,0);
  B.Shift(0,100,0);
  B.Shift(0,0,100); // ==A

  vtkAMRBox C(-2,-2,2,2);
  vtkAMRBox D(C);
  D.Shift(100,0,0);
  D.Shift(0,100,0);
  D.Shift(0,0,100);
  D.Shift(-200,-200,-200);
  D.Shift(100,0,0);
  D.Shift(0,100,0);
  D.Shift(0,0,100); // ==C

  if ( !(B==A)
    || !(D==C))
    {
    A.Print(cerr) << endl;
    B.Print(cerr) << endl;
    C.Print(cerr) << endl;
    D.Print(cerr) << endl;
    cerr << "Failed testing shift." << endl;
    return 1;
    }
  }
  // Grow/shrink.
  {
  vtkAMRBox A(-2,-2,-2,2,2,2);
  vtkAMRBox B(-4,-4,-4,4,4,4);
  vtkAMRBox A1(A);
  A1.Grow(2);       // ==B
  vtkAMRBox A2(A1);
  A2.Shrink(2);     // ==A

  vtkAMRBox C(-2,-2,2,2);
  vtkAMRBox D(-4,-4,4,4);
  vtkAMRBox C1(C);
  C1.Grow(2);       // ==D
  vtkAMRBox C2(C1);
  C2.Shrink(2);     // ==C

  if ( !(A2==A)
    || !(A1==B)
    || !(C2==C)
    || !(C1==D))
    {
    A.Print(cerr) << endl;
    B.Print(cerr) << endl;
    A1.Print(cerr) << endl;
    A2.Print(cerr) << endl;
    C.Print(cerr) << endl;
    D.Print(cerr) << endl;
    C1.Print(cerr) << endl;
    C2.Print(cerr) << endl;
    cerr << "Failed tetsing grow/shrink." << endl;
    return 1;
    }
  }
  // Intersect.
  {
  vtkAMRBox A(-4,-4,-4,4,4,4);
  vtkAMRBox B(-4,-4,-4,-1,-1,-1);
  vtkAMRBox C(1,1,1,4,4,4);
  vtkAMRBox AA(A);
  AA&=A;              // ==A
  vtkAMRBox AB(A);
  AB&=B;              // ==B
  vtkAMRBox BA(B);
  BA&=A;              // ==B
  vtkAMRBox AC(A);
  AC&=C;              // ==C
  vtkAMRBox CA(C);
  CA&=A;              // ==C
  vtkAMRBox BC(B); 
  BC&=C;              // ==NULL
  vtkAMRBox CB(C);
  CB&=B;              // ==NULL

  vtkAMRBox D(-4,-4,4,4);
  vtkAMRBox E(-4,-4,-1,-1);
  vtkAMRBox F(1,1,4,4);
  vtkAMRBox DD(D);
  DD&=D;              // ==D
  vtkAMRBox DE(D);
  DE&=E;              // ==E
  vtkAMRBox ED(E);
  ED&=D;              // ==E
  vtkAMRBox DF(D);
  DF&=F;              // ==F
  vtkAMRBox FD(F);
  FD&=D;              // ==F
  vtkAMRBox EF(E);
  EF&=F;              // ==NULL
  vtkAMRBox FE(F);
  FE&=E;              // ==NULL

  vtkAMRBox AD(A);
  AD&=D;              // ==NULL
  vtkAMRBox DA(D);
  DA&=A;              // ==NULL

  if (!(AA==A)
   || !(AB==B) || !(BA==AB)
   || !(AC==C) || !(AC==CA)
   || !BC.Empty() || !CB.Empty()
   || !(DD==D)
   || !(DE==E) || !(DE==ED)
   || !(DF==F) || !(DF==FD)
   || !EF.Empty() || !FE.Empty()
   || !(AD==A)
   || !(DA==D))
    {
    A.Print(cerr) << endl;
    B.Print(cerr) << endl;
    C.Print(cerr) << endl;
    AA.Print(cerr) << endl;
    AB.Print(cerr) << endl;
    BA.Print(cerr) << endl;
    AC.Print(cerr) << endl;
    CA.Print(cerr) << endl;
    BC.Print(cerr) << endl;
    CB.Print(cerr) << endl;
    D.Print(cerr) << endl;
    E.Print(cerr) << endl;
    F.Print(cerr) << endl;
    DD.Print(cerr) << endl;
    DE.Print(cerr) << endl;
    ED.Print(cerr) << endl;
    DF.Print(cerr) << endl;
    FD.Print(cerr) << endl;
    FE.Print(cerr) << endl;
    EF.Print(cerr) << endl;
    AD.Print(cerr) << endl;
    DA.Print(cerr) << endl;
    cerr << "Failed testing operator&=." << endl;
    return 1;
    }
  }
280
281
282
283
284
285
286
287
288
289
290
  // Serialize/Deserialize
  {
    vtkAMRBox A( 0,0,0, 9,9,9 );
    unsigned char *buffer = NULL;
    size_t bytesize       = 0;
    A.Serialize( buffer, bytesize );
    if( (buffer == NULL) || (bytesize == 0) )
      {
      std::cerr << "Failed serializing AMR box." << std::endl;
      return 1;
      }
291
    size_t expectedByteSize = vtkAMRBox::GetBytesize();
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
    if( bytesize != expectedByteSize )
      {
      std::cerr << "Bytesize of buffer did not match expected size.\n";
      return 1;
      }

    vtkAMRBox B;
    B.Deserialize( buffer, bytesize );

    if( !(A == B) )
      {
      std::cerr << "Deserialization of AMR box did not match initial box.\n";
      return 1;
      }

  }
Burlen Loring's avatar
 
Burlen Loring committed
308
309
310
311
312
313
  return 0;
}