Difference between revisions of "Contrib:BondMatt/Pointclouds"

From CAELinuxWiki
Jump to: navigation, search
Line 5: Line 5:
 
<br/>
 
<br/>
 
<br/>
 
<br/>
import salome <br/>
+
<nowiki>import salome <br/>
import geompy <br/>
+
import geompy <br/>
import smesh, SMESH <br/>
+
import smesh, SMESH <br/>
import math <br/>
+
import math <br/>
import GEOM <br/>
+
import GEOM <br/>
import SALOMEDS <br/>
+
import SALOMEDS <br/>
from Numeric import * <br/>
+
from Numeric import * <br/>
global pnt <br/>
+
global pnt <br/>
XYZM=array([ Note: text file contents are copied here ]); <br/>
+
XYZM=array([ Note: text file contents are copied here ]); <br/>
for i in range (1, 9, 3): <br/>
+
for i in range (1, 9, 3): <br/>
pnt=geompy.MakeVertex (XYZM[i],XYZM[i+1],XYZM[i+2]) <br/>
+
pnt=geompy.MakeVertex (XYZM[i],XYZM[i+1],XYZM[i+2]) <br/>
geompy.addToStudy(pnt,"pnt")
+
geompy.addToStudy(pnt,"pnt")</nowiki>
 
<br/>
 
<br/>
 
<br/>
 
<br/>
Line 25: Line 25:
 
<br/>
 
<br/>
 
<br/>
 
<br/>
% load point cloud data
+
<nowiki>% load point cloud data
 
B=load('Evenflow Baby Seat.xyz');
 
B=load('Evenflow Baby Seat.xyz');
 
leB=length(B);
 
leB=length(B);
Line 127: Line 127:
 
fprintf(fid,'\r\n');
 
fprintf(fid,'\r\n');
 
fprintf(fid,'\r\n');
 
fprintf(fid,'\r\n');
fprintf(fid,'+1 0');
+
fprintf(fid,'+1 0');</nowiki>
 
<br/>
 
<br/>
 
<br/>
 
<br/>
Line 134: Line 134:
 
<br/>
 
<br/>
 
<br/>
 
<br/>
% create .dyn file with nodes
+
<nowiki>% create .dyn file with nodes
 
%B=load('Evenflow Baby Seat.xyz');
 
%B=load('Evenflow Baby Seat.xyz');
 
%leB=length(B);
 
%leB=length(B);
Line 156: Line 156:
 
     m=m+1;
 
     m=m+1;
 
end
 
end
fprintf(fid,'*END');
+
fprintf(fid,'*END');</nowiki>
 
<br/>
 
<br/>
 
<br/>
 
<br/>
 
Only the newest versions of LSPP have the ability to create surfaces from a point cloud (v3.0+). Additionally, since there are only nodes in this model and no elements the nodes are unreferenced and hidden by the default LSPP settings. It can be helpful to turn on visualization of unreferenced nodes (there is a button in the menus along the bottom of the LSSPP window). The point cloud to surface tool can be found in the surfaces toolbar.
 
Only the newest versions of LSPP have the ability to create surfaces from a point cloud (v3.0+). Additionally, since there are only nodes in this model and no elements the nodes are unreferenced and hidden by the default LSPP settings. It can be helpful to turn on visualization of unreferenced nodes (there is a button in the menus along the bottom of the LSSPP window). The point cloud to surface tool can be found in the surfaces toolbar.

Revision as of 01:02, 2 August 2011

This page describes procedures used to create standard CAD format entities from point clouds in a text file format.
3D scanners can now be made using inexpensive equipment. Additionally, providers of this service in industry commonly offer 3D scanning at very affordable rates. The data that is obtained from this process can simply consist of a text file where each row consists of three floating point decimal numbers separated by commas. While commercial software with astonishing capabilities exist, they can be very expensive. Using Octave, Salome, and LS-Prepost (all freely available) CAD entities, including surfaces, can be generated.

The Salome platform ([1] available for Windows here: [2]) is an outstanding contribution to open source CAD software. One very interesting capability is the ability to output and read Python scripts. After completing tasks using the GUI one can output a Python script. This script can then be edited and imported to accomplish almost any task. Such a script can be used to generate points from the text file that may be the deliverable from the 3D scanning process. Such a script follows:

import salome <br/> import geompy <br/> import smesh, SMESH <br/> import math <br/> import GEOM <br/> import SALOMEDS <br/> from Numeric import * <br/> global pnt <br/> XYZM=array([ Note: text file contents are copied here ]); <br/> for i in range (1, 9, 3): <br/> pnt=geompy.MakeVertex (XYZM[i],XYZM[i+1],XYZM[i+2]) <br/> geompy.addToStudy(pnt,"pnt")

This is a crude solution with several disadvantages. As noted the text file with the coordinates of the points is directly copied into the script. With relatively small 3D scanning jobs there are millions of points and just copying the text from one file to another can take a decent workstations quite some time. Additionally, the format of the data must be consistent with Python syntax. Once this script is submitted to Salome a point cloud with millions of entities can take several hours to run. Also, visualizing the results is almost impossible. Several CAD environments were tested and all were unusable due to the large number of entities. The python script as shown does not group the points into a single entity, an operation that makes the CAD model much less computationally intensive. However, a simple revision of this script to accomplish this grouping does not seem possible.

Octave ([3]), which is very similar to MATLAB, is an environment in which rather complex computations can be completed very easily. It is quite simple to use this software to write files that use ASCII text. Octave is also available for Windows ([4]) and the XOctave GUI is highly recommended: [5]. A relatively simple script can directly generate a BREP CAD format file from a text file containing points from a 3D scanner:

% load point cloud data B=load('Evenflow Baby Seat.xyz'); leB=length(B); m=1; for k=1:100:leB-100 A(m,1)=B(k,1); A(m,2)=B(k,2); A(m,3)=B(k,3); m=m+1; end le=length(A); %A=[1 1 1; 2 2 2; 3 3 3; 4 4 4; 5 5 5; 6 6 6; 7 7 7; 8 8 8; 9 9 9; 0 0 0]; %le=length(A); % open file fid=fopen('evenflow3.brep','w'); % print BREP file type header fprintf(fid,'DBRep_DrawableShape'); fprintf(fid,'\r\n'); fprintf(fid,'\r\n'); fprintf(fid,'CASCADE Topology V1, (c) Matra-Datavision'); fprintf(fid,'\r\n'); fprintf(fid,'Locations 0'); fprintf(fid,'\r\n'); fprintf(fid,'Curve2ds 0'); fprintf(fid,'\r\n'); fprintf(fid,'Curves 0'); fprintf(fid,'\r\n'); fprintf(fid,'Polygon3D 0'); fprintf(fid,'\r\n'); fprintf(fid,'PolygonOnTriangulations 0'); fprintf(fid,'\r\n'); fprintf(fid,'Surfaces 0'); fprintf(fid,'\r\n'); fprintf(fid,'Triangulations 0'); fprintf(fid,'\r\n'); fprintf(fid,'\r\n'); fprintf(fid,'TShapes '); fprintf(fid,'%i',le+1); fprintf(fid,'\r\n'); fprintf(fid,'Ve'); fprintf(fid,'\r\n'); fprintf(fid,'1e-007'); fprintf(fid,'\r\n'); fprintf(fid,'%f',A(1,1)); fprintf(fid,' '); fprintf(fid,'%f',A(1,2)); fprintf(fid,' '); fprintf(fid,'%f',A(1,3)); fprintf(fid,'\r\n'); fprintf(fid,'0 0'); fprintf(fid,'\r\n'); fprintf(fid,'\r\n'); for i=2:le fprintf(fid,'0101111'); fprintf(fid,'\r\n'); fprintf(fid,'*'); fprintf(fid,'\r\n'); fprintf(fid,'Ve'); fprintf(fid,'\r\n'); fprintf(fid,'1e-007'); fprintf(fid,'\r\n'); fprintf(fid,'%f',A(i,1)); fprintf(fid,' '); fprintf(fid,'%f',A(i,2)); fprintf(fid,' '); fprintf(fid,'%f',A(i,3)); fprintf(fid,'\r\n'); fprintf(fid,'0 0'); fprintf(fid,'\r\n'); fprintf(fid,'\r\n'); end fprintf(fid,'0101111'); fprintf(fid,'\r\n'); fprintf(fid,'*'); fprintf(fid,'\r\n'); fprintf(fid,'Co'); fprintf(fid,'\r\n'); fprintf(fid,'\r\n'); fprintf(fid,'1100000'); fprintf(fid,'\r\n'); for j=1:le fprintf(fid,'+'); fprintf(fid,'%i',le+2-j); fprintf(fid,' 0 '); end fprintf(fid,'*'); fprintf(fid,'\r\n'); fprintf(fid,'\r\n'); fprintf(fid,'+1 0');

The resulting file has one advantage over the Salome script: the points are grouped into one entity. Any CAD engine will run much more efficiently with this arrangement. However, this does not generate surfaces. My goal in creating this BREP file was to create a CAD entity I could bring into the LS-DYNA pre-processor LS-PrePost (LSPP). LS-PrePost has crude point cloud to surface generation capabilities. Geomagic studio is much more capable (and expensive, $6000 for a license, LSPP is free). However, LS-PrePost does not accept BREP files. Additionally, even if the BREP file is converted to IGES or STEP, formats LSPP accepts, LSPP will bog down upon attempting to open a CAD file with a large number of entities. Furthermore, once the files is open (which I only achieved by reducing the number of points) I was unable to use CAD entities with the surface generation tools. Therefore, I created the following script to create nodes of a finite element mesh from the points:

% create .dyn file with nodes %B=load('Evenflow Baby Seat.xyz'); %leB=length(B); % open file fid=fopen('evenflow-nodes2.dyn','w'); fprintf(fid,'*KEYWORD\r\n*TITLE\r\n$#title\r\nLS_DYNA keyword deck\r\n*NODE\r\n'); fprintf(fid,'$# nid x y z tc rc\r\n'); m=1; for i=1:100:leB-100 fprintf(fid,'%i',m); fprintf(fid,','); fprintf(fid,'%f',B(i,1)); fprintf(fid,','); fprintf(fid,'%f',B(i,2)); fprintf(fid,','); fprintf(fid,'%f',B(i,3)); fprintf(fid,'0, 0\r\n'); m=m+1; end fprintf(fid,'*END');

Only the newest versions of LSPP have the ability to create surfaces from a point cloud (v3.0+). Additionally, since there are only nodes in this model and no elements the nodes are unreferenced and hidden by the default LSPP settings. It can be helpful to turn on visualization of unreferenced nodes (there is a button in the menus along the bottom of the LSSPP window). The point cloud to surface tool can be found in the surfaces toolbar.