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

VTK Camera Loader #147

Merged
merged 12 commits into from
Sep 26, 2023
Merged

Conversation

NicerNewerCar
Copy link
Contributor

@NicerNewerCar NicerNewerCar commented Jul 14, 2023

  • Adds a new camera loader for VTK cameras
    • Defined as a *.json file
{
  "@schema": "https://autoscoperm.slicer.org/vtk-schema-1.0.json",
  "version": 1.0,
  "focal-point": [-7.9999999999999964, -245.50000000000006, -186.65000000000006],
  "camera-position": [104.71926635196253, -255.22259800818924, -179.66771669788898],
  "view-up": [0.0, 1.0, 0.0],
  "view-angle": 30.0,
  "image-width": 1760,
  "image-height": 1760,
}

@NicerNewerCar
Copy link
Contributor Author

NicerNewerCar commented Aug 17, 2023

Update 8.17.23

It would appear that both of the cameras are not looking at the correct spot, I suspect it has something to do with my Rotation calculations. Note the location of the manipulator in Autoscoper represents the focal point of both cameras. The radiograph images are the directions of the actual cameras within Autoscoper.

Camera Layout Slicer Autoscoper
image image

Another 8.17.23 Update

Getting closer, I think there may be another issue with the orientations of the VRGs but that will be fixed by the extension.

image

@NicerNewerCar NicerNewerCar force-pushed the camera-update branch 2 times, most recently from 89045a1 to e00fee9 Compare August 18, 2023 15:28
@NicerNewerCar
Copy link
Contributor Author

Update 8.18.23

Initially, I had thought that the issue had lied with the VRG gen but upon further inspection, I think the rotations within Autoscoper are just slightly off. As of right now, it is impossible to align the partial volumes with both of the radiographs.
Below is a quick recording of the problem as well as the current calculations being done to compute the rotation for each camera. [From Slicer I am exporting the camera position and the focal point, the view up vector is constant between cameras with the y-axis being the up direction.]

vrg-gen-autoscoper-test-1

Vec3d normal;
normal.x = focal_point[0] - camera_pos[0];
normal.y = focal_point[1] - camera_pos[1];
normal.z = focal_point[2] - camera_pos[2];
normal = unit(normal); // Normalize the vector

Vec3d up(0, 1, 0);
Vec3d w0(-normal.y, normal.x, 0);
Vec3d u0 = cross(w0,up);
double angle_x, angle_y, angle_z;
angle_z = std::atan(normal.x / -normal.y);
angle_y = std::atan(std::sqrt(normal.x * normal.x + normal.y * normal.y) / normal.z);
/*angle_z = std::atan2(normal.y, normal.x);
angle_y = std::asin(normal.z);*/
angle_x = std::atan2(
dot(w0,up),
dot(u0,up) / std::sqrt(dot(w0,w0)) * std::sqrt(dot(u0,u0))
);

@NicerNewerCar NicerNewerCar force-pushed the camera-update branch 2 times, most recently from aa7857d to 35c9100 Compare August 28, 2023 17:43
@NicerNewerCar
Copy link
Contributor Author

Update 8.28.23

I think I got it now, I ended up adding an implementation of glLookAt, similar to what is described here

image

double* Camera::lookAt(Vec3d eye, Vec3d center, Vec3d up) {
// Implementation based off of:
// https://www.khronos.org/opengl/wiki/GluLookAt_code
Vec3d forward = unit(center - eye);
Vec3d side = unit(cross(forward, up));
up = cross(side, forward);
double matrix[9];
matrix[0] = side.x; matrix[1] = side.y; matrix[2] = side.z;
matrix[3] = up.x; matrix[4] = up.y; matrix[5] = up.z;
matrix[6] = -forward.x; matrix[7] = -forward.y; matrix[8] = -forward.z;
return matrix;
}

@NicerNewerCar NicerNewerCar changed the title WIP: Camera update for Multi-modality support VTK Camera Loader Aug 28, 2023
@NicerNewerCar NicerNewerCar marked this pull request as ready for review August 28, 2023 18:06
@NicerNewerCar
Copy link
Contributor Author

Rebase with #200 once integrated

@NicerNewerCar NicerNewerCar force-pushed the camera-update branch 3 times, most recently from 524190a to b25162e Compare August 29, 2023 14:05
@NicerNewerCar NicerNewerCar linked an issue Aug 29, 2023 that may be closed by this pull request
@amymmorton
Copy link
Collaborator

After building PR #53 and PR #147 Anthony and I used the PRE PROC LEFT Hop Knee dicom to run through the vrg gen in SAM.

Successful use of all tabs in 53

When loaded with the optimized cams config, I attempted to track both tib and femur.. poor results.
trackingDIDcams

Same with all cameras (optimized and manually placed)
allC

Going to try with wrist data - both vrg/pv gen and see if we do get a good ncc optimizziton

libautoscoper/src/Camera.hpp Outdated Show resolved Hide resolved
libautoscoper/src/Camera.hpp Outdated Show resolved Hide resolved
libautoscoper/src/Camera.cpp Outdated Show resolved Hide resolved
libautoscoper/src/Camera.cpp Outdated Show resolved Hide resolved
@amymmorton
Copy link
Collaborator

The config file generation step in this branch is integral for agreement testing. Would it be possible to push that feature to main?

@NicerNewerCar
Copy link
Contributor Author

The config file generation step in this branch is integral for agreement testing. Would it be possible to push that feature to main?

There is no config generation on this branch, are you referring to BrownBiomechanics/SlicerAutoscoperM#53?

libautoscoper/src/Camera.cpp Outdated Show resolved Hide resolved
libautoscoper/src/Camera.cpp Outdated Show resolved Hide resolved
libautoscoper/src/Camera.cpp Show resolved Hide resolved
libautoscoper/src/Camera.cpp Show resolved Hide resolved
Documentation/file-specifications/camera-calibration.md Outdated Show resolved Hide resolved
Documentation/file-specifications/camera-calibration.md Outdated Show resolved Hide resolved
Documentation/file-specifications/camera-calibration.md Outdated Show resolved Hide resolved
Documentation/file-specifications/camera-calibration.md Outdated Show resolved Hide resolved
Documentation/file-specifications/camera-calibration.md Outdated Show resolved Hide resolved
Documentation/file-specifications/camera-calibration.md Outdated Show resolved Hide resolved
libautoscoper/src/Camera.cpp Outdated Show resolved Hide resolved
libautoscoper/src/Camera.cpp Outdated Show resolved Hide resolved
* Both loadMayaCam1 & 2 had duplicated code.
* Add new helper methods `calculateViewport` and `calculateImagePlane` to
  remove this duplication.
* Simplified some of the math by checking in loadMayaCam1 if z is
  negative.
@NicerNewerCar NicerNewerCar force-pushed the camera-update branch 2 times, most recently from cfb2260 to 3f724c9 Compare September 25, 2023 13:25
@jcfr
Copy link
Contributor

jcfr commented Sep 25, 2023

For reference, to review the changes while ignoring the space change, this link can be used. See https://github.com/BrownBiomechanics/Autoscoper/pull/147/files?w=1

@jcfr jcfr force-pushed the camera-update branch 2 times, most recently from 5f46175 to 0762d92 Compare September 25, 2023 20:48
NicerNewerCar and others added 7 commits September 25, 2023 17:06
…td::remove

Fix build error like the following reported when
using GCC 9.4.0 on Ubuntu 20.04:

/path/to/Autoscoper/libautoscoper/src/Camera.cpp:397:44: error: cannot convert ‘std::__cxx11::basic_string<char>::iterator’ {aka ‘__gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char> >’} to ‘const char*’
  397 |         value.erase(std::remove(value.begin(), value.end(), ']'), value.end());
      |                                 ~~~~~~~~~~~^~
      |                                            |
      |                                            std::__cxx11::basic_string<char>::iterator {aka __gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char> >}
Fix the following warning:

/path/to/Autoscoper/libautoscoper/src/Camera.cpp: In member function ‘double* xromm::Camera::calculateFocalLength(const double&)’:
/path/to/Autoscoper/libautoscoper/src/Camera.cpp:602:12: warning: address of local variable ‘focal_lengths’ returned [-Wreturn-local-addr]
  602 |     return focal_lengths;
      |            ^~~~~~~~~~~~~

/path/to/Autoscoper/libautoscoper/src/Camera.cpp: In member function ‘double* xromm::Camera::lookAt(Vec3d, Vec3d, Vec3d)’:
/path/to/Autoscoper/libautoscoper/src/Camera.cpp:615:12: warning: address of local variable ‘matrix’ returned [-Wreturn-local-addr]
  615 |     return matrix;
      |            ^~~~~~
Also improve readability by splitting setting of each matrix element
on its own line.
libautoscoper/src/Camera.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@jcfr jcfr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After updating the schema URL, this will be ready for integration.

NicerNewerCar and others added 3 commits September 26, 2023 09:20
For sake of consistency with how Slicer integrates JsonCpp, we ignore
the "jsoncppConfig.cmake" file provided by jsoncpp CMake project and
instead set JsonCpp_INCLUDE_DIR and JsonCpp_LIBRARY expected by the
"FindJsonCpp" CMake module.

To streamline distribution of the standalone Autoscoper executable, update
JsonCpp project to statically build the JsonCpp library.
@NicerNewerCar NicerNewerCar merged commit 97c8deb into BrownBiomechanics:main Sep 26, 2023
2 checks passed
@NicerNewerCar NicerNewerCar deleted the camera-update branch September 26, 2023 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Converting between VTK cameras and Autoscoper cameras
3 participants