/** - FUNCTION: GetResult - FUNCTIONALITY: Computes the function evaluador on all the blobs of the class and returns a vector with the result - PARAMETERS: - evaluador: function to apply to each blob (any object derived from the COperadorBlob class ) - RESULT: - vector with all the results in the same order as the blobs - RESTRICTIONS: - AUTHOR: Ricard Borràs - CREATION DATE: 25-05-2005. - MODIFICATION: Date. Author. Description. */ double_stl_vector CBlobResult::GetSTLResult( funcio_calculBlob *evaluador ) const { if( GetNumBlobs() <= 0 ) { return double_stl_vector(); } // definim el resultat double_stl_vector result = double_stl_vector( GetNumBlobs() ); // i iteradors sobre els blobs i el resultat double_stl_vector::iterator itResult = result.begin(); blob_vector::const_iterator itBlobs = m_blobs.begin(); // avaluem la funció en tots els blobs while( itBlobs != m_blobs.end() ) { *itResult = (*evaluador)(**itBlobs); itBlobs++; itResult++; } return result; }
/* - FUNCTION: GetNthBlob - FUNCTIONALITY: Gets the n-th blob ordering first the blobs with some criteria - PARAMETERS: - criteri: criteria to order the blob array - nBlob: index of the returned blob in the ordered blob array - dst: where to store the result - RESULT: - RESTRICTIONS: - AUTHOR: Ricard Borr�s - CREATION DATE: 25-05-2005. - MODIFICATION: Date. Author. Description. */ void CBlobResult::GetNthBlob( funcio_calculBlob* criteri, int nBlob, CBlob& dst ) const { // verifiquem que no estem accedint fora el vector de blobs if ( nBlob < 0 || nBlob >= GetNumBlobs() ) { //RaiseError( EXCEPTION_BLOB_OUT_OF_BOUNDS ); dst = CBlob(); return; } double_stl_vector avaluacioBlobs, avaluacioBlobsOrdenat; double valorEnessim; //avaluem els blobs amb la funci� pertinent avaluacioBlobs = GetSTLResult(criteri); avaluacioBlobsOrdenat = double_stl_vector( GetNumBlobs() ); // obtenim els nBlob primers resultats (en ordre descendent) std::partial_sort_copy( avaluacioBlobs.begin(), avaluacioBlobs.end(), avaluacioBlobsOrdenat.begin(), avaluacioBlobsOrdenat.end(), std::greater<double>() ); valorEnessim = avaluacioBlobsOrdenat[nBlob]; // busquem el primer blob que t� el valor n-ssim double_stl_vector::const_iterator itAvaluacio = avaluacioBlobs.begin(); bool trobatBlob = false; int indexBlob = 0; while ( itAvaluacio != avaluacioBlobs.end() && !trobatBlob ) { if ( *itAvaluacio == valorEnessim ) { trobatBlob = true; dst = CBlob( GetBlob(indexBlob)); } ++itAvaluacio; ++indexBlob; } }