• Apoorv Goel's avatar
    Merge pull request #2161 from UnderscoreAsterisk:dynafu · 8b59dffc
    Apoorv Goel authored
    DynamicFusion Implementation
    
    * Add new nodes from points
    
    * Addition of new node in the field
    
    * Warp nodes demo
    
    * Add newline before {
    
    * Remove 3rd party flann dependency
    
    * Regularisation Heirarchy
    
    * Correct node radius
    
    * Change default growth rate
    
    * New node position = centroid of the neighbourhood
    
    * Enlarge nodes while paused
    
    * Dynafu TSDF
    
    * TSDF demo
    
    * Avoid double calc and adjust initial tsdf weight
    
    * Fix bug that caused some voxels to disappear
    
    * getNodePos helper
    
    * Remove USE_INTRINSIC check
    
    * Correct RT avg calculation and remove redundant knn calc
    
    * Slight perf improvements
    
    * Use LinearIndex
    
    * Debug calculations
    
    * set all nodes' RT
    
    * Various bug fixes
    
    * Separate camera and warpfield
    
    * Add dynafu documentation
    
    * Adhere to coding style
    
    * Add dynafu unit test
    
    * update demo
    
    * Merge pull request #2133 from savuor:kinfu_truncate
    
    KinectFusion: several updates (#2133)
    
    * truncateThreshold added
    
    * demo updated for RealSense
    
    * first Kinect2, then RealSense
    
    * more distance-based parameters
    
    * Remove trailing whitespaces
    
    * Replace bool vector with array
    
    * create findNeighbours in WarpField
    
    * Maintain nodesPos matrix in WarpField
    
    * Fix warnings on Windows build
    
    * Remove cameraPose from WarpField
    
    * Use AutoBuffer
    
    * Marching Cubes
    
    * Fix MC
    
    * Split mesh vertices & edges
    
    * Change Mat types in MC
    
    * OpenGL rendering
    
    * Check for HAVE_OPENGL
    
    * Error handling in case HAVE_OPENGL is not defined
    
    * Replace Mat_ with std::vector inside marchCubes
    
    * Parallelise marching cubes
    
    * Fix warpfield and estimate depth inside DynaFuImpl::updateT()
    
    * Linearise depth and use points/normals from MC
    
    * Don't test dynafu without OpenGL support
    
    * Analytical calculation of Jacobian matrices
    
    * Add details about rotation and differentiate graph terms in J_r
    
    * Use derivative of T^-1 from the tutorial
    
    * Remove L2 norm from reg term
    
    * Use chain rule to differentiate data term
    
    * Markdown
    
    * Fix markdown
    
    * Replace MD file by HTML
    
    * Change the data term expression
    
    * Calculate J_d using vector identities
    
    * Rasterize vertex and normals
    
    * Apply warpfield before rendering
    
    * Add CV_UNUSED for normImage to fix warning
    
    * Render float image instead of uint8
    
    * Implement ICP data term and other changes:
    1. add option to applyWarp to normals
    2. add option to `fetchPointNormals` to return points in voxel coordinates
    3. Fix: Use voxel coordinates to update WarpField
    
    * Fix non-OpenGL build
    
    * Intialise newly discovered node transforms with DQB
    
    * Fix data term
    
    * Change data term normal and add kinfu-like distance/angle checks
    
    * Implement regularisation
    
    * Fix warnings
    
    * Credit authors of DQB and table for MC
    
    * cast size_t to int to supress warning
    
    * Correct regularisation and add normal equation set up
    
    * Delete html
    
    * Dynafu unit test
    8b59dffc
dqb.hpp 2.94 KB
/*
The code for Dual Quaternion Blending provided here is a modified
version of the sample codes by Arkan.

Copyright (c) 2019 Arkan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#ifndef __OPENCV_RGBD_DQB_HPP__
#define __OPENCV_RGBD_DQB_HPP__

#include "opencv2/core.hpp"
#include "opencv2/core/affine.hpp"

namespace cv {
namespace dynafu {

class Quaternion
{
public:
    Quaternion();
    Quaternion(float w, float i, float j, float k);

    // Generate a quaternion from rotation of a Rt matrix.
    Quaternion(const Affine3f& r);

    float normalize()
    {
        float n = (float)cv::norm(coeff);
        coeff /= n;
        return n;
    }

    Affine3f getRotation() const;

    float w() const {return coeff[0];}
    float i() const {return coeff[1];}
    float j() const {return coeff[2];}
    float k() const {return coeff[3];}

    float norm() const {return (float)cv::norm(coeff);}

    friend Quaternion operator*(float a, const Quaternion& q);
    friend Quaternion operator*(const Quaternion& q, float a);
    friend Quaternion operator/(const Quaternion& q, float a);
    friend Quaternion operator+(const Quaternion& q1, const Quaternion& q2);
    friend Quaternion& operator+=(Quaternion& q1, const Quaternion& q2);
    friend Quaternion& operator/=(Quaternion& q, float a);

private:
    // w, i, j, k coefficients
    Vec4f coeff;
};

class DualQuaternion
{
public:
    DualQuaternion();
    DualQuaternion(const Affine3f& Rt);
    DualQuaternion(Quaternion& q0, Quaternion& qe);

    void normalize();

    friend DualQuaternion& operator+=(DualQuaternion& q1, const DualQuaternion& q2);
    friend DualQuaternion operator*(float a, const DualQuaternion& q);

    Affine3f getAffine() const;

private:
    Quaternion q0; // rotation quaternion
    Quaternion qe; // translation quaternion
};

DualQuaternion DQB(std::vector<float>& weights, std::vector<DualQuaternion>& quats);

Affine3f DQB(std::vector<float>& weights, std::vector<Affine3f>& transforms);


} // namespace dynafu
} // namespace cv

#endif