From: Oliver O. <fr...@us...> - 2007-06-17 13:39:38
|
Update of /cvsroot/simspark/simspark/spark/oxygen/geometryserver In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv21072/oxygen/geometryserver Modified Files: geometryserver.cpp geometryserver.h geometryserver_c.cpp Added Files: meshexporter.h meshexporter_c.cpp Log Message: merge from projectx branch Index: geometryserver.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/oxygen/geometryserver/geometryserver.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** geometryserver.cpp 15 Jun 2007 08:48:16 -0000 1.3 --- geometryserver.cpp 17 Jun 2007 13:38:32 -0000 1.4 *************** *** 22,25 **** --- 22,26 ---- #include "geometryserver.h" #include "meshimporter.h" + #include "meshexporter.h" #include <zeitgeist/logserver/logserver.h> *************** *** 38,50 **** } ! void GeometryServer::OnLink() { if (mChildren.size() == 0) ! { ! InitMeshImporter("oxygen/StdMeshImporter"); ! } } ! bool GeometryServer::InitMeshImporter(const string& importerName) { shared_ptr<MeshImporter> importer --- 39,53 ---- } ! void ! GeometryServer::OnLink() { if (mChildren.size() == 0) ! { ! InitMeshImporter("oxygen/StdMeshImporter"); ! } } ! bool ! GeometryServer::InitMeshImporter(const string& importerName) { shared_ptr<MeshImporter> importer *************** *** 52,60 **** if (importer.get() == 0) ! { ! GetLog()->Error() << "(GeometryServer) ERROR: " ! << "unable to create '" << importerName << "'\n"; ! return false; ! } importer->SetName(importerName); --- 55,63 ---- if (importer.get() == 0) ! { ! GetLog()->Error() << "(GeometryServer) ERROR: " ! << "unable to create '" << importerName << "'\n"; ! return false; ! } importer->SetName(importerName); *************** *** 67,81 **** } ! shared_ptr<TriMesh> GeometryServer::GetMesh ! (const string& name, const::ParameterList& parameter) { // try a direct match string meshName = name; ! TMeshMap::iterator meshIter = mMeshMap.find(meshName); if (meshIter != mMeshMap.end()) ! { ! return (*meshIter).second; ! } TLeafList importer; --- 70,84 ---- } ! shared_ptr<TriMesh> ! GeometryServer::GetMesh(const string& name, const::ParameterList& parameter) { // try a direct match string meshName = name; ! TMeshMap::const_iterator meshIter = mMeshMap.find(meshName); if (meshIter != mMeshMap.end()) ! { ! return (*meshIter).second; ! } TLeafList importer; *************** *** 83,92 **** if (importer.size() == 0) ! { ! GetLog()->Error() ! << "(GeometryServer) Warning: no MeshImporter registered\n"; ! return shared_ptr<TriMesh>(); ! } // try to mangle the name --- 86,95 ---- if (importer.size() == 0) ! { ! GetLog()->Error() ! << "(GeometryServer) Warning: no MeshImporter registered\n"; ! return shared_ptr<TriMesh>(); ! } // try to mangle the name *************** *** 96,115 **** ++iter ) ! { ! shared_ptr<MeshImporter> importer = ! shared_static_cast<MeshImporter>(*iter); ! ! string str = importer->MangleName(name, parameter); ! if (str != meshName) ! { ! meshName = str; ! meshIter = mMeshMap.find(meshName); ! if (meshIter != mMeshMap.end()) ! { ! return (*meshIter).second; ! } ! } } // try to import the mesh --- 99,118 ---- ++iter ) ! { ! shared_ptr<MeshImporter> importer = ! shared_static_cast<MeshImporter>(*iter); ! string str = importer->MangleName(name, parameter); ! ! if (str != meshName) ! { ! meshName = str; ! meshIter = mMeshMap.find(meshName); ! if (meshIter != mMeshMap.end()) ! { ! return (*meshIter).second; ! } } + } // try to import the mesh *************** *** 119,150 **** ++iter ) ! { ! shared_ptr<MeshImporter> importer = ! shared_static_cast<MeshImporter>(*iter); ! ! shared_ptr<TriMesh> mesh = importer->ImportMesh(name,parameter); ! if (mesh.get() == 0 || mesh->GetVertexCount() == 0) ! { ! continue; ! } ! string meshName = mesh->GetName(); ! if (meshName == "") ! { ! meshName = name; ! mesh->SetName(name); ! } ! GetLog()->Normal() ! << "(GeometryServer) imported mesh '" ! << meshName << " with '" ! << importer->GetName() << "'\n"; ! RegisterMesh(mesh); ! return mesh; } GetLog()->Error() << "(GeometryServer) ERROR: cannot import mesh '" << name << "'\n"; --- 122,156 ---- ++iter ) ! { ! shared_ptr<MeshImporter> importer = ! shared_static_cast<MeshImporter>(*iter); ! shared_ptr<TriMesh> mesh = importer->ImportMesh(name,parameter); ! if (mesh.get() == 0) ! { ! continue; ! } ! string meshName = mesh->GetName(); ! if (meshName.empty()) ! { ! meshName = name; ! mesh->SetName(name); ! } ! GetLog()->Normal() << "(GeometryServer) imported mesh '" << meshName ! << " with '" << importer->GetName() << "'\n"; ! if (mesh.get() == 0 || mesh->GetVertexCount() == 0) ! { ! continue; } + RegisterMesh(mesh); + + return mesh; + } + GetLog()->Error() << "(GeometryServer) ERROR: cannot import mesh '" << name << "'\n"; *************** *** 153,181 **** } ! void GeometryServer::RegisterMesh(shared_ptr<TriMesh> mesh) { if (mesh.get() == 0) ! { ! GetLog()->Debug() << "(GeometryServer) RegisterMesh called with NULL mesh\n"; ! return; ! } std::string name = mesh->GetName(); if (name.empty()) ! { ! GetLog()->Error() << "(GeometryServer) Cannot register a mesh without a name\n"; ! return; ! } ! TMeshMap::iterator iter = mMeshMap.find(name); if (iter != mMeshMap.end()) ! { ! GetLog()->Debug() << "(GeometryServer) replacing mesh " << name << "\n"; ! } mMeshMap[name] = mesh; GetLog()->Normal() << "(GeometryServer) mesh " << name << " registered\n"; } --- 159,219 ---- } ! void ! GeometryServer::RegisterMesh(shared_ptr<TriMesh> mesh) { if (mesh.get() == 0) ! { ! GetLog()->Debug() ! << "(GeometryServer) RegisterMesh called with NULL mesh\n"; ! return; ! } std::string name = mesh->GetName(); if (name.empty()) ! { ! GetLog()->Error() ! << "(GeometryServer) Cannot register a mesh without a name\n"; ! return; ! } ! TMeshMap::const_iterator iter = mMeshMap.find(name); if (iter != mMeshMap.end()) ! { ! GetLog()->Debug() << "(GeometryServer) replacing mesh " << name << "\n"; ! } mMeshMap[name] = mesh; GetLog()->Normal() << "(GeometryServer) mesh " << name << " registered\n"; + + TLeafList exporters; + ListChildrenSupportingClass<MeshExporter>(exporters); + + for (TLeafList::const_iterator bi = exporters.begin(); bi != exporters.end(); ++bi) + { + GetLog()->Normal() << "(GeometryServer) additionally registered mesh " + << name << " via MeshExporter '" << (*bi)->GetName() << "'\n"; + shared_ptr<MeshExporter> mb = shared_static_cast<MeshExporter>(*bi); + mb->RegisterMesh(mesh); + } } + bool + GeometryServer::InitMeshExporter(const string& name) + { + shared_ptr<MeshExporter> exporter + = shared_dynamic_cast<MeshExporter>(GetCore()->New(name)); + + if (exporter.get() == 0) + { + GetLog()->Error() << "(GeometryServer) ERROR: " + << "unable to create MeshExporter '" << name << "'\n"; + return false; + } + + exporter->SetName(name); + AddChildReference(exporter); + GetLog()->Normal() << "(GeometryServer) MeshExporter '" << name << "' registered\n"; + return true; + } --- NEW FILE: meshexporter.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Tue May 9 2006 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2007 RoboCup Soccer Server 3D Maintenance Group $Id: meshexporter.h,v 1.2 2007/06/17 13:38:32 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. MeshExporter NOTE: This class serves as an (abstract) exporter to register meshes with other graphic engines (possibly also for exporting). HISTORY: 30/03/07 - OO - Initial version */ #ifndef OXYGEN_MESHEXPORTER_H #define OXYGEN_MESHEXPORTER_H #include <zeitgeist/class.h> #include <zeitgeist/node.h> #include "trimesh.h" namespace oxygen { /** \class MeshExporter. This class can be used to implement custom render server, which needs to be informed about the meshes used for a specific simulation. By registering a MeshExporter implementation to the GeometryServer, meshes can be registered (exported) to another class. */ class MeshExporter : public zeitgeist::Leaf { public: virtual ~MeshExporter() {} /** Register / Export the given mesh. \param mesh the mesh to register / export. */ virtual void RegisterMesh(boost::shared_ptr<TriMesh> mesh) = 0; }; DECLARE_ABSTRACTCLASS(MeshExporter); } // end namespace oxygen #endif // OXYGEN_MESHEXPORTER --- NEW FILE: meshexporter_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Tue May 9 2006 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2007 RoboCup Soccer Server 3D Maintenance Group $Id: meshexporter_c.cpp,v 1.2 2007/06/17 13:38:32 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. MeshExporter NOTE: This class serves as an (abstract) exporter, to register meshes with other graphic engines (possibly also for exporting) HISTORY: 30/03/07 - OO - Initial version */ #include "meshexporter.h" using namespace oxygen; void CLASS(MeshExporter)::DefineClass() { DEFINE_BASECLASS(zeitgeist/Leaf); } Index: geometryserver_c.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/oxygen/geometryserver/geometryserver_c.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** geometryserver_c.cpp 5 Dec 2005 21:16:49 -0000 1.1 --- geometryserver_c.cpp 17 Jun 2007 13:38:32 -0000 1.2 *************** *** 34,48 **** (! in.GetValue(in.begin(),inImporterName)) ) ! { ! return false; ! } return obj->InitMeshImporter(inImporterName); } ! void CLASS(GeometryServer)::DefineClass() { DEFINE_BASECLASS(zeitgeist/Node); DEFINE_FUNCTION(initMeshImporter); } --- 34,65 ---- (! in.GetValue(in.begin(),inImporterName)) ) ! { ! return false; ! } return obj->InitMeshImporter(inImporterName); } ! FUNCTION(GeometryServer,initMeshExporter) ! { ! string inExporterName; ! ! if ( ! (in.GetSize() != 1) || ! (! in.GetValue(in.begin(),inExporterName)) ! ) ! { ! return false; ! } ! ! return obj->InitMeshExporter(inExporterName); ! } ! ! void ! CLASS(GeometryServer)::DefineClass() { DEFINE_BASECLASS(zeitgeist/Node); DEFINE_FUNCTION(initMeshImporter); + DEFINE_FUNCTION(initMeshExporter); } Index: geometryserver.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/oxygen/geometryserver/geometryserver.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** geometryserver.h 23 Feb 2006 13:38:36 -0000 1.2 --- geometryserver.h 17 Jun 2007 13:38:32 -0000 1.3 *************** *** 25,28 **** --- 25,29 ---- #include <zeitgeist/class.h> #include <zeitgeist/node.h> + #include "meshexporter.h" #include "trimesh.h" *************** *** 43,48 **** ~GeometryServer(); ! /** creates an instance of \param importerName and registers it as a ! MeshImporter to the GeometryServer */ bool InitMeshImporter(const std::string& importerName); --- 44,50 ---- ~GeometryServer(); ! /** creates an instance of a mesh importer and registers it to the GeometryServer. ! * \param importerName the (class) name of the importer ! * \returns true if successful */ bool InitMeshImporter(const std::string& importerName); *************** *** 51,56 **** returns a cached reference */ ! boost::shared_ptr<TriMesh> GetMesh ! (const std::string& name, const zeitgeist::ParameterList& parameter); /** register a trimesh to the GeometryServer. The name of the mesh --- 53,58 ---- returns a cached reference */ ! boost::shared_ptr<TriMesh> ! GetMesh (const std::string& name, const zeitgeist::ParameterList& parameter); /** register a trimesh to the GeometryServer. The name of the mesh *************** *** 59,62 **** --- 61,74 ---- void RegisterMesh(boost::shared_ptr<TriMesh> mesh); + /** Create an instance of a mesh exporter and register it to the GeometryServer. + A MeshExporter is a class that takes care to additionally register/export + meshes registered at the GeometryServer at another class (potentially + external to spark). This has to be done only when spark/kerosin + rendering alone is not enough. + \param name name of the MeshExporter class name + \returns true if successful + */ + bool InitMeshExporter(const std::string& name); + protected: /** registers the standard mesh importer */ |