Skip to content

Commit

Permalink
Merge pull request #6 from potree/develop
Browse files Browse the repository at this point in the history
...
  • Loading branch information
m-schuetz authored Oct 29, 2020
2 parents fbdd950 + f1b2f76 commit 30c8ebe
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 14 deletions.
6 changes: 5 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"D:/temp/cpotree/sitn_dip_2.0",



// "-o", "stdout",
"-o", "D:/temp/cpotree/cpotree_2.0.potree",
// "-o", "D:/temp/cpotree/cpotree_2.0.laz",

Expand Down Expand Up @@ -51,7 +53,9 @@

// "--output-attributes", "rgb", "intensity",
"--min-level", "0",
"--max-level", "5",
"--max-level", "2",

// "--get-candidates",

],
"stopAtEntry": false,
Expand Down
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@
"editor.mouseWheelZoom": true,
"editor.renderWhitespace": "all",
"workbench.tree.indent": 30,
"cmake.configureOnOpen": true,
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
}
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

# Build

__Linux:__
```
mkdir build
cd build
cmake ../
make
```

__Windows:__
```
mkdir build
cd build
cmake ../
```
* Then open the generated sln file in Visual Studio.
* Make sure "Release" build is selected.
* Build "extract_profile".


# Usage

Extract points with the elevation profile:

// minimal
./extract_profile <input> -o <output> --coordinates "{x0, y1}, {x1, y}, ..." --width <scalar>

// Extract points in certain LOD level ranges
./extract_profile <input> -o <output> --coordinates "{x0, y1}, {x1, y}, ..." --width <scalar> --min-level <integer> --max-level <integer>

* __input__: A point cloud generated with PotreeConverter 2.
* __output__: Can be files ending with *.las, *.laz, *.potree or it can be "stdout". If stdout is specified, a potree format file will be printed directly to the console.
* __min-level__, __max-level__: Level range including the min and max levels. Can be omitted to process all levels.


With ```--get-candidates```, you'll get the number of candidate points, i.e., the number of points inside all nodes intersecting the profile. The actual number of points might be orders of magnitudes lower, especially if ```--width``` is small.

./extract_profile <input> --coordinates "{x0, y1}, {x1, y}, ..." --width <scalar> --min-level <integer> --max-level <integer> --get-candidates

A practical example:

./extract_profile ~/dev/tmp/retz -o ~/dev/tmp/retz.laz --coordinates "{-37.601, -100.733, 4.940},{-22.478, 75.982, 8.287},{66.444, 54.042, 5.388},{71.294, -67.140, -2.481},{165.519, -26.288, 0.253}" --width 2 --min-level 0 --max-level 3
28 changes: 21 additions & 7 deletions include/PotreeWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,22 @@ struct PotreeWriter : public Writer {

void close() {

ofstream stream;
stream.open(path, ios::binary);
ostream* stream = nullptr;

if (path == "stdout") {
stream = &cout;
} else {
ofstream* ofs = new ofstream();
ofs->open(path, ios::binary);

stream = ofs;
}

string header = createHeader();

int headerSize = header.size();
stream.write(reinterpret_cast<const char*>(&headerSize), 4);
stream.write(header.c_str(), headerSize);
stream->write(reinterpret_cast<const char*>(&headerSize), 4);
stream->write(header.c_str(), headerSize);

outputAttributes.posOffset = aabb.min;

Expand Down Expand Up @@ -168,16 +176,22 @@ struct PotreeWriter : public Writer {
if (buffer->size > points->numPoints* attribute.size) {
int debug = 10;
}
stream.write(buffer->data_char, buffer->size);
stream->write(buffer->data_char, buffer->size);
} else {
Buffer buffer(attribute.size * points->numPoints);
stream.write(buffer.data_char, buffer.size);
stream->write(buffer.data_char, buffer.size);
}

}
}

stream.close();
if (path == "stdout") {
// dont do anything
} else {
ofstream* ofs = (ofstream*)stream;
ofs->close();
}

}


Expand Down
6 changes: 5 additions & 1 deletion include/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ bool intersects(dvec3 point, Area& area) {
return false;
}

int64_t getNumCandidates(string path, Area area) {
int64_t getNumCandidates(string path, Area area, int minLevel, int maxLevel) {
string metadataPath = path + "/metadata.json";
string octreePath = path + "/octree.bin";

Expand All @@ -385,6 +385,10 @@ int64_t getNumCandidates(string path, Area area) {
vector<Node*> clippedNodes;
for (auto node : hierarchy.nodes) {

if (node->level() < minLevel || node->level() > maxLevel) {
continue;
}

if (intersects(node, area)) {
numCandidates += node->numPoints;
}
Expand Down
2 changes: 1 addition & 1 deletion src/executable_extract_area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ int main(int argc, char** argv) {
if (args.has("get-candidates")) {
int64_t numCandidates = 0;
for (string path : sources) {
numCandidates += getNumCandidates(path, area);
numCandidates += getNumCandidates(path, area, minLevel, maxLevel);
};

cout << formatNumber(numCandidates) << endl;
Expand Down
7 changes: 3 additions & 4 deletions src/executable_extract_profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ int main(int argc, char** argv) {

int64_t numCandidates = 0;
for (string path : sources) {
numCandidates += getNumCandidates(path, area);
numCandidates += getNumCandidates(path, area, minLevel, maxLevel);
};

cout << formatNumber(numCandidates) << endl;
Expand All @@ -266,8 +266,7 @@ int main(int argc, char** argv) {
} else if (iEndsWith(targetpath, "potree")) {
writer = make_shared<PotreeWriter>(targetpath, scale, offset, outputAttributes);
} else if (targetpath == "stdout") {
cout << "TODO: " << __FILE__ << ":" << __LINE__ << endl;
//writer = make_shared<PotreeWriter>(targetpath, scale, offset, outputAttributes);
writer = make_shared<PotreeWriter>("stdout", scale, offset, outputAttributes);
} else {
cout << "ERROR: unkown output format, extension not known: " << targetpath << endl;
}
Expand Down Expand Up @@ -384,7 +383,7 @@ int main(int argc, char** argv) {
}


printElapsedTime("duration", tStart);
//printElapsedTime("duration", tStart);


return 0;
Expand Down

0 comments on commit 30c8ebe

Please sign in to comment.