avoid several implicit conversions, replace several old C-casts with static_cast, do some optimizations

This commit is contained in:
wmayer
2019-09-20 14:56:36 +02:00
parent 81d2ff358d
commit d4d9cd093e
9 changed files with 232 additions and 169 deletions

View File

@@ -54,7 +54,7 @@ void MeshBuilder::SetTolerance(float fTol)
MeshDefinitions::_fMinPointDistanceD1 = fTol;
}
void MeshBuilder::Initialize (unsigned long ctFacets, bool deletion)
void MeshBuilder::Initialize (size_t ctFacets, bool deletion)
{
if (deletion)
{
@@ -71,8 +71,8 @@ void MeshBuilder::Initialize (unsigned long ctFacets, bool deletion)
// Usually the number of vertices is the half of the number of facets. So we reserve this memory with 10% surcharge
// To save memory we hold an array with iterators that point to the right vertex (insertion order) in the set, instead of
// holding the vertex array twice.
unsigned long ctPoints = ctFacets / 2;
_pointsIterator.reserve((unsigned long)(float(ctPoints)*1.10f));
size_t ctPoints = ctFacets / 2;
_pointsIterator.reserve(static_cast<size_t>(float(ctPoints)*1.10f));
_ptIdx = 0;
}
else
@@ -88,10 +88,10 @@ void MeshBuilder::Initialize (unsigned long ctFacets, bool deletion)
// memory as we reuse it later on anyway.
_meshKernel._aclPointArray.clear();
// additional memory
unsigned long newCtFacets = _meshKernel._aclFacetArray.size()+ctFacets;
size_t newCtFacets = _meshKernel._aclFacetArray.size()+ctFacets;
_meshKernel._aclFacetArray.reserve(newCtFacets);
unsigned long ctPoints = newCtFacets / 2;
_pointsIterator.reserve((unsigned long)(float(ctPoints)*1.10f));
size_t ctPoints = newCtFacets / 2;
_pointsIterator.reserve(static_cast<size_t>(float(ctPoints)*1.10f));
}
this->_seq = new Base::SequencerLauncher("create mesh structure...", ctFacets * 2);
@@ -156,7 +156,7 @@ void MeshBuilder::AddFacet (Base::Vector3f* facetPoints, unsigned char flag, uns
void MeshBuilder::SetNeighbourhood ()
{
std::set<Edge> edges;
int facetIdx = 0;
unsigned long facetIdx = 0;
for (MeshFacetArray::_TIterator it = _meshKernel._aclFacetArray.begin(); it != _meshKernel._aclFacetArray.end(); ++it)
{
@@ -236,8 +236,8 @@ void MeshBuilder::Finish (bool freeMemory)
// if AddFacet() has been called more often (or even less) as specified in Initialize() we have a wastage of memory
if ( freeMemory )
{
unsigned long cap = _meshKernel._aclFacetArray.capacity();
unsigned long siz = _meshKernel._aclFacetArray.size();
size_t cap = _meshKernel._aclFacetArray.capacity();
size_t siz = _meshKernel._aclFacetArray.size();
// wastage of more than 5%
if ( cap > siz+siz/20 )
{
@@ -265,7 +265,7 @@ struct MeshFastBuilder::Private {
Vertex(float x, float y, float z) : x(x), y(y), z(z), i(0) {}
float x, y, z;
size_t i;
size_type i;
bool operator!=(const Vertex& rhs) const
{
@@ -293,7 +293,7 @@ MeshFastBuilder::~MeshFastBuilder(void)
delete p;
}
void MeshFastBuilder::Initialize (unsigned long ctFacets)
void MeshFastBuilder::Initialize (size_type ctFacets)
{
p->verts.reserve(ctFacets * 3);
}
@@ -322,9 +322,10 @@ void MeshFastBuilder::AddFacet (const MeshGeomFacet& facetPoints)
void MeshFastBuilder::Finish ()
{
typedef QVector<Private::Vertex>::size_type size_type;
QVector<Private::Vertex>& verts = p->verts;
size_t ulCtPts = verts.size();
for (size_t i=0; i < ulCtPts; ++i) {
size_type ulCtPts = verts.size();
for (size_type i=0; i < ulCtPts; ++i) {
verts[i].i = i;
}
@@ -334,26 +335,26 @@ void MeshFastBuilder::Finish ()
QVector<unsigned long> indices(ulCtPts);
size_t vertex_count = 0;
size_type vertex_count = 0;
for (QVector<Private::Vertex>::iterator v = verts.begin(); v != verts.end(); ++v) {
if (!vertex_count || *v != verts[vertex_count-1])
verts[vertex_count++] = *v;
indices[v->i] = vertex_count - 1;
indices[v->i] = static_cast<unsigned long>(vertex_count - 1);
}
size_t ulCt = verts.size()/3;
MeshFacetArray rFacets(ulCt);
for (size_t i=0; i < ulCt; ++i) {
rFacets[i]._aulPoints[0] = indices[3*i];
rFacets[i]._aulPoints[1] = indices[3*i + 1];
rFacets[i]._aulPoints[2] = indices[3*i + 2];
size_type ulCt = verts.size()/3;
MeshFacetArray rFacets(static_cast<unsigned long>(ulCt));
for (size_type i=0; i < ulCt; ++i) {
rFacets[static_cast<size_t>(i)]._aulPoints[0] = indices[3*i];
rFacets[static_cast<size_t>(i)]._aulPoints[1] = indices[3*i + 1];
rFacets[static_cast<size_t>(i)]._aulPoints[2] = indices[3*i + 2];
}
verts.resize(vertex_count);
MeshPointArray rPoints;
rPoints.reserve(vertex_count);
rPoints.reserve(static_cast<size_t>(vertex_count));
for (QVector<Private::Vertex>::iterator v = verts.begin(); v != verts.end(); ++v) {
rPoints.push_back(MeshPoint(v->x, v->y, v->z));
}