Skip to content

convert x,y,z format from double to float #72

Answered by dranjan
SyZbidi asked this question in Q&A
Discussion options

You must be logged in to vote

Maybe this is oversimplified for your use case, but here's an example of what I think you want. In this one, I'm converting "x", "y", and "z" from float to double.

from plyfile import PlyData

data = PlyData.read('examples/tet.ply')

new_types = {
    'x': 'double',
    'y': 'double',
    'z': 'double',
}

for prop in data['vertex'].properties:
    if prop.name in new_types:
        prop.val_dtype = new_types[prop.name]

data.write('test.ply')

data = PlyData.read('test.ply')
print(data['vertex'].data)
print(data['vertex'].data.dtype)

It should be enough simply to change the types in the PlyProperty metadata, which will force the data to be cast when writing. If that works for you, it's p…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@SyZbidi
Comment options

Answer selected by SyZbidi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #71 on July 29, 2023 15:27.