Skip to content

Commit

Permalink
Works for multiple dims
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Pals committed Feb 12, 2020
1 parent 89dc09f commit 87a0286
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 19 deletions.
25 changes: 16 additions & 9 deletions plugins/hdf/io/Hdf5Handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ void Hdf5Handler::initialize(
{
throw pdal_error("Could not open HDF5 file '" + filename + "'.");
}
int index = 0;
std::vector<hsize_t> m_chunkOffset();

for(const auto& [dimName, datasetName] : map.items()) {
m_logger->get(LogLevel::Warning) << "Opening dataset '"
<< datasetName << "' with dimension name '" << dimName
Expand Down Expand Up @@ -120,7 +123,10 @@ void Hdf5Handler::initialize(
} else {
throw pdal_error("Unkown type: " + vague_type);
}
m_data.resize(m_chunkSize*dtype.getSize());
m_chunkOffsets.push_back(0);
m_buffers.push_back(std::vector<uint8_t>());
m_buffers.at(index).resize(m_chunkSize*dtype.getSize());
index++;
}
}

Expand All @@ -130,18 +136,19 @@ void Hdf5Handler::close()
}


uint8_t *Hdf5Handler::getNextChunk() {
hsize_t elementsRemaining = m_numPoints - m_chunkOffset;
uint8_t *Hdf5Handler::getNextChunk(int index) {
hsize_t elementsRemaining = m_numPoints - m_chunkOffsets.at(index);
hsize_t selectionSize = std::min(elementsRemaining, m_chunkSize);

H5::DataSpace memspace(1, &selectionSize);
m_dspaces.at(0).selectHyperslab(H5S_SELECT_SET, &selectionSize, &m_chunkOffset);
m_dsets.at(0).read(m_data.data(),
m_dsets.at(0).getDataType(),
m_dspaces.at(index).selectHyperslab(H5S_SELECT_SET, &selectionSize, &m_chunkOffsets.at(index));
auto& data = m_buffers.at(index);
m_dsets.at(index).read(data.data(),
m_dsets.at(index).getDataType(),
memspace,
m_dspaces.at(0) );
m_chunkOffset += m_chunkSize;
return m_data.data();
m_dspaces.at(index) );
m_chunkOffsets.at(index) += m_chunkSize;
return data.data();
}


Expand Down
6 changes: 3 additions & 3 deletions plugins/hdf/io/Hdf5Handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Hdf5Handler
// const std::vector<hdf5::Hdf5ColumnData>& columns);
void close();

uint8_t *getNextChunk();
uint8_t *getNextChunk(int index);

uint64_t getNumPoints() const;
std::vector<pdal::hdf5::DimInfo> getDimensionInfos();
Expand All @@ -96,14 +96,14 @@ class Hdf5Handler

private:
std::vector<pdal::hdf5::DimInfo> m_dimInfos;
std::vector<uint8_t> m_data;
std::vector<std::vector<uint8_t>> m_buffers;
hsize_t m_chunkSize;
// H5::DataSet m_dset;
// H5::DataSpace m_dspace;
std::vector<H5::DataSet> m_dsets;
std::vector<H5::DataSpace> m_dspaces;

hsize_t m_chunkOffset = 0;
std::vector<hsize_t> m_chunkOffsets;
pdal::LogPtr m_logger;

std::unique_ptr<H5::H5File> m_h5File;
Expand Down
33 changes: 26 additions & 7 deletions plugins/hdf/io/HdfReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,44 @@ void HdfReader::ready(PointTableRef table)

point_count_t HdfReader::read(PointViewPtr view, point_count_t count)
{
size_t point_size = m_infos.at(0).size;
PointId startId = view->size();
point_count_t remaining = m_hdf5Handler.getNumPoints() - m_index;
count = (std::min)(count, remaining);


PointId nextId = startId;
uint8_t *buf = nullptr;
for(uint64_t pi = 0; pi < m_hdf5Handler.getNumPoints(); pi++) {
// for(auto info : m_infos) {
auto info = m_infos.at(0);
// for(uint64_t pi = 0; pi < m_hdf5Handler.getNumPoints(); pi++) {
// int index = 0;
// for(auto info : m_infos) {
// // auto info = m_infos.at(0);
// int bufIndex = pi % m_hdf5Handler.getChunkSize();
// if(bufIndex == 0) {
// buf = m_hdf5Handler.getNextChunk(index);
// }
// uint8_t *p = buf + bufIndex*point_size;
// view->setField(info.id, info.pdal_type, nextId, (void*) p);
// index++;
// }
// nextId++;
// }
int index = 0;
std::cout << "num infos: " << m_infos.size() << std::endl;
std::cout << "num points: " << m_hdf5Handler.getNumPoints() << std::endl;
for(auto info: m_infos) {
size_t point_size = info.size;
std::cout << "type info: " << pdal::Dimension::interpretationName(info.pdal_type) << std::endl;
nextId=0;
for(uint64_t pi = 0; pi < m_hdf5Handler.getNumPoints(); pi++) {
int bufIndex = pi % m_hdf5Handler.getChunkSize();
if(bufIndex == 0) {
buf = m_hdf5Handler.getNextChunk();
buf = m_hdf5Handler.getNextChunk(index);
}
uint8_t *p = buf + bufIndex*point_size;
view->setField(info.id, info.pdal_type, nextId, (void*) p);
// }
nextId++;
nextId++;
}
index++;
}

return count;
Expand Down

0 comments on commit 87a0286

Please sign in to comment.