├── .gitignore
├── example-closest
├── Makefile
├── Project.xcconfig
├── addons.make
├── config.make
├── example-closest.xcodeproj
│ ├── project.pbxproj
│ └── xcshareddata
│ │ └── xcschemes
│ │ ├── example-closest Debug.xcscheme
│ │ └── example-closest Release.xcscheme
├── openFrameworks-Info.plist
└── src
│ ├── main.cpp
│ ├── ofApp.cpp
│ └── ofApp.h
├── example-radius
├── Makefile
├── Project.xcconfig
├── addons.make
├── config.make
├── example-radius.xcodeproj
│ ├── project.pbxproj
│ └── xcshareddata
│ │ └── xcschemes
│ │ ├── example-radius Debug.xcscheme
│ │ └── example-radius Release.xcscheme
├── openFrameworks-Info.plist
└── src
│ ├── main.cpp
│ ├── ofApp.cpp
│ └── ofApp.h
├── libs
└── nanoflann
│ └── include
│ └── nanoflann.hpp
├── readme.md
└── src
├── NearestNeighbour.h
├── PointCloud.h
└── ofxNearestNeighbour.h
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | */.DS_Store
3 | */bin
4 | */*/xcuserdata
5 | */*/*/xcuserdata
6 | */*/*/xcuserdata
7 | */.idea
8 |
--------------------------------------------------------------------------------
/example-closest/Makefile:
--------------------------------------------------------------------------------
1 | # Attempt to load a config.make file.
2 | # If none is found, project defaults in config.project.make will be used.
3 | ifneq ($(wildcard config.make),)
4 | include config.make
5 | endif
6 |
7 | # make sure the the OF_ROOT location is defined
8 | ifndef OF_ROOT
9 | OF_ROOT=../../..
10 | endif
11 |
12 | # call the project makefile!
13 | include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk
14 |
--------------------------------------------------------------------------------
/example-closest/Project.xcconfig:
--------------------------------------------------------------------------------
1 | //THE PATH TO THE ROOT OF OUR OF PATH RELATIVE TO THIS PROJECT.
2 | //THIS NEEDS TO BE DEFINED BEFORE CoreOF.xcconfig IS INCLUDED
3 | OF_PATH = ../../..
4 |
5 | //THIS HAS ALL THE HEADER AND LIBS FOR OF CORE
6 | #include "../../../libs/openFrameworksCompiled/project/osx/CoreOF.xcconfig"
7 |
8 | //ICONS - NEW IN 0072
9 | ICON_NAME_DEBUG = icon-debug.icns
10 | ICON_NAME_RELEASE = icon.icns
11 | ICON_FILE_PATH = $(OF_PATH)/libs/openFrameworksCompiled/project/osx/
12 |
13 | //IF YOU WANT AN APP TO HAVE A CUSTOM ICON - PUT THEM IN YOUR DATA FOLDER AND CHANGE ICON_FILE_PATH to:
14 | //ICON_FILE_PATH = bin/data/
15 |
16 | OTHER_CFLAGS = $(OF_CORE_CFLAGS)
17 | OTHER_LDFLAGS = $(OF_CORE_LIBS) $(OF_CORE_FRAMEWORKS)
18 | HEADER_SEARCH_PATHS = $(OF_CORE_HEADERS)
19 |
--------------------------------------------------------------------------------
/example-closest/addons.make:
--------------------------------------------------------------------------------
1 | ofxNearestNeighbour
2 |
--------------------------------------------------------------------------------
/example-closest/config.make:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # CONFIGURE PROJECT MAKEFILE (optional)
3 | # This file is where we make project specific configurations.
4 | ################################################################################
5 |
6 | ################################################################################
7 | # OF ROOT
8 | # The location of your root openFrameworks installation
9 | # (default) OF_ROOT = ../../..
10 | ################################################################################
11 | # OF_ROOT = ../../..
12 |
13 | ################################################################################
14 | # PROJECT ROOT
15 | # The location of the project - a starting place for searching for files
16 | # (default) PROJECT_ROOT = . (this directory)
17 | #
18 | ################################################################################
19 | # PROJECT_ROOT = .
20 |
21 | ################################################################################
22 | # PROJECT SPECIFIC CHECKS
23 | # This is a project defined section to create internal makefile flags to
24 | # conditionally enable or disable the addition of various features within
25 | # this makefile. For instance, if you want to make changes based on whether
26 | # GTK is installed, one might test that here and create a variable to check.
27 | ################################################################################
28 | # None
29 |
30 | ################################################################################
31 | # PROJECT EXTERNAL SOURCE PATHS
32 | # These are fully qualified paths that are not within the PROJECT_ROOT folder.
33 | # Like source folders in the PROJECT_ROOT, these paths are subject to
34 | # exlclusion via the PROJECT_EXLCUSIONS list.
35 | #
36 | # (default) PROJECT_EXTERNAL_SOURCE_PATHS = (blank)
37 | #
38 | # Note: Leave a leading space when adding list items with the += operator
39 | ################################################################################
40 | # PROJECT_EXTERNAL_SOURCE_PATHS =
41 |
42 | ################################################################################
43 | # PROJECT EXCLUSIONS
44 | # These makefiles assume that all folders in your current project directory
45 | # and any listed in the PROJECT_EXTERNAL_SOURCH_PATHS are are valid locations
46 | # to look for source code. The any folders or files that match any of the
47 | # items in the PROJECT_EXCLUSIONS list below will be ignored.
48 | #
49 | # Each item in the PROJECT_EXCLUSIONS list will be treated as a complete
50 | # string unless teh user adds a wildcard (%) operator to match subdirectories.
51 | # GNU make only allows one wildcard for matching. The second wildcard (%) is
52 | # treated literally.
53 | #
54 | # (default) PROJECT_EXCLUSIONS = (blank)
55 | #
56 | # Will automatically exclude the following:
57 | #
58 | # $(PROJECT_ROOT)/bin%
59 | # $(PROJECT_ROOT)/obj%
60 | # $(PROJECT_ROOT)/%.xcodeproj
61 | #
62 | # Note: Leave a leading space when adding list items with the += operator
63 | ################################################################################
64 | # PROJECT_EXCLUSIONS =
65 |
66 | ################################################################################
67 | # PROJECT LINKER FLAGS
68 | # These flags will be sent to the linker when compiling the executable.
69 | #
70 | # (default) PROJECT_LDFLAGS = -Wl,-rpath=./libs
71 | #
72 | # Note: Leave a leading space when adding list items with the += operator
73 | ################################################################################
74 |
75 | # Currently, shared libraries that are needed are copied to the
76 | # $(PROJECT_ROOT)/bin/libs directory. The following LDFLAGS tell the linker to
77 | # add a runtime path to search for those shared libraries, since they aren't
78 | # incorporated directly into the final executable application binary.
79 | # TODO: should this be a default setting?
80 | # PROJECT_LDFLAGS=-Wl,-rpath=./libs
81 |
82 | ################################################################################
83 | # PROJECT DEFINES
84 | # Create a space-delimited list of DEFINES. The list will be converted into
85 | # CFLAGS with the "-D" flag later in the makefile.
86 | #
87 | # (default) PROJECT_DEFINES = (blank)
88 | #
89 | # Note: Leave a leading space when adding list items with the += operator
90 | ################################################################################
91 | # PROJECT_DEFINES =
92 |
93 | ################################################################################
94 | # PROJECT CFLAGS
95 | # This is a list of fully qualified CFLAGS required when compiling for this
96 | # project. These CFLAGS will be used IN ADDITION TO the PLATFORM_CFLAGS
97 | # defined in your platform specific core configuration files. These flags are
98 | # presented to the compiler BEFORE the PROJECT_OPTIMIZATION_CFLAGS below.
99 | #
100 | # (default) PROJECT_CFLAGS = (blank)
101 | #
102 | # Note: Before adding PROJECT_CFLAGS, note that the PLATFORM_CFLAGS defined in
103 | # your platform specific configuration file will be applied by default and
104 | # further flags here may not be needed.
105 | #
106 | # Note: Leave a leading space when adding list items with the += operator
107 | ################################################################################
108 | # PROJECT_CFLAGS =
109 |
110 | ################################################################################
111 | # PROJECT OPTIMIZATION CFLAGS
112 | # These are lists of CFLAGS that are target-specific. While any flags could
113 | # be conditionally added, they are usually limited to optimization flags.
114 | # These flags are added BEFORE the PROJECT_CFLAGS.
115 | #
116 | # PROJECT_OPTIMIZATION_CFLAGS_RELEASE flags are only applied to RELEASE targets.
117 | #
118 | # (default) PROJECT_OPTIMIZATION_CFLAGS_RELEASE = (blank)
119 | #
120 | # PROJECT_OPTIMIZATION_CFLAGS_DEBUG flags are only applied to DEBUG targets.
121 | #
122 | # (default) PROJECT_OPTIMIZATION_CFLAGS_DEBUG = (blank)
123 | #
124 | # Note: Before adding PROJECT_OPTIMIZATION_CFLAGS, please note that the
125 | # PLATFORM_OPTIMIZATION_CFLAGS defined in your platform specific configuration
126 | # file will be applied by default and further optimization flags here may not
127 | # be needed.
128 | #
129 | # Note: Leave a leading space when adding list items with the += operator
130 | ################################################################################
131 | # PROJECT_OPTIMIZATION_CFLAGS_RELEASE =
132 | # PROJECT_OPTIMIZATION_CFLAGS_DEBUG =
133 |
134 | ################################################################################
135 | # PROJECT COMPILERS
136 | # Custom compilers can be set for CC and CXX
137 | # (default) PROJECT_CXX = (blank)
138 | # (default) PROJECT_CC = (blank)
139 | # Note: Leave a leading space when adding list items with the += operator
140 | ################################################################################
141 | # PROJECT_CXX =
142 | # PROJECT_CC =
143 |
--------------------------------------------------------------------------------
/example-closest/example-closest.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | archiveVersion
5 | 1
6 | classes
7 |
8 | objectVersion
9 | 46
10 | objects
11 |
12 | BD177D4812B4A02EA74827C7
13 |
14 | children
15 |
16 | A999FD3AA9430DF3DD79FDB1
17 |
18 | isa
19 | PBXGroup
20 | name
21 | include
22 | sourceTree
23 | <group>
24 |
25 | 4EBFD7E21A9DC0266BFB206E
26 |
27 | children
28 |
29 | BD177D4812B4A02EA74827C7
30 |
31 | isa
32 | PBXGroup
33 | name
34 | nanoflann
35 | sourceTree
36 | <group>
37 |
38 | FF311434F6080480F1E6B0DA
39 |
40 | children
41 |
42 | 4EBFD7E21A9DC0266BFB206E
43 |
44 | isa
45 | PBXGroup
46 | name
47 | libs
48 | sourceTree
49 | <group>
50 |
51 | A999FD3AA9430DF3DD79FDB1
52 |
53 | explicitFileType
54 | sourcecode.c.h
55 | fileEncoding
56 | 30
57 | isa
58 | PBXFileReference
59 | name
60 | nanoflann.hpp
61 | path
62 | ../../../addons/ofxNearestNeighbour/libs/nanoflann/include/nanoflann.hpp
63 | sourceTree
64 | SOURCE_ROOT
65 |
66 | 967BF5D5A05B88613BAB0BF6
67 |
68 | explicitFileType
69 | sourcecode.c.h
70 | fileEncoding
71 | 30
72 | isa
73 | PBXFileReference
74 | name
75 | PointCloud.h
76 | path
77 | ../../../addons/ofxNearestNeighbour/src/PointCloud.h
78 | sourceTree
79 | SOURCE_ROOT
80 |
81 | 0AFFFAC1F8BCCA02B87F6521
82 |
83 | explicitFileType
84 | sourcecode.c.h
85 | fileEncoding
86 | 30
87 | isa
88 | PBXFileReference
89 | name
90 | ofxNearestNeighbour.h
91 | path
92 | ../../../addons/ofxNearestNeighbour/src/ofxNearestNeighbour.h
93 | sourceTree
94 | SOURCE_ROOT
95 |
96 | 92EEB4240BA473E0C8052C5B
97 |
98 | children
99 |
100 | C7EB216AF3C37F5BEF455F61
101 | 0AFFFAC1F8BCCA02B87F6521
102 | 967BF5D5A05B88613BAB0BF6
103 |
104 | isa
105 | PBXGroup
106 | name
107 | src
108 | sourceTree
109 | <group>
110 |
111 | 3D3BA77954B2B04C9E000907
112 |
113 | children
114 |
115 | 92EEB4240BA473E0C8052C5B
116 | FF311434F6080480F1E6B0DA
117 |
118 | isa
119 | PBXGroup
120 | name
121 | ofxNearestNeighbour
122 | sourceTree
123 | <group>
124 |
125 | C7EB216AF3C37F5BEF455F61
126 |
127 | explicitFileType
128 | sourcecode.c.h
129 | fileEncoding
130 | 30
131 | isa
132 | PBXFileReference
133 | name
134 | NearestNeighbour.h
135 | path
136 | ../../../addons/ofxNearestNeighbour/src/NearestNeighbour.h
137 | sourceTree
138 | SOURCE_ROOT
139 |
140 | 6948EE371B920CB800B5AC1A
141 |
142 | children
143 |
144 | isa
145 | PBXGroup
146 | name
147 | local_addons
148 | sourceTree
149 | <group>
150 |
151 | 8466F1851C04CA0E00918B1C
152 |
153 | buildActionMask
154 | 12
155 | files
156 |
157 | inputPaths
158 |
159 | isa
160 | PBXShellScriptBuildPhase
161 | outputPaths
162 |
163 | runOnlyForDeploymentPostprocessing
164 | 0
165 | shellPath
166 | /bin/sh
167 | shellScript
168 | echo "$GCC_PREPROCESSOR_DEFINITIONS";
169 | APPSTORE=`expr "$GCC_PREPROCESSOR_DEFINITIONS" : ".*APPSTORE=\([0-9]*\)"`
170 | if [ -z "$APPSTORE" ] ; then
171 | echo "Note: Not copying bin/data to App Package or doing App Code signing. Use AppStore target for AppStore distribution";
172 | else
173 | # Copy bin/data into App/Resources
174 | rsync -avz --exclude='.DS_Store' "${SRCROOT}/bin/data/" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/data/"
175 |
176 | # ---- Code Sign App Package ----
177 |
178 | # WARNING: You may have to run Clean in Xcode after changing CODE_SIGN_IDENTITY!
179 |
180 | # Verify that $CODE_SIGN_IDENTITY is set
181 | if [ -z "${CODE_SIGN_IDENTITY}" ] ; then
182 | echo "CODE_SIGN_IDENTITY needs to be set for framework code-signing"
183 | exit 0
184 | fi
185 |
186 | if [ -z "${CODE_SIGN_ENTITLEMENTS}" ] ; then
187 | echo "CODE_SIGN_ENTITLEMENTS needs to be set for framework code-signing!"
188 |
189 | if [ "${CONFIGURATION}" = "Release" ] ; then
190 | exit 1
191 | else
192 | # Code-signing is optional for non-release builds.
193 | exit 0
194 | fi
195 | fi
196 |
197 | ITEMS=""
198 |
199 | FRAMEWORKS_DIR="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
200 | echo "$FRAMEWORKS_DIR"
201 | if [ -d "$FRAMEWORKS_DIR" ] ; then
202 | FRAMEWORKS=$(find "${FRAMEWORKS_DIR}" -depth -type d -name "*.framework" -or -name "*.dylib" -or -name "*.bundle" | sed -e "s/\(.*framework\)/\1\/Versions\/A\//")
203 | RESULT=$?
204 | if [[ $RESULT != 0 ]] ; then
205 | exit 1
206 | fi
207 |
208 | ITEMS="${FRAMEWORKS}"
209 | fi
210 |
211 | LOGINITEMS_DIR="${TARGET_BUILD_DIR}/${CONTENTS_FOLDER_PATH}/Library/LoginItems/"
212 | if [ -d "$LOGINITEMS_DIR" ] ; then
213 | LOGINITEMS=$(find "${LOGINITEMS_DIR}" -depth -type d -name "*.app")
214 | RESULT=$?
215 | if [[ $RESULT != 0 ]] ; then
216 | exit 1
217 | fi
218 |
219 | ITEMS="${ITEMS}"$'\n'"${LOGINITEMS}"
220 | fi
221 |
222 | # Prefer the expanded name, if available.
223 | CODE_SIGN_IDENTITY_FOR_ITEMS="${EXPANDED_CODE_SIGN_IDENTITY_NAME}"
224 | if [ "${CODE_SIGN_IDENTITY_FOR_ITEMS}" = "" ] ; then
225 | # Fall back to old behavior.
226 | CODE_SIGN_IDENTITY_FOR_ITEMS="${CODE_SIGN_IDENTITY}"
227 | fi
228 |
229 | echo "Identity:"
230 | echo "${CODE_SIGN_IDENTITY_FOR_ITEMS}"
231 |
232 | echo "Entitlements:"
233 | echo "${CODE_SIGN_ENTITLEMENTS}"
234 |
235 | echo "Found:"
236 | echo "${ITEMS}"
237 |
238 | # Change the Internal Field Separator (IFS) so that spaces in paths will not cause problems below.
239 | SAVED_IFS=$IFS
240 | IFS=$(echo -en "\n\b")
241 |
242 | # Loop through all items.
243 | for ITEM in $ITEMS;
244 | do
245 | echo "Signing '${ITEM}'"
246 | codesign --force --verbose --sign "${CODE_SIGN_IDENTITY_FOR_ITEMS}" --entitlements "${CODE_SIGN_ENTITLEMENTS}" "${ITEM}"
247 | RESULT=$?
248 | if [[ $RESULT != 0 ]] ; then
249 | echo "Failed to sign '${ITEM}'."
250 | IFS=$SAVED_IFS
251 | exit 1
252 | fi
253 | done
254 |
255 | # Restore $IFS.
256 | IFS=$SAVED_IFS
257 |
258 | fi
259 |
260 |
261 | 99FA3DBB1C7456C400CFA0EE
262 |
263 | baseConfigurationReference
264 | E4EB6923138AFD0F00A09F29
265 | buildSettings
266 |
267 | HEADER_SEARCH_PATHS
268 |
269 | $(OF_CORE_HEADERS)
270 | src
271 | ../../../addons/ofxNearestNeighbour/libs
272 | ../../../addons/ofxNearestNeighbour/libs/nanoflann
273 | ../../../addons/ofxNearestNeighbour/libs/nanoflann/include
274 | ../../../addons/ofxNearestNeighbour/src
275 |
276 | CONFIGURATION_BUILD_DIR
277 | $(SRCROOT)/bin/
278 | COPY_PHASE_STRIP
279 | YES
280 | DEAD_CODE_STRIPPING
281 | YES
282 | GCC_AUTO_VECTORIZATION
283 | YES
284 | GCC_ENABLE_SSE3_EXTENSIONS
285 | YES
286 | GCC_ENABLE_SUPPLEMENTAL_SSE3_INSTRUCTIONS
287 | YES
288 | GCC_INLINES_ARE_PRIVATE_EXTERN
289 | NO
290 | GCC_OPTIMIZATION_LEVEL
291 | 3
292 | GCC_PREPROCESSOR_DEFINITIONS[arch=*]
293 | DISTRIBUTION=1
294 | GCC_SYMBOLS_PRIVATE_EXTERN
295 | NO
296 | GCC_UNROLL_LOOPS
297 | YES
298 | GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS
299 | YES
300 | GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO
301 | NO
302 | GCC_WARN_ALLOW_INCOMPLETE_PROTOCOL
303 | NO
304 | GCC_WARN_UNINITIALIZED_AUTOS
305 | NO
306 | GCC_WARN_UNUSED_VALUE
307 | NO
308 | GCC_WARN_UNUSED_VARIABLE
309 | NO
310 | MACOSX_DEPLOYMENT_TARGET
311 | 10.9
312 | OTHER_CPLUSPLUSFLAGS
313 |
314 | -D__MACOSX_CORE__
315 | -mtune=native
316 |
317 | SDKROOT
318 | macosx
319 |
320 | isa
321 | XCBuildConfiguration
322 | name
323 | AppStore
324 |
325 | 99FA3DBC1C7456C400CFA0EE
326 |
327 | baseConfigurationReference
328 | E4EB6923138AFD0F00A09F29
329 | buildSettings
330 |
331 | HEADER_SEARCH_PATHS
332 |
333 | $(OF_CORE_HEADERS)
334 | src
335 | ../../../addons/ofxNearestNeighbour/libs
336 | ../../../addons/ofxNearestNeighbour/libs/nanoflann
337 | ../../../addons/ofxNearestNeighbour/libs/nanoflann/include
338 | ../../../addons/ofxNearestNeighbour/src
339 |
340 | COMBINE_HIDPI_IMAGES
341 | YES
342 | COPY_PHASE_STRIP
343 | YES
344 | FRAMEWORK_SEARCH_PATHS
345 | $(inherited)
346 | GCC_GENERATE_DEBUGGING_SYMBOLS
347 | YES
348 | GCC_MODEL_TUNING
349 | NONE
350 | GCC_PREPROCESSOR_DEFINITIONS[arch=*]
351 | APPSTORE=1
352 | ICON
353 | $(ICON_NAME_RELEASE)
354 | ICON_FILE
355 | $(ICON_FILE_PATH)$(ICON)
356 | INFOPLIST_FILE
357 | openFrameworks-Info.plist
358 | INSTALL_PATH
359 | /Applications
360 | LIBRARY_SEARCH_PATHS
361 | $(inherited)
362 | PRODUCT_NAME
363 | $(TARGET_NAME)
364 | WRAPPER_EXTENSION
365 | app
366 | baseConfigurationReference
367 | E4EB6923138AFD0F00A09F29
368 |
369 | isa
370 | XCBuildConfiguration
371 | name
372 | AppStore
373 |
374 | BB4B014C10F69532006C3DED
375 |
376 | children
377 |
378 | 3D3BA77954B2B04C9E000907
379 |
380 | isa
381 | PBXGroup
382 | name
383 | addons
384 | sourceTree
385 | <group>
386 |
387 | E4328143138ABC890047C5CB
388 |
389 | isa
390 | PBXFileReference
391 | lastKnownFileType
392 | wrapper.pb-project
393 | name
394 | openFrameworksLib.xcodeproj
395 | path
396 | ../../../libs/openFrameworksCompiled/project/osx/openFrameworksLib.xcodeproj
397 | sourceTree
398 | SOURCE_ROOT
399 |
400 | E4328144138ABC890047C5CB
401 |
402 | children
403 |
404 | E4328148138ABC890047C5CB
405 |
406 | isa
407 | PBXGroup
408 | name
409 | Products
410 | sourceTree
411 | <group>
412 |
413 | E4328147138ABC890047C5CB
414 |
415 | containerPortal
416 | E4328143138ABC890047C5CB
417 | isa
418 | PBXContainerItemProxy
419 | proxyType
420 | 2
421 | remoteGlobalIDString
422 | E4B27C1510CBEB8E00536013
423 | remoteInfo
424 | openFrameworks
425 |
426 | E4328148138ABC890047C5CB
427 |
428 | fileType
429 | archive.ar
430 | isa
431 | PBXReferenceProxy
432 | path
433 | openFrameworksDebug.a
434 | remoteRef
435 | E4328147138ABC890047C5CB
436 | sourceTree
437 | BUILT_PRODUCTS_DIR
438 |
439 | E4328149138ABC9F0047C5CB
440 |
441 | fileRef
442 | E4328148138ABC890047C5CB
443 | isa
444 | PBXBuildFile
445 |
446 | E4B69B4A0A3A1720003C02F2
447 |
448 | children
449 |
450 | E4B6FCAD0C3E899E008CF71C
451 | E4EB6923138AFD0F00A09F29
452 | E4B69E1C0A3A1BDC003C02F2
453 | E4EEC9E9138DF44700A80321
454 | BB4B014C10F69532006C3DED
455 | 6948EE371B920CB800B5AC1A
456 | E4B69B5B0A3A1756003C02F2
457 |
458 | isa
459 | PBXGroup
460 | sourceTree
461 | <group>
462 |
463 | E4B69B4C0A3A1720003C02F2
464 |
465 | attributes
466 |
467 | LastUpgradeCheck
468 | 0600
469 |
470 | buildConfigurationList
471 | E4B69B4D0A3A1720003C02F2
472 | compatibilityVersion
473 | Xcode 3.2
474 | developmentRegion
475 | English
476 | hasScannedForEncodings
477 | 0
478 | isa
479 | PBXProject
480 | knownRegions
481 |
482 | English
483 | Japanese
484 | French
485 | German
486 |
487 | mainGroup
488 | E4B69B4A0A3A1720003C02F2
489 | productRefGroup
490 | E4B69B4A0A3A1720003C02F2
491 | projectDirPath
492 |
493 | projectReferences
494 |
495 |
496 | ProductGroup
497 | E4328144138ABC890047C5CB
498 | ProjectRef
499 | E4328143138ABC890047C5CB
500 |
501 |
502 | projectRoot
503 |
504 | targets
505 |
506 | E4B69B5A0A3A1756003C02F2
507 |
508 |
509 | E4B69B4D0A3A1720003C02F2
510 |
511 | buildConfigurations
512 |
513 | E4B69B4E0A3A1720003C02F2
514 | E4B69B4F0A3A1720003C02F2
515 | 99FA3DBB1C7456C400CFA0EE
516 |
517 | defaultConfigurationIsVisible
518 | 0
519 | defaultConfigurationName
520 | Release
521 | isa
522 | XCConfigurationList
523 |
524 | E4B69B4E0A3A1720003C02F2
525 |
526 | baseConfigurationReference
527 | E4EB6923138AFD0F00A09F29
528 | buildSettings
529 |
530 | HEADER_SEARCH_PATHS
531 |
532 | $(OF_CORE_HEADERS)
533 | src
534 | ../../../addons/ofxNearestNeighbour/libs
535 | ../../../addons/ofxNearestNeighbour/libs/nanoflann
536 | ../../../addons/ofxNearestNeighbour/libs/nanoflann/include
537 | ../../../addons/ofxNearestNeighbour/src
538 |
539 | CONFIGURATION_BUILD_DIR
540 | $(SRCROOT)/bin/
541 | COPY_PHASE_STRIP
542 | NO
543 | DEAD_CODE_STRIPPING
544 | YES
545 | GCC_AUTO_VECTORIZATION
546 | YES
547 | GCC_ENABLE_SSE3_EXTENSIONS
548 | YES
549 | GCC_ENABLE_SUPPLEMENTAL_SSE3_INSTRUCTIONS
550 | YES
551 | GCC_INLINES_ARE_PRIVATE_EXTERN
552 | NO
553 | GCC_OPTIMIZATION_LEVEL
554 | 0
555 | GCC_SYMBOLS_PRIVATE_EXTERN
556 | NO
557 | GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS
558 | YES
559 | GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO
560 | NO
561 | GCC_WARN_ALLOW_INCOMPLETE_PROTOCOL
562 | NO
563 | GCC_WARN_UNINITIALIZED_AUTOS
564 | NO
565 | GCC_WARN_UNUSED_VALUE
566 | NO
567 | GCC_WARN_UNUSED_VARIABLE
568 | NO
569 | MACOSX_DEPLOYMENT_TARGET
570 | 10.9
571 | ONLY_ACTIVE_ARCH
572 | YES
573 | OTHER_CPLUSPLUSFLAGS
574 |
575 | -D__MACOSX_CORE__
576 | -mtune=native
577 |
578 | SDKROOT
579 | macosx
580 |
581 | isa
582 | XCBuildConfiguration
583 | name
584 | Debug
585 |
586 | E4B69B4F0A3A1720003C02F2
587 |
588 | baseConfigurationReference
589 | E4EB6923138AFD0F00A09F29
590 | buildSettings
591 |
592 | HEADER_SEARCH_PATHS
593 |
594 | $(OF_CORE_HEADERS)
595 | src
596 | ../../../addons/ofxNearestNeighbour/libs
597 | ../../../addons/ofxNearestNeighbour/libs/nanoflann
598 | ../../../addons/ofxNearestNeighbour/libs/nanoflann/include
599 | ../../../addons/ofxNearestNeighbour/src
600 |
601 | CONFIGURATION_BUILD_DIR
602 | $(SRCROOT)/bin/
603 | COPY_PHASE_STRIP
604 | YES
605 | DEAD_CODE_STRIPPING
606 | YES
607 | GCC_AUTO_VECTORIZATION
608 | YES
609 | GCC_ENABLE_SSE3_EXTENSIONS
610 | YES
611 | GCC_ENABLE_SUPPLEMENTAL_SSE3_INSTRUCTIONS
612 | YES
613 | GCC_INLINES_ARE_PRIVATE_EXTERN
614 | NO
615 | GCC_OPTIMIZATION_LEVEL
616 | 3
617 | GCC_SYMBOLS_PRIVATE_EXTERN
618 | NO
619 | GCC_UNROLL_LOOPS
620 | YES
621 | GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS
622 | YES
623 | GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO
624 | NO
625 | GCC_WARN_ALLOW_INCOMPLETE_PROTOCOL
626 | NO
627 | GCC_WARN_UNINITIALIZED_AUTOS
628 | NO
629 | GCC_WARN_UNUSED_VALUE
630 | NO
631 | GCC_WARN_UNUSED_VARIABLE
632 | NO
633 | MACOSX_DEPLOYMENT_TARGET
634 | 10.9
635 | OTHER_CPLUSPLUSFLAGS
636 |
637 | -D__MACOSX_CORE__
638 | -mtune=native
639 |
640 | SDKROOT
641 | macosx
642 |
643 | isa
644 | XCBuildConfiguration
645 | name
646 | Release
647 |
648 | E4B69B580A3A1756003C02F2
649 |
650 | buildActionMask
651 | 2147483647
652 | files
653 |
654 | E4B69E200A3A1BDC003C02F2
655 | E4B69E210A3A1BDC003C02F2
656 |
657 | isa
658 | PBXSourcesBuildPhase
659 | runOnlyForDeploymentPostprocessing
660 | 0
661 |
662 | E4B69B590A3A1756003C02F2
663 |
664 | buildActionMask
665 | 2147483647
666 | files
667 |
668 | E4328149138ABC9F0047C5CB
669 |
670 | isa
671 | PBXFrameworksBuildPhase
672 | runOnlyForDeploymentPostprocessing
673 | 0
674 |
675 | E4B69B5A0A3A1756003C02F2
676 |
677 | buildConfigurationList
678 | E4B69B5F0A3A1757003C02F2
679 | buildPhases
680 |
681 | E4B69B580A3A1756003C02F2
682 | E4B69B590A3A1756003C02F2
683 | E4B6FFFD0C3F9AB9008CF71C
684 | E4C2427710CC5ABF004149E2
685 | 8466F1851C04CA0E00918B1C
686 |
687 | buildRules
688 |
689 | dependencies
690 |
691 | E4EEB9AC138B136A00A80321
692 |
693 | isa
694 | PBXNativeTarget
695 | name
696 | example-closest
697 | productName
698 | myOFApp
699 | productReference
700 | E4B69B5B0A3A1756003C02F2
701 | productType
702 | com.apple.product-type.application
703 |
704 | E4B69B5B0A3A1756003C02F2
705 |
706 | explicitFileType
707 | wrapper.application
708 | includeInIndex
709 | 0
710 | isa
711 | PBXFileReference
712 | path
713 | example-closestDebug.app
714 | sourceTree
715 | BUILT_PRODUCTS_DIR
716 |
717 | E4B69B5F0A3A1757003C02F2
718 |
719 | buildConfigurations
720 |
721 | E4B69B600A3A1757003C02F2
722 | E4B69B610A3A1757003C02F2
723 | 99FA3DBC1C7456C400CFA0EE
724 |
725 | defaultConfigurationIsVisible
726 | 0
727 | defaultConfigurationName
728 | Release
729 | isa
730 | XCConfigurationList
731 |
732 | E4B69B600A3A1757003C02F2
733 |
734 | baseConfigurationReference
735 | E4EB6923138AFD0F00A09F29
736 | buildSettings
737 |
738 | HEADER_SEARCH_PATHS
739 |
740 | $(OF_CORE_HEADERS)
741 | src
742 | ../../../addons/ofxNearestNeighbour/libs
743 | ../../../addons/ofxNearestNeighbour/libs/nanoflann
744 | ../../../addons/ofxNearestNeighbour/libs/nanoflann/include
745 | ../../../addons/ofxNearestNeighbour/src
746 |
747 | COMBINE_HIDPI_IMAGES
748 | YES
749 | COPY_PHASE_STRIP
750 | NO
751 | FRAMEWORK_SEARCH_PATHS
752 | $(inherited)
753 | GCC_DYNAMIC_NO_PIC
754 | NO
755 | GCC_GENERATE_DEBUGGING_SYMBOLS
756 | YES
757 | GCC_MODEL_TUNING
758 | NONE
759 | ICON
760 | $(ICON_NAME_DEBUG)
761 | ICON_FILE
762 | $(ICON_FILE_PATH)$(ICON)
763 | INFOPLIST_FILE
764 | openFrameworks-Info.plist
765 | INSTALL_PATH
766 | /Applications
767 | LIBRARY_SEARCH_PATHS
768 | $(inherited)
769 | PRODUCT_NAME
770 | $(TARGET_NAME)Debug
771 | WRAPPER_EXTENSION
772 | app
773 |
774 | isa
775 | XCBuildConfiguration
776 | name
777 | Debug
778 |
779 | E4B69B610A3A1757003C02F2
780 |
781 | baseConfigurationReference
782 | E4EB6923138AFD0F00A09F29
783 | buildSettings
784 |
785 | HEADER_SEARCH_PATHS
786 |
787 | $(OF_CORE_HEADERS)
788 | src
789 | ../../../addons/ofxNearestNeighbour/libs
790 | ../../../addons/ofxNearestNeighbour/libs/nanoflann
791 | ../../../addons/ofxNearestNeighbour/libs/nanoflann/include
792 | ../../../addons/ofxNearestNeighbour/src
793 |
794 | COMBINE_HIDPI_IMAGES
795 | YES
796 | COPY_PHASE_STRIP
797 | YES
798 | FRAMEWORK_SEARCH_PATHS
799 | $(inherited)
800 | GCC_GENERATE_DEBUGGING_SYMBOLS
801 | YES
802 | GCC_MODEL_TUNING
803 | NONE
804 | ICON
805 | $(ICON_NAME_RELEASE)
806 | ICON_FILE
807 | $(ICON_FILE_PATH)$(ICON)
808 | INFOPLIST_FILE
809 | openFrameworks-Info.plist
810 | INSTALL_PATH
811 | /Applications
812 | LIBRARY_SEARCH_PATHS
813 | $(inherited)
814 | PRODUCT_NAME
815 | $(TARGET_NAME)
816 | WRAPPER_EXTENSION
817 | app
818 | baseConfigurationReference
819 | E4EB6923138AFD0F00A09F29
820 |
821 | isa
822 | XCBuildConfiguration
823 | name
824 | Release
825 |
826 | E4B69E1C0A3A1BDC003C02F2
827 |
828 | children
829 |
830 | E4B69E1D0A3A1BDC003C02F2
831 | E4B69E1E0A3A1BDC003C02F2
832 | E4B69E1F0A3A1BDC003C02F2
833 |
834 | isa
835 | PBXGroup
836 | path
837 | src
838 | sourceTree
839 | SOURCE_ROOT
840 |
841 | E4B69E1D0A3A1BDC003C02F2
842 |
843 | fileEncoding
844 | 4
845 | isa
846 | PBXFileReference
847 | lastKnownFileType
848 | sourcecode.cpp.cpp
849 | name
850 | main.cpp
851 | path
852 | src/main.cpp
853 | sourceTree
854 | SOURCE_ROOT
855 |
856 | E4B69E1E0A3A1BDC003C02F2
857 |
858 | explicitFileType
859 | sourcecode.cpp.cpp
860 | fileEncoding
861 | 4
862 | isa
863 | PBXFileReference
864 | name
865 | ofApp.cpp
866 | path
867 | src/ofApp.cpp
868 | sourceTree
869 | SOURCE_ROOT
870 |
871 | E4B69E1F0A3A1BDC003C02F2
872 |
873 | fileEncoding
874 | 4
875 | isa
876 | PBXFileReference
877 | lastKnownFileType
878 | sourcecode.c.h
879 | name
880 | ofApp.h
881 | path
882 | src/ofApp.h
883 | sourceTree
884 | SOURCE_ROOT
885 |
886 | E4B69E200A3A1BDC003C02F2
887 |
888 | fileRef
889 | E4B69E1D0A3A1BDC003C02F2
890 | isa
891 | PBXBuildFile
892 |
893 | E4B69E210A3A1BDC003C02F2
894 |
895 | fileRef
896 | E4B69E1E0A3A1BDC003C02F2
897 | isa
898 | PBXBuildFile
899 |
900 | E4B6FCAD0C3E899E008CF71C
901 |
902 | fileEncoding
903 | 4
904 | isa
905 | PBXFileReference
906 | lastKnownFileType
907 | text.plist.xml
908 | path
909 | openFrameworks-Info.plist
910 | sourceTree
911 | <group>
912 |
913 | E4B6FFFD0C3F9AB9008CF71C
914 |
915 | buildActionMask
916 | 2147483647
917 | files
918 |
919 | inputPaths
920 |
921 | isa
922 | PBXShellScriptBuildPhase
923 | outputPaths
924 |
925 | runOnlyForDeploymentPostprocessing
926 | 0
927 | shellPath
928 | /bin/sh
929 | shellScript
930 | mkdir -p "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Resources/"
931 | # Copy default icon file into App/Resources
932 | rsync -aved "$ICON_FILE" "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Resources/"
933 | # Copy libfmod and change install directory for fmod to run
934 | rsync -aved "$OF_PATH/libs/fmodex/lib/osx/libfmodex.dylib" "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Frameworks/";
935 | install_name_tool -change @executable_path/libfmodex.dylib @executable_path/../Frameworks/libfmodex.dylib "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/$PRODUCT_NAME";
936 |
937 | echo "$GCC_PREPROCESSOR_DEFINITIONS";
938 |
939 |
940 | E4C2427710CC5ABF004149E2
941 |
942 | buildActionMask
943 | 2147483647
944 | dstPath
945 |
946 | dstSubfolderSpec
947 | 10
948 | files
949 |
950 | isa
951 | PBXCopyFilesBuildPhase
952 | runOnlyForDeploymentPostprocessing
953 | 0
954 |
955 | E4EB691F138AFCF100A09F29
956 |
957 | fileEncoding
958 | 4
959 | isa
960 | PBXFileReference
961 | lastKnownFileType
962 | text.xcconfig
963 | name
964 | CoreOF.xcconfig
965 | path
966 | ../../../libs/openFrameworksCompiled/project/osx/CoreOF.xcconfig
967 | sourceTree
968 | SOURCE_ROOT
969 |
970 | E4EB6923138AFD0F00A09F29
971 |
972 | fileEncoding
973 | 4
974 | isa
975 | PBXFileReference
976 | lastKnownFileType
977 | text.xcconfig
978 | path
979 | Project.xcconfig
980 | sourceTree
981 | <group>
982 |
983 | E4EEB9AB138B136A00A80321
984 |
985 | containerPortal
986 | E4328143138ABC890047C5CB
987 | isa
988 | PBXContainerItemProxy
989 | proxyType
990 | 1
991 | remoteGlobalIDString
992 | E4B27C1410CBEB8E00536013
993 | remoteInfo
994 | openFrameworks
995 |
996 | E4EEB9AC138B136A00A80321
997 |
998 | isa
999 | PBXTargetDependency
1000 | name
1001 | openFrameworks
1002 | targetProxy
1003 | E4EEB9AB138B136A00A80321
1004 |
1005 | E4EEC9E9138DF44700A80321
1006 |
1007 | children
1008 |
1009 | E4EB691F138AFCF100A09F29
1010 | E4328143138ABC890047C5CB
1011 |
1012 | isa
1013 | PBXGroup
1014 | name
1015 | openFrameworks
1016 | sourceTree
1017 | <group>
1018 |
1019 |
1020 | rootObject
1021 | E4B69B4C0A3A1720003C02F2
1022 |
1023 |
1024 |
--------------------------------------------------------------------------------
/example-closest/example-closest.xcodeproj/xcshareddata/xcschemes/example-closest Debug.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
51 |
52 |
58 |
59 |
60 |
61 |
62 |
63 |
69 |
70 |
76 |
77 |
78 |
79 |
81 |
82 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/example-closest/example-closest.xcodeproj/xcshareddata/xcschemes/example-closest Release.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
51 |
52 |
58 |
59 |
60 |
61 |
62 |
63 |
69 |
70 |
76 |
77 |
78 |
79 |
81 |
82 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/example-closest/openFrameworks-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIdentifier
10 | cc.openFrameworks.ofapp
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundlePackageType
14 | APPL
15 | CFBundleSignature
16 | ????
17 | CFBundleVersion
18 | 1.0
19 | CFBundleIconFile
20 | ${ICON}
21 |
22 |
23 |
--------------------------------------------------------------------------------
/example-closest/src/main.cpp:
--------------------------------------------------------------------------------
1 | #include "ofMain.h"
2 | #include "ofApp.h"
3 |
4 | //========================================================================
5 | int main( ){
6 | ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context
7 |
8 | // this kicks off the running of my app
9 | // can be OF_WINDOW or OF_FULLSCREEN
10 | // pass in width and height too:
11 | ofRunApp(new ofApp());
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/example-closest/src/ofApp.cpp:
--------------------------------------------------------------------------------
1 | #include "ofApp.h"
2 |
3 | //--------------------------------------------------------------
4 | void ofApp::setup()
5 | {
6 | const unsigned numPoints = 10000;
7 | ofBackground(0);
8 | points.reserve(numPoints);
9 | for (unsigned i = 0; i < numPoints; ++i)
10 | {
11 | points.push_back(ofVec2f(ofRandom(50, ofGetWidth() - 50), ofRandom(50, ofGetHeight() - 50)));
12 | }
13 | nn.buildIndex(points);
14 | }
15 |
16 | //--------------------------------------------------------------
17 | void ofApp::update()
18 | {
19 | ofSetWindowTitle(ofToString(ofGetFrameRate(), 2));
20 | ofVec2f mouse(ofGetMouseX(), ofGetMouseY());
21 | vector distsSq;
22 | nn.findNClosestPoints(mouse, 100, indices, distsSq);
23 | }
24 |
25 | //--------------------------------------------------------------
26 | void ofApp::draw()
27 | {
28 | ofSetColor(255, 0, 0);
29 | for (unsigned i = 0; i < points.size(); ++i)
30 | {
31 | ofDrawCircle(points[i], 2);
32 | }
33 | ofSetColor(0, 255, 0);
34 | for (unsigned i = 0; i < indices.size(); ++i)
35 | {
36 | ofDrawCircle(points[indices[i]], 2);
37 | }
38 | ofSetColor(255);
39 | ofDrawBitmapString("Move mouse to find nearest neighbours", 10, 20);
40 | }
41 |
42 | //--------------------------------------------------------------
43 | void ofApp::keyPressed(int key){
44 |
45 | }
46 |
47 | //--------------------------------------------------------------
48 | void ofApp::keyReleased(int key){
49 |
50 | }
51 |
52 | //--------------------------------------------------------------
53 | void ofApp::mouseMoved(int x, int y ){
54 |
55 | }
56 |
57 | //--------------------------------------------------------------
58 | void ofApp::mouseDragged(int x, int y, int button){
59 |
60 | }
61 |
62 | //--------------------------------------------------------------
63 | void ofApp::mousePressed(int x, int y, int button){
64 |
65 | }
66 |
67 | //--------------------------------------------------------------
68 | void ofApp::mouseReleased(int x, int y, int button){
69 |
70 | }
71 |
72 | //--------------------------------------------------------------
73 | void ofApp::windowResized(int w, int h){
74 |
75 | }
76 |
77 | //--------------------------------------------------------------
78 | void ofApp::gotMessage(ofMessage msg){
79 |
80 | }
81 |
82 | //--------------------------------------------------------------
83 | void ofApp::dragEvent(ofDragInfo dragInfo){
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/example-closest/src/ofApp.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "ofMain.h"
4 | #include "ofxNearestNeighbour.h"
5 |
6 | class ofApp : public ofBaseApp
7 | {
8 | public:
9 | void setup();
10 | void update();
11 | void draw();
12 |
13 | void keyPressed(int key);
14 | void keyReleased(int key);
15 | void mouseMoved(int x, int y );
16 | void mouseDragged(int x, int y, int button);
17 | void mousePressed(int x, int y, int button);
18 | void mouseReleased(int x, int y, int button);
19 | void windowResized(int w, int h);
20 | void dragEvent(ofDragInfo dragInfo);
21 | void gotMessage(ofMessage msg);
22 |
23 | private:
24 | ofxNearestNeighbour2D nn;
25 | vector points;
26 | vector indices;
27 | };
28 |
--------------------------------------------------------------------------------
/example-radius/Makefile:
--------------------------------------------------------------------------------
1 | # Attempt to load a config.make file.
2 | # If none is found, project defaults in config.project.make will be used.
3 | ifneq ($(wildcard config.make),)
4 | include config.make
5 | endif
6 |
7 | # make sure the the OF_ROOT location is defined
8 | ifndef OF_ROOT
9 | OF_ROOT=../../..
10 | endif
11 |
12 | # call the project makefile!
13 | include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk
14 |
--------------------------------------------------------------------------------
/example-radius/Project.xcconfig:
--------------------------------------------------------------------------------
1 | //THE PATH TO THE ROOT OF OUR OF PATH RELATIVE TO THIS PROJECT.
2 | //THIS NEEDS TO BE DEFINED BEFORE CoreOF.xcconfig IS INCLUDED
3 | OF_PATH = ../../..
4 |
5 | //THIS HAS ALL THE HEADER AND LIBS FOR OF CORE
6 | #include "../../../libs/openFrameworksCompiled/project/osx/CoreOF.xcconfig"
7 |
8 | //ICONS - NEW IN 0072
9 | ICON_NAME_DEBUG = icon-debug.icns
10 | ICON_NAME_RELEASE = icon.icns
11 | ICON_FILE_PATH = $(OF_PATH)/libs/openFrameworksCompiled/project/osx/
12 |
13 | //IF YOU WANT AN APP TO HAVE A CUSTOM ICON - PUT THEM IN YOUR DATA FOLDER AND CHANGE ICON_FILE_PATH to:
14 | //ICON_FILE_PATH = bin/data/
15 |
16 | OTHER_CFLAGS = $(OF_CORE_CFLAGS)
17 | OTHER_LDFLAGS = $(OF_CORE_LIBS) $(OF_CORE_FRAMEWORKS)
18 | HEADER_SEARCH_PATHS = $(OF_CORE_HEADERS)
19 |
--------------------------------------------------------------------------------
/example-radius/addons.make:
--------------------------------------------------------------------------------
1 | ofxNearestNeighbour
2 |
--------------------------------------------------------------------------------
/example-radius/config.make:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # CONFIGURE PROJECT MAKEFILE (optional)
3 | # This file is where we make project specific configurations.
4 | ################################################################################
5 |
6 | ################################################################################
7 | # OF ROOT
8 | # The location of your root openFrameworks installation
9 | # (default) OF_ROOT = ../../..
10 | ################################################################################
11 | # OF_ROOT = ../../..
12 |
13 | ################################################################################
14 | # PROJECT ROOT
15 | # The location of the project - a starting place for searching for files
16 | # (default) PROJECT_ROOT = . (this directory)
17 | #
18 | ################################################################################
19 | # PROJECT_ROOT = .
20 |
21 | ################################################################################
22 | # PROJECT SPECIFIC CHECKS
23 | # This is a project defined section to create internal makefile flags to
24 | # conditionally enable or disable the addition of various features within
25 | # this makefile. For instance, if you want to make changes based on whether
26 | # GTK is installed, one might test that here and create a variable to check.
27 | ################################################################################
28 | # None
29 |
30 | ################################################################################
31 | # PROJECT EXTERNAL SOURCE PATHS
32 | # These are fully qualified paths that are not within the PROJECT_ROOT folder.
33 | # Like source folders in the PROJECT_ROOT, these paths are subject to
34 | # exlclusion via the PROJECT_EXLCUSIONS list.
35 | #
36 | # (default) PROJECT_EXTERNAL_SOURCE_PATHS = (blank)
37 | #
38 | # Note: Leave a leading space when adding list items with the += operator
39 | ################################################################################
40 | # PROJECT_EXTERNAL_SOURCE_PATHS =
41 |
42 | ################################################################################
43 | # PROJECT EXCLUSIONS
44 | # These makefiles assume that all folders in your current project directory
45 | # and any listed in the PROJECT_EXTERNAL_SOURCH_PATHS are are valid locations
46 | # to look for source code. The any folders or files that match any of the
47 | # items in the PROJECT_EXCLUSIONS list below will be ignored.
48 | #
49 | # Each item in the PROJECT_EXCLUSIONS list will be treated as a complete
50 | # string unless teh user adds a wildcard (%) operator to match subdirectories.
51 | # GNU make only allows one wildcard for matching. The second wildcard (%) is
52 | # treated literally.
53 | #
54 | # (default) PROJECT_EXCLUSIONS = (blank)
55 | #
56 | # Will automatically exclude the following:
57 | #
58 | # $(PROJECT_ROOT)/bin%
59 | # $(PROJECT_ROOT)/obj%
60 | # $(PROJECT_ROOT)/%.xcodeproj
61 | #
62 | # Note: Leave a leading space when adding list items with the += operator
63 | ################################################################################
64 | # PROJECT_EXCLUSIONS =
65 |
66 | ################################################################################
67 | # PROJECT LINKER FLAGS
68 | # These flags will be sent to the linker when compiling the executable.
69 | #
70 | # (default) PROJECT_LDFLAGS = -Wl,-rpath=./libs
71 | #
72 | # Note: Leave a leading space when adding list items with the += operator
73 | ################################################################################
74 |
75 | # Currently, shared libraries that are needed are copied to the
76 | # $(PROJECT_ROOT)/bin/libs directory. The following LDFLAGS tell the linker to
77 | # add a runtime path to search for those shared libraries, since they aren't
78 | # incorporated directly into the final executable application binary.
79 | # TODO: should this be a default setting?
80 | # PROJECT_LDFLAGS=-Wl,-rpath=./libs
81 |
82 | ################################################################################
83 | # PROJECT DEFINES
84 | # Create a space-delimited list of DEFINES. The list will be converted into
85 | # CFLAGS with the "-D" flag later in the makefile.
86 | #
87 | # (default) PROJECT_DEFINES = (blank)
88 | #
89 | # Note: Leave a leading space when adding list items with the += operator
90 | ################################################################################
91 | # PROJECT_DEFINES =
92 |
93 | ################################################################################
94 | # PROJECT CFLAGS
95 | # This is a list of fully qualified CFLAGS required when compiling for this
96 | # project. These CFLAGS will be used IN ADDITION TO the PLATFORM_CFLAGS
97 | # defined in your platform specific core configuration files. These flags are
98 | # presented to the compiler BEFORE the PROJECT_OPTIMIZATION_CFLAGS below.
99 | #
100 | # (default) PROJECT_CFLAGS = (blank)
101 | #
102 | # Note: Before adding PROJECT_CFLAGS, note that the PLATFORM_CFLAGS defined in
103 | # your platform specific configuration file will be applied by default and
104 | # further flags here may not be needed.
105 | #
106 | # Note: Leave a leading space when adding list items with the += operator
107 | ################################################################################
108 | # PROJECT_CFLAGS =
109 |
110 | ################################################################################
111 | # PROJECT OPTIMIZATION CFLAGS
112 | # These are lists of CFLAGS that are target-specific. While any flags could
113 | # be conditionally added, they are usually limited to optimization flags.
114 | # These flags are added BEFORE the PROJECT_CFLAGS.
115 | #
116 | # PROJECT_OPTIMIZATION_CFLAGS_RELEASE flags are only applied to RELEASE targets.
117 | #
118 | # (default) PROJECT_OPTIMIZATION_CFLAGS_RELEASE = (blank)
119 | #
120 | # PROJECT_OPTIMIZATION_CFLAGS_DEBUG flags are only applied to DEBUG targets.
121 | #
122 | # (default) PROJECT_OPTIMIZATION_CFLAGS_DEBUG = (blank)
123 | #
124 | # Note: Before adding PROJECT_OPTIMIZATION_CFLAGS, please note that the
125 | # PLATFORM_OPTIMIZATION_CFLAGS defined in your platform specific configuration
126 | # file will be applied by default and further optimization flags here may not
127 | # be needed.
128 | #
129 | # Note: Leave a leading space when adding list items with the += operator
130 | ################################################################################
131 | # PROJECT_OPTIMIZATION_CFLAGS_RELEASE =
132 | # PROJECT_OPTIMIZATION_CFLAGS_DEBUG =
133 |
134 | ################################################################################
135 | # PROJECT COMPILERS
136 | # Custom compilers can be set for CC and CXX
137 | # (default) PROJECT_CXX = (blank)
138 | # (default) PROJECT_CC = (blank)
139 | # Note: Leave a leading space when adding list items with the += operator
140 | ################################################################################
141 | # PROJECT_CXX =
142 | # PROJECT_CC =
143 |
--------------------------------------------------------------------------------
/example-radius/example-radius.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | archiveVersion
5 | 1
6 | classes
7 |
8 | objectVersion
9 | 46
10 | objects
11 |
12 | BD177D4812B4A02EA74827C7
13 |
14 | children
15 |
16 | A999FD3AA9430DF3DD79FDB1
17 |
18 | isa
19 | PBXGroup
20 | name
21 | include
22 | sourceTree
23 | <group>
24 |
25 | 4EBFD7E21A9DC0266BFB206E
26 |
27 | children
28 |
29 | BD177D4812B4A02EA74827C7
30 |
31 | isa
32 | PBXGroup
33 | name
34 | nanoflann
35 | sourceTree
36 | <group>
37 |
38 | FF311434F6080480F1E6B0DA
39 |
40 | children
41 |
42 | 4EBFD7E21A9DC0266BFB206E
43 |
44 | isa
45 | PBXGroup
46 | name
47 | libs
48 | sourceTree
49 | <group>
50 |
51 | A999FD3AA9430DF3DD79FDB1
52 |
53 | explicitFileType
54 | sourcecode.c.h
55 | fileEncoding
56 | 30
57 | isa
58 | PBXFileReference
59 | name
60 | nanoflann.hpp
61 | path
62 | ../../../addons/ofxNearestNeighbour/libs/nanoflann/include/nanoflann.hpp
63 | sourceTree
64 | SOURCE_ROOT
65 |
66 | 967BF5D5A05B88613BAB0BF6
67 |
68 | explicitFileType
69 | sourcecode.c.h
70 | fileEncoding
71 | 30
72 | isa
73 | PBXFileReference
74 | name
75 | PointCloud.h
76 | path
77 | ../../../addons/ofxNearestNeighbour/src/PointCloud.h
78 | sourceTree
79 | SOURCE_ROOT
80 |
81 | 0AFFFAC1F8BCCA02B87F6521
82 |
83 | explicitFileType
84 | sourcecode.c.h
85 | fileEncoding
86 | 30
87 | isa
88 | PBXFileReference
89 | name
90 | ofxNearestNeighbour.h
91 | path
92 | ../../../addons/ofxNearestNeighbour/src/ofxNearestNeighbour.h
93 | sourceTree
94 | SOURCE_ROOT
95 |
96 | 92EEB4240BA473E0C8052C5B
97 |
98 | children
99 |
100 | C7EB216AF3C37F5BEF455F61
101 | 0AFFFAC1F8BCCA02B87F6521
102 | 967BF5D5A05B88613BAB0BF6
103 |
104 | isa
105 | PBXGroup
106 | name
107 | src
108 | sourceTree
109 | <group>
110 |
111 | 3D3BA77954B2B04C9E000907
112 |
113 | children
114 |
115 | 92EEB4240BA473E0C8052C5B
116 | FF311434F6080480F1E6B0DA
117 |
118 | isa
119 | PBXGroup
120 | name
121 | ofxNearestNeighbour
122 | sourceTree
123 | <group>
124 |
125 | C7EB216AF3C37F5BEF455F61
126 |
127 | explicitFileType
128 | sourcecode.c.h
129 | fileEncoding
130 | 30
131 | isa
132 | PBXFileReference
133 | name
134 | NearestNeighbour.h
135 | path
136 | ../../../addons/ofxNearestNeighbour/src/NearestNeighbour.h
137 | sourceTree
138 | SOURCE_ROOT
139 |
140 | 6948EE371B920CB800B5AC1A
141 |
142 | children
143 |
144 | isa
145 | PBXGroup
146 | name
147 | local_addons
148 | sourceTree
149 | <group>
150 |
151 | 8466F1851C04CA0E00918B1C
152 |
153 | buildActionMask
154 | 12
155 | files
156 |
157 | inputPaths
158 |
159 | isa
160 | PBXShellScriptBuildPhase
161 | outputPaths
162 |
163 | runOnlyForDeploymentPostprocessing
164 | 0
165 | shellPath
166 | /bin/sh
167 | shellScript
168 | echo "$GCC_PREPROCESSOR_DEFINITIONS";
169 | APPSTORE=`expr "$GCC_PREPROCESSOR_DEFINITIONS" : ".*APPSTORE=\([0-9]*\)"`
170 | if [ -z "$APPSTORE" ] ; then
171 | echo "Note: Not copying bin/data to App Package or doing App Code signing. Use AppStore target for AppStore distribution";
172 | else
173 | # Copy bin/data into App/Resources
174 | rsync -avz --exclude='.DS_Store' "${SRCROOT}/bin/data/" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/data/"
175 |
176 | # ---- Code Sign App Package ----
177 |
178 | # WARNING: You may have to run Clean in Xcode after changing CODE_SIGN_IDENTITY!
179 |
180 | # Verify that $CODE_SIGN_IDENTITY is set
181 | if [ -z "${CODE_SIGN_IDENTITY}" ] ; then
182 | echo "CODE_SIGN_IDENTITY needs to be set for framework code-signing"
183 | exit 0
184 | fi
185 |
186 | if [ -z "${CODE_SIGN_ENTITLEMENTS}" ] ; then
187 | echo "CODE_SIGN_ENTITLEMENTS needs to be set for framework code-signing!"
188 |
189 | if [ "${CONFIGURATION}" = "Release" ] ; then
190 | exit 1
191 | else
192 | # Code-signing is optional for non-release builds.
193 | exit 0
194 | fi
195 | fi
196 |
197 | ITEMS=""
198 |
199 | FRAMEWORKS_DIR="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
200 | echo "$FRAMEWORKS_DIR"
201 | if [ -d "$FRAMEWORKS_DIR" ] ; then
202 | FRAMEWORKS=$(find "${FRAMEWORKS_DIR}" -depth -type d -name "*.framework" -or -name "*.dylib" -or -name "*.bundle" | sed -e "s/\(.*framework\)/\1\/Versions\/A\//")
203 | RESULT=$?
204 | if [[ $RESULT != 0 ]] ; then
205 | exit 1
206 | fi
207 |
208 | ITEMS="${FRAMEWORKS}"
209 | fi
210 |
211 | LOGINITEMS_DIR="${TARGET_BUILD_DIR}/${CONTENTS_FOLDER_PATH}/Library/LoginItems/"
212 | if [ -d "$LOGINITEMS_DIR" ] ; then
213 | LOGINITEMS=$(find "${LOGINITEMS_DIR}" -depth -type d -name "*.app")
214 | RESULT=$?
215 | if [[ $RESULT != 0 ]] ; then
216 | exit 1
217 | fi
218 |
219 | ITEMS="${ITEMS}"$'\n'"${LOGINITEMS}"
220 | fi
221 |
222 | # Prefer the expanded name, if available.
223 | CODE_SIGN_IDENTITY_FOR_ITEMS="${EXPANDED_CODE_SIGN_IDENTITY_NAME}"
224 | if [ "${CODE_SIGN_IDENTITY_FOR_ITEMS}" = "" ] ; then
225 | # Fall back to old behavior.
226 | CODE_SIGN_IDENTITY_FOR_ITEMS="${CODE_SIGN_IDENTITY}"
227 | fi
228 |
229 | echo "Identity:"
230 | echo "${CODE_SIGN_IDENTITY_FOR_ITEMS}"
231 |
232 | echo "Entitlements:"
233 | echo "${CODE_SIGN_ENTITLEMENTS}"
234 |
235 | echo "Found:"
236 | echo "${ITEMS}"
237 |
238 | # Change the Internal Field Separator (IFS) so that spaces in paths will not cause problems below.
239 | SAVED_IFS=$IFS
240 | IFS=$(echo -en "\n\b")
241 |
242 | # Loop through all items.
243 | for ITEM in $ITEMS;
244 | do
245 | echo "Signing '${ITEM}'"
246 | codesign --force --verbose --sign "${CODE_SIGN_IDENTITY_FOR_ITEMS}" --entitlements "${CODE_SIGN_ENTITLEMENTS}" "${ITEM}"
247 | RESULT=$?
248 | if [[ $RESULT != 0 ]] ; then
249 | echo "Failed to sign '${ITEM}'."
250 | IFS=$SAVED_IFS
251 | exit 1
252 | fi
253 | done
254 |
255 | # Restore $IFS.
256 | IFS=$SAVED_IFS
257 |
258 | fi
259 |
260 |
261 | 99FA3DBB1C7456C400CFA0EE
262 |
263 | baseConfigurationReference
264 | E4EB6923138AFD0F00A09F29
265 | buildSettings
266 |
267 | HEADER_SEARCH_PATHS
268 |
269 | $(OF_CORE_HEADERS)
270 | src
271 | ../../../addons/ofxNearestNeighbour/libs
272 | ../../../addons/ofxNearestNeighbour/libs/nanoflann
273 | ../../../addons/ofxNearestNeighbour/libs/nanoflann/include
274 | ../../../addons/ofxNearestNeighbour/src
275 |
276 | CONFIGURATION_BUILD_DIR
277 | $(SRCROOT)/bin/
278 | COPY_PHASE_STRIP
279 | YES
280 | DEAD_CODE_STRIPPING
281 | YES
282 | GCC_AUTO_VECTORIZATION
283 | YES
284 | GCC_ENABLE_SSE3_EXTENSIONS
285 | YES
286 | GCC_ENABLE_SUPPLEMENTAL_SSE3_INSTRUCTIONS
287 | YES
288 | GCC_INLINES_ARE_PRIVATE_EXTERN
289 | NO
290 | GCC_OPTIMIZATION_LEVEL
291 | 3
292 | GCC_PREPROCESSOR_DEFINITIONS[arch=*]
293 | DISTRIBUTION=1
294 | GCC_SYMBOLS_PRIVATE_EXTERN
295 | NO
296 | GCC_UNROLL_LOOPS
297 | YES
298 | GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS
299 | YES
300 | GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO
301 | NO
302 | GCC_WARN_ALLOW_INCOMPLETE_PROTOCOL
303 | NO
304 | GCC_WARN_UNINITIALIZED_AUTOS
305 | NO
306 | GCC_WARN_UNUSED_VALUE
307 | NO
308 | GCC_WARN_UNUSED_VARIABLE
309 | NO
310 | MACOSX_DEPLOYMENT_TARGET
311 | 10.9
312 | OTHER_CPLUSPLUSFLAGS
313 |
314 | -D__MACOSX_CORE__
315 | -mtune=native
316 |
317 | SDKROOT
318 | macosx
319 |
320 | isa
321 | XCBuildConfiguration
322 | name
323 | AppStore
324 |
325 | 99FA3DBC1C7456C400CFA0EE
326 |
327 | baseConfigurationReference
328 | E4EB6923138AFD0F00A09F29
329 | buildSettings
330 |
331 | HEADER_SEARCH_PATHS
332 |
333 | $(OF_CORE_HEADERS)
334 | src
335 | ../../../addons/ofxNearestNeighbour/libs
336 | ../../../addons/ofxNearestNeighbour/libs/nanoflann
337 | ../../../addons/ofxNearestNeighbour/libs/nanoflann/include
338 | ../../../addons/ofxNearestNeighbour/src
339 |
340 | COMBINE_HIDPI_IMAGES
341 | YES
342 | COPY_PHASE_STRIP
343 | YES
344 | FRAMEWORK_SEARCH_PATHS
345 | $(inherited)
346 | GCC_GENERATE_DEBUGGING_SYMBOLS
347 | YES
348 | GCC_MODEL_TUNING
349 | NONE
350 | GCC_PREPROCESSOR_DEFINITIONS[arch=*]
351 | APPSTORE=1
352 | ICON
353 | $(ICON_NAME_RELEASE)
354 | ICON_FILE
355 | $(ICON_FILE_PATH)$(ICON)
356 | INFOPLIST_FILE
357 | openFrameworks-Info.plist
358 | INSTALL_PATH
359 | /Applications
360 | LIBRARY_SEARCH_PATHS
361 | $(inherited)
362 | PRODUCT_NAME
363 | $(TARGET_NAME)
364 | WRAPPER_EXTENSION
365 | app
366 | baseConfigurationReference
367 | E4EB6923138AFD0F00A09F29
368 |
369 | isa
370 | XCBuildConfiguration
371 | name
372 | AppStore
373 |
374 | BB4B014C10F69532006C3DED
375 |
376 | children
377 |
378 | 3D3BA77954B2B04C9E000907
379 |
380 | isa
381 | PBXGroup
382 | name
383 | addons
384 | sourceTree
385 | <group>
386 |
387 | E4328143138ABC890047C5CB
388 |
389 | isa
390 | PBXFileReference
391 | lastKnownFileType
392 | wrapper.pb-project
393 | name
394 | openFrameworksLib.xcodeproj
395 | path
396 | ../../../libs/openFrameworksCompiled/project/osx/openFrameworksLib.xcodeproj
397 | sourceTree
398 | SOURCE_ROOT
399 |
400 | E4328144138ABC890047C5CB
401 |
402 | children
403 |
404 | E4328148138ABC890047C5CB
405 |
406 | isa
407 | PBXGroup
408 | name
409 | Products
410 | sourceTree
411 | <group>
412 |
413 | E4328147138ABC890047C5CB
414 |
415 | containerPortal
416 | E4328143138ABC890047C5CB
417 | isa
418 | PBXContainerItemProxy
419 | proxyType
420 | 2
421 | remoteGlobalIDString
422 | E4B27C1510CBEB8E00536013
423 | remoteInfo
424 | openFrameworks
425 |
426 | E4328148138ABC890047C5CB
427 |
428 | fileType
429 | archive.ar
430 | isa
431 | PBXReferenceProxy
432 | path
433 | openFrameworksDebug.a
434 | remoteRef
435 | E4328147138ABC890047C5CB
436 | sourceTree
437 | BUILT_PRODUCTS_DIR
438 |
439 | E4328149138ABC9F0047C5CB
440 |
441 | fileRef
442 | E4328148138ABC890047C5CB
443 | isa
444 | PBXBuildFile
445 |
446 | E4B69B4A0A3A1720003C02F2
447 |
448 | children
449 |
450 | E4B6FCAD0C3E899E008CF71C
451 | E4EB6923138AFD0F00A09F29
452 | E4B69E1C0A3A1BDC003C02F2
453 | E4EEC9E9138DF44700A80321
454 | BB4B014C10F69532006C3DED
455 | 6948EE371B920CB800B5AC1A
456 | E4B69B5B0A3A1756003C02F2
457 |
458 | isa
459 | PBXGroup
460 | sourceTree
461 | <group>
462 |
463 | E4B69B4C0A3A1720003C02F2
464 |
465 | attributes
466 |
467 | LastUpgradeCheck
468 | 0600
469 |
470 | buildConfigurationList
471 | E4B69B4D0A3A1720003C02F2
472 | compatibilityVersion
473 | Xcode 3.2
474 | developmentRegion
475 | English
476 | hasScannedForEncodings
477 | 0
478 | isa
479 | PBXProject
480 | knownRegions
481 |
482 | English
483 | Japanese
484 | French
485 | German
486 |
487 | mainGroup
488 | E4B69B4A0A3A1720003C02F2
489 | productRefGroup
490 | E4B69B4A0A3A1720003C02F2
491 | projectDirPath
492 |
493 | projectReferences
494 |
495 |
496 | ProductGroup
497 | E4328144138ABC890047C5CB
498 | ProjectRef
499 | E4328143138ABC890047C5CB
500 |
501 |
502 | projectRoot
503 |
504 | targets
505 |
506 | E4B69B5A0A3A1756003C02F2
507 |
508 |
509 | E4B69B4D0A3A1720003C02F2
510 |
511 | buildConfigurations
512 |
513 | E4B69B4E0A3A1720003C02F2
514 | E4B69B4F0A3A1720003C02F2
515 | 99FA3DBB1C7456C400CFA0EE
516 |
517 | defaultConfigurationIsVisible
518 | 0
519 | defaultConfigurationName
520 | Release
521 | isa
522 | XCConfigurationList
523 |
524 | E4B69B4E0A3A1720003C02F2
525 |
526 | baseConfigurationReference
527 | E4EB6923138AFD0F00A09F29
528 | buildSettings
529 |
530 | HEADER_SEARCH_PATHS
531 |
532 | $(OF_CORE_HEADERS)
533 | src
534 | ../../../addons/ofxNearestNeighbour/libs
535 | ../../../addons/ofxNearestNeighbour/libs/nanoflann
536 | ../../../addons/ofxNearestNeighbour/libs/nanoflann/include
537 | ../../../addons/ofxNearestNeighbour/src
538 |
539 | CONFIGURATION_BUILD_DIR
540 | $(SRCROOT)/bin/
541 | COPY_PHASE_STRIP
542 | NO
543 | DEAD_CODE_STRIPPING
544 | YES
545 | GCC_AUTO_VECTORIZATION
546 | YES
547 | GCC_ENABLE_SSE3_EXTENSIONS
548 | YES
549 | GCC_ENABLE_SUPPLEMENTAL_SSE3_INSTRUCTIONS
550 | YES
551 | GCC_INLINES_ARE_PRIVATE_EXTERN
552 | NO
553 | GCC_OPTIMIZATION_LEVEL
554 | 0
555 | GCC_SYMBOLS_PRIVATE_EXTERN
556 | NO
557 | GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS
558 | YES
559 | GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO
560 | NO
561 | GCC_WARN_ALLOW_INCOMPLETE_PROTOCOL
562 | NO
563 | GCC_WARN_UNINITIALIZED_AUTOS
564 | NO
565 | GCC_WARN_UNUSED_VALUE
566 | NO
567 | GCC_WARN_UNUSED_VARIABLE
568 | NO
569 | MACOSX_DEPLOYMENT_TARGET
570 | 10.9
571 | ONLY_ACTIVE_ARCH
572 | YES
573 | OTHER_CPLUSPLUSFLAGS
574 |
575 | -D__MACOSX_CORE__
576 | -mtune=native
577 |
578 | SDKROOT
579 | macosx
580 |
581 | isa
582 | XCBuildConfiguration
583 | name
584 | Debug
585 |
586 | E4B69B4F0A3A1720003C02F2
587 |
588 | baseConfigurationReference
589 | E4EB6923138AFD0F00A09F29
590 | buildSettings
591 |
592 | HEADER_SEARCH_PATHS
593 |
594 | $(OF_CORE_HEADERS)
595 | src
596 | ../../../addons/ofxNearestNeighbour/libs
597 | ../../../addons/ofxNearestNeighbour/libs/nanoflann
598 | ../../../addons/ofxNearestNeighbour/libs/nanoflann/include
599 | ../../../addons/ofxNearestNeighbour/src
600 |
601 | CONFIGURATION_BUILD_DIR
602 | $(SRCROOT)/bin/
603 | COPY_PHASE_STRIP
604 | YES
605 | DEAD_CODE_STRIPPING
606 | YES
607 | GCC_AUTO_VECTORIZATION
608 | YES
609 | GCC_ENABLE_SSE3_EXTENSIONS
610 | YES
611 | GCC_ENABLE_SUPPLEMENTAL_SSE3_INSTRUCTIONS
612 | YES
613 | GCC_INLINES_ARE_PRIVATE_EXTERN
614 | NO
615 | GCC_OPTIMIZATION_LEVEL
616 | 3
617 | GCC_SYMBOLS_PRIVATE_EXTERN
618 | NO
619 | GCC_UNROLL_LOOPS
620 | YES
621 | GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS
622 | YES
623 | GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO
624 | NO
625 | GCC_WARN_ALLOW_INCOMPLETE_PROTOCOL
626 | NO
627 | GCC_WARN_UNINITIALIZED_AUTOS
628 | NO
629 | GCC_WARN_UNUSED_VALUE
630 | NO
631 | GCC_WARN_UNUSED_VARIABLE
632 | NO
633 | MACOSX_DEPLOYMENT_TARGET
634 | 10.9
635 | OTHER_CPLUSPLUSFLAGS
636 |
637 | -D__MACOSX_CORE__
638 | -mtune=native
639 |
640 | SDKROOT
641 | macosx
642 |
643 | isa
644 | XCBuildConfiguration
645 | name
646 | Release
647 |
648 | E4B69B580A3A1756003C02F2
649 |
650 | buildActionMask
651 | 2147483647
652 | files
653 |
654 | E4B69E200A3A1BDC003C02F2
655 | E4B69E210A3A1BDC003C02F2
656 |
657 | isa
658 | PBXSourcesBuildPhase
659 | runOnlyForDeploymentPostprocessing
660 | 0
661 |
662 | E4B69B590A3A1756003C02F2
663 |
664 | buildActionMask
665 | 2147483647
666 | files
667 |
668 | E4328149138ABC9F0047C5CB
669 |
670 | isa
671 | PBXFrameworksBuildPhase
672 | runOnlyForDeploymentPostprocessing
673 | 0
674 |
675 | E4B69B5A0A3A1756003C02F2
676 |
677 | buildConfigurationList
678 | E4B69B5F0A3A1757003C02F2
679 | buildPhases
680 |
681 | E4B69B580A3A1756003C02F2
682 | E4B69B590A3A1756003C02F2
683 | E4B6FFFD0C3F9AB9008CF71C
684 | E4C2427710CC5ABF004149E2
685 | 8466F1851C04CA0E00918B1C
686 |
687 | buildRules
688 |
689 | dependencies
690 |
691 | E4EEB9AC138B136A00A80321
692 |
693 | isa
694 | PBXNativeTarget
695 | name
696 | example-radius
697 | productName
698 | myOFApp
699 | productReference
700 | E4B69B5B0A3A1756003C02F2
701 | productType
702 | com.apple.product-type.application
703 |
704 | E4B69B5B0A3A1756003C02F2
705 |
706 | explicitFileType
707 | wrapper.application
708 | includeInIndex
709 | 0
710 | isa
711 | PBXFileReference
712 | path
713 | example-radiusDebug.app
714 | sourceTree
715 | BUILT_PRODUCTS_DIR
716 |
717 | E4B69B5F0A3A1757003C02F2
718 |
719 | buildConfigurations
720 |
721 | E4B69B600A3A1757003C02F2
722 | E4B69B610A3A1757003C02F2
723 | 99FA3DBC1C7456C400CFA0EE
724 |
725 | defaultConfigurationIsVisible
726 | 0
727 | defaultConfigurationName
728 | Release
729 | isa
730 | XCConfigurationList
731 |
732 | E4B69B600A3A1757003C02F2
733 |
734 | baseConfigurationReference
735 | E4EB6923138AFD0F00A09F29
736 | buildSettings
737 |
738 | HEADER_SEARCH_PATHS
739 |
740 | $(OF_CORE_HEADERS)
741 | src
742 | ../../../addons/ofxNearestNeighbour/libs
743 | ../../../addons/ofxNearestNeighbour/libs/nanoflann
744 | ../../../addons/ofxNearestNeighbour/libs/nanoflann/include
745 | ../../../addons/ofxNearestNeighbour/src
746 |
747 | COMBINE_HIDPI_IMAGES
748 | YES
749 | COPY_PHASE_STRIP
750 | NO
751 | FRAMEWORK_SEARCH_PATHS
752 | $(inherited)
753 | GCC_DYNAMIC_NO_PIC
754 | NO
755 | GCC_GENERATE_DEBUGGING_SYMBOLS
756 | YES
757 | GCC_MODEL_TUNING
758 | NONE
759 | ICON
760 | $(ICON_NAME_DEBUG)
761 | ICON_FILE
762 | $(ICON_FILE_PATH)$(ICON)
763 | INFOPLIST_FILE
764 | openFrameworks-Info.plist
765 | INSTALL_PATH
766 | /Applications
767 | LIBRARY_SEARCH_PATHS
768 | $(inherited)
769 | PRODUCT_NAME
770 | $(TARGET_NAME)Debug
771 | WRAPPER_EXTENSION
772 | app
773 |
774 | isa
775 | XCBuildConfiguration
776 | name
777 | Debug
778 |
779 | E4B69B610A3A1757003C02F2
780 |
781 | baseConfigurationReference
782 | E4EB6923138AFD0F00A09F29
783 | buildSettings
784 |
785 | HEADER_SEARCH_PATHS
786 |
787 | $(OF_CORE_HEADERS)
788 | src
789 | ../../../addons/ofxNearestNeighbour/libs
790 | ../../../addons/ofxNearestNeighbour/libs/nanoflann
791 | ../../../addons/ofxNearestNeighbour/libs/nanoflann/include
792 | ../../../addons/ofxNearestNeighbour/src
793 |
794 | COMBINE_HIDPI_IMAGES
795 | YES
796 | COPY_PHASE_STRIP
797 | YES
798 | FRAMEWORK_SEARCH_PATHS
799 | $(inherited)
800 | GCC_GENERATE_DEBUGGING_SYMBOLS
801 | YES
802 | GCC_MODEL_TUNING
803 | NONE
804 | ICON
805 | $(ICON_NAME_RELEASE)
806 | ICON_FILE
807 | $(ICON_FILE_PATH)$(ICON)
808 | INFOPLIST_FILE
809 | openFrameworks-Info.plist
810 | INSTALL_PATH
811 | /Applications
812 | LIBRARY_SEARCH_PATHS
813 | $(inherited)
814 | PRODUCT_NAME
815 | $(TARGET_NAME)
816 | WRAPPER_EXTENSION
817 | app
818 | baseConfigurationReference
819 | E4EB6923138AFD0F00A09F29
820 |
821 | isa
822 | XCBuildConfiguration
823 | name
824 | Release
825 |
826 | E4B69E1C0A3A1BDC003C02F2
827 |
828 | children
829 |
830 | E4B69E1D0A3A1BDC003C02F2
831 | E4B69E1E0A3A1BDC003C02F2
832 | E4B69E1F0A3A1BDC003C02F2
833 |
834 | isa
835 | PBXGroup
836 | path
837 | src
838 | sourceTree
839 | SOURCE_ROOT
840 |
841 | E4B69E1D0A3A1BDC003C02F2
842 |
843 | fileEncoding
844 | 4
845 | isa
846 | PBXFileReference
847 | lastKnownFileType
848 | sourcecode.cpp.cpp
849 | name
850 | main.cpp
851 | path
852 | src/main.cpp
853 | sourceTree
854 | SOURCE_ROOT
855 |
856 | E4B69E1E0A3A1BDC003C02F2
857 |
858 | explicitFileType
859 | sourcecode.cpp.cpp
860 | fileEncoding
861 | 4
862 | isa
863 | PBXFileReference
864 | name
865 | ofApp.cpp
866 | path
867 | src/ofApp.cpp
868 | sourceTree
869 | SOURCE_ROOT
870 |
871 | E4B69E1F0A3A1BDC003C02F2
872 |
873 | fileEncoding
874 | 4
875 | isa
876 | PBXFileReference
877 | lastKnownFileType
878 | sourcecode.c.h
879 | name
880 | ofApp.h
881 | path
882 | src/ofApp.h
883 | sourceTree
884 | SOURCE_ROOT
885 |
886 | E4B69E200A3A1BDC003C02F2
887 |
888 | fileRef
889 | E4B69E1D0A3A1BDC003C02F2
890 | isa
891 | PBXBuildFile
892 |
893 | E4B69E210A3A1BDC003C02F2
894 |
895 | fileRef
896 | E4B69E1E0A3A1BDC003C02F2
897 | isa
898 | PBXBuildFile
899 |
900 | E4B6FCAD0C3E899E008CF71C
901 |
902 | fileEncoding
903 | 4
904 | isa
905 | PBXFileReference
906 | lastKnownFileType
907 | text.plist.xml
908 | path
909 | openFrameworks-Info.plist
910 | sourceTree
911 | <group>
912 |
913 | E4B6FFFD0C3F9AB9008CF71C
914 |
915 | buildActionMask
916 | 2147483647
917 | files
918 |
919 | inputPaths
920 |
921 | isa
922 | PBXShellScriptBuildPhase
923 | outputPaths
924 |
925 | runOnlyForDeploymentPostprocessing
926 | 0
927 | shellPath
928 | /bin/sh
929 | shellScript
930 | mkdir -p "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Resources/"
931 | # Copy default icon file into App/Resources
932 | rsync -aved "$ICON_FILE" "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Resources/"
933 | # Copy libfmod and change install directory for fmod to run
934 | rsync -aved "$OF_PATH/libs/fmodex/lib/osx/libfmodex.dylib" "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Frameworks/";
935 | install_name_tool -change @executable_path/libfmodex.dylib @executable_path/../Frameworks/libfmodex.dylib "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/$PRODUCT_NAME";
936 |
937 | echo "$GCC_PREPROCESSOR_DEFINITIONS";
938 |
939 |
940 | E4C2427710CC5ABF004149E2
941 |
942 | buildActionMask
943 | 2147483647
944 | dstPath
945 |
946 | dstSubfolderSpec
947 | 10
948 | files
949 |
950 | isa
951 | PBXCopyFilesBuildPhase
952 | runOnlyForDeploymentPostprocessing
953 | 0
954 |
955 | E4EB691F138AFCF100A09F29
956 |
957 | fileEncoding
958 | 4
959 | isa
960 | PBXFileReference
961 | lastKnownFileType
962 | text.xcconfig
963 | name
964 | CoreOF.xcconfig
965 | path
966 | ../../../libs/openFrameworksCompiled/project/osx/CoreOF.xcconfig
967 | sourceTree
968 | SOURCE_ROOT
969 |
970 | E4EB6923138AFD0F00A09F29
971 |
972 | fileEncoding
973 | 4
974 | isa
975 | PBXFileReference
976 | lastKnownFileType
977 | text.xcconfig
978 | path
979 | Project.xcconfig
980 | sourceTree
981 | <group>
982 |
983 | E4EEB9AB138B136A00A80321
984 |
985 | containerPortal
986 | E4328143138ABC890047C5CB
987 | isa
988 | PBXContainerItemProxy
989 | proxyType
990 | 1
991 | remoteGlobalIDString
992 | E4B27C1410CBEB8E00536013
993 | remoteInfo
994 | openFrameworks
995 |
996 | E4EEB9AC138B136A00A80321
997 |
998 | isa
999 | PBXTargetDependency
1000 | name
1001 | openFrameworks
1002 | targetProxy
1003 | E4EEB9AB138B136A00A80321
1004 |
1005 | E4EEC9E9138DF44700A80321
1006 |
1007 | children
1008 |
1009 | E4EB691F138AFCF100A09F29
1010 | E4328143138ABC890047C5CB
1011 |
1012 | isa
1013 | PBXGroup
1014 | name
1015 | openFrameworks
1016 | sourceTree
1017 | <group>
1018 |
1019 |
1020 | rootObject
1021 | E4B69B4C0A3A1720003C02F2
1022 |
1023 |
1024 |
--------------------------------------------------------------------------------
/example-radius/example-radius.xcodeproj/xcshareddata/xcschemes/example-radius Debug.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
51 |
52 |
58 |
59 |
60 |
61 |
62 |
63 |
69 |
70 |
76 |
77 |
78 |
79 |
81 |
82 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/example-radius/example-radius.xcodeproj/xcshareddata/xcschemes/example-radius Release.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
51 |
52 |
58 |
59 |
60 |
61 |
62 |
63 |
69 |
70 |
76 |
77 |
78 |
79 |
81 |
82 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/example-radius/openFrameworks-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIdentifier
10 | cc.openFrameworks.ofapp
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundlePackageType
14 | APPL
15 | CFBundleSignature
16 | ????
17 | CFBundleVersion
18 | 1.0
19 | CFBundleIconFile
20 | ${ICON}
21 |
22 |
23 |
--------------------------------------------------------------------------------
/example-radius/src/main.cpp:
--------------------------------------------------------------------------------
1 | #include "ofMain.h"
2 | #include "ofApp.h"
3 |
4 | //========================================================================
5 | int main( ){
6 | ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context
7 |
8 | // this kicks off the running of my app
9 | // can be OF_WINDOW or OF_FULLSCREEN
10 | // pass in width and height too:
11 | ofRunApp(new ofApp());
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/example-radius/src/ofApp.cpp:
--------------------------------------------------------------------------------
1 | #include "ofApp.h"
2 |
3 | //--------------------------------------------------------------
4 | void ofApp::setup()
5 | {
6 | const unsigned numPoints = 10000;
7 | ofBackground(0);
8 | points.reserve(numPoints);
9 | for (unsigned i = 0; i < numPoints; ++i)
10 | {
11 | points.push_back(ofVec2f(ofRandom(50, ofGetWidth() - 50), ofRandom(50, ofGetHeight() - 50)));
12 | }
13 | nn.buildIndex(points);
14 | }
15 |
16 | //--------------------------------------------------------------
17 | void ofApp::update()
18 | {
19 | ofSetWindowTitle(ofToString(ofGetFrameRate(), 2));
20 | ofVec2f mouse(ofGetMouseX(), ofGetMouseY());
21 | nn.findPointsWithinRadius(mouse, 50, indices);
22 | }
23 |
24 | //--------------------------------------------------------------
25 | void ofApp::draw()
26 | {
27 | ofSetColor(255, 0, 0);
28 | for (unsigned i = 0; i < points.size(); ++i)
29 | {
30 | ofDrawCircle(points[i], 2);
31 | }
32 | ofSetColor(0, 255, 0);
33 | for (unsigned i = 0; i < indices.size(); ++i)
34 | {
35 | ofDrawCircle(points[indices[i].first], 2);
36 | }
37 | ofSetColor(255);
38 | ofDrawBitmapString("Move mouse to find nearest neighbours", 10, 20);
39 | }
40 |
41 | //--------------------------------------------------------------
42 | void ofApp::keyPressed(int key){
43 |
44 | }
45 |
46 | //--------------------------------------------------------------
47 | void ofApp::keyReleased(int key){
48 |
49 | }
50 |
51 | //--------------------------------------------------------------
52 | void ofApp::mouseMoved(int x, int y ){
53 |
54 | }
55 |
56 | //--------------------------------------------------------------
57 | void ofApp::mouseDragged(int x, int y, int button){
58 |
59 | }
60 |
61 | //--------------------------------------------------------------
62 | void ofApp::mousePressed(int x, int y, int button){
63 |
64 | }
65 |
66 | //--------------------------------------------------------------
67 | void ofApp::mouseReleased(int x, int y, int button){
68 |
69 | }
70 |
71 | //--------------------------------------------------------------
72 | void ofApp::windowResized(int w, int h){
73 |
74 | }
75 |
76 | //--------------------------------------------------------------
77 | void ofApp::gotMessage(ofMessage msg){
78 |
79 | }
80 |
81 | //--------------------------------------------------------------
82 | void ofApp::dragEvent(ofDragInfo dragInfo){
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/example-radius/src/ofApp.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "ofMain.h"
4 | #include "ofxNearestNeighbour.h"
5 |
6 | class ofApp : public ofBaseApp
7 | {
8 | public:
9 | void setup();
10 | void update();
11 | void draw();
12 |
13 | void keyPressed(int key);
14 | void keyReleased(int key);
15 | void mouseMoved(int x, int y );
16 | void mouseDragged(int x, int y, int button);
17 | void mousePressed(int x, int y, int button);
18 | void mouseReleased(int x, int y, int button);
19 | void windowResized(int w, int h);
20 | void dragEvent(ofDragInfo dragInfo);
21 | void gotMessage(ofMessage msg);
22 |
23 | private:
24 | ofxNearestNeighbour2D nn;
25 | vector points;
26 | vector > indices;
27 | };
28 |
--------------------------------------------------------------------------------
/libs/nanoflann/include/nanoflann.hpp:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 | * Software License Agreement (BSD License)
3 | *
4 | * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved.
5 | * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved.
6 | * Copyright 2011-2013 Jose Luis Blanco (joseluisblancoc@gmail.com).
7 | * All rights reserved.
8 | *
9 | * THE BSD LICENSE
10 | *
11 | * Redistribution and use in source and binary forms, with or without
12 | * modification, are permitted provided that the following conditions
13 | * are met:
14 | *
15 | * 1. Redistributions of source code must retain the above copyright
16 | * notice, this list of conditions and the following disclaimer.
17 | * 2. Redistributions in binary form must reproduce the above copyright
18 | * notice, this list of conditions and the following disclaimer in the
19 | * documentation and/or other materials provided with the distribution.
20 | *
21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | *************************************************************************/
32 |
33 | #ifndef NANOFLANN_HPP_
34 | #define NANOFLANN_HPP_
35 |
36 | #include
37 | #include
38 | #include
39 | #include
40 | #include // for fwrite()
41 | #include // for fabs(),...
42 | #include
43 |
44 | // Avoid conflicting declaration of min/max macros in windows headers
45 | #if !defined(NOMINMAX) && (defined(_WIN32) || defined(_WIN32_) || defined(WIN32) || defined(_WIN64))
46 | # define NOMINMAX
47 | # ifdef max
48 | # undef max
49 | # undef min
50 | # endif
51 | #endif
52 |
53 | namespace nanoflann
54 | {
55 | /** @addtogroup nanoflann_grp nanoflann C++ library for ANN
56 | * @{ */
57 |
58 | /** Library version: 0xMmP (M=Major,m=minor,P=path) */
59 | #define NANOFLANN_VERSION 0x117
60 |
61 | /** @addtogroup result_sets_grp Result set classes
62 | * @{ */
63 | template
64 | class KNNResultSet
65 | {
66 | IndexType * indices;
67 | DistanceType* dists;
68 | CountType capacity;
69 | CountType count;
70 |
71 | public:
72 | inline KNNResultSet(CountType capacity_) : capacity(capacity_), count(0)
73 | {
74 | }
75 |
76 | inline void init(IndexType* indices_, DistanceType* dists_)
77 | {
78 | indices = indices_;
79 | dists = dists_;
80 | count = 0;
81 | dists[capacity-1] = (std::numeric_limits::max)();
82 | }
83 |
84 | inline CountType size() const
85 | {
86 | return count;
87 | }
88 |
89 | inline bool full() const
90 | {
91 | return count == capacity;
92 | }
93 |
94 |
95 | inline void addPoint(DistanceType dist, IndexType index)
96 | {
97 | CountType i;
98 | for (i=count; i>0; --i) {
99 | #ifdef NANOFLANN_FIRST_MATCH // If defined and two poins have the same distance, the one with the lowest-index will be returned first.
100 | if ( (dists[i-1]>dist) || ((dist==dists[i-1])&&(indices[i-1]>index)) ) {
101 | #else
102 | if (dists[i-1]>dist) {
103 | #endif
104 | if (i
129 | class RadiusResultSet
130 | {
131 | public:
132 | const DistanceType radius;
133 |
134 | std::vector >& m_indices_dists;
135 |
136 | inline RadiusResultSet(DistanceType radius_, std::vector >& indices_dists) : radius(radius_), m_indices_dists(indices_dists)
137 | {
138 | init();
139 | }
140 |
141 | inline ~RadiusResultSet() { }
142 |
143 | inline void init() { clear(); }
144 | inline void clear() { m_indices_dists.clear(); }
145 |
146 | inline size_t size() const { return m_indices_dists.size(); }
147 |
148 | inline bool full() const { return true; }
149 |
150 | inline void addPoint(DistanceType dist, IndexType index)
151 | {
152 | if (dist 0
168 | */
169 | std::pair worst_item() const
170 | {
171 | if (m_indices_dists.empty()) throw std::runtime_error("Cannot invoke RadiusResultSet::worst_item() on an empty list of results.");
172 | typedef typename std::vector >::const_iterator DistIt;
173 | DistIt it = std::max_element(m_indices_dists.begin(), m_indices_dists.end());
174 | return *it;
175 | }
176 | };
177 |
178 | /** operator "<" for std::sort() */
179 | struct IndexDist_Sorter
180 | {
181 | /** PairType will be typically: std::pair */
182 | template
183 | inline bool operator()(const PairType &p1, const PairType &p2) const {
184 | return p1.second < p2.second;
185 | }
186 | };
187 |
188 | /** @} */
189 |
190 |
191 | /** @addtogroup loadsave_grp Load/save auxiliary functions
192 | * @{ */
193 | template
194 | void save_value(FILE* stream, const T& value, size_t count = 1)
195 | {
196 | fwrite(&value, sizeof(value),count, stream);
197 | }
198 |
199 | template
200 | void save_value(FILE* stream, const std::vector& value)
201 | {
202 | size_t size = value.size();
203 | fwrite(&size, sizeof(size_t), 1, stream);
204 | fwrite(&value[0], sizeof(T), size, stream);
205 | }
206 |
207 | template
208 | void load_value(FILE* stream, T& value, size_t count = 1)
209 | {
210 | size_t read_cnt = fread(&value, sizeof(value), count, stream);
211 | if (read_cnt != count) {
212 | throw std::runtime_error("Cannot read from file");
213 | }
214 | }
215 |
216 |
217 | template
218 | void load_value(FILE* stream, std::vector& value)
219 | {
220 | size_t size;
221 | size_t read_cnt = fread(&size, sizeof(size_t), 1, stream);
222 | if (read_cnt!=1) {
223 | throw std::runtime_error("Cannot read from file");
224 | }
225 | value.resize(size);
226 | read_cnt = fread(&value[0], sizeof(T), size, stream);
227 | if (read_cnt!=size) {
228 | throw std::runtime_error("Cannot read from file");
229 | }
230 | }
231 | /** @} */
232 |
233 |
234 | /** @addtogroup metric_grp Metric (distance) classes
235 | * @{ */
236 |
237 | template inline T abs(T x) { return (x<0) ? -x : x; }
238 | template<> inline int abs(int x) { return ::abs(x); }
239 | template<> inline float abs(float x) { return fabsf(x); }
240 | template<> inline double abs(double x) { return fabs(x); }
241 | template<> inline long double abs(long double x) { return fabsl(x); }
242 |
243 | /** Manhattan distance functor (generic version, optimized for high-dimensionality data sets).
244 | * Corresponding distance traits: nanoflann::metric_L1
245 | * \tparam T Type of the elements (e.g. double, float, uint8_t)
246 | * \tparam DistanceType Type of distance variables (must be signed) (e.g. float, double, int64_t)
247 | */
248 | template
249 | struct L1_Adaptor
250 | {
251 | typedef T ElementType;
252 | typedef _DistanceType DistanceType;
253 |
254 | const DataSource &data_source;
255 |
256 | L1_Adaptor(const DataSource &_data_source) : data_source(_data_source) { }
257 |
258 | inline DistanceType operator()(const T* a, const size_t b_idx, size_t size, DistanceType worst_dist = -1) const
259 | {
260 | DistanceType result = DistanceType();
261 | const T* last = a + size;
262 | const T* lastgroup = last - 3;
263 | size_t d = 0;
264 |
265 | /* Process 4 items with each loop for efficiency. */
266 | while (a < lastgroup) {
267 | const DistanceType diff0 = nanoflann::abs(a[0] - data_source.kdtree_get_pt(b_idx,d++));
268 | const DistanceType diff1 = nanoflann::abs(a[1] - data_source.kdtree_get_pt(b_idx,d++));
269 | const DistanceType diff2 = nanoflann::abs(a[2] - data_source.kdtree_get_pt(b_idx,d++));
270 | const DistanceType diff3 = nanoflann::abs(a[3] - data_source.kdtree_get_pt(b_idx,d++));
271 | result += diff0 + diff1 + diff2 + diff3;
272 | a += 4;
273 | if ((worst_dist>0)&&(result>worst_dist)) {
274 | return result;
275 | }
276 | }
277 | /* Process last 0-3 components. Not needed for standard vector lengths. */
278 | while (a < last) {
279 | result += nanoflann::abs( *a++ - data_source.kdtree_get_pt(b_idx,d++) );
280 | }
281 | return result;
282 | }
283 |
284 | template
285 | inline DistanceType accum_dist(const U a, const V b, int ) const
286 | {
287 | return nanoflann::abs(a-b);
288 | }
289 | };
290 |
291 | /** Squared Euclidean distance functor (generic version, optimized for high-dimensionality data sets).
292 | * Corresponding distance traits: nanoflann::metric_L2
293 | * \tparam T Type of the elements (e.g. double, float, uint8_t)
294 | * \tparam DistanceType Type of distance variables (must be signed) (e.g. float, double, int64_t)
295 | */
296 | template
297 | struct L2_Adaptor
298 | {
299 | typedef T ElementType;
300 | typedef _DistanceType DistanceType;
301 |
302 | const DataSource &data_source;
303 |
304 | L2_Adaptor(const DataSource &_data_source) : data_source(_data_source) { }
305 |
306 | inline DistanceType operator()(const T* a, const size_t b_idx, size_t size, DistanceType worst_dist = -1) const
307 | {
308 | DistanceType result = DistanceType();
309 | const T* last = a + size;
310 | const T* lastgroup = last - 3;
311 | size_t d = 0;
312 |
313 | /* Process 4 items with each loop for efficiency. */
314 | while (a < lastgroup) {
315 | const DistanceType diff0 = a[0] - data_source.kdtree_get_pt(b_idx,d++);
316 | const DistanceType diff1 = a[1] - data_source.kdtree_get_pt(b_idx,d++);
317 | const DistanceType diff2 = a[2] - data_source.kdtree_get_pt(b_idx,d++);
318 | const DistanceType diff3 = a[3] - data_source.kdtree_get_pt(b_idx,d++);
319 | result += diff0 * diff0 + diff1 * diff1 + diff2 * diff2 + diff3 * diff3;
320 | a += 4;
321 | if ((worst_dist>0)&&(result>worst_dist)) {
322 | return result;
323 | }
324 | }
325 | /* Process last 0-3 components. Not needed for standard vector lengths. */
326 | while (a < last) {
327 | const DistanceType diff0 = *a++ - data_source.kdtree_get_pt(b_idx,d++);
328 | result += diff0 * diff0;
329 | }
330 | return result;
331 | }
332 |
333 | template
334 | inline DistanceType accum_dist(const U a, const V b, int ) const
335 | {
336 | return (a-b)*(a-b);
337 | }
338 | };
339 |
340 | /** Squared Euclidean distance functor (suitable for low-dimensionality datasets, like 2D or 3D point clouds)
341 | * Corresponding distance traits: nanoflann::metric_L2_Simple
342 | * \tparam T Type of the elements (e.g. double, float, uint8_t)
343 | * \tparam DistanceType Type of distance variables (must be signed) (e.g. float, double, int64_t)
344 | */
345 | template
346 | struct L2_Simple_Adaptor
347 | {
348 | typedef T ElementType;
349 | typedef _DistanceType DistanceType;
350 |
351 | const DataSource &data_source;
352 |
353 | L2_Simple_Adaptor(const DataSource &_data_source) : data_source(_data_source) { }
354 |
355 | inline DistanceType operator()(const T* a, const size_t b_idx, size_t size) const {
356 | return data_source.kdtree_distance(a,b_idx,size);
357 | }
358 |
359 | template
360 | inline DistanceType accum_dist(const U a, const V b, int ) const
361 | {
362 | return (a-b)*(a-b);
363 | }
364 | };
365 |
366 | /** Metaprogramming helper traits class for the L1 (Manhattan) metric */
367 | struct metric_L1 {
368 | template
369 | struct traits {
370 | typedef L1_Adaptor distance_t;
371 | };
372 | };
373 | /** Metaprogramming helper traits class for the L2 (Euclidean) metric */
374 | struct metric_L2 {
375 | template
376 | struct traits {
377 | typedef L2_Adaptor distance_t;
378 | };
379 | };
380 | /** Metaprogramming helper traits class for the L2_simple (Euclidean) metric */
381 | struct metric_L2_Simple {
382 | template
383 | struct traits {
384 | typedef L2_Simple_Adaptor distance_t;
385 | };
386 | };
387 |
388 | /** @} */
389 |
390 |
391 |
392 | /** @addtogroup param_grp Parameter structs
393 | * @{ */
394 |
395 | /** Parameters (see http://code.google.com/p/nanoflann/ for help choosing the parameters)
396 | */
397 | struct KDTreeSingleIndexAdaptorParams
398 | {
399 | KDTreeSingleIndexAdaptorParams(size_t _leaf_max_size = 10, int dim_ = -1) :
400 | leaf_max_size(_leaf_max_size), dim(dim_)
401 | {}
402 |
403 | size_t leaf_max_size;
404 | int dim;
405 | };
406 |
407 | /** Search options for KDTreeSingleIndexAdaptor::findNeighbors() */
408 | struct SearchParams
409 | {
410 | /** Note: The first argument (checks_IGNORED_) is ignored, but kept for compatibility with the FLANN interface */
411 | SearchParams(int checks_IGNORED_ = 32, float eps_ = 0, bool sorted_ = true ) :
412 | checks(checks_IGNORED_), eps(eps_), sorted(sorted_) {}
413 |
414 | int checks; //!< Ignored parameter (Kept for compatibility with the FLANN interface).
415 | float eps; //!< search for eps-approximate neighbours (default: 0)
416 | bool sorted; //!< only for radius search, require neighbours sorted by distance (default: true)
417 | };
418 | /** @} */
419 |
420 |
421 | /** @addtogroup memalloc_grp Memory allocation
422 | * @{ */
423 |
424 | /**
425 | * Allocates (using C's malloc) a generic type T.
426 | *
427 | * Params:
428 | * count = number of instances to allocate.
429 | * Returns: pointer (of type T*) to memory buffer
430 | */
431 | template
432 | inline T* allocate(size_t count = 1)
433 | {
434 | T* mem = (T*) ::malloc(sizeof(T)*count);
435 | return mem;
436 | }
437 |
438 |
439 | /**
440 | * Pooled storage allocator
441 | *
442 | * The following routines allow for the efficient allocation of storage in
443 | * small chunks from a specified pool. Rather than allowing each structure
444 | * to be freed individually, an entire pool of storage is freed at once.
445 | * This method has two advantages over just using malloc() and free(). First,
446 | * it is far more efficient for allocating small objects, as there is
447 | * no overhead for remembering all the information needed to free each
448 | * object or consolidating fragmented memory. Second, the decision about
449 | * how long to keep an object is made at the time of allocation, and there
450 | * is no need to track down all the objects to free them.
451 | *
452 | */
453 |
454 | const size_t WORDSIZE=16;
455 | const size_t BLOCKSIZE=8192;
456 |
457 | class PooledAllocator
458 | {
459 | /* We maintain memory alignment to word boundaries by requiring that all
460 | allocations be in multiples of the machine wordsize. */
461 | /* Size of machine word in bytes. Must be power of 2. */
462 | /* Minimum number of bytes requested at a time from the system. Must be multiple of WORDSIZE. */
463 |
464 |
465 | size_t remaining; /* Number of bytes left in current block of storage. */
466 | void* base; /* Pointer to base of current block of storage. */
467 | void* loc; /* Current location in block to next allocate memory. */
468 | size_t blocksize;
469 |
470 | void internal_init()
471 | {
472 | remaining = 0;
473 | base = NULL;
474 | usedMemory = 0;
475 | wastedMemory = 0;
476 | }
477 |
478 | public:
479 | size_t usedMemory;
480 | size_t wastedMemory;
481 |
482 | /**
483 | Default constructor. Initializes a new pool.
484 | */
485 | PooledAllocator(const size_t blocksize_ = BLOCKSIZE) : blocksize(blocksize_) {
486 | internal_init();
487 | }
488 |
489 | /**
490 | * Destructor. Frees all the memory allocated in this pool.
491 | */
492 | ~PooledAllocator() {
493 | free_all();
494 | }
495 |
496 | /** Frees all allocated memory chunks */
497 | void free_all()
498 | {
499 | while (base != NULL) {
500 | void *prev = *((void**) base); /* Get pointer to prev block. */
501 | ::free(base);
502 | base = prev;
503 | }
504 | internal_init();
505 | }
506 |
507 | /**
508 | * Returns a pointer to a piece of new memory of the given size in bytes
509 | * allocated from the pool.
510 | */
511 | void* malloc(const size_t req_size)
512 | {
513 | /* Round size up to a multiple of wordsize. The following expression
514 | only works for WORDSIZE that is a power of 2, by masking last bits of
515 | incremented size to zero.
516 | */
517 | const size_t size = (req_size + (WORDSIZE - 1)) & ~(WORDSIZE - 1);
518 |
519 | /* Check whether a new block must be allocated. Note that the first word
520 | of a block is reserved for a pointer to the previous block.
521 | */
522 | if (size > remaining) {
523 |
524 | wastedMemory += remaining;
525 |
526 | /* Allocate new storage. */
527 | const size_t blocksize = (size + sizeof(void*) + (WORDSIZE-1) > BLOCKSIZE) ?
528 | size + sizeof(void*) + (WORDSIZE-1) : BLOCKSIZE;
529 |
530 | // use the standard C malloc to allocate memory
531 | void* m = ::malloc(blocksize);
532 | if (!m) {
533 | fprintf(stderr,"Failed to allocate memory.\n");
534 | return NULL;
535 | }
536 |
537 | /* Fill first word of new block with pointer to previous block. */
538 | ((void**) m)[0] = base;
539 | base = m;
540 |
541 | size_t shift = 0;
542 | //int size_t = (WORDSIZE - ( (((size_t)m) + sizeof(void*)) & (WORDSIZE-1))) & (WORDSIZE-1);
543 |
544 | remaining = blocksize - sizeof(void*) - shift;
545 | loc = ((char*)m + sizeof(void*) + shift);
546 | }
547 | void* rloc = loc;
548 | loc = (char*)loc + size;
549 | remaining -= size;
550 |
551 | usedMemory += size;
552 |
553 | return rloc;
554 | }
555 |
556 | /**
557 | * Allocates (using this pool) a generic type T.
558 | *
559 | * Params:
560 | * count = number of instances to allocate.
561 | * Returns: pointer (of type T*) to memory buffer
562 | */
563 | template
564 | T* allocate(const size_t count = 1)
565 | {
566 | T* mem = (T*) this->malloc(sizeof(T)*count);
567 | return mem;
568 | }
569 |
570 | };
571 | /** @} */
572 |
573 | /** @addtogroup nanoflann_metaprog_grp Auxiliary metaprogramming stuff
574 | * @{ */
575 |
576 | // ---------------- CArray -------------------------
577 | /** A STL container (as wrapper) for arrays of constant size defined at compile time (class imported from the MRPT project)
578 | * This code is an adapted version from Boost, modifed for its integration
579 | * within MRPT (JLBC, Dec/2009) (Renamed array -> CArray to avoid possible potential conflicts).
580 | * See
581 | * http://www.josuttis.com/cppcode
582 | * for details and the latest version.
583 | * See
584 | * http://www.boost.org/libs/array for Documentation.
585 | * for documentation.
586 | *
587 | * (C) Copyright Nicolai M. Josuttis 2001.
588 | * Permission to copy, use, modify, sell and distribute this software
589 | * is granted provided this copyright notice appears in all copies.
590 | * This software is provided "as is" without express or implied
591 | * warranty, and with no claim as to its suitability for any purpose.
592 | *
593 | * 29 Jan 2004 - minor fixes (Nico Josuttis)
594 | * 04 Dec 2003 - update to synch with library TR1 (Alisdair Meredith)
595 | * 23 Aug 2002 - fix for Non-MSVC compilers combined with MSVC libraries.
596 | * 05 Aug 2001 - minor update (Nico Josuttis)
597 | * 20 Jan 2001 - STLport fix (Beman Dawes)
598 | * 29 Sep 2000 - Initial Revision (Nico Josuttis)
599 | *
600 | * Jan 30, 2004
601 | */
602 | template
603 | class CArray {
604 | public:
605 | T elems[N]; // fixed-size array of elements of type T
606 |
607 | public:
608 | // type definitions
609 | typedef T value_type;
610 | typedef T* iterator;
611 | typedef const T* const_iterator;
612 | typedef T& reference;
613 | typedef const T& const_reference;
614 | typedef std::size_t size_type;
615 | typedef std::ptrdiff_t difference_type;
616 |
617 | // iterator support
618 | inline iterator begin() { return elems; }
619 | inline const_iterator begin() const { return elems; }
620 | inline iterator end() { return elems+N; }
621 | inline const_iterator end() const { return elems+N; }
622 |
623 | // reverse iterator support
624 | #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS)
625 | typedef std::reverse_iterator reverse_iterator;
626 | typedef std::reverse_iterator const_reverse_iterator;
627 | #elif defined(_MSC_VER) && (_MSC_VER == 1300) && defined(BOOST_DINKUMWARE_STDLIB) && (BOOST_DINKUMWARE_STDLIB == 310)
628 | // workaround for broken reverse_iterator in VC7
629 | typedef std::reverse_iterator > reverse_iterator;
631 | typedef std::reverse_iterator > const_reverse_iterator;
633 | #else
634 | // workaround for broken reverse_iterator implementations
635 | typedef std::reverse_iterator reverse_iterator;
636 | typedef std::reverse_iterator const_reverse_iterator;
637 | #endif
638 |
639 | reverse_iterator rbegin() { return reverse_iterator(end()); }
640 | const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
641 | reverse_iterator rend() { return reverse_iterator(begin()); }
642 | const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
643 | // operator[]
644 | inline reference operator[](size_type i) { return elems[i]; }
645 | inline const_reference operator[](size_type i) const { return elems[i]; }
646 | // at() with range check
647 | reference at(size_type i) { rangecheck(i); return elems[i]; }
648 | const_reference at(size_type i) const { rangecheck(i); return elems[i]; }
649 | // front() and back()
650 | reference front() { return elems[0]; }
651 | const_reference front() const { return elems[0]; }
652 | reference back() { return elems[N-1]; }
653 | const_reference back() const { return elems[N-1]; }
654 | // size is constant
655 | static inline size_type size() { return N; }
656 | static bool empty() { return false; }
657 | static size_type max_size() { return N; }
658 | enum { static_size = N };
659 | /** This method has no effects in this class, but raises an exception if the expected size does not match */
660 | inline void resize(const size_t nElements) { if (nElements!=N) throw std::logic_error("Try to change the size of a CArray."); }
661 | // swap (note: linear complexity in N, constant for given instantiation)
662 | void swap (CArray& y) { std::swap_ranges(begin(),end(),y.begin()); }
663 | // direct access to data (read-only)
664 | const T* data() const { return elems; }
665 | // use array as C array (direct read/write access to data)
666 | T* data() { return elems; }
667 | // assignment with type conversion
668 | template CArray& operator= (const CArray& rhs) {
669 | std::copy(rhs.begin(),rhs.end(), begin());
670 | return *this;
671 | }
672 | // assign one value to all elements
673 | inline void assign (const T& value) { for (size_t i=0;i= size()) { throw std::out_of_range("CArray<>: index out of range"); } }
679 | }; // end of CArray
680 |
681 | /** Used to declare fixed-size arrays when DIM>0, dynamically-allocated vectors when DIM=-1.
682 | * Fixed size version for a generic DIM:
683 | */
684 | template
685 | struct array_or_vector_selector
686 | {
687 | typedef CArray container_t;
688 | };
689 | /** Dynamic size version */
690 | template
691 | struct array_or_vector_selector<-1,T> {
692 | typedef std::vector container_t;
693 | };
694 | /** @} */
695 |
696 | /** @addtogroup kdtrees_grp KD-tree classes and adaptors
697 | * @{ */
698 |
699 | /** kd-tree index
700 | *
701 | * Contains the k-d trees and other information for indexing a set of points
702 | * for nearest-neighbor matching.
703 | *
704 | * The class "DatasetAdaptor" must provide the following interface (can be non-virtual, inlined methods):
705 | *
706 | * \code
707 | * // Must return the number of data points
708 | * inline size_t kdtree_get_point_count() const { ... }
709 | *
710 | * // Must return the Euclidean (L2) distance between the vector "p1[0:size-1]" and the data point with index "idx_p2" stored in the class:
711 | * inline DistanceType kdtree_distance(const T *p1, const size_t idx_p2,size_t size) const { ... }
712 | *
713 | * // Must return the dim'th component of the idx'th point in the class:
714 | * inline T kdtree_get_pt(const size_t idx, int dim) const { ... }
715 | *
716 | * // Optional bounding-box computation: return false to default to a standard bbox computation loop.
717 | * // Return true if the BBOX was already computed by the class and returned in "bb" so it can be avoided to redo it again.
718 | * // Look at bb.size() to find out the expected dimensionality (e.g. 2 or 3 for point clouds)
719 | * template
720 | * bool kdtree_get_bbox(BBOX &bb) const
721 | * {
722 | * bb[0].low = ...; bb[0].high = ...; // 0th dimension limits
723 | * bb[1].low = ...; bb[1].high = ...; // 1st dimension limits
724 | * ...
725 | * return true;
726 | * }
727 | *
728 | * \endcode
729 | *
730 | * \tparam IndexType Will be typically size_t or int
731 | */
732 | template
733 | class KDTreeSingleIndexAdaptor
734 | {
735 | public:
736 | typedef typename Distance::ElementType ElementType;
737 | typedef typename Distance::DistanceType DistanceType;
738 | protected:
739 |
740 | /**
741 | * Array of indices to vectors in the dataset.
742 | */
743 | std::vector vind;
744 |
745 | size_t m_leaf_max_size;
746 |
747 |
748 | /**
749 | * The dataset used by this index
750 | */
751 | const DatasetAdaptor &dataset; //!< The source of our data
752 |
753 | const KDTreeSingleIndexAdaptorParams index_params;
754 |
755 | size_t m_size;
756 | int dim; //!< Dimensionality of each data point
757 |
758 |
759 | /*--------------------- Internal Data Structures --------------------------*/
760 | struct Node
761 | {
762 | union {
763 | struct
764 | {
765 | /**
766 | * Indices of points in leaf node
767 | */
768 | IndexType left, right;
769 | } lr;
770 | struct
771 | {
772 | /**
773 | * Dimension used for subdivision.
774 | */
775 | int divfeat;
776 | /**
777 | * The values used for subdivision.
778 | */
779 | DistanceType divlow, divhigh;
780 | } sub;
781 | };
782 | /**
783 | * The child nodes.
784 | */
785 | Node* child1, * child2;
786 | };
787 | typedef Node* NodePtr;
788 |
789 |
790 | struct Interval
791 | {
792 | ElementType low, high;
793 | };
794 |
795 | /** Define "BoundingBox" as a fixed-size or variable-size container depending on "DIM" */
796 | typedef typename array_or_vector_selector::container_t BoundingBox;
797 |
798 | /** Define "distance_vector_t" as a fixed-size or variable-size container depending on "DIM" */
799 | typedef typename array_or_vector_selector::container_t distance_vector_t;
800 |
801 | /** This record represents a branch point when finding neighbors in
802 | the tree. It contains a record of the minimum distance to the query
803 | point, as well as the node at which the search resumes.
804 | */
805 | template
806 | struct BranchStruct
807 | {
808 | T node; /* Tree node at which search resumes */
809 | DistanceType mindist; /* Minimum distance to query for all nodes below. */
810 |
811 | BranchStruct() {}
812 | BranchStruct(const T& aNode, DistanceType dist) : node(aNode), mindist(dist) {}
813 |
814 | inline bool operator<(const BranchStruct& rhs) const
815 | {
816 | return mindist BranchSt;
825 | typedef BranchSt* Branch;
826 |
827 | BoundingBox root_bbox;
828 |
829 | /**
830 | * Pooled memory allocator.
831 | *
832 | * Using a pooled memory allocator is more efficient
833 | * than allocating memory directly when there is a large
834 | * number small of memory allocations.
835 | */
836 | PooledAllocator pool;
837 |
838 | public:
839 |
840 | Distance distance;
841 |
842 | /**
843 | * KDTree constructor
844 | *
845 | * Params:
846 | * inputData = dataset with the input features
847 | * params = parameters passed to the kdtree algorithm (see http://code.google.com/p/nanoflann/ for help choosing the parameters)
848 | */
849 | KDTreeSingleIndexAdaptor(const int dimensionality, const DatasetAdaptor& inputData, const KDTreeSingleIndexAdaptorParams& params = KDTreeSingleIndexAdaptorParams() ) :
850 | dataset(inputData), index_params(params), root_node(NULL), distance(inputData)
851 | {
852 | m_size = dataset.kdtree_get_point_count();
853 | dim = dimensionality;
854 | if (DIM>0) dim=DIM;
855 | else {
856 | if (params.dim>0) dim = params.dim;
857 | }
858 | m_leaf_max_size = params.leaf_max_size;
859 |
860 | // Create a permutable array of indices to the input vectors.
861 | //init_vind();
862 | }
863 |
864 | /**
865 | * Standard destructor
866 | */
867 | ~KDTreeSingleIndexAdaptor()
868 | {
869 | }
870 |
871 | /** Frees the previously-built index. Automatically called within buildIndex(). */
872 | void freeIndex()
873 | {
874 | pool.free_all();
875 | root_node=NULL;
876 | }
877 |
878 | /**
879 | * Builds the index
880 | */
881 | void buildIndex()
882 | {
883 | init_vind();
884 | computeBoundingBox(root_bbox);
885 | freeIndex();
886 | root_node = divideTree(0, m_size, root_bbox ); // construct the tree
887 | }
888 |
889 | /**
890 | * Returns size of index.
891 | */
892 | size_t size() const
893 | {
894 | return m_size;
895 | }
896 |
897 | /**
898 | * Returns the length of an index feature.
899 | */
900 | size_t veclen() const
901 | {
902 | return static_cast(DIM>0 ? DIM : dim);
903 | }
904 |
905 | /**
906 | * Computes the inde memory usage
907 | * Returns: memory used by the index
908 | */
909 | size_t usedMemory() const
910 | {
911 | return pool.usedMemory+pool.wastedMemory+dataset.kdtree_get_point_count()*sizeof(IndexType); // pool memory and vind array memory
912 | }
913 |
914 | /** \name Query methods
915 | * @{ */
916 |
917 | /**
918 | * Find set of nearest neighbors to vec[0:dim-1]. Their indices are stored inside
919 | * the result object.
920 | *
921 | * Params:
922 | * result = the result object in which the indices of the nearest-neighbors are stored
923 | * vec = the vector for which to search the nearest neighbors
924 | *
925 | * \tparam RESULTSET Should be any ResultSet
926 | * \sa knnSearch, radiusSearch
927 | */
928 | template
929 | void findNeighbors(RESULTSET& result, const ElementType* vec, const SearchParams& searchParams) const
930 | {
931 | assert(vec);
932 | if (!root_node) throw std::runtime_error("[nanoflann] findNeighbors() called before building the index.");
933 | float epsError = 1+searchParams.eps;
934 |
935 | distance_vector_t dists; // fixed or variable-sized container (depending on DIM)
936 | dists.assign((DIM>0 ? DIM : dim) ,0); // Fill it with zeros.
937 | DistanceType distsq = computeInitialDistances(vec, dists);
938 | searchLevel(result, vec, root_node, distsq, dists, epsError); // "count_leaf" parameter removed since was neither used nor returned to the user.
939 | }
940 |
941 | /**
942 | * Find the "num_closest" nearest neighbors to the \a query_point[0:dim-1]. Their indices are stored inside
943 | * the result object.
944 | * \sa radiusSearch, findNeighbors
945 | * \note nChecks_IGNORED is ignored but kept for compatibility with the original FLANN interface.
946 | */
947 | inline void knnSearch(const ElementType *query_point, const size_t num_closest, IndexType *out_indices, DistanceType *out_distances_sq, const int nChecks_IGNORED = 10) const
948 | {
949 | nanoflann::KNNResultSet resultSet(num_closest);
950 | resultSet.init(out_indices, out_distances_sq);
951 | this->findNeighbors(resultSet, query_point, nanoflann::SearchParams());
952 | }
953 |
954 | /**
955 | * Find all the neighbors to \a query_point[0:dim-1] within a maximum radius.
956 | * The output is given as a vector of pairs, of which the first element is a point index and the second the corresponding distance.
957 | * Previous contents of \a IndicesDists are cleared.
958 | *
959 | * If searchParams.sorted==true, the output list is sorted by ascending distances.
960 | *
961 | * For a better performance, it is advisable to do a .reserve() on the vector if you have any wild guess about the number of expected matches.
962 | *
963 | * \sa knnSearch, findNeighbors
964 | * \return The number of points within the given radius (i.e. indices.size() or dists.size() )
965 | */
966 | size_t radiusSearch(const ElementType *query_point,const DistanceType radius, std::vector >& IndicesDists, const SearchParams& searchParams) const
967 | {
968 | RadiusResultSet resultSet(radius,IndicesDists);
969 | this->findNeighbors(resultSet, query_point, searchParams);
970 |
971 | if (searchParams.sorted)
972 | std::sort(IndicesDists.begin(),IndicesDists.end(), IndexDist_Sorter() );
973 |
974 | return resultSet.size();
975 | }
976 |
977 | /** @} */
978 |
979 | private:
980 | /** Make sure the auxiliary list \a vind has the same size than the current dataset, and re-generate if size has changed. */
981 | void init_vind()
982 | {
983 | // Create a permutable array of indices to the input vectors.
984 | m_size = dataset.kdtree_get_point_count();
985 | if (vind.size()!=m_size) vind.resize(m_size);
986 | for (size_t i = 0; i < m_size; i++) vind[i] = i;
987 | }
988 |
989 | /// Helper accessor to the dataset points:
990 | inline ElementType dataset_get(size_t idx, int component) const {
991 | return dataset.kdtree_get_pt(idx,component);
992 | }
993 |
994 |
995 | void save_tree(FILE* stream, NodePtr tree)
996 | {
997 | save_value(stream, *tree);
998 | if (tree->child1!=NULL) {
999 | save_tree(stream, tree->child1);
1000 | }
1001 | if (tree->child2!=NULL) {
1002 | save_tree(stream, tree->child2);
1003 | }
1004 | }
1005 |
1006 |
1007 | void load_tree(FILE* stream, NodePtr& tree)
1008 | {
1009 | tree = pool.allocate();
1010 | load_value(stream, *tree);
1011 | if (tree->child1!=NULL) {
1012 | load_tree(stream, tree->child1);
1013 | }
1014 | if (tree->child2!=NULL) {
1015 | load_tree(stream, tree->child2);
1016 | }
1017 | }
1018 |
1019 |
1020 | void computeBoundingBox(BoundingBox& bbox)
1021 | {
1022 | bbox.resize((DIM>0 ? DIM : dim));
1023 | if (dataset.kdtree_get_bbox(bbox))
1024 | {
1025 | // Done! It was implemented in derived class
1026 | }
1027 | else
1028 | {
1029 | for (int i=0; i<(DIM>0 ? DIM : dim); ++i) {
1030 | bbox[i].low =
1031 | bbox[i].high = dataset_get(0,i);
1032 | }
1033 | const size_t N = dataset.kdtree_get_point_count();
1034 | for (size_t k=1; k0 ? DIM : dim); ++i) {
1036 | if (dataset_get(k,i)bbox[i].high) bbox[i].high = dataset_get(k,i);
1038 | }
1039 | }
1040 | }
1041 | }
1042 |
1043 |
1044 | /**
1045 | * Create a tree node that subdivides the list of vecs from vind[first]
1046 | * to vind[last]. The routine is called recursively on each sublist.
1047 | * Place a pointer to this new tree node in the location pTree.
1048 | *
1049 | * Params: pTree = the new node to create
1050 | * first = index of the first vector
1051 | * last = index of the last vector
1052 | */
1053 | NodePtr divideTree(const IndexType left, const IndexType right, BoundingBox& bbox)
1054 | {
1055 | NodePtr node = pool.allocate(); // allocate memory
1056 |
1057 | /* If too few exemplars remain, then make this a leaf node. */
1058 | if ( (right-left) <= m_leaf_max_size) {
1059 | node->child1 = node->child2 = NULL; /* Mark as leaf node. */
1060 | node->lr.left = left;
1061 | node->lr.right = right;
1062 |
1063 | // compute bounding-box of leaf points
1064 | for (int i=0; i<(DIM>0 ? DIM : dim); ++i) {
1065 | bbox[i].low = dataset_get(vind[left],i);
1066 | bbox[i].high = dataset_get(vind[left],i);
1067 | }
1068 | for (IndexType k=left+1; k0 ? DIM : dim); ++i) {
1070 | if (bbox[i].low>dataset_get(vind[k],i)) bbox[i].low=dataset_get(vind[k],i);
1071 | if (bbox[i].highsub.divfeat = cutfeat;
1082 |
1083 | BoundingBox left_bbox(bbox);
1084 | left_bbox[cutfeat].high = cutval;
1085 | node->child1 = divideTree(left, left+idx, left_bbox);
1086 |
1087 | BoundingBox right_bbox(bbox);
1088 | right_bbox[cutfeat].low = cutval;
1089 | node->child2 = divideTree(left+idx, right, right_bbox);
1090 |
1091 | node->sub.divlow = left_bbox[cutfeat].high;
1092 | node->sub.divhigh = right_bbox[cutfeat].low;
1093 |
1094 | for (int i=0; i<(DIM>0 ? DIM : dim); ++i) {
1095 | bbox[i].low = std::min(left_bbox[i].low, right_bbox[i].low);
1096 | bbox[i].high = std::max(left_bbox[i].high, right_bbox[i].high);
1097 | }
1098 | }
1099 |
1100 | return node;
1101 | }
1102 |
1103 | void computeMinMax(IndexType* ind, IndexType count, int element, ElementType& min_elem, ElementType& max_elem)
1104 | {
1105 | min_elem = dataset_get(ind[0],element);
1106 | max_elem = dataset_get(ind[0],element);
1107 | for (IndexType i=1; imax_elem) max_elem = val;
1111 | }
1112 | }
1113 |
1114 | void middleSplit(IndexType* ind, IndexType count, IndexType& index, int& cutfeat, DistanceType& cutval, const BoundingBox& bbox)
1115 | {
1116 | // find the largest span from the approximate bounding box
1117 | ElementType max_span = bbox[0].high-bbox[0].low;
1118 | cutfeat = 0;
1119 | cutval = (bbox[0].high+bbox[0].low)/2;
1120 | for (int i=1; i<(DIM>0 ? DIM : dim); ++i) {
1121 | ElementType span = bbox[i].low-bbox[i].low;
1122 | if (span>max_span) {
1123 | max_span = span;
1124 | cutfeat = i;
1125 | cutval = (bbox[i].high+bbox[i].low)/2;
1126 | }
1127 | }
1128 |
1129 | // compute exact span on the found dimension
1130 | ElementType min_elem, max_elem;
1131 | computeMinMax(ind, count, cutfeat, min_elem, max_elem);
1132 | cutval = (min_elem+max_elem)/2;
1133 | max_span = max_elem - min_elem;
1134 |
1135 | // check if a dimension of a largest span exists
1136 | size_t k = cutfeat;
1137 | for (size_t i=0; i<(DIM>0 ? DIM : dim); ++i) {
1138 | if (i==k) continue;
1139 | ElementType span = bbox[i].high-bbox[i].low;
1140 | if (span>max_span) {
1141 | computeMinMax(ind, count, i, min_elem, max_elem);
1142 | span = max_elem - min_elem;
1143 | if (span>max_span) {
1144 | max_span = span;
1145 | cutfeat = i;
1146 | cutval = (min_elem+max_elem)/2;
1147 | }
1148 | }
1149 | }
1150 | IndexType lim1, lim2;
1151 | planeSplit(ind, count, cutfeat, cutval, lim1, lim2);
1152 |
1153 | if (lim1>count/2) index = lim1;
1154 | else if (lim2(0.00001);
1162 | ElementType max_span = bbox[0].high-bbox[0].low;
1163 | for (int i=1; i<(DIM>0 ? DIM : dim); ++i) {
1164 | ElementType span = bbox[i].high-bbox[i].low;
1165 | if (span>max_span) {
1166 | max_span = span;
1167 | }
1168 | }
1169 | ElementType max_spread = -1;
1170 | cutfeat = 0;
1171 | for (int i=0; i<(DIM>0 ? DIM : dim); ++i) {
1172 | ElementType span = bbox[i].high-bbox[i].low;
1173 | if (span>(1-EPS)*max_span) {
1174 | ElementType min_elem, max_elem;
1175 | computeMinMax(ind, count, cutfeat, min_elem, max_elem);
1176 | ElementType spread = max_elem-min_elem;;
1177 | if (spread>max_spread) {
1178 | cutfeat = i;
1179 | max_spread = spread;
1180 | }
1181 | }
1182 | }
1183 | // split in the middle
1184 | DistanceType split_val = (bbox[cutfeat].low+bbox[cutfeat].high)/2;
1185 | ElementType min_elem, max_elem;
1186 | computeMinMax(ind, count, cutfeat, min_elem, max_elem);
1187 |
1188 | if (split_valmax_elem) cutval = max_elem;
1190 | else cutval = split_val;
1191 |
1192 | IndexType lim1, lim2;
1193 | planeSplit(ind, count, cutfeat, cutval, lim1, lim2);
1194 |
1195 | if (lim1>count/2) index = lim1;
1196 | else if (lim2cutval
1209 | */
1210 | void planeSplit(IndexType* ind, const IndexType count, int cutfeat, DistanceType cutval, IndexType& lim1, IndexType& lim2)
1211 | {
1212 | /* Move vector indices for left subtree to front of list. */
1213 | IndexType left = 0;
1214 | IndexType right = count-1;
1215 | for (;; ) {
1216 | while (left<=right && dataset_get(ind[left],cutfeat)=cutval) --right;
1218 | if (left>right || !right) break; // "!right" was added to support unsigned Index types
1219 | std::swap(ind[left], ind[right]);
1220 | ++left;
1221 | --right;
1222 | }
1223 | /* If either list is empty, it means that all remaining features
1224 | * are identical. Split in the middle to maintain a balanced tree.
1225 | */
1226 | lim1 = left;
1227 | right = count-1;
1228 | for (;; ) {
1229 | while (left<=right && dataset_get(ind[left],cutfeat)<=cutval) ++left;
1230 | while (right && left<=right && dataset_get(ind[right],cutfeat)>cutval) --right;
1231 | if (left>right || !right) break; // "!right" was added to support unsigned Index types
1232 | std::swap(ind[left], ind[right]);
1233 | ++left;
1234 | --right;
1235 | }
1236 | lim2 = left;
1237 | }
1238 |
1239 | DistanceType computeInitialDistances(const ElementType* vec, distance_vector_t& dists) const
1240 | {
1241 | assert(vec);
1242 | DistanceType distsq = 0.0;
1243 |
1244 | for (int i = 0; i < (DIM>0 ? DIM : dim); ++i) {
1245 | if (vec[i] < root_bbox[i].low) {
1246 | dists[i] = distance.accum_dist(vec[i], root_bbox[i].low, i);
1247 | distsq += dists[i];
1248 | }
1249 | if (vec[i] > root_bbox[i].high) {
1250 | dists[i] = distance.accum_dist(vec[i], root_bbox[i].high, i);
1251 | distsq += dists[i];
1252 | }
1253 | }
1254 |
1255 | return distsq;
1256 | }
1257 |
1258 | /**
1259 | * Performs an exact search in the tree starting from a node.
1260 | * \tparam RESULTSET Should be any ResultSet
1261 | */
1262 | template
1263 | void searchLevel(RESULTSET& result_set, const ElementType* vec, const NodePtr node, DistanceType mindistsq,
1264 | distance_vector_t& dists, const float epsError) const
1265 | {
1266 | /* If this is a leaf node, then do check and return. */
1267 | if ((node->child1 == NULL)&&(node->child2 == NULL)) {
1268 | //count_leaf += (node->lr.right-node->lr.left); // Removed since was neither used nor returned to the user.
1269 | DistanceType worst_dist = result_set.worstDist();
1270 | for (IndexType i=node->lr.left; ilr.right; ++i) {
1271 | const IndexType index = vind[i];// reorder... : i;
1272 | DistanceType dist = distance(vec, index, (DIM>0 ? DIM : dim));
1273 | if (distsub.divfeat;
1282 | ElementType val = vec[idx];
1283 | DistanceType diff1 = val - node->sub.divlow;
1284 | DistanceType diff2 = val - node->sub.divhigh;
1285 |
1286 | NodePtr bestChild;
1287 | NodePtr otherChild;
1288 | DistanceType cut_dist;
1289 | if ((diff1+diff2)<0) {
1290 | bestChild = node->child1;
1291 | otherChild = node->child2;
1292 | cut_dist = distance.accum_dist(val, node->sub.divhigh, idx);
1293 | }
1294 | else {
1295 | bestChild = node->child2;
1296 | otherChild = node->child1;
1297 | cut_dist = distance.accum_dist( val, node->sub.divlow, idx);
1298 | }
1299 |
1300 | /* Call recursively to search next level down. */
1301 | searchLevel(result_set, vec, bestChild, mindistsq, dists, epsError);
1302 |
1303 | DistanceType dst = dists[idx];
1304 | mindistsq = mindistsq + cut_dist - dst;
1305 | dists[idx] = cut_dist;
1306 | if (mindistsq*epsError<=result_set.worstDist()) {
1307 | searchLevel(result_set, vec, otherChild, mindistsq, dists, epsError);
1308 | }
1309 | dists[idx] = dst;
1310 | }
1311 |
1312 | public:
1313 | /** Stores the index in a binary file.
1314 | * IMPORTANT NOTE: The set of data points is NOT stored in the file, so when loading the index object it must be constructed associated to the same source of data points used while building it.
1315 | * See the example: examples/saveload_example.cpp
1316 | * \sa loadIndex */
1317 | void saveIndex(FILE* stream)
1318 | {
1319 | save_value(stream, m_size);
1320 | save_value(stream, dim);
1321 | save_value(stream, root_bbox);
1322 | save_value(stream, m_leaf_max_size);
1323 | save_value(stream, vind);
1324 | save_tree(stream, root_node);
1325 | }
1326 |
1327 | /** Loads a previous index from a binary file.
1328 | * IMPORTANT NOTE: The set of data points is NOT stored in the file, so the index object must be constructed associated to the same source of data points used while building the index.
1329 | * See the example: examples/saveload_example.cpp
1330 | * \sa loadIndex */
1331 | void loadIndex(FILE* stream)
1332 | {
1333 | load_value(stream, m_size);
1334 | load_value(stream, dim);
1335 | load_value(stream, root_bbox);
1336 | load_value(stream, m_leaf_max_size);
1337 | load_value(stream, vind);
1338 | load_tree(stream, root_node);
1339 | }
1340 |
1341 | }; // class KDTree
1342 |
1343 |
1344 | /** A simple KD-tree adaptor for working with data directly stored in an Eigen Matrix, without duplicating the data storage.
1345 | * Each row in the matrix represents a point in the state space.
1346 | *
1347 | * Example of usage:
1348 | * \code
1349 | * Eigen::Matrix mat;
1350 | * // Fill out "mat"...
1351 | *
1352 | * typedef KDTreeEigenMatrixAdaptor< Eigen::Matrix > my_kd_tree_t;
1353 | * const int max_leaf = 10;
1354 | * my_kd_tree_t mat_index(dimdim, mat, max_leaf );
1355 | * mat_index.index->buildIndex();
1356 | * mat_index.index->...
1357 | * \endcode
1358 | *
1359 | * \tparam DIM If set to >0, it specifies a compile-time fixed dimensionality for the points in the data set, allowing more compiler optimizations.
1360 | * \tparam Distance The distance metric to use: nanoflann::metric_L1, nanoflann::metric_L2, nanoflann::metric_L2_Simple, etc.
1361 | * \tparam IndexType The type for indices in the KD-tree index (typically, size_t of int)
1362 | */
1363 | template
1364 | struct KDTreeEigenMatrixAdaptor
1365 | {
1366 | typedef KDTreeEigenMatrixAdaptor self_t;
1367 | typedef typename MatrixType::Scalar num_t;
1368 | typedef typename Distance::template traits::distance_t metric_t;
1369 | typedef KDTreeSingleIndexAdaptor< metric_t,self_t,DIM,IndexType> index_t;
1370 |
1371 | index_t* index; //! The kd-tree index for the user to call its methods as usual with any other FLANN index.
1372 |
1373 | /// Constructor: takes a const ref to the matrix object with the data points
1374 | KDTreeEigenMatrixAdaptor(const int dimensionality, const MatrixType &mat, const int leaf_max_size = 10) : m_data_matrix(mat)
1375 | {
1376 | const size_t dims = mat.cols();
1377 | if (DIM>0 && static_cast(dims)!=DIM)
1378 | throw std::runtime_error("Data set dimensionality does not match the 'DIM' template argument");
1379 | index = new index_t( dims, *this /* adaptor */, nanoflann::KDTreeSingleIndexAdaptorParams(leaf_max_size, dims ) );
1380 | index->buildIndex();
1381 | }
1382 |
1383 | ~KDTreeEigenMatrixAdaptor() {
1384 | delete index;
1385 | }
1386 |
1387 | const MatrixType &m_data_matrix;
1388 |
1389 | /** Query for the \a num_closest closest points to a given point (entered as query_point[0:dim-1]).
1390 | * Note that this is a short-cut method for index->findNeighbors().
1391 | * The user can also call index->... methods as desired.
1392 | * \note nChecks_IGNORED is ignored but kept for compatibility with the original FLANN interface.
1393 | */
1394 | inline void query(const num_t *query_point, const size_t num_closest, IndexType *out_indices, num_t *out_distances_sq, const int nChecks_IGNORED = 10) const
1395 | {
1396 | nanoflann::KNNResultSet resultSet(num_closest);
1397 | resultSet.init(out_indices, out_distances_sq);
1398 | index->findNeighbors(resultSet, query_point, nanoflann::SearchParams());
1399 | }
1400 |
1401 | /** @name Interface expected by KDTreeSingleIndexAdaptor
1402 | * @{ */
1403 |
1404 | const self_t & derived() const {
1405 | return *this;
1406 | }
1407 | self_t & derived() {
1408 | return *this;
1409 | }
1410 |
1411 | // Must return the number of data points
1412 | inline size_t kdtree_get_point_count() const {
1413 | return m_data_matrix.rows();
1414 | }
1415 |
1416 | // Returns the distance between the vector "p1[0:size-1]" and the data point with index "idx_p2" stored in the class:
1417 | inline num_t kdtree_distance(const num_t *p1, const size_t idx_p2,size_t size) const
1418 | {
1419 | num_t s=0;
1420 | for (size_t i=0; i
1436 | bool kdtree_get_bbox(BBOX &bb) const {
1437 | return false;
1438 | }
1439 |
1440 | /** @} */
1441 |
1442 | }; // end of KDTreeEigenMatrixAdaptor
1443 | /** @} */
1444 |
1445 | /** @} */ // end of grouping
1446 | } // end of NS
1447 |
1448 |
1449 | #endif /* NANOFLANN_HPP_ */
1450 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # ofxNearestNeighbour
2 |
3 | A templated k-d tree nearest neighbour search addon for openFrameworks based on nanoflann.
4 |
5 | ## Features
6 |
7 | Search for n nearest neighbours or neighbours within a certain radius in 2D or 3D.
8 |
9 | ## Usage
10 |
11 | See examples.
12 |
--------------------------------------------------------------------------------
/src/NearestNeighbour.h:
--------------------------------------------------------------------------------
1 | /*
2 | * NearestNeighbour.h
3 | *
4 | * Copyright (c) 2013, Neil Mendoza, http://www.neilmendoza.com
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * * Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | * * Neither the name of Neil Mendoza nor the names of its contributors may be used
16 | * to endorse or promote products derived from this software without
17 | * specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 | * POSSIBILITY OF SUCH DAMAGE.
30 | *
31 | */
32 | #pragma once
33 |
34 | #include "nanoflann.hpp"
35 | #include "PointCloud.h"
36 |
37 | namespace nm
38 | {
39 | using namespace nanoflann;
40 |
41 | // T is type of nn point
42 | template
43 | class NearestNeighbour
44 | {
45 | public:
46 | typedef KDTreeSingleIndexAdaptor<
47 | L2_Simple_Adaptor>,
48 | PointCloud,
49 | U> KdTree;
50 |
51 | NearestNeighbour() : kdTree(U, cloud, KDTreeSingleIndexAdaptorParams(10 /* max leaf */))
52 | {
53 | }
54 |
55 | void buildIndex(const vector& points)
56 | {
57 | cloud.points = points;
58 | if (points.empty()) ofLogError() << "Cannot build index with no points.";
59 | else kdTree.buildIndex();
60 | }
61 |
62 | void findNClosestPoints(const T& point, unsigned n, vector& indices, vector& distsSquared)
63 | {
64 | indices.resize(n);
65 | distsSquared.resize(n);
66 | kdTree.knnSearch(glm::value_ptr(point), n, &indices[0], &distsSquared[0]);
67 | }
68 |
69 | unsigned findPointsWithinRadius(const T& point, float radius, vector >& matches)
70 | {
71 | nanoflann::SearchParams params;
72 | return kdTree.radiusSearch(glm::value_ptr(point), radius * radius, matches, params);
73 | }
74 |
75 | private:
76 | KdTree kdTree;
77 | PointCloud cloud;
78 | };
79 | }
80 |
--------------------------------------------------------------------------------
/src/PointCloud.h:
--------------------------------------------------------------------------------
1 | /*
2 | * PointCloud.h
3 | *
4 | * Copyright (c) 2013, Neil Mendoza, http://www.neilmendoza.com
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * * Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | * * Neither the name of Neil Mendoza nor the names of its contributors may be used
16 | * to endorse or promote products derived from this software without
17 | * specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 | * POSSIBILITY OF SUCH DAMAGE.
30 | *
31 | */
32 | #pragma once
33 |
34 | namespace nm
35 | {
36 | template
37 | struct PointCloud
38 | {
39 | std::vector points;
40 |
41 | // Must return the number of data points
42 | inline size_t kdtree_get_point_count() const { return points.size(); }
43 |
44 | // Returns the distance between the vector "p1[0:size-1]" and the data point with index "idx_p2" stored in the class:
45 | inline float kdtree_distance(const float* p1, const size_t idx_p2, size_t size) const
46 | {
47 | float total = 0;
48 | for (unsigned i = 0; i < T::length(); ++i)
49 | {
50 | const float d = p1[i] - points[idx_p2][i];
51 | total += d * d;
52 | }
53 | return total;
54 | }
55 |
56 | // Returns the dim'th component of the idx'th point in the class:
57 | // Since this is inlined and the "dim" argument is typically an immediate value, the
58 | // "if/else's" are actually solved at compile time.
59 | inline float kdtree_get_pt(const size_t idx, int dim) const
60 | {
61 | return points[idx][dim];
62 | }
63 |
64 | // Optional bounding-box computation: return false to default to a standard bbox computation loop.
65 | // Return true if the BBOX was already computed by the class and returned in "bb" so it can be avoided to redo it again.
66 | // Look at bb.size() to find out the expected dimensionality (e.g. 2 or 3 for point clouds)
67 | template
68 | bool kdtree_get_bbox(BBOX &bb) const { return false; }
69 |
70 | };
71 | }
72 |
--------------------------------------------------------------------------------
/src/ofxNearestNeighbour.h:
--------------------------------------------------------------------------------
1 | /*
2 | * ofxNearestNeighbour.h
3 | *
4 | * Copyright (c) 2013, Neil Mendoza, http://www.neilmendoza.com
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * * Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | * * Neither the name of Neil Mendoza nor the names of its contributors may be used
16 | * to endorse or promote products derived from this software without
17 | * specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 | * POSSIBILITY OF SUCH DAMAGE.
30 | *
31 | */
32 | #pragma once
33 |
34 | #include "NearestNeighbour.h"
35 |
36 | typedef nm::NearestNeighbour ofxNearestNeighbour3D;
37 | typedef nm::NearestNeighbour ofxNearestNeighbour2D;
38 | typedef size_t NNIndex;
39 |
--------------------------------------------------------------------------------