本文整理汇总了C++中eigen::Vector3f::squaredNorm方法的典型用法代码示例。如果您正苦于以下问题:C++ Vector3f::squaredNorm方法的具体用法?C++ Vector3f::squaredNorm怎么用?C++ Vector3f::squaredNorm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eigen::Vector3f
的用法示例。
在下文中一共展示了Vector3f::squaredNorm方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: area
template <typename PointSource, typename PointTarget, typename NormalT, typename Scalar> int
pcl::registration::FPCSInitialAlignment <PointSource, PointTarget, NormalT, Scalar>::selectBaseTriangle (std::vector <int> &base_indices)
{
int nr_points = static_cast <int> (target_indices_->size ());
float best_t = 0.f;
// choose random first point
base_indices[0] = (*target_indices_)[rand () % nr_points];
int *index1 = &base_indices[0];
// random search for 2 other points (as far away as overlap allows)
for (int i = 0; i < ransac_iterations_; i++)
{
int *index2 = &(*target_indices_)[rand () % nr_points];
int *index3 = &(*target_indices_)[rand () % nr_points];
Eigen::Vector3f u = target_->points[*index2].getVector3fMap () - target_->points[*index1].getVector3fMap ();
Eigen::Vector3f v = target_->points[*index3].getVector3fMap () - target_->points[*index1].getVector3fMap ();
float t = u.cross (v).squaredNorm (); // triangle area (0.5 * sqrt(t)) should be maximal
// check for most suitable point triple
if (t > best_t && u.squaredNorm () < max_base_diameter_sqr_ && v.squaredNorm () < max_base_diameter_sqr_)
{
best_t = t;
base_indices[1] = *index2;
base_indices[2] = *index3;
}
}
// return if a triplet could be selected
return (best_t == 0.f ? -1 : 0);
}
示例2: v
inline Eigen::Affine3f tf_from_plane_model(float a, float b, float c, float d) {
Eigen::Vector3f new_normal(a, b, c);
Eigen::Vector3f old_normal(0, 0, 1);
Eigen::Vector3f v = old_normal.cross(new_normal);
float s2 = v.squaredNorm();
float cc = old_normal.dot(new_normal);
Eigen::Matrix3f v_cross;
v_cross << 0, -v(2), v(1), v(2), 0, -v(0), -v(1), v(0), 0;
Eigen::Matrix3f rot = Eigen::Matrix3f::Identity() + v_cross + v_cross * v_cross * (1 - cc) / s2;
Eigen::Affine3f arot(rot);
// Create a transform where the rotation component is given by the rotation axis as the normal vector (a, b, c)
// and some arbitrary angle about that axis and the translation component is -d in the z direction after
// that rotation (not the original z direction, which is how transforms are usually defined).
auto result = Eigen::Translation3f(0, 0, d) * arot.inverse();
return result;
}
示例3: performPlayerUpdate
void Streamer::performPlayerUpdate(Player &player, bool automatic)
{
Eigen::Vector3f delta = Eigen::Vector3f::Zero(), position = player.position;
int state = GetPlayerState(player.playerID);
bool update = true;
if (automatic)
{
player.interiorID = GetPlayerInterior(player.playerID);
player.worldID = GetPlayerVirtualWorld(player.playerID);
GetPlayerPos(player.playerID, &player.position[0], &player.position[1], &player.position[2]);
if (state != PLAYER_STATE_NONE && state != PLAYER_STATE_WASTED)
{
if (player.position != position)
{
position = player.position;
Eigen::Vector3f velocity = Eigen::Vector3f::Zero();
if (state == PLAYER_STATE_ONFOOT)
{
GetPlayerVelocity(player.playerID, &velocity[0], &velocity[1], &velocity[2]);
}
else if (state == PLAYER_STATE_DRIVER || state == PLAYER_STATE_PASSENGER)
{
GetVehicleVelocity(GetPlayerVehicleID(player.playerID), &velocity[0], &velocity[1], &velocity[2]);
}
float velocityNorm = velocity.squaredNorm();
if (velocityNorm >= velocityBoundaries.get<0>() && velocityNorm <= velocityBoundaries.get<1>())
{
delta = velocity * averageUpdateTime;
player.position += delta;
}
}
else
{
update = player.updateWhenIdle;
}
}
else
{
update = false;
}
}
std::vector<SharedCell> cells;
if (update)
{
core->getGrid()->findAllCells(player, cells);
if (!cells.empty())
{
if (!core->getData()->objects.empty() && player.enabledItems[STREAMER_TYPE_OBJECT] && !IsPlayerNPC(player.playerID))
{
processObjects(player, cells);
}
if (!core->getData()->checkpoints.empty() && player.enabledItems[STREAMER_TYPE_CP])
{
processCheckpoints(player, cells);
}
if (!core->getData()->raceCheckpoints.empty() && player.enabledItems[STREAMER_TYPE_RACE_CP])
{
processRaceCheckpoints(player, cells);
}
if (!core->getData()->mapIcons.empty() && player.enabledItems[STREAMER_TYPE_MAP_ICON] && !IsPlayerNPC(player.playerID))
{
processMapIcons(player, cells);
}
if (!core->getData()->textLabels.empty() && player.enabledItems[STREAMER_TYPE_3D_TEXT_LABEL] && !IsPlayerNPC(player.playerID))
{
processTextLabels(player, cells);
}
if (!core->getData()->areas.empty() && player.enabledItems[STREAMER_TYPE_AREA])
{
if (!delta.isZero())
{
player.position = position;
}
processAreas(player, cells);
if (!delta.isZero())
{
player.position += delta;
}
}
}
}
if (automatic)
{
if (!core->getData()->pickups.empty())
{
if (!update)
{
core->getGrid()->findMinimalCells(player, cells);
}
processPickups(player, cells);
}
if (!delta.isZero())
{
player.position = position;
}
executeCallbacks();
}
}
示例4: interval
//.........这里部分代码省略.........
for (; pIdx < polygon.size (); ++pIdx)
{
covariance.coeffRef (0) += polygon [pIdx].x * polygon [pIdx].x;
covariance.coeffRef (1) += polygon [pIdx].x * polygon [pIdx].y;
covariance.coeffRef (3) += polygon [pIdx].y * polygon [pIdx].y;
centroid [0] += polygon [pIdx].x;
centroid [1] += polygon [pIdx].y;
}
pIdx = 0;
}
num_points += result[nIdx] - pIdx;
for (; pIdx < result[nIdx]; ++pIdx)
{
covariance.coeffRef (0) += polygon [pIdx].x * polygon [pIdx].x;
covariance.coeffRef (1) += polygon [pIdx].x * polygon [pIdx].y;
covariance.coeffRef (3) += polygon [pIdx].y * polygon [pIdx].y;
centroid [0] += polygon [pIdx].x;
centroid [1] += polygon [pIdx].y;
}
covariance.coeffRef (2) = covariance.coeff (1);
float norm = 1.0f / float (num_points);
centroid *= norm;
covariance *= norm;
covariance.coeffRef (0) -= centroid [0] * centroid [0];
covariance.coeffRef (1) -= centroid [0] * centroid [1];
covariance.coeffRef (3) -= centroid [1] * centroid [1];
float eval;
Eigen::Vector2f normal;
eigen22 (covariance, eval, normal);
// select the one which is more "parallel" to the original line
Eigen::Vector2f direction;
direction [0] = polygon[result[nIdx]].x - polygon[result[rIdx]].x;
direction [1] = polygon[result[nIdx]].y - polygon[result[rIdx]].y;
direction.normalize ();
if (fabs (direction.dot (normal)) > float(M_SQRT1_2))
{
std::swap (normal [0], normal [1]);
normal [0] = -normal [0];
}
// needs to be on the left side of the edge
if (direction [0] * normal [1] < direction [1] * normal [0])
normal *= -1.0;
lines [rIdx].head<2> () = normal;
lines [rIdx] [2] = -normal.dot (centroid);
}
float threshold2 = threshold * threshold;
for (unsigned rIdx = 0; rIdx < lines.size (); ++rIdx)
{
unsigned nIdx = rIdx + 1;
if (nIdx == result.size ())
nIdx = 0;
Eigen::Vector3f vertex = lines [rIdx].cross (lines [nIdx]);
vertex /= vertex [2];
vertex [2] = 0.0;
PointT point;
// test whether we need another edge since the intersection point is too far away from the original vertex
Eigen::Vector3f pq = polygon [result[nIdx]].getVector3fMap () - vertex;
pq [2] = 0.0;
float distance = pq.squaredNorm ();
if (distance > threshold2)
{
// test whether the old point is inside the new polygon or outside
if ((pq [0] * lines [rIdx] [0] + pq [1] * lines [rIdx] [1] < 0.0) &&
(pq [0] * lines [nIdx] [0] + pq [1] * lines [nIdx] [1] < 0.0) )
{
float distance1 = lines [rIdx] [0] * polygon[result[nIdx]].x + lines [rIdx] [1] * polygon[result[nIdx]].y + lines [rIdx] [2];
float distance2 = lines [nIdx] [0] * polygon[result[nIdx]].x + lines [nIdx] [1] * polygon[result[nIdx]].y + lines [nIdx] [2];
point.x = polygon[result[nIdx]].x - distance1 * lines [rIdx] [0];
point.y = polygon[result[nIdx]].y - distance1 * lines [rIdx] [1];
approx_polygon.push_back (point);
vertex [0] = polygon[result[nIdx]].x - distance2 * lines [nIdx] [0];
vertex [1] = polygon[result[nIdx]].y - distance2 * lines [nIdx] [1];
}
}
point.getVector3fMap () = vertex;
approx_polygon.push_back (point);
}
}
else
{
// we have a new polygon in results, but inverted (clockwise <-> counter-clockwise)
for (std::vector<unsigned>::reverse_iterator it = result.rbegin (); it != result.rend (); ++it)
approx_polygon.push_back (polygon [*it]);
}
}