本文整理汇总了C++中eigen::Matrix3f::col方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix3f::col方法的具体用法?C++ Matrix3f::col怎么用?C++ Matrix3f::col使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eigen::Matrix3f
的用法示例。
在下文中一共展示了Matrix3f::col方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: es
visualization_msgs::Marker SatDetector3DMonitor::getMarker(int marker_id, Eigen::Vector4f centroid, Eigen::Matrix3f covariance_matrix){
//------- Compute Principal Componets for Marker publishing
//Get the principal components and the quaternion
Eigen::Matrix3f evecs;
Eigen::Vector3f evals;
//pcl::eigen33 (covariance_matrix, evecs, evals);
Eigen::EigenSolver<Eigen::Matrix3f> es(covariance_matrix);
evecs = es.eigenvectors().real();
evals = es.eigenvalues().real();
Eigen::Matrix3f rotation;
rotation.row (0) = evecs.col (0);
rotation.row (1) = evecs.col (1);
rotation.row (2) = rotation.row (0).cross (rotation.row (1));
rotation.transposeInPlace ();
Eigen::Quaternion<float> qt (rotation);
qt.normalize ();
//Publish Marker for cluster
visualization_msgs::Marker marker;
marker.header.frame_id = base_frame_;
marker.header.stamp = ros::Time().now();
marker.ns = "Perception";
marker.action = visualization_msgs::Marker::ADD;
marker.id = marker_id;
marker.lifetime = ros::Duration(1);
//centroid position
marker.type = visualization_msgs::Marker::SPHERE;
marker.pose.position.x = centroid[0];
marker.pose.position.y = centroid[1];
marker.pose.position.z = centroid[2];
marker.pose.orientation.x = qt.x();
marker.pose.orientation.y = qt.y();
marker.pose.orientation.z = qt.z();
marker.pose.orientation.w = qt.w();
//std::cout << "e1: " << evals(0) << " e2: " << evals(1) << " e3: " << evals(2) << std::endl;
marker.scale.x = sqrt(evals(0)) * 4;
marker.scale.y = sqrt(evals(1)) * 4;
marker.scale.z = sqrt(evals(2)) * 4;
//give it some color!
marker.color.a = 0.75;
satToRGB(marker.color.r, marker.color.g, marker.color.b);
//std::cout << "marker being published" << std::endl;
return marker;
}
示例2: fuzzyAffines
void fuzzyAffines()
{
std::vector<Eigen::Matrix4f> trans;
trans.reserve(count/10);
for( size_t i=0; i<count/10; i++ )
{
Eigen::Vector3f x = Eigen::Vector3f::Random();
Eigen::Vector3f y = Eigen::Vector3f::Random();
x.normalize();
y.normalize();
Eigen::Vector3f z = x.cross(y);
z.normalize();
y = z.cross(x);
y.normalize();
Eigen::Affine3f t = Eigen::Affine3f::Identity();
Eigen::Matrix3f r = Eigen::Matrix3f::Identity();
r.col(0) = x;
r.col(1) = y;
r.col(2) = z;
t.rotate(r);
t.translate( 0.5f * Eigen::Vector3f::Random() + Eigen::Vector3f(0.5,0.5,0.5) );
trans.push_back( t.matrix() );
}
s_plot.setColor( Eigen::Vector4f(1,0,0,1) );
s_plot.setLineWidth( 3.0 );
s_plot( trans, nox::plot<float>::Pos | nox::plot<float>::CS );
}
示例3: cloud_temp
void SQ_fitter<PointT>::getBoundingBox(const PointCloudPtr &_cloud,
double _dim[3],
double _trans[3],
double _rot[3] ) {
// 1. Compute the bounding box center
Eigen::Vector4d centroid;
pcl::compute3DCentroid( *_cloud, centroid );
_trans[0] = centroid(0);
_trans[1] = centroid(1);
_trans[2] = centroid(2);
// 2. Compute main axis orientations
pcl::PCA<PointT> pca;
pca.setInputCloud( _cloud );
Eigen::Vector3f eigVal = pca.getEigenValues();
Eigen::Matrix3f eigVec = pca.getEigenVectors();
// Make sure 3 vectors are normal w.r.t. each other
Eigen::Vector3f temp;
eigVec.col(2) = eigVec.col(0); // Z
Eigen::Vector3f v3 = (eigVec.col(1)).cross( eigVec.col(2) );
eigVec.col(0) = v3;
Eigen::Vector3f rpy = eigVec.eulerAngles(2,1,0);
_rot[0] = (double)rpy(2);
_rot[1] = (double)rpy(1);
_rot[2] = (double)rpy(0);
// Transform _cloud
Eigen::Matrix4f transf = Eigen::Matrix4f::Identity();
transf.block(0,3,3,1) << (float)centroid(0), (float)centroid(1), (float)centroid(2);
transf.block(0,0,3,3) = eigVec;
Eigen::Matrix4f tinv; tinv = transf.inverse();
PointCloudPtr cloud_temp( new pcl::PointCloud<PointT>() );
pcl::transformPointCloud( *_cloud, *cloud_temp, tinv );
// Get maximum and minimum
PointT minPt; PointT maxPt;
pcl::getMinMax3D( *cloud_temp, minPt, maxPt );
_dim[0] = ( maxPt.x - minPt.x ) / 2.0;
_dim[1] = ( maxPt.y - minPt.y ) / 2.0;
_dim[2] = ( maxPt.z - minPt.z ) / 2.0;
}
示例4: qfinal
void
drawBoundingBox(PointCloudT::Ptr cloud,
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer,
int z)
{
//Eigen::Vector4f centroid;
pcl::compute3DCentroid(*cloud, centroid);
//Eigen::Matrix3f covariance;
computeCovarianceMatrixNormalized(*cloud, centroid, covariance);
//Eigen::SelfAdjointEigenSolver<Eigen::Matrix3f> eigen_solver(covariance,
//Eigen::ComputeEigenvectors);
eigen_solver.compute(covariance,Eigen::ComputeEigenvectors);
// eigen_solver = boost::shared_ptr<Eigen::SelfAdjointEigenSolver>
// (covariance,Eigen::ComputeEigenvectors);
eigDx = eigen_solver.eigenvectors();
eigDx.col(2) = eigDx.col(0).cross(eigDx.col(1));
//Eigen::Matrix4f p2w(Eigen::Matrix4f::Identity());
p2w.block<3,3>(0,0) = eigDx.transpose();
p2w.block<3,1>(0,3) = -1.f * (p2w.block<3,3>(0,0) * centroid.head<3>());
//pcl::PointCloud<PointT> cPoints;
pcl::transformPointCloud(*cloud, cPoints, p2w);
//PointT min_pt, max_pt;
pcl::getMinMax3D(cPoints, min_pt, max_pt);
const Eigen::Vector3f mean_diag = 0.5f*(max_pt.getVector3fMap() + min_pt.getVector3fMap());
const Eigen::Quaternionf qfinal(eigDx);
const Eigen::Vector3f tfinal = eigDx*mean_diag + centroid.head<3>();
//viewer->addPointCloud(cloud);
viewer->addCube(tfinal, qfinal, max_pt.x - min_pt.x, max_pt.y - min_pt.y, max_pt.z - min_pt.z,boost::lexical_cast<std::string>((z+1)*200));
}
示例5: isOrthographic
bool Utils::
factorViewMatrix(const Eigen::Projective3f& iMatrix,
Eigen::Matrix3f& oCalib, Eigen::Isometry3f& oPose,
bool& oIsOrthographic) {
oIsOrthographic = isOrthographic(iMatrix.matrix());
// get appropriate rows
std::vector<int> rows = {0,1,2};
if (!oIsOrthographic) rows[2] = 3;
// get A matrix (upper left 3x3) and t vector
Eigen::Matrix3f A;
Eigen::Vector3f t;
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
A(i,j) = iMatrix(rows[i],j);
}
t[i] = iMatrix(rows[i],3);
}
// determine translation vector
oPose.setIdentity();
oPose.translation() = -(A.inverse()*t);
// determine calibration matrix
Eigen::Matrix3f AAtrans = A*A.transpose();
AAtrans.col(0).swap(AAtrans.col(2));
AAtrans.row(0).swap(AAtrans.row(2));
Eigen::LLT<Eigen::Matrix3f, Eigen::Upper> llt(AAtrans);
oCalib = llt.matrixU();
oCalib.col(0).swap(oCalib.col(2));
oCalib.row(0).swap(oCalib.row(2));
oCalib.transposeInPlace();
// compute rotation matrix
oPose.linear() = (oCalib.inverse()*A).transpose();
return true;
}
示例6: ComputeDarbouxVector
bool PositionBasedElasticRod::ComputeDarbouxVector(const Eigen::Matrix3f& dA, const Eigen::Matrix3f& dB, const float mid_edge_length, Eigen::Vector3f& darboux_vector)
{
float factor = 1.0f + dA.col(0).dot(dB.col(0)) + dA.col(1).dot(dB.col(1)) + dA.col(2).dot(dB.col(2));
factor = 2.0f / (mid_edge_length * factor);
for (int c = 0; c < 3; ++c)
{
const int i = permutation[c][0];
const int j = permutation[c][1];
const int k = permutation[c][2];
darboux_vector[i] = dA.col(j).dot(dB.col(k)) - dA.col(k).dot(dB.col(j));
}
darboux_vector *= factor;
return true;
}
示例7: find_toy_block
bool ObjectFinder::find_toy_block(float surface_height, geometry_msgs::PoseStamped &object_pose) {
Eigen::Vector3f plane_normal;
double plane_dist;
//bool valid_plane;
Eigen::Vector3f major_axis;
Eigen::Vector3f centroid;
bool found_object = true; //should verify this
double block_height = 0.035; //this height is specific to the TOY_BLOCK model
//if insufficient points in plane, find_plane_fit returns "false"
//should do more sanity testing on found_object status
//hard-coded search bounds based on a block of width 0.035
found_object = pclUtils_.find_plane_fit(0.4, 1, -0.5, 0.5, surface_height + 0.025, surface_height + 0.045, 0.001,
plane_normal, plane_dist, major_axis, centroid);
//should have put a return value on find_plane_fit;
//
if (plane_normal(2) < 0) plane_normal(2) *= -1.0; //in world frame, normal must point UP
Eigen::Matrix3f R;
Eigen::Vector3f y_vec;
R.col(0) = major_axis;
R.col(2) = plane_normal;
R.col(1) = plane_normal.cross(major_axis);
Eigen::Quaternionf quat(R);
object_pose.header.frame_id = "base_link";
object_pose.pose.position.x = centroid(0);
object_pose.pose.position.y = centroid(1);
//the TOY_BLOCK model has its origin in the middle of the block, not the top surface
//so lower the block model origin by half the block height from upper surface
object_pose.pose.position.z = centroid(2)-0.5*block_height;
//create R from normal and major axis, then convert R to quaternion
object_pose.pose.orientation.x = quat.x();
object_pose.pose.orientation.y = quat.y();
object_pose.pose.orientation.z = quat.z();
object_pose.pose.orientation.w = quat.w();
return found_object;
}
示例8: ComputeMaterialFrame
// ----------------------------------------------------------------------------------------------
bool PositionBasedElasticRod::ComputeMaterialFrame(
const Eigen::Vector3f& pA,
const Eigen::Vector3f& pB,
const Eigen::Vector3f& pG,
Eigen::Matrix3f& frame)
{
frame.col(2) = (pB - pA);
frame.col(2).normalize();
frame.col(1) = (frame.col(2).cross(pG - pA));
frame.col(1).normalize();
frame.col(0) = frame.col(1).cross(frame.col(2));
// frame.col(0).normalize();
return true;
}
示例9: main
int main(int argc, char** argv) {
ros::init(argc, argv, "eigen_test");
ros::NodeHandle nh_jntPub; // node handle for joint command publisher
// ros::Publisher pub_joint_commands; //
// pub_joint_commands = nh_jntPub.advertise<atlas_msgs::AtlasCommand>("/atlas/atlas_command", 1, true);
ROS_INFO("test eigen program");
Eigen::Matrix3f A;
Eigen::Vector3f b;
A << 1,2,3, 4,5,6, 7,8,10;
A(1,2)=0; // how to access one element of matrix; start from 0; no warning out of range...
b << 3,3,4;
std::cout <<"b = "<<b <<std::endl;
// column operaton: replace first column of A with vector b:
A.col(0)= b; // could copy columns of matrices w/ A.col(0) = B.col(0);
std::cout <<"A = "<<A <<std::endl;
Eigen::MatrixXd mat1 = Eigen::MatrixXd::Zero(6, 6); //6x6 matrix full of zeros
Eigen::MatrixXd mat2 = Eigen::MatrixXd::Identity(6, 6); //6x6 identity matrix
std::cout<<mat1<<std::endl;
std::cout<<mat2<<std::endl;
Eigen::Vector3f xtest = A.colPivHouseholderQr().solve(b);
std::cout<<"soln xtest = "<<xtest<<std::endl;
Eigen::Vector3f x = A.partialPivLu().solve(b); //dec.solve(b); //A.colPivHouseholderQr().solve(b);
std::cout<<"soln x = "<<x<<std::endl;
Eigen::Vector3f btest = A*x;
std::cout<<"test soln: A*x = " <<btest<<std::endl;
//extend to 6x6 test: v = M*z, find z using 2 methods
// use double-precision matrices/vectors
Eigen::MatrixXd M = Eigen::MatrixXd::Random(6,6);
std::cout<<"test 6x6: M = "<<M<<std::endl;
Eigen::VectorXd v(6);
v << 1,2,3,4,5,6;
std::cout<<"v = "<<v<<std::endl;
Eigen::VectorXd z(6);
Eigen::VectorXd ztest(6);
ztest = M.colPivHouseholderQr().solve(v);
std::cout<<"soln ztest = "<<ztest<<std::endl;
z = M.partialPivLu().solve(v);
std::cout<<"soln 6x6: z = "<<z<<std::endl;
Eigen::VectorXd vtest(6);
vtest = M*z;
std::cout<<"test soln: M*z = "<<vtest<<std::endl;
// .norm() operator...
double relative_error = (M*z - v).norm() / v.norm(); // norm() is L2 norm
std::cout << "The relative error is:\n" << relative_error << std::endl;
std::cout<<"dot prod, v, z: "<< v.dot(z)<<std::endl;
std::cout<<"cross prod, b-cross-x: " << b.cross(x)<<std::endl;
return 0;
}
示例10: main
//.........这里部分代码省略.........
//Erzeugen einer Ebene aus Cluster_cloud
pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients ());
pcl::PointIndices::Ptr inliers (new pcl::PointIndices ());
pcl::SACSegmentation<pcl::PointXYZ> seg;
seg.setOptimizeCoefficients(true);
seg.setModelType(pcl::SACMODEL_PLANE);
seg.setMethodType(pcl::SAC_RANSAC);
seg.setMaxIterations(1000);
seg.setDistanceThreshold(0.1);
seg.setInputCloud(cluster_cloud);
seg.segment(*inliers, *coefficients);
// Wenn Ebene vertikal: Abspeichern in Cluster_i.pcd
if(coefficients->values[2]<.9 && coefficients->values[2]>(-.9))//ax+by+cz+d=0 (wenn c=0 => Ebene parallel zur z-Achse)
{
pcl::PointCloud<pcl::PointXYZ>::Ptr planes_projected (new pcl::PointCloud<pcl::PointXYZ>);
//Inliers auf Ebene projizieren:
pcl::PCA<pcl::PointXYZ> pca2;
pcl::ProjectInliers<pcl::PointXYZ> proj2;
proj2.setModelType(pcl::SACMODEL_PLANE);
proj2.setIndices(inliers);
proj2.setInputCloud(cluster_cloud);
proj2.setModelCoefficients(coefficients);
proj2.filter(*planes_projected);
// Punkte in Eigenraum transformieren, um bounding box zu berechnen (Quelle: pcl-users Forum (http://www.pcl-users.org/Finding-oriented-bounding-box-of-a-cloud-td4024616.html)
// compute principal direction
Eigen::Vector4f centroid;
pcl::compute3DCentroid(*planes_projected, centroid);
Eigen::Matrix3f covariance;
computeCovarianceMatrixNormalized(*planes_projected, centroid, covariance);
Eigen::SelfAdjointEigenSolver<Eigen::Matrix3f> eigen_solver(covariance, Eigen::ComputeEigenvectors);
Eigen::Matrix3f eigDx = eigen_solver.eigenvectors();
eigDx.col(2) = eigDx.col(0).cross(eigDx.col(1));
// move the points to the that reference frame
Eigen::Matrix4f p2w(Eigen::Matrix4f::Identity());
p2w.block<3,3>(0,0) = eigDx.transpose();
p2w.block<3,1>(0,3) = -1.f * (p2w.block<3,3>(0,0) * centroid.head<3>());
pcl::PointCloud<pcl::PointXYZ> cPoints;
pcl::transformPointCloud(*planes_projected, cPoints, p2w);
pcl::PointXYZ min_pt, max_pt;
pcl::getMinMax3D(cPoints, min_pt, max_pt);
const Eigen::Vector3f mean_diag = 0.5f*(max_pt.getVector3fMap() + min_pt.getVector3fMap());
// final transform
const Eigen::Quaternionf qfinal(eigDx);
const Eigen::Vector3f tfinal = eigDx*mean_diag + centroid.head<3>();
// Punktwolke und bounding box im viewer anzeigen
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer (new pcl::visualization::PCLVisualizer);
viewer->addCoordinateSystem ();
viewer->addPointCloud(planes_projected);// Danach auskommentieren
viewer->addCube(tfinal, qfinal, max_pt.x - min_pt.x, max_pt.y - min_pt.y, max_pt.z - min_pt.z);
// Ausgabe der Eckpunkte (kann gelöscht werden)
std::cout << " min.x= " << min_pt.x << " max.x= " << max_pt.x << " min.y= " << min_pt.y << " max.y= " << max_pt.y << " min.z= " << min_pt.z << " max.z= " << max_pt.z<< std::endl;
std::cout << "Punkte: " << min_pt.x <<";" << min_pt.y << ";" << min_pt.z <<std::endl;
std::cout << min_pt.x <<";" << min_pt.y << ";" << max_pt.z <<std::endl;
std::cout << min_pt.x <<";" << max_pt.y << ";" << min_pt.z <<std::endl;
std::cout << min_pt.x <<";" << max_pt.y << ";" << max_pt.z <<std::endl;
std::cout << max_pt.x <<";" << min_pt.y << ";" << min_pt.z <<std::endl;
std::cout << max_pt.x <<";" << min_pt.y << ";" << max_pt.z <<std::endl;
std::cout << max_pt.x <<";" << max_pt.y << ";" << min_pt.z <<std::endl;
std::cout << max_pt.x <<";" << max_pt.y << ";" << max_pt.z <<std::endl;
示例11: process
int process(const tendrils& inputs, const tendrils& outputs,
boost::shared_ptr<const ::pcl::PointCloud<Point> >& input)
{
centers_->clear();
centers_->resize(static_cast<std::size_t>(clusters_->size()));
::pcl::ExtractIndices<Point> filter;
filter.setInputCloud(input);
Eigen::Vector3f firstAxis;
Eigen::Vector3f secondAxis;
Eigen::Matrix3f frame;
for(std::size_t i = 0; i < clusters_->size(); ++i)
{
if((*clusters_)[i].indices.size() == 0)
continue;
frame = (*frames_)[i];
firstAxis = frame.col(0);
secondAxis = frame.col(1);
boost::shared_ptr< ::pcl::PointCloud<Point> > cloud;
cloud = boost::make_shared< ::pcl::PointCloud<Point> > ();
// extract indices into a cloud
filter.setIndices( ::pcl::PointIndicesPtr(
new ::pcl::PointIndices ((*clusters_)[i])) );
filter.filter(*cloud);
Eigen::Vector3f point(cloud->points[0].x,
cloud->points[0].y, cloud->points[0].z);
Eigen::Vector3f minPoint(cloud->points[0].x,
cloud->points[0].y, cloud->points[0].z);
double firstMin = point.dot(firstAxis);
double firstMax = point.dot(firstAxis);
double secondMin = point.dot(secondAxis);
double secondMax = point.dot(secondAxis);
for(std::size_t p = 0; p < cloud->points.size(); ++p)
{
point = Eigen::Vector3f(cloud->points[p].x,
cloud->points[p].y, cloud->points[p].z);
if(point.dot(firstAxis) > firstMax)
{
firstMax = point.dot(firstAxis);
}
if(point.dot(firstAxis) < firstMin)
{
firstMin = point.dot(firstAxis);
minPoint.x() = point.x();
}
if(point.dot(secondAxis) > secondMax)
{
secondMax = point.dot(secondAxis);
}
if(point.dot(secondAxis) < secondMin)
{
secondMin = point.dot(secondAxis);
minPoint.y() = point.y();
}
}
Eigen::Vector3f Center = minPoint +
((firstMax-firstMin)/2)*firstAxis +
((secondMax-secondMin)/2)*secondAxis;
centers_->at(i) = Eigen::Vector4f(Center.x(),
Center.y(),
Center.z(),
0.0);
}
return ecto::OK;
}
示例12: computeCovarianceMatrix
void get3DMoments(vector<Point> feature_points, int feat_index, int index)
{
// for(int i=0; i<feature_points.size(); i++)
// ROS_INFO("%d --> %d,%d",i,feature_points[i].x,feature_points[i].y);
//ROS_INFO("Getting 3D Moments : %d --> %d,%d", feature_points.size(), width, height);
//Extract the indices for the points in the point cloud data
pcl::PointIndices point_indices;
for(int i=0; i<feature_points.size(); i++)
{
//ROS_INFO("Feature Index : %d, %d",feature_points[i].x, feature_points[i].y);
point_indices.indices.push_back(feature_points[i].y * width + feature_points[i].x);
}
//ROS_INFO("Computing 3D Centroid : %d",point_indices.indices.size());
Eigen::Vector4f centroid;
Eigen::Matrix3f covariance_matrix;
// Estimate the XYZ centroid
pcl::compute3DCentroid (pcl_in, point_indices, centroid);
#ifdef DEBUG
ROS_INFO("Centroid %d: %f, %f, %f, %f",index,centroid(0),centroid(1),centroid(2),centroid(3));
#endif
//ROS_INFO("Computing Covariance ");
//Compute the centroid and the covariance of the points
computeCovarianceMatrix(pcl_in, point_indices.indices, centroid, covariance_matrix);
//Print the 3D Moments
//ROS_INFO("Centroid : %f, %f, %f, %f",centroid(0),centroid(1),centroid(2),centroid(3));
#ifdef DEBUG
std::cout<<"Covariance : "<<std::endl<<covariance_matrix <<std::endl;
#endif
for(int i=0; i<3; i++)
{
feedback_.features[feat_index].moments[index].mean[i] = centroid(i);
for(int j=0; j<3; j++)
{
feedback_.features[feat_index].moments[index].covariance[i*3+j] = covariance_matrix(i,j);
}
}
//Get the principal components and the quaternion
Eigen::Matrix3f evecs;
Eigen::Vector3f evals;
pcl::eigen33 (covariance_matrix, evecs, evals);
Eigen::Matrix3f rotation;
rotation.row (0) = evecs.col (0);
rotation.row (1) = evecs.col (1);
//rotation.row (2) = evecs.col (2);
rotation.row (2) = rotation.row (0).cross (rotation.row (1));
//rotation.transposeInPlace ();
#ifdef DEBUG
std::cerr << "Rotation matrix: " << endl;
std::cerr << rotation << endl;
std::cout<<"Eigen vals : "<<evals<<std::endl;
#endif
rotation.transposeInPlace ();
Eigen::Quaternion<float> qt (rotation);
qt.normalize ();
//Publish Marker
visualization_msgs::Marker marker;
marker.header.frame_id = "/openni_rgb_optical_frame";
marker.header.stamp = ros::Time().now();
marker.ns = "Triangulation";
marker.id = index+1;
marker.action = visualization_msgs::Marker::ADD;
marker.lifetime = ros::Duration(5);
//centroid position
marker.type = visualization_msgs::Marker::SPHERE;
marker.pose.position.x = centroid(0);
marker.pose.position.y = centroid(1);
marker.pose.position.z = centroid(2);
marker.pose.orientation.x = qt.x();
marker.pose.orientation.y = qt.y();
marker.pose.orientation.z = qt.z();
marker.pose.orientation.w = qt.w();
marker.scale.x = sqrt(evals(0)) *2;
marker.scale.y = sqrt(evals(1)) *2;
marker.scale.z = sqrt(evals(2)) *2;
//red
marker.color.a = 0.5;
marker.color.r = rand()/((double)RAND_MAX + 1);
marker.color.g = rand()/((double)RAND_MAX + 1);
marker.color.b = rand()/((double)RAND_MAX + 1);
object_pose_marker_pub_.publish(marker);
}
示例13: ComputeDarbouxGradient
bool PositionBasedElasticRod::ComputeDarbouxGradient(
const Eigen::Vector3f& darboux_vector, const float length,
const Eigen::Matrix3f& da, const Eigen::Matrix3f& db,
//const Eigen::Matrix3f(*dajpi)[3], const Eigen::Matrix3f(*dbjpi)[3],
const Eigen::Matrix3f dajpi[3][3], const Eigen::Matrix3f dbjpi[3][3],
const Eigen::Vector3f& bendAndTwistKs,
Eigen::Matrix3f& omega_pa, Eigen::Matrix3f& omega_pb, Eigen::Matrix3f& omega_pc, Eigen::Matrix3f& omega_pd, Eigen::Matrix3f& omega_pe
)
{
//float x = 1.0f + da[0] * db[0] + da[1] * db[1] + da[2] * db[2];
float x = 1.0f + da.col(0).dot(db.col(0)) + da.col(1).dot(db.col(1)) + da.col(2).dot(db.col(2));
x = 2.0f / (length * x);
for (int c = 0; c < 3; ++c)
{
const int i = permutation[c][0];
const int j = permutation[c][1];
const int k = permutation[c][2];
// pa
{
Eigen::Vector3f term1(0,0,0);
Eigen::Vector3f term2(0,0,0);
Eigen::Vector3f tmp(0,0,0);
// first term
//dj::MulVecMatrix3x3<real>(db[k](), (real(*)[3]) &dajpi[j][0], term1());
//dj::MulVecMatrix3x3<real>(db[j](), (real(*)[3]) &dajpi[k][0], tmp());
//DOUBLE CHECK !!!
term1 = dajpi[j][0].transpose() * db.col(k);
tmp = dajpi[k][0].transpose() * db.col(j);
term1 = term1 - tmp;
// second term
for (int n = 0; n < 3; ++n)
{
//dj::MulVecMatrix3x3<real>(db[n](), (real(*)[3]) &dajpi[n][0], tmp());
//DOUBLE CHECK !!!
tmp = dajpi[n][0].transpose() * db.col(n);
term2 = term2 + tmp;
}
omega_pa.col(i) = (term1)-(0.5f * darboux_vector[i] * length) * (term2);
omega_pa.col(i) *= (x * bendAndTwistKs[i]);
}
// pb
{
Eigen::Vector3f term1(0, 0, 0);
Eigen::Vector3f term2(0, 0, 0);
Eigen::Vector3f tmp(0, 0, 0);
// first term
//dj::MulVecMatrix3x3<real>(db[k](), (real(*)[3]) &dajpi[j][1], term1());
//dj::MulVecMatrix3x3<real>(db[j](), (real(*)[3]) &dajpi[k][1], tmp());
term1 = dajpi[j][1].transpose() * db.col(k);
tmp = dajpi[k][1].transpose() * db.col(j);
term1 = term1 - tmp;
// third term
//dj::MulVecMatrix3x3<real>(da[k](), (real(*)[3]) &dbjpi[j][0], tmp());
tmp = dbjpi[j][0].transpose() * da.col(k);
term1 = term1 - tmp;
//dj::MulVecMatrix3x3<real>(da[j](), (real(*)[3]) &dbjpi[k][0], tmp());
tmp = dbjpi[k][0].transpose() * da.col(j);
term1 = term1 + tmp;
// second term
for (int n = 0; n < 3; ++n)
{
//dj::MulVecMatrix3x3<real>(db[n](), (real(*)[3]) &dajpi[n][1], tmp());
tmp = dajpi[n][1].transpose() * db.col(n);
term2 = term2 + tmp;
//dj::MulVecMatrix3x3<real>(da[n](), (real(*)[3]) &dbjpi[n][0], tmp());
tmp = dbjpi[n][0].transpose() * da.col(n);
term2 = term2 + tmp;
}
omega_pb.col(i) = (term1)-(0.5f * darboux_vector[i] * length) * (term2);
omega_pb.col(i) *= (x * bendAndTwistKs[i]);
}
// pc
{
Eigen::Vector3f term1(0, 0, 0);
Eigen::Vector3f term2(0, 0, 0);
Eigen::Vector3f tmp(0, 0, 0);
// first term
//dj::MulVecMatrix3x3<real>(da[k](), (real(*)[3]) &dbjpi[j][1], term1());
//dj::MulVecMatrix3x3<real>(da[j](), (real(*)[3]) &dbjpi[k][1], tmp());
term1 = dbjpi[j][1].transpose() * da.col(k);
tmp = dbjpi[k][1].transpose() * da.col(j);
term1 = term1 - tmp;
// second term
for (int n = 0; n < 3; ++n)
{
//dj::MulVecMatrix3x3<real>(da[n](), (real(*)[3]) &dbjpi[n][1], tmp());
tmp = dbjpi[n][1].transpose() * da.col(n);
term2 = term2 + tmp;
}
omega_pc.col(i) = (term1)+(0.5f * darboux_vector[i] * length) * (term2);
//.........这里部分代码省略.........
示例14: ComputeMaterialFrameDerivative
bool PositionBasedElasticRod::ComputeMaterialFrameDerivative(
const Eigen::Vector3f& p0, const Eigen::Vector3f& p1, const Eigen::Vector3f& p2, const Eigen::Matrix3f& d,
Eigen::Matrix3f& d1p0, Eigen::Matrix3f& d1p1, Eigen::Matrix3f& d1p2,
Eigen::Matrix3f& d2p0, Eigen::Matrix3f& d2p1, Eigen::Matrix3f& d2p2,
Eigen::Matrix3f& d3p0, Eigen::Matrix3f& d3p1, Eigen::Matrix3f& d3p2)
{
// d3pi
Eigen::Vector3f p01 = p1 - p0;
float length_p01 = p01.norm();
d3p0.col(0) = d.col(2)[0] * d.col(2);
d3p0.col(1) = d.col(2)[1] * d.col(2);
d3p0.col(2) = d.col(2)[2] * d.col(2);
d3p0.col(0)[0] -= 1.0f;
d3p0.col(1)[1] -= 1.0f;
d3p0.col(2)[2] -= 1.0f;
d3p0.col(0) *= (1.0f / length_p01);
d3p0.col(1) *= (1.0f / length_p01);
d3p0.col(2) *= (1.0f / length_p01);
d3p1.col(0) = -d3p0.col(0);
d3p1.col(1) = -d3p0.col(1);
d3p1.col(2) = -d3p0.col(2);
d3p2.col(0).setZero();
d3p2.col(1).setZero();
d3p2.col(2).setZero();
////>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//// d2pi
Eigen::Vector3f p02 = p2 - p0;
Eigen::Vector3f p01_cross_p02 = p01.cross(p02);
float length_cross = p01_cross_p02.norm();
Eigen::Matrix3f mat;
mat.col(0) = d.col(1)[0] * d.col(1);
mat.col(1) = d.col(1)[1] * d.col(1);
mat.col(2) = d.col(1)[2] * d.col(1);
mat.col(0)[0] -= 1.0f;
mat.col(1)[1] -= 1.0f;
mat.col(2)[2] -= 1.0f;
mat.col(0) *= (-1.0f / length_cross);
mat.col(1) *= (-1.0f / length_cross);
mat.col(2) *= (-1.0f / length_cross);
Eigen::Matrix3f product_matrix;
MathFunctions::crossProductMatrix(p2 - p1, product_matrix);
d2p0 = mat * product_matrix;
MathFunctions::crossProductMatrix(p0 - p2, product_matrix);
d2p1 = mat * product_matrix;
MathFunctions::crossProductMatrix(p1 - p0, product_matrix);
d2p2 = mat * product_matrix;
////>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//// d1pi
Eigen::Matrix3f product_mat_d3;
Eigen::Matrix3f product_mat_d2;
Eigen::Matrix3f m1, m2;
MathFunctions::crossProductMatrix(d.col(2), product_mat_d3);
MathFunctions::crossProductMatrix(d.col(1), product_mat_d2);
//dj::MulMatrix3x3<real>(&product_mat_d3[0][0], &d2p0[0][0], &m1[0][0]);
//dj::MulMatrix3x3<real>(&product_mat_d2[0][0], &d3p0[0][0], &m2[0][0]);
d1p0 = product_mat_d2 * d3p0 - product_mat_d3 * d2p0;
//dj::MulMatrix3x3<real>(&product_mat_d3[0][0], &d2p1[0][0], &m1[0][0]);
//dj::MulMatrix3x3<real>(&product_mat_d2[0][0], &d3p1[0][0], &m2[0][0]);
d1p1 = product_mat_d2 * d3p1 - product_mat_d3 * d2p1;
/*dj::MulMatrix3x3<real>(&product_mat_d3[0][0], &d2p2[0][0], &d1p2[0][0]);*/
d1p2 = product_mat_d3 * d2p2;
d1p2.col(0) *= -1.0f;
d1p2.col(1) *= -1.0f;
d1p2.col(2) *= -1.0f;
return true;
}
示例15: computeCube
}
}
return corr;
}
//--------------------------------------------------------------------------------------------------------------
//Pose estimation tools
void computeCube(Eigen::Vector3f& tfinal, Eigen::Quaternionf& qfinal_r, pcl::PointCloud<PointN>::Ptr final, float& _x, float& _y, float& _z) {
Eigen::Vector4f centroid;
pcl::compute3DCentroid(*final, centroid);
std::cout << "centroid: \n" << centroid[0] << " " << centroid[1] << " " << centroid[2]<< std::endl;
Eigen::Matrix3f covariance;
computeCovarianceMatrixNormalized(*final, centroid, covariance);
Eigen::SelfAdjointEigenSolver<Eigen::Matrix3f> eigen_solver(covariance, Eigen::ComputeEigenvectors);
Eigen::Matrix3f eigDx = eigen_solver.eigenvectors();
eigDx.col(2) = eigDx.col(0).cross(eigDx.col(1));
// move the points to the that reference frame
Eigen::Matrix4f p2w(Eigen::Matrix4f::Identity());
p2w.block<3,3>(0,0) = eigDx.transpose();
p2w.block<3,1>(0,3) = -1.f * (p2w.block<3,3>(0,0) * centroid.head<3>());
pcl::PointCloud<PointN> cPoints;
pcl::transformPointCloud(*final, cPoints, p2w);
PointN min_pt, max_pt;
pcl::getMinMax3D(cPoints, min_pt, max_pt);
const Eigen::Vector3f mean_diag = 0.5f*(max_pt.getVector3fMap() + min_pt.getVector3fMap());
// final transform
const Eigen::Quaternionf qfinal(eigDx);
tfinal = eigDx*mean_diag + centroid.head<3>();