1 #ifndef __IMAGECLUSTERMANAGER_CXX__
2 #define __IMAGECLUSTERMANAGER_CXX__
4 #include <opencv2/imgproc/imgproc.hpp>
34 if(
id >=
_alg_v.size())
throw larbys(
"Invalid algorithm ID requested...");
45 auto iter =
_alg_m.find(name);
47 return (*iter).second;
63 _profile = main_cfg.get<
bool>(
"Profile");
67 std::vector<std::string> instance_type_v = main_cfg.get<std::vector<std::string> >(
"AlgoType");
68 std::vector<std::string> instance_name_v = main_cfg.get<std::vector<std::string> >(
"AlgoName");
70 if(instance_type_v.size() != instance_name_v.size()) {
71 LARCV_CRITICAL((*
this)) <<
"AlgoType and AlgoName config parameters have different length! "
72 <<
"(" << instance_type_v.size() <<
" vs. " << instance_name_v.size() <<
")" << std::endl;
78 for(
size_t i=0; i<instance_type_v.size(); ++i) {
79 auto const& name = instance_name_v[i];
80 auto const& type = instance_type_v[i];
82 LARCV_CRITICAL((*
this)) <<
"Duplicate algorithm name found!" << std::endl;
83 throw larbys(
"Duplicate algorithm name found!");
92 ptr->set_verbosity(this->
logger().level());
93 ptr->Configure(main_cfg.get_pset(ptr->Name()));
102 std::cout <<
" ================== " <<
Name() <<
" Profile Report ==================" << std::endl
104 for(
auto const& ptr :
_alg_v) {
105 std::cout << Form(
" \033[93m%-20s\033[00m ... # call %-5zu ... total time %g [s] ... average time %g [s/process]",
106 ptr->Name().c_str(), ptr->ProcessCount(), ptr->ProcessTime(), ptr->ProcessTime() / (double)(ptr->ProcessCount()))
118 if(meta.num_pixel_row()!=img.rows)
119 throw larbys(
"Provided metadata has incorrect # horizontal pixels w.r.t. image!");
121 if(meta.num_pixel_column()!=img.cols)
122 throw larbys(
"Provided metadata has incorrect # vertical pixels w.r.t. image!");
132 for(
auto& alg_ptr :
_alg_v) {
134 if(!alg_ptr)
throw larbys(
"Invalid algorithm pointer!");
136 if(alg_ptr == _alg_v.front()) {
150 auto const& result_meta =
_meta_v.back();
151 if(result_meta.height() >
_orig_meta.height()) {
152 std::cerr <<
"Return meta data by " << alg_ptr->Name() <<
" exceeds original image height!" << std::endl;
155 if(result_meta.width() >
_orig_meta.width()) {
156 std::cerr <<
"Return meta data by " << alg_ptr->Name() <<
" exceeds original image width!" << std::endl;
170 if(alg_id >=
_meta_v.size())
throw larbys(
"Invalid algorithm ID requested");
171 throw larbys(
"Execution of an algorithm not yet done!");
176 auto const& clusters =
Clusters(alg_id);
177 if(cluster_id >= clusters.size())
throw larbys(
"Invalid cluster ID requested");
178 return clusters[cluster_id];
185 throw larbys(
"Execution of an algorithm not yet done!");
199 auto const& meta =
_meta_v[alg_id];
201 auto const& origin = meta.origin();
203 if(x < origin.x || x > (origin.x + meta.width()))
return result;
205 if(y < origin.y || x > (origin.y + meta.height()))
return result;
209 auto pt = ::cv::Point2d((x-origin.x)/meta.pixel_width(),(y-origin.y)/meta.pixel_height());
213 for(
size_t id=0;
id<clusters.size(); ++id) {
215 auto const& c = clusters[id];
217 double inside = ::cv::pointPolygonTest(c,pt,
false);
219 if(inside < 0)
continue;