Do a few cleanup tasks in collada_urdf (#183)
* Style cleanup within collada_urdf. No functional change, just style. Signed-off-by: Chris Lalancette <clalancette@osrfoundation.org> * Make sure to quit out of urdf_to_collada when invalid file is found. Otherwise, we'll just end up segfaulting later on. Signed-off-by: Chris Lalancette <clalancette@osrfoundation.org> * Re-enable one of the collada-urdf tests. In point of fact, we delete the rest of the tests because they don't make much sense anymore. Just enable this one for now; we'll enable further ones in the future. Signed-off-by: Chris Lalancette <clalancette@osrfoundation.org> * Add in another test for collada_urdf. Signed-off-by: Chris Lalancette <clalancette@osrfoundation.org>
This commit is contained in:
parent
fc71f00e33
commit
4d03177186
|
@ -75,8 +75,8 @@ set_target_properties(collada_to_urdf PROPERTIES COMPILER_FLAGS "${ASSIMP_CXX_FL
|
||||||
set_target_properties(collada_to_urdf PROPERTIES LINK_FLAGS "${ASSIMP_LINK_FLAGS}")
|
set_target_properties(collada_to_urdf PROPERTIES LINK_FLAGS "${ASSIMP_LINK_FLAGS}")
|
||||||
|
|
||||||
if(CATKIN_ENABLE_TESTING)
|
if(CATKIN_ENABLE_TESTING)
|
||||||
catkin_add_gtest(test_collada_writer test/test_collada_urdf.cpp)
|
catkin_add_gtest(test_collada_urdf test/test_collada_urdf.cpp WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/test)
|
||||||
target_link_libraries(test_collada_writer ${PROJECT_NAME} ${catkin_LIBRARIES} ${COLLADA_DOM_LIBRARIES}
|
target_link_libraries(test_collada_urdf ${PROJECT_NAME} ${catkin_LIBRARIES} ${COLLADA_DOM_LIBRARIES}
|
||||||
${Boost_LIBRARIES})
|
${Boost_LIBRARIES})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
|
@ -949,17 +949,17 @@ protected:
|
||||||
|
|
||||||
// Declare all the joints
|
// Declare all the joints
|
||||||
_mapjointindices.clear();
|
_mapjointindices.clear();
|
||||||
int index=0;
|
int index = 0;
|
||||||
FOREACHC(itj, _robot.joints_) {
|
FOREACHC(itj, _robot.joints_) {
|
||||||
_mapjointindices[itj->second] = index++;
|
_mapjointindices[itj->second] = index++;
|
||||||
}
|
}
|
||||||
_maplinkindices.clear();
|
_maplinkindices.clear();
|
||||||
index=0;
|
index = 0;
|
||||||
FOREACHC(itj, _robot.links_) {
|
FOREACHC(itj, _robot.links_) {
|
||||||
_maplinkindices[itj->second] = index++;
|
_maplinkindices[itj->second] = index++;
|
||||||
}
|
}
|
||||||
_mapmaterialindices.clear();
|
_mapmaterialindices.clear();
|
||||||
index=0;
|
index = 0;
|
||||||
FOREACHC(itj, _robot.materials_) {
|
FOREACHC(itj, _robot.materials_) {
|
||||||
_mapmaterialindices[itj->second] = index++;
|
_mapmaterialindices[itj->second] = index++;
|
||||||
}
|
}
|
||||||
|
@ -980,8 +980,8 @@ protected:
|
||||||
pdomjoint->setName(pjoint->name.c_str());
|
pdomjoint->setName(pjoint->name.c_str());
|
||||||
domAxis_constraintRef axis;
|
domAxis_constraintRef axis;
|
||||||
if( !!pjoint->limits ) {
|
if( !!pjoint->limits ) {
|
||||||
lmin=pjoint->limits->lower;
|
lmin = pjoint->limits->lower;
|
||||||
lmax=pjoint->limits->upper;
|
lmax = pjoint->limits->upper;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
lmin = lmax = 0;
|
lmin = lmax = 0;
|
||||||
|
@ -993,8 +993,8 @@ protected:
|
||||||
case urdf::Joint::CONTINUOUS:
|
case urdf::Joint::CONTINUOUS:
|
||||||
axis = daeSafeCast<domAxis_constraint>(pdomjoint->add(COLLADA_ELEMENT_REVOLUTE));
|
axis = daeSafeCast<domAxis_constraint>(pdomjoint->add(COLLADA_ELEMENT_REVOLUTE));
|
||||||
fmult = 180.0f/M_PI;
|
fmult = 180.0f/M_PI;
|
||||||
lmin*=fmult;
|
lmin *= fmult;
|
||||||
lmax*=fmult;
|
lmax *= fmult;
|
||||||
break;
|
break;
|
||||||
case urdf::Joint::PRISMATIC:
|
case urdf::Joint::PRISMATIC:
|
||||||
axis = daeSafeCast<domAxis_constraint>(pdomjoint->add(COLLADA_ELEMENT_PRISMATIC));
|
axis = daeSafeCast<domAxis_constraint>(pdomjoint->add(COLLADA_ELEMENT_PRISMATIC));
|
||||||
|
@ -1165,48 +1165,49 @@ protected:
|
||||||
if( !!geometry ) {
|
if( !!geometry ) {
|
||||||
bool write_visual = false;
|
bool write_visual = false;
|
||||||
if ( !!plink->visual ) {
|
if ( !!plink->visual ) {
|
||||||
if (plink->visual_array.size() > 1) {
|
if (plink->visual_array.size() > 1) {
|
||||||
int igeom = 0;
|
int igeom = 0;
|
||||||
for (std::vector<urdf::VisualSharedPtr >::const_iterator it = plink->visual_array.begin();
|
for (std::vector<urdf::VisualSharedPtr >::const_iterator it = plink->visual_array.begin();
|
||||||
it != plink->visual_array.end(); it++) {
|
it != plink->visual_array.end(); it++) {
|
||||||
// geom
|
// geom
|
||||||
string geomid = _ComputeId(str(boost::format("g%s_%s_geom%d")%strModelUri%linksid%igeom));
|
string geomid = _ComputeId(str(boost::format("g%s_%s_geom%d")%strModelUri%linksid%igeom));
|
||||||
igeom++;
|
igeom++;
|
||||||
domGeometryRef pdomgeom;
|
domGeometryRef pdomgeom;
|
||||||
if ( it != plink->visual_array.begin() ) {
|
if ( it != plink->visual_array.begin() ) {
|
||||||
urdf::Pose org_trans = _poseMult(geometry_origin_inv, (*it)->origin);
|
urdf::Pose org_trans = _poseMult(geometry_origin_inv, (*it)->origin);
|
||||||
pdomgeom = _WriteGeometry((*it)->geometry, geomid, &org_trans);
|
pdomgeom = _WriteGeometry((*it)->geometry, geomid, &org_trans);
|
||||||
} else {
|
}
|
||||||
pdomgeom = _WriteGeometry((*it)->geometry, geomid);
|
else {
|
||||||
}
|
pdomgeom = _WriteGeometry((*it)->geometry, geomid);
|
||||||
domInstance_geometryRef pinstgeom = daeSafeCast<domInstance_geometry>(pnode->add(COLLADA_ELEMENT_INSTANCE_GEOMETRY));
|
}
|
||||||
pinstgeom->setUrl((string("#") + geomid).c_str());
|
domInstance_geometryRef pinstgeom = daeSafeCast<domInstance_geometry>(pnode->add(COLLADA_ELEMENT_INSTANCE_GEOMETRY));
|
||||||
// material
|
pinstgeom->setUrl((string("#") + geomid).c_str());
|
||||||
_WriteMaterial(pdomgeom->getID(), (*it)->material);
|
// material
|
||||||
domBind_materialRef pmat = daeSafeCast<domBind_material>(pinstgeom->add(COLLADA_ELEMENT_BIND_MATERIAL));
|
_WriteMaterial(pdomgeom->getID(), (*it)->material);
|
||||||
domBind_material::domTechnique_commonRef pmattec = daeSafeCast<domBind_material::domTechnique_common>(pmat->add(COLLADA_ELEMENT_TECHNIQUE_COMMON));
|
domBind_materialRef pmat = daeSafeCast<domBind_material>(pinstgeom->add(COLLADA_ELEMENT_BIND_MATERIAL));
|
||||||
domInstance_materialRef pinstmat = daeSafeCast<domInstance_material>(pmattec->add(COLLADA_ELEMENT_INSTANCE_MATERIAL));
|
domBind_material::domTechnique_commonRef pmattec = daeSafeCast<domBind_material::domTechnique_common>(pmat->add(COLLADA_ELEMENT_TECHNIQUE_COMMON));
|
||||||
pinstmat->setTarget(xsAnyURI(*pdomgeom, string("#")+geomid+string("_mat")));
|
domInstance_materialRef pinstmat = daeSafeCast<domInstance_material>(pmattec->add(COLLADA_ELEMENT_INSTANCE_MATERIAL));
|
||||||
pinstmat->setSymbol("mat0");
|
pinstmat->setTarget(xsAnyURI(*pdomgeom, string("#")+geomid+string("_mat")));
|
||||||
write_visual = true;
|
pinstmat->setSymbol("mat0");
|
||||||
}
|
write_visual = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!write_visual) {
|
if (!write_visual) {
|
||||||
// just 1 visual
|
// just 1 visual
|
||||||
int igeom = 0;
|
int igeom = 0;
|
||||||
string geomid = _ComputeId(str(boost::format("g%s_%s_geom%d")%strModelUri%linksid%igeom));
|
string geomid = _ComputeId(str(boost::format("g%s_%s_geom%d")%strModelUri%linksid%igeom));
|
||||||
domGeometryRef pdomgeom = _WriteGeometry(geometry, geomid);
|
domGeometryRef pdomgeom = _WriteGeometry(geometry, geomid);
|
||||||
domInstance_geometryRef pinstgeom = daeSafeCast<domInstance_geometry>(pnode->add(COLLADA_ELEMENT_INSTANCE_GEOMETRY));
|
domInstance_geometryRef pinstgeom = daeSafeCast<domInstance_geometry>(pnode->add(COLLADA_ELEMENT_INSTANCE_GEOMETRY));
|
||||||
pinstgeom->setUrl((string("#")+geomid).c_str());
|
pinstgeom->setUrl((string("#")+geomid).c_str());
|
||||||
|
|
||||||
// material
|
// material
|
||||||
_WriteMaterial(pdomgeom->getID(), material);
|
_WriteMaterial(pdomgeom->getID(), material);
|
||||||
domBind_materialRef pmat = daeSafeCast<domBind_material>(pinstgeom->add(COLLADA_ELEMENT_BIND_MATERIAL));
|
domBind_materialRef pmat = daeSafeCast<domBind_material>(pinstgeom->add(COLLADA_ELEMENT_BIND_MATERIAL));
|
||||||
domBind_material::domTechnique_commonRef pmattec = daeSafeCast<domBind_material::domTechnique_common>(pmat->add(COLLADA_ELEMENT_TECHNIQUE_COMMON));
|
domBind_material::domTechnique_commonRef pmattec = daeSafeCast<domBind_material::domTechnique_common>(pmat->add(COLLADA_ELEMENT_TECHNIQUE_COMMON));
|
||||||
domInstance_materialRef pinstmat = daeSafeCast<domInstance_material>(pmattec->add(COLLADA_ELEMENT_INSTANCE_MATERIAL));
|
domInstance_materialRef pinstmat = daeSafeCast<domInstance_material>(pmattec->add(COLLADA_ELEMENT_INSTANCE_MATERIAL));
|
||||||
pinstmat->setTarget(xsAnyURI(*pdomgeom, string("#")+geomid+string("_mat")));
|
pinstmat->setTarget(xsAnyURI(*pdomgeom, string("#")+geomid+string("_mat")));
|
||||||
pinstmat->setSymbol("mat0");
|
pinstmat->setSymbol("mat0");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1282,28 +1283,28 @@ protected:
|
||||||
switch (geometry->type) {
|
switch (geometry->type) {
|
||||||
case urdf::Geometry::MESH: {
|
case urdf::Geometry::MESH: {
|
||||||
urdf::Mesh* urdf_mesh = (urdf::Mesh*) geometry.get();
|
urdf::Mesh* urdf_mesh = (urdf::Mesh*) geometry.get();
|
||||||
cgeometry->setName(urdf_mesh->filename.c_str());
|
cgeometry->setName(urdf_mesh->filename.c_str());
|
||||||
_loadMesh(urdf_mesh->filename, cgeometry, urdf_mesh->scale, org_trans);
|
_loadMesh(urdf_mesh->filename, cgeometry, urdf_mesh->scale, org_trans);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case urdf::Geometry::SPHERE: {
|
case urdf::Geometry::SPHERE: {
|
||||||
shapes::Sphere sphere(static_cast<urdf::Sphere*>(geometry.get())->radius);
|
shapes::Sphere sphere(static_cast<urdf::Sphere*>(geometry.get())->radius);
|
||||||
boost::scoped_ptr<shapes::Mesh> mesh(shapes::createMeshFromShape(sphere));
|
boost::scoped_ptr<shapes::Mesh> mesh(shapes::createMeshFromShape(sphere));
|
||||||
_loadVertices(mesh.get(), cgeometry);
|
_loadVertices(mesh.get(), cgeometry);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case urdf::Geometry::BOX: {
|
case urdf::Geometry::BOX: {
|
||||||
shapes::Box box(static_cast<urdf::Box*>(geometry.get())->dim.x,
|
shapes::Box box(static_cast<urdf::Box*>(geometry.get())->dim.x,
|
||||||
static_cast<urdf::Box*>(geometry.get())->dim.y,
|
static_cast<urdf::Box*>(geometry.get())->dim.y,
|
||||||
static_cast<urdf::Box*>(geometry.get())->dim.z);
|
static_cast<urdf::Box*>(geometry.get())->dim.z);
|
||||||
boost::scoped_ptr<shapes::Mesh> mesh(shapes::createMeshFromShape(box));
|
boost::scoped_ptr<shapes::Mesh> mesh(shapes::createMeshFromShape(box));
|
||||||
_loadVertices(mesh.get(), cgeometry);
|
_loadVertices(mesh.get(), cgeometry);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case urdf::Geometry::CYLINDER: {
|
case urdf::Geometry::CYLINDER: {
|
||||||
shapes::Cylinder cyl(static_cast<urdf::Cylinder*>(geometry.get())->radius,
|
shapes::Cylinder cyl(static_cast<urdf::Cylinder*>(geometry.get())->radius,
|
||||||
static_cast<urdf::Cylinder*>(geometry.get())->length);
|
static_cast<urdf::Cylinder*>(geometry.get())->length);
|
||||||
boost::scoped_ptr<shapes::Mesh> mesh(shapes::createMeshFromShape(cyl));
|
boost::scoped_ptr<shapes::Mesh> mesh(shapes::createMeshFromShape(cyl));
|
||||||
_loadVertices(mesh.get(), cgeometry);
|
_loadVertices(mesh.get(), cgeometry);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1435,55 +1436,55 @@ protected:
|
||||||
|
|
||||||
void _loadVertices(const shapes::Mesh *mesh, domGeometryRef pdomgeom) {
|
void _loadVertices(const shapes::Mesh *mesh, domGeometryRef pdomgeom) {
|
||||||
|
|
||||||
// convert the mesh into an STL binary (in memory)
|
// convert the mesh into an STL binary (in memory)
|
||||||
std::vector<char> buffer;
|
std::vector<char> buffer;
|
||||||
shapes::writeSTLBinary(mesh, buffer);
|
shapes::writeSTLBinary(mesh, buffer);
|
||||||
|
|
||||||
// Create an instance of the Importer class
|
// Create an instance of the Importer class
|
||||||
Assimp::Importer importer;
|
Assimp::Importer importer;
|
||||||
|
|
||||||
// And have it read the given file with some postprocessing
|
// And have it read the given file with some postprocessing
|
||||||
const aiScene* scene = importer.ReadFileFromMemory(reinterpret_cast<const void*>(&buffer[0]), buffer.size(),
|
const aiScene* scene = importer.ReadFileFromMemory(reinterpret_cast<const void*>(&buffer[0]), buffer.size(),
|
||||||
aiProcess_Triangulate |
|
aiProcess_Triangulate |
|
||||||
aiProcess_JoinIdenticalVertices |
|
aiProcess_JoinIdenticalVertices |
|
||||||
aiProcess_SortByPType |
|
aiProcess_SortByPType |
|
||||||
aiProcess_OptimizeGraph |
|
aiProcess_OptimizeGraph |
|
||||||
aiProcess_OptimizeMeshes, "stl");
|
aiProcess_OptimizeMeshes, "stl");
|
||||||
|
|
||||||
// Note: we do this mesh -> STL -> assimp mesh because the aiScene::aiScene symbol is hidden by default
|
// Note: we do this mesh -> STL -> assimp mesh because the aiScene::aiScene symbol is hidden by default
|
||||||
|
|
||||||
domMeshRef pdommesh = daeSafeCast<domMesh>(pdomgeom->add(COLLADA_ELEMENT_MESH));
|
domMeshRef pdommesh = daeSafeCast<domMesh>(pdomgeom->add(COLLADA_ELEMENT_MESH));
|
||||||
domSourceRef pvertsource = daeSafeCast<domSource>(pdommesh->add(COLLADA_ELEMENT_SOURCE));
|
domSourceRef pvertsource = daeSafeCast<domSource>(pdommesh->add(COLLADA_ELEMENT_SOURCE));
|
||||||
domAccessorRef pacc;
|
domAccessorRef pacc;
|
||||||
domFloat_arrayRef parray;
|
domFloat_arrayRef parray;
|
||||||
{
|
{
|
||||||
pvertsource->setId(str(boost::format("%s_positions")%pdomgeom->getID()).c_str());
|
pvertsource->setId(str(boost::format("%s_positions")%pdomgeom->getID()).c_str());
|
||||||
|
|
||||||
parray = daeSafeCast<domFloat_array>(pvertsource->add(COLLADA_ELEMENT_FLOAT_ARRAY));
|
parray = daeSafeCast<domFloat_array>(pvertsource->add(COLLADA_ELEMENT_FLOAT_ARRAY));
|
||||||
parray->setId(str(boost::format("%s_positions-array")%pdomgeom->getID()).c_str());
|
parray->setId(str(boost::format("%s_positions-array")%pdomgeom->getID()).c_str());
|
||||||
parray->setDigits(6); // 6 decimal places
|
parray->setDigits(6); // 6 decimal places
|
||||||
|
|
||||||
domSource::domTechnique_commonRef psourcetec = daeSafeCast<domSource::domTechnique_common>(pvertsource->add(COLLADA_ELEMENT_TECHNIQUE_COMMON));
|
domSource::domTechnique_commonRef psourcetec = daeSafeCast<domSource::domTechnique_common>(pvertsource->add(COLLADA_ELEMENT_TECHNIQUE_COMMON));
|
||||||
pacc = daeSafeCast<domAccessor>(psourcetec->add(COLLADA_ELEMENT_ACCESSOR));
|
pacc = daeSafeCast<domAccessor>(psourcetec->add(COLLADA_ELEMENT_ACCESSOR));
|
||||||
pacc->setSource(xsAnyURI(*parray, std::string("#")+string(parray->getID())));
|
pacc->setSource(xsAnyURI(*parray, std::string("#")+string(parray->getID())));
|
||||||
pacc->setStride(3);
|
pacc->setStride(3);
|
||||||
|
|
||||||
domParamRef px = daeSafeCast<domParam>(pacc->add(COLLADA_ELEMENT_PARAM));
|
domParamRef px = daeSafeCast<domParam>(pacc->add(COLLADA_ELEMENT_PARAM));
|
||||||
px->setName("X"); px->setType("float");
|
px->setName("X"); px->setType("float");
|
||||||
domParamRef py = daeSafeCast<domParam>(pacc->add(COLLADA_ELEMENT_PARAM));
|
domParamRef py = daeSafeCast<domParam>(pacc->add(COLLADA_ELEMENT_PARAM));
|
||||||
py->setName("Y"); py->setType("float");
|
py->setName("Y"); py->setType("float");
|
||||||
domParamRef pz = daeSafeCast<domParam>(pacc->add(COLLADA_ELEMENT_PARAM));
|
domParamRef pz = daeSafeCast<domParam>(pacc->add(COLLADA_ELEMENT_PARAM));
|
||||||
pz->setName("Z"); pz->setType("float");
|
pz->setName("Z"); pz->setType("float");
|
||||||
}
|
}
|
||||||
domVerticesRef pverts = daeSafeCast<domVertices>(pdommesh->add(COLLADA_ELEMENT_VERTICES));
|
domVerticesRef pverts = daeSafeCast<domVertices>(pdommesh->add(COLLADA_ELEMENT_VERTICES));
|
||||||
{
|
{
|
||||||
pverts->setId("vertices");
|
pverts->setId("vertices");
|
||||||
domInput_localRef pvertinput = daeSafeCast<domInput_local>(pverts->add(COLLADA_ELEMENT_INPUT));
|
domInput_localRef pvertinput = daeSafeCast<domInput_local>(pverts->add(COLLADA_ELEMENT_INPUT));
|
||||||
pvertinput->setSemantic("POSITION");
|
pvertinput->setSemantic("POSITION");
|
||||||
pvertinput->setSource(domUrifragment(*pvertsource, std::string("#")+std::string(pvertsource->getID())));
|
pvertinput->setSource(domUrifragment(*pvertsource, std::string("#")+std::string(pvertsource->getID())));
|
||||||
}
|
}
|
||||||
_buildAiMesh(scene,scene->mRootNode,pdommesh,parray, pdomgeom->getID(), urdf::Vector3(1,1,1));
|
_buildAiMesh(scene,scene->mRootNode,pdommesh,parray, pdomgeom->getID(), urdf::Vector3(1,1,1));
|
||||||
pacc->setCount(parray->getCount());
|
pacc->setCount(parray->getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
void _loadMesh(std::string const& filename, domGeometryRef pdomgeom, const urdf::Vector3& scale, urdf::Pose *org_trans)
|
void _loadMesh(std::string const& filename, domGeometryRef pdomgeom, const urdf::Vector3& scale, urdf::Pose *org_trans)
|
||||||
|
@ -1568,18 +1569,19 @@ protected:
|
||||||
aiVector3D p = input_mesh->mVertices[j];
|
aiVector3D p = input_mesh->mVertices[j];
|
||||||
p *= transform;
|
p *= transform;
|
||||||
if (org_trans) {
|
if (org_trans) {
|
||||||
urdf::Vector3 vv;
|
urdf::Vector3 vv;
|
||||||
vv.x = p.x*scale.x;
|
vv.x = p.x*scale.x;
|
||||||
vv.y = p.y*scale.y;
|
vv.y = p.y*scale.y;
|
||||||
vv.z = p.z*scale.z;
|
vv.z = p.z*scale.z;
|
||||||
urdf::Vector3 nv = _poseMult(*org_trans, vv);
|
urdf::Vector3 nv = _poseMult(*org_trans, vv);
|
||||||
parray->getValue().append(nv.x);
|
parray->getValue().append(nv.x);
|
||||||
parray->getValue().append(nv.y);
|
parray->getValue().append(nv.y);
|
||||||
parray->getValue().append(nv.z);
|
parray->getValue().append(nv.z);
|
||||||
} else {
|
}
|
||||||
parray->getValue().append(p.x*scale.x);
|
else {
|
||||||
parray->getValue().append(p.y*scale.y);
|
parray->getValue().append(p.x*scale.x);
|
||||||
parray->getValue().append(p.z*scale.z);
|
parray->getValue().append(p.y*scale.y);
|
||||||
|
parray->getValue().append(p.z*scale.z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1935,7 +1937,7 @@ ColladaUrdfException::ColladaUrdfException(std::string const& what)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WriteUrdfModelToColladaFile(urdf::Model const& robot_model, string const& file) {
|
bool WriteUrdfModelToColladaFile(urdf::Model const& robot_model, string const& file) {
|
||||||
ColladaWriter writer(robot_model,0);
|
ColladaWriter writer(robot_model, 0);
|
||||||
if ( ! writer.convert() ) {
|
if ( ! writer.convert() ) {
|
||||||
std::cerr << std::endl << "Error converting document" << std::endl;
|
std::cerr << std::endl << "Error converting document" << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -50,14 +50,15 @@ int main(int argc, char** argv)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ros::init(argc, argv, "urdf_to_collada");
|
ros::init(argc, argv, "urdf_to_collada");
|
||||||
|
|
||||||
std::string input_filename(argv[1]);
|
std::string input_filename(argv[1]);
|
||||||
std::string output_filename(argv[2]);
|
std::string output_filename(argv[2]);
|
||||||
|
|
||||||
urdf::Model robot_model;
|
urdf::Model robot_model;
|
||||||
if( !robot_model.initFile(input_filename) ) {
|
if( !robot_model.initFile(input_filename) ) {
|
||||||
ROS_ERROR("failed to open urdf file %s",input_filename.c_str());
|
ROS_ERROR("failed to open urdf file %s", input_filename.c_str());
|
||||||
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
collada_urdf::WriteUrdfModelToColladaFile(robot_model, output_filename);
|
collada_urdf::WriteUrdfModelToColladaFile(robot_model, output_filename);
|
||||||
|
|
|
@ -34,52 +34,23 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
/*
|
|
||||||
std::string readTestUrdfString() {
|
|
||||||
std::ifstream file("test/pr2.urdf");
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << file.rdbuf();
|
|
||||||
return ss.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(collada_urdf, collada_from_urdf_file_works)
|
TEST(collada_urdf, collada_from_urdf_file_works)
|
||||||
{
|
{
|
||||||
boost::shared_ptr<DAE> dom;
|
urdf::Model robot_model;
|
||||||
ASSERT_TRUE(collada_urdf::colladaFromUrdfFile("test/pr2.urdf", dom));
|
|
||||||
ASSERT_TRUE(collada_urdf::colladaToFile(dom, "test/pr2.dae"));
|
ASSERT_TRUE(robot_model.initFile("pr2.urdf"));
|
||||||
|
ASSERT_TRUE(collada_urdf::WriteUrdfModelToColladaFile(robot_model, "pr2.dae"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(collada_urdf, collada_from_urdf_string_works)
|
TEST(collada_urdf, collada_output_dir_does_not_exist)
|
||||||
{
|
|
||||||
std::string urdf_str = readTestUrdfString();
|
|
||||||
|
|
||||||
boost::shared_ptr<DAE> dom;
|
|
||||||
ASSERT_TRUE(collada_urdf::colladaFromUrdfString(urdf_str, dom));
|
|
||||||
ASSERT_TRUE(collada_urdf::colladaToFile(dom, "test/pr2.dae"));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(collada_urdf, collada_from_urdf_xml_works)
|
|
||||||
{
|
|
||||||
TiXmlDocument urdf_xml;
|
|
||||||
ASSERT_TRUE(urdf_xml.Parse(readTestUrdfString().c_str()) > 0);
|
|
||||||
|
|
||||||
boost::shared_ptr<DAE> dom;
|
|
||||||
ASSERT_TRUE(collada_urdf::colladaFromUrdfXml(&urdf_xml, dom));
|
|
||||||
ASSERT_TRUE(collada_urdf::colladaToFile(dom, "test/pr2.dae"));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(collada_urdf, collada_from_urdf_model_works)
|
|
||||||
{
|
{
|
||||||
urdf::Model robot_model;
|
urdf::Model robot_model;
|
||||||
TiXmlDocument urdf_xml;
|
|
||||||
ASSERT_TRUE(urdf_xml.Parse(readTestUrdfString().c_str()) > 0);
|
|
||||||
ASSERT_TRUE(robot_model.initXml(&urdf_xml));
|
|
||||||
|
|
||||||
boost::shared_ptr<DAE> dom;
|
ASSERT_TRUE(robot_model.initFile("pr2.urdf"));
|
||||||
ASSERT_TRUE(collada_urdf::colladaFromUrdfModel(robot_model, dom));
|
ASSERT_FALSE(collada_urdf::WriteUrdfModelToColladaFile(robot_model, "a/very/long/directory/path/that/should/not/exist/pr2.dae"));
|
||||||
ASSERT_TRUE(collada_urdf::colladaToFile(dom, "test/pr2.dae"));
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
testing::InitGoogleTest(&argc, argv);
|
testing::InitGoogleTest(&argc, argv);
|
||||||
return RUN_ALL_TESTS();
|
return RUN_ALL_TESTS();
|
||||||
|
|
Loading…
Reference in New Issue