TVectorImageP MyInbetweener::tween(double t)
{
	TVectorImageP vi = m_vi0->clone();
	int n = tmin(m_vi0->getStrokeCount(), m_vi1->getStrokeCount());
	for (int i = 0; i < n; i++) {
		TStroke *stroke0 = m_vi0->getStroke(i);
		TStroke *stroke1 = m_vi1->getStroke(i);
		TStroke *stroke = vi->getStroke(i);
		int m = tmin(stroke0->getControlPointCount(), stroke1->getControlPointCount());
		for (int j = 0; j < m; j++) {
			TThickPoint p0 = stroke0->getControlPoint(j);
			TThickPoint p1 = stroke1->getControlPoint(j);
			TThickPoint p = (1 - t) * p0 + t * p1;
			stroke->setControlPoint(j, p);
		}
		/*
    for(int j=2;j+2<m;j+=2)
    {
      TThickPoint p0 = stroke0->getControlPoint(j-2);
      TThickPoint p1 = stroke0->getControlPoint(j-1);
      TThickPoint p2 = stroke0->getControlPoint(j);
      TThickPoint p3 = stroke0->getControlPoint(j+1);
      TThickPoint p4 = stroke0->getControlPoint(j+2);
      if(tdistance2(p0,p1)<0.001 && tdistance2(p3,p4)<0.001)
      {
        p2 = 0.5*(p1+p2);
        stroke->setControlPoint(j,p2);
      }
    }
    */
	}
	return vi;
}
示例#2
0
	void updateLevel()
	{
		TTool::Application *app = TTool::getApplication();
		if (!app->getCurrentLevel()->getLevel())
			return;
		TXshSimpleLevelP xl = app->getCurrentLevel()->getLevel()->getSimpleLevel();
		if (app->getCurrentFrame()->getFrameType() != TFrameHandle::LevelFrame)
			return;

		TFrameId fid = app->getCurrentFrame()->getFid();
		TVectorImageP src = xl->getFrame(fid, true);
		int count = src->getStrokeCount();

		for (int i = 1; i < 10; i++) {
			++fid;
			if (!xl->isFid(fid)) {
				TVectorImageP vi = new TVectorImage();
				xl->setFrame(fid, vi);
			}
			TVectorImageP vi = xl->getFrame(fid, true);
			TVectorImageP dst = src->clone();
			deform(dst.getPointer(), src.getPointer(), (double)i / (double)9);
			count = dst->getStrokeCount();
			vi->mergeImage(dst, TAffine());
			app->getCurrentTool()->getTool()->notifyImageChanged(fid);
		}
	}
示例#3
0
//!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;
}