OpenVDB: openvdb/math/Maps.h Source File

OpenVDB 13.0.0

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