Menu

STL: wrong IsBinary detection

Help
Dirk C
2017-06-09
2018-06-23
  • Dirk C

    Dirk C - 2017-06-09

    Hello,

    i wanted to created a report in bugtracker but i don't have permissions, so i want to report it here:

    The STL file importer seems to have a wrong IsBinary detection. This file is recognized as ASCII but it's a binary:

    Deathstar.stl:
    https://drive.google.com/open?id=0Bx84-peUdIgZQl9UOTE1SlFlRjg

    Meshlab and Repetier Host loading is fine.

    See also:
    https://stackoverflow.com/questions/26171521/verifying-that-an-stl-file-is-ascii-or-binary

    As far as i remember this file was expoted as STL with meshlab.

    Hope this helps,
    Best regards
    Dirk

     

    Last edit: Dirk C 2017-06-09
  • Jerome.D (BeanzMaster)

    Hi Dirk Thanks, we know this bug but i never (search) localised before. I'll take a look

    cheers

     

    Last edit: Jerome.D (BeanzMaster) 2017-06-10
  • Dirk C

    Dirk C - 2017-06-10

    Hi Jerome,
    thanks for looking at this! Can you send me the SVN / bugtracker access so i can conribute?
    Best regards
    Dirk

     
  • Andrea Menapace

    Andrea Menapace - 2017-06-24

    Hello friends,
    I also wonder about this problem.
    I have two .stl files for the same model, one processed in Binary format and the other processed in ASCII format.
    Unfortunately, Binary model does not appear...
    Will I overcome this problem?
    Thank you

     
  • Dirk C

    Dirk C - 2017-06-26

    Hi Andrea,

    do you have debugged the STL file IsBinary detection? Can you post the STL file?
    Place a breakpoint in
    ~~~
    procedure TGLSTLVectorFile.LoadFromStream(aStream: TStream);
    begin
    ..
    isBinary := True;
    i := 0;
    while i < 80 do
    begin
    if (headerBuf[i] < #32) and (headerBuf[i] <> #0) then
    begin
    isBinary := False;
    Break;
    end;
    Inc(i);
    end;

    ..
    ~~~

    My bugreport was about the wrong IsBinary detection..
    Best regards
    Dirk

     

    Last edit: Dirk C 2017-06-26
  • Andrea Menapace

    Andrea Menapace - 2017-06-27

    Hi Dirk,
    to begin thank you for availability.

    I work with scanners for my dental laboratory that generate .stl ASCII files.
    I did a small project with GLScene to open these files.
    Now files are sent to me .stl Binary files generated by Intraoral Scanner
    Unfortunately I can not open them with my project but it would be indispensable to me.

    I attach an example of files I can not open.

    Thank you again for your kindness.

    Andrew

    P.S. Sorry for my English... ;)

     
  • Jerome.D (BeanzMaster)

    Hi Andrea, Hi Dirk I take a look, it's just a small error change :In GLFileSTL around line 145

    isBinary := True;
    i := 0;
    while i < 80 do
    begin
    if (headerBuf[i] < #32) and (headerBuf[i] <> #0) then
    begin
    isBinary := False;
    Break;
    end;
    Inc(i);
    end;
    

    by

    isBinary := False;
    i := 0;
    while i < 80 do
    begin
    if (headerBuf[i] < #32) and (headerBuf[i] <> #0) then
    begin
    isBinary := True;
    Break;
    end;
    Inc(i);
    end;
    

    That's it

    I'll update SVN later

    Bye

     
  • Dirk C

    Dirk C - 2017-06-27

    Hi Jerome,

    isBinary := True;

    did the trick! Generally STL import works very good and now even better..
    Thanks & best regards
    Dirk

     
  • Dirk C

    Dirk C - 2017-06-28

    Sorry, but this fix does not work, see attached binary STL.
    This file was loading fine before the fix, so it's a regression..

     
  • Dirk C

    Dirk C - 2017-06-29

    Hi Jerome,

    i've fixed the STL format detection, sanity checks done as suggested.
    I've tested against a few STL and seems to work fine now.

    Attached is the SVN patch. You can can send me SVN account to dirk(dot)carstensen(at)gmail.com, i have more fixes and enhancements done..

    Best regards
    Dirk

     
  • Pavel Vassiliev

    Pavel Vassiliev - 2017-06-30

    Hi Dirc,
    I've updated GLFileSTL using your patch, so if you have any other bug fixes send your patches to check and repair units

     
  • Andrea Menapace

    Andrea Menapace - 2017-07-02

    Hi Dirk, hi Jerome, thank you.
    I saw your great work to update GLFileSTL.
    I tried to change the variation on [isBinary:=True or False] suggested by Jerome and it works by alternating the opening of files.
    Then I updated with Dirk's suggested text to intercept the file type, but I still report the error "The STL file is not long enough (% d bytes)."

    Any other precious suggestion?
    Thank you very much.

     
  • Andrea Menapace

    Andrea Menapace - 2017-07-05

    Hi Dirk

    Good job!
    Now everything works best!

    Thank you.

     
  • Bottleneck

    Bottleneck - 2018-06-15

    Hello Jerome,

    I am working with Lazarus and GlScene to create G-Code for LinuxCNC from 3D files.

    I encountered a problem loading an ASCII STL file. Within the first 80 Characters there is a LF (#10) in this file. So this routine detects the file as being binary.
    I changed your if clause. First I removed
    and (headerBuf[i]<>#0)
    and added:
    and (headerBuf[i]<>#10) and (headerBuf[i]<>#13)
    and it worked perfect.

    Afterwards I found that there is a #0 in the header of every binary STL file. I did not find any #0 in all of my ASCII STl files. So I think to detect an binary you only have to detect #0 within the first 80 characters.

    This is the code I am using now:
    It works fine for all of my STL flies.

      isBinary:=False;
       i:=0;
       while i<80 do begin
               if (headerBuf[i] = #0) then begin
                     isBinary:=True;
                     break;
    

    Could you please check the branch "GLScene_LCL". I did not find the change above.

    Thank you very much

     
  • Jerome.D (BeanzMaster)

    Hi Bottleneck, sorry for answer just now, i was very busy
    Thanks i'll do the change. Great !!!

    Can you send or tell me where i can found STL file for testing ?

    the code is in : source/fileformats/GLFileSTL.pas

    Thank you

    EDIT : the current code is :

     isBinary:=True;
       i:=0;
       while i<80 do begin
         if (headerBuf[i]<#32) and (headerBuf[i]<>#0) then begin
             isBinary:=False;
             Break;
         end;
         Inc(i);
       end;
    

    Can you test with it ? Thanks in advance

     

    Last edit: Jerome.D (BeanzMaster) 2018-06-23

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.