-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtility.asv
96 lines (67 loc) · 2.73 KB
/
Utility.asv
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
classdef Utility
%UTILITY Summary of this class goes here
% Detailed explanation goes here
properties
end
methods
% calculate distance between two vector
function h=distanceCost(self,a, b)
h = sqrt(sum((a-b).^2));
end
% calculate the differential of two vector
function output = differential(self,pos1,pos2)
output = (pos2 - pos1)/norm(pos1-pos2);
end
% normalize the vector
function unitVec = getUnitVec(self,vec)
unitVec = vec/sqrt(sum(vec.^2));
end
function normVec = getNormalized(self, distMax, vec)
normVec = vec / distMax;
end
function dis = getCos(self, vec1, vec2)
dis = vec1 .* vec2 / (norm(vec1) * norm(vec2));
end
function saveCSV(self,data, filename)
writematrix(data, [filename],'Delimiter',',','WriteMode','append');
end
function coordinates = loadPtCld(self,filename)
dimRow=true;
rowCount = 1;
vertexCount = [];
fileID=fopen(filename);
coordinates = [];
x=0;
y=0;
z=0;
while (~feof(fileID))
currLine = textscan(fileID,'%s',1,'Delimiter','\n');
currRow = char(currLine{1});
splittedRow = strsplit(currRow,' ');
if (~strcmp(splittedRow(1),'#') && ~strcmp(splittedRow(1),'OFF'))
splittedRow = str2double(splittedRow);
if(dimRow)
dimRow = false;
vertexCount = splittedRow(1);
else
if(rowCount <= vertexCount)
%vertexList{rowCount} = [splittedRow(1)*multiplier splittedRow(2)*multiplier splittedRow(3)*multiplier];
x = splittedRow(1);
y = splittedRow(2);
z = splittedRow(3);
coordinates = [coordinates; [rowCount,x,y,z]];
end
rowCount = rowCount +1;
% progress
if(mod(rowCount,100)==0)
disp('.');
end
end
end
end
fclose(fileID); %Close the input file
%plot3(X,Y,Z, ".")
disp("finished")
end
end
end