Skip to content

Commit

Permalink
Define M_PI_2 on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
tobre1 committed Feb 4, 2025
1 parent 1fe0671 commit 8c53721
Show file tree
Hide file tree
Showing 2 changed files with 212 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/viennaray/rayUtil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
#define M_PI 3.14159265358979323846
#endif

#ifndef M_PI_2
#define M_PI_2 1.57079632679489661923
#endif

namespace viennaray {

using namespace viennacore;
Expand Down
208 changes: 208 additions & 0 deletions tests/reflection/visualize.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 194,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 195,
"metadata": {},
"outputs": [],
"source": [
"path = '../../build/tests/reflection/'"
]
},
{
"cell_type": "code",
"execution_count": 196,
"metadata": {},
"outputs": [],
"source": [
"diffuse = np.genfromtxt(path + 'diffuse_reflection.txt')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# arrow plot in 3D\n",
"fig = plt.figure()\n",
"ax = fig.add_subplot(111, projection='3d')\n",
"\n",
"# draw arrow\n",
"for ref in diffuse[:100]:\n",
" ax.quiver(0, 0, 0, ref[0], ref[1], ref[2], color='blue', alpha=0.5)\n",
"\n",
"ax.set_xlim([-1, 1])\n",
"ax.set_ylim([-1, 1])\n",
"ax.set_zlim([0, 1])\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# theta and phi\n",
"theta = np.arccos(diffuse[:, 2])\n",
"phi = np.arctan2(diffuse[:, 1], diffuse[:, 0])\n",
"\n",
"plt.hist(theta, bins=100, histtype='step', color='blue', label='theta', density=True)\n",
"plt.hist(phi, bins=100, histtype='step', color='red', label='phi', density=True)\n",
"\n",
"# expected distribution\n",
"theta = np.linspace(0, np.pi / 2, 100)\n",
"plt.plot(theta, np.sin(theta * 2), '--', color='blue', label='sin(theta)')\n",
"\n",
"plt.show()\n"
]
},
{
"cell_type": "code",
"execution_count": 199,
"metadata": {},
"outputs": [],
"source": [
"conedSpecularOld = np.genfromtxt(path + 'coned_specular_reflection_old.txt')\n",
"conedSpecular = np.genfromtxt(path + 'coned_specular_reflection.txt')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# arrow plot in 3D\n",
"fig = plt.figure()\n",
"ax = fig.add_subplot(111, projection='3d')\n",
"\n",
"# draw arrow\n",
"for ref in conedSpecular[:100]:\n",
" ax.quiver(0, 0, 0, ref[0], ref[1], ref[2], color='blue', alpha=0.5)\n",
"\n",
"ax.set_xlim([-1, 1])\n",
"ax.set_ylim([-1, 1])\n",
"ax.set_zlim([0, 1])\n",
"plt.title(\"New\")\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4)) \n",
"\n",
"# theta and phi\n",
"theta = np.arccos(conedSpecular[:, 2])\n",
"phi = np.arctan2(conedSpecular[:, 1], conedSpecular[:, 0])\n",
"\n",
"ax1.hist(theta, bins=80, histtype='step', color='blue', label='theta', density=True)\n",
"ax1.hist(phi, bins=80, histtype='step', color='red', label='phi', density=True)\n",
"ax1.set_xlim([-np.pi, np.pi])\n",
"ax1.set_title('New')\n",
"\n",
"theta = np.arccos(conedSpecularOld[:, 2])\n",
"phi = np.arctan2(conedSpecularOld[:, 1], conedSpecularOld[:, 0])\n",
"\n",
"ax2.hist(theta, bins=80, histtype='step', color='blue', label='theta', density=True)\n",
"ax2.hist(phi, bins=80, histtype='step', color='red', label='phi', density=True)\n",
"ax2.set_xlim([-np.pi, np.pi])\n",
"ax2.set_title('Old')\n",
"\n",
"plt.show()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, (ax1) = plt.subplots(1, 1, figsize=(6, 4)) \n",
"\n",
"# theta and phi\n",
"theta = np.arccos(conedSpecular[:, 2])\n",
"phi = np.arctan2(conedSpecular[:, 1], conedSpecular[:, 0])\n",
"\n",
"ax1.hist(theta, bins=80, histtype='step', color='blue', label='theta new', density=True)\n",
"ax1.hist(phi, bins=80, histtype='step', color='red', label='phi new', density=True)\n",
"ax1.set_xlim([-np.pi, np.pi])\n",
"ax1.set_title('New')\n",
"\n",
"theta = np.arccos(conedSpecularOld[:, 2])\n",
"phi = np.arctan2(conedSpecularOld[:, 1], conedSpecularOld[:, 0])\n",
"\n",
"ax1.hist(theta, bins=80, histtype='step', color='purple', label='theta old', density=True)\n",
"ax1.hist(phi, bins=80, histtype='step', color='orange', label='phi old', density=True)\n",
"\n",
"plt.legend()\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# arrow plot in 3D\n",
"fig = plt.figure()\n",
"ax = fig.add_subplot(111, projection='3d')\n",
"\n",
"# draw arrow\n",
"for ref in conedSpecularOld[:100]:\n",
" ax.quiver(0, 0, 0, ref[0], ref[1], ref[2], color='blue', alpha=0.5)\n",
"\n",
"ax.set_xlim([-1, 1])\n",
"ax.set_ylim([-1, 1])\n",
"ax.set_zlim([0, 1])\n",
"plt.title('Old')\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 8c53721

Please sign in to comment.