ColorParameterSet.cpp
Go to the documentation of this file.
00001 // ****************************************************************************
00002 // This file is part of the Integrating Vision Toolkit (IVT).
00003 //
00004 // The IVT is maintained by the Karlsruhe Institute of Technology (KIT)
00005 // (www.kit.edu) in cooperation with the company Keyetech (www.keyetech.de).
00006 //
00007 // Copyright (C) 2014 Karlsruhe Institute of Technology (KIT).
00008 // All rights reserved.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are met:
00012 //
00013 // 1. Redistributions of source code must retain the above copyright
00014 //    notice, this list of conditions and the following disclaimer.
00015 //
00016 // 2. Redistributions in binary form must reproduce the above copyright
00017 //    notice, this list of conditions and the following disclaimer in the
00018 //    documentation and/or other materials provided with the distribution.
00019 //
00020 // 3. Neither the name of the KIT nor the names of its contributors may be
00021 //    used to endorse or promote products derived from this software
00022 //    without specific prior written permission.
00023 //
00024 // THIS SOFTWARE IS PROVIDED BY THE KIT AND CONTRIBUTORS “AS IS” AND ANY
00025 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00026 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027 // DISCLAIMED. IN NO EVENT SHALL THE KIT OR CONTRIBUTORS BE LIABLE FOR ANY
00028 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00029 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00031 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00033 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034 // ****************************************************************************
00035 // ****************************************************************************
00036 // Filename:  ColorParameterSet.cpp
00037 // Author:    Pedram Azad
00038 // Date:      2005
00039 // ****************************************************************************
00040 
00041 
00042 // ****************************************************************************
00043 // Includes
00044 // ****************************************************************************
00045 
00046 #include <new> // for explicitly using correct new/delete operators on VC DSPs
00047 
00048 #include "ColorParameterSet.h"
00049 
00050 #include <stdio.h>
00051 #include <string.h>
00052 #include <string>
00053 
00054 
00055 
00056 
00057 // *****************************************************************
00058 // Constructor / Destructor
00059 // *****************************************************************
00060 
00061 CColorParameterSet::CColorParameterSet()
00062 {
00063     m_nColors = (int) eNumberOfColors;
00064         
00065         m_ppParameters = new int*[m_nColors];
00066         for (int i = 0; i < m_nColors; i++)
00067         {
00068                 m_ppParameters[i] = new int[6];
00069                 
00070                 for (int j = 0; j < 6; j++)
00071                         m_ppParameters[i][j] = 0;
00072         }
00073         
00074         SetColorParameters(eSkin, 1, 16, 20, 128, 25, 255);
00075         SetColorParameters(eYellow, 40, 26, 36, 255, 25, 255);
00076         SetColorParameters(eOrange, 21, 15, 128, 255, 25, 255);
00077         SetColorParameters(eRed, 0, 10, 140, 255, 25, 255);
00078         SetColorParameters(eBlue, 113, 13, 149, 255, 25, 255);
00079     SetColorParameters(eGreen, 65, 20, 100, 255, 25, 255);
00080     SetColorParameters(eWhite, 90, 90, 0, 120, 200, 255);
00081 }
00082 
00083 CColorParameterSet::~CColorParameterSet()
00084 {
00085         for (int i = 0; i < m_nColors; i++)
00086                 delete [] m_ppParameters[i];
00087         
00088         delete [] m_ppParameters;
00089 }
00090 
00091 
00092 // ****************************************************************************
00093 // Copy Constructor
00094 // ****************************************************************************
00095 
00096 CColorParameterSet::CColorParameterSet(const CColorParameterSet &colorParameterSet)
00097 {
00098         m_nColors = colorParameterSet.m_nColors;
00099         
00100         m_ppParameters = new int*[m_nColors];
00101 
00102         for (int i = 0; i < m_nColors; i++)
00103         {
00104                 m_ppParameters[i] = new int[6];
00105                 
00106                 m_ppParameters[i][0] = colorParameterSet.m_ppParameters[i][0];
00107                 m_ppParameters[i][1] = colorParameterSet.m_ppParameters[i][1];
00108                 m_ppParameters[i][2] = colorParameterSet.m_ppParameters[i][2];
00109                 m_ppParameters[i][3] = colorParameterSet.m_ppParameters[i][3];
00110                 m_ppParameters[i][4] = colorParameterSet.m_ppParameters[i][4];
00111                 m_ppParameters[i][5] = colorParameterSet.m_ppParameters[i][5];
00112         }
00113 }
00114 
00115 
00116 // ****************************************************************************
00117 // Methods
00118 // ****************************************************************************
00119 
00120 CColorParameterSet& CColorParameterSet::operator=(const CColorParameterSet &colorParameterSet)
00121 {
00122         if (this == &colorParameterSet)
00123                 return *this;
00124 
00125         int i;
00126                
00127         for (i = 0; i < m_nColors; i++)
00128                 delete [] m_ppParameters[i];
00129        
00130         delete [] m_ppParameters;
00131         
00132         // create new content
00133         m_nColors = colorParameterSet.m_nColors;
00134         
00135         m_ppParameters = new int*[m_nColors];
00136         
00137         for (i = 0; i < m_nColors; i++)
00138         {
00139                 m_ppParameters[i] = new int[6];
00140                
00141         m_ppParameters[i][0] = colorParameterSet.m_ppParameters[i][0];
00142         m_ppParameters[i][1] = colorParameterSet.m_ppParameters[i][1];
00143         m_ppParameters[i][2] = colorParameterSet.m_ppParameters[i][2];
00144         m_ppParameters[i][3] = colorParameterSet.m_ppParameters[i][3];
00145         m_ppParameters[i][4] = colorParameterSet.m_ppParameters[i][4];
00146         m_ppParameters[i][5] = colorParameterSet.m_ppParameters[i][5];
00147         }
00148 
00149         return *this;
00150 }
00151 
00152 void CColorParameterSet::SetColorParameters(ObjectColor color, int par1, int par2, int par3, int par4, int par5, int par6)
00153 {
00154         const int nIndex = (int) color;
00155         
00156         if (nIndex < 0 || nIndex >= m_nColors)
00157         {
00158                 printf("error: tried to assign color '%i' with enum out of range (m_nColors = %i)\n", nIndex, m_nColors);
00159                 return;
00160         }
00161         
00162         m_ppParameters[nIndex][0] = par1;
00163         m_ppParameters[nIndex][1] = par2;
00164         m_ppParameters[nIndex][2] = par3;
00165         m_ppParameters[nIndex][3] = par4;
00166         m_ppParameters[nIndex][4] = par5;
00167         m_ppParameters[nIndex][5] = par6;
00168 }
00169 
00170 const int* CColorParameterSet::GetColorParameters(ObjectColor color) const
00171 {
00172         const int nIndex = (int) color;
00173         
00174         if (nIndex < 0 || nIndex >= m_nColors)
00175         {
00176                 printf("error: tried to retrieve color '%i' with enum out of range (m_nColors = %i)\n", nIndex, m_nColors);
00177                 return 0;
00178         }
00179         
00180         return m_ppParameters[nIndex];
00181 }
00182 
00183 ObjectColor CColorParameterSet::Translate(const char *pColorName)
00184 {
00185         if (strcmp(pColorName, "skin") == 0) return eSkin;
00186         else if (strcmp(pColorName, "yellow") == 0) return eYellow;
00187         else if (strcmp(pColorName, "yellow2") == 0) return eYellow2;
00188         else if (strcmp(pColorName, "yellow3") == 0) return eYellow3;
00189         else if (strcmp(pColorName, "orange") == 0) return eOrange;
00190         else if (strcmp(pColorName, "orange2") == 0) return eOrange2;
00191         else if (strcmp(pColorName, "orange3") == 0) return eOrange3;
00192         else if (strcmp(pColorName, "red") == 0) return eRed;
00193         else if (strcmp(pColorName, "red2") == 0) return eRed2;
00194         else if (strcmp(pColorName, "red3") == 0) return eRed3;
00195         else if (strcmp(pColorName, "blue") == 0) return eBlue;
00196         else if (strcmp(pColorName, "blue2") == 0) return eBlue2;
00197         else if (strcmp(pColorName, "blue3") == 0) return eBlue3;
00198         else if (strcmp(pColorName, "green") == 0) return eGreen;
00199         else if (strcmp(pColorName, "green2") == 0) return eGreen2;
00200     else if (strcmp(pColorName, "green3") == 0) return eGreen3;
00201     else if (strcmp(pColorName, "white") == 0) return eWhite;
00202     else if (strcmp(pColorName, "none") == 0) return eNone;
00203     else if (strcmp(pColorName, "colored") == 0) return eColored;
00204     else return eNone;
00205 }
00206 
00207 void CColorParameterSet::Translate(ObjectColor color, std::string &sName)
00208 {
00209         switch (color)
00210         {
00211                 case eSkin: sName = "skin"; break;
00212                 case eYellow: sName = "yellow"; break;
00213                 case eYellow2: sName = "yellow2"; break;
00214                 case eYellow3: sName = "yellow3"; break;
00215                 case eOrange: sName = "orange"; break;
00216                 case eOrange2: sName = "orange2"; break;
00217                 case eOrange3: sName = "orange3"; break;
00218                 case eRed: sName = "red"; break;
00219                 case eRed2: sName = "red2"; break;
00220                 case eRed3: sName = "red3"; break;
00221                 case eBlue: sName = "blue"; break;
00222                 case eBlue2: sName = "blue2"; break;
00223                 case eBlue3: sName = "blue3"; break;
00224                 case eGreen: sName = "green"; break;
00225                 case eGreen2: sName = "green2"; break;
00226         case eGreen3: sName = "green3"; break;
00227         case eWhite: sName = "white"; break;
00228         case eNone: sName = "none"; break;
00229         case eColored: sName = "colored"; break;
00230         default: sName = ""; printf("error: (internal error) color %i not handled\n", (int) color); break;
00231         }
00232 }
00233 
00234 
00235 bool CColorParameterSet::LoadFromFile(const char *pFileName)
00236 {
00237         FILE *f = fopen(pFileName, "r");
00238         if (!f)
00239                 return false;
00240                 
00241         char colorName[100];
00242         int par1, par2, par3, par4, par5, par6;
00243         int **pp = m_ppParameters;
00244                 
00245         while (true)
00246         {
00247                 if (fscanf(f, "%s%i%i%i%i%i%i", colorName, &par1, &par2, &par3, &par4, &par5, &par6) == EOF)
00248                         break;
00249                 
00250                 ObjectColor color = Translate(colorName);
00251                 
00252                 if (color < eNone || color >= eNumberOfColors)
00253                 {
00254                         printf("error: color name '%s' is not handled\n", colorName);
00255                 }
00256                 else
00257                 {
00258                         const int nIndex = (int) color;
00259                         
00260                         pp[nIndex][0] = par1;
00261                         pp[nIndex][1] = par2;
00262                         pp[nIndex][2] = par3;
00263                         pp[nIndex][3] = par4;
00264                         pp[nIndex][4] = par5;
00265                         pp[nIndex][5] = par6;
00266                 }
00267         }
00268         
00269         fclose(f);
00270         
00271         return true;
00272 }
00273 
00274 bool CColorParameterSet::SaveToFile(const char *pFileName)
00275 {
00276         FILE *f = fopen(pFileName, "w");
00277         if (!f)
00278                 return false;
00279                 
00280         int **pp = m_ppParameters;
00281         
00282         for (int i = 0; i < m_nColors; i++)
00283         {
00284                 ObjectColor c = (ObjectColor) i;
00285                 std::string sName;
00286                 Translate(c, sName);
00287                 fprintf(f, "%s %i %i %i %i %i %i\n", sName.c_str(), pp[c][0], pp[c][1], pp[c][2], pp[c][3], pp[c][4], pp[c][5]);
00288         }
00289         
00290         fclose(f);
00291 
00292         return true;
00293 }


asr_ivt
Author(s): Allgeyer Tobias, Hutmacher Robin, Kleinert Daniel, Meißner Pascal, Scholz Jonas, Stöckle Patrick
autogenerated on Thu Jun 6 2019 21:46:57