POV-Ray : Newsgroups : povray.text.scene-files : bounding box calculator : bounding box calculator Server Time21 Mar 2023 23:16:17 EDT (-0400)
 bounding box calculator
 From: jr Date: 27 Oct 2019 11:05:01 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.5db5b0ff51c96acafeeb22ff0%40news.povray.org",
"headline": "bounding box calculator",
"dateCreated": "2019-10-27T15:05:01+00:00",
"datePublished": "2019-10-27T15:05:01+00:00",
"author": {
"@type": "Person",
"name": "jr"
}
}
hi,

as part of some stuff I'm playing with, I noticed that the bounding box of the
"Boy's Surface"[1] contains a lot of .. air.  :-)  after reading up on things, I
wrote a macro which "scans" an object's BB to find the actual dimensions (using
'inside()' tests), and print out information about how much "slack" is found[2]
between object and bounding box face(s).

[1]

[2] v basic still.  only distinguishes three scenarios: up to 1% space all
around, up to 5%, and over 5%.

I've tested the code with a handful of different objects, and so far, so good.
perhaps someone else will find use(s) for it too.  it is a work in progress
though, and it would be nice if one or two wanted to be "guinea pigs", beta
test, and help find bugs/problems, suggest improvements.

there is no documentation apart from a few header lines in the .inc, but the
macro is easy to use:

macro Bounder(object, optional resolution)

where object is some object identifier, and the resolution an integer, or a
3-vector of ints, giving the number of "probes" per POV unit.

the simplest usage example is something like:
-----<snip>-----
#version 3.8;
global_settings {...}
#declare O = cylinder {...};
#include "bounder.inc"
Bounder(O,)
-----<snip>-----

uses the default resolution <50,50,50>.

the cut'n'paste stuff below shows the before and after for the 'boy-file.pov'
(with minimal adaptations, and renamed), with timings.  the difference is that
for the second run I'd added a 'clipped_by {box {}}' calculated from the values
in the "diff" lines, and a 'bounded_by {clipped_by}', as suggested in the docs.

enjoy, jr.

-----<snip>-----
the 'povparse' command is a BASH alias, shown here in case it's of interest to a
Linux user, useful when only the '#debug' output matters:
alias povparse='nice -n 19 povray -w32 -h32 -D -F -GS -GR +i'

Script started on Sun 27 Oct 2019 12:16:05 GMT
jr@crow:1:bounder\$ time povparse bta.pov
Persistence of Vision(tm) Ray Tracer Version 3.8.0-alpha.10013324.unofficial
...
==== [Parsing...] ==========================================================
----------[Bounder info]------------------------------------------------
resolutions (per POV unit): <20, 20, 20>
object "as is" (BB) min: <-6.000000, -6.000000, -6.000000>
object "as is" (BB) max: <5.000000, 5.000000, 5.000000>
object aligned (BB) max: <11.000000, 11.000000, 11.000000>
axis 'X' scan resolution: 220
probes per face: 48400
scan axis increment: 0.05000000
face col increment: 0.05000000
face row increment: 0.05000000
-: ...scanning...
Parsing 140263K tokens
total # probes: 3000800
axis 'Y' scan resolution: 220
probes per face: 48400
scan axis increment: 0.05000000
face col increment: 0.05000000
face row increment: 0.05000000
-: ...scanning...
Parsing 289350K tokens
total # probes: 3049200
axis 'Z' scan resolution: 220
probes per face: 48400
scan axis increment: 0.05000000
face col increment: 0.05000000
face row increment: 0.05000000
-: ...scanning...
Parsing 432765K tokens
total # probes: 3000800
--------------------
diff lower bound: 1.95000000,2.00000000,1.95000000
diff upper bound: 0.95000000,0.95000000,0.95000000
object bounding box has at least 5% "slack".
------------------------------------------------------------------------
==== [Rendering...] ========================================================
Rendered 1024 of 1024 pixels (100%)
POV-Ray finished

real 1m37.487s
user 1m36.884s
sys 0m0.041s

Script started on Sun 27 Oct 2019 12:18:31 GMT
jr@crow:4:bounder\$ time povparse bt2.pov
Persistence of Vision(tm) Ray Tracer Version 3.8.0-alpha.10013324.unofficial
...
==== [Parsing...] ==========================================================
----------[Bounder info]------------------------------------------------
resolutions (per POV unit): <20, 20, 20>
object "as is" (BB) min: <-4.100000, -4.100000, -4.100000>
object "as is" (BB) max: <4.100000, 4.100000, 4.100000>
object aligned (BB) max: <8.200000, 8.200000, 8.200000>
axis 'X' scan resolution: 164
probes per face: 26896
scan axis increment: 0.05000000
face col increment: 0.05000000
face row increment: 0.05000000
-: ...scanning...
Parsing 4616K tokens
total # probes: 161376
axis 'Y' scan resolution: 164
probes per face: 26896
scan axis increment: 0.05000000
face col increment: 0.05000000
face row increment: 0.05000000
-: ...scanning...
Parsing 9246K tokensParsing 13950K tokens
total # probes: 161376
axis 'Z' scan resolution: 164
probes per face: 26896
scan axis increment: 0.05000000
face col increment: 0.05000000
face row increment: 0.05000000
-: ...scanning...
Parsing 18627K tokensParsing 23261K tokens
total # probes: 161376
--------------------
diff lower bound: 0.05000000,0.05000000,0.05000000
diff upper bound: 0.05000000,0.05000000,0.05000000
object bounding box is (near) optimal.
------------------------------------------------------------------------
==== [Rendering...] ========================================================
Rendered 1024 of 1024 pixels (100%)
POV-Ray finished

real 0m5.896s
user 0m5.236s
sys 0m0.006s
```

Attachments: