本文整理汇总了C++中GImage::setPixel方法的典型用法代码示例。如果您正苦于以下问题:C++ GImage::setPixel方法的具体用法?C++ GImage::setPixel怎么用?C++ GImage::setPixel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GImage
的用法示例。
在下文中一共展示了GImage::setPixel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: regionMask
void G2DRegionGraph::makeCoarserRegions(G2DRegionGraph* pFineRegions)
{
// Find every region's closest neighbor
GImage* pFineRegionMask = pFineRegions->regionMask();
GImage* pCoarseRegionMask = regionMask();
GAssert(pCoarseRegionMask->width() == pFineRegionMask->width() && pCoarseRegionMask->height() == pFineRegionMask->height()); // size mismatch
int* pBestNeighborMap = new int[pFineRegions->regionCount()];
ArrayHolder<int> hBestNeighborMap(pBestNeighborMap);
for(size_t i = 0; i < pFineRegions->regionCount(); i++)
{
struct GRegion* pRegion = pFineRegions->m_regions[i];
struct GRegionEdge* pEdge;
double d;
double dBestDiff = 1e200;
int nBestNeighbor = -1;
for(pEdge = pRegion->m_pNeighbors; pEdge; pEdge = pEdge->GetNext(i))
{
size_t j = pEdge->GetOther(i);
struct GRegion* pOtherRegion = pFineRegions->m_regions[j];
d = MeasureRegionDifference(pRegion, pOtherRegion);
if(d < dBestDiff)
{
dBestDiff = d;
nBestNeighbor = (int)j;
}
}
GAssert(nBestNeighbor != -1 || pFineRegions->regionCount() == 1); // failed to find a neighbor
pBestNeighborMap[i] = nBestNeighbor;
}
// Create a mapping to new regions numbers
int* pNewRegionMap = new int[pFineRegions->regionCount()];
ArrayHolder<int> hNewRegionMap(pNewRegionMap);
memset(pNewRegionMap, 0xff, sizeof(int) * pFineRegions->regionCount());
int nNewRegionCount = 0;
for(size_t i = 0; i < pFineRegions->regionCount(); i++)
{
size_t nNewRegion = -1;
size_t j = i;
while(pNewRegionMap[j] == -1)
{
pNewRegionMap[j] = -2;
j = pBestNeighborMap[j];
}
if(pNewRegionMap[j] == -2)
nNewRegion = nNewRegionCount++;
else
nNewRegion = pNewRegionMap[j];
j = i;
while(pNewRegionMap[j] == -2)
{
pNewRegionMap[j] = (int)nNewRegion;
j = pBestNeighborMap[j];
}
}
// Make the new regions
for(size_t i = 0; i < pFineRegions->regionCount(); i++)
{
struct GRegion* pRegion = pFineRegions->m_regions[i];
size_t j = pNewRegionMap[i];
if(regionCount() <= j)
{
GAssert(regionCount() == j); // how'd it get two behind?
addRegion();
}
struct GRegion* pCoarseRegion = m_regions[j];
pCoarseRegion->m_nSumRed += pRegion->m_nSumRed;
pCoarseRegion->m_nSumGreen += pRegion->m_nSumGreen;
pCoarseRegion->m_nSumBlue += pRegion->m_nSumBlue;
pCoarseRegion->m_nPixels += pRegion->m_nPixels;
}
for(size_t i = 0; i < pFineRegions->regionCount(); i++)
{
struct GRegion* pRegion = pFineRegions->m_regions[i];
size_t j = pNewRegionMap[i];
struct GRegionEdge* pEdge;
for(pEdge = pRegion->m_pNeighbors; pEdge; pEdge = pEdge->GetNext(i))
{
size_t k = pNewRegionMap[pEdge->GetOther(i)];
if(j != k)
makeNeighbors(j, k);
}
}
// Make the fine region mask
unsigned int nOldRegion;
int x, y;
for(y = 0; y < (int)pFineRegionMask->height(); y++)
{
for(x = 0; x < (int)pFineRegionMask->width(); x++)
{
nOldRegion = pFineRegionMask->pixel(x, y);
pCoarseRegionMask->setPixel(x, y, pNewRegionMap[nOldRegion]);
}
}
}