# Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics

[Home] [Tutorials] [All Classes] [Grouped Classes]

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# D:/VL/BuildSystem/VL_DISTRO/Visualization_Library_SDK/src/vlGraphics/IndexIterator.hpp

Go to the documentation of this file.

    00001 /**************************************************************************************/
    00002 /*                                                                                    */
    00003 /*  Visualization Library                                                             */
    00004 /*  http://www.visualizationlibrary.com                                               */
    00005 /*                                                                                    */
    00006 /*  Copyright (c) 2005-2010, Michele Bosi                                             */
    00007 /*  All rights reserved.                                                              */
    00008 /*                                                                                    */
    00009 /*  Redistribution and use in source and binary forms, with or without modification,  */
    00010 /*  are permitted provided that the following conditions are met:                     */
    00011 /*                                                                                    */
    00012 /*  - Redistributions of source code must retain the above copyright notice, this     */
    00013 /*  list of conditions and the following disclaimer.                                  */
    00014 /*                                                                                    */
    00015 /*  - Redistributions in binary form must reproduce the above copyright notice, this  */
    00016 /*  list of conditions and the following disclaimer in the documentation and/or       */
    00017 /*  other materials provided with the distribution.                                   */
    00018 /*                                                                                    */
    00019 /*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND   */
    00020 /*  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED     */
    00021 /*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE            */
    00022 /*  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR  */
    00023 /*  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    */
    00024 /*  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;      */
    00025 /*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON    */
    00026 /*  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT           */
    00027 /*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS     */
    00028 /*  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                      */
    00029 /*                                                                                    */
    00030 /**************************************************************************************/
    00031
    00032 #ifndef IndexIterator_INCLUDE_ONCE
    00033 #define IndexIterator_INCLUDE_ONCE
    00034
    00035 #include <vlCore/Object.hpp>
    00036
    00037 namespace vl
    00038 {
    00039 //-----------------------------------------------------------------------------
    00040 // IndexIteratorAbstract
    00041 //-----------------------------------------------------------------------------
    00043   class IndexIteratorAbstract: public Object
    00044   {
    00045   public:
    00046     virtual const char* className() { return "vl::IndexIteratorAbstract"; }
    00047
    00048     IndexIteratorAbstract(): mIndex(-1)
    00049     {
    00050       VL_DEBUG_SET_OBJECT_NAME()
    00051     }
    00052     int index() const { return mIndex; }
    00053     virtual bool isEnd() const = 0;
    00054     virtual bool next() = 0;
    00055
    00056   protected:
    00057     int mIndex;
    00058   };
    00059 //-----------------------------------------------------------------------------
    00060 // IndexIterator
    00061 //-----------------------------------------------------------------------------
    00063   class IndexIterator: public Object
    00064   {
    00065   public:
    00066     virtual const char* className() { return "vl::IndexIterator"; }
    00067
    00068     IndexIterator()
    00069     {
    00070       VL_DEBUG_SET_OBJECT_NAME()
    00071     }
    00072     void initialize(IndexIteratorAbstract* iterator) { mIterator = iterator; }
    00073     int  index() { return mIterator->index(); }
    00074     bool isEnd() { return mIterator->isEnd(); }
    00075     bool next()  { return mIterator->next();  }
    00076
    00077   protected:
    00078     ref<IndexIteratorAbstract> mIterator;
    00079   };
    00080 //-----------------------------------------------------------------------------
    00081 // IndexIteratorDrawArrays
    00082 //-----------------------------------------------------------------------------
    00084   class IndexIteratorDrawArrays: public IndexIteratorAbstract
    00085   {
    00086   public:
    00087     virtual const char* className() { return "vl::IndexIteratorDrawArrays"; }
    00088
    00089     IndexIteratorDrawArrays()
    00090     {
    00091       VL_DEBUG_SET_OBJECT_NAME()
    00092       initialize(0,0);
    00093     }
    00094
    00095     void initialize(int start, int count)
    00096     {
    00097       mStart  = start;
    00098       mCount  = count;
    00099       mCurPos = start;
    00100       mIndex  = start;
    00101     }
    00102
    00103     virtual bool isEnd() const
    00104     {
    00105       return mCurPos == mStart + mCount;
    00106     }
    00107
    00108     virtual bool next()
    00109     {
    00110       ++mCurPos;
    00111       mIndex = mCurPos;
    00112       return true;
    00113     }
    00114
    00115   protected:
    00116     int mStart;
    00117     int mCount;
    00118     int mCurPos;
    00119   };
    00120 //-----------------------------------------------------------------------------
    00121 // IndexIteratorElements
    00122 //-----------------------------------------------------------------------------
    00124   template<class TArray>
    00125   class IndexIteratorElements: public IndexIteratorAbstract
    00126   {
    00127   public:
    00128     virtual const char* className() { return "vl::IndexIteratorElements"; }
    00129
    00130     IndexIteratorElements()
    00131     {
    00132       VL_DEBUG_SET_OBJECT_NAME()
    00133       initialize( NULL, NULL, NULL, 0, false, 0 );
    00134     }
    00135
    00136     void initialize( TArray* idx_array, const std::vector<GLint>* p_base_vertices, const std::vector<GLsizei>* p_vert_counts,
    00137                      int base_vert, bool prim_restart_on, unsigned int prim_restart_idx )
    00138     {
    00139       mArray = idx_array;
    00140       mBaseVert = base_vert;
    00141       mpBaseVertices = p_base_vertices;
    00142       mpVertCounts   = p_vert_counts;
    00143       mBaseCount     = 0;
    00144       mBaseIdx       = 0;
    00145
    00146       mPrimRestartEnabled = prim_restart_on;
    00147       mPrimRestartIdx = prim_restart_idx;
    00148       mCurPos = 0;
    00149       if (mArray && mArray->size())
    00150       {
    00151         mIndex = mArray->at(0) + mBaseVert;
    00152       }
    00153
    00154       if (p_vert_counts)
    00155       {
    00156         VL_CHECK(p_base_vertices)
    00157         VL_CHECK( p_base_vertices->size() == p_vert_counts->size() )
    00158
    00159         mBaseCount = (*p_vert_counts)[mBaseIdx];
    00160
    00161         mIndex = (*mpBaseVertices)[mBaseIdx];
    00162       }
    00163     }
    00164
    00165     virtual bool isEnd() const
    00166     {
    00167       return mCurPos == (int)mArray->size();
    00168     }
    00169
    00170     virtual bool next()
    00171     {
    00172       ++mCurPos;
    00173       while( mCurPos < (int)mArray->size() && mArray->at(mCurPos) == mPrimRestartIdx && mPrimRestartEnabled  )
    00174         ++mCurPos;
    00175       if ( mCurPos < (int)mArray->size() )
    00176       {
    00177         mIndex = mArray->at(mCurPos) + mBaseVert;
    00178         if (mpVertCounts)
    00179         {
    00180           VL_CHECK(mpBaseVertices)
    00181           mBaseCount--;
    00182           if (!mBaseCount)
    00183           {
    00184             mBaseIdx++;
    00185             mBaseCount = (*mpVertCounts)[mBaseIdx];
    00186           }
    00187           mIndex += (*mpBaseVertices)[mBaseIdx];
    00188         }
    00189
    00190         return true;
    00191       }
    00192       else
    00193       {
    00194         mIndex = -1;
    00195         mCurPos = (int)mArray->size();
    00196         return false;
    00197       }
    00198     }
    00199
    00200   protected:
    00201     ref<TArray> mArray;
    00202     int mBaseVert;
    00203     int mCurPos;
    00204     bool mPrimRestartEnabled;
    00205     unsigned int mPrimRestartIdx;
    00206     const std::vector<GLint>* mpBaseVertices;
    00207     const std::vector<GLsizei>* mpVertCounts;
    00208     int mBaseCount;
    00209     int mBaseIdx;
    00210   };
    00211 //-----------------------------------------------------------------------------
    00212 }
    00213
    00214 #endif

Visualization Library v2011.05.1142 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu May 26 2011 22:51:23.
Permission is granted to use this page to write and publish articles regarding Visualization Library.