|
35 | 35 | "metadata": {}, |
36 | 36 | "outputs": [], |
37 | 37 | "source": [ |
38 | | - "MESH_FILE = 'Input/cow.vtk'\n", |
| 38 | + "MESH_FILE = \"Input/cow.vtk\"\n", |
39 | 39 | "\n", |
40 | 40 | "# Download mesh\n", |
41 | | - "os.makedirs('Input', exist_ok=True)\n", |
| 41 | + "os.makedirs(\"Input\", exist_ok=True)\n", |
42 | 42 | "if not os.path.exists(MESH_FILE):\n", |
43 | | - " url = 'https://data.kitware.com/api/v1/file/5c43feba8d777f072b0cd3da/download'\n", |
| 43 | + " url = \"https://data.kitware.com/api/v1/file/5c43feba8d777f072b0cd3da/download\"\n", |
44 | 44 | " urlretrieve(url, MESH_FILE)" |
45 | 45 | ] |
46 | 46 | }, |
47 | 47 | { |
48 | 48 | "cell_type": "code", |
49 | | - "execution_count": 3, |
50 | | - "metadata": {}, |
51 | | - "outputs": [], |
52 | | - "source": [ |
53 | | - "mesh_input = itk.meshread(MESH_FILE, itk.D)" |
54 | | - ] |
55 | | - }, |
56 | | - { |
57 | | - "cell_type": "code", |
58 | | - "execution_count": 4, |
| 49 | + "execution_count": 5, |
59 | 50 | "metadata": {}, |
60 | 51 | "outputs": [ |
61 | 52 | { |
62 | 53 | "name": "stdout", |
63 | 54 | "output_type": "stream", |
64 | 55 | "text": [ |
65 | | - "2903\n", |
66 | | - "3263\n" |
| 56 | + "Mesh (0000026EE123F310)\n", |
| 57 | + " RTTI typeinfo: class itk::Mesh<double,3,class itk::DefaultStaticMeshTraits<double,3,3,float,float,double> >\n", |
| 58 | + " Reference Count: 1\n", |
| 59 | + " Modified Time: 28464\n", |
| 60 | + " Debug: Off\n", |
| 61 | + " Object Name: \n", |
| 62 | + " Observers: \n", |
| 63 | + " none\n", |
| 64 | + " Source: (none)\n", |
| 65 | + " Source output name: (none)\n", |
| 66 | + " Release Data: Off\n", |
| 67 | + " Data Released: False\n", |
| 68 | + " Global Release Data: Off\n", |
| 69 | + " PipelineMTime: 19016\n", |
| 70 | + " UpdateMTime: 28463\n", |
| 71 | + " RealTimeStamp: 0 seconds \n", |
| 72 | + " Number Of Points: 2903\n", |
| 73 | + " Requested Number Of Regions: 1\n", |
| 74 | + " Requested Region: 0\n", |
| 75 | + " Buffered Region: 0\n", |
| 76 | + " Maximum Number Of Regions: 1\n", |
| 77 | + " Point Data Container pointer: 0000000000000000\n", |
| 78 | + " Size of Point Data Container: 0\n", |
| 79 | + " Number Of Points: 2903\n", |
| 80 | + " Number Of Cell Links: 0\n", |
| 81 | + " Number Of Cells: 3263\n", |
| 82 | + " Cell Data Container pointer: 0000000000000000\n", |
| 83 | + " Size of Cell Data Container: 0\n", |
| 84 | + " Number of explicit cell boundary assignments: 3\n", |
| 85 | + " CellsAllocationMethod: itk::MeshEnums::MeshClassCellsAllocationMethod::CellsAllocatedDynamicallyCellByCell\n", |
| 86 | + "\n" |
67 | 87 | ] |
68 | 88 | } |
69 | 89 | ], |
70 | 90 | "source": [ |
71 | | - "print(mesh_input.GetNumberOfPoints())\n", |
72 | | - "print(mesh_input.GetNumberOfCells())" |
| 91 | + "mesh_input = itk.meshread(MESH_FILE, itk.D)\n", |
| 92 | + "\n", |
| 93 | + "assert type(mesh_input) == itk.Mesh[itk.D, 3]\n", |
| 94 | + "print(mesh_input)" |
73 | 95 | ] |
74 | 96 | }, |
75 | 97 | { |
76 | 98 | "cell_type": "code", |
77 | | - "execution_count": 5, |
| 99 | + "execution_count": 6, |
78 | 100 | "metadata": {}, |
79 | 101 | "outputs": [ |
80 | 102 | { |
|
90 | 112 | } |
91 | 113 | ], |
92 | 114 | "source": [ |
93 | | - "# Visualize points\n", |
94 | | - "for i in range(0,5):\n", |
| 115 | + "# Inspect a few points\n", |
| 116 | + "for i in range(0, 5):\n", |
95 | 117 | " print(mesh_input.GetPoints().GetElement(i))" |
96 | 118 | ] |
97 | 119 | }, |
98 | 120 | { |
99 | 121 | "cell_type": "code", |
100 | | - "execution_count": 6, |
| 122 | + "execution_count": 7, |
101 | 123 | "metadata": {}, |
102 | 124 | "outputs": [ |
103 | 125 | { |
104 | 126 | "data": { |
105 | 127 | "application/vnd.jupyter.widget-view+json": { |
106 | | - "model_id": "9a86a686b49a44bb982404601090aa47", |
| 128 | + "model_id": "dd14dc2d3e1942c48e154f89573a872d", |
107 | 129 | "version_major": 2, |
108 | 130 | "version_minor": 0 |
109 | 131 | }, |
|
119 | 141 | "view(geometries=[mesh_input])" |
120 | 142 | ] |
121 | 143 | }, |
122 | | - { |
123 | | - "cell_type": "code", |
124 | | - "execution_count": 7, |
125 | | - "metadata": {}, |
126 | | - "outputs": [], |
127 | | - "source": [ |
128 | | - "# Test preservation of point data\n", |
129 | | - "mesh_input.GetPointData().Reserve(1)\n", |
130 | | - "mesh_input.GetPointData().SetElement(0,500) #FIXME remove" |
131 | | - ] |
132 | | - }, |
133 | 144 | { |
134 | 145 | "cell_type": "markdown", |
135 | 146 | "metadata": {}, |
136 | 147 | "source": [ |
137 | 148 | "### Convert to `itk.PolyData`" |
138 | 149 | ] |
139 | 150 | }, |
140 | | - { |
141 | | - "cell_type": "code", |
142 | | - "execution_count": 8, |
143 | | - "metadata": {}, |
144 | | - "outputs": [], |
145 | | - "source": [ |
146 | | - "filter = itk.MeshToPolyDataFilter[type(mesh_input)].New(Input=mesh_input)" |
147 | | - ] |
148 | | - }, |
149 | 151 | { |
150 | 152 | "cell_type": "code", |
151 | 153 | "execution_count": 9, |
152 | 154 | "metadata": {}, |
153 | 155 | "outputs": [], |
154 | 156 | "source": [ |
155 | | - "filter.Update()" |
| 157 | + "poly_data = itk.mesh_to_poly_data_filter(mesh_input)\n", |
| 158 | + "\n", |
| 159 | + "assert type(poly_data) == itk.PolyData[itk.D]" |
156 | 160 | ] |
157 | 161 | }, |
158 | 162 | { |
159 | 163 | "cell_type": "code", |
160 | 164 | "execution_count": 10, |
161 | 165 | "metadata": {}, |
162 | | - "outputs": [], |
163 | | - "source": [ |
164 | | - "poly_data = filter.GetOutput()" |
165 | | - ] |
166 | | - }, |
167 | | - { |
168 | | - "cell_type": "code", |
169 | | - "execution_count": 11, |
170 | | - "metadata": {}, |
171 | | - "outputs": [], |
172 | | - "source": [ |
173 | | - "assert(type(poly_data) == itk.PolyData[itk.D])" |
174 | | - ] |
175 | | - }, |
176 | | - { |
177 | | - "cell_type": "code", |
178 | | - "execution_count": 12, |
179 | | - "metadata": {}, |
180 | 166 | "outputs": [ |
181 | 167 | { |
182 | 168 | "name": "stdout", |
|
407 | 393 | "polygons = poly_data.GetPolygons()\n", |
408 | 394 | "while i < 1000:\n", |
409 | 395 | " x = list()\n", |
410 | | - " for j in range(0,polygons.ElementAt(i)):\n", |
| 396 | + " for j in range(0, polygons.ElementAt(i)):\n", |
411 | 397 | " x.append(polygons.ElementAt(i + 1 + j))\n", |
412 | 398 | " print(x)\n", |
413 | 399 | " i += polygons.ElementAt(i) + 1" |
|
422 | 408 | }, |
423 | 409 | { |
424 | 410 | "cell_type": "code", |
425 | | - "execution_count": 13, |
426 | | - "metadata": {}, |
427 | | - "outputs": [], |
428 | | - "source": [ |
429 | | - "filter = itk.PolyDataToMeshFilter[type(poly_data)].New(Input=poly_data)" |
430 | | - ] |
431 | | - }, |
432 | | - { |
433 | | - "cell_type": "code", |
434 | | - "execution_count": 14, |
435 | | - "metadata": {}, |
436 | | - "outputs": [], |
437 | | - "source": [ |
438 | | - "filter.Update()" |
439 | | - ] |
440 | | - }, |
441 | | - { |
442 | | - "cell_type": "code", |
443 | | - "execution_count": 15, |
| 411 | + "execution_count": 12, |
444 | 412 | "metadata": {}, |
445 | 413 | "outputs": [], |
446 | 414 | "source": [ |
447 | | - "mesh_output = filter.GetOutput()" |
| 415 | + "mesh_output = itk.poly_data_to_mesh_filter(poly_data)\n", |
| 416 | + "\n", |
| 417 | + "assert type(mesh_output) == itk.Mesh[itk.D, 3]" |
448 | 418 | ] |
449 | 419 | }, |
450 | 420 | { |
451 | 421 | "cell_type": "code", |
452 | | - "execution_count": 16, |
| 422 | + "execution_count": 13, |
453 | 423 | "metadata": { |
454 | 424 | "scrolled": true |
455 | 425 | }, |
456 | 426 | "outputs": [], |
457 | 427 | "source": [ |
458 | | - "assert(mesh_output.GetNumberOfPoints() == mesh_input.GetNumberOfPoints())\n", |
459 | | - "assert(mesh_output.GetNumberOfCells() == mesh_input.GetNumberOfCells())\n", |
460 | | - "for i in range(0,mesh_output.GetNumberOfPoints()):\n", |
461 | | - " assert(mesh_output.GetPoint(i) == mesh_input.GetPoint(i))" |
| 428 | + "assert mesh_output.GetNumberOfPoints() == mesh_input.GetNumberOfPoints()\n", |
| 429 | + "assert mesh_output.GetNumberOfCells() == mesh_input.GetNumberOfCells()\n", |
| 430 | + "for i in range(0, mesh_output.GetNumberOfPoints()):\n", |
| 431 | + " assert mesh_output.GetPoint(i) == mesh_input.GetPoint(i)" |
462 | 432 | ] |
463 | 433 | }, |
464 | 434 | { |
465 | 435 | "cell_type": "code", |
466 | | - "execution_count": 17, |
| 436 | + "execution_count": 14, |
467 | 437 | "metadata": {}, |
468 | 438 | "outputs": [ |
469 | 439 | { |
470 | 440 | "data": { |
471 | 441 | "application/vnd.jupyter.widget-view+json": { |
472 | | - "model_id": "de7f8f07558e443392b3dbd6859b2ef0", |
| 442 | + "model_id": "71ab9ed224294f46a4ecc1711b479cea", |
473 | 443 | "version_major": 2, |
474 | 444 | "version_minor": 0 |
475 | 445 | }, |
|
488 | 458 | ], |
489 | 459 | "metadata": { |
490 | 460 | "kernelspec": { |
491 | | - "display_name": "venv-itk4", |
| 461 | + "display_name": "Python 3", |
492 | 462 | "language": "python", |
493 | | - "name": "venv-itk4" |
| 463 | + "name": "python3" |
494 | 464 | }, |
495 | 465 | "language_info": { |
496 | 466 | "codemirror_mode": { |
|
0 commit comments