# Visualization Library

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

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

- Main Page
- Related Pages
- 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.org                                               */
    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     VL_INSTRUMENT_ABSTRACT_CLASS(vl::IndexIteratorAbstract, Object)
    00046
    00047   public:
    00048     IndexIteratorAbstract(): mIndex(-1)
    00049     {
    00050       VL_DEBUG_SET_OBJECT_NAME()
    00051     }
    00052     int index() const { return mIndex; }
    00053     virtual bool hasNext() 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     VL_INSTRUMENT_CLASS(vl::IndexIterator, Object)
    00066
    00067   public:
    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 hasNext() { return mIterator->hasNext(); }
    00075     bool next()  { return mIterator->next();  }
    00076     bool operator++() { return next(); }
    00077
    00078   protected:
    00079     ref<IndexIteratorAbstract> mIterator;
    00080   };
    00081 //-----------------------------------------------------------------------------
    00082 // IndexIteratorDrawArrays
    00083 //-----------------------------------------------------------------------------
    00085   class IndexIteratorDrawArrays: public IndexIteratorAbstract
    00086   {
    00087     VL_INSTRUMENT_CLASS(vl::IndexIteratorDrawArrays, IndexIteratorAbstract)
    00088
    00089   public:
    00090     IndexIteratorDrawArrays()
    00091     {
    00092       VL_DEBUG_SET_OBJECT_NAME()
    00093       initialize(0,0);
    00094     }
    00095
    00096     void initialize(int start, int count)
    00097     {
    00098       mStart  = start;
    00099       mCount  = count;
    00100       mCurPos = start;
    00101       mIndex  = start;
    00102     }
    00103
    00104     virtual bool hasNext() const
    00105     {
    00106       return mCurPos != mStart + mCount;
    00107     }
    00108
    00109     virtual bool next()
    00110     {
    00111       ++mCurPos;
    00112       mIndex = mCurPos;
    00113       return true;
    00114     }
    00115
    00116   protected:
    00117     int mStart;
    00118     int mCount;
    00119     int mCurPos;
    00120   };
    00121 //-----------------------------------------------------------------------------
    00122 // IndexIteratorElements
    00123 //-----------------------------------------------------------------------------
    00125   template<class TArray>
    00126   class IndexIteratorElements: public IndexIteratorAbstract
    00127   {
    00128     VL_INSTRUMENT_CLASS(vl::IndexIteratorElements<TArray>, IndexIteratorAbstract)
    00129
    00130   public:
    00131     IndexIteratorElements()
    00132     {
    00133       VL_DEBUG_SET_OBJECT_NAME()
    00134       initialize( NULL, NULL, NULL, 0, false, 0 );
    00135     }
    00136
    00137     void initialize( const TArray* idx_array, const std::vector<GLint>* p_base_vertices, const std::vector<GLsizei>* p_vert_counts,
    00138                      int base_vert, bool prim_restart_on, unsigned int prim_restart_idx )
    00139     {
    00140       mArray = idx_array;
    00141       mBaseVert = base_vert;
    00142       mpBaseVertices = p_base_vertices;
    00143       mpVertCounts   = p_vert_counts;
    00144       mBaseCount     = 0;
    00145       mBaseIdx       = 0;
    00146
    00147       mPrimRestartEnabled = prim_restart_on;
    00148       mPrimRestartIdx = prim_restart_idx;
    00149       mCurPos = 0;
    00150       if (mArray && mArray->size())
    00151       {
    00152         mIndex = mArray->at(0) + mBaseVert;
    00153       }
    00154
    00155       if (p_vert_counts)
    00156       {
    00157         VL_CHECK(p_base_vertices)
    00158         VL_CHECK( p_base_vertices->size() == p_vert_counts->size() )
    00159
    00160         mBaseCount = (*p_vert_counts)[mBaseIdx];
    00161
    00162         mIndex = (*mpBaseVertices)[mBaseIdx];
    00163       }
    00164     }
    00165
    00166     virtual bool hasNext() const
    00167     {
    00168       return mCurPos != (int)mArray->size();
    00169     }
    00170
    00171     virtual bool next()
    00172     {
    00173       ++mCurPos;
    00174       while( mCurPos < (int)mArray->size() && mArray->at(mCurPos) == mPrimRestartIdx && mPrimRestartEnabled  )
    00175         ++mCurPos;
    00176       if ( mCurPos < (int)mArray->size() )
    00177       {
    00178         mIndex = mArray->at(mCurPos) + mBaseVert;
    00179         if (mpVertCounts)
    00180         {
    00181           VL_CHECK(mpBaseVertices)
    00182           mBaseCount--;
    00183           if (!mBaseCount)
    00184           {
    00185             mBaseIdx++;
    00186             mBaseCount = (*mpVertCounts)[mBaseIdx];
    00187           }
    00188           mIndex += (*mpBaseVertices)[mBaseIdx];
    00189         }
    00190
    00191         return true;
    00192       }
    00193       else
    00194       {
    00195         mIndex = -1;
    00196         mCurPos = (int)mArray->size();
    00197         return false;
    00198       }
    00199     }
    00200
    00201   protected:
    00202     const TArray* mArray;
    00203     int mBaseVert;
    00204     int mCurPos;
    00205     bool mPrimRestartEnabled;
    00206     unsigned int mPrimRestartIdx;
    00207     const std::vector<GLint>* mpBaseVertices;
    00208     const std::vector<GLsizei>* mpVertCounts;
    00209     int mBaseCount;
    00210     int mBaseIdx;
    00211   };
    00212 //-----------------------------------------------------------------------------
    00213 }
    00214
    00215 #endif

Visualization Library v2011.09.1162 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu Jan 26 2012 00:43:39.
Permission is granted to use this page to write and publish articles regarding Visualization Library.