-
Notifications
You must be signed in to change notification settings - Fork 2
Transform
Harumo Sasatake edited this page Oct 20, 2018
·
4 revisions
平行移動と回転は同時に下記の関数で行います. どちらも入力点群と出力点群と同次回転行列を引数に与えます. この同次変換行列が並行移動と回転を表しています. 下記では,同次回転行列の2種類の作成方法を紹介します.
pcl::transformPointCloud(src_cloud, dist_cloud, eigen_transform_matrix)
pcl::transformPointCloud(*src_cloud_ptr, *dist_cloud_ptr, eigen_transform_matrix)
| クラス名 | 変数名 | 説明 |
|---|---|---|
| pcl::PointCloudpcl::PointXYZ | src_cloud | 入力点群 |
| pcl::PointCloudpcl::PointXYZ::Ptr | src_cloud_ptr | 入力点群 |
| pcl::PointCloudpcl::PointXYZ | dist_cloud | 出力点群 |
| pcl::PointCloudpcl::PointXYZ::Ptr | dist_cloud_ptr | 出力点群 |
| Eigen::Matirx4f | eigen_transform_matrix | 同次回転行列 |
同次変換行列がわからない人は勉強してからのほうがいいかもしれない... 参考
|1 0 0 X|
|0 1 0 Y|
|0 0 1 Z|
|0 0 0 1|
みたいなやつです.上のは平行移動だけの同次行列ですね. では,回転行列を作っていきましょう.加点行列は3次元の場合,回転を表す3x3の行列と3要素のベクトルからなります.
//単位行列で回転行列を埋めます.
Eigen::Matrix4f transform = Eigen::Matrix4f::Edentity();
//3x3の回転行列の部分を埋めます.今回は90度でいきます.
double theta = M_PI/2
//transform(raw, column)
transform(0,0) = std::cos(theta);
transform(0,1) = -std::sin(theta);
transform(1.0) = sin(theta);
transform(1,1) = cos(theta);
//平行移動の部分を埋めます.今回は2.5mだけx軸に沿って移動させます.
transform(0,3) = 2.5;
//できた回転行列を出力してみます
std::cout << transform;
//移動しておわりです
pcl::transformPointCloud(src_cloud, dist_cloud, transform)
ちなみに,平行移動だけだったら,transform(0,3) = 2.5だけで,回転の方は設定しなくても大丈夫です.
Eigen::Affine3f = transform = Eigen::Affine3f::Identity();
//平行移動を設定
//2.5mでいきます
transform.translation() << 2.5, 0, 0; //x,y,zの順
//回転を設定
//z軸まわりに90度回します
double theta = M_PI/2;
transform.rotate(Eigen::AngleAxisf(theta, Eigen::Vector3f::UnitZ()));
//表示
std::cout << transform.matrix();
//実行
pcl::transformPointCloud(src_cloud, dist_cloud, transform);
こちらも同様に,平行移動だけだったら,transform.translation() << 2.5, 0, 0 だけで,回転の方は設定しなくても大丈夫です.