ndt_frame_viewer.cpp
Go to the documentation of this file.
00001 #include <ndt_map/pointcloud_utils.h>
00002 #include <ndt_feature_reg/ndt_frame_viewer.h>
00003 
00004 namespace ndt_feature_reg
00005 {
00006 
00007 NDTFrameViewer::NDTFrameViewer(NDTFrameProc *proc)
00008 {
00009     //_frames.push_back(f);
00010     _proc = proc;
00011     initViewer();
00012 }
00013 /*
00014 template <typename PointT>
00015 NDTFrameViewer<PointT>::NDTFrameViewer(NDTFrame<PointT> *f0, NDTFrame<PointT> *f1, NDTFrameProc<PointT> &proc) : _proc(proc)
00016 {
00017      _frames.push_back(f0);
00018      _frames.push_back(f1);
00019      initViewer();
00020 } */
00021 
00022 void
00023 NDTFrameViewer::initViewer()
00024 {
00025     _viewer.reset (new pcl::visualization::PCLVisualizer ("3D Viewer"));
00026     _viewer->setBackgroundColor( 0, 0, 0.01 );
00027     _viewer->addCoordinateSystem(1.0);
00028 }
00029 
00030 /*
00031 template <typename PointT>
00032 void
00033 NDTFrameViewer<PointT>::showPC()
00034 {
00035      for (size_t i = 0; i < _proc.frames.size(); i++)
00036      {
00037           std::string name = "cloud" + toString(i);
00038           pcl::PointCloud<pcl::PointXYZRGB>::Ptr tmp;
00039           *tmp = _proc.frames[i].get
00040           = _proc.createColoredFeaturePC(*(_frames[i]), getPCLColor(i));
00041           _viewer->addPointCloud<PointT> (pc.makeShared(), name);
00042      }
00043 }*/
00044 
00045 void
00046 NDTFrameViewer::showFeaturePC()
00047 {
00048 
00049     pcl::PointCloud<pcl::PointXYZRGB>::Ptr big_cloud (new pcl::PointCloud<pcl::PointXYZRGB>());
00050     std::string name = "featcloud"; // + toString(i);
00051     for (size_t i = 0; i < _proc->frames.size(); i++)
00052     {
00053         pcl::PointCloud<pcl::PointXYZRGB>::Ptr tmp = _proc->createColoredFeaturePC(*_proc->frames[i], this->getPCLColor(i));
00054         lslgeneric::transformPointCloudInPlace(_proc->transformVector[i],*tmp);
00055 
00056         //lslgeneric::writeToVRML(name.c_str(),*tmp);
00057         // TODO -> check why this is needed here!?!
00058         //pcl::io::savePCDFile ("tmp.pcd", *tmp);
00059         //pcl::io::loadPCDFile ("tmp.pcd", *tmp);
00060 
00061         *big_cloud += *tmp;
00062     }
00063     big_cloud->is_dense = false;
00064     pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB> rgb(big_cloud);
00065     _viewer->addPointCloud<pcl::PointXYZRGB> (big_cloud, rgb, name);
00066     //FIXME
00067     //lslgeneric::writeToVRML(name.c_str(),*big_cloud);
00068 }
00069 
00070 void
00071 NDTFrameViewer::showNDT()
00072 {
00073 
00074 }
00075 
00076 void
00077 NDTFrameViewer::showMatches(const std::vector<std::pair<int,int> > &matches)
00078 {
00079     assert(_proc->frames.size() == 2);
00080 
00081     for (size_t i = 0; i < matches.size(); i++)
00082     {
00083         const pcl::PointXYZ& pt1 = _proc->frames[0]->getKeyPointCenter(matches[i].first);
00084         const pcl::PointXYZ& pt2 = _proc->frames[1]->getKeyPointCenter(matches[i].second);
00085 
00086         Eigen::Transform<double,3,Eigen::Affine,Eigen::ColMajor> T = _proc->transformVector[1];
00087         Eigen::Vector3d pt;
00088         pt<<pt2.x,pt2.y,pt2.z;
00089         pt = T*pt;
00090         pcl::PointXYZ pt3;
00091         pt3.x = pt(0);
00092         pt3.y = pt(1);
00093         pt3.z = pt(2);
00094 
00095         std::string name = "line" + toString(i);
00096         _viewer->addLine(pt1, pt3, 0, 1, 1, name);
00097     }
00098 }
00099 
00100 void
00101 NDTFrameViewer::showMatches(const std::vector<cv::DMatch> &matches)
00102 {
00103     std::vector<std::pair<int,int> > tmp;
00104     _proc->convertMatches(matches, tmp);
00105     this->showMatches(tmp);
00106 }
00107 
00108 bool
00109 NDTFrameViewer::wasStopped()
00110 {
00111     return _viewer->wasStopped();
00112 }
00113 
00114 void
00115 NDTFrameViewer::spinOnce()
00116 {
00117     _viewer->spinOnce(100);
00118 }
00119 
00120 }


ndt_feature_reg
Author(s): Henrik Andreasson, Todor Stoyanov, Jari Saarinen
autogenerated on Wed Aug 26 2015 15:25:07