本文整理汇总了C++中TRegion::getStyle方法的典型用法代码示例。如果您正苦于以下问题:C++ TRegion::getStyle方法的具体用法?C++ TRegion::getStyle怎么用?C++ TRegion::getStyle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TRegion
的用法示例。
在下文中一共展示了TRegion::getStyle方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pickStyleId
/*-- (StylePickerTool内で)LineとAreaを切り替えてPickできる。mode: 0=Area, 1=Line, 2=Line&Areas(default) --*/
int StylePicker::pickStyleId(const TPointD &pos, double radius2, int mode) const
{
int styleId = 0;
if (TToonzImageP ti = m_image) {
TRasterCM32P ras = ti->getRaster();
TPoint point = getRasterPoint(pos);
if (!ras->getBounds().contains(point))
return -1;
TPixelCM32 col = ras->pixels(point.y)[point.x];
switch (mode) {
case 0: //AREAS
styleId = col.getPaint();
break;
case 1: //LINES
styleId = col.getInk();
break;
case 2: //ALL (Line & Area)
default:
styleId = col.isPurePaint() ? col.getPaint() : col.getInk();
break;
}
} else if (TRasterImageP ri = m_image) {
const TPalette *palette = m_palette.getPointer();
if (!palette)
return -1;
TRaster32P ras = ri->getRaster();
if (!ras)
return -1;
TPoint point = getRasterPoint(pos);
if (!ras->getBounds().contains(point))
return -1;
TPixel32 col = ras->pixels(point.y)[point.x];
styleId = palette->getClosestStyle(col);
} else if (TVectorImageP vi = m_image) {
// prima cerca lo stile della regione piu' vicina
TRegion *r = vi->getRegion(pos);
if (r)
styleId = r->getStyle();
// poi cerca quello della stroke, ma se prima aveva trovato una regione, richiede che
// il click sia proprio sopra la stroke, altrimenti cerca la stroke piu' vicina (max circa 10 pixel)
const double maxDist2 = (styleId == 0) ? 100.0 * radius2 : 0;
bool strokeFound;
double dist2, w, thick;
UINT index;
//!funzionerebbe ancora meglio con un getNearestStroke che considera
//la thickness, cioe' la min distance dalla outline e non dalla centerLine
strokeFound = vi->getNearestStroke(pos, w, index, dist2);
if (strokeFound) {
TStroke *stroke = vi->getStroke(index);
thick = stroke->getThickPoint(w).thick;
if (dist2 - thick * thick < maxDist2) {
assert(stroke);
styleId = stroke->getStyle();
}
}
}
return styleId;
}
示例2: vectorToFullColorImage
//!Converts a TVectorImage into a TRasterImage. The input vector image
//!is transformed through the passed affine \b aff, and put into a
//!TRasterImage strictly covering the bounding box of the transformed
//!vector image. The output image has its lower-left position in the
//!world reference specified by the \b pos parameter, which is granted to
//!be an integer displacement of the passed value. Additional parameters
//!include an integer \b enlarge by which the output image is enlarged with
//!respect to the transformed image's bbox, and the bool \b transformThickness
//!to specify whether the transformation should involve strokes' thickensses
//!or not.
TRasterImageP TRasterImageUtils::vectorToFullColorImage(
const TVectorImageP &vimage, const TAffine &aff, TPalette *palette,
const TPointD &outputPos, const TDimension &outputSize,
const std::vector<TRasterFxRenderDataP> *fxs, bool transformThickness)
{
if (!vimage || !palette)
return 0;
//Transform the vector image through aff
TVectorImageP vi = vimage->clone();
vi->transform(aff, transformThickness);
//Allocate the output ToonzImage
TRaster32P raster(outputSize.lx, outputSize.ly);
raster->clear();
TRasterImageP ri(raster);
ri->setPalette(palette->clone());
//Shift outputPos to the origin
vi->transform(TTranslation(-outputPos));
int strokeCount = vi->getStrokeCount();
std::vector<int> strokeIndex(strokeCount);
std::vector<TStroke *> strokes(strokeCount);
int i;
for (i = 0; i < strokeCount; ++i) {
strokeIndex[i] = i;
strokes[i] = vi->getStroke(i);
}
vi->notifyChangedStrokes(strokeIndex, strokes);
int maxStyleId = palette->getStyleCount() - 1;
for (i = 0; i < (int)vi->getRegionCount(); ++i) {
TRegion *region = vi->getRegion(i);
fastAddPaintRegion(ri, region, tmin(maxStyleId, region->getStyle()), maxStyleId);
}
set<int> colors;
if (fxs) {
for (i = 0; i < (int)fxs->size(); i++) {
SandorFxRenderData *sandorData = dynamic_cast<SandorFxRenderData *>((*fxs)[i].getPointer());
if (sandorData && sandorData->m_type == BlendTz) {
std::string indexes = toString(sandorData->m_blendParams.m_colorIndex);
std::vector<std::string> items;
parseIndexes(indexes, items);
PaletteFilterFxRenderData paletteFilterData;
insertIndexes(items, &paletteFilterData);
colors = paletteFilterData.m_colors;
break;
}
}
}
for (i = 0; i < strokeCount; ++i) {
TStroke *stroke = vi->getStroke(i);
bool visible = false;
int styleId = stroke->getStyle();
TColorStyleP style = palette->getStyle(styleId);
assert(style);
int colorCount = style->getColorParamCount();
if (colorCount == 0)
visible = true;
else {
visible = false;
for (int j = 0; j < style->getColorParamCount() && !visible; j++) {
TPixel32 color = style->getColorParamValue(j);
if (color.m != 0)
visible = true;
}
}
if (visible)
fastAddInkStroke(ri, stroke, TRectD(), 1, true);
}
return ri;
}
示例3: stroke_autofill_apply
bool stroke_autofill_apply(const TVectorImageP &imgToApply, TStroke *stroke,
bool selective) {
if (!imgToApply || !stroke || stroke->getControlPointCount() == 0)
return false;
TVectorImage appImg;
TStroke *appStroke = new TStroke(*stroke);
appImg.addStroke(appStroke);
appImg.findRegions();
if (regionsReference.size() <= 0) return false;
double pbx, pby;
double totalArea = 0;
pbx = pby = 0.0;
if (!regionsWork.isEmpty()) regionsWork.clear();
int i, j, index = 0;
for (i = 0; i < (int)imgToApply->getRegionCount(); i++) {
TRegion *currentRegion = imgToApply->getRegion(i);
for (j = 0; j < (int)appImg.getRegionCount(); j++) {
TRegion *region = appImg.getRegion(j);
if (contains(region, currentRegion)) {
scanRegion(currentRegion, index, regionsWork, region->getBBox());
index++;
int k, subRegionCount = currentRegion->getSubregionCount();
for (k = 0; k < subRegionCount; k++) {
TRegion *subRegion = currentRegion->getSubregion(k);
if (contains(region, subRegion))
scanSubRegion(subRegion, index, regionsWork, region->getBBox());
}
}
}
}
if (regionsWork.size() <= 0) return false;
QMap<int, Region>::Iterator it;
for (it = regionsWork.begin(); it != regionsWork.end(); it++) {
pbx += it.value().m_barycentre.x;
pby += it.value().m_barycentre.y;
totalArea += it.value().m_area;
}
workB = TPointD(pbx / totalArea, pby / totalArea);
std::vector<MatchingProbs> probVector;
RegionDataList::Iterator refIt, workIt;
for (refIt = regionsReference.begin(); refIt != regionsReference.end();
refIt++)
for (workIt = regionsWork.begin(); workIt != regionsWork.end(); workIt++)
assignProbs(probVector, refIt.value(), workIt.value(), refIt.key(),
workIt.key());
bool filledRegions = false;
for (refIt = regionsReference.begin(); refIt != regionsReference.end();
refIt++) {
int to = 0, from = 0;
int valore = 0;
do
valore = match(probVector, from, to);
while ((regionsWork[to].m_match != -1 ||
regionsReference[from].m_match != -1) &&
valore > 0);
if (valore > AMB_TRESH) {
regionsWork[to].m_match = from;
regionsReference[from].m_match = to;
regionsWork[to].m_styleId = regionsReference[from].m_styleId;
TRegion *reg = regionsWork[to].m_region;
if (reg && (!selective || selective && reg->getStyle() == 0)) {
reg->setStyle(regionsWork[to].m_styleId);
filledRegions = true;
}
}
}
return filledRegions;
}
示例4: rect_autofill_apply
bool rect_autofill_apply(const TVectorImageP &imgToApply, const TRectD &rect,
bool selective) {
if (rect.getLx() * rect.getLy() < MIN_SIZE) return false;
if (regionsReference.size() <= 0) return false;
double pbx, pby;
double totalArea = 0;
pbx = pby = 0.0;
if (!regionsWork.isEmpty()) regionsWork.clear();
int i, index = 0, regionCount = imgToApply->getRegionCount();
for (i = 0; i < regionCount; i++) {
TRegion *region = imgToApply->getRegion(i);
TRectD bbox = region->getBBox();
if (rect.contains(bbox)) {
scanRegion(region, index, regionsWork, rect);
index++;
}
int j, subRegionCount = region->getSubregionCount();
for (j = 0; j < subRegionCount; j++) {
TRegion *subRegion = region->getSubregion(j);
if (rect.contains(subRegion->getBBox()))
scanSubRegion(subRegion, index, regionsWork, rect);
}
}
if (regionsWork.size() <= 0) return false;
QMap<int, Region>::Iterator it;
for (it = regionsWork.begin(); it != regionsWork.end(); it++) {
pbx += it.value().m_barycentre.x;
pby += it.value().m_barycentre.y;
totalArea += it.value().m_area;
}
workB = TPointD(pbx / totalArea, pby / totalArea);
std::vector<MatchingProbs> probVector;
RegionDataList::Iterator refIt, workIt;
for (refIt = regionsReference.begin(); refIt != regionsReference.end();
refIt++)
for (workIt = regionsWork.begin(); workIt != regionsWork.end(); workIt++)
assignProbs(probVector, refIt.value(), workIt.value(), refIt.key(),
workIt.key());
bool filledRegions = false;
for (refIt = regionsReference.begin(); refIt != regionsReference.end();
refIt++) {
int to = 0, from = 0;
int valore = 0;
do
valore = match(probVector, from, to);
while ((regionsWork[to].m_match != -1 ||
regionsReference[from].m_match != -1) &&
valore > 0);
if (valore > AMB_TRESH) {
regionsWork[to].m_match = from;
regionsReference[from].m_match = to;
regionsWork[to].m_styleId = regionsReference[from].m_styleId;
TRegion *reg = regionsWork[to].m_region;
if (reg && (!selective || selective && reg->getStyle() == 0)) {
reg->setStyle(regionsWork[to].m_styleId);
filledRegions = true;
}
}
}
return filledRegions;
}