Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zhixiong-tang committed Aug 22, 2023
1 parent d7a9c7b commit 5f55d03
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/nano_fmm/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ FlatGeobuf::PackedRTree &Network::rtree() const
auto &polyline = pair.second.polyline();
for (int64_t seg_idx = 0, N = polyline.rows(); seg_idx < N - 1;
++seg_idx) {
auto index = std::make_pair(poly_idx, seg_idx);
IndexIJ index(poly_idx, seg_idx);
seg2idx_[index] = segs_.size();
segs_.push_back(index);
double x0 = polyline(seg_idx, 0);
Expand Down
4 changes: 2 additions & 2 deletions src/nano_fmm/network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ struct Network
std::shared_ptr<Config> config_;

// spatial index
mutable std::vector<std::pair<int64_t, int64_t>> segs_;
mutable std::unordered_map<std::pair<int64_t, int64_t>, size_t> seg2idx_;
mutable std::vector<IndexIJ> segs_;
mutable std::unordered_map<IndexIJ, size_t, hash_eigen<IndexIJ>> seg2idx_;
mutable std::optional<FlatGeobuf::PackedRTree> rtree_;
FlatGeobuf::PackedRTree &rtree() const;
};
Expand Down
16 changes: 16 additions & 0 deletions src/nano_fmm/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,21 @@ using RowVectorsNx3 = RowVectors;
using RowVectorsNx2 = Eigen::Matrix<double, Eigen::Dynamic, 2, Eigen::RowMajor>;

using VectorUi64 = Eigen::Matrix<uint64_t, Eigen::Dynamic, 1>;
using IndexIJ = Eigen::Matrix<int64_t, 1, 2>;
using IndexIJK = Eigen::Matrix<int64_t, 1, 3>;

// https://github.com/isl-org/Open3D/blob/179886dfd57797b2b0d379062387c60313a58b2b/cpp/open3d/utility/Helper.h#L71
template <typename T> struct hash_eigen
{
std::size_t operator()(T const &matrix) const
{
size_t hash_seed = 0;
for (int i = 0; i < (int)matrix.size(); i++) {
auto elem = *(matrix.data() + i);
hash_seed ^= std::hash<typename T::Scalar>()(elem) + 0x9e3779b9 +
(hash_seed << 6) + (hash_seed >> 2);
}
return hash_seed;
}
};
} // namespace nano_fmm

0 comments on commit 5f55d03

Please sign in to comment.