Skip to content
Snippets Groups Projects
Commit 61de7c3e authored by Dmitri Naumov's avatar Dmitri Naumov Committed by Tom Fischer
Browse files

[GL] Copy getNewellPlane() using vector<Point>;

The copied algorithm allows passing of a vector of
points instead of pointers to points.
parent 5c026bf8
No related branches found
No related tags found
No related merge requests found
...@@ -33,6 +33,28 @@ void getNewellPlane (const std::vector<T_POINT*>& pnts, ...@@ -33,6 +33,28 @@ void getNewellPlane (const std::vector<T_POINT*>& pnts,
d = MathLib::scalarProduct(centroid, plane_normal) / n_pnts; d = MathLib::scalarProduct(centroid, plane_normal) / n_pnts;
} }
template <class T_POINT>
std::pair<MathLib::Vector3, double> getNewellPlane (const std::vector<T_POINT>& pnts)
{
MathLib::Vector3 plane_normal;
MathLib::Vector3 centroid;
std::size_t n_pnts(pnts.size());
for (std::size_t i = n_pnts - 1, j = 0; j < n_pnts; i = j, j++) {
plane_normal[0] += (pnts[i][1] - pnts[j][1])
* (pnts[i][2] + pnts[j][2]); // projection on yz
plane_normal[1] += (pnts[i][2] - pnts[j][2])
* (pnts[i][0] + pnts[j][0]); // projection on xz
plane_normal[2] += (pnts[i][0] - pnts[j][0])
* (pnts[i][1] + pnts[j][1]); // projection on xy
centroid += pnts[j];
}
plane_normal.normalize();
double d = MathLib::scalarProduct(centroid, plane_normal) / n_pnts;
return std::make_pair(plane_normal, d);
}
template<class T_MATRIX> template<class T_MATRIX>
void compute2DRotationMatrixToX(MathLib::Vector3 const& v, void compute2DRotationMatrixToX(MathLib::Vector3 const& v,
T_MATRIX & rot_mat) T_MATRIX & rot_mat)
......
...@@ -66,6 +66,11 @@ void getNewellPlane (const std::vector<T_POINT*>& pnts, ...@@ -66,6 +66,11 @@ void getNewellPlane (const std::vector<T_POINT*>& pnts,
MathLib::Vector3 &plane_normal, MathLib::Vector3 &plane_normal,
double& d); double& d);
/** Same as getNewellPlane(pnts, plane_normal, d).
*/
template <class T_POINT>
std::pair<MathLib::Vector3, double> getNewellPlane(const std::vector<T_POINT>& pnts);
/** /**
* Computes a rotation matrix that rotates the given 2D normal vector parallel to X-axis * Computes a rotation matrix that rotates the given 2D normal vector parallel to X-axis
* @param v a 2D normal vector to be rotated * @param v a 2D normal vector to be rotated
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment