float WaterElevationLayer::WaterElevationCurveData::getSampleLength(CurvePtr c) { float width = min(c->getWidth(), 20.0f); if (c->getType() == LAKE) { width = 6.0f; } return 20.0f * width / 6.0f; }
WaterElevationLayer::WaterElevationCurveData::WaterElevationCurveData(CurveId id, CurvePtr flattenCurve, ptr<TileProducer> elevations) : ElevationCurveData(id, flattenCurve, elevations, true) { if (flattenCurve->getType() == LAKE && flattenCurve->getWidth() > 12) { // large river if (startCapLength + endCapLength > 2 * length / 3) { startCapLength = endCapLength = length / 3; } } }
void LazyGraph::movePoint(CurvePtr c, int i, const vec2d &p) { if (i == 0 || i == c->getSize() - 1) { NodePtr n = i == 0 ? c->getStart() : c->getEnd(); nodeCache->add(n.get(), true); } else { curveCache->add(c.get(), true); } Graph::movePoint(c, i, p); }
void TrackMarker::getCenterKeyframes(std::set<double>* keyframes) const { CurvePtr curve = _imp->center.lock()->getAnimationCurve(ViewIdx(0), DimIdx(0)); assert(curve); KeyFrameSet keys = curve->getKeyFrames_mt_safe(); for (KeyFrameSet::iterator it = keys.begin(); it != keys.end(); ++it) { keyframes->insert( it->getTime() ); } }
CurvePtr LazyGraph::newCurve(CurvePtr parent, bool setParent) { CurveId id = nextCurveId; nextCurveId.id++; CurvePtr c = new LazyCurve(this, id); curves.insert(make_pair(id, c.get())); if (curveOffsets.find(id) == curveOffsets.end()) { curveOffsets.insert(make_pair(id, (long int) - 1)); } curveCache->add(c.get(), true); return c; }
double WaterElevationLayer::WaterElevationMargin::getMargin(double clipSize, CurvePtr p) { float pwidth = p->getWidth(); if (p->getType() == WaterElevationCurveData::RIVER) { float scale = 2.0f * (samplesPerTile - 1) / clipSize; if (p->getParent() != NULL && pwidth * scale >= 1) { return TOTALWIDTH(BASEWIDTH(pwidth, scale)); } else { return 0; } } else { return pwidth / 2; } }
float WaterElevationLayer::WaterElevationCurveData::getCapLength(NodePtr p, vec2d q) { vec2d o = p->getPos(); float capLength = 0; bool largeRiver = false; for (int i = 0; i < p->getCurveCount(); ++i) { CurvePtr ipath = p->getCurve(i); if ((ipath->getAncestor()->getId() == id) == false) { if (ipath->getType() == LAKE && ipath->getWidth() > 12) { largeRiver = true; } vec2d r = ipath->getXY(p, 1); if (abs(angle(q - o, r - o) - M_PI) < 0.01) { continue; } float pw = flattenCurve->getType() == RIVER ? 2 * flattenCurve->getWidth() : flattenCurve->getWidth(); float ipw = ipath->getType() == RIVER ? 2 * ipath->getWidth() : ipath->getWidth(); vec2d corner = proland::corner(o, q, r, (double) pw, (double) ipw); float dot = (q - o).dot(corner - o); capLength = max((double) capLength, dot / (o - q).length()); } } if (largeRiver && flattenCurve->getType() == RIVER) { capLength = (q - o).length(); } return ceil(capLength); }
NodePtr LazyHydroGraph::addNode(CurvePtr c, int i, Graph::Changes &changed) { CurveId riverId = c.cast<HydroCurve>()->getRiver(); float potential = c.cast<HydroCurve>()->getPotential(); NodePtr n = Graph::addNode(c, i, changed); for (int i = 0; i < 2; i++) { CurvePtr cc = n->getCurve(i); if (!(cc->getId() == c->getId())) { cc.cast<HydroCurve>()->setRiver(riverId); cc.cast<HydroCurve>()->setPotential(potential); } } return n; }
static void deleteKnobAnimation(const std::set<double>& userKeyframes, const KnobIPtr& knob, DeleteKnobAnimationEnum type, double currentTime) { for (int i = 0; i < knob->getNDimensions(); ++i) { CurvePtr curve = knob->getAnimationCurve(ViewIdx(0), DimIdx(i)); assert(curve); KeyFrameSet keys = curve->getKeyFrames_mt_safe(); std::list<double> toRemove; switch (type) { case eDeleteKnobAnimationAll: { for (KeyFrameSet::iterator it = keys.begin(); it != keys.end(); ++it) { std::set<double>::iterator found = userKeyframes.find( it->getTime() ); if ( found == userKeyframes.end() ) { toRemove.push_back( it->getTime() ); } } break; } case eDeleteKnobAnimationBeforeTime: { for (KeyFrameSet::iterator it = keys.begin(); it != keys.end(); ++it) { if (it->getTime() >= currentTime) { break; } std::set<double>::iterator found = userKeyframes.find( it->getTime() ); if ( found == userKeyframes.end() ) { toRemove.push_back( it->getTime() ); } } break; } case eDeleteKnobAnimationAfterTime: { for (KeyFrameSet::reverse_iterator it = keys.rbegin(); it != keys.rend(); ++it) { if (it->getTime() <= currentTime) { break; } std::set<double>::iterator found = userKeyframes.find( it->getTime() ); if ( found == userKeyframes.end() ) { toRemove.push_back( it->getTime() ); } } break; } } knob->deleteValuesAtTime(toRemove, ViewSetSpec::all(), DimIdx(i), eValueChangedReasonUserEdited); } }
void C2M::buildRings(CurvePtr sp){ if (!sp) return; cout<<"rwfer:"<<sp->size()<<endl; ac = new ArrCurve(sp->toArr(), sp->size(), true); RingPtr pre = 0; for(int i=0; i<ac->size(); i++){ Vec3 o = ac->getP(i); Vec3 no = (o - Eye::get()->P).normalize(); Vec3 tan = ac->getT(i); Vec3 up = (no%tan).normalize(); double z = (o - Eye::get()->P).norm(); Vec3 pmid = Eye::get()->P + no*( PZ / (no*Eye::get()->N) ); ac->setP(i, pmid); double t0 = getHit(pmid, up); double t1 = getHit(pmid, -up); //cout<<"..........................................."<<endl; if (t0<0 || t1<0) continue; Vec3 p0 = pmid + up*t0; Vec3 p1 = pmid - up*t1; o = (p0+p1)*0.5; z = (o - Eye::get()->P).norm(); //o = Eye::get()->P + ((p0+p1)*0.5 - Eye::get()->P ).normalize()*z; no = (o - Eye::get()->P).normalize(); Vec3 n0 = (p0 - Eye::get()->P).normalize(); Vec3 n1 = (p1 - Eye::get()->P).normalize(); double a0 = z * (n0*no); double a1 = z * (n1*no); double a = (a0+a1)*0.5; //recompute center to be exactly in the middle of p0 and p1 RingPtr rng = new Ring(o, Eye::get()->P + a*n0, Eye::get()->P + a*n1); //rng->reorient(tan); if (pre) rng->setPrevNext(pre,0); else _rings.push_back(rng); pre = rng; } }
void ChooseColorDialog::apply() { CurveList curveList = _store->getObjects<Curve>(); for (CurveList::iterator curve_iter = curveList.begin(); curve_iter != curveList.end(); ++curve_iter) { VectorPtr vector; CurvePtr curve = kst_cast<Curve>(*curve_iter); if (_xVector->isChecked()) { vector = curve->xVector(); } else { vector = curve->yVector(); } if (DataVectorPtr dataVector = kst_cast<DataVector>(vector)) { curve->writeLock(); curve->setColor(getColorForFile(dataVector->filename())); curve->registerChange(); curve->unlock(); } } // Store the selected colors in the corresponding datasource objects QMutableMapIterator<DataSourcePtr, QColor> itDatasource(_dataSourceColors); QListIterator<ColorButton*> itColorButton(_colorButtons); DataSourcePtr ds; while (itDatasource.hasNext()) { ds = itDatasource.next().key(); ds->setColor(itColorButton.next()->color()); // Per construction there should always be as many color buttons as datasources } updateColorGroup(); // This will update the _dataSourceColors map UpdateManager::self()->doUpdates(true); kstApp->mainWindow()->document()->setChanged(true); }
CurvePtr LazyGraph::newCurve(CurvePtr model, NodePtr start, NodePtr end) { CurveId id = nextCurveId; nextCurveId.id++; CurvePtr c = new LazyCurve(this, id, start->getId(), end->getId()); start->addCurve(id); end->addCurve(id); if (model != NULL) { map<CurveId, long int>::iterator ci = curveOffsets.find(model->getId()); curveOffsets.insert(make_pair(id, ci->second)); } else { curveOffsets.insert(make_pair(id, (long int) -1)); } curves.insert(make_pair(id, c.get())); curveCache->add(c.get(), true); return c; }
void LazyGraph::removeArea(AreaId id) { AreaPtr a = getArea(id); if (a != NULL) { for (int i = 0; i < a->getCurveCount(); i++) { CurvePtr c = a->getCurve(i); c->removeArea(a->getId()); curveCache->add(c.get(), true); } while (a->getCurveCount()) { a->removeCurve(0); } } areaCache->changedResources.erase(a.get()); map<AreaId, long int>::iterator k = areaOffsets.find(id); if (k != areaOffsets.end()) { areaOffsets.erase(k); } }
double HydroFlowProducer::RiverMargin::getMargin(double clipSize, CurvePtr p) { if (p->getType() != HydroCurve::BANK) { float pwidth = p->getWidth(); if (p->getType() == HydroCurve::AXIS) { float scale = 2.0f * (samplesPerTile - 1) / clipSize; if (pwidth * scale >= 1) { return TOTALWIDTH(BASEWIDTH(pwidth, scale)); } else { return 0.0f; } } else { return pwidth / 2.0f; } } if (p.cast<HydroCurve>()->getRiver().id == NULL_ID) { return 0.f; } CurvePtr ancestor = p.cast<HydroCurve>()->getRiverPtr(); assert(ancestor != NULL); return getMargin(clipSize, ancestor) * 2.0f; }
void DifferentiateCurvesDialog::apply() { bool lineColorOrder = !_selectedListBox->findItems(tr("Line Color"), Qt::MatchExactly).empty(); bool pointStyleOrder = !_selectedListBox->findItems(tr("Point Style"), Qt::MatchExactly).empty(); bool lineStyleOrder = !_selectedListBox->findItems(tr("Line Style"), Qt::MatchExactly).empty(); bool lineWidthOrder = !_selectedListBox->findItems(tr("Line Width"), Qt::MatchExactly).empty(); int maxLineWidth = _maxLineWidth->value(); int pointDensity = _pointDensity->currentIndex(); int sequenceNum = 0; CurveList curveList = _store->getObjects<Curve>(); for (CurveList::iterator curve_iter = curveList.begin(); curve_iter != curveList.end(); ++curve_iter) { CurvePtr curve = kst_cast<Curve>(*curve_iter); curve->writeLock(); if (lineColorOrder) { curve->setColor(ColorSequence::entry(sequenceNum)); } if (pointStyleOrder) { curve->setPointType(sequenceNum % KSTPOINT_MAXTYPE); curve->setHasPoints(true); curve->setPointDensity(pointDensity); } if (lineStyleOrder) { curve->setLineStyle(sequenceNum % LINESTYLE_MAXTYPE); } if (lineWidthOrder) { curve->setLineWidth((sequenceNum + 1) % maxLineWidth); } curve->registerChange(); curve->unlock(); ++sequenceNum; } resetLists(); UpdateManager::self()->doUpdates(true); kstApp->mainWindow()->document()->setChanged(true); }
void LazyGraph::removeCurve(CurveId id) { CurvePtr c = getCurve(id); if (c != NULL) { NodePtr start = c->getStart(); NodePtr end = c->getEnd(); NodeId nId; nId.id = NULL_ID; c->addVertex(nId, 0); c->addVertex(nId, 1); if (start != end && start != NULL) { start->removeCurve(id); if (start->getCurveCount() == 0) { NodeId sid = start->getId(); start = NULL; removeNode(sid); } else { nodeCache->add(start.get(), true); } } if (end != NULL) { end->removeCurve(id); if (end->getCurveCount() == 0) { NodeId eid = end->getId(); end = NULL; removeNode(eid); } else { nodeCache->add(end.get(), true); } } } curveCache->changedResources.erase(c.get()); map<CurveId, long int>::iterator k = curveOffsets.find(id); if (k != curveOffsets.end()) { curveOffsets.erase(k); } }
CurvePtr LazyGraph::getCurve(CurveId id) { if (id.id == NULL_ID) { return NULL; } map<CurveId, Curve *>::iterator i = curves.find(id); if (i != curves.end()) { // if the requested resource has already been loaded CurvePtr r = i->second; curveCache->remove(r);// we remove it from the unusedResources Cache //r->owner = this; // and we return the resource return r; } if (Logger::DEBUG_LOGGER != NULL) { ostringstream os; os << "Loading curve '" << id.id << "'"; Logger::DEBUG_LOGGER->log("GRAPH", os.str()); } // otherwise the resource is not already loaded; we first load its descriptor CurvePtr r = NULL; long int offset; map<CurveId, long int>::iterator j = curveOffsets.find(id); if (j != curveOffsets.end()) { offset = j->second; r = loadCurve(offset, id); curves.insert(make_pair(id, r.get())); return r; } if (Logger::ERROR_LOGGER != NULL) { ostringstream os; os << "Loading : Missing or invalid curve '" << id.id << "'"; Logger::ERROR_LOGGER->log("GRAPH", os.str()); } throw exception(); // return NULL; }
void ChooseColorDialog::apply() { CurveList curveList = _store->getObjects<Curve>(); for (CurveList::iterator curve_iter = curveList.begin(); curve_iter != curveList.end(); ++curve_iter) { VectorPtr vector; CurvePtr curve = kst_cast<Curve>(*curve_iter); if (_xVector->isChecked()) { vector = curve->xVector(); } else { vector = curve->yVector(); } if (DataVectorPtr dataVector = kst_cast<DataVector>(vector)) { curve->writeLock(); curve->setColor(getColorForFile(dataVector->dp()->filename())); curve->registerChange(); curve->unlock(); } } updateColorGroup(); UpdateManager::self()->doUpdates(true); kstApp->mainWindow()->document()->setChanged(true); }
void CurveGui::drawCurve(int curveIndex, int curvesCount) { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); AnimItemBasePtr item = _imp->item.lock(); if (!item) { return; } std::vector<float> vertices, exprVertices; const double widgetWidth = _imp->curveWidget->width(); KeyFrameSet keyframes; bool hasDrawnExpr = false; if (item->hasExpression(_imp->dimension, _imp->view)) { //we have no choice but to evaluate the expression at each time for (int i = 0; i < widgetWidth; ++i) { double x = _imp->curveWidget->toZoomCoordinates(i, 0).x(); double y = evaluate(true /*useExpr*/, x); exprVertices.push_back(x); exprVertices.push_back(y); } hasDrawnExpr = true; } QPointF btmLeft = _imp->curveWidget->toZoomCoordinates(0, _imp->curveWidget->height() - 1); QPointF topRight = _imp->curveWidget->toZoomCoordinates(_imp->curveWidget->width() - 1, 0); bool isPeriodic = false; std::pair<double,double> parametricRange = std::make_pair(-std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity()); keyframes = getInternalCurve()->getKeyFrames_mt_safe(); isPeriodic = getInternalCurve()->isCurvePeriodic(); parametricRange = getInternalCurve()->getXRange(); if ( keyframes.empty() ) { // Add a horizontal line for constant knobs, except string knobs. KnobIPtr isKnob = boost::dynamic_pointer_cast<KnobI>(item->getInternalAnimItem()); if (isKnob) { KnobStringBasePtr isString = boost::dynamic_pointer_cast<KnobStringBase>(isKnob); if (!isString) { double value = evaluate(false, 0); vertices.push_back(btmLeft.x() + 1); vertices.push_back(value); vertices.push_back(topRight.x() - 1); vertices.push_back(value); } } } else { try { double x1 = 0; double x2; bool isX1AKey = false; KeyFrame x1Key; KeyFrameSet::const_iterator lastUpperIt = keyframes.end(); while ( x1 < (widgetWidth - 1) ) { double x, y; if (!isX1AKey) { x = _imp->curveWidget->toZoomCoordinates(x1, 0).x(); y = evaluate(false, x); } else { x = x1Key.getTime(); y = x1Key.getValue(); } vertices.push_back( (float)x ); vertices.push_back( (float)y ); nextPointForSegment(x, keyframes, isPeriodic, parametricRange.first, parametricRange.second, &lastUpperIt, &x2, &x1Key, &isX1AKey); x1 = x2; } //also add the last point { double x = _imp->curveWidget->toZoomCoordinates(x1, 0).x(); double y = evaluate(false, x); vertices.push_back( (float)x ); vertices.push_back( (float)y ); } } catch (...) { } } // No Expr curve or no vertices for the curve, don't draw anything else if (exprVertices.empty() && vertices.empty()) { return; } AnimationModuleSelectionModelPtr selectionModel = item->getModel()->getSelectionModel(); assert(selectionModel); const AnimItemDimViewKeyFramesMap& selectedKeys = selectionModel->getCurrentKeyFramesSelection(); const KeyFrameWithStringSet* foundThisCurveSelectedKeys = 0; { AnimItemDimViewIndexID k; k.item = item; k.dim = _imp->dimension; k.view = _imp->view; AnimItemDimViewKeyFramesMap::const_iterator foundDimView = selectedKeys.find(k); if (foundDimView != selectedKeys.end()) { foundThisCurveSelectedKeys = &foundDimView->second; } } { GLProtectAttrib<GL_GPU> a(GL_HINT_BIT | GL_ENABLE_BIT | GL_LINE_BIT | GL_COLOR_BUFFER_BIT | GL_POINT_BIT | GL_CURRENT_BIT); // If this is the only curve selected, draw min/max if (foundThisCurveSelectedKeys && selectedKeys.size()) { // Draw y min/max axis so the user understands why the value is clamped Curve::YRange curveYRange = getCurveYRange(); if (curveYRange.min != INT_MIN && curveYRange.min != -std::numeric_limits<double>::infinity() && curveYRange.max != INT_MAX && curveYRange.max != std::numeric_limits<double>::infinity() ) { QColor minMaxColor; minMaxColor.setRgbF(0.398979, 0.398979, 0.398979); GL_GPU::Color4d(minMaxColor.redF(), minMaxColor.greenF(), minMaxColor.blueF(), 1.); GL_GPU::Begin(GL_LINES); GL_GPU::Vertex2d(btmLeft.x(), curveYRange.min); GL_GPU::Vertex2d(topRight.x(), curveYRange.min); GL_GPU::Vertex2d(btmLeft.x(), curveYRange.max); GL_GPU::Vertex2d(topRight.x(), curveYRange.max); GL_GPU::End(); GL_GPU::Color4d(1., 1., 1., 1.); double xText = _imp->curveWidget->toZoomCoordinates(10, 0).x(); _imp->curveWidget->renderText( xText, curveYRange.min, tr("min").toStdString(), minMaxColor.redF(), minMaxColor.greenF(), minMaxColor.blueF(), minMaxColor.alphaF()); _imp->curveWidget->renderText( xText, curveYRange.max, tr("max").toStdString(), minMaxColor.redF(), minMaxColor.greenF(), minMaxColor.blueF(), minMaxColor.alphaF()); } } GL_GPU::Color4f(_imp->color[0], _imp->color[1], _imp->color[2], _imp->color[3]); GL_GPU::PointSize(_imp->lineWidth); GL_GPU::Enable(GL_BLEND); GL_GPU::BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); GL_GPU::Enable(GL_LINE_SMOOTH); GL_GPU::Hint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE); GL_GPU::LineWidth(1.5); glCheckError(GL_GPU); if (hasDrawnExpr) { drawLineStrip(exprVertices, btmLeft, topRight); GL_GPU::LineStipple(2, 0xAAAA); GL_GPU::Enable(GL_LINE_STIPPLE); } drawLineStrip(vertices, btmLeft, topRight); if (hasDrawnExpr) { GL_GPU::Disable(GL_LINE_STIPPLE); } glCheckErrorIgnoreOSXBug(GL_GPU); //render the name of the curve GL_GPU::Color4f(1.f, 1.f, 1.f, 1.f); double interval = ( topRight.x() - btmLeft.x() ) / (double)curvesCount; double textX = _imp->curveWidget->toZoomCoordinates(15, 0).x() + interval * (double)curveIndex; double textY; CurvePtr internalCurve = _imp->internalCurve.lock(); QString curveName = getName(); QColor thisColor; thisColor.setRgbF(Image::clamp(_imp->color[0], 0., 1.), Image::clamp(_imp->color[1], 0., 1.), Image::clamp(_imp->color[2], 0., 1.)); try { // Use expression to place the text if the curve is not animated textY = evaluate(internalCurve && !internalCurve->isAnimated(), textX); } catch (...) { // if it fails attempt without expression, this will most likely return a constant value textY = evaluate(false /*useExpression*/, textX); } if ( ( textX >= btmLeft.x() ) && ( textX <= topRight.x() ) && ( textY >= btmLeft.y() ) && ( textY <= topRight.y() ) ) { _imp->curveWidget->renderText( textX, textY, curveName.toStdString(), thisColor.redF(), thisColor.greenF(), thisColor.blueF(), thisColor.alphaF()); } GL_GPU::Color4f(_imp->color[0], _imp->color[1], _imp->color[2], _imp->color[3]); //draw keyframes GL_GPU::PointSize(7.f); GL_GPU::Enable(GL_POINT_SMOOTH); KeyFrameWithStringSet::const_iterator foundSelectedKey; if (foundThisCurveSelectedKeys) { foundSelectedKey = foundThisCurveSelectedKeys->end(); } for (KeyFrameSet::const_iterator k = keyframes.begin(); k != keyframes.end(); ++k) { const KeyFrame & key = (*k); // Do not draw keyframes out of range if ( ( key.getTime() < btmLeft.x() ) || ( key.getTime() > topRight.x() ) || ( key.getValue() < btmLeft.y() ) || ( key.getValue() > topRight.y() ) ) { continue; } GL_GPU::Color4f(_imp->color[0], _imp->color[1], _imp->color[2], _imp->color[3]); bool drawKeySelected = false; if (foundThisCurveSelectedKeys) { KeyFrameWithStringSet::const_iterator start = foundSelectedKey == foundThisCurveSelectedKeys->end() ? foundThisCurveSelectedKeys->begin() : foundSelectedKey; foundSelectedKey = std::find_if(start, foundThisCurveSelectedKeys->end(), KeyFrameWithStringTimePredicate(key.getTime())); drawKeySelected = foundSelectedKey != foundThisCurveSelectedKeys->end(); if (!drawKeySelected) { // Also draw the keyframe as selected if it is inside the selection rectangle (but not yet selected) RectD selectionRect = _imp->curveWidget->getSelectionRectangle(); drawKeySelected |= _imp->curveWidget->_imp->eventTriggeredFromCurveEditor && (!selectionRect.isNull() && selectionRect.contains(key.getTime(), key.getValue())); } } // If the key is selected change its color if (drawKeySelected) { GL_GPU::Color4f(0.8f, 0.8f, 0.8f, 1.f); } RectD keyframeBbox = _imp->curveWidget->_imp->getKeyFrameBoundingRectCanonical(_imp->curveWidget->_imp->curveEditorZoomContext, key.getTime(), key.getValue()); // draw texture of the keyframe { AnimationModuleViewPrivate::KeyframeTexture texType = AnimationModuleViewPrivate::kfTextureFromKeyframeType( key.getInterpolation(), drawKeySelected); if (texType != AnimationModuleViewPrivate::kfTextureNone) { _imp->curveWidget->_imp->drawTexturedKeyframe(texType, keyframeBbox, false /*drawdimed*/); } } // Draw tangents if not constant bool drawTangents = drawKeySelected && internalCurve->isYComponentMovable() && (key.getInterpolation() != eKeyframeTypeConstant); if (drawTangents) { QFontMetrics m( _imp->curveWidget->font()); // If interpolation is not free and not broken display with dashes the tangents lines if ( (key.getInterpolation() != eKeyframeTypeFree) && (key.getInterpolation() != eKeyframeTypeBroken) ) { GL_GPU::LineStipple(2, 0xAAAA); GL_GPU::Enable(GL_LINE_STIPPLE); } QPointF leftTanPos, rightTanPos; _imp->curveWidget->getKeyTangentPoints(k, keyframes, &leftTanPos, &rightTanPos); // Draw the derivatives lines GL_GPU::Begin(GL_LINES); GL_GPU::Color4f(1., 0.35, 0.35, 1.); GL_GPU::Vertex2f( leftTanPos.x(), leftTanPos.y() ); GL_GPU::Vertex2f(key.getTime(), key.getValue()); GL_GPU::Vertex2f(key.getTime(), key.getValue()); GL_GPU::Vertex2f( rightTanPos.x(), rightTanPos.y()); GL_GPU::End(); if ( (key.getInterpolation() != eKeyframeTypeFree) && (key.getInterpolation() != eKeyframeTypeBroken) ) { GL_GPU::Disable(GL_LINE_STIPPLE); } // Draw the tangents handles GL_GPU::Begin(GL_POINTS); GL_GPU::Vertex2f( leftTanPos.x(), leftTanPos.y() ); GL_GPU::Vertex2f( rightTanPos.x(), rightTanPos.y()); GL_GPU::End(); // If only one keyframe is selected, also draw the coordinates if (selectedKeys.size() == 1 && foundThisCurveSelectedKeys && foundThisCurveSelectedKeys->size() == 1) { double rounding = std::pow(10., CURVEWIDGET_DERIVATIVE_ROUND_PRECISION); QString leftDerivStr = QString::fromUtf8("l: %1").arg(std::floor( (key.getLeftDerivative() * rounding) + 0.5 ) / rounding); QString rightDerivStr = QString::fromUtf8("r: %1").arg(std::floor( (key.getRightDerivative() * rounding) + 0.5 ) / rounding); double yLeftWidgetCoord = _imp->curveWidget->toWidgetCoordinates(0, leftTanPos.y()).y(); yLeftWidgetCoord += (m.height() + 4); double yRightWidgetCoord = _imp->curveWidget->toWidgetCoordinates(0, rightTanPos.y()).y(); yRightWidgetCoord += (m.height() + 4); GL_GPU::Color4f(1., 1., 1., 1.); glCheckFramebufferError(GL_GPU); _imp->curveWidget->renderText( leftTanPos.x(), _imp->curveWidget->toZoomCoordinates(0, yLeftWidgetCoord).y(), leftDerivStr.toStdString(), 0.9, 0.9, 0.9, 1.); _imp->curveWidget->renderText( rightTanPos.x(), _imp->curveWidget->toZoomCoordinates(0, yRightWidgetCoord).y(), rightDerivStr.toStdString(), 0.9, 0.9, 0.9, 1.); QString coordStr = QString::fromUtf8("x: %1, y: %2"); coordStr = coordStr.arg(key.getTime()).arg(key.getValue()); double yWidgetCoord = _imp->curveWidget->toWidgetCoordinates( 0, key.getValue() ).y(); yWidgetCoord += (m.height() + 4); GL_GPU::Color4f(1., 1., 1., 1.); glCheckFramebufferError(GL_GPU); _imp->curveWidget->renderText( key.getTime(), _imp->curveWidget->toZoomCoordinates(0, yWidgetCoord).y(), coordStr.toStdString(), 0.9, 0.9, 0.9, 1.); } } // drawTangents } // for (KeyFrameSet::const_iterator k = keyframes.begin(); k != keyframes.end(); ++k) { } // GLProtectAttrib(GL_HINT_BIT | GL_ENABLE_BIT | GL_LINE_BIT | GL_COLOR_BUFFER_BIT | GL_POINT_BIT | GL_CURRENT_BIT); glCheckError(GL_GPU); } // drawCurve
ObjectPtr FilterFitDialog::createNewDataObject() { BasicPluginPtr dataObject = kst_cast<BasicPlugin>(DataObject::createPlugin(_filterFitTab->pluginName(), _document->objectStore(), _filterFitTab->configWidget())); Q_ASSERT(dataObject); if (!dataObject->isValid()) { _document->objectStore()->removeObject(dataObject); QString msg(tr("Unable to create Plugin Object using provided parameters.\n\n")); msg += dataObject->errorMessage(); QMessageBox::warning(this, tr("Kst"), msg); return 0; } if(editMode()==New) { PlotItem *plotItem = 0; switch (_filterFitTab->curvePlacement()->place()) { case CurvePlacement::NoPlot: break; case CurvePlacement::ExistingPlot: { plotItem = static_cast<PlotItem*>(_filterFitTab->curvePlacement()->existingPlot()); break; } case CurvePlacement::NewPlotNewTab: _document->createView(); // fall through to case NewPlot. case CurvePlacement::NewPlot: { CreatePlotForCurve *cmd = new CreatePlotForCurve(); cmd->createItem(); plotItem = static_cast<PlotItem*>(cmd->item()); if (_filterFitTab->curvePlacement()->scaleFonts()) { plotItem->view()->resetPlotFontSizes(plotItem); plotItem->view()->configurePlotFontDefaults(plotItem); // copy plots already in window } plotItem->view()->appendToLayout(_filterFitTab->curvePlacement()->layout(), plotItem, _filterFitTab->curvePlacement()->gridColumns()); if (_filterFitTab->curvePlacement()->layout() == CurvePlacement::Custom) { plotItem->createCustomLayout(_filterFitTab->curvePlacement()->gridColumns()); } break; } default: break; } if (plotItem) { CurvePtr curve = _document->objectStore()->createObject<Curve>(); Q_ASSERT(curve); if (!_vectorX) { setVectorX(dataObject->inputVectors().value(dataObject->inputVectorList().first())); } Q_ASSERT(_vectorX); curve->setXVector(_vectorX); VectorPtr yVector = dataObject->outputVectors().value(dataObject->outputVectorList().first()); Q_ASSERT(yVector); curve->setYVector(yVector); curve->setColor(_filterFitTab->curveAppearance()->color()); curve->setHasPoints(_filterFitTab->curveAppearance()->showPoints()); curve->setHasLines(_filterFitTab->curveAppearance()->showLines()); curve->setHasBars(_filterFitTab->curveAppearance()->showBars()); curve->setLineWidth(_filterFitTab->curveAppearance()->lineWidth()); curve->setPointSize(_filterFitTab->curveAppearance()->pointSize()); curve->setLineStyle(_filterFitTab->curveAppearance()->lineStyle()); curve->setPointType(_filterFitTab->curveAppearance()->pointType()); curve->setPointDensity(_filterFitTab->curveAppearance()->pointDensity()); curve->setBarFillColor(_filterFitTab->curveAppearance()->barFillColor()); curve->writeLock(); curve->registerChange(); curve->unlock(); _filterFitTab->curveAppearance()->setWidgetDefaults(); PlotRenderItem *renderItem = plotItem->renderItem(PlotRenderItem::Cartesian); renderItem->addRelation(kst_cast<Relation>(curve)); dataObject->writeLock(); dataObject->internalUpdate(); dataObject->unlock(); if (dataObject->hasParameterVector()) { CreateLabelCommand *cmd = new CreateLabelCommand; QString *tmpstring = new QString(dataObject->parameterVectorToString()); cmd->createItem(tmpstring); } plotItem->update(); } } _filterFitTab->configWidget()->save(); return dataObject; }
RelationPtr Curve::makeDuplicate(QMap<RelationPtr, RelationPtr> &duplicatedRelations) { CurvePtr curve = store()->createObject<Curve>(); if (descriptiveNameIsManual()) { curve->setDescriptiveName(descriptiveName()); } curve->setXVector(xVector()); curve->setYVector(yVector()); if (hasXError()) { curve->setXError(xErrorVector()); } if (hasYError()) { curve->setYError(yErrorVector()); } if (hasXMinusError()) { curve->setXMinusError(xMinusErrorVector()); } if (hasYMinusError()) { curve->setYMinusError(yMinusErrorVector()); } curve->setColor(Color); curve->setHasPoints(HasPoints); curve->setHasLines(HasLines); curve->setHasBars(HasBars); curve->setLineWidth(LineWidth); curve->setLineStyle(LineStyle); curve->setPointType(PointDensity); curve->setPointDensity(PointDensity); curve->setBarStyle(BarStyle); curve->writeLock(); curve->registerChange(); curve->unlock(); duplicatedRelations.insert(this, RelationPtr(curve)); return RelationPtr(curve); }
bool WaterElevationLayer::doCreateTile(int level, int tx, int ty, TileStorage::Slot *data) { if (Logger::DEBUG_LOGGER != NULL) { ostringstream oss; oss << "ElevationRoad tile " << getProducerId() << " " << level << " " << tx << " " << ty; Logger::DEBUG_LOGGER->log("DEM", oss.str()); } if (level >= displayLevel) { TileCache::Tile *t = graphProducer->findTile(level, tx, ty); assert(t != NULL); ObjectTileStorage::ObjectSlot *graphData = dynamic_cast<ObjectTileStorage::ObjectSlot*>(t->getData()); GraphPtr g = graphData->data.cast<Graph>(); if (g->getCurveCount() == 0) { return false; } ptr<FrameBuffer> fb = SceneManager::getCurrentFrameBuffer(); vec3d q = getTileCoords(level, tx, ty); vec2d nx, ny, lx, ly; getDeformParameters(q, nx, ny, lx, ly); float scale = 2.0f * (getTileSize() - 1.0f - (2.0f * getTileBorder())) / q.z; vec3d tileOffset = vec3d(q.x + q.z / 2.0f, q.y + q.z / 2.0f, scale / getTileSize()); //tileOffsetU->set(vec3f(q.x + q.z / 2.0f, q.y + q.z / 2.0f, scale / getTileSize())); tileOffsetU->set(vec3f(0.0, 0.0, 1.0)); fb->clear(false, false, true); if (g->getAreaCount() > 0) { //fillOffsetU->set(vec3f(q.x + q.z / 2.0f, q.y + q.z / 2.0f, scale / getTileSize())); fillOffsetU->set(vec3f(0.0, 0.0, 1.0)); depthU->set(0.02f); colorU->set(vec4f(0.0f, 0.0f, 0.0f, 0.0f)); fb->setDepthTest(true, ALWAYS); fb->setColorMask(false, false, false, true); fb->setDepthMask(true); mesh->setMode(TRIANGLES); mesh->clear(); tess->beginPolygon(mesh); ptr<Graph::AreaIterator> ai = g->getAreas(); while (ai->hasNext()) { AreaPtr a = ai->next(); GraphLayer::drawArea(tileOffset, a, *tess); } tess->endPolygon(); fb->draw(fillProg, *mesh); riverU->set(1); ai = g->getAreas(); while (ai->hasNext()) { AreaPtr a = ai->next(); bool island = true; for (int j = 0; j < a->getCurveCount(); ++j) { int o; island &= (a->getCurve(j, o)->getType() == WaterElevationCurveData::ISLAND); if (!island) { break; } } for (int j = 0; j < a->getCurveCount(); ++j) { int orientation; CurvePtr p = a->getCurve(j, orientation); if (island) { orientation = 1 - orientation; } else { if (p->getType() == WaterElevationCurveData::ISLAND) { continue; } } if (orientation != 0) { GraphLayer::drawCurve(tileOffset, p, vec4f(0, 12, 1, 2), fb, layerProgram, *(meshuv), &nx, &ny, &lx, &ly); } else { GraphLayer::drawCurve(tileOffset, p, vec4f(0, -12, 1, 2), fb, layerProgram, *(meshuv), &nx, &ny, &lx, &ly); } } } fb->setDepthTest(true, NOTEQUAL); fb->setColorMask(false, false, true, false); fb->setDepthMask(false); riverU->set(2); ptr<Graph::CurveIterator> ci = g->getCurves(); while (ci->hasNext()) { CurvePtr c = ci->next(); float w = c->getWidth(); float tw = w; if (w * scale <= 1 || (c->getParent() == NULL && level != 0) || c->getType() == WaterElevationCurveData::LAKE || c->getType() == WaterElevationCurveData::RIVER || c->getArea1() != NULL) {//== WaterElevationCurveData::RIVER) { continue; } ElevationCurveData *cData = dynamic_cast<ElevationCurveData*>(findCurveData(c)); ElevationGraphLayer::drawCurveAltitude(tileOffset, c, cData, tw, tw / w, max(1.0f, 1.0f / scale), false, fb, layerProgram, *meshuv, &nx, &ny, &lx, &ly); } } fb->setColorMask(false, false, true, true); fb->setDepthTest(true, LESS); fb->setDepthMask(true); riverU->set(1); ptr<Graph::CurveIterator> ci = g->getCurves(); while (ci->hasNext()) { CurvePtr c = ci->next(); float cwidth = c->getWidth(); if (cwidth * scale <= 1 || c->getType() != WaterElevationCurveData::RIVER || (c->getParent() == NULL && level != 0)) { continue; } float w = BASEWIDTH(cwidth, scale); float tw = TOTALWIDTH(w); ElevationCurveData *cData = dynamic_cast<ElevationCurveData*>(findCurveData(c)); ElevationGraphLayer::drawCurveAltitude(tileOffset, c, cData, tw, tw / w, max(1.0f, 1.0f / scale), true, fb, layerProgram, *meshuv, &nx, &ny, &lx, &ly); } fb->setColorMask(true, true, true, true); } return true; }
std::pair<MoveTangentCommand::SelectedTangentEnum, AnimItemDimViewKeyFrame > AnimationModuleViewPrivate::isNearbySelectedTangentText(const QPoint & pt) const { QFontMetrics fm( _publicInterface->font() ); int yOffset = TO_DPIY(4); std::pair<MoveTangentCommand::SelectedTangentEnum, AnimItemDimViewKeyFrame > ret; AnimationModuleBasePtr model = _model.lock(); const AnimItemDimViewKeyFramesMap& selectedKeys = model->getSelectionModel()->getCurrentKeyFramesSelection(); if (selectedKeys.empty() || selectedKeys.size() > 1) { return ret; } AnimItemDimViewKeyFramesMap::const_iterator curveIT = selectedKeys.begin(); const KeyFrameWithStringSet& keys = curveIT->second; if (keys.empty() || keys.size() > 1) { return ret; } const KeyFrameWithString& key = *keys.begin(); CurvePtr curve = curveIT->first.item->getCurve(curveIT->first.dim, curveIT->first.view); if (!curve) { return ret; } KeyFrameSet curveKeys = curve->getKeyFrames_mt_safe(); KeyFrameSet::iterator foundKey = Curve::findWithTime(curveKeys, curveKeys.begin(), key.key.getTime()); assert(foundKey != curveKeys.end()); if (foundKey == curveKeys.end()) { return ret; } for (KeyFrameWithStringSet::const_iterator it = keys.begin(); it != keys.end(); ++it) { QPointF leftTanPos, rightTanPos; _publicInterface->getKeyTangentPoints(foundKey, curveKeys, &leftTanPos, &rightTanPos); double rounding = std::pow(10., CURVEWIDGET_DERIVATIVE_ROUND_PRECISION); QPointF topLeft_LeftTanWidget = curveEditorZoomContext.toWidgetCoordinates( leftTanPos.x(), leftTanPos.y() ); QPointF topLeft_RightTanWidget = curveEditorZoomContext.toWidgetCoordinates( rightTanPos.x(), rightTanPos.y() ); topLeft_LeftTanWidget.ry() += yOffset; topLeft_RightTanWidget.ry() += yOffset; QString leftCoordStr = QString( tr("l: %1") ).arg(std::floor( ( key.key.getLeftDerivative() * rounding ) + 0.5 ) / rounding); QString rightCoordStr = QString( tr("r: %1") ).arg(std::floor( ( key.key.getRightDerivative() * rounding ) + 0.5 ) / rounding); QPointF btmRight_LeftTanWidget( topLeft_LeftTanWidget.x() + fm.width(leftCoordStr), topLeft_LeftTanWidget.y() + fm.height() ); QPointF btmRight_RightTanWidget( topLeft_RightTanWidget.x() + fm.width(rightCoordStr), topLeft_RightTanWidget.y() + fm.height() ); if ( (pt.x() >= topLeft_LeftTanWidget.x() - TO_DPIX(CLICK_DISTANCE_TOLERANCE)) && (pt.x() <= btmRight_LeftTanWidget.x() + TO_DPIX(CLICK_DISTANCE_TOLERANCE)) && ( pt.y() >= topLeft_LeftTanWidget.y() - TO_DPIX(CLICK_DISTANCE_TOLERANCE)) && ( pt.y() <= btmRight_LeftTanWidget.y() + TO_DPIX(CLICK_DISTANCE_TOLERANCE)) ) { ret.second.key.key = key.key; StringAnimationManagerPtr stringAnim = curveIT->first.item->getInternalAnimItem()->getStringAnimation(); if (stringAnim) { stringAnim->stringFromInterpolatedIndex(key.key.getValue(), curveIT->first.view, &ret.second.key.string); } ret.second.id = curveIT->first; ret.first = MoveTangentCommand::eSelectedTangentLeft; } else if ( (pt.x() >= topLeft_RightTanWidget.x() - TO_DPIX(CLICK_DISTANCE_TOLERANCE)) && (pt.x() <= btmRight_RightTanWidget.x() + TO_DPIX(CLICK_DISTANCE_TOLERANCE)) && ( pt.y() >= topLeft_RightTanWidget.y() - TO_DPIX(CLICK_DISTANCE_TOLERANCE)) && ( pt.y() <= btmRight_RightTanWidget.y() + TO_DPIX(CLICK_DISTANCE_TOLERANCE)) ) { ret.second.key.key = key.key; StringAnimationManagerPtr stringAnim = curveIT->first.item->getInternalAnimItem()->getStringAnimation(); if (stringAnim) { stringAnim->stringFromInterpolatedIndex(key.key.getValue(), curveIT->first.view, &ret.second.key.string); } ret.second.id = curveIT->first; ret.first = MoveTangentCommand::eSelectedTangentRight; } } // for all curves return ret; } // isNearbySelectedTangentText
ObjectPtr PowerSpectrumDialog::createNewDataObject() const { Q_ASSERT(_document && _document->objectStore()); ObjectTag tag = _document->objectStore()->suggestObjectTag<PSD>(tagString(), ObjectTag::globalTagContext); PSDPtr powerspectrum = _document->objectStore()->createObject<PSD>(tag); Q_ASSERT(powerspectrum); powerspectrum->setVector(_powerSpectrumTab->vector()); powerspectrum->setFreq(_powerSpectrumTab->FFTOptionsWidget()->sampleRate()); powerspectrum->setAverage(_powerSpectrumTab->FFTOptionsWidget()->interleavedAverage()); powerspectrum->setLen(_powerSpectrumTab->FFTOptionsWidget()->FFTLength()); powerspectrum->setApodize(_powerSpectrumTab->FFTOptionsWidget()->apodize()); powerspectrum->setRemoveMean(_powerSpectrumTab->FFTOptionsWidget()->removeMean()); powerspectrum->setVUnits(_powerSpectrumTab->FFTOptionsWidget()->vectorUnits()); powerspectrum->setRUnits(_powerSpectrumTab->FFTOptionsWidget()->rateUnits()); powerspectrum->setApodizeFxn(_powerSpectrumTab->FFTOptionsWidget()->apodizeFunction()); powerspectrum->setGaussianSigma(_powerSpectrumTab->FFTOptionsWidget()->sigma()); powerspectrum->setOutput(_powerSpectrumTab->FFTOptionsWidget()->output()); powerspectrum->setInterpolateHoles(_powerSpectrumTab->FFTOptionsWidget()->interpolateOverHoles()); powerspectrum->writeLock(); powerspectrum->update(0); powerspectrum->unlock(); //FIXME this should be a command... //FIXME need some smart placement... tag = _document->objectStore()->suggestObjectTag<Curve>(powerspectrum->tag().tagString(), ObjectTag::globalTagContext); CurvePtr curve = _document->objectStore()->createObject<Curve>(tag); Q_ASSERT(curve); curve->setXVector(powerspectrum->vX()); curve->setYVector(powerspectrum->vY()); curve->setColor(_powerSpectrumTab->curveAppearance()->color()); curve->setHasPoints(_powerSpectrumTab->curveAppearance()->showPoints()); curve->setHasLines(_powerSpectrumTab->curveAppearance()->showLines()); curve->setHasBars(_powerSpectrumTab->curveAppearance()->showBars()); curve->setLineWidth(_powerSpectrumTab->curveAppearance()->lineWidth()); curve->setLineStyle(_powerSpectrumTab->curveAppearance()->lineStyle()); curve->pointType = _powerSpectrumTab->curveAppearance()->pointType(); curve->setPointDensity(_powerSpectrumTab->curveAppearance()->pointDensity()); curve->setBarStyle(_powerSpectrumTab->curveAppearance()->barStyle()); curve->writeLock(); curve->update(0); curve->unlock(); PlotItem *plotItem = 0; switch (_powerSpectrumTab->curvePlacement()->place()) { case CurvePlacement::NoPlot: break; case CurvePlacement::ExistingPlot: { plotItem = static_cast<PlotItem*>(_powerSpectrumTab->curvePlacement()->existingPlot()); break; } case CurvePlacement::NewPlot: { CreatePlotForCurve *cmd = new CreatePlotForCurve( _powerSpectrumTab->curvePlacement()->createLayout(), _powerSpectrumTab->curvePlacement()->appendToLayout()); cmd->createItem(); plotItem = static_cast<PlotItem*>(cmd->item()); break; } default: break; } PlotRenderItem *renderItem = plotItem->renderItem(PlotRenderItem::Cartesian); renderItem->addRelation(kst_cast<Relation>(curve)); plotItem->update(); return ObjectPtr(powerspectrum.data()); }
void NodeAnimPrivate::computeGroupRange() { NodeGuiPtr nodeUI = nodeGui.lock(); NodePtr node = nodeUI->getNode(); if (!node) { return; } AnimationModulePtr isAnimModel = toAnimationModule(model.lock()); if (!isAnimModel) { return; } NodeGroupPtr nodegroup = node->isEffectNodeGroup(); assert(nodegroup); if (!nodegroup) { return; } AnimationModuleTreeView* treeView = isAnimModel->getEditor()->getTreeView(); NodesList nodes = nodegroup->getNodes(); std::set<double> times; for (NodesList::const_iterator it = nodes.begin(); it != nodes.end(); ++it) { NodeAnimPtr childAnim = isAnimModel->findNodeAnim(*it); if (!childAnim) { continue; } if (!treeView->isItemVisibleRecursive(childAnim->getTreeItem())) { continue; } childAnim->refreshFrameRange(); RangeD childRange = childAnim->getFrameRange(); times.insert(childRange.min); times.insert(childRange.max); // Also check the child knobs keyframes NodeGuiPtr childGui = childAnim->getNodeGui(); const KnobsVec &knobs = childGui->getNode()->getKnobs(); for (KnobsVec::const_iterator it2 = knobs.begin(); it2 != knobs.end(); ++it2) { if ( !(*it2)->isAnimationEnabled() || !(*it2)->hasAnimation() ) { continue; } else { // For each dimension and for each split view get the first/last keyframe (if any) int nDims = (*it2)->getNDimensions(); std::list<ViewIdx> views = (*it2)->getViewsList(); for (std::list<ViewIdx>::const_iterator it3 = views.begin(); it3 != views.end(); ++it3) { for (int i = 0; i < nDims; ++i) { CurvePtr curve = (*it2)->getCurve(*it3, DimIdx(i)); if (!curve) { continue; } int nKeys = curve->getKeyFramesCount(); if (nKeys > 0) { KeyFrame k; if (curve->getKeyFrameWithIndex(0, &k)) { times.insert( k.getTime() ); } if (curve->getKeyFrameWithIndex(nKeys - 1, &k)) { times.insert( k.getTime() ); } } } } } } // for all knobs } // for all children nodes if (times.size() <= 1) { frameRange.min = 0; frameRange.max = 0; } else { frameRange.min = *times.begin(); frameRange.max = *times.rbegin(); } } // computeGroupRange