7 #include "fwAtomConversion/mapper/Landmarks.hpp" 9 #include "fwAtomConversion/convert.hpp" 10 #include "fwAtomConversion/exception/ConversionNotManaged.hpp" 11 #include "fwAtomConversion/mapper/registry/macros.hpp" 13 #include <fwAtoms/Boolean.hpp> 14 #include <fwAtoms/Map.hpp> 15 #include <fwAtoms/Numeric.hpp> 16 #include <fwAtoms/Numeric.hxx> 17 #include <fwAtoms/Sequence.hpp> 18 #include <fwAtoms/String.hpp> 20 #include <fwData/Landmarks.hpp> 22 #include <fwTools/UUID.hpp> 24 #include <boost/algorithm/string.hpp> 38 DataVisitor::AtomCacheType& cache )
40 const camp::Class& metaclass = ::camp::classByName( object->getClassname() );
42 metaclass.visit(visitor);
43 ::fwAtoms::Object::sptr atom = visitor.getAtomObject();
45 ::fwData::Landmarks::csptr landmarks = ::fwData::Landmarks::dynamicCast(
object);
47 ::fwAtoms::Map::sptr map = ::fwAtoms::Map::New();
49 ::fwData::Landmarks::GroupNameContainer names = landmarks->getGroupNames();
50 for (
const auto& name: names)
52 const ::fwData::Landmarks::LandmarksGroup& group = landmarks->getGroup(name);
53 ::fwAtoms::Object::sptr atomGroup = ::fwAtoms::Object::New();
56 const std::string colorStr = std::to_string(group.m_color[0]) +
";" +
57 std::to_string(group.m_color[1]) +
";" +
58 std::to_string(group.m_color[2]) +
";" +
59 std::to_string(group.m_color[3]);
62 const std::string shapeStr = (group.m_shape == ::fwData::Landmarks::Shape::SPHERE) ?
"SPHERE" :
"CUBE";
66 ::fwAtoms::Sequence::sptr seq = ::fwAtoms::Sequence::New();
68 for (
const auto&
point : group.m_points)
70 const std::string pointStr = std::to_string(
point[0]) +
";" +
71 std::to_string(
point[1]) +
";" +
72 std::to_string(
point[2]);
75 atomGroup->setAttribute(
"points", seq);
76 map->insert(name, atomGroup);
78 atom->setAttribute(
"landmarks", map );
86 AtomVisitor::DataCacheType& cache,
87 const AtomVisitor::IReadPolicy& uuidPolicy
92 ::fwData::Object::sptr data = visitor.getDataObject();
93 ::fwData::Landmarks::sptr landmarks = ::fwData::Landmarks::dynamicCast(data);
95 ::fwAtoms::Map::sptr map = ::fwAtoms::Map::dynamicCast(atom->getAttribute(
"landmarks"));
97 for (
const auto& elt : map->getValue())
99 const std::string name = elt.first;
100 FW_RAISE_EXCEPTION_IF( exception::ConversionNotManaged(
101 "sub atoms stored in fwAtom::Map 'landmarks' must be atom objects"),
102 elt.second->type() != ::fwAtoms::Base::OBJECT );
103 ::fwAtoms::Object::sptr obj = ::fwAtoms::Object::dynamicCast(elt.second);
106 ::fwAtoms::String::csptr colorObj = ::fwAtoms::String::dynamicCast(obj->getAttribute(
"color"));
107 FW_RAISE_EXCEPTION_IF( exception::ConversionNotManaged(
108 "sub atom 'color' stored in fwAtom::Object 'landmarks' must be ::fwAtoms::String"),
111 const std::string& colorStr = colorObj->getValue();
113 std::vector< std::string> result;
114 ::boost::split(result, colorStr, ::boost::is_any_of(
";"));
116 FW_RAISE_EXCEPTION_IF( exception::ConversionNotManaged(
"'color' atom must be of type rgba"),
117 result.size() != 4 );
118 const ::fwData::Landmarks::ColorType color = {{
119 std::stof(result[0]), std::stof(result[1]),
120 std::stof(result[2]), std::stof(result[3])
124 ::fwAtoms::Numeric::csptr sizeObj = ::fwAtoms::Numeric::dynamicCast(obj->getAttribute(
"size"));
125 FW_RAISE_EXCEPTION_IF( exception::ConversionNotManaged(
126 "sub atom 'size' stored in fwAtom::Object 'landmarks' must be ::fwAtoms::Numeric"),
128 const ::fwData::Landmarks::SizeType size = sizeObj->getValue< ::fwData::Landmarks::SizeType >();
131 ::fwAtoms::String::csptr shapeObj = ::fwAtoms::String::dynamicCast(obj->getAttribute(
"shape"));
132 FW_RAISE_EXCEPTION_IF( exception::ConversionNotManaged(
133 "sub atom 'shape' stored in fwAtom::Object 'landmarks' must be ::fwAtoms::String"),
136 const std::string& shapeStr = shapeObj->getValue();
137 ::fwData::Landmarks::Shape shape;
138 if (shapeStr ==
"SPHERE")
140 shape = ::fwData::Landmarks::Shape::SPHERE;
142 else if (shapeStr ==
"CUBE")
144 shape = ::fwData::Landmarks::Shape::CUBE;
148 FW_RAISE_EXCEPTION(exception::ConversionNotManaged(
"'shape' value '"+ shapeStr +
"' is not managed"));
152 ::fwAtoms::Boolean::csptr visuObj = ::fwAtoms::Boolean::dynamicCast(obj->getAttribute(
"visibility"));
153 FW_RAISE_EXCEPTION_IF( exception::ConversionNotManaged(
154 "sub atom 'visibility' stored in 'landmarks' must be ::fwAtoms::Boolean"),
156 const bool visibility = visuObj->getValue();
158 landmarks->addGroup(name, color, size, shape, visibility);
161 ::fwAtoms::Sequence::csptr seq = ::fwAtoms::Sequence::dynamicCast(obj->getAttribute(
"points"));
162 for (
const auto& elt : seq->getValue())
164 FW_RAISE_EXCEPTION_IF( exception::ConversionNotManaged(
165 "sub atoms stored in 'points' must be ::fwAtoms::String"),
166 elt->type() != ::fwAtoms::Base::STRING );
168 ::fwAtoms::String::csptr ptStrObj = ::fwAtoms::String::dynamicCast(elt);
169 const std::string& ptStr = ptStrObj->getValue();
171 std::vector< std::string> resultPt;
172 ::boost::split(resultPt, ptStr, ::boost::is_any_of(
";"));
174 FW_RAISE_EXCEPTION_IF( exception::ConversionNotManaged(
"point atom must be of type x;y;z"),
175 resultPt.size() != 3 );
177 ::fwData::Landmarks::PointType pt = {{
178 std::stod(resultPt[0]), std::stod(resultPt[1]),
179 std::stod(resultPt[2])
181 landmarks->addPoint(name, pt);
virtual FWATOMCONVERSION_API std::shared_ptr< ::fwAtoms::Object > convert(std::shared_ptr< ::fwData::Object > object, DataVisitor::AtomCacheType &cache)
Convert a fwData::Object to a fwAtoms::Object.
This class defines a list of 3D points inside groups.
This namespace contains the necessary class for fwData <-> fwAtoms conversion.
Specific mapper used to convert a fwData::Landmarks.
static FWATOMS_API String::sptr New(std::string value)
Construct a new Object represented a string.
static Numeric::sptr New(T value)
Build a new numeric type.
Visitor used to convert a fwData to a fwAtoms. fwData camp property names are used like key to store ...
static FWATOMS_API Boolean::sptr New(std::string value)
Construct an object storing a bool value.
This class is used to convert a fwAtoms to a fwData.