From 5c8762f1f209e2781184a7816bbd3b6af78c0188 Mon Sep 17 00:00:00 2001 From: 李良庭 <liliangting@shlanbao.cn> Date: 星期二, 22 四月 2025 15:33:45 +0800 Subject: [PATCH] no message --- cloud_viewer.cpp | 81 ++++++++++++++++------------------------ 1 files changed, 32 insertions(+), 49 deletions(-) diff --git a/cloud_viewer.cpp b/cloud_viewer.cpp index fd33030..6303654 100644 --- a/cloud_viewer.cpp +++ b/cloud_viewer.cpp @@ -1,67 +1,50 @@ -锘�// cloud_viewer.cpp : 姝ゆ枃浠跺寘鍚� "main" 鍑芥暟銆傜▼搴忔墽琛屽皢鍦ㄦ澶勫紑濮嬪苟缁撴潫銆� -// -#define PCL_SILENCE_MALLOC_WARNING 1 +锘�#define PCL_SILENCE_MALLOC_WARNING 1 #include <pcl/visualization/cloud_viewer.h> -#include <iostream> -//#include <pcl/io/io.h> +#include <pcl/point_types.h> #include <pcl/io/pcd_io.h> +#include <atomic> +#include <thread> -int user_data; +std::atomic<int> user_data(0); -void viewerOneOff(pcl::visualization::PCLVisualizer& viewer) -{ - viewer.setBackgroundColor(0, 0, 0); - std::cout << "i only run once" << std::endl; - +void viewerOneOff(pcl::visualization::PCLVisualizer& viewer) { + viewer.setBackgroundColor(0.1, 0.1, 0.1); // 娣辩伆鑳屾櫙鏇存槗瑙傚療 + viewer.addCoordinateSystem(1.0); // 娣诲姞鍧愭爣绯� + viewer.initCameraParameters(); // 鍒濆鍖栫浉鏈哄弬鏁� + std::cout << "Initial setup complete." << std::endl; } -void viewerPsycho(pcl::visualization::PCLVisualizer& viewer) -{ +void viewerPsycho(pcl::visualization::PCLVisualizer& viewer) { static unsigned count = 0; - std::stringstream ss; - ss << "Once per viewer loop: " << count++; - viewer.removeShape("text", 0); - viewer.addText(ss.str(), 200, 300, "text", 0); - - //FIXME: possible race condition here: - user_data++; + viewer.removeShape("text"); + viewer.addText("Frame: " + std::to_string(count++), 20, 30, 20, 1, 1, 1, "text"); + user_data.fetch_add(1, std::memory_order_relaxed); } -int main() -{ +int main() { + // 鍔犺浇鐐逛簯锛堝甫閿欒澶勭悊锛� pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGBA>); - pcl::io::loadPCDFile("sampledata.pcd", *cloud); + if (pcl::io::loadPCDFile<pcl::PointXYZRGBA>("sampledata.pcd", *cloud) == -1) { + std::cerr << "Error: Failed to load PCD file!" << std::endl; + return -1; + } - pcl::visualization::CloudViewer viewer("Cloud Viewer"); + // 鍒涘缓鍙鍖栧櫒 + pcl::visualization::CloudViewer viewer("Enhanced Cloud Viewer"); - //blocks until the cloud is actually rendered + // 鏄剧ず鐐逛簯 viewer.showCloud(cloud); - //use the following functions to get access to the underlying more advanced/powerful - //PCLVisualizer - - //This will only get called once + // 璁剧疆鍥炶皟鍑芥暟 viewer.runOnVisualizationThreadOnce(viewerOneOff); - - //This will get called once per visualization iteration viewer.runOnVisualizationThread(viewerPsycho); - while (!viewer.wasStopped()) - { - //you can also do cool processing here - //FIXME: Note that this is running in a separate thread from viewerPsycho - //and you should guard against race conditions yourself... - user_data++; + + // 涓诲惊鐜� + while (!viewer.wasStopped()) { + // 绀轰緥澶勭悊閫昏緫锛堢嚎绋嬪畨鍏級 + user_data.fetch_add(1, std::memory_order_relaxed); + std::this_thread::sleep_for(std::chrono::milliseconds(50)); } + return 0; -} - -// 杩愯绋嬪簭: Ctrl + F5 鎴栬皟璇� >鈥滃紑濮嬫墽琛�(涓嶈皟璇�)鈥濊彍鍗� -// 璋冭瘯绋嬪簭: F5 鎴栬皟璇� >鈥滃紑濮嬭皟璇曗�濊彍鍗� - -// 鍏ラ棬浣跨敤鎶�宸�: -// 1. 浣跨敤瑙e喅鏂规璧勬簮绠$悊鍣ㄧ獥鍙f坊鍔�/绠$悊鏂囦欢 -// 2. 浣跨敤鍥㈤槦璧勬簮绠$悊鍣ㄧ獥鍙h繛鎺ュ埌婧愪唬鐮佺鐞� -// 3. 浣跨敤杈撳嚭绐楀彛鏌ョ湅鐢熸垚杈撳嚭鍜屽叾浠栨秷鎭� -// 4. 浣跨敤閿欒鍒楄〃绐楀彛鏌ョ湅閿欒 -// 5. 杞埌鈥滈」鐩��>鈥滄坊鍔犳柊椤光�濅互鍒涘缓鏂扮殑浠g爜鏂囦欢锛屾垨杞埌鈥滈」鐩��>鈥滄坊鍔犵幇鏈夐」鈥濅互灏嗙幇鏈変唬鐮佹枃浠舵坊鍔犲埌椤圭洰 -// 6. 灏嗘潵锛岃嫢瑕佸啀娆℃墦寮�姝ら」鐩紝璇疯浆鍒扳�滄枃浠垛��>鈥滄墦寮�鈥�>鈥滈」鐩�濆苟閫夋嫨 .sln 鏂囦欢 +} \ No newline at end of file -- Gitblit v1.9.3