colortable.cpp

Go to the documentation of this file.
00001 /* ============================================================================
00002 'colortable.cpp' defines a pair of classes used to maintain the color tables
00003 required by the application.
00004 
00005 Written by Nicholas Phillips.
00006 QT4 adaption and Black/White color table by Michael R. Greason, ADNET,
00007         27 August 2007.
00008 ============================================================================ */
00009 /*
00010                         Fetch header files.
00011 */
00012 #include <iostream>
00013 #include "colortable.h"
00014 #include "define_colortable.h"
00015 
00016 using namespace std;
00017 /* ============================================================================
00018 'ColorTable' maintains a single color table.  Each element represents one
00019 usable color; it may be accessed either by indexing it directly or by supplying
00020 a value from 0--1.
00021 
00022 The color tables currently supported are staticly defined in 
00023 'define_colortable.h'.
00024 
00025 TBD:
00026         - Allow the setting of color tables from image files.
00027         - Return a pixmap of the color table.
00028 ============================================================================ */
00029 /* ----------------------------------------------------------------------------
00030 'ColorTable' is the default class constructor; it defines the default color
00031 table in the new instance.
00032 
00033 Arguments:
00034         None.
00035 
00036 Written by Michael R. Greason, ADNET, 27 August 2007.
00037 ---------------------------------------------------------------------------- */
00038 ColorTable::ColorTable()
00039 {
00040         name = default_ct_name;
00041         define_table(default_colortable);
00042         return;
00043 }
00044 /* ----------------------------------------------------------------------------
00045 'ColorTable' is a class constructor; it defines the 'indexed' color table from
00046 'define_colortable.h'
00047 
00048 Arguments:
00049         id - The color table in the file to define:
00050                         0 - default
00051                         1 - black-white
00052 
00053 Written by Michael R. Greason, ADNET, 27 August 2007.
00054 ---------------------------------------------------------------------------- */
00055 ColorTable::ColorTable(int id)
00056 {
00057         switch (id)
00058         {
00059           case 1:
00060                 name = blkwht_ct_name;
00061                 define_table(blkwht_colortable);
00062                 break;
00063           default:
00064                 name = default_ct_name;
00065                 define_table(default_colortable);
00066                 break;
00067         }
00068         return;
00069 }
00070 /* ----------------------------------------------------------------------------
00071 'define_table' performs the work in defining a color table from
00072 'define_colortable.h'.  This routine does NOT define the name of the table.
00073 
00074 Arguments:
00075         intab - The desired color table as a float array.
00076 
00077 Returned:
00078         Nothing.
00079 
00080 Written by Michael R. Greason, ADNET, 27 August 2007.
00081 ---------------------------------------------------------------------------- */
00082 void ColorTable::define_table (float intab[][3])
00083 {
00084         for(ncols = 0; intab[ncols][0] != -1; ncols++);
00085         table.resize(ncols);
00086         for(uint i = 0; i < ncols; i++)
00087                 table[i].setRgbF(intab[i][0], intab[i][1], intab[i][2]);
00088 }
00089 /* ----------------------------------------------------------------------------
00090 'operator[]' returns the indexed element in the table.
00091 
00092 Arguments:
00093         v - The 'index'; this is a value between 0 and 1 identifying the 
00094             desired color as a fractional position in the table.
00095 
00096 Returned:
00097         col - The desired color.
00098 
00099 Written by Michael R. Greason, ADNET, 27 August 2007.
00100 ---------------------------------------------------------------------------- */
00101 QColor ColorTable::operator[](float v) const
00102 {
00103         v = v < 0 ? 0 : v;
00104         v = v > 1 ? 1 : v;
00105         uint idx = (uint)(v*(ncols-1));
00106         //cout << idx;
00107         return table[idx];
00108 }
00109 /* ----------------------------------------------------------------------------
00110 'getPixmap' returns a pixmap of the color table.
00111 
00112 NOT CURRENTLY DEFINED
00113 
00114 Arguments:
00115         None.
00116 
00117 Returned:
00118         pm - The pixmap.
00119 
00120 Written by Michael R. Greason, ADNET, 27 August 2007.
00121 ---------------------------------------------------------------------------- */
00122 QPixmap ColorTable::getPixmap()
00123 {
00124         cout << "ColorTable::getPixmap(): Not implemented yet!" << endl;
00125         return QPixmap();
00126 }
00127 /* ============================================================================
00128 'ColorTableList' maintains a vector of color tables.
00129 ============================================================================ */
00130 /* ----------------------------------------------------------------------------
00131 'ColorTableList' is the default class constructor, defining all the color
00132 tables defined in 'define_colortable.h'.
00133 
00134 Arguments:
00135         None.
00136 
00137 Written by Michael R. Greason, ADNET, 27 August 2007.
00138 ---------------------------------------------------------------------------- */
00139 ColorTableList::ColorTableList(void)
00140 {
00141         set();
00142 }
00143 /* ----------------------------------------------------------------------------
00144 '~ColorTableList' is class destructor, destroying the color tables before
00145 this instance is destroyed.
00146 
00147 Arguments:
00148         None.
00149 
00150 Written by Michael R. Greason, ADNET, 27 August 2007.
00151 ---------------------------------------------------------------------------- */
00152 ColorTableList::~ColorTableList()
00153 {
00154         for( iterator cti = begin(); cti != end(); ++cti){
00155                 delete *cti;
00156         }
00157         return;
00158 }
00159 /* ----------------------------------------------------------------------------
00160 'set' defines all the color tables defined in 'define_colortable.h'.
00161 
00162 Arguments:
00163         None.
00164 
00165 Returned:
00166         flg - true if successful.
00167 
00168 Written by Michael R. Greason, ADNET, 27 August 2007.
00169 ---------------------------------------------------------------------------- */
00170 bool ColorTableList::set()
00171 {
00172         ColorTable *ct;
00173         clear();
00174         for (int i = 0; i < colortable_count; i++)
00175         {
00176                 ct = new ColorTable(i);
00177                 push_back(ct);
00178         }
00179         return true;
00180 }

Generated on Fri Feb 6 15:32:42 2009 for Skyviewer by  doxygen 1.4.7