Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Angelo-abel
autopybind11
Commits
19a18acc
Commit
19a18acc
authored
May 20, 2020
by
tao558
Browse files
Add input files, automatic generation works
parent
1797c23f
Changes
8
Hide whitespace changes
Inline
Side-by-side
PyBindHelper.cmake
View file @
19a18acc
...
...
@@ -78,8 +78,8 @@ function(autopybind11_add_module)
file
(
GENERATE OUTPUT
"
${
PYBIND_ADD_LIB_RESPONSE_DIR
}
"
CONTENT
"includes:
${
includes
}
\n
defines:
${
defines
}
"
)
if
(
PYBIND_ADD_LIB_
CONFIG
_INPUT AND EXISTS
${
PYBIND_ADD_LIB_CONFIG_INPUT
}
)
add_custom_command
(
OUTPUT
${
PYBIND_ADD_LIB_FILES
}
wrapper.cpp COMMAND
${
PYTHON_EXECUTABLE
}
${
AutoPyBind11_generator
}
-j
${
PYBIND_ADD_LIB_JSON_INPUT
}
if
(
PYBIND_ADD_LIB_
JSON
_INPUT AND EXISTS
${
PYBIND_ADD_LIB_CONFIG_INPUT
}
)
add_custom_command
(
OUTPUT
${
PYBIND_ADD_LIB_FILES
}
wrapper.cpp COMMAND
${
PYTHON_EXECUTABLE
}
${
AutoPyBind11_generator
}
-j
${
PYBIND_ADD_LIB_JSON_INPUT
}
"--module_name"
${
PYBIND_ADD_LIB_NAME
}
"-g"
${
CastXML_EXECUTABLE
}
"-cg"
"
${
PYBIND_ADD_LIB_CONFIG_INPUT
}
"
...
...
example/CMakeLists.txt
View file @
19a18acc
...
...
@@ -16,6 +16,7 @@ autopybind11_fetch_build_pybind11()
# Create default library
add_subdirectory
(
additional
)
add_subdirectory
(
kwiver_inheritance
)
autopybind11_add_module
(
"example"
JSON_INPUT
${
CMAKE_CURRENT_SOURCE_DIR
}
/wrapper_input.json
CONFIG_INPUT
${
CMAKE_CURRENT_SOURCE_DIR
}
/config.yml
...
...
example/kwiver_inheritance/CMakeLists.txt
0 → 100644
View file @
19a18acc
add_library
(
kwiver_descriptor SHARED descriptor.hpp descriptor_array_of.hpp descriptor_dynamic.hpp
)
set_target_properties
(
kwiver_descriptor PROPERTIES LINKER_LANGUAGE CXX
)
target_include_directories
(
kwiver_descriptor PUBLIC
${
CMAKE_CURRENT_SOURCE_DIR
}
)
autopybind11_fetch_build_pybind11
()
autopybind11_add_module
(
"descriptor"
JSON_INPUT
${
CMAKE_CURRENT_SOURCE_DIR
}
/wrapper_input.json
CONFIG_INPUT
${
CMAKE_CURRENT_SOURCE_DIR
}
/config.yml
DESTINATION
${
CMAKE_CURRENT_BINARY_DIR
}
LINK_LIBRARIES kwiver_descriptor
)
example/kwiver_inheritance/config.yml
0 → 100644
View file @
19a18acc
private_members
:
false
example/kwiver_inheritance/descriptor.hpp
0 → 100644
View file @
19a18acc
/*ckwg +29
* Copyright 2013-2018 by Kitware, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither name of Kitware, Inc. nor the names of any contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* \file
* \brief core descriptor interface and template implementations
*/
#ifndef VITAL_DESCRIPTOR_H_
#define VITAL_DESCRIPTOR_H_
#include
<iostream>
#include
<limits>
#include
<memory>
#include
<vector>
#include
<cstring>
/// Shared pointer for base descriptor type
class
descriptor
;
typedef
std
::
shared_ptr
<
descriptor
>
descriptor_sptr
;
// a short name for unsigned char
typedef
unsigned
char
byte
;
// ------------------------------------------------------------------
/// A representation of a feature descriptor used in matching.
class
descriptor
{
public:
int
foo
()
{
return
5
;
}
/// Destructor
virtual
~
descriptor
()
=
default
;
virtual
descriptor_sptr
clone
()
const
=
0
;
/// Access the type info of the underlying data (double or float)
virtual
std
::
type_info
const
&
data_type
()
const
=
0
;
/// The number of elements of the underlying type
virtual
std
::
size_t
size
()
const
=
0
;
/// The number of bytes used to represent the data
virtual
std
::
size_t
num_bytes
()
const
=
0
;
/// Return the descriptor as pointer to bytes
/**
* Subclasses should ensure this always works by storing the data
* as a continuous byte array.
* Note that as_bytes returns a pointer to the underlying data while
* as_double returns a vector of doubles which will be copied from
* the underlying data if possible. As_bytes is written this way
* for speed (no copying) at the cost of being restrictive on sub-classes
* in terms of the way they lay out their descriptors in memory.
*/
virtual
const
byte
*
as_bytes
()
const
=
0
;
/// Return the descriptor as a vector of doubles
/**
* Return an empty vector if this makes no sense
* for the underlying type.
*/
virtual
std
::
vector
<
double
>
as_double
()
const
=
0
;
/// Equality operator
bool
operator
==
(
descriptor
const
&
other
)
const
{
if
(
this
->
data_type
()
!=
other
.
data_type
()
||
this
->
size
()
!=
other
.
size
()
)
{
return
false
;
}
auto
b1
=
this
->
as_bytes
();
auto
b2
=
other
.
as_bytes
();
return
std
::
equal
(
b1
,
b1
+
this
->
num_bytes
(),
b2
);
}
/// Inequality operator
bool
operator
!=
(
descriptor
const
&
other
)
const
{
return
!
operator
==
(
other
);
}
/// Returns the node_id for the descriptor.
/**
* The node_id is generally the vocabulary tree leaf index computed when
* the descriptor is quantized in the tree. Two features with the same
* node_id are expected to have similar visual appearance.
*/
virtual
unsigned
int
node_id
()
const
{
return
0
;
}
/// Sets the node_id for the descriptor.
/**
* By default this returns false because this base class has nowhere
* to store the node_id. Derived classes that do store the node_id
* should return true if it successfully stored.
*/
virtual
bool
set_node_id
(
unsigned
int
node_id
)
{
return
false
;
}
};
// // ------------------------------------------------------------------
// /// output stream operator for a feature
// std::ostream& operator<<( std::ostream& s, const descriptor& d );
// /// input stream operator for a feature
// std::istream& operator>>( std::istream& s, descriptor& d );
#endif // VITAL_DESCRIPTOR_H_
example/kwiver_inheritance/descriptor_array_of.hpp
0 → 100644
View file @
19a18acc
#ifndef VITAL_DESCRIPTOR_ARRAY_OF_H_
#define VITAL_DESCRIPTOR_ARRAY_OF_H_
#include
"descriptor.hpp"
// ------------------------------------------------------------------
/// Abstract base class of a descriptor containing an array of type T
template
<
typename
T
>
class
descriptor_array_of
:
public
descriptor
{
public:
/// Access the type info of the underlying data (double or float)
virtual
std
::
type_info
const
&
data_type
()
const
{
return
typeid
(
T
);
}
/// The number of bytes used to represent the data
std
::
size_t
num_bytes
()
const
{
return
this
->
size
()
*
sizeof
(
T
);
}
/// Return the descriptor as a vector of doubles
std
::
vector
<
double
>
as_double
()
const
{
const
std
::
size_t
length
=
this
->
size
();
std
::
vector
<
double
>
double_data
(
length
);
for
(
std
::
size_t
i
=
0
;
i
<
length
;
++
i
)
{
double_data
[
i
]
=
static_cast
<
double
>
(
this
->
raw_data
()[
i
]
);
}
return
double_data
;
}
virtual
const
byte
*
as_bytes
()
const
{
return
reinterpret_cast
<
const
byte
*>
(
raw_data
());
}
/// Return an pointer to the raw data array
virtual
T
*
raw_data
()
=
0
;
/// Return an pointer to the raw data array
virtual
const
T
*
raw_data
()
const
=
0
;
// Iterator interface
T
const
*
begin
()
const
{
return
this
->
raw_data
();
}
T
const
*
end
()
const
{
return
this
->
raw_data
()
+
this
->
size
();
}
/// Equality operator
bool
operator
==
(
descriptor_array_of
<
T
>
const
&
other
)
const
{
if
(
this
->
size
()
!=
other
.
size
()
)
{
return
false
;
}
return
std
::
equal
(
this
->
raw_data
(),
this
->
raw_data
()
+
this
->
size
(),
other
.
raw_data
());
}
/// Inequality operator
bool
operator
!=
(
descriptor_array_of
<
T
>
const
&
other
)
const
{
return
!
operator
==
(
other
);
}
};
#endif
\ No newline at end of file
example/kwiver_inheritance/descriptor_dynamic.hpp
0 → 100644
View file @
19a18acc
#include
"descriptor_array_of.hpp"
// ------------------------------------------------------------------
/// A representation of a descriptor of fixed type and variable size
template
<
typename
T
>
class
descriptor_dynamic
:
public
descriptor_array_of
<
T
>
{
public:
/// Constructor
descriptor_dynamic
<
T
>
(
size_t
len
)
:
data_
(
new
T
[
len
]
),
length_
(
len
),
node_id_
(
std
::
numeric_limits
<
unsigned
int
>::
max
())
{
}
descriptor_dynamic
<
T
>
(
size_t
len
,
T
*
dat
)
:
length_
(
len
)
{
data_
=
new
T
[
len
];
memmove
(
data_
,
dat
,
len
*
sizeof
(
T
)
);
}
/// Destructor
virtual
~
descriptor_dynamic
<
T
>
(
)
{
delete
[]
data_
;
}
/// The number of elements of the underlying type
std
::
size_t
size
()
const
{
return
length_
;
}
/// Return an pointer to the raw data array
T
*
raw_data
()
{
return
data_
;
}
/// Return an pointer to the raw data array
const
T
*
raw_data
()
const
{
return
data_
;
}
virtual
descriptor_sptr
clone
()
const
{
auto
ptr
=
std
::
make_shared
<
descriptor_dynamic
<
T
>>
(
length_
);
memcpy
(
ptr
->
data_
,
data_
,
length_
*
sizeof
(
T
));
return
ptr
;
}
virtual
unsigned
int
node_id
()
const
{
return
node_id_
;
}
virtual
bool
set_node_id
(
unsigned
int
node_id
)
{
node_id_
=
node_id
;
return
true
;
}
protected:
/// data array
T
*
data_
;
/// length of data array
size_t
length_
;
/// node id
unsigned
int
node_id_
;
};
example/kwiver_inheritance/wrapper_input.json
0 → 100644
View file @
19a18acc
{
"classes"
:
{
"descriptor"
:
{
"file"
:
"descriptor.hpp"
,
"inst"
:
[]
},
"descriptor_array_of"
:
{
"file"
:
"descriptor_array_of.hpp"
,
"inst"
:
[
"float"
]
},
"descriptor_dynamic"
:
{
"file"
:
"descriptor_dynamic.hpp"
,
"inst"
:
[
"float"
]
}
}
}
Write
Preview
Supports
Markdown
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