function PROCEDURE_AddPoly2AppearanceData(AppearanceFN,objname);
%function PROCEDURE_AddPoly2AppearanceData(AppearanceFN,objname);
%
%intent:  Add Polygon  data to the Appearance Data for cars, peds, bicycles
%         only holds polygons for true object examples.

D = load(AppearanceFN);
%--> at least y, myBBox,myIdx
load CAfilelist_FilterSS
for i = 1:length(D.myIdx)
  if(not(D.y(i) == 1)), continue, end
  olist = QReadOList2(CAfilelist{D.myIdx(i)}.olistname);
  polygon{i} = FindBestMatchPolygon(olist.(objname), D.myBBox(i,:));
end
save('-append',AppearanceFN, 'polygon');

function poly = FindBestMatchPolygon(caPoly, bbox);
nCandidates = length(caPoly);
for j=1:nCandidates
  bbox_cand(j,:) = poly2bbox(caPoly{j});
  bbox_cand(j,:) = bboxEnforceAspectRatio(bbox_cand(j,:),[.1 .1],'bottom');
  bbox_cand(j,:) = [bbox_cand(j,1) - bbox_cand(j,3)/6,bbox_cand(j,2) - bbox_cand(j,4)/6,bbox_cand(j,3)*4/3,bbox_cand(j,4)*4/3];
end
IntersectionScore = BBoxListOverlap(bbox, bbox_cand);
[M,mi] = max(IntersectionScore);
poly = caPoly{mi};