Пример #1
0
void ShiftTraceTool::drawDot(const TPointD &center, double r,
                             const TPixel32 &color) {
  tglColor(color);
  tglDrawDisk(center, r);
  glColor3d(0.2, 0.2, 0.2);
  tglDrawCircle(center, r);
}
Пример #2
0
void ShiftTraceTool::drawControlRect() {
  if (m_ghostIndex < 0 || m_ghostIndex > 1) return;
  int row = m_row[m_ghostIndex];
  if (row < 0) return;
  int col       = TApp::instance()->getCurrentColumn()->getColumnIndex();
  TXsheet *xsh  = TApp::instance()->getCurrentXsheet()->getXsheet();
  TXshCell cell = xsh->getCell(row, col);
  if (cell.isEmpty()) return;
  TImageP img = cell.getImage(false);
  if (!img) return;
  TRectD box;
  if (TRasterImageP ri = img) {
    TRasterP ras = ri->getRaster();
    box =
        (convert(ras->getBounds()) - ras->getCenterD()) * ri->getSubsampling();
  } else if (TToonzImageP ti = img) {
    TRasterP ras = ti->getRaster();
    box =
        (convert(ras->getBounds()) - ras->getCenterD()) * ti->getSubsampling();
  } else if (TVectorImageP vi = img) {
    box = vi->getBBox();
  } else {
    return;
  }
  glPushMatrix();
  tglMultMatrix(getGhostAff());
  TPixel32 color;
  color = m_highlightedGadget == TranslateGadget ? TPixel32(200, 100, 100)
                                                 : TPixel32(120, 120, 120);
  tglColor(color);
  glBegin(GL_LINE_STRIP);
  glVertex2d(box.x0, box.y0);
  glVertex2d(box.x1, box.y0);
  glVertex2d(box.x1, box.y1);
  glVertex2d(box.x0, box.y1);
  glVertex2d(box.x0, box.y0);
  glEnd();
  color =
      m_highlightedGadget == 2000 ? TPixel32(200, 100, 100) : TPixel32::White;
  double r = 4 * sqrt(tglGetPixelSize2());
  drawDot(box.getP00(), r, color);
  drawDot(box.getP01(), r, color);
  drawDot(box.getP10(), r, color);
  drawDot(box.getP11(), r, color);
  if (m_curveStatus == NoCurve) {
    color =
        m_highlightedGadget == 2001 ? TPixel32(200, 100, 100) : TPixel32::White;
    TPointD c = m_center[m_ghostIndex];
    drawDot(c, r, color);
  }
  glPopMatrix();
}
Пример #3
0
void tglDraw(const TVectorRenderData &rd, const TStroke *s)
{
	assert(s);
	if (!s)
		return;

	const TStroke &stroke = *s;

	// initialize information for aaliasing
	glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_BLEND);
	glEnable(GL_LINE_SMOOTH);

	// it's necessary to do line function of pixel size ?
	glLineWidth((float)1.0);

	assert(rd.m_palette);
	TStrokeProp *prop = stroke.getProp(/*rd.m_palette*/);
	/////questo codice stava dentro tstroke::getprop/////////
	TColorStyle *style = rd.m_palette->getStyle(stroke->getStyle() /*m_imp->m_styleId*/);
	if (!style->isStrokeStyle() || style->isEnabled() == false) {
		prop = 0;
	} else {
		if (!prop || style != prop->getColorStyle()) {
			stroke->setProp(style->makeStrokeProp(stroke));
			prop = stroke->getProp();
		}
	}
	///
	//---------------------
	if (prop)
		prop->draw(rd);
	//---------------------

	tglColor(TPixel32::White);

	glDisable(GL_BLEND);
	glDisable(GL_LINE_SMOOTH);
}
Пример #4
0
void CameraTestTool::draw() {
  double pixelSize = getPixelSize();
  glPushMatrix();

  CleanupParameters *cp =
      CleanupSettingsModel::instance()->getCurrentParameters();

  glTranslated(-0.5 * cp->m_offx * Stage::inch, -0.5 * cp->m_offy * Stage::inch,
               0);
  drawCleanupCamera(pixelSize);
  // drawClosestFieldCamera(pixelSize);

  TRectD r(cp->m_camera.getStageRect());
  TPointD size(10, 10);

  double pixelSize4 = 4.0 * pixelSize;

  tglColor(TPixel::Red);
  ToolUtils::drawSquare(r.getP00(), pixelSize4, TPixel::Red);
  ToolUtils::drawSquare(r.getP01(), pixelSize4, TPixel::Red);
  ToolUtils::drawSquare(r.getP10(), pixelSize4, TPixel::Red);
  ToolUtils::drawSquare(r.getP11(), pixelSize4, TPixel::Red);

  TPointD center(0.5 * (r.getP00() + r.getP11()));

  ToolUtils::drawSquare(TPointD(center.x, r.y0), pixelSize4,
                        TPixel::Red);  // draw M0 handle
  ToolUtils::drawSquare(TPointD(r.x1, center.y), pixelSize4,
                        TPixel::Red);  // draw 1M handle
  ToolUtils::drawSquare(TPointD(center.x, r.y1), pixelSize4,
                        TPixel::Red);  // draw M1 handle
  ToolUtils::drawSquare(TPointD(r.x0, center.y), pixelSize4,
                        TPixel::Red);  // draw 0M handle

  glPopMatrix();
}
Пример #5
0
void ImageViewer::paintGL() {
  if (m_lutCalibrator && m_lutCalibrator->isValid()) m_fbo->bind();

  TDimension viewerSize(width(), height());
  TAffine aff = m_viewAff;

  // if (!m_visualSettings.m_defineLoadbox && m_flipbook &&
  // m_flipbook->getLoadbox()!=TRect())
  //  offs =
  //  convert(m_flipbook->getLoadbox().getP00())-TPointD(m_flipbook->getImageSize().lx/2.0,
  //  m_flipbook->getImageSize().ly/2.0);

  TDimension imageSize;
  TRect loadbox;

  if (m_flipbook) {
    QString title =
        (!m_image)
            ? m_flipbook->getTitle() + tr("  ::  Zoom : ") +
                  QString::number(tround(sqrt(m_viewAff.det()) * 100)) + " %"
            : m_flipbook->getLevelZoomTitle() + tr("  ::  Zoom : ") +
                  QString::number(tround(sqrt(m_viewAff.det()) * 100)) + " %";
    m_flipbook->parentWidget()->setWindowTitle(title);
    imageSize = m_flipbook->getImageSize();
    if (m_visualSettings.m_useLoadbox && m_flipbook->getLoadbox() != TRect())
      loadbox = m_flipbook->getLoadbox();
  }
  m_visualSettings.m_sceneProperties =
      TApp::instance()->getCurrentScene()->getScene()->getProperties();
  // enable checks only in the color model
  m_visualSettings.m_useChecks = m_isColorModel;
  ImagePainter::paintImage(m_image, imageSize, viewerSize, aff,
                           m_visualSettings, m_compareSettings, loadbox);

  // when fx parameter is modified with showing the fx preview,
  // a flipbook shows a red border line before the rendered result is shown.
  if (m_isRemakingPreviewFx) {
    glPushMatrix();
    glLoadIdentity();
    glColor3d(1.0, 0.0, 0.0);

    glBegin(GL_LINE_LOOP);
    glVertex2d(5, 5);
    glVertex2d(5, height() - 5);
    glVertex2d(width() - 5, height() - 5);
    glVertex2d(width() - 5, 5);
    glEnd();

    glBegin(GL_LINE_LOOP);
    glVertex2d(10, 10);
    glVertex2d(10, height() - 10);
    glVertex2d(width() - 10, height() - 10);
    glVertex2d(width() - 10, 10);
    glEnd();
    glPopMatrix();
  }

  if (!m_image) {
    if (m_lutCalibrator && m_lutCalibrator->isValid())
      m_lutCalibrator->onEndDraw(m_fbo);
    return;
  }

  if (safeAreaToggle.getStatus() && !m_isColorModel) {
    TRasterImageP rimg = (TRasterImageP)m_image;
    TVectorImageP vimg = (TVectorImageP)m_image;
    TToonzImageP timg  = (TToonzImageP)m_image;
    TRect bbox;

    TPointD centerD;
    TRect bounds;
    if (rimg) {
      centerD = rimg->getRaster()->getCenterD();
      bounds  = rimg->getRaster()->getBounds();
    } else if (timg) {
      centerD = timg->getRaster()->getCenterD();
      bounds  = timg->getRaster()->getBounds();
    }

    if (!vimg) {
      TAffine aff = TTranslation(viewerSize.lx * 0.5, viewerSize.ly * 0.5) *
                    m_viewAff * TTranslation(-centerD);
      TRectD bbox = aff * TRectD(0, 0, bounds.getLx() - 1, bounds.getLy() - 1);
      drawSafeArea(bbox);
    }
  }
  TPoint fromPos, toPos;

  if (m_visualSettings.m_defineLoadbox && m_flipbook) {
    TRect loadbox =
        convert(getImgToWidgetAffine() * convert(m_flipbook->getLoadbox()));
    if (loadbox != TRect()) {
      TPoint p00 = loadbox.getP00();
      TPoint p11 = loadbox.getP11();
      fromPos =
          TPoint(p00.x - width() * 0.5,
                 height() * 0.5 - p00.y);  // m_flipbook->getLoadbox().getP00();
      toPos =
          TPoint(p11.x - width() * 0.5,
                 height() * 0.5 - p11.y);  // m_flipbook->getLoadbox().getP11();
    }
  } else if (m_draggingZoomSelection || m_rectRGBPick) {
    fromPos = TPoint(m_pressedMousePos.x - width() * 0.5,
                     height() * 0.5 - m_pressedMousePos.y);
    toPos = TPoint(m_pos.x() - width() * 0.5, height() * 0.5 - m_pos.y());
  }
  if (fromPos != TPoint() || toPos != TPoint()) {
    if (m_rectRGBPick) {
      tglColor(TPixel32::Red);
      // TODO: glLineStipple is deprecated in the latest OpenGL. Need to be
      // replaced. (shun_iwasawa 2015/12/25)
      glLineStipple(1, 0x3F33);
      glEnable(GL_LINE_STIPPLE);

      glBegin(GL_LINE_STRIP);
      // do not draw the rect around the mouse cursor
      int margin = (fromPos.y < toPos.y) ? -3 : 3;
      glVertex2i(toPos.x, toPos.y + margin);
      glVertex2i(toPos.x, fromPos.y);
      glVertex2i(fromPos.x, fromPos.y);
      glVertex2i(fromPos.x, toPos.y);
      margin = (fromPos.x < toPos.x) ? -3 : 3;
      glVertex2i(toPos.x + margin, toPos.y);
      glEnd();
      glDisable(GL_LINE_STIPPLE);
    } else {
      tglColor(m_draggingZoomSelection ? TPixel32::Red : TPixel32::Blue);
      glBegin(GL_LINE_STRIP);
      glVertex2i(fromPos.x, fromPos.y);
      glVertex2i(fromPos.x, toPos.y);
      glVertex2i(toPos.x, toPos.y);
      glVertex2i(toPos.x, fromPos.y);
      glVertex2i(fromPos.x, fromPos.y);
      glEnd();
    }
  }

  if (m_lutCalibrator && m_lutCalibrator->isValid())
    m_lutCalibrator->onEndDraw(m_fbo);
}
Пример #6
0
void tglDraw(const TRectD &rect, const TRaster32P &tex, bool blending)
{
	CHECK_ERRORS_BY_GL;
	glPushAttrib(GL_ALL_ATTRIB_BITS);
	if (blending) {
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	}

	unsigned int texWidth = 1;
	unsigned int texHeight = 1;

	while (texWidth < (unsigned int)tex->getLx())
		texWidth = texWidth << 1;

	while (texHeight < (unsigned int)tex->getLy())
		texHeight = texHeight << 1;

	double lwTex = 1.0;
	double lhTex = 1.0;

	TRaster32P texture;
	unsigned int texLx = (unsigned int)tex->getLx();
	unsigned int texLy = (unsigned int)tex->getLy();

	if (texWidth != texLx ||
		texHeight != texLy) {
		texture = TRaster32P(texWidth, texHeight);
		texture->fill(TPixel32(0, 0, 0, 0));
		texture->copy(tex);
		lwTex = (texLx) / (double)(texWidth);
		lhTex = (texLy) / (double)(texHeight);
		if (lwTex > 1.0)
			lwTex = 1.0;
		if (lhTex > 1.0)
			lhTex = 1.0;
	} else
		texture = tex;
	GLenum fmt =
#ifdef TNZ_MACHINE_CHANNEL_ORDER_BGRM
		GL_BGRA_EXT;
#elif TNZ_MACHINE_CHANNEL_ORDER_MBGR
		GL_ABGR_EXT;
#elif TNZ_MACHINE_CHANNEL_ORDER_RGBM
		GL_RGBA;
#elif TNZ_MACHINE_CHANNEL_ORDER_MRGB
		GL_BGRA;
#else
//   Error  PLATFORM NOT SUPPORTED
#error "unknown channel order!"
#endif

	// Generate a texture id and bind it.
	GLuint texId;
	glGenTextures(1, &texId);

	glBindTexture(GL_TEXTURE_2D, texId);

	glPixelStorei(GL_UNPACK_ROW_LENGTH, texture->getWrap());

	texture->lock();
	glTexImage2D(GL_TEXTURE_2D,
				 0,
				 4,
				 texWidth,
				 texHeight,
				 0,
				 fmt,
#ifdef TNZ_MACHINE_CHANNEL_ORDER_MRGB
				 GL_UNSIGNED_INT_8_8_8_8_REV,
#else
				 GL_UNSIGNED_BYTE,
#endif
				 texture->getRawData());

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
	glEnable(GL_TEXTURE_2D);

	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

	double rectLx = rect.getLx();
	double rectLy = rect.getLy();

	tglColor(TPixel32(0, 0, 0, 0));

	glPushMatrix();

	glTranslated(rect.x0, rect.y0, 0.0);
	glBegin(GL_POLYGON);

	glTexCoord2d(0, 0);
	tglVertex(TPointD(0.0, 0.0));

	glTexCoord2d(lwTex, 0);
	tglVertex(TPointD(rectLx, 0.0));

	glTexCoord2d(lwTex, lhTex);
	tglVertex(TPointD(rectLx, rectLy));

	glTexCoord2d(0, lhTex);
	tglVertex(TPointD(0.0, rectLy));

	glEnd();
	glDisable(GL_TEXTURE_2D);

	glPopMatrix();
	glPopAttrib();

	// Delete texture
	glDeleteTextures(1, &texId);

	texture->unlock();
}
Пример #7
0
void TglTessellator::tessellate(const TColorFunction *cf, const bool antiAliasing, TRegionOutline &outline, TPixel32 color)
{
	if (cf)
		color = (*(cf))(color);

	if (color.m == 0)
		return;

	bool transparencyFlag = color.m < 255;

	tglColor(color);

	if (transparencyFlag) {
		tglEnableLineSmooth();
	}

	TglTessellator::GLTess glTess;
	gluTessCallback(glTess.m_tess, GLU_TESS_VERTEX, (GluCallback)glVertex3dv);

	//------------------------//
	doTessellate(glTess, cf, antiAliasing, outline);
	//------------------------//

	if (antiAliasing && outline.m_doAntialiasing) {

		tglEnableLineSmooth();

		for (TRegionOutline::Boundary::iterator poly_it = outline.m_exterior.begin(); poly_it != outline.m_exterior.end(); ++poly_it) {
			vector<GLdouble> v;
			if (poly_it->size() == 0)
				continue;
			v.resize(poly_it->size() * 2);
			int i = 0;
			for (TRegionOutline::PointVector::iterator it = poly_it->begin(); it != poly_it->end(); ++it) {
				v[i++] = it->x;
				v[i++] = it->y;
			}

			glEnableClientState(GL_VERTEX_ARRAY);

			glVertexPointer(2, GL_DOUBLE, sizeof(GLdouble) * 2, &v[0]);
			glDrawArrays(GL_LINE_LOOP, 0, v.size() / 2);

			glDisableClientState(GL_VERTEX_ARRAY);
		}

		for (TRegionOutline::Boundary::iterator poly_it = outline.m_interior.begin(); poly_it != outline.m_interior.end(); ++poly_it) {
			vector<GLdouble> v;
			v.resize(poly_it->size() * 2);
			int i = 0;
			for (TRegionOutline::PointVector::iterator it = poly_it->begin(); it != poly_it->end(); ++it) {
				v[i++] = it->x;
				v[i++] = it->y;
			}
			if (v.empty())
				continue;
			glEnableClientState(GL_VERTEX_ARRAY);

			glVertexPointer(2, GL_DOUBLE, sizeof(GLdouble) * 2, &v[0]);
			glDrawArrays(GL_LINE_LOOP, 0, v.size() / 2);

			glDisableClientState(GL_VERTEX_ARRAY);
		}
	}
}