@@ -128,6 +128,19 public: | |||
|
128 | 128 | } |
|
129 | 129 | |
|
130 | 130 | /** |
|
131 | * @return the data of a component | |
|
132 | * @param componentIndex the index of the component to retrieve the data | |
|
133 | * @return the component's data, empty vector if the index is invalid | |
|
134 | */ | |
|
135 | QVector<double> data(int componentIndex) const noexcept | |
|
136 | { | |
|
137 | QReadLocker locker{&m_Lock}; | |
|
138 | ||
|
139 | return (componentIndex >= 0 && componentIndex < m_Data.size()) ? m_Data.at(componentIndex) | |
|
140 | : QVector<double>{}; | |
|
141 | } | |
|
142 | ||
|
143 | /** | |
|
131 | 144 | * @return the data as a vector, as a const reference |
|
132 | 145 | * @remarks this method is only available for a unidimensional ArrayData |
|
133 | 146 | */ |
@@ -139,24 +152,28 public: | |||
|
139 | 152 | } |
|
140 | 153 | |
|
141 | 154 | /** |
|
142 | * Merges into the array data an other array data | |
|
155 | * Merges into the array data an other array data. The two array datas must have the same number | |
|
156 | * of components so the merge can be done | |
|
143 | 157 | * @param other the array data to merge with |
|
144 | 158 | * @param prepend if true, the other array data is inserted at the beginning, otherwise it is |
|
145 | 159 | * inserted at the end |
|
146 | * @remarks this method is only available for a unidimensional ArrayData | |
|
147 | 160 | */ |
|
148 | template <int D = Dim, typename = std::enable_if_t<D == 1> > | |
|
149 | void add(const ArrayData<1> &other, bool prepend = false) | |
|
161 | void add(const ArrayData<Dim> &other, bool prepend = false) | |
|
150 | 162 | { |
|
151 | 163 | QWriteLocker locker{&m_Lock}; |
|
152 | if (!m_Data.empty()) { | |
|
153 | 164 |
|
|
154 | 165 | |
|
166 | auto nbComponents = m_Data.size(); | |
|
167 | if (nbComponents != other.m_Data.size()) { | |
|
168 | return; | |
|
169 | } | |
|
170 | ||
|
171 | for (auto componentIndex = 0; componentIndex < nbComponents; ++componentIndex) { | |
|
155 | 172 | if (prepend) { |
|
156 | const auto &otherData = other.data(); | |
|
173 | const auto &otherData = other.data(componentIndex); | |
|
157 | 174 | const auto otherDataSize = otherData.size(); |
|
158 | 175 | |
|
159 |
auto &data = m_Data[ |
|
|
176 | auto &data = m_Data[componentIndex]; | |
|
160 | 177 | data.insert(data.begin(), otherDataSize, 0.); |
|
161 | 178 | |
|
162 | 179 | for (auto i = 0; i < otherDataSize; ++i) { |
@@ -164,7 +181,7 public: | |||
|
164 | 181 | } |
|
165 | 182 | } |
|
166 | 183 | else { |
|
167 |
m_Data[ |
|
|
184 | m_Data[componentIndex] += other.data(componentIndex); | |
|
168 | 185 | } |
|
169 | 186 | } |
|
170 | 187 | } |
General Comments 0
You need to be logged in to leave comments.
Login now