1 /**************************************************************************\
2 * Copyright (c) Kongsberg Oil & Gas Technologies AS
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * Neither the name of the copyright holder nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 \**************************************************************************/
32
33 /*!
34 \class SoMFVec4d SoMFVec4d.h Inventor/fields/SoMFVec4d.h
35 \brief The SoMFVec4d class is a container for SbVec4d vectors.
36
37 \ingroup fields
38
39 This field is used where nodes, engines or other field containers
40 needs to store an array of vectors with four elements.
41
42 This field supports application data sharing through a
43 setValuesPointer() method. See SoMField documentation for
44 information on how to use this function.
45
46 \sa SbVec4d, SoSFVec4d
47 \COIN_CLASS_EXTENSION
48 \since Coin 2.5
49 */
50
51 // *************************************************************************
52
53 #include <Inventor/fields/SoMFVec4d.h>
54
55 #include <cassert>
56
57 #include <Inventor/SoInput.h>
58 #include <Inventor/errors/SoDebugError.h>
59
60 #include "fields/SoSubFieldP.h"
61 #include "fields/shared.h"
62
63 // *************************************************************************
64
65 SO_MFIELD_SOURCE(SoMFVec4d, SbVec4d, const SbVec4d &);
66
67 SO_MFIELD_SETVALUESPOINTER_SOURCE(SoMFVec4d, SbVec4d, SbVec4d);
68 SO_MFIELD_SETVALUESPOINTER_SOURCE(SoMFVec4d, SbVec4d, double);
69
70 // *************************************************************************
71
72 // Override from parent class.
73 void
initClass(void)74 SoMFVec4d::initClass(void)
75 {
76 SO_MFIELD_INTERNAL_INIT_CLASS(SoMFVec4d);
77 }
78
79 // *************************************************************************
80
81 // No need to document readValue() and writeValue() here, as the
82 // necessary information is provided by the documentation of the
83 // parent classes.
84 #ifndef DOXYGEN_SKIP_THIS
85
86 SbBool
read1Value(SoInput * in,int idx)87 SoMFVec4d::read1Value(SoInput * in, int idx)
88 {
89 assert(idx < this->maxNum);
90 return
91 in->read(this->values[idx][0]) &&
92 in->read(this->values[idx][1]) &&
93 in->read(this->values[idx][2]) &&
94 in->read(this->values[idx][3]);
95 }
96
97 void
write1Value(SoOutput * out,int idx) const98 SoMFVec4d::write1Value(SoOutput * out, int idx) const
99 {
100 sosfvec4d_write_value(out, (*this)[idx]);
101 }
102
103 #endif // DOXYGEN_SKIP_THIS
104
105 // *************************************************************************
106
107 /*!
108 Set \a num vector array elements from \a xyzw, starting at index
109 \a start.
110 */
111 void
setValues(int start,int numarg,const double xyzw[][4])112 SoMFVec4d::setValues(int start, int numarg, const double xyzw[][4])
113 {
114 if(start+numarg > this->maxNum) this->allocValues(start+numarg);
115 else if(start+numarg > this->num) this->num = start+numarg;
116
117 for(int i=0; i < numarg; i++) this->values[i+start].setValue(xyzw[i]);
118 this->valueChanged();
119 }
120
121 /*!
122 Set the vector at \a idx.
123 */
124 void
set1Value(int idx,double x,double y,double z,double w)125 SoMFVec4d::set1Value(int idx, double x, double y, double z, double w)
126 {
127 this->set1Value(idx, SbVec4d(x, y, z, w));
128 }
129
130 /*!
131 Set the vector at \a idx.
132 */
133 void
set1Value(int idx,const double xyzw[4])134 SoMFVec4d::set1Value(int idx, const double xyzw[4])
135 {
136 this->set1Value(idx, SbVec4d(xyzw));
137 }
138
139 /*!
140 Set this field to contain a single vector with the given
141 element values.
142 */
143 void
setValue(double x,double y,double z,double w)144 SoMFVec4d::setValue(double x, double y, double z, double w)
145 {
146 this->setValue(SbVec4d(x,y,z,w));
147 }
148
149 /*!
150 Set this field to contain a single vector with the given
151 element values.
152 */
153 void
setValue(const double xyzw[4])154 SoMFVec4d::setValue(const double xyzw[4])
155 {
156 if (xyzw == NULL) this->setNum(0);
157 else this->setValue(SbVec4d(xyzw));
158 }
159
160 // *************************************************************************
161
162 #ifdef COIN_TEST_SUITE
163
BOOST_AUTO_TEST_CASE(initialized)164 BOOST_AUTO_TEST_CASE(initialized)
165 {
166 SoMFVec4d field;
167 BOOST_CHECK_MESSAGE(field.getTypeId() != SoType::badType(),
168 "missing class initialization");
169 BOOST_CHECK_EQUAL(field.getNum(), 0);
170 }
171
172 #endif // COIN_TEST_SUITE
173