Просмотр исходного кода

Merge branch 'master' of dbv.inf-cv.uni-jena.de:nice/nice-core

Johannes Ruehle 11 лет назад
Родитель
Сommit
6822e2d529

+ 14 - 0
CMakeLists.txt

@@ -71,12 +71,26 @@ if(WITH_DBV_LIBRARIES)
         #message(STATUS "ipp link dir: ${IPP_LIBRARY_DIRS}")
         #message(STATUS "ipp link libs: ${IPP_LIBRARIES}")
         ADD_DEFINITIONS( "-DNICE_USELIB_IPP=5" )
+	ADD_DEFINITIONS( "-lpthread" )
         INCLUDE_DIRECTORIES(${IPP_INCLUDE_DIRS})
         
       else()
         message(STATUS "IPP library not found")
       endif()
     endif()
+
+    NICE_OPTION(WITH_LINAL "Build with dbv LinAl support" OFF)
+    if(WITH_LINAL)
+      FIND_PACKAGE(LinAl)
+      if(LINAL_FOUND)
+	ADD_DEFINITIONS( "-DNICE_USELIB_LINAL" )
+	#ADD_DEFINITIONS("-lgfortran")
+        INCLUDE_DIRECTORIES(${LINAL_INCLUDE_DIR})
+	#message(STATUS "linal link libs: ${LINAL_LIBRARIES}")
+        message(STATUS "Using LinAl include dir: ${LINAL_INCLUDE_DIR}")
+      endif()
+    endif()
+
   else()
     message( SEND_ERROR "trying to use DBV extern library dir, but couldn't be found ${NICE_DBV_LIBRARIES_DIR}. Switch off DBV Usage to continue.") #unsetting dbv libraries path
     unset(WITH_DBV_LIBRARIES) #unsetting, since dbv dir not found

+ 45 - 0
cmake/FindLinAl.cmake

@@ -0,0 +1,45 @@
+# Find the DBV library LinAl headers and library.
+#
+#  LINAL_INCLUDE_DIR - where to find Linal/linal.h, etc.
+#  LINAL_LIBRARIES      - List of libraries.
+#  LINAL_FOUND        - True if LinAl found.
+
+
+
+# Look for the library.
+#execute_process(COMMAND /home/dbv/3rdparty64-gcc43/LinAl/bin/linal-config --libs
+#                OUTPUT_VARIABLE LINAL_LIBRARIES)
+
+set(LINAL_LIBRARIES "/home/dbv/3rdparty64-gcc43/LinAl/lib/libLinAl.so;/home/dbv/3rdparty64-gcc43/LinAl/lib/libarpack++.a;/home/dbv/3rdparty64-gcc43/LinAl/lib/libsuperlu.a;/home/dbv/3rdparty64-gcc43/LinAl/lib/libarpack.a;/home/dbv/3rdparty64-gcc43/LinAl/lib/liblapack.a;/home/dbv/3rdparty64-gcc43/LinAl/lib/libblas.so")
+IF(UNIX) #find gfortran
+  # If the faster 'gold' linker is used, to avoid complaints about undefined symbol
+  # '_gfortran_concat_string', '_gfortran_pow_i4_i4', ... , let's link against gfortran libraries.
+  # These errors happen while linking against VTK static built with R support
+  SET(CMAKE_FIND_LIBRARY_SUFFIXES_SAVED ${CMAKE_FIND_LIBRARY_SUFFIXES}) # Backup
+  LIST(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".so.3")
+  FIND_LIBRARY(GFortran_LIBRARY gfortran)
+  SET(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_SAVED}) # Restore
+  LIST(APPEND LINAL_LIBRARIES ${GFortran_LIBRARY})
+#  message(STATUS "GFortran_LIBRARY: ${GFortran_LIBRARY}")
+ENDIF()
+MARK_AS_ADVANCED(LINAL_LIBRARIES)
+
+# Look for the header file.
+#execute_process(COMMAND /home/dbv/3rdparty64-gcc43/LinAl/bin/linal-config --cxxflags
+#                OUTPUT_VARIABLE LINAL_INCLUDE_DIR)
+set(LINAL_INCLUDE_DIR "/home/dbv/3rdparty64-gcc43/LinAl/include/")
+MARK_AS_ADVANCED(LINAL_INCLUDE_DIR)
+
+
+# handle the QUIETLY and REQUIRED arguments and set LINAL_FOUND to TRUE if 
+# all listed variables are TRUE
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(LINAL DEFAULT_MSG LINAL_LIBRARIES LINAL_INCLUDE_DIR)
+
+#IF(MATIO_FOUND)
+#  SET(MATIO_LIBRARIES ${MATIO_LIBRARY} ${HDF5_LIBRARIES})
+#  SET(MATIO_INCLUDE_DIRS ${MATIO_INCLUDE_DIR} ${HDF5_INCLUDE_DIR})
+#ELSE(MATIO_FOUND)
+  #SET(MATIO_LIBRARIES)
+  #SET(MATIO_INCLUDE_DIRS)
+#ENDIF(MATIO_FOUND)

+ 1 - 1
core/CMakeLists.txt

@@ -5,7 +5,7 @@
 set(the_library "core")
 
 #add linkage dependencies to other libraries here
-set("nice_${the_library}_LINKING_DEPENDENCIES"  ${Boost_LIBRARIES} ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES} ${QT_LIBRARIES} ${IPP_LIBRARIES} ${ImageMagick_LIBRARIES})
+set("nice_${the_library}_LINKING_DEPENDENCIES"  ${Boost_LIBRARIES} ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES} ${QT_LIBRARIES} ${IPP_LIBRARIES} ${LINAL_LIBRARIES} ${ImageMagick_LIBRARIES})
 if(MATIO_FOUND)
   list(APPEND nice_${the_library}_LINKING_DEPENDENCIES ${MATIO_LIBRARIES})
 endif(MATIO_FOUND)

+ 1 - 1
core/tutorial/progs/05_matio.cpp

@@ -89,7 +89,7 @@ int main(int argc, char** argv) {
 
 #ifdef NICE_USELIB_LINAL
 	// Calculate singular value decomposition
-	NICE::SVD matrix_svd(matrix);
+	NICE::SVD<double> matrix_svd(matrix);
 
 	std::cout << "Vt:\n";
 	printMatrix(matrix_svd.getVt());

+ 73 - 0
core/vector/tests/TestSVD.cpp

@@ -0,0 +1,73 @@
+/*
+ * NICE-Core - efficient algebra and computer vision methods
+ *  - libbasicvector - An core/vector/template for new NICE libraries
+ * See file License for license information.
+ */
+
+#ifdef NICE_USELIB_CPPUNIT
+#include "TestSVD.h"
+#include "core/basics/cppunitex.h"
+#include "core/vector/MatrixT.h"
+#include "core/vector/SVD.h"
+
+#include <string>
+#include <exception>
+
+using namespace std;
+
+CPPUNIT_TEST_SUITE_REGISTRATION( TestSVD );
+
+void TestSVD::setUp() {
+}
+
+void TestSVD::tearDown() {
+}
+
+
+#define sr(tr, tm, t0, t1, t2, t3) tm(tr,0)=t0; tm(tr,1)=t1; tm(tr,2)=t2; tm(tr,3)=t3;
+
+#define ASSERT_MATRIX_EQUAL(m1, m2) for(int i=0; i<m1.rows(); i++) { \
+	for(int j=0; j<m1.cols(); j++) { \
+		CPPUNIT_ASSERT_DOUBLES_EQUAL(m1(i,j),m2(i,j),0.0002); \
+	} \
+}
+
+void TestSVD::testSVD() {
+	NICE::MatrixT<double> matrix(4,4);
+
+	sr(0, matrix, 1, 2, 3, 4);
+	sr(1, matrix, 4, 5, 6, 7);
+	sr(2, matrix, 2, 3, 4, 5);
+	sr(3, matrix, 2, 9, 8, 1);
+
+	NICE::MatrixT<double> exu(4,4,0);
+	sr(0, exu, -0.2852, -0.2948, -0.7390, -0.5345);
+	sr(1, exu, -0.6079, -0.4409,  0.6038, -0.2673);
+	sr(2, exu, -0.3927, -0.3435, -0.2914,  0.8018);
+	sr(3, exu, -0.6284,  0.7750, -0.0667, -0.0000);
+
+	NICE::MatrixT<double> exs(4,4,0);
+	exs(0,0) = 17.8539;
+	exs(1,1) = 6.3372;
+	exs(2,2) = 1.0374;
+	
+	NICE::MatrixT<double> exv(4,4,0);
+	sr(0, exv, -0.2666, -0.1866,  0.9256, -0.1913);
+	sr(1, exv, -0.5849,  0.4971,  0.0646,  0.6376);
+	sr(2, exv, -0.6218,  0.2046, -0.2823, -0.7013);
+	sr(3, exv, -0.4474, -0.8218, -0.2436,  0.2550);
+
+	NICE::MatrixT<double> fail(4,4,999.999);
+
+#ifdef NICE_USELIB_LINAL
+	NICE::SVD<double> test_svd(matrix);
+	ASSERT_MATRIX_EQUAL(exu, test_svd.getU());
+	ASSERT_MATRIX_EQUAL(exs, test_svd.getS());
+	ASSERT_MATRIX_EQUAL(exv, test_svd.getV());
+#else
+	ASSERT_MATRIX_EQUAL(exu, fail);
+#endif
+
+}
+
+#endif

+ 28 - 0
core/vector/tests/TestSVD.h

@@ -0,0 +1,28 @@
+/*
+ * NICE-Core - efficient algebra and computer vision methods
+ *  - libbasicvector - An core/vector/template for new NICE libraries
+ * See file License for license information.
+ */
+#ifndef _TESTSVD_H
+#define _TESTSVD_H
+
+#include <cppunit/extensions/HelperMacros.h>
+/**
+ * CppUnit-Testcase. 
+ * Test template...
+ */
+class TestSVD : public CppUnit::TestFixture {
+  CPPUNIT_TEST_SUITE( TestSVD );
+  CPPUNIT_TEST( testSVD );
+  CPPUNIT_TEST_SUITE_END();
+  
+ private:
+ 
+ public:
+  void setUp();
+  void tearDown();
+
+  void testSVD();
+};
+
+#endif // _TESTSVD_H