Exemplo n.º 1
0
/// mean normal + from center
void Sculptor::inflatePoints()
{ 
	Vector3F nor = m_active->meanNormal;
	Array<int, VertexP> * vs = m_active->vertices;
	
	float wei, round;
	vs->begin();
	while(!vs->end()) {
		
		VertexP * l = vs->value();
		wei = *l->index->t4;
		
		const Vector3F p0(*(l->index->t1));
		
		Vector3F pn = *l->index->t2;
/// blow outwards
		if(pn.dot(nor) < 0.f) pn.reverse();
		
		round = cos(p0.distanceTo(m_active->meanPosition) / selectRadius() * 1.5f );
		pn *= round;
		pn += nor * round;
		
		*(l->index->t1) += pn * wei * m_strength * 0.1f;
	
		m_tree->displace(l, *(l->index->t1), p0);

		vs->next();
	}
	smoothPoints(0.4f);
}
void WritingTool::addPoint(cv::Point sPoint){
  points_.push_back(sPoint);
  smoothPoints();
}
Exemplo n.º 3
0
// Note: with no antialiasing, the coordinates in QPointF are rounded to the nearest integer.
void
IntonationWidget::paintEvent(QPaintEvent*)
{
	if (eventList_ == nullptr || eventList_->list().empty()) {
		return;
	}

	QPainter painter(this);
	painter.setFont(QFont("monospace"));

	if (modelUpdated_) {
		QFontMetrics fm = painter.fontMetrics();
		textYOffset_ = 0.5 * fm.ascent();
		leftMargin_ = MARGIN + TEXT_MARGIN + fm.width(yLabels[0]);

		modelUpdated_ = false;
	}

	totalWidth_ = std::ceil(leftMargin_ + graphWidth_ + 6.0 * MARGIN);
	if (totalWidth_ < MININUM_WIDTH) {
		totalWidth_ = MININUM_WIDTH;
	}
	totalHeight_ = std::ceil(2.0 * MARGIN + 3.0 * TRACK_HEIGHT + 15.0 * yStep_);
	if (totalHeight_ < MININUM_HEIGHT) {
		totalHeight_ = MININUM_HEIGHT;
	}
	setMinimumWidth(totalWidth_);
	setMinimumHeight(totalHeight_);

	double xStart = timeToX(0.0);
	double yStart = valueToY(MIN_VALUE);
	double xEnd = timeToX(maxTime_);
	double yEnd = valueToY(MAX_VALUE);

	// Y labels.
	for (unsigned int i = 0; i < yLabels.size(); ++i) {
		double y = MARGIN + (i + 3) * yStep_ + textYOffset_;
		painter.drawText(QPointF(MARGIN, y), yLabels[i]);
	}
	// Horizontal lines.
	painter.setPen(Qt::lightGray);
	for (int i = 1; i < 15; ++i) {
		double y = MARGIN + (i + 3) * yStep_;
		painter.drawLine(QPointF(xStart, y), QPointF(xEnd, y));
	}
	painter.setPen(Qt::black);

	postureTimeList_.clear();

	double yPosture = MARGIN + 3.0 * TRACK_HEIGHT - 0.5 * (TRACK_HEIGHT - 1.0) + textYOffset_;
	unsigned int postureIndex = 0;
	for (const TRMControlModel::Event_ptr& ev : eventList_->list()) {
		double x = timeToX(ev->time);
		if (ev->flag) {
			postureTimeList_.push_back(ev->time);
			const TRMControlModel::Posture* posture = eventList_->getPostureAtIndex(postureIndex++);
			if (posture) {
				painter.setPen(Qt::black);
				// Posture name.
				painter.drawText(QPointF(x, yPosture), posture->name().c_str());
			}
			painter.setPen(Qt::lightGray);
			// Event vertical line.
			painter.drawLine(QPointF(x, yStart), QPointF(x, yEnd));
		}
	}
	painter.setPen(Qt::black);

	// Frame.
	painter.drawRect(QRectF(QPointF(xStart, yStart), QPointF(xEnd, yEnd)));

	double yRuleText  = MARGIN + TRACK_HEIGHT - 0.5 * (TRACK_HEIGHT - 1.0) + textYOffset_;
	double yRuleText2 = yRuleText + TRACK_HEIGHT;

	for (int i = 0; i < eventList_->numberOfRules(); ++i) {
		auto* ruleData = eventList_->getRuleAtIndex(i);
		if (ruleData) {
			unsigned int firstPosture = ruleData->firstPosture;
			unsigned int lastPosture = ruleData->lastPosture;

			int postureTime1, postureTime2;
			if (firstPosture < postureTimeList_.size()) {
				postureTime1 = postureTimeList_[firstPosture];
			} else {
				postureTime1 = 0; // invalid
			}
			if (lastPosture < postureTimeList_.size()) {
				postureTime2 = postureTimeList_[lastPosture];
			} else {
				postureTime2 = postureTime1 + ruleData->duration;
			}

			// Rule frame.
			painter.drawRect(QRectF(
					QPointF(timeToX(postureTime1), MARGIN),
					QPointF(timeToX(postureTime2), MARGIN + 2.0 * TRACK_HEIGHT)));
			// Rule number.
			painter.drawText(QPointF(timeToX(postureTime1) + TEXT_MARGIN, yRuleText), QString::number(ruleData->number));

			// Rule duration.
			painter.drawText(QPointF(timeToX(postureTime1) + TEXT_MARGIN, yRuleText2), QString::number(ruleData->duration, 'f', 0));
		}
	}

	QPen pen;
	QPen pen2;
	pen2.setWidth(2);

	painter.setRenderHint(QPainter::Antialiasing);
	painter.setBrush(QBrush(Qt::black));

	// Lines between intonation points.
	QPointF prevPoint(0.5 + xStart, 0.5 + yStart);
	for (unsigned int i = 0, size = intonationPointList_.size(); i < size; ++i) {
		QPointF currPoint(
			0.5 + timeToX(intonationPointList_[i].absoluteTime()),
			0.5 + valueToY(intonationPointList_[i].semitone()));

		painter.setPen(pen2);
		painter.drawLine(prevPoint, currPoint);

		painter.setPen(pen);
		drawPointMarker(painter, 0.5 + currPoint.x(), 0.5 + currPoint.y());

		prevPoint = currPoint;
	}

	painter.setBrush(QBrush());

	painter.setPen(pen2);
	smoothPoints(painter);
	painter.setPen(pen);

	painter.setRenderHint(QPainter::Antialiasing, false);

	// Point selection.
	if (selectedPoint_ >= 0) {
		double x = timeToX(intonationPointList_[selectedPoint_].absoluteTime());
		double y = valueToY(intonationPointList_[selectedPoint_].semitone());
		painter.drawRect(QRectF(
			 QPointF(x - SELECTION_SIZE, y - SELECTION_SIZE),
			 QPointF(x + SELECTION_SIZE, y + SELECTION_SIZE)));
	}

	// Beat lines.
	for (unsigned int i = 0, size = intonationPointList_.size(); i < size; ++i) {
		double x = timeToX(intonationPointList_[i].beatTime());
		painter.drawLine(QPointF(x, yStart), QPointF(x, yEnd));
	}

	// Time scale.
	double yTick1 = yStart + TIME_DIVISION_MARK_SIZE;
	double yTick2 = yStart + 2.0 * TIME_DIVISION_MARK_SIZE;
	double yTimeText = yTick2 + 0.5 * TRACK_HEIGHT + textYOffset_;
	for (int time = 0, end = static_cast<int>(maxTime_); time <= end; time += 10) {
		double x = timeToX(time);
		if (time % 100 == 0) {
			painter.drawLine(QPointF(x, yStart), QPointF(x, yTick2));
			painter.drawText(QPointF(x, yTimeText), QString::number(time));
		} else {
			painter.drawLine(QPointF(x, yStart), QPointF(x, yTick1));
		}
	}
}