11 _id = std::make_shared<lazy<rs2_extrinsics>>([]()
45 _extrinsics[to_idx][from_idx] = std::shared_ptr<lazy<rs2_extrinsics>>(
nullptr);
50 auto lazy_extr = std::make_shared<lazy<rs2_extrinsics>>([=]() {
return extr; });
66 throw std::runtime_error(
"override_extrinsics called for invalid <from> stream" );
67 auto& from_map = from_it->second;
70 auto to_it = from_map.find( to_idx );
71 if( to_it == from_map.end() )
72 throw std::runtime_error(
"override_extrinsics called for invalid <to> stream" );
73 auto& weak_ptr = to_it->second;
74 auto sp = weak_ptr.lock();
76 throw std::runtime_error(
"override_extrinsics called for out-of-date stream" );
78 auto & lazy_extr = *sp;
79 lazy_extr = [=]() {
return extr; };
87 std::vector<int> invalid_ids;
90 if (!
kvp.second.lock())
92 auto invalid_id =
kvp.first;
96 invalid_ids.push_back(invalid_id);
100 for (
auto removed_id : invalid_ids)
102 _streams.erase(removed_id);
106 elem.second.erase(removed_id);
111 if (!invalid_ids.empty())
112 LOG_INFO(
"Found " << invalid_ids.size() <<
" unreachable streams, " << std::dec <<
counter <<
" extrinsics deleted");
117 auto sp = p.shared_from_this();
121 if (
kvp.second.lock().get() == sp.get())
123 max = std::max( max,
kvp.first );
125 if( !add_if_not_there )
127 _streams[max + 1] = sp;
139 if (from_idx == to_idx)
145 std::set<int> visited;
151 if (visited.count(from))
return false;
156 auto back_edge = fetch_edge(to, from);
157 auto fwd_edge = fetch_edge(from, to);
160 if (fwd_edge.get() || back_edge.get())
163 *extr = fwd_edge->operator*();
165 *extr =
inverse(back_edge->operator*());
171 visited.insert(from);
172 for (
auto&&
kvp :
it->second)
174 auto new_from =
kvp.first;
175 auto way =
kvp.second;
178 back_edge = fetch_edge(new_from, from);
179 fwd_edge = fetch_edge(from, new_from);
181 if ((back_edge.get() || fwd_edge.get()) &&
184 const auto local = [&]() {
186 return fwd_edge->operator*();
188 return inverse(back_edge->operator*());
201 std::shared_ptr<lazy<rs2_extrinsics>> extrinsics_graph::fetch_edge(
int from,
int to)
206 auto it2 =
it->second.find(to);
207 if (it2 !=
it->second.end())
209 return it2->second.lock();
std::vector< std::shared_ptr< lazy< rs2_extrinsics > > > _external_extrinsics
rs2_extrinsics from_pose(pose a)
std::shared_ptr< platform::time_service > get_time_service()
std::map< int, std::map< int, std::weak_ptr< lazy< rs2_extrinsics > > > > _extrinsics
void cleanup_extrinsics()
std::atomic< int > _locks_count
void register_same_extrinsics(const stream_interface &from, const stream_interface &to)
std::map< int, std::weak_ptr< const stream_interface > > _streams
void override_extrinsics(const stream_interface &from, const stream_interface &to, rs2_extrinsics const &extr)
rs2_extrinsics identity_matrix()
pose inverse(const pose &a)
pose to_pose(const rs2_extrinsics &a)
void register_extrinsics(const stream_interface &from, const stream_interface &to, std::weak_ptr< lazy< rs2_extrinsics >> extr)
void set_time_service(std::shared_ptr< platform::time_service > ts)
static environment & get_instance()
extrinsics_graph & get_extrinsics_graph()
Cross-stream extrinsics: encodes the topology describing how the different devices are oriented...
LOG_INFO("Log message using LOG_INFO()")
int find_stream_profile(const stream_interface &p, bool add_if_not_there=true)
std::shared_ptr< lazy< rs2_extrinsics > > _id
bool try_fetch_extrinsics(const stream_interface &from, const stream_interface &to, rs2_extrinsics *extr)