├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── applications ├── CMakeLists.txt ├── camera_capture │ ├── CMakeLists.txt │ ├── camera_capture.cpp │ ├── includes.cmake │ └── install.cmake ├── camera_viewer │ ├── CMakeLists.txt │ ├── camera_viewer.cpp │ ├── includes.cmake │ └── install.cmake ├── copy_file.cmake ├── copy_folder.cmake ├── face_detection │ ├── CMakeLists.txt │ ├── face_detection.cpp │ ├── includes.cmake │ └── install.cmake ├── face_modeling │ ├── CMakeLists.txt │ ├── face_modeling.cpp │ ├── includes.cmake │ └── install.cmake └── object_modeling │ ├── CMakeLists.txt │ ├── includes.cmake │ ├── install.cmake │ └── object_modeling.cpp ├── cameras ├── CMakeLists.txt ├── include │ └── dip │ │ └── cameras │ │ ├── camera.h │ │ ├── dumpfile.h │ │ ├── primesense.h │ │ └── softkinetic.h ├── includes.cmake └── src │ ├── dumpfile.cpp │ ├── primesense.cpp │ └── softkinetic.cpp ├── cmake └── modules │ ├── FindDIP.cmake │ ├── FindDepthSense.cmake │ ├── FindEigen.cmake │ ├── FindGLEW.cmake │ ├── FindGLFW.cmake │ └── FindOpenNI2.cmake ├── common ├── CMakeLists.txt ├── include │ └── dip │ │ └── common │ │ ├── error.h │ │ ├── macros.h │ │ ├── memory.h │ │ ├── reduction.h │ │ └── types.h ├── includes.cmake └── src │ ├── error.cu │ ├── memory.cu │ └── reduction.cu ├── data └── haarcascade_frontalface_default.xml ├── filters ├── CMakeLists.txt ├── include │ └── dip │ │ └── filters │ │ ├── bilateral.h │ │ ├── threshold.h │ │ └── variance.h ├── includes.cmake └── src │ ├── bilateral.cpp │ ├── bilateral.cu │ ├── threshold.cpp │ ├── threshold.cu │ ├── variance.cpp │ └── variance.cu ├── io ├── CMakeLists.txt ├── include │ └── dip │ │ └── io │ │ ├── hdf5dumper.h │ │ ├── hdf5wrapper.h │ │ └── objfile.h ├── includes.cmake └── src │ ├── hdf5dumper.cpp │ ├── hdf5wrapper.cpp │ └── objfile.cpp ├── point_cloud ├── CMakeLists.txt ├── include │ └── dip │ │ └── point_cloud │ │ ├── backprojection.h │ │ └── centroid.h ├── includes.cmake └── src │ ├── backprojection.cpp │ ├── backprojection.cu │ ├── centroid.cpp │ └── centroid.cu ├── projects ├── CMakeLists.txt ├── include │ └── dip │ │ └── projects │ │ ├── facemodeling.h │ │ └── objectmodeling.h ├── includes.cmake └── src │ ├── facemodeling.cpp │ └── objectmodeling.cpp ├── registration ├── CMakeLists.txt ├── include │ └── dip │ │ └── registration │ │ └── icp.h ├── includes.cmake └── src │ ├── icp.cpp │ └── icp.cu ├── sampling ├── CMakeLists.txt ├── include │ └── dip │ │ └── sampling │ │ └── downsample.h ├── includes.cmake └── src │ ├── downsample.cpp │ └── downsample.cu ├── segmentation ├── CMakeLists.txt ├── include │ └── dip │ │ └── segmentation │ │ ├── connectedcomponents.h │ │ ├── facemasker.h │ │ └── headsegmenter.h ├── includes.cmake └── src │ ├── connectedcomponents.cpp │ ├── facemasker.cpp │ └── headsegmenter.cpp ├── surface ├── CMakeLists.txt ├── include │ └── dip │ │ └── surface │ │ ├── marchingcubes.h │ │ ├── mesh.h │ │ ├── raycasting.h │ │ ├── volumetric.h │ │ └── voxel.h ├── includes.cmake └── src │ ├── marchingcubes.cpp │ ├── raycasting.cpp │ ├── raycasting.cu │ ├── volumetric.cpp │ └── volumetric.cu └── visualization ├── CMakeLists.txt ├── include └── dip │ └── visualization │ └── colorize.h ├── includes.cmake └── src └── colorize.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | build/ -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(dip) 3 | 4 | set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/" ${CMAKE_MODULE_PATH}) 5 | 6 | set(BIN_INSTALL_DIR "bin") 7 | set(LIB_INSTALL_DIR "lib") 8 | set(INCLUDE_INSTALL_DIR "include/${PROJECT_NAME}") 9 | 10 | #add_definitions(-DSOFTKINETIC) 11 | 12 | if(WIN32) 13 | set(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE OFF) 14 | endif() 15 | 16 | if(UNIX) 17 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") 18 | set(BUILD_SHARED_LIBS true) 19 | endif() 20 | 21 | # CUDA 22 | find_package(CUDA REQUIRED) 23 | set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -arch=sm_20") 24 | if(UNIX) 25 | set(CUDA_PROPAGATE_HOST_FLAGS false) 26 | endif() 27 | # DepthSense 28 | find_package(DepthSense REQUIRED) 29 | # Eigen 30 | find_package(Eigen REQUIRED) 31 | # GLEW 32 | find_package(GLEW REQUIRED) 33 | # GLFW 34 | find_package(GLFW REQUIRED) 35 | # HDF5 36 | find_package(HDF5 REQUIRED NO_MODULE) 37 | # OpenCV 38 | find_package(OpenCV REQUIRED) 39 | # OpenGL 40 | find_package(OpenGL REQUIRED) 41 | # OpenNI 42 | find_package(OpenNI2 REQUIRED) 43 | # OpenMP 44 | find_package(OpenMP) 45 | if (OPENMP_FOUND) 46 | set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") 47 | set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") 48 | endif() 49 | # X11 50 | if(UNIX) 51 | find_package(X11 REQUIRED) 52 | set(X11_LIBS ${X11_Xrandr_LIB} ${X11_Xxf86vm_LIB} ${X11_Xi_LIB} ${X11_Xinerama_LIB} ${X11_Xcursor_LIB}) 53 | endif() 54 | 55 | set(MODULE_NAMES 56 | cameras 57 | common 58 | filters 59 | io 60 | point_cloud 61 | projects 62 | registration 63 | sampling 64 | segmentation 65 | surface 66 | visualization 67 | ) 68 | 69 | foreach(MODULE_NAME ${MODULE_NAMES}) 70 | add_subdirectory(${MODULE_NAME}) 71 | endforeach(MODULE_NAME) 72 | 73 | add_subdirectory(applications) 74 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2015, Gregory P. Meyer 2 | University of Illinois Board of Trustees 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of the copyright holder(s) nor the names of its 13 | contributors may be used to endorse or promote products derived from 14 | this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Depth Image Processing 2 | ====================== 3 | 4 | Depth Image Processing (DIP) is a library of research code created by 5 | [Greg Meyer](http://gregmeyer.info/) at the University of Illinois at 6 | Urbana-Champaign. The following projects are currently implemented in DIP: 7 | 8 | * [Real-time 3D face modeling with a commodity depth camera] 9 | (http://gregmeyer.info/papers/icme2013.pdf) 10 | * [Improving Face Detection with Depth] 11 | (http://gregmeyer.info/papers/icassp2016.pdf) 12 | 13 | DIP can be compiled and installed using CMake. 14 | 15 | ### Requirements ### 16 | 17 | * CUDA 5.0 18 | * Eigen 3.0.0 19 | * HDF5 20 | * OpenCV 21 | * OpenNI2 22 | * OpenGL/GLUT 23 | -------------------------------------------------------------------------------- /applications/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(APPLICATION_NAMES 2 | camera_capture 3 | camera_viewer 4 | face_detection 5 | face_modeling 6 | object_modeling 7 | ) 8 | 9 | foreach(APPLICATION_NAME ${APPLICATION_NAMES}) 10 | add_subdirectory(${APPLICATION_NAME}) 11 | endforeach(APPLICATION_NAME) 12 | -------------------------------------------------------------------------------- /applications/camera_capture/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | SET(APPICATION_NAME camera_capture) 2 | 3 | SET(MODULE_DEPENDENCIES 4 | cameras 5 | common 6 | io 7 | visualization 8 | ) 9 | 10 | include(includes.cmake) 11 | 12 | foreach(DEPENDENT ${MODULE_DEPENDENCIES}) 13 | include(${PROJECT_SOURCE_DIR}/${DEPENDENT}/includes.cmake) 14 | 15 | set(INCLUDE_DIRS 16 | ${INCLUDE_DIRS} 17 | ${PROJECT_SOURCE_DIR}/${DEPENDENT}/include 18 | ) 19 | endforeach(DEPENDENT) 20 | 21 | set(INCLUDE_DIRS 22 | ${INCLUDE_DIRS} 23 | ) 24 | 25 | include_directories(${INCLUDE_DIRS}) 26 | 27 | set(INCS 28 | ) 29 | 30 | set(SRCS 31 | ${APPICATION_NAME}.cpp 32 | ) 33 | 34 | set(LIBS 35 | ${GLEW_LIBRARIES} 36 | ${GLFW_LIBRARIES} 37 | ${OPENGL_LIBRARIES} 38 | ${X11_LIBS} 39 | ${MODULE_DEPENDENCIES} 40 | ) 41 | 42 | add_executable(${APPICATION_NAME} ${SRCS} ${INCS}) 43 | target_link_libraries(${APPICATION_NAME} ${LIBS}) 44 | 45 | install(TARGETS ${APPICATION_NAME} DESTINATION ${BIN_INSTALL_DIR}) 46 | 47 | if(WIN32) 48 | include(install.cmake) 49 | endif() 50 | -------------------------------------------------------------------------------- /applications/camera_capture/includes.cmake: -------------------------------------------------------------------------------- 1 | set(INCLUDE_DIRS 2 | ${INCLUDE_DIRS} 3 | ${GLEW_INCLUDE_DIRS} 4 | ${GLFW_INCLUDE_DIRS} 5 | ${OPENGL_INCLUDE_DIR} 6 | ) 7 | -------------------------------------------------------------------------------- /applications/camera_capture/install.cmake: -------------------------------------------------------------------------------- 1 | include(../copy_file.cmake) 2 | include(../copy_folder.cmake) 3 | 4 | # Copy and Install HDF5 DLLs 5 | copy_file("hdf5.dll" "${HDF5_INCLUDE_DIR}/../bin") 6 | copy_file("hdf5_cpp.dll" "${HDF5_INCLUDE_DIR}/../bin") 7 | copy_file("szip.dll" "${HDF5_INCLUDE_DIR}/../bin") 8 | copy_file("zlib.dll" "${HDF5_INCLUDE_DIR}/../bin") 9 | 10 | # Copy and Install GLEW DLLs 11 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 12 | copy_file("glew32.dll" "${GLEW_INCLUDE_DIRS}/../bin/Release/x64") 13 | else() 14 | copy_file("glew32.dll" "${GLEW_INCLUDE_DIRS}/../bin/Release/Win32") 15 | endif() 16 | 17 | # Copy and Install OpenNI2 DLLs 18 | copy_file("OpenNI2.dll" "${OPENNI2_INCLUDE_DIRS}/../Redist") 19 | copy_folder("OpenNI2" "${OPENNI2_INCLUDE_DIRS}/../Redist") 20 | -------------------------------------------------------------------------------- /applications/camera_viewer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | SET(APPICATION_NAME camera_viewer) 2 | 3 | SET(MODULE_DEPENDENCIES 4 | cameras 5 | common 6 | io 7 | visualization 8 | ) 9 | 10 | include(includes.cmake) 11 | 12 | foreach(DEPENDENT ${MODULE_DEPENDENCIES}) 13 | include(${PROJECT_SOURCE_DIR}/${DEPENDENT}/includes.cmake) 14 | 15 | set(INCLUDE_DIRS 16 | ${INCLUDE_DIRS} 17 | ${PROJECT_SOURCE_DIR}/${DEPENDENT}/include 18 | ) 19 | endforeach(DEPENDENT) 20 | 21 | set(INCLUDE_DIRS 22 | ${INCLUDE_DIRS} 23 | ) 24 | 25 | include_directories(${INCLUDE_DIRS}) 26 | 27 | set(INCS 28 | ) 29 | 30 | set(SRCS 31 | ${APPICATION_NAME}.cpp 32 | ) 33 | 34 | set(LIBS 35 | ${GLEW_LIBRARIES} 36 | ${GLFW_LIBRARIES} 37 | ${OPENGL_LIBRARIES} 38 | ${X11_LIBS} 39 | ${MODULE_DEPENDENCIES} 40 | ) 41 | 42 | add_executable(${APPICATION_NAME} ${SRCS} ${INCS}) 43 | target_link_libraries(${APPICATION_NAME} ${LIBS}) 44 | 45 | install(TARGETS ${APPICATION_NAME} DESTINATION ${BIN_INSTALL_DIR}) 46 | 47 | if(WIN32) 48 | include(install.cmake) 49 | endif() 50 | -------------------------------------------------------------------------------- /applications/camera_viewer/camera_viewer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | // Standard Libraries 30 | #include 31 | #include 32 | 33 | // OpenGL 34 | #include 35 | #include 36 | 37 | // DIP 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | using namespace dip; 45 | 46 | const int kWindowWidth = 640; 47 | const int kWindowHeight = 480; 48 | 49 | const int kMinDepth = 64; 50 | const int kMaxDepth = 8192; 51 | 52 | static void key_callback(GLFWwindow* window, int key, int scancode, 53 | int action, int mods) { 54 | if ((key == GLFW_KEY_ESCAPE) && (action == GLFW_PRESS)) 55 | glfwSetWindowShouldClose(window, GL_TRUE); 56 | } 57 | 58 | int main(int argc, char **argv) { 59 | if (argc > 2) { 60 | printf("Usage: %s [Dump File]\n", argv[0]); 61 | return -1; 62 | } 63 | 64 | // Initialize Camera 65 | Camera *camera = NULL; 66 | if (argc < 2) { 67 | #ifndef SOFTKINETIC 68 | camera = new PrimeSense(); 69 | #else 70 | camera = new SoftKinetic(); 71 | #endif 72 | } else { 73 | camera = new DumpFile(argv[1]); 74 | } 75 | 76 | if (!camera->enabled()) { 77 | printf("Unable to Open Camera\n"); 78 | return -1; 79 | } 80 | 81 | // Initialize Buffers 82 | Depth *depth = new Depth[camera->width(DEPTH_SENSOR) * 83 | camera->height(DEPTH_SENSOR)]; 84 | Color *colorized_depth = new Color[camera->width(DEPTH_SENSOR) * 85 | camera->height(DEPTH_SENSOR)]; 86 | Color *color = new Color[camera->width(COLOR_SENSOR) * 87 | camera->height(COLOR_SENSOR)]; 88 | 89 | // Initialize GLFW 90 | if (!glfwInit()) { 91 | printf("Unable to Initialize GLFW.\n"); 92 | return -1; 93 | } 94 | 95 | GLFWwindow *window = glfwCreateWindow(kWindowWidth * 2, kWindowHeight, 96 | "Camera Viewer", NULL, NULL); 97 | 98 | if (!window) { 99 | printf("Unable to create window.\n"); 100 | glfwTerminate(); 101 | return -1; 102 | } 103 | 104 | glfwMakeContextCurrent(window); 105 | glfwSetKeyCallback(window, key_callback); 106 | 107 | // Initialize Texture 108 | GLuint textures[2]; 109 | glEnable(GL_TEXTURE_2D); 110 | glGenTextures(2, textures); 111 | 112 | glBindTexture(GL_TEXTURE_2D, textures[0]); 113 | 114 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 115 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 116 | 117 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 118 | camera->width(COLOR_SENSOR), camera->height(COLOR_SENSOR), 119 | 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); 120 | 121 | glBindTexture(GL_TEXTURE_2D, textures[1]); 122 | 123 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 124 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 125 | 126 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 127 | camera->width(DEPTH_SENSOR), camera->height(DEPTH_SENSOR), 128 | 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); 129 | 130 | Colorize colorize; 131 | while (!glfwWindowShouldClose(window)) { 132 | // Update depth image. 133 | if (camera->Update(depth)) { 134 | printf("Unable to update depth image.\n"); 135 | break; 136 | } 137 | 138 | // Update color image. 139 | if (camera->Update(color)) { 140 | printf("Unable to update color image.\n"); 141 | break; 142 | } 143 | 144 | // Colorize depth image. 145 | colorize.Run(camera->width(DEPTH_SENSOR), camera->height(DEPTH_SENSOR), 146 | depth, colorized_depth); 147 | 148 | glfwMakeContextCurrent(window); 149 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 150 | 151 | glMatrixMode(GL_PROJECTION); 152 | glLoadIdentity(); 153 | glOrtho(0.0f, 1.0f, 0.0f, 1.0f, -10.0f, 10.0f); 154 | 155 | glMatrixMode(GL_MODELVIEW); 156 | glLoadIdentity(); 157 | 158 | glViewport(0, 0, kWindowWidth, kWindowHeight); 159 | glBindTexture(GL_TEXTURE_2D, textures[0]); 160 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 161 | camera->width(COLOR_SENSOR), camera->height(COLOR_SENSOR), 162 | GL_RGB, GL_UNSIGNED_BYTE, color); 163 | 164 | glBegin(GL_QUADS); 165 | glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 0.0f, 0.0f); 166 | glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 1.0f, 0.0f); 167 | glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f, 1.0f, 0.0f); 168 | glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, 0.0f, 0.0f); 169 | glEnd(); 170 | 171 | glViewport(kWindowWidth, 0, kWindowWidth, kWindowHeight); 172 | glBindTexture(GL_TEXTURE_2D, textures[1]); 173 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 174 | camera->width(DEPTH_SENSOR), camera->height(DEPTH_SENSOR), 175 | GL_RGB, GL_UNSIGNED_BYTE, colorized_depth); 176 | 177 | glBegin(GL_QUADS); 178 | glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 0.0f, 0.0f); 179 | glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 1.0f, 0.0f); 180 | glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f, 1.0f, 0.0f); 181 | glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, 0.0f, 0.0f); 182 | glEnd(); 183 | 184 | glfwSwapBuffers(window); 185 | glfwPollEvents(); 186 | } 187 | 188 | glfwDestroyWindow(window); 189 | glfwTerminate(); 190 | 191 | delete camera; 192 | delete [] depth; 193 | delete [] color; 194 | delete [] colorized_depth; 195 | 196 | return 0; 197 | } 198 | -------------------------------------------------------------------------------- /applications/camera_viewer/includes.cmake: -------------------------------------------------------------------------------- 1 | set(INCLUDE_DIRS 2 | ${INCLUDE_DIRS} 3 | ${GLEW_INCLUDE_DIRS} 4 | ${GLFW_INCLUDE_DIRS} 5 | ${OPENGL_INCLUDE_DIR} 6 | ) 7 | -------------------------------------------------------------------------------- /applications/camera_viewer/install.cmake: -------------------------------------------------------------------------------- 1 | include(../copy_file.cmake) 2 | include(../copy_folder.cmake) 3 | 4 | # Copy and Install HDF5 DLLs 5 | copy_file("hdf5.dll" "${HDF5_INCLUDE_DIR}/../bin") 6 | copy_file("hdf5_cpp.dll" "${HDF5_INCLUDE_DIR}/../bin") 7 | copy_file("szip.dll" "${HDF5_INCLUDE_DIR}/../bin") 8 | copy_file("zlib.dll" "${HDF5_INCLUDE_DIR}/../bin") 9 | 10 | # Copy and Install GLEW DLLs 11 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 12 | copy_file("glew32.dll" "${GLEW_INCLUDE_DIRS}/../bin/Release/x64") 13 | else() 14 | copy_file("glew32.dll" "${GLEW_INCLUDE_DIRS}/../bin/Release/Win32") 15 | endif() 16 | 17 | # Copy and Install OpenNI2 DLLs 18 | copy_file("OpenNI2.dll" "${OPENNI2_INCLUDE_DIRS}/../Redist") 19 | copy_folder("OpenNI2" "${OPENNI2_INCLUDE_DIRS}/../Redist") 20 | -------------------------------------------------------------------------------- /applications/copy_file.cmake: -------------------------------------------------------------------------------- 1 | function(copy_file filename directory) 2 | set(file_location ${directory}/${filename}) 3 | 4 | # Copy file to working directory. 5 | add_custom_command(TARGET ${APPICATION_NAME} POST_BUILD COMMAND 6 | ${CMAKE_COMMAND} -E copy "${file_location}" 7 | $) 8 | # Install file. 9 | install(FILES "${file_location}" DESTINATION ${BIN_INSTALL_DIR}) 10 | endfunction() 11 | -------------------------------------------------------------------------------- /applications/copy_folder.cmake: -------------------------------------------------------------------------------- 1 | function(copy_folder folder_name directory) 2 | add_custom_command(TARGET ${APPICATION_NAME} POST_BUILD 3 | COMMAND ${CMAKE_COMMAND} -E copy_directory 4 | "${directory}/${folder_name}" 5 | "$/${folder_name}") 6 | 7 | install(DIRECTORY "${directory}/${folder_name}" 8 | DESTINATION "${BIN_INSTALL_DIR}") 9 | endfunction() 10 | -------------------------------------------------------------------------------- /applications/face_detection/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | SET(APPICATION_NAME face_detection) 2 | 3 | SET(MODULE_DEPENDENCIES 4 | cameras 5 | common 6 | io 7 | segmentation 8 | ) 9 | 10 | include(includes.cmake) 11 | 12 | foreach(DEPENDENT ${MODULE_DEPENDENCIES}) 13 | include(${PROJECT_SOURCE_DIR}/${DEPENDENT}/includes.cmake) 14 | 15 | set(INCLUDE_DIRS 16 | ${INCLUDE_DIRS} 17 | ${PROJECT_SOURCE_DIR}/${DEPENDENT}/include 18 | ) 19 | endforeach(DEPENDENT) 20 | 21 | set(INCLUDE_DIRS 22 | ${INCLUDE_DIRS} 23 | ) 24 | 25 | include_directories(${INCLUDE_DIRS}) 26 | 27 | set(INCS 28 | ) 29 | 30 | set(SRCS 31 | ${APPICATION_NAME}.cpp 32 | ) 33 | 34 | set(LIBS 35 | ${GLEW_LIBRARIES} 36 | ${GLFW_LIBRARIES} 37 | ${OpenCV_LIBRARIES} 38 | ${OPENGL_LIBRARIES} 39 | ${X11_LIBS} 40 | ${MODULE_DEPENDENCIES} 41 | ) 42 | 43 | add_executable(${APPICATION_NAME} ${SRCS} ${INCS}) 44 | target_link_libraries(${APPICATION_NAME} ${LIBS}) 45 | 46 | install(TARGETS ${APPICATION_NAME} DESTINATION ${BIN_INSTALL_DIR}) 47 | 48 | include(../copy_file.cmake) 49 | copy_file("haarcascade_frontalface_default.xml" "${PROJECT_SOURCE_DIR}/data") 50 | 51 | if(WIN32) 52 | include(install.cmake) 53 | endif() 54 | -------------------------------------------------------------------------------- /applications/face_detection/includes.cmake: -------------------------------------------------------------------------------- 1 | set(INCLUDE_DIRS 2 | ${INCLUDE_DIRS} 3 | ${GLEW_INCLUDE_DIRS} 4 | ${GLFW_INCLUDE_DIRS} 5 | ${OpenCV_INCLUDE_DIRS} 6 | ${OPENGL_INCLUDE_DIR} 7 | ) 8 | -------------------------------------------------------------------------------- /applications/face_detection/install.cmake: -------------------------------------------------------------------------------- 1 | include(../copy_file.cmake) 2 | include(../copy_folder.cmake) 3 | 4 | # Copy and Install HDF5 DLLs 5 | copy_file("hdf5.dll" "${HDF5_INCLUDE_DIR}/../bin") 6 | copy_file("hdf5_cpp.dll" "${HDF5_INCLUDE_DIR}/../bin") 7 | copy_file("szip.dll" "${HDF5_INCLUDE_DIR}/../bin") 8 | copy_file("zlib.dll" "${HDF5_INCLUDE_DIR}/../bin") 9 | 10 | # Copy and Install GLEW DLLs 11 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 12 | copy_file("glew32.dll" "${GLEW_INCLUDE_DIRS}/../bin/Release/x64") 13 | else() 14 | copy_file("glew32.dll" "${GLEW_INCLUDE_DIRS}/../bin/Release/Win32") 15 | endif() 16 | 17 | # Copy and Install OpenNI2 DLLs 18 | copy_file("OpenNI2.dll" "${OPENNI2_INCLUDE_DIRS}/../Redist") 19 | copy_folder("OpenNI2" "${OPENNI2_INCLUDE_DIRS}/../Redist") 20 | 21 | # Copy and Install OpenCV DLLs 22 | set(OpenCV_NUMBER 23 | "${OpenCV_VERSION_MAJOR}${OpenCV_VERSION_MINOR}${OpenCV_VERSION_PATCH}") 24 | 25 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 26 | copy_file("opencv_core${OpenCV_NUMBER}.dll" "${OpenCV_DIR}/x64/vc11/bin") 27 | copy_file("opencv_core${OpenCV_NUMBER}d.dll" "${OpenCV_DIR}/x64/vc11/bin") 28 | copy_file("opencv_highgui${OpenCV_NUMBER}.dll" "${OpenCV_DIR}/x64/vc11/bin") 29 | copy_file("opencv_highgui${OpenCV_NUMBER}d.dll" "${OpenCV_DIR}/x64/vc11/bin") 30 | copy_file("opencv_imgproc${OpenCV_NUMBER}.dll" "${OpenCV_DIR}/x64/vc11/bin") 31 | copy_file("opencv_imgproc${OpenCV_NUMBER}d.dll" "${OpenCV_DIR}/x64/vc11/bin") 32 | copy_file("opencv_objdetect${OpenCV_NUMBER}.dll" "${OpenCV_DIR}/x64/vc11/bin") 33 | copy_file("opencv_objdetect${OpenCV_NUMBER}d.dll" "${OpenCV_DIR}/x64/vc11/bin") 34 | else() 35 | copy_file("opencv_core${OpenCV_NUMBER}.dll" "${OpenCV_DIR}/x86/vc11/bin") 36 | copy_file("opencv_core${OpenCV_NUMBER}d.dll" "${OpenCV_DIR}/x86/vc11/bin") 37 | copy_file("opencv_highgui${OpenCV_NUMBER}.dll" "${OpenCV_DIR}/x86/vc11/bin") 38 | copy_file("opencv_highgui${OpenCV_NUMBER}d.dll" "${OpenCV_DIR}/x86/vc11/bin") 39 | copy_file("opencv_imgproc${OpenCV_NUMBER}.dll" "${OpenCV_DIR}/x86/vc11/bin") 40 | copy_file("opencv_imgproc${OpenCV_NUMBER}d.dll" "${OpenCV_DIR}/x86/vc11/bin") 41 | copy_file("opencv_objdetect${OpenCV_NUMBER}.dll" "${OpenCV_DIR}/x86/vc11/bin") 42 | copy_file("opencv_objdetect${OpenCV_NUMBER}d.dll" "${OpenCV_DIR}/x86/vc11/bin") 43 | endif() 44 | -------------------------------------------------------------------------------- /applications/face_modeling/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | SET(APPICATION_NAME face_modeling) 2 | 3 | SET(MODULE_DEPENDENCIES 4 | cameras 5 | common 6 | filters 7 | io 8 | point_cloud 9 | projects 10 | registration 11 | sampling 12 | segmentation 13 | surface 14 | visualization 15 | ) 16 | 17 | include(includes.cmake) 18 | 19 | foreach(DEPENDENT ${MODULE_DEPENDENCIES}) 20 | include(${PROJECT_SOURCE_DIR}/${DEPENDENT}/includes.cmake) 21 | 22 | set(INCLUDE_DIRS 23 | ${INCLUDE_DIRS} 24 | ${PROJECT_SOURCE_DIR}/${DEPENDENT}/include 25 | ) 26 | endforeach(DEPENDENT) 27 | 28 | set(INCLUDE_DIRS 29 | ${INCLUDE_DIRS} 30 | ) 31 | 32 | include_directories(${INCLUDE_DIRS}) 33 | 34 | set(INCS 35 | ) 36 | 37 | set(SRCS 38 | ${APPICATION_NAME}.cpp 39 | ) 40 | 41 | set(LIBS 42 | ${GLEW_LIBRARIES} 43 | ${GLFW_LIBRARIES} 44 | ${OPENGL_LIBRARIES} 45 | ${X11_LIBS} 46 | ${MODULE_DEPENDENCIES} 47 | ) 48 | 49 | add_executable(${APPICATION_NAME} ${SRCS} ${INCS}) 50 | target_link_libraries(${APPICATION_NAME} ${LIBS}) 51 | 52 | install(TARGETS ${APPICATION_NAME} DESTINATION ${BIN_INSTALL_DIR}) 53 | 54 | if(WIN32) 55 | include(install.cmake) 56 | endif() 57 | -------------------------------------------------------------------------------- /applications/face_modeling/includes.cmake: -------------------------------------------------------------------------------- 1 | set(INCLUDE_DIRS 2 | ${INCLUDE_DIRS} 3 | ${GLEW_INCLUDE_DIRS} 4 | ${GLFW_INCLUDE_DIRS} 5 | ${OPENGL_INCLUDE_DIR} 6 | ) 7 | -------------------------------------------------------------------------------- /applications/face_modeling/install.cmake: -------------------------------------------------------------------------------- 1 | include(../copy_file.cmake) 2 | include(../copy_folder.cmake) 3 | 4 | # Copy and Install HDF5 DLLs 5 | copy_file("hdf5.dll" "${HDF5_INCLUDE_DIR}/../bin") 6 | copy_file("hdf5_cpp.dll" "${HDF5_INCLUDE_DIR}/../bin") 7 | copy_file("szip.dll" "${HDF5_INCLUDE_DIR}/../bin") 8 | copy_file("zlib.dll" "${HDF5_INCLUDE_DIR}/../bin") 9 | 10 | # Copy and Install GLEW DLLs 11 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 12 | copy_file("glew32.dll" "${GLEW_INCLUDE_DIRS}/../bin/Release/x64") 13 | else() 14 | copy_file("glew32.dll" "${GLEW_INCLUDE_DIRS}/../bin/Release/Win32") 15 | endif() 16 | 17 | # Copy and Install OpenNI2 DLLs 18 | copy_file("OpenNI2.dll" "${OPENNI2_INCLUDE_DIRS}/../Redist") 19 | copy_folder("OpenNI2" "${OPENNI2_INCLUDE_DIRS}/../Redist") 20 | -------------------------------------------------------------------------------- /applications/object_modeling/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | SET(APPICATION_NAME object_modeling) 2 | 3 | SET(MODULE_DEPENDENCIES 4 | cameras 5 | common 6 | filters 7 | io 8 | point_cloud 9 | projects 10 | registration 11 | sampling 12 | surface 13 | visualization 14 | ) 15 | 16 | include(includes.cmake) 17 | 18 | foreach(DEPENDENT ${MODULE_DEPENDENCIES}) 19 | include(${PROJECT_SOURCE_DIR}/${DEPENDENT}/includes.cmake) 20 | 21 | set(INCLUDE_DIRS 22 | ${INCLUDE_DIRS} 23 | ${PROJECT_SOURCE_DIR}/${DEPENDENT}/include 24 | ) 25 | endforeach(DEPENDENT) 26 | 27 | set(INCLUDE_DIRS 28 | ${INCLUDE_DIRS} 29 | ) 30 | 31 | include_directories(${INCLUDE_DIRS}) 32 | 33 | set(INCS 34 | ) 35 | 36 | set(SRCS 37 | ${APPICATION_NAME}.cpp 38 | ) 39 | 40 | set(LIBS 41 | ${GLEW_LIBRARIES} 42 | ${GLFW_LIBRARIES} 43 | ${OPENGL_LIBRARIES} 44 | ${X11_LIBS} 45 | ${MODULE_DEPENDENCIES} 46 | ) 47 | 48 | add_executable(${APPICATION_NAME} ${SRCS} ${INCS}) 49 | target_link_libraries(${APPICATION_NAME} ${LIBS}) 50 | 51 | install(TARGETS ${APPICATION_NAME} DESTINATION ${BIN_INSTALL_DIR}) 52 | 53 | if(WIN32) 54 | include(install.cmake) 55 | endif() 56 | -------------------------------------------------------------------------------- /applications/object_modeling/includes.cmake: -------------------------------------------------------------------------------- 1 | set(INCLUDE_DIRS 2 | ${INCLUDE_DIRS} 3 | ${GLEW_INCLUDE_DIRS} 4 | ${GLFW_INCLUDE_DIRS} 5 | ${OPENGL_INCLUDE_DIR} 6 | ) 7 | -------------------------------------------------------------------------------- /applications/object_modeling/install.cmake: -------------------------------------------------------------------------------- 1 | include(../copy_file.cmake) 2 | include(../copy_folder.cmake) 3 | 4 | # Copy and Install HDF5 DLLs 5 | copy_file("hdf5.dll" "${HDF5_INCLUDE_DIR}/../bin") 6 | copy_file("hdf5_cpp.dll" "${HDF5_INCLUDE_DIR}/../bin") 7 | copy_file("szip.dll" "${HDF5_INCLUDE_DIR}/../bin") 8 | copy_file("zlib.dll" "${HDF5_INCLUDE_DIR}/../bin") 9 | 10 | # Copy and Install GLEW DLLs 11 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 12 | copy_file("glew32.dll" "${GLEW_INCLUDE_DIRS}/../bin/Release/x64") 13 | else() 14 | copy_file("glew32.dll" "${GLEW_INCLUDE_DIRS}/../bin/Release/Win32") 15 | endif() 16 | 17 | # Copy and Install OpenNI2 DLLs 18 | copy_file("OpenNI2.dll" "${OPENNI2_INCLUDE_DIRS}/../Redist") 19 | copy_folder("OpenNI2" "${OPENNI2_INCLUDE_DIRS}/../Redist") 20 | -------------------------------------------------------------------------------- /cameras/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(MODULE_NAME cameras) 2 | 3 | SET(MODULE_DEPENDENCIES 4 | common 5 | io 6 | ) 7 | 8 | include(includes.cmake) 9 | 10 | foreach(DEPENDENT ${MODULE_DEPENDENCIES}) 11 | include(${PROJECT_SOURCE_DIR}/${DEPENDENT}/includes.cmake) 12 | 13 | set(INCLUDE_DIRS 14 | ${INCLUDE_DIRS} 15 | ${PROJECT_SOURCE_DIR}/${DEPENDENT}/include 16 | ) 17 | endforeach(DEPENDENT) 18 | 19 | set(INCLUDE_DIRS 20 | ${INCLUDE_DIRS} 21 | include/ 22 | ) 23 | 24 | include_directories(${INCLUDE_DIRS}) 25 | 26 | set(INCS 27 | include/dip/${MODULE_NAME}/camera.h 28 | include/dip/${MODULE_NAME}/dumpfile.h 29 | include/dip/${MODULE_NAME}/primesense.h 30 | include/dip/${MODULE_NAME}/softkinetic.h 31 | ) 32 | 33 | set(SRCS 34 | src/dumpfile.cpp 35 | src/primesense.cpp 36 | src/softkinetic.cpp 37 | ) 38 | 39 | set(LIBS 40 | ${DEPTHSENSE_LIBRARIES} 41 | ${OPENNI2_LIBRARIES} 42 | ${MODULE_DEPENDENCIES} 43 | ) 44 | 45 | add_library(${MODULE_NAME} ${SRCS} ${INCS}) 46 | target_link_libraries(${MODULE_NAME} ${LIBS}) 47 | 48 | if(WIN32) 49 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}/Release 50 | CONFIGURATIONS Release) 51 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}/Debug 52 | CONFIGURATIONS Debug) 53 | endif() 54 | 55 | if(UNIX) 56 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}) 57 | endif() 58 | 59 | install(FILES ${INCS} DESTINATION ${INCLUDE_INSTALL_DIR}/${MODULE_NAME}) 60 | -------------------------------------------------------------------------------- /cameras/include/dip/cameras/camera.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | // Interface for accessing depth/color cameras. 30 | 31 | #ifndef DIP_CAMERAS_CAMERA_H 32 | #define DIP_CAMERAS_CAMERA_H 33 | 34 | #include 35 | 36 | namespace dip { 37 | 38 | enum SensorTypes { 39 | DEPTH_SENSOR, 40 | COLOR_SENSOR, 41 | SENSOR_TYPES, 42 | }; 43 | 44 | class Camera { 45 | public: 46 | virtual ~Camera() {}; 47 | 48 | // Update depth image. 49 | // depth - Buffer to hold the next depth image captured by the camera. 50 | // The dimensions of the image should be the same as the dimensions 51 | // returned by width() and height() functions. 52 | // Return zero when depth image is succesfully updated. 53 | virtual int Update(Depth *depth) = 0; 54 | 55 | // Update color image. 56 | // color - Buffer to hold the next color image captured by the camera. 57 | // The dimensions of the image should be the same as the dimensions 58 | // returned by width() and height() functions. 59 | // Return zero when color image is succesfully updated. 60 | virtual int Update(Color *color) = 0; 61 | 62 | // Returns true if the camera was successfully enabled. 63 | virtual bool enabled() const = 0; 64 | 65 | // Dimensions of depth/color images. 66 | virtual int width(int sensor) const = 0; 67 | virtual int height(int sensor) const = 0; 68 | 69 | // Focal length of depth/color images. 70 | virtual float fx(int sensor) const = 0; 71 | virtual float fy(int sensor) const = 0; 72 | 73 | // Request image resolution. 74 | virtual int resolution(int sensor, int width, int height) = 0; 75 | }; 76 | 77 | } // namespace dip 78 | 79 | #endif // DIP_CAMERAS_CAMERA_H 80 | -------------------------------------------------------------------------------- /cameras/include/dip/cameras/dumpfile.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | // Loads depth and color images from a HDF5 dump file. 30 | 31 | #ifndef DIP_CAMERAS_DUMPFILE_H 32 | #define DIP_CAMERAS_DUMPFILE_H 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | namespace dip { 40 | 41 | class DumpFile : public Camera { 42 | public: 43 | // Opens dump file. 44 | // file_name - File name of HDF5 dump file. 45 | DumpFile(const char *file_name); 46 | ~DumpFile(); 47 | 48 | // Update depth image. 49 | // depth - Buffer to hold the next depth image captured by the camera. 50 | // The dimensions of the image should be the same as the dimensions 51 | // returned by width() and height() functions. 52 | // Return zero when depth image is succesfully updated. 53 | int Update(Depth *depth); 54 | 55 | // Update color image. 56 | // color - Buffer to hold the next color image captured by the camera. 57 | // The dimensions of the image should be the same as the dimensions 58 | // returned by width() and height() functions. 59 | // Return zero when color image is succesfully updated. 60 | int Update(Color *color); 61 | 62 | // Returns true if the camera was successfully enabled. 63 | bool enabled() const { return enabled_; } 64 | 65 | // Dimensions of depth/color images. 66 | int width(int sensor) const { return width_[sensor]; } 67 | int height(int sensor) const { return height_[sensor]; } 68 | 69 | // Focal length of depth/color images. 70 | float fx(int sensor) const { return fx_[sensor]; } 71 | float fy(int sensor) const { return fy_[sensor]; } 72 | 73 | // Request image resolution. 74 | int resolution(int sensor, int width, int height) { return -1; } 75 | 76 | private: 77 | bool enabled_; 78 | int width_[SENSOR_TYPES], height_[SENSOR_TYPES]; 79 | float fx_[SENSOR_TYPES], fy_[SENSOR_TYPES]; 80 | int count_[SENSOR_TYPES]; 81 | 82 | // Interface to HDF5 file. 83 | HDF5Wrapper *dump_file_; 84 | 85 | DISALLOW_COPY_AND_ASSIGN(DumpFile); 86 | }; 87 | 88 | } // namespace dip 89 | 90 | #endif // DIP_CAMERAS_DUMPFILE_H 91 | -------------------------------------------------------------------------------- /cameras/include/dip/cameras/primesense.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | // Captures depth and color images from a PrimeSense camera 30 | // using the OpenNI2 SDK. 31 | 32 | #ifndef DIP_CAMERAS_PRIMESENSE_H 33 | #define DIP_CAMERAS_PRIMESENSE_H 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #include 40 | 41 | namespace dip { 42 | 43 | class PrimeSense : public Camera { 44 | public: 45 | // Opens PrimeSense depth camera. 46 | // calibration - Enables calibration mode. While in calibration mode, 47 | // IR frames are captured instead of depth frames. 48 | PrimeSense(bool calibration = false); 49 | // Opens PrimeSense depth camera. 50 | // id - ID of camera. 51 | // calibration - Enables calibration mode. While in calibration mode, 52 | // IR frames are captured instead of depth frames. Also, 53 | // the color frames cannot be captured. 54 | PrimeSense(int id, bool calibration = false); 55 | // Opens PrimeSense depth camera. 56 | // uri - URI of camera. 57 | // calibration - Enables calibration mode. While in calibration mode, 58 | // IR frames are captured instead of depth frames. Also, 59 | // the color frames cannot be captured. 60 | PrimeSense(const char *uri, bool calibration = false); 61 | ~PrimeSense(); 62 | 63 | // Update depth image. 64 | // depth - Buffer to hold the next depth image captured by the camera. 65 | // The dimensions of the image should be the same as the dimensions 66 | // returned by width() and height() functions. 67 | // Return zero when depth image is successfully updated. 68 | int Update(Depth *depth); 69 | 70 | // Update color image. 71 | // color - Buffer to hold the next color image captured by the camera. 72 | // The dimensions of the image should be the same as the dimensions 73 | // returned by width() and height() functions. 74 | // Return zero when color image is successfully updated. 75 | int Update(Color *color); 76 | 77 | // Returns true if the camera was successfully enabled. 78 | bool enabled() const { return enabled_; } 79 | 80 | // Dimensions of depth/color images. 81 | int width(int sensor) const { return width_[sensor]; } 82 | int height(int sensor) const { return height_[sensor]; } 83 | 84 | // Focal length of depth/color images. 85 | float fx(int sensor) const { return fx_[sensor]; } 86 | float fy(int sensor) const { return fy_[sensor]; } 87 | 88 | // Device URI 89 | // uri - String containing the URI of the camera. It is the client's 90 | // responsibility to delete the string when it is no longer needed. 91 | // Returns zero on success. 92 | int URI(char **uri) const; 93 | 94 | // Start/Stop running the depth/color sensors. 95 | int start(int sensor); 96 | int stop(int sensor); 97 | 98 | // Request image resolution. 99 | int resolution(int sensor, int width, int height); 100 | 101 | private: 102 | // Initialize PrimeSense camera. 103 | // uri - String containing the URI of the camera. 104 | void initialize(const char *uri, bool calibration); 105 | 106 | bool enabled_, running_[SENSOR_TYPES]; 107 | int width_[SENSOR_TYPES], height_[SENSOR_TYPES]; 108 | float fx_[SENSOR_TYPES], fy_[SENSOR_TYPES]; 109 | 110 | // Handles PrimeSense sensor. 111 | openni::Device device_; 112 | // Manages depth and color streams. 113 | openni::VideoStream stream_[SENSOR_TYPES]; 114 | 115 | // References to current depth and color frame. 116 | openni::VideoFrameRef frame_; 117 | 118 | DISALLOW_COPY_AND_ASSIGN(PrimeSense); 119 | }; 120 | 121 | } // namespace dip 122 | 123 | #endif // DIP_CAMERAS_PRIMESENSE_H 124 | -------------------------------------------------------------------------------- /cameras/include/dip/cameras/softkinetic.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | // Captures depth and color images from a SoftKinetic camera 30 | // using the OpenNI2 SDK. 31 | 32 | #ifndef DIP_CAMERAS_SOFTKINETIC_H 33 | #define DIP_CAMERAS_SOFTKINETIC_H 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #include 40 | 41 | namespace dip { 42 | 43 | class SoftKinetic : public Camera { 44 | public: 45 | // Opens SoftKinetic depth camera. 46 | SoftKinetic(); 47 | ~SoftKinetic(); 48 | 49 | // Update depth image. 50 | // depth - Buffer to hold the next depth image captured by the camera. 51 | // The dimensions of the image should be the same as the dimensions 52 | // returned by width() and height() functions. 53 | // Return zero when depth image is successfully updated. 54 | int Update(Depth *depth); 55 | 56 | // Update color image. 57 | // color - Buffer to hold the next color image captured by the camera. 58 | // The dimensions of the image should be the same as the dimensions 59 | // returned by width() and height() functions. 60 | // Return zero when color image is successfully updated. 61 | int Update(Color *color); 62 | 63 | // Returns true if the camera was successfully enabled. 64 | bool enabled() const { return enabled_; } 65 | 66 | // Dimensions of depth/color images. 67 | int width(int sensor) const { return width_[sensor]; } 68 | int height(int sensor) const { return height_[sensor]; } 69 | 70 | // Focal length of depth/color images. 71 | float fx(int sensor) const { return fx_[sensor]; } 72 | float fy(int sensor) const { return fy_[sensor]; } 73 | 74 | // Start/Stop running the depth/color sensors. 75 | int start(int sensor) { return -1; } 76 | int stop(int sensor) { return -1; } 77 | 78 | // Request image resolution. 79 | int resolution(int sensor, int width, int height) { return -1; } 80 | 81 | private: 82 | bool enabled_; 83 | int width_[SENSOR_TYPES], height_[SENSOR_TYPES]; 84 | float fx_[SENSOR_TYPES], fy_[SENSOR_TYPES]; 85 | 86 | DISALLOW_COPY_AND_ASSIGN(SoftKinetic); 87 | }; 88 | 89 | } // namespace dip 90 | 91 | #endif // DIP_CAMERAS_SOFTKINETIC_H 92 | -------------------------------------------------------------------------------- /cameras/includes.cmake: -------------------------------------------------------------------------------- 1 | set(INCLUDE_DIRS 2 | ${INCLUDE_DIRS} 3 | ${DEPTHSENSE_INCLUDE_DIRS} 4 | ${OPENNI2_INCLUDE_DIRS} 5 | ) 6 | -------------------------------------------------------------------------------- /cameras/src/dumpfile.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | 31 | #include 32 | 33 | namespace dip { 34 | 35 | DumpFile::DumpFile(const char *file_name) : enabled_(false), dump_file_(NULL) { 36 | // Initialize Variables 37 | for (int i = 0; i < SENSOR_TYPES; i++) { 38 | width_[i] = height_[i] = -1; 39 | fx_[i] = fy_[i] = -1.0f; 40 | count_[i] = 0; 41 | } 42 | 43 | if (file_name != NULL) { 44 | // Open dump file using HDF5 Wrapper. 45 | dump_file_ = new HDF5Wrapper(file_name, READ_HDF5); 46 | enabled_ = dump_file_->enabled(); 47 | 48 | if (enabled_) { 49 | // Read image dimensions from file. 50 | dump_file_->Read("WIDTH", "/INFORMATION/DEPTH_SENSOR", 51 | &width_[DEPTH_SENSOR], H5T_NATIVE_INT); 52 | dump_file_->Read("HEIGHT", "/INFORMATION/DEPTH_SENSOR", 53 | &height_[DEPTH_SENSOR], H5T_NATIVE_INT); 54 | 55 | dump_file_->Read("WIDTH", "/INFORMATION/COLOR_SENSOR", 56 | &width_[COLOR_SENSOR], H5T_NATIVE_INT); 57 | dump_file_->Read("HEIGHT", "/INFORMATION/COLOR_SENSOR", 58 | &height_[COLOR_SENSOR], H5T_NATIVE_INT); 59 | 60 | // Read focal lengths from file. 61 | dump_file_->Read("FX", "/INFORMATION/DEPTH_SENSOR", 62 | &fx_[DEPTH_SENSOR], H5T_NATIVE_FLOAT); 63 | dump_file_->Read("FY", "/INFORMATION/DEPTH_SENSOR", 64 | &fy_[DEPTH_SENSOR], H5T_NATIVE_FLOAT); 65 | 66 | dump_file_->Read("FX", "/INFORMATION/COLOR_SENSOR", 67 | &fx_[COLOR_SENSOR], H5T_NATIVE_FLOAT); 68 | dump_file_->Read("FY", "/INFORMATION/COLOR_SENSOR", 69 | &fy_[COLOR_SENSOR], H5T_NATIVE_FLOAT); 70 | } 71 | } 72 | } 73 | 74 | DumpFile::~DumpFile() { 75 | if (dump_file_ != NULL) 76 | delete dump_file_; 77 | } 78 | 79 | int DumpFile::Update(Depth *depth) { 80 | if (enabled_) { 81 | char group[64]; 82 | sprintf(group, "/FRAME%04d", count_[DEPTH_SENSOR]); 83 | 84 | hsize_t dimensions[2] = { (hsize_t)height_[DEPTH_SENSOR], 85 | (hsize_t)width_[DEPTH_SENSOR] }; 86 | 87 | // Read depth image from file. 88 | if (!dump_file_->Read("DEPTH", group, depth, dimensions, 2, 89 | H5T_NATIVE_SHORT)) { 90 | // Update current depth frame. 91 | count_[DEPTH_SENSOR]++; 92 | return 0; 93 | } 94 | } 95 | 96 | return -1; 97 | } 98 | 99 | int DumpFile::Update(Color *color) { 100 | if (enabled_) { 101 | char group[64]; 102 | sprintf(group, "/FRAME%04d", count_[COLOR_SENSOR]); 103 | 104 | hsize_t dimensions[3] = { (hsize_t)height_[COLOR_SENSOR], 105 | (hsize_t)width_[COLOR_SENSOR], 3 }; 106 | 107 | // Read color image from file. 108 | if (!dump_file_->Read("COLOR", group, color, dimensions, 3, 109 | H5T_NATIVE_UCHAR)) { 110 | // Update current color frame. 111 | count_[COLOR_SENSOR]++; 112 | return 0; 113 | } 114 | } 115 | 116 | return -1; 117 | } 118 | 119 | } // namespace dip 120 | -------------------------------------------------------------------------------- /cmake/modules/FindDIP.cmake: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Find Depth-Image-Processing (DIP) 3 | # 4 | # DIP_FOUND - True if DIP was found. 5 | # DIP_INCLUDE_DIR - Directory containing the DIP include files. 6 | # DIP_LIBRARIES - Libraries need to use DIP. 7 | 8 | find_path(DIP_INCLUDE_DIR dip 9 | HINTS /usr/local/include/ 10 | "$ENV{PROGRAMFILES}/dip/include" 11 | "$ENV{PROGRAMW6432}/dip/include" 12 | ) 13 | 14 | set(DIP_MODULES 15 | cameras 16 | common 17 | filters 18 | io 19 | point_cloud 20 | projects 21 | registration 22 | sampling 23 | segmentation 24 | surface 25 | visualization 26 | ) 27 | 28 | foreach(MODULE ${DIP_MODULES}) 29 | find_library(DIP_${MODULE}_LIBRARY_DEBUG 30 | NAMES ${MODULE} 31 | PATHS /usr/local/lib 32 | "$ENV{PROGRAMFILES}/dip/lib/Debug" 33 | "$ENV{PROGRAMW6432}/dip/lib/Debug" 34 | ) 35 | 36 | find_library(DIP_${MODULE}_LIBRARY_RELEASE 37 | NAMES ${MODULE} 38 | PATHS /usr/local/lib 39 | "$ENV{PROGRAMFILES}/dip/lib/Release" 40 | "$ENV{PROGRAMW6432}/dip/lib/Release" 41 | ) 42 | 43 | set(DIP_LIBRARIES 44 | ${DIP_LIBRARIES} 45 | debug ${DIP_${MODULE}_LIBRARY_DEBUG} 46 | optimized ${DIP_${MODULE}_LIBRARY_RELEASE} 47 | ) 48 | 49 | set(DIP_LIBRARY_VARS 50 | ${DIP_LIBRARY_VARS} 51 | DIP_${MODULE}_LIBRARY_DEBUG 52 | DIP_${MODULE}_LIBRARY_RELEASE 53 | ) 54 | endforeach() 55 | 56 | include(FindPackageHandleStandardArgs) 57 | find_package_handle_standard_args(DIP DEFAULT_MSG 58 | DIP_INCLUDE_DIR ${DIP_LIBRARY_VARS}) 59 | -------------------------------------------------------------------------------- /cmake/modules/FindDepthSense.cmake: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Find DepthSense SDK 3 | # 4 | # DEPTHSENSE_FOUND - True if DepthSense was found. 5 | # DEPTHSENSE_INCLUDE_DIRS - Directories containing the DepthSense include 6 | # files. 7 | # DEPTHSENSE_LIBRARIES - Libraries need to use DepthSense. 8 | 9 | find_path(DEPTHSENSE_INCLUDE_DIR DepthSense.hxx 10 | HINTS /opt/softkinetic/DepthSenseSDK/include 11 | PATHS "$ENV{PROGRAMFILES}/SoftKinetic/DepthSenseSDK/include" 12 | "$ENV{PROGRAMW6432}/SoftKinetic/DepthSenseSDK/include") 13 | 14 | find_library(DEPTHSENSE_LIBRARY 15 | NAMES DepthSense 16 | HINTS /opt/softkinetic/DepthSenseSDK/lib 17 | PATHS "$ENV{PROGRAMFILES}/SoftKinetic/DepthSenseSDK/lib" 18 | "$ENV{PROGRAMW6432}/SoftKinetic/DepthSenseSDK/lib") 19 | 20 | set(DEPTHSENSE_INCLUDE_DIRS 21 | ${DEPTHSENSE_INCLUDE_DIR} 22 | ) 23 | 24 | set(DEPTHSENSE_LIBRARIES 25 | ${DEPTHSENSE_LIBRARY} 26 | ) 27 | 28 | include(FindPackageHandleStandardArgs) 29 | find_package_handle_standard_args(DEPTHSENSE DEFAULT_MSG 30 | DEPTHSENSE_INCLUDE_DIR DEPTHSENSE_LIBRARY) 31 | -------------------------------------------------------------------------------- /cmake/modules/FindEigen.cmake: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Find Eigen3 3 | # 4 | # This sets the following variables: 5 | # EIGEN_FOUND - True if Eigen was found. 6 | # EIGEN_INCLUDE_DIRS - Directories containing the Eigen include files. 7 | # EIGEN_DEFINITIONS - Compiler flags for Eigen. 8 | 9 | find_package(PkgConfig) 10 | pkg_check_modules(PC_EIGEN eigen3) 11 | set(EIGEN_DEFINITIONS ${PC_EIGEN_CFLAGS_OTHER}) 12 | 13 | find_path(EIGEN_INCLUDE_DIR Eigen/Core 14 | HINTS ${PC_EIGEN_INCLUDEDIR} ${PC_EIGEN_INCLUDE_DIRS} "${EIGEN_ROOT}" "$ENV{EIGEN_ROOT}" 15 | PATHS "$ENV{PROGRAMFILES}/Eigen" "$ENV{PROGRAMW6432}/Eigen" 16 | "$ENV{PROGRAMFILES}/Eigen 3.0.0" "$ENV{PROGRAMW6432}/Eigen 3.0.0" 17 | PATH_SUFFIXES eigen3 include/eigen3 include) 18 | 19 | set(EIGEN_INCLUDE_DIRS ${EIGEN_INCLUDE_DIR}) 20 | 21 | include(FindPackageHandleStandardArgs) 22 | find_package_handle_standard_args(Eigen DEFAULT_MSG EIGEN_INCLUDE_DIR) 23 | 24 | mark_as_advanced(EIGEN_INCLUDE_DIR) 25 | 26 | if(EIGEN_FOUND) 27 | message(STATUS "Eigen found (include: ${EIGEN_INCLUDE_DIRS})") 28 | endif(EIGEN_FOUND) 29 | -------------------------------------------------------------------------------- /cmake/modules/FindGLEW.cmake: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Find GLEW 3 | # 4 | # GLEW_FOUND - True if GLEW was found. 5 | # GLEW_INCLUDE_DIRS - Directories containing the GLEW include files. 6 | # GLEW_LIBRARIES - Libraries needed to use GLEW. 7 | 8 | find_path(GLEW_INCLUDE_DIR GL/glew.h 9 | HINTS /usr/include 10 | PATHS "$ENV{PROGRAMFILES}/glew/include" 11 | "$ENV{PROGRAMW6432}/glew/include") 12 | 13 | find_library(GLEW_LIBRARY 14 | NAMES GLEW glew32 15 | HINTS /usr/lib 16 | /usr/lib64 17 | PATHS "$ENV{PROGRAMFILES}/glew/lib/Release/Win32" 18 | "$ENV{PROGRAMW6432}/glew/lib/Release/x64") 19 | 20 | set(GLEW_INCLUDE_DIRS 21 | ${GLEW_INCLUDE_DIR} 22 | ) 23 | 24 | set(GLEW_LIBRARIES 25 | ${GLEW_LIBRARY} 26 | ) 27 | 28 | include(FindPackageHandleStandardArgs) 29 | find_package_handle_standard_args(GLEW DEFAULT_MSG 30 | GLEW_INCLUDE_DIR GLEW_LIBRARY) 31 | -------------------------------------------------------------------------------- /cmake/modules/FindGLFW.cmake: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Find GLFW 3 | # 4 | # GLFW_FOUND - True if GLFW was found. 5 | # GLFW_INCLUDE_DIRS - Directories containing the GLFW include files. 6 | # GLFW_LIBRARIES - Libraries needed to use GLFW. 7 | 8 | find_path(GLFW_INCLUDE_DIR GLFW/glfw3.h 9 | HINTS /usr/local/include 10 | PATHS "$ENV{PROGRAMFILES}/glfw/include/" 11 | "$ENV{PROGRAMW6432}/glfw/include/") 12 | 13 | find_library(GLFW_LIBRARY 14 | NAMES glfw3 15 | HINTS /usr/local/lib 16 | PATHS "$ENV{PROGRAMFILES}/glfw/lib-msvc110" 17 | "$ENV{PROGRAMFILES}/glfw/lib-vc2012" 18 | "$ENV{PROGRAMW6432}/glfw/lib-msvc110" 19 | "$ENV{PROGRAMW6432}/glfw/lib-vc2012") 20 | 21 | set(GLFW_INCLUDE_DIRS 22 | ${GLFW_INCLUDE_DIR} 23 | ) 24 | 25 | set(GLFW_LIBRARIES 26 | ${GLFW_LIBRARY} 27 | ) 28 | 29 | include(FindPackageHandleStandardArgs) 30 | find_package_handle_standard_args(GLFW DEFAULT_MSG 31 | GLFW_INCLUDE_DIR GLFW_LIBRARY) 32 | -------------------------------------------------------------------------------- /cmake/modules/FindOpenNI2.cmake: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Find OpenNI2 3 | # 4 | # OPENNI2_FOUND - True if OpenNI2 was found. 5 | # OPENNI2_INCLUDE_DIRS - Directories containing the OpenNI2 include files. 6 | # OPENNI2_LIBRARIES - Libraries need to use OpenNI2. 7 | 8 | find_path(OPENNI2_INCLUDE_DIR OpenNI.h 9 | HINTS ${PC_OPENNI2_INCLUDEDIR} ${PC_OPENNI2_INCLUDE_DIRS} 10 | /usr/include/openni2 /usr/include/ni2 11 | PATHS "$ENV{PROGRAMFILES}/OpenNI2/include" 12 | "$ENV{PROGRAMW6432}/OpenNI2/include" 13 | PATH_SUFFIXES openni2 ni2) 14 | 15 | find_library(OPENNI2_LIBRARY 16 | NAMES OpenNI2 17 | HINTS ${PC_OPENNI2_LIBDIR} ${PC_OPENNI2_LIBRARY_DIRS} 18 | /usr/lib 19 | PATHS "$ENV{PROGRAMFILES}/OpenNI2/Lib${OPENNI2_SUFFIX}" 20 | "$ENV{PROGRAMW6432}/OpenNI2/Lib${OPENNI2_SUFFIX}" 21 | "$ENV{PROGRAMW6432}/OpenNI2" 22 | PATH_SUFFIXES lib lib64) 23 | 24 | set(OPENNI2_INCLUDE_DIRS 25 | ${OPENNI2_INCLUDE_DIR} 26 | ) 27 | 28 | set(OPENNI2_LIBRARIES 29 | ${OPENNI2_LIBRARY} 30 | ) 31 | 32 | include(FindPackageHandleStandardArgs) 33 | find_package_handle_standard_args(OPENNI2 DEFAULT_MSG 34 | OPENNI2_INCLUDE_DIR OPENNI2_LIBRARY) 35 | -------------------------------------------------------------------------------- /common/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(MODULE_NAME common) 2 | 3 | SET(MODULE_DEPENDENCIES 4 | ) 5 | 6 | include(includes.cmake) 7 | 8 | foreach(DEPENDENT ${MODULE_DEPENDENCIES}) 9 | include(${PROJECT_SOURCE_DIR}/${DEPENDENT}/includes.cmake) 10 | 11 | set(INCLUDE_DIRS 12 | ${INCLUDE_DIRS} 13 | ${PROJECT_SOURCE_DIR}/${DEPENDENT}/include 14 | ) 15 | endforeach(DEPENDENT) 16 | 17 | set(INCLUDE_DIRS 18 | ${INCLUDE_DIRS} 19 | include/ 20 | ) 21 | 22 | include_directories(${INCLUDE_DIRS}) 23 | 24 | set(INCS 25 | include/dip/${MODULE_NAME}/error.h 26 | include/dip/${MODULE_NAME}/macros.h 27 | include/dip/${MODULE_NAME}/memory.h 28 | include/dip/${MODULE_NAME}/reduction.h 29 | include/dip/${MODULE_NAME}/types.h 30 | ) 31 | 32 | set(SRCS 33 | src/error.cu 34 | src/memory.cu 35 | src/reduction.cu 36 | ) 37 | 38 | set(LIBS 39 | ${MODULE_DEPENDENCIES} 40 | ) 41 | 42 | cuda_add_library(${MODULE_NAME} ${SRCS} ${INCS}) 43 | target_link_libraries(${MODULE_NAME} ${LIBS}) 44 | 45 | if(WIN32) 46 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}/Release 47 | CONFIGURATIONS Release) 48 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}/Debug 49 | CONFIGURATIONS Debug) 50 | endif() 51 | 52 | if(UNIX) 53 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}) 54 | endif() 55 | 56 | install(FILES ${INCS} DESTINATION ${INCLUDE_INSTALL_DIR}/${MODULE_NAME}) 57 | -------------------------------------------------------------------------------- /common/include/dip/common/error.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef DIP_COMMON_ERROR_H 30 | #define DIP_COMMON_ERROR_H 31 | 32 | namespace dip { 33 | 34 | #define CUDA_ERROR_CHECK(result) { CUDAError((result), __FILE__, __LINE__); } 35 | extern void CUDAError(cudaError_t result, char *file, int line); 36 | 37 | } // namespace dip 38 | 39 | #endif // DIP_COMMON_ERROR_H 40 | -------------------------------------------------------------------------------- /common/include/dip/common/macros.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | // Define commonly used marcos. 30 | 31 | #ifndef DIP_COMMON_MACROS_H 32 | #define DIP_COMMON_MACROS_H 33 | 34 | namespace dip { 35 | 36 | #ifndef ABS 37 | #define ABS(a) (((a) < 0) ? -(a) : (a)) 38 | #endif 39 | 40 | #ifndef SGN 41 | #define SGN(a) (((a) < 0) ? -1 : 1) 42 | #endif 43 | 44 | #ifndef DIFF 45 | #define DIFF(a, b) (ABS((a) - (b))) 46 | #endif 47 | 48 | #ifndef MIN 49 | #define MIN(a, b) (((a) < (b)) ? (a) : (b)) 50 | #endif 51 | 52 | #ifndef MAX 53 | #define MAX(a, b) (((a) > (b)) ? (a) : (b)) 54 | #endif 55 | 56 | #ifndef INDEX2D 57 | #define INDEX2D(x, y, width) ((x) + ((y) * (width))) 58 | #endif 59 | 60 | #ifndef INDEX3D 61 | #define INDEX3D(x, y, z, width, height) ((x) + ((y) * (width)) + \ 62 | ((z) * (width) * (height))) 63 | #endif 64 | 65 | #ifndef DISALLOW_COPY_AND_ASSIGN 66 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ 67 | TypeName(const TypeName&); \ 68 | void operator=(const TypeName&) 69 | #endif 70 | 71 | } // namespace dip 72 | 73 | #endif // DIP_COMMON_MACROS_H 74 | -------------------------------------------------------------------------------- /common/include/dip/common/memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef DIP_COMMON_MEMORY_H 30 | #define DIP_COMMON_MEMORY_H 31 | 32 | namespace dip { 33 | 34 | extern void Allocate(void **buffer, int bytes); 35 | extern void Deallocate(void *buffer); 36 | 37 | extern void Clear(void *buffer, int bytes); 38 | extern void Set(void *buffer, int value, int bytes); 39 | 40 | extern void Upload(void *dst, const void *src, int bytes); 41 | extern void Download(void *dst, const void *src, int bytes); 42 | extern void Copy(void *dst, const void *src, int bytes); 43 | 44 | extern void UploadImage(void *dst, const void *src, int width, int height, 45 | int dst_pitch, int src_pitch); 46 | extern void DownloadImage(void *dst, const void *src, int width, int height, 47 | int dst_pitch, int src_pitch); 48 | extern void CopyImage(void *dst, const void *src, int width, int height, 49 | int dst_pitch, int src_pitch); 50 | 51 | } // namespace dip 52 | 53 | #endif // DIP_COMMON_MEMORY_H 54 | -------------------------------------------------------------------------------- /common/include/dip/common/reduction.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef DIP_COMMON_REDUCTION_H 30 | #define DIP_COMMON_REDUCTION_H 31 | 32 | namespace dip { 33 | 34 | extern int Reduce(int elements, int *buffer); 35 | extern float Reduce(int elements, float *buffer); 36 | 37 | } // namespace dip 38 | 39 | #endif // DIP_COMMON_REDUCTION_H 40 | -------------------------------------------------------------------------------- /common/include/dip/common/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | // Define commonly used datatypes. 30 | 31 | #ifndef DIP_COMMON_TYPES_H 32 | #define DIP_COMMON_TYPES_H 33 | 34 | #include 35 | 36 | namespace dip { 37 | 38 | typedef struct { 39 | float x; 40 | float y; 41 | float z; 42 | } Vertex; 43 | 44 | typedef struct { 45 | float x; 46 | float y; 47 | float z; 48 | } Vector; 49 | 50 | typedef struct { 51 | float *x; 52 | float *y; 53 | float *z; 54 | } Vertices; 55 | 56 | typedef struct { 57 | float *x; 58 | float *y; 59 | float *z; 60 | } Normals; 61 | 62 | typedef struct { 63 | unsigned char r; 64 | unsigned char g; 65 | unsigned char b; 66 | } Color; 67 | 68 | typedef unsigned short Depth; 69 | 70 | } // namespace dip 71 | 72 | #endif // DIP_COMMON_TYPES_H 73 | -------------------------------------------------------------------------------- /common/includes.cmake: -------------------------------------------------------------------------------- 1 | set(INCLUDE_DIRS 2 | ${INCLUDE_DIRS} 3 | ) 4 | -------------------------------------------------------------------------------- /common/src/error.cu: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | 31 | namespace dip { 32 | 33 | void CUDAError(cudaError_t result, char *file, int line) { 34 | if (result != cudaSuccess) { 35 | fprintf(stderr,"CUDA Error: %s %s %d\n", cudaGetErrorString(result), 36 | file, line); 37 | } 38 | } 39 | 40 | } // namespace dip 41 | -------------------------------------------------------------------------------- /common/src/memory.cu: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | 31 | namespace dip { 32 | 33 | void Allocate(void **buffer, int bytes) { 34 | // Allocate buffer. 35 | CUDA_ERROR_CHECK(cudaMalloc(buffer, bytes)) 36 | } 37 | 38 | void Deallocate(void *buffer) { 39 | // Deallocate buffer. 40 | CUDA_ERROR_CHECK(cudaFree(buffer)); 41 | } 42 | 43 | void Clear(void *buffer, int bytes) { 44 | // Clear buffer. 45 | CUDA_ERROR_CHECK(cudaMemset(buffer, 0, bytes)); 46 | } 47 | 48 | void Set(void *buffer, int value, int bytes) { 49 | // Set buffer. 50 | CUDA_ERROR_CHECK(cudaMemset(buffer, value, bytes)); 51 | } 52 | 53 | void Upload(void *dst, const void *src, int bytes) { 54 | // Copy buffer from CPU to GPU. 55 | CUDA_ERROR_CHECK(cudaMemcpy(dst, src, bytes, cudaMemcpyHostToDevice)); 56 | } 57 | 58 | void Download(void *dst, const void *src, int bytes) { 59 | // Copy buffer from GPU to CPU. 60 | CUDA_ERROR_CHECK(cudaMemcpy(dst, src, bytes, cudaMemcpyDeviceToHost)); 61 | } 62 | 63 | void Copy(void *dst, const void *src, int bytes) { 64 | // Copy buffer from GPU to GPU. 65 | CUDA_ERROR_CHECK(cudaMemcpy(dst, src, bytes, cudaMemcpyDeviceToDevice)); 66 | } 67 | 68 | void UploadImage(void *dst, const void *src, int width, int height, 69 | int dst_pitch, int src_pitch) { 70 | // Copy Image from CPU to GPU. 71 | CUDA_ERROR_CHECK(cudaMemcpy2D(dst, dst_pitch, src, src_pitch, 72 | width, height, cudaMemcpyHostToDevice)); 73 | } 74 | 75 | void DownloadImage(void *dst, const void *src, int width, int height, 76 | int dst_pitch, int src_pitch) { 77 | // Copy Image from GPU to CPU. 78 | CUDA_ERROR_CHECK(cudaMemcpy2D(dst, dst_pitch, src, src_pitch, 79 | width, height, cudaMemcpyDeviceToHost)); 80 | } 81 | 82 | void CopyImage(void *dst, const void *src, int width, int height, 83 | int dst_pitch, int src_pitch) { 84 | // Copy Image from GPU to GPU. 85 | CUDA_ERROR_CHECK(cudaMemcpy2D(dst, dst_pitch, src, src_pitch, 86 | width, height, cudaMemcpyDeviceToDevice)); 87 | } 88 | 89 | } // namespace dip 90 | -------------------------------------------------------------------------------- /common/src/reduction.cu: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | #include 31 | 32 | #define BLOCK_SIZE 256 33 | 34 | namespace dip { 35 | 36 | __global__ void Reduction(int elements, int *buffer) { 37 | // Allocate Shared Memory 38 | __shared__ int sm[2 * BLOCK_SIZE]; 39 | 40 | // Get Block and Thread Id 41 | int b = blockIdx.x; 42 | int t = threadIdx.x; 43 | 44 | // Cooperative Load Elements into Shared Memory 45 | if ((t + (b * BLOCK_SIZE * 2)) < elements) 46 | sm[t] = buffer[t + (b * BLOCK_SIZE * 2)]; 47 | else 48 | sm[t] = 0; 49 | 50 | if (((t + BLOCK_SIZE) + (b * BLOCK_SIZE * 2)) < elements) 51 | sm[t + BLOCK_SIZE] = buffer[(t + BLOCK_SIZE) + (b * BLOCK_SIZE * 2)]; 52 | else 53 | sm[t + BLOCK_SIZE] = 0; 54 | 55 | // Initialize Offset 56 | int offset = 1; 57 | 58 | // Perform Reduction 59 | for (int d = (2 * BLOCK_SIZE) >> 1; d > 0; d >>= 1) { 60 | __syncthreads(); 61 | 62 | if (t < d) { 63 | int ai = offset * (2 * t + 1) - 1; 64 | int bi = offset * (2 * t + 2) - 1; 65 | 66 | sm[bi] += sm[ai]; 67 | } 68 | 69 | offset *= 2; 70 | } 71 | 72 | // Store Results 73 | if (t == 0) 74 | buffer[b] = sm[(2 * BLOCK_SIZE) - 1]; 75 | } 76 | 77 | __global__ void Reduction(int elements, float *buffer) { 78 | // Allocate Shared Memory 79 | __shared__ float sm[2 * BLOCK_SIZE]; 80 | 81 | // Get Block and Thread Id 82 | int b = blockIdx.x; 83 | int t = threadIdx.x; 84 | 85 | // Cooperative Load Elements into Shared Memory 86 | if ((t + (b * BLOCK_SIZE * 2)) < elements) 87 | sm[t] = buffer[t + (b * BLOCK_SIZE * 2)]; 88 | else 89 | sm[t] = 0; 90 | 91 | if (((t + BLOCK_SIZE) + (b * BLOCK_SIZE * 2)) < elements) 92 | sm[t + BLOCK_SIZE] = buffer[(t + BLOCK_SIZE) + (b * BLOCK_SIZE * 2)]; 93 | else 94 | sm[t + BLOCK_SIZE] = 0; 95 | 96 | // Initialize Offset 97 | int offset = 1; 98 | 99 | // Perform Reduction 100 | for (int d = (2 * BLOCK_SIZE) >> 1; d > 0; d >>= 1) { 101 | __syncthreads(); 102 | 103 | if (t < d) { 104 | int ai = offset * (2 * t + 1) - 1; 105 | int bi = offset * (2 * t + 2) - 1; 106 | 107 | sm[bi] += sm[ai]; 108 | } 109 | 110 | offset *= 2; 111 | } 112 | 113 | // Store Results 114 | if (t == 0) 115 | buffer[b] = sm[(2 * BLOCK_SIZE) - 1]; 116 | } 117 | 118 | int Reduce(int elements, int *buffer) { 119 | // Launch Reduction Kernel 120 | while(elements > 1) { 121 | int grid_size = (elements + (2 * BLOCK_SIZE - 1)) / (2 * BLOCK_SIZE); 122 | 123 | dim3 grid_dim(grid_size, 1, 1); 124 | dim3 block_dim(BLOCK_SIZE, 1, 1); 125 | 126 | Reduction<<>>(elements, buffer); 127 | 128 | CUDA_ERROR_CHECK(cudaDeviceSynchronize()); 129 | 130 | elements = grid_size; 131 | } 132 | 133 | int value; 134 | Download(&value, buffer, sizeof(int)); 135 | return value; 136 | } 137 | 138 | float Reduce(int elements, float *buffer) { 139 | // Launch Reduction Kernel 140 | while(elements > 1) { 141 | int grid_size = (elements + (2 * BLOCK_SIZE - 1)) / (2 * BLOCK_SIZE); 142 | 143 | dim3 grid_dim(grid_size, 1, 1); 144 | dim3 block_dim(BLOCK_SIZE, 1, 1); 145 | 146 | Reduction<<>>(elements, buffer); 147 | 148 | CUDA_ERROR_CHECK(cudaDeviceSynchronize()); 149 | 150 | elements = grid_size; 151 | } 152 | 153 | float value; 154 | Download(&value, buffer, sizeof(float)); 155 | return value; 156 | } 157 | 158 | } // namespace dip 159 | -------------------------------------------------------------------------------- /filters/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(MODULE_NAME filters) 2 | 3 | SET(MODULE_DEPENDENCIES 4 | common 5 | ) 6 | 7 | include(includes.cmake) 8 | 9 | foreach(DEPENDENT ${MODULE_DEPENDENCIES}) 10 | include(${PROJECT_SOURCE_DIR}/${DEPENDENT}/includes.cmake) 11 | 12 | set(INCLUDE_DIRS 13 | ${INCLUDE_DIRS} 14 | ${PROJECT_SOURCE_DIR}/${DEPENDENT}/include 15 | ) 16 | endforeach(DEPENDENT) 17 | 18 | set(INCLUDE_DIRS 19 | ${INCLUDE_DIRS} 20 | include/ 21 | ) 22 | 23 | include_directories(${INCLUDE_DIRS}) 24 | 25 | set(INCS 26 | include/dip/${MODULE_NAME}/bilateral.h 27 | include/dip/${MODULE_NAME}/threshold.h 28 | include/dip/${MODULE_NAME}/variance.h 29 | ) 30 | 31 | set(SRCS 32 | src/bilateral.cpp 33 | src/bilateral.cu 34 | src/threshold.cpp 35 | src/threshold.cu 36 | src/variance.cpp 37 | src/variance.cu 38 | ) 39 | 40 | set(LIBS 41 | ${MODULE_DEPENDENCIES} 42 | ) 43 | 44 | cuda_add_library(${MODULE_NAME} ${SRCS} ${INCS}) 45 | target_link_libraries(${MODULE_NAME} ${LIBS}) 46 | 47 | if(WIN32) 48 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}/Release 49 | CONFIGURATIONS Release) 50 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}/Debug 51 | CONFIGURATIONS Debug) 52 | endif() 53 | 54 | if(UNIX) 55 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}) 56 | endif() 57 | 58 | install(FILES ${INCS} DESTINATION ${INCLUDE_INSTALL_DIR}/${MODULE_NAME}) 59 | -------------------------------------------------------------------------------- /filters/include/dip/filters/bilateral.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef DIP_FILTERS_BILATERAL_H 30 | #define DIP_FILTERS_BILATERAL_H 31 | 32 | #include 33 | #include 34 | 35 | namespace dip { 36 | 37 | class Bilateral { 38 | public: 39 | Bilateral() {} 40 | ~Bilateral() {} 41 | 42 | void Run(float sigma_d, float sigma_r, int width, int height, 43 | const Depth *depth, Depth *filtered_depth); 44 | 45 | private: 46 | DISALLOW_COPY_AND_ASSIGN(Bilateral); 47 | }; 48 | 49 | } // namespace dip 50 | 51 | #endif // DIP_FILTERS_BILATERAL_H -------------------------------------------------------------------------------- /filters/include/dip/filters/threshold.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef DIP_FILTERS_THRESHOLD_H 30 | #define DIP_FILTERS_THRESHOLD_H 31 | 32 | #include 33 | #include 34 | 35 | namespace dip { 36 | 37 | class Threshold { 38 | public: 39 | Threshold() {} 40 | ~Threshold() {} 41 | 42 | void Run(int min_depth, int max_depth, int width, int height, Depth *depth); 43 | 44 | private: 45 | DISALLOW_COPY_AND_ASSIGN(Threshold); 46 | }; 47 | 48 | } // namespace dip 49 | 50 | #endif // DIP_FILTERS_THRESHOLD_H 51 | -------------------------------------------------------------------------------- /filters/include/dip/filters/variance.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef DIP_FILTERS_VARIANCE_H 30 | #define DIP_FILTERS_VARIANCE_H 31 | 32 | #include 33 | #include 34 | 35 | namespace dip { 36 | 37 | class Variance { 38 | public: 39 | Variance(); 40 | ~Variance(); 41 | 42 | void Run(int width, int height, const Depth *depth, Depth *filtered_depth); 43 | 44 | private: 45 | float *variance_, *std_, *valid_; 46 | int bytes_; 47 | 48 | DISALLOW_COPY_AND_ASSIGN(Variance); 49 | }; 50 | 51 | } // namespace dip 52 | 53 | #endif // DIP_FILTERS_VARIANCE_H 54 | -------------------------------------------------------------------------------- /filters/includes.cmake: -------------------------------------------------------------------------------- 1 | set(INCLUDE_DIRS 2 | ${INCLUDE_DIRS} 3 | ) -------------------------------------------------------------------------------- /filters/src/bilateral.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | 31 | namespace dip { 32 | 33 | extern void BilateralKernel(float sigma_d, float sigma_r, int width, int height, 34 | const Depth *depth, Depth *filtered_depth); 35 | 36 | void Bilateral::Run(float sigma_d, float sigma_r, int width, int height, 37 | const Depth *depth, Depth *filtered_depth) { 38 | BilateralKernel(sigma_d, sigma_r, width, height, depth, filtered_depth); 39 | } 40 | 41 | } // namespace dip 42 | -------------------------------------------------------------------------------- /filters/src/bilateral.cu: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | #include 31 | 32 | #define FILTER_HALF_WIDTH 3 33 | #define BLOCK_WIDTH 16 34 | 35 | namespace dip { 36 | 37 | __global__ void BilateralFilter(float sigma_d, float sigma_r, 38 | int width, int height, 39 | const Depth *depth, Depth *filtered_depth) { 40 | // Allocate Shared Memory 41 | __shared__ Depth ds[BLOCK_WIDTH][BLOCK_WIDTH]; 42 | 43 | // Get Block and Thread Id 44 | int bx = blockIdx.x; int by = blockIdx.y; 45 | int tx = threadIdx.x; int ty = threadIdx.y; 46 | 47 | // Calculate Row & Column 48 | int col = tx + bx * BLOCK_WIDTH; 49 | int row = ty + by * BLOCK_WIDTH; 50 | 51 | // Cooperative Load of the Tile 52 | if ((col < width) && (row < height)) { 53 | ds[ty][tx] = depth[col + row * width]; 54 | } 55 | else { 56 | ds[ty][tx] = 0; 57 | } 58 | 59 | // Sync Threads in Block 60 | __syncthreads(); 61 | 62 | // Perform the Bilateral Filter 63 | if ((col < width) && (row < height)) { 64 | float center_depth = ds[ty][tx]; 65 | float h = 0.0f, k = 0.0f; 66 | 67 | if (center_depth > 0) { 68 | for (int dy = -FILTER_HALF_WIDTH; dy <= FILTER_HALF_WIDTH; dy++) { 69 | for (int dx = -FILTER_HALF_WIDTH; dx <= FILTER_HALF_WIDTH; dx++) { 70 | int x = col + dx; 71 | int y = row + dy; 72 | 73 | if ((x >= 0) && (x < width) && (y >= 0) && (y < height)) { 74 | int i = tx + dx; 75 | int j = ty + dy; 76 | 77 | float current_depth; 78 | if ((i >= 0) && (i < BLOCK_WIDTH) && (j >= 0) && (j < BLOCK_WIDTH)) 79 | current_depth = ds[j][i]; 80 | else 81 | current_depth = depth[x + y * width]; 82 | 83 | if (current_depth > 0) { 84 | float d = static_cast((dx * dx) + (dy * dy)); 85 | float r = static_cast((current_depth - center_depth) * 86 | (current_depth - center_depth)); 87 | 88 | float weight = __expf(-0.5f * (d * sigma_d + r * sigma_r)); 89 | 90 | h += current_depth * weight; 91 | k += weight; 92 | } 93 | } 94 | } 95 | } 96 | } 97 | 98 | if (k > 0.0f) 99 | filtered_depth[col + row * width] = h / k; 100 | else 101 | filtered_depth[col + row * width] = 0; 102 | } 103 | } 104 | 105 | void BilateralKernel(float sigma_d, float sigma_r, int width, int height, 106 | const Depth *depth, Depth *filtered_depth) { 107 | // Launch Bilateral Filter Kernel 108 | int grid_width = (width + (BLOCK_WIDTH - 1)) / BLOCK_WIDTH; 109 | int grid_height = (height + (BLOCK_WIDTH - 1)) / BLOCK_WIDTH; 110 | 111 | dim3 grid_dim(grid_width, grid_height, 1); 112 | dim3 block_dim(BLOCK_WIDTH, BLOCK_WIDTH, 1); 113 | 114 | BilateralFilter<<>>(sigma_d, sigma_r, width, height, 115 | depth, filtered_depth); 116 | 117 | CUDA_ERROR_CHECK(cudaDeviceSynchronize()); 118 | } 119 | 120 | } // namespace dip 121 | -------------------------------------------------------------------------------- /filters/src/threshold.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | 31 | namespace dip { 32 | 33 | extern void ThresholdKernel(int min_depth, int max_depth, int width, int height, 34 | Depth *depth); 35 | 36 | void Threshold::Run(int min_depth, int max_depth, int width, int height, 37 | Depth *depth) { 38 | ThresholdKernel(min_depth, max_depth, width, height, depth); 39 | } 40 | 41 | } // namespace dip 42 | -------------------------------------------------------------------------------- /filters/src/threshold.cu: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | #include 31 | 32 | #define BLOCK_WIDTH 16 33 | 34 | namespace dip { 35 | 36 | __global__ void ThresholdFilter(int min_depth, int max_depth, 37 | int width, int height, Depth *depth) { 38 | // Get Block and Thread Id 39 | int bx = blockIdx.x; int by = blockIdx.y; 40 | int tx = threadIdx.x; int ty = threadIdx.y; 41 | 42 | // Calculate Row & Column 43 | int col = tx + bx * BLOCK_WIDTH; 44 | int row = ty + by * BLOCK_WIDTH; 45 | 46 | // Perform Threshold 47 | if ((col < width) && (row < height)) { 48 | int i = col + row * width; 49 | 50 | int depth_value = depth[i]; 51 | 52 | if((depth_value < min_depth) || (depth_value > max_depth)) 53 | depth[i] = 0; 54 | } 55 | } 56 | 57 | void ThresholdKernel(int min_depth, int max_depth, int width, int height, 58 | Depth *depth) { 59 | // Launch Threshold Filter Kernel 60 | int grid_width = (width + (BLOCK_WIDTH - 1)) / BLOCK_WIDTH; 61 | int grid_height = (height + (BLOCK_WIDTH - 1)) / BLOCK_WIDTH; 62 | 63 | dim3 grid_dim(grid_width, grid_height, 1); 64 | dim3 block_dim(BLOCK_WIDTH, BLOCK_WIDTH, 1); 65 | 66 | ThresholdFilter<<>>(min_depth, max_depth, width, height, 67 | depth); 68 | 69 | CUDA_ERROR_CHECK(cudaDeviceSynchronize()); 70 | } 71 | 72 | } // namespace dip 73 | -------------------------------------------------------------------------------- /filters/src/variance.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | 31 | #include 32 | 33 | #include 34 | #include 35 | 36 | namespace dip { 37 | 38 | extern void VarianceKernel(int width, int height, const Depth *depth, 39 | float *variance, float *std, float *valid); 40 | extern void ThresholdKernel(float threshold, int width, int height, 41 | const float *std, const Depth *depth, 42 | Depth *filtered_depth); 43 | 44 | Variance::Variance() : bytes_(0) { 45 | variance_ = NULL; 46 | std_ = NULL; 47 | valid_ = NULL; 48 | } 49 | 50 | Variance::~Variance() { 51 | if (variance_!= NULL) 52 | Deallocate((void*)variance_); 53 | if (std_!= NULL) 54 | Deallocate((void*)std_); 55 | if (valid_!= NULL) 56 | Deallocate((void*)valid_); 57 | } 58 | 59 | void Variance::Run(int width, int height, const Depth *depth, 60 | Depth *filtered_depth) { 61 | int required_bytes = sizeof(float) * width * height; 62 | 63 | if (bytes_ < required_bytes) { 64 | bytes_ = required_bytes; 65 | 66 | if (variance_!= NULL) 67 | Deallocate((void*)variance_); 68 | if (std_!= NULL) 69 | Deallocate((void*)std_); 70 | if (valid_!= NULL) 71 | Deallocate((void*)valid_); 72 | 73 | Allocate((void**)&variance_, bytes_); 74 | Allocate((void**)&std_, bytes_); 75 | Allocate((void**)&valid_, bytes_); 76 | } 77 | 78 | VarianceKernel(width, height, depth, variance_, std_, valid_); 79 | 80 | float valid = Reduce(width * height, valid_); 81 | float mean_variance = Reduce(width * height, variance_) / valid; 82 | float mean_std = Reduce(width * height, std_) / valid; 83 | float std_std = sqrt(mean_variance - (mean_std * mean_std)); 84 | 85 | ThresholdKernel(mean_std + 2.0f * std_std, width, height, std_, 86 | depth, filtered_depth); 87 | } 88 | 89 | } // namespace dip 90 | -------------------------------------------------------------------------------- /filters/src/variance.cu: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | #include 31 | 32 | #define FILTER_HALF_WIDTH 3 33 | #define BLOCK_WIDTH 16 34 | 35 | namespace dip { 36 | 37 | __global__ void Variance(int width, int height, const Depth *depth, 38 | float *variance, float *std, float *valid) { 39 | // Allocate Shared Memory 40 | __shared__ Depth ds[BLOCK_WIDTH][BLOCK_WIDTH]; 41 | 42 | // Get Block and Thread Id 43 | int bx = blockIdx.x; int by = blockIdx.y; 44 | int tx = threadIdx.x; int ty = threadIdx.y; 45 | 46 | // Calculate Row & Column 47 | int col = tx + bx * BLOCK_WIDTH; 48 | int row = ty + by * BLOCK_WIDTH; 49 | 50 | // Cooperative Load of the Tile 51 | if ((col < width) && (row < height)) { 52 | ds[ty][tx] = depth[col + row * width]; 53 | } else { 54 | ds[ty][tx] = 0; 55 | } 56 | 57 | // Sync Threads in Block 58 | __syncthreads(); 59 | 60 | // Perform the Variance Filter 61 | if ((col < width) && (row < height)) { 62 | float sum = 0.0f, squared_sum = 0.0f; 63 | int count = 0; 64 | 65 | for (int dy = -FILTER_HALF_WIDTH; dy <= FILTER_HALF_WIDTH; dy++) { 66 | for (int dx = -FILTER_HALF_WIDTH; dx <= FILTER_HALF_WIDTH; dx++) { 67 | int x = col + dx; 68 | int y = row + dy; 69 | 70 | if ((x >= 0) && (x < width) && (y >= 0) && (y < height)) { 71 | int i = tx + dx; 72 | int j = ty + dy; 73 | 74 | float depth_value; 75 | if ((i >= 0) && (i < BLOCK_WIDTH) && (j >= 0) && (j < BLOCK_WIDTH)) 76 | depth_value = ds[j][i]; 77 | else 78 | depth_value = depth[x + y * width]; 79 | 80 | if (depth_value > 0) { 81 | sum += depth_value; 82 | squared_sum += depth_value * depth_value; 83 | count++; 84 | } 85 | } 86 | } 87 | } 88 | 89 | if ((ds[ty][tx] > 0) && (count > 0)) { 90 | float mean = sum / count; 91 | float squared_mean = squared_sum / count; 92 | float var = squared_mean - (mean * mean); 93 | 94 | if (var > 0.0f) { 95 | variance[col + row * width] = var; 96 | std[col + row * width] = sqrt(var); 97 | valid[col + row * width] = 1.0f; 98 | } else { 99 | variance[col + row * width] = 0.0f; 100 | std[col + row * width] = 0.0f; 101 | valid[col + row * width] = 0.0f; 102 | } 103 | } else { 104 | variance[col + row * width] = 0.0f; 105 | std[col + row * width] = 0.0f; 106 | valid[col + row * width] = 0.0f; 107 | } 108 | } 109 | } 110 | 111 | __global__ void Threshold(float threshold, int width, int height, 112 | const float *std, const Depth *depth, 113 | Depth *filtered_depth) { 114 | // Get Block and Thread Id 115 | int bx = blockIdx.x; int by = blockIdx.y; 116 | int tx = threadIdx.x; int ty = threadIdx.y; 117 | 118 | // Calculate Row & Column 119 | int col = tx + bx * BLOCK_WIDTH; 120 | int row = ty + by * BLOCK_WIDTH; 121 | 122 | // Perform Threshold 123 | if ((col < width) && (row < height)) { 124 | int i = col + row * width; 125 | 126 | if (std[i] < threshold) 127 | filtered_depth[i] = depth[i]; 128 | else 129 | filtered_depth[i] = 0; 130 | } 131 | } 132 | 133 | void VarianceKernel(int width, int height, const Depth *depth, 134 | float *variance, float *std, float *valid) { 135 | // Launch Variance Filter Kernel 136 | int grid_width = (width + (BLOCK_WIDTH - 1)) / BLOCK_WIDTH; 137 | int grid_height = (height + (BLOCK_WIDTH - 1)) / BLOCK_WIDTH; 138 | 139 | dim3 grid_dim(grid_width, grid_height, 1); 140 | dim3 block_dim(BLOCK_WIDTH, BLOCK_WIDTH, 1); 141 | 142 | Variance<<>>(width, height, depth, variance, std, valid); 143 | 144 | CUDA_ERROR_CHECK(cudaDeviceSynchronize()); 145 | } 146 | 147 | void ThresholdKernel(float threshold, int width, int height, 148 | const float *std, const Depth *depth, 149 | Depth *filtered_depth) { 150 | // Launch Variance Filter Kernel 151 | int grid_width = (width + (BLOCK_WIDTH - 1)) / BLOCK_WIDTH; 152 | int grid_height = (height + (BLOCK_WIDTH - 1)) / BLOCK_WIDTH; 153 | 154 | dim3 grid_dim(grid_width, grid_height, 1); 155 | dim3 block_dim(BLOCK_WIDTH, BLOCK_WIDTH, 1); 156 | 157 | Threshold<<>>(threshold, width, height, std, 158 | depth, filtered_depth); 159 | 160 | CUDA_ERROR_CHECK(cudaDeviceSynchronize()); 161 | } 162 | 163 | } // namespace dip 164 | -------------------------------------------------------------------------------- /io/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(MODULE_NAME io) 2 | 3 | SET(MODULE_DEPENDENCIES 4 | common 5 | surface 6 | ) 7 | 8 | include(includes.cmake) 9 | 10 | foreach(DEPENDENT ${MODULE_DEPENDENCIES}) 11 | include(${PROJECT_SOURCE_DIR}/${DEPENDENT}/includes.cmake) 12 | 13 | set(INCLUDE_DIRS 14 | ${INCLUDE_DIRS} 15 | ${PROJECT_SOURCE_DIR}/${DEPENDENT}/include 16 | ) 17 | endforeach(DEPENDENT) 18 | 19 | set(INCLUDE_DIRS 20 | ${INCLUDE_DIRS} 21 | include/ 22 | ) 23 | 24 | include_directories(${INCLUDE_DIRS}) 25 | 26 | set(INCS 27 | include/dip/${MODULE_NAME}/hdf5dumper.h 28 | include/dip/${MODULE_NAME}/hdf5wrapper.h 29 | include/dip/${MODULE_NAME}/objfile.h 30 | ) 31 | 32 | set(SRCS 33 | src/hdf5dumper.cpp 34 | src/hdf5wrapper.cpp 35 | src/objfile.cpp 36 | ) 37 | 38 | set(LIBS 39 | ${HDF5_LIBRARIES} 40 | ${MODULE_DEPENDENCIES} 41 | ) 42 | 43 | add_library(${MODULE_NAME} ${SRCS} ${INCS}) 44 | target_link_libraries(${MODULE_NAME} ${LIBS}) 45 | 46 | if(WIN32) 47 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}/Release 48 | CONFIGURATIONS Release) 49 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}/Debug 50 | CONFIGURATIONS Debug) 51 | endif() 52 | 53 | if(UNIX) 54 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}) 55 | endif() 56 | 57 | install(FILES ${INCS} DESTINATION ${INCLUDE_INSTALL_DIR}/${MODULE_NAME}) 58 | -------------------------------------------------------------------------------- /io/include/dip/io/hdf5dumper.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef DIP_IO_HDF5DUMPER_H 30 | #define DIP_IO_HDF5DUMPER_H 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include 38 | #include 39 | 40 | namespace dip { 41 | 42 | typedef struct { 43 | char *name, *group; 44 | void *buffer; 45 | hsize_t *dimensions; 46 | int number_dimensions; 47 | hid_t datatype; 48 | } HDF5Data; 49 | 50 | class HDF5Dumper { 51 | public: 52 | HDF5Dumper(HDF5Wrapper *hdf5); 53 | ~HDF5Dumper(); 54 | 55 | void Write(const char *name, const char *group, const void *buffer, 56 | int bytes, const hsize_t *dimensions, int number_dimensions, 57 | hid_t datatype); 58 | 59 | friend void dump_data(HDF5Dumper *dumper); 60 | 61 | private: 62 | HDF5Wrapper *hdf5_; 63 | std::queue data_; 64 | 65 | std::thread worker_; 66 | std::mutex mtx_; 67 | std::condition_variable cv_; 68 | 69 | bool running_; 70 | 71 | DISALLOW_COPY_AND_ASSIGN(HDF5Dumper); 72 | }; 73 | 74 | } // namespace dip 75 | 76 | #endif // DIP_IO_HDF5DUMPER_H 77 | -------------------------------------------------------------------------------- /io/include/dip/io/objfile.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | // This class simplifies the task of reading, modifying, and creating OBJ 30 | // geometry files. 31 | 32 | #ifndef DIP_IO_OBJFILE_H 33 | #define DIP_IO_OBJFILE_H 34 | 35 | #include 36 | 37 | #include 38 | #include 39 | 40 | namespace dip { 41 | 42 | // OBJ file access modes. 43 | enum OBJ_MODES { 44 | READ_OBJ = 1, // Read an existing OBJ file. 45 | MODIFY_OBJ = 2, // Read/Write an existing OBJ file. 46 | CREATE_OBJ = 4, // Creates a new OBJ file. 47 | }; 48 | 49 | class OBJFile { 50 | public: 51 | // Opens a OBJ file. 52 | // file_name - Name of OBJ file. 53 | // mode - File access mode (READ_OBJ, MODIFY_OBJ, CREATE_OBJ). 54 | OBJFile(const char* file_name, int mode); 55 | ~OBJFile(); 56 | 57 | // Reads a mesh from the OBJ file. 58 | // mesh - Pointer to mesh data structure. 59 | // Returns zero when successful. 60 | int Read(Mesh *mesh) const; 61 | 62 | // Writes a mesh into the OBJ file. 63 | // mesh - Pointer to mesh data structure. 64 | // Returns zero when successful. 65 | int Write(Mesh *mesh) const; 66 | 67 | // Returns true if the OBJ file was successfully opened. 68 | bool enabled() const { return enabled_; } 69 | 70 | private: 71 | int mode_; 72 | bool enabled_; 73 | 74 | FILE *file_; 75 | 76 | DISALLOW_COPY_AND_ASSIGN(OBJFile); 77 | }; 78 | 79 | } // namespace dip 80 | 81 | #endif // DIP_IO_HDF5WRAPPER_H 82 | -------------------------------------------------------------------------------- /io/includes.cmake: -------------------------------------------------------------------------------- 1 | set(INCLUDE_DIRS 2 | ${INCLUDE_DIRS} 3 | ${HDF5_INCLUDE_DIRS} 4 | ) 5 | -------------------------------------------------------------------------------- /io/src/hdf5dumper.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | 31 | #include 32 | 33 | using namespace std; 34 | 35 | namespace dip { 36 | 37 | const int kMaxLength = 256; 38 | 39 | void dump_data(HDF5Dumper *dumper) { 40 | unique_lock lck(dumper->mtx_); 41 | while(dumper->running_) { 42 | while(dumper->data_.empty() && dumper->running_) dumper->cv_.wait(lck); 43 | 44 | while(!dumper->data_.empty()) { 45 | HDF5Data data = dumper->data_.front(); 46 | dumper->data_.pop(); 47 | 48 | lck.unlock(); 49 | dumper->hdf5_->Write(data.name, data.group, data.buffer, data.dimensions, 50 | data.number_dimensions, data.datatype); 51 | 52 | delete [] data.name; 53 | delete [] data.group; 54 | delete [] data.buffer; 55 | delete [] data.dimensions; 56 | lck.lock(); 57 | } 58 | } 59 | } 60 | 61 | HDF5Dumper::HDF5Dumper(HDF5Wrapper *hdf5) : hdf5_(hdf5), running_(true) { 62 | worker_ = thread(dump_data, this); 63 | } 64 | 65 | HDF5Dumper::~HDF5Dumper() { 66 | unique_lock lck(mtx_); 67 | running_ = false; 68 | cv_.notify_one(); 69 | 70 | lck.unlock(); 71 | worker_.join(); 72 | } 73 | 74 | void HDF5Dumper::Write(const char *name, const char *group, const void *buffer, 75 | int bytes, const hsize_t *dimensions, 76 | int number_dimensions, hid_t datatype) { 77 | HDF5Data data; 78 | 79 | data.name = new char[strnlen(name, kMaxLength) + 1]; 80 | memcpy(data.name, name, sizeof(char) * strnlen(name, kMaxLength)); 81 | data.name[strnlen(name, kMaxLength)] = '\0'; 82 | 83 | data.group = new char[strnlen(group, kMaxLength) + 1]; 84 | memcpy(data.group, group, sizeof(char) * strnlen(group, kMaxLength)); 85 | data.group[strnlen(group, kMaxLength)] = '\0'; 86 | 87 | data.buffer = new unsigned char[bytes]; 88 | memcpy(data.buffer, buffer, bytes); 89 | 90 | data.dimensions = new hsize_t[number_dimensions]; 91 | memcpy(data.dimensions, dimensions, sizeof(hsize_t) * number_dimensions); 92 | 93 | data.number_dimensions = number_dimensions; 94 | data.datatype = datatype; 95 | 96 | unique_lock lck(mtx_); 97 | data_.push(data); 98 | cv_.notify_one(); 99 | } 100 | 101 | } // namespace dip 102 | -------------------------------------------------------------------------------- /io/src/objfile.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | 31 | namespace dip { 32 | 33 | OBJFile::OBJFile(const char* file_name, int mode) : enabled_(false), 34 | file_(NULL) { 35 | // Open/Create OBJ File 36 | switch (mode) { 37 | case READ_OBJ: 38 | file_ = fopen(file_name, "r"); 39 | break; 40 | case MODIFY_OBJ: 41 | file_ = fopen(file_name, "a+"); 42 | break; 43 | case CREATE_OBJ: 44 | file_ = fopen(file_name, "w+"); 45 | break; 46 | } 47 | 48 | if (file_ != NULL) { 49 | mode_ = mode; 50 | enabled_ = true; 51 | } 52 | } 53 | 54 | OBJFile::~OBJFile() { 55 | if (enabled_) 56 | fclose(file_); 57 | } 58 | 59 | int OBJFile::Read(Mesh *mesh) const { 60 | if (enabled_) { 61 | fseek(file_, 0, SEEK_SET); 62 | 63 | char type; 64 | 65 | Vertex vertex; 66 | Face face; 67 | 68 | while(true) { 69 | if(fscanf(file_, "%c ", &type) != 1) 70 | break; 71 | 72 | if(type == 'v') { 73 | // Read Vertex 74 | fscanf(file_, "%f %f %f\n", &vertex.x, &vertex.y, &vertex.z); 75 | 76 | // Add to mesh 77 | mesh->AddVertex(vertex); 78 | } 79 | else if(type == 'f') { 80 | // Read Face 81 | fscanf(file_, "%d %d %d\n", &face.a, &face.b, &face.c); 82 | 83 | // Decrement vertex ids 84 | // With the OBJ format the first id 85 | // is one instead of zero. 86 | face.a--; 87 | face.b--; 88 | face.c--; 89 | 90 | // Add to mesh 91 | mesh->AddFace(face); 92 | } 93 | else { 94 | char junk; 95 | 96 | do { 97 | junk = fgetc(file_); 98 | } while((junk != '\n') && (junk != EOF)); 99 | } 100 | } 101 | 102 | return 0; 103 | } 104 | 105 | return -1; 106 | } 107 | 108 | int OBJFile::Write(Mesh *mesh) const { 109 | if (enabled_ && (mode_ & (MODIFY_OBJ | CREATE_OBJ))) { 110 | fseek(file_, 0, SEEK_END); 111 | 112 | for (int n = 0; n < mesh->VertexCount(); n++) { 113 | Vertex vertex = mesh->GetVertex(n); 114 | fprintf(file_, "v %f %f %f\n", vertex.x, vertex.y, vertex.z); 115 | } 116 | 117 | for (int n = 0; n < mesh->FaceCount(); n++) { 118 | Face face = mesh->GetFace(n); 119 | fprintf(file_, "f %d %d %d\n", face.a + 1, face.b + 1, face.c + 1); 120 | } 121 | 122 | return 0; 123 | } 124 | 125 | return -1; 126 | } 127 | 128 | } // namespace dip 129 | -------------------------------------------------------------------------------- /point_cloud/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(MODULE_NAME point_cloud) 2 | 3 | SET(MODULE_DEPENDENCIES 4 | common 5 | ) 6 | 7 | include(includes.cmake) 8 | 9 | foreach(DEPENDENT ${MODULE_DEPENDENCIES}) 10 | include(${PROJECT_SOURCE_DIR}/${DEPENDENT}/includes.cmake) 11 | 12 | set(INCLUDE_DIRS 13 | ${INCLUDE_DIRS} 14 | ${PROJECT_SOURCE_DIR}/${DEPENDENT}/include 15 | ) 16 | endforeach(DEPENDENT) 17 | 18 | set(INCLUDE_DIRS 19 | ${INCLUDE_DIRS} 20 | include/ 21 | ) 22 | 23 | include_directories(${INCLUDE_DIRS}) 24 | 25 | set(INCS 26 | include/dip/${MODULE_NAME}/backprojection.h 27 | include/dip/${MODULE_NAME}/centroid.h 28 | ) 29 | 30 | set(SRCS 31 | src/backprojection.cpp 32 | src/backprojection.cu 33 | src/centroid.cpp 34 | src/centroid.cu 35 | ) 36 | 37 | set(LIBS 38 | ${MODULE_DEPENDENCIES} 39 | ) 40 | 41 | cuda_add_library(${MODULE_NAME} ${SRCS} ${INCS}) 42 | target_link_libraries(${MODULE_NAME} ${LIBS}) 43 | 44 | if(WIN32) 45 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}/Release 46 | CONFIGURATIONS Release) 47 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}/Debug 48 | CONFIGURATIONS Debug) 49 | endif() 50 | 51 | if(UNIX) 52 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}) 53 | endif() 54 | 55 | install(FILES ${INCS} DESTINATION ${INCLUDE_INSTALL_DIR}/${MODULE_NAME}) 56 | -------------------------------------------------------------------------------- /point_cloud/include/dip/point_cloud/backprojection.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef DIP_POINT_CLOUD_BACKPROJECTION_H 30 | #define DIP_POINT_CLOUD_BACKPROJECTION_H 31 | 32 | #include 33 | #include 34 | 35 | namespace dip { 36 | 37 | class BackProjection { 38 | public: 39 | BackProjection() {} 40 | ~BackProjection() {} 41 | 42 | void Run(int width, int height, float fx, float fy, float cx, float cy, 43 | const Depth *depth, Vertices vertices, Normals normals); 44 | 45 | private: 46 | DISALLOW_COPY_AND_ASSIGN(BackProjection); 47 | }; 48 | 49 | } // namespace dip 50 | 51 | #endif // DIP_POINT_CLOUD_BACKPROJECTION_H -------------------------------------------------------------------------------- /point_cloud/include/dip/point_cloud/centroid.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef DIP_POINT_CLOUD_CENTROID_H 30 | #define DIP_POINT_CLOUD_CENTROID_H 31 | 32 | #include 33 | #include 34 | 35 | namespace dip { 36 | 37 | class Centroid { 38 | public: 39 | Centroid(); 40 | ~Centroid(); 41 | 42 | Vertex Run(int width, int height, Vertices vertices); 43 | 44 | private: 45 | float *buffer_[4]; 46 | int bytes_; 47 | 48 | DISALLOW_COPY_AND_ASSIGN(Centroid); 49 | }; 50 | 51 | } // namespace dip 52 | 53 | #endif // DIP_POINT_CLOUD_CENTROID_H 54 | -------------------------------------------------------------------------------- /point_cloud/includes.cmake: -------------------------------------------------------------------------------- 1 | set(INCLUDE_DIRS 2 | ${INCLUDE_DIRS} 3 | ) -------------------------------------------------------------------------------- /point_cloud/src/backprojection.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | 31 | namespace dip { 32 | 33 | extern void BackProjectionKernel(int width, int height, float fx, float fy, 34 | float cx, float cy, const Depth *depth, 35 | Vertices vertices, Normals normals); 36 | 37 | void BackProjection::Run(int width, int height, float fx, float fy, 38 | float cx, float cy, const Depth *depth, 39 | Vertices vertices, Normals normals) { 40 | BackProjectionKernel(width, height, fx, fy, cx, cy, depth, vertices, normals); 41 | } 42 | 43 | } // namespace dip 44 | -------------------------------------------------------------------------------- /point_cloud/src/backprojection.cu: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | #include 31 | 32 | #define BLOCK_WIDTH 16 33 | 34 | namespace dip { 35 | 36 | __global__ void ComputeVertices(int width, int height, float fx, float fy, 37 | float cx, float cy, const Depth *depth, 38 | Vertices vertices) { 39 | // Get Block and Thread Id 40 | int bx = blockIdx.x; int by = blockIdx.y; 41 | int tx = threadIdx.x; int ty = threadIdx.y; 42 | 43 | // Calculate Row & Column 44 | int col = tx + bx * BLOCK_WIDTH; 45 | int row = ty + by * BLOCK_WIDTH; 46 | 47 | // Compute Vertices 48 | if ((col < width) && (row < height)) { 49 | int i = col + row * width; 50 | 51 | Depth depth_value = depth[i]; 52 | 53 | if (depth_value > 0) { 54 | vertices.x[i] = depth_value * ((col - cx) / fx); 55 | vertices.y[i] = depth_value * ((row - cy) / fy); 56 | vertices.z[i] = depth_value; 57 | } 58 | else { 59 | vertices.x[i] = 0.0f; 60 | vertices.y[i] = 0.0f; 61 | vertices.z[i] = 0.0f; 62 | } 63 | } 64 | } 65 | 66 | __global__ void ComputeNormals(int width, int height, Vertices vertices, 67 | Normals normals) { 68 | // Allocate Shared Memory 69 | __shared__ Vertex vs[BLOCK_WIDTH][BLOCK_WIDTH]; 70 | 71 | // Get Block and Thread Id 72 | int bx = blockIdx.x; int by = blockIdx.y; 73 | int tx = threadIdx.x; int ty = threadIdx.y; 74 | 75 | // Calculate Row & Column 76 | int col = tx + bx * BLOCK_WIDTH; 77 | int row = ty + by * BLOCK_WIDTH; 78 | 79 | // Cooperative Load of the Tile 80 | if ((col < width) && (row < height)) { 81 | vs[ty][tx].x = vertices.x[col + row * width]; 82 | vs[ty][tx].y = vertices.y[col + row * width]; 83 | vs[ty][tx].z = vertices.z[col + row * width]; 84 | } 85 | else { 86 | vs[ty][tx].x = 0.0f; 87 | vs[ty][tx].y = 0.0f; 88 | vs[ty][tx].z = 0.0f; 89 | } 90 | 91 | // Sync Threads in Block 92 | __syncthreads(); 93 | 94 | // Compute Normals 95 | if ((col < width) && (row < height)) { 96 | int i = col + row * width; 97 | 98 | // Load Center Vertex 99 | Vertex center; 100 | center.x = vs[ty][tx].x; 101 | center.y = vs[ty][tx].y; 102 | center.z = vs[ty][tx].z; 103 | 104 | // Load Neighboring Vertices 105 | Vertex west, north; 106 | if ((col - 1) >= 0) { 107 | if ((tx - 1) >= 0) { 108 | west.x = vs[ty][tx - 1].x; 109 | west.y = vs[ty][tx - 1].y; 110 | west.z = vs[ty][tx - 1].z; 111 | } 112 | else { 113 | west.x = vertices.x[i - 1]; 114 | west.y = vertices.y[i - 1]; 115 | west.z = vertices.z[i - 1]; 116 | } 117 | } 118 | else { 119 | west.x = 0.0f; 120 | west.y = 0.0f; 121 | west.z = 0.0f; 122 | } 123 | 124 | if ((row - 1) >= 0) { 125 | if ((ty - 1) >= 0) { 126 | north.x = vs[ty - 1][tx].x; 127 | north.y = vs[ty - 1][tx].y; 128 | north.z = vs[ty - 1][tx].z; 129 | } 130 | else { 131 | north.x = vertices.x[i - width]; 132 | north.y = vertices.y[i - width]; 133 | north.z = vertices.z[i - width]; 134 | } 135 | } 136 | else { 137 | north.x = 0.0f; 138 | north.y = 0.0f; 139 | north.z = 0.0f; 140 | } 141 | 142 | if((center.z > 0.0f) && (west.z > 0.0f) && (north.z > 0.0f)) { 143 | // Compute Vectors 144 | Vector left, up; 145 | left.x = west.x - center.x; 146 | left.y = west.y - center.y; 147 | left.z = west.z - center.z; 148 | 149 | up.x = north.x - center.x; 150 | up.y = north.y - center.y; 151 | up.z = north.z - center.z; 152 | 153 | // Perform Cross Product 154 | Vector normal; 155 | normal.x = left.y * up.z - up.y * left.z; 156 | normal.y = up.x * left.z - left.x * up.z; 157 | normal.z = left.x * up.y - up.x * left.y; 158 | 159 | // Normalize 160 | float inorm = rsqrt(normal.x * normal.x + normal.y * normal.y + 161 | normal.z * normal.z); 162 | 163 | normals.x[i] = normal.x * inorm; 164 | normals.y[i] = normal.y * inorm; 165 | normals.z[i] = normal.z * inorm; 166 | } 167 | else { 168 | normals.x[i] = 0.0f; 169 | normals.y[i] = 0.0f; 170 | normals.z[i] = 0.0f; 171 | } 172 | } 173 | } 174 | 175 | void BackProjectionKernel(int width, int height, float fx, float fy, 176 | float cx, float cy, const Depth *depth, 177 | Vertices vertices, Normals normals) { 178 | // Launch Back Projection Kernel 179 | int grid_width = (width + (BLOCK_WIDTH - 1)) / BLOCK_WIDTH; 180 | int grid_height = (height + (BLOCK_WIDTH - 1)) / BLOCK_WIDTH; 181 | 182 | dim3 grid_dim(grid_width, grid_height, 1); 183 | dim3 block_dim(BLOCK_WIDTH, BLOCK_WIDTH, 1); 184 | 185 | ComputeVertices<<>>(width, height, fx, fy, cx, cy, depth, 186 | vertices); 187 | 188 | CUDA_ERROR_CHECK(cudaDeviceSynchronize()); 189 | 190 | ComputeNormals<<>>(width, height, vertices, normals); 191 | 192 | CUDA_ERROR_CHECK(cudaDeviceSynchronize()); 193 | } 194 | 195 | } // namespace dip 196 | -------------------------------------------------------------------------------- /point_cloud/src/centroid.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | namespace dip { 35 | 36 | extern void CentroidKernel(int width, int height, Vertices vertices, 37 | float *buffer[4]); 38 | 39 | Centroid::Centroid() : bytes_(0) { 40 | for (int n = 0; n < 4; n++) 41 | buffer_[n] = NULL; 42 | } 43 | 44 | Centroid::~Centroid() { 45 | for (int n = 0; n < 4; n++) { 46 | if (buffer_[n] != NULL) 47 | Deallocate((void*)buffer_[n]); 48 | } 49 | } 50 | 51 | Vertex Centroid::Run(int width, int height, Vertices vertices) { 52 | int required_bytes = sizeof(float) * width * height; 53 | 54 | if (bytes_ < required_bytes) { 55 | bytes_ = required_bytes; 56 | 57 | for (int n = 0; n < 4; n++) { 58 | if (buffer_[n] != NULL) 59 | Deallocate((void*)buffer_[n]); 60 | 61 | Allocate((void**)&(buffer_[n]), bytes_); 62 | } 63 | } 64 | 65 | CentroidKernel(width, height, vertices, buffer_); 66 | 67 | // Compute Centroid 68 | Vertex center; 69 | int count; 70 | 71 | center.x = Reduce(width * height, buffer_[0]); 72 | center.y = Reduce(width * height, buffer_[1]); 73 | center.z = Reduce(width * height, buffer_[2]); 74 | count = Reduce(width * height, buffer_[3]); 75 | 76 | center.x /= count; 77 | center.y /= count; 78 | center.z /= count; 79 | 80 | return center; 81 | } 82 | 83 | } // namespace dip 84 | -------------------------------------------------------------------------------- /point_cloud/src/centroid.cu: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | #include 31 | 32 | #define BLOCK_WIDTH 16 33 | 34 | namespace dip { 35 | 36 | __constant__ float *buffer_ptr[4]; 37 | 38 | __global__ void Initialize(int width, int height, Vertices vertices) { 39 | // Get Block and Thread Id 40 | int bx = blockIdx.x; int by = blockIdx.y; 41 | int tx = threadIdx.x; int ty = threadIdx.y; 42 | 43 | // Calculate Row & Column 44 | int col = tx + bx * BLOCK_WIDTH; 45 | int row = ty + by * BLOCK_WIDTH; 46 | 47 | if ((col < width) && (row < height)) { 48 | int i = col + row * width; 49 | 50 | Vertex vertex; 51 | vertex.x = vertices.x[i]; 52 | vertex.y = vertices.y[i]; 53 | vertex.z = vertices.z[i]; 54 | 55 | if (vertex.z > 0.0f) { 56 | buffer_ptr[0][i] = vertex.x; 57 | buffer_ptr[1][i] = vertex.y; 58 | buffer_ptr[2][i] = vertex.z; 59 | buffer_ptr[3][i] = 1.0f; 60 | } 61 | else { 62 | buffer_ptr[0][i] = 0.0f; 63 | buffer_ptr[1][i] = 0.0f; 64 | buffer_ptr[2][i] = 0.0f; 65 | buffer_ptr[3][i] = 0.0f; 66 | } 67 | } 68 | } 69 | 70 | void CentroidKernel(int width, int height, Vertices vertices, 71 | float *buffer[4]) { 72 | // Copy buffer pointers to Constant Memory 73 | CUDA_ERROR_CHECK(cudaMemcpyToSymbol(buffer_ptr, buffer, sizeof(float*) * 4)); 74 | 75 | // Launch Centroid Kernel 76 | int grid_width = (width + (BLOCK_WIDTH - 1)) / BLOCK_WIDTH; 77 | int grid_height = (height + (BLOCK_WIDTH - 1)) / BLOCK_WIDTH; 78 | 79 | dim3 grid_dim(grid_width, grid_height, 1); 80 | dim3 block_dim(BLOCK_WIDTH, BLOCK_WIDTH, 1); 81 | 82 | Initialize<<>>(width, height, vertices); 83 | 84 | CUDA_ERROR_CHECK(cudaDeviceSynchronize()); 85 | } 86 | 87 | } // namespace dip 88 | -------------------------------------------------------------------------------- /projects/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(MODULE_NAME projects) 2 | 3 | SET(MODULE_DEPENDENCIES 4 | common 5 | filters 6 | point_cloud 7 | sampling 8 | segmentation 9 | surface 10 | registration 11 | visualization 12 | ) 13 | 14 | include(includes.cmake) 15 | 16 | foreach(DEPENDENT ${MODULE_DEPENDENCIES}) 17 | include(${PROJECT_SOURCE_DIR}/${DEPENDENT}/includes.cmake) 18 | 19 | set(INCLUDE_DIRS 20 | ${INCLUDE_DIRS} 21 | ${PROJECT_SOURCE_DIR}/${DEPENDENT}/include 22 | ) 23 | endforeach(DEPENDENT) 24 | 25 | set(INCLUDE_DIRS 26 | ${INCLUDE_DIRS} 27 | include/ 28 | ) 29 | 30 | include_directories(${INCLUDE_DIRS}) 31 | 32 | set(INCS 33 | include/dip/${MODULE_NAME}/facemodeling.h 34 | include/dip/${MODULE_NAME}/objectmodeling.h 35 | ) 36 | 37 | set(SRCS 38 | src/facemodeling.cpp 39 | src/objectmodeling.cpp 40 | ) 41 | 42 | set(LIBS 43 | ${MODULE_DEPENDENCIES} 44 | ) 45 | 46 | add_library(${MODULE_NAME} ${SRCS} ${INCS}) 47 | target_link_libraries(${MODULE_NAME} ${LIBS}) 48 | 49 | if(WIN32) 50 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}/Release 51 | CONFIGURATIONS Release) 52 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}/Debug 53 | CONFIGURATIONS Debug) 54 | endif() 55 | 56 | if(UNIX) 57 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}) 58 | endif() 59 | 60 | install(FILES ${INCS} DESTINATION ${INCLUDE_INSTALL_DIR}/${MODULE_NAME}) 61 | -------------------------------------------------------------------------------- /projects/includes.cmake: -------------------------------------------------------------------------------- 1 | set(INCLUDE_DIRS 2 | ${INCLUDE_DIRS} 3 | ${EIGEN_INCLUDE_DIRS} 4 | ) 5 | -------------------------------------------------------------------------------- /registration/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(MODULE_NAME registration) 2 | 3 | SET(MODULE_DEPENDENCIES 4 | common 5 | ) 6 | 7 | include(includes.cmake) 8 | 9 | foreach(DEPENDENT ${MODULE_DEPENDENCIES}) 10 | include(${PROJECT_SOURCE_DIR}/${DEPENDENT}/includes.cmake) 11 | 12 | set(INCLUDE_DIRS 13 | ${INCLUDE_DIRS} 14 | ${PROJECT_SOURCE_DIR}/${DEPENDENT}/include 15 | ) 16 | endforeach(DEPENDENT) 17 | 18 | set(INCLUDE_DIRS 19 | ${INCLUDE_DIRS} 20 | include/ 21 | ) 22 | 23 | include_directories(${INCLUDE_DIRS}) 24 | 25 | set(INCS 26 | include/dip/${MODULE_NAME}/icp.h 27 | ) 28 | 29 | set(SRCS 30 | src/icp.cpp 31 | src/icp.cu 32 | ) 33 | 34 | set(LIBS 35 | ${MODULE_DEPENDENCIES} 36 | ) 37 | 38 | cuda_add_library(${MODULE_NAME} ${SRCS} ${INCS}) 39 | target_link_libraries(${MODULE_NAME} ${LIBS}) 40 | 41 | if(WIN32) 42 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}/Release 43 | CONFIGURATIONS Release) 44 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}/Debug 45 | CONFIGURATIONS Debug) 46 | endif() 47 | 48 | if(UNIX) 49 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}) 50 | endif() 51 | 52 | install(FILES ${INCS} DESTINATION ${INCLUDE_INSTALL_DIR}/${MODULE_NAME}) 53 | -------------------------------------------------------------------------------- /registration/include/dip/registration/icp.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef DIP_REGISTRATION_ICP_H 30 | #define DIP_REGISTRATION_ICP_H 31 | 32 | #include 33 | 34 | #include 35 | #include 36 | 37 | namespace dip { 38 | 39 | class ICP { 40 | public: 41 | ICP(); 42 | ~ICP(); 43 | 44 | int Run(int max_iterations, 45 | int min_correspondences_begin, int min_correspondences_end, 46 | float distance_threshold_begin, float distance_threshold_end, 47 | float normal_threshold_begin, float normal_threshold_end, 48 | float max_rotation, float max_translation, 49 | float fx, float fy, float cx, float cy, 50 | int src_width, int src_height, 51 | int dst_width, int dst_height, 52 | Vertices src_vertices, Normals src_normals, 53 | Vertices dst_vertices, Normals dst_normals, 54 | const Eigen::Matrix4f &previous_transformation, 55 | Eigen::Matrix4f &transformation); 56 | 57 | private: 58 | Eigen::Matrix4f ConstructTransform(Eigen::VectorXf &x); 59 | 60 | float *buffer_[29]; 61 | int bytes_; 62 | 63 | DISALLOW_COPY_AND_ASSIGN(ICP); 64 | }; 65 | 66 | } // namespace dip 67 | 68 | #endif // DIP_REGISTRATION_ICP_H 69 | -------------------------------------------------------------------------------- /registration/includes.cmake: -------------------------------------------------------------------------------- 1 | set(INCLUDE_DIRS 2 | ${INCLUDE_DIRS} 3 | ${EIGEN_INCLUDE_DIRS} 4 | ) 5 | -------------------------------------------------------------------------------- /sampling/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(MODULE_NAME sampling) 2 | 3 | SET(MODULE_DEPENDENCIES 4 | common 5 | ) 6 | 7 | include(includes.cmake) 8 | 9 | foreach(DEPENDENT ${MODULE_DEPENDENCIES}) 10 | include(${PROJECT_SOURCE_DIR}/${DEPENDENT}/includes.cmake) 11 | 12 | set(INCLUDE_DIRS 13 | ${INCLUDE_DIRS} 14 | ${PROJECT_SOURCE_DIR}/${DEPENDENT}/include 15 | ) 16 | endforeach(DEPENDENT) 17 | 18 | set(INCLUDE_DIRS 19 | ${INCLUDE_DIRS} 20 | include/ 21 | ) 22 | 23 | include_directories(${INCLUDE_DIRS}) 24 | 25 | set(INCS 26 | include/dip/${MODULE_NAME}/downsample.h 27 | ) 28 | 29 | set(SRCS 30 | src/downsample.cpp 31 | src/downsample.cu 32 | ) 33 | 34 | set(LIBS 35 | ${MODULE_DEPENDENCIES} 36 | ) 37 | 38 | cuda_add_library(${MODULE_NAME} ${SRCS} ${INCS}) 39 | target_link_libraries(${MODULE_NAME} ${LIBS}) 40 | 41 | if(WIN32) 42 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}/Release 43 | CONFIGURATIONS Release) 44 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}/Debug 45 | CONFIGURATIONS Debug) 46 | endif() 47 | 48 | if(UNIX) 49 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}) 50 | endif() 51 | 52 | install(FILES ${INCS} DESTINATION ${INCLUDE_INSTALL_DIR}/${MODULE_NAME}) 53 | -------------------------------------------------------------------------------- /sampling/include/dip/sampling/downsample.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef DIP_SAMPLING_DOWNSAMPLE_H 30 | #define DIP_SAMPLING_DOWNSAMPLE_H 31 | 32 | #include 33 | #include 34 | 35 | namespace dip { 36 | 37 | class Downsample { 38 | public: 39 | Downsample() {} 40 | ~Downsample() {} 41 | 42 | void Run(int factor, int max_difference, int width, int height, 43 | int downsampled_width, int downsampled_height, 44 | const Depth *depth, Depth *downsampled_depth); 45 | 46 | private: 47 | DISALLOW_COPY_AND_ASSIGN(Downsample); 48 | }; 49 | 50 | } // namespace dip 51 | 52 | #endif // DIP_SAMPLING_DOWNSAMPLE_H -------------------------------------------------------------------------------- /sampling/includes.cmake: -------------------------------------------------------------------------------- 1 | set(INCLUDE_DIRS 2 | ${INCLUDE_DIRS} 3 | ) -------------------------------------------------------------------------------- /sampling/src/downsample.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | 31 | namespace dip { 32 | 33 | extern void DownsampleKernel(int factor, int max_difference, 34 | int width, int height, 35 | int downsampled_width, int downsampled_height, 36 | const Depth *depth, Depth *downsampled_depth); 37 | 38 | void Downsample::Run(int factor, int max_difference, int width, int height, 39 | int downsampled_width, int downsampled_height, 40 | const Depth *depth, Depth *downsampled_depth) { 41 | DownsampleKernel(factor, max_difference, width, height, 42 | downsampled_width, downsampled_height, 43 | depth, downsampled_depth); 44 | } 45 | 46 | } // namespace dip 47 | -------------------------------------------------------------------------------- /sampling/src/downsample.cu: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | #include 31 | 32 | #define BLOCK_WIDTH 16 33 | 34 | namespace dip { 35 | 36 | __global__ void DownsampleDepth(int factor, int max_difference, 37 | int width, int height, 38 | int downsampled_width, int downsampled_height, 39 | const Depth *depth, Depth *downsampled_depth) { 40 | // Get Block and Thread Id 41 | int bx = blockIdx.x; int by = blockIdx.y; 42 | int tx = threadIdx.x; int ty = threadIdx.y; 43 | 44 | // Calculate Row & Column 45 | int output_col = tx + bx * BLOCK_WIDTH; 46 | int output_row = ty + by * BLOCK_WIDTH; 47 | int input_col = output_col << factor; 48 | int input_row = output_row << factor; 49 | 50 | // Perform block average and downsample 51 | if ((output_col < downsampled_width) && (output_row < downsampled_height)) { 52 | if ((input_col < width) && (input_row < height)) { 53 | float center_depth = depth[input_col + input_row * width]; 54 | 55 | // Block average on input depth image 56 | int size = 1 << factor; 57 | float h = 0.0f, k = 0.0f; 58 | 59 | for (int dy = 0; dy < size; dy++) { 60 | for (int dx = 0; dx < size; dx++) { 61 | int x = input_col + dx; 62 | int y = input_row + dy; 63 | 64 | if ((x < width) && (y < height)) { 65 | float current_depth = depth[x + y * width]; 66 | float difference = fabs(current_depth - center_depth); 67 | 68 | if(difference < max_difference) { 69 | h += current_depth; 70 | k++; 71 | } 72 | } 73 | } 74 | } 75 | 76 | // Downsample depth image 77 | downsampled_depth[output_col + output_row * downsampled_width] = h / k; 78 | } 79 | } 80 | } 81 | 82 | void DownsampleKernel(int factor, int max_difference, 83 | int width, int height, 84 | int downsampled_width, int downsampled_height, 85 | const Depth *depth, Depth *downsampled_depth) { 86 | // Launch Downsample Kernel 87 | int grid_width = (downsampled_width + (BLOCK_WIDTH - 1)) / BLOCK_WIDTH; 88 | int grid_height = (downsampled_height + (BLOCK_WIDTH - 1)) / BLOCK_WIDTH; 89 | 90 | dim3 grid_dim(grid_width, grid_height, 1); 91 | dim3 block_dim(BLOCK_WIDTH, BLOCK_WIDTH, 1); 92 | 93 | DownsampleDepth<<>>(factor, max_difference, 94 | width, height, 95 | downsampled_width, 96 | downsampled_height, 97 | depth, downsampled_depth); 98 | 99 | CUDA_ERROR_CHECK(cudaDeviceSynchronize()); 100 | } 101 | 102 | } // namespace dip 103 | -------------------------------------------------------------------------------- /segmentation/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(MODULE_NAME segmentation) 2 | 3 | SET(MODULE_DEPENDENCIES 4 | common 5 | ) 6 | 7 | include(includes.cmake) 8 | 9 | foreach(DEPENDENT ${MODULE_DEPENDENCIES}) 10 | include(${PROJECT_SOURCE_DIR}/${DEPENDENT}/includes.cmake) 11 | 12 | set(INCLUDE_DIRS 13 | ${INCLUDE_DIRS} 14 | ${PROJECT_SOURCE_DIR}/${DEPENDENT}/include 15 | ) 16 | endforeach(DEPENDENT) 17 | 18 | set(INCLUDE_DIRS 19 | ${INCLUDE_DIRS} 20 | include/ 21 | ) 22 | 23 | include_directories(${INCLUDE_DIRS}) 24 | 25 | set(INCS 26 | include/dip/${MODULE_NAME}/connectedcomponents.h 27 | include/dip/${MODULE_NAME}/facemasker.h 28 | include/dip/${MODULE_NAME}/headsegmenter.h 29 | ) 30 | 31 | set(SRCS 32 | src/connectedcomponents.cpp 33 | src/facemasker.cpp 34 | src/headsegmenter.cpp 35 | ) 36 | 37 | set(LIBS 38 | ${OpenCV_LIBRARIES} 39 | ${MODULE_DEPENDENCIES} 40 | ) 41 | 42 | add_library(${MODULE_NAME} ${SRCS} ${INCS}) 43 | target_link_libraries(${MODULE_NAME} ${LIBS}) 44 | 45 | if(WIN32) 46 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}/Release 47 | CONFIGURATIONS Release) 48 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}/Debug 49 | CONFIGURATIONS Debug) 50 | endif() 51 | 52 | if(UNIX) 53 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}) 54 | endif() 55 | 56 | install(FILES ${INCS} DESTINATION ${INCLUDE_INSTALL_DIR}/${MODULE_NAME}) 57 | -------------------------------------------------------------------------------- /segmentation/include/dip/segmentation/connectedcomponents.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | // Identify connected components within a depth image. Two neighboring pixels 30 | // are considered connected when the difference between their depth values is 31 | // below a threshold. Connected component labeling uses a disjoint-set data 32 | // structure and a union-find algorithm to efficiently determine connected 33 | // components. 34 | 35 | #ifndef DIP_SEGMENTATION_CONNECTEDCOMPONENTS_H 36 | #define DIP_SEGMENTATION_CONNECTEDCOMPONENTS_H 37 | 38 | #include 39 | 40 | #include 41 | #include 42 | 43 | namespace dip { 44 | 45 | // Component structure (disjoint-set) 46 | typedef struct { 47 | int parent; // Parent label 48 | int size; // Number of pixels in component 49 | int mean; // Average depth of component 50 | bool root; // Root component flag 51 | 52 | // Initialize Component with a single pixel. 53 | // label - Unique set label. 54 | // depth - Depth value of pixel. 55 | void init(int label, int depth) { 56 | parent = label; 57 | size = 1; 58 | mean = depth; 59 | root = true; 60 | } 61 | } CC; 62 | 63 | class ConnectedComponents { 64 | public: 65 | ConnectedComponents() {} 66 | ~ConnectedComponents() {} 67 | 68 | // Performs connected component labeling. 69 | // max_difference - Maximum difference between neighbor depth values to be 70 | // considered connected. 71 | // width & height - Dimensions of depth image. 72 | // depth - Depth image. 73 | // component - Vector of all components (including non-root 74 | // components) within the depth image. 75 | // labels - Label map used to identify which connected component a 76 | // pixel belongs to. Label map should have the same 77 | // dimensions as the depth image. 78 | void Run(int max_difference, int width, int height, const Depth *depth, 79 | std::vector &components, int *labels); 80 | 81 | private: 82 | // Finds parent component of disjoint-set. 83 | // component - Vector of all components. 84 | // a - Label of child component. 85 | // Returns the label of the parent component. If the child component is 86 | // the parent, then the returned label equals a. 87 | int Find(std::vector &components, int a); 88 | 89 | // Merges two components. 90 | // component - Vector of all components. 91 | // a & b - Labels of the two components to be merged. 92 | // Returns the label of the parent component after the merge. 93 | int Merge(std::vector &components, int a, int b); 94 | 95 | DISALLOW_COPY_AND_ASSIGN(ConnectedComponents); 96 | }; 97 | 98 | } // namespace dip 99 | 100 | #endif // DIP_SEGMENTATION_CONNECTEDCOMPONENTS_H 101 | -------------------------------------------------------------------------------- /segmentation/include/dip/segmentation/facemasker.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef DIP_SEGMENTATION_FACEMASKER_H 30 | #define DIP_SEGMENTATION_FACEMASKER_H 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | namespace dip { 37 | 38 | class FaceMasker : public cv::CascadeClassifier::MaskGenerator { 39 | public: 40 | FaceMasker() : valid_mask_(NULL), head_mask_(NULL), depth_integral_(NULL), 41 | valid_integral_(NULL), head_integral_(NULL), 42 | min_sizes_(NULL), max_sizes_(NULL), 43 | size_(0), frame_(0), scale_(0) {} 44 | ~FaceMasker(); 45 | 46 | void Run(int min_depth, int min_pixels, int open_size, 47 | int head_width, int head_height, int head_depth, 48 | int face_size, int extended_size, int window_size, 49 | int width, int height, float focal_length, 50 | const Depth *depth, Color *color); 51 | 52 | // MaskGenerator functions. 53 | cv::Mat generateMask(const cv::Mat& src); 54 | void initializeMask(const cv::Mat& src) {} 55 | 56 | private: 57 | void Integral(int width, int height, bool *valid, const Depth *depth, 58 | int *integral); 59 | void Integral(int width, int height, bool flag, const bool *mask, 60 | int *integral); 61 | 62 | void Erode(int width, int height, int half_window, const int *integral, 63 | bool *mask); 64 | void Dilate(int width, int height, int half_window, const int *integral, 65 | bool *mask); 66 | 67 | int Sum(int width, int height, int left, int right, int top, int bottom, 68 | const int *integral); 69 | int Mean(int width, int height, int left, int right, int top, int bottom, 70 | const int *value_integral, const int *valid_integral); 71 | 72 | bool *valid_mask_, *head_mask_; 73 | int *depth_integral_, *valid_integral_, *head_integral_; 74 | 75 | float *min_sizes_, *max_sizes_; 76 | 77 | int window_size_; 78 | int width_, height_, size_; 79 | int frame_, scale_; 80 | 81 | DISALLOW_COPY_AND_ASSIGN(FaceMasker); 82 | }; 83 | 84 | } // namespace dip 85 | 86 | #endif // DIP_SEGMENTATION_FACEMASKER_H 87 | -------------------------------------------------------------------------------- /segmentation/include/dip/segmentation/headsegmenter.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef DIP_SEGMENTATION_HEADSEGMENTER_H 30 | #define DIP_SEGMENTATION_HEADSEGMENTER_H 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | namespace dip { 37 | 38 | class HeadSegmenter { 39 | public: 40 | HeadSegmenter() : labels_(NULL), column_histogram_(NULL), 41 | row_histogram_(NULL), width_(0), height_(0), size_(0) {} 42 | ~HeadSegmenter(); 43 | 44 | int Run(int min_depth, int max_depth, int max_difference, 45 | int min_width, int min_height, int max_width, int max_height, 46 | float fx, float fy, int width, int height, const Depth *depth, 47 | Depth *segmented_depth); 48 | 49 | private: 50 | ConnectedComponents connected_components_; 51 | std::vector components_; 52 | int *labels_; 53 | 54 | int *column_histogram_; 55 | int *row_histogram_; 56 | 57 | int width_, height_, size_; 58 | 59 | DISALLOW_COPY_AND_ASSIGN(HeadSegmenter); 60 | }; 61 | 62 | } // namespace dip 63 | 64 | #endif // DIP_SEGMENTATION_HEADSEGMENTER_H 65 | -------------------------------------------------------------------------------- /segmentation/includes.cmake: -------------------------------------------------------------------------------- 1 | set(INCLUDE_DIRS 2 | ${INCLUDE_DIRS} 3 | ${OpenCV_INCLUDE_DIRS} 4 | ) -------------------------------------------------------------------------------- /segmentation/src/connectedcomponents.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | 31 | #include 32 | 33 | namespace dip { 34 | 35 | void ConnectedComponents::Run(int max_difference, int width, int height, 36 | const Depth *depth, std::vector &components, 37 | int *labels) { 38 | // Determine Connected Components 39 | components.clear(); 40 | 41 | // Initialize First Component 42 | labels[0] = 0; 43 | 44 | CC component; 45 | component.init(0, depth[0]); 46 | components.push_back(component); 47 | 48 | // Run Connected Component on First Row 49 | for (int x = 1; x < width; x++) { 50 | int i = x; 51 | 52 | // Initialize Label 53 | labels[i] = -1; 54 | 55 | // Check West 56 | if (DIFF(depth[i], depth[i - 1]) < max_difference) { 57 | // Current Pixel belongs to Neighbor's Component 58 | labels[i] = Find(components, labels[i - 1]); 59 | } 60 | 61 | // Initialize Component 62 | if (labels[i] == -1) { 63 | labels[i] = components.size(); 64 | 65 | component.init(components.size(), depth[i]); 66 | components.push_back(component); 67 | } 68 | else { 69 | components.at(labels[i]).size++; 70 | components.at(labels[i]).mean += depth[i]; 71 | } 72 | } 73 | 74 | // Run Connected Component on First Column 75 | for (int y = 1; y < height; y++) { 76 | int i = y * width; 77 | 78 | // Initialize Label 79 | labels[i] = -1; 80 | 81 | // Check North 82 | if (DIFF(depth[i], depth[i - width]) < max_difference) { 83 | // Current Pixel belongs to Neighbor's Component 84 | labels[i] = Find(components, labels[i - width]); 85 | } 86 | 87 | // Initialize Component 88 | if (labels[i] == -1) { 89 | labels[i] = components.size(); 90 | 91 | component.init(components.size(), depth[i]); 92 | components.push_back(component); 93 | } 94 | else { 95 | components.at(labels[i]).size++; 96 | components.at(labels[i]).mean += depth[i]; 97 | } 98 | } 99 | 100 | // Run Connected Component on the Rest of the Frame 101 | for (int y = 1; y < height; y++) { 102 | for (int x = 1; x < width; x++) { 103 | int i = x + y * width; 104 | 105 | // Initialize Label 106 | labels[i] = -1; 107 | 108 | // Check West 109 | if (DIFF(depth[i], depth[i - 1]) < max_difference) { 110 | // Current Pixel belongs to Neighbor's Component 111 | labels[i] = Find(components, labels[i - 1]); 112 | } 113 | 114 | // Check North 115 | if (DIFF(depth[i], depth[i - width]) < max_difference) { 116 | if (labels[i] != -1) { 117 | if (labels[i] != Find(components, labels[i - width])) 118 | labels[i] = Merge(components, labels[i], labels[i - width]); 119 | } 120 | else { 121 | labels[i] = Find(components, labels[i - width]); 122 | } 123 | } 124 | 125 | // Initialize Component 126 | if (labels[i] == -1) { 127 | labels[i] = components.size(); 128 | 129 | component.init(components.size(), depth[i]); 130 | components.push_back(component); 131 | 132 | } 133 | else { 134 | components.at(labels[i]).size++; 135 | components.at(labels[i]).mean += depth[i]; 136 | } 137 | } 138 | } 139 | 140 | // Update Components 141 | for (unsigned int n = 0; n < components.size(); n++) { 142 | if (components.at(n).root) 143 | components.at(n).mean /= components.at(n).size; 144 | else 145 | components.at(n).parent = Find(components, components.at(n).parent); 146 | } 147 | 148 | // Update Labels 149 | for (int n = 0; n < (width * height); n++) 150 | labels[n] = components.at(labels[n]).parent; 151 | } 152 | 153 | int ConnectedComponents::Find(std::vector &components, int a) { 154 | while (components.at(a).parent != a) 155 | a = components.at(a).parent; 156 | 157 | return a; 158 | } 159 | 160 | int ConnectedComponents::Merge(std::vector &components, int a, int b) { 161 | a = Find(components, a); 162 | b = Find(components, b); 163 | 164 | if (a < b) { 165 | components.at(b).parent = a; 166 | components.at(b).root = false; 167 | components.at(a).size += components.at(b).size; 168 | components.at(a).mean += components.at(b).mean; 169 | 170 | return a; 171 | } 172 | else { 173 | components.at(a).parent = b; 174 | components.at(a).root = false; 175 | components.at(b).size += components.at(a).size; 176 | components.at(b).mean += components.at(a).mean; 177 | 178 | return b; 179 | } 180 | } 181 | 182 | } // namespace dip 183 | -------------------------------------------------------------------------------- /segmentation/src/headsegmenter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | 31 | #include 32 | 33 | namespace dip { 34 | 35 | HeadSegmenter::~HeadSegmenter() { 36 | if (labels_ != NULL) 37 | delete [] labels_; 38 | if (column_histogram_ != NULL) 39 | delete [] column_histogram_; 40 | if (row_histogram_ != NULL) 41 | delete [] row_histogram_; 42 | } 43 | 44 | int HeadSegmenter::Run(int min_depth, int max_depth, int max_difference, 45 | int min_width, int min_height, 46 | int max_width, int max_height, 47 | float fx, float fy, int width, int height, 48 | const Depth *depth, Depth *segmented_depth) { 49 | if (size_ < (width * height)) { 50 | size_ = width * height; 51 | 52 | if (labels_ != NULL) 53 | delete [] labels_; 54 | 55 | labels_ = new int[size_]; 56 | } 57 | 58 | if (width_ < width) { 59 | width_ = width; 60 | 61 | if (column_histogram_ != NULL) 62 | delete [] column_histogram_; 63 | 64 | column_histogram_ = new int[width_]; 65 | } 66 | 67 | if (height_ < height) { 68 | height_ = height; 69 | 70 | if (row_histogram_ != NULL) 71 | delete [] row_histogram_; 72 | 73 | row_histogram_ = new int[height_]; 74 | } 75 | 76 | memset(segmented_depth, 0, sizeof(Depth) * width * height); 77 | 78 | // Determine foreground region 79 | connected_components_.Run(max_difference, width, height, depth, components_, 80 | labels_); 81 | 82 | int foreground_id = 0; 83 | int foreground_size = 0; 84 | int foreground_depth = 0; 85 | 86 | for (unsigned int n = 0; n < components_.size(); n++) { 87 | if (components_.at(n).root) { 88 | if (components_.at(n).mean > min_depth) { 89 | if (components_.at(n).mean < max_depth) { 90 | if (components_.at(n).size > foreground_size) { 91 | foreground_id = components_.at(n).parent; 92 | foreground_size = components_.at(n).size; 93 | foreground_depth = components_.at(n).mean; 94 | } 95 | } 96 | } 97 | } 98 | } 99 | 100 | // Determine head region 101 | memset(column_histogram_, 0, sizeof(int) * width); 102 | memset(row_histogram_, 0, sizeof(int) * height); 103 | 104 | // Generate Histograms 105 | int count = 0; 106 | int i = 0; 107 | for (int y = 0; y < height; y++) { 108 | for (int x = 0; x < width; x++, i++) { 109 | if (labels_[i] == foreground_id) { 110 | column_histogram_[x]++; 111 | row_histogram_[y]++; 112 | 113 | count++; 114 | } 115 | } 116 | } 117 | 118 | // Locate Top of Head 119 | int max_value = 0; 120 | int head_center = 0; 121 | for (int x = 0; x < width; x++) { 122 | if (column_histogram_[x] > max_value) { 123 | max_value = column_histogram_[x]; 124 | head_center = x; 125 | } 126 | } 127 | 128 | int head_top = 0; 129 | for (int y = 0; y < height; y++) { 130 | int i = head_center + y * width; 131 | 132 | if (labels_[i] == foreground_id) { 133 | head_top = y; 134 | break; 135 | } 136 | } 137 | 138 | // Locate Bottom of Head 139 | float max_variance = 0.0f; 140 | 141 | float weight_torso = 0.0f, weight_head = 0.0f; 142 | int count_head = 0; 143 | 144 | int head_bottom = 0; 145 | for (int y = head_top; y < height; y++) { 146 | // Compute Weights 147 | weight_head++; 148 | weight_torso = (float)((height - 1) - head_top) - weight_head; 149 | 150 | if ((weight_head > 0) && (weight_torso > 0)) { 151 | count_head += row_histogram_[y]; 152 | 153 | // Compute Means 154 | float mean_torso, mean_head; 155 | mean_head = count_head / weight_head; 156 | mean_torso = (count - count_head) / weight_torso; 157 | 158 | // Compute Between Class Variance 159 | float between_variance; 160 | between_variance = (weight_head / ((height - 1) - head_top)) * 161 | (weight_torso / ((height - 1) - head_top)) * 162 | (mean_head - mean_torso) * (mean_head - mean_torso); 163 | 164 | if (between_variance > max_variance) { 165 | max_variance = between_variance; 166 | head_bottom = y; 167 | } 168 | } 169 | } 170 | 171 | head_bottom -= (int)((head_bottom - head_top) * 0.10f); 172 | 173 | // Locate Left and Right side of Head 174 | int head_left = width; 175 | int head_right = 0; 176 | for (int y = head_top; y < head_bottom; y++) { 177 | for (int x = 0; x < width; x++) { 178 | int i = x + y * width; 179 | 180 | if (labels_[i] == foreground_id) { 181 | if (x < head_left) 182 | head_left = x; 183 | 184 | if (x > head_right) 185 | head_right = x; 186 | } 187 | } 188 | } 189 | 190 | // Check head dimensions. 191 | float head_width = ((head_right - head_left) * foreground_depth) / fx; 192 | float head_height = ((head_bottom - head_top) * foreground_depth) / fy; 193 | 194 | if ((head_width > min_width) && (head_width < max_width)) { 195 | if ((head_height > min_height) && (head_height < max_height)) { 196 | // Segment User's Head 197 | for (int y = head_top; y < head_bottom; y++) { 198 | for (int x = head_left; x < head_right; x++) { 199 | int i = x + y * width; 200 | 201 | if (labels_[i] == foreground_id) 202 | segmented_depth[i] = depth[i]; 203 | } 204 | } 205 | 206 | return 0; 207 | } 208 | } 209 | 210 | return -1; 211 | } 212 | 213 | } // namespace dip 214 | -------------------------------------------------------------------------------- /surface/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(MODULE_NAME surface) 2 | 3 | SET(MODULE_DEPENDENCIES 4 | common 5 | ) 6 | 7 | include(includes.cmake) 8 | 9 | foreach(DEPENDENT ${MODULE_DEPENDENCIES}) 10 | include(${PROJECT_SOURCE_DIR}/${DEPENDENT}/includes.cmake) 11 | 12 | set(INCLUDE_DIRS 13 | ${INCLUDE_DIRS} 14 | ${PROJECT_SOURCE_DIR}/${DEPENDENT}/include 15 | ) 16 | endforeach(DEPENDENT) 17 | 18 | set(INCLUDE_DIRS 19 | ${INCLUDE_DIRS} 20 | include/ 21 | ) 22 | 23 | include_directories(${INCLUDE_DIRS}) 24 | 25 | set(INCS 26 | include/dip/${MODULE_NAME}/marchingcubes.h 27 | include/dip/${MODULE_NAME}/mesh.h 28 | include/dip/${MODULE_NAME}/raycasting.h 29 | include/dip/${MODULE_NAME}/volumetric.h 30 | include/dip/${MODULE_NAME}/voxel.h 31 | ) 32 | 33 | set(SRCS 34 | src/marchingcubes.cpp 35 | src/raycasting.cpp 36 | src/raycasting.cu 37 | src/volumetric.cpp 38 | src/volumetric.cu 39 | ) 40 | 41 | set(LIBS 42 | ${MODULE_DEPENDENCIES} 43 | ) 44 | 45 | cuda_add_library(${MODULE_NAME} ${SRCS} ${INCS}) 46 | target_link_libraries(${MODULE_NAME} ${LIBS}) 47 | 48 | if(WIN32) 49 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}/Release 50 | CONFIGURATIONS Release) 51 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}/Debug 52 | CONFIGURATIONS Debug) 53 | endif() 54 | 55 | if(UNIX) 56 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}) 57 | endif() 58 | 59 | install(FILES ${INCS} DESTINATION ${INCLUDE_INSTALL_DIR}/${MODULE_NAME}) 60 | -------------------------------------------------------------------------------- /surface/include/dip/surface/marchingcubes.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef DIP_SURFACE_MARCHINGCUBES_H 30 | #define DIP_SURFACE_MARCHINGCUBES_H 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | namespace dip { 38 | 39 | typedef struct { 40 | int ids[12]; 41 | } Cube; 42 | 43 | class MarchingCubes { 44 | public: 45 | MarchingCubes() {} 46 | ~MarchingCubes() {} 47 | 48 | void Run(int volume_size, float volume_dimension, float voxel_dimension, 49 | float min_weight, Vertex center, const Voxel *volume, Mesh *mesh); 50 | 51 | private: 52 | Vertex Interpolate(const Voxel *volume, Vertex position_1, Vertex position_2, 53 | int index_1, int index_2); 54 | bool Check(float min_weight, const Voxel *volume, const int *grid); 55 | int Neighbors(int id, int x, int y, int width, Cube *current, Cube *previous); 56 | 57 | DISALLOW_COPY_AND_ASSIGN(MarchingCubes); 58 | }; 59 | 60 | } // namespace dip 61 | 62 | #endif // DIP_SURFACE_MARCHINGCUBES_H 63 | -------------------------------------------------------------------------------- /surface/include/dip/surface/mesh.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef DIP_SURFACE_MESH_H 30 | #define DIP_SURFACE_MESH_H 31 | 32 | #include 33 | 34 | #include 35 | 36 | namespace dip { 37 | 38 | typedef struct { 39 | unsigned int a, b, c; 40 | } Face; 41 | 42 | class Mesh { 43 | public: 44 | void AddVertex(const Vertex &vertex) { vertices_.push_back(vertex); } 45 | void AddFace(const Face &face) { faces_.push_back(face); } 46 | 47 | Vertex GetVertex(int n) const { return vertices_.at(n); } 48 | Face GetFace(int n) const { return faces_.at(n); } 49 | 50 | unsigned int VertexCount() const { return vertices_.size(); } 51 | unsigned int FaceCount() const { return faces_.size(); } 52 | 53 | private: 54 | std::vector vertices_; 55 | std::vector faces_; 56 | }; 57 | 58 | } // namespace dip 59 | 60 | #endif // DIP_SURFACE_MESH_H 61 | -------------------------------------------------------------------------------- /surface/include/dip/surface/raycasting.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef DIP_SURFACE_RAYCASTING_H 30 | #define DIP_SURFACE_RAYCASTING_H 31 | 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | namespace dip { 39 | 40 | class RayCasting { 41 | public: 42 | RayCasting() {} 43 | ~RayCasting() {} 44 | 45 | void Run(float max_distance, float max_truncation, int volume_size, 46 | float volume_dimension, float voxel_dimension, float min_weight, 47 | int width, int height, float fx, float fy, float cx, float cy, 48 | Vertex center, const Eigen::Matrix4f &transformation, 49 | const Voxel *volume, Vertices model_vertices, 50 | Normals model_normals, Color *normal_map = NULL); 51 | 52 | private: 53 | DISALLOW_COPY_AND_ASSIGN(RayCasting); 54 | }; 55 | 56 | } // namespace dip 57 | 58 | #endif // DIP_SURFACE_RAYCASTING_H 59 | -------------------------------------------------------------------------------- /surface/include/dip/surface/volumetric.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef DIP_SURFACE_VOLUMETRIC_H 30 | #define DIP_SURFACE_VOLUMETRIC_H 31 | 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | namespace dip { 39 | 40 | class Volumetric { 41 | public: 42 | Volumetric() {} 43 | ~Volumetric() {} 44 | 45 | void Run(int volume_size, float volume_dimension, float voxel_dimension, 46 | float max_truncation, float max_weight, int width, int height, 47 | float fx, float fy, float cx, float cy, Vertex center, 48 | const Eigen::Matrix4f &transformation, const Depth *depth, 49 | const Normals normals, Voxel *volume); 50 | 51 | private: 52 | DISALLOW_COPY_AND_ASSIGN(Volumetric); 53 | }; 54 | 55 | } // namespace dip 56 | 57 | #endif // DIP_POINT_CLOUD_BACKPROJECTION_H 58 | -------------------------------------------------------------------------------- /surface/include/dip/surface/voxel.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef DIP_SURFACE_VOXEL_H 30 | #define DIP_SURFACE_VOXEL_H 31 | 32 | namespace dip { 33 | 34 | #define MAX_UINT32 4294967295 35 | 36 | #define COMPRESS(f, w) \ 37 | (((unsigned int)(((f + 1.0f) / 2.0f) * MAX_UINT32) & ~(0xFFFF)) | \ 38 | (((unsigned int)(w * MAX_UINT32) >> 0x10) & (0xFFFF))) 39 | 40 | #define UNCOMPRESS_VALUE(v) \ 41 | (((float)(v & ~(0xFFFF)) / MAX_UINT32) * 2.0f - 1.0f) 42 | 43 | #define UNCOMPRESS_WEIGHT(v) \ 44 | ((float)((v & (0xFFFF)) << 0x10) / MAX_UINT32) 45 | 46 | typedef unsigned int Voxel; 47 | 48 | } // namespace dip 49 | 50 | #endif // DIP_SURFACE_VOXEL_H 51 | -------------------------------------------------------------------------------- /surface/includes.cmake: -------------------------------------------------------------------------------- 1 | set(INCLUDE_DIRS 2 | ${INCLUDE_DIRS} 3 | ${EIGEN_INCLUDE_DIRS} 4 | ) 5 | -------------------------------------------------------------------------------- /surface/src/raycasting.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | 31 | using namespace Eigen; 32 | 33 | namespace dip { 34 | 35 | extern void RayCastingKernel(float max_distance, float max_truncation, 36 | int volume_size, float volume_dimension, 37 | float voxel_dimension, float min_weight, 38 | int width, int height, float fx, float fy, 39 | float cx, float cy, Vertex center, 40 | float *transformation, const Voxel *volume, 41 | Vertices model_vertices, Normals model_normals, 42 | Color *normal_map); 43 | 44 | void RayCasting::Run(float max_distance, float max_truncation, int volume_size, 45 | float volume_dimension, float voxel_dimension, 46 | float min_weight, int width, int height, 47 | float fx, float fy, float cx, float cy, Vertex center, 48 | const Matrix4f &transformation, const Voxel *volume, 49 | Vertices model_vertices, Normals model_normals, 50 | Color *normal_map) { 51 | float T[16]; 52 | for (int m = 0; m < 4; m++) { 53 | for (int n = 0; n < 4; n++) { 54 | T[n + m * 4] = transformation(m, n); 55 | } 56 | } 57 | 58 | RayCastingKernel(max_distance, max_truncation, volume_size, volume_dimension, 59 | voxel_dimension, min_weight, width, height, fx, fy, cx, cy, 60 | center, T, volume, model_vertices, model_normals, 61 | normal_map); 62 | } 63 | 64 | } // namespace dip 65 | -------------------------------------------------------------------------------- /surface/src/volumetric.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | 31 | using namespace Eigen; 32 | 33 | namespace dip { 34 | 35 | extern void VolumetricKernel(int volume_size, float volume_dimension, 36 | float voxel_dimension, float max_truncation, 37 | float max_weight, int width, int height, 38 | float fx, float fy, float cx, float cy, 39 | Vertex center, float *transformation, 40 | const Depth *depth, const Normals normals, 41 | Voxel *volume); 42 | 43 | void Volumetric::Run(int volume_size, float volume_dimension, 44 | float voxel_dimension, float max_truncation, 45 | float max_weight, int width, int height, 46 | float fx, float fy, float cx, float cy, Vertex center, 47 | const Matrix4f &transformation, const Depth *depth, 48 | const Normals normals, Voxel *volume) { 49 | float T[16]; 50 | for (int m = 0; m < 4; m++) { 51 | for (int n = 0; n < 4; n++) { 52 | T[n + m * 4] = transformation(m, n); 53 | } 54 | } 55 | 56 | VolumetricKernel(volume_size, volume_dimension, voxel_dimension, 57 | max_truncation, max_weight, width, height, fx, fy, cx, cy, 58 | center, T, depth, normals, volume); 59 | } 60 | 61 | } // namespace dip 62 | -------------------------------------------------------------------------------- /visualization/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(MODULE_NAME visualization) 2 | 3 | SET(MODULE_DEPENDENCIES 4 | common 5 | ) 6 | 7 | include(includes.cmake) 8 | 9 | foreach(DEPENDENT ${MODULE_DEPENDENCIES}) 10 | include(${PROJECT_SOURCE_DIR}/${DEPENDENT}/includes.cmake) 11 | 12 | set(INCLUDE_DIRS 13 | ${INCLUDE_DIRS} 14 | ${PROJECT_SOURCE_DIR}/${DEPENDENT}/include 15 | ) 16 | endforeach(DEPENDENT) 17 | 18 | set(INCLUDE_DIRS 19 | ${INCLUDE_DIRS} 20 | include/ 21 | ) 22 | 23 | include_directories(${INCLUDE_DIRS}) 24 | 25 | set(INCS 26 | include/dip/${MODULE_NAME}/colorize.h 27 | ) 28 | 29 | set(SRCS 30 | src/colorize.cpp 31 | ) 32 | 33 | 34 | set(LIBS 35 | ${MODULE_DEPENDENCIES} 36 | ) 37 | 38 | add_library(${MODULE_NAME} ${SRCS} ${INCS}) 39 | target_link_libraries(${MODULE_NAME} ${LIBS}) 40 | 41 | if(WIN32) 42 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}/Release 43 | CONFIGURATIONS Release) 44 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}/Debug 45 | CONFIGURATIONS Debug) 46 | endif() 47 | 48 | if(UNIX) 49 | install(TARGETS ${MODULE_NAME} DESTINATION ${LIB_INSTALL_DIR}) 50 | endif() 51 | 52 | install(FILES ${INCS} DESTINATION ${INCLUDE_INSTALL_DIR}/${MODULE_NAME}) 53 | -------------------------------------------------------------------------------- /visualization/include/dip/visualization/colorize.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef DIP_VISUALIZATION_COLORIZE_H 30 | #define DIP_VISUALIZATION_COLORIZE_H 31 | 32 | #include 33 | #include 34 | 35 | namespace dip { 36 | 37 | class Colorize { 38 | public: 39 | Colorize() {}; 40 | 41 | void Run(int width, int height, const Depth *input, Color *output); 42 | void Run(int width, int height, const int *input, Color *output); 43 | void Run(int width, int height, const float *input, Color *output); 44 | 45 | void Run(int width, int height, int min_value, int max_value, 46 | const Depth *input, Color *output); 47 | void Run(int width, int height, int min_value, int max_value, 48 | const int *input, Color *output); 49 | void Run(int width, int height, float min_value, float max_value, 50 | const float *input, Color *output); 51 | 52 | private: 53 | Color jet(float value, float min, float max); 54 | 55 | DISALLOW_COPY_AND_ASSIGN(Colorize); 56 | }; 57 | 58 | } // namespace dip 59 | 60 | #endif // DIP_VISUALIZATION_COLORIZE_H 61 | -------------------------------------------------------------------------------- /visualization/includes.cmake: -------------------------------------------------------------------------------- 1 | set(INCLUDE_DIRS 2 | ${INCLUDE_DIRS} 3 | ) -------------------------------------------------------------------------------- /visualization/src/colorize.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2015, Gregory P. Meyer 3 | University of Illinois Board of Trustees 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder(s) nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | 31 | namespace dip { 32 | 33 | void Colorize::Run(int width, int height, const Depth *input, Color *output) { 34 | int min_value, max_value; 35 | min_value = max_value = input[0]; 36 | 37 | for (int i = 1; i < (width * height); i++) { 38 | min_value = MIN(input[i], min_value); 39 | max_value = MAX(input[i], max_value); 40 | } 41 | 42 | for (int i = 0; i < (width * height); i++) 43 | output[i] = jet(input[i], min_value, max_value); 44 | } 45 | 46 | void Colorize::Run(int width, int height, const int *input, Color *output) { 47 | int min_value, max_value; 48 | min_value = max_value = input[0]; 49 | 50 | for (int i = 1; i < (width * height); i++) { 51 | min_value = MIN(input[i], min_value); 52 | max_value = MAX(input[i], max_value); 53 | } 54 | 55 | for (int i = 0; i < (width * height); i++) 56 | output[i] = jet(input[i], min_value, max_value); 57 | } 58 | 59 | void Colorize::Run(int width, int height, const float *input, Color *output) { 60 | float min_value, max_value; 61 | min_value = max_value = input[0]; 62 | 63 | for (int i = 1; i < (width * height); i++) { 64 | min_value = MIN(input[i], min_value); 65 | max_value = MAX(input[i], max_value); 66 | } 67 | 68 | for (int i = 0; i < (width * height); i++) 69 | output[i] = jet(input[i], min_value, max_value); 70 | } 71 | 72 | void Colorize::Run(int width, int height, int min_value, int max_value, 73 | const Depth *input, Color *output) { 74 | for (int i = 0; i < (width * height); i++) 75 | output[i] = jet(input[i], min_value, max_value); 76 | } 77 | 78 | void Colorize::Run(int width, int height, int min_value, int max_value, 79 | const int *input, Color *output) { 80 | for (int i = 0; i < (width * height); i++) 81 | output[i] = jet(input[i], min_value, max_value); 82 | } 83 | 84 | void Colorize::Run(int width, int height, float min_value, float max_value, 85 | const float *input, Color *output) { 86 | for (int i = 0; i < (width * height); i++) 87 | output[i] = jet(input[i], min_value, max_value); 88 | } 89 | 90 | Color Colorize::jet(float value, float min, float max) { 91 | Color color = { 0, 0, 0 }; 92 | 93 | if ((value >= min) && (value <= max)) { 94 | float v = (value - min) / (max - min); 95 | 96 | if (v < 0.25f) { 97 | color.b = 255; 98 | color.g = (unsigned char)((4.0f * v) * 255.0f); 99 | } else if (v < 0.5f) { 100 | color.g = 255; 101 | color.b = (unsigned char)((1.0f + (4.0f * (0.25f - v))) * 255.0f); 102 | } else if (v < 0.75f) { 103 | color.g = 255; 104 | color.r = (unsigned char)((4.0f * (v - 0.5f)) * 255.0f); 105 | } else { 106 | color.r = 255; 107 | color.g = (unsigned char)((1.0f + (4.0f * (0.75f - v))) * 255.0f); 108 | } 109 | } 110 | 111 | return color; 112 | } 113 | 114 | } // namespace dip 115 | --------------------------------------------------------------------------------