Skip to content

Commit

Permalink
Added colormap range scene parameter (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
favreau committed Mar 9, 2018
1 parent 6da9908 commit c799e12
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 9 deletions.
3 changes: 2 additions & 1 deletion brayns/Brayns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@ struct Brayns::Impl
if (!colorMapFilename.empty())
{
TransferFunctionLoader transferFunctionLoader;
transferFunctionLoader.loadFromFile(colorMapFilename, scene);
transferFunctionLoader.loadFromFile(
colorMapFilename, sceneParameters.getColorMapRange(), scene);
}

if (!geometryParameters.getLoadCacheFile().empty())
Expand Down
7 changes: 3 additions & 4 deletions brayns/io/TransferFunctionLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ TransferFunctionLoader::TransferFunctionLoader()
}

bool TransferFunctionLoader::loadFromFile(const std::string& filename,
Scene& scene)
const Vector2f& range, Scene& scene)
{
BRAYNS_INFO << "Loading transfer function color map from " << filename
<< std::endl;
Expand Down Expand Up @@ -90,9 +90,8 @@ bool TransferFunctionLoader::loadFromFile(const std::string& filename,
++nbEntries;
}

_range = Vector2f(0.f, nbEntries);
transferFunction.setValuesRange(_range);
BRAYNS_INFO << "Transfer function values range: " << _range << std::endl;
transferFunction.setValuesRange(range);
BRAYNS_INFO << "Transfer function values range: " << range << std::endl;
file.close();
return validParsing;
}
Expand Down
6 changes: 4 additions & 2 deletions brayns/io/TransferFunctionLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ class TransferFunctionLoader
/**
* @brief Loads values from a transfer function file
* @param filename Full file name of the transfer function file
* @param range Range of values to which the transfer function is applied
* @param scene Scene holding the transfer function
* @return True if the colormap file was successfully loaded, false
* @return True if the transfer function file was successfully loaded, false
* otherwise
*/
bool loadFromFile(const std::string& filename, Scene& scene);
bool loadFromFile(const std::string& filename, const Vector2f& range,
Scene& scene);

private:
Vector2f _range;
Expand Down
14 changes: 12 additions & 2 deletions brayns/parameters/SceneParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
namespace
{
const std::string PARAM_COLOR_MAP_FILE = "color-map-file";
const std::string PARAM_COLOR_MAP_RANGE = "color-map-range";
const std::string PARAM_ENVIRONMENT_MAP = "environment-map";
}

Expand All @@ -34,14 +35,22 @@ SceneParameters::SceneParameters()
_parameters.add_options()(PARAM_COLOR_MAP_FILE.c_str(),
po::value<std::string>(),
"Color map filename [string]")(
PARAM_ENVIRONMENT_MAP.c_str(), po::value<std::string>(),
"Environment map filename [string]");
PARAM_COLOR_MAP_RANGE.c_str(), po::value<floats>()->multitoken(),
"Color map range [float float]")(PARAM_ENVIRONMENT_MAP.c_str(),
po::value<std::string>(),
"Environment map filename [string]");
}

bool SceneParameters::_parse(const po::variables_map& vm)
{
if (vm.count(PARAM_COLOR_MAP_FILE))
_colorMapFilename = vm[PARAM_COLOR_MAP_FILE].as<std::string>();
if (vm.count(PARAM_COLOR_MAP_RANGE))
{
floats values = vm[PARAM_COLOR_MAP_RANGE].as<floats>();
if (values.size() == 2)
_colorMapRange = Vector2f(values[0], values[1]);
}
if (vm.count(PARAM_ENVIRONMENT_MAP))
_environmentMap = vm[PARAM_ENVIRONMENT_MAP].as<std::string>();
return true;
Expand All @@ -52,6 +61,7 @@ void SceneParameters::print()
AbstractParameters::print();
BRAYNS_INFO << "Color Map filename :" << _colorMapFilename
<< std::endl;
BRAYNS_INFO << "Color Map range :" << _colorMapRange << std::endl;
BRAYNS_INFO << "Environment map filename : " << _environmentMap
<< std::endl;
}
Expand Down
2 changes: 2 additions & 0 deletions brayns/parameters/SceneParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class SceneParameters final : public AbstractParameters
void print() final;

const std::string& getColorMapFilename() const { return _colorMapFilename; }
const Vector2f& getColorMapRange() const { return _colorMapRange; }
/**
file name of the environment map
*/
Expand All @@ -44,6 +45,7 @@ class SceneParameters final : public AbstractParameters
bool _parse(const po::variables_map& vm) final;

std::string _colorMapFilename;
Vector2f _colorMapRange{0.f, 255.f};
std::string _environmentMap;

SERIALIZATION_FRIEND(SceneParameters)
Expand Down
1 change: 1 addition & 0 deletions plugins/engines/ospray/OSPRayScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ void OSPRayScene::commitTransferFunctionData()
ospSet1f(impl, "transferFunctionRange",
_transferFunction.getValuesRange().y() -
_transferFunction.getValuesRange().x());
ospCommit(impl);
}
markModified();
}
Expand Down
2 changes: 2 additions & 0 deletions plugins/extensions/plugins/jsonSerialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ inline void init(brayns::RenderingParameters* r, ObjectHandler* h)
inline void init(brayns::SceneParameters* s, ObjectHandler* h)
{
h->add_property("color_map_file", &s->_colorMapFilename, Flags::Optional);
h->add_property("color_map_range", Vector2fArray(s->_colorMapRange),
Flags::Optional);
h->add_property("environment_map", &s->_environmentMap, Flags::Optional);
h->set_flags(Flags::DisallowUnknownKey);
}
Expand Down

0 comments on commit c799e12

Please sign in to comment.