Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate arcMap generation from writing to file #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions ContourTree/ContourTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,19 @@ void ContourTree::computeCT() {
}
}

void ContourTree::output(std::string fileName) {
std::cout << "removing deg-2 nodes and computing segmentation" << std::endl;

// saving some memory
nodesJoin.clear();
nodesJoin.shrink_to_fit();
nodesSplit.clear();
nodesSplit.shrink_to_fit();
std::tuple<uint32_t, std::vector<int64_t>, std::vector<scalar_t>, std::vector<char>,
std::vector<int64_t>>
ContourTree::computeArcMap() {

uint32_t arcNo = 0;
std::vector<int64_t> nodeids;
std::vector<scalar_t> nodefns;
std::vector<char> nodeTypes;
std::vector<int64_t> arcs;

arcMap.resize(nv, -1);

uint32_t arcNo = 0;
for (int64_t i = 0; i < nv; i++) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there a nested loop here?

for(int64_t i = 0;i < nv;i ++) {
// go in sorted order
int64_t v = tree->sv[i];
Expand Down Expand Up @@ -147,6 +143,20 @@ void ContourTree::output(std::string fileName) {
}
}

return {arcNo, nodeids, nodefns, nodeTypes, arcs};
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this added because of the additional loop? Based in this, the return statement is anyway inside the second loop. Was the first loop a copy paste error?

void ContourTree::output(std::string fileName) {
std::cout << "removing deg-2 nodes and computing segmentation" << std::endl;

// saving some memory
nodesJoin.clear();
nodesJoin.shrink_to_fit();
nodesSplit.clear();
nodesSplit.shrink_to_fit();

auto [arcNo, nodeids, nodefns, nodeTypes, arcs] = computeArcMap();

// write meta data
std::cout << "Writing meta data" << std::endl;
{
Expand Down
4 changes: 4 additions & 0 deletions ContourTree/ContourTree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string>
#include <vector>

#include "constants.h"
namespace contourtree {

class MergeTree;
Expand All @@ -22,6 +23,9 @@ class ContourTree

void setup(const MergeTree * tree);
void computeCT();
std::tuple<uint32_t, std::vector<int64_t>, std::vector<scalar_t>, std::vector<char>,
std::vector<int64_t>>
computeArcMap();
void output(std::string fileName);

private:
Expand Down
51 changes: 32 additions & 19 deletions ContourTree/MergeTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,21 @@ void MergeTree::computeSplitTree() {
newRoot = in;
}

void MergeTree::output(std::string fileName, TreeType tree)
{
if(tree == TypeContourTree) {
ctree.output(fileName);
return;
const std::vector<uint32_t>& MergeTree::getArcMap(TreeType type) const {

if (type == TypeContourTree) {
return ctree.arcMap;
}
// assume size of contour tree fits within 4 bytes
std::vector<uint32_t> arcMap;
if(newVertex) {
arcMap.resize(noVertices + 1,-1);
return arcMap;
}

std::tuple<uint32_t, uint32_t, std::vector<int64_t>, std::vector<scalar_t>, std::vector<char>,
std::vector<int64_t>>
MergeTree::computeArcMap(TreeType tree) {
if (newVertex) {
arcMap.resize(noVertices + 1, -1);
} else {
arcMap .resize(noVertices,-1);
arcMap.resize(noVertices, -1);
}
uint32_t noArcs = 0;
uint32_t noNodes = 0;
Expand All @@ -149,15 +152,6 @@ void MergeTree::output(std::string fileName, TreeType tree)
}
noArcs = noNodes - 1;

// write meta data
std::cout << "Writing meta data" << std::endl;
{
std::ofstream pr(fileName + ".rg.dat");
pr << noNodes << "\n";
pr << noArcs << "\n";
pr.close();
}

std::cout << ("Creating required memory!") << std::endl;
std::vector<int64_t> nodeids(noNodes);
std::vector<scalar_t> nodefns(noNodes);
Expand Down Expand Up @@ -262,6 +256,25 @@ void MergeTree::output(std::string fileName, TreeType tree)
assert(arcNo == noArcs);
}

return {noArcs, noNodes, nodeids, nodefns, nodeTypes, arcs};
}

void MergeTree::output(std::string fileName, TreeType tree) {
if (tree == TypeContourTree) {
ctree.output(fileName);
return;
}

auto [noArcs, noNodes, nodeids, nodefns, nodeTypes, arcs] = computeArcMap(tree);

// write meta data
std::cout << "Writing meta data" << std::endl;
{
std::ofstream pr(fileName + ".rg.dat");
pr << noNodes << "\n";
pr << noArcs << "\n";
pr.close();
}
std::cout << "writing tree output" << std::endl;
std::string rgFile = fileName + ".rg.bin";
std::ofstream of(rgFile,std::ios::binary);
Expand Down
4 changes: 4 additions & 0 deletions ContourTree/MergeTree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class MergeTree
void computeTree(ScalarFunction* data, TreeType type);
void computeJoinTree();
void computeSplitTree();
std::tuple<uint32_t, uint32_t, std::vector<int64_t>, std::vector<scalar_t>, std::vector<char>,
std::vector<int64_t>> computeArcMap(TreeType tree);
const std::vector<uint32_t>& getArcMap(TreeType type) const;
void output(std::string fileName, TreeType tree);

protected:
Expand All @@ -53,6 +56,7 @@ class MergeTree

std::set<int64_t> set;
ContourTree ctree;
std::vector<uint32_t> arcMap;

private:
std::vector<int64_t> star;
Expand Down