6 #ifndef OPENVDB_MATH_MAPS_HAS_BEEN_INCLUDED
7 #define OPENVDB_MATH_MAPS_HAS_BEEN_INCLUDED
35 class ScaleTranslateMap;
36 class UniformScaleMap;
37 class UniformScaleTranslateMap;
40 class NonlinearFrustumMap;
79 template<
typename T>
struct is_scale {
static const bool value =
false; };
139 using MapFactory =
Ptr (*)();
150 template<
typename MapT>
bool isType()
const {
return this->
type() == MapT::mapType(); }
153 virtual bool isEqual(
const MapBase& other)
const = 0;
156 virtual bool isLinear()
const = 0;
158 virtual bool hasUniformScale()
const = 0;
161 virtual Vec3d applyInverseMap(
const Vec3d&
in)
const = 0;
175 virtual double determinant()
const = 0;
176 virtual double determinant(
const Vec3d&)
const = 0;
183 virtual Vec3d voxelSize()
const = 0;
184 virtual Vec3d voxelSize(
const Vec3d&)
const = 0;
187 virtual void read(std::istream&) = 0;
188 virtual void write(std::ostream&)
const = 0;
223 virtual Vec3d applyInverseJacobian(
const Vec3d&
in)
const = 0;
224 virtual Vec3d applyInverseJacobian(
const Vec3d&
in,
const Vec3d& domainPos)
const = 0;
249 template<
typename MapT>
252 return other.
isType<MapT>() && (
self == *static_cast<const MapT*>(&other));
273 static bool isRegistered(
const Name&);
279 static void unregisterMap(
const Name&);
305 mMatrix(
Mat4d::identity()),
306 mMatrixInv(
Mat4d::identity()),
307 mJacobianInv(
Mat3d::identity()),
309 mVoxelSize(
Vec3d(1,1,1)),
321 updateAcceleration();
328 "Tried to initialize an affine transform from a non-affine 4x4 matrix");
330 updateAcceleration();
335 mMatrix(other.mMatrix),
336 mMatrixInv(other.mMatrixInv),
337 mJacobianInv(other.mJacobianInv),
338 mDeterminant(other.mDeterminant),
339 mVoxelSize(other.mVoxelSize),
340 mIsDiagonal(other.mIsDiagonal),
341 mIsIdentity(other.mIsIdentity)
347 mMatrix(first.mMatrix * second.mMatrix)
349 updateAcceleration();
379 Mat3d mat = mMatrix.getMat3();
380 const double det = mat.
det();
389 bool isEqual(
const MapBase& other)
const override {
return isEqualBase(*
this, other); }
394 if (!mMatrix.eq(other.mMatrix)) {
return false; }
395 if (!mMatrixInv.eq(other.mMatrixInv)) {
return false; }
403 mMatrix = other.mMatrix;
404 mMatrixInv = other.mMatrixInv;
406 mJacobianInv = other.mJacobianInv;
407 mDeterminant = other.mDeterminant;
408 mVoxelSize = other.mVoxelSize;
409 mIsDiagonal = other.mIsDiagonal;
410 mIsIdentity = other.mIsIdentity;
426 return applyInverseJacobian(in);
431 return mMatrixInv.transform3x3(in);
440 return Vec3d( m[ 0] * in[0] + m[ 1] * in[1] + m[ 2] * in[2],
441 m[ 4] * in[0] + m[ 5] * in[1] + m[ 6] * in[2],
442 m[ 8] * in[0] + m[ 9] * in[1] + m[10] * in[2] );
451 return mJacobianInv.
transpose()* m * mJacobianInv;
484 mMatrix.preRotate(axis, radians);
485 updateAcceleration();
490 updateAcceleration();
494 mMatrix.preTranslate(v);
495 updateAcceleration();
499 mMatrix.preShear(axis0, axis1, shear);
500 updateAcceleration();
509 mMatrix.postRotate(axis, radians);
510 updateAcceleration();
514 mMatrix.postScale(v);
515 updateAcceleration();
519 mMatrix.postTranslate(v);
520 updateAcceleration();
524 mMatrix.postShear(axis0, axis1, shear);
525 updateAcceleration();
531 void read(std::istream& is)
override { mMatrix.read(is); updateAcceleration(); }
533 void write(std::ostream& os)
const override { mMatrix.write(os); }
537 std::ostringstream
buffer;
538 buffer <<
" - mat4:\n" << mMatrix.str() << std::endl;
539 buffer <<
" - voxel dimensions: " << mVoxelSize << std::endl;
562 affineMap->accumPreRotation(axis, radians);
568 affineMap->accumPreTranslation(t);
569 return StaticPtrCast<MapBase, AffineMap>(affineMap);
574 affineMap->accumPreScale(s);
575 return StaticPtrCast<MapBase, AffineMap>(affineMap);
580 affineMap->accumPreShear(axis0, axis1, shear);
592 affineMap->accumPostRotation(axis, radians);
598 affineMap->accumPostTranslation(t);
599 return StaticPtrCast<MapBase, AffineMap>(affineMap);
604 affineMap->accumPostScale(s);
605 return StaticPtrCast<MapBase, AffineMap>(affineMap);
610 affineMap->accumPostShear(axis0, axis1, shear);
621 void updateAcceleration() {
622 Mat3d mat3 = mMatrix.getMat3();
623 mDeterminant = mat3.
det();
627 "Tried to initialize an affine transform from a nearly singular matrix");
629 mMatrixInv = mMatrix.inverse();
634 mVoxelSize(0) = (applyMap(
Vec3d(1,0,0)) - pos).
length();
635 mVoxelSize(1) = (applyMap(
Vec3d(0,1,0)) - pos).
length();
636 mVoxelSize(2) = (applyMap(
Vec3d(0,0,1)) - pos).
length();
647 bool mIsDiagonal, mIsIdentity;
663 mScaleValuesInverse(
Vec3d(1,1,1)),
664 mInvScaleSqr(1,1,1), mInvTwiceScale(0.5,0.5,0.5){}
669 mVoxelSize(
Vec3d(std::
abs(scale(0)),std::
abs(scale(1)), std::
abs(scale(2))))
671 double determinant = scale[0]* scale[1] * scale[2];
673 OPENVDB_THROW(ArithmeticError,
"Non-zero scale values required");
675 mScaleValuesInverse = 1.0 / mScaleValues;
676 mInvScaleSqr = mScaleValuesInverse * mScaleValuesInverse;
677 mInvTwiceScale = mScaleValuesInverse / 2;
682 mScaleValues(other.mScaleValues),
683 mVoxelSize(other.mVoxelSize),
684 mScaleValuesInverse(other.mScaleValuesInverse),
685 mInvScaleSqr(other.mInvScaleSqr),
686 mInvTwiceScale(other.mInvTwiceScale)
730 in.
x() * mScaleValues.x(),
731 in.
y() * mScaleValues.y(),
732 in.
z() * mScaleValues.z());
738 in.
x() * mScaleValuesInverse.x(),
739 in.
y() * mScaleValuesInverse.y(),
740 in.
z() * mScaleValuesInverse.z());
750 return applyInverseJacobian(in);
771 for (
int i = 0; i < 3; i++) {
772 tmp.
setRow(i, in.
row(i) * mScaleValuesInverse(i));
774 for (
int i = 0; i < 3; i++) {
775 tmp.
setCol(i, tmp.
col(i) * mScaleValuesInverse(i));
786 return mScaleValues.x() * mScaleValues.y() * mScaleValues.z();
808 void read(std::istream& is)
override
810 mScaleValues.read(is);
812 mScaleValuesInverse.read(is);
813 mInvScaleSqr.read(is);
814 mInvTwiceScale.read(is);
817 void write(std::ostream& os)
const override
819 mScaleValues.write(os);
820 mVoxelSize.write(os);
821 mScaleValuesInverse.write(os);
822 mInvScaleSqr.write(os);
823 mInvTwiceScale.write(os);
828 std::ostringstream
buffer;
829 buffer <<
" - scale: " << mScaleValues << std::endl;
830 buffer <<
" - voxel dimensions: " << mVoxelSize << std::endl;
834 bool isEqual(
const MapBase& other)
const override {
return isEqualBase(*
this, other); }
839 if (!mScaleValues.eq(other.mScaleValues)) {
return false; }
859 affineMap->accumPreRotation(axis, radians);
868 affineMap->accumPreShear(axis0, axis1, shear);
880 affineMap->accumPostRotation(axis, radians);
888 affineMap->accumPostShear(axis0, axis1, shear);
894 Vec3d mScaleValues, mVoxelSize, mScaleValuesInverse, mInvScaleSqr, mInvTwiceScale;
918 const Vec3d& invScale = getInvScale();
933 bool isEqual(
const MapBase& other)
const override {
return isEqualBase(*
this, other); }
955 const Vec3d new_scale(v * mScaleValues);
1024 return applyInverseJacobian(in);
1046 return applyIJC(mat);
1063 void read(std::istream& is)
override { mTranslation.read(is); }
1065 void write(std::ostream& os)
const override { mTranslation.write(os); }
1069 std::ostringstream
buffer;
1070 buffer <<
" - translation: " << mTranslation << std::endl;
1071 return buffer.str();
1074 bool isEqual(
const MapBase& other)
const override {
return isEqualBase(*
this, other); }
1079 return mTranslation.eq(other.mTranslation);
1100 affineMap->accumPreRotation(axis, radians);
1114 affineMap->accumPreShear(axis0, axis1, shear);
1125 affineMap->accumPostRotation(axis, radians);
1139 affineMap->accumPostShear(axis0, axis1, shear);
1163 mTranslation(
Vec3d(0,0,0)),
1164 mScaleValues(
Vec3d(1,1,1)),
1165 mVoxelSize(
Vec3d(1,1,1)),
1166 mScaleValuesInverse(
Vec3d(1,1,1)),
1167 mInvScaleSqr(1,1,1),
1168 mInvTwiceScale(0.5,0.5,0.5)
1174 mTranslation(translate),
1175 mScaleValues(scale),
1176 mVoxelSize(std::
abs(scale(0)), std::
abs(scale(1)), std::
abs(scale(2)))
1178 const double determinant = scale[0]* scale[1] * scale[2];
1180 OPENVDB_THROW(ArithmeticError,
"Non-zero scale values required");
1182 mScaleValuesInverse = 1.0 / mScaleValues;
1183 mInvScaleSqr = mScaleValuesInverse * mScaleValuesInverse;
1184 mInvTwiceScale = mScaleValuesInverse / 2;
1189 mTranslation(translate.getTranslation()),
1191 mVoxelSize(std::
abs(mScaleValues(0)),
1192 std::
abs(mScaleValues(1)),
1193 std::
abs(mScaleValues(2))),
1194 mScaleValuesInverse(1.0 / scale.
getScale())
1196 mInvScaleSqr = mScaleValuesInverse * mScaleValuesInverse;
1197 mInvTwiceScale = mScaleValuesInverse / 2;
1202 mTranslation(other.mTranslation),
1203 mScaleValues(other.mScaleValues),
1204 mVoxelSize(other.mVoxelSize),
1205 mScaleValuesInverse(other.mScaleValuesInverse),
1206 mInvScaleSqr(other.mInvScaleSqr),
1207 mInvTwiceScale(other.mInvTwiceScale)
1220 mScaleValuesInverse, -mScaleValuesInverse * mTranslation));
1253 in.
x() * mScaleValues.x() + mTranslation.x(),
1254 in.
y() * mScaleValues.y() + mTranslation.y(),
1255 in.
z() * mScaleValues.z() + mTranslation.z());
1261 (in.
x() - mTranslation.x() ) * mScaleValuesInverse.x(),
1262 (in.
y() - mTranslation.y() ) * mScaleValuesInverse.y(),
1263 (in.
z() - mTranslation.z() ) * mScaleValuesInverse.z());
1291 in.
x() * mScaleValuesInverse.x(),
1292 in.
y() * mScaleValuesInverse.y(),
1293 in.
z() * mScaleValuesInverse.z());
1299 for (
int i=0; i<3; i++){
1300 tmp.
setRow(i, in.
row(i)*mScaleValuesInverse(i));
1302 for (
int i=0; i<3; i++){
1303 tmp.
setCol(i, tmp.
col(i)*mScaleValuesInverse(i));
1308 return applyIJC(in);
1315 return mScaleValues.x() * mScaleValues.y() * mScaleValues.z();
1335 void read(std::istream& is)
override
1337 mTranslation.read(is);
1338 mScaleValues.read(is);
1339 mVoxelSize.read(is);
1340 mScaleValuesInverse.read(is);
1341 mInvScaleSqr.read(is);
1342 mInvTwiceScale.read(is);
1345 void write(std::ostream& os)
const override
1347 mTranslation.write(os);
1348 mScaleValues.write(os);
1349 mVoxelSize.write(os);
1350 mScaleValuesInverse.write(os);
1351 mInvScaleSqr.write(os);
1352 mInvTwiceScale.write(os);
1357 std::ostringstream
buffer;
1358 buffer <<
" - translation: " << mTranslation << std::endl;
1359 buffer <<
" - scale: " << mScaleValues << std::endl;
1360 buffer <<
" - voxel dimensions: " << mVoxelSize << std::endl;
1361 return buffer.str();
1364 bool isEqual(
const MapBase& other)
const override {
return isEqualBase(*
this, other); }
1369 if (!mScaleValues.eq(other.mScaleValues)) {
return false; }
1370 if (!mTranslation.eq(other.mTranslation)) {
return false; }
1380 affineMap->accumPostTranslation(mTranslation);
1390 affineMap->accumPreRotation(axis, radians);
1395 const Vec3d&
s = mScaleValues;
1396 const Vec3d scaled_trans( t.
x() * s.
x(),
1407 affineMap->accumPreShear(axis0, axis1, shear);
1418 affineMap->accumPostRotation(axis, radians);
1431 affineMap->accumPostShear(axis0, axis1, shear);
1437 Vec3d mTranslation, mScaleValues, mVoxelSize, mScaleValuesInverse,
1438 mInvScaleSqr, mInvTwiceScale;
1453 const Vec3d&
s = mScaleValues;
1454 const Vec3d scaled_trans( t.
x() * s.
x(),
1485 const Vec3d& scaleInv = getInvScale();
1504 bool isEqual(
const MapBase& other)
const override {
return isEqualBase(*
this, other); }
1517 const Vec3d new_trans = this->getTranslation() + scale *
t;
1565 mTranslation.
y()*v.
y(),
1566 mTranslation.
z()*v.
z());
1575 const Vec3d new_scale( v * mScaleValues );
1587 const Vec3d new_scale( v * mScaleValues );
1588 const Vec3d new_trans( mTranslation.
x()*v.
x(),
1589 mTranslation.
y()*v.
y(),
1590 mTranslation.
z()*v.
z() );
1634 OPENVDB_THROW(ArithmeticError,
"Matrix initializing unitary map was not unitary");
1646 "4x4 Matrix initializing unitary map was not unitary: not invertible");
1651 "4x4 Matrix initializing unitary map was not unitary: not affine");
1656 "4x4 Matrix initializing unitary map was not unitary: had translation");
1661 "4x4 Matrix initializing unitary map was not unitary");
1669 mAffineMap(other.mAffineMap)
1674 mAffineMap(*(first.getAffineMap()), *(second.getAffineMap()))
1710 bool isEqual(
const MapBase& other)
const override {
return isEqualBase(*
this, other); }
1715 if (mAffineMap!=other.mAffineMap)
return false;
1732 return applyInverseJacobian(in);
1737 return mAffineMap.applyInverseJacobian(in);
1745 return applyInverseMap(in);
1757 return applyIJC(in);
1763 double determinant()
const override {
return mAffineMap.determinant(); }
1774 void read(std::istream& is)
override
1776 mAffineMap.read(is);
1780 void write(std::ostream& os)
const override
1782 mAffineMap.write(os);
1787 std::ostringstream
buffer;
1788 buffer << mAffineMap.str();
1789 return buffer.str();
1802 return StaticPtrCast<MapBase, UnitaryMap>(unitaryMap);
1809 affineMap->accumPreTranslation(t);
1817 affineMap->accumPreScale(v);
1825 affineMap->accumPreShear(axis0, axis1, shear);
1835 return StaticPtrCast<MapBase, UnitaryMap>(unitaryMap);
1842 affineMap->accumPostTranslation(t);
1850 affineMap->accumPostScale(v);
1858 affineMap->accumPostShear(axis0, axis1, shear);
1895 MapBase(),mBBox(bb), mTaper(taper), mDepth(depth)
1907 mBBox(bb), mTaper(taper), mDepth(depth)
1909 if (!secondMap->isLinear() ) {
1911 "The second map in the Frustum transfrom must be linear");
1913 mSecondMap = *( secondMap->getAffineMap() );
1920 mTaper(other.mTaper),
1921 mDepth(other.mDepth),
1922 mSecondMap(other.mSecondMap),
1923 mHasSimpleAffine(other.mHasSimpleAffine)
1947 double z_near,
double depth,
1955 "The frustum depth must be non-zero and positive");
1957 if (!(up.
length() > 0)) {
1959 "The frustum height must be non-zero and positive");
1961 if (!(aspect > 0)) {
1963 "The frustum aspect ratio must be non-zero and positive");
1967 "The frustum up orientation must be perpendicular to into-frustum direction");
1970 double near_plane_height = 2 * up.
length();
1971 double near_plane_width = aspect * near_plane_height;
1976 mDepth = depth / near_plane_width;
1977 double gamma = near_plane_width / z_near;
1978 mTaper = 1./(mDepth*gamma + 1.);
1989 Vec3d(near_plane_width, near_plane_width, near_plane_width));
1993 Mat4d mat = scale * r2 * r1;
2014 "inverseMap() is not implemented for NonlinearFrustumMap");
2043 const Vec3d e1(1,0,0);
2044 if (!applyMap(e1).eq(e1))
return false;
2046 const Vec3d e2(0,1,0);
2047 if (!applyMap(e2).eq(e2))
return false;
2049 const Vec3d e3(0,0,1);
2050 if (!applyMap(e3).eq(e3))
return false;
2055 bool isEqual(
const MapBase& other)
const override {
return isEqualBase(*
this, other); }
2059 if (mBBox!=other.mBBox)
return false;
2066 if (!mSecondMap.applyMap(e).eq(other.mSecondMap.
applyMap(e)))
return false;
2069 if (!mSecondMap.applyMap(e).eq(other.mSecondMap.
applyMap(e)))
return false;
2072 if (!mSecondMap.applyMap(e).eq(other.mSecondMap.
applyMap(e)))
return false;
2075 if (!mSecondMap.applyMap(e).eq(other.mSecondMap.
applyMap(e)))
return false;
2084 return mSecondMap.applyMap(applyFrustumMap(in));
2090 return applyFrustumInverseMap(mSecondMap.applyInverseMap(in));
2099 Vec3d centered(isloc);
2100 centered = centered - mBBox.min();
2101 centered.
x() -= mXo;
2102 centered.
y() -= mYo;
2105 const double zprime = centered.
z()*mDepthOnLz;
2107 const double scale = (mGamma * zprime + 1.) / mLx;
2108 const double scale2 = mGamma * mDepthOnLz / mLx;
2110 const Vec3d tmp(scale * in.
x() + scale2 * centered.
x()* in.
z(),
2111 scale * in.
y() + scale2 * centered.
y()* in.
z(),
2112 mDepthOnLz * in.
z());
2114 return mSecondMap.applyJacobian(tmp);
2121 return mSecondMap.applyInverseJacobian(in);
2128 Vec3d centered(isloc);
2129 centered = centered - mBBox.min();
2130 centered.
x() -= mXo;
2131 centered.
y() -= mYo;
2134 const double zprime = centered.
z()*mDepthOnLz;
2136 const double scale = (mGamma * zprime + 1.) / mLx;
2137 const double scale2 = mGamma * mDepthOnLz / mLx;
2140 Vec3d out = mSecondMap.applyInverseJacobian(in);
2142 out.
x() = (out.
x() - scale2 * centered.
x() * out.
z() / mDepthOnLz) / scale;
2143 out.
y() = (out.
y() - scale2 * centered.
y() * out.
z() / mDepthOnLz) / scale;
2144 out.
z() = out.
z() / mDepthOnLz;
2152 const Vec3d tmp = mSecondMap.applyJT(in);
2155 Vec3d centered(isloc);
2156 centered = centered - mBBox.min();
2157 centered.
x() -= mXo;
2158 centered.
y() -= mYo;
2161 const double zprime = centered.
z()*mDepthOnLz;
2163 const double scale = (mGamma * zprime + 1.) / mLx;
2164 const double scale2 = mGamma * mDepthOnLz / mLx;
2166 return Vec3d(scale * tmp.
x(),
2168 scale2 * centered.
x()* tmp.
x() +
2169 scale2 * centered.
y()* tmp.
y() +
2170 mDepthOnLz * tmp.
z());
2174 return mSecondMap.applyJT(in);
2190 const Vec3d loc = applyFrustumMap(ijk);
2191 const double s = mGamma * loc.
z() + 1.;
2195 OPENVDB_THROW(ArithmeticError,
"Tried to evaluate the frustum transform"
2196 " at the singular focal point (e.g. camera)");
2199 const double sinv = 1.0/
s;
2200 const double pt0 = mLx * sinv;
2201 const double pt1 = mGamma * pt0;
2202 const double pt2 = pt1 * sinv;
2204 const Mat3d& jacinv = mSecondMap.getConstJacobianInv();
2208 for (
int j = 0; j < 3; ++j ) {
2209 gradE(0,j) = pt0 * jacinv(0,j) - pt2 * loc.
x()*jacinv(2,j);
2210 gradE(1,j) = pt0 * jacinv(1,j) - pt2 * loc.
y()*jacinv(2,j);
2211 gradE(2,j) = (1./mDepthOnLz) * jacinv(2,j);
2215 for (
int i = 0; i < 3; ++i) {
2216 result(i) = d1_is(0) * gradE(0,i) + d1_is(1) * gradE(1,i) + d1_is(2) * gradE(2,i);
2231 const Vec3d loc = applyFrustumMap(ijk);
2233 const double s = mGamma * loc.
z() + 1.;
2237 OPENVDB_THROW(ArithmeticError,
"Tried to evaluate the frustum transform"
2238 " at the singular focal point (e.g. camera)");
2242 const double sinv = 1.0/
s;
2243 const double pt0 = mLx * sinv;
2244 const double pt1 = mGamma * pt0;
2245 const double pt2 = pt1 * sinv;
2246 const double pt3 = pt2 * sinv;
2248 const Mat3d& jacinv = mSecondMap.getConstJacobianInv();
2254 for(
int j = 0; j < 3; j++) {
2255 for (
int k = 0; k < 3; k++) {
2257 const double pt4 = 2. * jacinv(2,j) * jacinv(2,k) * pt3;
2259 matE0(j,k) = -(jacinv(0,j) * jacinv(2,k) + jacinv(2,j) * jacinv(0,k)) * pt2 +
2262 matE1(j,k) = -(jacinv(1,j) * jacinv(2,k) + jacinv(2,j) * jacinv(1,k)) * pt2 +
2269 for (
int j = 0; j < 3; ++j ) {
2270 gradE(0,j) = pt0 * jacinv(0,j) - pt2 * loc.
x()*jacinv(2,j);
2271 gradE(1,j) = pt0 * jacinv(1,j) - pt2 * loc.
y()*jacinv(2,j);
2272 gradE(2,j) = (1./mDepthOnLz) * jacinv(2,j);
2278 for (
int m = 0;
m < 3; ++
m ) {
2279 for (
int n = 0;
n < 3; ++
n) {
2280 for (
int i = 0; i < 3; ++i ) {
2281 for (
int j = 0; j < 3; ++j) {
2282 result(
m,
n) += gradE(j,
m) * gradE(i,
n) * d2_is(i, j);
2288 for (
int m = 0;
m < 3; ++
m ) {
2289 for (
int n = 0;
n < 3; ++
n) {
2291 matE0(
m,
n) * d1_is(0) + matE1(
m,
n) * d1_is(1);
2299 double determinant()
const override {
return mSecondMap.determinant();}
2305 double s = mGamma * loc.
z() + 1.0;
2306 double frustum_determinant = s * s * mDepthOnLzLxLx;
2307 return mSecondMap.determinant() * frustum_determinant;
2313 const Vec3d loc( 0.5*(mBBox.min().x() + mBBox.max().x()),
2314 0.5*(mBBox.min().y() + mBBox.max().y()),
2317 return voxelSize(loc);
2327 Vec3d out, pos = applyMap(loc);
2328 out(0) = (applyMap(loc +
Vec3d(1,0,0)) - pos).
length();
2329 out(1) = (applyMap(loc +
Vec3d(0,1,0)) - pos).
length();
2330 out(2) = (applyMap(loc +
Vec3d(0,0,1)) - pos).
length();
2360 void read(std::istream& is)
override
2366 mBBox =
BBoxd(bb.
min().asVec3d(), bb.
max().asVec3d());
2371 is.read(reinterpret_cast<char*>(&mTaper),
sizeof(
double));
2372 is.read(reinterpret_cast<char*>(&mDepth),
sizeof(
double));
2379 OPENVDB_THROW(KeyError,
"Map " << type <<
" is not registered");
2385 mSecondMap = *(proxy->getAffineMap());
2390 void write(std::ostream& os)
const override
2393 os.write(reinterpret_cast<const char*>(&mTaper),
sizeof(
double));
2394 os.write(reinterpret_cast<const char*>(&mDepth),
sizeof(
double));
2397 mSecondMap.write(os);
2403 std::ostringstream
buffer;
2404 buffer <<
" - taper: " << mTaper << std::endl;
2405 buffer <<
" - depth: " << mDepth << std::endl;
2406 buffer <<
" SecondMap: "<< mSecondMap.type() << std::endl;
2407 buffer << mSecondMap.str() << std::endl;
2408 return buffer.str();
2437 mBBox, mTaper, mDepth, mSecondMap.preShear(shear, axis0, axis1)));
2466 mBBox, mTaper, mDepth, mSecondMap.postShear(shear, axis0, axis1)));
2473 mLx = mBBox.extents().x();
2474 mLy = mBBox.extents().y();
2475 mLz = mBBox.extents().z();
2478 OPENVDB_THROW(ArithmeticError,
"The index space bounding box"
2479 " must have at least two index points in each direction.");
2486 mGamma = (1./mTaper - 1) / mDepth;
2488 mDepthOnLz = mDepth/mLz;
2489 mDepthOnLzLxLx = mDepthOnLz/(mLx * mLx);
2492 mHasSimpleAffine =
true;
2493 Vec3d tmp = mSecondMap.voxelSize();
2496 if (!
isApproxEqual(tmp(0), tmp(1))) { mHasSimpleAffine =
false;
return; }
2497 if (!
isApproxEqual(tmp(0), tmp(2))) { mHasSimpleAffine =
false;
return; }
2506 if (!
isApproxEqual(tmp1.dot(tmp2), 0., 1.e-7)) { mHasSimpleAffine =
false;
return; }
2507 if (!
isApproxEqual(tmp2.dot(tmp3), 0., 1.e-7)) { mHasSimpleAffine =
false;
return; }
2508 if (!
isApproxEqual(tmp3.dot(tmp1), 0., 1.e-7)) { mHasSimpleAffine =
false;
return; }
2517 out = out - mBBox.min();
2522 out.z() *= mDepthOnLz;
2524 double scale = (mGamma * out.z() + 1.)/ mLx;
2533 Vec3d applyFrustumInverseMap(
const Vec3d& in)
const
2537 double invScale = mLx / (mGamma * out.z() + 1.);
2538 out.x() *= invScale;
2539 out.y() *= invScale;
2544 out.z() /= mDepthOnLz;
2547 out = out + mBBox.min();
2559 AffineMap mSecondMap;
2562 double mLx, mLy, mLz;
2563 double mXo, mYo, mGamma, mDepthOnLz, mDepthOnLzLxLx;
2566 bool mHasSimpleAffine;
2576 template<
typename FirstMapType,
typename SecondMapType>
2588 CompoundMap(
const FirstMapType&
f,
const SecondMapType&
s): mFirstMap(f), mSecondMap(s)
2590 updateAffineMatrix();
2594 mFirstMap(other.mFirstMap),
2595 mSecondMap(other.mSecondMap),
2596 mAffineMap(other.mAffineMap)
2602 return (FirstMapType::mapType() +
Name(
":") + SecondMapType::mapType());
2607 if (mFirstMap != other.mFirstMap)
return false;
2608 if (mSecondMap != other.mSecondMap)
return false;
2609 if (mAffineMap != other.mAffineMap)
return false;
2617 mFirstMap = other.mFirstMap;
2618 mSecondMap = other.mSecondMap;
2619 mAffineMap = other.mAffineMap;
2628 return mFirstMap.isIdentity()&&mSecondMap.isIdentity();
2636 return mFirstMap.isDiagonal()&&mSecondMap.isDiagonal();
2647 "Constant affine matrix representation not possible for this nonlinear map");
2652 const FirstMapType&
firstMap()
const {
return mFirstMap; }
2653 const SecondMapType&
secondMap()
const {
return mSecondMap; }
2656 void setSecondMap(
const SecondMapType& second) { mSecondMap = second; updateAffineMatrix(); }
2660 mAffineMap.
read(is);
2662 mSecondMap.read(is);
2666 mAffineMap.
write(os);
2667 mFirstMap.write(os);
2668 mSecondMap.write(os);
2672 void updateAffineMatrix()
2678 mAffineMap =
AffineMap(*first, *second);
2682 FirstMapType mFirstMap;
2683 SecondMapType mSecondMap;
2685 AffineMap mAffineMap;
2692 #endif // OPENVDB_MATH_MAPS_HAS_BEEN_INCLUDED
void setDepth(double d)
set the frustum depth: distance between near and far plane = frustm depth * frustm x-width ...
void accumPreScale(const Vec3d &v)
Modify the existing affine map by pre-applying the given operation.
Vec3d voxelSize(const Vec3d &) const override
Return the absolute values of the scale values, ignores argument.
void accumPostShear(Axis axis0, Axis axis1, double shear)
Modify the existing affine map by post-applying the given operation.
MapBase::Ptr postTranslate(const Vec3d &t) const override
Return a MapBase::Ptr to a new map that is the result of postfixing the appropraite operation...
MapBase::Ptr copy() const override
Return a MapBase::Ptr to a deep copy of this map.
UnitaryMap(const UnitaryMap &other)
static bool isRegistered()
void write(std::ostream &os) const override
write serialization
std::string str() const override
string serialization, useful for debuging
MapBase::Ptr preTranslate(const Vec3d &t) const override
Return a MapBase::Ptr to a new map that is the result of prepending the appropraite operation...
MapBase::Ptr preShear(double shear, Axis axis0, Axis axis1) const override
Return a MapBase::Ptr to a new map that is the result of prepending the appropriate operation...
std::string str() const override
string serialization, useful for debuging
const Vec3d & getInvTwiceScale() const
Return 1/(2 scale). Used to optimize some finite difference calculations.
MyType & operator=(const MyType &other)
NonlinearFrustumMap(const BBoxd &bb, double taper, double depth)
Constructor that takes an index-space bounding box to be mapped into a frustum with a given depth and...
Mat3d applyIJC(const Mat3d &mat, const Vec3d &, const Vec3d &) const override
double determinant(const Vec3d &) const override
Return the determinant of the Jacobian, ignores argument.
bool isInvertible(const MatType &m)
Determine if a matrix is invertible.
NonlinearFrustumMap(const NonlinearFrustumMap &other)
MapBase::Ptr postRotate(double radians, Axis axis) const override
Return a MapBase::Ptr to a new map that is the result of prepending the appropraite operation to the ...
ScaleTranslateMap(const Vec3d &scale, const Vec3d &translate)
MapBase::Ptr inverseMap() const override
Return a new map representing the inverse of this map.
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...
void setToRotation(const Quat< T > &q)
Set this matrix to the rotation matrix specified by the quaternion.
bool isLinear() const override
Return false (a NonlinearFrustumMap is never linear).
Vec3d applyInverseJacobian(const Vec3d &in) const override
Return the Inverse Jacobian of the map applied to in (i.e. inverse map with out translation) ...
bool isType() const
Return true if this map is of concrete type MapT (e.g., AffineMap).
AffineMap & operator=(const AffineMap &other)
void accumPreTranslation(const Vec3d &v)
Modify the existing affine map by pre-applying the given operation.
Creates the composition of two maps, each of which could be a composition. In the case that each comp...
static Name mapType()
Return NonlinearFrustumMap.
bool hasUniformScale() const override
Return false (by convention true)
Vec3d applyJacobian(const Vec3d &in, const Vec3d &) const override
Return the Jacobian of the map applied to in.
void accumPreShear(Axis axis0, Axis axis1, double shear)
Modify the existing affine map by pre-applying the given operation.
bool isLinear() const override
Return true (a UnitaryMap is always linear).
bool operator!=(const ScaleTranslateMap &other) const
bool operator!=(const UnitaryMap &other) const
void read(std::istream &is) override
read serialization
void accumPostScale(const Vec3d &v)
Modify the existing affine map by post-applying the given operation.
MapBase::Ptr postShear(double shear, Axis axis0, Axis axis1) const override
Return a MapBase::Ptr to a new map that is the result of postfixing the appropraite operation...
bool operator==(const ScaleTranslateMap &other) const
Mat3d applyIJC(const Mat3d &in, const Vec3d &, const Vec3d &) const override
Vec3d applyJacobian(const Vec3d &in) const override
Return the Jacobian of the map applied to in.
bool normalize(T eps=T(1.0e-7))
this = normalized this
NonlinearFrustumMap(const BBoxd &bb, double taper, double depth, const MapBase::Ptr &secondMap)
Constructor that takes an index-space bounding box to be mapped into a frustum with a given depth and...
MatType shear(Axis axis0, Axis axis1, typename MatType::value_type shear)
Set the matrix to a shear along axis0 by a fraction of axis1.
const Mat3d & getConstJacobianInv() const
Vec3d applyJacobian(const Vec3d &in) const override
Return the Jacobian of the map applied to in.
Vec3d applyJT(const Vec3d &in) const override
Return the Jacobian Transpose of the map applied to in.
Threadsafe singleton object for accessing the map type-name dictionary. Associates a map type-name wi...
MapBase::Ptr postTranslate(const Vec3d &t) const override
Return a MapBase::Ptr to a new map that is the result of appending the given translation.
void read(std::istream &is) override
read serialization
OIIO_HOSTDEVICE T radians(T deg)
Convert degrees to radians.
const BBoxd & getBBox() const
Return the bounding box that defines the frustum in pre-image space.
MapBase::Ptr preScale(const Vec3d &) const override
Return a MapBase::Ptr to a new map that is the result of prepending the appropraite operation to the ...
std::map< Name, MapBase::MapFactory > MapDictionary
MapBase::Ptr preTranslate(const Vec3d &t) const override
Return a MapBase::Ptr to a new map that is the result of prepending the given translation to the line...
IMF_EXPORT IMATH_NAMESPACE::V3f direction(const IMATH_NAMESPACE::Box2i &dataWindow, const IMATH_NAMESPACE::V2f &pixelPosition)
MapBase::Ptr preRotate(double radians, Axis axis) const override
Return a MapBase::Ptr to a new map that is the result of prepending the appropraite operation...
Vec3d applyMap(const Vec3d &in) const override
Return the image of in under the map.
bool hasUniformScale() const override
Return false ( test if this is unitary with translation )
Mat3d applyIJC(const Mat3d &in) const override
Return the Jacobian Curvature: zero for a linear map.
Name type() const override
Return the name of this map's concrete type (e.g., "AffineMap").
Vec3< T > col(int j) const
Get jth column, e.g. Vec3d v = m.col(0);.
Mat3< T > getMat3() const
Mat3d applyIJC(const Mat3d &in, const Vec3d &, const Vec3d &) const override
GLenum GLenum GLenum GLenum GLenum scale
bool isLinear() const override
Return true (a ScaleTranslateMap is always linear).
A specialized Affine transform that scales along the principal axis the scaling need not be uniform i...
MapBase::Ptr preRotate(double radians, Axis axis=X_AXIS) const override
Return a MapBase::Ptr to a new map that is the result of prepending the appropraite operation...
Vec3d applyJacobian(const Vec3d &in, const Vec3d &) const override
Return the Jacobian of the map applied to in.
bool isLinear() const override
Return true (a TranslationMap is always linear).
bool isScaleTranslate() const
Return true if the map is equivalent to a ScaleTranslateMap.
static bool isRegistered()
Vec3d applyJT(const Vec3d &in) const override
Return the Jacobian Transpose of the map applied to in.
MapBase::Ptr preShear(double shear, Axis axis0, Axis axis1) const override
Return a MapBase::Ptr to a new map that is the result of prepending the given shear to the linear par...
Mat3d applyIJC(const Mat3d &in) const override
Return the Jacobian Curvature: zero for a linear map.
MapBase::Ptr postRotate(double radians, Axis axis=X_AXIS) const override
Return a MapBase::Ptr to a new map that is the result of appending the given rotation to the linear p...
bool isIdentity(const MatType &m)
Determine if a matrix is an identity matrix.
This map is composed of three steps. First it will take a box of size (Lx X Ly X Lz) defined by a mem...
Vec3d applyJT(const Vec3d &in) const override
Return the Jacobian Transpose of the second map applied to in.
#define OPENVDB_USE_VERSION_NAMESPACE
MapBase::Ptr postTranslate(const Vec3d &) const override
Return a MapBase::Ptr to a new map that is the result of prepending the appropraite operation to the ...
double determinant(const Vec3d &loc) const override
AffineMap::Ptr getAffineMap() const
void accumPreRotation(Axis axis, double radians)
Modify the existing affine map by pre-applying the given operation.
UnitaryMap(Axis axis, double radians)
Vec3d applyJT(const Vec3d &in, const Vec3d &isloc) const override
Return the Jacobian Transpose of the map applied to vector in at indexloc.
static bool isRegistered()
NonlinearFrustumMap(const Vec3d &position, const Vec3d &direction, const Vec3d &up, double aspect, double z_near, double depth, Coord::ValueType x_count, Coord::ValueType z_count)
Constructor from a camera frustum.
const SecondMapType & secondMap() const
double determinant() const override
Return the product of the scale values.
SharedPtr< const MapBase > ConstPtr
double determinant() const override
Return 1.
Vec3d applyMap(const Vec3d &in) const override
Return the image of under the map.
static bool isRegistered(const Name &)
Return true if the given map type name is registered.
Vec3d applyJT(const Vec3d &in, const Vec3d &) const override
Return the Jacobian Transpose of the map applied to in.
Vec3d voxelSize() const override
Return (1,1,1).
static MapBase::Ptr create()
Return a MapBase::Ptr to a new TranslationMap.
Vec3d applyInverseMap(const Vec3d &in) const override
Return the pre-image of in under the map.
AffineMap::Ptr getAffineMap() const override
Return AffineMap::Ptr to an AffineMap equivalent to *this.
void write(std::ostream &os) const override
write serialization
Vec3d applyIJT(const Vec3d &in) const override
Return the transpose of the inverse Jacobian of the map applied to in.
Vec3d voxelSize(const Vec3d &) const override
Return (1,1,1).
AffineMap(const AffineMap &first, const AffineMap &second)
constructor that merges the matrixes for two affine maps
MapBase::Ptr postScale(const Vec3d &) const override
Return a MapBase::Ptr to a new map that is the result of prepending the appropraite operation to the ...
void write(std::ostream &os) const override
write serialization
MapBase::Ptr preShear(double shear, Axis axis0, Axis axis1) const override
Return a MapBase::Ptr to a new map that is the result of prepending the appropraite operation...
MapBase::Ptr postTranslate(const Vec3d &t) const override
Return a MapBase::Ptr to a new map that is the result of postfixing the appropraite operation...
bool isEqual(const MapBase &other) const override
Return true if this map is equal to the given map.
MapBase::Ptr postTranslate(const Vec3d &t) const override
Return a MapBase::Ptr to a new map that is the result of postfixing the appropriate operation...
OPENVDB_API Mat4d approxInverse(const Mat4d &mat)
Returns the left pseudoInverse of the input matrix when the 3x3 part is symmetric otherwise it zeros ...
const AffineMap & secondMap() const
Return MapBase::Ptr& to the second map.
T dot(const Vec3< T > &v) const
Dot product.
void setToRotation(Axis axis, T angle)
Sets the matrix to a rotation about the given axis.
void read(T &in, bool &v)
bool isEqual(const MapBase &other) const override
Return true if this map is equal to the given map.
double determinant(const Vec3d &) const override
Return the product of the scale values, ignores argument.
MapBase::Ptr preTranslate(const Vec3d &t) const override
Return a MapBase::Ptr to a new map that is the result of prepending the appropriate operation...
UnitaryMap(const Vec3d &axis, double radians)
MapBase::Ptr preScale(const Vec3d &s) const override
Return a MapBase::Ptr to a new map that is the result of prepending the given scale to the linear par...
ScaleTranslateMap(const ScaleTranslateMap &other)
Vec3d applyJacobian(const Vec3d &in, const Vec3d &) const override
Return the Jacobian of the map applied to in.
Vec3d voxelSize(const Vec3d &) 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...
Tolerance for floating-point comparison.
void setTranslation(const Vec3< T > &t)
MapBase::Ptr inverseMap() const override
Return a new map representing the inverse of this map.
bool operator==(const TranslationMap &other) const
Vec3d applyIJT(const Vec3d &in) const override
Return the transpose of the inverse Jacobian of the map applied to in.
void read(std::istream &is)
Unserialize this bounding box from the given stream.
Mat3d applyIJC(const Mat3d &in, const Vec3d &, const Vec3d &) const override
std::string str() const override
string serialization, useful for debuging
Vec3d applyInverseMap(const Vec3d &in) const override
Return the pre-image of in under the map.
MapBase::Ptr postShear(double shear, Axis axis0, Axis axis1) const override
Return a MapBase::Ptr to a new map that is the result of appending the given shear.
static MapBase::Ptr createMap(const Name &)
Create a new map of the given (registered) type name.
const Coord & min() const
bool isEqual(const MapBase &other) const override
Return true if this map is equal to the given map.
const FirstMapType & firstMap() const
const Vec3d & getScale() const
Returns the scale values.
std::string str() const override
string serialization, useful for debuging
void read(std::istream &is)
bool isLinear() const override
Return true (a ScaleMap is always linear).
OPENVDB_API SharedPtr< PolarDecomposedMap > createPolarDecomposedMap(const Mat3d &m)
Decomposes a general linear into translation following polar decomposition.
Vec3d applyJT(const Vec3d &in) const override
Return the Jacobian Transpose of the map applied to in.
std::shared_ptr< T > SharedPtr
ImageBuf OIIO_API pow(const ImageBuf &A, cspan< float > B, ROI roi={}, int nthreads=0)
static MapBase::Ptr create()
Return a MapBase::Ptr to a new ScaleTranslateMap.
static void registerMap()
MapBase::Ptr preTranslate(const Vec3d &) const override
Return a MapBase::Ptr to a new map that is the result of prepending the appropraite operation to the ...
static MapBase::Ptr create()
Return a MapBase::Ptr to a new UnitaryMap.
Mat3 transpose() const
returns transpose of this
static void registerMap()
bool operator==(const MyType &other) const
Mat3d applyIJC(const Mat3d &mat) const override
Return the Jacobian Curvature: zero for a linear map.
const Vec3d & getInvScale() const
Return 1/(scale)
bool operator!=(const ScaleMap &other) const
ScaleTranslateMap(const ScaleMap &scale, const TranslationMap &translate)
static void registerMap()
const Vec3d & getInvScaleSqr() const
Return the square of the scale. Used to optimize some finite difference calculations.
OPENVDB_API SharedPtr< FullyDecomposedMap > createFullyDecomposedMap(const Mat4d &m)
General decomposition of a Matrix into a Unitary (e.g. rotation) following a Symmetric (e...
void write(std::ostream &os) const override
write serialization
const Mat4d & getConstMat4() const
static MapBase::Ptr create()
Return a MapBase::Ptr to a new AffineMap.
MapBase::Ptr copy() const override
Return a MapBase::Ptr to a deep copy of this map.
bool operator==(const ScaleMap &other) const
Name type() const override
Return the name of this map's concrete type (e.g., "AffineMap").
void accumPostRotation(Axis axis, double radians)
Modify the existing affine map by post-applying the given operation.
double getDepth() const
Return the unscaled frustm depth.
MapBase::Ptr postTranslate(const Vec3d &t) const override
Return a MapBase::Ptr to a new map that is the result of appending the given translation to the linea...
Vec3d applyMap(const Vec3d &in) const override
Return the image of in under the map.
const Vec3d & getInvScaleSqr() const
Return the square of the scale. Used to optimize some finite difference calculations.
bool isApproxEqual(const Type &a, const Type &b, const Type &tolerance)
Return true if a is equal to b to within the given tolerance.
MapBase::Ptr copy() const override
Return a MapBase::Ptr to a deep copy of this map.
MapBase::Ptr preRotate(double radians, Axis axis) const override
Return a MapBase::Ptr to a new map that is the result of prepending the given rotation.
bool hasUniformScale() const override
Return true if the scale values have the same magnitude (eg. -1, 1, -1 would be a rotation)...
double getTaper() const
Return the taper value.
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER T abs(T a)
bool operator!=(const AffineMap &other) const
Vec3d applyIJT(const Vec3d &in) const override
Return the transpose of the inverse Jacobian (Identity for TranslationMap) of the map applied to in...
CompoundMap(const FirstMapType &f, const SecondMapType &s)
Vec3d applyJacobian(const Vec3d &in, const Vec3d &isloc) const override
Return the Jacobian defined at isloc applied to in.
Vec3d applyIJT(const Vec3d &in) const override
Return the transpose of the inverse Jacobian of the map applied to in.
UnitaryMap()
default constructor makes an Idenity.
Vec3d applyIJT(const Vec3d &in, const Vec3d &) const override
Return the transpose of the inverse Jacobian of the map applied to in.
std::string str() const override
string serialization, useful for debugging
bool isDiagonal(const MatType &mat)
Determine if a matrix is diagonal.
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,0,0) − (0,0,1).
Vec3d voxelSize(const Vec3d &loc) const override
Returns the lengths of the images of the three segments from loc to loc + (1,0,0), from loc to loc + (0,1,0) and from loc to loc + (0,0,1)
Mat3 inverse(T tolerance=0) const
static MapBase::Ptr create()
Return a MapBase::Ptr to a new ScaleMap.
double determinant() const override
Return the determinant of the Jacobian of linear second map.
GA_API const UT_StringHolder trans
void writeString(std::ostream &os, const Name &name)
AffineMap::Ptr getAffineMap() const override
Return AffineMap::Ptr to an AffineMap equivalent to *this.
MapBase::Ptr postScale(const Vec3d &v) const override
Return a MapBase::Ptr to a new map that is the result of postfixing the appropraite operation...
float Round(float x)
Return x rounded to the nearest integer.
MapBase::Ptr postRotate(double radians, Axis axis) const override
Return a MapBase::Ptr to a new map that is the result of postfixing the appropraite operation...
MapBase::Ptr copy() const override
Return a MapBase::Ptr to a deep copy of this map.
Vec3d applyJT(const Vec3d &in, const Vec3d &) const override
Return the Jacobian Transpose of the map applied to in.
MapBase::Ptr inverseMap() const override
Return a new map representing the inverse of this map.
Vec3d applyInverseMap(const Vec3d &in) const override
Return the pre-image of under the map.
void read(std::istream &is) override
read serialization
static bool isRegistered()
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
A general linear transform using homogeneous coordinates to perform rotation, scaling, shear and translation.
bool operator!=(const MyType &other) const
void setCol(int j, const Vec3< T > &v)
Set jth column to vector v.
Vec3d applyInverseJacobian(const Vec3d &in) const override
Return the Inverse Jacobian of the map applied to in (i.e. inverse map with out translation) ...
Vec3< T > row(int i) const
Get ith row, e.g. Vec3d v = m.row(1);.
Vec3d voxelSize(const Vec3d &) 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,0,0) − (0,0,1).
void read(std::istream &is)
Unserialize this bounding box from the given stream.
TranslationMap(const TranslationMap &other)
bool hasSimpleAffine() const
Return true if the second map is a uniform scale, Rotation and translation.
ScaleMap(const Vec3d &scale)
Vec3d applyInverseJacobian(const Vec3d &in, const Vec3d &isloc) const override
Return the Inverse Jacobian defined at isloc of the map applied to in.
TranslationMap(const Vec3d &t)
const Vec3d & getTranslation() const
Returns the translation.
GLuint GLsizei GLsizei * length
MapBase::Ptr preScale(const Vec3d &s) const override
Return a MapBase::Ptr to a new map that is the result of prepending the appropraite operation...
const Coord & max() const
MapBase::Ptr postScale(const Vec3d &s) const override
Return a MapBase::Ptr to a new map that is the result of postfixing the appropraite operation...
Vec3d voxelSize() const override
Return the size of a voxel at the center of the near plane.
void write(std::ostream &os) const
void setMat3(const Mat3< T > &m)
Set upper left to a Mat3.
double determinant(const Vec3d &) const override
Return the determinant of the Jacobian, ignores argument.
Mat4d getMat4() const
Return the matrix representation of this AffineMap.
void write(std::ostream &os) const override
write serialization
Axis-aligned bounding box of signed integer coordinates.
MapBase::Ptr preRotate(double radians, Axis axis) const override
Return a MapBase::Ptr to a new map that is the result of prepending the appropraite operation to the ...
Vec3d applyInverseJacobian(const Vec3d &in, const Vec3d &) const override
Return the Inverse Jacobian of the map applied to in (i.e. inverse map with out translation) ...
bool isUnitary(const MatType &m)
Determine if a matrix is unitary (i.e., rotation or reflection).
MapBase::Ptr preScale(const Vec3d &v) const override
Return a MapBase::Ptr to a new map that is the result of prepending the appropriate operation...
Mat3d applyIJC(const Mat3d &in) const override
Return the Jacobian Curvature: zero for a linear map.
double determinant(const Vec3d &) const override
Return the product of the scale values, ignores argument.
MapBase::Ptr preTranslate(const Vec3d &t) const override
Return a MapBase::Ptr to a new map that is the result of prepending the given translation.
T det() const
Determinant of matrix.
Vec3d applyInverseMap(const Vec3d &in) const override
Return the pre-image of in under the map.
Vec3d applyJacobian(const Vec3d &in) const override
Return the Jacobian of the map applied to in.
bool isIdentity() const
Return true if the underlying matrix is approximately an identity.
AffineMap::Ptr getAffineMap() const override
Return a AffineMap equivalent to this map.
Vec3d applyJT(const Vec3d &in) const override
Return the Jacobian Transpose of the map applied to in.
MapBase::Ptr inverseMap() const override
Return a new map representing the inverse of this map.
bool hasUniformScale() const override
Return false (by convention true)
MapBase::Ptr preShear(double shear, Axis axis0, Axis axis1) const override
Return a MapBase::Ptr to a new map that is the result of prepending the appropraite operation to the ...
Vec3d applyIJT(const Vec3d &in) const override
Return the transpose of the inverse Jacobian of the map applied to in.
static bool isEqualBase(const MapT &self, const MapBase &other)
Name type() const override
Return the name of this map's concrete type (e.g., "AffineMap").
Name type() const override
Return the name of this map's concrete type (e.g., "AffineMap").
SharedPtr< FullyDecomposedMap > createDecomposedMap()
on-demand decomposition of the affine map
GLuint GLuint GLsizei GLenum type
AffineMap::Ptr getAffineMap() const override
Return AffineMap::Ptr to an AffineMap equivalent to *this.
MapBase::Ptr postShear(double shear, Axis axis0, Axis axis1) const override
Return a MapBase::Ptr to a new map that is the result of appending the given shear to the linear part...
Vec3d applyJacobian(const Vec3d &in) const override
Return the Jacobian of the linear second map applied to in.
Vec3d applyMap(const Vec3d &in) const override
Return the image of in under the map.
static const Mat3< double > & zero()
Predefined constant for zero matrix.
void setTaper(double t)
set the taper value, the ratio of nearplane width / far plane width
ScaleMap(const ScaleMap &other)
bool operator!=(const NonlinearFrustumMap &other) const
static void registerMap()
static void registerMap()
MapBase::Ptr postRotate(double radians, Axis axis) const override
Return a MapBase::Ptr to a new map that is the result of appending the given rotation.
bool operator==(const UnitaryMap &other) const
Vec3d applyMap(const Vec3d &in) const override
Return the image of in under the map.
MapBase::Ptr postScale(const Vec3d &s) const override
Return a MapBase::Ptr to a new map that is the result of appending the given scale to the linear part...
double determinant() const override
Return the determinant of the Jacobian.
static Name mapType()
Return UnitaryMap.
void setFirstMap(const FirstMapType &first)
Vec3d applyJT(const Vec3d &in, const Vec3d &) const override
UnitaryMap(const UnitaryMap &first, const UnitaryMap &second)
bool isEqual(const MapBase &other) const override
Return true if this map is equal to the given map.
bool hasTranslation(const Mat4< T > &m)
bool isEqual(const MapBase &other) const override
Return true if this map is equal to the given map.
Vec3d applyInverseMap(const Vec3d &in) const override
Return the pre-image of in under the map.
UnitaryMap(const Mat3d &m)
GLsizei const GLchar *const * string
MatType scale(const Vec3< typename MatType::value_type > &s)
Return a matrix that scales by s.
static void registerMap()
AffineMap(const Mat3d &m)
static MapBase::Ptr create()
Return a MapBase::Ptr to a new NonlinearFrustumMap.
void setRow(int i, const Vec3< T > &v)
Set ith row to vector v.
CompoundMap< CompoundMap< UnitaryMap, ScaleMap >, UnitaryMap > SpectralDecomposedMap
SharedPtr< const MyType > ConstPtr
bool isDiagonal() const
Return true if the underylying matrix is diagonal.
Vec3d applyJacobian(const Vec3d &in) const override
Return the Jacobian of the map applied to in.
bool operator!=(const TranslationMap &other) const
MapBase::Ptr preRotate(double radians, Axis axis) const override
Return a MapBase::Ptr to a new map that is the result of prepending the appropriate operation...
Vec3d applyInverseJacobian(const Vec3d &in, const Vec3d &) const override
Return the Inverse Jacobian of the map applied to in (i.e. inverse map with out translation) ...
Vec3d applyInverseJacobian(const Vec3d &in, const Vec3d &) const override
Return the Inverse Jacobian of the map applied to in (i.e. inverse map with out translation) ...
A specialized Affine transform that scales along the principal axis the scaling need not be uniform i...
bool operator==(const NonlinearFrustumMap &other) const
double determinant() const override
Return the determinant of the Jacobian.
MapBase::Ptr postShear(double shear, Axis axis0, Axis axis1) const override
Return a MapBase::Ptr to a new map that is the result of postfixing the appropraite operation...
A specialized linear transform that performs a unitary maping i.e. rotation and or reflection...
bool isScale() const
Return true if the map is equivalent to a ScaleMap.
MapBase::Ptr preRotate(double radians, Axis axis=X_AXIS) const override
Return a MapBase::Ptr to a new map that is the result of prepending the given rotation to the linear ...
bool hasUniformScale() const override
Return true if the values have the same magitude (eg. -1, 1, -1 would be a rotation).
GA_API const UT_StringHolder up
Vec3d applyInverseJacobian(const Vec3d &in) const override
Return the Inverse Jacobian of the map applied to in (i.e. inverse map with out translation) ...
MapBase::Ptr preShear(double shear, Axis axis0, Axis axis1) const override
Return a MapBase::Ptr to a new map that is the result of prepending the given shear.
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
AffineMap(const Mat4d &m)
Vec3d voxelSize() const override
Return the absolute values of the scale values.
Vec3d applyInverseJacobian(const Vec3d &in) const override
Return the Inverse Jacobian of the map applied to in (i.e. inverse map with out translation) ...
std::string str() const override
string serialization, useful for debuging
Mat3d applyIJC(const Mat3d &in) const override
Return the Jacobian Curvature for the linear second map.
Vec3d applyInverseJacobian(const Vec3d &in, const Vec3d &) const override
Return the Inverse Jacobian of the map applied to in (i.e. inverse map with out translation) ...
OIIO_API bool copy(string_view from, string_view to, std::string &err)
OPENVDB_API SharedPtr< MapBase > simplify(SharedPtr< AffineMap > affine)
reduces an AffineMap to a ScaleMap or a ScaleTranslateMap when it can
Vec4< T0 > transform(const Vec4< T0 > &v) const
Transform a Vec4 by post-multiplication.
MapBase::Ptr postScale(const Vec3d &v) const override
Return a MapBase::Ptr to a new map that is the result of appending the given scale.
MapBase::Ptr preScale(const Vec3d &v) const override
Return a MapBase::Ptr to a new map that is the result of prepending the given scale.
math::BBox< Vec3d > BBoxd
void write(std::ostream &os) const override
write serialization
Vec3< typename MatType::value_type > getScale(const MatType &mat)
Return a Vec3 representing the lengths of the passed matrix's upper 3×3's rows.
static const Mat4< double > & identity()
Predefined constant for identity matrix.
MapBase::Ptr copy() const override
Return a MapBase::Ptr to a deep copy of this map.
Vec3d applyIJT(const Vec3d &in, const Vec3d &) const override
Return the transpose of the inverse Jacobian of the map applied to in.
Name readString(std::istream &is)
Vec3d applyInverseJacobian(const Vec3d &in) const override
Return the Inverse Jacobian of the map applied to in (i.e. inverse map with out translation) ...
MapBase::Ptr preShear(double shear, Axis axis0, Axis axis1) const override
Return a MapBase::Ptr to a new map that is the result of prepending the appropraite operation...
CompoundMap(const MyType &other)
void accumPostTranslation(const Vec3d &v)
Modify the existing affine map by post-applying the given operation.
SharedPtr< UnitaryMap > Ptr
void read(std::istream &is) override
read serialization
Vec3d applyIJT(const Vec3d &in, const Vec3d &) const override
Return the transpose of the inverse Jacobian (Identity for TranslationMap) of the map applied to in...
MapBase::Ptr copy() const override
Returns a MapBase::Ptr to a deep copy of *this.
bool hasUniformScale() const override
Return false (by convention false)
MapBase::Ptr postShear(double shear, Axis axis0, Axis axis1) const override
Return a MapBase::Ptr to a new map that is the result of postfixing the appropriate operation...
Mat3d applyIJC(const Mat3d &in, const Vec3d &, const Vec3d &) const override
Vec3d applyInverseJacobian(const Vec3d &in) const override
Return the Inverse Jacobian of the map applied to in (i.e. inverse map with out translation) ...
const Vec3d & getTranslation() const
Return the translation vector.
Vec3d applyJT(const Vec3d &in, const Vec3d &) const override
Return the Jacobian Transpose of the map applied to in.
MapBase::Ptr postShear(double shear, Axis axis0, Axis axis1) const override
Return a MapBase::Ptr to a new map that is the result of prepending the appropraite operation to the ...
Name type() const override
Return UnitaryMap.
const Vec3d & getInvTwiceScale() const
Return 1/(2 scale). Used to optimize some finite difference calculations.
void read(std::istream &is) override
read serialization
const Vec3d & getScale() const
Return the scale values that define the map.
Vec3d applyIJT(const Vec3d &in) const override
Return the transpose of the inverse Jacobian of the linear second map applied to in.
Vec3d applyJT(const Vec3d &in, const Vec3d &) const override
Return the Jacobian Transpose of the map applied to in.
SharedPtr< AffineMap > Ptr
double determinant() const override
Return the product of the scale values.
Vec3d applyInverseJacobian(const Vec3d &in, const Vec3d &) const override
Return the Inverse Jacobian of the map applied to in (i.e. inverse map with out translation) ...
AffineMap::Ptr getAffineMap() const override
Return AffineMap::Ptr to a deep copy of the current AffineMap.
MapBase::Ptr postRotate(double radians, Axis axis=X_AXIS) const override
Return a MapBase::Ptr to a new map that is the result of postfixing the appropraite operation...
Vec3d applyJacobian(const Vec3d &in, const Vec3d &) const override
Return the Jacobian of the map applied to in.
const Vec3d & getInvScale() const
Return 1/(scale)
PUGI__FN char_t * translate(char_t *buffer, const char_t *from, const char_t *to, size_t to_length)
Mat3d applyIJC(const Mat3d &d2_is, const Vec3d &d1_is, const Vec3d &ijk) const override
UnitaryMap(const Mat4d &m)
Vec3d applyJacobian(const Vec3d &in) const override
Return the Jacobian of the map applied to in.
Vec3d applyIJT(const Vec3d &d1_is, const Vec3d &ijk) const override
MapBase::Ptr postScale(const Vec3d &v) const override
Return a MapBase::Ptr to a new map that is the result of postfixing the appropriate operation...
Name type() const override
Return NonlinearFrustumMap.
static bool isRegistered()
void write(T &out, bool v)
bool isIdentity() const
Return true if the map is equivalent to an identity.
static void registerMap(const Name &, MapBase::MapFactory)
Register a map type along with a factory function.
Abstract base class for maps.
AffineMap::Ptr inverse() const
Return AffineMap::Ptr to the inverse of this map.
bool isAffine(const Mat4< T > &m)
OPENVDB_API SharedPtr< SymmetricMap > createSymmetricMap(const Mat3d &m)
Utility methods.
Mat3d applyIJC(const Mat3d &m) const override
Return the Jacobian Curvature: zero for a linear map.
MapBase::Ptr postRotate(double radians, Axis axis) const override
Return a MapBase::Ptr to a new map that is the result of postfixing the appropriate operation...
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
GLsizei const GLfloat * value
MapBase::Ptr preScale(const Vec3d &v) const override
Return a MapBase::Ptr to a new map that is the result of prepending the appropraite operation...
MapBase::Ptr inverseMap() const override
Not implemented, since there is currently no map type that can represent the inverse of a frustum...
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
bool isEqual(const MapBase &other) const override
Return true if this map is equal to the given map.
AffineMap(const AffineMap &other)
Vec3d applyIJT(const Vec3d &in, const Vec3d &) const override
Return the transpose of the inverse Jacobian of the map applied to in.
MapBase::Ptr preTranslate(const Vec3d &t) const override
Return a MapBase::Ptr to a new map that is the result of prepending the appropraite operation...
static bool isRegistered()
bool isLinear() const override
Return true (an AffineMap is always linear).
Vec3d applyMap(const Vec3d &in) const override
Return the image of in under the map.
Vec3d applyInverseMap(const Vec3d &in) const override
Return the pre-image of in under the map.
bool operator==(const AffineMap &other) const
Vec3d voxelSize(const Vec3d &) const override
Returns the lengths of the images of the segments (0,0,0) − (1,0,0), (0,0,0) − (0,1,0) and (0,0,0) − (0,0,1).
Mat4 inverse(T tolerance=0) const
void read(std::istream &is) override
read serialization
T length() const
Length of the vector.
double determinant(const Vec3d &) const override
Return 1.
MapBase::Ptr inverseMap() const override
Return a new map representing the inverse of this map.
#define OPENVDB_THROW(exception, message)
Vec3d applyJacobian(const Vec3d &in, const Vec3d &) const override
Apply the Jacobian of this map to a vector. For a linear map this is equivalent to applying the map e...
GLint GLint GLsizei GLsizei GLsizei depth
AffineMap::Ptr getAffineMap() const override
Vec3d voxelSize() const override
Returns the lengths of the images of the segments (0,0,0) − (1,0,0), (0,0,0) − (0,1,0) and (0,0,0) − (0,0,1).
void setSecondMap(const SecondMapType &second)
Vec3d applyJT(const Vec3d &in) const override
Return the Jacobian Transpose of the map applied to in.
Vec3d applyIJT(const Vec3d &in, const Vec3d &) const override
Return the transpose of the inverse Jacobian of the map applied to in.
A specialized linear transform that performs a translation.