uint64_t IAlgoGen::getFitness(const cinder::Surface& realImage, const cinder::Surface& popImage) const { uint64_t fitness = 0; auto realIter = realImage.getIter(); auto popIter = popImage.getIter(); while (realIter.line() && popIter.line()) { while (realIter.pixel() && popIter.pixel()) { fitness += std::abs(popIter.r() - realIter.r()); fitness += std::abs(popIter.g() - realIter.g()); fitness += std::abs(popIter.b() - realIter.b()); } } return fitness; }
cinder::Surface ColorAlgoGen::crossOver(const cinder::Surface& s1, const cinder::Surface& s2) const { cinder::Surface crossOver = s1.clone(); auto s1Iter = crossOver.getIter(); auto s2Iter = s2.getIter(); while (s1Iter.line() && s2Iter.line()) { while (s1Iter.pixel() && s2Iter.pixel()) { if(RANDOMIZER.nextBool()) { s1Iter.r() = s2Iter.r(); s1Iter.g() = s2Iter.g(); s1Iter.b() = s2Iter.b(); } } } return crossOver; }