RMF
feature.h
Go to the documentation of this file.
1 /**
2  * \file RMF/decorator/feature.h
3  * \brief Helper functions for manipulating RMF files.
4  *
5  * Copyright 2007-2022 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef RMF_FEATURE_DECORATORS_H
10 #define RMF_FEATURE_DECORATORS_H
11 
12 #include <RMF/config.h>
14 #include <RMF/NodeHandle.h>
15 #include <RMF/FileHandle.h>
16 #include <RMF/Decorator.h>
17 #include <RMF/constants.h>
18 #include <RMF/Vector.h>
19 #include <RMF/internal/paths.h>
20 #include <array>
21 #include <boost/lexical_cast.hpp>
22 
23 RMF_ENABLE_WARNINGS
24 namespace RMF {
25 namespace decorator {
26 
27 
28  /** See also Score and ScoreFactory.
29  */
30  class ScoreConst: public Decorator {
31  friend class ScoreFactory;
32  protected:
33  FloatKey score_;
35  FloatKey score):
36  Decorator(nh),
37 score_(score) {
38  }
39  public:
40 
41  Float get_score() const {
42  try {
43  return get_node().get_value(score_);
44  } RMF_DECORATOR_CATCH( );
45  }
46  Float get_frame_score() const {
47  try {
48  return get_node().get_frame_value(score_);
49  } RMF_DECORATOR_CATCH( );
50  }
51  Float get_static_score() const {
52  try {
53  return get_node().get_static_value(score_);
54  } RMF_DECORATOR_CATCH( );
55  }
56 
57  static std::string get_decorator_type_name() {
58  return "ScoreConst";
59  }
60  RMF_SHOWABLE(ScoreConst, "Score: " << get_node());
61  };
62  /** See also ScoreFactory.
63  */
64  class Score: public ScoreConst {
65  friend class ScoreFactory;
66  Score(NodeHandle nh,
67  FloatKey score):
68  ScoreConst(nh, score) {
69  }
70  public:
71 
72  void set_score(Float v) {
73  try {
74  get_node().set_value(score_, v);
75  } RMF_DECORATOR_CATCH( );
76  }
77  void set_frame_score(Float v) {
78  try {
79  get_node().set_frame_value(score_, v);
80  } RMF_DECORATOR_CATCH( );
81  }
82  void set_static_score(Float v) {
83  try {
84  get_node().set_static_value(score_, v);
85  } RMF_DECORATOR_CATCH( );
86  }
87 
88  static std::string get_decorator_type_name() {
89  return "Score";
90  }
91  };
92 
93 
94  /** Create decorators of type Score.
95  */
96  class ScoreFactory: public Factory {
97  Category cat_;
98 FloatKey score_;
99 
100  public:
102  cat_(fh.get_category("feature")),
103  score_(fh.get_key<FloatTag>(cat_, "score")) {
104  }
106  cat_(fh.get_category("feature")),
107  score_(fh.get_key<FloatTag>(cat_, "score")) {
108  }
109  /** Get a ScoreConst for nh.*/
110  ScoreConst get(NodeConstHandle nh) const {
111  RMF_USAGE_CHECK((nh.get_type() == RMF::FEATURE), std::string("Bad node type. Got \"")
112  + boost::lexical_cast<std::string>(nh.get_type())
113  + "\" in decorator type Score");
114  return ScoreConst(nh, score_);
115  }
116  /** Get a Score for nh.*/
117  Score get(NodeHandle nh) const {
118  RMF_USAGE_CHECK((nh.get_type() == RMF::FEATURE), std::string("Bad node type. Got \"")
119  + boost::lexical_cast<std::string>(nh.get_type())
120  + "\" in decorator type Score");
121  return Score(nh, score_);
122  }
123  /** Check whether nh has all the attributes required to be a
124  ScoreConst.*/
125  bool get_is(NodeConstHandle nh) const {
126  return (nh.get_type() == RMF::FEATURE)
127  && !nh.get_value(score_).get_is_null();
128  }
129  bool get_is_static(NodeConstHandle nh) const {
130  return (nh.get_type() == RMF::FEATURE)
131  && !nh.get_static_value(score_).get_is_null();
132  }
133  RMF_SHOWABLE(ScoreFactory, "ScoreFactory");
134  };
135  #ifndef RMF_DOXYGEN
136 struct ScoreConstFactory: public ScoreFactory {
137  ScoreConstFactory(FileConstHandle fh):
138  ScoreFactory(fh) {
139  }
140  ScoreConstFactory(FileHandle fh):
141  ScoreFactory(fh) {
142  }
143 
144 };
145  #endif
146 
147 
148 
149 } /* namespace decorator */
150 } /* namespace RMF */
151 RMF_DISABLE_WARNINGS
152 
153 #endif /* RMF_FEATURE_DECORATORS_H */
Mostly empty base classes for decorators and factories.
const NodeType FEATURE
Store information about some feature of the system.
bool get_is(NodeConstHandle nh) const
Definition: feature.h:125
A handle for a particular node in the hierarchy.
Definition: NodeHandle.h:60
float Float
Definition: types.h:33
The base class for decorators.
Definition: Decorator.h:29
NodeType get_type() const
get the type of this node
Various constants.
A handle for a particular node in a read-only hierarchy.
A handle for a read-only RMF file.
void set_value(ID< Tag > k, typename Tag::ArgumentType v) const
Definition: NodeHandle.h:115
A handle for an RMF file.
Definition: FileHandle.h:54
The base class for Factories.
Definition: Decorator.h:46
Declaration for RMF::FileHandle.
Represent coordinates.
Declaration of NodeHandle.
void set_static_value(ID< Tag > k, typename Tag::ArgumentType v) const
set the value of the attribute k for all frames.
Definition: NodeHandle.h:122
ID< Tag > get_key(Category category, std::string name) const
Various general useful macros for IMP.
void set_frame_value(ID< Tag > k, typename Tag::ArgumentType v) const
set the value of the attribute k for this node on the current frame.
Definition: NodeHandle.h:103