Skip to content

Commit 10fe707

Browse files
authored
Merge pull request #174 from AdaptiveParticles/developKrzysztof
PixelDataDim structure
2 parents ac82b06 + b0a0d43 commit 10fe707

File tree

3 files changed

+100
-2
lines changed

3 files changed

+100
-2
lines changed

src/data_structures/Mesh/PixelData.hpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,39 @@
2929
#include "misc/CudaMemory.cuh"
3030
#endif
3131

32+
struct PixelDataDim {
33+
size_t y;
34+
size_t x;
35+
size_t z;
36+
37+
PixelDataDim(size_t y, size_t x, size_t z) : y(y), x(x), z(z) {}
38+
39+
size_t size() const { return y * x * z; }
40+
41+
PixelDataDim operator+(const PixelDataDim &rhs) const { return {y + rhs.y, x + rhs.x, z + rhs.z}; }
42+
PixelDataDim operator-(const PixelDataDim &rhs) const { return {y - rhs.y, x - rhs.x, z - rhs.z}; }
43+
44+
template<typename INTEGER>
45+
constexpr typename std::enable_if<std::is_integral<INTEGER>::value, PixelDataDim>::type
46+
operator+(INTEGER i) const { return {y + i, x + i, z + i}; }
47+
48+
template<typename INTEGER>
49+
constexpr typename std::enable_if<std::is_integral<INTEGER>::value, PixelDataDim>::type
50+
operator-(INTEGER i) const { return *this + (-i); }
51+
52+
friend bool operator==(const PixelDataDim& lhs, const PixelDataDim& rhs) {
53+
return (lhs.x == rhs.x) && (lhs.y == rhs.y) && (lhs.z == rhs.z);
54+
}
55+
friend bool operator!=(const PixelDataDim& lhs, const PixelDataDim& rhs) {
56+
return !(lhs == rhs);
57+
}
58+
59+
friend std::ostream &operator<<(std::ostream &os, const PixelDataDim &obj) {
60+
os << "{" << obj.y << ", " << obj.x << ", " << obj.z << "}";
61+
return os;
62+
}
63+
};
64+
3265
template <typename T>
3366
class ArrayWrapper
3467
{
@@ -438,6 +471,13 @@ public :
438471
if (aShouldCopyData) std::copy(aMesh.mesh.begin(), aMesh.mesh.end(), mesh.begin());
439472
}
440473

474+
/**
475+
* Returns dimensions of PixelData
476+
*/
477+
PixelDataDim getDimension() const {
478+
return {static_cast<size_t>(y_num), static_cast<size_t>(x_num), static_cast<size_t>(z_num)};
479+
}
480+
441481
/**
442482
* Creates copy of this mesh converting each element to new type
443483
* @tparam U new type of mesh

test/MeshDataTest.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,64 @@ namespace {
2424
VectorData<MESH_TYPE> m;
2525
};
2626

27+
TEST(MeshDataSimpleTest, PixelDataDimTest) {
28+
// size provided
29+
{
30+
PixelData<int> md(10, 20, 30);
31+
auto d = md.getDimension();
32+
33+
ASSERT_EQ(d.y, 10);
34+
ASSERT_EQ(d.x, 20);
35+
ASSERT_EQ(d.z, 30);
36+
ASSERT_EQ(d.size(), 10*20*30);
37+
}
38+
{ // adding int to all dims
39+
40+
PixelDataDim x = {1,2,3};
41+
auto d = x + 1;
42+
ASSERT_EQ(d.y, 2);
43+
ASSERT_EQ(d.x, 3);
44+
ASSERT_EQ(d.z, 4);
45+
}
46+
{ // subtract int from all dims
47+
48+
const PixelDataDim x = {1,2,3};
49+
auto d = x - 1;
50+
ASSERT_EQ(d.y, 0);
51+
ASSERT_EQ(d.x, 1);
52+
ASSERT_EQ(d.z, 2);
53+
}
54+
{ // adding another PixelDataDim
55+
56+
PixelDataDim x = {1,2,3};
57+
const PixelDataDim y = {5, 10, 15};
58+
auto d = x + y;
59+
ASSERT_EQ(d.y, 6);
60+
ASSERT_EQ(d.x, 12);
61+
ASSERT_EQ(d.z, 18);
62+
}
63+
{ // subtract another PixelDataDim
64+
65+
const PixelDataDim x = {5, 10, 15};
66+
PixelDataDim y = {1, 2, 3};
67+
auto d = x - y;
68+
ASSERT_EQ(d.y, 4);
69+
ASSERT_EQ(d.x, 8);
70+
ASSERT_EQ(d.z, 12);
71+
}
72+
{ // compare two PixelDataDim structures
73+
const PixelDataDim x = {2, 3, 5};
74+
const PixelDataDim y = {2, 3, 5};
75+
const PixelDataDim z = {3, 4, 5};
76+
77+
ASSERT_TRUE(x == y);
78+
ASSERT_FALSE(x != y);
79+
80+
ASSERT_FALSE(x == z);
81+
ASSERT_TRUE(x != z);
82+
}
83+
}
84+
2785
TEST_F(VectorDataTest, InitTest) {
2886
// Check initialize and resize and size are working correctly
2987

test/TestTools.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ inline int compareMeshes(const PixelData<T> &expected, const PixelData<T> &teste
8181

8282

8383
template <typename T>
84-
inline size_t compareParticles(const ParticleData<T> &expected, const ParticleData<T> &tested, double maxError = 0.0001, int maxNumOfErrPrinted = 10) {
85-
size_t cnt = 0;
84+
inline int64_t compareParticles(const ParticleData<T> &expected, const ParticleData<T> &tested, double maxError = 0.0001, int maxNumOfErrPrinted = 10) {
85+
int64_t cnt = 0;
8686
if(expected.size() != tested.size()) {
8787
std::cerr << "ERROR compareParticles: sizes differ!" << std::endl;
8888
cnt++;

0 commit comments

Comments
 (0)