Skip to content

Commit

Permalink
Merge pull request #144 from hackerde/window
Browse files Browse the repository at this point in the history
Implement Load New Data Feature
  • Loading branch information
mlesnick committed Jun 19, 2019
2 parents 821493d + 62bfafe commit 51356c6
Show file tree
Hide file tree
Showing 16 changed files with 187 additions and 88 deletions.
4 changes: 3 additions & 1 deletion dataselectdialog.cpp
Expand Up @@ -66,8 +66,10 @@ void DataSelectDialog::closeEvent(QCloseEvent* event)
{
event->accept();

if (!data_selected)
if (!data_selected) {
qobject_cast<QWidget*>(this->parent())->close();
exit(0);
}
}

void DataSelectDialog::on_computeButton_clicked()
Expand Down
10 changes: 5 additions & 5 deletions interface/c_api.cpp
Expand Up @@ -34,7 +34,7 @@ extern "C" RivetComputationResult read_rivet_computation(const char* bytes, size
extern "C" void free_rivet_computation_result(RivetComputationResult result)
{
if (result.computation != nullptr) {
delete reinterpret_cast<ComputationResult *>(result.computation);
delete reinterpret_cast<ComputationResult*>(result.computation);
} else {
delete[] result.error;
}
Expand Down Expand Up @@ -67,7 +67,7 @@ extern "C" BarCodesResult barcodes_from_computation(RivetComputation* rivet_comp
barcodes[i].angle = angles[i];
barcodes[i].offset = offsets[i];
}
// Bounds bounds = compute_bounds(*computation);
// Bounds bounds = compute_bounds(*computation);
result.barcodes = barcodes;
result.length = query_results.size();
result.error = nullptr;
Expand Down Expand Up @@ -108,8 +108,7 @@ extern "C" void free_barcodes_result(BarCodesResult result)
}
}


extern "C" StructurePoints * structure_from_computation(RivetComputation* rivet_computation)
extern "C" StructurePoints* structure_from_computation(RivetComputation* rivet_computation)
{
ComputationResult* computation = reinterpret_cast<ComputationResult*>(rivet_computation);
auto x_exact = new Ratio[computation->arrangement->x_exact.size()];
Expand Down Expand Up @@ -146,7 +145,8 @@ extern "C" StructurePoints * structure_from_computation(RivetComputation* rivet_
return result;
}

void free_structure_points(StructurePoints *points) {
void free_structure_points(StructurePoints* points)
{
delete[] points->grades->x_grades;
delete[] points->grades->y_grades;
delete points->grades;
Expand Down
15 changes: 7 additions & 8 deletions interface/c_api.h
Expand Up @@ -40,7 +40,7 @@ typedef struct {
typedef struct {
BarCode* barcodes;
size_t length;
char * error;
char* error;
size_t error_length;
} BarCodesResult;

Expand Down Expand Up @@ -80,9 +80,9 @@ typedef struct {
} Ratio;

typedef struct {
Ratio *x_grades;
Ratio* x_grades;
size_t x_length;
Ratio *y_grades;
Ratio* y_grades;
size_t y_length;
} ExactGrades;

Expand All @@ -95,15 +95,14 @@ typedef struct {
} StructurePoint;

typedef struct {
ExactGrades *grades;
StructurePoint *points;
ExactGrades* grades;
StructurePoint* points;
size_t length;
} StructurePoints;

StructurePoints * structure_from_computation(RivetComputation* rivet_computation);

void free_structure_points(StructurePoints *points);
StructurePoints* structure_from_computation(RivetComputation* rivet_computation);

void free_structure_points(StructurePoints* points);
}

#endif //RIVET_CONSOLE_C_API_H
6 changes: 6 additions & 0 deletions interface/configuredialog.cpp
Expand Up @@ -119,6 +119,12 @@ ConfigureDialog::~ConfigureDialog()
delete ui;
}

void ConfigureDialog::closeEvent(QCloseEvent* event)
{
emit window_closed(); // tells visualization window to check for changes and redraw
QDialog::closeEvent(event);
}

void ConfigureDialog::on_cancelButton_clicked()
{
close();
Expand Down
4 changes: 4 additions & 0 deletions interface/configuredialog.h
Expand Up @@ -41,6 +41,10 @@ class ConfigureDialog : public QDialog {
public:
explicit ConfigureDialog(ConfigParameters& c_params, InputParameters& i_params, QWidget* parent = 0);
~ConfigureDialog();
void closeEvent(QCloseEvent* event);

signals:
void window_closed();

private slots:
void on_cancelButton_clicked();
Expand Down
13 changes: 5 additions & 8 deletions interface/control_dot.cpp
Expand Up @@ -56,11 +56,9 @@ void ControlDot::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*unus
QRectF rect = boundingRect();
QBrush brush(config_params->sliceLineColor);

if(!slice_line->is_inside_view())
{
if (!slice_line->is_inside_view()) {
brush.setColor(Qt::gray);
}
else if (pressed) {
} else if (pressed) {
brush.setColor(config_params->sliceLineHighlightColor);
}

Expand All @@ -74,8 +72,7 @@ QVariant ControlDot::itemChange(GraphicsItemChange change, const QVariant& value
{
if (change == QGraphicsItem::ItemPositionChange && !update_lock) {


if(!slice_line->is_inside_view()){
if (!slice_line->is_inside_view()) {
//then don't allow the user to drag the dot
return pos();
}
Expand Down Expand Up @@ -165,7 +162,7 @@ void ControlDot::set_position(const QPointF& newpos)

void ControlDot::mousePressEvent(QGraphicsSceneMouseEvent* event)
{
if(!slice_line->is_inside_view()){
if (!slice_line->is_inside_view()) {
return;
}
pressed = true;
Expand All @@ -177,7 +174,7 @@ void ControlDot::mousePressEvent(QGraphicsSceneMouseEvent* event)

void ControlDot::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
{
if(!slice_line->is_inside_view()){
if (!slice_line->is_inside_view()) {
return;
}
pressed = false;
Expand Down
12 changes: 11 additions & 1 deletion interface/persistence_diagram.cpp
Expand Up @@ -48,6 +48,16 @@ PersistenceDiagram::PersistenceDiagram(ConfigParameters* params, QObject* parent
setItemIndexMethod(NoIndex); //not sure why, but this seems to fix the dot update issue (#7 in the issue tracker)
}

// resets data structures and variables to draw new diagram
void PersistenceDiagram::reset()
{
clear();
all_dots.clear();
dots_by_bc_index.clear();
selected = NULL;
barcode = new Barcode();
}

//simply creates all objects; resize_diagram() handles positioning of objects
void PersistenceDiagram::create_diagram()
{
Expand Down Expand Up @@ -541,7 +551,7 @@ void PersistenceDiagram::update_diagram(double slice_length_pix, double diagram_
if (is_visible) {
line_size = slice_length_pix / sqrt(2); //divide by sqrt(2) because the line is drawn at a 45-degree angle
} else {
line_size=0;
line_size = 0;
}
dist_to_origin = slice_dist_dat;
scale = diagram_scale / sqrt(2); //similarly to line_size, divide by sqrt(2)
Expand Down
1 change: 1 addition & 0 deletions interface/persistence_diagram.h
Expand Up @@ -52,6 +52,7 @@ class PersistenceDiagram : public QGraphicsScene {
void deselect_dot(); //remove selection and propagate to the slice diagram

void receive_parameter_change(); //updates the diagram after a change in the configuration parameters
void reset(); // clears up data structures and variable values

public slots:
void receive_dot_selection(unsigned index); //highlight the specified dot, which has been selected externally
Expand Down
3 changes: 1 addition & 2 deletions interface/progressdialog.cpp
Expand Up @@ -85,8 +85,7 @@ void ProgressDialog::updateProgress(unsigned current)
void ProgressDialog::setComputationFinished()
{
computation_finished = true;
QThread::msleep(200); //seems to prevent ProgressDialog from sticking around after it is supposed to have been closed
done(0);
close();
}

void ProgressDialog::closeEvent(QCloseEvent* event)
Expand Down
37 changes: 29 additions & 8 deletions interface/slice_diagram.cpp
Expand Up @@ -58,6 +58,27 @@ SliceDiagram::~SliceDiagram()
clear(); //removes and deletes all items from the QGraphicsScene
}

// resets data structures and variables to draw new diagram
void SliceDiagram::reset()
{
clear();
xi0_dots.clear();
xi1_dots.clear();
xi2_dots.clear();
bars.clear();
primary_selected.clear();
secondary_selected.clear();
points.clear();
hom_dim_rects.resize(boost::extents[0][0]);
dot_left = nullptr;
dot_right = nullptr;
slice_line = nullptr;
max_xi_value = 0;
line_visible = true;
created = false;
control_dot_moved = false;
}

//receives an xi support point, which will be drawn when create_diagram() is called
void SliceDiagram::add_point(double x_coord, double y_coord, int xi0m, int xi1m, int xi2m)
{
Expand Down Expand Up @@ -536,7 +557,7 @@ void SliceDiagram::zoom_diagram(double angle, double offset, double distance_to_
if (line_vert) {
double relative_intercept_horz = (-offset - data_xmin) / (data_xmax - data_xmin); //vertical line has negative offset
x = relative_intercept_horz * diagram_width;
line_visible = (0 <= relative_intercept_horz && relative_intercept_horz <= 1+float(padding)/diagram_width);
line_visible = (0 <= relative_intercept_horz && relative_intercept_horz <= 1 + float(padding) / diagram_width);
slice_line->update_position(x, y, line_vert, 0);
slice_line->set_visibility(line_visible); //don't plot the line if it lies outisde of the viewing window
line_pos = -1 * relative_intercept_horz;
Expand All @@ -550,12 +571,12 @@ void SliceDiagram::zoom_diagram(double angle, double offset, double distance_to_
double relative_intercept_horz = -data_xmin + (data_ymin - intrinsic_y_int) / (intrinsic_slope);
relative_intercept_horz /= data_xmax - data_xmin;
x = relative_intercept_horz * diagram_width;
line_visible = relative_intercept_horz < 1+float(padding)/diagram_width;
line_visible = relative_intercept_horz < 1 + float(padding) / diagram_width;
line_pos = -1 * relative_intercept_horz;
} else //then left-bottom endpoint is along left edge of box
{
y = relative_intercept_vert * diagram_height;
line_visible = relative_intercept_vert < 1+float(padding)/diagram_height;
line_visible = relative_intercept_vert < 1 + float(padding) / diagram_height;
line_pos = relative_intercept_vert;
}

Expand Down Expand Up @@ -689,7 +710,7 @@ void SliceDiagram::update_line(double angle, double offset, double distance_to_o
line_vert = true;
line_pos = offset / (data_xmax - data_xmin); //relative units

line_visible = (-1 <= line_pos && line_pos <= float(padding)/diagram_width); //vertical line has negative offset
line_visible = (-1 <= line_pos && line_pos <= float(padding) / diagram_width); //vertical line has negative offset

//update the SliceLine

Expand All @@ -703,7 +724,7 @@ void SliceDiagram::update_line(double angle, double offset, double distance_to_o
line_vert = false;
line_slope = 0;
line_pos = offset / (data_ymax - data_ymin); //relative units
line_visible = (0 <= line_pos && line_pos <= 1+float(padding)/diagram_height);
line_visible = (0 <= line_pos && line_pos <= 1 + float(padding) / diagram_height);

//update the SliceLine
int ypos = (offset - data_ymin) * scale_y; //pixel units
Expand All @@ -721,14 +742,14 @@ void SliceDiagram::update_line(double angle, double offset, double distance_to_o
if (y_coord >= data_ymin) //then slice line intersects left edge of box
{
line_pos = (y_coord - data_ymin) / (data_ymax - data_ymin); //relative units
line_visible = line_pos < 1+float(padding)/diagram_height;
line_visible = line_pos < 1 + float(padding) / diagram_height;
slice_line->update_position(0, (y_coord - data_ymin) * scale_y, false, line_slope * scale_y / scale_x);

} else //then slice line intersects bottom of box
{
double x_coord = (data_ymin - offset / cos(radians)) / line_slope; //x-coordinate of slice line at y=data_ymin; data units
line_pos = -1 * (x_coord - data_xmin) / (data_xmax - data_xmin); //relative units
line_visible = -1 -float(padding)/diagram_width< line_pos;
line_visible = -1 - float(padding) / diagram_width < line_pos;

slice_line->update_position((x_coord - data_xmin) * scale_x, 0, false, line_slope * scale_y / scale_x);
}
Expand Down Expand Up @@ -903,7 +924,7 @@ std::pair<double, double> SliceDiagram::compute_endpoint(double coordinate, unsi
if (coordinate == std::numeric_limits<double>::infinity() || coordinate * std::min(scale_x, scale_y) > pow(10.0, 7.0)) {
//set coordinate so that it will be outside the viewable window
//the finite cutoff seems to patch over the issue with phantom barcodes-not sure why
coordinate = dist_to_origin+view_length / std::min(scale_x, scale_y);
coordinate = dist_to_origin + view_length / std::min(scale_x, scale_y);
}

//find (x,y) along the line
Expand Down
2 changes: 2 additions & 0 deletions interface/slice_diagram.h
Expand Up @@ -105,6 +105,8 @@ class SliceDiagram : public QGraphicsScene {
int get_diagram_width() { return diagram_width; }; //the width of the above region corresponding to the displayed window bounds
int get_diagram_height() { return diagram_height; };

void reset(); // clears up data structures and variable values

public slots:
void receive_bar_selection(std::vector<unsigned> indexes); //highlight the specified class of bars, which has been selected externally
void receive_bar_secondary_selection(std::vector<unsigned> indexes); //secondary highlight, used for persistence dots that represent multiple classes of bars
Expand Down
18 changes: 7 additions & 11 deletions interface/slice_line.cpp
Expand Up @@ -67,10 +67,9 @@ void SliceLine::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*unuse
QPen pen(config_params->sliceLineColor);
pen.setWidth(config_params->sliceLineWidth);

if(!inside_view){
if (!inside_view) {
pen.setColor(Qt::gray);
}
else if (pressed) {
} else if (pressed) {
pen.setColor(config_params->sliceLineHighlightColor);
}

Expand Down Expand Up @@ -101,8 +100,7 @@ void SliceLine::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*unuse
//left-click and drag to move line, maintaining the same slope
QVariant SliceLine::itemChange(GraphicsItemChange change, const QVariant& value)
{
if(!inside_view)
{//then don't allow the line to be moved
if (!inside_view) { //then don't allow the line to be moved
return QGraphicsItem::itemChange(change, value);
}
if (change == QGraphicsItem::ItemPositionChange && !update_lock) {
Expand Down Expand Up @@ -308,7 +306,7 @@ void SliceLine::update_position(double xpos, double ypos, bool vert, double pixe

void SliceLine::mousePressEvent(QGraphicsSceneMouseEvent* event)
{
if(!inside_view){
if (!inside_view) {
return;
}
if (event->button() == Qt::RightButton) {
Expand All @@ -325,7 +323,7 @@ void SliceLine::mousePressEvent(QGraphicsSceneMouseEvent* event)

void SliceLine::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
{
if(!inside_view){
if (!inside_view) {
return;
}
if (event->button() == Qt::RightButton) {
Expand All @@ -343,7 +341,7 @@ void SliceLine::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
//right-click and drag to change slope, left/bottom endpoint stays fixed
void SliceLine::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
{
if(!inside_view){
if (!inside_view) {
return;
}
if (rotating) {
Expand Down Expand Up @@ -419,7 +417,5 @@ bool SliceLine::is_inside_view()

void SliceLine::set_visibility(bool visible)
{
inside_view=visible;


inside_view = visible;
}
3 changes: 2 additions & 1 deletion interface/slice_line.h
Expand Up @@ -63,6 +63,7 @@ class SliceLine : public QGraphicsItem {

void set_visibility(bool visible);
bool is_inside_view();

protected:
void mousePressEvent(QGraphicsSceneMouseEvent* event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
Expand All @@ -87,7 +88,7 @@ class SliceLine : public QGraphicsItem {
SliceDiagram* sdgm;
ConfigParameters* config_params;

bool inside_view=true;
bool inside_view = true;
void compute_right_point(); //sets correct position of right_point, given slope of line and position of left point
};

Expand Down
6 changes: 3 additions & 3 deletions math/presentation.cpp
Expand Up @@ -371,9 +371,9 @@ void Presentation::minimize(int verbosity)
//mark pivot_i for removal from row indices
new_row_indices[pivot_i] = -1;

//zero out the part of the row pivot_i to the right of i.
//The part of the row to the left is already zero.
#pragma omp parallel for
//zero out the part of the row pivot_i to the right of i.
//The part of the row to the left is already zero.
#pragma omp parallel for
for (unsigned j = i + 1; j < mat.width(); j++) {

if (mat.entry_sorted(pivot_i, j)) {
Expand Down

0 comments on commit 51356c6

Please sign in to comment.