-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
620 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
44
cpp/PotreeConverter/PotreeConverter/include/Tile3DConverter.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.