Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
masterarbeit-kai
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Philipp Adolf
masterarbeit-kai
Commits
9f572c13
Commit
9f572c13
authored
Oct 13, 2017
by
wester
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update
parent
63e925bc
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
81 additions
and
39 deletions
+81
-39
example.pnts
3_PointCloud/example.pnts
+0
-0
example2.pnts
3_PointCloud/example2.pnts
+0
-0
main.cpp
3_PointCloud/main.cpp
+79
-37
main.h
3_PointCloud/main.h
+1
-1
tileset1.json
3_PointCloud/tileset1.json
+1
-1
No files found.
3_PointCloud/example.pnts
View file @
9f572c13
No preview for this file type
3_PointCloud/example2.pnts
0 → 100644
View file @
9f572c13
File added
3_PointCloud/main.cpp
View file @
9f572c13
...
...
@@ -45,9 +45,9 @@ IMultiSourceFrameReader* reader; // Kinect data source
ICoordinateMapper
*
mapper
;
// Converts between depth, color, and 3d coordinates
TIMESPAN
colorFrameTime
=
-
1
;
float
KinectSizeX
=
0.249
;
float
KinectSizeY
=
0.042
;
// 42 mm, 66mm ist die gesammthhe
float
KinectSizeZ
=
0.067
;
float
KinectSizeX
=
0.249
f
;
float
KinectSizeY
=
0.042
f
;
// 42 mm, 66mm ist die gesammthhe
float
KinectSizeZ
=
0.067
f
;
float
KinectOriginOffsetX
=
((
92
+
73
)
/
2.0
f
)
/
1000.0
f
;
float
KinectOriginOffsetY
=
KinectSizeY
/
2.0
f
;
...
...
@@ -60,7 +60,11 @@ glm::vec3 FrameTranslation(0.0,0.0,0.0);
SteamTracking
*
steamTracking
=
nullptr
;
char
*
controllerSerial
=
"LHR-FFFDBD41"
;
int
controllerID
=
1
;
char
*
trackerSerial
=
"LHR-18DC0D92"
;
int
trackerID
=
5
;
glm
::
mat4x4
*
currentControlerPos
=
nullptr
;
glm
::
mat4x4
*
currentTrackerPos
=
nullptr
;
bool
useTrackerTransform
=
true
;
glm
::
vec3
lastClicketControlelrPos
;
glm
::
mat4x4
controlerToKinect
;
std
::
vector
<
glm
::
vec3
>
controllerPositions
;
...
...
@@ -80,10 +84,10 @@ int lastX, lastY;
//Filter Settings
float
minTrackingKinect
=
0.2
f
;
//0.8f;
float
maxTrackingKinect
=
1.
8
f
;
// 2.5f;
float
maxTrackingKinect
=
1.
0
f
;
// 2.5f;
//Custom
//float angleDegrees = 20.0f;
float
maxNormalAngle
=
degreeToRadi
o
an
(
25.0
f
);
float
maxNormalAngle
=
degreeToRadian
(
25.0
f
);
bool
enableDepthFilter
=
false
;
bool
enableNormalFilter
=
false
;
//true;
//Bilateral / FastDepthNoise
...
...
@@ -94,8 +98,8 @@ float repairThreshold = 100.0f;
float
degreeToRadi
o
an
(
float
degree
)
{
return
degree
*
M_PI
/
180.0
;
float
degreeToRadian
(
float
degree
)
{
return
(
float
)
(
degree
*
M_PI
/
180.0
f
)
;
}
...
...
@@ -231,8 +235,8 @@ void getDepthData(IMultiSourceFrame* frame) {
if
((
enableNormalFilter
||
enableDepthFilter
)
&&
x
>
0
&&
y
>
0
&&
x
<
width
-
1
&&
y
<
height
-
1
)
{
if
(
enableNormalFilter
)
{
//normalen
float
dzdx
=
(
curr
[
x
+
1
+
width
*
y
]
-
curr
[
x
-
1
+
width
*
y
])
/
2.0
;
float
dzdy
=
(
curr
[
x
+
width
*
(
y
+
1
)]
-
curr
[
x
+
width
*
(
y
-
1
)])
/
2.0
;
float
dzdx
=
(
curr
[
x
+
1
+
width
*
y
]
-
curr
[
x
-
1
+
width
*
y
])
/
2.0
f
;
float
dzdy
=
(
curr
[
x
+
width
*
(
y
+
1
)]
-
curr
[
x
+
width
*
(
y
-
1
)])
/
2.0
f
;
glm
::
vec3
d
(
-
dzdx
,
-
dzdy
,
1.0
f
);
frameNormals
[
i
]
=
normalize
(
d
);
...
...
@@ -385,10 +389,13 @@ void processCurrentFrameForExport() {
float
maxx
,
maxy
,
maxz
;
maxx
=
maxy
=
maxz
=
-
std
::
numeric_limits
<
float
>::
max
();
bool
captureFramesTXT
=
false
;
std
::
ofstream
myfile
;
char
buffer
[
64
];
// make sure it's big enough
snprintf
(
buffer
,
sizeof
(
buffer
),
"frames/pnts_%d.txt"
,
counter
++
);
myfile
.
open
(
buffer
,
std
::
ios
::
out
|
std
::
ios
::
binary
);
if
(
captureFramesTXT
)
{
char
buffer
[
64
];
// make sure it's big enough
snprintf
(
buffer
,
sizeof
(
buffer
),
"frames/pnts_%d.txt"
,
counter
++
);
myfile
.
open
(
buffer
,
std
::
ios
::
out
|
std
::
ios
::
binary
);
}
for
(
unsigned
int
i
=
0
;
i
<
width
*
height
;
i
++
)
{
if
(
frameValidPoints
[
i
])
{
...
...
@@ -411,17 +418,17 @@ void processCurrentFrameForExport() {
colors
.
push_back
(
frameColors
[
i
*
3
]);
colors
.
push_back
(
frameColors
[
i
*
3
+
1
]);
colors
.
push_back
(
frameColors
[
i
*
3
+
2
]);
myfile
<<
positionGlobal
.
x
<<
" "
<<
positionGlobal
.
y
<<
" "
<<
positionGlobal
.
z
<<
" "
<<
(
int
)
frameColors
[
i
*
3
]
<<
" "
<<
(
int
)
frameColors
[
i
*
3
+
1
]
<<
" "
<<
(
int
)
frameColors
[
i
*
3
+
2
]
<<
std
::
endl
;
if
(
captureFramesTXT
)
{
myfile
<<
positionGlobal
.
x
<<
" "
<<
positionGlobal
.
y
<<
" "
<<
positionGlobal
.
z
<<
" "
<<
(
int
)
frameColors
[
i
*
3
]
<<
" "
<<
(
int
)
frameColors
[
i
*
3
+
1
]
<<
" "
<<
(
int
)
frameColors
[
i
*
3
+
2
]
<<
std
::
endl
;
}
}
}
myfile
.
close
();
if
(
captureFramesTXT
)
{
myfile
.
close
();
}
std
::
cout
<<
"Frame Local Boundingbox Min: ["
<<
minx
<<
"|"
<<
miny
<<
"|"
<<
minz
<<
"] Max: ["
<<
maxx
<<
"|"
<<
maxy
<<
"|"
<<
maxz
<<
"]"
<<
std
::
endl
;
//update Buffers
if
(
points
.
size
()
==
0
)
return
;
...
...
@@ -444,25 +451,47 @@ void writePointCloud() {
return
;
}
if
(
!
currentTrackerPos
)
currentTrackerPos
=
new
glm
::
mat4x4
(
glm
::
rotate
(
*
steamTracking
->
getTransformationForDevice
(
trackerID
,
0.0
f
),
degreeToRadian
(
-
00
),
glm
::
vec3
(
1.0
f
,
0.0
f
,
0.0
f
)));
std
::
vector
<
glm
::
vec3
>
exportpoints
;
exportpoints
.
reserve
(
points
.
size
());
for
(
size_t
i
=
0
;
i
<
points
.
size
();
i
++
)
{
exportpoints
.
push_back
(
glm
::
vec3
(
glm
::
rotate
(
glm
::
inverse
(
*
currentTrackerPos
),
degreeToRadian
(
00
),
glm
::
vec3
(
1.0
f
,
0.0
f
,
0.0
f
))
*
glm
::
vec4
(
points
[
i
],
1.0
f
)));
}
//exportpoints.clear();
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
exportpoints
.
push_back
(
glm
::
vec3
(
i
/
1000.0
f
,
0.0
f
,
0.0
f
));
exportpoints
.
push_back
(
glm
::
vec3
(
0.0
f
,
i
/
1000.0
f
,
0.0
f
));
exportpoints
.
push_back
(
glm
::
vec3
(
0.0
f
,
i
/
2000.0
f
,
1.0
f
));
exportpoints
.
push_back
(
glm
::
vec3
(
0.0
f
,
0.0
f
,
i
/
1000.0
f
));
}
pntsHeader
header
;
size_t
pointArrayByteSize
=
points
.
size
()
*
sizeof
(
glm
::
vec3
);
std
::
cout
<<
points
.
size
()
<<
" "
<<
sizeof
(
glm
::
vec3
)
;
size_t
pointArrayByteSize
=
export
points
.
size
()
*
sizeof
(
glm
::
vec3
);
std
::
cout
<<
"writing File: Number of Points:"
<<
exportpoints
.
size
()
;
size_t
coloArrayByteSize
=
colors
.
size
()
*
sizeof
(
unsigned
char
);
header
.
featureTableByteLenght
=
pointArrayByteSize
+
coloArrayByteSize
;
std
::
ostringstream
os
;
os
<<
"{
\"
POINTS_LENGTH
\"
:"
<<
(
points
.
size
()
)
<<
",
\"
POSITION
\"
: {
\"
byteOffset
\"
:0},
\"
RGB
\"
: {
\"
byteOffset
\"
:"
<<
pointArrayByteSize
<<
"}}"
;
os
<<
"{
\"
POINTS_LENGTH
\"
:"
<<
(
export
points
.
size
()
)
<<
",
\"
POSITION
\"
: {
\"
byteOffset
\"
:0},
\"
RGB
\"
: {
\"
byteOffset
\"
:"
<<
pointArrayByteSize
<<
"}}"
;
std
::
string
json
=
os
.
str
();
header
.
featureTableJSONByteLenght
=
json
.
size
();
header
.
byteLenght
=
28
/*header*/
+
header
.
featureTableJSONByteLenght
+
header
.
featureTableByteLenght
;
std
::
cout
<<
"
File Size "
<<
header
.
byteLenght
;
std
::
cout
<<
"
File Size in byte"
<<
header
.
byteLenght
<<
std
::
endl
;
std
::
ofstream
myfile
;
myfile
.
open
(
"example.pnts"
,
std
::
ios
::
out
|
std
::
ios
::
binary
);
myfile
.
write
((
char
*
)
&
header
,
28
);
myfile
<<
json
;
myfile
.
write
(
reinterpret_cast
<
const
char
*>
(
&
points
[
0
]),
pointArrayByteSize
);
myfile
.
write
(
reinterpret_cast
<
const
char
*>
(
&
export
points
[
0
]),
pointArrayByteSize
);
myfile
.
write
(
reinterpret_cast
<
const
char
*>
(
&
colors
[
0
]),
coloArrayByteSize
);
//myfile <<
...
...
@@ -507,6 +536,11 @@ void mainRenderLoop() {
//get controler pos
delete
currentControlerPos
;
currentControlerPos
=
steamTracking
->
getTransformationForDevice
(
controllerID
,
0.0
f
);
delete
currentTrackerPos
;
currentTrackerPos
=
steamTracking
->
getTransformationForDevice
(
trackerID
,
0.0
f
);
currentTrackerPos
=
new
glm
::
mat4x4
(
glm
::
rotate
(
*
currentTrackerPos
,
degreeToRadian
(
-
90
),
glm
::
vec3
(
1.0
f
,
0.0
f
,
0.0
f
)));
if
(
trackControllerPos
)
{
glm
::
vec3
tempPos
=
glm
::
vec3
(
*
currentControlerPos
*
glm
::
vec4
(
0
,
0
,
0
,
1
));
...
...
@@ -528,8 +562,11 @@ void mainRenderLoop() {
//add points to point cloud
if
(
captureFrame
)
{
processCurrentFrameForExport
();
glm
::
vec3
TrackerPos
=
glm
::
vec3
(
*
steamTracking
->
getTransformationForDevice
(
trackerID
,
0.0
f
)
*
glm
::
vec4
(
0
,
0
,
0
,
1
));
glm
::
vec3
current
=
controllerPositions
.
back
();
std
::
cout
<<
"Current Position ["
<<
current
.
x
<<
"/"
<<
current
.
y
<<
"/"
<<
current
.
z
<<
"] distance "
<<
distance
(
lastClicketControlelrPos
,
current
)
<<
std
::
endl
;
std
::
cout
<<
"Current Position ["
<<
current
.
x
<<
"/"
<<
current
.
y
<<
"/"
<<
current
.
z
<<
"]
TrackerPos: ["
<<
TrackerPos
.
x
<<
"/"
<<
TrackerPos
.
y
<<
"/"
<<
TrackerPos
.
z
<<
"]
distance "
<<
distance
(
lastClicketControlelrPos
,
current
)
<<
std
::
endl
;
lastClicketControlelrPos
=
controllerPositions
.
back
();
FrameTranslation
=
glm
::
vec3
(
0.0
,
0.0
,
0.0
);
...
...
@@ -546,7 +583,7 @@ void mainRenderLoop() {
//rotateCamera(); //todo
if
(
toggleCam
&&
trackControllerPos
)
{
glTranslatef
(
0.0
,
-
0.3
,
-
1.0
);
glTranslatef
(
0.0
f
,
-
0.3
f
,
-
1.0
f
);
glRotatef
(
10.0
,
1.0
,
0.0
,
0.0
);
glRotatef
(
180.0
,
0.0
,
1.0
,
0.0
);
glMultMatrixf
(
glm
::
value_ptr
(
glm
::
inverse
(
controlerToKinect
)));
...
...
@@ -582,10 +619,15 @@ void mainRenderLoop() {
glVertexPointer
(
3
,
GL_FLOAT
,
0
,
NULL
);
glDrawArrays
(
GL_LINE_STRIP
,
0
,
controllerPosData
.
size
);
}
glPushMatrix
();
glMultMatrixf
(
glm
::
value_ptr
(
*
currentTrackerPos
));
DrawCoordinateSystem
();
glPopMatrix
();
{
// Controller Space
glPushMatrix
();
if
(
currentControlerPos
)
{
//applay controler Transformation
glMultMatrixf
(
glm
::
value_ptr
(
*
currentControlerPos
));
}
...
...
@@ -629,7 +671,7 @@ void mainRenderLoop() {
}
void
moveCurrentFrame
(
glm
::
vec3
dir
)
{
float
factor
=
0.002
;
float
factor
=
0.002
f
;
FrameTranslation
+=
factor
*
dir
;
std
::
cout
<<
"Frame Transformation "
;
printVector
(
FrameTranslation
);
...
...
@@ -646,7 +688,6 @@ void keyPressed(unsigned char key, int x, int y)
captureFrame
=
true
;
break
;
case
'x'
:
std
::
cout
<<
"writing File"
<<
std
::
endl
;
writeFile
=
true
;
break
;
case
'c'
:
...
...
@@ -727,6 +768,7 @@ int main(int argc, char* argv[]) {
steamTracking
->
printVRDevices
();
steamTracking
->
onButtonPress
=
captureNextFrame
;
controllerID
=
steamTracking
->
getDeviceIDForSerial
(
controllerSerial
);
trackerID
=
steamTracking
->
getDeviceIDForSerial
(
trackerSerial
);
// OpenGL setup
...
...
@@ -771,13 +813,13 @@ int main(int argc, char* argv[]) {
//controlerToKinect = glm::translate(glm::mat4x4(), (glm::vec3(0.0f, 0.0f,0.173 /*controller*/+0.03 /*Halterung*/ )));
controlerToKinect
=
glm
::
mat4x4
();
controlerToKinect
=
glm
::
rotate
(
controlerToKinect
,
degreeToRadi
o
an
(
-
58
+
180
/*63,9...*/
),
glm
::
vec3
(
1.0
f
,
0.0
f
,
0.0
f
));
controlerToKinect
=
glm
::
rotate
(
controlerToKinect
,
degreeToRadi
o
an
(
180.0
f
),
glm
::
vec3
(
0.0
f
,
1.0
f
,
0.0
f
));
controlerToKinect
=
glm
::
rotate
(
controlerToKinect
,
degreeToRadian
(
-
58
+
180
/*63,9...*/
),
glm
::
vec3
(
1.0
f
,
0.0
f
,
0.0
f
));
controlerToKinect
=
glm
::
rotate
(
controlerToKinect
,
degreeToRadian
(
180.0
f
),
glm
::
vec3
(
0.0
f
,
1.0
f
,
0.0
f
));
//controlerToKinect = glm::rotate(controlerToKinect, degreeToRadioan(180.0f), glm::vec3(0.0f, 0.0f, 1.0f));
float
dx
=
0.0
10
;
// 0.00
;
float
dy
=
KinectSizeY
/
2.0
f
+
0.004
/*HAlterung Platte*/
+
0.011
/* Conroller*/
;
float
dz
=
-
0.01
;
//-0.023 + 0.02; // 0.045f /*= versatz auf der Halterung; Distanz zur Halterung:*/ + (KinectSizeZ - (0.066 /*halterung z*/ - 0.012 /*halterung berstand*/));
float
dx
=
0.0
00
f
;
// 0.01
;
float
dy
=
KinectSizeY
/
2.0
f
+
0.004
f
/*HAlterung Platte*/
+
0.011
f
/* Conroller*/
;
float
dz
=
-
0.01
f
;
//-0.023 + 0.02; // 0.045f /*= versatz auf der Halterung; Distanz zur Halterung:*/ + (KinectSizeZ - (0.066 /*halterung z*/ - 0.012 /*halterung berstand*/));
controlerToKinect
=
glm
::
translate
(
controlerToKinect
,
(
glm
::
vec3
(
dx
,
-
dy
,
dz
)));
...
...
@@ -792,17 +834,17 @@ int main(int argc, char* argv[]) {
glm
::
mat4
kinectToController
=
glm
::
inverse
(
controlerToKinect
);
float
angleInDegrees
=
30
;
glm
::
vec4
test
=
controlerToKinect
*
glm
::
rotate
(
glm
::
mat4
(),
degreeToRadi
o
an
(
angleInDegrees
),
glm
::
vec3
(
1.0
f
,
0.0
f
,
0.0
f
))
*
kinectToController
*
glm
::
vec4
(
0.0
,
0.0
,
1.0
,
1.0
);
glm
::
vec4
test
=
controlerToKinect
*
glm
::
rotate
(
glm
::
mat4
(),
degreeToRadian
(
angleInDegrees
),
glm
::
vec3
(
1.0
f
,
0.0
f
,
0.0
f
))
*
kinectToController
*
glm
::
vec4
(
0.0
,
0.0
,
1.0
,
1.0
);
std
::
cout
<<
"Angle Error x "
;
printVector
(
test
);
std
::
cout
<<
std
::
endl
;
test
=
controlerToKinect
*
glm
::
rotate
(
glm
::
mat4
(),
degreeToRadi
o
an
(
angleInDegrees
),
glm
::
vec3
(
0.0
f
,
1.0
f
,
0.0
f
))
*
kinectToController
*
glm
::
vec4
(
0.0
,
0.0
,
1.0
,
1.0
);
test
=
controlerToKinect
*
glm
::
rotate
(
glm
::
mat4
(),
degreeToRadian
(
angleInDegrees
),
glm
::
vec3
(
0.0
f
,
1.0
f
,
0.0
f
))
*
kinectToController
*
glm
::
vec4
(
0.0
,
0.0
,
1.0
,
1.0
);
std
::
cout
<<
"Angle Error y "
;
printVector
(
test
);
std
::
cout
<<
std
::
endl
;
test
=
controlerToKinect
*
glm
::
rotate
(
glm
::
mat4
(),
degreeToRadi
o
an
(
angleInDegrees
),
glm
::
vec3
(
0.0
f
,
0.0
f
,
1.0
f
))
*
kinectToController
*
glm
::
vec4
(
0.0
,
0.0
,
1.0
,
1.0
);
test
=
controlerToKinect
*
glm
::
rotate
(
glm
::
mat4
(),
degreeToRadian
(
angleInDegrees
),
glm
::
vec3
(
0.0
f
,
0.0
f
,
1.0
f
))
*
kinectToController
*
glm
::
vec4
(
0.0
,
0.0
,
1.0
,
1.0
);
std
::
cout
<<
"Angle Error z "
;
printVector
(
test
);
std
::
cout
<<
std
::
endl
;
...
...
3_PointCloud/main.h
View file @
9f572c13
...
...
@@ -45,7 +45,7 @@ void setupFrameBuffer();
void
reshapeFunction
(
int
width
,
int
height
);
void
printVector
(
glm
::
vec3
vector
);
float
degreeToRadi
o
an
(
float
degree
);
float
degreeToRadian
(
float
degree
);
struct
pntsHeader
{
...
...
3_PointCloud/tileset.json
→
3_PointCloud/tileset
1
.json
View file @
9f572c13
...
...
@@ -18,7 +18,7 @@
{
"transform"
:
[
1.0
,
0.0
,
0.0
,
0.0
,
0.0
,
1.0
,
0.0
,
0.0
,
0.0
,
1.0
,
0.0
,
5
0.0
,
0.0
,
0.0
,
1.0
,
0.0
,
0.0
,
0.0
,
0.0
,
1.0
],
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment