Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64525 - sandbox/SOC/2010/quasi_random/libs/random/example
From: jvd_at_[hidden]
Date: 2010-08-01 12:55:28


Author: qrng
Date: 2010-08-01 12:55:27 EDT (Sun, 01 Aug 2010)
New Revision: 64525
URL: http://svn.boost.org/trac/boost/changeset/64525

Log:
Modified file names

Added:
   sandbox/SOC/2010/quasi_random/libs/random/example/cauchy_crofton.cpp
      - copied, changed from r64521, /sandbox/SOC/2010/quasi_random/libs/random/example/cauchy-crofton.cpp
   sandbox/SOC/2010/quasi_random/libs/random/example/cauchy_crofton_convergence.png
      - copied unchanged from r64521, /sandbox/SOC/2010/quasi_random/libs/random/example/Cauchy-Crofton convergence.png
Removed:
   sandbox/SOC/2010/quasi_random/libs/random/example/Cauchy-Crofton convergence.png
   sandbox/SOC/2010/quasi_random/libs/random/example/cauchy-crofton.cpp
Text files modified:
   sandbox/SOC/2010/quasi_random/libs/random/example/cauchy_crofton.cpp | 4 ++--
   1 files changed, 2 insertions(+), 2 deletions(-)

Deleted: sandbox/SOC/2010/quasi_random/libs/random/example/Cauchy-Crofton convergence.png
==============================================================================
Binary file. No diff available.

Deleted: sandbox/SOC/2010/quasi_random/libs/random/example/cauchy-crofton.cpp
==============================================================================
--- sandbox/SOC/2010/quasi_random/libs/random/example/cauchy-crofton.cpp 2010-08-01 12:55:27 EDT (Sun, 01 Aug 2010)
+++ (empty file)
@@ -1,112 +0,0 @@
-// Copyright Justinas Vygintas Daugmaudis, 2010.
-// Use, modification and distribution is subject to the
-// Boost Software License, Version 1.0. (See accompanying
-// file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
-
-#include <boost/random/niederreiter_base2.hpp>
-#include <boost/random/uniform_real.hpp>
-#include <boost/math/constants/constants.hpp>
-
-#include <iostream>
-
-//
-// DESCRIPTION:
-// ~~~~~~~~~~~~
-//
-// Samples the surface area of a box using the Cauchy-Crofton method.
-// The example is intentionally simple. It is important to note that while
-// the surface area of a box is easy to compute, it is not always the case,
-// especially if one needs to compute the surface area of an isosurface. This,
-// for example, is useful when one computes solvent excluded protein surface area;
-// in that case one would replace a 'box' with, for example, a 'protein_model'.
-
-#include "box_intersection.hpp"
-
-
-template<typename Engine, typename Vector, typename T>
-void uniform_chords(Engine& gen, const Vector& center, T radius, std::size_t n_chords,
- std::vector<Vector>& points)
-{
- const T angle = 2 * boost::math::constants::pi<T>();
-
- const std::size_t n_points = n_chords * 2;
-
- boost::uniform_real<T> rnd;
-
- Vector point_on_sphere;
-
- // Using formula from Rovira 05 to compute points uniformly
- // distributed on the surface of a sphere
- for(std::size_t i = 0; i != n_points; ++i)
- {
- T cos_theta = 1 - 2 * rnd(gen);
- T sin_theta = std::sqrt(1 - (cos_theta * cos_theta));
- T phi = angle * rnd(gen);
- T sin_phi = std::sin(phi), cos_phi = std::cos(phi); // consider using sincos function
-
- point_on_sphere = sin_theta*sin_phi, cos_theta, sin_theta*cos_phi;
-
- point_on_sphere *= radius;
- point_on_sphere += center;
-
- points.push_back(point_on_sphere);
- } // surface point generation
-}
-
-
-template<typename Engine>
-void cauchy_crofton(Engine& gen, const example::box& model, std::size_t n_chords)
-{
- typedef typename example::box::vector_t vector_t;
- typedef typename vector_t::value_type value_t;
-
- std::cout << "Sample surface area, number of chords = " << n_chords << "\n";
-
- vector_t bounding_sphere_center = (model.min_corner() + model.max_corner()) * 0.5f;
- value_t bounding_sphere_radius = math::distance(bounding_sphere_center, model.max_corner());
- value_t bounding_sphere_area = 4 * boost::math::constants::pi<value_t>() *
- (bounding_sphere_radius * bounding_sphere_radius);
-
- std::vector<vector_t> points;
-
- // Generate uniformly distributed chord entry and exit points on a S^2 ball
- uniform_chords(gen, bounding_sphere_center, bounding_sphere_radius, n_chords, points);
-
- // Compute the number of chords that intersect a given Model
- std::size_t points_on_model = 0;
- for(std::size_t i = 0; i != points.size(); i += 2)
- {
- example::ray r(points[i], points[i+1] - points[i]);
- if( model.intersect(r, 0, 1) ) {
- points_on_model += 2; // this is an approximation,
- } // but sufficient enough for this particular example
- }
-
- value_t sampled_area =
- static_cast<value_t>(points_on_model) /
- static_cast<value_t>(points.size())
- * bounding_sphere_area;
-
- std::cout
- << "Bounding sphere area: " << bounding_sphere_area << "\n"
- << "Points on model: " << points_on_model << "\n"
- << "Points on sphere: " << points.size() << "\n"
- << "Sampled area: " << sampled_area << "\n"
- ;
-}
-
-
-int main()
-{
- example::box aab(1.f, 0.3f, 0.2f); // a simple slightly oblong box
-
- std::cout << "The analytical surface area of a box: " << aab.surface_area() << "\n";
-
- boost::niederreiter_base2_4d gen_4d; // QRNG must be 4-dimensional!
- cauchy_crofton(gen_4d, aab, 500);
-
- gen_4d.seed(); // restart the generator in order to repeat the experiment above
- cauchy_crofton(gen_4d, aab, 5000);
-
- return 0;
-}

Copied: sandbox/SOC/2010/quasi_random/libs/random/example/cauchy_crofton.cpp (from r64521, /sandbox/SOC/2010/quasi_random/libs/random/example/cauchy-crofton.cpp)
==============================================================================
--- /sandbox/SOC/2010/quasi_random/libs/random/example/cauchy-crofton.cpp (original)
+++ sandbox/SOC/2010/quasi_random/libs/random/example/cauchy_crofton.cpp 2010-08-01 12:55:27 EDT (Sun, 01 Aug 2010)
@@ -27,7 +27,7 @@
 void uniform_chords(Engine& gen, const Vector& center, T radius, std::size_t n_chords,
     std::vector<Vector>& points)
 {
- const T angle = 2 * boost::math::constants::pi<T>();
+ const T two_pi = 2 * boost::math::constants::pi<T>();
 
   const std::size_t n_points = n_chords * 2;
 
@@ -41,7 +41,7 @@
   {
     T cos_theta = 1 - 2 * rnd(gen);
     T sin_theta = std::sqrt(1 - (cos_theta * cos_theta));
- T phi = angle * rnd(gen);
+ T phi = two_pi * rnd(gen);
     T sin_phi = std::sin(phi), cos_phi = std::cos(phi); // consider using sincos function
 
     point_on_sphere = sin_theta*sin_phi, cos_theta, sin_theta*cos_phi;


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk