Update tutorial get_points

This commit is contained in:
John Zhao 2018-05-10 22:11:20 +08:00
parent 4dc9108ae4
commit 90bb1cdd9a
4 changed files with 16 additions and 16 deletions

View File

@ -98,7 +98,7 @@ make_executable(get_disparity SRCS data/get_disparity.cc WITH_OPENCV)
make_executable(get_depth SRCS data/get_depth.cc WITH_OPENCV) make_executable(get_depth SRCS data/get_depth.cc WITH_OPENCV)
if(PCL_FOUND) if(PCL_FOUND)
make_executable(get_points make_executable(get_points
SRCS data/get_points.cc data/pcviewer.cc SRCS data/get_points.cc data/pc_viewer.cc
WITH_OPENCV WITH_PCL WITH_OPENCV WITH_PCL
) )
endif() endif()

View File

@ -17,7 +17,7 @@
#include "mynteye/api.h" #include "mynteye/api.h"
#include "data/pcviewer.h" #include "data/pc_viewer.h"
MYNTEYE_USE_NAMESPACE MYNTEYE_USE_NAMESPACE
@ -43,14 +43,14 @@ int main(int argc, char *argv[]) {
auto &&points_data = api->GetStreamData(Stream::POINTS); auto &&points_data = api->GetStreamData(Stream::POINTS);
if (!points_data.frame.empty()) { if (!points_data.frame.empty()) {
pcviewer.Draw(points_data.frame); pcviewer.Update(points_data.frame);
} }
char key = static_cast<char>(cv::waitKey(1)); char key = static_cast<char>(cv::waitKey(1));
if (key == 27 || key == 'q' || key == 'Q') { // ESC/Q if (key == 27 || key == 'q' || key == 'Q') { // ESC/Q
break; break;
} }
if (pcviewer.WasDrew() && pcviewer.WasStopped()) { if (pcviewer.WasStopped()) {
break; break;
} }
} }

View File

@ -11,7 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "data/pcviewer.h" #include "data/pc_viewer.h"
#include <glog/logging.h> #include <glog/logging.h>
@ -52,13 +52,13 @@ PCViewer::~PCViewer() {
} }
} }
void PCViewer::Draw(const cv::Mat &xyz) { void PCViewer::Update(const cv::Mat &xyz) {
pcl::PointCloud<pcl::PointXYZ>::Ptr pc(new pcl::PointCloud<pcl::PointXYZ>); pcl::PointCloud<pcl::PointXYZ>::Ptr pc(new pcl::PointCloud<pcl::PointXYZ>);
ConvertMatToPointCloud(xyz, pc); ConvertMatToPointCloud(xyz, pc);
Draw(pc); Update(pc);
} }
void PCViewer::Draw(pcl::PointCloud<pcl::PointXYZ>::ConstPtr pc) { void PCViewer::Update(pcl::PointCloud<pcl::PointXYZ>::ConstPtr pc) {
if (viewer_ == nullptr) { if (viewer_ == nullptr) {
viewer_ = CustomColorVis(pc); viewer_ = CustomColorVis(pc);
} }
@ -66,12 +66,12 @@ void PCViewer::Draw(pcl::PointCloud<pcl::PointXYZ>::ConstPtr pc) {
viewer_->spinOnce(); viewer_->spinOnce();
} }
bool PCViewer::WasDrew() const { bool PCViewer::WasVisual() const {
return viewer_ != nullptr; return viewer_ != nullptr;
} }
bool PCViewer::WasStopped() const { bool PCViewer::WasStopped() const {
return viewer_ == nullptr || viewer_->wasStopped(); return viewer_ != nullptr && viewer_->wasStopped();
} }
void PCViewer::ConvertMatToPointCloud( void PCViewer::ConvertMatToPointCloud(

View File

@ -11,8 +11,8 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#ifndef MYNTEYE_TUTORIALS_PCVIEWER_H_ // NOLINT #ifndef MYNTEYE_TUTORIALS_PC_VIEWER_H_ // NOLINT
#define MYNTEYE_TUTORIALS_PCVIEWER_H_ #define MYNTEYE_TUTORIALS_PC_VIEWER_H_
#pragma once #pragma once
#include <opencv2/core/core.hpp> #include <opencv2/core/core.hpp>
@ -26,11 +26,11 @@ class PCViewer {
PCViewer(); PCViewer();
~PCViewer(); ~PCViewer();
void Draw(const cv::Mat &xyz); void Update(const cv::Mat &xyz);
void Draw(pcl::PointCloud<pcl::PointXYZ>::ConstPtr pc); void Update(pcl::PointCloud<pcl::PointXYZ>::ConstPtr pc);
bool WasDrew() const; bool WasVisual() const;
bool WasStopped() const; bool WasStopped() const;
private: private:
@ -40,4 +40,4 @@ class PCViewer {
std::shared_ptr<pcl::visualization::PCLVisualizer> viewer_; std::shared_ptr<pcl::visualization::PCLVisualizer> viewer_;
}; };
#endif // MYNTEYE_TUTORIALS_PCVIEWER_H_ NOLINT #endif // MYNTEYE_TUTORIALS_PC_VIEWER_H_ NOLINT