Przeglądaj źródła

Added ability to serialize UV and FUV and checking current data with previously serialized reference data.

Former-commit-id: 39a9de87041055e35515d99468a2dc021890e14b
wkevin 10 lat temu
rodzic
commit
7821577d36
2 zmienionych plików z 75 dodań i 0 usunięć
  1. 2 0
      tutorial/505_MIQ/CMakeLists.txt
  2. 73 0
      tutorial/505_MIQ/main.cpp

+ 2 - 0
tutorial/505_MIQ/CMakeLists.txt

@@ -4,9 +4,11 @@ project(505_MIQ)
 include("../CMakeLists.shared")
 
 find_package(LIBCOMISO REQUIRED)
+find_package(TINYXML2 REQUIRED)
 
 include_directories( ${LIBCOMISO_INCLUDE_DIR}
                      ${LIBCOMISO_INCLUDE_DIRS} )
+include_directories( ${TINYXML2_INCLUDE_DIR})
 
 set(SOURCES
 ${PROJECT_SOURCE_DIR}/main.cpp

+ 73 - 0
tutorial/505_MIQ/main.cpp

@@ -14,6 +14,8 @@
 #include <igl/viewer/Viewer.h>
 #include <sstream>
 
+#include <igl/serialize.h>
+#include <igl/xml/serialize_xml.h>
 // Input mesh
 Eigen::MatrixXd V;
 Eigen::MatrixXi F;
@@ -55,6 +57,49 @@ Eigen::MatrixXi FUV_seams;
 Eigen::MatrixXd UV;
 Eigen::MatrixXi FUV;
 
+// Serialization state
+struct MIQState : public igl::Serializable
+{
+  Eigen::MatrixXd UV;
+  Eigen::MatrixXi FUV;
+
+  // You have to define this function to
+  // register the fields you want to serialize
+  void InitSerialization()
+  {
+    this->Add(UV  , "UV");
+    this->Add(FUV , "FUV");
+  }
+
+  virtual ~MIQState(){}
+
+  void printDiff(const MIQState &other, std::ostream& out = std::cout){
+    std::cout << "Start Diff..\n";
+    out << "Checking UV..\n";
+    int nErrorsUV = 0;
+    for(int i = 0; i < UV.rows(); i++){
+      if(UV.row(i) != other.UV.row(i)){
+        if(nErrorsUV == 0)
+          out << "Index\tthisUV\totherUV\n";
+        out << i << UV(i,0) << "\t" << UV(i,1) << "\t" << other.UV(i,0) << "\t" << other.UV(i,1) << std::endl;
+        nErrorsUV++;
+      }
+    }
+
+    out << "Checking FUV..\n";
+    int nErrorsFUV = 0;
+    for(int i = 0; i < FUV.rows(); i++){
+      if(FUV.row(i) != other.FUV.row(i)){
+        if(nErrorsFUV == 0)
+          out << "Index\tthisFUV\totherFUV\n";
+        out << i << FUV(i,0) << "\t" << FUV(i,1) << "\t" << other.FUV(i,0) << "\t" << other.FUV(i,1) << std::endl;
+        nErrorsFUV++;
+      }
+    }
+
+    std::cout << "Finished.\n" << nErrorsUV << " errors in UV.\n" << nErrorsFUV << " errors in FUV.\n";
+  }
+};
 
 // Create a texture that hides the integer translation in the parametrization
 void line_texture(Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic> &texture_R,
@@ -397,6 +442,34 @@ igl::comiso::miq(V,
         }
     });
 
+    viewer.ngui->addNewGroup("Check results");
+    viewer.ngui->addButton("Serialize results", [&](){
+      auto path = nanogui::file_dialog({}, true);
+
+      if(path != ""){
+        MIQState miqstate;
+        miqstate.UV = UV;
+        miqstate.FUV = FUV;
+        // Serialize the state of the application
+        igl::serialize(miqstate,"MIQState",path,true);
+        std::cout << "Serialized UV(" << UV.rows() << " rows) and FUV(" << FUV.rows() << " rows)\n";
+      }
+    });
+
+    viewer.ngui->addButton("Check results with reference", [&](){
+      auto path = nanogui::file_dialog({ {"*", "Any file"}, }, true);
+
+      if(path != ""){
+        MIQState miqstate_ref, miqstate;
+        miqstate.UV = UV;
+        miqstate.FUV = FUV;
+        // Serialize the state of the application
+        igl::deserialize(miqstate_ref,"MIQState",path);
+        std::cout << "this = reference\n";
+        miqstate_ref.printDiff(miqstate);
+      }
+    });
+
 
     viewer.ngui->layout();
     return false;