Ejemplo n.º 1
0
BOOL LASreadPoint::read(U8* const * point)
{
  U32 i;

  try
  {
    if (dec)
    {
      if (chunk_count == chunk_size)
      {
        if (point_start != 0)
        {
          dec->done();
          current_chunk++;
          // check integrity
          if (current_chunk < tabled_chunks)
          {
            I64 here = instream->tell();
            if (chunk_starts[current_chunk] != here)
            {
              // previous chunk was corrupt
              current_chunk--;
              throw 4711;
            }
          }
        }
        init_dec();
        if (current_chunk == tabled_chunks) // no or incomplete chunk table?
        {
          if (current_chunk == number_chunks)
          {
            number_chunks += 256;
            chunk_starts = (I64*)realloc(chunk_starts, sizeof(I64)*(number_chunks+1));
          }
          chunk_starts[tabled_chunks] = point_start; // needs fixing
          tabled_chunks++;
        }
        else if (chunk_totals) // variable sized chunks?
        {
          chunk_size = chunk_totals[current_chunk+1]-chunk_totals[current_chunk];
        }
        chunk_count = 0;
      }
      chunk_count++;

      if (readers)
      {
        for (i = 0; i < num_readers; i++)
        {
          readers[i]->read(point[i]);
        }
      }
      else
      {
        for (i = 0; i < num_readers; i++)
        {
          readers_raw[i]->read(point[i]);
          ((LASreadItemCompressed*)(readers_compressed[i]))->init(point[i]);
        }
        readers = readers_compressed;
        dec->init(instream);
      }
    }
    else
    {
#if 0
      for (i = 0; i < num_readers; i++)
      {
        readers[i]->read(point[i]);
      }
#else
        bool isEOF = false;
        bool canCopy = true;

        if (m_bufferPos == 0 || m_bufferPos >= m_bufferSize) {
            auto readBytes = instream->getBytesWithoutException(m_buffer, m_bufferSize);
            
            if (readBytes != m_bufferSize) {
                isEOF = true;
                canCopy = (readBytes > 0);
            }

            m_bufferPos = 0;
        }

        if (canCopy) {
            for (i = 0; i < num_readers; i++)
            {
                auto size = m_vtxSizeArray[i];

                //point[i] = m_buffer;
                auto src = m_buffer + m_bufferPos;
                memcpy(point[i], src, size);

                m_bufferPos += size;
            }
        }

        if (isEOF) {
            //throw EOF;
            return FALSE;
        }
#endif
    }
  }
  catch (I32 exception) 
  {
    // create error string
    if (last_error == 0) last_error = new CHAR[128];
    // report error
    if (exception == EOF)
    {
      // end-of-file
      if (dec)
      {
        sprintf(last_error, "end-of-file during chunk with index %u", current_chunk);
      }
      else
      {
        sprintf(last_error, "end-of-file");
      }
    }
    else
    {
      // decompression error
      sprintf(last_error, "chunk with index %u of %u is corrupt", current_chunk, tabled_chunks);
      // if we know where the next chunk starts ...
      if ((current_chunk+1) < tabled_chunks)
      {
        // ... try to seek to the next chunk
        instream->seek(chunk_starts[(current_chunk+1)]);
        // ... ready for next LASreadPoint::read()
        chunk_count = chunk_size;
      }
    }
    return FALSE;
  }
  return TRUE;
}
Ejemplo n.º 2
0
BOOL LASreadPoint::read(U8* const * point)
{
  U32 i;

  try
  {
    if (dec)
    {
      if (chunk_count == chunk_size)
      {
        if (point_start != 0)
        {
          current_chunk++;
          dec->done();
        }
        init_dec();
        if (tabled_chunks == current_chunk) // no or incomplete chunk table?
        {
          if (current_chunk == number_chunks)
          {
            number_chunks += 256;
            chunk_starts = (I64*)realloc(chunk_starts, sizeof(I64)*(number_chunks+1));
          }
          chunk_starts[tabled_chunks] = point_start; // needs fixing
          tabled_chunks++;
        }
        else if (chunk_totals) // variable sized chunks?
        {
          chunk_size = chunk_totals[current_chunk+1]-chunk_totals[current_chunk];
        }
        chunk_count = 0;
      }
      chunk_count++;

      if (readers)
      {
        for (i = 0; i < num_readers; i++)
        {
          readers[i]->read(point[i]);
        }
      }
      else
      {
        for (i = 0; i < num_readers; i++)
        {
          readers_raw[i]->read(point[i]);
          ((LASreadItemCompressed*)(readers_compressed[i]))->init(point[i]);
        }
        readers = readers_compressed;
        dec->init(instream);
      }
    }
    else
    {
      for (i = 0; i < num_readers; i++)
      {
        readers[i]->read(point[i]);
      }
    }
  }
  catch (...)
  {
    return FALSE;
  }
  return TRUE;
}
Ejemplo n.º 3
0
BOOL LASreadPoint::seek(const U32 current, const U32 target)
{
  if (!instream->isSeekable()) return FALSE;
  U32 delta = 0;
  if (dec)
  {
    if (point_start == 0)
    {
      init_dec();
      chunk_count = 0;
    }
    if (chunk_starts)
    {
      U32 target_chunk;
      if (chunk_totals)
      {
        target_chunk = search_chunk_table(target, 0, number_chunks);
        chunk_size = chunk_totals[target_chunk+1]-chunk_totals[target_chunk];
        delta = target - chunk_totals[target_chunk];
      }
      else
      {
        target_chunk = target/chunk_size;
        delta = target%chunk_size;
      }
      if (target_chunk >= tabled_chunks)
      {
        if (current_chunk < (tabled_chunks-1))
        {
          dec->done();
          current_chunk = (tabled_chunks-1);
          instream->seek(chunk_starts[current_chunk]);
          init_dec();
          chunk_count = 0;
        }
        delta += (chunk_size*(target_chunk-current_chunk) - chunk_count);
      }
      else if (current_chunk != target_chunk || current > target)
      {
        dec->done();
        current_chunk = target_chunk;
        instream->seek(chunk_starts[current_chunk]);
        init_dec();
        chunk_count = 0;
      }
      else
      {
        delta = target - current;
      }
    }
    else if (current > target)
    {
      dec->done();
      instream->seek(point_start);
      init_dec();
      delta = target;
    }
    else if (current < target)
    {
      delta = target - current;
    }
    while (delta)
    {
      read(seek_point);
      delta--;
    }
  }
  else
  {
    if (current != target)
    {
      instream->seek(point_start+point_size*target);
    }
  }
  return TRUE;
}
Ejemplo n.º 4
0
BOOL LASreadPoint::read(U8* const * point)
{
  U32 i;

  try
  {
    if (dec)
    {
      if (chunk_count == chunk_size)
      {
        if (point_start != 0)
        {
          dec->done();
          current_chunk++;
          // check integrity
          if (current_chunk < tabled_chunks)
          {
            I64 here = instream->tell();
            if (chunk_starts[current_chunk] != here)
            {
              // previous chunk was corrupt
              current_chunk--;
              throw 4711;
            }
          }
        }
        init_dec();
        if (current_chunk == tabled_chunks) // no or incomplete chunk table?
        {
          if (current_chunk == number_chunks)
          {
            number_chunks += 256;
            chunk_starts = (I64*)realloc(chunk_starts, sizeof(I64)*(number_chunks+1));
          }
          chunk_starts[tabled_chunks] = point_start; // needs fixing
          tabled_chunks++;
        }
        else if (chunk_totals) // variable sized chunks?
        {
          chunk_size = chunk_totals[current_chunk+1]-chunk_totals[current_chunk];
        }
        chunk_count = 0;
      }
      chunk_count++;

      if (readers)
      {
        for (i = 0; i < num_readers; i++)
        {
          readers[i]->read(point[i]);
        }
      }
      else
      {
        for (i = 0; i < num_readers; i++)
        {
          readers_raw[i]->read(point[i]);
          ((LASreadItemCompressed*)(readers_compressed[i]))->init(point[i]);
        }
        readers = readers_compressed;
        dec->init(instream);
      }
    }
    else
    {
      for (i = 0; i < num_readers; i++)
      {
        readers[i]->read(point[i]);
      }
    }
  }
  catch (I32 exception) 
  {
    // create error string
    if (last_error == 0) last_error = new CHAR[128];
    // report error
    if (exception == EOF)
    {
      // end-of-file
      if (dec)
      {
        sprintf(last_error, "end-of-file during chunk with index %u", current_chunk);
      }
      else
      {
        sprintf(last_error, "end-of-file");
      }
    }
    else
    {
      // decompression error
      sprintf(last_error, "chunk with index %u of %u is corrupt", current_chunk, tabled_chunks);
      // if we know where the next chunk starts ...
      if ((current_chunk+1) < tabled_chunks)
      {
        // ... try to seek to the next chunk
        instream->seek(chunk_starts[(current_chunk+1)]);
        // ... ready for next LASreadPoint::read()
        chunk_count = chunk_size;
      }
    }
    return FALSE;
  }
  return TRUE;
}