#ifndef NODESAMPLER_H #define NODESAMPLER_H #include "Types.h" namespace svr { //------------------------------------------------------------------------ // Define neighborIter class //------------------------------------------------------------------------ class neighborIter { public: neighborIter(const std::map &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& operator*() { return *m_neighborIter; } std::map::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::const_iterator m_neighborIter; std::map::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 non_unisamples_Radius; Mesh * m_mesh; public: std::vector> m_nodeContainer; std::vector> m_vertexGraph; // vertex node graph std::vector> m_nodeGraph; std::vector m_geoDistContainer; Eigen::VectorXi VertexNodeIdx; Eigen::VectorXi projection_indices; }; } #endif