1 #ifndef HIERARCHY_H_ 2 #define HIERARCHY_H_ 3 4 #ifdef WITH_CUDA 5 # include <glm/glm.hpp> 6 #endif 7 8 #include <map> 9 #include <vector> 10 #include "adjacent-matrix.hpp" 11 #include "config.hpp" 12 #include "serialize.hpp" 13 #define RCPOVERFLOW 2.93873587705571876e-39f 14 15 using namespace Eigen; 16 17 namespace qflow { 18 19 class Hierarchy { 20 public: 21 Hierarchy(); 22 void Initialize(double scale, int with_scale = 0); 23 void DownsampleGraph(const AdjacentMatrix adj, const MatrixXd& V, const MatrixXd& N, 24 const VectorXd& A, MatrixXd& V_p, MatrixXd& N_p, VectorXd& A_p, 25 MatrixXi& to_upper, VectorXi& to_lower, AdjacentMatrix& adj_p); 26 void generate_graph_coloring_deterministic(const AdjacentMatrix& adj, int size, 27 std::vector<std::vector<int>>& phases); 28 void FixFlip(); 29 int FixFlipSat(int depth, int threshold = 0); 30 void PushDownwardFlip(int depth); 31 void PropagateEdge(); 32 void DownsampleEdgeGraph(std::vector<Vector3i>& FQ, std::vector<Vector3i>& F2E, 33 std::vector<Vector2i>& edge_diff, 34 std::vector<int>& allow_changes, int level); 35 void UpdateGraphValue(std::vector<Vector3i>& FQ, std::vector<Vector3i>& F2E, 36 std::vector<Vector2i>& edge_diff); 37 38 enum { MAX_DEPTH = 25 }; 39 40 void SaveToFile(FILE* fp); 41 void LoadFromFile(FILE* fp); 42 43 void clearConstraints(); 44 void propagateConstraints(); 45 46 double mScale; 47 int rng_seed; 48 49 MatrixXi mF; // mF(i, j) i \in [0, 3) ith index in face j 50 VectorXi mE2E; // inverse edge 51 std::vector<AdjacentMatrix> mAdj; 52 std::vector<MatrixXd> mV; 53 std::vector<MatrixXd> mN; 54 std::vector<VectorXd> mA; 55 std::vector<std::vector<std::vector<int>>> mPhases; 56 // parameters 57 std::vector<MatrixXd> mQ; 58 std::vector<MatrixXd> mO; 59 std::vector<VectorXi> mToLower; 60 std::vector<MatrixXi> mToUpper; // mToUpper[h](i, j) \in V; i \in [0, 2); j \in V 61 std::vector<MatrixXd> mS; 62 std::vector<MatrixXd> mK; 63 64 // constraints 65 std::vector<MatrixXd> mCQ; 66 std::vector<MatrixXd> mCO; 67 std::vector<VectorXd> mCQw; 68 std::vector<VectorXd> mCOw; 69 70 int with_scale; 71 72 // upper: fine to coarse 73 std::vector<std::vector<int>> mToUpperFaces; // face correspondance 74 std::vector<std::vector<int>> mSing; 75 std::vector<std::vector<int>> mToUpperEdges; // edge correspondance 76 std::vector<std::vector<int>> mToUpperOrients; // rotation of edges from fine to coarse 77 std::vector<std::vector<Vector3i>> mFQ; // face_edgeOrients 78 std::vector<std::vector<Vector3i>> mF2E; // face_edgeIds 79 std::vector<std::vector<Vector2i>> mE2F; // undirect edges to face ID 80 std::vector<std::vector<int> > mAllowChanges; 81 std::vector<std::vector<Vector2i>> mEdgeDiff; // face_edgeDiff 82 83 #ifdef WITH_CUDA 84 std::vector<Link*> cudaAdj; 85 std::vector<int*> cudaAdjOffset; 86 std::vector<glm::dvec3*> cudaN; 87 std::vector<glm::dvec3*> cudaV; 88 std::vector<glm::dvec3*> cudaQ; 89 std::vector<glm::dvec3*> cudaO; 90 std::vector<std::vector<int*>> cudaPhases; 91 std::vector<glm::ivec2*> cudaToUpper; 92 void CopyToDevice(); 93 void CopyToHost(); 94 #endif 95 }; 96 97 } // namespace qflow 98 99 #endif 100