本文整理汇总了C++中eigen::Matrix3f::diagonal方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix3f::diagonal方法的具体用法?C++ Matrix3f::diagonal怎么用?C++ Matrix3f::diagonal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eigen::Matrix3f
的用法示例。
在下文中一共展示了Matrix3f::diagonal方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: t
void X3DConverter::startShape(const std::array<float, 12>& matrix) {
// Finding axis/angle from matrix using Eigen for its bullet proof implementation.
Eigen::Transform<float, 3, Eigen::Affine> t;
t.setIdentity();
for (unsigned int i = 0; i < 3; i++) {
for (unsigned int j = 0; j < 4; j++) {
t(i, j) = matrix[i+j*3];
}
}
Eigen::Matrix3f rotationMatrix;
Eigen::Matrix3f scaleMatrix;
t.computeRotationScaling(&rotationMatrix, &scaleMatrix);
Eigen::Quaternionf q;
Eigen::AngleAxisf aa;
q = rotationMatrix;
aa = q;
Eigen::Vector3f scale = scaleMatrix.diagonal();
Eigen::Vector3f translation = t.translation();
startNode(ID::Transform);
m_writers.back()->setSFVec3f(ID::translation, translation.x(), translation.y() , translation.z());
m_writers.back()->setSFRotation(ID::rotation, aa.axis().x(), aa.axis().y(), aa.axis().z(), aa.angle());
m_writers.back()->setSFVec3f(ID::scale, scale.x(), scale.y(), scale.z());
startNode(ID::Shape);
startNode(ID::Appearance);
startNode(ID::Material);
m_writers.back()->setSFColor<vector<float> >(ID::diffuseColor, RVMColorHelper::color(m_materials.back()));
endNode(ID::Material); // Material
endNode(ID::Appearance); // Appearance
}
示例2: computeVariances
bool StereoSensorProcessor::computeVariances(
const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr pointCloud,
const Eigen::Matrix<double, 6, 6>& robotPoseCovariance,
Eigen::VectorXf& variances)
{
variances.resize(pointCloud->size());
// Projection vector (P).
const Eigen::RowVector3f projectionVector = Eigen::RowVector3f::UnitZ();
// Sensor Jacobian (J_s).
const Eigen::RowVector3f sensorJacobian = projectionVector * (rotationMapToBase_.transposed() * rotationBaseToSensor_.transposed()).toImplementation().cast<float>();
// Robot rotation covariance matrix (Sigma_q).
Eigen::Matrix3f rotationVariance = robotPoseCovariance.bottomRightCorner(3, 3).cast<float>();
// Preparations for#include <pcl/common/transforms.h> robot rotation Jacobian (J_q) to minimize computation for every point in point cloud.
const Eigen::Matrix3f C_BM_transpose = rotationMapToBase_.transposed().toImplementation().cast<float>();
const Eigen::RowVector3f P_mul_C_BM_transpose = projectionVector * C_BM_transpose;
const Eigen::Matrix3f C_SB_transpose = rotationBaseToSensor_.transposed().toImplementation().cast<float>();
const Eigen::Matrix3f B_r_BS_skew = kindr::getSkewMatrixFromVector(Eigen::Vector3f(translationBaseToSensorInBaseFrame_.toImplementation().cast<float>()));
for (unsigned int i = 0; i < pointCloud->size(); ++i)
{
// For every point in point cloud.
// Preparation.
pcl::PointXYZRGB point = pointCloud->points[i];
double disparity = sensorParameters_.at("depth_to_disparity_factor")/point.z;
Eigen::Vector3f pointVector(point.x, point.y, point.z); // S_r_SP
float heightVariance = 0.0; // sigma_p
// Measurement distance.
float measurementDistance = pointVector.norm();
// Compute sensor covariance matrix (Sigma_S) with sensor model.
float varianceNormal = pow(sensorParameters_.at("depth_to_disparity_factor") / pow(disparity, 2), 2)
* ((sensorParameters_.at("p_5") * disparity + sensorParameters_.at("p_2"))
* sqrt(pow(sensorParameters_.at("p_3") * disparity + sensorParameters_.at("p_4") - getJ(i), 2)
+ pow(240 - getI(i), 2)) + sensorParameters_.at("p_1"));
float varianceLateral = pow(sensorParameters_.at("lateral_factor") * measurementDistance, 2);
Eigen::Matrix3f sensorVariance = Eigen::Matrix3f::Zero();
sensorVariance.diagonal() << varianceLateral, varianceLateral, varianceNormal;
// Robot rotation Jacobian (J_q).
const Eigen::Matrix3f C_SB_transpose_times_S_r_SP_skew = kindr::getSkewMatrixFromVector(Eigen::Vector3f(C_SB_transpose * pointVector));
Eigen::RowVector3f rotationJacobian = P_mul_C_BM_transpose * (C_SB_transpose_times_S_r_SP_skew + B_r_BS_skew);
// Measurement variance for map (error propagation law).
heightVariance = rotationJacobian * rotationVariance * rotationJacobian.transpose();
heightVariance += sensorJacobian * sensorVariance * sensorJacobian.transpose();
// Copy to list.
variances(i) = heightVariance;
}
return true;
}
示例3: computeVariances
bool LaserSensorProcessor::computeVariances(
const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr pointCloud,
const Eigen::Matrix<double, 6, 6>& robotPoseCovariance,
Eigen::VectorXf& variances)
{
variances.resize(pointCloud->size());
// Projection vector (P).
const Eigen::RowVector3f projectionVector = Eigen::RowVector3f::UnitZ();
// Sensor Jacobian (J_s).
const Eigen::RowVector3f sensorJacobian = projectionVector * (rotationMapToBase_.transposed() * rotationBaseToSensor_.transposed()).toImplementation().cast<float>();
// Robot rotation covariance matrix (Sigma_q).
Eigen::Matrix3f rotationVariance = robotPoseCovariance.bottomRightCorner(3, 3).cast<float>();
// Preparations for robot rotation Jacobian (J_q) to minimize computation for every point in point cloud.
const Eigen::Matrix3f C_BM_transpose = rotationMapToBase_.transposed().toImplementation().cast<float>();
const Eigen::RowVector3f P_mul_C_BM_transpose = projectionVector * C_BM_transpose;
const Eigen::Matrix3f C_SB_transpose = rotationBaseToSensor_.transposed().toImplementation().cast<float>();
const Eigen::Matrix3f B_r_BS_skew = kindr::linear_algebra::getSkewMatrixFromVector(Eigen::Vector3f(translationBaseToSensorInBaseFrame_.toImplementation().cast<float>()));
for (unsigned int i = 0; i < pointCloud->size(); ++i)
{
// For every point in point cloud.
// Preparation.
auto& point = pointCloud->points[i];
Eigen::Vector3f pointVector(point.x, point.y, point.z); // S_r_SP
float heightVariance = 0.0; // sigma_p
// Measurement distance.
float measurementDistance = pointVector.norm();
// Compute sensor covariance matrix (Sigma_S) with sensor model.
float varianceNormal = pow(sensorParameters_.at("min_radius"), 2);
float varianceLateral = pow(sensorParameters_.at("beam_constant") + sensorParameters_.at("beam_angle") * measurementDistance, 2);
Eigen::Matrix3f sensorVariance = Eigen::Matrix3f::Zero();
sensorVariance.diagonal() << varianceLateral, varianceLateral, varianceNormal;
// Robot rotation Jacobian (J_q).
const Eigen::Matrix3f C_SB_transpose_times_S_r_SP_skew = kindr::linear_algebra::getSkewMatrixFromVector(Eigen::Vector3f(C_SB_transpose * pointVector));
Eigen::RowVector3f rotationJacobian = P_mul_C_BM_transpose * (C_SB_transpose_times_S_r_SP_skew + B_r_BS_skew);
// Measurement variance for map (error propagation law).
heightVariance = rotationJacobian * rotationVariance * rotationJacobian.transpose();
heightVariance += sensorJacobian * sensorVariance * sensorJacobian.transpose();
// Copy to list.
variances(i) = heightVariance;
}
return true;
}
示例4: processFrame
void PwnTracker::processFrame(const DepthImage& depthImage_,
const Eigen::Isometry3f& sensorOffset_,
const Eigen::Matrix3f& cameraMatrix_,
const Eigen::Isometry3f& initialGuess){
int r,c;
Eigen::Matrix3f scaledCameraMatrix = cameraMatrix_;
_currentCloudOffset = sensorOffset_;
_currentCameraMatrix = cameraMatrix_;
_currentDepthImage = depthImage_;
_currentCloud = makeCloud(r,c,scaledCameraMatrix,_currentCloudOffset,_currentDepthImage);
bool newFrame = false;
bool newRelation = false;
PwnTrackerFrame* currentTrackerFrame=0;
Eigen::Isometry3d relationMean;
if (_previousCloud){
_aligner->setCurrentSensorOffset(_currentCloudOffset);
_aligner->setCurrentFrame(_currentCloud);
_aligner->setReferenceSensorOffset(_previousCloudOffset);
_aligner->setReferenceFrame(_previousCloud);
_aligner->correspondenceFinder()->setImageSize(r,c);
PinholePointProjector* alprojector=dynamic_cast<PinholePointProjector*>(_aligner->projector());
alprojector->setCameraMatrix(scaledCameraMatrix);
alprojector->setImageSize(r,c);
Eigen::Isometry3f guess=_previousCloudTransform.inverse()*_globalT*initialGuess;
_aligner->setInitialGuess(guess);
double t0, t1;
t0 = g2o::get_time();
_aligner->align();
t1 = g2o::get_time();
std::cout << "Time: " << t1 - t0 << " seconds " << std::endl;
cerr << "inliers: " << _aligner->inliers() << endl;
// cerr << "chi2: " << _aligner->error() << endl;
// cerr << "chi2/inliers: " << _aligner->error()/_aligner->inliers() << endl;
// cerr << "initialGuess: " << t2v(guess).transpose() << endl;
// cerr << "transform : " << t2v(_aligner->T()).transpose() << endl;
if (_aligner->inliers()>0){
_globalT = _previousCloudTransform*_aligner->T();
//cerr << "TRANSFORM FOUND" << endl;
} else {
//cerr << "FAILURE" << endl;
_globalT = _globalT*guess;
}
convertScalar(relationMean, _aligner->T());
if (! (_counter%50) ) {
Eigen::Matrix3f R = _globalT.linear();
Eigen::Matrix3f E = R.transpose() * R;
E.diagonal().array() -= 1;
_globalT.linear() -= 0.5 * R * E;
}
_globalT.matrix().row(3) << 0,0,0,1;
newAlignmentCallbacks(_globalT, _aligner->T(), _aligner->inliers(), _aligner->error());
int maxInliers = r*c;
float inliersFraction = (float) _aligner->inliers()/(float) maxInliers;
cerr << "inliers/maxinliers/fraction: " << _aligner->inliers() << "/" << maxInliers << "/" << inliersFraction << endl;
if (inliersFraction<_newFrameInliersFraction){
newFrame = true;
newRelation = true;
// char filename[1024];
// sprintf (filename, "frame-%05d.pwn", _numKeyframes);
// frame->save(filename,1,true,_globalT);
_numKeyframes ++;
if (!_cache)
delete _previousCloud;
else{
_previousCloudHandle.release();
}
//_cache->unlock(_previousTrackerFrame);
// _aligner->setReferenceSensorOffset(_currentCloudOffset);
// _aligner->setReferenceFrame(_currentCloud);
_previousCloud = _currentCloud;
_previousCloudTransform = _globalT;
// cerr << "new frame added (" << _numKeyframes << ")" << endl;
// cerr << "inliers: " << _aligner->inliers() << endl;
// cerr << "maxInliers: " << maxInliers << endl;
// cerr << "chi2: " << _aligner->error() << endl;
// cerr << "chi2/inliers: " << _aligner->error()/_aligner->inliers() << endl;
// cerr << "initialGuess: " << t2v(guess).transpose() << endl;
// cerr << "transform : " << t2v(_aligner->T()).transpose() << endl;
// cerr << "globalTransform : " << t2v(_globalT).transpose() << endl;
} else { // previous frame but offset is small
delete _currentCloud;
_currentCloud = 0;
}
} else { // first frame
//ser.writeObject(*manager);
newFrame = true;
// _aligner->setReferenceSensorOffset(_currentCloudOffset);
// _aligner->setReferenceFrame(_currentCloud);
_previousCloud = _currentCloud;
_previousCloudTransform = _globalT;
_previousCloudOffset = _currentCloudOffset;
//.........这里部分代码省略.........
示例5: main
int main(int argc, char **argv){
#if 0
DOF6::TFLinkvf rot1,rot2;
Eigen::Matrix4f tf1 = build_random_tflink(rot1,3);
Eigen::Matrix4f tf2 = build_random_tflink(rot2,3);
DOF6::DOF6_Source<DOF6::TFLinkvf,DOF6::TFLinkvf,float> abc(rot1.makeShared(), rot2.makeShared());
abc.getRotation();
abc.getTranslation();
std::cout<<"tf1\n"<<tf1<<"\n";
std::cout<<"tf2\n"<<tf2<<"\n";
std::cout<<"tf1*2\n"<<tf1*tf2<<"\n";
std::cout<<"tf2*1\n"<<tf2*tf1<<"\n";
std::cout<<"tf1\n"<<rot1.getTransformation()<<"\n";
std::cout<<"tf2\n"<<rot2.getTransformation()<<"\n";
std::cout<<"tf1*2\n"<<(rot1+rot2).getTransformation()<<"\n";
rot1.check();
rot2.check();
return 0;
pcl::RotationFromCorrespondences rfc;
Eigen::Vector3f n, nn, v,n2,n3,z,y,tv;
float a = 0.1f;
z.fill(0);y.fill(0);
z(2)=1;y(1)=1;
nn.fill(0);
nn(0) = 1;
Eigen::AngleAxisf aa(a,nn);
nn.fill(100);
n.fill(0);
n(0) = 1;
n2.fill(0);
n2=n;
n2(1) = 0.2;
n3.fill(0);
n3=n;
n3(2) = 0.2;
n2.normalize();
n3.normalize();
tv.fill(1);
tv.normalize();
#if 0
#if 0
rfc.add(n,aa.toRotationMatrix()*n+nn,
1*n.cross(y),1*n.cross(z),
1*(aa.toRotationMatrix()*n).cross(y),1*(aa.toRotationMatrix()*n).cross(z),
1,1/sqrtf(3));
#else
rfc.add(n,aa.toRotationMatrix()*n,
0*n.cross(y),0*n.cross(z),
0*(aa.toRotationMatrix()*n).cross(y),0*(aa.toRotationMatrix()*n).cross(z),
1,0);
#endif
#if 1
rfc.add(n2,aa.toRotationMatrix()*n2+nn,
tv,tv,
tv,tv,
1,1);
#else
rfc.add(n2,aa.toRotationMatrix()*n2+nn,
1*n2.cross(y),1*n2.cross(z),
1*(aa.toRotationMatrix()*n2).cross(y),1*(aa.toRotationMatrix()*n2).cross(z),
1,1/sqrtf(3));
#endif
#else
float f=1;
Eigen::Vector3f cyl;
cyl.fill(1);
cyl(0)=1;
Eigen::Matrix3f cylM;
cylM.fill(0);
cylM.diagonal() = cyl;
rfc.add(n,aa.toRotationMatrix()*n,
f*n.cross(y),f*n.cross(z),
f*(aa.toRotationMatrix()*n).cross(y),f*(aa.toRotationMatrix()*n).cross(z),
1,0);
rfc.add(n2,aa.toRotationMatrix()*n2+nn,
1*n2.cross(y),1*n2.cross(z),
1*(aa.toRotationMatrix()*n2).cross(y),1*(aa.toRotationMatrix()*n2).cross(z),
1,1);
#endif
rfc.add(n3,aa.toRotationMatrix()*n3+nn,
//tv,tv,
//tv,tv,
n3.cross(y),n3.cross(z),
1*(aa.toRotationMatrix()*n3).cross(y),1*(aa.toRotationMatrix()*n3).cross(z),
//.........这里部分代码省略.........
示例6: rawCloudHandler
//.........这里部分代码省略.........
// Test set - calculate performance statistics
if (testdata == true)
{
std::cout << confMat << std::endl;
confMats.push_back(confMat);
if (true)//k==files.size()-1)
{
ofstream myfile;
string resultsFolder = "/home/mikkel/catkin_ws/src/Results/";
myfile.open ((resultsFolder + "run_number_here.txt").c_str());
// Distance threshold
myfile << "DistanceThreshold:" << distThr << ";\n";
// Neighborhood parameters
myfile << "Neighborhood:" << rmin << ";" << rmindist << ";" << rmax << ";" << rmaxdist << ";\n";
// Features
myfile << "Features:";
for (int d=0;d<dim;d++)
myfile << useFeatures[d] << ";";
myfile << "\n";
myfile << "ConfusionMatrix:";
for (size_t i=0;i<confMats.size();i++)
{
for (int r=0;r<confMats[i].rows();r++)
for (int c=0;c<confMats[i].cols();c++)
myfile << confMats[i](r,c) << ";";
myfile << "\n";
}
myfile << "Accuracy:" << confMat.diagonal().sum()/confMat.sum() << ";\n";
myfile.close();
}
}
featureCloudAcc->clear();
labels.clear();
#else
for (size_t i=0;i<transformedCloud->size();i++)
{
pcl::PointXYZI pTmp2 = transformedCloud->points[i];
pcl::PointXYZRGB pTmp;
pTmp.x = pTmp2.x;
pTmp.y = pTmp2.y;
pTmp.z = pTmp2.z;
pTmp.r = 255;
pTmp.g = 255;
if (pTmp.z > 0.1) // Object
{
classificationCloud->push_back(pTmp);
}
}
if (visualizationFlag)
{
pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB> colorC(classificationCloud);
viewer->addPointCloud<pcl::PointXYZRGB>(classificationCloud,colorC,"Classification",viewP(Classification));
viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 2, "Classification");
viewer->addText ("Classification", 10, 10, fontsize, 1, 1, 1, "Classification text", viewP(Classification));
示例7: processNode
//.........这里部分代码省略.........
cerr << "Frames: " << _previousFrame << " " << frame << endl;
// projector->setCameraMatrix(cameraMatrix);
// projector->setTransform(Eigen::Isometry3f::Identity());
// Eigen::MatrixXi debugIndices(r,c);
// DepthImage debugImage(r,c);
// projector->project(debugIndices, debugImage, frame->points());
_aligner->align();
// sprintf(buf, "img-dbg-%05d.pgm",j);
// debugImage.save(buf);
//sprintf(buf, "img-ref-%05d.pgm",j);
//_aligner->correspondenceFinder()->referenceDepthImage().save(buf);
//sprintf(buf, "img-cur-%05d.pgm",j);
//_aligner->correspondenceFinder()->currentDepthImage().save(buf);
cerr << "inliers: " << _aligner->inliers() << endl;
cerr << "chi2: " << _aligner->error() << endl;
cerr << "chi2/inliers: " << _aligner->error()/_aligner->inliers() << endl;
cerr << "initialGuess: " << t2v(guess).transpose() << endl;
cerr << "transform : " << t2v(_aligner->T()).transpose() << endl;
if (_aligner->inliers()>-1){
_globalT = _globalT*_aligner->T();
cerr << "TRANSFORM FOUND" << endl;
} else {
cerr << "FAILURE" << endl;
_globalT = _globalT*guess;
}
if (! (_counter%50) ) {
Eigen::Matrix3f R = _globalT.linear();
Eigen::Matrix3f E = R.transpose() * R;
E.diagonal().array() -= 1;
_globalT.linear() -= 0.5 * R * E;
}
_globalT.matrix().row(3) << 0,0,0,1;
cerr << "globalTransform : " << t2v(_globalT).transpose() << endl;
// char buf[1024];
// sprintf(buf, "frame-%05d.pwn",_counter);
// frame->save(buf, 1, true, _globalT);
cerr << "creating alias" << endl;
// create an alias for the previous node
MapNodeAlias* newRoot = new MapNodeAlias(_previousSensingFrameNode,_previousSensingFrameNode->manager());
_previousSensingFrameNode->manager()->addNode(newRoot);
cerr << "creating alias relation" << endl;
MapNodeAliasRelation* aliasRel = new MapNodeAliasRelation(newRoot,_previousSensingFrameNode->manager());
aliasRel->nodes()[0] = newRoot;
aliasRel->nodes()[1] = _previousSensingFrameNode;
_previousSensingFrameNode->manager()->addRelation(aliasRel);
cerr << "reparenting old elements" << endl;
// assign all the used relations to the alias node
if (imu){
imu->setOwner(newRoot);
imu->manager()->addRelation(imu);
}
if (odom){
odom->setOwner(newRoot);
odom->manager()->addRelation(imu);
}