From a62b4e58c7f8787731b606119325c5913f5969cb Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 24 Oct 2004 14:31:07 +0000 Subject: [PATCH] From Pavel Moloshtan, speed improvments in reading and writing index arrays --- src/osgPlugins/ive/DrawElementsUByte.cpp | 81 +++++++++++------------ src/osgPlugins/ive/DrawElementsUInt.cpp | 81 +++++++++++------------ src/osgPlugins/ive/DrawElementsUShort.cpp | 81 +++++++++++------------ 3 files changed, 117 insertions(+), 126 deletions(-) diff --git a/src/osgPlugins/ive/DrawElementsUByte.cpp b/src/osgPlugins/ive/DrawElementsUByte.cpp index ed76ac209..e39835f6f 100644 --- a/src/osgPlugins/ive/DrawElementsUByte.cpp +++ b/src/osgPlugins/ive/DrawElementsUByte.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: DrawElementsUByte.cpp + * FILE: DrawElementsUByte.cpp * - * DESCRIPTION: Read/Write osg::DrawElementsUByte in binary format to disk. + * DESCRIPTION: Read/Write osg::DrawElementsUByte in binary format to disk. * - * CREATED BY: Auto generated by iveGenerated - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerated + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 20.3.2003 + * HISTORY: Created 20.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -19,46 +19,43 @@ using namespace ive; void DrawElementsUByte::write(DataOutputStream* out){ - // Write DrawElementsUByte's identification. - out->writeInt(IVEDRAWELEMENTSUBYTE); + // Write DrawElementsUByte's identification. + out->writeInt(IVEDRAWELEMENTSUBYTE); - // If the osg class is inherited by any other class we should also write this to file. - osg::PrimitiveSet* prim = dynamic_cast(this); - if(prim){ - ((ive::PrimitiveSet*)(prim))->write(out); - } - else - throw Exception("DrawElementsUByte::write(): Could not cast this osg::DrawElementsUByte to an osg::PrimitiveSet."); - // Write DrawElementsUByte's properties. + // If the osg class is inherited by any other class we should also write this to file. + osg::PrimitiveSet* prim = dynamic_cast(this); + if(prim){ + ((ive::PrimitiveSet*)(prim))->write(out); + } + else + throw Exception("DrawElementsUByte::write(): Could not cast this osg::DrawElementsUByte to an osg::PrimitiveSet."); + // Write DrawElementsUByte's properties. - // Write array length and its elements. - out->writeInt(size()); - for(unsigned int i=0; iwriteUChar((*this)[i]); - } + // Write array length and its elements. + out->writeInt(size()); + out->writeCharArray((const char*)&front(), size() * CHARSIZE); } void DrawElementsUByte::read(DataInputStream* in){ - // Read DrawElementsUByte's identification. - int id = in->peekInt(); - if(id == IVEDRAWELEMENTSUBYTE){ - // Code to read DrawElementsUByte's properties. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::PrimitiveSet* prim = dynamic_cast(this); - if(prim){ - ((ive::PrimitiveSet*)(prim))->read(in); - } - else - throw Exception("DrawElementsUByte::read(): Could not cast this osg::DrawElementsUByte to an osg::PrimtiveSet."); + // Read DrawElementsUByte's identification. + int id = in->peekInt(); + if(id == IVEDRAWELEMENTSUBYTE){ + // Code to read DrawElementsUByte's properties. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::PrimitiveSet* prim = dynamic_cast(this); + if(prim){ + ((ive::PrimitiveSet*)(prim))->read(in); + } + else + throw Exception("DrawElementsUByte::read(): Could not cast this osg::DrawElementsUByte to an osg::PrimtiveSet."); - // Read array length and its elements. - int size = in->readInt(); - for(int i=0; ireadUChar()); - } - } - else{ - throw Exception("DrawElementsUByte::read(): Expected DrawElementsUByte identification."); - } + // Read array length and its elements. + int size = in->readInt(); + resize(size); + in->readCharArray((char*)&front(), size * CHARSIZE); + } + else{ + throw Exception("DrawElementsUByte::read(): Expected DrawElementsUByte identification."); + } } diff --git a/src/osgPlugins/ive/DrawElementsUInt.cpp b/src/osgPlugins/ive/DrawElementsUInt.cpp index 6ed1be61d..cc1647224 100644 --- a/src/osgPlugins/ive/DrawElementsUInt.cpp +++ b/src/osgPlugins/ive/DrawElementsUInt.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: DrawElementsUInt.cpp + * FILE: DrawElementsUInt.cpp * - * DESCRIPTION: Read/Write osg::DrawElementsUInt in binary format to disk. + * DESCRIPTION: Read/Write osg::DrawElementsUInt in binary format to disk. * - * CREATED BY: Copied from DrawElementsUShort.cpp by Marco Jez - * + * CREATED BY: Copied from DrawElementsUShort.cpp by Marco Jez + * * - * HISTORY: Created 20.3.2003 + * HISTORY: Created 20.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -19,46 +19,43 @@ using namespace ive; void DrawElementsUInt::write(DataOutputStream* out){ - // Write DrawElementsUInt's identification. - out->writeInt(IVEDRAWELEMENTSUINT); + // Write DrawElementsUInt's identification. + out->writeInt(IVEDRAWELEMENTSUINT); - // If the osg class is inherited by any other class we should also write this to file. - osg::PrimitiveSet* prim = dynamic_cast(this); - if(prim){ - ((ive::PrimitiveSet*)(prim))->write(out); - } - else - throw Exception("DrawElementsUInt::write(): Could not cast this osg::DrawElementsUInt to an osg::PrimitiveSet."); - // Write DrawElementsUInt's properties. + // If the osg class is inherited by any other class we should also write this to file. + osg::PrimitiveSet* prim = dynamic_cast(this); + if(prim){ + ((ive::PrimitiveSet*)(prim))->write(out); + } + else + throw Exception("DrawElementsUInt::write(): Could not cast this osg::DrawElementsUInt to an osg::PrimitiveSet."); + // Write DrawElementsUInt's properties. - // Write array length and its elements. - out->writeInt(size()); - for(unsigned int i=0; iwriteUInt((*this)[i]); - } + // Write array length and its elements. + out->writeInt(size()); + out->writeCharArray((const char*)&front(), size() * INTSIZE); } void DrawElementsUInt::read(DataInputStream* in){ - // Read DrawElementsUInt's identification. - int id = in->peekInt(); - if(id == IVEDRAWELEMENTSUINT){ - // Code to read DrawElementsUInt's properties. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::PrimitiveSet* prim = dynamic_cast(this); - if(prim){ - ((ive::PrimitiveSet*)(prim))->read(in); - } - else - throw Exception("DrawElementsUInt::read(): Could not cast this osg::DrawElementsUInt to an osg::PrimtiveSet."); + // Read DrawElementsUInt's identification. + int id = in->peekInt(); + if(id == IVEDRAWELEMENTSUINT){ + // Code to read DrawElementsUInt's properties. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::PrimitiveSet* prim = dynamic_cast(this); + if(prim){ + ((ive::PrimitiveSet*)(prim))->read(in); + } + else + throw Exception("DrawElementsUInt::read(): Could not cast this osg::DrawElementsUInt to an osg::PrimtiveSet."); - // Read array length and its elements. - int size = in->readInt(); - for(int i=0; ireadUInt()); - } - } - else{ - throw Exception("DrawElementsUInt::read(): Expected DrawElementsUInt identification."); - } + // Read array length and its elements. + int size = in->readInt(); + resize(size); + in->readCharArray((char*)&front(), size * INTSIZE); + } + else{ + throw Exception("DrawElementsUInt::read(): Expected DrawElementsUInt identification."); + } } diff --git a/src/osgPlugins/ive/DrawElementsUShort.cpp b/src/osgPlugins/ive/DrawElementsUShort.cpp index f2f10c9ac..f497edcd7 100644 --- a/src/osgPlugins/ive/DrawElementsUShort.cpp +++ b/src/osgPlugins/ive/DrawElementsUShort.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: DrawElementsUShort.cpp + * FILE: DrawElementsUShort.cpp * - * DESCRIPTION: Read/Write osg::DrawElementsUShort in binary format to disk. + * DESCRIPTION: Read/Write osg::DrawElementsUShort in binary format to disk. * - * CREATED BY: Auto generated by iveGenerated - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerated + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 20.3.2003 + * HISTORY: Created 20.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -19,46 +19,43 @@ using namespace ive; void DrawElementsUShort::write(DataOutputStream* out){ - // Write DrawElementsUShort's identification. - out->writeInt(IVEDRAWELEMENTSUSHORT); + // Write DrawElementsUShort's identification. + out->writeInt(IVEDRAWELEMENTSUSHORT); - // If the osg class is inherited by any other class we should also write this to file. - osg::PrimitiveSet* prim = dynamic_cast(this); - if(prim){ - ((ive::PrimitiveSet*)(prim))->write(out); - } - else - throw Exception("DrawElementsUShort::write(): Could not cast this osg::DrawElementsUShort to an osg::PrimitiveSet."); - // Write DrawElementsUShort's properties. + // If the osg class is inherited by any other class we should also write this to file. + osg::PrimitiveSet* prim = dynamic_cast(this); + if(prim){ + ((ive::PrimitiveSet*)(prim))->write(out); + } + else + throw Exception("DrawElementsUShort::write(): Could not cast this osg::DrawElementsUShort to an osg::PrimitiveSet."); + // Write DrawElementsUShort's properties. - // Write array length and its elements. - out->writeInt(size()); - for(unsigned int i=0; iwriteUShort((*this)[i]); - } + // Write array length and its elements. + out->writeInt(size()); + out->writeCharArray((const char*)&front(), size() * SHORTSIZE); } void DrawElementsUShort::read(DataInputStream* in){ - // Read DrawElementsUShort's identification. - int id = in->peekInt(); - if(id == IVEDRAWELEMENTSUSHORT){ - // Code to read DrawElementsUShort's properties. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::PrimitiveSet* prim = dynamic_cast(this); - if(prim){ - ((ive::PrimitiveSet*)(prim))->read(in); - } - else - throw Exception("DrawElementsUShort::read(): Could not cast this osg::DrawElementsUShort to an osg::PrimtiveSet."); + // Read DrawElementsUShort's identification. + int id = in->peekInt(); + if(id == IVEDRAWELEMENTSUSHORT){ + // Code to read DrawElementsUShort's properties. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::PrimitiveSet* prim = dynamic_cast(this); + if(prim){ + ((ive::PrimitiveSet*)(prim))->read(in); + } + else + throw Exception("DrawElementsUShort::read(): Could not cast this osg::DrawElementsUShort to an osg::PrimtiveSet."); - // Read array length and its elements. - int size = in->readInt(); - for(int i=0; ireadUShort()); - } - } - else{ - throw Exception("DrawElementsUShort::read(): Expected DrawElementsUShort identification."); - } + // Read array length and its elements. + int size = in->readInt(); + resize(size); + in->readCharArray((char*)&front(), size * SHORTSIZE); + } + else{ + throw Exception("DrawElementsUShort::read(): Expected DrawElementsUShort identification."); + } }