PRO ROIPolygonAlternativeView2 poly = [[0.8, 1.7, 2.7, 2.7, 0.8], [0.2, 2.2, 2.2, 0.2, 0.2]] nn = 4 centersX = transpose(fltarr(nn)+1) ## (INDGEN(nn)+ 0.5) centersY = transpose(INDGEN(nn)+ 0.5) ## (fltarr(nn)+1) TVLCT, cgColor('red6', /Triple), 255 TVLCT, cgColor('white', /Triple), 1 cgDisplay, 1200, 800 pos = cgLayout([2,2], OXMARGIN=[4, 2], OYMARGIN=[5, 6], XGAP=4, YGAP=8) ; Rule 0 p = OBJ_NEW('IDLanROI', poly[*,0], poly[*,1]) mask = p->ComputeMask(DIMENSIONS=[nn, nn], MASK_RULE=0) anImage = BytArr(nn,nn)+1B anImage[Where(mask EQ 255)] = 255 po = pos[*,0] cgImage, anImage, /AXES, /SAVE, POS=po, TITLE='RULE 0', /NOERASE cgPlotS, centersX, centersY, PSYM=16, /DATA cgPlotS, poly[*, 0]+ 0.5, poly[*, 1]+ 0.5, COLOR='green', /DATA, THICK=3 cgPlot, [1], XRange=[0,4], YRange=[0,4], /NoData, $ YTickLen=1.0, XTickLen=1.0, POS=po, /NOERASE ; Rule 1 p = OBJ_NEW('IDLanROI', poly[*,0], poly[*,1]) mask = p->ComputeMask(DIMENSIONS=[nn, nn], MASK_RULE=1) anImage = BytArr(nn,nn)+1B anImage[Where(mask EQ 255)] = 255 po = pos[*,1] cgImage, anImage, /AXES, /SAVE, POS=po, TITLE='RULE 1', /NOERASE cgPlotS, centersX, centersY, PSYM=16, /DATA cgPlotS, poly[*, 0]+ 0.5, poly[*, 1]+ 0.5, COLOR='green', /DATA, THICK=3 cgPlot, [1], XRange=[0,4], YRange=[0,4], /NoData, $ YTickLen=1.0, XTickLen=1.0, POS=po, /NOERASE ; Rule 2 p = OBJ_NEW('IDLanROI', poly[*,0], poly[*,1]) mask = p->ComputeMask(DIMENSIONS=[nn, nn], MASK_RULE=2) anImage = BytArr(nn,nn)+1B anImage[Where(mask EQ 255)] = 255 po = pos[*,2] cgImage, anImage, /AXES, /SAVE, POS=po, TITLE='RULE 2', /NOERASE cgPlotS, centersX, centersY, PSYM=16, /DATA cgPlotS, poly[*, 0]+ 0.5, poly[*, 1]+ 0.5, COLOR='green', /DATA, THICK=3 cgPlot, [1], XRange=[0,4], YRange=[0,4], /NoData, $ YTickLen=1.0, XTickLen=1.0, POS=po, /NOERASE ; Contains points p = OBJ_NEW('IDLanROI', poly[*,0], poly[*,1]) mask = p->ContainsPoints(centersX[*]-0.5, centersY[*]-0.5) anImage = BytArr(nn,nn)+1B p = where(mask eq 1) po = pos[*,3] cgImage, anImage, /AXES, /SAVE, POS=po, TITLE='CONTAINS POINTS', /NOERASE cgPlotS, centersX, centersY, PSYM=16, /DATA cgPlotS, centersX[p], centersY[p], PSYM=16, /DATA, COLOR='red' cgPlotS, poly[*, 0]+ 0.5, poly[*, 1]+ 0.5, COLOR='green', /DATA, THICK=3 end