6#ifndef OPENVDB_UTIL_MAPSUTIL_HAS_BEEN_INCLUDED
7#define OPENVDB_UTIL_MAPSUTIL_HAS_BEEN_INCLUDED
25template<
typename MapType>
27calculateBounds(
const MapType& map,
const BBoxd& in,
BBoxd& out)
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) {
51 out_min(j) = std::min( out_min(j), pre_image(j));
52 out_max(j) = std::max( out_max(j), pre_image(j));
60template<
typename MapType>
62calculateBounds(
const MapType& map,
const Vec3d& center,
const Real radius,
BBoxd& out)
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();
90 for (
int direction = 0; direction < 3; ++direction) {
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);
118findTangentPoints(
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;
163 const Vec3d& center,
const Real radius,
BBoxd& out)
178 BBoxd bounding_box(center - radius*Vec3d(1,1,1), center + radius*Vec3d(1,1,1));
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);
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);
230 out_max.
x() = std::max(x_min, std::min(x_max, pre_image.x()));
233 extreme.y() = centerLS.y();
236 extreme2 = secondMap.
applyMap(extreme);
240 out_min.
x() = std::max(x_min, std::min(x_max, pre_image.x()));
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);
259 out_max.
y() = std::max(y_min, std::min(y_max, pre_image.y()));
261 extreme.x() = centerLS.x();
264 extreme2 = secondMap.
applyMap(extreme);
268 out_min.
y() = std::max(y_min, std::min(y_max, pre_image.y()));
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);
A general linear transform using homogeneous coordinates to perform rotation, scaling,...
Definition: Maps.h:299
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,...
Definition: Maps.h:464
Vec3d applyMap(const Vec3d &in) const override
Return the image of in under the map.
Definition: Maps.h:414
Vec3d applyInverseMap(const Vec3d &in) const override
Return the pre-image of in under the map.
Definition: Maps.h:416
const Vec3T & max() const
Return a const reference to the maximum point of this bounding box.
Definition: BBox.h:64
const Vec3T & min() const
Return a const reference to the minimum point of this bounding box.
Definition: BBox.h:62
This map is composed of three steps. First it will take a box of size (Lx X Ly X Lz) defined by a mem...
Definition: Maps.h:1895
const BBoxd & getBBox() const
Return the bounding box that defines the frustum in pre-image space.
Definition: Maps.h:2366
const AffineMap & secondMap() const
Return MapBase::Ptr& to the second map.
Definition: Maps.h:2369
double getGamma() const
Definition: Maps.h:2363
double getDepth() const
Return the unscaled frustm depth.
Definition: Maps.h:2361
Vec3d applyInverseMap(const Vec3d &in) const override
Return the pre-image of in under the map.
Definition: Maps.h:2106
bool hasSimpleAffine() const
Return true if the second map is a uniform scale, Rotation and translation.
Definition: Maps.h:2375
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec3.h:85
T & y()
Definition: Vec3.h:86
T & z()
Definition: Vec3.h:87
double Real
Definition: Types.h:60
Definition: Exceptions.h:13
Map traits.
Definition: Maps.h:55
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:212