CMakeLists.txt 15.9 KB
Newer Older
1
cmake_minimum_required (VERSION 3.2)
2
project (alta CXX)
3

4 5 6 7
#############################
#      Preconfiguration     #
#############################

8 9 10
# Set Python version number
set(Python_ADDITIONAL_VERSIONS 2.7)

11 12 13 14 15 16 17 18 19
# Require C++11 options
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)


#############################
#        Dependencies       #
#############################

20
# Find required packages
21
find_package(Eigen3)
22
find_package(OpenMP)
23 24
find_package(PythonLibs)
find_package(Boost COMPONENTS python)
25 26 27

add_definitions(-DALTA_PLUGIN_DIRECTORY="/usr/lib/alta_plugins")

28
# Add core and library include files
29
include_directories("external/build" "sources" ${EIGEN3_INCLUDE_DIR})
30
include_directories("external" "external/Catch/include" "external/quadprog++")
31

32
# Look for header only dependencies
33 34 35
find_file(EIGEN_FOUND "Eigen/Core"      HINTS ${EIGEN3_INCLUDE_DIR})
find_file(CATCH_FOUND "catch.hpp"       HINTS external/Catch/include)
find_file(FLANN_FOUND "flann/flann.hpp")
36 37 38 39 40

# Check if Eigen is found
if(NOT EIGEN_FOUND)
    message(FATAL_ERROR "Unable to find Eigen header")
endif()
41

42 43 44 45 46 47 48
# Update compilation option to include OpenMP if present
if(OPENMP_FOUND)
    set (CMAKE_CXX_FLAGS ${OpenMP_CXX_FLAGS})
endif(OPENMP_FOUND)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

49

50 51 52 53 54 55
#############################
#      Helper functions     #
#############################

function(alta_add_plugin name sources)
	add_library(${name} SHARED sources/plugins/${sources})
56
        target_link_libraries(${name} core)
57 58 59 60
endfunction(alta_add_plugin)

function(alta_add_soft name sources)
	add_executable(${name} sources/softs/${sources})
61
        target_link_libraries(${name} core)
62 63
endfunction(alta_add_soft)

64
function(alta_test_unit name sources)
65 66
        add_executable(${name} sources/tests/${sources})
        target_link_libraries(${name} core)
67 68
        add_test(NAME ${name} COMMAND ${CMAKE_BINARY_DIR}/tests/${name} WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
        set_tests_properties(${name} PROPERTIES ENVIRONMENT "TEST_DATA_DIRECTORY=${CMAKE_SOURCE_DIR}/sources/tests;ALTA_PLUGIN_PATH=${CMAKE_BINARY_DIR}/plugins")
69 70 71 72 73
endfunction(alta_test_unit)

function(alta_test_soft name)
        add_test(NAME ${name} COMMAND ${CMAKE_BINARY_DIR}/softs/${name} --help)
endfunction(alta_test_soft)
74

75
function(alta_download_merl name)
76
    find_file(${name}_FOUND "${name}.binary" PATHS "${CMAKE_BINARY_DIR}/tests/")
77 78
    if(NOT ${name}_FOUND)
        message("Dowloading ${name} from MERL database:")
Laurent Belcour's avatar
Laurent Belcour committed
79 80 81 82
	file(DOWNLOAD
	     "http://people.csail.mit.edu/wojciech/BRDFDatabase/brdfs/${name}.binary"
	     "${CMAKE_BINARY_DIR}/tests/${name}.binary" SHOW_PROGRESS)
	set(${name}_FOUND TRUE PARENT_SCOPE)
83
    endif()
84 85
endfunction(alta_download_merl)

86 87 88 89 90 91

#############################
#         ALTA core         #
#############################

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
92

93 94 95 96
add_library(core STATIC
            sources/core/args.h
            sources/core/common.h
            sources/core/common.cpp
97 98 99 100 101 102
            sources/core/metrics.h
            sources/core/metrics.cpp
            sources/core/params.h
            sources/core/params.cpp
            sources/core/data.h
            sources/core/data.cpp
103
            sources/core/data_storage.h
104 105 106 107 108 109 110 111 112
            sources/core/data_storage.cpp
            sources/core/vertical_segment.h
            sources/core/vertical_segment.cpp
            sources/core/function.h
            sources/core/function.cpp
            sources/core/rational_function.h
            sources/core/rational_function.cpp
            sources/core/plugins_manager.h
            sources/core/plugins_manager.cpp)
113

114 115 116 117 118

add_library(quadprog STATIC
            external/quadprog++/QuadProg++.hh
            external/quadprog++/QuadProg++.cc)

119 120
target_link_libraries(core ${CMAKE_DL_LIBS})

121 122 123 124 125

#############################
#         Plugins           #
#############################

126
#    set(CMAKE_SHARED_LIBRARY_PREFIX "")
127 128 129
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/plugins)

# Data
130 131 132 133
alta_add_plugin(data_astm       data_io/astm.cpp)
alta_add_plugin(data_merl       data_io/merl.cpp)
alta_add_plugin(data_utia       data_io/utia.cpp)
alta_add_plugin(data_brdf_slice data_io/slice.cpp)
134

135
alta_add_plugin(data_grid       data_interpolants/grid.cpp)
136 137 138 139
if(FLANN_FOUND)
    alta_add_plugin(data_rbf    data_interpolants/rbf.cpp)
endif()
#alta_add_plugin(data_matlab data_interpolants/matlab.cpp)
140 141

# Functions
142 143 144
alta_add_plugin(rational_function_legendre		rational_function_legendre/rational_function.cpp)
alta_add_plugin(rational_function_chebychev		rational_function_chebychev/rational_function.cpp)
alta_add_plugin(rational_function_cosine 		rational_function_cosine/rational_function.cpp)
145 146 147 148 149 150 151 152 153
alta_add_plugin(nonlinear_function_abc                  nonlinear_function_abc/function.cpp)
alta_add_plugin(nonlinear_function_beckmann             nonlinear_function_beckmann/function.cpp)
alta_add_plugin(nonlinear_function_blinn                nonlinear_function_blinn/function.cpp)
alta_add_plugin(nonlinear_function_diffuse              nonlinear_function_diffuse/function.cpp)
alta_add_plugin(nonlinear_function_lafortune            nonlinear_function_lafortune/function.cpp)
alta_add_plugin(nonlinear_function_sgd                  nonlinear_function_sgd/function.cpp)
alta_add_plugin(nonlinear_function_spherical_gaussian   nonlinear_function_spherical_gaussian/function.cpp)
alta_add_plugin(nonlinear_function_ward                 nonlinear_function_ward/function.cpp)

154 155 156 157
alta_add_plugin(nonlinear_function_retrobeckmann        nonlinear_function_retrobeckmann/function.cpp)
alta_add_plugin(nonlinear_function_retroblinn		nonlinear_function_retroblinn/function.cpp)
alta_add_plugin(nonlinear_function_retroyoo             nonlinear_function_retroyoo/function.cpp)
alta_add_plugin(nonlinear_fresnel_retroschlick		nonlinear_fresnel_retroschlick/function.cpp)
158 159

alta_add_plugin(nonlinear_fresnel_schlick               nonlinear_fresnel_schlick/function.cpp)
160
alta_add_plugin(nonlinear_fresnel_normalized_schlick    nonlinear_fresnel_normalized_schlick/function.cpp)
161 162 163 164

alta_add_plugin(nonlinear_shadowing_schlick             nonlinear_shadowing_schlick/function.cpp)
alta_add_plugin(nonlinear_shadowing_smith               nonlinear_shadowing_smith/function.cpp)
alta_add_plugin(nonlinear_shadowing_walter_smith        nonlinear_shadowing_walter_smith/function.cpp)
165

166
# Fitters
167 168 169 170
alta_add_plugin(rational_fitter_eigen 			rational_fitter_eigen/rational_fitter.cpp)
alta_add_plugin(rational_fitter_leastsquare		rational_fitter_leastsquare/rational_fitter.cpp)
alta_add_plugin(rational_fitter_quadprog		rational_fitter_quadprog/rational_fitter.cpp)
alta_add_plugin(rational_fitter_parallel		rational_fitter_parallel/rational_fitter.cpp)
171
alta_add_plugin(nonlinear_fitter_eigen                  nonlinear_fitter_eigen/fitter.cpp)
172 173
target_link_libraries(rational_fitter_quadprog quadprog)
target_link_libraries(rational_fitter_parallel quadprog)
174 175 176

# TODO: Add check before compiling CERES, NLOPT and IPOPT
alta_add_plugin(nonlinear_fitter_ceres                  nonlinear_fitter_ceres/fitter.cpp)
177
target_link_libraries(nonlinear_fitter_ceres ceres)
178
alta_add_plugin(nonlinear_fitter_nlopt                  nonlinear_fitter_nlopt/fitter.cpp)
179
target_link_libraries(nonlinear_fitter_nlopt nlopt)
180
#alta_add_plugin(nonlinear_fitter_ipopt                  nonlinear_fitter_ipopt/fitter.cpp)
181

182 183 184 185 186 187
# Python bindings
if(PYTHONLIBS_FOUND AND Boost_FOUND)
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/python)
    include_directories(${PYTHON_INCLUDE_DIRS} ${Boost_INCLUDE_DIR})
    add_library(alta SHARED sources/python/alta.cpp)
    target_link_libraries(alta core ${PYTHON_LIBRARIES} ${Boost_LIBRARIES})
188
    set_target_properties(alta PROPERTIES PREFIX "")
189 190 191 192 193
    if(APPLE)
        set_target_properties(alta PROPERTIES SUFFIX ".so")
    endif()
endif()

194

195 196 197 198 199 200
#############################
#          Softs            #
#############################

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/softs)

201 202 203 204 205 206 207 208 209
alta_add_soft(brdf2brdf    brdf2brdf/main.cpp)
alta_add_soft(brdf2data    brdf2data/main.cpp)
alta_add_soft(brdf2gnuplot brdf2gnuplot/main.cpp)
#alta_add_soft(brdf2moments brdf2moments/main.cpp)
alta_add_soft(brdf2stats   fit2stat/fit2stat.cpp)
alta_add_soft(data2data    data2data/main.cpp)
alta_add_soft(data2brdf    data2brdf/main.cpp)
alta_add_soft(data2stats   data2stats/data2stats.cpp)
alta_add_soft(data2moments data2moments/main.cpp)
210

211

212 213 214 215
#############################
#          Tests            #
#############################

216
enable_testing()
217

218 219 220 221 222 223 224
# Test all softs with `--help` option
alta_test_soft(brdf2data)
alta_test_soft(data2data)
alta_test_soft(data2stats)
alta_test_soft(data2brdf)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests)
225
include_directories("sources/tests")
226

227 228 229 230 231 232 233 234 235
# Unit test
alta_test_unit(test_data_io  core/data-io.cpp)
alta_test_unit(half-test-1   core/half-test-1.cpp)
alta_test_unit(half-test-2   core/half-test-2.cpp)
alta_test_unit(half-test-3   core/half-test-3.cpp)
alta_test_unit(half-test-4   core/half-test-4.cpp)
alta_test_unit(nonlinear-fit core/nonlinear-fit.cpp)
alta_test_unit(params-test-1 core/params-test-1.cpp)
alta_test_unit(params-test-2 core/params-test-2.cpp)
236 237

if(CPPQUICKCHECK_FOUND)
238
    alta_test_unit(params-qc-1 core/params-qc-1.cpp)
239 240
endif()

241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
# Integration test for rational function fitting
foreach(fitter IN ITEMS eigen leastsquare quadprog parallel)
    add_test(NAME "data2dbrdf_kirby_${fitter}"
             COMMAND "data2brdf" "--input"   "${CMAKE_SOURCE_DIR}/sources/tests/Kirby2.dat"
                                 "--output"  "Kirby2.func"
                                 "--fitter"  "rational_fitter_${fitter}"
             WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/tests")

    set_tests_properties("data2dbrdf_kirby_${fitter}"
                         PROPERTIES ENVIRONMENT "ALTA_PLUGIN_PATH=${CMAKE_BINARY_DIR}/plugins")
endforeach()

add_test(NAME "brdf2data_kirby"
         COMMAND "brdf2data" "--input"     "Kirby2.func"
                             "--output"    "Kirby2.dat"
                             "--data-file" "${CMAKE_SOURCE_DIR}/sources/tests/Kirby2.dat"
         WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/tests")

add_test(NAME "data2stats_kirby"
         COMMAND "data2stats" "--input"     "Kirby2.dat"
                              "--ref"       "${CMAKE_SOURCE_DIR}/sources/tests/Kirby2.dat"
         WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/tests")



266
# Integration tests using MERL data
Laurent Belcour's avatar
Laurent Belcour committed
267
#
268
alta_download_merl("gold-metallic-paint")
Laurent Belcour's avatar
Laurent Belcour committed
269 270 271
if(NOT gold-metallic-paint_FOUND)
	message("Error checking for gold-metallic-paint.binary but not found")
endif()
272
if(gold-metallic-paint_FOUND)
273

Laurent Belcour's avatar
Laurent Belcour committed
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
     # Converting back an forth between MERL format and BRDF Slice format
     # At the end of this batch, there should be multiple file of the same
     # view of the gold metallic paint.
     #
     add_test(NAME "data2data_gold_slice_stark"
              COMMAND "data2data" "--input"    "gold-metallic-paint.binary"
                                  "--output"   "gold-metallic-paint-stark.exr"
                                  "--in-data"  "data_merl"
                                  "--out-data" "data_brdf_slice"
              WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/tests")

     add_test(NAME "data2data_gold_slice_merl"
              COMMAND "data2data" "--input"    "gold-metallic-paint-stark.exr"
                                  "--output"   "gold-metallic-paint-2.binary"
                                  "--in-data"  "data_brdf_slice"
                                  "--out-data" "data_merl"
              WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/tests")

     add_test(NAME "data2data_gold_slice_rusin_1"
293
              COMMAND "data2data" "--input"    "gold-metallic-paint.binary"
Laurent Belcour's avatar
Laurent Belcour committed
294
                                  "--output"   "gold-metallic-paint-rusin-1.exr"
295
                                  "--in-data"  "data_merl"
Laurent Belcour's avatar
Laurent Belcour committed
296
                                  "--param"    "RUSIN_TH_TD"
297 298
                                  "--out-data" "data_brdf_slice"
              WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
Laurent Belcour's avatar
Laurent Belcour committed
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324

    add_test(NAME "data2data_gold_alta_rusin_1"
              COMMAND "data2data" "--input"    "gold-metallic-paint-rusin-1.exr"
                                  "--output"   "gold-metallic-paint-rusin-1.alta"
                                  "--in-data"  "data_brdf_slice"
              WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/tests")

     add_test(NAME "data2data_gold_slice_rusin_2"
              COMMAND "data2data" "--input"    "gold-metallic-paint.binary"
                                  "--output"   "gold-metallic-paint-rusin-2.exr"
                                  "--in-data"  "data_merl"
                                  "--param"    "RUSIN_TH_TD_PD"
                                  "--angle"    "90"
                                  "--out-data" "data_brdf_slice"
              WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/tests")

    # Remove zeros from the BRDF slice plugin
    #
    add_test(NAME "data2data_gold_remove_zeros"
              COMMAND "data2data" "--input"    "gold-metallic-paint-stark.exr"
                                  "--output"   "gold-metallic-paint-stark.alta"
                                  "--in-data"  "data_brdf_slice"
                                  "--ymin"     "[0.001, 0.001, 0.001]"
              WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/tests")


325 326 327 328 329 330 331 332
    set_tests_properties("data2data_gold_slice_stark"
                         "data2data_gold_remove_zeros"
                         "data2data_gold_slice_merl"
                         "data2data_gold_slice_rusin_1"
                         "data2data_gold_alta_rusin_1"
                         "data2data_gold_slice_rusin_2"
                         PROPERTIES ENVIRONMENT "ALTA_PLUGIN_PATH=${CMAKE_BINARY_DIR}/plugins")

Laurent Belcour's avatar
Laurent Belcour committed
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
    # Test all the rational fitters on the gold metallic data
    # At the end of this pass, there should be one ALTA function file per fitter
    #
    foreach(fitter IN ITEMS eigen leastsquare quadprog parallel)
        add_test(NAME "data2dbrdf_gold_rf_${fitter}"
                COMMAND "data2brdf" "--output"   "gold-metallic-paint-rf-${fitter}.func"
                                    "--input"    "gold-metallic-paint-rusin-1.alta"
                                    "--fitter"  "rational_fitter_${fitter}"
                                    "--min-np"  "100"
                                    "--np"      "100"
                                    "--nq"      "50"
                WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/tests")

        set_tests_properties("data2dbrdf_gold_rf_${fitter}"
                            PROPERTIES ENVIRONMENT "ALTA_PLUGIN_PATH=${CMAKE_BINARY_DIR}/plugins")

        add_test(NAME "brdf2data_gold_rf_${fitter}"
                COMMAND "brdf2data" "--input"     "gold-metallic-paint-rf-${fitter}.func"
                                    "--output"    "gold-metallic-paint-${fitter}.exr"
                                    "--data"      "data_brdf_slice"
                                    "--data-file" "gold-metallic-paint-rusin-1.exr"
                WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/tests")

356 357 358
        set_tests_properties("brdf2data_gold_rf_${fitter}"
                            PROPERTIES ENVIRONMENT "ALTA_PLUGIN_PATH=${CMAKE_BINARY_DIR}/plugins")

Laurent Belcour's avatar
Laurent Belcour committed
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
    endforeach()



    # Test all the nonlinear fitters on the gold metallic data
    # At the end of this pass, there should be one ALTA function file per fitter
    #
    foreach(fitter IN ITEMS eigen ceres nlopt)
        add_test(NAME "data2dbrdf_gold_${fitter}"
            COMMAND "data2brdf" "--input"   "gold-metallic-paint-stark.alta"
                            "--output"  "gold-metallic-paint-${fitter}.func"
                            "--fitter"  "nonlinear_fitter_${fitter}"
                            "--func"    "[nonlinear_function_diffuse, nonlinear_function_blinn]"
            WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/tests")

        set_tests_properties("data2dbrdf_gold_${fitter}"
            PROPERTIES ENVIRONMENT "ALTA_PLUGIN_PATH=${CMAKE_BINARY_DIR}/plugins")
    endforeach()
377
endif()
378

379
if(gold-metallic-paint_FOUND AND CATCH_FOUND)
380
    alta_test_unit(conversion-catch-1 core/conversion-catch-1.cpp )
381
endif()