1. Alexander Konovalov
  2. poissonraytracer

Commits

Alexander Konovalov  committed 91783a7

Various fixes

  • Participants
  • Parent commits ef92505
  • Branches default

Comments (0)

Files changed (8)

File core/hit.cpp

View file
  • Ignore whitespace
     float* newTheta,
     float* newIntensity,
     float* newX) {
-  assert(-1 <= impactParameter && impactParameter <= 1);
-  assert(relativeRefractionIndex > 0);
-  assert(newImpactParameter != NULL);
-  assert(newTheta != NULL);
-  assert(newIntensity != NULL);
-  assert(newX != NULL);
+  MPI_ASSERT(-1 <= impactParameter && impactParameter <= 1);
+  MPI_ASSERT(relativeRefractionIndex > 0);
+  MPI_ASSERT(newImpactParameter != NULL);
+  MPI_ASSERT(newTheta != NULL);
+  MPI_ASSERT(newIntensity != NULL);
+  MPI_ASSERT(newX != NULL);
 
   float h = impactParameter;
   float n = relativeRefractionIndex;
 
-  if (h == 1 || h == -1) {
+  if (h >= 1 || h <= -1) {
     *newImpactParameter = h;
     *newTheta = 0;
     *newIntensity = 1;
   float alphaSin = h / n;
   if (abs(alphaSin) >= 1) {  // full reflection
     *newImpactParameter = h;
-    *newTheta = 2 *asin(h);
+    *newTheta = 2 * asin(h);
     *newIntensity = 1;
-    *newX = - sqrt(1-h*h);
+    *newX = -sqrt(1 - h * h);
     return 0;
   }
 

File core/mpi_assert.h

View file
  • Ignore whitespace
 
 #include <cassert>
 
-#ifdef assert
-  #undef assert
-#endif
-
 extern void __mpi_assert_fail(__const char *__assertion, __const char *__file,
                               unsigned int __line, __const char *__function);
-     
-#define assert(expr) \
+
+#define MPI_ASSERT(expr) \
   ((expr) \
    ? __ASSERT_VOID_CAST(0) \
    : __mpi_assert_fail(__STRING(expr), __FILE__, __LINE__, __PRETTY_FUNCTION__))

File core/random.cpp

View file
  • Ignore whitespace
 }
 
 void RandomPointOnDisk(float maxRadius, float* angle, float* radius) {
-  assert(maxRadius > 0);
+  MPI_ASSERT(maxRadius > 0);
   // For explanation @see
   // http://www.ece.virginia.edu/mv/edu/prob/stat/random-number-generation.pdf
   // Since the total area of the tube front side is pi * r^2,
 
   if (*radius >= maxRadius)
     std::cout << *radius << " Max = " << maxRadius << '\n';
-  assert(*radius < maxRadius);
+  MPI_ASSERT(*radius < maxRadius);
 }

File core/sphere.cpp

View file
  • Ignore whitespace
     Eigen::Vector3f* b) {
   using Eigen::Vector3f;
 
-  assert(!isnan(vec.norm()));
-  assert(!isinf(vec.norm()));
-  assert(vec.norm() > 0);
-  assert(a != NULL);
-  assert(b != NULL);
+  MPI_ASSERT(!isnan(vec.norm()));
+  MPI_ASSERT(!isinf(vec.norm()));
+  MPI_ASSERT(vec.norm() > 0);
+  MPI_ASSERT(a != NULL);
+  MPI_ASSERT(b != NULL);
 
   Vector3f z(0, 0, 1.0);
   Vector3f vec_norm = vec;
   x.normalize();
   y.normalize();
 
-  assert(!isnan(x.norm()) && !isnan(y.norm()));
+  MPI_ASSERT(!isnan(x.norm()) && !isnan(y.norm()));
 
-  assert(fabs(x.dot(y)) < kFloatEpsilon);
-  assert(fabs(x.dot(vec)) < kFloatEpsilon);
-  assert(fabs(y.dot(vec)) < kFloatEpsilon);
+  MPI_ASSERT(fabs(x.dot(y)) < kFloatEpsilon);
+  MPI_ASSERT(fabs(x.dot(vec)) < kFloatEpsilon);
+  MPI_ASSERT(fabs(y.dot(vec)) < kFloatEpsilon);
 
-  assert(fabs(x.squaredNorm() - 1) < kFloatEpsilon);
-  assert(fabs(y.squaredNorm() - 1) < kFloatEpsilon);
+  MPI_ASSERT(fabs(x.squaredNorm() - 1) < kFloatEpsilon);
+  MPI_ASSERT(fabs(y.squaredNorm() - 1) < kFloatEpsilon);
 
   *a = x;
   *b = y;
     const float            distance,
     Eigen::Vector3f* sphereCentre) {
   // Check if the ray direction is valid.
-  assert(abs(rayDirection.squaredNorm() - 1) < kFloatEpsilon);
-  assert(!isnan(rayDirection.norm()) && !isinf(rayDirection.norm()));
+  MPI_ASSERT(fabs(rayDirection.squaredNorm() - 1) < kFloatEpsilon);
+  MPI_ASSERT(!isnan(rayDirection.norm()) && !isinf(rayDirection.norm()));
 
   // Check if the forward distance is valid.
-  assert(distance >= 0 && !isinf(distance) && !isnan(distance));
+  MPI_ASSERT(distance >= 0 && !isinf(distance) && !isnan(distance));
 
   // Check if the angle is valid.
-  assert(angle >= 0 && angle <= 2 * M_PI);
-  assert(!isinf(angle) && !isnan(angle));
+  MPI_ASSERT(angle >= 0 && angle <= 2 * M_PI);
+  MPI_ASSERT(!isinf(angle) && !isnan(angle));
 
   // Check if the radius is valid.
-  assert(radius >= 0 && !isinf(radius) && !isnan(radius));
+  MPI_ASSERT(radius >= 0 && !isinf(radius) && !isnan(radius));
 
   // Generate three mutually orthogonal vectors.
   Eigen::Vector3f x, y, z;
 
   *sphereCentre = z * distance + r * radius;
 
-  assert((*sphereCentre).norm() >= distance * distance + radius * radius);
-  assert(!isnan(sphereCentre->norm()));
-  assert(!isinf(sphereCentre->norm()));
+  MPI_ASSERT((*sphereCentre).norm() >= distance * distance + radius * radius);
+  MPI_ASSERT(!isnan(sphereCentre->norm()));
+  MPI_ASSERT(!isinf(sphereCentre->norm()));
 }

File core/vhit.cpp

View file
  • Ignore whitespace
 #include <cstdlib>
 #include <algorithm>
 #include <limits>
+#include <iostream>
 
 #include "core/mpi_assert.h"
 #include "core/hit.h"
 
 namespace {
-const float kFloatEpsilon = std::numeric_limits<float>::epsilon();
+const float kFloatEpsilon = std::numeric_limits<float>::epsilon() * 10;
 }
 
 bool SimpleSphereHit(
     Eigen::Vector3f*       newOrigin,
     Eigen::Vector3f*       newDirection,
     float*                 newIntensity) {
-  assert(sphereCentre.squaredNorm() >= sphereRadius * sphereRadius);
-  assert(abs(rayDirection.squaredNorm() - 1) < kFloatEpsilon);
-  assert(rayDirection.norm() > 0);
-  assert(!isnan(sphereCentre.norm()) && !isinf(sphereCentre.norm()));
-  assert(sphereRadius > 0);
-  assert(relativeRefractionIndex > 0);
-  assert(newOrigin != NULL);
-  assert(newDirection != NULL);
-  assert(newIntensity != NULL);
+  MPI_ASSERT(sphereCentre.squaredNorm() >= sphereRadius * sphereRadius);
+  MPI_ASSERT(fabs(rayDirection.squaredNorm() - 1) < kFloatEpsilon);
+  MPI_ASSERT(rayDirection.norm() > 0);
+  MPI_ASSERT(!isnan(sphereCentre.norm()) && !isinf(sphereCentre.norm()));
+  MPI_ASSERT(sphereRadius > 0);
+  MPI_ASSERT(relativeRefractionIndex > 0);
+  MPI_ASSERT(newOrigin != NULL);
+  MPI_ASSERT(newDirection != NULL);
+  MPI_ASSERT(newIntensity != NULL);
 
   Eigen::Vector3f a = rayDirection * rayDirection.dot(sphereCentre);
   Eigen::Vector3f b = a - sphereCentre;
 
   float h = b.norm();
-  assert(!isnan(h));
-  assert(!isinf(h));
+  MPI_ASSERT(!isnan(h));
+  MPI_ASSERT(!isinf(h));
 
-  // Check that there is no intersection with the sphere.
+  // Check if there is no intersection with the sphere.
   if ((rayDirection.dot(sphereCentre) < 0) || (h > sphereRadius)) {
     // NOTE(alexknvl): The first condition is extremely unlikely to happen.
     //   I have never actually seen it happening.
+
     return false;
   }
 
 
   *newOrigin = sphereCentre + rayOrigin + sphereRadius * (a * xOut + b * hOut);
   *newDirection = a * cos(thetaOut) + b * sin(thetaOut);
+  (*newDirection).normalize();
   *newIntensity = iOut;
 
-  assert(abs((*newDirection).norm() - 1.0f) <= kFloatEpsilon);
-  assert(0 <= (*newIntensity) && (*newIntensity) <= 1);
+  MPI_ASSERT(fabs((*newDirection).norm() - 1.0f) <= kFloatEpsilon);
+  MPI_ASSERT(0 <= (*newIntensity) && (*newIntensity) <= 1);
   return true;
 }

File experiments/scattering_diagram/mc_alister.cfg

View file
  • Ignore whitespace
 averageSphereRadius          = 1e-3;
 sphereRadiusDeviation        = 0.00001;
 refractionIndexDeviation     = 0.0002;
-targetPrecision              = 0.01;
+targetPrecision              = 0.005;
 minPhotons                   = 100;
 
-minRefractiveIndex           = 0.980;
-maxRefractiveIndex           = 1.020;
-refractiveIndexStep          = 0.0001;
+minRefractiveIndex           = 0.750;
+maxRefractiveIndex           = 1.250;
+refractiveIndexStep          = 0.001;
 outputFileName               = "results/ns.dat";
 
 scatteringDiagramPoints      = 100;

File rt/simulator.cpp

View file
  • Ignore whitespace
         // Numerical error can lead to a properly generated sphere still
         // being too close.
         if (sphereCentre.squaredNorm() < sphereRadius * sphereRadius) {
-          fprintf(stderr, "Sphere too close, regenerating a new sphere.");
+          fprintf(stderr, "Sphere too close, regenerating a new sphere.\n");
           continue;
         }
 
                         &photon.position, &photon.direction, &newIntensity);
 
         if (!hit) {
-          fprintf(stderr, "No hit, regenerating a new sphere.");
+          fprintf(stderr, "No hit, regenerating a new sphere.\n");
           continue;
         }
 

File utils/plot_scattering.py

View file
  • Ignore whitespace
 if __name__ == "__main__":
     data = np.genfromtxt(sys.argv[1])
     n_data = data.T[0]
+    print(n_data)
+    print(len(n_data))
 
     # prepare scatter data
-    scatter_data = data[1:,:]
+    scatter_data = data.T[1:].T
     scatter_points = len(scatter_data[0,:])
     print(scatter_points)
     scatter_data = np.append(scatter_data[:, ::-1], scatter_data, axis=1) / 2