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

Would it be possible to set camera parameters? #59

Closed
pythoro opened this issue Jan 24, 2022 · 11 comments
Closed

Would it be possible to set camera parameters? #59

pythoro opened this issue Jan 24, 2022 · 11 comments

Comments

@pythoro
Copy link

pythoro commented Jan 24, 2022

I'd like to set the camera location, depth of view, etc. via code, but I cannot find any way to do this. Is it possible to add this as a feature? Is there a workaround I could use in the meantime?

Thanks, and thanks for all the great work!

@jourdain
Copy link
Collaborator

I guess we only have those properties so far.
But the list of camera parameters could be extended here and have dash-vtk expose the latest library with any add-on parameters.

@pythoro
Copy link
Author

pythoro commented Jan 24, 2022

Is there a way to do that via js so I can get something working until a release of dash-vtk that makes it possible in python? (I'm a novice with react and js so sorry if that's a silly question.)

@jourdain
Copy link
Collaborator

I don't think that you have much control on the JS side from Dash but I might be wrong.

If you can make a JS call on the react VtkView component, you can get your hand on the camera by calling componentRef.renderer.getActiveCamera().set({ ... })

@pythoro
Copy link
Author

pythoro commented Jan 24, 2022

Thanks. I've no idea how to get that view component, yet, but I'll look into it.

@pythoro
Copy link
Author

pythoro commented Jan 26, 2022

Even if I could find a way to make a JS call on the React-vtk-js View component, I don't think it'd work. I realise now that the resetCamera method is called here, which moves the camera position anyway.

So, I think I need to make a custom React class, based on the View component of React-vtk-js, and turn it into a Dash component using the dash-component-boilerplate. Then I think I can get the functionality I need. And, I think I can use clientside callbacks to make the camera updates fast (e.g. for animation). Hopefully that makes sense and will work. And hopefully it's not too hard to do!

Thanks again for your comments. I'll close this issue as it doesn't seem like it's a dash-vtk issue to me now.

@pythoro pythoro closed this as completed Jan 26, 2022
@pythoro
Copy link
Author

pythoro commented Jan 26, 2022

Update: I now think I can create a Dash component that wraps a standard vtkView and keeps a ref to it, like this. That'll allow me to make JS calls on the vtkView component, like you suggested, @jourdain. I think that will let me bypass the resetCamera method.

@pythoro
Copy link
Author

pythoro commented Jan 26, 2022

I have one more question for you, @jourdain, if you have a moment to answer. If I make a stand-alone Dash component, I'm not sure how to properly configure and write my JS imports so that I can use dash_vtk seamlessly with the new component (still a novice with JS, Dash, React, webpack, etc.). I can't find how to do that. I think I need to import the View.react.js View from dash-vtk. Is there an easy way to do that? Can I do something like this in my JS file?

import View as DashVTKView from 'dash-vtk';

I'm not sure how to structure the files so that that might work.

Or do I need to do something like clone the dash-vtk repo, add a new custom class, and build it?

I'd appreciate any guidance you can give.

@jourdain
Copy link
Collaborator

jourdain commented Jan 26, 2022

If your code is JS, you should import react-vtk-js directly. dash-vtk is just exposing for Python/R/Julia react-vtk-js.

@pythoro
Copy link
Author

pythoro commented Jan 26, 2022

Ah, so I just make react-vtk-js a dependency in the package.json and do something like `import VtkView from 'react-vtk-js' in the JS file? And it won't matter that my component doesn't know about dash_vtk?

@jourdain
Copy link
Collaborator

yes exactly. You can double check how dash-vtk do its import as you are basically doing the same thing yourself.

@pythoro
Copy link
Author

pythoro commented Jan 26, 2022

Great, thanks again!

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