From 18ee4fa71f16982ebb237175aae79f902438b933 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Wed, 21 Aug 2019 14:51:13 +0300
Subject: [PATCH] Ifdef all optflow code

---
 components/rgbd-sources/include/ftl/offilter.hpp        | 8 +++++++-
 components/rgbd-sources/src/algorithms/fixstars_sgm.cpp | 4 ++++
 components/rgbd-sources/src/algorithms/fixstars_sgm.hpp | 3 +++
 components/rgbd-sources/src/offilter.cpp                | 4 ++++
 4 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/components/rgbd-sources/include/ftl/offilter.hpp b/components/rgbd-sources/include/ftl/offilter.hpp
index 7775de411..4c4fbbb98 100644
--- a/components/rgbd-sources/include/ftl/offilter.hpp
+++ b/components/rgbd-sources/include/ftl/offilter.hpp
@@ -1,4 +1,8 @@
 #pragma once
+
+#include <ftl/config.h>
+
+#ifdef HAVE_OPTFLOW
 #include <opencv2/core.hpp>
 #include <opencv2/core/cuda.hpp>
 #include <opencv2/cudaoptflow.hpp>
@@ -28,4 +32,6 @@ private:
 };
 
 }
-}
\ No newline at end of file
+}
+
+#endif  // HAVE_OPTFLOW
diff --git a/components/rgbd-sources/src/algorithms/fixstars_sgm.cpp b/components/rgbd-sources/src/algorithms/fixstars_sgm.cpp
index 33bc92a17..347d66184 100644
--- a/components/rgbd-sources/src/algorithms/fixstars_sgm.cpp
+++ b/components/rgbd-sources/src/algorithms/fixstars_sgm.cpp
@@ -37,6 +37,7 @@ FixstarsSGM::FixstarsSGM(nlohmann::json &config) : Disparity(config) {
 		filter_ = cv::cuda::createDisparityBilateralFilter(max_disp_ << 4, radius, iter);
 	}
 	
+#ifdef HAVE_OPTFLOW
 	bool use_off_ = value("use_off", false);
 
 	if (use_off_)
@@ -45,6 +46,7 @@ FixstarsSGM::FixstarsSGM(nlohmann::json &config) : Disparity(config) {
 		double off_threshold = value("off_threshold", 0.9);
 		off_ = ftl::rgbd::OFDisparityFilter(size_, off_size, off_threshold);
 	}
+#endif
 
 	init(size_);
 }
@@ -105,11 +107,13 @@ void FixstarsSGM::compute(const cv::cuda::GpuMat &l, const cv::cuda::GpuMat &r,
 
 	dispt_full_res_.convertTo(disp, CV_32F, 1.0f / 16.0f, stream);
 
+#ifdef HAVE_OPTFLOW
 	if (use_off_) {
 		Mat disp_host(disp);
 		off_.filter(disp_host, Mat(lbw_));
 		disp.upload(disp_host);
 	}
+#endif
 }
 
 void FixstarsSGM::setMask(Mat &mask) {
diff --git a/components/rgbd-sources/src/algorithms/fixstars_sgm.hpp b/components/rgbd-sources/src/algorithms/fixstars_sgm.hpp
index 521241a70..8102444f4 100644
--- a/components/rgbd-sources/src/algorithms/fixstars_sgm.hpp
+++ b/components/rgbd-sources/src/algorithms/fixstars_sgm.hpp
@@ -53,7 +53,10 @@ namespace ftl {
 
 			cv::cuda::GpuMat l_downscaled_;
 			cv::cuda::GpuMat dispt_full_res_;
+
+			#ifdef HAVE_OPTFLOW
 			ftl::rgbd::OFDisparityFilter off_;
+			#endif
 		};
 	};
 };
diff --git a/components/rgbd-sources/src/offilter.cpp b/components/rgbd-sources/src/offilter.cpp
index b74ff3ce3..2ed77845d 100644
--- a/components/rgbd-sources/src/offilter.cpp
+++ b/components/rgbd-sources/src/offilter.cpp
@@ -1,3 +1,5 @@
+#ifdef HAVE_OPTFLOW
+
 #include <loguru.hpp>
 
 #include "ftl/offilter.hpp"
@@ -107,3 +109,5 @@ void OFDisparityFilter::filter(Mat &disp, const Mat &gray)
 		}
 	}
 }
+
+#endif  // HAVE_OPTFLOW
-- 
GitLab