Skip to content

Commit

Permalink
Improved SDF GetElement. Added SDF2POV tool. Fixed RecalculateNormals…
Browse files Browse the repository at this point in the history
… to make objects smooth.
  • Loading branch information
nkoenig committed Nov 14, 2011
1 parent 9eaf0a2 commit ea54b56
Show file tree
Hide file tree
Showing 14 changed files with 474 additions and 34 deletions.
3 changes: 2 additions & 1 deletion sdf/worlds/pr2.world
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
</link>
</model>

<include filename="pr2.model"/>
<!--<include filename="pr2.model" />-->
<include filename="pr2.model" model_pose="0 0 0 0 0 3.1415"/>

<light type="directional" name="sun" cast_shadows="true">
<origin pose="0 0 10 0 0 0"/>
Expand Down
2 changes: 1 addition & 1 deletion src/Server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ bool Server::Load(const std::string &_filename)
gzthrow("Failed to load the World\n" << e);
}

worldElem = sdf->root->GetNextElement("world", worldElem);
worldElem = worldElem->GetNextElement();
}

return true;
Expand Down
13 changes: 10 additions & 3 deletions src/common/Mesh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -669,9 +669,16 @@ void SubMesh::RecalculateNormals()
math::Vector3 v2 = this->vertices[this->indices[i+1]];
math::Vector3 v3 = this->vertices[this->indices[i+2]];
math::Vector3 n = math::Vector3::GetNormal(v1, v2, v3);
this->normals[this->indices[i]] += n;
this->normals[this->indices[i+1]] += n;
this->normals[this->indices[i+2]] += n;

for (unsigned int j=0; j< this->vertices.size(); j++)
{
if (this->vertices[j] == v1 ||
this->vertices[j] == v2 ||
this->vertices[j] == v3)
{
this->normals[j] += n;
}
}
}

// Normalize the results
Expand Down
4 changes: 2 additions & 2 deletions src/gui/InsertModelWidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ void InsertModelWidget::OnModelSelection(QTreeWidgetItem *_item, int /*_column*/
this->visuals.push_back(visVisual);


visualElem = linkElem->GetNextElement("visual", visualElem);
visualElem = visualElem->GetNextElement();
}

linkElem = modelElem->GetNextElement("link", linkElem);
linkElem = linkElem->GetNextElement();
}

msgs::Selection selectMsg;
Expand Down
10 changes: 5 additions & 5 deletions src/physics/Link.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void Link::Load( sdf::ElementPtr &_sdf )
this->visPub->Publish(msg);
this->visuals.push_back(msg.name());

visualElem = this->sdf->GetNextElement("visual", visualElem);
visualElem = visualElem->GetNextElement();
}
}

Expand All @@ -135,7 +135,7 @@ void Link::Load( sdf::ElementPtr &_sdf )
{
// Create and Load a collision, which will belong to this body.
this->LoadCollision(collisionElem);
collisionElem = this->sdf->GetNextElement("collision", collisionElem);
collisionElem = collisionElem->GetNextElement();
}
}

Expand All @@ -145,7 +145,7 @@ void Link::Load( sdf::ElementPtr &_sdf )
while (sensorElem)
{
this->LoadSensor(sensorElem);
sensorElem = this->sdf->GetNextElement("sensor", sensorElem);
sensorElem = sensorElem->GetNextElement();
}
}
}
Expand Down Expand Up @@ -294,7 +294,7 @@ void Link::UpdateParameters( sdf::ElementPtr &_sdf )

this->visPub->Publish(msg);

visualElem = this->sdf->GetNextElement("visual", visualElem);
visualElem = visualElem->GetNextElement();
}
}

Expand All @@ -308,7 +308,7 @@ void Link::UpdateParameters( sdf::ElementPtr &_sdf )

if (collision)
collision->UpdateParameters(collisionElem);
collisionElem = this->sdf->GetNextElement("collision", collisionElem);
collisionElem = collisionElem->GetNextElement();
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/physics/Model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void Model::Load( sdf::ElementPtr &_sdf )
// bodies collisionetries
link->Load(linkElem);

linkElem = _sdf->GetNextElement("link", linkElem);
linkElem = linkElem->GetNextElement();
}
}

Expand All @@ -122,7 +122,7 @@ void Model::Load( sdf::ElementPtr &_sdf )
while (jointElem)
{
this->LoadJoint(jointElem);
jointElem = _sdf->GetNextElement("joint", jointElem);
jointElem = jointElem->GetNextElement();
}
}

Expand All @@ -133,7 +133,7 @@ void Model::Load( sdf::ElementPtr &_sdf )
while (pluginElem)
{
this->LoadPlugin(pluginElem);
pluginElem = _sdf->GetNextElement("plugin", pluginElem);
pluginElem = pluginElem->GetNextElement();
}
}
}
Expand Down Expand Up @@ -304,7 +304,7 @@ void Model::UpdateParameters( sdf::ElementPtr &_sdf )
LinkPtr link = boost::shared_dynamic_cast<Link>(
this->GetChild(linkElem->GetValueString("name")));
link->UpdateParameters(linkElem);
linkElem = _sdf->GetNextElement("link", linkElem);
linkElem = linkElem->GetNextElement();
}
}
/*
Expand All @@ -316,7 +316,7 @@ void Model::UpdateParameters( sdf::ElementPtr &_sdf )
{
JointPtr joint = boost::shared_dynamic_cast<Joint>(this->GetChild(jointElem->GetValueString("name")));
joint->UpdateParameters(jointElem);
jointElem = _sdf->GetNextElement("joint", jointElem);
jointElem = jointElem->GetNextElement();
}
}
*/
Expand Down
6 changes: 3 additions & 3 deletions src/physics/World.cc
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ void World::LoadEntities( sdf::ElementPtr &_sdf, BasePtr _parent )
msgs::Light *lm = this->sceneMsg.add_light();
lm->CopyFrom( msgs::LightFromSDF(childElem) );

childElem = _sdf->GetNextElement("light", childElem);
childElem = childElem->GetNextElement();
}
}

Expand All @@ -453,7 +453,7 @@ void World::LoadEntities( sdf::ElementPtr &_sdf, BasePtr _parent )
// TODO : Put back in the ability to nest models. We should do this
// without requiring a joint.

childElem = _sdf->GetNextElement("model", childElem);
childElem = childElem->GetNextElement();
}
}

Expand All @@ -464,7 +464,7 @@ void World::LoadEntities( sdf::ElementPtr &_sdf, BasePtr _parent )
while (pluginElem)
{
this->LoadPlugin(pluginElem);
pluginElem = _sdf->GetNextElement("plugin", pluginElem);
pluginElem = pluginElem->GetNextElement();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/physics/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void Load()
gzthrow("Failed to load the World\n" << e);
}

worldElem = sdf->root->GetNextElement("world", worldElem);
worldElem = worldElem->GetNextElement();
}

gazebo::physics::init_worlds();
Expand Down
28 changes: 20 additions & 8 deletions src/sdf/interface/SDF.cc
Original file line number Diff line number Diff line change
Expand Up @@ -428,21 +428,33 @@ ElementPtr Element::GetFirstElement() const
return this->elements.front();
}

ElementPtr Element::GetNextElement(const std::string &_name,
const ElementPtr &_elem) const
ElementPtr Element::GetNextElement(const std::string &_name) const
{
ElementPtr_V::const_iterator iter;
iter = std::find(this->elements.begin(), this->elements.end(), _elem);

for (iter++; iter != this->elements.end(); iter++)
if (this->parent)
{
if ( (*iter)->GetName() == _name )
return (*iter);
ElementPtr_V::const_iterator iter;
iter = std::find(this->parent->elements.begin(),
this->parent->elements.end(), shared_from_this());

if (iter == this->parent->elements.end())
return ElementPtr();

for (iter++; iter != this->parent->elements.end(); iter++)
{
if ( (*iter)->GetName() == _name )
return (*iter);
}
}

return ElementPtr();
}

ElementPtr Element::GetNextElement() const
{
return this->GetNextElement(this->name);
}


boost::shared_ptr<Element> Element::GetOrCreateElement(const std::string &_name)
{
if (this->HasElement(_name))
Expand Down
6 changes: 4 additions & 2 deletions src/sdf/interface/SDF.hh
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@ namespace sdf

public: ElementPtr GetElement(const std::string &_name) const;
public: ElementPtr GetFirstElement() const;
public: ElementPtr GetNextElement(const std::string &_name,
const ElementPtr &_elem) const;

public: ElementPtr GetNextElement(const std::string &_name) const;
public: ElementPtr GetNextElement() const;


public: ElementPtr GetOrCreateElement(const std::string &_name);
public: ElementPtr AddElement(const std::string &_name);
Expand Down
3 changes: 1 addition & 2 deletions src/sensors/ContactSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ void ContactSensor::Load()
this->connections.push_back(collision->ConnectContact(
boost::bind(&ContactSensor::OnContact, this, _1, _2)));
}
collisionElem = this->sdf->GetElement("contact")->GetNextElement(
"collision", collisionElem);
collisionElem = collisionElem->GetNextElement();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/sensors/Sensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void Sensor::Init()
while (pluginElem)
{
this->LoadPlugin(pluginElem);
pluginElem = this->sdf->GetNextElement("plugin", pluginElem);
pluginElem = pluginElem->GetNextElement();
}
}
//SensorManager::Instance()->AddSensor(shared_from_this());
Expand Down
4 changes: 4 additions & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ add_executable( gzstats gzstats.cc )
target_link_libraries(gzstats gazebo_msgs gazebo_common gazebo_transport )
INSTALL_EXECUTABLE( gzstats )

add_executable( sdf2pov sdf2pov.cc )
target_link_libraries(sdf2pov gazebo_common gazebo_sdf_parser)
INSTALL_EXECUTABLE( sdf2pov )

Loading

0 comments on commit ea54b56

Please sign in to comment.