Tissue Forge C++ 0.2.1
Interactive, particle-based physics, chemistry and biology modeling and simulation environment
Loading...
Searching...
No Matches
tfParticleEvent.h
Go to the documentation of this file.
1/*******************************************************************************
2 * This file is part of Tissue Forge.
3 * Copyright (c) 2022-2024 T.J. Sego
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 ******************************************************************************/
19
24
25#ifndef _SOURCE_EVENT_TFPARTICLEEVENT_H_
26#define _SOURCE_EVENT_TFPARTICLEEVENT_H_
27
28#include "tfEvent.h"
29#include "tfEventList.h"
30
31#include <unordered_map>
32
33
34namespace TissueForge {
35
36
37 struct ParticleHandle;
38 struct ParticleType;
39
40
41 namespace event {
42
43
44 // Particle selector function template
45 template<typename event_t> using ParticleEventParticleSelectorT = ParticleHandle* (*)(const event_t&);
46
47 // ParticleEvent
48
49 struct ParticleEvent;
50
51 using ParticleEventMethod = EventMethodT<ParticleEvent>;
52
53 using ParticleEventParticleSelector = ParticleEventParticleSelectorT<ParticleEvent>;
54
62 CAPI_FUNC(ParticleHandle*) particleSelectorUniform(const int16_t &typeId, const int32_t &nr_parts);
63
70 CAPI_FUNC(ParticleHandle*) particleSelectorLargest(const int16_t &typeId);
71
79
87
88 // keys for selecting a particle selector
89 enum class ParticleEventParticleSelectorEnum : unsigned int {
90 LARGEST,
91 UNIFORM,
92 DEFAULT
93 };
94
95 typedef std::unordered_map<ParticleEventParticleSelectorEnum, ParticleEventParticleSelector> ParticleEventParticleSelectorMapType;
96 static ParticleEventParticleSelectorMapType particleEventParticleSelectorMap {
97 {ParticleEventParticleSelectorEnum::LARGEST, &particleEventParticleSelectorLargest},
98 {ParticleEventParticleSelectorEnum::UNIFORM, &particleEventParticleSelectorUniform},
99 {ParticleEventParticleSelectorEnum::DEFAULT, &particleEventParticleSelectorUniform}
100 };
101
102 typedef std::unordered_map<std::string, ParticleEventParticleSelectorEnum> ParticleEventParticleSelectorNameMapType;
103 static ParticleEventParticleSelectorNameMapType particleEventParticleSelectorNameMap {
104 {"largest", ParticleEventParticleSelectorEnum::LARGEST},
105 {"uniform", ParticleEventParticleSelectorEnum::UNIFORM},
106 {"default", ParticleEventParticleSelectorEnum::DEFAULT}
107 };
108
115 CAPI_FUNC(ParticleEventParticleSelector*) getParticleEventParticleSelector(ParticleEventParticleSelectorEnum selectorEnum);
116
123 CAPI_FUNC(ParticleEventParticleSelector*) getParticleEventParticleSelectorN(std::string setterName);
124
125 // Particle event
126 struct CAPI_EXPORT ParticleEvent : EventBase {
127
132
137
138 ParticleEvent() {}
140 ParticleType *targetType,
141 ParticleEventMethod *invokeMethod,
142 ParticleEventMethod *predicateMethod,
143 ParticleEventParticleSelector *particleSelector=NULL
144 );
145 virtual ~ParticleEvent() {}
146
148 virtual HRESULT invoke();
149 virtual HRESULT eval(const FloatP_t &time);
150
151 HRESULT setParticleEventParticleSelector(ParticleEventParticleSelector *particleSelector);
152 HRESULT setParticleEventParticleSelector(ParticleEventParticleSelectorEnum selectorEnum);
153 HRESULT setParticleEventParticleSelector(std::string selectorName);
154
155 protected:
156
157 ParticleHandle *getNextParticle();
158
159 private:
160
161 ParticleEventMethod *invokeMethod;
162 ParticleEventMethod *predicateMethod;
163 ParticleEventParticleSelector *particleSelector;
164
165 };
166
167 // Event list for particle events
168 using ParticleEventList = EventListT<ParticleEvent>;
169
170 // Module entry points
171
181 ParticleType *targetType,
182 ParticleEventMethod *invokeMethod,
183 ParticleEventMethod *predicateMethod
184 );
185
186}};
187
188#endif // _SOURCE_EVENT_TFPARTICLEEVENT_H_
Tissue Forge event system.
Definition tfEvent.h:34
ParticleHandle * particleSelectorLargest(const int16_t &typeId)
Selects largest particle by event target type.
ParticleEventParticleSelector * getParticleEventParticleSelector(ParticleEventParticleSelectorEnum selectorEnum)
Gets the particle selector on an event.
ParticleHandle * particleEventParticleSelectorUniform(const ParticleEvent &event)
Selects a particle according to a uniform random distribution by event target type.
ParticleHandle * particleSelectorUniform(const int16_t &typeId, const int32_t &nr_parts)
Selects a particle according to a uniform random distribution by event target type.
ParticleHandle * particleEventParticleSelectorLargest(const ParticleEvent &event)
Selects largest particle by event target type.
ParticleEvent * onParticleEvent(ParticleType *targetType, ParticleEventMethod *invokeMethod, ParticleEventMethod *predicateMethod)
Creates a particle event using prescribed invoke and predicate functions.
ParticleEventParticleSelector * getParticleEventParticleSelectorN(std::string setterName)
Gets the particle selector on an event.
Include Python header, disable linking to pythonX_d.lib on Windows in debug mode.
Definition tfAngleConfig.h:26
A handle to a particle.
Definition tfParticle.h:313
Structure containing information on each particle type.
Definition tfParticle.h:768
Definition tfEventList.h:59
Definition tfParticleEvent.h:126
ParticleHandle * targetParticle
Target particle of an event evaluation.
Definition tfParticleEvent.h:136
ParticleType * targetType
Target particle type of this event.
Definition tfParticleEvent.h:131
int32_t HRESULT
Definition tf_port.h:255