Path.Area: use FC tag based logging

This commit is contained in:
Zheng, Lei
2017-05-06 02:37:38 +08:00
committed by wmayer
parent f10431ba05
commit de2c826f86
3 changed files with 71 additions and 143 deletions

View File

@@ -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()
@@ -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 {
@@ -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) \
@@ -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;
@@ -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");
@@ -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);
@@ -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) {
@@ -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);
}
@@ -1348,7 +1357,7 @@ void Area::build() {
return;
}
TIME_INIT(t);
FC_TIME_INIT(t);
gp_Trsf trsf;
getPlane(&trsf);
@@ -1434,7 +1443,7 @@ void Area::build() {
}
}
TIME_TRACE(t,"prepare");
FC_TIME_TRACE(t,"prepare");
}catch(...) {
clean();
@@ -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;
@@ -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();) {
@@ -1573,7 +1582,7 @@ TopoDS_Shape Area::getShape(int index) {
break;
}
myShapeDone = true;
TIME_PRINT(t,"total");
FC_TIME_LOG(t,"total");
return myShape;
}
@@ -1586,9 +1595,9 @@ 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();
@@ -1596,8 +1605,8 @@ TopoDS_Shape Area::makeOffset(int index,PARAM_ARGS(PARAM_FARG,AREA_PARAMS_OFFSET
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();
@@ -1605,7 +1614,7 @@ TopoDS_Shape Area::makeOffset(int index,PARAM_ARGS(PARAM_FARG,AREA_PARAMS_OFFSET
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;
@@ -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();
@@ -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) {
@@ -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)) {
@@ -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) {
@@ -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);
@@ -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));
@@ -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());
@@ -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) {
@@ -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);
@@ -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);
}
};
@@ -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);
@@ -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();
@@ -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());
@@ -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);
@@ -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;
@@ -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())
@@ -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);
@@ -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);
}

View File

@@ -42,87 +42,6 @@ namespace Part {
extern PartExport Py::Object shape2pyshape(const TopoDS_Shape &shape);
}
#define _AREA_LOG(_l,_msg) do {\
if(Area::_l##Enabled()){\
std::stringstream str;\
str << _msg;\
const char *_f = strrchr(__FILE__, '/');\
Base::Console()._l("%s:(%d): %s\n",_f?_f+1:__FILE__,__LINE__,str.str().c_str());\
}\
QCoreApplication::sendPostedEvents();\
if(Area::aborting()) {\
Area::abort(false);\
throw Base::AbortException("operation aborted");\
}\
}while(0)
#define AREA_LOG(_msg) _AREA_LOG(Log,_msg)
#define AREA_WARN(_msg) _AREA_LOG(Warning,_msg)
#define AREA_ERR(_msg) _AREA_LOG(Error,_msg)
#define AREA_XYZ(_pt) '('<<(_pt).X()<<", " << (_pt).Y()<<", " << (_pt).Z()<<')'
#define AREA_XY(_pt) '('<<(_pt).x<<", " << (_pt).y<<')'
#define AREA_TRACE(_msg) do{\
if(Area::TraceEnabled()) AREA_LOG(_msg);\
}while(0)
#define AREA_DBG AREA_WARN
#define AREA_TIME_ENABLE
#ifdef AREA_TIME_ENABLE
#define TIME_UNIT duration<double>
#define TIME_CLOCK high_resolution_clock
#define TIME_POINT std::chrono::TIME_CLOCK::time_point
#define TIME_DURATION std::chrono::TIME_UNIT
#define _TIME_INIT(_t) _t=std::chrono::TIME_CLOCK::now()
#define TIME_INIT(_t) TIME_POINT _TIME_INIT(_t)
#define TIME_INIT2(_t1,_t2) TIME_INIT(_t1),_t2=_t1
#define TIME_INIT3(_t1,_t2,_t3) TIME_INIT(_t1),_t2=_t1,_t3=_t1
#define _DURATION_PRINT(_l,_d,_msg) \
AREA_##_l(_msg<< " time: " << _d.count()<<'s');
#define DURATION_PRINT(_d,_msg) _DURATION_PRINT(LOG,_d,_msg)
#define TIME_PRINT(_t,_msg) \
DURATION_PRINT(Path::getDuration(_t),_msg);
#define TIME_TRACE(_t,_msg) \
_DURATION_PRINT(TRACE,Path::getDuration(_t),_msg);
#define DURATION_INIT(_d) \
TIME_DURATION _d(0)
#define DURATION_INIT2(_d1,_d2) DURATION_INIT(_d1),_d2(0)
namespace Path {
inline std::chrono::TIME_UNIT getDuration(TIME_POINT &t)
{
auto tnow = std::chrono::TIME_CLOCK::now();
auto d = std::chrono::duration_cast<std::chrono::TIME_UNIT>(tnow-t);
t = tnow;
return d;
}
}
#define DURATION_PLUS(_d,_t) _d += Path::getDuration(_t)
#else
#define TIME_POINT
#define _TIME_INIT(...) do{}while(0)
#define TIME_INIT(...) do{}while(0)
#define TIME_INIT2(...) do{}while(0)
#define TIME_INIT3(...) do{}while(0)
#define TIME_PRINT(...) do{}while(0)
#define DURATION_PRINT(...) do{}while(0)
#define DURATION_INIT(...) do{}while(0)
#define DURATION_INIT2(...) do{}while(0)
#define DURATION_PLUS(...) do{}while(0)
#endif
class CArea;
class CCurve;
class Bnd_Box;

View File

@@ -34,6 +34,8 @@
#include <Base/Placement.h>
#include <Mod/Part/App/PartFeature.h>
FC_LOG_LEVEL_INIT("Path.Area",true,true)
using namespace Path;
PROPERTY_SOURCE(Path::FeatureArea, Part::Feature)
@@ -84,7 +86,7 @@ App::DocumentObjectExecReturn *FeatureArea::execute(void)
return new App::DocumentObjectExecReturn("Linked shape object is empty");
}
TIME_INIT(t);
FC_TIME_INIT(t);
AreaParams params;
@@ -129,7 +131,7 @@ App::DocumentObjectExecReturn *FeatureArea::execute(void)
Shape.setValue(compound);
}
TIME_PRINT(t,"feature execute");
FC_TIME_LOG(t,"feature execute");
if(!hasShape)
return new App::DocumentObjectExecReturn("no output shape");