Fesapi  0.13.0.0
This project provides C++ classes which allow an easy access in import and export to the Energistics standards.
ContinuousProperty.h
1 /*-----------------------------------------------------------------------
2 Licensed to the Apache Software Foundation (ASF) under one
3 or more contributor license agreements. See the NOTICE file
4 distributed with this work for additional information
5 regarding copyright ownership. The ASF licenses this file
6 to you under the Apache License, Version 2.0 (the
7 "License"; you may not use this file except in compliance
8 with the License. You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12 Unless required by applicable law or agreed to in writing,
13 software distributed under the License is distributed on an
14 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 KIND, either express or implied. See the License for the
16 specific language governing permissions and limitations
17 under the License.
18 -----------------------------------------------------------------------*/
19 #pragma once
20 
21 #include "resqml2/AbstractValuesProperty.h"
22 #include "common/AbstractHdfProxy.h"
23 
24 #include <stdexcept>
25 #include <sstream> // std::ostringstream
26 
27 namespace RESQML2_0_1_NS
28 {
29  class DLL_IMPORT_OR_EXPORT ContinuousProperty : public RESQML2_NS::AbstractValuesProperty
30  {
31  protected:
32 
37 
38  private:
39 
48  void init(RESQML2_NS::AbstractRepresentation * rep, const std::string & guid, const std::string & title,
49  const unsigned int & dimension, const gsoap_resqml2_0_1::resqml2__IndexableElements & attachmentKind);
50 
51  public:
52 
56  ContinuousProperty(gsoap_resqml2_0_1::eml20__DataObjectReference* partialObject) : RESQML2_NS::AbstractValuesProperty(partialObject) {}
57 
68  ContinuousProperty(RESQML2_NS::AbstractRepresentation * rep, const std::string & guid, const std::string & title,
69  const unsigned int & dimension, const gsoap_resqml2_0_1::resqml2__IndexableElements & attachmentKind, const gsoap_resqml2_0_1::resqml2__ResqmlUom & uom, const gsoap_resqml2_0_1::resqml2__ResqmlPropertyKind & energisticsPropertyKind);
70 
81  ContinuousProperty(RESQML2_NS::AbstractRepresentation * rep, const std::string & guid, const std::string & title,
82  const unsigned int & dimension, const gsoap_resqml2_0_1::resqml2__IndexableElements & attachmentKind, const gsoap_resqml2_0_1::resqml2__ResqmlUom & uom, RESQML2_NS::PropertyKind * localPropKind);
83 
94  ContinuousProperty(RESQML2_NS::AbstractRepresentation * rep, const std::string & guid, const std::string & title,
95  const unsigned int & dimension, const gsoap_resqml2_0_1::resqml2__IndexableElements & attachmentKind, const std::string & nonStandardUom, const gsoap_resqml2_0_1::resqml2__ResqmlPropertyKind & energisticsPropertyKind);
96 
107  ContinuousProperty(RESQML2_NS::AbstractRepresentation * rep, const std::string & guid, const std::string & title,
108  const unsigned int & dimension, const gsoap_resqml2_0_1::resqml2__IndexableElements & attachmentKind, const std::string & nonStandardUom, RESQML2_NS::PropertyKind * localPropKind);
109 
113  ContinuousProperty(gsoap_resqml2_0_1::_resqml2__ContinuousProperty* fromGsoap): AbstractValuesProperty(fromGsoap) {}
114 
118  virtual ~ContinuousProperty() {}
119 
120  static const char* XML_TAG;
121  virtual std::string getXmlTag() const {return XML_TAG;}
122 
127  const gsoap_resqml2_0_1::resqml2__ResqmlUom & getUom() const;
128 
133  std::string getUomAsString() const;
134 
143  void pushBackDoubleHdf5Array1dOfValues(double * values, const ULONG64 & valueCount, COMMON_NS::AbstractHdfProxy* proxy,
144  const double & minimumValue = std::numeric_limits<double>::quiet_NaN(), const double & maximumValue = std::numeric_limits<double>::quiet_NaN());
145 
155  void pushBackDoubleHdf5Array2dOfValues(double * values, const ULONG64 & valueCountInFastestDim, const ULONG64 & valueCountInSlowestDim, COMMON_NS::AbstractHdfProxy* proxy,
156  const double & minimumValue = std::numeric_limits<double>::quiet_NaN(), const double & maximumValue = std::numeric_limits<double>::quiet_NaN());
157 
168  void pushBackDoubleHdf5Array3dOfValues(double * values, const ULONG64 & valueCountInFastestDim, const ULONG64 & valueCountInMiddleDim, const ULONG64 & valueCountInSlowestDim, COMMON_NS::AbstractHdfProxy* proxy,
169  const double & minimumValue = std::numeric_limits<double>::quiet_NaN(), const double & maximumValue = std::numeric_limits<double>::quiet_NaN());
170 
180  void pushBackDoubleHdf5ArrayOfValues(double * values, unsigned long long * numValues, const unsigned int & numArrayDimensions, COMMON_NS::AbstractHdfProxy* proxy,
181  double * minimumValue = nullptr, double * maximumValue = nullptr);
182 
191  void pushBackFloatHdf5Array1dOfValues(float * values, const ULONG64 & valueCount, COMMON_NS::AbstractHdfProxy* proxy,
192  const float & minimumValue = std::numeric_limits<float>::quiet_NaN(), const float & maximumValue = std::numeric_limits<float>::quiet_NaN());
193 
203  void pushBackFloatHdf5Array2dOfValues(float * values, const ULONG64 & valueCountInFastestDim, const ULONG64 & valueCountInSlowestDim, COMMON_NS::AbstractHdfProxy* proxy,
204  const float & minimumValue = std::numeric_limits<float>::quiet_NaN(), const float & maximumValue = std::numeric_limits<float>::quiet_NaN());
205 
216  void pushBackFloatHdf5Array3dOfValues(float * values, const ULONG64 & valueCountInFastestDim, const ULONG64 & valueCountInMiddleDim, const ULONG64 & valueCountInSlowestDim, COMMON_NS::AbstractHdfProxy* proxy,
217  const float & minimumValue = std::numeric_limits<float>::quiet_NaN(), const float & maximumValue = std::numeric_limits<float>::quiet_NaN());
218 
228  void pushBackFloatHdf5ArrayOfValues(float * values, unsigned long long * numValues, const unsigned int & numArrayDimensions, COMMON_NS::AbstractHdfProxy* proxy,
229  float * minimumValue = nullptr, float * maximumValue = nullptr);
230 
237  void pushBackFloatHdf5ArrayOfValues(
238  unsigned long long* numValues,
239  const unsigned int& numArrayDimensions,
241  );
242 
250  void pushBackFloatHdf5ArrayOfValues(
251  const ULONG64& valueCountInFastestDim,
252  const ULONG64& valueCountInMiddleDim,
253  const ULONG64& valueCountInSlowestDim,
255  );
256 
270  void setValuesOfFloatHdf5ArrayOfValues(
271  float* values,
272  const ULONG64& valueCountInFastestDim,
273  const ULONG64& valueCountInMiddleDim,
274  const ULONG64& valueCountInSlowestDim,
275  const ULONG64& offsetInFastestDim,
276  const ULONG64& offsetInMiddleDim,
277  const ULONG64& offsetInSlowestDim,
279  unsigned int patchIndex = (std::numeric_limits<unsigned int>::max)()
280  );
281 
292  void setValuesOfFloatHdf5ArrayOfValues(
293  float * values,
294  unsigned long long * numValues,
295  unsigned long long * offsetValues,
296  const unsigned int & numArrayDimensions,
298  unsigned int patchIndex = (std::numeric_limits<unsigned int>::max)()
299  );
300 
309  std::string pushBackRefToExistingDataset(COMMON_NS::AbstractHdfProxy* hdfProxy, const std::string & datasetName = "", const long & nullValue = (std::numeric_limits<long>::max)());
310 
316  void getDoubleValuesOfPatch(const unsigned int & patchIndex, double * values);
317 
323  void getFloatValuesOfPatch(const unsigned int & patchIndex, float * values);
324 
333  void getFloatValuesOfPatch(
334  const unsigned int& patchIndex,
335  float* values,
336  unsigned long long* numValuesInEachDimension,
337  unsigned long long* offsetInEachDimension,
338  const unsigned int& numArrayDimensions
339  );
340 
352  void getFloatValuesOf3dPatch(
353  const unsigned int& patchIndex,
354  float* values,
355  const ULONG64& valueCountInFastestDim,
356  const ULONG64& valueCountInMiddleDim,
357  const ULONG64& valueCountInSlowestDim,
358  const ULONG64& offsetInFastestDim,
359  const ULONG64& offsetInMiddleDim,
360  const ULONG64& offsetInSlowestDim
361  );
362 
363  /*
364  * Get the minimum value in this continuous properties. It reads it from file.
365  * @return the minimum value if present in the file otherwise NaN.
366  */
367  double getMinimumValue();
368 
369  /*
370  * Get the maximum value in this discrete properties. It reads it from file.
371  * @return the maximum value if present in the file otherwise NaN.
372  */
373  double getMaximumValue();
374 
378  bool validatePropertyKindAssociation(RESQML2_NS::PropertyKind* pk);
379 
383  bool validatePropertyKindAssociation(const gsoap_resqml2_0_1::resqml2__ResqmlPropertyKind & pk);
384 
385  private:
386 
395  template <class T>
396  void setPropertyMinMax(
397  T* values,
398  unsigned long long* numValuesInEachDimension,
399  const unsigned int& numArrayDimensions,
400  T * minimumValue = nullptr, T * maximumValue = nullptr)
401  {
402  gsoap_resqml2_0_1::_resqml2__ContinuousProperty* prop = static_cast<gsoap_resqml2_0_1::_resqml2__ContinuousProperty*>(gsoapProxy2_0_1);
403  prop->MinimumValue.clear();
404  prop->MaximumValue.clear();
405 
406  if (minimumValue != nullptr && maximumValue != nullptr) {
407  for (unsigned int i = 0; i < prop->Count; ++i)
408  {
409  prop->MinimumValue.push_back(minimumValue[i]);
410  prop->MaximumValue.push_back(maximumValue[i]);
411  }
412  }
413  else {
414 
415  ULONG64 nValues = numValuesInEachDimension[0];
416  if (prop->Count == 1) {
417  for (unsigned int dim = 1; dim < numArrayDimensions; dim++) {
418  nValues *= numValuesInEachDimension[dim];
419  }
420  }
421  else if (prop->Count > 1) {
422  //In this case, the last (fastest) dimension has the number of properties per indexable element of the representation.
423  for (unsigned int dim = 1; dim < numArrayDimensions - 1; dim++) {
424  nValues *= numValuesInEachDimension[dim];
425  }
426  }
427  else {
428  throw std::invalid_argument("Cannot compute and set min and max value on a property which has a Count set to zero or negative.");
429  }
430 
431  for (ULONG64 propIndex = 0; propIndex < prop->Count; ++propIndex) {
432  size_t i = propIndex;
433  T computedMin = std::numeric_limits<T>::quiet_NaN();
434  T computedMax = std::numeric_limits<T>::quiet_NaN();
435  while (i < nValues && values[i] != values[i]) i += prop->Count;
436  if (i >= nValues) {
437  // All values of a dimension of the vectorial property look to be only NaN values.
438  if (prop->Count == 1) {
439  return; // Does not set min and max value
440  }
441  else { // Set min and max as NaN values
442  prop->MinimumValue.push_back(std::numeric_limits<T>::quiet_NaN());
443  prop->MaximumValue.push_back(std::numeric_limits<T>::quiet_NaN());
444  }
445  }
446  computedMin = values[i];
447  computedMax = values[i];
448 
449  for (; i < nValues; i += prop->Count) {
450  T propVal = values[i];
451  if (propVal < computedMin) {
452  computedMin = propVal;
453  }
454  else if (propVal > computedMax) {
455  computedMax = propVal;
456  }
457  }
458  prop->MinimumValue.push_back(computedMin);
459  prop->MaximumValue.push_back(computedMax);
460  }
461  }
462  }
463  };
464 }
465 
Definition: AbstractRepresentation.h:31
Definition: EpcDocument.h:65
virtual std::string getXmlTag() const
Definition: ContinuousProperty.h:121
ContinuousProperty()
Definition: ContinuousProperty.h:36
ContinuousProperty(gsoap_resqml2_0_1::eml20__DataObjectReference *partialObject)
Definition: ContinuousProperty.h:56
Definition: AbstractHdfProxy.h:30
Definition: PropertyKind.h:25
ContinuousProperty(gsoap_resqml2_0_1::_resqml2__ContinuousProperty *fromGsoap)
Definition: ContinuousProperty.h:113
virtual ~ContinuousProperty()
Definition: ContinuousProperty.h:118
Definition: AbstractValuesProperty.h:26
Definition: EpcDocument.h:49
Definition: ContinuousProperty.h:29