Skip to content

Commit

Permalink
Inspection: [skip-ci] const correctness
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Jan 28, 2020
1 parent f95c87a commit 94280f1
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 43 deletions.
75 changes: 45 additions & 30 deletions src/Mod/Inspection/App/InspectionFeature.cpp
Expand Up @@ -59,10 +59,11 @@

using namespace Inspection;

InspectActualMesh::InspectActualMesh(const Mesh::MeshObject& rMesh) : _iter(rMesh.getKernel())
InspectActualMesh::InspectActualMesh(const Mesh::MeshObject& rMesh) : _mesh(rMesh.getKernel())
{
this->_count = rMesh.countPoints();
this->_iter.Transform(rMesh.getTransform());
Base::Matrix4D tmp;
_clTrf = rMesh.getTransform();
_bApply = _clTrf != tmp;
}

InspectActualMesh::~InspectActualMesh()
Expand All @@ -71,13 +72,15 @@ InspectActualMesh::~InspectActualMesh()

unsigned long InspectActualMesh::countPoints() const
{
return this->_count;
return _mesh.CountPoints();
}

Base::Vector3f InspectActualMesh::getPoint(unsigned long index)
Base::Vector3f InspectActualMesh::getPoint(unsigned long index) const
{
_iter.Set(index);
return *_iter;
Base::Vector3f point = _mesh.GetPoint(index);
if (_bApply)
_clTrf.multVec(point, point);
return point;
}

// ----------------------------------------------------------------
Expand All @@ -91,10 +94,10 @@ unsigned long InspectActualPoints::countPoints() const
return _rKernel.size();
}

Base::Vector3f InspectActualPoints::getPoint(unsigned long index)
Base::Vector3f InspectActualPoints::getPoint(unsigned long index) const
{
Base::Vector3d p = _rKernel.getPoint(index);
return Base::Vector3f((float)p.x,(float)p.y,(float)p.z);
return Base::Vector3f(float(p.x), float(p.y), float(p.z));
}

// ----------------------------------------------------------------
Expand All @@ -117,7 +120,7 @@ unsigned long InspectActualShape::countPoints() const
return points.size();
}

Base::Vector3f InspectActualShape::getPoint(unsigned long index)
Base::Vector3f InspectActualShape::getPoint(unsigned long index) const
{
return Base::toVector<float>(points[index]);
}
Expand Down Expand Up @@ -252,18 +255,19 @@ namespace Inspection {
};
}

InspectNominalMesh::InspectNominalMesh(const Mesh::MeshObject& rMesh, float offset) : _iter(rMesh.getKernel())
InspectNominalMesh::InspectNominalMesh(const Mesh::MeshObject& rMesh, float offset) : _mesh(rMesh.getKernel())
{
const MeshCore::MeshKernel& kernel = rMesh.getKernel();
_iter.Transform(rMesh.getTransform());
Base::Matrix4D tmp;
_clTrf = rMesh.getTransform();
_bApply = _clTrf != tmp;

// Max. limit of grid elements
float fMaxGridElements=8000000.0f;
Base::BoundBox3f box = kernel.GetBoundBox().Transformed(rMesh.getTransform());
Base::BoundBox3f box = _mesh.GetBoundBox().Transformed(rMesh.getTransform());

// estimate the minimum allowed grid length
float fMinGridLen = (float)pow((box.LengthX()*box.LengthY()*box.LengthZ()/fMaxGridElements), 0.3333f);
float fGridLen = 5.0f * MeshCore::MeshAlgorithm(kernel).GetAverageEdgeLength();
float fGridLen = 5.0f * MeshCore::MeshAlgorithm(_mesh).GetAverageEdgeLength();

// We want to avoid to get too small grid elements otherwise building up the grid structure would take
// too much time and memory.
Expand All @@ -272,7 +276,7 @@ InspectNominalMesh::InspectNominalMesh(const Mesh::MeshObject& rMesh, float offs
fGridLen = std::max<float>(fMinGridLen, fGridLen);

// build up grid structure to speed up algorithms
_pGrid = new MeshInspectGrid(kernel, fGridLen, rMesh.getTransform());
_pGrid = new MeshInspectGrid(_mesh, fGridLen, rMesh.getTransform());
_box = box;
_box.Enlarge(offset);
}
Expand All @@ -282,7 +286,7 @@ InspectNominalMesh::~InspectNominalMesh()
delete this->_pGrid;
}

float InspectNominalMesh::getDistance(const Base::Vector3f& point)
float InspectNominalMesh::getDistance(const Base::Vector3f& point) const
{
if (!_box.IsInBox(point))
return FLT_MAX; // must be inside bbox
Expand All @@ -298,11 +302,15 @@ float InspectNominalMesh::getDistance(const Base::Vector3f& point)
float fMinDist=FLT_MAX;
bool positive = true;
for (std::vector<unsigned long>::iterator it = indices.begin(); it != indices.end(); ++it) {
_iter.Set(*it);
float fDist = _iter->DistanceToPoint(point);
MeshCore::MeshGeomFacet geomFace = _mesh.GetFacet(*it);
if (_bApply) {
geomFace.Transform(_clTrf);
}

float fDist = geomFace.DistanceToPoint(point);
if (fabs(fDist) < fabs(fMinDist)) {
fMinDist = fDist;
positive = point.DistanceToPlane(_iter->_aclPoints[0], _iter->GetNormal()) > 0;
positive = point.DistanceToPlane(geomFace._aclPoints[0], geomFace.GetNormal()) > 0;
}
}

Expand All @@ -313,10 +321,13 @@ float InspectNominalMesh::getDistance(const Base::Vector3f& point)

// ----------------------------------------------------------------

InspectNominalFastMesh::InspectNominalFastMesh(const Mesh::MeshObject& rMesh, float offset) : _iter(rMesh.getKernel())
InspectNominalFastMesh::InspectNominalFastMesh(const Mesh::MeshObject& rMesh, float offset) : _mesh(rMesh.getKernel())
{
const MeshCore::MeshKernel& kernel = rMesh.getKernel();
_iter.Transform(rMesh.getTransform());

Base::Matrix4D tmp;
_clTrf = rMesh.getTransform();
_bApply = _clTrf != tmp;

// Max. limit of grid elements
float fMaxGridElements=8000000.0f;
Expand Down Expand Up @@ -348,7 +359,7 @@ InspectNominalFastMesh::~InspectNominalFastMesh()
* This algorithm is not that exact as that from InspectNominalMesh but is by
* factors faster and sufficient for many cases.
*/
float InspectNominalFastMesh::getDistance(const Base::Vector3f& point)
float InspectNominalFastMesh::getDistance(const Base::Vector3f& point) const
{
if (!_box.IsInBox(point))
return FLT_MAX; // must be inside bbox
Expand All @@ -371,11 +382,15 @@ float InspectNominalFastMesh::getDistance(const Base::Vector3f& point)
float fMinDist=FLT_MAX;
bool positive = true;
for (std::set<unsigned long>::iterator it = indices.begin(); it != indices.end(); ++it) {
_iter.Set(*it);
float fDist = _iter->DistanceToPoint(point);
MeshCore::MeshGeomFacet geomFace = _mesh.GetFacet(*it);
if (_bApply) {
geomFace.Transform(_clTrf);
}

float fDist = geomFace.DistanceToPoint(point);
if (fabs(fDist) < fabs(fMinDist)) {
fMinDist = fDist;
positive = point.DistanceToPlane(_iter->_aclPoints[0], _iter->GetNormal()) > 0;
positive = point.DistanceToPlane(geomFace._aclPoints[0], geomFace.GetNormal()) > 0;
}
}

Expand All @@ -398,7 +413,7 @@ InspectNominalPoints::~InspectNominalPoints()
delete this->_pGrid;
}

float InspectNominalPoints::getDistance(const Base::Vector3f& point)
float InspectNominalPoints::getDistance(const Base::Vector3f& point) const
{
//TODO: Make faster
std::set<unsigned long> indices;
Expand Down Expand Up @@ -447,7 +462,7 @@ InspectNominalShape::~InspectNominalShape()
delete distss;
}

float InspectNominalShape::getDistance(const Base::Vector3f& point)
float InspectNominalShape::getDistance(const Base::Vector3f& point) const
{
gp_Pnt pnt3d(point.x,point.y,point.z);
BRepBuilderAPI_MakeVertex mkVert(pnt3d);
Expand Down Expand Up @@ -647,12 +662,12 @@ struct DistanceInspection
: radius(radius), actual(a), nominal(n)
{
}
float mapped(unsigned long index)
float mapped(unsigned long index) const
{
Base::Vector3f pnt = actual->getPoint(index);

float fMinDist=FLT_MAX;
for (std::vector<InspectNominalGeometry*>::iterator it = nominal.begin(); it != nominal.end(); ++it) {
for (std::vector<InspectNominalGeometry*>::const_iterator it = nominal.begin(); it != nominal.end(); ++it) {
float fDist = (*it)->getDistance(pnt);
if (fabs(fDist) < fabs(fMinDist))
fMinDist = fDist;
Expand Down
31 changes: 18 additions & 13 deletions src/Mod/Inspection/App/InspectionFeature.h
Expand Up @@ -54,7 +54,7 @@ class InspectionExport InspectActualGeometry
virtual ~InspectActualGeometry() {}
/// Number of points to be checked
virtual unsigned long countPoints() const = 0;
virtual Base::Vector3f getPoint(unsigned long) = 0;
virtual Base::Vector3f getPoint(unsigned long) const = 0;
};

class InspectionExport InspectActualMesh : public InspectActualGeometry
Expand All @@ -63,19 +63,20 @@ class InspectionExport InspectActualMesh : public InspectActualGeometry
InspectActualMesh(const Mesh::MeshObject& rMesh);
~InspectActualMesh();
virtual unsigned long countPoints() const;
virtual Base::Vector3f getPoint(unsigned long);
virtual Base::Vector3f getPoint(unsigned long) const;

private:
MeshCore::MeshPointIterator _iter;
unsigned long _count;
const MeshCore::MeshKernel& _mesh;
bool _bApply;
Base::Matrix4D _clTrf;
};

class InspectionExport InspectActualPoints : public InspectActualGeometry
{
public:
InspectActualPoints(const Points::PointKernel&);
virtual unsigned long countPoints() const;
virtual Base::Vector3f getPoint(unsigned long);
virtual Base::Vector3f getPoint(unsigned long) const;

private:
const Points::PointKernel& _rKernel;
Expand All @@ -86,7 +87,7 @@ class InspectionExport InspectActualShape : public InspectActualGeometry
public:
InspectActualShape(const Part::TopoShape&);
virtual unsigned long countPoints() const;
virtual Base::Vector3f getPoint(unsigned long);
virtual Base::Vector3f getPoint(unsigned long) const;

private:
const Part::TopoShape& _rShape;
Expand All @@ -99,42 +100,46 @@ class InspectionExport InspectNominalGeometry
public:
InspectNominalGeometry() {}
virtual ~InspectNominalGeometry() {}
virtual float getDistance(const Base::Vector3f&) = 0;
virtual float getDistance(const Base::Vector3f&) const = 0;
};

class InspectionExport InspectNominalMesh : public InspectNominalGeometry
{
public:
InspectNominalMesh(const Mesh::MeshObject& rMesh, float offset);
~InspectNominalMesh();
virtual float getDistance(const Base::Vector3f&);
virtual float getDistance(const Base::Vector3f&) const;

private:
MeshCore::MeshFacetIterator _iter;
const MeshCore::MeshKernel& _mesh;
MeshCore::MeshGrid* _pGrid;
Base::BoundBox3f _box;
bool _bApply;
Base::Matrix4D _clTrf;
};

class InspectionExport InspectNominalFastMesh : public InspectNominalGeometry
{
public:
InspectNominalFastMesh(const Mesh::MeshObject& rMesh, float offset);
~InspectNominalFastMesh();
virtual float getDistance(const Base::Vector3f&);
virtual float getDistance(const Base::Vector3f&) const;

protected:
MeshCore::MeshFacetIterator _iter;
const MeshCore::MeshKernel& _mesh;
MeshCore::MeshGrid* _pGrid;
Base::BoundBox3f _box;
unsigned long max_level;
bool _bApply;
Base::Matrix4D _clTrf;
};

class InspectionExport InspectNominalPoints : public InspectNominalGeometry
{
public:
InspectNominalPoints(const Points::PointKernel&, float offset);
~InspectNominalPoints();
virtual float getDistance(const Base::Vector3f&);
virtual float getDistance(const Base::Vector3f&) const;

private:
const Points::PointKernel& _rKernel;
Expand All @@ -146,7 +151,7 @@ class InspectionExport InspectNominalShape : public InspectNominalGeometry
public:
InspectNominalShape(const TopoDS_Shape&, float offset);
~InspectNominalShape();
virtual float getDistance(const Base::Vector3f&);
virtual float getDistance(const Base::Vector3f&) const;

private:
BRepExtrema_DistShapeShape* distss;
Expand Down

0 comments on commit 94280f1

Please sign in to comment.