Skip to content

Commit

Permalink
Sync with c27a90f
Browse files Browse the repository at this point in the history
  • Loading branch information
jdumas committed May 5, 2021
1 parent 7d05eef commit b24c2f4
Show file tree
Hide file tree
Showing 36 changed files with 961 additions and 316 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/LagrangeOptions.cmake)
endif()

################################################################################
project(Lagrange VERSION 4.2.0)
project(Lagrange VERSION 4.3.0)

# Detects whether internal libs are available
if(IS_DIRECTORY "${PROJECT_SOURCE_DIR}/cmake/recipes/internal")
Expand All @@ -65,7 +65,7 @@ if(ARPACK_BUILD_FROM_SOURCE)
enable_language(Fortran)
endif()

# Tests and examples
# General CMake options
option(LAGRANGE_UNIT_TESTS "Build all unit tests" ${LAGRANGE_TOPLEVEL_PROJECT})
option(LAGRANGE_PERFORMANCE_TESTS "Build all performance tests" ${LAGRANGE_TOPLEVEL_PROJECT})
option(LAGRANGE_EXAMPLES "Build all examples" ${LAGRANGE_TOPLEVEL_PROJECT})
Expand All @@ -74,6 +74,7 @@ option(LAGRANGE_INSTALL "Enable installation" ${LAGRANGE_
option(LAGRANGE_DOCUMENTATION "Build Doxygen documentation" OFF)
option(LAGRANGE_COPY_RUNTIME_DEPS "Copy runtime dependencies into executable folders" ${LAGRANGE_TOPLEVEL_PROJECT})
option(LAGRANGE_CI_BUILD "Building for continuous integration" OFF)
option(LAGRANGE_WITH_TRACY "Build tracy client with Lagrange" OFF)

# Third-party dependency management
option(LAGRANGE_EXTERNAL_FIRST "Third-party libs: prefer public mirrors over corporate ones" OFF)
Expand Down
25 changes: 25 additions & 0 deletions cmake/lagrange/lagrange_filter_flags.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
# Copyright 2021 Adobe. All rights reserved.
# This file is licensed to you under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. You may obtain a copy
# of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
# OF ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.
#
function(lagrange_filter_flags flags)
include(CheckCXXCompilerFlag)
set(output_flags)
foreach(FLAG IN ITEMS ${${flags}})
string(REPLACE "=" "-" FLAG_VAR "${FLAG}")
if(NOT DEFINED IS_SUPPORTED_${FLAG_VAR})
check_cxx_compiler_flag("${FLAG}" IS_SUPPORTED_${FLAG_VAR})
endif()
if(IS_SUPPORTED_${FLAG_VAR})
list(APPEND output_flags ${FLAG})
endif()
endforeach()
set(${flags} PARENT_SCOPE ${output_flags})
endfunction()
11 changes: 11 additions & 0 deletions cmake/lagrange/lagrange_global_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,14 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# https://developercommunity.visualstudio.com/content/problem/48897/c1090-pdb-api-call-failed-error-code-23.html
add_compile_options(/FS)
endif()

if(LAGRANGE_WITH_TRACY)
include(lagrange_filter_flags)
set(LAGRANGE_GLOBAL_FLAGS
"-fno-omit-frame-pointer"
"-g"
)
lagrange_filter_flags(LAGRANGE_GLOBAL_FLAGS)
message(STATUS "Adding global flags: ${LAGRANGE_GLOBAL_FLAGS}")
add_compile_options(${LAGRANGE_GLOBAL_FLAGS})
endif()
49 changes: 49 additions & 0 deletions cmake/recipes/external/tracy.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#
# Copyright 2021 Adobe. All rights reserved.
# This file is licensed to you under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. You may obtain a copy
# of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
# OF ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.
#
if(TARGET tracy::client)
return()
endif()

message(STATUS "Third-party (external): creating target 'tracy::client'")

include(FetchContent)
FetchContent_Declare(
tracy
GIT_REPOSITORY https://github.com/wolfpld/tracy.git
GIT_TAG v0.7.7
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(tracy)

################################################################################
# Client
################################################################################

# Do not forget to add global compilation flags '-fno-omit-frame-pointer' and '-g'!
add_library(tracy_client ${tracy_SOURCE_DIR}/TracyClient.cpp)
add_library(tracy::client ALIAS tracy_client)

include(GNUInstallDirs)
target_include_directories(tracy_client SYSTEM INTERFACE
$<BUILD_INTERFACE:${tracy_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

target_compile_definitions(tracy_client PUBLIC TRACY_ENABLE)

target_compile_features(tracy_client PUBLIC cxx_std_11)
set_target_properties(tracy_client PROPERTIES ENABLE_EXPORTS ON)

# Install rules
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME tracy)
install(TARGETS tracy_client EXPORT Tracy_Targets)
install(EXPORT Tracy_Targets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/tracy NAMESPACE tracy::)
5 changes: 5 additions & 0 deletions modules/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ target_link_libraries(lagrange_core PUBLIC
TBB::tbb
)

if(LAGRANGE_WITH_TRACY)
include(tracy)
target_link_libraries(lagrange_core PUBLIC tracy::client)
endif()

# precompile headers target. Link to this target in tests or modules with
# lots of compilation units (.cpp files) to speed up compilation time!
if(LAGRANGE_USE_PCH)
Expand Down
11 changes: 4 additions & 7 deletions modules/core/include/lagrange/DisjointSets.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class DisjointSets
std::iota(m_parent.begin(), m_parent.end(), IndexType(0));
}

IndexType size() const { return safe_cast<IndexType>(m_parent.size()); }

void clear() { m_parent.clear(); }

IndexType find(IndexType i)
{
LA_ASSERT(i >= 0 && i < safe_cast<IndexType>(m_parent.size()), "Index out of bound!");
Expand All @@ -51,8 +55,6 @@ class DisjointSets
return m_parent[root_j] = root_i;
}

void clear() { m_parent.clear(); }

std::vector<std::vector<IndexType>> extract_disjoint_sets()
{
const IndexType num_entries = size();
Expand Down Expand Up @@ -95,11 +97,6 @@ class DisjointSets
return counter;
}

IndexType& operator[](IndexType i) { return m_parent[i]; }
const IndexType& operator[](IndexType i) const { return m_parent[i]; }

IndexType size() const { return safe_cast<IndexType>(m_parent.size()); }

private:
std::vector<IndexType> m_parent;
};
Expand Down
72 changes: 72 additions & 0 deletions modules/core/include/lagrange/ExactPredicates.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,91 @@ namespace lagrange {
class ExactPredicates
{
public:
///
/// Factory method to create an exact predicate engine. Currently only the only engine supported
/// is "shewchuk", so you might as well create it directly.
///
/// @param[in] engine Engine name.
///
/// @return The created engine.
///
static std::unique_ptr<ExactPredicates> create(const std::string& engine);

public:
ExactPredicates() = default;
virtual ~ExactPredicates() = default;

public:
///
/// Tests whether p1, p2, and p3 are collinear in 3D. This works by calling orient2D
/// successively on the xy, yz and zx projections of p1, p2 p3.
///
/// @param p1 First 3D point.
/// @param p2 Second 3D point.
/// @param p3 Third 3D point.
///
/// @return 1 if the points are collinear, 0 otherwise.
///
virtual short collinear3D(double p1[3], double p2[3], double p3[3]) const;

///
/// Exact 2D orientation test.
///
/// @param p1 First 2D point.
/// @param p2 Second 2D point.
/// @param p3 Third 2D point.
///
/// @return Return a positive value if the points p1, p2, and p3 occur in counterclockwise
/// order; a negative value if they occur in clockwise order; and zero if they are
/// collinear.
///
virtual short orient2D(double p1[2], double p2[2], double p3[2]) const = 0;

///
/// Exact 3D orientation test.
///
/// @param p1 First 3D point.
/// @param p2 Second 3D point.
/// @param p3 Third 3D point.
/// @param p4 Fourth 3D point.
///
/// @return Return a positive value if the point pd lies below the plane passing through p1,
/// p2, and p3; "below" is defined so that p1, p2, and p3 appear in counterclockwise
/// order when viewed from above the plane. Returns a negative value if pd lies
/// above the plane. Returns zero if the points are coplanar.
///
virtual short orient3D(double p1[3], double p2[3], double p3[3], double p4[3]) const = 0;

///
/// Exact 2D incircle test.
///
/// @param p1 First 2D point.
/// @param p2 Second 2D point.
/// @param p3 Third 2D point.
/// @param p4 Fourth 3D point.
///
/// @return Return a positive value if the point pd lies inside the circle passing through
/// p1, p2, and p3; a negative value if it lies outside; and zero if the four points
/// are cocircular. The points p1, p2, and p3 must be in counterclockwise order, or
/// the sign of the result will be reversed.
///
virtual short incircle(double p1[2], double p2[2], double p3[2], double p4[2]) const = 0;

///
/// Exact 3D insphere test.
///
/// @param p1 First 3D point.
/// @param p2 Second 3D point.
/// @param p3 Third 3D point.
/// @param p4 Fourth 3D point.
/// @param p5 Fifth 3D point.
///
/// @return Return a positive value if the point p5 lies inside the sphere passing through
/// p1, p2, p3, and p4; a negative value if it lies outside; and zero if the five
/// points are cospherical. The points p1, p2, p3, and p4 must be ordered so that
/// they have a positive orientation (as defined by orient3d()), or the sign of the
/// result will be reversed.
///
virtual short insphere(double p1[3], double p2[3], double p3[3], double p4[3], double p5[3])
const = 0;
};
Expand Down
63 changes: 22 additions & 41 deletions modules/core/include/lagrange/ExactPredicatesShewchuk.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,54 +11,35 @@
*/
#pragma once

#include <iostream>
#include <memory>
#include <mutex>

#include <lagrange/ExactPredicates.h>
#include <lagrange/common.h>
#include <lagrange/predicates.h>

namespace lagrange {

class ExactPredicatesShewchuk : public ExactPredicates
{
private:
static void exact_init()
{
// Make sure that exact_init() is only called once, even if multiple threads are
// attempting to call it around the same time.
// We can alternatively use Meyer's singleton.
static std::once_flag once_flag;
std::call_once(once_flag, []() { lagrange::exactinit(); });
}

public:
ExactPredicatesShewchuk() { exact_init(); }
ExactPredicatesShewchuk();

public:
virtual short orient2D(double p1[2], double p2[2], double p3[2]) const
{
auto r = lagrange::orient2d(p1, p2, p3);
return (r == 0) ? 0 : ((r > 0) ? 1 : -1);
}

virtual short orient3D(double p1[3], double p2[3], double p3[3], double p4[3]) const
{
auto r = lagrange::orient3d(p1, p2, p3, p4);
return (r == 0) ? 0 : ((r > 0) ? 1 : -1);
}

virtual short incircle(double p1[2], double p2[2], double p3[2], double p4[2]) const
{
auto r = lagrange::incircle(p1, p2, p3, p4);
return (r == 0) ? 0 : ((r > 0) ? 1 : -1);
}

virtual short insphere(double p1[3], double p2[3], double p3[3], double p4[3], double p5[3])
const
{
auto r = lagrange::insphere(p1, p2, p3, p4, p5);
return (r == 0) ? 0 : ((r > 0) ? 1 : -1);
}
///
/// @copydoc ExactPredicates::orient2D
///
virtual short orient2D(double p1[2], double p2[2], double p3[2]) const;

///
/// @copydoc ExactPredicates::orient2D
///
virtual short orient3D(double p1[3], double p2[3], double p3[3], double p4[3]) const;

///
/// @copydoc ExactPredicates::orient2D
///
virtual short incircle(double p1[2], double p2[2], double p3[2], double p4[2]) const;

///
/// @copydoc ExactPredicates::orient2D
///
virtual short insphere(double p1[3], double p2[3], double p3[3], double p4[3], double p5[3]) const;
};

} // namespace lagrange
19 changes: 19 additions & 0 deletions modules/core/include/lagrange/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,23 @@ spdlog::logger& logger();
///
void set_logger(std::shared_ptr<spdlog::logger> logger);

///
/// Changes the level of logger to something else in a scope.
/// Mostly used in unit tests. Don't use in the library itself.
///
/// @param[in] level New level to set temporarily.
/// @param[in] logger Which logger to apply this to, defaults to the lagrange logger
///
class ScopedLogLevel
{
public:
ScopedLogLevel(spdlog::level::level_enum, spdlog::logger& = logger());
~ScopedLogLevel();

private:
spdlog::level::level_enum m_prev_level;
spdlog::logger* m_logger;
};


} // namespace lagrange
Loading

0 comments on commit b24c2f4

Please sign in to comment.