File: AVTestRectilinearGridToTetrahedra.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 (313 lines) | stat: -rw-r--r-- 10,265 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
using Kitware.VTK;
using System;
// input file is C:\VTK\Graphics\Testing\Tcl\TestRectilinearGridToTetrahedra.tcl
// output file is AVTestRectilinearGridToTetrahedra.cs
/// <summary>
/// The testing class derived from AVTestRectilinearGridToTetrahedra
/// </summary>
public class AVTestRectilinearGridToTetrahedraClass
{
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVTestRectilinearGridToTetrahedra(String[] argv)
    {
        //Prefix Content is: ""

        //## SetUp the pipeline[]
        FormMesh = new vtkRectilinearGridToTetrahedra();
        FormMesh.SetInput((double)4, (double)2, (double)2, (double)1, (double)1, (double)1, (double)0.001);
        FormMesh.RememberVoxelIdOn();
        TetraEdges = new vtkExtractEdges();
        TetraEdges.SetInputConnection((vtkAlgorithmOutput)FormMesh.GetOutputPort());
        tubes = new vtkTubeFilter();
        tubes.SetInputConnection((vtkAlgorithmOutput)TetraEdges.GetOutputPort());
        tubes.SetRadius((double)0.05);
        tubes.SetNumberOfSides((int)6);
        //## Run the pipeline 3 times, with different conversions to TetMesh[]
        Tubes[0] = new vtkPolyData();
        FormMesh.SetTetraPerCellTo5();
        tubes.Update();
        Tubes[0].DeepCopy((vtkDataObject)tubes.GetOutput());
        Tubes[1] = new vtkPolyData();
        FormMesh.SetTetraPerCellTo6();
        tubes.Update();
        Tubes[1].DeepCopy((vtkDataObject)tubes.GetOutput());
        Tubes[2] = new vtkPolyData();
        FormMesh.SetTetraPerCellTo12();
        tubes.Update();
        Tubes[2].DeepCopy((vtkDataObject)tubes.GetOutput());
        //## Run the pipeline once more, this time converting some cells to[]
        //## 5 and some data to 12 TetMesh[]
        //## Determine which cells are which[]
        DivTypes = new vtkIntArray();
        numCell = (long)((vtkDataSet)FormMesh.GetInput()).GetNumberOfCells();
        DivTypes.SetNumberOfValues((int)numCell);
        i = 0;
        while ((i) < numCell)
        {
            DivTypes.SetValue((int)i, (int)5 + (7 * (i % 4)));
            i = i + 1;
        }

        //## Finish this pipeline[]
        Tubes[3] = new vtkPolyData();
        FormMesh.SetTetraPerCellTo5And12();
        ((vtkRectilinearGrid)FormMesh.GetInput()).GetCellData().SetScalars(DivTypes);
        tubes.Update();
        Tubes[3].DeepCopy((vtkDataObject)tubes.GetOutput());
        //## Finish the 4 pipelines[]
        i = 1;
        while ((i) < 5)
        {
            mapEdges[i] = vtkPolyDataMapper.New();
            mapEdges[i].SetInput((vtkPolyData)Tubes[i - 1]);
            edgeActor[i] = new vtkActor();
            edgeActor[i].SetMapper((vtkMapper)mapEdges[i]);
            edgeActor[i].GetProperty().SetColor((double)0.2000, 0.6300, 0.7900);
            edgeActor[i].GetProperty().SetSpecularColor((double)1, (double)1, (double)1);
            edgeActor[i].GetProperty().SetSpecular((double)0.3);
            edgeActor[i].GetProperty().SetSpecularPower((double)20);
            edgeActor[i].GetProperty().SetAmbient((double)0.2);
            edgeActor[i].GetProperty().SetDiffuse((double)0.8);
            ren[i] = vtkRenderer.New();
            ren[i].AddActor((vtkProp)edgeActor[i]);
            ren[i].SetBackground((double)0, (double)0, (double)0);
            ren[i].ResetCamera();
            ren[i].GetActiveCamera().Zoom((double)1);
            ren[i].GetActiveCamera().SetPosition((double)1.73906, (double)12.7987, (double)-0.257808);
            ren[i].GetActiveCamera().SetViewUp((double)0.992444, (double)0.00890284, (double)-0.122379);
            ren[i].GetActiveCamera().SetClippingRange((double)9.36398, (double)15.0496);
            i = i + 1;
        }

        // Create graphics objects[]
        // Create the rendering window, renderer, and interactive renderer[]
        renWin = vtkRenderWindow.New();
        renWin.AddRenderer(ren[1]);
        renWin.AddRenderer(ren[2]);
        renWin.AddRenderer(ren[3]);
        renWin.AddRenderer(ren[4]);
        renWin.SetSize(600, 300);
        iren = new vtkRenderWindowInteractor();
        iren.SetRenderWindow((vtkRenderWindow)renWin);
        // Add the actors to the renderer, set the background and size[]
        ren[1].SetViewport((double).75, (double)0, (double)1, (double)1);
        ren[2].SetViewport((double).50, (double)0, (double).75, (double)1);
        ren[3].SetViewport((double).25, (double)0, (double).50, (double)1);
        ren[4].SetViewport((double)0, (double)0, (double).25, (double)1);
        // render the image[]
        //[]
        iren.Initialize();
        // prevent the tk window from showing up then start the event loop[]

        //deleteAllVTKObjects();
    }
    static string VTK_DATA_ROOT;
    static int threshold;
    static vtkRectilinearGridToTetrahedra FormMesh;
    static vtkExtractEdges TetraEdges;
    static vtkTubeFilter tubes;
    static vtkPolyData[] Tubes = new vtkPolyData[4];
    static vtkIntArray DivTypes;
    static long numCell;
    static int i;
    static vtkPolyDataMapper[] mapEdges = new vtkPolyDataMapper[100];
    static vtkActor[] edgeActor = new vtkActor[100];
    static vtkRenderer[] ren = new vtkRenderer[100];
    static vtkRenderWindow renWin;
    static vtkRenderWindowInteractor iren;

    ///<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 vtkRectilinearGridToTetrahedra GetFormMesh()
    {
        return FormMesh;
    }

    ///<summary> A Set Method for Static Variables </summary>
    public static void SetFormMesh(vtkRectilinearGridToTetrahedra toSet)
    {
        FormMesh = toSet;
    }

    ///<summary> A Get Method for Static Variables </summary>
    public static vtkExtractEdges GetTetraEdges()
    {
        return TetraEdges;
    }

    ///<summary> A Set Method for Static Variables </summary>
    public static void SetTetraEdges(vtkExtractEdges toSet)
    {
        TetraEdges = toSet;
    }

    ///<summary> A Get Method for Static Variables </summary>
    public static vtkTubeFilter Gettubes()
    {
        return tubes;
    }

    ///<summary> A Set Method for Static Variables </summary>
    public static void Settubes(vtkTubeFilter toSet)
    {
        tubes = toSet;
    }

    ///<summary> A Get Method for Static Variables </summary>
    public static vtkPolyData[] GetTubes()
    {
        return Tubes;
    }

    ///<summary> A Set Method for Static Variables </summary>
    public static void SetTubes(vtkPolyData[] toSet)
    {
        Tubes = toSet;
    }

    ///<summary> A Get Method for Static Variables </summary>
    public static vtkIntArray GetDivTypes()
    {
        return DivTypes;
    }

    ///<summary> A Set Method for Static Variables </summary>
    public static void SetDivTypes(vtkIntArray toSet)
    {
        DivTypes = toSet;
    }

    ///<summary> A Get Method for Static Variables </summary>
    public static long GetnumCell()
    {
        return numCell;
    }

    ///<summary> A Set Method for Static Variables </summary>
    public static void SetnumCell(int toSet)
    {
        numCell = toSet;
    }

    ///<summary> A Get Method for Static Variables </summary>
    public static int Geti()
    {
        return i;
    }

    ///<summary> A Set Method for Static Variables </summary>
    public static void Seti(int toSet)
    {
        i = toSet;
    }


    ///<summary> A Get Method for Static Variables </summary>
    public static vtkPolyDataMapper[] GetmapEdges()
    {
        return mapEdges;
    }

    ///<summary> A Set Method for Static Variables </summary>
    public static void SetmapEdges(vtkPolyDataMapper[] toSet)
    {
        mapEdges = toSet;
    }

    ///<summary> A Get Method for Static Variables </summary>
    public static vtkActor[] GetedgeActor()
    {
        return edgeActor;
    }

    ///<summary> A Set Method for Static Variables </summary>
    public static void SetedgeActor(vtkActor[] toSet)
    {
        edgeActor = toSet;
    }

    ///<summary> A Get Method for Static Variables </summary>
    public static vtkRenderer[] Getren()
    {
        return ren;
    }

    ///<summary> A Set Method for Static Variables </summary>
    public static void Setren(vtkRenderer[] toSet)
    {
        ren = toSet;
    }

    ///<summary> A Get Method for Static Variables </summary>
    public static vtkRenderWindow GetrenWin()
    {
      return renWin;
    }

    ///<summary> A Get Method for Static Variables </summary>
    public static vtkRenderWindowInteractor Getiren()
    {
      return iren;
    }

    ///<summary>Deletes all static objects created</summary>
    public static void deleteAllVTKObjects()
    {
        //clean up vtk objects
        if (renWin != null) { renWin.Dispose(); }
        if (iren != null) { iren.Dispose(); }
        if (FormMesh != null) { FormMesh.Dispose(); }
        if (TetraEdges != null) { TetraEdges.Dispose(); }
        if (tubes != null) { tubes.Dispose(); }
        if (Tubes[0] != null) { Tubes[0].Dispose(); }
        if (Tubes[1] != null) { Tubes[1].Dispose(); }
        if (Tubes[2] != null) { Tubes[2].Dispose(); }
        if (Tubes[3] != null) { Tubes[3].Dispose(); }
        if (DivTypes != null) { DivTypes.Dispose(); }
        for (int i = 0; i < 100; i++)
        {
            if (mapEdges[i] != null)
            {
                mapEdges[i].Dispose();
            }
            if (edgeActor[i] != null)
            {
                edgeActor[i].Dispose();
            }
            if (ren[i] != null)
            {
                ren[i].Dispose();
            }
        }

    }

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