Merge remote-tracking branch 'cgal/5.1.x-branch' into HEAD

This commit is contained in:
Sébastien Loriot 2021-04-17 11:11:28 +02:00
commit cbd95907cd
14 changed files with 244 additions and 155 deletions

View File

@ -1680,7 +1680,7 @@ bool IO_base_test<Base_geom_traits>::read_xcurve(InputStream_& is,
read_point(is, p2);
assert(p1 != p2);
unsigned int flag;
unsigned int flag = static_cast<unsigned int>(-1);
is >> flag;
if (flag == 1) {
X_monotone_curve_2::Direction_3 normal;

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

View File

@ -92,6 +92,11 @@ When you hit the *Configure* button, you must:
<li>select *Specify toolchain file for cross compilation* (the file `vcpkg.cmake` within the directory
where you have installed `vcpkg`, e.g. `C:/dev/vcpkg/scripts/buildsystems/vcpkg.cmake`).</li>
</ul>
\cgalFigureBegin{toolchain,toolchain.png}
The box to check to get to the toolchain option
\cgalFigureEnd
Once the configuration process is done, tick *Advanced* and *Grouped* in `cmake-gui`.
You will see entries for where header files and libraries are taken from.

View File

@ -21,13 +21,17 @@ generated polygons is not known since it depends on the generated points.
- `PointGenerator::value_type` is equivalent to
`Traits::Point_2` and `OutputIterator::value_type`.
The default traits class `Default_traits` is the kernel in which
`Traits::Point_2` is defined.
\sa `CGAL::Random_points_in_disc_2<Point_2, Creator>`
\sa `CGAL::Random_points_in_square_2<Point_2, Creator>`
\cgalHeading{Preconditions}
- The number of unique points in the first \f$ n\f$ points generated by `pg` is at least `3`.
- The unique points in the first \f$ n\f$ points generated by `pg` do not all lie on the same line.
\cgalHeading{Implementation}
The implementation is based on the method of eliminating self-intersections in

View File

@ -154,7 +154,7 @@ bool Less_segments<ForwardIterator, PolygonTraits>::
less_than_in_tree(Vertex_index new_edge, Vertex_index tree_edge) const
{
#if defined(CGAL_POLY_GENERATOR_DEBUG)
std::cout << "less_than_in_tree" << std::endl;
std::cout << "less_than_in_tree; new: " << new_edge.as_int() << " tree edge: " << tree_edge.as_int() << std::endl;
#endif
CGAL_polygon_precondition(
m_vertex_data->edges[tree_edge.as_int()].is_in_tree);
@ -179,6 +179,52 @@ less_than_in_tree(Vertex_index new_edge, Vertex_index tree_edge) const
m_vertex_data->point(mid),
m_vertex_data->point(right)));
m_vertex_data->is_simple_result = false;
// need to handle the specific combinations:
// as the standard x;x+k swap (see below) will not work
if (m_vertex_data->edges[tree_edge.as_int()].is_left_to_right)
{
// x+1 x x+2
// This is actually already handled in the insertion event, when the orientation returns "COPLANAR"
// but leaving the code below for completion.
if (m_vertex_data->next(mid) == left || m_vertex_data->next(mid) == right)
{
// swap mid & left
m_vertex_data->conflict1 = m_vertex_data->prev(mid);
m_vertex_data->conflict2 = left;
return true;
}
// x-2 x x-1
else if (m_vertex_data->prev(mid) == left || m_vertex_data->prev(mid) == right)
{
// swap mid & right
m_vertex_data->conflict1 = left;
m_vertex_data->conflict2 = mid;
return true;
}
}
else // right to left
{
// x+2 x x+1
if (m_vertex_data->next(mid) == left || m_vertex_data->next(mid) == right)
{
// swap mid & right
m_vertex_data->conflict1 = m_vertex_data->prev(mid);
m_vertex_data->conflict2 = right;
return true;
}
// x-1 x x-2
// This is actually already handled in the insertion event, when the orientation returns "COPLANAR"
// but leaving the code below for completion.
else if (m_vertex_data->prev(mid) == left || m_vertex_data->prev(mid) == right)
{
// swap mid & left
m_vertex_data->conflict1 = right;
m_vertex_data->conflict2 = mid;
return true;
}
}
Vertex_index mid_succ = m_vertex_data->next(mid);
if (mid_succ.as_int() <= (std::min)(left.as_int(), right.as_int()))
{
@ -515,6 +561,15 @@ check_simple_polygon(Iterator points_begin, Iterator points_end,
typedef Iterator ForwardIterator;
typedef std::set<i_generator_polygon::Vertex_index,
i_generator_polygon::Less_segments<ForwardIterator,PolygonTraits> > Tree;
#if defined(CGAL_POLY_GENERATOR_DEBUG)
Iterator it;
std::cout << "In check_simple_polygon the points are: " << std::endl;
for(it = points_begin; it != points_end; it++)
std::cout << *it << " ";
std::cout << std::endl;
#endif
i_generator_polygon::Vertex_data<ForwardIterator, PolygonTraits>
vertex_data(points_begin, points_end, polygon_traits);
Tree tree(&vertex_data);
@ -556,8 +611,8 @@ void make_simple_polygon(Iterator points_begin, Iterator points_end,
swap_interval = check_simple_polygon(points_begin,
points_end, polygon_traits);
#if defined(CGAL_POLY_GENERATOR_DEBUG)
std::cout << swap_interval.first << " "
<< swap_interval.second << std::endl;
std::cout << "To swap: " << swap_interval.first << " "
<< swap_interval.second << std::endl;
CGAL_polygon_assertion(swap_interval.first >= -1 &&
swap_interval.second >= -1 &&
swap_interval.first < size &&

View File

@ -46,6 +46,21 @@ OutputIterator random_polygon_2(std::size_t n, OutputIterator result,
copy_n_unique(pg, n, std::back_inserter(vertices), traits);
CGAL_assertion(!duplicate_points(vertices.begin(), vertices.end(), traits));
CGAL_precondition_code(auto d = std::distance(vertices.begin(), vertices.end());)
CGAL_precondition(d > 2);
CGAL_precondition_code(const Point_2& p = *(vertices.begin());)
CGAL_precondition_code(const Point_2& q = *(std::next(vertices.begin()));)
CGAL_precondition_code(auto third_it = std::next(vertices.begin(), 2);)
CGAL_precondition_code(bool all_collinear = true;)
CGAL_precondition_code(do {)
CGAL_precondition_code( if(traits.orientation_2_object()(p, q, *third_it) != CGAL::COLLINEAR) {)
CGAL_precondition_code( all_collinear = false;)
CGAL_precondition_code( break;)
CGAL_precondition_code( })
CGAL_precondition_code(} while(++third_it != vertices.end());)
CGAL_precondition(!all_collinear);
#ifndef CGAL_DONT_SHUFFLE_IN_RANDOM_POLYGON_2
CGAL::cpp98::random_shuffle(vertices.begin(), vertices.end());
#endif

View File

@ -22,56 +22,82 @@
// Random Simple Polygons: Test Program
// ============================================================================
#define CGAL_DONT_SHUFFLE_IN_RANDOM_POLYGON_2
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Homogeneous.h>
#include <CGAL/point_generators_2.h>
#include <CGAL/random_polygon_2.h>
#include <CGAL/Polygon_2.h>
#include <array>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <list>
typedef CGAL::Simple_cartesian< double > CR;
typedef CGAL::Point_2< CR > CPoint_2;
typedef std::list<CPoint_2> CContainer;
typedef CGAL::Polygon_2<CR, CContainer> CPolygon_2;
typedef CGAL::Creator_uniform_2<double, CPoint_2> CCreator;
typedef CGAL::Random_points_in_square_2<CPoint_2, CCreator> CPoint_generator;
template <typename K>
void test_fold()
{
// (-5, -7) is on [(-9, 5); (-2, -16)]
std::array<typename K::Point_2, 4> input {typename K::Point_2{-5,-7},{7,-85},{-9,5},{-2,-16}};
typedef CGAL::Homogeneous< double > HR;
typedef CGAL::Point_2< HR > HPoint_2;
typedef std::list<HPoint_2> HContainer;
typedef CGAL::Polygon_2<HR, HContainer> HPolygon_2;
typedef CGAL::Creator_uniform_2<double, HPoint_2> HCreator;
typedef CGAL::Random_points_in_square_2<HPoint_2, HCreator> HPoint_generator;
int i = 0;
do
{
std::cout << "permutation #" << i++ << std::endl;
for(const auto& pt : input)
std::cout << " (" << pt << ")";
std::cout << std::endl;
int main() {
CGAL::Polygon_2<K> polygon;
CGAL::random_polygon_2(input.size(), std::back_inserter(polygon), input.begin());
CPolygon_2 polygon1;
if (! polygon.is_simple())
{
std::cerr << "ERROR: polygon is not simple." << std::endl;
assert(false);
}
}
while(std::next_permutation(input.begin(), input.end()));
}
template <typename K>
void test_random()
{
typedef CGAL::Point_2< K > Point_2;
typedef std::list<Point_2> Container;
typedef CGAL::Polygon_2<K, Container> Polygon_2;
typedef CGAL::Creator_uniform_2<double, Point_2> Creator;
typedef CGAL::Random_points_in_square_2<Point_2, Creator> Point_generator;
Polygon_2 polygon;
int n = 50;
// create a polygon
CGAL::random_polygon_2(n, std::back_inserter(polygon1),
CPoint_generator(0.5));
CGAL::random_polygon_2(n, std::back_inserter(polygon), Point_generator(0.5));
// make sure it is simple
if (! polygon1.is_simple())
if (! polygon.is_simple())
{
std::cerr << "ERROR: polygon is not simple." << std::endl;
return 1;
assert(false);
}
HPolygon_2 polygon2;
// create a polygon
CGAL::random_polygon_2(n, std::back_inserter(polygon2),
HPoint_generator(0.5));
// make sure it is simple
if (! polygon1.is_simple())
{
std::cerr << "ERROR: polygon is not simple." << std::endl;
return 1;
}
return 0;
}
// EOF
int main()
{
typedef CGAL::Simple_cartesian<double> CK;
typedef CGAL::Homogeneous<double> HK;
test_random<CK>();
test_random<HK>();
test_fold<CK>();
test_fold<HK>();
std::cout << "Done!" << std::endl;
return EXIT_SUCCESS;
}

View File

@ -31,20 +31,35 @@ if( NOT GMP_in_cache )
DOC "The directory containing the GMP header files"
)
find_library(GMP_LIBRARIES NAMES gmp libgmp-10 mpir
find_library(GMP_LIBRARY_RELEASE NAMES gmp libgmp-10 mpir
HINTS ENV GMP_LIB_DIR
ENV GMP_DIR
${CGAL_INSTALLATION_PACKAGE_DIR}/auxiliary/gmp/lib
PATH_SUFFIXES lib
DOC "Path to the GMP library"
DOC "Path to the Release GMP library"
)
if ( GMP_LIBRARIES )
get_filename_component(GMP_LIBRARIES_DIR ${GMP_LIBRARIES} PATH CACHE )
find_library(GMP_LIBRARY_DEBUG NAMES gmpd gmp libgmp-10 mpir
HINTS ENV GMP_LIB_DIR
ENV GMP_DIR
${CGAL_INSTALLATION_PACKAGE_DIR}/auxiliary/gmp/lib
PATH_SUFFIXES lib
DOC "Path to the Debug GMP library"
)
get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(IS_MULTI_CONFIG)
set(GMP_LIBRARIES debug ${GMP_LIBRARY_DEBUG} optimized ${GMP_LIBRARY_RELEASE})
else()
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(GMP_LIBRARIES ${GMP_LIBRARY_DEBUG})
else()
set(GMP_LIBRARIES ${GMP_LIBRARY_RELEASE})
endif()
endif()
# Attempt to load a user-defined configuration for GMP if couldn't be found
if ( NOT GMP_INCLUDE_DIR OR NOT GMP_LIBRARIES_DIR )
if ( NOT GMP_INCLUDE_DIR OR NOT GMP_LIBRARIES)
include( GMPConfig OPTIONAL )
endif()

View File

@ -38,38 +38,6 @@ typedef CGAL::Interpolation_traits_2<K> Traits;
typedef std::vector<std::pair<Vertex_handle, Coord_type> > Coordinate_vector;
template <typename V, typename T>
struct Value_function
{
typedef V argument_type;
typedef std::pair<T, bool> result_type;
result_type operator()(const argument_type& a) const {
return result_type(a->info().value, true);
}
};
template <typename V, typename G>
struct Gradient_function
: public std::iterator<std::output_iterator_tag, void, void, void, void>
{
typedef V argument_type;
typedef std::pair<G, bool> result_type;
result_type operator()(const argument_type& a) const {
return std::make_pair(a->info().gradient, a->info().gradient != CGAL::NULL_VECTOR);
}
const Gradient_function& operator=(const std::pair<V, G>& p) const {
p.first->info().gradient = p.second;
return *this;
}
const Gradient_function& operator++(int) const { return *this; }
const Gradient_function& operator*() const { return *this; }
};
int main()
{
//number of sample points:
@ -94,9 +62,15 @@ int main()
Delaunay_triangulation T;
// Note that a supported alternative to creating the functors below is to use lambdas
Value_function<Vertex_handle, Coord_type> value_function;
Gradient_function<Vertex_handle, Vector> gradient_function;
auto value_function = [](const Vertex_handle& a) -> std::pair<Coord_type, bool>
{
return std::make_pair(a->info().value, true);
};
auto gradient_function = [](const Vertex_handle& a) -> std::pair<Vector, bool>
{
return std::make_pair(a->info().gradient, a->info().gradient != CGAL::NULL_VECTOR);
};
//parameters for quadratic function:
Coord_type alpha = Coord_type(1.0),

View File

@ -8,6 +8,8 @@
#include <CGAL/Triangulation_vertex_base_with_info_2.h>
#include <CGAL/Regular_triangulation_2.h>
#include <boost/iterator/function_output_iterator.hpp>
#include <iostream>
#include <iterator>
#include <utility>
@ -38,44 +40,26 @@ typedef CGAL::Triangulation_data_structure_2<Vb, Fb> Tds;
typedef CGAL::Regular_triangulation_2<K, Tds> Regular_triangulation;
typedef Regular_triangulation::Vertex_handle Vertex_handle;
template <typename V, typename T>
struct Value_function
{
typedef V argument_type;
typedef std::pair<T, bool> result_type;
result_type operator()(const argument_type& a) const {
return result_type(a->info().value, true);
}
};
template <typename V, typename G>
struct Gradient_function
: public std::iterator<std::output_iterator_tag, void, void, void, void>
{
typedef V argument_type;
typedef std::pair<G, bool> result_type;
result_type operator()(const argument_type& a) const {
return std::make_pair(a->info().gradient, a->info().gradient != CGAL::NULL_VECTOR);
}
const Gradient_function& operator=(const std::pair<V, G>& p) const {
p.first->info().gradient = p.second;
return *this;
}
const Gradient_function& operator++(int) const { return *this; }
const Gradient_function& operator*() const { return *this; }
};
int main()
{
Regular_triangulation rt;
// Note that a supported alternative to creating the functors below is to use lambdas
Value_function<Vertex_handle, Coord_type> value_function;
Gradient_function<Vertex_handle, Vector> gradient_function;
auto value_function = [](const Vertex_handle& a) -> std::pair<Coord_type, bool>
{
return std::make_pair(a->info().value, true);
};
auto gradient_function = [](const Vertex_handle& a) -> std::pair<Vector, bool>
{
return std::make_pair(a->info().gradient, a->info().gradient != CGAL::NULL_VECTOR);
};
auto gradient_output_iterator
= boost::make_function_output_iterator
([](const std::pair<Vertex_handle, Vector>& p)
{
p.first->info().gradient = p.second;
});
// parameters for spherical function:
Coord_type a(0.25), bx(1.3), by(-0.7), c(0.2);
@ -89,7 +73,7 @@ int main()
}
CGAL::sibson_gradient_fitting_rn_2(rt,
gradient_function,
gradient_output_iterator,
CGAL::Identity<std::pair<Vertex_handle, Vector> >(),
value_function,
Traits());

View File

@ -249,6 +249,7 @@ struct Enriched_pixel {
Domain_type domain;
Image_word_type word;
bool on_edge_of_the_cube;
bool on_corner_of_the_cube;
}; // end struct template Enriched_pixel<Pix,P,D,C>
} // end namespace internal
@ -536,17 +537,21 @@ polylines_to_protect
double x = pixel[0] * vx + tx;
double y = pixel[1] * vy + ty;
double z = pixel[2] * vz + tz;
square[ii][jj].on_edge_of_the_cube =
( ( ( 0 == pixel[0] || (xdim - 1) == pixel[0] ) ? 1 : 0 )
+
( ( 0 == pixel[1] || (ydim - 1) == pixel[1] ) ? 1 : 0 )
+
( ( 0 == pixel[2] || (zdim - 1) == pixel[2] ) ? 1 : 0 ) > 1 );
short sum_faces = ((0 == pixel[0] || (xdim - 1) == pixel[0]) ? 1 : 0)
+ ((0 == pixel[1] || (ydim - 1) == pixel[1]) ? 1 : 0)
+ ((0 == pixel[2] || (zdim - 1) == pixel[2]) ? 1 : 0);
square[ii][jj].on_edge_of_the_cube = (sum_faces > 1);
square[ii][jj].on_corner_of_the_cube = (sum_faces > 2);
#ifdef CGAL_MESH_3_DEBUG_POLYLINES_TO_PROTECT
if(square[ii][jj].on_edge_of_the_cube) {
std::cerr << " Pixel(" << pixel[0] << ", " << pixel[1] << ", "
<< pixel[2] << ") is on edge\n";
}
if (square[ii][jj].on_corner_of_the_cube) {
std::cerr << " Pixel(" << pixel[0] << ", " << pixel[1] << ", "
<< pixel[2] << ") is on corner\n";
}
#endif // CGAL_MESH_3_DEBUG_POLYLINES_TO_PROTECT
square[ii][jj].point = Point_3(x, y, z);
@ -582,10 +587,10 @@ polylines_to_protect
bool out01 = null(square[0][1].domain);
bool out11 = null(square[1][1].domain);
bool on_edge00 = square[0][0].on_edge_of_the_cube;
bool on_edge10 = square[1][0].on_edge_of_the_cube;
bool on_edge01 = square[0][1].on_edge_of_the_cube;
bool on_edge11 = square[1][1].on_edge_of_the_cube;
bool is_corner00 = square[0][0].on_corner_of_the_cube;
bool is_corner10 = square[1][0].on_corner_of_the_cube;
bool is_corner01 = square[0][1].on_corner_of_the_cube;
bool is_corner11 = square[1][1].on_corner_of_the_cube;
//
// Protect the edges of the cube
@ -593,26 +598,26 @@ polylines_to_protect
if(pix00[axis_xx] == 0 &&
! ( out00 && out01 ) )
{
g_manip.try_add_edge(g_manip.get_vertex(p00, on_edge00),
g_manip.get_vertex(p01, on_edge01));
g_manip.try_add_edge(g_manip.get_vertex(p00, is_corner00),
g_manip.get_vertex(p01, is_corner01));
}
if(pix11[axis_xx] == image_dims[axis_xx]-1 &&
! ( out10 && out11 ) )
{
g_manip.try_add_edge(g_manip.get_vertex(p10, on_edge10),
g_manip.get_vertex(p11, on_edge11));
g_manip.try_add_edge(g_manip.get_vertex(p10, is_corner10),
g_manip.get_vertex(p11, is_corner11));
}
if(pix00[axis_yy] == 0 &&
! ( out00 && out10 ) )
{
g_manip.try_add_edge(g_manip.get_vertex(p00, on_edge00),
g_manip.get_vertex(p10, on_edge10));
g_manip.try_add_edge(g_manip.get_vertex(p00, is_corner00),
g_manip.get_vertex(p10, is_corner10));
}
if(pix11[axis_yy] == image_dims[axis_yy]-1 &&
! ( out01 && out11 ) )
{
g_manip.try_add_edge(g_manip.get_vertex(p01, on_edge01),
g_manip.get_vertex(p11, on_edge11));
g_manip.try_add_edge(g_manip.get_vertex(p01, is_corner01),
g_manip.get_vertex(p11, is_corner11));
}
} // end of scope for outIJ and on_edgeIJ

View File

@ -114,32 +114,35 @@ int main(int argc, const char** argv)
* */
);
// OR call the ICP registration method from pointmatcher and apply the transformation to pwn2
bool converged =
CGAL::pointmatcher::register_point_sets
(pwns1, pwns2,
params::point_map(Point_map()).normal_map(Normal_map())
.point_set_filters(point_set_1_filters)
.matcher(matcher)
.outlier_filters(outlier_filters)
.error_minimizer(error_minimizer)
.transformation_checkers(transformation_checkers)
.inspector(inspector)
.logger(logger),
params::point_map(Point_map()).normal_map(Normal_map())
.point_set_filters(point_set_2_filters)
.transformation(res.first) /* pass the above computed transformation as initial transformation.
* as a result, the registration will require less iterations to converge.
* */
);
if (converged)
std::cerr << "Success" << std::endl;
else
bool converged = false;
do
{
std::cerr << "Failure" << std::endl;
return EXIT_FAILURE;
// OR call the ICP registration method from pointmatcher and apply the transformation to pwn2
converged =
CGAL::pointmatcher::register_point_sets
(pwns1, pwns2,
params::point_map(Point_map()).normal_map(Normal_map())
.point_set_filters(point_set_1_filters)
.matcher(matcher)
.outlier_filters(outlier_filters)
.error_minimizer(error_minimizer)
.transformation_checkers(transformation_checkers)
.inspector(inspector)
.logger(logger),
params::point_map(Point_map()).normal_map(Normal_map())
.point_set_filters(point_set_2_filters)
.transformation(res.first) /* pass the above computed transformation as initial transformation.
* as a result, the registration will require less iterations to converge.
* */
);
// Algorithm may randomly not converge, repeat until it does
if (converged)
std::cerr << "Success" << std::endl;
else
std::cerr << "Did not converge, try again" << std::endl;
}
while (!converged);
std::ofstream out("pwns2_aligned.ply");
if (!out ||

View File

@ -74,6 +74,8 @@ struct Vertex_index {
explicit Vertex_index(Index_t i): m_i(i) {}
Index_t as_int() const {return m_i;}
Vertex_index operator++() {++m_i; return *this; }
bool operator==(const Vertex_index& other) const { return (m_i == other.m_i); }
private:
Index_t m_i;
};

View File

@ -772,6 +772,7 @@ bool Scene_edit_box_item::eventFilter(QObject *obj, QEvent *event)
int type, picked;
d->picked_pixel = e->pos();
d->picking(type, picked, viewer);
viewer->makeCurrent();
if(type !=-1)
{
bool found = false;