CMakeLists.txt 16.2 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
find_package(Doxygen)
26 27 28

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

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

33
# Look for header only dependencies
34 35 36
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")
37 38 39 40 41

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

43 44 45 46 47 48 49
# 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)

50

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

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

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

65
function(alta_test_unit name sources)
66 67
        add_executable(${name} sources/tests/${sources})
        target_link_libraries(${name} core)
68 69
        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")
70 71 72 73 74
endfunction(alta_test_unit)

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

76
function(alta_download_merl name)
77
    find_file(${name}_FOUND "${name}.binary" PATHS "${CMAKE_BINARY_DIR}/tests/")
78 79
    if(NOT ${name}_FOUND)
        message("Dowloading ${name} from MERL database:")
Laurent Belcour's avatar
Laurent Belcour committed
80 81 82 83
	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)
84
    endif()
85 86
endfunction(alta_download_merl)

87 88 89 90 91 92

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

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
93

94 95 96 97
add_library(core STATIC
            sources/core/args.h
            sources/core/common.h
            sources/core/common.cpp
98 99 100 101 102 103
            sources/core/metrics.h
            sources/core/metrics.cpp
            sources/core/params.h
            sources/core/params.cpp
            sources/core/data.h
            sources/core/data.cpp
104
            sources/core/data_storage.h
105 106 107 108 109 110 111 112 113
            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)
114

115 116 117 118 119

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

120 121
target_link_libraries(core ${CMAKE_DL_LIBS})

122 123 124 125 126

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

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

# Data
131 132 133 134
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)
135

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

# Functions
143 144 145
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)
146 147 148 149 150 151 152 153 154
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)

155 156 157 158
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)
159 160

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

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)
166

167
# Fitters
168 169 170 171
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)
172
alta_add_plugin(nonlinear_fitter_eigen                  nonlinear_fitter_eigen/fitter.cpp)
173 174
target_link_libraries(rational_fitter_quadprog quadprog)
target_link_libraries(rational_fitter_parallel quadprog)
175 176 177

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

183 184 185 186 187 188
# 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})
189
    set_target_properties(alta PROPERTIES PREFIX "")
190 191 192 193 194
    if(APPLE)
        set_target_properties(alta PROPERTIES SUFFIX ".so")
    endif()
endif()

195

196 197 198 199 200 201
#############################
#          Softs            #
#############################

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/softs)

202 203 204 205 206 207 208 209 210
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)
211

212

213 214 215 216
#############################
#          Tests            #
#############################

217
enable_testing()
218

219 220 221 222 223 224 225
# 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)
226
include_directories("sources/tests")
227

228 229 230 231 232 233 234 235 236
# 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)
237 238

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

242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
# 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")



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

Laurent Belcour's avatar
Laurent Belcour committed
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
     # 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"
294
              COMMAND "data2data" "--input"    "gold-metallic-paint.binary"
Laurent Belcour's avatar
Laurent Belcour committed
295
                                  "--output"   "gold-metallic-paint-rusin-1.exr"
296
                                  "--in-data"  "data_merl"
Laurent Belcour's avatar
Laurent Belcour committed
297
                                  "--param"    "RUSIN_TH_TD"
298 299
                                  "--out-data" "data_brdf_slice"
              WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
Laurent Belcour's avatar
Laurent Belcour committed
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 325

    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")


326 327 328 329 330 331 332 333
    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
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
    # 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")

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

Laurent Belcour's avatar
Laurent Belcour committed
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
    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()
378
endif()
379

380
if(gold-metallic-paint_FOUND AND CATCH_FOUND)
381
    alta_test_unit(conversion-catch-1 core/conversion-catch-1.cpp )
382
endif()
383 384 385 386 387 388 389 390 391


# add a target to generate API documentation with Doxygen
if(DOXYGEN_FOUND)
	add_custom_target(doc
			  ${DOXYGEN_EXECUTABLE} ${CMAKE_SOURCE_DIR}/documents/doxygen.conf
			  WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/documents/
			  COMMENT "Generating API documentation with Doxygen" VERBATIM)
endif(DOXYGEN_FOUND)