Skip to content

Commit

Permalink
avoid several implicit conversions, replace several old C-casts, othe…
Browse files Browse the repository at this point in the history
…r minor changes
  • Loading branch information
wwmayer committed Sep 18, 2019
1 parent 2e5e340 commit 5a83dc2
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 74 deletions.
30 changes: 16 additions & 14 deletions src/Mod/Mesh/App/Core/Approximation.h
Expand Up @@ -267,7 +267,7 @@ class MeshExport QuadraticFit : public Approximation
/**
* Destruction
*/
virtual ~QuadraticFit(){};
virtual ~QuadraticFit(){}
/**
* Get the quadric coefficients
* @param ulIndex Number of coefficient (0..9)
Expand Down Expand Up @@ -515,7 +515,9 @@ class FunctionContainer
Base::Vector3f GetGradient( double x, double y, double z ) const
{
Wm4::Vector3<double> grad = pImplSurf->GetGradient( Wm4::Vector3<double>(x, y, z) );
return Base::Vector3f( (float)grad.X(), (float)grad.Y(), (float)grad.Z() );
return Base::Vector3f(static_cast<float>(grad.X()),
static_cast<float>(grad.Y()),
static_cast<float>(grad.Z()));
}

Base::Matrix4D GetHessian( double x, double y, double z ) const
Expand All @@ -535,16 +537,16 @@ class FunctionContainer
double zx = - ( Fx(x,y,z) / dQuot );
double zy = - ( Fy(x,y,z) / dQuot );

double zxx = - ( 2.0f * ( dKoeff[5] + dKoeff[6] * zx * zx + dKoeff[8] * zx ) ) / dQuot;
double zyy = - ( 2.0f * ( dKoeff[5] + dKoeff[6] * zy * zy + dKoeff[9] * zy ) ) / dQuot;
double zxx = - ( 2.0 * ( dKoeff[5] + dKoeff[6] * zx * zx + dKoeff[8] * zx ) ) / dQuot;
double zyy = - ( 2.0 * ( dKoeff[5] + dKoeff[6] * zy * zy + dKoeff[9] * zy ) ) / dQuot;
double zxy = - ( dKoeff[6] * zx * zy + dKoeff[7] + dKoeff[8] * zy + dKoeff[9] * zx ) / dQuot;

double dNen = 1 + zx*zx + zy*zy;
double dNenSqrt = (double)sqrt( dNen );
double dNenSqrt = sqrt( dNen );
double K = ( zxx * zyy - zxy * zxy ) / ( dNen * dNen );
double H = 0.5f * ( ( 1.0f+zx*zx - 2*zx*zy*zxy + (1.0f+zy*zy)*zxx ) / ( dNenSqrt * dNenSqrt * dNenSqrt ) ) ;
double H = 0.5 * ( ( 1.0+zx*zx - 2*zx*zy*zxy + (1.0+zy*zy)*zxx ) / ( dNenSqrt * dNenSqrt * dNenSqrt ) ) ;

double dDiscr = (double)sqrt(fabs(H*H-K));
double dDiscr = sqrt(fabs(H*H-K));
rfCurv0 = H - dDiscr;
rfCurv1 = H + dDiscr;

Expand All @@ -562,22 +564,22 @@ class FunctionContainer
//+++++++++ 1. derivations ++++++++++++++++++++++++++++++++
double Fx ( double x, double y, double z )
{
return( dKoeff[1] + 2.0f*dKoeff[4]*x + dKoeff[7]*y + dKoeff[8]*z );
return( dKoeff[1] + 2.0*dKoeff[4]*x + dKoeff[7]*y + dKoeff[8]*z );
}
double Fy ( double x, double y, double z )
{
return( dKoeff[2] + 2.0f*dKoeff[5]*y + dKoeff[7]*x + dKoeff[9]*z );
return( dKoeff[2] + 2.0*dKoeff[5]*y + dKoeff[7]*x + dKoeff[9]*z );
}
double Fz ( double x, double y, double z )
{
return( dKoeff[3] + 2.0f*dKoeff[6]*z + dKoeff[8]*x + dKoeff[9]*y );
return( dKoeff[3] + 2.0*dKoeff[6]*z + dKoeff[8]*x + dKoeff[9]*y );
}

//+++++++++ 2. derivations ++++++++++++++++++++++++++++++++
double Fxx( double x, double y, double z )
{
(void)x; (void)y; (void)z;
return( 2.0f*dKoeff[4] );
return( 2.0*dKoeff[4] );
}
double Fxy( double x, double y, double z )
{
Expand All @@ -592,7 +594,7 @@ class FunctionContainer
double Fyy( double x, double y, double z )
{
(void)x; (void)y; (void)z;
return( 2.0f*dKoeff[5] );
return( 2.0*dKoeff[5] );
}
double Fyz( double x, double y, double z )
{
Expand All @@ -602,7 +604,7 @@ class FunctionContainer
double Fzz( double x, double y, double z )
{
(void)x; (void)y; (void)z;
return( 2.0f*dKoeff[6] );
return( 2.0*dKoeff[6] );
}

protected:
Expand All @@ -613,7 +615,7 @@ class FunctionContainer
/**
* Private construction.
*/
FunctionContainer(){};
FunctionContainer(){}
};

class MeshExport PolynomialFit : public Approximation
Expand Down
29 changes: 19 additions & 10 deletions src/Mod/Mesh/App/Core/Elements.cpp
Expand Up @@ -533,7 +533,7 @@ bool MeshGeomFacet::IsDegenerated(float epsilon) const
Base::Vector3d u = p2 - p1;
Base::Vector3d v = p3 - p1;

double eps = epsilon;
double eps = static_cast<double>(epsilon);
double uu = u*u;
if (uu <= eps)
return true;
Expand Down Expand Up @@ -991,15 +991,15 @@ int MeshGeomFacet::IntersectWithFacet (const MeshGeomFacet& rclFacet,
// Note: The algorithm delivers sometimes false-positives, i.e. it claims
// that the two triangles intersect but they don't. It seems that this bad
// behaviour occurs if the triangles are nearly co-planar
float mult = (float)fabs(this->GetNormal() * rclFacet.GetNormal());
float mult = fabs(this->GetNormal() * rclFacet.GetNormal());
if (rclPt0 == rclPt1) {
if (mult < 0.995) // not co-planar, thus no test needed
if (mult < 0.995f) // not co-planar, thus no test needed
return 1;
if (this->IsPointOf(rclPt0) && rclFacet.IsPointOf(rclPt0))
return 1;
}
else {
if (mult < 0.995) // not co-planar, thus no test needed
if (mult < 0.995f) // not co-planar, thus no test needed
return 2;
if (this->IsPointOf(rclPt0) && rclFacet.IsPointOf(rclPt0) &&
this->IsPointOf(rclPt1) && rclFacet.IsPointOf(rclPt1))
Expand Down Expand Up @@ -1085,9 +1085,9 @@ float MeshGeomFacet::CenterOfCircumCircle(Base::Vector3f& rclCenter) const
float vw = - (v * w);
float uw = - (w * u);

float w0 = (float)(2 * sqrt(uu * ww - uw * uw) * uw / (uu * ww));
float w1 = (float)(2 * sqrt(uu * vv - uv * uv) * uv / (uu * vv));
float w2 = (float)(2 * sqrt(vv * ww - vw * vw) * vw / (vv * ww));
float w0 = static_cast<float>(2 * sqrt(uu * ww - uw * uw) * uw / (uu * ww));
float w1 = static_cast<float>(2 * sqrt(uu * vv - uv * uv) * uv / (uu * vv));
float w2 = static_cast<float>(2 * sqrt(vv * ww - vw * vw) * vw / (vv * ww));

// center of the circle
float wx = w0 + w1 + w2;
Expand All @@ -1096,7 +1096,7 @@ float MeshGeomFacet::CenterOfCircumCircle(Base::Vector3f& rclCenter) const
rclCenter.z = (w0*p0.z + w1*p1.z + w2*p2.z)/wx;

// radius of the circle
float fRadius = (float)(sqrt(uu * vv * ww) / (4 * Area()));
float fRadius = static_cast<float>(sqrt(uu * vv * ww) / (4 * Area()));

return fRadius;
}
Expand Down Expand Up @@ -1378,10 +1378,19 @@ float MeshGeomFacet::AspectRatio2() const
float MeshGeomFacet::Roundness() const
{
const double FOUR_ROOT3 = 6.928203230275509;
double area = Area();
double area = static_cast<double>(Area());
Base::Vector3f d0 = _aclPoints[0] - _aclPoints[1];
Base::Vector3f d1 = _aclPoints[1] - _aclPoints[2];
Base::Vector3f d2 = _aclPoints[2] - _aclPoints[0];

return (float) (FOUR_ROOT3 * area / (d0.Sqr() + d1.Sqr() + d2.Sqr()));
double sum = static_cast<double>(d0.Sqr() + d1.Sqr() + d2.Sqr());
return static_cast<float>(FOUR_ROOT3 * area / sum);
}

void MeshGeomFacet::Transform(const Base::Matrix4D& mat)
{
mat.multVec(_aclPoints[0], _aclPoints[0]);
mat.multVec(_aclPoints[1], _aclPoints[1]);
mat.multVec(_aclPoints[2], _aclPoints[2]);
NormalInvalid();
}
23 changes: 13 additions & 10 deletions src/Mod/Mesh/App/Core/Elements.h
Expand Up @@ -121,11 +121,11 @@ class MeshExport MeshPoint: public Base::Vector3f
*/
//@{
void SetFlag (TFlagType tF) const
{ const_cast<MeshPoint*>(this)->_ucFlag |= (unsigned char)(tF); }
{ const_cast<MeshPoint*>(this)->_ucFlag |= static_cast<unsigned char>(tF); }
void ResetFlag (TFlagType tF) const
{ const_cast<MeshPoint*>(this)->_ucFlag &= ~(unsigned char)(tF); }
{ const_cast<MeshPoint*>(this)->_ucFlag &= ~static_cast<unsigned char>(tF); }
bool IsFlag (TFlagType tF) const
{ return (_ucFlag & (unsigned char)(tF)) == (unsigned char)(tF); }
{ return (_ucFlag & static_cast<unsigned char>(tF)) == static_cast<unsigned char>(tF); }
void ResetInvalid (void) const
{ ResetFlag(INVALID); }
void SetInvalid (void) const
Expand Down Expand Up @@ -226,11 +226,11 @@ class MeshFacet
*/
//@{
void SetFlag (TFlagType tF) const
{ const_cast<MeshFacet*>(this)->_ucFlag |= (unsigned char)(tF); }
{ const_cast<MeshFacet*>(this)->_ucFlag |= static_cast<unsigned char>(tF); }
void ResetFlag (TFlagType tF) const
{ const_cast<MeshFacet*>(this)->_ucFlag &= ~(unsigned char)(tF); }
{ const_cast<MeshFacet*>(this)->_ucFlag &= ~static_cast<unsigned char>(tF); }
bool IsFlag (TFlagType tF) const
{ return (_ucFlag & (unsigned char)(tF)) == (unsigned char)(tF); }
{ return (_ucFlag & static_cast<unsigned char>(tF)) == static_cast<unsigned char>(tF); }
void ResetInvalid (void) const
{ ResetFlag(INVALID); }
void SetProperty(unsigned long uP) const
Expand Down Expand Up @@ -412,17 +412,17 @@ class MeshExport MeshGeomFacet
* Adjusts the facet's orientation to its normal.
*/
inline void AdjustCirculationDirection (void);
/** Checks if the normal is not yet calculated. */
/** Invalidate the normal. It will be recomputed when querying it. */
void NormalInvalid (void) { _bNormalCalculated = false; }
/** Query the flag state of the facet. */
bool IsFlag (MeshFacet::TFlagType tF) const
{ return (_ucFlag & (unsigned char)(tF)) == (unsigned char)(tF); }
{ return (_ucFlag & static_cast<unsigned char>(tF)) == static_cast<unsigned char>(tF); }
/** Set flag state */
void SetFlag (MeshFacet::TFlagType tF)
{ _ucFlag |= (unsigned char)(tF); }
{ _ucFlag |= static_cast<unsigned char>(tF); }
/** Reset flag state */
void ResetFlag (MeshFacet::TFlagType tF)
{ _ucFlag &= ~(unsigned char)(tF); }
{ _ucFlag &= ~static_cast<unsigned char>(tF); }
/** Calculates the facet's gravity point. */
inline Base::Vector3f GetGravityPoint (void) const;
/** Returns the normal of the facet. */
Expand Down Expand Up @@ -517,6 +517,9 @@ class MeshExport MeshGeomFacet
/** The roundness is in the range between 0.0 (colinear) and 1.0 (equilateral).
*/
float Roundness() const;
/** Apply a transformation on the triangle.
*/
void Transform(const Base::Matrix4D&);

protected:
Base::Vector3f _clNormal; /**< Normal of the facet. */
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Mesh/App/Core/Evaluation.h
Expand Up @@ -239,7 +239,7 @@ class MeshExport MeshEvalPointManifolds : public MeshEvaluation
void GetFacetIndices (std::vector<unsigned long> &facets) const;
const std::list<std::vector<unsigned long> >& GetFacetIndices () const { return facetsOfNonManifoldPoints; }
const std::vector<unsigned long>& GetIndices() const { return nonManifoldPoints; }
unsigned long CountManifolds() const { return nonManifoldPoints.size(); }
unsigned long CountManifolds() const { return static_cast<unsigned long>(nonManifoldPoints.size()); }

protected:
std::vector<unsigned long> nonManifoldPoints;
Expand Down
14 changes: 7 additions & 7 deletions src/Mod/Mesh/App/Core/Grid.h
Expand Up @@ -125,7 +125,7 @@ class MeshExport MeshGrid
bool GetPositionToIndex(unsigned long id, unsigned long& ulX, unsigned long& ulY, unsigned long& ulZ) const;
/** Returns the number of elements in a given grid. */
unsigned long GetCtElements(unsigned long ulX, unsigned long ulY, unsigned long ulZ) const
{ return _aulGrid[ulX][ulY][ulZ].size(); }
{ return static_cast<unsigned long>(_aulGrid[ulX][ulY][ulZ].size()); }
/** Validates the grid structure and rebuilds it if needed. Must be implemented in sub-classes. */
virtual void Validate (const MeshKernel &rclM) = 0;
/** Verifies the grid structure and returns false if inconsistencies are found. */
Expand Down Expand Up @@ -395,9 +395,9 @@ inline bool MeshGrid::CheckPos (unsigned long ulX, unsigned long ulY, unsigned l

inline void MeshFacetGrid::Pos (const Base::Vector3f &rclPoint, unsigned long &rulX, unsigned long &rulY, unsigned long &rulZ) const
{
rulX = (unsigned long)((rclPoint.x - _fMinX) / _fGridLenX);
rulY = (unsigned long)((rclPoint.y - _fMinY) / _fGridLenY);
rulZ = (unsigned long)((rclPoint.z - _fMinZ) / _fGridLenZ);
rulX = static_cast<unsigned long>((rclPoint.x - _fMinX) / _fGridLenX);
rulY = static_cast<unsigned long>((rclPoint.y - _fMinY) / _fGridLenY);
rulZ = static_cast<unsigned long>((rclPoint.z - _fMinZ) / _fGridLenZ);

assert((rulX < _ulCtGridsX) && (rulY < _ulCtGridsY) && (rulZ < _ulCtGridsZ));
}
Expand All @@ -408,7 +408,7 @@ inline void MeshFacetGrid::PosWithCheck (const Base::Vector3f &rclPoint, unsigne
rulX = 0;
else
{
rulX = (unsigned long)((rclPoint.x - _fMinX) / _fGridLenX);
rulX = static_cast<unsigned long>((rclPoint.x - _fMinX) / _fGridLenX);
if (rulX >= _ulCtGridsX)
rulX = (_ulCtGridsX-1);
}
Expand All @@ -417,7 +417,7 @@ inline void MeshFacetGrid::PosWithCheck (const Base::Vector3f &rclPoint, unsigne
rulY = 0;
else
{
rulY = (unsigned long)((rclPoint.y - _fMinY) / _fGridLenY);
rulY = static_cast<unsigned long>((rclPoint.y - _fMinY) / _fGridLenY);
if (rulY >= _ulCtGridsY)
rulY = (_ulCtGridsY-1);
}
Expand All @@ -426,7 +426,7 @@ inline void MeshFacetGrid::PosWithCheck (const Base::Vector3f &rclPoint, unsigne
rulZ = 0;
else
{
rulZ = (unsigned long)((rclPoint.z - _fMinZ) / _fGridLenZ);
rulZ = static_cast<unsigned long>((rclPoint.z - _fMinZ) / _fGridLenZ);
if (rulZ >= _ulCtGridsZ)
rulZ = (_ulCtGridsZ-1);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/Mesh/App/Core/Iterator.h
Expand Up @@ -43,6 +43,7 @@ class MeshHelpEdge;
* The MeshFacetIterator allows to iterate over the facets that
* hold the topology of the mesh and provides access to their
* geometric information.
* \note This class is not thread-safe.
*/
class MeshFacetIterator
{
Expand Down Expand Up @@ -167,6 +168,7 @@ class MeshFacetIterator
/**
* The MeshPointIterator allows to iterate over the vertices of the mesh and provides access to their
* geometric information.
* \note This class is not thread-safe.
*/
class MeshExport MeshPointIterator
{
Expand Down
4 changes: 2 additions & 2 deletions src/Mod/Mesh/App/Core/MeshIO.cpp
Expand Up @@ -719,7 +719,7 @@ bool MeshInput::LoadPLY (std::istream &inp)
str >> space_format_string >> std::ws
>> format_string >> space_format_version
>> std::ws >> version;
if (!str || !str.eof() ||
if (/*!str || !str.eof() ||*/
!std::isspace(space_format_string) ||
!std::isspace(space_format_version)) {
return false;
Expand Down Expand Up @@ -749,7 +749,7 @@ bool MeshInput::LoadPLY (std::istream &inp)
str >> space_element_name >> std::ws
>> name >> space_name_count >> std::ws
>> count;
if (!str || !str.eof() ||
if (/*!str || !str.eof() ||*/
!std::isspace(space_element_name) ||
!std::isspace(space_name_count)) {
return false;
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/Mesh/App/Core/Simplify.h
Expand Up @@ -13,7 +13,9 @@
#include <vector>
#include <Base/Vector3D.h>

#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif

typedef Base::Vector3f vec3f;

Expand Down

0 comments on commit 5a83dc2

Please sign in to comment.