root/OpenSceneGraph/trunk/src/osgPlugins/ply/ReaderWriterPLY.cpp
@
13041
| Revision 13041, 2.9 kB (checked in by robert, 14 months ago) | |
|---|---|
|
|
| Line | |
|---|---|
| 1 | /* |
| 2 | * PLY ( Stanford Triangle Format ) File Loader for OSG |
| 3 | * Copyright (C) 2009 by VizExperts Limited |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU Lesser General Public License as published by |
| 8 | * the Free Software Foundation; either version 2.1 of the License, or (at |
| 9 | * your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 13 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
| 14 | * License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public License |
| 17 | * along with this program; if not, write to the Free Software Foundation, |
| 18 | * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | */ |
| 20 | |
| 21 | #include <osgDB/Registry> |
| 22 | #include <osgDB/ReadFile> |
| 23 | #include <osgDB/FileUtils> |
| 24 | #include <osgDB/FileNameUtils> |
| 25 | |
| 26 | |
| 27 | #include "vertexData.h" |
| 28 | |
| 29 | using namespace osg; |
| 30 | using namespace osgDB; |
| 31 | using namespace std; |
| 32 | |
| 33 | /////////////////////////////////////////////////////////////////////////////// |
| 34 | //! |
| 35 | //! \class ReaderWriterPLY |
| 36 | //! \brief This is the Reader for the ply file format |
| 37 | //! |
| 38 | ////////////////////////////////////////////////////////////////////////////// |
| 39 | class ReaderWriterPLY : public osgDB::ReaderWriter |
| 40 | { |
| 41 | public: |
| 42 | ReaderWriterPLY() |
| 43 | { |
| 44 | supportsExtension("ply","Stanford Triangle Format"); |
| 45 | } |
| 46 | |
| 47 | virtual const char* className() { return "ReaderWriterPLY"; } |
| 48 | virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*) const; |
| 49 | protected: |
| 50 | }; |
| 51 | |
| 52 | // register with Registry to instantiate the above reader/writer. |
| 53 | REGISTER_OSGPLUGIN(ply, ReaderWriterPLY) |
| 54 | |
| 55 | /////////////////////////////////////////////////////////////////////////////// |
| 56 | //! |
| 57 | //! \brief Function which is called when any ply file is requested to load in |
| 58 | //! \osgDB. Load read ply file and if it successes return the osg::Node |
| 59 | //! |
| 60 | /////////////////////////////////////////////////////////////////////////////// |
| 61 | osgDB::ReaderWriter::ReadResult ReaderWriterPLY::readNode(const std::string& filename, const osgDB::ReaderWriter::Options* options) const |
| 62 | { |
| 63 | // Get the file extension |
| 64 | std::string ext = osgDB::getFileExtension(filename); |
| 65 | |
| 66 | // If the file extension does not support then return that file is not handled |
| 67 | if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; |
| 68 | |
| 69 | // Check whether or not file exist or not |
| 70 | std::string fileName = osgDB::findDataFile(filename, options); |
| 71 | if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; |
| 72 | |
| 73 | //Instance of vertex data which will read the ply file and convert in to osg::Node |
| 74 | ply::VertexData vertexData; |
| 75 | osg::Node* node = vertexData.readPlyFile(filename.c_str()); |
| 76 | |
| 77 | if (node) |
| 78 | return node; |
| 79 | |
| 80 | return ReadResult::FILE_NOT_HANDLED; |
| 81 | } |
Note: See TracBrowser
for help on using the browser.
