Skip to content

Commit

Permalink
Add .clang-format; formatted files
Browse files Browse the repository at this point in the history
  • Loading branch information
kzampog committed Jun 25, 2022
1 parent d0ba7a9 commit 31a43c3
Show file tree
Hide file tree
Showing 86 changed files with 18,103 additions and 16,479 deletions.
12 changes: 12 additions & 0 deletions .clang-format
@@ -0,0 +1,12 @@
---
Language: Cpp
BasedOnStyle: Google
AccessModifierOffset: -2
AlignEscapedNewlines: Left
AlwaysBreakBeforeMultilineStrings: false
ColumnLimit: 100
DerivePointerAlignment: false
IndentCaseLabels: false
PointerAlignment: Left
SortIncludes: false
...
111 changes: 57 additions & 54 deletions examples/connected_component_extraction.cpp
Expand Up @@ -3,75 +3,78 @@
#include <cilantro/utilities/timer.hpp>
#include <cilantro/visualization.hpp>

int main(int argc, char ** argv) {
if (argc < 2) {
std::cout << "Please provide path to PLY file." << std::endl;
return 0;
}
int main(int argc, char** argv) {
if (argc < 2) {
std::cout << "Please provide path to PLY file." << std::endl;
return 0;
}

cilantro::PointCloud3f cloud(argv[1]);
cloud.gridDownsample(0.005f).removeInvalidData();
cilantro::PointCloud3f cloud(argv[1]);
cloud.gridDownsample(0.005f).removeInvalidData();

if (!cloud.hasNormals()) {
std::cout << "Input cloud does not have normals!" << std::endl;
return 0;
}
if (!cloud.hasNormals()) {
std::cout << "Input cloud does not have normals!" << std::endl;
return 0;
}

// Perform segmentation
cilantro::Timer timer;
timer.start();
// Perform segmentation
cilantro::Timer timer;
timer.start();

cilantro::RadiusNeighborhoodSpecification<float> nh(0.02f*0.02f);
cilantro::NormalsProximityEvaluator<float,3> ev(cloud.normals, (float)(2.0*M_PI/180.0));
cilantro::RadiusNeighborhoodSpecification<float> nh(0.02f * 0.02f);
cilantro::NormalsProximityEvaluator<float, 3> ev(cloud.normals, (float)(2.0 * M_PI / 180.0));

cilantro::ConnectedComponentExtraction3f<> cce(cloud.points);
cce.segment(nh, ev, 100, cloud.size());
cilantro::ConnectedComponentExtraction3f<> cce(cloud.points);
cce.segment(nh, ev, 100, cloud.size());

timer.stop();
timer.stop();

std::cout << "Segmentation time: " << timer.getElapsedTime() << "ms" << std::endl;
std::cout << cce.getNumberOfClusters() << " components found" << std::endl;
std::cout << "Segmentation time: " << timer.getElapsedTime() << "ms" << std::endl;
std::cout << cce.getNumberOfClusters() << " components found" << std::endl;

// Build a color map
size_t num_labels = cce.getNumberOfClusters();
const auto& labels = cce.getPointToClusterIndexMap();
// Build a color map
size_t num_labels = cce.getNumberOfClusters();
const auto& labels = cce.getPointToClusterIndexMap();

cilantro::VectorSet3f color_map(3, num_labels+1);
for (size_t i = 0; i < num_labels; i++) {
color_map.col(i) = Eigen::Vector3f::Random().cwiseAbs();
}
// No label
color_map.col(num_labels).setZero();
cilantro::VectorSet3f color_map(3, num_labels + 1);
for (size_t i = 0; i < num_labels; i++) {
color_map.col(i) = Eigen::Vector3f::Random().cwiseAbs();
}
// No label
color_map.col(num_labels).setZero();

cilantro::VectorSet3f colors(3, labels.size());
for (size_t i = 0; i < colors.cols(); i++) {
colors.col(i) = color_map.col(labels[i]);
}
cilantro::VectorSet3f colors(3, labels.size());
for (size_t i = 0; i < colors.cols(); i++) {
colors.col(i) = color_map.col(labels[i]);
}

// Create a new colored cloud
cilantro::PointCloud3f cloud_seg(cloud.points, cloud.normals, colors);
// Create a new colored cloud
cilantro::PointCloud3f cloud_seg(cloud.points, cloud.normals, colors);

// Visualize result
const std::string window_name = "ConnectedComponentSegmentation demo";
pangolin::CreateWindowAndBind(window_name, 1280, 480);
pangolin::Display("multi").SetBounds(0.0, 1.0, 0.0, 1.0).SetLayout(pangolin::LayoutEqual)
.AddDisplay(pangolin::Display("disp1")).AddDisplay(pangolin::Display("disp2"));
// Visualize result
const std::string window_name = "ConnectedComponentSegmentation demo";
pangolin::CreateWindowAndBind(window_name, 1280, 480);
pangolin::Display("multi")
.SetBounds(0.0, 1.0, 0.0, 1.0)
.SetLayout(pangolin::LayoutEqual)
.AddDisplay(pangolin::Display("disp1"))
.AddDisplay(pangolin::Display("disp2"));

cilantro::Visualizer viz1(window_name, "disp1");
viz1.addObject<cilantro::PointCloudRenderable>("cloud", cloud);
cilantro::Visualizer viz1(window_name, "disp1");
viz1.addObject<cilantro::PointCloudRenderable>("cloud", cloud);

cilantro::Visualizer viz2(window_name, "disp2");
viz2.addObject<cilantro::PointCloudRenderable>("cloud_seg", cloud_seg);
cilantro::Visualizer viz2(window_name, "disp2");
viz2.addObject<cilantro::PointCloudRenderable>("cloud_seg", cloud_seg);

// Keep viewpoints in sync
viz2.setRenderState(viz1.getRenderState());
// Keep viewpoints in sync
viz2.setRenderState(viz1.getRenderState());

while (!viz1.wasStopped() && !viz2.wasStopped()) {
viz1.clearRenderArea();
viz1.render();
viz2.render();
pangolin::FinishFrame();
}
while (!viz1.wasStopped() && !viz2.wasStopped()) {
viz1.clearRenderArea();
viz1.render();
viz2.render();
pangolin::FinishFrame();
}

return 0;
return 0;
}
179 changes: 94 additions & 85 deletions examples/convex_hull.cpp
Expand Up @@ -3,99 +3,108 @@
#include <cilantro/utilities/point_cloud.hpp>

void run_demo() {
std::vector<Eigen::Vector3f> points;
points.emplace_back(0,0,0);
points.emplace_back(1,0,0);
points.emplace_back(0,1,0);
points.emplace_back(0,0,1);
points.emplace_back(0,1,1);
points.emplace_back(1,0,1);
points.emplace_back(1,1,0);
points.emplace_back(1,1,1);
points.emplace_back(0.5,0.5,0.5);

cilantro::ConvexHull3f ch(points, true);

std::cout << "Vertices:" << std::endl;
for (size_t i = 0; i < ch.getVertices().cols(); i++) {
std::cout << ch.getVertices().col(i).transpose() << std::endl;
std::vector<Eigen::Vector3f> points;
points.emplace_back(0, 0, 0);
points.emplace_back(1, 0, 0);
points.emplace_back(0, 1, 0);
points.emplace_back(0, 0, 1);
points.emplace_back(0, 1, 1);
points.emplace_back(1, 0, 1);
points.emplace_back(1, 1, 0);
points.emplace_back(1, 1, 1);
points.emplace_back(0.5, 0.5, 0.5);

cilantro::ConvexHull3f ch(points, true);

std::cout << "Vertices:" << std::endl;
for (size_t i = 0; i < ch.getVertices().cols(); i++) {
std::cout << ch.getVertices().col(i).transpose() << std::endl;
}

std::cout << "Faces:" << std::endl;
for (size_t i = 0; i < ch.getFacetVertexIndices().size(); i++) {
for (size_t j = 0; j < ch.getFacetVertexIndices()[i].size(); j++) {
std::cout << ch.getFacetVertexIndices()[i][j] << " ";
}
std::cout << std::endl;
}

std::cout << "Faces:" << std::endl;
for (size_t i = 0; i < ch.getFacetVertexIndices().size(); i++) {
for (size_t j = 0; j < ch.getFacetVertexIndices()[i].size(); j++) {
std::cout << ch.getFacetVertexIndices()[i][j] << " ";
}
std::cout << std::endl;
std::cout << "Vertex neighbor faces:" << std::endl;
for (size_t i = 0; i < ch.getVertexNeighborFacets().size(); i++) {
for (size_t j = 0; j < ch.getVertexNeighborFacets()[i].size(); j++) {
std::cout << ch.getVertexNeighborFacets()[i][j] << " ";
}
std::cout << std::endl;
}

std::cout << "Vertex neighbor faces:" << std::endl;
for (size_t i = 0; i < ch.getVertexNeighborFacets().size(); i++) {
for (size_t j = 0; j < ch.getVertexNeighborFacets()[i].size(); j++) {
std::cout << ch.getVertexNeighborFacets()[i][j] << " ";
}
std::cout << std::endl;
}

std::cout << "Face neighbor faces:" << std::endl;
for (size_t i = 0; i < ch.getFacetNeighborFacets().size(); i++) {
for (size_t j = 0; j < ch.getFacetNeighborFacets()[i].size(); j++) {
std::cout << ch.getFacetNeighborFacets()[i][j] << " ";
}
std::cout << std::endl;
std::cout << "Face neighbor faces:" << std::endl;
for (size_t i = 0; i < ch.getFacetNeighborFacets().size(); i++) {
for (size_t j = 0; j < ch.getFacetNeighborFacets()[i].size(); j++) {
std::cout << ch.getFacetNeighborFacets()[i][j] << " ";
}
std::cout << std::endl;
}
}

int main(int argc, char ** argv) {
if (argc < 2) {
std::cout << "No input PLY file path provided, running simple demo." << std::endl;
run_demo();
return 0;
}

cilantro::PointCloud3f cloud(argv[1]);

if (cloud.isEmpty()) {
std::cout << "Input cloud is empty!" << std::endl;
return 0;
}

cilantro::ConvexHull3f ch(cloud.points, true, true);
cilantro::PointCloud3f hull_cloud(cloud, ch.getVertexPointIndices());

cilantro::VectorSet3f vertex_colors(3, ch.getVertices().cols());
std::vector<float> vertex_values(ch.getVertices().cols());
for (size_t i = 0; i < ch.getVertices().cols(); i++) {
if (i%3 == 0) vertex_colors.col(i) = Eigen::Vector3f(1,0,0);
if (i%3 == 1) vertex_colors.col(i) = Eigen::Vector3f(0,1,0);
if (i%3 == 2) vertex_colors.col(i) = Eigen::Vector3f(0,0,1);
vertex_values[i] = ch.getVertices().col(i).norm();
}

cilantro::VectorSet3f face_colors(3, ch.getFacetVertexIndices().size());
std::vector<float> face_values(ch.getFacetVertexIndices().size());
for (size_t i = 0; i < ch.getFacetVertexIndices().size(); i++) {
if (i%3 == 0) face_colors.col(i) = Eigen::Vector3f(1,0,0);
if (i%3 == 1) face_colors.col(i) = Eigen::Vector3f(0,1,0);
if (i%3 == 2) face_colors.col(i) = Eigen::Vector3f(0,0,1);
face_values[i] = (ch.getVertices().col(ch.getFacetVertexIndices()[i][0]) +
ch.getVertices().col(ch.getFacetVertexIndices()[i][1]) +
ch.getVertices().col(ch.getFacetVertexIndices()[i][2])).rowwise().mean().norm();
}

const std::string window_name = "3D convex hull";
pangolin::CreateWindowAndBind(window_name, 640, 480);
cilantro::Visualizer viz(window_name, "disp");
viz.addObject<cilantro::PointCloudRenderable>("cloud", cloud, cilantro::RenderingProperties().setOpacity(1.0));
viz.addObject<cilantro::TriangleMeshRenderable>("mesh", ch.getVertices(), ch.getFacetVertexIndices())
->setVertexNormals(hull_cloud.normals).setVertexColors(vertex_colors).setVertexValues(vertex_values)
.setFaceColors(face_colors).setFaceValues(face_values);

cilantro::RenderingProperties rp = viz.getRenderingProperties("mesh");
rp.setUseFaceNormals(true).setUseFaceColors(false).setOpacity(0.8).setColormapType(cilantro::ColormapType::BLUE2RED);
viz.setRenderingProperties("mesh", rp);
int main(int argc, char** argv) {
if (argc < 2) {
std::cout << "No input PLY file path provided, running simple demo." << std::endl;
run_demo();
return 0;
}

viz.spin();
cilantro::PointCloud3f cloud(argv[1]);

if (cloud.isEmpty()) {
std::cout << "Input cloud is empty!" << std::endl;
return 0;
}

cilantro::ConvexHull3f ch(cloud.points, true, true);
cilantro::PointCloud3f hull_cloud(cloud, ch.getVertexPointIndices());

cilantro::VectorSet3f vertex_colors(3, ch.getVertices().cols());
std::vector<float> vertex_values(ch.getVertices().cols());
for (size_t i = 0; i < ch.getVertices().cols(); i++) {
if (i % 3 == 0) vertex_colors.col(i) = Eigen::Vector3f(1, 0, 0);
if (i % 3 == 1) vertex_colors.col(i) = Eigen::Vector3f(0, 1, 0);
if (i % 3 == 2) vertex_colors.col(i) = Eigen::Vector3f(0, 0, 1);
vertex_values[i] = ch.getVertices().col(i).norm();
}

cilantro::VectorSet3f face_colors(3, ch.getFacetVertexIndices().size());
std::vector<float> face_values(ch.getFacetVertexIndices().size());
for (size_t i = 0; i < ch.getFacetVertexIndices().size(); i++) {
if (i % 3 == 0) face_colors.col(i) = Eigen::Vector3f(1, 0, 0);
if (i % 3 == 1) face_colors.col(i) = Eigen::Vector3f(0, 1, 0);
if (i % 3 == 2) face_colors.col(i) = Eigen::Vector3f(0, 0, 1);
face_values[i] = (ch.getVertices().col(ch.getFacetVertexIndices()[i][0]) +
ch.getVertices().col(ch.getFacetVertexIndices()[i][1]) +
ch.getVertices().col(ch.getFacetVertexIndices()[i][2]))
.rowwise()
.mean()
.norm();
}

const std::string window_name = "3D convex hull";
pangolin::CreateWindowAndBind(window_name, 640, 480);
cilantro::Visualizer viz(window_name, "disp");
viz.addObject<cilantro::PointCloudRenderable>("cloud", cloud,
cilantro::RenderingProperties().setOpacity(1.0));
viz.addObject<cilantro::TriangleMeshRenderable>("mesh", ch.getVertices(),
ch.getFacetVertexIndices())
->setVertexNormals(hull_cloud.normals)
.setVertexColors(vertex_colors)
.setVertexValues(vertex_values)
.setFaceColors(face_colors)
.setFaceValues(face_values);

cilantro::RenderingProperties rp = viz.getRenderingProperties("mesh");
rp.setUseFaceNormals(true).setUseFaceColors(false).setOpacity(0.8).setColormapType(
cilantro::ColormapType::BLUE2RED);
viz.setRenderingProperties("mesh", rp);

viz.spin();

return 0;
}

0 comments on commit 31a43c3

Please sign in to comment.