Coin Logo http://www.coin3d.org/
http://www.kongsberg.com/kogt/

SbVec3d.h
1 #ifndef COIN_SBVEC3D_H
2 #define COIN_SBVEC3D_H
3 
4 /**************************************************************************\
5  * Copyright (c) Kongsberg Oil & Gas Technologies AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from
21  * this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 \**************************************************************************/
35 
36 #include <stdio.h>
37 #include <Inventor/SbBasic.h>
38 #include <Inventor/SbString.h>
39 
40 #ifndef NDEBUG
41 #include <Inventor/errors/SoDebugError.h>
42 #endif // !NDEBUG
43 
44 class SbVec3f;
45 class SbVec3b;
46 class SbVec3s;
47 class SbVec3i32;
48 class SbDPPlane;
49 
50 class COIN_DLL_API SbVec3d {
51 public:
52  SbVec3d(void) { }
53  SbVec3d(const double v[3]) { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2]; }
54  SbVec3d(double x, double y, double z) { vec[0] = x; vec[1] = y; vec[2] = z; }
55  explicit SbVec3d(const SbVec3f & v) { setValue(v); }
56  explicit SbVec3d(const SbVec3b & v) { setValue(v); }
57  explicit SbVec3d(const SbVec3s & v) { setValue(v); }
58  explicit SbVec3d(const SbVec3i32 & v) { setValue(v); }
59  SbVec3d(const SbDPPlane & p0, const SbDPPlane & p1, const SbDPPlane & p2);
60 
61  SbVec3d & setValue(const double v[3]) { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2]; return *this; }
62  SbVec3d & setValue(double x, double y, double z) { vec[0] = x; vec[1] = y; vec[2] = z; return *this; }
63  SbVec3d & setValue(const SbVec3d & barycentric,
64  const SbVec3d & v0,
65  const SbVec3d & v1,
66  const SbVec3d & v2);
67  SbVec3d & setValue(const SbVec3f & v);
68  SbVec3d & setValue(const SbVec3b & v);
69  SbVec3d & setValue(const SbVec3s & v);
70  SbVec3d & setValue(const SbVec3i32 & v);
71 
72  const double * getValue(void) const { return vec; }
73  void getValue(double & x, double & y, double & z) const { x = vec[0]; y = vec[1]; z = vec[2]; }
74 
75  double & operator [] (const int i) { return vec[i]; }
76  const double & operator [] (const int i) const { return vec[i]; }
77 
78  SbVec3d cross(const SbVec3d & v) const;
79  double dot(const SbVec3d & v) const { return vec[0] * v.vec[0] + vec[1] * v.vec[1] + vec[2] * v.vec[2]; }
80  SbBool equals(const SbVec3d & v, double tolerance) const;
81  SbVec3d getClosestAxis(void) const;
82  double length(void) const;
83  double sqrLength(void) const { return vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]; }
84  void negate(void) { vec[0] = -vec[0]; vec[1] = -vec[1]; vec[2] = -vec[2]; }
85  double normalize(void);
86 
87  SbVec3d & operator *= (double d) { vec[0] *= d; vec[1] *= d; vec[2] *= d; return *this; }
88  SbVec3d & operator /= (double d) { SbDividerChk("SbVec3d::operator/=(double)", d); return operator *= (1.0 / d); }
89  SbVec3d & operator += (const SbVec3d & v) { vec[0] += v[0]; vec[1] += v[1]; vec[2] += v[2]; return *this; }
90  SbVec3d & operator -= (const SbVec3d & v) { vec[0] -= v[0]; vec[1] -= v[1]; vec[2] -= v[2]; return *this; }
91  SbVec3d operator - (void) const { return SbVec3d(-vec[0], -vec[1], -vec[2]); }
92 
93  SbString toString() const;
94  SbBool fromString(const SbString & str);
95 
96  void print(FILE * fp) const;
97 
98 private:
99  double vec[3];
100 
101 }; // SbVec3d
102 
103 COIN_DLL_API inline SbVec3d operator * (const SbVec3d & v, double d) {
104  SbVec3d val(v); val *= d; return val;
105 }
106 
107 COIN_DLL_API inline SbVec3d operator * (double d, const SbVec3d & v) {
108  SbVec3d val(v); val *= d; return val;
109 }
110 
111 COIN_DLL_API inline SbVec3d operator / (const SbVec3d & v, double d) {
112  SbDividerChk("operator/(SbVec3d,double)", d);
113  SbVec3d val(v); val /= d; return val;
114 }
115 
116 COIN_DLL_API inline SbVec3d operator + (const SbVec3d & v1, const SbVec3d & v2) {
117  SbVec3d v(v1); v += v2; return v;
118 }
119 
120 COIN_DLL_API inline SbVec3d operator - (const SbVec3d & v1, const SbVec3d & v2) {
121  SbVec3d v(v1); v -= v2; return v;
122 }
123 
124 COIN_DLL_API inline int operator == (const SbVec3d & v1, const SbVec3d & v2) {
125  return ((v1[0] == v2[0]) && (v1[1] == v2[1]) && (v1[2] == v2[2]));
126 }
127 
128 COIN_DLL_API inline int operator != (const SbVec3d & v1, const SbVec3d & v2) {
129  return !(v1 == v2);
130 }
131 
132 #endif // !COIN_SBVEC3D_H
SbVec3d(const SbVec3s &v)
Definition: SbVec3d.h:57
SbVec3d & setValue(const double v[3])
Definition: SbVec3d.h:61
The SbVec3d class is a 3 dimensional vector with double precision floating point coordinates.This vector class provides storage for a 3 dimensional double precision floating point vector aswell as simple floating point arithmetic operations.
Definition: SbVec3d.h:50
SbVec3d(const SbVec3b &v)
Definition: SbVec3d.h:56
The SbDPPlane class represents a plane in 3D space.SbDPPlane is used by many other classes in Coin...
Definition: SbDPPlane.h:43
void getValue(double &x, double &y, double &z) const
Definition: SbVec3d.h:73
SbVec3d & setValue(double x, double y, double z)
Definition: SbVec3d.h:62
SbVec3d(double x, double y, double z)
Definition: SbVec3d.h:54
SbVec3d(const SbVec3f &v)
Definition: SbVec3d.h:55
The SbVec3s class is a 3 dimensional vector with short integer coordinates.This vector class provides...
Definition: SbVec3s.h:51
SbVec3d(const double v[3])
Definition: SbVec3d.h:53
SbVec3d(void)
Definition: SbVec3d.h:52
The SbVec3f class is a 3 dimensional vector with floating point coordinates.This vector class is used...
Definition: SbVec3f.h:51
SbVec3d(const SbVec3i32 &v)
Definition: SbVec3d.h:58
Definition: SbVec3b.h:48
Definition: SbVec3i32.h:48
double dot(const SbVec3d &v) const
Definition: SbVec3d.h:79
The SbString class is a string class with convenience functions for string operations.This is the class used for storing and working with character strings. It automatically takes care of supporting all the "bookkeeping" tasks usually associated with working with character strings, like memory allocation and deallocation etc.
Definition: SbString.h:52
const double * getValue(void) const
Definition: SbVec3d.h:72
void negate(void)
Definition: SbVec3d.h:84
double sqrLength(void) const
Definition: SbVec3d.h:83

Copyright © by Kongsberg Oil & Gas Technologies. All rights reserved.

Generated for Coin by Doxygen