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
5e384614
Commit
5e384614
authored
May 28, 2011
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed the array2d object so you don't have to say array2d<type>::kernel_1a
anymore to declare it. Now you just say array2d<type>.
parent
35a6408f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
106 additions
and
457 deletions
+106
-457
array2d.h
dlib/array2d.h
+0
-32
array2d_kernel_1.h
dlib/array2d/array2d_kernel_1.h
+102
-20
array2d_kernel_c.h
dlib/array2d/array2d_kernel_c.h
+0
-382
containers.xml
docs/docs/containers.xml
+0
-19
image_ex.cpp
examples/image_ex.cpp
+3
-3
surf_ex.cpp
examples/surf_ex.cpp
+1
-1
No files found.
dlib/array2d.h
View file @
5e384614
...
...
@@ -5,39 +5,7 @@
#include "array2d/array2d_kernel_1.h"
#include "array2d/array2d_kernel_c.h"
#include "algs.h"
namespace
dlib
{
template
<
typename
T
,
typename
mem_manager
=
default_memory_manager
>
class
array2d
{
array2d
()
{}
public
:
//----------- kernels ---------------
// kernel_1a
typedef
array2d_kernel_1
<
T
,
mem_manager
>
kernel_1a
;
typedef
array2d_kernel_c
<
kernel_1a
>
kernel_1a_c
;
};
}
#endif // DLIB_ARRAY2d_
dlib/array2d/array2d_kernel_1.h
View file @
5e384614
...
...
@@ -15,7 +15,7 @@ namespace dlib
typename
T
,
typename
mem_manager
=
default_memory_manager
>
class
array2d
_kernel_1
:
public
enumerable
<
T
>
class
array2d
:
public
enumerable
<
T
>
{
/*!
...
...
@@ -59,6 +59,10 @@ namespace dlib
class
row_helper
;
public
:
// These typedefs are here for backwards compatibility with older versions of dlib.
typedef
array2d
kernel_1a
;
typedef
array2d
kernel_1a_c
;
typedef
T
type
;
typedef
mem_manager
mem_manager_type
;
...
...
@@ -74,7 +78,7 @@ namespace dlib
- (*this)[x] == data[x]
!*/
friend
class
array2d
_kernel_1
;
friend
class
array2d
;
friend
class
row_helper
;
public
:
...
...
@@ -83,11 +87,35 @@ namespace dlib
const
T
&
operator
[]
(
long
column
)
const
{
return
data
[
column
];
}
)
const
{
// make sure requires clause is not broken
DLIB_ASSERT
(
column
<
nc
()
&&
column
>=
0
,
"
\t
const T& array2d::operator[](long column) const"
<<
"
\n\t
The column index given must be less than the number of columns."
<<
"
\n\t
this: "
<<
this
<<
"
\n\t
column: "
<<
column
<<
"
\n\t
nc(): "
<<
nc
()
);
return
data
[
column
];
}
T
&
operator
[]
(
long
column
)
{
return
data
[
column
];
}
)
{
// make sure requires clause is not broken
DLIB_ASSERT
(
column
<
nc
()
&&
column
>=
0
,
"
\t
T& array2d::operator[](long column)"
<<
"
\n\t
The column index given must be less than the number of columns."
<<
"
\n\t
this: "
<<
this
<<
"
\n\t
column: "
<<
column
<<
"
\n\t
nc(): "
<<
nc
()
);
return
data
[
column
];
}
private
:
...
...
@@ -103,7 +131,7 @@ namespace dlib
// -----------------------------------
array2d
_kernel_1
(
array2d
(
)
:
nc_
(
0
),
nr_
(
0
),
...
...
@@ -115,7 +143,7 @@ namespace dlib
{
}
virtual
~
array2d
_kernel_1
(
virtual
~
array2d
(
)
{
clear
();
}
long
nc
(
...
...
@@ -126,14 +154,38 @@ namespace dlib
row
&
operator
[]
(
long
row
)
{
return
rows
[
row
];
}
)
{
// make sure requires clause is not broken
DLIB_ASSERT
(
row
<
nr
()
&&
row
>=
0
,
"
\t
row& array2d::operator[](long row)"
<<
"
\n\t
The row index given must be less than the number of rows."
<<
"
\n\t
this: "
<<
this
<<
"
\n\t
row: "
<<
row
<<
"
\n\t
nr(): "
<<
nr
()
);
return
rows
[
row
];
}
const
row
&
operator
[]
(
long
row
)
const
{
return
rows
[
row
];
}
)
const
{
// make sure requires clause is not broken
DLIB_ASSERT
(
row
<
nr
()
&&
row
>=
0
,
"
\t
const row& array2d::operator[](long row) const"
<<
"
\n\t
The row index given must be less than the number of rows."
<<
"
\n\t
this: "
<<
this
<<
"
\n\t
row: "
<<
row
<<
"
\n\t
nr(): "
<<
nr
()
);
return
rows
[
row
];
}
void
swap
(
array2d
_kernel_1
&
item
array2d
&
item
)
{
exchange
(
data
,
item
.
data
);
...
...
@@ -179,10 +231,30 @@ namespace dlib
)
const
{
return
(
cur
!=
0
);
}
const
T
&
element
(
)
const
{
return
*
cur
;
}
)
const
{
// make sure requires clause is not broken
DLIB_ASSERT
(
current_element_valid
()
==
true
,
"
\t
const T& array2d::element()()"
<<
"
\n\t
You can only call element() when you are at a valid one."
<<
"
\n\t
this: "
<<
this
);
return
*
cur
;
}
T
&
element
(
)
{
return
*
cur
;
}
)
{
// make sure requires clause is not broken
DLIB_ASSERT
(
current_element_valid
()
==
true
,
"
\t
T& array2d::element()()"
<<
"
\n\t
You can only call element() when you are at a valid one."
<<
"
\n\t
this: "
<<
this
);
return
*
cur
;
}
bool
move_next
(
)
const
...
...
@@ -233,8 +305,8 @@ namespace dlib
mutable
bool
at_start_
;
// restricted functions
array2d
_kernel_1
(
array2d_kernel_1
&
);
// copy constructor
array2d
_kernel_1
&
operator
=
(
array2d_kernel_1
&
);
// assignment operator
array2d
(
array2d
&
);
// copy constructor
array2d
&
operator
=
(
array2d
&
);
// assignment operator
};
...
...
@@ -245,8 +317,8 @@ namespace dlib
typename
mem_manager
>
inline
void
swap
(
array2d
_kernel_1
<
T
,
mem_manager
>&
a
,
array2d
_kernel_1
<
T
,
mem_manager
>&
b
array2d
<
T
,
mem_manager
>&
a
,
array2d
<
T
,
mem_manager
>&
b
)
{
a
.
swap
(
b
);
}
...
...
@@ -255,7 +327,7 @@ namespace dlib
typename
mem_manager
>
void
serialize
(
const
array2d
_kernel_1
<
T
,
mem_manager
>&
item
,
const
array2d
<
T
,
mem_manager
>&
item
,
std
::
ostream
&
out
)
{
...
...
@@ -271,7 +343,7 @@ namespace dlib
}
catch
(
serialization_error
e
)
{
throw
serialization_error
(
e
.
info
+
"
\n
while serializing object of type array2d
_kernel_1
"
);
throw
serialization_error
(
e
.
info
+
"
\n
while serializing object of type array2d"
);
}
}
...
...
@@ -279,7 +351,7 @@ namespace dlib
typename
T
>
void
deserialize
(
array2d
_kernel_1
<
T
>&
item
,
array2d
<
T
>&
item
,
std
::
istream
&
in
)
{
...
...
@@ -298,7 +370,7 @@ namespace dlib
catch
(
serialization_error
e
)
{
item
.
clear
();
throw
serialization_error
(
e
.
info
+
"
\n
while deserializing object of type array2d
_kernel_1
"
);
throw
serialization_error
(
e
.
info
+
"
\n
while deserializing object of type array2d"
);
}
}
...
...
@@ -312,12 +384,22 @@ namespace dlib
typename
T
,
typename
mem_manager
>
void
array2d
_kernel_1
<
T
,
mem_manager
>::
void
array2d
<
T
,
mem_manager
>::
set_size
(
long
nr__
,
long
nc__
)
{
// make sure requires clause is not broken
DLIB_ASSERT
((
nc__
>
0
&&
nr__
>
0
)
||
(
nc__
==
0
&&
nr__
==
0
),
"
\t
void array2d::set_size(long nr__, long nc__)"
<<
"
\n\t
You have to give a non zero nc and nr or just make both zero."
<<
"
\n\t
this: "
<<
this
<<
"
\n\t
nc__: "
<<
nc__
<<
"
\n\t
nr__: "
<<
nr__
);
// set the enumerator back at the start
at_start_
=
true
;
cur
=
0
;
...
...
dlib/array2d/array2d_kernel_c.h
deleted
100644 → 0
View file @
35a6408f
// Copyright (C) 2006 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_ARRAY2D_KERNEl_C_
#define DLIB_ARRAY2D_KERNEl_C_
#include "array2d_kernel_abstract.h"
#include "../algs.h"
#include "../assert.h"
#include "../interfaces/enumerable.h"
namespace
dlib
{
template
<
typename
array2d_base
// is an implementation of array2d_kernel_abstract.h
>
class
array2d_kernel_c
:
public
enumerable
<
typename
array2d_base
::
type
>
{
/*!
CONVENTION
- if (obj.size() > 0) then
- rows == an array of size obj.nr() row objects and
each row object in the array has a valid pointer to its
associated row in obj.
- else
- rows == 0
!*/
typedef
typename
array2d_base
::
type
T
;
public
:
typedef
typename
array2d_base
::
type
type
;
typedef
typename
array2d_base
::
mem_manager_type
mem_manager_type
;
// -----------------------------------
class
row
{
friend
class
array2d_kernel_c
;
public
:
long
nc
(
)
const
{
return
data
->
nc
();
}
const
T
&
operator
[]
(
long
column
)
const
;
T
&
operator
[]
(
long
column
);
private
:
typename
array2d_base
::
row
*
data
;
// restricted functions
row
(){}
row
(
row
&
);
row
&
operator
=
(
row
&
);
};
// -----------------------------------
array2d_kernel_c
(
)
:
rows
(
0
)
{
}
virtual
~
array2d_kernel_c
(
)
{
clear
();
}
long
nc
(
)
const
{
return
obj
.
nc
();
}
long
nr
(
)
const
{
return
obj
.
nr
();
}
row
&
operator
[]
(
long
row
);
const
row
&
operator
[]
(
long
row
)
const
;
void
swap
(
array2d_kernel_c
&
item
)
{
exchange
(
obj
,
item
.
obj
);
exchange
(
rows
,
item
.
rows
);
}
void
clear
(
)
{
obj
.
clear
();
if
(
rows
!=
0
)
{
delete
[]
rows
;
rows
=
0
;
}
}
void
set_size
(
long
nr__
,
long
nc__
);
bool
at_start
(
)
const
{
return
obj
.
at_start
();;
}
void
reset
(
)
const
{
obj
.
reset
();
}
bool
current_element_valid
(
)
const
{
return
obj
.
current_element_valid
();
}
const
T
&
element
(
)
const
;
T
&
element
(
);
bool
move_next
(
)
const
{
return
obj
.
move_next
();
}
unsigned
long
size
(
)
const
{
return
obj
.
size
();
}
private
:
array2d_base
obj
;
row
*
rows
;
};
template
<
typename
array2d_base
>
inline
void
swap
(
array2d_kernel_c
<
array2d_base
>&
a
,
array2d_kernel_c
<
array2d_base
>&
b
)
{
a
.
swap
(
b
);
}
template
<
typename
array2d_base
>
void
serialize
(
const
array2d_kernel_c
<
array2d_base
>&
item
,
std
::
ostream
&
out
)
{
try
{
serialize
(
item
.
nc
(),
out
);
serialize
(
item
.
nr
(),
out
);
item
.
reset
();
while
(
item
.
move_next
())
serialize
(
item
.
element
(),
out
);
item
.
reset
();
}
catch
(
serialization_error
e
)
{
throw
serialization_error
(
e
.
info
+
"
\n
while serializing object of type array2d_kernel_c"
);
}
}
template
<
typename
array2d_base
>
void
deserialize
(
array2d_kernel_c
<
array2d_base
>&
item
,
std
::
istream
&
in
)
{
try
{
long
nc
,
nr
;
deserialize
(
nc
,
in
);
deserialize
(
nr
,
in
);
item
.
set_size
(
nr
,
nc
);
while
(
item
.
move_next
())
deserialize
(
item
.
element
(),
in
);
item
.
reset
();
}
catch
(
serialization_error
e
)
{
item
.
clear
();
throw
serialization_error
(
e
.
info
+
"
\n
while deserializing object of type array2d_kernel_c"
);
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// member function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
typename
array2d_base
>
const
typename
array2d_base
::
type
&
array2d_kernel_c
<
array2d_base
>::
element
(
)
const
{
// make sure requires clause is not broken
DLIB_CASSERT
(
current_element_valid
()
==
true
,
"
\t
T& array2d::element()()"
<<
"
\n\t
You can only call element() when you are at a valid one."
<<
"
\n\t
this: "
<<
this
);
return
obj
.
element
();
}
// ----------------------------------------------------------------------------------------
template
<
typename
array2d_base
>
typename
array2d_base
::
type
&
array2d_kernel_c
<
array2d_base
>::
element
(
)
{
// make sure requires clause is not broken
DLIB_CASSERT
(
current_element_valid
()
==
true
,
"
\t
T& array2d::element()()"
<<
"
\n\t
You can only call element() when you are at a valid one."
<<
"
\n\t
this: "
<<
this
);
return
obj
.
element
();
}
// ----------------------------------------------------------------------------------------
template
<
typename
array2d_base
>
void
array2d_kernel_c
<
array2d_base
>::
set_size
(
long
nr_
,
long
nc_
)
{
// make sure requires clause is not broken
DLIB_CASSERT
((
nc_
>
0
&&
nr_
>
0
)
||
(
nc_
==
0
&&
nr_
==
0
),
"
\t
void array2d::set_size(long nr_, long nc_)"
<<
"
\n\t
You have to give a non zero nc and nr or just make both zero."
<<
"
\n\t
this: "
<<
this
<<
"
\n\t
nc_: "
<<
nc_
<<
"
\n\t
nr_: "
<<
nr_
);
obj
.
set_size
(
nr_
,
nc_
);
// set up the rows array
if
(
rows
!=
0
)
delete
[]
rows
;
try
{
rows
=
new
row
[
obj
.
nr
()];
}
catch
(...)
{
rows
=
0
;
obj
.
clear
();
throw
;
}
for
(
long
i
=
0
;
i
<
obj
.
nr
();
++
i
)
{
rows
[
i
].
data
=
&
obj
[
i
];
}
}
// ----------------------------------------------------------------------------------------
template
<
typename
array2d_base
>
typename
array2d_kernel_c
<
array2d_base
>::
row
&
array2d_kernel_c
<
array2d_base
>::
operator
[]
(
long
row
)
{
// make sure requires clause is not broken
DLIB_CASSERT
(
row
<
nr
()
&&
row
>=
0
,
"
\t
row& array2d::operator[](long row)"
<<
"
\n\t
The row index given must be less than the number of rows."
<<
"
\n\t
this: "
<<
this
<<
"
\n\t
row: "
<<
row
<<
"
\n\t
nr(): "
<<
nr
()
);
return
rows
[
row
];
}
// ----------------------------------------------------------------------------------------
template
<
typename
array2d_base
>
const
typename
array2d_kernel_c
<
array2d_base
>::
row
&
array2d_kernel_c
<
array2d_base
>::
operator
[]
(
long
row
)
const
{
// make sure requires clause is not broken
DLIB_CASSERT
(
row
<
nr
()
&&
row
>=
0
,
"
\t
const row& array2d::operator[](long row) const"
<<
"
\n\t
The row index given must be less than the number of rows."
<<
"
\n\t
this: "
<<
this
<<
"
\n\t
row: "
<<
row
<<
"
\n\t
nr(): "
<<
nr
()
);
return
rows
[
row
];
}
// ----------------------------------------------------------------------------------------
template
<
typename
array2d_base
>
const
typename
array2d_base
::
type
&
array2d_kernel_c
<
array2d_base
>::
row
::
operator
[]
(
long
column
)
const
{
// make sure requires clause is not broken
DLIB_CASSERT
(
column
<
nc
()
&&
column
>=
0
,
"
\t
const T& array2d::operator[](long column) const"
<<
"
\n\t
The column index given must be less than the number of columns."
<<
"
\n\t
this: "
<<
this
<<
"
\n\t
column: "
<<
column
<<
"
\n\t
nc(): "
<<
nc
()
);
return
(
*
data
)[
column
];
}
// ----------------------------------------------------------------------------------------
template
<
typename
array2d_base
>
typename
array2d_base
::
type
&
array2d_kernel_c
<
array2d_base
>::
row
::
operator
[]
(
long
column
)
{
// make sure requires clause is not broken
DLIB_CASSERT
(
column
<
nc
()
&&
column
>=
0
,
"
\t
T& array2d::operator[](long column)"
<<
"
\n\t
The column index given must be less than the number of columns."
<<
"
\n\t
this: "
<<
this
<<
"
\n\t
column: "
<<
column
<<
"
\n\t
nc(): "
<<
nc
()
);
return
(
*
data
)[
column
];
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_ARRAY2D_KERNEl_C_
docs/docs/containers.xml
View file @
5e384614
...
...
@@ -815,25 +815,6 @@
<example>
image_ex.cpp.html
</example>
</examples>
<implementations>
<implementation>
<name>
array2d_kernel_1
</name>
<file>
dlib/array2d/array2d_kernel_1.h
</file>
<description>
This is implemented in the obvious way. See the source for details.
It uses the
<a
href=
"other.html#memory_manager"
>
memory_manager
</a>
for all memory allocations.
</description>
<typedefs>
<typedef>
<name>
kernel_1a
</name>
<description>
is a typedef for array2d_kernel_1
</description>
</typedef>
</typedefs>
</implementation>
</implementations>
</component>
<!-- ************************************************************************* -->
...
...
examples/image_ex.cpp
View file @
5e384614
...
...
@@ -37,7 +37,7 @@ int main(int argc, char** argv)
// Here we declare an image object that can store rgb_pixels. Note that in
// dlib there is no explicit image object, just a 2D array and
// various pixel types.
array2d
<
rgb_pixel
>
::
kernel_1a
img
;
array2d
<
rgb_pixel
>
img
;
// Now load the image file into our image. If something is wrong then
// load_image() will throw an exception. Also, if you compiled with libpng
...
...
@@ -48,8 +48,8 @@ int main(int argc, char** argv)
// Now lets use some image functions. This example is going to perform
// simple edge detection on the image. First lets find the horizontal and
// vertical gradient images.
array2d
<
short
>
::
kernel_1a
horz_gradient
,
vert_gradient
;
array2d
<
unsigned
char
>
::
kernel_1a
edge_image
;
array2d
<
short
>
horz_gradient
,
vert_gradient
;
array2d
<
unsigned
char
>
edge_image
;
sobel_edge_detector
(
img
,
horz_gradient
,
vert_gradient
);
// now we do the non-maximum edge suppression step so that our edges are nice and thin
...
...
examples/surf_ex.cpp
View file @
5e384614
...
...
@@ -43,7 +43,7 @@ int main(int argc, char** argv)
// Here we declare an image object that can store rgb_pixels. Note that in
// dlib there is no explicit image object, just a 2D array and
// various pixel types.
array2d
<
rgb_pixel
>
::
kernel_1a
img
;
array2d
<
rgb_pixel
>
img
;
// Now load the image file into our image. If something is wrong then
// load_image() will throw an exception. Also, if you compiled with libpng
...
...
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