Ignore:
Timestamp:
02/09/07 14:39:35 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/include/ObjManualMeshLoader.h

    r2110 r2111  
    1 #ifndef __IVManualMeshLoader_H__ 
    2 #define __IVManualMeshLoader_H__ 
     1#ifndef __ObjManualMeshLoader_H__ 
     2#define __ObjManualMeshLoader_H__ 
    33 
    44 
     
    77 
    88 
    9 class __declspec(dllexport) IVManualMeshLoader: public Ogre::ManualResourceLoader 
     9class __declspec(dllexport) ObjManualMeshLoader: public Ogre::ManualResourceLoader 
    1010{ 
    1111        public: 
    12                 IVManualMeshLoader(); 
    13                 IVManualMeshLoader(IVMeshData *mData); 
    14                 ~IVManualMeshLoader();  
     12                ObjManualMeshLoader(); 
     13                ObjManualMeshLoader(ObjMeshData *mData); 
     14                ~ObjManualMeshLoader();  
    1515 
    1616                void loadResource(Ogre::Resource *resource); 
     
    1818                Ogre::AxisAlignedBox *getBoundingBox(); 
    1919        private: 
    20                 IVMeshData *data; 
     20                ObjMeshData *data; 
    2121 
    2222}; 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/include/ObjMeshData.h

    r2109 r2111  
    1 #ifndef __IVMeshData_H__ 
    2 #define __IVMeshData_H__ 
     1#ifndef __ObjMeshData_H__ 
     2#define __ObjMeshData_H__ 
    33 
    44 
    55#include <Ogre.h> 
    66 
    7 enum mIVReaderenderOperationType 
     7enum ObjReaderOpType 
    88{ 
    99        IV_ROT_INVALID = -1, 
     
    1313}; 
    1414 
    15 class __declspec(dllexport) IVMeshData 
     15class __declspec(dllexport) ObjMeshData 
    1616{ 
    1717        public:  
    18                 IVMeshData(); 
    19                 ~IVMeshData(); 
     18                ObjMeshData(); 
     19                ~ObjMeshData(); 
    2020 
    21                 IVMeshData *expand(); 
     21                ObjMeshData *expand(); 
    2222 
    2323                void collapse(); 
     
    2525                Ogre::Real *vertices, *normals, *texCoords, *indices, *normalIndices, *texCoordIndices; 
    2626                int vcnt, ncnt, tcnt, icnt, nicnt, ticnt; 
    27                 mIVReaderenderOperationType roType; 
     27                ObjReaderOpType roType; 
    2828                Ogre::AxisAlignedBox *boundingBox; 
    2929 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/include/ObjNode.h

    r2109 r2111  
    1 #ifndef __IVNode_H__ 
    2 #define __IVNode_H__ 
     1#ifndef __ObjNode_H__ 
     2#define __ObjNode_H__ 
    33 
    44 
     
    66#include <Ogre.h> 
    77 
    8 enum IVType 
     8enum ObjType 
    99{ 
    1010        IV_INVALID = -1, 
     
    1515 
    1616 
    17 class IVField 
     17class ObjField 
    1818{ 
    1919public: 
    20         IVField(); 
    21         ~IVField(); 
     20        ObjField(); 
     21        ~ObjField(); 
    2222 
    2323        char *name; 
    2424        void *value; 
    25         IVType typ; 
     25        ObjType typ; 
    2626        int cnt; 
    27         IVField *next; 
     27        ObjField *next; 
    2828}; 
    2929 
    30 class __declspec(dllexport) IVNode 
     30class __declspec(dllexport) ObjNode 
    3131{ 
    3232        public: 
    33                 IVNode(); 
    34                 IVNode(const char *s); 
    35                 ~IVNode(); 
     33                ObjNode(); 
     34                ObjNode(const char *s); 
     35                ~ObjNode(); 
    3636 
    3737                void print(int ident=0); 
    38                 void attachNode(IVNode *child); 
     38                void attachNode(ObjNode *child); 
    3939                void addField(const char *name, char *value); 
    40                 void addField(const char *name, void *value, int cnt, IVType typ); 
     40                void addField(const char *name, void *value, int cnt, ObjType typ); 
    4141 
    42                 IVNode *getParent() { return parent; } 
     42                ObjNode *getParent() { return parent; } 
    4343                char *getName() { return name; } 
    44                 IVNode *getNodeRecursive(const char *name); 
    45                 IVNode *getNextChildNode(bool reset = false); 
    46                 IVField *getField(const char *name); 
    47                 void *getField(const char *name, IVType *typ, int *cnt); 
     44                ObjNode *getNodeRecursive(const char *name); 
     45                ObjNode *getNextChildNode(bool reset = false); 
     46                ObjField *getField(const char *name); 
     47                void *getField(const char *name, ObjType *typ, int *cnt); 
    4848 
    4949        private: 
    5050                char *name; 
    51                 IVField *fields; 
    52                 IVNode *parent; 
    53                 IVNode *children; 
    54                 IVNode *next; 
     51                ObjField *fields; 
     52                ObjNode *parent; 
     53                ObjNode *children; 
     54                ObjNode *next; 
    5555 
    56                 IVNode *actual; 
     56                ObjNode *actual; 
    5757}; 
    5858 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/include/ObjReader.h

    r2110 r2111  
    1 #ifndef __mIVReader_H__ 
    2 #define __mIVReader_H__ 
     1#ifndef __ObjReader_H__ 
     2#define __ObjReader_H__ 
     3 
     4//#include <stdlib> 
     5#include <string> 
     6#include <vector> 
     7#include <Ogre.h> 
     8/*#include "ObjNode.h" 
     9#include "ObjMeshData.h" 
     10#include "ObjManualMeshLoader.h" 
     11*/ 
    312 
    413 
    5 #include "ObjNode.h" 
    6 #include "ObjMeshData.h" 
    7 #include "ObjManualMeshLoader.h" 
    8 #include "Ogre.h" 
     14namespace GtpVisibilityPreprocessor { 
    915 
    10 #define COMMENTCHAR '#' 
    11 #define BLOCKSIZE 150 
    12 #define BUFFERSIZE 256 
     16struct Triangle3; 
    1317 
     18} 
    1419 
    15 static const int validIVHeaderCnt = 2; 
     20typedef std::vector<GtpVisibilityPreprocessor::Triangle3 *> TriangleContainer; 
    1621 
    17 static const char *validIVHeader[2] = { 
    18     { "#Inventor V2.1 ascii\n" }, 
    19         { "#VRML V1.0 ascii\n" }, 
     22class __declspec(dllexport) ObjReader 
     23{ 
     24public: 
     25        ObjReader(); 
     26        ~ObjReader(); 
     27 
     28        bool LoadFile(const std::string &filename, 
     29                                  TriangleContainer &triangles) const; 
     30         
     31        const std::vector<Ogre::Entity *> &GetObjects() const; 
     32 
     33protected: 
     34 
     35        std::vector<Ogre::Entity *> mObjects; 
    2036}; 
    2137 
    22  
    23 enum IVTokenType 
    24 { 
    25         IV_TOKEN_INVALID = -1, 
    26         IV_TOKEN_STRING = 0, 
    27         IV_TOKEN_INT = 1, 
    28         IV_TOKEN_REAL = 2, 
    29         IV_TOKEN_BRACEOPEN = 3,                         // { 
    30         IV_TOKEN_BRACECLOSE = 4,                        // } 
    31         IV_TOKEN_BRACKETOPEN = 5,                       // [ 
    32         IV_TOKEN_BRACKETCLOSE = 6,                      // ] 
    33         IV_TOKEN_PARENTHESISOPEN = 7,           // ( 
    34         IV_TOKEN_PARENTHESISCLOSE = 8,          // ) 
    35         IV_TOKEN_DEF = 9,                                       // DEF 
    36         IV_TOKEN_USE = 10,                                      // USE 
    37 }; 
    38  
    39 class __declspec(dllexport) IVMeshListNode 
    40 { 
    41         public: 
    42                 IVMeshListNode(std::string name, IVManualMeshLoader *loader); 
    43                 ~IVMeshListNode(); 
    44  
    45                 void attachNewNode(std::string name, IVManualMeshLoader *loader); 
    46  
    47                 IVManualMeshLoader *getManualMeshLoader(std::string name); 
    48  
    49                 IVMeshListNode *next; 
    50  
    51         private: 
    52                 std::string name; 
    53                 IVManualMeshLoader *loader; 
    54 }; 
    55  
    56 class __declspec(dllexport) IVDefListNode 
    57 { 
    58         public: 
    59                 IVDefListNode(std::string name, IVNode *node); 
    60                 ~IVDefListNode(); 
    61  
    62                 void attachNewNode(std::string name, IVNode *node); 
    63  
    64                 IVNode *getDef(std::string name); 
    65  
    66                 IVDefListNode *next; 
    67  
    68         private: 
    69                 std::string name; 
    70                 IVNode *node; 
    71  
    72 }; 
    73  
    74 class __declspec(dllexport) IVReader 
    75 { 
    76         public: 
    77                 IVReader(); 
    78                 ~IVReader(); 
    79  
    80                 void setLog(Ogre::Log *IVLog = NULL); 
    81  
    82                 bool loadFile(const char* filename); 
    83                 void print(); 
    84 //              IVNode *getNode(const char* name); 
    85  
    86  
    87                 void buildTree(Ogre::SceneManager *sceneMgr, Ogre::SceneNode *sceneNodeRoot); 
    88  
    89                 void collapse(); 
    90  
    91                 static std::string intToStr(int num); 
    92                 static std::string realToStr(Ogre::Real num); 
    93                  
    94                 static Ogre::Log *IVLog; 
    95  
    96         private: 
    97                 bool checkHeader(const char *string); 
    98                 char buf[BUFFERSIZE]; 
    99                 int bufOffset; 
    100                 bool getNextElement(char *token, IVTokenType *type); 
    101                 void classify(char *token, IVTokenType *type); 
    102  
    103                 bool isSpace(char c); 
    104                 bool isNewline(char c); 
    105                 bool eof; 
    106                 bool isDigit(char c); 
    107                 bool isHexDigit(char c); 
    108  
    109                 IVNode *root; 
    110                 FILE* infile; 
    111  
    112                 static IVMeshListNode *meshList; 
    113                 static void addMeshToList(std::string name, IVManualMeshLoader *loader); 
    114                  
    115                 static int instanceCnt; 
    116  
    117                 int treeCnt, nodeCnt, matCnt; 
    118                 char *fileName; 
    119  
    120                 Ogre::Entity *createEntity(Ogre::SceneManager* sceneMgr, std::string name, IVMeshData *mData, Ogre::Vector3 *translation = NULL); 
    121  
    122                 void buildTree(Ogre::SceneManager *sceneMgr, Ogre::SceneNode *sceneNodeRoot, IVNode *mIVReaderoot, IVMeshData *mData = NULL, Ogre::Material *material = NULL); 
    123  
    124                 IVDefListNode *defList; 
    125                 void addDefToList(std::string name, IVNode *node); 
    126  
    127  
    128 }; 
    129  
    130  
    13138#endif 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjManualMeshLoader.cpp

    r2110 r2111  
    22#include "ObjReader.h" 
    33 
    4 IVManualMeshLoader::IVManualMeshLoader() 
     4ObjManualMeshLoader::ObjManualMeshLoader() 
    55{ 
    66        data = NULL; 
     
    88 
    99 
    10 IVManualMeshLoader::IVManualMeshLoader(IVMeshData *mData) 
     10ObjManualMeshLoader::ObjManualMeshLoader(ObjMeshData *mData): 
     11data(mData) 
    1112{ 
    12         data = mData; 
    13 /*      data = new IVMeshData(); 
    14         if ((mData->indices != NULL) && (mData->icnt > 0)) 
    15         { 
    16                 data->icnt = mData->icnt; 
    17                 data->indices = new Ogre::Real[mData->icnt]; 
    18                 memcpy(data->indices, mData->indices, mData->icnt*sizeof(Ogre::Real)); 
    19         } 
    20         if ((mData->vertices != NULL) && (mData->vcnt > 0)) 
    21         { 
    22                 data->vcnt = mData->vcnt; 
    23                 data->vertices = new Ogre::Real[mData->vcnt]; 
    24                 memcpy(data->vertices, mData->vertices, mData->vcnt*sizeof(Ogre::Real)); 
    25         } 
    26         if ((mData->normals != NULL) && (mData->vcnt > 0)) 
    27         { 
    28                 data->ncnt = mData->ncnt; 
    29                 data->normals = new Ogre::Real[mData->ncnt]; 
    30                 memcpy(data->normals, mData->normals, mData->ncnt*sizeof(Ogre::Real)); 
    31         } 
    32         if ((mData->texCoords != NULL) && (mData->tcnt > 0)) 
    33         { 
    34                 data->tcnt = mData->tcnt; 
    35                 data->texCoords = new Ogre::Real[mData->tcnt]; 
    36                 memcpy(data->texCoords, mData->texCoords, mData->tcnt*sizeof(Ogre::Real)); 
    37         } 
    38         */ 
    3913} 
    4014 
    41 IVManualMeshLoader::~IVManualMeshLoader() 
     15 
     16ObjManualMeshLoader::~ObjManualMeshLoader() 
    4217{ 
    43 /*      if (data != NULL) 
    44         { 
    45                 if (data->vertices != NULL)             delete [] data->vertices; 
    46                 if (data->normals != NULL)              delete [] data->normals; 
    47                 if (data->texCoords != NULL)    delete [] data->texCoords; 
    48                 if (data->indices != NULL)              delete [] data->indices; 
    49                 delete data; 
    50         } 
    51         */ 
    5218        if (data != NULL) 
    5319        { 
     
    5824 
    5925 
    60 Ogre::AxisAlignedBox *IVManualMeshLoader::getBoundingBox() 
     26Ogre::AxisAlignedBox *ObjManualMeshLoader::getBoundingBox() 
    6127{ 
    6228        return data->boundingBox; 
     
    6430 
    6531 
    66 void IVManualMeshLoader::loadResource(Ogre::Resource *resource) 
     32void ObjManualMeshLoader::loadResource(Ogre::Resource *resource) 
    6733{ 
    6834        using namespace Ogre; 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjMeshData.cpp

    r2110 r2111  
    33 
    44 
    5 IVMeshData::IVMeshData() 
     5ObjMeshData::ObjMeshData() 
    66{  
    77        vertices = normals = texCoords = indices = normalIndices = texCoordIndices = NULL;  
     
    1111} 
    1212 
    13 IVMeshData::~IVMeshData() 
     13ObjMeshData::~ObjMeshData() 
    1414{  
    1515} 
    1616 
    17 void IVMeshData::collapse() 
     17void ObjMeshData::collapse() 
    1818{ 
    1919        if (indices != NULL)    delete [] indices; 
     
    2828} 
    2929 
    30 int IVMeshData::getSeparatorCnt(Ogre::Real *data, int end) 
     30int ObjMeshData::getSeparatorCnt(Ogre::Real *data, int end) 
    3131{ 
    3232        int cnt = 0; 
     
    3535} 
    3636 
    37 Ogre::AxisAlignedBox *IVMeshData::calcBoundingBox() 
     37Ogre::AxisAlignedBox *ObjMeshData::calcBoundingBox() 
    3838{ 
    3939        if ((vertices == NULL) || (vcnt <=0))  
     
    5858 
    5959 
    60 Ogre::Real *IVMeshData::expandTriangleStripIndices(Ogre::Real *indices, int icnt, int *icntOut) 
     60Ogre::Real *ObjMeshData::expandTriangleStripIndices(Ogre::Real *indices, int icnt, int *icntOut) 
    6161{ 
    6262        if (indices[icnt-1] >= 0.0) 
     
    9494}        
    9595 
    96 int IVMeshData::getNextFaceSize(int start) 
     96 
     97int ObjMeshData::getNextFaceSize(int start) 
    9798{ 
    9899        for (int i=start; i < icnt; i++)  
     
    103104} 
    104105 
    105 Ogre::Real *IVMeshData::expandFaceSetIndices(Ogre::Real *indices, int icnt, int *icntOut) 
     106 
     107Ogre::Real *ObjMeshData::expandFaceSetIndices(Ogre::Real *indices, int icnt, int *icntOut) 
    106108{ 
    107109        if (indices[icnt-1] >= 0.0) 
     
    126128} 
    127129 
    128 IVMeshData *IVMeshData::expand() 
     130ObjMeshData *ObjMeshData::expand() 
    129131{ 
    130132        using namespace Ogre; 
    131133 
    132         IVMeshData *mDataOut = new IVMeshData(); 
     134        ObjMeshData *mDataOut = new ObjMeshData(); 
    133135 
    134136        mDataOut->boundingBox = calcBoundingBox(); 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjNode.cpp

    r2110 r2111  
    22#include "ObjReader.h" 
    33 
    4 IVField::IVField() 
     4ObjField::ObjField() 
    55{ 
    66        next = NULL; 
     
    99 
    1010 
    11 IVField::~IVField() 
     11ObjField::~ObjField() 
    1212{ 
    1313        if (value != NULL) free(value); 
     
    1717 
    1818 
    19 IVNode::IVNode() 
     19ObjNode::ObjNode() 
    2020{ 
    2121        parent = children = next = actual = NULL;  
     
    2525 
    2626 
    27 IVNode::IVNode(const char *s) 
     27ObjNode::ObjNode(const char *s) 
    2828{ 
    2929        name = new char[strlen(s)+1]; 
     
    3333} 
    3434 
    35 IVNode::~IVNode() 
     35ObjNode::~ObjNode() 
    3636{ 
    3737        if (name != NULL) delete[] name; 
    3838        if (fields != NULL)  
    3939        { 
    40                 IVField *help = fields, *delme = NULL; 
     40                ObjField *help = fields, *delme = NULL; 
    4141                while (help->next != NULL) 
    4242                { 
     
    4747        if (children != NULL)  
    4848        { 
    49                 IVNode *help = children, *delme = NULL; 
     49                ObjNode *help = children, *delme = NULL; 
    5050                while (help->next != NULL) 
    5151                { 
     
    6060 
    6161 
    62 void IVNode::attachNode(IVNode *child) 
     62void ObjNode::attachNode(ObjNode *child) 
    6363{ 
    6464        if (children == NULL) children = child; 
    6565        else  
    6666        { 
    67                 IVNode *help = children; 
     67                ObjNode *help = children; 
    6868                while (help->next != NULL) help = help->next; 
    6969                help->next = child; 
     
    7373 
    7474 
    75 void IVNode::print(int ident) 
     75void ObjNode::print(int ident) 
    7676{ 
    7777        if (IVReader::IVLog != NULL) 
     
    8585                IVReader::IVLog->logMessage(msg); 
    8686 
    87                 IVField *help = fields; 
     87                ObjField *help = fields; 
    8888                while (help != NULL) 
    8989                { 
     
    128128} 
    129129 
    130 void IVNode::addField(const char *name, void *value, int cnt, IVType typ) 
    131 { 
    132         IVField *newone = new IVField(); 
     130void ObjNode::addField(const char *name, void *value, int cnt, ObjType typ) 
     131{ 
     132        ObjField *newone = new ObjField(); 
    133133        newone->name = new char[strlen(name)+1]; 
    134134        strcpy(newone->name, name); 
     
    153153        else 
    154154        { 
    155                 IVField *help = fields; 
     155                ObjField *help = fields; 
    156156                while (help->next != NULL) help = help->next; 
    157157                help->next = newone; 
     
    160160 
    161161 
    162 void IVNode::addField(const char *name, char *value) 
     162void ObjNode::addField(const char *name, char *value) 
    163163{ 
    164164        addField(name, value, 1, IV_STRING); 
     
    166166 
    167167 
    168 IVNode *IVNode::getNodeRecursive(const char *name) 
     168ObjNode *ObjNode::getNodeRecursive(const char *name) 
    169169{ 
    170170        if (strcmp(name, this->name) == 0) return this; 
    171171        if (this->children != NULL) 
    172172        { 
    173                 IVNode *help = this->children->getNodeRecursive(name); 
     173                ObjNode *help = this->children->getNodeRecursive(name); 
    174174                if (help != NULL) return help; 
    175175        } 
     
    178178 
    179179 
    180 IVNode *IVNode::getNextChildNode(bool reset) 
     180ObjNode *ObjNode::getNextChildNode(bool reset) 
    181181{ 
    182182        if (reset) actual = this->children; 
     
    186186 
    187187 
    188 IVField *IVNode::getField(const char *name) 
    189 { 
    190         IVField *help = fields; 
     188ObjField *ObjNode::getField(const char *name) 
     189{ 
     190        ObjField *help = fields; 
    191191        while (help != NULL) 
    192192        { 
     
    197197} 
    198198 
    199 void *IVNode::getField(const char *name, IVType *typ, int *cnt) 
    200 { 
    201         IVField *help = fields; 
     199void *ObjNode::getField(const char *name, ObjType *typ, int *cnt) 
     200{ 
     201        ObjField *help = fields; 
    202202        while (help != NULL) 
    203203        { 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.cpp

    r2110 r2111  
    11#include "ObjReader.h" 
    2 #include <string> 
    3 #include <stdlib.h> 
    4 #include <sstream> 
    5  
    6 IVMeshListNode *IVReader::meshList = NULL; 
    7 int IVReader::instanceCnt = 0; 
    8 Ogre::Log *IVReader::IVLog = NULL; 
    9  
    10  
    11  
    12 IVMeshListNode::IVMeshListNode(std::string name, IVManualMeshLoader *loader) 
    13 { 
    14         this->name = name; 
    15         this->loader = loader; 
    16         next = NULL; 
    17 } 
    18  
    19 IVMeshListNode::~IVMeshListNode() 
    20 { 
    21         if (loader != NULL) delete loader; 
    22 } 
    23  
    24 void IVMeshListNode::attachNewNode(std::string name, IVManualMeshLoader *loader) 
    25 { 
    26         IVMeshListNode *help = this; 
    27  
    28         while (help->next != NULL) help = help->next; 
    29         help->next = new IVMeshListNode(name, loader); 
    30 } 
    31  
    32 IVManualMeshLoader *IVMeshListNode::getManualMeshLoader(std::string name) 
    33 { 
    34         IVMeshListNode *help = this; 
    35         if (help->name == name) return help->loader; 
    36         while (help->next != NULL)  
    37         { 
    38                 help = help->next; 
    39                 if (help->name == name) return help->loader; 
    40         } 
    41         return NULL; 
    42 } 
    43  
    44 IVDefListNode::IVDefListNode(std::string name, IVNode *node) 
    45 { 
    46         this->name = name; 
    47         this->node = node; 
    48         next = NULL; 
    49 } 
    50  
    51 IVDefListNode::~IVDefListNode() 
    52 { 
    53 } 
    54  
    55 void IVDefListNode::attachNewNode(std::string name, IVNode *node) 
    56 { 
    57         IVDefListNode *help = this; 
    58  
    59         while (help->next != NULL) help = help->next; 
    60         help->next = new IVDefListNode(name, node); 
    61 } 
    62  
    63 IVNode *IVDefListNode::getDef(std::string name) 
    64 { 
    65         IVDefListNode *help = this; 
    66         if (help->name == name) return help->node; 
    67         while (help->next != NULL)  
    68         { 
    69                 help = help->next; 
    70                 if (help->name == name) return help->node; 
    71         } 
    72         return NULL; 
    73 } 
    74  
    75 IVReader::IVReader() 
    76 {        
    77         root = NULL; meshList = NULL; defList = NULL; fileName = NULL; 
    78         instanceCnt++; 
    79         IVLog = NULL; 
    80 } 
    81  
    82 IVReader::~IVReader() 
    83 { 
    84         collapse(); 
    85  
    86         instanceCnt--; 
    87         if (instanceCnt == 0) if (meshList != NULL)  
    88         {        
    89                 IVMeshListNode *help = meshList, *delme = NULL; 
    90                 while (help->next != NULL) 
    91                 { 
    92                         delme = help; help = help->next; delete delme; 
    93                 } 
    94                 delete help; 
    95         } 
    96 } 
    97  
    98 void IVReader::collapse() 
    99 { 
    100         if (root != NULL) {     delete root; root = NULL; } 
    101         if (defList != NULL) 
    102         {        
    103                 IVDefListNode *help = defList, *delme = NULL; 
    104                 while (help->next != NULL) 
    105                 { 
    106                         delme = help; help = help->next; delete delme; 
    107                 } 
    108                 delete help; 
    109                 defList = NULL; 
    110         } 
    111         if (this->fileName != NULL) { delete [] this->fileName; this->fileName = NULL; } 
    112  
    113 } 
    114  
    115 void IVReader::setLog(Ogre::Log *IVLog) 
    116 { 
    117         this->IVLog = IVLog; 
    118 } 
    119  
    120 std::string IVReader::intToStr(int num) 
    121 { 
    122         std::ostringstream myStream;  
    123         myStream << num; 
    124         myStream.flush(); 
    125          
    126         return(myStream.str()); 
    127 } 
    128  
    129 std::string IVReader::realToStr(Ogre::Real num) 
    130 { 
    131         std::ostringstream myStream;  
    132         myStream << num; 
    133         myStream.flush(); 
    134          
    135         return(myStream.str()); 
    136 } 
    137  
    138 bool IVReader::loadFile(const char* fileName) 
    139 { 
    140         std::string message = "trying to load "; message = message + fileName + "..."; 
    141          
    142         if (IVLog != NULL)  
    143                 IVLog->logMessage(message); 
    144          
    145         collapse(); 
    146         this->fileName = new char[strlen(fileName)+1]; strcpy(this->fileName, fileName); 
    147         treeCnt = 0; 
    148  
    149     infile = fopen(fileName, "r"); root = NULL; 
    150  
    151         if (infile == NULL) 
    152         { 
    153                 message = "! Error loading File "; message = message + fileName + " !"; 
    154                 if (IVLog != NULL) IVLog->logMessage(message); 
     2#include "gzstream.h" 
     3#include "Triangle3.h" 
     4 
     5 
     6ObjReader::ObjReader() 
     7{} 
     8 
     9ObjReader::~ObjReader() 
     10{} 
     11 
     12 
     13bool ObjReader::LoadFile(const string &filename, 
     14                                                 TriangleContainer &triangles) const 
     15{ 
     16        igzstream samplesIn(filename.c_str()); 
     17         
     18        if (!samplesIn.is_open()) 
    15519                return false; 
    156         } 
    157  
    158         if ((fgets(buf, BUFFERSIZE, infile) == NULL) && !feof(infile))  
    159         { 
    160                 message = "! Error loading File "; message = message + fileName + " !"; 
    161                 if (IVLog != NULL) IVLog->logMessage(message); 
    162                 fclose(infile); 
    163                 return false; 
    164         } 
    165  
    166         if (!checkHeader(buf))  
    167         { 
    168                 message = "! Invalid Header !"; 
    169                 if (IVLog != NULL) IVLog->logMessage(message); 
    170                 fclose(infile); 
    171                 return false; 
    172         } 
    173  
    174         IVTokenType tmptyp = IV_TOKEN_INVALID; 
    175         eof = false;     
    176  
    177         bufOffset = 0; 
    178         char token[BUFFERSIZE] = "\0", oldtoken[BUFFERSIZE] = "\0", fieldtoken[BUFFERSIZE] = "\0"; 
    179         int level = 0;  
    180  
    181         while (getNextElement(token, &tmptyp))  
    182         { 
    183                 if (tmptyp == IV_TOKEN_BRACEOPEN)  
    184                 { 
    185                         root = new IVNode(oldtoken); 
    186                         level++; 
     20         
     21        // read in triangle size 
     22        int numTriangles; 
     23 
     24        samplesIn.read(reinterpret_cast<char *>(&numTriangles), sizeof(int)); 
     25        triangles.reserve(numTriangles); 
     26         
     27        while (1) 
     28        { 
     29                GtpVisibilityPreprocessor::Triangle3 *tri =  
     30                        new GtpVisibilityPreprocessor::Triangle3(); 
     31                 
     32                samplesIn.read(reinterpret_cast<char *>((*tri).mVertices + 0),  
     33                                           sizeof(GtpVisibilityPreprocessor::Vector3)); 
     34                samplesIn.read(reinterpret_cast<char *>((*tri).mVertices + 1),  
     35                                           sizeof(GtpVisibilityPreprocessor::Vector3)); 
     36                samplesIn.read(reinterpret_cast<char *>((*tri).mVertices + 2),  
     37                                           sizeof(GtpVisibilityPreprocessor::Vector3)); 
     38 
     39                // end of file reached 
     40                if (samplesIn.eof()) 
    18741                        break; 
    188                 } 
    189  
    190                 strcpy(oldtoken, token); 
    191         } 
    192  
    193         IVNode *actualNode = root, *parent = root, *fieldNode = root, *newNode = NULL; 
    194         IVTokenType oldtmptyp = tmptyp; 
    195         bool textfield = false, realfield = false; IVType fieldtyp = IV_INVALID; 
    196         bool def = false; std::string defLabel; 
    197         Ogre::Real rblock[BLOCKSIZE];  
    198         float *rvalues; 
    199         int cnt = 0; int blockcnt = 0; 
    200         while (getNextElement(token, &tmptyp)) 
    201         { 
    202                 if ((tmptyp == IV_TOKEN_BRACKETOPEN))  
    203                         if (!getNextElement(token, &tmptyp)) break; 
    204                 if ((tmptyp == IV_TOKEN_INVALID))  
    205                         if (!getNextElement(token, &tmptyp)) break; 
    206                 if (tmptyp == IV_TOKEN_BRACEOPEN)  
    207                 { 
    208                         actualNode = new IVNode(oldtoken);  
    209                         if (parent == NULL) 
    210                         { 
    211                                 message = "Error loading file "; message = message + fileName + "! Invalid tree structure."; 
    212                                 if (IVLog != NULL) IVLog->logMessage(message); 
    213                                 fclose(infile); 
    214                                 return false; 
    215                         } 
    216                         parent->attachNode(actualNode); 
    217                         parent = actualNode; 
    218                         level++; 
    219  
    220                         if (def) 
    221                         { 
    222                                 addDefToList(defLabel, actualNode); 
    223                                 def = false; 
    224                         } 
    225  
    226                 } else 
    227                 if (tmptyp == IV_TOKEN_BRACECLOSE)  
    228                 { 
    229                         if (realfield) 
    230                         { 
    231                                 if (blockcnt == 0) rvalues = (Ogre::Real *)malloc((cnt)*sizeof(Ogre::Real)); 
    232                                 else rvalues = (Ogre::Real *)realloc(rvalues, (BLOCKSIZE*(blockcnt) + cnt)*sizeof(Ogre::Real));                                          
    233                                 memcpy((void *)&rvalues[BLOCKSIZE*blockcnt], rblock, cnt*sizeof(Ogre::Real)); 
    234                                 fieldNode->addField(fieldtoken, rvalues, BLOCKSIZE*blockcnt+cnt, fieldtyp); 
    235                                 realfield = false; 
    236 //                              free(rvalues); 
    237                         } 
    238  
    239                         if (level > 0) 
    240                         { 
    241                                 actualNode = parent = actualNode->getParent(); 
    242                                 level--; 
    243                         } 
    244                 } else 
    245                 { 
    246                         if (oldtmptyp == IV_TOKEN_DEF) 
    247                         { 
    248                                 def = true; defLabel = ""; defLabel = defLabel + token; 
    249                         } else 
    250                         if (oldtmptyp == IV_TOKEN_USE) 
    251                         { 
    252                                         newNode = new IVNode("USE");  
    253                                         if (parent == NULL) 
    254                                         { 
    255                                                 message = "Error loading file "; message = message + fileName + "! Invalid tree structure."; 
    256                                                 if (IVLog != NULL) IVLog->logMessage(message); 
    257                                                 fclose(infile); 
    258                                                 return false; 
    259                                         } 
    260                                         char *s = (char *)malloc(sizeof(char)*(strlen(token)+1)); 
    261                                         memcpy(s, token, strlen(token)); 
    262                                         s[strlen(token)] = '\0'; 
    263                                         newNode->addField("label", s); 
    264                                         actualNode->attachNode(newNode); 
    265                         } else 
    266                         if (!def) 
    267                         if (oldtmptyp == IV_TOKEN_STRING) 
    268                         { 
    269                                 if (!textfield) 
    270                                 { 
    271                                         if (tmptyp == IV_TOKEN_STRING) 
    272                                         { 
    273 /*                                              char *s = new char[strlen(token)+1]; 
    274                                                 strcpy(s, token); 
    275 */                                               
    276                                                 char *s = (char *)malloc(sizeof(char)*(strlen(token)+1)); 
    277                                                 memcpy(s, token, strlen(token)); 
    278                                                 s[strlen(token)] = '\0'; 
    279                                                 actualNode->addField(oldtoken, s); 
    280 //                                              delete [] s; 
    281                                         } 
    282                                 } 
    283                                 if (!realfield) 
    284                                 { 
    285                                         if ((tmptyp == IV_TOKEN_REAL) || (tmptyp == IV_TOKEN_INT)) 
    286                                         {        
    287                                                 cnt = 0; blockcnt = 0; 
    288                                                 char *stopstring;                                                
    289                                                 rblock[0] = strtod(token, &stopstring); 
    290                                                 cnt++; 
    291                                                 strcpy(fieldtoken, oldtoken); 
    292                                                 fieldNode = actualNode; 
    293                                             if (tmptyp == IV_TOKEN_REAL) fieldtyp = IV_REAL; 
    294                                                 if (tmptyp == IV_TOKEN_INT)     fieldtyp = IV_INT; 
    295                                                 realfield = true; 
    296                                         } 
    297                                 } 
    298                                 textfield = !textfield; 
    299                         } 
    300                         else  
    301                         { 
    302                                 if (realfield)   
    303                                 { 
    304                                         if ((tmptyp == IV_TOKEN_REAL) || (tmptyp == IV_TOKEN_INT)) 
    305                                         {                
    306                                                 char *stopstring; 
    307                                                 if (cnt >= BLOCKSIZE)  
    308                                                 { 
    309                                                         if (blockcnt == 0) rvalues = (Ogre::Real *)malloc((BLOCKSIZE)*sizeof(Ogre::Real)); 
    310                                                         else rvalues = (Ogre::Real *)realloc(rvalues, (BLOCKSIZE*(blockcnt+1))*sizeof(Ogre::Real)); 
    311                                                         memcpy((void *)&rvalues[BLOCKSIZE*blockcnt], rblock, BLOCKSIZE*sizeof(Ogre::Real)); 
    312                                                         cnt = 0; 
    313                                                         blockcnt++; 
    314                                                          
    315                                                 } 
    316                                                 rblock[cnt] = strtod(token, &stopstring); 
    317                                                 cnt++; 
    318                                             if (tmptyp == IV_TOKEN_REAL) fieldtyp = IV_REAL; 
    319                                         } 
    320                                         else 
    321                                         { 
    322                                                 if (blockcnt == 0) rvalues = (Ogre::Real *)malloc((cnt)*sizeof(Ogre::Real)); 
    323                                                 else rvalues = (Ogre::Real *)realloc(rvalues, (BLOCKSIZE*(blockcnt) + cnt)*sizeof(Ogre::Real));                                          
    324                                                 memcpy((void *)&rvalues[BLOCKSIZE*blockcnt], rblock, cnt*sizeof(Ogre::Real)); 
    325                                                 fieldNode->addField(fieldtoken, rvalues, BLOCKSIZE*blockcnt+cnt, fieldtyp); 
    326                                                 realfield = false; 
    327 //                                              free(rvalues); 
    328                                         } 
    329                                 } 
    330                                  
    331                                 textfield = false; 
    332                         } 
    333                 } 
    334  
    335  
    336                 strcpy(oldtoken, token); 
    337                 oldtmptyp = tmptyp; 
    338         } 
    339         message = ""; ; message = message + fileName + " loaded."; 
    340         if (IVLog != NULL) IVLog->logMessage(message); 
    341         fclose(infile); 
    342  
     42 
     43                triangles.push_back(tri); 
     44        } 
     45         
    34346        return true; 
    34447} 
    34548 
    346 void IVReader::print() 
    347 { 
    348         if (root != NULL) root->print(); 
    349 } 
    350  
    351 bool IVReader::checkHeader(const char *string) 
    352 { 
    353         for (int i=0; i < validIVHeaderCnt; i++) 
    354                 if (strcmp(validIVHeader[i], string) == 0) return true; 
    355         return false; 
    356 } 
    357 bool IVReader::isSpace(char c) 
    358 { 
    359         if ((c==' ') || (c=='\t')) return true; 
    360         return false; 
    361 } 
    362 bool IVReader::isNewline(char c) 
    363 { 
    364         if (c=='\n') return true; 
    365         return false; 
    366 } 
    367 bool IVReader::isDigit(char c) 
    368 { 
    369         if ((c>=48) && (c<=57)) return true; 
    370         return false; 
    371 } 
    372 bool IVReader::isHexDigit(char c) 
    373 { 
    374         if ( ((c>=48) && (c<=57)) || ((c>=65) && (c<=70)) || ((c>=97) && (c<=102)) ) return true; 
    375         return false; 
    376 } 
    377  
    378  
    379 bool IVReader::getNextElement(char *token, IVTokenType *type) 
    380 { 
    381         if (eof) return false; 
    382         bool quoted = false; 
    383         while (isSpace(buf[bufOffset])) bufOffset++; 
    384         int i=0; 
    385         while ((!isSpace(buf[bufOffset])) || (quoted)) 
    386         { 
    387                 if (!quoted) 
    388                 { 
    389                         if (isNewline(buf[bufOffset]) || (buf[bufOffset] == COMMENTCHAR)) 
    390                         { 
    391                                 token[i] = '\0';  
    392                                 classify(token, type); 
    393                                 bufOffset = 0; 
    394                                 if (fgets(buf, BUFFERSIZE, infile) == NULL)  
    395                                 {                        
    396                                         eof = true; 
    397                                 } 
    398                                 if (i==0) return getNextElement(token, type); 
    399                                 return true; 
    400                         } 
    401                         if ((buf[bufOffset] == ',') || (buf[bufOffset] == ']')) 
    402                         { 
    403                                 token[i] = '\0'; 
    404                                 bufOffset++; 
    405                                 classify(token, type); 
    406                                 return true; 
    407                         } 
    408                  
    409                          
    410  
    411                 } else if (isNewline(buf[bufOffset])) { eof = true;     } 
    412  
    413                  
    414                 token[i] = buf[bufOffset];  
    415                 i++; 
    416                 if (buf[bufOffset] == '"')  
    417                 { 
    418                         quoted = !quoted; i--; 
    419                 } 
    420                 bufOffset++; 
    421  
    422                  
    423         } 
    424         token[i] = '\0'; 
    425         classify(token, type); 
    426         return true; 
    427 } 
    428  
    429 void IVReader::classify(char *token, IVTokenType *type) 
    430 { 
    431         bool isInt = true, isReal = true; 
    432         if (!isDigit(token[0]) && (token[0] != '-') && (token[0] != '+'))  
    433         { 
    434                 isInt = false;  
    435                 if (token[0] != '.') isReal = false;  
    436         } 
    437         int i = 1; 
    438         while ((token[i] != '\0') && isReal) 
    439         { 
    440                 if (isInt && (i!=2) && !isHexDigit(token[i]))  
    441                 { 
    442                         isInt = false; 
    443                 } 
    444                 if (isInt && (i==2) && !isHexDigit(token[i]) && (token[i] != 'x') && (token[i] != 'X')) isInt = false; 
    445                 if (isReal && (!isDigit(token[i])) && (token[i] != '.') && (token[i] != 'e') && (token[i] != 'E') && (token[i] != 'd') && (token[i] != 'D') && (token[i] != '-') && (token[i] != '+')) isReal = false; 
    446                 i++; 
    447         } 
    448         if (isInt) *type = IV_TOKEN_INT;  
    449         else if (isReal) *type = IV_TOKEN_REAL; 
    450         else *type = IV_TOKEN_STRING; 
    451  
    452         if (strcmp(token, "DEF") == 0) *type = IV_TOKEN_DEF; 
    453         if (strcmp(token, "USE") == 0) *type = IV_TOKEN_USE; 
    454  
    455         if (token[1] == '\0') 
    456         { 
    457                 if (token[0] == '{') *type = IV_TOKEN_BRACEOPEN; 
    458                 if (token[0] == '}') *type = IV_TOKEN_BRACECLOSE; 
    459                 if (token[0] == '[') *type = IV_TOKEN_BRACKETOPEN; 
    460                 if (token[0] == ']') *type = IV_TOKEN_BRACKETCLOSE; 
    461                 if (token[0] == '(') *type = IV_TOKEN_PARENTHESISOPEN; 
    462                 if (token[0] == ')') *type = IV_TOKEN_PARENTHESISCLOSE; 
    463         } 
    464         if (token[0] == '\0') 
    465         { 
    466                 *type = IV_TOKEN_INVALID; 
    467         } 
    468  
    469 } 
    470  
    471 /* 
    472 IVNode *IVReader::getNode(const char* name) 
    473 { 
    474         return root->getNodeRecursive(name); 
    475 } 
    476 */ 
    477 void IVReader::addMeshToList(std::string name, IVManualMeshLoader *loader) 
    478 {        
    479         if (meshList == NULL)  
    480         { 
    481                 meshList = new IVMeshListNode(name, loader); 
    482         } 
    483         else 
    484         { 
    485                 meshList->attachNewNode(name, loader); 
    486         } 
    487 } 
    488  
    489 void IVReader::addDefToList(std::string name, IVNode *node) 
    490 {        
    491         if (defList == NULL)  
    492         { 
    493                 defList = new IVDefListNode(name, node); 
    494         } 
    495         else 
    496         { 
    497                 defList->attachNewNode(name, node); 
    498         } 
    499 } 
    500  
    501 Ogre::Entity *IVReader::createEntity(Ogre::SceneManager* sceneMgr, std::string name, IVMeshData *mData, Ogre::Vector3 *translation) 
     49 
     50const std::vector<Ogre::Entity *> &ObjReader::GetObjects() const 
     51{ 
     52        return mObjects; 
     53} 
     54 
     55 
     56#if TODO 
     57 
     58Ogre::Entity *IVReader::createEntity(Ogre::SceneManager* sceneMgr, std::string name, ObjMeshData *mData, Ogre::Vector3 *translation) 
    50259{ 
    50360        using namespace Ogre; 
     
    51067        { 
    51168 
    512                 IVMeshData *data = mData->expand(); 
    513  
    514                 IVManualMeshLoader *loader      = new IVManualMeshLoader(data); 
     69                ObjMeshData *data = mData->expand(); 
     70 
     71                ObjManualMeshLoader *loader     = new ObjManualMeshLoader(data); 
    51572 
    51673                if (translation != NULL) *translation = data->boundingBox->getCenter(); 
     
    544101 
    545102 
    546  
    547 void IVReader::buildTree(Ogre::SceneManager* sceneMgr,  Ogre::SceneNode *sceneNodeRoot) 
     103void IVReader::buildTree(Ogre::SceneManager* sceneMgr, Ogre::SceneNode *sceneNodeRoot) 
    548104{ 
    549105        using namespace Ogre; 
     
    575131void IVReader::buildTree(Ogre::SceneManager* sceneMgr,   
    576132                                                 Ogre::SceneNode *sceneNodeRoot,  
    577                                                  IVNode *IVReaderoot, IVMeshData *mData,  
     133                                                 ObjNode *IVReaderoot, ObjMeshData *mData,  
    578134                                                 Ogre::Material *material) 
    579135{ 
     
    585141        if (mData == NULL) 
    586142        { 
    587                 mData = new IVMeshData(); 
     143                mData = new ObjMeshData(); 
    588144                meshDataCreated = true; 
    589145        } 
    590146 
    591         IVType t; int i; 
    592          
    593         IVNode *help = IVReaderoot->getNextChildNode(true); 
     147        ObjType t; int i; 
     148         
     149        ObjNode *help = IVReaderoot->getNextChildNode(true); 
    594150        while (help != NULL) 
    595151        {        
     
    743299                        if (t != IV_INT) mData->texCoordIndices = NULL; 
    744300 
    745                         IVNode *n = help->getNextChildNode(true); 
     301                        ObjNode *n = help->getNextChildNode(true); 
    746302                        while ((n != NULL) && (strcmp(help->getName(), "VertexProperty") == 0)) 
    747303                        { 
     
    775331        if (meshDataCreated) if (mData != NULL) delete mData; 
    776332} 
    777  
     333#endif 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.vcproj

    r2110 r2111  
    7272                        <Tool 
    7373                                Name="VCCLCompilerTool" 
    74                                 AdditionalIncludeDirectories="&quot;$(OGRE_PATH)\Dependencies\include\CEGUI&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\include&quot;;&quot;$(OGRE_PATH)\OgreMain\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\include&quot;;..\include" 
     74                                AdditionalIncludeDirectories="&quot;$(OGRE_PATH)\OgreMain\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\include&quot;;..\include;..\..\..\Preprocessing\src" 
    7575                                PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;OBJREADER_EXPORTS;GTP_VISIBILITY_MODIFIED_OGRE;GAMETOOLS_ILLUMINATION_MODULE" 
    7676                                RuntimeLibrary="2" 
     
    8383                        <Tool 
    8484                                Name="VCLinkerTool" 
    85                                 AdditionalDependencies="OgreMain.lib CEGUIBase.lib OgreGUIRenderer.lib" 
    86                                 OutputFile="$(OutDir)/ObjReader.dll" 
    87                                 LinkIncremental="1" 
    88                                 AdditionalLibraryDirectories="&quot;$(OGRE_PATH)\OgreMain\lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\lib&quot;;&quot;..\..\GtpVisibility\lib\$(ConfigurationName)&quot;;&quot;..\..\lib\$(ConfigurationName)&quot;;&quot;..\lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Dependencies\lib\$(ConfigurationName)&quot;" 
     85                                AdditionalDependencies="OgreMain.lib zdll.lib zziplib.lib Preprocessor.lib xerces-c_2.lib" 
     86                                OutputFile="$(OutDir)/ObjReader.dll" 
     87                                LinkIncremental="1" 
     88                                AdditionalLibraryDirectories="&quot;$(OGRE_PATH)\OgreMain\lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Dependencies\lib\$(ConfigurationName)&quot;;&quot;..\..\lib\$(ConfigurationName)&quot;;&quot;..\lib\$(ConfigurationName)&quot;;&quot;..\..\..\Preprocessing\lib\$(ConfigurationName)&quot;;..\..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib" 
    8989                                GenerateDebugInformation="FALSE" 
    9090                                SubSystem="2" 
     
    339339                        UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> 
    340340                        <File 
    341                                 RelativePath="..\src\ObjManualMeshLoader.cpp"> 
    342                         </File> 
    343                         <File 
    344                                 RelativePath="..\src\ObjMeshData.cpp"> 
    345                         </File> 
    346                         <File 
    347                                 RelativePath="..\src\ObjNode.cpp"> 
    348                         </File> 
    349                         <File 
    350341                                RelativePath="..\src\ObjReader.cpp"> 
    351342                        </File> 
     
    356347                        UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"> 
    357348                        <File 
    358                                 RelativePath="..\include\ObjManualMeshLoader.h"> 
    359                         </File> 
    360                         <File 
    361                                 RelativePath="..\include\ObjMeshData.h"> 
    362                         </File> 
    363                         <File 
    364                                 RelativePath="..\include\ObjNode.h"> 
    365                         </File> 
    366                         <File 
    367349                                RelativePath="..\include\ObjReader.h"> 
    368350                        </File> 
Note: See TracChangeset for help on using the changeset viewer.