Search - User list
Full Version: Fit field-of-view to a BoundingBox
Root » Technical Discussion » Fit field-of-view to a BoundingBox
philippkl
Hello all,

I have a maybe tricky question to solve. Maybe it's not tricky at all and there is a simple solution that I don't know.

I have a geo that randomly changes its x and y size indepentendly. Now my problem is that I want to fit the field of view to those changes by moving the camera (non orthographic) back and forth (just on one axis). In general it is easy to just calculate it if the size change is only in one direction like this:

distance = (focallength) * ( (size of object in y or x) / filmsize +1 )

But what I am struggling with is how to calculate when both are changing…

I was thinking maybe the diameter could help as its composes out of both axis .. how could I get that value?


Would really appreachiate any help!
philippkl
To give you a little update on the problem solving:

Its not solved but by calculating the diagonal value of the boundingbox of the final object as the object size helped. It somehow works because both x and y are affecting the length of the diagonal but its not precise at all and more a workaround…

Maybe someone knows a better solution.

There is also an article on the documentation
https://www.sidefx.com/docs/houdini/ref/cameralenses.html [www.sidefx.com]
ziconic
You just have to calculate distance twice, once for the x axis, and again for the y axis, and use the larger of the 2 distance values. Don't forget that filmsize is different along the x and the y axes.
Librarian
maybe it Helps !

http://howiem.com/wordpress/index.php/2019/09/ [howiem.com]
philippkl
ziconic
You just have to calculate distance twice, once for the x axis, and again for the y axis, and use the larger of the 2 distance values. Don't forget that filmsize is different along the x and the y axes.

Yes definitely I am having that in mind I just didn't know how to compare the two values and also just took the filmsize Y value which returns a not very accurate result as its just accurate for the size y of the object. (now that I think about it the correct way would've been to also take the diagonal of the filmsize to make it more accurate). So the diagonal way is the cheap workaround.

But the solution to compare the two values would definitely be the way to go. How would I do that?


Thank you!!


srletak76
maybe it Helps !

http://howiem.com/wordpress/index.php/2019/09/ [howiem.com]

Thank you I will have a look into it!
ziconic
One way is to control the camera position using a Python expression that takes into account the bounding box of your geometry. See my hip file for an example for how this can be done.

(Edit: removed original attachment)
philippkl
Oh amazing thanks a lot for the effort ziconic! But it seems I am missing something… how solve that? I honestly have never implemented python in Houdini..
ziconic
Hmm are you on 17.5? Looks like I'm using a Python feature that was added as of 18.0.245.
philippkl
No I am on 18.0.460 and also this here pops up.
Maybe something is set up incorrectly on my side..
ziconic
I don't think the tops error matters but it's still weird. I'm on 18.0.532 and I don't see these errors. :-/
philippkl
It is really too bad as I would have been really interested in your solution…
ziconic
Try this version, which avoids using the missing Python API.

(Also I found another weird quirk with the original file I posted. Opening a hip file where an object node has a script that sets its own position but is parented to an object node with child compensation enabled can cause a pre-transform to be added to the child node. I should probably file this as a bug.)
philippkl
ziconic
Try this version, which avoids using the missing Python API.

(Also I found another weird quirk with the original file I posted. Opening a hip file where an object node has a script that sets its own position but is parented to an object node with child compensation enabled can cause a pre-transform to be added to the child node. I should probably file this as a bug.)

Hey all,

coming back to this one once again. I'm still trying to make this work.

I would still like to find a way to control two things... and I don't seem to find a solution for this. Sometimes the framing is not right (the object is sometimes too far away). That somehow happens when the calculated boundingbox has one very long and one short edge. Maybe it would be possible to find a solution to define a maximum and minimum edge on both the top and the sides of the framing.

Would be super happy if someone has an idea for this.

THANK YOU!
Soothsayer
If you're interested, I had a similar problem and this solved it for me:

vector campos = chv('campos');
vector objectpos = chv('objectpos');

// Initial horizontal aperture
float H_initial = 20.955;

// Object size (A) and distance (R) from the camera
float A = chf("object_size"); // Example channel referencing object size
float R = distance(campos, objectpos);
// Field of View (FOV) needed to fit the object at distance R
float FOV_needed = 2 * atan(A / (2 * R));
// focal length to achieve the required FOV with the initial horizontal aperture
@focal_length = H_initial / (2 * tan(FOV_needed / 2));
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB