Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CodeQL issues #100

Merged
merged 4 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/BuildACVD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if(VC_BUILD_ACVD)
FetchContent_Declare(
acvd
GIT_REPOSITORY https://gitlab.com/educelab/acvd.git
GIT_TAG 9efaeb4d
GIT_TAG v1.2.1
)

# Populate the project but exclude from all
Expand Down
6 changes: 4 additions & 2 deletions core/include/vc/core/util/HashFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ namespace volcart

/**
* Hash for 3D vector types. Must support []-operator. It's designed for integer
* types, so don't expect much if using with floating-point types.
* types, and only makes sense for positive integer values, so don't expect
* much if using with floating-point types.
*
* Uses the hash function from:
* https://dmauro.com/post/77011214305/a-hashing-function-for-x-y-z-coordinates
Expand All @@ -24,7 +25,8 @@ struct Vec3Hash {
std::size_t hash = (max * max * max) + (2 * max * v[2]) + v[2];
if (max == v[2]) {
auto val = std::max({v[0], v[1]});
hash += val * val;
hash +=
static_cast<std::size_t>(val) * static_cast<std::size_t>(val);
}
if (v[1] >= v[0]) {
hash += v[0] + v[1];
Expand Down
20 changes: 12 additions & 8 deletions core/test/VolumeMaskTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ namespace vc = volcart;
using VolumeMask = vc::VolumeMask;
using State = vc::VolumeMask::State;

const int XY_SIZE = 3000;
const int Z_SIZE = 3000;
constexpr int XY_SIZE = 3000;
constexpr int Z_SIZE = 3000;

TEST(VolumeMask, BasicAssignment)
{
// Constructor
VolumeMask mask(5, 5, 5);

// Assignment
cv::Vec3i voxel(1, 2, 3);
const cv::Vec3i voxel(1, 2, 3);
mask.setVoxelState(voxel, State::Segmented);

// Retrieval
Expand All @@ -38,7 +38,7 @@ TEST(VolumeMask, Performance_LargeSlice)
VolumeMask mask(XY_SIZE, XY_SIZE, Z_SIZE);

// Assignment
cv::Vec3i voxel(XY_SIZE / 10, XY_SIZE / 10, Z_SIZE / 10);
const cv::Vec3i voxel(XY_SIZE / 10, XY_SIZE / 10, Z_SIZE / 10);

mask.setVoxelState(voxel, State::Segmented);

Expand All @@ -58,8 +58,10 @@ TEST(VolumeMask, Performance_ThousandVoxelSubvolume)

// Retrieval
auto subvolume = mask.getSubvolumeState(origin, dims);
std::vector<State> key(dims[0] * dims[1] * dims[2]);
std::fill(key.begin(), key.end(), State::Segmented);
const auto count = static_cast<std::size_t>(dims[0]) *
static_cast<std::size_t>(dims[1]) *
static_cast<std::size_t>(dims[2]);
std::vector key(count, State::Segmented);

// Retrieval
EXPECT_THAT(subvolume.as_vector(), testing::ContainerEq(key));
Expand All @@ -85,8 +87,10 @@ TEST(VolumeMask, Performance_EightThousandVoxelSubvolume)

// Retrieval
auto subvolume = mask.getSubvolumeState(origin, dims);
std::vector<State> key(dims[0] * dims[1] * dims[2]);
std::fill(key.begin(), key.end(), State::Segmented);
const auto count = static_cast<std::size_t>(dims[0]) *
static_cast<std::size_t>(dims[1]) *
static_cast<std::size_t>(dims[2]);
std::vector key(count, State::Segmented);

// Retrieval
EXPECT_THAT(subvolume.as_vector(), testing::ContainerEq(key));
Expand Down
38 changes: 20 additions & 18 deletions utils/src/SurfArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,53 +14,55 @@
#include "vc/meshing/ITK2VTK.hpp"
#include "vc/meshing/OrderedPointSetMesher.hpp"

auto main(int argc, char** argv) -> int
using namespace volcart;
using namespace volcart::meshing;

auto main(const int argc, char** argv) -> int
{
if (argc < 3) {
std::cout << "Usage: vc_area volpkg (seg-id | mesh)" << '\n';
exit(-1);
}

// Load the VolumePkg
volcart::VolumePkg vpkg(argv[1]);
VolumePkg vpkg(argv[1]);

volcart::ITKMesh::Pointer mesh;
ITKMesh::Pointer mesh;
std::string segID;
if (volcart::IsFileType(argv[2], {"obj", "ply"})) {
if (IsFileType(argv[2], {"obj", "ply"})) {
// Load the mesh
auto meshReaderResult = volcart::ReadMesh(argv[2]);
mesh = meshReaderResult.mesh;
const auto [mesh, uv, texture] = ReadMesh(argv[2]);
} else {
// Get the segmentation
segID = argv[2];
auto seg = vpkg.segmentation(segID);
const auto seg = vpkg.segmentation(segID);

// Mesh the point cloud
volcart::meshing::OrderedPointSetMesher mesher;
OrderedPointSetMesher mesher;
mesher.setPointSet(seg->getPointSet());
mesh = mesher.compute();
}

auto smoothVTK = vtkPolyData::New();
volcart::meshing::ITK2VTK(mesh, smoothVTK);
const auto smoothVTK = vtkPolyData::New();
ITK2VTK(mesh, smoothVTK);

auto smooth = vtkSmoothPolyDataFilter::New();
const auto smooth = vtkSmoothPolyDataFilter::New();
smooth->SetInputData(smoothVTK);
smooth->SetBoundarySmoothing(1);
smooth->SetNumberOfIterations(10);
smooth->SetRelaxationFactor(0.3);
smooth->Update();

auto massProperties = vtkMassProperties::New();
const auto massProperties = vtkMassProperties::New();
massProperties->AddInputData(smooth->GetOutput());

auto areaVoxels = massProperties->GetSurfaceArea();
auto voxelSize = vpkg.volume()->voxelSize();
const auto areaVoxels = massProperties->GetSurfaceArea();
const auto voxelSize = vpkg.volume()->voxelSize();

long double umArea = areaVoxels * std::pow(voxelSize, 2);
long double mmArea = umArea * std::pow(0.001, 2);
long double cmArea = umArea * std::pow(0.0001, 2);
long double inArea = umArea * std::pow(3.93700787e-5, 2);
const auto umArea = areaVoxels * std::pow(voxelSize, 2);
const auto mmArea = umArea * std::pow(0.001, 2);
const auto cmArea = umArea * std::pow(0.0001, 2);
const auto inArea = umArea * std::pow(3.93700787e-5, 2);

std::cout << std::endl;
std::cout << "Area: " << segID << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion vc-deps
Submodule vc-deps updated 1 files
+2 −2 cmake/BuildACVD.cmake