From 18c1cc40ccfdfae7ee7a43d4443230a7cb559a03 Mon Sep 17 00:00:00 2001 From: David Mayerich Date: Tue, 14 Jul 2020 15:38:35 -0500 Subject: [PATCH] Updated SIproc for vcpkg --- CMakeLists.txt | 13 ++++++++----- FindFANN.cmake | 81 --------------------------------------------------------------------------------- FindGLEW.cmake | 124 ---------------------------------------------------------------------------------------------------------------------------- FindGLUT.cmake | 185 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- FindLAPACKE.cmake | 43 ------------------------------------------- README.md | 61 +++++++++++++++++++++++++++++++++++-------------------------- src/linalg.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ src/linalg.h | 25 +++++++++++++++++++++++++ src/proc/hsiproc.cpp | 147 +++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------ src/proc/mnf.cpp | 45 ++++++++++++++++++++++++++++++--------------- 10 files changed, 174 insertions(+), 599 deletions(-) delete mode 100644 FindFANN.cmake delete mode 100644 FindGLEW.cmake delete mode 100644 FindGLUT.cmake delete mode 100644 FindLAPACKE.cmake create mode 100644 src/linalg.cpp create mode 100644 src/linalg.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 5108268..80b7cdb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,14 +64,15 @@ if(WIN32) endif(WIN32) #find LAPACK and supporting link_libraries -find_package(LAPACKE REQUIRED) +find_package(clapack CONFIG REQUIRED) +find_package(OpenBLAS CONFIG REQUIRED) #if(MSVC) # message("Warning: VS2015 made a change to printf and scanf functions that requires linking to legacy_stdio_definitions.lib") #endif() #include include directories include_directories(${CUDA_INCLUDE_DIRS} - ${LAPACKE_INCLUDE_DIR} + ${CLAPACK_INCLUDE_DIR} ${STIM_INCLUDE_DIRS} ${OpenGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIR} @@ -96,9 +97,11 @@ add_executable(siproc target_link_libraries(siproc ${CUDA_LIBRARIES} ${CUDA_CUBLAS_LIBRARIES} ${CUDA_CUFFT_LIBRARIES} - ${LAPACKE_LIBRARIES} + ${CLAPACK_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${X11_LIBRARIES} + OpenBLAS::OpenBLAS + f2c lapack ) #create the VIEW executable---------------------------------------------- @@ -112,7 +115,7 @@ target_link_libraries(siview ${GLUT_LIBRARIES} ) if(WIN32) - target_link_libraries(siview ${GLEW_GLEW_LIBRARY}) + target_link_libraries(siview ${GLEW_LIBRARIES}) endif(WIN32) #create instrument-specific subroutine executables @@ -140,7 +143,7 @@ target_link_libraries(spero #if Boost is found, set an environment variable to use with preprocessor directives if(Boost_FILESYSTEM_FOUND) target_link_libraries(siproc ${Boost_FILESYSTEM_LIBRARIES} - ${Boost_SYSTEM_LIBRARY} + ${Boost_SYSTEM_LIBRARY} ) target_link_libraries(siview ${Boost_FILESYSTEM_LIBRARIES} diff --git a/FindFANN.cmake b/FindFANN.cmake deleted file mode 100644 index 681b6cb..0000000 --- a/FindFANN.cmake +++ /dev/null @@ -1,81 +0,0 @@ -# -# Windows users: define the GLEW_PATH environment variable to point -# to the directory containing: -# include/fann.h -# lib/*fann.lib - - -# FANN_FOUND - system has fann -# FANN_INCLUDE_DIRS - the fann include directory -# FANN_LIBRARIES - Link these to use fann -# FANN_DEFINITIONS - Compiler switches required for using fann -# - -if(FANN_LIBRARIES AND FANN_INCLUDE_DIRS) - set(FANN_FOUND TRUE) -else() - find_path(FANN_INCLUDE_DIR - NAMES - fann.h - PATHS - $ENV{FANN_PATH}/include - ${FANN_DIR}/include - /usr/include - /usr/local/include - /opt/local/include - /sw/include - ) - - set( _libraries doublefann floatfann ) - - foreach( _lib ${_libraries} ) - string( TOUPPER ${_lib} _name ) - - find_library(${_name}_LIBRARY - NAMES - ${_lib} - PATHS - $ENV{FANN_PATH}/lib - ${FANN_DIR}/lib - /usr/lib - /usr/local/lib - /opt/local/lib - /sw/lib - ) - endforeach() - - - set(FANN_INCLUDE_DIRS - ${FANN_INCLUDE_DIR} - ) - - set(FANN_LIBRARIES - ${FANN_LIBRARIES} - ${FANN_LIBRARY} - ${DOUBLEFANN_LIBRARY} - ${FIXEDFANN_LIBRARY} - ${FLOATFANN_LIBRARY} - ) - - if( UNIX ) - set( FANN_LIBRARIES ${FANN_LIBRARIES} m ) - endif() - - if(FANN_INCLUDE_DIRS AND FANN_LIBRARIES) - set(FANN_FOUND TRUE) - endif() - - if(FANN_FOUND) - if(NOT FANN_FIND_QUIETLY) - message(STATUS "Found FANN") - #message(STATUS "FANN_INCLUDE_DIRS: ${FANN_INCLUDE_DIRS}") - #message(STATUS "FANN_LIBRARIES: ${FANN_LIBRARIES}") - endif() - else() - if(FANN_FIND_REQUIRED) - message(FATAL_ERROR "Could not find FANN") - endif() - endif() - - mark_as_advanced(FANN_INCLUDE_DIRS FANN_LIBRARIES) -endif() diff --git a/FindGLEW.cmake b/FindGLEW.cmake deleted file mode 100644 index cb9f710..0000000 --- a/FindGLEW.cmake +++ /dev/null @@ -1,124 +0,0 @@ -# Copyright (c) 2012-2016 DreamWorks Animation LLC -# -# All rights reserved. This software is distributed under the -# Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ ) -# -# Redistributions of source code must retain the above copyright -# and license notice and the following restrictions and disclaimer. -# -# * Neither the name of DreamWorks Animation nor the names of -# its contributors may be used to endorse or promote products derived -# from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE -# LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00. -# - -#-*-cmake-*- -# - Find GLEW -# -# Author : Nicholas Yue yue.nicholas@gmail.com -# -# This auxiliary CMake file helps in find the GLEW headers and libraries -# -# GLEW_FOUND set if Glew is found. -# GLEW_INCLUDE_DIR GLEW's include directory -# GLEW_GLEW_LIBRARY GLEW libraries -# GLEW_glewmx_LIBRARY GLEWmx libraries (Mulitple Rendering Context) - -FIND_PACKAGE ( PackageHandleStandardArgs ) - -FIND_PATH( GLEW_LOCATION include/GL/glew.h - "$ENV{GLEW_ROOT}" - NO_DEFAULT_PATH - NO_SYSTEM_ENVIRONMENT_PATH - ) - -FIND_PACKAGE_HANDLE_STANDARD_ARGS ( GLEW - REQUIRED_VARS GLEW_LOCATION - ) - -IF ( GLEW_LOCATION ) - SET( GLEW_INCLUDE_DIR "${GLEW_LOCATION}/include" CACHE STRING "GLEW include path") - - SET ( ORIGINAL_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) - IF (GLEW_USE_STATIC_LIBS) - IF (APPLE) - SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a") - FIND_LIBRARY ( GLEW_LIBRARY_PATH GLEW PATHS ${GLEW_LOCATION}/lib - NO_DEFAULT_PATH - NO_SYSTEM_ENVIRONMENT_PATH - ) - FIND_LIBRARY ( GLEWmx_LIBRARY_PATH GLEWmx PATHS ${GLEW_LOCATION}/lib - NO_DEFAULT_PATH - NO_SYSTEM_ENVIRONMENT_PATH - ) - # MESSAGE ( "APPLE STATIC" ) - # MESSAGE ( "GLEW_LIBRARY_PATH = " ${GLEW_LIBRARY_PATH} ) - ELSEIF (WIN32) - message("Windows Found!") - # Link library - SET(CMAKE_FIND_LIBRARY_SUFFIXES ".lib") - if( CMAKE_SIZEOF_VOID_P EQUAL 8 ) - FIND_LIBRARY ( GLEW_LIBRARY_PATH GLEW32S PATHS $ENV{GLEW_ROOT}/lib/x64 NO_DEFAULT_PATH) - message("64-bit library") - else( CMAKE_SIZEOF_VOID_P EQUAL 8 ) - FIND_LIBRARY ( GLEW_LIBRARY_PATH GLEW32S PATHS $ENV{GLEW_ROOT}/lib NO_DEFAULT_PATH) - message("32-bit library") - endif( CMAKE_SIZEOF_VOID_P EQUAL 8 ) - ELSE (APPLE) - SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a") - FIND_LIBRARY ( GLEW_LIBRARY_PATH GLEW PATHS ${GLEW_LOCATION}/lib - NO_DEFAULT_PATH - NO_SYSTEM_ENVIRONMENT_PATH - ) - FIND_LIBRARY ( GLEWmx_LIBRARY_PATH GLEWmx PATHS ${GLEW_LOCATION}/lib - NO_DEFAULT_PATH - NO_SYSTEM_ENVIRONMENT_PATH - ) - # MESSAGE ( "LINUX STATIC" ) - # MESSAGE ( "GLEW_LIBRARY_PATH = " ${GLEW_LIBRARY_PATH} ) - ENDIF (APPLE) - ELSE () - IF (APPLE) - SET(CMAKE_FIND_LIBRARY_SUFFIXES ".dylib") - FIND_LIBRARY ( GLEW_LIBRARY_PATH GLEW PATHS ${GLEW_LOCATION}/lib ) - FIND_LIBRARY ( GLEWmx_LIBRARY_PATH GLEWmx PATHS ${GLEW_LOCATION}/lib ) - ELSEIF (WIN32) - # Link library - SET(CMAKE_FIND_LIBRARY_SUFFIXES ".lib") - if( CMAKE_SIZEOF_VOID_P EQUAL 8 ) - FIND_LIBRARY ( GLEW_LIBRARY_PATH GLEW32S PATHS $ENV{GLEW_ROOT}/lib/x64 NO_DEFAULT_PATH) - else( CMAKE_SIZEOF_VOID_P EQUAL 8 ) - FIND_LIBRARY ( GLEW_LIBRARY_PATH GLEW32S PATHS $ENV{GLEW_ROOT}/lib NO_DEFAULT_PATH) - endif( CMAKE_SIZEOF_VOID_P EQUAL 8 ) - ELSE (APPLE) - # Unices - FIND_LIBRARY ( GLEW_LIBRARY_PATH GLEW PATHS ${GLEW_LOCATION}/lib - NO_DEFAULT_PATH - NO_SYSTEM_ENVIRONMENT_PATH - ) - FIND_LIBRARY ( GLEWmx_LIBRARY_PATH GLEWmx PATHS ${GLEW_LOCATION}/lib - NO_DEFAULT_PATH - NO_SYSTEM_ENVIRONMENT_PATH - ) - ENDIF (APPLE) - ENDIF () - # MUST reset - SET(CMAKE_FIND_LIBRARY_SUFFIXES ${ORIGINAL_CMAKE_FIND_LIBRARY_SUFFIXES}) - - SET( GLEW_GLEW_LIBRARY ${GLEW_LIBRARY_PATH} CACHE STRING "GLEW library") - SET( GLEW_GLEWmx_LIBRARY ${GLEWmx_LIBRARY_PATH} CACHE STRING "GLEWmx library") - -ENDIF () diff --git a/FindGLUT.cmake b/FindGLUT.cmake deleted file mode 100644 index 1a59a5d..0000000 --- a/FindGLUT.cmake +++ /dev/null @@ -1,185 +0,0 @@ -#.rst: -# FindGLUT -# -------- -# -# try to find glut library and include files. -# -# IMPORTED Targets -# ^^^^^^^^^^^^^^^^ -# -# This module defines the :prop_tgt:`IMPORTED` targets: -# -# ``GLUT::GLUT`` -# Defined if the system has GLUT. -# -# Result Variables -# ^^^^^^^^^^^^^^^^ -# -# This module sets the following variables: -# -# :: -# -# GLUT_INCLUDE_DIR, where to find GL/glut.h, etc. -# GLUT_LIBRARIES, the libraries to link against -# GLUT_FOUND, If false, do not try to use GLUT. -# -# Also defined, but not for general use are: -# -# :: -# -# GLUT_glut_LIBRARY = the full path to the glut library. -# GLUT_Xmu_LIBRARY = the full path to the Xmu library. -# GLUT_Xi_LIBRARY = the full path to the Xi Library. - -#============================================================================= -# Copyright 2001-2009 Kitware, Inc. -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - -if (WIN32) - find_path( GLUT_INCLUDE_DIR NAMES GL/glut.h - PATHS $ENV{GLUT_ROOT}/include) - - if( CMAKE_SIZEOF_VOID_P EQUAL 8 ) - find_library( GLUT_glut_LIBRARY NAMES freeglut - PATHS - $ENV{GLUT_ROOT}/lib/x64 - - NO_DEFAULT_PATH - ) - else( CMAKE_SIZEOF_VOID_P EQUAL 8 ) - find_library( GLUT_glut_LIBRARY NAMES glut glut32 freeglut - PATHS - $ENV{GLUT_ROOT}/lib - ) - endif( CMAKE_SIZEOF_VOID_P EQUAL 8 ) - -else () - - if (APPLE) - find_path(GLUT_INCLUDE_DIR glut.h ${OPENGL_LIBRARY_DIR}) - find_library(GLUT_glut_LIBRARY GLUT DOC "GLUT library for OSX") - find_library(GLUT_cocoa_LIBRARY Cocoa DOC "Cocoa framework for OSX") - - if(GLUT_cocoa_LIBRARY AND NOT TARGET GLUT::Cocoa) - add_library(GLUT::Cocoa UNKNOWN IMPORTED) - # Cocoa should always be a Framework, but we check to make sure. - if(GLUT_cocoa_LIBRARY MATCHES "/([^/]+)\\.framework$") - set_target_properties(GLUT::Cocoa PROPERTIES - IMPORTED_LOCATION "${GLUT_cocoa_LIBRARY}/${CMAKE_MATCH_1}") - else() - set_target_properties(GLUT::Cocoa PROPERTIES - IMPORTED_LOCATION "${GLUT_cocoa_LIBRARY}") - endif() - endif() - else () - - if (BEOS) - - set(_GLUT_INC_DIR /boot/develop/headers/os/opengl) - set(_GLUT_glut_LIB_DIR /boot/develop/lib/x86) - - else() - - find_library( GLUT_Xi_LIBRARY Xi - /usr/openwin/lib - ) - - find_library( GLUT_Xmu_LIBRARY Xmu - /usr/openwin/lib - ) - - if(GLUT_Xi_LIBRARY AND NOT TARGET GLUT::Xi) - add_library(GLUT::Xi UNKNOWN IMPORTED) - set_target_properties(GLUT::Xi PROPERTIES - IMPORTED_LOCATION "${GLUT_Xi_LIBRARY}") - endif() - - if(GLUT_Xmu_LIBRARY AND NOT TARGET GLUT::Xmu) - add_library(GLUT::Xmu UNKNOWN IMPORTED) - set_target_properties(GLUT::Xmu PROPERTIES - IMPORTED_LOCATION "${GLUT_Xmu_LIBRARY}") - endif() - - endif () - - find_path( GLUT_INCLUDE_DIR GL/glut.h - /usr/include/GL - /usr/openwin/share/include - /usr/openwin/include - /opt/graphics/OpenGL/include - /opt/graphics/OpenGL/contrib/libglut - ${_GLUT_INC_DIR} - ) - - find_library( GLUT_glut_LIBRARY glut - /usr/openwin/lib - ${_GLUT_glut_LIB_DIR} - ) - - unset(_GLUT_INC_DIR) - unset(_GLUT_glut_LIB_DIR) - - endif () - -endif () - -FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLUT REQUIRED_VARS GLUT_glut_LIBRARY GLUT_INCLUDE_DIR) - -if (GLUT_FOUND) - # Is -lXi and -lXmu required on all platforms that have it? - # If not, we need some way to figure out what platform we are on. - set( GLUT_LIBRARIES - ${GLUT_glut_LIBRARY} - ${GLUT_Xmu_LIBRARY} - ${GLUT_Xi_LIBRARY} - ${GLUT_cocoa_LIBRARY} - ) - - if(NOT TARGET GLUT::GLUT) - add_library(GLUT::GLUT UNKNOWN IMPORTED) - set_target_properties(GLUT::GLUT PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${GLUT_INCLUDE_DIR}") - if(GLUT_glut_LIBRARY MATCHES "/([^/]+)\\.framework$") - set_target_properties(GLUT::GLUT PROPERTIES - IMPORTED_LOCATION "${GLUT_glut_LIBRARY}/${CMAKE_MATCH_1}") - else() - set_target_properties(GLUT::GLUT PROPERTIES - IMPORTED_LOCATION "${GLUT_glut_LIBRARY}") - endif() - - if(TARGET GLUT::Xmu) - set_property(TARGET GLUT::GLUT APPEND - PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Xmu) - endif() - - if(TARGET GLUT::Xi) - set_property(TARGET GLUT::GLUT APPEND - PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Xi) - endif() - - if(TARGET GLUT::Cocoa) - set_property(TARGET GLUT::GLUT APPEND - PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Cocoa) - endif() - endif() - - #The following deprecated settings are for backwards compatibility with CMake1.4 - set (GLUT_LIBRARY ${GLUT_LIBRARIES}) - set (GLUT_INCLUDE_PATH ${GLUT_INCLUDE_DIR}) -endif() - -mark_as_advanced( - GLUT_INCLUDE_DIR - GLUT_glut_LIBRARY - GLUT_Xmu_LIBRARY - GLUT_Xi_LIBRARY - ) diff --git a/FindLAPACKE.cmake b/FindLAPACKE.cmake deleted file mode 100644 index 96dacf2..0000000 --- a/FindLAPACKE.cmake +++ /dev/null @@ -1,43 +0,0 @@ -# - Try to find LAPACKE -# -# Once done this will define -# LAPACKE_FOUND - System has LAPACKE -# LAPACKE_INCLUDE_DIRS - The LAPACKE include directories -# LAPACKE_LIBRARIES - The libraries needed to use LAPACKE -# LAPACKE_DEFINITIONS - Compiler switches required for using LAPACKE -# -# Usually, LAPACKE requires LAPACK and the BLAS. This module does -# not enforce anything about that. - -find_path(LAPACKE_INCLUDE_DIR - NAMES lapacke.h - PATHS $ENV{LAPACK_ROOT} $ENV{LAPACK_PATH} ${INCLUDE_INSTALL_DIR} - PATHS ENV INCLUDE) - -find_library(LAPACKE_LIBRARY liblapacke lapacke - PATHS $ENV{LAPACK_ROOT} $ENV{LAPACK_PATH} ${LIB_INSTALL_DIR} - PATHS ENV LIBRARY_PATH - PATHS ENV LD_LIBRARY_PATH) - -if(MSVC) - find_library(LAPACK_LIBRARY liblapack lapack - PATHS $ENV{LAPACK_ROOT} $ENV{LAPACK_PATH} ${LIB_INSTALL_DIR} - PATHS ENV LIBRARY_PATH - PATHS ENV LD_LIBRARY_PATH) - - find_library(BLAS_LIBRARY libblas blas - PATHS $ENV{LAPACK_ROOT} $ENV{LAPACK_PATH} ${LIB_INSTALL_DIR} - PATHS ENV LIBRARY_PATH - PATHS ENV LD_LIBRARY_PATH) - -else() - find_library(LAPACK REQUIRED) - find_library(BLAS REQUIRED) -endif() -set(LAPACKE_LIBRARIES ${LAPACKE_LIBRARY} ${LAPACK_LIBRARY} ${BLAS_LIBRARY}) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(LAPACKE DEFAULT_MSG - LAPACKE_INCLUDE_DIR - LAPACKE_LIBRARIES) -mark_as_advanced(LAPACKE_INCLUDE_DIR LAPACKE_LIBRARIES) diff --git a/README.md b/README.md index 1dccbe9..8d393cf 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,35 @@ -HSIproc can be built using CMake (https://cmake.org/) and a C/C++ compiler. - -The STIM codebase is required, but will be cloned automatically if Git (https://git-scm.com/) is installed. The codebase can be downloaded manually here: -https://git.stim.ee.uh.edu/codebase/stimlib - -Required libraries: -OpenCV: http://opencv.org/ - - - ------------------------------------------------------------------------ -Step-by-step instructions: - -1) Download and install CMake - -2) Download and install OpenCV - -3) Download and install Git - -4) Set the CMake source directory to the directory containing this file - -5) Specify the CMake build directory where you want the executable built - -6) Use CMake to Configure and Generate the build environment - -7) Build the software (ex. in Visual Studio you will open the generated solution and compile) +SIproc is written using C++ and compatible with both CMake (https://cmake.org/) and the vcpkg (https://docs.microsoft.com/en-us/cpp/build/vcpkg) package manager. + +STIM (https://git.stim.ee.uh.edu/codebase/stimlib) is also required. + +Step-by-step instructions (Windows): +============= +1) Download and install CMake (https://cmake.org/) +2) Download and install Git (https://git-scm.com/) +3) Download and install vcpkg (https://github.com/microsoft/vcpkg): + + git clone https://github.com/Microsoft/vcpkg.git + cd vcpkg +4) Install the required packages: + + vcpkg install boost:x64-windows + vcpkg install glew:x64-windows + vcpkg install freeglut:x64-windows + vcpkg install clapack:x64-windows +5) Clone SIproc: + + git clone https://git.stim.ee.uh.edu/release/siproc.git +6) Run CMake, and select the cloned siproc directory and your choice of build location +7) Configure the build environment: +a) Click __Configure__ +b) Select your preferred build environment (ex. Visual Studio) +c) Set the platform to __x64__ +d) Select the option to __Specify toolchain file for cross-compiling__ +e) Click __ Next__ +f) When asked, provide the vcpkg toolchain file in: + + [vcpkg directory]\scripts\buildsystems\vcpkg.cmake +g) Assuming no errors were encountered, click __Generate__ +8) Click __Open Project__ to open your build environment +9) Build the project (ex. Visual Studio's __Build Project__) + diff --git a/src/linalg.cpp b/src/linalg.cpp new file mode 100644 index 0000000..200c445 --- /dev/null +++ b/src/linalg.cpp @@ -0,0 +1,49 @@ + +// This file contains a set of wrapper functions that are linked to the corresponding functions in CLAPACK + +extern "C" { +#include "f2c.h" +#include "clapack.h" +} + +void LINALG_dgeev( + char JOBVL, + char JOBVR, + int n, + double* A, + int LDA, + double* WR, + double* WI, + double* VL, + int LDVL, + double* VR, + int LDVR) +{ + integer LWORK = -1; + double WORK[1]; + integer INFO; + dgeev_(&JOBVL, &JOBVR, (integer*)&n, A, (integer*)&LDA, WR, WI, VL, (integer*)&LDVL, VR, (integer*)&LDVR, WORK, &LWORK, &INFO); +} + +void LINALG_dgetrf( + int M, + int N, + double* A, + int LDA, + int* IPIV) +{ + integer INFO; + dgetrf_((integer*)&M, (integer*)&N, A, (integer*)&LDA, (integer*)IPIV, &INFO); +} + +void LINALG_dgetri( + int N, + double* A, + int LDA, + int* IPIV) +{ + integer LWORK = -1; + double WORK[1]; + integer INFO; + dgetri_((integer*)&N, A, (integer*)&LDA, (integer*)IPIV, WORK, &LWORK, &INFO); +} \ No newline at end of file diff --git a/src/linalg.h b/src/linalg.h new file mode 100644 index 0000000..77909f2 --- /dev/null +++ b/src/linalg.h @@ -0,0 +1,25 @@ +void LINALG_dgeev( + char JOBVL, + char JOBVR, + int n, + double* A, + int LDA, + double* WR, + double* WI, + double* VL, + int LDVL, + double* VR, + int LDVR); + +void LINALG_dgetrf( + int M, + int N, + double* A, + int LDA, + int* IPIV); + +void LINALG_dgetri( + int N, + double* A, + int LDA, + int* IPIV); \ No newline at end of file diff --git a/src/proc/hsiproc.cpp b/src/proc/hsiproc.cpp index a35a425..42caffe 100644 --- a/src/proc/hsiproc.cpp +++ b/src/proc/hsiproc.cpp @@ -1,3 +1,9 @@ +//#include "lapacke.h" +//#include "cblas.h" + +//#include +#include "linalg.h" + #include #include #include @@ -13,18 +19,16 @@ #include #include #include -#include #include //LAPACKE support for Visual Studio -#include -#ifndef LAPACK_COMPLEX_CUSTOM -#define LAPACK_COMPLEX_CUSTOM -#define lapack_complex_float std::complex -#define lapack_complex_double std::complex -#endif -#include "lapacke.h" -//#include "cblas.h" +//#include +//#ifndef LAPACK_COMPLEX_CUSTOM +//#define LAPACK_COMPLEX_CUSTOM +//#define lapack_complex_float std::complex +//#define lapack_complex_double std::complex +//#endif + void baseline(std::string infile, std::string outfile, std::string headerfile, std::vector points, unsigned char* mask); void normalize(std::string infile, std::string outfile, std::string headerfile, double band, unsigned char* mask); @@ -512,12 +516,6 @@ int main(int argc, char** argv){ //output the average spectrum std::ofstream csv(outfile.c_str()); //open a CSV file to write the mean - /*if (ENVI.header.wavelength.size() > 0) //output the first wavelength - csv << ENVI.header.wavelength[0]<<','; - csv << spectrum[0]; //output the first variable - for (unsigned long long b = 1; b < B; b++) //for each band - csv << "," << spectrum[b]; //output the next variable - */ for (unsigned long long b = 0; b < B; b++) { //for each band if (ENVI.header.wavelength.size() == B) //output the wavelength, if available csv << ENVI.header.wavelength[b] << ','; @@ -552,22 +550,6 @@ int main(int argc, char** argv){ csv << m[b] << "," << std[b] << std::endl; } - - - - - //output the average spectrum - /*std::ofstream csv(outfile.c_str()); //open a CSV file to write the mean - csv< JtJi = JtJ; //allocate space for the matrix inverse int* piv = (int*) malloc(JtJi.rows() * sizeof(int)); //allocate space to store the LU decomposition pivot indices - LAPACKE_dgetrf(LAPACK_COL_MAJOR, (int)JtJi.rows(), (int)JtJi.cols(), JtJi.data(), (int)JtJi.rows(), piv); //use LAPACK for LU decomposition - LAPACKE_dgetri(LAPACK_COL_MAJOR, (int)JtJi.rows(), JtJi.data(), (int)JtJi.rows(), piv); //use LAPACK to solve the inverse + //LAPACKE_dgetrf(LAPACK_COL_MAJOR, (int)JtJi.rows(), (int)JtJi.cols(), JtJi.data(), (int)JtJi.rows(), piv); //use LAPACK for LU decomposition + //LAPACKE_dgetri(LAPACK_COL_MAJOR, (int)JtJi.rows(), JtJi.data(), (int)JtJi.rows(), piv); //use LAPACK to solve the inverse + // REPLACED THE ABOVE LAPACKE functions with new CLAPACK functions in linalg.cpp + LINALG_dgetrf((int)JtJi.rows(), (int)JtJi.cols(), JtJi.data(), (int)JtJi.rows(), piv); //use LAPACK for LU decomposition + LINALG_dgetri((int)JtJi.rows(), JtJi.data(), (int)JtJi.rows(), piv); //use LAPACK to solve the inverse + stim::matrix C = JtJi * Jt; //calculate C @@ -781,7 +767,12 @@ int main(int argc, char** argv){ double* lambda_real = (double*) malloc(B * sizeof(double)); double* lambda_imag = (double*) malloc(B * sizeof(double)); double* evec = (double*) malloc(B * B * sizeof(double)); - LAPACKE_dgeev(LAPACK_COL_MAJOR, 'N', 'V', (int)B, co, (int)B, lambda_real, lambda_imag, NULL, (int)B, evec, (int)B); + //LAPACKE_dgeev(LAPACK_COL_MAJOR, 'N', 'V', (int)B, co, (int)B, lambda_real, lambda_imag, NULL, (int)B, evec, (int)B); + + // REPLACED THE ABOVE LAPACKE functions with new CLAPACK functions in linalg.cpp + LINALG_dgeev('N', 'V', (int)B, co, (int)B, lambda_real, lambda_imag, NULL, (int)B, evec, (int)B); + + std::ofstream csv(outfile.c_str(), std::ios::out); //create a text file to store the PCA stats (mean and covariance matrix) csv<((int)j, 0); - for (unsigned long long i = 1; i < B; i++) - csv<<","<((int)j, (int)i); - csv << std::endl; - }*/ for(size_t j = 0; j < B; j++){ csv< bkg; - if(args["background"].is_set()){ //if a background is specified - stim::filename bkg_file(args["background"].as_string(0)); //create a filename for the background file - if(bkg_file.extension() != "seq"){ - std::cout<<"ERROR - Agilent SEQ file expected for the background."< drd_list = f.get_list(); //generate a list of DRD files - if(drd_list.size() == 0){ - std::cerr<<"ERROR: no interferogram (*.drd) files found."< interferogram(drd_list[i].str()); //load the interferogram - interferogram.meancenter(); //mean center the interferogram - interferogram.zeropad(); //pad to the nearest power-of-two - stim::agilent_binary fft = interferogram.fft(wn_min, wn_max, elwn, udr); //calculate the FFT and crop out the desired wavenumber range - if(i == 0){ //if this is the first file - stim::envi_header header = fft.create_header(); //create a header - header.save(drd_list[0].extension("hdr")); //save the header - } - - if(ratio) fft.absorbance(&bkg_fft); //if we are calculating a ratio to a background, calculate the absorbance - fft.save(drd_list[i].extension("dmd")); //save the output file as a DMD - //std::cout< #include #include "stim/envi/envi_header.h" @@ -5,20 +7,18 @@ #include #include #include -//#include #include #include #include "stim/envi/bil.h" -//#include //LAPACKE support for Visual Studio -#include -#ifndef LAPACK_COMPLEX_CUSTOM -#define LAPACK_COMPLEX_CUSTOM -#define lapack_complex_float std::complex -#define lapack_complex_double std::complex -#endif -#include "lapacke.h" +//#include +//#ifndef LAPACK_COMPLEX_CUSTOM +//#define LAPACK_COMPLEX_CUSTOM +//#define lapack_complex_float std::complex +//#define lapack_complex_double std::complex +//#endif +//#include "lapacke.h" @@ -101,8 +101,14 @@ void mnf(std::string outfile, int keptComponents, std::string NoiseFractions, in std::cout << std::endl << "Calculating the inverse covariance matrix S^(-1)..."; int *IPIV = (int*)malloc(sizeof(int) * B); - LAPACKE_dgetrf(LAPACK_COL_MAJOR, (int)B, (int)B, cov.data(), (int)B, IPIV); //perform LU factorization - LAPACKE_dgetri(LAPACK_COL_MAJOR, (int)B, cov.data(), (int)B, IPIV); //calculate matrix inverse + + //LAPACKE_dgetrf(LAPACK_COL_MAJOR, (int)B, (int)B, cov.data(), (int)B, IPIV); //perform LU factorization + //LAPACKE_dgetri(LAPACK_COL_MAJOR, (int)B, cov.data(), (int)B, IPIV); //calculate matrix inverse + + // REPLACED THE ABOVE LAPACKE functions with new CLAPACK functions in linalg.cpp + LINALG_dgetrf((int)B, (int)B, cov.data(), (int)B, IPIV); //perform LU factorization + LINALG_dgetri((int)B, cov.data(), (int)B, IPIV); //calculate matrix inverse + free(IPIV); std::cout << "done." << std::endl; @@ -118,7 +124,11 @@ void mnf(std::string outfile, int keptComponents, std::string NoiseFractions, in std::cout << std::endl << "Calculating left eigenvectors X * A = v * X..."; stim::matrix ev_left(B, B); - LAPACKE_dgeev(LAPACK_COL_MAJOR, 'V', 'N', (int)B, Q.data(), (int)B, EigenvaluesReal, EigenvaluesIm, ev_left.data(), (int)B, 0, (int)B); //perform eigenvalue decomposition + //LAPACKE_dgeev(LAPACK_COL_MAJOR, 'V', 'N', (int)B, Q.data(), (int)B, EigenvaluesReal, EigenvaluesIm, ev_left.data(), (int)B, 0, (int)B); //perform eigenvalue decomposition + + // REPLACED THE ABOVE LAPACKE functions with new CLAPACK functions in linalg.cpp + LINALG_dgeev('V', 'N', (int)B, Q.data(), (int)B, EigenvaluesReal, EigenvaluesIm, ev_left.data(), (int)B, 0, (int)B); //perform eigenvalue decomposition + std::cout << "done." << std::endl; std::cout << std::endl << "Sorting eigenvectors..."; @@ -157,8 +167,13 @@ void mnf(std::string outfile, int keptComponents, std::string NoiseFractions, in //calculate inverse of As matrix int *IPIV2 = (int*)malloc(sizeof(int) * B); - LAPACKE_dgetrf(LAPACK_COL_MAJOR, (int)B, (int)B, As.data(), (int)B, IPIV2); - LAPACKE_dgetri(LAPACK_COL_MAJOR, (int)B, As.data(), (int)B, IPIV2); + //LAPACKE_dgetrf(LAPACK_COL_MAJOR, (int)B, (int)B, As.data(), (int)B, IPIV2); + //LAPACKE_dgetri(LAPACK_COL_MAJOR, (int)B, As.data(), (int)B, IPIV2); + + // REPLACED THE ABOVE LAPACKE functions with new CLAPACK functions in linalg.cpp + LINALG_dgetrf((int)B, (int)B, As.data(), (int)B, IPIV2); + LINALG_dgetri((int)B, As.data(), (int)B, IPIV2); + free(IPIV2); //calculate transpose of As inversed matrix (transpose of transformation matrix inveresed ) . @@ -186,4 +201,4 @@ void mnf(std::string outfile, int keptComponents, std::string NoiseFractions, in csv << "\n" << EigenSortedIndices[b] << ", " << EigenvaluesReal[EigenSortedIndices[b]]; //output the next variable csv.close(); } -} //end MNF +} //end MNF \ No newline at end of file -- libgit2 0.21.4