Skip to content

Commit

Permalink
Fix warnings around type conversions and use float as much as possible
Browse files Browse the repository at this point in the history
  • Loading branch information
fspindle committed Sep 6, 2023
1 parent 82ac8da commit 335d075
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 43 deletions.
4 changes: 2 additions & 2 deletions modules/core/test/image-with-dataset/testImageFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,8 @@ int main(int argc, const char *argv[])
I_median_rgba[r][c].B = 3 * (r * 3 + c);
}
}
std::vector<double> median_rgba = vpImageFilter::median(I_median_rgba);
std::vector<double> expected_median_rgba = { 4, 8, 12 };
std::vector<float> median_rgba = vpImageFilter::median(I_median_rgba);
std::vector<float> expected_median_rgba = { 4.f, 8.f, 12.f };
for (unsigned int i = 0; i < 3; i++) {
bool test_local = (median_rgba[i] == expected_median_rgba[i]);
test &= test_local;
Expand Down
16 changes: 8 additions & 8 deletions modules/java/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ vp_add_library(${the_module} ${__type}
${copied_files}
)
add_dependencies(${the_module} gen_visp_java_source)

vp_target_include_directories(${the_module} "${CMAKE_CURRENT_SOURCE_DIR}/../generator/src/cpp")
vp_target_include_directories(${the_module} "${VISP_JAVA_BINDINGS_DIR}/gen/cpp")
vp_target_include_modules(${the_module} ${VISP_MODULE_${the_module}_DEPS})
Expand All @@ -51,17 +51,17 @@ if(BUILD_FAT_JAVA_LIB)
endif()
if(APPLE)
foreach(_dep ${__deps})
vp_target_link_libraries(${the_module} LINK_PRIVATE -Wl,-force_load "${_dep}")
vp_target_link_libraries(${the_module} PRIVATE -Wl,-force_load "${_dep}")
endforeach()
# TODO: Just check visp's file once, they had a condition I ignored
elseif(((UNIX) OR (VISP_FORCE_FAT_JAVA_LIB_LD_RULES)) AND (NOT VISP_SKIP_FAT_JAVA_LIB_LD_RULES))
vp_target_link_libraries(${the_module} LINK_PRIVATE -Wl,-whole-archive ${__deps} -Wl,-no-whole-archive)
vp_target_link_libraries(${the_module} PRIVATE -Wl,-whole-archive ${__deps} -Wl,-no-whole-archive)
else()
vp_target_link_libraries(${the_module} LINK_PRIVATE ${__deps})
vp_target_link_libraries(${the_module} PRIVATE ${__deps})
endif()
vp_target_link_libraries(${the_module} LINK_PRIVATE ${__extradeps} ${VISP_LINKER_LIBS})
vp_target_link_libraries(${the_module} PRIVATE ${__extradeps} ${VISP_LINKER_LIBS})
else()
vp_target_link_libraries(${the_module} LINK_PRIVATE ${__deps} ${VISP_LINKER_LIBS})
vp_target_link_libraries(${the_module} PRIVATE ${__deps} ${VISP_LINKER_LIBS})
endif()

# Additional target properties
Expand All @@ -74,8 +74,8 @@ set_target_properties(${the_module} PROPERTIES
)

if(ANDROID)
vp_target_link_libraries(${the_module} LINK_PUBLIC jnigraphics)
vp_target_link_libraries(${the_module} LINK_PUBLIC log dl z)
vp_target_link_libraries(${the_module} PUBLIC jnigraphics)
vp_target_link_libraries(${the_module} PUBLIC log dl z)

# force strip library after the build command
# because samples and tests will make a copy of the library before install
Expand Down
8 changes: 4 additions & 4 deletions tutorial/image/tutorial-draw-circle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ int main()
vpDisplay::setTitle(I, "Gray image");
vpDisplay::display(I);
//! [Circle display]
vpImageCircle circle(vpImagePoint(I.getHeight()/3, I.getWidth()/3), I.getWidth()/10);
vpImageCircle circle(vpImagePoint(I.getHeight()/3, I.getWidth()/3), I.getWidth()/10.f);
// Displays in overlay a red circle on the image
// i.e. does not modify I
vpDisplay::displayCircle(I, circle, vpColor::red, 2);
vpDisplay::displayCircle(I, circle, vpColor::red, false, 2);
//! [Circle display]
vpDisplay::flush(I);
vpDisplay::setTitle(I, "Overlay");
Expand All @@ -32,7 +32,7 @@ int main()
vpDisplay::getClick(I);

//! [Circle draw uchar]
vpImageCircle circle2(vpImagePoint(I.getHeight()/3, 2*I.getWidth()/3), I.getWidth()/10);
vpImageCircle circle2(vpImagePoint(I.getHeight()/3, 2*I.getWidth()/3), I.getWidth()/10.f);
// Draws a white circle on the image
// i.e. modifies I
vpImageDraw::drawCircle(I, circle2, 255, 2);
Expand All @@ -47,7 +47,7 @@ int main()

{
//! [Circle draw color]
vpImageCircle circle3(vpImagePoint(2*I.getHeight()/3, I.getWidth()/2), I.getWidth()/10);
vpImageCircle circle3(vpImagePoint(2*I.getHeight()/3, I.getWidth()/2), I.getWidth()/10.f);
// Draws a blue circle on the image
// i.e. modifies I_rgb
vpImageDraw::drawCircle(I_rgb, circle3, vpColor::blue, 2);
Expand Down
57 changes: 28 additions & 29 deletions tutorial/imgproc/hough-transform/tutorial-circle-hough.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ std::string getAvailableTypeInputImage(const std::string &prefix = "<", const st

//! [Draw disks]
void
drawDisk(vpImage<unsigned char> &I, const vpImagePoint &center, const unsigned int &radius
, const unsigned int &borderColor, const unsigned int &fillingColor, const unsigned int &thickness, const unsigned int &bckg)
drawDisk(vpImage<unsigned char> &I, const vpImagePoint &center, const unsigned int &radius,
const unsigned int &borderColor, const unsigned int &fillingColor, const unsigned int &thickness, const unsigned int &bckg)
//! [Draw disks]
{
vpImageDraw::drawCircle(I, center, radius, borderColor, thickness);
Expand Down Expand Up @@ -146,13 +146,13 @@ generateImage(const TypeInputImage &inputType)
}

drawDisk(I_src, vpImagePoint(top, left), circleRadius, circleColor, circleColor, circleThickness, bckg);
drawDisk(I_src, vpImagePoint(top, left), circleRadius * 0.50, circleColor / 2, circleColor / 2, circleThickness, circleColor);
drawDisk(I_src, vpImagePoint(top, left), circleRadius / 2, circleColor / 2, circleColor / 2, circleThickness, circleColor);
drawDisk(I_src, vpImagePoint(bottom, left), circleRadius, circleColor, circleColor, circleThickness, bckg);
drawDisk(I_src, vpImagePoint(bottom, left), circleRadius * 0.50, circleColor / 2, circleColor / 2, circleThickness, circleColor);
drawDisk(I_src, vpImagePoint(bottom, left), circleRadius / 2, circleColor / 2, circleColor / 2, circleThickness, circleColor);
drawDisk(I_src, vpImagePoint(top, right), circleRadius, circleColor, circleColor, circleThickness, bckg);
drawDisk(I_src, vpImagePoint(top, right), circleRadius * 0.50, circleColor / 2, circleColor / 2, circleThickness, circleColor);
drawDisk(I_src, vpImagePoint(top, right), circleRadius / 2, circleColor / 2, circleColor / 2, circleThickness, circleColor);
drawDisk(I_src, vpImagePoint(bottom, right), circleRadius, circleColor, circleColor, circleThickness, bckg);
drawDisk(I_src, vpImagePoint(bottom, right), circleRadius * 0.50, circleColor / 2, circleColor / 2, circleThickness, circleColor);
drawDisk(I_src, vpImagePoint(bottom, right), circleRadius / 2, circleColor / 2, circleColor / 2, circleThickness, circleColor);

std::cout << "Done drawing" << std::endl << std::flush;
return I_src;
Expand Down Expand Up @@ -196,44 +196,43 @@ int main(int argc, char **argv)
const std::string def_jsonFilePath = std::string("");
const int def_nbCirclesToDetect = -1;
const int def_gaussianKernelSize = 5;
const double def_gaussianSigma = 1.;
const float def_gaussianSigma = 1.f;
const int def_sobelKernelSize = 3;
#ifdef HAVE_OPENCV_IMGPROC
const double def_cannyThresh = 150.;
const float def_cannyThresh = 150.f;
#else
const double def_cannyThresh = 25.;
const float def_cannyThresh = 25.f;
#endif
const int def_nbEdgeFilteringIter = 2;
const std::pair<int, int> def_centerXlimits = std::pair<int, int>(0, 640);
const std::pair<int, int> def_centerYlimits = std::pair<int, int>(0, 480);
const unsigned int def_minRadius = 0;
const unsigned int def_maxRadius = 1000;
const int def_dilatationRepet = 1;
const double def_centerThresh = -1.;
const double def_radiusThreshRatio = -1.;
const double def_circlePerfectness = 0.85;
const double def_centerDistanceThresh = 15;
const double def_radiusDifferenceThresh = 15;

const float def_centerThresh = -1.f;
const float def_radiusThreshRatio = -1.f;
const float def_circlePerfectness = 0.85f;
const float def_centerDistanceThresh = 15.f;
const float def_radiusDifferenceThresh = 15.f;

std::string opt_input(def_input);
std::string opt_jsonFilePath = def_jsonFilePath;
int opt_nbCirclesToDetect = def_nbCirclesToDetect;
int opt_gaussianKernelSize = def_gaussianKernelSize;
double opt_gaussianSigma = def_gaussianSigma;
float opt_gaussianSigma = def_gaussianSigma;
int opt_sobelKernelSize = def_sobelKernelSize;
double opt_cannyThresh = def_cannyThresh;
float opt_cannyThresh = def_cannyThresh;
int opt_nbEdgeFilteringIter = def_nbEdgeFilteringIter;
std::pair<int, int> opt_centerXlimits = def_centerXlimits;
std::pair<int, int> opt_centerYlimits = def_centerYlimits;
unsigned int opt_minRadius = def_minRadius;
unsigned int opt_maxRadius = def_maxRadius;
int opt_dilatationRepet = def_dilatationRepet;
double opt_centerThresh = def_centerThresh;
int opt_radiusThreshRatio = def_radiusThreshRatio;
double opt_circlePerfectness = def_circlePerfectness;
double opt_centerDistanceThresh = def_centerDistanceThresh;
double opt_radiusDifferenceThresh = def_radiusDifferenceThresh;
float opt_centerThresh = def_centerThresh;
float opt_radiusThreshRatio = def_radiusThreshRatio;
float opt_circlePerfectness = def_circlePerfectness;
float opt_centerDistanceThresh = def_centerDistanceThresh;
float opt_radiusDifferenceThresh = def_radiusDifferenceThresh;
bool opt_displayCanny = false;

for (int i = 1; i < argc; i++) {
Expand All @@ -257,15 +256,15 @@ int main(int argc, char **argv)
i++;
}
else if (argName == "--gaussian-sigma" && i + 1 < argc) {
opt_gaussianSigma = atof(argv[i + 1]);
opt_gaussianSigma = static_cast<float>(atof(argv[i + 1]));
i++;
}
else if (argName == "--sobel-kernel" && i + 1 < argc) {
opt_sobelKernelSize = atoi(argv[i + 1]);
i++;
}
else if (argName == "--canny-thresh" && i + 1 < argc) {
opt_cannyThresh = atof(argv[i + 1]);
opt_cannyThresh = static_cast<float>(atof(argv[i + 1]));
i++;
}
else if (argName == "--edge-filter" && i + 1 < argc) {
Expand All @@ -282,7 +281,7 @@ int main(int argc, char **argv)
i += 2;
}
else if (argName == "--center-thresh" && i + 1 < argc) {
opt_centerThresh = atof(argv[i + 1]);
opt_centerThresh = static_cast<float>(atof(argv[i + 1]));
i++;
}
else if (argName == "--center-xlim" && i + 2 < argc) {
Expand All @@ -294,16 +293,16 @@ int main(int argc, char **argv)
i += 2;
}
else if (argName == "--radius-thresh" && i + 1 < argc) {
opt_radiusThreshRatio = atof(argv[i + 1]);
opt_radiusThreshRatio = static_cast<float>(atof(argv[i + 1]));
i++;
}
else if (argName == "--circle-perfectness" && i + 1 < argc) {
opt_circlePerfectness = atof(argv[i + 1]);
opt_circlePerfectness = static_cast<float>(atof(argv[i + 1]));
i++;
}
else if (argName == "--merging-thresh" && i + 2 < argc) {
opt_centerDistanceThresh = atof(argv[i + 1]);
opt_radiusDifferenceThresh = atof(argv[i + 2]);
opt_centerDistanceThresh = static_cast<float>(atof(argv[i + 1]));
opt_radiusDifferenceThresh = static_cast<float>(atof(argv[i + 2]));
i += 2;
}
else if (argName == "--display-edge-map") {
Expand Down

0 comments on commit 335d075

Please sign in to comment.