diff --git a/src/Mod/Mesh/App/CMakeLists.txt b/src/Mod/Mesh/App/CMakeLists.txt index e68840bab2..ca6c698a70 100644 --- a/src/Mod/Mesh/App/CMakeLists.txt +++ b/src/Mod/Mesh/App/CMakeLists.txt @@ -91,6 +91,7 @@ SET(Core_SRCS Core/TrimByPlane.cpp Core/TrimByPlane.h Core/tritritest.h + Core/Utilities.h Core/Visitor.cpp Core/Visitor.h ) diff --git a/src/Mod/Mesh/App/Core/Approximation.cpp b/src/Mod/Mesh/App/Core/Approximation.cpp index 5b3a260bec..379487a586 100644 --- a/src/Mod/Mesh/App/Core/Approximation.cpp +++ b/src/Mod/Mesh/App/Core/Approximation.cpp @@ -29,6 +29,7 @@ #endif #include "Approximation.h" +#include "Utilities.h" #include #include @@ -56,22 +57,12 @@ Approximation::~Approximation() Clear(); } -void Approximation::Convert( const Wm4::Vector3& Wm4, Base::Vector3f& pt) -{ - pt.Set( (float)Wm4.X(), (float)Wm4.Y(), (float)Wm4.Z() ); -} - -void Approximation::Convert( const Base::Vector3f& pt, Wm4::Vector3& Wm4) -{ - Wm4.X() = pt.x; Wm4.Y() = pt.y; Wm4.Z() = pt.z; -} - void Approximation::GetMgcVectorArray(std::vector< Wm4::Vector3 >& rcPts) const { std::list< Base::Vector3f >::const_iterator It; + rcPts.reserve(_vPoints.size()); for (It = _vPoints.begin(); It != _vPoints.end(); ++It) { - Wm4::Vector3 pt( (*It).x, (*It).y, (*It).z ); - rcPts.push_back( pt ); + rcPts.push_back(Base::convertTo(*It)); } } @@ -81,27 +72,21 @@ void Approximation::AddPoint(const Base::Vector3f &rcVector) _bIsFitted = false; } -void Approximation::AddPoints(const std::vector &rvPointVect) +void Approximation::AddPoints(const std::vector &points) { - std::vector::const_iterator cIt; - for (cIt = rvPointVect.begin(); cIt != rvPointVect.end(); ++cIt) - _vPoints.push_back(*cIt); + std::copy(points.begin(), points.end(), _vPoints.end()); _bIsFitted = false; } -void Approximation::AddPoints(const std::set &rsPointSet) +void Approximation::AddPoints(const std::set &points) { - std::set::const_iterator cIt; - for (cIt = rsPointSet.begin(); cIt != rsPointSet.end(); ++cIt) - _vPoints.push_back(*cIt); + std::copy(points.begin(), points.end(), _vPoints.end()); _bIsFitted = false; } -void Approximation::AddPoints(const std::list &rsPointList) +void Approximation::AddPoints(const std::list &points) { - std::list::const_iterator cIt; - for (cIt = rsPointList.begin(); cIt != rsPointList.end(); ++cIt) - _vPoints.push_back(*cIt); + std::copy(points.begin(), points.end(), _vPoints.end()); _bIsFitted = false; } @@ -158,22 +143,22 @@ float PlaneFit::Fit() return FLOAT_MAX; double sxx,sxy,sxz,syy,syz,szz,mx,my,mz; - sxx=sxy=sxz=syy=syz=szz=mx=my=mz=0.0f; + sxx=sxy=sxz=syy=syz=szz=mx=my=mz=0.0; for (std::list::iterator it = _vPoints.begin(); it!=_vPoints.end(); ++it) { - sxx += it->x * it->x; sxy += it->x * it->y; - sxz += it->x * it->z; syy += it->y * it->y; - syz += it->y * it->z; szz += it->z * it->z; - mx += it->x; my += it->y; mz += it->z; + sxx += double(it->x * it->x); sxy += double(it->x * it->y); + sxz += double(it->x * it->z); syy += double(it->y * it->y); + syz += double(it->y * it->z); szz += double(it->z * it->z); + mx += double(it->x); my += double(it->y); mz += double(it->z); } - unsigned int nSize = _vPoints.size(); - sxx = sxx - mx*mx/((double)nSize); - sxy = sxy - mx*my/((double)nSize); - sxz = sxz - mx*mz/((double)nSize); - syy = syy - my*my/((double)nSize); - syz = syz - my*mz/((double)nSize); - szz = szz - mz*mz/((double)nSize); + size_t nSize = _vPoints.size(); + sxx = sxx - mx*mx/(double(nSize)); + sxy = sxy - mx*my/(double(nSize)); + sxz = sxz - mx*mz/(double(nSize)); + syy = syy - my*my/(double(nSize)); + syz = syz - my*mz/(double(nSize)); + szz = szz - mz*mz/(double(nSize)); #if defined(FC_USE_EIGEN) Eigen::Matrix3d covMat = Eigen::Matrix3d::Zero(); @@ -225,11 +210,11 @@ float PlaneFit::Fit() return FLOAT_MAX; } - _vDirU.Set((float)U.X(), (float)U.Y(), (float)U.Z()); - _vDirV.Set((float)V.X(), (float)V.Y(), (float)V.Z()); - _vDirW.Set((float)W.X(), (float)W.Y(), (float)W.Z()); - _vBase.Set((float)(mx/nSize), (float)(my/nSize), (float)(mz/nSize)); - float sigma = (float)W.Dot(akMat * W); + _vDirU.Set(float(U.X()), float(U.Y()), float(U.Z())); + _vDirV.Set(float(V.X()), float(V.Y()), float(V.Z())); + _vDirW.Set(float(W.X()), float(W.Y()), float(W.Z())); + _vBase.Set(float(mx/nSize), float(my/nSize), float(mz/nSize)); + float sigma = float(W.Dot(akMat * W)); #endif // In case sigma is nan @@ -309,7 +294,7 @@ float PlaneFit::GetStdDeviation() const float fSumXi = 0.0f, fSumXi2 = 0.0f, fMean = 0.0f, fDist = 0.0f; - float ulPtCt = (float)CountPoints(); + float ulPtCt = float(CountPoints()); std::list< Base::Vector3f >::const_iterator cIt; for (cIt = _vPoints.begin(); cIt != _vPoints.end(); ++cIt) { @@ -319,7 +304,7 @@ float PlaneFit::GetStdDeviation() const } fMean = (1.0f / ulPtCt) * fSumXi; - return (float)sqrt((ulPtCt / (ulPtCt - 3.0)) * ((1.0 / ulPtCt) * fSumXi2 - fMean * fMean)); + return sqrt((ulPtCt / (ulPtCt - 3.0f)) * ((1.0f / ulPtCt) * fSumXi2 - fMean * fMean)); } float PlaneFit::GetSignedStdDeviation() const @@ -335,7 +320,7 @@ float PlaneFit::GetSignedStdDeviation() const float fMinDist = FLOAT_MAX; float fFactor; - float ulPtCt = (float)CountPoints(); + float ulPtCt = float(CountPoints()); Base::Vector3f clGravity, clPt; std::list::const_iterator cIt; for (cIt = _vPoints.begin(); cIt != _vPoints.end(); ++cIt) @@ -360,7 +345,7 @@ float PlaneFit::GetSignedStdDeviation() const fMean = 1.0f / ulPtCt * fSumXi; - return fFactor * (float)sqrt((ulPtCt / (ulPtCt - 3.0)) * ((1.0 / ulPtCt) * fSumXi2 - fMean * fMean)); + return fFactor * sqrt((ulPtCt / (ulPtCt - 3.0f)) * ((1.0f / ulPtCt) * fSumXi2 - fMean * fMean)); } void PlaneFit::ProjectToPlane () @@ -397,14 +382,14 @@ std::vector PlaneFit::GetLocalPoints() const { std::vector localPoints; if (_bIsFitted && _fLastResult < FLOAT_MAX) { - Base::Vector3d bs(this->_vBase.x,this->_vBase.y,this->_vBase.z); - Base::Vector3d ex(this->_vDirU.x,this->_vDirU.y,this->_vDirU.z); - Base::Vector3d ey(this->_vDirV.x,this->_vDirV.y,this->_vDirV.z); - Base::Vector3d ez(this->_vDirW.x,this->_vDirW.y,this->_vDirW.z); + Base::Vector3d bs = Base::convertTo(this->_vBase); + Base::Vector3d ex = Base::convertTo(this->_vDirU); + Base::Vector3d ey = Base::convertTo(this->_vDirV); + //Base::Vector3d ez = Base::convertTo(this->_vDirW); localPoints.insert(localPoints.begin(), _vPoints.begin(), _vPoints.end()); for (std::vector::iterator it = localPoints.begin(); it != localPoints.end(); ++it) { - Base::Vector3d clPoint(it->x,it->y,it->z); + Base::Vector3d clPoint = Base::convertTo(*it); clPoint.TransformToCoordinateSystem(bs, ex, ey); it->Set(static_cast(clPoint.x), static_cast(clPoint.y), static_cast(clPoint.z)); } @@ -427,9 +412,9 @@ bool QuadraticFit::GetCurvatureInfo(double x, double y, double z, FunctionContainer clFuncCont( _fCoeff ); bResult = clFuncCont.CurvatureInfo( x, y, z, rfCurv0, rfCurv1, Dir0, Dir1, dDistance ); - dDistance = clFuncCont.GetGradient( x, y, z ).Length(); - Convert( Dir0, rkDir0 ); - Convert( Dir1, rkDir1 ); + dDistance = double(clFuncCont.GetGradient( x, y, z ).Length()); + rkDir0 = Base::convertTo(Dir0); + rkDir1 = Base::convertTo(Dir1); } return bResult; @@ -459,7 +444,7 @@ double QuadraticFit::GetCoeff(unsigned long ulIndex) const if( _bIsFitted ) return _fCoeff[ ulIndex ]; else - return FLOAT_MAX; + return double(FLOAT_MAX); } float QuadraticFit::Fit() @@ -504,9 +489,9 @@ void QuadraticFit::CalcEigenValues(double &dLambda1, double &dLambda2, double &d * */ - Wm4::Matrix3 akMat(_fCoeff[4], _fCoeff[7]/2.0f, _fCoeff[8]/2.0f, - _fCoeff[7]/2.0f, _fCoeff[5], _fCoeff[9]/2.0f, - _fCoeff[8]/2.0f, _fCoeff[9]/2.0f, _fCoeff[6] ); + Wm4::Matrix3 akMat(_fCoeff[4], _fCoeff[7]/2.0, _fCoeff[8]/2.0, + _fCoeff[7]/2.0, _fCoeff[5], _fCoeff[9]/2.0, + _fCoeff[8]/2.0, _fCoeff[9]/2.0, _fCoeff[6] ); Wm4::Matrix3 rkRot, rkDiag; akMat.EigenDecomposition( rkRot, rkDiag ); @@ -515,9 +500,9 @@ void QuadraticFit::CalcEigenValues(double &dLambda1, double &dLambda2, double &d Wm4::Vector3 vEigenV = rkRot.GetColumn(1); Wm4::Vector3 vEigenW = rkRot.GetColumn(2); - Convert( vEigenU, clEV1 ); - Convert( vEigenV, clEV2 ); - Convert( vEigenW, clEV3 ); + clEV1 = Base::convertTo(vEigenU); + clEV2 = Base::convertTo(vEigenV); + clEV3 = Base::convertTo(vEigenW); dLambda1 = rkDiag[0][0]; dLambda2 = rkDiag[1][1]; @@ -534,14 +519,14 @@ void QuadraticFit::CalcZValues( double x, double y, double &dZ1, double &dZ2 ) c 4*_fCoeff[6]*_fCoeff[7]*x*y-4*_fCoeff[6]*_fCoeff[4]*x*x-4*_fCoeff[6]*_fCoeff[5]*y*y; if (fabs( _fCoeff[6] ) < 0.000005) { - dZ1 = FLOAT_MAX; - dZ2 = FLOAT_MAX; + dZ1 = double(FLOAT_MAX); + dZ2 = double(FLOAT_MAX); return; } - if (dDisk < 0.0f) { - dZ1 = FLOAT_MAX; - dZ2 = FLOAT_MAX; + if (dDisk < 0.0) { + dZ1 = double(FLOAT_MAX); + dZ2 = double(FLOAT_MAX); return; } else @@ -556,16 +541,16 @@ void QuadraticFit::CalcZValues( double x, double y, double &dZ1, double &dZ2 ) c SurfaceFit::SurfaceFit() : PlaneFit() { - _fCoeff[0] = 0.0f; - _fCoeff[1] = 0.0f; - _fCoeff[2] = 0.0f; - _fCoeff[3] = 0.0f; - _fCoeff[4] = 0.0f; - _fCoeff[5] = 0.0f; - _fCoeff[6] = 0.0f; - _fCoeff[7] = 0.0f; - _fCoeff[8] = 0.0f; - _fCoeff[9] = 0.0f; + _fCoeff[0] = 0.0; + _fCoeff[1] = 0.0; + _fCoeff[2] = 0.0; + _fCoeff[3] = 0.0; + _fCoeff[4] = 0.0; + _fCoeff[5] = 0.0; + _fCoeff[6] = 0.0; + _fCoeff[7] = 0.0; + _fCoeff[8] = 0.0; + _fCoeff[9] = 0.0; } float SurfaceFit::Fit() @@ -573,7 +558,7 @@ float SurfaceFit::Fit() float fResult = FLOAT_MAX; if (CountPoints() > 0) { - fResult = (float) PolynomFit(); + fResult = float(PolynomFit()); _fLastResult = fResult; _bIsFitted = true; @@ -592,9 +577,9 @@ bool SurfaceFit::GetCurvatureInfo(double x, double y, double z, double &rfCurv0, FunctionContainer clFuncCont( _fCoeff ); bResult = clFuncCont.CurvatureInfo( x, y, z, rfCurv0, rfCurv1, Dir0, Dir1, dDistance ); - dDistance = clFuncCont.GetGradient( x, y, z ).Length(); - Convert( Dir0, rkDir0 ); - Convert( Dir1, rkDir1 ); + dDistance = double(clFuncCont.GetGradient( x, y, z ).Length()); + rkDir0 = Base::convertTo(Dir0); + rkDir1 = Base::convertTo(Dir1); } return bResult; @@ -615,13 +600,13 @@ bool SurfaceFit::GetCurvatureInfo(double x, double y, double z, double &rfCurv0, double SurfaceFit::PolynomFit() { - if (PlaneFit::Fit() == FLOAT_MAX) - return FLOAT_MAX; + if (PlaneFit::Fit() >= FLOAT_MAX) + return double(FLOAT_MAX); - Base::Vector3d bs(this->_vBase.x,this->_vBase.y,this->_vBase.z); - Base::Vector3d ex(this->_vDirU.x,this->_vDirU.y,this->_vDirU.z); - Base::Vector3d ey(this->_vDirV.x,this->_vDirV.y,this->_vDirV.z); - Base::Vector3d ez(this->_vDirW.x,this->_vDirW.y,this->_vDirW.z); + Base::Vector3d bs = Base::convertTo(this->_vBase); + Base::Vector3d ex = Base::convertTo(this->_vDirU); + Base::Vector3d ey = Base::convertTo(this->_vDirV); + //Base::Vector3d ez = Base::convertTo(this->_vDirW); // A*x = b // See also www.cs.jhu.edu/~misha/Fall05/10.23.05.pdf @@ -648,7 +633,7 @@ double SurfaceFit::PolynomFit() double dW2 = 0; for (std::list::const_iterator it = _vPoints.begin(); it != _vPoints.end(); ++it) { - Base::Vector3d clPoint(it->x,it->y,it->z); + Base::Vector3d clPoint = Base::convertTo(*it); clPoint.TransformToCoordinateSystem(bs, ex, ey); transform.push_back(clPoint); double dU = clPoint.x; @@ -772,7 +757,7 @@ double SurfaceFit::PolynomFit() sigma = sqrt(sigma/_vPoints.size()); _fLastResult = static_cast(sigma); - return _fLastResult; + return double(_fLastResult); } double SurfaceFit::Value(double x, double y) const @@ -862,7 +847,7 @@ float CylinderFit::GetStdDeviation() const float fSumXi = 0.0f, fSumXi2 = 0.0f, fMean = 0.0f, fDist = 0.0f; - float ulPtCt = (float)CountPoints(); + float ulPtCt = float(CountPoints()); std::list< Base::Vector3f >::const_iterator cIt; for (cIt = _vPoints.begin(); cIt != _vPoints.end(); ++cIt) { @@ -872,7 +857,7 @@ float CylinderFit::GetStdDeviation() const } fMean = (1.0f / ulPtCt) * fSumXi; - return (float)sqrt((ulPtCt / (ulPtCt - 3.0)) * ((1.0 / ulPtCt) * fSumXi2 - fMean * fMean)); + return sqrt((ulPtCt / (ulPtCt - 3.0f)) * ((1.0f / ulPtCt) * fSumXi2 - fMean * fMean)); } void CylinderFit::ProjectToCylinder() @@ -894,9 +879,9 @@ void CylinderFit::ProjectToCylinder() // any direction perpendicular to the cylinder axis Base::Vector3f cMov(cPnt); do { - float x = ((float)rand() / (float)RAND_MAX); - float y = ((float)rand() / (float)RAND_MAX); - float z = ((float)rand() / (float)RAND_MAX); + float x = (float(rand()) / float(RAND_MAX)); + float y = (float(rand()) / float(RAND_MAX)); + float z = (float(rand()) / float(RAND_MAX)); cMov.Move(x,y,z); } while (cMov.DistanceToLine(cBase, cAxis) == 0); @@ -984,7 +969,7 @@ float PolynomialFit::Fit() } try { - float* coeff = Wm4::PolyFit3(_vPoints.size(), &(x[0]), &(y[0]), &(z[0]), 2 , 2); + float* coeff = Wm4::PolyFit3(_vPoints.size(), &(x[0]), &(y[0]), &(z[0]), 2, 2); for (int i=0; i<9; i++) _fCoeff[i] = coeff[i]; } diff --git a/src/Mod/Mesh/App/Core/Approximation.h b/src/Mod/Mesh/App/Core/Approximation.h index f494abce8d..9ce2911593 100644 --- a/src/Mod/Mesh/App/Core/Approximation.h +++ b/src/Mod/Mesh/App/Core/Approximation.h @@ -159,14 +159,6 @@ public: bool Done() const; protected: - /** - * Converts point from Wm4::Vector3 to Base::Vector3f. - */ - static void Convert( const Wm4::Vector3&, Base::Vector3f&); - /** - * Converts point from Base::Vector3f to Wm4::Vector3. - */ - static void Convert( const Base::Vector3f&, Wm4::Vector3&); /** * Creates a vector of Wm4::Vector3 elements. */ diff --git a/src/Mod/Mesh/App/Core/Builder.cpp b/src/Mod/Mesh/App/Core/Builder.cpp index ec7f82e5e3..02e6174f3c 100644 --- a/src/Mod/Mesh/App/Core/Builder.cpp +++ b/src/Mod/Mesh/App/Core/Builder.cpp @@ -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(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(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 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::size_type size_type; QVector& 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 indices(ulCtPts); - size_t vertex_count = 0; + size_type vertex_count = 0; for (QVector::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(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(ulCt)); + for (size_type i=0; i < ulCt; ++i) { + rFacets[static_cast(i)]._aulPoints[0] = indices[3*i]; + rFacets[static_cast(i)]._aulPoints[1] = indices[3*i + 1]; + rFacets[static_cast(i)]._aulPoints[2] = indices[3*i + 2]; } verts.resize(vertex_count); MeshPointArray rPoints; - rPoints.reserve(vertex_count); + rPoints.reserve(static_cast(vertex_count)); for (QVector::iterator v = verts.begin(); v != verts.end(); ++v) { rPoints.push_back(MeshPoint(v->x, v->y, v->z)); } diff --git a/src/Mod/Mesh/App/Core/Builder.h b/src/Mod/Mesh/App/Core/Builder.h index e308b80693..65d24649d1 100644 --- a/src/Mod/Mesh/App/Core/Builder.h +++ b/src/Mod/Mesh/App/Core/Builder.h @@ -105,7 +105,7 @@ private: // keep an array of iterators pointing to the vertex inside the set to save memory typedef std::pair::iterator, bool> MeshPointIterator; std::vector _pointsIterator; - unsigned long _ptIdx; + size_t _ptIdx; void SetNeighbourhood (); // As it's forbidden to insert a degenerated facet but insert its vertices anyway we must remove them @@ -128,7 +128,7 @@ public: * AddFacet(), otherwise you'll possibly run into wastage of memory * and performance problems. */ - void Initialize (unsigned long ctFacets, bool deletion = true); + void Initialize (size_t ctFacets, bool deletion = true); /** adding facets */ /** Add new facet @@ -187,13 +187,14 @@ private: MeshKernel& _meshKernel; public: + typedef int size_type; MeshFastBuilder(MeshKernel &rclM); ~MeshFastBuilder(void); /** Initializes the class. Must be done before adding facets * @param ctFacets count of facets. */ - void Initialize (unsigned long ctFacets); + void Initialize (size_type ctFacets); /** Add new facet */ void AddFacet (const Base::Vector3f* facetPoints); diff --git a/src/Mod/Mesh/App/Core/Elements.cpp b/src/Mod/Mesh/App/Core/Elements.cpp index 93f9e3dad0..3bd4a14f5a 100644 --- a/src/Mod/Mesh/App/Core/Elements.cpp +++ b/src/Mod/Mesh/App/Core/Elements.cpp @@ -34,6 +34,7 @@ #include "Elements.h" #include "Algorithm.h" #include "tritritest.h" +#include "Utilities.h" using namespace MeshCore; using namespace Wm4; @@ -526,9 +527,9 @@ bool MeshGeomFacet::IsDegenerated(float epsilon) const // (u*u)*(v*v)-(u*v)*(u*v) < max(eps*(u*u),eps*(v*v)). // // BTW (u*u)*(v*v)-(u*v)*(u*v) is the same as (uxv)*(uxv). - Base::Vector3d p1(this->_aclPoints[0].x,this->_aclPoints[0].y,this->_aclPoints[0].z); - Base::Vector3d p2(this->_aclPoints[1].x,this->_aclPoints[1].y,this->_aclPoints[1].z); - Base::Vector3d p3(this->_aclPoints[2].x,this->_aclPoints[2].y,this->_aclPoints[2].z); + Base::Vector3d p1 = Base::convertTo(this->_aclPoints[0]); + Base::Vector3d p2 = Base::convertTo(this->_aclPoints[1]); + Base::Vector3d p3 = Base::convertTo(this->_aclPoints[2]); Base::Vector3d u = p2 - p1; Base::Vector3d v = p3 - p1; @@ -1012,10 +1013,10 @@ int MeshGeomFacet::IntersectWithFacet (const MeshGeomFacet& rclFacet, bool MeshGeomFacet::IsPointOf (const Base::Vector3f &P) const { - Base::Vector3d p1(this->_aclPoints[0].x,this->_aclPoints[0].y,this->_aclPoints[0].z); - Base::Vector3d p2(this->_aclPoints[1].x,this->_aclPoints[1].y,this->_aclPoints[1].z); - Base::Vector3d p3(this->_aclPoints[2].x,this->_aclPoints[2].y,this->_aclPoints[2].z); - Base::Vector3d p4(P.x,P.y,P.z); + Base::Vector3d p1 = Base::convertTo(this->_aclPoints[0]); + Base::Vector3d p2 = Base::convertTo(this->_aclPoints[1]); + Base::Vector3d p3 = Base::convertTo(this->_aclPoints[2]); + Base::Vector3d p4 = Base::convertTo(P); Base::Vector3d u = p2 - p1; Base::Vector3d v = p3 - p1; diff --git a/src/Mod/Mesh/App/Core/Triangulation.cpp b/src/Mod/Mesh/App/Core/Triangulation.cpp index 774845e102..f286130ca1 100644 --- a/src/Mod/Mesh/App/Core/Triangulation.cpp +++ b/src/Mod/Mesh/App/Core/Triangulation.cpp @@ -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(ex.x); + rInverse[0][1] = static_cast(ey.x); + rInverse[0][2] = static_cast(ez.x); + rInverse[0][3] = static_cast(bs.x); + + rInverse[1][0] = static_cast(ex.y); + rInverse[1][1] = static_cast(ey.y); + rInverse[1][2] = static_cast(ez.y); + rInverse[1][3] = static_cast(bs.y); + + rInverse[2][0] = static_cast(ex.z); + rInverse[2][1] = static_cast(ey.z); + rInverse[2][2] = static_cast(ez.z); + rInverse[2][3] = static_cast(bs.z); return rInverse; } @@ -165,9 +176,15 @@ std::vector AbstractPolygonTriangulator::ProjectToFitPlane() { std::vector 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(_inverse[0][3]), + static_cast(_inverse[1][3]), + static_cast(_inverse[2][3])); + Base::Vector3f ex(static_cast(_inverse[0][0]), + static_cast(_inverse[1][0]), + static_cast(_inverse[2][0])); + Base::Vector3f ey(static_cast(_inverse[0][1]), + static_cast(_inverse[1][1]), + static_cast(_inverse[2][1])); for (std::vector::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(_inverse[0][3]), + static_cast(_inverse[1][3]), + static_cast(_inverse[2][3])); + Base::Vector3f ex(static_cast(_inverse[0][0]), + static_cast(_inverse[1][0]), + static_cast(_inverse[2][0])); + Base::Vector3f ey(static_cast(_inverse[0][1]), + static_cast(_inverse[1][1]), + static_cast(_inverse[2][1])); for (std::vector::const_iterator it = points.begin(); it != points.end(); ++it) { Base::Vector3f pt = *it; @@ -192,7 +215,7 @@ void AbstractPolygonTriangulator::PostProcessing(const std::vector= uMinPts && polyFit.Fit() < FLOAT_MAX) { for (std::vector::iterator pt = _newpoints.begin(); pt != _newpoints.end(); ++pt) - pt->z = (float)polyFit.Value(pt->x, pt->y); + pt->z = static_cast(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 @@ -625,13 +648,13 @@ bool DelaunayTriangulator::Triangulate() std::vector akVertex; akVertex.reserve(_points.size()); for (std::vector::iterator it = _points.begin(); it != _points.end(); ++it) { - akVertex.push_back(Wm4::Vector2d(it->x, it->y)); + akVertex.push_back(Wm4::Vector2d(static_cast(it->x), static_cast(it->y))); } - Wm4::Delaunay2d del(akVertex.size(), &(akVertex[0]), 0.001, false, Wm4::Query::QT_INT64); + Wm4::Delaunay2d del(static_cast(akVertex.size()), &(akVertex[0]), 0.001, false, Wm4::Query::QT_INT64); int iTQuantity = del.GetSimplexQuantity(); - std::vector aiTVertex(3*iTQuantity); - size_t uiSize = 3*iTQuantity*sizeof(int); + std::vector aiTVertex(static_cast(3*iTQuantity)); + size_t uiSize = static_cast(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(aiTVertex[static_cast(3*i+j)]); + facet._aulPoints[j] = static_cast(index); + triangle._aclPoints[j].x = static_cast(akVertex[index].X()); + triangle._aclPoints[j].y = static_cast(akVertex[index].Y()); } _triangles.push_back(triangle); diff --git a/src/Mod/Mesh/App/Core/Trim.cpp b/src/Mod/Mesh/App/Core/Trim.cpp index b4f00b73ce..e08fa463ad 100644 --- a/src/Mod/Mesh/App/Core/Trim.cpp +++ b/src/Mod/Mesh/App/Core/Trim.cpp @@ -103,7 +103,7 @@ void MeshTrimming::CheckFacets(const MeshFacetGrid& rclGrid, std::vector(A.x*B.y+A.y*C.x+B.x*C.y-(B.y*C.x+A.y*B.x+A.x*C.y)); for (unsigned long j=0; j calculate the corresponding 3d-point if (clFacPoly.Contains(myPoly[j])) { P = myPoly[j]; - fDetPAC = (float)(A.x*P.y+A.y*C.x+P.x*C.y-(P.y*C.x+A.y*P.x+A.x*C.y)); - fDetPBC = (float)(P.x*B.y+P.y*C.x+B.x*C.y-(B.y*C.x+P.y*B.x+P.x*C.y)); - fDetPAB = (float)(A.x*B.y+A.y*P.x+B.x*P.y-(B.y*P.x+A.y*B.x+A.x*P.y)); + fDetPAC = static_cast(A.x*P.y+A.y*C.x+P.x*C.y-(P.y*C.x+A.y*P.x+A.x*C.y)); + fDetPBC = static_cast(P.x*B.y+P.y*C.x+B.x*C.y-(B.y*C.x+P.y*B.x+P.x*C.y)); + fDetPAB = static_cast(A.x*B.y+A.y*P.x+B.x*P.y-(B.y*P.x+A.y*B.x+A.x*P.y)); u = fDetPBC / fDetABC; v = fDetPAC / fDetABC; w = fDetPAB / fDetABC; // point is on edge or no valid convex combination - if (u == 0.0f || v == 0.0f || w == 0.0f || fabs(u+v+w-1.0f) >= 0.001) + if (u == 0.0f || v == 0.0f || w == 0.0f || fabs(u+v+w-1.0f) >= 0.001f) return false; // 3d point clPoint = u*rclFacet._aclPoints[0]+v*rclFacet._aclPoints[1]+w*rclFacet._aclPoints[2]; @@ -223,23 +223,23 @@ bool MeshTrimming::GetIntersectionPointsOfPolygonAndFacet(unsigned long ulIndex, clFacLine.clV1 = P1; clFacLine.clV2 = P2; - if (clPolyLine.Intersect(P1, MESH_MIN_PT_DIST)) { + if (clPolyLine.Intersect(P1, double(MESH_MIN_PT_DIST))) { // do not pick up corner points iIntersections++; } - else if (clPolyLine.Intersect(P2, MESH_MIN_PT_DIST)) { + else if (clPolyLine.Intersect(P2, double(MESH_MIN_PT_DIST))) { // do not pick up corner points iIntersections++; } else if (clPolyLine.Intersect(clFacLine, S)) { bool bPushBack=true; - float fP1P2 = (float)(P2-P1).Length(); - float fSP1 = (float)(P1-S).Length(); - float fSP2 = (float)(P2-S).Length(); + float fP1P2 = static_cast((P2-P1).Length()); + float fSP1 = static_cast((P1-S).Length()); + float fSP2 = static_cast((P2-S).Length()); - float fP3P4 = (float)(P4-P3).Length(); - float fSP3 = (float)(P3-S).Length(); - float fSP4 = (float)(P4-S).Length(); + float fP3P4 = static_cast((P4-P3).Length()); + float fSP3 = static_cast((P3-S).Length()); + float fSP4 = static_cast((P4-S).Length()); // compute proportion of length float l = fSP1 / fP1P2; float m = fSP2 / fP1P2; @@ -248,7 +248,7 @@ bool MeshTrimming::GetIntersectionPointsOfPolygonAndFacet(unsigned long ulIndex, float s = fSP4 / fP3P4; // is intersection point convex combination? - if ((fabs(l+m-1.0f) < 0.001) && (fabs(r+s-1.0f) < 0.001)) { + if ((fabs(l+m-1.0f) < 0.001f) && (fabs(r+s-1.0f) < 0.001f)) { Base::Vector3f clIntersection(m*clFac._aclPoints[j]+l*clFac._aclPoints[(j+1)%3]); iIntersections++; @@ -353,7 +353,7 @@ bool MeshTrimming::CreateFacets(unsigned long ulFacetPos, int iSide, const std:: for (int i=0; i<3; i++) { clFacPnt = (*myProj)(myMesh._aclPointArray[facet._aulPoints[i]]); clProjPnt = Base::Vector2d(clFacPnt.x, clFacPnt.y); - if (myPoly.Intersect(clProjPnt, MESH_MIN_PT_DIST)) + if (myPoly.Intersect(clProjPnt, double(MESH_MIN_PT_DIST))) ++iCtPtsOn; else if (myPoly.Contains(clProjPnt) == myInner) ++iCtPtsIn; @@ -380,7 +380,7 @@ bool MeshTrimming::CreateFacets(unsigned long ulFacetPos, int iSide, const std:: clFacLine.clV1 = P1; clFacLine.clV2 = P2; - if (clFacLine.Intersect(P, MESH_MIN_PT_DIST)) { + if (clFacLine.Intersect(P, double(MESH_MIN_PT_DIST))) { if (myPoly.Contains(P1) == myInner) { MeshGeomFacet clNew; clNew._aclPoints[0] = raclPoints[0]; diff --git a/src/Mod/Mesh/App/Core/Utilities.h b/src/Mod/Mesh/App/Core/Utilities.h new file mode 100644 index 0000000000..0ed6f838d1 --- /dev/null +++ b/src/Mod/Mesh/App/Core/Utilities.h @@ -0,0 +1,58 @@ +/*************************************************************************** + * Copyright (c) 2019 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef MESH_UTILITIES_H +#define MESH_UTILITIES_H + +#include +#include + +namespace Base { +// Specialization for Wm4::Vector3d +template <> +struct vec_traits { + typedef Wm4::Vector3d vec_type; + typedef double float_type; + vec_traits(const vec_type& v) : v(v){} + inline std::tuple get() const { + return std::make_tuple(v.X(), v.Y(), v.Z()); + } +private: + const vec_type& v; +}; +// Specialization for Wm4::Vector3f +template <> +struct vec_traits { + typedef Wm4::Vector3f vec_type; + typedef float float_type; + vec_traits(const vec_type& v) : v(v){} + inline std::tuple get() const { + return std::make_tuple(v.X(), v.Y(), v.Z()); + } +private: + const vec_type& v; +}; +} + + +#endif // MESH_UTILITIES_H