File: AVTestPolygonWriters.cs

package info (click to toggle)
activiz.net 1%3A1.0~git20111214-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,280 kB
  • ctags: 5,957
  • sloc: cs: 28,767; python: 915; cpp: 130; makefile: 35; sh: 11
file content (494 lines) | stat: -rw-r--r-- 15,450 bytes parent folder | download | duplicates (2)
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
using System.IO;
using Kitware.VTK;
using System;
// input file is C:\VTK\IO\Testing\Tcl\TestPolygonWriters.tcl
// output file is AVTestPolygonWriters.cs
/// <summary>
/// The testing class derived from AVTestPolygonWriters
/// </summary>
public class AVTestPolygonWritersClass
{
  /// <summary>
  /// The main entry method called by the CSharp driver
  /// </summary>
  /// <param name="argv"></param>
  public static void AVTestPolygonWriters(String [] argv)
  {
  //Prefix Content is: ""
  
  // Create the RenderWindow, Renderer and both Actors[]
  //[]
  ren1 = vtkRenderer.New();
  renWin = vtkRenderWindow.New();
  renWin.AddRenderer((vtkRenderer)ren1);
  iren = new vtkRenderWindowInteractor();
  iren.SetRenderWindow((vtkRenderWindow)renWin);
  // read data[]
  //[]
  input = new vtkPolyDataReader();
  input.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/brainImageSmooth.vtk");
  //[]
  // generate vectors[]
  clean = new vtkCleanPolyData();
  clean.SetInputConnection((vtkAlgorithmOutput)input.GetOutputPort());
  smooth = new vtkWindowedSincPolyDataFilter();
  smooth.SetInputConnection((vtkAlgorithmOutput)clean.GetOutputPort());
  smooth.GenerateErrorVectorsOn();
  smooth.GenerateErrorScalarsOn();
  smooth.Update();
  mapper = vtkPolyDataMapper.New();
  mapper.SetInputConnection((vtkAlgorithmOutput)smooth.GetOutputPort());
  mapper.SetScalarRange((double)((vtkDataSet)smooth.GetOutput()).GetScalarRange()[0],
      (double)((vtkDataSet)smooth.GetOutput()).GetScalarRange()[1]);
  brain = new vtkActor();
  brain.SetMapper((vtkMapper)mapper);
  // Add the actors to the renderer, set the background and size[]
  //[]
  ren1.AddActor((vtkProp)brain);
  renWin.SetSize((int)320,(int)240);
  ren1.GetActiveCamera().SetPosition((double)149.653,(double)-65.3464,(double)96.0401);
  ren1.GetActiveCamera().SetFocalPoint((double)146.003,(double)22.3839,(double)0.260541);
  ren1.GetActiveCamera().SetViewAngle((double)30);
  ren1.GetActiveCamera().SetViewUp((double)-0.255578,(double)-0.717754,(double)-0.647695);
  ren1.GetActiveCamera().SetClippingRange((double)79.2526,(double)194.052);
  iren.Initialize();
  renWin.Render();
  // render the image[]
  //[]
  // prevent the tk window from showing up then start the event loop[]
  //[]
  // If the current directory is writable, then test the witers[]
  //[]
  try
  {
     channel = new StreamWriter("test.tmp");
      tryCatchError = "NOERROR";
  }
  catch(Exception)
  {tryCatchError = "ERROR";}
  
if(tryCatchError.Equals("NOERROR"))
  {
      channel.Close();
      File.Delete("test.tmp");
      //[]
      //[]
      // test the writers[]
      dsw = new vtkDataSetWriter();
      dsw.SetInputConnection((vtkAlgorithmOutput)smooth.GetOutputPort());
      dsw.SetFileName((string)"brain.dsw");
      dsw.Write();
      File.Delete("brain.dsw");
      pdw = new vtkPolyDataWriter();
      pdw.SetInputConnection((vtkAlgorithmOutput)smooth.GetOutputPort());
      pdw.SetFileName((string)"brain.pdw");
      pdw.Write();
      File.Delete("brain.pdw");
          iv = new vtkIVWriter();
          iv.SetInputConnection((vtkAlgorithmOutput)smooth.GetOutputPort());
          iv.SetFileName((string)"brain.iv");
          iv.Write();
          File.Delete("brain.iv");

      
      //[]
      // the next writers only handle triangles[]
      triangles = new vtkTriangleFilter();
      triangles.SetInputConnection((vtkAlgorithmOutput)smooth.GetOutputPort());
          iv2 = new vtkIVWriter();
          iv2.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort());
          iv2.SetFileName((string)"brain2.iv");
          iv2.Write();
          File.Delete("brain2.iv");


          edges = new vtkExtractEdges();
          edges.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort());
          iv3 = new vtkIVWriter();
          iv3.SetInputConnection((vtkAlgorithmOutput)edges.GetOutputPort());
          iv3.SetFileName((string)"brain3.iv");
          iv3.Write();
          File.Delete("brain3.iv");

      
      byu = new vtkBYUWriter();
      byu.SetGeometryFileName((string)"brain.g");
      byu.SetScalarFileName((string)"brain.s");
      byu.SetDisplacementFileName((string)"brain.d");
      byu.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort());
      byu.Write();
      File.Delete("brain.g");
      File.Delete("brain.s");
      File.Delete("brain.d");
      mcubes = new vtkMCubesWriter();
      mcubes.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort());
      mcubes.SetFileName((string)"brain.tri");
      mcubes.SetLimitsFileName((string)"brain.lim");
      mcubes.Write();
      File.Delete("brain.lim");
      File.Delete("brain.tri");
      stl = new vtkSTLWriter();
      stl.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort());
      stl.SetFileName((string)"brain.stl");
      stl.Write();
      File.Delete("brain.stl");
      stlBinary = new vtkSTLWriter();
      stlBinary.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort());
      stlBinary.SetFileName((string)"brainBinary.stl");
      stlBinary.SetFileType((int)2);
      stlBinary.Write();
      File.Delete("brainBinary.stl");
      cgm = new vtkCGMWriter();
      cgm.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort());
      cgm.SetFileName((string)"brain.cgm");
      cgm.Write();
      File.Delete("brain.cgm");
    }

  
  
//deleteAllVTKObjects();
  }
static string VTK_DATA_ROOT;
static int threshold;
static vtkRenderer ren1;
static vtkRenderWindow renWin;
static vtkRenderWindowInteractor iren;
static vtkPolyDataReader input;
static vtkCleanPolyData clean;
static vtkWindowedSincPolyDataFilter smooth;
static vtkPolyDataMapper mapper;
static vtkActor brain;
static string tryCatchError;
static StreamWriter channel;
static vtkDataSetWriter dsw;
static vtkPolyDataWriter pdw;
static vtkIVWriter iv;
static vtkTriangleFilter triangles;
static vtkIVWriter iv2;
static vtkExtractEdges edges;
static vtkIVWriter iv3;
static vtkBYUWriter byu;
static vtkMCubesWriter mcubes;
static vtkSTLWriter stl;
static vtkSTLWriter stlBinary;
static vtkCGMWriter cgm;


        ///<summary> A Get Method for Static Variables </summary>
        public static string GetVTK_DATA_ROOT()
        {
            return VTK_DATA_ROOT;
        }
        
        ///<summary> A Set Method for Static Variables </summary>
        public static void SetVTK_DATA_ROOT(string toSet)
        {
            VTK_DATA_ROOT = toSet;
        }
        
        ///<summary> A Get Method for Static Variables </summary>
        public static int Getthreshold()
        {
            return threshold;
        }
        
        ///<summary> A Set Method for Static Variables </summary>
        public static void Setthreshold(int toSet)
        {
            threshold = toSet;
        }
        
        ///<summary> A Get Method for Static Variables </summary>
        public static vtkRenderer Getren1()
        {
            return ren1;
        }
        
        ///<summary> A Set Method for Static Variables </summary>
        public static void Setren1(vtkRenderer toSet)
        {
            ren1 = toSet;
        }
        
        ///<summary> A Get Method for Static Variables </summary>
        public static vtkRenderWindow GetrenWin()
        {
            return renWin;
        }
        
        ///<summary> A Set Method for Static Variables </summary>
        public static void SetrenWin(vtkRenderWindow toSet)
        {
            renWin = toSet;
        }
        
        ///<summary> A Get Method for Static Variables </summary>
        public static vtkRenderWindowInteractor Getiren()
        {
            return iren;
        }
        
        ///<summary> A Set Method for Static Variables </summary>
        public static void Setiren(vtkRenderWindowInteractor toSet)
        {
            iren = toSet;
        }
        
        ///<summary> A Get Method for Static Variables </summary>
        public static vtkPolyDataReader Getinput()
        {
            return input;
        }
        
        ///<summary> A Set Method for Static Variables </summary>
        public static void Setinput(vtkPolyDataReader toSet)
        {
            input = toSet;
        }
        
        ///<summary> A Get Method for Static Variables </summary>
        public static vtkCleanPolyData Getclean()
        {
            return clean;
        }
        
        ///<summary> A Set Method for Static Variables </summary>
        public static void Setclean(vtkCleanPolyData toSet)
        {
            clean = toSet;
        }
        
        ///<summary> A Get Method for Static Variables </summary>
        public static vtkWindowedSincPolyDataFilter Getsmooth()
        {
            return smooth;
        }
        
        ///<summary> A Set Method for Static Variables </summary>
        public static void Setsmooth(vtkWindowedSincPolyDataFilter toSet)
        {
            smooth = toSet;
        }
        
        ///<summary> A Get Method for Static Variables </summary>
        public static vtkPolyDataMapper Getmapper()
        {
            return mapper;
        }
        
        ///<summary> A Set Method for Static Variables </summary>
        public static void Setmapper(vtkPolyDataMapper toSet)
        {
            mapper = toSet;
        }
        
        ///<summary> A Get Method for Static Variables </summary>
        public static vtkActor Getbrain()
        {
            return brain;
        }
        
        ///<summary> A Set Method for Static Variables </summary>
        public static void Setbrain(vtkActor toSet)
        {
            brain = toSet;
        }
        
        ///<summary> A Get Method for Static Variables </summary>
        public static string GettryCatchError()
        {
            return tryCatchError;
        }
        
        ///<summary> A Set Method for Static Variables </summary>
        public static void SettryCatchError(string toSet)
        {
            tryCatchError = toSet;
        }
        
        ///<summary> A Get Method for Static Variables </summary>
        public static StreamWriter Getchannel()
        {
            return channel;
        }
        
        ///<summary> A Set Method for Static Variables </summary>
        public static void Setchannel(StreamWriter toSet)
        {
            channel = toSet;
        }
        
        ///<summary> A Get Method for Static Variables </summary>
        public static vtkDataSetWriter Getdsw()
        {
            return dsw;
        }
        
        ///<summary> A Set Method for Static Variables </summary>
        public static void Setdsw(vtkDataSetWriter toSet)
        {
            dsw = toSet;
        }
        
        ///<summary> A Get Method for Static Variables </summary>
        public static vtkPolyDataWriter Getpdw()
        {
            return pdw;
        }
        
        ///<summary> A Set Method for Static Variables </summary>
        public static void Setpdw(vtkPolyDataWriter toSet)
        {
            pdw = toSet;
        }
        
        ///<summary> A Get Method for Static Variables </summary>
        public static vtkIVWriter Getiv()
        {
            return iv;
        }
        
        ///<summary> A Set Method for Static Variables </summary>
        public static void Setiv(vtkIVWriter toSet)
        {
            iv = toSet;
        }
        
        ///<summary> A Get Method for Static Variables </summary>
        public static vtkTriangleFilter Gettriangles()
        {
            return triangles;
        }
        
        ///<summary> A Set Method for Static Variables </summary>
        public static void Settriangles(vtkTriangleFilter toSet)
        {
            triangles = toSet;
        }
        
        ///<summary> A Get Method for Static Variables </summary>
        public static vtkIVWriter Getiv2()
        {
            return iv2;
        }
        
        ///<summary> A Set Method for Static Variables </summary>
        public static void Setiv2(vtkIVWriter toSet)
        {
            iv2 = toSet;
        }
        
        ///<summary> A Get Method for Static Variables </summary>
        public static vtkExtractEdges Getedges()
        {
            return edges;
        }
        
        ///<summary> A Set Method for Static Variables </summary>
        public static void Setedges(vtkExtractEdges toSet)
        {
            edges = toSet;
        }
        
        ///<summary> A Get Method for Static Variables </summary>
        public static vtkIVWriter Getiv3()
        {
            return iv3;
        }
        
        ///<summary> A Set Method for Static Variables </summary>
        public static void Setiv3(vtkIVWriter toSet)
        {
            iv3 = toSet;
        }
        
        ///<summary> A Get Method for Static Variables </summary>
        public static vtkBYUWriter Getbyu()
        {
            return byu;
        }
        
        ///<summary> A Set Method for Static Variables </summary>
        public static void Setbyu(vtkBYUWriter toSet)
        {
            byu = toSet;
        }
        
        ///<summary> A Get Method for Static Variables </summary>
        public static vtkMCubesWriter Getmcubes()
        {
            return mcubes;
        }
        
        ///<summary> A Set Method for Static Variables </summary>
        public static void Setmcubes(vtkMCubesWriter toSet)
        {
            mcubes = toSet;
        }
        
        ///<summary> A Get Method for Static Variables </summary>
        public static vtkSTLWriter Getstl()
        {
            return stl;
        }
        
        ///<summary> A Set Method for Static Variables </summary>
        public static void Setstl(vtkSTLWriter toSet)
        {
            stl = toSet;
        }
        
        ///<summary> A Get Method for Static Variables </summary>
        public static vtkSTLWriter GetstlBinary()
        {
            return stlBinary;
        }
        
        ///<summary> A Set Method for Static Variables </summary>
        public static void SetstlBinary(vtkSTLWriter toSet)
        {
            stlBinary = toSet;
        }
        
        ///<summary> A Get Method for Static Variables </summary>
        public static vtkCGMWriter Getcgm()
        {
            return cgm;
        }
        
        ///<summary> A Set Method for Static Variables </summary>
        public static void Setcgm(vtkCGMWriter toSet)
        {
            cgm = toSet;
        }
        
  ///<summary>Deletes all static objects created</summary>
  public static void deleteAllVTKObjects()
  {
  	//clean up vtk objects
  	if(ren1!= null){ren1.Dispose();}
  	if(renWin!= null){renWin.Dispose();}
  	if(iren!= null){iren.Dispose();}
  	if(input!= null){input.Dispose();}
  	if(clean!= null){clean.Dispose();}
  	if(smooth!= null){smooth.Dispose();}
  	if(mapper!= null){mapper.Dispose();}
  	if(brain!= null){brain.Dispose();}
  	if(dsw!= null){dsw.Dispose();}
  	if(pdw!= null){pdw.Dispose();}
  	if(iv!= null){iv.Dispose();}
  	if(triangles!= null){triangles.Dispose();}
  	if(iv2!= null){iv2.Dispose();}
  	if(edges!= null){edges.Dispose();}
  	if(iv3!= null){iv3.Dispose();}
  	if(byu!= null){byu.Dispose();}
  	if(mcubes!= null){mcubes.Dispose();}
  	if(stl!= null){stl.Dispose();}
  	if(stlBinary!= null){stlBinary.Dispose();}
  	if(cgm!= null){cgm.Dispose();}
  }

}
//--- end of script --//