Skip to content

Commit

Permalink
Coverity issues: fix Mesh, Points and Inspection module
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Aug 17, 2016
1 parent e4f0dda commit 9b013f7
Show file tree
Hide file tree
Showing 18 changed files with 127 additions and 86 deletions.
7 changes: 5 additions & 2 deletions src/Mod/Inspection/App/InspectionFeature.cpp
Expand Up @@ -751,8 +751,11 @@ App::DocumentObjectExecReturn* Feature::execute(void)
}
}

fRMS = fRMS / countRMS;
fRMS = sqrt(fRMS);
if (countRMS > 0) {
fRMS = fRMS / countRMS;
fRMS = sqrt(fRMS);
}

Base::Console().Message("RMS value for '%s' with search radius=%.4f is: %.4f\n",
this->Label.getValue(), this->SearchRadius.getValue(), fRMS);

Expand Down
10 changes: 7 additions & 3 deletions src/Mod/Inspection/Gui/ViewProviderInspection.cpp
Expand Up @@ -183,7 +183,7 @@ void ViewProviderInspection::updateData(const App::Property* prop)
{
// set to the expected size
if (prop->getTypeId() == App::PropertyLink::getClassTypeId()) {
App::GeoFeature* object = static_cast<const App::PropertyLink*>(prop)->getValue<App::GeoFeature*>();
App::GeoFeature* object = dynamic_cast<const App::PropertyLink*>(prop)->getValue<App::GeoFeature*>();
if (object) {
float accuracy=0;
Base::Type meshId = Base::Type::fromName("Mesh::Feature");
Expand Down Expand Up @@ -260,9 +260,10 @@ void ViewProviderInspection::updateData(const App::Property* prop)
// force an update of the Inventor data nodes
if (this->pcObject) {
App::Property* link = this->pcObject->getPropertyByName("Actual");
if (link) updateData(link);
if (link)
updateData(link);
setDistances();
}
setDistances();
}
else if (prop->getTypeId() == App::PropertyFloat::getClassTypeId()) {
if (strcmp(prop->getName(), "SearchRadius") == 0) {
Expand All @@ -281,6 +282,9 @@ SoSeparator* ViewProviderInspection::getFrontRoot(void) const

void ViewProviderInspection::setDistances()
{
if (!pcObject)
return;

App::Property* pDistances = pcObject->getPropertyByName("Distances");
if (!pDistances) {
SoDebugError::post("ViewProviderInspection::setDistances", "Unknown property 'Distances'");
Expand Down
48 changes: 24 additions & 24 deletions src/Mod/Mesh/App/Core/Algorithm.cpp
Expand Up @@ -1570,34 +1570,34 @@ bool MeshAlgorithm::ConnectPolygons(std::list<std::vector<Base::Vector3f> > &clP
std::list<std::pair<Base::Vector3f, Base::Vector3f> > &rclLines) const
{

for(std::list< std::vector<Base::Vector3f> >::iterator OutIter = clPolyList.begin(); OutIter != clPolyList.end(); ++OutIter)
{
std::pair<Base::Vector3f,Base::Vector3f> currentSort;
float fDist = Base::Distance(OutIter->front(),OutIter->back());
currentSort.first = OutIter->front();
currentSort.second = OutIter->back();

for(std::list< std::vector<Base::Vector3f> >::iterator InnerIter = clPolyList.begin(); InnerIter != clPolyList.end(); ++InnerIter)
{
if(OutIter == InnerIter) continue;
for (std::list< std::vector<Base::Vector3f> >::iterator OutIter = clPolyList.begin(); OutIter != clPolyList.end(); ++OutIter) {
if (OutIter->empty())
continue;
std::pair<Base::Vector3f,Base::Vector3f> currentSort;
float fDist = Base::Distance(OutIter->front(),OutIter->back());
currentSort.first = OutIter->front();
currentSort.second = OutIter->back();

for (std::list< std::vector<Base::Vector3f> >::iterator InnerIter = clPolyList.begin(); InnerIter != clPolyList.end(); ++InnerIter) {
if (OutIter == InnerIter)
continue;

if (Base::Distance(OutIter->front(), InnerIter->front()) < fDist) {
currentSort.second = InnerIter->front();
fDist = Base::Distance(OutIter->front(),InnerIter->front());
}

if(Base::Distance(OutIter->front(),InnerIter->front()) < fDist)
{
currentSort.second = InnerIter->front();
fDist = Base::Distance(OutIter->front(),InnerIter->front());
}
if(Base::Distance(OutIter->front(),InnerIter->back()) < fDist)
{
currentSort.second = InnerIter->back();
fDist = Base::Distance(OutIter->front(),InnerIter->back());
}
}
if (Base::Distance(OutIter->front(), InnerIter->back()) < fDist) {
currentSort.second = InnerIter->back();
fDist = Base::Distance(OutIter->front(),InnerIter->back());
}
}

rclLines.push_front(currentSort);
rclLines.push_front(currentSort);

}
}

return true;
return true;
}

void MeshAlgorithm::GetFacetsFromPlane (const MeshFacetGrid &rclGrid, const Base::Vector3f& clNormal, float d, const Base::Vector3f &rclLeft,
Expand Down
27 changes: 15 additions & 12 deletions src/Mod/Mesh/App/Core/Approximation.cpp
Expand Up @@ -107,9 +107,11 @@ void Approximation::AddPoints(const std::list<Base::Vector3f> &rsPointList)
Base::Vector3f Approximation::GetGravity() const
{
Base::Vector3f clGravity;
for (std::list<Base::Vector3f>::const_iterator it = _vPoints.begin(); it!=_vPoints.end(); ++it)
clGravity += *it;
clGravity *= 1.0f / float(_vPoints.size());
if (!_vPoints.empty()) {
for (std::list<Base::Vector3f>::const_iterator it = _vPoints.begin(); it!=_vPoints.end(); ++it)
clGravity += *it;
clGravity *= 1.0f / float(_vPoints.size());
}
return clGravity;
}

Expand Down Expand Up @@ -173,10 +175,10 @@ float PlaneFit::Fit()
szz = szz - mz*mz/((double)nSize);

#if defined(FC_USE_EIGEN)
Eigen::Matrix3d covMat = Eigen::Matrix3d::Zero();
covMat(0,0) = sxx;
covMat(1,1) = syy;
covMat(2,2) = szz;
Eigen::Matrix3d covMat = Eigen::Matrix3d::Zero();
covMat(0,0) = sxx;
covMat(1,1) = syy;
covMat(2,2) = szz;
covMat(0,1) = sxy; covMat(1,0) = sxy;
covMat(0,2) = sxz; covMat(2,0) = sxz;
covMat(1,2) = syz; covMat(2,1) = syz;
Expand Down Expand Up @@ -451,7 +453,7 @@ const double& QuadraticFit::GetCoeffArray() const

double QuadraticFit::GetCoeff(unsigned long ulIndex) const
{
assert( ulIndex >= 0 && ulIndex < 10 );
assert(ulIndex < 10);

if( _bIsFitted )
return _fCoeff[ ulIndex ];
Expand Down Expand Up @@ -636,9 +638,9 @@ double SurfaceFit::PolynomFit()
// <=> sum[(P*Vi)*Vi] = sum[Vi*zi]
// <=> sum[(Vi*Vi^t)*P] = sum[Vi*zi] where (Vi*Vi^t) is a symmetric matrix
// <=> sum[(Vi*Vi^t)]*P = sum[Vi*zi]
Eigen::Matrix<double,6,6> A = Eigen::Matrix<double,6,6>::Zero();
Eigen::Matrix<double,6,1> b = Eigen::Matrix<double,6,1>::Zero();
Eigen::Matrix<double,6,1> x = Eigen::Matrix<double,6,1>::Zero();
Eigen::Matrix<double,6,6> A = Eigen::Matrix<double,6,6>::Zero();
Eigen::Matrix<double,6,1> b = Eigen::Matrix<double,6,1>::Zero();
Eigen::Matrix<double,6,1> x = Eigen::Matrix<double,6,1>::Zero();

std::vector<Base::Vector3d> transform;
transform.reserve(_vPoints.size());
Expand Down Expand Up @@ -765,7 +767,8 @@ double SurfaceFit::PolynomFit()
// that 'sigma' becomes negative.
if (sigma < 0)
sigma = 0;
sigma = sqrt(sigma/_vPoints.size());
if (!_vPoints.empty())
sigma = sqrt(sigma/_vPoints.size());

_fLastResult = static_cast<float>(sigma);
return _fLastResult;
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Mesh/App/Core/Builder.cpp
Expand Up @@ -36,7 +36,7 @@
using namespace MeshCore;


MeshBuilder::MeshBuilder (MeshKernel& kernel) : _meshKernel(kernel), _seq(0)
MeshBuilder::MeshBuilder (MeshKernel& kernel) : _meshKernel(kernel), _seq(0), _ptIdx(0)
{
_fSaveTolerance = MeshDefinitions::_fMinPointDistanceD1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Mesh/App/Core/Builder.h
Expand Up @@ -105,7 +105,7 @@ class MeshExport MeshBuilder
// keep an array of iterators pointing to the vertex inside the set to save memory
typedef std::pair<std::set<MeshPoint>::iterator, bool> MeshPointIterator;
std::vector<MeshPointIterator> _pointsIterator;
unsigned long _ptIdx;
unsigned long _ptIdx;

void SetNeighbourhood ();
// As it's forbidden to insert a degenerated facet but insert its vertices anyway we must remove them
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Mesh/App/Core/Evaluation.cpp
Expand Up @@ -508,7 +508,7 @@ void MeshEvalPointManifolds::GetFacetIndices (std::vector<unsigned long> &facets
bool MeshEvalSingleFacet::Evaluate ()
{
// get all non-manifolds
MeshEvalTopology::Evaluate();
(void)MeshEvalTopology::Evaluate();
/*
// for each (multiple) single linked facet there should
// exist two valid facets sharing the same edge
Expand Down
3 changes: 2 additions & 1 deletion src/Mod/Mesh/App/Core/MeshIO.cpp
Expand Up @@ -1793,7 +1793,8 @@ bool MeshOutput::SaveBinarySTL (std::ostream &rstrOut) const
return false;

Base::SequencerLauncher seq("saving...", _rclMesh.CountFacets() + 1);


// stl_header has a length of 80
strcpy(szInfo, stl_header.c_str());
rstrOut.write(szInfo, std::strlen(szInfo));

Expand Down
1 change: 0 additions & 1 deletion src/Mod/Mesh/App/Core/SetOperations.h
Expand Up @@ -74,7 +74,6 @@ class MeshExport SetOperations
MeshKernel &_resultMesh; /** Result mesh */
OperationType _operationType; /** Set Operation Type */
float _minDistanceToPoint; /** Minimal distance to facet corner points */
float _saveMinMeshDistance;

private:
// Helper class cutting edge to his two attached facets
Expand Down
6 changes: 5 additions & 1 deletion src/Mod/Mesh/App/Core/Smoothing.cpp
Expand Up @@ -36,7 +36,11 @@
using namespace MeshCore;


AbstractSmoothing::AbstractSmoothing(MeshKernel& m) : kernel(m)
AbstractSmoothing::AbstractSmoothing(MeshKernel& m)
: kernel(m)
, tolerance(0)
, component(Normal)
, continuity(C0)
{
}

Expand Down
12 changes: 7 additions & 5 deletions src/Mod/Mesh/App/Core/Tools.cpp
Expand Up @@ -34,11 +34,13 @@
using namespace MeshCore;

MeshSearchNeighbours::MeshSearchNeighbours (const MeshKernel &rclM, float fSampleDistance)
: _rclMesh(rclM),
_rclFAry(rclM.GetFacets()),
_rclPAry(rclM.GetPoints()),
_clPt2Fa(rclM),
_fSampleDistance(fSampleDistance)
: _rclMesh(rclM)
, _rclFAry(rclM.GetFacets())
, _rclPAry(rclM.GetPoints())
, _clPt2Fa(rclM)
, _fMaxDistanceP2(0)
, _fSampleDistance(fSampleDistance)
, _bTooFewPoints(false)
{
MeshAlgorithm(_rclMesh).ResetFacetFlag(MeshFacet::MARKED);
MeshAlgorithm(_rclMesh).ResetPointFlag(MeshPoint::MARKED);
Expand Down
7 changes: 6 additions & 1 deletion src/Mod/Mesh/Gui/MeshEditor.cpp
Expand Up @@ -409,7 +409,12 @@ namespace MeshGui {
/* TRANSLATOR MeshGui::MeshFillHole */

MeshFillHole::MeshFillHole(MeshHoleFiller& hf, Gui::View3DInventor* parent)
: QObject(parent), myMesh(0), myNumPoints(0), myHoleFiller(hf)
: QObject(parent)
, myMesh(0)
, myNumPoints(0)
, myVertex1(0)
, myVertex2(0)
, myHoleFiller(hf)
{
myBoundariesRoot = new SoSeparator;
myBoundariesRoot->ref();
Expand Down
3 changes: 3 additions & 0 deletions src/Mod/Mesh/Gui/MeshSelection.cpp
Expand Up @@ -78,6 +78,9 @@ unsigned char MeshSelection::cross_mask_bitmap[] = {
MeshSelection::MeshSelection()
: onlyPointToUserTriangles(false)
, onlyVisibleTriangles(false)
, addToSelection(false)
, addComponent(false)
, removeComponent(false)
, activeCB(0)
, selectionCB(0)
, ivViewer(0)
Expand Down
5 changes: 4 additions & 1 deletion src/Mod/Mesh/Gui/SoFCMeshObject.cpp
Expand Up @@ -588,7 +588,10 @@ void SoFCMeshObjectShape::initClass()
SO_NODE_INIT_CLASS(SoFCMeshObjectShape, SoShape, "Shape");
}

SoFCMeshObjectShape::SoFCMeshObjectShape() : renderTriangleLimit(100000), meshChanged(true)
SoFCMeshObjectShape::SoFCMeshObjectShape()
: renderTriangleLimit(100000)
, meshChanged(true)
, selectBuf(0)
{
SO_NODE_CONSTRUCTOR(SoFCMeshObjectShape);
setName(SoFCMeshObjectShape::getClassTypeId().getName());
Expand Down
6 changes: 5 additions & 1 deletion src/Mod/Mesh/Gui/ViewProvider.cpp
Expand Up @@ -1028,7 +1028,7 @@ void ViewProviderMesh::getFacetsFromPolygon(const std::vector<SbVec2f>& picked,
std::vector<unsigned long>& indices) const
{
#if 1
bool ok = true;
const bool ok = true;
Base::Polygon2D polygon;
for (std::vector<SbVec2f>::const_iterator it = picked.begin(); it != picked.end(); ++it)
polygon.Add(Base::Vector2D((*it)[0],(*it)[1]));
Expand Down Expand Up @@ -1890,6 +1890,8 @@ PROPERTY_SOURCE(MeshGui::ViewProviderIndexedFaceSet, MeshGui::ViewProviderMesh)

ViewProviderIndexedFaceSet::ViewProviderIndexedFaceSet()
{
pcMeshCoord = 0;
pcMeshFaces = 0;
}

ViewProviderIndexedFaceSet::~ViewProviderIndexedFaceSet()
Expand Down Expand Up @@ -1979,6 +1981,8 @@ PROPERTY_SOURCE(MeshGui::ViewProviderMeshObject, MeshGui::ViewProviderMesh)

ViewProviderMeshObject::ViewProviderMeshObject()
{
pcMeshNode = 0;
pcMeshShape = 0;
}

ViewProviderMeshObject::~ViewProviderMeshObject()
Expand Down
20 changes: 10 additions & 10 deletions src/Mod/Mesh/Gui/ViewProviderDefects.cpp
Expand Up @@ -145,7 +145,7 @@ void ViewProviderMeshOrientation::attach(App::DocumentObject* pcFeat)

void ViewProviderMeshOrientation::showDefects(const std::vector<unsigned long>& inds)
{
Mesh::Feature* f = dynamic_cast<Mesh::Feature*>(pcObject);
Mesh::Feature* f = static_cast<Mesh::Feature*>(pcObject);
const MeshCore::MeshKernel & rMesh = f->Mesh.getValue().getKernel();

pcCoords->point.deleteValues(0);
Expand Down Expand Up @@ -212,7 +212,7 @@ void ViewProviderMeshNonManifolds::showDefects(const std::vector<unsigned long>&
{
if ((inds.size() % 2) != 0)
return;
Mesh::Feature* f = dynamic_cast<Mesh::Feature*>(pcObject);
Mesh::Feature* f = static_cast<Mesh::Feature*>(pcObject);
const MeshCore::MeshKernel & rMesh = f->Mesh.getValue().getKernel();

pcCoords->point.deleteValues(0);
Expand Down Expand Up @@ -275,7 +275,7 @@ void ViewProviderMeshNonManifoldPoints::attach(App::DocumentObject* pcFeat)

void ViewProviderMeshNonManifoldPoints::showDefects(const std::vector<unsigned long>& inds)
{
Mesh::Feature* f = dynamic_cast<Mesh::Feature*>(pcObject);
Mesh::Feature* f = static_cast<Mesh::Feature*>(pcObject);
const MeshCore::MeshKernel & rMesh = f->Mesh.getValue().getKernel();
pcCoords->point.deleteValues(0);
pcCoords->point.setNum(inds.size());
Expand Down Expand Up @@ -339,7 +339,7 @@ void ViewProviderMeshDuplicatedFaces::attach(App::DocumentObject* pcFeat)

void ViewProviderMeshDuplicatedFaces::showDefects(const std::vector<unsigned long>& inds)
{
Mesh::Feature* f = dynamic_cast<Mesh::Feature*>(pcObject);
Mesh::Feature* f = static_cast<Mesh::Feature*>(pcObject);
const MeshCore::MeshKernel & rMesh = f->Mesh.getValue().getKernel();

pcCoords->point.deleteValues(0);
Expand Down Expand Up @@ -404,7 +404,7 @@ void ViewProviderMeshDuplicatedPoints::attach(App::DocumentObject* pcFeat)

void ViewProviderMeshDuplicatedPoints::showDefects(const std::vector<unsigned long>& inds)
{
Mesh::Feature* f = dynamic_cast<Mesh::Feature*>(pcObject);
Mesh::Feature* f = static_cast<Mesh::Feature*>(pcObject);
const MeshCore::MeshKernel & rMesh = f->Mesh.getValue().getKernel();
pcCoords->point.deleteValues(0);
pcCoords->point.setNum(inds.size());
Expand Down Expand Up @@ -461,7 +461,7 @@ void ViewProviderMeshDegenerations::attach(App::DocumentObject* pcFeat)

void ViewProviderMeshDegenerations::showDefects(const std::vector<unsigned long>& inds)
{
Mesh::Feature* f = dynamic_cast<Mesh::Feature*>(pcObject);
Mesh::Feature* f = static_cast<Mesh::Feature*>(pcObject);
const MeshCore::MeshKernel & rMesh = f->Mesh.getValue().getKernel();

pcCoords->point.deleteValues(0);
Expand Down Expand Up @@ -567,7 +567,7 @@ void ViewProviderMeshIndices::attach(App::DocumentObject* pcFeat)

void ViewProviderMeshIndices::showDefects(const std::vector<unsigned long>& inds)
{
Mesh::Feature* f = dynamic_cast<Mesh::Feature*>(pcObject);
Mesh::Feature* f = static_cast<Mesh::Feature*>(pcObject);
const MeshCore::MeshKernel & rMesh = f->Mesh.getValue().getKernel();

if (!inds.empty()) {
Expand Down Expand Up @@ -636,7 +636,7 @@ void ViewProviderMeshSelfIntersections::showDefects(const std::vector<unsigned l
{
if (indices.size() % 2 != 0)
return;
Mesh::Feature* f = dynamic_cast<Mesh::Feature*>(pcObject);
Mesh::Feature* f = static_cast<Mesh::Feature*>(pcObject);
const MeshCore::MeshKernel & rMesh = f->Mesh.getValue().getKernel();
MeshCore::MeshEvalSelfIntersection eval(rMesh);

Expand All @@ -645,7 +645,7 @@ void ViewProviderMeshSelfIntersections::showDefects(const std::vector<unsigned l
for (it = indices.begin(); it != indices.end(); ) {
unsigned long id1 = *it; ++it;
unsigned long id2 = *it; ++it;
intersection.push_back(std::make_pair(id1,id2));
intersection.push_back(std::make_pair(id1,id2));
}

std::vector<std::pair<Base::Vector3f, Base::Vector3f> > lines;
Expand Down Expand Up @@ -714,7 +714,7 @@ void ViewProviderMeshFolds::attach(App::DocumentObject* pcFeat)

void ViewProviderMeshFolds::showDefects(const std::vector<unsigned long>& inds)
{
Mesh::Feature* f = dynamic_cast<Mesh::Feature*>(pcObject);
Mesh::Feature* f = static_cast<Mesh::Feature*>(pcObject);
const MeshCore::MeshKernel & rMesh = f->Mesh.getValue().getKernel();

pcCoords->point.deleteValues(0);
Expand Down

0 comments on commit 9b013f7

Please sign in to comment.