88#include " precomp.hpp"
99#include " loop_closure_detection.hpp"
1010
11+ // DEBUG
12+ #include " opencv2/viz.hpp"
13+
1114namespace cv
1215{
1316namespace large_kinfu
@@ -335,8 +338,51 @@ bool LargeKinfuImpl<MatType>::updateT(const MatType& _depth, const Mat& _img)
335338 }
336339 }
337340
341+ // DEBUG
342+ auto drawScene = [&]()
343+ {
344+ viz::Viz3d view (" debug" );
345+ std::vector<viz::Color> colors = { viz::Color::amethyst (), viz::Color::apricot (), viz::Color::azure (),
346+ viz::Color::bluberry (), viz::Color::blue (), viz::Color::brown (),
347+ viz::Color::celestial_blue (), viz::Color::chartreuse (), viz::Color::cherry () };
348+ for (int i = 0 ; i < submapMgr->submapList .size (); i++)
349+ {
350+ Ptr<detail::Submap<MatType>> ps = submapMgr->submapList [i];
351+ MatType p;
352+ ps->volume ->fetchPointsNormals (p, noArray ());
353+
354+ Mat pmat; p.copyTo (pmat);
355+ float step = 0 .03f ;
356+ typedef std::tuple<int , int , int > int3;
357+ std::set<int3> dset;
358+ for (int j = 0 ; j < pmat.rows ; j++)
359+ {
360+ Vec4f pp = pmat.at <Vec4f>(j);
361+ dset.insert (int3 (pp[0 ] / step, pp[1 ] / step, pp[2 ] / step));
362+ }
363+ std::vector<Point3f> downsampled;
364+ for (auto ix : dset)
365+ {
366+ int x, y, z;
367+ std::tie (x, y, z) = ix;
368+ downsampled.push_back (Point3f (x * step, y * step, z * step));
369+ }
370+ Mat pp (downsampled);
371+ viz::WCloud c (pp, colors[i % colors.size ()]);
372+ Affine3f pm = ps->pose ;
373+ // pm = Affine3f(pm.rotation().t(), pm.translation());
374+ view.showWidget (cv::format (" d%d" , i), c, pm);
375+ }
376+ view.showWidget (" 3d" , viz::WCoordinateSystem ());
377+ view.showWidget (" plane" , viz::WGrid ());
378+ view.spin ();
379+ };
380+
338381 if (isMapUpdated)
339382 {
383+ // DEBUG
384+ drawScene ();
385+
340386 // TODO: Convert constraints to posegraph
341387 Ptr<detail::PoseGraph> poseGraph = submapMgr->MapToPoseGraph ();
342388 CV_LOG_INFO (NULL , " Created posegraph" );
@@ -349,6 +395,9 @@ bool LargeKinfuImpl<MatType>::updateT(const MatType& _depth, const Mat& _img)
349395
350396 submapMgr->PoseGraphToMap (poseGraph);
351397
398+ // DEBUG
399+ drawScene ();
400+
352401 }
353402 CV_LOG_INFO (NULL , " Number of submaps: " << submapMgr->submapList .size ());
354403
@@ -361,12 +410,34 @@ template<typename MatType>
361410void LargeKinfuImpl<MatType>::render(OutputArray image) const
362411{
363412 CV_TRACE_FUNCTION ();
413+ // DEBUG
414+ /*
364415 auto currSubmap = submapMgr->getCurrentSubmap();
365416 //! TODO: Can render be dependent on current submap
366417 MatType pts, nrm;
367418 currSubmap->frame->getPyramidAt(pts, OdometryFrame::PYR_CLOUD, 0);
368419 currSubmap->frame->getPyramidAt(nrm, OdometryFrame::PYR_NORM, 0);
369420 detail::renderPointsNormals(pts, nrm, image, params.lightPose);
421+ */
422+ Mat places (Size (1280 , 900 ), CV_8UC4);
423+ size_t sz = submapMgr->submapList .size ();
424+ for (int i = 0 ; i < sz; i++)
425+ {
426+ auto s = submapMgr->submapList [i];
427+ MatType pts, nrm, img;
428+ s->frame ->getPyramidAt (pts, OdometryFrame::PYR_CLOUD, 0 );
429+ s->frame ->getPyramidAt (nrm, OdometryFrame::PYR_NORM, 0 );
430+ detail::renderPointsNormals (pts, nrm, img, params.lightPose );
431+ MatType smallImg;
432+ resize (img, smallImg, Size (320 , 240 ));
433+ smallImg.copyTo (
434+ places (
435+ Rect (Point (320 *(i%4 ), 240 *(i/4 )), Size (320 , 240 ))
436+ )
437+ );
438+ }
439+ image.createSameSize (places, CV_8UC4);
440+ places.copyTo (image);
370441}
371442
372443
0 commit comments