Jump to content

Help Needed, convert .csv to 3d image/object to open in CAD softwear

I've been struggling to find a way to do this for a while, i have a laser profiler (scanner) that I have retro fitted to a CNC router to scan surfaces to look at the undulations, I have to export these out of the proprietary software to a .csv file in order to stich multiple together (still working on this but am close) but i have then no way of viewing these images again as the software does not then allow you to import the .csv file back into it and will only open a .lhi file. I don't need it back into that software as i can use fusion 360 to open it, but i need to make it into a file format that will understand. fusion 360 allows a lot of 3d file types, and does have an option to import .csv files but it doesn't seem to work with the way the original software wrights the .csv files

 

I have attched the .csv file for reference 

 

any ideas would be greatly appreciated,

Thanks

csv_file.zip

Link to comment
Share on other sites

Link to post
Share on other sites

a csv is not a 3d file format. It's a table. It could represent material properties, part listing, templates. Can be millions of different things.

Do you know what the file mean ?

Link to comment
Share on other sites

Link to post
Share on other sites

If it's a height map you can generate vertices on a grid and set their height according to the table.

Then you can create triangles between those like this:

 

1--2--3--4

|\ |\ |\ |

| \| \| \|

5--6--7--8

|\ |\ |\ |

| \| \| \|

9-10-11-12

 

Where numbers are vertices and |, \, --,  are edges.

Generated .obj file can be something like this:

# list of vertices
v 0.0 0.0 <z>  # vertex 1, x=0, y=0, z=(value from .csv file)
v 1.0 0.0 <z>  # vertex 2,
...
# list of triangles
f 1 5 6    # first triangle between vertex 1, 5 and 6
f 1 2 6    # and so on
f 2 6 7
...

 

 

ಠ_ಠ

Link to comment
Share on other sites

Link to post
Share on other sites

3 hours ago, Franck said:

a csv is not a 3d file format. It's a table. It could represent material properties, part listing, templates. Can be millions of different things.

Do you know what the file mean ?

Its a height map like Shadow_ray has suggested each cell location representing a coordinate, with the number in the cell representing the height value (Z value). I'm aware that a csv isn't a 3d format, its just basically storing numbers and coordinates. I just need a way to open this type of height map image (using an existing program would be ideal if you know of any). failing that I will have to build a program to analyse the data and spit out an image.

 

Thanks for the Help 😊

Link to comment
Share on other sites

Link to post
Share on other sites

9 hours ago, Leon Butterill said:

I've been struggling to find a way to do this for a while, i have a laser profiler (scanner) that I have retro fitted to a CNC router to scan surfaces to look at the undulations, I have to export these out of the proprietary software to a .csv file in order to stich multiple together (still working on this but am close) but i have then no way of viewing these images again as the software does not then allow you to import the .csv file back into it and will only open a .lhi file. I don't need it back into that software as i can use fusion 360 to open it, but i need to make it into a file format that will understand. fusion 360 allows a lot of 3d file types, and does have an option to import .csv files but it doesn't seem to work with the way the original software wrights the .csv files

 

I have attched the .csv file for reference 

 

any ideas would be greatly appreciated,

Thanks

csv_file.zip 6.41 MB · 5 downloads

you can use auto lisp for 2d models:https://www.devcadlisp.com/autolispdev/snippet-2-codigo-lisp-para-conectar-autocad-con-ms-excel-y-obtener-los-valores-de-celdas/

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Ok. I wrote a python script to generate a grayscale .png height map from the .csv file. It's kinda ugly code but hey, it works.

 

output.thumb.png.2580c6b90cc6154c96cbf31e45f93e60.png

 

And here is the code:

Spoiler

from PIL import Image
import  csv
import math


def to_grayscale(val, min, max):
    diff = max - min
    val_diff = val - min
    ratio = val_diff / diff 
    return math.floor(ratio * 255)

rows = []
max = 0.0
min = 0.0

max_row_len = 0

with open("Scan 2_20.10.2020.csv") as csv_file:
    csv_reader = csv.reader(csv_file, delimiter=",")

    for row in csv_reader:
        new_line = []        
        for cell in row:
            val = float(cell)
            if val < -900.0:
                val = -10       # todo

            new_line.append(val)
            
            if val < min:
                min = val
            
            if val > max:
                max = val
                                                              
        rows.append(new_line)
        if len(new_line) > max_row_len:
            max_row_len = len(new_line)


print("max: " + str(max))
print("min: " + str(min))
print("rows: " + str(len(rows)))
print("max row len: " + str(max_row_len))


#img = Image.new('RGB', (len(rows), max_row_len), color = 'black')
img = Image.new('L', (len(rows), max_row_len), color = 'black')

for x, row in enumerate(rows):
    for y, value in enumerate(row):
        img.putpixel((x,y), to_grayscale(value, min, max))

img.save("output.png")

 

 

ಠ_ಠ

Link to comment
Share on other sites

Link to post
Share on other sites

3 hours ago, shadow_ray said:

btw what am i seeing here?

it seems to be a surface grill. Similar to those i used on water jet or laser cutter.

Link to comment
Share on other sites

Link to post
Share on other sites

4 hours ago, shadow_ray said:

btw what am i seeing here?

that looks good thanks, 

its just a small pice of net, the scan is 1 pass, im looking at stitching a few passe
s together to form 1 full image, the only way to do this is to export the data as the csv file, and working on stitching the images that way. i was just looking for a way to open it aain hopefully so it looks somthing like the computer image attached. 

20201022_125255.jpg

20201022_132541.jpg

Link to comment
Share on other sites

Link to post
Share on other sites

Cool.

May i ask what is the use case for this?

And could you share a pic from the machine you built? I'm kinda interested.

ಠ_ಠ

Link to comment
Share on other sites

Link to post
Share on other sites

Being Cell[0,0] is 0 x, 0 y then you can create OBJ or STL by hand. It's a text readable format in both cases. OBJ is much easier for the task at hand.

Other option to use in some cad is to simply convert to gray scale image and then create a sheet of the correct dimensions and apply the image as a bump map and you should have a viable visual part in your program.

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, shadow_ray said:

Cool.

May i ask what is the use case for this?

And could you share a pic from the machine you built? I'm kinda interested.

Im sorry i wish i could give you details and pictures but i can't, it's a project I'm working on in work so can't give too much away as its R&D stuff and you have to sign not disclosure agreements. but a basic outline is..

 

its a laser profiler scanner which is retro fitted to a cnc router machine (in place of the router attachment), and you use the cnc software to move across whatever you are scanning, and a encoder is used to monitor the location to "scale" the image correctly this is captured in a separate software for control of the laser

 

the use case is for scanning materials to look look at surface undulations to a very high accuracy. the reason iv used the above net type material is as its very easy to visualise for stitching multiple passes into one image or csv file to have a large complete scan without having to have a ridiculously big scanner with a really wide laser beam. 

 

Thankyou for all your help by the way it has helped a lot. and I'm glad your interested just sorry i can't really dive into too much detail. 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×