PCLVisualizerã¯ç¹ç¾¤ã表示ããããã®GUIã¯ã©ã¹ã§ããã¦ã¹ãã©ãã°ã«ãã£ã¦ä»»æã®è¦ç¹ããç¹ç¾¤ãè¦ããã¨ãã§ãã¾ãã
ãã¦ãããã§ä»ã®è¦ç¹ãä¸ç座æ¨ç³»ä¸ã®ã©ã®ä½ç½®ãããªã®ããã¾ãGUIä¸ãã¯ãªãã¯ããã¨ãããã®ãç»åå¹³é¢ä¸ã®ãç¹ã¯ä¸ç座æ¨ç³»ä¸ã®ã©ããªã®ããåå¾ããæ¹æ³ã調ã¹ã¾ããã(ã¯ãªãã¯ããç¹ã®ã¨ããã¼ã©ç·ãæ±ãããã£ãã®ã§)
(追è¨ï¼åã«ç¹ç¾¤ã®ä¸ã®ç¹ãé¸æãããã ããªããPCLVisualizerã®registerPointPickingCallback()ã¡ã³ãé¢æ°ãå©ç¨ãã¦ãPointPickingEventãå¼æ°ã«æã¤é¢æ°ãèªåã§æ¸ãã¦ãããã°ãShift Key + ãã¦ã¹ã¯ãªãã¯ã§é¸æããç¹ã®IDã座æ¨ãåå¾ã§ãã¾ãã
ãã®è¨äºã§ãããã¨ãã¦ããã®ã¯ãã¯ãªãã¯ããGUIç»é¢ã®ï¼æ¬¡å 座æ¨ãä¸ç座æ¨ç³»ã®ä¸æ¬¡å 座æ¨ã¸å¤æãããã¨ã§ããï¼
PCLVisualizerã®èª¬æã¯このチュートリアルãåèã«ãã¦ãã ããã
以ä¸ã®èª¬æã¯ä¸è¨ãã¥ã¼ããªã¢ã«ã®å
容ãè¸ã¾ãã¦ï¼ã¤ã¾ããããããã®ä½¿ãæ¹ã¯ããã£ã¦ãããã®ã¨ãã¦ï¼æ¸ãã¾ãã
ã«ã¡ã©ãã©ã¡ã¼ã¿ã®åå¾
ç¾å¨ã®è¦ç¹ã®ã«ã¡ã©ãã©ã¡ã¼ã¿ã§ããã以ä¸ã®é¢æ°ã§ç°¡åã«åå¾ã§ãã¾ãã
boost::shared_ptr<:visualization::pclvisualizer> viewer(new pcl::visualization::PCLVisualizer("PCL Viewer")); /************* ï¼çç¥ï¼ PointCloudã®ã»ããããã¦ã¹ã³ã¼ã«ããã¯é¢æ°æå®ãªã© 詳ããã¯PCLã®ãã¥ã¼ããªã¢ã«åç § **************/ std::vector<:visualization::camera> Cameras; viewer->getCameras(Cameras);
ãã®Cameraã¯ã©ã¹ãç¨ãã¦View Matrix (ä¸ç座æ¨ç³»ãã«ã¡ã©åº§æ¨ç³»ã¸å¤æãã4x4è¡å)ã¨Projection Matrix (ã«ã¡ã©åº§æ¨ç³»ãGUIã®äºæ¬¡å
座æ¨ä¸ã¸æå½±ãã4x4è¡å)ãå¾ããã¨ãã§ãã¾ãã
Eigen::Matrix4d prj_matrix, view_matrix; Cameras[0].computeProjectionMatrix(prj_matrix); // Projection Matrixåå¾ Cameras[0].computeViewMatrix(view_matrix); // View Matrixåå¾
ãã®View Matrixããã®ã¾ã¾ç¾å¨ã®è¦ç¹ã®ä½ç½®/姿å¢ã表ãã¾ãã
ãªãã以ä¸ã®é¢æ°ã§ããç´æ¥çã«ã«ã¡ã©ã®ä½ç½®/姿å¢ã«ã¤ãã¦ã®ãã©ã¡ã¼ã¿ãå¾ããã¨ãã§ãã¾ããï¼View MatrixãProjection Matrixèªä½ãã以ä¸ã®ãã©ã¡ã¼ã¿ãç¨ãã¦è¨ç®ããã¦ããï¼
int win_w = Cameras[0].window_size[0]; // GUIç»é¢ã®å¹ int win_h = Cameras[0].window_size[1]; // GUIç»é¢ã®é«ã Eigen::Vector3d camera_pos; //ä¸ç座æ¨ç³»ã«ãããä»®æ³ã«ã¡ã©åº§æ¨ camera_pos << Cameras[0].pos[0],Cameras[0].pos[1], Cameras[0].pos[2]; Eigen::Vector3d camera_focal; //ä»®æ³ã«ã¡ã©ã®è¦ç·æ¹åãã¯ãã« camera_focal << Cameras[0].focal[0],Cameras[0].focal[1], Cameras[0].focal[2]; Eigen:: Vector3d camera_up; //ä»®æ³ã«ã¡ã©ã®ä¸æ¹åï¼ã«ã¡ã©åº§æ¨ç³»ã®Yãã¯ãã«ï¼ camera_up << Cameras[0].view[0],Cameras[0].view[1], Cameras[0].view[2]; double near = Cameras[0].clip[0]; //奥è¡æ¹åã®è¡¨ç¤ºç¯å²ï¼æåï¼ double far = Cameras[0].clip[1]; //奥è¡æ¹åã®è¡¨ç¤ºç¯å²ï¼å¥¥ï¼ double fovy = Cameras[0].fovy //ç»é¢ã®é«ããç¦ç¹ã¨ãªãè§åº¦ï¼radianï¼
ãªãCameraã¯ã©ã¹ã«ã¯window_posã¨ããã¦ã£ã³ãã¦ä½ç½®ã表ãã¡ã³ãå¤æ°ãããã®ã§ãããããã¯å¸¸ã«(0,0)ã¨ãªã£ã¦ãããã©ãã使ããã¦ããªãããã§ãã
ã¯ãªãã¯ç¹ã®ä¸æ¬¡å 座æ¨ç®åº
ã¯ãªãã¯ããç¹ã®GUIä¸ã®ï¼æ¬¡å 座æ¨ã¯ããã¦ã¹ã¤ãã³ããç¨ãã¦ä»¥ä¸ã®é¢æ°ã§åå¾ã§ãã¾ããï¼ãã¦ã¹ã¤ãã³ãã®åå¾æ¹æ³ã¯ãã¥ã¼ããªã¢ã«åç §ï¼
/* pcl::visualization::MouseEvent mouse_event */ click_x = mouse_event.getX(); click_y = mouse_event.getY();
ãã¦ãé常ãªãããã§Projection Matrixãå©ç¨ããã°ã¯ãªãã¯ç¹ã®ã«ã¡ã©åº§æ¨ç³»ã«ãããä¸æ¬¡å
座æ¨ãæ±ã¾ãããã§ãããå®ã¯ãã®Projection Matrixã¯ç¸¦æ¨ªã¨ãã«[-1,+1]ã«æ£è¦åããã座æ¨ã«æå½±ãããããã«ãªã£ã¦ãã¾ãã
ãããã£ã¦ãã¦ã¹ã¤ãã³ãã§åå¾ãã座æ¨ãæ£è¦åããä¸ã§ãProjection Matrixã®éè¡åãããã¦ã«ã¡ã©åº§æ¨ç³»ã«ããããã¦ã¹ã¯ãªãã¯ç¹ã®åº§æ¨ãæ±ãã¾ããã¾ããView Matrixã®éè¡åãããã¦ä¸ç座æ¨ç³»ã«ãããã¯ãªãã¯ç¹ã®ä¸æ¬¡å
座æ¨ãæ±ãã¾ãã
// 座æ¨ã®æ£è¦å Eigen::Vector4d norm_click_pt; norm_click_pt << 2.0 * click_x / win_w - 1.0, 2.0 * click_y / win_h - 1.0, 1.0, 1.0; // ã«ã¡ã©åº§æ¨ç³»ã«ãããã¯ãªãã¯ç¹ã®ç®åº Eigen::Vector4d click_pt_camera = prj_matrix.inverse() * norm_click_pt; click_pt_camera(3) = 1.0; // ä¸ç座æ¨ç³»ã«ãããã¯ãªãã¯ç¹ã®ç®åº click_pt_world = view_matrix.inverse() * click_pt_camera;
ãã ããProjection Matrixããã¯ç´æ¥ç¦ç¹è·é¢ã¯æ±ã¾ããªãã®ã§ãããã§ã¯ç¦ç¹è·é¢ï¼ã«ã¡ã©ã®ç¦ç¹ããç»åå¹³é¢ã¾ã§ã®è·é¢ï¼ã1ã¨ãã¦è¨ç®ãã¦ãã¾ãã