RMF
Toggle main menu visibility
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>
13
#include <
RMF/infrastructure_macros.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_;
34
ScoreConst(
NodeConstHandle
nh,
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
:
101
ScoreFactory(
FileConstHandle
fh):
102
cat_(fh.get_category(
"feature"
)),
103
score_(fh.get_key<FloatTag>(cat_,
"score"
)) {
104
}
105
ScoreFactory(
FileHandle
fh):
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 */
Decorator.h
Mostly empty base classes for decorators and factories.
FileHandle.h
Declaration for RMF::FileHandle.
NodeHandle.h
Declaration of NodeHandle.
Vector.h
Represent coordinates.
RMF::Factory
The base class for Factories.
Definition
Decorator.h:46
RMF::FileConstHandle
A handle for a read-only RMF file.
Definition
FileConstHandle.h:78
RMF::FileHandle
A handle for an RMF file.
Definition
FileHandle.h:54
RMF::NodeConstHandle
A handle for a particular node in a read-only hierarchy.
Definition
NodeConstHandle.h:86
RMF::NodeConstHandle::get_type
NodeType get_type() const
get the type of this node
Definition
NodeConstHandle.h:203
RMF::NodeHandle
A handle for a particular node in the hierarchy.
Definition
NodeHandle.h:60
RMF::decorator::ScoreConst
Definition
feature.h:30
RMF::decorator::ScoreFactory::get
ScoreConst get(NodeConstHandle nh) const
Definition
feature.h:110
RMF::decorator::ScoreFactory::get_is
bool get_is(NodeConstHandle nh) const
Definition
feature.h:125
RMF::decorator::ScoreFactory::get
Score get(NodeHandle nh) const
Definition
feature.h:117
RMF::decorator::Score
Definition
feature.h:64
constants.h
Various constants.
infrastructure_macros.h
Various general useful macros for IMP.
RMF::decorator
See Decorators and Attributes for more information.
Definition
CoordinateTransformer.h:22
RMF
The namespace for all functionality in the library.
Definition
BufferConstHandle.h:21
RMF::FEATURE
const NodeType FEATURE
Store information about some feature of the system.
RMF::Category
ID< CategoryTag > Category
Definition
ID.h:110
RMF::Float
float Float
Definition
types.h:33
RMF::FloatKey
ID< FloatTag > FloatKey
Definition
keys.h:41