1 |
/* |
/* |
2 |
Fillets2.hxx |
Fillets2.hxx |
3 |
* |
* |
4 |
* Copyright (c) 2003, Tuomas J. Lukka |
* Copyright (c) 2003, Tuomas J. Lukka and Janne V. Kujala |
5 |
* This file is part of Libvob. |
* This file is part of Libvob. |
6 |
* |
* |
7 |
* Libvob is free software; you can redistribute it and/or modify it under |
* Libvob is free software; you can redistribute it and/or modify it under |
21 |
* |
* |
22 |
*/ |
*/ |
23 |
/* |
/* |
24 |
* Written by Tuomas J. Lukka |
* Written by Tuomas J. Lukka and Janne V. Kujala |
25 |
*/ |
*/ |
26 |
|
|
27 |
#include <boost/format.hpp> |
#include <boost/format.hpp> |
645 |
|
|
646 |
}; |
}; |
647 |
|
|
648 |
|
struct int3 { |
649 |
|
int v[3]; |
650 |
|
int3(int a, int b, int c) { v[0] = a; v[1] = b; v[2] = c; } |
651 |
|
|
652 |
|
int operator[](int i) const { return v[i]; } |
653 |
|
}; |
654 |
|
|
655 |
|
/** Spherical delaunay triangulation |
656 |
|
* Naive O(n^4) implementation, |
657 |
|
* probably has problems with more than three coplanar vertices |
658 |
|
*/ |
659 |
|
template <class ZVecArray> |
660 |
|
void Triangulate(ZVecArray v, int n, |
661 |
|
std::vector<int3> &tri) { |
662 |
|
int i, j, k, l; |
663 |
|
|
664 |
|
for (i = 0; i < n; i++) |
665 |
|
for (j = i + 1; j < n; j++) |
666 |
|
for (k = j + 1; k < n; k++) { |
667 |
|
ZVec d = (v[i] - v[k]).crossp(v[j] - v[k]).normalized(); |
668 |
|
d /= d.dot(v[k]); |
669 |
|
for (l = 0; l < n; l++) { |
670 |
|
if (l == i || l == j || l == k) continue; |
671 |
|
if (d.dot(v[l]) >= 1) break; |
672 |
|
} |
673 |
|
if (l == n) |
674 |
|
tri.push_back(int3(i,j,k)); |
675 |
|
} |
676 |
|
|
677 |
|
} |
678 |
|
|
679 |
|
/** Build a matrix of the number of triangles using each edge |
680 |
|
*/ |
681 |
|
template <class IntArray> |
682 |
|
void FindEdges(IntArray edge, int n, |
683 |
|
std::vector<int3> &tri) { |
684 |
|
int i, j; |
685 |
|
int m = tri.size(); |
686 |
|
|
687 |
|
for (i = 0; i < n; i++) |
688 |
|
for (j = 0; j < n; j++) |
689 |
|
edge[n * i + j] = 0; |
690 |
|
|
691 |
|
for (i = 0; i < m; i++) { |
692 |
|
edge[n * tri[i][0] + tri[i][1]]++; |
693 |
|
edge[n * tri[i][1] + tri[i][2]]++; |
694 |
|
edge[n * tri[i][0] + tri[i][2]]++; |
695 |
|
} |
696 |
|
} |
697 |
|
|
698 |
|
/** Mark vertices whose edges belong to only one triangle |
699 |
|
*/ |
700 |
|
template <class IntArray1, class IntArray2> |
701 |
|
void FindEdgeVertices(IntArray1 vert, IntArray2 edge, int n) { |
702 |
|
int i, j; |
703 |
|
|
704 |
|
for (i = 0; i < n; i++) |
705 |
|
vert[i] = 0; |
706 |
|
|
707 |
|
for (i = 0; i < n; i++) |
708 |
|
for (j = i + 1; j < n; j++) |
709 |
|
if (edge[n * i + j] == 1) |
710 |
|
vert[i] = vert[j] = 1; |
711 |
|
} |
712 |
|
|
713 |
|
|
714 |
|
|
715 |
} |
} |
716 |
} |
} |