Choreonoid  1.8
SceneNodeExtractor.h
Go to the documentation of this file.
1 #ifndef CNOID_UTIL_SCENE_NODE_EXTRACTOR_H
2 #define CNOID_UTIL_SCENE_NODE_EXTRACTOR_H
3 
4 #include "SceneGraph.h"
5 #include <functional>
6 #include "exportdecl.h"
7 
8 namespace cnoid {
9 
10 class CNOID_EXPORT SceneNodeExtractor
11 {
12 public:
13  template<class NodeType>
14  SgNodePath extractNode(SgNode* root, bool includeRoot = true){
15  extractNode_(
16  root,
17  [](SgNode* node){
18  if(dynamic_cast<NodeType*>(node)){
19  return true;
20  }
21  return false;
22  },
23  includeRoot);
24  return std::move(nodePath_);
25  }
26 
27  template<class NodeType>
28  std::vector<SgNodePath> extractNodes(SgNode* root, bool includeRoot = true){
29  extractNodes_(
30  root,
31  [](SgNode* node){
32  if(dynamic_cast<NodeType*>(node)){
33  return true;
34  }
35  return false;
36  },
37  includeRoot);
38  return std::move(nodePathList_);
39  }
40 
41 private:
42  void extractNode_(SgNode* root, std::function<bool(SgNode* node)> pred, bool includeRoot);
43  void extractNodes_(SgNode* root, std::function<bool(SgNode* node)> pred, bool includeRoot);
44  bool extractNodesIter(SgNode* node, const std::function<bool(SgNode* node)>& pred, bool extractMultiplePaths);
45 
46  SgNodePath nodePath_;
47  std::vector<SgNodePath> nodePathList_;
48 };
49 
50 }
51 
52 #endif
cnoid::SceneNodeExtractor
Definition: SceneNodeExtractor.h:10
cnoid::SceneNodeExtractor::extractNodes
std::vector< SgNodePath > extractNodes(SgNode *root, bool includeRoot=true)
Definition: SceneNodeExtractor.h:28
cnoid
Definition: AbstractSceneLoader.h:11
SceneGraph.h
cnoid::SgNodePath
std::vector< SgNode * > SgNodePath
Definition: SceneGraph.h:24
cnoid::SceneNodeExtractor::extractNode
SgNodePath extractNode(SgNode *root, bool includeRoot=true)
Definition: SceneNodeExtractor.h:14
cnoid::SgNode
Definition: SceneGraph.h:157