ColorMap.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: ColorMap.cpp 1644 2009-01-27 19:26:14Z ckiesch $"
00002 
00004 
00005 //============================================================================
00006 //
00007 //  This file is part of GPSTk, the GPS Toolkit.
00008 //
00009 //  The GPSTk is free software; you can redistribute it and/or modify
00010 //  it under the terms of the GNU Lesser General Public License as published
00011 //  by the Free Software Foundation; either version 2.1 of the License, or
00012 //  any later version.
00013 //
00014 //  The GPSTk is distributed in the hope that it will be useful,
00015 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 //  GNU Lesser General Public License for more details.
00018 //
00019 //  You should have received a copy of the GNU Lesser General Public
00020 //  License along with GPSTk; if not, write to the Free Software Foundation,
00021 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //  
00023 //  Copyright 2004, The University of Texas at Austin
00024 //
00025 //============================================================================
00026 
00027 #include "ColorMap.hpp"
00028 
00029 namespace vdraw
00030 {
00031   ColorMap::ColorMap(const ColorMap &o)
00032   {
00033     init(o.getCols(),o.getRows());        
00034 
00035     for(int row=0;row<rows;row++)
00036       for(int col=0;col<cols;col++)
00037         c[row][col] = o.get(row,col);
00038   }
00039 
00040   ColorMap::ColorMap(const InterpolatedColorMap &o)
00041   {
00042     init(o.getCols(),o.getRows());        
00043 
00044     for(int row=0;row<rows;row++)
00045       for(int col=0;col<cols;col++)
00046         c[row][col] = o.get(row,col);
00047   }
00048 
00049   //ColorMap::ColorMap(const IndexedColorMap &o)
00050   //{
00051   //  init(o.getCols(),o.getRows());        
00052   //
00053   //  for(int row=0;row<rows;row++)
00054   //    for(int col=0;col<cols;col++)
00055   //      c[row][col] = o.get(row,col);
00056   //}
00057 
00058   ColorMap::ColorMap(int icols, int irows, const Color &base)
00059   {
00060     init(icols,irows);        
00061 
00062     for(int row=0;row<rows;row++)
00063       for(int col=0;col<cols;col++)
00064         c[row][col] = base;
00065   }
00066 
00067   ColorMap& ColorMap::operator=(ColorMap o)
00068   {
00069     // o is a copy, swap the variables
00070     std::swap(rows,o.rows);
00071     std::swap(cols,o.cols);
00072     std::swap(c,o.c);
00073     // o is destructed with the old data from this
00074     return *this;
00075   }
00076   
00077   void ColorMap::init(int icols, int irows)
00078   {
00079     if(icols == 0 || irows == 0)
00080     {
00081       cols = rows = 0;
00082       c = 0;
00083       return;
00084     }
00085 
00086     cols = icols;
00087     rows = irows;
00088 
00089     // Initialize the color array
00090     c = new Color*[rows];
00091 
00092     for(int row=0;row<rows;row++)
00093       c[row] = new Color[cols];
00094   }
00095 
00096   void ColorMap::reset()
00097   {
00098     if(c)
00099     {
00100       for(int row=0;row<rows;row++)
00101         delete[] c[row];
00102       delete[] c;
00103     }
00104 
00105     cols=rows=0;
00106     c=0;
00107   }
00108 
00109 }

Generated on Wed Feb 8 03:30:58 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1