blender/intern/cycles/util/util_boundbox.h
Dalai Felinto 8c4fa687e0 Cycles bugfix: AUTO wasn't working for Equisolid Fisheye lens
Now one no longer needs to match the sensor dimensions with the render dimensions manually.

IMPORTANT NOTE: if you were using AUTO before with mismathing sensor aspect ratio (comparing to the render dimensions)
this will change your render! We can doversion this, but apart from Tube project I don't know if anyone else
is using this yet (part due to this bug and the only recently fixed 3dview preview aspect ratio).

That should help more artists to take advantage of this fantastic Blender feature.
It still helps to know the parameters of kwnown cameras/lens though.
For example:

Nikon DX2S with a 10.5mm fisheye can be set with:
Render resolution: 4288 x 2848
Sensor 23.7 x 15.70 (15.70 can be ommitted if AUTO is used as fit method)

Note: some cameras render different sizes according to the recording mode.
For example, a Red Scarlet in 5k (@12 fps) can render a full circular fisheye with a sigma 4.5 lens.
The same camera in the 30fps recording mode renders 4k in a cropped circular image.
So it's not only the resolution that changes, but the actual sensor been used.

So just keep in mind that the more information you have from the camera/lens you want to emulate the better.
Bug found at/patch written as a follow up of the BlenderPRO2012, patch reviewed by Brecht Van Lommel
2012-11-21 01:07:30 +00:00

242 lines
5.0 KiB
C++

/*
* Copyright 2011, Blender Foundation.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef __UTIL_BOUNDBOX_H__
#define __UTIL_BOUNDBOX_H__
#include <math.h>
#include <float.h>
#include "util_math.h"
#include "util_string.h"
#include "util_transform.h"
#include "util_types.h"
using namespace std;
CCL_NAMESPACE_BEGIN
/* 3D BoundBox */
class BoundBox
{
public:
float3 min, max;
__forceinline BoundBox()
{
}
__forceinline BoundBox(const float3& pt)
: min(pt), max(pt)
{
}
__forceinline BoundBox(const float3& min_, const float3& max_)
: min(min_), max(max_)
{
}
enum empty_t { empty = 0};
__forceinline BoundBox(empty_t)
: min(make_float3(FLT_MAX, FLT_MAX, FLT_MAX)), max(make_float3(-FLT_MAX, -FLT_MAX, -FLT_MAX))
{
}
__forceinline void grow(const float3& pt)
{
min = ccl::min(min, pt);
max = ccl::max(max, pt);
}
__forceinline void grow(const BoundBox& bbox)
{
grow(bbox.min);
grow(bbox.max);
}
__forceinline void intersect(const BoundBox& bbox)
{
min = ccl::max(min, bbox.min);
max = ccl::min(max, bbox.max);
}
/* todo: avoid using this */
__forceinline float safe_area() const
{
if(!((min.x <= max.x) && (min.y <= max.y) && (min.z <= max.z)))
return 0.0f;
return area();
}
__forceinline float area() const
{
return half_area()*2.0f;
}
__forceinline float half_area() const
{
float3 d = max - min;
return (d.x*d.z + d.y*d.z + d.x*d.y);
}
__forceinline float3 center() const
{
return 0.5f*(min + max);
}
__forceinline float3 center2() const
{
return min + max;
}
__forceinline float3 size() const
{
return max - min;
}
__forceinline bool valid() const
{
return (min.x <= max.x) && (min.y <= max.y) && (min.z <= max.z) &&
(isfinite(min.x) && isfinite(min.y) && isfinite(min.z)) &&
(isfinite(max.x) && isfinite(max.y) && isfinite(max.z));
}
BoundBox transformed(const Transform *tfm)
{
BoundBox result = BoundBox::empty;
for(int i = 0; i < 8; i++) {
float3 p;
p.x = (i & 1)? min.x: max.x;
p.y = (i & 2)? min.y: max.y;
p.z = (i & 4)? min.z: max.z;
result.grow(transform_point(tfm, p));
}
return result;
}
};
__forceinline BoundBox merge(const BoundBox& bbox, const float3& pt)
{
return BoundBox(min(bbox.min, pt), max(bbox.max, pt));
}
__forceinline BoundBox merge(const BoundBox& a, const BoundBox& b)
{
return BoundBox(min(a.min, b.min), max(a.max, b.max));
}
__forceinline BoundBox merge(const BoundBox& a, const BoundBox& b, const BoundBox& c, const BoundBox& d)
{
return merge(merge(a, b), merge(c, d));
}
__forceinline BoundBox intersect(const BoundBox& a, const BoundBox& b)
{
return BoundBox(max(a.min, b.min), min(a.max, b.max));
}
__forceinline BoundBox intersect(const BoundBox& a, const BoundBox& b, const BoundBox& c)
{
return intersect(a, intersect(b, c));
}
/* 2D BoundBox */
class BoundBox2D {
public:
float left;
float right;
float bottom;
float top;
BoundBox2D()
: left(0.0f), right(1.0f), bottom(0.0f), top(1.0f)
{
}
bool operator==(const BoundBox2D& other) const
{
return (left == other.left && right == other.right &&
bottom == other.bottom && top == other.top);
}
float width() {return right - left;}
float height() {return bottom - top;}
BoundBox2D operator*(float f) const
{
BoundBox2D result;
result.left = left*f;
result.right = right*f;
result.bottom = bottom*f;
result.top = top*f;
return result;
}
BoundBox2D subset(const BoundBox2D& other) const
{
BoundBox2D subset;
subset.left = left + other.left*(right - left);
subset.right = left + other.right*(right - left);
subset.bottom = bottom + other.bottom*(top - bottom);
subset.top = bottom + other.top*(top - bottom);
return subset;
}
BoundBox2D make_relative_to(const BoundBox2D& other) const
{
BoundBox2D result;
result.left = ((left - other.left) / (other.right - other.left));
result.right = ((right - other.left) / (other.right - other.left));
result.bottom = ((bottom - other.bottom) / (other.top - other.bottom));
result.top = ((top - other.bottom) / (other.top - other.bottom));
return result;
}
BoundBox2D clamp(float mn = 0.0f, float mx = 1.0f)
{
BoundBox2D result;
result.left = ccl::clamp(left, mn, mx);
result.right = ccl::clamp(right, mn, mx);
result.bottom = ccl::clamp(bottom, mn, mx);
result.top = ccl::clamp(top, mn, mx);
return result;
}
};
CCL_NAMESPACE_END
#endif /* __UTIL_BOUNDBOX_H__ */