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

Optimized curvature calculation + other updates #118

Merged
merged 5 commits into from
Jan 4, 2025
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 .ci/conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CCCoreLib
channels:
- conda-forge
dependencies:
- cgal=5.*
- ninja
- qt=5.15.*
- cgal=5.*
- tbb-devel=2021.*
15 changes: 5 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ on: [ push, pull_request ]

jobs:
build:
name: ${{ matrix.config.name }} SCALAR_DOUBLE=${{ matrix.scalar_double }}
name: ${{ matrix.config.name }}
runs-on: ${{ matrix.config.os }}
if: "!contains(github.event.head_commit.message, '[skip ci]')"

strategy:
fail-fast: false
matrix:
scalar_double: ["OFF", "ON"]
config:
- {
name: "Windows MSVC",
Expand All @@ -35,10 +34,10 @@ jobs:
- name: Install Dependencies
uses: conda-incubator/setup-miniconda@v3
with:
architecture: ${{ matrix.config.os == 'macos-latest' && 'arm64' || 'x64' }}
activate-environment: CCCoreLib
auto-activate-base: false
environment-file: .ci/conda.yml
mamba-version: '*'

- name: Configure MSVC console (Windows)
if: matrix.config.os == 'windows-latest'
Expand All @@ -65,7 +64,6 @@ jobs:
-G "${{ matrix.config.generator }}" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH="$CONDA_LIB_DIR" \
-DCCCORELIB_SCALAR_DOUBLE=${{ matrix.scalar_double }} \
-DCCCORELIB_USE_CGAL=FALSE \
-DCCCORELIB_USES_TBB=TRUE \
.
Expand All @@ -82,8 +80,7 @@ jobs:
-B cccorelib-build \
-G "${{ matrix.config.generator }}" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH="$CONDA_LIB_DIR" \
-DCCCORELIB_SCALAR_DOUBLE=${{ matrix.scalar_double }} \
-DCMAKE_PREFIX_PATH="$CONDA_LIB_DIR" \
-DCCCORELIB_USE_CGAL=FALSE \
-DCCCORELIB_USES_TBB=TRUE \
.
Expand All @@ -92,19 +89,18 @@ jobs:
run: cmake --build cccorelib-build --parallel

ubuntu-build:
name: Ubuntu ${{ matrix.compiler }} SCALAR_DOUBLE=${{ matrix.scalar_double }}
name: Ubuntu ${{ matrix.compiler }}
runs-on: ubuntu-22.04
if: "!contains(github.event.head_commit.message, '[skip ci]')"

strategy:
fail-fast: false
matrix:
scalar_double: [ "OFF", "ON" ]
compiler: ["GCC", "Clang"]

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: recursive

Expand Down Expand Up @@ -138,7 +134,6 @@ jobs:
-S .
-G Ninja
-DCMAKE_BUILD_TYPE=Release
-DCCCORELIB_SCALAR_DOUBLE=${{ matrix.scalar_double }}
-DCCCORELIB_USE_CGAL=TRUE
-DCCCORELIB_USES_TBB=TRUE
.
Expand Down
3 changes: 3 additions & 0 deletions include/DgmOctreeReferenceCloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ namespace CCCoreLib
//! Forwards global iterator
inline void forwardIterator() { ++m_globalIterator; }

//! Returns a given point descriptor
inline const DgmOctree::PointDescriptor& getPointDescriptor(unsigned pointIndex) const { assert(pointIndex < size()); return m_set->at(pointIndex); }

protected:

//! Computes the cloud bounding-box (internal)
Expand Down
15 changes: 7 additions & 8 deletions include/Neighbourhood.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "GenericIndexedCloudPersist.h"
#include "SquareMatrix.h"


namespace CCCoreLib
{
class GenericIndexedMesh;
Expand Down Expand Up @@ -260,11 +259,12 @@ namespace CCCoreLib
//! Returns the best interpolating 2.5D quadric
/** Returns an array of the form [a,b,c,d,e,f] such as:
Z = a + b.X + c.Y + d.X^2 + e.X.Y + f.Y^2
\warning: 'X','Y' and 'Z' are output in dims (optional):
dims = [index(X),index(Y),index(Z)] where: 0=x, 1=y, 2=z
\warning: 'X','Y' and 'Z' are implicitly expressed in a local coordinate system (see 'toLocalCS')
\param[out] toLocalOrientation optional 3x3 matrix to convert the points to the local coordinate/orientation system in which the Quadric is expressed
(point coordinates should already be expressed relative to the gravity center)
\return nullptr if computation failed
**/
const PointCoordinateType* getQuadric(Tuple3ub* dims = nullptr);
const PointCoordinateType* getQuadric(SquareMatrix* localOrientation = nullptr);

//! Computes the best interpolating quadric (Least-square)
/** \param[out] quadricEquation an array of 10 coefficients [a,b,c,d,e,f,g,l,m,n] such as
Expand All @@ -288,11 +288,10 @@ namespace CCCoreLib
**/
PointCoordinateType m_quadricEquation[6];

//! 2.5D Quadric equation dimensions
/** Array (index(X),index(Y),index(Z)) where: 0=x, 1=y, 2=z
Only valid if 'structuresValidity & QUADRIC != 0'.
//! 2.5D Quadric equation local coordinate/orientation system
/** Only valid if 'structuresValidity & QUADRIC != 0'.
**/
Tuple3ub m_quadricEquationDirections;
SquareMatrix m_quadricEquationOrientation;

//! Least-square best fitting plane parameters
/** Array [a,b,c,d] such that ax+by+cz = d
Expand Down
6 changes: 3 additions & 3 deletions include/SquareMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ namespace CCCoreLib
//we scale the matrix to make the pivot equal to 1
if (tempM[i][i] != 1.0)
{
const Scalar& tmpVal = tempM[i][i];
const Scalar tmpVal = tempM[i][i];
for (unsigned k = i; k < 2 * m_matrixSize; ++k)
tempM[i][k] /= tmpVal;
}
Expand All @@ -427,7 +427,7 @@ namespace CCCoreLib
{
if (tempM[j][i] != 0)
{
const Scalar& tmpVal = tempM[j][i];
const Scalar tmpVal = tempM[j][i];
for (unsigned k = i; k < 2 * m_matrixSize; k++)
tempM[j][k] -= tempM[i][k] * tmpVal;
}
Expand All @@ -443,7 +443,7 @@ namespace CCCoreLib
{
if (tempM[j][i] != 0)
{
const Scalar& tmpVal = tempM[j][i];
const Scalar tmpVal = tempM[j][i];
for (unsigned k = i; k < 2 * m_matrixSize; k++)
tempM[j][k] -= tempM[i][k] * tmpVal;
}
Expand Down
47 changes: 21 additions & 26 deletions src/LocalModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,15 @@ class QuadricLocalModel : public LocalModel

//! Constructor
QuadricLocalModel( const PointCoordinateType eq[6],
unsigned char X,
unsigned char Y,
unsigned char Z,
CCVector3 gravityCenter,
const SquareMatrix& localOrientation,
const CCVector3& gravityCenter,
const CCVector3 &center,
PointCoordinateType squaredRadius )
: LocalModel(center, squaredRadius)
, m_X(X)
, m_Y(Y)
, m_Z(Z)
, m_localOrientation(localOrientation)
, m_gravityCenter(gravityCenter)
{
m_localOrientationInv = m_localOrientation.inv();
memcpy(m_eq, eq, sizeof(PointCoordinateType) * 6);
}

Expand All @@ -130,31 +127,31 @@ class QuadricLocalModel : public LocalModel
//inherited from LocalModel
ScalarType computeDistanceFromModelToPoint(const CCVector3* _P, CCVector3* nearestPoint = nullptr) const override
{
CCVector3 P = *_P - m_gravityCenter;
CCVector3 Plocal = m_localOrientation * (*_P - m_gravityCenter);

//height = h0 + h1.x + h2.y + h3.x^2 + h4.x.y + h5.y^2
PointCoordinateType z = m_eq[0] + m_eq[1] * P.u[m_X] + m_eq[2] * P.u[m_Y] + m_eq[3] * P.u[m_X] * P.u[m_X] + m_eq[4] * P.u[m_X] * P.u[m_Y] + m_eq[5] * P.u[m_Y] * P.u[m_Y];
PointCoordinateType z = m_eq[0]
+ m_eq[1] * Plocal.x
+ m_eq[2] * Plocal.y
+ m_eq[3] * Plocal.x * Plocal.x
+ m_eq[4] * Plocal.x * Plocal.y
+ m_eq[5] * Plocal.y * Plocal.y;

if (nearestPoint)
{
nearestPoint->u[m_X] = P.u[m_X];
nearestPoint->u[m_Y] = P.u[m_Y];
nearestPoint->u[m_Z] = z;
*nearestPoint = m_localOrientationInv * CCVector3(Plocal.x, Plocal.y, z);
}

return static_cast<ScalarType>(std::abs(P.u[m_Z] - z));
return static_cast<ScalarType>(std::abs(Plocal.z - z));
}

protected:

//! Quadric equation
PointCoordinateType m_eq[6];
//! Height function first dimension (0=X, 1=Y, 2=Z)
unsigned char m_X;
//! Height function second dimension (0=X, 1=Y, 2=Z)
unsigned char m_Y;
//! Height function third dimension (0=X, 1=Y, 2=Z)
unsigned char m_Z;
//! Quadric local 'orientation' system
SquareMatrix m_localOrientation;
//! Quadric local 'orientation' system (inverse)
SquareMatrix m_localOrientationInv;
//! Model gravity center
CCVector3 m_gravityCenter;

Expand Down Expand Up @@ -202,17 +199,15 @@ LocalModel* LocalModel::New(LOCAL_MODEL_TYPES type,

case QUADRIC:
{
Tuple3ub dims;
const PointCoordinateType* eq = subset.getQuadric(&dims);
SquareMatrix toLocalCS;
const PointCoordinateType* eq = subset.getQuadric(&toLocalCS);
if (eq)
{
return new QuadricLocalModel( eq,
dims.x,
dims.y,
dims.z,
toLocalCS,
*subset.getGravityCenter(), //should be ok as the quadric computation succeeded!
center,
squaredRadius);
squaredRadius );
}
}
break;
Expand Down
Loading
Loading