bool readKeyFrame() { // init expected segements uint8_t *raw_iv = new uint8_t[numTraj * sizeof(Real)]; ChunkSize sz = chunkSrc((char*) raw_iv); if (!sz.raw) return false; uint bit_count = sz.raw / numTraj; assert(bit_count * numTraj == sz.raw); dynamic_bitset<uint8_t> iv(raw_iv, raw_iv + sz.compressed); delete[] raw_iv; for (int i=0; i<numTraj; i++) { uint32_t x_quant = 0; for (uint j=0; j<bit_count; j++) x_quant |= decltype(x_quant)(iv[i * bit_count + j]) << j; STP stp; stp.id = i; stp.time = 1; expectedSegment.push(stp); DecompTrajState &traj = trajState[i]; traj.t0 = 0; traj.x0 = unsigned2signed(x_quant); traj.dt = 0; traj.dx = 0; #ifdef HACKY_STATS stat_key_x[traj.x0]++; #endif } loadNextChunk(); return true; }
size_t InputBuffer<T>::getNextChunk(T*& dest) { size_t readBytes = loadNextChunk(); dest = (T*) _buffer; return readBytes / DATA_SIZE; }
void readSegment() { assert(chunkCur < chunkSz); // update mentioned traj TId id = expectedSegment.top().id; SVI svi = buf.get(chunkCur); DecompTrajState &traj = trajState[id]; traj.x0 += traj.dx; traj.t0 += traj.dt; assert(traj.t0 == curTime-1); traj.dt = svi.dt + 1; traj.dx = unsigned2signed(svi.v); // gather histogram data #ifdef HACKY_STATS stat_dx[traj.dx]++; stat_dt[traj.dt]++; #endif // add next expected point STP stp; stp.id = id; stp.time = curTime + traj.dt; expectedSegment.pop(); expectedSegment.push(stp); chunkCur++; // fetch new trajectory data if (chunkCur == chunkSz) loadNextChunk(); }
size_t InputBuffer<T>::getNextElement(T& dest) { //load new chunk either when no chunk was loaded before (_cur==-1), or current chunk is at the end (_cur== _bufferSize)) // return 1 when everything was okay if (_cur == -1 || (size_t)_cur == _currentChunkSize) { size_t loadResult = loadNextChunk(); if (loadResult <= 0) { return loadResult; } } memcpy(&dest, _buffer + _cur, DATA_SIZE); _cur += DATA_SIZE; return 1; }