void plot_functions( const string& filepath, const FuncDef<Function> functions[], const size_t function_count, const T low, const T high, const size_t step_count) { GnuplotFile plotfile; for (size_t f = 0; f < function_count; ++f) { vector<Vector<T, 2> > points(step_count); for (size_t i = 0; i < step_count; ++i) { const T x = fit<size_t, T>(i, 0, step_count - 1, low, high); const T y = functions[f].m_function(x); points[i] = Vector2f(x, y); } plotfile .new_plot() .set_points(points) .set_title(functions[f].m_title) .set_color(functions[f].m_color); } plotfile.write(filepath); }
void plot_dirpole_rd( const char* filename, const char* title, const double sigma_a, const double ymin, const double ymax) { GnuplotFile plotfile; plotfile.set_title(title); plotfile.set_xlabel("r [cm]"); plotfile.set_ylabel("Rd(r)"); plotfile.set_logscale_y(); plotfile.set_xrange(-16.0, 16.0); // cm plotfile.set_yrange(ymin, ymax); DipoleBSSRDFEvaluator<DirectionalDipoleBSSRDFFactory> bssrdf_eval; bssrdf_eval.set_values_from_sigmas(sigma_a, 1.0, 1.0, 0.0); const size_t N = 1000; vector<Vector2d> points; for (size_t i = 0; i < N; ++i) { const double r = fit<size_t, double>(i, 0, N - 1, -16.0, 16.0); const double result = bssrdf_eval.evaluate(r); points.push_back(Vector2d(r, result * Pi / abs(r))); } plotfile .new_plot() .set_points(points); plotfile.write(filename); }
void plot_rd_curves( const char* filename, const char* title, const float sigma_a, const float sigma_s, const double ymin, const double ymax) { GnuplotFile plotfile; plotfile.set_title(title); plotfile.set_xlabel("r [cm]"); plotfile.set_ylabel("Rd(r)"); plotfile.set_logscale_y(); plotfile.set_xrange(-16.0, 16.0); // cm plotfile.set_yrange(ymin, ymax); plot_rd_curve<StandardDipoleBSSRDFFactory, DipoleBSSRDFInputValues>( plotfile, "Standard Dipole", sigma_a, sigma_s); plot_rd_curve<BetterDipoleBSSRDFFactory, DipoleBSSRDFInputValues>( plotfile, "Better Dipole", sigma_a, sigma_s); plot_rd_curve<DirectionalDipoleBSSRDFFactory, DipoleBSSRDFInputValues>( plotfile, "Directional Dipole", sigma_a, sigma_s); plotfile.write(filename); }
void BenchmarkSuite::run( const IFilter& filter, BenchmarkResult& suite_result) const { BenchmarkingThreadContext benchmarking_context; bool has_begun_suite = false; for (size_t i = 0; i < impl->m_factories.size(); ++i) { IBenchmarkCaseFactory* factory = impl->m_factories[i]; // Skip benchmark cases that aren't let through by the filter. if (!filter.accepts(factory->get_name())) continue; if (!has_begun_suite) { // Tell the listeners that a benchmark suite is about to be executed. suite_result.begin_suite(*this); suite_result.signal_suite_execution(); has_begun_suite = true; } // Instantiate the benchmark case. unique_ptr<IBenchmarkCase> benchmark(factory->create()); // Recreate the stopwatch (and the underlying timer) for every benchmark // case, since the CPU frequency will fluctuate quite a bit depending on // the CPU load. We need an up-to-date frequency estimation in order to // compute accurate call rates. Impl::StopwatchType stopwatch(100000); // Tell the listeners that a benchmark case is about to be executed. suite_result.begin_case(*this, *benchmark.get()); #ifdef NDEBUG try #endif { suite_result.signal_case_execution(); // Estimate benchmarking parameters. const size_t measurement_count = Impl::compute_measurement_count(benchmark.get(), stopwatch); // Measure the overhead of calling IBenchmarkCase::run(). const double overhead_ticks = Impl::measure_call_overhead_ticks(stopwatch, measurement_count); // Run the benchmark case. const double runtime_ticks = Impl::measure_runtime( benchmark.get(), stopwatch, BenchmarkSuite::Impl::measure_runtime_ticks, measurement_count); #ifdef GENERATE_BENCHMARK_PLOTS vector<Vector2d> points; for (size_t j = 0; j < 100; ++j) { const double ticks = Impl::measure_runtime( benchmark.get(), stopwatch, BenchmarkSuite::Impl::measure_runtime_ticks, max<size_t>(1, measurement_count / 100)); points.emplace_back( static_cast<double>(j), ticks > overhead_ticks ? ticks - overhead_ticks : 0.0); } stringstream sstr; sstr << "unit benchmarks/plots/"; sstr << get_name() << "_" << benchmark->get_name(); sstr << ".gnuplot"; GnuplotFile plotfile; plotfile.new_plot().set_points(points); plotfile.write(sstr.str()); #endif // Gather the timing results. TimingResult timing_result; timing_result.m_iteration_count = 1; timing_result.m_measurement_count = measurement_count; timing_result.m_frequency = static_cast<double>(stopwatch.get_timer().frequency()); timing_result.m_ticks = runtime_ticks > overhead_ticks ? runtime_ticks - overhead_ticks : 0.0; // Post the timing result. suite_result.write( *this, *benchmark.get(), __FILE__, __LINE__, timing_result); } #ifdef NDEBUG catch (const exception& e) { if (e.what()[0] != '\0') { suite_result.write( *this, *benchmark.get(), __FILE__, __LINE__, "an unexpected exception was caught: %s", e.what()); } else { suite_result.write( *this, *benchmark.get(), __FILE__, __LINE__, "an unexpected exception was caught (no details available)."); } suite_result.signal_case_failure(); } catch (...) { suite_result.write( *this, *benchmark.get(), __FILE__, __LINE__, "an unexpected exception was caught (no details available)."); suite_result.signal_case_failure(); } #endif // Tell the listeners that the benchmark case execution has ended. suite_result.end_case(*this, *benchmark.get()); } if (has_begun_suite) { // Report a benchmark suite failure if one or more benchmark cases failed. if (suite_result.get_case_failure_count() > 0) suite_result.signal_suite_failure(); // Tell the listeners that the benchmark suite execution has ended. suite_result.end_suite(*this); } }
void plot_dirpole_and_nd_r( const char* filename, const char* title, const double rd, const double dmfp) { GnuplotFile plotfile; plotfile.set_title(title); plotfile.set_xlabel("r"); plotfile.set_ylabel("r R(r)"); plotfile.set_xrange(0.0, 4.0); plotfile.set_yrange(0.001, 1.0); plotfile.set_logscale_y(); auto_release_ptr<BSSRDF> dp_bssrdf( DirectionalDipoleBSSRDFFactory().create("dirpole", ParamArray())); DipoleBSSRDFInputValues dp_values; init_dipole_bssrdf_values_rd_dmfp(rd, dmfp, 1.0, 0.0, dp_values); auto_release_ptr<BSSRDF> nd_bssrdf( NormalizedDiffusionBSSRDFFactory().create("norm_diff", ParamArray())); NormalizedDiffusionBSSRDFInputValues nd_values; nd_values.m_weight = 1.0; nd_values.m_reflectance.set(static_cast<float>(rd)); nd_values.m_reflectance_multiplier = 1.0; nd_values.m_dmfp = dmfp; nd_values.m_dmfp_multiplier = 1.0; nd_values.m_inside_ior = 1.0; nd_values.m_outside_ior = 1.0; nd_values.m_s.set(static_cast<float>(normalized_diffusion_s(rd))); const Vector3d normal(0.0, 1.0, 0.0); ShadingPoint outgoing; ShadingPointBuilder outgoing_builder(outgoing); outgoing_builder.set_primitive_type(ShadingPoint::PrimitiveTriangle); outgoing_builder.set_point(Vector3d(0.0, 0.0, 0.0)); outgoing_builder.set_shading_basis(Basis3d(normal)); ShadingPoint incoming; ShadingPointBuilder incoming_builder(incoming); incoming_builder.set_primitive_type(ShadingPoint::PrimitiveTriangle); incoming_builder.set_shading_basis(Basis3d(normal)); const size_t N = 1000; vector<Vector2d> nd_points, dp_points; for (size_t j = 0; j < N; ++j) { const double r = max(fit<size_t, double>(j, 0, N - 1, 0.0, 4.0), 0.0001); incoming_builder.set_point(Vector3d(r, 0.0, 0.0)); Spectrum result; dp_bssrdf->evaluate( &dp_values, outgoing, normal, incoming, normal, result); dp_points.push_back(Vector2d(r, result[0])); nd_bssrdf->evaluate( &nd_values, outgoing, normal, incoming, normal, result); nd_points.push_back(Vector2d(r, result[0])); } plotfile .new_plot() .set_points(dp_points) .set_title("dirpole") .set_color("orange"); plotfile .new_plot() .set_points(nd_points) .set_title("normdiff") .set_color("blue"); plotfile.write(filename); }