+ improve the plane fit from REEN module
This commit is contained in:
@@ -127,6 +127,15 @@ void CmdApproxPlane::activated(int iMsg)
|
||||
std::vector<Data::ComplexGeoData::Facet> aTopo;
|
||||
static_cast<App::PropertyComplexGeoData*>(jt->second)->getFaces(aPoints, aTopo,0.01f);
|
||||
|
||||
// get a reference normal for the plane fit
|
||||
Base::Vector3f refNormal(0,0,0);
|
||||
if (!aTopo.empty()) {
|
||||
Data::ComplexGeoData::Facet f = aTopo.front();
|
||||
Base::Vector3d v1 = aPoints[f.I2] - aPoints[f.I1];
|
||||
Base::Vector3d v2 = aPoints[f.I3] - aPoints[f.I1];
|
||||
refNormal = Base::convertTo<Base::Vector3f>(v1 % v2);
|
||||
}
|
||||
|
||||
std::vector<Base::Vector3f> aData;
|
||||
aData.reserve(aPoints.size());
|
||||
for (std::vector<Base::Vector3d>::iterator jt = aPoints.begin(); jt != aPoints.end(); ++jt)
|
||||
@@ -135,21 +144,38 @@ void CmdApproxPlane::activated(int iMsg)
|
||||
fit.AddPoints(aData);
|
||||
float sigma = fit.Fit();
|
||||
Base::Vector3f base = fit.GetBase();
|
||||
Base::Vector3f dirU = fit.GetDirU();
|
||||
Base::Vector3f dirV = fit.GetDirV();
|
||||
Base::Vector3f norm = fit.GetNormal();
|
||||
|
||||
Base::Console().Message("RMS value for plane fit with %ld points: %.4f\n", aData.size(), sigma);
|
||||
Base::Console().Message(" Plane base(%.4f, %.4f, %.4f)\n", base.x, base.y, base.z);
|
||||
Base::Console().Message(" Plane normal(%.4f, %.4f, %.4f)\n", norm.x, norm.y, norm.z);
|
||||
// if the dot product of the refernce with the plane normal is negative
|
||||
// a flip must be done
|
||||
if (refNormal * norm < 0) {
|
||||
norm = -norm;
|
||||
dirU = -dirU;
|
||||
}
|
||||
|
||||
float width, length;
|
||||
fit.Dimension(width, length);
|
||||
// move to the corner point
|
||||
base = base - (0.5f * length * dirU + 0.5f * width * dirV);
|
||||
|
||||
Base::Console().Log("RMS value for plane fit with %ld points: %.4f\n", aData.size(), sigma);
|
||||
Base::Console().Log(" Plane base(%.4f, %.4f, %.4f)\n", base.x, base.y, base.z);
|
||||
Base::Console().Log(" Plane normal(%.4f, %.4f, %.4f)\n", norm.x, norm.y, norm.z);
|
||||
|
||||
std::stringstream str;
|
||||
str << "import Part" << std::endl;
|
||||
str << "from FreeCAD import Base" << std::endl;
|
||||
str << "Part.show(Part.makePlane("
|
||||
<< 10 << ", " << 10 << ", "
|
||||
str << "App.ActiveDocument.addObject('Part::Feature','Plane_fit').Shape="
|
||||
<< "Part.makePlane("
|
||||
<< width << ", " << length << ", "
|
||||
<< "Base.Vector("
|
||||
<< base.x << ", " << base.y << ", " << base.z << "), "
|
||||
<< "Base.Vector("
|
||||
<< norm.x << ", " << norm.y << ", " << norm.z << ")))" << std::endl;
|
||||
<< norm.x << ", " << norm.y << ", " << norm.z << "), "
|
||||
<< "Base.Vector("
|
||||
<< dirU.x << ", " << dirU.y << ", " << dirU.z << "))" << std::endl;
|
||||
|
||||
openCommand("Fit plane");
|
||||
doCommand(Gui::Command::Doc, str.str().c_str());
|
||||
|
||||
Reference in New Issue
Block a user