From 7f325559b85756239abba5d004a723281d311a85 Mon Sep 17 00:00:00 2001
From: Jan Schnathmeier <jschnathmeier@veil.informatik.rwth-aachen.de>
Date: Fri, 13 Mar 2020 15:02:47 +0100
Subject: [PATCH] Lab closed, committing what I have

#41
---
 Embedding.cc         |  4 +--
 IsotropicRemesher.cc | 41 +++++++----------------------
 IsotropicRemesher.hh | 13 +++++-----
 MetaMeshPlugin.cc    | 33 ++++++++++-------------
 MetaMeshToolbox.cc   | 62 ++++++++++++++++++++++++++++++++++++--------
 MetaMeshToolbox.hh   | 14 +++++++---
 6 files changed, 93 insertions(+), 74 deletions(-)

diff --git a/Embedding.cc b/Embedding.cc
index b7c7c2f..6ed84f9 100644
--- a/Embedding.cc
+++ b/Embedding.cc
@@ -2003,7 +2003,7 @@ double Embedding::MetaHalfedgeWeight(OpenMesh::HalfedgeHandle mheh) {
   double weight = 0.0;
   std::vector<OpenMesh::HalfedgeHandle> hes = GetBaseHalfedges(mheh);
   for (auto bheh : hes) {
-    weight += std::log(base_mesh_->property(halfedge_weight_, bheh));
+    weight += base_mesh_->property(halfedge_weight_, bheh);
   }
   return weight;
 }
@@ -2017,7 +2017,7 @@ double Embedding::MetaVertexWeight(OpenMesh::VertexHandle mvh) {
   double weight = 0.0;
   for (auto moh : meta_mesh_->voh_range(mvh)) {
     auto bheh = meta_mesh_->property(mhe_connection_, moh);
-    weight += std::log(base_mesh_->property(halfedge_weight_, bheh));
+    weight += base_mesh_->property(halfedge_weight_, bheh);
   }
   return weight;
 }
diff --git a/IsotropicRemesher.cc b/IsotropicRemesher.cc
index a979bf5..a671c6c 100644
--- a/IsotropicRemesher.cc
+++ b/IsotropicRemesher.cc
@@ -122,11 +122,7 @@ void IsotropicRemesher::Remesh(Embedding* embedding,
     qDebug() << "Time elapsed: " << swatchlocal->Delta() << "ms.";
     swatchlocal->Reset();
     qDebug() << "Iteration" << i+1 << "; Smoothing...";
-    if (strtype == IMPLICIT) {
-      Smoothing(embedding, smtype, true);
-    } else {
-      Smoothing(embedding, smtype, false);
-    }
+    Smoothing(embedding, smtype);
     if (debug_hard_stop_) return;
     embedding->CleanUpBaseMesh();
     if (screenshot) {
@@ -442,7 +438,7 @@ int IsotropicRemesher::FlipEval(Embedding *embedding, OpenMesh::EdgeHandle meh)
  * \param shakeup: smoothes vertices twice, moving them away from center first and then
  * back to it. Not recommended as it is very expensive and doesn't seem to help much.
  */
-void IsotropicRemesher::Smoothing(Embedding *embedding, SmoothingType stype, bool shakeup) {
+void IsotropicRemesher::Smoothing(Embedding *embedding, SmoothingType stype) {
   switch(stype) {
     case FORESTFIRE: {
       qDebug() << "Forest Fire Smoothing";
@@ -451,12 +447,12 @@ void IsotropicRemesher::Smoothing(Embedding *embedding, SmoothingType stype, boo
     }
     case VERTEXWEIGHTS: {
       qDebug() << "Vertex Weights Smoothing";
-      SmoothingVWD(embedding, VERTEXWEIGHTS, shakeup);
+      SmoothingVWD(embedding, VERTEXWEIGHTS);
       break;
     }
     case VERTEXDISTANCES:{
       qDebug() << "Vertex Distances Smoothing";
-      SmoothingVWD(embedding, VERTEXDISTANCES, shakeup);
+      SmoothingVWD(embedding, VERTEXDISTANCES);
       break;
     }
   }
@@ -468,8 +464,7 @@ void IsotropicRemesher::Smoothing(Embedding *embedding, SmoothingType stype, boo
  * \param stype
  * \param shakeup
  */
-void IsotropicRemesher::SmoothingVWD(Embedding *embedding, SmoothingType stype
-                                     , bool shakeup) {
+void IsotropicRemesher::SmoothingVWD(Embedding *embedding, SmoothingType stype) {
   auto meta_mesh = embedding->GetMetaMesh();
   auto base_mesh = embedding->GetBaseMesh();
   OpenMesh::VPropHandleT<std::vector<double>> distances;
@@ -491,7 +486,7 @@ void IsotropicRemesher::SmoothingVWD(Embedding *embedding, SmoothingType stype
       for (auto bvh : base_mesh->vertices()) {
         base_mesh->property(distances, bvh) = {};
       }
-      SmoothVertexVWD(embedding, &distances, mvh, stype, shakeup);
+      SmoothVertexVWD(embedding, &distances, mvh, stype);
       if (debug_hard_stop_) return;
       embedding->CleanUpBaseMesh();
     }
@@ -512,18 +507,10 @@ void IsotropicRemesher::SmoothingVWD(Embedding *embedding, SmoothingType stype
 void IsotropicRemesher::SmoothVertexVWD(Embedding *embedding,
                         const OpenMesh::VPropHandleT<std::vector<double>>* distances,
                         OpenMesh::VertexHandle mvh,
-                        SmoothingType stype,
-                        bool shakeup) {
+                        SmoothingType stype) {
   const double inf = std::numeric_limits<double>::infinity();
   auto meta_mesh = embedding->GetMetaMesh();
   auto base_mesh = embedding->GetBaseMesh();
-  // Ensure the vertex is moved twice in order to clean up the underlying basemesh
-  if (shakeup) {
-    embedding->Relocate(mvh, base_mesh->to_vertex_handle(meta_mesh->property(
-      embedding->mhe_connection_, meta_mesh->opposite_halfedge_handle(
-      meta_mesh->halfedge_handle(mvh)))));
-    embedding->CleanUpBaseMesh();
-  }
   std::list<OpenMesh::HalfedgeHandle> mih_list;
   for (auto mhehit : meta_mesh->vih_range(mvh)) {
     if (meta_mesh->is_valid_handle(mhehit)
@@ -916,11 +903,7 @@ void IsotropicRemesher::Straightening(Embedding *embedding, StraighteningType st
   case NONE: {
     break;
   }
-  case IMPLICIT: {
-    // Straightening handled in smoothing by moving vertices twice.
-    break;
-  }
-  case SIMPLE: {
+  case EDGEWISE: {
     // Straighten edgewise
     std::vector<OpenMesh::EdgeHandle> medges;
     for (auto meh : meta_mesh->edges()) {
@@ -1069,12 +1052,8 @@ void IsotropicRemesher::DataOutputParam(Embedding *embedding,
       strtype_str = QString("None");
       break;
     }
-    case IMPLICIT: {
-      strtype_str = QString("Implicit");
-      break;
-    }
-    case SIMPLE: {
-      strtype_str = QString("Simple");
+    case EDGEWISE: {
+      strtype_str = QString("Edgewise");
       break;
     }
     case PATCHWISE: {
diff --git a/IsotropicRemesher.hh b/IsotropicRemesher.hh
index 84bea59..8292ec8 100644
--- a/IsotropicRemesher.hh
+++ b/IsotropicRemesher.hh
@@ -19,7 +19,7 @@ public:
   ~IsotropicRemesher() {}
 
   enum SmoothingType{FORESTFIRE, VERTEXWEIGHTS, VERTEXDISTANCES};
-  enum StraighteningType{NONE, IMPLICIT, SIMPLE, PATCHWISE};
+  enum StraighteningType{NONE, EDGEWISE, PATCHWISE};
   enum CollapsingOrder{RANDOM, VALENCE, SPLITWEIGHT};
 
   void Remesh(Embedding* embedding,
@@ -27,10 +27,10 @@ public:
               uint iterations = 1,
               double alpha = 4.0/3.0,
               double beta = 4.0/5.0,
-              SmoothingType smtype = VERTEXWEIGHTS,
+              SmoothingType smtype = VERTEXDISTANCES,
               std::function<void (QString, QString, double, double)> screenshot = {},
               bool limitflips = false,
-              StraighteningType strtype = PATCHWISE,
+              StraighteningType strtype = NONE,
               CollapsingOrder corder = SPLITWEIGHT,
               bool dataoutput = true);
   bool DebugStopStatus() {return debug_hard_stop_;}
@@ -40,13 +40,12 @@ private:
   void Collapses(Embedding* embedding, double low, CollapsingOrder corder = SPLITWEIGHT);
   void Flips(Embedding* embedding, bool limitflips = false);
   int FlipEval(Embedding* embedding, OpenMesh::EdgeHandle meh);
-  void Smoothing(Embedding* embedding, SmoothingType stype = FORESTFIRE, bool shakeup = true);
-  void SmoothingVWD(Embedding* embedding, SmoothingType stype, bool shakeup = true);
+  void Smoothing(Embedding* embedding, SmoothingType stype = FORESTFIRE);
+  void SmoothingVWD(Embedding* embedding, SmoothingType stype);
   void SmoothVertexVWD(Embedding* embedding,
                     const OpenMesh::VPropHandleT<std::vector<double>>* distances,
                     OpenMesh::VertexHandle mvh,
-                    SmoothingType stype,
-                    bool shakeup = true);
+                    SmoothingType stype);
   double DistanceScoreVW(Embedding* embedding,
                          const OpenMesh::VPropHandleT<std::vector<double>>* distances,
                          OpenMesh::VertexHandle bvh, uint numv);
diff --git a/MetaMeshPlugin.cc b/MetaMeshPlugin.cc
index a854c7a..d197648 100644
--- a/MetaMeshPlugin.cc
+++ b/MetaMeshPlugin.cc
@@ -318,26 +318,19 @@ void MetaMeshPlugin::remesh() {
     screenshot(name, dir, width, height);
   };
 
-  switch(widget_->combo_box_remeshing_->currentIndex()) {
-  case IsotropicRemesher::FORESTFIRE: {
-    remesher.Remesh(embedding_,  widget_->input_length_->value(),
-                     static_cast<uint>(widget_->input_iterations_->value()), 4.0/3.0, 4.0/5.0,
-                     IsotropicRemesher::FORESTFIRE, take_screenshot);
-    break;
-  }
-  case IsotropicRemesher::VERTEXWEIGHTS:{
-    remesher.Remesh(embedding_,  widget_->input_length_->value(),
-                     static_cast<uint>(widget_->input_iterations_->value()), 4.0/3.0, 4.0/5.0,
-                     IsotropicRemesher::VERTEXWEIGHTS, take_screenshot);
-    break;
-  }
-  case IsotropicRemesher::VERTEXDISTANCES:{
-    remesher.Remesh(embedding_,  widget_->input_length_->value(),
-                     static_cast<uint>(widget_->input_iterations_->value()), 4.0/3.0, 4.0/5.0,
-                     IsotropicRemesher::VERTEXDISTANCES, take_screenshot);
-    break;
-  }
-  }
+  remesher.Remesh(embedding_,  widget_->input_length_->value(),
+                  static_cast<uint>(widget_->input_iterations_->value()),
+                  widget_->input_alpha_->value(),
+                  widget_->input_beta_->value(),
+                  IsotropicRemesher::SmoothingType(
+                    widget_->combo_box_remeshing_smtype_->currentIndex()),
+                  take_screenshot,
+                  widget_->checkbox_limit_flips_->isChecked(),
+                  IsotropicRemesher::StraighteningType(
+                  widget_->combo_box_remeshing_strype_->currentIndex()),
+                  IsotropicRemesher::CollapsingOrder(
+                  widget_->combo_box_remeshing_crorder_->currentIndex()),
+                  widget_->checkbox_data_output_->isChecked());
 
   postoperation(UPDATE_TOPOLOGY, UPDATE_TOPOLOGY);
 }
diff --git a/MetaMeshToolbox.cc b/MetaMeshToolbox.cc
index ddb168c..10d32f3 100644
--- a/MetaMeshToolbox.cc
+++ b/MetaMeshToolbox.cc
@@ -29,11 +29,23 @@ MetaMeshToolbox::MetaMeshToolbox(QWidget* parent) : QWidget(parent)
   combo_box_tests_->addItem("Relocations");
   combo_box_tests_->setCurrentIndex(1);
 
-  combo_box_remeshing_ = new QComboBox;
-  combo_box_remeshing_->addItem("Forest Fire");
-  combo_box_remeshing_->addItem("Vertex Weights");
-  combo_box_remeshing_->addItem("Vertex Distances");
-  combo_box_remeshing_->setCurrentIndex(2);
+  combo_box_remeshing_smtype_ = new QComboBox;
+  combo_box_remeshing_smtype_->addItem("Forest Fire");
+  combo_box_remeshing_smtype_->addItem("Vertex Weights");
+  combo_box_remeshing_smtype_->addItem("Vertex Distances");
+  combo_box_remeshing_smtype_->setCurrentIndex(2);
+
+  combo_box_remeshing_strype_ = new QComboBox;
+  combo_box_remeshing_strype_->addItem("None");
+  combo_box_remeshing_strype_->addItem("Edgewise");
+  combo_box_remeshing_strype_->addItem("Patchwise");
+  combo_box_remeshing_strype_->setCurrentIndex(2);
+
+  combo_box_remeshing_crorder_ = new QComboBox;
+  combo_box_remeshing_crorder_->addItem("Random");
+  combo_box_remeshing_crorder_->addItem("Valence");
+  combo_box_remeshing_crorder_->addItem("Splitweight");
+  combo_box_remeshing_crorder_->setCurrentIndex(2);
 
   button_triangulate_ = new QPushButton("Triangulate");
   button_randomize_ratio_ = new QPushButton("Randomize a ratio of points");
@@ -51,8 +63,12 @@ MetaMeshToolbox::MetaMeshToolbox(QWidget* parent) : QWidget(parent)
   button_opp_ = new QPushButton("opp");
   button_prev_ = new QPushButton("prv");
   button_remesh_ = new QPushButton("Remesh");
+  checkbox_limit_flips_ = new QCheckBox("Limit Flips");
+  checkbox_data_output_ = new QCheckBox("Output Data");
 
   checkbox_copy_markings_->setCheckState(Qt::Checked);
+  checkbox_limit_flips_->setCheckState(Qt::Unchecked);
+  checkbox_data_output_->setCheckState(Qt::Checked);
 
   input_ratio_ = new QDoubleSpinBox();
   input_ratio_->setRange(0,1);
@@ -62,8 +78,22 @@ MetaMeshToolbox::MetaMeshToolbox(QWidget* parent) : QWidget(parent)
   input_ratio_->setToolTip("Ratio of Base Mesh Vertices to be "
                            "randomly assigned as Meta Mesh vertices");
 
+  input_alpha_ = new QDoubleSpinBox();
+  input_alpha_->setRange(1,10);
+  input_alpha_->setDecimals(3);
+  input_alpha_->setSingleStep(0.001);
+  input_alpha_->setValue(4.0/3.0);
+  input_alpha_->setToolTip("Alpha parameter; splitting slack var");
+
+  input_beta_ = new QDoubleSpinBox();
+  input_beta_->setRange(0.1,1);
+  input_beta_->setDecimals(3);
+  input_beta_->setSingleStep(0.001);
+  input_beta_->setValue(4.0/5.0);
+  input_beta_->setToolTip("Beta parameter; collapsing slack var");
+
   input_length_ = new QDoubleSpinBox();
-  input_length_->setRange(0,1);
+  input_length_->setRange(0,2);
   input_length_->setDecimals(3);
   input_length_->setSingleStep(0.001);
   input_length_->setValue(0.2);
@@ -75,6 +105,8 @@ MetaMeshToolbox::MetaMeshToolbox(QWidget* parent) : QWidget(parent)
   input_iterations_->setSingleStep(1);
   input_iterations_->setToolTip("Number of times the algorithm runs");
 
+  QLabel* label_alpha = new QLabel("Alpha:");
+  QLabel* label_beta = new QLabel("Beta:");
   QLabel* label_length = new QLabel("Length:");
   QLabel* label_iterations = new QLabel("Iterations:");
 
@@ -97,10 +129,18 @@ MetaMeshToolbox::MetaMeshToolbox(QWidget* parent) : QWidget(parent)
   layout->addWidget(button_opp_, 10, 2, 1, 2);
   layout->addWidget(button_prev_, 10, 4, 1, 2);
   layout->addWidget(button_remesh_, 11, 0, 1, 3);
-  layout->addWidget(combo_box_remeshing_, 11, 3, 1, 3);
-  layout->addWidget(label_length, 12, 0, 1, 3);
-  layout->addWidget(input_length_, 13, 0, 1, 3);
-  layout->addWidget(label_iterations, 12, 3, 1, 3);
-  layout->addWidget(input_iterations_, 13, 3, 1, 3);
+  layout->addWidget(combo_box_remeshing_smtype_, 11, 3, 1, 3);
+  layout->addWidget(combo_box_remeshing_strype_, 12, 0, 1, 3);
+  layout->addWidget(combo_box_remeshing_crorder_, 12, 3, 1, 3);
+  layout->addWidget(checkbox_limit_flips_, 14, 0, 1, 2);
+  layout->addWidget(label_alpha, 13, 2, 1, 2);
+  layout->addWidget(input_alpha_, 14, 2, 1, 2);
+  layout->addWidget(label_beta, 13, 4, 1, 2);
+  layout->addWidget(input_beta_, 14, 4, 1, 2);
+  layout->addWidget(checkbox_data_output_, 16, 0, 1, 2);
+  layout->addWidget(label_length, 15, 2, 1, 2);
+  layout->addWidget(input_length_, 16, 2, 1, 2);
+  layout->addWidget(label_iterations, 15, 4, 1, 2);
+  layout->addWidget(input_iterations_, 16, 4, 1, 2);
   this->setLayout(layout);
 }
diff --git a/MetaMeshToolbox.hh b/MetaMeshToolbox.hh
index ebe4ff0..8c530a3 100644
--- a/MetaMeshToolbox.hh
+++ b/MetaMeshToolbox.hh
@@ -22,7 +22,6 @@ public:
     QRadioButton* checkbox_a_star_triangulation_;
     QRadioButton* checkbox_a_star_midpoint_triangulation_;
     QComboBox* combo_box_tests_;
-    QComboBox* combo_box_remeshing_;
 
     QPushButton* button_triangulate_;
     QPushButton* button_randomize_ratio_;
@@ -34,14 +33,23 @@ public:
     QPushButton* button_split_;
     QPushButton* button_collapse_;
     QPushButton* button_relocate_;
-    QPushButton* button_remesh_;
     QPushButton* button_dummy1_;
     QPushButton* button_dummy2_;
     QPushButton* button_next_;
     QPushButton* button_opp_;
     QPushButton* button_prev_;
-    QDoubleSpinBox* input_length_;
     QDoubleSpinBox* input_ratio_;
+
+    // Remeshing
+    QPushButton* button_remesh_;
+    QComboBox* combo_box_remeshing_smtype_;
+    QComboBox* combo_box_remeshing_strype_;
+    QComboBox* combo_box_remeshing_crorder_;
+    QCheckBox* checkbox_limit_flips_;
+    QDoubleSpinBox* input_alpha_;
+    QDoubleSpinBox* input_beta_;
+    QCheckBox* checkbox_data_output_;
+    QDoubleSpinBox* input_length_;
     QSpinBox* input_iterations_;
 };
 
-- 
GitLab