App: move from float to double for accuracy parameter, add a virtual method to determine a default accuracy

This commit is contained in:
wmayer
2022-09-15 09:52:14 +02:00
parent 12e2985bf3
commit 1309b86ea5
13 changed files with 46 additions and 41 deletions

View File

@@ -100,6 +100,11 @@ Base::Placement ComplexGeoData::getPlacement() const
Base::Rotation(mat));
}
double ComplexGeoData::getAccuracy() const
{
return 0.0;
}
void ComplexGeoData::getLinesFromSubElement(const Segment*,
std::vector<Base::Vector3d> &Points,
std::vector<Line> &lines) const
@@ -128,7 +133,7 @@ Base::Vector3d ComplexGeoData::getPointFromLineIntersection(const Base::Vector3f
void ComplexGeoData::getPoints(std::vector<Base::Vector3d> &Points,
std::vector<Base::Vector3d> &Normals,
float Accuracy, uint16_t flags) const
double Accuracy, uint16_t flags) const
{
(void)Points;
(void)Normals;
@@ -138,7 +143,7 @@ void ComplexGeoData::getPoints(std::vector<Base::Vector3d> &Points,
void ComplexGeoData::getLines(std::vector<Base::Vector3d> &Points,
std::vector<Line> &lines,
float Accuracy, uint16_t flags) const
double Accuracy, uint16_t flags) const
{
(void)Points;
(void)lines;
@@ -148,7 +153,7 @@ void ComplexGeoData::getLines(std::vector<Base::Vector3d> &Points,
void ComplexGeoData::getFaces(std::vector<Base::Vector3d> &Points,
std::vector<Facet> &faces,
float Accuracy, uint16_t flags) const
double Accuracy, uint16_t flags) const
{
(void)Points;
(void)faces;

View File

@@ -139,8 +139,10 @@ public:
/** @name Getting basic geometric entities */
//@{
/// Get the standard accuracy to be used with getPoints, getLines or getFaces
virtual double getAccuracy() const;
/// Get the bound box
virtual Base::BoundBox3d getBoundBox()const=0;
virtual Base::BoundBox3d getBoundBox() const=0;
/** Get point from line object intersection */
virtual Base::Vector3d getPointFromLineIntersection(
const Base::Vector3f& base,
@@ -148,13 +150,13 @@ public:
/** Get points from object with given accuracy */
virtual void getPoints(std::vector<Base::Vector3d> &Points,
std::vector<Base::Vector3d> &Normals,
float Accuracy, uint16_t flags=0) const;
double Accuracy, uint16_t flags=0) const;
/** Get lines from object with given accuracy */
virtual void getLines(std::vector<Base::Vector3d> &Points,std::vector<Line> &lines,
float Accuracy, uint16_t flags=0) const;
double Accuracy, uint16_t flags=0) const;
/** Get faces from object with given accuracy */
virtual void getFaces(std::vector<Base::Vector3d> &Points,std::vector<Facet> &faces,
float Accuracy, uint16_t flags=0) const;
double Accuracy, uint16_t flags=0) const;
/** Get the center of gravity
* If this method is implemented then true is returned and the center of gravity.
* The default implementation only returns false.

View File

@@ -106,13 +106,7 @@ Base::Vector3f InspectActualPoints::getPoint(unsigned long index) const
InspectActualShape::InspectActualShape(const Part::TopoShape& shape) : _rShape(shape)
{
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath
("User parameter:BaseApp/Preferences/Mod/Part");
float deviation = hGrp->GetFloat("MeshDeviation",0.2);
Base::BoundBox3d bbox = _rShape.getBoundBox();
Standard_Real deflection = (bbox.LengthX() + bbox.LengthY() + bbox.LengthZ())/300.0 * deviation;
Standard_Real deflection = _rShape.getAccuracy();
fetchPoints(deflection);
}
@@ -123,13 +117,13 @@ void InspectActualShape::fetchPoints(double deflection)
TopExp::MapShapes(_rShape.getShape(), TopAbs_FACE, mapOfShapes);
if (!mapOfShapes.IsEmpty()) {
std::vector<Data::ComplexGeoData::Facet> f;
_rShape.getFaces(points, f, static_cast<float>(deflection));
_rShape.getFaces(points, f, deflection);
}
else {
TopExp::MapShapes(_rShape.getShape(), TopAbs_EDGE, mapOfShapes);
if (!mapOfShapes.IsEmpty()) {
std::vector<Base::Vector3d> n;
_rShape.getPoints(points, n, static_cast<float>(deflection));
_rShape.getPoints(points, n, deflection);
}
}
}

View File

@@ -188,7 +188,7 @@ void ViewProviderInspection::updateData(const App::Property* prop)
if (prop->getTypeId().isDerivedFrom(App::PropertyLink::getClassTypeId())) {
App::GeoFeature* object = static_cast<const App::PropertyLink*>(prop)->getValue<App::GeoFeature*>();
if (object) {
float accuracy=0;
double accuracy = 0.0;
Base::Type meshId = Base::Type::fromName("Mesh::Feature");
Base::Type shapeId = Base::Type::fromName("Part::Feature");
Base::Type pointId = Base::Type::fromName("Points::Feature");
@@ -211,12 +211,7 @@ void ViewProviderInspection::updateData(const App::Property* prop)
App::Property* propS = object->getPropertyByName("Shape");
if (propS && propS->getTypeId().isDerivedFrom(propId)) {
const Data::ComplexGeoData* data = static_cast<App::PropertyComplexGeoData*>(propS)->getComplexData();
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath
("User parameter:BaseApp/Preferences/Mod/Part");
float deviation = hGrp->GetFloat("MeshDeviation",0.2);
Base::BoundBox3d bbox = data->getBoundBox();
accuracy = (float)((bbox.LengthX() + bbox.LengthY() + bbox.LengthZ())/300.0 * deviation);
accuracy = data->getAccuracy();
data->getFaces(points, faces, accuracy);
if (points.empty()) {
std::vector<Base::Vector3d> normals_d;

View File

@@ -140,10 +140,10 @@ void MeshObject::getFacesFromSubElement(const Data::Segment* element,
const MeshSegment* segm = static_cast<const MeshSegment*>(element);
if (segm->segment) {
Base::Reference<MeshObject> submesh(segm->mesh->meshFromSegment(segm->segment->getIndices()));
submesh->getFaces(points, faces, 0.0f);
submesh->getFaces(points, faces, 0.0);
}
else {
segm->mesh->getFaces(points, faces, 0.0f);
segm->mesh->getFaces(points, faces, 0.0);
}
}
}
@@ -309,7 +309,7 @@ MeshPoint MeshObject::getMeshPoint(PointIndex index) const
void MeshObject::getPoints(std::vector<Base::Vector3d> &Points,
std::vector<Base::Vector3d> &Normals,
float /*Accuracy*/, uint16_t /*flags*/) const
double /*Accuracy*/, uint16_t /*flags*/) const
{
Points = transformPointsToOutside(_kernel.GetPoints());
MeshCore::MeshRefNormalToPoints ptNormals(_kernel);
@@ -323,7 +323,7 @@ Mesh::Facet MeshObject::getMeshFacet(FacetIndex index) const
}
void MeshObject::getFaces(std::vector<Base::Vector3d> &Points,std::vector<Facet> &Topo,
float /*Accuracy*/, uint16_t /*flags*/) const
double /*Accuracy*/, uint16_t /*flags*/) const
{
unsigned long ctpoints = _kernel.CountPoints();
Points.reserve(ctpoints);

View File

@@ -150,9 +150,9 @@ public:
/** Get points from object with given accuracy */
void getPoints(std::vector<Base::Vector3d> &Points,
std::vector<Base::Vector3d> &Normals,
float Accuracy, uint16_t flags=0) const override;
double Accuracy, uint16_t flags=0) const override;
void getFaces(std::vector<Base::Vector3d> &Points,std::vector<Facet> &Topo,
float Accuracy, uint16_t flags=0) const override;
double Accuracy, uint16_t flags=0) const override;
std::vector<PointIndex> getPointsFromFacets(const std::vector<FacetIndex>& facets) const;
bool nearestFacetOnRay(const TRay& ray, double maxAngle, TFaceSection& output) const;
std::vector<TFaceSection> foraminate(const TRay& ray, double maxAngle) const;

View File

@@ -2050,7 +2050,7 @@ Py::Tuple MeshPy::getTopology() const
{
std::vector<Base::Vector3d> Points;
std::vector<Data::ComplexGeoData::Facet> Facets;
getMeshObjectPtr()->getFaces(Points, Facets, 0.0f);
getMeshObjectPtr()->getFaces(Points, Facets, 0.0);
Py::Tuple tuple(2);
Py::List vertex;
for (std::vector<Base::Vector3d>::const_iterator it = Points.begin();

View File

@@ -3487,9 +3487,16 @@ void TopoShape::getFacesFromDomains(const std::vector<Domain>& domains,
points.swap(meshPoints);
}
double TopoShape::getAccuracy() const
{
double deviation = 0.2;
Base::BoundBox3d bbox = getBoundBox();
return ((bbox.LengthX() + bbox.LengthY() + bbox.LengthZ())/300.0 * deviation);
}
void TopoShape::getFaces(std::vector<Base::Vector3d> &aPoints,
std::vector<Facet> &aTopo,
float accuracy, uint16_t /*flags*/) const
double accuracy, uint16_t /*flags*/) const
{
if (this->_Shape.IsNull())
return;
@@ -3679,14 +3686,14 @@ void TopoShape::getLinesFromSubShape(const TopoDS_Shape& shape,
void TopoShape::getLines(std::vector<Base::Vector3d> &vertices,
std::vector<TopoShape::Line> &lines,
float /*Accuracy*/, uint16_t /*flags*/) const
double /*Accuracy*/, uint16_t /*flags*/) const
{
getLinesFromSubShape(_Shape, vertices, lines);
}
void TopoShape::getPoints(std::vector<Base::Vector3d> &Points,
std::vector<Base::Vector3d> &Normals,
float Accuracy, uint16_t /*flags*/) const
double Accuracy, uint16_t /*flags*/) const
{
if (_Shape.IsNull())
return;

View File

@@ -136,15 +136,17 @@ private:
void getFacesFromDomains(const std::vector<Domain>& domains, std::vector<Base::Vector3d>& vertices, std::vector<Facet>& faces) const;
public:
/// Get the standard accuracy to be used with getPoints, getLines or getFaces
double getAccuracy() const override;
/** Get points from object with given accuracy */
void getPoints(std::vector<Base::Vector3d> &Points,
std::vector<Base::Vector3d> &Normals,
float Accuracy, uint16_t flags=0) const override;
double Accuracy, uint16_t flags=0) const override;
/** Get lines from object with given accuracy */
void getLines(std::vector<Base::Vector3d> &Points,std::vector<Line> &lines,
float Accuracy, uint16_t flags=0) const override;
double Accuracy, uint16_t flags=0) const override;
void getFaces(std::vector<Base::Vector3d> &Points,std::vector<Facet> &faces,
float Accuracy, uint16_t flags=0) const override;
double Accuracy, uint16_t flags=0) const override;
void setFaces(const std::vector<Base::Vector3d> &Points,
const std::vector<Facet> &faces, double tolerance=1.0e-06);
void getDomains(std::vector<Domain>&) const;

View File

@@ -1931,9 +1931,9 @@ PyObject* TopoShapePy::hashCode(PyObject *args)
PyObject* TopoShapePy::tessellate(PyObject *args)
{
float tolerance;
double tolerance;
PyObject* ok = Py_False;
if (!PyArg_ParseTuple(args, "f|O!",&tolerance,&PyBool_Type,&ok))
if (!PyArg_ParseTuple(args, "d|O!", &tolerance, &PyBool_Type, &ok))
return nullptr;
try {

View File

@@ -235,7 +235,7 @@ void PointKernel::save(std::ostream& out) const
void PointKernel::getPoints(std::vector<Base::Vector3d> &Points,
std::vector<Base::Vector3d> &/*Normals*/,
float /*Accuracy*/, uint16_t /*flags*/) const
double /*Accuracy*/, uint16_t /*flags*/) const
{
unsigned long ctpoints = _Points.size();
Points.reserve(ctpoints);

View File

@@ -92,7 +92,7 @@ public:
void getPoints(std::vector<Base::Vector3d> &Points,
std::vector<Base::Vector3d> &Normals,
float Accuracy, uint16_t flags=0) const override;
double Accuracy, uint16_t flags=0) const override;
void transformGeometry(const Base::Matrix4D &rclMat) override;
Base::BoundBox3d getBoundBox()const override;

View File

@@ -120,7 +120,7 @@ void FitBSplineSurfaceWidget::on_makePlacement_clicked()
const App::PropertyComplexGeoData* geom = geo->getPropertyOfGeometry();
if (geom) {
std::vector<Base::Vector3d> points, normals;
geom->getComplexData()->getPoints(points, normals, 0.001f);
geom->getComplexData()->getPoints(points, normals, 0.001);
std::vector<Base::Vector3f> data;
std::transform(points.begin(), points.end(), std::back_inserter(data), [](const Base::Vector3d& v) {