OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
util.hpp
1 /*
2  * util.hpp
3  *
4  * Created on: May 7, 2015
5  * Author: Pietro Incardona
6  */
7 
8 #include "config.h"
9 
10 #include "util/SimpleRNG.hpp"
11 
12 #ifndef UTIL_HPP_
13 #define UTIL_HPP_
14 
15 #include <boost/iostreams/device/mapped_file.hpp>
16 
17 
26 static inline bool compare(std::string file1, std::string file2)
27 {
28  boost::iostreams::mapped_file_source f1(file1);
29  boost::iostreams::mapped_file_source f2(file2);
30 
31  if( f1.size() == f2.size() && std::equal(f1.data(), f1.data() + f1.size(), f2.data()) )
32  return true;
33  else
34  return false;
35 }
36 
38 struct RGB
39 {
41  float R;
42 
44  float G;
45 
47  float B;
48 
50  std::string toString()
51  {
52  return std::to_string(R) + " " + std::to_string(G) + " " + std::to_string(B);
53  }
54 };
55 
77 static inline struct RGB getColor(int group, SimpleRNG & d)
78 {
79  struct RGB col;
80 
81  float s = (float)d.GetUniform();
82 
83  group = group % 12;
84 
85 #ifdef ON_IO_UNIT_TESTS
86  s = 0.5;
87 #endif
88 
89  if (group == 0)
90  {
91  col.R = s/2 + 0.5;
92  col.G = 0.0;
93  col.B = 0.0;
94  }
95  else if (group == 1)
96  {
97  col.R = 0.0;
98  col.G = s/2 + 0.5;
99  col.B = 0.0;
100  }
101  else if (group == 2)
102  {
103  col.R = 0.0;
104  col.G = 0.0;
105  col.B = s;
106  }
107  else if (group == 3)
108  {
109  col.R = s/2 + 0.5;
110  col.G = s/2 + 0.5;
111  col.B = 0.0;
112  }
113  else if (group == 4)
114  {
115  col.R = s/2 + 0.5;
116  col.G = 0.0;
117  col.B = s/2 + 0.5;
118  }
119  else if (group == 5)
120  {
121  col.R = 0.0;
122  col.G = s/2 + 0.5;
123  col.B = s/2 + 0.5;
124  }
125  else if (group == 6)
126  {
127  col.R = s/2 + 0.5;
128  col.G = s/4 + 0.5;
129  col.B = 0.0;
130  }
131  else if (group == 7)
132  {
133  col.R = s/4 + 0.5;
134  col.G = s/2 + 0.5;
135  col.B = 0.0;
136  }
137  else if (group == 8)
138  {
139  col.R = 0.0;
140  col.G = s/2 + 0.5;
141  col.B = s/4 + 0.5;
142  }
143  else if (group == 9)
144  {
145  col.R = 0.0;
146  col.G = s/4 + 0.5;
147  col.B = s/2 + 0.5;
148  }
149  else if (group == 10)
150  {
151  col.R = s/4 + 0.5;
152  col.G = 0.0;
153  col.B = s/2 + 0.5;
154  }
155  else
156  {
157  col.R = s/2 + 0.5;
158  col.G = 0.0;
159  col.B = s/4 + 0.5;
160  }
161 
162  return col;
163 }
164 
171 static inline bool hasEnding (std::string const &fullString, std::string const &ending)
172 {
173  if (fullString.length() >= ending.length())
174  {return (0 == fullString.compare (fullString.length() - ending.length(), ending.length(), ending));}
175  else
176  {return false;}
177 }
178 
179 #endif /* UTIL_HPP_ */
float B
Blue.
Definition: util.hpp:47
std::string toString()
Return the color as string.
Definition: util.hpp:50
SimpleRNG is a simple random number generator based on George Marsaglia's MWC (multiply with carry) g...
Definition: SimpleRNG.hpp:18
float R
Red.
Definition: util.hpp:41
RGB color struct.
Definition: util.hpp:38
float G
Green.
Definition: util.hpp:44