// // Reads data from the input file // static void pngReadFunc(png_struct * pngPtr, png_byte * data, png_size_t bytes) { MemoryFile * file = (MemoryFile *)pngPtr->io_ptr; Q_ASSERT(file); int64 result = file->read((char *)data, bytes); if (unlikely(result != (int64)bytes)) png_error(pngPtr, "I/O error"); }
// // tries to open a file from the given framenumber and reads the content into the vector of particles // void loadParticles( std::string fileName, std::vector<Particle> &particles ) { // if the file is a zip file, then we assume that the zip contains the pcl file among other things if( util::getExtension( fileName ) == ".zip" ) { // unzip the pcl file into the memory std::string title = dk::util::PathInfo::getTitle( fileName ); // open the zipfile HZIP zip = OpenZip( util::toWString( fileName ).c_str(), 0 ); // set base directory for unzipping operations SetUnzipBaseDir( zip, _T("\\") ); // zip entry for the pcl file ZIPENTRY ze; int entryIndex = -1; // look for the pcl file FindZipItem( zip, util::toWString( std::string( title ) + ".pcl" ).c_str(), false, &entryIndex, &ze ); if( entryIndex == -1 ) { printf( "error : zip file doesnt contain %s\n", util::setExtension( fileName, ".pcl" ).c_str() ); // stop everything return; } // prepare memory MemoryFile file; file.resize( ze.unc_size ); // we have found the particles -> unpack them into memory UnzipItem( zip, entryIndex, file.getMemory(), file.size() ); CloseZip( zip ); // now read the particles int particleCount = 0; file.read((char *) &particleCount, sizeof(int) ); printf( "number of particles: %i\n", particleCount ); // prepare vector particles.resize( particleCount ); // now read in (kinda rough) for( int i=0; i<particleCount; ++i ) { float pos[3]; file.read((char *) pos, sizeof(float) * 3 ); particles[i].position.x = pos[0]; particles[i].position.y = pos[1]; particles[i].position.z = pos[2]; } }else { // open file from disk std::ifstream in( fileName.c_str(), std::ios::in | std::ios::binary ); if( !in ) return; int particleCount = 0; in.read((char *) &particleCount, sizeof(int) ); printf( "number of particles: %i\n", particleCount ); // prepare vector particles.resize( particleCount ); // now read in (kinda rough) for( int i=0; i<particleCount; ++i ) { float pos[3]; in.read((char *) pos, sizeof(float) * 3 ); particles[i].position.x = pos[0]; particles[i].position.y = pos[1]; particles[i].position.z = pos[2]; } in.close(); } }