and colorpicking is faster again

This commit is contained in:
Titus Tscharntke 2013-04-25 23:46:55 +00:00
parent 9d3c99d6d0
commit 77ca62240e

View File

@ -1667,47 +1667,48 @@ vector<int> BaseColorPickEntity::getPickedList(int x,int y,int w,int h,
map<int,bool> modelAlreadyPickedList; map<int,bool> modelAlreadyPickedList;
map<unsigned char,map<unsigned char, map<unsigned char,bool> > > colorAlreadyPickedList; map<unsigned char,map<unsigned char, map<unsigned char,bool> > > colorAlreadyPickedList;
int nEnd = w * h;
int skipSteps=4;
unsigned char *oldpixel = &pixelBuffer[0]; unsigned char *oldpixel = &pixelBuffer[0];
for(int x = 0; x < nEnd && pickedModels.size() < rendererModels.size(); x=x+4) { for(int hh = 0; hh < h && pickedModels.size() < rendererModels.size(); hh=hh+skipSteps) {
int index = x * COLOR_COMPONENTS; for(int ww=0;ww < w && pickedModels.size() < rendererModels.size(); ww=ww+skipSteps){
unsigned char *pixel = &pixelBuffer[index];
if(pixel[3]==0) continue;
if(x>0)
{
oldpixel = &pixelBuffer[index-1*COLOR_COMPONENTS];
if(memcmp(pixel,oldpixel,4)) continue;
}
int index = (hh*w+ww) * COLOR_COMPONENTS;
unsigned char *pixel = &pixelBuffer[index];
if(pixel[3]==0) continue;
if(x>0)
{
oldpixel = &pixelBuffer[index-1*COLOR_COMPONENTS];
if(memcmp(pixel,oldpixel,4)) continue;
}
// Skip duplicate scanned colors
map<unsigned char,map<unsigned char, map<unsigned char,bool> > >::const_iterator iterFind1 = colorAlreadyPickedList.find(pixel[0]);
// Skip duplicate scanned colors if(iterFind1 != colorAlreadyPickedList.end()) {
map<unsigned char,map<unsigned char, map<unsigned char,bool> > >::const_iterator iterFind1 = colorAlreadyPickedList.find(pixel[0]); map<unsigned char, map<unsigned char,bool> >::const_iterator iterFind2 = iterFind1->second.find(pixel[1]);
if(iterFind1 != colorAlreadyPickedList.end()) { if(iterFind2 != iterFind1->second.end()) {
map<unsigned char, map<unsigned char,bool> >::const_iterator iterFind2 = iterFind1->second.find(pixel[1]); map<unsigned char,bool>::const_iterator iterFind3 = iterFind2->second.find(pixel[2]);
if(iterFind2 != iterFind1->second.end()) { if(iterFind3 != iterFind2->second.end()) {
map<unsigned char,bool>::const_iterator iterFind3 = iterFind2->second.find(pixel[2]); continue;
if(iterFind3 != iterFind2->second.end()) { }
continue;
} }
} }
}
for(unsigned int i = 0; i < rendererModels.size(); ++i) { for(unsigned int i = 0; i < rendererModels.size(); ++i) {
// Skip models already selected // Skip models already selected
if(modelAlreadyPickedList.find(i) != modelAlreadyPickedList.end()) { if(modelAlreadyPickedList.find(i) != modelAlreadyPickedList.end()) {
continue; continue;
} }
const BaseColorPickEntity *model = rendererModels[i]; const BaseColorPickEntity *model = rendererModels[i];
if( model != NULL && model->isUniquePickingColor(pixel) == true) { if( model != NULL && model->isUniquePickingColor(pixel) == true) {
//printf("Found match pixel [%d.%d.%d] for model [%s] ptr [%p][%s]\n",pixel[0],pixel[1],pixel[2],model->getColorDescription().c_str(), model,model->getUniquePickName().c_str()); //printf("Found match pixel [%d.%d.%d] for model [%s] ptr [%p][%s]\n",pixel[0],pixel[1],pixel[2],model->getColorDescription().c_str(), model,model->getUniquePickName().c_str());
pickedModels.push_back(i); pickedModels.push_back(i);
modelAlreadyPickedList[i]=true; modelAlreadyPickedList[i]=true;
colorAlreadyPickedList[pixel[0]][pixel[1]][pixel[2]]=true; colorAlreadyPickedList[pixel[0]][pixel[1]][pixel[2]]=true;
break; break;
}
} }
} }
} }