From 034329f35432e7a9cb02a355ab2361f7cd730a80 Mon Sep 17 00:00:00 2001
From: faber <faber@j102wsdozent>
Date: Sat, 15 Feb 2020 16:27:17 +0100
Subject: [PATCH] Updates for OpenCL2, OpenCV3/4

Introduced cl2.hpp; corrected OpenCV libraries (for OpenCV3); corrected
waitkey() for int->char->-1 peculiarities
---
 parallel_worlds_0/src/main.cpp            |  9 +++++----
 parallel_worlds_1/.cproject               |  8 +++++++-
 parallel_worlds_1/src/CMakeLists.txt      |  2 +-
 parallel_worlds_1/src/OpenCLInterface.hpp | 13 ++++++++-----
 parallel_worlds_1/src/main.cpp            |  2 +-
 parallel_worlds_2/.cproject               |  8 +++++++-
 parallel_worlds_2/src/CMakeLists.txt      |  2 +-
 parallel_worlds_2/src/OpenCLInterface.hpp | 13 ++++++++-----
 parallel_worlds_2/src/main.cpp            |  2 +-
 parallel_worlds_3/.cproject               | 10 +++++++++-
 parallel_worlds_3/src/CMakeLists.txt      |  2 +-
 parallel_worlds_3/src/DeviceInterface.hpp |  2 +-
 parallel_worlds_3/src/OpenCLInterface.hpp | 13 ++++++++-----
 parallel_worlds_3/src/main.cpp            |  2 +-
 14 files changed, 59 insertions(+), 29 deletions(-)

diff --git a/parallel_worlds_0/src/main.cpp b/parallel_worlds_0/src/main.cpp
index 1fac059..3b35c77 100644
--- a/parallel_worlds_0/src/main.cpp
+++ b/parallel_worlds_0/src/main.cpp
@@ -3,7 +3,6 @@
 // Author      :
 // Version     :
 // Copyright   : Your copyright notice
-// Description : Hello World in C++, Ansi-style
 //============================================================================
 
 
@@ -11,7 +10,7 @@
 #include <sstream>
 #include <stdlib.h>
 
-#include "cl.hpp"
+#include "cl2.hpp"
 
 /*
  * VECTOR_CLASS and STRING_CLASS are defined by OpenCL so that
@@ -20,10 +19,12 @@
  * all these definitions available
  */
 #ifndef STRING_CLASS
-#define STRING_CLASS cl::STRING_CLASS
+#define STRING_CLASS ::std::string
+//cl::STRING_CLASS
 #endif
 #ifndef VECTOR_CLASS
-#define VECTOR_CLASS cl::VECTOR_CLASS
+#define VECTOR_CLASS ::std::vector
+//cl::VECTOR_CLASS
 #endif
 
 /*
diff --git a/parallel_worlds_1/.cproject b/parallel_worlds_1/.cproject
index 57e7159..37386bc 100644
--- a/parallel_worlds_1/.cproject
+++ b/parallel_worlds_1/.cproject
@@ -73,10 +73,16 @@
                             							
                             <tool id="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug.207526064" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug">
                                 								
-                                <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.cpp.link.option.libs.982738935" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" valueType="libs">
+                                <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.cpp.link.option.libs.982738935" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" useByScannerDiscovery="false" valueType="libs">
                                     									
                                     <listOptionValue builtIn="false" value="opencv_highgui"/>
                                     									
+                                    <listOptionValue builtIn="false" value="opencv_videoio"/>
+                                    									
+                                    <listOptionValue builtIn="false" value="opencv_imgcodecs"/>
+                                    									
+                                    <listOptionValue builtIn="false" value="opencv_imgproc"/>
+                                    									
                                     <listOptionValue builtIn="false" value="opencv_core"/>
                                     									
                                     <listOptionValue builtIn="false" value="OpenCL"/>
diff --git a/parallel_worlds_1/src/CMakeLists.txt b/parallel_worlds_1/src/CMakeLists.txt
index 1e2bd59..4725493 100644
--- a/parallel_worlds_1/src/CMakeLists.txt
+++ b/parallel_worlds_1/src/CMakeLists.txt
@@ -1,7 +1,7 @@
 cmake_minimum_required( VERSION 3.1 )
 project( parallel_worlds_1 )
 
-set( EXECUTABLE parallel_worlds_1 )
+set( EXECUTABLE ${PROJECT_NAME} )
 
 if( MSVC )
 	message( "MSVC: adding compiler flags" )
diff --git a/parallel_worlds_1/src/OpenCLInterface.hpp b/parallel_worlds_1/src/OpenCLInterface.hpp
index 3361878..dd51e53 100644
--- a/parallel_worlds_1/src/OpenCLInterface.hpp
+++ b/parallel_worlds_1/src/OpenCLInterface.hpp
@@ -6,19 +6,22 @@
 #include <stdlib.h>
 #include <stdio.h>
 
-#include "cl.hpp"
+#include <string>
+#include <vector>
+
+#include "cl2.hpp"
 
 /*
- * VECTOR_CLASS and STRING_CLASS are defined by OpenCL so that
- * the user may use her own implementation of these classes, if she
+ * VECTOR_CLASS and STRING_CLASS are defined by OpenCL 1.x BUT NOT 2.x(!)
+ * so that the user may use her own implementation of these classes, if she
  * wants to avoid the STL; the defines below are only safeguards to have
  * all these definitions available
  */
 #ifndef STRING_CLASS
-#define STRING_CLASS cl::STRING_CLASS
+#define STRING_CLASS ::std::string
 #endif
 #ifndef VECTOR_CLASS
-#define VECTOR_CLASS cl::VECTOR_CLASS
+#define VECTOR_CLASS ::std::vector
 #endif
 
 /*
diff --git a/parallel_worlds_1/src/main.cpp b/parallel_worlds_1/src/main.cpp
index 8b6e88c..f83915d 100644
--- a/parallel_worlds_1/src/main.cpp
+++ b/parallel_worlds_1/src/main.cpp
@@ -27,7 +27,7 @@ int main(int argc, const char** argv) {
 	cv::namedWindow("preview", 0);
 	cv::namedWindow("converted", 0);
 
-	while (cv::waitKey(10) < 0) {
+	while (((char)cv::waitKey(10)) <= -1) {
 		if (cameraOn && !capture.read(frame))
 			exit(3);
 
diff --git a/parallel_worlds_2/.cproject b/parallel_worlds_2/.cproject
index 57e7159..37386bc 100644
--- a/parallel_worlds_2/.cproject
+++ b/parallel_worlds_2/.cproject
@@ -73,10 +73,16 @@
                             							
                             <tool id="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug.207526064" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug">
                                 								
-                                <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.cpp.link.option.libs.982738935" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" valueType="libs">
+                                <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.cpp.link.option.libs.982738935" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" useByScannerDiscovery="false" valueType="libs">
                                     									
                                     <listOptionValue builtIn="false" value="opencv_highgui"/>
                                     									
+                                    <listOptionValue builtIn="false" value="opencv_videoio"/>
+                                    									
+                                    <listOptionValue builtIn="false" value="opencv_imgcodecs"/>
+                                    									
+                                    <listOptionValue builtIn="false" value="opencv_imgproc"/>
+                                    									
                                     <listOptionValue builtIn="false" value="opencv_core"/>
                                     									
                                     <listOptionValue builtIn="false" value="OpenCL"/>
diff --git a/parallel_worlds_2/src/CMakeLists.txt b/parallel_worlds_2/src/CMakeLists.txt
index 74c59bb..67aabe5 100644
--- a/parallel_worlds_2/src/CMakeLists.txt
+++ b/parallel_worlds_2/src/CMakeLists.txt
@@ -1,7 +1,7 @@
 cmake_minimum_required( VERSION 3.1 )
 project( parallel_worlds_2 )
 
-set( EXECUTABLE parallelwelten_2 )
+set( EXECUTABLE ${PROJECT_NAME} )
 
 if( MSVC )
 	message( "MSVC: adding compiler flags" )
diff --git a/parallel_worlds_2/src/OpenCLInterface.hpp b/parallel_worlds_2/src/OpenCLInterface.hpp
index 3361878..dd51e53 100644
--- a/parallel_worlds_2/src/OpenCLInterface.hpp
+++ b/parallel_worlds_2/src/OpenCLInterface.hpp
@@ -6,19 +6,22 @@
 #include <stdlib.h>
 #include <stdio.h>
 
-#include "cl.hpp"
+#include <string>
+#include <vector>
+
+#include "cl2.hpp"
 
 /*
- * VECTOR_CLASS and STRING_CLASS are defined by OpenCL so that
- * the user may use her own implementation of these classes, if she
+ * VECTOR_CLASS and STRING_CLASS are defined by OpenCL 1.x BUT NOT 2.x(!)
+ * so that the user may use her own implementation of these classes, if she
  * wants to avoid the STL; the defines below are only safeguards to have
  * all these definitions available
  */
 #ifndef STRING_CLASS
-#define STRING_CLASS cl::STRING_CLASS
+#define STRING_CLASS ::std::string
 #endif
 #ifndef VECTOR_CLASS
-#define VECTOR_CLASS cl::VECTOR_CLASS
+#define VECTOR_CLASS ::std::vector
 #endif
 
 /*
diff --git a/parallel_worlds_2/src/main.cpp b/parallel_worlds_2/src/main.cpp
index 1791853..97e2b6f 100644
--- a/parallel_worlds_2/src/main.cpp
+++ b/parallel_worlds_2/src/main.cpp
@@ -27,7 +27,7 @@ int main(int argc, const char** argv) {
 	cv::namedWindow("preview", 0);
 	cv::namedWindow("converted", 0);
 
-	while (cv::waitKey(10) < 0) {
+	while (((char)cv::waitKey(10)) <= -1) {
 		if (cameraOn && !capture.read(frame))
 			exit(3);
 
diff --git a/parallel_worlds_3/.cproject b/parallel_worlds_3/.cproject
index 57e7159..2a99925 100644
--- a/parallel_worlds_3/.cproject
+++ b/parallel_worlds_3/.cproject
@@ -73,10 +73,16 @@
                             							
                             <tool id="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug.207526064" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug">
                                 								
-                                <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.cpp.link.option.libs.982738935" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" valueType="libs">
+                                <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.cpp.link.option.libs.982738935" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" useByScannerDiscovery="false" valueType="libs">
                                     									
                                     <listOptionValue builtIn="false" value="opencv_highgui"/>
                                     									
+                                    <listOptionValue builtIn="false" value="opencv_videoio"/>
+                                    									
+                                    <listOptionValue builtIn="false" value="opencv_imgcodecs"/>
+                                    									
+                                    <listOptionValue builtIn="false" value="opencv_imgproc"/>
+                                    									
                                     <listOptionValue builtIn="false" value="opencv_core"/>
                                     									
                                     <listOptionValue builtIn="false" value="OpenCL"/>
@@ -248,5 +254,7 @@
     <storageModule moduleId="refreshScope"/>
     	
     <storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
+    	
+    <storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
     
 </cproject>
diff --git a/parallel_worlds_3/src/CMakeLists.txt b/parallel_worlds_3/src/CMakeLists.txt
index ee66933..8c23766 100644
--- a/parallel_worlds_3/src/CMakeLists.txt
+++ b/parallel_worlds_3/src/CMakeLists.txt
@@ -1,7 +1,7 @@
 cmake_minimum_required( VERSION 3.1 )
 project( parallel_worlds_3 )
 
-set( EXECUTABLE parallelwelten_3 )
+set( EXECUTABLE ${PROJECT_NAME} )
 
 if( MSVC )
 	message( "MSVC: adding compiler flags" )
diff --git a/parallel_worlds_3/src/DeviceInterface.hpp b/parallel_worlds_3/src/DeviceInterface.hpp
index 9116842..d3090cc 100644
--- a/parallel_worlds_3/src/DeviceInterface.hpp
+++ b/parallel_worlds_3/src/DeviceInterface.hpp
@@ -44,7 +44,7 @@ private:
 		for (VECTOR_CLASS<cl::Platform>::iterator pit = platforms.begin();
 				platforms.end() != pit; ++pit) {
 			// try to find a device of type devType
-			CHECK_ERROR(pit->getDevices(devType, &deviceVector));
+			pit->getDevices(devType, &deviceVector);
 			/* the C-way:
 			 * cl_int clGetDeviceIDs (cl_platform_id platform,
 			 * cl_device_type device_type,
diff --git a/parallel_worlds_3/src/OpenCLInterface.hpp b/parallel_worlds_3/src/OpenCLInterface.hpp
index 3361878..dd51e53 100644
--- a/parallel_worlds_3/src/OpenCLInterface.hpp
+++ b/parallel_worlds_3/src/OpenCLInterface.hpp
@@ -6,19 +6,22 @@
 #include <stdlib.h>
 #include <stdio.h>
 
-#include "cl.hpp"
+#include <string>
+#include <vector>
+
+#include "cl2.hpp"
 
 /*
- * VECTOR_CLASS and STRING_CLASS are defined by OpenCL so that
- * the user may use her own implementation of these classes, if she
+ * VECTOR_CLASS and STRING_CLASS are defined by OpenCL 1.x BUT NOT 2.x(!)
+ * so that the user may use her own implementation of these classes, if she
  * wants to avoid the STL; the defines below are only safeguards to have
  * all these definitions available
  */
 #ifndef STRING_CLASS
-#define STRING_CLASS cl::STRING_CLASS
+#define STRING_CLASS ::std::string
 #endif
 #ifndef VECTOR_CLASS
-#define VECTOR_CLASS cl::VECTOR_CLASS
+#define VECTOR_CLASS ::std::vector
 #endif
 
 /*
diff --git a/parallel_worlds_3/src/main.cpp b/parallel_worlds_3/src/main.cpp
index 6fc237e..a72d6b4 100644
--- a/parallel_worlds_3/src/main.cpp
+++ b/parallel_worlds_3/src/main.cpp
@@ -36,7 +36,7 @@ int main(int argc, const char** argv) {
 	cv::namedWindow("edge", 0);
 	cv::namedWindow("effect", 0);
 
-	while (cv::waitKey(10) < 0) {
+	while (((char)cv::waitKey(10)) <= -1) {
 		if (cameraOn && !capture.read(frame))
 			exit(3);
 		greyFilter(frame.data, convertedFrame.data, w, h);
-- 
GitLab