SurfaceMap.hpp 1.12 KB
#pragma once

#include "data/ResourceLocator.hpp"
#include "data/hdf5/CVMatLoader.hpp"

class SurfaceMap {
  public:
	explicit SurfaceMap(const cv::Size &size) : surface(buildSurface(size)) {}

	cv::Point3f at(int column, int row) const {
		return surface.at<cv::Point3f>(row, column);
	}

	cv::Point3f at(const cv::Point &point) const {
		return at(point.x, point.y);
	}

	std::vector<cv::Point3f> at(const std::vector<cv::Point> &points) const {
		std::vector<cv::Point3f> surfacePoints(points.size());

		std::transform(points.begin(), points.end(), surfacePoints.begin(),
		               [&](const cv::Point &point) { return at(point); });

		return surfacePoints;
	}

  private:
	const cv::Mat surface;

	static cv::Mat buildSurface(const cv::Size &size) {
		cv::Mat result(size, CV_32FC3);

		const CVMatLoader loader(
		    ResourceLocator::getPathProvider().path("20171114.053_AEF20.h5"));
		const std::vector<cv::Mat> coordinates = {
		    loader.asMat("/scene_model/x", CV_32F),
		    loader.asMat("/scene_model/y", CV_32F),
		    loader.asMat("/scene_model/z", CV_32F),
		};

		cv::merge(coordinates, result);
		return result;
	}
};