fw4spl
Bundles/core/dataReg/src/dataReg/parser/TransferFunction.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "dataReg/parser/TransferFunction.hpp"
8 
9 #include <fwData/Color.hpp>
10 #include <fwData/TransferFunction.hpp>
11 
12 #include <fwRuntime/Convert.hpp>
13 
14 #include <fwServices/macros.hpp>
15 
16 #include <boost/property_tree/xml_parser.hpp>
18 
19 namespace dataReg
20 {
21 namespace parser
22 {
23 
24 // ------------------------------------------------------------------------------
25 
27 {
28  SLM_FATAL("This method is deprecated, and this shouldn't be used.");
29 }
30 
31 // ------------------------------------------------------------------------------
32 
33 void TransferFunction::createConfig( ::fwTools::Object::sptr _obj )
34 {
35  ::fwData::TransferFunction::sptr tf = ::fwData::TransferFunction::dynamicCast( _obj );
36  SLM_ASSERT("TransferFunction not instanced", tf);
37 
38  const ConfigType config = ::fwRuntime::Convert::toPropertyTree(m_cfg).get_child("object");
39  if(config.count("colors"))
40  {
41  const ConfigType colorCfg = config.get_child("colors");
42 
43  const bool isDefault = colorCfg.get("<xmlattr>.default", false);
44  if(isDefault)
45  {
46  ::fwData::TransferFunction::sptr defaultTf = ::fwData::TransferFunction::createDefaultTF();
47  tf->deepCopy(defaultTf);
48  }
49  else
50  {
51  const auto stepsConfig = colorCfg.equal_range("step");
52 
53  for (auto itStepCfg = stepsConfig.first; itStepCfg != stepsConfig.second; ++itStepCfg)
54  {
55  const double value = itStepCfg->second.get<double>("<xmlattr>.value");
56  const std::string strColor = itStepCfg->second.get<std::string>("<xmlattr>.color");
57 
58  ::fwData::Color::sptr newColor = ::fwData::Color::New();
59  newColor->setRGBA(strColor);
60 
61  const ::fwData::TransferFunction::TFColor color(newColor->red(), newColor->green(),
62  newColor->blue(), newColor->alpha());
63  tf->addTFColor(value, color);
64  }
65  tf->setWLMinMax(tf->getMinMaxTFValues());
66 
67  if (colorCfg.count("<xmlattr>.isClamped"))
68  {
69  const bool isClamped = colorCfg.get<bool>("<xmlattr>.isClamped");
70  tf->setIsClamped(isClamped);
71  }
72  }
73  }
74 }
75 
76 // ------------------------------------------------------------------------------
77 
78 } // namespace parser
79 } // namespace dataReg
80 
Specific service for the construction of a TransferFunction and its associated services from an XML-b...
The namespace dataReg (data registration) contains classes which allow to parse the xml configuration...
virtual DATAREG_API void updating() override
Updating method : create the process object.
DATAREG_API void createConfig(::fwTools::Object::sptr _obj) override
#define SLM_FATAL(message)
Definition: spyLog.hpp:283
#define SLM_ASSERT(message, cond)
work like &#39;assert&#39; from &#39;cassert&#39;, with in addition a message logged by spylog (with FATAL loglevel) ...
Definition: spyLog.hpp:308
Service type for the construction of an object and associated services from an XML-based description...
Definition: IXMLParser.hpp:36