Menu

load models from files in one step

Anonymous
2011-10-05
2012-12-26
  • Anonymous

    Anonymous - 2011-10-05

    Hello.

    Thanx for a such lovely library. I'm realy love the fact, what it will be core for Processing 2.0.

    I'm using this library a lots, and now work with project where i load 6 mln. points from file. Before latest 1.0.0 version you store vertex info in files via shorts arrays. now you change this to floats. this is reaaly great. but loading 95 mb file of floats vertices now take 130 sec. for me. pretty long time.

    so i investigate and found what we can use byte for read it all in one step. now it take only 2.45 sec for load 6 mln. points from file.

    I put some code below, maybe you will find it useful

     volume = new GLModel(this, 5966572, GLModel.POINTS, GLModel.STATIC);
      volume.beginUpdateVertices();
      loadFloatsFromBinary("vertices_float.bin", volume.vertices, 5966572);
      volume.endUpdateVertices();
    void loadFloatsFromBinary(String filename, FloatBuffer floats, int len) {
      try {
        FileInputStream fis = new FileInputStream(filename);
        DataInputStream dis = new DataInputStream(fis);
        //    int len = floats.capacity();
        byte[] tmp = new byte[len*4*4];
        int readed = dis.read(tmp, 0, len*4*4);
        ByteBuffer buffer = ByteBuffer.wrap(tmp);
        FloatBuffer fView = buffer.asFloatBuffer();
        floats.put(fView);
        fis.close();
      //  tmp = null;
      } 
      catch (Exception e) {
        System.out.println("Exception: " + e);
      }
    }
    
     
  • Andres Colubri

    Andres Colubri - 2011-10-05

    Hello, thanks so much for your feedback and code!

    Right now I will be focusing on Processing 2.0, so I will open a feature request with your code:

    https://sourceforge.net/tracker/?func=detail&aid=3419046&group_id=225391&atid=1064716

    to include in a later maintenance release of GLGraphics.

     

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.