Point cloud vertex color


#1

Hi !

Does any one knows of a way /script to assign vertex color to a point cloud ?

Thank you
Shim


#2

Hi, how do you plan to determine the colors for the pointcloud?
By X,Y and/or Z value, or are the points to be colored one by one, or by proximity to a mesh etc?

-J


#3

Hi Holo,

I would prefer to do it by z values. but frankly I m not really sure how to assign any color at all. my intention is to export it to ply with the vertex color.

Thank you


#4

As far as I know:
You would have to make a python script that reads all the original points into an array, then make a new array for all the z values and then make a new pointcloud that gets the colors assigned to replace the old.


(Willem Derks) #5

Hi Shimon,

Below is a quick setup that might get you started:

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
"""
script by willemderks.com
quick n dirty setup to show how colors can be set to an existing pointcloud
color is set to a grey value relative to the lowest and highest point in the cloud
"""


def pointcloud_zcolor():
    
    ptcloud = rs.GetObject('select pointcloud',filter = rs.filter.pointcloud)
    if not ptcloud : retun
    
    
    
    
    
    #here we find the minimal and maximum Z value to be used to set the color
    bbox = rs.BoundingBox(ptcloud)
    zmin = bbox[0].Z
    zmax = bbox[4].Z
    
    #interval to easily calculate color later
    interval = Rhino.Geometry.Interval(zmin,zmax)
    
    #get rhinocommon pointcloud geometry object here
    pcloud_geometry = rs.coercegeometry(ptcloud)
    pass
    #itterate through the points in the cloud and set the color based on the z value
    for p in pcloud_geometry:
        #color factor at point z
        cfactor  = interval.NormalizedParameterAt(p.Z)
        color_gray_value = int(255*cfactor)
        color = rs.coercecolor([color_gray_value,color_gray_value,color_gray_value])
        
        p.Color = color 
        
    
    sc.doc.Objects.Replace(ptcloud,pcloud_geometry)
    
    
pointcloud_zcolor()

pcloud_height_grey.py (1.3 KB)

HTH
-Willem


#6

Thank you !

I will give it a go


#7

Another quick question for you experts…

Is it possible to export point cloud and a mesh objects in the same OBJ or PLY file?

Thanks again!


(Dale Fugier) #8

Sure, just script either the SaveAs or Export command using rs.Command.

– Dale