diff --git a/src/Mod/Inspection/App/InspectionFeature.cpp b/src/Mod/Inspection/App/InspectionFeature.cpp index 390407056a..b4c465fc81 100644 --- a/src/Mod/Inspection/App/InspectionFeature.cpp +++ b/src/Mod/Inspection/App/InspectionFeature.cpp @@ -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() @@ -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; } // ---------------------------------------------------------------- @@ -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)); } // ---------------------------------------------------------------- @@ -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(points[index]); } @@ -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. @@ -272,7 +276,7 @@ InspectNominalMesh::InspectNominalMesh(const Mesh::MeshObject& rMesh, float offs fGridLen = std::max(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); } @@ -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 @@ -298,11 +302,15 @@ float InspectNominalMesh::getDistance(const Base::Vector3f& point) float fMinDist=FLT_MAX; bool positive = true; for (std::vector::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; } } @@ -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; @@ -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 @@ -371,11 +382,15 @@ float InspectNominalFastMesh::getDistance(const Base::Vector3f& point) float fMinDist=FLT_MAX; bool positive = true; for (std::set::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; } } @@ -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 indices; @@ -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); @@ -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::iterator it = nominal.begin(); it != nominal.end(); ++it) { + for (std::vector::const_iterator it = nominal.begin(); it != nominal.end(); ++it) { float fDist = (*it)->getDistance(pnt); if (fabs(fDist) < fabs(fMinDist)) fMinDist = fDist; diff --git a/src/Mod/Inspection/App/InspectionFeature.h b/src/Mod/Inspection/App/InspectionFeature.h index f2fd7761c2..29906154aa 100644 --- a/src/Mod/Inspection/App/InspectionFeature.h +++ b/src/Mod/Inspection/App/InspectionFeature.h @@ -54,7 +54,7 @@ public: 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 @@ -63,11 +63,12 @@ public: 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 @@ -75,7 +76,7 @@ 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; @@ -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; @@ -99,7 +100,7 @@ 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 @@ -107,12 +108,14 @@ 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 @@ -120,13 +123,15 @@ 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 @@ -134,7 +139,7 @@ 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; @@ -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;