33 #ifndef OPENVDB_UTIL_MAPSUTIL_HAS_BEEN_INCLUDED
34 #define OPENVDB_UTIL_MAPSUTIL_HAS_BEEN_INCLUDED
36 #include <openvdb/math/Maps.h>
49 template<
typename MapType>
58 corners[0] = in.
min();;
70 out_min = map.applyInverseMap(corners[0]);
72 for (
int i = 1; i < 8; ++i) {
73 pre_image = map.applyInverseMap(corners[i]);
74 for (
int j = 0; j < 3; ++j) {
75 out_min(j) =
std::min( out_min(j), pre_image(j));
76 out_max(j) =
std::max( out_max(j), pre_image(j));
84 template<
typename MapType>
105 Vec3d center_pre_image = map.applyInverseMap(center);
107 std::vector<Vec3d> coordinate_units;
108 coordinate_units.push_back(
Vec3d(1,0,0));
109 coordinate_units.push_back(
Vec3d(0,1,0));
110 coordinate_units.push_back(
Vec3d(0,0,1));
114 for (
int direction = 0; direction < 3; ++direction) {
115 Vec3d temp = map.applyIJT(coordinate_units[direction]);
117 radius * sqrt(temp.
x()*temp.
x() + temp.
y()*temp.
y() + temp.
z()*temp.
z());
118 out_min(direction) = center_pre_image(direction) - offset;
119 out_max(direction) = center_pre_image(direction) + offset;
127 BBoxd bounding_box(center - radius*
Vec3d(1,1,1), center + radius*
Vec3d(1,1,1));
128 calculateBounds<MapType>(map, bounding_box, out);
141 findTangentPoints(
const double g,
const double xo,
const double zo,
142 const double r,
double& xp,
double& zp,
double& xm,
double& zm)
148 double zd = g * zo + 1.;
152 double distA = xd2 + zd2;
153 double distB = distA - rd2;
156 double discriminate = sqrt(distB);
158 xp = xo - xo*rd2/distA + r * zd *discriminate / distA;
159 xm = xo - xo*rd2/distA - r * zd *discriminate / distA;
161 zp = (zo*zd2 + zd*g*(x2 - r2) - xo*xo*g - r*xd*discriminate) / distA;
162 zm = (zo*zd2 + zd*g*(x2 - r2) - xo*xo*g + r*xd*discriminate) / distA;
166 }
if (0 >= distB && distB >= -1e-9) {
169 zp = -1/g; zm = -1/g;
196 if (!frustum.hasSimpleAffine()) {
201 BBoxd bounding_box(center - radius*
Vec3d(1,1,1), center + radius*
Vec3d(1,1,1));
202 calculateBounds<math::NonlinearFrustumMap>(frustum, bounding_box, out);
207 Vec3d& out_min = out.min();
208 Vec3d& out_max = out.max();
214 double radiusLS = radius / voxelSize(0);
216 double gamma = frustum.getGamma();
224 const BBoxd& bbox = frustum.getBBox();
226 const double x_min = bbox.
min().
x();
227 const double y_min = bbox.
min().
y();
228 const double z_min = bbox.
min().
z();
230 const double x_max = bbox.
max().
x();
231 const double y_max = bbox.
max().
y();
232 const double z_max = bbox.
max().
z();
243 soln_number = findTangentPoints(gamma, centerLS.
x(), centerLS.
z(), radiusLS, xp, zp, xm, zm);
244 if (soln_number == 2) {
246 extreme.
y() = centerLS.
y();
250 extreme2 = secondMap.
applyMap(extreme);
252 pre_image = frustum.applyInverseMap(extreme2);
255 const Vec3d tmpPlus = extreme2;
258 extreme.
y() = centerLS.
y();
261 extreme2 = secondMap.
applyMap(extreme);
263 const Vec3d tmpMinus = extreme2;
266 pre_image = frustum.applyInverseMap(extreme2);
269 }
else if (soln_number == 1) {
271 }
else if (soln_number == 0) {
276 soln_number = findTangentPoints(gamma, centerLS.
y(), centerLS.
z(), radiusLS, xp, zp, xm, zm);
277 if (soln_number == 2) {
278 extreme.
x() = centerLS.
x();
283 extreme2 = secondMap.
applyMap(extreme);
285 pre_image = frustum.applyInverseMap(extreme2);
288 const Vec3d tmpPlus = extreme2;
290 extreme.
x() = centerLS.
x();
293 extreme2 = secondMap.
applyMap(extreme);
295 const Vec3d tmpMinus = extreme2;
298 pre_image = frustum.applyInverseMap(extreme2);
301 }
else if (soln_number == 1) {
303 }
else if (soln_number == 0) {
309 double near_dist =
std::max(centerLS.
z() - radiusLS, 0.);
311 double far_dist =
std::min(centerLS.
z() + radiusLS, frustum.getDepth() );
313 Vec3d near_point(0.f, 0.f, near_dist);
314 Vec3d far_point(0.f, 0.f, far_dist);
316 out_min.
z() =
std::max(z_min, frustum.applyInverseMap(secondMap.
applyMap(near_point)).z());
317 out_max.
z() =
std::min(z_max, frustum.applyInverseMap(secondMap.
applyMap(far_point)).z());
325 #endif // OPENVDB_UTIL_MAPSUTIL_HAS_BEEN_INCLUDED