Skip to content

Commit

Permalink
AM-60 Fix warnings for analyze based on cppcheck analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
ben authored and MaksymT17 committed Oct 28, 2023
1 parent 558b0e5 commit f8963b9
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 71 deletions.
2 changes: 1 addition & 1 deletion analyze/AffinityComparer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace am
class AffinityComparer : public IComparer
{
public:
AffinityComparer(common::types::Matrix<common::types::Color24b> &base);
explicit AffinityComparer(common::types::Matrix<common::types::Color24b> &base);

~AffinityComparer() = default;

Expand Down
4 changes: 2 additions & 2 deletions analyze/ThresholdDiffChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace am

ThresholdDiffChecker::ThresholdDiffChecker(const uint16_t channelTreshold) : mThreshold(channelTreshold) {}

void setThresholdChanges(size_t rowId, size_t width, Matrix<Color24bDiff> &diff,
void setThresholdChanges(size_t rowId, size_t width, const Matrix<Color24bDiff> &diff,
const uint16_t threshold, MatrixU16 &result)
{
for (std::size_t x = 0; x < width; ++x)
Expand All @@ -21,7 +21,7 @@ namespace am
}
}

void checlImageRow(size_t rowId, size_t width, Matrix<Color24bDiff> &diff,
void checlImageRow(size_t rowId, size_t width, const Matrix<Color24bDiff> &diff,
const uint16_t threshold, std::atomic_size_t &diffCounter)
{
for (std::size_t x = 0; x < width; ++x)
Expand Down
2 changes: 1 addition & 1 deletion analyze/ThresholdDiffChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace am
class ThresholdDiffChecker
{
public:
ThresholdDiffChecker(const uint16_t channelTreshold);
explicit ThresholdDiffChecker(const uint16_t channelTreshold);
~ThresholdDiffChecker() = default;

// shows persent of similarity based on diffs of two images
Expand Down
32 changes: 11 additions & 21 deletions analyze/algorithm/BfsObjectDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@ namespace am
using namespace am::common::types;
using Pixels = std::vector<Pixel>;

bool isNew(Pixels &object, size_t rowId, size_t colId) noexcept
bool isNew(const Pixels &object, size_t rowId, size_t colId) noexcept
{
for (auto &pos : object)
{
if (pos.colId == colId && pos.rowId == rowId)
return false;
}
return true;
return !std::all_of(object.cbegin(), object.cend(), [&](auto pos)
{ return (pos.colId != colId && pos.rowId != rowId); });
}

void pushCheckIfNew(Pixels &object, Pixels &toCheck, size_t rowId,
void pushCheckIfNew(const Pixels &object, Pixels &toCheck, size_t rowId,
size_t colId)
{
if (isNew(object, rowId, colId))
Expand All @@ -36,27 +32,27 @@ namespace am
}

void checkClosest(size_t rowId, size_t colId, Pixels &nextCheck, ObjectRectangle &object,
ImageRowSegment& row, const size_t width, const size_t step) noexcept
ImageRowSegment &row, const size_t width, const size_t step) noexcept
{
if (static_cast<int>(rowId - step) >= row.start)
{
//mv: commented in sake of optimization
//pushCheckIfNew(object, nextCheck, rowId - step, colId);
// mv: commented in sake of optimization
// pushCheckIfNew(object, nextCheck, rowId - step, colId);
nextCheck.emplace_back(rowId - step, colId);
}
if (rowId + step < row.end)
{
//pushCheckIfNew(object, nextCheck, rowId + step, colId);
// pushCheckIfNew(object, nextCheck, rowId + step, colId);
nextCheck.emplace_back(rowId + step, colId);
}
if (static_cast<int>(colId - step) >= 0)
{
//pushCheckIfNew(object, nextCheck, rowId, colId - step);
// pushCheckIfNew(object, nextCheck, rowId, colId - step);
nextCheck.emplace_back(rowId, colId - step);
}
if (colId + step < width)
{
//pushCheckIfNew(object, nextCheck, rowId, colId + step);
// pushCheckIfNew(object, nextCheck, rowId, colId + step);
nextCheck.emplace_back(rowId, colId + step);
}
}
Expand All @@ -77,7 +73,6 @@ namespace am
if (static_cast<int>(colId - step) >= 0)
{
toCheck.emplace_back(rowId, colId - step);

}
if (colId + step < width)
{
Expand Down Expand Up @@ -106,12 +101,7 @@ namespace am
{
std::vector<ObjectRectangle> threadObjs;

for (auto &objs : thrList)
{
// skip objects if smaller that minObjSize, avoid noise
// if (objs.size() >= mConfiguration->MinPixelsForObject)
threadObjs.emplace_back(objs);
}
std::copy(thrList.begin(), thrList.end(), std::back_inserter(threadObjs));

rects.push_back(threadObjs);
}
Expand Down
6 changes: 3 additions & 3 deletions analyze/algorithm/BfsObjectDetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace am

class ImagePair;

bool isNew(std::vector<Pixel> &object, size_t rowId, size_t colId) noexcept;
void pushCheckIfNew(std::vector<Pixel> &object, std::vector<Pixel> &toCheck, size_t rowId, size_t colId);
bool isNew(const std::vector<Pixel> &object, size_t rowId, size_t colId) noexcept;
void pushCheckIfNew(const std::vector<Pixel> &object, std::vector<Pixel> &toCheck, size_t rowId, size_t colId);
void checkClosest(size_t rowId, size_t colId, std::vector<Pixel> &nextCheck, ObjectRectangle &object, ImageRowSegment& row, const size_t width, const size_t step) noexcept;
std::vector<Pixel> checkConnections(size_t rowId, size_t colId, const size_t &width, const ImageRowSegment &col, const size_t step) noexcept;

Expand All @@ -29,7 +29,7 @@ namespace am
// DescObjects getObjectsRects(std::shared_ptr<common::types::Matrix<common::types::Color24bDiff>> diffs);

// search of ebjects within ImagePair data provided
virtual DescObjects getObjectsRects(ImagePair &pair) = 0;
virtual DescObjects getObjectsRects(ImagePair &pair) override = 0;

// creation of ordered objects list: Descending(bigger first)
DescObjects createObjectRects(std::vector<std::vector<ObjectRectangle>> &objPixels,
Expand Down
76 changes: 40 additions & 36 deletions analyze/algorithm/DiffObjectDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,64 +8,68 @@ namespace am
{
namespace analyze
{

namespace algorithm
{
using ColorDiffsMatrix = common::types::Matrix<common::types::Color24bDiff>;
using namespace am::common::types;
using Pixels = std::vector<Pixel>;

DiffObjectDetector::DiffObjectDetector(const size_t threads, std::shared_ptr<am::configuration::Configuration> &conf, std::shared_ptr<am::common::Logger> &logger) : BfsObjectDetector(threads, conf, logger)
{
}

// optimized bfs depending to left/right borders for threads,
// every thread will search in defined area(column) of image
ObjectRectangle bfs(MatrixU16 &changes, Pixels &toCheck, ObjectRectangle &object, ImageRowSegment row)
namespace
{
Pixels nextCheck;

for (auto &position : toCheck)
// optimized bfs depending to left/right borders for threads,
// every thread will search in defined area(column) of image
ObjectRectangle bfs(MatrixU16 &changes, Pixels &toCheck, ObjectRectangle &object, ImageRowSegment row)
{
if (changes(position.rowId, position.colId) == common::CHANGE)
Pixels nextCheck;

for (auto &position : toCheck)
{
checkClosest(position.rowId, position.colId, nextCheck, object, row, changes.getWidth(), 1u);
if (changes(position.rowId, position.colId) == common::CHANGE)
{
checkClosest(position.rowId, position.colId, nextCheck, object, row, changes.getWidth(), 1u);

//if (isNew(object, position.rowId, position.colId))
//{
//object.emplace_back(position.rowId, position.colId);
// if (isNew(object, position.rowId, position.colId))
//{
// object.emplace_back(position.rowId, position.colId);
object.addPixel(position.rowId, position.colId);
changes(position.rowId, position.colId) = 0;
//}
//}
}
}
}
if (nextCheck.size())
bfs(changes, nextCheck, object, row);
if (nextCheck.size())
bfs(changes, nextCheck, object, row);

return object;
}
return object;
}

std::vector<ObjectRectangle> startObjectsSearch(MatrixU16 &changes, am::configuration::Configuration *conf, const ImageRowSegment &row)
{
std::vector<ObjectRectangle> result;
const size_t step = conf->PixelStep;
// check all diffs on potential objects
// if change found -> run bsf to figure out how many pixels included in this object
//for (size_t rowId = step; rowId < changes.getHeight(); rowId += step)
for (size_t rowId = row.start; rowId < row.end; rowId += step)
std::vector<ObjectRectangle> startObjectsSearch(MatrixU16 &changes, const am::configuration::Configuration *conf, const ImageRowSegment &row)
{
for (size_t colId = step; colId < changes.getWidth(); colId += step)
std::vector<ObjectRectangle> result;
const size_t step = conf->PixelStep;
// check all diffs on potential objects
// if change found -> run bsf to figure out how many pixels included in this object
// for (size_t rowId = step; rowId < changes.getHeight(); rowId += step)
for (size_t rowId = row.start; rowId < row.end; rowId += step)
{
if (changes(rowId, colId) == common::CHANGE)
for (size_t colId = step; colId < changes.getWidth(); colId += step)
{
//std::vector<Pixel> obj;
ObjectRectangle obj(rowId, colId);
if (changes(rowId, colId) == common::CHANGE)
{
// std::vector<Pixel> obj;
ObjectRectangle obj(rowId, colId);

auto conns = checkConnections(rowId, colId, changes.getWidth(), row, 1u);
result.emplace_back(bfs(changes, conns, obj, row));
auto conns = checkConnections(rowId, colId, changes.getWidth(), row, 1u);
result.emplace_back(bfs(changes, conns, obj, row));
}
}
}
return result;
}
return result;
}

DiffObjectDetector::DiffObjectDetector(const size_t threads, std::shared_ptr<am::configuration::Configuration> &conf, std::shared_ptr<am::common::Logger> &logger) : BfsObjectDetector(threads, conf, logger)
{
}

DescObjects DiffObjectDetector::getObjectsRects(ColorDiffsMatrix &diffs)
Expand Down
2 changes: 1 addition & 1 deletion analyze/algorithm/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace am
class Object : public ObjectBase
{
public:
Object(std::vector<Pixel> &pixels);
explicit Object(std::vector<Pixel> &pixels);
~Object() = default;
std::vector<Pixel> &getPixels() const noexcept;

Expand Down
6 changes: 3 additions & 3 deletions analyze/algorithm/ObjectBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace am
namespace algorithm
{

bool ObjectBase::isMeargableToVertical(ObjectBase &leftObj) const noexcept
bool ObjectBase::isMeargableToVertical(const ObjectBase &leftObj) const noexcept
{
if (leftObj.getMaxHeight() + 1 == mMin_height)
{
Expand All @@ -22,7 +22,7 @@ namespace am
return false;
}

void ObjectBase::mergeToMe(ObjectBase &toCompare) noexcept
void ObjectBase::mergeToMe(const ObjectBase &toCompare) noexcept
{
mPixelsCount += toCompare.mPixelsCount;

Expand All @@ -40,7 +40,7 @@ namespace am
mMax_height = toCompare.mMax_height;
}

bool ObjectBase::mergeIfPossibleVerticalToMe(ObjectBase &toCompare) noexcept
bool ObjectBase::mergeIfPossibleVerticalToMe(const ObjectBase &toCompare) noexcept
{
if (isMeargableToVertical(toCompare))
{
Expand Down
6 changes: 3 additions & 3 deletions analyze/algorithm/ObjectBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ namespace am
mMax_height(row) {}
~ObjectBase() = default;

bool isMeargableToVertical(ObjectBase &toCompare) const noexcept;
bool mergeIfPossibleVerticalToMe(ObjectBase &toCompare) noexcept;
bool isMeargableToVertical(const ObjectBase &toCompare) const noexcept;
bool mergeIfPossibleVerticalToMe(const ObjectBase &toCompare) noexcept;

size_t getLeft() const noexcept;
size_t getRight() const noexcept;
Expand All @@ -31,7 +31,7 @@ namespace am
void clearPixelsCount() noexcept;

protected:
void mergeToMe(ObjectBase &toCompare) noexcept;
void mergeToMe(const ObjectBase &toCompare) noexcept;
size_t mPixelsCount;
size_t mLeft;
size_t mMin_height;
Expand Down

0 comments on commit f8963b9

Please sign in to comment.