Commit 432c010b authored by Jens Petit's avatar Jens Petit Committed by Tobias Lasser
Browse files

#32 fix warnings and clang-tidy issues everywhere

parent 47915505
Pipeline #191720 passed with stages
in 7 minutes and 59 seconds
......@@ -61,7 +61,8 @@ namespace elsa
}
template <typename data_t>
LinearOperator<data_t> Quadric<data_t>::getHessianImpl(const DataContainer<data_t>& Rx)
LinearOperator<data_t>
Quadric<data_t>::getHessianImpl([[maybe_unused]] const DataContainer<data_t>& Rx)
{
if (_linearResidual.hasOperator())
return leaf(_linearResidual.getOperator());
......
......@@ -48,7 +48,7 @@ namespace elsa
template <typename data_t>
LinearOperator<data_t>
WeightedL2NormPow2<data_t>::getHessianImpl(const DataContainer<data_t>& Rx)
WeightedL2NormPow2<data_t>::getHessianImpl([[maybe_unused]] const DataContainer<data_t>& Rx)
{
return leaf(*_weightingOp);
}
......
......@@ -66,10 +66,10 @@ SCENARIO("Testing the Huber norm functional")
for (index_t i = 0; i < dataVec.size(); ++i) {
real_t value = dataVec[i];
if (std::abs(value) <= delta) {
trueValue += 0.5 * value * value;
trueValue += 0.5f * value * value;
trueGrad[i] = value;
} else {
trueValue += delta * (std::abs(value) - 0.5 * delta);
trueValue += delta * (std::abs(value) - 0.5f * delta);
trueGrad[i] = (value > 0) ? delta : -delta;
}
}
......@@ -136,10 +136,10 @@ SCENARIO("Testing the Huber norm functional")
for (index_t i = 0; i < dataVec.size(); ++i) {
real_t value = dataVec[i] - randomData[i];
if (std::abs(value) <= delta) {
trueValue += 0.5 * value * value;
trueValue += 0.5f * value * value;
trueGrad[i] = value;
} else {
trueValue += delta * (std::abs(value) - 0.5 * delta);
trueValue += delta * (std::abs(value) - 0.5f * delta);
trueGrad[i] = (value > 0) ? delta : -delta;
}
}
......
......@@ -24,12 +24,14 @@ public:
}
protected:
void applyImpl(const DataContainer<data_t>& x, DataContainer<data_t>& Ax) const override
void applyImpl([[maybe_unused]] const DataContainer<data_t>& x,
DataContainer<data_t>& Ax) const override
{
Ax = 1;
}
void applyAdjointImpl(const DataContainer<data_t>& y, DataContainer<data_t>& Aty) const override
void applyAdjointImpl([[maybe_unused]] const DataContainer<data_t>& y,
DataContainer<data_t>& Aty) const override
{
Aty = 3;
}
......
......@@ -38,7 +38,7 @@ namespace elsa
real_t angleIncrement = static_cast<real_t>(1.0) * arcDegrees / (numberOfPoses - 1.0);
for (index_t i = 0; i < numberOfPoses; ++i) {
real_t angle = i * angleIncrement * pi / 180.0; // convert to radians
real_t angle = i * angleIncrement * pi_t / 180.0; // convert to radians
if (dim == 2) {
Geometry geom(sourceToCenter, centerToDetector, angle, volumeDescriptor,
sinoDescriptor);
......
......@@ -17,7 +17,7 @@ namespace elsa
"EllipseGenerator::drawFilledEllipse2d: can only work on 2d DataContainers");
// convert to radians
auto angleRad = angle * pi / 180.0;
auto angleRad = angle * pi<double> / 180.0;
// special case: circle or no rotation
if (sizes[0] == sizes[1] || std::fmod(angle, 180.0) == 0) {
......@@ -55,9 +55,9 @@ namespace elsa
bool hasRotation = (std::abs(phi) + std::abs(theta) + std::abs(psi)) > 0;
// convert to radians
auto phiRad = phi * pi / 180.0;
auto thetaRad = theta * pi / 180.0;
auto psiRad = psi * pi / 180.0;
auto phiRad = phi * pi<double> / 180.0;
auto thetaRad = theta * pi<double> / 180.0;
auto psiRad = psi * pi<double> / 180.0;
auto cosPhi = std::cos(phiRad);
auto sinPhi = std::sin(phiRad);
......
......@@ -41,9 +41,9 @@ SCENARIO("Create a Circular Trajectory")
const real_t sourceToCenter = diffCenterSource;
const real_t centerToDetector = diffCenterDetector;
real_t angle = (1.0 / (numberOfAngles - 1)) * halfCircular;
real_t angle = (1.0f / (numberOfAngles - 1)) * halfCircular;
for (int i = 0; i < numberOfAngles; ++i) {
real_t currAngle = i * angle * pi / 180.0;
real_t currAngle = i * angle * pi_t / 180.0f;
Geometry tmpGeom(sourceToCenter, centerToDetector, currAngle, desc, *sdesc);
REQUIRE((tmpGeom.getCameraCenter() - geomList[i].getCameraCenter()).norm()
......@@ -76,7 +76,7 @@ SCENARIO("Create a Circular Trajectory")
real_t angle = (1.0 / (numberOfAngles - 1)) * halfCircular;
for (int i = 0; i < numberOfAngles; ++i) {
real_t currAngle = i * angle * pi / 180.0;
real_t currAngle = i * angle * pi_t / 180.0;
Geometry tmpGeom(sourceToCenter, centerToDetector, currAngle, desc, *sdesc);
REQUIRE((tmpGeom.getCameraCenter() - geomList[i].getCameraCenter()).norm()
......@@ -117,7 +117,7 @@ SCENARIO("Create a Circular Trajectory")
real_t angleInc = 1.0 * halfCircular / (numberOfAngles - 1);
for (int i = 0; i < numberOfAngles; ++i) {
real_t angle = i * angleInc * pi / 180.0;
real_t angle = i * angleInc * pi_t / 180.0;
Geometry tmpGeom(sourceToCenter, centerToDetector, desc, *sdesc, angle);
REQUIRE((tmpGeom.getCameraCenter() - geomList[i].getCameraCenter()).norm()
......@@ -150,7 +150,7 @@ SCENARIO("Create a Circular Trajectory")
real_t angleInc = 1.0 * halfCircular / (numberOfAngles - 1);
for (int i = 0; i < numberOfAngles; ++i) {
real_t angle = i * angleInc * pi / 180.0;
real_t angle = i * angleInc * pi_t / 180.0;
Geometry tmpGeom(sourceToCenter, centerToDetector, desc, *sdesc, angle);
REQUIRE((tmpGeom.getCameraCenter() - geomList[i].getCameraCenter()).norm()
......
......@@ -11,6 +11,8 @@
using namespace elsa;
static constexpr auto pi_d = pi<double>;
SCENARIO("Drawing a rotated filled ellipse in 2d")
{
GIVEN("a volume and example ellipse parameters")
......@@ -29,7 +31,7 @@ SCENARIO("Drawing a rotated filled ellipse in 2d")
{
// check a few rotation angles
for (real_t angleDeg : {0, 18, 30, 45, 60, 72, 90}) {
real_t angleRad = angleDeg * pi / 180.0;
real_t angleRad = angleDeg * pi_d / 180.0;
dc = 0;
EllipseGenerator<real_t>::drawFilledEllipse2d(dc, 1.0, center, sizes, angleDeg);
......
......@@ -79,7 +79,7 @@ namespace elsa
bool quotesSingle = false, quotesDouble = false;
std::string assignment;
while (!file.eof()) {
const char chr = file.get();
auto chr = static_cast<char>(file.get());
// abort on end-of-assignment
if (chr == ';' && !(quotesSingle || quotesDouble))
......@@ -134,7 +134,7 @@ namespace elsa
dim.push_back(DataUtils::parse<index_t>(dimIt->second));
}
const std::size_t nDims = dim.size();
const auto nDims = static_cast<index_t>(dim.size());
if (nDims == 0u)
throw std::runtime_error("EDF::parseHeader: dimension information not found");
......@@ -195,17 +195,17 @@ namespace elsa
// convert size
IndexVector_t dimSizeVec(nDims);
for (index_t i = 0; i < nDims; ++i)
dimSizeVec[i] = dim[i];
dimSizeVec[i] = dim[static_cast<std::size_t>(i)];
if (dimSizeVec.prod() * DataUtils::getSizeOfDataType(dataType) != size)
throw std::runtime_error("EDF::parseHeader: size inconsistency");
// convert spacing
RealVector_t dimSpacingVec(RealVector_t::Ones(nDims));
if (!spacing.empty()) {
if (spacing.size() != nDims)
if (nDims != static_cast<index_t>(spacing.size()))
throw std::runtime_error("EDF::parseHeader: spacing inconsistency");
for (index_t i = 0; i < nDims; ++i)
dimSpacingVec[i] = spacing[i];
dimSpacingVec[i] = spacing[static_cast<std::size_t>(i)];
}
return std::make_pair(std::make_unique<DataDescriptor>(dimSizeVec, dimSpacingVec),
......@@ -226,10 +226,12 @@ namespace elsa
auto& descriptor = data.getDataDescriptor();
// write dimension and size
for (std::size_t i = 0; i < descriptor.getNumberOfDimensions(); ++i)
for (index_t i = 0; i < descriptor.getNumberOfDimensions(); ++i)
file << "Dim_" << (i + 1) << " = "
<< descriptor.getNumberOfCoefficientsPerDimension()[i] << ";\n";
file << "Size = " << descriptor.getNumberOfCoefficients() * sizeof(data_t) << ";\n";
file << "Size = "
<< descriptor.getNumberOfCoefficients() * static_cast<index_t>(sizeof(data_t))
<< ";\n";
// write spacing
file << "Spacing =";
......@@ -238,7 +240,7 @@ namespace elsa
file << ";\n";
// pad the header by adding spaces such that the header ends on a kilobyte boundary
std::size_t n = 1024;
index_t n = 1024;
while (n < (static_cast<index_t>(file.tellp()) + 3))
n += 1024;
n -= static_cast<index_t>(file.tellp()) + 3;
......@@ -252,38 +254,38 @@ namespace elsa
}
template <typename data_t>
std::string EDF::getDataTypeName(const DataContainer<data_t>& data)
std::string EDF::getDataTypeName([[maybe_unused]] const DataContainer<data_t>& data)
{
throw std::invalid_argument("EDF::getDataTypeName: invalid/unsupported data type");
}
template <>
std::string EDF::getDataTypeName(const DataContainer<int8_t>& data)
std::string EDF::getDataTypeName([[maybe_unused]] const DataContainer<int8_t>& data)
{
return "SignedByte";
}
template <>
std::string EDF::getDataTypeName(const DataContainer<uint8_t>& data)
std::string EDF::getDataTypeName([[maybe_unused]] const DataContainer<uint8_t>& data)
{
return "UnsignedByte";
}
template <>
std::string EDF::getDataTypeName(const DataContainer<int16_t>& data)
std::string EDF::getDataTypeName([[maybe_unused]] const DataContainer<int16_t>& data)
{
return "SignedShort";
}
template <>
std::string EDF::getDataTypeName(const DataContainer<uint16_t>& data)
std::string EDF::getDataTypeName([[maybe_unused]] const DataContainer<uint16_t>& data)
{
return "UnsignedShort";
}
template <>
std::string EDF::getDataTypeName(const DataContainer<float>& data)
std::string EDF::getDataTypeName([[maybe_unused]] const DataContainer<float>& data)
{
return "FloatValue";
}
template <>
std::string EDF::getDataTypeName(const DataContainer<double>& data)
std::string EDF::getDataTypeName([[maybe_unused]] const DataContainer<double>& data)
{
return "DoubleValue";
}
......
......@@ -102,7 +102,7 @@ namespace elsa
{
// check the dimensions
auto nDimsIt = properties.find("ndims");
std::size_t nDims;
index_t nDims;
if (nDimsIt != properties.end())
nDims = DataUtils::parse<index_t>(nDimsIt->second);
else
......@@ -157,7 +157,7 @@ namespace elsa
auto dimSizeIt = properties.find("dimsize");
if (dimSizeIt != properties.end()) {
dimSizeVec = DataUtils::parseVector<index_t>(dimSizeIt->second);
if (dimSizeVec.size() != nDims)
if (static_cast<index_t>(dimSizeVec.size()) != nDims)
throw std::runtime_error("MHD::parseHeader: dimension size mismatch");
} else
throw std::runtime_error("MHD::parseHeader: tag 'dim size' not found");
......@@ -167,20 +167,20 @@ namespace elsa
auto dimSpacingIt = properties.find("elementspacing");
if (dimSpacingIt != properties.end()) {
dimSpacingVec = DataUtils::parseVector<real_t>(dimSpacingIt->second);
if (dimSpacingVec.size() != nDims)
if (static_cast<index_t>(dimSpacingVec.size()) != nDims)
throw std::runtime_error("MHD::parseHeader: spacing size mismatch");
}
// convert size
IndexVector_t dimSizes(nDims);
for (index_t i = 0; i < nDims; ++i)
dimSizes[i] = dimSizeVec[i];
dimSizes[i] = dimSizeVec[static_cast<std::size_t>(i)];
// convert spacing
RealVector_t dimSpacing(RealVector_t::Ones(nDims));
if (!dimSpacingVec.empty()) {
for (index_t i = 0; i < nDims; ++i)
dimSpacing[i] = dimSpacingVec[i];
dimSpacing[i] = dimSpacingVec[static_cast<std::size_t>(i)];
}
return std::make_tuple(std::make_unique<DataDescriptor>(dimSizes, dimSpacing), rawDataPath,
......@@ -211,38 +211,38 @@ namespace elsa
}
template <typename data_t>
std::string MHD::getDataTypeName(const DataContainer<data_t>& data)
std::string MHD::getDataTypeName([[maybe_unused]] const DataContainer<data_t>& data)
{
throw std::invalid_argument("MHD::getDataTypeName: invalid/unsupported data type");
}
template <>
std::string MHD::getDataTypeName(const DataContainer<int8_t>& data)
std::string MHD::getDataTypeName([[maybe_unused]] const DataContainer<int8_t>& data)
{
return "MET_CHAR";
}
template <>
std::string MHD::getDataTypeName(const DataContainer<uint8_t>& data)
std::string MHD::getDataTypeName([[maybe_unused]] const DataContainer<uint8_t>& data)
{
return "MET_UCHAR";
}
template <>
std::string MHD::getDataTypeName(const DataContainer<int16_t>& data)
std::string MHD::getDataTypeName([[maybe_unused]] const DataContainer<int16_t>& data)
{
return "MET_SHORT";
}
template <>
std::string MHD::getDataTypeName(const DataContainer<uint16_t>& data)
std::string MHD::getDataTypeName([[maybe_unused]] const DataContainer<uint16_t>& data)
{
return "MET_USHORT";
}
template <>
std::string MHD::getDataTypeName(const DataContainer<float>& data)
std::string MHD::getDataTypeName([[maybe_unused]] const DataContainer<float>& data)
{
return "MET_FLOAT";
}
template <>
std::string MHD::getDataTypeName(const DataContainer<double>& data)
std::string MHD::getDataTypeName([[maybe_unused]] const DataContainer<double>& data)
{
return "MET_DOUBLE";
}
......
......@@ -83,8 +83,8 @@ namespace elsa
template <typename raw_data_t, typename data_t>
void DataUtils::parseRawData(std::ifstream& file, DataContainer<data_t>& data)
{
index_t sizeInElements = data.getSize();
index_t sizeInBytes = sizeInElements * sizeof(raw_data_t);
auto sizeInElements = static_cast<std::size_t>(data.getSize());
auto sizeInBytes = static_cast<index_t>(sizeInElements * sizeof(raw_data_t));
// allocate temporary storage
auto ptr = std::make_unique<raw_data_t[]>(sizeInElements);
......@@ -97,8 +97,8 @@ namespace elsa
throw std::runtime_error("DataUtils::parseRawData: failed to read sufficient data");
// perform a component-wise copy to the data container
for (index_t i = 0; i < sizeInElements; ++i)
data[i] = static_cast<data_t>(ptr[i]);
for (std::size_t i = 0; i < sizeInElements; ++i)
data[static_cast<index_t>(i)] = static_cast<data_t>(ptr[i]);
}
std::string FileSystemUtils::getAbsolutePath(std::string path, std::string base)
......
......@@ -16,8 +16,11 @@ namespace elsa
const BooleanVector_t& activeDims, DiffType type)
: LinearOperator<data_t>(domainDescriptor,
domainDescriptor), // setting range in body of constructor
_type{type},
_activeDims{activeDims},
_type{type}
_coordDiff{activeDims.size()},
_coordDelta{activeDims.size()},
_dimCounter{activeDims.size()}
{
// build the range descriptor of appropriate size
IndexVector_t coefficients(domainDescriptor.getNumberOfDimensions() + 1);
......@@ -41,14 +44,14 @@ namespace elsa
index_t deltaTmp = 1;
int count = -1;
for (index_t ic = 0; ic < this->getDomainDescriptor().getNumberOfDimensions(); ++ic) {
_coordDiff.push_back(numberOfCoefficients.head(ic).prod());
_coordDiff[ic] = numberOfCoefficients.head(ic).prod();
deltaTmp *= numberOfCoefficients[ic];
_coordDelta.push_back(deltaTmp);
_coordDelta[ic] = deltaTmp;
if (_activeDims[ic])
++count;
_dimCounter.push_back(count);
_dimCounter[ic] = count;
}
}
......@@ -109,7 +112,7 @@ namespace elsa
- IndexVector_t::Ones(this->getRangeDescriptor().getNumberOfDimensions());
#pragma omp parallel
for (int currDim = 0; currDim < numDim; ++currDim) {
for (long currDim = 0; currDim < numDim; ++currDim) {
if (!_activeDims[currDim])
continue;
......@@ -159,7 +162,7 @@ namespace elsa
IndexVector_t decrementedCoefficients = numberOfCoefficients - IndexVector_t::Ones(numDim);
#pragma omp parallel
for (index_t currDim = 0; currDim < numDim; ++currDim) {
for (long currDim = 0; currDim < numDim; ++currDim) {
if (!_activeDims[currDim])
continue;
......
......@@ -90,9 +90,9 @@ namespace elsa
/// precompute some helper variables to optimize speed
void precomputeHelpers();
std::vector<index_t> _coordDiff{}; /// precomputed helper for coordinate diffs
std::vector<index_t> _coordDelta{}; /// precomputed helper for coordinate deltas
std::vector<index_t> _dimCounter{}; /// precomputed helper for active dim counter
IndexVector_t _coordDiff; /// precomputed helper for coordinate diffs
IndexVector_t _coordDelta; /// precomputed helper for coordinate deltas
IndexVector_t _dimCounter; /// precomputed helper for active dim counter
/// the actual finite differences computations (with mode as template parameter for
/// performance)
......
......@@ -158,7 +158,7 @@ namespace elsa
if (*_dataTerm != *other._dataTerm)
return false;
for (index_t i = 0; i < _regTerms.size(); ++i)
for (std::size_t i = 0; i < _regTerms.size(); ++i)
if (_regTerms.at(i) != other._regTerms.at(i))
return false;
......
......@@ -29,23 +29,18 @@ namespace elsa
}
template <typename data_t>
RegularizationTerm<data_t>::RegularizationTerm(RegularizationTerm<data_t>&& other)
RegularizationTerm<data_t>::RegularizationTerm(RegularizationTerm<data_t>&& other) noexcept
: _weight{std::move(other._weight)}, _functional{std::move(other._functional)}
{
// make sure we leave other in a valid state (since we do not check for empty pointers!)
other._functional = std::make_unique<L1Norm<data_t>>(_functional->getDomainDescriptor());
}
template <typename data_t>
RegularizationTerm<data_t>& RegularizationTerm<data_t>::
operator=(RegularizationTerm<data_t>&& other)
operator=(RegularizationTerm<data_t>&& other) noexcept
{
_weight = std::move(other._weight);
_functional = std::move(other._functional);
// make sure we leave other in a valid state (since we do not check for empty pointers!)
other._functional = std::make_unique<L1Norm<data_t>>(_functional->getDomainDescriptor());
return *this;
}
......
......@@ -37,10 +37,10 @@ namespace elsa
RegularizationTerm<data_t>& operator=(const RegularizationTerm<data_t>& other);
/// move constructor
RegularizationTerm(RegularizationTerm<data_t>&& other);
RegularizationTerm(RegularizationTerm<data_t>&& other) noexcept;
/// move assignment
RegularizationTerm<data_t>& operator=(RegularizationTerm<data_t>&& other);
RegularizationTerm<data_t>& operator=(RegularizationTerm<data_t>&& other) noexcept;
/// the default destructor
~RegularizationTerm() = default;
......
......@@ -34,7 +34,7 @@ TEMPLATE_TEST_CASE("Scenario: Testing QuadricProblem", "", QuadricProblem<float>
numCoeff << 13, 11, 7;
DataDescriptor dd{numCoeff};
data_t scaleFactor = 3.0;
auto scaleFactor = static_cast<data_t>(3.0);
Scaling<data_t> scalingOp{dd, scaleFactor};
Eigen::Matrix<data_t, -1, 1> randomData{dd.getNumberOfCoefficients()};
......@@ -501,14 +501,14 @@ TEMPLATE_TEST_CASE("Scenario: Testing QuadricProblem", "", QuadricProblem<float>
// conversion of data terms already tested, fix to 0.5*||Ax-b||^2 for tikhonov
// problem tests
data_t dataScaleFactor = 5.0;
auto dataScaleFactor = static_cast<data_t>(5.0);
Scaling<data_t> dataScalingOp{dd, dataScaleFactor};
randomData.setRandom();
DataContainer<data_t> dataB{dd, randomData};
L2NormPow2<data_t> func{LinearResidual<data_t>{dataScalingOp, dataB}};
data_t regWeight = 0.01;
auto regWeight = static_cast<data_t>(0.01);
RegularizationTerm<data_t> reg{regWeight, *regTerm};
Problem<data_t> initialProb{func, reg};
......@@ -584,14 +584,14 @@ TEMPLATE_TEST_CASE("Scenario: Testing QuadricProblem", "", QuadricProblem<float>
// conversion of data terms already tested, fix to 0.5*||Ax-b||^2 for tikhonov
// problem tests
data_t dataScaleFactor = 5.0;
auto dataScaleFactor = static_cast<data_t>(5.0);
Scaling<data_t> dataScalingOp{dd, dataScaleFactor};
randomData.setRandom();
DataContainer<data_t> dataB{dd, randomData};
L2NormPow2<data_t> func{LinearResidual<data_t>{dataScalingOp, dataB}};
data_t regWeight = 0.01;
auto regWeight = static_cast<data_t>(0.01);
RegularizationTerm<data_t> reg{regWeight, *regTerm};
Problem<data_t> initialProb{func, reg, x0};
......
......@@ -37,7 +37,7 @@ SCENARIO("Testing RegularizationTerm")
numCoeff << 11, 17, 23;
DataDescriptor dd(numCoeff);
real_t weight = 3.1;
auto weight = real_t{3.1f};
L2NormPow2 functional(dd);
RegularizationTerm regTerm(weight, functional);
......
......@@ -11,8 +11,8 @@ namespace elsa
const DataDescriptor& rangeDescriptor,
const std::vector<Geometry>& geometryList)
: LinearOperator<data_t>(domainDescriptor, rangeDescriptor),
_geometryList{geometryList},
_boundingBox{domainDescriptor.getNumberOfCoefficientsPerDimension()}
_boundingBox{domainDescriptor.getNumberOfCoefficientsPerDimension()},
_geometryList{geometryList}
{
// sanity checks
auto dim = _domainDescriptor->getNumberOfDimensions();
......@@ -69,19 +69,18 @@ namespace elsa
void BinaryMethod<data_t>::traverseVolume(const DataContainer<data_t>& vector,
DataContainer<data_t>& result) const
{
index_t maxIterations{0};
if (adjoint) {
maxIterations = vector.getSize();
const index_t maxIterations = adjoint ? vector.getSize() : result.getSize();
if constexpr (adjoint) {
result = 0; // initialize volume to 0, because we are not going to hit every voxel!
} else
maxIterations = result.getSize();
}
const auto rangeDim = _rangeDescriptor->getNumberOfDimensions();
// --> loop either over every voxel that should be updated or every detector
// cell that should be calculated
#pragma omp parallel for
for (size_t rangeIndex = 0; rangeIndex < maxIterations; ++rangeIndex) {
for (index_t rangeIndex = 0; rangeIndex < maxIterations; ++rangeIndex) {
// --> get the current ray to the detector center
auto ray = computeRayToDetector(rangeIndex, rangeDim);
......@@ -89,7 +88,7 @@ namespace elsa
// --> setup traversal algorithm
TraverseAABB traverse(_boundingBox, ray);
if (!adjoint)
if constexpr (!adjoint)
result[rangeIndex] = 0;