My Project
ContinuousProperty.h
1 /*-----------------------------------------------------------------------
2 Copyright F2I-CONSULTING, (2014-2017)
3 
4 philippe.verney@f2i-consulting.com
5 
6 This software is a computer program whose purpose is to access to data formatted using Energistics standards.
7 
8 This software is governed by the CeCILL-B license under French law and
9 abiding by the rules of distribution of free software. You can use,
10 modify and/ or redistribute the software under the terms of the CeCILL-B
11 license as circulated by CEA, CNRS and INRIA at the following URL
12 "http://www.cecill.info".
13 
14 As a counterpart to the access to the source code and rights to copy,
15 modify and redistribute granted by the license, users are provided only
16 with a limited warranty and the software's author, the holder of the
17 economic rights, and the successive licensors have only limited
18 liability.
19 
20 In this respect, the user's attention is drawn to the risks associated
21 with loading, using, modifying and/or developing or reproducing the
22 software by the user in light of its specific status of free software,
23 that may mean that it is complicated to manipulate, and that also
24 therefore means that it is reserved for developers and experienced
25 professionals having in-depth computer knowledge. Users are therefore
26 encouraged to load and test the software's suitability as regards their
27 requirements in conditions enabling the security of their systems and/or
28 data to be ensured and, more generally, to use and operate it in the
29 same conditions as regards security.
30 
31 The fact that you are presently reading this means that you have had
32 knowledge of the CeCILL-B license and that you accept its terms.
33 -----------------------------------------------------------------------*/
34 #pragma once
35 
36 #include "resqml2/AbstractValuesProperty.h"
37 #include "common/AbstractHdfProxy.h"
38 
39 #include <stdexcept>
40 #include <sstream> // std::ostringstream
41 
42 namespace resqml2_0_1
43 {
44  class DLL_IMPORT_OR_EXPORT ContinuousProperty : public resqml2::AbstractValuesProperty
45  {
46  protected:
47 
52 
53  private:
54 
63  void init(resqml2::AbstractRepresentation * rep, const std::string & guid, const std::string & title,
64  const unsigned int & dimension, const gsoap_resqml2_0_1::resqml2__IndexableElements & attachmentKind);
65 
66  public:
67 
71  ContinuousProperty(gsoap_resqml2_0_1::eml20__DataObjectReference* partialObject) : resqml2::AbstractValuesProperty(partialObject) {}
72 
83  ContinuousProperty(resqml2::AbstractRepresentation * rep, const std::string & guid, const std::string & title,
84  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);
85 
96  ContinuousProperty(resqml2::AbstractRepresentation * rep, const std::string & guid, const std::string & title,
97  const unsigned int & dimension, const gsoap_resqml2_0_1::resqml2__IndexableElements & attachmentKind, const gsoap_resqml2_0_1::resqml2__ResqmlUom & uom, resqml2::PropertyKind * localPropKind);
98 
109  ContinuousProperty(resqml2::AbstractRepresentation * rep, const std::string & guid, const std::string & title,
110  const unsigned int & dimension, const gsoap_resqml2_0_1::resqml2__IndexableElements & attachmentKind, const std::string & nonStandardUom, const gsoap_resqml2_0_1::resqml2__ResqmlPropertyKind & energisticsPropertyKind);
111 
122  ContinuousProperty(resqml2::AbstractRepresentation * rep, const std::string & guid, const std::string & title,
123  const unsigned int & dimension, const gsoap_resqml2_0_1::resqml2__IndexableElements & attachmentKind, const std::string & nonStandardUom, resqml2::PropertyKind * localPropKind);
124 
128  ContinuousProperty(gsoap_resqml2_0_1::_resqml2__ContinuousProperty* fromGsoap): AbstractValuesProperty(fromGsoap) {}
129 
133  virtual ~ContinuousProperty() {}
134 
135  static const char* XML_TAG;
136  virtual std::string getXmlTag() const {return XML_TAG;}
137 
142  const gsoap_resqml2_0_1::resqml2__ResqmlUom & getUom() const;
143 
148  std::string getUomAsString() const;
149 
158  void pushBackDoubleHdf5Array1dOfValues(double * values, const ULONG64 & valueCount, common::AbstractHdfProxy* proxy,
159  const double & minimumValue = std::numeric_limits<double>::quiet_NaN(), const double & maximumValue = std::numeric_limits<double>::quiet_NaN());
160 
170  void pushBackDoubleHdf5Array2dOfValues(double * values, const ULONG64 & valueCountInFastestDim, const ULONG64 & valueCountInSlowestDim, common::AbstractHdfProxy* proxy,
171  const double & minimumValue = std::numeric_limits<double>::quiet_NaN(), const double & maximumValue = std::numeric_limits<double>::quiet_NaN());
172 
183  void pushBackDoubleHdf5Array3dOfValues(double * values, const ULONG64 & valueCountInFastestDim, const ULONG64 & valueCountInMiddleDim, const ULONG64 & valueCountInSlowestDim, common::AbstractHdfProxy* proxy,
184  const double & minimumValue = std::numeric_limits<double>::quiet_NaN(), const double & maximumValue = std::numeric_limits<double>::quiet_NaN());
185 
195  void pushBackDoubleHdf5ArrayOfValues(double * values, unsigned long long * numValues, const unsigned int & numArrayDimensions, common::AbstractHdfProxy* proxy,
196  double * minimumValue = nullptr, double * maximumValue = nullptr);
197 
206  void pushBackFloatHdf5Array1dOfValues(float * values, const ULONG64 & valueCount, common::AbstractHdfProxy* proxy,
207  const float & minimumValue = std::numeric_limits<float>::quiet_NaN(), const float & maximumValue = std::numeric_limits<float>::quiet_NaN());
208 
218  void pushBackFloatHdf5Array2dOfValues(float * values, const ULONG64 & valueCountInFastestDim, const ULONG64 & valueCountInSlowestDim, common::AbstractHdfProxy* proxy,
219  const float & minimumValue = std::numeric_limits<float>::quiet_NaN(), const float & maximumValue = std::numeric_limits<float>::quiet_NaN());
220 
231  void pushBackFloatHdf5Array3dOfValues(float * values, const ULONG64 & valueCountInFastestDim, const ULONG64 & valueCountInMiddleDim, const ULONG64 & valueCountInSlowestDim, common::AbstractHdfProxy* proxy,
232  const float & minimumValue = std::numeric_limits<float>::quiet_NaN(), const float & maximumValue = std::numeric_limits<float>::quiet_NaN());
233 
243  void pushBackFloatHdf5ArrayOfValues(float * values, unsigned long long * numValues, const unsigned int & numArrayDimensions, common::AbstractHdfProxy* proxy,
244  float * minimumValue = nullptr, float * maximumValue = nullptr);
245 
252  void pushBackFloatHdf5ArrayOfValues(
253  unsigned long long* numValues,
254  const unsigned int& numArrayDimensions,
256  );
257 
265  void pushBackFloatHdf5ArrayOfValues(
266  const ULONG64& valueCountInFastestDim,
267  const ULONG64& valueCountInMiddleDim,
268  const ULONG64& valueCountInSlowestDim,
270  );
271 
285  void setValuesOfFloatHdf5ArrayOfValues(
286  float* values,
287  const ULONG64& valueCountInFastestDim,
288  const ULONG64& valueCountInMiddleDim,
289  const ULONG64& valueCountInSlowestDim,
290  const ULONG64& offsetInFastestDim,
291  const ULONG64& offsetInMiddleDim,
292  const ULONG64& offsetInSlowestDim,
294  unsigned int patchIndex = (std::numeric_limits<unsigned int>::max)()
295  );
296 
307  void setValuesOfFloatHdf5ArrayOfValues(
308  float * values,
309  unsigned long long * numValues,
310  unsigned long long * offsetValues,
311  const unsigned int & numArrayDimensions,
313  unsigned int patchIndex = (std::numeric_limits<unsigned int>::max)()
314  );
315 
324  std::string pushBackRefToExistingDataset(common::AbstractHdfProxy* hdfProxy, const std::string & datasetName = "", const long & nullValue = (std::numeric_limits<long>::max)());
325 
331  void getDoubleValuesOfPatch(const unsigned int & patchIndex, double * values);
332 
338  void getFloatValuesOfPatch(const unsigned int & patchIndex, float * values);
339 
348  void getFloatValuesOfPatch(
349  const unsigned int& patchIndex,
350  float* values,
351  unsigned long long* numValuesInEachDimension,
352  unsigned long long* offsetInEachDimension,
353  const unsigned int& numArrayDimensions
354  );
355 
367  void getFloatValuesOf3dPatch(
368  const unsigned int& patchIndex,
369  float* values,
370  const ULONG64& valueCountInFastestDim,
371  const ULONG64& valueCountInMiddleDim,
372  const ULONG64& valueCountInSlowestDim,
373  const ULONG64& offsetInFastestDim,
374  const ULONG64& offsetInMiddleDim,
375  const ULONG64& offsetInSlowestDim
376  );
377 
378  double getMinimumValue();
379  double getMaximumValue();
380 
384  bool validatePropertyKindAssociation(resqml2::PropertyKind* pk);
385 
389  bool validatePropertyKindAssociation(const gsoap_resqml2_0_1::resqml2__ResqmlPropertyKind & pk);
390 
391  private:
392 
401  template <class T>
402  void setPropertyMinMax(
403  T* values,
404  unsigned long long* numValuesInEachDimension,
405  const unsigned int& numArrayDimensions,
406  T * minimumValue = nullptr, T * maximumValue = nullptr)
407  {
408  gsoap_resqml2_0_1::_resqml2__ContinuousProperty* prop = static_cast<gsoap_resqml2_0_1::_resqml2__ContinuousProperty*>(gsoapProxy2_0_1);
409  prop->MinimumValue.clear();
410  prop->MaximumValue.clear();
411 
412  if (minimumValue != nullptr && maximumValue != nullptr) {
413  for (unsigned int i = 0; i < prop->Count; ++i)
414  {
415  prop->MinimumValue.push_back(minimumValue[i]);
416  prop->MaximumValue.push_back(maximumValue[i]);
417  }
418  }
419  else {
420 
421  ULONG64 nValues = numValuesInEachDimension[0];
422  if (prop->Count == 1) {
423  for (unsigned int dim = 1; dim < numArrayDimensions; dim++) {
424  nValues *= numValuesInEachDimension[dim];
425  }
426  }
427  else if (prop->Count > 1) {
428  //In this case, the last (fastest) dimension has the number of properties per indexable element of the representation.
429  for (unsigned int dim = 1; dim < numArrayDimensions - 1; dim++) {
430  nValues *= numValuesInEachDimension[dim];
431  }
432  }
433  else {
434  throw std::invalid_argument("Cannot compute and set min and max value on a property which has a Count set to zero or negative.");
435  }
436 
437  for (unsigned int propIndex = 0; propIndex < prop->Count; ++propIndex) {
438  size_t i = propIndex;
439  T computedMin = std::numeric_limits<T>::quiet_NaN();
440  T computedMax = std::numeric_limits<T>::quiet_NaN();
441  while (i < nValues && values[i] != values[i]) i += prop->Count;
442  if (i >= nValues) {
443  throw std::invalid_argument("All values of a dimension of the vectorial property look to be only NaN values.");
444  }
445  computedMin = values[i];
446  computedMax = values[i];
447 
448  for (; i < nValues; i += prop->Count) {
449  T propVal = values[i];
450  if (propVal < computedMin) {
451  computedMin = propVal;
452  }
453  else if (propVal > computedMax) {
454  computedMax = propVal;
455  }
456  }
457  prop->MinimumValue.push_back(computedMin);
458  prop->MaximumValue.push_back(computedMax);
459  }
460  }
461  }
462  };
463 }
ContinuousProperty(gsoap_resqml2_0_1::eml20__DataObjectReference *partialObject)
Definition: ContinuousProperty.h:71
virtual ~ContinuousProperty()
Definition: ContinuousProperty.h:133
Definition: AbstractValuesProperty.h:41
Definition: PropertyKind.h:40
Definition: ContinuousProperty.h:44
virtual std::string getXmlTag() const
Definition: ContinuousProperty.h:136
Definition: EpcDocument.h:78
Definition: AbstractRepresentation.h:44
Definition: EpcDocument.h:62
Definition: AbstractHdfProxy.h:45
ContinuousProperty()
Definition: ContinuousProperty.h:51
ContinuousProperty(gsoap_resqml2_0_1::_resqml2__ContinuousProperty *fromGsoap)
Definition: ContinuousProperty.h:128