4343#include < mcptam/SmallBlurryImage.h>
4444#include < mcptam/Map.h>
4545#include < mcptam/BundleAdjusterBase.h>
46+ #include < mcptam/MapMakerTiming.h>
4647
4748MapMaker::MapMaker (Map &map, TaylorCameraMap &cameras, BundleAdjusterBase &bundleAdjuster)
4849: MapMakerBase(map, true )
4950, MapMakerClientBase(map)
5051, MapMakerServerBase(map, cameras, bundleAdjuster)
5152{
53+ mCreationTimingPub = mNodeHandlePriv .advertise <mcptam::MapMakerTiming>(" timing_mkf_creation" , 1 , true );
54+ mLocalTimingPub = mNodeHandlePriv .advertise <mcptam::MapMakerTiming>(" timing_local_ba" , 1 ,true );
55+ mGlobalTimingPub = mNodeHandlePriv .advertise <mcptam::MapMakerTiming>(" timing_global_ba" , 1 ,true );
56+
5257 Reset ();
5358 start ();
5459}
@@ -189,9 +194,19 @@ void MapMaker::run()
189194 mBundleAdjuster .UseTukey ((mState == MM_RUNNING && mMap .mlpMultiKeyFrames .size () > 2 ));
190195 mBundleAdjuster .UseTwoStep ((mState == MM_RUNNING && mMap .mlpMultiKeyFrames .size () > 2 ));
191196
197+ mcptam::MapMakerTiming timingMsg;
198+ timingMsg.map_num_mkfs = mMap .mlpMultiKeyFrames .size ();
199+ timingMsg.map_num_points = mMap .mlpPoints .size ();
200+
201+ ros::Time start = ros::Time::now ();
202+
192203 int nAccepted = mBundleAdjuster .BundleAdjustRecent (vOutliers);
193204 // mdMaxCov = mBundleAdjuster.GetMaxCov();
194205
206+ ros::Time nowTime = ros::Time::now ();
207+ timingMsg.elapsed = (nowTime - start).toSec ();
208+ timingMsg.header .stamp = nowTime;
209+
195210 ROS_DEBUG_STREAM (" Accepted iterations: " <<nAccepted);
196211 ROS_DEBUG_STREAM (" Number of outliers: " <<vOutliers.size ());
197212 // ROS_DEBUG_STREAM("Max cov: "<<mdMaxCov);
@@ -210,6 +225,9 @@ void MapMaker::run()
210225 mnNumConsecutiveFailedBA = 0 ;
211226 HandleOutliers (vOutliers);
212227 PublishMapVisualization ();
228+
229+ timingMsg.elapsed /= nAccepted;
230+ mLocalTimingPub .publish (timingMsg);
213231 }
214232 }
215233
@@ -233,7 +251,18 @@ void MapMaker::run()
233251 mBundleAdjuster .UseTukey (mState == MM_RUNNING && mMap .mlpMultiKeyFrames .size () > 2 );
234252 mBundleAdjuster .UseTwoStep ((mState == MM_RUNNING && mMap .mlpMultiKeyFrames .size () > 2 ));
235253
254+ mcptam::MapMakerTiming timingMsg;
255+ timingMsg.map_num_mkfs = mMap .mlpMultiKeyFrames .size ();
256+ timingMsg.map_num_points = mMap .mlpPoints .size ();
257+
258+ ros::Time start = ros::Time::now ();
259+
236260 int nAccepted = mBundleAdjuster .BundleAdjustAll (vOutliers);
261+
262+ ros::Time nowTime = ros::Time::now ();
263+ timingMsg.elapsed = (nowTime - start).toSec ();
264+ timingMsg.header .stamp = nowTime;
265+
237266 mdMaxCov = mBundleAdjuster .GetMaxCov ();
238267
239268 ROS_DEBUG_STREAM (" Accepted iterations: " <<nAccepted);
@@ -255,6 +284,9 @@ void MapMaker::run()
255284 HandleOutliers (vOutliers);
256285 PublishMapVisualization ();
257286
287+ timingMsg.elapsed /= nAccepted;
288+ mGlobalTimingPub .publish (timingMsg);
289+
258290 if (mState == MM_INITIALIZING && (mdMaxCov < MapMakerServerBase::sdInitCovThresh || mbStopInit))
259291 {
260292 ROS_INFO_STREAM (" INITIALIZING, Max cov " <<mdMaxCov<<" below threshold " <<MapMakerServerBase::sdInitCovThresh<<" , switching to MM_RUNNING" );
@@ -401,6 +433,12 @@ void MapMaker::AddMultiKeyFrameFromTopOfQueue()
401433 }
402434*/
403435
436+ mcptam::MapMakerTiming timingMsg;
437+ timingMsg.map_num_mkfs = mMap .mlpMultiKeyFrames .size ();
438+ timingMsg.map_num_points = mMap .mlpPoints .size ();
439+
440+ ros::Time start = ros::Time::now ();
441+
404442 if (mState == MM_RUNNING)
405443 {
406444 if (pMKF->NoImages ()) // leftovers from Tracker, don't bother adding these
@@ -427,6 +465,11 @@ void MapMaker::AddMultiKeyFrameFromTopOfQueue()
427465 mMap .MoveDeletedMultiKeyFramesToTrash ();
428466 }
429467
468+ ros::Time nowTime = ros::Time::now ();
469+ timingMsg.elapsed = (nowTime - start).toSec ();
470+ timingMsg.header .stamp = nowTime;
471+ mCreationTimingPub .publish (timingMsg);
472+
430473 lock.lock ();
431474 mqpMultiKeyFramesFromTracker.pop_front ();
432475 lock.unlock ();
0 commit comments