File size: 3,690 Bytes
f6dd1c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef NODESAMPLER_H
#define NODESAMPLER_H
#include "Types.h"

namespace svr
{
    //------------------------------------------------------------------------
    //	Define neighborIter class
    //------------------------------------------------------------------------
    class neighborIter
    {
    public:
        neighborIter(const std::map<size_t, Scalar> &nodeNeighbors)
        {
            m_neighborIter = nodeNeighbors.begin();
            m_neighborEnd = nodeNeighbors.end();
        }

        neighborIter& operator++()
        {
            if (m_neighborIter != m_neighborEnd)
                ++m_neighborIter;
            return *this;
        }

        neighborIter operator++(int)
        {
            neighborIter tempIter(*this);
            ++*this;
            return tempIter;
        }

        const std::pair<const size_t, Scalar>& operator*() { return *m_neighborIter; }
        std::map<size_t, Scalar>::const_iterator operator->() { return m_neighborIter; }
        bool is_valid() { return m_neighborIter != m_neighborEnd; }
        size_t getIndex() { return m_neighborIter->first; }
        Scalar getWeight() { return m_neighborIter->second; }

    private:
        std::map<size_t, Scalar>::const_iterator m_neighborIter;
        std::map<size_t, Scalar>::const_iterator m_neighborEnd;
    };

    //------------------------------------------------------------------------
    //	Define node sampling class
    //------------------------------------------------------------------------
    class nodeSampler
    {
    public:
        enum sampleAxis { X_AXIS, Y_AXIS, Z_AXIS };
        nodeSampler() {};

        // return sample radius
        Scalar SampleAndConstuct(Mesh &mesh, Scalar sampleRadiusRatio, const Matrix3X & src_points);
        Scalar SampleAndConstuctAxis(Mesh &mesh, Scalar sampleRadiusRatio, sampleAxis axis);

        Scalar SampleAndConstuctForSrcPoints(Mesh &mesh, Scalar sampleRadiusRatio, const Matrix3X & src_points, const Eigen::MatrixXi & src_knn_indices);
        Scalar SampleAndConstuctFPS(Mesh &mesh, Scalar sampleRadiusRatio, const Matrix3X & src_points, const Eigen::MatrixXi & src_knn_indices, int num_vn, int num_nn);


        void updateWeight(Mesh &mesh);
        void constructGraph(bool is_uniform);

        size_t nodeSize() const { return m_nodeContainer.size(); }

        neighborIter getNodeNodeIter(size_t nodeIdx) const { return neighborIter(m_nodeGraph[nodeIdx]); }
        neighborIter getVertexNodeIter(size_t vertexIdx) const { return neighborIter(m_vertexGraph[vertexIdx]); }
        size_t getNodeVertexIdx(size_t nodeIdx) const { return m_nodeContainer.at(nodeIdx).second; }

        size_t getVertexNeighborSize(size_t vertexIdx) const { return m_vertexGraph.at(vertexIdx).size(); }
        size_t getNodeNeighborSize(size_t nodeIdx) const { return m_nodeGraph.at(nodeIdx).size(); }
        void initWeight(RowMajorSparseMatrix& matPV, VectorX & matP,
			RowMajorSparseMatrix& matB, VectorX& matD, VectorX& smoothw);
        void print_nodes(Mesh & mesh, std::string file_path);

    private:
        size_t m_meshVertexNum = 0;
        size_t m_meshEdgeNum = 0;
        Scalar m_averageEdgeLen = 0.0f;
        Scalar m_sampleRadius = 0.0f;
        std::vector<Scalar> non_unisamples_Radius;
        Mesh * m_mesh;

    public:
        std::vector<std::pair<size_t, size_t>> m_nodeContainer;
        std::vector<std::map<size_t, Scalar>> m_vertexGraph; // vertex node graph
        std::vector<std::map<size_t, Scalar>> m_nodeGraph;
        std::vector<VectorX> m_geoDistContainer;
        Eigen::VectorXi      VertexNodeIdx;
        Eigen::VectorXi      projection_indices;

    };
}
#endif