Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
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
钟尚武
dlib
Commits
3044fff8
Commit
3044fff8
authored
Jun 03, 2015
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved the depth testing for the perspective_display.
parent
acca22a9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
57 deletions
+16
-57
widgets.cpp
dlib/gui_widgets/widgets.cpp
+14
-47
widgets.h
dlib/gui_widgets/widgets.h
+2
-10
No files found.
dlib/gui_widgets/widgets.cpp
View file @
3044fff8
...
...
@@ -5722,14 +5722,12 @@ namespace dlib
max_pts
.
z
()
=
std
::
max
(
overlay
[
i
].
p2
.
z
(),
max_pts
.
z
());
}
dot_sorting_is_stale
=
true
;
tform
=
camera_transform
(
max_pts
,
sum_pts
/
(
overlay_lines
.
size
()
*
2
+
overlay_dots
.
size
()),
vector
<
double
>
(
0
,
0
,
1
),
tform
.
get_camera_field_of_view
(),
std
::
min
(
rect
.
width
(),
rect
.
height
()));
sort_dots
();
// make the parent window redraw us now that we changed the overlay
parent
.
invalidate_rectangle
(
rect
);
...
...
@@ -5748,7 +5746,7 @@ namespace dlib
for
(
unsigned
long
i
=
0
;
i
<
overlay
.
size
();
++
i
)
{
overlay_dots
.
push_back
(
std
::
make_pair
(
overlay
[
i
],
0
)
);
overlay_dots
.
push_back
(
overlay
[
i
]
);
sum_pts
+=
overlay
[
i
].
p
;
max_pts
.
x
()
=
std
::
max
(
overlay
[
i
].
p
.
x
(),
max_pts
.
x
());
...
...
@@ -5756,7 +5754,6 @@ namespace dlib
max_pts
.
z
()
=
std
::
max
(
overlay
[
i
].
p
.
z
(),
max_pts
.
z
());
}
dot_sorting_is_stale
=
true
;
tform
=
camera_transform
(
max_pts
,
sum_pts
/
(
overlay_lines
.
size
()
*
2
+
overlay_dots
.
size
()),
vector
<
double
>
(
0
,
0
,
1
),
...
...
@@ -5803,6 +5800,10 @@ namespace dlib
const
canvas
&
c
)
const
{
if
(
depth
.
nr
()
<
c
.
height
()
||
depth
.
nc
()
<
c
.
width
())
depth
.
set_size
(
c
.
height
(),
c
.
width
());
assign_all_pixels
(
depth
,
std
::
numeric_limits
<
float
>::
infinity
());
rectangle
area
=
rect
.
intersect
(
c
);
fill_rect
(
c
,
area
,
0
);
for
(
unsigned
long
i
=
0
;
i
<
overlay_lines
.
size
();
++
i
)
...
...
@@ -5814,9 +5815,13 @@ namespace dlib
}
for
(
unsigned
long
i
=
0
;
i
<
overlay_dots
.
size
();
++
i
)
{
point
p
=
tform
(
overlay_dots
[
i
].
first
.
p
)
+
rect
.
tl_corner
();
if
(
area
.
contains
(
p
))
assign_pixel
(
c
[
p
.
y
()
-
c
.
top
()][
p
.
x
()
-
c
.
left
()],
overlay_dots
[
i
].
first
.
color
);
double
scale
,
distance
;
point
p
=
tform
(
overlay_dots
[
i
].
p
,
scale
,
distance
)
+
rect
.
tl_corner
();
if
(
area
.
contains
(
p
)
&&
depth
[
p
.
y
()
-
c
.
top
()][
p
.
x
()
-
c
.
left
()]
>
distance
)
{
depth
[
p
.
y
()
-
c
.
top
()][
p
.
x
()
-
c
.
left
()]
=
distance
;
assign_pixel
(
c
[
p
.
y
()
-
c
.
top
()][
p
.
x
()
-
c
.
left
()],
overlay_dots
[
i
].
color
);
}
}
}
...
...
@@ -5885,7 +5890,7 @@ namespace dlib
const
dpoint
pp
(
x
,
y
);
for
(
unsigned
long
i
=
0
;
i
<
overlay_dots
.
size
();
++
i
)
{
dpoint
p
=
tform
(
overlay_dots
[
i
].
first
.
p
)
+
rect
.
tl_corner
();
dpoint
p
=
tform
(
overlay_dots
[
i
].
p
)
+
rect
.
tl_corner
();
double
dist
=
length_squared
(
p
-
pp
);
if
(
dist
<
best_dist
)
{
...
...
@@ -5894,43 +5899,7 @@ namespace dlib
}
}
if
(
dot_clicked_event_handler
.
is_set
())
dot_clicked_event_handler
(
overlay_dots
[
best_idx
].
first
.
p
);
}
}
// ----------------------------------------------------------------------------------------
void
perspective_display
::
sort_dots
(
)
{
if
(
dot_sorting_is_stale
)
{
// sort the dots so that the dots farthest from the camera are drawn first.
// We begin by updating the distance from each dot to the camera.
const
vector
<
double
>
cam
=
tform
.
get_camera_pos
();
for
(
unsigned
long
i
=
0
;
i
<
overlay_dots
.
size
();
++
i
)
overlay_dots
[
i
].
second
=
length_squared
(
overlay_dots
[
i
].
first
.
p
-
cam
);
std
::
sort
(
overlay_dots
.
rbegin
(),
overlay_dots
.
rend
(),
compare_second
);
dot_sorting_is_stale
=
false
;
parent
.
invalidate_rectangle
(
rect
);
}
}
// ----------------------------------------------------------------------------------------
void
perspective_display
::
on_mouse_up
(
unsigned
long
,
// btn,
unsigned
long
,
// state,
long
,
// x,
long
// y
)
{
if
(
!
hidden
&&
enabled
&&
overlay_dots
.
size
()
!=
0
)
{
sort_dots
();
dot_clicked_event_handler
(
overlay_dots
[
best_idx
].
p
);
}
}
...
...
@@ -5961,7 +5930,6 @@ namespace dlib
// now make it have the correct radius relative to the looking at point.
new_pos
=
(
new_pos
-
tform
.
get_camera_looking_at
()).
normalize
()
*
length
(
radius
)
+
tform
.
get_camera_looking_at
();
dot_sorting_is_stale
=
true
;
tform
=
camera_transform
(
new_pos
,
tform
.
get_camera_looking_at
(),
tangent_y
,
...
...
@@ -5984,7 +5952,6 @@ namespace dlib
vector
<
double
>
offset
=
tangent_x
*
delta
.
x
()
+
tangent_y
*-
delta
.
y
();
dot_sorting_is_stale
=
true
;
tform
=
camera_transform
(
tform
.
get_camera_pos
()
+
offset
,
tform
.
get_camera_looking_at
()
+
offset
,
...
...
dlib/gui_widgets/widgets.h
View file @
3044fff8
...
...
@@ -3706,13 +3706,6 @@ namespace dlib
bool
is_double_click
);
void
on_mouse_up
(
unsigned
long
btn
,
unsigned
long
state
,
long
x
,
long
y
);
void
on_mouse_move
(
unsigned
long
state
,
long
x
,
...
...
@@ -3724,17 +3717,16 @@ namespace dlib
const
std
::
pair
<
overlay_dot
,
float
>&
b
)
{
return
a
.
second
<
b
.
second
;
}
void
sort_dots
();
point
last
;
std
::
vector
<
overlay_line
>
overlay_lines
;
std
::
vector
<
std
::
pair
<
overlay_dot
,
float
>
>
overlay_dots
;
std
::
vector
<
overlay_dot
>
overlay_dots
;
camera_transform
tform
;
vector
<
double
>
sum_pts
;
vector
<
double
>
max_pts
;
any_function
<
void
(
const
vector
<
double
>&
)
>
dot_clicked_event_handler
;
bool
dot_sorting_is_stale
;
mutable
array2d
<
float
>
depth
;
};
// ----------------------------------------------------------------------------------------
...
...
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