3d point cloud data (laser scan) in blender???

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

cuzner
Posts: 2
Joined: Thu Sep 04, 2008 8:54 am
Location: uk

3d point cloud data (laser scan) in blender???

Postby cuzner » Thu Sep 04, 2008 8:56 am

Blender - 3d Point Data usefull??
Any one tried to use Laser scan Point data in Blender yet?

I have been playing with point data of buildings and machines at work in blender and I am having some success.
So far I have made use of a basic script that takes a TXT file with XYZ data and loads all the point data into blender - perfect!

What I want to know is can a script be made that would also use extra point data (RGB values) for each point and is there a way that blender can render the information - pref. without using the Halo effect.
I don't want the points to scale in size as they move towards the camera.(Halo problem)
Also I only want to use the points not a mesh.

Some great effects could be achieved with this technique.

Ideas anyone?

cuzner
Posts: 2
Joined: Thu Sep 04, 2008 8:54 am
Location: uk

Postby cuzner » Mon Sep 08, 2008 3:34 pm

Sample Point Files
Thought I would post up some sample files for people to make use of.
It is a curved surface section of a simple sphere.

I have 2 files - one is a basic .XYZ points text file
the other uses extra information cells to create the RGB colour levels of each point.

Image Sample here
http://picasaweb.google.com/cuznerdexter/PointCloudUpdatesRenderingPoints#

Sample point files here
http://uk.briefcase.yahoo.com/bc/cuznerdexter/

psullie
Posts: 554
Joined: Thu Sep 11, 2008 11:09 am
Location: Ireland

Point CLoud

Postby psullie » Thu Sep 11, 2008 11:36 am

Hi Cuzner

I too would be interested in seeing point cloud RGBXYZ data being supported in Blender. Although I'm a complete Blender Noob and have no Python experience I'd like to know how you got the XYZ data into Blender.

My current workflow requires converting the cloud to a mesh if I need to do any complicated modeling, often resulting in the loss of the RGB data.

To render Point Clouds in Blender would open up a lot of possibilities, although I'm not sure if Blender's renderer would 'see' a point cloud.

Maybe it's time I learn some python scripting...

Anyway, keep in touch and if I can help out I'll do what I can.

psullie

Absolut
Posts: 1
Joined: Fri Sep 26, 2008 7:08 pm

Postby Absolut » Fri Sep 26, 2008 7:10 pm

Hi,

I am very new in Blender and I want to do the same thing as you. To load into Blender a point cloud with XYZ values and RGB color. Can you post a tutorial how you did that? I try to do this for over a week and I still have many things to learn.

psullie
Posts: 554
Joined: Thu Sep 11, 2008 11:09 am
Location: Ireland

Postby psullie » Sat Sep 27, 2008 1:56 pm

Hi Absolut

Like you I'm new to Blender but regularly work with Point Cloud files with other software. Blender can import PLY files examples of which can be found here:
http://graphics.stanford.edu/data/3Dscanrep/
also listed are some resources for working with Cloud data.
Included are some of the original Bunny cloud scans which will open in Blender, but suffer form what Cuzner called the Halo Problem, and the Blender internal render can't see the object to render, a poly version is also listed which can be rendered (it's very small when imported so you might miss it).
Let us know if you have more success,

cheers

psullie

cyde
Posts: 6
Joined: Thu Oct 16, 2008 3:21 pm

Postby cyde » Thu Oct 16, 2008 3:46 pm

Hi

Maybe this will help you:

http://local.wasp.uwa.edu.au/~pbourke/dataformats/ply/

is a short document about the PLY format. With this you should be able to get any kind of xyzrgb data into blender - at least almost:

I have a problem myself: I imported some PLY files into blender and it works fine- except for the Vertex Colors. I just can't make them visible...

In 3D Max it's easy. After I imported the PLY file (e.g. with the HABWare PLY2MAX v4.0 for 3D Max 8 or Randall Hand – PLY File Importer v1.0 for 3D Max 2009) I just

Right Click on the object > object properties > check vertex channel display > vertex color > OK

And MAX shows me the colors.

But I can't see the colors in Blender!

Excuse me, I'm very new to blender, I would realy appreciate some help!

Thanks

psullie
Posts: 554
Joined: Thu Sep 11, 2008 11:09 am
Location: Ireland

Postby psullie » Thu Oct 16, 2008 5:04 pm

thanks for the tip cyde,

However I only have limited access to Max at work, so a Blender solution similar to what you found in Max would be ideal.

Keep digging

psullie

cyde
Posts: 6
Joined: Thu Oct 16, 2008 3:21 pm

Postby cyde » Thu Oct 16, 2008 5:37 pm

You can Download 3DS MAX Trial here: www.autodesk.com (works perfectly, also with the plugins!)

and the plugins here: http://www.maxplugins.de/ > search for "PLY", "gw::PlyImp v0.96b" or "PLY2MAX v4.0"

I would prefere a Blender based solution... if you find out how to display the colors- PLEEEEEASE POST!




:wink:

psullie
Posts: 554
Joined: Thu Sep 11, 2008 11:09 am
Location: Ireland

Postby psullie » Thu Oct 23, 2008 11:38 am

Hi Cyde

From another post I've received a note form Ideasman who has fixed this bug in importing ply vertex colors and has been submitted as an update for 2.48a

Thanks too for the links, I've seen how easy it easy it is in Max, hopefully it'll be the same in Blender.

psullie

cyde
Posts: 6
Joined: Thu Oct 16, 2008 3:21 pm

Postby cyde » Thu Oct 23, 2008 11:43 am

Thanks!
Fighting already with compiling ...



:evil:

johngflower
Posts: 25
Joined: Sat Nov 01, 2008 8:23 pm
Location: New Zealand

Postby johngflower » Sat Nov 01, 2008 8:51 pm

Hi,


I'm interested in going in the opposite direction. I want to be able to export point clouds for the purpose of Sub Surface Laser Engraving. SSLE typically involves a single laser firing into a block of crystal. The laser is focused on a point and causes the crystal to shatter creating a small white dot.

My boss has accepted the agency for a company doing SSLE and would rather that we do the artwork ourselves. I'm keen to see this work as I've been having alot of fun playing with blender at home, and would like to be paid for it :)

At the moment we're just testing the waters and have sent them a .dxf file to see if what we see on our screen will generate a good point cloud. A .obj would be better because we can include the textures - assuming they can import it (probably can, I'm guessing they're using an AutoDesk product). It would be better if we could generate the point cloud ourselves so that we have a better idea of what the engraved object will look like and thus reduce the churn of acting as an intermediary.

I've asked my boss to ask them if they can accept .obj files and for them to send a point cloud file to us. I'm hoping that the point cloud file format is a simple text file with a list of coordinates. Then the next step (possibly pie in the sky given my knowledge of python) would be to write a script export to a point cloud from blender.

Possibly this would involve:
1) Reducing the object down to a mesh
2) Using a formula to calculate the area of each face.
3) Distribute points with a density determined by the colour (greyscale?)
4) Find a nice way to handle edges between faces so that there is no obvious seam
5) Write to a file the point cloud with the points listed started from the back of the object. (So that when the laser fires it always passes through clear crystal)

The work being done to import points into blender would be very helpful for what I'm wanting to do.


Regards,

John

genesis12122
Posts: 2
Joined: Mon Nov 03, 2008 9:58 am
Location: Spain

point cloud

Postby genesis12122 » Mon Nov 03, 2008 10:03 am

i´m blender user for 2 years more or less, and actually working with faro photon lasser scanner. i´ve tried to import a large number of points into blender. Making a script is simple, but the large number of points into blender is dificult to manipulate.
And God Saw That It Was Good, And Blessed Them Saying...

johngflower
Posts: 25
Joined: Sat Nov 01, 2008 8:23 pm
Location: New Zealand

Postby johngflower » Tue Nov 18, 2008 8:54 am

Looking into it a bit further. For exporting:-

1) Use the subdivide command to create the desired number of vertices
2) Cut down the .obj, or other file format, export script so that it only exports the vertices
3) Add code to script to sort by desired axis

Output file may look like this:-

# Blender3D v247 OBJ File:
# www.blender3d.org
o Dots
v 1.000000 -0.000000 -1.000000
v -1.000000 0.000000 1.000000


Could an idea like this work for importing?

Write a script that searches a file for vertices and then creates a small pyramid using the original vertex eg

o Dots
v 0.000000 0.000000 1.000000

becomes

o Pyramid_1
v 0.000000 0.000000 1.000000
v 0.000000 1.000000 1.000000
v 0.000000 1.000000 2.000000
v 1.000000 1.000000 2.000000
s 1
f 1 2 3 4

This would create a point cloud that could be rendered accurately.

johngflower
Posts: 25
Joined: Sat Nov 01, 2008 8:23 pm
Location: New Zealand

Here's a working export script

Postby johngflower » Fri Nov 21, 2008 9:30 am

I've got a working point cloud export script. A plane with four vertices becomes:-

ply
format ascii 1.0
comment Created by Blender3D 247 - www.blender.org, source file:
element vertex 4
property float x
property float y
property float z
end_header
0.502806 1.041486 -0.046079
-1.320690 1.041486 -0.046079
-1.320690 -0.782010 -0.046079
0.502806 -0.782010 -0.046079


It is based on the current ply export script. All I've done is rip out code. Next step is to figure out a way to script subdivision of meshes. Point colour would be nice too.

For viewing the point cloud accurately I think the key is at the render stage to have a script create a mesh of a size proportional to the distance from the camera. What do you think?

Here's the export script:-

Code: Select all

#!BPY

"""
Name: 'Point Cloud PLY (*.ply)...'
Blender: 241
Group: 'Export'
Tooltip: 'Export active object to Stanford PLY format'
"""

import bpy
import Blender
from Blender import Mesh, Scene, Window, sys, Image, Draw
import BPyMesh

__author__ = "Bruce Merry"
__version__ = "0.93"
__bpydoc__ = """\
This script exports Stanford PLY files from Blender. It supports normals,
colours, and texture coordinates per face or per vertex.
Only one mesh can be exported at a time.
"""

# Copyright (C) 2004, 2005: Bruce Merry, bmerry@cs.uct.ac.za
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
# Vector rounding se we can use as keys
#
# Updated on Aug 11, 2008 by Campbell Barton
#    - added 'comment' prefix to comments - Needed to comply with the PLY spec.
#
# Updated on Jan 1, 2007 by Gabe Ghearing
#    - fixed normals so they are correctly smooth/flat
#    - fixed crash when the model doesn't have uv coords or vertex colors
#    - fixed crash when the model has vertex colors but doesn't have uv coords
#    - changed float32 to float and uint8 to uchar for compatibility
# Errata/Notes as of Jan 1, 2007
#    - script exports texture coords if they exist even if TexFace isn't selected (not a big deal to me)
#    - ST(R) should probably be renamed UV(T) like in most PLY files (importer needs to be updated to take either)
#
# Updated on Jan 3, 2007 by Gabe Ghearing
#    - fixed "sticky" vertex UV exporting
#    - added pupmenu to enable/disable exporting normals, uv coords, and colors
# Errata/Notes as of Jan 3, 2007
#    - ST(R) coords should probably be renamed UV(T) like in most PLY files (importer needs to be updated to take either)
#    - edges should be exported since PLY files support them
#    - code is getting spaghettish, it should be refactored...
#


def rvec3d(v):   return round(v[0], 6), round(v[1], 6), round(v[2], 6)
def rvec2d(v):   return round(v[0], 6), round(v[1], 6)

def file_callback(filename):
   
   if not filename.lower().endswith('.ply'):
      filename += '.ply'
   
   scn= bpy.data.scenes.active
   ob= scn.objects.active
   if not ob:
      Blender.Draw.PupMenu('Error%t|Select 1 active object')
      return
   
   file = open(filename, 'wb')
   

   is_editmode = Blender.Window.EditMode()
   if is_editmode:
      Blender.Window.EditMode(0, '', 0)
   
   Window.WaitCursor(1)
   
   
   mesh = BPyMesh.getMeshFromObject(ob, None, scn)
   
   if not mesh:
      Blender.Draw.PupMenu('Error%t|Could not get mesh data from active object')
      return
   
   mesh.transform(ob.matrixWorld)
   
   
   # incase
   normal = None
   
   verts = [] # list of dictionaries
   # vdict = {} # (index, normal, uv) -> new index
   vdict = [{} for i in xrange(len(mesh.verts))]
   vert_count = 0
   for i, f in enumerate(mesh.faces):
      
      for j, v in enumerate(f):
         vdict_local = vdict[v.index]
         
         if not vdict_local:
            vdict_local = vert_count;
            verts.append( (tuple(v.co), normal) )
            vert_count += 1
   
   
   file.write('ply\n')
   file.write('format ascii 1.0\n')
   file.write('comment Created by Blender3D %s - www.blender.org, source file: %s\n' % (Blender.Get('version'), Blender.Get('filename').split('/')[-1].split('\\')[-1] ))
   
   file.write('element vertex %d\n' % len(verts))
   
   file.write('property float x\n')
   file.write('property float y\n')
   file.write('property float z\n')

   file.write('end_header\n')

   for i, v in enumerate(verts):
      file.write('%.6f %.6f %.6f ' % v[0]) # co
      file.write('\n')
   file.close()
   
   if is_editmode:
      Blender.Window.EditMode(1, '', 0)

def main():
   Blender.Window.FileSelector(file_callback, 'PLY Export', Blender.sys.makename(ext='.ply'))

if __name__=='__main__':
   main()
Last edited by johngflower on Fri Nov 21, 2008 9:06 pm, edited 1 time in total.

stiv
Posts: 3646
Joined: Tue Aug 05, 2003 7:58 am
Location: 45N 86W

Postby stiv » Fri Nov 21, 2008 3:38 pm

You might notice that your script is unformatted. This will break the Python code. Either use the Code tag or provide a link to download.


Return to “Python”

Who is online

Users browsing this forum: No registered users and 2 guests