Replies: 4 comments 6 replies
-
Should be something like:
|
Beta Was this translation helpful? Give feedback.
-
vertex() is the target of the edge so you are not splitting the intersected halfedge.Also you cannot iterate over halfedge and split halfedge in the loop, this does invalidate the iterator. |
Beta Was this translation helpful? Give feedback.
-
you're almost there. You need to pick |
Beta Was this translation helpful? Give feedback.
-
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Polyhedron_incremental_builder_3.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/intersections.h> //temp
#include <cassert>
#include <vector> //temp
#include <set>
template <class HDS>
class Build_quad : public CGAL::Modifier_base<HDS>
{
public:
Build_quad() {}
void operator()(HDS &hds)
{
CGAL::Polyhedron_incremental_builder_3<HDS> B(hds, true);
B.begin_surface(4, 1, 8);
typedef typename HDS::Vertex Vertex;
typedef typename Vertex::Point Point;
B.add_vertex(Point(0, 0, 0));
B.add_vertex(Point(1, 0, 0));
B.add_vertex(Point(1, 1, 0));
B.add_vertex(Point(0, 1, 0));
B.begin_facet();
B.add_vertex_to_facet(0);
B.add_vertex_to_facet(1);
B.add_vertex_to_facet(2);
B.add_vertex_to_facet(3);
B.end_facet();
B.end_surface();
}
};
typedef CGAL::Simple_cartesian<double> Kernel;
typedef Kernel::Point_3 Point_3;
typedef Kernel::Segment_3 Segment_3;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef Polyhedron::HalfedgeDS HalfedgeDS;
typedef Kernel::Line_3 Line_3;
typedef Kernel::Vector_3 Vector_3;
// function declarations
void print_halfedgeInformation(const Polyhedron &P);
int main()
{
const double epsilon = 1e-6;
Polyhedron P;
Build_quad<HalfedgeDS> quad;
P.delegate(quad);
// VALIDATION !
print_halfedgeInformation(P);
// --------------------------------------------------------------------------------------------------------------------------------------------------------------
// Define the line given two points
Point_3 p(0, 0.5, 0);
Point_3 q(1, 0.5, 0);
Line_3 line(p, q);
// ------------------------------------------------------------------------ Find intersection points ------------------------------------------------------------
int counter = 0;
std::vector<std::pair<Point_3, Polyhedron::Halfedge_handle>> Intersection_PointSet;
for (Polyhedron::Edge_iterator eit = P.edges_begin(); eit != P.edges_end(); ++eit)
{
std::cout << " ------------------------ " << counter << " ------------------------ " << std::endl;
counter++;
Polyhedron::Halfedge_handle he = eit;
Polyhedron::Vertex_handle v1 = he->opposite()->vertex();
Polyhedron::Vertex_handle v2 = he->vertex();
std::cout << "Half-edge: (" << v1->point() << ") -> (" << v2->point() << ")" << std::endl;
Segment_3 segment(v1->point(), v2->point());
if (v1->point() != v2->point())
{
auto result = CGAL::do_intersect(line, segment); // Checks whether line and segment intersect.
if (result)
{
std::cout << "Does intersect!" << std::endl;
// Find the intersection point
auto intersection_result = CGAL::intersection(line, segment);
if (const Point_3 *p = boost::get<Point_3>(&*intersection_result))
{
std::cout << "Intersection point: " << *p << std::endl;
Intersection_PointSet.emplace_back(*p, he);
}
else
{
std::cout << "Intersection result is not a point!" << std::endl;
}
}
else
{
std::cout << " Intersection NOT found !!" << std::endl;
}
}
else
{
std::cout << "two vertices of the segment are the same! " << std::endl;
}
}
// ------------------------------------------------------------------------ Intersect points with half edges ------------------------------------------------------------
std::cout << std::endl
<< std::endl;
std::cout << "Number of intersection pointsSet are: " << Intersection_PointSet.size() << std::endl
<< std::endl
<< std::endl;
// Intersect points in the "Intersection_PointSet" with all the half-edges in a copy of P
for (const auto& p : Intersection_PointSet)
P.split_edge(p.second)->vertex()->point()=p.first;
// VALIDATION !
print_halfedgeInformation(P);
return 0;
}
// VALIDATION !
// Function implementation
void print_halfedgeInformation(const Polyhedron &P)
{
std::cout << "---------------------------------------------------" << std::endl;
std::cout << "Is it empty? " << P.is_empty() << std::endl;
std::cout << "Is it closed? " << P.is_closed() << std::endl;
std::cout << "Is it pure bivalent? " << P.is_pure_bivalent() << std::endl;
std::cout << "Is it pure quad? " << P.is_pure_quad() << std::endl;
std::cout << "Is it pure triangle? " << P.is_pure_triangle() << std::endl;
std::cout << "Is it valid? " << P.is_valid() << std::endl;
std::cout << "Size of half edges? " << P.size_of_halfedges() << std::endl;
std::cout << "---------------------------------------------------" << std::endl;
std::cout << "---------------------------------------------------" << std::endl;
int counter = 0;
for (Polyhedron::Halfedge_const_iterator he = P.halfedges_begin(); he != P.halfedges_end(); ++he)
{
std::cout << "---------------- Halfedge number: " << counter << "----------------" << std::endl;
std::cout << he->opposite()->vertex()->point() << " TO " << he->vertex()->point() << std::endl;
counter++;
}
std::cout << "---------------------------------------------------" << std::endl;
} Here is the updated code. Note that I got rid of |
Beta Was this translation helpful? Give feedback.
-
Hi,
I want to split my polyhedral surface edges at a given point.
I use
P.split_edge(edge_to_split, splitPoint);
but it returns error on the second argument (too many arguments in function call
).How can I correctly add a split a given halfedge at a given point?
This is the full code:
Beta Was this translation helpful? Give feedback.
All reactions