本文整理汇总了C++中Matrixf::ncols方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrixf::ncols方法的具体用法?C++ Matrixf::ncols怎么用?C++ Matrixf::ncols使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrixf
的用法示例。
在下文中一共展示了Matrixf::ncols方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetMatrixRow
/**
* Extract a row from a matrix
* @param matrix The matrix that we are extracting the row for
* @param rowNumber The number of the row that we are working
* @return The matrix row that we are retrieving
*/
Matrixf GetMatrixRow(Matrixf & matrix, int rowNumber)
{
Matrixf result(matrix.ncols(), 1);
for (int column = 0; column<matrix.ncols(); column++)
{
float value = matrix.get(rowNumber, column);
result.set(column, 0, value);
}
return result;
}
示例2: main
/**
* Main application entry point
* @param argumentCount The amount of arguments comment in
* @param arguments The list of incomming arguments
* @returns SUCCESS or FAILURE
*/
int main(int argumentCount, char **arguments)
{
try
{
if (argumentCount != 2) throw runtime_error("USAGE: q5 <fileName>");
Matrixf vertices = ReadFile(arguments[1]);
// ---------------- Compute the robust normal ----------------
// compute centroid
Matrixf centroid(vertices.ncols(), 1);
for (unsigned int c = 0; c < vertices.ncols(); c++)
{
float total = 0;
for (unsigned int r = 0; r < vertices.nrows(); r++)
total += vertices(r, c);
centroid(c, 0) = total / vertices.nrows();
}
// find normal of our plane (formed by points 0, 1, and C)
Matrixf normEst = cross(subtract(GetMatrixRow(vertices, 0), centroid), subtract(GetMatrixRow(vertices, 1), centroid));
// find the absolute largest component (x,y,z) of the normal
for (unsigned int i = 0; i < 3; i++)
normEst(i, 0) = abs(normEst(i, 0));
int componentI;
if (normEst(0,0) > normEst(1,0) && normEst(0,0) > normEst(2,0))
componentI = 0;
else if (normEst(1,0) > normEst(0,0) && normEst(1,0) > normEst(2,0))
componentI = 1;
else
componentI = 2;
// copy vertices -- removing the largest component
unsigned int tempCount;
Matrixf projVertices(vertices.nrows(), vertices.ncols() - 1);
for (unsigned int r = 0; r < projVertices.nrows(); r++)
{
tempCount = 0;
for (unsigned int c = 0; c < vertices.ncols(); c++)
{
if (c != componentI)
{
projVertices(r, tempCount) = vertices(r, c);
tempCount++;
}
}
}
Matrixf projCentroid(centroid.nrows() - 1, 1);
tempCount = 0;
for (unsigned int r = 0; r < centroid.nrows(); r++)
{
if (r != componentI)
{
projCentroid(tempCount, 0) = centroid(r, 0);
tempCount++;
}
}
// calculate the counter-clockwise ordering of the vertices
Matrixf vecOA = subtract(GetMatrixRow(projVertices, 0), projCentroid);
Matrixf rotate(2, 2);
rotate(0, 0) = 0; rotate(0, 1) = -1;
rotate(1, 0) = 1; rotate(1, 1) = 0;
IndexAngle indexAng[5];
indexAng[0].index = 0;
indexAng[0].angle = 0.0f;
for (unsigned int r = 1; r < projVertices.nrows(); r++) // for each other vertex
{
Matrixf temp = subtract(GetMatrixRow(projVertices, r), projCentroid);
float angle = acos(dot(temp, vecOA) / (length(temp) * length(vecOA)));
// rotate ccw pi/2
Matrixf tempRot = multiply(rotate, temp);
float angleRot = acos(dot(tempRot, vecOA) / (length(tempRot) * length(vecOA)));
if ((angle < M_PI_2 && angleRot < M_PI_2) || (angle > M_PI_2 && angleRot < M_PI_2)) // angle on right
angle = (M_PI * 2) - angle;
indexAng[r].index = r;
indexAng[r].angle = angle;
}
// sort by angle size
sort(indexAng, indexAng + 5, &angle_sorter);
// compute the normal at each vertex
Matrixf normalAtVert(vertices.nrows(), vertices.ncols());
//.........这里部分代码省略.........