1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
| #include "stdafx.h"
#include "Reference.h"
#include <sstream>
#ifdef _DEBUG
#include <fstream>
#endif
using namespace std;
IMPLEMENT_SERIAL(Reference, CObject, 0)
Reference::Reference(void)
{
m_teinte = new int[TAILLE_TEINTE];
m_teinteEch = new int[TAILLE_TEINTE_ECH];
m_niveauGris = new int[TAILLE_NIVEAU_GRIS];
m_niveauGrisEch = new int[TAILLE_NIVEAU_GRIS_ECH];
initialize();
}
Reference::~Reference(void)
{
delete [] m_teinte;
delete [] m_teinteEch;
delete [] m_niveauGris;
delete [] m_niveauGrisEch;
}
void Reference::initialize()
{
for (int i = 0; i < TAILLE_NIVEAU_GRIS; ++i) m_niveauGris[i] = 0;
for (int i = 0; i < TAILLE_TEINTE; ++i) m_teinte[i] = 0;
for (int i = 0; i < TAILLE_NIVEAU_GRIS_ECH; ++i) m_niveauGrisEch[i] = 0;
for (int i = 0; i < TAILLE_TEINTE_ECH; ++i) m_teinteEch[i] = 0;
m_blanc = 0;
m_noir = 0;
m_nbPixelChromatiques = 0;
m_nbPixelGris = 0;
}
void Reference::traitementInterneTeintes()
{
m_teinteEch[0] = accumulate(teinte(), 0, red_orange, 0) + accumulate(teinte(), magenta_red, TAILLE_TEINTE, 0);
m_teinteEch[1] = accumulate(teinte(), red_orange, orange_yellow, 0);
m_teinteEch[2] = accumulate(teinte(), orange_yellow, yellow_green, 0);
m_teinteEch[3] = accumulate(teinte(), yellow_green, green_turquoise, 0);
m_teinteEch[4] = accumulate(teinte(), green_turquoise, turquoise_cyan, 0);
m_teinteEch[5] = accumulate(teinte(), turquoise_cyan, cyan_azur, 0);
m_teinteEch[6] = accumulate(teinte(), cyan_azur, azur_blue, 0);
m_teinteEch[7] = accumulate(teinte(), azur_blue, blue_violet, 0);
m_teinteEch[8] = accumulate(teinte(), blue_violet, violet_magenta, 0);
m_teinteEch[9] = accumulate(teinte(), violet_magenta, magenta_red, 0);
m_nbPixelChromatiques = accumulate(m_teinteEch, 0, TAILLE_TEINTE_ECH, 0);
}
void Reference::traitementInterneNiveauGris()
{
m_noir = accumulate(niveauGris(), 0, 64, 0);
m_blanc = accumulate(niveauGris(), 192, TAILLE_NIVEAU_GRIS, 0);
m_niveauGrisEch[0] = accumulate(niveauGris(), 64, 96, 0);
m_niveauGrisEch[1] = accumulate(niveauGris(), 96, 128, 0);
m_niveauGrisEch[2] = accumulate(niveauGris(), 128, 160, 0);
m_niveauGrisEch[3] = accumulate(niveauGris(), 160, 192, 0);
m_nbPixelGris = accumulate(m_niveauGrisEch, 0, TAILLE_NIVEAU_GRIS_ECH, m_noir + m_blanc);
}
double Reference::intersection(const Reference& autre) const
{
if (nbPixel() == 0 || autre.nbPixel() == 0) return 0;
double cumul = 0;
for (int i = 0; i < TAILLE_TEINTE_ECH; ++i)
{
cumul += min(m_teinteEch[i], double(autre.m_teinteEch[i]) * double(m_nbPixelChromatiques + m_nbPixelGris) / double(autre.m_nbPixelChromatiques + autre.m_nbPixelGris) );
}
for (int i = 0; i < TAILLE_NIVEAU_GRIS_ECH; ++i)
{
cumul += min(m_niveauGrisEch[i], double(autre.m_niveauGrisEch[i]) * double(m_nbPixelChromatiques + m_nbPixelGris) / double(autre.m_nbPixelChromatiques + autre.m_nbPixelGris) );
}
cumul += min(m_noir, autre.m_noir * double(m_nbPixelChromatiques + m_nbPixelGris) / double(autre.m_nbPixelChromatiques + autre.m_nbPixelGris));
cumul += min(m_blanc, autre.m_blanc * double(m_nbPixelChromatiques + m_nbPixelGris) / double(autre.m_nbPixelChromatiques + autre.m_nbPixelGris));
return cumul / double(m_nbPixelChromatiques + m_nbPixelGris);
}
void Reference::setTeinte(const int* teintes) {
for (int i = 0; i < TAILLE_TEINTE; ++i) {
m_teinte[i] = teintes[i];
}
traitementInterneTeintes();
}
void Reference::setNiveauGris(const int* niveauGris) {
for (int i = 0; i < TAILLE_NIVEAU_GRIS; ++i) {
m_niveauGris[i] = niveauGris[i];
}
traitementInterneNiveauGris();
}
CString Reference::toString() {
ostringstream oss117;
oss117 << "t(";
for (int i = 0; i < TAILLE_TEINTE_ECH; ++i) {
if (i != 0) oss117 << ";";
oss117 << m_teinteEch[i];
}
oss117 << "), g(";
for (int i = 0; i < TAILLE_NIVEAU_GRIS_ECH; ++i) {
if (i != 0) oss117 << ";";
oss117 << m_niveauGrisEch[i];
}
oss117 << "), b:" << m_blanc << " n:" << m_noir;
return CString(oss117.str().c_str());
}
void Reference::Serialize(CArchive &ar) {
if (ar.IsStoring()) {
for (int i = 0; i < TAILLE_TEINTE; ++i) ar << m_teinte[i];
for (int i = 0; i < TAILLE_NIVEAU_GRIS ; ++i) ar << m_niveauGris[i];
} else {
for (int i = 0; i < TAILLE_TEINTE; ++i) ar >> m_teinte[i];
for (int i = 0; i < TAILLE_NIVEAU_GRIS ; ++i) ar >> m_niveauGris[i];
traitementInterneNiveauGris();
traitementInterneTeintes();
}
} |
Partager