Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
xoltar committed Jul 13, 2016
1 parent 5c93238 commit b8faef9
Show file tree
Hide file tree
Showing 22 changed files with 261 additions and 161 deletions.
45 changes: 32 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required (VERSION 3.1)
set (CMAKE_CXX_STANDARD 11)
set(CMAKE_BUILD_TYPE Debug)

set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-ftemplate-depth=1024 -Wall -Wextra -pedantic")
project (rivet_console)

include(ExternalProject)
Expand All @@ -16,20 +16,13 @@ externalproject_add(
CMAKE_ARGS -D CMAKE_CXX_STANDARD=11 -D CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
)

externalproject_add(
cereal_project
PREFIX cereal
GIT_REPOSITORY https://github.com/USCiLab/cereal
GIT_TAG v1.2.0
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND COMMAND cp -R ${CMAKE_CURRENT_BINARY_DIR}/cereal/src/cereal_project/include/cereal ${PROJECT_SOURCE_DIR}
)

find_package(Boost 1.60 COMPONENTS serialization-mt system-mt)

#note this must come before add_executable or it will be ignored
link_directories(${CMAKE_CURRENT_BINARY_DIR}/docopt/src/docopt_project-build)

include_directories("${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/include")
include_directories("${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/include" ${Boost_INCLUDE_DIR})

add_executable (rivet_console
console.cpp
Expand All @@ -56,8 +49,34 @@ add_executable (rivet_console
debug.cpp
base_64.cpp)

add_dependencies(rivet_console docopt_project cereal_project)
add_dependencies(rivet_console docopt_project)

target_link_libraries(rivet_console docopt_s ${Boost_LIBRARIES})

target_link_libraries(rivet_console docopt_s)
add_executable(unit_tests
computation.cpp
interface/progress.cpp
interface/file_writer.cpp
interface/file_input_reader.cpp
interface/input_manager.cpp
dcel/mesh.cpp
dcel/mesh_builder.cpp
dcel/anchor.cpp
dcel/barcode_template.cpp
dcel/dcel.cpp
math/map_matrix.cpp
math/multi_betti.cpp
math/simplex_tree.cpp
math/st_node.cpp
math/xi_point.cpp
math/xi_support_matrix.cpp
math/index_matrix.cpp
math/persistence_updater.cpp
numerics.cpp
timer.cpp
debug.cpp
test/unit_tests.cpp)

include_directories("${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/include" ${Boost_INCLUDE_DIR} ${PROJECT_SOURCE_DIR}/test)

target_link_libraries(unit_tests ${Boost_LIBRARIES})
2 changes: 1 addition & 1 deletion RIVET.pro
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#-------------------------------------------------

macx {
QMAKE_CXXFLAGS+="-g -gdwarf-2"
QMAKE_CXXFLAGS+="-g -gdwarf-2 -ftemplate-depth=1024 "
QMAKE_POST_LINK='/usr/bin/dsymutil RIVET.app/Contents/MacOS/RIVET -o RIVET.app/Contents/MacOS/RIVET.dsym'
}

Expand Down
1 change: 1 addition & 0 deletions computation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ std::unique_ptr<ComputationResult> Computation::compute_rivet(RivetInput &input)

//send (a pointer to) the arrangement back to the VisualizationWindow
arrangementReady(arrangement);
return result;
}

std::unique_ptr<ComputationResult> Computation::compute_raw(RawDataInput &input) {
Expand Down
19 changes: 9 additions & 10 deletions computationthread.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "computationthread.h"

#define CEREAL_SERIALIZE_FUNCTION_NAME cerealize

#include "dcel/mesh.h"
#include "interface/input_manager.h"
#include "interface/input_parameters.h"
Expand All @@ -10,13 +8,12 @@
#include "math/xi_point.h"
#include "dcel/serialization.h"

#include <cereal/archives/json.hpp>
#include <cereal/archives/xml.hpp>
#include <cereal/archives/binary.hpp>
#include <cereal/types/memory.hpp>
#include "interface/console_interaction.h"
#include "base_64.h"

#include <boost/archive/tmpdir.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <vector>
#include <QDebug>
#include <QTime>
Expand Down Expand Up @@ -70,8 +67,9 @@ void ComputationThread::run()
// cereal::BinaryInputArchive archive(ss);
XiSupportMessage message;
{
cereal::XMLInputArchive archive(ss);
archive(message);
// cereal::XMLInputArchive archive(ss);
boost::archive::text_iarchive archive(ss);
archive >> message;
}
xi_support = message.xi_support;
std::vector<unsigned> dims(message.homology_dimensions.shape(),
Expand All @@ -93,9 +91,10 @@ void ComputationThread::run()
{
// cereal::BinaryInputArchive archive(ss);
// cereal::JSONInputArchive archive(ss);
cereal::XMLInputArchive archive(ss);
// cereal::XMLInputArchive archive(ss);
boost::archive::text_iarchive archive(ss);
arrangement.reset(new Mesh());
archive(*arrangement);
archive >> *arrangement;
}
qDebug() << "Mesh received: " << arrangement->x_exact.size() << " x " << arrangement->y_exact.size();
emit arrangementReady(&*arrangement);
Expand Down
31 changes: 21 additions & 10 deletions console.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CEREAL_SERIALIZE_FUNCTION_NAME cerealize

#include "interface/input_parameters.h"
#include "dcel/mesh.h"
Expand All @@ -7,9 +6,11 @@
#include "debug.h"
#include <interface/file_writer.h>
#include "docopt/docopt.h"
#include <cereal/archives/json.hpp>
#include <cereal/archives/binary.hpp>
#include <cereal/archives/xml.hpp>
#include <boost/archive/tmpdir.hpp>

#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>

#include "dcel/serialization.h"
#include "base_64.h"

Expand Down Expand Up @@ -93,25 +94,35 @@ int main(int argc, char *argv[])
{
// cereal::JSONOutputArchive archive(std::cout);
// cereal::BinaryOutputArchive archive(ss);
cereal::XMLOutputArchive archive(std::cout);
archive(*mesh);
// cereal::XMLOutputArchive archive(std::cout);
boost::archive::text_oarchive archive(ss);
archive << mesh;

}
// std::string original = ss.str();

// std::string result = encode64(original);
// std::string decoded = decode64(result);
// assert(decoded == original);
std::cout << ss.str() << std::endl;
std::cout << "END ARRANGEMENT" << std::endl;
std::cerr << "Arrangement received: " << mesh->x_exact.size() << " x " << mesh->y_exact.size() << std::endl;
std::cout.flush();
{
std::cerr << "Testing deserialization locally..." << std::endl;
std::string original = ss.str();
boost::archive::text_iarchive inarch(ss);
Mesh test;
inarch >> test;
std::cerr << "Arrangement received: " << test.x_exact.size() << " x " << test.y_exact.size() << std::endl;
}
});
computation.xiSupportReady.connect([](XiSupportMessage message){
std::cout << "XI" << std::endl;
// cereal::JSONOutputArchive archive(std::cout);
// cereal::BinaryOutputArchive archive(std::cout);
{
cereal::XMLOutputArchive archive(std::cout);
archive(message);
// cereal::XMLOutputArchive archive(std::cout);
boost::archive::text_oarchive archive(std::cout);
archive << message;
}
std::cout << "END XI" << std::endl;
std::cout.flush();
Expand Down
9 changes: 7 additions & 2 deletions dcel/anchor.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "anchor.h"

#include <ostream>
#include "../math/xi_support_matrix.h"

Anchor::Anchor(std::shared_ptr<xiMatrixEntry> e) :
Expand Down Expand Up @@ -37,7 +37,12 @@ Anchor& Anchor::operator= (const Anchor& other)
return *this;
}

Anchor::Anchor() { }
std::ostream & operator<<(std::ostream &stream, const Anchor &anchor) {
stream << "Anchor(" << anchor.get_x() << ", " << anchor.get_y() << ")";
return stream;
}

Anchor::Anchor() : x_coord(0), y_coord(0), entry(), dual_line(), position(), above_line(false), weight(0) { }

bool Anchor::operator== (const Anchor& other) const
{
Expand Down
3 changes: 2 additions & 1 deletion dcel/anchor.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ class Anchor
void set_weight(unsigned long w); //sets the estimate of the cost of updating the RU-decomposition when crossing this anchor
unsigned long get_weight(); //returns estimate of the cost of updating the RU-decomposition when crossing this anchor


template <class Archive>
void cerealize(Archive &ar);
void serialize(Archive &ar, const unsigned int version);
private:
unsigned x_coord; //discrete x-coordinate
unsigned y_coord; //discrete y-coordinate
Expand Down
2 changes: 1 addition & 1 deletion dcel/barcode_template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ BarTemplate::BarTemplate(const BarTemplate& other) :
begin(other.begin), end(other.end), multiplicity(other.multiplicity)
{ }

BarTemplate::BarTemplate() { }
BarTemplate::BarTemplate(): begin(0), end(0), multiplicity(0) { }

bool BarTemplate::operator<(const BarTemplate other) const
{
Expand Down
8 changes: 4 additions & 4 deletions dcel/barcode_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ struct BarTemplate
bool operator<(const BarTemplate other) const;

template <class Archive>
void cerealize(Archive & ar) {
ar(begin, end, multiplicity);
void serialize(Archive & ar, const unsigned int version) {
ar & begin & end & multiplicity;
}
};

Expand All @@ -38,8 +38,8 @@ class BarcodeTemplate
void print(); //for testing only

template <class Archive>
void cerealize(Archive &ar) {
ar(bars);
void serialize(Archive &ar, const unsigned int version) {
ar & bars;
}
private:
std::set<BarTemplate> bars;
Expand Down
36 changes: 21 additions & 15 deletions dcel/dcel.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#include "dcel.h"

#include "anchor.h"
#include <ostream>

#include "debug.h"


/*** implementation of class Vertex **/

Vertex::Vertex(double x_coord, double y_coord) :
incident_edge(NULL),
incident_edge(nullptr),
x(x_coord),
y(y_coord)
{ }

Vertex::Vertex() { }
Vertex::Vertex() : incident_edge(nullptr), x(0), y(0) { }

void Vertex::set_incident_edge(std::shared_ptr<Halfedge> edge)
{
Expand All @@ -35,31 +36,36 @@ double Vertex::get_y()
return y;
}

Debug& operator<<(Debug& qd, const Vertex& v)
std::ostream & operator<<(std::ostream &qd, const Vertex &v)
{
qd << "(" << v.x << ", " << v.y << ")";
auto raw = reinterpret_cast<uintptr_t>(&*(v.incident_edge));
qd << "(" << v.x << ", " << v.y << ", " << raw << ")";
return qd;
}

bool Vertex::operator==(Vertex const &other) {
return x == other.x && y == other.y;
}


/*** implementation of class Halfedge ***/

Halfedge::Halfedge(std::shared_ptr<Vertex> v, std::shared_ptr<Anchor> p) :
origin(v),
twin(NULL),
next(NULL),
prev(NULL),
face(NULL),
twin(nullptr),
next(nullptr),
prev(nullptr),
face(nullptr),
anchor(p)
{ }

Halfedge::Halfedge() :
origin(NULL),
twin(NULL),
next(NULL),
prev(NULL),
face(NULL),
anchor(NULL)
origin(nullptr),
twin(nullptr),
next(nullptr),
prev(nullptr),
face(nullptr),
anchor(nullptr)
{ }

void Halfedge::set_twin(std::shared_ptr<Halfedge> e)
Expand Down Expand Up @@ -121,7 +127,7 @@ Debug& operator<<(Debug& qd, const Halfedge& e)
{
std::shared_ptr<Halfedge> t = e.twin;
qd << *(e.origin) << "--" << *(t->origin) << "; ";
if(e.anchor == NULL)
if(e.anchor == nullptr)
qd << "Anchor null; ";
else
qd << "Anchor coords (" << e.anchor->get_x() << ", " << e.anchor->get_y() << "); ";
Expand Down
14 changes: 8 additions & 6 deletions dcel/dcel.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ class Vertex
double get_x(); //get the x-coordinate
double get_y(); //get the y-coordinate

friend Debug& operator<<(Debug& qd, const Vertex& v); //for printing the vertex
friend std::ostream& operator<<(std::ostream &qd, const Vertex& v); //for printing the vertex

template <class Archive> void cerealize(Archive &ar);
bool operator==(Vertex const &other);

template <class Archive> void serialize(Archive &ar, const unsigned int version);

private:
std::shared_ptr<Halfedge> incident_edge; //pointer to one edge incident to this vertex
Expand Down Expand Up @@ -74,7 +76,7 @@ class Halfedge
friend Debug& operator<<(Debug& qd, const Halfedge& e); //for printing the halfedge

template <class Archive>
void cerealize(Archive &ar);
void serialize(Archive &ar, const unsigned int version);
private:
std::shared_ptr<Vertex> origin; //pointer to the vertex from which this halfedge originates
std::shared_ptr<Halfedge> twin; //pointer to the halfedge that, together with this halfedge, make one edge
Expand Down Expand Up @@ -105,7 +107,7 @@ class Face
friend Debug& operator<<(Debug& os, const Face& f); //for printing the face

template<class Archive>
void cerealize(Archive & ar);
void serialize(Archive & ar, const unsigned int version);
private:
std::shared_ptr<Halfedge> boundary; //pointer to one halfedge in the boundary of this cell
BarcodeTemplate dbc; //barcode template stored in this cell
Expand All @@ -121,8 +123,8 @@ struct XiSupportMessage {
std::vector<exact> y_exact;

template<class Archive>
void cerealize(Archive &ar) {
ar(xi_support, homology_dimensions, x_exact, y_exact);
void serialize(Archive &ar, const unsigned int version) {
ar & xi_support & homology_dimensions & x_exact & y_exact;
}
};

Expand Down
Loading

0 comments on commit b8faef9

Please sign in to comment.