From 0404f167f1cb044f867a9bee59177d550e7fd1ca Mon Sep 17 00:00:00 2001 From: TheFrenchLeaf Date: Thu, 13 Oct 2011 17:49:05 +0200 Subject: [PATCH 1/5] Change convolution to be a template function (it's more generic). It avoids code duplicates. Add CMakeLists build rules to compile daisy as a library. --- CMakeLists.txt | 40 ++++++++++++++++++++++++++++++++++ include/kutility/convolution.h | 23 +++---------------- 2 files changed, 43 insertions(+), 20 deletions(-) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..f433322 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,40 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +#README +# Compile only daisy as a library. +# do not compile the binary because third party libraries are required +# such as png zlib and jpeg + +project(daisy) + +IF (UNIX OR APPLE) + check_symbol_exists(mmap64 "sys/mman.h" HAVE_MMAP64) +ENDIF () + +if(${HAVE_MMAP64}) + message("System has large file support.") + add_definitions(-DHAVE_LARGE_FILE_SUPPORT) +else() + message("System hasn't large file support.") +endif() + +include_directories(include) + +# Make the headers appear in IDEs. +file(GLOB daisy_hdrs include/kutility/*.h include/daisy/*.h) + +set(daisy_srcs + src/daisy.cpp + src/corecv.cpp + src/image_io_bmp.cpp + src/image_io_pnm.cpp + src/image_io_png.cpp + src/image_io_jpeg.cpp + src/image_manipulation.cpp + src/progress_bar.cpp + src/general.cpp + src/interaction.cpp +) + +add_library(daisy ${daisy_srcs} ${daisy_hdrs}) + diff --git a/include/kutility/convolution.h b/include/kutility/convolution.h index 11ce7c2..db45c94 100644 --- a/include/kutility/convolution.h +++ b/include/kutility/convolution.h @@ -9,28 +9,11 @@ namespace kutility { - inline void convolve_sym( float* image, int h, int w, float* kernel, int ksize, float* out=NULL ) + template + inline void convolve_sym( T* image, int h, int w, T* kernel, int ksize, T* out=NULL ) { if( out == NULL ) out = image; - else memcpy( out, image, sizeof(float)*h*w ); - - if( h == 240 && w == 320 ) { convolve_sym_(out, 240, 320, kernel, ksize); return; } - if( h == 480 && w == 640 ) { convolve_sym_(out, 480, 640, kernel, ksize); return; } - if( h == 512 && w == 512 ) { convolve_sym_(out, 512, 512, kernel, ksize); return; } - if( h == 512 && w == 768 ) { convolve_sym_(out, 512, 768, kernel, ksize); return; } - if( h == 600 && w == 800 ) { convolve_sym_(out, 600, 800, kernel, ksize); return; } - if( h == 768 && w == 1024 ) { convolve_sym_(out, 768, 1024, kernel, ksize); return; } - if( h == 1024 && w == 768 ) { convolve_sym_(out, 1024, 768, kernel, ksize); return; } - if( h == 256 && w == 256 ) { convolve_sym_(out, 256, 256, kernel, ksize); return; } - if( h == 128 && w == 128 ) { convolve_sym_(out, 128, 128, kernel, ksize); return; } - if( h == 128 && w == 192 ) { convolve_sym_(out, 128, 192, kernel, ksize); return; } - cout<<"[convolve_sym] insert this h,w to unrolling list: "< Date: Fri, 13 Apr 2012 15:19:02 +0200 Subject: [PATCH 2/5] Fix warnings. --- include/kutility/general.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/kutility/general.h b/include/kutility/general.h index 5c86ac2..a37fe91 100644 --- a/include/kutility/general.h +++ b/include/kutility/general.h @@ -571,9 +571,9 @@ namespace kutility inline bool is_number( std::string str ) { - int len=str.length(); + size_t len=str.length(); - for( int i=0; i Date: Fri, 13 Apr 2012 15:19:14 +0200 Subject: [PATCH 3/5] Fix compilation on windows. --- src/main.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 81b5a0e..5eca4a2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -252,7 +252,7 @@ int main( int argc, char **argv ) double yy, xx; int ori; string outname = filename; - int rand_samples[N*2]; + std::vector rand_samples(N*2, 0); for( int i=0; iget_descriptor(opy,opx,opo,thor); save( fname, thor, desc->grid_point_number(), histq ); break; From 1ce0682f75003ebf883f4d94416951a53b521eb3 Mon Sep 17 00:00:00 2001 From: TheFrenchLeaf Date: Fri, 13 Apr 2012 15:19:56 +0200 Subject: [PATCH 4/5] Add openmp support. Add compilation of the main.cpp file. Support only grayscale ppm files natively. --- CMakeLists.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f433322..173776e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,15 @@ else() message("System hasn't large file support.") endif() +#Detect OpenMP +FIND_PACKAGE(OpenMP) +if (OPENMP_FOUND) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") + option(USE_OPENMP "Use OpenMP for parallelization" ON) +else(OPENMP_FOUND) + option(USE_OPENMP "Use OpenMP for parallelization" OFF) +endif (OPENMP_FOUND) + include_directories(include) # Make the headers appear in IDEs. @@ -38,3 +47,6 @@ set(daisy_srcs add_library(daisy ${daisy_srcs} ${daisy_hdrs}) +ADD_EXECUTABLE(main_daisy src/main.cpp) +TARGET_LINK_LIBRARIES(main_daisy daisy) + From 640fbf7af3ea70be62a5b7061985f34c75fcd3df Mon Sep 17 00:00:00 2001 From: TheFrenchLeaf Date: Fri, 25 May 2012 16:40:17 +0200 Subject: [PATCH 5/5] Fix the definition of a preprocessor in the OpenMP compilation. --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 173776e..49dc76a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,7 @@ FIND_PACKAGE(OpenMP) if (OPENMP_FOUND) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") option(USE_OPENMP "Use OpenMP for parallelization" ON) + add_definitions(-DUSE_OPENMP) else(OPENMP_FOUND) option(USE_OPENMP "Use OpenMP for parallelization" OFF) endif (OPENMP_FOUND)