DART  6.10.1
Worldbody.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2021, The DART development contributors
3  * All rights reserved.
4  *
5  * The list of contributors can be found at:
6  * https://github.com/dartsim/dart/blob/master/LICENSE
7  *
8  * This file is provided under the following "BSD-style" License:
9  * Redistribution and use in source and binary forms, with or
10  * without modification, are permitted provided that the following
11  * conditions are met:
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef DART_UTILS_MJCF_DETAIL_WORLDBODY_HPP_
34 #define DART_UTILS_MJCF_DETAIL_WORLDBODY_HPP_
35 
36 #include <string>
37 #include <vector>
38 
39 #include <tinyxml2.h>
40 
47 
48 namespace dart {
49 namespace utils {
50 namespace MjcfParser {
51 namespace detail {
52 
53 class Worldbody final
54 {
55 public:
57  Worldbody() = default;
58 
60  std::size_t getNumRootBodies() const;
61 
63  const Body& getRootBody(std::size_t index) const;
64 
66  std::size_t getNumGeoms() const;
67 
69  const Geom& getGeom(std::size_t index) const;
70 
72  std::size_t getNumSites() const;
73 
75  const Site& getSite(std::size_t index) const;
76 
77 private:
78  // Private memebers used by MujocoModel class
79  friend class MujocoModel;
80  Errors read(
81  tinyxml2::XMLElement* element,
82  const common::optional<Size>& size,
83  const Defaults& defaults,
84  const Default* currentDefault,
85  const common::Uri& baseUri,
86  const common::ResourceRetrieverPtr& retriever);
87 
89  Errors preprocess(const Compiler& compiler);
90 
93  Errors compile(const Compiler& compiler);
94 
96  Errors postprocess(const Compiler& compiler);
97 
98 private:
100  std::vector<Geom> mGeoms;
101  std::vector<Site> mSites;
102  std::vector<Body> mRootBodies;
103 };
104 
105 } // namespace detail
106 } // namespace MjcfParser
107 } // namespace utils
108 } // namespace dart
109 
110 #endif // #ifndef DART_UTILS_MJCF_DETAIL_WORLDBODY_HPP_
std::size_t index
Definition: SkelParser.cpp:1672
Main class to parse MJCF model file.
Definition: MujocoModel.hpp:56
Definition: Worldbody.hpp:54
std::vector< Geom > mGeoms
Definition: Worldbody.hpp:100
Worldbody()=default
Default constructor.
const Body & getRootBody(std::size_t index) const
Returns a root <body> elements at index in <worldbody>.
Definition: Worldbody.cpp:225
Errors compile(const Compiler &compiler)
Updates attributes and elements that require the preprocessed child elements of this <worldbody>.
Definition: Worldbody.cpp:155
const Geom & getGeom(std::size_t index) const
Returns a root <geom> element at index in <worldbody>.
Definition: Worldbody.cpp:201
std::vector< Body > mRootBodies
Definition: Worldbody.hpp:102
const Site & getSite(std::size_t index) const
Returns a root <site> element at index in <worldbody>.
Definition: Worldbody.cpp:213
common::optional< std::string > mChildClass
Definition: Worldbody.hpp:99
std::size_t getNumSites() const
Returns the number of <site> elements in <worldbody>.
Definition: Worldbody.cpp:207
Errors preprocess(const Compiler &compiler)
Updates attributes and elements that doesn't require any other elements.
Definition: Worldbody.cpp:135
Errors postprocess(const Compiler &compiler)
Updates attributes and elements that require the compiled parent element.
Definition: Worldbody.cpp:175
std::size_t getNumGeoms() const
Returns the number of <geom> elements in <worldbody>.
Definition: Worldbody.cpp:195
std::vector< Site > mSites
Definition: Worldbody.hpp:101
Errors read(tinyxml2::XMLElement *element, const common::optional< Size > &size, const Defaults &defaults, const Default *currentDefault, const common::Uri &baseUri, const common::ResourceRetrieverPtr &retriever)
Definition: Worldbody.cpp:46
std::size_t getNumRootBodies() const
Returns the number of root <body> elements in <worldbody>.
Definition: Worldbody.cpp:219
std::shared_ptr< ResourceRetriever > ResourceRetrieverPtr
Definition: ResourceRetriever.hpp:76
boost::optional< T > optional
Definition: Optional.hpp:50
std::vector< Error > Errors
Definition: Error.hpp:85
Definition: BulletCollisionDetector.cpp:65
The Uri struct provides URI parsing and merging functionality based on RFC 3986.
Definition: Uri.hpp:87