diff --git a/.clang-format b/.clang-format index 1b19ad89..45b7d9f2 100644 --- a/.clang-format +++ b/.clang-format @@ -32,14 +32,19 @@ BraceWrapping: BeforeCatch: true BeforeElse: true IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false BreakBeforeBinaryOperators: None BreakBeforeBraces: Custom +BreakBeforeInheritanceComma: false BreakBeforeTernaryOperators: true -BreakConstructorInitializersBeforeComma: true +BreakConstructorInitializers: BeforeComma BreakAfterJavaFieldAnnotations: false BreakStringLiterals: true ColumnLimit: 0 -CommentPragmas: '^ IWYU pragma:' +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false ConstructorInitializerAllOnOneLineOrOnePerLine: true ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 4 @@ -47,8 +52,13 @@ Cpp11BracedListStyle: true DerivePointerAlignment: false DisableFormat: false ExperimentalAutoDetectBinPacking: false -ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] -IncludeCategories: +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: - Regex: '^<.*>' Priority: 1 - Regex: '^".*"' @@ -57,8 +67,11 @@ IncludeCategories: Priority: 3 IncludeIsMainRegex: '([-_](test|unittest))?$' IndentCaseLabels: true +IndentPPDirectives: AfterHash IndentWidth: 4 IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true KeepEmptyLinesAtTheStartOfBlocks: false MacroBlockBegin: '' MacroBlockEnd: '' @@ -67,7 +80,7 @@ NamespaceIndentation: All ObjCBlockIndentWidth: 2 ObjCSpaceAfterProperty: false ObjCSpaceBeforeProtocolList: false -IndentPPDirectives: AfterHash +PenaltyBreakAssignment: 2 PenaltyBreakBeforeFirstCallParameter: 1 PenaltyBreakComment: 300 PenaltyBreakFirstLessLess: 120 @@ -75,8 +88,13 @@ PenaltyBreakString: 1000 PenaltyExcessCharacter: 1000000 PenaltyReturnTypeOnItsOwnLine: 200 PointerAlignment: Left +RawStringFormats: + - Delimiter: pb + Language: TextProto + BasedOnStyle: google ReflowComments: true SortIncludes: true +SortUsingDeclarations: true SpaceAfterCStyleCast: false SpaceAfterTemplateKeyword: false SpaceBeforeAssignmentOperators: true diff --git a/example/kdTreeFiltering/src/main.cpp b/example/kdTreeFiltering/src/main.cpp index f94b5ad2..be321dc2 100644 --- a/example/kdTreeFiltering/src/main.cpp +++ b/example/kdTreeFiltering/src/main.cpp @@ -13,8 +13,8 @@ #include "ApproxMVBB/Config/Config.hpp" #include ApproxMVBB_TypeDefs_INCLUDE_FILE -#include "ApproxMVBB/KdTree.hpp" #include "ApproxMVBB/Common/CPUTimer.hpp" +#include "ApproxMVBB/KdTree.hpp" #ifdef ApproxMVBB_XMLSUPPORT # include "ApproxMVBB/KdTreeXml.hpp" diff --git a/include/ApproxMVBB/Common/LogDefines.hpp b/include/ApproxMVBB/Common/LogDefines.hpp index 1a72885e..8f9207ea 100644 --- a/include/ApproxMVBB/Common/LogDefines.hpp +++ b/include/ApproxMVBB/Common/LogDefines.hpp @@ -15,25 +15,11 @@ #include "ApproxMVBB/Config/Config.hpp" -#define ApproxMVBB_LOG(message) \ - { \ - std::cout << message; \ - } +#define ApproxMVBB_LOG(message) std::cout << message; #define ApproxMVBB_LOGLEVEL(level, setlevel, message) \ + if(level <= setlevel) \ { \ - if(level <= setlevel) \ - { \ - ApproxMVBB_LOG(message); \ - } \ - } -#define ApproxMVBB_LOGLEVEL_SCOPE(level) \ - { \ - if(level <= setlevel) \ - { \ - } -#define ApproxMVBB_LOGLEVEL_SCOPE_END \ - { \ - } \ + ApproxMVBB_LOG(message); \ } // Message Log @@ -49,18 +35,9 @@ # endif #endif -#define ApproxMVBB_MSGLOG_L1(message) \ - { \ - ApproxMVBB_LOGLEVEL(1, ApproxMVBB_MSGLOG_LEVEL, message) \ - } -#define ApproxMVBB_MSGLOG_L2(message) \ - { \ - ApproxMVBB_LOGLEVEL(2, ApproxMVBB_MSGLOG_LEVEL, message) \ - } -#define ApproxMVBB_MSGLOG_L3(message) \ - { \ - ApproxMVBB_LOGLEVEL(3, ApproxMVBB_MSGLOG_LEVEL, message) \ - } -// ============================================================================================== +#define ApproxMVBB_MSGLOG_L1(message) ApproxMVBB_LOGLEVEL(1, ApproxMVBB_MSGLOG_LEVEL, message) +#define ApproxMVBB_MSGLOG_L2(message) ApproxMVBB_LOGLEVEL(2, ApproxMVBB_MSGLOG_LEVEL, message) +#define ApproxMVBB_MSGLOG_L3(message) ApproxMVBB_LOGLEVEL(3, ApproxMVBB_MSGLOG_LEVEL, message) +// ================================================================================== #endif diff --git a/include/ApproxMVBB/Common/MyMatrixTypeDefs.hpp b/include/ApproxMVBB/Common/MyMatrixTypeDefs.hpp index f5a73b73..7f38ba9d 100644 --- a/include/ApproxMVBB/Common/MyMatrixTypeDefs.hpp +++ b/include/ApproxMVBB/Common/MyMatrixTypeDefs.hpp @@ -21,9 +21,9 @@ namespace ApproxMVBB { // ================================================================================================ - /** @brief This - * These are some small matrix definitions. - */ + /*! @brief This + These are some small matrix definitions. + */ namespace MyMatrix { diff --git a/include/ApproxMVBB/ComputeApproxMVBB.hpp b/include/ApproxMVBB/ComputeApproxMVBB.hpp index 200867fc..e5947ab8 100644 --- a/include/ApproxMVBB/ComputeApproxMVBB.hpp +++ b/include/ApproxMVBB/ComputeApproxMVBB.hpp @@ -27,22 +27,22 @@ namespace ApproxMVBB ApproxMVBB_DEFINE_MATRIX_TYPES; ApproxMVBB_DEFINE_POINTS_CONFIG_TYPES; - /** We are given a point set, and (hopefully) a tight fitting - * bounding box. We compute a sample of the given size nPoints that - * represents - * the point-set. The only guarenteed is that if we use sample of size m, - * we get an approximation of quality about 1/\sqrt{m}. Note that we pad - * the sample if necessary to get the desired size. - * This function changes the oobb and sets the z Axis to the greates - * extent! - * @param nPoints needs to be greater or equal than 2 - */ + /*! + We are given a point set, and (hopefully) a tight fitting + bounding box. We compute a sample of the given size nPoints that + represents the point-set. The only guarenteed is that if we use sample of size m, + we get an approximation of quality about 1/\sqrt{m}. Note that we pad + the sample if necessary to get the desired size. + This function changes the oobb and sets the z Axis to the greatest + extent! + @param nPoints needs to be greater or equal than 2 + */ template - APPROXMVBB_EXPORT void samplePointsGrid(Matrix3Dyn& newPoints, - const MatrixBase& points, - const unsigned int nPoints, - OOBB& oobb, - std::size_t seed = ApproxMVBB::RandomGenerators::defaultSeed) + void samplePointsGrid(Matrix3Dyn& newPoints, + const MatrixBase& points, + const unsigned int nPoints, + OOBB& oobb, + std::size_t seed = ApproxMVBB::RandomGenerators::defaultSeed) { using IndexType = typename Derived::Index; @@ -126,7 +126,7 @@ namespace ApproxMVBB // Copy top and bottom points IndexType k = 0; - ApproxMVBB_MSGLOG_L2("Sampled Points incides: [ ") + ApproxMVBB_MSGLOG_L2("Sampled Points incides: [ "); // k does not overflow -> 2* halfSampleSize = 2*gridSize*gridSize <= // nPoints; for(IndexType i = 0; i < halfSampleSize; ++i) @@ -137,16 +137,15 @@ namespace ApproxMVBB // Array3 a(i % // gridSize,i/gridSize,oobb.m_maxPoint(2)-oobb.m_minPoint(2)); // a.head<2>()*=dxdyInv.inverse(); - ApproxMVBB_MSGLOG_L2(boundaryPoints[i].topIdx - 1 << ", " << ((k % 30 == 0) ? "\n" : "")) - newPoints.col(k++) = - points.col(boundaryPoints[i].topIdx - 1); // A_KI.transpose()*(oobb.m_minPoint + a.matrix()).eval() ; + ApproxMVBB_MSGLOG_L2(boundaryPoints[i].topIdx - 1 << ", " << ((k % 30 == 0) ? "\n" : "")); + newPoints.col(k++) = points.col(boundaryPoints[i].topIdx - 1); // A_KI.transpose()*(oobb.m_minPoint + a.matrix()).eval() ; if(boundaryPoints[i].topIdx != boundaryPoints[i].bottomIdx) { // comment in if you want the bottom points of the grid // Array3 a(i % gridSize,i/gridSize,0); // a.head<2>()*=dxdyInv.inverse(); - ApproxMVBB_MSGLOG_L2(boundaryPoints[i].bottomIdx - 1 << ", ") newPoints.col(k++) = points.col( - boundaryPoints[i].bottomIdx - 1); // A_KI.transpose()*(oobb.m_minPoint + a.matrix()).eval() ; + ApproxMVBB_MSGLOG_L2(boundaryPoints[i].bottomIdx - 1 << ", "); + newPoints.col(k++) = points.col(boundaryPoints[i].bottomIdx - 1); // A_KI.transpose()*(oobb.m_minPoint + a.matrix()).eval() ; } } } @@ -161,30 +160,31 @@ namespace ApproxMVBB IndexType s; while(k < nPoints) { - s = dis(gen); - ApproxMVBB_MSGLOG_L2(s << ", ") newPoints.col(k++) = points.col(s); //= Vector3(0,0,0);// + s = dis(gen); + ApproxMVBB_MSGLOG_L2(s << ", "); + newPoints.col(k++) = points.col(s); //= Vector3(0,0,0);// } } - ApproxMVBB_MSGLOG_L2("]" << std::endl) + ApproxMVBB_MSGLOG_L2("]" << std::endl); } - /** - * Function to optimize oriented bounding box volume. - * Projecting nLoops times into the direction of the axis of the current oobb, - * constructing the mvbb and overwriting the current oobb if volume is smaller - * @param volumeAcceptFactor is volumeAcceptTol = oobb.volume * - * volumeAcceptFactor, which determines the tolerance when a new volume is - * accepted - * @param minBoxExtent is the minmum extent direction a box must have, to make - * the volume not zero and comparable to other volumes - * which is useful for degenerate cases, such as all points in a surface - */ + /*! + Function to optimize oriented bounding box volume. + Projecting nLoops times into the direction of the axis of the current oobb, + constructing the mvbb and overwriting the current oobb if volume is smaller + @param volumeAcceptFactor is volumeAcceptTol = oobb.volume * + volumeAcceptFactor, which determines the tolerance when a new volume is + accepted + @param minBoxExtent is the minmum extent direction a box must have, to make + the volume not zero and comparable to other volumes + which is useful for degenerated cases, such as all points in a surface + */ template - APPROXMVBB_EXPORT OOBB optimizeMVBB(const MatrixBase& points, - OOBB oobb, - unsigned int nLoops = 10, - PREC volumeAcceptFactor = 1e-6, - PREC minBoxExtent = 1e-12) + OOBB optimizeMVBB(const MatrixBase& points, + OOBB oobb, + unsigned int nLoops = 10, + PREC volumeAcceptFactor = 1e-6, + PREC minBoxExtent = 1e-12) { EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Derived, 3, Eigen::Dynamic); @@ -200,13 +200,13 @@ namespace ApproxMVBB // =============================================================== // #ifdef ApproxMVBB_OPENMP_SUPPORT // #pragma omp declare reduction(volumeIsSmaller:OOBB: \ -// omp_in.volume() - APPROXMVBB_EXPORT OOBB approximateMVBBGridSearch(const MatrixBase& points, - OOBB oobb, - PREC epsilon, - const unsigned int gridSize = 5, - const unsigned int optLoops = 6, - PREC volumeAcceptFactor = 1e-6, - PREC minBoxExtent = 1e-12) + OOBB approximateMVBBGridSearch(const MatrixBase& points, + OOBB oobb, + PREC epsilon, + const unsigned int gridSize = 5, + const unsigned int optLoops = 6, + PREC volumeAcceptFactor = 1e-6, + PREC minBoxExtent = 1e-12) { EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Derived, 3, Eigen::Dynamic); @@ -303,18 +304,21 @@ namespace ApproxMVBB Vector3 dir3 = oobb.getDirection(2); ProjectedPointSet proj; - Vector3 dir; + Vector3 dir; // clang-format off + + #ifdef ApproxMVBB_OPENMP_SUPPORT -#ifdef ApproxMVBB_OPENMP_SUPPORT -# pragma omp declare reduction(volumeIsSmaller \ - : OOBB \ - : omp_in.volume() < omp_out.volume() ? omp_out = omp_in : omp_out) \ + #pragma omp declare reduction(volumeIsSmaller \ + : OOBB \ + : omp_in.volume() < omp_out.volume() ? omp_out = omp_in : omp_out) \ initializer(omp_priv(omp_orig)) -# pragma omp parallel for schedule(dynamic, 4) collapse(3) shared(points) private(proj, dir) \ - reduction(volumeIsSmaller \ - : oobb) ApproxMVBB_OPENMP_NUMTHREADS -#endif + #pragma omp parallel for schedule(dynamic, 4) collapse(3) shared(points) private(proj, dir) \ + reduction(volumeIsSmaller \ + : oobb) ApproxMVBB_OPENMP_NUMTHREADS + + #endif + // clang-format on for(int x = -int(gridSize); x <= (int)gridSize; ++x) { for(int y = -int(gridSize); y <= (int)gridSize; ++y) @@ -328,10 +332,10 @@ namespace ApproxMVBB // Make direction Vector3 dir = x * dir1 + y * dir2 + z * dir3; - ApproxMVBB_MSGLOG_L3("gridSearch: dir: " << dir.transpose() << std::endl;) + ApproxMVBB_MSGLOG_L3("gridSearch: dir: " << dir.transpose() << std::endl); - // Compute MVBB in dirZ - auto res = proj.computeMVBB(dir, points); + // Compute MVBB in dirZ + auto res = proj.computeMVBB(dir, points); // Expand to minimal extent for points in a surface or line res.expandToMinExtentAbsolute(minBoxExtent); @@ -341,13 +345,14 @@ namespace ApproxMVBB res = optimizeMVBB(points, res, optLoops, volumeAcceptFactor, minBoxExtent); } ApproxMVBB_MSGLOG_L3("gridSearch: volume: " - << res.volume() - << std::endl;) if(res.volume() < - oobb.volume() /*&& res.volume()>volumeAcceptTol */) + << res.volume() + << std::endl); + + if(res.volume() < oobb.volume() /*&& res.volume()>volumeAcceptTol */) { ApproxMVBB_MSGLOG_L2("gridSearch: new volume: " << res.volume() << std::endl - << "for dir: " << dir.transpose() << std::endl;) - oobb = res; + << "for dir: " << dir.transpose() << std::endl); + oobb = res; } } } @@ -355,19 +360,19 @@ namespace ApproxMVBB return oobb; } - /** - * Function to optimize oriented bounding box volume. - * This constructs an approximation of a tightly fitted bounding box by computing - * the diameter d in 3d and afterwards the projection of the points in the plane - * perpendicular to direction d - * and then the diameter f in 2d and extruding the OOBB in 2d to the final OOBB - * approximation in 3d. - */ + /*! + Function to optimize oriented bounding box volume. + This constructs an approximation of a tightly fitted bounding box by computing + the diameter d in 3d and afterwards the projection of the points in the plane + perpendicular to direction d + and then the diameter f in 2d and extruding the OOBB in 2d to the final OOBB + approximation in 3d. + */ template - APPROXMVBB_EXPORT OOBB approximateMVBBDiam(const MatrixBase& points, - const PREC epsilon, - const unsigned int optLoops = 10, - std::size_t seed = ApproxMVBB::RandomGenerators::defaultSeed) + OOBB approximateMVBBDiam(const MatrixBase& points, + const PREC epsilon, + const unsigned int optLoops = 10, + std::size_t seed = ApproxMVBB::RandomGenerators::defaultSeed) { EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Derived, 3, Eigen::Dynamic); @@ -388,10 +393,10 @@ namespace ApproxMVBB dirZ.setZero(); dirZ(0) = 1; } - ApproxMVBB_MSGLOG_L1("estimated 3d diameter: " << dirZ.transpose() << " eps: " << epsilon << std::endl;) + ApproxMVBB_MSGLOG_L1("estimated 3d diameter: " << dirZ.transpose() << " eps: " << epsilon << std::endl); - // Compute MVBB in dirZ - ProjectedPointSet proj; + // Compute MVBB in dirZ + ProjectedPointSet proj; // OOBB oobb = proj.computeMVBB(); // or faster estimate diameter in projected plane and build coordinate system OOBB oobb = proj.computeMVBBApprox(dirZ, points, epsilon); @@ -404,13 +409,13 @@ namespace ApproxMVBB } template - APPROXMVBB_EXPORT OOBB approximateMVBB(const MatrixBase& points, - const PREC epsilon, - const unsigned int pointSamples = 400, - const unsigned int gridSize = 5, - const unsigned int mvbbDiamOptLoops = 0, - const unsigned int mvbbGridSearchOptLoops = 6, - std::size_t seed = ApproxMVBB::RandomGenerators::defaultSeed) + OOBB approximateMVBB(const MatrixBase& points, + const PREC epsilon, + const unsigned int pointSamples = 400, + const unsigned int gridSize = 5, + const unsigned int mvbbDiamOptLoops = 0, + const unsigned int mvbbGridSearchOptLoops = 6, + std::size_t seed = ApproxMVBB::RandomGenerators::defaultSeed) { EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Derived, 3, Eigen::Dynamic);