Skip to content

Commit

Permalink
Merge pull request #2928 from realthunder/PathFix
Browse files Browse the repository at this point in the history
Path: fix b-spline discretization problem
  • Loading branch information
sliptonic committed Jan 25, 2020
2 parents 26aed44 + ec10b5e commit f362b95
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/Mod/Path/App/Area.cpp
Expand Up @@ -65,6 +65,7 @@
# include <gp_GTrsf.hxx>
# include <Standard_Version.hxx>
# include <GCPnts_QuasiUniformDeflection.hxx>
# include <GCPnts_UniformDeflection.hxx>
# include <GCPnts_UniformAbscissa.hxx>
# include <BRepBndLib.hxx>
# include <BRepLib_MakeFace.hxx>
Expand Down Expand Up @@ -134,6 +135,20 @@ AreaParams::AreaParams()
:PARAM_INIT(PARAM_FNAME,AREA_PARAMS_AREA)
{}

void AreaParams::dump(const char *msg) const {

#define AREA_PARAM_PRINT(_param) \
ss << PARAM_FNAME_STR(_param) << " = " << PARAM_FNAME(_param) << '\n';

if(FC_LOG_INSTANCE.level()>FC_LOGLEVEL_TRACE) {
std::ostringstream ss;
ss << msg << '\n';
PARAM_FOREACH(AREA_PARAM_PRINT, AREA_PARAMS_AREA)

FC_MSG(ss.str());
}
}

CAreaConfig::CAreaConfig(const CAreaParams &p, bool noFitArcs)
{
#define AREA_CONF_SAVE_AND_APPLY(_param) \
Expand Down Expand Up @@ -342,7 +357,12 @@ static std::vector<gp_Pnt> discretize(const TopoDS_Edge &edge, double deflection
// same for any other discetization algorithm, althgouth it seems only
// QuasiUniformDeflection has this bug.

GCPnts_QuasiUniformDeflection discretizer(curve, deflection, first, last);
// NOTE: QuasiUniformDeflection has trouble with some B-Spline, see
// https://forum.freecadweb.org/viewtopic.php?f=15&t=42628
//
// GCPnts_QuasiUniformDeflection discretizer(curve, deflection, first, last);
//
GCPnts_UniformDeflection discretizer(curve, deflection, first, last);
if (!discretizer.IsDone ())
Standard_Failure::Raise("Curve discretization failed");
if(discretizer.NbPoints () > 1) {
Expand Down Expand Up @@ -871,7 +891,9 @@ struct WireJoiner {
if(info.p1.SquareDistance(info.p2)<tol)
#endif
{
builder.Add(comp,BRepBuilderAPI_MakeWire(info.edge).Wire());
auto wire = BRepBuilderAPI_MakeWire(info.edge).Wire();
Area::showShape(wire,"closed");
builder.Add(comp,wire);
++count;
continue;
}
Expand Down Expand Up @@ -996,6 +1018,7 @@ struct WireJoiner {
TopoDS_Wire wire = makeCleanWire(wireData,0.01);
if(!BRep_Tool::IsClosed(wire)) {
FC_WARN("failed to close some projection wire");
Area::showShape(wire,"failed");
++skips;
}else{
for(auto &r : stack) {
Expand Down Expand Up @@ -1265,6 +1288,8 @@ int Area::project(TopoDS_Shape &shape_out,
int skips = joiner.findClosedWires();
FC_TIME_LOG(t1,"WireJoiner findClosedWires");

showShape(joiner.comp,"pre_project");

Area area(params);
area.myParams.SectionCount = 0;
area.myParams.Offset = 0.0;
Expand All @@ -1278,6 +1303,9 @@ int Area::project(TopoDS_Shape &shape_out,
area.myProjecting = true;
area.add(joiner.comp, OperationUnion);
const TopoDS_Shape &shape = area.getShape();

area.myParams.dump("project");

showShape(shape,"projected");

FC_TIME_LOG(t1,"Clipper wire union");
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/Path/App/Area.h
Expand Up @@ -68,6 +68,8 @@ struct PathExport AreaParams: CAreaParams {
return !(*this == other);
}

void dump(const char *) const;

AreaParams();
};

Expand Down

1 comment on commit f362b95

@donovaly
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I cannot compile:
2>D:\FreeCADGit\src\Mod\Path\App\Area.cpp(367): error C2065: 'GCPnts_UniformDeflection': undeclared identifier

To fix this, I must add the line # include <GCPnts_UniformDeflection.hxx>
outside the #ifndef PreComp block.

OS: Windows 7 SP 1 (6.1)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.19373 (Git)
Build type: Release
Branch: master
Hash: 1f89710
Python version: 3.6.8
Qt version: 5.12.1
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: German/Germany (de_DE)

Please sign in to comment.