Skip to content

Commit

Permalink
Merge pull request #354 from favreau/master
Browse files Browse the repository at this point in the history
Fixed focal distance widget / Optix6 engine
  • Loading branch information
favreau authored Jan 22, 2024
2 parents 2854571 + 1fb835c commit bfedd29
Show file tree
Hide file tree
Showing 28 changed files with 486 additions and 381 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ static __device__ inline void shade(bool textured)
}

prd.result = make_float4(color, opacity);
prd.zDepth = optix::length(eye - hit_point);
}

RT_PROGRAM void any_hit_shadow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ static __device__ inline void shade()
}

prd.result = make_float4(::optix::clamp(color, 0.f, 1.f), opacity);
prd.zDepth = optix::length(eye - hit_point);
}

RT_PROGRAM void any_hit_shadow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ static __device__ inline void shade()
const float3 hit_point = ray.origin + t_hit * ray.direction;
const float depth = 1.f - ::optix::length(eye - hit_point) / infinity;
prd.result = make_float4(make_float3(depth), 1.f);
prd.zDepth = optix::length(eye - hit_point);
}

RT_PROGRAM void any_hit_shadow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ static __device__ inline void shade()
{
const float3 world_geometric_normal = optix::normalize(rtTransformNormal(RT_OBJECT_TO_WORLD, geometric_normal));
prd.result = make_float4(0.5 + 0.5 * world_geometric_normal, 1.f);
const float3 hit_point = ray.origin + t_hit * ray.direction;
prd.zDepth = optix::length(eye - hit_point);
}

RT_PROGRAM void any_hit_shadow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
static __device__ inline void shade()
{
prd.result = make_float4(Ka, 1.f);
const float3 hit_point = ray.origin + t_hit * ray.direction;
prd.zDepth = optix::length(eye - hit_point);
}

RT_PROGRAM void any_hit_shadow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ static __device__ inline void shade()
{
const float3 world_shading_normal = optix::normalize(rtTransformNormal(RT_OBJECT_TO_WORLD, shading_normal));
prd.result = make_float4(0.5 + 0.5 * world_shading_normal, 1.f);
const float3 hit_point = ray.origin + t_hit * ray.direction;
prd.zDepth = optix::length(eye - hit_point);
}

RT_PROGRAM void any_hit_shadow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ static __device__ inline void shade()
}
attenuation = ::optix::clamp(attenuation / float(shadowSamples), 0.f, 1.f);
prd.result = make_float4(make_float3(attenuation), 1.f);
prd.zDepth = optix::length(eye - hit_point);
}

RT_PROGRAM void any_hit_shadow()
Expand Down
88 changes: 44 additions & 44 deletions bioexplorer/pythonsdk/bioexplorer/notebook_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,14 @@ def __init__(self, bioexplorer):
self._be = bioexplorer
self._client = bioexplorer.core_api()

def display_focal_distance(self, with_preview=False):
def focal_distance(self, with_preview=False):
"""Display visual controls for setting camera focal distance"""
x_slider = FloatSlider(description="X", min=0, max=1, value=0.5)
y_slider = FloatSlider(description="Y", min=0, max=1, value=0.5)
a_slider = FloatSlider(description="Aperture", min=0, max=1, value=0)
f_slider = FloatSlider(description="Focus radius", min=0, max=1, value=0.01)
x_slider = FloatSlider(description="X", min=0.0, max=1.0, value=0.5)
y_slider = FloatSlider(description="Y", min=0.0, max=1.0, value=0.5)
a_slider = FloatSlider(description="Aperture", min=0.0, max=10.0, value=0.0)
f_slider = FloatSlider(description="Focus radius", min=0.0, max=1.0, value=0.01)
d_slider = FloatSlider(
description="Focus distance", min=0, max=10000, value=0, disabled=True
description="Focus distance", min=0.0, max=10000.0, value=0.0, disabled=True
)
f_button = Button(description="Refresh")
f_target = Button(description="Target")
Expand All @@ -272,31 +272,31 @@ def __init__(self, client, with_preview):
self._widget_value = None
self._x = 0.5
self._y = 0.5
self._aperture = 0.0
self._focus_radius = 0.01
self._focus_distance = 0.0
self._nb_focus_points = 20
self._aperture_radius = 0.0
self._focal_radius = 0.01
self._focal_distance = 0.0
self._nb_focal_points = 20
self._snapshot = None
self._with_preview = with_preview

def _update_camera(self):
self._focus_distance = 1e6
for _ in range(self._nb_focus_points):
self._focus_distance = min(
self._focus_distance,
self._focal_distance = 1e6
for _ in range(self._nb_focal_points):
self._focal_distance = min(
self._focal_distance,
self._get_focal_distance(
(
self._x + random.random() * self._focus_radius,
self._y + random.random() * self._focus_radius,
self._x + random.random() * self._focal_radius,
self._y + random.random() * self._focal_radius,
)
),
)

params = self._client.PerspectiveCameraParams()
params.focus_distance = self._focus_distance
params.aperture_radius = self._aperture
params.focal_distance = self._focal_distance
params.aperture_radius = self._aperture_radius
params.enable_clipping_planes = True
d_slider.value = self._focus_distance
d_slider.value = self._focal_distance
self._client.set_camera_params(params)

if self._with_preview:
Expand All @@ -317,16 +317,16 @@ def update_target(self):
self._client.set_camera(target=position)
self._client.set_renderer()

def update_focus_radius(self, val_dict) -> None:
def update_focal_radius(self, val_dict) -> None:
"""Update camera focus radius"""
self._widget_value = val_dict["new"]
self._focus_radius = self._widget_value
self._focal_radius = self._widget_value
self._update_camera()

def update_aperture(self, val_dict) -> None:
def update_aperture_radius(self, val_dict) -> None:
"""Update camera aperture"""
self._widget_value = val_dict["new"]
self._aperture = self._widget_value
self._aperture_radius = self._widget_value
self._update_camera()

def update_x(self, val_dict) -> None:
Expand Down Expand Up @@ -372,8 +372,8 @@ def _get_preview(self, update_image):

x = self._x * size[0]
y = (1.0 - self._y) * size[1]
rx = self._focus_radius * size[0]
ry = self._focus_radius * size[1]
rx = self._focal_radius * size[0]
ry = self._focal_radius * size[1]
byte_io = io.BytesIO()
snapshot = self._snapshot.copy()
draw = ImageDraw.Draw(snapshot)
Expand All @@ -392,11 +392,11 @@ def update_x(value):
def update_y(value):
update_class.update_y(value)

def update_aperture(value):
update_class.update_aperture(value)
def update_aperture_radius(value):
update_class.update_aperture_radius(value)

def update_focus_radius(value):
update_class.update_focus_radius(value)
def update_focal_radius(value):
update_class.update_focal_radius(value)

def update_button(_):
update_class.update()
Expand All @@ -406,8 +406,8 @@ def update_target(_):

x_slider.observe(update_x, "value")
y_slider.observe(update_y, "value")
a_slider.observe(update_aperture, "value")
f_slider.observe(update_focus_radius, "value")
a_slider.observe(update_aperture_radius, "value")
f_slider.observe(update_focal_radius, "value")
f_button.on_click(update_button)
f_target.on_click(update_target)

Expand All @@ -423,7 +423,7 @@ def update_target(_):
preview = Image(value=byte_io.getvalue(), format="png", width=1, height=1)
display(preview)

def display_palette_for_models(self):
def model_material(self):
"""Display visual controls for color palettes applied to models"""
def set_colormap(model_id, colormap_name, shading_mode):
material_ids = self._be.get_material_ids(model_id)["ids"]
Expand Down Expand Up @@ -546,7 +546,7 @@ def update_materials_from_chameleon_modes(_):
)
display(vertical_box)

def display_model_visibility(self):
def model_visibility(self):
"""Display visual controls for setting visibility of models"""
model_names = list()
for model in self._client.scene.models:
Expand Down Expand Up @@ -640,7 +640,7 @@ def adjust_camera(event):
hbox = HBox([model_select, hbox_params], layout=Widgets.DEFAULT_GRID_LAYOUT)
display(hbox)

def display_model_focus(self, max_number_of_instances=1e6):
def model_focus(self, max_number_of_instances=1e6):
"""Display visual controls for setting visibility of models"""
directions = dict()
directions["front"] = Vector3(0, 0, -1)
Expand Down Expand Up @@ -699,7 +699,7 @@ def focus_on_instance(event):

display(vbox)

def __display_advanced_settings(self, object_type, threaded):
def __advanced_settings(self, object_type, threaded):
"""Display visual controls for camera or renderer advanced settings"""
class Updated:
"""Inner class that insures communication with the remote server"""
Expand Down Expand Up @@ -845,15 +845,15 @@ def _create_widgets(self):
hbox = VBox(vboxes, layout=Widgets.DEFAULT_GRID_LAYOUT)
display(hbox)

def display_advanced_rendering_settings(self, is_threaded=True):
def advanced_rendering_settings(self, is_threaded=True):
"""Display visual controls for renderer advanced settings"""
self.__display_advanced_settings("renderer", is_threaded)
self.__advanced_settings("renderer", is_threaded)

def display_advanced_camera_settings(self, is_threaded=True):
def advanced_camera_settings(self, is_threaded=True):
"""Display visual controls for camera advanced settings"""
self.__display_advanced_settings("camera", is_threaded)
self.__advanced_settings("camera", is_threaded)

def display_rendering_settings(self):
def rendering_settings(self):
"""Display visual controls for renderer settings"""
def update_params(_):
"""Update renderer params"""
Expand Down Expand Up @@ -906,7 +906,7 @@ def update_params(_):
)
display(VBox([hbox_1, hbox_2], layout=Widgets.DEFAULT_GRID_LAYOUT))

def display_environment_maps(self, folder):
def environment_maps(self, folder):
"""Display visual controls for setting environment map"""
supported_extensions = ["jpg", "jpeg", "png"]
hdri_files = list()
Expand All @@ -925,7 +925,7 @@ def update_envmap(value):
cb_names.observe(update_envmap, "value")
display(cb_names)

def show_amino_acid_on_protein(
def protein_amino_acids(
self, assembly_name, name, sequence_id=0, palette_name="Set1", palette_size=2
):
"""
Expand Down Expand Up @@ -969,7 +969,7 @@ def update_slider(value):
display(irs)
display(lbl)

def display_clipping_planes(self, value_range=[0, 128]):
def clipping_planes(self, value_range=[0, 128]):
"""
Add and manipulate clip planes in a 3D space
Expand Down Expand Up @@ -1058,7 +1058,7 @@ def update_z(value):
hbox = HBox([w_x, w_y, w_z], layout=Widgets.DEFAULT_GRID_LAYOUT)
display(hbox)

def display_model_transformation(self, model_id):
def model_transformation(self, model_id):
"""
Manipulate and transform models within a 3D scene
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"metadata": {},
"outputs": [],
"source": [
"w.display_palette_for_models()"
"w.model_material()"
]
},
{
Expand All @@ -38,7 +38,7 @@
},
"outputs": [],
"source": [
"w.display_focal_distance(with_preview=True)"
"w.focal_distance(with_preview=False)"
]
},
{
Expand All @@ -47,7 +47,7 @@
"metadata": {},
"outputs": [],
"source": [
"w.display_model_visibility()"
"w.model_visibility()"
]
},
{
Expand All @@ -56,7 +56,7 @@
"metadata": {},
"outputs": [],
"source": [
"w.display_advanced_camera_settings()"
"w.advanced_camera_settings()"
]
},
{
Expand All @@ -68,8 +68,8 @@
"outputs": [],
"source": [
"be.core_api().set_renderer(current='advanced')\n",
"w.display_rendering_settings()\n",
"w.display_advanced_rendering_settings()"
"w.rendering_settings()\n",
"w.advanced_rendering_settings()"
]
},
{
Expand All @@ -78,7 +78,7 @@
"metadata": {},
"outputs": [],
"source": [
"w.display_model_focus(max_number_of_instances=10)"
"w.model_focus(max_number_of_instances=10)"
]
},
{
Expand All @@ -87,7 +87,7 @@
"metadata": {},
"outputs": [],
"source": [
"w.display_clipping_planes([-50, 50])"
"w.clipping_planes([-50, 50])"
]
}
],
Expand Down
10 changes: 5 additions & 5 deletions bioexplorer/pythonsdk/tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@


def test_widgets_environment_maps():
widgets.display_environment_maps('')
widgets.environment_maps('')


def test_widgets_advanced_camera_settings():
widgets.display_advanced_camera_settings(is_threaded=False)
widgets.advanced_camera_settings(is_threaded=False)


def test_widgets_display_rendering_settings():
widgets.display_rendering_settings()
widgets.rendering_settings()


def test_widgets_advanced_rendering_settings():
widgets.display_advanced_rendering_settings(is_threaded=False)
widgets.advanced_rendering_settings(is_threaded=False)


def test_widgets_focal_distance():
widgets.display_focal_distance()
widgets.focal_distance()


if __name__ == '__main__':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ static __device__ inline void shade()
outCol = make_float4(make_float3(col) + make_float3(glow) * (col.w + glow.w), 1.f);

prd.result = ::optix::clamp(outCol, 0.f, 1.f);
const float3 hit_point = ray.origin + t_hit * ray.direction;
prd.zDepth = optix::length(eye - hit_point);
}

RT_PROGRAM void any_hit_shadow()
Expand Down
2 changes: 2 additions & 0 deletions extensions/medicalimaging/dicom/module/cuda/renderer/DICOM.cu
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ static __device__ void dicomShade(const bool textured)

// Final result
prd.result = make_float4(result, 1.f);
prd.zDepth = z;
}

RT_PROGRAM void any_hit_shadow()
Expand All @@ -282,4 +283,5 @@ RT_PROGRAM void closest_hit_radiance_textured()
RT_PROGRAM void exception()
{
output_buffer[launch_index] = make_color(make_float4(0.f, 1.f, 0.f, 1.f));
depth_buffer[launch_index] = INFINITY;
}
Loading

0 comments on commit bfedd29

Please sign in to comment.