AGX Dynamics  2.37.2.0
ParticlePostProcessColorer.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGXQT_PARTICLEPOSTPROCESSCOLORER_H
18 #define AGXQT_PARTICLEPOSTPROCESSCOLORER_H
19 
20 #include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
21 #include <osg/ref_ptr>
22 #include <agx/PopDisableWarnings.h> // End of disabled warnings.
23 
24 #include <functional>
25 #include <agxQt/export.h>
26 #include <agx/Referenced.h>
27 #include <agx/Bound.h>
28 #include <agx/ParticleSystem.h>
29 #include <agx/AnalysisBox.h>
30 #include <agxOSG/ScalarColorMap.h>
31 
32 namespace agx
33 {
34  class ParticleSystem;
35 }
36 
37 namespace agxQt
38 {
39  // Forward declaration
41 
45  typedef std::function<ParticleColorer*()> ColorerConstructor;
47  {
49  ColorerConstructor m_constructor;
51 
52  bool operator==(const ParticleColorMode& rhs) { return m_id == rhs.m_id; }
53  };
55 
61  {
62  public:
63  typedef std::function<agx::Real(agx::ParticleSystem*, agx::Physics::ParticlePtr)> GetParticleRealFunc;
64  static const char* const COLORMODE_NONE_NAME;
65 
66  public:
67  ParticleColorer(const agx::Name& name);
68 
69  virtual void colorParticles(agx::ParticleSystem * system, bool limitBound, const agx::Bound3& bound, bool modifyAlpha) = 0;
70 
71  virtual void initColorRange(agx::Real minScalar, agx::Real maxScalar);
72 
73  agxOSG::ScalarColorMap* getColorMap() const;
74 
75  agx::Name getName() const;
76 
77  protected:
78  void applyColorFromMap( agx::Vec4f& targetColorData, agx::Real scalar, bool modifyAlpha );
79 
80  protected:
81  virtual ~ParticleColorer() {};
82 
84  // Variables
86  protected:
87  agxOSG::ScalarColorMapRef m_colorMap;
89  };
90 
91  AGX_FORCE_INLINE agxOSG::ScalarColorMap* ParticleColorer::getColorMap() const { return m_colorMap; }
92 
93  AGX_FORCE_INLINE agx::Name ParticleColorer::getName() const { return m_name; }
94 
96  {
97  return ParticleColorMode{ ParticleColorer::COLORMODE_NONE_NAME, []{ return nullptr; }, "" };
98  }
99 
105  {
106  public:
108  public:
110 
111  void setMaxScalar(agx::Real maxScalar);
112 
113  void setMinScalar(agx::Real minScalar);
114 
115  agx::Real getMaxScalar() const;
116 
117  agx::Real getMinScalar() const;
118 
119  void setAnalysisBox(const agx::AnalysisBox* analysisBox);
120 
121  void setParticleColorModeFromName(const agx::String& name);
122 
123  bool particleColorModeExists(const agx::String& name);
124 
125  void addCustomColorMode(const agx::String& name, ParticleColorer::GetParticleRealFunc getRealFunc, const agx::String& unitString);
126 
127  ParticleColorMode getActiveParticleColorMode() const;
128 
129  ParticleColorModeVector getAvailableParticleColorModes();
130 
131  void colorParticles(agx::ParticleSystem * system);
132 
133  agxOSG::ScalarColorMap* getColorMap() const;
134 
135  void setEnableModifyScalarFromAlpha(bool enable);
136 
137  void setLimitInBound(bool limitInBound);
138 
139  bool getLimitInBound() const;
140 
141  protected:
142  void setParticleColorMode(ParticleColorMode mode);
143 
144  void initParticleModes();
145 
147 
148  void initColorRange();
149 
150  bool shouldLimitColorToBound() const;
151 
153  // Variables
155  protected:
161  ParticleColorModeTable m_particleColorModeTable;
163  };
164 
165  AGX_FORCE_INLINE agx::Real ParticleColorerManager::getMaxScalar() const { return m_maxScalar; }
166 
167  AGX_FORCE_INLINE agx::Real ParticleColorerManager::getMinScalar() const { return m_minScalar; }
168 
169  AGX_FORCE_INLINE void ParticleColorerManager::setMaxScalar(agx::Real maxScalar) { m_maxScalar = maxScalar; initColorRange(); }
170 
171  AGX_FORCE_INLINE void ParticleColorerManager::setMinScalar(agx::Real minScalar) { m_minScalar = minScalar; initColorRange(); }
172 
173  AGX_FORCE_INLINE void ParticleColorerManager::setAnalysisBox(const agx::AnalysisBox* analysisBox) { m_analysisBox = analysisBox; initColorRange(); }
174 
175  AGX_FORCE_INLINE void ParticleColorerManager::setLimitInBound(bool limitInBound) { m_limitInBound = limitInBound; }
176 
177  AGX_FORCE_INLINE bool ParticleColorerManager::getLimitInBound() const { return m_limitInBound; }
178 
179  AGX_FORCE_INLINE void ParticleColorerManager::setEnableModifyScalarFromAlpha(bool enable) { m_modifyAlphaFromScalar = enable; }
180 
185  {
186  public:
188 
189  virtual void colorParticles(agx::ParticleSystem * system, bool limitBound, const agx::Bound3& bound, bool modifyAlpha) override;
190 
191  protected:
193  };
194 
199  {
200  public:
202 
203  virtual void colorParticles(agx::ParticleSystem * system, bool limitBound, const agx::Bound3& bound, bool modifyAlpha) override;
204 
205  protected:
207  };
208 
213  {
214  public:
215  ParticlePostPorcessColorerHeight(const agx::Name& name, const agx::Vec3& heightAxis = agx::Vec3::Z_AXIS());
216 
217  virtual void colorParticles(agx::ParticleSystem * system, bool limitBound, const agx::Bound3& bound, bool modifyAlpha) override;
218 
219  protected:
221  agx::Vec3 m_heightAxis;
222  };
223 
228  {
229  public:
231 
232  virtual void colorParticles(agx::ParticleSystem * system, bool limitBound, const agx::Bound3& bound, bool modifyAlpha) override;
233 
234  protected:
236  };
237 
242  {
243  public:
245 
246  virtual void colorParticles(agx::ParticleSystem * system, bool limitBound, const agx::Bound3& bound, bool modifyAlpha) override;
247 
248  protected:
250 
252  // Variables
254  protected:
255  bool m_shouldResetPostions;
257  };
258 
263  {
264  public:
266 
267  virtual void colorParticles(agx::ParticleSystem * system, bool limitBound, const agx::Bound3& bound, bool modifyAlpha) override;
268 
269  protected:
271 
273  // Variables
275  protected:
276  };
277 
282  {
283  public:
285 
286  virtual void colorParticles(agx::ParticleSystem * system, bool limitBound, const agx::Bound3& bound, bool modifyAlpha) override;
287 
288  protected:
290 
292  // Variables
294  protected:
295  GetParticleRealFunc m_getRealFunc;
296  };
297 }
298 
299 #endif
Implements the particle post processor colorer for contact force.
#define AGXQT_EXPORT
Implements the particle post processor colorer for contact force.
std::function< agx::Real(agx::ParticleSystem *, agx::Physics::ParticlePtr)> GetParticleRealFunc
A class holding 4 dimensional vectors and providing basic arithmetic.
Definition: Vec4Template.h:34
Implements the particle post processor colorer for velocities.
Contains classes/utility functions for connecting AGX to QT with OSG.
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
bool operator==(const ParticleColorMode &rhs)
Representation of a name string.
Definition: Name.h:32
#define AGX_FORCE_INLINE
Definition: Object.h:59
ParticleColorMode AGXQT_EXPORT createNoneParticleColorMode()
Base class providing referencing counted objects.
Definition: Referenced.h:119
static Vec3T Z_AXIS()
Definition: Vec3Template.h:783
Implements the particle post processor colorer for contact force.
A basic particle system that contains all the storages and buffers required for basic operation and a...
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
std::function< ParticleColorer *()> ColorerConstructor
ParticleColorMode.
Implements the particle post processor colorer for velocities.
agx::HashTable< agx::Index, agx::Vec3 > m_particleIdToPosition
static const char *const COLORMODE_NONE_NAME
Class that can be used to extract data from elements in a simulation within a specified bound...
Definition: AnalysisBox.h:31
Implements the particle post processor colorer for velocities.
ParticleColorModeTable m_particleColorModeTable
Implements the particle post processor colorer for velocities.
agx::HashTable< agx::Name, ParticleColorMode > ParticleColorModeTable
double Real
Definition: Real.h:42
Class that represents a linear scalar color map that converts a scalar interval to a specified color ...
agx::Vector< ParticleColorMode > ParticleColorModeVector
Inheritance with partial specialization due to bug with ref_ptr containers.