Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/tatsy/spica into dev…
Browse files Browse the repository at this point in the history
…elopment

# Conflicts:
#	sources/CMakeLists.txt
#	sources/core/CMakeLists.txt
#	sources/core/renderparams.h
  • Loading branch information
tatsy committed Jun 14, 2016
2 parents 1061027 + 7991d3e commit 4c48796
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 64 deletions.
2 changes: 1 addition & 1 deletion sources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ function (process_subdirectory dirname)
add_subdirectory(${dirname})
set(ALL_SOURCES ${ALL_SOURCES} ${SOURCES} PARENT_SCOPE)
set(ALL_HEADERS ${ALL_HEADERS} ${HEADERS} PARENT_SCOPE)
# include_directories(${CMAKE_CURRENT_LIST_DIR}/${dirname})
file(GLOB FILTER_FILES "${dirname}/*.cc" "${dirname}/*.h")

if (MSVC)
Expand Down Expand Up @@ -49,6 +48,7 @@ if (spica_USE_STATIC_LIBS)
add_library(${BUILD_TARGET} ${ALL_SOURCES} ${ALL_HEADERS})
else()
add_library(${BUILD_TARGET} SHARED ${ALL_SOURCES} ${ALL_HEADERS})
set(SPICA_LIBS ${LIB_PREFIX}${BUILD_TARGET}${LIB_SUFFIX} CACHE INTERNAL "")
endif()

if (MSVC)
Expand Down
1 change: 1 addition & 0 deletions sources/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ configure_file(${CMAKE_CURRENT_LIST_DIR}/spica_dirs.h.in
set(SOURCES ${SOURCES}
${CMAKE_CURRENT_LIST_DIR}/parallel.cc
${CMAKE_CURRENT_LIST_DIR}/engine.cc
${CMAKE_CURRENT_LIST_DIR}/renderparams.cc
${CMAKE_CURRENT_LIST_DIR}/memory.cc
${CMAKE_CURRENT_LIST_DIR}/spectrum.cc
${CMAKE_CURRENT_LIST_DIR}/sampling.cc
Expand Down
22 changes: 22 additions & 0 deletions sources/core/renderparams.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#define SPICA_API_EXPORT
#include "renderparams.h"

namespace spica {

// -----------------------------------------------------------------------------
// Other method definitions
// -----------------------------------------------------------------------------

RenderParams::RenderParams()
: table_{} {
// Set default parameters
set("MAX_BOUNCES", 32);
set("NUM_SAMPLES", 32);
set("CAST_PHOTONS", 500000);
}

void RenderParams::clear() {
table_.clear();
}

} // namespace spica
124 changes: 61 additions & 63 deletions sources/core/renderparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,85 +8,83 @@
#include <string>
#include <map>

#include "common.h"

namespace spica {

class RenderParams {
class SPICA_EXPORTS RenderParams {
public:
RenderParams()
: table_{} {
// Set default parameters
set("MAX_BOUNCES", 32);
set("NUM_SAMPLES", 32);
set("CAST_PHOTONS", 500000);
}
RenderParams();

void clear() {
table_.clear();
}
void clear();

template <class T>
void set(const std::string& key, const T& value);

template <>
void set(const std::string& key, const int& value) {
char buf[32];
sprintf(buf, "%d", value);
table_[key] = std::string(buf);
}

template <>
void set(const std::string& key, const double& value) {
char buf[32];
sprintf(buf, "%f", value);
table_[key] = std::string(buf);
}

template <>
void set(const std::string& key, const std::string& value) {
table_[key] = value;
}

template <class T>
T get(const std::string& key) const;

template <>
int get(const std::string& key) const {
const auto it = table_.find(key);
if (it == table_.cend()) {
fprintf(stderr, "Specified key \"%s\" was not found\n",
key.c_str());
return 0;
}
return std::atoi(it->second.c_str());
}

template <>
double get(const std::string& key) const {
const auto it = table_.find(key);
if (it == table_.cend()) {
fprintf(stderr, "Specified key \"%s\" was not found\n",
key.c_str());
return 0;
}
return std::atof(it->second.c_str());
}

template <>
std::string get(const std::string& key) const {
const auto it = table_.find(key);
if (it == table_.cend()) {
fprintf(stderr, "Specified key \"%s\" was not found\n",
key.c_str());
return 0;
}
return std::move(it->second);
}

private:
// Private fields
std::map<std::string, std::string> table_;
};

// -----------------------------------------------------------------------------
// Template specialization for getter/setter methods
// -----------------------------------------------------------------------------

template <>
inline void RenderParams::set(const std::string& key, const int& value) {
char buf[32];
sprintf(buf, "%d", value);
table_[key] = std::string(buf);
}

template <>
inline void RenderParams::set(const std::string& key, const double& value) {
char buf[32];
sprintf(buf, "%f", value);
table_[key] = std::string(buf);
}

template <>
inline void RenderParams::set(const std::string& key, const std::string& value) {
table_[key] = value;
}

template <>
inline int RenderParams::get(const std::string& key) const {
const auto it = table_.find(key);
if (it == table_.cend()) {
fprintf(stderr, "Specified key \"%s\" was not found\n",
key.c_str());
return 0;
}
return std::atoi(it->second.c_str());
}

template <>
inline double RenderParams::get(const std::string& key) const {
const auto it = table_.find(key);
if (it == table_.cend()) {
fprintf(stderr, "Specified key \"%s\" was not found\n",
key.c_str());
return 0;
}
return std::atof(it->second.c_str());
}

template <>
inline std::string RenderParams::get(const std::string& key) const {
const auto it = table_.find(key);
if (it == table_.cend()) {
fprintf(stderr, "Specified key \"%s\" was not found\n",
key.c_str());
return 0;
}
return std::move(it->second);
}

} // namespace spica

#endif // _SPICA_RENDER_PARAMETERS_H_

0 comments on commit 4c48796

Please sign in to comment.