
Tue, 03/24/2009 - 18:44
There is a bug in the STL reader method named
Handle_StlMesh_Mesh RWStl::ReadAscii(const OSD_Path& aPath)
that is located in the file named RWStl.cxx.
The code as it stands now will not correctly read an ASCII STL file that contains more that one "solid." (See the STL file format documentation for a description of solids.) STL files with more than one solid are rare, but when they are encountered, OCC will create a BRep with a lot of garbage in it. Shown below is my fix.
Jim
Handle_StlMesh_Mesh RWStl::ReadAscii(const OSD_Path& aPath)
{
TCollection_AsciiString filename;
long ipos;
Standard_Integer nbLines = 0;
Standard_Integer nbTris = 0;
Standard_Integer iTri;
Standard_ShortReal x[4],y[4],z[4];
Standard_Integer i1,i2,i3;
fpos_t pos; //NEW CODE
char C; //NEW CODE
Handle(StlMesh_Mesh) ReadMesh;
...
// skip the keywords "endloop"
fscanf(file,"%*s");
// skip the keywords "endfacet"
fscanf(file,"%*s");
//NEW CODE START
//skip any 'endsolid' and 'solid' delimiters
fgetpos(file, &pos);
C = getc(file);C = getc(file);
if( C==EOF ) {
break;
}
else if( C=='e' ) {
while (getc(file) != '\n');
C = getc(file);
if( C==EOF )
break;
while (getc(file) != '\n');
}
else {
fsetpos(file, &pos);
}
//NEW CODE END
}
cout
fclose(file);
return ReadMesh;
}
Wed, 03/25/2009 - 12:21
(OCCPATCH)
Good to have this improvement, thank you!
However I doubt the STL format is supposed to contain several solids. Descriptions that I found always speak (implicitly or explicitly) of a single solid expected. For example, the binary file header only specifies a number of facets in the file, it does not split them per solids as Ascii format would allow.
Roman
---
opencascade.blogspot.com - the Open CASCADE blog
Wed, 03/25/2009 - 18:32
I did consult the STL documentation -- all two pages of it -- and, indeed, more than one solid may be present in a file. Additionally, we attempted to import a STL file that, unknown to us, had several solids. When we displayed the BRep it looked totally crazy; this is because the extra lines "solid" and "endsolid" were read in as numerical data!
Wed, 03/25/2009 - 18:38
J, could you send a link to your documentation? I could not find *the Standard*, and my assumption was it's more a de-facto conventional format rather than an industrial standard. For many years Open CASCADE has this interface, I have not encountered a single file with multiple solids.
Thanks.
Roman
---
opencascade.blogspot.com - the Open CASCADE blog
Wed, 03/25/2009 - 20:51
Look at www.gom.com/CONTAINER/files/sp_stl_en.pdf
Wed, 03/25/2009 - 23:23
Quod erat demonstrandum.
The Backus-Naur Form (BNF) on page 3 unambiguously defines that the ASCII STL file is a *single* solid ;-).
Roman
---
opencascade.blogspot.com - the Open CASCADE blog
Fri, 04/10/2009 - 00:58
STL has been broadly adopted as a generic mesh interchange format. My unserstanding is that strictly speaking it should only have a single solid. However, we encounter (and generate) stl files with multiple solids on a daily basis. It is VERY common in additive fabrication ie. rapid prototyping, (the original industry for stl) to have multiple solids and most commercial applications now support this.
It would be a mistake not to make small accommodations, when possible to enable multiple solids to be read.
Wed, 12/08/2010 - 10:46
Hi
I am trying to read a binary file created using OCC itself.
Which API to use for creating a binary stl - StlAPI or StlAPI_Writer class?
regards
-PG
Wed, 12/08/2010 - 14:22
Take a look at the samples:
ImportExport.cpp
It uses StlAPI_Writer...
Greets,
Patrik