-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
234 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/******************************************************************************************** | ||
* Copyright (C) 2024 'Yet Another Gamma Index Tool' Developers. | ||
* | ||
* This file is part of 'Yet Another Gamma Index Tool'. | ||
* | ||
* 'Yet Another Gamma Index Tool' is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* 'Yet Another Gamma Index Tool' is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with 'Yet Another Gamma Index Tool'. If not, see <http://www.gnu.org/licenses/>. | ||
********************************************************************************************/ | ||
|
||
#include "yagit/Image.hpp" | ||
|
||
#include <sstream> | ||
#include <iomanip> | ||
|
||
namespace yagit{ | ||
|
||
namespace{ | ||
std::string imageNDimToString(const std::vector<float>& vector, std::streamsize precision = -1, uint32_t = 0){ | ||
std::ostringstream oss; | ||
if(precision > 0){ | ||
oss << std::fixed << std::setprecision(precision); | ||
} | ||
oss << "["; | ||
for(size_t i = 0; i < vector.size() - 1; i++){ | ||
oss << vector[i] << ", "; | ||
} | ||
oss << vector.back() << "]"; | ||
return oss.str(); | ||
} | ||
|
||
template <typename T> | ||
std::string imageNDimToString(const std::vector<T>& vector, std::streamsize precision = -1, uint32_t level = 0){ | ||
std::string spaces(level + 1, ' '); | ||
std::string res = ""; | ||
res += "["; | ||
for(size_t i = 0; i < vector.size() - 1; i++){ | ||
res += imageNDimToString(vector[i], precision, level + 1) + ",\n" + spaces; | ||
} | ||
res += imageNDimToString(vector.back(), precision, level + 1); | ||
res += "]"; | ||
return res; | ||
} | ||
} | ||
|
||
std::string image2DToString(const yagit::Image2D& img, std::streamsize precision){ | ||
return imageNDimToString(img, precision); | ||
} | ||
|
||
std::string image3DToString(const yagit::Image3D& img, std::streamsize precision){ | ||
return imageNDimToString(img, precision); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ set(TESTS_SRCS | |
GammaTest | ||
GammaCommonTest | ||
GammaResultTest | ||
ImageTest | ||
ImageDataTest | ||
InterpolationTest | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/******************************************************************************************** | ||
* Copyright (C) 2024 'Yet Another Gamma Index Tool' Developers. | ||
* | ||
* This file is part of 'Yet Another Gamma Index Tool'. | ||
* | ||
* 'Yet Another Gamma Index Tool' is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* 'Yet Another Gamma Index Tool' is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with 'Yet Another Gamma Index Tool'. If not, see <http://www.gnu.org/licenses/>. | ||
********************************************************************************************/ | ||
|
||
#include "yagit/Image.hpp" | ||
|
||
#include <limits> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
namespace{ | ||
const yagit::Image3D IMAGE = { | ||
{{1.45364, 45.578234}, | ||
{-0.34921, 999.876543}}, | ||
{{-12.74829, 43.45903}, | ||
{0, 9.999999}} | ||
}; | ||
|
||
const yagit::Image3D IMAGE_SPECIAL_VALUES = { | ||
{{std::numeric_limits<float>::quiet_NaN(), | ||
std::numeric_limits<float>::infinity(), | ||
-std::numeric_limits<float>::infinity()}} | ||
}; | ||
|
||
const yagit::Image3D IMAGE_NONUNIFORM = { | ||
{{1}, | ||
{2, 3}, | ||
{4, 5, 6}}, | ||
{{7, 8, 9, 10}} | ||
}; | ||
} | ||
|
||
TEST(ImageTest, image2DToString){ | ||
const std::string image2DStr = yagit::image2DToString(IMAGE[0]); | ||
|
||
const std::string expected = | ||
"[[1.45364, 45.5782],\n" | ||
" [-0.34921, 999.877]]"; | ||
EXPECT_EQ(expected, image2DStr); | ||
} | ||
|
||
TEST(ImageTest, image2DToStringWithPrecision){ | ||
const std::string image2DStr = yagit::image2DToString(IMAGE[0], 2); | ||
|
||
const std::string expected = | ||
"[[1.45, 45.58],\n" | ||
" [-0.35, 999.88]]"; | ||
EXPECT_EQ(expected, image2DStr); | ||
} | ||
|
||
TEST(ImageTest, image2DToStringWithNegativePrecision){ | ||
const std::string image2DStr = yagit::image2DToString(IMAGE[0], -2); | ||
|
||
const std::string expected = | ||
"[[1.45364, 45.5782],\n" | ||
" [-0.34921, 999.877]]"; | ||
EXPECT_EQ(expected, image2DStr); | ||
} | ||
|
||
TEST(ImageTest, image2DToStringForSpecialValues){ | ||
const std::string image2DStr = yagit::image2DToString(IMAGE_SPECIAL_VALUES[0]); | ||
|
||
const std::string expected = "[[nan, inf, -inf]]"; | ||
EXPECT_EQ(expected, image2DStr); | ||
} | ||
|
||
TEST(ImageTest, image2DToStringForNonuniformImage){ | ||
const std::string image2DStr = yagit::image2DToString(IMAGE_NONUNIFORM[0]); | ||
|
||
const std::string expected = | ||
"[[1],\n" | ||
" [2, 3],\n" | ||
" [4, 5, 6]]"; | ||
EXPECT_EQ(expected, image2DStr); | ||
} | ||
|
||
TEST(ImageTest, image3DToString){ | ||
const std::string image3DStr = yagit::image3DToString(IMAGE); | ||
|
||
const std::string expected = | ||
"[[[1.45364, 45.5782],\n" | ||
" [-0.34921, 999.877]],\n" | ||
" [[-12.7483, 43.459],\n" | ||
" [0, 10]]]"; | ||
EXPECT_EQ(expected, image3DStr); | ||
} | ||
|
||
TEST(ImageTest, image3DToStringWithPrecision){ | ||
const std::string image3DStr = yagit::image3DToString(IMAGE, 2); | ||
|
||
const std::string expected = | ||
"[[[1.45, 45.58],\n" | ||
" [-0.35, 999.88]],\n" | ||
" [[-12.75, 43.46],\n" | ||
" [0.00, 10.00]]]"; | ||
EXPECT_EQ(expected, image3DStr); | ||
} | ||
|
||
TEST(ImageTest, image3DToStringWithNegativePrecision){ | ||
const std::string image3DStr = yagit::image3DToString(IMAGE, -2); | ||
|
||
const std::string expected = | ||
"[[[1.45364, 45.5782],\n" | ||
" [-0.34921, 999.877]],\n" | ||
" [[-12.7483, 43.459],\n" | ||
" [0, 10]]]"; | ||
EXPECT_EQ(expected, image3DStr); | ||
} | ||
|
||
TEST(ImageTest, image3DToStringForSpecialValues){ | ||
const std::string image3DStr = yagit::image3DToString(IMAGE_SPECIAL_VALUES); | ||
|
||
const std::string expected = "[[[nan, inf, -inf]]]"; | ||
EXPECT_EQ(expected, image3DStr); | ||
} | ||
|
||
TEST(ImageTest, image3DToStringForNonuniformImage){ | ||
const std::string image3DStr = yagit::image3DToString(IMAGE_NONUNIFORM); | ||
|
||
const std::string expected = | ||
"[[[1],\n" | ||
" [2, 3],\n" | ||
" [4, 5, 6]],\n" | ||
" [[7, 8, 9, 10]]]"; | ||
EXPECT_EQ(expected, image3DStr); | ||
} |