Skip to content

Commit

Permalink
Reads!
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Pals committed Jan 29, 2020
1 parent b81353e commit 3eb420d
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 24 deletions.
46 changes: 39 additions & 7 deletions plugins/hdf/io/Hdf5Handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,33 @@
#include "Hdf5Handler.hpp"
#include <pdal/util/FileUtils.hpp>
#include <pdal/pdal_types.hpp>
#include <pdal/Dimension.hpp>

namespace pdal
{

// Dimension::Type getPdalType(DimInfo info) {
// Dimension::BaseType b = Dimension::BaseType::None;
// Dimension::Type t = Dimension::Type::None;
// if(info.hdf_type == H5T_INTEGER) {
// if(info.sign == H5T_SGN_NONE) {
// b = Dimension::BaseType::Unsigned;
// }
// else if(info.sign == H5T_SGN_2) {
// b = Dimension::BaseType::Signed;
// }
// } else if(info.hdf_type == H5T_FLOAT) {
// b = Dimension::BaseType::Floating;
// } else {
// throwError("Invalid hdf type");
// }

// t = Dimension::Type(unsigned(b) | info.size);
// return t;
// }
using namespace hdf5;



Hdf5Handler::Hdf5Handler()
: m_numPoints(0)
, m_columnDataMap()
Expand All @@ -56,13 +77,14 @@ void Hdf5Handler::initialize(
std::cout << "Number of HD5 Objects: " << m_h5File.get()->getObjCount() <<std::endl;
H5::DataSet dset = m_h5File.get()->openDataSet("/autzen");
H5::DataSpace dspace = dset.getSpace();
m_numPoints = 1065; //TODO FIX
std::cout << "Number of dataspace dimensions: " << dspace.getSimpleExtentNdims() << std::endl;
H5::CompType ctype = dset.getCompType();//H5::CompType(dset);
m_numPoints = ctype.getNmembers();
std::cout << "Number of points: " << m_numPoints << std::endl;
std::cout << "Point length: " << ctype.getSize() << std::endl;
std::cout << "Number of HDF compound type members (PDAL dimensions): " << ctype.getNmembers() << std::endl;

m_buf = malloc(ctype.getSize() * m_numPoints); //TODO free
dset.read(m_buf, ctype);
// print names
for(int j = 0; j < ctype.getNmembers(); ++j) {
// m_dimNames.push_back(ctype.getMemberName(j));
Expand All @@ -81,32 +103,38 @@ void Hdf5Handler::initialize(
ctype.getMemberName(j),
vauge_type,
int_type.getOrder(),
int_type.getSign(),
int_type.getSize(),
int_type.getOffset())
int_type.getOffset(),
Dimension::Type(unsigned(Dimension::BaseType::Unsigned) | int_type.getSize()))
);
std::cout << "uint, s:" << int_type.getSize() << ", e:" << int_type.getOrder();
} else if(int_type.getSign() == H5T_SGN_2) {
m_dimInfos.push_back(DimInfo(
ctype.getMemberName(j),
vauge_type,
int_type.getOrder(),
int_type.getSign(),
int_type.getSize(),
int_type.getOffset())
int_type.getOffset(),
Dimension::Type(unsigned(Dimension::BaseType::Signed) | int_type.getSize()))
);
std::cout << "sint, s:" << int_type.getSize() << ", e:" << int_type.getOrder();
} else {
std::cout << "sign error";
}
break;
case H5T_FLOAT:
std::cout << "float, s:" << float_type.getSize() << ", e:" << float_type.getOrder();
m_dimInfos.push_back(DimInfo(
ctype.getMemberName(j),
vauge_type,
float_type.getOrder(),
H5T_SGN_ERROR,
float_type.getSize(),
float_type.getOffset())
float_type.getOffset(),
Dimension::Type(unsigned(Dimension::BaseType::Floating) | float_type.getSize()))
);
std::cout << "float, s:" << float_type.getSize() << ", e:" << float_type.getOrder();
break;
default:
std::cout << "Unkown type: " << vauge_type;
Expand Down Expand Up @@ -191,6 +219,10 @@ void Hdf5Handler::getColumnEntries(
std::vector<pdal::hdf5::DimInfo> Hdf5Handler::getDimensionInfos() {
return m_dimInfos;
}
void *
Hdf5Handler::getBuffer() {
return m_buf;
}

hsize_t
Hdf5Handler::getColumnNumEntries(const std::string& dataSetName) const
Expand Down
20 changes: 15 additions & 5 deletions plugins/hdf/io/Hdf5Handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#pragma once

#include <pdal/pdal_export.hpp> // Suppresses windows 4251 messages
#include <pdal/Dimension.hpp>
#include "H5Cpp.h"

#include <memory>
Expand Down Expand Up @@ -64,22 +65,28 @@ namespace hdf5
const std::string& name,
const H5T_class_t hdf_type,
const H5T_order_t endianness,
const size_t s,
const int offset)
const H5T_sign_t sign,
const size_t size,
const int offset,
Dimension::Type pdal_type)
: name(name)
, hdf_type(hdf_type)
, endianness(endianness)
, s(s)
, sign(sign)
, size(size)
, offset(offset)
, pdal_type(pdal_type)
{ }

std::string name;
H5T_class_t hdf_type;
H5T_order_t endianness;
size_t s;
H5T_sign_t sign;
size_t size;
int offset;
Dimension::Type pdal_type;
Dimension::Id id;
};

}

class Hdf5Handler
Expand All @@ -98,6 +105,8 @@ class Hdf5Handler
// const std::vector<hdf5::Hdf5ColumnData>& columns);
void close();

void *getBuffer();

uint64_t getNumPoints() const;
std::vector<pdal::hdf5::DimInfo> getDimensionInfos();

Expand Down Expand Up @@ -134,6 +143,7 @@ class Hdf5Handler
std::vector<pdal::hdf5::DimInfo> m_dimInfos;
hsize_t getColumnNumEntries(const std::string& dataSetName) const;
const ColumnData& getColumnData(const std::string& dataSetName) const;
void *m_buf;

std::unique_ptr<H5::H5File> m_h5File;
uint64_t m_numPoints;
Expand Down
93 changes: 81 additions & 12 deletions plugins/hdf/io/HdfReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,33 @@ void HdfReader::addDimensions(PointLayoutPtr layout)
{
// layout->registerDims(dimensions());
std::cout << "HdfReader::addDimensions begin" << std::endl;
auto infos = m_hdf5Handler.getDimensionInfos();
for(auto info : infos) {
m_idlist.push_back(
layout->registerOrAssignDim(info.name, Dimension::Type::Unsigned64)
); // TODO: add correct type
}
m_infos = m_hdf5Handler.getDimensionInfos();
for(int i = 0; i < m_infos.size(); i++) {
// Dimension::BaseType b = Dimension::BaseType::None;
// Dimension::Type t = Dimension::Type::None;
// if(info.hdf_type == H5T_INTEGER) {
// if(info.sign == H5T_SGN_NONE) {
// b = Dimension::BaseType::Unsigned;
// }
// else if(info.sign == H5T_SGN_2) {
// b = Dimension::BaseType::Signed;
// }
// } else if(info.hdf_type == H5T_FLOAT) {
// b = Dimension::BaseType::Floating;
// } else {
// throwError("Invalid hdf type");
// }

// t = Dimension::Type(unsigned(b) | info.size);
// m_idlist.push_back(
std::cout << unsigned(m_infos[i].id) << " : ";
m_infos[i].id = layout->registerOrAssignDim(m_infos[i].name, m_infos[i].pdal_type);
std::cout << unsigned(m_infos[i].id) << std::endl;
// ); // TODO: add correct type
};
for(auto info: m_infos) {
std::cout << unsigned(info.id) << std::endl;
};
std::cout << "HdfReader::addDimensions end" << std::endl;
}

Expand Down Expand Up @@ -110,21 +131,69 @@ point_count_t HdfReader::read(PointViewPtr view, point_count_t count)
//This could be a huge allocation. Perhaps we should do something
// in the icebridge handler?
std::cout << "HdfReader::read" << std::endl;
size_t point_size = 52; //TODO Fix
PointId startId = view->size();
point_count_t remaining = m_hdf5Handler.getNumPoints() - m_index;
count = (std::min)(count, remaining);

std::unique_ptr<unsigned char>
rawData(new unsigned char[count * sizeof(float)]);
// std::unique_ptr<unsigned char>
// rawData(new unsigned char[count * point_size]);

// for(std::size_t di = 0; di < m_idlist.size(); di++) {
// Dimension::Id dimId = m_idlist[di];
std::cout << m_idlist.size() << std::endl;
for(auto dimId : m_idlist) {
// std::cout << m_idlist.size() << std::endl;
// for(auto dimId : m_idlist) {
for(auto info : m_infos) {
PointId nextId = startId;
std::cout << (int)dimId << std::endl;
std::cout << (unsigned)info.id << ": ";
for(uint64_t pi = 0; pi < m_hdf5Handler.getNumPoints(); pi++) {
view->setField(dimId, nextId++, 0);
// void *p = (void *)rawData.get() + 0*pi*point_size + info.offset;
void *p = m_hdf5Handler.getBuffer() + pi*point_size + info.offset;
switch(info.pdal_type) {
case Dimension::Type::Double:
if(pi == 0) std::cout<< Dimension::interpretationName(info.pdal_type) <<std::endl;
view->setField(info.id, nextId++, * ((double *) p));
break;
case Dimension::Type::Float:
if(pi == 0) std::cout<< Dimension::interpretationName(info.pdal_type) <<std::endl;
view->setField(info.id, nextId++, * ((float *) p));
break;
case Dimension::Type::Signed8:
if(pi == 0) std::cout<< Dimension::interpretationName(info.pdal_type) <<std::endl;
view->setField(info.id, nextId++, * ((int8_t *) p));
break;
case Dimension::Type::Signed16:
if(pi == 0) std::cout<< Dimension::interpretationName(info.pdal_type) <<std::endl;
view->setField(info.id, nextId++, * ((int16_t *) p));
break;
case Dimension::Type::Signed32:
if(pi == 0) std::cout<< Dimension::interpretationName(info.pdal_type) <<std::endl;
view->setField(info.id, nextId++, * ((int32_t *) p));
break;
case Dimension::Type::Signed64:
if(pi == 0) std::cout<< Dimension::interpretationName(info.pdal_type) <<std::endl;
view->setField(info.id, nextId++, * ((int64_t *) p));
break;
case Dimension::Type::Unsigned8:
if(pi == 0) std::cout<< Dimension::interpretationName(info.pdal_type) <<std::endl;
view->setField(info.id, nextId++, * ((uint8_t *) p));
break;
case Dimension::Type::Unsigned16:
if(pi == 0) std::cout<< Dimension::interpretationName(info.pdal_type) <<std::endl;
view->setField(info.id, nextId++, * ((uint16_t *) p));
break;
case Dimension::Type::Unsigned32:
if(pi == 0) std::cout<< Dimension::interpretationName(info.pdal_type) <<std::endl;
view->setField(info.id, nextId++, * ((uint32_t *) p));
break;
case Dimension::Type::Unsigned64:
if(pi == 0) std::cout<< Dimension::interpretationName(info.pdal_type) <<std::endl;
view->setField(info.id, nextId++, * ((uint64_t *) p));
break;
default:
view->setField(info.id, nextId, 0);
break;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions plugins/hdf/io/HdfReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class PDAL_DLL HdfReader : public pdal::Reader
std::string m_metadataFile;
std::string m_datasetName;
Dimension::IdList m_idlist;
std::vector<hdf5::DimInfo> m_infos;

HdfReader& operator=(const HdfReader&); // Not implemented.
HdfReader(const HdfReader&); // Not implemented.
Expand Down

0 comments on commit 3eb420d

Please sign in to comment.