Skip to content

Commit

Permalink
fix 2d ply output for polymesh (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
kip-hart committed Nov 11, 2020
1 parent 1558c7f commit 7075a5d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ All notable changes to this project will be documented in this file.
The format is based on `Keep a Changelog`_,
and this project adheres to `Semantic Versioning`_.

`1.4.3`_ - 2020-11-11
--------------------------
Fixed
'''''''
- PLY file format in 2D.

`1.4.2`_ - 2020-11-3
--------------------------
Fixed
Expand Down Expand Up @@ -178,7 +184,8 @@ Added

.. LINKS
.. _`Unreleased`: https://github.com/kip-hart/MicroStructPy/compare/v1.4.2...HEAD
.. _`Unreleased`: https://github.com/kip-hart/MicroStructPy/compare/v1.4.3...HEAD
.. _`1.4.3`: https://github.com/kip-hart/MicroStructPy/compare/v1.4.2...v1.4.3
.. _`1.4.2`: https://github.com/kip-hart/MicroStructPy/compare/v1.4.1...v1.4.2
.. _`1.4.1`: https://github.com/kip-hart/MicroStructPy/compare/v1.4.0...v1.4.1
.. _`1.4.0`: https://github.com/kip-hart/MicroStructPy/compare/v1.3.5...v1.4.0
Expand Down
2 changes: 1 addition & 1 deletion src/microstructpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
import microstructpy.seeding
import microstructpy.verification

__version__ = '1.4.2'
__version__ = '1.4.3'
29 changes: 23 additions & 6 deletions src/microstructpy/meshing/polymesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,25 +273,42 @@ def write(self, filename, format='txt'):
nv = len(self.points)
nd = len(self.points[0])
nf = len(self.facets)
nr = len(self.regions)
assert nd <= 3
axes = ['x', 'y', 'z'][:nd]

# Force 3D points
pts = np.zeros((nv, 3))
pts[:, :nd] = self.points
axes = ['x', 'y', 'z']

# header
ply = 'ply\n'
ply += 'format ascii 1.0\n'
ply += 'element vertex ' + str(nv) + '\n'
ply += ''.join(['property float32 ' + a + '\n' for a in axes])
ply += 'element face ' + str(nf) + '\n'
ply += 'property list uint8 int32 vertex_indices\n'
if nd == 2:
n_faces = nr
else:
n_faces = nf
ply += 'element face {}\n'.format(n_faces)
ply += 'property list uchar int vertex_indices\n'
ply += 'end_header\n'

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

# faces
ply += ''.join([str(len(f)) + ''.join([' ' + str(kp) for kp in f])
+ '\n' for f in self.facets])
if nd == 2: # regions -> faces
facets = np.array(self.facets)
ply += ''.join([str(len(r)) + ''.join([' ' + str(kp) for kp in
kp_loop(facets[r])])
+ '\n' for r in self.regions])

else: # facets -> faces
ply += ''.join([str(len(f)) + ''.join([' ' + str(kp)
for kp in f])
+ '\n' for f in self.facets])

with open(filename, 'w') as f:
f.write(ply)
Expand Down

0 comments on commit 7075a5d

Please sign in to comment.