Skip to content
Snippets Groups Projects
ilw.hpp 2.08 KiB
Newer Older
Nicolas Pope's avatar
Nicolas Pope committed
#ifndef _FTL_RECONSTRUCT_ILW_HPP_
#define _FTL_RECONSTRUCT_ILW_HPP_

Nicolas Pope's avatar
Nicolas Pope committed
#include <ftl/cuda_common.hpp>
#include <ftl/rgbd/frameset.hpp>
Nicolas Pope's avatar
Nicolas Pope committed
#include <ftl/configurable.hpp>
Nicolas Pope's avatar
Nicolas Pope committed
#include <vector>

Nicolas Pope's avatar
Nicolas Pope committed
#include "ilw_cuda.hpp"

#include <ftl/cuda/points.hpp>

Nicolas Pope's avatar
Nicolas Pope committed
namespace ftl {

Nicolas Pope's avatar
Nicolas Pope committed
namespace detail {
struct ILWData{
    // x,y,z + confidence
    ftl::cuda::TextureObject<float4> correspondence;

    ftl::cuda::TextureObject<float4> points;
Nicolas Pope's avatar
Nicolas Pope committed

	// Residual potential energy
	ftl::cuda::TextureObject<float> residual;

	// Flow magnitude
	ftl::cuda::TextureObject<float> flow;
Nicolas Pope's avatar
Nicolas Pope committed
/**
 * For a set of sources, perform Iterative Lattice Warping to correct the
 * location of points between the cameras. The algorithm finds possible
 * correspondences and warps the original pixel lattice of points in each
 * camera towards the correspondences, iterating the process as many times as
 * possible. The result is that both local and global adjustment is made to the
 * point clouds to improve micro alignment that may have been incorrect due to
 * either inaccurate camera pose estimation or noise/errors in the depth maps.
 */
Nicolas Pope's avatar
Nicolas Pope committed
class ILW : public ftl::Configurable {
Nicolas Pope's avatar
Nicolas Pope committed
    public:
Nicolas Pope's avatar
Nicolas Pope committed
    explicit ILW(nlohmann::json &config);
Nicolas Pope's avatar
Nicolas Pope committed
    ~ILW();

    /**
Nicolas Pope's avatar
Nicolas Pope committed
     * Take a frameset and perform the iterative lattice warping.
Nicolas Pope's avatar
Nicolas Pope committed
     */
    bool process(ftl::rgbd::FrameSet &fs, cudaStream_t stream=0);
Nicolas Pope's avatar
Nicolas Pope committed

Nicolas Pope's avatar
Nicolas Pope committed
    inline bool isLabColour() const { return use_lab_; }

Nicolas Pope's avatar
Nicolas Pope committed
    private:
Nicolas Pope's avatar
Nicolas Pope committed
    /*
     * Initialise data.
     */
    bool _phase0(ftl::rgbd::FrameSet &fs, cudaStream_t stream);
Nicolas Pope's avatar
Nicolas Pope committed

    /*
     * Find possible correspondences and a confidence value.
     */
Nicolas Pope's avatar
Nicolas Pope committed
    bool _phase1(ftl::rgbd::FrameSet &fs, int win, cudaStream_t stream);
Nicolas Pope's avatar
Nicolas Pope committed

    /*
     * Calculate energies and move the points.
     */
Nicolas Pope's avatar
Nicolas Pope committed
    bool _phase2(ftl::rgbd::FrameSet &fs, float rate, cudaStream_t stream);
Nicolas Pope's avatar
Nicolas Pope committed

    std::vector<detail::ILWData> data_;
Nicolas Pope's avatar
Nicolas Pope committed
    bool enabled_;
    ftl::cuda::ILWParams params_;
    int iterations_;
    float motion_rate_;
    int motion_window_;
    bool use_lab_;
	int discon_mask_;
Nicolas Pope's avatar
Nicolas Pope committed
	bool fill_depth_;
	ftl::cuda::ClipSpace clip_;
	bool clipping_;
Nicolas Pope's avatar
Nicolas Pope committed
};

}

#endif  // _FTL_RECONSTRUCT_ILW_HPP_