Coder Social home page Coder Social logo

edikkesh / open3d Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 119.2 MB

A clone of the Open3D repository with extended functionality for finding connected components by color in a triangle mesh

License: Other

CMake 1.46% C++ 94.55% C 1.55% GLSL 0.34% Batchfile 0.01% Shell 0.93% Python 0.80% JavaScript 0.33% Dockerfile 0.04%

open3d's Introduction

This repository is a clone of the Open3D repository with extended functionality for finding connected components of a triangle mesh with identical colors. The original Open3D repository can be found here: https://github.com/intel-isl/Open3D

Requirements for this enhancement are detailed in the requirement.pdf document.

Building the new Open3D

Please follow the build instructions given at the original Open3D site (above link). 

Testing the new functionality

The code was developed and tested on Windows.
One C++ sample program and one Python script are added to the examples.
A test case is also added to the set of unit tests.
  • The C++ example executable is located at Open3D\build\bin\examples\Debug. The program accepts the name of a mesh file as a parameter as follows:

      solution test_mesh.ply
    

    The program writes a sorted list of sorted lists in a file named results.txt.

  • The python example is located at Open3D\examples\Python\Basic. It can be run as follows:

      python solution.py
    

    The script writes a sorted list of sorted lists in a file named results.txt.

  • The test is called ColoredTriangleMesh.IdenticallyColoredConnectedComponents. The program unitTests is located at Open3D\build\bin\Debug. Run the test as follows:

      unitTests --gtest_filter=ColoredTriangleMesh.IdenticallyColoredConnectedComponents
    

New and modified files

CMakeLists.txt
examples/Cpp/CMakeLists.txt
examples/Cpp/solution.cpp (new)
examples/Python/Basic/solution.py (new)
examples/TestData/results.txt (new)
examples/TestData/test_mesh.ply (new)
src/Open3D/Geometry/TriangleMesh.cpp
src/Open3D/Geometry/TriangleMesh.h
src/Python/open3d_pybind/geometry/trianglemesh.cpp
src/UnitTest/Geometry/ColoredTriangleMesh.cpp (new)

Algorithm design

The algorithm is implemented as a method of the class TriangleMesh. Since the algorithm is fairly straightforward we only present the C++ code and not the psuedo code.

The core idea is to iterate through all the vertices of the mesh and for each vertex find the adjacent vertices and retain the ones that have the same color as the vertex. This is done recursively until a complete set of identically-colored and connected vertices is identified. An identified set is stored in a data member representing a set of sets. The choice for the type of the data member follows the pattern used in the Open3D design. The data member declaration is as follows:

std::vector<std::set<int>> identically_colored_connected_components_list_;

The choice for the signuture of the funtion also follows the pattern used with similar functions in Open3D. As can be seen from the code below, our implementation uses two nested loops to simulate recursion.

TriangleMesh &TriangleMesh::IdenticallyColoredConnectedComponents() {
    if (!HasAdjacencyList()) {
	ComputeAdjacencyList();
    }

    std::vector<bool> visited(vertices_.size(), false);

    for (int vidx = 0; vidx < vertices_.size(); vidx++) {
	if (visited[vidx]) continue;

	std::set<int> identicallyColoredPatch;
	identicallyColoredPatch.insert(vidx);
	visited[vidx] = true;

	Eigen::Vector3d color = vertex_colors_[vidx];
	std::queue<int> queue;

	queue.push(vidx);
	while (!queue.empty()) {
	    int idx = queue.front();
	    queue.pop();

	    std::unordered_set<int> adjacents = adjacency_list_[idx];

	    for (auto nidx : adjacents) {
		if (vertex_colors_[nidx] == color && !visited[nidx]) {
		    identicallyColoredPatch.insert(nidx);
		    visited[nidx] = true;
		    queue.push(nidx);
		}
	    }
	}

	identically_colored_connected_components_list_.push_back(identicallyColoredPatch);
    }

    return *this;
}

Notes

  • Our C++ implementaion generates a sorted list of sorted lists (std::vector< std::set >). However, when the data is accessed in our Python example (solution.py), the individual member lists are no longer sorted. As a remedy, we sort the individual lists inside the Python script before writing them to the output file.

  • In Visual Studio, the option /biobj should be added as a command line option for project Geometry.

  • In Visual Studio, the library pthread.lib should be removed from the link libraries list for project unitTests.

open3d's People

Contributors

syncle avatar takanokage avatar qianyizh avatar yxlao avatar griegler avatar edikkesh avatar csukuangfj avatar germanros1987 avatar kongsgard avatar rohanrathi avatar nicolas-chaulet avatar thended avatar scimad avatar benjaminum avatar sammo2828 avatar cv3d avatar dotchang avatar zjudmd1015 avatar jacklangerman avatar prewettg avatar kuonangzhe avatar iory avatar xardvor avatar puzzlepaint avatar barnjamin avatar forestjylee avatar mwtarnowski avatar pezcode avatar pauljurczak avatar theodoret avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.