<jupyter_start><jupyter_text>[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/Bratusse/WGAN-caustics/blob/main/notebooks/Caustics_using_Poisson_equation.ipynb) This notebook is an implementation of the technique presented in this paper https://www.researchgate.net/publication/274483217_Poisson-Based_Continuous_Surface_Generation_for_Goal-Based_Caustics.There are some variations in the way the loss is calculated, but the rest is as described in the paper. **I am not the inventor of the technique**, but merely a programming enthusiast, and an optics addict. :)The output file is supposed to be used directly in Blender, with a screen positioned at y=H, and rendering with LuxRender engines.You have to choose **one variation** or the other, usually, the "Mesh-cells variation" is faster and gives better, more contrasted results. I kept the other because it is supposed to be more close to the theory, and doesn't interpolate the loss.If you want to contact me you can send me an email, I'd be happy to hear about the way this tool can be used : <EMAIL>.  Install Fenics and other libraries<jupyter_code>!sudo apt-key del <KEY>
!sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/3bf863cc.pub
try:
    import dolfin
except ImportError:
    !wget "https://fem-on-colab.github.io/releases/fenics-install.sh" -O "/tmp/fenics-install.sh" && bash "/tmp/fenics-install.sh"
    import dolfin
!pip install trimesh
!pip install shapely
!pip install rtree<jupyter_output>Collecting trimesh
  Downloading trimesh-3.12.0-py3-none-any.whl (646 kB)
[?25l
[K     |▌                               | 10 kB 21.1 MB/s eta 0:00:01
[K     |█                               | 20 kB 16.6 MB/s eta 0:00:01
[K     |█▌                              | 30 kB 11.1 MB/s eta 0:00:01
[K     |██                              | 40 kB 9.2 MB/s eta 0:00:01
[K     |██▌                             | 51 kB 4.3 MB/s eta 0:00:01
[K     |███                             | 61 kB 5.0 MB/s eta 0:00:01
[K     |███▌                            | 71 kB 5.5 MB/s eta 0:00:01
[K     |████                            | 81 kB 4.2 MB/s eta 0:00:01
[K     |████▋                           | 92 kB 4.6 MB/s eta 0:00:01
[K     |█████                           | 102 kB 5.1 MB/s eta 0:00:01
[K     |█████▋                          | 112 kB 5.1 MB/s eta 0:00:01
[K     |██████                          | 122 kB 5.1 MB/s eta 0:00:01
[K     |██████▋                         | 133 kB 5.1 MB/s eta 0:00:01
[[...]<jupyter_text>Imports<jupyter_code>!git clone https://github.com/Bratusse/WGAN_caustics.git
%cd WGAN_caustics/src/poisson/
from poisson_caustics import CausticsDesign
import PIL
import matplotlib.pyplot as plt
%cd ../../..
%matplotlib inline<jupyter_output><empty_output><jupyter_text>Parameters<jupyter_code>#@title Titre par défaut
file_name = 'image_oeil'
file_ext = '.jpg'
object_size = 1.        # Width size in meters
res_img =     250       # Number of pixels in width that you want (resizing is performed automatically)
it_nb =       20        # Number of iterations to do (usually the more the better)
rho =         1.49      # Refraction index of the material used to 
H =           2.        # Distance to the screen (in meters)
voron =       False     # Using Voronoi method or Cell method<jupyter_output><empty_output><jupyter_text>Code<jupyter_code>img_grey = PIL.Image.open(file_name+file_ext).convert('L')
mydesign = CausticsDesign("mydesign", img_grey, object_size)

mydesign.generate_grid_mesh(res_img)
mydesign.compute_loss(voron)
mydesign.show_image()
mydesign.show_loss()
mydesign.compute_transport_map(it_nb)
strife = 3
plt.plot(mydesign.lens_grid[::strife,::strife,0],mydesign.lens_grid[::strife,::strife,1], 'r-');
plt.plot(mydesign.lens_grid[::strife,::strife,0].T,mydesign.lens_grid[::strife,::strife,1].T, 'r-');
plt.axis('equal');<jupyter_output><empty_output><jupyter_text>Compute the height and save to .stl<jupyter_code>mydesign.compute_height(rho, H);
mydesign.save_mesh()
mydesign.show_height()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12243914196191853, 'fraction_numerical': 0.04097372860930345, 'mean_word_length': 2.8640595903165735, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 5, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '437039', 'license': 'MIT', 'n_tokens_mistral': 1602, 'n_tokens_neox': 1423, 'n_words': 379, 'path': 'notebooks/Caustics_using_Poisson_equation.ipynb', 'repo_name': 'Bratusse/WGAN-caustics', 'size': '4178'}