Permalink
Browse files

corrected position of barcode in viewer

  • Loading branch information...
mlwright84 committed Jul 21, 2017
1 parent a2d3d9b commit b5d486e2046422e5907b57eb38e03fc7409c948b
Showing with 47 additions and 9 deletions.
  1. +13 −0 dcel/barcode.cpp
  2. +3 −0 dcel/barcode.h
  3. +15 −5 numerics.cpp
  4. +1 −1 numerics.h
  5. +15 −3 visualizationwindow.cpp
View
@@ -65,6 +65,19 @@ void Barcode::add_bar(double b, double d, unsigned m)
bars.insert(MultiBar(b, d, m));
}
//shifts the barcode by adding amount to each endpoint of each bar
std::unique_ptr<Barcode> Barcode::shift(double amount)
{
std::unique_ptr<Barcode> bc = std::unique_ptr<Barcode>(new Barcode());
for (std::multiset<MultiBar>::iterator it = bars.begin(); it != bars.end(); ++it) {
MultiBar mb = *it;
bc->add_bar(mb.birth + amount, mb.death + amount, mb.multiplicity);
}
return bc;
}
//returns an iterator to the first bar in the barcode
std::set<MultiBar>::const_iterator Barcode::begin() const
{
View
@@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef __BARCODE_H__
#define __BARCODE_H__
#include <memory>
#include <set>
struct MultiBar {
@@ -40,6 +41,8 @@ class Barcode {
void add_bar(double b, double d, unsigned m); //adds a bar to the barcode
std::unique_ptr<Barcode> shift(double amount); //shifts the barcode by adding amount to each endpoint of each bar
std::multiset<MultiBar>::const_iterator begin() const; //returns an iterator to the first bar in the barcode
std::multiset<MultiBar>::const_iterator end() const; //returns an iterator to the pst-the-end element the barcode
unsigned size() const; //returns the number of multibars in the barcode
View
@@ -92,7 +92,9 @@ namespace numeric {
}
//computes the projection of the lower-left corner of the line-selection window onto the specified line
double project_zero(double angle, double offset, double x_0, double y_0)
// NOTE: parametrization of the line is as in the RIVET paper
// this function is similar to BarcodeTemplate::project()
double project_to_line(double angle, double offset, double x_0, double y_0)
{
if (angle == 0) //then line is horizontal
return x_0;
@@ -103,10 +105,18 @@ namespace numeric {
//if we get here, then line is neither horizontal nor vertical
double radians = angle * PI / 180;
if (y_0 > x_0 * tan(radians) + offset / cos(radians)) //then point is above line
return y_0 / sin(radians) - offset / tan(radians); //project right
return x_0 / cos(radians) + offset * tan(radians); //project up
double yL = x_0 * tan(radians) + offset / cos(radians); // the point (x_0, yL) is on the line
if (y_0 >= yL) { //then point is above line, so project to the right
if (offset >= 0) {
return (y_0 * cos(radians) - offset) / (sin(radians) * cos(radians));
} //else
return y_0 / sin(radians);
} //else: point is below the line, so project up
if (offset >= 0) {
return x_0 / cos(radians);
} //else
return yL / sin(radians);
} //end project_zero()
}
}
View
@@ -38,7 +38,7 @@ namespace numeric {
exact str_to_exact(const std::string& str);
bool is_number(const std::string& str);
std::vector<double> to_doubles(const std::vector<exact> exacts);
double project_zero(double angle, double offset, double x_0, double y_0);
double project_to_line(double angle, double offset, double x_0, double y_0);
const double INFTY(std::numeric_limits<double>::infinity());
const double PI(3.14159265358979323846);
}
View
@@ -184,7 +184,11 @@ void VisualizationWindow::augmented_arrangement_ready(std::shared_ptr<Arrangemen
barcode->print();
if (!grades.x.empty() && !grades.y.empty()) {
//draw the barcode
//shift the barcode so that "zero" is where the selected line crosses the bottom or left side of the viewing window
double ll_corner = rivet::numeric::project_to_line(angle_precise, offset_precise, grades.x[0], grades.y[0]); //lower-left corner of line selection window
barcode = barcode->shift(-1*ll_corner);
//draw the barcode
p_diagram.set_barcode(*barcode);
p_diagram.resize_diagram(slice_diagram.get_slice_length(), slice_diagram.get_pd_scale());
@@ -276,19 +280,27 @@ void VisualizationWindow::update_persistence_diagram()
{
if (persistence_diagram_drawn) {
//get the barcode
if (verbosity >= 4) {
if (verbosity >= 0) {
qDebug() << " QUERY: angle =" << angle_precise << ", offset =" << offset_precise;
}
BarcodeTemplate dbc = arrangement->get_barcode_template(angle_precise, offset_precise);
barcode = dbc.rescale(angle_precise, offset_precise, template_points->template_points, grades);
qDebug() << "Unshifted barcode:";
barcode->print();
//shift the barcode so that "zero" is where the selected line crosses the bottom or left side of the viewing window
double ll_corner = rivet::numeric::project_to_line(angle_precise, offset_precise, grades.x[0], grades.y[0]); //lower-left corner of line selection window
qDebug() << "ll_corner: " << ll_corner;
barcode = barcode->shift(-1*ll_corner);
//TESTING
//qDebug() << " XI SUPPORT VECTOR:";
//for (unsigned i = 0; i < template_points->template_points.size(); i++) {
// TemplatePoint p = template_points->template_points[i];
// qDebug().nospace() << " [" << i << "]: (" << p.x << "," << p.y << ") --> (" << grades.x[p.x] << "," << grades.y[p.y] << ")";
//}
if (verbosity >= 4) {
if (verbosity >= 0) {
dbc.print();
barcode->print();
}

0 comments on commit b5d486e

Please sign in to comment.