Changeset 3524

Show
Ignore:
Timestamp:
10/24/04 16:31:07 (9 years ago)
Author:
robert
Message:

From Pavel Moloshtan, speed improvments in reading and writing index arrays

Location:
OpenSceneGraph/trunk/src/osgPlugins/ive
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgPlugins/ive/DrawElementsUByte.cpp

    r3433 r3524  
    11/********************************************************************** 
    22 * 
    3  *      FILE:                   DrawElementsUByte.cpp 
     3 *    FILE:            DrawElementsUByte.cpp 
    44 * 
    5  *      DESCRIPTION:    Read/Write osg::DrawElementsUByte in binary format to disk. 
     5 *    DESCRIPTION:    Read/Write osg::DrawElementsUByte in binary format to disk. 
    66 * 
    7  *      CREATED BY:             Auto generated by iveGenerated 
    8  *                                      and later modified by Rune Schmidt Jensen. 
     7 *    CREATED BY:        Auto generated by iveGenerated 
     8 *                    and later modified by Rune Schmidt Jensen. 
    99 * 
    10  *      HISTORY:                Created 20.3.2003 
     10 *    HISTORY:        Created 20.3.2003 
    1111 * 
    12  *      Copyright 2003 VR-C 
     12 *    Copyright 2003 VR-C 
    1313 **********************************************************************/ 
    1414 
     
    2020 
    2121void DrawElementsUByte::write(DataOutputStream* out){ 
    22         // Write DrawElementsUByte's identification. 
    23         out->writeInt(IVEDRAWELEMENTSUBYTE); 
     22    // Write DrawElementsUByte's identification. 
     23    out->writeInt(IVEDRAWELEMENTSUBYTE); 
    2424 
    25         // If the osg class is inherited by any other class we should also write this to file. 
    26         osg::PrimitiveSet*  prim = dynamic_cast<osg::PrimitiveSet*>(this); 
    27         if(prim){ 
    28                 ((ive::PrimitiveSet*)(prim))->write(out); 
    29         } 
    30         else 
    31                 throw Exception("DrawElementsUByte::write(): Could not cast this osg::DrawElementsUByte to an osg::PrimitiveSet."); 
    32         // Write DrawElementsUByte's properties. 
     25    // If the osg class is inherited by any other class we should also write this to file. 
     26    osg::PrimitiveSet*  prim = dynamic_cast<osg::PrimitiveSet*>(this); 
     27    if(prim){ 
     28        ((ive::PrimitiveSet*)(prim))->write(out); 
     29    } 
     30    else 
     31        throw Exception("DrawElementsUByte::write(): Could not cast this osg::DrawElementsUByte to an osg::PrimitiveSet."); 
     32    // Write DrawElementsUByte's properties. 
    3333 
    34         // Write array length and its elements. 
    35         out->writeInt(size()); 
    36         for(unsigned int i=0; i<size(); i++){ 
    37                 out->writeUChar((*this)[i]); 
    38         } 
     34    // Write array length and its elements. 
     35    out->writeInt(size()); 
     36    out->writeCharArray((const char*)&front(), size() * CHARSIZE); 
    3937} 
    4038 
    4139void DrawElementsUByte::read(DataInputStream* in){ 
    42         // Read DrawElementsUByte's identification. 
    43         int id = in->peekInt(); 
    44         if(id == IVEDRAWELEMENTSUBYTE){ 
    45                 // Code to read DrawElementsUByte's properties. 
    46                 id = in->readInt(); 
    47                 // If the osg class is inherited by any other class we should also read this from file. 
    48                 osg::PrimitiveSet*  prim = dynamic_cast<osg::PrimitiveSet*>(this); 
    49                 if(prim){ 
    50                         ((ive::PrimitiveSet*)(prim))->read(in); 
    51                 } 
    52                 else 
    53                         throw Exception("DrawElementsUByte::read(): Could not cast this osg::DrawElementsUByte to an osg::PrimtiveSet."); 
     40    // Read DrawElementsUByte's identification. 
     41    int id = in->peekInt(); 
     42    if(id == IVEDRAWELEMENTSUBYTE){ 
     43        // Code to read DrawElementsUByte's properties. 
     44        id = in->readInt(); 
     45        // If the osg class is inherited by any other class we should also read this from file. 
     46        osg::PrimitiveSet*  prim = dynamic_cast<osg::PrimitiveSet*>(this); 
     47        if(prim){ 
     48            ((ive::PrimitiveSet*)(prim))->read(in); 
     49        } 
     50        else 
     51            throw Exception("DrawElementsUByte::read(): Could not cast this osg::DrawElementsUByte to an osg::PrimtiveSet."); 
    5452 
    55                 // Read array length and its elements. 
    56                 int size = in->readInt(); 
    57                 for(int i=0; i<size; i++){ 
    58                         push_back(in->readUChar()); 
    59                 } 
    60         } 
    61         else{ 
    62                 throw Exception("DrawElementsUByte::read(): Expected DrawElementsUByte identification."); 
    63         } 
     53        // Read array length and its elements. 
     54        int size = in->readInt(); 
     55        resize(size); 
     56        in->readCharArray((char*)&front(), size * CHARSIZE); 
     57    } 
     58    else{ 
     59        throw Exception("DrawElementsUByte::read(): Expected DrawElementsUByte identification."); 
     60    } 
    6461} 
  • OpenSceneGraph/trunk/src/osgPlugins/ive/DrawElementsUInt.cpp

    r3433 r3524  
    11/********************************************************************** 
    22 * 
    3  *      FILE:                   DrawElementsUInt.cpp 
     3 *    FILE:            DrawElementsUInt.cpp 
    44 * 
    5  *      DESCRIPTION:    Read/Write osg::DrawElementsUInt in binary format to disk. 
     5 *    DESCRIPTION:    Read/Write osg::DrawElementsUInt in binary format to disk. 
    66 * 
    7  *      CREATED BY:             Copied from DrawElementsUShort.cpp by Marco Jez 
    8  *                                       
     7 *    CREATED BY:        Copied from DrawElementsUShort.cpp by Marco Jez 
     8 *                     
    99 * 
    10  *      HISTORY:                Created 20.3.2003 
     10 *    HISTORY:        Created 20.3.2003 
    1111 * 
    12  *      Copyright 2003 VR-C 
     12 *    Copyright 2003 VR-C 
    1313 **********************************************************************/ 
    1414 
     
    2020 
    2121void DrawElementsUInt::write(DataOutputStream* out){ 
    22         // Write DrawElementsUInt's identification. 
    23         out->writeInt(IVEDRAWELEMENTSUINT); 
     22    // Write DrawElementsUInt's identification. 
     23    out->writeInt(IVEDRAWELEMENTSUINT); 
    2424 
    25         // If the osg class is inherited by any other class we should also write this to file. 
    26         osg::PrimitiveSet*  prim = dynamic_cast<osg::PrimitiveSet*>(this); 
    27         if(prim){ 
    28                 ((ive::PrimitiveSet*)(prim))->write(out); 
    29         } 
    30         else 
    31                 throw Exception("DrawElementsUInt::write(): Could not cast this osg::DrawElementsUInt to an osg::PrimitiveSet."); 
    32         // Write DrawElementsUInt's properties. 
     25    // If the osg class is inherited by any other class we should also write this to file. 
     26    osg::PrimitiveSet*  prim = dynamic_cast<osg::PrimitiveSet*>(this); 
     27    if(prim){ 
     28        ((ive::PrimitiveSet*)(prim))->write(out); 
     29    } 
     30    else 
     31        throw Exception("DrawElementsUInt::write(): Could not cast this osg::DrawElementsUInt to an osg::PrimitiveSet."); 
     32    // Write DrawElementsUInt's properties. 
    3333 
    34         // Write array length and its elements. 
    35         out->writeInt(size()); 
    36         for(unsigned int i=0; i<size(); i++){ 
    37                 out->writeUInt((*this)[i]); 
    38         } 
     34    // Write array length and its elements. 
     35    out->writeInt(size()); 
     36    out->writeCharArray((const char*)&front(), size() * INTSIZE); 
    3937} 
    4038 
    4139void DrawElementsUInt::read(DataInputStream* in){ 
    42         // Read DrawElementsUInt's identification. 
    43         int id = in->peekInt(); 
    44         if(id == IVEDRAWELEMENTSUINT){ 
    45                 // Code to read DrawElementsUInt's properties. 
    46                 id = in->readInt(); 
    47                 // If the osg class is inherited by any other class we should also read this from file. 
    48                 osg::PrimitiveSet*  prim = dynamic_cast<osg::PrimitiveSet*>(this); 
    49                 if(prim){ 
    50                         ((ive::PrimitiveSet*)(prim))->read(in); 
    51                 } 
    52                 else 
    53                         throw Exception("DrawElementsUInt::read(): Could not cast this osg::DrawElementsUInt to an osg::PrimtiveSet."); 
     40    // Read DrawElementsUInt's identification. 
     41    int id = in->peekInt(); 
     42    if(id == IVEDRAWELEMENTSUINT){ 
     43        // Code to read DrawElementsUInt's properties. 
     44        id = in->readInt(); 
     45        // If the osg class is inherited by any other class we should also read this from file. 
     46        osg::PrimitiveSet*  prim = dynamic_cast<osg::PrimitiveSet*>(this); 
     47        if(prim){ 
     48            ((ive::PrimitiveSet*)(prim))->read(in); 
     49        } 
     50        else 
     51            throw Exception("DrawElementsUInt::read(): Could not cast this osg::DrawElementsUInt to an osg::PrimtiveSet."); 
    5452 
    55                 // Read array length and its elements. 
    56                 int size = in->readInt(); 
    57                 for(int i=0; i<size; i++){ 
    58                         push_back(in->readUInt()); 
    59                 } 
    60         } 
    61         else{ 
    62                 throw Exception("DrawElementsUInt::read(): Expected DrawElementsUInt identification."); 
    63         } 
     53        // Read array length and its elements. 
     54        int size = in->readInt(); 
     55        resize(size); 
     56        in->readCharArray((char*)&front(), size * INTSIZE); 
     57    } 
     58    else{ 
     59        throw Exception("DrawElementsUInt::read(): Expected DrawElementsUInt identification."); 
     60    } 
    6461} 
  • OpenSceneGraph/trunk/src/osgPlugins/ive/DrawElementsUShort.cpp

    r3433 r3524  
    11/********************************************************************** 
    22 * 
    3  *      FILE:                   DrawElementsUShort.cpp 
     3 *    FILE:            DrawElementsUShort.cpp 
    44 * 
    5  *      DESCRIPTION:    Read/Write osg::DrawElementsUShort in binary format to disk. 
     5 *    DESCRIPTION:    Read/Write osg::DrawElementsUShort in binary format to disk. 
    66 * 
    7  *      CREATED BY:             Auto generated by iveGenerated 
    8  *                                      and later modified by Rune Schmidt Jensen. 
     7 *    CREATED BY:        Auto generated by iveGenerated 
     8 *                    and later modified by Rune Schmidt Jensen. 
    99 * 
    10  *      HISTORY:                Created 20.3.2003 
     10 *    HISTORY:        Created 20.3.2003 
    1111 * 
    12  *      Copyright 2003 VR-C 
     12 *    Copyright 2003 VR-C 
    1313 **********************************************************************/ 
    1414 
     
    2020 
    2121void DrawElementsUShort::write(DataOutputStream* out){ 
    22         // Write DrawElementsUShort's identification. 
    23         out->writeInt(IVEDRAWELEMENTSUSHORT); 
     22    // Write DrawElementsUShort's identification. 
     23    out->writeInt(IVEDRAWELEMENTSUSHORT); 
    2424 
    25         // If the osg class is inherited by any other class we should also write this to file. 
    26         osg::PrimitiveSet*  prim = dynamic_cast<osg::PrimitiveSet*>(this); 
    27         if(prim){ 
    28                 ((ive::PrimitiveSet*)(prim))->write(out); 
    29         } 
    30         else 
    31                 throw Exception("DrawElementsUShort::write(): Could not cast this osg::DrawElementsUShort to an osg::PrimitiveSet."); 
    32         // Write DrawElementsUShort's properties. 
     25    // If the osg class is inherited by any other class we should also write this to file. 
     26    osg::PrimitiveSet*  prim = dynamic_cast<osg::PrimitiveSet*>(this); 
     27    if(prim){ 
     28        ((ive::PrimitiveSet*)(prim))->write(out); 
     29    } 
     30    else 
     31        throw Exception("DrawElementsUShort::write(): Could not cast this osg::DrawElementsUShort to an osg::PrimitiveSet."); 
     32    // Write DrawElementsUShort's properties. 
    3333 
    34         // Write array length and its elements. 
    35         out->writeInt(size()); 
    36         for(unsigned int i=0; i<size(); i++){ 
    37                 out->writeUShort((*this)[i]); 
    38         } 
     34    // Write array length and its elements. 
     35    out->writeInt(size()); 
     36    out->writeCharArray((const char*)&front(), size() * SHORTSIZE); 
    3937} 
    4038 
    4139void DrawElementsUShort::read(DataInputStream* in){ 
    42         // Read DrawElementsUShort's identification. 
    43         int id = in->peekInt(); 
    44         if(id == IVEDRAWELEMENTSUSHORT){ 
    45                 // Code to read DrawElementsUShort's properties. 
    46                 id = in->readInt(); 
    47                 // If the osg class is inherited by any other class we should also read this from file. 
    48                 osg::PrimitiveSet*  prim = dynamic_cast<osg::PrimitiveSet*>(this); 
    49                 if(prim){ 
    50                         ((ive::PrimitiveSet*)(prim))->read(in); 
    51                 } 
    52                 else 
    53                         throw Exception("DrawElementsUShort::read(): Could not cast this osg::DrawElementsUShort to an osg::PrimtiveSet."); 
     40    // Read DrawElementsUShort's identification. 
     41    int id = in->peekInt(); 
     42    if(id == IVEDRAWELEMENTSUSHORT){ 
     43        // Code to read DrawElementsUShort's properties. 
     44        id = in->readInt(); 
     45        // If the osg class is inherited by any other class we should also read this from file. 
     46        osg::PrimitiveSet*  prim = dynamic_cast<osg::PrimitiveSet*>(this); 
     47        if(prim){ 
     48            ((ive::PrimitiveSet*)(prim))->read(in); 
     49        } 
     50        else 
     51            throw Exception("DrawElementsUShort::read(): Could not cast this osg::DrawElementsUShort to an osg::PrimtiveSet."); 
    5452 
    55                 // Read array length and its elements. 
    56                 int size = in->readInt(); 
    57                 for(int i=0; i<size; i++){ 
    58                         push_back(in->readUShort()); 
    59                 } 
    60         } 
    61         else{ 
    62                 throw Exception("DrawElementsUShort::read(): Expected DrawElementsUShort identification."); 
    63         } 
     53        // Read array length and its elements. 
     54        int size = in->readInt(); 
     55        resize(size); 
     56        in->readCharArray((char*)&front(), size * SHORTSIZE); 
     57    } 
     58    else{ 
     59        throw Exception("DrawElementsUShort::read(): Expected DrawElementsUShort identification."); 
     60    } 
    6461}