GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
ExportMethodT.hpp
Go to the documentation of this file.
1 // This file is part of GranOO, a workbench for DEM simulation.
2 //
3 // Author(s) : - Damien Andre IRCER/UNILIM, Limoges France
4 // <damien.andre@unilim.fr>
5 // - Jean-luc Charles Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
6 // <jean-luc.charles@ensam.eu>
7 // - Jeremie Girardot Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
8 // <jeremie.girardot@ensam.eu>
9 // - Cedric Hubert LAMIH/UPHF, Valenciennes France
10 // <cedric.hubert@uphf.fr>
11 // - Ivan Iordanoff Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
12 // <ivan.iordanoff@ensam.eu>
13 //
14 // Copyright (C) 2008-2019 D. Andre, JL. Charles, J. Girardot, C. Hubert, I. Iordanoff
15 //
16 // This program is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 // This program is distributed in the hope that it will be useful,
22 // but WITHOUT ANY WARRANTY; without even the implied warranty of
23 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 // GNU General Public License for more details.
25 //
26 // You should have received a copy of the GNU General Public License
27 // along with this program. If not, see <http://www.gnu.org/licenses/>.
28 
29 
30 #ifndef _libCore_ExportMethodT_hpp_
31 #define _libCore_ExportMethodT_hpp_
32 
33 #include <limits>
34 
36 #include "GranOO3/Core/SetOf.hpp"
37 #include "GranOO3/Core/Null.hpp"
38 
39 namespace GranOO3
40 {
41  namespace Core
42  {
43 
44  template<class T>
45  class ExportMethodT : public ExportMethod
46  {
47  public:
48  ExportMethodT(const std::string& key,
49  const std::string& unit,
50  const std::function<double ()>& function,
51  T*& item);
53 
54  void update_min_max();
55  void update_min();
56  void update_max();
57  void scan_and_apply_color();
59 
60  private:
61  T*& item_;
63  };
64 
65  template<class T>
66  ExportMethodT<T>::ExportMethodT(const std::string& key,
67  const std::string& unit,
68  const std::function<double ()>& function,
69  T*& item)
70  : ExportMethod(key, unit, function),
71  item_(item),
72  _set(&Core::SetOf<T>::get_global_set()) {
73  }
74 
75  template<class T>
77  }
78 
79  template<class T>
80  void
84  for (unsigned int i = 0; i<_set->size(); ++i) {
85  item_ = _set->get_item_by_rank(i);
86  const double value = function_();
87  min_ = value < min_ ? value : min_;
88  max_ = value > max_ ? value : max_;
89  }
90  }
91 
92  template<class T>
93  void
96  for (unsigned int i = 0; i<_set->size(); ++i) {
97  item_ = _set->get_item_by_rank(i);
98  const double value = function_();
99  min_ = value < min_ ? value : min_;
100  }
101  }
102 
103  template<class T>
104  void
107  for (unsigned int i = 0; i<_set->size(); ++i) {
108  item_ = _set->get_item_by_rank(i);
109  const double value = function_();
110  max_ = value > max_ ? value : max_;
111  }
112  }
113 
114  template<class T>
115  void
117  for (unsigned int i = 0; i<_set->size(); ++i) {
118  item_ = _set->get_item_by_rank(i);
119  Core::Color color;
120  apply_color(function_(), color);
121  item_->set_color(color);
122  }
123  }
124 
125  template<class T>
126  void
128  for (unsigned int i = 0; i<_set->size(); ++i) {
129  item_ = _set->get_item_by_rank(i);
130  float& lineWidth = item_->get_line_width();
131  apply_line_width(function_(), lineWidth);
132  }
133  }
134 
135  template<>
136  class ExportMethodT<Core::Null> : public ExportMethod
137  {
138  public:
139  ExportMethodT() : ExportMethod("null", "", std::function<double ()>()) {
140  }
141 
143  }
144 
145  void update_min_max() {
146  }
147 
148  void update_min() {
149  }
150 
151  void update_max() {
152  }
153 
155  }
156 
158  }
159 
160  };
161 
162  }
163 }
164 
165 #endif
Definition: Color.hpp:44
Definition: ExportMethod.hpp:46
void update_max()
Definition: ExportMethodT.hpp:151
ExportMethodT()
Definition: ExportMethodT.hpp:139
void update_min()
Definition: ExportMethodT.hpp:148
void update_min_max()
Definition: ExportMethodT.hpp:145
void scan_and_apply_line_width()
Definition: ExportMethodT.hpp:157
~ExportMethodT()
Definition: ExportMethodT.hpp:142
void scan_and_apply_color()
Definition: ExportMethodT.hpp:154
Definition: ExportMethodT.hpp:46
void scan_and_apply_line_width()
Definition: ExportMethodT.hpp:127
void update_min()
Definition: ExportMethodT.hpp:94
void update_min_max()
Definition: ExportMethodT.hpp:81
Core::SetOf< T > * _set
Definition: ExportMethodT.hpp:62
T *& item_
Definition: ExportMethodT.hpp:61
~ExportMethodT()
Definition: ExportMethodT.hpp:76
ExportMethodT(const std::string &key, const std::string &unit, const std::function< double()> &function, T *&item)
Definition: ExportMethodT.hpp:66
void update_max()
Definition: ExportMethodT.hpp:105
void scan_and_apply_color()
Definition: ExportMethodT.hpp:116
Definition: Null.hpp:47
Definition: Common.hpp:198
T min(const T v0, const T v1)
Definition: Exprtk.hpp:1456
T max(const T v0, const T v1)
Definition: Exprtk.hpp:1463
T value(details::expression_node< T > *n)
Definition: Exprtk.hpp:15070