HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
line.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_BASE_GF_LINE_H
25 #define PXR_BASE_GF_LINE_H
26 
27 /// \file gf/line.h
28 /// \ingroup group_gf_BasicGeometry
29 
30 #include "pxr/pxr.h"
31 #include "pxr/base/gf/vec3d.h"
32 
33 #include <float.h>
34 #include <iosfwd>
35 
37 
38 /// \class GfLine
39 /// \ingroup group_gf_BasicGeometry
40 ///
41 /// Basic type: 3D line
42 ///
43 /// This class represents a three-dimensional line in space. Lines are
44 /// constructed from a point, \p p0, and a direction, dir. The direction is
45 /// normalized in the constructor.
46 ///
47 /// The line is kept in a parametric represention, p = p0 + t * dir.
48 ///
49 class GfLine {
50 
51  public:
52 
53  /// The default constructor leaves line parameters undefined.
54  GfLine() {
55  }
56 
57  /// Construct a line from a point and a direction.
58  GfLine(const GfVec3d &p0, const GfVec3d &dir ) {
59  Set( p0, dir );
60  }
61 
62  double Set(const GfVec3d &p0, const GfVec3d &dir ) {
63  _p0 = p0;
64  _dir = dir;
65  return _dir.Normalize();
66  }
67 
68  /// Return the point on the line at \p ( p0 + t * dir ).
69  /// Remember dir has been normalized so t represents a unit distance.
70  GfVec3d GetPoint( double t ) const { return _p0 + _dir * t; }
71 
72  /// Return the normalized direction of the line.
73  const GfVec3d &GetDirection() const { return _dir; }
74 
75  /// Returns the point on the line that is closest to \p point. If \p t is
76  /// not \c NULL, it will be set to the parametric distance along the line
77  /// of the returned point.
78  GF_API
79  GfVec3d FindClosestPoint(const GfVec3d &point, double *t = NULL) const;
80 
81  /// Component-wise equality test. The starting points and directions,
82  /// must match exactly for lines to be considered equal.
83  bool operator ==(const GfLine &l) const {
84  return _p0 == l._p0 && _dir == l._dir;
85  }
86 
87  /// Component-wise inequality test. The starting points, and directions
88  /// must match exactly for lines to be considered equal.
89  bool operator !=(const GfLine &r) const {
90  return ! (*this == r);
91  }
92 
93  private:
94  GF_API
95  friend bool GfFindClosestPoints( const GfLine &, const GfLine &,
96  GfVec3d *, GfVec3d *,
97  double *, double * );
98  // Parametric description:
99  // l(t) = _p0 + t * _length * _dir;
100  GfVec3d _p0;
101  GfVec3d _dir;
102 };
103 
104 /// Computes the closets points between two lines.
105 ///
106 /// The two points are returned in \p p1 and \p p2. The parametric distance
107 /// of each point on the lines is returned in \p t1 and \p t2.
108 ///
109 /// This returns \c false if the lines were close enough to parallel that no
110 /// points could be computed; in this case, the other return values are
111 /// undefined.
112 GF_API
113 bool GfFindClosestPoints(const GfLine &l1, const GfLine &l2,
114  GfVec3d *p1 = nullptr, GfVec3d *p2 = nullptr,
115  double *t1 = nullptr, double *t2 = nullptr);
116 
117 /// Output a GfLine.
118 /// \ingroup group_gf_DebuggingOutput
119 GF_API std::ostream &operator<<(std::ostream&, const GfLine&);
120 
122 
123 #endif // PXR_BASE_GF_LINE_H
GF_API std::ostream & operator<<(std::ostream &, const GfLine &)
bool operator==(const GfLine &l) const
Definition: line.h:83
GF_API bool GfFindClosestPoints(const GfLine &l1, const GfLine &l2, GfVec3d *p1=nullptr, GfVec3d *p2=nullptr, double *t1=nullptr, double *t2=nullptr)
GF_API friend bool GfFindClosestPoints(const GfLine &, const GfLine &, GfVec3d *, GfVec3d *, double *, double *)
Definition: line.h:49
GfLine()
The default constructor leaves line parameters undefined.
Definition: line.h:54
double Set(const GfVec3d &p0, const GfVec3d &dir)
Definition: line.h:62
GLdouble t
Definition: glad.h:2397
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
const GfVec3d & GetDirection() const
Return the normalized direction of the line.
Definition: line.h:73
Definition: vec3d.h:62
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
bool operator!=(const GfLine &r) const
Definition: line.h:89
GF_API GfVec3d FindClosestPoint(const GfVec3d &point, double *t=NULL) const
GfLine(const GfVec3d &p0, const GfVec3d &dir)
Construct a line from a point and a direction.
Definition: line.h:58
GLboolean r
Definition: glcorearb.h:1222
GfVec3d GetPoint(double t) const
Definition: line.h:70
double Normalize(double eps=GF_MIN_VECTOR_LENGTH)
Definition: vec3d.h:269
#define GF_API
Definition: api.h:40