-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathply.cpp
More file actions
109 lines (87 loc) · 2.25 KB
/
ply.cpp
File metadata and controls
109 lines (87 loc) · 2.25 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include <fstream>
#include <vector>
using namespace std;
#include<string>
struct vertices
{
float x,y,z ;
};
class ply
{
public:
vector <int> face_list;
int faces_num ;
int vertices_num ;
vector <vertices> vertices_list ;
ply(vector <vertices> &v,vector <int> &f,int ver , int fac)
{
face_list = f ;
vertices_num = ver ;
faces_num = fac ;
vertices_list = v ;
}
float area(vertices v1,vertices v2, vertices v3) //its always going to be 3X3 matrix
{
float det ;
det = v1.x * ((v2.y * v3.z) - (v2.z * v3.y)) - v1.y * ((v2.x * v3.z)-(v2.z * v3.x)) + v1.z*((v2.x * v3.y) - (v2.y*v3.x)) ;
float area = det*0.5 ;
return area ;
}
float triangle(vector <int> temp)
{
float tri_area = area(vertices_list[temp[0]],vertices_list[temp[1]],vertices_list[temp[2]]) ;
return abs(tri_area) ;
}
vector <float> face(vector <int> &temp,int facelines)
{
vector <float> sublist ;
int count = 0 ;
bool flag = true ;
int area ;
while(flag)
{
count = count + 1 ;
int x = temp[0] ;
int y = temp[1] ;
int z = temp[2] ;
vector <int> :: iterator it ;
it = temp.begin() ;
it++ ;
area= triangle(temp) ;
sublist.push_back(area) ;
temp.erase(it) ;
if(count == facelines-2)
{
flag =false ;
}
}
return sublist ;
}
vector <float> face_area(int face_lines)
{
int count = 0 ;
vector <int> temp ;
vector <float> list ;
vector <float> sublist ;
for(int x : face_list)
{
count=count+1 ;
temp.push_back(x) ;
if(count==face_lines)
{
count=0 ;
sublist=face(temp,face_lines) ;
for(float x : sublist)
{
list.push_back(x) ;
}
temp.clear() ;
}
}
return list ;
}
};