-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvxSurfaceSlicer.cpp
72 lines (58 loc) · 1.57 KB
/
vxSurfaceSlicer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
*
* file vxSurfaceSlicer.cpp
*
* This source file is a part of VoxelBrain software.
*
* (c) Nanyang Technological University
*
* Author: Konstantin Levinski
*
*/
#include "vxSurfaceSlicer.h"
#include "vxSurface.h"
#include "vxProjection.h"
#include "vxOpenGlTools.h"
using namespace std;
//Splice edge with centered sphere.
bool SpliceEdgeWithSphere(const V3f & a, const V3f & b, float radius, V3f * out){
float al = a.length();
float bl = b.length();
if( ( (al >= radius) && (bl >= radius) ) ||
( (al <= radius) && (bl <= radius) ) ) return false;
*out = a * (bl-radius)/(bl-al) + b * (radius-al)/(bl-al);
return true;
};
void GetBorderLine(Surface * in, V3f center, float radius, BorderLine * bdr){
V3f edge[3];
for(size_t i = 0; i < in->tri.size(); i++){
V3f cur_vertex;
int cur_side = 0;
V3f a; V3f b;
//Check 3 sides.
for(int j = 0; j < 3; j++){
int ind_1 = in->tri[i][j]; int ind_2 = in->tri[i][(j+1)%3];
a = in->v[ind_1]-center; b = in->v[ind_2]-center;
if(SpliceEdgeWithSphere( a, b, radius, &cur_vertex)){
edge[cur_side] = cur_vertex+center;
cur_side++;
};
};
//if crossing 2: (forget about edge cases.)
if(cur_side == 2){
bdr->push_back(edge[0]);
bdr->push_back(edge[1]);
};
}; //Each triangle
};
//OpenGL
void DrawBorder(BorderLine * bdr){
V3f d = GetProjection()->Z();
glColor3f(1,0,0);
glBegin(GL_LINES);
for(BorderLine::iterator i = bdr->begin(); i != bdr->end(); i++){
glVertex3f((*i)+d);
};
glEnd();
};
// End of vxSurfaceSlicer.cpp