| 113 | } |
| 114 | |
| 115 | DimInfo::DimInfo( |
| 116 | const std::string& dimName, |
| 117 | const std::string& datasetName, |
| 118 | H5::H5File *file |
| 119 | ) |
| 120 | : m_name(dimName) |
| 121 | , m_dset(file->openDataSet(datasetName)) |
| 122 | { |
| 123 | // Will throw if dataset doesn't exists. Gives adequate error message |
| 124 | H5::DataSpace dspace = m_dset.getSpace(); |
| 125 | |
| 126 | // Sanity check before we cast from signed to unsigned |
| 127 | if(dspace.getSelectNpoints() < 0) |
| 128 | throw pdal_error("Selection had a negative number of points. " |
| 129 | "this should never happen, and it's probably a PDAL bug."); |
| 130 | m_numPoints = (hsize_t) dspace.getSelectNpoints(); |
| 131 | |
| 132 | // check if dataset is 'chunked' |
| 133 | H5::DSetCreatPropList plist = m_dset.getCreatePlist(); |
| 134 | if(plist.getLayout() == H5D_CHUNKED) { |
| 135 | int dimensionality = plist.getChunk(1, &m_chunkSize); //modifies m_chunkSize |
| 136 | if(dimensionality != 1) |
| 137 | throw pdal_error("Only 1-dimensional arrays are supported."); |
| 138 | } else { |
| 139 | //if dataset is not chunked, use an arbitrary number for buffer size |
| 140 | m_chunkSize = 1024; // completely arbitrary number |
| 141 | } |
| 142 | |
| 143 | // populate fields base on HDF type |
| 144 | H5T_class_t vague_type = m_dset.getDataType().getClass(); |
| 145 | |
| 146 | if(vague_type == H5T_INTEGER) { |
| 147 | H5::IntType int_type = m_dset.getIntType(); |
| 148 | H5T_sign_t sign = int_type.getSign(); |
| 149 | m_size = int_type.getSize(); |
| 150 | if(sign == H5T_SGN_2) |
| 151 | m_pdalType = Dimension::Type(unsigned(Dimension::BaseType::Signed) | int_type.getSize()); |
| 152 | else |
| 153 | m_pdalType = Dimension::Type(unsigned(Dimension::BaseType::Unsigned) | int_type.getSize()); |
| 154 | } |
| 155 | else if(vague_type == H5T_FLOAT) { |
| 156 | H5::FloatType float_type = m_dset.getFloatType(); |
| 157 | m_size = float_type.getSize(); |
| 158 | m_pdalType = Dimension::Type(unsigned(Dimension::BaseType::Floating) | float_type.getSize()); |
| 159 | } |
| 160 | else { |
| 161 | throw pdal_error("Dataset '" + datasetName + "' has an " + |
| 162 | "unsupported type. Only integer and float types are supported."); |
| 163 | } |
| 164 | |
| 165 | //allocate buffer for getValue() to write into |
| 166 | m_buffer.resize(m_chunkSize*m_size); |
| 167 | } |
| 168 | |
| 169 | |
| 170 | std::vector<pdal::hdf5::DimInfo>& Handler::getDimensions() { |