├── .gitattributes
├── LICENSE.txt
├── README.md
├── libmin
├── CMakeLists.txt
├── cmake
│ ├── CudaAutodetectCompute.cmake
│ ├── CudaComputeTargetFlags.cmake
│ ├── DeclareDPIAware.manifest
│ ├── FindLibmin.cmake
│ └── HelpersBootstrap.cmake
├── include
│ ├── GL
│ │ ├── eglew.h
│ │ ├── glew.h
│ │ ├── glxew.h
│ │ └── wglew.h
│ ├── camera3d.h
│ ├── common_cuda.h
│ ├── common_defs.h
│ ├── cutil_math.h
│ ├── dataptr.h
│ ├── datax.h
│ ├── directory.h
│ ├── event.h
│ ├── event_system.h
│ ├── file_png.h
│ ├── file_tga.h
│ ├── httplib.h
│ ├── image.h
│ ├── image_info.h
│ ├── imageformat.h
│ ├── imageformat_bmp.h
│ ├── imageformat_generic.h
│ ├── imageformat_jpg.h
│ ├── imageformat_png.h
│ ├── imageformat_tga.h
│ ├── imageformat_tiff.h
│ ├── main_includes.h
│ ├── nvToolsExt.h
│ ├── nv_gui.h
│ ├── quaternion.h
│ ├── string_helper.h
│ ├── timex.h
│ ├── vec.h
│ └── widget.h
├── mains
│ ├── main.h
│ ├── main_android.cpp
│ ├── main_win.cpp
│ └── main_x11.cpp
└── src
│ ├── camera3d.cpp
│ ├── common_cuda.cpp
│ ├── common_defs.cpp
│ ├── dataptr.cpp
│ ├── datax.cpp
│ ├── directory.cpp
│ ├── event.cpp
│ ├── event_system.cpp
│ ├── file_png.cpp
│ ├── file_tga.cpp
│ ├── glew.c
│ ├── glewinfo.c
│ ├── image.cpp
│ ├── image_bgr24.cpp
│ ├── image_bw16.cpp
│ ├── image_bw32.cpp
│ ├── image_bw8.cpp
│ ├── image_f8.cpp
│ ├── image_info.cpp
│ ├── image_rgb24.cpp
│ ├── image_rgba32.cpp
│ ├── imageformat.cpp
│ ├── imageformat_bmp.cpp
│ ├── imageformat_generic.cpp
│ ├── imageformat_jpg.cpp
│ ├── imageformat_png.cpp
│ ├── imageformat_tga.cpp
│ ├── imageformat_tiff.cpp
│ ├── nv_gui.cpp
│ ├── quaternion.cpp
│ ├── string_helper.cpp
│ ├── timex.cpp
│ ├── vec.cpp
│ └── widget.cpp
├── math_voxelizer
├── CMakeLists.txt
├── assets
│ ├── arial_256.bin
│ └── arial_256.tga
└── main_voxelizer.cpp
└── voxelizer.jpg
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 |
2 | Voxelizer
3 |
4 | Copyright Rama Hoetzlein (c) 2019
5 | This work is licensed as CC0, public domain with no restrictions
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | ## Voxelizer
4 | ------------------------------------------------
5 | by Rama Karl Hoetzlein, http://ramakarl.com
6 | This code is licensed CC-BY (c) 2021
7 |
8 | The interface lets you move the vertices of the triangle.
9 | Use 1,2,3,4 keys to change the Algorithm.
10 |
11 | Code gives the basic math for the 3D voxelization of a triangle.
12 |
13 | Four techniques are provided. The first three are triangle-box intersection tests, and test the triangle against every voxel in the domain O(V^3). The last is a direct DDA Rasterizer, which only visits the voxels touched by the triangle O(Vt).
14 |
15 | 1- **Explicit edge tests**: Use edge fuctions to explicitly test each edge of triangle. 27 tests/voxel.
16 | 2- **Schwarz-Seidel tests**: Recent paper that uses a reduced, efficient set of edge tests. 9 tests/voxel.
17 | 3- **Akenine-Moller tests**: The first paper to provide efficient, exact voxelization. 18 tests/voxel.
18 | 4- **DDA Rasterizer**: Starts at one corner and scans along the edges, performing a DDA (2D differential analyzer) to fill the interior of the triangle in 3D. This technique is much faster as it only visits voxels on the triangle.
19 |
20 | Sources:
21 | Schwarz & Seidel, 2010, Fast Parallel Surface and Solid Voxelization on GPUs, http://research.michael-schwarz.com/publ/files/vox-siga10.pdf
22 | Akenine-Moller, 2001, Fast 3D Triangle-Box Overlap Testing, https://fileadmin.cs.lth.se/cs/Personal/Tomas_Akenine-Moller/pubs/tribox.pdf
23 | Pineda, 1998, A Parallel Algorithm for Polygon Rasterization (Edge Functions), https://www.cs.drexel.edu/~david/Classes/Papers/comp175-06-pineda.pdf
24 |
25 | Citation of this code when used in papers or projects is appreciated:
26 | 2019. Hoetzlein, Rama. *Voxelization of a triangle in 3D*. https://github.com/ramakarl/voxelizer
27 |
28 | ### How to Build
29 |
30 | 1. Run cmake in \libmin
31 | 2. Build the solution for libmin
32 | 3. Run cmake in \math_voxelizer
33 | 4. During cmake it should find libmin. If not, set the LIBMIN_ROOT_DIR
34 | 4. Build the solution. Run it.
35 |
36 |
37 | Rama Hoetzlein (c) 2019
38 |
39 |
--------------------------------------------------------------------------------
/libmin/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 2.8)
2 |
3 | set(PROJNAME libmin)
4 | Project(${PROJNAME})
5 |
6 | Message("-------------------------------")
7 | Message("PROJECT NAME: ${PROJNAME}")
8 |
9 | #####################################################################################
10 | # Bootstrap
11 | #
12 | set( BASE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
13 | find_path ( CMAKE_HELPERS_PATH "HelpersBootstrap.cmake" HINTS ${BASE_DIRECTORY}/cmake/ )
14 | if ( ${CMAKE_HELPERS_PATH} STREQUAL "HELPERS-NOTFOUND" )
15 | message ( FATAL_ERROR "\n Please set the CMAKE_HELPERS_PATH to location of HelpersBootstrap.cmake" )
16 | endif()
17 | include( ${CMAKE_HELPERS_PATH}/HelpersBootstrap.cmake ) # Cross-Platform functions
18 | include_directories ("${CMAKE_CURRENT_SOURCE_DIR}/src")
19 | include_directories ("${CMAKE_CURRENT_SOURCE_DIR}/include")
20 |
21 | #####################################################################################
22 | #
23 | # LIBMIN - Options
24 | #
25 | add_definitions ( -DLIBHELP_EXPORTS)
26 |
27 | add_definitions ( -DGLEW_STATIC)
28 |
29 | OPTION (BUILD_OPENGL "Build with OpenGL" ON)
30 | if (BUILD_OPENGL)
31 | add_definitions(-DUSE_OPENGL) # Use OpenGL
32 |
33 | IF (WIN32)
34 | LIST(APPEND LIBRARIES_OPTIMIZED "opengl32.lib" )
35 | LIST(APPEND LIBRARIES_DEBUG "opengl32.lib" )
36 | ENDIF()
37 |
38 | endif()
39 |
40 | #####################################################################################
41 | # Source files for this project
42 | #
43 | file(GLOB SOURCE_FILES src/*.cpp src/*.c)
44 | file(GLOB INCLUDE_FILES include/*.hpp include/*.h)
45 |
46 | #####################################################################################
47 | # Library paths
48 | #
49 | # CMAKE_INSTALL_PREFIX -- path where library will be installed to
50 |
51 | if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
52 | if ( WIN32 )
53 | get_filename_component ( _instpath "${CMAKE_CURRENT_BINARY_DIR}" REALPATH )
54 | else()
55 | get_filename_component ( _instpath "/usr/local/libhelp" REALPATH )
56 | endif()
57 | set ( CMAKE_INSTALL_PREFIX ${_instpath} CACHE PATH "default install path" FORCE)
58 | endif()
59 |
60 | get_filename_component( LIB_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} REALPATH)
61 | get_filename_component( INSTALL_BIN_PATH ${CMAKE_INSTALL_PREFIX}/bin REALPATH)
62 | get_filename_component( INSTALL_INC_PATH ${CMAKE_INSTALL_PREFIX}/include REALPATH)
63 | get_filename_component( SHARE_PATH ${CMAKE_INSTALL_PREFIX}/lib REALPATH)
64 |
65 | set ( EXECUTABLE_OUTPUT_PATH ${INSTALL_BIN_PATH} CACHE PATH "" FORCE )
66 |
67 |
68 | #####################################################################################
69 | # Library output
70 | #
71 | unset ( ALL_SOURCE_FILES )
72 | list( APPEND ALL_SOURCE_FILES ${SOURCE_FILES} )
73 | list( APPEND ALL_SOURCE_FILES ${INCLUDE_FILES} )
74 | list( APPEND ALL_SOURCE_FILES ${PACKAGE_SOURCE_FILES} )
75 |
76 | # Definitions
77 | add_definitions(-DLIBHELP_EXPORTS) # Export dll symbols
78 |
79 | # Set the library type
80 | OPTION (BUILD_SHARED_LIBS "Build Shared Libraries" ON)
81 | set (LIB_TYPE STATIC)
82 | if (BUILD_SHARED_LIBS)
83 | set (LIB_TYPE SHARED)
84 | endif()
85 |
86 | if( WIN32 AND NOT GLUT_FOUND)
87 | add_definitions(/wd4267) #remove size_t to int warning
88 | add_definitions(/wd4996) #remove printf warning
89 | add_definitions(/wd4244) #remove double to float conversion warning
90 | add_definitions(/wd4305) #remove double to float truncation warning
91 | add_library (${PROJNAME} ${LIB_TYPE} ${ALL_SOURCE_FILES} ${CUDA_FILES} )
92 | else()
93 | add_library (${PROJNAME} ${LIB_TYPE} ${ALL_SOURCE_FILES} ${CUDA_FILES} ${PTX_FILES} )
94 | endif()
95 |
96 | # debug and relase libs
97 | set ( CMAKE_DEBUG_POSTFIX "d" CACHE STRING "" )
98 | set_target_properties( ${PROJNAME} PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
99 |
100 | set_target_properties( ${PROJNAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${LIB_OUTPUT_PATH} )
101 | set_target_properties( ${PROJNAME} PROPERTIES VS_INTERMEDIATE_DIRECTORY_DEBUG ${LIB_OUTPUT_PATH}/Debug )
102 | set_target_properties( ${PROJNAME} PROPERTIES VS_INTERMEDIATE_DIRECTORY_RELEASE ${LIB_OUTPUT_PATH}/Release )
103 | set_target_properties( ${PROJNAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${LIB_OUTPUT_PATH} )
104 | set_target_properties( ${PROJNAME} PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
105 |
106 | message ( STATUS "Output: ${LIB_OUTPUT_PATH}" )
107 | message ( STATUS "Installed Bin: ${INSTALL_BIN_PATH}" )
108 | message ( STATUS "Installed Inc: ${INSTALL_INC_PATH}" )
109 |
110 | #####################################################################################
111 | # Linkage
112 | #
113 | _LINK ( PROJECT ${PROJNAME} OPT ${LIBRARIES_OPTIMIZED} DEBUG ${LIBRARIES_DEBUG} PLATFORM ${PLATFORM_LIBRARIES} )
114 |
115 | ################################################################
116 | # Windows specific
117 | #
118 | if ( WIN32 )
119 | # instruct CMake to automatically build INSTALL project in Visual Studio
120 | set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1)
121 | # visual studio source groups
122 | source_group(Include FILES
123 | ${INCLUDE_FILES}
124 | )
125 | source_group(Source FILES
126 | ${SOURCE_FILES}
127 | )
128 | endif()
129 |
130 | ################################################################
131 | # Install Binaries
132 | #
133 | file (COPY "${CMAKE_CURRENT_SOURCE_DIR}/include/GL" DESTINATION ${INSTALL_INC_PATH} )
134 | file (COPY "${CMAKE_CURRENT_SOURCE_DIR}/src/glew.c" DESTINATION ${INSTALL_INC_PATH} )
135 | install ( FILES ${INCLUDE_FILES} DESTINATION ${INSTALL_INC_PATH} )
136 |
137 | install ( FILES ${INSTALL_LIST} DESTINATION ${INSTALL_BIN_PATH} )
138 | install ( FILES $ DESTINATION ${INSTALL_BIN_PATH} OPTIONAL )
139 | install ( FILES $ DESTINATION ${INSTALL_BIN_PATH} )
140 | _INSTALL ( FILES ${PACKAGE_DLLS} DESTINATION ${INSTALL_BIN_PATH} )
141 | install ( TARGETS ${PROJNAME} DESTINATION ${INSTALL_BIN_PATH} )
142 |
143 | #################################
144 | # Done
145 | message ( STATUS "\nLIBMIN INSTALL PATH: ${CMAKE_INSTALL_PREFIX}" )
146 | message ( STATUS "LIBMIN will be installed to this path post-build (win32) or during make install (linux)")
147 |
148 |
149 |
--------------------------------------------------------------------------------
/libmin/cmake/CudaAutodetectCompute.cmake:
--------------------------------------------------------------------------------
1 | function(REMOVE_DUPES ARG_STR OUTPUT)
2 | set(ARG_LIST ${ARG_STR})
3 | separate_arguments(ARG_LIST)
4 | list(REMOVE_DUPLICATES ARG_LIST)
5 | string (REGEX REPLACE "([^\\]|^);" "\\1 " _TMP_STR "${ARG_LIST}")
6 | string (REGEX REPLACE "[\\](.)" "\\1" _TMP_STR "${_TMP_STR}") #fixes escaping
7 | set (${OUTPUT} "${_TMP_STR}" PARENT_SCOPE)
8 | endfunction()
9 |
10 |
11 | ################################################################################################
12 | # A function for automatic detection of GPUs installed (if autodetection is enabled)
13 | # Usage:
14 | # detect_installed_gpus(out_variable)
15 | function(detect_installed_gpus out_variable)
16 | if(NOT CUDA_gpu_detect_output)
17 | set(__cufile ${PROJECT_BINARY_DIR}/detect_cuda_archs.cu)
18 |
19 | file(WRITE ${__cufile} ""
20 | "#include \n"
21 | "int main()\n"
22 | "{\n"
23 | " int count = 0;\n"
24 | " if (cudaSuccess != cudaGetDeviceCount(&count)) return -1;\n"
25 | " if (count == 0) return -1;\n"
26 | " for (int device = 0; device < count; ++device)\n"
27 | " {\n"
28 | " cudaDeviceProp prop;\n"
29 | " if (cudaSuccess == cudaGetDeviceProperties(&prop, device))\n"
30 | " std::printf(\"%d.%d \", prop.major, prop.minor);\n"
31 | " }\n"
32 | " return 0;\n"
33 | "}\n")
34 |
35 | execute_process(COMMAND "${CUDA_NVCC_EXECUTABLE}" "--run" "${__cufile}"
36 | WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/CMakeFiles/"
37 | RESULT_VARIABLE __nvcc_res OUTPUT_VARIABLE __nvcc_out
38 | ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
39 |
40 | if(__nvcc_res EQUAL 0)
41 | string(REPLACE "2.1" "2.1(2.0)" __nvcc_out "${__nvcc_out}")
42 | message("BEFORE DUPE ${__nvcc_out}!!")
43 | REMOVE_DUPES(${__nvcc_out} dedup)
44 | message("AFTER DUPE ${dedup}")
45 | set(CUDA_gpu_detect_output ${dedup} CACHE INTERNAL "Returned GPU architectures from detect_gpus tool" FORCE)
46 | endif()
47 | endif()
48 |
49 | if(NOT CUDA_gpu_detect_output)
50 | message(STATUS "Automatic GPU detection failed. Building for all known architectures.")
51 | set(${out_variable} ${CUDA_known_gpu_archs} PARENT_SCOPE)
52 | else()
53 | set(${out_variable} ${CUDA_gpu_detect_output} PARENT_SCOPE)
54 | endif()
55 | endfunction()
56 |
57 |
--------------------------------------------------------------------------------
/libmin/cmake/CudaComputeTargetFlags.cmake:
--------------------------------------------------------------------------------
1 | #
2 | # Compute target flags macros by Anatoly Baksheev
3 | #
4 | # Usage in CmakeLists.txt:
5 | # include(CudaComputeTargetFlags.cmake)
6 | # APPEND_TARGET_ARCH_FLAGS()
7 |
8 | #compute flags macros
9 | MACRO(CUDA_COMPUTE_TARGET_FLAGS arch_bin arch_ptx cuda_nvcc_target_flags)
10 | string(REGEX REPLACE "\\." "" ARCH_BIN_WITHOUT_DOTS "${${arch_bin}}")
11 | string(REGEX REPLACE "\\." "" ARCH_PTX_WITHOUT_DOTS "${${arch_ptx}}")
12 |
13 | set(cuda_computer_target_flags_temp "")
14 |
15 | # Tell NVCC to add binaries for the specified GPUs
16 | string(REGEX MATCHALL "[0-9()]+" ARCH_LIST "${ARCH_BIN_WITHOUT_DOTS}")
17 | foreach(ARCH IN LISTS ARCH_LIST)
18 | if (ARCH MATCHES "([0-9]+)\\(([0-9]+)\\)")
19 | # User explicitly specified PTX for the concrete BIN
20 | set(cuda_computer_target_flags_temp ${cuda_computer_target_flags_temp} -gencode arch=compute_${CMAKE_MATCH_2},code=sm_${CMAKE_MATCH_1})
21 | else()
22 | # User didn't explicitly specify PTX for the concrete BIN, we assume PTX=BIN
23 | set(cuda_computer_target_flags_temp ${cuda_computer_target_flags_temp} -gencode arch=compute_${ARCH},code=sm_${ARCH})
24 | endif()
25 | endforeach()
26 |
27 | # Tell NVCC to add PTX intermediate code for the specified architectures
28 | string(REGEX MATCHALL "[0-9]+" ARCH_LIST "${ARCH_PTX_WITHOUT_DOTS}")
29 | foreach(ARCH IN LISTS ARCH_LIST)
30 | set(cuda_computer_target_flags_temp ${cuda_computer_target_flags_temp} -gencode arch=compute_${ARCH},code=compute_${ARCH})
31 | endforeach()
32 |
33 | set(${cuda_nvcc_target_flags} ${cuda_computer_target_flags_temp})
34 | ENDMACRO()
35 |
36 | MACRO(APPEND_TARGET_ARCH_FLAGS)
37 | set(cuda_nvcc_target_flags "")
38 | CUDA_COMPUTE_TARGET_FLAGS(CUDA_ARCH_BIN CUDA_ARCH_PTX cuda_nvcc_target_flags)
39 | if (cuda_nvcc_target_flags)
40 | message(STATUS "CUDA NVCC target flags: ${cuda_nvcc_target_flags}")
41 | list(APPEND CUDA_NVCC_FLAGS ${cuda_nvcc_target_flags})
42 | endif()
43 | ENDMACRO()
--------------------------------------------------------------------------------
/libmin/cmake/DeclareDPIAware.manifest:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
12 | true/PM
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/libmin/cmake/FindLibmin.cmake:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # Find LibHelp
4 | #
5 |
6 | unset(LIBMIN_FOUND CACHE)
7 | unset(LIBMIN_INC_DIR CACHE)
8 |
9 | if ( NOT DEFINED LIBMIN_ROOT_DIR )
10 | if (WIN32)
11 | get_filename_component ( BASEDIR "${CMAKE_CURRENT_BINARY_DIR}/../libmin" REALPATH )
12 | else()
13 | get_filename_component ( BASEDIR "/usr/local/libmin/" REALPATH )
14 | endif()
15 | set ( LIBMIN_ROOT_DIR ${BASEDIR} CACHE PATH "Location of libmin" FORCE)
16 | endif()
17 | message ( STATUS "Searching for libhelp at.. ${LIBMIN_ROOT_DIR}")
18 | set( LIBMIN_FOUND "YES" )
19 |
20 | if ( LIBMIN_ROOT_DIR )
21 |
22 | #-- Paths
23 | set ( LIBMIN_INC_DIR "${LIBMIN_ROOT_DIR}/include" CACHE PATH "Path to include files" FORCE)
24 | set ( LIBMIN_LIB_DIR "${LIBMIN_ROOT_DIR}/bin" CACHE PATH "Path to libraries" FORCE)
25 |
26 | #-------- Locate Header files
27 | set ( OK_H "0" )
28 | _FIND_FILE ( LIBMIN_FILES LIBMIN_INC_DIR "common_defs.h" "common_defs.h" OK_H )
29 | _FIND_FILE ( LIBMIN_FILES LIBMIN_INC_DIR "nv_gui.h" "nv_gui.h" OK_H )
30 | _FIND_FILE ( LIBMIN_FILES LIBMIN_INC_DIR "vec.h" "vec.h" OK_H )
31 | _FIND_FILE ( LIBMIN_FILES LIBMIN_INC_DIR "timex.h" "timex.h" OK_H )
32 | if ( OK_H EQUAL 4 )
33 | message ( STATUS " Found. Libhelp header files. ${LIBMIN_INCLUDE_DIR}" )
34 | else()
35 | message ( " NOT FOUND. Libhelp Header files" )
36 | set ( LIBMIN_FOUND "NO" )
37 | endif ()
38 |
39 | #-------- Locate Library
40 | set ( LIST_DLL "" )
41 | set ( LIST_DEBUG "" )
42 | set ( LIST_REL "" )
43 | set ( OK_DLL 0 )
44 | set ( OK_LIB 0 )
45 | _FIND_FILE ( LIST_DEBUG LIBMIN_LIB_DIR "libmind.lib" "libmind.so" OK_LIB )
46 | _FIND_FILE ( LIST_DLL LIBMIN_LIB_DIR "libmind.dll" "" OK_DLL )
47 |
48 | _FIND_FILE ( LIST_REL LIBMIN_LIB_DIR "libmin.lib" "libmin.so" OK_LIB )
49 | _FIND_FILE ( LIST_DLL LIBMIN_LIB_DIR "libmin.dll" "" OK_DLL )
50 |
51 | if ( (${OK_DLL} GREATER_EQUAL 1) AND (${OK_LIB} GREATER_EQUAL 1) )
52 | message ( STATUS " Found. Libhelp Library. ${LIBMIN_LIB_DIR}" )
53 | else()
54 | set ( LIBMIN_FOUND "NO" )
55 | message ( " NOT FOUND. Libhelp Library. (so/dll or lib missing)" )
56 | endif()
57 |
58 | endif()
59 |
60 | if ( ${LIBMIN_FOUND} STREQUAL "NO" )
61 | message( FATAL_ERROR "
62 | Please set LIBMIN_ROOT_DIR to the root location
63 | of installed Libhelp library containing LIBMIN_full.lib/dll
64 | Not found at LIBMIN_ROOT_DIR: ${LIBMIN_ROOT_DIR}\n"
65 | )
66 | endif()
67 |
68 | set ( LIBMIN_DLLS ${LIST_DLL} CACHE INTERNAL "" FORCE)
69 | set ( LIBMIN_DEBUG ${LIST_DEBUG} CACHE INTERNAL "" FORCE)
70 | set ( LIBMIN_REL ${LIST_REL} CACHE INTERNAL "" FORCE)
71 |
72 | #-- We do not want user to modified these vars, but helpful to show them
73 | message ( STATUS " LIBMIN_ROOT_DIR: ${LIBMIN_ROOT_DIR}" )
74 | message ( STATUS " LIBMIN_LIB_DIR: ${LIBMIN_LIB_DIR}" )
75 | message ( STATUS " LIBMIN_DLL: ${LIBMIN_DLLS}" )
76 | message ( STATUS " LIBMIN_DEBUG: ${LIBMIN_DEBUG}" )
77 | message ( STATUS " LIBMIN_REL: ${LIBMIN_REL}" )
78 |
79 | mark_as_advanced(LIBMIN_FOUND)
80 |
81 |
82 |
--------------------------------------------------------------------------------
/libmin/include/camera3d.h:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------
2 | // NVIDIA(R) GVDB VOXELS
3 | // Copyright 2017, NVIDIA Corporation.
4 | //
5 | // Redistribution and use in source and binary forms, with or without modification,
6 | // are permitted provided that the following conditions are met:
7 | // 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
9 | // in the documentation and/or other materials provided with the distribution.
10 | // 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived
11 | // from this software without specific prior written permission.
12 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
13 | // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
14 | // SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
15 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
16 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
17 | // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
18 | //
19 | // Version 1.0: Rama Hoetzlein, 5/1/2017
20 | //----------------------------------------------------------------------------------
21 |
22 |
23 | #include "vec.h"
24 |
25 | #ifndef DEF_PIVOTX
26 | #define DEF_PIVOTX
27 |
28 | class HELPAPI PivotX {
29 | public:
30 | PivotX() { from_pos.Set(0,0,0); to_pos.Set(0,0,0); ang_euler.Set(0,0,0); scale.Set(1,1,1); trans.Identity(); }
31 | PivotX( Vector3DF& f, Vector3DF& t, Vector3DF& s, Vector3DF& a) { from_pos=f; to_pos=t; scale=s; ang_euler=a; }
32 |
33 | void setPivot ( float x, float y, float z, float rx, float ry, float rz );
34 | void setPivot ( Vector3DF& pos, Vector3DF& ang ) { from_pos = pos; ang_euler = ang; }
35 | void setPivot ( PivotX piv ) { from_pos = piv.from_pos; to_pos = piv.to_pos; ang_euler = piv.ang_euler; updateTform(); }
36 | void setPivot ( PivotX& piv ) { from_pos = piv.from_pos; to_pos = piv.to_pos; ang_euler = piv.ang_euler; updateTform(); }
37 |
38 | void setIdentity () { from_pos.Set(0,0,0); to_pos.Set(0,0,0); ang_euler.Set(0,0,0); scale.Set(1,1,1); trans.Identity(); }
39 |
40 | void setAng ( float rx, float ry, float rz ) { ang_euler.Set(rx,ry,rz); updateTform(); }
41 | void setAng ( Vector3DF& a ) { ang_euler = a; updateTform(); }
42 |
43 | void setPos ( float x, float y, float z ) { from_pos.Set(x,y,z); updateTform(); }
44 | void setPos ( Vector3DF& p ) { from_pos = p; updateTform(); }
45 |
46 | void setToPos ( float x, float y, float z ) { to_pos.Set(x,y,z); updateTform(); }
47 |
48 | void updateTform ();
49 | void setTform ( Matrix4F& t ) { trans = t; }
50 | inline Matrix4F& getTform () { return trans; }
51 | inline float* getTformData () { return trans.GetDataF(); }
52 |
53 | // Pivot
54 | PivotX getPivot () { return PivotX(from_pos, to_pos, scale, ang_euler); }
55 | Vector3DF& getPos () { return from_pos; }
56 | Vector3DF& getToPos () { return to_pos; }
57 | Vector3DF& getAng () { return ang_euler; }
58 | Vector3DF getDir () {
59 | return to_pos - from_pos;
60 | }
61 | void getPreciseEye (Vector3DF& hi, Vector3DF& lo)
62 | {
63 | //-- should use a double precision camera position as input
64 | // see: https://prideout.net/emulating-double-precision
65 | hi = from_pos;
66 | lo.Set(0,0,0);
67 | }
68 | Vector3DF from_pos;
69 | Vector3DF to_pos;
70 | Vector3DF scale;
71 | Vector3DF ang_euler;
72 | Matrix4F trans;
73 |
74 | //Quatern ang_quat;
75 | //Quatern dang_quat;
76 | };
77 |
78 | #endif
79 |
80 | #ifndef DEF_CAMERA_3D
81 | #define DEF_CAMERA_3D
82 |
83 | #define DEG_TO_RAD (3.141592/180.0)
84 |
85 | class HELPAPI Camera3D : public PivotX {
86 | public:
87 | enum eProjection {
88 | Perspective = 0,
89 | Parallel = 1
90 | };
91 | Camera3D ();
92 | void Copy ( Camera3D& op );
93 |
94 | void draw_gl();
95 |
96 | // Camera settings
97 | void setAspect ( float asp ) { mAspect = asp; updateMatricies(); }
98 | void setPos ( float x, float y, float z ) { from_pos.Set(x,y,z); updateMatricies(); }
99 | void setToPos ( float x, float y, float z ) { to_pos.Set(x,y,z); updateMatricies(); }
100 | void setFov (float fov) { mFov = fov; updateMatricies(); }
101 | void setNearFar (float n, float f ) { mNear = n; mFar = f; updateMatricies(); }
102 | void setDist ( float d ) { mOrbitDist = d; updateMatricies(); }
103 | void setTile ( float x1, float y1, float x2, float y2 ) { mTile.Set ( x1, y1, x2, y2 ); updateMatricies(); }
104 | void setSize ( float w, float h ) { mXres=w; mYres=h; }
105 | void setProjection (eProjection proj_type);
106 | void setModelMatrix ( float* mtx );
107 | void setViewMatrix ( float* mtx, float* invmtx );
108 | void setProjMatrix ( float* mtx, float* invmtx );
109 | void setMatrices (const float* view_mtx, const float* proj_mtx, Vector3DF model_pos );
110 |
111 | // Camera motion
112 | void setOrbit ( float ax, float ay, float az, Vector3DF tp, float dist, float dolly );
113 | void setOrbit ( Vector3DF angs, Vector3DF tp, float dist, float dolly );
114 | void setAngles ( float ax, float ay, float az );
115 | void moveOrbit ( float ax, float ay, float az, float dist );
116 | void moveToPos ( float tx, float ty, float tz );
117 | void moveRelative ( float dx, float dy, float dz );
118 |
119 | // Frustum testing
120 | bool pointInFrustum ( float x, float y, float z );
121 | bool boxInFrustum ( Vector3DF bmin, Vector3DF bmax);
122 | float calculateLOD ( Vector3DF pnt, float minlod, float maxlod, float maxdist );
123 |
124 | // Utility functions
125 | void updateMatricies (bool compute_view=false); // Updates camera axes and projection matricies
126 | void updateFrustum (); // Updates frustum planes
127 | Vector3DF inverseRay ( float x, float y, float z=1.0 );
128 | Vector3DF inverseRayProj ( float x, float y, float z );
129 | Vector4DF project ( Vector3DF& p );
130 | Vector4DF project ( Vector3DF& p, Matrix4F& vm ); // Project point - override view matrix
131 |
132 | void getVectors ( Vector3DF& dir, Vector3DF& up, Vector3DF& side ) { dir = dir_vec; up = up_vec; side = side_vec; }
133 | void getBounds ( float dst, Vector3DF& min, Vector3DF& max );
134 | float getNear () { return mNear; }
135 | float getFar () { return mFar; }
136 | float getFov () { return mFov; }
137 | float getDolly() { return mDolly; }
138 | float getOrbitDist() { return mOrbitDist; }
139 | Vector3DF& getUpDir () { return up_dir; }
140 | Vector4DF& getTile () { return mTile; }
141 | Matrix4F& getInvViewProjMatrix () { return invviewproj_matrix; }
142 | Matrix4F& getViewMatrix () { return view_matrix; }
143 | Matrix4F& getInvView () { return invrot_matrix; }
144 | Matrix4F& getRotateMatrix () { return rotate_matrix; }
145 | Matrix4F& getProjMatrix () { return tileproj_matrix; }
146 | Matrix4F& getFullProjMatrix () { return proj_matrix; }
147 | Matrix4F& getModelMatrix() { return model_matrix; }
148 | Matrix4F& getMVMatrix() { return mv_matrix; }
149 | float getAspect () { return mAspect; }
150 | Vector3DF getU ();
151 | Vector3DF getV ();
152 | Vector3DF getW ();
153 | float getDu ();
154 | float getDv ();
155 |
156 |
157 | public:
158 | eProjection mProjType; // Projection type
159 |
160 | // Camera Parameters // NOTE: Pivot maintains camera from and orientation
161 | float mDolly; // Camera to distance
162 | float mOrbitDist;
163 | float mFov, mAspect; // Camera field-of-view
164 | float mNear, mFar; // Camera frustum planes
165 | float mXres, mYres;
166 | Vector3DF dir_vec, side_vec, up_vec; // Camera aux vectors (W, V, and U)
167 | Vector3DF up_dir;
168 | Vector4DF mTile;
169 |
170 | // Transform Matricies
171 | Matrix4F invviewproj_matrix;
172 | Matrix4F rotate_matrix; // Vr matrix (rotation only)
173 | Matrix4F view_matrix; // V matrix (rotation + translation)
174 | Matrix4F proj_matrix; // P matrix
175 | Matrix4F invrot_matrix; // Vr^-1 matrix
176 | Matrix4F invproj_matrix;
177 | Matrix4F tileproj_matrix; // tiled projection matrix
178 | Matrix4F model_matrix;
179 | Matrix4F mv_matrix;
180 | float frustum[6][4]; // frustum plane equations
181 |
182 | bool mOps[8];
183 | int mWire;
184 |
185 | Vector3DF origRayWorld;
186 | Vector4DF tlRayWorld;
187 | Vector4DF trRayWorld;
188 | Vector4DF blRayWorld;
189 | Vector4DF brRayWorld;
190 | };
191 |
192 | typedef Camera3D Light;
193 |
194 | #endif
195 |
--------------------------------------------------------------------------------
/libmin/include/common_cuda.h:
--------------------------------------------------------------------------------
1 |
2 | #ifdef USE_CUDA
3 | #ifndef DEF_MAIN_CUDA
4 | #define DEF_MAIN_CUDA
5 |
6 |
7 | #include
8 | #include
9 |
10 | #define DEV_FIRST -1
11 | #define DEV_CURRENT -2
12 | #define DEV_EXISTING -3
13 |
14 | HELPAPI bool cuCheck(CUresult launch_stat, char* method, char* apicall, char* arg, bool bDebug);
15 | HELPAPI void cuStart(int devsel, CUcontext ctxsel, CUdevice& dev, CUcontext& ctx, CUstream* strm, bool verbose);
16 | HELPAPI void cuGetMemUsage(int& total, int& used, int& free);
17 |
18 | #endif
19 | #endif
--------------------------------------------------------------------------------
/libmin/include/common_defs.h:
--------------------------------------------------------------------------------
1 |
2 |
3 | #ifndef DEF_COMMON
4 | #define DEF_COMMON
5 |
6 | #pragma warning ( disable: 4005)
7 |
8 | #ifdef _WIN32
9 |
10 | #define WIN32_LEAN_AND_MEAN
11 | #include
12 | #undef WIN32_LEAN_AND_MEAN
13 |
14 | #pragma warning ( disable : 4800 ) // cast to bool performance warning
15 | #pragma warning ( disable : 4996 ) // fopen_s, strcpy_s (not linux compatible)
16 | #pragma warning ( disable : 4244 ) // conversion from double to float
17 | #pragma warning ( disable : 4305 ) // truncation from double to float (constants)
18 | #pragma warning ( disable : 4251 ) // STL objects inside DLL-interface classes
19 |
20 | #if !defined ( LIBHELP_STATIC )
21 | #if defined ( LIBHELP_EXPORTS ) // inside DLL
22 | #if defined(_WIN32) || defined(__CYGWIN__)
23 | #define HELPAPI __declspec(dllexport)
24 | #else
25 | #define HELPAPI __attribute__((visibility("default")))
26 | #endif
27 | #else // outside DLL
28 | #if defined(_WIN32) || defined(__CYGWIN__)
29 | #define HELPAPI __declspec(dllimport)
30 | #else
31 | #define HELPAPI //https://stackoverflow.com/questions/2164827/explicitly-exporting-shared-library-functions-in-linux
32 | #endif
33 | #endif
34 | #else
35 | #define HELP_API
36 | #endif
37 |
38 | #include "inttypes.h"
39 |
40 | #define ALIGN(x) __declspec(align(x))
41 | #define CACHE_ALIGNED __declspec(align(64))
42 |
43 | typedef signed char sint8_t;
44 | typedef signed short sint16_t;
45 | typedef signed int sint32_t;
46 | typedef signed long sint64_t;
47 |
48 | typedef unsigned char uchar;
49 | typedef uint64_t xlong;
50 | typedef uint8_t XCHAR;
51 | typedef uint8_t XBYTE;
52 | typedef uint16_t XBYTE2;
53 | typedef uint32_t XBYTE4;
54 | typedef uint64_t XBYTE8;
55 | typedef sint8_t schar;
56 | typedef sint16_t sshort;
57 | typedef sint32_t sint;
58 | typedef sint64_t slong;
59 | typedef uint8_t uchar;
60 | typedef uint16_t ushort;
61 | typedef uint32_t uint;
62 | typedef uint64_t uxlong; // note: keyword 'ulong' cannot be used with NV_ARM. 'slong' is signed, dont use here
63 |
64 | #define FALSE 0
65 | #define TRUE 1
66 |
67 | // DWORD included from windows.h (32-bit unsigned int)
68 |
69 | #else // ANDOID and linux
70 |
71 | #define ALIGN(x) __attribute__ ((aligned(x)))
72 | #define CACHE_ALIGNED __attribute__ ((aligned(64)))
73 |
74 | #include "inttypes.h"
75 |
76 | // typedef __s64 xlong;
77 | typedef unsigned long long xlong;
78 | typedef unsigned char XCHAR;
79 | typedef unsigned char XBYTE; // 8-bit
80 | typedef unsigned short XBYTE2; // 16-bit
81 | typedef unsigned long XBYTE4; // 32-bit
82 | typedef long long XBYTE8; // 64-bit
83 | typedef XBYTE4 DWORD;
84 |
85 | #define FALSE 0
86 | #define TRUE 1
87 |
88 | typedef uint8_t uchar;
89 | typedef uint16_t ushort;
90 | typedef uint32_t uint;
91 | typedef uint64_t uxlong;
92 |
93 | typedef int8_t schar;
94 | typedef int16_t sshort;
95 | typedef int32_t sint;
96 | typedef int64_t slong;
97 |
98 | // avoids Clang warnings
99 | #define __cdecl
100 | #define __stdcall
101 |
102 | #include // for va_start, va_args
103 |
104 | #endif
105 |
106 | typedef float f32;
107 | typedef double f64;
108 |
109 | const f32 ROUNDING_ERROR_f32 = 0.000001f;
110 | const f64 ROUNDING_ERROR_f64 = 0.00000001;
111 | const f64 PI64 = 3.1415926535897932384626433832795028841971693993751;
112 |
113 |
114 | //--- OpenGL include
115 | #ifdef USE_OPENGL
116 | #if defined(__ANDROID__)
117 | #include
118 | #include
119 | #elif defined(__linux__)
120 |
121 | #elif defined(_WIN32)
122 | #include
123 | #include
124 | #endif
125 | #endif
126 |
127 | // Universal functions
128 | #include
129 | #include
130 | HELPAPI void checkMem( xlong& total, xlong& used, xlong& app);
131 | HELPAPI char getPathDelim();
132 | HELPAPI void addSearchPath ( const char* path );
133 | HELPAPI bool getFileLocation ( const char* filename, char* outpath );
134 | HELPAPI bool getFileLocation ( const char* filename, char* outpath, std::vector paths );
135 | HELPAPI bool getFileLocation ( const std::string filename, std::string &outpath );
136 | HELPAPI unsigned long getFileSize ( const std::string filename );
137 | HELPAPI unsigned long getFilePos ( FILE* fp );
138 | HELPAPI void dbgprintf(const char * fmt, ...);
139 |
140 | // Basic OpenGL interface
141 | HELPAPI void checkGL(const char* msg);
142 | HELPAPI void initTexGL();
143 | HELPAPI void clearGL();
144 | HELPAPI void createTexGL(int& glid, int w, int h, int clamp = 0x812D, int fmt = 0x8058, int typ = 0x1401, int filter = 0x2601); // defaults: GL_CLAMP_TO_BORDER, GL_RGBA8, GL_UNSIGNED_BYTE, GL_LINEAR
145 | HELPAPI void renderTexGL(int w, int h, int glid, char inv1 = 0);
146 | HELPAPI void renderTexGL(float x1, float y1, float x2, float y2, int glid1, char inv1 = 0);
147 | HELPAPI void compositeTexGL(float blend, int w, int h, int glid1, int glid2, char inv1 = 0, char inv2 = 0); // composite two textures
148 |
149 | struct HELPAPI TexInterface {
150 | int prog[3];
151 | int vshader[3];
152 | int fshader[3];
153 | int vbo[3];
154 | int utex1[3];
155 | int utex2[3];
156 | int utexflags[3];
157 | int ucoords[3];
158 | int uscreen[3];
159 | };
160 |
161 | HELPAPI void strncpy_sc ( char *dst, const char *src, size_t len); // cross-platform
162 | HELPAPI void strncpy_sc (char *dst, size_t dstsz, const char *src, size_t count ); // cross-platform
163 |
164 | // mathematical macros & inlines
165 | #ifndef imax
166 | #define imax(a,b) (((a) > (b)) ? (a) : (b))
167 | #endif
168 | #ifndef imin
169 | #define imin(a,b) (((a) < (b)) ? (a) : (b))
170 | #endif
171 | inline f64 clamp(f64 value, f64 low, f64 high) { return imin(imax(value, low), high); }
172 |
173 | inline bool fequal(double a, double b, double eps) { return (fabs(a - b) < eps); }
174 |
175 | inline float fast_inv_squareroot (float number) {
176 | long i;
177 | float x2, y;
178 | const float threehalfs = 1.5F;
179 | x2 = number * 0.5F; y = number;
180 | i = *(long*)&y; i = 0x5f3759df - (i >> 1);
181 | y = *(float*)&i; y = y * (threehalfs - (x2 * y * y));
182 | #ifndef Q3_VM
183 | #ifdef __linux__
184 | assert(!isnan(y));
185 | #endif
186 | #endif
187 | return y;
188 | }
189 |
190 | // color storage in 4-byte uint
191 | typedef uint32_t CLRVAL;
192 | #ifndef COLOR
193 | #define COLOR(r,g,b) ( (uint(r*255.0f)<<24) | (uint(g*255.0f)<<16) | (uint(b*255.0f)<<8) )
194 | #endif
195 | #ifndef COLORA
196 | #define COLORA(r,g,b,a) ( (uint(a*255.0f)<<24) | (uint(b*255.0f)<<16) | (uint(g*255.0f)<<8) | uint(r*255.0f) )
197 | #endif
198 | #define ALPH(c) (float((c>>24) & 0xFF)/255.0)
199 | #define BLUE(c) (float((c>>16) & 0xFF)/255.0)
200 | #define GRN(c) (float((c>>8) & 0xFF)/255.0)
201 | #define RED(c) (float( c & 0xFF)/255.0)
202 | #ifndef CLRVEC
203 | #define CLRVEC(c) ( Vector4DF( RED(c), GRN(c), BLUE(c), ALPH(c) ) )
204 | #endif
205 | #ifndef VECCLR
206 | #define VECCLR(v) ( COLORA( v.x, v.y, v.z, v.w ) )
207 | #endif
208 |
209 | // math defs
210 | #ifndef PI
211 | #define PI (3.14159265358979f) // sometimes useful :)
212 | #endif
213 | #ifndef DEGtoRAD
214 | #define DEGtoRAD (3.14159265358979f/180.0f)
215 | #endif
216 | #ifndef RADtoDEG
217 | #define RADtoDEG (180.0f/3.14159265358979f)
218 | #endif
219 |
220 | #endif
221 |
--------------------------------------------------------------------------------
/libmin/include/dataptr.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef DEF_DATAPTR_H
3 | #define DEF_DATAPTR_H
4 |
5 | #include "common_defs.h"
6 | #include
7 | #include
8 | #include
9 | #include "vec.h"
10 | #ifdef USE_CUDA
11 | #include "cuda.h"
12 | #define PUSH_CTX cuCtxPushCurrent(cuCtx);
13 | #define POP_CTX CUcontext pctx; cuCtxPopCurrent(&pctx);
14 | #else
15 | #define PUSH_CTX
16 | #define POP_CTX
17 | #endif
18 |
19 | #define DT_MISC 0
20 | #define DT_UCHAR 1 // 8-bit
21 | #define DT_USHORT 2 // 16-bit
22 | #define DT_UCHAR3 3 // 24-bit
23 |
24 | #define DT_UCHAR4 4 // 32-bit, 4 bytes, 4*sizeof(char)
25 | #define DT_INT 5 // 32-bit, 4 bytes, 1*sizeof(int32_t)
26 | #define DT_UINT 6 // 32-bit, 4 bytes, 1*sizeof(uint32_t)
27 | #define DT_FLOAT 7 // 32-bit, 4 bytes, 1*sizeof(float)
28 |
29 | #define DT_UINT64 8 // 64-bit, 8 bytes, 1*sizeof(uint64_t)
30 | #define DT_FLOAT3 12 // 96-bit, 12 bytes, 3*sizeof(float)
31 | #define DT_FLOAT4 16 // 128-bit, 16 bytes, 4*sizeof(float)
32 |
33 | #define DT_CPU 1 // use flags
34 | #define DT_CUMEM 2
35 | #define DT_CUARRAY 4
36 | #define DT_GLTEX 8
37 | #define DT_GLVBO 16
38 |
39 | class HELPAPI DataPtr {
40 | public:
41 | DataPtr() { mNum=0; mMax=0; mStride=0; mUseRes.Set(0,0,0); mUseType=DT_MISC; mUseFlags=DT_MISC;
42 | mSize=0; mCpu=0;
43 | #ifdef USE_CUDA
44 | mGpu=0; mGrsc=0; mGarray=0; mGLID=-1; mGtex = -1; mGsurf = -1;
45 | #endif
46 | }
47 | ~DataPtr();
48 |
49 | void Resize ( int stride, uint64_t cnt, char* dat=0x0, uchar dest_flags=DT_CPU );
50 | int Append ( int stride, uint64_t cnt, char* dat=0x0, uchar dest_flags=DT_CPU );
51 | void SetUsage ( uchar dt, uchar flags=DT_MISC, Vector3DI res = Vector3DI(-1,-1,-1) ); // special usage (2D,3D,GLtex,GLvbo,etc.)
52 | void UpdateUsage ( uchar flags );
53 | void ReallocateCPU ( uint64_t oldsz, uint64_t newsz );
54 | void FillBuffer ( uchar v );
55 | void CopyTo ( DataPtr* dest, uchar dest_flags );
56 | void Commit ();
57 | void Retrieve ();
58 | void Clear ();
59 |
60 | int getStride ( uchar dtype );
61 | uint64_t getDataSz ( int cnt, int stride ) { return (uint64_t) cnt * stride; }
62 |
63 | int getNum() { return mNum; }
64 | int getMax() { return mMax; }
65 | char* getData() { return mCpu; }
66 | #ifdef USE_CUDA
67 | CUdeviceptr getGPU() { return mGpu; }
68 | #endif
69 | char* getPtr(int n) { return mCpu + n*mStride; }
70 |
71 | public:
72 | uint64_t mNum, mMax, mSize;
73 | int mStride;
74 | uchar mRefID, mUseType, mUseFlags; // usage
75 | Vector3DI mUseRes;
76 | bool bCpu, bGpu;
77 | char* mCpu;
78 |
79 | int mGLID; // OpenGL
80 |
81 | #ifdef USE_CUDA
82 | CUdeviceptr mGpu; // CUDA
83 | CUgraphicsResource mGrsc; // CUDA-GL interop
84 | CUarray mGarray;
85 | CUtexObject mGtex; // CUDA texture/surface interop
86 | CUsurfObject mGsurf;
87 | #endif
88 |
89 | static int mFBO;
90 | };
91 |
92 | #endif
93 |
94 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/libmin/include/directory.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef DEF_DIR_OBJECT
3 | #define DEF_DIR_OBJECT
4 |
5 | #include "common_defs.h"
6 | #include
7 | #include
8 |
9 | #define FILE_TYPE_DIR 0
10 | #define FILE_TYPE_FILE 1
11 |
12 | // Hmmm - have to factor this specific stuff out.
13 | #define FILE_TYPE_BLOCKSAVE 2
14 | #define FILE_TYPE_BLOCKLEV 3
15 |
16 | typedef struct {
17 | int type;
18 | std::string text;
19 | std::string extension;
20 | int length;
21 | } dir_list_element;
22 |
23 | typedef std::vector< dir_list_element > dir_list;
24 |
25 | typedef struct {
26 | std::string text;
27 | float length;
28 | } text_element_t;
29 |
30 | typedef std::vector< text_element_t > elem_vec_t;
31 |
32 |
33 | class HELPAPI Directory {
34 | public:
35 | Directory ();
36 |
37 | void LoadDir ( std::string path, std::string filter );
38 | int CreateDir ( std::string path );
39 | int getNumFiles () { return (int) mList.size(); }
40 | dir_list_element getFile ( int n ) { return mList[n]; }
41 | bool isDir ( int n ) { return mList[n].type==0; }
42 |
43 | // Static functions
44 | static dir_list DirList( std::string path, std::string filter );
45 | static bool FileExists( std::string filename );
46 | static std::string ws2s(const std::wstring& s);
47 | static std::wstring s2ws(const std::string& s);
48 | static dir_list GetFileItems( dir_list input);
49 | static dir_list GetDirectoryItems( dir_list input);
50 | static std::string NormalizeSlashies( std::string path );
51 | static std::string GetExtension( std::string path );
52 | static std::string GetExecutablePath();
53 | static std::string GetCollapsedPath( std::string path );
54 | static std::string gPathDelim;
55 |
56 | std::string getPath () { return mPath; }
57 | std::string getFilter () { return mFileFilter; }
58 |
59 | private:
60 |
61 | std::string mPath;
62 | std::string mFileFilter;
63 |
64 |
65 | dir_list mList;
66 |
67 | };
68 |
69 | #endif
70 |
--------------------------------------------------------------------------------
/libmin/include/event.h:
--------------------------------------------------------------------------------
1 | //---------------------------------------------------------------------
2 | //
3 | // Event System
4 | // Quanta Sciences, Rama Hoetzlein (c) 2007-2020
5 | //
6 | //---------------------------------------------------------------------
7 |
8 |
9 | #ifndef DEF_EVENT_H
10 | #define DEF_EVENT_H
11 |
12 | #include "common_defs.h"
13 | #include "vec.h"
14 | #include "timex.h"
15 | #include
16 |
17 | #define NULL_TARGET 65535
18 | #define ID(y) ( (const xlong) *( (const xlong*) y ) ) // for 64-bit names, but not a const expression
19 |
20 | // Event typedefs
21 | typedef TimeX timeStamp_t;
22 | typedef uint32_t eventStr_t;
23 | typedef unsigned long netIP;
24 | typedef signed int netPort;
25 | typedef signed int netSock;
26 | typedef uint16_t sysID_t; // locally assigned ID
27 | typedef uint32_t objType;
28 | typedef uint8_t datType;
29 |
30 | class EventPool;
31 |
32 | // Event names
33 | std::string nameToStr ( eventStr_t name );
34 | eventStr_t strToName ( std::string str );
35 |
36 | // Event
37 | struct HELPAPI CACHE_ALIGNED Event {
38 | public:
39 | Event ();
40 | Event ( const Event& src );
41 | Event& operator= ( const Event* op ); // assignment (not acquire)
42 | Event& operator= ( const Event& op );
43 | ~Event ();
44 | void copyEventVars ( Event* dst, const Event* src );
45 | void acquire ( Event& esrc); // acquire - transfer of ownership
46 |
47 | // Event Accessors
48 | std::string getNameStr ();
49 | std::string getSysStr ();
50 | inline eventStr_t getName () { return mName; }
51 | inline eventStr_t getTarget () { return mTarget; }
52 | inline sysID_t getTargetID () { return mTargetID; }
53 | inline timeStamp_t getTimeStamp() { return mTimeStamp; }
54 | inline EventPool* getPool() { return mOwner; }
55 | inline void set ( eventStr_t targ, eventStr_t name ) { mTarget = targ; mName = name; }
56 | inline void setName ( eventStr_t x ) { mName = x; }
57 | inline void setTarget ( eventStr_t x ) { mTarget = x; }
58 | inline void setTargetID ( sysID_t t ) { mTargetID = t; }
59 | inline void setTimeStamp ( timeStamp_t t ) { mTimeStamp = t; }
60 |
61 | // Event Reference counting
62 | inline int incRefs () { return ++mRefs; }
63 | inline int decRefs () { return --mRefs; }
64 | inline int getRefs () { return mRefs; }
65 |
66 | // Data Access
67 | void startRead ();
68 | void startWrite ();
69 | void expand ( int s );
70 | char* serialize ();
71 | void deserialize ( char* buf, int len );
72 | void rescope ( char* scope ) { memcpy ( mScope, scope, 4 ); mScope[4]='\0'; }
73 | //int getEventLenOffs () { return int((char*) &mDataLen - (char*) &mTarget); }
74 | char* getData () { return mData; }
75 | char* getPos() { return mPos; }
76 | unsigned long getPosInt() { return mPos - mData; }
77 | char* getEndPos () { return getData() + mMax; }
78 | bool isEnd () { return mPos >= getData() + mDataLen; }
79 | bool isEmpty () { return mData == 0x0; }
80 | int getDataLength () { return mDataLen; } // daata payload
81 | int getPayloadLength() { return mDataLen; } // synonym
82 | int getSerializedLength () { return mDataLen + Event::staticSerializedHeaderSize(); } // length of network packet data
83 | char* getSerializedData () { return mData - Event::staticSerializedHeaderSize(); }
84 |
85 | // Get/set
86 | inline void setDataLength (int n ) { mDataLen = n; }
87 | inline void setPos (int offs) { mPos = mData + offs; }
88 | inline void setPos (char* pos ) { mPos = pos; }
89 | inline timeStamp_t getTime () { return mTimeStamp; }
90 | inline void setTime ( timeStamp_t t ) { mTimeStamp = t; }
91 | void setTime ( unsigned long t );
92 | inline void setConnection ( unsigned short id ) { mConnection = id; }
93 | inline ushort getConnection () { return mConnection; }
94 | inline void setSrcIP ( netIP ip ) { mSrcIP = ip; }
95 | inline void setSrcSock ( netSock s ) { mSrcSock = s; }
96 | inline netIP getSrcIP () { return mSrcIP; }
97 | inline netSock getSrcSock () { return mSrcSock; }
98 |
99 | // Data Attach/Retrieve
100 | void attachBool (bool b);
101 | void attachInt (int i);
102 | void attachShort (signed short i );
103 | void attachUChar (unsigned char i );
104 | void attachUShort (unsigned short i );
105 | void attachULong (unsigned long i );
106 | void attachUInt (unsigned int i );
107 | void attachInt64 (xlong i);
108 | void attachFloat (float f);
109 | void attachDouble (double d);
110 | void attachStr (std::string str );
111 | void attachPrintf (const char* format, ... );
112 | void attachVec4 (Vector4DF i );
113 | void attachMem (char* buf, int len );
114 | void attachBuf (char* buf, int len );
115 | void attachBufAtPos (int pos, char* buf, int len );
116 | void writeUShort (int pos, unsigned short i ); // does not increase length
117 | void attachFromFile (FILE* fp, int len );
118 |
119 | bool getBool ();
120 | int getInt ();
121 | signed short getShort ();
122 | unsigned char getUChar ();
123 | unsigned short getUShort ();
124 | unsigned int getUInt ();
125 | unsigned long getULong ();
126 | xlong getInt64 ();
127 | float getFloat ();
128 | double getDouble ();
129 | Vector4DF getVec4 ();
130 | std::string getStr ();
131 | void getStr (char* str );
132 | void getMem (char* buf, int len );
133 | void getBuf (char* buf, int len );
134 | void getBufAtPos (int pos, char* buf, int len );
135 |
136 | // Serialized header length. Must match platform size of member vars
137 | static int staticSerializedHeaderSize() { return 2*sizeof(int) + 2*sizeof(eventStr_t) + sizeof(timeStamp_t); }
138 | static int staticOffsetLenInfo() { return 0; } // <-- assumes mDataLen is first
139 |
140 | // **** NOTE ***
141 | // !! ORDER OF MEMBERS IS IMPORTANT HERE !!
142 | // Serialized first. mDataLen first member.
143 |
144 | // Serialized members
145 | // Header: Offset Bytes
146 | int mDataLen; // Event length 32+ 0 4 // <-- offsetDataLen (!)
147 | eventStr_t mName; // Event name 32+ 4 4
148 | eventStr_t mTarget; // Event target system 32+ 8 4
149 | int mConnection; // Event connection 32+ 12 4
150 | timeStamp_t mTimeStamp; // Event time stamp 32+ 16 8
151 | // 56 24 byte // <-- offsetHeader (!)
152 | // Data payload is pre-pended with serialized members
153 | char* mData; // Data payload (elsewhere in memory)
154 |
155 | // Non-serialized members
156 | ushort mRefs; // Ref counting (max: 65535)
157 | ushort mSrcSock; // Source Socket (max: 65535)
158 | netIP mSrcIP; // Source IP
159 | sysID_t mTargetID; // Target ID
160 | int mMax; // Data max
161 | EventPool* mOwner; // Memory pool owner
162 | bool bOwn; // Owner info
163 | bool bDestroy; // Destroy
164 | char mScope[5]; // Scope info
165 | char* mPos; // Data pos
166 | };
167 |
168 |
169 |
170 | #endif
171 |
--------------------------------------------------------------------------------
/libmin/include/event_system.h:
--------------------------------------------------------------------------------
1 | //---------------------------------------------------------------------
2 | //
3 | // Event System
4 | // Quanta Sciences, Rama Hoetzlein (c) 2007-2020
5 | //
6 | //---------------------------------------------------------------------
7 |
8 |
9 | //#define BUILD_EVENT_POOLING // Enable/disable compiliation of Event Pooling
10 |
11 | //#define USE_EVENT_POOLING // Enable or disable event pooling
12 |
13 | #ifndef DEF_EVENT_SYSTEM_H
14 | #define DEF_EVENT_SYSTEM_H
15 |
16 | #include