avoid several implicit conversions, replace several old C-casts with static_cast, do some optimizations
This commit is contained in:
@@ -154,9 +154,20 @@ Base::Matrix4D AbstractPolygonTriangulator::GetTransformToFitPlane() const
|
||||
// build the matrix for the inverse transformation
|
||||
Base::Matrix4D rInverse;
|
||||
rInverse.setToUnity();
|
||||
rInverse[0][0] = ex.x; rInverse[0][1] = ey.x; rInverse[0][2] = ez.x; rInverse[0][3] = bs.x;
|
||||
rInverse[1][0] = ex.y; rInverse[1][1] = ey.y; rInverse[1][2] = ez.y; rInverse[1][3] = bs.y;
|
||||
rInverse[2][0] = ex.z; rInverse[2][1] = ey.z; rInverse[2][2] = ez.z; rInverse[2][3] = bs.z;
|
||||
rInverse[0][0] = static_cast<double>(ex.x);
|
||||
rInverse[0][1] = static_cast<double>(ey.x);
|
||||
rInverse[0][2] = static_cast<double>(ez.x);
|
||||
rInverse[0][3] = static_cast<double>(bs.x);
|
||||
|
||||
rInverse[1][0] = static_cast<double>(ex.y);
|
||||
rInverse[1][1] = static_cast<double>(ey.y);
|
||||
rInverse[1][2] = static_cast<double>(ez.y);
|
||||
rInverse[1][3] = static_cast<double>(bs.y);
|
||||
|
||||
rInverse[2][0] = static_cast<double>(ex.z);
|
||||
rInverse[2][1] = static_cast<double>(ey.z);
|
||||
rInverse[2][2] = static_cast<double>(ez.z);
|
||||
rInverse[2][3] = static_cast<double>(bs.z);
|
||||
|
||||
return rInverse;
|
||||
}
|
||||
@@ -165,9 +176,15 @@ std::vector<Base::Vector3f> AbstractPolygonTriangulator::ProjectToFitPlane()
|
||||
{
|
||||
std::vector<Base::Vector3f> proj = _points;
|
||||
_inverse = GetTransformToFitPlane();
|
||||
Base::Vector3f bs((float)_inverse[0][3], (float)_inverse[1][3], (float)_inverse[2][3]);
|
||||
Base::Vector3f ex((float)_inverse[0][0], (float)_inverse[1][0], (float)_inverse[2][0]);
|
||||
Base::Vector3f ey((float)_inverse[0][1], (float)_inverse[1][1], (float)_inverse[2][1]);
|
||||
Base::Vector3f bs(static_cast<float>(_inverse[0][3]),
|
||||
static_cast<float>(_inverse[1][3]),
|
||||
static_cast<float>(_inverse[2][3]));
|
||||
Base::Vector3f ex(static_cast<float>(_inverse[0][0]),
|
||||
static_cast<float>(_inverse[1][0]),
|
||||
static_cast<float>(_inverse[2][0]));
|
||||
Base::Vector3f ey(static_cast<float>(_inverse[0][1]),
|
||||
static_cast<float>(_inverse[1][1]),
|
||||
static_cast<float>(_inverse[2][1]));
|
||||
for (std::vector<Base::Vector3f>::iterator jt = proj.begin(); jt!=proj.end(); ++jt)
|
||||
jt->TransformToCoordinateSystem(bs, ex, ey);
|
||||
return proj;
|
||||
@@ -180,9 +197,15 @@ void AbstractPolygonTriangulator::PostProcessing(const std::vector<Base::Vector3
|
||||
unsigned int uMinPts = 50;
|
||||
|
||||
PolynomialFit polyFit;
|
||||
Base::Vector3f bs((float)_inverse[0][3], (float)_inverse[1][3], (float)_inverse[2][3]);
|
||||
Base::Vector3f ex((float)_inverse[0][0], (float)_inverse[1][0], (float)_inverse[2][0]);
|
||||
Base::Vector3f ey((float)_inverse[0][1], (float)_inverse[1][1], (float)_inverse[2][1]);
|
||||
Base::Vector3f bs(static_cast<float>(_inverse[0][3]),
|
||||
static_cast<float>(_inverse[1][3]),
|
||||
static_cast<float>(_inverse[2][3]));
|
||||
Base::Vector3f ex(static_cast<float>(_inverse[0][0]),
|
||||
static_cast<float>(_inverse[1][0]),
|
||||
static_cast<float>(_inverse[2][0]));
|
||||
Base::Vector3f ey(static_cast<float>(_inverse[0][1]),
|
||||
static_cast<float>(_inverse[1][1]),
|
||||
static_cast<float>(_inverse[2][1]));
|
||||
|
||||
for (std::vector<Base::Vector3f>::const_iterator it = points.begin(); it != points.end(); ++it) {
|
||||
Base::Vector3f pt = *it;
|
||||
@@ -192,7 +215,7 @@ void AbstractPolygonTriangulator::PostProcessing(const std::vector<Base::Vector3
|
||||
|
||||
if (polyFit.CountPoints() >= uMinPts && polyFit.Fit() < FLOAT_MAX) {
|
||||
for (std::vector<Base::Vector3f>::iterator pt = _newpoints.begin(); pt != _newpoints.end(); ++pt)
|
||||
pt->z = (float)polyFit.Value(pt->x, pt->y);
|
||||
pt->z = static_cast<float>(polyFit.Value(pt->x, pt->y));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,7 +298,7 @@ bool EarClippingTriangulator::Triangulate()
|
||||
Triangulate::Process(pts,result);
|
||||
|
||||
// print out the results.
|
||||
unsigned long tcount = result.size()/3;
|
||||
size_t tcount = result.size()/3;
|
||||
|
||||
bool ok = tcount+2 == _points.size();
|
||||
if (tcount > _points.size())
|
||||
@@ -582,7 +605,7 @@ struct Vertex2d_Less : public std::binary_function<const Base::Vector3f&, const
|
||||
if (fabs(p.x - q.x) < MeshDefinitions::_fMinPointDistanceD1) {
|
||||
if (fabs(p.y - q.y) < MeshDefinitions::_fMinPointDistanceD1) {
|
||||
return false; } else return p.y < q.y;
|
||||
} else return p.x < q.x; return true;
|
||||
} else return p.x < q.x;
|
||||
}
|
||||
};
|
||||
struct Vertex2d_EqualTo : public std::binary_function<const Base::Vector3f&, const Base::Vector3f&, bool>
|
||||
@@ -625,13 +648,13 @@ bool DelaunayTriangulator::Triangulate()
|
||||
std::vector<Wm4::Vector2d> akVertex;
|
||||
akVertex.reserve(_points.size());
|
||||
for (std::vector<Base::Vector3f>::iterator it = _points.begin(); it != _points.end(); ++it) {
|
||||
akVertex.push_back(Wm4::Vector2d(it->x, it->y));
|
||||
akVertex.push_back(Wm4::Vector2d(static_cast<double>(it->x), static_cast<double>(it->y)));
|
||||
}
|
||||
|
||||
Wm4::Delaunay2d del(akVertex.size(), &(akVertex[0]), 0.001, false, Wm4::Query::QT_INT64);
|
||||
Wm4::Delaunay2d del(static_cast<int>(akVertex.size()), &(akVertex[0]), 0.001, false, Wm4::Query::QT_INT64);
|
||||
int iTQuantity = del.GetSimplexQuantity();
|
||||
std::vector<int> aiTVertex(3*iTQuantity);
|
||||
size_t uiSize = 3*iTQuantity*sizeof(int);
|
||||
std::vector<int> aiTVertex(static_cast<size_t>(3*iTQuantity));
|
||||
size_t uiSize = static_cast<size_t>(3*iTQuantity)*sizeof(int);
|
||||
Wm4::System::Memcpy(&(aiTVertex[0]),uiSize,del.GetIndices(),uiSize);
|
||||
|
||||
// If H is the number of hull edges and N is the number of vertices,
|
||||
@@ -652,9 +675,10 @@ bool DelaunayTriangulator::Triangulate()
|
||||
MeshFacet facet;
|
||||
for (int i = 0; i < iTQuantity; i++) {
|
||||
for (int j=0; j<3; j++) {
|
||||
facet._aulPoints[j] = aiTVertex[3*i+j];
|
||||
triangle._aclPoints[j].x = (float)akVertex[aiTVertex[3*i+j]].X();
|
||||
triangle._aclPoints[j].y = (float)akVertex[aiTVertex[3*i+j]].Y();
|
||||
size_t index = static_cast<size_t>(aiTVertex[static_cast<size_t>(3*i+j)]);
|
||||
facet._aulPoints[j] = static_cast<unsigned long>(index);
|
||||
triangle._aclPoints[j].x = static_cast<float>(akVertex[index].X());
|
||||
triangle._aclPoints[j].y = static_cast<float>(akVertex[index].Y());
|
||||
}
|
||||
|
||||
_triangles.push_back(triangle);
|
||||
|
||||
Reference in New Issue
Block a user