Hi
In the points workbench, is it possible to colour each point in a collection individually (presumably via python)? I have in the region of 5000 points so I don't really want each point as a separate object in the tree.
This actually comes about from having a 3D sample space, with each sample point having an error associated with it - so I figured that having sample points in FreeCAD and colouring by the error might be a good way of visualising the data.
Cheers
Joe
doh!
OS: Ubuntu 14.04 LTS
Word size: 64-bit
Version: 0.14.3681 (Git)
Branch: master
Hash: ef08a61a4dbec598101e0c1aead95a031ef53f7b
Python version: 2.7.6
Qt version: 4.8.6
Coin version: 4.0.0a
SoQt version: 1.6.0a
OCC version: 6.7.0
Individually colouring points
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: Individually colouring points
Code: Select all
import Points
class PointsFeature:
def __init__(self, obj):
obj.addProperty("App::PropertyColorList","Colors","Points","Ponts").Colors=[]
obj.Proxy = self
def execute(self, fp):
pass
FreeCAD.newDocument()
a=FreeCAD.ActiveDocument.addObject("Points::FeaturePython","Points")
PointsFeature(a)
a.ViewObject.Proxy=0
p=Points.Points()
p.addPoints([App.Vector(0,0,0),App.Vector(1,1,1),App.Vector(2,2,2)])
a.Points=p
c=[(1.0,0.0,0.0),(0.0,1.0,0.0),(0.0,0.0,1.0)]
a.Colors=c
a.ViewObject.DisplayMode="Color"
Re: Individually colouring points
Ooooh! Cool, I'll try that out tomorrow but on the face of it it looks perfect! Thanks
Re: Individually colouring points
...so I couldn't wait till tomorrow!
Beautiful, thanks very much!
Beautiful, thanks very much!
Re: Individually colouring points
I wanted this function for years
Wouldn't it make sense to implement the importer in c++ and include it in the points module?
Code: Select all
import FreeCAD
if open.__module__ == '__builtin__':
pythonopen = open # to distinguish python built-in open function from the one declared here
class PointsFeature:
def __init__(self, obj):
obj.addProperty("App::PropertyColorList","Colors","Points","Ponts").Colors=[]
obj.Proxy = self
def execute(self, fp):
pass
def parsepts(filename):
f1=pythonopen(filename)
color=[]
points=[]
for line in f1:
x,y,z,r,g,b=[float(s) for s in line.strip().split(' ')[0:6] ]
points.append(FreeCAD.Vector(x,y,z))
color.append((r/255.0,g/255.0,b/255.0))
return points,color
def createcoloredpointdcloud(doc,points,color):
import Points
obj=doc.addObject("Points::FeaturePython","Points")
PointsFeature(obj)
obj.ViewObject.Proxy=0
p=Points.Points()
p.addPoints(points)
obj.Points=p
obj.Colors=color
if FreeCAD.GuiUp:
obj.ViewObject.DisplayMode="Color"
return obj
def open(filename):
import os.path
docname = os.path.splitext(os.path.basename(filename))[0]
doc = FreeCAD.newDocument(docname)
points,color = parsepts(filename)
createcoloredpointdcloud(doc,points,color)
return doc
def insert(filename,docname):
try:
doc=FreeCAD.getDocument(docname)
except:
doc=FreeCAD.newDocument(docname)
points,color = parsepts(filename)
createcoloredpointdcloud(doc,points,color)
def registerFCTypes():
import FreeCAD
FreeCAD.addImportType("colored poind cloud (*.pts)","coloredpts")
try:
import FreeCAD
registerFCTypes()
except ImportError:
pass
Re: Individually colouring points
Since this is about python scripting I'm moving this topic from the Help forum to the appropriate forum.