487
link(k3d::split_edge* Edge, bool dummy_edge = false) : edge(Edge), counter_clockwise(0), companion_clockwise(0), companion(0), m_Complete(false), m_Dummy_edge(dummy_edge)
493
if (!is_complete() && m_Dummy_edge && edge)
499
/// the split_edge associated with this link
500
k3d::split_edge* edge;
501
/// counter-clockwise link to this one
502
link* counter_clockwise;
503
/// clockwise link to the companion of this one
504
link* companion_clockwise;
505
/// link with the companion edge
507
/// true if the link is completed
512
/// complete the link, i.e. set the actual companion and face_clockwise on the k3d::split_edge that is represented by the link
513
void complete(bool recurse = true)
520
return_if_fail(edge);
521
return_if_fail(edge->vertex);
522
return_if_fail(counter_clockwise);
523
return_if_fail(companion_clockwise);
524
return_if_fail(companion);
527
companion->complete(false);
529
return_if_fail(companion->edge);
530
return_if_fail(companion_clockwise->edge);
531
companion->edge->face_clockwise = companion_clockwise->edge;
532
return_if_fail(counter_clockwise->edge);
533
counter_clockwise->edge->face_clockwise = edge;
534
if (!(edge->companion))
535
k3d::join_edges(*edge, *(companion->edge));
544
friend void splitter::make_creases();
546
point() : vertex(0), m_Reorder(false) {}
547
point(k3d::point* Point) : vertex(Point), m_Reorder(false), m_Updated(false) {}
550
for (unsigned long i = 0; i < links.size(); ++i)
555
/// the point represented
557
/// update the relations between the links. Works correctly only if links are ordered clockwise around the vertex. Use reorder_on if this is not the case.
558
virtual void update()
563
for (unsigned long i = 0; i < links.size(); ++i)
565
links[i]->counter_clockwise = links[(i+1) % links.size()]->companion;
566
links[i]->companion_clockwise = links[(links.size()+i-1) % links.size()];
569
virtual link* join(point* other_point, bool recurse = true)
571
link* new_link = new link(new k3d::split_edge(vertex));
572
links.push_back(new_link);
575
new_link->companion = other_point->join(this, false);
576
new_link->companion->companion = new_link;
581
/// complete all links
582
virtual void complete()
584
return_if_fail(m_Updated);
585
for (unsigned long i = 0; i < links.size(); ++i)
587
links[i]->complete();
591
/// Turn on automatic link reordering, arranging links clockwise around the face normal.
592
void reorder_on(k3d::vector3& normal)
595
m_Normal = normal / normal.Length();
599
/// reorder the links around the vertex so they are arranged clockwise around the normal vector of the face.
602
if (links.size() < 1)
604
std::map<double, link*> angle_links;
606
k3d::vector3 v0 = links[0]->companion->edge->vertex->position - vertex->position;
608
for (unsigned long i = 0; i < links.size(); ++i)
610
k3d::vector3 v = links[i]->companion->edge->vertex->position - vertex->position;
611
angle_links[angle(v0, v)] = links[i];
615
for (std::map<double, link*>::iterator it = angle_links.begin(); it != angle_links.end(); ++it)
617
links[i] = it->second;
621
/// Calculate the angle between 2 vectors
622
double angle(k3d::vector3& v1, k3d::vector3& v2)
624
// cosine of the angle:
625
double cos_th = (v1 * v2) / (v1.Length() * v2.Length());
626
//sometimes this value is greater than 1
631
k3d::vector3 normal = (v1 ^ v2);
632
normal /= normal.Length();
633
double tol = 0.00001;
635
double th = (normal + m_Normal).Length() > tol ? acos(cos_th) : k3d::pi_times_2() - acos(cos_th);
636
//std::cerr << debug << "cos_th: " << cos_th << ". angle is " << th * 180 / k3d::pi() << " degrees" << std::endl;
639
k3d::vector3 m_Normal;
643
/// a vector of all links from this point
644
std::vector<link*> links;
647
// point at a t-junction. links[0] is the incomplete link (the leg of the T)
648
class t_point : public point
651
t_point(k3d::point* Point, k3d::split_edge* To, k3d::split_edge* From, bool dummy_edge = false)
653
this->vertex = Point;
654
link* leg = new link(new k3d::split_edge(vertex), dummy_edge);
655
leg->counter_clockwise = new link(To);
656
leg->companion_clockwise = new link(From);
657
links.push_back(leg);
663
delete links[0]->counter_clockwise;
664
delete links[0]->companion_clockwise;
669
return_if_fail(links.size() == 1);
672
link* leg = links[0];
673
return_if_fail(leg->edge);
674
return_if_fail(leg->counter_clockwise);
675
return_if_fail(leg->companion);
676
return_if_fail(leg->companion_clockwise);
678
link* join(point* other_point, bool recurse = true)
681
link* leg = links[0];
684
leg->companion = other_point->join(this, false);
685
leg->companion->companion = leg;
693
links[0]->complete();
479
699
/// class splitter
480
k3d::split_edge* splitter::split_edge(k3d::split_edge& Edge, const double factor)
482
double sharpness = get_sharpness(Edge);
483
double comp_sharpness = Edge.companion ? get_sharpness(*(Edge.companion)) : 0.0;
700
splitter::splitter(k3d::polyhedron& Polyhedron, k3d::mesh::points_t& Points, bool Use_selection) : m_Polyhedron(Polyhedron), m_Points(Points)
702
for (unsigned long i = 0; i < Polyhedron.faces.size(); ++i)
704
m_all_faces[Polyhedron.faces[i]->first_edge] = Polyhedron.faces[i];
705
k3d::split_edge* last_edge = Polyhedron.faces[i]->first_edge;
706
k3d::split_edge* this_edge = last_edge->face_clockwise;
708
bool has_selected_edge = false;
709
has_selected_edge = get_sharpness(*last_edge) > 0.0 ? true : has_selected_edge;
711
if (Use_selection && last_edge->vertex->selected)
712
has_selected_edge = true;
714
k3d::point* centroid = new k3d::point(last_edge->vertex->position);
716
unsigned long corners = 1;
718
while(this_edge != Polyhedron.faces[i]->first_edge)
721
centroid->position += this_edge->vertex->position;
722
has_selected_edge = get_sharpness(*this_edge) > 0.0 ? true : has_selected_edge;
723
if (Use_selection && this_edge->vertex->selected)
724
has_selected_edge = true;
725
last_edge = this_edge;
726
this_edge = this_edge->face_clockwise;
728
if (has_selected_edge)
730
point_edge_info info;
731
info.second[1] = last_edge;
732
centroid->position /= corners;
733
last_edge = Polyhedron.faces[i]->first_edge;
734
this_edge = last_edge->face_clockwise;
735
info.second[0] = this_edge;
736
info.second[2] = last_edge->companion;
737
info.first[1] = add_point(centroid);
738
m_edges[last_edge] = info;
740
while(this_edge != Polyhedron.faces[i]->first_edge)
742
info.second[0] = this_edge->face_clockwise;
743
info.second[1] = last_edge;
744
info.second[2] = this_edge->companion;
745
info.first[0] = add_t_point(this_edge->vertex, last_edge, this_edge, true);
746
info.first[1] = add_point(centroid);
747
m_edges[this_edge] = info;
748
last_edge = this_edge;
749
this_edge = this_edge->face_clockwise;
751
m_edges[Polyhedron.faces[i]->first_edge].first[0] = add_t_point(Polyhedron.faces[i]->first_edge->vertex, last_edge, Polyhedron.faces[i]->first_edge, true);
752
m_faces[Polyhedron.faces[i]->first_edge] = Polyhedron.faces[i];
753
m_centroids.push_back(centroid);
762
splitter::~splitter()
764
for (unsigned long i = 0; i < m_centroids.size(); ++i)
766
delete m_centroids[i];
769
for (unsigned long i = 0; i < m_added_points.size(); ++i)
771
delete m_added_points[i];
775
point* splitter::split_edge(k3d::split_edge& Edge, const double Factor, point* Start, point* End)
485
777
// first point of the edge:
486
k3d::point* this_point = Edge.vertex;
778
k3d::point* this_point = (!Start || (Start->vertex == 0)) ? Edge.vertex : Start->vertex;
487
779
// second point of the edge:
488
k3d::point* other_point = Edge.face_clockwise->vertex;
489
std::cerr << debug << "Starting split_edge with [" << this_point->position[0] << ", " << this_point->position[1] << ", " << this_point->position[2] << "] and [" << other_point->position[0] << ", " << other_point->position[1] << ", " << other_point->position[2] << "]" << std::endl;
780
k3d::point* other_point = (!End || (End->vertex == 0)) ? Edge.face_clockwise->vertex : End->vertex;
491
781
// new point position:
492
782
k3d::vector3 new_pos;
493
k3d::split_edge* ret_edge = 0;
494
point_map::iterator it = m_other_points.find(this_point);
495
if(it != m_other_points.end()) {
496
this_point = (other_point == it->second.first) ? it->second.second : it->second.first;
499
it = m_other_points.find(other_point);
500
if(it != m_other_points.end()) {
501
other_point = (this_point == it->second.first) ? it->second.second : it->second.first;
502
ret_edge = Edge.face_clockwise;
505
std::cerr << debug << "Finishing split_edge with [" << this_point->position[0] << ", " << this_point->position[1] << ", " << this_point->position[2] << "] and [" << other_point->position[0] << ", " << other_point->position[1] << ", " << other_point->position[2] << "]" << std::endl;
506
new_pos = k3d::mix<k3d::vector3>(this_point->position, other_point->position, f);
507
if(Edge.companion && m_split_edges.find(Edge.companion) != m_split_edges.end()) {
508
std::cerr << debug << "Mixing old and new split-point." << std::endl;
509
it->first->position = k3d::mix<k3d::vector3>(new_pos, it->first->position, 0.5);
512
std::cerr << debug << "Split edge [" << Edge.vertex->position[0] << ", " << Edge.vertex->position[1] << ", " << Edge.vertex->position[2] << "]->[" << other_point->position[0] << ", " << other_point->position[1] << ", " << other_point->position[2] << "] at [" << new_pos[0] << ", " << new_pos[1] << ", " << new_pos[2] << "]" << std::endl;
783
new_pos = k3d::mix<k3d::vector3>(this_point->position, other_point->position, Factor);
514
std::cerr << debug << "Adding new point [" << new_pos[0] << ", " << new_pos[1] << ", " << new_pos[2] << "]" << std::endl;
515
785
k3d::point* new_point = new k3d::point(new_pos);
516
m_Points.push_back(new_point);
518
787
k3d::split_edge* new_edge = new k3d::split_edge(new_point, Edge.face_clockwise);
519
788
Edge.face_clockwise = new_edge;
520
new_edge->tags["crease"] = sharpness;
521
789
// companion edge
522
790
if(Edge.companion) {
523
791
k3d::split_edge* new_comp_edge = new k3d::split_edge(new_point, Edge.companion->face_clockwise);
525
793
k3d::join_edges(*Edge.companion, *new_edge);
526
794
k3d::join_edges(Edge, *new_comp_edge);
527
795
m_Polyhedron.edges.push_back(new_comp_edge);
528
new_comp_edge->tags["crease"] = comp_sharpness;
530
m_Polyhedron.edges.push_back(new_edge);
531
m_other_points[new_edge->vertex] = std::pair<k3d::point*, k3d::point*>(this_point, other_point);
532
//m_split_edges.insert(Edge.companion);
536
k3d::split_edge* splitter::detach_edge_novertex(k3d::split_edge& Edge, const k3d::vector3& centroid)
538
std::cerr << debug << "detach_edge_novertex" << std::endl;
539
k3d::split_edge* clockwise = Edge.face_clockwise;
540
//double f = adapt_factor(*clockwise, m_f);
541
double f = 2*sqrt(m_f * m_parallel_edges[clockwise]);
542
f = f > 1.0 ? 1.0 : f;
543
std::cerr << debug << "Moving [" << clockwise->vertex->position[0] << ", " << clockwise->vertex->position[1] << ", " << clockwise->vertex->position[2] << "] to [";
544
//clockwise->vertex->position = k3d::mix(clockwise->vertex->position, clockwise->face_clockwise->vertex->position, f);
545
clockwise->vertex->position = k3d::mix(Edge.vertex->position, centroid, f);
546
m_other_points.erase(clockwise->vertex);
547
std::cerr << debug << clockwise->vertex->position[0] << ", " << clockwise->vertex->position[1] << ", " << clockwise->vertex->position[2] << "]" << std::endl;
548
m_last_factor[clockwise] = f;
549
clockwise->companion->face_clockwise->vertex = Edge.vertex;
550
m_last_factor.erase(clockwise->companion->face_clockwise);
551
m_split_edges.erase(clockwise->companion->face_clockwise);
552
if(clockwise->companion->face_clockwise->companion) {
553
clockwise->companion->face_clockwise->companion->face_clockwise = clockwise->companion->face_clockwise->companion->face_clockwise->face_clockwise;
554
m_last_factor.erase(clockwise->companion->face_clockwise->companion);
555
m_split_edges.erase(clockwise->companion->face_clockwise->companion);
557
k3d::split_edge* companion = Edge.companion;
559
companion = new k3d::split_edge(clockwise->vertex, clockwise->companion->face_clockwise);
560
k3d::join_edges(*companion, Edge);
561
m_Polyhedron.edges.push_back(companion);
563
companion->face_clockwise = clockwise->companion->face_clockwise;
564
clockwise->companion->face_clockwise = companion;
565
edge_face_map::iterator it = m_face_starts.find(Edge.companion);
566
if(it != m_face_starts.end()) {
567
k3d::face* removed_face = it->second;
568
removed_face->first_edge = companion->face_clockwise->companion;
569
m_face_starts.erase(it);
570
m_face_starts[companion->face_clockwise->companion] = removed_face;
576
// Detach the starting point of a parallel split face, where the detached vertex belongs to Edge.
577
k3d::split_edge* splitter::detach_edge_vertex(k3d::split_edge& Edge, const k3d::vector3& centroid)
579
std::cerr << debug << "detach_edge_vertex" << std::endl;
580
k3d::split_edge* c_clockwise = counter_clockwise(Edge);
581
k3d::split_edge* other_edge = counter_clockwise(*(c_clockwise->companion));
582
//double f = adapt_factor(*c_clockwise, m_f);
583
double f = 2*sqrt(m_f * m_parallel_edges[c_clockwise]);
584
f = f > 1.0 ? 1.0 : f;
585
std::cerr << debug << "Moving [" << Edge.vertex->position[0] << ", " << Edge.vertex->position[1] << ", " << Edge.vertex->position[2] << "] to [";
586
//Edge.vertex->position = k3d::mix(Edge.vertex->position, c_clockwise->vertex->position, f);
587
Edge.vertex->position = k3d::mix(Edge.face_clockwise->vertex->position, centroid, f);
588
m_other_points.erase(Edge.vertex);
589
std::cerr << debug << Edge.vertex->position[0] << ", " << Edge.vertex->position[1] << ", " << Edge.vertex->position[2] << "]" << std::endl;
590
m_last_factor[c_clockwise] = f;
591
k3d::split_edge* companion = Edge.companion;
593
k3d::split_edge* companion_ccl = counter_clockwise(*companion);
594
companion->face_clockwise->vertex = Edge.face_clockwise->vertex;
595
m_last_factor.erase(companion->face_clockwise);
596
m_split_edges.erase(companion->face_clockwise);
597
companion_ccl->face_clockwise = companion->face_clockwise;
599
companion = new k3d::split_edge(Edge.face_clockwise->vertex, c_clockwise->companion);
600
k3d::join_edges(Edge, *companion);
601
m_Polyhedron.edges.push_back(companion);
603
companion->face_clockwise = c_clockwise->companion;
604
other_edge->face_clockwise = companion;
605
m_last_factor.erase(other_edge);
606
m_split_edges.erase(other_edge);
607
edge_face_map::iterator it = m_face_starts.find(Edge.companion);
608
if(it != m_face_starts.end()) {
609
k3d::face* removed_face = it->second;
610
removed_face->first_edge = other_edge->companion;
611
m_face_starts.erase(it);
612
m_face_starts[other_edge->companion] = removed_face;
614
return companion->face_clockwise;
617
k3d::split_edge* splitter::split_face_along_edge(k3d::split_edge& Edge, const double factor, const k3d::vector3& centroid)
620
// get the two neigbour edges
621
k3d::split_edge* clockwise = Edge.face_clockwise;
622
k3d::split_edge* c_clockwise = counter_clockwise(Edge);
623
// Check if the clockwise edge is new
625
bool is_new_companion = false;
626
bool is_new_cc = false;
627
k3d::split_edge* other_end = 0;
628
if(m_parallel_edges.find(clockwise) != m_parallel_edges.end())
630
if(m_parallel_edges.find(clockwise->companion) != m_parallel_edges.end())
631
is_new_companion = true;
632
if(Edge.face_clockwise->companion && Edge.face_clockwise->companion->face_clockwise->face_clockwise->companion && (m_parallel_edges.find(Edge.face_clockwise->companion->face_clockwise->face_clockwise->companion) != m_parallel_edges.end())) {
634
other_end = Edge.face_clockwise->companion->face_clockwise->face_clockwise->companion->face_clockwise;
636
k3d::split_edge* new_ccl_edge = 0;
637
k3d::split_edge* new_cl_edge = 0;
638
if(is_new || is_new_companion || is_new_cc) {
640
std::cerr << debug << "is_new" << std::endl;
641
new_ccl_edge = detach_edge_novertex(Edge, centroid);
643
new_cl_edge = this->split_edge(*(Edge.companion->face_clockwise->face_clockwise), factor);
644
m_last_factor[new_cl_edge] = factor;
645
m_split_edges.insert(Edge.companion->face_clockwise->face_clockwise);
648
if(is_new_companion) {
649
std::cerr << debug << "is_new_companion" << std::endl;
650
new_cl_edge = detach_edge_vertex(*(Edge.face_clockwise->companion->face_clockwise), centroid);
652
new_ccl_edge = this->split_edge(*c_clockwise, 1-factor);
653
m_last_factor[c_clockwise] = factor;
654
m_split_edges.insert(new_ccl_edge);
655
if(c_clockwise == new_ccl_edge)
656
c_clockwise = counter_clockwise(*c_clockwise);
660
std::cerr << debug << "is_new_cc" << std::endl;
661
new_cl_edge = detach_edge_vertex(*other_end, centroid);
663
clockwise = counter_clockwise(*new_cl_edge);
664
c_clockwise = counter_clockwise(*new_ccl_edge);
666
// split neighbour edges at the desired length
667
new_ccl_edge = this->split_edge(*c_clockwise, 1-factor);
668
m_last_factor[c_clockwise] = factor;
669
m_split_edges.insert(new_ccl_edge);
670
if(c_clockwise == new_ccl_edge)
671
c_clockwise = counter_clockwise(*c_clockwise);
672
new_cl_edge = this->split_edge(*clockwise, factor);
673
m_last_factor[new_cl_edge] = factor;
674
m_split_edges.insert(clockwise);
677
k3d::split_edge* new_edge = new k3d::split_edge(new_ccl_edge->vertex, new_cl_edge);
678
k3d::split_edge* new_edge_companion = new k3d::split_edge(new_cl_edge->vertex, new_ccl_edge);
679
// add them to the list
680
m_Polyhedron.edges.push_back(new_edge);
681
m_Polyhedron.edges.push_back(new_edge_companion);
683
k3d::join_edges(*new_edge, *new_edge_companion);
684
// fix the other face_clockwise pointers
685
clockwise->face_clockwise = new_edge_companion;
686
c_clockwise->face_clockwise = new_edge;
797
m_Polyhedron.edges.push_back(new_edge);
798
return add_t_point(new_point, &Edge, Edge.face_clockwise);
801
void splitter::split_edge_add_point(k3d::split_edge& Edge, const double factor, point* Start, point* End)
803
point* p = split_edge(Edge, factor, Start, End);
804
m_Points.push_back(p->vertex);
807
void splitter::split_near(k3d::split_edge& edge, const double factor)
809
point* far_point = far(*companion(edge));
812
k3d::vector3 new_pos = k3d::mix(start(edge)->vertex->position, end(edge)->vertex->position, factor);
813
far_point->vertex->position = k3d::mix(new_pos, far_point->vertex->position, 0.5);
814
set_near(edge, *(add_t_point(far_point->vertex, 0, 0)));
818
point* new_point = split_edge(edge, factor, start(edge), end(edge));
819
m_Points.push_back(new_point->vertex);
820
set_near(edge, *new_point);
824
void splitter::split_far(k3d::split_edge& edge, const double factor)
826
point* near_point = near(*companion(edge));
829
k3d::vector3 new_pos = k3d::mix(start(edge)->vertex->position, end(edge)->vertex->position, factor);
830
near_point->vertex->position = k3d::mix(new_pos, near_point->vertex->position, 0.5);
831
set_far(edge, *(add_t_point(near_point->vertex, 0, 0)));
835
point* new_point = split_edge(*(edge.face_clockwise), factor, start(edge), end(edge));
836
m_Points.push_back(new_point->vertex);
837
set_far(edge, *new_point);
841
point* new_point = split_edge(edge, factor, start(edge), end(edge));
842
m_Points.push_back(new_point->vertex);
843
set_far(edge, *new_point);
847
void splitter::make_creases()
849
// add the new points
850
for (faces_t::iterator face = m_faces.begin(); face != m_faces.end(); ++face)
852
k3d::split_edge* first_edge = face->first;
853
k3d::split_edge* this_edge = first_edge;
855
while (this_edge != first_edge || start)
857
edges_t::iterator edge = find_info(*this_edge);
858
double sharpness = get_sharpness(*(edge->first));
859
double cl_sharpness = get_sharpness(*(edge->second.second[0]));
862
if (cl_sharpness > 0.0)
864
// Use the geometric mean of both factors to calculate the factor for lerping between the centroid and the corner
865
double f = 2*sqrt(sharpness_to_factor(sharpness) * sharpness_to_factor(cl_sharpness));
866
k3d::vector3 face_pos(k3d::mix<k3d::vector3>(edge->second.second[0]->vertex->position, edge->second.first[1]->vertex->position, f));
867
point* face_vertex = add_point(new k3d::point(face_pos));
868
m_Points.push_back(face_vertex->vertex);
869
set_face_vertex(*(edge->second.second[0]), *face_vertex);
870
if (!companion(*(edge->second.second[0])) || get_sharpness(*clockwise(*companion(*(edge->second.second[0])))) > 0.0)
872
// the clockwise edge
873
split_near(*(edge->second.second[0]),sharpness_to_factor(sharpness));
875
split_far(*(edge->first), 1-sharpness_to_factor(cl_sharpness));
877
else if (get_sharpness(*counter_clockwise(*companion(*(edge->first)))))
879
// the clockwise edge
880
split_near(*(edge->second.second[0]),sharpness_to_factor(sharpness));
882
split_far(*(edge->first), 1-sharpness_to_factor(cl_sharpness));
887
split_near(*(edge->second.second[0]),sharpness_to_factor(sharpness));
890
else if (cl_sharpness > 0.0)
892
split_far(*(edge->first), 1-sharpness_to_factor(cl_sharpness));
895
this_edge = clockwise(*this_edge);
899
// correct clockwise and counter-clockwise edges
900
for (faces_t::iterator face = m_faces.begin(); face != m_faces.end(); ++face)
902
k3d::split_edge* first_edge = face->first;
903
k3d::split_edge* this_edge = first_edge;
905
while (this_edge != first_edge || start)
907
point* end_v = end(*this_edge);
908
point* near_v = near(*this_edge);
909
point* far_v = far(*this_edge);
910
point* companion_far_v = far(*companion(*this_edge));
911
point* companion_near_v = near(*companion(*this_edge));
912
if (near_v || companion_far_v)
916
near_v->links[0]->counter_clockwise->edge = this_edge;
917
near_v->links[0]->companion_clockwise->edge = this_edge->face_clockwise;
919
if (far_v || companion_near_v)
923
far_v->links[0]->counter_clockwise->edge = this_edge->face_clockwise;
924
far_v->links[0]->companion_clockwise->edge = this_edge->face_clockwise->face_clockwise;
926
end_v->links[0]->counter_clockwise->edge = this_edge->face_clockwise->face_clockwise;
930
end_v->links[0]->counter_clockwise->edge = this_edge->face_clockwise;
933
else if (far_v || companion_near_v)
937
far_v->links[0]->counter_clockwise->edge = this_edge;
938
far_v->links[0]->companion_clockwise->edge = this_edge->face_clockwise;
940
end_v->links[0]->counter_clockwise->edge = this_edge->face_clockwise;
943
this_edge = clockwise(*this_edge);
946
this_edge = first_edge;
948
// connect the new points
949
while (this_edge != first_edge || start)
951
point* face_v = face_vertex(*this_edge);
952
point* near_v = near(*this_edge);
953
point* far_v = far(*this_edge);
954
point* start_v = this->start(*this_edge);
955
point* next_face_v = face_vertex(*clockwise(*this_edge));
956
point* next_near_v = 0;
957
if (face_v && !next_face_v)
958
next_near_v = near(*clockwise(*this_edge));
963
link* l = near_v->join(face_v);
964
m_Polyhedron.edges.push_back(l->edge);
965
m_Polyhedron.edges.push_back(l->companion->edge);
971
link* l = next_face_v->join(face_v);
972
m_Polyhedron.edges.push_back(l->edge);
973
m_Polyhedron.edges.push_back(l->companion->edge);
974
l = far_v->join(next_face_v);
975
m_Polyhedron.edges.push_back(l->edge);
976
m_Polyhedron.edges.push_back(l->companion->edge);
980
if (face_v && !near_v && !far(*counter_clockwise(*this_edge)))
982
link* l = start_v->join(face_v);
983
m_Polyhedron.edges.push_back(l->edge);
984
m_Polyhedron.edges.push_back(l->companion->edge);
985
k3d::vector3 n = k3d::normal(this_edge);
986
face_v->reorder_on(n);
988
if (face_v && next_face_v && !far_v)
990
link* l = face_v->join(next_face_v);
991
m_Polyhedron.edges.push_back(l->edge);
992
m_Polyhedron.edges.push_back(l->companion->edge);
994
if (!face_v && far_v && next_face_v)
996
link* l = far_v->join(next_face_v);
997
m_Polyhedron.edges.push_back(l->edge);
998
m_Polyhedron.edges.push_back(l->companion->edge);
999
k3d::vector3 n = k3d::normal(this_edge);
1000
next_face_v->reorder_on(n);
1002
if (!next_face_v && far_v)
1004
point* next_v = face_vertex(*clockwise(*clockwise(*this_edge)));
1007
link* l = next_v->join(far_v);
1008
m_Polyhedron.edges.push_back(l->edge);
1009
m_Polyhedron.edges.push_back(l->companion->edge);
1012
point* last_far_v = far(*counter_clockwise(*this_edge));
1013
if (!next_face_v && !face_v && last_far_v)
1015
link* l = last_far_v->join(near(*clockwise(*this_edge)));
1016
m_Polyhedron.edges.push_back(l->edge);
1017
m_Polyhedron.edges.push_back(l->companion->edge);
1022
link* l = next_near_v->join(face_v);
1023
m_Polyhedron.edges.push_back(l->edge);
1024
m_Polyhedron.edges.push_back(l->companion->edge);
1027
this_edge = clockwise(*this_edge);
1028
} // end while (face loop)
1030
this_edge = first_edge;
1033
while (this_edge != first_edge || start)
1035
point* face_v = face_vertex(*this_edge);
1036
point* near_v = near(*this_edge);
1037
point* far_v = far(*this_edge);
1051
this_edge = clockwise(*this_edge);
1052
} // end while (face loop)
1054
this_edge = first_edge;
1056
// complete the k3d::split_edges in the links
1057
while (this_edge != first_edge || start)
1059
point* face_v = face_vertex(*this_edge);
1060
point* near_v = near(*this_edge);
1061
point* far_v = far(*this_edge);
1075
this_edge = clockwise(*this_edge);
1076
} // end while (face loop)
1077
} // end for (all faces)
687
1079
// add new faces
688
if(!is_face(*new_edge)) {
691
add_face(*new_edge_companion);
693
m_parallel_edges[new_edge_companion] = factor;
695
m_last_factor[new_edge_companion] = m_parallel_edges[(counter_clockwise(*new_edge))->companion];
697
m_last_factor[new_edge_companion] = m_parallel_edges[new_edge->face_clockwise->companion];
698
std::cerr << debug << "Created parallel edge [" << new_edge_companion->vertex->position[0] << ", " << new_edge_companion->vertex->position[1] << ", " << new_edge_companion->vertex->position[2] << "]->[" << new_edge->vertex->position[0] << ", " << new_edge->vertex->position[1] << ", " << new_edge->vertex->position[2] << "]" << std::endl;
699
return new_edge_companion;
1080
for (k3d::polyhedron::edges_t::iterator edge = m_Polyhedron.edges.begin(); edge != m_Polyhedron.edges.end(); ++edge)
1086
void splitter::link_points(point* A, point* B)
1088
return_if_fail(A || B || A->vertex || B->vertex);
1089
link* l = A->join(B);
1090
m_Polyhedron.edges.push_back(l->edge);
1091
m_Polyhedron.edges.push_back(l->companion->edge);
1096
add_face(*(l->edge));
1097
add_face(*(l->companion->edge));
1100
void splitter::link_points()
1102
for (faces_t::iterator face = m_faces.begin(); face != m_faces.end(); ++face)
1104
k3d::split_edge* first_edge = face->first;
1105
k3d::split_edge* this_edge = first_edge;
1107
std::vector<point*> points;
1108
while (this_edge != first_edge || start)
1110
if (this_edge->vertex->selected && (!this_edge->face_clockwise->vertex->selected || this_edge->face_clockwise->face_clockwise->vertex->selected))
1111
points.push_back(this->start(*this_edge));
1113
this_edge = clockwise(*this_edge);
1115
if (points.size() == 2)
1116
link_points(points[0], points[1]);
1120
void splitter::split_face_parallel(k3d::split_edge& Edge, double Factor)
1122
return_if_fail(&Edge);
1123
return_if_fail(Edge.face_clockwise);
1124
// get the counter-clockwise edge
1125
k3d::split_edge* ccl;
1126
for(ccl = &Edge; ccl && ccl->face_clockwise; ccl = ccl->face_clockwise)
1128
if (ccl->face_clockwise == &Edge)
1131
point* start = split_edge(*ccl, 1-Factor);
1132
m_Points.push_back(start->vertex);
1133
point* end = split_edge(*(Edge.face_clockwise), Factor);
1134
m_Points.push_back(end->vertex);
1135
link_points(start, end);
1138
splitter::edges_t::iterator& splitter::find_info(k3d::split_edge& Edge)
1140
if (&Edge == m_cached_edge.first)
1141
return m_cached_edge.second;
1142
m_cached_edge.first = &Edge;
1143
m_cached_edge.second = m_edges.find(&Edge);
1144
return m_cached_edge.second;
1147
k3d::split_edge* splitter::get_edge(k3d::split_edge& Edge, int Index)
1149
edges_t::iterator edge = find_info(Edge);
1150
if (edge != m_edges.end())
1152
return edge->second.second[Index];
1157
k3d::split_edge* splitter::clockwise(k3d::split_edge& Edge)
1159
return get_edge(Edge, 0);
702
1162
k3d::split_edge* splitter::counter_clockwise(k3d::split_edge& Edge)
704
k3d::split_edge* last_edge = &Edge;
705
k3d::split_edge* this_edge = Edge.face_clockwise;
707
while(this_edge != &Edge)
709
last_edge = this_edge;
710
this_edge = this_edge->face_clockwise;
1164
return get_edge(Edge, 1);
1167
k3d::split_edge* splitter::companion(k3d::split_edge& Edge)
1169
return get_edge(Edge, 2);
1172
point* splitter::get_point(k3d::split_edge& Edge, int Index)
1174
edges_t::iterator edge = find_info(Edge);
1175
if (edge != m_edges.end())
1177
return edge->second.first[Index];
1182
point* splitter::start(k3d::split_edge& Edge)
1184
return get_point(Edge, 0);
1187
point* splitter::end(k3d::split_edge& Edge)
1189
return start(*clockwise(Edge));
1192
k3d::point* splitter::centroid(k3d::split_edge& Edge)
1194
return get_point(Edge, 1)->vertex;
1197
point* splitter::near(k3d::split_edge& Edge)
1199
return get_point(Edge, 2);
1202
point* splitter::far(k3d::split_edge& Edge)
1204
return get_point(Edge, 3);
1207
point* splitter::face_vertex(k3d::split_edge& Edge)
1209
return get_point(Edge, 4);
1212
void splitter::set_point(k3d::split_edge& Edge, point& Point, int Index)
1214
edges_t::iterator edge = find_info(Edge);
1215
if (edge != m_edges.end())
1217
edge->second.first[Index] = &Point;
1221
void splitter::set_near(k3d::split_edge& Edge, point& Point)
1223
set_point(Edge, Point, 2);
1226
void splitter::set_far(k3d::split_edge& Edge, point& Point)
1228
set_point(Edge, Point, 3);
1231
void splitter::set_face_vertex(k3d::split_edge& Edge, point& Point)
1233
set_point(Edge, Point, 4);
716
1236
bool splitter::is_face(k3d::split_edge& Edge)