Skip to content

Commit

Permalink
Merge 7d9ddf5 into 2331b35
Browse files Browse the repository at this point in the history
  • Loading branch information
jianhuang01 committed Oct 21, 2019
2 parents 2331b35 + 7d9ddf5 commit 6e6c84d
Show file tree
Hide file tree
Showing 11 changed files with 620 additions and 39 deletions.
4 changes: 3 additions & 1 deletion cpp/PotreeConverter/PotreeConverter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ add_executable(PotreeConverter ${files} ${lib_rapidjson_files} ${lib_argument_fi

target_link_libraries(PotreeConverter ${LASZIP_LIBRARY})

if(UNIX)
if(APPLE AND XCODE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++14 -pthread")
elseif(UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++14 -pthread -lstdc++ -lm")
target_link_libraries(PotreeConverter -lstdc++fs)
endif()
Expand Down
45 changes: 45 additions & 0 deletions cpp/PotreeConverter/PotreeConverter/include/OctreeNode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#ifndef OCTREE_NODE_H
#define OCTREE_NODE_H

#include <memory>
#include <vector>
#include <string>

namespace Tile3D{

using std::vector;
using std::unique_ptr;
using std::string;

class OctreeNode{
public:
OctreeNode(int level, string id);
OctreeNode(int level, string id, string filepath_);

int level() const {
return level_;
}

const string& id() const {
return id_;
}

const string& filepath() const {
return filepath_;
}

const vector<unique_ptr<OctreeNode>>& children() const {
return children_;
}

bool add(unique_ptr<OctreeNode>& node);

private:
int level_;
string id_;
string filepath_;
vector<unique_ptr<OctreeNode>> children_;
};
}

#endif
3 changes: 2 additions & 1 deletion cpp/PotreeConverter/PotreeConverter/include/PTXPointReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define PTXPOINTREADER_H

#include <map>
#include <vector>
#include "PointReader.h"

using std::string;
Expand Down Expand Up @@ -84,4 +85,4 @@ class PTXPointReader : public PointReader {

}

#endif
#endif
51 changes: 51 additions & 0 deletions cpp/PotreeConverter/PotreeConverter/include/Tile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#ifndef TILE_H
#define TILE_H


#include <memory>
#include <vector>
#include <string>
#include <OctreeNode.h>
#include <LASPointReader.h>
#include <Point.h>

#include <rapidjson/document.h>

namespace Tile3D{

using std::vector;
using std::unique_ptr;
using std::string;

using Potree::LIBLASReader;
using Potree::Point;

using rapidjson::Document;
using rapidjson::Value;

class Tile{
public:
Tile(const OctreeNode& node);
void writeData(const string& path);
Value toJson(Document& doc);
bool isValid() {
return points_.size() > 3;
}

private:
void createBbox();
void readData();
void readPoints();

private:
int level_;
string id_;
string filepath_;
unique_ptr<LIBLASReader> reader_;
vector<double> bbox_;
vector<Point> points_;
double geometricError_;
};
}

#endif
44 changes: 44 additions & 0 deletions cpp/PotreeConverter/PotreeConverter/include/Tile3DConverter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef TILE_3D_CONVERTER_H
#define TILE_3D_CONVERTER_H

#include <string>
#include <vector>
#include <memory>
#include <rapidjson/document.h>
#include <experimental/filesystem>
#include <OctreeNode.h>

namespace Tile3D{
namespace fs = std::experimental::filesystem;

using std::string;
using std::vector;
using std::unique_ptr;
using rapidjson::Document;
using rapidjson::Value;
using fs::path;

class Tile3DConverter{

public:
Tile3DConverter(string dataDir, string workDir);
void convert();
void readJsonHeader();
void collectPotreeFiles();
void buildOctree();
void processOctree();

private:
void traverseOctree(const OctreeNode& node, Value& value);
private:
string dataDir_;
string workDir_;
Document cloudJsonDoc_;
Document tilesetJsonDoc_;
vector<path> filePaths_;
unique_ptr<OctreeNode> rootNode_;
};

}

#endif
32 changes: 32 additions & 0 deletions cpp/PotreeConverter/PotreeConverter/include/TileWriter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef TILE_WRITER_H
#define TILE_WRITER_H

#include <vector>
#include <string>
#include <Point.h>

namespace Tile3D{

using std::vector;
using std::string;
using Potree::Point;

class TileWriter{
public:
TileWriter(const string& filepath);
bool write(const vector<Point>& points);

private:
void write(const vector<char>& data);
vector<char> serializePositions(const vector<Point>& points);
vector<char> serializeColors(const vector<Point>& points);
string serializeFeatureTableHeader(int pointSize, int positionBytes);
void verifyData(const vector<Point>& points);

private:
string filepath_;
bool hasColor_;
};
}

#endif
32 changes: 32 additions & 0 deletions cpp/PotreeConverter/PotreeConverter/src/OctreeNode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <OctreeNode.h>
#include <string>

namespace Tile3D{
OctreeNode::OctreeNode(int level, string id)
: level_(level), id_(id){
}

OctreeNode::OctreeNode(int level, string id, string filepath)
: level_(level), id_(id), filepath_(filepath){
}

bool OctreeNode::add(unique_ptr<OctreeNode>& node) {
bool ret = false;
if(node == NULL) {
ret = true;
}
else if(node->level_ == level_ + 1 && node->id_.substr(0, node->id_.size() - 1) == id_){
children_.push_back(std::move(node));
ret = true;
}
else {
for(auto& child : children_) {
if(child->add(node)){
ret = true;
break;
}
}
}
return ret;
}
}
92 changes: 92 additions & 0 deletions cpp/PotreeConverter/PotreeConverter/src/Tile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#include <iostream>
#include <Tile.h>
#include <TileWriter.h>
#include <AABB.h>
#include <rapidjson/prettywriter.h>


namespace Tile3D{
using rapidjson::Document;
using rapidjson::Value;
using rapidjson::kObjectType;
using rapidjson::kArrayType;

using Potree::AABB;

Tile::Tile(const OctreeNode& node)
: level_(node.level()), id_(node.id()), filepath_(node.filepath()), reader_(new LIBLASReader(filepath_)), geometricError_(0.0){
readData();
}

void Tile::createBbox() {
auto header = reader_->header;
vector<double> zeros({0, 0, 0});
bbox_.clear();

AABB aabb;

for(auto& point : points_) {
aabb.update(point.position);
}
double maxHalfSize = max(max(aabb.size.x, aabb.size.y), aabb.size.z) / 2.0;
bbox_.push_back((aabb.min.x + aabb.max.x) / 2.0);
bbox_.push_back((aabb.min.y + aabb.max.y) / 2.0);
bbox_.push_back((aabb.min.z + aabb.max.z) / 2.0);
bbox_.push_back(maxHalfSize);
bbox_.insert(bbox_.end(), zeros.begin(), zeros.end());
bbox_.push_back(maxHalfSize);
bbox_.insert(bbox_.end(), zeros.begin(), zeros.end());
bbox_.push_back(maxHalfSize);

geometricError_ = (header->max_x - header->min_x) / 115.0;
}

void Tile::readPoints() {
while(reader_->readPoint()) {
points_.push_back(reader_->GetPoint());
}
}

void Tile::readData() {
if(reader_ == nullptr || reader_->header == nullptr) {
return;
}
readPoints();
createBbox();
}

void Tile::writeData(const string& path) {
string filePath = path + "/r" + id_ + ".pnts";
TileWriter writer(filePath);
writer.write(points_);
}

Value Tile::toJson(Document& doc){
Value value(kObjectType);

Value bbox(kArrayType);
Value volume(kObjectType);
for(auto& v : bbox_) {
bbox.PushBack(v, doc.GetAllocator());
}
volume.AddMember("box", bbox, doc.GetAllocator());
value.AddMember("boundingVolume", volume, doc.GetAllocator());

Value children(kArrayType);
value.AddMember("children", children, doc.GetAllocator());

string str("r" + id_ + ".pnts");
Value url;
url.SetString(str.c_str(), static_cast<int>(str.size()), doc.GetAllocator());
Value content(kObjectType);
content.AddMember("url", url, doc.GetAllocator());
value.AddMember("content", content, doc.GetAllocator());

value.AddMember("geometricError", geometricError_, doc.GetAllocator());

if(id_.empty()) {
value.AddMember("refine", "ADD", doc.GetAllocator());
}
return value;
}
}
Loading

0 comments on commit 6e6c84d

Please sign in to comment.