Skip to content

Commit 7075a5d

Browse files
authored
fix 2d ply output for polymesh (#35)
1 parent 1558c7f commit 7075a5d

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

CHANGELOG.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ All notable changes to this project will be documented in this file.
66
The format is based on `Keep a Changelog`_,
77
and this project adheres to `Semantic Versioning`_.
88

9+
`1.4.3`_ - 2020-11-11
10+
--------------------------
11+
Fixed
12+
'''''''
13+
- PLY file format in 2D.
14+
915
`1.4.2`_ - 2020-11-3
1016
--------------------------
1117
Fixed
@@ -178,7 +184,8 @@ Added
178184

179185
.. LINKS
180186
181-
.. _`Unreleased`: https://github.com/kip-hart/MicroStructPy/compare/v1.4.2...HEAD
187+
.. _`Unreleased`: https://github.com/kip-hart/MicroStructPy/compare/v1.4.3...HEAD
188+
.. _`1.4.3`: https://github.com/kip-hart/MicroStructPy/compare/v1.4.2...v1.4.3
182189
.. _`1.4.2`: https://github.com/kip-hart/MicroStructPy/compare/v1.4.1...v1.4.2
183190
.. _`1.4.1`: https://github.com/kip-hart/MicroStructPy/compare/v1.4.0...v1.4.1
184191
.. _`1.4.0`: https://github.com/kip-hart/MicroStructPy/compare/v1.3.5...v1.4.0

src/microstructpy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
import microstructpy.seeding
55
import microstructpy.verification
66

7-
__version__ = '1.4.2'
7+
__version__ = '1.4.3'

src/microstructpy/meshing/polymesh.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,25 +273,42 @@ def write(self, filename, format='txt'):
273273
nv = len(self.points)
274274
nd = len(self.points[0])
275275
nf = len(self.facets)
276+
nr = len(self.regions)
276277
assert nd <= 3
277-
axes = ['x', 'y', 'z'][:nd]
278+
279+
# Force 3D points
280+
pts = np.zeros((nv, 3))
281+
pts[:, :nd] = self.points
282+
axes = ['x', 'y', 'z']
278283

279284
# header
280285
ply = 'ply\n'
281286
ply += 'format ascii 1.0\n'
282287
ply += 'element vertex ' + str(nv) + '\n'
283288
ply += ''.join(['property float32 ' + a + '\n' for a in axes])
284-
ply += 'element face ' + str(nf) + '\n'
285-
ply += 'property list uint8 int32 vertex_indices\n'
289+
if nd == 2:
290+
n_faces = nr
291+
else:
292+
n_faces = nf
293+
ply += 'element face {}\n'.format(n_faces)
294+
ply += 'property list uchar int vertex_indices\n'
286295
ply += 'end_header\n'
287296

288297
# vertices
289298
ply += ''.join([' '.join(['{: e}'.format(x) for x in pt]) + '\n'
290-
for pt in self.points])
299+
for pt in pts])
291300

292301
# faces
293-
ply += ''.join([str(len(f)) + ''.join([' ' + str(kp) for kp in f])
294-
+ '\n' for f in self.facets])
302+
if nd == 2: # regions -> faces
303+
facets = np.array(self.facets)
304+
ply += ''.join([str(len(r)) + ''.join([' ' + str(kp) for kp in
305+
kp_loop(facets[r])])
306+
+ '\n' for r in self.regions])
307+
308+
else: # facets -> faces
309+
ply += ''.join([str(len(f)) + ''.join([' ' + str(kp)
310+
for kp in f])
311+
+ '\n' for f in self.facets])
295312

296313
with open(filename, 'w') as f:
297314
f.write(ply)

0 commit comments

Comments
 (0)