loading and saving large binary .stl (stereolithography) files

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • andrew78
    New Member
    • Apr 2010
    • 7

    loading and saving large binary .stl (stereolithography) files

    hi @all. i have written a c++ program for visualization of .stl files using opengl. for small files the loading time is no problem, but if the files get larger (a couple of mb which means a few hundred thousand triangles) the loading time gets minutes. for the read in process i use both ifstream and fopen. there is nearly no difference in time. i think the problem is the way i save the data in memory. i use a single linked list consisting of pointers to a class for each triangle. now i am thinking of using float** matrizes and initializing them with the values read in using malloc(). but i don't know if this will increase performance. i will try. does anyone have any other ideas to solve my loading problem?
    thanks in advance, andrew
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    If you are using C++ they you should be using a std::list

    It is unlikely that you will be able to write anything that goes significantly faster than this.

    Using a float** instead of your classes is also unlikely to make a difference.

    How many of these triangle classes do you end up with? What is the memory size of each class? How much physical memory is in your machine?

    I guess the problem may be doing lots of little memory allocations. You could try doing your memory allocation using a std::vector, as soon as you know how many triangles there are going to be reserve that much space in your std::vector so that the memory is allocated in 1 operation.

    You may still want to use a std::list, particularly if you are going to be sorting or re-arranging the order of the triangles then sorting a std::list of pointers into a std::vector of objects will be much faster than sorting the std::vector directly.

    Comment

    • andrew78
      New Member
      • Apr 2010
      • 7

      #3
      thank you for your quick answer!
      i am using the std::list to extract points and visualize as a point cloud - because the unique() function is very useful to delete repeated points. the performance of std::list is ok, but not for visualization. moving the 3d-object visualized as a point cloud using list performs relatively slow. but that doesn't matter.

      i used a float** matrix now and the performance is much better now. the loading time of a 8mb .stl file (>200000 triangles) is 4 seconds now - and this is ok. and moving the object on the opengl screen works much better than it does with the point cloud using std::list.

      you see, i end up with 10 000 to 500 000 triangles and for now i am happy with the loading time.

      the memory size of one class (triangle) is 52 bytes.
      my machine has 2gb ram and xp prof. sp3 but the program will run on a quad core ~3GHz, ~4GB RAM, win7 prof. in future.

      Comment

      • donbock
        Recognized Expert Top Contributor
        • Mar 2008
        • 2427

        #4
        Use a stopwatch to time how long it takes to make a copy of your triangle file (using operating system commands, no C++ program). This establishes the time it takes to read in, and write out, the triangle file. You can't go any faster than this without making the file smaller. If your program is taking substantially longer than this then you know the problem is something other than mere file I/O.

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          Do you have to use floating point? That is incredibly slow.

          I recommend using integers only unless there is a technical reason you can write down on paper that requires you use it.

          If you do have to use it, then use double. C++ promotes float to double, does the calulation, and them demotes double back to float.

          All major finance systems use intgers.

          Comment

          • andrew78
            New Member
            • Apr 2010
            • 7

            #6
            yes, the data i get is in floating point 4 bytes. for the moment there are no calculations, just visualization using GLfloat and opengl. and for now i am working on a 32bit system - so i think using float is the better choice.
            does c++ really convert a float to double and back for calculations? that's new for me. as i said, i am working on a 32bit system.
            a conversion to int isn't possible because the values will get changed in future and have to be saved as float again.

            Comment

            Working...