41 m_structure(structure),
42 m_buildSpec(buildSpec)
44 createTree(*
this, structure);
50 m_structure(structure),
51 m_buildSpec(buildSpec)
53 createTree(*
this, structure);
56 tgStructureInfo::~tgStructureInfo()
59 for (std::size_t i = 0; i < m_compounded.size(); i++)
61 const tgRigidInfo *
const pRigidInfo = m_compounded[i];
62 assert(pRigidInfo != NULL);
71 for (std::size_t i = 0; i < m_rigids.size(); i++)
76 for (std::size_t i = 0; i < m_connectors.size(); i++)
78 delete m_connectors[i];
81 for (std::size_t i = 0; i < m_children.size(); i++)
90 const std::vector<tgStructure*> children = structure.
getChildren();
91 for (
int i = 0; i < children.size(); i++)
94 assert(pStructure != NULL);
97 structureInfo.addChild(pStructureInfo);
98 createTree(*pStructureInfo, *pStructure);
102 std::vector<tgRigidInfo*> tgStructureInfo::getAllRigids()
const
104 std::vector<tgRigidInfo*> result;
105 result.insert(result.end(), m_rigids.begin(), m_rigids.end());
108 for (
int i = 0; i < m_children.size(); i++)
111 assert(pStructureInfo != NULL);
112 std::vector<tgRigidInfo*> childRigids = pStructureInfo->getAllRigids();
113 result.insert(result.end(), childRigids.begin(), childRigids.end());
123 void tgStructureInfo::initRigidInfo()
127 const std::vector<tgBuildSpec::RigidAgent*> rigidAgents = m_buildSpec.getRigidAgents();
129 for (
int i = 0; i < rigidAgents.size(); i++)
132 assert(pRigidAgent != NULL);
139 tagSearch.
remove(getTags());
141 tgRigidInfo* pRigidInfo = pRigidAgent->infoFactory;
142 assert(pRigidInfo != NULL);
145 std::vector<tgRigidInfo*> nodeRigids =
146 pRigidInfo->createRigidInfos(m_structure.
getNodes(), tagSearch);
147 m_rigids.insert(m_rigids.end(), nodeRigids.begin(), nodeRigids.end());
150 std::vector<tgRigidInfo*> pairRigids =
151 pRigidInfo->createRigidInfos(m_structure.
getPairs(), tagSearch);
152 m_rigids.insert(m_rigids.end(), pairRigids.begin(), pairRigids.end());
157 for (
int i = 0; i < m_children.size(); i++)
161 assert(pStructureInfo != NULL);
162 pStructureInfo->initRigidInfo();
166 void tgStructureInfo::autoCompoundRigids()
169 m_compounded = c.execute();
172 void tgStructureInfo::initConnectorInfo()
177 const std::vector<tgBuildSpec::ConnectorAgent*> connectorAgents =
178 m_buildSpec.getConnectorAgents();
180 for (
int i = 0; i < connectorAgents.size(); i++)
183 assert(pConnectorAgent != NULL);
190 tagSearch.
remove(getTags());
193 assert(pConnectorInfo != NULL);
198 std::vector<tgConnectorInfo*> pairConnectors =
199 pConnectorInfo->createConnectorInfos(m_structure.
getPairs(), tagSearch);
200 m_connectors.insert(m_connectors.end(), pairConnectors.begin(),
201 pairConnectors.end());
206 for (
int i = 0; i < m_children.size(); i++)
209 assert(pStructureInfo != NULL);
210 pStructureInfo->initConnectorInfo();
214 void tgStructureInfo::chooseConnectorRigids()
216 chooseConnectorRigids(getAllRigids());
219 void tgStructureInfo::chooseConnectorRigids(std::vector<tgRigidInfo*> allRigids)
221 for (
int i = 0; i < m_connectors.size(); i++)
224 assert(pConnectorInfo != NULL);
225 pConnectorInfo->chooseRigids(allRigids);
229 for (
int i = 0; i < m_children.size(); i++)
232 assert(pStructureInfo != NULL);
233 pStructureInfo->chooseConnectorRigids(allRigids);
237 void tgStructureInfo::initRigidBodies(
tgWorld& world)
240 for (
int i = 0; i < m_rigids.size(); i++)
243 assert(pRigidInfo != NULL);
244 pRigidInfo->initRigidBody(world);
248 for (
int i = 0; i < m_children.size(); i++)
251 assert(pStructureInfo != NULL);
252 pStructureInfo->initRigidBodies(world);
256 void tgStructureInfo::initConnectors(
tgWorld& world)
259 for (
int i = 0; i < m_connectors.size(); i++)
262 assert(pConnectorInfo != NULL);
263 pConnectorInfo->initConnector(world);
267 for (
int i = 0; i < m_children.size(); i++)
270 assert(pStructureInfo != NULL);
271 pStructureInfo->initConnectors(world);
279 autoCompoundRigids();
281 chooseConnectorRigids();
282 initRigidBodies(world);
285 initConnectors(world);
287 buildIntoHelper(model, world, *
this);
290 void tgStructureInfo::buildIntoHelper(
tgModel& model,
tgWorld& world,
294 const std::vector<tgRigidInfo*> rigids = structureInfo.getRigids();
295 for (
int i = 0; i < rigids.size(); i++)
298 assert(pRigidInfo != NULL);
299 tgModel*
const pModel = pRigidInfo->createModel(world);
302 pModel->setTags(pRigidInfo->getTags());
307 const std::vector<tgConnectorInfo*> connectors = structureInfo.getConnectors();
308 for (
int i = 0; i < connectors.size(); i++)
311 assert(pConnectorInfo != NULL);
312 tgModel*
const pModel = pConnectorInfo->createModel(world);
315 pModel->setTags(pConnectorInfo->getTags());
320 const std::vector<tgStructureInfo*> children = structureInfo.getChildren();
321 for (
int i = 0; i < children.size(); i++)
324 assert(pStructureInfo != NULL);
326 assert(pModel != NULL);
327 buildIntoHelper(*pModel, world, *pStructureInfo);
331 model.setTags(structureInfo.getTags());
338 throw std::invalid_argument(
"Child is NULL");
342 m_children.push_back(pChild);
346 std::string tgStructureInfo::toString(
const std::string& prefix)
const
349 std::ostringstream os;
350 os << prefix <<
"tgStructureInfo(" << std::endl;
352 os << prefix << p <<
"Rigids:" << std::endl;
353 for (
int i = 0; i < m_rigids.size(); i++) {
354 os << prefix << p << p << *(m_rigids[i]) << std::endl;
357 os << prefix << p <<
"Connectors:" << std::endl;
358 for (
int i = 0; i < m_connectors.size(); i++) {
359 os << prefix << p << p << *(m_connectors[i]) << std::endl;
362 os << prefix << p <<
"Children:" << std::endl;
363 for (
int i = 0; i < m_children.size(); i++) {
364 os << m_children[i]->toString(prefix + p + p) << std::endl;
367 os << prefix << p <<
"Tags: [" << getTags() <<
"]" << std::endl;
369 os << prefix <<
")" << std::endl;
376 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 tgBuildSpec.
Definition of class tgRigidAutoCompound.