fw4spl
fwData/include/fwData/camp/mapper.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
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 #ifndef __FWDATA_CAMP_MAPPER_HPP__
8 #define __FWDATA_CAMP_MAPPER_HPP__
9 
10 #include "fwData/TransferFunction.hpp"
11 
12 #include <fwCamp/Mapper/ValueMapper.hpp>
13 
14 #include <boost/algorithm/string.hpp>
15 
16 namespace camp_ext
17 {
18 
19 template <>
20 struct ValueMapper< ::fwData::TransferFunction::TFColor >
21 {
22  typedef ::fwData::TransferFunction::TFColor ReturnType;
23  static const int type = camp::stringType;
24  static const std::string to(const ReturnType& source)
25  {
26  std::string result = "";
27 
28  std::string current = boost::lexical_cast< std::string>(source.r);
29  result += current;
30  result += ";";
31 
32  current = boost::lexical_cast< std::string>(source.g);
33  result += current;
34  result += ";";
35 
36  current = boost::lexical_cast< std::string>(source.b);
37  result += current;
38  result += ";";
39 
40  current = boost::lexical_cast< std::string>(source.a);
41  result += current;
42  result += ";";
43 
44  return result;
45  }
46 
47  static ReturnType from(bool source)
48  {
49  CAMP_ERROR(camp::BadType(camp::boolType, camp::mapType<ReturnType>()));
50  }
51  static ReturnType from(long source)
52  {
53  CAMP_ERROR(camp::BadType(camp::intType, camp::mapType<ReturnType>()));
54  }
55  static ReturnType from(double source)
56  {
57  CAMP_ERROR(camp::BadType(camp::realType, camp::mapType<ReturnType>()));
58  }
59  static ReturnType from(const camp::EnumObject& source)
60  {
61  CAMP_ERROR(camp::BadType(camp::enumType, camp::mapType<ReturnType>()));
62  }
63  static ReturnType from(const camp::UserObject& source)
64  {
65  CAMP_ERROR(camp::BadType(camp::userType, camp::mapType<ReturnType>()));
66  }
67  static ReturnType from(const std::string& source)
68  {
69  std::vector< std::string> result;
70  ReturnType tfColor;
71  ::boost::split(result, source, boost::is_any_of(";"));
72 
73  if(result.size() >= 4)
74  {
75  tfColor.r = ValueMapper<float>::from(result[0]);
76  tfColor.g = ValueMapper<float>::from(result[1]);
77  tfColor.b = ValueMapper<float>::from(result[2]);
78  tfColor.a = ValueMapper<float>::from(result[3]);
79  }
80  else
81  {
82  OSLM_WARN("Your tf color is not correctly setted, nb of component : " << result.size());
83  }
84  return tfColor;
85  }
86 };
87 
88 
89 } //camp_ext
90 
91 #endif /* __FWDATA_CAMP_MAPPER_HPP__ */
#define OSLM_WARN(message)
Definition: spyLog.hpp:263