Skip to content

Commit

Permalink
Path.Area: use FC tag based logging
Browse files Browse the repository at this point in the history
  • Loading branch information
realthunder authored and wwmayer committed May 13, 2017
1 parent dbbc32d commit fa00b4f
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 143 deletions.
127 changes: 67 additions & 60 deletions src/Mod/Path/App/Area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ typedef bgi::linear<16> RParameters;
BOOST_GEOMETRY_REGISTER_POINT_3D_GET_SET(
gp_Pnt,double,bg::cs::cartesian,X,Y,Z,SetX,SetY,SetZ)

#define AREA_LOG FC_LOG
#define AREA_WARN FC_WARN
#define AREA_ERR FC_ERR
#define AREA_TRACE FC_TRACE
#define AREA_XYZ FC_XYZ
#define AREA_XY AREA_XY

FC_LOG_LEVEL_INIT("Path.Area",true,true)

using namespace Path;

CAreaParams::CAreaParams()
Expand Down Expand Up @@ -976,7 +985,7 @@ TopoDS_Shape Area::findPlane(const TopoDS_Shape &shape, gp_Trsf &trsf)
int Area::project(TopoDS_Shape &shape_out,
const TopoDS_Shape &shape_in, const AreaParams *params)
{
TIME_INIT2(t,t1);
FC_TIME_INIT2(t,t1);
Handle_HLRBRep_Algo brep_hlr = NULL;
gp_Dir dir(0,0,1);
try {
Expand All @@ -990,7 +999,7 @@ int Area::project(TopoDS_Shape &shape_out,
AREA_ERR("error occurred while projecting shape");
return -1;
}
TIME_PRINT(t1,"HLRBrep_Algo");
FC_TIME_LOG(t1,"HLRBrep_Algo");
WireJoiner joiner;
try {
#define ADD_HLR_SHAPE(_name) \
Expand All @@ -1011,16 +1020,16 @@ int Area::project(TopoDS_Shape &shape_out,
AREA_ERR("error occurred while extracting edges");
return -1;
}
TIME_PRINT(t1,"WireJoiner init");
FC_TIME_LOG(t1,"WireJoiner init");
joiner.splitEdges();
TIME_PRINT(t1,"WireJoiner splitEdges");
FC_TIME_LOG(t1,"WireJoiner splitEdges");
for(const auto &v : joiner.edges) {
// joiner.builder.Add(joiner.comp,BRepBuilderAPI_MakeWire(v.edge).Wire());
showShape(v.edge,"split");
}

int skips = joiner.findClosedWires();
TIME_PRINT(t1,"WireJoiner findClosedWires");
FC_TIME_LOG(t1,"WireJoiner findClosedWires");

Area area(params);
area.myParams.Explode = false;
Expand All @@ -1034,8 +1043,8 @@ int Area::project(TopoDS_Shape &shape_out,
const TopoDS_Shape &shape = area.getShape();
showShape(shape,"projected");

TIME_PRINT(t1,"Clipper wire union");
TIME_PRINT(t,"project total");
FC_TIME_LOG(t1,"Clipper wire union");
FC_TIME_LOG(t,"project total");

if(shape.IsNull()) {
AREA_ERR("poject failed");
Expand All @@ -1061,7 +1070,7 @@ std::vector<shared_ptr<Area> > Area::makeSections(
if(plane.IsNull())
throw Base::ValueError("failed to obtain section plane");

TIME_INIT2(t,t1);
FC_TIME_INIT2(t,t1);

TopLoc_Location loc(trsf);

Expand Down Expand Up @@ -1272,7 +1281,7 @@ std::vector<shared_ptr<Area> > Area::makeSections(
}
if(area->myShapes.size()){
sections.push_back(area);
TIME_PRINT(t1,"makeSection " << z);
FC_TIME_LOG(t1,"makeSection " << z);
break;
}
if(retried) {
Expand All @@ -1285,7 +1294,7 @@ std::vector<shared_ptr<Area> > Area::makeSections(
}
}
}
TIME_PRINT(t,"makeSection count: " << sections.size()<<", total");
FC_TIME_LOG(t,"makeSection count: " << sections.size()<<", total");
return std::move(sections);
}

Expand Down Expand Up @@ -1348,7 +1357,7 @@ void Area::build() {
return;
}

TIME_INIT(t);
FC_TIME_INIT(t);
gp_Trsf trsf;
getPlane(&trsf);

Expand Down Expand Up @@ -1434,7 +1443,7 @@ void Area::build() {
}
}

TIME_TRACE(t,"prepare");
FC_TIME_TRACE(t,"prepare");

}catch(...) {
clean();
Expand Down Expand Up @@ -1517,7 +1526,7 @@ TopoDS_Shape Area::getShape(int index) {
return myShape;
}

TIME_INIT(t);
FC_TIME_INIT(t);

// do offset first, then pocket the inner most offseted shape
std::list<shared_ptr<CArea> > areas;
Expand Down Expand Up @@ -1551,19 +1560,19 @@ TopoDS_Shape Area::getShape(int index) {
builder.MakeCompound(compound);

short fill = myParams.Thicken?FillFace:FillNone;
TIME_INIT(t2);
DURATION_INIT(d);
FC_TIME_INIT(t2);
FC_DURATION_DECL_INIT(d);
for(shared_ptr<CArea> area : areas) {
if(myParams.Thicken){
area->Thicken(myParams.ToolRadius);
DURATION_PLUS(d,t2);
FC_DURATION_PLUS(d,t2);
}
const TopoDS_Shape &shape = toShape(*area,fill);
if(shape.IsNull()) continue;
builder.Add(compound,shape);
}
if(myParams.Thicken)
DURATION_PRINT(d,"Thicken");
FC_DURATION_LOG(d,"Thicken");

// make sure the compound has at least one edge
for(TopExp_Explorer it(compound,TopAbs_EDGE);it.More();) {
Expand All @@ -1573,7 +1582,7 @@ TopoDS_Shape Area::getShape(int index) {
break;
}
myShapeDone = true;
TIME_PRINT(t,"total");
FC_TIME_LOG(t,"total");
return myShape;
}

Expand All @@ -1586,26 +1595,26 @@ TopoDS_Shape Area::makeOffset(int index,PARAM_ARGS(PARAM_FARG,AREA_PARAMS_OFFSET
if(areas.empty()) {
if(myParams.Thicken && myParams.ToolRadius>Precision::Confusion()) {
CArea area(*myArea);
TIME_INIT(t);
FC_TIME_INIT(t);
area.Thicken(myParams.ToolRadius);
TIME_PRINT(t,"Thicken");
FC_TIME_LOG(t,"Thicken");
return toShape(area,FillFace,reorient);
}
return TopoDS_Shape();
}
BRep_Builder builder;
TopoDS_Compound compound;
builder.MakeCompound(compound);
TIME_INIT(t);
DURATION_INIT(d);
FC_TIME_INIT(t);
FC_DURATION_DECL_INIT(d);

bool thicken = myParams.Thicken && myParams.ToolRadius>Precision::Confusion();

for(shared_ptr<CArea> area : areas) {
short fill;
if(thicken){
area->Thicken(myParams.ToolRadius);
DURATION_PLUS(d,t);
FC_DURATION_PLUS(d,t);
fill = FillFace;
}else if(areas.size()==1)
fill = myParams.Fill;
Expand All @@ -1616,7 +1625,7 @@ TopoDS_Shape Area::makeOffset(int index,PARAM_ARGS(PARAM_FARG,AREA_PARAMS_OFFSET
builder.Add(compound,shape);
}
if(thicken)
DURATION_PRINT(d,"Thicken");
FC_DURATION_LOG(d,"Thicken");
for(TopExp_Explorer it(compound,TopAbs_EDGE);it.More();)
return compound;
return TopoDS_Shape();
Expand All @@ -1628,7 +1637,7 @@ void Area::makeOffset(list<shared_ptr<CArea> > &areas,
if(fabs(offset)<Precision::Confusion())
return;

TIME_INIT2(t,t1);
FC_TIME_INIT2(t,t1);

long count = 1;
if(extra_pass) {
Expand Down Expand Up @@ -1686,11 +1695,11 @@ void Area::makeOffset(list<shared_ptr<CArea> > &areas,
}
#endif
if(count>1)
TIME_PRINT(t1,"makeOffset " << i << '/' << count);
FC_TIME_LOG(t1,"makeOffset " << i << '/' << count);
if(area.m_curves.empty())
return;
}
TIME_PRINT(t,"makeOffset count: " << count);
FC_TIME_LOG(t,"makeOffset count: " << count);
}

TopoDS_Shape Area::makePocket(int index, PARAM_ARGS(PARAM_FARG,AREA_PARAMS_POCKET)) {
Expand All @@ -1709,7 +1718,7 @@ TopoDS_Shape Area::makePocket(int index, PARAM_ARGS(PARAM_FARG,AREA_PARAMS_POCKE
build();
AREA_SECTION(makePocket,index,PARAM_FIELDS(PARAM_FARG,AREA_PARAMS_POCKET));

TIME_INIT(t);
FC_TIME_INIT(t);
bool done = false;

if(index>=0) {
Expand Down Expand Up @@ -1818,12 +1827,12 @@ TopoDS_Shape Area::makePocket(int index, PARAM_ARGS(PARAM_FARG,AREA_PARAMS_POCKE
in.MakePocketToolpath(out.m_curves,params);
}

TIME_PRINT(t,"makePocket");
FC_TIME_LOG(t,"makePocket");

if(myParams.Thicken){
TIME_INIT(t);
FC_TIME_INIT(t);
out.Thicken(tool_radius);
TIME_PRINT(t,"thicken");
FC_TIME_LOG(t,"thicken");
return toShape(out,FillFace);
}else
return toShape(out,FillNone);
Expand Down Expand Up @@ -1924,7 +1933,7 @@ TopoDS_Shape Area::toShape(const CArea &area, bool fill, const gp_Trsf *trsf, in
if(!xp.More()) return TopoDS_Shape();
if(fill) {
try{
TIME_INIT(t);
FC_TIME_INIT(t);
Part::FaceMakerBullseye mkFace;
if(trsf)
mkFace.setPlane(gp_Pln().Transformed(*trsf));
Expand All @@ -1933,7 +1942,7 @@ TopoDS_Shape Area::toShape(const CArea &area, bool fill, const gp_Trsf *trsf, in
mkFace.Build();
if (mkFace.Shape().IsNull())
AREA_WARN("FaceMakerBullseye returns null shape");
TIME_PRINT(t,"makeFace");
FC_TIME_LOG(t,"makeFace");
return mkFace.Shape();
}catch (Base::Exception &e){
AREA_WARN("FaceMakerBullseye failed: "<<e.what());
Expand Down Expand Up @@ -1970,19 +1979,17 @@ struct ShapeParams {
int k;
short orientation;
short direction;
#ifdef AREA_TIME_ENABLE
TIME_DURATION qd; //rtree query duration
TIME_DURATION bd; //rtree build duration
TIME_DURATION rd; //rtree remove duration
TIME_DURATION xd; //BRepExtrema_DistShapeShape duration
#endif
FC_DURATION_DECLARE(qd); //rtree query duration
FC_DURATION_DECLARE(bd); //rtree build duration
FC_DURATION_DECLARE(rd); //rtree remove duration
FC_DURATION_DECLARE(xd); //BRepExtrema_DistShapeShape duration

ShapeParams(double _a, int _k, short o, short d)
:abscissa(_a),k(_k),orientation(o),direction(d)
#ifdef AREA_TIME_ENABLE
,qd(0),bd(0),rd(0),xd(0)
#endif
{}
{
FC_DURATION_INIT3(qd,bd,rd);
FC_DURATION_INIT(xd);
}
};

bool operator<(const Wires::iterator &a, const Wires::iterator &b) {
Expand All @@ -2009,7 +2016,7 @@ struct GetWires {
if(info.isClosed && params.orientation == Area::OrientationReversed)
info.wire.Reverse();

TIME_INIT(t);
FC_TIME_INIT(t);
if(params.abscissa<Precision::Confusion() || !info.isClosed) {
gp_Pnt p1,p2;
getEndPoints(info.wire,p1,p2);
Expand Down Expand Up @@ -2077,7 +2084,7 @@ struct GetWires {
--it;
for(size_t i=0,count=info.points.size();i<count;++i)
rtree.insert(RValue(it,i));
DURATION_PLUS(params.bd,t);
FC_DURATION_PLUS(params.bd,t);
}
};

Expand Down Expand Up @@ -2119,9 +2126,9 @@ struct ShapeInfo{

RResults ret;
{
TIME_INIT(t);
FC_TIME_INIT(t);
myRTree.query(bgi::nearest(pt,myParams.k),bgi::inserter(ret));
DURATION_PLUS(myParams.qd,t);
FC_DURATION_PLUS(myParams.qd,t);
}

TopoDS_Shape v = BRepBuilderAPI_MakeVertex(pt);
Expand All @@ -2138,7 +2145,7 @@ struct ShapeInfo{
bool done = false;
bool is_start = false;
if(BRep_Tool::IsClosed(wire)) {
TIME_INIT(t);
FC_TIME_INIT(t);
BRepExtrema_DistShapeShape extss(v,wire);
if(extss.IsDone() && extss.NbSolution()) {
d = extss.Value();
Expand All @@ -2150,7 +2157,7 @@ struct ShapeInfo{
done = true;
}else
AREA_WARN("BRepExtrema_DistShapeShape failed");
DURATION_PLUS(myParams.xd,t);
FC_DURATION_PLUS(myParams.xd,t);
}
if(!done){
double d1 = pt.SquareDistance(it->pstart());
Expand Down Expand Up @@ -2336,10 +2343,10 @@ struct ShapeInfo{
wires.push_back(myBestWire->wire);
pend = myBestWire->pend();
}
TIME_INIT(t);
FC_TIME_INIT(t);
for(size_t i=0,count=myBestWire->points.size();i<count;++i)
myRTree.remove(RValue(myBestWire,i));
DURATION_PLUS(myParams.rd,t);
FC_DURATION_PLUS(myParams.rd,t);
myWires.erase(myBestWire);
if(myWires.empty()) break;
nearest(pend);
Expand Down Expand Up @@ -2526,7 +2533,7 @@ std::list<TopoDS_Shape> Area::sortWires(const std::list<TopoDS_Shape> &shapes,
ShapeParams rparams(abscissa,nearest_k>0?nearest_k:1,orientation,direction);
std::list<ShapeInfo> shape_list;

TIME_INIT2(t,t1);
FC_TIME_INIT2(t,t1);

gp_Trsf trsf;
bool arcPlaneFound = false;
Expand All @@ -2551,7 +2558,7 @@ std::list<TopoDS_Shape> Area::sortWires(const std::list<TopoDS_Shape> &shapes,
arcPlaneFound,arc_plane,trsf,shape_list,rparams));
}
}
TIME_PRINT(t1,"plane finding");
FC_TIME_LOG(t1,"plane finding");
}

if(shape_list.empty())
Expand Down Expand Up @@ -2602,10 +2609,10 @@ std::list<TopoDS_Shape> Area::sortWires(const std::list<TopoDS_Shape> &shapes,
it->myShape = comp;
}
}
TIME_PRINT(t,"plane merging");
FC_TIME_LOG(t,"plane merging");
}

DURATION_INIT(td);
FC_DURATION_DECL_INIT(td);

if(use_bound) {
bounds.SetGap(0.0);
Expand Down Expand Up @@ -2638,11 +2645,11 @@ std::list<TopoDS_Shape> Area::sortWires(const std::list<TopoDS_Shape> &shapes,
shape_list.erase(best_it);
}
if(_pend) *_pend = pend;
DURATION_PRINT(rparams.bd,"rtree build");
DURATION_PRINT(rparams.qd,"rtree query");
DURATION_PRINT(rparams.rd,"rtree clean");
DURATION_PRINT(rparams.xd,"BRepExtrema");
TIME_PRINT(t,"sortWires total");
FC_DURATION_LOG(rparams.bd,"rtree build");
FC_DURATION_LOG(rparams.qd,"rtree query");
FC_DURATION_LOG(rparams.rd,"rtree clean");
FC_DURATION_LOG(rparams.xd,"BRepExtrema");
FC_TIME_LOG(t,"sortWires total");
return std::move(wires);
}

Expand Down
Loading

0 comments on commit fa00b4f

Please sign in to comment.