commit 31d1a0e36ed57547d1809a5dc81340b1ffe73bf7
parent e55a93f29b5f3f1f8d56f380e4c580fe98b9d45d
Author: Fabian Wermelinger <fabianw@mavt.ethz.ch>
Date: Fri, 30 Sep 2016 20:12:09 +0200
added hdf5 slice reader for cam
Diffstat:
3 files changed, 72 insertions(+), 0 deletions(-)
diff --git a/apps/polaroidCamera/SceneProcessor.cpp b/apps/polaroidCamera/SceneProcessor.cpp
@@ -65,6 +65,8 @@ void SceneProcessor::_load_cam(Polaroid& cam, const char* const fname) const
if (input_type == "hdf5")
cam.load_hdf5(fname, m_parser);
+ else if (input_type == "hdf5_slice")
+ cam.load_hdf5_slice(fname, m_parser);
else if (input_type == "wavelet")
cam.load_wavelet(fname, m_parser);
else
diff --git a/include/Polaroid.h b/include/Polaroid.h
@@ -37,6 +37,7 @@ public:
// scene loader
void load_hdf5(const char* filename, ArgumentParser& parser);
+ void load_hdf5_slice(const char* filename, ArgumentParser& parser);
void load_wavelet(const char* filename, ArgumentParser& parser);
// capture scene
diff --git a/src/Polaroid.cpp b/src/Polaroid.cpp
@@ -151,6 +151,75 @@ void Polaroid::load_hdf5(const char* filename, ArgumentParser& parser)
#endif /* _USE_HDF_ */
}
+void Polaroid::load_hdf5_slice(const char* filename, ArgumentParser& parser)
+{
+#ifdef _USE_HDF_
+ const int channel = parser("-channel").asInt(0); // data channel
+ const bool magnitude = parser("-magnitude").asBool(false); // vector magnitude (only if NCH == 3)
+
+ /* open data */
+ hid_t file_id, dataset_id, dataspace_id, file_dataspace_id;
+ hsize_t* dims;
+ hssize_t num_elem;
+ int rank, ndims, NCH;
+ int maxDim[2];
+ Real* data;
+
+ file_id = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT);
+ dataset_id = H5Dopen(file_id, "/data", H5P_DEFAULT);
+ file_dataspace_id = H5Dget_space(dataset_id);
+ rank = H5Sget_simple_extent_ndims(file_dataspace_id);
+ dims = new hsize_t[rank];
+ ndims = H5Sget_simple_extent_dims(file_dataspace_id, dims, NULL);
+ num_elem = H5Sget_simple_extent_npoints(file_dataspace_id);
+ data = new Real[num_elem];
+ maxDim[1] = dims[0];
+ maxDim[0] = dims[1];
+ NCH = dims[2];
+ dataspace_id = H5Screate_simple(rank, dims, NULL);
+ int status = H5Dread(dataset_id, HDF_PRECISION, dataspace_id, file_dataspace_id, H5P_DEFAULT, data);
+
+ const int Nmax = std::max(maxDim[0], maxDim[1]);
+ m_data.set_max3Ddim(Nmax);
+
+ /* release stuff */
+ delete [] dims;
+ status = H5Dclose(dataset_id);
+ status = H5Sclose(dataspace_id);
+ status = H5Sclose(file_dataspace_id);
+ status = H5Fclose(file_id);
+
+ assert(channel < NCH);
+
+ /* extract plane */
+ m_data.set_sliceDir('s'); // from 2D slice
+ m_data.set_sliceID(-1);
+ m_data.resize(maxDim[0], maxDim[1]);
+ if (magnitude && NCH == 3)
+ {
+ for (int h=0; h < m_data.height(); ++h)
+ for (int w=0; w < m_data.width(); ++w)
+ {
+ const Real a = data[0 + NCH*(w + maxDim[0]*h)];
+ const Real b = data[1 + NCH*(w + maxDim[0]*h)];
+ const Real c = data[2 + NCH*(w + maxDim[0]*h)];
+ m_data(w,h) = std::sqrt(a*a + b*b + c*c);
+ }
+ }
+ else
+ {
+ for (int h=0; h < m_data.height(); ++h)
+ for (int w=0; w < m_data.width(); ++w)
+ m_data(w,h) = data[channel + NCH*(w + maxDim[0]*h)];
+ }
+ delete [] data;
+ m_dataLoaded = true;
+
+#else
+ fprintf(stderr, "WARNING: Executable was compiled without HDF support...\n");
+#endif /* _USE_HDF_ */
+}
+
void Polaroid::load_wavelet(const char* filename, ArgumentParser& parser)
{
#ifdef _USE_CUBISMZ_