rtVTK  0.6.0
Texture.h
00001 
00002 /******************************************************************************
00003  * Copyright (c) 2012, Grove City College
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions are
00008  * met:
00009  * 
00010  *  * Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer.
00012  *
00013  *  * Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in
00015  *    the documentation and/or other materials provided with the
00016  *    distribution.
00017  *
00018  *  * Neither the name of Grove City College nor the names of its
00019  *    contributors may be used to endorse or promote products derived
00020  *    from this software without specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00025  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00026  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00027  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00028  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00029  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00030  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00031  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00032  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  */
00035 
00036 
00037 #ifndef Core_Texture_h
00038 #define Core_Texture_h
00039 
00040 #include <string>
00041 using std::string;
00042 
00043 #include <Math/Math.h>
00044 
00045 
00046 namespace Core
00047 {
00048 
00050   // Using declarations
00051 
00052   using MathF::Vector;
00053 
00054 
00056   // Class definition
00057 
00061   class Texture
00062   {
00063   public:
00064     Texture(const string&, float, float);
00065     Texture(const CoreF::RGB&, float, float);
00066     Texture();
00067 
00068     ~Texture();
00069 
00070     size_t size() const;
00071 
00072     bool load(const char*);
00073 
00074     bool readData(      FILE*,
00075                   const char*,
00076                         uint,
00077                         uint,
00078                         uint);
00079 
00080     CoreF::RGB getRGB(const Vector&) const;
00081 
00082     bool read(istream&);
00083     bool write(ostream&) const;
00084 
00085 
00087     // Data members
00088 
00094     uint  width;
00095     uint  height;
00096     float uscale;
00097     float vscale;
00098 
00099     CoreF::RGB*  values;
00100   };
00101 
00102   inline Texture::Texture(const string& filename,
00103                                 float   uscale_,
00104                                 float   vscale_) :
00105     width(0),
00106     height(0),
00107     uscale(uscale_),
00108     vscale(vscale_),
00109     values(0)
00110   {
00111     load(filename.c_str());
00112   }
00113 
00114   inline Texture::Texture(const CoreF::RGB& rgb,
00115                                 float         uscale_,
00116                                 float         vscale_) :
00117     width(1),
00118     height(1),
00119     uscale(uscale_),
00120     vscale(vscale_),
00121     values(new CoreF::RGB(rgb))
00122   {
00123     // no-op
00124   }
00125 
00126   inline Texture::Texture() :
00127     width(0),
00128     height(0),
00129     uscale(1.f),
00130     vscale(1.f),
00131     values(0)
00132   {
00133     // no-op
00134   }
00135 
00136   inline Texture::~Texture()
00137   {
00138     if (values)
00139       delete [] values;
00140   }
00141 
00142   inline size_t Texture::size() const
00143   {
00144     return (2*sizeof(unsigned int) +
00145             2*sizeof(float) +
00146             width*height*sizeof(CoreF::RGB));
00147   }
00148 
00149 }
00150 
00151 #endif // Core_Texture_h
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends