示例#1
0
void rect_autofill_learn(const TVectorImageP &imgToLearn, const TRectD &rect)

{
  if (rect.getLx() * rect.getLy() < MIN_SIZE) return;

  double pbx, pby;
  double totalArea = 0;
  pbx = pby = 0;

  if (!regionsReference.isEmpty()) regionsReference.clear();

  int i, index = 0, regionCount = imgToLearn->getRegionCount();
  for (i = 0; i < regionCount; i++) {
    TRegion *region = imgToLearn->getRegion(i);
    if (rect.contains(region->getBBox())) {
      scanRegion(region, index, regionsReference, 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, regionsReference, rect);
    }
  }

  QMap<int, Region>::Iterator it;
  for (it = regionsReference.begin(); it != regionsReference.end(); it++) {
    pbx += it.value().m_barycentre.x;
    pby += it.value().m_barycentre.y;
    totalArea += it.value().m_area;
  }

  if (totalArea > 0)
    referenceB = TPointD(pbx / totalArea, pby / totalArea);
  else
    referenceB = TPointD(0.0, 0.0);
}
示例#2
0
bool TRegion::selectFill(const TRectD &selArea, int styleId)
{
	bool hitSomeRegions = false;

	if (selArea.contains(getBBox())) {
		hitSomeRegions = true;
		setStyle(styleId);
	}

	int regNum = m_imp->m_includedRegionArray.size();

	for (int i = 0; i < regNum; i++)
		hitSomeRegions |= m_imp->m_includedRegionArray[i]->selectFill(selArea, styleId);

	return hitSomeRegions;
}
示例#3
0
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;
}
void SceneViewer::mouseMoveEvent(QMouseEvent *event) {
  if (m_freezedStatus != NO_FREEZED) return;

  QPoint curPos  = event->pos();
  bool cursorSet = false;
  m_lastMousePos = curPos;

  if (m_editPreviewSubCamera) {
    if (!PreviewSubCameraManager::instance()->mouseMoveEvent(this, event))
      return;
  }

  // if the "compare with snapshot" mode is activated, change the mouse cursor
  // on the border handle
  if (m_visualSettings.m_doCompare) {
    if (abs(curPos.x() - width() * m_compareSettings.m_compareX) < 20) {
      cursorSet = true;
      setToolCursor(this, ToolCursor::ScaleHCursor);
    } else if (abs((height() - curPos.y()) -
                   height() * m_compareSettings.m_compareY) < 20) {
      cursorSet = true;
      setToolCursor(this, ToolCursor::ScaleVCursor);
    }
  }

  // control of the border handle when the "compare with snapshot" mode is
  // activated
  if (m_compareSettings.m_dragCompareX || m_compareSettings.m_dragCompareY) {
    if (m_compareSettings.m_dragCompareX)
      m_compareSettings.m_compareX +=
          ((double)(curPos.x() - m_pos.x())) / width();
    else if (m_compareSettings.m_dragCompareY)
      m_compareSettings.m_compareY -=
          ((double)(curPos.y() - m_pos.y())) / height();
    m_compareSettings.m_compareX =
        tcrop(m_compareSettings.m_compareX, 0.0, 1.0);
    m_compareSettings.m_compareY =
        tcrop(m_compareSettings.m_compareY, 0.0, 1.0);

    update();

    m_pos = curPos;
  } else if (m_mouseButton == Qt::NoButton || m_mouseButton == Qt::LeftButton) {
    if (is3DView() && m_current3DDevice != NONE &&
        m_mouseButton == Qt::LeftButton)
      return;
    else if (is3DView() && m_mouseButton == Qt::NoButton) {
      TRectD rect = TRectD(TPointD(m_topRasterPos.x, m_topRasterPos.y),
                           TDimensionD(20, 20));
      if (rect.contains(TPointD(curPos.x(), curPos.y())))
        m_current3DDevice = TOP_3D;
      else {
        rect = TRectD(TPointD(m_sideRasterPos.x, m_sideRasterPos.y),
                      TDimensionD(20, 20));
        if (rect.contains(TPointD(curPos.x(), curPos.y()))) {
          if (m_phi3D > 0)
            m_current3DDevice = SIDE_RIGHT_3D;
          else
            m_current3DDevice = SIDE_LEFT_3D;
        } else
          m_current3DDevice = NONE;
      }
      if (m_current3DDevice != NONE) {
        cursorSet = true;
        setToolCursor(this, ToolCursor::CURSOR_ARROW);
      }
    }

    // if the middle mouse button is pressed while dragging, then do panning
    Qt::MouseButtons mousebuttons;
    mousebuttons = event->buttons();
    if (mousebuttons & Qt::MidButton) {
      // panning
      QPoint p = curPos - m_pos;
      if (m_pos == QPoint(0, 0) && p.manhattanLength() > 300) return;
      panQt(curPos - m_pos);
      m_pos = curPos;
      return;
    }

    TTool *tool = TApp::instance()->getCurrentTool()->getTool();
    if (!tool || !tool->isEnabled()) {
      m_tabletEvent = false;
      return;
    }
    tool->setViewer(this);
    TMouseEvent toonzEvent;
    initToonzEvent(toonzEvent, event, height(), m_pressure, m_tabletEvent,
                   false);
    TPointD worldPos = winToWorld(curPos);
    TPointD pos      = tool->getMatrix().inv() * worldPos;

    if (m_locator) {
      m_locator->onChangeViewAff(worldPos);
    }

    TObjectHandle *objHandle = TApp::instance()->getCurrentObject();
    if (tool->getToolType() & TTool::LevelTool && !objHandle->isSpline()) {
      pos.x /= m_dpiScale.x;
      pos.y /= m_dpiScale.y;
    }

    // qDebug() << "mouseMoveEvent. "  << (m_tabletEvent?"tablet":"mouse")
    //         << " pressure=" << m_pressure << " mouseButton=" << m_mouseButton
    //         << " buttonClicked=" << m_buttonClicked;
    if ((m_tabletEvent && m_pressure > 0) || m_mouseButton == Qt::LeftButton) {
      // sometimes the mousePressedEvent is postponed to a wrong  mouse move
      // event!
      if (m_buttonClicked) tool->leftButtonDrag(pos, toonzEvent);
    } else if (m_pressure == 0) {
      tool->mouseMove(pos, toonzEvent);
      // m_tabletEvent=false;
    }
    if (!cursorSet) setToolCursor(this, tool->getCursorId());
    m_pos = curPos;
  } else if (m_mouseButton == Qt::MidButton) {
    if ((event->buttons() & Qt::MidButton) == 0)
      m_mouseButton = Qt::NoButton;
    else
      // panning
      panQt(curPos - m_pos);
    m_pos = curPos;

    return;
  }
}