Refactor NSS and DNSS implementations for improved readability and modularity#8
Refactor NSS and DNSS implementations for improved readability and modularity#8eclipse0922 wants to merge 2 commits intomasterfrom
Conversation
…dularity - Rewrote legacy code into clean C++17 style. - Added missing method implementations and input validation. - Introduced options struct for configurable parameters in NSS and DNSS. - Implemented CUDA support for DNSS rotational feature computation. - Added new CMake configuration for building with or without CUDA. - Updated README to reflect changes and provide build instructions. - Added .gitignore to exclude build directories.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Summary of ChangesHello @eclipse0922, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request undertakes a significant modernization and enhancement of the Normal Space Sampling (NSS) and Dual Normal Space Sampling (DNSS) algorithms. The codebase has been extensively refactored to align with C++17 standards, prioritizing clarity and modularity. Key improvements include the introduction of flexible configuration options, robust input validation, and a substantial performance boost for DNSS through optional CUDA acceleration. The underlying sampling logic has been optimized for efficiency, and the project's build process and documentation have been updated to reflect these comprehensive changes. Highlights
Changelog
Ignored Files
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
PR Description updated to latest commit (4bb5106) |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨
|
There was a problem hiding this comment.
Code Review
This is an excellent and comprehensive refactoring of the NSS and DNSS implementations. The code is now much more readable, modular, and follows modern C++17 practices.
Key improvements include:
- The introduction of
Optionsstructs for bothNSSandDNSS, which makes configuration much cleaner. - A complete rewrite of the core algorithms, replacing complex and inefficient legacy code with clear, robust, and more efficient implementations. For example, using an
is_activeflag instead ofvector::eraseis a great performance improvement. - The addition of optional CUDA support with a clean CPU fallback is a fantastic feature.
- The new CMake build system is well-structured.
I have a few minor suggestions to further improve the code, mostly related to best practices and code simplification. Overall, this is a very high-quality pull request.
|
|
||
| option(DNSS_ENABLE_CUDA "Enable CUDA acceleration for DNSS rotational feature computation" OFF) | ||
|
|
||
| add_library(dnss NSS.cpp NSS.h) |
There was a problem hiding this comment.
It's generally not recommended to include header files in add_library. While it might work with some generators (like adding the file to a Visual Studio project), it's not a portable practice and can have unintended side effects with others. Headers are made available to targets via target_include_directories, which is already correctly used.
add_library(dnss NSS.cpp)
| if (sampled_vertices.size() < static_cast<std::size_t>(target_count)) | ||
| { | ||
| for (std::size_t point_index = 0; point_index < is_active.size(); ++point_index) | ||
| { | ||
| if (sampled_vertices.size() >= static_cast<std::size_t>(target_count)) | ||
| { | ||
| break; | ||
| } | ||
| if (is_active[point_index] == 0u) | ||
| { | ||
| continue; | ||
| } | ||
| selectPoint(static_cast<int>(point_index)); | ||
| } | ||
| } | ||
| return pid; | ||
| } |
There was a problem hiding this comment.
This final loop appears to be redundant. The main sampling loop preceding this will terminate either when target_count is reached or when all available points have been sampled (leading to best_type == BucketType::None). In the latter scenario, all points would have been sampled, meaning this loop would not select any additional points. This block of code seems safe to remove.
| cudaFree(d_vertices); | ||
| cudaFree(d_normals); | ||
| cudaFree(d_rot_normals); | ||
| cudaFree(d_rot_returns); |
There was a problem hiding this comment.
This block of cleanup code is repeated in multiple error-handling paths. To improve maintainability and reduce redundancy, consider extracting it into a helper lambda or, for a more robust solution, using a RAII wrapper (like std::unique_ptr with a custom deleter) for the CUDA memory allocations. This would simplify the error handling logic significantly.
User description
PR Type
Enhancement, Bug fix, Documentation
Description
Refactored NSS and DNSS implementations into clean C++17 with modular design and options structs.
Added input validation, missing methods, and fixed rotational-return math to use radians consistently.
Implemented optional CUDA acceleration for DNSS rotational feature computation with CPU fallback.
Updated README with algorithm notes, build instructions, and references; added CMake CUDA support.
Changes walkthrough 📝
NSS.cpp
Refactor sampling logic and add helper functionsNSS.cpp
and options-based configuration.
computeCenteredAndScaledVertices,sphericalBucketIndex,and
computeRotationalReturnValue.DNSSComputeRotationalFeaturesCudadeclaration.
normalSpaceSamplinganddualNormalSpaceSamplingwith lazyremoval and priority queues.
NSS.h
Modernize header and add optionsNSS.h
concurrency dependencies.
Optionsstructs for configurable parameters in bothNSSandDNSS.setUseCuda,getUseCuda, and input validation insetInputCloud.glm::fvec3fallback implementation for portability.dnss_cuda.cu
Add CUDA implementation for DNSSdnss_cuda.cu
host-side wrapper.
failure.
CMakeLists.txt
Add CMake CUDA build supportCMakeLists.txt
DNSS_ENABLE_CUDAoption.cudart.targets.
pr-agent.yml
Update PR agent config.github/workflows/pr-agent.yml
PR_REVIEWER__NUM_CODE_SUGGESTIONSfrom 3 to 5.PR_DESCRIPTION__PUBLISH_LABELSline.README.md
Update documentation and build guideREADME.md
and references.
CUDA fallback.