OBJPrimitiveIO.h

Go to the documentation of this file.
00001 // Copyright (C) 2008 Dave Griffiths
00002 //
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 //
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016  
00017 #ifndef FLUX_OBJ_PRIMITIVE_IO
00018 #define FLUX_OBJ_PRIMITIVE_IO
00019 
00020 #include "PrimitiveIO.h"
00021 #include <vector>
00022 
00023 namespace Fluxus
00024 {
00025 
00026 class OBJPrimitiveIO : public PrimitiveIO
00027 {
00028 public:
00029     OBJPrimitiveIO();
00030     virtual ~OBJPrimitiveIO();
00031     virtual Primitive *FormatRead(const std::string &filename);
00032     virtual bool FormatWrite(const std::string &filename, const Primitive *ob);
00033     
00034 private:
00035     class Indices
00036     {
00037     public:
00038         Indices() : Position(0), Texture(0), Normal(0) {}
00039         
00040         bool operator==(const Indices &other) const
00041         {
00042             return Position==other.Position &&
00043                    Texture==other.Texture &&
00044                    Normal==other.Normal;
00045         }
00046         
00047         unsigned int Position;
00048         unsigned int Texture;
00049         unsigned int Normal;
00050     };
00051     
00052     struct Face
00053     {
00054         vector<Indices> Index;
00055     };
00056     
00057     unsigned int TokeniseLine(unsigned int pos, vector<string> &output);
00058     void TokeniseIndices(const string &str, vector<string> &output);
00059     void ReadVectors(const std::string &code, std::vector<dVector> &output);
00060     void ReadIndices(std::vector<Face> &output);
00061     vector<Indices> RemoveDuplicateIndices();
00062     void ReorderData(const vector<Indices> &unique);
00063     void UnifyIndices(const vector<Indices> &unique);
00064     Primitive *MakePrimitive();
00065     
00066     void WriteVertices(const std::string &pdataname, const std::string &objname, const Primitive *ob, FILE *file);
00067     void WriteIndices(const Primitive *ob, FILE *file);
00068 
00069     unsigned int m_DataSize;
00070     char *m_Data;
00071     
00072     vector<Face> m_Faces;
00073     vector<dVector> m_Position;
00074     vector<dVector> m_Texture;
00075     vector<dVector> m_Normal;
00076     vector<unsigned int> m_Indices;
00077 };
00078 
00079 }
00080 
00081 #endif

Generated on Wed Sep 17 21:16:30 2008 for The Fluxus Renderer (libfluxus) by  doxygen 1.5.1