×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Need to convert SLDPRT Solids to voxels
6

Need to convert SLDPRT Solids to voxels

Need to convert SLDPRT Solids to voxels

(OP)
Has anybody worked with a program that conceivably would take a solid model (organic shapes with complex surfaces) from Solidworks and output or convert to voxels? I have a customer who has some very sophisticated simulation software that relies on voxel input. My goal is to re-define the separate models into 1mm cubes or "voxels".
 From some recent reading I've deduced that voxels are "cubes" that have a number of associated properties for each cube- thus enabling things like anisotropy or optical properties, even time constraints on each cube or groups of cubes. Anyway, I assume there must be a pathway to render SLDPRT files into "slices" or other intermediate topologies that may be a step towards voxels. I've spent more than a day so far looking online for solutions to no avail. Any ideas?
Thanks in advance!

RE: Need to convert SLDPRT Solids to voxels

I would search for a neutral format translator like step, igs, sat, stl to voxel.  I hope this helps.

Rob Stupplebeen

RE: Need to convert SLDPRT Solids to voxels

I hadn't heard of Voxels till now, but of the litle I've just read, the Voxel using software would have to create the voxels.

SolidWorks does not have an export function for this. A model could be sliced up into cubes, creating a multi-body part, but I don't know if the Voxel software would recognise that.

RE: Need to convert SLDPRT Solids to voxels

(OP)
Rob;
Thanks for the suggestion- I have included neutral formats in my searches so far, I also suspect these will be much more likely to meet with success.  

RE: Need to convert SLDPRT Solids to voxels

"Very sophisticated software" that can't read IGES?

RE: Need to convert SLDPRT Solids to voxels

(OP)
I do not run or own the software package that is used by my customer so I cannot fully defend the inability to read iges files. I do know that most software is written with specific goals and specifications- many, many 3D design systems were written that do not use nor even acknowledge formats like Iges, step, or stl.
The "heritage" of the "voxel software" being used is in the medical field- using "sliced data" files orginally generated from MRI scans. The colors for various organs and tissues are then assigned to a discrete "pallette" and the similar colors on adjacent layers (slices) are combined and cut into small cubes or "voxels". Apprently this technique has been used for some time quite successfully to generate very accurate shapes of internal organs. Obviously the original goals did not include mechanical CAD software or formats. Now we are providing additional capability for the system that utilizes 3D CAD models of organs (SolidWorks) to accomplish some unique molding and fabrication. These same CAD models can be very useful as simulation input to the medical types ONLY if we can arrange it in voxels for input to their system. I deliberately ommited these details in the original post but perhaps it is useful in some way. I would describe it as evolving and merging disparate systems.

RE: Need to convert SLDPRT Solids to voxels

See if your customer can use HOOPS or VRML.

RE: Need to convert SLDPRT Solids to voxels

One of the secrets to doing real time 2D graphics with small computers is to get the problem into pixel space as soon as possible, so all of the math associated with the image can be done with integers.  E.g. Bresenham's algorithm instead of trig.
I'm guessing that voxels are used for similar reasons; not surprising given the amount of data to be stored and presented.

When the issue was first raised, I was thinking it should be a simple matter to 'voxelize' a DXF file, just by rounding all the float numbers to a chosen voxel size, a task that could be done by unix style filters... but it would still be a DXF file.


What is surprising is that there seems to be zero overlap in file formats.  I.e., while I got many hits on file formats for voxels, there doesn't appear to _be_ a neutral file format that's used in both CAD and medical imaging universes.

Maniacal, the useful neutral CAD file formats have been documented formally, and are available to the public.

Can your customer name a similarly documented and disclosed file format for voxels?   Or has he otherwise disclosed in what form the data is to arrive at his demarcation point?

 

Mike Halloran
Pembroke Pines, FL, USA

RE: Need to convert SLDPRT Solids to voxels

Here's an interesting little macro to voxelize a solid body.
It will create individual voxel bodies for an entire part.  The voxel size and fill percentage are constants at the top.

Basically, the macro will create a cubical body for each cube of the part that is filled to at least the fill percentage.

Note that voxel size is in METERS, and the fill percentage is not really percentage.  0.5 means 50%.

This will take a long time to run if you make the voxel size very small compared to the model size.

I don't particularly think it's actually very useful, but I've never seen a macro yet that takes pure math and makes dumb geometry out of it, so I thought I'd give it a shot.

CODE

Const VOXSIZE As Double = 0.01
Const FillPct As Double = 0.5

Dim swApp As SldWorks.SldWorks
Dim swMainBody As Body2
Dim allBodies As Variant
Dim TmpBod As Body2
Dim swTool As Body2
Dim swMod As Modeler
Dim myBox(8) As Double
Dim swPart As PartDoc
Dim swDoc As SldWorks.ModelDoc2
Dim NewBod As Body2
Dim NewBods As Variant
Dim BodyVol As Double
Dim BodyProps As Variant
Dim myFeat As Feature
Dim myCorners As Variant
Sub main()

Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
Set swPart = swDoc
allBodies = swPart.GetBodies2(swSolidBody, False)
Set swMainBody = allBodies(0)
Set swMod = swApp.GetModeler

myCorners = swMainBody.GetBodyBox

If myCorners(0) > myCorners(3) Then
    myCorners(0) = (CInt(myCorners(0) / VOXSIZE) + 1) * VOXSIZE
    myCorners(3) = (CInt(myCorners(3) / VOXSIZE) - 1) * VOXSIZE
Else
    myCorners(0) = (CInt(myCorners(0) / VOXSIZE) - 1) * VOXSIZE
    myCorners(3) = (CInt(myCorners(3) / VOXSIZE) + 1) * VOXSIZE
End If

If myCorners(1) > myCorners(4) Then
    myCorners(1) = (CInt(myCorners(1) / VOXSIZE) + 1) * VOXSIZE
    myCorners(4) = (CInt(myCorners(4) / VOXSIZE) - 1) * VOXSIZE
Else
    myCorners(1) = (CInt(myCorners(1) / VOXSIZE) - 1) * VOXSIZE
    myCorners(4) = (CInt(myCorners(4) / VOXSIZE) + 1) * VOXSIZE
End If

If myCorners(2) > myCorners(5) Then
    myCorners(2) = (CInt(myCorners(2) / VOXSIZE) + 1) * VOXSIZE
    myCorners(5) = (CInt(myCorners(5) / VOXSIZE) - 1) * VOXSIZE
Else
    myCorners(2) = (CInt(myCorners(2) / VOXSIZE) - 1) * VOXSIZE
    myCorners(5) = (CInt(myCorners(5) / VOXSIZE) + 1) * VOXSIZE
End If



Dim i As Double
Dim j As Double
Dim k As Double

For i = 0 To UBound(myCorners)
    Debug.Print myCorners(i)
Next i


For i = myCorners(0) To myCorners(3) Step VOXSIZE
    For j = myCorners(1) To myCorners(4) Step VOXSIZE
        For k = myCorners(2) To myCorners(5) Step VOXSIZE
            

            myBox(0) = i 'x
            myBox(1) = j 'y
            myBox(2) = k 'z
            myBox(3) = 0 'x
            myBox(4) = 0 'y
            myBox(5) = 1 'z
            myBox(6) = VOXSIZE 'width
            myBox(7) = VOXSIZE 'length
            myBox(8) = VOXSIZE 'height

            Set swTool = swMod.CreateBodyFromBox(myBox)

            Set TmpBod = swMainBody.Copy
            NewBods = TmpBod.Operations2(SWBODYINTERSECT, swTool, Empty)
            Set TmpBod = Nothing
            Set swTool = Nothing
            If IsArray(NewBods) Then
                If Not (NewBods(0) Is Nothing) Then
                    Set NewBod = NewBods(0)
                    BodyProps = NewBod.GetMassProperties(0.05)
                    BodyVol = BodyProps(3)
                    If BodyVol > (FillPct * (VOXSIZE ^ 3)) Then
                        Set NewBod = swMod.CreateBodyFromBox(myBox)
                        NewBod.CreateBaseFeature NewBod
                        Set NewBod = Nothing
                    End If
                    Debug.Print i, j, k
                End If
            End If
        Next k
    Next j
Next i
End Sub

-handleman, CSWP (The new, easy test)

RE: Need to convert SLDPRT Solids to voxels

(OP)
Mike Halloran- I really appreciate your insights and replies- these look genuinely helpful. You seem to have a good understanding of the underlying conundrum with file formats that do not easily "bridge" the CAD world to the Medical files...
I will see if I can find a "neutral" format that is acceptable to the customer's needs and helps define a mutual "demarcation".  

RE: Need to convert SLDPRT Solids to voxels

(OP)
Handleman:

WOW! Your reply may be exactly what I need if I can figure how to use it. Thank you very much for the effort and interest you've shown!

Can you give me an idea of how this can be used? I need to know the input data format, how to "execute" the file, etc...

Thank You!

RE: Need to convert SLDPRT Solids to voxels

(OP)
Handleman:

I copied and pasted the script- assuming it is a macro to run in Soliworks, renamed the extension as .swb.
I then tried running the "macro" on a simple cube about 1in x 1in x .4in, it appeared to run (no errors) but where does it put the results? I cannot see any changes to the actual part or any new file that may have been created...

thx in advance

RE: Need to convert SLDPRT Solids to voxels

Based on my understanding, voxel is to 3d CAD as TIFF file is to DXF file (one is mathematical and the other is discrete pixel data).  You are looking at "3d" pixels because it's one of the few ways to work with highly varied data in 3d, as opposed to parts made of 100% the same material.  In fact, computer games used this for 3d graphics before hardware 3d processing was common.

This article talks about going from MRI data to CAD data, so you are looking to go the other direction.  So apparently tools exists for at least one direction.
http://www.devicelink.com/mddi/archive/97/03/017.html

The biggest detail is to understand the format that is expected, since I suspect it may be specific to each system out there.

RE: Need to convert SLDPRT Solids to voxels

This program appears to do this function, but may or may not be suitable for your needs.

It can import 3D cad format and convert it to its native format then to a voxel format.

http://www.whiterockscience.com/moritz/voxel.html

RE: Need to convert SLDPRT Solids to voxels

Maniacal, a cube is exactly the wrong example to feed to Handleman's code.  If I'm understanding it correctly, it will just subdivide the original cube into a bunch of smaller cubes, all adjacent and visually indistinct.

Better to start with a cylinder or a sphere.

But you've then still got a Solidworks file, not a voxel file... but keepin may have solved that problem.

 

Mike Halloran
Pembroke Pines, FL, USA

RE: Need to convert SLDPRT Solids to voxels

To use it, go to Tools->Macro->New.  Make sure "SolidWorks VBA Macro" is selected from the popup's dropdown and type in a name for the new macro.  The correct extension (.swp) will be added automatically.  Once you accept the name, you should be presented with a code editing window containing a couple of lines of code.  Completely delete those code lines and paste in the macro text, then save.  Then you can run the macro.  You should modify the constant for voxel size based on your model size.  0.001m (1mm) voxels would be ridiculous for a model on the order of a meter or so.   

-handleman, CSWP (The new, easy test)

RE: Need to convert SLDPRT Solids to voxels

What you really need more than anything else is communication.  For you customer to simply say "send me voxels" is absurd.  What was your customer paying for?  If they needed voxels, why was the work done in SW?

The voxel model request could be coming from anywhere, most likely a non-techie who only knows what he's been told to ask for.  What you need to do is get on the phone with the person who actually runs the software and find out what they might be able to use.

Get a list of formats their software can import, and compare it to what SW can export.  You may need to try several different formats before finding a winner.

RE: Need to convert SLDPRT Solids to voxels

(OP)
keepinitcool and Milehalloran;

Thanks again for the great suggestions, code, and links- I will work on this later in the week as an opportunity to learn more about voxels and possibly provide a solution. Seems that voxels are one of the few formats that enable highly detailed characteristics in a 3D model to accurately convey anisotropy, non-homogeneity, temporal assets, etc.. I'm taking full scale CAD models of organs (approx 100-400mm typical dimensions) and dividing down to 1mm voxels- should be reasonable.

I'm attempting this particular solution for my customer freely- I have separately provided several related CAD organic models and molded parts that will benefit from the voxel code when done.
Outstanding, much appreciated! This hopefully will benefit many people in the longer run!  

RE: Need to convert SLDPRT Solids to voxels

This thread has definately piqued my interest in the voxel format, as I can see the real world applications for it.  

Converting between formats should be acheivable once the syntax issue is sorted out.  Looks like the voxel format is a bit of a nightmare though, with every viewer etc having their own file format.

Voxel to SW looks like the creation of a number of cubes at specified positions.  From what I can find, traversing through the voxel file and deciding whether a voxel is to be displayed solid or not is all that should be needed.

SW to voxel is likely to be very similar to handleman's code, but instead of creating cubes, it is about deciding whether the cube has enough volume to be considered a full voxel.

After a bit of a search for more info, I came across the following site.  The first links may be of use to those trying to have a play with these.

 

RE: Need to convert SLDPRT Solids to voxels

(OP)
Cpretty;
Thanks for the link to lots of interesting info related to voxels- my initial foray into the sites indicates this should prove useful in several ways. I also agree with your comments about the boundary definition for the voxels, this should be done in a very coordinated manner. In my understanding so far, if one has a single, homogenous, arbitrarily shaped "organic" solid it can be subdivided into voxels but the outer surface(s) boundary is typically done using some type of threshold or averaging scheme for the outermost voxels. Unfortunately this may not be the optimal plan for adjacent solids.
As a simplified organ pair example, the heart and lungs are very close physically, so if both are "voxelized" simultaneously (resulting in two separate "voxel solids", the surface(s) boundary voxels will be significantly different than when a single organ is voxelized (i.e. heart OR lungs separately and independently). The "multi-solid" strategy affects the tiny "airspaces" between the adjacent organs in significant ways and it is typically important to minimize "air" where it does not actually exist in various types of simulations.

RE: Need to convert SLDPRT Solids to voxels

From what I read, some voxel formats include data for surface normal.  This would go a long way toward improving analysis results without excessively high resolution.

RE: Need to convert SLDPRT Solids to voxels

Whatever you end up doing, I doubt a SW document made up of a bunch of cubes will be an intermediate format you want to mess with.  The sheer number of 1mm cubes in a volume will blow SW up.  Think about it - there are 1,000,000 cubes of 1mm side in a 100mm cube.  SW struggles to generate a 100x100 pattern of 1mm cubes (10,000 cubes) in an assembly pattern feature.  Patterning that square into a 1,000,000 piece cube brings it to its knees.  

Multibody parts don't even perform as well as assemblies.

 

-handleman, CSWP (The new, easy test)

RE: Need to convert SLDPRT Solids to voxels

Just for completeness and educational value, here is the best macro I could come up with for voxelization.  It's much, much faster than the one posted above, but still pretty slow, and will run out of memory if you try to do too big a model.  Instead of solid bodies within the part, it creates a new assembly with a bunch instances of a voxel part, which is also automatically created.  For reference, a part which voxelized to 15,344 elements took 54 seconds to analyze and 160 seconds to create the assembly.  SW runs out of memory during voxel calculation somewhere around 100,000 voxels.

-handleman, CSWP (The new, easy test)

RE: Need to convert SLDPRT Solids to voxels

handleman,

I expect that a cloud of points at the centers of the cubes that you are currently creating would be as useful as an array of cubes as a starting point for voxelization.

Eric

RE: Need to convert SLDPRT Solids to voxels

(OP)
Handleman:
HOLY COW! The macro you provided works really well! I ran it on a 0.5in dia hemisphere with 1mm voxels and 50% fill settings, the results are shown in the attached pictorial.The 50% setting appears to produce a "3D circumscribed" voxel arrangement. This is a great start towards my goals on voxels! The macro ran about 2.1 secs generating the voxels, and about 4secs creating the assembly with 798 voxels. When I created a more complex "organic" part measuring about 5in x 2in x 1in and asked for 1mm voxels it generated about 75,000 voxels in about 5 minutes and I stopped the assembly sequence after 30 minutes. It was obviously struggling with the task too much. But I believe this has convinced me that there is a decent solution using this or a similar strategy. I've asked my customer to provide a sample format for the voxels he can use, I'll try to proceed from there. I really appreciate this invaluable and enlightening glimpse into the macros with SolidWorks- I'd never used macros with SW before and it is awesome! Thank you very much!!

RE: Need to convert SLDPRT Solids to voxels

Glad you liked the macro.... It's got an error.

Not a huge one, but I never reset the body volume summation to zero.  Meaning that once it found one voxel that was full enough, the percentage was essentially anything over zero for all subsequent voxels.

Attached are two versions, one that's similar to the earlier posted one except that you can set a max number of voxels per assembly.  Once that number is reached, the assembly is saved, closed, and another picks up where that one left off.  Once the macro finishes, you can easily assemble the different subassemblies into one main assembly.  If SW will do it, that is.

The other version incorporates Eric's suggestion of a 3D sketch point cloud.  It's much simpler.

http://files.engineering.com/getfile.aspx?folder=e8cf3b90-a1d7-4b2b-a024-1669882ce51f&file=Voxelizer(POINTS).swp

http://files.engineering.com/getfile.aspx?folder=71ad5ca4-442f-4922-b12a-9a139c0f1091&file=Voxelizer(SOLIDS).swp

-handleman, CSWP (The new, easy test)

RE: Need to convert SLDPRT Solids to voxels

(OP)
Handleman;
You are really outstanding! I certainly appreciate your creative and useful macros. I'm definitely looking forward to exercising these newer versions to see how they work. I also enjoy "dissecting" these macros so I can use them as a teaching tool for myself. Truly awesome!
Thank you very much!

RE: Need to convert SLDPRT Solids to voxels

Hi all heres a software link for voxel sculpting instrutions .plus a link www.3d-coat.com/
 
Also blender 3d has a developer designing a plugin or script for future addition to  its core functions.
it is still very much at alpha testing stage but could be a valuable conversion tool for you later on save sw part out as as iges or sat and import it in to blender and save out as voxel format .
  just something to keep an eye on
   Cheers
 

RE: Need to convert SLDPRT Solids to voxels

This was a very interesting topic, how have things developed?

CSWP-Surf

RE: Need to convert SLDPRT Solids to voxels

(OP)
KevinDeSmet;
The information gathered from this thread has been very useful for my goal of converting Solidworks models to Voxels. The primary work I'm doing now is learning to write and adapt some of the initial Solidworks macro conversion programs provided by Handleman in this thread... This has opened my eyes to a whole new world of powerful functionality within SolidWorks that I'd never used before. I was unsure about whether the initial thread was more likely to solicit meaningful replies in the computer programming forums or the Solidworks forum (I actually double posted the intial query- a no-no)- now I'm glad that I chose the SolidWorks forum because I'll use these newfound skills on many varied problems in SolidWorks!  

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources