| 276 | } |
| 277 | |
| 278 | void Frame::SetReferenceKeyframe(std::shared_ptr<Frame> reference_kf) { |
| 279 | std::lock_guard<std::mutex> lock(m_pose_mutex); |
| 280 | m_reference_keyframe = reference_kf; |
| 281 | |
| 282 | // Calculate relative transformation at the time of setting reference keyframe |
| 283 | if (reference_kf) { |
| 284 | // Current frame pose (direct from m_rotation, m_translation) |
| 285 | Eigen::Matrix4f T_wb_current = Eigen::Matrix4f::Identity(); |
| 286 | T_wb_current.block<3, 3>(0, 0) = m_rotation; |
| 287 | T_wb_current.block<3, 1>(0, 3) = m_translation; |
| 288 | |
| 289 | // Reference keyframe pose - need to unlock before calling GetTwb on another frame |
| 290 | // to avoid potential issues, we get pose components directly |
| 291 | Eigen::Matrix4f T_wb_ref = Eigen::Matrix4f::Identity(); |
| 292 | T_wb_ref.block<3, 3>(0, 0) = reference_kf->GetRotation(); |
| 293 | T_wb_ref.block<3, 1>(0, 3) = reference_kf->GetTranslation(); |
| 294 | |
| 295 | // Calculate relative transformation: T_rel = T_ref^-1 * T_current |
| 296 | m_T_relative_from_ref = T_wb_ref.inverse() * T_wb_current; |
| 297 | } else { |
| 298 | // No reference keyframe, set to identity |
| 299 | m_T_relative_from_ref = Eigen::Matrix4f::Identity(); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | std::shared_ptr<Frame> Frame::GetReferenceKeyframe() const { |
| 304 | return m_reference_keyframe.lock(); |
no test coverage detected