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);
256 extreme.y() = centerLS.y();
259 extreme2 = secondMap.
applyMap(extreme);
262 pre_image = frustum.applyInverseMap(extreme2);
265 }
else if (soln_number == 1) {
267 }
else if (soln_number == 0) {
272 soln_number = findTangentPoints(gamma, centerLS.y(), centerLS.z(), radiusLS, xp, zp, xm, zm);
273 if (soln_number == 2) {
274 extreme.x() = centerLS.x();
279 extreme2 = secondMap.
applyMap(extreme);
281 pre_image = frustum.applyInverseMap(extreme2);
284 extreme.x() = centerLS.x();
287 extreme2 = secondMap.
applyMap(extreme);
290 pre_image = frustum.applyInverseMap(extreme2);
293 }
else if (soln_number == 1) {
295 }
else if (soln_number == 0) {
301 double near_dist =
std::max(centerLS.z() - radiusLS, 0.);
303 double far_dist =
std::min(centerLS.z() + radiusLS, frustum.getDepth() );
305 Vec3d near_point(0.f, 0.f, near_dist);
306 Vec3d far_point(0.f, 0.f, far_dist);
308 out_min.z() =
std::max(z_min, frustum.applyInverseMap(secondMap.
applyMap(near_point)).z());
309 out_max.z() =
std::min(z_max, frustum.applyInverseMap(secondMap.
applyMap(far_point)).z());
317 #endif // OPENVDB_UTIL_MAPSUTIL_HAS_BEEN_INCLUDED
Vec3d applyMap(const Vec3d &in) const
Return the image of in under the map.
Definition: Maps.h:440
A general linear transform using homogeneous coordinates to perform rotation, scaling, shear and translation.
Definition: Maps.h:324
T & z()
Definition: Vec3.h:99
double Real
Definition: Types.h:65
#define OPENVDB_VERSION_NAME
Definition: version.h:43
Definition: Exceptions.h:39
OPENVDB_API Hermite min(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec3.h:97
Vec3< double > Vec3d
Definition: Vec3.h:629
T & y()
Definition: Vec3.h:98
Vec3d voxelSize() const
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:484
void calculateBounds(const MapType &map, const Vec3d ¢er, const Real radius, BBoxd &out)
Calculate an axis-aligned bounding box in the given map's domain from a spherical bounding box in its...
Definition: MapsUtil.h:86
This map is composed of three steps. Frist it will take a box of size (Lx X Ly X Lz) defined by an me...
Definition: Maps.h:1874
Map traits.
Definition: Maps.h:80
OPENVDB_API Hermite max(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
Vec3d applyInverseMap(const Vec3d &in) const
Return the pre-image of in under the map.
Definition: Maps.h:442
const Vec3T & min() const
Return a const reference to the minimum point of the BBox.
Definition: BBox.h:81
const Vec3T & max() const
Return a const reference to the maximum point of the BBox.
Definition: BBox.h:84
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71