NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgStructureInfo.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2012, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
6  * The NASA Tensegrity Robotics Toolkit (NTRT) v1 platform is licensed
7  * under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * http://www.apache.org/licenses/LICENSE-2.0.
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
15  * either express or implied. See the License for the specific language
16  * governing permissions and limitations under the License.
17 */
18 
27 #ifndef TG_STRUCTURE_INFO_H
28 #define TG_STRUCTURE_INFO_H
29 
30 // This library
31 #include "tgBuildSpec.h"
32 // NTRT Core library
33 #include "core/tgTaggable.h"
34 // The C++ Standard Library
35 #include <iostream>
36 #include <vector>
37 
38 // Forward declarations
39 class tgBuildSpec;
40 class tgConnectorInfo;
41 class tgModel;
42 class tgRigidInfo;
43 class tgStructure;
44 class tgWorld;
45 
51 {
52 
53  friend std::ostream& operator<<(std::ostream& os, const tgStructureInfo& obj);
54 
55 public:
56 
57  tgStructureInfo(tgStructure& structure, tgBuildSpec& buildSpec);
58 
59  tgStructureInfo(tgStructure& structure, tgBuildSpec& buildSpec, const tgTags& tags);
60 
61  virtual ~tgStructureInfo();
62 
63  // Return all rigids in this structure and its descendants
64  std::vector<tgRigidInfo*> getAllRigids() const;
65 
66  const std::vector<tgConnectorInfo*>& getConnectors() const
67  {
68  return m_connectors;
69  }
70 
71  // Build our info into the provided model
72  void buildInto(tgModel& model, tgWorld& world);
73 
74 private:
75 
76  /*
77  * Initialize all the rigidInfo and connectorInfo objects for this structureInfo and all of its children
78  */
79  void addRigidsAndConnectors();
80 
81  /*
82  * Create and return a rigidInfo object using a matching rigidAgent
83  */
84  template <class T>
85  tgRigidInfo* initRigidInfo(const T& rigidCandidate, const std::vector<tgBuildSpec::RigidAgent*>& rigidAgents) const;
86 
87  /*
88  * Create and return a connectorInfo object using a matching connectorAgent
89  */
90  template <class T>
91  tgConnectorInfo* initConnectorInfo(const T& connectorCandidate, const std::vector<tgBuildSpec::ConnectorAgent*>& connectorAgents) const;
92 
93  void autoCompoundRigids();
94 
95  void chooseConnectorRigids();
96 
97  void chooseConnectorRigids(std::vector<tgRigidInfo*> allRigids);
98 
99  void initRigidBodies(tgWorld& world);
100 
101  void initConnectors(tgWorld& world);
102 
103  const std::vector<tgRigidInfo*>& getRigids() const
104  {
105  return m_rigids;
106  }
107 
108  void addChild(tgStructureInfo* pChild);
109 
110  const std::vector<tgStructureInfo*>& getChildren() const
111  {
112  return m_children;
113  }
114 
118  void createTree(tgStructureInfo& scaffold, const tgStructure& structure);
119 
120  void buildIntoHelper(tgModel& model, tgWorld& world, tgStructureInfo& structureInfo);
121 
122  std::string toString(const std::string& prefix = "") const;
123 
124 private:
125 
126  tgStructure& m_structure;
127 
128  tgBuildSpec& m_buildSpec;
129 
130  // We do own these
131  std::vector<tgRigidInfo*> m_rigids;
132 
133  std::vector<tgConnectorInfo*> m_connectors;
134 
135  std::vector<tgStructureInfo*> m_children;
136 
137  std::vector<tgRigidInfo*> m_compounded;
138 };
139 
147 std::ostream& operator<<(std::ostream& os, const tgStructureInfo& obj);
148 
149 #endif
friend std::ostream & operator<<(std::ostream &os, const tgStructureInfo &obj)
Contains the definition of class tgTaggable.
std::ostream & operator<<(std::ostream &os, const tgStructureInfo &obj)
Definition of class tgBuildSpec.
Definition: tgTags.h:44
void buildInto(tgModel &model, tgWorld &world)