RMF
alternatives.h
Go to the documentation of this file.
1 /**
2  * \file RMF/decorator/alternatives.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_DECORATORS_ALTERNATIVES_H
10 #define RMF_DECORATORS_ALTERNATIVES_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/Enum.h>
19 #include <RMF/Vector.h>
20 
21 RMF_ENABLE_WARNINGS
22 namespace RMF {
23 namespace decorator {
24 
25 /** See also Alternatives and AlternativesFactory.
26  */
27 class RMFEXPORT AlternativesConst : public Decorator {
28  friend class AlternativesFactory;
29  friend class Alternatives;
30  IntsKey types_key_;
31  IntsKey roots_key_;
32  AlternativesConst(NodeConstHandle nh, IntsKey types_key, IntsKey roots_key)
33  : Decorator(nh), types_key_(types_key), roots_key_(roots_key) {}
34  NodeID get_alternative_impl(RepresentationType type, float resolution) const;
35  NodeIDs get_alternatives_impl(RepresentationType type) const;
36 
37  public:
38  /** Get the alternative root that best matches the criteria. */
39  NodeConstHandle get_alternative(RepresentationType type,
40  double resolution) const;
41 
42  /** Get the type of the representation with the given node id. */
43  RepresentationType get_representation_type(NodeID id) const;
44 
45  RepresentationType get_representation_type(NodeConstHandle id) const {
46  return get_representation_type(id.get_id());
47  }
48 
49  /** Get all the alternatives (including this node).
50 
51  You can use get_resolution() and get_representation_type() to get info
52  about them. */
53  NodeConstHandles get_alternatives(RepresentationType type) const;
54 
55  static std::string get_decorator_type_name() { return "AlternativesConst"; }
56  RMF_SHOWABLE(AlternativesConst, "Alternatives: " << get_node());
57 };
58 
59 /** See also AlternativesConst and AlternativesFactory.
60  */
61 class RMFEXPORT Alternatives : public AlternativesConst {
62  friend class AlternativesFactory;
63  Alternatives(NodeHandle nh, IntsKey types_key, IntsKey roots_key);
64 
65  public:
66  void add_alternative(NodeHandle root, RepresentationType type);
67 
68  static std::string get_decorator_type_name() { return "Alternatives"; }
69 };
70 
71 /** Create decorators of type Alternatives.
72 
73  See also Alternatives and AlternativesFactory.
74  */
75 class RMFEXPORT AlternativesFactory : public Factory {
76  Category cat_;
77  IntsKey types_key_;
78  IntsKey roots_key_;
79 
80  public:
83 
84  Alternatives get(NodeHandle nh) const {
85  return Alternatives(nh, types_key_, roots_key_);
86  }
87  AlternativesConst get(NodeConstHandle nh) const {
88  return AlternativesConst(nh, types_key_, roots_key_);
89  }
90  bool get_is(NodeConstHandle nh) const { return nh.get_has_value(types_key_); }
91  bool get_is_static(NodeConstHandle nh) const {
92  return nh.get_has_value(types_key_);
93  }
94  RMF_SHOWABLE(AlternativesFactory, "AlternativesFactory");
95 };
96 
97 #ifndef RMF_DOXYGEN
98 struct AlternativesConstFactory : public AlternativesFactory {
99  AlternativesConstFactory(FileConstHandle fh) : AlternativesFactory(fh) {}
100  AlternativesConstFactory(FileHandle fh) : AlternativesFactory(fh) {}
101 };
102 #endif
103 
104 /** Return the canonical resolution of the subtree. */
105 RMFEXPORT double get_resolution(NodeConstHandle root);
106 
107 /** Return a list of (clustered) resolution levels available in the subtree.
108 
109  Use this, for example, when making a slider for display.
110 */
111 RMFEXPORT Floats get_resolutions(NodeConstHandle root,
113  double accuracy = 0);
114 
115 } /* namespace decorator */
116 } /* namespace RMF */
117 RMF_DISABLE_WARNINGS
118 
119 #endif /* RMF_DECORATORS_ALTERNATIVES_H */
Mostly empty base classes for decorators and factories.
A handle for a particular node in the hierarchy.
Definition: NodeHandle.h:60
double get_resolution(NodeConstHandle root)
The base class for decorators.
Definition: Decorator.h:29
Enum< RepresentationTypeTag > RepresentationType
Definition: Enum.h:127
Various constants.
A handle for a particular node in a read-only hierarchy.
const RepresentationType PARTICLE
A handle for a read-only RMF file.
Declaration of RMF::Enum.
A handle for an RMF file.
Definition: FileHandle.h:54
The base class for Factories.
Definition: Decorator.h:46
Floats get_resolutions(NodeConstHandle root, RepresentationType type=PARTICLE, double accuracy=0)
Declaration for RMF::FileHandle.
Represent coordinates.
Declaration of NodeHandle.
A strong enum with an associated string name for each value.
Definition: Enum.h:46
std::vector< NodeConstHandle > NodeConstHandles
Pass a list of them.
std::vector< Float > Floats
Definition: types.h:35
Various general useful macros for IMP.
std::vector< NodeID > NodeIDs
Definition: ID.h:113