Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

geometryserver.cpp

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
00002 
00003    this file is part of rcssserver3D
00004    Fri May 9 2003
00005    Copyright (C) 2002,2003 Koblenz University
00006    Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group
00007    $Id: geometryserver.cpp,v 1.1 2004/04/22 17:01:18 rollmark Exp $
00008 
00009    This program is free software; you can redistribute it and/or modify
00010    it under the terms of the GNU General Public License as published by
00011    the Free Software Foundation; version 2 of the License.
00012 
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with this program; if not, write to the Free Software
00020    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00021 */
00022 #include "geometryserver.h"
00023 #include "meshimporter.h"
00024 #include <zeitgeist/logserver/logserver.h>
00025 
00026 using namespace oxygen;
00027 using namespace zeitgeist;
00028 using namespace salt;
00029 using namespace std;
00030 using namespace boost;
00031 
00032 GeometryServer::GeometryServer() : Node()
00033 {
00034 }
00035 
00036 GeometryServer::~GeometryServer()
00037 {
00038 }
00039 
00040 void GeometryServer::OnLink()
00041 {
00042     if (mChildren.size() == 0)
00043         {
00044             InitMeshImporter("oxygen/StdMeshImporter");
00045         }
00046 }
00047 
00048 bool GeometryServer::InitMeshImporter(const string& importerName)
00049 {
00050     shared_ptr<MeshImporter> importer
00051         = shared_dynamic_cast<MeshImporter>(GetCore()->New(importerName));
00052 
00053     if (importer.get() == 0)
00054         {
00055             GetLog()->Error() << "(GeometryServer) ERROR: "
00056                               << "unable to create '" << importerName << "'\n";
00057             return false;
00058         }
00059 
00060     importer->SetName(importerName);
00061     AddChildReference(importer);
00062 
00063     GetLog()->Normal()
00064         << "(GeometryServer) MeshImporter '" << importerName << "' registered\n";
00065 
00066     return true;
00067 }
00068 
00069 shared_ptr<TriMesh> GeometryServer::GetMesh
00070 (const string& name, const::ParameterList& parameter)
00071 {
00072     // try a direct match
00073     string meshName = name;
00074     TMeshMap::iterator meshIter = mMeshMap.find(meshName);
00075 
00076     if (meshIter != mMeshMap.end())
00077         {
00078             return (*meshIter).second;
00079         }
00080 
00081     TLeafList importer;
00082     ListChildrenSupportingClass<MeshImporter>(importer);
00083 
00084     if (importer.size() == 0)
00085         {
00086             GetLog()->Error()
00087                 << "(GeometryServer) Warning: no MeshImporter registered\n";
00088 
00089             return shared_ptr<TriMesh>();
00090         }
00091 
00092     // try to mangle the name
00093     for (
00094          TLeafList::iterator iter = importer.begin();
00095          iter != importer.end();
00096          ++iter
00097          )
00098         {
00099             shared_ptr<MeshImporter> importer =
00100                 shared_static_cast<MeshImporter>(*iter);
00101 
00102             string str = importer->MangleName(name, parameter);
00103 
00104             if (str != meshName)
00105                 {
00106                     meshName = str;
00107                     meshIter = mMeshMap.find(meshName);
00108                     if (meshIter != mMeshMap.end())
00109                         {
00110                             return (*meshIter).second;
00111                         }
00112                 }
00113         }
00114 
00115     // try to import the mesh
00116     for (
00117          TLeafList::iterator iter = importer.begin();
00118          iter != importer.end();
00119          ++iter
00120          )
00121         {
00122             shared_ptr<MeshImporter> importer =
00123                 shared_static_cast<MeshImporter>(*iter);
00124 
00125             shared_ptr<TriMesh> mesh = importer->ImportMesh(name,parameter);
00126 
00127             if (mesh.get() == 0)
00128                 {
00129                     continue;
00130                 }
00131 
00132             string meshName = mesh->GetName();
00133             if (meshName == "")
00134                 {
00135                     mesh->SetName(name);
00136                     meshName = name;
00137                 }
00138 
00139             GetLog()->Normal()
00140                 << "(GeometryServer) imported mesh '"
00141                 << meshName << " with '"
00142                 << importer->GetName() << "'\n";
00143 
00144             mMeshMap[meshName] = mesh;
00145             return mesh;
00146         }
00147 
00148     GetLog()->Error() << "(GeometryServer) ERROR: cannot import mesh '"
00149                       << name << "'\n";
00150 
00151     return shared_ptr<TriMesh>();
00152 }
00153 

Generated on Thu Apr 6 15:25:38 2006 for rcssserver3d by  doxygen 1.4.4