Skip to content

Commit 43c185f

Browse files
fsalmoirmtezzele
authored andcommitted
Tutorial iges (#62)
* new tutorial on iges file * modified picture added * some font changes to tutorial
1 parent cc2f97b commit 43c185f

File tree

3 files changed

+149
-0
lines changed

3 files changed

+149
-0
lines changed
22.6 KB
Loading
8.19 KB
Loading

tutorials/tutorial-2-iges.ipynb

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
{
2+
"metadata": {
3+
"name": ""
4+
},
5+
"nbformat": 3,
6+
"nbformat_minor": 0,
7+
"worksheets": [
8+
{
9+
"cells": [
10+
{
11+
"cell_type": "heading",
12+
"level": 1,
13+
"metadata": {},
14+
"source": [
15+
"PyGeM"
16+
]
17+
},
18+
{
19+
"cell_type": "heading",
20+
"level": 2,
21+
"metadata": {},
22+
"source": [
23+
"Tutorial 2: Free Form Deformation on a cylinder in iges file format"
24+
]
25+
},
26+
{
27+
"cell_type": "markdown",
28+
"metadata": {},
29+
"source": [
30+
"In this tutorial we will show the typical workflow. In particular we are going to parse the parameters file for the FFD, read an iges file of a cylinder, perform the FFD and write the results on a new iges file. We also provide the example of the show function which is not present in tutorial 1."
31+
]
32+
},
33+
{
34+
"cell_type": "markdown",
35+
"metadata": {},
36+
"source": [
37+
"First of all we just import pygem package, we set matplotlib for the notebook and we read a parameters file."
38+
]
39+
},
40+
{
41+
"cell_type": "code",
42+
"collapsed": false,
43+
"input": [
44+
"import pygem as pg\n",
45+
"\n",
46+
"params = pg.params.FFDParameters()\n",
47+
"params.read_parameters(filename='../tests/test_datasets/parameters_test_ffd_iges.prm')"
48+
],
49+
"language": "python",
50+
"metadata": {},
51+
"outputs": [],
52+
"prompt_number": 1
53+
},
54+
{
55+
"cell_type": "markdown",
56+
"metadata": {},
57+
"source": [
58+
"Now we have to load the iges file on which we will perform the FFD. Since it is an iges we use the IgesHandler() class. The parse method extract the control points (or poles) coordinate of the NURBS surfaces that represent each face of the iges geometry without touching the topology."
59+
]
60+
},
61+
{
62+
"cell_type": "code",
63+
"collapsed": false,
64+
"input": [
65+
"iges_handler = pg.igeshandler.IgesHandler()\n",
66+
"mesh_points = iges_handler.parse('../tests/test_datasets/test_pipe.iges')"
67+
],
68+
"language": "python",
69+
"metadata": {},
70+
"outputs": [],
71+
"prompt_number": 2
72+
},
73+
{
74+
"cell_type": "markdown",
75+
"metadata": {},
76+
"source": [
77+
"We can now use the show method to visualize the iges geometry. It basically load the file and shows its geometry. It is different from the plot method since:\n",
78+
"- it shows directly the geometry and not its triangulation\n",
79+
"- it can not save the picture in a png file (it shows only)\n",
80+
"\n",
81+
"Here you can see the result of \n",
82+
"\n",
83+
"\n",
84+
" iges_handler.show('../tests/test_datasets/test_pipe.iges')\n",
85+
"\n",
86+
"\n",
87+
"![](pictures/cylinder_orig.png)\n",
88+
"\n",
89+
"For some \"backend\" issues we can show only one shape for session. Be careful when you try to show many geometries in the same script.\n",
90+
"\n",
91+
"Finally we can actually perform the FFD with the freeform module and then we can write the modified iges file with the new control points (or poles)."
92+
]
93+
},
94+
{
95+
"cell_type": "code",
96+
"collapsed": false,
97+
"input": [
98+
"free_form = pg.freeform.FFD(params, mesh_points)\n",
99+
"free_form.perform()\n",
100+
"new_mesh_points = free_form.modified_mesh_points\n",
101+
"\n",
102+
"iges_handler.write(new_mesh_points, 'test_pipe_mod.iges')"
103+
],
104+
"language": "python",
105+
"metadata": {},
106+
"outputs": [],
107+
"prompt_number": 3
108+
},
109+
{
110+
"cell_type": "markdown",
111+
"metadata": {},
112+
"source": [
113+
"Sometimes the write method can fail. In fact, in write function we perform some operations like \n",
114+
"- linking edges into a single wire; \n",
115+
"- trimming the surface with the wire.\n",
116+
"\n",
117+
"Often, a CAD file has its own tolerance and some entities that seems to be, for instance, linked actually are not.\n",
118+
"The linking and trimming operations can be hard for the software to be performed, especially when the starting CAD has not been made for analysis but for design purposes.\n",
119+
"Thus, for non trivial geometries it could be necessary to increase the tolerance.\n",
120+
"For the cylinder this is not the case, but we can increse the tolerance as well and write a, indeed almost equal, result."
121+
]
122+
},
123+
{
124+
"cell_type": "code",
125+
"collapsed": false,
126+
"input": [
127+
"iges_handler.write(new_mesh_points, 'test_pipe_mod.iges', 1e-3)"
128+
],
129+
"language": "python",
130+
"metadata": {},
131+
"outputs": [],
132+
"prompt_number": 4
133+
},
134+
{
135+
"cell_type": "markdown",
136+
"metadata": {},
137+
"source": [
138+
"And here we show the final shape:\n",
139+
"\n",
140+
" iges_handler.show('test_pipe_mod.iges')\n",
141+
"\n",
142+
"![](pictures/cylinder_mod.png)"
143+
]
144+
}
145+
],
146+
"metadata": {}
147+
}
148+
]
149+
}

0 commit comments

Comments
 (0)