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

[KSR] Cleaning up dependencies #8563

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
155 changes: 0 additions & 155 deletions Kinetic_space_partition/include/CGAL/KSP/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,11 @@
#include <map>

// CGAL includes.
#include <CGAL/Bbox_3.h>
#include <CGAL/centroid.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/Iterator_range.h>
#include <CGAL/convex_hull_2.h>
#include <CGAL/number_utils.h>
#include <CGAL/assertions.h>

#include <CGAL/Cartesian_converter.h>
#include <CGAL/linear_least_squares_fitting_2.h>
#include <CGAL/linear_least_squares_fitting_3.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>

// Boost includes.
Expand Down Expand Up @@ -70,22 +64,6 @@ decltype(auto) distance(const Point_d& p, const Point_d& q) {
return static_cast<FT>(CGAL::approximate_sqrt(sq_dist));
}

// Project 3D point onto 2D plane.
template<typename Point_3>
typename Kernel_traits<Point_3>::Kernel::Point_2
point_2_from_point_3(const Point_3& point_3) {
return typename Kernel_traits<Point_3>::Kernel::Point_2(
point_3.x(), point_3.y());
}

// Get 3D point from a 2D point.
template<typename Point_2>
typename Kernel_traits<Point_2>::Kernel::Point_3
point_3_from_point_2(const Point_2& point_2) {
return typename Kernel_traits<Point_2>::Kernel::Point_3(
point_2.x(), point_2.y(), typename Kernel_traits<Point_2>::Kernel::FT(0));
}

// Normalize vector.
template<typename Vector_d>
inline const Vector_d normalize(const Vector_d& v) {
Expand All @@ -96,7 +74,6 @@ inline const Vector_d normalize(const Vector_d& v) {
return v / static_cast<FT>(CGAL::approximate_sqrt(dot_product));
}


// Intersections. Used only in the 2D version.
// For the 3D version, see conversions.h!
template<typename Type1, typename Type2, typename ResultType>
Expand All @@ -121,40 +98,6 @@ inline const ResultType intersection(const Type1& t1, const Type2& t2) {
return out;
}

// Get boundary points from a set of points.
template<typename Point_2, typename Line_2>
void boundary_points_on_line_2(
const std::vector<Point_2>& input_range,
const std::vector<std::size_t>& indices,
const Line_2& line, Point_2& p, Point_2& q) {

using Traits = typename Kernel_traits<Point_2>::Kernel;
using FT = typename Traits::FT;
using Vector_2 = typename Traits::Vector_2;

FT min_proj_value = (std::numeric_limits<FT>::max)();
FT max_proj_value = -min_proj_value;

const auto ref_vector = line.to_vector();
const auto& ref_point = input_range[indices.front()];

for (const std::size_t index : indices) {
const auto& query = input_range[index];
const auto point = line.projection(query);
const Vector_2 curr_vector(ref_point, point);
const FT value = CGAL::scalar_product(curr_vector, ref_vector);

if (value < min_proj_value) {
min_proj_value = value;
p = point;
}
if (value > max_proj_value) {
max_proj_value = value;
q = point;
}
}
}

// Angles.

// Converts radians to degrees.
Expand Down Expand Up @@ -202,104 +145,6 @@ angle_2(const Direction_2& dir1, const Direction_2& dir2) {
return CGAL::abs(convert_angle_2(angle_2));
}

// Classes.
template<typename IVertex>
class Indexer {
public:
std::size_t operator()(const IVertex& ivertex) {
const auto pair = m_indices.insert(
std::make_pair(ivertex, m_indices.size()));
const auto& item = pair.first;
const std::size_t idx = item->second;
return idx;
}
void clear() { m_indices.clear(); }

private:
std::map<IVertex, std::size_t> m_indices;
};

template<
typename GeomTraits,
typename InputRange,
typename NeighborQuery>
class Estimate_normals_2 {

public:
using Traits = GeomTraits;
using Input_range = InputRange;
using Neighbor_query = NeighborQuery;

using Kernel = Traits;
using FT = typename Kernel::FT;
using Vector_2 = typename Kernel::Vector_2;
using Line_2 = typename Kernel::Line_2;

using Indices = std::vector<std::size_t>;

using IK = CGAL::Exact_predicates_inexact_constructions_kernel;
using IPoint_2 = typename IK::Point_2;
using ILine_2 = typename IK::Line_2;
using Converter = CGAL::Cartesian_converter<Kernel, IK>;

Estimate_normals_2(
const Input_range& input_range,
const Neighbor_query& neighbor_query) :
m_input_range(input_range),
m_neighbor_query(neighbor_query) {

CGAL_precondition(input_range.size() > 0);
}

void get_normals(std::vector<Vector_2>& normals) const {

normals.clear();
normals.reserve(m_input_range.size());

Indices neighbors;
for (std::size_t i = 0; i < m_input_range.size(); ++i) {
neighbors.clear();
m_neighbor_query(i, neighbors);
const auto line = fit_line(neighbors);
auto normal = line.to_vector();
normal = normal.perpendicular(CGAL::COUNTERCLOCKWISE);
normal = normalize(normal);
normals.push_back(normal);
}
CGAL_assertion(normals.size() == m_input_range.size());
}

private:
const Input_range& m_input_range;
const Neighbor_query& m_neighbor_query;
const Converter m_converter;

const Line_2 fit_line(const Indices& indices) const {
CGAL_assertion(indices.size() > 0);

std::vector<IPoint_2> points;
points.reserve(indices.size());
for (const std::size_t index : indices) {
const auto& point = get(m_neighbor_query.point_map(), index);
points.push_back(m_converter(point));
}
CGAL_assertion(points.size() == indices.size());

ILine_2 fitted_line;
IPoint_2 fitted_centroid;
CGAL::linear_least_squares_fitting_2(
points.begin(), points.end(),
fitted_line, fitted_centroid,
CGAL::Dimension_tag<0>());

const Line_2 line(
static_cast<FT>(fitted_line.a()),
static_cast<FT>(fitted_line.b()),
static_cast<FT>(fitted_line.c()));
return line;
}
};

#endif

} // namespace internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ class Kinetic_space_partition_3 {

using Point_3 = typename Kernel::Point_3;

using Index = std::pair<std::size_t, std::size_t>;

/*!
identifies the support of a face in the exported linear cell complex, which is either an input polygon, identified by a non-negative number, a side of the bounding box in the rotated coordinate system or a face of the octree used to partition the scene.
*/
Expand Down Expand Up @@ -126,6 +124,8 @@ class Kinetic_space_partition_3 {
using Triangle_2 = typename Kernel::Triangle_2;
using Transform_3 = CGAL::Aff_transformation_3<Kernel>;

using Index = std::pair<std::size_t, std::size_t>;

using Data_structure = KSP_3::internal::Data_structure<Kernel, Intersection_kernel>;

using IVertex = typename Data_structure::IVertex;
Expand Down Expand Up @@ -730,6 +730,7 @@ class Kinetic_space_partition_3 {
m_partition_nodes[i].m_data->face_to_volumes().clear();
}

if (m_parameters.verbose)
std::cout << "ksp v: " << m_partition_nodes[0].m_data->vertices().size() << " f: " << m_partition_nodes[0].face2vertices.size() << " vol: " << m_volumes.size() << std::endl;

return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int main(const int, const char**) {
std::vector<Point_3> vtx;
std::vector<std::vector<std::size_t> > polylist;

std::vector<FT> lambdas{0.3, 0.5, 0.7, 0.8, 0.9, 0.95, 0.99};
std::vector<FT> lambdas{0.5, 0.7, 0.8, 0.9};

bool non_empty = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,6 @@ int main(const int argc, const char** argv) {
// Algorithm.
KSR ksr(point_set, param);

FT max_d, max_dev;
std::size_t num;
ksr.estimate_detection_parameters(max_d, max_dev, num);
std::cout << "d: " << max_d << std::endl;
std::cout << "dev: " << max_dev << std::endl;
std::cout << "num: " << num << std::endl;

Timer timer;
timer.start();
std::size_t num_shapes = ksr.detect_planar_shapes(param);
Expand Down Expand Up @@ -206,7 +199,7 @@ int main(const int argc, const char** argv) {
FT after_reconstruction = timer.time();

if (polylist.size() > 0)
CGAL::IO::write_polygon_soup("building_c_" + std::to_string(parameters.graphcut_lambda) + (parameters.use_ground ? "_g" : "_") + ".off", vtx, polylist);
CGAL::IO::write_polygon_soup("polylist_" + std::to_string(parameters.graphcut_lambda) + (parameters.use_ground ? "_g" : "_") + ".off", vtx, polylist);

timer.stop();
const FT time = static_cast<FT>(timer.time());
Expand All @@ -230,7 +223,7 @@ int main(const int argc, const char** argv) {

if (polylist.size() > 0) {
non_empty = true;
CGAL::IO::write_polygon_soup("building_c_" + std::to_string(l) + (parameters.use_ground ? "_g" : "_") + ".off", vtx, polylist);
CGAL::IO::write_polygon_soup("polylist_" + std::to_string(l) + (parameters.use_ground ? "_g" : "_") + ".off", vtx, polylist);
}
}

Expand Down
2 changes: 0 additions & 2 deletions Kinetic_surface_reconstruction/include/CGAL/KSR_3/Graphcut.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
#include <CGAL/boost/graph/alpha_expansion_graphcut.h>
#include <CGAL/boost/graph/Alpha_expansion_MaxFlow_tag.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_2.h>
#include <CGAL/Delaunay_triangulation_3.h>
#include <CGAL/Cartesian_converter.h>

// Internal includes.
Expand Down
Loading