Revision: 8260
http://playerstage.svn.sourceforge.net/playerstage/?rev=8260&view=rev
Author: hsujohnhsu
Date: 2009-09-20 07:27:21 +0000 (Sun, 20 Sep 2009)
Log Message:
-----------
make Image search through gazebo resource paths on Image::Load() call. Update
HeightmapGeom and MapGeom accordingly.
Modified Paths:
--------------
code/gazebo/trunk/server/physics/HeightmapGeom.cc
code/gazebo/trunk/server/physics/MapGeom.cc
code/gazebo/trunk/server/rendering/Image.cc
Modified: code/gazebo/trunk/server/physics/HeightmapGeom.cc
===================================================================
--- code/gazebo/trunk/server/physics/HeightmapGeom.cc 2009-09-14 17:26:16 UTC
(rev 8259)
+++ code/gazebo/trunk/server/physics/HeightmapGeom.cc 2009-09-20 07:27:21 UTC
(rev 8260)
@@ -112,7 +112,7 @@
/// Load the heightmap
void HeightmapGeom::LoadChild(XMLConfigNode *node)
{
- Image tmpImage;
+ Image img;
this->imageFilenameP->Load(node);
this->worldTextureP->Load(node);
@@ -121,16 +121,18 @@
this->offsetP->Load(node);
// Use the image to get the size of the heightmap
- tmpImage.Load( (**this->imageFilenameP) );
+ img.Load( (**this->imageFilenameP) );
// Width and height must be the same
- if (tmpImage.GetWidth() != tmpImage.GetHeight())
+ if (img.GetWidth() != img.GetHeight())
{
gzthrow("Heightmap image must be square\n");
}
this->terrainSize = (**this->sizeP);
- this->odeVertSize = tmpImage.GetWidth() * 4;
+
+ // sampling size along image width and height
+ this->odeVertSize = img.GetWidth() * 4;
this->odeScale = this->terrainSize / this->odeVertSize;
@@ -156,13 +158,13 @@
this->odeData,
this,
HeightmapGeom::GetHeightCallback,
- this->terrainSize.x,
- this->terrainSize.y,
- this->odeVertSize,
- this->odeVertSize,
- 1.0, // scale
- 0.0, // vertical offset
- 0.0, // vertical thickness
+ this->terrainSize.x, // in meters
+ this->terrainSize.y, // in meters
+ this->odeVertSize, // width sampling size
+ this->odeVertSize, // depth sampling size (along height of image)
+ 1.0, // vertical (z-axis) scaling
+ 0.0, // vertical (z-axis) offset
+ 0.1, // vertical thickness for closing the height map mesh
0 // wrap mode
);
Modified: code/gazebo/trunk/server/physics/MapGeom.cc
===================================================================
--- code/gazebo/trunk/server/physics/MapGeom.cc 2009-09-14 17:26:16 UTC (rev
8259)
+++ code/gazebo/trunk/server/physics/MapGeom.cc 2009-09-20 07:27:21 UTC (rev
8260)
@@ -109,21 +109,8 @@
// Load the image
this->mapImage = new Image();
+ this->mapImage->Load(imageFilename);
- std::list<std::string>::iterator iter;
- GazeboConfig *gzcfg = Simulator::Instance()->GetGazeboConfig();
- std::string filename;
-
- for (iter = gzcfg->GetGazeboPaths().begin();
- iter != gzcfg->GetGazeboPaths().end(); iter++)
- {
- filename = (*iter) + "/Media/materials/textures/" + imageFilename;
- if (this->mapImage->Load(filename) >= 0)
- {
- break;
- }
- }
-
if (!this->mapImage->Valid())
gzthrow(std::string("Unable to open image file[") + imageFilename + "]" );
Modified: code/gazebo/trunk/server/rendering/Image.cc
===================================================================
--- code/gazebo/trunk/server/rendering/Image.cc 2009-09-14 17:26:16 UTC (rev
8259)
+++ code/gazebo/trunk/server/rendering/Image.cc 2009-09-20 07:27:21 UTC (rev
8260)
@@ -28,12 +28,16 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <dirent.h>
+#include <string.h>
//#include <GL/gl.h>
#include "Vector3.hh"
#include "GazeboMessage.hh"
#include "Image.hh"
+#include "Simulator.hh"
+#include "GazeboConfig.hh"
using namespace gazebo;
@@ -72,31 +76,67 @@
{
struct stat st;
- if (stat(filename.c_str(), &st) != 0)
+ // @todo: fix path search. for now repeat similar path search in OgreAdaptor
+ std::list<std::string>
gazeboPaths=Simulator::Instance()->GetGazeboConfig()->GetGazeboPaths();
+
+ for (std::list<std::string>::iterator iter=gazeboPaths.begin();
+ iter!=gazeboPaths.end(); ++iter)
{
- gzerr(5) << "Unable to open image file[" << filename << "]\n";
- return -1;
- }
+ std::vector<std::string> pathNames;
+ pathNames.push_back((*iter)+"/Media");
+ pathNames.push_back((*iter)+"/Media/fonts");
+ pathNames.push_back((*iter)+"/Media/materials/programs");
+ pathNames.push_back((*iter)+"/Media/materials/scripts");
+ pathNames.push_back((*iter)+"/Media/materials/textures");
+ pathNames.push_back((*iter)+"/Media/models");
+ pathNames.push_back((*iter)+"/Media/sets");
+ pathNames.push_back((*iter)+"/Media/maps");
- FREE_IMAGE_FORMAT fifmt = FreeImage_GetFIFFromFilename(filename.c_str());
+ for (std::vector<std::string>::iterator piter =
pathNames.begin();piter!=pathNames.end();piter++)
+ {
+ std::string path(*piter);
+ DIR *dir=opendir(path.c_str());
- if (this->bitmap)
- FreeImage_Unload(this->bitmap);
- this->bitmap = NULL;
+ //std::cout << "searching path[" << path << "]\n";
+ // if directory exist
+ if (dir != NULL)
+ {
+ closedir(dir);
- if (fifmt == FIF_PNG)
- this->bitmap = FreeImage_Load(fifmt, filename.c_str(), PNG_DEFAULT);
- else if (fifmt == FIF_JPEG)
- this->bitmap = FreeImage_Load(fifmt, filename.c_str(), JPEG_DEFAULT);
- else if (fifmt == FIF_BMP)
- this->bitmap = FreeImage_Load(fifmt, filename.c_str(), BMP_DEFAULT);
- else
- {
- std::cerr << "Unknown image format[" << filename << "]\n";
- return -1;
+ std::string fullName = (((*piter)+"/")+filename);
+ //std::cout << "searching file[" << fullName << "]\n";
+ // if file exist
+ if (stat(fullName.c_str(), &st) == 0)
+ {
+ FREE_IMAGE_FORMAT fifmt =
FreeImage_GetFIFFromFilename(fullName.c_str());
+
+ if (this->bitmap)
+ FreeImage_Unload(this->bitmap);
+ this->bitmap = NULL;
+
+ if (fifmt == FIF_PNG)
+ this->bitmap = FreeImage_Load(fifmt, fullName.c_str(),
PNG_DEFAULT);
+ else if (fifmt == FIF_JPEG)
+ this->bitmap = FreeImage_Load(fifmt, fullName.c_str(),
JPEG_DEFAULT);
+ else if (fifmt == FIF_BMP)
+ this->bitmap = FreeImage_Load(fifmt, fullName.c_str(),
BMP_DEFAULT);
+ else
+ {
+ gzerr(5) << "Unknown image format[" << fullName << "]\n";
+ return -1;
+ }
+
+ return 0;
+ }
+ }
+
+ }
+
}
- return 0;
+ gzerr(5) << "Unable to open image file[" << filename << "]\n";
+ return -1;
+
}
////////////////////////////////////////////////////////////////////////////////
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit