40 m_structure(structure),
41 m_buildSpec(buildSpec)
43 createTree(*
this, structure);
49 m_structure(structure),
50 m_buildSpec(buildSpec)
52 createTree(*
this, structure);
55 tgStructureInfo::~tgStructureInfo()
58 for (std::size_t i = 0; i < m_compounded.size(); i++)
60 const tgRigidInfo *
const pRigidInfo = m_compounded[i];
61 assert(pRigidInfo != NULL);
70 for (std::size_t i = 0; i < m_rigids.size(); i++)
75 for (std::size_t i = 0; i < m_connectors.size(); i++)
77 delete m_connectors[i];
80 for (std::size_t i = 0; i < m_children.size(); i++)
89 const std::vector<tgStructure*> children = structure.
getChildren();
90 for (std::size_t i = 0; i < children.size(); i++)
93 assert(pStructure != NULL);
96 structureInfo.addChild(pStructureInfo);
100 std::vector<tgRigidInfo*> tgStructureInfo::getAllRigids()
const
102 std::vector<tgRigidInfo*> result;
103 result.insert(result.end(), m_rigids.begin(), m_rigids.end());
106 for (std::size_t i = 0; i < m_children.size(); i++)
109 assert(pStructureInfo != NULL);
110 std::vector<tgRigidInfo*> childRigids = pStructureInfo->getAllRigids();
111 result.insert(result.end(), childRigids.begin(), childRigids.end());
121 void tgStructureInfo::addRigidsAndConnectors() {
122 const std::vector<tgBuildSpec::RigidAgent*> rigidAgents = m_buildSpec.getRigidAgents();
123 const std::vector<tgBuildSpec::ConnectorAgent*> connectorAgents = m_buildSpec.getConnectorAgents();
129 for (
int i = 0; i < nodes.size(); i++) {
130 tgRigidInfo* nodeRigid = initRigidInfo<tgNode>(nodes[i], rigidAgents);
132 m_rigids.push_back(nodeRigid);
136 for (
int i = 0; i < pairs.size(); i++) {
137 tgRigidInfo* pairRigid = initRigidInfo<tgPair>(pairs[i], rigidAgents);
139 m_rigids.push_back(pairRigid);
142 tgConnectorInfo* pairConnector = initConnectorInfo<tgPair>(pairs[i], connectorAgents);
144 m_connectors.push_back(pairConnector);
150 for (std::size_t i = 0; i < m_children.size(); i++) {
153 assert(pStructureInfo != NULL);
154 pStructureInfo->addRigidsAndConnectors();
159 tgRigidInfo* tgStructureInfo::initRigidInfo(
const T& rigidCandidate,
const std::vector<tgBuildSpec::RigidAgent*>& rigidAgents)
const {
160 for (
int i = rigidAgents.size() - 1; i >= 0; i--) {
162 assert(pRigidAgent != NULL);
169 tagSearch.
remove(getTags());
171 tgRigidInfo* pRigidInfo = pRigidAgent->infoFactory;
172 assert(pRigidInfo != NULL);
174 tgRigidInfo* rigid = pRigidInfo->createRigidInfo(rigidCandidate, tagSearch);
183 tgConnectorInfo* tgStructureInfo::initConnectorInfo(
const T& connectorCandidate,
const std::vector<tgBuildSpec::ConnectorAgent*>& connectorAgents)
const {
184 for (
int i = connectorAgents.size() - 1; i >= 0; i--) {
186 assert(pConnectorAgent != NULL);
193 tagSearch.
remove(getTags());
196 assert(pConnectorInfo != NULL);
198 tgConnectorInfo* connector = pConnectorInfo->createConnectorInfo(connectorCandidate, tagSearch);
205 void tgStructureInfo::autoCompoundRigids()
208 m_compounded = c.execute();
211 void tgStructureInfo::chooseConnectorRigids()
213 chooseConnectorRigids(getAllRigids());
216 void tgStructureInfo::chooseConnectorRigids(std::vector<tgRigidInfo*> allRigids)
218 for (std::size_t i = 0; i < m_connectors.size(); i++)
221 assert(pConnectorInfo != NULL);
222 pConnectorInfo->chooseRigids(allRigids);
226 for (std::size_t i = 0; i < m_children.size(); i++)
229 assert(pStructureInfo != NULL);
230 pStructureInfo->chooseConnectorRigids(allRigids);
234 void tgStructureInfo::initRigidBodies(
tgWorld& world)
237 for (std::size_t i = 0; i < m_rigids.size(); i++)
240 assert(pRigidInfo != NULL);
241 pRigidInfo->initRigidBody(world);
245 for (std::size_t i = 0; i < m_children.size(); i++)
248 assert(pStructureInfo != NULL);
249 pStructureInfo->initRigidBodies(world);
253 void tgStructureInfo::initConnectors(
tgWorld& world)
256 for (std::size_t i = 0; i < m_connectors.size(); i++)
259 assert(pConnectorInfo != NULL);
260 pConnectorInfo->initConnector(world);
264 for (std::size_t i = 0; i < m_children.size(); i++)
267 assert(pStructureInfo != NULL);
268 pStructureInfo->initConnectors(world);
280 addRigidsAndConnectors();
281 autoCompoundRigids();
282 chooseConnectorRigids();
283 initRigidBodies(world);
286 initConnectors(world);
288 buildIntoHelper(model, world, *
this);
313 void tgStructureInfo::buildIntoHelper(
tgModel& model,
tgWorld& world,
317 const std::vector<tgRigidInfo*> rigids = structureInfo.getRigids();
318 for (std::size_t i = 0; i < rigids.size(); i++)
321 assert(pRigidInfo != NULL);
322 tgModel*
const pModel = pRigidInfo->createModel(world);
325 pModel->setTags(pRigidInfo->getTags());
330 const std::vector<tgConnectorInfo*> connectors = structureInfo.getConnectors();
331 for (std::size_t i = 0; i < connectors.size(); i++)
334 assert(pConnectorInfo != NULL);
335 tgModel*
const pModel = pConnectorInfo->createModel(world);
338 pModel->setTags(pConnectorInfo->getTags());
343 const std::vector<tgStructureInfo*> children = structureInfo.getChildren();
344 for (std::size_t i = 0; i < children.size(); i++)
347 assert(pStructureInfo != NULL);
349 assert(pModel != NULL);
350 buildIntoHelper(*pModel, world, *pStructureInfo);
354 model.setTags(structureInfo.getTags());
361 throw std::invalid_argument(
"Child is NULL");
365 m_children.push_back(pChild);
369 std::string tgStructureInfo::toString(
const std::string& prefix)
const
372 std::ostringstream os;
373 os << prefix <<
"tgStructureInfo(" << std::endl;
375 os << prefix << p <<
"Rigids:" << std::endl;
376 for (std::size_t i = 0; i < m_rigids.size(); i++) {
377 os << prefix << p << p << *(m_rigids[i]) << std::endl;
380 os << prefix << p <<
"Connectors:" << std::endl;
381 for (std::size_t i = 0; i < m_connectors.size(); i++) {
382 os << prefix << p << p << *(m_connectors[i]) << std::endl;
385 os << prefix << p <<
"Children:" << std::endl;
386 for (std::size_t i = 0; i < m_children.size(); i++) {
387 os << m_children[i]->toString(prefix + p + p) << std::endl;
390 os << prefix << p <<
"Tags: [" << getTags() <<
"]" << std::endl;
392 os << prefix <<
")" << std::endl;
399 os << obj.toString() << std::endl;
const std::vector< tgStructure * > & getChildren() const
void addChild(tgModel *pChild)
virtual tgRigidInfo * getRigidInfoGroup()
const tgNodes & getNodes() const
Contains the definition of class tgModel.
const tgPairs & getPairs() const
Definition of class tgConnectorInfo.
Contains the definition of class tgWorld $Id$.
Definition of class tgStructure.
Definition of class tgStructureInfo.
void remove(const tgTags &tags)
std::ostream & operator<<(std::ostream &os, const tgStructureInfo &obj)
Definition of class tgRigidAutoCompound.
void buildInto(tgModel &model, tgWorld &world)