add usd-21-11-win64_py39

This commit is contained in:
Sébastien Albert committed 2021-12-07 17:43:55 +01:00
1 parent 41d23e71ba
commit ba5e1f7e67
15684 files changed
+3069957

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
//
// Copyright 2017 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_GF_API_H
#define PXR_BASE_GF_API_H
#include "pxr/base/arch/export.h"
#if defined(PXR_STATIC)
# define GF_API
# define GF_API_TEMPLATE_CLASS(...)
# define GF_API_TEMPLATE_STRUCT(...)
# define GF_LOCAL
#else
# if defined(GF_EXPORTS)
# define GF_API ARCH_EXPORT
# define GF_API_TEMPLATE_CLASS(...) ARCH_EXPORT_TEMPLATE(class, __VA_ARGS__)
# define GF_API_TEMPLATE_STRUCT(...) ARCH_EXPORT_TEMPLATE(struct, __VA_ARGS__)
# else
# define GF_API ARCH_IMPORT
# define GF_API_TEMPLATE_CLASS(...) ARCH_IMPORT_TEMPLATE(class, __VA_ARGS__)
# define GF_API_TEMPLATE_STRUCT(...) ARCH_IMPORT_TEMPLATE(struct, __VA_ARGS__)
# endif
# define GF_LOCAL ARCH_HIDDEN
#endif
#endif
+269
View File
@@ -0,0 +1,269 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_GF_BBOX3D_H
#define PXR_BASE_GF_BBOX3D_H
/// \file gf/bbox3d.h
/// \ingroup group_gf_BasicGeometry
#include "pxr/pxr.h"
#include "pxr/base/gf/matrix4d.h"
#include "pxr/base/gf/range3d.h"
#include "pxr/base/gf/api.h"
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
/// \class GfBBox3d
/// \ingroup group_gf_BasicGeometry
/// Basic type: arbitrarily oriented 3D bounding box.
///
/// This class represents a three-dimensional bounding box as an
/// axis-aligned box (\c GfRange3d) and a matrix (\c GfMatrix4d) to
/// transform it into the correct space.
///
/// A \c GfBBox3d is more useful than using just \c GfRange3d instances
/// (which are always axis-aligned) for these reasons:
///
/// \li When an axis-aligned bounding box is transformed several times,
/// each transformation can result in inordinate growth of the bounding
/// box. By storing the transformation separately, it can be applied once
/// at the end, resulting in a much better fit. For example, if the
/// bounding box at the leaf of a scene graph is transformed through
/// several levels of the graph hierarchy to the coordinate space at the
/// root, a \c GfBBox3d is generally much smaller than the \c GfRange3d
/// computed by transforming the box at each level.
///
/// \li When two or more such bounding boxes are combined, having the
/// transformations stored separately means that there is a better
/// opportunity to choose a better coordinate space in which to combine
/// the boxes.
///
/// \anchor bbox3d_zeroAreaFlag
/// <b> The Zero-area Primitives Flag </b>
///
/// When bounding boxes are used in intersection test culling, it is
/// sometimes useful to extend them a little bit to allow
/// lower-dimensional objects with zero area, such as lines and points,
/// to be intersected. For example, consider a cube constructed of line
/// segments. The bounding box for this shape fits the cube exactly. If
/// an application wants to allow a near-miss of the silhouette edges of
/// the cube to be considered an intersection, it has to loosen the bbox
/// culling test a little bit.
///
/// To distinguish when this loosening is necessary, each \c GfBBox3d
/// instance maintains a flag indicating whether any zero-area primitives
/// are contained within it. The application is responsible for setting
/// this flag correctly by calling \c SetHasZeroAreaPrimitives(). The
/// flag can be accessed during intersection tests by calling \c
/// HasZeroAreaPrimitives(). This flag is set by default in all
/// constructors to \c false.
///
class GfBBox3d {
public:
/// The default constructor leaves the box empty, the transformation
/// matrix identity, and the \ref bbox3d_zeroAreaFlag "zero-area
/// primitives flag" \c false.
GfBBox3d() {
_matrix.SetIdentity();
_inverse.SetIdentity();
_isDegenerate = false;
_hasZeroAreaPrimitives = false;
}
/// Copy constructor
GfBBox3d(const GfBBox3d& rhs) :
_box(rhs._box) {
_matrix = rhs._matrix;
_inverse = rhs._inverse;
_isDegenerate = rhs._isDegenerate;
_hasZeroAreaPrimitives = rhs._hasZeroAreaPrimitives;
}
/// This constructor takes a box and sets the matrix to identity.
GfBBox3d(const GfRange3d &box) :
_box(box) {
_matrix.SetIdentity();
_inverse.SetIdentity();
_isDegenerate = false;
_hasZeroAreaPrimitives = false;
}
/// This constructor takes a box and a transformation matrix.
GfBBox3d(const GfRange3d &box, const GfMatrix4d &matrix) {
Set(box, matrix);
_hasZeroAreaPrimitives = false;
}
/// Sets the axis-aligned box and transformation matrix.
void Set(const GfRange3d &box, const GfMatrix4d &matrix) {
_box = box;
_SetMatrices(matrix);
}
/// Sets the transformation matrix only. The axis-aligned box is not
/// modified.
void SetMatrix(const GfMatrix4d& matrix) {
_SetMatrices(matrix);
}
/// Sets the range of the axis-aligned box only. The transformation
/// matrix is not modified.
void SetRange(const GfRange3d& box) {
_box = box;
}
/// Returns the range of the axis-aligned untransformed box.
const GfRange3d & GetRange() const {
return _box;
}
/// Returns the range of the axis-aligned untransformed box.
/// This synonym of \c GetRange exists for compatibility purposes.
const GfRange3d & GetBox() const {
return GetRange();
}
/// Returns the transformation matrix.
const GfMatrix4d & GetMatrix() const {
return _matrix;
}
/// Returns the inverse of the transformation matrix. This will be the
/// identity matrix if the transformation matrix is not invertible.
const GfMatrix4d & GetInverseMatrix() const {
return _inverse;
}
/// Sets the \ref bbox3d_zeroAreaFlag "zero-area primitives flag" to the
/// given value.
void SetHasZeroAreaPrimitives(bool hasThem) {
_hasZeroAreaPrimitives = hasThem;
}
/// Returns the current state of the \ref bbox3d_zeroAreaFlag "zero-area
/// primitives flag".
bool HasZeroAreaPrimitives() const {
return _hasZeroAreaPrimitives;
}
/// Returns the volume of the box (0 for an empty box).
GF_API
double GetVolume() const;
/// Transforms the bounding box by the given matrix, which is assumed to
/// be a global transformation to apply to the box. Therefore, this just
/// post-multiplies the box's matrix by \p matrix.
void Transform(const GfMatrix4d &matrix) {
_SetMatrices(_matrix * matrix);
}
/// Returns the axis-aligned range (as a \c GfRange3d) that results from
/// applying the transformation matrix to the wxis-aligned box and
/// aligning the result.
GF_API
GfRange3d ComputeAlignedRange() const;
/// Returns the axis-aligned range (as a \c GfRange3d) that results from
/// applying the transformation matrix to the axis-aligned box and
/// aligning the result. This synonym for \c ComputeAlignedRange exists
/// for compatibility purposes.
GfRange3d ComputeAlignedBox() const {
return ComputeAlignedRange();
}
/// Combines two bboxes, returning a new bbox that contains both. This
/// uses the coordinate space of one of the two original boxes as the
/// space of the result; it uses the one that produces whe smaller of the
/// two resulting boxes.
GF_API
static GfBBox3d Combine(const GfBBox3d &b1, const GfBBox3d &b2);
/// Returns the centroid of the bounding box.
/// The centroid is computed as the transformed centroid of the range.
GF_API
GfVec3d ComputeCentroid() const;
/// Hash.
friend inline size_t hash_value(const GfBBox3d &b) {
size_t h = 0;
boost::hash_combine(h, b._box);
boost::hash_combine(h, b._matrix);
return h;
}
/// Component-wise equality test. The axis-aligned boxes and
/// transformation matrices match exactly for bboxes to be considered
/// equal. (To compare equality of the actual boxes, you can compute both
/// aligned boxes and test the results for equality.)
bool operator ==(const GfBBox3d &b) const {
return (_box == b._box &&
_matrix == b._matrix);
}
/// Component-wise inequality test. The axis-aligned boxes and
/// transformation matrices match exactly for bboxes to be considered
/// equal. (To compare equality of the actual boxes, you can compute both
/// aligned boxes and test the results for equality.)
bool operator !=(const GfBBox3d &that) const {
return !(*this == that);
}
private:
/// The axis-aligned box.
GfRange3d _box;
/// Transformation matrix.
GfMatrix4d _matrix;
/// Inverse of the transformation matrix.
GfMatrix4d _inverse;
/// Flag indicating whether the matrix is degenerate.
bool _isDegenerate;
/// Flag indicating whether the bbox contains zero-area primitives.
bool _hasZeroAreaPrimitives;
/// Sets the transformation matrix and the inverse, checking for
/// degeneracies.
GF_API
void _SetMatrices(const GfMatrix4d &matrix);
/// This is used by \c Combine() when it is determined which coordinate
/// space to use to combine two boxes: \p b2 is transformed into the space
/// of \p b1 and the results are merged in that space.
static GfBBox3d _CombineInOrder(const GfBBox3d &b1, const GfBBox3d &b2);
};
/// Output a GfBBox3d using the format [(range) matrix zeroArea]
///
/// The zeroArea flag is true or false and indicates whether the
/// bbox has zero area primitives in it.
///
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream&, const GfBBox3d&);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_BBOX3D_H
+256
View File
@@ -0,0 +1,256 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_GF_CAMERA_H
#define PXR_BASE_GF_CAMERA_H
/// \file gf/camera.h
/// \ingroup group_gf_BasicGeometry
#include "pxr/pxr.h"
#include "pxr/base/gf/matrix4d.h"
#include "pxr/base/gf/range1f.h"
#include "pxr/base/gf/vec4f.h"
#include "pxr/base/gf/api.h"
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
class GfFrustum;
/// \class GfCamera
/// \ingroup group_gf_BasicGeometry
/// \brief Object-based representation of a camera.
///
/// This class provides a thin wrapper on the camera data model,
/// with a small number of computations.
///
class GfCamera
{
public:
/// Projection type.
enum Projection {
Perspective = 0,
Orthographic,
};
/// Direction used for Field of View or orthographic size
enum FOVDirection {
FOVHorizontal = 0,
FOVVertical
};
/// The unit for horizontal and vertical aperture is one tenth of the
/// world unit. Thus, if the world unit is assumed to be cm, the horizontal
/// and vertical aperture unit is mm.
GF_API static const double APERTURE_UNIT;
/// The unit for focal length. Similar to APERTURE_UNIT.
GF_API static const double FOCAL_LENGTH_UNIT;
/// Default horizontal and vertical aperture, based on a 35mm
/// (non-anamorphic) projector aperture (0.825 x 0602 inches, converted to
/// mm).
GF_API static const double DEFAULT_HORIZONTAL_APERTURE;
GF_API static const double DEFAULT_VERTICAL_APERTURE;
public:
GF_API GfCamera(
const GfMatrix4d &transform = GfMatrix4d(1.0),
Projection projection = Perspective,
float horizontalAperture = DEFAULT_HORIZONTAL_APERTURE,
float verticalAperture = DEFAULT_VERTICAL_APERTURE,
float horizontalApertureOffset = 0.0,
float verticalApertureOffset = 0.0,
float focalLength = 50.0,
const GfRange1f &clippingRange = GfRange1f(1, 1000000),
const std::vector<GfVec4f> &clippingPlanes = std::vector<GfVec4f>(),
float fStop = 0.0,
float focusDistance = 0.0);
/// Sets the transform of the filmback in world space to \p val.
GF_API void SetTransform(const GfMatrix4d &val);
/// Sets the projection type.
GF_API void SetProjection(const Projection &val);
/// \name Physics based camera setup
/// These are the values actually stored in the class and they correspond
/// to measurements of an actual physical camera (in mm).
/// Together with the clipping range, they determine the camera frustum.
/// @{
/// Sets the focal length in tenths of a world unit (e.g., mm if the world
/// unit is assumed to be cm).
GF_API void SetFocalLength(const float val);
/// Sets the width of the projector aperture in tenths of a world unit
/// (e.g., mm if the world unit is assumed to be cm).
GF_API void SetHorizontalAperture(const float val);
/// Sets the height of the projector aperture in tenths of a world unit
/// (e.g., mm if the world unit is assumed to be cm).
GF_API void SetVerticalAperture(const float val);
/// Sets the horizontal offset of the projector aperture in tenths of a
/// world unit (e.g., mm if the world unit is assumed to be cm).
GF_API void SetHorizontalApertureOffset(const float val);
/// Sets the vertical offset of the projector aperture in tenths of a
/// world unit (e.g., mm if the world unit is assumed to be cm).
GF_API void SetVerticalApertureOffset(const float val);
/// @}
/// \name Frustum geometry setup
/// @{
/// Sets the frustum to be projective with the given \p aspectRatio
/// and horizontal, respectively, vertical field of view \p fieldOfView
/// (similar to gluPerspective when direction = FOVVertical).
///
/// Do not pass values for \p horionztalAperture unless you care about
/// DepthOfField.
GF_API void SetPerspectiveFromAspectRatioAndFieldOfView(
float aspectRatio,
float fieldOfView,
FOVDirection direction,
float horizontalAperture = DEFAULT_HORIZONTAL_APERTURE);
/// Sets the frustum to be orthographic such that it has the given
/// \p aspectRatio and such that the orthographic width, respectively,
/// orthographic height (in cm) is equal to \p orthographicSize
/// (depending on direction).
GF_API void SetOrthographicFromAspectRatioAndSize(
float aspectRatio, float orthographicSize, FOVDirection direction);
/// Sets the camera from a view and projection matrix.
///
/// Note that the projection matrix does only determine the ratio
/// of aperture to focal length, so there is a choice which defaults
/// to 50mm (or more accurately, 50 tenths of a world unit).
GF_API void SetFromViewAndProjectionMatrix(
const GfMatrix4d &viewMatrix, const GfMatrix4d &projMatix,
const float focalLength = 50.0);
/// @}
/// Sets the clipping range in world units.
GF_API void SetClippingRange(const GfRange1f &val);
/// Sets additional arbitrarily oriented clipping planes.
/// A vector (a,b,c,d) encodes a clipping plane that clips off points
/// (x,y,z) with
///
/// a * x + b * y + c * z + d * 1 < 0
///
/// where (x,y,z) are the coordinates in the camera's space.
GF_API void SetClippingPlanes(const std::vector<GfVec4f> &val);
/// Sets the lens aperture, unitless.
GF_API void SetFStop(const float val);
/// Sets the focus distance in world units.
GF_API void SetFocusDistance(const float val);
/// Returns the transform of the filmback in world space. This is
/// exactly the transform specified via SetTransform().
GF_API GfMatrix4d GetTransform() const;
/// Returns the projection type.
GF_API Projection GetProjection() const;
/// Returns the width of the projector aperture in tenths of a world unit
/// (e.g., mm if the world unit is assumed to be cm).
GF_API float GetHorizontalAperture() const;
/// Returns the height of the projector aperture in tenths of a world unit
/// (e.g., mm if the world unit is assumed to be cm).
GF_API float GetVerticalAperture() const;
/// Returns the horizontal offset of the projector aperture in tenths of a
/// world unit (e.g., mm if the world unit is assumed to be cm).
/// In particular, an offset is necessary when writing out a stereo camera
/// with finite convergence distance as two cameras.
GF_API float GetHorizontalApertureOffset() const;
/// Returns the vertical offset of the projector aperture in tenths of a
/// world unit (e.g., mm if the world unit is assumed to be cm).
GF_API float GetVerticalApertureOffset() const;
/// Returns the projector aperture aspect ratio.
GF_API float GetAspectRatio() const;
/// Returns the focal length in tenths of a world unit (e.g., mm if the
/// world unit is assumed to be cm).
GF_API float GetFocalLength() const;
/// Returns the horizontal or vertical field of view in degrees.
GF_API float GetFieldOfView(FOVDirection direction) const;
/// Returns the clipping range in world units.
GF_API GfRange1f GetClippingRange() const;
/// Returns additional clipping planes.
GF_API const std::vector<GfVec4f> &GetClippingPlanes() const;
/// Returns the computed, world-space camera frustum. The frustum
/// will always be that of a Y-up, -Z-looking camera.
GF_API GfFrustum GetFrustum() const;
/// Returns the lens aperture.
GF_API float GetFStop() const;
/// Returns the focus distance in world units.
GF_API float GetFocusDistance() const;
/// Equality operator. true iff all parts match.
GF_API bool operator==(const GfCamera& other) const;
// Inequality operator. true iff not equality.
GF_API bool operator!=(const GfCamera& other) const;
private:
// frustum
GfMatrix4d _transform;
Projection _projection;
float _horizontalAperture;
float _verticalAperture;
float _horizontalApertureOffset;
float _verticalApertureOffset;
float _focalLength;
GfRange1f _clippingRange;
std::vector<GfVec4f> _clippingPlanes;
// focus
float _fStop;
float _focusDistance;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_CAMERA_H
+80
View File
@@ -0,0 +1,80 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_GF_DECLARE_H
#define PXR_BASE_GF_DECLARE_H
#include "pxr/pxr.h"
/// \file gf/declare.h
/// Declares Gf types.
///
/// This file provides forward declarations for Gf types.
PXR_NAMESPACE_OPEN_SCOPE
class GfBBox3d;
class GfFrustum;
class GfInterval;
class GfMultiInterval;
class GfLine;
class GfLineSeg;
class GfPlane;
class GfQuatd;
class GfQuatf;
class GfQuath;
class GfQuaternion;
class GfRay;
class GfRect2i;
class GfRect2i;
class GfRotation;
class GfSize2;
class GfSize3;
class GfMatrix2d;
class GfMatrix2f;
class GfMatrix3d;
class GfMatrix3f;
class GfMatrix4d;
class GfMatrix4f;
class GfRange1d;
class GfRange1f;
class GfRange2d;
class GfRange2f;
class GfRange3d;
class GfRange3f;
class GfVec2d;
class GfVec2f;
class GfVec2h;
class GfVec2i;
class GfVec3d;
class GfVec3f;
class GfVec3h;
class GfVec3i;
class GfVec4d;
class GfVec4f;
class GfVec4h;
class GfVec4i;
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_DECLARE_H
+690
View File
@@ -0,0 +1,690 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_GF_FRUSTUM_H
#define PXR_BASE_GF_FRUSTUM_H
/// \file gf/frustum.h
/// \ingroup group_gf_BasicGeometry
#include "pxr/pxr.h"
#include "pxr/base/gf/bbox3d.h"
#include "pxr/base/gf/matrix4d.h"
#include "pxr/base/gf/plane.h"
#include "pxr/base/gf/ray.h"
#include "pxr/base/gf/range1d.h"
#include "pxr/base/gf/range2d.h"
#include "pxr/base/gf/rotation.h"
#include "pxr/base/gf/vec2d.h"
#include "pxr/base/gf/vec3d.h"
#include "pxr/base/gf/api.h"
#include <boost/functional/hash.hpp>
#include <array>
#include <atomic>
#include <iosfwd>
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
/// \class GfFrustum
/// \ingroup group_gf_BasicGeometry
///
/// Basic type: View frustum.
///
/// This class represents a viewing frustum in three dimensional eye space. It
/// may represent either a parallel (orthographic) or perspective projection.
/// One can think of the frustum as being defined by 6 boundary planes.
///
/// The frustum is specified using these parameters:
/// \li The \em position of the viewpoint.
/// \li The \em rotation applied to the default view frame, which is
/// looking along the -z axis with the +y axis as the "up"
/// direction.
/// \li The 2D \em window on the reference plane that defines the left,
/// right, top, and bottom planes of the viewing frustum, as
/// described below.
/// \li The distances to the \em near and \em far planes.
/// \li The \em projection \em type
/// \li The view distance.
///
/// The window and near/far parameters combine to define the view frustum as
/// follows. Transform the -z axis and the +y axis by the frustum rotation to
/// get the world-space \em view \em direction and \em up \em direction. Now
/// consider the \em reference \em plane that is perpendicular to the view
/// direction, a distance of referencePlaneDepth from the viewpoint, and whose
/// y axis corresponds to the up direction. The window rectangle is specified
/// in a 2D coordinate system embedded in this plane. The origin of the
/// coordinate system is the point at which the view direction vector
/// intersects the plane. Therefore, the point (0,1) in this plane is found by
/// moving 1 unit along the up direction vector in this plane. The vector from
/// the viewpoint to the resulting point will form a 45-degree angle with the
/// view direction.
///
/// The view distance is only useful for interactive applications. It can be
/// used to compute a look at point which is useful when rotating around an
/// object of interest.
///
class GfFrustum {
public:
/// This enum is used to determine the type of projection represented by a
/// frustum.
enum ProjectionType {
Orthographic, ///< Orthographic projection
Perspective, ///< Perspective projection
};
/// This constructor creates an instance with default viewing parameters:
/// \li The position is the origin.
/// \li The rotation is the identity rotation. (The view is along
/// the -z axis, with the +y axis as "up").
/// \li The window is -1 to +1 in both dimensions.
/// \li The near/far interval is (1, 10).
/// \li The view distance is 5.0.
/// \li The projection type is \c GfFrustum::Perspective.
GF_API GfFrustum();
/// Copy constructor.
GfFrustum(GfFrustum const &o)
: _position(o._position)
, _rotation(o._rotation)
, _window(o._window)
, _nearFar(o._nearFar)
, _viewDistance(o._viewDistance)
, _projectionType(o._projectionType)
, _planes(nullptr) {
if (auto *planes = o._planes.load()) {
_planes = new std::array<GfPlane, 6>(*planes);
}
}
/// Move constructor.
GfFrustum(GfFrustum &&o) noexcept
: _position(o._position)
, _rotation(o._rotation)
, _window(o._window)
, _nearFar(o._nearFar)
, _viewDistance(o._viewDistance)
, _projectionType(o._projectionType)
, _planes(nullptr) {
if (auto *planes =
o._planes.exchange(nullptr, std::memory_order_relaxed)) {
_planes = planes;
}
}
/// This constructor creates an instance with the given viewing
/// parameters.
GF_API GfFrustum(const GfVec3d &position, const GfRotation &rotation,
const GfRange2d &window, const GfRange1d &nearFar,
GfFrustum::ProjectionType projectionType,
double viewDistance = 5.0);
/// This constructor creates an instance from a camera matrix (always of a
/// y-Up camera, also see SetPositionAndRotationFromMatrix) and the given
/// viewing parameters.
GF_API GfFrustum(const GfMatrix4d &camToWorldXf,
const GfRange2d &window, const GfRange1d &nearFar,
GfFrustum::ProjectionType projectionType,
double viewDistance = 5.0);
/// Copy assignment.
GfFrustum &operator=(GfFrustum const &o) noexcept {
if (this == &o) {
return *this;
}
_position = o._position;
_rotation = o._rotation;
_window = o._window;
_nearFar = o._nearFar;
_viewDistance = o._viewDistance;
_projectionType = o._projectionType;
delete _planes.load(std::memory_order_relaxed);
if (auto *planes = o._planes.load(std::memory_order_relaxed)) {
_planes.store(new std::array<GfPlane, 6>(*planes),
std::memory_order_relaxed);
}
else {
_planes.store(nullptr, std::memory_order_relaxed);
}
return *this;
}
/// Move assignment.
GfFrustum &operator=(GfFrustum &&o) noexcept {
if (this == &o) {
return *this;
}
_position = o._position;
_rotation = o._rotation;
_window = o._window;
_nearFar = o._nearFar;
_viewDistance = o._viewDistance;
_projectionType = o._projectionType;
delete _planes.load(std::memory_order_relaxed);
_planes.store(o._planes.load(std::memory_order_relaxed),
std::memory_order_relaxed);
o._planes.store(nullptr, std::memory_order_relaxed);
return *this;
}
friend inline size_t hash_value(const GfFrustum &f) {
size_t h = 0;
boost::hash_combine(h, f._position);
boost::hash_combine(h, f._rotation);
boost::hash_combine(h, f._window);
boost::hash_combine(h, f._nearFar);
boost::hash_combine(h, f._viewDistance);
boost::hash_combine(h, f._projectionType);
return h;
}
// Equality operator. true iff all parts match.
bool operator ==(const GfFrustum& f) const {
if (_position != f._position) return false;
if (_rotation != f._rotation) return false;
if (_window != f._window) return false;
if (_nearFar != f._nearFar) return false;
if (_viewDistance != f._viewDistance) return false;
if (_projectionType != f._projectionType) return false;
return true;
}
// Inequality operator. true iff not equality.
bool operator !=(const GfFrustum& f) const {
return !(*this == f);
}
/// Destructor.
GF_API ~GfFrustum();
/// \name Value setting and access
/// The methods in this group set and access the values that are used to
/// define a frustum.
///@{
/// Sets the position of the frustum in world space.
void SetPosition(const GfVec3d &position) {
_position = position;
_DirtyFrustumPlanes();
}
/// Returns the position of the frustum in world space.
const GfVec3d & GetPosition() const {
return _position;
}
/// Sets the orientation of the frustum in world space as a rotation to
/// apply to the default frame: looking along the -z axis with the +y axis
/// as "up".
void SetRotation(const GfRotation &rotation) {
_rotation = rotation;
_DirtyFrustumPlanes();
}
/// Returns the orientation of the frustum in world space as a rotation to
/// apply to the -z axis.
const GfRotation & GetRotation() const {
return _rotation;
}
/// Sets the position and rotation of the frustum from a camera matrix
/// (always from a y-Up camera). The resulting frustum's transform will
/// always represent a right-handed and orthonormal coordinate sytem
/// (scale, shear, and projection are removed from the given \p
/// camToWorldXf).
GF_API void SetPositionAndRotationFromMatrix(const GfMatrix4d &camToWorldXf);
/// Sets the window rectangle in the reference plane that defines the
/// left, right, top, and bottom planes of the frustum.
void SetWindow(const GfRange2d &window) {
_window = window;
_DirtyFrustumPlanes();
}
/// Returns the window rectangle in the reference plane.
const GfRange2d & GetWindow() const {
return _window;
}
/// Returns the depth of the reference plane.
static double GetReferencePlaneDepth() {
return 1.0;
}
/// Sets the near/far interval.
void SetNearFar(const GfRange1d &nearFar) {
_nearFar = nearFar;
_DirtyFrustumPlanes();
}
/// Returns the near/far interval.
const GfRange1d & GetNearFar() const {
return _nearFar;
}
/// Sets the view distance.
void SetViewDistance(double viewDistance) {
_viewDistance = viewDistance;
}
/// Returns the view distance.
double GetViewDistance() const {
return _viewDistance;
}
/// Sets the projection type.
void SetProjectionType(GfFrustum::ProjectionType projectionType) {
_projectionType = projectionType;
_DirtyFrustumPlanes();
}
/// Returns the projection type.
GfFrustum::ProjectionType GetProjectionType() const {
return _projectionType;
}
///@}
/// \name Convenience methods
///
/// The methods in this group allow the frustum's data to be accessed and
/// modified in terms of different representations that may be more
/// convenient for certain applications.
///
///@{
/// Sets up the frustum in a manner similar to \c gluPerspective().
///
/// It sets the projection type to \c GfFrustum::Perspective and sets the
/// window specification so that the resulting symmetric frustum encloses
/// an angle of \p fieldOfViewHeight degrees in the vertical direction,
/// with \p aspectRatio used to figure the angle in the horizontal
/// direction. The near and far distances are specified as well. The
/// window coordinates are computed as:
/// \code
/// top = tan(fieldOfViewHeight / 2)
/// bottom = -top
/// right = top * aspectRatio
/// left = -right
/// near = nearDistance
/// far = farDistance
/// \endcode
///
GF_API void SetPerspective(double fieldOfViewHeight,
double aspectRatio,
double nearDistance, double farDistance);
/// Sets up the frustum in a manner similar to gluPerspective().
///
/// It sets the projection type to \c GfFrustum::Perspective and
/// sets the window specification so that:
///
/// If \a isFovVertical is true, the resulting symmetric frustum encloses
/// an angle of \p fieldOfView degrees in the vertical direction, with \p
/// aspectRatio used to figure the angle in the horizontal direction.
///
/// If \a isFovVertical is false, the resulting symmetric frustum encloses
/// an angle of \p fieldOfView degrees in the horizontal direction, with
/// \p aspectRatio used to figure the angle in the vertical direction.
///
/// The near and far distances are specified as well. The window
/// coordinates are computed as follows:
///
/// \li if isFovVertical:
/// \li top = tan(fieldOfView / 2)
/// \li right = top * aspectRatio
/// \li if NOT isFovVertical:
/// \li right = tan(fieldOfView / 2)
/// \li top = right / aspectRation
/// \li bottom = -top
/// \li left = -right
/// \li near = nearDistance
/// \li far = farDistance
///
GF_API void SetPerspective(double fieldOfView,
bool isFovVertical,
double aspectRatio,
double nearDistance, double farDistance);
/// Returns the current frustum in the format used by \c SetPerspective().
/// If the current frustum is not a perspective projection, this returns
/// \c false and leaves the parameters untouched.
GF_API bool GetPerspective(double *fieldOfViewHeight,
double *aspectRatio,
double *nearDistance,
double *farDistance) const;
/// Returns the current frustum in the format used by \c SetPerspective().
/// If the current frustum is not a perspective projection, this returns
/// \c false and leaves the parameters untouched.
GF_API bool GetPerspective(bool isFovVertical,
double *fieldOfView,
double *aspectRatio,
double *nearDistance,
double *farDistance) const;
/// Returns the horizontal or vertical fov of the frustum. The fov of the
/// frustum is not necessarily the same value as displayed in the viewer.
/// The displayed fov is a function of the focal length or FOV avar. The
/// frustum's fov may be different due to things like lens breathing.
///
/// If the frustum is not of type \c GfFrustum::Perspective, the returned
/// FOV will be 0.0.
///
/// \note The default value for \c isFovVertical is false so calling \c
/// GetFOV without an argument will return the horizontal field of view
/// which is compatible with menv2x's old GfFrustum::GetFOV routine.
GF_API double GetFOV(bool isFovVertical = false);
/// Sets up the frustum in a manner similar to \c glOrtho().
///
/// Sets the projection to \c GfFrustum::Orthographic and sets the window
/// and near/far specifications based on the given values.
GF_API
void SetOrthographic(double left, double right,
double bottom, double top,
double nearPlane, double farPlane);
/// Returns the current frustum in the format used by \c
/// SetOrthographic(). If the current frustum is not an orthographic
/// projection, this returns \c false and leaves the parameters untouched.
GF_API bool GetOrthographic(double *left, double *right,
double *bottom, double *top,
double *nearPlane, double *farPlane)
const;
/// Modifies the frustum to tightly enclose a sphere with the given center
/// and radius, using the current view direction. The planes of the
/// frustum are adjusted as necessary. The given amount of slack is added
/// to the sphere's radius is used around the sphere to avoid boundary
/// problems.
GF_API void FitToSphere(const GfVec3d &center,
double radius,
double slack = 0.0);
/// Transforms the frustum by the given matrix.
///
/// The transformation matrix is applied as follows: the position and the
/// direction vector are transformed with the given matrix. Then the
/// length of the new direction vector is used to rescale the near and far
/// plane and the view distance. Finally, the points that define the
/// reference plane are transformed by the matrix. This method assures
/// that the frustum will not be sheared or perspective-projected.
///
/// \note Note that this definition means that the transformed frustum
/// does not preserve scales very well. Do \em not use this function to
/// transform a frustum that is to be used for precise operations such as
/// intersection testing.
GF_API GfFrustum& Transform(const GfMatrix4d &matrix);
/// Returns the normalized world-space view direction vector, which is
/// computed by rotating the -z axis by the frustum's rotation.
GF_API GfVec3d ComputeViewDirection() const;
/// Returns the normalized world-space up vector, which is computed by
/// rotating the y axis by the frustum's rotation.
GF_API GfVec3d ComputeUpVector() const;
/// Computes the view frame defined by this frustum. The frame consists of
/// the view direction, up vector and side vector, as shown in this
/// diagram.
///
/// \code
/// up
/// ^ ^
/// | /
/// | / view
/// |/
/// +- - - - > side
/// \endcode
///
GF_API void ComputeViewFrame(GfVec3d *side,
GfVec3d *up,
GfVec3d *view) const;
/// Computes and returns the world-space look-at point from the eye point
/// (position), view direction (rotation), and view distance.
GF_API GfVec3d ComputeLookAtPoint() const;
/// Returns a matrix that represents the viewing transformation for this
/// frustum. That is, it returns the matrix that converts points from
/// world space to eye (frustum) space.
GF_API GfMatrix4d ComputeViewMatrix() const;
/// Returns a matrix that represents the inverse viewing transformation
/// for this frustum. That is, it returns the matrix that converts points
/// from eye (frustum) space to world space.
GF_API GfMatrix4d ComputeViewInverse() const;
/// Returns a GL-style projection matrix corresponding to the frustum's
/// projection.
GF_API GfMatrix4d ComputeProjectionMatrix() const;
/// Returns the aspect ratio of the frustum, defined as the width of the
/// window divided by the height. If the height is zero or negative, this
/// returns 0.
GF_API double ComputeAspectRatio() const;
/// Returns the world-space corners of the frustum as a vector of 8
/// points, ordered as:
/// \li Left bottom near
/// \li Right bottom near
/// \li Left top near
/// \li Right top near
/// \li Left bottom far
/// \li Right bottom far
/// \li Left top far
/// \li Right top far
GF_API
std::vector<GfVec3d> ComputeCorners() const;
/// Returns the world-space corners of the intersection of the frustum
/// with a plane parallel to the near/far plane at distance d from the
/// apex, ordered as:
/// \li Left bottom
/// \li Right bottom
/// \li Left top
/// \li Right top
/// In particular, it gives the partial result of ComputeCorners when given
/// near or far distance.
GF_API
std::vector<GfVec3d> ComputeCornersAtDistance(double d) const;
/// Returns a frustum that is a narrowed-down version of this frustum,
/// such that the frustum rectangle on the near plane encloses \p point
/// with at most \p halfSize[0] distance on the left and right and at most
/// \p halfSize[1] distance on the top and bottom. (If \p point is closer
/// than the half size to a side of the frustum, that side is left alone.
/// The point and sizes are in normalized 2D coordinates; they range from
/// (-1, -1) at the lower left corner of the near-plane window rectangle
/// to (1,1) at the upper right corner.
///
/// \p point is a 2d point expressed as a normalized window position.
///
/// This method is useful for computing a volume to use for interactive
/// picking.
GF_API GfFrustum ComputeNarrowedFrustum(const GfVec2d &point,
const GfVec2d &halfSize) const;
/// Returns a frustum that is a narrowed-down version of this frustum,
/// such that the frustum rectangle on the near plane encloses \p point
/// with at most \p halfSize[0] distance on the left and right and at most
/// \p halfSize[1] distance on the top and bottom. (If \p point is closer
/// than the half size to a side of the frustum, that side is left alone.
/// The point and sizes are in normalized 2D coordinates; they range from
/// (-1, -1) at the lower left corner of the near-plane window rectangle
/// to (1,1) at the upper right corner.
///
/// \p point is a 3d point expressed in world coordinates
///
/// This method is useful for computing a volume to use for interactive
/// picking.
GF_API GfFrustum ComputeNarrowedFrustum(const GfVec3d &worldPoint,
const GfVec2d &halfSize) const;
/// Builds and returns a \c GfRay that starts at the viewpoint and extends
/// through the given \a windowPos given in normalized coords (-1 to +1 in
/// both dimensions) window position.
///
/// Contrasted with ComputePickRay(), this method returns a ray whose
/// origin is the eyepoint, while that method returns a ray whose origin
/// is on the near plane.
GF_API GfRay ComputeRay(const GfVec2d &windowPos) const;
/// Builds and returns a \c GfRay that connects the viewpoint to the given
/// 3d point in worldspace.
///
/// Contrasted with ComputePickRay(), this method returns a ray whose
/// origin is the eyepoint, while that method returns a ray whose origin
/// is on the near plane.
GF_API GfRay ComputeRay(const GfVec3d &worldSpacePos) const;
/// Builds and returns a \c GfRay that can be used for picking at the
/// given normalized (-1 to +1 in both dimensions) window position.
///
/// Contrasted with ComputeRay(), that method returns a ray whose origin
/// is the eyepoint, while this method returns a ray whose origin is on
/// the near plane.
GF_API GfRay ComputePickRay(const GfVec2d &windowPos) const;
/// Builds and returns a \c GfRay that can be used for picking that
/// connects the viewpoint to the given 3d point in worldspace.
GF_API GfRay ComputePickRay(const GfVec3d &worldSpacePos) const;
///@}
/// \name Intersection methods
///
/// The methods in this group implement intersection operations
/// between this frustum and a given primitive.
///
///@{
/// Returns true if the given axis-aligned bbox is inside or intersecting
/// the frustum. Otherwise, it returns false. Useful when doing picking or
/// frustum culling.
GF_API bool Intersects(const GfBBox3d &bbox) const;
/// Returns true if the given point is inside or intersecting the frustum.
/// Otherwise, it returns false.
GF_API bool Intersects(const GfVec3d &point) const;
/// Returns \c true if the line segment formed by the given points is
/// inside or intersecting the frustum. Otherwise, it returns false.
GF_API bool Intersects(const GfVec3d &p0,
const GfVec3d &p1) const;
/// Returns \c true if the triangle formed by the given points is inside
/// or intersecting the frustum. Otherwise, it returns false.
GF_API bool Intersects(const GfVec3d &p0,
const GfVec3d &p1,
const GfVec3d &p2) const;
/// Returns \c true if the bbox volume intersects the view volume given by
/// the view-projection matrix, erring on the side of false positives for
/// efficiency.
///
/// This method is intended for cases where a GfFrustum is not available
/// or when the view-projection matrix yields a view volume that is not
/// expressable as a GfFrustum.
///
/// Because it errs on the side of false positives, it is suitable for
/// early-out tests such as draw or intersection culling.
///
GF_API static bool IntersectsViewVolume(const GfBBox3d &bbox,
const GfMatrix4d &vpMat);
///@}
private:
// Dirty the result of _CalculateFrustumPlanes.
GF_API void _DirtyFrustumPlanes();
// Calculates cached frustum planes used for intersection tests.
GF_API void _CalculateFrustumPlanes() const;
// Builds and returns a \c GfRay that can be used for picking. Given an
// eye position and direction in camera space, offsets the ray to emanate
// from the near plane, then transforms into worldspace
GF_API GfRay _ComputePickRayOffsetToNearPlane(
const GfVec3d &camSpaceFrom,
const GfVec3d &camSpaceDir) const;
// Returns a frustum that is a narrowed-down version of this frustum, such
// that the frustum rectangle on the near plane encloses \p point with at
// most \p halfSize[0] distance on the left and right and at most \p
// halfSize[1] distance on the top and bottom. (If \p point is closer than
// the half size to a side of the frustum, that side is left alone. The
// point and sizes are in normalized 2D coordinates; they range from (-1,
// -1) at the lower left corner of the near-plane window rectangle to
// (1,1) at the upper right corner.
//
// \p windowPoint is expressed in window coordinates
//
// This method is useful for computing a volume to use for interactive
// picking.
GfFrustum _ComputeNarrowedFrustumSub(const GfVec2d windowPoint,
const GfVec2d &halfSize) const;
bool _SegmentIntersects(GfVec3d const &p0, uint32_t p0Mask,
GfVec3d const &p1, uint32_t p1Mask) const;
// Position of the frustum in world space.
GfVec3d _position;
// Orientation of the frustum in world space as a rotation to apply to the
// -z axis.
GfRotation _rotation;
// Window rectangle in the image plane.
GfRange2d _window;
// Near/far interval.
GfRange1d _nearFar;
// View distance.
double _viewDistance;
// Projection type.
ProjectionType _projectionType;
// Cached planes.
// If null, the planes have not been calculated.
mutable std::atomic<std::array<GfPlane, 6> *> _planes;
};
/// Output a GfFrustum using the format [(position) (rotation) [window]
/// [nearFar] viewDistance type]
///
/// The "type" is "perspective", or "orthographic, depending on the
/// projection type of the frustum.
///
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream& out, const GfFrustum& f);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_FRUSTUM_H
+106
View File
@@ -0,0 +1,106 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_GF_GAMMA_H
#define PXR_BASE_GF_GAMMA_H
#include "pxr/pxr.h"
#include "pxr/base/gf/api.h"
/// \file gf/gamma.h
/// Utilities to map colors between gamma spaces.
PXR_NAMESPACE_OPEN_SCOPE
class GfVec3f;
class GfVec3d;
class GfVec4f;
class GfVec4d;
class GfVec3h;
class GfVec4h;
/// Return a new vector with each component of \p v raised to the power \p
/// gamma
GF_API
GfVec3f GfApplyGamma(const GfVec3f &v, double gamma);
/// Return a new vector with each component of \p v raised to the power \p
/// gamma
GF_API
GfVec3d GfApplyGamma(const GfVec3d &v, double gamma);
/// \copydoc GfApplyGamma(GfVec3d,double)
GF_API
GfVec3h GfApplyGamma(const GfVec3h &v, double gamma);
/// Return a new vector with the first three components of \p v raised to the
/// power \p gamma and the fourth component unchanged.
GF_API
GfVec4f GfApplyGamma(const GfVec4f &v, double gamma);
/// Return a new vector with the first three components of \p v raised to the
/// power \p gamma and the fourth component unchanged.
GF_API
GfVec4d GfApplyGamma(const GfVec4d &v, double gamma);
/// \copydoc GfApplyGamma(GfVec4h,double)
GF_API
GfVec4h GfApplyGamma(const GfVec4h &v, double gamma);
/// Return a new float raised to the power \p gamma
GF_API
float GfApplyGamma(const float &v, double gamma);
/// Return a new char raised to the power \p gamma
GF_API
unsigned char GfApplyGamma(const unsigned char &v, double gamma);
/// Return the system display gamma
GF_API
double GfGetDisplayGamma();
/// Given a vec, \p v, representing an energy-linear RGB(A) color, return a
/// vec of the same type converted to the system's display gamma.
GF_API GfVec3f GfConvertLinearToDisplay(const GfVec3f &v);
GF_API GfVec3d GfConvertLinearToDisplay(const GfVec3d &v);
GF_API GfVec3h GfConvertLinearToDisplay(const GfVec3h &v);
GF_API GfVec4f GfConvertLinearToDisplay(const GfVec4f &v);
GF_API GfVec4d GfConvertLinearToDisplay(const GfVec4d &v);
GF_API GfVec4h GfConvertLinearToDisplay(const GfVec4h &v);
GF_API float GfConvertLinearToDisplay(const float &v);
GF_API unsigned char GfConvertLinearToDisplay(const unsigned char &v);
/// Given a vec, \p v, representing an RGB(A) color in the system's display
/// gamma space, return an energy-linear vec of the same type.
GF_API GfVec3f GfConvertDisplayToLinear(const GfVec3f &v);
GF_API GfVec3d GfConvertDisplayToLinear(const GfVec3d &v);
GF_API GfVec3h GfConvertDisplayToLinear(const GfVec3h &v);
GF_API GfVec4f GfConvertDisplayToLinear(const GfVec4f &v);
GF_API GfVec4d GfConvertDisplayToLinear(const GfVec4d &v);
GF_API GfVec4h GfConvertDisplayToLinear(const GfVec4h &v);
GF_API float GfConvertDisplayToLinear(const float &v);
GF_API unsigned char GfConvertDisplayToLinear(const unsigned char &v);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_GAMMA_H
+60
View File
@@ -0,0 +1,60 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_GF_HALF_H
#define PXR_BASE_GF_HALF_H
/// \file gf/half.h
///
/// This header serves to simply bring in the half float datatype and
/// provide a hash_value function. For documentation, of the half type,
/// please see the half header in ilmbase_half.h.
#include "pxr/pxr.h"
#include "pxr/base/gf/ilmbase_half.h"
#include "pxr/base/gf/ilmbase_halfLimits.h"
#include "pxr/base/gf/traits.h"
#include <type_traits>
PXR_NAMESPACE_OPEN_SCOPE
/// A 16-bit floating point data type.
using GfHalf = pxr_half::half;
namespace pxr_half {
/// Overload hash_value for half.
template<typename Half>
inline
typename std::enable_if<std::is_same<Half, half>::value, size_t>::type
hash_value(const Half& h) { return h.bits(); }
}
template <>
struct GfIsFloatingPoint<GfHalf> :
public std::integral_constant<bool, true>{};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_HALF_H
+79
View File
@@ -0,0 +1,79 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_GF_HOMOGENEOUS_H
#define PXR_BASE_GF_HOMOGENEOUS_H
/// \file gf/homogeneous.h
/// \ingroup group_gf_LinearAlgebra
/// Utility functions for GfVec4f and GfVec4d as homogeneous vectors
#include "pxr/pxr.h"
#include "pxr/base/gf/vec3d.h"
#include "pxr/base/gf/vec3f.h"
#include "pxr/base/gf/vec4d.h"
#include "pxr/base/gf/vec4f.h"
#include "pxr/base/gf/api.h"
PXR_NAMESPACE_OPEN_SCOPE
/// Returns a vector which is \p v homogenized. If the fourth element of \p v
/// is 0, it is set to 1.
/// \ingroup group_gf_LinearAlgebra
GF_API
GfVec4f GfGetHomogenized(const GfVec4f &v);
/// Homogenizes \p a and \p b and then performs the cross product on the first
/// three elements of each. Returns the cross product as a homogenized
/// vector.
/// \ingroup group_gf_LinearAlgebra
GF_API
GfVec4f GfHomogeneousCross(const GfVec4f &a, const GfVec4f &b);
GF_API
GfVec4d GfGetHomogenized(const GfVec4d &v);
/// Homogenizes \p a and \p b and then performs the cross product on the first
/// three elements of each. Returns the cross product as a homogenized
/// vector.
/// \ingroup group_gf_LinearAlgebra
GF_API
GfVec4d GfHomogeneousCross(const GfVec4d &a, const GfVec4d &b);
/// Projects homogeneous \p v into Euclidean space and returns the result as a
/// Vec3f.
inline GfVec3f GfProject(const GfVec4f &v) {
float inv = (v[3] != 0.0f) ? 1.0f/v[3] : 1.0f;
return GfVec3f(inv * v[0], inv * v[1], inv * v[2]);
}
/// Projects homogeneous \p v into Euclidean space and returns the result as a
/// Vec3d.
inline GfVec3d GfProject(const GfVec4d &v) {
double inv = (v[3] != 0.0) ? 1.0/v[3] : 1.0;
return GfVec3d(inv * v[0], inv * v[1], inv * v[2]);
}
PXR_NAMESPACE_CLOSE_SCOPE
#endif /* PXR_BASE_GF_HOMOGENEOUS_H */
+759
View File
@@ -0,0 +1,759 @@
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
// Primary authors:
// Florian Kainz <kainz@ilm.com>
// Rod Bogart <rgb@ilm.com>
//---------------------------------------------------------------------------
//
// half -- a 16-bit floating point number class:
//
// Type half can represent positive and negative numbers whose
// magnitude is between roughly 6.1e-5 and 6.5e+4 with a relative
// error of 9.8e-4; numbers smaller than 6.1e-5 can be represented
// with an absolute error of 6.0e-8. All integers from -2048 to
// +2048 can be represented exactly.
//
// Type half behaves (almost) like the built-in C++ floating point
// types. In arithmetic expressions, half, float and double can be
// mixed freely. Here are a few examples:
//
// half a (3.5);
// float b (a + sqrt (a));
// a += b;
// b += a;
// b = a + 7;
//
// Conversions from half to float are lossless; all half numbers
// are exactly representable as floats.
//
// Conversions from float to half may not preserve a float's value
// exactly. If a float is not representable as a half, then the
// float value is rounded to the nearest representable half. If a
// float value is exactly in the middle between the two closest
// representable half values, then the float value is rounded to
// the closest half whose least significant bit is zero.
//
// Overflows during float-to-half conversions cause arithmetic
// exceptions. An overflow occurs when the float value to be
// converted is too large to be represented as a half, or if the
// float value is an infinity or a NAN.
//
// The implementation of type half makes the following assumptions
// about the implementation of the built-in C++ types:
//
// float is an IEEE 754 single-precision number
// sizeof (float) == 4
// sizeof (unsigned int) == sizeof (float)
// alignof (unsigned int) == alignof (float)
// sizeof (unsigned short) == 2
//
//---------------------------------------------------------------------------
#ifndef PXR_HALF_H
#define PXR_HALF_H
#include "pxr/pxr.h"
#include "pxr/base/gf/api.h"
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
namespace pxr_half {
class half
{
public:
//-------------
// Constructors
//-------------
half () = default; // no initialization
half (float f);
// rule of 5
~half () = default;
constexpr half (const half &) noexcept = default;
constexpr half (half &&) noexcept = default;
//--------------------
// Conversion to float
//--------------------
operator float () const;
//------------
// Unary minus
//------------
half operator - () const;
//-----------
// Assignment
//-----------
half & operator = (const half &h) = default;
half & operator = (half &&h) noexcept = default;
half & operator = (float f);
half & operator += (half h);
half & operator += (float f);
half & operator -= (half h);
half & operator -= (float f);
half & operator *= (half h);
half & operator *= (float f);
half & operator /= (half h);
half & operator /= (float f);
//---------------------------------------------------------
// Round to n-bit precision (n should be between 0 and 10).
// After rounding, the significand's 10-n least significant
// bits will be zero.
//---------------------------------------------------------
half round (unsigned int n) const;
//--------------------------------------------------------------------
// Classification:
//
// h.isFinite() returns true if h is a normalized number,
// a denormalized number or zero
//
// h.isNormalized() returns true if h is a normalized number
//
// h.isDenormalized() returns true if h is a denormalized number
//
// h.isZero() returns true if h is zero
//
// h.isNan() returns true if h is a NAN
//
// h.isInfinity() returns true if h is a positive
// or a negative infinity
//
// h.isNegative() returns true if the sign bit of h
// is set (negative)
//--------------------------------------------------------------------
bool isFinite () const;
bool isNormalized () const;
bool isDenormalized () const;
bool isZero () const;
bool isNan () const;
bool isInfinity () const;
bool isNegative () const;
//--------------------------------------------
// Special values
//
// posInf() returns +infinity
//
// negInf() returns -infinity
//
// qNan() returns a NAN with the bit
// pattern 0111111111111111
//
// sNan() returns a NAN with the bit
// pattern 0111110111111111
//--------------------------------------------
static half posInf ();
static half negInf ();
static half qNan ();
static half sNan ();
//--------------------------------------
// Access to the internal representation
//--------------------------------------
GF_API unsigned short bits () const;
GF_API void setBits (unsigned short bits);
public:
union uif
{
unsigned int i;
float f;
};
private:
GF_API static short convert (int i);
GF_API static float overflow ();
unsigned short _h;
GF_API static const uif _toFloat[1 << 16];
GF_API static const unsigned short _eLut[1 << 9];
};
//-----------
// Stream I/O
//-----------
GF_API std::ostream & operator << (std::ostream &os, half h);
GF_API std::istream & operator >> (std::istream &is, half &h);
//----------
// Debugging
//----------
GF_API void printBits (std::ostream &os, half h);
GF_API void printBits (std::ostream &os, float f);
GF_API void printBits (char c[19], half h);
GF_API void printBits (char c[35], float f);
//-------------------------------------------------------------------------
// Limits
//
// Visual C++ will complain if PXR_HALF_MIN, PXR_HALF_NRM_MIN etc. are not float
// constants, but at least one other compiler (gcc 2.96) produces incorrect
// results if they are.
//-------------------------------------------------------------------------
#if (defined _WIN32 || defined _WIN64) && defined _MSC_VER
#define PXR_HALF_MIN 5.96046448e-08f // Smallest positive half
#define PXR_HALF_NRM_MIN 6.10351562e-05f // Smallest positive normalized half
#define PXR_HALF_MAX 65504.0f // Largest positive half
#define PXR_HALF_EPSILON 0.00097656f // Smallest positive e for which
// half (1.0 + e) != half (1.0)
#else
#define PXR_HALF_MIN 5.96046448e-08 // Smallest positive half
#define PXR_HALF_NRM_MIN 6.10351562e-05 // Smallest positive normalized half
#define PXR_HALF_MAX 65504.0 // Largest positive half
#define PXR_HALF_EPSILON 0.00097656 // Smallest positive e for which
// half (1.0 + e) != half (1.0)
#endif
#define PXR_HALF_MANT_DIG 11 // Number of digits in mantissa
// (significand + hidden leading 1)
//
// floor( (PXR_HALF_MANT_DIG - 1) * log10(2) ) => 3.01... -> 3
#define PXR_HALF_DIG 3 // Number of base 10 digits that
// can be represented without change
// ceil(PXR_HALF_MANT_DIG * log10(2) + 1) => 4.31... -> 5
#define PXR_HALF_DECIMAL_DIG 5 // Number of base-10 digits that are
// necessary to uniquely represent all
// distinct values
#define PXR_HALF_RADIX 2 // Base of the exponent
#define PXR_HALF_MIN_EXP -13 // Minimum negative integer such that
// PXR_HALF_RADIX raised to the power of
// one less than that integer is a
// normalized half
#define PXR_HALF_MAX_EXP 16 // Maximum positive integer such that
// PXR_HALF_RADIX raised to the power of
// one less than that integer is a
// normalized half
#define PXR_HALF_MIN_10_EXP -4 // Minimum positive integer such
// that 10 raised to that power is
// a normalized half
#define PXR_HALF_MAX_10_EXP 4 // Maximum positive integer such
// that 10 raised to that power is
// a normalized half
//---------------------------------------------------------------------------
//
// Implementation --
//
// Representation of a float:
//
// We assume that a float, f, is an IEEE 754 single-precision
// floating point number, whose bits are arranged as follows:
//
// 31 (msb)
// |
// | 30 23
// | | |
// | | | 22 0 (lsb)
// | | | | |
// X XXXXXXXX XXXXXXXXXXXXXXXXXXXXXXX
//
// s e m
//
// S is the sign-bit, e is the exponent and m is the significand.
//
// If e is between 1 and 254, f is a normalized number:
//
// s e-127
// f = (-1) * 2 * 1.m
//
// If e is 0, and m is not zero, f is a denormalized number:
//
// s -126
// f = (-1) * 2 * 0.m
//
// If e and m are both zero, f is zero:
//
// f = 0.0
//
// If e is 255, f is an "infinity" or "not a number" (NAN),
// depending on whether m is zero or not.
//
// Examples:
//
// 0 00000000 00000000000000000000000 = 0.0
// 0 01111110 00000000000000000000000 = 0.5
// 0 01111111 00000000000000000000000 = 1.0
// 0 10000000 00000000000000000000000 = 2.0
// 0 10000000 10000000000000000000000 = 3.0
// 1 10000101 11110000010000000000000 = -124.0625
// 0 11111111 00000000000000000000000 = +infinity
// 1 11111111 00000000000000000000000 = -infinity
// 0 11111111 10000000000000000000000 = NAN
// 1 11111111 11111111111111111111111 = NAN
//
// Representation of a half:
//
// Here is the bit-layout for a half number, h:
//
// 15 (msb)
// |
// | 14 10
// | | |
// | | | 9 0 (lsb)
// | | | | |
// X XXXXX XXXXXXXXXX
//
// s e m
//
// S is the sign-bit, e is the exponent and m is the significand.
//
// If e is between 1 and 30, h is a normalized number:
//
// s e-15
// h = (-1) * 2 * 1.m
//
// If e is 0, and m is not zero, h is a denormalized number:
//
// S -14
// h = (-1) * 2 * 0.m
//
// If e and m are both zero, h is zero:
//
// h = 0.0
//
// If e is 31, h is an "infinity" or "not a number" (NAN),
// depending on whether m is zero or not.
//
// Examples:
//
// 0 00000 0000000000 = 0.0
// 0 01110 0000000000 = 0.5
// 0 01111 0000000000 = 1.0
// 0 10000 0000000000 = 2.0
// 0 10000 1000000000 = 3.0
// 1 10101 1111000001 = -124.0625
// 0 11111 0000000000 = +infinity
// 1 11111 0000000000 = -infinity
// 0 11111 1000000000 = NAN
// 1 11111 1111111111 = NAN
//
// Conversion:
//
// Converting from a float to a half requires some non-trivial bit
// manipulations. In some cases, this makes conversion relatively
// slow, but the most common case is accelerated via table lookups.
//
// Converting back from a half to a float is easier because we don't
// have to do any rounding. In addition, there are only 65536
// different half numbers; we can convert each of those numbers once
// and store the results in a table. Later, all conversions can be
// done using only simple table lookups.
//
//---------------------------------------------------------------------------
//----------------------------
// Half-from-float constructor
//----------------------------
inline
half::half (float f)
{
uif x;
x.f = f;
if (f == 0)
{
//
// Common special case - zero.
// Preserve the zero's sign bit.
//
_h = (x.i >> 16);
}
else
{
//
// We extract the combined sign and exponent, e, from our
// floating-point number, f. Then we convert e to the sign
// and exponent of the half number via a table lookup.
//
// For the most common case, where a normalized half is produced,
// the table lookup returns a non-zero value; in this case, all
// we have to do is round f's significand to 10 bits and combine
// the result with e.
//
// For all other cases (overflow, zeroes, denormalized numbers
// resulting from underflow, infinities and NANs), the table
// lookup returns zero, and we call a longer, non-inline function
// to do the float-to-half conversion.
//
int e = (x.i >> 23) & 0x000001ff;
e = _eLut[e];
if (e)
{
//
// Simple case - round the significand, m, to 10
// bits and combine it with the sign and exponent.
//
int m = x.i & 0x007fffff;
_h = e + ((m + 0x00000fff + ((m >> 13) & 1)) >> 13);
}
else
{
//
// Difficult case - call a function.
//
_h = convert (x.i);
}
}
}
//------------------------------------------
// Half-to-float conversion via table lookup
//------------------------------------------
inline
half::operator float () const
{
return _toFloat[_h].f;
}
//-------------------------
// Round to n-bit precision
//-------------------------
inline half
half::round (unsigned int n) const
{
//
// Parameter check.
//
if (n >= 10)
return *this;
//
// Disassemble h into the sign, s,
// and the combined exponent and significand, e.
//
unsigned short s = _h & 0x8000;
unsigned short e = _h & 0x7fff;
//
// Round the exponent and significand to the nearest value
// where ones occur only in the (10-n) most significant bits.
// Note that the exponent adjusts automatically if rounding
// up causes the significand to overflow.
//
e >>= 9 - n;
e += e & 1;
e <<= 9 - n;
//
// Check for exponent overflow.
//
if (e >= 0x7c00)
{
//
// Overflow occurred -- truncate instead of rounding.
//
e = _h;
e >>= 10 - n;
e <<= 10 - n;
}
//
// Put the original sign bit back.
//
half h;
h._h = s | e;
return h;
}
//-----------------------
// Other inline functions
//-----------------------
inline half
half::operator - () const
{
half h;
h._h = _h ^ 0x8000;
return h;
}
inline half &
half::operator = (float f)
{
*this = half (f);
return *this;
}
inline half &
half::operator += (half h)
{
*this = half (float (*this) + float (h));
return *this;
}
inline half &
half::operator += (float f)
{
*this = half (float (*this) + f);
return *this;
}
inline half &
half::operator -= (half h)
{
*this = half (float (*this) - float (h));
return *this;
}
inline half &
half::operator -= (float f)
{
*this = half (float (*this) - f);
return *this;
}
inline half &
half::operator *= (half h)
{
*this = half (float (*this) * float (h));
return *this;
}
inline half &
half::operator *= (float f)
{
*this = half (float (*this) * f);
return *this;
}
inline half &
half::operator /= (half h)
{
*this = half (float (*this) / float (h));
return *this;
}
inline half &
half::operator /= (float f)
{
*this = half (float (*this) / f);
return *this;
}
inline bool
half::isFinite () const
{
unsigned short e = (_h >> 10) & 0x001f;
return e < 31;
}
inline bool
half::isNormalized () const
{
unsigned short e = (_h >> 10) & 0x001f;
return e > 0 && e < 31;
}
inline bool
half::isDenormalized () const
{
unsigned short e = (_h >> 10) & 0x001f;
unsigned short m = _h & 0x3ff;
return e == 0 && m != 0;
}
inline bool
half::isZero () const
{
return (_h & 0x7fff) == 0;
}
inline bool
half::isNan () const
{
unsigned short e = (_h >> 10) & 0x001f;
unsigned short m = _h & 0x3ff;
return e == 31 && m != 0;
}
inline bool
half::isInfinity () const
{
unsigned short e = (_h >> 10) & 0x001f;
unsigned short m = _h & 0x3ff;
return e == 31 && m == 0;
}
inline bool
half::isNegative () const
{
return (_h & 0x8000) != 0;
}
inline half
half::posInf ()
{
half h;
h._h = 0x7c00;
return h;
}
inline half
half::negInf ()
{
half h;
h._h = 0xfc00;
return h;
}
inline half
half::qNan ()
{
half h;
h._h = 0x7fff;
return h;
}
inline half
half::sNan ()
{
half h;
h._h = 0x7dff;
return h;
}
inline unsigned short
half::bits () const
{
return _h;
}
inline void
half::setBits (unsigned short bits)
{
_h = bits;
}
} // namespace pxr_half
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+114
View File
@@ -0,0 +1,114 @@
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
// Primary authors:
// Florian Kainz <kainz@ilm.com>
// Rod Bogart <rgb@ilm.com>
#ifndef PXR_HALF_LIMITS_H
#define PXR_HALF_LIMITS_H
//------------------------------------------------------------------------
//
// C++ standard library-style numeric_limits for class half
//
//------------------------------------------------------------------------
#include <limits>
#include "pxr/base/gf/ilmbase_half.h"
namespace std {
template <>
class numeric_limits <PXR_NS::pxr_half::half>
{
private:
using half = PXR_NS::pxr_half::half;
public:
static const bool is_specialized = true;
static half min () throw () {return PXR_HALF_NRM_MIN;}
static half max () throw () {return PXR_HALF_MAX;}
static const int digits = PXR_HALF_MANT_DIG;
static const int digits10 = PXR_HALF_DIG;
static const bool is_signed = true;
static const bool is_integer = false;
static const bool is_exact = false;
static const int radix = PXR_HALF_RADIX;
static half epsilon () throw () {return PXR_HALF_EPSILON;}
static half round_error () throw () {return PXR_HALF_EPSILON / 2;}
static const int min_exponent = PXR_HALF_MIN_EXP;
static const int min_exponent10 = PXR_HALF_MIN_10_EXP;
static const int max_exponent = PXR_HALF_MAX_EXP;
static const int max_exponent10 = PXR_HALF_MAX_10_EXP;
static const bool has_infinity = true;
static const bool has_quiet_NaN = true;
static const bool has_signaling_NaN = true;
static const float_denorm_style has_denorm = denorm_present;
static const bool has_denorm_loss = false;
static half infinity () throw () {return half::posInf();}
static half quiet_NaN () throw () {return half::qNan();}
static half signaling_NaN () throw () {return half::sNan();}
static half denorm_min () throw () {return PXR_HALF_MIN;}
static const bool is_iec559 = false;
static const bool is_bounded = false;
static const bool is_modulo = false;
static const bool traps = true;
static const bool tinyness_before = false;
static const float_round_style round_style = round_to_nearest;
#if __cplusplus >= 201103L
// C++11 additions.
static constexpr int max_digits10 = PXR_HALF_DECIMAL_DIG;
static half lowest () {return -PXR_HALF_MAX;}
#endif
};
} // namespace std
#endif
+427
View File
@@ -0,0 +1,427 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_GF_INTERVAL_H
#define PXR_BASE_GF_INTERVAL_H
/// \file gf/interval.h
/// \ingroup group_gf_BasicMath
#include "pxr/pxr.h"
#include "pxr/base/gf/math.h"
#include "pxr/base/gf/api.h"
#include <boost/functional/hash.hpp>
#include <float.h>
#include <iosfwd>
#include <limits>
PXR_NAMESPACE_OPEN_SCOPE
/// \class GfInterval
/// \ingroup group_gf_BasicMath
///
/// A basic mathematical interval class.
///
/// Can represent intervals with either open or closed boundary
/// conditions.
///
class GfInterval
{
public:
/// \name Constructors
///@{
/// Construct an empty open interval, (0,0).
GfInterval() :
_min(0.0, false),
_max(0.0, false)
{}
/// Construct a closed interval representing the single point, as [val,val].
GfInterval(double val) :
_min(val, true),
_max(val, true)
{}
/// Construct an interval with the given arguments.
GfInterval(double min, double max,
bool minClosed=true, bool maxClosed=true) :
_min(min, minClosed),
_max(max, maxClosed)
{}
///@}
/// Equality operator.
bool operator==(const GfInterval &rhs) const {
return _min == rhs._min && _max == rhs._max;
}
/// Inequality operator.
bool operator!=(const GfInterval &rhs) const {
return !(*this == rhs);
}
/// Less-than operator.
bool operator<(const GfInterval &rhs) const {
// Compare min bound
if (_min != rhs._min)
return _min < rhs._min;
// Compare max bound
if (_max != rhs._max)
return _max < rhs._max;
// Equal
return false;
}
/// Hash value.
/// Just a basic hash function, not particularly high quality.
size_t Hash() const { return hash_value(*this); }
friend inline size_t hash_value(GfInterval const &i) {
size_t h = 0;
boost::hash_combine(h, i._min);
boost::hash_combine(h, i._max);
return h;
}
/// Minimum value
double GetMin() const { return _min.value; }
/// Maximum value
double GetMax() const { return _max.value; }
/// Set minimum value
void SetMin(double v) {
_min = _Bound(v, _min.closed);
}
/// Set minimum value and boundary condition
void SetMin(double v, bool minClosed ) {
_min = _Bound(v, minClosed);
}
/// Set maximum value
void SetMax(double v) {
_max = _Bound(v, _max.closed);
}
/// Set maximum value and boundary condition
void SetMax(double v, bool maxClosed ) {
_max = _Bound(v, maxClosed);
}
/// Minimum boundary condition
bool IsMinClosed() const { return _min.closed; }
/// Maximum boundary condition
bool IsMaxClosed() const { return _max.closed; }
/// Minimum boundary condition
bool IsMinOpen() const { return ! _min.closed; }
/// Maximum boundary condition
bool IsMaxOpen() const { return ! _max.closed; }
/// Returns true if the maximum value is finite.
bool IsMaxFinite() const {
return (_max.value != -std::numeric_limits<double>::infinity()
&& _max.value != std::numeric_limits<double>::infinity());
}
/// Returns true if the minimum value is finite.
bool IsMinFinite() const {
return (_min.value != -std::numeric_limits<double>::infinity()
&& _min.value != std::numeric_limits<double>::infinity());
}
/// Returns true if both the maximum and minimum value are finite.
bool IsFinite() const {
return IsMaxFinite() && IsMinFinite();
}
/// Return true iff the interval is empty.
bool IsEmpty() const {
return (_min.value > _max.value) ||
((_min.value == _max.value)
&& (! _min.closed || !_max.closed));
}
/// Width of the interval.
/// An empty interval has size 0.
double GetSize() const {
return GfMax( 0.0, _max.value - _min.value );
}
// For 2x compatibility
double Size() const { return GetSize(); }
/// Return true iff the value d is contained in the interval.
/// An empty interval contains no values.
bool Contains(double d) const {
return ((d > _min.value) || (d == _min.value && _min.closed))
&& ((d < _max.value) || (d == _max.value && _max.closed));
}
// For 2x compatibility
bool In(double d) const { return Contains(d); }
/// Return true iff the interval i is entirely contained in the interval.
/// An empty interval contains no intervals, not even other
/// empty intervals.
bool Contains(const GfInterval &i) const {
return (*this & i) == i;
}
/// Return true iff the given interval i intersects this interval.
bool Intersects(const GfInterval &i) const {
return !(*this & i).IsEmpty();
}
/// \name Math operations
///@{
/// Boolean intersection.
GfInterval & operator&=(const GfInterval &rhs) {
if (IsEmpty()) {
// No change
} else if (rhs.IsEmpty()) {
// Intersection is empty
*this = GfInterval();
} else {
// Intersect min edge
if (_min.value < rhs._min.value)
_min = rhs._min;
else if (_min.value == rhs._min.value)
_min.closed &= rhs._min.closed;
// Intersect max edge
if (_max.value > rhs._max.value)
_max = rhs._max;
else if (_max.value == rhs._max.value)
_max.closed &= rhs._max.closed;
}
return *this;
}
/// Returns the interval that bounds the union of this interval and rhs.
GfInterval & operator|=(const GfInterval &rhs) {
if (IsEmpty()) {
*this = rhs;
} else if (rhs.IsEmpty()) {
// No change
} else {
// Expand min edge
if (_min.value > rhs._min.value)
_min = rhs._min;
else if (_min.value == rhs._min.value)
_min.closed |= rhs._min.closed;
// Expand max edge
if (_max.value < rhs._max.value)
_max = rhs._max;
else if (_max.value == rhs._max.value)
_max.closed |= rhs._max.closed;
}
return *this;
}
/// Interval addition.
GfInterval & operator+=(const GfInterval &rhs) {
if (!rhs.IsEmpty()) {
_min.value += rhs._min.value;
_max.value += rhs._max.value;
_min.closed &= rhs._min.closed;
_max.closed &= rhs._max.closed;
}
return *this;
}
/// Interval subtraction.
GfInterval & operator-=(const GfInterval &rhs) {
return *this += -rhs;
}
/// Interval unary minus.
GfInterval operator-() const {
return GfInterval(-_max.value, -_min.value, _max.closed, _min.closed);
}
/// Interval multiplication.
GfInterval & operator*=(const GfInterval &rhs) {
const _Bound a = _min * rhs._min;
const _Bound b = _min * rhs._max;
const _Bound c = _max * rhs._min;
const _Bound d = _max * rhs._max;
_max = _Max( _Max(a,b), _Max(c,d) );
_min = _Min( _Min(a,b), _Min(c,d) );
return *this;
}
/// Greater than operator
bool operator>(const GfInterval& rhs) {
// Defined in terms of operator<()
return rhs < *this;
}
/// Less than or equal operator
bool operator<=(const GfInterval& rhs) {
// Defined in terms of operator<()
return !(rhs < *this);
}
/// Greater than or equal operator
bool operator>=(const GfInterval& rhs) {
// Defined in terms of operator<()
return !(*this < rhs);
}
/// Union operator
GfInterval operator|(const GfInterval& rhs) const {
// Defined in terms of operator |=()
GfInterval tmp(*this);
tmp |= rhs;
return tmp;
}
/// Intersection operator
GfInterval operator&(const GfInterval& rhs) const {
// Defined in terms of operator &=()
GfInterval tmp(*this);
tmp &= rhs;
return tmp;
}
/// Addition operator
GfInterval operator+(const GfInterval& rhs) const {
// Defined in terms of operator +=()
GfInterval tmp(*this);
tmp += rhs;
return tmp;
}
/// Subtraction operator
GfInterval operator-(const GfInterval& rhs) const {
// Defined in terms of operator -=()
GfInterval tmp(*this);
tmp -= rhs;
return tmp;
}
/// Multiplication operator
GfInterval operator*(const GfInterval& rhs) const {
// Defined in terms of operator *=()
GfInterval tmp(*this);
tmp *= rhs;
return tmp;
}
///@}
/// Returns the full interval (-inf, inf).
static GfInterval GetFullInterval() {
return GfInterval( -std::numeric_limits<double>::infinity(),
std::numeric_limits<double>::infinity(),
false, false );
}
private:
// Helper struct to represent interval boundaries.
struct _Bound {
// Boundary value.
double value;
// Boundary condition. The boundary value is included in interval
// only if the boundary is closed.
bool closed;
_Bound(double val, bool isClosed) :
value(val),
closed(isClosed)
{
// Closed boundaries on infinite values do not make sense so
// force the bound to be open
if (value == -std::numeric_limits<double>::infinity() ||
value == std::numeric_limits<double>::infinity()) {
closed = false;
}
}
bool operator==(const _Bound &rhs) const {
return value == rhs.value && closed == rhs.closed;
}
bool operator!=(const _Bound &rhs) const {
return !(*this == rhs);
}
bool operator<(const _Bound &rhs) const {
return value < rhs.value || (value == rhs.value && closed && !rhs.closed);
}
_Bound & operator=(const _Bound &rhs) {
value = rhs.value;
closed = rhs.closed;
return *this;
}
_Bound operator*(const _Bound &rhs) const {
return _Bound( value * rhs.value, closed & rhs.closed );
}
friend inline size_t hash_value(const _Bound &b) {
size_t h = 0;
boost::hash_combine(h, b.value);
boost::hash_combine(h, b.closed);
return h;
}
};
// Return the lesser minimum bound, handling boundary conditions.
inline static const _Bound &
_Min( const _Bound &a, const _Bound &b ) {
return (a.value < b.value
|| ((a.value == b.value) && a.closed && !b.closed)) ?
a : b;
}
// Return the greater maximum bound, handling boundary conditions.
inline static const _Bound &
_Max( const _Bound &a, const _Bound &b ) {
return (a.value < b.value
|| ((a.value == b.value) && !a.closed && b.closed)) ?
b : a;
}
/// Data
_Bound _min, _max;
};
/// Output a GfInterval using the format (x, y).
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream &operator<<(std::ostream&, const GfInterval&);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_INTERVAL_H
+41
View File
@@ -0,0 +1,41 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_GF_LIMITS_H
#define PXR_BASE_GF_LIMITS_H
/// \file gf/limits.h
/// \ingroup group_gf_BasicMath
/// Defines useful mathematical limits.
/// This constant is used to determine whether the length of a vector is too
/// small to handle accurately.
/// \ingroup group_gf_BasicMath
#define GF_MIN_VECTOR_LENGTH 1e-10
/// This constant is used to determine when a set of basis vectors is close to
/// orthogonal.
/// \ingroup group_gf_LinearAlgebra
#define GF_MIN_ORTHO_TOLERANCE 1e-6
#endif
+123
View File
@@ -0,0 +1,123 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_GF_LINE_H
#define PXR_BASE_GF_LINE_H
/// \file gf/line.h
/// \ingroup group_gf_BasicGeometry
#include "pxr/pxr.h"
#include "pxr/base/gf/vec3d.h"
#include <float.h>
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
/// \class GfLine
/// \ingroup group_gf_BasicGeometry
///
/// Basic type: 3D line
///
/// This class represents a three-dimensional line in space. Lines are
/// constructed from a point, \p p0, and a direction, dir. The direction is
/// normalized in the constructor.
///
/// The line is kept in a parametric represention, p = p0 + t * dir.
///
class GfLine {
public:
/// The default constructor leaves line parameters undefined.
GfLine() {
}
/// Construct a line from a point and a direction.
GfLine(const GfVec3d &p0, const GfVec3d &dir ) {
Set( p0, dir );
}
double Set(const GfVec3d &p0, const GfVec3d &dir ) {
_p0 = p0;
_dir = dir;
return _dir.Normalize();
}
/// Return the point on the line at \p ( p0 + t * dir ).
/// Remember dir has been normalized so t represents a unit distance.
GfVec3d GetPoint( double t ) const { return _p0 + _dir * t; }
/// Return the normalized direction of the line.
const GfVec3d &GetDirection() const { return _dir; }
/// Returns the point on the line that is closest to \p point. If \p t is
/// not \c NULL, it will be set to the parametric distance along the line
/// of the returned point.
GF_API
GfVec3d FindClosestPoint(const GfVec3d &point, double *t = NULL) const;
/// Component-wise equality test. The starting points and directions,
/// must match exactly for lines to be considered equal.
bool operator ==(const GfLine &l) const {
return _p0 == l._p0 && _dir == l._dir;
}
/// Component-wise inequality test. The starting points, and directions
/// must match exactly for lines to be considered equal.
bool operator !=(const GfLine &r) const {
return ! (*this == r);
}
private:
GF_API
friend bool GfFindClosestPoints( const GfLine &, const GfLine &,
GfVec3d *, GfVec3d *,
double *, double * );
// Parametric description:
// l(t) = _p0 + t * _length * _dir;
GfVec3d _p0;
GfVec3d _dir;
};
/// Computes the closets points between two lines.
///
/// The two points are returned in \p p1 and \p p2. The parametric distance
/// of each point on the lines is returned in \p t1 and \p t2.
///
/// This returns \c false if the lines were close enough to parallel that no
/// points could be computed; in this case, the other return values are
/// undefined.
GF_API
bool GfFindClosestPoints(const GfLine &l1, const GfLine &l2,
GfVec3d *p1 = nullptr, GfVec3d *p2 = nullptr,
double *t1 = nullptr, double *t2 = nullptr);
/// Output a GfLine.
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream &operator<<(std::ostream&, const GfLine&);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_LINE_H
+120
View File
@@ -0,0 +1,120 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_GF_LINE2D_H
#define PXR_BASE_GF_LINE2D_H
/// \file gf/line2d.h
/// \ingroup group_gf_BasicGeometry
#include "pxr/pxr.h"
#include "pxr/base/gf/vec2d.h"
#include "pxr/base/gf/api.h"
#include <float.h>
PXR_NAMESPACE_OPEN_SCOPE
/// \class GfLine2d
/// \ingroup group_gf_BasicGeometry
///
/// Basic type: 2D line
///
/// This class represents a two-dimensional line in space. Lines are
/// constructed from a point, \p p0, and a direction, dir. The direction is
/// normalized in the constructor.
///
/// The line is kept in a parametric represention, p = p0 + t * dir.
///
class GfLine2d {
public:
/// The default constructor leaves line parameters undefined.
GfLine2d() {
}
/// Construct a line from a point and a direction.
GfLine2d(const GfVec2d &p0, const GfVec2d &dir ) {
Set( p0, dir );
}
double Set(const GfVec2d &p0, const GfVec2d &dir ) {
_p0 = p0;
_dir = dir;
return _dir.Normalize();
}
/// Return the point on the line at \p ( p0 + t * dir ).
/// Remember dir has been normalized so t represents a unit distance.
GfVec2d GetPoint( double t ) const { return _p0 + _dir * t; }
/// Return the normalized direction of the line.
const GfVec2d &GetDirection() const { return _dir; }
/// Returns the point on the line that is closest to \p point. If \p t is
/// not \c NULL, it will be set to the parametric distance along the line
/// of the returned point.
GF_API
GfVec2d FindClosestPoint(const GfVec2d &point, double *t = NULL) const;
/// Component-wise equality test. The starting points and directions, must
/// match exactly for lines to be considered equal.
bool operator ==(const GfLine2d &l) const {
return _p0 == l._p0 && _dir == l._dir;
}
/// Component-wise inequality test. The starting points, and directions
/// must match exactly for lines to be considered equal.
bool operator !=(const GfLine2d &r) const {
return ! (*this == r);
}
private:
GF_API
friend bool GfFindClosestPoints( const GfLine2d &, const GfLine2d &,
GfVec2d *, GfVec2d *,
double *, double *);
// Parametric description:
// l(t) = _p0 + t * _length * _dir;
GfVec2d _p0;
GfVec2d _dir;
};
/// Computes the closets points between two lines.
///
/// The two points are returned in \p p1 and \p p2. The parametric distance
/// of each point on the lines is returned in \p t1 and \p t2.
///
/// This returns \c false if the lines were close enough to parallel that no
/// points could be computed; in this case, the other return values are
/// undefined.
GF_API
bool GfFindClosestPoints(const GfLine2d &l1, const GfLine2d &l2,
GfVec2d *p1 = nullptr, GfVec2d *p2 = nullptr,
double *t1 = nullptr, double *t2 = nullptr);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_LINE2D_H
+135
View File
@@ -0,0 +1,135 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_GF_LINE_SEG_H
#define PXR_BASE_GF_LINE_SEG_H
/// \file gf/lineSeg.h
/// \ingroup group_gf_BasicGeometry
#include "pxr/pxr.h"
#include "pxr/base/gf/line.h"
#include "pxr/base/gf/vec3d.h"
#include "pxr/base/gf/api.h"
#include <float.h>
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
/// \class GfLineSeg
/// \ingroup group_gf_BasicGeometry
///
/// Basic type: 3D line segment
///
/// This class represents a three-dimensional line segment in space.
///
class GfLineSeg {
public:
/// The default constructor leaves line parameters undefined.
GfLineSeg() {
}
/// Construct a line segment that spans two points.
GfLineSeg(const GfVec3d &p0, const GfVec3d &p1 ) {
_length = _line.Set( p0, p1 - p0 );
}
/// Return the point on the segment specified by the parameter t.
/// p = p0 + t * (p1 - p0)
GfVec3d GetPoint( double t ) const {return _line.GetPoint( t * _length );}
/// Return the normalized direction of the line.
const GfVec3d &GetDirection() const { return _line.GetDirection(); }
/// Return the length of the line
double GetLength() const { return _length; }
/// Returns the point on the line that is closest to \p point. If
/// \p t is not \c NULL, it will be set to the parametric
/// distance along the line of the closest point.
GF_API
GfVec3d FindClosestPoint(const GfVec3d &point, double *t = NULL) const;
/// Component-wise equality test. The starting points and directions,
/// must match exactly for lines to be considered equal.
bool operator ==(const GfLineSeg &l) const {
return (_line == l._line && _length == l._length);
}
/// Component-wise inequality test. The starting points,
/// and directions must match exactly for lines to be
/// considered equal.
bool operator !=(const GfLineSeg &r) const {
return ! (*this == r);
}
private:
GF_API
friend bool GfFindClosestPoints( const GfLine &, const GfLineSeg &,
GfVec3d *, GfVec3d *,
double *, double * );
GF_API
friend bool GfFindClosestPoints( const GfLineSeg &, const GfLineSeg &,
GfVec3d *, GfVec3d *,
double *, double * );
GfLine _line;
double _length; // distance from p0 to p1
};
/// Computes the closets points on \p line and \p seg.
///
/// The two points are returned in \p p1 and \p p2. The parametric distances
/// of \p p1 and \p p2 along the line and segment are returned in \p t1 and \p
/// t2.
///
/// This returns \c false if the lines were close enough to parallel that no
/// points could be computed; in this case, the other return values are
/// undefined.
GF_API
bool GfFindClosestPoints( const GfLine &line, const GfLineSeg &seg,
GfVec3d *p1 = nullptr, GfVec3d *p2 = nullptr,
double *t1 = nullptr, double *t2 = nullptr );
/// Computes the closets points on two line segments, \p seg1 and \p seg2. The
/// two points are returned in \p p1 and \p p2. The parametric distances of \p
/// p1 and \p p2 along the segments are returned in \p t1 and \p t2.
///
/// This returns \c false if the lines were close enough to parallel that no
/// points could be computed; in this case, the other return values are
/// undefined.
GF_API
bool GfFindClosestPoints( const GfLineSeg &seg1, const GfLineSeg &seg2,
GfVec3d *p1 = nullptr, GfVec3d *p2 = nullptr,
double *t1 = nullptr, double *t2 = nullptr );
/// Output a GfLineSeg.
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream &operator<<(std::ostream&, const GfLineSeg&);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_LINE_SEG_H
+131
View File
@@ -0,0 +1,131 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_GF_LINE_SEG2D_H
#define PXR_BASE_GF_LINE_SEG2D_H
/// \file gf/lineSeg2d.h
/// \ingroup group_gf_BasicGeometry
#include "pxr/pxr.h"
#include "pxr/base/gf/line2d.h"
#include "pxr/base/gf/vec2d.h"
#include "pxr/base/gf/api.h"
#include <float.h>
PXR_NAMESPACE_OPEN_SCOPE
/// \class GfLineSeg2d
/// \ingroup group_gf_BasicGeometry
///
/// Basic type: 2D line segment
///
/// This class represents a three-dimensional line segment in space.
///
class GfLineSeg2d {
public:
/// The default constructor leaves line parameters undefined.
GfLineSeg2d() {
}
/// Construct a line segment that spans two points.
GfLineSeg2d(const GfVec2d &p0, const GfVec2d &p1 ) {
_length = _line.Set( p0, p1 - p0 );
}
/// Return the point on the segment specified by the parameter t.
/// p = p0 + t * (p1 - p0)
GfVec2d GetPoint( double t ) const {return _line.GetPoint( t * _length );}
/// Return the normalized direction of the line.
const GfVec2d &GetDirection() const { return _line.GetDirection(); }
/// Return the length of the line
double GetLength() const { return _length; }
/// Returns the point on the line that is closest to \p point. If
/// \p t is not \c NULL, it will be set to the parametric
/// distance along the line of the closest point.
GF_API
GfVec2d FindClosestPoint(const GfVec2d &point, double *t = NULL) const;
/// Component-wise equality test. The starting points and directions,
/// must match exactly for lines to be considered equal.
bool operator ==(const GfLineSeg2d &l) const {
return (_line == l._line && _length == l._length);
}
/// Component-wise inequality test. The starting points,
/// and directions must match exactly for lines to be
/// considered equal.
bool operator !=(const GfLineSeg2d &r) const {
return ! (*this == r);
}
private:
GF_API
friend bool GfFindClosestPoints( const GfLine2d &, const GfLineSeg2d &,
GfVec2d *, GfVec2d *,
double *t1, double *t2 );
GF_API
friend bool GfFindClosestPoints( const GfLineSeg2d &, const GfLineSeg2d &,
GfVec2d *, GfVec2d *,
double *, double * );
GfLine2d _line;
double _length; // distance from p0 to p1
};
/// Computes the closets points on \p line and \p seg.
///
/// The two points are returned in \p p1 and \p p2. The parametric distances
/// of \p p1 and \p p2 along the line and segment are returned in \p t1 and \p
/// t2.
///
/// This returns \c false if the lines were close enough to parallel that no
/// points could be computed; in this case, the other return values are
/// undefined.
GF_API
bool GfFindClosestPoints( const GfLine2d &line, const GfLineSeg2d &seg,
GfVec2d *p1 = nullptr, GfVec2d *p2 = nullptr,
double *t1 = nullptr, double *t2 = nullptr );
/// Computes the closets points on two line segments, \p seg1 and \p seg2.
///
/// The two points are returned in \p p1 and \p p2. The parametric distances
/// of \p p1 and \p p2 along the segments are returned in \p t1 and \p t2.
///
/// This returns \c false if the lines were close enough to parallel that no
/// points could be computed; in this case, the other return values are
/// undefined.
GF_API
bool GfFindClosestPoints( const GfLineSeg2d &seg1, const GfLineSeg2d &seg2,
GfVec2d *p1 = nullptr, GfVec2d *p2 = nullptr,
double *t1 = nullptr, double *t2 = nullptr );
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_LINE_SEG2D_H
+271
View File
@@ -0,0 +1,271 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_GF_MATH_H
#define PXR_BASE_GF_MATH_H
/// \file gf/math.h
/// \ingroup group_gf_BasicMath
/// Assorted mathematical utility functions.
#include "pxr/pxr.h"
#include "pxr/base/arch/math.h"
#include "pxr/base/gf/api.h"
#include "pxr/base/gf/traits.h"
#include <type_traits>
PXR_NAMESPACE_OPEN_SCOPE
/// Returns true if \p a and \p b are with \p epsilon of each other.
/// \ingroup group_gf_BasicMath
inline bool GfIsClose(double a, double b, double epsilon) {
return fabs(a-b) < epsilon;
}
/// Converts an angle in radians to degrees.
/// \ingroup group_gf_BasicMath
inline double GfRadiansToDegrees(double radians) {
return radians * (180.0 / M_PI);
}
/// Converts an angle in degrees to radians.
/// \ingroup group_gf_BasicMath
inline double GfDegreesToRadians(double degrees) {
return degrees * (M_PI / 180.0);
}
/// Returns the inner product of \c x with itself: specifically, \c x*x.
/// Defined for \c int, \c float, \c double, and all \c GfVec types.
/// \ingroup group_gf_BasicMath
template <class T>
inline double GfSqr(const T& x) {
return x * x;
}
/// Return the signum of \p v (i.e. -1, 0, or 1).
///
/// The type \c T must implement the < and > operators; the function returns
/// zero only if value neither positive, nor negative.
///
/// \ingroup group_gf_BasicMath
template <typename T>
inline T
GfSgn(T v) {
return (v < 0) ? -1 : ((v > 0) ? 1 : 0);
}
/// Return sqrt(\p f).
/// \ingroup group_gf_BasicMath
inline double GfSqrt(double f) { return std::sqrt(f); }
/// Return sqrt(\p f).
/// \ingroup group_gf_BasicMath
inline float GfSqrt(float f) { return std::sqrt(f); }
/// Return exp(\p f).
/// \ingroup group_gf_BasicMath
inline double GfExp(double f) { return std::exp(f); }
/// Return exp(\p f).
/// \ingroup group_gf_BasicMath
inline float GfExp(float f) { return std::exp(f); }
/// Return log(\p f).
/// \ingroup group_gf_BasicMath
inline double GfLog(double f) { return std::log(f); }
/// Return log(\p f).
/// \ingroup group_gf_BasicMath
inline float GfLog(float f) { return std::log(f); }
/// Return floor(\p f).
/// \ingroup group_gf_BasicMath
inline double GfFloor(double f) { return std::floor(f); }
/// Return floor(\p f).
/// \ingroup group_gf_BasicMath
inline float GfFloor(float f) { return std::floor(f); }
/// Return ceil(\p f).
/// \ingroup group_gf_BasicMath
inline double GfCeil(double f) { return std::ceil(f); }
/// Return ceil(\p f).
/// \ingroup group_gf_BasicMath
inline float GfCeil(float f) { return std::ceil(f); }
/// Return abs(\p f).
/// \ingroup group_gf_BasicMath
inline double GfAbs(double f) { return std::fabs(f); }
/// Return abs(\p f).
/// \ingroup group_gf_BasicMath
inline float GfAbs(float f) { return std::fabs(f); }
/// Return round(\p f).
/// \ingroup group_gf_BasicMath
inline double GfRound(double f) { return std::rint(f); }
/// Return round(\p f).
/// \ingroup group_gf_BasicMath
inline float GfRound(float f) { return std::rint(f); }
/// Return pow(\p f, \p p).
/// \ingroup group_gf_BasicMath
inline double GfPow(double f, double p) { return std::pow(f, p); }
/// Return pow(\p f, \p p).
/// \ingroup group_gf_BasicMath
inline float GfPow(float f, float p) { return std::pow(f, p); }
/// Return sin(\p v).
/// \ingroup group_gf_BasicMath
inline double GfSin(double v) { return std::sin(v); }
/// Return sin(\p v).
/// \ingroup group_gf_BasicMath
inline float GfSin(float v) { return std::sin(v); }
/// Return cos(\p v).
/// \ingroup group_gf_BasicMath
inline double GfCos(double v) { return std::cos(v); }
/// Return cos(\p v).
/// \ingroup group_gf_BasicMath
inline float GfCos(float v) { return std::cos(v); }
/// Return sin(\p v) in \p s and cos(\p v) in \p c.
/// \ingroup group_gf_BasicMath
inline void GfSinCos(double v, double *s, double *c) { ArchSinCos(v, s, c); }
/// Return sin(\p v) in \p s and cos(\p v) in \p c.
/// \ingroup group_gf_BasicMath
inline void GfSinCos(float v, float *s, float *c) { ArchSinCosf(v, s, c); }
/// Return the resulting of clamping \p value to lie between
/// \p min and \p max. This function is also defined for GfVecs.
/// \ingroup group_gf_BasicMath
inline double GfClamp(double value, double min, double max) {
if (value < min) return min;
if (value > max) return max;
return value;
}
/// \overload
/// \ingroup group_gf_BasicMath
inline float GfClamp(float value, float min, float max) {
if (value < min) return min;
if (value > max) return max;
return value;
}
/// The mod function with "correct" behaviour for negative numbers.
///
/// If \p a = \c n \p b for some integer \p n, zero is returned.
/// Otherwise, for positive \p a, the value returned is \c fmod(a,b),
/// and for negative \p a, the value returned is \c fmod(a,b)+b.
///
/// \ingroup group_gf_BasicMath
GF_API
double GfMod(double a, double b);
/// \overload
// \ingroup group_gf_BasicMath
GF_API
float GfMod(float a, float b);
/// Linear interpolation function.
///
/// For any type that supports multiplication by a scalar and binary addition, returns
/// \code
/// (1-alpha) * a + alpha * b
/// \endcode
///
/// \ingroup group_gf_BasicMath
template <class T>
inline T GfLerp( double alpha, const T& a, const T& b) {
return (1-alpha)* a + alpha * b;
}
/// Returns the smallest of the given \c values.
/// \ingroup group_gf_BasicMath
template <class T>
inline T GfMin(T a1, T a2) {
return (a1 < a2 ? a1 : a2);
}
template <class T>
inline T GfMin(T a1, T a2, T a3) {
return GfMin(GfMin(a1, a2), a3);
}
template <class T>
inline T GfMin(T a1, T a2, T a3, T a4) {
return GfMin(GfMin(a1, a2, a3), a4);
}
template <class T>
inline T GfMin(T a1, T a2, T a3, T a4, T a5) {
return GfMin(GfMin(a1, a2, a3, a4), a5);
}
/// Returns the largest of the given \c values.
/// \ingroup group_gf_BasicMath
template <class T>
inline T GfMax(T a1, T a2) {
return (a1 < a2 ? a2 : a1);
}
template <class T>
inline T GfMax(T a1, T a2, T a3) {
return GfMax(GfMax(a1, a2), a3);
}
template <class T>
inline T GfMax(T a1, T a2, T a3, T a4) {
return GfMax(GfMax(a1, a2, a3), a4);
}
template <class T>
inline T GfMax(T a1, T a2, T a3, T a4, T a5) {
return GfMax(GfMax(a1, a2, a3, a4), a5);
}
/// Returns the dot (inner) product of two vectors.
/// For scalar types, this is just the regular product.
/// \ingroup group_gf_BasicMath
template <typename Left, typename Right,
std::enable_if_t<GfIsArithmetic<Left>::value &&
GfIsArithmetic<Right>::value, int> = 0>
inline decltype(std::declval<Left>() * std::declval<Right>())
GfDot(Left left, Right right) {
return left * right;
}
/// Returns component-wise multiplication of vectors.
/// For scalar types, this is just the regular product.
/// \ingroup group_gf_BasicMath
template <typename Left, typename Right,
std::enable_if_t<GfIsArithmetic<Left>::value &&
GfIsArithmetic<Right>::value, int> = 0>
inline decltype(std::declval<Left>() * std::declval<Right>())
GfCompMult(Left left, Right right) {
return left * right;
}
/// Returns component-wise quotient of vectors.
/// For scalar types, this is just the regular quotient.
/// \ingroup group_gf_BasicMath
template <typename Left, typename Right,
std::enable_if_t<GfIsArithmetic<Left>::value &&
GfIsArithmetic<Right>::value, int> = 0>
inline decltype(std::declval<Left>() / std::declval<Right>())
GfCompDiv(Left left, Right right) {
return left / right;
}
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_MATH_H
+382
View File
@@ -0,0 +1,382 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// matrix2.template.h file to make changes.
#ifndef PXR_BASE_GF_MATRIX2D_H
#define PXR_BASE_GF_MATRIX2D_H
/// \file gf/matrix2d.h
/// \ingroup group_gf_LinearAlgebra
#include "pxr/pxr.h"
#include "pxr/base/gf/api.h"
#include "pxr/base/gf/declare.h"
#include "pxr/base/gf/matrixData.h"
#include "pxr/base/gf/vec2d.h"
#include "pxr/base/gf/traits.h"
#include <boost/functional/hash.hpp>
#include <iosfwd>
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
template <>
struct GfIsGfMatrix<class GfMatrix2d> { static const bool value = true; };
class GfMatrix2d;
class GfMatrix2f;
/// \class GfMatrix2d
/// \ingroup group_gf_LinearAlgebra
///
/// Stores a 2x2 matrix of \c double elements. A basic type.
///
/// Matrices are defined to be in row-major order, so <c>matrix[i][j]</c>
/// indexes the element in the \e i th row and the \e j th column.
///
class GfMatrix2d
{
public:
typedef double ScalarType;
static const size_t numRows = 2;
static const size_t numColumns = 2;
/// Default constructor. Leaves the matrix component values undefined.
GfMatrix2d() = default;
/// Constructor. Initializes the matrix from 4 independent
/// \c double values, specified in row-major order. For example,
/// parameter \e m10 specifies the value in row 1 and column 0.
GfMatrix2d(double m00, double m01,
double m10, double m11) {
Set(m00, m01,
m10, m11);
}
/// Constructor. Initializes the matrix from a 2x2 array
/// of \c double values, specified in row-major order.
GfMatrix2d(const double m[2][2]) {
Set(m);
}
/// Constructor. Explicitly initializes the matrix to \e s times the
/// identity matrix.
explicit GfMatrix2d(double s) {
SetDiagonal(s);
}
/// This explicit constructor initializes the matrix to \p s times
/// the identity matrix.
explicit GfMatrix2d(int s) {
SetDiagonal(s);
}
/// Constructor. Explicitly initializes the matrix to diagonal form,
/// with the \e i th element on the diagonal set to <c>v[i]</c>.
explicit GfMatrix2d(const GfVec2d& v) {
SetDiagonal(v);
}
/// Constructor. Initialize the matrix from a vector of vectors of
/// double. The vector is expected to be 2x2. If it is
/// too big, only the first 2 rows and/or columns will be used.
/// If it is too small, uninitialized elements will be filled in with
/// the corresponding elements from an identity matrix.
///
GF_API
explicit GfMatrix2d(const std::vector< std::vector<double> >& v);
/// Constructor. Initialize the matrix from a vector of vectors of
/// float. The vector is expected to be 2x2. If it is
/// too big, only the first 2 rows and/or columns will be used.
/// If it is too small, uninitialized elements will be filled in with
/// the corresponding elements from an identity matrix.
///
GF_API
explicit GfMatrix2d(const std::vector< std::vector<float> >& v);
/// This explicit constructor converts a "float" matrix to a "double" matrix.
GF_API
explicit GfMatrix2d(const class GfMatrix2f& m);
/// Sets a row of the matrix from a Vec2.
void SetRow(int i, const GfVec2d & v) {
_mtx[i][0] = v[0];
_mtx[i][1] = v[1];
}
/// Sets a column of the matrix from a Vec2.
void SetColumn(int i, const GfVec2d & v) {
_mtx[0][i] = v[0];
_mtx[1][i] = v[1];
}
/// Gets a row of the matrix as a Vec2.
GfVec2d GetRow(int i) const {
return GfVec2d(_mtx[i][0], _mtx[i][1]);
}
/// Gets a column of the matrix as a Vec2.
GfVec2d GetColumn(int i) const {
return GfVec2d(_mtx[0][i], _mtx[1][i]);
}
/// Sets the matrix from 4 independent \c double values,
/// specified in row-major order. For example, parameter \e m10 specifies
/// the value in row 1 and column 0.
GfMatrix2d& Set(double m00, double m01,
double m10, double m11) {
_mtx[0][0] = m00; _mtx[0][1] = m01;
_mtx[1][0] = m10; _mtx[1][1] = m11;
return *this;
}
/// Sets the matrix from a 2x2 array of \c double
/// values, specified in row-major order.
GfMatrix2d& Set(const double m[2][2]) {
_mtx[0][0] = m[0][0];
_mtx[0][1] = m[0][1];
_mtx[1][0] = m[1][0];
_mtx[1][1] = m[1][1];
return *this;
}
/// Sets the matrix to the identity matrix.
GfMatrix2d& SetIdentity() {
return SetDiagonal(1);
}
/// Sets the matrix to zero.
GfMatrix2d& SetZero() {
return SetDiagonal(0);
}
/// Sets the matrix to \e s times the identity matrix.
GF_API
GfMatrix2d& SetDiagonal(double s);
/// Sets the matrix to have diagonal (<c>v[0], v[1]</c>).
GF_API
GfMatrix2d& SetDiagonal(const GfVec2d&);
/// Fills a 2x2 array of \c double values with the values in
/// the matrix, specified in row-major order.
GF_API
double* Get(double m[2][2]) const;
/// Returns raw access to components of matrix as an array of
/// \c double values. Components are in row-major order.
double* data() {
return _mtx.GetData();
}
/// Returns const raw access to components of matrix as an array of
/// \c double values. Components are in row-major order.
const double* data() const {
return _mtx.GetData();
}
/// Returns vector components as an array of \c double values.
double* GetArray() {
return _mtx.GetData();
}
/// Returns vector components as a const array of \c double values.
const double* GetArray() const {
return _mtx.GetData();
}
/// Accesses an indexed row \e i of the matrix as an array of 2 \c
/// double values so that standard indexing (such as <c>m[0][1]</c>)
/// works correctly.
double* operator [](int i) { return _mtx[i]; }
/// Accesses an indexed row \e i of the matrix as an array of 2 \c
/// double values so that standard indexing (such as <c>m[0][1]</c>)
/// works correctly.
const double* operator [](int i) const { return _mtx[i]; }
/// Hash.
friend inline size_t hash_value(GfMatrix2d const &m) {
int nElems = 2 * 2;
size_t h = 0;
const double *p = m.GetArray();
while (nElems--)
boost::hash_combine(h, *p++);
return h;
}
/// Tests for element-wise matrix equality. All elements must match
/// exactly for matrices to be considered equal.
GF_API
bool operator ==(const GfMatrix2d& m) const;
/// Tests for element-wise matrix equality. All elements must match
/// exactly for matrices to be considered equal.
GF_API
bool operator ==(const GfMatrix2f& m) const;
/// Tests for element-wise matrix inequality. All elements must match
/// exactly for matrices to be considered equal.
bool operator !=(const GfMatrix2d& m) const {
return !(*this == m);
}
/// Tests for element-wise matrix inequality. All elements must match
/// exactly for matrices to be considered equal.
bool operator !=(const GfMatrix2f& m) const {
return !(*this == m);
}
/// Returns the transpose of the matrix.
GF_API
GfMatrix2d GetTranspose() const;
/// Returns the inverse of the matrix, or FLT_MAX * SetIdentity() if the
/// matrix is singular. (FLT_MAX is the largest value a \c float can have,
/// as defined by the system.) The matrix is considered singular if the
/// determinant is less than or equal to the optional parameter \e eps. If
/// \e det is non-null, <c>*det</c> is set to the determinant.
GF_API
GfMatrix2d GetInverse(double* det = NULL, double eps = 0) const;
/// Returns the determinant of the matrix.
GF_API
double GetDeterminant() const;
/// Post-multiplies matrix \e m into this matrix.
GF_API
GfMatrix2d& operator *=(const GfMatrix2d& m);
/// Multiplies the matrix by a double.
GF_API
GfMatrix2d& operator *=(double);
/// Returns the product of a matrix and a double.
friend GfMatrix2d operator *(const GfMatrix2d& m1, double d)
{
GfMatrix2d m = m1;
return m *= d;
}
///
// Returns the product of a matrix and a double.
friend GfMatrix2d operator *(double d, const GfMatrix2d& m)
{
return m * d;
}
/// Adds matrix \e m to this matrix.
GF_API
GfMatrix2d& operator +=(const GfMatrix2d& m);
/// Subtracts matrix \e m from this matrix.
GF_API
GfMatrix2d& operator -=(const GfMatrix2d& m);
/// Returns the unary negation of matrix \e m.
GF_API
friend GfMatrix2d operator -(const GfMatrix2d& m);
/// Adds matrix \e m2 to \e m1
friend GfMatrix2d operator +(const GfMatrix2d& m1, const GfMatrix2d& m2)
{
GfMatrix2d tmp(m1);
tmp += m2;
return tmp;
}
/// Subtracts matrix \e m2 from \e m1.
friend GfMatrix2d operator -(const GfMatrix2d& m1, const GfMatrix2d& m2)
{
GfMatrix2d tmp(m1);
tmp -= m2;
return tmp;
}
/// Multiplies matrix \e m1 by \e m2.
friend GfMatrix2d operator *(const GfMatrix2d& m1, const GfMatrix2d& m2)
{
GfMatrix2d tmp(m1);
tmp *= m2;
return tmp;
}
/// Divides matrix \e m1 by \e m2 (that is, <c>m1 * inv(m2)</c>).
friend GfMatrix2d operator /(const GfMatrix2d& m1, const GfMatrix2d& m2)
{
return(m1 * m2.GetInverse());
}
/// Returns the product of a matrix \e m and a column vector \e vec.
friend inline GfVec2d operator *(const GfMatrix2d& m, const GfVec2d& vec) {
return GfVec2d(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[0][1],
vec[0] * m._mtx[1][0] + vec[1] * m._mtx[1][1]);
}
/// Returns the product of row vector \e vec and a matrix \e m.
friend inline GfVec2d operator *(const GfVec2d &vec, const GfMatrix2d& m) {
return GfVec2d(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[1][0],
vec[0] * m._mtx[0][1] + vec[1] * m._mtx[1][1]);
}
/// Returns the product of a matrix \e m and a column vector \e vec.
/// Note that the return type is a \c GfVec2f.
GF_API
friend GfVec2f operator *(const GfMatrix2d& m, const GfVec2f& vec);
/// Returns the product of row vector \e vec and a matrix \e m.
/// Note that the return type is a \c GfVec2f.
GF_API
friend GfVec2f operator *(const GfVec2f &vec, const GfMatrix2d& m);
private:
/// Matrix storage, in row-major order.
GfMatrixData<double, 2, 2> _mtx;
// Friend declarations
friend class GfMatrix2f;
};
/// Tests for equality within a given tolerance, returning \c true if the
/// difference between each component of the matrix is less than or equal
/// to \p tolerance, or false otherwise.
GF_API
bool GfIsClose(GfMatrix2d const &m1, GfMatrix2d const &m2, double tolerance);
/// Output a GfMatrix2d
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream &, GfMatrix2d const &);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_MATRIX2D_H
+372
View File
@@ -0,0 +1,372 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// matrix2.template.h file to make changes.
#ifndef PXR_BASE_GF_MATRIX2F_H
#define PXR_BASE_GF_MATRIX2F_H
/// \file gf/matrix2f.h
/// \ingroup group_gf_LinearAlgebra
#include "pxr/pxr.h"
#include "pxr/base/gf/api.h"
#include "pxr/base/gf/declare.h"
#include "pxr/base/gf/matrixData.h"
#include "pxr/base/gf/vec2f.h"
#include "pxr/base/gf/traits.h"
#include <boost/functional/hash.hpp>
#include <iosfwd>
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
template <>
struct GfIsGfMatrix<class GfMatrix2f> { static const bool value = true; };
class GfMatrix2d;
class GfMatrix2f;
/// \class GfMatrix2f
/// \ingroup group_gf_LinearAlgebra
///
/// Stores a 2x2 matrix of \c float elements. A basic type.
///
/// Matrices are defined to be in row-major order, so <c>matrix[i][j]</c>
/// indexes the element in the \e i th row and the \e j th column.
///
class GfMatrix2f
{
public:
typedef float ScalarType;
static const size_t numRows = 2;
static const size_t numColumns = 2;
/// Default constructor. Leaves the matrix component values undefined.
GfMatrix2f() = default;
/// Constructor. Initializes the matrix from 4 independent
/// \c float values, specified in row-major order. For example,
/// parameter \e m10 specifies the value in row 1 and column 0.
GfMatrix2f(float m00, float m01,
float m10, float m11) {
Set(m00, m01,
m10, m11);
}
/// Constructor. Initializes the matrix from a 2x2 array
/// of \c float values, specified in row-major order.
GfMatrix2f(const float m[2][2]) {
Set(m);
}
/// Constructor. Explicitly initializes the matrix to \e s times the
/// identity matrix.
explicit GfMatrix2f(float s) {
SetDiagonal(s);
}
/// This explicit constructor initializes the matrix to \p s times
/// the identity matrix.
explicit GfMatrix2f(int s) {
SetDiagonal(s);
}
/// Constructor. Explicitly initializes the matrix to diagonal form,
/// with the \e i th element on the diagonal set to <c>v[i]</c>.
explicit GfMatrix2f(const GfVec2f& v) {
SetDiagonal(v);
}
/// Constructor. Initialize the matrix from a vector of vectors of
/// double. The vector is expected to be 2x2. If it is
/// too big, only the first 2 rows and/or columns will be used.
/// If it is too small, uninitialized elements will be filled in with
/// the corresponding elements from an identity matrix.
///
GF_API
explicit GfMatrix2f(const std::vector< std::vector<double> >& v);
/// Constructor. Initialize the matrix from a vector of vectors of
/// float. The vector is expected to be 2x2. If it is
/// too big, only the first 2 rows and/or columns will be used.
/// If it is too small, uninitialized elements will be filled in with
/// the corresponding elements from an identity matrix.
///
GF_API
explicit GfMatrix2f(const std::vector< std::vector<float> >& v);
/// This explicit constructor converts a "double" matrix to a "float" matrix.
GF_API
explicit GfMatrix2f(const class GfMatrix2d& m);
/// Sets a row of the matrix from a Vec2.
void SetRow(int i, const GfVec2f & v) {
_mtx[i][0] = v[0];
_mtx[i][1] = v[1];
}
/// Sets a column of the matrix from a Vec2.
void SetColumn(int i, const GfVec2f & v) {
_mtx[0][i] = v[0];
_mtx[1][i] = v[1];
}
/// Gets a row of the matrix as a Vec2.
GfVec2f GetRow(int i) const {
return GfVec2f(_mtx[i][0], _mtx[i][1]);
}
/// Gets a column of the matrix as a Vec2.
GfVec2f GetColumn(int i) const {
return GfVec2f(_mtx[0][i], _mtx[1][i]);
}
/// Sets the matrix from 4 independent \c float values,
/// specified in row-major order. For example, parameter \e m10 specifies
/// the value in row 1 and column 0.
GfMatrix2f& Set(float m00, float m01,
float m10, float m11) {
_mtx[0][0] = m00; _mtx[0][1] = m01;
_mtx[1][0] = m10; _mtx[1][1] = m11;
return *this;
}
/// Sets the matrix from a 2x2 array of \c float
/// values, specified in row-major order.
GfMatrix2f& Set(const float m[2][2]) {
_mtx[0][0] = m[0][0];
_mtx[0][1] = m[0][1];
_mtx[1][0] = m[1][0];
_mtx[1][1] = m[1][1];
return *this;
}
/// Sets the matrix to the identity matrix.
GfMatrix2f& SetIdentity() {
return SetDiagonal(1);
}
/// Sets the matrix to zero.
GfMatrix2f& SetZero() {
return SetDiagonal(0);
}
/// Sets the matrix to \e s times the identity matrix.
GF_API
GfMatrix2f& SetDiagonal(float s);
/// Sets the matrix to have diagonal (<c>v[0], v[1]</c>).
GF_API
GfMatrix2f& SetDiagonal(const GfVec2f&);
/// Fills a 2x2 array of \c float values with the values in
/// the matrix, specified in row-major order.
GF_API
float* Get(float m[2][2]) const;
/// Returns raw access to components of matrix as an array of
/// \c float values. Components are in row-major order.
float* data() {
return _mtx.GetData();
}
/// Returns const raw access to components of matrix as an array of
/// \c float values. Components are in row-major order.
const float* data() const {
return _mtx.GetData();
}
/// Returns vector components as an array of \c float values.
float* GetArray() {
return _mtx.GetData();
}
/// Returns vector components as a const array of \c float values.
const float* GetArray() const {
return _mtx.GetData();
}
/// Accesses an indexed row \e i of the matrix as an array of 2 \c
/// float values so that standard indexing (such as <c>m[0][1]</c>)
/// works correctly.
float* operator [](int i) { return _mtx[i]; }
/// Accesses an indexed row \e i of the matrix as an array of 2 \c
/// float values so that standard indexing (such as <c>m[0][1]</c>)
/// works correctly.
const float* operator [](int i) const { return _mtx[i]; }
/// Hash.
friend inline size_t hash_value(GfMatrix2f const &m) {
int nElems = 2 * 2;
size_t h = 0;
const float *p = m.GetArray();
while (nElems--)
boost::hash_combine(h, *p++);
return h;
}
/// Tests for element-wise matrix equality. All elements must match
/// exactly for matrices to be considered equal.
GF_API
bool operator ==(const GfMatrix2d& m) const;
/// Tests for element-wise matrix equality. All elements must match
/// exactly for matrices to be considered equal.
GF_API
bool operator ==(const GfMatrix2f& m) const;
/// Tests for element-wise matrix inequality. All elements must match
/// exactly for matrices to be considered equal.
bool operator !=(const GfMatrix2d& m) const {
return !(*this == m);
}
/// Tests for element-wise matrix inequality. All elements must match
/// exactly for matrices to be considered equal.
bool operator !=(const GfMatrix2f& m) const {
return !(*this == m);
}
/// Returns the transpose of the matrix.
GF_API
GfMatrix2f GetTranspose() const;
/// Returns the inverse of the matrix, or FLT_MAX * SetIdentity() if the
/// matrix is singular. (FLT_MAX is the largest value a \c float can have,
/// as defined by the system.) The matrix is considered singular if the
/// determinant is less than or equal to the optional parameter \e eps. If
/// \e det is non-null, <c>*det</c> is set to the determinant.
GF_API
GfMatrix2f GetInverse(double* det = NULL, double eps = 0) const;
/// Returns the determinant of the matrix.
GF_API
double GetDeterminant() const;
/// Post-multiplies matrix \e m into this matrix.
GF_API
GfMatrix2f& operator *=(const GfMatrix2f& m);
/// Multiplies the matrix by a float.
GF_API
GfMatrix2f& operator *=(double);
/// Returns the product of a matrix and a float.
friend GfMatrix2f operator *(const GfMatrix2f& m1, double d)
{
GfMatrix2f m = m1;
return m *= d;
}
///
// Returns the product of a matrix and a float.
friend GfMatrix2f operator *(double d, const GfMatrix2f& m)
{
return m * d;
}
/// Adds matrix \e m to this matrix.
GF_API
GfMatrix2f& operator +=(const GfMatrix2f& m);
/// Subtracts matrix \e m from this matrix.
GF_API
GfMatrix2f& operator -=(const GfMatrix2f& m);
/// Returns the unary negation of matrix \e m.
GF_API
friend GfMatrix2f operator -(const GfMatrix2f& m);
/// Adds matrix \e m2 to \e m1
friend GfMatrix2f operator +(const GfMatrix2f& m1, const GfMatrix2f& m2)
{
GfMatrix2f tmp(m1);
tmp += m2;
return tmp;
}
/// Subtracts matrix \e m2 from \e m1.
friend GfMatrix2f operator -(const GfMatrix2f& m1, const GfMatrix2f& m2)
{
GfMatrix2f tmp(m1);
tmp -= m2;
return tmp;
}
/// Multiplies matrix \e m1 by \e m2.
friend GfMatrix2f operator *(const GfMatrix2f& m1, const GfMatrix2f& m2)
{
GfMatrix2f tmp(m1);
tmp *= m2;
return tmp;
}
/// Divides matrix \e m1 by \e m2 (that is, <c>m1 * inv(m2)</c>).
friend GfMatrix2f operator /(const GfMatrix2f& m1, const GfMatrix2f& m2)
{
return(m1 * m2.GetInverse());
}
/// Returns the product of a matrix \e m and a column vector \e vec.
friend inline GfVec2f operator *(const GfMatrix2f& m, const GfVec2f& vec) {
return GfVec2f(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[0][1],
vec[0] * m._mtx[1][0] + vec[1] * m._mtx[1][1]);
}
/// Returns the product of row vector \e vec and a matrix \e m.
friend inline GfVec2f operator *(const GfVec2f &vec, const GfMatrix2f& m) {
return GfVec2f(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[1][0],
vec[0] * m._mtx[0][1] + vec[1] * m._mtx[1][1]);
}
private:
/// Matrix storage, in row-major order.
GfMatrixData<float, 2, 2> _mtx;
// Friend declarations
friend class GfMatrix2d;
};
/// Tests for equality within a given tolerance, returning \c true if the
/// difference between each component of the matrix is less than or equal
/// to \p tolerance, or false otherwise.
GF_API
bool GfIsClose(GfMatrix2f const &m1, GfMatrix2f const &m2, double tolerance);
/// Output a GfMatrix2f
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream &, GfMatrix2f const &);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_MATRIX2F_H
+509
View File
@@ -0,0 +1,509 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// matrix3.template.h file to make changes.
#ifndef PXR_BASE_GF_MATRIX3D_H
#define PXR_BASE_GF_MATRIX3D_H
/// \file gf/matrix3d.h
/// \ingroup group_gf_LinearAlgebra
#include "pxr/pxr.h"
#include "pxr/base/gf/api.h"
#include "pxr/base/gf/declare.h"
#include "pxr/base/gf/matrixData.h"
#include "pxr/base/gf/vec3d.h"
#include "pxr/base/gf/traits.h"
#include <boost/functional/hash.hpp>
#include <iosfwd>
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
template <>
struct GfIsGfMatrix<class GfMatrix3d> { static const bool value = true; };
class GfMatrix3d;
class GfMatrix3f;
class GfRotation;
class GfQuaternion;
class GfQuatd;
/// \class GfMatrix3d
/// \ingroup group_gf_LinearAlgebra
///
/// Stores a 3x3 matrix of \c double elements. A basic type.
///
/// Matrices are defined to be in row-major order, so <c>matrix[i][j]</c>
/// indexes the element in the \e i th row and the \e j th column.
///
/// <h3>3D Transformations</h3>
///
/// Three methods, SetRotate(), SetScale(), and ExtractRotation(), interpret
/// a GfMatrix3d as a 3D transformation. By convention, vectors are treated
/// primarily as row vectors, implying the following:
///
/// \li Transformation matrices are organized to deal with row
/// vectors, not column vectors.
/// \li Each of the Set() methods in this class completely rewrites the
/// matrix; for example, SetRotate() yields a matrix
/// which does nothing but rotate.
/// \li When multiplying two transformation matrices, the matrix
/// on the left applies a more local transformation to a row
/// vector. For example, if R represents a rotation
/// matrix and S represents a scale matrix, the
/// product R*S will rotate a row vector, then scale
/// it.
class GfMatrix3d
{
public:
typedef double ScalarType;
static const size_t numRows = 3;
static const size_t numColumns = 3;
/// Default constructor. Leaves the matrix component values undefined.
GfMatrix3d() = default;
/// Constructor. Initializes the matrix from 9 independent
/// \c double values, specified in row-major order. For example,
/// parameter \e m10 specifies the value in row 1 and column 0.
GfMatrix3d(double m00, double m01, double m02,
double m10, double m11, double m12,
double m20, double m21, double m22) {
Set(m00, m01, m02,
m10, m11, m12,
m20, m21, m22);
}
/// Constructor. Initializes the matrix from a 3x3 array
/// of \c double values, specified in row-major order.
GfMatrix3d(const double m[3][3]) {
Set(m);
}
/// Constructor. Explicitly initializes the matrix to \e s times the
/// identity matrix.
explicit GfMatrix3d(double s) {
SetDiagonal(s);
}
/// This explicit constructor initializes the matrix to \p s times
/// the identity matrix.
explicit GfMatrix3d(int s) {
SetDiagonal(s);
}
/// Constructor. Explicitly initializes the matrix to diagonal form,
/// with the \e i th element on the diagonal set to <c>v[i]</c>.
explicit GfMatrix3d(const GfVec3d& v) {
SetDiagonal(v);
}
/// Constructor. Initialize the matrix from a vector of vectors of
/// double. The vector is expected to be 3x3. If it is
/// too big, only the first 3 rows and/or columns will be used.
/// If it is too small, uninitialized elements will be filled in with
/// the corresponding elements from an identity matrix.
///
GF_API
explicit GfMatrix3d(const std::vector< std::vector<double> >& v);
/// Constructor. Initialize the matrix from a vector of vectors of
/// float. The vector is expected to be 3x3. If it is
/// too big, only the first 3 rows and/or columns will be used.
/// If it is too small, uninitialized elements will be filled in with
/// the corresponding elements from an identity matrix.
///
GF_API
explicit GfMatrix3d(const std::vector< std::vector<float> >& v);
/// Constructor. Initialize matrix from rotation.
GF_API
GfMatrix3d(const GfRotation& rot);
/// Constructor. Initialize matrix from a quaternion.
GF_API
explicit GfMatrix3d(const GfQuatd& rot);
/// This explicit constructor converts a "float" matrix to a "double" matrix.
GF_API
explicit GfMatrix3d(const class GfMatrix3f& m);
/// Sets a row of the matrix from a Vec3.
void SetRow(int i, const GfVec3d & v) {
_mtx[i][0] = v[0];
_mtx[i][1] = v[1];
_mtx[i][2] = v[2];
}
/// Sets a column of the matrix from a Vec3.
void SetColumn(int i, const GfVec3d & v) {
_mtx[0][i] = v[0];
_mtx[1][i] = v[1];
_mtx[2][i] = v[2];
}
/// Gets a row of the matrix as a Vec3.
GfVec3d GetRow(int i) const {
return GfVec3d(_mtx[i][0], _mtx[i][1], _mtx[i][2]);
}
/// Gets a column of the matrix as a Vec3.
GfVec3d GetColumn(int i) const {
return GfVec3d(_mtx[0][i], _mtx[1][i], _mtx[2][i]);
}
/// Sets the matrix from 9 independent \c double values,
/// specified in row-major order. For example, parameter \e m10 specifies
/// the value in row 1 and column 0.
GfMatrix3d& Set(double m00, double m01, double m02,
double m10, double m11, double m12,
double m20, double m21, double m22) {
_mtx[0][0] = m00; _mtx[0][1] = m01; _mtx[0][2] = m02;
_mtx[1][0] = m10; _mtx[1][1] = m11; _mtx[1][2] = m12;
_mtx[2][0] = m20; _mtx[2][1] = m21; _mtx[2][2] = m22;
return *this;
}
/// Sets the matrix from a 3x3 array of \c double
/// values, specified in row-major order.
GfMatrix3d& Set(const double m[3][3]) {
_mtx[0][0] = m[0][0];
_mtx[0][1] = m[0][1];
_mtx[0][2] = m[0][2];
_mtx[1][0] = m[1][0];
_mtx[1][1] = m[1][1];
_mtx[1][2] = m[1][2];
_mtx[2][0] = m[2][0];
_mtx[2][1] = m[2][1];
_mtx[2][2] = m[2][2];
return *this;
}
/// Sets the matrix to the identity matrix.
GfMatrix3d& SetIdentity() {
return SetDiagonal(1);
}
/// Sets the matrix to zero.
GfMatrix3d& SetZero() {
return SetDiagonal(0);
}
/// Sets the matrix to \e s times the identity matrix.
GF_API
GfMatrix3d& SetDiagonal(double s);
/// Sets the matrix to have diagonal (<c>v[0], v[1], v[2]</c>).
GF_API
GfMatrix3d& SetDiagonal(const GfVec3d&);
/// Fills a 3x3 array of \c double values with the values in
/// the matrix, specified in row-major order.
GF_API
double* Get(double m[3][3]) const;
/// Returns raw access to components of matrix as an array of
/// \c double values. Components are in row-major order.
double* data() {
return _mtx.GetData();
}
/// Returns const raw access to components of matrix as an array of
/// \c double values. Components are in row-major order.
const double* data() const {
return _mtx.GetData();
}
/// Returns vector components as an array of \c double values.
double* GetArray() {
return _mtx.GetData();
}
/// Returns vector components as a const array of \c double values.
const double* GetArray() const {
return _mtx.GetData();
}
/// Accesses an indexed row \e i of the matrix as an array of 3 \c
/// double values so that standard indexing (such as <c>m[0][1]</c>)
/// works correctly.
double* operator [](int i) { return _mtx[i]; }
/// Accesses an indexed row \e i of the matrix as an array of 3 \c
/// double values so that standard indexing (such as <c>m[0][1]</c>)
/// works correctly.
const double* operator [](int i) const { return _mtx[i]; }
/// Hash.
friend inline size_t hash_value(GfMatrix3d const &m) {
int nElems = 3 * 3;
size_t h = 0;
const double *p = m.GetArray();
while (nElems--)
boost::hash_combine(h, *p++);
return h;
}
/// Tests for element-wise matrix equality. All elements must match
/// exactly for matrices to be considered equal.
GF_API
bool operator ==(const GfMatrix3d& m) const;
/// Tests for element-wise matrix equality. All elements must match
/// exactly for matrices to be considered equal.
GF_API
bool operator ==(const GfMatrix3f& m) const;
/// Tests for element-wise matrix inequality. All elements must match
/// exactly for matrices to be considered equal.
bool operator !=(const GfMatrix3d& m) const {
return !(*this == m);
}
/// Tests for element-wise matrix inequality. All elements must match
/// exactly for matrices to be considered equal.
bool operator !=(const GfMatrix3f& m) const {
return !(*this == m);
}
/// Returns the transpose of the matrix.
GF_API
GfMatrix3d GetTranspose() const;
/// Returns the inverse of the matrix, or FLT_MAX * SetIdentity() if the
/// matrix is singular. (FLT_MAX is the largest value a \c float can have,
/// as defined by the system.) The matrix is considered singular if the
/// determinant is less than or equal to the optional parameter \e eps. If
/// \e det is non-null, <c>*det</c> is set to the determinant.
GF_API
GfMatrix3d GetInverse(double* det = NULL, double eps = 0) const;
/// Returns the determinant of the matrix.
GF_API
double GetDeterminant() const;
/// Makes the matrix orthonormal in place. This is an iterative method that
/// is much more stable than the previous cross/cross method. If the
/// iterative method does not converge, a warning is issued.
///
/// Returns true if the iteration converged, false otherwise. Leaves any
/// translation part of the matrix unchanged. If \a issueWarning is true,
/// this method will issue a warning if the iteration does not converge,
/// otherwise it will be silent.
GF_API
bool Orthonormalize(bool issueWarning=true);
/// Returns an orthonormalized copy of the matrix.
GF_API
GfMatrix3d GetOrthonormalized(bool issueWarning=true) const;
/// Returns the sign of the determinant of the matrix, i.e. 1 for a
/// right-handed matrix, -1 for a left-handed matrix, and 0 for a
/// singular matrix.
GF_API
double GetHandedness() const;
/// Returns true if the vectors in the matrix form a right-handed
/// coordinate system.
bool IsRightHanded() const {
return GetHandedness() == 1.0;
}
/// Returns true if the vectors in matrix form a left-handed
/// coordinate system.
bool IsLeftHanded() const {
return GetHandedness() == -1.0;
}
/// Post-multiplies matrix \e m into this matrix.
GF_API
GfMatrix3d& operator *=(const GfMatrix3d& m);
/// Multiplies the matrix by a double.
GF_API
GfMatrix3d& operator *=(double);
/// Returns the product of a matrix and a double.
friend GfMatrix3d operator *(const GfMatrix3d& m1, double d)
{
GfMatrix3d m = m1;
return m *= d;
}
///
// Returns the product of a matrix and a double.
friend GfMatrix3d operator *(double d, const GfMatrix3d& m)
{
return m * d;
}
/// Adds matrix \e m to this matrix.
GF_API
GfMatrix3d& operator +=(const GfMatrix3d& m);
/// Subtracts matrix \e m from this matrix.
GF_API
GfMatrix3d& operator -=(const GfMatrix3d& m);
/// Returns the unary negation of matrix \e m.
GF_API
friend GfMatrix3d operator -(const GfMatrix3d& m);
/// Adds matrix \e m2 to \e m1
friend GfMatrix3d operator +(const GfMatrix3d& m1, const GfMatrix3d& m2)
{
GfMatrix3d tmp(m1);
tmp += m2;
return tmp;
}
/// Subtracts matrix \e m2 from \e m1.
friend GfMatrix3d operator -(const GfMatrix3d& m1, const GfMatrix3d& m2)
{
GfMatrix3d tmp(m1);
tmp -= m2;
return tmp;
}
/// Multiplies matrix \e m1 by \e m2.
friend GfMatrix3d operator *(const GfMatrix3d& m1, const GfMatrix3d& m2)
{
GfMatrix3d tmp(m1);
tmp *= m2;
return tmp;
}
/// Divides matrix \e m1 by \e m2 (that is, <c>m1 * inv(m2)</c>).
friend GfMatrix3d operator /(const GfMatrix3d& m1, const GfMatrix3d& m2)
{
return(m1 * m2.GetInverse());
}
/// Returns the product of a matrix \e m and a column vector \e vec.
friend inline GfVec3d operator *(const GfMatrix3d& m, const GfVec3d& vec) {
return GfVec3d(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[0][1] + vec[2] * m._mtx[0][2],
vec[0] * m._mtx[1][0] + vec[1] * m._mtx[1][1] + vec[2] * m._mtx[1][2],
vec[0] * m._mtx[2][0] + vec[1] * m._mtx[2][1] + vec[2] * m._mtx[2][2]);
}
/// Returns the product of row vector \e vec and a matrix \e m.
friend inline GfVec3d operator *(const GfVec3d &vec, const GfMatrix3d& m) {
return GfVec3d(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[1][0] + vec[2] * m._mtx[2][0],
vec[0] * m._mtx[0][1] + vec[1] * m._mtx[1][1] + vec[2] * m._mtx[2][1],
vec[0] * m._mtx[0][2] + vec[1] * m._mtx[1][2] + vec[2] * m._mtx[2][2]);
}
/// Returns the product of a matrix \e m and a column vector \e vec.
/// Note that the return type is a \c GfVec3f.
GF_API
friend GfVec3f operator *(const GfMatrix3d& m, const GfVec3f& vec);
/// Returns the product of row vector \e vec and a matrix \e m.
/// Note that the return type is a \c GfVec3f.
GF_API
friend GfVec3f operator *(const GfVec3f &vec, const GfMatrix3d& m);
/// Sets matrix to specify a uniform scaling by \e scaleFactor.
GF_API
GfMatrix3d& SetScale(double scaleFactor);
/// \name 3D Transformation Utilities
/// @{
/// Sets the matrix to specify a rotation equivalent to \e rot.
GF_API
GfMatrix3d& SetRotate(const GfQuatd &rot);
/// Sets the matrix to specify a rotation equivalent to \e rot.
GF_API
GfMatrix3d& SetRotate(const GfRotation &rot);
/// Sets the matrix to specify a nonuniform scaling in x, y, and z by
/// the factors in vector \e scaleFactors.
GF_API
GfMatrix3d& SetScale(const GfVec3d &scaleFactors);
/// Returns the rotation corresponding to this matrix. This works
/// well only if the matrix represents a rotation.
///
/// For good results, consider calling Orthonormalize() before calling
/// this method.
GF_API
GfRotation ExtractRotation() const;
/// Decompose the rotation corresponding to this matrix about 3
/// orthogonal axes. If the axes are not orthogonal, warnings
/// will be spewed.
///
/// This is a convenience method that is equivalent to calling
/// ExtractRotation().Decompose().
GF_API
GfVec3d DecomposeRotation(const GfVec3d &axis0,
const GfVec3d &axis1,
const GfVec3d &axis2 ) const;
/// Returns the quaternion corresponding to this matrix. This works
/// well only if the matrix represents a rotation.
///
/// For good results, consider calling Orthonormalize() before calling
/// this method.
GF_API
GfQuaternion ExtractRotationQuaternion() const;
/// @}
private:
/// Set the matrix to the rotation given by a quaternion,
/// defined by the real component \p r and imaginary components \p i.
void _SetRotateFromQuat(double r, const GfVec3d& i);
private:
/// Matrix storage, in row-major order.
GfMatrixData<double, 3, 3> _mtx;
// Friend declarations
friend class GfMatrix3f;
};
/// Tests for equality within a given tolerance, returning \c true if the
/// difference between each component of the matrix is less than or equal
/// to \p tolerance, or false otherwise.
GF_API
bool GfIsClose(GfMatrix3d const &m1, GfMatrix3d const &m2, double tolerance);
/// Output a GfMatrix3d
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream &, GfMatrix3d const &);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_MATRIX3D_H
+499
View File
@@ -0,0 +1,499 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// matrix3.template.h file to make changes.
#ifndef PXR_BASE_GF_MATRIX3F_H
#define PXR_BASE_GF_MATRIX3F_H
/// \file gf/matrix3f.h
/// \ingroup group_gf_LinearAlgebra
#include "pxr/pxr.h"
#include "pxr/base/gf/api.h"
#include "pxr/base/gf/declare.h"
#include "pxr/base/gf/matrixData.h"
#include "pxr/base/gf/vec3f.h"
#include "pxr/base/gf/traits.h"
#include <boost/functional/hash.hpp>
#include <iosfwd>
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
template <>
struct GfIsGfMatrix<class GfMatrix3f> { static const bool value = true; };
class GfMatrix3d;
class GfMatrix3f;
class GfRotation;
class GfQuaternion;
class GfQuatf;
/// \class GfMatrix3f
/// \ingroup group_gf_LinearAlgebra
///
/// Stores a 3x3 matrix of \c float elements. A basic type.
///
/// Matrices are defined to be in row-major order, so <c>matrix[i][j]</c>
/// indexes the element in the \e i th row and the \e j th column.
///
/// <h3>3D Transformations</h3>
///
/// Three methods, SetRotate(), SetScale(), and ExtractRotation(), interpret
/// a GfMatrix3f as a 3D transformation. By convention, vectors are treated
/// primarily as row vectors, implying the following:
///
/// \li Transformation matrices are organized to deal with row
/// vectors, not column vectors.
/// \li Each of the Set() methods in this class completely rewrites the
/// matrix; for example, SetRotate() yields a matrix
/// which does nothing but rotate.
/// \li When multiplying two transformation matrices, the matrix
/// on the left applies a more local transformation to a row
/// vector. For example, if R represents a rotation
/// matrix and S represents a scale matrix, the
/// product R*S will rotate a row vector, then scale
/// it.
class GfMatrix3f
{
public:
typedef float ScalarType;
static const size_t numRows = 3;
static const size_t numColumns = 3;
/// Default constructor. Leaves the matrix component values undefined.
GfMatrix3f() = default;
/// Constructor. Initializes the matrix from 9 independent
/// \c float values, specified in row-major order. For example,
/// parameter \e m10 specifies the value in row 1 and column 0.
GfMatrix3f(float m00, float m01, float m02,
float m10, float m11, float m12,
float m20, float m21, float m22) {
Set(m00, m01, m02,
m10, m11, m12,
m20, m21, m22);
}
/// Constructor. Initializes the matrix from a 3x3 array
/// of \c float values, specified in row-major order.
GfMatrix3f(const float m[3][3]) {
Set(m);
}
/// Constructor. Explicitly initializes the matrix to \e s times the
/// identity matrix.
explicit GfMatrix3f(float s) {
SetDiagonal(s);
}
/// This explicit constructor initializes the matrix to \p s times
/// the identity matrix.
explicit GfMatrix3f(int s) {
SetDiagonal(s);
}
/// Constructor. Explicitly initializes the matrix to diagonal form,
/// with the \e i th element on the diagonal set to <c>v[i]</c>.
explicit GfMatrix3f(const GfVec3f& v) {
SetDiagonal(v);
}
/// Constructor. Initialize the matrix from a vector of vectors of
/// double. The vector is expected to be 3x3. If it is
/// too big, only the first 3 rows and/or columns will be used.
/// If it is too small, uninitialized elements will be filled in with
/// the corresponding elements from an identity matrix.
///
GF_API
explicit GfMatrix3f(const std::vector< std::vector<double> >& v);
/// Constructor. Initialize the matrix from a vector of vectors of
/// float. The vector is expected to be 3x3. If it is
/// too big, only the first 3 rows and/or columns will be used.
/// If it is too small, uninitialized elements will be filled in with
/// the corresponding elements from an identity matrix.
///
GF_API
explicit GfMatrix3f(const std::vector< std::vector<float> >& v);
/// Constructor. Initialize matrix from rotation.
GF_API
GfMatrix3f(const GfRotation& rot);
/// Constructor. Initialize matrix from a quaternion.
GF_API
explicit GfMatrix3f(const GfQuatf& rot);
/// This explicit constructor converts a "double" matrix to a "float" matrix.
GF_API
explicit GfMatrix3f(const class GfMatrix3d& m);
/// Sets a row of the matrix from a Vec3.
void SetRow(int i, const GfVec3f & v) {
_mtx[i][0] = v[0];
_mtx[i][1] = v[1];
_mtx[i][2] = v[2];
}
/// Sets a column of the matrix from a Vec3.
void SetColumn(int i, const GfVec3f & v) {
_mtx[0][i] = v[0];
_mtx[1][i] = v[1];
_mtx[2][i] = v[2];
}
/// Gets a row of the matrix as a Vec3.
GfVec3f GetRow(int i) const {
return GfVec3f(_mtx[i][0], _mtx[i][1], _mtx[i][2]);
}
/// Gets a column of the matrix as a Vec3.
GfVec3f GetColumn(int i) const {
return GfVec3f(_mtx[0][i], _mtx[1][i], _mtx[2][i]);
}
/// Sets the matrix from 9 independent \c float values,
/// specified in row-major order. For example, parameter \e m10 specifies
/// the value in row 1 and column 0.
GfMatrix3f& Set(float m00, float m01, float m02,
float m10, float m11, float m12,
float m20, float m21, float m22) {
_mtx[0][0] = m00; _mtx[0][1] = m01; _mtx[0][2] = m02;
_mtx[1][0] = m10; _mtx[1][1] = m11; _mtx[1][2] = m12;
_mtx[2][0] = m20; _mtx[2][1] = m21; _mtx[2][2] = m22;
return *this;
}
/// Sets the matrix from a 3x3 array of \c float
/// values, specified in row-major order.
GfMatrix3f& Set(const float m[3][3]) {
_mtx[0][0] = m[0][0];
_mtx[0][1] = m[0][1];
_mtx[0][2] = m[0][2];
_mtx[1][0] = m[1][0];
_mtx[1][1] = m[1][1];
_mtx[1][2] = m[1][2];
_mtx[2][0] = m[2][0];
_mtx[2][1] = m[2][1];
_mtx[2][2] = m[2][2];
return *this;
}
/// Sets the matrix to the identity matrix.
GfMatrix3f& SetIdentity() {
return SetDiagonal(1);
}
/// Sets the matrix to zero.
GfMatrix3f& SetZero() {
return SetDiagonal(0);
}
/// Sets the matrix to \e s times the identity matrix.
GF_API
GfMatrix3f& SetDiagonal(float s);
/// Sets the matrix to have diagonal (<c>v[0], v[1], v[2]</c>).
GF_API
GfMatrix3f& SetDiagonal(const GfVec3f&);
/// Fills a 3x3 array of \c float values with the values in
/// the matrix, specified in row-major order.
GF_API
float* Get(float m[3][3]) const;
/// Returns raw access to components of matrix as an array of
/// \c float values. Components are in row-major order.
float* data() {
return _mtx.GetData();
}
/// Returns const raw access to components of matrix as an array of
/// \c float values. Components are in row-major order.
const float* data() const {
return _mtx.GetData();
}
/// Returns vector components as an array of \c float values.
float* GetArray() {
return _mtx.GetData();
}
/// Returns vector components as a const array of \c float values.
const float* GetArray() const {
return _mtx.GetData();
}
/// Accesses an indexed row \e i of the matrix as an array of 3 \c
/// float values so that standard indexing (such as <c>m[0][1]</c>)
/// works correctly.
float* operator [](int i) { return _mtx[i]; }
/// Accesses an indexed row \e i of the matrix as an array of 3 \c
/// float values so that standard indexing (such as <c>m[0][1]</c>)
/// works correctly.
const float* operator [](int i) const { return _mtx[i]; }
/// Hash.
friend inline size_t hash_value(GfMatrix3f const &m) {
int nElems = 3 * 3;
size_t h = 0;
const float *p = m.GetArray();
while (nElems--)
boost::hash_combine(h, *p++);
return h;
}
/// Tests for element-wise matrix equality. All elements must match
/// exactly for matrices to be considered equal.
GF_API
bool operator ==(const GfMatrix3d& m) const;
/// Tests for element-wise matrix equality. All elements must match
/// exactly for matrices to be considered equal.
GF_API
bool operator ==(const GfMatrix3f& m) const;
/// Tests for element-wise matrix inequality. All elements must match
/// exactly for matrices to be considered equal.
bool operator !=(const GfMatrix3d& m) const {
return !(*this == m);
}
/// Tests for element-wise matrix inequality. All elements must match
/// exactly for matrices to be considered equal.
bool operator !=(const GfMatrix3f& m) const {
return !(*this == m);
}
/// Returns the transpose of the matrix.
GF_API
GfMatrix3f GetTranspose() const;
/// Returns the inverse of the matrix, or FLT_MAX * SetIdentity() if the
/// matrix is singular. (FLT_MAX is the largest value a \c float can have,
/// as defined by the system.) The matrix is considered singular if the
/// determinant is less than or equal to the optional parameter \e eps. If
/// \e det is non-null, <c>*det</c> is set to the determinant.
GF_API
GfMatrix3f GetInverse(double* det = NULL, double eps = 0) const;
/// Returns the determinant of the matrix.
GF_API
double GetDeterminant() const;
/// Makes the matrix orthonormal in place. This is an iterative method that
/// is much more stable than the previous cross/cross method. If the
/// iterative method does not converge, a warning is issued.
///
/// Returns true if the iteration converged, false otherwise. Leaves any
/// translation part of the matrix unchanged. If \a issueWarning is true,
/// this method will issue a warning if the iteration does not converge,
/// otherwise it will be silent.
GF_API
bool Orthonormalize(bool issueWarning=true);
/// Returns an orthonormalized copy of the matrix.
GF_API
GfMatrix3f GetOrthonormalized(bool issueWarning=true) const;
/// Returns the sign of the determinant of the matrix, i.e. 1 for a
/// right-handed matrix, -1 for a left-handed matrix, and 0 for a
/// singular matrix.
GF_API
double GetHandedness() const;
/// Returns true if the vectors in the matrix form a right-handed
/// coordinate system.
bool IsRightHanded() const {
return GetHandedness() == 1.0;
}
/// Returns true if the vectors in matrix form a left-handed
/// coordinate system.
bool IsLeftHanded() const {
return GetHandedness() == -1.0;
}
/// Post-multiplies matrix \e m into this matrix.
GF_API
GfMatrix3f& operator *=(const GfMatrix3f& m);
/// Multiplies the matrix by a float.
GF_API
GfMatrix3f& operator *=(double);
/// Returns the product of a matrix and a float.
friend GfMatrix3f operator *(const GfMatrix3f& m1, double d)
{
GfMatrix3f m = m1;
return m *= d;
}
///
// Returns the product of a matrix and a float.
friend GfMatrix3f operator *(double d, const GfMatrix3f& m)
{
return m * d;
}
/// Adds matrix \e m to this matrix.
GF_API
GfMatrix3f& operator +=(const GfMatrix3f& m);
/// Subtracts matrix \e m from this matrix.
GF_API
GfMatrix3f& operator -=(const GfMatrix3f& m);
/// Returns the unary negation of matrix \e m.
GF_API
friend GfMatrix3f operator -(const GfMatrix3f& m);
/// Adds matrix \e m2 to \e m1
friend GfMatrix3f operator +(const GfMatrix3f& m1, const GfMatrix3f& m2)
{
GfMatrix3f tmp(m1);
tmp += m2;
return tmp;
}
/// Subtracts matrix \e m2 from \e m1.
friend GfMatrix3f operator -(const GfMatrix3f& m1, const GfMatrix3f& m2)
{
GfMatrix3f tmp(m1);
tmp -= m2;
return tmp;
}
/// Multiplies matrix \e m1 by \e m2.
friend GfMatrix3f operator *(const GfMatrix3f& m1, const GfMatrix3f& m2)
{
GfMatrix3f tmp(m1);
tmp *= m2;
return tmp;
}
/// Divides matrix \e m1 by \e m2 (that is, <c>m1 * inv(m2)</c>).
friend GfMatrix3f operator /(const GfMatrix3f& m1, const GfMatrix3f& m2)
{
return(m1 * m2.GetInverse());
}
/// Returns the product of a matrix \e m and a column vector \e vec.
friend inline GfVec3f operator *(const GfMatrix3f& m, const GfVec3f& vec) {
return GfVec3f(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[0][1] + vec[2] * m._mtx[0][2],
vec[0] * m._mtx[1][0] + vec[1] * m._mtx[1][1] + vec[2] * m._mtx[1][2],
vec[0] * m._mtx[2][0] + vec[1] * m._mtx[2][1] + vec[2] * m._mtx[2][2]);
}
/// Returns the product of row vector \e vec and a matrix \e m.
friend inline GfVec3f operator *(const GfVec3f &vec, const GfMatrix3f& m) {
return GfVec3f(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[1][0] + vec[2] * m._mtx[2][0],
vec[0] * m._mtx[0][1] + vec[1] * m._mtx[1][1] + vec[2] * m._mtx[2][1],
vec[0] * m._mtx[0][2] + vec[1] * m._mtx[1][2] + vec[2] * m._mtx[2][2]);
}
/// Sets matrix to specify a uniform scaling by \e scaleFactor.
GF_API
GfMatrix3f& SetScale(float scaleFactor);
/// \name 3D Transformation Utilities
/// @{
/// Sets the matrix to specify a rotation equivalent to \e rot.
GF_API
GfMatrix3f& SetRotate(const GfQuatf &rot);
/// Sets the matrix to specify a rotation equivalent to \e rot.
GF_API
GfMatrix3f& SetRotate(const GfRotation &rot);
/// Sets the matrix to specify a nonuniform scaling in x, y, and z by
/// the factors in vector \e scaleFactors.
GF_API
GfMatrix3f& SetScale(const GfVec3f &scaleFactors);
/// Returns the rotation corresponding to this matrix. This works
/// well only if the matrix represents a rotation.
///
/// For good results, consider calling Orthonormalize() before calling
/// this method.
GF_API
GfRotation ExtractRotation() const;
/// Decompose the rotation corresponding to this matrix about 3
/// orthogonal axes. If the axes are not orthogonal, warnings
/// will be spewed.
///
/// This is a convenience method that is equivalent to calling
/// ExtractRotation().Decompose().
GF_API
GfVec3f DecomposeRotation(const GfVec3f &axis0,
const GfVec3f &axis1,
const GfVec3f &axis2 ) const;
/// Returns the quaternion corresponding to this matrix. This works
/// well only if the matrix represents a rotation.
///
/// For good results, consider calling Orthonormalize() before calling
/// this method.
GF_API
GfQuaternion ExtractRotationQuaternion() const;
/// @}
private:
/// Set the matrix to the rotation given by a quaternion,
/// defined by the real component \p r and imaginary components \p i.
void _SetRotateFromQuat(float r, const GfVec3f& i);
private:
/// Matrix storage, in row-major order.
GfMatrixData<float, 3, 3> _mtx;
// Friend declarations
friend class GfMatrix3d;
};
/// Tests for equality within a given tolerance, returning \c true if the
/// difference between each component of the matrix is less than or equal
/// to \p tolerance, or false otherwise.
GF_API
bool GfIsClose(GfMatrix3f const &m1, GfMatrix3f const &m2, double tolerance);
/// Output a GfMatrix3f
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream &, GfMatrix3f const &);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_MATRIX3F_H
+761
View File
@@ -0,0 +1,761 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// matrix4.template.h file to make changes.
#ifndef PXR_BASE_GF_MATRIX4D_H
#define PXR_BASE_GF_MATRIX4D_H
/// \file gf/matrix4d.h
/// \ingroup group_gf_LinearAlgebra
#include "pxr/pxr.h"
#include "pxr/base/gf/api.h"
#include "pxr/base/gf/declare.h"
#include "pxr/base/gf/matrixData.h"
#include "pxr/base/gf/vec4d.h"
#include "pxr/base/gf/traits.h"
#include "pxr/base/gf/homogeneous.h"
#include "pxr/base/gf/limits.h"
#include "pxr/base/gf/math.h"
#include "pxr/base/gf/vec3d.h"
#include <boost/functional/hash.hpp>
#include <iosfwd>
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
template <>
struct GfIsGfMatrix<class GfMatrix4d> { static const bool value = true; };
class GfMatrix4d;
class GfMatrix4f;
class GfQuatd;
class GfRotation;
class GfMatrix3d;
/// \class GfMatrix4d
/// \ingroup group_gf_LinearAlgebra
///
/// Stores a 4x4 matrix of \c double elements. A basic type.
///
/// Matrices are defined to be in row-major order, so <c>matrix[i][j]</c>
/// indexes the element in the \e i th row and the \e j th column.
///
/// <h3>3D Transformations</h3>
///
/// The following methods interpret a GfMatrix4d as a 3D
/// transformation: SetRotate(), SetScale(), SetTranslate(), SetLookAt(),
/// Factor(), ExtractTranslation(), ExtractRotation(), Transform(), TransformDir().
/// By convention, vectors are treated primarily as row vectors,
/// implying the following:
/// \li Transformation matrices are organized to deal with row
/// vectors, not column vectors. For example, the last row of a matrix
/// contains the translation amounts.
/// \li Each of the Set() methods below completely rewrites the
/// matrix; for example, SetTranslate() yields a matrix
/// which does nothing but translate.
/// \li When multiplying two transformation matrices, the matrix
/// on the left applies a more local transformation to a row
/// vector. For example, if R represents a rotation
/// matrix and T represents a translation matrix, the
/// product R*T will rotate a row vector, then translate
/// it.
class GfMatrix4d
{
public:
typedef double ScalarType;
static const size_t numRows = 4;
static const size_t numColumns = 4;
/// Default constructor. Leaves the matrix component values undefined.
GfMatrix4d() = default;
/// Constructor. Initializes the matrix from 16 independent
/// \c double values, specified in row-major order. For example,
/// parameter \e m10 specifies the value in row 1 and column 0.
GfMatrix4d(double m00, double m01, double m02, double m03,
double m10, double m11, double m12, double m13,
double m20, double m21, double m22, double m23,
double m30, double m31, double m32, double m33) {
Set(m00, m01, m02, m03,
m10, m11, m12, m13,
m20, m21, m22, m23,
m30, m31, m32, m33);
}
/// Constructor. Initializes the matrix from a 4x4 array
/// of \c double values, specified in row-major order.
GfMatrix4d(const double m[4][4]) {
Set(m);
}
/// Constructor. Explicitly initializes the matrix to \e s times the
/// identity matrix.
explicit GfMatrix4d(double s) {
SetDiagonal(s);
}
/// Constructor. Explicitly initializes the matrix to diagonal form,
/// with the \e i th element on the diagonal set to <c>v[i]</c>.
explicit GfMatrix4d(const GfVec4d& v) {
SetDiagonal(v);
}
/// Constructor. Initialize the matrix from a vector of vectors of
/// double. The vector is expected to be 4x4. If it is
/// too big, only the first 4 rows and/or columns will be used.
/// If it is too small, uninitialized elements will be filled in with
/// the corresponding elements from an identity matrix.
///
GF_API
explicit GfMatrix4d(const std::vector< std::vector<double> >& v);
/// Constructor. Initialize the matrix from a vector of vectors of
/// float. The vector is expected to be 4x4. If it is
/// too big, only the first 4 rows and/or columns will be used.
/// If it is too small, uninitialized elements will be filled in with
/// the corresponding elements from an identity matrix.
///
GF_API
explicit GfMatrix4d(const std::vector< std::vector<float> >& v);
/// Constructor. Initialize the matrix from 4 row vectors of
/// double. Each vector is expected to length 4. If it is too
/// big, only the first 4 items will be used. If it is too small,
/// uninitialized elements will be filled in with the
/// corresponding elements from an identity matrix.
///
GF_API
explicit GfMatrix4d(const std::vector<double>& r0,
const std::vector<double>& r1,
const std::vector<double>& r2,
const std::vector<double>& r3);
/// Constructor. Initialize the matrix from 4 row vectors of
/// float. Each vector is expected to length 4. If it is too
/// big, only the first 4 items will be used. If it is too small,
/// uninitialized elements will be filled in with the
/// corresponding elements from an identity matrix.
///
GF_API
explicit GfMatrix4d(const std::vector<float>& r0,
const std::vector<float>& r1,
const std::vector<float>& r2,
const std::vector<float>& r3);
/// Constructor. Initializes a transformation matrix to perform the
/// indicated rotation and translation.
GF_API
GfMatrix4d(const GfRotation& rotate,
const GfVec3d& translate);
/// Constructor. Initializes a transformation matrix to perform the
/// indicated rotation and translation.
GF_API
GfMatrix4d(const GfMatrix3d& rotmx,
const GfVec3d& translate);
/// This explicit constructor converts a "float" matrix to a "double" matrix.
GF_API
explicit GfMatrix4d(const class GfMatrix4f& m);
/// Sets a row of the matrix from a Vec4.
void SetRow(int i, const GfVec4d & v) {
_mtx[i][0] = v[0];
_mtx[i][1] = v[1];
_mtx[i][2] = v[2];
_mtx[i][3] = v[3];
}
/// Sets a column of the matrix from a Vec4.
void SetColumn(int i, const GfVec4d & v) {
_mtx[0][i] = v[0];
_mtx[1][i] = v[1];
_mtx[2][i] = v[2];
_mtx[3][i] = v[3];
}
/// Gets a row of the matrix as a Vec4.
GfVec4d GetRow(int i) const {
return GfVec4d(_mtx[i][0], _mtx[i][1], _mtx[i][2], _mtx[i][3]);
}
/// Gets a column of the matrix as a Vec4.
GfVec4d GetColumn(int i) const {
return GfVec4d(_mtx[0][i], _mtx[1][i], _mtx[2][i], _mtx[3][i]);
}
/// Sets the matrix from 16 independent \c double values,
/// specified in row-major order. For example, parameter \e m10 specifies
/// the value in row 1 and column 0.
GfMatrix4d& Set(double m00, double m01, double m02, double m03,
double m10, double m11, double m12, double m13,
double m20, double m21, double m22, double m23,
double m30, double m31, double m32, double m33) {
_mtx[0][0] = m00; _mtx[0][1] = m01; _mtx[0][2] = m02; _mtx[0][3] = m03;
_mtx[1][0] = m10; _mtx[1][1] = m11; _mtx[1][2] = m12; _mtx[1][3] = m13;
_mtx[2][0] = m20; _mtx[2][1] = m21; _mtx[2][2] = m22; _mtx[2][3] = m23;
_mtx[3][0] = m30; _mtx[3][1] = m31; _mtx[3][2] = m32; _mtx[3][3] = m33;
return *this;
}
/// Sets the matrix from a 4x4 array of \c double
/// values, specified in row-major order.
GfMatrix4d& Set(const double m[4][4]) {
_mtx[0][0] = m[0][0];
_mtx[0][1] = m[0][1];
_mtx[0][2] = m[0][2];
_mtx[0][3] = m[0][3];
_mtx[1][0] = m[1][0];
_mtx[1][1] = m[1][1];
_mtx[1][2] = m[1][2];
_mtx[1][3] = m[1][3];
_mtx[2][0] = m[2][0];
_mtx[2][1] = m[2][1];
_mtx[2][2] = m[2][2];
_mtx[2][3] = m[2][3];
_mtx[3][0] = m[3][0];
_mtx[3][1] = m[3][1];
_mtx[3][2] = m[3][2];
_mtx[3][3] = m[3][3];
return *this;
}
/// Sets the matrix to the identity matrix.
GfMatrix4d& SetIdentity() {
return SetDiagonal(1);
}
/// Sets the matrix to zero.
GfMatrix4d& SetZero() {
return SetDiagonal(0);
}
/// Sets the matrix to \e s times the identity matrix.
GF_API
GfMatrix4d& SetDiagonal(double s);
/// Sets the matrix to have diagonal (<c>v[0], v[1], v[2], v[3]</c>).
GF_API
GfMatrix4d& SetDiagonal(const GfVec4d&);
/// Fills a 4x4 array of \c double values with the values in
/// the matrix, specified in row-major order.
GF_API
double* Get(double m[4][4]) const;
/// Returns raw access to components of matrix as an array of
/// \c double values. Components are in row-major order.
double* data() {
return _mtx.GetData();
}
/// Returns const raw access to components of matrix as an array of
/// \c double values. Components are in row-major order.
const double* data() const {
return _mtx.GetData();
}
/// Returns vector components as an array of \c double values.
double* GetArray() {
return _mtx.GetData();
}
/// Returns vector components as a const array of \c double values.
const double* GetArray() const {
return _mtx.GetData();
}
/// Accesses an indexed row \e i of the matrix as an array of 4 \c
/// double values so that standard indexing (such as <c>m[0][1]</c>)
/// works correctly.
double* operator [](int i) { return _mtx[i]; }
/// Accesses an indexed row \e i of the matrix as an array of 4 \c
/// double values so that standard indexing (such as <c>m[0][1]</c>)
/// works correctly.
const double* operator [](int i) const { return _mtx[i]; }
/// Hash.
friend inline size_t hash_value(GfMatrix4d const &m) {
int nElems = 4 * 4;
size_t h = 0;
const double *p = m.GetArray();
while (nElems--)
boost::hash_combine(h, *p++);
return h;
}
/// Tests for element-wise matrix equality. All elements must match
/// exactly for matrices to be considered equal.
GF_API
bool operator ==(const GfMatrix4d& m) const;
/// Tests for element-wise matrix equality. All elements must match
/// exactly for matrices to be considered equal.
GF_API
bool operator ==(const GfMatrix4f& m) const;
/// Tests for element-wise matrix inequality. All elements must match
/// exactly for matrices to be considered equal.
bool operator !=(const GfMatrix4d& m) const {
return !(*this == m);
}
/// Tests for element-wise matrix inequality. All elements must match
/// exactly for matrices to be considered equal.
bool operator !=(const GfMatrix4f& m) const {
return !(*this == m);
}
/// Returns the transpose of the matrix.
GF_API
GfMatrix4d GetTranspose() const;
/// Returns the inverse of the matrix, or FLT_MAX * SetIdentity() if the
/// matrix is singular. (FLT_MAX is the largest value a \c float can have,
/// as defined by the system.) The matrix is considered singular if the
/// determinant is less than or equal to the optional parameter \e eps. If
/// \e det is non-null, <c>*det</c> is set to the determinant.
GF_API
GfMatrix4d GetInverse(double* det = NULL, double eps = 0) const;
/// Returns the determinant of the matrix.
GF_API
double GetDeterminant() const;
/// Sets a row of the matrix from a Vec3.
/// The fourth element of the row is ignored.
void SetRow3(int i, const GfVec3d & v) {
_mtx[i][0] = v[0];
_mtx[i][1] = v[1];
_mtx[i][2] = v[2];
}
/// Gets a row of the matrix as a Vec3.
GfVec3d GetRow3(int i) const {
return GfVec3d(_mtx[i][0], _mtx[i][1], _mtx[i][2]);
}
/// Returns the determinant of the upper 3x3 matrix. This method is useful
/// when the matrix describes a linear transformation such as a rotation or
/// scale because the other values in the 4x4 matrix are not important.
double GetDeterminant3() const {
return _GetDeterminant3(0, 1, 2, 0, 1, 2);
}
/// Returns true, if the row vectors of the upper 3x3 matrix form an
/// orthogonal basis. Note they do not have to be unit length for this
/// test to return true.
bool HasOrthogonalRows3() const {
// XXX Should add GfAreOrthogonal(v0, v1, v2) (which also
// GfRotation::Decompose() could use).
GfVec3d axis0(GetRow3(0)), axis1(GetRow3(1)), axis2(GetRow3(2));
return (GfAbs(GfDot(axis0, axis1)) < GF_MIN_ORTHO_TOLERANCE &&
GfAbs(GfDot(axis0, axis2)) < GF_MIN_ORTHO_TOLERANCE &&
GfAbs(GfDot(axis1, axis2)) < GF_MIN_ORTHO_TOLERANCE);
}
/// Makes the matrix orthonormal in place. This is an iterative method
/// that is much more stable than the previous cross/cross method. If the
/// iterative method does not converge, a warning is issued.
///
/// Returns true if the iteration converged, false otherwise. Leaves any
/// translation part of the matrix unchanged. If \a issueWarning is true,
/// this method will issue a warning if the iteration does not converge,
/// otherwise it will be silent.
GF_API
bool Orthonormalize(bool issueWarning=true);
/// Returns an orthonormalized copy of the matrix.
GF_API
GfMatrix4d GetOrthonormalized(bool issueWarning=true) const;
/// Returns the sign of the determinant of the upper 3x3 matrix, i.e. 1
/// for a right-handed matrix, -1 for a left-handed matrix, and 0 for a
/// singular matrix.
GF_API
double GetHandedness() const;
/// Returns true if the vectors in the upper 3x3 matrix form a
/// right-handed coordinate system.
bool IsRightHanded() const {
return GetHandedness() == 1.0;
}
/// Returns true if the vectors in the upper 3x3 matrix form a left-handed
/// coordinate system.
bool IsLeftHanded() const {
return GetHandedness() == -1.0;
}
/// Post-multiplies matrix \e m into this matrix.
GF_API
GfMatrix4d& operator *=(const GfMatrix4d& m);
/// Multiplies the matrix by a double.
GF_API
GfMatrix4d& operator *=(double);
/// Returns the product of a matrix and a double.
friend GfMatrix4d operator *(const GfMatrix4d& m1, double d)
{
GfMatrix4d m = m1;
return m *= d;
}
///
// Returns the product of a matrix and a double.
friend GfMatrix4d operator *(double d, const GfMatrix4d& m)
{
return m * d;
}
/// Adds matrix \e m to this matrix.
GF_API
GfMatrix4d& operator +=(const GfMatrix4d& m);
/// Subtracts matrix \e m from this matrix.
GF_API
GfMatrix4d& operator -=(const GfMatrix4d& m);
/// Returns the unary negation of matrix \e m.
GF_API
friend GfMatrix4d operator -(const GfMatrix4d& m);
/// Adds matrix \e m2 to \e m1
friend GfMatrix4d operator +(const GfMatrix4d& m1, const GfMatrix4d& m2)
{
GfMatrix4d tmp(m1);
tmp += m2;
return tmp;
}
/// Subtracts matrix \e m2 from \e m1.
friend GfMatrix4d operator -(const GfMatrix4d& m1, const GfMatrix4d& m2)
{
GfMatrix4d tmp(m1);
tmp -= m2;
return tmp;
}
/// Multiplies matrix \e m1 by \e m2.
friend GfMatrix4d operator *(const GfMatrix4d& m1, const GfMatrix4d& m2)
{
GfMatrix4d tmp(m1);
tmp *= m2;
return tmp;
}
/// Divides matrix \e m1 by \e m2 (that is, <c>m1 * inv(m2)</c>).
friend GfMatrix4d operator /(const GfMatrix4d& m1, const GfMatrix4d& m2)
{
return(m1 * m2.GetInverse());
}
/// Returns the product of a matrix \e m and a column vector \e vec.
friend inline GfVec4d operator *(const GfMatrix4d& m, const GfVec4d& vec) {
return GfVec4d(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[0][1] + vec[2] * m._mtx[0][2] + vec[3] * m._mtx[0][3],
vec[0] * m._mtx[1][0] + vec[1] * m._mtx[1][1] + vec[2] * m._mtx[1][2] + vec[3] * m._mtx[1][3],
vec[0] * m._mtx[2][0] + vec[1] * m._mtx[2][1] + vec[2] * m._mtx[2][2] + vec[3] * m._mtx[2][3],
vec[0] * m._mtx[3][0] + vec[1] * m._mtx[3][1] + vec[2] * m._mtx[3][2] + vec[3] * m._mtx[3][3]);
}
/// Returns the product of row vector \e vec and a matrix \e m.
friend inline GfVec4d operator *(const GfVec4d &vec, const GfMatrix4d& m) {
return GfVec4d(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[1][0] + vec[2] * m._mtx[2][0] + vec[3] * m._mtx[3][0],
vec[0] * m._mtx[0][1] + vec[1] * m._mtx[1][1] + vec[2] * m._mtx[2][1] + vec[3] * m._mtx[3][1],
vec[0] * m._mtx[0][2] + vec[1] * m._mtx[1][2] + vec[2] * m._mtx[2][2] + vec[3] * m._mtx[3][2],
vec[0] * m._mtx[0][3] + vec[1] * m._mtx[1][3] + vec[2] * m._mtx[2][3] + vec[3] * m._mtx[3][3]);
}
/// Returns the product of a matrix \e m and a column vector \e vec.
/// Note that the return type is a \c GfVec4f.
GF_API
friend GfVec4f operator *(const GfMatrix4d& m, const GfVec4f& vec);
/// Returns the product of row vector \e vec and a matrix \e m.
/// Note that the return type is a \c GfVec4f.
GF_API
friend GfVec4f operator *(const GfVec4f &vec, const GfMatrix4d& m);
/// Sets matrix to specify a uniform scaling by \e scaleFactor.
GF_API
GfMatrix4d& SetScale(double scaleFactor);
/// Returns the matrix with any scaling or shearing removed,
/// leaving only the rotation and translation.
/// If the matrix cannot be decomposed, returns the original matrix.
GF_API
GfMatrix4d RemoveScaleShear() const;
/// \name 3D Transformation Utilities
/// @{
/// Sets the matrix to specify a rotation equivalent to \e rot,
/// and clears the translation.
GF_API
GfMatrix4d& SetRotate(const GfQuatd &rot);
/// Sets the matrix to specify a rotation equivalent to \e rot,
/// without clearing the translation.
GF_API
GfMatrix4d& SetRotateOnly(const GfQuatd &rot);
/// Sets the matrix to specify a rotation equivalent to \e rot,
/// and clears the translation.
GF_API
GfMatrix4d& SetRotate(const GfRotation &rot);
/// Sets the matrix to specify a rotation equivalent to \e rot,
/// without clearing the translation.
GF_API
GfMatrix4d& SetRotateOnly(const GfRotation &rot);
/// Sets the matrix to specify a rotation equivalent to \e mx,
/// and clears the translation.
GF_API
GfMatrix4d& SetRotate(const GfMatrix3d &mx);
/// Sets the matrix to specify a rotation equivalent to \e mx,
/// without clearing the translation.
GF_API
GfMatrix4d& SetRotateOnly(const GfMatrix3d &mx);
/// Sets the matrix to specify a nonuniform scaling in x, y, and z by
/// the factors in vector \e scaleFactors.
GF_API
GfMatrix4d& SetScale(const GfVec3d &scaleFactors);
/// Sets matrix to specify a translation by the vector \e trans,
/// and clears the rotation.
GF_API
GfMatrix4d& SetTranslate(const GfVec3d &trans);
/// Sets matrix to specify a translation by the vector \e trans,
/// without clearing the rotation.
GF_API
GfMatrix4d& SetTranslateOnly(const GfVec3d &t);
/// Sets matrix to specify a rotation by \e rotate and a
/// translation by \e translate.
GF_API
GfMatrix4d& SetTransform(const GfRotation& rotate,
const GfVec3d& translate);
/// Sets matrix to specify a rotation by \e rotmx and a
/// translation by \e translate.
GF_API
GfMatrix4d& SetTransform(const GfMatrix3d& rotmx,
const GfVec3d& translate);
/// Sets the matrix to specify a viewing matrix from parameters
/// similar to those used by <c>gluLookAt(3G)</c>. \e eyePoint
/// represents the eye point in world space. \e centerPoint
/// represents the world-space center of attention. \e upDirection
/// is a vector indicating which way is up.
GF_API
GfMatrix4d& SetLookAt(const GfVec3d &eyePoint,
const GfVec3d &centerPoint,
const GfVec3d &upDirection);
/// Sets the matrix to specify a viewing matrix from a world-space
/// \e eyePoint and a world-space rotation that rigidly rotates the
/// orientation from its canonical frame, which is defined to be
/// looking along the <c>-z</c> axis with the <c>+y</c> axis as the up
/// direction.
GF_API
GfMatrix4d& SetLookAt(const GfVec3d &eyePoint,
const GfRotation &orientation);
/// Factors the matrix into 5 components:
/// \li <c>\e M = r * s * -r * u * t</c>
/// where
/// \li \e t is a translation.
/// \li \e u and \e r are rotations, and \e -r is the transpose
/// (inverse) of \e r. The \e u matrix may contain shear
/// information.
/// \li \e s is a scale.
/// Any projection information could be returned in matrix \e p,
/// but currently p is never modified.
///
/// Returns \c false if the matrix is singular (as determined by \e eps).
/// In that case, any zero scales in \e s are clamped to \e eps
/// to allow computation of \e u.
GF_API
bool Factor(GfMatrix4d* r, GfVec3d* s, GfMatrix4d* u,
GfVec3d* t, GfMatrix4d* p,
double eps = 1e-10) const;
/// Returns the translation part of the matrix, defined as the first three
/// elements of the last row.
GfVec3d ExtractTranslation() const {
return GfVec3d(_mtx[3][0], _mtx[3][1], _mtx[3][2]);
}
/// Returns the rotation corresponding to this matrix. This works well
/// only if the matrix represents a rotation.
///
/// For good results, consider calling Orthonormalize() before calling
/// this method.
GF_API
GfRotation ExtractRotation() const;
/// Return the rotation corresponding to this matrix as a quaternion.
/// This works well only if the matrix represents a rotation.
///
/// For good results, consider calling Orthonormalize() before calling
/// this method.
GF_API
GfQuatd ExtractRotationQuat() const;
/// Decompose the rotation corresponding to this matrix about 3 orthogonal
/// axes. If the axes are not orthogonal, warnings will be spewed.
///
/// This is a convenience method that is equivalent to calling
/// ExtractRotation().Decompose().
GF_API
GfVec3d DecomposeRotation(const GfVec3d &axis0,
const GfVec3d &axis1,
const GfVec3d &axis2) const;
/// Returns the rotation corresponding to this matrix. This works well
/// only if the matrix represents a rotation.
///
/// For good results, consider calling Orthonormalize() before calling
/// this method.
GF_API
GfMatrix3d ExtractRotationMatrix() const;
/// Transforms the row vector \e vec by the matrix, returning the result.
/// This treats the vector as a 4-component vector whose fourth component
/// is 1.
GfVec3d Transform(const GfVec3d &vec) const {
return GfProject(GfVec4d(
vec[0] * _mtx[0][0] + vec[1] * _mtx[1][0] + vec[2] * _mtx[2][0] + _mtx[3][0],
vec[0] * _mtx[0][1] + vec[1] * _mtx[1][1] + vec[2] * _mtx[2][1] + _mtx[3][1],
vec[0] * _mtx[0][2] + vec[1] * _mtx[1][2] + vec[2] * _mtx[2][2] + _mtx[3][2],
vec[0] * _mtx[0][3] + vec[1] * _mtx[1][3] + vec[2] * _mtx[2][3] + _mtx[3][3]));
}
/// Transforms the row vector \e vec by the matrix, returning the result.
/// This treats the vector as a 4-component vector whose fourth component
/// is 1. This is an overloaded method; it differs from the other version
/// in that it returns a different value type.
GfVec3f Transform(const GfVec3f &vec) const {
return GfVec3f(GfProject(GfVec4d(
vec[0] * _mtx[0][0] + vec[1] * _mtx[1][0] + vec[2] * _mtx[2][0] + _mtx[3][0],
vec[0] * _mtx[0][1] + vec[1] * _mtx[1][1] + vec[2] * _mtx[2][1] + _mtx[3][1],
vec[0] * _mtx[0][2] + vec[1] * _mtx[1][2] + vec[2] * _mtx[2][2] + _mtx[3][2],
vec[0] * _mtx[0][3] + vec[1] * _mtx[1][3] + vec[2] * _mtx[2][3] + _mtx[3][3])));
}
/// Transforms row vector \e vec by the matrix, returning the result. This
/// treats the vector as a direction vector, so the translation
/// information in the matrix is ignored. That is, it treats the vector as
/// a 4-component vector whose fourth component is 0.
GfVec3d TransformDir(const GfVec3d &vec) const {
return GfVec3d(
vec[0] * _mtx[0][0] + vec[1] * _mtx[1][0] + vec[2] * _mtx[2][0],
vec[0] * _mtx[0][1] + vec[1] * _mtx[1][1] + vec[2] * _mtx[2][1],
vec[0] * _mtx[0][2] + vec[1] * _mtx[1][2] + vec[2] * _mtx[2][2]);
}
/// Transforms row vector \e vec by the matrix, returning the result. This
/// treats the vector as a direction vector, so the translation
/// information in the matrix is ignored. That is, it treats the vector as
/// a 4-component vector whose fourth component is 0. This is an
/// overloaded method; it differs from the other version in that it
/// returns a different value type.
GfVec3f TransformDir(const GfVec3f &vec) const {
return GfVec3f(
vec[0] * _mtx[0][0] + vec[1] * _mtx[1][0] + vec[2] * _mtx[2][0],
vec[0] * _mtx[0][1] + vec[1] * _mtx[1][1] + vec[2] * _mtx[2][1],
vec[0] * _mtx[0][2] + vec[1] * _mtx[1][2] + vec[2] * _mtx[2][2]);
}
/// Transforms the row vector \e vec by the matrix, returning the result.
/// This treats the vector as a 4-component vector whose fourth component
/// is 1 and ignores the fourth column of the matrix (i.e. assumes it is
/// (0, 0, 0, 1)).
GfVec3d TransformAffine(const GfVec3d &vec) const {
return GfVec3d(
vec[0] * _mtx[0][0] + vec[1] * _mtx[1][0] + vec[2] * _mtx[2][0] + _mtx[3][0],
vec[0] * _mtx[0][1] + vec[1] * _mtx[1][1] + vec[2] * _mtx[2][1] + _mtx[3][1],
vec[0] * _mtx[0][2] + vec[1] * _mtx[1][2] + vec[2] * _mtx[2][2] + _mtx[3][2]);
}
/// Transforms the row vector \e vec by the matrix, returning the result.
/// This treats the vector as a 4-component vector whose fourth component
/// is 1 and ignores the fourth column of the matrix (i.e. assumes it is
/// (0, 0, 0, 1)).
GfVec3f TransformAffine(const GfVec3f &vec) const {
return GfVec3f(
vec[0] * _mtx[0][0] + vec[1] * _mtx[1][0] + vec[2] * _mtx[2][0] + _mtx[3][0],
vec[0] * _mtx[0][1] + vec[1] * _mtx[1][1] + vec[2] * _mtx[2][1] + _mtx[3][1],
vec[0] * _mtx[0][2] + vec[1] * _mtx[1][2] + vec[2] * _mtx[2][2] + _mtx[3][2]);
}
/// @}
private:
/// Returns the determinant of the 3x3 submatrix specified by the three
/// given row and column indices (0-3 for each).
GF_API
double _GetDeterminant3(size_t row1, size_t row2, size_t row3,
size_t col1, size_t col2, size_t col3) const;
/// Diagonalizes the upper 3x3 matrix of a matrix known to be symmetric.
void _Jacobi3(GfVec3d *eigenvalues, GfVec3d eigenvectors[3]) const;
/// Set the 3x3 submatrix to the rotation given by a quaternion,
/// defined by the real component \p r and imaginary components \p i.
void _SetRotateFromQuat(double r, const GfVec3d& i);
private:
/// Matrix storage, in row-major order.
GfMatrixData<double, 4, 4> _mtx;
// Friend declarations
friend class GfMatrix4f;
};
/// Tests for equality within a given tolerance, returning \c true if the
/// difference between each component of the matrix is less than or equal
/// to \p tolerance, or false otherwise.
GF_API
bool GfIsClose(GfMatrix4d const &m1, GfMatrix4d const &m2, double tolerance);
/// Output a GfMatrix4d
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream &, GfMatrix4d const &);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_MATRIX4D_H
+751
View File
@@ -0,0 +1,751 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// matrix4.template.h file to make changes.
#ifndef PXR_BASE_GF_MATRIX4F_H
#define PXR_BASE_GF_MATRIX4F_H
/// \file gf/matrix4f.h
/// \ingroup group_gf_LinearAlgebra
#include "pxr/pxr.h"
#include "pxr/base/gf/api.h"
#include "pxr/base/gf/declare.h"
#include "pxr/base/gf/matrixData.h"
#include "pxr/base/gf/vec4f.h"
#include "pxr/base/gf/traits.h"
#include "pxr/base/gf/homogeneous.h"
#include "pxr/base/gf/limits.h"
#include "pxr/base/gf/math.h"
#include "pxr/base/gf/vec3f.h"
#include <boost/functional/hash.hpp>
#include <iosfwd>
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
template <>
struct GfIsGfMatrix<class GfMatrix4f> { static const bool value = true; };
class GfMatrix4d;
class GfMatrix4f;
class GfQuatf;
class GfRotation;
class GfMatrix3f;
/// \class GfMatrix4f
/// \ingroup group_gf_LinearAlgebra
///
/// Stores a 4x4 matrix of \c float elements. A basic type.
///
/// Matrices are defined to be in row-major order, so <c>matrix[i][j]</c>
/// indexes the element in the \e i th row and the \e j th column.
///
/// <h3>3D Transformations</h3>
///
/// The following methods interpret a GfMatrix4f as a 3D
/// transformation: SetRotate(), SetScale(), SetTranslate(), SetLookAt(),
/// Factor(), ExtractTranslation(), ExtractRotation(), Transform(), TransformDir().
/// By convention, vectors are treated primarily as row vectors,
/// implying the following:
/// \li Transformation matrices are organized to deal with row
/// vectors, not column vectors. For example, the last row of a matrix
/// contains the translation amounts.
/// \li Each of the Set() methods below completely rewrites the
/// matrix; for example, SetTranslate() yields a matrix
/// which does nothing but translate.
/// \li When multiplying two transformation matrices, the matrix
/// on the left applies a more local transformation to a row
/// vector. For example, if R represents a rotation
/// matrix and T represents a translation matrix, the
/// product R*T will rotate a row vector, then translate
/// it.
class GfMatrix4f
{
public:
typedef float ScalarType;
static const size_t numRows = 4;
static const size_t numColumns = 4;
/// Default constructor. Leaves the matrix component values undefined.
GfMatrix4f() = default;
/// Constructor. Initializes the matrix from 16 independent
/// \c float values, specified in row-major order. For example,
/// parameter \e m10 specifies the value in row 1 and column 0.
GfMatrix4f(float m00, float m01, float m02, float m03,
float m10, float m11, float m12, float m13,
float m20, float m21, float m22, float m23,
float m30, float m31, float m32, float m33) {
Set(m00, m01, m02, m03,
m10, m11, m12, m13,
m20, m21, m22, m23,
m30, m31, m32, m33);
}
/// Constructor. Initializes the matrix from a 4x4 array
/// of \c float values, specified in row-major order.
GfMatrix4f(const float m[4][4]) {
Set(m);
}
/// Constructor. Explicitly initializes the matrix to \e s times the
/// identity matrix.
explicit GfMatrix4f(float s) {
SetDiagonal(s);
}
/// Constructor. Explicitly initializes the matrix to diagonal form,
/// with the \e i th element on the diagonal set to <c>v[i]</c>.
explicit GfMatrix4f(const GfVec4f& v) {
SetDiagonal(v);
}
/// Constructor. Initialize the matrix from a vector of vectors of
/// double. The vector is expected to be 4x4. If it is
/// too big, only the first 4 rows and/or columns will be used.
/// If it is too small, uninitialized elements will be filled in with
/// the corresponding elements from an identity matrix.
///
GF_API
explicit GfMatrix4f(const std::vector< std::vector<double> >& v);
/// Constructor. Initialize the matrix from a vector of vectors of
/// float. The vector is expected to be 4x4. If it is
/// too big, only the first 4 rows and/or columns will be used.
/// If it is too small, uninitialized elements will be filled in with
/// the corresponding elements from an identity matrix.
///
GF_API
explicit GfMatrix4f(const std::vector< std::vector<float> >& v);
/// Constructor. Initialize the matrix from 4 row vectors of
/// double. Each vector is expected to length 4. If it is too
/// big, only the first 4 items will be used. If it is too small,
/// uninitialized elements will be filled in with the
/// corresponding elements from an identity matrix.
///
GF_API
explicit GfMatrix4f(const std::vector<double>& r0,
const std::vector<double>& r1,
const std::vector<double>& r2,
const std::vector<double>& r3);
/// Constructor. Initialize the matrix from 4 row vectors of
/// float. Each vector is expected to length 4. If it is too
/// big, only the first 4 items will be used. If it is too small,
/// uninitialized elements will be filled in with the
/// corresponding elements from an identity matrix.
///
GF_API
explicit GfMatrix4f(const std::vector<float>& r0,
const std::vector<float>& r1,
const std::vector<float>& r2,
const std::vector<float>& r3);
/// Constructor. Initializes a transformation matrix to perform the
/// indicated rotation and translation.
GF_API
GfMatrix4f(const GfRotation& rotate,
const GfVec3f& translate);
/// Constructor. Initializes a transformation matrix to perform the
/// indicated rotation and translation.
GF_API
GfMatrix4f(const GfMatrix3f& rotmx,
const GfVec3f& translate);
/// This explicit constructor converts a "double" matrix to a "float" matrix.
GF_API
explicit GfMatrix4f(const class GfMatrix4d& m);
/// Sets a row of the matrix from a Vec4.
void SetRow(int i, const GfVec4f & v) {
_mtx[i][0] = v[0];
_mtx[i][1] = v[1];
_mtx[i][2] = v[2];
_mtx[i][3] = v[3];
}
/// Sets a column of the matrix from a Vec4.
void SetColumn(int i, const GfVec4f & v) {
_mtx[0][i] = v[0];
_mtx[1][i] = v[1];
_mtx[2][i] = v[2];
_mtx[3][i] = v[3];
}
/// Gets a row of the matrix as a Vec4.
GfVec4f GetRow(int i) const {
return GfVec4f(_mtx[i][0], _mtx[i][1], _mtx[i][2], _mtx[i][3]);
}
/// Gets a column of the matrix as a Vec4.
GfVec4f GetColumn(int i) const {
return GfVec4f(_mtx[0][i], _mtx[1][i], _mtx[2][i], _mtx[3][i]);
}
/// Sets the matrix from 16 independent \c float values,
/// specified in row-major order. For example, parameter \e m10 specifies
/// the value in row 1 and column 0.
GfMatrix4f& Set(float m00, float m01, float m02, float m03,
float m10, float m11, float m12, float m13,
float m20, float m21, float m22, float m23,
float m30, float m31, float m32, float m33) {
_mtx[0][0] = m00; _mtx[0][1] = m01; _mtx[0][2] = m02; _mtx[0][3] = m03;
_mtx[1][0] = m10; _mtx[1][1] = m11; _mtx[1][2] = m12; _mtx[1][3] = m13;
_mtx[2][0] = m20; _mtx[2][1] = m21; _mtx[2][2] = m22; _mtx[2][3] = m23;
_mtx[3][0] = m30; _mtx[3][1] = m31; _mtx[3][2] = m32; _mtx[3][3] = m33;
return *this;
}
/// Sets the matrix from a 4x4 array of \c float
/// values, specified in row-major order.
GfMatrix4f& Set(const float m[4][4]) {
_mtx[0][0] = m[0][0];
_mtx[0][1] = m[0][1];
_mtx[0][2] = m[0][2];
_mtx[0][3] = m[0][3];
_mtx[1][0] = m[1][0];
_mtx[1][1] = m[1][1];
_mtx[1][2] = m[1][2];
_mtx[1][3] = m[1][3];
_mtx[2][0] = m[2][0];
_mtx[2][1] = m[2][1];
_mtx[2][2] = m[2][2];
_mtx[2][3] = m[2][3];
_mtx[3][0] = m[3][0];
_mtx[3][1] = m[3][1];
_mtx[3][2] = m[3][2];
_mtx[3][3] = m[3][3];
return *this;
}
/// Sets the matrix to the identity matrix.
GfMatrix4f& SetIdentity() {
return SetDiagonal(1);
}
/// Sets the matrix to zero.
GfMatrix4f& SetZero() {
return SetDiagonal(0);
}
/// Sets the matrix to \e s times the identity matrix.
GF_API
GfMatrix4f& SetDiagonal(float s);
/// Sets the matrix to have diagonal (<c>v[0], v[1], v[2], v[3]</c>).
GF_API
GfMatrix4f& SetDiagonal(const GfVec4f&);
/// Fills a 4x4 array of \c float values with the values in
/// the matrix, specified in row-major order.
GF_API
float* Get(float m[4][4]) const;
/// Returns raw access to components of matrix as an array of
/// \c float values. Components are in row-major order.
float* data() {
return _mtx.GetData();
}
/// Returns const raw access to components of matrix as an array of
/// \c float values. Components are in row-major order.
const float* data() const {
return _mtx.GetData();
}
/// Returns vector components as an array of \c float values.
float* GetArray() {
return _mtx.GetData();
}
/// Returns vector components as a const array of \c float values.
const float* GetArray() const {
return _mtx.GetData();
}
/// Accesses an indexed row \e i of the matrix as an array of 4 \c
/// float values so that standard indexing (such as <c>m[0][1]</c>)
/// works correctly.
float* operator [](int i) { return _mtx[i]; }
/// Accesses an indexed row \e i of the matrix as an array of 4 \c
/// float values so that standard indexing (such as <c>m[0][1]</c>)
/// works correctly.
const float* operator [](int i) const { return _mtx[i]; }
/// Hash.
friend inline size_t hash_value(GfMatrix4f const &m) {
int nElems = 4 * 4;
size_t h = 0;
const float *p = m.GetArray();
while (nElems--)
boost::hash_combine(h, *p++);
return h;
}
/// Tests for element-wise matrix equality. All elements must match
/// exactly for matrices to be considered equal.
GF_API
bool operator ==(const GfMatrix4d& m) const;
/// Tests for element-wise matrix equality. All elements must match
/// exactly for matrices to be considered equal.
GF_API
bool operator ==(const GfMatrix4f& m) const;
/// Tests for element-wise matrix inequality. All elements must match
/// exactly for matrices to be considered equal.
bool operator !=(const GfMatrix4d& m) const {
return !(*this == m);
}
/// Tests for element-wise matrix inequality. All elements must match
/// exactly for matrices to be considered equal.
bool operator !=(const GfMatrix4f& m) const {
return !(*this == m);
}
/// Returns the transpose of the matrix.
GF_API
GfMatrix4f GetTranspose() const;
/// Returns the inverse of the matrix, or FLT_MAX * SetIdentity() if the
/// matrix is singular. (FLT_MAX is the largest value a \c float can have,
/// as defined by the system.) The matrix is considered singular if the
/// determinant is less than or equal to the optional parameter \e eps. If
/// \e det is non-null, <c>*det</c> is set to the determinant.
GF_API
GfMatrix4f GetInverse(double* det = NULL, double eps = 0) const;
/// Returns the determinant of the matrix.
GF_API
double GetDeterminant() const;
/// Sets a row of the matrix from a Vec3.
/// The fourth element of the row is ignored.
void SetRow3(int i, const GfVec3f & v) {
_mtx[i][0] = v[0];
_mtx[i][1] = v[1];
_mtx[i][2] = v[2];
}
/// Gets a row of the matrix as a Vec3.
GfVec3f GetRow3(int i) const {
return GfVec3f(_mtx[i][0], _mtx[i][1], _mtx[i][2]);
}
/// Returns the determinant of the upper 3x3 matrix. This method is useful
/// when the matrix describes a linear transformation such as a rotation or
/// scale because the other values in the 4x4 matrix are not important.
double GetDeterminant3() const {
return _GetDeterminant3(0, 1, 2, 0, 1, 2);
}
/// Returns true, if the row vectors of the upper 3x3 matrix form an
/// orthogonal basis. Note they do not have to be unit length for this
/// test to return true.
bool HasOrthogonalRows3() const {
// XXX Should add GfAreOrthogonal(v0, v1, v2) (which also
// GfRotation::Decompose() could use).
GfVec3f axis0(GetRow3(0)), axis1(GetRow3(1)), axis2(GetRow3(2));
return (GfAbs(GfDot(axis0, axis1)) < GF_MIN_ORTHO_TOLERANCE &&
GfAbs(GfDot(axis0, axis2)) < GF_MIN_ORTHO_TOLERANCE &&
GfAbs(GfDot(axis1, axis2)) < GF_MIN_ORTHO_TOLERANCE);
}
/// Makes the matrix orthonormal in place. This is an iterative method
/// that is much more stable than the previous cross/cross method. If the
/// iterative method does not converge, a warning is issued.
///
/// Returns true if the iteration converged, false otherwise. Leaves any
/// translation part of the matrix unchanged. If \a issueWarning is true,
/// this method will issue a warning if the iteration does not converge,
/// otherwise it will be silent.
GF_API
bool Orthonormalize(bool issueWarning=true);
/// Returns an orthonormalized copy of the matrix.
GF_API
GfMatrix4f GetOrthonormalized(bool issueWarning=true) const;
/// Returns the sign of the determinant of the upper 3x3 matrix, i.e. 1
/// for a right-handed matrix, -1 for a left-handed matrix, and 0 for a
/// singular matrix.
GF_API
double GetHandedness() const;
/// Returns true if the vectors in the upper 3x3 matrix form a
/// right-handed coordinate system.
bool IsRightHanded() const {
return GetHandedness() == 1.0;
}
/// Returns true if the vectors in the upper 3x3 matrix form a left-handed
/// coordinate system.
bool IsLeftHanded() const {
return GetHandedness() == -1.0;
}
/// Post-multiplies matrix \e m into this matrix.
GF_API
GfMatrix4f& operator *=(const GfMatrix4f& m);
/// Multiplies the matrix by a float.
GF_API
GfMatrix4f& operator *=(double);
/// Returns the product of a matrix and a float.
friend GfMatrix4f operator *(const GfMatrix4f& m1, double d)
{
GfMatrix4f m = m1;
return m *= d;
}
///
// Returns the product of a matrix and a float.
friend GfMatrix4f operator *(double d, const GfMatrix4f& m)
{
return m * d;
}
/// Adds matrix \e m to this matrix.
GF_API
GfMatrix4f& operator +=(const GfMatrix4f& m);
/// Subtracts matrix \e m from this matrix.
GF_API
GfMatrix4f& operator -=(const GfMatrix4f& m);
/// Returns the unary negation of matrix \e m.
GF_API
friend GfMatrix4f operator -(const GfMatrix4f& m);
/// Adds matrix \e m2 to \e m1
friend GfMatrix4f operator +(const GfMatrix4f& m1, const GfMatrix4f& m2)
{
GfMatrix4f tmp(m1);
tmp += m2;
return tmp;
}
/// Subtracts matrix \e m2 from \e m1.
friend GfMatrix4f operator -(const GfMatrix4f& m1, const GfMatrix4f& m2)
{
GfMatrix4f tmp(m1);
tmp -= m2;
return tmp;
}
/// Multiplies matrix \e m1 by \e m2.
friend GfMatrix4f operator *(const GfMatrix4f& m1, const GfMatrix4f& m2)
{
GfMatrix4f tmp(m1);
tmp *= m2;
return tmp;
}
/// Divides matrix \e m1 by \e m2 (that is, <c>m1 * inv(m2)</c>).
friend GfMatrix4f operator /(const GfMatrix4f& m1, const GfMatrix4f& m2)
{
return(m1 * m2.GetInverse());
}
/// Returns the product of a matrix \e m and a column vector \e vec.
friend inline GfVec4f operator *(const GfMatrix4f& m, const GfVec4f& vec) {
return GfVec4f(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[0][1] + vec[2] * m._mtx[0][2] + vec[3] * m._mtx[0][3],
vec[0] * m._mtx[1][0] + vec[1] * m._mtx[1][1] + vec[2] * m._mtx[1][2] + vec[3] * m._mtx[1][3],
vec[0] * m._mtx[2][0] + vec[1] * m._mtx[2][1] + vec[2] * m._mtx[2][2] + vec[3] * m._mtx[2][3],
vec[0] * m._mtx[3][0] + vec[1] * m._mtx[3][1] + vec[2] * m._mtx[3][2] + vec[3] * m._mtx[3][3]);
}
/// Returns the product of row vector \e vec and a matrix \e m.
friend inline GfVec4f operator *(const GfVec4f &vec, const GfMatrix4f& m) {
return GfVec4f(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[1][0] + vec[2] * m._mtx[2][0] + vec[3] * m._mtx[3][0],
vec[0] * m._mtx[0][1] + vec[1] * m._mtx[1][1] + vec[2] * m._mtx[2][1] + vec[3] * m._mtx[3][1],
vec[0] * m._mtx[0][2] + vec[1] * m._mtx[1][2] + vec[2] * m._mtx[2][2] + vec[3] * m._mtx[3][2],
vec[0] * m._mtx[0][3] + vec[1] * m._mtx[1][3] + vec[2] * m._mtx[2][3] + vec[3] * m._mtx[3][3]);
}
/// Sets matrix to specify a uniform scaling by \e scaleFactor.
GF_API
GfMatrix4f& SetScale(float scaleFactor);
/// Returns the matrix with any scaling or shearing removed,
/// leaving only the rotation and translation.
/// If the matrix cannot be decomposed, returns the original matrix.
GF_API
GfMatrix4f RemoveScaleShear() const;
/// \name 3D Transformation Utilities
/// @{
/// Sets the matrix to specify a rotation equivalent to \e rot,
/// and clears the translation.
GF_API
GfMatrix4f& SetRotate(const GfQuatf &rot);
/// Sets the matrix to specify a rotation equivalent to \e rot,
/// without clearing the translation.
GF_API
GfMatrix4f& SetRotateOnly(const GfQuatf &rot);
/// Sets the matrix to specify a rotation equivalent to \e rot,
/// and clears the translation.
GF_API
GfMatrix4f& SetRotate(const GfRotation &rot);
/// Sets the matrix to specify a rotation equivalent to \e rot,
/// without clearing the translation.
GF_API
GfMatrix4f& SetRotateOnly(const GfRotation &rot);
/// Sets the matrix to specify a rotation equivalent to \e mx,
/// and clears the translation.
GF_API
GfMatrix4f& SetRotate(const GfMatrix3f &mx);
/// Sets the matrix to specify a rotation equivalent to \e mx,
/// without clearing the translation.
GF_API
GfMatrix4f& SetRotateOnly(const GfMatrix3f &mx);
/// Sets the matrix to specify a nonuniform scaling in x, y, and z by
/// the factors in vector \e scaleFactors.
GF_API
GfMatrix4f& SetScale(const GfVec3f &scaleFactors);
/// Sets matrix to specify a translation by the vector \e trans,
/// and clears the rotation.
GF_API
GfMatrix4f& SetTranslate(const GfVec3f &trans);
/// Sets matrix to specify a translation by the vector \e trans,
/// without clearing the rotation.
GF_API
GfMatrix4f& SetTranslateOnly(const GfVec3f &t);
/// Sets matrix to specify a rotation by \e rotate and a
/// translation by \e translate.
GF_API
GfMatrix4f& SetTransform(const GfRotation& rotate,
const GfVec3f& translate);
/// Sets matrix to specify a rotation by \e rotmx and a
/// translation by \e translate.
GF_API
GfMatrix4f& SetTransform(const GfMatrix3f& rotmx,
const GfVec3f& translate);
/// Sets the matrix to specify a viewing matrix from parameters
/// similar to those used by <c>gluLookAt(3G)</c>. \e eyePoint
/// represents the eye point in world space. \e centerPoint
/// represents the world-space center of attention. \e upDirection
/// is a vector indicating which way is up.
GF_API
GfMatrix4f& SetLookAt(const GfVec3f &eyePoint,
const GfVec3f &centerPoint,
const GfVec3f &upDirection);
/// Sets the matrix to specify a viewing matrix from a world-space
/// \e eyePoint and a world-space rotation that rigidly rotates the
/// orientation from its canonical frame, which is defined to be
/// looking along the <c>-z</c> axis with the <c>+y</c> axis as the up
/// direction.
GF_API
GfMatrix4f& SetLookAt(const GfVec3f &eyePoint,
const GfRotation &orientation);
/// Factors the matrix into 5 components:
/// \li <c>\e M = r * s * -r * u * t</c>
/// where
/// \li \e t is a translation.
/// \li \e u and \e r are rotations, and \e -r is the transpose
/// (inverse) of \e r. The \e u matrix may contain shear
/// information.
/// \li \e s is a scale.
/// Any projection information could be returned in matrix \e p,
/// but currently p is never modified.
///
/// Returns \c false if the matrix is singular (as determined by \e eps).
/// In that case, any zero scales in \e s are clamped to \e eps
/// to allow computation of \e u.
GF_API
bool Factor(GfMatrix4f* r, GfVec3f* s, GfMatrix4f* u,
GfVec3f* t, GfMatrix4f* p,
float eps = 1e-5) const;
/// Returns the translation part of the matrix, defined as the first three
/// elements of the last row.
GfVec3f ExtractTranslation() const {
return GfVec3f(_mtx[3][0], _mtx[3][1], _mtx[3][2]);
}
/// Returns the rotation corresponding to this matrix. This works well
/// only if the matrix represents a rotation.
///
/// For good results, consider calling Orthonormalize() before calling
/// this method.
GF_API
GfRotation ExtractRotation() const;
/// Return the rotation corresponding to this matrix as a quaternion.
/// This works well only if the matrix represents a rotation.
///
/// For good results, consider calling Orthonormalize() before calling
/// this method.
GF_API
GfQuatf ExtractRotationQuat() const;
/// Decompose the rotation corresponding to this matrix about 3 orthogonal
/// axes. If the axes are not orthogonal, warnings will be spewed.
///
/// This is a convenience method that is equivalent to calling
/// ExtractRotation().Decompose().
GF_API
GfVec3f DecomposeRotation(const GfVec3f &axis0,
const GfVec3f &axis1,
const GfVec3f &axis2) const;
/// Returns the rotation corresponding to this matrix. This works well
/// only if the matrix represents a rotation.
///
/// For good results, consider calling Orthonormalize() before calling
/// this method.
GF_API
GfMatrix3f ExtractRotationMatrix() const;
/// Transforms the row vector \e vec by the matrix, returning the result.
/// This treats the vector as a 4-component vector whose fourth component
/// is 1.
GfVec3d Transform(const GfVec3d &vec) const {
return GfProject(GfVec4d(
vec[0] * _mtx[0][0] + vec[1] * _mtx[1][0] + vec[2] * _mtx[2][0] + _mtx[3][0],
vec[0] * _mtx[0][1] + vec[1] * _mtx[1][1] + vec[2] * _mtx[2][1] + _mtx[3][1],
vec[0] * _mtx[0][2] + vec[1] * _mtx[1][2] + vec[2] * _mtx[2][2] + _mtx[3][2],
vec[0] * _mtx[0][3] + vec[1] * _mtx[1][3] + vec[2] * _mtx[2][3] + _mtx[3][3]));
}
/// Transforms the row vector \e vec by the matrix, returning the result.
/// This treats the vector as a 4-component vector whose fourth component
/// is 1. This is an overloaded method; it differs from the other version
/// in that it returns a different value type.
GfVec3f Transform(const GfVec3f &vec) const {
return (GfProject(GfVec4f(
vec[0] * _mtx[0][0] + vec[1] * _mtx[1][0] + vec[2] * _mtx[2][0] + _mtx[3][0],
vec[0] * _mtx[0][1] + vec[1] * _mtx[1][1] + vec[2] * _mtx[2][1] + _mtx[3][1],
vec[0] * _mtx[0][2] + vec[1] * _mtx[1][2] + vec[2] * _mtx[2][2] + _mtx[3][2],
vec[0] * _mtx[0][3] + vec[1] * _mtx[1][3] + vec[2] * _mtx[2][3] + _mtx[3][3])));
}
/// Transforms row vector \e vec by the matrix, returning the result. This
/// treats the vector as a direction vector, so the translation
/// information in the matrix is ignored. That is, it treats the vector as
/// a 4-component vector whose fourth component is 0.
GfVec3d TransformDir(const GfVec3d &vec) const {
return GfVec3d(
vec[0] * _mtx[0][0] + vec[1] * _mtx[1][0] + vec[2] * _mtx[2][0],
vec[0] * _mtx[0][1] + vec[1] * _mtx[1][1] + vec[2] * _mtx[2][1],
vec[0] * _mtx[0][2] + vec[1] * _mtx[1][2] + vec[2] * _mtx[2][2]);
}
/// Transforms row vector \e vec by the matrix, returning the result. This
/// treats the vector as a direction vector, so the translation
/// information in the matrix is ignored. That is, it treats the vector as
/// a 4-component vector whose fourth component is 0. This is an
/// overloaded method; it differs from the other version in that it
/// returns a different value type.
GfVec3f TransformDir(const GfVec3f &vec) const {
return GfVec3f(
vec[0] * _mtx[0][0] + vec[1] * _mtx[1][0] + vec[2] * _mtx[2][0],
vec[0] * _mtx[0][1] + vec[1] * _mtx[1][1] + vec[2] * _mtx[2][1],
vec[0] * _mtx[0][2] + vec[1] * _mtx[1][2] + vec[2] * _mtx[2][2]);
}
/// Transforms the row vector \e vec by the matrix, returning the result.
/// This treats the vector as a 4-component vector whose fourth component
/// is 1 and ignores the fourth column of the matrix (i.e. assumes it is
/// (0, 0, 0, 1)).
GfVec3d TransformAffine(const GfVec3d &vec) const {
return GfVec3d(
vec[0] * _mtx[0][0] + vec[1] * _mtx[1][0] + vec[2] * _mtx[2][0] + _mtx[3][0],
vec[0] * _mtx[0][1] + vec[1] * _mtx[1][1] + vec[2] * _mtx[2][1] + _mtx[3][1],
vec[0] * _mtx[0][2] + vec[1] * _mtx[1][2] + vec[2] * _mtx[2][2] + _mtx[3][2]);
}
/// Transforms the row vector \e vec by the matrix, returning the result.
/// This treats the vector as a 4-component vector whose fourth component
/// is 1 and ignores the fourth column of the matrix (i.e. assumes it is
/// (0, 0, 0, 1)).
GfVec3f TransformAffine(const GfVec3f &vec) const {
return GfVec3f(
vec[0] * _mtx[0][0] + vec[1] * _mtx[1][0] + vec[2] * _mtx[2][0] + _mtx[3][0],
vec[0] * _mtx[0][1] + vec[1] * _mtx[1][1] + vec[2] * _mtx[2][1] + _mtx[3][1],
vec[0] * _mtx[0][2] + vec[1] * _mtx[1][2] + vec[2] * _mtx[2][2] + _mtx[3][2]);
}
/// @}
private:
/// Returns the determinant of the 3x3 submatrix specified by the three
/// given row and column indices (0-3 for each).
GF_API
double _GetDeterminant3(size_t row1, size_t row2, size_t row3,
size_t col1, size_t col2, size_t col3) const;
/// Diagonalizes the upper 3x3 matrix of a matrix known to be symmetric.
void _Jacobi3(GfVec3d *eigenvalues, GfVec3d eigenvectors[3]) const;
/// Set the 3x3 submatrix to the rotation given by a quaternion,
/// defined by the real component \p r and imaginary components \p i.
void _SetRotateFromQuat(float r, const GfVec3f& i);
private:
/// Matrix storage, in row-major order.
GfMatrixData<float, 4, 4> _mtx;
// Friend declarations
friend class GfMatrix4d;
};
/// Tests for equality within a given tolerance, returning \c true if the
/// difference between each component of the matrix is less than or equal
/// to \p tolerance, or false otherwise.
GF_API
bool GfIsClose(GfMatrix4f const &m1, GfMatrix4f const &m2, double tolerance);
/// Output a GfMatrix4f
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream &, GfMatrix4f const &);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_MATRIX4F_H
+66
View File
@@ -0,0 +1,66 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_GF_MATRIX_DATA_H
#define PXR_BASE_GF_MATRIX_DATA_H
#include "pxr/pxr.h"
#include "pxr/base/gf/api.h"
PXR_NAMESPACE_OPEN_SCOPE
/// \class GfMatrixData
///
/// A class template used by GfMatrixXX to store values.
template <class T, int Rows, int Columns>
class GfMatrixData {
public:
/// Return a pointer to a \a row of data.
T *operator[](int row) {
return _data + (row * Columns);
}
/// Return a const pointer to a \a row of data.
T const *operator[](int row) const {
return _data + (row * Columns);
}
/// Return a pointer to the start of all the data.
T *GetData() {
return _data;
}
/// Return a const pointer to the start of all the data.
T const *GetData() const {
return _data;
}
private:
T _data[Rows * Columns];
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_MATRIX_DATA_H
+183
View File
@@ -0,0 +1,183 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_GF_MULTI_INTERVAL_H
#define PXR_BASE_GF_MULTI_INTERVAL_H
/// \file gf/multiInterval.h
/// \ingroup group_gf_BasicMath
#include "pxr/pxr.h"
#include "pxr/base/gf/interval.h"
#include "pxr/base/gf/api.h"
#include <iosfwd>
#include <set>
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
/// \class GfMultiInterval
/// \ingroup group_gf_BasicMath
///
/// GfMultiInterval represents a subset of the real number line as an
/// ordered set of non-intersecting GfIntervals.
///
class GfMultiInterval
{
public:
typedef std::set<GfInterval> Set;
typedef Set::const_iterator const_iterator;
typedef Set::const_iterator iterator;
/// \name Constructors
/// @{
/// Constructs an empty multi-interval.
GfMultiInterval() = default;
/// Constructs an multi-interval with the single given interval.
GF_API explicit GfMultiInterval(const GfInterval &i);
/// Constructs an multi-interval containing the given input intervals.
GF_API explicit GfMultiInterval(const std::vector<GfInterval> &intervals);
/// @}
GF_API bool operator==(const GfMultiInterval &that) const { return _set == that._set; }
GF_API bool operator!=(const GfMultiInterval &that) const { return !(*this == that); }
GF_API bool operator<(const GfMultiInterval &that) const { return _set < that._set; }
GF_API bool operator>=(const GfMultiInterval &that) const { return !(*this < that); }
GF_API bool operator>(const GfMultiInterval &that) const { return (that < *this); }
GF_API bool operator<=(const GfMultiInterval &that) const { return !(that < *this); }
/// Hash value.
/// Just a basic hash function, not particularly high quality.
GF_API size_t Hash() const;
friend inline size_t hash_value(const GfMultiInterval &mi) {
return mi.Hash();
}
/// \name Accessors
/// @{
/// Returns true if the multi-interval is empty.
GF_API bool IsEmpty() const { return _set.empty(); }
/// Returns the number of intervals in the set.
GF_API size_t GetSize() const { return _set.size(); }
/// Returns an interval bounding the entire multi-interval.
/// Returns an empty interval if the multi-interval is empty.
GF_API GfInterval GetBounds() const;
/// Returns true if the multi-interval contains the given value.
GF_API bool Contains(double d) const;
/// Returns true if the multi-interval contains the given interval.
GF_API bool Contains(const GfInterval & i) const;
/// Returns true if the multi-interval contains all the intervals in the
/// given multi-interval.
GF_API bool Contains(const GfMultiInterval & s) const;
/// @}
/// \name Mutation
/// @{
/// Clear the multi-interval.
GF_API void Clear() { _set.clear(); }
/// Add the given interval to the multi-interval.
GF_API void Add( const GfInterval & i );
/// Add the given multi-interval to the multi-interval.
/// Sets this object to the union of the two sets.
GF_API void Add( const GfMultiInterval &s );
/// Uses the given interval to extend the multi-interval in
/// the interval arithmetic sense.
GF_API void ArithmeticAdd( const GfInterval &i );
/// Remove the given interval from this multi-interval.
GF_API void Remove( const GfInterval & i );
/// Remove the given multi-interval from this multi-interval.
GF_API void Remove( const GfMultiInterval &s );
GF_API void Intersect( const GfInterval & i );
GF_API void Intersect( const GfMultiInterval &s );
/// Return the complement of this set.
GF_API GfMultiInterval GetComplement() const;
/// @}
/// \name Iteration
/// Only const iterators are returned. To maintain the invariants of
/// the multi-interval, changes must be made via the public mutation API.
/// @{
GF_API const_iterator begin() const { return _set.begin(); }
GF_API const_iterator end() const { return _set.end(); }
/// Returns an iterator identifying the first (lowest) interval whose
/// minimum value is >= x. If no such interval exists, returns end().
GF_API const_iterator lower_bound( double x ) const;
/// Returns an iterator identifying the first (lowest) interval whose
/// minimum value is > x. If no such interval exists, returns end().
GF_API const_iterator upper_bound( double x ) const;
/// Returns an iterator identifying the first (loest) interval whose
/// minimum value is > x. If no such interval exists, returns end().
GF_API const_iterator GetNextNonContainingInterval( double x ) const;
/// Returns an iterator identifying the last (highest) interval whose
/// maximum value is < x. If no such interval exists, returns end().
GF_API const_iterator GetPriorNonContainingInterval( double x ) const;
/// Returns an iterator identifying the interval that contains x. If
/// no interval contains x, then it returns end()
GF_API const_iterator GetContainingInterval( double x ) const;
/// @}
/// Returns the full interval (-inf, inf).
static GfMultiInterval GetFullInterval() {
return GfMultiInterval(GfInterval::GetFullInterval());
}
/// Swap two multi-intervals
void swap(GfMultiInterval &other) { _set.swap(other._set); }
private:
void _AssertInvariants() const;
Set _set;
};
/// Output a GfMultiInterval
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream & operator<<(std::ostream &out, const GfMultiInterval &s);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_MULTI_INTERVAL_H
+215
View File
@@ -0,0 +1,215 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_GF_PLANE_H
#define PXR_BASE_GF_PLANE_H
/// \file gf/plane.h
/// \ingroup group_gf_BasicGeometry
#include "pxr/pxr.h"
#include "pxr/base/gf/vec3d.h"
#include "pxr/base/gf/api.h"
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
class GfRange3d;
class GfMatrix4d;
class GfVec4d;
/// \class GfPlane
/// \ingroup group_gf_BasicGeometry
///
/// Basic type: 3-dimensional plane
///
/// This class represents a three-dimensional plane as a normal vector
/// and the distance of the plane from the origin, measured along the
/// normal. The plane can also be used to represent a half-space: the
/// side of the plane in the direction of the normal.
///
class GfPlane
{
public:
/// The default constructor leaves the plane parameters undefined.
GfPlane() {
}
/// This constructor sets this to the plane perpendicular to \p normal and
/// at \p distance units from the origin. The passed-in normal is
/// normalized to unit length first.
GfPlane(const GfVec3d &normal, double distanceToOrigin) {
Set(normal, distanceToOrigin);
}
/// This constructor sets this to the plane perpendicular to \p normal and
/// that passes through \p point. The passed-in normal is normalized to
/// unit length first.
GfPlane(const GfVec3d &normal, const GfVec3d &point) {
Set(normal, point);
}
/// This constructor sets this to the plane that contains the three given
/// points. The normal is constructed from the cross product of (\p p1 -
/// \p p0) (\p p2 - \p p0). Results are undefined if the points are
/// collinear.
GfPlane(const GfVec3d &p0, const GfVec3d &p1, const GfVec3d &p2) {
Set(p0, p1, p2);
}
/// This constructor creates a plane given by the equation
/// \p eqn[0] * x + \p eqn[1] * y + \p eqn[2] * z + \p eqn[3] = 0.
GfPlane(const GfVec4d &eqn) {
Set(eqn);
}
/// Sets this to the plane perpendicular to \p normal and at \p distance
/// units from the origin. The passed-in normal is normalized to unit
/// length first.
void Set(const GfVec3d &normal, double distanceToOrigin) {
_normal = normal.GetNormalized();
_distance = distanceToOrigin;
}
/// This constructor sets this to the plane perpendicular to \p normal and
/// that passes through \p point. The passed-in normal is normalized to
/// unit length first.
GF_API
void Set(const GfVec3d &normal, const GfVec3d &point);
/// This constructor sets this to the plane that contains the three given
/// points. The normal is constructed from the cross product of (\p p1 -
/// \p p0) (\p p2 - \p p0). Results are undefined if the points are
/// collinear.
GF_API
void Set(const GfVec3d &p0,
const GfVec3d &p1,
const GfVec3d &p2);
/// This method sets this to the plane given by the equation
/// \p eqn[0] * x + \p eqn[1] * y + \p eqn[2] * z + \p eqn[3] = 0.
GF_API
void Set(const GfVec4d &eqn);
/// Returns the unit-length normal vector of the plane.
const GfVec3d & GetNormal() const {
return _normal;
}
/// Returns the distance of the plane from the origin.
double GetDistanceFromOrigin() const {
return _distance;
}
/// Give the coefficients of the equation of the plane. Suitable
/// to OpenGL calls to set the clipping plane.
GF_API
GfVec4d GetEquation() const;
/// Component-wise equality test. The normals and distances must match
/// exactly for planes to be considered equal.
bool operator ==(const GfPlane &p) const {
return (_normal == p._normal &&
_distance == p._distance);
}
/// Component-wise inequality test. The normals and distances must match
/// exactly for planes to be considered equal.
bool operator !=(const GfPlane &p) const {
return ! (*this == p);
}
/// Returns the distance of point \p from the plane. This distance will be
/// positive if the point is on the side of the plane containing the
/// normal.
double GetDistance(const GfVec3d &p) const {
return p * _normal - _distance;
}
/// Return the projection of \p p onto the plane.
GfVec3d Project(const GfVec3d& p) const {
return p - GetDistance(p) * _normal;
}
/// Transforms the plane by the given matrix.
GF_API
GfPlane & Transform(const GfMatrix4d &matrix);
/// Flip the plane normal (if necessary) so that \p p is in the positive
/// halfspace.
void Reorient(const GfVec3d& p) {
if (GetDistance(p) < 0) {
_normal = -_normal;
_distance = -_distance;
}
}
/// Returns \c true if the given aligned bounding box is at least
/// partially on the positive side (the one the normal points into) of the
/// plane.
GF_API
bool IntersectsPositiveHalfSpace(const GfRange3d &box) const;
/// Returns true if the given point is on the plane or within its positive
/// half space.
bool IntersectsPositiveHalfSpace(const GfVec3d &pt) const {
return GetDistance(pt) >= 0.0;
}
private:
/// The normal to the plane. Points in direction of half-space.
GfVec3d _normal;
/// Distance from the plane to the origin.
double _distance;
};
/// Fits a plane to the given \p points. There must be at least three points in
/// order to fit the plane; if the size of \p points is less than three, this
/// issues a coding error.
///
/// If the \p points are all collinear, then no plane can be determined, and
/// this function returns \c false. Otherwise, if the fitting is successful,
/// it returns \c true and sets \p *fitPlane to the fitted plane. If \p points
/// contains exactly three points, then the resulting plane is the exact plane
/// defined by the three points. If \p points contains more than three points,
/// then this function determines the best-fitting plane for the given points.
/// The orientation of the plane normal is arbitrary with regards to the
/// plane's positive and negative half-spaces; you can use GfPlane::Reorient()
/// to flip the plane if necessary.
///
/// The current implementation uses linear least squares and thus defines
/// "best-fitting" as minimizing the sum of the squares of the vertical
/// distances between points and the plane surface.
GF_API
bool GfFitPlaneToPoints(const std::vector<GfVec3d>& points, GfPlane* fitPlane);
/// Output a GfPlane using the format [(nx ny nz) distance].
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream&, const GfPlane&);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_PLANE_H
+42
View File
@@ -0,0 +1,42 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_GF_PY_BUFFER_UTILS_H
#define PXR_BASE_GF_PY_BUFFER_UTILS_H
#include "pxr/pxr.h"
#include "pxr/base/gf/api.h"
PXR_NAMESPACE_OPEN_SCOPE
////////////////////////////////////////////////////////////////////////
// Format strings matching Python buffer proto / struct module scheme.
// This function template is explicitly instantiated for T =
// bool, [unsigned] (char, short, int, long), half, float, and double.
template <class T>
char *Gf_GetPyBufferFmtFor();
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_PY_BUFFER_UTILS_H
+289
View File
@@ -0,0 +1,289 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// quat.template.h file to make changes.
#ifndef PXR_BASE_GF_QUATD_H
#define PXR_BASE_GF_QUATD_H
/// \file gf/quatd.h
/// \ingroup group_gf_LinearAlgebra
#include "pxr/pxr.h"
#include "pxr/base/gf/api.h"
#include "pxr/base/gf/declare.h"
#include "pxr/base/gf/vec3d.h"
#include "pxr/base/gf/traits.h"
#include <boost/functional/hash.hpp>
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
template <>
struct GfIsGfQuat<class GfQuatd> { static const bool value = true; };
/// Return the dot (inner) product of two quaternions.
double GfDot(const GfQuatd& q1, const GfQuatd& q2);
/// \class GfQuatd
/// \ingroup group_gf_LinearAlgebra
///
/// Basic type: a quaternion, a complex number with a real coefficient and
/// three imaginary coefficients, stored as a 3-vector.
///
class GfQuatd
{
public:
typedef double ScalarType;
typedef GfVec3d ImaginaryType;
/// Default constructor leaves the quaternion undefined.
GfQuatd() {}
/// Initialize the real coefficient to \p realVal and the imaginary
/// coefficients to zero.
///
/// Since quaternions typically must be normalized, reasonable values for
/// \p realVal are -1, 0, or 1. Other values are legal but are likely to
/// be meaningless.
///
explicit GfQuatd (double realVal) : _imaginary(0), _real(realVal) {}
/// Initialize the real and imaginary coefficients.
GfQuatd(double real, double i, double j, double k)
: _imaginary(i, j, k), _real(real)
{
}
/// Initialize the real and imaginary coefficients.
GfQuatd(double real, const GfVec3d &imaginary)
: _imaginary(imaginary), _real(real)
{
}
/// Implicitly convert from GfQuatf.
GF_API
GfQuatd(class GfQuatf const &other);
/// Implicitly convert from GfQuath.
GF_API
GfQuatd(class GfQuath const &other);
/// Return the identity quaternion, with real coefficient 1 and an
/// imaginary coefficients all zero.
static GfQuatd GetIdentity() { return GfQuatd(1.0); }
/// Return the real coefficient.
double GetReal() const { return _real; }
/// Set the real coefficient.
void SetReal(double real) { _real = real; }
/// Return the imaginary coefficient.
const GfVec3d &GetImaginary() const { return _imaginary; }
/// Set the imaginary coefficients.
void SetImaginary(const GfVec3d &imaginary) {
_imaginary = imaginary;
}
/// Set the imaginary coefficients.
void SetImaginary(double i, double j, double k) {
_imaginary.Set(i, j, k);
}
/// Return geometric length of this quaternion.
double GetLength() const { return GfSqrt(_GetLengthSquared()); }
/// length of this quaternion is smaller than \p eps, return the identity
/// quaternion.
GfQuatd
GetNormalized(double eps = GF_MIN_VECTOR_LENGTH) const {
GfQuatd ret(*this);
ret.Normalize(eps);
return ret;
}
/// Normalizes this quaternion in place to unit length, returning the
/// length before normalization. If the length of this quaternion is
/// smaller than \p eps, this sets the quaternion to identity.
GF_API
double Normalize(double eps = GF_MIN_VECTOR_LENGTH);
/// Return this quaternion's conjugate, which is the quaternion with the
/// same real coefficient and negated imaginary coefficients.
GfQuatd GetConjugate() const {
return GfQuatd(GetReal(), -GetImaginary());
}
/// Return this quaternion's inverse, or reciprocal. This is the
/// quaternion's conjugate divided by it's squared length.
GfQuatd GetInverse() const {
return GetConjugate() / _GetLengthSquared();
}
/// Transform the GfVec3d point. If the quaternion is normalized,
/// the transformation is a rotation. Given a GfQuatd q, q.Transform(point)
/// is equivalent to:
///
/// (q * GfQuatd(0, point) * q.GetInverse()).GetImaginary()
///
/// but is more efficient.
GF_API
GfVec3d Transform(const GfVec3d& point) const;
/// Hash.
friend inline size_t hash_value(const GfQuatd &q) {
size_t h = boost::hash<ScalarType>()(q.GetReal());
boost::hash_combine(h, q.GetImaginary());
return h;
}
/// Component-wise negation.
GfQuatd operator-() const {
return GfQuatd(-GetReal(), -GetImaginary());
}
/// Component-wise quaternion equality test. The real and imaginary parts
/// must match exactly for quaternions to be considered equal.
bool operator==(const GfQuatd &q) const {
return (GetReal() == q.GetReal() &&
GetImaginary() == q.GetImaginary());
}
/// Component-wise quaternion inequality test. The real and imaginary
/// parts must match exactly for quaternions to be considered equal.
bool operator!=(const GfQuatd &q) const {
return !(*this == q);
}
/// Post-multiply quaternion \p q into this quaternion.
GF_API
GfQuatd &operator *=(const GfQuatd &q);
/// Multiply this quaternion's coefficients by \p s.
GfQuatd &operator *=(double s) {
_real *= s;
_imaginary *= s;
return *this;
}
/// Divide this quaternion's coefficients by \p s.
GfQuatd &operator /=(double s) {
_real /= s;
_imaginary /= s;
return *this;
}
/// Add quaternion \p q to this quaternion.
GfQuatd &operator +=(const GfQuatd &q) {
_real += q._real;
_imaginary += q._imaginary;
return *this;
}
/// Component-wise unary difference operator.
GfQuatd &operator -=(const GfQuatd &q) {
_real -= q._real;
_imaginary -= q._imaginary;
return *this;
}
/// Component-wise binary sum operator.
friend GfQuatd
operator +(const GfQuatd &q1, const GfQuatd &q2) {
return GfQuatd(q1) += q2;
}
/// Component-wise binary difference operator.
friend GfQuatd
operator -(const GfQuatd &q1, const GfQuatd &q2) {
return GfQuatd(q1) -= q2;
}
/// Returns the product of quaternions \p q1 and \p q2.
friend GfQuatd
operator *(const GfQuatd &q1, const GfQuatd &q2) {
return GfQuatd(q1) *= q2;
}
/// Returns the product of quaternion \p q and scalar \p s.
friend GfQuatd
operator *(const GfQuatd &q, double s) {
return GfQuatd(q) *= s;
}
/// Returns the product of quaternion \p q and scalar \p s.
friend GfQuatd
operator *(double s, const GfQuatd &q) {
return GfQuatd(q) *= s;
}
/// Returns the product of quaternion \p q and scalar 1 / \p s.
friend GfQuatd
operator /(const GfQuatd &q, double s) {
return GfQuatd(q) /= s;
}
private:
/// Imaginary part
GfVec3d _imaginary;
/// Real part
double _real;
/// Returns the square of the length
double
_GetLengthSquared() const {
return GfDot(*this, *this);
}
};
/// Spherically linearly interpolate between \p q0 and \p q1.
///
/// If the interpolant \p alpha is zero, then the result is \p q0, while
/// \p alpha of one yields \p q1.
GF_API GfQuatd
GfSlerp(double alpha, const GfQuatd& q0, const GfQuatd& q1);
GF_API GfQuatd
GfSlerp(const GfQuatd& q0, const GfQuatd& q1, double alpha);
inline double
GfDot(GfQuatd const &q1, GfQuatd const &q2) {
return GfDot(q1.GetImaginary(), q2.GetImaginary()) +
q1.GetReal()*q2.GetReal();
}
/// Output a GfQuatd using the format (re, i, j, k)
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream &, GfQuatd const &);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_QUATD_H
+244
View File
@@ -0,0 +1,244 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_GF_QUATERNION_H
#define PXR_BASE_GF_QUATERNION_H
/// \file gf/quaternion.h
/// \ingroup group_gf_LinearAlgebra
#include "pxr/pxr.h"
#include "pxr/base/gf/api.h"
#include "pxr/base/gf/vec3d.h"
#include <boost/functional/hash.hpp>
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
/// \class GfQuaternion
/// \ingroup group_gf_LinearAlgebra
///
/// Basic type: complex number with scalar real part and vector imaginary
/// part.
///
/// This class represents a generalized complex number that has a scalar real
/// part and a vector of three imaginary values. Quaternions are used by the
/// \c GfRotation class to represent arbitrary-axis rotations.
///
class GfQuaternion
{
public:
/// The default constructor leaves the quaternion undefined.
GfQuaternion() {
}
/// This constructor initializes the real part to the argument and
/// the imaginary parts to zero.
///
/// Since quaternions typically need to be normalized, the only reasonable
/// values for \p realVal are -1, 0, or 1. Other values are legal but are
/// likely to be meaningless.
explicit GfQuaternion(int realVal)
: _real(realVal), _imaginary(0)
{
}
/// This constructor initializes the real and imaginary parts.
GfQuaternion(double real, const GfVec3d &imaginary)
: _real(real), _imaginary(imaginary) {
}
/// Sets the real part of the quaternion.
void SetReal(double real) {
_real = real;
}
/// Sets the imaginary part of the quaternion.
void SetImaginary(const GfVec3d &imaginary) {
_imaginary = imaginary;
}
/// Returns the real part of the quaternion.
double GetReal() const {
return _real;
}
/// Returns the imaginary part of the quaternion.
const GfVec3d & GetImaginary() const {
return _imaginary;
}
/// Returns the identity quaternion, which has a real part of 1 and
/// an imaginary part of (0,0,0).
static GfQuaternion GetIdentity() {
return GfQuaternion(1.0, GfVec3d(0.0, 0.0, 0.0));
}
/// Returns geometric length of this quaternion.
GF_API
double GetLength() const;
/// Returns a normalized (unit-length) version of this quaternion.
/// direction as this. If the length of this quaternion is smaller than \p
/// eps, this returns the identity quaternion.
GF_API
GfQuaternion GetNormalized(double eps = GF_MIN_VECTOR_LENGTH) const;
/// Normalizes this quaternion in place to unit length, returning the
/// length before normalization. If the length of this quaternion is
/// smaller than \p eps, this sets the quaternion to identity.
GF_API
double Normalize(double eps = GF_MIN_VECTOR_LENGTH);
/// Returns the inverse of this quaternion.
GF_API
GfQuaternion GetInverse() const;
/// Hash.
friend inline size_t hash_value(const GfQuaternion &q) {
size_t h = 0;
boost::hash_combine(h, q.GetReal());
boost::hash_combine(h, q.GetImaginary());
return h;
}
/// Component-wise quaternion equality test. The real and imaginary parts
/// must match exactly for quaternions to be considered equal.
bool operator ==(const GfQuaternion &q) const {
return (GetReal() == q.GetReal() &&
GetImaginary() == q.GetImaginary());
}
/// Component-wise quaternion inequality test. The real and imaginary
/// parts must match exactly for quaternions to be considered equal.
bool operator !=(const GfQuaternion &q) const {
return ! (*this == q);
}
/// Post-multiplies quaternion \p q into this quaternion.
GF_API
GfQuaternion & operator *=(const GfQuaternion &q);
/// Scales this quaternion by \p s.
GF_API
GfQuaternion & operator *=(double s);
/// Scales this quaternion by 1 / \p s.
GfQuaternion & operator /=(double s) {
return (*this) *= 1.0 / s;
}
/// Component-wise unary sum operator.
GfQuaternion & operator +=(const GfQuaternion &q) {
_real += q._real;
_imaginary += q._imaginary;
return *this;
}
/// Component-wise unary difference operator.
GfQuaternion & operator -=(const GfQuaternion &q) {
_real -= q._real;
_imaginary -= q._imaginary;
return *this;
}
/// Component-wise binary sum operator.
friend GfQuaternion operator +(const GfQuaternion &q1,
const GfQuaternion &q2) {
GfQuaternion qt = q1;
return qt += q2;
}
/// Component-wise binary difference operator.
friend GfQuaternion operator -(const GfQuaternion &q1,
const GfQuaternion &q2) {
GfQuaternion qt = q1;
return qt -= q2;
}
/// Returns the product of quaternions \p q1 and \p q2.
friend GfQuaternion operator *(const GfQuaternion &q1,
const GfQuaternion &q2) {
GfQuaternion qt = q1;
return qt *= q2;
}
/// Returns the product of quaternion \p q and scalar \p s.
friend GfQuaternion operator *(const GfQuaternion &q, double s) {
GfQuaternion qt = q;
return qt *= s;
}
/// Returns the product of quaternion \p q and scalar \p s.
friend GfQuaternion operator *(double s, const GfQuaternion &q) {
GfQuaternion qt = q;
return qt *= s;
}
/// Returns the product of quaternion \p q and scalar 1 / \p s.
friend GfQuaternion operator /(const GfQuaternion &q, double s) {
GfQuaternion qt = q;
return qt /= s;
}
/// Spherically interpolate between \p q0 and \p q1.
///
/// If the interpolant \p alpha
/// is zero, then the result is \p q0, while \p alpha of one yields
/// \p q1.
GF_API
friend GfQuaternion GfSlerp(double alpha,
const GfQuaternion& q0,
const GfQuaternion& q1);
// TODO Remove this legacy alias/overload.
friend GF_API GfQuaternion GfSlerp(const GfQuaternion& q0,
const GfQuaternion& q1,
double alpha);
private:
/// Real part
double _real;
/// Imaginary part
GfVec3d _imaginary;
/// Returns the square of the length
double _GetLengthSquared() const {
return (_real * _real + GfDot(_imaginary, _imaginary));
}
};
// Friend functions must be declared.
GF_API GfQuaternion GfSlerp(double alpha, const GfQuaternion& q0, const GfQuaternion& q1);
GF_API GfQuaternion GfSlerp(const GfQuaternion& q0, const GfQuaternion& q1, double alpha);
/// Output a GfQuaternion using the format (r + (x, y, z)).
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream& out, const GfQuaternion& q);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_QUATERNION_H
+289
View File
@@ -0,0 +1,289 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// quat.template.h file to make changes.
#ifndef PXR_BASE_GF_QUATF_H
#define PXR_BASE_GF_QUATF_H
/// \file gf/quatf.h
/// \ingroup group_gf_LinearAlgebra
#include "pxr/pxr.h"
#include "pxr/base/gf/api.h"
#include "pxr/base/gf/declare.h"
#include "pxr/base/gf/vec3f.h"
#include "pxr/base/gf/traits.h"
#include <boost/functional/hash.hpp>
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
template <>
struct GfIsGfQuat<class GfQuatf> { static const bool value = true; };
/// Return the dot (inner) product of two quaternions.
float GfDot(const GfQuatf& q1, const GfQuatf& q2);
/// \class GfQuatf
/// \ingroup group_gf_LinearAlgebra
///
/// Basic type: a quaternion, a complex number with a real coefficient and
/// three imaginary coefficients, stored as a 3-vector.
///
class GfQuatf
{
public:
typedef float ScalarType;
typedef GfVec3f ImaginaryType;
/// Default constructor leaves the quaternion undefined.
GfQuatf() {}
/// Initialize the real coefficient to \p realVal and the imaginary
/// coefficients to zero.
///
/// Since quaternions typically must be normalized, reasonable values for
/// \p realVal are -1, 0, or 1. Other values are legal but are likely to
/// be meaningless.
///
explicit GfQuatf (float realVal) : _imaginary(0), _real(realVal) {}
/// Initialize the real and imaginary coefficients.
GfQuatf(float real, float i, float j, float k)
: _imaginary(i, j, k), _real(real)
{
}
/// Initialize the real and imaginary coefficients.
GfQuatf(float real, const GfVec3f &imaginary)
: _imaginary(imaginary), _real(real)
{
}
/// Construct from GfQuatd.
GF_API
explicit GfQuatf(class GfQuatd const &other);
/// Implicitly convert from GfQuath.
GF_API
GfQuatf(class GfQuath const &other);
/// Return the identity quaternion, with real coefficient 1 and an
/// imaginary coefficients all zero.
static GfQuatf GetIdentity() { return GfQuatf(1.0); }
/// Return the real coefficient.
float GetReal() const { return _real; }
/// Set the real coefficient.
void SetReal(float real) { _real = real; }
/// Return the imaginary coefficient.
const GfVec3f &GetImaginary() const { return _imaginary; }
/// Set the imaginary coefficients.
void SetImaginary(const GfVec3f &imaginary) {
_imaginary = imaginary;
}
/// Set the imaginary coefficients.
void SetImaginary(float i, float j, float k) {
_imaginary.Set(i, j, k);
}
/// Return geometric length of this quaternion.
float GetLength() const { return GfSqrt(_GetLengthSquared()); }
/// length of this quaternion is smaller than \p eps, return the identity
/// quaternion.
GfQuatf
GetNormalized(float eps = GF_MIN_VECTOR_LENGTH) const {
GfQuatf ret(*this);
ret.Normalize(eps);
return ret;
}
/// Normalizes this quaternion in place to unit length, returning the
/// length before normalization. If the length of this quaternion is
/// smaller than \p eps, this sets the quaternion to identity.
GF_API
float Normalize(float eps = GF_MIN_VECTOR_LENGTH);
/// Return this quaternion's conjugate, which is the quaternion with the
/// same real coefficient and negated imaginary coefficients.
GfQuatf GetConjugate() const {
return GfQuatf(GetReal(), -GetImaginary());
}
/// Return this quaternion's inverse, or reciprocal. This is the
/// quaternion's conjugate divided by it's squared length.
GfQuatf GetInverse() const {
return GetConjugate() / _GetLengthSquared();
}
/// Transform the GfVec3f point. If the quaternion is normalized,
/// the transformation is a rotation. Given a GfQuatf q, q.Transform(point)
/// is equivalent to:
///
/// (q * GfQuatf(0, point) * q.GetInverse()).GetImaginary()
///
/// but is more efficient.
GF_API
GfVec3f Transform(const GfVec3f& point) const;
/// Hash.
friend inline size_t hash_value(const GfQuatf &q) {
size_t h = boost::hash<ScalarType>()(q.GetReal());
boost::hash_combine(h, q.GetImaginary());
return h;
}
/// Component-wise negation.
GfQuatf operator-() const {
return GfQuatf(-GetReal(), -GetImaginary());
}
/// Component-wise quaternion equality test. The real and imaginary parts
/// must match exactly for quaternions to be considered equal.
bool operator==(const GfQuatf &q) const {
return (GetReal() == q.GetReal() &&
GetImaginary() == q.GetImaginary());
}
/// Component-wise quaternion inequality test. The real and imaginary
/// parts must match exactly for quaternions to be considered equal.
bool operator!=(const GfQuatf &q) const {
return !(*this == q);
}
/// Post-multiply quaternion \p q into this quaternion.
GF_API
GfQuatf &operator *=(const GfQuatf &q);
/// Multiply this quaternion's coefficients by \p s.
GfQuatf &operator *=(float s) {
_real *= s;
_imaginary *= s;
return *this;
}
/// Divide this quaternion's coefficients by \p s.
GfQuatf &operator /=(float s) {
_real /= s;
_imaginary /= s;
return *this;
}
/// Add quaternion \p q to this quaternion.
GfQuatf &operator +=(const GfQuatf &q) {
_real += q._real;
_imaginary += q._imaginary;
return *this;
}
/// Component-wise unary difference operator.
GfQuatf &operator -=(const GfQuatf &q) {
_real -= q._real;
_imaginary -= q._imaginary;
return *this;
}
/// Component-wise binary sum operator.
friend GfQuatf
operator +(const GfQuatf &q1, const GfQuatf &q2) {
return GfQuatf(q1) += q2;
}
/// Component-wise binary difference operator.
friend GfQuatf
operator -(const GfQuatf &q1, const GfQuatf &q2) {
return GfQuatf(q1) -= q2;
}
/// Returns the product of quaternions \p q1 and \p q2.
friend GfQuatf
operator *(const GfQuatf &q1, const GfQuatf &q2) {
return GfQuatf(q1) *= q2;
}
/// Returns the product of quaternion \p q and scalar \p s.
friend GfQuatf
operator *(const GfQuatf &q, float s) {
return GfQuatf(q) *= s;
}
/// Returns the product of quaternion \p q and scalar \p s.
friend GfQuatf
operator *(float s, const GfQuatf &q) {
return GfQuatf(q) *= s;
}
/// Returns the product of quaternion \p q and scalar 1 / \p s.
friend GfQuatf
operator /(const GfQuatf &q, float s) {
return GfQuatf(q) /= s;
}
private:
/// Imaginary part
GfVec3f _imaginary;
/// Real part
float _real;
/// Returns the square of the length
float
_GetLengthSquared() const {
return GfDot(*this, *this);
}
};
/// Spherically linearly interpolate between \p q0 and \p q1.
///
/// If the interpolant \p alpha is zero, then the result is \p q0, while
/// \p alpha of one yields \p q1.
GF_API GfQuatf
GfSlerp(double alpha, const GfQuatf& q0, const GfQuatf& q1);
GF_API GfQuatf
GfSlerp(const GfQuatf& q0, const GfQuatf& q1, double alpha);
inline float
GfDot(GfQuatf const &q1, GfQuatf const &q2) {
return GfDot(q1.GetImaginary(), q2.GetImaginary()) +
q1.GetReal()*q2.GetReal();
}
/// Output a GfQuatd using the format (re, i, j, k)
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream &, GfQuatf const &);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_QUATF_H
+290
View File
@@ -0,0 +1,290 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// quat.template.h file to make changes.
#ifndef PXR_BASE_GF_QUATH_H
#define PXR_BASE_GF_QUATH_H
/// \file gf/quath.h
/// \ingroup group_gf_LinearAlgebra
#include "pxr/pxr.h"
#include "pxr/base/gf/api.h"
#include "pxr/base/gf/declare.h"
#include "pxr/base/gf/vec3h.h"
#include "pxr/base/gf/traits.h"
#include "pxr/base/gf/half.h"
#include <boost/functional/hash.hpp>
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
template <>
struct GfIsGfQuat<class GfQuath> { static const bool value = true; };
/// Return the dot (inner) product of two quaternions.
GfHalf GfDot(const GfQuath& q1, const GfQuath& q2);
/// \class GfQuath
/// \ingroup group_gf_LinearAlgebra
///
/// Basic type: a quaternion, a complex number with a real coefficient and
/// three imaginary coefficients, stored as a 3-vector.
///
class GfQuath
{
public:
typedef GfHalf ScalarType;
typedef GfVec3h ImaginaryType;
/// Default constructor leaves the quaternion undefined.
GfQuath() {}
/// Initialize the real coefficient to \p realVal and the imaginary
/// coefficients to zero.
///
/// Since quaternions typically must be normalized, reasonable values for
/// \p realVal are -1, 0, or 1. Other values are legal but are likely to
/// be meaningless.
///
explicit GfQuath (GfHalf realVal) : _imaginary(0), _real(realVal) {}
/// Initialize the real and imaginary coefficients.
GfQuath(GfHalf real, GfHalf i, GfHalf j, GfHalf k)
: _imaginary(i, j, k), _real(real)
{
}
/// Initialize the real and imaginary coefficients.
GfQuath(GfHalf real, const GfVec3h &imaginary)
: _imaginary(imaginary), _real(real)
{
}
/// Construct from GfQuatd.
GF_API
explicit GfQuath(class GfQuatd const &other);
/// Construct from GfQuatf.
GF_API
explicit GfQuath(class GfQuatf const &other);
/// Return the identity quaternion, with real coefficient 1 and an
/// imaginary coefficients all zero.
static GfQuath GetIdentity() { return GfQuath(1.0); }
/// Return the real coefficient.
GfHalf GetReal() const { return _real; }
/// Set the real coefficient.
void SetReal(GfHalf real) { _real = real; }
/// Return the imaginary coefficient.
const GfVec3h &GetImaginary() const { return _imaginary; }
/// Set the imaginary coefficients.
void SetImaginary(const GfVec3h &imaginary) {
_imaginary = imaginary;
}
/// Set the imaginary coefficients.
void SetImaginary(GfHalf i, GfHalf j, GfHalf k) {
_imaginary.Set(i, j, k);
}
/// Return geometric length of this quaternion.
GfHalf GetLength() const { return GfSqrt(_GetLengthSquared()); }
/// length of this quaternion is smaller than \p eps, return the identity
/// quaternion.
GfQuath
GetNormalized(GfHalf eps = GF_MIN_VECTOR_LENGTH) const {
GfQuath ret(*this);
ret.Normalize(eps);
return ret;
}
/// Normalizes this quaternion in place to unit length, returning the
/// length before normalization. If the length of this quaternion is
/// smaller than \p eps, this sets the quaternion to identity.
GF_API
GfHalf Normalize(GfHalf eps = GF_MIN_VECTOR_LENGTH);
/// Return this quaternion's conjugate, which is the quaternion with the
/// same real coefficient and negated imaginary coefficients.
GfQuath GetConjugate() const {
return GfQuath(GetReal(), -GetImaginary());
}
/// Return this quaternion's inverse, or reciprocal. This is the
/// quaternion's conjugate divided by it's squared length.
GfQuath GetInverse() const {
return GetConjugate() / _GetLengthSquared();
}
/// Transform the GfVec3h point. If the quaternion is normalized,
/// the transformation is a rotation. Given a GfQuath q, q.Transform(point)
/// is equivalent to:
///
/// (q * GfQuath(0, point) * q.GetInverse()).GetImaginary()
///
/// but is more efficient.
GF_API
GfVec3h Transform(const GfVec3h& point) const;
/// Hash.
friend inline size_t hash_value(const GfQuath &q) {
size_t h = boost::hash<ScalarType>()(q.GetReal());
boost::hash_combine(h, q.GetImaginary());
return h;
}
/// Component-wise negation.
GfQuath operator-() const {
return GfQuath(-GetReal(), -GetImaginary());
}
/// Component-wise quaternion equality test. The real and imaginary parts
/// must match exactly for quaternions to be considered equal.
bool operator==(const GfQuath &q) const {
return (GetReal() == q.GetReal() &&
GetImaginary() == q.GetImaginary());
}
/// Component-wise quaternion inequality test. The real and imaginary
/// parts must match exactly for quaternions to be considered equal.
bool operator!=(const GfQuath &q) const {
return !(*this == q);
}
/// Post-multiply quaternion \p q into this quaternion.
GF_API
GfQuath &operator *=(const GfQuath &q);
/// Multiply this quaternion's coefficients by \p s.
GfQuath &operator *=(GfHalf s) {
_real *= s;
_imaginary *= s;
return *this;
}
/// Divide this quaternion's coefficients by \p s.
GfQuath &operator /=(GfHalf s) {
_real /= s;
_imaginary /= s;
return *this;
}
/// Add quaternion \p q to this quaternion.
GfQuath &operator +=(const GfQuath &q) {
_real += q._real;
_imaginary += q._imaginary;
return *this;
}
/// Component-wise unary difference operator.
GfQuath &operator -=(const GfQuath &q) {
_real -= q._real;
_imaginary -= q._imaginary;
return *this;
}
/// Component-wise binary sum operator.
friend GfQuath
operator +(const GfQuath &q1, const GfQuath &q2) {
return GfQuath(q1) += q2;
}
/// Component-wise binary difference operator.
friend GfQuath
operator -(const GfQuath &q1, const GfQuath &q2) {
return GfQuath(q1) -= q2;
}
/// Returns the product of quaternions \p q1 and \p q2.
friend GfQuath
operator *(const GfQuath &q1, const GfQuath &q2) {
return GfQuath(q1) *= q2;
}
/// Returns the product of quaternion \p q and scalar \p s.
friend GfQuath
operator *(const GfQuath &q, GfHalf s) {
return GfQuath(q) *= s;
}
/// Returns the product of quaternion \p q and scalar \p s.
friend GfQuath
operator *(GfHalf s, const GfQuath &q) {
return GfQuath(q) *= s;
}
/// Returns the product of quaternion \p q and scalar 1 / \p s.
friend GfQuath
operator /(const GfQuath &q, GfHalf s) {
return GfQuath(q) /= s;
}
private:
/// Imaginary part
GfVec3h _imaginary;
/// Real part
GfHalf _real;
/// Returns the square of the length
GfHalf
_GetLengthSquared() const {
return GfDot(*this, *this);
}
};
/// Spherically linearly interpolate between \p q0 and \p q1.
///
/// If the interpolant \p alpha is zero, then the result is \p q0, while
/// \p alpha of one yields \p q1.
GF_API GfQuath
GfSlerp(double alpha, const GfQuath& q0, const GfQuath& q1);
GF_API GfQuath
GfSlerp(const GfQuath& q0, const GfQuath& q1, double alpha);
inline GfHalf
GfDot(GfQuath const &q1, GfQuath const &q2) {
return GfDot(q1.GetImaginary(), q2.GetImaginary()) +
q1.GetReal()*q2.GetReal();
}
/// Output a GfQuatd using the format (re, i, j, k)
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream &, GfQuath const &);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_QUATH_H
+358
View File
@@ -0,0 +1,358 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// range.template.h file to make changes.
#ifndef PXR_BASE_GF_RANGE1D_H
#define PXR_BASE_GF_RANGE1D_H
/// \file gf/range1d.h
/// \ingroup group_gf_BasicGeometry
#include "pxr/pxr.h"
#include "pxr/base/gf/api.h"
#include "pxr/base/gf/traits.h"
#include <boost/functional/hash.hpp>
#include <cfloat>
#include <cstddef>
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
class GfRange1d;
class GfRange1f;
template <>
struct GfIsGfRange<class GfRange1d> { static const bool value = true; };
/// \class GfRange1d
/// \ingroup group_gf_BasicGeometry
///
/// Basic type: 1-dimensional floating point range.
///
/// This class represents a 1-dimensional range (or interval) All
/// operations are component-wise and conform to interval mathematics. An
/// empty range is one where max < min.
/// The default empty is [FLT_MAX,-FLT_MAX]
class GfRange1d
{
public:
/// Helper typedef.
typedef double MinMaxType;
static const size_t dimension = 1;
typedef MinMaxType ScalarType;
/// Sets the range to an empty interval
// TODO check whether this can be deprecated.
void inline SetEmpty() {
_min = FLT_MAX;
_max = -FLT_MAX;
}
/// The default constructor creates an empty range.
GfRange1d() {
SetEmpty();
}
/// This constructor initializes the minimum and maximum points.
GfRange1d(double min, double max)
: _min(min), _max(max)
{
}
/// Returns the minimum value of the range.
double GetMin() const { return _min; }
/// Returns the maximum value of the range.
double GetMax() const { return _max; }
/// Returns the size of the range.
double GetSize() const { return _max - _min; }
/// Returns the midpoint of the range, that is, 0.5*(min+max).
/// Note: this returns zero in the case of default-constructed ranges,
/// or ranges set via SetEmpty().
double GetMidpoint() const {
return static_cast<ScalarType>(0.5) * _min
+ static_cast<ScalarType>(0.5) * _max;
}
/// Sets the minimum value of the range.
void SetMin(double min) { _min = min; }
/// Sets the maximum value of the range.
void SetMax(double max) { _max = max; }
/// Returns whether the range is empty (max < min).
bool IsEmpty() const {
return _min > _max;
}
/// Modifies the range if necessary to surround the given value.
/// \deprecated Use UnionWith() instead.
void ExtendBy(double point) { UnionWith(point); }
/// Modifies the range if necessary to surround the given range.
/// \deprecated Use UnionWith() instead.
void ExtendBy(const GfRange1d &range) { UnionWith(range); }
/// Returns true if the \p point is located inside the range. As with all
/// operations of this type, the range is assumed to include its extrema.
bool Contains(double point) const {
return (point >= _min && point <= _max);
}
/// Returns true if the \p range is located entirely inside the range. As
/// with all operations of this type, the ranges are assumed to include
/// their extrema.
bool Contains(const GfRange1d &range) const {
return Contains(range._min) && Contains(range._max);
}
/// Returns true if the \p point is located inside the range. As with all
/// operations of this type, the range is assumed to include its extrema.
/// \deprecated Use Contains() instead.
bool IsInside(double point) const {
return Contains(point);
}
/// Returns true if the \p range is located entirely inside the range. As
/// with all operations of this type, the ranges are assumed to include
/// their extrema.
/// \deprecated Use Contains() instead.
bool IsInside(const GfRange1d &range) const {
return Contains(range);
}
/// Returns true if the \p range is located entirely outside the range. As
/// with all operations of this type, the ranges are assumed to include
/// their extrema.
bool IsOutside(const GfRange1d &range) const {
return (range._max < _min || range._min > _max);
}
/// Returns the smallest \c GfRange1d which contains both \p a and \p b.
static GfRange1d GetUnion(const GfRange1d &a, const GfRange1d &b) {
GfRange1d res = a;
_FindMin(res._min,b._min);
_FindMax(res._max,b._max);
return res;
}
/// Extend \p this to include \p b.
const GfRange1d &UnionWith(const GfRange1d &b) {
_FindMin(_min,b._min);
_FindMax(_max,b._max);
return *this;
}
/// Extend \p this to include \p b.
const GfRange1d &UnionWith(double b) {
_FindMin(_min,b);
_FindMax(_max,b);
return *this;
}
/// Returns the smallest \c GfRange1d which contains both \p a and \p b
/// \deprecated Use GetUnion() instead.
static GfRange1d Union(const GfRange1d &a, const GfRange1d &b) {
return GetUnion(a, b);
}
/// Extend \p this to include \p b.
/// \deprecated Use UnionWith() instead.
const GfRange1d &Union(const GfRange1d &b) {
return UnionWith(b);
}
/// Extend \p this to include \p b.
/// \deprecated Use UnionWith() instead.
const GfRange1d &Union(double b) {
return UnionWith(b);
}
/// Returns a \c GfRange1d that describes the intersection of \p a and \p b.
static GfRange1d GetIntersection(const GfRange1d &a, const GfRange1d &b) {
GfRange1d res = a;
_FindMax(res._min,b._min);
_FindMin(res._max,b._max);
return res;
}
/// Returns a \c GfRange1d that describes the intersection of \p a and \p b.
/// \deprecated Use GetIntersection() instead.
static GfRange1d Intersection(const GfRange1d &a, const GfRange1d &b) {
return GetIntersection(a, b);
}
/// Modifies this range to hold its intersection with \p b and returns the
/// result
const GfRange1d &IntersectWith(const GfRange1d &b) {
_FindMax(_min,b._min);
_FindMin(_max,b._max);
return *this;
}
/// Modifies this range to hold its intersection with \p b and returns the
/// result.
/// \deprecated Use IntersectWith() instead.
const GfRange1d &Intersection(const GfRange1d &b) {
return IntersectWith(b);
}
/// unary sum.
GfRange1d operator +=(const GfRange1d &b) {
_min += b._min;
_max += b._max;
return *this;
}
/// unary difference.
GfRange1d operator -=(const GfRange1d &b) {
_min -= b._max;
_max -= b._min;
return *this;
}
/// unary multiply.
GfRange1d operator *=(double m) {
if (m > 0) {
_min *= m;
_max *= m;
} else {
double tmp = _min;
_min = _max * m;
_max = tmp * m;
}
return *this;
}
/// unary division.
GfRange1d operator /=(double m) {
return *this *= (1.0 / m);
}
/// binary sum.
GfRange1d operator +(const GfRange1d &b) const {
return GfRange1d(_min + b._min, _max + b._max);
}
/// binary difference.
GfRange1d operator -(const GfRange1d &b) const {
return GfRange1d(_min - b._max, _max - b._min);
}
/// scalar multiply.
friend GfRange1d operator *(double m, const GfRange1d &r) {
return (m > 0 ?
GfRange1d(r._min*m, r._max*m) :
GfRange1d(r._max*m, r._min*m));
}
/// scalar multiply.
friend GfRange1d operator *(const GfRange1d &r, double m) {
return (m > 0 ?
GfRange1d(r._min*m, r._max*m) :
GfRange1d(r._max*m, r._min*m));
}
/// scalar divide.
friend GfRange1d operator /(const GfRange1d &r, double m) {
return r * (1.0 / m);
}
/// hash.
friend inline size_t hash_value(const GfRange1d &r) {
size_t h = 0;
boost::hash_combine(h, r._min);
boost::hash_combine(h, r._max);
return h;
}
/// The min and max points must match exactly for equality.
bool operator ==(const GfRange1d &b) const {
return (_min == b._min && _max == b._max);
}
bool operator !=(const GfRange1d &b) const {
return !(*this == b);
}
/// Compare this range to a GfRange1f.
///
/// The values must match exactly and it does exactly what you might
/// expect when comparing float and double values.
GF_API inline bool operator ==(const GfRange1f& other) const;
GF_API inline bool operator !=(const GfRange1f& other) const;
/// Compute the squared distance from a point to the range.
GF_API
double GetDistanceSquared(double p) const;
private:
/// Minimum and maximum points.
double _min, _max;
/// Extends minimum point if necessary to contain given point.
static void _FindMin(double &dest, double point) {
if (point < dest) dest = point;
}
/// Extends maximum point if necessary to contain given point.
static void _FindMax(double &dest, double point) {
if (point > dest) dest = point;
}
};
/// Output a GfRange1d.
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream &, GfRange1d const &);
PXR_NAMESPACE_CLOSE_SCOPE
#include "pxr/base/gf/range1f.h"
PXR_NAMESPACE_OPEN_SCOPE
inline bool
GfRange1d::operator ==(const GfRange1f& other) const {
return _min == double(other.GetMin()) &&
_max == double(other.GetMax());
}
inline bool
GfRange1d::operator !=(const GfRange1f& other) const {
return !(*this == other);
}
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_RANGE1D_H
+358
View File
@@ -0,0 +1,358 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// range.template.h file to make changes.
#ifndef PXR_BASE_GF_RANGE1F_H
#define PXR_BASE_GF_RANGE1F_H
/// \file gf/range1f.h
/// \ingroup group_gf_BasicGeometry
#include "pxr/pxr.h"
#include "pxr/base/gf/api.h"
#include "pxr/base/gf/traits.h"
#include <boost/functional/hash.hpp>
#include <cfloat>
#include <cstddef>
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
class GfRange1d;
class GfRange1f;
template <>
struct GfIsGfRange<class GfRange1f> { static const bool value = true; };
/// \class GfRange1f
/// \ingroup group_gf_BasicGeometry
///
/// Basic type: 1-dimensional floating point range.
///
/// This class represents a 1-dimensional range (or interval) All
/// operations are component-wise and conform to interval mathematics. An
/// empty range is one where max < min.
/// The default empty is [FLT_MAX,-FLT_MAX]
class GfRange1f
{
public:
/// Helper typedef.
typedef float MinMaxType;
static const size_t dimension = 1;
typedef MinMaxType ScalarType;
/// Sets the range to an empty interval
// TODO check whether this can be deprecated.
void inline SetEmpty() {
_min = FLT_MAX;
_max = -FLT_MAX;
}
/// The default constructor creates an empty range.
GfRange1f() {
SetEmpty();
}
/// This constructor initializes the minimum and maximum points.
GfRange1f(float min, float max)
: _min(min), _max(max)
{
}
/// Returns the minimum value of the range.
float GetMin() const { return _min; }
/// Returns the maximum value of the range.
float GetMax() const { return _max; }
/// Returns the size of the range.
float GetSize() const { return _max - _min; }
/// Returns the midpoint of the range, that is, 0.5*(min+max).
/// Note: this returns zero in the case of default-constructed ranges,
/// or ranges set via SetEmpty().
float GetMidpoint() const {
return static_cast<ScalarType>(0.5) * _min
+ static_cast<ScalarType>(0.5) * _max;
}
/// Sets the minimum value of the range.
void SetMin(float min) { _min = min; }
/// Sets the maximum value of the range.
void SetMax(float max) { _max = max; }
/// Returns whether the range is empty (max < min).
bool IsEmpty() const {
return _min > _max;
}
/// Modifies the range if necessary to surround the given value.
/// \deprecated Use UnionWith() instead.
void ExtendBy(float point) { UnionWith(point); }
/// Modifies the range if necessary to surround the given range.
/// \deprecated Use UnionWith() instead.
void ExtendBy(const GfRange1f &range) { UnionWith(range); }
/// Returns true if the \p point is located inside the range. As with all
/// operations of this type, the range is assumed to include its extrema.
bool Contains(float point) const {
return (point >= _min && point <= _max);
}
/// Returns true if the \p range is located entirely inside the range. As
/// with all operations of this type, the ranges are assumed to include
/// their extrema.
bool Contains(const GfRange1f &range) const {
return Contains(range._min) && Contains(range._max);
}
/// Returns true if the \p point is located inside the range. As with all
/// operations of this type, the range is assumed to include its extrema.
/// \deprecated Use Contains() instead.
bool IsInside(float point) const {
return Contains(point);
}
/// Returns true if the \p range is located entirely inside the range. As
/// with all operations of this type, the ranges are assumed to include
/// their extrema.
/// \deprecated Use Contains() instead.
bool IsInside(const GfRange1f &range) const {
return Contains(range);
}
/// Returns true if the \p range is located entirely outside the range. As
/// with all operations of this type, the ranges are assumed to include
/// their extrema.
bool IsOutside(const GfRange1f &range) const {
return (range._max < _min || range._min > _max);
}
/// Returns the smallest \c GfRange1f which contains both \p a and \p b.
static GfRange1f GetUnion(const GfRange1f &a, const GfRange1f &b) {
GfRange1f res = a;
_FindMin(res._min,b._min);
_FindMax(res._max,b._max);
return res;
}
/// Extend \p this to include \p b.
const GfRange1f &UnionWith(const GfRange1f &b) {
_FindMin(_min,b._min);
_FindMax(_max,b._max);
return *this;
}
/// Extend \p this to include \p b.
const GfRange1f &UnionWith(float b) {
_FindMin(_min,b);
_FindMax(_max,b);
return *this;
}
/// Returns the smallest \c GfRange1f which contains both \p a and \p b
/// \deprecated Use GetUnion() instead.
static GfRange1f Union(const GfRange1f &a, const GfRange1f &b) {
return GetUnion(a, b);
}
/// Extend \p this to include \p b.
/// \deprecated Use UnionWith() instead.
const GfRange1f &Union(const GfRange1f &b) {
return UnionWith(b);
}
/// Extend \p this to include \p b.
/// \deprecated Use UnionWith() instead.
const GfRange1f &Union(float b) {
return UnionWith(b);
}
/// Returns a \c GfRange1f that describes the intersection of \p a and \p b.
static GfRange1f GetIntersection(const GfRange1f &a, const GfRange1f &b) {
GfRange1f res = a;
_FindMax(res._min,b._min);
_FindMin(res._max,b._max);
return res;
}
/// Returns a \c GfRange1f that describes the intersection of \p a and \p b.
/// \deprecated Use GetIntersection() instead.
static GfRange1f Intersection(const GfRange1f &a, const GfRange1f &b) {
return GetIntersection(a, b);
}
/// Modifies this range to hold its intersection with \p b and returns the
/// result
const GfRange1f &IntersectWith(const GfRange1f &b) {
_FindMax(_min,b._min);
_FindMin(_max,b._max);
return *this;
}
/// Modifies this range to hold its intersection with \p b and returns the
/// result.
/// \deprecated Use IntersectWith() instead.
const GfRange1f &Intersection(const GfRange1f &b) {
return IntersectWith(b);
}
/// unary sum.
GfRange1f operator +=(const GfRange1f &b) {
_min += b._min;
_max += b._max;
return *this;
}
/// unary difference.
GfRange1f operator -=(const GfRange1f &b) {
_min -= b._max;
_max -= b._min;
return *this;
}
/// unary multiply.
GfRange1f operator *=(double m) {
if (m > 0) {
_min *= m;
_max *= m;
} else {
float tmp = _min;
_min = _max * m;
_max = tmp * m;
}
return *this;
}
/// unary division.
GfRange1f operator /=(double m) {
return *this *= (1.0 / m);
}
/// binary sum.
GfRange1f operator +(const GfRange1f &b) const {
return GfRange1f(_min + b._min, _max + b._max);
}
/// binary difference.
GfRange1f operator -(const GfRange1f &b) const {
return GfRange1f(_min - b._max, _max - b._min);
}
/// scalar multiply.
friend GfRange1f operator *(double m, const GfRange1f &r) {
return (m > 0 ?
GfRange1f(r._min*m, r._max*m) :
GfRange1f(r._max*m, r._min*m));
}
/// scalar multiply.
friend GfRange1f operator *(const GfRange1f &r, double m) {
return (m > 0 ?
GfRange1f(r._min*m, r._max*m) :
GfRange1f(r._max*m, r._min*m));
}
/// scalar divide.
friend GfRange1f operator /(const GfRange1f &r, double m) {
return r * (1.0 / m);
}
/// hash.
friend inline size_t hash_value(const GfRange1f &r) {
size_t h = 0;
boost::hash_combine(h, r._min);
boost::hash_combine(h, r._max);
return h;
}
/// The min and max points must match exactly for equality.
bool operator ==(const GfRange1f &b) const {
return (_min == b._min && _max == b._max);
}
bool operator !=(const GfRange1f &b) const {
return !(*this == b);
}
/// Compare this range to a GfRange1d.
///
/// The values must match exactly and it does exactly what you might
/// expect when comparing float and double values.
GF_API inline bool operator ==(const GfRange1d& other) const;
GF_API inline bool operator !=(const GfRange1d& other) const;
/// Compute the squared distance from a point to the range.
GF_API
double GetDistanceSquared(float p) const;
private:
/// Minimum and maximum points.
float _min, _max;
/// Extends minimum point if necessary to contain given point.
static void _FindMin(float &dest, float point) {
if (point < dest) dest = point;
}
/// Extends maximum point if necessary to contain given point.
static void _FindMax(float &dest, float point) {
if (point > dest) dest = point;
}
};
/// Output a GfRange1f.
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream &, GfRange1f const &);
PXR_NAMESPACE_CLOSE_SCOPE
#include "pxr/base/gf/range1d.h"
PXR_NAMESPACE_OPEN_SCOPE
inline bool
GfRange1f::operator ==(const GfRange1d& other) const {
return _min == float(other.GetMin()) &&
_max == float(other.GetMax());
}
inline bool
GfRange1f::operator !=(const GfRange1d& other) const {
return !(*this == other);
}
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_RANGE1F_H
+377
View File
@@ -0,0 +1,377 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// range.template.h file to make changes.
#ifndef PXR_BASE_GF_RANGE2D_H
#define PXR_BASE_GF_RANGE2D_H
/// \file gf/range2d.h
/// \ingroup group_gf_BasicGeometry
#include "pxr/pxr.h"
#include "pxr/base/gf/api.h"
#include "pxr/base/gf/vec2d.h"
#include "pxr/base/gf/vec2f.h"
#include "pxr/base/gf/traits.h"
#include <boost/functional/hash.hpp>
#include <cfloat>
#include <cstddef>
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
class GfRange2d;
class GfRange2f;
template <>
struct GfIsGfRange<class GfRange2d> { static const bool value = true; };
/// \class GfRange2d
/// \ingroup group_gf_BasicGeometry
///
/// Basic type: 2-dimensional floating point range.
///
/// This class represents a 2-dimensional range (or interval) All
/// operations are component-wise and conform to interval mathematics. An
/// empty range is one where max < min.
/// The default empty is [FLT_MAX,-FLT_MAX]
class GfRange2d
{
public:
/// Helper typedef.
typedef GfVec2d MinMaxType;
static const size_t dimension = GfVec2d::dimension;
typedef GfVec2d::ScalarType ScalarType;
/// Sets the range to an empty interval
// TODO check whether this can be deprecated.
void inline SetEmpty() {
_min[0] = _min[1] = FLT_MAX;
_max[0] = _max[1] = -FLT_MAX;
}
/// The default constructor creates an empty range.
GfRange2d() {
SetEmpty();
}
/// This constructor initializes the minimum and maximum points.
GfRange2d(const GfVec2d &min, const GfVec2d &max)
: _min(min), _max(max)
{
}
/// Returns the minimum value of the range.
const GfVec2d &GetMin() const { return _min; }
/// Returns the maximum value of the range.
const GfVec2d &GetMax() const { return _max; }
/// Returns the size of the range.
GfVec2d GetSize() const { return _max - _min; }
/// Returns the midpoint of the range, that is, 0.5*(min+max).
/// Note: this returns zero in the case of default-constructed ranges,
/// or ranges set via SetEmpty().
GfVec2d GetMidpoint() const {
return static_cast<ScalarType>(0.5) * _min
+ static_cast<ScalarType>(0.5) * _max;
}
/// Sets the minimum value of the range.
void SetMin(const GfVec2d &min) { _min = min; }
/// Sets the maximum value of the range.
void SetMax(const GfVec2d &max) { _max = max; }
/// Returns whether the range is empty (max < min).
bool IsEmpty() const {
return _min[0] > _max[0] || _min[1] > _max[1];
}
/// Modifies the range if necessary to surround the given value.
/// \deprecated Use UnionWith() instead.
void ExtendBy(const GfVec2d &point) { UnionWith(point); }
/// Modifies the range if necessary to surround the given range.
/// \deprecated Use UnionWith() instead.
void ExtendBy(const GfRange2d &range) { UnionWith(range); }
/// Returns true if the \p point is located inside the range. As with all
/// operations of this type, the range is assumed to include its extrema.
bool Contains(const GfVec2d &point) const {
return (point[0] >= _min[0] && point[0] <= _max[0]
&& point[1] >= _min[1] && point[1] <= _max[1]);
}
/// Returns true if the \p range is located entirely inside the range. As
/// with all operations of this type, the ranges are assumed to include
/// their extrema.
bool Contains(const GfRange2d &range) const {
return Contains(range._min) && Contains(range._max);
}
/// Returns true if the \p point is located inside the range. As with all
/// operations of this type, the range is assumed to include its extrema.
/// \deprecated Use Contains() instead.
bool IsInside(const GfVec2d &point) const {
return Contains(point);
}
/// Returns true if the \p range is located entirely inside the range. As
/// with all operations of this type, the ranges are assumed to include
/// their extrema.
/// \deprecated Use Contains() instead.
bool IsInside(const GfRange2d &range) const {
return Contains(range);
}
/// Returns true if the \p range is located entirely outside the range. As
/// with all operations of this type, the ranges are assumed to include
/// their extrema.
bool IsOutside(const GfRange2d &range) const {
return ((range._max[0] < _min[0] || range._min[0] > _max[0])
|| (range._max[1] < _min[1] || range._min[1] > _max[1]));
}
/// Returns the smallest \c GfRange2d which contains both \p a and \p b.
static GfRange2d GetUnion(const GfRange2d &a, const GfRange2d &b) {
GfRange2d res = a;
_FindMin(res._min,b._min);
_FindMax(res._max,b._max);
return res;
}
/// Extend \p this to include \p b.
const GfRange2d &UnionWith(const GfRange2d &b) {
_FindMin(_min,b._min);
_FindMax(_max,b._max);
return *this;
}
/// Extend \p this to include \p b.
const GfRange2d &UnionWith(const GfVec2d &b) {
_FindMin(_min,b);
_FindMax(_max,b);
return *this;
}
/// Returns the smallest \c GfRange2d which contains both \p a and \p b
/// \deprecated Use GetUnion() instead.
static GfRange2d Union(const GfRange2d &a, const GfRange2d &b) {
return GetUnion(a, b);
}
/// Extend \p this to include \p b.
/// \deprecated Use UnionWith() instead.
const GfRange2d &Union(const GfRange2d &b) {
return UnionWith(b);
}
/// Extend \p this to include \p b.
/// \deprecated Use UnionWith() instead.
const GfRange2d &Union(const GfVec2d &b) {
return UnionWith(b);
}
/// Returns a \c GfRange2d that describes the intersection of \p a and \p b.
static GfRange2d GetIntersection(const GfRange2d &a, const GfRange2d &b) {
GfRange2d res = a;
_FindMax(res._min,b._min);
_FindMin(res._max,b._max);
return res;
}
/// Returns a \c GfRange2d that describes the intersection of \p a and \p b.
/// \deprecated Use GetIntersection() instead.
static GfRange2d Intersection(const GfRange2d &a, const GfRange2d &b) {
return GetIntersection(a, b);
}
/// Modifies this range to hold its intersection with \p b and returns the
/// result
const GfRange2d &IntersectWith(const GfRange2d &b) {
_FindMax(_min,b._min);
_FindMin(_max,b._max);
return *this;
}
/// Modifies this range to hold its intersection with \p b and returns the
/// result.
/// \deprecated Use IntersectWith() instead.
const GfRange2d &Intersection(const GfRange2d &b) {
return IntersectWith(b);
}
/// unary sum.
GfRange2d operator +=(const GfRange2d &b) {
_min += b._min;
_max += b._max;
return *this;
}
/// unary difference.
GfRange2d operator -=(const GfRange2d &b) {
_min -= b._max;
_max -= b._min;
return *this;
}
/// unary multiply.
GfRange2d operator *=(double m) {
if (m > 0) {
_min *= m;
_max *= m;
} else {
GfVec2d tmp = _min;
_min = _max * m;
_max = tmp * m;
}
return *this;
}
/// unary division.
GfRange2d operator /=(double m) {
return *this *= (1.0 / m);
}
/// binary sum.
GfRange2d operator +(const GfRange2d &b) const {
return GfRange2d(_min + b._min, _max + b._max);
}
/// binary difference.
GfRange2d operator -(const GfRange2d &b) const {
return GfRange2d(_min - b._max, _max - b._min);
}
/// scalar multiply.
friend GfRange2d operator *(double m, const GfRange2d &r) {
return (m > 0 ?
GfRange2d(r._min*m, r._max*m) :
GfRange2d(r._max*m, r._min*m));
}
/// scalar multiply.
friend GfRange2d operator *(const GfRange2d &r, double m) {
return (m > 0 ?
GfRange2d(r._min*m, r._max*m) :
GfRange2d(r._max*m, r._min*m));
}
/// scalar divide.
friend GfRange2d operator /(const GfRange2d &r, double m) {
return r * (1.0 / m);
}
/// hash.
friend inline size_t hash_value(const GfRange2d &r) {
size_t h = 0;
boost::hash_combine(h, r._min);
boost::hash_combine(h, r._max);
return h;
}
/// The min and max points must match exactly for equality.
bool operator ==(const GfRange2d &b) const {
return (_min == b._min && _max == b._max);
}
bool operator !=(const GfRange2d &b) const {
return !(*this == b);
}
/// Compare this range to a GfRange2f.
///
/// The values must match exactly and it does exactly what you might
/// expect when comparing float and double values.
GF_API inline bool operator ==(const GfRange2f& other) const;
GF_API inline bool operator !=(const GfRange2f& other) const;
/// Compute the squared distance from a point to the range.
GF_API
double GetDistanceSquared(const GfVec2d &p) const;
/// Returns the ith corner of the range, in the following order:
/// SW, SE, NW, NE.
GF_API
GfVec2d GetCorner(size_t i) const;
/// Returns the ith quadrant of the range, in the following order:
/// SW, SE, NW, NE.
GF_API
GfRange2d GetQuadrant(size_t i) const;
/// The unit square.
GF_API
static const GfRange2d UnitSquare;
private:
/// Minimum and maximum points.
GfVec2d _min, _max;
/// Extends minimum point if necessary to contain given point.
static void _FindMin(GfVec2d &dest, const GfVec2d &point) {
if (point[0] < dest[0]) dest[0] = point[0];
if (point[1] < dest[1]) dest[1] = point[1];
}
/// Extends maximum point if necessary to contain given point.
static void _FindMax(GfVec2d &dest, const GfVec2d &point) {
if (point[0] > dest[0]) dest[0] = point[0];
if (point[1] > dest[1]) dest[1] = point[1];
}
};
/// Output a GfRange2d.
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream &, GfRange2d const &);
PXR_NAMESPACE_CLOSE_SCOPE
#include "pxr/base/gf/range2f.h"
PXR_NAMESPACE_OPEN_SCOPE
inline bool
GfRange2d::operator ==(const GfRange2f& other) const {
return _min == GfVec2d(other.GetMin()) &&
_max == GfVec2d(other.GetMax());
}
inline bool
GfRange2d::operator !=(const GfRange2f& other) const {
return !(*this == other);
}
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_RANGE2D_H
+377
View File
@@ -0,0 +1,377 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// range.template.h file to make changes.
#ifndef PXR_BASE_GF_RANGE2F_H
#define PXR_BASE_GF_RANGE2F_H
/// \file gf/range2f.h
/// \ingroup group_gf_BasicGeometry
#include "pxr/pxr.h"
#include "pxr/base/gf/api.h"
#include "pxr/base/gf/vec2d.h"
#include "pxr/base/gf/vec2f.h"
#include "pxr/base/gf/traits.h"
#include <boost/functional/hash.hpp>
#include <cfloat>
#include <cstddef>
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
class GfRange2d;
class GfRange2f;
template <>
struct GfIsGfRange<class GfRange2f> { static const bool value = true; };
/// \class GfRange2f
/// \ingroup group_gf_BasicGeometry
///
/// Basic type: 2-dimensional floating point range.
///
/// This class represents a 2-dimensional range (or interval) All
/// operations are component-wise and conform to interval mathematics. An
/// empty range is one where max < min.
/// The default empty is [FLT_MAX,-FLT_MAX]
class GfRange2f
{
public:
/// Helper typedef.
typedef GfVec2f MinMaxType;
static const size_t dimension = GfVec2f::dimension;
typedef GfVec2f::ScalarType ScalarType;
/// Sets the range to an empty interval
// TODO check whether this can be deprecated.
void inline SetEmpty() {
_min[0] = _min[1] = FLT_MAX;
_max[0] = _max[1] = -FLT_MAX;
}
/// The default constructor creates an empty range.
GfRange2f() {
SetEmpty();
}
/// This constructor initializes the minimum and maximum points.
GfRange2f(const GfVec2f &min, const GfVec2f &max)
: _min(min), _max(max)
{
}
/// Returns the minimum value of the range.
const GfVec2f &GetMin() const { return _min; }
/// Returns the maximum value of the range.
const GfVec2f &GetMax() const { return _max; }
/// Returns the size of the range.
GfVec2f GetSize() const { return _max - _min; }
/// Returns the midpoint of the range, that is, 0.5*(min+max).
/// Note: this returns zero in the case of default-constructed ranges,
/// or ranges set via SetEmpty().
GfVec2f GetMidpoint() const {
return static_cast<ScalarType>(0.5) * _min
+ static_cast<ScalarType>(0.5) * _max;
}
/// Sets the minimum value of the range.
void SetMin(const GfVec2f &min) { _min = min; }
/// Sets the maximum value of the range.
void SetMax(const GfVec2f &max) { _max = max; }
/// Returns whether the range is empty (max < min).
bool IsEmpty() const {
return _min[0] > _max[0] || _min[1] > _max[1];
}
/// Modifies the range if necessary to surround the given value.
/// \deprecated Use UnionWith() instead.
void ExtendBy(const GfVec2f &point) { UnionWith(point); }
/// Modifies the range if necessary to surround the given range.
/// \deprecated Use UnionWith() instead.
void ExtendBy(const GfRange2f &range) { UnionWith(range); }
/// Returns true if the \p point is located inside the range. As with all
/// operations of this type, the range is assumed to include its extrema.
bool Contains(const GfVec2f &point) const {
return (point[0] >= _min[0] && point[0] <= _max[0]
&& point[1] >= _min[1] && point[1] <= _max[1]);
}
/// Returns true if the \p range is located entirely inside the range. As
/// with all operations of this type, the ranges are assumed to include
/// their extrema.
bool Contains(const GfRange2f &range) const {
return Contains(range._min) && Contains(range._max);
}
/// Returns true if the \p point is located inside the range. As with all
/// operations of this type, the range is assumed to include its extrema.
/// \deprecated Use Contains() instead.
bool IsInside(const GfVec2f &point) const {
return Contains(point);
}
/// Returns true if the \p range is located entirely inside the range. As
/// with all operations of this type, the ranges are assumed to include
/// their extrema.
/// \deprecated Use Contains() instead.
bool IsInside(const GfRange2f &range) const {
return Contains(range);
}
/// Returns true if the \p range is located entirely outside the range. As
/// with all operations of this type, the ranges are assumed to include
/// their extrema.
bool IsOutside(const GfRange2f &range) const {
return ((range._max[0] < _min[0] || range._min[0] > _max[0])
|| (range._max[1] < _min[1] || range._min[1] > _max[1]));
}
/// Returns the smallest \c GfRange2f which contains both \p a and \p b.
static GfRange2f GetUnion(const GfRange2f &a, const GfRange2f &b) {
GfRange2f res = a;
_FindMin(res._min,b._min);
_FindMax(res._max,b._max);
return res;
}
/// Extend \p this to include \p b.
const GfRange2f &UnionWith(const GfRange2f &b) {
_FindMin(_min,b._min);
_FindMax(_max,b._max);
return *this;
}
/// Extend \p this to include \p b.
const GfRange2f &UnionWith(const GfVec2f &b) {
_FindMin(_min,b);
_FindMax(_max,b);
return *this;
}
/// Returns the smallest \c GfRange2f which contains both \p a and \p b
/// \deprecated Use GetUnion() instead.
static GfRange2f Union(const GfRange2f &a, const GfRange2f &b) {
return GetUnion(a, b);
}
/// Extend \p this to include \p b.
/// \deprecated Use UnionWith() instead.
const GfRange2f &Union(const GfRange2f &b) {
return UnionWith(b);
}
/// Extend \p this to include \p b.
/// \deprecated Use UnionWith() instead.
const GfRange2f &Union(const GfVec2f &b) {
return UnionWith(b);
}
/// Returns a \c GfRange2f that describes the intersection of \p a and \p b.
static GfRange2f GetIntersection(const GfRange2f &a, const GfRange2f &b) {
GfRange2f res = a;
_FindMax(res._min,b._min);
_FindMin(res._max,b._max);
return res;
}
/// Returns a \c GfRange2f that describes the intersection of \p a and \p b.
/// \deprecated Use GetIntersection() instead.
static GfRange2f Intersection(const GfRange2f &a, const GfRange2f &b) {
return GetIntersection(a, b);
}
/// Modifies this range to hold its intersection with \p b and returns the
/// result
const GfRange2f &IntersectWith(const GfRange2f &b) {
_FindMax(_min,b._min);
_FindMin(_max,b._max);
return *this;
}
/// Modifies this range to hold its intersection with \p b and returns the
/// result.
/// \deprecated Use IntersectWith() instead.
const GfRange2f &Intersection(const GfRange2f &b) {
return IntersectWith(b);
}
/// unary sum.
GfRange2f operator +=(const GfRange2f &b) {
_min += b._min;
_max += b._max;
return *this;
}
/// unary difference.
GfRange2f operator -=(const GfRange2f &b) {
_min -= b._max;
_max -= b._min;
return *this;
}
/// unary multiply.
GfRange2f operator *=(double m) {
if (m > 0) {
_min *= m;
_max *= m;
} else {
GfVec2f tmp = _min;
_min = _max * m;
_max = tmp * m;
}
return *this;
}
/// unary division.
GfRange2f operator /=(double m) {
return *this *= (1.0 / m);
}
/// binary sum.
GfRange2f operator +(const GfRange2f &b) const {
return GfRange2f(_min + b._min, _max + b._max);
}
/// binary difference.
GfRange2f operator -(const GfRange2f &b) const {
return GfRange2f(_min - b._max, _max - b._min);
}
/// scalar multiply.
friend GfRange2f operator *(double m, const GfRange2f &r) {
return (m > 0 ?
GfRange2f(r._min*m, r._max*m) :
GfRange2f(r._max*m, r._min*m));
}
/// scalar multiply.
friend GfRange2f operator *(const GfRange2f &r, double m) {
return (m > 0 ?
GfRange2f(r._min*m, r._max*m) :
GfRange2f(r._max*m, r._min*m));
}
/// scalar divide.
friend GfRange2f operator /(const GfRange2f &r, double m) {
return r * (1.0 / m);
}
/// hash.
friend inline size_t hash_value(const GfRange2f &r) {
size_t h = 0;
boost::hash_combine(h, r._min);
boost::hash_combine(h, r._max);
return h;
}
/// The min and max points must match exactly for equality.
bool operator ==(const GfRange2f &b) const {
return (_min == b._min && _max == b._max);
}
bool operator !=(const GfRange2f &b) const {
return !(*this == b);
}
/// Compare this range to a GfRange2d.
///
/// The values must match exactly and it does exactly what you might
/// expect when comparing float and double values.
GF_API inline bool operator ==(const GfRange2d& other) const;
GF_API inline bool operator !=(const GfRange2d& other) const;
/// Compute the squared distance from a point to the range.
GF_API
double GetDistanceSquared(const GfVec2f &p) const;
/// Returns the ith corner of the range, in the following order:
/// SW, SE, NW, NE.
GF_API
GfVec2f GetCorner(size_t i) const;
/// Returns the ith quadrant of the range, in the following order:
/// SW, SE, NW, NE.
GF_API
GfRange2f GetQuadrant(size_t i) const;
/// The unit square.
GF_API
static const GfRange2f UnitSquare;
private:
/// Minimum and maximum points.
GfVec2f _min, _max;
/// Extends minimum point if necessary to contain given point.
static void _FindMin(GfVec2f &dest, const GfVec2f &point) {
if (point[0] < dest[0]) dest[0] = point[0];
if (point[1] < dest[1]) dest[1] = point[1];
}
/// Extends maximum point if necessary to contain given point.
static void _FindMax(GfVec2f &dest, const GfVec2f &point) {
if (point[0] > dest[0]) dest[0] = point[0];
if (point[1] > dest[1]) dest[1] = point[1];
}
};
/// Output a GfRange2f.
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream &, GfRange2f const &);
PXR_NAMESPACE_CLOSE_SCOPE
#include "pxr/base/gf/range2d.h"
PXR_NAMESPACE_OPEN_SCOPE
inline bool
GfRange2f::operator ==(const GfRange2d& other) const {
return _min == GfVec2f(other.GetMin()) &&
_max == GfVec2f(other.GetMax());
}
inline bool
GfRange2f::operator !=(const GfRange2d& other) const {
return !(*this == other);
}
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_RANGE2F_H
+383
View File
@@ -0,0 +1,383 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// range.template.h file to make changes.
#ifndef PXR_BASE_GF_RANGE3D_H
#define PXR_BASE_GF_RANGE3D_H
/// \file gf/range3d.h
/// \ingroup group_gf_BasicGeometry
#include "pxr/pxr.h"
#include "pxr/base/gf/api.h"
#include "pxr/base/gf/vec3d.h"
#include "pxr/base/gf/vec3f.h"
#include "pxr/base/gf/traits.h"
#include <boost/functional/hash.hpp>
#include <cfloat>
#include <cstddef>
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
class GfRange3d;
class GfRange3f;
template <>
struct GfIsGfRange<class GfRange3d> { static const bool value = true; };
/// \class GfRange3d
/// \ingroup group_gf_BasicGeometry
///
/// Basic type: 3-dimensional floating point range.
///
/// This class represents a 3-dimensional range (or interval) All
/// operations are component-wise and conform to interval mathematics. An
/// empty range is one where max < min.
/// The default empty is [FLT_MAX,-FLT_MAX]
class GfRange3d
{
public:
/// Helper typedef.
typedef GfVec3d MinMaxType;
static const size_t dimension = GfVec3d::dimension;
typedef GfVec3d::ScalarType ScalarType;
/// Sets the range to an empty interval
// TODO check whether this can be deprecated.
void inline SetEmpty() {
_min[0] = _min[1] = _min[2] = FLT_MAX;
_max[0] = _max[1] = _max[2] = -FLT_MAX;
}
/// The default constructor creates an empty range.
GfRange3d() {
SetEmpty();
}
/// This constructor initializes the minimum and maximum points.
GfRange3d(const GfVec3d &min, const GfVec3d &max)
: _min(min), _max(max)
{
}
/// Returns the minimum value of the range.
const GfVec3d &GetMin() const { return _min; }
/// Returns the maximum value of the range.
const GfVec3d &GetMax() const { return _max; }
/// Returns the size of the range.
GfVec3d GetSize() const { return _max - _min; }
/// Returns the midpoint of the range, that is, 0.5*(min+max).
/// Note: this returns zero in the case of default-constructed ranges,
/// or ranges set via SetEmpty().
GfVec3d GetMidpoint() const {
return static_cast<ScalarType>(0.5) * _min
+ static_cast<ScalarType>(0.5) * _max;
}
/// Sets the minimum value of the range.
void SetMin(const GfVec3d &min) { _min = min; }
/// Sets the maximum value of the range.
void SetMax(const GfVec3d &max) { _max = max; }
/// Returns whether the range is empty (max < min).
bool IsEmpty() const {
return _min[0] > _max[0] || _min[1] > _max[1] || _min[2] > _max[2];
}
/// Modifies the range if necessary to surround the given value.
/// \deprecated Use UnionWith() instead.
void ExtendBy(const GfVec3d &point) { UnionWith(point); }
/// Modifies the range if necessary to surround the given range.
/// \deprecated Use UnionWith() instead.
void ExtendBy(const GfRange3d &range) { UnionWith(range); }
/// Returns true if the \p point is located inside the range. As with all
/// operations of this type, the range is assumed to include its extrema.
bool Contains(const GfVec3d &point) const {
return (point[0] >= _min[0] && point[0] <= _max[0]
&& point[1] >= _min[1] && point[1] <= _max[1]
&& point[2] >= _min[2] && point[2] <= _max[2]);
}
/// Returns true if the \p range is located entirely inside the range. As
/// with all operations of this type, the ranges are assumed to include
/// their extrema.
bool Contains(const GfRange3d &range) const {
return Contains(range._min) && Contains(range._max);
}
/// Returns true if the \p point is located inside the range. As with all
/// operations of this type, the range is assumed to include its extrema.
/// \deprecated Use Contains() instead.
bool IsInside(const GfVec3d &point) const {
return Contains(point);
}
/// Returns true if the \p range is located entirely inside the range. As
/// with all operations of this type, the ranges are assumed to include
/// their extrema.
/// \deprecated Use Contains() instead.
bool IsInside(const GfRange3d &range) const {
return Contains(range);
}
/// Returns true if the \p range is located entirely outside the range. As
/// with all operations of this type, the ranges are assumed to include
/// their extrema.
bool IsOutside(const GfRange3d &range) const {
return ((range._max[0] < _min[0] || range._min[0] > _max[0])
|| (range._max[1] < _min[1] || range._min[1] > _max[1])
|| (range._max[2] < _min[2] || range._min[2] > _max[2]));
}
/// Returns the smallest \c GfRange3d which contains both \p a and \p b.
static GfRange3d GetUnion(const GfRange3d &a, const GfRange3d &b) {
GfRange3d res = a;
_FindMin(res._min,b._min);
_FindMax(res._max,b._max);
return res;
}
/// Extend \p this to include \p b.
const GfRange3d &UnionWith(const GfRange3d &b) {
_FindMin(_min,b._min);
_FindMax(_max,b._max);
return *this;
}
/// Extend \p this to include \p b.
const GfRange3d &UnionWith(const GfVec3d &b) {
_FindMin(_min,b);
_FindMax(_max,b);
return *this;
}
/// Returns the smallest \c GfRange3d which contains both \p a and \p b
/// \deprecated Use GetUnion() instead.
static GfRange3d Union(const GfRange3d &a, const GfRange3d &b) {
return GetUnion(a, b);
}
/// Extend \p this to include \p b.
/// \deprecated Use UnionWith() instead.
const GfRange3d &Union(const GfRange3d &b) {
return UnionWith(b);
}
/// Extend \p this to include \p b.
/// \deprecated Use UnionWith() instead.
const GfRange3d &Union(const GfVec3d &b) {
return UnionWith(b);
}
/// Returns a \c GfRange3d that describes the intersection of \p a and \p b.
static GfRange3d GetIntersection(const GfRange3d &a, const GfRange3d &b) {
GfRange3d res = a;
_FindMax(res._min,b._min);
_FindMin(res._max,b._max);
return res;
}
/// Returns a \c GfRange3d that describes the intersection of \p a and \p b.
/// \deprecated Use GetIntersection() instead.
static GfRange3d Intersection(const GfRange3d &a, const GfRange3d &b) {
return GetIntersection(a, b);
}
/// Modifies this range to hold its intersection with \p b and returns the
/// result
const GfRange3d &IntersectWith(const GfRange3d &b) {
_FindMax(_min,b._min);
_FindMin(_max,b._max);
return *this;
}
/// Modifies this range to hold its intersection with \p b and returns the
/// result.
/// \deprecated Use IntersectWith() instead.
const GfRange3d &Intersection(const GfRange3d &b) {
return IntersectWith(b);
}
/// unary sum.
GfRange3d operator +=(const GfRange3d &b) {
_min += b._min;
_max += b._max;
return *this;
}
/// unary difference.
GfRange3d operator -=(const GfRange3d &b) {
_min -= b._max;
_max -= b._min;
return *this;
}
/// unary multiply.
GfRange3d operator *=(double m) {
if (m > 0) {
_min *= m;
_max *= m;
} else {
GfVec3d tmp = _min;
_min = _max * m;
_max = tmp * m;
}
return *this;
}
/// unary division.
GfRange3d operator /=(double m) {
return *this *= (1.0 / m);
}
/// binary sum.
GfRange3d operator +(const GfRange3d &b) const {
return GfRange3d(_min + b._min, _max + b._max);
}
/// binary difference.
GfRange3d operator -(const GfRange3d &b) const {
return GfRange3d(_min - b._max, _max - b._min);
}
/// scalar multiply.
friend GfRange3d operator *(double m, const GfRange3d &r) {
return (m > 0 ?
GfRange3d(r._min*m, r._max*m) :
GfRange3d(r._max*m, r._min*m));
}
/// scalar multiply.
friend GfRange3d operator *(const GfRange3d &r, double m) {
return (m > 0 ?
GfRange3d(r._min*m, r._max*m) :
GfRange3d(r._max*m, r._min*m));
}
/// scalar divide.
friend GfRange3d operator /(const GfRange3d &r, double m) {
return r * (1.0 / m);
}
/// hash.
friend inline size_t hash_value(const GfRange3d &r) {
size_t h = 0;
boost::hash_combine(h, r._min);
boost::hash_combine(h, r._max);
return h;
}
/// The min and max points must match exactly for equality.
bool operator ==(const GfRange3d &b) const {
return (_min == b._min && _max == b._max);
}
bool operator !=(const GfRange3d &b) const {
return !(*this == b);
}
/// Compare this range to a GfRange3f.
///
/// The values must match exactly and it does exactly what you might
/// expect when comparing float and double values.
GF_API inline bool operator ==(const GfRange3f& other) const;
GF_API inline bool operator !=(const GfRange3f& other) const;
/// Compute the squared distance from a point to the range.
GF_API
double GetDistanceSquared(const GfVec3d &p) const;
/// Returns the ith corner of the range, in the following order:
/// LDB, RDB, LUB, RUB, LDF, RDF, LUF, RUF. Where L/R is left/right,
/// D/U is down/up, and B/F is back/front.
GF_API
GfVec3d GetCorner(size_t i) const;
/// Returns the ith octant of the range, in the following order:
/// LDB, RDB, LUB, RUB, LDF, RDF, LUF, RUF. Where L/R is left/right,
/// D/U is down/up, and B/F is back/front.
GF_API
GfRange3d GetOctant(size_t i) const;
/// The unit cube.
GF_API
static const GfRange3d UnitCube;
private:
/// Minimum and maximum points.
GfVec3d _min, _max;
/// Extends minimum point if necessary to contain given point.
static void _FindMin(GfVec3d &dest, const GfVec3d &point) {
if (point[0] < dest[0]) dest[0] = point[0];
if (point[1] < dest[1]) dest[1] = point[1];
if (point[2] < dest[2]) dest[2] = point[2];
}
/// Extends maximum point if necessary to contain given point.
static void _FindMax(GfVec3d &dest, const GfVec3d &point) {
if (point[0] > dest[0]) dest[0] = point[0];
if (point[1] > dest[1]) dest[1] = point[1];
if (point[2] > dest[2]) dest[2] = point[2];
}
};
/// Output a GfRange3d.
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream &, GfRange3d const &);
PXR_NAMESPACE_CLOSE_SCOPE
#include "pxr/base/gf/range3f.h"
PXR_NAMESPACE_OPEN_SCOPE
inline bool
GfRange3d::operator ==(const GfRange3f& other) const {
return _min == GfVec3d(other.GetMin()) &&
_max == GfVec3d(other.GetMax());
}
inline bool
GfRange3d::operator !=(const GfRange3f& other) const {
return !(*this == other);
}
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_RANGE3D_H
+383
View File
@@ -0,0 +1,383 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// range.template.h file to make changes.
#ifndef PXR_BASE_GF_RANGE3F_H
#define PXR_BASE_GF_RANGE3F_H
/// \file gf/range3f.h
/// \ingroup group_gf_BasicGeometry
#include "pxr/pxr.h"
#include "pxr/base/gf/api.h"
#include "pxr/base/gf/vec3d.h"
#include "pxr/base/gf/vec3f.h"
#include "pxr/base/gf/traits.h"
#include <boost/functional/hash.hpp>
#include <cfloat>
#include <cstddef>
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
class GfRange3d;
class GfRange3f;
template <>
struct GfIsGfRange<class GfRange3f> { static const bool value = true; };
/// \class GfRange3f
/// \ingroup group_gf_BasicGeometry
///
/// Basic type: 3-dimensional floating point range.
///
/// This class represents a 3-dimensional range (or interval) All
/// operations are component-wise and conform to interval mathematics. An
/// empty range is one where max < min.
/// The default empty is [FLT_MAX,-FLT_MAX]
class GfRange3f
{
public:
/// Helper typedef.
typedef GfVec3f MinMaxType;
static const size_t dimension = GfVec3f::dimension;
typedef GfVec3f::ScalarType ScalarType;
/// Sets the range to an empty interval
// TODO check whether this can be deprecated.
void inline SetEmpty() {
_min[0] = _min[1] = _min[2] = FLT_MAX;
_max[0] = _max[1] = _max[2] = -FLT_MAX;
}
/// The default constructor creates an empty range.
GfRange3f() {
SetEmpty();
}
/// This constructor initializes the minimum and maximum points.
GfRange3f(const GfVec3f &min, const GfVec3f &max)
: _min(min), _max(max)
{
}
/// Returns the minimum value of the range.
const GfVec3f &GetMin() const { return _min; }
/// Returns the maximum value of the range.
const GfVec3f &GetMax() const { return _max; }
/// Returns the size of the range.
GfVec3f GetSize() const { return _max - _min; }
/// Returns the midpoint of the range, that is, 0.5*(min+max).
/// Note: this returns zero in the case of default-constructed ranges,
/// or ranges set via SetEmpty().
GfVec3f GetMidpoint() const {
return static_cast<ScalarType>(0.5) * _min
+ static_cast<ScalarType>(0.5) * _max;
}
/// Sets the minimum value of the range.
void SetMin(const GfVec3f &min) { _min = min; }
/// Sets the maximum value of the range.
void SetMax(const GfVec3f &max) { _max = max; }
/// Returns whether the range is empty (max < min).
bool IsEmpty() const {
return _min[0] > _max[0] || _min[1] > _max[1] || _min[2] > _max[2];
}
/// Modifies the range if necessary to surround the given value.
/// \deprecated Use UnionWith() instead.
void ExtendBy(const GfVec3f &point) { UnionWith(point); }
/// Modifies the range if necessary to surround the given range.
/// \deprecated Use UnionWith() instead.
void ExtendBy(const GfRange3f &range) { UnionWith(range); }
/// Returns true if the \p point is located inside the range. As with all
/// operations of this type, the range is assumed to include its extrema.
bool Contains(const GfVec3f &point) const {
return (point[0] >= _min[0] && point[0] <= _max[0]
&& point[1] >= _min[1] && point[1] <= _max[1]
&& point[2] >= _min[2] && point[2] <= _max[2]);
}
/// Returns true if the \p range is located entirely inside the range. As
/// with all operations of this type, the ranges are assumed to include
/// their extrema.
bool Contains(const GfRange3f &range) const {
return Contains(range._min) && Contains(range._max);
}
/// Returns true if the \p point is located inside the range. As with all
/// operations of this type, the range is assumed to include its extrema.
/// \deprecated Use Contains() instead.
bool IsInside(const GfVec3f &point) const {
return Contains(point);
}
/// Returns true if the \p range is located entirely inside the range. As
/// with all operations of this type, the ranges are assumed to include
/// their extrema.
/// \deprecated Use Contains() instead.
bool IsInside(const GfRange3f &range) const {
return Contains(range);
}
/// Returns true if the \p range is located entirely outside the range. As
/// with all operations of this type, the ranges are assumed to include
/// their extrema.
bool IsOutside(const GfRange3f &range) const {
return ((range._max[0] < _min[0] || range._min[0] > _max[0])
|| (range._max[1] < _min[1] || range._min[1] > _max[1])
|| (range._max[2] < _min[2] || range._min[2] > _max[2]));
}
/// Returns the smallest \c GfRange3f which contains both \p a and \p b.
static GfRange3f GetUnion(const GfRange3f &a, const GfRange3f &b) {
GfRange3f res = a;
_FindMin(res._min,b._min);
_FindMax(res._max,b._max);
return res;
}
/// Extend \p this to include \p b.
const GfRange3f &UnionWith(const GfRange3f &b) {
_FindMin(_min,b._min);
_FindMax(_max,b._max);
return *this;
}
/// Extend \p this to include \p b.
const GfRange3f &UnionWith(const GfVec3f &b) {
_FindMin(_min,b);
_FindMax(_max,b);
return *this;
}
/// Returns the smallest \c GfRange3f which contains both \p a and \p b
/// \deprecated Use GetUnion() instead.
static GfRange3f Union(const GfRange3f &a, const GfRange3f &b) {
return GetUnion(a, b);
}
/// Extend \p this to include \p b.
/// \deprecated Use UnionWith() instead.
const GfRange3f &Union(const GfRange3f &b) {
return UnionWith(b);
}
/// Extend \p this to include \p b.
/// \deprecated Use UnionWith() instead.
const GfRange3f &Union(const GfVec3f &b) {
return UnionWith(b);
}
/// Returns a \c GfRange3f that describes the intersection of \p a and \p b.
static GfRange3f GetIntersection(const GfRange3f &a, const GfRange3f &b) {
GfRange3f res = a;
_FindMax(res._min,b._min);
_FindMin(res._max,b._max);
return res;
}
/// Returns a \c GfRange3f that describes the intersection of \p a and \p b.
/// \deprecated Use GetIntersection() instead.
static GfRange3f Intersection(const GfRange3f &a, const GfRange3f &b) {
return GetIntersection(a, b);
}
/// Modifies this range to hold its intersection with \p b and returns the
/// result
const GfRange3f &IntersectWith(const GfRange3f &b) {
_FindMax(_min,b._min);
_FindMin(_max,b._max);
return *this;
}
/// Modifies this range to hold its intersection with \p b and returns the
/// result.
/// \deprecated Use IntersectWith() instead.
const GfRange3f &Intersection(const GfRange3f &b) {
return IntersectWith(b);
}
/// unary sum.
GfRange3f operator +=(const GfRange3f &b) {
_min += b._min;
_max += b._max;
return *this;
}
/// unary difference.
GfRange3f operator -=(const GfRange3f &b) {
_min -= b._max;
_max -= b._min;
return *this;
}
/// unary multiply.
GfRange3f operator *=(double m) {
if (m > 0) {
_min *= m;
_max *= m;
} else {
GfVec3f tmp = _min;
_min = _max * m;
_max = tmp * m;
}
return *this;
}
/// unary division.
GfRange3f operator /=(double m) {
return *this *= (1.0 / m);
}
/// binary sum.
GfRange3f operator +(const GfRange3f &b) const {
return GfRange3f(_min + b._min, _max + b._max);
}
/// binary difference.
GfRange3f operator -(const GfRange3f &b) const {
return GfRange3f(_min - b._max, _max - b._min);
}
/// scalar multiply.
friend GfRange3f operator *(double m, const GfRange3f &r) {
return (m > 0 ?
GfRange3f(r._min*m, r._max*m) :
GfRange3f(r._max*m, r._min*m));
}
/// scalar multiply.
friend GfRange3f operator *(const GfRange3f &r, double m) {
return (m > 0 ?
GfRange3f(r._min*m, r._max*m) :
GfRange3f(r._max*m, r._min*m));
}
/// scalar divide.
friend GfRange3f operator /(const GfRange3f &r, double m) {
return r * (1.0 / m);
}
/// hash.
friend inline size_t hash_value(const GfRange3f &r) {
size_t h = 0;
boost::hash_combine(h, r._min);
boost::hash_combine(h, r._max);
return h;
}
/// The min and max points must match exactly for equality.
bool operator ==(const GfRange3f &b) const {
return (_min == b._min && _max == b._max);
}
bool operator !=(const GfRange3f &b) const {
return !(*this == b);
}
/// Compare this range to a GfRange3d.
///
/// The values must match exactly and it does exactly what you might
/// expect when comparing float and double values.
GF_API inline bool operator ==(const GfRange3d& other) const;
GF_API inline bool operator !=(const GfRange3d& other) const;
/// Compute the squared distance from a point to the range.
GF_API
double GetDistanceSquared(const GfVec3f &p) const;
/// Returns the ith corner of the range, in the following order:
/// LDB, RDB, LUB, RUB, LDF, RDF, LUF, RUF. Where L/R is left/right,
/// D/U is down/up, and B/F is back/front.
GF_API
GfVec3f GetCorner(size_t i) const;
/// Returns the ith octant of the range, in the following order:
/// LDB, RDB, LUB, RUB, LDF, RDF, LUF, RUF. Where L/R is left/right,
/// D/U is down/up, and B/F is back/front.
GF_API
GfRange3f GetOctant(size_t i) const;
/// The unit cube.
GF_API
static const GfRange3f UnitCube;
private:
/// Minimum and maximum points.
GfVec3f _min, _max;
/// Extends minimum point if necessary to contain given point.
static void _FindMin(GfVec3f &dest, const GfVec3f &point) {
if (point[0] < dest[0]) dest[0] = point[0];
if (point[1] < dest[1]) dest[1] = point[1];
if (point[2] < dest[2]) dest[2] = point[2];
}
/// Extends maximum point if necessary to contain given point.
static void _FindMax(GfVec3f &dest, const GfVec3f &point) {
if (point[0] > dest[0]) dest[0] = point[0];
if (point[1] > dest[1]) dest[1] = point[1];
if (point[2] > dest[2]) dest[2] = point[2];
}
};
/// Output a GfRange3f.
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream &, GfRange3f const &);
PXR_NAMESPACE_CLOSE_SCOPE
#include "pxr/base/gf/range3d.h"
PXR_NAMESPACE_OPEN_SCOPE
inline bool
GfRange3f::operator ==(const GfRange3d& other) const {
return _min == GfVec3f(other.GetMin()) &&
_max == GfVec3f(other.GetMax());
}
inline bool
GfRange3f::operator !=(const GfRange3d& other) const {
return !(*this == other);
}
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_RANGE3F_H
+291
View File
@@ -0,0 +1,291 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_GF_RAY_H
#define PXR_BASE_GF_RAY_H
/// \file gf/ray.h
/// \ingroup group_gf_BasicGeometry
#include "pxr/pxr.h"
#include "pxr/base/gf/matrix4d.h"
#include "pxr/base/gf/api.h"
#include <float.h>
#include <limits>
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
class GfBBox3d;
class GfLine;
class GfLineSeg;
class GfPlane;
class GfRange3d;
/// \class GfRay
/// \ingroup group_gf_BasicGeometry
///
/// Basic type: Ray used for intersection testing
///
/// This class represents a three-dimensional ray in space, typically
/// used for intersection testing. It consists of an origin and a
/// direction.
///
/// Note that by default a \c GfRay does not normalize its direction
/// vector to unit length.
///
/// Note for ray intersections, the start point is included in the computations,
/// i.e., a distance of zero is defined to be intersecting.
///
class GfRay {
public:
/// The default constructor leaves the ray parameters undefined.
GfRay() {
}
/// This constructor takes a starting point and a direction.
GfRay(const GfVec3d &startPoint, const GfVec3d &direction) {
SetPointAndDirection(startPoint, direction);
}
/// Sets the ray by specifying a starting point and a direction.
GF_API
void SetPointAndDirection(const GfVec3d &startPoint,
const GfVec3d &direction);
/// Sets the ray by specifying a starting point and an ending point.
GF_API
void SetEnds(const GfVec3d &startPoint, const GfVec3d &endPoint);
/// Returns the starting point of the segment.
const GfVec3d & GetStartPoint() const {
return _startPoint;
}
/// Returns the direction vector of the segment. This is not guaranteed to
/// be unit length.
const GfVec3d & GetDirection() const {
return _direction;
}
/// Returns the point that is \p distance units from the starting point
/// along the direction vector, expressed in parametic distance.
GfVec3d GetPoint(double distance) const {
return _startPoint + distance * _direction;
}
/// Transforms the ray by the given matrix.
GF_API
GfRay & Transform(const GfMatrix4d &matrix);
/// Returns the point on the ray that is closest to \p point. If \p
/// rayDistance is not \c NULL, it will be set to the parametric distance
/// along the ray of the closest point.
GF_API
GfVec3d FindClosestPoint(const GfVec3d &point,
double *rayDistance = NULL) const;
/// Component-wise equality test. The starting points, directions, and
/// lengths must match exactly for rays to be considered equal.
bool operator ==(const GfRay &r) const {
return (_startPoint == r._startPoint &&
_direction == r._direction);
}
/// Component-wise inequality test. The starting points, directions, and
/// lengths must match exactly for rays to be considered equal.
bool operator !=(const GfRay &r) const {
return ! (*this == r);
}
/// \name Intersection methods.
///
/// The methods in this group intersect the ray with a geometric entity.
///
///@{
/// Intersects the ray with the triangle formed by points \p p0, \p p1,
/// and \p p2, returning \c true if it hits. If there is an intersection,
/// it also returns the parametric distance to the intersection point in
/// \p distance, the barycentric coordinates of the intersection point in
/// \p barycentricCoords and the front-facing flag in \p frontFacing. The
/// barycentric coordinates are defined with respect to the three vertices
/// taken in order. The front-facing flag is \c true if the intersection
/// hit the side of the triangle that is formed when the vertices are
/// ordered counter-clockwise (right-hand rule). If any of the return
/// pointers are \c NULL, the corresponding values are not returned.
///
/// If the distance to the intersection is greater than \p maxDist, then
/// the method will return false.
///
/// Barycentric coordinates are defined to sum to 1 and satisfy this
/// relationsip:
/// \code
/// intersectionPoint = (barycentricCoords[0] * p0 +
/// barycentricCoords[1] * p1 +
/// barycentricCoords[2] * p2);
/// \endcode
GF_API
bool Intersect(const GfVec3d &p0,
const GfVec3d &p1,
const GfVec3d &p2,
double *distance = NULL,
GfVec3d *barycentricCoords = NULL,
bool *frontFacing = NULL,
double maxDist = std::numeric_limits<double>::infinity())
const;
/// Intersects the ray with a plane, returning \c true if the ray is not
/// parallel to the plane and the intersection is within the ray bounds.
/// If there is an intersection, it also returns the parametric distance
/// to the intersection point in \p distance and the front-facing flag in
/// \p frontFacing, if they are not \c NULL. The front-facing flag is \c
/// true if the intersection is on the side of the plane in which its
/// normal points.
GF_API
bool Intersect(const GfPlane &plane, double *distance = NULL,
bool *frontFacing = NULL) const;
/// Intersects the ray with an axis-aligned box, returning \c true if the
/// ray intersects it at all within bounds. If there is an intersection,
/// this also returns the parametric distances to the two intersection
/// points in \p enterDistance and \p exitDistance.
GF_API
bool Intersect(const GfRange3d &box,
double *enterDistance = NULL,
double *exitDistance = NULL) const;
/// Intersects the ray with an oriented box, returning \c true if the
/// ray intersects it at all within bounds. If there is an intersection,
/// this also returns the parametric distances to the two intersection
/// points in \p enterDistance and \p exitDistance.
GF_API
bool Intersect(const GfBBox3d &box,
double *enterDistance = NULL,
double *exitDistance = NULL) const;
/// Intersects the ray with a sphere, returning \c true if the ray
/// intersects it at all within bounds. If there is an intersection,
/// returns the parametric distance to the two intersection points in \p
/// enterDistance and \p exitDistance.
GF_API
bool Intersect(const GfVec3d &center, double radius,
double *enterDistance = NULL,
double *exitDistance = NULL ) const;
/// Intersects the ray with an infinite cylinder, with axis \p axis,
/// centered at the \p origin, with radius \p radius.
///
/// Returns \c true if the ray intersects it at all within bounds. If
/// there is an intersection, returns the parametric distance to the two
/// intersection points in \p enterDistance and \p exitDistance.
///
/// Note this method does not validate whether the radius is valid.
GF_API
bool Intersect(const GfVec3d &origin,
const GfVec3d &axis,
const double radius,
double *enterDistance = NULL,
double *exitDistance = NULL) const;
/// Intersects the ray with an infinite non-double cone, centered at \p
/// origin, with axis \p axis, radius \p radius and apex at \p height.
///
/// Returns \c true if the ray intersects it at all within bounds. If
/// there is an intersection, returns the parametric distance to the two
/// intersection points in \p enterDistance and \p exitDistance.
///
/// Note this method does not validate whether the radius are height are
/// valid.
GF_API
bool Intersect(const GfVec3d &origin,
const GfVec3d &axis,
const double radius,
const double height,
double *enterDistance = NULL,
double *exitDistance = NULL) const;
///@}
private:
GF_API
friend bool GfFindClosestPoints( const GfRay &, const GfLine &,
GfVec3d *, GfVec3d *,
double *, double * );
GF_API
friend bool GfFindClosestPoints( const GfRay &, const GfLineSeg &,
GfVec3d *, GfVec3d *,
double *, double * );
/// Solves the quadratic equation returning the solutions, if defined, in
/// \p enterDistance and \p exitDistance, where \p enterDistance is less
/// than or equal to \p exitDistance.
bool _SolveQuadratic(const double a,
const double b,
const double c,
double *enterDistance = NULL,
double *exitDistance = NULL) const;
/// The starting point of the ray.
GfVec3d _startPoint;
/// The direction vector.
GfVec3d _direction;
};
/// Computes the closest points between a ray and a line. The two points are
/// returned in \p rayPoint and \p linePoint. The parametric distance of each
/// point on the lines is returned in \p rayDistance and \p lineDistance.
///
/// This returns \c false if the lines were close enough to parallel that no
/// points could be computed; in this case, the other return values are
/// undefined.
GF_API
bool GfFindClosestPoints( const GfRay &ray, const GfLine &line,
GfVec3d *rayPoint = nullptr,
GfVec3d *linePoint = nullptr,
double *rayDistance = nullptr,
double *lineDistance = nullptr );
/// Computes the closest points between a ray and a line segment. The two
/// points are returned in \p rayPoint and \p segPoint. The parametric
/// distance of each point is returned in \p rayDistance and \p segDistance.
///
/// This returns \c false if the lines were close enough to parallel that no
/// points could be computed; in this case, the other return values are
/// undefined.
GF_API
bool GfFindClosestPoints( const GfRay &ray, const GfLineSeg &seg,
GfVec3d *rayPoint = nullptr,
GfVec3d *segPoint = nullptr,
double *rayDistance = nullptr,
double *segDistance = nullptr );
/// Output a GfRay using the format [(x y z) >> (x y z)].
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream&, const GfRay&);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_RAY_H
+309
View File
@@ -0,0 +1,309 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_GF_RECT2I_H
#define PXR_BASE_GF_RECT2I_H
/// \file gf/rect2i.h
/// \ingroup group_gf_LinearAlgebra
#include "pxr/pxr.h"
#include "pxr/base/gf/math.h"
#include "pxr/base/gf/vec2i.h"
#include "pxr/base/gf/api.h"
#include <boost/functional/hash.hpp>
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
/// \class GfRect2i
/// \ingroup group_gf_LinearAlgebra
///
/// A 2D rectangle with integer coordinates.
///
/// A rectangle is internally represented as two corners. We refer to these
/// as the min and max corner where the min's x-coordinate and y-coordinate
/// are assumed to be less than or equal to the max's corresponding coordinates.
/// Normally, it is expressed as a min corner and a size.
///
/// Note that the max corner is included when computing the size (width and
/// height) of a rectangle as the number of integral points in the x- and
/// y-direction. In particular, if the min corner and max corner are the same,
/// then the width and the height of the rectangle will both be one since we
/// have exactly one integral point with coordinates greater or equal to the
/// min corner and less or equal to the max corner.
///
/// Specifically, <em> width = maxX - minX + 1</em> and
/// <em>height = maxY - minY + 1.</em>
///
class GfRect2i {
public:
/// Constructs an empty rectangle.
GfRect2i(): _min(0,0), _max(-1,-1)
{
}
/// Constructs a rectangle with \p min and \p max corners.
GfRect2i(const GfVec2i& min, const GfVec2i& max)
: _min(min), _max(max)
{
}
/// Constructs a rectangle with \p min corner and the indicated \p width
/// and \p height.
GfRect2i(const GfVec2i& min, int width, int height)
: _min(min), _max(min + GfVec2i(width-1, height-1))
{
}
/// Returns true if the rectangle is a null rectangle.
///
/// A null rectangle has both the width and the height set to 0, that is
/// \code
/// GetMaxX() == GetMinX() - 1
/// \endcode
/// and
/// \code
/// GetMaxY() == GetMinY() - 1
/// \endcode
/// Remember that if \c GetMinX() and \c GetMaxX() return the same value
/// then the rectangle has width 1, and similarly for the height.
///
/// A null rectangle is both empty, and not valid.
bool IsNull() const {
return GetWidth() == 0 && GetHeight() == 0;
}
/// Returns true if the rectangle is empty.
///
/// An empty rectangle has one or both of its min coordinates strictly
/// greater than the corresponding max coordinate.
///
/// An empty rectangle is not valid.
bool IsEmpty() const {
return GetWidth() <= 0 || GetHeight() <= 0;
}
/// Return true if the rectangle is valid (equivalently, not empty).
bool IsValid() const {
return !IsEmpty();
}
/// Returns a normalized rectangle, i.e. one that has a non-negative width
/// and height.
///
/// \c GetNormalized() swaps the min and max x-coordinates to
/// ensure a non-negative width, and similarly for the
/// y-coordinates.
GF_API
GfRect2i GetNormalized() const;
/// Returns the min corner of the rectangle.
const GfVec2i& GetMin() const {
return _min;
}
/// Returns the max corner of the rectangle.
const GfVec2i& GetMax() const {
return _max;
}
/// Return the X value of min corner.
///
int GetMinX() const {
return _min[0];
}
/// Set the X value of the min corner.
///
void SetMinX(int x) {
_min[0] = x;
}
/// Return the X value of the max corner.
///
int GetMaxX() const {
return _max[0];
}
/// Set the X value of the max corner
void SetMaxX(int x) {
_max[0] = x;
}
/// Return the Y value of the min corner
///
int GetMinY() const {
return _min[1];
}
/// Set the Y value of the min corner.
///
void SetMinY(int y) {
_min[1] = y;
}
/// Return the Y value of the max corner
int GetMaxY() const {
return _max[1];
}
/// Set the Y value of the max corner
void SetMaxY(int y) {
_max[1] = y;
}
/// Sets the min corner of the rectangle.
void SetMin(const GfVec2i& min) {
_min = min;
}
/// Sets the max corner of the rectangle.
void SetMax(const GfVec2i& max) {
_max = max;
}
/// Returns the center point of the rectangle.
GfVec2i GetCenter() const {
return (_min + _max) / 2;
}
/// Move the rectangle by \p displ.
void Translate(const GfVec2i& displacement) {
_min += displacement;
_max += displacement;
}
/// Return the area of the rectangle.
unsigned long GetArea() const {
return (unsigned long)GetWidth() * (unsigned long)GetHeight();
}
/// Returns the size of the rectangle as a vector (width,height).
GfVec2i GetSize() const {
return GfVec2i(GetWidth(), GetHeight());
}
/// Returns the width of the rectangle.
///
/// \note If the min and max x-coordinates are coincident, the width is
/// one.
int GetWidth() const {
return (_max[0] - _min[0]) + 1;
}
/// Returns the height of the rectangle.
///
/// \note If the min and max y-coordinates are coincident, the height is
/// one.
int GetHeight() const {
return (_max[1] - _min[1]) + 1;
}
/// Computes the intersection of two rectangles.
GfRect2i GetIntersection(const GfRect2i& that) const {
if(IsEmpty())
return *this;
else if(that.IsEmpty())
return that;
else
return GfRect2i(GfVec2i(GfMax(_min[0], that._min[0]),
GfMax(_min[1], that._min[1])),
GfVec2i(GfMin(_max[0], that._max[0]),
GfMin(_max[1], that._max[1])));
}
/// Computes the intersection of two rectangles.
/// \deprecated Use GetIntersection() instead
GfRect2i Intersect(const GfRect2i& that) const {
return GetIntersection(that);
}
/// Computes the union of two rectangles.
GfRect2i GetUnion(const GfRect2i& that) const {
if(IsEmpty())
return that;
else if(that.IsEmpty())
return *this;
else
return GfRect2i(GfVec2i(GfMin(_min[0], that._min[0]),
GfMin(_min[1], that._min[1])),
GfVec2i(GfMax(_max[0], that._max[0]),
GfMax(_max[1], that._max[1])));
}
/// Computes the union of two rectangles
/// \deprecated Use GetUnion() instead.
GfRect2i Union(const GfRect2i& that) const {
return GetUnion(that);
}
/// Returns true if the specified point in the rectangle.
bool Contains(const GfVec2i& p) const {
return ((p[0] >= _min[0]) && (p[0] <= _max[0]) &&
(p[1] >= _min[1]) && (p[1] <= _max[1]));
}
friend inline size_t hash_value(const GfRect2i &r) {
size_t h = 0;
boost::hash_combine(h, r._min);
boost::hash_combine(h, r._max);
return h;
}
/// Returns true if \p r1 and \p r2 are equal.
friend bool operator==(const GfRect2i& r1, const GfRect2i& r2) {
return r1._min == r2._min && r1._max == r2._max;
}
/// Returns true if \p r1 and \p r2 are different.
friend bool operator!=(const GfRect2i& r1, const GfRect2i& r2) {
return !(r1 == r2);
}
/// Computes the union of two rectangles.
/// \see GetUnion()
GfRect2i operator += (const GfRect2i& that) {
*this = GetUnion(that);
return *this;
}
friend GfRect2i operator + (const GfRect2i r1, const GfRect2i& r2) {
GfRect2i tmp(r1);
tmp += r2;
return tmp;
}
private:
GfVec2i _min, _max;
};
/// Output a GfRect2i using the format [(x y):(x y)].
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream&, const GfRect2i&);
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+304
View File
@@ -0,0 +1,304 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_GF_ROTATION_H
#define PXR_BASE_GF_ROTATION_H
/// \file gf/rotation.h
/// \ingroup group_gf_LinearAlgebra
#include "pxr/pxr.h"
#include "pxr/base/gf/quaternion.h"
#include "pxr/base/gf/quatd.h"
#include "pxr/base/gf/matrix4d.h"
#include "pxr/base/gf/vec3d.h"
#include "pxr/base/gf/vec3f.h"
#include "pxr/base/gf/api.h"
#include <boost/functional/hash.hpp>
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
/// \class GfRotation
/// \ingroup group_gf_LinearAlgebra
///
/// Basic type: 3-space rotation specification.
///
/// This class represents a rotation in 3-space. This stores an axis as a
/// normalized vector of 3 \c doubles and an angle in degrees (as a double).
/// Rotations follow the right-hand rule: a positive rotation about an axis
/// vector appears counter-clockwise when looking from the end of the vector
/// toward the origin.
///
class GfRotation {
public:
/// The default constructor leaves the rotation undefined.
GfRotation() {
}
/// This constructor initializes the rotation to be \p angle
/// degrees about \p axis.
GfRotation(const GfVec3d &axis, double angle) {
SetAxisAngle(axis, angle);
}
/// This constructor initializes the rotation from a quaternion.
GfRotation(const GfQuaternion &quaternion) {
SetQuaternion(quaternion);
}
/// This constructor initializes the rotation from a quaternion. Note that
/// this constructor accepts GfQuatf and GfQuath since they implicitly
/// convert to GfQuatd.
GfRotation(const GfQuatd &quat) { SetQuat(quat); }
/// This constructor initializes the rotation to one that brings
/// the \p rotateFrom vector to align with \p rotateTo. The passed
/// vectors need not be unit length.
GF_API
GfRotation(const GfVec3d &rotateFrom, const GfVec3d &rotateTo) {
SetRotateInto(rotateFrom, rotateTo);
}
/// Sets the rotation to be \p angle degrees about \p axis.
GfRotation & SetAxisAngle(const GfVec3d &axis, double angle) {
_axis = axis;
_angle = angle;
if (!GfIsClose(_axis * _axis, 1.0, 1e-10))
_axis.Normalize();
return *this;
}
/// Sets the rotation from a quaternion. Note that this method accepts
/// GfQuatf and GfQuath since they implicitly convert to GfQuatd.
GF_API
GfRotation & SetQuat(const GfQuatd &quat);
/// Sets the rotation from a quaternion.
GfRotation & SetQuaternion(const GfQuaternion &quat) {
return SetQuat(GfQuatd(quat.GetReal(), quat.GetImaginary()));
}
/// Sets the rotation to one that brings the \p rotateFrom vector
/// to align with \p rotateTo. The passed vectors need not be unit
/// length.
GF_API
GfRotation & SetRotateInto(const GfVec3d &rotateFrom,
const GfVec3d &rotateTo);
/// Sets the rotation to an identity rotation.
/// (This is chosen to be 0 degrees around the positive X axis.)
GfRotation & SetIdentity() {
_axis.Set(1.0, 0.0, 0.0);
_angle = 0.0;
return *this;
}
/// Returns the axis of rotation.
const GfVec3d & GetAxis() const {
return _axis;
}
/// Returns the rotation angle in degrees.
double GetAngle() const {
return _angle;
}
/// Returns the rotation expressed as a quaternion.
GfQuaternion GetQuaternion() const {
auto quat = GetQuat();
return GfQuaternion(quat.GetReal(), quat.GetImaginary());
}
/// Returns the rotation expressed as a quaternion.
GF_API
GfQuatd GetQuat() const;
/// Returns the inverse of this rotation.
GfRotation GetInverse() const {
return GfRotation(_axis, -_angle);
}
/// Decompose rotation about 3 orthogonal axes.
/// If the axes are not orthogonal, warnings will be spewed.
GF_API
GfVec3d Decompose( const GfVec3d &axis0,
const GfVec3d &axis1,
const GfVec3d &axis2 ) const;
// Full-featured method to Decompose a rotation matrix into Cardarian
// angles.
// Axes have must be normalized. If useHint is specified
// then the current values stored within thetaTw, thetaFB, thetaLR,
// and thetaSw will be treated as hint and used to help choose
// an equivalent rotation that is as close as possible to the hints.
//
// One can use this routine to generate any combination of the three
// angles by passing in nullptr for the angle that is to be omitted.
//
// Passing in valid pointers for all four angles will decompose into
// Tw, FB, and LR but allows Sw to be used for best matching of hint
// values. It also allows an swShift value to be passed in as a
// Sw that is applied after the rotation matrix to get a best fit rotation
// in four angles.
//
// Angles are in radians.
//
// Specify \p handedness as -1.0 or 1.0, same as for MultiRotate.
//
// NOTE:
// Geppetto math function Originally brought over to extMover
// from //depot/main/tools/src/menv/lib/gpt/util.h [10/16/06]
// And moved into GfRotation[12/1/08]. Updated for any
// combination of three angles [12/1/11].
//
GF_API
static void DecomposeRotation(const GfMatrix4d &rot,
const GfVec3d &TwAxis,
const GfVec3d &FBAxis,
const GfVec3d &LRAxis,
double handedness,
double *thetaTw,
double *thetaFB,
double *thetaLR,
double *thetaSw = nullptr,
bool useHint=false,
const double *swShift=nullptr);
// This function projects the vectors \p v1 and \p v2 onto the plane
// normal to \p axis, and then returns the rotation about \p axis that
// brings \p v1 onto \p v2.
GF_API
static GfRotation RotateOntoProjected(const GfVec3d &v1,
const GfVec3d &v2,
const GfVec3d &axis);
/// Replace the hint angles with the closest rotation of the given
/// rotation to the hint.
///
/// Each angle in the rotation will be within Pi of the corresponding
/// hint angle and the sum of the differences with the hint will
/// be minimized. If a given rotation value is null then that angle will
/// be treated as 0.0 and ignored in the calculations.
///
/// All angles are in radians. The rotation order is Tw/FB/LR/Sw.
GF_API
static void MatchClosestEulerRotation(
double targetTw, double targetFB, double targetLR, double targetSw,
double *thetaTw, double *thetaFB, double *thetaLR, double *thetaSw);
/// Transforms row vector \p vec by the rotation, returning the result.
GF_API
GfVec3f TransformDir( const GfVec3f &vec ) const;
/// \overload
GF_API
GfVec3d TransformDir( const GfVec3d &vec ) const;
/// Hash.
friend inline size_t hash_value(const GfRotation &r) {
size_t h = 0;
boost::hash_combine(h, r._axis);
boost::hash_combine(h, r._angle);
return h;
}
/// Component-wise rotation equality test. The axes and angles must match
/// exactly for rotations to be considered equal. (To compare equality of
/// the actual rotations, you can convert both to quaternions and test the
/// results for equality.)
bool operator ==(const GfRotation &r) const {
return (_axis == r._axis &&
_angle == r._angle);
}
/// Component-wise rotation inequality test. The axes and angles must
/// match exactly for rotations to be considered equal. (To compare
/// equality of the actual rotations, you can convert both to quaternions
/// and test the results for equality.)
bool operator !=(const GfRotation &r) const {
return ! (*this == r);
}
/// Post-multiplies rotation \p r into this rotation.
GF_API
GfRotation & operator *=(const GfRotation &r);
/// Scales rotation angle by multiplying by \p scale.
GfRotation & operator *=(double scale) {
_angle *= scale;
return *this;
}
/// Scales rotation angle by dividing by \p scale.
GfRotation & operator /=(double scale) {
_angle /= scale;
return *this;
}
/// Returns composite rotation of rotations \p r1 and \p r2.
friend GfRotation operator *(const GfRotation &r1,
const GfRotation &r2) {
GfRotation r = r1;
return r *= r2;
}
/// Returns a rotation equivalent to \p r with its angle multiplied
/// by \p scale.
friend GfRotation operator *(const GfRotation &r, double scale) {
GfRotation rTmp = r;
return rTmp *= scale;
}
/// Returns a rotation equivalent to \p r with its angle multiplied
/// by \p scale.
friend GfRotation operator *(double scale, const GfRotation &r) {
return (r * scale);
}
/// Returns a rotation equivalent to \p r with its angle divided
/// by \p scale.
friend GfRotation operator /(const GfRotation &r, double scale) {
GfRotation rTmp = r;
return rTmp /= scale;
}
private:
/// Axis storage.
/// This axis is normalized to unit length whenever it is set.
GfVec3d _axis;
/// Angle storage (represented in degrees).
double _angle;
};
/// Output a GfRotation using the format [(x y z) a].
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream&, const GfRotation&);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_ROTATION_H
+200
View File
@@ -0,0 +1,200 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_GF_SIZE2_H
#define PXR_BASE_GF_SIZE2_H
/// \file gf/size2.h
/// \ingroup group_gf_LinearAlgebra
#include "pxr/pxr.h"
#include "pxr/base/arch/inttypes.h"
#include "pxr/base/gf/vec2i.h"
#include "pxr/base/gf/api.h"
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
/// \class GfSize2
/// \ingroup group_gf_LinearAlgebra
///
/// Two-dimensional array of sizes
///
/// GfSize2 is used to represent pairs of counts. It is based on the datatype
/// size_t, and thus can only represent non-negative values in each dimension.
/// If you need to represent negative numbers as well, use GfVec2i.
///
/// Usage of GfSize2 is similar to that of GfVec2i, except that all
/// mathematical operations are componentwise (including multiplication).
///
class GfSize2 {
public:
/// Default constructor initializes components to zero.
GfSize2() {
Set(0, 0);
}
/// Copy constructor.
GfSize2(const GfSize2& o) {
*this = o;
}
/// Conversion from GfVec2i.
explicit GfSize2(const GfVec2i&o) {
Set(o[0], o[1]);
}
/// Construct from an array.
GfSize2(const size_t v[2]) {
Set(v);
}
/// Construct from two values.
GfSize2(size_t v0, size_t v1) {
Set(v0, v1);
}
/// Set to the values in a given array.
GfSize2 & Set(const size_t v[2]) {
_vec[0] = v[0];
_vec[1] = v[1];
return *this;
}
/// Set to values passed directly.
GfSize2 & Set(size_t v0, size_t v1) {
_vec[0] = v0;
_vec[1] = v1;
return *this;
}
/// Array operator.
size_t & operator [](size_t i) {
return _vec[i];
}
/// Const array operator.
const size_t & operator [](size_t i) const {
return _vec[i];
}
/// Component-wise equality.
bool operator ==(const GfSize2 &v) const {
return _vec[0] == v._vec[0] && _vec[1] == v._vec[1];
}
/// Component-wise inequality.
bool operator !=(const GfSize2 &v) const {
return ! (*this == v);
}
/// Component-wise in-place addition.
GfSize2 & operator +=(const GfSize2 &v) {
_vec[0] += v._vec[0];
_vec[1] += v._vec[1];
return *this;
}
/// Component-wise in-place subtraction.
GfSize2 & operator -=(const GfSize2 &v) {
_vec[0] -= v._vec[0];
_vec[1] -= v._vec[1];
return *this;
}
/// Component-wise in-place multiplication.
GfSize2 & operator *=(GfSize2 const &v) {
_vec[0] *= v._vec[0];
_vec[1] *= v._vec[1];
return *this;
}
/// Component-wise in-place multiplication by a scalar.
GfSize2 & operator *=(int d) {
_vec[0] = _vec[0] * d;
_vec[1] = _vec[1] * d;
return *this;
}
/// Component-wise in-place division by a scalar.
GfSize2 & operator /=(int d) {
_vec[0] = _vec[0] / d;
_vec[1] = _vec[1] / d;
return *this;
}
/// Component-wise addition.
friend GfSize2 operator +(const GfSize2 &v1, const GfSize2 &v2) {
return GfSize2(v1._vec[0]+v2._vec[0],
v1._vec[1]+v2._vec[1]);
}
/// Component-wise subtraction.
friend GfSize2 operator -(const GfSize2 &v1, const GfSize2 &v2) {
return GfSize2(v1._vec[0]-v2._vec[0],
v1._vec[1]-v2._vec[1]);
}
/// Component-wise multiplication.
friend GfSize2 operator *(const GfSize2 &v1, const GfSize2 &v2) {
return GfSize2(v1._vec[0]*v2._vec[0],
v1._vec[1]*v2._vec[1]);
}
/// Component-wise multiplication by a scalar.
friend GfSize2 operator *(const GfSize2 &v1, int s) {
return GfSize2(v1._vec[0]*s,
v1._vec[1]*s);
}
/// Component-wise multiplication by a scalar.
friend GfSize2 operator *(int s, const GfSize2 &v1) {
return GfSize2(v1._vec[0]*s,
v1._vec[1]*s);
}
/// Component-wise division by a scalar.
friend GfSize2 operator /(const GfSize2 &v1, int s) {
return GfSize2(v1._vec[0]/s,
v1._vec[1]/s);
}
/// Output operator.
GF_API
friend std::ostream &operator<<(std::ostream &o, GfSize2 const &v);
/// Conversion to GfVec2i.
operator GfVec2i() const {
return GfVec2i(_vec[0], _vec[1]);
}
private:
size_t _vec[2];
};
// Friend functions must be declared
GF_API std::ostream &operator<<(std::ostream &o, GfSize2 const &v);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_SIZE2_H
+213
View File
@@ -0,0 +1,213 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_GF_SIZE3_H
#define PXR_BASE_GF_SIZE3_H
/// \file gf/size3.h
/// \ingroup group_gf_LinearAlgebra
#include "pxr/pxr.h"
#include "pxr/base/arch/inttypes.h"
#include "pxr/base/gf/vec3i.h"
#include "pxr/base/gf/api.h"
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
/// \class GfSize3
/// \ingroup group_gf_LinearAlgebra
///
/// Three-dimensional array of sizes
///
/// GfSize3 is used to represent triples of counts. It is based on the
/// datatype size_t, and thus can only represent non-negative values in each
/// dimension. If you need to represent negative numbers as well, use GfVeci.
///
/// Usage of GfSize3 is similar to that of GfVec3i, except that all
/// mathematical operations are componentwise (including multiplication).
///
class GfSize3 {
public:
/// Default constructor initializes components to zero
GfSize3() {
Set(0, 0, 0);
}
/// Copy constructor.
GfSize3(const GfSize3& o) {
*this = o;
}
/// Conversion from GfVec3i
explicit GfSize3(const GfVec3i&o) {
Set(o[0], o[1], o[2]);
}
/// Construct from an array
GfSize3(const size_t v[3]) {
Set(v);
}
/// Construct from three values
GfSize3(size_t v0, size_t v1, size_t v2) {
Set(v0, v1, v2);
}
/// Set to the values in \p v.
GfSize3 & Set(const size_t v[3]) {
_vec[0] = v[0];
_vec[1] = v[1];
_vec[2] = v[2];
return *this;
}
/// Set to values passed directly
GfSize3 & Set(size_t v0, size_t v1, size_t v2) {
_vec[0] = v0;
_vec[1] = v1;
_vec[2] = v2;
return *this;
}
/// Array operator
size_t & operator [](size_t i) {
return _vec[i];
}
/// Const array operator
const size_t & operator [](size_t i) const {
return _vec[i];
}
/// Component-wise equality
bool operator ==(const GfSize3 &v) const {
return _vec[0] == v._vec[0] && _vec[1] == v._vec[1] &&
_vec[2] == v._vec[2];
}
/// Component-wise inequality
bool operator !=(const GfSize3 &v) const {
return ! (*this == v);
}
/// Component-wise in-place addition
GfSize3 & operator +=(const GfSize3 &v) {
_vec[0] += v._vec[0];
_vec[1] += v._vec[1];
_vec[2] += v._vec[2];
return *this;
}
/// Component-wise in-place subtraction
GfSize3 & operator -=(const GfSize3 &v) {
_vec[0] -= v._vec[0];
_vec[1] -= v._vec[1];
_vec[2] -= v._vec[2];
return *this;
}
/// Component-wise in-place multiplication.
GfSize3 & operator *=(GfSize3 const &v) {
_vec[0] *= v._vec[0];
_vec[1] *= v._vec[1];
_vec[2] *= v._vec[2];
return *this;
}
/// Component-wise in-place multiplication by a scalar
GfSize3 & operator *=(size_t d) {
_vec[0] = _vec[0] * d;
_vec[1] = _vec[1] * d;
_vec[2] = _vec[2] * d;
return *this;
}
/// Component-wise in-place division by a scalar
GfSize3 & operator /=(size_t d) {
_vec[0] = _vec[0] / d;
_vec[1] = _vec[1] / d;
_vec[2] = _vec[2] / d;
return *this;
}
/// Component-wise addition
friend GfSize3 operator +(const GfSize3 &v1, const GfSize3 &v3) {
return GfSize3(v1._vec[0]+v3._vec[0],
v1._vec[1]+v3._vec[1],
v1._vec[2]+v3._vec[2]);
}
/// Component-wise subtraction
friend GfSize3 operator -(const GfSize3 &v1, const GfSize3 &v3) {
return GfSize3(v1._vec[0]-v3._vec[0],
v1._vec[1]-v3._vec[1],
v1._vec[2]-v3._vec[2]);
}
/// Component-wise multiplication
friend GfSize3 operator *(const GfSize3 &v1, const GfSize3 &v3) {
return GfSize3(v1._vec[0]*v3._vec[0],
v1._vec[1]*v3._vec[1],
v1._vec[2]*v3._vec[2]);
}
/// Component-wise multiplication by a scalar
friend GfSize3 operator *(const GfSize3 &v1, size_t s) {
return GfSize3(v1._vec[0]*s,
v1._vec[1]*s,
v1._vec[2]*s);
}
/// Component-wise multiplication by a scalar
friend GfSize3 operator *(size_t s, const GfSize3 &v1) {
return GfSize3(v1._vec[0]*s,
v1._vec[1]*s,
v1._vec[2]*s);
}
/// Component-wise division by a scalar
friend GfSize3 operator /(const GfSize3 &v1, size_t s) {
return GfSize3(v1._vec[0]/s,
v1._vec[1]/s,
v1._vec[2]/s);
}
/// Output operator
friend GF_API std::ostream &operator<<(std::ostream &o, GfSize3 const &v);
/// Conversion to GfVec3i
operator GfVec3i() const {
return GfVec3i(_vec[0],_vec[1],_vec[2]);
}
private:
size_t _vec[3];
};
// Friend functions must be declared
GF_API std::ostream &operator<<(std::ostream &o, GfSize3 const &v);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_SIZE3_H
+67
View File
@@ -0,0 +1,67 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_GF_TRAITS_H
#define PXR_BASE_GF_TRAITS_H
#include "pxr/pxr.h"
#include <type_traits>
PXR_NAMESPACE_OPEN_SCOPE
/// A metafunction with a static const bool member 'value' that is true for
/// GfVec types, like GfVec2i, GfVec4d, etc and false for all other types.
template <class T>
struct GfIsGfVec { static const bool value = false; };
/// A metafunction with a static const bool member 'value' that is true for
/// GfMatrix types, like GfMatrix3d, GfMatrix4f, etc and false for all other
/// types.
template <class T>
struct GfIsGfMatrix { static const bool value = false; };
/// A metafunction with a static const bool member 'value' that is true for
/// GfQuat types and false for all other types.
template <class T>
struct GfIsGfQuat { static const bool value = false; };
/// A metafunction with a static const bool member 'value' that is true for
/// GfRange types and false for all other types.
template <class T>
struct GfIsGfRange { static const bool value = false; };
/// A metafunction which is equivalent to std::is_floating_point but
/// allows for additional specialization for types like GfHalf
template <class T>
struct GfIsFloatingPoint : public std::is_floating_point<T>{};
/// A metafunction which is equivalent to std::arithmetic but
/// also includes any specializations from GfIsFloatingPoint (like GfHalf)
template <class T>
struct GfIsArithmetic : public std::integral_constant<
bool, GfIsFloatingPoint<T>::value || std::is_arithmetic<T>::value>{};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_TRAITS_H
+252
View File
@@ -0,0 +1,252 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_GF_TRANSFORM_H
#define PXR_BASE_GF_TRANSFORM_H
/// \file gf/transform.h
/// \ingroup group_gf_LinearAlgebra
#include "pxr/pxr.h"
#include "pxr/base/gf/rotation.h"
#include "pxr/base/gf/vec3d.h"
#include "pxr/base/gf/api.h"
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
class GfMatrix4d;
/// \class GfTransform
/// \ingroup group_gf_LinearAlgebra
///
/// Basic type: Compound linear transformation.
///
/// This class represents a linear transformation specified as a series of
/// individual components: a \em translation, a \em rotation, a \em scale, a
/// \em pivotPosition, and a \em pivotOrientation. When applied to a point,
/// the point will be transformed as follows (in order):
///
/// \li Scaled by the \em scale with respect to \em pivotPosition and the
/// orientation specified by the \em pivotOrientation.
/// \li Rotated by the \em rotation about \em pivotPosition.
/// \li Translated by \em Translation
///
/// That is, the cumulative matrix that this represents looks like this.
///
/// \code
/// M = -P * -O * S * O * R * P * T
/// \endcode
///
/// where
/// \li \em T is the \em translation matrix
/// \li \em P is the matrix that translates by \em pivotPosition
/// \li \em R is the \em rotation matrix
/// \li \em O is the matrix that rotates to \em pivotOrientation
/// \li \em S is the \em scale matrix
///
class GfTransform {
public:
/// The default constructor sets the component values to the
/// identity transformation.
GfTransform() {
SetIdentity();
}
/// This constructor initializes the transformation from all
/// component values. This is the constructor used by 2x code.
GfTransform(const GfVec3d &scale,
const GfRotation &pivotOrientation,
const GfRotation &rotation,
const GfVec3d &pivotPosition,
const GfVec3d &translation) {
Set(scale, pivotOrientation, rotation, pivotPosition, translation);
}
/// This constructor initializes the transformation from all
/// component values. This is the constructor used by 3x code.
GfTransform(const GfVec3d &translation,
const GfRotation &rotation,
const GfVec3d &scale,
const GfVec3d &pivotPosition,
const GfRotation &pivotOrientation) {
Set(translation, rotation, scale, pivotPosition, pivotOrientation);
}
/// This constructor initializes the transformation with a matrix. See
/// SetMatrix() for more information.
GfTransform(const GfMatrix4d &m) {
SetIdentity();
SetMatrix(m);
}
/// Sets the transformation from all component values.
/// This constructor orders its arguments the way that 2x expects.
GF_API
GfTransform & Set(const GfVec3d &scale,
const GfRotation &pivotOrientation,
const GfRotation &rotation,
const GfVec3d &pivotPosition,
const GfVec3d &translation);
/// Sets the transformation from all component values.
/// This constructor orders its arguments the way that 3x expects.
GfTransform & Set(const GfVec3d &translation,
const GfRotation &rotation,
const GfVec3d &scale,
const GfVec3d &pivotPosition,
const GfRotation &pivotOrientation) {
return Set(scale, pivotOrientation, rotation,
pivotPosition, translation);
}
/// Sets the transform components to implement the transformation
/// represented by matrix \p m , ignoring any projection. This tries to
/// leave the current center unchanged.
GF_API
GfTransform & SetMatrix(const GfMatrix4d &m);
/// Sets the transformation to the identity transformation.
GF_API
GfTransform & SetIdentity();
/// Sets the scale component, leaving all others untouched.
void SetScale(const GfVec3d &scale) {
_scale = scale;
}
/// Sets the pivot orientation component, leaving all others untouched.
void SetPivotOrientation(const GfRotation &pivotOrient) {
_pivotOrientation = pivotOrient;
}
/// Sets the pivot orientation component, leaving all others untouched.
void SetScaleOrientation(const GfRotation &pivotOrient) {
SetPivotOrientation(pivotOrient);
}
/// Sets the rotation component, leaving all others untouched.
void SetRotation(const GfRotation &rotation) {
_rotation = rotation;
}
/// Sets the pivot position component, leaving all others untouched.
void SetPivotPosition(const GfVec3d &pivPos) {
_pivotPosition = pivPos;
}
/// Sets the pivot position component, leaving all others untouched.
void SetCenter(const GfVec3d &pivPos) {
SetPivotPosition(pivPos);
}
/// Sets the translation component, leaving all others untouched.
void SetTranslation(const GfVec3d &translation) {
_translation = translation;
}
/// Returns the scale component.
const GfVec3d & GetScale() const {
return _scale;
}
/// Returns the pivot orientation component.
const GfRotation & GetPivotOrientation() const {
return _pivotOrientation;
}
/// Returns the scale orientation component.
const GfRotation & GetScaleOrientation() const {
return GetPivotOrientation();
}
/// Returns the rotation component.
const GfRotation & GetRotation() const {
return _rotation;
}
/// Returns the pivot position component.
const GfVec3d & GetPivotPosition() const {
return _pivotPosition;
}
/// Returns the pivot position component.
const GfVec3d & GetCenter() const {
return GetPivotPosition();
}
/// Returns the translation component.
const GfVec3d & GetTranslation() const {
return _translation;
}
/// Returns a \c GfMatrix4d that implements the cumulative transformation.
GF_API
GfMatrix4d GetMatrix() const;
/// Component-wise transform equality test. All components must match
/// exactly for transforms to be considered equal.
GF_API
bool operator ==(const GfTransform &xf) const;
/// Component-wise transform inequality test. All components must match
/// exactly for transforms to be considered equal.
bool operator !=(const GfTransform &xf) const {
return ! (*this == xf);
}
/// Post-multiplies transform \p xf into this transform.
GF_API
GfTransform & operator *=(const GfTransform &xf);
/// Returns the product of transforms \p xf1 and \p xf2.
friend GfTransform operator *(const GfTransform &xf1,
const GfTransform &xf2) {
GfTransform xf = xf1;
return xf *= xf2;
}
private:
/// translation
GfVec3d _translation;
/// rotation
GfRotation _rotation;
/// scale factors
GfVec3d _scale;
/// orientation used for scaling and rotation
GfRotation _pivotOrientation;
/// center of rotation and scaling
GfVec3d _pivotPosition;
};
/// Output a GfTransform using the format
/// [scale, scaleorientation, rotation, center, translation].
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream&, const GfTransform&);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_TRANSFORM_H
+397
View File
@@ -0,0 +1,397 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// vec.template.h file to make changes.
#ifndef PXR_BASE_GF_VEC2D_H
#define PXR_BASE_GF_VEC2D_H
/// \file gf/vec2d.h
/// \ingroup group_gf_LinearAlgebra
#include "pxr/pxr.h"
#include "pxr/base/tf/diagnostic.h"
#include "pxr/base/gf/api.h"
#include "pxr/base/gf/limits.h"
#include "pxr/base/gf/traits.h"
#include "pxr/base/gf/math.h"
#include <boost/functional/hash.hpp>
#include <cstddef>
#include <cmath>
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
class GfVec2d;
template <>
struct GfIsGfVec<class GfVec2d> { static const bool value = true; };
/// \class GfVec2d
/// \ingroup group_gf_LinearAlgebra
///
/// Basic type for a vector of 2 double components.
///
/// Represents a vector of 2 components of type \c double.
/// It is intended to be fast and simple.
///
class GfVec2d
{
public:
/// Scalar element type and dimension.
typedef double ScalarType;
static const size_t dimension = 2;
/// Default constructor does no initialization.
GfVec2d() = default;
/// Initialize all elements to a single value.
constexpr explicit GfVec2d(double value)
: _data{ value, value }
{
}
/// Initialize all elements with explicit arguments.
constexpr GfVec2d(double s0, double s1)
: _data{ s0, s1 }
{
}
/// Construct with pointer to values.
template <class Scl>
constexpr explicit GfVec2d(Scl const *p)
: _data{ p[0], p[1] }
{
}
/// Implicitly convert from GfVec2f.
GfVec2d(class GfVec2f const &other);
/// Implicitly convert from GfVec2h.
GfVec2d(class GfVec2h const &other);
/// Implicitly convert from GfVec2i.
GfVec2d(class GfVec2i const &other);
/// Create a unit vector along the X-axis.
static GfVec2d XAxis() {
GfVec2d result(0);
result[0] = 1;
return result;
}
/// Create a unit vector along the Y-axis.
static GfVec2d YAxis() {
GfVec2d result(0);
result[1] = 1;
return result;
}
/// Create a unit vector along the i-th axis, zero-based. Return the zero
/// vector if \p i is greater than or equal to 2.
static GfVec2d Axis(size_t i) {
GfVec2d result(0);
if (i < 2)
result[i] = 1;
return result;
}
/// Set all elements with passed arguments.
GfVec2d &Set(double s0, double s1) {
_data[0] = s0;
_data[1] = s1;
return *this;
}
/// Set all elements with a pointer to data.
GfVec2d &Set(double const *a) {
return Set(a[0], a[1]);
}
/// Direct data access.
double const *data() const { return _data; }
double *data() { return _data; }
double const *GetArray() const { return data(); }
/// Indexing.
double const &operator[](size_t i) const { return _data[i]; }
double &operator[](size_t i) { return _data[i]; }
/// Hash.
friend inline size_t hash_value(GfVec2d const &vec) {
size_t h = 0;
boost::hash_combine(h, vec[0]);
boost::hash_combine(h, vec[1]);
return h;
}
/// Equality comparison.
bool operator==(GfVec2d const &other) const {
return _data[0] == other[0] &&
_data[1] == other[1];
}
bool operator!=(GfVec2d const &other) const {
return !(*this == other);
}
// TODO Add inequality for other vec types...
/// Equality comparison.
GF_API
bool operator==(class GfVec2f const &other) const;
/// Equality comparison.
GF_API
bool operator==(class GfVec2h const &other) const;
/// Equality comparison.
GF_API
bool operator==(class GfVec2i const &other) const;
/// Create a vec with negated elements.
GfVec2d operator-() const {
return GfVec2d(-_data[0], -_data[1]);
}
/// Addition.
GfVec2d &operator+=(GfVec2d const &other) {
_data[0] += other[0];
_data[1] += other[1];
return *this;
}
friend GfVec2d operator+(GfVec2d const &l, GfVec2d const &r) {
return GfVec2d(l) += r;
}
/// Subtraction.
GfVec2d &operator-=(GfVec2d const &other) {
_data[0] -= other[0];
_data[1] -= other[1];
return *this;
}
friend GfVec2d operator-(GfVec2d const &l, GfVec2d const &r) {
return GfVec2d(l) -= r;
}
/// Multiplication by scalar.
GfVec2d &operator*=(double s) {
_data[0] *= s;
_data[1] *= s;
return *this;
}
GfVec2d operator*(double s) const {
return GfVec2d(*this) *= s;
}
friend GfVec2d operator*(double s, GfVec2d const &v) {
return v * s;
}
/// Division by scalar.
// TODO should divide by the scalar type.
GfVec2d &operator/=(double s) {
// TODO This should not multiply by 1/s, it should do the division.
// Doing the division is more numerically stable when s is close to
// zero.
return *this *= (1.0 / s);
}
GfVec2d operator/(double s) const {
return *this * (1.0 / s);
}
/// See GfDot().
double operator*(GfVec2d const &v) const {
return _data[0] * v[0] + _data[1] * v[1];
}
/// Returns the projection of \p this onto \p v. That is:
/// \code
/// v * (*this * v)
/// \endcode
GfVec2d GetProjection(GfVec2d const &v) const {
return v * (*this * v);
}
/// Returns the orthogonal complement of \p this->GetProjection(b).
/// That is:
/// \code
/// *this - this->GetProjection(b)
/// \endcode
GfVec2d GetComplement(GfVec2d const &b) const {
return *this - this->GetProjection(b);
}
/// Squared length.
double GetLengthSq() const {
return *this * *this;
}
/// Length
double GetLength() const {
// TODO should use GfSqrt.
return sqrt(GetLengthSq());
}
/// Normalizes the vector in place to unit length, returning the
/// length before normalization. If the length of the vector is
/// smaller than \p eps, then the vector is set to vector/\c eps.
/// The original length of the vector is returned. See also GfNormalize().
///
/// \todo This was fixed for bug 67777. This is a gcc64 optimizer bug.
/// By tickling the code, it no longer tries to write into
/// an illegal memory address (in the code section of memory).
double Normalize(double eps = GF_MIN_VECTOR_LENGTH) {
// TODO this seems suspect... suggest dividing by length so long as
// length is not zero.
double length = GetLength();
*this /= (length > eps) ? length : eps;
return length;
}
GfVec2d GetNormalized(double eps = GF_MIN_VECTOR_LENGTH) const {
GfVec2d normalized(*this);
normalized.Normalize(eps);
return normalized;
}
private:
double _data[2];
};
/// Output a GfVec2d.
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream &, GfVec2d const &);
PXR_NAMESPACE_CLOSE_SCOPE
#include "pxr/base/gf/vec2f.h"
#include "pxr/base/gf/vec2h.h"
#include "pxr/base/gf/vec2i.h"
PXR_NAMESPACE_OPEN_SCOPE
inline
GfVec2d::GfVec2d(class GfVec2f const &other)
{
_data[0] = other[0];
_data[1] = other[1];
}
inline
GfVec2d::GfVec2d(class GfVec2h const &other)
{
_data[0] = other[0];
_data[1] = other[1];
}
inline
GfVec2d::GfVec2d(class GfVec2i const &other)
{
_data[0] = other[0];
_data[1] = other[1];
}
/// Returns component-wise multiplication of vectors \p v1 and \p v2.
inline GfVec2d
GfCompMult(GfVec2d const &v1, GfVec2d const &v2) {
return GfVec2d(
v1[0] * v2[0],
v1[1] * v2[1]
);
}
/// Returns component-wise quotient of vectors \p v1 and \p v2.
inline GfVec2d
GfCompDiv(GfVec2d const &v1, GfVec2d const &v2) {
return GfVec2d(
v1[0] / v2[0],
v1[1] / v2[1]
);
}
/// Returns the dot (inner) product of two vectors.
inline double
GfDot(GfVec2d const &v1, GfVec2d const &v2) {
return v1 * v2;
}
/// Returns the geometric length of \c v.
inline double
GfGetLength(GfVec2d const &v)
{
return v.GetLength();
}
/// Normalizes \c *v in place to unit length, returning the length before
/// normalization. If the length of \c *v is smaller than \p eps then \c *v is
/// set to \c *v/eps. The original length of \c *v is returned.
inline double
GfNormalize(GfVec2d *v, double eps = GF_MIN_VECTOR_LENGTH)
{
return v->Normalize(eps);
}
/// Returns a normalized (unit-length) vector with the same direction as \p v.
/// If the length of this vector is smaller than \p eps, the vector divided by
/// \p eps is returned.
inline GfVec2d
GfGetNormalized(GfVec2d const &v, double eps = GF_MIN_VECTOR_LENGTH)
{
return v.GetNormalized(eps);
}
/// Returns the projection of \p a onto \p b. That is:
/// \code
/// b * (a * b)
/// \endcode
inline GfVec2d
GfGetProjection(GfVec2d const &a, GfVec2d const &b)
{
return a.GetProjection(b);
}
/// Returns the orthogonal complement of \p a.GetProjection(b). That is:
/// \code
/// a - a.GetProjection(b)
/// \endcode
inline GfVec2d
GfGetComplement(GfVec2d const &a, GfVec2d const &b)
{
return a.GetComplement(b);
}
/// Tests for equality within a given tolerance, returning \c true if the
/// length of the difference vector is less than or equal to \p tolerance.
inline bool
GfIsClose(GfVec2d const &v1, GfVec2d const &v2, double tolerance)
{
GfVec2d delta = v1 - v2;
return delta.GetLengthSq() <= tolerance * tolerance;
}
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_VEC2D_H
+397
View File
@@ -0,0 +1,397 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// vec.template.h file to make changes.
#ifndef PXR_BASE_GF_VEC2F_H
#define PXR_BASE_GF_VEC2F_H
/// \file gf/vec2f.h
/// \ingroup group_gf_LinearAlgebra
#include "pxr/pxr.h"
#include "pxr/base/tf/diagnostic.h"
#include "pxr/base/gf/api.h"
#include "pxr/base/gf/limits.h"
#include "pxr/base/gf/traits.h"
#include "pxr/base/gf/math.h"
#include <boost/functional/hash.hpp>
#include <cstddef>
#include <cmath>
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
class GfVec2f;
template <>
struct GfIsGfVec<class GfVec2f> { static const bool value = true; };
/// \class GfVec2f
/// \ingroup group_gf_LinearAlgebra
///
/// Basic type for a vector of 2 float components.
///
/// Represents a vector of 2 components of type \c float.
/// It is intended to be fast and simple.
///
class GfVec2f
{
public:
/// Scalar element type and dimension.
typedef float ScalarType;
static const size_t dimension = 2;
/// Default constructor does no initialization.
GfVec2f() = default;
/// Initialize all elements to a single value.
constexpr explicit GfVec2f(float value)
: _data{ value, value }
{
}
/// Initialize all elements with explicit arguments.
constexpr GfVec2f(float s0, float s1)
: _data{ s0, s1 }
{
}
/// Construct with pointer to values.
template <class Scl>
constexpr explicit GfVec2f(Scl const *p)
: _data{ p[0], p[1] }
{
}
/// Construct from GfVec2d.
explicit GfVec2f(class GfVec2d const &other);
/// Implicitly convert from GfVec2h.
GfVec2f(class GfVec2h const &other);
/// Implicitly convert from GfVec2i.
GfVec2f(class GfVec2i const &other);
/// Create a unit vector along the X-axis.
static GfVec2f XAxis() {
GfVec2f result(0);
result[0] = 1;
return result;
}
/// Create a unit vector along the Y-axis.
static GfVec2f YAxis() {
GfVec2f result(0);
result[1] = 1;
return result;
}
/// Create a unit vector along the i-th axis, zero-based. Return the zero
/// vector if \p i is greater than or equal to 2.
static GfVec2f Axis(size_t i) {
GfVec2f result(0);
if (i < 2)
result[i] = 1;
return result;
}
/// Set all elements with passed arguments.
GfVec2f &Set(float s0, float s1) {
_data[0] = s0;
_data[1] = s1;
return *this;
}
/// Set all elements with a pointer to data.
GfVec2f &Set(float const *a) {
return Set(a[0], a[1]);
}
/// Direct data access.
float const *data() const { return _data; }
float *data() { return _data; }
float const *GetArray() const { return data(); }
/// Indexing.
float const &operator[](size_t i) const { return _data[i]; }
float &operator[](size_t i) { return _data[i]; }
/// Hash.
friend inline size_t hash_value(GfVec2f const &vec) {
size_t h = 0;
boost::hash_combine(h, vec[0]);
boost::hash_combine(h, vec[1]);
return h;
}
/// Equality comparison.
bool operator==(GfVec2f const &other) const {
return _data[0] == other[0] &&
_data[1] == other[1];
}
bool operator!=(GfVec2f const &other) const {
return !(*this == other);
}
// TODO Add inequality for other vec types...
/// Equality comparison.
GF_API
bool operator==(class GfVec2d const &other) const;
/// Equality comparison.
GF_API
bool operator==(class GfVec2h const &other) const;
/// Equality comparison.
GF_API
bool operator==(class GfVec2i const &other) const;
/// Create a vec with negated elements.
GfVec2f operator-() const {
return GfVec2f(-_data[0], -_data[1]);
}
/// Addition.
GfVec2f &operator+=(GfVec2f const &other) {
_data[0] += other[0];
_data[1] += other[1];
return *this;
}
friend GfVec2f operator+(GfVec2f const &l, GfVec2f const &r) {
return GfVec2f(l) += r;
}
/// Subtraction.
GfVec2f &operator-=(GfVec2f const &other) {
_data[0] -= other[0];
_data[1] -= other[1];
return *this;
}
friend GfVec2f operator-(GfVec2f const &l, GfVec2f const &r) {
return GfVec2f(l) -= r;
}
/// Multiplication by scalar.
GfVec2f &operator*=(double s) {
_data[0] *= s;
_data[1] *= s;
return *this;
}
GfVec2f operator*(double s) const {
return GfVec2f(*this) *= s;
}
friend GfVec2f operator*(double s, GfVec2f const &v) {
return v * s;
}
/// Division by scalar.
// TODO should divide by the scalar type.
GfVec2f &operator/=(double s) {
// TODO This should not multiply by 1/s, it should do the division.
// Doing the division is more numerically stable when s is close to
// zero.
return *this *= (1.0 / s);
}
GfVec2f operator/(double s) const {
return *this * (1.0 / s);
}
/// See GfDot().
float operator*(GfVec2f const &v) const {
return _data[0] * v[0] + _data[1] * v[1];
}
/// Returns the projection of \p this onto \p v. That is:
/// \code
/// v * (*this * v)
/// \endcode
GfVec2f GetProjection(GfVec2f const &v) const {
return v * (*this * v);
}
/// Returns the orthogonal complement of \p this->GetProjection(b).
/// That is:
/// \code
/// *this - this->GetProjection(b)
/// \endcode
GfVec2f GetComplement(GfVec2f const &b) const {
return *this - this->GetProjection(b);
}
/// Squared length.
float GetLengthSq() const {
return *this * *this;
}
/// Length
float GetLength() const {
// TODO should use GfSqrt.
return sqrt(GetLengthSq());
}
/// Normalizes the vector in place to unit length, returning the
/// length before normalization. If the length of the vector is
/// smaller than \p eps, then the vector is set to vector/\c eps.
/// The original length of the vector is returned. See also GfNormalize().
///
/// \todo This was fixed for bug 67777. This is a gcc64 optimizer bug.
/// By tickling the code, it no longer tries to write into
/// an illegal memory address (in the code section of memory).
float Normalize(float eps = GF_MIN_VECTOR_LENGTH) {
// TODO this seems suspect... suggest dividing by length so long as
// length is not zero.
float length = GetLength();
*this /= (length > eps) ? length : eps;
return length;
}
GfVec2f GetNormalized(float eps = GF_MIN_VECTOR_LENGTH) const {
GfVec2f normalized(*this);
normalized.Normalize(eps);
return normalized;
}
private:
float _data[2];
};
/// Output a GfVec2f.
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream &, GfVec2f const &);
PXR_NAMESPACE_CLOSE_SCOPE
#include "pxr/base/gf/vec2d.h"
#include "pxr/base/gf/vec2h.h"
#include "pxr/base/gf/vec2i.h"
PXR_NAMESPACE_OPEN_SCOPE
inline
GfVec2f::GfVec2f(class GfVec2d const &other)
{
_data[0] = other[0];
_data[1] = other[1];
}
inline
GfVec2f::GfVec2f(class GfVec2h const &other)
{
_data[0] = other[0];
_data[1] = other[1];
}
inline
GfVec2f::GfVec2f(class GfVec2i const &other)
{
_data[0] = other[0];
_data[1] = other[1];
}
/// Returns component-wise multiplication of vectors \p v1 and \p v2.
inline GfVec2f
GfCompMult(GfVec2f const &v1, GfVec2f const &v2) {
return GfVec2f(
v1[0] * v2[0],
v1[1] * v2[1]
);
}
/// Returns component-wise quotient of vectors \p v1 and \p v2.
inline GfVec2f
GfCompDiv(GfVec2f const &v1, GfVec2f const &v2) {
return GfVec2f(
v1[0] / v2[0],
v1[1] / v2[1]
);
}
/// Returns the dot (inner) product of two vectors.
inline float
GfDot(GfVec2f const &v1, GfVec2f const &v2) {
return v1 * v2;
}
/// Returns the geometric length of \c v.
inline float
GfGetLength(GfVec2f const &v)
{
return v.GetLength();
}
/// Normalizes \c *v in place to unit length, returning the length before
/// normalization. If the length of \c *v is smaller than \p eps then \c *v is
/// set to \c *v/eps. The original length of \c *v is returned.
inline float
GfNormalize(GfVec2f *v, float eps = GF_MIN_VECTOR_LENGTH)
{
return v->Normalize(eps);
}
/// Returns a normalized (unit-length) vector with the same direction as \p v.
/// If the length of this vector is smaller than \p eps, the vector divided by
/// \p eps is returned.
inline GfVec2f
GfGetNormalized(GfVec2f const &v, float eps = GF_MIN_VECTOR_LENGTH)
{
return v.GetNormalized(eps);
}
/// Returns the projection of \p a onto \p b. That is:
/// \code
/// b * (a * b)
/// \endcode
inline GfVec2f
GfGetProjection(GfVec2f const &a, GfVec2f const &b)
{
return a.GetProjection(b);
}
/// Returns the orthogonal complement of \p a.GetProjection(b). That is:
/// \code
/// a - a.GetProjection(b)
/// \endcode
inline GfVec2f
GfGetComplement(GfVec2f const &a, GfVec2f const &b)
{
return a.GetComplement(b);
}
/// Tests for equality within a given tolerance, returning \c true if the
/// length of the difference vector is less than or equal to \p tolerance.
inline bool
GfIsClose(GfVec2f const &v1, GfVec2f const &v2, double tolerance)
{
GfVec2f delta = v1 - v2;
return delta.GetLengthSq() <= tolerance * tolerance;
}
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_VEC2F_H
+398
View File
@@ -0,0 +1,398 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// vec.template.h file to make changes.
#ifndef PXR_BASE_GF_VEC2H_H
#define PXR_BASE_GF_VEC2H_H
/// \file gf/vec2h.h
/// \ingroup group_gf_LinearAlgebra
#include "pxr/pxr.h"
#include "pxr/base/tf/diagnostic.h"
#include "pxr/base/gf/api.h"
#include "pxr/base/gf/limits.h"
#include "pxr/base/gf/traits.h"
#include "pxr/base/gf/math.h"
#include "pxr/base/gf/half.h"
#include <boost/functional/hash.hpp>
#include <cstddef>
#include <cmath>
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
class GfVec2h;
template <>
struct GfIsGfVec<class GfVec2h> { static const bool value = true; };
/// \class GfVec2h
/// \ingroup group_gf_LinearAlgebra
///
/// Basic type for a vector of 2 GfHalf components.
///
/// Represents a vector of 2 components of type \c GfHalf.
/// It is intended to be fast and simple.
///
class GfVec2h
{
public:
/// Scalar element type and dimension.
typedef GfHalf ScalarType;
static const size_t dimension = 2;
/// Default constructor does no initialization.
GfVec2h() = default;
/// Initialize all elements to a single value.
constexpr explicit GfVec2h(GfHalf value)
: _data{ value, value }
{
}
/// Initialize all elements with explicit arguments.
constexpr GfVec2h(GfHalf s0, GfHalf s1)
: _data{ s0, s1 }
{
}
/// Construct with pointer to values.
template <class Scl>
constexpr explicit GfVec2h(Scl const *p)
: _data{ p[0], p[1] }
{
}
/// Construct from GfVec2d.
explicit GfVec2h(class GfVec2d const &other);
/// Construct from GfVec2f.
explicit GfVec2h(class GfVec2f const &other);
/// Implicitly convert from GfVec2i.
GfVec2h(class GfVec2i const &other);
/// Create a unit vector along the X-axis.
static GfVec2h XAxis() {
GfVec2h result(0);
result[0] = 1;
return result;
}
/// Create a unit vector along the Y-axis.
static GfVec2h YAxis() {
GfVec2h result(0);
result[1] = 1;
return result;
}
/// Create a unit vector along the i-th axis, zero-based. Return the zero
/// vector if \p i is greater than or equal to 2.
static GfVec2h Axis(size_t i) {
GfVec2h result(0);
if (i < 2)
result[i] = 1;
return result;
}
/// Set all elements with passed arguments.
GfVec2h &Set(GfHalf s0, GfHalf s1) {
_data[0] = s0;
_data[1] = s1;
return *this;
}
/// Set all elements with a pointer to data.
GfVec2h &Set(GfHalf const *a) {
return Set(a[0], a[1]);
}
/// Direct data access.
GfHalf const *data() const { return _data; }
GfHalf *data() { return _data; }
GfHalf const *GetArray() const { return data(); }
/// Indexing.
GfHalf const &operator[](size_t i) const { return _data[i]; }
GfHalf &operator[](size_t i) { return _data[i]; }
/// Hash.
friend inline size_t hash_value(GfVec2h const &vec) {
size_t h = 0;
boost::hash_combine(h, vec[0]);
boost::hash_combine(h, vec[1]);
return h;
}
/// Equality comparison.
bool operator==(GfVec2h const &other) const {
return _data[0] == other[0] &&
_data[1] == other[1];
}
bool operator!=(GfVec2h const &other) const {
return !(*this == other);
}
// TODO Add inequality for other vec types...
/// Equality comparison.
GF_API
bool operator==(class GfVec2d const &other) const;
/// Equality comparison.
GF_API
bool operator==(class GfVec2f const &other) const;
/// Equality comparison.
GF_API
bool operator==(class GfVec2i const &other) const;
/// Create a vec with negated elements.
GfVec2h operator-() const {
return GfVec2h(-_data[0], -_data[1]);
}
/// Addition.
GfVec2h &operator+=(GfVec2h const &other) {
_data[0] += other[0];
_data[1] += other[1];
return *this;
}
friend GfVec2h operator+(GfVec2h const &l, GfVec2h const &r) {
return GfVec2h(l) += r;
}
/// Subtraction.
GfVec2h &operator-=(GfVec2h const &other) {
_data[0] -= other[0];
_data[1] -= other[1];
return *this;
}
friend GfVec2h operator-(GfVec2h const &l, GfVec2h const &r) {
return GfVec2h(l) -= r;
}
/// Multiplication by scalar.
GfVec2h &operator*=(double s) {
_data[0] *= s;
_data[1] *= s;
return *this;
}
GfVec2h operator*(double s) const {
return GfVec2h(*this) *= s;
}
friend GfVec2h operator*(double s, GfVec2h const &v) {
return v * s;
}
/// Division by scalar.
// TODO should divide by the scalar type.
GfVec2h &operator/=(double s) {
// TODO This should not multiply by 1/s, it should do the division.
// Doing the division is more numerically stable when s is close to
// zero.
return *this *= (1.0 / s);
}
GfVec2h operator/(double s) const {
return *this * (1.0 / s);
}
/// See GfDot().
GfHalf operator*(GfVec2h const &v) const {
return _data[0] * v[0] + _data[1] * v[1];
}
/// Returns the projection of \p this onto \p v. That is:
/// \code
/// v * (*this * v)
/// \endcode
GfVec2h GetProjection(GfVec2h const &v) const {
return v * (*this * v);
}
/// Returns the orthogonal complement of \p this->GetProjection(b).
/// That is:
/// \code
/// *this - this->GetProjection(b)
/// \endcode
GfVec2h GetComplement(GfVec2h const &b) const {
return *this - this->GetProjection(b);
}
/// Squared length.
GfHalf GetLengthSq() const {
return *this * *this;
}
/// Length
GfHalf GetLength() const {
// TODO should use GfSqrt.
return sqrt(GetLengthSq());
}
/// Normalizes the vector in place to unit length, returning the
/// length before normalization. If the length of the vector is
/// smaller than \p eps, then the vector is set to vector/\c eps.
/// The original length of the vector is returned. See also GfNormalize().
///
/// \todo This was fixed for bug 67777. This is a gcc64 optimizer bug.
/// By tickling the code, it no longer tries to write into
/// an illegal memory address (in the code section of memory).
GfHalf Normalize(GfHalf eps = 0.001) {
// TODO this seems suspect... suggest dividing by length so long as
// length is not zero.
GfHalf length = GetLength();
*this /= (length > eps) ? length : eps;
return length;
}
GfVec2h GetNormalized(GfHalf eps = 0.001) const {
GfVec2h normalized(*this);
normalized.Normalize(eps);
return normalized;
}
private:
GfHalf _data[2];
};
/// Output a GfVec2h.
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream &, GfVec2h const &);
PXR_NAMESPACE_CLOSE_SCOPE
#include "pxr/base/gf/vec2d.h"
#include "pxr/base/gf/vec2f.h"
#include "pxr/base/gf/vec2i.h"
PXR_NAMESPACE_OPEN_SCOPE
inline
GfVec2h::GfVec2h(class GfVec2d const &other)
{
_data[0] = other[0];
_data[1] = other[1];
}
inline
GfVec2h::GfVec2h(class GfVec2f const &other)
{
_data[0] = other[0];
_data[1] = other[1];
}
inline
GfVec2h::GfVec2h(class GfVec2i const &other)
{
_data[0] = other[0];
_data[1] = other[1];
}
/// Returns component-wise multiplication of vectors \p v1 and \p v2.
inline GfVec2h
GfCompMult(GfVec2h const &v1, GfVec2h const &v2) {
return GfVec2h(
v1[0] * v2[0],
v1[1] * v2[1]
);
}
/// Returns component-wise quotient of vectors \p v1 and \p v2.
inline GfVec2h
GfCompDiv(GfVec2h const &v1, GfVec2h const &v2) {
return GfVec2h(
v1[0] / v2[0],
v1[1] / v2[1]
);
}
/// Returns the dot (inner) product of two vectors.
inline GfHalf
GfDot(GfVec2h const &v1, GfVec2h const &v2) {
return v1 * v2;
}
/// Returns the geometric length of \c v.
inline GfHalf
GfGetLength(GfVec2h const &v)
{
return v.GetLength();
}
/// Normalizes \c *v in place to unit length, returning the length before
/// normalization. If the length of \c *v is smaller than \p eps then \c *v is
/// set to \c *v/eps. The original length of \c *v is returned.
inline GfHalf
GfNormalize(GfVec2h *v, GfHalf eps = 0.001)
{
return v->Normalize(eps);
}
/// Returns a normalized (unit-length) vector with the same direction as \p v.
/// If the length of this vector is smaller than \p eps, the vector divided by
/// \p eps is returned.
inline GfVec2h
GfGetNormalized(GfVec2h const &v, GfHalf eps = 0.001)
{
return v.GetNormalized(eps);
}
/// Returns the projection of \p a onto \p b. That is:
/// \code
/// b * (a * b)
/// \endcode
inline GfVec2h
GfGetProjection(GfVec2h const &a, GfVec2h const &b)
{
return a.GetProjection(b);
}
/// Returns the orthogonal complement of \p a.GetProjection(b). That is:
/// \code
/// a - a.GetProjection(b)
/// \endcode
inline GfVec2h
GfGetComplement(GfVec2h const &a, GfVec2h const &b)
{
return a.GetComplement(b);
}
/// Tests for equality within a given tolerance, returning \c true if the
/// length of the difference vector is less than or equal to \p tolerance.
inline bool
GfIsClose(GfVec2h const &v1, GfVec2h const &v2, double tolerance)
{
GfVec2h delta = v1 - v2;
return delta.GetLengthSq() <= tolerance * tolerance;
}
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_VEC2H_H
+273
View File
@@ -0,0 +1,273 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// vec.template.h file to make changes.
#ifndef PXR_BASE_GF_VEC2I_H
#define PXR_BASE_GF_VEC2I_H
/// \file gf/vec2i.h
/// \ingroup group_gf_LinearAlgebra
#include "pxr/pxr.h"
#include "pxr/base/tf/diagnostic.h"
#include "pxr/base/gf/api.h"
#include "pxr/base/gf/limits.h"
#include "pxr/base/gf/traits.h"
#include <boost/functional/hash.hpp>
#include <cstddef>
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
class GfVec2i;
template <>
struct GfIsGfVec<class GfVec2i> { static const bool value = true; };
/// \class GfVec2i
/// \ingroup group_gf_LinearAlgebra
///
/// Basic type for a vector of 2 int components.
///
/// Represents a vector of 2 components of type \c int.
/// It is intended to be fast and simple.
///
class GfVec2i
{
public:
/// Scalar element type and dimension.
typedef int ScalarType;
static const size_t dimension = 2;
/// Default constructor does no initialization.
GfVec2i() = default;
/// Initialize all elements to a single value.
constexpr explicit GfVec2i(int value)
: _data{ value, value }
{
}
/// Initialize all elements with explicit arguments.
constexpr GfVec2i(int s0, int s1)
: _data{ s0, s1 }
{
}
/// Construct with pointer to values.
template <class Scl>
constexpr explicit GfVec2i(Scl const *p)
: _data{ p[0], p[1] }
{
}
/// Create a unit vector along the X-axis.
static GfVec2i XAxis() {
GfVec2i result(0);
result[0] = 1;
return result;
}
/// Create a unit vector along the Y-axis.
static GfVec2i YAxis() {
GfVec2i result(0);
result[1] = 1;
return result;
}
/// Create a unit vector along the i-th axis, zero-based. Return the zero
/// vector if \p i is greater than or equal to 2.
static GfVec2i Axis(size_t i) {
GfVec2i result(0);
if (i < 2)
result[i] = 1;
return result;
}
/// Set all elements with passed arguments.
GfVec2i &Set(int s0, int s1) {
_data[0] = s0;
_data[1] = s1;
return *this;
}
/// Set all elements with a pointer to data.
GfVec2i &Set(int const *a) {
return Set(a[0], a[1]);
}
/// Direct data access.
int const *data() const { return _data; }
int *data() { return _data; }
int const *GetArray() const { return data(); }
/// Indexing.
int const &operator[](size_t i) const { return _data[i]; }
int &operator[](size_t i) { return _data[i]; }
/// Hash.
friend inline size_t hash_value(GfVec2i const &vec) {
size_t h = 0;
boost::hash_combine(h, vec[0]);
boost::hash_combine(h, vec[1]);
return h;
}
/// Equality comparison.
bool operator==(GfVec2i const &other) const {
return _data[0] == other[0] &&
_data[1] == other[1];
}
bool operator!=(GfVec2i const &other) const {
return !(*this == other);
}
// TODO Add inequality for other vec types...
/// Equality comparison.
GF_API
bool operator==(class GfVec2d const &other) const;
/// Equality comparison.
GF_API
bool operator==(class GfVec2f const &other) const;
/// Equality comparison.
GF_API
bool operator==(class GfVec2h const &other) const;
/// Create a vec with negated elements.
GfVec2i operator-() const {
return GfVec2i(-_data[0], -_data[1]);
}
/// Addition.
GfVec2i &operator+=(GfVec2i const &other) {
_data[0] += other[0];
_data[1] += other[1];
return *this;
}
friend GfVec2i operator+(GfVec2i const &l, GfVec2i const &r) {
return GfVec2i(l) += r;
}
/// Subtraction.
GfVec2i &operator-=(GfVec2i const &other) {
_data[0] -= other[0];
_data[1] -= other[1];
return *this;
}
friend GfVec2i operator-(GfVec2i const &l, GfVec2i const &r) {
return GfVec2i(l) -= r;
}
/// Multiplication by scalar.
GfVec2i &operator*=(double s) {
_data[0] *= s;
_data[1] *= s;
return *this;
}
GfVec2i operator*(double s) const {
return GfVec2i(*this) *= s;
}
friend GfVec2i operator*(double s, GfVec2i const &v) {
return v * s;
}
/// Division by scalar.
GfVec2i &operator/=(int s) {
_data[0] /= s;
_data[1] /= s;
return *this;
}
GfVec2i operator/(int s) const {
return GfVec2i(*this) /= s;
}
/// See GfDot().
int operator*(GfVec2i const &v) const {
return _data[0] * v[0] + _data[1] * v[1];
}
/// Returns the projection of \p this onto \p v. That is:
/// \code
/// v * (*this * v)
/// \endcode
GfVec2i GetProjection(GfVec2i const &v) const {
return v * (*this * v);
}
/// Returns the orthogonal complement of \p this->GetProjection(b).
/// That is:
/// \code
/// *this - this->GetProjection(b)
/// \endcode
GfVec2i GetComplement(GfVec2i const &b) const {
return *this - this->GetProjection(b);
}
/// Squared length.
int GetLengthSq() const {
return *this * *this;
}
private:
int _data[2];
};
/// Output a GfVec2i.
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream &, GfVec2i const &);
/// Returns component-wise multiplication of vectors \p v1 and \p v2.
inline GfVec2i
GfCompMult(GfVec2i const &v1, GfVec2i const &v2) {
return GfVec2i(
v1[0] * v2[0],
v1[1] * v2[1]
);
}
/// Returns component-wise quotient of vectors \p v1 and \p v2.
inline GfVec2i
GfCompDiv(GfVec2i const &v1, GfVec2i const &v2) {
return GfVec2i(
v1[0] / v2[0],
v1[1] / v2[1]
);
}
/// Returns the dot (inner) product of two vectors.
inline int
GfDot(GfVec2i const &v1, GfVec2i const &v2) {
return v1 * v2;
}
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_VEC2I_H
+470
View File
@@ -0,0 +1,470 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// vec.template.h file to make changes.
#ifndef PXR_BASE_GF_VEC3D_H
#define PXR_BASE_GF_VEC3D_H
/// \file gf/vec3d.h
/// \ingroup group_gf_LinearAlgebra
#include "pxr/pxr.h"
#include "pxr/base/tf/diagnostic.h"
#include "pxr/base/gf/api.h"
#include "pxr/base/gf/limits.h"
#include "pxr/base/gf/traits.h"
#include "pxr/base/gf/math.h"
#include <boost/functional/hash.hpp>
#include <cstddef>
#include <cmath>
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
class GfVec3d;
template <>
struct GfIsGfVec<class GfVec3d> { static const bool value = true; };
/// \class GfVec3d
/// \ingroup group_gf_LinearAlgebra
///
/// Basic type for a vector of 3 double components.
///
/// Represents a vector of 3 components of type \c double.
/// It is intended to be fast and simple.
///
class GfVec3d
{
public:
/// Scalar element type and dimension.
typedef double ScalarType;
static const size_t dimension = 3;
/// Default constructor does no initialization.
GfVec3d() = default;
/// Initialize all elements to a single value.
constexpr explicit GfVec3d(double value)
: _data{ value, value, value }
{
}
/// Initialize all elements with explicit arguments.
constexpr GfVec3d(double s0, double s1, double s2)
: _data{ s0, s1, s2 }
{
}
/// Construct with pointer to values.
template <class Scl>
constexpr explicit GfVec3d(Scl const *p)
: _data{ p[0], p[1], p[2] }
{
}
/// Implicitly convert from GfVec3f.
GfVec3d(class GfVec3f const &other);
/// Implicitly convert from GfVec3h.
GfVec3d(class GfVec3h const &other);
/// Implicitly convert from GfVec3i.
GfVec3d(class GfVec3i const &other);
/// Create a unit vector along the X-axis.
static GfVec3d XAxis() {
GfVec3d result(0);
result[0] = 1;
return result;
}
/// Create a unit vector along the Y-axis.
static GfVec3d YAxis() {
GfVec3d result(0);
result[1] = 1;
return result;
}
/// Create a unit vector along the Z-axis.
static GfVec3d ZAxis() {
GfVec3d result(0);
result[2] = 1;
return result;
}
/// Create a unit vector along the i-th axis, zero-based. Return the zero
/// vector if \p i is greater than or equal to 3.
static GfVec3d Axis(size_t i) {
GfVec3d result(0);
if (i < 3)
result[i] = 1;
return result;
}
/// Set all elements with passed arguments.
GfVec3d &Set(double s0, double s1, double s2) {
_data[0] = s0;
_data[1] = s1;
_data[2] = s2;
return *this;
}
/// Set all elements with a pointer to data.
GfVec3d &Set(double const *a) {
return Set(a[0], a[1], a[2]);
}
/// Direct data access.
double const *data() const { return _data; }
double *data() { return _data; }
double const *GetArray() const { return data(); }
/// Indexing.
double const &operator[](size_t i) const { return _data[i]; }
double &operator[](size_t i) { return _data[i]; }
/// Hash.
friend inline size_t hash_value(GfVec3d const &vec) {
size_t h = 0;
boost::hash_combine(h, vec[0]);
boost::hash_combine(h, vec[1]);
boost::hash_combine(h, vec[2]);
return h;
}
/// Equality comparison.
bool operator==(GfVec3d const &other) const {
return _data[0] == other[0] &&
_data[1] == other[1] &&
_data[2] == other[2];
}
bool operator!=(GfVec3d const &other) const {
return !(*this == other);
}
// TODO Add inequality for other vec types...
/// Equality comparison.
GF_API
bool operator==(class GfVec3f const &other) const;
/// Equality comparison.
GF_API
bool operator==(class GfVec3h const &other) const;
/// Equality comparison.
GF_API
bool operator==(class GfVec3i const &other) const;
/// Create a vec with negated elements.
GfVec3d operator-() const {
return GfVec3d(-_data[0], -_data[1], -_data[2]);
}
/// Addition.
GfVec3d &operator+=(GfVec3d const &other) {
_data[0] += other[0];
_data[1] += other[1];
_data[2] += other[2];
return *this;
}
friend GfVec3d operator+(GfVec3d const &l, GfVec3d const &r) {
return GfVec3d(l) += r;
}
/// Subtraction.
GfVec3d &operator-=(GfVec3d const &other) {
_data[0] -= other[0];
_data[1] -= other[1];
_data[2] -= other[2];
return *this;
}
friend GfVec3d operator-(GfVec3d const &l, GfVec3d const &r) {
return GfVec3d(l) -= r;
}
/// Multiplication by scalar.
GfVec3d &operator*=(double s) {
_data[0] *= s;
_data[1] *= s;
_data[2] *= s;
return *this;
}
GfVec3d operator*(double s) const {
return GfVec3d(*this) *= s;
}
friend GfVec3d operator*(double s, GfVec3d const &v) {
return v * s;
}
/// Division by scalar.
// TODO should divide by the scalar type.
GfVec3d &operator/=(double s) {
// TODO This should not multiply by 1/s, it should do the division.
// Doing the division is more numerically stable when s is close to
// zero.
return *this *= (1.0 / s);
}
GfVec3d operator/(double s) const {
return *this * (1.0 / s);
}
/// See GfDot().
double operator*(GfVec3d const &v) const {
return _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2];
}
/// Returns the projection of \p this onto \p v. That is:
/// \code
/// v * (*this * v)
/// \endcode
GfVec3d GetProjection(GfVec3d const &v) const {
return v * (*this * v);
}
/// Returns the orthogonal complement of \p this->GetProjection(b).
/// That is:
/// \code
/// *this - this->GetProjection(b)
/// \endcode
GfVec3d GetComplement(GfVec3d const &b) const {
return *this - this->GetProjection(b);
}
/// Squared length.
double GetLengthSq() const {
return *this * *this;
}
/// Length
double GetLength() const {
// TODO should use GfSqrt.
return sqrt(GetLengthSq());
}
/// Normalizes the vector in place to unit length, returning the
/// length before normalization. If the length of the vector is
/// smaller than \p eps, then the vector is set to vector/\c eps.
/// The original length of the vector is returned. See also GfNormalize().
///
/// \todo This was fixed for bug 67777. This is a gcc64 optimizer bug.
/// By tickling the code, it no longer tries to write into
/// an illegal memory address (in the code section of memory).
double Normalize(double eps = GF_MIN_VECTOR_LENGTH) {
// TODO this seems suspect... suggest dividing by length so long as
// length is not zero.
double length = GetLength();
*this /= (length > eps) ? length : eps;
return length;
}
GfVec3d GetNormalized(double eps = GF_MIN_VECTOR_LENGTH) const {
GfVec3d normalized(*this);
normalized.Normalize(eps);
return normalized;
}
/// Orthogonalize and optionally normalize a set of basis vectors. This
/// uses an iterative method that is very stable even when the vectors are
/// far from orthogonal (close to colinear). The number of iterations and
/// thus the computation time does increase as the vectors become close to
/// colinear, however. Returns a bool specifying whether the solution
/// converged after a number of iterations. If it did not converge, the
/// returned vectors will be as close as possible to orthogonal within the
/// iteration limit. Colinear vectors will be unaltered, and the method
/// will return false.
GF_API
static bool OrthogonalizeBasis(
GfVec3d *tx, GfVec3d *ty, GfVec3d *tz,
const bool normalize,
double eps = GF_MIN_ORTHO_TOLERANCE);
/// Sets \c v1 and \c v2 to unit vectors such that v1, v2 and *this are
/// mutually orthogonal. If the length L of *this is smaller than \c eps,
/// then v1 and v2 will have magnitude L/eps. As a result, the function
/// delivers a continuous result as *this shrinks in length.
GF_API
void BuildOrthonormalFrame(GfVec3d *v1, GfVec3d *v2,
double eps = GF_MIN_VECTOR_LENGTH) const;
private:
double _data[3];
};
/// Output a GfVec3d.
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream &, GfVec3d const &);
PXR_NAMESPACE_CLOSE_SCOPE
#include "pxr/base/gf/vec3f.h"
#include "pxr/base/gf/vec3h.h"
#include "pxr/base/gf/vec3i.h"
PXR_NAMESPACE_OPEN_SCOPE
inline
GfVec3d::GfVec3d(class GfVec3f const &other)
{
_data[0] = other[0];
_data[1] = other[1];
_data[2] = other[2];
}
inline
GfVec3d::GfVec3d(class GfVec3h const &other)
{
_data[0] = other[0];
_data[1] = other[1];
_data[2] = other[2];
}
inline
GfVec3d::GfVec3d(class GfVec3i const &other)
{
_data[0] = other[0];
_data[1] = other[1];
_data[2] = other[2];
}
/// Returns component-wise multiplication of vectors \p v1 and \p v2.
inline GfVec3d
GfCompMult(GfVec3d const &v1, GfVec3d const &v2) {
return GfVec3d(
v1[0] * v2[0],
v1[1] * v2[1],
v1[2] * v2[2]
);
}
/// Returns component-wise quotient of vectors \p v1 and \p v2.
inline GfVec3d
GfCompDiv(GfVec3d const &v1, GfVec3d const &v2) {
return GfVec3d(
v1[0] / v2[0],
v1[1] / v2[1],
v1[2] / v2[2]
);
}
/// Returns the dot (inner) product of two vectors.
inline double
GfDot(GfVec3d const &v1, GfVec3d const &v2) {
return v1 * v2;
}
/// Returns the geometric length of \c v.
inline double
GfGetLength(GfVec3d const &v)
{
return v.GetLength();
}
/// Normalizes \c *v in place to unit length, returning the length before
/// normalization. If the length of \c *v is smaller than \p eps then \c *v is
/// set to \c *v/eps. The original length of \c *v is returned.
inline double
GfNormalize(GfVec3d *v, double eps = GF_MIN_VECTOR_LENGTH)
{
return v->Normalize(eps);
}
/// Returns a normalized (unit-length) vector with the same direction as \p v.
/// If the length of this vector is smaller than \p eps, the vector divided by
/// \p eps is returned.
inline GfVec3d
GfGetNormalized(GfVec3d const &v, double eps = GF_MIN_VECTOR_LENGTH)
{
return v.GetNormalized(eps);
}
/// Returns the projection of \p a onto \p b. That is:
/// \code
/// b * (a * b)
/// \endcode
inline GfVec3d
GfGetProjection(GfVec3d const &a, GfVec3d const &b)
{
return a.GetProjection(b);
}
/// Returns the orthogonal complement of \p a.GetProjection(b). That is:
/// \code
/// a - a.GetProjection(b)
/// \endcode
inline GfVec3d
GfGetComplement(GfVec3d const &a, GfVec3d const &b)
{
return a.GetComplement(b);
}
/// Tests for equality within a given tolerance, returning \c true if the
/// length of the difference vector is less than or equal to \p tolerance.
inline bool
GfIsClose(GfVec3d const &v1, GfVec3d const &v2, double tolerance)
{
GfVec3d delta = v1 - v2;
return delta.GetLengthSq() <= tolerance * tolerance;
}
GF_API bool
GfOrthogonalizeBasis(GfVec3d *tx, GfVec3d *ty, GfVec3d *tz,
bool normalize, double eps = GF_MIN_ORTHO_TOLERANCE);
GF_API void
GfBuildOrthonormalFrame(GfVec3d const &v0,
GfVec3d* v1,
GfVec3d* v2,
double eps = GF_MIN_VECTOR_LENGTH);
/// Returns the cross product of \p v1 and \p v2.
inline GfVec3d
GfCross(GfVec3d const &v1, GfVec3d const &v2)
{
return GfVec3d(
v1[1] * v2[2] - v1[2] * v2[1],
v1[2] * v2[0] - v1[0] * v2[2],
v1[0] * v2[1] - v1[1] * v2[0]);
}
/// Returns the cross product of \p v1 and \p v2.
/// \see GfCross()
inline GfVec3d
operator^(GfVec3d const &v1, GfVec3d const &v2)
{
return GfCross(v1, v2);
}
/// Spherical linear interpolation in three dimensions.
GF_API GfVec3d
GfSlerp(double alpha, GfVec3d const &v0, GfVec3d const &v1);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_VEC3D_H
+470
View File
@@ -0,0 +1,470 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// vec.template.h file to make changes.
#ifndef PXR_BASE_GF_VEC3F_H
#define PXR_BASE_GF_VEC3F_H
/// \file gf/vec3f.h
/// \ingroup group_gf_LinearAlgebra
#include "pxr/pxr.h"
#include "pxr/base/tf/diagnostic.h"
#include "pxr/base/gf/api.h"
#include "pxr/base/gf/limits.h"
#include "pxr/base/gf/traits.h"
#include "pxr/base/gf/math.h"
#include <boost/functional/hash.hpp>
#include <cstddef>
#include <cmath>
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
class GfVec3f;
template <>
struct GfIsGfVec<class GfVec3f> { static const bool value = true; };
/// \class GfVec3f
/// \ingroup group_gf_LinearAlgebra
///
/// Basic type for a vector of 3 float components.
///
/// Represents a vector of 3 components of type \c float.
/// It is intended to be fast and simple.
///
class GfVec3f
{
public:
/// Scalar element type and dimension.
typedef float ScalarType;
static const size_t dimension = 3;
/// Default constructor does no initialization.
GfVec3f() = default;
/// Initialize all elements to a single value.
constexpr explicit GfVec3f(float value)
: _data{ value, value, value }
{
}
/// Initialize all elements with explicit arguments.
constexpr GfVec3f(float s0, float s1, float s2)
: _data{ s0, s1, s2 }
{
}
/// Construct with pointer to values.
template <class Scl>
constexpr explicit GfVec3f(Scl const *p)
: _data{ p[0], p[1], p[2] }
{
}
/// Construct from GfVec3d.
explicit GfVec3f(class GfVec3d const &other);
/// Implicitly convert from GfVec3h.
GfVec3f(class GfVec3h const &other);
/// Implicitly convert from GfVec3i.
GfVec3f(class GfVec3i const &other);
/// Create a unit vector along the X-axis.
static GfVec3f XAxis() {
GfVec3f result(0);
result[0] = 1;
return result;
}
/// Create a unit vector along the Y-axis.
static GfVec3f YAxis() {
GfVec3f result(0);
result[1] = 1;
return result;
}
/// Create a unit vector along the Z-axis.
static GfVec3f ZAxis() {
GfVec3f result(0);
result[2] = 1;
return result;
}
/// Create a unit vector along the i-th axis, zero-based. Return the zero
/// vector if \p i is greater than or equal to 3.
static GfVec3f Axis(size_t i) {
GfVec3f result(0);
if (i < 3)
result[i] = 1;
return result;
}
/// Set all elements with passed arguments.
GfVec3f &Set(float s0, float s1, float s2) {
_data[0] = s0;
_data[1] = s1;
_data[2] = s2;
return *this;
}
/// Set all elements with a pointer to data.
GfVec3f &Set(float const *a) {
return Set(a[0], a[1], a[2]);
}
/// Direct data access.
float const *data() const { return _data; }
float *data() { return _data; }
float const *GetArray() const { return data(); }
/// Indexing.
float const &operator[](size_t i) const { return _data[i]; }
float &operator[](size_t i) { return _data[i]; }
/// Hash.
friend inline size_t hash_value(GfVec3f const &vec) {
size_t h = 0;
boost::hash_combine(h, vec[0]);
boost::hash_combine(h, vec[1]);
boost::hash_combine(h, vec[2]);
return h;
}
/// Equality comparison.
bool operator==(GfVec3f const &other) const {
return _data[0] == other[0] &&
_data[1] == other[1] &&
_data[2] == other[2];
}
bool operator!=(GfVec3f const &other) const {
return !(*this == other);
}
// TODO Add inequality for other vec types...
/// Equality comparison.
GF_API
bool operator==(class GfVec3d const &other) const;
/// Equality comparison.
GF_API
bool operator==(class GfVec3h const &other) const;
/// Equality comparison.
GF_API
bool operator==(class GfVec3i const &other) const;
/// Create a vec with negated elements.
GfVec3f operator-() const {
return GfVec3f(-_data[0], -_data[1], -_data[2]);
}
/// Addition.
GfVec3f &operator+=(GfVec3f const &other) {
_data[0] += other[0];
_data[1] += other[1];
_data[2] += other[2];
return *this;
}
friend GfVec3f operator+(GfVec3f const &l, GfVec3f const &r) {
return GfVec3f(l) += r;
}
/// Subtraction.
GfVec3f &operator-=(GfVec3f const &other) {
_data[0] -= other[0];
_data[1] -= other[1];
_data[2] -= other[2];
return *this;
}
friend GfVec3f operator-(GfVec3f const &l, GfVec3f const &r) {
return GfVec3f(l) -= r;
}
/// Multiplication by scalar.
GfVec3f &operator*=(double s) {
_data[0] *= s;
_data[1] *= s;
_data[2] *= s;
return *this;
}
GfVec3f operator*(double s) const {
return GfVec3f(*this) *= s;
}
friend GfVec3f operator*(double s, GfVec3f const &v) {
return v * s;
}
/// Division by scalar.
// TODO should divide by the scalar type.
GfVec3f &operator/=(double s) {
// TODO This should not multiply by 1/s, it should do the division.
// Doing the division is more numerically stable when s is close to
// zero.
return *this *= (1.0 / s);
}
GfVec3f operator/(double s) const {
return *this * (1.0 / s);
}
/// See GfDot().
float operator*(GfVec3f const &v) const {
return _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2];
}
/// Returns the projection of \p this onto \p v. That is:
/// \code
/// v * (*this * v)
/// \endcode
GfVec3f GetProjection(GfVec3f const &v) const {
return v * (*this * v);
}
/// Returns the orthogonal complement of \p this->GetProjection(b).
/// That is:
/// \code
/// *this - this->GetProjection(b)
/// \endcode
GfVec3f GetComplement(GfVec3f const &b) const {
return *this - this->GetProjection(b);
}
/// Squared length.
float GetLengthSq() const {
return *this * *this;
}
/// Length
float GetLength() const {
// TODO should use GfSqrt.
return sqrt(GetLengthSq());
}
/// Normalizes the vector in place to unit length, returning the
/// length before normalization. If the length of the vector is
/// smaller than \p eps, then the vector is set to vector/\c eps.
/// The original length of the vector is returned. See also GfNormalize().
///
/// \todo This was fixed for bug 67777. This is a gcc64 optimizer bug.
/// By tickling the code, it no longer tries to write into
/// an illegal memory address (in the code section of memory).
float Normalize(float eps = GF_MIN_VECTOR_LENGTH) {
// TODO this seems suspect... suggest dividing by length so long as
// length is not zero.
float length = GetLength();
*this /= (length > eps) ? length : eps;
return length;
}
GfVec3f GetNormalized(float eps = GF_MIN_VECTOR_LENGTH) const {
GfVec3f normalized(*this);
normalized.Normalize(eps);
return normalized;
}
/// Orthogonalize and optionally normalize a set of basis vectors. This
/// uses an iterative method that is very stable even when the vectors are
/// far from orthogonal (close to colinear). The number of iterations and
/// thus the computation time does increase as the vectors become close to
/// colinear, however. Returns a bool specifying whether the solution
/// converged after a number of iterations. If it did not converge, the
/// returned vectors will be as close as possible to orthogonal within the
/// iteration limit. Colinear vectors will be unaltered, and the method
/// will return false.
GF_API
static bool OrthogonalizeBasis(
GfVec3f *tx, GfVec3f *ty, GfVec3f *tz,
const bool normalize,
double eps = GF_MIN_ORTHO_TOLERANCE);
/// Sets \c v1 and \c v2 to unit vectors such that v1, v2 and *this are
/// mutually orthogonal. If the length L of *this is smaller than \c eps,
/// then v1 and v2 will have magnitude L/eps. As a result, the function
/// delivers a continuous result as *this shrinks in length.
GF_API
void BuildOrthonormalFrame(GfVec3f *v1, GfVec3f *v2,
float eps = GF_MIN_VECTOR_LENGTH) const;
private:
float _data[3];
};
/// Output a GfVec3f.
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream &, GfVec3f const &);
PXR_NAMESPACE_CLOSE_SCOPE
#include "pxr/base/gf/vec3d.h"
#include "pxr/base/gf/vec3h.h"
#include "pxr/base/gf/vec3i.h"
PXR_NAMESPACE_OPEN_SCOPE
inline
GfVec3f::GfVec3f(class GfVec3d const &other)
{
_data[0] = other[0];
_data[1] = other[1];
_data[2] = other[2];
}
inline
GfVec3f::GfVec3f(class GfVec3h const &other)
{
_data[0] = other[0];
_data[1] = other[1];
_data[2] = other[2];
}
inline
GfVec3f::GfVec3f(class GfVec3i const &other)
{
_data[0] = other[0];
_data[1] = other[1];
_data[2] = other[2];
}
/// Returns component-wise multiplication of vectors \p v1 and \p v2.
inline GfVec3f
GfCompMult(GfVec3f const &v1, GfVec3f const &v2) {
return GfVec3f(
v1[0] * v2[0],
v1[1] * v2[1],
v1[2] * v2[2]
);
}
/// Returns component-wise quotient of vectors \p v1 and \p v2.
inline GfVec3f
GfCompDiv(GfVec3f const &v1, GfVec3f const &v2) {
return GfVec3f(
v1[0] / v2[0],
v1[1] / v2[1],
v1[2] / v2[2]
);
}
/// Returns the dot (inner) product of two vectors.
inline float
GfDot(GfVec3f const &v1, GfVec3f const &v2) {
return v1 * v2;
}
/// Returns the geometric length of \c v.
inline float
GfGetLength(GfVec3f const &v)
{
return v.GetLength();
}
/// Normalizes \c *v in place to unit length, returning the length before
/// normalization. If the length of \c *v is smaller than \p eps then \c *v is
/// set to \c *v/eps. The original length of \c *v is returned.
inline float
GfNormalize(GfVec3f *v, float eps = GF_MIN_VECTOR_LENGTH)
{
return v->Normalize(eps);
}
/// Returns a normalized (unit-length) vector with the same direction as \p v.
/// If the length of this vector is smaller than \p eps, the vector divided by
/// \p eps is returned.
inline GfVec3f
GfGetNormalized(GfVec3f const &v, float eps = GF_MIN_VECTOR_LENGTH)
{
return v.GetNormalized(eps);
}
/// Returns the projection of \p a onto \p b. That is:
/// \code
/// b * (a * b)
/// \endcode
inline GfVec3f
GfGetProjection(GfVec3f const &a, GfVec3f const &b)
{
return a.GetProjection(b);
}
/// Returns the orthogonal complement of \p a.GetProjection(b). That is:
/// \code
/// a - a.GetProjection(b)
/// \endcode
inline GfVec3f
GfGetComplement(GfVec3f const &a, GfVec3f const &b)
{
return a.GetComplement(b);
}
/// Tests for equality within a given tolerance, returning \c true if the
/// length of the difference vector is less than or equal to \p tolerance.
inline bool
GfIsClose(GfVec3f const &v1, GfVec3f const &v2, double tolerance)
{
GfVec3f delta = v1 - v2;
return delta.GetLengthSq() <= tolerance * tolerance;
}
GF_API bool
GfOrthogonalizeBasis(GfVec3f *tx, GfVec3f *ty, GfVec3f *tz,
bool normalize, double eps = GF_MIN_ORTHO_TOLERANCE);
GF_API void
GfBuildOrthonormalFrame(GfVec3f const &v0,
GfVec3f* v1,
GfVec3f* v2,
float eps = GF_MIN_VECTOR_LENGTH);
/// Returns the cross product of \p v1 and \p v2.
inline GfVec3f
GfCross(GfVec3f const &v1, GfVec3f const &v2)
{
return GfVec3f(
v1[1] * v2[2] - v1[2] * v2[1],
v1[2] * v2[0] - v1[0] * v2[2],
v1[0] * v2[1] - v1[1] * v2[0]);
}
/// Returns the cross product of \p v1 and \p v2.
/// \see GfCross()
inline GfVec3f
operator^(GfVec3f const &v1, GfVec3f const &v2)
{
return GfCross(v1, v2);
}
/// Spherical linear interpolation in three dimensions.
GF_API GfVec3f
GfSlerp(double alpha, GfVec3f const &v0, GfVec3f const &v1);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_VEC3F_H
+471
View File
@@ -0,0 +1,471 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// vec.template.h file to make changes.
#ifndef PXR_BASE_GF_VEC3H_H
#define PXR_BASE_GF_VEC3H_H
/// \file gf/vec3h.h
/// \ingroup group_gf_LinearAlgebra
#include "pxr/pxr.h"
#include "pxr/base/tf/diagnostic.h"
#include "pxr/base/gf/api.h"
#include "pxr/base/gf/limits.h"
#include "pxr/base/gf/traits.h"
#include "pxr/base/gf/math.h"
#include "pxr/base/gf/half.h"
#include <boost/functional/hash.hpp>
#include <cstddef>
#include <cmath>
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
class GfVec3h;
template <>
struct GfIsGfVec<class GfVec3h> { static const bool value = true; };
/// \class GfVec3h
/// \ingroup group_gf_LinearAlgebra
///
/// Basic type for a vector of 3 GfHalf components.
///
/// Represents a vector of 3 components of type \c GfHalf.
/// It is intended to be fast and simple.
///
class GfVec3h
{
public:
/// Scalar element type and dimension.
typedef GfHalf ScalarType;
static const size_t dimension = 3;
/// Default constructor does no initialization.
GfVec3h() = default;
/// Initialize all elements to a single value.
constexpr explicit GfVec3h(GfHalf value)
: _data{ value, value, value }
{
}
/// Initialize all elements with explicit arguments.
constexpr GfVec3h(GfHalf s0, GfHalf s1, GfHalf s2)
: _data{ s0, s1, s2 }
{
}
/// Construct with pointer to values.
template <class Scl>
constexpr explicit GfVec3h(Scl const *p)
: _data{ p[0], p[1], p[2] }
{
}
/// Construct from GfVec3d.
explicit GfVec3h(class GfVec3d const &other);
/// Construct from GfVec3f.
explicit GfVec3h(class GfVec3f const &other);
/// Implicitly convert from GfVec3i.
GfVec3h(class GfVec3i const &other);
/// Create a unit vector along the X-axis.
static GfVec3h XAxis() {
GfVec3h result(0);
result[0] = 1;
return result;
}
/// Create a unit vector along the Y-axis.
static GfVec3h YAxis() {
GfVec3h result(0);
result[1] = 1;
return result;
}
/// Create a unit vector along the Z-axis.
static GfVec3h ZAxis() {
GfVec3h result(0);
result[2] = 1;
return result;
}
/// Create a unit vector along the i-th axis, zero-based. Return the zero
/// vector if \p i is greater than or equal to 3.
static GfVec3h Axis(size_t i) {
GfVec3h result(0);
if (i < 3)
result[i] = 1;
return result;
}
/// Set all elements with passed arguments.
GfVec3h &Set(GfHalf s0, GfHalf s1, GfHalf s2) {
_data[0] = s0;
_data[1] = s1;
_data[2] = s2;
return *this;
}
/// Set all elements with a pointer to data.
GfVec3h &Set(GfHalf const *a) {
return Set(a[0], a[1], a[2]);
}
/// Direct data access.
GfHalf const *data() const { return _data; }
GfHalf *data() { return _data; }
GfHalf const *GetArray() const { return data(); }
/// Indexing.
GfHalf const &operator[](size_t i) const { return _data[i]; }
GfHalf &operator[](size_t i) { return _data[i]; }
/// Hash.
friend inline size_t hash_value(GfVec3h const &vec) {
size_t h = 0;
boost::hash_combine(h, vec[0]);
boost::hash_combine(h, vec[1]);
boost::hash_combine(h, vec[2]);
return h;
}
/// Equality comparison.
bool operator==(GfVec3h const &other) const {
return _data[0] == other[0] &&
_data[1] == other[1] &&
_data[2] == other[2];
}
bool operator!=(GfVec3h const &other) const {
return !(*this == other);
}
// TODO Add inequality for other vec types...
/// Equality comparison.
GF_API
bool operator==(class GfVec3d const &other) const;
/// Equality comparison.
GF_API
bool operator==(class GfVec3f const &other) const;
/// Equality comparison.
GF_API
bool operator==(class GfVec3i const &other) const;
/// Create a vec with negated elements.
GfVec3h operator-() const {
return GfVec3h(-_data[0], -_data[1], -_data[2]);
}
/// Addition.
GfVec3h &operator+=(GfVec3h const &other) {
_data[0] += other[0];
_data[1] += other[1];
_data[2] += other[2];
return *this;
}
friend GfVec3h operator+(GfVec3h const &l, GfVec3h const &r) {
return GfVec3h(l) += r;
}
/// Subtraction.
GfVec3h &operator-=(GfVec3h const &other) {
_data[0] -= other[0];
_data[1] -= other[1];
_data[2] -= other[2];
return *this;
}
friend GfVec3h operator-(GfVec3h const &l, GfVec3h const &r) {
return GfVec3h(l) -= r;
}
/// Multiplication by scalar.
GfVec3h &operator*=(double s) {
_data[0] *= s;
_data[1] *= s;
_data[2] *= s;
return *this;
}
GfVec3h operator*(double s) const {
return GfVec3h(*this) *= s;
}
friend GfVec3h operator*(double s, GfVec3h const &v) {
return v * s;
}
/// Division by scalar.
// TODO should divide by the scalar type.
GfVec3h &operator/=(double s) {
// TODO This should not multiply by 1/s, it should do the division.
// Doing the division is more numerically stable when s is close to
// zero.
return *this *= (1.0 / s);
}
GfVec3h operator/(double s) const {
return *this * (1.0 / s);
}
/// See GfDot().
GfHalf operator*(GfVec3h const &v) const {
return _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2];
}
/// Returns the projection of \p this onto \p v. That is:
/// \code
/// v * (*this * v)
/// \endcode
GfVec3h GetProjection(GfVec3h const &v) const {
return v * (*this * v);
}
/// Returns the orthogonal complement of \p this->GetProjection(b).
/// That is:
/// \code
/// *this - this->GetProjection(b)
/// \endcode
GfVec3h GetComplement(GfVec3h const &b) const {
return *this - this->GetProjection(b);
}
/// Squared length.
GfHalf GetLengthSq() const {
return *this * *this;
}
/// Length
GfHalf GetLength() const {
// TODO should use GfSqrt.
return sqrt(GetLengthSq());
}
/// Normalizes the vector in place to unit length, returning the
/// length before normalization. If the length of the vector is
/// smaller than \p eps, then the vector is set to vector/\c eps.
/// The original length of the vector is returned. See also GfNormalize().
///
/// \todo This was fixed for bug 67777. This is a gcc64 optimizer bug.
/// By tickling the code, it no longer tries to write into
/// an illegal memory address (in the code section of memory).
GfHalf Normalize(GfHalf eps = 0.001) {
// TODO this seems suspect... suggest dividing by length so long as
// length is not zero.
GfHalf length = GetLength();
*this /= (length > eps) ? length : eps;
return length;
}
GfVec3h GetNormalized(GfHalf eps = 0.001) const {
GfVec3h normalized(*this);
normalized.Normalize(eps);
return normalized;
}
/// Orthogonalize and optionally normalize a set of basis vectors. This
/// uses an iterative method that is very stable even when the vectors are
/// far from orthogonal (close to colinear). The number of iterations and
/// thus the computation time does increase as the vectors become close to
/// colinear, however. Returns a bool specifying whether the solution
/// converged after a number of iterations. If it did not converge, the
/// returned vectors will be as close as possible to orthogonal within the
/// iteration limit. Colinear vectors will be unaltered, and the method
/// will return false.
GF_API
static bool OrthogonalizeBasis(
GfVec3h *tx, GfVec3h *ty, GfVec3h *tz,
const bool normalize,
double eps = GF_MIN_ORTHO_TOLERANCE);
/// Sets \c v1 and \c v2 to unit vectors such that v1, v2 and *this are
/// mutually orthogonal. If the length L of *this is smaller than \c eps,
/// then v1 and v2 will have magnitude L/eps. As a result, the function
/// delivers a continuous result as *this shrinks in length.
GF_API
void BuildOrthonormalFrame(GfVec3h *v1, GfVec3h *v2,
GfHalf eps = 0.001) const;
private:
GfHalf _data[3];
};
/// Output a GfVec3h.
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream &, GfVec3h const &);
PXR_NAMESPACE_CLOSE_SCOPE
#include "pxr/base/gf/vec3d.h"
#include "pxr/base/gf/vec3f.h"
#include "pxr/base/gf/vec3i.h"
PXR_NAMESPACE_OPEN_SCOPE
inline
GfVec3h::GfVec3h(class GfVec3d const &other)
{
_data[0] = other[0];
_data[1] = other[1];
_data[2] = other[2];
}
inline
GfVec3h::GfVec3h(class GfVec3f const &other)
{
_data[0] = other[0];
_data[1] = other[1];
_data[2] = other[2];
}
inline
GfVec3h::GfVec3h(class GfVec3i const &other)
{
_data[0] = other[0];
_data[1] = other[1];
_data[2] = other[2];
}
/// Returns component-wise multiplication of vectors \p v1 and \p v2.
inline GfVec3h
GfCompMult(GfVec3h const &v1, GfVec3h const &v2) {
return GfVec3h(
v1[0] * v2[0],
v1[1] * v2[1],
v1[2] * v2[2]
);
}
/// Returns component-wise quotient of vectors \p v1 and \p v2.
inline GfVec3h
GfCompDiv(GfVec3h const &v1, GfVec3h const &v2) {
return GfVec3h(
v1[0] / v2[0],
v1[1] / v2[1],
v1[2] / v2[2]
);
}
/// Returns the dot (inner) product of two vectors.
inline GfHalf
GfDot(GfVec3h const &v1, GfVec3h const &v2) {
return v1 * v2;
}
/// Returns the geometric length of \c v.
inline GfHalf
GfGetLength(GfVec3h const &v)
{
return v.GetLength();
}
/// Normalizes \c *v in place to unit length, returning the length before
/// normalization. If the length of \c *v is smaller than \p eps then \c *v is
/// set to \c *v/eps. The original length of \c *v is returned.
inline GfHalf
GfNormalize(GfVec3h *v, GfHalf eps = 0.001)
{
return v->Normalize(eps);
}
/// Returns a normalized (unit-length) vector with the same direction as \p v.
/// If the length of this vector is smaller than \p eps, the vector divided by
/// \p eps is returned.
inline GfVec3h
GfGetNormalized(GfVec3h const &v, GfHalf eps = 0.001)
{
return v.GetNormalized(eps);
}
/// Returns the projection of \p a onto \p b. That is:
/// \code
/// b * (a * b)
/// \endcode
inline GfVec3h
GfGetProjection(GfVec3h const &a, GfVec3h const &b)
{
return a.GetProjection(b);
}
/// Returns the orthogonal complement of \p a.GetProjection(b). That is:
/// \code
/// a - a.GetProjection(b)
/// \endcode
inline GfVec3h
GfGetComplement(GfVec3h const &a, GfVec3h const &b)
{
return a.GetComplement(b);
}
/// Tests for equality within a given tolerance, returning \c true if the
/// length of the difference vector is less than or equal to \p tolerance.
inline bool
GfIsClose(GfVec3h const &v1, GfVec3h const &v2, double tolerance)
{
GfVec3h delta = v1 - v2;
return delta.GetLengthSq() <= tolerance * tolerance;
}
GF_API bool
GfOrthogonalizeBasis(GfVec3h *tx, GfVec3h *ty, GfVec3h *tz,
bool normalize, double eps = GF_MIN_ORTHO_TOLERANCE);
GF_API void
GfBuildOrthonormalFrame(GfVec3h const &v0,
GfVec3h* v1,
GfVec3h* v2,
GfHalf eps = 0.001);
/// Returns the cross product of \p v1 and \p v2.
inline GfVec3h
GfCross(GfVec3h const &v1, GfVec3h const &v2)
{
return GfVec3h(
v1[1] * v2[2] - v1[2] * v2[1],
v1[2] * v2[0] - v1[0] * v2[2],
v1[0] * v2[1] - v1[1] * v2[0]);
}
/// Returns the cross product of \p v1 and \p v2.
/// \see GfCross()
inline GfVec3h
operator^(GfVec3h const &v1, GfVec3h const &v2)
{
return GfCross(v1, v2);
}
/// Spherical linear interpolation in three dimensions.
GF_API GfVec3h
GfSlerp(double alpha, GfVec3h const &v0, GfVec3h const &v1);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_VEC3H_H
+288
View File
@@ -0,0 +1,288 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// vec.template.h file to make changes.
#ifndef PXR_BASE_GF_VEC3I_H
#define PXR_BASE_GF_VEC3I_H
/// \file gf/vec3i.h
/// \ingroup group_gf_LinearAlgebra
#include "pxr/pxr.h"
#include "pxr/base/tf/diagnostic.h"
#include "pxr/base/gf/api.h"
#include "pxr/base/gf/limits.h"
#include "pxr/base/gf/traits.h"
#include <boost/functional/hash.hpp>
#include <cstddef>
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
class GfVec3i;
template <>
struct GfIsGfVec<class GfVec3i> { static const bool value = true; };
/// \class GfVec3i
/// \ingroup group_gf_LinearAlgebra
///
/// Basic type for a vector of 3 int components.
///
/// Represents a vector of 3 components of type \c int.
/// It is intended to be fast and simple.
///
class GfVec3i
{
public:
/// Scalar element type and dimension.
typedef int ScalarType;
static const size_t dimension = 3;
/// Default constructor does no initialization.
GfVec3i() = default;
/// Initialize all elements to a single value.
constexpr explicit GfVec3i(int value)
: _data{ value, value, value }
{
}
/// Initialize all elements with explicit arguments.
constexpr GfVec3i(int s0, int s1, int s2)
: _data{ s0, s1, s2 }
{
}
/// Construct with pointer to values.
template <class Scl>
constexpr explicit GfVec3i(Scl const *p)
: _data{ p[0], p[1], p[2] }
{
}
/// Create a unit vector along the X-axis.
static GfVec3i XAxis() {
GfVec3i result(0);
result[0] = 1;
return result;
}
/// Create a unit vector along the Y-axis.
static GfVec3i YAxis() {
GfVec3i result(0);
result[1] = 1;
return result;
}
/// Create a unit vector along the Z-axis.
static GfVec3i ZAxis() {
GfVec3i result(0);
result[2] = 1;
return result;
}
/// Create a unit vector along the i-th axis, zero-based. Return the zero
/// vector if \p i is greater than or equal to 3.
static GfVec3i Axis(size_t i) {
GfVec3i result(0);
if (i < 3)
result[i] = 1;
return result;
}
/// Set all elements with passed arguments.
GfVec3i &Set(int s0, int s1, int s2) {
_data[0] = s0;
_data[1] = s1;
_data[2] = s2;
return *this;
}
/// Set all elements with a pointer to data.
GfVec3i &Set(int const *a) {
return Set(a[0], a[1], a[2]);
}
/// Direct data access.
int const *data() const { return _data; }
int *data() { return _data; }
int const *GetArray() const { return data(); }
/// Indexing.
int const &operator[](size_t i) const { return _data[i]; }
int &operator[](size_t i) { return _data[i]; }
/// Hash.
friend inline size_t hash_value(GfVec3i const &vec) {
size_t h = 0;
boost::hash_combine(h, vec[0]);
boost::hash_combine(h, vec[1]);
boost::hash_combine(h, vec[2]);
return h;
}
/// Equality comparison.
bool operator==(GfVec3i const &other) const {
return _data[0] == other[0] &&
_data[1] == other[1] &&
_data[2] == other[2];
}
bool operator!=(GfVec3i const &other) const {
return !(*this == other);
}
// TODO Add inequality for other vec types...
/// Equality comparison.
GF_API
bool operator==(class GfVec3d const &other) const;
/// Equality comparison.
GF_API
bool operator==(class GfVec3f const &other) const;
/// Equality comparison.
GF_API
bool operator==(class GfVec3h const &other) const;
/// Create a vec with negated elements.
GfVec3i operator-() const {
return GfVec3i(-_data[0], -_data[1], -_data[2]);
}
/// Addition.
GfVec3i &operator+=(GfVec3i const &other) {
_data[0] += other[0];
_data[1] += other[1];
_data[2] += other[2];
return *this;
}
friend GfVec3i operator+(GfVec3i const &l, GfVec3i const &r) {
return GfVec3i(l) += r;
}
/// Subtraction.
GfVec3i &operator-=(GfVec3i const &other) {
_data[0] -= other[0];
_data[1] -= other[1];
_data[2] -= other[2];
return *this;
}
friend GfVec3i operator-(GfVec3i const &l, GfVec3i const &r) {
return GfVec3i(l) -= r;
}
/// Multiplication by scalar.
GfVec3i &operator*=(double s) {
_data[0] *= s;
_data[1] *= s;
_data[2] *= s;
return *this;
}
GfVec3i operator*(double s) const {
return GfVec3i(*this) *= s;
}
friend GfVec3i operator*(double s, GfVec3i const &v) {
return v * s;
}
/// Division by scalar.
GfVec3i &operator/=(int s) {
_data[0] /= s;
_data[1] /= s;
_data[2] /= s;
return *this;
}
GfVec3i operator/(int s) const {
return GfVec3i(*this) /= s;
}
/// See GfDot().
int operator*(GfVec3i const &v) const {
return _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2];
}
/// Returns the projection of \p this onto \p v. That is:
/// \code
/// v * (*this * v)
/// \endcode
GfVec3i GetProjection(GfVec3i const &v) const {
return v * (*this * v);
}
/// Returns the orthogonal complement of \p this->GetProjection(b).
/// That is:
/// \code
/// *this - this->GetProjection(b)
/// \endcode
GfVec3i GetComplement(GfVec3i const &b) const {
return *this - this->GetProjection(b);
}
/// Squared length.
int GetLengthSq() const {
return *this * *this;
}
private:
int _data[3];
};
/// Output a GfVec3i.
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream &, GfVec3i const &);
/// Returns component-wise multiplication of vectors \p v1 and \p v2.
inline GfVec3i
GfCompMult(GfVec3i const &v1, GfVec3i const &v2) {
return GfVec3i(
v1[0] * v2[0],
v1[1] * v2[1],
v1[2] * v2[2]
);
}
/// Returns component-wise quotient of vectors \p v1 and \p v2.
inline GfVec3i
GfCompDiv(GfVec3i const &v1, GfVec3i const &v2) {
return GfVec3i(
v1[0] / v2[0],
v1[1] / v2[1],
v1[2] / v2[2]
);
}
/// Returns the dot (inner) product of two vectors.
inline int
GfDot(GfVec3i const &v1, GfVec3i const &v2) {
return v1 * v2;
}
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_VEC3I_H
+431
View File
@@ -0,0 +1,431 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// vec.template.h file to make changes.
#ifndef PXR_BASE_GF_VEC4D_H
#define PXR_BASE_GF_VEC4D_H
/// \file gf/vec4d.h
/// \ingroup group_gf_LinearAlgebra
#include "pxr/pxr.h"
#include "pxr/base/tf/diagnostic.h"
#include "pxr/base/gf/api.h"
#include "pxr/base/gf/limits.h"
#include "pxr/base/gf/traits.h"
#include "pxr/base/gf/math.h"
#include <boost/functional/hash.hpp>
#include <cstddef>
#include <cmath>
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
class GfVec4d;
template <>
struct GfIsGfVec<class GfVec4d> { static const bool value = true; };
/// \class GfVec4d
/// \ingroup group_gf_LinearAlgebra
///
/// Basic type for a vector of 4 double components.
///
/// Represents a vector of 4 components of type \c double.
/// It is intended to be fast and simple.
///
class GfVec4d
{
public:
/// Scalar element type and dimension.
typedef double ScalarType;
static const size_t dimension = 4;
/// Default constructor does no initialization.
GfVec4d() = default;
/// Initialize all elements to a single value.
constexpr explicit GfVec4d(double value)
: _data{ value, value, value, value }
{
}
/// Initialize all elements with explicit arguments.
constexpr GfVec4d(double s0, double s1, double s2, double s3)
: _data{ s0, s1, s2, s3 }
{
}
/// Construct with pointer to values.
template <class Scl>
constexpr explicit GfVec4d(Scl const *p)
: _data{ p[0], p[1], p[2], p[3] }
{
}
/// Implicitly convert from GfVec4f.
GfVec4d(class GfVec4f const &other);
/// Implicitly convert from GfVec4h.
GfVec4d(class GfVec4h const &other);
/// Implicitly convert from GfVec4i.
GfVec4d(class GfVec4i const &other);
/// Create a unit vector along the X-axis.
static GfVec4d XAxis() {
GfVec4d result(0);
result[0] = 1;
return result;
}
/// Create a unit vector along the Y-axis.
static GfVec4d YAxis() {
GfVec4d result(0);
result[1] = 1;
return result;
}
/// Create a unit vector along the Z-axis.
static GfVec4d ZAxis() {
GfVec4d result(0);
result[2] = 1;
return result;
}
/// Create a unit vector along the W-axis.
static GfVec4d WAxis() {
GfVec4d result(0);
result[3] = 1;
return result;
}
/// Create a unit vector along the i-th axis, zero-based. Return the zero
/// vector if \p i is greater than or equal to 4.
static GfVec4d Axis(size_t i) {
GfVec4d result(0);
if (i < 4)
result[i] = 1;
return result;
}
/// Set all elements with passed arguments.
GfVec4d &Set(double s0, double s1, double s2, double s3) {
_data[0] = s0;
_data[1] = s1;
_data[2] = s2;
_data[3] = s3;
return *this;
}
/// Set all elements with a pointer to data.
GfVec4d &Set(double const *a) {
return Set(a[0], a[1], a[2], a[3]);
}
/// Direct data access.
double const *data() const { return _data; }
double *data() { return _data; }
double const *GetArray() const { return data(); }
/// Indexing.
double const &operator[](size_t i) const { return _data[i]; }
double &operator[](size_t i) { return _data[i]; }
/// Hash.
friend inline size_t hash_value(GfVec4d const &vec) {
size_t h = 0;
boost::hash_combine(h, vec[0]);
boost::hash_combine(h, vec[1]);
boost::hash_combine(h, vec[2]);
boost::hash_combine(h, vec[3]);
return h;
}
/// Equality comparison.
bool operator==(GfVec4d const &other) const {
return _data[0] == other[0] &&
_data[1] == other[1] &&
_data[2] == other[2] &&
_data[3] == other[3];
}
bool operator!=(GfVec4d const &other) const {
return !(*this == other);
}
// TODO Add inequality for other vec types...
/// Equality comparison.
GF_API
bool operator==(class GfVec4f const &other) const;
/// Equality comparison.
GF_API
bool operator==(class GfVec4h const &other) const;
/// Equality comparison.
GF_API
bool operator==(class GfVec4i const &other) const;
/// Create a vec with negated elements.
GfVec4d operator-() const {
return GfVec4d(-_data[0], -_data[1], -_data[2], -_data[3]);
}
/// Addition.
GfVec4d &operator+=(GfVec4d const &other) {
_data[0] += other[0];
_data[1] += other[1];
_data[2] += other[2];
_data[3] += other[3];
return *this;
}
friend GfVec4d operator+(GfVec4d const &l, GfVec4d const &r) {
return GfVec4d(l) += r;
}
/// Subtraction.
GfVec4d &operator-=(GfVec4d const &other) {
_data[0] -= other[0];
_data[1] -= other[1];
_data[2] -= other[2];
_data[3] -= other[3];
return *this;
}
friend GfVec4d operator-(GfVec4d const &l, GfVec4d const &r) {
return GfVec4d(l) -= r;
}
/// Multiplication by scalar.
GfVec4d &operator*=(double s) {
_data[0] *= s;
_data[1] *= s;
_data[2] *= s;
_data[3] *= s;
return *this;
}
GfVec4d operator*(double s) const {
return GfVec4d(*this) *= s;
}
friend GfVec4d operator*(double s, GfVec4d const &v) {
return v * s;
}
/// Division by scalar.
// TODO should divide by the scalar type.
GfVec4d &operator/=(double s) {
// TODO This should not multiply by 1/s, it should do the division.
// Doing the division is more numerically stable when s is close to
// zero.
return *this *= (1.0 / s);
}
GfVec4d operator/(double s) const {
return *this * (1.0 / s);
}
/// See GfDot().
double operator*(GfVec4d const &v) const {
return _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2] + _data[3] * v[3];
}
/// Returns the projection of \p this onto \p v. That is:
/// \code
/// v * (*this * v)
/// \endcode
GfVec4d GetProjection(GfVec4d const &v) const {
return v * (*this * v);
}
/// Returns the orthogonal complement of \p this->GetProjection(b).
/// That is:
/// \code
/// *this - this->GetProjection(b)
/// \endcode
GfVec4d GetComplement(GfVec4d const &b) const {
return *this - this->GetProjection(b);
}
/// Squared length.
double GetLengthSq() const {
return *this * *this;
}
/// Length
double GetLength() const {
// TODO should use GfSqrt.
return sqrt(GetLengthSq());
}
/// Normalizes the vector in place to unit length, returning the
/// length before normalization. If the length of the vector is
/// smaller than \p eps, then the vector is set to vector/\c eps.
/// The original length of the vector is returned. See also GfNormalize().
///
/// \todo This was fixed for bug 67777. This is a gcc64 optimizer bug.
/// By tickling the code, it no longer tries to write into
/// an illegal memory address (in the code section of memory).
double Normalize(double eps = GF_MIN_VECTOR_LENGTH) {
// TODO this seems suspect... suggest dividing by length so long as
// length is not zero.
double length = GetLength();
*this /= (length > eps) ? length : eps;
return length;
}
GfVec4d GetNormalized(double eps = GF_MIN_VECTOR_LENGTH) const {
GfVec4d normalized(*this);
normalized.Normalize(eps);
return normalized;
}
private:
double _data[4];
};
/// Output a GfVec4d.
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream &, GfVec4d const &);
PXR_NAMESPACE_CLOSE_SCOPE
#include "pxr/base/gf/vec4f.h"
#include "pxr/base/gf/vec4h.h"
#include "pxr/base/gf/vec4i.h"
PXR_NAMESPACE_OPEN_SCOPE
inline
GfVec4d::GfVec4d(class GfVec4f const &other)
{
_data[0] = other[0];
_data[1] = other[1];
_data[2] = other[2];
_data[3] = other[3];
}
inline
GfVec4d::GfVec4d(class GfVec4h const &other)
{
_data[0] = other[0];
_data[1] = other[1];
_data[2] = other[2];
_data[3] = other[3];
}
inline
GfVec4d::GfVec4d(class GfVec4i const &other)
{
_data[0] = other[0];
_data[1] = other[1];
_data[2] = other[2];
_data[3] = other[3];
}
/// Returns component-wise multiplication of vectors \p v1 and \p v2.
inline GfVec4d
GfCompMult(GfVec4d const &v1, GfVec4d const &v2) {
return GfVec4d(
v1[0] * v2[0],
v1[1] * v2[1],
v1[2] * v2[2],
v1[3] * v2[3]
);
}
/// Returns component-wise quotient of vectors \p v1 and \p v2.
inline GfVec4d
GfCompDiv(GfVec4d const &v1, GfVec4d const &v2) {
return GfVec4d(
v1[0] / v2[0],
v1[1] / v2[1],
v1[2] / v2[2],
v1[3] / v2[3]
);
}
/// Returns the dot (inner) product of two vectors.
inline double
GfDot(GfVec4d const &v1, GfVec4d const &v2) {
return v1 * v2;
}
/// Returns the geometric length of \c v.
inline double
GfGetLength(GfVec4d const &v)
{
return v.GetLength();
}
/// Normalizes \c *v in place to unit length, returning the length before
/// normalization. If the length of \c *v is smaller than \p eps then \c *v is
/// set to \c *v/eps. The original length of \c *v is returned.
inline double
GfNormalize(GfVec4d *v, double eps = GF_MIN_VECTOR_LENGTH)
{
return v->Normalize(eps);
}
/// Returns a normalized (unit-length) vector with the same direction as \p v.
/// If the length of this vector is smaller than \p eps, the vector divided by
/// \p eps is returned.
inline GfVec4d
GfGetNormalized(GfVec4d const &v, double eps = GF_MIN_VECTOR_LENGTH)
{
return v.GetNormalized(eps);
}
/// Returns the projection of \p a onto \p b. That is:
/// \code
/// b * (a * b)
/// \endcode
inline GfVec4d
GfGetProjection(GfVec4d const &a, GfVec4d const &b)
{
return a.GetProjection(b);
}
/// Returns the orthogonal complement of \p a.GetProjection(b). That is:
/// \code
/// a - a.GetProjection(b)
/// \endcode
inline GfVec4d
GfGetComplement(GfVec4d const &a, GfVec4d const &b)
{
return a.GetComplement(b);
}
/// Tests for equality within a given tolerance, returning \c true if the
/// length of the difference vector is less than or equal to \p tolerance.
inline bool
GfIsClose(GfVec4d const &v1, GfVec4d const &v2, double tolerance)
{
GfVec4d delta = v1 - v2;
return delta.GetLengthSq() <= tolerance * tolerance;
}
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_VEC4D_H
+431
View File
@@ -0,0 +1,431 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// vec.template.h file to make changes.
#ifndef PXR_BASE_GF_VEC4F_H
#define PXR_BASE_GF_VEC4F_H
/// \file gf/vec4f.h
/// \ingroup group_gf_LinearAlgebra
#include "pxr/pxr.h"
#include "pxr/base/tf/diagnostic.h"
#include "pxr/base/gf/api.h"
#include "pxr/base/gf/limits.h"
#include "pxr/base/gf/traits.h"
#include "pxr/base/gf/math.h"
#include <boost/functional/hash.hpp>
#include <cstddef>
#include <cmath>
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
class GfVec4f;
template <>
struct GfIsGfVec<class GfVec4f> { static const bool value = true; };
/// \class GfVec4f
/// \ingroup group_gf_LinearAlgebra
///
/// Basic type for a vector of 4 float components.
///
/// Represents a vector of 4 components of type \c float.
/// It is intended to be fast and simple.
///
class GfVec4f
{
public:
/// Scalar element type and dimension.
typedef float ScalarType;
static const size_t dimension = 4;
/// Default constructor does no initialization.
GfVec4f() = default;
/// Initialize all elements to a single value.
constexpr explicit GfVec4f(float value)
: _data{ value, value, value, value }
{
}
/// Initialize all elements with explicit arguments.
constexpr GfVec4f(float s0, float s1, float s2, float s3)
: _data{ s0, s1, s2, s3 }
{
}
/// Construct with pointer to values.
template <class Scl>
constexpr explicit GfVec4f(Scl const *p)
: _data{ p[0], p[1], p[2], p[3] }
{
}
/// Construct from GfVec4d.
explicit GfVec4f(class GfVec4d const &other);
/// Implicitly convert from GfVec4h.
GfVec4f(class GfVec4h const &other);
/// Implicitly convert from GfVec4i.
GfVec4f(class GfVec4i const &other);
/// Create a unit vector along the X-axis.
static GfVec4f XAxis() {
GfVec4f result(0);
result[0] = 1;
return result;
}
/// Create a unit vector along the Y-axis.
static GfVec4f YAxis() {
GfVec4f result(0);
result[1] = 1;
return result;
}
/// Create a unit vector along the Z-axis.
static GfVec4f ZAxis() {
GfVec4f result(0);
result[2] = 1;
return result;
}
/// Create a unit vector along the W-axis.
static GfVec4f WAxis() {
GfVec4f result(0);
result[3] = 1;
return result;
}
/// Create a unit vector along the i-th axis, zero-based. Return the zero
/// vector if \p i is greater than or equal to 4.
static GfVec4f Axis(size_t i) {
GfVec4f result(0);
if (i < 4)
result[i] = 1;
return result;
}
/// Set all elements with passed arguments.
GfVec4f &Set(float s0, float s1, float s2, float s3) {
_data[0] = s0;
_data[1] = s1;
_data[2] = s2;
_data[3] = s3;
return *this;
}
/// Set all elements with a pointer to data.
GfVec4f &Set(float const *a) {
return Set(a[0], a[1], a[2], a[3]);
}
/// Direct data access.
float const *data() const { return _data; }
float *data() { return _data; }
float const *GetArray() const { return data(); }
/// Indexing.
float const &operator[](size_t i) const { return _data[i]; }
float &operator[](size_t i) { return _data[i]; }
/// Hash.
friend inline size_t hash_value(GfVec4f const &vec) {
size_t h = 0;
boost::hash_combine(h, vec[0]);
boost::hash_combine(h, vec[1]);
boost::hash_combine(h, vec[2]);
boost::hash_combine(h, vec[3]);
return h;
}
/// Equality comparison.
bool operator==(GfVec4f const &other) const {
return _data[0] == other[0] &&
_data[1] == other[1] &&
_data[2] == other[2] &&
_data[3] == other[3];
}
bool operator!=(GfVec4f const &other) const {
return !(*this == other);
}
// TODO Add inequality for other vec types...
/// Equality comparison.
GF_API
bool operator==(class GfVec4d const &other) const;
/// Equality comparison.
GF_API
bool operator==(class GfVec4h const &other) const;
/// Equality comparison.
GF_API
bool operator==(class GfVec4i const &other) const;
/// Create a vec with negated elements.
GfVec4f operator-() const {
return GfVec4f(-_data[0], -_data[1], -_data[2], -_data[3]);
}
/// Addition.
GfVec4f &operator+=(GfVec4f const &other) {
_data[0] += other[0];
_data[1] += other[1];
_data[2] += other[2];
_data[3] += other[3];
return *this;
}
friend GfVec4f operator+(GfVec4f const &l, GfVec4f const &r) {
return GfVec4f(l) += r;
}
/// Subtraction.
GfVec4f &operator-=(GfVec4f const &other) {
_data[0] -= other[0];
_data[1] -= other[1];
_data[2] -= other[2];
_data[3] -= other[3];
return *this;
}
friend GfVec4f operator-(GfVec4f const &l, GfVec4f const &r) {
return GfVec4f(l) -= r;
}
/// Multiplication by scalar.
GfVec4f &operator*=(double s) {
_data[0] *= s;
_data[1] *= s;
_data[2] *= s;
_data[3] *= s;
return *this;
}
GfVec4f operator*(double s) const {
return GfVec4f(*this) *= s;
}
friend GfVec4f operator*(double s, GfVec4f const &v) {
return v * s;
}
/// Division by scalar.
// TODO should divide by the scalar type.
GfVec4f &operator/=(double s) {
// TODO This should not multiply by 1/s, it should do the division.
// Doing the division is more numerically stable when s is close to
// zero.
return *this *= (1.0 / s);
}
GfVec4f operator/(double s) const {
return *this * (1.0 / s);
}
/// See GfDot().
float operator*(GfVec4f const &v) const {
return _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2] + _data[3] * v[3];
}
/// Returns the projection of \p this onto \p v. That is:
/// \code
/// v * (*this * v)
/// \endcode
GfVec4f GetProjection(GfVec4f const &v) const {
return v * (*this * v);
}
/// Returns the orthogonal complement of \p this->GetProjection(b).
/// That is:
/// \code
/// *this - this->GetProjection(b)
/// \endcode
GfVec4f GetComplement(GfVec4f const &b) const {
return *this - this->GetProjection(b);
}
/// Squared length.
float GetLengthSq() const {
return *this * *this;
}
/// Length
float GetLength() const {
// TODO should use GfSqrt.
return sqrt(GetLengthSq());
}
/// Normalizes the vector in place to unit length, returning the
/// length before normalization. If the length of the vector is
/// smaller than \p eps, then the vector is set to vector/\c eps.
/// The original length of the vector is returned. See also GfNormalize().
///
/// \todo This was fixed for bug 67777. This is a gcc64 optimizer bug.
/// By tickling the code, it no longer tries to write into
/// an illegal memory address (in the code section of memory).
float Normalize(float eps = GF_MIN_VECTOR_LENGTH) {
// TODO this seems suspect... suggest dividing by length so long as
// length is not zero.
float length = GetLength();
*this /= (length > eps) ? length : eps;
return length;
}
GfVec4f GetNormalized(float eps = GF_MIN_VECTOR_LENGTH) const {
GfVec4f normalized(*this);
normalized.Normalize(eps);
return normalized;
}
private:
float _data[4];
};
/// Output a GfVec4f.
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream &, GfVec4f const &);
PXR_NAMESPACE_CLOSE_SCOPE
#include "pxr/base/gf/vec4d.h"
#include "pxr/base/gf/vec4h.h"
#include "pxr/base/gf/vec4i.h"
PXR_NAMESPACE_OPEN_SCOPE
inline
GfVec4f::GfVec4f(class GfVec4d const &other)
{
_data[0] = other[0];
_data[1] = other[1];
_data[2] = other[2];
_data[3] = other[3];
}
inline
GfVec4f::GfVec4f(class GfVec4h const &other)
{
_data[0] = other[0];
_data[1] = other[1];
_data[2] = other[2];
_data[3] = other[3];
}
inline
GfVec4f::GfVec4f(class GfVec4i const &other)
{
_data[0] = other[0];
_data[1] = other[1];
_data[2] = other[2];
_data[3] = other[3];
}
/// Returns component-wise multiplication of vectors \p v1 and \p v2.
inline GfVec4f
GfCompMult(GfVec4f const &v1, GfVec4f const &v2) {
return GfVec4f(
v1[0] * v2[0],
v1[1] * v2[1],
v1[2] * v2[2],
v1[3] * v2[3]
);
}
/// Returns component-wise quotient of vectors \p v1 and \p v2.
inline GfVec4f
GfCompDiv(GfVec4f const &v1, GfVec4f const &v2) {
return GfVec4f(
v1[0] / v2[0],
v1[1] / v2[1],
v1[2] / v2[2],
v1[3] / v2[3]
);
}
/// Returns the dot (inner) product of two vectors.
inline float
GfDot(GfVec4f const &v1, GfVec4f const &v2) {
return v1 * v2;
}
/// Returns the geometric length of \c v.
inline float
GfGetLength(GfVec4f const &v)
{
return v.GetLength();
}
/// Normalizes \c *v in place to unit length, returning the length before
/// normalization. If the length of \c *v is smaller than \p eps then \c *v is
/// set to \c *v/eps. The original length of \c *v is returned.
inline float
GfNormalize(GfVec4f *v, float eps = GF_MIN_VECTOR_LENGTH)
{
return v->Normalize(eps);
}
/// Returns a normalized (unit-length) vector with the same direction as \p v.
/// If the length of this vector is smaller than \p eps, the vector divided by
/// \p eps is returned.
inline GfVec4f
GfGetNormalized(GfVec4f const &v, float eps = GF_MIN_VECTOR_LENGTH)
{
return v.GetNormalized(eps);
}
/// Returns the projection of \p a onto \p b. That is:
/// \code
/// b * (a * b)
/// \endcode
inline GfVec4f
GfGetProjection(GfVec4f const &a, GfVec4f const &b)
{
return a.GetProjection(b);
}
/// Returns the orthogonal complement of \p a.GetProjection(b). That is:
/// \code
/// a - a.GetProjection(b)
/// \endcode
inline GfVec4f
GfGetComplement(GfVec4f const &a, GfVec4f const &b)
{
return a.GetComplement(b);
}
/// Tests for equality within a given tolerance, returning \c true if the
/// length of the difference vector is less than or equal to \p tolerance.
inline bool
GfIsClose(GfVec4f const &v1, GfVec4f const &v2, double tolerance)
{
GfVec4f delta = v1 - v2;
return delta.GetLengthSq() <= tolerance * tolerance;
}
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_VEC4F_H
+432
View File
@@ -0,0 +1,432 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// vec.template.h file to make changes.
#ifndef PXR_BASE_GF_VEC4H_H
#define PXR_BASE_GF_VEC4H_H
/// \file gf/vec4h.h
/// \ingroup group_gf_LinearAlgebra
#include "pxr/pxr.h"
#include "pxr/base/tf/diagnostic.h"
#include "pxr/base/gf/api.h"
#include "pxr/base/gf/limits.h"
#include "pxr/base/gf/traits.h"
#include "pxr/base/gf/math.h"
#include "pxr/base/gf/half.h"
#include <boost/functional/hash.hpp>
#include <cstddef>
#include <cmath>
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
class GfVec4h;
template <>
struct GfIsGfVec<class GfVec4h> { static const bool value = true; };
/// \class GfVec4h
/// \ingroup group_gf_LinearAlgebra
///
/// Basic type for a vector of 4 GfHalf components.
///
/// Represents a vector of 4 components of type \c GfHalf.
/// It is intended to be fast and simple.
///
class GfVec4h
{
public:
/// Scalar element type and dimension.
typedef GfHalf ScalarType;
static const size_t dimension = 4;
/// Default constructor does no initialization.
GfVec4h() = default;
/// Initialize all elements to a single value.
constexpr explicit GfVec4h(GfHalf value)
: _data{ value, value, value, value }
{
}
/// Initialize all elements with explicit arguments.
constexpr GfVec4h(GfHalf s0, GfHalf s1, GfHalf s2, GfHalf s3)
: _data{ s0, s1, s2, s3 }
{
}
/// Construct with pointer to values.
template <class Scl>
constexpr explicit GfVec4h(Scl const *p)
: _data{ p[0], p[1], p[2], p[3] }
{
}
/// Construct from GfVec4d.
explicit GfVec4h(class GfVec4d const &other);
/// Construct from GfVec4f.
explicit GfVec4h(class GfVec4f const &other);
/// Implicitly convert from GfVec4i.
GfVec4h(class GfVec4i const &other);
/// Create a unit vector along the X-axis.
static GfVec4h XAxis() {
GfVec4h result(0);
result[0] = 1;
return result;
}
/// Create a unit vector along the Y-axis.
static GfVec4h YAxis() {
GfVec4h result(0);
result[1] = 1;
return result;
}
/// Create a unit vector along the Z-axis.
static GfVec4h ZAxis() {
GfVec4h result(0);
result[2] = 1;
return result;
}
/// Create a unit vector along the W-axis.
static GfVec4h WAxis() {
GfVec4h result(0);
result[3] = 1;
return result;
}
/// Create a unit vector along the i-th axis, zero-based. Return the zero
/// vector if \p i is greater than or equal to 4.
static GfVec4h Axis(size_t i) {
GfVec4h result(0);
if (i < 4)
result[i] = 1;
return result;
}
/// Set all elements with passed arguments.
GfVec4h &Set(GfHalf s0, GfHalf s1, GfHalf s2, GfHalf s3) {
_data[0] = s0;
_data[1] = s1;
_data[2] = s2;
_data[3] = s3;
return *this;
}
/// Set all elements with a pointer to data.
GfVec4h &Set(GfHalf const *a) {
return Set(a[0], a[1], a[2], a[3]);
}
/// Direct data access.
GfHalf const *data() const { return _data; }
GfHalf *data() { return _data; }
GfHalf const *GetArray() const { return data(); }
/// Indexing.
GfHalf const &operator[](size_t i) const { return _data[i]; }
GfHalf &operator[](size_t i) { return _data[i]; }
/// Hash.
friend inline size_t hash_value(GfVec4h const &vec) {
size_t h = 0;
boost::hash_combine(h, vec[0]);
boost::hash_combine(h, vec[1]);
boost::hash_combine(h, vec[2]);
boost::hash_combine(h, vec[3]);
return h;
}
/// Equality comparison.
bool operator==(GfVec4h const &other) const {
return _data[0] == other[0] &&
_data[1] == other[1] &&
_data[2] == other[2] &&
_data[3] == other[3];
}
bool operator!=(GfVec4h const &other) const {
return !(*this == other);
}
// TODO Add inequality for other vec types...
/// Equality comparison.
GF_API
bool operator==(class GfVec4d const &other) const;
/// Equality comparison.
GF_API
bool operator==(class GfVec4f const &other) const;
/// Equality comparison.
GF_API
bool operator==(class GfVec4i const &other) const;
/// Create a vec with negated elements.
GfVec4h operator-() const {
return GfVec4h(-_data[0], -_data[1], -_data[2], -_data[3]);
}
/// Addition.
GfVec4h &operator+=(GfVec4h const &other) {
_data[0] += other[0];
_data[1] += other[1];
_data[2] += other[2];
_data[3] += other[3];
return *this;
}
friend GfVec4h operator+(GfVec4h const &l, GfVec4h const &r) {
return GfVec4h(l) += r;
}
/// Subtraction.
GfVec4h &operator-=(GfVec4h const &other) {
_data[0] -= other[0];
_data[1] -= other[1];
_data[2] -= other[2];
_data[3] -= other[3];
return *this;
}
friend GfVec4h operator-(GfVec4h const &l, GfVec4h const &r) {
return GfVec4h(l) -= r;
}
/// Multiplication by scalar.
GfVec4h &operator*=(double s) {
_data[0] *= s;
_data[1] *= s;
_data[2] *= s;
_data[3] *= s;
return *this;
}
GfVec4h operator*(double s) const {
return GfVec4h(*this) *= s;
}
friend GfVec4h operator*(double s, GfVec4h const &v) {
return v * s;
}
/// Division by scalar.
// TODO should divide by the scalar type.
GfVec4h &operator/=(double s) {
// TODO This should not multiply by 1/s, it should do the division.
// Doing the division is more numerically stable when s is close to
// zero.
return *this *= (1.0 / s);
}
GfVec4h operator/(double s) const {
return *this * (1.0 / s);
}
/// See GfDot().
GfHalf operator*(GfVec4h const &v) const {
return _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2] + _data[3] * v[3];
}
/// Returns the projection of \p this onto \p v. That is:
/// \code
/// v * (*this * v)
/// \endcode
GfVec4h GetProjection(GfVec4h const &v) const {
return v * (*this * v);
}
/// Returns the orthogonal complement of \p this->GetProjection(b).
/// That is:
/// \code
/// *this - this->GetProjection(b)
/// \endcode
GfVec4h GetComplement(GfVec4h const &b) const {
return *this - this->GetProjection(b);
}
/// Squared length.
GfHalf GetLengthSq() const {
return *this * *this;
}
/// Length
GfHalf GetLength() const {
// TODO should use GfSqrt.
return sqrt(GetLengthSq());
}
/// Normalizes the vector in place to unit length, returning the
/// length before normalization. If the length of the vector is
/// smaller than \p eps, then the vector is set to vector/\c eps.
/// The original length of the vector is returned. See also GfNormalize().
///
/// \todo This was fixed for bug 67777. This is a gcc64 optimizer bug.
/// By tickling the code, it no longer tries to write into
/// an illegal memory address (in the code section of memory).
GfHalf Normalize(GfHalf eps = 0.001) {
// TODO this seems suspect... suggest dividing by length so long as
// length is not zero.
GfHalf length = GetLength();
*this /= (length > eps) ? length : eps;
return length;
}
GfVec4h GetNormalized(GfHalf eps = 0.001) const {
GfVec4h normalized(*this);
normalized.Normalize(eps);
return normalized;
}
private:
GfHalf _data[4];
};
/// Output a GfVec4h.
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream &, GfVec4h const &);
PXR_NAMESPACE_CLOSE_SCOPE
#include "pxr/base/gf/vec4d.h"
#include "pxr/base/gf/vec4f.h"
#include "pxr/base/gf/vec4i.h"
PXR_NAMESPACE_OPEN_SCOPE
inline
GfVec4h::GfVec4h(class GfVec4d const &other)
{
_data[0] = other[0];
_data[1] = other[1];
_data[2] = other[2];
_data[3] = other[3];
}
inline
GfVec4h::GfVec4h(class GfVec4f const &other)
{
_data[0] = other[0];
_data[1] = other[1];
_data[2] = other[2];
_data[3] = other[3];
}
inline
GfVec4h::GfVec4h(class GfVec4i const &other)
{
_data[0] = other[0];
_data[1] = other[1];
_data[2] = other[2];
_data[3] = other[3];
}
/// Returns component-wise multiplication of vectors \p v1 and \p v2.
inline GfVec4h
GfCompMult(GfVec4h const &v1, GfVec4h const &v2) {
return GfVec4h(
v1[0] * v2[0],
v1[1] * v2[1],
v1[2] * v2[2],
v1[3] * v2[3]
);
}
/// Returns component-wise quotient of vectors \p v1 and \p v2.
inline GfVec4h
GfCompDiv(GfVec4h const &v1, GfVec4h const &v2) {
return GfVec4h(
v1[0] / v2[0],
v1[1] / v2[1],
v1[2] / v2[2],
v1[3] / v2[3]
);
}
/// Returns the dot (inner) product of two vectors.
inline GfHalf
GfDot(GfVec4h const &v1, GfVec4h const &v2) {
return v1 * v2;
}
/// Returns the geometric length of \c v.
inline GfHalf
GfGetLength(GfVec4h const &v)
{
return v.GetLength();
}
/// Normalizes \c *v in place to unit length, returning the length before
/// normalization. If the length of \c *v is smaller than \p eps then \c *v is
/// set to \c *v/eps. The original length of \c *v is returned.
inline GfHalf
GfNormalize(GfVec4h *v, GfHalf eps = 0.001)
{
return v->Normalize(eps);
}
/// Returns a normalized (unit-length) vector with the same direction as \p v.
/// If the length of this vector is smaller than \p eps, the vector divided by
/// \p eps is returned.
inline GfVec4h
GfGetNormalized(GfVec4h const &v, GfHalf eps = 0.001)
{
return v.GetNormalized(eps);
}
/// Returns the projection of \p a onto \p b. That is:
/// \code
/// b * (a * b)
/// \endcode
inline GfVec4h
GfGetProjection(GfVec4h const &a, GfVec4h const &b)
{
return a.GetProjection(b);
}
/// Returns the orthogonal complement of \p a.GetProjection(b). That is:
/// \code
/// a - a.GetProjection(b)
/// \endcode
inline GfVec4h
GfGetComplement(GfVec4h const &a, GfVec4h const &b)
{
return a.GetComplement(b);
}
/// Tests for equality within a given tolerance, returning \c true if the
/// length of the difference vector is less than or equal to \p tolerance.
inline bool
GfIsClose(GfVec4h const &v1, GfVec4h const &v2, double tolerance)
{
GfVec4h delta = v1 - v2;
return delta.GetLengthSq() <= tolerance * tolerance;
}
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_VEC4H_H
+303
View File
@@ -0,0 +1,303 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// vec.template.h file to make changes.
#ifndef PXR_BASE_GF_VEC4I_H
#define PXR_BASE_GF_VEC4I_H
/// \file gf/vec4i.h
/// \ingroup group_gf_LinearAlgebra
#include "pxr/pxr.h"
#include "pxr/base/tf/diagnostic.h"
#include "pxr/base/gf/api.h"
#include "pxr/base/gf/limits.h"
#include "pxr/base/gf/traits.h"
#include <boost/functional/hash.hpp>
#include <cstddef>
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
class GfVec4i;
template <>
struct GfIsGfVec<class GfVec4i> { static const bool value = true; };
/// \class GfVec4i
/// \ingroup group_gf_LinearAlgebra
///
/// Basic type for a vector of 4 int components.
///
/// Represents a vector of 4 components of type \c int.
/// It is intended to be fast and simple.
///
class GfVec4i
{
public:
/// Scalar element type and dimension.
typedef int ScalarType;
static const size_t dimension = 4;
/// Default constructor does no initialization.
GfVec4i() = default;
/// Initialize all elements to a single value.
constexpr explicit GfVec4i(int value)
: _data{ value, value, value, value }
{
}
/// Initialize all elements with explicit arguments.
constexpr GfVec4i(int s0, int s1, int s2, int s3)
: _data{ s0, s1, s2, s3 }
{
}
/// Construct with pointer to values.
template <class Scl>
constexpr explicit GfVec4i(Scl const *p)
: _data{ p[0], p[1], p[2], p[3] }
{
}
/// Create a unit vector along the X-axis.
static GfVec4i XAxis() {
GfVec4i result(0);
result[0] = 1;
return result;
}
/// Create a unit vector along the Y-axis.
static GfVec4i YAxis() {
GfVec4i result(0);
result[1] = 1;
return result;
}
/// Create a unit vector along the Z-axis.
static GfVec4i ZAxis() {
GfVec4i result(0);
result[2] = 1;
return result;
}
/// Create a unit vector along the W-axis.
static GfVec4i WAxis() {
GfVec4i result(0);
result[3] = 1;
return result;
}
/// Create a unit vector along the i-th axis, zero-based. Return the zero
/// vector if \p i is greater than or equal to 4.
static GfVec4i Axis(size_t i) {
GfVec4i result(0);
if (i < 4)
result[i] = 1;
return result;
}
/// Set all elements with passed arguments.
GfVec4i &Set(int s0, int s1, int s2, int s3) {
_data[0] = s0;
_data[1] = s1;
_data[2] = s2;
_data[3] = s3;
return *this;
}
/// Set all elements with a pointer to data.
GfVec4i &Set(int const *a) {
return Set(a[0], a[1], a[2], a[3]);
}
/// Direct data access.
int const *data() const { return _data; }
int *data() { return _data; }
int const *GetArray() const { return data(); }
/// Indexing.
int const &operator[](size_t i) const { return _data[i]; }
int &operator[](size_t i) { return _data[i]; }
/// Hash.
friend inline size_t hash_value(GfVec4i const &vec) {
size_t h = 0;
boost::hash_combine(h, vec[0]);
boost::hash_combine(h, vec[1]);
boost::hash_combine(h, vec[2]);
boost::hash_combine(h, vec[3]);
return h;
}
/// Equality comparison.
bool operator==(GfVec4i const &other) const {
return _data[0] == other[0] &&
_data[1] == other[1] &&
_data[2] == other[2] &&
_data[3] == other[3];
}
bool operator!=(GfVec4i const &other) const {
return !(*this == other);
}
// TODO Add inequality for other vec types...
/// Equality comparison.
GF_API
bool operator==(class GfVec4d const &other) const;
/// Equality comparison.
GF_API
bool operator==(class GfVec4f const &other) const;
/// Equality comparison.
GF_API
bool operator==(class GfVec4h const &other) const;
/// Create a vec with negated elements.
GfVec4i operator-() const {
return GfVec4i(-_data[0], -_data[1], -_data[2], -_data[3]);
}
/// Addition.
GfVec4i &operator+=(GfVec4i const &other) {
_data[0] += other[0];
_data[1] += other[1];
_data[2] += other[2];
_data[3] += other[3];
return *this;
}
friend GfVec4i operator+(GfVec4i const &l, GfVec4i const &r) {
return GfVec4i(l) += r;
}
/// Subtraction.
GfVec4i &operator-=(GfVec4i const &other) {
_data[0] -= other[0];
_data[1] -= other[1];
_data[2] -= other[2];
_data[3] -= other[3];
return *this;
}
friend GfVec4i operator-(GfVec4i const &l, GfVec4i const &r) {
return GfVec4i(l) -= r;
}
/// Multiplication by scalar.
GfVec4i &operator*=(double s) {
_data[0] *= s;
_data[1] *= s;
_data[2] *= s;
_data[3] *= s;
return *this;
}
GfVec4i operator*(double s) const {
return GfVec4i(*this) *= s;
}
friend GfVec4i operator*(double s, GfVec4i const &v) {
return v * s;
}
/// Division by scalar.
GfVec4i &operator/=(int s) {
_data[0] /= s;
_data[1] /= s;
_data[2] /= s;
_data[3] /= s;
return *this;
}
GfVec4i operator/(int s) const {
return GfVec4i(*this) /= s;
}
/// See GfDot().
int operator*(GfVec4i const &v) const {
return _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2] + _data[3] * v[3];
}
/// Returns the projection of \p this onto \p v. That is:
/// \code
/// v * (*this * v)
/// \endcode
GfVec4i GetProjection(GfVec4i const &v) const {
return v * (*this * v);
}
/// Returns the orthogonal complement of \p this->GetProjection(b).
/// That is:
/// \code
/// *this - this->GetProjection(b)
/// \endcode
GfVec4i GetComplement(GfVec4i const &b) const {
return *this - this->GetProjection(b);
}
/// Squared length.
int GetLengthSq() const {
return *this * *this;
}
private:
int _data[4];
};
/// Output a GfVec4i.
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream &, GfVec4i const &);
/// Returns component-wise multiplication of vectors \p v1 and \p v2.
inline GfVec4i
GfCompMult(GfVec4i const &v1, GfVec4i const &v2) {
return GfVec4i(
v1[0] * v2[0],
v1[1] * v2[1],
v1[2] * v2[2],
v1[3] * v2[3]
);
}
/// Returns component-wise quotient of vectors \p v1 and \p v2.
inline GfVec4i
GfCompDiv(GfVec4i const &v1, GfVec4i const &v2) {
return GfVec4i(
v1[0] / v2[0],
v1[1] / v2[1],
v1[2] / v2[2],
v1[3] / v2[3]
);
}
/// Returns the dot (inner) product of two vectors.
inline int
GfDot(GfVec4i const &v1, GfVec4i const &v2) {
return v1 * v2;
}
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_GF_VEC4I_H