6 #ifndef OPENVDB_UTIL_MAPSUTIL_HAS_BEEN_INCLUDED
7 #define OPENVDB_UTIL_MAPSUTIL_HAS_BEEN_INCLUDED
25 template<
typename MapType>
29 const Vec3d&
min = in.
min();
30 const Vec3d&
max = in.
max();
34 corners[0] = in.
min();;
35 corners[1] = Vec3d(
min(0),
min(1),
min(2));
36 corners[2] = Vec3d(
max(0),
max(1),
min(2));
37 corners[3] = Vec3d(
min(0),
max(1),
min(2));
38 corners[4] = Vec3d(
min(0),
min(1),
max(2));
39 corners[5] = Vec3d(
max(0),
min(1),
max(2));
41 corners[7] = Vec3d(
min(0),
max(1),
max(2));
44 Vec3d& out_min = out.
min();
45 Vec3d& out_max = out.
max();
46 out_min = map.applyInverseMap(corners[0]);
48 for (
int i = 1; i < 8; ++i) {
49 pre_image = map.applyInverseMap(corners[i]);
50 for (
int j = 0;
j < 3; ++
j) {
60 template<
typename MapType>
81 Vec3d center_pre_image = map.applyInverseMap(center);
83 std::vector<Vec3d> coordinate_units;
84 coordinate_units.push_back(Vec3d(1,0,0));
85 coordinate_units.push_back(Vec3d(0,1,0));
86 coordinate_units.push_back(Vec3d(0,0,1));
88 Vec3d& out_min = out.
min();
89 Vec3d& out_max = out.
max();
91 Vec3d temp = map.applyIJT(coordinate_units[
direction]);
93 radius *
sqrt(temp.x()*temp.x() + temp.y()*temp.y() + temp.z()*temp.z());
94 out_min(direction) = center_pre_image(direction) -
offset;
95 out_max(direction) = center_pre_image(direction) +
offset;
103 BBoxd bounding_box(center - radius*Vec3d(1,1,1), center + radius*Vec3d(1,1,1));
104 calculateBounds<MapType>(map, bounding_box, out);
118 findTangentPoints(
const double g,
const double xo,
const double zo,
119 const double r,
double& xp,
double& zp,
double& xm,
double& zm)
125 double zd = g * zo + 1.;
129 double distA = xd2 + zd2;
130 double distB = distA - rd2;
133 double discriminate =
sqrt(distB);
135 xp = xo - xo*rd2/distA + r * zd *discriminate / distA;
136 xm = xo - xo*rd2/distA - r * zd *discriminate / distA;
138 zp = (zo*zd2 + zd*g*(x2 - r2) - xo*xo*g - r*xd*discriminate) / distA;
139 zm = (zo*zd2 + zd*g*(x2 - r2) - xo*xo*g + r*xd*discriminate) / distA;
143 }
if (0 >= distB && distB >= -1e-9) {
146 zp = -1/
g; zm = -1/
g;
173 if (!frustum.hasSimpleAffine()) {
179 calculateBounds<math::NonlinearFrustumMap>(frustum, bounding_box, out);
184 Vec3d& out_min = out.
min();
185 Vec3d& out_max = out.
max();
191 double radiusLS = radius / voxelSize(0);
193 double gamma = frustum.getGamma();
201 const BBoxd& bbox = frustum.getBBox();
203 const double x_min = bbox.
min().
x();
204 const double y_min = bbox.
min().
y();
205 const double z_min = bbox.
min().
z();
207 const double x_max = bbox.
max().
x();
208 const double y_max = bbox.
max().
y();
209 const double z_max = bbox.
max().
z();
220 soln_number = findTangentPoints(gamma, centerLS.x(), centerLS.z(), radiusLS, xp, zp, xm, zm);
221 if (soln_number == 2) {
223 extreme.y() = centerLS.y();
227 extreme2 = secondMap.
applyMap(extreme);
229 pre_image = frustum.applyInverseMap(extreme2);
233 extreme.y() = centerLS.y();
236 extreme2 = secondMap.
applyMap(extreme);
239 pre_image = frustum.applyInverseMap(extreme2);
242 }
else if (soln_number == 1) {
244 }
else if (soln_number == 0) {
249 soln_number = findTangentPoints(gamma, centerLS.y(), centerLS.z(), radiusLS, xp, zp, xm, zm);
250 if (soln_number == 2) {
251 extreme.x() = centerLS.x();
256 extreme2 = secondMap.
applyMap(extreme);
258 pre_image = frustum.applyInverseMap(extreme2);
261 extreme.x() = centerLS.x();
264 extreme2 = secondMap.
applyMap(extreme);
267 pre_image = frustum.applyInverseMap(extreme2);
270 }
else if (soln_number == 1) {
272 }
else if (soln_number == 0) {
278 double near_dist =
std::max(centerLS.z() - radiusLS, 0.);
280 double far_dist =
std::min(centerLS.z() + radiusLS, frustum.getDepth() );
282 Vec3d near_point(0.
f, 0.
f, near_dist);
283 Vec3d far_point(0.
f, 0.
f, far_dist);
285 out_min.z() =
std::max(z_min, frustum.applyInverseMap(secondMap.
applyMap(near_point)).
z());
286 out_max.z() =
std::min(z_max, frustum.applyInverseMap(secondMap.
applyMap(far_point)).
z());
294 #endif // OPENVDB_UTIL_MAPSUTIL_HAS_BEEN_INCLUDED
Vec3d voxelSize() const override
Return the lengths of the images of the segments (0,0,0)-(1,0,0), (0,0,0)-(0,1,0) and (0...
__hostdev__ ValueType min() const
Return the smallest vector component.
IMF_EXPORT IMATH_NAMESPACE::V3f direction(const IMATH_NAMESPACE::Box2i &dataWindow, const IMATH_NAMESPACE::V2f &pixelPosition)
vfloat4 sqrt(const vfloat4 &a)
GLdouble GLdouble GLdouble z
This map is composed of three steps. First it will take a box of size (Lx X Ly X Lz) defined by a mem...
#define OPENVDB_USE_VERSION_NAMESPACE
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
const Vec3T & min() const
Return a const reference to the minimum point of this bounding box.
A general linear transform using homogeneous coordinates to perform rotation, scaling, shear and translation.
__hostdev__ ValueType max() const
Return the largest vector component.
Vec3d applyInverseMap(const Vec3d &in) const override
Return the pre-image of in under the map.
const Vec3T & max() const
Return a const reference to the maximum point of this bounding box.
Vec3d applyMap(const Vec3d &in) const override
Return the image of in under the map.
void calculateBounds(const MapType &map, const BBoxd &in, BBoxd &out)
Calculate an axis-aligned bounding box in the given map's domain (e.g., index space) from an axis-ali...
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.