Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removearma #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<<<<<<< HEAD
/.clang_complete
/GPATH
/GRTAGS
Expand All @@ -10,8 +9,6 @@ build
*.pdf
*.tex
*.fdb_latexmk
=======
>>>>>>> 9ee4789... Initial commit
# Compiled Object files
*.slo
*.lo
Expand Down Expand Up @@ -40,3 +37,4 @@ build
*.exe
*.out
*.app
.vscode/c_cpp_properties.json
27 changes: 27 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/softpositdemo",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
60 changes: 60 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"files.associations": {
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"array": "cpp",
"atomic": "cpp",
"*.tcc": "cpp",
"chrono": "cpp",
"complex": "cpp",
"condition_variable": "cpp",
"cstdint": "cpp",
"deque": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"map": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp",
"core": "cpp",
"dense": "cpp",
"armadillo": "cpp"
}
}
26 changes: 26 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"tasks": [
{
"type": "shell",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
],
"version": "2.0.0"
}
17 changes: 5 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ IF(CMAKE_VERSION VERSION_EQUAL "3.0.0" OR CMAKE_VERSION VERSION_GREATER "3.0.0")
ENDIF()

# use libc++ for osx
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -std=c++1y")

if (APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif
endif()

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR})
Expand Down Expand Up @@ -40,23 +38,18 @@ if (APPLE)
set(ALL_LIBS ${Accelerate_LIBRARIES})
endif()

# find Eigen3
find_package(Eigen3 3.0.0 REQUIRED)

# find boost
find_package(Boost)
link_directories(${Boost_LIBRARY_DIRS})

# armadillo
find_package(Armadillo REQUIRED)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${PROJECT_BINARY_DIR}
${Boost_INCLUDE_DIRS}
${ARMADILLO_INCLUDE_DIRS}
"/usr/include/eigen3/"
)

add_definitions("-D_USE_MATH_DEFINES")

set(ALL_LIBS ${ALL_LIBS} ${Boost_LIBRARIES} ${ARMADILLO_LIBRARIES})
set(ALL_LIBS ${ALL_LIBS})


add_subdirectory(src)
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,20 @@ This repo. provides my cpp implementation.
# How to Build

## Dependency
1. Armadillo
1. Eigen3

It mainly depends on the Armadillo linear algebra library.
It mainly depends on the Eigen3 linear algebra library.

2. Boost (Format)

There are also dependency on Boost, and only for outside logging code which can be easily removed.

## Build Steps
The project is managed with CMake.

Suggested steps:

```
git clone git@github.com:autosquid/softposit.git
git clone https://github.com/wqhot/softposit-cpp
cd softposit
git checkout removearma
mkdir build
cd build
cmake ..
Expand Down
131 changes: 67 additions & 64 deletions src/demo/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,79 +6,82 @@

int main()
{
std::string name;
std::cout<<"hello, "<<name<<std::endl;
std::string name;
std::cout << "hello, " << name << std::endl;

std::vector<bloody::point2di_type> imagePts;
std::vector<bloody::point3d_type> worldPts;
std::vector<bloody::point2di_type> imagePts;
std::vector<bloody::point3d_type> worldPts;

std::vector<int> raw_imagePts {
612,
117,
486,
145,
567,
206,
476,
234,
441,
329};
std::vector<int> raw_imagePts{
612,
117,
486,
145,
567,
206,
476,
234,
441,
329};

std::cout<<"load image points"<<std::endl;
for (uint i=0u; i<raw_imagePts.size(); i+=2){
imagePts.push_back(bloody::point2di_type{raw_imagePts[i], raw_imagePts[i+1]});
}
std::cout << "load image points" << std::endl;
for (uint i = 0u; i < raw_imagePts.size(); i += 2)
{
imagePts.push_back(bloody::point2di_type{raw_imagePts[i], raw_imagePts[i + 1]});
}

std::vector<double> raw_worldPts{-3.7500,
0,
0.5000,
7.5000,
0,
2.7500,
-3.0000,
-5.0000,
-2.0000,
3.0000,
5.0000,
-2.0000,
0,
2.2500,
-0.7500,
0,
-2.2500,
-0.7500};

std::vector<double> raw_worldPts{ -3.7500,
0,
0.5000,
7.5000,
0,
2.7500,
-3.0000,
-5.0000,
-2.0000,
3.0000,
5.0000,
-2.0000,
0,
2.2500,
-0.7500,
0,
-2.2500,
-0.7500
};
std::cout << "load world points" << std::endl;
for (uint i = 0u; i < raw_worldPts.size(); i += 3)
{
worldPts.push_back(bloody::point3d_type{raw_worldPts[i], raw_worldPts[i + 1], raw_worldPts[i + 2]});
}

std::cout<<"load world points"<<std::endl;
for (uint i=0u; i<raw_worldPts.size(); i+=3){
worldPts.push_back(bloody::point3d_type{raw_worldPts[i], raw_worldPts[i+1], raw_worldPts[i+2]});
}
bloody::Param_type param{2.0E-4, 10.0};
bloody::CamInfo_type caminfo{982.1f, bloody::point2di_type{376, 240}};

bloody::Param_type param{ 2.0E-4, 10.0};
bloody::CamInfo_type caminfo{982.1f, bloody::point2di_type{376, 240}};
bloody::Pose_type initpose;

bloody::Pose_type initpose;
initpose.rot << 0, -1, 0, 1, 0, 0, 0, 0, 1;
initpose.trans = bloody::point3d_type{0, 0, 30};

initpose.rot = arma::mat("0, 1, 0; -1, 0, 0; 0, 0, 1").t();
initpose.trans = bloody::point3d_type{0, 0, 30};
auto maybe_pose = softposit(
imagePts,
worldPts,
param,
initpose,
std::make_pair(caminfo, true));

auto maybe_pose = softposit(
imagePts,
worldPts,
param,
initpose,
caminfo
);

if (maybe_pose){
auto pose = std::get<0>(*maybe_pose);
std::cout<<pose.rot<<std::endl;
std::cout<<pose.trans<<std::endl;
}else{
std::cout<<"failed"<<std::endl;
}

return 0;
if (maybe_pose.second)
{
bloody::Pose_type pose;
bloody::match_type match;
std::tie(pose, match) = maybe_pose.first;
std::cout << pose.rot << std::endl;
std::cout << pose.trans << std::endl;
}
else
{
std::cout << "failed" << std::endl;
}

return 0;
}
Loading