Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New scoped_view API #260

Merged
merged 6 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/setup-code.org
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#+HTML_HEAD: <style>pre.src{border-radius:5px;background:#343131;color:white;} </style>
#+HTML_HEAD: <style>pre.example{border-radius:5px;background:#454242;color:white;} </style>
#+HTML_HEAD: <style>code{border-radius:5px;background:#454242;color:#0f0;} </style>
#+latex_header: \usepackage[dvipsnames]{xcolor}
4 changes: 4 additions & 0 deletions docs/setup-listings.org
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

# if you get weird error like:
# json-read: Invalid number format: 5
# then "pip install jupyter". nfc.


#+begin_export latex
\colorlet{punct}{red!60!black}
Expand Down
4 changes: 2 additions & 2 deletions gen/src/Reframer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ bool Gen::Reframer::operator()(const input_pointer& inframe, output_pointer& out
out_traces = process_one(*(inframe->traces()));
}
else {
for (const auto tag : m_input_tags) {
for (const auto& tag : m_input_tags) {
const auto& isummary = inframe->trace_summary(tag);
ITrace::vector in_traces = Aux::tagged_traces(inframe, tag);
auto [out_one, threshold] = process_one(in_traces, isummary);
Expand All @@ -171,7 +171,7 @@ bool Gen::Reframer::operator()(const input_pointer& inframe, output_pointer& out
sframe->tag_frame(m_frame_tag);
}

for (const auto tag : m_input_tags) {
for (const auto& tag : m_input_tags) {
sframe->tag_traces(tag, tag_indicies.at(tag), tag_summary[tag]);
}

Expand Down
37 changes: 26 additions & 11 deletions img/test/doctest_clustering_prototype.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ using spdlog::debug;

using node_ptr = std::unique_ptr<Points::node_t>;

static void print_dds(const scoped_pointcloud_t& dds) {
// No more explicit DisjointDataset. It is a PointCloud::Tree::scoped_pointcloud_t.
template <typename DisjointDataset>
void print_dds(const DisjointDataset& dds) {
for (size_t idx=0; idx<dds.size(); ++idx) {
const Dataset& ds = dds[idx];
std::stringstream ss;
ss << "ds: " << idx << std::endl;
const size_t len = ds.size_major();
// const size_t len = ds.size_major();
for (const auto& key : ds.keys()) {
auto arr = ds.get(key)->elements<double>();
ss << key << ": ";
Expand All @@ -44,8 +46,14 @@ Points::node_ptr make_simple_pctree()

// Insert a child with a set of named points clouds with one point
// cloud from a track.

/// QUESTION: can only do this on construction?
/// bv: see NaryTree.h for several insert()'s

/// QUESTION: units?
/// bv: units are always assumed in WCT system-of-units. To be correct
/// here, we should be multiplying by some [length] unit.

auto* n1 = root->insert(Points({
{"center", make_janky_track(Ray(Point(0.5, 0, 0), Point(0.7, 0, 0)))},
{"3d", make_janky_track(Ray(Point(0, 0, 0), Point(1, 0, 0)))}
Expand Down Expand Up @@ -103,27 +111,34 @@ TEST_CASE("PointCloudFacade test")

// name, coords, [depth]
Scope scope{ "3d", {"x","y","z"}};
const scoped_pointcloud_t& pc3d = rval.scoped_pc(scope);
auto const& s3d = rval.scoped_view({ "3d", {"x","y","z"}});

auto const& pc3d = s3d.pcs();
CHECK(pc3d.size() == 2);
print_dds(pc3d);

const scoped_pointcloud_t& pccenter = rval.scoped_pc({ "center", {"x","y","z"}});
auto const& pccenter = rval.scoped_view({ "center", {"x","y","z"}}).pcs();
print_dds(pccenter);

const auto& skd = rval.scoped_kd<double>(scope);
// CHECK(&kd.pointclouds() == &pc3d);
const auto& kd = s3d.kd();

/// QUESTION: how to get it -> node?
const std::vector<double> origin = {1,0,0};
auto knn = skd.knn(2, origin);
/// bv: get the "major index" of the iterator and use that to index in whatever "node like" container
/// auto pts = kd.points();
/// size_t ind = pts.major_index(it);
/// auto& thing = vector_of_node_like_things[ind];
/// see doctest-pointtree-example for details.

std::vector<double> some_point = {1, 0, 0};
auto knn = kd.knn(2, some_point);
for (auto [it,dist] : knn) {
auto& pt = *it;
debug("knn: pt=({},{},{}) dist={}",
pt[0], pt[1], pt[2], dist);
}
CHECK(knn.size() == 2);

const auto& all_points = skd.points();
const auto& all_points = kd.points();
for (size_t pt_ind = 0; pt_ind<knn.size(); ++pt_ind) {
auto& [pit,dist] = knn[pt_ind];
const size_t maj_ind = all_points.major_index(pit);
Expand All @@ -136,12 +151,12 @@ TEST_CASE("PointCloudFacade test")
}
}

auto rad = skd.radius(.01, origin);
auto rad = kd.radius(.01, some_point);
for (auto [it,dist] : rad) {
auto& pt = *it;
debug("rad: pt=({},{},{}) dist={}",
pt[0], pt[1], pt[2], dist);
}
CHECK(rad.size() == 2);

}
}
13 changes: 13 additions & 0 deletions util/inc/WireCellUtil/NFKD.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ namespace WireCell::NFKD {
points_t& points() { return m_points; }
const points_t& points() const { return m_points; }

size_t major_index(iterator it) const {
return m_points.major_index(it);
}
size_t major_index(const_iterator it) const {
return m_points.major_index(it);
}
size_t minor_index(iterator it) const {
return m_points.minor_index(it);
}
size_t minor_index(const_iterator it) const {
return m_points.minor_index(it);
}

// Return the number calls made so far to resolve a point
// coordinate. Mostly for debugging/perfing.
size_t point_calls() const {
Expand Down
203 changes: 0 additions & 203 deletions util/inc/WireCellUtil/Nary.h

This file was deleted.

Loading