-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Prototype for callback: add a callback in Triangulation_3::file_input
#1036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Triangulation_3::file_input
I Cc also @janetournois, that can help you create big c3t3 files, and re-read them. |
} | ||
#endif // CGAL_CXX11 | ||
); | ||
std::cerr << "DONE.\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the moment, the callback is this big C++11 lambda function, that:
- uses a timer to return very fastly but every second,
- and displays stats about:
- the size of the triangulation being read,
- the size of the portion of the file that has been read, and the full size of the file.
Optionally, this callback can get a string as argument, so that the function force the display of a given string.
One needs C++11 to evaluation that prototype. One should:
|
} | ||
if(text != 0) { std::cerr << text; return; } | ||
const double current_time = timer.time(); | ||
if(current_time > last_time + 1.) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my experience with progress trackers, it is a good idea to only refresh every second, but calling time()
in itself can be a bit costly if it is done too often (for example if it's called inside a loop with a large number of very short iterations). I am not sure if this is the case here, but one simple option is to add a simple iterative counter and to only check time every 100 or 1000 iterations for example
static int i = 0;
if (i ++ != 100)
return;
const double current_time = time.time();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, in general, because time()
can make a syscall. But in my case the loop itself is just a lot of syscalls, that read the file. I do not think that can slow down. ...
-> to bench.
@lrineau is this PR ready to be tested? |
Yes, I would like to verify how portable my proposal is. But I do no think it is ready to be integrated in |
Locally building the polyhedron demo I got:
|
# define CGAL_CALLBACK(f, p1, p2, p3) | ||
# define CGAL_CALLBACK(f, p1, p2, p3, p4) | ||
# define CGAL_CALLBACK(f, p1, p2, p3, p4, p5) | ||
# define CGAL_CALLBACK_VAR(x) 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(In reply to #1036 (comment), by @sloriot)
Oops. I forgot that C++03 not only does not allow variadic macros but it does not allow either to define a macro with several number of arguments.
Probably the lines 33-38 should define macros with different names:
# define CGAL_CALLBACK0(f)
# define CGAL_CALLBACK1(f, p1)
# define CGAL_CALLBACK2(f, p1, p2)
# define CGAL_CALLBACK3(f, p1, p2, p3)
# define CGAL_CALLBACK4(f, p1, p2, p3, p4)
# define CGAL_CALLBACK5(f, p1, p2, p3, p4, p5)
and same for the C++11 part. But the API is not as nice as the previous one.
Or I could use:
# define CGAL_CALLBACK(...)
depending on the fact that all compilers we support probably support the variadic macros.
the link https://cgal.geometryfactory.com/CGAL/Members/wiki/Meeting/Sophia16#.E2.9C.94_Progress_tracker given by Laurent in his initial message does not work. |
Is there anything we can do to advance on this feature? (There is still one issue opened #102.) |
A callback mechanism similar to this one (but using |
@sgiraudot, in #1036 (comment):
Part of this PR was a prototype, that has to be refreshed, to use But the example I choose itself (load a big c3t3 file) is a real and useful one. For the moment, I propose that we refresh the PR, and try to display on the console ( @maxGimeno Would you mind take over this PR, and try to refresh it using the simpler mechanism used in #2695? |
8e1dc17
to
4573f3a
Compare
Problem with |
Anyway the code of this PR should be refreshed with the new way, using @sgiraudot Do you have a documentation of the use of callbacks? |
You can refer to the documentation of detect() in the classes of Shape Detection. |
@lrineau is it really for 4.14-beta ? It doesn't look ready. |
@afabri @sgiraudot
I have implemented a proof of concept for "progress tracker", using a
std::function
. This PR is for evaluation.https://cgal.geometryfactory.com/CGAL/Members/wiki/Meetings/Sophia16#.E2.9C.94_Progress_tracker
I Cc also @MoniqueTeillaud.
The undocumented fonction
TDS_3::read_cell
is modified, so that one can pass astd::function
as last argument. The non-documented functionT_3::file_input
is also modified. That allows to implement a progress tracking of the reading of a huge triangulation (actually a huge Mesh_3 C3t3).Please review and give feedback during my vacation next week.