Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "third_party/experiments"]
path = third_party/experiments
url = https://github.com/jpanikulam/experiments.git
1 change: 0 additions & 1 deletion third_party/experiments
Submodule experiments deleted from 9af2e1
12 changes: 12 additions & 0 deletions third_party/experiments/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Set "style": "File" in your local sublime clang-format config
# This will make sublime look in the current repo

BasedOnStyle: Google
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AllowShortFunctionsOnASingleLine: None
BinPackParameters: false
ColumnLimit: 90
ExperimentalAutoDetectBinPacking: true
PenaltyReturnTypeOnItsOwnLine: 10000
6 changes: 6 additions & 0 deletions third_party/experiments/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.png binary
*.stl binary
*.pgm binary
*.ppm binary
*.dae binary
*.jpg binary
96 changes: 96 additions & 0 deletions third_party/experiments/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# IPython Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# dotenv
.env

# virtualenv
venv/
ENV/

# Spyder project settings
.spyderproject

# Rope project settings
.ropeproject

bin/
tmp/

*.sublime-workspace


74 changes: 74 additions & 0 deletions third_party/experiments/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
cmake_minimum_required(VERSION 2.8)

set(BASEPATH "${CMAKE_CURRENT_SOURCE_DIR}")
include_directories("${BASEPATH}/third_party/Sophus")
include_directories("${BASEPATH}/third_party/eigen3")
include_directories("${BASEPATH}")

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

#########################
# GTest
#
enable_testing()
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})

#########################
# OpenCV
#
find_package(OpenCV REQUIRED)

#########################
# OpenGL
#
find_package(OpenGL REQUIRED)
include_directories( ${OPENGL_INCLUDE_DIRS})

#########################
# GLFW
#
find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
include_directories(${GLFW_INCLUDE_DIRS})

#########################
# GLEW
#
find_package(GLEW REQUIRED)

#########################
# ASSIMP
#
find_package(ASSIMP REQUIRED)

SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/run)

macro(add_test test_name test_file test_libs)
add_executable(
${test_name}
${test_file}
)
set_target_properties(
${test_name}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test
)
target_link_libraries(${test_name} ${test_libs} ${GTEST_LIBRARIES} pthread)
endmacro(add_test)

execute_process(
COMMAND pymake -v success -p "${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE ret
)
if(ret EQUAL "1")
message(FATAL_ERROR "Could not run pymake; run sudo pip install generate-cmake")
endif()

set(CMAKE_CXX_COMPILER "g++-7")
set(CMAKE_CXX_FLAGS "--std=c++17 -g -O1 -fno-omit-frame-pointer -Wall -Wno-deprecated-declarations ${CMAKE_CXX_FLAGS}")

add_subdirectory(tmp)
target_compile_definitions(environment PRIVATE ASSET_PATH="${BASEPATH}/data")
# add_definitions(-DEIGEN_MAX_ALIGN_BYTES=0)
# add_definitions(-DEIGEN_MAX_STATIC_ALIGN_BYTES=0)
21 changes: 21 additions & 0 deletions third_party/experiments/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Jake

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
80 changes: 80 additions & 0 deletions third_party/experiments/clang/find_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import os

from clang import cindex
from clang.cindex import CursorKind
import clang


kinds = set()


def visitor(cursor, path, go=False):
children = list(cursor.get_children())
# print ' has {0} children'.format(len(children))

if (cursor.kind not in kinds):
print cursor.kind, ':', cursor.location.file, cursor.spelling

kinds.add(cursor.kind)

if cursor.kind == clang.cindex.CursorKind.INCLUSION_DIRECTIVE:
print 'ffff'
print cursor.spelling

if cursor.kind in [CursorKind.UNEXPOSED_EXPR, CursorKind.UNEXPOSED_DECL, CursorKind.TRANSLATION_UNIT]:
print cursor.kind, ':', cursor.location.file, cursor.spelling

if (cursor.location.file is not None):
if (os.path.realpath(cursor.location.file.name) != path):
return

if (cursor.location.file is not None and cursor.kind == clang.cindex.CursorKind.CXX_METHOD):
path = os.path.realpath(cursor.location.file.name)

print os.path.split(path)[-1], cursor.spelling
for child in children:
visitor(child, path)

for child in children:
visitor(child, path)


if __name__ == '__main__':
cindex.Config.set_library_path('/usr/lib/llvm-3.8/lib')
path = '/home/jacob/repos/experiments/geometry/spatial/bounding_volume_hierarchy.hh'

index = cindex.Index.create()

include_paths = [
"/home/jacob/repos/experiments/geometry/spatial",
"/home/jacob/repos/experiments/",
"/home/jacob/repos/third_party/Sophus",
"/home/jacob/repos/third_party/eigen3",
]

include_args = map(lambda o: "-I" + o, include_paths)

tu = index.parse(path, args=include_args)

for incl in tu.get_includes():
name = os.path.realpath(incl.location.file.name)

if name.startswith('/home/jacob/repos/experiments/') and incl.depth <= 3:
# print incl.location.file.name, ': ', incl.source.name, ': ', incl.depth
location = os.path.split(incl.location.file.name)[-1]
source = os.path.split(incl.source.name)[-1]
include = os.path.split(incl.include.name)[-1]

outstr = "loc: {0: <50} src: {1: <50} incl: {2: <40} depth: {3: <10}".format(
location,
source,
include,
incl.depth,
)
print outstr

print '---'

visitor(tu.cursor, path)

print kinds
97 changes: 97 additions & 0 deletions third_party/experiments/clustering/meanshift_view.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#include "clustering/spatial_hash.hh"

#include "viewer/window_2d.hh"

#include "out.hh"

#include "eigen.hh"
#include <map>

namespace clustering {
using Vec2 = Eigen::Vector2d;
using Vec3 = Eigen::Vector3d;
using Vec4 = Eigen::Vector4d;

struct MeanShiftState {
std::vector<Vec2> initial_points;
std::vector<Vec2> current_points;
};

Vec2 local_mean(const std::vector<Vec2> &points,
const int index,
const double window_size) {
Vec2 mean = Vec2::Zero();
int added = 0;
for (const auto &pt : points) {
const double dist = (pt - points[index]).norm();
if (dist < window_size) {
mean += pt;
++added;
}
}
mean /= static_cast<double>(added);
return mean;
}

void shift_means(Vout<std::vector<Vec2>> points, const double radius) {
constexpr double DAMPING = 0.1;

for (size_t k = 0; k < points->size(); ++k) {
const Vec2 lmean = local_mean(*points, k, radius);
const Vec2 direction = lmean - points[k];
points[k] += DAMPING * direction;
}
}

void run() {
auto viewer = viewer::get_window2d("Meanshift View");

constexpr int NUM_PTS = 500;
std::vector<Vec2> points(NUM_PTS);
for (int k = 0; k < 250; ++k) {
points[k] = (Vec2::Random() * 2.0) + Vec2(-1, -1.5);
}

for (int k = 250; k < NUM_PTS; ++k) {
points[k] = (Vec2::Random() * 2.0) + Vec2(1, 1.5);
}

std::vector<Vec2> deformed_pts(points);

constexpr double MEANSHIFT_RADIUS = 1.0;
for (int k = 0; k < 100; ++k) {
viewer->clear();
viewer->add_points({points, Vec4(0.0, 1.0, 0.0, 0.8)});
shift_means(vout(deformed_pts), MEANSHIFT_RADIUS);
viewer->add_points({deformed_pts, Vec4(1.0, 0.0, 0.0, 0.8)});
viewer->spin_until_step();
}

//
// Compute the cluster identities using an lsh
//

const std::vector<HashInt> identities = spatial_hash(deformed_pts, 100.0);
std::map<HashInt, std::vector<Vec2>> identified_points;
for (size_t k = 0; k < identities.size(); ++k) {
const HashInt id = identities[k];
identified_points[id].push_back(points[k]);
}

//
// Draw the identified points
//

viewer->clear();
for (const auto &pt_group : identified_points) {
const Vec3 color = (Vec3::Random() + Vec3::Ones()) * 0.5;
const Vec4 color_and_alpha = (Vec4() << color, 1.0).finished();
viewer->add_points({pt_group.second, color_and_alpha});
}
viewer->spin_until_step();
}
} // namespace clustering

int main() {
clustering::run();
}
Loading