SimpleFastOpenAtomicVisualiser
Loading...
Searching...
No Matches
atom.h
Go to the documentation of this file.
1#ifndef ATOM_H
2#define ATOM_H
3
4#include <cstdint>
5#include <iostream>
6#include <set>
7#include <vector>
8#include <map>
9
10#include <glm/glm.hpp>
11
12#include <element.h>
13#include <colour.h>
14
19class Atom
20{
21public:
22
34 (
36 glm::vec3 position = glm::vec3(0),
37 float scale = 1.0f,
38 glm::vec4 colour = glm::vec4(1.0, 0.5, 0.5, 1.0),
39 glm::vec3 velocity = glm::vec3(0),
40 glm::vec3 force = glm::vec3(0)
41 )
42 :
45 scale(scale),
49 {}
50
61 (
62 glm::vec3 position = glm::vec3(0),
63 float scale = 1.0f,
64 glm::vec4 colour = glm::vec4(1.0, 0.5, 0.5, 1.0),
65 glm::vec3 velocity = glm::vec3(0),
66 glm::vec3 force = glm::vec3(0)
67 ) : Atom(
70 scale,
71 colour,
73 force
74 )
75 {}
76
78 glm::vec3 position;
79 float scale;
80 glm::vec4 colour;
81 glm::vec3 velocity;
82 glm::vec3 force;
83
84private:
85};
86
95std::ostream & operator <<(std::ostream & o, Atom & atom)
96{
97 return o << atom.symbol << ": " << atom.position;
98}
99
106glm::vec3 getCenter(const std::vector<Atom> & atoms)
107{
108 glm::vec3 com = glm::vec3(0);
109 for (const auto & atom : atoms)
110 {
111 com += atom.position;
112 }
113 return com / float(atoms.size());
114}
115
121void center(std::vector<Atom> & atoms)
122{
123 glm::vec3 com = getCenter(atoms);
124 for (auto & atom : atoms)
125 {
126 atom.position -= com;
127 }
128}
129
136void centerOn(std::vector<Atom> & atoms, uint64_t index)
137{
138 center(atoms);
139 glm::vec3 pos = atoms[index].position;
140 for (auto & atom : atoms)
141 {
142 atom.position -= pos;
143 }
144}
145
146void translate(std::vector<Atom> & atoms, glm::vec3 r)
147{
148 for (auto & atom : atoms) { atom.position += r; }
149}
150
157glm::vec3 min(const std::vector<Atom> & atoms)
158{
159 glm::vec3 min = glm::vec3(std::numeric_limits<float>::max());
160 for (const auto & atom : atoms)
161 {
162 for (uint8_t i = 0; i < 3; i++)
163 {
164 min[i] = std::min(min[i], atom.position[i]);
165 }
166 }
167 return min;
168}
169
176glm::vec3 max(const std::vector<Atom> & atoms)
177{
178 glm::vec3 max = glm::vec3(-std::numeric_limits<float>::max());
179 for (const auto & atom : atoms)
180 {
181 for (uint8_t i = 0; i < 3; i++)
182 {
183 max[i] = std::max(max[i], atom.position[i]);
184 }
185 }
186 return max;
187}
188
195glm::vec3 extent(const std::vector<Atom> & atoms)
196{
197 glm::vec3 min = glm::vec3(std::numeric_limits<float>::max());
198 glm::vec3 max = glm::vec3(-std::numeric_limits<float>::max());
199 for (const auto & atom : atoms)
200 {
201 for (uint8_t i = 0; i < 3; i++)
202 {
203 min[i] = std::min(min[i], atom.position[i]);
204 max[i] = std::max(max[i], atom.position[i]);
205 }
206 }
207 return max-min;
208}
209
216std::set<Element> uniqueElements(const std::vector<Atom> & atoms)
217{
218 std::set<Element> e;
219 for (const auto & atom : atoms)
220 {
221 e.insert(atom.symbol);
222 }
223 return e;
224}
225
232float largest(const std::vector<Atom> & atoms)
233{
234 float r = -std::numeric_limits<float>::max();
235 for (const auto & atom : atoms)
236 {
237 r = std::max(r, atom.scale);
238 }
239 return r;
240}
241
248std::multimap<Element, uint64_t> elementIndices(const std::vector<Atom> & atoms)
249{
250 std::multimap<Element, uint64_t> m;
251 for (uint64_t i = 0; i < atoms.size(); i++)
252 {
253 m.insert(std::pair(atoms[i].symbol, i));
254 }
255 return m;
256}
257
265(
266 std::vector<Atom> & atoms,
267 const std::map<uint64_t, glm::vec4> & colours
268)
269{
270 for (const auto & ic : colours)
271 {
272 atoms[ic.first].colour = ic.second;
273 }
274}
275
283(
284 std::vector<Atom> & atoms,
285 const std::vector<float> sizes
286)
287{
288 for (uint64_t i = 0; i < sizes.size(); i++)
289 {
290 atoms[i].scale = sizes[i];
291 }
292}
293
294#endif /* ATOM_H */
void applySizes(std::vector< Atom > &atoms, const std::vector< float > sizes)
Apply sizes by index.
Definition atom.h:283
void center(std::vector< Atom > &atoms)
Subtract the centre of mass of some Atoms.
Definition atom.h:121
glm::vec3 getCenter(const std::vector< Atom > &atoms)
Calculate the centre of mass.
Definition atom.h:106
void centerOn(std::vector< Atom > &atoms, uint64_t index)
Centre on a particular Atom.
Definition atom.h:136
void applyColours(std::vector< Atom > &atoms, const std::map< uint64_t, glm::vec4 > &colours)
Apply colours by index.
Definition atom.h:265
std::multimap< Element, uint64_t > elementIndices(const std::vector< Atom > &atoms)
Obtain indices of each element.
Definition atom.h:248
std::set< Element > uniqueElements(const std::vector< Atom > &atoms)
Determine the unique elements in a list of Atom.
Definition atom.h:216
glm::vec3 max(const std::vector< Atom > &atoms)
Calculate the maximum positions of some Atoms.
Definition atom.h:176
glm::vec3 extent(const std::vector< Atom > &atoms)
Calculate the extent of some Atoms.
Definition atom.h:195
glm::vec3 min(const std::vector< Atom > &atoms)
Calculate the minimum positions of some Atoms.
Definition atom.h:157
float largest(const std::vector< Atom > &atoms)
Calculate the largest Atom.
Definition atom.h:232
void translate(std::vector< Atom > &atoms, glm::vec3 r)
Definition atom.h:146
std::ostream & operator<<(std::ostream &o, Atom &atom)
Print an atom to std::ostream.
Definition atom.h:95
An atom structure.
Definition atom.h:20
glm::vec3 force
Definition atom.h:82
Element symbol
Definition atom.h:77
glm::vec3 position
Definition atom.h:78
float scale
Definition atom.h:79
glm::vec3 velocity
Definition atom.h:81
Atom(glm::vec3 position=glm::vec3(0), float scale=1.0f, glm::vec4 colour=glm::vec4(1.0, 0.5, 0.5, 1.0), glm::vec3 velocity=glm::vec3(0), glm::vec3 force=glm::vec3(0))
Construct a Atom of unknown Element type.
Definition atom.h:61
Atom(Element symbol, glm::vec3 position=glm::vec3(0), float scale=1.0f, glm::vec4 colour=glm::vec4(1.0, 0.5, 0.5, 1.0), glm::vec3 velocity=glm::vec3(0), glm::vec3 force=glm::vec3(0))
Construct a Atom of a given Element.
Definition atom.h:34
glm::vec4 colour
Definition atom.h:80
Element
Representable elements.
Definition element.h:13