ColorParameterSet.cpp
Go to the documentation of this file.
1 // ****************************************************************************
2 // This file is part of the Integrating Vision Toolkit (IVT).
3 //
4 // The IVT is maintained by the Karlsruhe Institute of Technology (KIT)
5 // (www.kit.edu) in cooperation with the company Keyetech (www.keyetech.de).
6 //
7 // Copyright (C) 2014 Karlsruhe Institute of Technology (KIT).
8 // All rights reserved.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are met:
12 //
13 // 1. Redistributions of source code must retain the above copyright
14 // notice, this list of conditions and the following disclaimer.
15 //
16 // 2. Redistributions in binary form must reproduce the above copyright
17 // notice, this list of conditions and the following disclaimer in the
18 // documentation and/or other materials provided with the distribution.
19 //
20 // 3. Neither the name of the KIT nor the names of its contributors may be
21 // used to endorse or promote products derived from this software
22 // without specific prior written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE KIT AND CONTRIBUTORS “AS IS” AND ANY
25 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 // DISCLAIMED. IN NO EVENT SHALL THE KIT OR CONTRIBUTORS BE LIABLE FOR ANY
28 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 // ****************************************************************************
35 // ****************************************************************************
36 // Filename: ColorParameterSet.cpp
37 // Author: Pedram Azad
38 // Date: 2005
39 // ****************************************************************************
40 
41 
42 // ****************************************************************************
43 // Includes
44 // ****************************************************************************
45 
46 #include <new> // for explicitly using correct new/delete operators on VC DSPs
47 
48 #include "ColorParameterSet.h"
49 
50 #include <stdio.h>
51 #include <string.h>
52 #include <string>
53 
54 
55 
56 
57 // *****************************************************************
58 // Constructor / Destructor
59 // *****************************************************************
60 
62 {
63  m_nColors = (int) eNumberOfColors;
64 
65  m_ppParameters = new int*[m_nColors];
66  for (int i = 0; i < m_nColors; i++)
67  {
68  m_ppParameters[i] = new int[6];
69 
70  for (int j = 0; j < 6; j++)
71  m_ppParameters[i][j] = 0;
72  }
73 
74  SetColorParameters(eSkin, 1, 16, 20, 128, 25, 255);
75  SetColorParameters(eYellow, 40, 26, 36, 255, 25, 255);
76  SetColorParameters(eOrange, 21, 15, 128, 255, 25, 255);
77  SetColorParameters(eRed, 0, 10, 140, 255, 25, 255);
78  SetColorParameters(eBlue, 113, 13, 149, 255, 25, 255);
79  SetColorParameters(eGreen, 65, 20, 100, 255, 25, 255);
80  SetColorParameters(eWhite, 90, 90, 0, 120, 200, 255);
81 }
82 
84 {
85  for (int i = 0; i < m_nColors; i++)
86  delete [] m_ppParameters[i];
87 
88  delete [] m_ppParameters;
89 }
90 
91 
92 // ****************************************************************************
93 // Copy Constructor
94 // ****************************************************************************
95 
97 {
98  m_nColors = colorParameterSet.m_nColors;
99 
100  m_ppParameters = new int*[m_nColors];
101 
102  for (int i = 0; i < m_nColors; i++)
103  {
104  m_ppParameters[i] = new int[6];
105 
106  m_ppParameters[i][0] = colorParameterSet.m_ppParameters[i][0];
107  m_ppParameters[i][1] = colorParameterSet.m_ppParameters[i][1];
108  m_ppParameters[i][2] = colorParameterSet.m_ppParameters[i][2];
109  m_ppParameters[i][3] = colorParameterSet.m_ppParameters[i][3];
110  m_ppParameters[i][4] = colorParameterSet.m_ppParameters[i][4];
111  m_ppParameters[i][5] = colorParameterSet.m_ppParameters[i][5];
112  }
113 }
114 
115 
116 // ****************************************************************************
117 // Methods
118 // ****************************************************************************
119 
121 {
122  if (this == &colorParameterSet)
123  return *this;
124 
125  int i;
126 
127  for (i = 0; i < m_nColors; i++)
128  delete [] m_ppParameters[i];
129 
130  delete [] m_ppParameters;
131 
132  // create new content
133  m_nColors = colorParameterSet.m_nColors;
134 
135  m_ppParameters = new int*[m_nColors];
136 
137  for (i = 0; i < m_nColors; i++)
138  {
139  m_ppParameters[i] = new int[6];
140 
141  m_ppParameters[i][0] = colorParameterSet.m_ppParameters[i][0];
142  m_ppParameters[i][1] = colorParameterSet.m_ppParameters[i][1];
143  m_ppParameters[i][2] = colorParameterSet.m_ppParameters[i][2];
144  m_ppParameters[i][3] = colorParameterSet.m_ppParameters[i][3];
145  m_ppParameters[i][4] = colorParameterSet.m_ppParameters[i][4];
146  m_ppParameters[i][5] = colorParameterSet.m_ppParameters[i][5];
147  }
148 
149  return *this;
150 }
151 
152 void CColorParameterSet::SetColorParameters(ObjectColor color, int par1, int par2, int par3, int par4, int par5, int par6)
153 {
154  const int nIndex = (int) color;
155 
156  if (nIndex < 0 || nIndex >= m_nColors)
157  {
158  printf("error: tried to assign color '%i' with enum out of range (m_nColors = %i)\n", nIndex, m_nColors);
159  return;
160  }
161 
162  m_ppParameters[nIndex][0] = par1;
163  m_ppParameters[nIndex][1] = par2;
164  m_ppParameters[nIndex][2] = par3;
165  m_ppParameters[nIndex][3] = par4;
166  m_ppParameters[nIndex][4] = par5;
167  m_ppParameters[nIndex][5] = par6;
168 }
169 
171 {
172  const int nIndex = (int) color;
173 
174  if (nIndex < 0 || nIndex >= m_nColors)
175  {
176  printf("error: tried to retrieve color '%i' with enum out of range (m_nColors = %i)\n", nIndex, m_nColors);
177  return 0;
178  }
179 
180  return m_ppParameters[nIndex];
181 }
182 
184 {
185  if (strcmp(pColorName, "skin") == 0) return eSkin;
186  else if (strcmp(pColorName, "yellow") == 0) return eYellow;
187  else if (strcmp(pColorName, "yellow2") == 0) return eYellow2;
188  else if (strcmp(pColorName, "yellow3") == 0) return eYellow3;
189  else if (strcmp(pColorName, "orange") == 0) return eOrange;
190  else if (strcmp(pColorName, "orange2") == 0) return eOrange2;
191  else if (strcmp(pColorName, "orange3") == 0) return eOrange3;
192  else if (strcmp(pColorName, "red") == 0) return eRed;
193  else if (strcmp(pColorName, "red2") == 0) return eRed2;
194  else if (strcmp(pColorName, "red3") == 0) return eRed3;
195  else if (strcmp(pColorName, "blue") == 0) return eBlue;
196  else if (strcmp(pColorName, "blue2") == 0) return eBlue2;
197  else if (strcmp(pColorName, "blue3") == 0) return eBlue3;
198  else if (strcmp(pColorName, "green") == 0) return eGreen;
199  else if (strcmp(pColorName, "green2") == 0) return eGreen2;
200  else if (strcmp(pColorName, "green3") == 0) return eGreen3;
201  else if (strcmp(pColorName, "white") == 0) return eWhite;
202  else if (strcmp(pColorName, "none") == 0) return eNone;
203  else if (strcmp(pColorName, "colored") == 0) return eColored;
204  else return eNone;
205 }
206 
208 {
209  switch (color)
210  {
211  case eSkin: sName = "skin"; break;
212  case eYellow: sName = "yellow"; break;
213  case eYellow2: sName = "yellow2"; break;
214  case eYellow3: sName = "yellow3"; break;
215  case eOrange: sName = "orange"; break;
216  case eOrange2: sName = "orange2"; break;
217  case eOrange3: sName = "orange3"; break;
218  case eRed: sName = "red"; break;
219  case eRed2: sName = "red2"; break;
220  case eRed3: sName = "red3"; break;
221  case eBlue: sName = "blue"; break;
222  case eBlue2: sName = "blue2"; break;
223  case eBlue3: sName = "blue3"; break;
224  case eGreen: sName = "green"; break;
225  case eGreen2: sName = "green2"; break;
226  case eGreen3: sName = "green3"; break;
227  case eWhite: sName = "white"; break;
228  case eNone: sName = "none"; break;
229  case eColored: sName = "colored"; break;
230  default: sName = ""; printf("error: (internal error) color %i not handled\n", (int) color); break;
231  }
232 }
233 
234 
235 bool CColorParameterSet::LoadFromFile(const char *pFileName)
236 {
237  FILE *f = fopen(pFileName, "r");
238  if (!f)
239  return false;
240 
241  char colorName[100];
242  int par1, par2, par3, par4, par5, par6;
243  int **pp = m_ppParameters;
244 
245  while (true)
246  {
247  if (fscanf(f, "%s%i%i%i%i%i%i", colorName, &par1, &par2, &par3, &par4, &par5, &par6) == EOF)
248  break;
249 
250  ObjectColor color = Translate(colorName);
251 
252  if (color < eNone || color >= eNumberOfColors)
253  {
254  printf("error: color name '%s' is not handled\n", colorName);
255  }
256  else
257  {
258  const int nIndex = (int) color;
259 
260  pp[nIndex][0] = par1;
261  pp[nIndex][1] = par2;
262  pp[nIndex][2] = par3;
263  pp[nIndex][3] = par4;
264  pp[nIndex][4] = par5;
265  pp[nIndex][5] = par6;
266  }
267  }
268 
269  fclose(f);
270 
271  return true;
272 }
273 
274 bool CColorParameterSet::SaveToFile(const char *pFileName)
275 {
276  FILE *f = fopen(pFileName, "w");
277  if (!f)
278  return false;
279 
280  int **pp = m_ppParameters;
281 
282  for (int i = 0; i < m_nColors; i++)
283  {
284  ObjectColor c = (ObjectColor) i;
285  std::string sName;
286  Translate(c, sName);
287  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]);
288  }
289 
290  fclose(f);
291 
292  return true;
293 }
const int * GetColorParameters(ObjectColor color) const
bool SaveToFile(const char *pFileName)
void SetColorParameters(ObjectColor color, int par1, int par2, int par3, int par4, int par5, int par6)
const GLubyte * c
Definition: glext.h:5181
GLsizei const GLchar ** string
Definition: glext.h:3528
bool LoadFromFile(const char *pFileName)
CColorParameterSet & operator=(const CColorParameterSet &colorParameterSet)
static ObjectColor Translate(const char *pColorName)
ObjectColor


asr_ivt
Author(s): Allgeyer Tobias, Hutmacher Robin, Kleinert Daniel, Meißner Pascal, Scholz Jonas, Stöckle Patrick
autogenerated on Mon Dec 2 2019 03:47:27