00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef VRS_CONTAINER_PACKEDCOLORITERATOR_H
00029 #define VRS_CONTAINER_PACKEDCOLORITERATOR_H
00030
00031 #include <vrs/container/iterator.h>
00032 #include <vrs/color.h>
00033 #include <vector>
00034
00035 namespace VRS {
00036
00044 template<typename COLOR>
00045 class PackedColorIteratorBase :
00046 public Iterator<COLOR>
00047 {
00048 public:
00049 VRS_TYPEINFO(PackedColorIteratorBase, Iterator<COLOR>);
00050 VRS_SERIALIZABLE(PackedColorIteratorBase);
00051
00052 public:
00053 PackedColorIteratorBase(
00054 SO<Iterator<Color> > colors
00055 ) :
00056 Iterator<Color>(),
00057 m_colors()
00058 {
00059 if(!colors || (colors->size() == 0)) { return; }
00060
00061 m_colors.resize(colors->size());
00062 for(unsigned int i = 0, iEnd = colors->size(); i < iEnd; ++i) {
00063 const Color c = colors->get(i);
00064 m_colors[i] = Color4ub(
00065 static_cast<unsigned char>(c[0] * 255.0 + 0.5),
00066 static_cast<unsigned char>(c[1] * 255.0 + 0.5),
00067 static_cast<unsigned char>(c[2] * 255.0 + 0.5),
00068 static_cast<unsigned char>(c[3] * 255.0 + 0.5)
00069 );
00070 }
00071 }
00072
00073 public:
00074 virtual unsigned int size() const {
00075 return m_colors.size();
00076 }
00077
00078 virtual COLOR get(
00079 unsigned int i
00080 ) const {
00081 return COLOR(
00082 static_cast<double>(m_colors[i][0]) / 255.0,
00083 static_cast<double>(m_colors[i][1]) / 255.0,
00084 static_cast<double>(m_colors[i][2]) / 255.0,
00085 static_cast<double>(m_colors[i][3]) / 255.0
00086 );
00087 }
00088
00089 protected:
00090 PackedColorIteratorBase() { }
00091
00092 private:
00093 typedef VertexData<4, unsigned char> Color4ub;
00094 std::vector<Color4ub> m_colors;
00095 };
00096
00097 template<typename COLOR>
00098 void PackedColorIteratorBase<COLOR>::serialize(
00099 SerializationManager& manager
00100 ) {
00101 UINT8 version = 0;
00102 manager.classVersion(version);
00103
00104 VRS_SERIALIZATION_PARENT_CLASS(manager, Iterator<COLOR>);
00105 serialization(manager, "colors", m_colors);
00106 }
00107
00108 VRS_SERIALIZATION_REGISTRATION_TEMPLATE(PackedColorIteratorBase);
00109
00110 typedef PackedColorIteratorBase<Color> PackedColorIterator;
00111
00112 }
00113
00114 #endif // VRS_CONTAINER_PACKEDCOLORITERATOR_H