#include <CGAL/Real_timer.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Barycentric_coordinates_2/Triangle_coordinates_2.h>
template<typename Scalar>
class overwrite_iterator
{
private:
Scalar* pointer;
public:
explicit overwrite_iterator(Scalar* new_pointer) : pointer(new_pointer) { }
inline Scalar&
operator* () {
return *pointer; }
inline void operator++ () { ++pointer; }
};
typedef CGAL::Real_timer Timer;
typedef overwrite_iterator<Scalar> Overwrite_iterator;
using std::cout; using std::endl; using std::string;
int main()
{
const int number_of_x_coordinates = 100000;
const int number_of_y_coordinates = 1000;
const int number_of_runs = 10;
const Scalar zero = Scalar(0);
const Scalar one = Scalar(1);
const Scalar two = Scalar(2);
const Scalar x_step = one / Scalar(number_of_x_coordinates);
const Scalar y_step = one / Scalar(number_of_y_coordinates);
const Point first_vertex(zero - x_step, zero - x_step);
const Point second_vertex(two + y_step, zero - x_step);
const Point third_vertex(zero - x_step, two + y_step);
Triangle_coordinates triangle_coordinates(first_vertex, second_vertex, third_vertex);
Scalar coordinates [3] = {0, 0, 0};
Overwrite_iterator it( &(coordinates[0]) );
Timer time_to_compute;
double time = 0.0;
for(int i = 0; i < number_of_runs; ++i) {
time_to_compute.start();
for(Scalar x = zero; x <= one; x += x_step) {
for(Scalar y = zero; y <= one; y += y_step)
triangle_coordinates(Point(x, y), it);
}
time_to_compute.stop();
time += time_to_compute.time();
time_to_compute.reset();
}
const double mean_time = time / number_of_runs;
cout.precision(10);
cout << endl << "CPU time to compute triangle coordinates for "
<< number_of_x_coordinates * number_of_y_coordinates << " points = " << mean_time << " seconds.";
cout << endl << endl;
return EXIT_SUCCESS;
}