OpenVDB  2.0.0
Maps.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2013 DreamWorks Animation LLC
4 //
5 // All rights reserved. This software is distributed under the
6 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
7 //
8 // Redistributions of source code must retain the above copyright
9 // and license notice and the following restrictions and disclaimer.
10 //
11 // * Neither the name of DreamWorks Animation nor the names of
12 // its contributors may be used to endorse or promote products derived
13 // from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 // IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
27 // LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
28 //
30 //
32 
33 #ifndef OPENVDB_MATH_MAPS_HAS_BEEN_INCLUDED
34 #define OPENVDB_MATH_MAPS_HAS_BEEN_INCLUDED
35 
36 #include "Math.h"
37 #include "Mat4.h"
38 #include "Vec3.h"
39 #include "BBox.h"
40 #include "Coord.h"
41 #include <openvdb/util/Name.h>
42 #include <openvdb/Types.h>
43 #include <boost/shared_ptr.hpp>
44 #include <map>
45 
46 namespace openvdb {
48 namespace OPENVDB_VERSION_NAME {
49 namespace math {
50 
51 
53 
55 
56 class MapBase;
57 class ScaleMap;
58 class TranslationMap;
59 class ScaleTranslateMap;
60 class UniformScaleMap;
61 class UniformScaleTranslateMap;
62 class AffineMap;
63 class UnitaryMap;
64 class NonlinearFrustumMap;
65 
66 template<typename T1, typename T2> class CompoundMap;
67 
73 
74 
76 
78 
79 template<typename T> struct is_linear { static const bool value = false; };
80 template<> struct is_linear<AffineMap> { static const bool value = true; };
81 template<> struct is_linear<ScaleMap> { static const bool value = true; };
82 template<> struct is_linear<UniformScaleMap> { static const bool value = true; };
83 template<> struct is_linear<UnitaryMap> { static const bool value = true; };
84 template<> struct is_linear<TranslationMap> { static const bool value = true; };
85 template<> struct is_linear<ScaleTranslateMap> { static const bool value = true; };
86 template<> struct is_linear<UniformScaleTranslateMap> { static const bool value = true; };
87 
88 template<typename T1, typename T2> struct is_linear<CompoundMap<T1, T2> > {
89  static const bool value = is_linear<T1>::value && is_linear<T2>::value;
90 };
91 
92 
93 template<typename T> struct is_uniform_scale { static const bool value = false; };
94 template<> struct is_uniform_scale<UniformScaleMap> { static const bool value = true; };
95 
96 template<typename T> struct is_uniform_scale_translate { static const bool value = false; };
97 template<> struct is_uniform_scale_translate<TranslationMap> { static const bool value = true; };
99  static const bool value = true;
100 };
101 
102 
103 template<typename T> struct is_scale { static const bool value = false; };
104 template<> struct is_scale<ScaleMap> { static const bool value = true; };
105 
106 template<typename T> struct is_scale_translate { static const bool value = false; };
107 template<> struct is_scale_translate<ScaleTranslateMap> { static const bool value = true; };
108 
109 
110 template<typename T> struct is_uniform_diagonal_jacobian {
112 };
113 
114 template<typename T> struct is_diagonal_jacobian {
115  static const bool value = is_scale<T>::value || is_scale_translate<T>::value;
116 };
117 
118 
120 
122 
125 OPENVDB_API boost::shared_ptr<SymmetricMap> createSymmetricMap(const Mat3d& m);
126 
127 
130 OPENVDB_API boost::shared_ptr<FullyDecomposedMap> createFullyDecomposedMap(const Mat4d& m);
131 
132 
143 OPENVDB_API boost::shared_ptr<PolarDecomposedMap> createPolarDecomposedMap(const Mat3d& m);
144 
145 
147 OPENVDB_API boost::shared_ptr<MapBase> simplify(boost::shared_ptr<AffineMap> affine);
148 
152 
153 
155 
156 
159 {
160 public:
161  typedef boost::shared_ptr<MapBase> Ptr;
162  typedef boost::shared_ptr<const MapBase> ConstPtr;
163  typedef Ptr (*MapFactory)();
164 
165  virtual ~MapBase(){}
166 
167  virtual boost::shared_ptr<AffineMap> getAffineMap() const = 0;
168 
170  virtual Name type() const = 0;
171 
173  template<typename MapT> bool isType() const { return this->type() == MapT::mapType(); }
174 
176  virtual bool isEqual(const MapBase& other) const = 0;
177 
179  virtual bool isLinear() const = 0;
181  virtual bool hasUniformScale() const = 0;
182 
183  virtual Vec3d applyMap(const Vec3d& in) const = 0;
184  virtual Vec3d applyInverseMap(const Vec3d& in) const = 0;
185 
187  virtual Vec3d applyIJT(const Vec3d& in) const = 0;
191  virtual Vec3d applyIJT(const Vec3d& in, const Vec3d& domainPos) const = 0;
193 
194  virtual Mat3d applyIJC(const Mat3d& m) const = 0;
195  virtual Mat3d applyIJC(const Mat3d& m, const Vec3d& v, const Vec3d& domainPos) const = 0;
196 
197 
198  virtual double determinant() const = 0;
199  virtual double determinant(const Vec3d&) const = 0;
200 
201 
203  virtual Vec3d voxelSize() const = 0;
207  virtual Vec3d voxelSize(const Vec3d&) const = 0;
209 
210  virtual void read(std::istream&) = 0;
211  virtual void write(std::ostream&) const = 0;
212 
213  virtual std::string str() const = 0;
214 
215  virtual MapBase::Ptr copy() const = 0;
216 
218  virtual MapBase::Ptr preRotate(double radians, Axis axis = X_AXIS) const = 0;
220  virtual MapBase::Ptr preTranslate(const Vec3d&) const = 0;
221  virtual MapBase::Ptr preScale(const Vec3d&) const = 0;
222  virtual MapBase::Ptr preShear(double shear, Axis axis0, Axis axis1) const = 0;
223 
224  virtual MapBase::Ptr postRotate(double radians, Axis axis = X_AXIS) const = 0;
225  virtual MapBase::Ptr postTranslate(const Vec3d&) const = 0;
226  virtual MapBase::Ptr postScale(const Vec3d&) const = 0;
227  virtual MapBase::Ptr postShear(double shear, Axis axis0, Axis axis1) const = 0;
229 
231  virtual Vec3d applyJacobian(const Vec3d& in) const = 0;
237  virtual Vec3d applyJacobian(const Vec3d& in, const Vec3d& domainPos) const = 0;
239 
241  virtual Vec3d applyInverseJacobian(const Vec3d& in) const = 0;
247  virtual Vec3d applyInverseJacobian(const Vec3d& in, const Vec3d& domainPos) const = 0;
249 
250 
252  virtual Vec3d applyJT(const Vec3d& in) const = 0;
259  virtual Vec3d applyJT(const Vec3d& in, const Vec3d& domainPos) const = 0;
261 
267  virtual MapBase::Ptr inverseMap() const = 0;
268 
269 protected:
270  MapBase() {}
271 
272  template<typename MapT>
273  static bool isEqualBase(const MapT& self, const MapBase& other)
274  {
275  return other.isType<MapT>() && (self == *static_cast<const MapT*>(&other));
276  }
277 };
278 
279 
281 
282 
286 {
287 public:
288  typedef std::map<Name, MapBase::MapFactory> MapDictionary;
289 
290  static MapRegistry* instance();
291 
293  static MapBase::Ptr createMap(const Name&);
294 
296  static bool isRegistered(const Name&);
297 
299  static void registerMap(const Name&, MapBase::MapFactory);
300 
302  static void unregisterMap(const Name&);
303 
305  static void clear();
306 
307 private:
308  MapRegistry() {}
309 
310  static MapRegistry* staticInstance();
311 
312  static MapRegistry* mInstance;
313 
314  MapDictionary mMap;
315 };
316 
317 
319 
320 
324 {
325 public:
326  typedef boost::shared_ptr<AffineMap> Ptr;
327  typedef boost::shared_ptr<const AffineMap> ConstPtr;
328 
330  mMatrix(Mat4d::identity()),
331  mMatrixInv(Mat4d::identity()),
332  mJacobianInv(Mat3d::identity()),
333  mDeterminant(1),
334  mVoxelSize(Vec3d(1,1,1)),
335  mIsDiagonal(true),
336  mIsIdentity(true)
337  // the default constructor for translation is zero
338  {
339  }
340 
341  AffineMap(const Mat3d& m)
342  {
343  Mat4d mat4(Mat4d::identity());
344  mat4.setMat3(m);
345  mMatrix = mat4;
346  updateAcceleration();
347  }
348 
349  AffineMap(const Mat4d& m): mMatrix(m)
350  {
351  if (!isAffine(m)) {
353  "Tried to initialize an affine transform from a non-affine 4x4 matrix");
354  }
355  updateAcceleration();
356  }
357 
358  AffineMap(const AffineMap& other):
359  MapBase(other),
360  mMatrix(other.mMatrix),
361  mMatrixInv(other.mMatrixInv),
362  mJacobianInv(other.mJacobianInv),
363  mDeterminant(other.mDeterminant),
364  mVoxelSize(other.mVoxelSize),
365  mIsDiagonal(other.mIsDiagonal),
366  mIsIdentity(other.mIsIdentity)
367  {
368  }
369 
371  AffineMap(const AffineMap& first, const AffineMap& second):
372  mMatrix(first.mMatrix * second.mMatrix)
373  {
374  updateAcceleration();
375  }
376 
378 
380  static MapBase::Ptr create() { return MapBase::Ptr(new AffineMap()); }
382  MapBase::Ptr copy() const { return MapBase::Ptr(new AffineMap(*this)); }
383 
384  MapBase::Ptr inverseMap() const { return MapBase::Ptr(new AffineMap(mMatrixInv)); }
385 
386  static bool isRegistered() { return MapRegistry::isRegistered(AffineMap::mapType()); }
387 
388  static void registerMap()
389  {
390  MapRegistry::registerMap(
391  AffineMap::mapType(),
392  AffineMap::create);
393  }
394 
395  Name type() const { return mapType(); }
396  static Name mapType() { return Name("AffineMap"); }
397 
399  bool isLinear() const { return true; }
400 
402  bool hasUniformScale() const
403  {
404  Mat3d mat = mMatrix.getMat3();
405  const double det = mat.det();
406  if (isApproxEqual(det, double(0))) {
407  return false;
408  } else {
409  mat *= (1.f / pow(std::abs(det),1./3.));
410  return isUnitary(mat);
411  }
412  }
413 
414  virtual bool isEqual(const MapBase& other) const { return isEqualBase(*this, other); }
415 
416  bool operator==(const AffineMap& other) const
417  {
418  // the Mat.eq() is approximate
419  if (!mMatrix.eq(other.mMatrix)) { return false; }
420  if (!mMatrixInv.eq(other.mMatrixInv)) { return false; }
421  return true;
422  }
423 
424  bool operator!=(const AffineMap& other) const { return !(*this == other); }
425 
427  {
428  mMatrix = other.mMatrix;
429  mMatrixInv = other.mMatrixInv;
430 
431  mJacobianInv = other.mJacobianInv;
432  mDeterminant = other.mDeterminant;
433  mVoxelSize = other.mVoxelSize;
434  mIsDiagonal = other.mIsDiagonal;
435  mIsIdentity = other.mIsIdentity;
436  return *this;
437  }
439  Vec3d applyMap(const Vec3d& in) const { return in * mMatrix; }
441  Vec3d applyInverseMap(const Vec3d& in) const {return in * mMatrixInv; }
442 
444  Vec3d applyJacobian(const Vec3d& in, const Vec3d&) const { return applyJacobian(in); }
446  Vec3d applyJacobian(const Vec3d& in) const { return mMatrix.transform3x3(in); }
447 
449  Vec3d applyInverseJacobian(const Vec3d& in, const Vec3d&) const { return applyInverseJacobian(in); }
451  Vec3d applyInverseJacobian(const Vec3d& in) const { return mMatrixInv.transform3x3(in); }
452 
455  Vec3d applyJT(const Vec3d& in, const Vec3d&) const { return applyJT(in); }
457  Vec3d applyJT(const Vec3d& in) const {
458  const double* m = mMatrix.asPointer();
459  return Vec3d( m[ 0] * in[0] + m[ 1] * in[1] + m[ 2] * in[2],
460  m[ 4] * in[0] + m[ 5] * in[1] + m[ 6] * in[2],
461  m[ 8] * in[0] + m[ 9] * in[1] + m[10] * in[2] );
462  }
463 
465  Vec3d applyIJT(const Vec3d& in, const Vec3d&) const { return applyIJT(in); }
467  Vec3d applyIJT(const Vec3d& in) const { return in * mJacobianInv; }
469  Mat3d applyIJC(const Mat3d& m) const {
470  return mJacobianInv.transpose()* m * mJacobianInv;
471  }
472  Mat3d applyIJC(const Mat3d& in, const Vec3d& , const Vec3d& ) const {
473  return applyIJC(in);
474  }
476  double determinant(const Vec3d& ) const { return determinant(); }
478  double determinant() const { return mDeterminant; }
479 
481  Vec3d voxelSize() const { return mVoxelSize; }
484  Vec3d voxelSize(const Vec3d&) const { return voxelSize(); }
486 
488  bool isIdentity() const { return mIsIdentity; }
490  bool isDiagonal() const { return mIsDiagonal; }
492  bool isScale() const { return isDiagonal(); }
494  bool isScaleTranslate() const { return math::isDiagonal(mMatrix.getMat3()); }
495 
496 
497  // Methods that modify the existing affine map
498 
500  void accumPreRotation(Axis axis, double radians)
502  {
503  mMatrix.preRotate(axis, radians);
504  updateAcceleration();
505  }
506  void accumPreScale(const Vec3d& v)
507  {
508  mMatrix.preScale(v);
509  updateAcceleration();
510  }
511  void accumPreTranslation(const Vec3d& v)
512  {
513  mMatrix.preTranslate(v);
514  updateAcceleration();
515  }
516  void accumPreShear(Axis axis0, Axis axis1, double shear)
517  {
518  mMatrix.preShear(axis0, axis1, shear);
519  updateAcceleration();
520  }
522 
523 
525  void accumPostRotation(Axis axis, double radians)
527  {
528  mMatrix.postRotate(axis, radians);
529  updateAcceleration();
530  }
531  void accumPostScale(const Vec3d& v)
532  {
533  mMatrix.postScale(v);
534  updateAcceleration();
535  }
537  {
538  mMatrix.postTranslate(v);
539  updateAcceleration();
540  }
541  void accumPostShear(Axis axis0, Axis axis1, double shear)
542  {
543  mMatrix.postShear(axis0, axis1, shear);
544  updateAcceleration();
545  }
547 
548 
550  void read(std::istream& is)
551  {
552  mMatrix.read(is);
553  updateAcceleration();
554  }
555 
557  void write(std::ostream& os) const
558  {
559  mMatrix.write(os);
560  }
561 
563  std::string str() const
564  {
565  std::ostringstream buffer;
566  buffer << " - mat4:\n" << mMatrix.str() << std::endl;
567  buffer << " - voxel dimensions: " << mVoxelSize << std::endl;
568  return buffer.str();
569  }
570 
572  boost::shared_ptr<FullyDecomposedMap> createDecomposedMap()
573  {
574  return createFullyDecomposedMap(mMatrix);
575  }
576 
578  AffineMap::Ptr getAffineMap() const { return AffineMap::Ptr(new AffineMap(*this)); }
579 
581  AffineMap::Ptr inverse() const { return AffineMap::Ptr(new AffineMap(mMatrixInv)); }
582 
583 
585  MapBase::Ptr preRotate(double radians, Axis axis = X_AXIS) const
588  {
589  AffineMap::Ptr affineMap = getAffineMap();
590  affineMap->accumPreRotation(axis, radians);
591  return simplify(affineMap);
592  }
594  {
595  AffineMap::Ptr affineMap = getAffineMap();
596  affineMap->accumPreTranslation(t);
597  return boost::static_pointer_cast<MapBase, AffineMap>(affineMap);
598  }
599  MapBase::Ptr preScale(const Vec3d& s) const
600  {
601  AffineMap::Ptr affineMap = getAffineMap();
602  affineMap->accumPreScale(s);
603  return boost::static_pointer_cast<MapBase, AffineMap>(affineMap);
604  }
605  MapBase::Ptr preShear(double shear, Axis axis0, Axis axis1) const
606  {
607  AffineMap::Ptr affineMap = getAffineMap();
608  affineMap->accumPreShear(axis0, axis1, shear);
609  return simplify(affineMap);
610  }
612 
613 
615  MapBase::Ptr postRotate(double radians, Axis axis = X_AXIS) const
618  {
619  AffineMap::Ptr affineMap = getAffineMap();
620  affineMap->accumPostRotation(axis, radians);
621  return simplify(affineMap);
622  }
624  {
625  AffineMap::Ptr affineMap = getAffineMap();
626  affineMap->accumPostTranslation(t);
627  return boost::static_pointer_cast<MapBase, AffineMap>(affineMap);
628  }
629  MapBase::Ptr postScale(const Vec3d& s) const
630  {
631  AffineMap::Ptr affineMap = getAffineMap();
632  affineMap->accumPostScale(s);
633  return boost::static_pointer_cast<MapBase, AffineMap>(affineMap);
634  }
635  MapBase::Ptr postShear(double shear, Axis axis0, Axis axis1) const
636  {
637  AffineMap::Ptr affineMap = getAffineMap();
638  affineMap->accumPostShear(axis0, axis1, shear);
639  return simplify(affineMap);
640  }
642 
644  Mat4d getMat4() const { return mMatrix;}
645  const Mat4d& getConstMat4() const {return mMatrix;}
646  const Mat3d& getConstJacobianInv() const {return mJacobianInv;}
647 
648 private:
649  void updateAcceleration() {
650  Mat3d mat3 = mMatrix.getMat3();
651  mDeterminant = mat3.det();
652 
653  if (std::abs(mDeterminant) < (3.0 * math::Tolerance<double>::value())) {
655  "Tried to initialize an affine transform from a nearly singular matrix");
656  }
657  mMatrixInv = mMatrix.inverse();
658  mJacobianInv = mat3.inverse().transpose();
659  mIsDiagonal = math::isDiagonal(mMatrix);
660  mIsIdentity = math::isIdentity(mMatrix);
661  Vec3d pos = applyMap(Vec3d(0,0,0));
662  mVoxelSize(0) = (applyMap(Vec3d(1,0,0)) - pos).length();
663  mVoxelSize(1) = (applyMap(Vec3d(0,1,0)) - pos).length();
664  mVoxelSize(2) = (applyMap(Vec3d(0,0,1)) - pos).length();
665  }
666 
667  // the underlying matrix
668  Mat4d mMatrix;
669 
670  // stored for acceleration
671  Mat4d mMatrixInv;
672  Mat3d mJacobianInv;
673  double mDeterminant;
674  Vec3d mVoxelSize;
675  bool mIsDiagonal, mIsIdentity;
676 }; // class AffineMap
677 
678 
680 
681 
685 {
686 public:
687  typedef boost::shared_ptr<ScaleMap> Ptr;
688  typedef boost::shared_ptr<const ScaleMap> ConstPtr;
689 
690  ScaleMap(): MapBase(), mScaleValues(Vec3d(1,1,1)), mVoxelSize(Vec3d(1,1,1)),
691  mScaleValuesInverse(Vec3d(1,1,1)),
692  mInvScaleSqr(1,1,1), mInvTwiceScale(0.5,0.5,0.5){}
693 
695  MapBase(),
696  mScaleValues(scale),
697  mVoxelSize(Vec3d(std::abs(scale(0)),std::abs(scale(1)), std::abs(scale(2))))
698  {
699  double determinant = scale[0]* scale[1] * scale[2];
700  if (std::abs(determinant) < 3.0 * math::Tolerance<double>::value()) {
701  OPENVDB_THROW(ArithmeticError, "Non-zero scale values required");
702  }
703  mScaleValuesInverse = 1.0 / mScaleValues;
704  mInvScaleSqr = mScaleValuesInverse * mScaleValuesInverse;
705  mInvTwiceScale = mScaleValuesInverse / 2;
706  }
707 
708  ScaleMap(const ScaleMap& other):
709  MapBase(),
710  mScaleValues(other.mScaleValues),
711  mVoxelSize(other.mVoxelSize),
712  mScaleValuesInverse(other.mScaleValuesInverse),
713  mInvScaleSqr(other.mInvScaleSqr),
714  mInvTwiceScale(other.mInvTwiceScale)
715  {
716  }
717 
719 
721  static MapBase::Ptr create() { return MapBase::Ptr(new ScaleMap()); }
723  MapBase::Ptr copy() const { return MapBase::Ptr(new ScaleMap(*this)); }
724 
725  MapBase::Ptr inverseMap() const { return MapBase::Ptr(new ScaleMap(mScaleValuesInverse)); }
726 
727  static bool isRegistered() { return MapRegistry::isRegistered(ScaleMap::mapType()); }
728 
729  static void registerMap()
730  {
731  MapRegistry::registerMap(
732  ScaleMap::mapType(),
733  ScaleMap::create);
734  }
735 
736  Name type() const { return mapType(); }
737  static Name mapType() { return Name("ScaleMap"); }
738 
740  bool isLinear() const { return true; }
741 
743  bool hasUniformScale() const
744  {
745  bool value = isApproxEqual(
746  std::abs(mScaleValues.x()), std::abs(mScaleValues.y()), double(5e-7));
747  value = value && isApproxEqual(
748  std::abs(mScaleValues.x()), std::abs(mScaleValues.z()), double(5e-7));
749  return value;
750  }
751 
753  Vec3d applyMap(const Vec3d& in) const
754  {
755  return Vec3d(
756  in.x() * mScaleValues.x(),
757  in.y() * mScaleValues.y(),
758  in.z() * mScaleValues.z());
759  }
761  Vec3d applyInverseMap(const Vec3d& in) const
762  {
763  return Vec3d(
764  in.x() * mScaleValuesInverse.x(),
765  in.y() * mScaleValuesInverse.y(),
766  in.z() * mScaleValuesInverse.z());
767  }
769  Vec3d applyJacobian(const Vec3d& in, const Vec3d&) const { return applyJacobian(in); }
771  Vec3d applyJacobian(const Vec3d& in) const { return applyMap(in); }
772 
774  Vec3d applyInverseJacobian(const Vec3d& in, const Vec3d&) const { return applyInverseJacobian(in); }
776  Vec3d applyInverseJacobian(const Vec3d& in) const { return applyInverseMap(in); }
777 
780  Vec3d applyJT(const Vec3d& in, const Vec3d&) const { return applyJT(in); }
782  Vec3d applyJT(const Vec3d& in) const { return applyMap(in); }
783 
784 
785 
788  Vec3d applyIJT(const Vec3d& in, const Vec3d&) const { return applyIJT(in);}
790  Vec3d applyIJT(const Vec3d& in) const { return applyInverseMap(in); }
792  Mat3d applyIJC(const Mat3d& in) const
793  {
794  Mat3d tmp;
795  for (int i = 0; i < 3; i++) {
796  tmp.setRow(i, in.row(i) * mScaleValuesInverse(i));
797  }
798  for (int i = 0; i < 3; i++) {
799  tmp.setCol(i, tmp.col(i) * mScaleValuesInverse(i));
800  }
801  return tmp;
802  }
803  Mat3d applyIJC(const Mat3d& in, const Vec3d&, const Vec3d&) const { return applyIJC(in); }
805  double determinant(const Vec3d&) const { return determinant(); }
807  double determinant() const { return mScaleValues.x() * mScaleValues.y() * mScaleValues.z(); }
808 
810  const Vec3d& getScale() const {return mScaleValues;}
811 
813  const Vec3d& getInvScaleSqr() const { return mInvScaleSqr; }
815  const Vec3d& getInvTwiceScale() const { return mInvTwiceScale; }
817  const Vec3d& getInvScale() const { return mScaleValuesInverse; }
818 
820  Vec3d voxelSize() const { return mVoxelSize; }
825  Vec3d voxelSize(const Vec3d&) const { return voxelSize(); }
827 
829  void read(std::istream& is)
830  {
831  mScaleValues.read(is);
832  mVoxelSize.read(is);
833  mScaleValuesInverse.read(is);
834  mInvScaleSqr.read(is);
835  mInvTwiceScale.read(is);
836  }
838  void write(std::ostream& os) const
839  {
840  mScaleValues.write(os);
841  mVoxelSize.write(os);
842  mScaleValuesInverse.write(os);
843  mInvScaleSqr.write(os);
844  mInvTwiceScale.write(os);
845  }
847  std::string str() const
848  {
849  std::ostringstream buffer;
850  buffer << " - scale: " << mScaleValues << std::endl;
851  buffer << " - voxel dimensions: " << mVoxelSize << std::endl;
852  return buffer.str();
853  }
854 
855  virtual bool isEqual(const MapBase& other) const { return isEqualBase(*this, other); }
856 
857  bool operator==(const ScaleMap& other) const
858  {
859  // ::eq() uses a tolerance
860  if (!mScaleValues.eq(other.mScaleValues)) { return false; }
861  return true;
862  }
863 
864  bool operator!=(const ScaleMap& other) const { return !(*this == other); }
865 
868  {
869  return AffineMap::Ptr(new AffineMap(math::scale<Mat4d>(mScaleValues)));
870  }
871 
872 
873 
875  MapBase::Ptr preRotate(double radians, Axis axis) const
878  {
879  AffineMap::Ptr affineMap = getAffineMap();
880  affineMap->accumPreRotation(axis, radians);
881  return simplify(affineMap);
882  }
883 
884  MapBase::Ptr preTranslate(const Vec3d& tr) const;
885 
886  MapBase::Ptr preScale(const Vec3d& v) const;
887 
888  MapBase::Ptr preShear(double shear, Axis axis0, Axis axis1) const
889  {
890  AffineMap::Ptr affineMap = getAffineMap();
891  affineMap->accumPreShear(axis0, axis1, shear);
892  return simplify(affineMap);
893  }
895 
896 
898  MapBase::Ptr postRotate(double radians, Axis axis) const
901  {
902  AffineMap::Ptr affineMap = getAffineMap();
903  affineMap->accumPostRotation(axis, radians);
904  return simplify(affineMap);
905  }
906 
907  MapBase::Ptr postTranslate(const Vec3d& tr) const;
908 
909  MapBase::Ptr postScale(const Vec3d& v) const;
910 
911  MapBase::Ptr postShear(double shear, Axis axis0, Axis axis1) const
912  {
913  AffineMap::Ptr affineMap = getAffineMap();
914  affineMap->accumPostShear(axis0, axis1, shear);
915  return simplify(affineMap);
916  }
918 
919 private:
920  Vec3d mScaleValues, mVoxelSize, mScaleValuesInverse, mInvScaleSqr, mInvTwiceScale;
921 }; // class ScaleMap
922 
923 
927 {
928 public:
929  typedef boost::shared_ptr<UniformScaleMap> Ptr;
930  typedef boost::shared_ptr<const UniformScaleMap> ConstPtr;
931 
933  UniformScaleMap(double scale): ScaleMap(Vec3d(scale, scale, scale)) {}
934  UniformScaleMap(const UniformScaleMap& other): ScaleMap(other) {}
936 
938  static MapBase::Ptr create() { return MapBase::Ptr(new UniformScaleMap()); }
940  MapBase::Ptr copy() const { return MapBase::Ptr(new UniformScaleMap(*this)); }
941 
943  const Vec3d& invScale = getInvScale();
944  return MapBase::Ptr(new UniformScaleMap( invScale[0])); }
945 
946  static bool isRegistered() { return MapRegistry::isRegistered(UniformScaleMap::mapType()); }
947  static void registerMap()
948  {
949  MapRegistry::registerMap(
950  UniformScaleMap::mapType(),
951  UniformScaleMap::create);
952  }
953 
954  Name type() const { return mapType(); }
955  static Name mapType() { return Name("UniformScaleMap"); }
956 
957  virtual bool isEqual(const MapBase& other) const { return isEqualBase(*this, other); }
958 
959  bool operator==(const UniformScaleMap& other) const { return ScaleMap::operator==(other); }
960  bool operator!=(const UniformScaleMap& other) const { return !(*this == other); }
961 
964  MapBase::Ptr preTranslate(const Vec3d& tr) const;
965 
968  MapBase::Ptr postTranslate(const Vec3d& tr) const;
969 
970 }; // class UniformScaleMap
971 
972 
974 
975 
976 inline MapBase::Ptr
977 ScaleMap::preScale(const Vec3d& v) const
978 {
979  const Vec3d new_scale(v * mScaleValues);
980  if (isApproxEqual(new_scale[0],new_scale[1]) && isApproxEqual(new_scale[0],new_scale[2])) {
981  return MapBase::Ptr(new UniformScaleMap(new_scale[0]));
982  } else {
983  return MapBase::Ptr(new ScaleMap(new_scale));
984  }
985 }
986 
987 
988 inline MapBase::Ptr
989 ScaleMap::postScale(const Vec3d& v) const
990 { // pre-post Scale are the same for a scale map
991  return preScale(v);
992 }
993 
994 
997 {
998 public:
999  typedef boost::shared_ptr<TranslationMap> Ptr;
1000  typedef boost::shared_ptr<const TranslationMap> ConstPtr;
1001 
1002  // default constructor is a translation by zero.
1003  TranslationMap(): MapBase(), mTranslation(Vec3d(0,0,0)) {}
1004  TranslationMap(const Vec3d& t): MapBase(), mTranslation(t) {}
1005  TranslationMap(const TranslationMap& other): MapBase(), mTranslation(other.mTranslation) {}
1006 
1008 
1010  static MapBase::Ptr create() { return MapBase::Ptr(new TranslationMap()); }
1012  MapBase::Ptr copy() const { return MapBase::Ptr(new TranslationMap(*this)); }
1013 
1014  MapBase::Ptr inverseMap() const { return MapBase::Ptr(new TranslationMap(-mTranslation)); }
1015 
1016  static bool isRegistered() { return MapRegistry::isRegistered(TranslationMap::mapType()); }
1017 
1018  static void registerMap()
1019  {
1020  MapRegistry::registerMap(
1021  TranslationMap::mapType(),
1022  TranslationMap::create);
1023  }
1024 
1025  Name type() const { return mapType(); }
1026  static Name mapType() { return Name("TranslationMap"); }
1027 
1029  bool isLinear() const { return true; }
1030 
1032  bool hasUniformScale() const { return true; }
1033 
1035  Vec3d applyMap(const Vec3d& in) const { return in + mTranslation; }
1037  Vec3d applyInverseMap(const Vec3d& in) const { return in - mTranslation; }
1039  Vec3d applyJacobian(const Vec3d& in, const Vec3d&) const { return applyJacobian(in); }
1041  Vec3d applyJacobian(const Vec3d& in) const { return in; }
1042 
1044  Vec3d applyInverseJacobian(const Vec3d& in, const Vec3d&) const { return applyInverseJacobian(in); }
1046  Vec3d applyInverseJacobian(const Vec3d& in) const { return in; }
1047 
1048 
1051  Vec3d applyJT(const Vec3d& in, const Vec3d&) const { return applyJT(in); }
1053  Vec3d applyJT(const Vec3d& in) const { return in; }
1054 
1057  Vec3d applyIJT(const Vec3d& in, const Vec3d& ) const { return applyIJT(in);}
1060  Vec3d applyIJT(const Vec3d& in) const {return in;}
1062  Mat3d applyIJC(const Mat3d& mat) const {return mat;}
1063  Mat3d applyIJC(const Mat3d& mat, const Vec3d&, const Vec3d&) const { return applyIJC(mat); }
1064 
1066  double determinant(const Vec3d& ) const { return determinant(); }
1068  double determinant() const { return 1.0; }
1069 
1071  Vec3d voxelSize() const { return Vec3d(1,1,1);}
1073  Vec3d voxelSize(const Vec3d&) const { return voxelSize();}
1074 
1076  const Vec3d& getTranslation() const { return mTranslation; }
1078  void read(std::istream& is) { mTranslation.read(is); }
1080  void write(std::ostream& os) const { mTranslation.write(os); }
1081 
1083  std::string str() const
1084  {
1085  std::ostringstream buffer;
1086  buffer << " - translation: " << mTranslation << std::endl;
1087  return buffer.str();
1088  }
1089 
1090  virtual bool isEqual(const MapBase& other) const { return isEqualBase(*this, other); }
1091 
1092  bool operator==(const TranslationMap& other) const
1093  {
1094  // ::eq() uses a tolerance
1095  return mTranslation.eq(other.mTranslation);
1096  }
1097 
1098  bool operator!=(const TranslationMap& other) const { return !(*this == other); }
1099 
1102  {
1103  Mat4d matrix(Mat4d::identity());
1104  matrix.setTranslation(mTranslation);
1105 
1106  AffineMap::Ptr affineMap(new AffineMap(matrix));
1107  return affineMap;
1108  }
1109 
1111  MapBase::Ptr preRotate(double radians, Axis axis) const
1114  {
1115  AffineMap::Ptr affineMap = getAffineMap();
1116  affineMap->accumPreRotation(axis, radians);
1117  return simplify(affineMap);
1118 
1119  }
1121  {
1122  return MapBase::Ptr(new TranslationMap(t + mTranslation));
1123  }
1124 
1125  MapBase::Ptr preScale(const Vec3d& v) const;
1126 
1127  MapBase::Ptr preShear(double shear, Axis axis0, Axis axis1) const
1128  {
1129  AffineMap::Ptr affineMap = getAffineMap();
1130  affineMap->accumPreShear(axis0, axis1, shear);
1131  return simplify(affineMap);
1132  }
1134 
1136  MapBase::Ptr postRotate(double radians, Axis axis) const
1139  {
1140  AffineMap::Ptr affineMap = getAffineMap();
1141  affineMap->accumPostRotation(axis, radians);
1142  return simplify(affineMap);
1143 
1144  }
1146  { // post and pre are the same for this
1147  return MapBase::Ptr(new TranslationMap(t + mTranslation));
1148  }
1149 
1150  MapBase::Ptr postScale(const Vec3d& v) const;
1151 
1152  MapBase::Ptr postShear(double shear, Axis axis0, Axis axis1) const
1153  {
1154  AffineMap::Ptr affineMap = getAffineMap();
1155  affineMap->accumPostShear(axis0, axis1, shear);
1156  return simplify(affineMap);
1157  }
1159 
1160 private:
1161  Vec3d mTranslation;
1162 }; // class TranslationMap
1163 
1164 
1166 
1167 
1172 {
1173 public:
1174  typedef boost::shared_ptr<ScaleTranslateMap> Ptr;
1175  typedef boost::shared_ptr<const ScaleTranslateMap> ConstPtr;
1176 
1178  MapBase(),
1179  mTranslation(Vec3d(0,0,0)),
1180  mScaleValues(Vec3d(1,1,1)),
1181  mVoxelSize(Vec3d(1,1,1)),
1182  mScaleValuesInverse(Vec3d(1,1,1)),
1183  mInvScaleSqr(1,1,1),
1184  mInvTwiceScale(0.5,0.5,0.5)
1185  {
1186  }
1187 
1188  ScaleTranslateMap(const Vec3d& scale, const Vec3d& translate):
1189  MapBase(),
1190  mTranslation(translate),
1191  mScaleValues(scale),
1192  mVoxelSize(std::abs(scale(0)), std::abs(scale(1)), std::abs(scale(2)))
1193  {
1194  const double determinant = scale[0]* scale[1] * scale[2];
1195  if (std::abs(determinant) < 3.0 * math::Tolerance<double>::value()) {
1196  OPENVDB_THROW(ArithmeticError, "Non-zero scale values required");
1197  }
1198  mScaleValuesInverse = 1.0 / mScaleValues;
1199  mInvScaleSqr = mScaleValuesInverse * mScaleValuesInverse;
1200  mInvTwiceScale = mScaleValuesInverse / 2;
1201  }
1202 
1203  ScaleTranslateMap(const ScaleMap& scale, const TranslationMap& translate):
1204  MapBase(),
1205  mTranslation(translate.getTranslation()),
1206  mScaleValues(scale.getScale()),
1207  mVoxelSize(std::abs(mScaleValues(0)),
1208  std::abs(mScaleValues(1)),
1209  std::abs(mScaleValues(2))),
1210  mScaleValuesInverse(1.0 / scale.getScale())
1211  {
1212  mInvScaleSqr = mScaleValuesInverse * mScaleValuesInverse;
1213  mInvTwiceScale = mScaleValuesInverse / 2;
1214  }
1215 
1217  MapBase(),
1218  mTranslation(other.mTranslation),
1219  mScaleValues(other.mScaleValues),
1220  mVoxelSize(other.mVoxelSize),
1221  mScaleValuesInverse(other.mScaleValuesInverse),
1222  mInvScaleSqr(other.mInvScaleSqr),
1223  mInvTwiceScale(other.mInvTwiceScale)
1224  {}
1225 
1227 
1231  MapBase::Ptr copy() const { return MapBase::Ptr(new ScaleTranslateMap(*this)); }
1232 
1234  {
1235  return MapBase::Ptr(new ScaleTranslateMap(
1236  mScaleValuesInverse, -mScaleValuesInverse * mTranslation));
1237  }
1238 
1239  static bool isRegistered() { return MapRegistry::isRegistered(ScaleTranslateMap::mapType()); }
1240 
1241  static void registerMap()
1242  {
1243  MapRegistry::registerMap(
1244  ScaleTranslateMap::mapType(),
1245  ScaleTranslateMap::create);
1246  }
1247 
1248  Name type() const { return mapType(); }
1249  static Name mapType() { return Name("ScaleTranslateMap"); }
1250 
1252  bool isLinear() const { return true; }
1253 
1256  bool hasUniformScale() const
1257  {
1258  bool value = isApproxEqual(
1259  std::abs(mScaleValues.x()), std::abs(mScaleValues.y()), double(5e-7));
1260  value = value && isApproxEqual(
1261  std::abs(mScaleValues.x()), std::abs(mScaleValues.z()), double(5e-7));
1262  return value;
1263  }
1264 
1266  Vec3d applyMap(const Vec3d& in) const
1267  {
1268  return Vec3d(
1269  in.x() * mScaleValues.x() + mTranslation.x(),
1270  in.y() * mScaleValues.y() + mTranslation.y(),
1271  in.z() * mScaleValues.z() + mTranslation.z());
1272  }
1274  Vec3d applyInverseMap(const Vec3d& in) const
1275  {
1276  return Vec3d(
1277  (in.x() - mTranslation.x() ) / mScaleValues.x(),
1278  (in.y() - mTranslation.y() ) / mScaleValues.y(),
1279  (in.z() - mTranslation.z() ) / mScaleValues.z());
1280  }
1281 
1283  Vec3d applyJacobian(const Vec3d& in, const Vec3d&) const { return applyJacobian(in); }
1285  Vec3d applyJacobian(const Vec3d& in) const { return in * mScaleValues; }
1286 
1288  Vec3d applyInverseJacobian(const Vec3d& in, const Vec3d&) const { return applyInverseJacobian(in); }
1290  Vec3d applyInverseJacobian(const Vec3d& in) const { return in / mScaleValues; }
1291 
1294  Vec3d applyJT(const Vec3d& in, const Vec3d&) const { return applyJT(in); }
1296  Vec3d applyJT(const Vec3d& in) const { return applyJacobian(in); }
1297 
1300  Vec3d applyIJT(const Vec3d& in, const Vec3d& ) const { return applyIJT(in);}
1302  Vec3d applyIJT(const Vec3d& in) const
1303  {
1304  return Vec3d(
1305  in.x() / mScaleValues.x(),
1306  in.y() / mScaleValues.y(),
1307  in.z() / mScaleValues.z());
1308  }
1310  Mat3d applyIJC(const Mat3d& in) const
1311  {
1312  Mat3d tmp;
1313  for (int i=0; i<3; i++){
1314  tmp.setRow(i, in.row(i)*mScaleValuesInverse(i));
1315  }
1316  for (int i=0; i<3; i++){
1317  tmp.setCol(i, tmp.col(i)*mScaleValuesInverse(i));
1318  }
1319  return tmp;
1320  }
1321  Mat3d applyIJC(const Mat3d& in, const Vec3d&, const Vec3d& ) const { return applyIJC(in); }
1322 
1324  double determinant(const Vec3d& ) const { return determinant(); }
1326  double determinant() const { return mScaleValues.x()*mScaleValues.y()*mScaleValues.z(); }
1328  Vec3d voxelSize() const { return mVoxelSize;}
1331  Vec3d voxelSize(const Vec3d&) const { return voxelSize();}
1332 
1334  const Vec3d& getScale() const { return mScaleValues; }
1336  const Vec3d& getTranslation() const { return mTranslation; }
1337 
1339  const Vec3d& getInvScaleSqr() const {return mInvScaleSqr;}
1341  const Vec3d& getInvTwiceScale() const {return mInvTwiceScale;}
1343  const Vec3d& getInvScale() const {return mScaleValuesInverse; }
1344 
1346  void read(std::istream& is)
1347  {
1348  mTranslation.read(is);
1349  mScaleValues.read(is);
1350  mVoxelSize.read(is);
1351  mScaleValuesInverse.read(is);
1352  mInvScaleSqr.read(is);
1353  mInvTwiceScale.read(is);
1354  }
1356  void write(std::ostream& os) const
1357  {
1358  mTranslation.write(os);
1359  mScaleValues.write(os);
1360  mVoxelSize.write(os);
1361  mScaleValuesInverse.write(os);
1362  mInvScaleSqr.write(os);
1363  mInvTwiceScale.write(os);
1364  }
1366  std::string str() const
1367  {
1368  std::ostringstream buffer;
1369  buffer << " - translation: " << mTranslation << std::endl;
1370  buffer << " - scale: " << mScaleValues << std::endl;
1371  buffer << " - voxel dimensions: " << mVoxelSize << std::endl;
1372  return buffer.str();
1373  }
1374 
1375  virtual bool isEqual(const MapBase& other) const { return isEqualBase(*this, other); }
1376 
1377  bool operator==(const ScaleTranslateMap& other) const
1378  {
1379  // ::eq() uses a tolerance
1380  if (!mScaleValues.eq(other.mScaleValues)) { return false; }
1381  if (!mTranslation.eq(other.mTranslation)) { return false; }
1382  return true;
1383  }
1384 
1385  bool operator!=(const ScaleTranslateMap& other) const { return !(*this == other); }
1386 
1389  {
1390  AffineMap::Ptr affineMap(new AffineMap(math::scale<Mat4d>(mScaleValues)));
1391  affineMap->accumPostTranslation(mTranslation);
1392  return affineMap;
1393  }
1394 
1396  MapBase::Ptr preRotate(double radians, Axis axis) const
1399  {
1400  AffineMap::Ptr affineMap = getAffineMap();
1401  affineMap->accumPreRotation(axis, radians);
1402  return simplify(affineMap);
1403  }
1405  {
1406  const Vec3d& s = mScaleValues;
1407  const Vec3d scaled_trans( t.x() * s.x(),
1408  t.y() * s.y(),
1409  t.z() * s.z() );
1410  return MapBase::Ptr( new ScaleTranslateMap(mScaleValues, mTranslation + scaled_trans));
1411  }
1412 
1413  MapBase::Ptr preScale(const Vec3d& v) const;
1414 
1415  MapBase::Ptr preShear(double shear, Axis axis0, Axis axis1) const
1416  {
1417  AffineMap::Ptr affineMap = getAffineMap();
1418  affineMap->accumPreShear(axis0, axis1, shear);
1419  return simplify(affineMap);
1420  }
1422 
1424  MapBase::Ptr postRotate(double radians, Axis axis) const
1427  {
1428  AffineMap::Ptr affineMap = getAffineMap();
1429  affineMap->accumPostRotation(axis, radians);
1430  return simplify(affineMap);
1431  }
1433  {
1434  return MapBase::Ptr( new ScaleTranslateMap(mScaleValues, mTranslation + t));
1435  }
1436 
1437  MapBase::Ptr postScale(const Vec3d& v) const;
1438 
1439  MapBase::Ptr postShear(double shear, Axis axis0, Axis axis1) const
1440  {
1441  AffineMap::Ptr affineMap = getAffineMap();
1442  affineMap->accumPostShear(axis0, axis1, shear);
1443  return simplify(affineMap);
1444  }
1446 
1447 private:
1448  Vec3d mTranslation, mScaleValues, mVoxelSize, mScaleValuesInverse,
1449  mInvScaleSqr, mInvTwiceScale;
1450 }; // class ScaleTanslateMap
1451 
1452 
1453 inline MapBase::Ptr
1454 ScaleMap::postTranslate(const Vec3d& t) const
1455 {
1456  return MapBase::Ptr(new ScaleTranslateMap(mScaleValues, t));
1457 }
1458 
1459 
1460 inline MapBase::Ptr
1461 ScaleMap::preTranslate(const Vec3d& t) const
1462 {
1463 
1464  const Vec3d& s = mScaleValues;
1465  const Vec3d scaled_trans( t.x() * s.x(),
1466  t.y() * s.y(),
1467  t.z() * s.z() );
1468  return MapBase::Ptr(new ScaleTranslateMap(mScaleValues, scaled_trans));
1469 }
1470 
1471 
1475 {
1476 public:
1477  typedef boost::shared_ptr<UniformScaleTranslateMap> Ptr;
1478  typedef boost::shared_ptr<const UniformScaleTranslateMap> ConstPtr;
1479 
1481  UniformScaleTranslateMap(double scale, const Vec3d& translate):
1482  ScaleTranslateMap(Vec3d(scale,scale,scale), translate) {}
1484  ScaleTranslateMap(scale.getScale(), translate.getTranslation()) {}
1485 
1488 
1492  MapBase::Ptr copy() const { return MapBase::Ptr(new UniformScaleTranslateMap(*this)); }
1493 
1495  {
1496  const Vec3d& scaleInv = getInvScale();
1497  const Vec3d& trans = getTranslation();
1498  return MapBase::Ptr(new UniformScaleTranslateMap(scaleInv[0], -scaleInv[0] * trans));
1499  }
1500 
1501  static bool isRegistered()
1502  {
1503  return MapRegistry::isRegistered(UniformScaleTranslateMap::mapType());
1504  }
1505 
1506  static void registerMap()
1507  {
1508  MapRegistry::registerMap(
1509  UniformScaleTranslateMap::mapType(),
1510  UniformScaleTranslateMap::create);
1511  }
1512 
1513  Name type() const { return mapType(); }
1514  static Name mapType() { return Name("UniformScaleTranslateMap"); }
1515 
1516  virtual bool isEqual(const MapBase& other) const { return isEqualBase(*this, other); }
1517 
1518  bool operator==(const UniformScaleTranslateMap& other) const
1519  {
1520  return ScaleTranslateMap::operator==(other);
1521  }
1522  bool operator!=(const UniformScaleTranslateMap& other) const { return !(*this == other); }
1523 
1527  {
1528  const double scale = this->getScale().x();
1529  const Vec3d new_trans = this->getTranslation() + scale * t;
1530  return MapBase::Ptr( new UniformScaleTranslateMap(scale, new_trans));
1531  }
1532 
1536  {
1537  const double scale = this->getScale().x();
1538  return MapBase::Ptr( new UniformScaleTranslateMap(scale, this->getTranslation() + t));
1539  }
1540 }; // class UniformScaleTanslateMap
1541 
1542 
1543 inline MapBase::Ptr
1544 UniformScaleMap::postTranslate(const Vec3d& t) const
1545 {
1546  const double scale = this->getScale().x();
1547  return MapBase::Ptr(new UniformScaleTranslateMap(scale, t));
1548 }
1549 
1550 
1551 inline MapBase::Ptr
1552 UniformScaleMap::preTranslate(const Vec3d& t) const
1553 {
1554  const double scale = this->getScale().x();
1555  return MapBase::Ptr(new UniformScaleTranslateMap(scale, scale*t));
1556 }
1557 
1558 
1559 inline MapBase::Ptr
1560 TranslationMap::preScale(const Vec3d& v) const
1561 {
1562  if (isApproxEqual(v[0],v[1]) && isApproxEqual(v[0],v[2])) {
1563  return MapBase::Ptr(new UniformScaleTranslateMap(v[0], mTranslation));
1564  } else {
1565  return MapBase::Ptr(new ScaleTranslateMap(v, mTranslation));
1566  }
1567 }
1568 
1569 
1570 inline MapBase::Ptr
1571 TranslationMap::postScale(const Vec3d& v) const
1572 {
1573  if (isApproxEqual(v[0],v[1]) && isApproxEqual(v[0],v[2])) {
1574  return MapBase::Ptr(new UniformScaleTranslateMap(v[0], v[0]*mTranslation));
1575  } else {
1576  const Vec3d trans(mTranslation.x()*v.x(),
1577  mTranslation.y()*v.y(),
1578  mTranslation.z()*v.z());
1579  return MapBase::Ptr(new ScaleTranslateMap(v, trans));
1580  }
1581 }
1582 
1583 
1584 inline MapBase::Ptr
1585 ScaleTranslateMap::preScale(const Vec3d& v) const
1586 {
1587  const Vec3d new_scale( v * mScaleValues );
1588  if (isApproxEqual(new_scale[0],new_scale[1]) && isApproxEqual(new_scale[0],new_scale[2])) {
1589  return MapBase::Ptr( new UniformScaleTranslateMap(new_scale[0], mTranslation));
1590  } else {
1591  return MapBase::Ptr( new ScaleTranslateMap(new_scale, mTranslation));
1592  }
1593 }
1594 
1595 
1596 inline MapBase::Ptr
1597 ScaleTranslateMap::postScale(const Vec3d& v) const
1598 {
1599  const Vec3d new_scale( v * mScaleValues );
1600  const Vec3d new_trans( mTranslation.x()*v.x(),
1601  mTranslation.y()*v.y(),
1602  mTranslation.z()*v.z() );
1603 
1604  if (isApproxEqual(new_scale[0],new_scale[1]) && isApproxEqual(new_scale[0],new_scale[2])) {
1605  return MapBase::Ptr( new UniformScaleTranslateMap(new_scale[0], new_trans));
1606  } else {
1607  return MapBase::Ptr( new ScaleTranslateMap(new_scale, new_trans));
1608  }
1609 }
1610 
1611 
1613 
1614 
1618 {
1619 public:
1620  typedef boost::shared_ptr<UnitaryMap> Ptr;
1621  typedef boost::shared_ptr<const UnitaryMap> ConstPtr;
1622 
1624  UnitaryMap(): mAffineMap(Mat4d::identity())
1625  {
1626  }
1627 
1628  UnitaryMap(const Vec3d& axis, double radians)
1629  {
1630  Mat3d matrix;
1631  matrix.setToRotation(axis, radians);
1632  mAffineMap = AffineMap(matrix);
1633  }
1634 
1635  UnitaryMap(Axis axis, double radians)
1636  {
1637  Mat4d matrix;
1638  matrix.setToRotation(axis, radians);
1639  mAffineMap = AffineMap(matrix);
1640  }
1641 
1642  UnitaryMap(const Mat3d& m)
1643  {
1644  // test that the mat3 is a rotation || reflection
1645  if (!isUnitary(m)) {
1646  OPENVDB_THROW(ArithmeticError, "Matrix initializing unitary map was not unitary");
1647  }
1648 
1649  Mat4d matrix(Mat4d::identity());
1650  matrix.setMat3(m);
1651  mAffineMap = AffineMap(matrix);
1652  }
1653 
1654  UnitaryMap(const Mat4d& m)
1655  {
1656  if (!isInvertible(m)) {
1658  "4x4 Matrix initializing unitary map was not unitary: not invertible");
1659  }
1660 
1661  if (!isAffine(m)) {
1663  "4x4 Matrix initializing unitary map was not unitary: not affine");
1664  }
1665 
1666  if (hasTranslation(m)) {
1668  "4x4 Matrix initializing unitary map was not unitary: had translation");
1669  }
1670 
1671  if (!isUnitary(m.getMat3())) {
1673  "4x4 Matrix initializing unitary map was not unitary");
1674  }
1675 
1676  mAffineMap = AffineMap(m);
1677  }
1678 
1679  UnitaryMap(const UnitaryMap& other):
1680  MapBase(other),
1681  mAffineMap(other.mAffineMap)
1682  {
1683  }
1684 
1685  UnitaryMap(const UnitaryMap& first, const UnitaryMap& second):
1686  mAffineMap(*(first.getAffineMap()), *(second.getAffineMap()))
1687  {
1688  }
1689 
1692  static MapBase::Ptr create() { return MapBase::Ptr(new UnitaryMap()); }
1694  MapBase::Ptr copy() const { return MapBase::Ptr(new UnitaryMap(*this)); }
1695 
1697  {
1698  return MapBase::Ptr(new UnitaryMap(mAffineMap.getMat4().inverse()));
1699  }
1700 
1701  static bool isRegistered() { return MapRegistry::isRegistered(UnitaryMap::mapType()); }
1702 
1703  static void registerMap()
1704  {
1705  MapRegistry::registerMap(
1706  UnitaryMap::mapType(),
1707  UnitaryMap::create);
1708  }
1709 
1711  Name type() const { return mapType(); }
1713  static Name mapType() { return Name("UnitaryMap"); }
1714 
1716  bool isLinear() const { return true; }
1717 
1719  bool hasUniformScale() const { return true; }
1720 
1721  virtual bool isEqual(const MapBase& other) const { return isEqualBase(*this, other); }
1722 
1723  bool operator==(const UnitaryMap& other) const
1724  {
1725  // compare underlying linear map.
1726  if (mAffineMap!=other.mAffineMap) return false;
1727  return true;
1728  }
1729 
1730  bool operator!=(const UnitaryMap& other) const { return !(*this == other); }
1732  Vec3d applyMap(const Vec3d& in) const { return mAffineMap.applyMap(in); }
1734  Vec3d applyInverseMap(const Vec3d& in) const { return mAffineMap.applyInverseMap(in); }
1735 
1736  Vec3d applyJacobian(const Vec3d& in, const Vec3d&) const { return applyJacobian(in); }
1738  Vec3d applyJacobian(const Vec3d& in) const { return mAffineMap.applyJacobian(in); }
1739 
1741  Vec3d applyInverseJacobian(const Vec3d& in, const Vec3d&) const { return applyInverseJacobian(in); }
1743  Vec3d applyInverseJacobian(const Vec3d& in) const { return mAffineMap.applyInverseJacobian(in); }
1744 
1745 
1748  Vec3d applyJT(const Vec3d& in, const Vec3d&) const { return applyJT(in); }
1750  Vec3d applyJT(const Vec3d& in) const {
1751  // The transpose of the unitary map is its inverse
1752  return applyInverseMap(in);
1753  }
1754 
1755 
1758  Vec3d applyIJT(const Vec3d& in, const Vec3d& ) const { return applyIJT(in);}
1760  Vec3d applyIJT(const Vec3d& in) const { return mAffineMap.applyIJT(in); }
1762  Mat3d applyIJC(const Mat3d& in) const { return mAffineMap.applyIJC(in); }
1763  Mat3d applyIJC(const Mat3d& in, const Vec3d&, const Vec3d& ) const { return applyIJC(in); }
1765  double determinant(const Vec3d& ) const { return determinant(); }
1767  double determinant() const { return mAffineMap.determinant(); }
1768 
1769 
1774  Vec3d voxelSize() const { return mAffineMap.voxelSize();}
1775  Vec3d voxelSize(const Vec3d&) const { return voxelSize();}
1776 
1778  void read(std::istream& is)
1779  {
1780  mAffineMap.read(is);
1781  }
1782 
1784  void write(std::ostream& os) const
1785  {
1786  mAffineMap.write(os);
1787  }
1789  std::string str() const
1790  {
1791  std::ostringstream buffer;
1792  buffer << mAffineMap.str();
1793  return buffer.str();
1794  }
1796  AffineMap::Ptr getAffineMap() const { return AffineMap::Ptr(new AffineMap(mAffineMap)); }
1797 
1799  MapBase::Ptr preRotate(double radians, Axis axis) const
1802  {
1803  UnitaryMap first(axis, radians);
1804  UnitaryMap::Ptr unitaryMap(new UnitaryMap(first, *this));
1805  return boost::static_pointer_cast<MapBase, UnitaryMap>(unitaryMap);
1806  }
1808  {
1809  AffineMap::Ptr affineMap = getAffineMap();
1810  affineMap->accumPreTranslation(t);
1811  return simplify(affineMap);
1812  }
1813  MapBase::Ptr preScale(const Vec3d& v) const
1814  {
1815  AffineMap::Ptr affineMap = getAffineMap();
1816  affineMap->accumPreScale(v);
1817  return simplify(affineMap);
1818  }
1819  MapBase::Ptr preShear(double shear, Axis axis0, Axis axis1) const
1820  {
1821  AffineMap::Ptr affineMap = getAffineMap();
1822  affineMap->accumPreShear(axis0, axis1, shear);
1823  return simplify(affineMap);
1824  }
1826 
1827 
1829  MapBase::Ptr postRotate(double radians, Axis axis) const
1832  {
1833  UnitaryMap second(axis, radians);
1834  UnitaryMap::Ptr unitaryMap(new UnitaryMap(*this, second));
1835  return boost::static_pointer_cast<MapBase, UnitaryMap>(unitaryMap);
1836  }
1838  {
1839  AffineMap::Ptr affineMap = getAffineMap();
1840  affineMap->accumPostTranslation(t);
1841  return simplify(affineMap);
1842  }
1843  MapBase::Ptr postScale(const Vec3d& v) const
1844  {
1845  AffineMap::Ptr affineMap = getAffineMap();
1846  affineMap->accumPostScale(v);
1847  return simplify(affineMap);
1848  }
1849  MapBase::Ptr postShear(double shear, Axis axis0, Axis axis1) const
1850  {
1851  AffineMap::Ptr affineMap = getAffineMap();
1852  affineMap->accumPostShear(axis0, axis1, shear);
1853  return simplify(affineMap);
1854  }
1856 
1857 private:
1858  AffineMap mAffineMap;
1859 }; // class UnitaryMap
1860 
1861 
1863 
1864 
1872 {
1873 public:
1874  typedef boost::shared_ptr<NonlinearFrustumMap> Ptr;
1875  typedef boost::shared_ptr<const NonlinearFrustumMap> ConstPtr;
1876 
1878  MapBase(),
1879  mBBox(Vec3d(0), Vec3d(1)),
1880  mTaper(1),
1881  mDepth(1)
1882  {
1883  init();
1884  }
1885 
1889  NonlinearFrustumMap(const BBoxd& bb, double taper, double depth):
1890  MapBase(),mBBox(bb), mTaper(taper), mDepth(depth)
1891  {
1892  init();
1893  }
1894 
1900  NonlinearFrustumMap(const BBoxd& bb, double taper, double depth,
1901  const MapBase::Ptr& secondMap):
1902  mBBox(bb), mTaper(taper), mDepth(depth)
1903  {
1904  if (!secondMap->isLinear() ) {
1906  "The second map in the Frustum transfrom must be linear");
1907  }
1908  mSecondMap = *( secondMap->getAffineMap() );
1909  init();
1910  }
1911 
1913  MapBase(),
1914  mBBox(other.mBBox),
1915  mTaper(other.mTaper),
1916  mDepth(other.mDepth),
1917  mSecondMap(other.mSecondMap),
1918  mHasSimpleAffine(other.mHasSimpleAffine)
1919  {
1920  init();
1921  }
1922 
1938  NonlinearFrustumMap(const Vec3d& position,
1939  const Vec3d& direction,
1940  const Vec3d& up,
1941  double aspect /* width / height */,
1942  double z_near, double depth,
1943  Coord::ValueType x_count, Coord::ValueType z_count) {
1944 
1948  if (!(depth > 0)) {
1950  "The frustum depth must be non-zero and positive");
1951  }
1952  if (!(up.length() > 0)) {
1954  "The frustum height must be non-zero and positive");
1955  }
1956  if (!(aspect > 0)) {
1958  "The frustum aspect ratio must be non-zero and positive");
1959  }
1960  if (!(isApproxEqual(up.dot(direction), 0.))) {
1962  "The frustum up orientation must be perpendicular to into-frustum direction");
1963  }
1964 
1965  double near_plane_height = 2 * up.length();
1966  double near_plane_width = aspect * near_plane_height;
1967 
1968  Coord::ValueType y_count = static_cast<int>(Round(x_count / aspect));
1969 
1970  mBBox = BBoxd(Vec3d(0,0,0), Vec3d(x_count, y_count, z_count));
1971  mDepth = depth / near_plane_width; // depth non-dimensionalized on width
1972  double gamma = near_plane_width / z_near;
1973  mTaper = 1./(mDepth*gamma + 1.);
1974 
1975  Vec3d direction_unit = direction;
1976  direction_unit.normalize();
1977 
1978  Mat4d r1(Mat4d::identity());
1979  r1.setToRotation(/*from*/Vec3d(0,0,1), /*to */direction_unit);
1980  Mat4d r2(Mat4d::identity());
1981  Vec3d temp = r1.inverse().transform(up);
1982  r2.setToRotation(/*from*/Vec3d(0,1,0), /*to*/temp );
1983  Mat4d scale = math::scale<Mat4d>(
1984  Vec3d(near_plane_width, near_plane_width, near_plane_width));
1985 
1986  // move the near plane to origin, rotate to align with axis, and scale down
1987  // T_inv * R1_inv * R2_inv * scale_inv
1988  Mat4d mat = scale * r2 * r1;
1989  mat.setTranslation(position + z_near*direction_unit);
1990 
1991  mSecondMap = AffineMap(mat);
1992 
1993  init();
1994  }
1995 
2000  MapBase::Ptr copy() const { return MapBase::Ptr(new NonlinearFrustumMap(*this)); }
2001 
2006  {
2008  "inverseMap() is not implemented for NonlinearFrustumMap");
2009  }
2010  static bool isRegistered() { return MapRegistry::isRegistered(NonlinearFrustumMap::mapType()); }
2011 
2012  static void registerMap()
2013  {
2014  MapRegistry::registerMap(
2015  NonlinearFrustumMap::mapType(),
2016  NonlinearFrustumMap::create);
2017  }
2019  Name type() const { return mapType(); }
2021  static Name mapType() { return Name("NonlinearFrustumMap"); }
2022 
2024  bool isLinear() const { return false; }
2025 
2027  bool hasUniformScale() const { return false; }
2028 
2030  bool isIdentity() const
2031  {
2032  // The frustum can only be consistent with a linear map if the taper value is 1
2033  if (!isApproxEqual(mTaper, double(1)) ) return false;
2034 
2035  // There are various ways an identity can decomposed between the two parts of the
2036  // map. Best to just check that the principle vectors are stationary.
2037  const Vec3d e1(1,0,0);
2038  if (!applyMap(e1).eq(e1)) return false;
2039 
2040  const Vec3d e2(0,1,0);
2041  if (!applyMap(e2).eq(e2)) return false;
2042 
2043  const Vec3d e3(0,0,1);
2044  if (!applyMap(e3).eq(e3)) return false;
2045 
2046  return true;
2047  }
2048 
2049  virtual bool isEqual(const MapBase& other) const { return isEqualBase(*this, other); }
2050 
2051  bool operator==(const NonlinearFrustumMap& other) const
2052  {
2053  if (mBBox!=other.mBBox) return false;
2054  if (!isApproxEqual(mTaper, other.mTaper)) return false;
2055  if (!isApproxEqual(mDepth, other.mDepth)) return false;
2056 
2057  // Two linear transforms are equivalent iff they have the same translation
2058  // and have the same affects on orthongal spanning basis check translation
2059  Vec3d e(0,0,0);
2060  if (!mSecondMap.applyMap(e).eq(other.mSecondMap.applyMap(e))) return false;
2062  e(0) = 1;
2063  if (!mSecondMap.applyMap(e).eq(other.mSecondMap.applyMap(e))) return false;
2064  e(0) = 0;
2065  e(1) = 1;
2066  if (!mSecondMap.applyMap(e).eq(other.mSecondMap.applyMap(e))) return false;
2067  e(1) = 0;
2068  e(2) = 1;
2069  if (!mSecondMap.applyMap(e).eq(other.mSecondMap.applyMap(e))) return false;
2070  return true;
2071  }
2072 
2073  bool operator!=(const NonlinearFrustumMap& other) const { return !(*this == other); }
2074 
2076  Vec3d applyMap(const Vec3d& in) const
2077  {
2078  return mSecondMap.applyMap(applyFrustumMap(in));
2079  }
2080 
2082  Vec3d applyInverseMap(const Vec3d& in) const
2083  {
2084  return applyFrustumInverseMap(mSecondMap.applyInverseMap(in));
2085  }
2087  Vec3d applyJacobian(const Vec3d& in) const { return mSecondMap.applyJacobian(in); }
2089  Vec3d applyJacobian(const Vec3d& in, const Vec3d& isloc) const
2090  {
2091  // Move the center of the x-face of the bbox
2092  // to the origin in index space.
2093  Vec3d centered(isloc);
2094  centered = centered - mBBox.min();
2095  centered.x() -= mXo;
2096  centered.y() -= mYo;
2097 
2098  // scale the z-direction on depth / K count
2099  const double zprime = centered.z()*mDepthOnLz;
2100 
2101  const double scale = (mGamma * zprime + 1.) / mLx;
2102  const double scale2 = mGamma * mDepthOnLz / mLx;
2103 
2104  const Vec3d tmp(scale * in.x() + scale2 * centered.x()* in.z(),
2105  scale * in.y() + scale2 * centered.y()* in.z(),
2106  mDepthOnLz * in.z());
2107 
2108  return mSecondMap.applyJacobian(tmp);
2109  }
2110 
2111 
2113  Vec3d applyInverseJacobian(const Vec3d& in) const { return mSecondMap.applyInverseJacobian(in); }
2115  Vec3d applyInverseJacobian(const Vec3d& in, const Vec3d& isloc) const {
2116 
2117  // Move the center of the x-face of the bbox
2118  // to the origin in index space.
2119  Vec3d centered(isloc);
2120  centered = centered - mBBox.min();
2121  centered.x() -= mXo;
2122  centered.y() -= mYo;
2123 
2124  // scale the z-direction on depth / K count
2125  const double zprime = centered.z()*mDepthOnLz;
2126 
2127  const double scale = (mGamma * zprime + 1.) / mLx;
2128  const double scale2 = mGamma * mDepthOnLz / mLx;
2129 
2130 
2131  Vec3d out = mSecondMap.applyInverseJacobian(in);
2132 
2133  out.x() = (out.x() - scale2 * centered.x() * out.z() / mDepthOnLz) / scale;
2134  out.y() = (out.y() - scale2 * centered.y() * out.z() / mDepthOnLz) / scale;
2135  out.z() = out.z() / mDepthOnLz;
2136 
2137  return out;
2138  }
2139 
2140 
2141 
2145  Vec3d applyJT(const Vec3d& in, const Vec3d& isloc) const {
2146  const Vec3d tmp = mSecondMap.applyJT(in);
2147  // Move the center of the x-face of the bbox
2148  // to the origin in index space.
2149  Vec3d centered(isloc);
2150  centered = centered - mBBox.min();
2151  centered.x() -= mXo;
2152  centered.y() -= mYo;
2153 
2154  // scale the z-direction on depth / K count
2155  const double zprime = centered.z()*mDepthOnLz;
2156 
2157  const double scale = (mGamma * zprime + 1.) / mLx;
2158  const double scale2 = mGamma * mDepthOnLz / mLx;
2159 
2160  return Vec3d(scale * tmp.x(),
2161  scale * tmp.y(),
2162  scale2 * centered.x()* tmp.x() +
2163  scale2 * centered.y()* tmp.y() +
2164  mDepthOnLz * tmp.z());
2165  }
2167  Vec3d applyJT(const Vec3d& in) const {
2168  return mSecondMap.applyJT(in);
2169  }
2170 
2172  Vec3d applyIJT(const Vec3d& in) const { return mSecondMap.applyIJT(in); }
2173 
2174  // the Jacobian of the nonlinear part of the transform is a sparse matrix
2175  // Jacobian^(-T) =
2176  //
2177  // (Lx)( 1/s 0 0 )
2178  // ( 0 1/s 0 )
2179  // ( -(x-xo)g/(sLx) -(y-yo)g/(sLx) Lz/(Depth Lx) )
2182  Vec3d applyIJT(const Vec3d& d1_is, const Vec3d& ijk) const
2183  {
2184  const Vec3d loc = applyFrustumMap(ijk);
2185  const double s = mGamma * loc.z() + 1.;
2186 
2187  // verify that we aren't at the singularity
2188  if (isApproxEqual(s, 0.)) {
2189  OPENVDB_THROW(ArithmeticError, "Tried to evaluate the frustum transform"
2190  " at the singular focal point (e.g. camera)");
2191  }
2192 
2193  const double sinv = 1.0/s; // 1/(z*gamma + 1)
2194  const double pt0 = mLx * sinv; // Lx / (z*gamma +1)
2195  const double pt1 = mGamma * pt0; // gamma * Lx / ( z*gamma +1)
2196  const double pt2 = pt1 * sinv; // gamma * Lx / ( z*gamma +1)**2
2197 
2198  const Mat3d& jacinv = mSecondMap.getConstJacobianInv();
2199 
2200  // compute \frac{\partial E_i}{\partial x_j}
2201  Mat3d gradE(Mat3d::zero());
2202  for (int j = 0; j < 3; ++j ) {
2203  gradE(0,j) = pt0 * jacinv(0,j) - pt2 * loc.x()*jacinv(2,j);
2204  gradE(1,j) = pt0 * jacinv(1,j) - pt2 * loc.y()*jacinv(2,j);
2205  gradE(2,j) = (1./mDepthOnLz) * jacinv(2,j);
2206  }
2207 
2208  Vec3d result;
2209  for (int i = 0; i < 3; ++i) {
2210  result(0) = d1_is(0) * gradE(0,i) + d1_is(1) * gradE(1,i) + d1_is(2) * gradE(2,i);
2211  }
2212 
2213  return result;
2214 
2215  }
2216 
2218  Mat3d applyIJC(const Mat3d& in) const { return mSecondMap.applyIJC(in); }
2223  Mat3d applyIJC(const Mat3d& d2_is, const Vec3d& d1_is, const Vec3d& ijk) const
2224  {
2225  const Vec3d loc = applyFrustumMap(ijk);
2226 
2227  const double s = mGamma * loc.z() + 1.;
2228 
2229  // verify that we aren't at the singularity
2230  if (isApproxEqual(s, 0.)) {
2231  OPENVDB_THROW(ArithmeticError, "Tried to evaluate the frustum transform"
2232  " at the singular focal point (e.g. camera)");
2233  }
2234 
2235  // precompute
2236  const double sinv = 1.0/s; // 1/(z*gamma + 1)
2237  const double pt0 = mLx * sinv; // Lx / (z*gamma +1)
2238  const double pt1 = mGamma * pt0; // gamma * Lx / ( z*gamma +1)
2239  const double pt2 = pt1 * sinv; // gamma * Lx / ( z*gamma +1)**2
2240  const double pt3 = pt2 * sinv; // gamma * Lx / ( z*gamma +1)**3
2241 
2242  const Mat3d& jacinv = mSecondMap.getConstJacobianInv();
2243 
2244  // compute \frac{\partial^2 E_i}{\partial x_j \partial x_k}
2245 
2246  Mat3d matE0(Mat3d::zero());
2247  Mat3d matE1(Mat3d::zero()); // matE2 = 0
2248  for(int j = 0; j < 3; j++) {
2249  for (int k = 0; k < 3; k++) {
2250 
2251  const double pt4 = 2. * jacinv(2,j) * jacinv(2,k) * pt3;
2252 
2253  matE0(j,k) = -(jacinv(0,j) * jacinv(2,k) + jacinv(2,j) * jacinv(0,k)) * pt2 +
2254  pt4 * loc.x();
2255 
2256  matE1(j,k) = -(jacinv(1,j) * jacinv(2,k) + jacinv(2,j) * jacinv(1,k)) * pt2 +
2257  pt4 * loc.y();
2258  }
2259  }
2260 
2261  // compute \frac{\partial E_i}{\partial x_j}
2262  Mat3d gradE(Mat3d::zero());
2263  for (int j = 0; j < 3; ++j ) {
2264  gradE(0,j) = pt0 * jacinv(0,j) - pt2 * loc.x()*jacinv(2,j);
2265  gradE(1,j) = pt0 * jacinv(1,j) - pt2 * loc.y()*jacinv(2,j);
2266  gradE(2,j) = (1./mDepthOnLz) * jacinv(2,j);
2267  }
2268 
2269  Mat3d result(Mat3d::zero());
2270  // compute \fac{\partial E_j}{\partial x_m} \fac{\partial E_i}{\partial x_n}
2271  // \frac{\partial^2 input}{\partial E_i \partial E_j}
2272  for (int m = 0; m < 3; ++m ) {
2273  for ( int n = 0; n < 3; ++n) {
2274  for (int i = 0; i < 3; ++i ) {
2275  for (int j = 0; j < 3; ++j) {
2276  result(m, n) += gradE(j, m) * gradE(i, n) * d2_is(i, j);
2277  }
2278  }
2279  }
2280  }
2281 
2282  for (int m = 0; m < 3; ++m ) {
2283  for ( int n = 0; n < 3; ++n) {
2284  result(m, n) +=
2285  matE0(m, n) * d1_is(0) + matE1(m, n) * d1_is(1);// + matE2(m, n) * d1_is(2);
2286  }
2287  }
2288 
2289  return result;
2290  }
2291 
2293  double determinant() const {return mSecondMap.determinant();} // no implementation
2294 
2297  double determinant(const Vec3d& loc) const
2298  {
2299  double s = mGamma * loc.z() + 1.0;
2300  double frustum_determinant = s * s * mDepthOnLzLxLx;
2301  return mSecondMap.determinant() * frustum_determinant;
2302  }
2303 
2306  {
2307  const Vec3d loc( 0.5*(mBBox.min().x() + mBBox.max().x()),
2308  0.5*(mBBox.min().y() + mBBox.max().y()),
2309  mBBox.min().z());
2310 
2311  return voxelSize(loc);
2312 
2313  }
2314 
2319  Vec3d voxelSize(const Vec3d& loc) const
2320  {
2321  Vec3d out, pos = applyMap(loc);
2322  out(0) = (applyMap(loc + Vec3d(1,0,0)) - pos).length();
2323  out(1) = (applyMap(loc + Vec3d(0,1,0)) - pos).length();
2324  out(2) = (applyMap(loc + Vec3d(0,0,1)) - pos).length();
2325  return out;
2326  }
2327 
2328  AffineMap::Ptr getAffineMap() const { return mSecondMap.getAffineMap(); }
2329 
2331  void setTaper(double t) { mTaper = t; init();}
2333  double getTaper() const { return mTaper; }
2335  void setDepth(double d) { mDepth = d; init();}
2337  double getDepth() const { return mDepth; }
2338  // gamma a non-dimensional number: nearplane x-width / camera to near plane distance
2339  double getGamma() const { return mGamma; }
2340 
2342  const BBoxd& getBBox() const { return mBBox; }
2343 
2345  const AffineMap& secondMap() const { return mSecondMap; }
2348  bool isValid() const { return !mBBox.empty();}
2349 
2351  bool hasSimpleAffine() const { return mHasSimpleAffine; }
2352 
2354  void read(std::istream& is)
2355  {
2356  // for backward compatibility with earlier version
2358  CoordBBox bb;
2359  bb.read(is);
2360  mBBox = BBoxd(bb.min().asVec3d(), bb.max().asVec3d());
2361  } else {
2362  mBBox.read(is);
2363  }
2364 
2365  is.read(reinterpret_cast<char*>(&mTaper), sizeof(double));
2366  is.read(reinterpret_cast<char*>(&mDepth), sizeof(double));
2367 
2368  // Read the second maps type.
2369  Name type = readString(is);
2370 
2371  // Check if the map has been registered.
2372  if(!MapRegistry::isRegistered(type)) {
2373  OPENVDB_THROW(KeyError, "Map " << type << " is not registered");
2374  }
2375 
2376  // Create the second map of the type and then read it in.
2377  MapBase::Ptr proxy = math::MapRegistry::createMap(type);
2378  proxy->read(is);
2379  mSecondMap = *(proxy->getAffineMap());
2380  init();
2381  }
2382 
2384  void write(std::ostream& os) const
2385  {
2386  mBBox.write(os);
2387  os.write(reinterpret_cast<const char*>(&mTaper), sizeof(double));
2388  os.write(reinterpret_cast<const char*>(&mDepth), sizeof(double));
2389 
2390  writeString(os, mSecondMap.type());
2391  mSecondMap.write(os);
2392  }
2393 
2395  std::string str() const
2396  {
2397  std::ostringstream buffer;
2398  buffer << " - taper: " << mTaper << std::endl;
2399  buffer << " - depth: " << mDepth << std::endl;
2400  buffer << " SecondMap: "<< mSecondMap.type() << std::endl;
2401  buffer << mSecondMap.str() << std::endl;
2402  return buffer.str();
2403  }
2404 
2406  MapBase::Ptr preRotate(double radians, Axis axis = X_AXIS) const
2409  {
2410  return MapBase::Ptr(
2411  new NonlinearFrustumMap(mBBox, mTaper, mDepth, mSecondMap.preRotate(radians, axis)));
2412  }
2414  {
2415  return MapBase::Ptr(
2416  new NonlinearFrustumMap(mBBox, mTaper, mDepth, mSecondMap.preTranslate(t)));
2417  }
2418  MapBase::Ptr preScale(const Vec3d& s) const
2419  {
2420  return MapBase::Ptr(
2421  new NonlinearFrustumMap(mBBox, mTaper, mDepth, mSecondMap.preScale(s)));
2422  }
2423  MapBase::Ptr preShear(double shear, Axis axis0, Axis axis1) const
2424  {
2425  return MapBase::Ptr(new NonlinearFrustumMap(
2426  mBBox, mTaper, mDepth, mSecondMap.preShear(shear, axis0, axis1)));
2427  }
2429 
2431  MapBase::Ptr postRotate(double radians, Axis axis = X_AXIS) const
2434  {
2435  return MapBase::Ptr(
2436  new NonlinearFrustumMap(mBBox, mTaper, mDepth, mSecondMap.postRotate(radians, axis)));
2437  }
2439  {
2440  return MapBase::Ptr(
2441  new NonlinearFrustumMap(mBBox, mTaper, mDepth, mSecondMap.postTranslate(t)));
2442  }
2443  MapBase::Ptr postScale(const Vec3d& s) const
2444  {
2445  return MapBase::Ptr(
2446  new NonlinearFrustumMap(mBBox, mTaper, mDepth, mSecondMap.postScale(s)));
2447  }
2448  MapBase::Ptr postShear(double shear, Axis axis0, Axis axis1) const
2449  {
2450  return MapBase::Ptr(new NonlinearFrustumMap(
2451  mBBox, mTaper, mDepth, mSecondMap.postShear(shear, axis0, axis1)));
2452  }
2454 
2455 private:
2456  void init()
2457  {
2458  // set up as a frustum
2459  mLx = mBBox.extents().x();
2460  mLy = mBBox.extents().y();
2461  mLz = mBBox.extents().z();
2462 
2463  if (isApproxEqual(mLx,0.) || isApproxEqual(mLy,0.) || isApproxEqual(mLz,0.) ) {
2464  OPENVDB_THROW(ArithmeticError, "The index space bounding box"
2465  " must have at least two index points in each direction.");
2466  }
2467 
2468  mXo = 0.5* mLx;
2469  mYo = 0.5* mLy;
2470 
2471  // mDepth is non-dimensionalized on near
2472  mGamma = (1./mTaper - 1) / mDepth;
2473 
2474  mDepthOnLz = mDepth/mLz;
2475  mDepthOnLzLxLx = mDepthOnLz/(mLx * mLx);
2476 
2478  mHasSimpleAffine = true;
2479  Vec3d tmp = mSecondMap.voxelSize();
2480 
2482  if (!isApproxEqual(tmp(0), tmp(1))) { mHasSimpleAffine = false; return; }
2483  if (!isApproxEqual(tmp(0), tmp(2))) { mHasSimpleAffine = false; return; }
2484 
2485  Vec3d trans = mSecondMap.applyMap(Vec3d(0,0,0));
2487  Vec3d tmp1 = mSecondMap.applyMap(Vec3d(1,0,0)) - trans;
2488  Vec3d tmp2 = mSecondMap.applyMap(Vec3d(0,1,0)) - trans;
2489  Vec3d tmp3 = mSecondMap.applyMap(Vec3d(0,0,1)) - trans;
2490 
2492  if (!isApproxEqual(tmp1.dot(tmp2), 0., 1.e-7)) { mHasSimpleAffine = false; return; }
2493  if (!isApproxEqual(tmp2.dot(tmp3), 0., 1.e-7)) { mHasSimpleAffine = false; return; }
2494  if (!isApproxEqual(tmp3.dot(tmp1), 0., 1.e-7)) { mHasSimpleAffine = false; return; }
2495  }
2496 
2497  Vec3d applyFrustumMap(const Vec3d& in) const
2498  {
2499 
2500  // Move the center of the x-face of the bbox
2501  // to the origin in index space.
2502  Vec3d out(in);
2503  out = out - mBBox.min();
2504  out.x() -= mXo;
2505  out.y() -= mYo;
2506 
2507  // scale the z-direction on depth / K count
2508  out.z() *= mDepthOnLz;
2509 
2510  double scale = (mGamma * out.z() + 1.)/ mLx;
2511 
2512  // scale the x-y on the length I count and apply tapper
2513  out.x() *= scale ;
2514  out.y() *= scale ;
2515 
2516  return out;
2517  }
2518 
2519  Vec3d applyFrustumInverseMap(const Vec3d& in) const
2520  {
2521  // invert taper and resize: scale = 1/( (z+1)/2 (mt-1) + 1)
2522  Vec3d out(in);
2523  double invScale = mLx / (mGamma * out.z() + 1.);
2524  out.x() *= invScale;
2525  out.y() *= invScale;
2526 
2527  out.x() += mXo;
2528  out.y() += mYo;
2529 
2530  out.z() /= mDepthOnLz;
2531 
2532  // move back
2533  out = out + mBBox.min();
2534  return out;
2535  }
2536 
2537  // bounding box in index space used in Frustum transforms.
2538  BBoxd mBBox;
2539 
2540  // taper value used in constructing Frustums.
2541  double mTaper;
2542  double mDepth;
2543 
2544  // defines the second map
2545  AffineMap mSecondMap;
2546 
2547  // these are derived from the above.
2548  double mLx, mLy, mLz;
2549  double mXo, mYo, mGamma, mDepthOnLz, mDepthOnLzLxLx;
2550 
2551  // true: if the mSecondMap is linear and has no shear, and has no non-uniform scale
2552  bool mHasSimpleAffine;
2553 }; // class NonlinearFrustumMap
2554 
2555 
2557 
2558 
2562 template<typename FirstMapType, typename SecondMapType>
2563 class CompoundMap
2564 {
2565 public:
2567 
2568  typedef boost::shared_ptr<MyType> Ptr;
2569  typedef boost::shared_ptr<const MyType> ConstPtr;
2570 
2571 
2572  CompoundMap() { updateAffineMatrix(); }
2573 
2574  CompoundMap(const FirstMapType& f, const SecondMapType& s): mFirstMap(f), mSecondMap(s)
2575  {
2576  updateAffineMatrix();
2577  }
2578 
2579  CompoundMap(const MyType& other):
2580  mFirstMap(other.mFirstMap),
2581  mSecondMap(other.mSecondMap),
2582  mAffineMap(other.mAffineMap)
2583  {}
2584 
2585  Name type() const { return mapType(); }
2586  static Name mapType()
2587  {
2588  return (FirstMapType::mapType() + Name(":") + SecondMapType::mapType());
2589  }
2590 
2591  bool operator==(const MyType& other) const
2592  {
2593  if (mFirstMap != other.mFirstMap) return false;
2594  if (mSecondMap != other.mSecondMap) return false;
2595  if (mAffineMap != other.mAffineMap) return false;
2596  return true;
2597  }
2598 
2599  bool operator!=(const MyType& other) const { return !(*this == other); }
2600 
2601  MyType& operator=(const MyType& other)
2602  {
2603  mFirstMap = other.mFirstMap;
2604  mSecondMap = other.mSecondMap;
2605  mAffineMap = other.mAffineMap;
2606  return *this;
2607  }
2608 
2609  bool isIdentity() const
2610  {
2612  return mAffineMap.isIdentity();
2613  } else {
2614  return mFirstMap.isIdentity()&&mSecondMap.isIdentity();
2615  }
2616  }
2617 
2618  bool isDiagonal() const {
2620  return mAffineMap.isDiagonal();
2621  } else {
2622  return mFirstMap.isDiagonal()&&mSecondMap.isDiagonal();
2623  }
2624  }
2625 
2627  {
2629  AffineMap::Ptr affine(new AffineMap(mAffineMap));
2630  return affine;
2631  } else {
2633  "Constant affine matrix representation not possible for this nonlinear map");
2634  }
2635  }
2636 
2637  // direct decompotion
2638  const FirstMapType& firstMap() const { return mFirstMap; }
2639  const SecondMapType& secondMap() const {return mSecondMap; }
2640 
2641  void setFirstMap(const FirstMapType& first) { mFirstMap = first; updateAffineMatrix(); }
2642  void setSecondMap(const SecondMapType& second) { mSecondMap = second; updateAffineMatrix(); }
2643 
2644  void read(std::istream& is)
2645  {
2646  mAffineMap.read(is);
2647  mFirstMap.read(is);
2648  mSecondMap.read(is);
2649  }
2650  void write(std::ostream& os) const
2651  {
2652  mAffineMap.write(os);
2653  mFirstMap.write(os);
2654  mSecondMap.write(os);
2655  }
2656 
2657 private:
2658  void updateAffineMatrix()
2659  {
2661  // both maps need to be linear, these methods are only defined for linear maps
2662  AffineMap::Ptr first = mFirstMap.getAffineMap();
2663  AffineMap::Ptr second= mSecondMap.getAffineMap();
2664  mAffineMap = AffineMap(*first, *second);
2665  }
2666  }
2667 
2668  FirstMapType mFirstMap;
2669  SecondMapType mSecondMap;
2670  // used for acceleration
2671  AffineMap mAffineMap;
2672 }; // class CompoundMap
2673 
2674 } // namespace math
2675 } // namespace OPENVDB_VERSION_NAME
2676 } // namespace openvdb
2677 
2678 #endif // OPENVDB_MATH_MAPS_HAS_BEEN_INCLUDED
2679 
2680 // Copyright (c) 2012-2013 DreamWorks Animation LLC
2681 // All rights reserved. This software is distributed under the
2682 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
AffineMap()
Definition: Maps.h:329
static MapBase::Ptr create()
Return a MapBase::Ptr to a new UnitaryMap.
Definition: Maps.h:1692
virtual bool isEqual(const MapBase &other) const
Return true if this map is equal to the given map.
Definition: Maps.h:957
virtual bool isEqual(const MapBase &other) const
Return true if this map is equal to the given map.
Definition: Maps.h:1721
Vec3d applyJT(const Vec3d &in) const
Return the Jacobian Transpose of the map applied to in.
Definition: Maps.h:1750
Vec3d applyJacobian(const Vec3d &in, const Vec3d &isloc) const
Return the Jacobian defined at isloc applied to in.
Definition: Maps.h:2089
Name type() const
Return the name of this map&#39;s concrete type (e.g., &quot;AffineMap&quot;).
Definition: Maps.h:954
boost::shared_ptr< const MapBase > ConstPtr
Definition: Maps.h:162
bool isIdentity() const
Return true if the map is equivalent to an identity.
Definition: Maps.h:2030
static MapBase::Ptr create()
Return a MapBase::Ptr to a new UniformScaleTranslateMap.
Definition: Maps.h:1490
const Vec3d & getTranslation() const
Return the translation vector.
Definition: Maps.h:1076
Vec3d applyMap(const Vec3d &in) const
Return the image of in under the map.
Definition: Maps.h:1035
virtual ~MapBase()
Definition: Maps.h:165
boost::shared_ptr< UnitaryMap > Ptr
Definition: Maps.h:1620
bool isValid() const
Definition: Maps.h:2348
Name type() const
Return UnitaryMap.
Definition: Maps.h:1711
Mat3d applyIJC(const Mat3d &mat, const Vec3d &, const Vec3d &) const
Definition: Maps.h:1063
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:162
Vec3d voxelSize() const
Return the absolute values of the scale values.
Definition: Maps.h:1328
void setTaper(double t)
set the taper value, the ratio of nearplane width / far plane width
Definition: Maps.h:2331
MapBase::Ptr preShear(double shear, Axis axis0, Axis axis1) const
Return a MapBase::Ptr to a new map that is the result of prepending the appropraite operation...
Definition: Maps.h:1819
~AffineMap()
Definition: Maps.h:377
Vec3d applyJacobian(const Vec3d &in) const
Return the Jacobian of the map applied to in.
Definition: Maps.h:771
Vec3d voxelSize(const Vec3d &) const
Definition: Maps.h:1331
Vec3d applyInverseJacobian(const Vec3d &in, const Vec3d &) const
Return the Inverse Jacobian of the map applied to in. (i.e. inverse map with out translation) ...
Definition: Maps.h:1741
static bool isRegistered()
Definition: Maps.h:1501
static MapBase::Ptr create()
Return a MapBase::Ptr to a new TranslationMap.
Definition: Maps.h:1010
UnitaryMap(const UnitaryMap &first, const UnitaryMap &second)
Definition: Maps.h:1685
Vec3d applyInverseJacobian(const Vec3d &in) const
Return the Inverse Jacobian of the map applied to in. (i.e. inverse map with out translation) ...
Definition: Maps.h:451
TranslationMap()
Definition: Maps.h:1003
Mat3d applyIJC(const Mat3d &d2_is, const Vec3d &d1_is, const Vec3d &ijk) const
Definition: Maps.h:2223
const SecondMapType & secondMap() const
Definition: Maps.h:2639
Vec3d applyIJT(const Vec3d &in, const Vec3d &) const
Return the transpose of the inverse Jacobian of the map applied to in.
Definition: Maps.h:465
static MapBase::Ptr create()
Return a MapBase::Ptr to a new NonlinearFrustumMap.
Definition: Maps.h:1998
Vec3d applyInverseJacobian(const Vec3d &in, const Vec3d &) const
Return the Inverse Jacobian of the map applied to in. (i.e. inverse map with out translation) ...
Definition: Maps.h:1044
boost::shared_ptr< const MyType > ConstPtr
Definition: Maps.h:2569
OPENVDB_API boost::shared_ptr< PolarDecomposedMap > createPolarDecomposedMap(const Mat3d &m)
Decomposes a general linear into translation following polar decomposition.
void write(std::ostream &os) const
write serialization
Definition: Maps.h:1080
bool hasUniformScale() const
Return true if the scale values have the same magnitude (eg. -1, 1, -1 would be a rotation)...
Definition: Maps.h:1256
MapBase::Ptr postTranslate(const Vec3d &t) const
Return a MapBase::Ptr to a new map that is the result of postfixing the appropraite operation...
Definition: Maps.h:1837
double determinant() const
Return the determinant of the Jacobian.
Definition: Maps.h:1767
void read(std::istream &is)
Unserialize this bounding box from the given stream.
Definition: Coord.h:360
double getTaper() const
Return the taper value.
Definition: Maps.h:2333
void setCol(int j, const Vec3< T > &v)
Set jth column to vector v.
Definition: Mat3.h:175
bool hasUniformScale() const
Return false (by convention true)
Definition: Maps.h:1032
Name type() const
Return the name of this map&#39;s concrete type (e.g., &quot;AffineMap&quot;).
Definition: Maps.h:1248
Map traits.
Definition: Maps.h:79
static Name mapType()
Definition: Maps.h:955
MapBase::Ptr postTranslate(const Vec3d &t) const
Return a MapBase::Ptr to a new map that is the result of postfixing the appropiate operation to the l...
Definition: Maps.h:2438
Vec3d applyJT(const Vec3d &in) const
Return the Jacobian Transpose of the second map applied to in.
Definition: Maps.h:2167
CompoundMap()
Definition: Maps.h:2572
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
const Vec3d & getScale() const
Returns the scale values.
Definition: Maps.h:1334
void write(std::ostream &os) const
write serialization
Definition: Maps.h:838
const MapT & mMap
Definition: GridOperators.h:260
Vec3d voxelSize(const Vec3d &) const
Return .
Definition: Maps.h:1073
Vec3d applyJacobian(const Vec3d &in, const Vec3d &) const
Return the Jacobian of the map applied to in.
Definition: Maps.h:444
Vec3d applyIJT(const Vec3d &in) const
Return the transpose of the inverse Jacobian of the linear second map applied to in.
Definition: Maps.h:2172
Name type() const
Return the name of this map&#39;s concrete type (e.g., &quot;AffineMap&quot;).
Definition: Maps.h:1513
boost::shared_ptr< const UniformScaleTranslateMap > ConstPtr
Definition: Maps.h:1478
MapBase::Ptr copy() const
Return a MapBase::Ptr to a deep copy of this map.
Definition: Maps.h:723
virtual bool isEqual(const MapBase &other) const
Return true if this map is equal to the given map.
Definition: Maps.h:1516
virtual bool isEqual(const MapBase &other) const
Return true if this map is equal to the given map.
Definition: Maps.h:1375
A specialized linear transform that performs a unitary maping i.e. rotation and or reflection...
Definition: Maps.h:1617
~NonlinearFrustumMap()
Definition: Maps.h:1996
A specialized Affine transform that scales along the principal axis the scaling need not be uniform i...
Definition: Maps.h:684
Vec3d asVec3d() const
Definition: Coord.h:136
MapBase::Ptr inverseMap() const
Return a new map representing the inverse of this map.
Definition: Maps.h:1233
static Name mapType()
Return UnitaryMap.
Definition: Maps.h:1713
MapBase::Ptr preShear(double shear, Axis axis0, Axis axis1) const
Return a MapBase::Ptr to a new map that is the result of prepending the appropraite operation...
Definition: Maps.h:1415
Vec3d applyInverseMap(const Vec3d &in) const
Return the pre-image of in under the map.
Definition: Maps.h:1734
boost::shared_ptr< UniformScaleTranslateMap > Ptr
Definition: Maps.h:1477
Mat3d applyIJC(const Mat3d &in) const
Return the Jacobian Curvature: zero for a linear map.
Definition: Maps.h:792
MapBase::Ptr preShear(double shear, Axis axis0, Axis axis1) const
Return a MapBase::Ptr to a new map that is the result of prepending the appropriate operation...
Definition: Maps.h:1127
T length() const
Length of the vector.
Definition: Vec3.h:208
T & z()
Definition: Vec3.h:96
const Vec3d & getInvScale() const
Return 1/(scale)
Definition: Maps.h:1343
MapBase::Ptr postScale(const Vec3d &v) const
Return a MapBase::Ptr to a new map that is the result of postfixing the appropraite operation...
Definition: Maps.h:1843
void setRow(int i, const Vec3< T > &v)
Set ith row to vector v.
Definition: Mat3.h:157
const Mat3d & getConstJacobianInv() const
Definition: Maps.h:646
UnitaryMap(const Mat3d &m)
Definition: Maps.h:1642
bool operator!=(const UnitaryMap &other) const
Definition: Maps.h:1730
void setDepth(double d)
set the frustum depth: distance between near and far plane = frustm depth * frustm x-width ...
Definition: Maps.h:2335
Vec3d voxelSize(const Vec3d &) const
Returns the lengths of the images of the segments , , this is equivalent to the absolute values of t...
Definition: Maps.h:825
AffineMap::Ptr getAffineMap() const
Return AffineMap::Ptr to an AffineMap equivalent to *this.
Definition: Maps.h:1101
static Name mapType()
Definition: Maps.h:1249
MapBase::Ptr preShear(double shear, Axis axis0, Axis axis1) const
Return a MapBase::Ptr to a new map that is the result of prepending the appropraite operation to the ...
Definition: Maps.h:888
Vec3d applyIJT(const Vec3d &in, const Vec3d &) const
Return the transpose of the inverse Jacobian (Identity for TranslationMap) of the map applied to in...
Definition: Maps.h:1057
bool isLinear() const
Return true (a ScaleTranslateMap is always linear).
Definition: Maps.h:1252
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
Mat3< double > Mat3d
Definition: Mat3.h:666
std::string str() const
string serialization, useful for debuging
Definition: Maps.h:1366
ScaleTranslateMap(const ScaleMap &scale, const TranslationMap &translate)
Definition: Maps.h:1203
const AffineMap & secondMap() const
Return MapBase::Ptr&amp; to the second map.
Definition: Maps.h:2345
Vec3d applyInverseJacobian(const Vec3d &in, const Vec3d &isloc) const
Return the Inverse Jacobian defined at isloc of the map applied to in.
Definition: Maps.h:2115
double determinant() const
Return the product of the scale values.
Definition: Maps.h:1326
Vec3d voxelSize(const Vec3d &loc) const
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)
Definition: Maps.h:2319
static bool isRegistered()
Definition: Maps.h:946
Definition: Exceptions.h:78
double determinant(const Vec3d &) const
Return the determinant of the Jacobian, ignores argument.
Definition: Maps.h:1765
MatType shear(Axis axis0, Axis axis1, typename MatType::value_type shear)
Set the matrix to a shear along axis0 by a fraction of axis1.
Definition: Mat.h:669
AffineMap::Ptr getAffineMap() const
Return AffineMap::Ptr to an AffineMap equivalent to *this.
Definition: Maps.h:1388
AffineMap & operator=(const AffineMap &other)
Definition: Maps.h:426
Mat3d applyIJC(const Mat3d &in, const Vec3d &, const Vec3d &) const
Definition: Maps.h:1321
Vec3d applyJT(const Vec3d &in, const Vec3d &) const
Definition: Maps.h:455
ScaleMap(const Vec3d &scale)
Definition: Maps.h:694
ScaleTranslateMap(const Vec3d &scale, const Vec3d &translate)
Definition: Maps.h:1188
A specialized Affine transform that scales along the principal axis the scaling is uniform in the thr...
Definition: Maps.h:926
double determinant() const
Return the product of the scale values.
Definition: Maps.h:807
Vec3d applyIJT(const Vec3d &in) const
Return the transpose of the inverse Jacobian of the map applied to in.
Definition: Maps.h:467
bool isDiagonal(const MatType &mat)
Determine if a matrix is diagonal.
Definition: Mat.h:864
MapBase::Ptr inverseMap() const
Return a new map representing the inverse of this map.
Definition: Maps.h:1014
Vec3d applyInverseJacobian(const Vec3d &in, const Vec3d &) const
Return the Inverse Jacobian of the map applied to in. (i.e. inverse map with out translation) ...
Definition: Maps.h:774
static MapBase::Ptr create()
Return a MapBase::Ptr to a new ScaleTranslateMap.
Definition: Maps.h:1229
bool isLinear() const
Return true (a ScaleMap is always linear).
Definition: Maps.h:740
static bool isRegistered()
Definition: Maps.h:727
void write(std::ostream &os) const
write serialization
Definition: Maps.h:557
static bool isRegistered()
Definition: Maps.h:1701
virtual bool isEqual(const MapBase &other) const
Return true if this map is equal to the given map.
Definition: Maps.h:414
std::string str() const
string serialization, useful for debugging
Definition: Maps.h:563
bool hasTranslation(const Mat4< T > &m)
Definition: Mat4.h:1342
boost::shared_ptr< ScaleTranslateMap > Ptr
Definition: Maps.h:1174
bool isIdentity(const MatType &m)
Definition: Mat.h:834
bool isDiagonal() const
Definition: Maps.h:2618
MapBase::Ptr preTranslate(const Vec3d &t) const
Return a MapBase::Ptr to a new map that is the result of prepending the appropraite operation...
Definition: Maps.h:1404
bool operator!=(const MyType &other) const
Definition: Maps.h:2599
Vec3d applyJacobian(const Vec3d &in) const
Return the Jacobian of the map applied to in.
Definition: Maps.h:1285
bool operator==(const ScaleMap &other) const
Definition: Maps.h:857
Tolerance for floating-point comparison.
Definition: Math.h:116
void write(std::ostream &os) const
write serialization
Definition: Maps.h:1356
bool hasUniformScale() const
Return false (by convention true)
Definition: Maps.h:1719
MapBase::Ptr postShear(double shear, Axis axis0, Axis axis1) const
Return a MapBase::Ptr to a new map that is the result of postfixing the appropraite operation...
Definition: Maps.h:1439
Vec3d applyInverseJacobian(const Vec3d &in) const
Return the Inverse Jacobian of the map applied to in. (i.e. inverse map with out translation) ...
Definition: Maps.h:2113
static void registerMap()
Definition: Maps.h:1241
double determinant(const Vec3d &) const
Return 1.
Definition: Maps.h:1066
Vec3d applyMap(const Vec3d &in) const
Return the image of in under the map.
Definition: Maps.h:1732
static Name mapType()
Definition: Maps.h:1026
Vec3d applyInverseJacobian(const Vec3d &in) const
Return the Inverse Jacobian of the map applied to in. (i.e. inverse map with out translation) ...
Definition: Maps.h:1290
MapBase::Ptr copy() const
Return a MapBase::Ptr to a deep copy of this map.
Definition: Maps.h:940
const Vec3d & getTranslation() const
Returns the translation.
Definition: Maps.h:1336
bool hasUniformScale() const
Return false (by convention false)
Definition: Maps.h:2027
Type Round(Type x)
Return x rounded down to the nearest integer.
Definition: Math.h:693
MapBase::Ptr inverseMap() const
Return a new map representing the inverse of this map.
Definition: Maps.h:1696
void read(std::istream &is)
read serialization
Definition: Maps.h:1778
Vec3d applyJacobian(const Vec3d &in, const Vec3d &) const
Return the Jacobian of the map applied to in.
Definition: Maps.h:1039
MapBase::Ptr postTranslate(const Vec3d &t) const
Return a MapBase::Ptr to a new map that is the result of postfixing the appropriate operation...
Definition: Maps.h:1145
Vec3d applyIJT(const Vec3d &in, const Vec3d &) const
Return the transpose of the inverse Jacobian of the map applied to in.
Definition: Maps.h:788
MapBase::Ptr preTranslate(const Vec3d &t) const
Return a MapBase::Ptr to a new map that is the result of prepending the appropraite operation...
Definition: Maps.h:1807
static Name mapType()
Definition: Maps.h:1514
CompoundMap(const FirstMapType &f, const SecondMapType &s)
Definition: Maps.h:2574
bool isUnitary(const MatType &m)
Determine is a matrix is Unitary (i.e. rotation or reflection)
Definition: Mat.h:854
Name type() const
Return the name of this map&#39;s concrete type (e.g., &quot;AffineMap&quot;).
Definition: Maps.h:395
Vec3< T > row(int i) const
Get ith row, e.g. Vec3d v = m.row(1);.
Definition: Mat3.h:168
const Vec3d & getInvScaleSqr() const
Return the square of the scale. Used to optimize some finite difference calculations.
Definition: Maps.h:813
CompoundMap(const MyType &other)
Definition: Maps.h:2579
SpectralDecomposedMap SymmetricMap
Definition: Maps.h:70
bool isIdentity() const
Return true if the underlying matrix is approximately an identity.
Definition: Maps.h:488
T * asPointer()
Definition: Vec3.h:103
Vec3d applyInverseJacobian(const Vec3d &in, const Vec3d &) const
Return the Inverse Jacobian of the map applied to in. (i.e. inverse map with out translation) ...
Definition: Maps.h:449
CompoundMap< FirstMapType, SecondMapType > MyType
Definition: Maps.h:2566
boost::shared_ptr< NonlinearFrustumMap > Ptr
Definition: Maps.h:1874
Threadsafe singleton object for accessing the map type-name dictionary. Associates a map type-name wi...
Definition: Maps.h:285
Vec3d applyJT(const Vec3d &in, const Vec3d &) const
Definition: Maps.h:1051
bool operator==(const UniformScaleTranslateMap &other) const
Definition: Maps.h:1518
Mat3d applyIJC(const Mat3d &in, const Vec3d &, const Vec3d &) const
Definition: Maps.h:472
bool isInvertible(const MatType &m)
Definition: Mat.h:841
Vec3d applyMap(const Vec3d &in) const
Return the image of in under the map.
Definition: Maps.h:2076
boost::shared_ptr< const AffineMap > ConstPtr
Definition: Maps.h:327
bool isLinear() const
Return false (a NonlinearFrustumMap is never linear).
Definition: Maps.h:2024
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:430
Vec3d applyMap(const Vec3d &in) const
Return the image of in under the map.
Definition: Maps.h:753
MapBase::Ptr preShear(double shear, Axis axis0, Axis axis1) const
Return a MapBase::Ptr to a new map that is the result of prepending the appropriate operation to the ...
Definition: Maps.h:2423
AffineMap(const AffineMap &first, const AffineMap &second)
constructor that merges the matrixes for two affine maps
Definition: Maps.h:371
Mat3d applyIJC(const Mat3d &in, const Vec3d &, const Vec3d &) const
Definition: Maps.h:803
MapBase::Ptr preTranslate(const Vec3d &t) const
Return a MapBase::Ptr to a new map that is the result of prepending the appropriate operation to the ...
Definition: Maps.h:2413
boost::shared_ptr< const TranslationMap > ConstPtr
Definition: Maps.h:1000
~ScaleTranslateMap()
Definition: Maps.h:1226
MapBase::Ptr copy() const
Returns a MapBase::Ptr to a deep copy of *this.
Definition: Maps.h:1694
void write(std::ostream &os) const
write serialization
Definition: Maps.h:2384
double determinant(const Vec3d &loc) const
Definition: Maps.h:2297
Name type() const
Definition: Maps.h:2585
boost::shared_ptr< TranslationMap > Ptr
Definition: Maps.h:999
CompoundMap< CompoundMap< UnitaryMap, ScaleMap >, UnitaryMap > SpectralDecomposedMap
Definition: Maps.h:69
OPENVDB_IMPORT uint32_t getFormatVersion(std::istream &)
Return the file format version number associated with the given input stream.
boost::shared_ptr< const ScaleTranslateMap > ConstPtr
Definition: Maps.h:1175
static Name mapType()
Definition: Maps.h:2586
static Name mapType()
Definition: Maps.h:737
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:1871
Vec3d applyJT(const Vec3d &in) const
Return the Jacobian Transpose of the map applied to in.
Definition: Maps.h:457
Definition: Math.h:763
static void registerMap()
Definition: Maps.h:947
Vec3d applyIJT(const Vec3d &in) const
Return the transpose of the inverse Jacobian of the map applied to in.
Definition: Maps.h:790
Vec3d applyJT(const Vec3d &in, const Vec3d &) const
Definition: Maps.h:1748
T det() const
Determinant of matrix.
Definition: Mat3.h:481
MapBase::Ptr copy() const
Return a MapBase::Ptr to a deep copy of this map.
Definition: Maps.h:2000
std::string Name
Definition: Name.h:44
bool operator==(const UnitaryMap &other) const
Definition: Maps.h:1723
static bool isEqualBase(const MapT &self, const MapBase &other)
Definition: Maps.h:273
bool operator!=(const TranslationMap &other) const
Definition: Maps.h:1098
Vec3d applyJacobian(const Vec3d &in) const
Return the Jacobian of the linear second map applied to in.
Definition: Maps.h:2087
const Vec3d & getScale() const
Return the scale values that define the map.
Definition: Maps.h:810
Vec3d applyInverseMap(const Vec3d &in) const
Return the pre-image of in under the map.
Definition: Maps.h:441
A specialized linear transform that performs a translation.
Definition: Maps.h:996
#define OPENVDB_VERSION_NAME
Definition: version.h:45
void setSecondMap(const SecondMapType &second)
Definition: Maps.h:2642
Vec3d applyJacobian(const Vec3d &in) const
Return the Jacobian of the map applied to in.
Definition: Maps.h:1738
boost::shared_ptr< UniformScaleMap > Ptr
Definition: Maps.h:929
Vec3< T > col(int j) const
Get jth column, e.g. Vec3d v = m.col(0);.
Definition: Mat3.h:184
UnitaryMap(const Vec3d &axis, double radians)
Definition: Maps.h:1628
Vec3d applyJacobian(const Vec3d &in) const
Return the Jacobian of the map applied to in.
Definition: Maps.h:1041
MapBase::Ptr preTranslate(const Vec3d &t) const
Return a MapBase::Ptr to a new map that is the result of prepending the appropriate operation...
Definition: Maps.h:1120
bool operator!=(const ScaleTranslateMap &other) const
Definition: Maps.h:1385
const Coord & min() const
Definition: Coord.h:257
TranslationMap(const Vec3d &t)
Definition: Maps.h:1004
MapBase::Ptr copy() const
Return a MapBase::Ptr to a deep copy of this map.
Definition: Maps.h:1492
Vec3d applyJT(const Vec3d &in) const
Return the Jacobian Transpose of the map applied to in.
Definition: Maps.h:1296
bool isIdentity() const
Definition: Maps.h:2609
Abstract base class for maps.
Definition: Maps.h:158
Mat3< T > getMat3() const
Definition: Mat4.h:304
Name type() const
Return the name of this map&#39;s concrete type (e.g., &quot;AffineMap&quot;).
Definition: Maps.h:1025
static void registerMap()
Definition: Maps.h:1018
AffineMap(const AffineMap &other)
Definition: Maps.h:358
bool isLinear() const
Return true (a TranslationMap is always linear).
Definition: Maps.h:1029
Vec3d applyJacobian(const Vec3d &in, const Vec3d &) const
Return the Jacobian of the map applied to in.
Definition: Maps.h:1283
Name readString(std::istream &is)
Definition: Name.h:47
Vec3d applyJT(const Vec3d &in, const Vec3d &) const
Definition: Maps.h:780
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec3.h:94
boost::shared_ptr< ScaleMap > Ptr
Definition: Maps.h:687
bool isDiagonal() const
Return true if the underylying matrix is diagonal.
Definition: Maps.h:490
double determinant() const
Return the determinant of the Jacobian of linear second map.
Definition: Maps.h:2293
Vec3d applyInverseJacobian(const Vec3d &in) const
Return the Inverse Jacobian of the map applied to in. (i.e. inverse map with out translation) ...
Definition: Maps.h:776
CompoundMap< UnitaryMap, TranslationMap > UnitaryAndTranslationMap
Definition: Maps.h:66
bool operator==(const ScaleTranslateMap &other) const
Definition: Maps.h:1377
Vec3d voxelSize() const
Returns the lengths of the images of the segments , , .
Definition: Maps.h:1774
~UniformScaleMap()
Definition: Maps.h:935
Vec3d applyIJT(const Vec3d &d1_is, const Vec3d &ijk) const
Definition: Maps.h:2182
A general linear transform using homogeneous coordinates to perform rotation, scaling, shear and translation.
Definition: Maps.h:323
boost::shared_ptr< const NonlinearFrustumMap > ConstPtr
Definition: Maps.h:1875
void read(std::istream &is)
read serialization
Definition: Maps.h:550
static bool isRegistered()
Definition: Maps.h:1016
T dot(const Vec3< T > &v) const
Dot product.
Definition: Vec3.h:199
Vec3d applyIJT(const Vec3d &in) const
Return the transpose of the inverse Jacobian (Identity for TranslationMap) of the map applied to in...
Definition: Maps.h:1060
MapBase::Ptr copy() const
Return a MapBase::Ptr to a deep copy of this map.
Definition: Maps.h:1231
static bool isRegistered()
Definition: Maps.h:1239
AffineMap::Ptr getAffineMap() const
Definition: Maps.h:2328
void accumPreTranslation(const Vec3d &v)
Modify the existing affine map by pre-applying the given operation.
Definition: Maps.h:511
bool normalize(T eps=T(1.0e-7))
this = normalized this
Definition: Vec3.h:328
Vec3d applyInverseJacobian(const Vec3d &in, const Vec3d &) const
Return the Inverse Jacobian of the map applied to in. (i.e. inverse map with out translation) ...
Definition: Maps.h:1288
Vec3d applyInverseMap(const Vec3d &in) const
Return the pre-image of in under the map.
Definition: Maps.h:761
Mat3d applyIJC(const Mat3d &in) const
Return the Jacobian Curvature: zero for a linear map.
Definition: Maps.h:1310
const Mat4d & getConstMat4() const
Definition: Maps.h:645
boost::shared_ptr< MyType > Ptr
Definition: Maps.h:2568
ScaleTranslateMap(const ScaleTranslateMap &other)
Definition: Maps.h:1216
MapBase::Ptr postShear(double shear, Axis axis0, Axis axis1) const
Return a MapBase::Ptr to a new map that is the result of postfixing the appropiate operation to the l...
Definition: Maps.h:2448
OPENVDB_API boost::shared_ptr< FullyDecomposedMap > createFullyDecomposedMap(const Mat4d &m)
General decomposition of a Matrix into a Unitary (e.g. rotation) following a Symmetric (e...
static void registerMap()
Definition: Maps.h:1506
ScaleMap()
Definition: Maps.h:690
MapBase::Ptr preShear(double shear, Axis axis0, Axis axis1) const
Return a MapBase::Ptr to a new map that is the result of prepending the appropraite operation...
Definition: Maps.h:605
void accumPostTranslation(const Vec3d &v)
Modify the existing affine map by post-applying the given operation.
Definition: Maps.h:536
Vec3< double > Vec3d
Definition: Vec3.h:605
static MapBase::Ptr create()
Return a MapBase::Ptr to a new UniformScaleMap.
Definition: Maps.h:938
MapBase::Ptr preTranslate(const Vec3d &t) const
Return a MapBase::Ptr to a UniformScaleTranslateMap that is the result of prepending translation on t...
Definition: Maps.h:1526
Vec4< T0 > transform(const Vec4< T0 > &v) const
Transform a Vec4 by post-multiplication.
Definition: Mat4.h:1012
UniformScaleMap(double scale)
Definition: Maps.h:933
const BBoxd & getBBox() const
Return the bounding box that defines the frustum in pre-image space.
Definition: Maps.h:2342
Mat3d applyIJC(const Mat3d &in) const
Return the Jacobian Curvature: zero for a linear map.
Definition: Maps.h:1762
NonlinearFrustumMap(const NonlinearFrustumMap &other)
Definition: Maps.h:1912
UnitaryMap(const Mat4d &m)
Definition: Maps.h:1654
UnitaryMap()
default constructor makes an Idenity.
Definition: Maps.h:1624
Vec3d applyInverseMap(const Vec3d &in) const
Return the pre-image of in under the map.
Definition: Maps.h:2082
Vec3d applyInverseMap(const Vec3d &in) const
Return the pre-image of under the map.
Definition: Maps.h:1274
AffineMap::Ptr getAffineMap() const
Return a AffineMap equivalent to this map.
Definition: Maps.h:867
bool operator!=(const UniformScaleMap &other) const
Definition: Maps.h:960
~UniformScaleTranslateMap()
Definition: Maps.h:1487
T & y()
Definition: Vec3.h:95
A specialized Affine transform that scales along the principal axis the scaling need not be uniform i...
Definition: Maps.h:1171
MapBase::Ptr preTranslate(const Vec3d &t) const
Return a MapBase::Ptr to a new map that is the result of prepending the appropraite operation...
Definition: Maps.h:593
math::BBox< Vec3d > BBoxd
Definition: Types.h:84
void accumPostShear(Axis axis0, Axis axis1, double shear)
Modify the existing affine map by post-applying the given operation.
Definition: Maps.h:541
NonlinearFrustumMap()
Definition: Maps.h:1877
Mat3d applyIJC(const Mat3d &in) const
Return the Jacobian Curvature for the linear second map.
Definition: Maps.h:2218
Vec3d applyInverseJacobian(const Vec3d &in) const
Return the Inverse Jacobian of the map applied to in. (i.e. inverse map with out translation) ...
Definition: Maps.h:1046
Int32 ValueType
Definition: Coord.h:55
MapBase::Ptr postShear(double shear, Axis axis0, Axis axis1) const
Return a MapBase::Ptr to a new map that is the result of prepending the appropraite operation to the ...
Definition: Maps.h:911
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:229
static bool isRegistered()
Definition: Maps.h:2010
MapBase::Ptr inverseMap() const
Return a new map representing the inverse of this map.
Definition: Maps.h:725
void read(std::istream &is)
Definition: Maps.h:2644
Vec3d applyMap(const Vec3d &in) const
Return the image of in under the map.
Definition: Maps.h:439
MapBase::Ptr postTranslate(const Vec3d &t) const
Return a MapBase::Ptr to a new map that is the result of postfixing the appropraite operation...
Definition: Maps.h:1432
MapBase::Ptr inverseMap() const
Not implemented, since there is currently no map type that can represent the inverse of a frustum...
Definition: Maps.h:2005
Vec3d applyIJT(const Vec3d &in) const
Return the transpose of the inverse Jacobian of the map applied to in.
Definition: Maps.h:1760
void write(std::ostream &os) const
Definition: Maps.h:2650
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...
Definition: Maps.h:1900
boost::shared_ptr< const UniformScaleMap > ConstPtr
Definition: Maps.h:930
static void registerMap()
Definition: Maps.h:1703
virtual bool isEqual(const MapBase &other) const
Return true if this map is equal to the given map.
Definition: Maps.h:2049
Mat3 transpose() const
returns transpose of this
Definition: Mat3.h:455
UniformScaleTranslateMap(const UniformScaleMap &scale, const TranslationMap &translate)
Definition: Maps.h:1483
bool isLinear() const
Return true (a UnitaryMap is always linear).
Definition: Maps.h:1716
~UnitaryMap()
Definition: Maps.h:1690
UniformScaleTranslateMap(double scale, const Vec3d &translate)
Definition: Maps.h:1481
UniformScaleTranslateMap()
Definition: Maps.h:1480
Vec3d applyInverseJacobian(const Vec3d &in) const
Return the Inverse Jacobian of the map applied to in. (i.e. inverse map with out translation) ...
Definition: Maps.h:1743
OPENVDB_API Mat4d approxInverse(const Mat4d &mat)
Returns the left pseudoInverse of the input matrix when the 3x3 part is symmetric otherwise it zeros ...
Mat3 inverse(T tolerance=0) const
Definition: Mat3.h:466
double determinant(const Vec3d &) const
Return the determinant of the Jacobian, ignores argument.
Definition: Maps.h:476
Definition: Exceptions.h:82
Vec3< typename MatType::value_type > getScale(const MatType &mat)
Definition: Mat.h:614
MatType scale(const Vec3< typename MatType::value_type > &scaling)
Definition: Mat.h:595
MapBase::Ptr preScale(const Vec3d &v) const
Return a MapBase::Ptr to a new map that is the result of prepending the appropraite operation...
Definition: Maps.h:1813
UnitaryMap(const UnitaryMap &other)
Definition: Maps.h:1679
Definition: Exceptions.h:84
bool operator==(const TranslationMap &other) const
Definition: Maps.h:1092
CompoundMap< SymmetricMap, UnitaryMap > PolarDecomposedMap
Definition: Maps.h:72
bool operator==(const UniformScaleMap &other) const
Definition: Maps.h:959
MapBase::Ptr postScale(const Vec3d &s) const
Return a MapBase::Ptr to a new map that is the result of postfixing the appropraite operation...
Definition: Maps.h:629
const Vec3d & getInvScaleSqr() const
Return the square of the scale. Used to optimize some finite difference calculations.
Definition: Maps.h:1339
void setToRotation(Axis axis, T angle)
Sets the matrix to a rotation about the given axis.
Definition: Mat4.h:797
static void registerMap()
Definition: Maps.h:729
void accumPreScale(const Vec3d &v)
Modify the existing affine map by pre-applying the given operation.
Definition: Maps.h:506
OPENVDB_API boost::shared_ptr< SymmetricMap > createSymmetricMap(const Mat3d &m)
Utility methods.
Mat3d applyIJC(const Mat3d &mat) const
Return the Jacobian Curvature: zero for a linear map.
Definition: Maps.h:1062
void read(std::istream &is)
Unserialize this bounding box from the given stream.
Definition: BBox.h:157
OPENVDB_API boost::shared_ptr< MapBase > simplify(boost::shared_ptr< AffineMap > affine)
reduces an AffineMap to a ScaleMap or a ScaleTranslateMap when it can
static Name mapType()
Definition: Maps.h:396
double getDepth() const
Return the unscaled frustm depth.
Definition: Maps.h:2337
double getGamma() const
Definition: Maps.h:2339
bool isLinear() const
Return true (an AffineMap is always linear).
Definition: Maps.h:399
Vec3d voxelSize() const
Return the size of a voxel at the center of the near plane.
Definition: Maps.h:2305
MapBase::Ptr inverseMap() const
Return a new map representing the inverse of this map.
Definition: Maps.h:384
AffineMap(const Mat3d &m)
Definition: Maps.h:341
const Coord & max() const
Definition: Coord.h:258
boost::shared_ptr< const UnitaryMap > ConstPtr
Definition: Maps.h:1621
Vec3d applyJT(const Vec3d &in, const Vec3d &) const
Definition: Maps.h:1294
Vec3d voxelSize(const Vec3d &) const
Method to return the local size of a voxel. When a location is specified as an argument, it is understood to be be in the domain of the map (i.e. index space)
Definition: Maps.h:1775
void read(std::istream &is)
read serialization
Definition: Maps.h:1078
void writeString(std::ostream &os, const Name &name)
Definition: Name.h:58
MapBase::Ptr copy() const
Return a MapBase::Ptr to a deep copy of this map.
Definition: Maps.h:1012
bool operator!=(const AffineMap &other) const
Definition: Maps.h:424
MapBase::Ptr inverseMap() const
Return a new map representing the inverse of this map.
Definition: Maps.h:1494
boost::shared_ptr< AffineMap > Ptr
Definition: Maps.h:326
bool isScaleTranslate() const
Return true if the map is equivalent to a ScaleTranslateMap.
Definition: Maps.h:494
~ScaleMap()
Definition: Maps.h:718
Mat3d applyIJC(const Mat3d &in, const Vec3d &, const Vec3d &) const
Definition: Maps.h:1763
boost::shared_ptr< FullyDecomposedMap > createDecomposedMap()
on-demand decomposition of the affine map
Definition: Maps.h:572
AffineMap::Ptr getAffineMap() const
Return AffineMap::Ptr to an AffineMap equivalent to *this.
Definition: Maps.h:1796
Mat4 inverse(T tolerance=0) const
Definition: Mat4.h:492
static const Mat4< double > & identity()
Predefined constant for identity matrix.
Definition: Mat4.h:149
bool operator==(const NonlinearFrustumMap &other) const
Definition: Maps.h:2051
static void registerMap()
Definition: Maps.h:388
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...
Definition: Maps.h:1889
Vec3d applyJT(const Vec3d &in) const
Return the Jacobian Transpose of the map applied to in.
Definition: Maps.h:782
MapBase::Ptr postShear(double shear, Axis axis0, Axis axis1) const
Return a MapBase::Ptr to a new map that is the result of postfixing the appropriate operation...
Definition: Maps.h:1152
void read(std::istream &is)
read serialization
Definition: Maps.h:2354
Name type() const
Return NonlinearFrustumMap.
Definition: Maps.h:2019
Mat3d applyIJC(const Mat3d &m) const
Return the Jacobian Curvature: zero for a linear map.
Definition: Maps.h:469
std::string str() const
string serialization, useful for debuging
Definition: Maps.h:847
const Vec3d & getInvTwiceScale() const
Return 1/(2 scale). Used to optimize some finite difference calculations.
Definition: Maps.h:815
Vec3d applyJacobian(const Vec3d &in, const Vec3d &) const
Apply the Jacobian of this map to a vector. For a linear map this is equivalent to applying the map e...
Definition: Maps.h:1736
void read(std::istream &is)
read serialization
Definition: Maps.h:1346
std::map< Name, MapBase::MapFactory > MapDictionary
Definition: Maps.h:288
double determinant(const Vec3d &) const
Return the product of the scale values, ignores argument.
Definition: Maps.h:1324
Creates the composition of two maps, each of which could be a composition. In the case that each comp...
Definition: Maps.h:66
MapBase::Ptr postTranslate(const Vec3d &t) const
Return a MapBase::Ptr to a new map that is the result of postfixing the appropraite operation...
Definition: Maps.h:623
const FirstMapType & firstMap() const
Definition: Maps.h:2638
ScaleMap(const ScaleMap &other)
Definition: Maps.h:708
Vec3d applyIJT(const Vec3d &in, const Vec3d &) const
Return the transpose of the inverse Jacobian of the map applied to in.
Definition: Maps.h:1300
bool operator==(const AffineMap &other) const
Definition: Maps.h:416
Definition: Maps.h:103
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:56
UnitaryMap(Axis axis, double radians)
Definition: Maps.h:1635
Axis
Definition: Math.h:762
void setToRotation(const Quat< T > &q)
Set this matrix to the rotation matrix specified by the quaternion.
Definition: Mat3.h:270
MyType & operator=(const MyType &other)
Definition: Maps.h:2601
AffineMap::Ptr inverse() const
Return AffineMap::Ptr to the inverse of this map.
Definition: Maps.h:581
bool isApproxEqual(const Hermite &lhs, const Hermite &rhs)
Definition: Hermite.h:470
static MapBase::Ptr create()
Return a MapBase::Ptr to a new AffineMap.
Definition: Maps.h:380
MapBase::Ptr copy() const
Return a MapBase::Ptr to a deep copy of this map.
Definition: Maps.h:382
void setTranslation(const Vec3< T > &t)
Definition: Mat4.h:321
void accumPreShear(Axis axis0, Axis axis1, double shear)
Modify the existing affine map by pre-applying the given operation.
Definition: Maps.h:516
UniformScaleTranslateMap(const UniformScaleTranslateMap &other)
Definition: Maps.h:1486
MapBase::Ptr postShear(double shear, Axis axis0, Axis axis1) const
Return a MapBase::Ptr to a new map that is the result of postfixing the appropraite operation...
Definition: Maps.h:1849
void setMat3(const Mat3< T > &m)
Set upper left to a Mat3.
Definition: Mat4.h:297
std::string str() const
string serialization, useful for debuging
Definition: Maps.h:1789
MapBase::Ptr inverseMap() const
Return a new map representing the inverse of this map.
Definition: Maps.h:942
MapBase::Ptr postTranslate(const Vec3d &t) const
Return a MapBase::Ptr to a UniformScaleTranslateMap that is the result of postfixing translation on t...
Definition: Maps.h:1535
bool isType() const
Return true if this map is of concrete type MapT (e.g., AffineMap).
Definition: Maps.h:173
Vec3d applyJT(const Vec3d &in) const
Return the Jacobian Transpose of the map applied to in.
Definition: Maps.h:1053
void accumPostScale(const Vec3d &v)
Modify the existing affine map by post-applying the given operation.
Definition: Maps.h:531
Vec3d applyIJT(const Vec3d &in) const
Return the transpose of the inverse Jacobian of the map applied to in.
Definition: Maps.h:1302
Vec3d applyInverseMap(const Vec3d &in) const
Return the pre-image of in under the map.
Definition: Maps.h:1037
bool hasUniformScale() const
Return true if the values have the same magitude (eg. -1, 1, -1 would be a rotation).
Definition: Maps.h:743
CompoundMap< SymmetricMap, UnitaryAndTranslationMap > FullyDecomposedMap
Definition: Maps.h:71
UniformScaleMap()
Definition: Maps.h:932
static bool isRegistered()
Definition: Maps.h:386
AffineMap(const Mat4d &m)
Definition: Maps.h:349
bool operator!=(const ScaleMap &other) const
Definition: Maps.h:864
MapBase::Ptr preScale(const Vec3d &s) const
Return a MapBase::Ptr to a new map that is the result of prepending the appropraite operation...
Definition: Maps.h:599
const Vec3d & getInvTwiceScale() const
Return 1/(2 scale). Used to optimize some finite difference calculations.
Definition: Maps.h:1341
std::string str() const
string serialization, useful for debuging
Definition: Maps.h:1083
bool hasSimpleAffine() const
Return true if the second map is a uniform scale, Rotation and translation.
Definition: Maps.h:2351
MapBase::Ptr postShear(double shear, Axis axis0, Axis axis1) const
Return a MapBase::Ptr to a new map that is the result of postfixing the appropraite operation...
Definition: Maps.h:635
boost::shared_ptr< MapBase > Ptr
Definition: Maps.h:161
double determinant(const Vec3d &) const
Return the product of the scale values, ignores argument.
Definition: Maps.h:805
MapBase::Ptr postScale(const Vec3d &s) const
Return a MapBase::Ptr to a new map that is the result of postfixing the appropiate operation to the l...
Definition: Maps.h:2443
Vec3d applyJacobian(const Vec3d &in, const Vec3d &) const
Return the Jacobian of the map applied to in.
Definition: Maps.h:769
const Vec3d & getInvScale() const
Return 1/(scale)
Definition: Maps.h:817
~TranslationMap()
Definition: Maps.h:1007
bool isScale() const
Return true if the map is equivalent to a ScaleMap.
Definition: Maps.h:492
AffineMap::Ptr getAffineMap() const
Return AffineMap::Ptr to a deep copy of the current AffineMap.
Definition: Maps.h:578
bool hasUniformScale() const
Return false ( test if this is unitary with translation )
Definition: Maps.h:402
Vec3d applyMap(const Vec3d &in) const
Return the image of under the map.
Definition: Maps.h:1266
MapBase::Ptr preScale(const Vec3d &s) const
Return a MapBase::Ptr to a new map that is the result of prepending the appropriate operation to the ...
Definition: Maps.h:2418
Vec3d voxelSize() const
Return .
Definition: Maps.h:1071
static void registerMap()
Definition: Maps.h:2012
bool operator==(const MyType &other) const
Definition: Maps.h:2591
UniformScaleMap(const UniformScaleMap &other)
Definition: Maps.h:934
virtual bool isEqual(const MapBase &other) const
Return true if this map is equal to the given map.
Definition: Maps.h:1090
Name type() const
Return the name of this map&#39;s concrete type (e.g., &quot;AffineMap&quot;).
Definition: Maps.h:736
ScaleTranslateMap()
Definition: Maps.h:1177
TranslationMap(const TranslationMap &other)
Definition: Maps.h:1005
static MapBase::Ptr create()
Return a MapBase::Ptr to a new ScaleMap.
Definition: Maps.h:721
Mat4d getMat4() const
Return the matrix representation of this AffineMap.
Definition: Maps.h:644
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.
Definition: Maps.h:1938
bool operator!=(const UniformScaleTranslateMap &other) const
Definition: Maps.h:1522
void read(std::istream &is)
read serialization
Definition: Maps.h:829
MapBase()
Definition: Maps.h:270
void write(std::ostream &os) const
write serialization
Definition: Maps.h:1784
boost::shared_ptr< const ScaleMap > ConstPtr
Definition: Maps.h:688
virtual bool isEqual(const MapBase &other) const
Return true if this map is equal to the given map.
Definition: Maps.h:855
Vec3d voxelSize(const Vec3d &) 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
Vec3d applyJacobian(const Vec3d &in) const
Return the Jacobian of the map applied to in.
Definition: Maps.h:446
double determinant() const
Return 1.
Definition: Maps.h:1068
Vec3d applyJT(const Vec3d &in, const Vec3d &isloc) const
Definition: Maps.h:2145
void setFirstMap(const FirstMapType &first)
Definition: Maps.h:2641
A specialized Affine transform that uniformaly scales along the principal axis and then translates th...
Definition: Maps.h:1474
std::string str() const
string serialization, useful for debuging
Definition: Maps.h:2395
static Name mapType()
Return NonlinearFrustumMap.
Definition: Maps.h:2021
double determinant() const
Return the determinant of the Jacobian.
Definition: Maps.h:478
bool isAffine(const Mat4< T > &m)
Definition: Mat4.h:1337
bool operator!=(const NonlinearFrustumMap &other) const
Definition: Maps.h:2073
AffineMap::Ptr getAffineMap() const
Definition: Maps.h:2626
Vec3d applyIJT(const Vec3d &in, const Vec3d &) const
Return the transpose of the inverse Jacobian of the map applied to in.
Definition: Maps.h:1758