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

not sure if it is needed - just in case #250

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
29 changes: 17 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,25 @@ set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
# required libraries
find_package(SuiteParse REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(Boost COMPONENTS system thread)
#find_package(Boost COMPONENTS system thread)

# optional libraries
find_package(LibZip QUIET)
find_package(Pangolin 0.2 QUIET)
find_package(OpenCV QUIET)

set(CMAKE_CXX_STANDARD 17)

# flags
add_definitions("-DENABLE_SSE")
add_definitions("-DSOPHUS_USE_BASIC_LOGGING")
set(CMAKE_CXX_FLAGS
"${SSE_FLAGS} -O3 -g -std=c++0x -march=native"
# "${SSE_FLAGS} -O3 -g -std=c++0x -fno-omit-frame-pointer"
)

if (MSVC)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /bigobj -D_USE_MATH_DEFINES -D__SSE3__")
endif (MSVC)

# Sources files
Expand All @@ -55,11 +58,12 @@ set(dso_SOURCE_FILES
${PROJECT_SOURCE_DIR}/src/util/globalCalib.cpp
)


find_path(SOPHUS_INCLUDE_DIRS "sophus/common.hpp")

include_directories(
${PROJECT_SOURCE_DIR}/src
${PROJECT_SOURCE_DIR}/thirdparty/Sophus
# ${PROJECT_SOURCE_DIR}/thirdparty/Sophus
${SOPHUS_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/thirdparty/sse2neon
${EIGEN3_INCLUDE_DIR}
)
Expand Down Expand Up @@ -109,23 +113,24 @@ endif()


# compile main library.
include_directories( ${CSPARSE_INCLUDE_DIR} ${CHOLMOD_INCLUDE_DIR})
add_library(dso ${dso_SOURCE_FILES} ${dso_opencv_SOURCE_FILES} ${dso_pangolin_SOURCE_FILES})
#include_directories( ${CSPARSE_INCLUDE_DIR} ${CHOLMOD_INCLUDE_DIR})
add_library(dso STATIC ${dso_SOURCE_FILES} ${dso_opencv_SOURCE_FILES} ${dso_pangolin_SOURCE_FILES})
#target_link_libraries(dso PRIVATE Eigen3::Eigen)

#set_property( TARGET dso APPEND_STRING PROPERTY COMPILE_FLAGS -Wall )


if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") # OSX
set(BOOST_THREAD_LIBRARY boost_thread-mt)
else()
set(BOOST_THREAD_LIBRARY boost_thread)
endif()
#if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") # OSX
# set(BOOST_THREAD_LIBRARY boost_thread-mt)
#else()
# set(BOOST_THREAD_LIBRARY boost_thread)
#endif()

# build main executable (only if we have both OpenCV and Pangolin)
if (OpenCV_FOUND AND Pangolin_FOUND)
message("--- compiling dso_dataset.")
add_executable(dso_dataset ${PROJECT_SOURCE_DIR}/src/main_dso_pangolin.cpp )
target_link_libraries(dso_dataset dso boost_system cxsparse ${BOOST_THREAD_LIBRARY} ${LIBZIP_LIBRARY} ${Pangolin_LIBRARIES} ${OpenCV_LIBS})
target_link_libraries(dso_dataset dso ${LIBZIP_LIBRARY} ${Pangolin_LIBRARIES} ${OpenCV_LIBS} ${EIGEN3_LIBS})
else()
message("--- not building dso_dataset, since either don't have openCV or Pangolin.")
endif()
Expand Down
63 changes: 47 additions & 16 deletions src/FullSystem/CoarseInitializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,32 @@
#include "FullSystem/PixelSelector2.h"
#include "util/nanoflann.h"

//#include "Eigen/src/Cholesky/LDLT.H"

#include <Eigen/Cholesky>
#include <Eigen/Core>
#include <Eigen/Dense>
#include <Eigen/Eigen>
#include <Eigen/Eigenvalues>
#include <Eigen/Geometry>
#include <Eigen/Householder>
#include <Eigen/IterativeLinearSolvers>
#include <Eigen/Jacobi>
#include <Eigen/LU>
#include <Eigen/MetisSupport>
#include <Eigen/OrderingMethods>
#include <Eigen/QR>
#include <Eigen/QtAlignedMalloc>
#include <Eigen/Sparse>
#include <Eigen/SparseCholesky>
#include <Eigen/SparseCore>
#include <Eigen/SparseLU>
#include <Eigen/SparseQR>
#include <Eigen/StdDeque>
#include <Eigen/StdList>
#include <Eigen/StdVector>
#include <Eigen/SVD>


#if !defined(__SSE3__) && !defined(__SSE2__) && !defined(__SSE1__)
#include "SSE2NEON.h"
Expand All @@ -45,11 +71,11 @@
namespace dso
{

CoarseInitializer::CoarseInitializer(int ww, int hh) : thisToNext_aff(0,0), thisToNext(SE3())
CoarseInitializer::CoarseInitializer(int ww, int hh) : thisToNext_aff(0,0)
{
for(int lvl=0; lvl<pyrLevelsUsed; lvl++)
{
points[lvl] = 0;
points[lvl] = nullptr;
numPoints[lvl] = 0;
}

Expand All @@ -70,7 +96,7 @@ CoarseInitializer::~CoarseInitializer()
{
for(int lvl=0; lvl<pyrLevelsUsed; lvl++)
{
if(points[lvl] != 0) delete[] points[lvl];
delete[] points[lvl];
}

delete[] JbBuffer;
Expand Down Expand Up @@ -648,11 +674,13 @@ void CoarseInitializer::optReg(int lvl)

float idnn[10];
int nnn=0;
for(int j=0;j<10;j++)
for(int neighbour : point->neighbours)
{
if(point->neighbours[j] == -1) continue;
Pnt* other = ptsl+point->neighbours[j];
if(!other->isGood) continue;
if(neighbour == -1) { continue;
}
Pnt* other = ptsl+neighbour;
if(!other->isGood) { continue;
}
idnn[nnn] = other->iR;
nnn++;
}
Expand Down Expand Up @@ -787,7 +815,7 @@ void CoarseInitializer::setFirst( CalibHessian* HCalib, FrameHessian* newFrameHe



if(points[lvl] != 0) delete[] points[lvl];
delete[] points[lvl];
points[lvl] = new Pnt[npts];

// set idepth map to initially 1 everywhere.
Expand Down Expand Up @@ -863,11 +891,13 @@ void CoarseInitializer::resetPoints(int lvl)

if(lvl==pyrLevelsUsed-1 && !pts[i].isGood)
{
float snd=0, sn=0;
for(int n = 0;n<10;n++)
float snd=0;
float sn=0;
for(int neighbour : pts[i].neighbours)
{
if(pts[i].neighbours[n] == -1 || !pts[pts[i].neighbours[n]].isGood) continue;
snd += pts[pts[i].neighbours[n]].iR;
if(neighbour == -1 || !pts[neighbour].isGood) { continue;
}
snd += pts[neighbour].iR;
sn += 1;
}

Expand All @@ -879,7 +909,7 @@ void CoarseInitializer::resetPoints(int lvl)
}
}
}
void CoarseInitializer::doStep(int lvl, float lambda, Vec8f inc)
void CoarseInitializer::doStep(int lvl, float lambda, const Vec8f& inc)
{

const float maxPixelStep = 0.25;
Expand Down Expand Up @@ -924,7 +954,7 @@ void CoarseInitializer::applyStep(int lvl)
pts[i].idepth = pts[i].idepth_new;
pts[i].lastHessian = pts[i].lastHessian_new;
}
std::swap<Vec10f*>(JbBuffer, JbBuffer_new);
std::swap(JbBuffer, JbBuffer_new);
}

void CoarseInitializer::makeK(CalibHessian* HCalib)
Expand Down Expand Up @@ -1009,8 +1039,9 @@ void CoarseInitializer::makeNN()
assert(ret_index[k]>=0 && ret_index[k] < npts);
myidx++;
}
for(int k=0;k<nn;k++)
pts[i].neighboursDist[k] *= 10/sumDF;
for(float & k : pts[i].neighboursDist) {
k *= 10/sumDF;
}


if(lvl < pyrLevelsUsed-1 )
Expand Down
2 changes: 1 addition & 1 deletion src/FullSystem/CoarseInitializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class CoarseInitializer {
float rescale();

void resetPoints(int lvl);
void doStep(int lvl, float lambda, Vec8f inc);
void doStep(int lvl, float lambda, const Vec8f& inc);
void applyStep(int lvl);

void makeGradients(Eigen::Vector3f** data);
Expand Down
55 changes: 45 additions & 10 deletions src/FullSystem/CoarseTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,34 @@
#include "FullSystem/Residuals.h"
#include "OptimizationBackend/EnergyFunctionalStructs.h"
#include "IOWrapper/ImageRW.h"

//#include "Eigen/src/Cholesky/LDLT.H"

#include <Eigen/Cholesky>
#include <Eigen/Core>
#include <Eigen/Dense>
#include <Eigen/Eigen>
#include <Eigen/Eigenvalues>
#include <Eigen/Geometry>
#include <Eigen/Householder>
#include <Eigen/IterativeLinearSolvers>
#include <Eigen/Jacobi>
#include <Eigen/LU>
#include <Eigen/MetisSupport>
#include <Eigen/OrderingMethods>
#include <Eigen/QR>
#include <Eigen/QtAlignedMalloc>
#include <Eigen/Sparse>
#include <Eigen/SparseCholesky>
#include <Eigen/SparseCore>
#include <Eigen/SparseLU>
#include <Eigen/SparseQR>
#include <Eigen/StdDeque>
#include <Eigen/StdList>
#include <Eigen/StdVector>
#include <Eigen/SVD>


#include <algorithm>

#if !defined(__SSE3__) && !defined(__SSE2__) && !defined(__SSE1__)
Expand Down Expand Up @@ -86,8 +114,8 @@ CoarseTracker::CoarseTracker(int ww, int hh) : lastRef_aff_g2l(0,0)
buf_warped_refColor = allocAligned<4,float>(ww*hh, ptrToDelete);


newFrame = 0;
lastRef = 0;
newFrame = nullptr;
lastRef = nullptr;
debugPlot = debugPrint = true;
w[0]=h[0]=0;
refFrameID=-1;
Expand Down Expand Up @@ -132,7 +160,7 @@ void CoarseTracker::makeK(CalibHessian* HCalib)



void CoarseTracker::makeCoarseDepthL0(std::vector<FrameHessian*> frameHessians)
void CoarseTracker::makeCoarseDepthL0(const std::vector<FrameHessian*>& frameHessians)
{
// make coarse tracking templates for latstRef.
memset(idepth[0], 0, sizeof(float)*w[0]*h[0]);
Expand Down Expand Up @@ -293,7 +321,7 @@ void CoarseTracker::makeCoarseDepthL0(std::vector<FrameHessian*> frameHessians)



void CoarseTracker::calcGSSSE(int lvl, Mat88 &H_out, Vec8 &b_out, const SE3 &refToNew, AffLight aff_g2l)
void CoarseTracker::calcGSSSE(int lvl, Mat88 &H_out, Vec8 &b_out, const SE3 & /*refToNew*/, AffLight aff_g2l)
{
acc.initialize();

Expand Down Expand Up @@ -383,7 +411,7 @@ Vec6 CoarseTracker::calcRes(int lvl, const SE3 &refToNew, AffLight aff_g2l, floa
float maxEnergy = 2*setting_huberTH*cutoffTH-setting_huberTH*setting_huberTH; // energy for r=setting_coarseCutoffTH.


MinimalImageB3* resImage = 0;
MinimalImageB3* resImage = nullptr;
if(debugPlot)
{
resImage = new MinimalImageB3(wl,hl);
Expand Down Expand Up @@ -538,7 +566,7 @@ bool CoarseTracker::trackNewestCoarse(
SE3 &lastToNew_out, AffLight &aff_g2l_out,
int coarsestLvl,
Vec5 minResForAbort,
IOWrap::Output3DWrapper* wrap)
IOWrap::Output3DWrapper* /*wrap*/)
{
debugPlot = setting_render_displayCoarseTrackingFull;
debugPrint = false;
Expand Down Expand Up @@ -733,6 +761,13 @@ void CoarseTracker::debugPlotIDepthMap(float* minID_pt, float* maxID_pt, std::ve
if(idepth[lvl][i] > 0)
allID.push_back(idepth[lvl][i]);
}

if (allID.empty())
{
printf("\nallID is empty.\n");
return;
}

std::sort(allID.begin(), allID.end());
int n = allID.size()-1;

Expand All @@ -742,7 +777,7 @@ void CoarseTracker::debugPlotIDepthMap(float* minID_pt, float* maxID_pt, std::ve
float minID, maxID;
minID = minID_new;
maxID = maxID_new;
if(minID_pt!=0 && maxID_pt!=0)
if(minID_pt!=nullptr && maxID_pt!=nullptr)
{
if(*minID_pt < 0 || *maxID_pt < 0)
{
Expand Down Expand Up @@ -867,7 +902,7 @@ CoarseDistanceMap::~CoarseDistanceMap()


void CoarseDistanceMap::makeDistanceMap(
std::vector<FrameHessian*> frameHessians,
const std::vector<FrameHessian*>& frameHessians,
FrameHessian* frame)
{
int w1 = w[1];
Expand Down Expand Up @@ -907,7 +942,7 @@ void CoarseDistanceMap::makeDistanceMap(



void CoarseDistanceMap::makeInlierVotes(std::vector<FrameHessian*> frameHessians)
void CoarseDistanceMap::makeInlierVotes(const std::vector<FrameHessian*>& frameHessians)
{

}
Expand All @@ -921,7 +956,7 @@ void CoarseDistanceMap::growDistBFS(int bfsNum)
for(int k=1;k<40;k++)
{
int bfsNum2 = bfsNum;
std::swap<Eigen::Vector2i*>(bfsList1,bfsList2);
std::swap(bfsList1,bfsList2);
bfsNum=0;

if(k%2==0)
Expand Down
6 changes: 3 additions & 3 deletions src/FullSystem/CoarseTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class CoarseTracker {
private:


void makeCoarseDepthL0(std::vector<FrameHessian*> frameHessians);
void makeCoarseDepthL0(const std::vector<FrameHessian*>& frameHessians);
float* idepth[PYR_LEVELS];
float* weightSums[PYR_LEVELS];
float* weightSums_bak[PYR_LEVELS];
Expand Down Expand Up @@ -135,11 +135,11 @@ class CoarseDistanceMap {
~CoarseDistanceMap();

void makeDistanceMap(
std::vector<FrameHessian*> frameHessians,
const std::vector<FrameHessian*>& frameHessians,
FrameHessian* frame);

void makeInlierVotes(
std::vector<FrameHessian*> frameHessians);
const std::vector<FrameHessian*>& frameHessians);

void makeK( CalibHessian* HCalib);

Expand Down
Loading