File size: 3,172 Bytes
2c55b92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2021 DeepMind Technologies Limited
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef THIRD_PARTY_MUJOCO_SRC_XML_XML_URDF_
#define THIRD_PARTY_MUJOCO_SRC_XML_XML_URDF_

#include <map>
#include <string>
#include <unordered_set>
#include <vector>

#include <mujoco/mjmodel.h>
#include <mujoco/mjspec.h>
#include "xml/xml_base.h"
#include "tinyxml2.h"

// rgb data
typedef struct _mjRGBA {
  float val[4];
} mjRGBA;

// XML parser for URDF files
class mjXURDF : public mjXBase {
 public:
  mjXURDF();                                          // constructor
  virtual ~mjXURDF();                                 // destructor

  // parse and set frame of base link and append a prefix to the name
  void Parse(
      tinyxml2::XMLElement* root,
      const std::string& prefix,
      double* pos,
      double* quat,
      bool static_body);
  void Parse(tinyxml2::XMLElement* root, const mjVFS* vfs = nullptr);  // main parser

 private:
  std::string GetPrefixedName(const std::string& name);            // get prefix/name of element
  int FindName(std::string name, std::vector<std::string>& list);  // find name in list
  void AddName(std::string name, std::vector<std::string>& list);  // add name to list
  void AddBody(std::string name);                                  // add body to local table
  void AddToTree(int n);                                           // add body to mjCModel tree
  void Body(tinyxml2::XMLElement* body_elem);                      // parse body
  void Joint(tinyxml2::XMLElement* joint_elem);                    // parse joint
  mjsGeom* Geom(tinyxml2::XMLElement* geom_elem,
                mjsBody* pbody, bool collision);      // parse origin and geometry of geom
  void Origin(tinyxml2::XMLElement* origin_elem, double* pos, double* quat); // parse origin element

  void MakeMaterials(tinyxml2::XMLElement* elem);     // find all materials recursively
  void Clear(void);                                   // clear local objects

  // URDF parser variables
  std::vector<std::string> urName;              // body name
  std::vector<int> urParent;                    // body parent (index in name vector)
  std::vector<std::vector<int> > urChildren;    // body children (index in name vector)
  std::vector<std::string> urMat;               // material name
  std::vector<mjRGBA> urRGBA;                   // material RBG value
  std::unordered_set<std::string> urGeomNames;  // geom name
  std::map<std::string, std::vector<mjsMesh*>> meshes;  // map from name to mjsMesh

  std::string urPrefix;                         // prefix to apply to all names
};

#endif  // THIRD_PARTY_MUJOCO_SRC_XML_XML_URDF_