Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fixes #124

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions deepdrr/projector/projector.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ def _setup_pyrender_scene(self, proj: geo.CameraProjection):
self.cam.cx = proj.intrinsic.cx
self.cam.cy = proj.intrinsic.cy
self.cam.znear = 1 # self.device.source_to_detector_distance / 1000
self.cam.zfar = self.device.source_to_detector_distance * 4
self.cam.zfar = self.source_to_detector_distance * 4

deepdrr_to_opengl_cam = np.array(
[
Expand All @@ -872,7 +872,7 @@ def _setup_pyrender_scene(self, proj: geo.CameraProjection):

self.cam_node.matrix = np.array(proj.extrinsic.inv) @ deepdrr_to_opengl_cam

zfar = self.device.source_to_detector_distance * 2 * 4 # TODO (liam)
zfar = self.source_to_detector_distance * 2 * 4 # TODO (liam)

return zfar

Expand Down Expand Up @@ -1166,7 +1166,7 @@ def _render_mesh_subtractive_single(
* NUMBYTES_INT8
),
np.int32(total_pixels),
np.float32(self.device.source_to_detector_distance * 2),
np.float32(self.source_to_detector_distance * 2),
),
block=(32, 1, 1), # TODO (liam)
grid=(2048, 1), # TODO (liam)
Expand Down Expand Up @@ -1363,8 +1363,8 @@ def initialize(self):
log.debug(f"beginning call to Projector.initialize")
init_tick = time.perf_counter()

width = self.device.sensor_width
height = self.device.sensor_height
width = self.camera_intrinsics.sensor_width
height = self.camera_intrinsics.sensor_height
total_pixels = width * height

device_id = int(os.environ.get("EGL_DEVICE_ID", "0"))
Expand Down Expand Up @@ -1469,16 +1469,16 @@ def initialize(self):
self.mesh_nodes.append(node)
self.scene.add(drrmesh.mesh, parent_node=node)

cam_intr = self.device.camera_intrinsics
cam_intr = self.camera_intrinsics

self.cam = IntrinsicsCamera(
fx=cam_intr.fx,
fy=cam_intr.fy,
cx=cam_intr.cx,
cy=cam_intr.cy,
znear=self.device.source_to_detector_distance
znear=self.source_to_detector_distance
/ 1000, # TODO (liam) near clipping plane parameter
zfar=self.device.source_to_detector_distance,
zfar=self.source_to_detector_distance,
)

self.cam_node = self.scene.add(self.cam)
Expand Down
6 changes: 3 additions & 3 deletions deepdrr/utils/image_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ def _neglog(image: np.ndarray, epsilon: float = 0.01) -> np.ndarray:
image_min = image.min(axis=(1, 2), keepdims=True)
image_max = image.max(axis=(1, 2), keepdims=True)
if np.any(image_max == image_min):
logger.debug(
log.debug(
f"mapping constant image to 0. This probably indicates the projector is pointed away from the volume."
)
# TODO(killeen): for multiple images, only fill the bad ones
image[:] = 0
if image.shape[0] > 1:
logger.error("TODO: zeroed all images, even though only one might be bad.")
log.error("TODO: zeroed all images, even though only one might be bad.")
else:
image = (image - image_min) / (image_max - image_min)

if np.any(np.isnan(image)):
logger.warning(f"got NaN values from negative log transform.")
log.warning(f"got NaN values from negative log transform.")

if len(shape) == 2:
return image[0]
Expand Down