Fit field-of-view to a BoundingBox

   2917   13   2
User Avatar
Member
8 posts
Joined: May 2020
Offline
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!
Edited by philippkl - Aug. 21, 2020 21:11:30
User Avatar
Member
8 posts
Joined: May 2020
Offline
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]
Edited by philippkl - Aug. 21, 2020 21:10:47
User Avatar
Member
73 posts
Joined: March 2020
Offline
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.
User Avatar
Member
142 posts
Joined: Aug. 2009
Offline
maybe it Helps !

http://howiem.com/wordpress/index.php/2019/09/ [howiem.com]
User Avatar
Member
8 posts
Joined: May 2020
Offline
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!
User Avatar
Member
73 posts
Joined: March 2020
Offline
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)
Edited by ziconic - Aug. 24, 2020 20:58:17
User Avatar
Member
8 posts
Joined: May 2020
Offline
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..
Edited by philippkl - Aug. 24, 2020 15:37:32

Attachments:
123.png (72.6 KB)

User Avatar
Member
73 posts
Joined: March 2020
Offline
Hmm are you on 17.5? Looks like I'm using a Python feature that was added as of 18.0.245.
User Avatar
Member
8 posts
Joined: May 2020
Offline
No I am on 18.0.460 and also this here pops up.
Maybe something is set up incorrectly on my side..
Edited by philippkl - Aug. 24, 2020 18:10:01

Attachments:
1.png (44.9 KB)

User Avatar
Member
73 posts
Joined: March 2020
Offline
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. :-/
User Avatar
Member
8 posts
Joined: May 2020
Offline
It is really too bad as I would have been really interested in your solution…
Edited by philippkl - Aug. 24, 2020 19:26:46
User Avatar
Member
73 posts
Joined: March 2020
Offline
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.)

Attachments:
auto_dolly.hiplc (364.5 KB)

User Avatar
Member
8 posts
Joined: May 2020
Offline
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!
User Avatar
Member
859 posts
Joined: Oct. 2008
Offline
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));
--
Jobless
  • Quick Links