00001 /* 00002 * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc. 00003 * All rights reserved. This program is made available under the terms of the 00004 * Eclipse Public License v1.0 which accompanies this distribution, and is 00005 * available at http://www.eclipse.org/legal/epl-v10.html 00006 * Contributors: 00007 * National Institute of Advanced Industrial Science and Technology (AIST) 00008 */ 00009 00015 #include "SceneInfo_impl.h" 00016 00017 #include <map> 00018 #include <vector> 00019 #include <iostream> 00020 #include <boost/bind.hpp> 00021 00022 #include <hrpCorba/ViewSimulator.hh> 00023 #include <hrpUtil/EasyScanner.h> 00024 #include <hrpUtil/VrmlNodes.h> 00025 #include <hrpUtil/VrmlParser.h> 00026 00027 #include "VrmlUtil.h" 00028 00029 00030 using namespace std; 00031 using namespace boost; 00032 00033 SceneInfo_impl::SceneInfo_impl(PortableServer::POA_ptr poa) : 00034 ShapeSetInfo_impl(poa) 00035 { 00036 00037 } 00038 00039 00040 SceneInfo_impl::~SceneInfo_impl() 00041 { 00042 00043 } 00044 00045 00046 const std::string& SceneInfo_impl::topUrl() 00047 { 00048 return url_; 00049 } 00050 00051 00052 char* SceneInfo_impl::url() 00053 { 00054 return CORBA::string_dup(url_.c_str()); 00055 } 00056 00057 00058 TransformedShapeIndexSequence* SceneInfo_impl::shapeIndices() 00059 { 00060 return new TransformedShapeIndexSequence(shapeIndices_); 00061 } 00062 00063 00064 void SceneInfo_impl::load(const std::string& url) 00065 { 00066 string filename(deleteURLScheme(url)); 00067 00068 // URL文字列の' \' 区切り子を'/' に置き換え Windows ファイルパス対応 00069 string url2; 00070 url2 = filename; 00071 replace( url2, string("\\"), string("/") ); 00072 filename = url2; 00073 url_ = CORBA::string_dup(url2.c_str()); 00074 00075 try { 00076 VrmlParser parser; 00077 parser.load(filename); 00078 00079 Matrix44 E(Matrix44::Identity()); 00080 00081 while(VrmlNodePtr node = parser.readNode()){ 00082 if(!node->isCategoryOf(PROTO_DEF_NODE)){ 00083 applyTriangleMeshShaper(node); 00084 traverseShapeNodes(node.get(), E, shapeIndices_, inlinedShapeTransformMatrices_, &topUrl()); 00085 } 00086 } 00087 } catch(EasyScanner::Exception& ex){ 00088 cout << ex.getFullMessage() << endl; 00089 throw ModelLoader::ModelLoaderException(ex.getFullMessage().c_str()); 00090 } 00091 }