Skip to content

Commit

Permalink
Some improvements with data mode and matrixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
netterfield committed Sep 30, 2013
1 parent 9441196 commit 78e90bb
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 9 deletions.
17 changes: 17 additions & 0 deletions src/libkst/matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,23 @@ double Matrix::value(double x, double y, bool* ok) const {

}

double Matrix::value(double x, double y, QPointF &matchedPoint, bool* ok) const {
int x_index = (int)((x - _minX) / (double)_stepX);
int y_index = (int)((y - _minY) / (double)_stepY);

matchedPoint.setX((x_index+0.5)*_stepX+_minX);
matchedPoint.setY((y_index+0.5)*_stepY+_minY);

int index = zIndex(x_index, y_index);
if ((index < 0) || !isfinite(_z[index]) || KST_ISNAN(_z[index])) {
if (ok) (*ok) = false;
return 0.0;
}
if (ok) (*ok) = true;
return _z[index];

}


double Matrix::valueRaw(int x, int y, bool* ok) const {
int index = zIndex(x,y);
Expand Down
1 change: 1 addition & 0 deletions src/libkst/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class KSTCORE_EXPORT Matrix : public Primitive
// return the z value of the rectangle in which the specified point lies
// ok is false if the point is out of bounds
double value(double x, double y, bool *ok = 0L) const;
double value(double x, double y, QPointF &matchedPoint, bool *ok = 0L) const;

// set the z value of the rectangle in which the specified point lies
// return false if the point is out of bounds
Expand Down
38 changes: 32 additions & 6 deletions src/libkstapp/plotrenderitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,10 +805,31 @@ void PlotRenderItem::processHoverMoveEvent(const QPointF &p) {
if (kstApp->mainWindow()->isHighlightPoint()) {
highlightNearestDataPoint(point);
} else {
QPointF matchedPoint;
double imageZ;
bool bFoundImage = false;
QString message;
QString imageName;

foreach(RelationPtr relation, relationList()) {
if (Image* image = kst_cast<Image>(relation)) {
if (!bFoundImage && image->getNearestZ(point.x(), point.y(), imageZ, matchedPoint)) {
bFoundImage = true;
imageName = image->CleanedName();
}
}
}
_highlightPointActive = false;
QString message = QString("(%1, %2)").
arg(plotItem()->xAxis()->statusBarString(point.x())).
arg(QString::number(point.y()));
if (bFoundImage) {
message = QString("%1 (%2, %3, %4)").arg(imageName).
arg(plotItem()->xAxis()->statusBarString(point.x())).
arg(QString::number(point.y())).
arg(QString::number(imageZ));
} else {
message = QString("(%1, %2)").
arg(plotItem()->xAxis()->statusBarString(point.x())).
arg(QString::number(point.y()));
}
if (_referencePointMode) {
message += QString(" [Offset: %1, %2]").arg(QString::number(point.x() - _referencePoint.x(), 'G')).arg(QString::number(point.y() - _referencePoint.y()));
}
Expand Down Expand Up @@ -852,7 +873,7 @@ void PlotRenderItem::highlightNearestDataPoint(const QPointF& position) {
}
}
} else if (Image* image = kst_cast<Image>(relation)) {
if (!bFoundImage && image->getNearestZ(position.x(), position.y(), imageZ)) {
if (!bFoundImage && image->getNearestZ(position.x(), position.y(), imageZ, matchedPoint)) {
bFoundImage = true;
imageName = image->CleanedName();
}
Expand All @@ -873,10 +894,15 @@ void PlotRenderItem::highlightNearestDataPoint(const QPointF& position) {
} else if (!imageName.isEmpty()) {
statusMessagePoint = position;
QString message = imageName + QString(" (%1, %2, %3)").
arg(plotItem()->xAxis()->statusBarString(position.x())).
arg(QString::number(position.y())).
arg(plotItem()->xAxis()->statusBarString(matchedPoint.x())).
arg(QString::number(matchedPoint.y())).
arg(QString::number(imageZ, 'G'));
kstApp->mainWindow()->setStatusMessage(message);
_highlightPointActive = true;
_highlightPoint = QPointF(matchedPoint.x(), matchedPoint.y());
} else {
QString message = QString("(%1 %2)").arg(QString::number(position.x())).arg(QString::number(position.y()));
kstApp->mainWindow()->setStatusMessage(message);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libkstmath/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ void Image::clearContourLines() {
}


bool Image::getNearestZ(double x, double y, double& z) {
bool Image::getNearestZ(double x, double y, double& z, QPointF &matchedPoint) {
bool ok;
z = _inputMatrices[THEMATRIX]->value(x,y,&ok);
z = _inputMatrices[THEMATRIX]->value(x, y, matchedPoint, &ok);
return ok;
}

Expand Down
2 changes: 1 addition & 1 deletion src/libkstmath/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class KSTMATH_EXPORT Image : public Relation {
virtual void internalUpdate();
virtual QString propertyString() const;

virtual bool getNearestZ(double x, double y, double& z);
virtual bool getNearestZ(double x, double y, double& z, QPointF &matchedPoint);
virtual QColor getMappedColor(double z);
virtual void setPalette(const Palette &pal);
virtual void setUpperThreshold(double z);
Expand Down

0 comments on commit 78e90bb

Please sign in to comment.