Choreonoid  1.8
StdSceneReader.h
Go to the documentation of this file.
1 
6 #ifndef CNOID_UTIL_STD_SCENE_READER_H
7 #define CNOID_UTIL_STD_SCENE_READER_H
8 
9 #include "EigenUtil.h"
10 #include "SceneGraph.h"
11 #include "ValueTree.h"
12 #include <cnoid/stdx/filesystem>
13 #include "exportdecl.h"
14 
15 namespace cnoid {
16 
17 class YAMLReader;
18 class FilePathVariableProcessor;
19 
20 class CNOID_EXPORT StdSceneReader
21 {
22 public:
24  ~StdSceneReader();
25 
26  void setMessageSink(std::ostream& os);
27  void setDefaultDivisionNumber(int n);
28  int defaultDivisionNumber() const;
29 
30  // One of the settings is valid for the following two functions
31  void setBaseDirectory(const std::string& directory);
32  void setFilePathVariableProcessor(FilePathVariableProcessor* processor);
33 
34  std::string baseDirectory() const;
35  stdx::filesystem::path baseDirPath() const;
36  void setYAMLReader(YAMLReader* reader);
37  void clear();
38  void readHeader(Mapping* info);
39  void readHeader(Mapping* info, double formatVersion);
40 
41  enum AngleUnit { DEGREE, RADIAN };
42  void setAngleUnit(AngleUnit unit);
43  bool isDegreeMode() const {
44  return isDegreeMode_;
45  }
46  double toRadian(double angle) const {
47  return isDegreeMode_ ? radian(angle) : angle;
48  }
49  float toRadian(float angle) const {
50  return isDegreeMode_ ? radian(angle) : angle;
51  }
52 
53  bool readAngle(const Mapping* info, const char* key, double& angle) const;
54  bool readAngle(const Mapping* info, std::initializer_list<const char*> keys, double& angle) const;
55  bool readAngle(const Mapping* info, const char* key, float& angle) const;
56  bool readAngle(const Mapping* info, std::initializer_list<const char*> keys, float& angle) const;
57  bool readRotation(const Mapping* info, Matrix3& out_R) const;
58  bool readRotation(const Mapping* info, const char* key, Matrix3& out_R) const;
59  bool readRotation(const Mapping* info, std::initializer_list<const char*> keys, Matrix3& out_R) const;
60  bool extractRotation(Mapping* info, Matrix3& out_R) const;
61  bool readTranslation(const Mapping* info, Vector3& out_p) const;
62  bool readTranslation(const Mapping* info, const char* key, Vector3& out_p) const;
63  bool extractTranslation(Mapping* info, Vector3& out_p) const;
64  SgNode* readNode(Mapping* info);
65  SgNode* readNode(Mapping* info, const std::string& type);
66  SgNode* readScene(ValueNode* scene);
67 
68  struct Resource {
71  std::string uri;
72  std::string directory;
73  std::string fragment;
74  };
75  Resource readResourceNode(Mapping* info);
76 
77  typedef std::function<std::string(const std::string& path, std::ostream& os)> UriSchemeHandler;
78 
79  static void registerUriSchemeHandler(const std::string& scheme, UriSchemeHandler handler);
80 
81  [[deprecated("Use readAngle(const Mapping* info, const char* key, double& angle) const")]]
82  bool readAngle(const Mapping& info, const char* key, double& angle) const;
83  [[deprecated("Use readAngle(const Mapping* info, const char* key, float& angle) const")]]
84  bool readAngle(const Mapping& info, const char* key, float& angle) const;
85  [[deprecated("Use readRotation(const Mapping* info, Matrix3& out_R) const")]]
86  bool readRotation(const Mapping& info, Matrix3& out_R) const;
87  [[deprecated("Use readRotation(const Mapping* info, const char* key, Matrix3& out_R) const")]]
88  bool readRotation(const Mapping& info, const char* key, Matrix3& out_R) const;
89  [[deprecated("Use extractRotation(Mapping* info, Matrix3& out_R) const")]]
90  bool extractRotation(Mapping& info, Matrix3& out_R) const;
91  [[deprecated("Use readTranslation(const Mapping* info, Vector3& out_p) const")]]
92  bool readTranslation(const Mapping& info, Vector3& out_p) const;
93  [[deprecated("Use readTranslation(const Mapping* info, const char* key, Vector3& out_p) const")]]
94  bool readTranslation(const Mapping& info, const char* key, Vector3& out_p) const;
95  [[deprecated("Use extractTranslation(Mapping* info, Vector3& out_p) const")]]
96  bool extractTranslation(Mapping& info, Vector3& out_p) const;
97  [[deprecated("Use readNode(Mapping* info)")]]
98  SgNode* readNode(Mapping& info);
99  [[deprecated("Use readNode(Mapping* info, const std::string& type)")]]
100  SgNode* readNode(Mapping& info, const std::string& type);
101  [[deprecated("Use readResourceNode(Mapping* info)")]]
102  Resource readResourceNode(Mapping& info);
103 
104 private:
105  class Impl;
106  Impl* impl;
107 
108  bool isDegreeMode_;
109 };
110 
111 }
112 
113 #endif
cnoid::YAMLReader
Definition: YAMLReader.h:15
cnoid::Mapping
Definition: ValueTree.h:253
EigenUtil.h
cnoid::Vector3
Eigen::Vector3d Vector3
Definition: EigenTypes.h:57
cnoid::StdSceneReader::Resource::fragment
std::string fragment
Definition: StdSceneReader.h:73
cnoid::StdSceneReader::Resource::uri
std::string uri
Definition: StdSceneReader.h:71
cnoid::StdSceneReader::AngleUnit
AngleUnit
Definition: StdSceneReader.h:41
cnoid::ValueNode
Definition: ValueTree.h:34
cnoid::StdSceneReader::Resource::info
ValueNodePtr info
Definition: StdSceneReader.h:70
cnoid::Matrix3
Eigen::Matrix3d Matrix3
Definition: EigenTypes.h:56
ValueTree.h
cnoid::ref_ptr< SgNode >
cnoid::radian
Vector3 radian(const Vector3 &v)
Definition: EigenUtil.h:16
cnoid::StdSceneReader::Resource::directory
std::string directory
Definition: StdSceneReader.h:72
cnoid::StdSceneReader::UriSchemeHandler
std::function< std::string(const std::string &path, std::ostream &os)> UriSchemeHandler
Definition: StdSceneReader.h:77
cnoid::FilePathVariableProcessor
Definition: FilePathVariableProcessor.h:18
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::StdSceneReader::isDegreeMode
bool isDegreeMode() const
Definition: StdSceneReader.h:43
cnoid::StdSceneReader::toRadian
double toRadian(double angle) const
Definition: StdSceneReader.h:46
cnoid::StdSceneReader::toRadian
float toRadian(float angle) const
Definition: StdSceneReader.h:49
cnoid::StdSceneReader::Resource::scene
SgNodePtr scene
Definition: StdSceneReader.h:69
SceneGraph.h
cnoid::SgNode
Definition: SceneGraph.h:157
cnoid::StdSceneReader
Definition: StdSceneReader.h:20
cnoid::StdSceneReader::Resource
Definition: StdSceneReader.h:68