POV-Ray : Newsgroups : povray.general : .ply macros Server Time
25 Nov 2024 04:44:05 EST (-0500)
  .ply macros (Message 1 to 1 of 1)  
From: Anthony D  Baye
Subject: .ply macros
Date: 1 Mar 2016 01:15:01
Message: <web.56d53218ca66a076fd6b6fe10@news.povray.org>
I created a couple macros for writing point cloud data to Stanford Polygon
format, and thought I'd share.

use like so:
#declare header = ply_header(FORMAT, VERSION, AUTHOR, DESC, POINT_COUNT)
write_ply(FILENAME, header, DATA)

e.g.
#local header = ply_header("ascii", 1.0, "Anthony D. Baye", "A twisteded
hexagonal column", pC)
write_ply("HexColumn.ply", header, DATA)

#macro ply_header(FMT, VRS, ATH, DSC, VCT)
array[9] {
    "ply\r\n",
    concat("format " FMT, " ", str(VRS,1,1), "           { ascii/binary, format
version number }\r\n"),
    concat("comment made by ", ATH, "     { comments keyword specified, like all
lines }\r\n"),
    concat("comment ", DSC, "\r\n"),
    concat("element vertex ", str(VCT, 0,0), "          { define \"vertex\"
element, ", str(VCT,0,0), " of them in file }\r\n"),
    "property float x           { vertex contains float \"x\" coordinate }\r\n",
    "property float y           { y coordinate is also a vertex property }\r\n",
    "property float z           { z coordinate, too }\r\n",
    "end_header                 { delimits the end of the header }\r\n"
    }
#end

#macro write_ply(FILENAME, HEADER, DATA)
    #fopen pCloudFile FILENAME write
        #for(L,0,dimension_size(HEADER,1)-1,1)
            #write(pCloudFile, HEADER[L])
        #end
        #for(P,0,dimension_size(DATA,1)-1,1)
            #write(pCloudFile, vstr(3, DATA[P], " ",0,6), "\r\n")
        #end
    #fclose pCloudFile
#end


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.