| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | #include "Exception.h" |
|---|
| 16 | #include "ImageSequence.h" |
|---|
| 17 | #include "Object.h" |
|---|
| 18 | |
|---|
| 19 | #include <osg/Notify> |
|---|
| 20 | |
|---|
| 21 | using namespace ive; |
|---|
| 22 | |
|---|
| 23 | void ImageSequence::write(DataOutputStream* out) |
|---|
| 24 | { |
|---|
| 25 | |
|---|
| 26 | out->writeInt(IVEIMAGESEQUENCE); |
|---|
| 27 | |
|---|
| 28 | osg::Object* obj = dynamic_cast<osg::Object*>(this); |
|---|
| 29 | if(obj){ |
|---|
| 30 | ((ive::Object*)(obj))->write(out); |
|---|
| 31 | } |
|---|
| 32 | else |
|---|
| 33 | out_THROW_EXCEPTION("ImageSequence::write(): Could not cast this osg::ImageSequence to an osg::Object."); |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | out->writeInt(getMode()); |
|---|
| 38 | out->writeDouble(getLength()); |
|---|
| 39 | |
|---|
| 40 | out->writeUInt(getFileNames().size()); |
|---|
| 41 | for(FileNames::iterator itr = getFileNames().begin(); |
|---|
| 42 | itr != getFileNames().end(); |
|---|
| 43 | ++itr) |
|---|
| 44 | { |
|---|
| 45 | out->writeString(*itr); |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | if (getFileNames().empty()) |
|---|
| 49 | { |
|---|
| 50 | out->writeUInt(getImages().size()); |
|---|
| 51 | for(Images::iterator itr = getImages().begin(); |
|---|
| 52 | itr != getImages().end(); |
|---|
| 53 | ++itr) |
|---|
| 54 | { |
|---|
| 55 | out->writeImage(itr->get()); |
|---|
| 56 | } |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | void ImageSequence::read(DataInputStream* in) |
|---|
| 62 | { |
|---|
| 63 | |
|---|
| 64 | int id = in->peekInt(); |
|---|
| 65 | if(id == IVEIMAGESEQUENCE){ |
|---|
| 66 | |
|---|
| 67 | id = in->readInt(); |
|---|
| 68 | |
|---|
| 69 | osg::Object* obj = dynamic_cast<osg::Object*>(this); |
|---|
| 70 | if(obj){ |
|---|
| 71 | ((ive::Object*)(obj))->read(in); |
|---|
| 72 | } |
|---|
| 73 | else |
|---|
| 74 | in_THROW_EXCEPTION("ImageSequence::read(): Could not cast this osg::ImageSequence to an osg::Object."); |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | setMode((osg::ImageSequence::Mode)(in->readInt())); |
|---|
| 79 | setLength(in->readDouble()); |
|---|
| 80 | |
|---|
| 81 | unsigned int numFileNames = in->readUInt(); |
|---|
| 82 | if (numFileNames>0) |
|---|
| 83 | { |
|---|
| 84 | for(unsigned int i=0; i<numFileNames; ++i) |
|---|
| 85 | { |
|---|
| 86 | addImageFile(in->readString()); |
|---|
| 87 | } |
|---|
| 88 | } |
|---|
| 89 | else |
|---|
| 90 | { |
|---|
| 91 | unsigned int numImages = in->readUInt(); |
|---|
| 92 | for(unsigned int i=0; i<numImages; ++i) |
|---|
| 93 | { |
|---|
| 94 | addImage(in->readImage()); |
|---|
| 95 | } |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | } |
|---|
| 99 | else{ |
|---|
| 100 | in_THROW_EXCEPTION("ImageSequence::read(): Expected ImageSequence identification."); |
|---|
| 101 | } |
|---|
| 102 | } |
|---|