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

Error on changing plane position of slice #399

Open
zicolimongi opened this issue Nov 26, 2019 · 6 comments
Open

Error on changing plane position of slice #399

zicolimongi opened this issue Nov 26, 2019 · 6 comments

Comments

@zicolimongi
Copy link

zicolimongi commented Nov 26, 2019

I am working on a feature that allows users to rotate the localizer helpers of quadview like this video. It is working fine, but after rotation of any 2D renderers, the translation of other renderers is not working fine. The slice of these other renderers is moving, but it should remain the same slice. Watch the video to understand what I am trying to explain. In the video, first I am rotating localizer helper on r2 renderer, and it worked fine. After I am translating the localizer helpers on r2, and observe the slice is not moving, it remains still, like I expected, but when I translate the localizer helper on r1, renderer r1's slice is moving, but it should not be.

How I am rotating (angle is in radian)

axis = renderer.stackHelper.slice.planeDirection
planeDirection = renderer.stackHelper.slice.planeDirection.clone()
planeDirection.applyAxisAngle(axis,angle)
renderer.stackHelper.slice.planeDirection = planeDirection
renderer.stackHelper.border.helpersSlice = renderer.stackHelper.slice

How I am translating

renderer.stackHelper.slice.planePosition = point
renderer.stackHelper.border.helpersSlice = renderer.stackHelper.slice

I guess there is some error on rounding (Math.ceil or Math.floor) the point that I am setting the planePosition, because it is not coplanar with planePosition and I don't have a clue how to solve this.

@NicolasRannou
Copy link
Member

Looking very nice!

Hmm, I can not seem to see what is not working, the video looks fine to me.

Can you maybe try to explain in other words the problem so I understand it better?

Thanks!

@zicolimongi
Copy link
Author

It is not so easy to see indeed! The movement is very subtle.
In the video from 3 secs to 6 secs I am translating the localizer helpers on r2 and the r2's slice remains still, I mean, the rendered image doesn't move, exactly the way I want it to be. But when I translate the localizer helper of r1, the slice of r1 moves slightly, but it shouldn't move at all (8-12secs of video). Focus on the last teeth with some artifacts. Could you see the undesired movement now?

@NicolasRannou
Copy link
Member

Oh I see now thanks -

How do you get the new plane position? By raycasting the cursor position?
renderer.stackHelper.slice.planePosition = point

@zicolimongi
Copy link
Author

zicolimongi commented Nov 27, 2019

Yes I am raycasting the cursor point like this:

rect = canvas.getBoundingClientRect();
mouseParametrized = {
  x: ((event.clientX - rect.x) / rect.width) * 2 - 1,
  y: -((event.clientY - rect.y) / rect.height) * 2 + 1,
};
camera = renderer.camera
raycaster.setFromCamera(mouseParametrized, camera);
stackHelper = renderer.stackHelper
intersects = raycaster.intersectObjects(renderer.localizerHelper.children, false);
point = intersects[0].point

The point returned is not coplanar with slice. I've already tried to make a projection on planePosition of this point, but it doesn't work either

@NicolasRannou
Copy link
Member

NicolasRannou commented Nov 28, 2019

The point returned is not coplanar with slice. I've already tried to make a projection on planePosition of this point, but it doesn't work either

That must be the problem.

Can you check if the localizerHelper is updated when you drag/rotate the localizer?

Also, does it work if you do the raycasting against renderer.stackHelper.slice?

@zicolimongi
Copy link
Author

It does not work when I do the raycasting against renderer.stackHelper.slice, it just works when I do it against renderer.stackHelper.slice.children. But the error remains :(

I checked the localizer helper and I am updating like this
Rotating

//Rotate plane method
let axis = renderer.stackHelper.slice.planeDirection
//updateLocalizer method - Update the renderer I am rotating
renderer.localizerHelper.plane1 = [r1,r2,r3].filter(function(e) { if(e!=renderer) return e })[0].stackHelper.slice.cartesianEquation()
renderer.localizerHelper.plane2 = [r1,r2,r3].filter(function(e) { if(e!=renderer) return e })[1].stackHelper.slice.cartesianEquation()
renderer.localizerHelper.referencePlane = renderer.stackHelper.slice.cartesianEquation()
renderer.localizerHelper.geometry = renderer.stackHelper.slice.geometry

for(let otherRenderer of [r1,r2,r3].filter(function(e) { if(e!=renderer) return e })){
 //Rotate PLane direction method
 let planeDirection = otherRenderer.stackHelper.slice.planeDirection.clone()
 planeDirection.applyAxisAngle(axis,angle)
 otherRenderer.stackHelper.slice.planeDirection = planeDirection
 otherRenderer.stackHelper.border.helpersSlice = otherRenderer.stackHelper.slice
 //updateLocalizer method - Update the other rendererers
 otherRenderer.localizerHelper.plane1 = [r1,r2,r3].filter(function(e) { if(e!=otherRenderer) return e })[0].stackHelper.slice.cartesianEquation()
 otherRenderer.localizerHelper.plane2 = [r1,r2,r3].filter(function(e) { if(e!=otherRenderer) return e })[1].stackHelper.slice.cartesianEquation()
 otherRenderer.localizerHelper.referencePlane = otherRenderer.stackHelper.slice.cartesianEquation()
 otherRenderer.localizerHelper.geometry = otherRenderer.stackHelper.slice.geometry
 //Rotate camera method
 for(let direction of otherRenderer.camera._directions){
   direction.applyAxisAngle(axis,angle)
 }
 otherRenderer.camera.update()
}

Translating

// translateLocalizerToMousePosition method
let raycaster = new THREE.Raycaster();
let camera = renderer.camera
let stackHelper = renderer.stackHelper
let scene = renderer.scene
if(renderer.domId == 'r0'){
 stackHelper = r1.stackHelper
}
raycaster.setFromCamera(point, camera);
let intersects = raycaster.intersectObjects(renderer.stackHelper.slice.children, false);
if (intersects.length > 0) {
 //translatePlanesToPoint method
 let point = CoreUtils.worldToData(renderer.stackHelper.stack.lps2IJK, intersects[0].point);
 for(let renderer of [r1,r2,r3]){
   renderer.stackHelper.slice.planePosition = point
   renderer.stackHelper.border.helpersSlice = renderer.stackHelper.slice
 }
 for(let renderer of [r1,r2,r3]){
   //updateLocalizer method
   renderer.localizerHelper.plane1 = [r1,r2,r3].filter(function(e) { if(e!=renderer) return e })[0].stackHelper.slice.cartesianEquation()
   renderer.localizerHelper.plane2 = [r1,r2,r3].filter(function(e) { if(e!=renderer) return e })[1].stackHelper.slice.cartesianEquation()
   renderer.localizerHelper.referencePlane = renderer.stackHelper.slice.cartesianEquation()
   renderer.localizerHelper.geometry = renderer.stackHelper.slice.geometry
 } 
}

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

No branches or pull requests

2 participants