Skip to content

Commit

Permalink
Prototype set_transform_from_points now tries to set rotation from …
Browse files Browse the repository at this point in the history
…transform `Euler` angle when the prototype guided marker is 1-ranked (electrode strip, `DBS` electrodes)
  • Loading branch information
dipterix committed Jul 22, 2024
1 parent 7529aa9 commit 00ba211
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 6 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Changes since last CRAN release
* `12970a6b (HEAD -> master, origin/master, origin/HEAD)` [_`dipterix`_]: Fixed the `GLTF` not showing inner-most contact issue
* `249626d4 (HEAD -> master)` [_`dipterix`_]: Prototype `set_transform_from_points` now tries to set rotation from transform `Euler` angle when the prototype guided marker is 1-ranked (electrode strip, `DBS` electrodes)
* `7529aa91` [_`dipterix`_]: Allowed electrode prototype to display markers; added viewer options for localization
* `b35e7dc1` [_`dipterix`_]: Changed electrode direction helper to be displayed inside of crosshair group; Allowed side panel to be displayed with atlas column-row-slice; Added controller to display symmetric continuous color map for volumes
* `12970a6b (origin/master, origin/HEAD)` [_`dipterix`_]: Fixed the `GLTF` not showing inner-most contact issue
* `c8522cd7` [_`dipterix`_]: Removed `devel` version of `ravetools` from check
* `11bb99e8` [_`dipterix`_]: Update `Github` action check script
* `cbeac8bc` [_`dipterix`_]: Added rhub check
Expand Down
49 changes: 46 additions & 3 deletions R/class_electrode_proto.R
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,54 @@ ElectrodePrototype <- R6::R6Class(
}
}

# check rank of the model
qr_decomp <- qr(m_cp)

if( qr_decomp$rank == 1 && sum((self$model_direction) ^ 2) > 0.5 ) {
# we need to account for rotations along `self$model_direction`
model_z <- normalize_vector3( self$model_direction )
model_x <- normalize_vector3( cross_prod(self$model_up, model_z) )
model_y <- normalize_vector3( cross_prod(model_z, model_x) )
basis <- cbind(model_x, model_y, model_z)
m33 <- solve(m44[1:3, 1:3]) %*% self$transform[1:3, 1:3] %*% solve(basis)
m33[m33 < -1] <- -1
m33[m33 > 1] <- 1

# rotation: euler angle from ZYX order
a_y <- asin( - m33[3, 1] )

if ( abs( a_y ) < 0.9999999 ) {

a_x = atan2( m33[3, 2], m33[3, 3] );
a_z = atan2( m33[2, 1], m33[1, 1] );

} else {

a_x = 0;
a_z = atan2( - m33[1, 2], m33[2, 2] );

}

euler_z <- matrix(
nrow = 3, byrow = TRUE,
c(
cos( a_z ), - sin( a_z ), 0,
sin( a_z ), cos( a_z ), 0,
0, 0, 1
)
)


m33 <- m44[1:3, 1:3] %*% euler_z %*% basis
m44[1:3, 1:3] <- m33

}

if( length(m_fixed) ) {
m44[1:3, 4] <- 0
m44[1:3, 4] <- t_fixed - (m44 %*% c(m_fixed, 1))[1:3]
}

# check rank of the model
qr_decomp <- qr(m_cp)

if(length(up) != 3) {
up <- private$.world_up
}
Expand Down Expand Up @@ -671,9 +711,11 @@ ElectrodePrototype <- R6::R6Class(
}
self$model_direction <- li$model_direction
self$model_up <- li$model_up

if(length(li$world_control_points) >= 6) {
tcp <- matrix(data = li$world_control_points, nrow = 3L, dimnames = NULL)
tryCatch({
self$set_transform(li$transform)
self$set_transform_from_points(x = tcp[1, ], y = tcp[2, ], z = tcp[3, ], up = li$world_up)
}, error = function(e) {
warning(e)
Expand Down Expand Up @@ -725,6 +767,7 @@ ElectrodePrototype <- R6::R6Class(
if(length(other$world_control_points) >= 6) {
tcp <- matrix(data = other$world_control_points, nrow = 3L, dimnames = NULL)
tryCatch({
self$set_transform(other$transform)
self$set_transform_from_points(x = tcp[1, ], y = tcp[2, ], z = tcp[3, ], up = other$world_up)
}, error = function(e) {
warning(e)
Expand Down
2 changes: 1 addition & 1 deletion inst/threeBrainJS/dist/threebrain-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inst/threeBrainJS/dist/threebrain-main.js.map

Large diffs are not rendered by default.

0 comments on commit 00ba211

Please sign in to comment.