Permalink
Browse files

modified to separate parsing from other calls, so a computationresult…

… can be kept in memory and re-used
  • Loading branch information...
xoltar committed Nov 20, 2017
1 parent 33b26b4 commit 158a4f5a291efd8cce87f70639e49391d342e5a4
Showing with 80 additions and 14 deletions.
  1. +14 −0 api.cpp
  2. +11 −0 api.h
  3. +3 −7 console.cpp
  4. +35 −5 interface/c_api.cpp
  5. +17 −2 interface/c_api.h
14 api.cpp
@@ -71,3 +71,17 @@ std::vector<std::unique_ptr<Barcode>> query_barcodes(const ComputationResult &co
}
return result;
}
Bounds compute_bounds(const ComputationResult &computation_result) {
const auto grades = Grades(computation_result.arrangement->x_exact, computation_result.arrangement->y_exact);
const auto x_low = grades.x.front();
const auto y_low = grades.y.front();
const auto x_high = grades.x.back();
const auto y_high = grades.y.back();
return Bounds {
x_low,
y_low,
x_high,
y_high
};
}
11 api.h
@@ -27,4 +27,15 @@ std::vector<std::unique_ptr<Barcode>> query_barcodes(const ComputationResult &co
const std::vector<std::pair<double, double>> &offset_slopes);
std::unique_ptr<ComputationResult> from_istream(std::istream &file);
struct Bounds {
double x_low;
double y_low;
double x_high;
double y_high;
};
Bounds compute_bounds(const ComputationResult &computation_result);
#endif //RIVET_CONSOLE_API_H
@@ -174,13 +174,9 @@ void print_betti(TemplatePointsMessage const& message, std::ostream& ostream)
}
void process_bounds(const ComputationResult &computation_result) {
const auto grades = Grades(computation_result.arrangement->x_exact, computation_result.arrangement->y_exact);
const auto x_low = grades.x.front();
const auto y_low = grades.y.front();
const auto x_high = grades.x.back();
const auto y_high = grades.y.back();
std::cout << "low: " << x_low << ", " << y_low << std::endl;
std::cout << "high: " << x_high << ", " << y_high << std::endl;
auto bounds = compute_bounds(computation_result);
std::cout << "low: " << bounds.x_low << ", " << bounds.y_low << std::endl;
std::cout << "high: " << bounds.x_high << ", " << bounds.y_high << std::endl;
}
void process_barcode_queries(std::string query_file_name, const ComputationResult& computation_result)
@@ -14,17 +14,32 @@
#include "input_parameters.h"
extern "C"
RivetComputation* read_rivet_computation(const char* bytes, size_t length) {
try {
std::istringstream buf(std::string(bytes, length));
auto computation = from_istream(buf);
return reinterpret_cast<RivetComputation*>(computation.release());
} catch (std::exception &e) {
std::cerr << "RIVET error: " << e.what() << std::endl;
return nullptr;
}
}
extern "C"
BarCodesResult* barcodes_from_bytes(const char* bytes,
size_t length,
void free_rivet_computation(RivetComputation* computation) {
delete reinterpret_cast<ComputationResult*>(computation);
}
extern "C"
BarCodesResult* barcodes_from_computation(RivetComputation* rivet_computation,
double* angles,
double* offsets,
size_t query_length
) {
try {
std::istringstream buf(std::string(bytes, length));
auto computation = from_istream(buf);
ComputationResult* computation = reinterpret_cast<ComputationResult*>(rivet_computation);
std::vector<std::pair<double, double>> pos;
for (size_t i = 0; i < query_length; i++) {
@@ -44,14 +59,29 @@ BarCodesResult* barcodes_from_bytes(const char* bytes,
barcodes[i].angle = angles[i];
barcodes[i].offset = offsets[i];
}
auto result = new BarCodesResult{barcodes, query_results.size()};
Bounds bounds = compute_bounds(*computation);
auto result = new BarCodesResult{ barcodes,
query_results.size(),
};
return result;
} catch (std::exception &e) {
std::cerr << "RIVET error: " << e.what() << std::endl;
return nullptr;
}
}
extern "C"
ArrangementBounds bounds_from_computation(RivetComputation * rivet_computation) {
ComputationResult* computation = reinterpret_cast<ComputationResult*>(rivet_computation);
auto bounds = compute_bounds(*computation);
return ArrangementBounds {
bounds.x_low,
bounds.y_low,
bounds.x_high,
bounds.y_high
};
}
extern "C"
void free_barcodes_result(BarCodesResult *result) {
for (size_t bc = 0; bc < result->length; bc++) {
@@ -42,14 +42,29 @@ typedef struct {
size_t length;
} BarCodesResult;
typedef struct {
double x_low;
double y_low;
double x_high;
double y_high;
} ArrangementBounds;
struct rivet_comp;
typedef rivet_comp RivetComputation;
RivetComputation * read_rivet_computation(const char* bytes, size_t length);
//Computed* compute_arrangement_from_point_cloud(PointCloud);
BarCodesResult* barcodes_from_bytes(const char* bytes,
size_t length,
BarCodesResult* barcodes_from_computation(RivetComputation* rivet_computation,
double* offsets,
double* angles,
size_t query_length
);
ArrangementBounds bounds_from_computation(RivetComputation* rivet_computation);
void free_rivet_computation(RivetComputation * rivet_computation);
void free_barcodes_result(BarCodesResult *result);
}

0 comments on commit 158a4f5

Please sign in to comment.