PCLでPointCloudの回転
PCLを使っていて、PointCloudの回転にちょっと躓いたので、その解決方法をメモ.
普通に各ポイントを回転させるのでは無理?
//**x軸を中心にtheta回転させるコード** for( auto & it : cloud ) { auto const y = it.y; auto const z = it.z; it.y = cos_theta * y - sin_theta * z; it.z = sin_theta * y + cos_theta * z; }
みたいに回転行列を適用するのではダメだった. 何か出力が変になる.
でもいける、凡ミスしててアレだったのだが、記事を書いた後15分後にミスに気づく. 以下、PCLライブラリが用意してくれたスマートそうに見えるコードをご覧ください(しろめ).
PCL付属のTransform関数を使う
//**x軸を中心にtheta回転させるコード** Eigen::Matrix4f rotation_matrix; //行列を作成する 4x4 rotation_matrix << \ 1, 0, 0, 0, \ 0, cos_theta, - sin_theta, 0, \ 0, sin_theta, cos_theta, 0, \ 0, 0, 0, 1; //回転 pcl::transformPointCloud( in_point_cloud, out_point_cloud, rotation_matrix );
OpenGLとDirectXで回転行列の形が違うとかいう話を聞きましたので、そこら辺も何か今後考えるかどうか悩み中?
別件だけれど、SpinOnce()はメインスレッドでやらないとうまく動かないっぽい?う〜ん、よくわからぬ〜(´・ω・`)
こことか参考にしましたよ http://imagingsolution.blog107.fc2.com/blog-entry-105.html