File: itkBinaryMask3DMeshSourceTest.cxx

package info (click to toggle)
insighttoolkit4 4.13.3withdata-dfsg2-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 491,256 kB
  • sloc: cpp: 557,600; ansic: 180,546; fortran: 34,788; python: 16,572; sh: 2,187; lisp: 2,070; tcl: 993; java: 362; perl: 200; makefile: 133; csh: 81; pascal: 69; xml: 19; ruby: 10
file content (320 lines) | stat: -rw-r--r-- 8,430 bytes parent folder | download | duplicates (6)
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
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/*=========================================================================
 *
 *  Copyright Insight Software Consortium
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/

#include <iostream>

#include "itkBinaryMask3DMeshSource.h"

// Define the dimension of the images
const unsigned int Dimension = 3;

// Declare the types of the output images
typedef itk::Image<unsigned short,   Dimension>   ImageType;

// Declare the type of the index,size and region to initialize images
typedef ImageType::IndexType                     IndexType;
typedef ImageType::SizeType                      SizeType;
typedef ImageType::RegionType                    RegionType;
typedef ImageType::PixelType                     PixelType;
typedef ImageType::Pointer                       ImagePointerType;

void CreateCubeConfig(
                  ImagePointerType image,
                  const unsigned int& StartX,
                  const unsigned int& StartY,
                  const unsigned int& StartZ,
                  const unsigned char& value1,
                  const unsigned char& value2,
                  const unsigned char& value3,
                  const unsigned char& value4,
                  const unsigned char& value5,
                  const unsigned char& value6,
                  const unsigned char& value7,
                  const unsigned char& value8 );

void Create16CubeConfig(
                  ImagePointerType image,
                  const unsigned int& StartX,
                  const unsigned int& StartY,
                  const unsigned int& StartZ,
                  const unsigned char& value1,
                  const unsigned char& value2,
                  const unsigned char& value3,
                  const unsigned char& value4 );

int itkBinaryMask3DMeshSourceTest(int argc, char *argv[] )
{
  // Declare the type of the Mesh
  typedef itk::Mesh<double>                                  MeshType;
  typedef itk::BinaryMask3DMeshSource< ImageType, MeshType > MeshSourceType;

  const PixelType backgroundValue = 0;
  const PixelType internalValue   = 1;

  SizeType size;
  size[0] = 128;
  size[1] = 128;
  size[2] = 128;

  IndexType start;
  start.Fill(0);

  RegionType region;
  region.SetSize( size );
  region.SetIndex( start );

  ImagePointerType image = ImageType::New();
  image->SetRegions( region );
  image->Allocate();
  image->FillBuffer( backgroundValue );

  unsigned int i,j,k,l;

  for( unsigned char counter = 0; counter < 18; counter++ )
    {
    i = ( counter / 1 ) % 2; // 0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1.
    j = ( counter / 2 ) % 2; // 0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1.
    k = ( counter / 4 ) % 2; // 0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1.
    l = ( counter / 8 ) % 2; // 0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1.
    Create16CubeConfig( image, 0, 0, 3 * counter, i, j, k, l );
    }

  MeshSourceType::Pointer meshSource = MeshSourceType::New();
  meshSource->SetInput( image );
  meshSource->SetObjectValue( internalValue );

  if ( argc == 2 )
    {
    if ( atoi( argv[1] ) == 1 )
      {
      size[0] = 9;
      size[1] = 9;
      size[2] = 9;
      region.SetSize(size);
      meshSource->SetRegionOfInterest( region );
      }
    }

  try
    {
    meshSource->Update();
    }
  catch( itk::ExceptionObject & excp )
    {
    std::cerr << "Exception thrown during Update() " << std::endl;
    std::cerr << excp << std::endl;
    return EXIT_FAILURE;
    }

  std::cout << meshSource->GetNameOfClass()   << std::endl;
  std::cout << meshSource->GetNumberOfNodes() << std::endl;
  std::cout << meshSource->GetNumberOfCells() << std::endl;
  std::cout << meshSource << std::endl;

  return EXIT_SUCCESS;

}

void CreateCubeConfig(
                  ImagePointerType image,
                  const unsigned int& StartX,
                  const unsigned int& StartY,
                  const unsigned int& StartZ,
                  const unsigned char& value1,
                  const unsigned char& value2,
                  const unsigned char& value3,
                  const unsigned char& value4,
                  const unsigned char& value5,
                  const unsigned char& value6,
                  const unsigned char& value7,
                  const unsigned char& value8 )
{
  IndexType index;

  // first corner 0, 0, 0 offset
  index[0] = StartX;
  index[1] = StartY;
  index[2] = StartZ;
  image->SetPixel( index, value1 );

  // second  corner 1, 0, 0
  index[0] = StartX + 1;
  index[1] = StartY;
  index[2] = StartZ;
  image->SetPixel( index, value2 );

  // third   corner 1, 1, 0
  index[0] = StartX + 1;
  index[1] = StartY + 1;
  index[2] = StartZ;
  image->SetPixel( index, value3 );

  // fourth  corner 0, 1, 0
  index[0] = StartX;
  index[1] = StartY + 1;
  index[2] = StartZ;
  image->SetPixel( index, value4 );

  // fifth   corner 0, 0, 1
  index[0] = StartX;
  index[1] = StartY;
  index[2] = StartZ + 1;
  image->SetPixel( index, value5 );

  // sixth   corner 1, 0, 1
  index[0] = StartX + 1;
  index[1] = StartY;
  index[2] = StartZ + 1;
  image->SetPixel( index, value6 );

  // seventh corner 1, 1, 1
  index[0] = StartX + 1;
  index[1] = StartY + 1;
  index[2] = StartZ + 1;
  image->SetPixel( index, value7 );

  // eighth  corner 0, 1, 1
  index[0] = StartX;
  index[1] = StartY + 1;
  index[2] = StartZ + 1;
  image->SetPixel( index, value8 );
}

void Create16CubeConfig(
  ImagePointerType image,
  const unsigned int& StartX,
  const unsigned int& StartY,
  const unsigned int& StartZ,
  const unsigned char& value1,
  const unsigned char& value2,
  const unsigned char& value3,
  const unsigned char& value4 )
{
  // Case 0
  CreateCubeConfig(
    image,
    StartX + 0, StartY + 0, StartZ + 0,
    value1, value2, value3, value4,
    0, 0, 0, 0 );

  // Case 1
  CreateCubeConfig(
    image,
    StartX + 3, StartY + 0, StartZ + 0,
    value1, value2, value3, value4,
    0, 0, 0, 1 );

  // Case 2
  CreateCubeConfig(
    image,
    StartX + 6, StartY + 0, StartZ + 0,
    value1, value2, value3, value4,
    0, 0, 1, 0 );

  // Case 3
  CreateCubeConfig(
    image,
    StartX + 9, StartY + 0, StartZ + 0,
    value1, value2, value3, value4,
    0, 0, 1, 1 );

  // Case 4
  CreateCubeConfig(
    image,
    StartX + 0, StartY + 3, StartZ + 0,
    value1, value2, value3, value4,
    0, 1, 0, 0 );

  // Case 5
  CreateCubeConfig(
    image,
    StartX + 3, StartY + 3, StartZ + 0,
    value1, value2, value3, value4,
    0, 1, 0, 1 );

  // Case 6
  CreateCubeConfig(
    image,
    StartX + 6, StartY + 3, StartZ + 0,
    value1, value2, value3, value4,
    0, 1, 1, 0 );

  // Case 7
  CreateCubeConfig(
    image,
    StartX + 9, StartY + 3, StartZ + 0,
    value1, value2, value3, value4,
    0, 1, 1, 1 );

  // Case 8
  CreateCubeConfig(
    image,
    StartX + 0, StartY + 6, StartZ + 0,
    value1, value2, value3, value4,
    1, 0, 0, 0 );

  // Case 9
  CreateCubeConfig(
    image,
    StartX + 3, StartY + 6, StartZ + 0,
    value1, value2, value3, value4,
    1, 0, 0, 1 );

  // Case 10
  CreateCubeConfig(
    image,
    StartX + 6, StartY + 6, StartZ + 0,
    value1, value2, value3, value4,
    1, 0, 1, 0 );

  // Case 11
  CreateCubeConfig(
    image,
    StartX + 9, StartY + 6, StartZ + 0,
    value1, value2, value3, value4,
    1, 0, 1, 1 );

  // Case 12
  CreateCubeConfig(
    image,
    StartX + 0, StartY + 9, StartZ + 0,
    value1, value2, value3, value4,
    1, 1, 0, 0 );

  // Case 13
  CreateCubeConfig(
    image,
    StartX + 3, StartY + 9, StartZ + 0,
    value1, value2, value3, value4,
    1, 1, 0, 1 );

  // Case 14
  CreateCubeConfig(
    image,
    StartX + 6, StartY + 9, StartZ + 0,
    value1, value2, value3, value4,
    1, 1, 1, 0 );

  // Case 15
  CreateCubeConfig(
    image,
    StartX + 9, StartY + 9, StartZ + 0,
    value1, value2, value3, value4,
    1, 1, 1, 1 );

}