Skip to content
New issue

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

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

Already on GitHub? # to your account

feat(Ellipse): add ellipse basic object and function to compute intersections and distances with ellipse #1072

Open
wants to merge 10 commits into
base: next
Choose a base branch
from
4 changes: 2 additions & 2 deletions bindings/python/src/image/core/raster_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
#define PYTHON_RASTER_IMAGE( dimension ) \
const auto name##dimension = \
"RasterImage" + std::to_string( dimension ) + "D"; \
pybind11::class_< RasterImage##dimension##D, CellArray##dimension##D >( \
module, name##dimension.c_str() ) \
pybind11::class_< RasterImage##dimension##D, CellArray##dimension##D, \
Identifier >( module, name##dimension.c_str() ) \
.def( pybind11::init< std::array< index_t, dimension > >() ) \
.def( \
"native_extension", &RasterImage##dimension##D::native_extension ) \
Expand Down
4 changes: 2 additions & 2 deletions bindings/python/src/mesh/core/light_regular_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
#define PYTHON_LIGHT_REGULAR_GRID( dimension ) \
const auto name##dimension = \
"LightRegularGrid" + std::to_string( dimension ) + "D"; \
pybind11::class_< LightRegularGrid##dimension##D, Grid##dimension##D >( \
module, name##dimension.c_str() ) \
pybind11::class_< LightRegularGrid##dimension##D, Grid##dimension##D, \
Identifier >( module, name##dimension.c_str() ) \
.def( pybind11::init< Point< dimension >, \
std::array< index_t, dimension >, \
std::array< double, dimension > >() ) \
Expand Down
2 changes: 1 addition & 1 deletion cmake/ConfigureEarcut.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ExternalProject_Add(earcut
BINARY_DIR ${EARCUT_PATH}/build
STAMP_DIR ${EARCUT_PATH}/stamp
GIT_REPOSITORY https://github.com/mapbox/earcut.hpp
GIT_TAG a30c14b5676adabe4714ff4173dae8a5d568ab59
GIT_TAG 7fa7aa30183849e988ae79ab2eef19f9ae97acf4
GIT_SHALLOW ON
GIT_PROGRESS ON
CMAKE_GENERATOR ${CMAKE_GENERATOR}
Expand Down
21 changes: 19 additions & 2 deletions include/geode/basic/console_progress_logger_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,33 @@ namespace geode

private:
void start( const uuid& progress_logger_id,
Logger::LEVEL level,
const std::string& message,
index_t nb_steps ) override;

void update( const uuid& progress_logger_id,
Logger::LEVEL level,
index_t current_step,
index_t nb_steps ) override;

void completed( const uuid& progress_logger_id ) override;
void completed(
const uuid& progress_logger_id, Logger::LEVEL level ) override;

void failed( const uuid& progress_logger_id ) override;
void failed(
const uuid& progress_logger_id, Logger::LEVEL level ) override;

[[deprecated]] void start( const uuid& progress_logger_id,
const std::string& message,
index_t nb_steps ) override;

[[deprecated]] void update( const uuid& progress_logger_id,
index_t current_step,
index_t nb_steps ) override;

[[deprecated]] void completed(
const uuid& progress_logger_id ) override;

[[deprecated]] void failed( const uuid& progress_logger_id ) override;

private:
IMPLEMENTATION_MEMBER( impl_ );
Expand Down
7 changes: 7 additions & 0 deletions include/geode/basic/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ namespace geode

static void set_level( LEVEL level );

template < typename... Args >
static void log( LEVEL level, const Args &...args )
{
log( level, absl::StrCat( args... ) );
}

template < typename... Args >
static void trace( const Args &...args )
{
Expand Down Expand Up @@ -96,6 +102,7 @@ namespace geode

[[nodiscard]] static Logger &instance();

static void log( LEVEL level, const std::string &message );
static void log_trace( const std::string &message );
static void log_debug( const std::string &message );
static void log_info( const std::string &message );
Expand Down
6 changes: 5 additions & 1 deletion include/geode/basic/progress_logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <string>

#include <geode/basic/common.hpp>
#include <geode/basic/logger.hpp>
#include <geode/basic/pimpl.hpp>

namespace absl
Expand All @@ -38,7 +39,10 @@ namespace geode
class opengeode_basic_api ProgressLogger
{
public:
ProgressLogger( const std::string& message, index_t nb_steps );
[[deprecated]] ProgressLogger(
const std::string& message, index_t nb_steps );
ProgressLogger(
Logger::LEVEL level, const std::string& message, index_t nb_steps );
~ProgressLogger();

index_t increment();
Expand Down
23 changes: 21 additions & 2 deletions include/geode/basic/progress_logger_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <string>

#include <geode/basic/common.hpp>
#include <geode/basic/logger.hpp>

namespace geode
{
Expand All @@ -40,16 +41,34 @@ namespace geode
virtual ~ProgressLoggerClient() = default;

virtual void start( const uuid& progress_logger_id,
Logger::LEVEL level,
const std::string& message,
index_t nb_steps ) = 0;

virtual void update( const uuid& progress_logger_id,
Logger::LEVEL level,
index_t current_step,
index_t nb_steps ) = 0;

virtual void completed( const uuid& progress_logger_id ) = 0;
virtual void completed(
const uuid& progress_logger_id, Logger::LEVEL level ) = 0;

virtual void failed( const uuid& progress_logger_id ) = 0;
virtual void failed(
const uuid& progress_logger_id, Logger::LEVEL level ) = 0;

[[deprecated]] virtual void start( const uuid& progress_logger_id,
const std::string& message,
index_t nb_steps ) = 0;

[[deprecated]] virtual void update( const uuid& progress_logger_id,
index_t current_step,
index_t nb_steps ) = 0;

[[deprecated]] virtual void completed(
const uuid& progress_logger_id ) = 0;

[[deprecated]] virtual void failed(
const uuid& progress_logger_id ) = 0;

protected:
ProgressLoggerClient() = default;
Expand Down
20 changes: 18 additions & 2 deletions include/geode/basic/progress_logger_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,32 @@ namespace geode
std::unique_ptr< ProgressLoggerClient >&& client );

static void start( const uuid& progress_logger_id,
Logger::LEVEL level,
const std::string& message,
index_t nb_steps );

static void update( const uuid& progress_logger_id,
Logger::LEVEL level,
index_t current_step,
index_t nb_steps );

static void completed( const uuid& progress_logger_id );
static void completed(
const uuid& progress_logger_id, Logger::LEVEL level );

static void failed( const uuid& progress_logger_id );
static void failed(
const uuid& progress_logger_id, Logger::LEVEL level );

[[deprecated]] static void start( const uuid& progress_logger_id,
const std::string& message,
index_t nb_steps );

[[deprecated]] static void update( const uuid& progress_logger_id,
index_t current_step,
index_t nb_steps );

[[deprecated]] static void completed( const uuid& progress_logger_id );

[[deprecated]] static void failed( const uuid& progress_logger_id );

private:
ProgressLoggerManager();
Expand Down
1 change: 1 addition & 0 deletions include/geode/basic/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#endif

#include <array>
#include <string>
#include <string_view>

namespace geode
Expand Down
110 changes: 110 additions & 0 deletions include/geode/geometry/basic_objects/ellipse.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Copyright (c) 2019 - 2025 Geode-solutions
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/

#pragma once

#include <geode/geometry/common.hpp>
#include <geode/geometry/frame.hpp>

namespace geode
{
FORWARD_DECLARATION_DIMENSION_CLASS( OwnerEllipse );
FORWARD_DECLARATION_DIMENSION_CLASS( Point );
FORWARD_DECLARATION_DIMENSION_CLASS( Frame );

template < index_t dimension >
using RefPoint = std::reference_wrapper< const Point< dimension > >;
ALIAS_2D_AND_3D( RefPoint );
template < index_t dimension >
using RefFrame = std::reference_wrapper< const Frame< dimension > >;
ALIAS_2D_AND_3D( RefFrame );
} // namespace geode

namespace geode
{
template < typename PointType, typename FrameType, index_t dimension >
class GenericEllipse
{
public:
GenericEllipse( PointType center, FrameType axis );

GenericEllipse(
const GenericEllipse< PointType, FrameType, dimension >& other );
GenericEllipse< PointType, FrameType, dimension >& operator=(
const GenericEllipse< PointType, FrameType, dimension >& other );
GenericEllipse( GenericEllipse< PointType, FrameType, dimension >&&
other ) noexcept;
GenericEllipse< PointType, FrameType, dimension >& operator=(
GenericEllipse< PointType, FrameType, dimension >&&
other ) noexcept;

[[nodiscard]] const Point< dimension >& center() const;
[[nodiscard]] const Frame< dimension >& axes() const;

private:
PointType center_;
FrameType axes_;
};

template < index_t dimension >
class OwnerEllipse : public GenericEllipse< Point< dimension >,
Frame< dimension >,
dimension >
{
using Base =
GenericEllipse< Point< dimension >, Frame< dimension >, dimension >;

public:
explicit OwnerEllipse(
Point< dimension > center, Frame< dimension > axes );

OwnerEllipse( const OwnerEllipse< dimension >& other );
OwnerEllipse< dimension >& operator=(
const OwnerEllipse< dimension >& other );
OwnerEllipse( OwnerEllipse< dimension >&& other ) noexcept;
OwnerEllipse< dimension >& operator=(
OwnerEllipse< dimension >&& other ) noexcept;
};
ALIAS_2D_AND_3D( OwnerEllipse );

template < index_t dimension >
class Ellipse : public GenericEllipse< RefPoint< dimension >,
RefFrame< dimension >,
dimension >
{
using Base = GenericEllipse< RefPoint< dimension >,
RefFrame< dimension >,
dimension >;

public:
Ellipse(
const Point< dimension >& center, const Frame< dimension >& axes );
Ellipse( const Ellipse< dimension >& other );
Ellipse( const OwnerEllipse< dimension >& other );
Ellipse< dimension >& operator=( const Ellipse< dimension >& other );
Ellipse( Ellipse< dimension >&& other ) noexcept;
Ellipse< dimension >& operator=(
Ellipse< dimension >&& other ) noexcept;
};
ALIAS_2D_AND_3D( Ellipse );
} // namespace geode
12 changes: 9 additions & 3 deletions include/geode/geometry/detail/aabb_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,15 @@ namespace geode
bboxes, ROOT_INDEX, 0, bboxes.size() );
}
const auto grain = async::detail::auto_grain_size( bboxes.size() );
const auto nb_async_depth = std::log2( grain );
async_depth_ =
depth_ > nb_async_depth ? depth_ - nb_async_depth : depth_;
if( grain < 8 )
{
async_depth_ = 0;
}
else
{
const auto nb_async_depth = std::log2( grain );
async_depth_ = depth_ - nb_async_depth;
}
}

[[nodiscard]] index_t nb_bboxes() const
Expand Down
41 changes: 41 additions & 0 deletions include/geode/geometry/distance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ namespace geode
FORWARD_DECLARATION_DIMENSION_CLASS( Segment );
FORWARD_DECLARATION_DIMENSION_CLASS( Triangle );
FORWARD_DECLARATION_DIMENSION_CLASS( Sphere );
FORWARD_DECLARATION_DIMENSION_CLASS( Ellipse );
ALIAS_2D_AND_3D( Point );
ALIAS_2D_AND_3D( Triangle );
ALIAS_2D_AND_3D( InfiniteLine );
ALIAS_3D( Segment );
ALIAS_2D_AND_3D( Ellipse );
class Plane;
class Tetrahedron;
class Circle;
Expand Down Expand Up @@ -136,6 +138,34 @@ namespace geode
opengeode_geometry_api segment_triangle_distance(
const Segment3D& segment, const Triangle3D& triangle );

/*!
* Compute the smallest distance between two triangles
* @return a tuple containing:
* - the smallest distance.
* - the closest point on the first triangle.
* - the closest point on the second triangle.
*/
[[nodiscard]] std::tuple< double, Point3D, Point3D >
opengeode_geometry_api triangle_triangle_distance(
const Triangle3D& triangle0, const Triangle3D& triangle1 );

/*!
* Compute the smallest distance between two triangles
* @details if the two triangles are the same, return nullopt. Only non
* conformal part of triangles are considered in computation of distance,
* i.e. if the triangle have a common point, it iterates on opposite
* segment, if the triangle have a common edge, it computes distance with
* the opposite point
* @return a tuple containing:
* - the smallest distance.
* - the closest point on the first triangle.
* - the closest point on the second triangle.
*/
[[nodiscard]] std::optional< std::tuple< double, Point3D, Point3D > >
opengeode_geometry_api
triangle_triangle_distance_between_non_conformal_parts(
const Triangle3D& triangle0, const Triangle3D& triangle1 );

/*!
* Compute the distance between a point and a tetrahedron
* @return a tuple containing:
Expand Down Expand Up @@ -229,4 +259,15 @@ namespace geode
*/
[[nodiscard]] std::tuple< double, Point3D > opengeode_geometry_api
point_disk_distance( const Point3D& point, const Disk& disk );

/*!
* Compute the smallest distance between a point and an ellipse
* @return a tuple containing:
* - the smallest distance.
* - the closest point on the ellipse.
*/
template < index_t dimension >
[[nodiscard]] std::tuple< double, Point< dimension > >
point_ellipse_distance( const Point< dimension >& point,
const Ellipse< dimension >& ellipse );
} // namespace geode
Loading