Compare commits

...

1049 Commits

Author SHA1 Message Date
David Williams
c986c9f0b1 Added note that development of PolyVox has now stopped. 2016-11-24 22:47:40 +00:00
David Williams
9a71004b1e Added ability to check whether previousVoxel has been set. 2016-05-21 08:34:13 +01:00
David Williams
f4c4bf984c Updated install instructions regarding different Python versions. 2016-02-07 10:29:04 +00:00
David Williams
fe2c29e013 Compile fix. 2016-02-07 10:00:07 +00:00
David Williams
98cce0ea26 Documentation fixes. 2016-02-07 00:19:18 +00:00
David Williams
c57cb96e80 Replaced LargeVolume reference with PagedVolume. 2016-02-07 00:13:05 +00:00
David Williams
817c799fcf Updated tutorial 1 with latest code from BasicExample. 2016-02-07 00:06:29 +00:00
David Williams
09c3c2e12f Minor changes to error handling documentation. 2016-02-06 09:38:46 +00:00
David Williams
dcbc3bd995 Minor changes to threading documentation. 2016-02-06 09:25:52 +00:00
David Williams
92c900b774 Minor updates to level-of-detail documentation. 2016-02-06 09:15:35 +00:00
David Williams
4f8ae5acea Minor tweaks to texture mapping documentation. 2016-01-31 17:36:09 +00:00
David Williams
615c1dc00a Tweaks to lighting documentation. 2016-01-31 10:32:27 +00:00
David Williams
3caa86a462 Minor update to 'Principles of PolyVox' 2016-01-31 10:23:46 +00:00
David Williams
b5e8b63810 Minor documentation tweaks. 2016-01-31 09:18:20 +00:00
David Williams
5103563365 Updating documentation. 2016-01-30 23:23:42 +00:00
David Williams
e0b00fc5ac Updated prerequisites section of PolyVox docs. 2016-01-28 23:00:16 +00:00
David Williams
92981f3599 Minor doc update. 2016-01-28 22:24:55 +00:00
David Williams
21e6b435a1 Linux compile fix. 2016-01-25 23:54:34 +01:00
David Williams
5644f837ca Fixed broken include paths causing compile errors on Linux. 2016-01-24 13:15:51 +00:00
David Williams
8d9fffd4c6 Minimal set of changes to get Python bindings building since the last big refactor made PolyVox header only. 2016-01-21 22:49:20 +00:00
David Williams
156bcef9c0 Added files which were accidently removed from repository. 2016-01-19 23:16:02 +00:00
David Williams
0fe41fe28c Documentation changes. 2016-01-11 22:54:27 +00:00
David Williams
e433a697cb Removed out-of-date PagedVolume documentation and added a little bit in it's place. 2016-01-09 09:47:20 +00:00
David Williams
3d01a8412e Documentation. 2016-01-03 23:12:28 +00:00
David Williams
abfe63a525 Moved some files into 'Impl' folder 2016-01-03 22:50:10 +00:00
David Williams
85b1bbb641 Documentation. 2016-01-03 22:45:55 +00:00
David Williams
eef0bebacf Various documentation enhancements. 2016-01-03 22:31:24 +00:00
David Williams
4d2a27ea8e Removed old Thermite reference! 2016-01-03 22:21:04 +00:00
David Williams
6a12a3dc7f Moved some code to .inl 2016-01-03 22:20:14 +00:00
David Williams
f4ebd4c6a9 Removed unnecessary headers. 2016-01-03 22:14:33 +00:00
David Williams
75a2831ae7 Documentation tweaks. 2016-01-03 18:04:07 +00:00
David Williams
c0b72b6a55 Tidying up comments. 2016-01-03 17:49:59 +00:00
David Williams
1444f187a6 More tidying up, moving private code out of main header. 2016-01-03 09:40:52 +00:00
David Williams
8678d741b3 Rearranging cubic extractor code. 2016-01-02 17:38:23 +00:00
David Williams
64c4c8ce86 Moving around some Marching Cubes code so that only the public stuff is in the header.
Tidying up some documentation.
2016-01-02 13:06:43 +00:00
David Williams
d544de6dd1 Removed deprecated functions. 2015-12-26 23:41:49 +00:00
David Williams
e89a55d154 Applied default Visual Studio formatting to most files. This is a quick fix for the tabs vs spaces issue that messes up the formatting in any editor (esp. Linux) which handles tabs/spaces differently to Visual Studio. Some parts of the formatting look a bit worse but overall it should be better (or at least more consistent).
I didn't apply the changes to a few macro-heavy files as Visual Studio removes all indentation from macros, whereas the indentation can be handy to see nesting.
2015-12-26 23:11:27 +00:00
David Williams
b3ca051878 Changed 'embedded' licenses from zlib to MIT. 2015-12-26 21:45:41 +00:00
David Williams
9a8e816485 Replaced uint32_t with size_t. 2015-12-20 21:59:27 +00:00
David Williams
1e9fdf074a Removed the old LargeVolume and SimpleVolume classes, which are now replaced by PagedVolume. 2015-12-20 21:22:29 +00:00
David Williams
403189f357 Removed PolyVoxForwardDeclarations.h. It was a source of confusion because the forward declarations often got out of sync with the real definitions, resulting in confusing template error messages. Furthermore, it does not appear to have actually hurt compile times so I guess it wasn't that useful (or wasn't being used to it's fullest potential). Overall I think PolyVox is not large enough to really benefit from this. 2015-12-20 21:19:20 +00:00
David Williams
354b6aa9d0 When PolyVox files include other PolyVox files the 'PolyVox' part of the path is not needed. This is only needed when examples, tests, and external applications include PolyVox. 2015-12-20 20:56:37 +00:00
David Williams
4fdecf42eb Removing unused code, tidying up. 2015-12-19 15:29:56 +00:00
David Williams
74dfaa293f Fixed usage of region which was too large for the cubic surface extractor. 2015-12-19 15:26:20 +00:00
David Williams
9e600c0bcb Refactoring CubicSurfaceExtractor to free functions rather than just wrapping a class. 2015-12-17 22:57:41 +00:00
David Williams
43bb832c46 Refactoring CubicSurfaceExtractor to free functions rather than just wrapping a class. 2015-12-08 23:50:41 +00:00
David Williams
9617197893 Refactoring CubicSurfaceExtractor to free functions rather than just wrapping a class. 2015-12-08 23:29:38 +00:00
David Williams
65a973f94e Started refactoring CubicSurfaceExtractor to free functions rather than just wrapping a class. 2015-12-07 23:45:24 +00:00
David Williams
28a3d78354 Removed old deprecated code. 2015-11-30 07:50:32 +00:00
David Williams
ed94fc6f25 Removed old/unused code. 2015-11-30 07:47:59 +00:00
David Williams
7fc9990b79 Fixed warning. 2015-11-29 22:50:09 +00:00
David Williams
20ff44c814 Changed license in readme. 2015-11-29 22:12:01 +00:00
David Williams
280c2fdeaa Changed license from zlib to MIT. 2015-11-29 22:08:30 +00:00
David Williams
6d2dcc7d02 Fixing case of file extension (step 2 of 2) 2015-11-29 22:06:57 +00:00
David Williams
67a9d90c0b Fixing case of file extension (step 1 of 2) 2015-11-29 22:06:23 +00:00
Matt Williams
735b0ab6b1 Fix compile on Linux 2015-06-22 12:06:39 +01:00
David Williams
920c78f4d1 Added sobel gradient back in. 2015-06-16 00:00:32 +02:00
David Williams
f8e1bb8452 Fix for broken normals in marching cubes code. 2015-06-14 13:59:51 +02:00
David Williams
14cac713bd Added comment. 2015-06-01 14:30:38 +02:00
David Williams
ff567aa9f8 Added performance notes. 2015-05-29 23:09:51 +02:00
David Williams
5aa631da8f Merge branch 'feature/extractor-optimizations' into develop 2015-05-29 22:39:57 +02:00
David Williams
8c35399fc6 Comments and renaming variables. 2015-05-29 20:34:03 +02:00
David Williams
a0c32e22b7 Added comment. 2015-05-29 17:41:40 +02:00
David Williams
96e747d0c3 Revert "Split the code which generates vertices and indices for a single cell into a separate function."
This reverts commit 2fa291d16f13adf039dc4fa636bfccde52377989.
2015-05-29 17:28:07 +02:00
David Williams
942bb37981 Revert "Passing sampled voxel."
This reverts commit ebab89b9adac576b0d20fd8cbacf0154e7e74fe4.
2015-05-29 17:28:01 +02:00
David Williams
ebab89b9ad Passing sampled voxel. 2015-05-28 23:42:50 +02:00
David Williams
2fa291d16f Split the code which generates vertices and indices for a single cell into a separate function. 2015-05-28 23:26:50 +02:00
David Williams
f32bb1d1ed Reduced array accesses. 2015-05-28 23:02:14 +02:00
David Williams
92db006250 Fixed compile warnings. 2015-05-28 22:40:25 +02:00
David Williams
01963bd462 Added comment about performance. 2015-05-28 22:37:05 +02:00
David Williams
68bdd9ca99 Tidying up. 2015-05-28 21:51:57 +02:00
David Williams
ac7bec0c45 Eliminated unused variables. 2015-05-28 21:46:50 +02:00
David Williams
6493e88d4c Removed unnecessary condition. 2015-05-27 22:58:46 +02:00
David Williams
edd1af14ca Removed unnecessary setting of sampler position. 2015-05-27 22:57:48 +02:00
David Williams
ccedb0e294 Replaced separate arrays with arrays of vectors. 2015-05-27 22:55:36 +02:00
David Williams
baf5cf2cab Removed unneeded memsets. 2015-05-27 07:25:04 +02:00
David Williams
48a6929a7a Tidying up. 2015-05-26 21:24:38 +02:00
David Williams
04c4e49aa1 Fully eliminated MarchingCubesSurfaceExtractor class. It's now only a standalone function called 'extractMarchingCubesMesh'. 2015-05-25 21:23:27 +02:00
David Williams
37db0bac52 Moved gradient calculation outside of class. 2015-05-25 21:16:29 +02:00
David Williams
e4ef845045 Removed sobel gradient calculation code.
Removed m_controller member.
2015-05-25 21:00:50 +02:00
David Williams
b3ce982ef3 Removed some member variables. 2015-05-25 20:51:42 +02:00
David Williams
d353685ce9 Restructuring code... 2015-05-25 20:42:40 +02:00
David Williams
1d51ee8d0a Revert "Rather ugly split of some code into a separate function, to keep the main loop as small and simple as possible. To be tidied up shortly."
This reverts commit 13be35aac906ee34448c3160372db4dcb031022f.
2015-05-25 20:35:55 +02:00
David Williams
c384fbfea8 Revert "Eliminated member variable."
This reverts commit 96ec47a972fea2cd6efcaddd276728f8062d8f7b.
2015-05-25 20:35:47 +02:00
David Williams
96ec47a972 Eliminated member variable. 2015-05-25 17:45:40 +02:00
David Williams
13be35aac9 Rather ugly split of some code into a separate function, to keep the main loop as small and simple as possible. To be tidied up shortly. 2015-05-25 17:37:30 +02:00
David Williams
e0ce93acb1 Added comments. 2015-05-25 16:45:52 +02:00
David Williams
b353cd1ce8 Removed unneeded conditions. 2015-05-25 16:39:30 +02:00
David Williams
ecc06ba986 Changed the way samplers are used for a minor speed improvement. 2015-05-25 12:05:15 +02:00
David Williams
f4941fb73c Minor tweaks. 2015-05-24 23:58:51 +02:00
David Williams
c8124097e3 Using a bit less memory. 2015-05-24 23:32:52 +02:00
David Williams
efb9844fe2 Merge branch 'develop' into feature/extractor-optimizations 2015-05-24 21:17:19 +02:00
David Williams
a34eda6250 Simple optimization. 2015-05-24 21:17:09 +02:00
David Williams
69349d95cd Tidying up. 2015-05-24 21:01:01 +02:00
David Williams
eb3727de30 Vastly simplified logic... hard to believe I made it so complicated :-) 2015-05-24 20:41:46 +02:00
David Williams
32df8be8da Tweaked conditions and comments. 2015-05-24 07:59:03 +02:00
David Williams
4e9b0e374b Moved code into outer loops. 2015-05-24 00:02:27 +02:00
David Williams
8e9e122c03 Merge branch 'develop' into feature/extractor-optimizations 2015-05-23 21:22:58 +02:00
David Williams
304e3d8f7a Faster tests when moving sampler. 2015-05-23 21:22:29 +02:00
David Williams
cee15a145f Avoid setting the sampler position every iteration. 2015-05-23 17:45:16 +02:00
David Williams
5b84c5a9a5 Removed unneeded call to setPosition(). 2015-05-23 17:23:59 +02:00
David Williams
762c9a5090 Switched 3D array back to two 2D arrays to reduce memory usage. 2015-05-22 16:48:42 +02:00
David Williams
50cf939e8a Reorganizing code. 2015-05-22 16:15:53 +02:00
David Williams
50a8bebfa9 Removed unneeded logic. 2015-05-21 23:31:19 +02:00
David Williams
711c262004 Skip outputting some indices. 2015-05-21 23:17:49 +02:00
David Williams
2a7eb51653 Refactoring multiple loops into one big loop. 2015-05-21 23:12:38 +02:00
David Williams
b19de819e2 Fixed compile error due to logging code changing scope. 2015-05-21 10:29:39 +02:00
David Williams
797689acea Trying to re-apply some previous optimizations to get old speed back. 2015-05-20 23:45:22 +02:00
David Williams
f178dc084b Updated unit tests. It seems we had a bug which was causing an excessive number of vertices to be generated. Not sure exactly what was wrong by the refactoring has fixed this. However, it still needs testing in Cubiquity to verify. 2015-05-19 23:14:31 +02:00
David Williams
9a68582530 Added bounds checks 2015-05-17 11:47:52 +02:00
David Williams
ccb76bc6d7 More work refactoring code. Examples appear to work now but tests still fail. 2015-05-17 09:52:13 +02:00
David Williams
a39b7f6a9f More refactoring. 2015-05-16 20:48:15 +02:00
David Williams
1a1ae75766 More refactoring. 2015-05-16 15:36:39 +02:00
David Williams
0e8c90c6ee More refactoring... 2015-05-16 09:00:04 +02:00
David Williams
227b11a764 Cleared array. 2015-05-15 10:03:29 +02:00
David Williams
b4267b11f5 More refactoring code. 2015-05-15 09:57:32 +02:00
David Williams
71adc7292c Restructuring code. 2015-05-14 22:10:37 +02:00
David Williams
89508f8b2b Restructuring code. 2015-05-14 11:48:28 +02:00
David Williams
f53efa1d64 Restructuring code. 2015-05-14 11:41:16 +02:00
David Williams
e912950317 Restructuring code... 2015-05-14 11:35:04 +02:00
David Williams
49683b4b48 Fixed compile error due to logging code changing scope. 2015-05-14 11:27:19 +02:00
David Williams
54f235e09a Restructuring computeBitmask code. 2015-05-14 11:14:39 +02:00
David Williams
5974a1de9b Restructuring loops... 2015-05-14 10:52:07 +02:00
David Williams
13fc8c5ba9 Removed unneeded variable. 2015-05-14 07:42:04 +02:00
David Williams
c4ce66dec5 Replaced 2D pPreviousBitmask and pCurrentBitmask with 3D pBitmask. 2015-05-14 07:15:36 +02:00
David Williams
2b22213bec Replaced 2D arrays with single 3D array when tracking existing vertices. 2015-05-13 23:05:58 +02:00
David Williams
5ce0d9c3e0 Cutting down and simplifying Marching Cubes code (also now slower...). 2015-05-10 19:43:09 +02:00
David Williams
3937dc3c61 Applying test to a larger region so we can more easily benchmark the performance (otherwise the VS profiler can fail if the test runs too quickly). 2015-05-10 11:40:58 +02:00
David Williams
16fca2529b Moved Config.h out of the 'Impl' folder. It should probably be considered part of the public API as users may want to adjust it for their purposes. 2015-05-09 08:58:14 +02:00
David Williams
65b0d1c3c5 Moved parts of the logging code into the public API (so users can redirect logs). 2015-05-09 08:52:30 +02:00
David Williams
040dc37057 Changed header guards. 2015-05-08 21:19:39 +02:00
David Williams
c2bb64d055 Renamed Logging.h to LoggingImpl.h
Added missing files to CMakeLists.txt
2015-05-08 21:18:10 +02:00
David Williams
09253a7bcc Removed a few uses of '#ifdef SWIG', mainly from areas where they would no longer work. e.g where the code has been templatized since the #ifdef was added so we can see that the SWIG version of the code is out of date and won't build anyway. 2015-05-08 21:08:43 +02:00
David Williams
3c31643e4f Exceptions are now part of the PolyVox public API (client code may need to catch them) but the utility macros we use to throw them are still private implementation details. 2015-05-08 16:15:11 +02:00
David Williams
4887fc2701 For work splitting error handling code into separate files for asserts vs. exceptions. 2015-05-08 15:59:17 +02:00
David Williams
a61d4556c1 Moved assertion code to separate file. 2015-05-08 15:31:17 +02:00
David Williams
e9bde59fbc Moved more code into PlatformDefinitions.h 2015-05-08 15:20:29 +02:00
David Williams
64fa004102 Comments and tidying of PlatformDefinitions.h 2015-05-08 15:16:26 +02:00
David Williams
ed64106237 More removing of API import/export macros. 2015-05-08 15:09:44 +02:00
David Williams
d8a422955d Now that PolyVox is header only we have no further use for the POLYVOX_API/LOCAL/SHARED macros which wrap API import/export. 2015-05-08 15:04:17 +02:00
David Williams
b36548ff20 Missed a couple of files during header renaming process. 2015-05-08 15:02:48 +02:00
David Williams
2a8e0a5f7b Renamed 'Typedef.h' to 'PlatformDefinitions.h'. 2015-05-08 14:57:12 +02:00
David Williams
64c30044b0 Moving some macros. 2015-05-08 14:50:10 +02:00
David Williams
f16a247934 Changed implementation of logging macros.
We have observed some strange performance-related behavior as described here: https://stackoverflow.com/questions/29652787/adding-stringstream-cout-hurts-performance-even-when-the-code-is-never-called

This set of changes addresses this problem. The old macros would simply expand the logging code in place, whereas we now have logging functions and the macros call these. Overall I believe it is tidier.
2015-05-07 22:58:00 +02:00
David Williams
4dadbbffd1 Added comment about performance for the future. 2015-04-26 09:25:57 +02:00
David Williams
1d925a59a1 Fixed crash. 2015-04-16 16:47:12 +02:00
David Williams
9947425169 Fix for code which determines which old chunk to delete. 2015-04-15 16:58:24 +02:00
David Williams
cd752b4459 Merge branch 'feature/custom-chunk-hash-table' into develop 2015-04-14 23:43:41 +02:00
David Williams
6ff7b46e26 Merge branch 'develop' into feature/custom-chunk-hash-table 2015-04-14 23:30:29 +02:00
Matt Williams
32c30471a6 Make m_uChunkSideLengthMinusOne const 2015-04-14 15:01:10 +01:00
David Williams
12fdeb8e52 Removed old chunk map.
Removed flush(Region) function as it's a bit trickier to implement with the new hash table, and it's not clear that we need it.
2015-04-13 23:51:18 +02:00
David Williams
1e0e8a8c16 Fixed calculation of volume size in bytes. 2015-04-13 23:48:33 +02:00
David Williams
f7c1962773 Removed commented-out code. 2015-04-13 23:32:23 +02:00
David Williams
143c9fd08d Made test 10x longer. 2015-04-13 21:34:59 +02:00
David Williams
37c35a08db Added code to ensure the number of chunks doesn't go over our target limit. 2015-04-13 21:30:59 +02:00
David Williams
8757f1e53e Removed unneeded assert. 2015-04-13 21:17:19 +02:00
David Williams
5dd46c4bcf Merge branch 'develop' into feature/custom-chunk-hash-table 2015-04-13 21:07:48 +02:00
David Williams
64be18cd14 Tidied up loop for inserting chunk into array. 2015-04-12 20:55:49 +02:00
David Williams
af70096fcc Tidying and adding comments. 2015-04-12 16:46:43 +02:00
David Williams
99390580dd Replaced number with constant. 2015-04-12 10:35:12 +02:00
David Williams
c4cccf9043 Replaced double for loop with cleaner do-while loop. 2015-04-12 09:55:30 +02:00
David Williams
f35581506c Minor optimization - only creating vector if we are going to use it. 2015-04-12 09:42:15 +02:00
David Williams
54903150e9 Merge branch 'develop' into feature/custom-chunk-hash-table 2015-04-12 09:19:14 +02:00
David Williams
c562341db0 Added a second PagedVolume to the tests with much higher allowed memory usage. This makes more sense when testing random access, as low permitted memory usage causes disk IO to become the bottleneck. 2015-04-10 16:56:19 +02:00
David Williams
b90f0d4e15 Made the FilePager a little more robust regarding filename conflicts. 2015-04-10 16:47:50 +02:00
David Williams
8bd013f28e Added RawVolume version of test as well. 2015-04-10 16:14:29 +02:00
David Williams
887ecc1aaa Adding test to measure voxel access times when sampling the volume randomly. 2015-04-10 16:09:35 +02:00
David Williams
a2fe1944af Initial work on replacing std::unordered_map with a specialized hash table for looking up chunks based on their 3D position. 2015-04-09 23:44:25 +02:00
David Williams
27a59f34bc Merge branch 'feature/morton-encoding' into develop 2015-04-05 17:44:27 +02:00
David Williams
4c24d61408 Added another function for backwards compatibility. 2015-04-05 12:03:12 +02:00
David Williams
c887d1444f Added utility function for people who already have data in linear order, to convert it to Morton order. 2015-04-05 10:14:25 +02:00
David Williams
d521b08cf9 Added comment. 2015-04-04 09:57:31 +02:00
David Williams
dec06bcfe4 Added caching of variable. 2015-04-04 09:49:12 +02:00
David Williams
77db90ac30 Removed unneeded variable. 2015-04-04 09:42:46 +02:00
David Williams
0d36c416f2 Tidied up macros. 2015-04-04 09:18:51 +02:00
David Williams
3ca0222b19 Applied simplified test when going in the negative direction as well. 2015-04-04 00:08:20 +02:00
David Williams
d1bcaec2c5 This commit knocks about 30% off the run time of the sampler tests by using a more efficient check for whether we are near the edge of the chunk. 2015-04-02 23:11:19 +02:00
David Williams
d41a7d2747 Removed redundant samplers. 2015-04-02 21:35:50 +02:00
David Williams
135aa96bdf Further fixes for move...() functions. 2015-04-01 23:34:57 +02:00
David Williams
056cae39b5 Fixed sampler move...() functions to work with Morton ordering. 2015-04-01 22:57:22 +02:00
David Williams
b518978cd6 Enlarged lookup tables to 256 elements. 2015-04-01 22:34:42 +02:00
David Williams
65f39e7b57 Made the values signed ints, as otherwise the casting was doing something strange on 64-bit systems. 2015-04-01 16:29:19 +02:00
David Williams
5d220c5d57 Added extra lookup tables to avoid the need to multiply y/z deltas by 2/4 each time. 2015-03-31 23:58:01 +02:00
David Williams
60612c5583 Implemented use of delta for the rest of the peek functions. 2015-03-31 19:55:22 +02:00
David Williams
afd0650230 Implemented peeking in positive x and negative x directions using Matt's delta lookup table. 2015-03-31 16:33:56 +02:00
David Williams
120b8e84cc Added position in chunk and pointer to current chunk data to sampler. 2015-03-30 23:33:51 +02:00
David Williams
d34c1d227c Merge branch 'develop' into feature/morton-encoding 2015-03-30 15:38:34 +02:00
David Williams
5847219331 Fixed bug with chunk timestamp not being updated. 2015-03-30 15:36:28 +02:00
David Williams
b415e5c5f3 calculateAmbientOcclusion() now works with both RawVolume and PagedVolume. 2015-03-30 11:44:25 +02:00
David Williams
d000616d3e Revert "Ambient occlusion test now uses RawVolume, as it need a fixed size volume to create a temporary array."
This reverts commit 396d1cfc599e6837cf38bc1a95e680e9721ea844.
2015-03-30 11:24:48 +02:00
David Williams
413bb95b1a Passing parameter as const ref. 2015-03-30 11:01:08 +02:00
David Williams
7f96005985 Commented out optimized path in sampler as it doesn't work now that we are using Morton ordering for the data in chunks. However, we can probably reinstate such a fast path if we give some thought as to how it should be done. 2015-03-29 09:58:28 +02:00
David Williams
d3b2dab1ac Switched to using lookup tables for Morton encoding. 2015-03-29 00:17:27 +01:00
David Williams
d99ed5e624 Implemented morton encoding using standard bit-twidling approach. 2015-03-28 09:46:05 +01:00
David Williams
1c17a7147b Made test do 10 times more iterations. 2015-03-28 08:42:06 +01:00
David Williams
9256f3deb5 Fixed compile warning. 2015-03-27 21:23:31 +01:00
David Williams
322bedc009 Improved test for PagedVolume::Chunk performance. 2015-03-26 23:45:01 +01:00
David Williams
1d24b189ca Refactoed test code. 2015-03-25 17:12:11 +01:00
David Williams
931c6cd3ec Added tests for chunk performance. 2015-03-25 16:40:05 +01:00
David Williams
6516c00e62 Merge branch 'feature/optimize-paged-volume' into develop 2015-03-21 16:30:07 +01:00
David Williams
3facd4df41 Removed commented out code. 2015-03-21 16:27:43 +01:00
David Williams
d6c708f869 Merge branch 'develop' into feature/optimize-paged-volume 2015-03-21 16:24:46 +01:00
David Williams
b027cf1a0c Moved common code into function. 2015-03-21 16:22:23 +01:00
David Williams
778238d11d Moved the test for whether we are accessing the same voxel as last time. 2015-03-21 14:57:48 +01:00
David Williams
d477bec540 Revert "Replaced Vector3D with integer as key to map."
This reverts commit e82d6beca1a5cf7e81c546e6dd0243f54ff5d3e6.
2015-03-21 14:41:15 +01:00
David Williams
672c375a7a Revert "Work on using a bitfield to set up chunk key."
This reverts commit 8bd8f8ba7a91de21fd56d4350f3bf8403a84c4b3.
2015-03-21 14:41:10 +01:00
David Williams
5fc0317260 Revert "Added typedef for chunk key type."
This reverts commit 6419c5827bc99d91dd5e96acd17bd507a30dc106.
2015-03-21 14:41:04 +01:00
David Williams
92eaaae765 Revert "Decided to always use a 64-bit chunk key, rather than trying to make it configurable."
This reverts commit 69f6f4ac3713e7a9eee804773a516cc5c3412183.
2015-03-21 14:40:57 +01:00
David Williams
ceeb8f70ce Revert "Going back to building key by shifting instead of using bitfield."
This reverts commit 0d638f98370907b5ffed6b3460e320f4f9b2cf52.
2015-03-21 14:40:49 +01:00
David Williams
0c619ebec7 Revert "Added typedef for ChunkKey."
This reverts commit 905ec27f47a3e2dc1cba3a3a384b2c7532dab03d.
2015-03-21 14:40:30 +01:00
David Williams
f574563672 Revert "New, safer method of packing which makes careful use of casting to avoid problems with e.g. signed integer sign extension."
This reverts commit fd451be2dd7b65671274791105e76bd6a31a0f79.
2015-03-21 14:40:11 +01:00
David Williams
fd451be2dd New, safer method of packing which makes careful use of casting to avoid problems with e.g. signed integer sign extension. 2015-03-21 08:48:45 +01:00
David Williams
905ec27f47 Added typedef for ChunkKey. 2015-03-21 08:12:02 +01:00
David Williams
0d638f9837 Going back to building key by shifting instead of using bitfield. 2015-03-21 08:05:58 +01:00
David Williams
0e995b5140 Fixed some compiler warnings. 2015-03-21 07:40:32 +01:00
David Williams
69f6f4ac37 Decided to always use a 64-bit chunk key, rather than trying to make it configurable. 2015-03-20 23:09:38 +01:00
David Williams
6419c5827b Added typedef for chunk key type. 2015-03-20 16:59:25 +01:00
David Williams
8bd8f8ba7a Work on using a bitfield to set up chunk key. 2015-03-20 15:48:46 +01:00
David Williams
cd48c6f611 Made method const. 2015-03-19 23:08:35 +01:00
David Williams
e82d6beca1 Replaced Vector3D with integer as key to map.
Chunks of voxel data are stored in a map, and it is quite common to need to search the map for a particular chunk. The key type used to be a Vector3D (i.e. the position of the chunk in 3D space) which makes conceptual sense but is relatively slow. Using a Vector3D as a key seems to have overhead, probably in terms of copying and performing comparisons. It seems to be significantly faster to use an integer as a key, so we now take the 3D position and pack it into a single integer by bitshifting.

Naturally this reduces the range of positions we can store - a 32-bit int can only encode 3 x 10-bit values, which means our volume can only be 1024 chunks in each direction (with a chunk often being 32x32x32 voxels). This should still be large enough for most uses, but an upcoming change will allow 64-bit keys to be used (at least on 64-bit builds) which then allows 21 bits of precision  per component. This is so large that it's almost infinite for any practical purposes.
2015-03-15 09:32:42 +01:00
David Williams
d305038c27 Replaced loop with fill. 2015-03-11 23:47:32 +01:00
David Williams
741234e4a5 Small speed improvement by storing variables separately (rather than in Vector3D) to void construction/comparison overhead. 2015-03-09 23:52:56 +01:00
David Williams
99d0a226c8 Tidying up. 2015-03-08 23:48:55 +01:00
David Williams
72abcd8e9c Chunks are now stored with unique_ptr rather than shared_ptr. 2015-03-08 23:30:12 +01:00
Matt Williams
639eb6620f Add 'this' pointer disambiguation.
I guess this didn't fail on MSVC due to the different name lookup rules
the use.

Fixes issue 56.
2015-03-08 12:51:00 +00:00
David Williams
c98ad8c948 Merge branch 'feature/remove-wrap-modes' into develop 2015-03-07 21:19:21 +01:00
David Williams
43c203a2c9 Removed declaration of function for which we already removed the definition. 2015-03-07 17:42:31 +01:00
David Williams
aaa6b1dc15 A PagedVolume must now always be provided with a Pager when it is constructed. 2015-03-07 17:01:07 +01:00
David Williams
5a5b2b3875 Spotted an optimization for computing the voxel position. 2015-03-06 23:03:38 +01:00
David Williams
2c0d9cb9e7 Moved contents of initialize() into constructor. 2015-03-05 23:51:16 +01:00
David Williams
c804190d84 Removed the ability to set the target memory usage after construction, and this is now just done through the constructor. I don't think the functionality was useful, and this simplifies more logic. 2015-03-05 23:42:50 +01:00
David Williams
89550fcd44 Fixed warnings. 2015-03-05 00:04:22 +01:00
David Williams
61bffc9783 Removed some not useful functions. 2015-03-04 23:31:24 +01:00
David Williams
1213a4047a Fully stripped out references to wrap modes. 2015-03-04 23:13:37 +01:00
David Williams
bd6efe8c3c Stuff related to valid regions is being moved from BaseVolum to RawVolume, as PagedVolume is now infinite. 2015-03-04 22:42:14 +01:00
David Williams
d3618ca688 Removed tracking of whether the PagedVolume::Sampler is currently valid. 2015-03-01 23:32:22 +01:00
David Williams
396d1cfc59 Ambient occlusion test now uses RawVolume, as it need a fixed size volume to create a temporary array. 2015-03-01 09:51:45 +01:00
David Williams
e7f41b7e0f More fixing/tidying of test, related to removing volume size limit. 2015-03-01 08:14:30 +01:00
David Williams
bfc7dfdc1b Removed the ability to specify a region in the PagedVolume's constructor, and updated the tests and examples where required. 2015-02-28 23:31:23 +01:00
David Williams
7e03c3e05b Compile fixes and tweaks for tests. 2015-02-28 13:43:17 +01:00
Matt Williams
09c15173f9 Simplify -std=c++0x flag logic
This could be improved in CMake 3.1 by using CXX_STANDARD and
CXX_STANDARD_REQUIRED (see http://stackoverflow.com/a/20165220/96704)
2015-02-28 10:55:01 +00:00
Matt Williams
41d5ea6178 Move FindQt5Test logic inside tests directory 2015-02-28 10:40:05 +00:00
Matt Williams
d9dae773dc Simplify the BUILD_EXAMPLES logic 2015-02-28 10:24:32 +00:00
Matt Williams
32b07659a8 Move all the examples' CMake logic into the examples directory 2015-02-28 10:19:17 +00:00
Matt Williams
969310f327 Make sure we're notifiying if the docs are available 2015-02-28 10:17:56 +00:00
Matt Williams
65f966555d Move Doxygen stuff into include directory where it is actually used 2015-02-28 10:06:56 +00:00
Matt Williams
cb1cd58288 Remove all mention of LIBRARY_TYPE as PolyVox is now header-only 2015-02-28 09:56:12 +00:00
David Williams
f262c0e8f5 Revert "Removing tests which depend on wrap modes, in preparation for removing the wrap modes themselves."
This reverts commit 917d3b8c953c7fa6ceb3ab232dab54b78d57751c.
2015-02-28 09:59:28 +01:00
David Williams
416ae8eb7f Revert "Removed 'AllInternal' part of function name as it is now redundant."
This reverts commit 42e8b2cf4478b40663437df724a2cd292255671f.
2015-02-28 09:59:11 +01:00
David Williams
1853a0fc4e Revert "More work on removing wrap modes."
This reverts commit 6817899e6a9f18d708597f6cdabfffed7d4f671f.
2015-02-28 09:58:41 +01:00
David Williams
6817899e6a More work on removing wrap modes. 2015-02-27 15:12:11 +01:00
David Williams
3ace735619 Work on removing wrap modes. 2015-02-27 13:48:31 +01:00
David Williams
64d010527b Removed old getVoxelAt()/setVoxelAt() functions. they've been flagged as deprecated for a while now, and are replaced by just getVoxel()/setVoxel(). 2015-02-27 11:07:15 +01:00
David Williams
42e8b2cf44 Removed 'AllInternal' part of function name as it is now redundant. 2015-02-26 22:15:19 +01:00
David Williams
917d3b8c95 Removing tests which depend on wrap modes, in preparation for removing the wrap modes themselves. 2015-02-26 17:07:00 +01:00
David Williams
7ac652e92b More compile fixes for GCC. Because our openGLWidget is now templatized we need to explicitly use 'this->' to access base members (and the gl...() functions are provided by the base class in Qt). See http://stackoverflow.com/a/15505043 2015-02-25 16:11:22 +01:00
David Williams
f7af804ccf Compile fix for GCC. 2015-02-25 15:57:59 +01:00
David Williams
1f3dc558da Added missing header. 2015-02-24 23:46:35 +01:00
David Williams
2ec29e33b7 Tidying up OpenGLWidget. 2015-02-24 23:44:04 +01:00
David Williams
fbb7ff4728 Merge branch 'feature/example-refactor' into develop 2015-02-24 22:23:57 +01:00
David Williams
e985dce075 Templatized OpenGLWidget so users can specify the version of OpenGL to support. 2015-02-24 22:17:46 +01:00
David Williams
d3b71a92b9 Tidying up code. 2015-02-24 16:53:34 +01:00
David Williams
9547824f14 Renamed matrices. I quite like names such as 'modelToWorldMatrix' and 'cameraToClipMatrix' because they were very explicit about what the transform was doing. However OpenGL uses common terms such as 'model matrix' and 'projection matrix', so other people wlil be able to follow the code more easily if we stick to these conventions. 2015-02-24 16:08:55 +01:00
David Williams
7262ca313e More work splitting example framework into two pieces. 2015-02-20 16:56:03 +01:00
David Williams
838407ba4f Started splitting example framework into to two classes. One will be general purpose (for use in Cubiquity, etc), and the other will have PolyVox specific stuff. 2015-02-20 16:20:09 +01:00
David Williams
9c93c5fc36 Switched examples to use FPS-style first person perspective camera. 2015-02-20 15:28:54 +01:00
David Williams
565aa21799 Refactoring example code. 2015-02-20 11:23:17 +01:00
David Williams
3f849e19a4 Started refactoring examples and got DecodeOnGPUExample working. 2015-02-15 12:03:31 +01:00
David Williams
92daf9a0c0 Fixed CMake script for DecodeOnGPU example, though it's currently disabled due to compile errors. 2015-02-14 09:30:59 +01:00
David Williams
28c516b5ad Merge branch 'feature/opengl' into develop 2015-02-10 23:44:14 +01:00
David Williams
7e19706681 C++11 random number generators are consistent across platforms, but the distribution classes are not: http://stackoverflow.com/a/13589262 2015-02-10 23:35:17 +01:00
David Williams
f87966686d Another 'typename', GCC really likes these. 2015-02-10 21:52:05 +01:00
David Williams
1cbc0605fd Added 'typename'. 2015-02-10 21:49:28 +01:00
David Williams
feb9b6bdc6 Switched to using C++11 random number generator (MT) for tests, hoping it will be consistent across platforms. 2015-02-10 21:46:09 +01:00
David Williams
41498cfcb8 Removed GLEW from repository. 2015-02-09 23:22:12 +01:00
David Williams
ec80bfe740 Switched to using Qt for loading extensions, instead of GLEW. 2015-02-09 23:17:33 +01:00
David Williams
f042584ed5 Removed old OpengGL widget. 2015-02-09 22:15:03 +01:00
David Williams
c62bde0066 Work on getting the OpenGL/Qt5 support working with new header-only library. 2015-02-09 22:11:06 +01:00
David Williams
d9da93b6c0 Merge branch 'develop' into feature/opengl
Conflicts:
	examples/Basic/CMakeLists.txt
	examples/Basic/OpenGLWidget.cpp
	examples/Basic/OpenGLWidget.h
	include/PolyVox/Impl/Timer.h
2015-02-08 20:49:25 +01:00
David Williams
d875ff33ce Fixed min/max related compile error on Windows. 2015-02-08 12:41:53 +01:00
David Williams
74089437b3 Merge branch 'feature/header-only' into develop 2015-02-07 23:22:00 +01:00
David Williams
72be03262a Fixed install to work on Windows. 2015-02-07 23:21:25 +01:00
David Williams
7946e55357 Fixed install on Linux. 2015-02-07 23:11:56 +01:00
David Williams
049a77cd0c Moved all headers from 'PolyVoxCore' to 'PolyVox', as we no longer have the core/util distinction. 2015-02-07 17:26:36 +01:00
David Williams
16a75d0606 Reoranising header structure. 2015-02-07 17:16:54 +01:00
David Williams
97bd3a232a Renamed 'library' folder to 'include' (as it just contains headers now). 2015-02-07 15:21:33 +01:00
David Williams
6e2004d9c5 Really removed PolyVoxUtil. 2015-02-07 15:04:34 +01:00
David Williams
a296807ed9 Removed PolyVoxUtil. 2015-02-07 14:59:08 +01:00
David Williams
630affbf4d Moved bindings from inside 'library' folder to root folder. 2015-02-07 14:47:21 +01:00
David Williams
c3305ea14b Reinstated some of the 'install' code. 2015-02-07 10:36:49 +01:00
David Williams
5d54c881a1 Added custom target (which doesn't build anything) so that our header-only library still shows up in VisualStudio for browsing the files. 2015-02-07 06:52:47 +01:00
David Williams
c3f2e5217e Removed CMake code which tries to build/use PolyVoxCore as a library. 2015-02-06 23:29:35 +01:00
David Williams
9d9e3996a3 Moved utility functions to header. 2015-02-06 21:28:47 +01:00
David Williams
07f1593561 Made logging functions header only. 2015-02-06 21:13:12 +01:00
David Williams
4325ffabc4 Moved error handling functions/macros to be header-only. 2015-02-06 21:08:19 +01:00
David Williams
6e8d9dfb75 Windows now uses standard C++ timer. I assume we weren't using it before because it wasn't present on older versions of Visual Studio?
Moved timer code to header.
2015-02-06 16:52:21 +01:00
David Williams
8cff2bb2da Moved random vectors to header files. 2015-02-06 16:43:29 +01:00
David Williams
eb45c97a61 Moved marching cubes tables to header file. 2015-02-06 16:37:08 +01:00
David Williams
d480935e38 Moved A* pathfinder data from .cpp to header. 2015-02-06 16:08:05 +01:00
David Williams
8065b709d1 Made Region header only. 2015-02-06 00:07:32 +01:00
Matt Williams
ecb3439d22 Reorder initialisation to silence -Wreorder warnings 2014-12-12 10:36:45 +00:00
Matt Williams
6d6b190743 Reorganise the CMake scripts to make sure the core library is independent 2014-12-10 15:53:25 +00:00
Matt Williams
2e98414fd3 Start updating the library bindings
Nothing works at the moment and the bindings are likely going to have to
change significantly.

In the meantime just disable them by default to avoid confusion.
2014-12-10 15:47:54 +00:00
David Williams
436e8d479c Compile fix. 2014-10-03 21:47:04 +02:00
David Williams
4ed75cd174 Updated changlelog with a quick braindump. 2014-09-27 09:26:21 +02:00
David Williams
66fdc19fe9 Added pattern for SWIG interface files. 2014-09-25 23:02:39 +02:00
David Williams
86357d66b7 Normalized line endings 2014-09-25 22:38:01 +02:00
David Williams
c560e84be5 Added gitattributes file for proper handling of line endings. 2014-09-25 22:31:13 +02:00
David Williams
6a6e1e49e1 Merge branch 'feature/volume-work' into develop 2014-09-21 23:13:06 +02:00
David Williams
75df6621bd GCC fixes 2014-09-21 23:07:14 +02:00
David Williams
db2e62d2a8 Replaced LargeVolume and SimpleVolume with PagedVolume in tests and examples. 2014-09-21 17:57:42 +02:00
David Williams
f95cc6bfca Added comments and warnings. 2014-09-21 17:50:35 +02:00
David Williams
3a56a70f38 Put deprecated functions back in - lets remove them in the future after more thought. 2014-09-21 15:07:54 +02:00
David Williams
ccb9f8d564 Updated documentation. 2014-09-21 15:03:13 +02:00
David Williams
ae0c5b3702 Added comments and removed deprecated functions. 2014-09-21 14:47:46 +02:00
David Williams
33ec5e1d79 Added a couple of comments. 2014-09-21 12:16:54 +02:00
David Williams
d6a7b83698 Moved Pager to be a nested class of PagedVolume. 2014-09-21 11:42:12 +02:00
David Williams
db9a74fdb4 Moving Chunk to be a nested class of PagedVolume. 2014-09-21 10:27:55 +02:00
David Williams
71035029d1 More renaming blocks to chunks. 2014-09-20 23:27:28 +02:00
David Williams
0ab7f27f0f More renaming of block to chunk. 2014-09-20 21:27:26 +02:00
David Williams
f3a18befad More renaming of 'block' to 'chunk' 2014-09-20 21:17:21 +02:00
David Williams
8d7d88a7df Renamed a bunch of stuff from using 'block' to 'chunk' 2014-09-20 17:39:12 +02:00
David Williams
ede35435a0 Renamed UncompressedBlock to Chunk. 2014-09-20 17:26:57 +02:00
David Williams
880dcd8645 Fixed incorrect messages about temp files not being deleted. 2014-09-20 17:17:18 +02:00
David Williams
4779f91787 TestVolume unit test now tests PagedVolume rather than SimpleVolume and LargeVolume. 2014-09-20 14:49:12 +02:00
David Williams
6f08184fcb Fixed initialization of blocks. 2014-09-19 17:02:44 +02:00
David Williams
25a1d95387 Renamed LargeVolume to PagedVolume, deleted SimpleVolume, and set up typedefs pointing LargeVolume and SimpleVolume to PagedVolume for backwards compatibility. 2014-09-19 16:50:24 +02:00
David Williams
3a08487dc2 Blocks now stored in an unordered_map (hash based) rather than a map. 2014-09-18 23:35:16 +02:00
David Williams
2602b00103 Simplifying code. 2014-09-18 16:54:14 +02:00
David Williams
b08974c197 Work on limiting memory usage. 2014-09-18 16:26:47 +02:00
David Williams
d2bbd6beba Some renaming. 2014-09-18 14:58:17 +02:00
David Williams
8dd026e095 Work on limiting maximum memory usage. 2014-09-18 14:51:43 +02:00
David Williams
38b8764129 Tidying up prefetch function. 2014-09-18 14:22:44 +02:00
David Williams
e88466ad4d Tidying flush function. 2014-09-18 14:14:08 +02:00
David Williams
277b6c7b9b Tidying up. 2014-09-17 23:53:14 +02:00
David Williams
916fe310ad Added function to purge null blocks. 2014-09-17 23:31:23 +02:00
David Williams
177eb16bec Tidying and commenting. 2014-09-17 21:40:27 +02:00
David Williams
daa93aab19 Tidying and commenting. 2014-09-17 21:27:52 +02:00
David Williams
98526d38d3 Crash fix. 2014-09-17 21:04:47 +02:00
David Williams
37f1ddaed2 Work on block storage. 2014-09-17 17:10:13 +02:00
David Williams
5b59bc2d8c Moved paging code into block constructor/destructor. 2014-09-17 13:35:43 +02:00
David Williams
2b47c959a5 Work on getUncompressedVoxel(). 2014-09-16 21:39:55 +02:00
David Williams
704eeaf948 Work on supporting no pager being attached. 2014-09-16 17:02:53 +02:00
David Williams
47ace554cc Making use of shared_ptr to track blocks. 2014-09-14 11:47:17 +02:00
David Williams
3cf8f38793 Merged Block and UncompressedBlock classes. 2014-09-13 23:38:11 +02:00
David Williams
5ff54c041f Renamed variable. 2014-09-13 23:14:07 +02:00
David Williams
c0a22de2df Removed a lot of compression-related code. 2014-09-13 12:20:56 +02:00
David Williams
302c6e688b More work eliminating compression from inside LargeVolume. 2014-09-13 11:59:51 +02:00
David Williams
bfe03142b7 Carefully dismanteling compression related code. 2014-09-13 11:30:52 +02:00
David Williams
4781ca5c42 Work on removing compression from LargeVolume. 2014-09-12 15:36:28 +02:00
David Williams
882798ccb8 Modifying surface extractor test to work with LargeVolume. 2014-09-12 00:02:06 +02:00
David Williams
a9f1a29868 Adding Vector performance test. 2014-09-05 16:06:40 +02:00
David Williams
40a290bfce Merge branch 'feature/optimize-extractors' into develop 2014-08-26 21:36:43 +02:00
David Williams
25860122b0 Fixed incorrect array indexing. 2014-08-25 23:07:29 +02:00
David Williams
09e68d923e Merge branch 'develop' into feature/optimize-extractors 2014-08-24 23:15:30 +02:00
David Williams
089303f02f Fix for example. 2014-08-24 23:05:29 +02:00
David Williams
d06dbdf054 Bit renaming. Old Array class is gone, and is replaced by the Array2D class which has also been renamed to Array. 2014-08-24 22:30:50 +02:00
David Williams
d49db280d5 TestVolumeSubclass now uses Array2D instead of Array. 2014-08-24 21:55:44 +02:00
David Williams
528873bcd3 Extended 'Array2D class to be multidimensional (will rename it shortly). 2014-08-24 21:54:59 +02:00
David Williams
9a1c6784df Steps towards making new array class be multidimensional. 2014-08-24 12:26:36 +02:00
David Williams
083c65ecd5 Added asserts. 2014-08-24 12:03:41 +02:00
David Williams
1fb82f40b3 Switched to C++11-style hiding of copy constructor and assignment operator. 2014-08-24 11:51:45 +02:00
David Williams
ad73caf368 Array2D now has private copy constructor and assignment operator to prevent accidental copying. 2014-08-22 15:49:30 +02:00
David Williams
0ff0234ce1 Switched marching cubes extractor to use new Array2D instead of array, and it now more than twice as fast in the best case (empty volume). 2014-08-21 23:04:30 +02:00
David Williams
83c287727f Additions to Array2D. 2014-08-21 23:03:38 +02:00
David Williams
5f8e3df5df Revert "Replaced usage of our 'Array' class with native C array and got significant performance increase."
This reverts commit d0aa7cd60f81bee3abf44f44571900464d7ac96f.
2014-08-21 21:38:36 +02:00
David Williams
20815b6083 Moved Array2D to it's own file. 2014-08-21 21:38:19 +02:00
David Williams
46358adfbc New array class is 50(!) times faster than the old one on raw read-write performance. It's also significantly simply. 2014-08-21 21:31:09 +02:00
David Williams
d9f328cadb It seems the PolyVox Array class is really slow compared to raw C arrays. I've added a test ready for some experimentation. 2014-08-21 16:57:23 +02:00
David Williams
d0aa7cd60f Replaced usage of our 'Array' class with native C array and got significant performance increase. 2014-08-21 00:06:20 +02:00
David Williams
458a534bf3 Eliminated creation of temporary vector. 2014-08-20 17:18:20 +02:00
David Williams
4482538f9e Added header for testing RawVolume as well as SimpleVolume. 2014-08-20 17:16:45 +02:00
David Williams
43e0d6f417 Merge branch 'feature/mesh-work' into develop 2014-08-19 21:44:09 +02:00
David Williams
33c5fe7526 More cubic surface extractor tests. 2014-08-19 21:36:08 +02:00
DavidWilliams
17ee7982d5 Added typename for GCC. 2014-08-19 21:30:37 +02:00
David Williams
9b88e97599 Linux/GCC fix. 2014-08-19 21:02:52 +02:00
David Williams
349009c67e Removed template aliases as they push GCC version up to 4.7, and we don't really *need* them. 2014-08-19 21:02:06 +02:00
David Williams
72f696652a Added marching cubes performance tests. 2014-08-18 22:10:35 +02:00
David Williams
c75b0d58ce Fixed incorrect threshold calculation for floats. 2014-08-18 22:06:44 +02:00
David Williams
e2051ed713 Tweaks to cubic surface tests. 2014-08-18 21:25:29 +02:00
David Williams
c0added385 Work on cubic extractor tests. 2014-08-18 16:48:32 +02:00
David Williams
ec9b06ef0f Work on cubic surface extractor tests. 2014-08-18 16:40:36 +02:00
David Williams
4b3b940b91 Removed old testing code. 2014-08-18 16:29:08 +02:00
David Williams
0863d82068 Added check to alert the user if their version of Visual Studio is too old. 2014-08-18 16:20:43 +02:00
David Williams
502b21c3bd Moved comments around. 2014-08-18 16:13:59 +02:00
David Williams
5e7c4fbc12 Added handy type aliases for meshes. 2014-08-18 16:01:31 +02:00
David Williams
be47aec7f7 Work on cubic extractor tests. 2014-08-18 15:47:00 +02:00
David Williams
3c82652f46 Removed the use of clever SFINAE tricks to resolve ambiguous functions. It was proving complex with the cubic surface extractor, so we remove it from the marching cubes version as well.
For now, we just rename the ambiguous functions differently to avoid the ambiguity but could come back to this in the future.
2014-08-18 15:38:18 +02:00
David Williams
ba6685289d Work on cubic extractor interface. 2014-08-17 23:43:59 +02:00
David Williams
5c30aa20f9 Working on new tests for extractCubicSurface(). 2014-08-17 15:45:23 +02:00
David Williams
1f5c074364 Bringing extractCubicMesh into line with extractMarchingCubesMesh. 2014-08-16 16:38:32 +02:00
David Williams
6c30f34089 Renamed 'Controller' to 'ControllerType' when used as a template parameter. 2014-08-16 16:24:52 +02:00
David Williams
0ccc268b16 Avoided ambiguous functions through the (possibly too clever) use of SFINAE. 2014-08-16 09:55:08 +02:00
David Williams
aa4591d206 Added comments. 2014-08-14 16:34:29 +02:00
David Williams
93fdd36f8f Work on interface to 'extractMarchingCubesMesh' and tests. 2014-08-14 15:57:10 +02:00
David Williams
f1ed0c1be2 Examples now support both 16 and 32 bit indices. 2014-08-13 15:59:13 +02:00
David Williams
d4118a2052 More work on tests. 2014-08-12 16:53:47 +02:00
David Williams
ed4bdf08c4 Added extraction test for MaterialDensityPair. 2014-08-12 16:09:56 +02:00
David Williams
0b5e7071ae Added double test. 2014-08-12 15:57:52 +02:00
David Williams
ccc9a3c158 More work on surface extraction tests. 2014-08-12 15:53:30 +02:00
David Williams
e2f43ebc5d More work on tests and surface extraction functions. 2014-08-11 23:46:01 +02:00
David Williams
64ba3f20f8 Work on extractor tests. 2014-08-11 16:20:11 +02:00
David Williams
11845c1d31 Work on tests. 2014-08-11 15:53:25 +02:00
David Williams
4b3c8a1648 Committing half-finished work on test so that I can work on it from elsewhere. 2014-08-11 08:46:06 +02:00
David Williams
eaea74b7f8 Templatizing marching cubes extractor on mesh type. 2014-08-10 09:18:27 +02:00
David Williams
29baac9d6d Tidying mesh class. 2014-08-09 09:31:45 +02:00
David Williams
94d1b57b81 Tidying mesh class. 2014-08-09 09:18:30 +02:00
David Williams
c5cf71b161 Extractors now templatised on index type. 2014-08-07 23:39:56 +02:00
David Williams
52dd0189d5 Simplified/removed multiple versions of functions, as we're now moving to VS2013 which supports default parameters for template functions. 2014-08-07 23:14:57 +02:00
David Williams
37757da98c Qualified use of abs() as it was causing problems on OS X 2014-07-30 23:43:26 +02:00
David Williams
e1cdf0ca06 Merge branch 'feature/better-normal-encoding' into develop 2014-07-24 22:39:06 +02:00
David Williams
112b277452 Updated GLSL decoder for new normal packing scheme. 2014-07-24 22:38:21 +02:00
David Williams
2b7ef5b966 Reverted some changes which were just for testing the new normal encoding. 2014-07-24 22:21:53 +02:00
David Williams
f9ee5a10b4 Merge branch 'develop' into feature/better-normal-encoding 2014-07-24 22:15:43 +02:00
David Williams
8326aa8668 Updated test (not really a useful fix but should probably think want we want from this test anyway). 2014-07-24 22:12:02 +02:00
David Williams
bfa14a32df Split 'decode()' function into several variants so it's not so heavily overloaded. 2014-07-24 16:55:11 +02:00
David Williams
98e722271e More restructuring code. 2014-07-24 15:40:03 +02:00
David Williams
972bc3a456 Restructuring some code. 2014-07-24 15:13:08 +02:00
David Williams
79c62be039 Oct-encoded normal now stored as uint again. 2014-07-23 23:50:04 +02:00
David Williams
4a42535f13 Added functions to perform 'octahedral' encoding and decoding of normals.
See http://jcgt.org/published/0003/02/01/paper-lowres.pdf
2014-07-23 23:35:46 +02:00
David Williams
dd5e34bc92 Moved normal encoding logic. 2014-07-22 23:48:18 +02:00
David Williams
9b84c9d07d Fixed compile error 2014-06-14 09:59:01 +02:00
David Williams
c68a48df6b Merge remote-tracking branch 'origin/feature/vertex-and-example-refactor' into develop
Conflicts:
	library/PolyVoxCore/include/PolyVoxCore/Mesh.h
2014-06-04 23:12:27 +02:00
David Williams
b1c03c9f9c Fix to mesh declaration. 2014-06-03 21:37:22 +02:00
David Williams
6bedd40694 Merge branch 'feature/vertex-and-example-refactor' into develop 2014-06-03 21:22:56 +02:00
David Williams
70b04a055e Compile fioxes for GCC.
Turns out the leading underscore was required, as otherwise GCC complains the typedef is hiding the original.
2014-06-03 21:21:04 +02:00
David Williams
b7be2ff7ab Added some error handling. 2014-06-03 16:59:09 +02:00
David Williams
06540d6c97 More work to make Mesh be templatized on IndexType.
This requires making the SurfaceExtractor classes be templatised on MeshType (at least for now - maybe there is a better approach when working with free functions). This has been partially done for CubicSurfaceExtractor.
2014-06-03 16:52:09 +02:00
David Williams
ffdf606ad6 Added IndexType template parameter to Mesh class. 2014-06-03 15:58:07 +02:00
David Williams
5701e7a6cc It seems we don't need these leading underscores? Perhaps they were required in older versions of Visual Studio? Let's see what GCC/Clang says. 2014-06-03 15:51:42 +02:00
David Williams
78d750a0f2 Removed unused 'LodRecord'. 2014-06-03 15:50:30 +02:00
David Williams
e6dc0716cd Merge branch 'feature/vertex-and-example-refactor' of https://bitbucket.org/volumesoffun/polyvox into feature/vertex-and-example-refactor 2014-06-03 15:36:45 +02:00
Matt Williams
9b19ea656b Fix commit on Linux 2014-06-03 10:37:11 +01:00
David Williams
31e5a6e346 Replaced 'm_region' with 'm_offset' and demonstrated its use. 2014-06-02 17:30:41 +02:00
David Williams
9fd52e3494 Removing more old stuff from the Mesh class. 2014-06-02 09:40:28 +02:00
David Williams
0bff22fbf5 Purged old/dead code from Mesh class. 2014-06-02 09:08:07 +02:00
David Williams
82f9d6ad6f Renamed VertexTypes.h to Vertex.h. 2014-06-02 08:57:30 +02:00
David Williams
d7d1d99ca9 Renamed members to differentiate between encoded and decoded values. 2014-06-02 08:45:25 +02:00
David Williams
4fa2400ef2 Comments and tidying. 2014-06-02 08:25:18 +02:00
David Williams
80d9feb5ea Made functions inline as they are defined in headers. 2014-06-01 21:54:31 +02:00
David Williams
b259b60de2 Tidying/commenting. 2014-06-01 17:35:00 +02:00
David Williams
392ccab703 Tidying decoding code. 2014-06-01 17:23:08 +02:00
David Williams
78ac1d12b5 The new, more compact vertex types are specific to their respective surface extractors, so they belong in the corresponding source files. 2014-06-01 17:01:36 +02:00
David Williams
4f1863eccb Removed apparently-incorrect use of logging statements (crashing under Visual Studio). 2014-05-30 16:36:24 +02:00
David Williams
224c27de50 Got normal decoding working in shader. 2014-05-29 23:31:36 +02:00
David Williams
2c916300ea Work on encoded marching cubes normals. 2014-05-29 21:45:26 +02:00
David Williams
a6a1c4dbb7 Getting ready to decode normal. 2014-05-29 19:34:43 +02:00
David Williams
e40eb6d762 Work on GPU decoding. 2014-05-29 19:29:15 +02:00
David Williams
8604d1209e Initial version of decoding shaders. 2014-05-29 14:23:22 +02:00
David Williams
f945fd4ce4 Work on example to decode vertices on the GPU. 2014-05-29 12:38:43 +02:00
David Williams
b635e9d29d Copied BasicExample as base for new 'DecodeOnGPU' example. 2014-05-29 12:20:33 +02:00
David Williams
2090b0087c Vertices now carry general purpose 'data' rather than a 'material', though the data will be treated as a material in many cases. This is part of making the architecture more generic and involves some renaming. 2014-05-29 11:39:29 +02:00
David Williams
85c5686ff9 Work on more compact version of MarchingCubesVertex. 2014-05-29 09:53:16 +02:00
David Williams
e9ba998f2f Changes to the folder organization of some files in Visual Studio (via CMake's source_group). 2014-05-28 14:03:26 +02:00
Matt Williams
c26686476d Use Qt's resource system to store the shader source
The shader source is included inside each comipled binary file. The
OpenGL example also provides its own shader files which overrides
the default. Common shader code is in the 'common' directory and
each example's custom shader is alongside the example's C++ code.
2014-05-28 10:29:05 +01:00
David Williams
35049b7a53 Throw exception if extracted region is too large. 2014-05-27 23:23:24 +02:00
David Williams
37ba9ab338 CubicVertex now uses a more memory efficient representation which can be decoded on the CPU or GPU. 2014-05-27 23:01:38 +02:00
David Williams
1790d8338f Merge branch 'feature/vertex-and-example-refactor' of https://bitbucket.org/volumesoffun/polyvox into feature/vertex-and-example-refactor 2014-05-27 17:05:46 +02:00
David Williams
764c9ac97c Simplified vertex types to structs with public members.
Added (currently dummy) decode methods.
2014-05-27 17:05:15 +02:00
Matt Williams
140cbc0fc7 Move shader code to external files rather than embedded
A bit of CMake code in each example copies the files to the
correct location and Qt loads them from the application's binary
directory.
2014-05-27 15:08:20 +01:00
David Williams
1d8fc25cb7 Compile fixes for GCC/Linux 2014-05-26 23:14:29 +02:00
David Williams
321d3eb7d4 Removed initializer which isn't supported in VS 2012. 2014-05-26 22:51:55 +02:00
David Williams
ba58cff815 Removed use of 'R' raw string literals as CS 2012 doesn't support them. 2014-05-26 22:51:09 +02:00
David Williams
5a23299634 More tidying shader code. 2014-05-26 21:14:54 +02:00
David Williams
fd3879faeb Tidying OpenGLExample shader code. 2014-05-26 21:10:07 +02:00
David Williams
40e528d782 Added lighting to OpenGL example. 2014-05-26 17:00:26 +02:00
David Williams
4ae25d6b1e More commenting. 2014-05-26 16:50:13 +02:00
David Williams
e9c8daa9cb Add comments and tidying. 2014-05-26 16:31:12 +02:00
David Williams
2a072f9347 Rearranged some functions. 2014-05-25 23:44:37 +02:00
David Williams
9e835a1110 Shader now passed by shared pointer. 2014-05-25 23:40:55 +02:00
David Williams
b97bf52214 Tidying up. 2014-05-25 23:34:12 +02:00
David Williams
ec08b28002 Turned off back-face culling in examples, as this makes it easier to view certain shapes such as heightmaps. 2014-05-25 21:45:28 +02:00
David Williams
499db6a185 Changed default shader to use normal as RGB (more useful for debugging). 2014-05-25 21:43:37 +02:00
David Williams
22869e4861 More tweaks to scaling and translation. 2014-05-25 21:36:41 +02:00
David Williams
b63a09cab3 Changing the way the examples handle translation and scaling. 2014-05-25 21:29:44 +02:00
David Williams
6738c4fc9e Smooth example now also uses new example OpenGLWidget. 2014-05-25 21:15:20 +02:00
David Williams
349dc2b0e6 Centered volume in viewport. 2014-05-25 21:06:44 +02:00
David Williams
e80c88a5ec Paging example now uses the new example OpenGLWidget. 2014-05-25 21:03:52 +02:00
David Williams
eb39f0bb4c OpenGLExample is once again rendered as multiple separate mehses (but using the example framework this time). 2014-05-25 12:28:45 +02:00
David Williams
f78aad8abd Fixed colors to match previous version of the example. 2014-05-24 22:58:31 +02:00
David Williams
99cf75e902 Material now passed to shader as integer rather than float. 2014-05-24 22:53:10 +02:00
David Williams
07b9cf05fa Changed OpenGLExample to use MaterialDensityPair88 instead of MaterialDensityPair44.
Added material to shaders.
2014-05-24 21:09:26 +02:00
David Williams
aace1f2e36 Exposing normals to example framework. 2014-05-24 09:38:01 +02:00
David Williams
f65edddd81 Tidying up. 2014-05-24 08:38:18 +02:00
David Williams
6cbb2d44bf Work on making OpenGLExample work with common example framework. 2014-05-23 22:44:58 +02:00
David Williams
34f57911a7 Converting OpenGLExample to use common OpenGLWidget. 2014-05-23 22:18:17 +02:00
David Williams
d34fd6b3c8 Moved OpenGLWidget into common folder so it can be used by other examples. 2014-05-23 22:11:47 +02:00
David Williams
4f7e1e6846 Each mesh now has it's own transform matrix applied, so that our example framework can support breaking a volume into regions. 2014-05-23 22:03:57 +02:00
David Williams
9f5b2e1659 Better templatization of addMesh. 2014-05-23 17:02:46 +02:00
David Williams
37bdf8e3ac Templatised code for example mesh conversion. 2014-05-23 16:26:56 +02:00
David Williams
79acf814db Revert "Compile fixes for VS2012"
This reverts commit e8313a683bd748ab36b2aff42ebdd16d28bd5320.
2014-05-23 16:11:53 +02:00
David Williams
e8313a683b Compile fixes for VS2012 2014-05-23 15:32:28 +02:00
David Williams
4aae00e4a8 Renamed SurfaceMesh to just Mesh 2014-05-23 15:17:07 +02:00
David Williams
da8f294847 Comments 2014-05-23 14:37:35 +02:00
David Williams
4cec89de38 Added ability to specify the visible region so that the example framework can support different volume sizes. 2014-05-23 14:32:46 +02:00
David Williams
ab741583e4 Renamed extractXxxSurface() to extractXxxMesh() 2014-05-22 23:26:40 +02:00
David Williams
f8ce3a5f3d Tidying camera code. 2014-05-22 17:03:06 +02:00
David Williams
16cbb94d90 Rotation is now applied by moving the camera rather than the meshes. 2014-05-22 16:51:41 +02:00
David Williams
7d55e00f76 More work adding support for multiple meshes. 2014-05-22 16:38:02 +02:00
David Williams
51e93fdabc Modifying the OpenGLWidget so that it can render multiple meshes. 2014-05-22 16:25:36 +02:00
Matt Williams
7fc954a6bf Fix SWIG include paths for C# bindings 2014-05-20 14:43:18 +01:00
David Williams
ef61480c3d Merge branch 'feature/vertex-refactor' into develop 2014-05-12 23:08:27 +02:00
David Williams
f2ba500c4c Merge branch 'develop' into feature/vertex-refactor
Conflicts:
	examples/Basic/main.cpp
	examples/Paging/main.cpp
	examples/SmoothLOD/main.cpp
	library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h
	tests/TestCubicSurfaceExtractor.cpp
	tests/TestSurfaceExtractor.cpp
	tests/TestVolumeSubclass.cpp
2014-05-12 23:04:19 +02:00
David Williams
1e0b8e97eb Merge branch 'feature/extractor-refactor' into develop 2014-05-12 21:13:26 +02:00
David Williams
d69e840055 Merge branch 'develop' into feature/vertex-refactor
Conflicts:
	library/PolyVoxCore/include/PolyVoxCore/DefaultIsQuadNeeded.h
	library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl
	library/PolyVoxCore/source/VertexTypes.cpp
2014-05-11 20:45:31 +02:00
David Williams
5191c3c068 Merge branch 'develop' into feature/extractor-refactor 2014-05-11 20:35:44 +02:00
David Williams
a34c106382 I accidentally merged the 'cubiquity-version' feature back into develop. It seems I can't simply reverse this commit (at least through SourceTree ) because it was a merge, so I'm having to simply revert the contents of the commit (i.e. the files). Bit of a mess! 2014-05-11 20:34:41 +02:00
David Williams
1bff5c207c Merge branch 'feature/cubiquity-version' of https://bitbucket.org/volumesoffun/polyvox.git into develop 2014-05-11 19:47:05 +02:00
David Williams
217aa93720 Test now uses free-function surface extractor. 2014-05-11 16:41:52 +02:00
David Williams
95a3e2e9ce Smooth LOD example now uses free function surface extractor. 2014-05-11 16:29:51 +02:00
David Williams
347028199c Paging example now also uses free-function surface extractor. 2014-05-11 16:27:38 +02:00
David Williams
a51eaa4a02 Merge branch 'develop' of https://bitbucket.org/volumesoffun/polyvox into feature/extractor-refactor
Conflicts:
	examples/Basic/main.cpp
2014-05-11 16:21:37 +02:00
David Williams
573c36db87 Renamed vertex classes to the far more meaningful 'CubicVertex' and 'MarchingCubesVertex'. The old names didn't make much sense, even less so now they are templatized. 2014-05-11 15:17:59 +02:00
David Williams
ae87dbee77 Fixed materials in OpenGL example. 2014-05-08 16:40:27 +02:00
David Williams
b0a8ca8a64 This commit templatizes the vertex classes on voxel types. This was the main change which was made for Cubiquity and it's very messy at the moment. However, this will improve when we make more use of 'auto' to hide the template madness. 2014-05-07 23:47:18 +02:00
David Williams
4c2aea3db1 Removed CubicSurfaceExtractorWithNornals. Going forward users will be expected to compute flat normals in the fragment shader. 2014-05-06 22:00:24 +02:00
David Williams
12246d1633 The PositionMaterial class can now be removed as we're not using it. 2014-05-05 20:58:35 +02:00
David Williams
5dfa7e2562 The CubicSurfaceExtractor now generates vertices of type PositionMaterialNormal rather than PositionMaterial. The normal property is just a dummy and is not filled in, though conceptually we could put something in there in the future (average normal of surrounding faces?)
The point of this change is to move towards having a single vertex class with known properties (including normal). This makes it simpler to write code which uses the vertices because we always know which properties are present. This will probably be useful when working with vertex buffer objects.
2014-05-05 20:53:47 +02:00
David Williams
2da902d5f9 This change reverts PolyVox back to using Qt 4.8. This is expected to be a temporary change, required because moving to Qt 5 caused various complications on Windows which we are not yet ready to address.
For more details see here: https://bitbucket.org/volumesoffun/polyvox/issue/41/upgrade-to-qt-5
2014-05-05 20:29:52 +02:00
David Williams
fe3f2d589e Fixed uninitialized variables (was causing crash on OS X). 2014-04-14 21:08:05 +02:00
Matt Williams
45302fde02 Qt is not REQUIERD. This was causing errors. 2014-03-27 10:24:29 +00:00
David Williams
d79ac03fb6 VS2012 doesn't accept these curly brackets (C++11 initializer lists?). The code seems to work without them though. 2014-03-25 23:03:18 +01:00
David Williams
7b5e1cd1d5 Unfortunately VS2012 doesn't support 'R' raw string literals . Maybe the shader code should be moved into separate files anyway. 2014-03-25 23:00:29 +01:00
David Williams
a78508a79f Switched from QOpenGLFunctions_3_1 to QOpenGLFunctions. This seems to require not using vertex arrays, which needs further investigation. 2014-03-25 22:49:59 +01:00
David Williams
19387fd62e I believe the correct way to use the QOpenGLFunction_3_1 class is actually to use protected inheritance, so that it's members are pulled into class scope and we can avoid the 'gl->' prefix. At least, this is the recommended approach for QOpenGLFunctions (http://qt-project.org/doc/qt-5/qopenglfunctions.html#details) 2014-03-25 21:53:14 +01:00
David Williams
1f1cc67fb7 Revert "Remove usage of QOpenGLFunctions and use GLEW instead."
This reverts commit 464d713c2affcf7d8acb3403c9bd33bca673fb56.
2014-03-25 21:44:01 +01:00
Matt Williams
464d713c2a Remove usage of QOpenGLFunctions and use GLEW instead.
Qt's OpenGL interface was causing problems on Windows since it doesn't mix
well with ANGLE.

Relates to issue #50.
2014-03-23 12:16:02 +00:00
Matt Williams
ac16dfd325 Update the BasicExample to use OpenGL 3
The example now uses OpenGL 3 features like Vertex Array Objects and uses
no immediate mode stuff. Qt5 is used for some features like matrices and
shaders.

There is now no dependency on GLEW either.
2014-03-19 21:26:04 +00:00
David Williams
f05d54b985 Merge branch 'develop' into feature/extractor-refactor 2014-03-17 16:07:29 +01:00
David Williams
d06650172a Added missing header which was causing problems when compiling Cubiquity on Linux. 2014-03-16 21:13:15 +01:00
Matt Williams
868fbb84a0 Update to use Qt5
The examples and tests now use Qt5. This allows some nice tidying of the
CMake files, some of which will come in future.

Closes issue #41
2014-03-09 18:02:24 +00:00
Matt Williams
00d1b8e10c Update required CMake version to 2.8.6 2014-03-09 17:55:14 +00:00
Matt Williams
cec740f429 Remove search for Boost
We don't use Boost anywhere any more so don't try to search for it.
2014-03-09 17:54:17 +00:00
David Williams
e52e9e373e Switched test to use unclassed function. 2014-03-07 16:25:24 +01:00
David Williams
0bbb648925 Added functions around CubicSurfaceExtractor. 2014-03-07 16:08:20 +01:00
David Williams
d50b910a45 Merge branch 'develop' into feature/cubiquity-version
Conflicts:
	library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl
2014-03-06 16:54:38 +01:00
David Williams
163e520e9f Changed he way that materials are blended by default, such that the material of the voxel with the highest density is used. 2014-03-06 16:38:57 +01:00
David Williams
d8bcd09d9b Compile fixes for GCC. 2014-03-05 16:47:51 +01:00
David Williams
acbfb184b8 Wrapped MarchingCubesSurfaceExtractor with functions (part of unclassing). 2014-03-05 16:30:54 +01:00
David Williams
529e97f71e Added use of auto for determining mesh type. 2014-03-05 15:58:33 +01:00
David Williams
0755961750 Added support for default parameters. 2014-03-05 15:50:17 +01:00
David Williams
67ec0d2db8 Initial function wrapper around CubicSurfaceExtractorWithNormals. 2014-03-05 15:41:16 +01:00
Daviw Williams
b416dc933f Merge branch 'develop' into feature/cubiquity-version
Conflicts:
	library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl
2014-02-27 15:40:01 +01:00
Daviw Williams
1cf5f4c899 Added comment. 2014-02-26 17:00:40 +01:00
Daviw Williams
c5780dd8e2 Brought improved blending changes across from Cubiquity branch. 2014-02-26 16:55:09 +01:00
Daviw Williams
60396a2699 Merge branch 'develop' into feature/cubiquity-version
Conflicts:
	library/PolyVoxCore/source/Impl/Utility.cpp
2014-02-25 16:55:52 +01:00
Daviw Williams
2458f94feb Eliminating some differences from the cubiquity-version branch. 2014-02-25 16:51:26 +01:00
Daviw Williams
aeefe7f938 Merge branch 'develop' into feature/cubiquity-version
Conflicts:
	library/PolyVoxCore/include/PolyVoxCore/DefaultIsQuadNeeded.h
2014-02-25 16:35:54 +01:00
Daviw Williams
0e8973e722 Fixed minor compile errors:
- Lack of <functional> in AStarPathfinder.h
 - Lack of <cstdint> in several files (why did this compile on GCC?)
2014-02-17 15:23:44 +01:00
Matt Williams
bc17c802bb Assume C++11 support
Remove all CMake checks for C++11 support since we now assume that we have it.
Replace all polyvox_* macros with standard C++ names.

See #48
2014-02-14 15:03:26 +00:00
David Williams
376ce595d6 Merge branch 'develop' into feature/cubiquity-version 2014-01-31 21:20:04 +01:00
David Williams
74be82e8cf Disabled trace stream by default.
Updated docs.
2014-01-30 23:40:50 +01:00
David Williams
f2dd852bd2 More stripping down of logging macros. 2014-01-30 23:18:41 +01:00
David Williams
906d685f5f Stripped down the 'removed' version of the logging macros to minimize the chance that they have any effect on the code. 2014-01-30 23:04:37 +01:00
David Williams
248a5c3e29 Removed old logging system. 2014-01-30 22:10:52 +01:00
Daviw Williams
109bfb7e9e Merge branch 'develop' into feature/cubiquity-version 2014-01-30 16:30:21 +01:00
Daviw Williams
af9eacef37 Changed new logging system to work on strings rather than streams. 2014-01-30 16:27:33 +01:00
David Williams
2955b35743 Merge branch 'develop' into feature/cubiquity-version 2014-01-29 21:31:36 +01:00
David Williams
f4e03cc537 Macros now call new logging system instead of the old one. 2014-01-29 21:29:00 +01:00
Daviw Williams
84921f4d0b The existing logging code is rather large and overwhelming. I'm starting to replace it with a simpler system that should also be easier to maintain. 2014-01-29 16:53:11 +01:00
David Williams
20576d7a6f Merge branch 'develop' into feature/cubiquity-version
Conflicts:
	library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl
2014-01-28 23:39:22 +01:00
David Williams
2ae5667986 Replaced some more logging commands with macros which can be compiled out. 2014-01-28 23:15:24 +01:00
David Williams
4c29d59430 Merge branch 'develop' of https://bitbucket.org/volumesoffun/polyvox into develop 2014-01-28 21:00:26 +01:00
David Williams
e0e860c45c Added <algorithm> 2014-01-28 20:59:55 +01:00
Matt Williams
832a45013a Simplify test creation and add XML output option 2014-01-27 19:39:50 +00:00
David Williams
a9238051fa Changed some logging statements to macros which can be #defined out. 2014-01-26 23:53:10 +01:00
David Williams
52e25f2b3d Merge branch 'develop' into feature/cubiquity-version 2014-01-26 21:34:46 +01:00
Daviw Williams
f58161c748 Added logging macros which can be disabled at compile time. 2014-01-24 16:35:58 +01:00
Daviw Williams
c177891e5d Separated logging code into different .cpp/.h files. 2014-01-24 15:21:59 +01:00
Daviw Williams
8d5f6af7cd Compile fix for VS2012, which now builds successfully. 2014-01-24 13:53:44 +01:00
David Williams
d96dcaa531 Another Mac/Clang fix. 2013-12-31 14:53:53 +01:00
David Williams
1cb486cb33 Fixed Clang detection. 2013-12-31 11:19:00 +01:00
Daviw Williams
31b59702be We're committed to LargeVolume now, so we don't need the define to switch volume types. 2013-11-18 16:57:37 +01:00
Daviw Williams
15b170696c Merge branch 'develop' into feature/cubiquity-version 2013-11-14 15:36:25 +01:00
Daviw Williams
3db5e1b2f6 Added microsecond precision to timers. 2013-11-14 15:35:41 +01:00
Daviw Williams
f2ecb667e8 Merge branch 'develop' into feature/cubiquity-version 2013-11-13 15:24:21 +01:00
Daviw Williams
5294efc473 Clear the 'last accessed block' flag before flushing the volume. 2013-11-12 16:57:11 +01:00
Daviw Williams
85d8bdb30c Rearranged some code to try and improve the robustness of block paging and compression. 2013-11-12 16:47:57 +01:00
Daviw Williams
1c5a3f7ef5 Reverted attempts to suppress GCC warnings and just removed the offending asserts instead.
Revert "Added asserts to catch invalid material/density values."

This reverts commit 89438220464778d167d86bb59e095a85ccdba080.
2013-10-25 12:44:40 +02:00
Daviw Williams
2d6bb91d96 Merge branch 'develop' into feature/cubiquity-version 2013-10-24 16:50:38 +02:00
Daviw Williams
afddb59d69 Reverted attempt to avoid warnings. Just suppressed them instead.
Revert "Attempting to work around a GCC warning."

This reverts commit 3fe92086f1bdde06eb3e9bd812fc19a279154458.
2013-10-24 14:37:18 +02:00
Daviw Williams
3fe92086f1 Attempting to work around a GCC warning. 2013-10-23 16:33:42 +02:00
David Williams
8943822046 Added asserts to catch invalid material/density values. 2013-10-20 09:12:37 +02:00
Daviw Williams
8a07d93b54 Merge branch 'develop' into feature/cubiquity-version 2013-10-04 13:57:03 +02:00
Daviw Williams
29bded222f Removed unnecessary error handling. 2013-10-04 13:56:31 +02:00
David Williams
21001d6862 Removed wrapper for class which was removed. 2013-10-04 13:35:31 +02:00
David Williams
1531e1cd00 Switched some code to size_t for compatibility with Miniz. 2013-10-04 13:30:30 +02:00
Daviw Williams
4d683627da Added some comments. 2013-10-03 16:56:14 +02:00
Daviw Williams
d17c1b404b Bit more tidying of Miniz code. 2013-10-03 16:45:46 +02:00
Daviw Williams
ef615cc838 Added missing file. 2013-10-03 16:26:43 +02:00
Daviw Williams
dcea5ccc54 Merge branch 'feature/miniz-fixes' into develop 2013-10-02 16:58:48 +02:00
Daviw Williams
498f21f63f Replaced arrays with std::vector. 2013-10-02 16:48:30 +02:00
Daviw Williams
a4e09c2481 Small fixes (including crash fix). 2013-10-02 15:36:21 +02:00
Daviw Williams
29ca1e763f Renamed functions to avoid confusion. 2013-10-02 15:09:55 +02:00
Daviw Williams
513c3a90b0 Rearranging some miniz code to simplify it a bit. 2013-10-01 16:33:39 +02:00
Daviw Williams
319a0ce352 Removed old compression classes. 2013-10-01 15:58:32 +02:00
Daviw Williams
f63bb510b3 Merged some code from MinizCompressor into MinizBlockCompressor. We don't really need two separate classes for this stuff. 2013-10-01 15:51:23 +02:00
Daviw Williams
4ee2a61a15 Added a siply wrapper .h/cpp pair to abstract away the fact that miniz in provided as a single .c file which we include directly, and to avoid linker problems. 2013-10-01 15:33:40 +02:00
Matt Williams
f81b42747b Implement Timer for C++11
This uses std::chrono::system_clock
2013-08-22 20:40:45 +01:00
David Williams
886c66d7c3 Merge branch 'develop' into feature/cubiquity-version 2013-08-19 16:28:23 +02:00
David Williams
55dc066a3f Fixed bug with MinizBlockCompressor always saving out 10,000 bytes of data. 2013-08-19 16:27:52 +02:00
David Williams
61e957314f Merge branch 'develop' into feature/cubiquity-version 2013-08-12 21:06:33 +02:00
David Williams
07f1ca42d2 Uncompressed blocks are now flushed before compressed blocks. 2013-08-12 21:04:55 +02:00
David Williams
6fb30a40f5 Bringing across Region enhancements from Cubiquity branch. 2013-08-09 20:39:17 +02:00
David Williams
fcf5b2b055 Making Cubiquity version of PolyVox more closely match develop version. 2013-08-09 20:32:20 +02:00
David Williams
6a009825b5 Merge branch 'develop' into feature/cubiquity-version
Conflicts:
	library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl
	library/PolyVoxCore/source/Region.cpp
2013-08-09 17:05:57 +02:00
David Williams
b9546ddcfa Extra checks in during marching cubes to try and catch corrupt data. 2013-08-09 14:09:59 +02:00
Matt Williams
7c74e1faff Move Timer.h to correct location
Also add a missing semi-colon.
2013-08-08 10:42:57 +01:00
David Williams
2f99964606 Tidying timer. 2013-08-07 23:24:20 +02:00
David Williams
9ad4c3fcf7 Initial checkin of Timer class. 2013-08-07 23:07:26 +02:00
David Williams
a308102585 VS2012 compile warning fix. 2013-08-07 14:53:08 +02:00
David Williams
acf5bef5e7 Merge branch 'feature/large-volume-tidying' into develop 2013-08-01 16:34:38 +02:00
David Williams
e485265dd8 Fixes to allow the SWIG/Python bindings to build again. 2013-08-01 16:08:44 +02:00
David Williams
dcf86a905c Split Block, CompressedBlock and UncompressedBlock into separate files. It's tidier, and maybe better for SWIG? 2013-08-01 15:32:12 +02:00
David Williams
6f17e0faa6 The 'Block' class is no longer considered just to be an implementation details of LargeVolume. Users may need to interact with them directly of they implement their own paging or compression systems. 2013-08-01 15:19:10 +02:00
David Williams
9503d975c1 GCC compile fixes. 2013-07-31 16:37:39 +02:00
David Williams
e35b58ba18 Fixed paging example. 2013-07-31 15:49:00 +02:00
David Williams
4478e365c9 Removed RLECompressor as the code is now in RLEBlockCompressor.
Things are starting to get back under control. All tests pass, and all examples except PagingExample work.
2013-07-30 17:01:27 +02:00
David Williams
fa8813ba86 FilePager now cleans up after itself. 2013-07-30 16:34:40 +02:00
David Williams
d1138dcdb1 Some new block compression code as I rework the previous code... 2013-07-30 16:01:03 +02:00
David Williams
020ac9655a Added random prefix to filename to prevent name conflicts. 2013-07-30 15:42:51 +02:00
David Williams
a4fc814a51 Rearranging and renaming some code. 2013-07-29 16:04:01 +02:00
David Williams
00fab818cc Added define to switch between SimpleVolume and LargeVolume in Cubiquity. This is an abuse of Typedef.h but it's a convenient location and just for temporary testing purposes. It won't get merged back into PolyVox. 2013-07-28 16:45:08 +02:00
David Williams
0c8013317e Added asserts to catch corrupt data probably resulting from multithreading. 2013-07-28 16:43:43 +02:00
David Williams
a10fcf8ecc Small changes for debugging Cubiquity. 2013-07-27 15:02:16 +02:00
David Williams
ef59f329b6 Reorganising compression code. 2013-07-26 16:25:50 +02:00
David Williams
f54532a905 Started moving compression code into separate class. 2013-07-26 16:00:29 +02:00
David Williams
c3c4ead1f3 Work on paging to files. 2013-07-26 15:38:03 +02:00
David Williams
b767d9b896 Tidying up. 2013-07-25 17:07:50 +02:00
David Williams
f4f85551c6 Starting some refactoring of the LargeVolume such that the uncompressed blocks are the 'main' representation, rather than the compressed block being the main version and the uncompressed blocks simply being a cached version. I hope this simplifies and improves the code. 2013-07-25 15:51:30 +02:00
David Williams
cf9b54e5ab Properly deleting data (delete vs. delete[]). 2013-07-24 16:53:40 +02:00
David Williams
b07dafc9fa Added code to initilise empty compressed blocks. 2013-07-24 16:39:31 +02:00
David Williams
69066a068e Implemented flushExcessiveCacheEntries() 2013-07-23 13:48:04 +02:00
David Williams
7c11a53484 Fixed flushOldestExcessiveBlocks(). 2013-07-23 13:31:24 +02:00
David Williams
7146b5ecdb The idea of a 'setTargetMemoryLimitInBytes' function was not really working out. It was too comp-lex and not really clear what the ideal size would be. I think user code needs to call setMaxNumberOfBlocksInMemory() and setMaxNumberOfUncompressedBlocks() directly, if they see from profiling toat too much camressing or paging is taking place. 2013-07-23 13:15:01 +02:00
Matt Williams
7ee913c8a8 Fix the SWIG warning in the SWIG interface files
This keeps the .cpp and .h files clean.
2013-07-22 16:10:31 +01:00
David Williams
3971e6415c Added SWIG tests to stop build warning about operator<<. 2013-07-22 16:37:35 +02:00
Matt Williams
63dfaa5a13 Enable C# bindings even if Python wasn't found. 2013-07-21 10:31:24 +01:00
David Williams
7cd115b33d Work on code which computes how the memory should be split between compressed and uncompressed data. 2013-07-19 16:43:59 +02:00
David Williams
ef6bd31651 Small fixes. 2013-07-18 17:03:14 +02:00
David Williams
88cbeb309c Reimplemented eraseBlock for uncompressed blocks. 2013-07-18 16:08:18 +02:00
David Williams
1e986f9aa6 Reimplemented eraseBlock for compressed blocks. 2013-07-17 17:00:12 +02:00
David Williams
404f12a43e Added typedefs to simplify code. 2013-07-17 16:33:46 +02:00
David Williams
5b99854c02 Making block copy constructors and assignment operators private to prevent accidental copying. 2013-07-17 16:23:46 +02:00
David Williams
dea7e6a4e9 Tidying up block classes. 2013-07-16 16:50:04 +02:00
David Williams
b5d930062b Const fixes. 2013-07-16 16:09:57 +02:00
David Williams
3904c9aa8f Tidying and renaming... 2013-07-16 15:59:06 +02:00
David Williams
0cfb9f5196 Splitting 'Block into CompressedBlock and UncompressedBlock. 2013-07-16 14:42:43 +02:00
David Williams
2acb98bdcb Compile warning fixes. 2013-07-16 11:50:59 +02:00
David Williams
a00574351f Renamed Block to CompressedBlock 2013-07-11 16:38:28 +02:00
David Williams
00eb281990 Stripping down Block class. 2013-07-11 16:30:19 +02:00
David Williams
0d92bc6c8c Starting to split Block class into CompressedBlock and UncompressedBlock. 2013-07-11 16:17:48 +02:00
David Williams
9ff95f7061 Minor fixes. 2013-07-11 15:55:34 +02:00
David Williams
e6cbc09e83 getUncompressedBlock now return raw pointer instead of block pointer. 2013-07-11 15:30:15 +02:00
David Williams
884fe04c12 Tidying up... 2013-07-11 15:01:18 +02:00
David Williams
abd1920d80 Adding new caching mechanism. 2013-07-11 14:50:06 +02:00
David Williams
a589c6e4ac Split come code into getCompressedBlock() function. 2013-07-11 14:26:38 +02:00
Daviw Williams
056064409d Work on LargeVolume. 2013-07-05 16:07:38 +02:00
Daviw Williams
0c55938242 Work on the code that frees up memory in LargeVolume. 2013-07-05 15:41:16 +02:00
Matt Williams
2f2475ad0c Avoid ambiguous function resolution of getVoxelImpl
Clang was complaining that the function couldn't access the *Volumes*'s
``getVoxelImpl``. Since we actually want the ``BaseVolume::Sampler``'s
version this solves the problem.
2013-07-04 22:05:06 +01:00
Matt Williams
8027f9904d On systems that support it, raise SIGTRAP to drop into the debugger
Clang was being clever and giving a warning for this line so it prompted me
to fix it. I believe that SIGTRAP is the correct way to get the debugger to
work here.

It does a compile-time check for the platform when not using MSVC.

Discussed at http://www.volumesoffun.com/phpBB3/viewtopic.php?p=3766#p3766
2013-07-04 19:35:09 +01:00
Matt Williams
9f7f893b68 Change the types of the edgeTable and triTable
The range on values in these tables is much less than needs an int so
making them specific width types packs them smaller.

I measure a 5% decrease in the size of the .so file created at -O3.
2013-07-04 19:35:09 +01:00
Daviw Williams
bd60f34bd7 Removing explicit functions to control the number of compressed and uncompressed blocks in memory, and letting the user set a memory limit instead. 2013-07-04 16:23:58 +02:00
Daviw Williams
26f512eba7 Fixed compile warning. 2013-07-02 16:08:52 +02:00
Matt Williams
c843e7e705 Remove unnecessary consts.
Since a copy is being made in the return, the const qualifiers are
ignored anyway.
2013-07-01 12:23:21 +01:00
David Williams
aab1149e8f Merge branch 'develop' into feature/cubiquity-version 2013-06-28 20:26:25 +02:00
Matt Williams
edf1f5d665 Fix compile error caused by missing #include. 2013-06-28 16:47:02 +01:00
Daviw Williams
059a4b9465 Reverted accidental commit of test code. 2013-06-28 16:58:31 +02:00
Daviw Williams
e38aa3b1b9 Unit tests now test FilePager. 2013-06-28 16:16:08 +02:00
David Williams
839f366174 Compile fixes for Linux.
Added SWIG files to make bindings build.
2013-06-28 15:07:19 +02:00
David Williams
7cad8388b9 Merge branch 'develop' into feature/cubiquity-version
Conflicts:
	library/PolyVoxCore/include/PolyVoxCore/Region.h
	library/PolyVoxCore/source/Region.cpp
2013-06-27 21:40:10 +02:00
Daviw Williams
0d839c4a51 Merge branch 'feature/paging' into develop 2013-06-27 16:49:32 +02:00
Daviw Williams
f3ec94dd75 Reverted changes made for testing. 2013-06-27 16:43:49 +02:00
Daviw Williams
97a501e3da Updated changelog. 2013-06-27 16:41:24 +02:00
David Williams
72b3cd5154 Tidying up and comments. 2013-06-26 23:39:21 +02:00
David Williams
885a50e781 Merge branch 'develop' into feature/paging 2013-06-26 22:49:36 +02:00
David Williams
56cf423bfd Added POLYVOX_THROW_IF macro to simplify error handling. 2013-06-26 22:39:15 +02:00
David Williams
1064ea1c47 Stripped out unused code. 2013-06-26 22:14:01 +02:00
David Williams
acb43d54d9 Fixed paging example. 2013-06-26 22:08:49 +02:00
David Williams
938eea7c8e Work on tidying LargeVolume... 2013-06-26 22:01:44 +02:00
Daviw Williams
44d525f591 Tidying up and refactoring LargeVolume. 2013-06-26 17:02:06 +02:00
David Williams
8ab6d73f0a Work on LargeVolume refactoring - getting FilePager working. 2013-06-25 23:34:58 +02:00
David Williams
0cf3de4e76 Removed LoadedBlock and put timestamp into regular Block. 2013-06-25 22:54:40 +02:00
David Williams
900e4e0ecd Refactoring some LargeVolume code... 2013-06-25 21:18:06 +02:00
David Williams
a2210fc3f0 Renamed compress and uncompress functions. 2013-06-25 20:57:50 +02:00
Daviw Williams
6b92a5ab51 More tidying/refaxctoring of Block class. 2013-06-25 17:04:10 +02:00
Daviw Williams
baed7ddccc Tidying up and refactoring of block class. 2013-06-25 16:45:53 +02:00
Daviw Williams
c346d19d77 Doing some tidying in the Block class. 2013-06-25 16:20:58 +02:00
David Williams
59505d47e9 Tidying up Block and FilePager. 2013-06-23 23:17:40 +02:00
David Williams
e80fa3de7d Added functions for accessing compressed data in block. 2013-06-22 12:16:52 +02:00
David Williams
785ac611b9 Work on file paging. 2013-06-22 11:20:05 +02:00
David Williams
5643140882 Work on paging to file. 2013-06-22 11:19:30 +02:00
David Williams
d9ebe96c5a Work on FilePager. 2013-06-22 10:16:33 +02:00
David Williams
288b448b9f Brought across Region operator<< from Cubiquity branch. 2013-06-22 10:16:16 +02:00
David Williams
77a340f2b3 ErrorHandling.rst edited online with Bitbucket
The was an extra bracket in the documentation.
2013-06-22 08:02:07 +00:00
David Williams
5664e2f681 Restored Paging Example back to previous values. 2013-06-22 07:30:06 +02:00
David Williams
20db75fb75 Added null pointer check.
Added files to CMakeLists.txt
2013-06-22 07:24:19 +02:00
David Williams
51f9898467 Reenabled unused vertex removal. 2013-06-22 06:32:26 +02:00
David Williams
6781462b59 More formatting fixes. 2013-06-17 11:19:36 +02:00
David Williams
3e1539fc62 Fixed some formatting. 2013-06-17 11:16:59 +02:00
David Williams
a14de4a72e Replaced std::functions with Pager class for paging. 2013-06-16 19:48:14 +02:00
David Williams
414a012230 Creating a Perlin noise generator as a 'pager'. 2013-06-16 19:12:37 +02:00
David Williams
f86ec57e14 Adding skeletons of new paging classes. 2013-06-16 18:25:20 +02:00
David Williams
42ce6ace77 Updated change log. 2013-06-16 17:56:07 +02:00
David Williams
a1d773f5e7 Added documentation on voxel access. 2013-06-16 17:22:53 +02:00
Daviw Williams
c91b10ce73 Merge branch 'feature/bounds-checks' into develop 2013-06-13 17:04:55 +02:00
Daviw Williams
1e55859107 Renamed WrapMode::None (and others) to avoid conflict with Python reserved word 'None'. 2013-06-13 16:49:02 +02:00
Daviw Williams
dc7c7eb552 Removed old BoundsCheck enum. 2013-06-13 16:27:46 +02:00
Daviw Williams
6e8030f4b5 Changes to hopefully fix Linux compile problems. 2013-06-13 15:55:15 +02:00
Daviw Williams
62f273bd74 Small changes, hoping to help the Linux version compile. 2013-06-12 16:52:17 +02:00
David Williams
0a4ffc2351 Linux compile fixes. 2013-06-12 16:38:27 +02:00
Daviw Williams
28f81a8ae1 Replaced call to getVoxelAt with getVoxel. 2013-06-12 15:57:51 +02:00
Daviw Williams
2f62a7de8d Marked getVoxelAt functions as deprecated. 2013-06-12 15:51:06 +02:00
Daviw Williams
27833ee03f Fixed compiler warnings. 2013-06-12 15:45:57 +02:00
Daviw Williams
3249562d97 Removing more calls to getVoxelAt()... 2013-06-12 15:41:45 +02:00
Daviw Williams
efb6d12fc8 Eliminated dome calls to getVoxelAt. 2013-06-12 15:22:21 +02:00
Daviw Williams
45af7a4246 Removed some getVoxelAt() calls in tests. 2013-06-12 15:11:45 +02:00
Daviw Williams
3a9b393459 Renamed getVoxelAt in volume samplers to avoid confusion with the version in volumes. 2013-06-12 15:10:14 +02:00
Daviw Williams
7276b872c4 More work replacing getVoxelAt with getVoxel. 2013-06-12 15:03:34 +02:00
Daviw Williams
60d6658e1a Changed a couple of 'getVoxelAt()' to 'getVoxel()'. 2013-06-12 13:38:36 +02:00
Daviw Williams
1f2b7e4742 Added modified setVoxel functions to SimpleVolume and LargeVolume. 2013-06-07 16:57:45 +02:00
Daviw Williams
d98856b276 setVoxel for RawVolume now takes WrapMode instead of bounds check. 2013-06-07 16:49:06 +02:00
Daviw Williams
292b21dcdf Added merging of BoundsCheck and WrapMode changes into LargeVolume. 2013-06-07 16:13:11 +02:00
Daviw Williams
3d82b9643f Applied BoundsCheck and WrapMode merging changes to SimpleVolume. 2013-06-07 15:58:24 +02:00
Daviw Williams
8ed5edf85f Documentation fix. 2013-06-07 15:47:21 +02:00
Daviw Williams
900b693e25 More work combining BoundsCheck with WrapMode. 2013-06-07 15:43:35 +02:00
Daviw Williams
745f24eab8 More work on wrap modes. 2013-06-06 16:39:49 +02:00
Daviw Williams
6bc379f0df More work combining WrapMode and BoundsCheck 2013-06-06 16:26:55 +02:00
Daviw Williams
2b03e84f83 Combining BoundsChecks and WrapMode into a single enum. 2013-06-06 16:07:47 +02:00
Daviw Williams
073c415a38 Work on new getVoxel() functions. 2013-05-29 16:07:27 +02:00
Daviw Williams
de8c69456f Added macro to throw an exception but not log it. Useful in some high-performance scenarios. 2013-05-27 15:09:43 +02:00
Daviw Williams
0c7002a1ce Avoided double bounds check. 2013-05-27 14:24:52 +02:00
Daviw Williams
869f5f6c49 Added function to check whether one region is inside of another. 2013-05-27 14:01:55 +02:00
Daviw Williams
61dd59c9bc Merge branch 'develop' into feature/bounds-checks 2013-05-27 13:00:02 +02:00
Daviw Williams
a56005478d Fix for Linux compile error. 2013-05-27 12:59:19 +02:00
Daviw Williams
dd7be8e7c3 Merge branch 'develop' into feature/cubiquity-version 2013-05-24 16:52:04 +02:00
Daviw Williams
d34ff02b0b Updated documentation on error handling. 2013-05-24 16:31:36 +02:00
Daviw Williams
60205425db Fixed warning about unreachable code. 2013-05-24 16:18:02 +02:00
Daviw Williams
2b3e9ca206 Merge branch 'develop' into feature/cubiquity-version 2013-05-24 16:01:11 +02:00
Daviw Williams
d12a81d345 Log messages now automatically have std::endl applied, and work/behave similar to Qt logging functions. 2013-05-24 16:00:19 +02:00
Daviw Williams
fcb38f0796 Merge branch 'develop' into feature/cubiquity-version 2013-05-24 13:52:21 +02:00
Daviw Williams
c1461e7582 Added a null stream to suppress logging. 2013-05-24 13:51:52 +02:00
Daviw Williams
d7d3df2197 Merge branch 'develop' into feature/cubiquity-version 2013-05-24 13:30:04 +02:00
Daviw Williams
b12e6d045c Added additional logging streams. 2013-05-24 13:26:26 +02:00
Daviw Williams
b50d3a299b Merge branch 'develop' into feature/cubiquity-version
Conflicts:
	library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h
	library/PolyVoxCore/source/Impl/ErrorHandling.cpp
2013-05-22 15:38:16 +02:00
Daviw Williams
6c77e778dd Added namespace qualifiers. 2013-05-22 15:18:08 +02:00
Daviw Williams
f3b0183013 Switching to a stream-based interface for logging. 2013-05-22 14:21:50 +02:00
Daviw Williams
efd4878450 Updated documentation. 2013-05-17 16:44:32 +02:00
Daviw Williams
ea4d6d3168 Added setVoxel() functions to replace setVoxelAt() functions in the same way that getVoxel() replaces getVoxelAt(). 2013-05-17 16:36:04 +02:00
Daviw Williams
fa8e7c390f replaced 'getVoxelWithWrapping()' with regular 'getVoxel()', as they can be differentiated by their parameters. 2013-05-17 15:52:18 +02:00
Daviw Williams
4765390ef6 Replaced bool parameter with 'BoundsCheck' parameter for a nicer API. 2013-05-17 14:51:14 +02:00
Daviw Williams
617834bed4 Made getVoxel() bounds checking optional, based on a function parameter. 2013-05-17 14:32:20 +02:00
Daviw Williams
db1c2bf0f8 Replaced 'code-block' with 'sourcecode'. 2013-05-16 16:19:38 +02:00
Daviw Williams
c806da9bb7 Compile fixes brought across from Cubiquity. 2013-05-16 16:17:01 +02:00
Daviw Williams
618b09df46 Fixed compile errors. 2013-05-16 16:14:05 +02:00
Daviw Williams
fa29a83ebd Merge branch 'develop' into feature/cubiquity-version 2013-05-16 16:06:53 +02:00
Daviw Williams
9fa0cc8a2a Updated error handling documentation. 2013-05-16 11:12:27 +02:00
David Williams
7d0fc3e3d2 ErrorHandling.rst edited online with Bitbucket: It seems we need to use 'sourcecode' rather than 'code-block' to make the code show up in the BitBucket preview. 2013-05-16 08:43:43 +00:00
David Williams
afd5f0efc6 ErrorHandling.rst edited online with Bitbucket - Just a test commit to see if code copy-and-pastedfrom the BitBucket docs actually shows up in the user manual. 2013-05-16 08:37:50 +00:00
David Williams
2010b46709 ErrorHandling.rst edited online with Bitbucket: Trying to fix syntax highlighting in user manual. 2013-05-16 08:35:00 +00:00
Daviw Williams
2203e30f39 Added documentation on error handling.
Default log handler now suppresses LogLevels::Debug messages.
2013-05-15 17:01:57 +02:00
Daviw Williams
a1355f6d50 More work on improved logging. 2013-05-15 15:55:39 +02:00
Daviw Williams
1010052ea6 Reworking the logging system. 2013-05-14 16:52:16 +02:00
Daviw Williams
e405b46b61 Removed the default value for emptyVoxelExample as it caused compile errors on VS2010. 2013-05-14 15:44:56 +02:00
David Williams
ee299a45f0 Work on error handling. I replaced some asserts with exceptions and also added basic error handling documentation. 2013-05-11 10:05:08 +02:00
Matt Williams
62d164ef8a Remove unnecessary assignment. 2013-05-10 09:44:15 +01:00
Matt Williams
edd2aecea2 Merge branch 'feature/raycast' into develop
Add a pickVoxel function. This closes issue #22.
2013-05-09 21:03:14 +01:00
Matt Williams
22a6714875 Add a default constructor to PickResult to avoid brittle instatiation. 2013-05-09 20:56:10 +01:00
Daviw Williams
2a839e583d Added stream serialisation to Region. 2013-05-07 15:41:26 +02:00
Matt Williams
f98959f92a Add a new pickVoxel function.
Hopefully this pickVoxel function will fulfil most most need with
raycasting which aren't covered by the existing raycast functions.

It's essentially a wrapper around the current functions, using a custom
functor to store the position of a solid voxel as well as the previous
empty voxel. It doesn't require the user to provide a functor of their own,
just the value that they've assigned to empty voxels.

As well as the function itself, we also have a unit test as well as it
being built in the bindings.
2013-05-01 22:28:46 +01:00
Matt Williams
cb808ab593 Update copyright year for manual 2013-04-21 17:17:08 +01:00
Matt Williams
cc430ae129 Update Python bindings, tests and example to use Python 3 2013-04-17 20:48:15 +01:00
Matt Williams
60826b4c85 Add documentation and a tutorial for the Python bindings
This should cover most questions about the Python bindings but of course,
some things in the bindings is still subject to change.
2013-04-16 23:18:16 +01:00
Matt Williams
7473cd4458 Slightly simplify the Python code in the example
This is in preparation for the Python bindings manual chapter I'm writing
at the moment.
2013-04-16 23:00:06 +01:00
Daviw Williams
1d643becc5 Replaced std::exit with a crash. 2013-03-27 15:21:38 +01:00
Daviw Williams
055539ef75 Reenabled exceptions as we're not using Cubiquity on mobile at the moment. 2013-03-26 11:45:53 +01:00
David Williams
5eedb9f21c Merge branch 'develop' into feature/cubiquity-version
Conflicts:
	library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h
	library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h
2013-03-04 22:11:19 +01:00
David Williams
5cab70b24c Fixed code to use proper zero initialisation. 2013-03-04 22:01:43 +01:00
David Williams
fcdb175f1c Merge branch 'develop' into feature/cubiquity-version
Conflicts:
	library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h
	library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl
2013-03-04 21:05:51 +01:00
Daviw Williams
6374ebf092 Apparently I didn't test my fix for warning 4127 because it didn't actually work. Now fixed :-) 2013-03-04 17:10:23 +01:00
Daviw Williams
23042c3fcb Moved warning suppression into the relevant file so that it's not global. 2013-03-04 16:00:43 +01:00
Daviw Williams
df5c339f64 Just remembered that we settled on a different formatting for the API docs so that it gets highlighted better in KDE. 2013-03-04 15:36:11 +01:00
Daviw Williams
b4fcb3daf8 Added API documentation regarding compression. 2013-03-04 15:17:19 +01:00
Daviw Williams
74b4caba6b Added some API docs to compressor. 2013-03-01 17:06:51 +01:00
Daviw Williams
d12db9906f Updated note about why we #include the miniz.c file. 2013-03-01 16:33:31 +01:00
David Williams
a7e49a1394 Still trying to get rid of the warnings on the CDash machine. It's tricky because I'm not seeing the locally and the warning supression seems to vary bewteen vesions of GCC (See: http://dbp-consulting.com/tutorials/SuppressingGCCWarnings.html). 2013-03-01 16:07:50 +01:00
David Williams
c28fa9a0ca It seems that GCC 4.3.5 (on the CDash machine) doesn't recognise ignoring the 'enum-compare' warning. This commit should switch of all warnings instead (just for this file). 2013-02-28 13:42:02 +01:00
David Williams
4534f721b5 A one line change for testing purposes. I'm curious whether another addition commit gets pushed. 2013-02-27 15:07:52 +01:00
David Williams
7e50dcbd93 It seems push/pop of diagnostic pragmas is only supported on GCC >= 4.6. I've just disabled the warning for the whole file instead. 2013-02-27 14:25:10 +01:00
David Williams
9ec2ebd78c Merge branch 'develop' of https://DavidWilliams@bitbucket.org/volumesoffun/polyvox.git into develop 2013-02-27 12:40:34 +01:00
Daviw Williams
80025eaa46 Attempting to disable GCC compiler warnings in miniz.c (as I don't want to modify external code). 2013-02-26 10:49:01 +01:00
Daviw Williams
62370868c8 Reverted accidental changes to tests.
Updated comments in compression code.
2013-02-25 17:06:12 +01:00
Daviw Williams
c42270f165 Possible Linux fix? I didn't reproduce the error myself so I'm just being guided by the CDash messages. 2013-02-25 16:51:57 +01:00
Daviw Williams
e770baeb05 Added assert for buffer size. 2013-02-25 16:46:04 +01:00
Daviw Williams
f70498e806 Removed old code. 2013-02-25 16:34:21 +01:00
Daviw Williams
34671130fb Tidying up Miniz compression code. 2013-02-25 16:33:39 +01:00
Daviw Williams
81eab0ebfb Work on low-level version of compression. 2013-02-22 17:03:47 +01:00
Daviw Williams
eb8ace0c54 Replaced high level miniz interface with low-level version. 2013-02-21 16:56:57 +01:00
Daviw Williams
1a39577ec0 CubicSurfaceExtractor now uses int for some internal work instead of floats. 2013-02-21 16:44:44 +01:00
David Williams
f517137991 Performance improvements brought across from develop. 2013-02-08 22:19:02 +01:00
David Williams
328d40f712 Merge branch 'develop' into feature/cubiquity-version
Conflicts:
	library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl
	library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl
2013-02-08 21:46:33 +01:00
Daviw Williams
b7eeda3370 Find and replace all instance of getLowerCorner().getX(), etc with getLowerX(), etc has resulted in all tests now running in 120 seconds instead of 144 seconds because it avoids creating temporary objects. 2013-02-08 16:15:53 +01:00
Daviw Williams
6bf9105e56 Merge branch 'develop' of https://bitbucket.org/volumesoffun/polyvox into develop 2013-02-08 15:44:35 +01:00
Daviw Williams
7327220b1c Performance enhancements identified through profiling. 2013-02-08 15:43:37 +01:00
Matt Williams
66bdf0e5a9 Add Compressor and subclasses to the bindings
This relates to issue 20 and should fix the compilation error mentioned
there.
2013-02-08 14:27:11 +00:00
Daviw Williams
608777bb9b Performance improvements for CubicSurfaceExtractor 2013-02-08 15:14:15 +01:00
Daviw Williams
7e08ed7aec Updated the CubicSurfaceExtractor test to make it a bit more performance intensive, Cubiquity is showing a need for some improvements here. Also added a performance improvement to the CubicsurfaceExtractor. 2013-02-08 15:05:45 +01:00
Daviw Williams
c5023ff623 Changed void* to uint8_t*. 2013-02-08 13:29:49 +01:00
David Williams
a38ac6b895 Merge branch 'develop' into feature/cubiquity-version 2013-02-07 23:02:23 +01:00
Daviw Williams
c3801db4e2 Set tests to use MinizCompressor. 2013-02-07 16:20:05 +01:00
Daviw Williams
e4f1a5f0ce Merge branch 'feature/large-volume-work' into develop 2013-02-07 16:17:03 +01:00
Daviw Williams
36968bdd79 Merge branch 'develop' into feature/large-volume-work 2013-02-07 16:11:03 +01:00
Daviw Williams
687dbe40cb Updated Changelog and credits. 2013-02-07 16:06:46 +01:00
Daviw Williams
50c1c7c64b Removed setCompressionEnabled() from LargeVolume. 2013-02-07 15:55:10 +01:00
Daviw Williams
8d2061bdb5 Fixed crash with MaxVerticesPerPosition being set too low. 2013-02-04 16:38:50 +01:00
David Williams
aef5373e8b Fixed case problem in folder name. 2013-02-01 16:37:13 +01:00
Daviw Williams
09c6e2bf26 More work making the compression more robust. 2013-02-01 16:10:10 +01:00
Daviw Williams
a5b768e5f9 Working to make compression handing more robust. 2013-02-01 15:43:20 +01:00
Daviw Williams
3d66db50e0 Fixes and comments for RLE compression. 2013-02-01 14:09:29 +01:00
David Williams
dadcf03d8d Added note. 2013-01-31 21:04:01 +01:00
Daviw Williams
46e38c4714 Work on compression. 2013-01-31 16:56:32 +01:00
Daviw Williams
a81ec68714 Work on compression interface. 2013-01-31 16:35:50 +01:00
Daviw Williams
36676433be Work on compression interface. 2013-01-31 15:54:04 +01:00
Daviw Williams
924744c5e6 Looks like RLECompressor works as well. 2013-01-30 16:58:13 +01:00
Daviw Williams
a1cdf78250 Block now working with new MinizCompressor. Removing some old compression code. 2013-01-30 16:49:06 +01:00
Daviw Williams
804a766037 Added my two new compressor classes - one based on Miniz and the other based on RLE. 2013-01-30 16:04:47 +01:00
David Williams
f76be64d6b Work on VolumeResampler (using real convolution). 2013-01-27 22:02:13 +01:00
David Williams
d3aed35d81 Added some (temporary) interpolation code. 2013-01-27 13:03:30 +01:00
Matt Williams
8ad0cae89a Add an example which uses the Python bindings
This is more or less a copy of the BasicExample but using ever so slightly more
modern OpenGL (>=3.0). I've tried to comment this as much as possible.

In addition to this simple example I will go on to develop a more complex
application as discussed in issue #21
2013-01-19 14:24:10 +00:00
Matt Williams
d50e9dfebc Start enabling the CubicSurfaceExtractors 2013-01-19 14:19:26 +00:00
David Williams
4df159dfd7 Changed volume sampler wrap mode. 2013-01-17 23:51:52 +01:00
Matt Williams
6e93048c9f Add a test for C#
This test is not actually run yet but it serves as an example of how to use
the C# bindings.
2013-01-16 15:31:52 +00:00
Matt Williams
bab3c32ec5 Wrap the Vector operators for C#
This should allow all the normal vector operations as well as silence the
warnings from SWIG.
2013-01-16 15:30:22 +00:00
Matt Williams
e90215b0fc These names only make sense for Python
In future, it might make sense to use these names as the intermediate names
for C# and Java too but for now, keep them separate.
2013-01-16 15:29:17 +00:00
David Williams
1d1dcc875a Added 'intersects' function to Region. 2013-01-14 23:13:17 +01:00
David Williams
e05cb1fefc Fix for zero length normals causing a crash. 2013-01-14 23:12:48 +01:00
Matt Williams
7b64c0c3c0 Move Compression.cpp to folder with correct case 2013-01-14 12:27:04 +00:00
Daviw Williams
68ee094cec More work on block compression with miniz. 2013-01-11 13:29:33 +01:00
Daviw Williams
7bb7be0dec Work on block compression. 2013-01-10 16:37:02 +01:00
Daviw Williams
c7937b176d Very bad (but functional!) initial implementation of LargeVolume compression with miniz. 2013-01-10 16:20:29 +01:00
Daviw Williams
a8383b47db Temporarily disabled multiple samplers as they break the LargeVolume tests. 2013-01-08 16:54:17 +01:00
Matt Williams
a5d55d4415 We ignore these operators since they don't exist in C# 2013-01-04 12:03:38 +00:00
Matt Williams
1f466d4931 Move this line to make sure the flag is always applied 2013-01-04 12:02:26 +00:00
Daviw Williams
a0cd1d09b3 Added a correct set of ADD_TEST macros. Oddly it seems that Visual Studio's 'RUN_TESTS' target doesn't really it care which ADD_TEST macros are used, it just runs all of them. Presumably Linux needs it though. 2013-01-03 13:23:40 +01:00
David Williams
575f4824cc Added 'upperPowerOfTwo' function. 2013-01-03 00:05:28 +01:00
David Williams
bf5a9f7ab8 Added getCentre() to Region class. 2013-01-02 23:03:07 +01:00
David Williams
8fe824eb58 Allowing boundary values to be negative. 2013-01-02 21:52:44 +01:00
Daviw Williams
4b45bb297f More volume unit tests - now iterating backwards as well as forwards. 2013-01-02 17:05:35 +01:00
Daviw Williams
25fae419f3 Removed some old testing code. 2013-01-02 16:11:19 +01:00
Daviw Williams
7bbaa0d559 Better testing of volume samplers. 2013-01-02 16:09:30 +01:00
Daviw Williams
a4b6339689 Fixed typos. 2013-01-02 15:15:30 +01:00
Daviw Williams
97024ba9b2 More volume test configurations. 2013-01-02 14:48:30 +01:00
Daviw Williams
1e9bb88337 Fixed compile errors in VS2008. 2013-01-02 14:13:42 +01:00
Daviw Williams
c05293844f Work on volume tests. 2013-01-02 14:13:14 +01:00
David Williams
ff789d296d Removed remaining traces of assert() 2013-01-01 18:08:59 +00:00
David Williams
4ee55bba2e More replacing assert() with POLYVOX_ASSERT 2013-01-01 15:34:34 +00:00
David Williams
29720c4568 More replacing assert() with POLYVOX_ASSERT. 2013-01-01 14:50:58 +00:00
David Williams
4fcc8a15d7 Merge branch 'develop' of https://bitbucket.org/volumesoffun/polyvox into develop 2013-01-01 14:10:24 +00:00
David Williams
858a9c0e1b Replaced some assert()s with POLYVOX_ASSERT()s. 2013-01-01 14:09:40 +00:00
David Williams
8e5a09d0fc Android compile fixes. 2012-12-29 23:47:32 +01:00
David Williams
7e8af71e52 Not quite sure what the difference is here... 2012-12-29 23:39:13 +01:00
David Williams
195a7a17a8 Merge branch 'develop' into feature/cubiquity-version
Conflicts:
	library/PolyVoxCore/include/PolyVoxCore/Impl/CompilerCapabilities.h
	library/PolyVoxCore/include/PolyVoxCore/Interpolation.h
2012-12-29 23:34:32 +01:00
David Williams
d5b03cdbc3 Made use of POLYVOX_THROW where appropriate. 2012-12-29 23:29:28 +01:00
David Williams
0c78d97ba5 Better defaults for compiler capabilities. 2012-12-29 23:16:29 +01:00
David Williams
9273094ebd Added config.h to control exceptions and asserts. 2012-12-29 22:56:15 +01:00
David Williams
161835f42b Boost is no longer needed if <cstdint> is not found. 2012-12-29 22:26:21 +01:00
David Williams
d6c4cfb9f3 Eliminating some of the differences between this branch and 'develop'. 2012-12-29 21:48:55 +01:00
David Williams
5be6a8ba44 Updated default compiler capabilities as used by Visual Studio - these are subject to change further. 2012-12-29 20:41:23 +00:00
David Williams
2b70f81a9a Added missing .cpp file... thought I did this already?! 2012-12-29 20:32:21 +00:00
David Williams
9051e7558e Setting appropriate build variables for Android version. 2012-12-29 21:32:07 +01:00
David Williams
9c970bd11a Added missing .cpp file to cubiquity version of PolyVox. 2012-12-29 21:16:36 +01:00
David Williams
50c9934376 Bringing minor improvements from Cubiquity's PolyVox into the main branch. 2012-12-29 17:02:07 +00:00
David Williams
d9dcf8a33c Merge branch 'develop' into feature/cubiquity-version
Conflicts:
	library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h
	library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl
	library/PolyVoxCore/include/PolyVoxCore/DefaultMarchingCubesController.h
	library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h
	library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl
	library/PolyVoxCore/include/PolyVoxCore/Vector.inl
	library/PolyVoxCore/source/Impl/Utility.cpp
2012-12-29 16:44:32 +00:00
David Williams
ed614802fe Merge branch 'develop' of https://bitbucket.org/volumesoffun/polyvox into develop 2012-12-29 14:07:11 +00:00
David Williams
607febb673 Merge branch 'feature/error-handling' into develop 2012-12-29 14:06:15 +00:00
David Williams
4f7a6256a9 The throwing of exceptions can now be disabled, and in this case a handler function is called instead. 2012-12-29 00:11:23 +00:00
Matt Williams
de26bb4b9c Merge branch 'hotfix/v0.2.1' into develop
Conflicts:
	library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl
	library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl
	library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl
2012-12-27 01:08:46 +00:00
Matt Williams
95f0aa22c1 Merge branch 'hotfix/v0.2.1' 2012-12-27 01:03:06 +00:00
Matt Williams
81a4294a7d Enable SWIG generation of C# bindings 2012-12-26 20:53:44 +00:00
David Williams
25a4ff1c8e Added comment. 2012-12-26 20:27:29 +00:00
David Williams
9ca84dc0e1 Updated CHANGELOG.txt 2012-12-26 20:24:55 +00:00
David Williams
ecad915001 Tidied up some code. 2012-12-26 20:18:46 +00:00
David Williams
64cd6e31b0 The non-C++11 implemention of POLYVOX_STATIC_ASSERT is no longer dependent on Boost. 2012-12-26 18:16:43 +00:00
David Williams
cc0b3ae2c0 Merge branch 'develop' into feature/error-handling 2012-12-26 17:18:42 +00:00
Matt Williams
59d415e305 Pave way for C# bindings
This callback implementation is Python-specific and so should be disabled
2012-12-26 17:11:08 +00:00
David Williams
3653528ae5 POLYVOX_HALT() implementation for Linux. 2012-12-26 16:44:34 +01:00
Matt Williams
9e7bb75687 Disable the C++11 feature detection on Visual Studio
There seems to be a bug in the interaction between CMake and Visual Studio
which floods the 'recent projects' list with the TRY_COMPILE projects.

If in the future this is fixed then it can re-enabled.
2012-12-26 15:40:59 +00:00
Matt Williams
03de39b8dd Add some documentation to the CompilerCapabilities.h files 2012-12-26 15:37:16 +00:00
Matt Williams
bc8240fe63 These checks are no longer needed since it's checked in the top level file 2012-12-26 15:09:54 +00:00
Matt Williams
a419c4f4e6 Mark Vector::operator< as deprecated in the Python bindings 2012-12-26 15:07:15 +00:00
David Williams
a3cb8f7a76 Now using new assert in Vector. 2012-12-26 15:02:03 +00:00
Matt Williams
f5ea8878c2 Add a default CompilerCapabilities.h
This file assumes that the compiler doesn't support anything. If building
without CMake, it will be used and if you want to enable things, the file
can be edited.

When using CMake, a proper CompilerCapabilites.h will be generated and
CMake will set the include path order correctly in order to source the
correct file.
2012-12-26 12:54:52 +00:00
David Williams
e17271a2c7 Work on new asserts. 2012-12-26 10:34:09 +00:00
David Williams
c74c1a2b44 Work on new assert macro. 2012-12-26 02:03:32 +00:00
David Williams
c78a8595fb Initial work on new assert macro. 2012-12-26 01:33:05 +00:00
Matt Williams
831689bd17 Fix tests
The names of some of the bound classes have changed and this fixes the
tests to match it.
2012-12-26 00:31:10 +00:00
David Williams
eb380b84c7 Compile fix for windows. 2012-12-24 21:54:49 +00:00
David Williams
ef4cb38fbe Merge branch 'develop' of https://bitbucket.org/volumesoffun/polyvox into develop 2012-12-24 20:20:52 +00:00
David Williams
b0b0216e67 Merge branch 'feature/cmake-cxx11-detect' into develop 2012-12-24 20:08:47 +00:00
David Williams
74f25eac23 Merge branch 'develop' into feature/cmake-cxx11-detect
Conflicts:
	examples/Basic/CMakeLists.txt
	examples/OpenGL/CMakeLists.txt
	examples/Paging/CMakeLists.txt
	examples/SmoothLOD/CMakeLists.txt
	library/PolyVoxCore/include/PolyVoxCore/Impl/TypeDef.h
2012-12-24 20:08:31 +00:00
Matt Williams
fc74ec5f0f The static_assert() methods are now not bound in SWIG
The ReducedStorageType here is to work around a bug in SWIG.
2012-12-24 15:51:40 +00:00
David Williams
f22410ed9a Linux compile fix. 2012-12-23 13:53:00 +01:00
Matt Williams
2ae111a67f Fix compile error 2012-12-23 12:29:45 +00:00
David Williams
d61ea322c7 Merge branch 'feature/wrap-modes' into develop 2012-12-21 09:17:46 +00:00
David Williams
edfbac122c Merge branch 'develop' into feature/wrap-modes 2012-12-21 09:17:12 +00:00
Matt Williams
b71b4dd032 Undefine POLYVOX_DEPRECATED when compiling with SWIG
We want to wrap the deprecated functions but we don't want to be told
off for it.

See issue #19
2012-12-19 16:14:31 +00:00
Daviw Williams
898aa24126 Removed code which is redundant after previous commit. 2012-12-19 11:46:44 +01:00
Daviw Williams
44dcb0ba89 Different method of controlling the war mode of the MarchingCubesSurfaceExtractor. 2012-12-19 11:32:45 +01:00
Daviw Williams
933c211d47 Added wrap mode support to CubicSurfaceExtractorWithNormals. 2012-12-19 11:23:55 +01:00
Daviw Williams
4396c609bb Added wrap mode support to CubicSurfaceExtractor. 2012-12-18 16:46:57 +01:00
Daviw Williams
8b018be2dc Fix for LargeVolumeSampler. 2012-12-18 16:25:31 +01:00
Matt Williams
1c61329e67 Fix compilation in Linux 2012-12-18 15:13:41 +00:00
Daviw Williams
2a12bcd6d6 Fixed behavior of SimpleVolumeSampler.inl 2012-12-18 14:34:36 +01:00
David Williams
db16a3d602 Started implementing a more mathematically correct volume resampler. 2012-12-17 23:42:03 +01:00
David Williams
8473b1e3e6 Added support for getting interpolated voxel value. 2012-12-16 18:04:33 +01:00
David Williams
342efec3fa More merging for Cubiquity version of PolyVox. 2012-12-16 14:43:18 +01:00
David Williams
a1ac75022c Initial changes required for Cubiquity. 2012-12-15 17:49:43 +01:00
David Williams
c0d4b2a36f Linux compile fix. 2012-12-14 16:50:06 +01:00
Daviw Williams
1af088b81e Merge branch 'feature/wrap-modes' into develop 2012-12-14 16:29:54 +01:00
Daviw Williams
46ca04704b Updated changelog with info on volume wrap modes. 2012-12-14 16:27:05 +01:00
Daviw Williams
d32d692810 Documentation formatting. 2012-12-14 16:12:24 +01:00
Daviw Williams
1f6cbb79a9 Merge branch 'develop' into feature/wrap-modes
Conflicts:
	library/PolyVoxCore/source/Region.cpp
2012-12-14 16:03:36 +01:00
Daviw Williams
298fb951b0 Documentation style update for KDE/Kate. 2012-12-14 15:38:02 +01:00
Daviw Williams
2bc8e8e201 Tidying up marching cubes wrap mode support. 2012-12-14 15:32:07 +01:00
Daviw Williams
ca45d49e0c More work on exposing wrap modes to marching cubes. 2012-12-14 15:25:21 +01:00
Daviw Williams
c06bfa9c09 Initial work on exposing the wrap modes to the marching cubes surface extractor. 2012-12-14 15:13:18 +01:00
Daviw Williams
c69417a72b Commented out failing volume tests - will have to come back to these. 2012-12-13 15:59:25 +01:00
Daviw Williams
2d7045ddd1 Compile fixes for Linux.
Removed use of qrand() until I can confirm results match between platforms.
2012-12-13 15:29:22 +01:00
Matt Williams
a8bc3081fb Disable checks for a few C++11 features
We don't use a lot of these features so don't bother checking for them
just yet.
2012-12-12 14:48:10 +00:00
David Williams
ab6ec9380d Tweaking results so that the tests pass... I'll have to debug this properly on a faster computer. 2012-12-11 22:14:26 +00:00
David Williams
d8da6a7b7f Refactoring the volume unit test code, trying to get some performance benchmarks. Unit tests are currently not passing. 2012-12-11 21:57:30 +00:00
David Williams
dac0e5449f Refactoring volume unit test code. 2012-12-11 20:18:26 +00:00
David Williams
8a376fa396 Improving (making tougher) the volume unit tests. 2012-12-10 23:25:17 +00:00
David Williams
416fdbb1d2 Moved GLEW into Examples/Common folder in Visual Studio. 2012-12-09 19:06:02 +01:00
David Williams
fa69584411 Updated changelog with Vector changes. 2012-12-09 18:50:54 +01:00
David Williams
414d242701 Updated Vector documentation. 2012-12-09 18:45:02 +01:00
David Williams
a502e84764 Updated comment style to match KDE/Kate (for Doxygen syntax highlighting). 2012-12-09 15:09:35 +01:00
David Williams
8b91e55c84 Changed documentation style to match that used by KDE/Kate (for Doxygen syntax highlighting) 2012-12-09 14:53:47 +01:00
David Williams
20a6095d75 Removed use of Vector deprecated operator<. 2012-12-09 14:36:22 +01:00
David Williams
14bf239a5b Some small documentation changes to Vector.h
Deprecated operator<
Fix for normalise()

The CDash machine will probably give deprecated warnings - I'll fix those soon...
2012-12-08 20:54:49 +01:00
David Williams
ec203c6954 Added QBENCHMARK macros to volume unit test. 2012-12-08 11:25:10 +01:00
David Williams
b93ceca542 Improved the logic of a few tests. 2012-12-08 10:42:59 +01:00
David Williams
c49caa1511 RawVolumeSampler now falls back on getVoxelWithWrapping. 2012-12-08 00:06:08 +01:00
David Williams
fbdee1a9eb LargeVolumeSampler now falls back on getVoxelWithWrapping. 2012-12-08 00:02:10 +01:00
David Williams
4c4a0f9f5c SimpleVolumeSampler now falls back on getVoxelWithWrapping. 2012-12-07 23:49:42 +01:00
Daviw Williams
4be54c6dd1 mCurrentVoxel is now zero if the current position is not in the volume. It used to just be set to some invalid address. 2012-12-07 15:56:46 +01:00
Daviw Williams
eb0c7e7a9f More work on volume unit test. 2012-12-07 14:01:42 +01:00
Daviw Williams
e7e1f80e74 Work on volume unit test. 2012-12-07 13:54:00 +01:00
Daviw Williams
d0c9b7ba3d Added extra tests to move functions. 2012-12-07 13:38:39 +01:00
David Williams
fea429a79a Compile fixes for GCC. 2012-12-07 10:57:26 +01:00
David Williams
ab6898c4c5 Removed the assignment operator from SimpleVolume::Sampler and LargeVolume::Sampler. I had forgotten to call the base class assignment operator and this was causing problems.
Also updated the volume unit tests... at least I know now that it's helping!
2012-12-06 23:53:51 +01:00
David Williams
1f9264a9f8 Fixed potential bug with negative voxel positions in large volume. 2012-12-06 21:06:40 +01:00
p265186
19a1f99723 Compile fixes for GCC. 2012-12-06 16:49:38 +01:00
Daviw Williams
d19f16ef64 Added new accessors to volume. getVoxel() and getVoxelWithWrapping() will probably replace getVoxelAt, which will be deprecated. 2012-12-06 16:17:21 +01:00
David Williams
93958998f6 Merge branch 'feature/wrap-modes' of https://bitbucket.org/volumesoffun/polyvox into feature/wrap-modes 2012-12-05 23:53:44 +01:00
David Williams
3f87fc780f Fixed bug with SimpleVolume and negative positions. 2012-12-05 23:49:39 +01:00
Daviw Williams
d5a5242409 Merge branch 'develop' into feature/wrap-modes 2012-12-05 15:47:33 +01:00
Daviw Williams
78cdf9acd6 Fixed use of static_asserts with Boost. These weren't working because static_assert takes two parameters (condition and message) whereas BOOST_STATIC_ASSERT only takes a condition. 2012-12-05 15:06:11 +01:00
David Williams
4ed8d4303b LargeVolume now uses the version of border handling which is in the BaseVolume. 2012-12-04 22:41:45 +01:00
David Williams
5a3d24e09b Changed type of single quotes used for link. I'm not sure if this makes a difference but it's for consistency. 2012-12-04 22:26:39 +01:00
David Williams
829e91ddf9 Updated readme with some real information for BitBucket. 2012-12-04 21:57:54 +01:00
David Williams
9d79035890 Moved volume border handling into base class. RawVolume and SimpleVolume updated, LargeVolume still to be done. 2012-12-03 23:43:44 +01:00
David Williams
9a05f04f85 Merge branch 'develop' into feature/wrap-modes
Conflicts:
	library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl
2012-12-03 21:30:51 +01:00
David Williams
7e38fc135e Removed features which were deprecated in release 0.2. 2012-12-03 21:22:57 +01:00
Daviw Williams
57b78e148b Extended volume unit test. This is mainly to test whether I can commit to the new Git repo on BitBucket. 2012-12-03 16:21:18 +01:00
David Williams
f4917e5001 Added an optimization note. 2012-12-02 17:43:36 +01:00
David Williams
47e8f4a86d Improved raycast unit test so that it exits early if the ray leaves the volume. 2012-12-02 17:33:59 +01:00
David Williams
e7f4c69102 Fixed bug with peek function checking in wrong direction. 2012-12-02 14:17:41 +01:00
David Williams
8792d1bd48 Fixed build error on VS2008 2012-12-02 14:15:34 +01:00
David Williams
c37997bfe2 Updated new volumes test. 2012-12-02 14:02:50 +01:00
David Williams
597b28d271 Support for wrap modes in LargeVolumeSampler 2012-12-02 13:57:08 +01:00
David Williams
9e8e976bfe Work on new unit test for volumes. 2012-12-02 09:43:00 +01:00
David Williams
f9250a778b Made SimpleVolumeSampler support wrap modes. 2012-12-02 08:59:48 +01:00
David Williams
649e3dddb9 Deprecated getSubSampledVoxel() in SimpeVolume and LargeVolume 2012-12-02 08:31:36 +01:00
David Williams
e5aab77cda Moved getVoxelAt into base sampler. 2012-12-01 23:49:13 +01:00
David Williams
ff3395643d Moved some functionality into Sampler base class. 2012-12-01 21:56:16 +01:00
David Williams
f310e51318 Renamed macros. 2012-12-01 21:28:49 +01:00
David Williams
90e279d7a4 Fixed bug with checking the wrong direction in peek function. 2012-12-01 20:41:27 +01:00
David Williams
5859281c62 Much as I hate to admit it, my fancy use of bit flags to detect which direction the sampler could move in was actually slower than the previous simpler version. This commit reverts most of the previous few commits. 2012-12-01 20:38:11 +01:00
David Williams
7b6fd11a06 Optimised code for setting the flag states. 2012-12-01 00:47:50 +01:00
David Williams
ba827d446b Added 'containsPoint' functions which take separate components instead of vectors. 2012-11-30 23:47:03 +01:00
David Williams
9c71c3fa30 Switched to using bitset for flags.
Optimized movement of samplers.
2012-11-30 22:42:35 +01:00
Daviw Williams
b57cec96a3 Fixed bug with checking the wrong direction before peeking. 2012-11-30 16:08:35 +01:00
Daviw Williams
256e289c8f Removed old code. 2012-11-30 15:56:45 +01:00
Daviw Williams
b53fee2627 Fixed behaviour. LowPassFilter now passes again. 2012-11-30 15:53:33 +01:00
David Williams
fab995225c Switched to using bitflags to test if sampler is i a valid position. At least the LowPassFilterTest is currently broken. 2012-11-29 23:02:26 +01:00
David Williams
a026546bb4 Making some functions in Vector use the new 'OperationType'. 2012-11-29 18:16:32 +01:00
David Williams
b10b995a84 Fixed compiler warning. 2012-11-29 18:13:41 +01:00
David Williams
bbdee0db25 Changed default wrap mode. 2012-11-27 23:54:11 +01:00
David Williams
a7d7f64554 getEnclosedRegion now return a const ref. 2012-11-27 22:53:36 +01:00
David Williams
c98f65c9a5 Added setWrapMode to BaseVolume::Sampler.
Added initial border/clamping to RawVolumeSampler.
2012-11-27 22:31:50 +01:00
Daviw Williams
7636b6fb55 Updated changelog with Region changes. 2012-11-27 16:54:56 +01:00
Daviw Williams
153d0afc77 Reordered functions for alphabetical order (except getters and setters). 2012-11-27 16:51:22 +01:00
Daviw Williams
61cd1d3a29 Renamed Region::erode() to Region::shrink() and renamed Region::dilate() to Region::grow. 2012-11-27 16:49:19 +01:00
Matt Williams
312a3def68 Fix GLEW compile error on Windows. 2012-11-26 23:15:19 +00:00
Matt Williams
79cc521666 Remove Density and Material tyes from bindings
We now only have the bindings for (u)int{8,16,32}_t and float. This will
hopefully simplify things.
2012-11-26 13:58:51 +00:00
Matt Williams
6e296b010f Fix path for test 2012-11-25 18:46:56 +00:00
Matt Williams
3ed3ac6998 Start Python bindings for Raycast
This is only beginning of the bindings here. It's starting to get more
complicated due to the use of callbacks. To be able to define a callback
function in Python which is then called by a C++ algorithm requires quite a
bit of wrapping boilerplate.

The class PyCallback here will wrap a Python callable and call it with the
density value of the voxel. It's not very generic and at present it can't
pass the sampler itself since it's not available in the Python bindings.

Regardless, the new test added here (TestRaycast.py) works as expected and
hopefully we will be able to build up from here.
2012-11-25 18:07:12 +00:00
Matt Williams
37fbe16939 Assert only takes one argument.
It was causing a compiler error on GCC.
2012-11-25 11:22:38 +00:00
Matt Williams
fd3ce69187 Wrap the correct class..but disable it since it needs more work. 2012-11-25 10:30:58 +00:00
David Williams
9960a757e5 Updated changelog. 2012-11-25 09:48:33 +01:00
David Williams
fbc39e1cc3 Merge branch 'feature/region-enhancements' into develop 2012-11-25 09:30:59 +01:00
David Williams
b2642ec5c6 More work on Region documentation. 2012-11-25 09:18:29 +01:00
David Williams
8f27c8fa9e Added accumulation functions. 2012-11-25 00:17:14 +01:00
David Williams
bd00c8e572 Added rounding functions. 2012-11-25 00:04:18 +01:00
David Williams
f5b638957c More Region documentation. 2012-11-24 23:36:46 +01:00
David Williams
e32d47ed8d Documentation of Region class. 2012-11-24 23:02:26 +01:00
David Williams
1b207325c4 Added documentation and new 'shift' functions. 2012-11-24 22:38:43 +01:00
David Williams
dec3f67a5a Inlined some functions. 2012-11-24 22:07:49 +01:00
David Williams
02b6421ab8 Reordered some functions. 2012-11-24 22:02:21 +01:00
David Williams
6d7246f907 More dilation and erosion functions for region. 2012-11-24 21:32:17 +01:00
Matt Williams
e048f7c2f6 Clean up in interface files and CubicExtractor bindings 2012-11-24 15:42:02 +00:00
Matt Williams
bb3d3c4b68 Add a EXTRACTORS macro to automate the generation of the extractors
Like with VOLUMETYPES it is centralising the definitions of the volume and
voxel types.
2012-11-24 15:37:46 +00:00
Matt Williams
e7daab5bbc Simplify macro by assuming PolyVox:: in front of all classes 2012-11-24 15:20:34 +00:00
Matt Williams
edf2bf87d4 Add LargeVolume binding 2012-11-24 14:23:52 +00:00
Matt Williams
63e0298fbf Add a VOLUMETYPES macro to avoid repeating ourselves. 2012-11-24 14:16:52 +00:00
Matt Williams
a932d060f2 Add RawVolume wrapper 2012-11-24 14:07:13 +00:00
Matt Williams
7fbe92e1e7 Separate out the BaseVolume definitions into their own file 2012-11-24 14:06:31 +00:00
David Williams
6e729ded56 Merge branch 'feature/region-enhancements' into develop 2012-11-24 12:52:52 +01:00
David Williams
cbddc9cba4 Added basic dilation and erosion functions. 2012-11-24 12:52:37 +01:00
David Williams
9671f19444 Added setters to region. 2012-11-24 12:42:45 +01:00
David Williams
c9df34336b Revert "Trivial change for testing."
This reverts commit 3d9f44af909fbe28853cf656c688a471c803a954.
2012-11-24 12:29:57 +01:00
David Williams
d2cc4da68d Merge branch 'feature/region-enhancements' into develop 2012-11-24 12:27:19 +01:00
David Williams
8bc10530d2 Merge branch 'develop' into feature/region-enhancements 2012-11-24 12:25:01 +01:00
David Williams
9226337756 Partially revert commit bef6a7746e9ecf0dc1bec6737273c19c7142ce71 as it was causing complier warnings in Visual Studio. 2012-11-24 10:57:51 +01:00
David Williams
beee8850e9 Added getters for upper corner (trivial commit - part of git testing). 2012-11-24 10:41:07 +01:00
David Williams
08ceb9df1d Merge branch 'feature/region-enhancements' into develop 2012-11-24 10:33:36 +01:00
David Williams
3d9f44af90 Trivial change for testing. 2012-11-24 10:24:45 +01:00
David Williams
cb992b7c34 Added getter methods for lower corner. (Trivial commit - part of Git testing) 2012-11-24 10:20:20 +01:00
David Williams
24dcdcb97d A simple testing change as I'm investigating Git problems. 2012-11-24 09:48:56 +01:00
David Williams
e56fd3ce4f Another code dump which was supposed to be a feature branch... having some Git issues at the moment. 2012-11-24 00:32:29 +01:00
Matt Williams
989cd453fe Consolidate glew into one location to speed up build. 2012-11-23 23:01:50 +00:00
Matt Williams
9f5fe452c9 Give shared_ptr the same treatment.
Here I have defined my own test for the feature. It's not an extensive test
but it checks for the presence of the class.
2012-11-23 15:41:27 +00:00
Matt Williams
989e6ea589 Fix SWIG complaining about redefining uint8_t etc. 2012-11-23 15:41:26 +00:00
Matt Williams
dbb5832d52 Move the cstdint detection to the new framework
Again, hopefully nothing will change but a test on MSVC 2008/2005 might be
needed.
2012-11-23 15:41:26 +00:00
Matt Williams
4b2c899dc6 Define static_assert in the same way
Hopefully this won't change anything as we already had a check for it.
However, it is now based compiler checks rather than version numbers.

We haven't use static_assert anywhere in code yet anyway.
2012-11-23 15:41:26 +00:00
Matt Williams
c8657943c8 Create polyvox_constexpr macros based on the detected features
We now have a two new polyvox_ macros:

* polyvox_constexpr which is 'constexpr' is supported and '' otherwise
* polyvox_constexpr_const constexpr which is also 'constexpr' is supported
  but falls back to 'const' otherwise.

These macros should be safe to use liberally without worrying about which
compiler you're on.
2012-11-23 15:41:26 +00:00
Matt Williams
3902e00a0f Add a CompilerCapabilities.h.in file which is filled in by CMake
It will #define a each of the basic features detected by CMake which can
then be used by other headers (like TypeDef.h) to set things up for
PolyVox.

It is this file which you will have to manually edit and rename if you want
to skip using CMake.
2012-11-23 15:41:26 +00:00
Matt Williams
596bf12877 Run the feature detection at CMake time 2012-11-23 15:41:25 +00:00
Matt Williams
a24fcc0c03 Add C++11 compiler support detection feature
This is currently copied from http://quickgit.kde.org/index.php?p=scratch%2Fdakon%2Fcmake-cxx11.git
but there is a chance that in future it will be merged into CMake proper.
2012-11-23 15:41:25 +00:00
Matt Williams
c981ed2706 Add forward declaration for DefaultIsQuadNeeded 2012-11-23 15:40:51 +00:00
Daviw Williams
d28c2aa61d This is a collection of commits which were supposed to be part of a feature branch... but I got in a mess with Git and so am committing them all together. 2012-11-23 15:51:22 +01:00
Matt Williams
3e79e0bfaa Fix LowPassFilter test
The implicit default kernel size for the non-SAT version was 3 but the SAT
version was using an explicit kernel of 5 which caused a discrepancy.

Now just use a kernel of 3.
2012-11-22 22:23:07 +00:00
Matt Williams
0f838d54b6 Fix to correct method 2012-11-22 21:56:18 +00:00
Matt Williams
839e5374b6 Add required header and use const& in constructor 2012-11-22 20:43:53 +00:00
Matt Williams
88c8c4014a Fit off-by-one error in resampler by using available functions
It still doesn't work as expected but this is a step in the right
direction.
2012-11-22 20:43:00 +00:00
Matt Williams
3577a56eb3 Rename some SWIG stuff to prepare for C# bindings 2012-11-21 17:03:17 +00:00
Matt Williams
bef6a7746e Add const qualifiers to variables where it makes sense. 2012-11-21 15:23:45 +00:00
Matt Williams
addbf9f365 This sampler is not used in the function. 2012-11-21 15:10:02 +00:00
303 changed files with 18087 additions and 169394 deletions

20
.gitattributes vendored Normal file
View File

@ -0,0 +1,20 @@
# Based on GitHub sample: https://help.github.com/articles/dealing-with-line-endings
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto
# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.
*.c text
*.cpp text
*.h text
*.inl text
*.txt text
*.i text
# Declare files that will always have CRLF line endings on checkout.
#*.sln text eol=crlf
# Denote all files that are truly binary and should not be modified.
#*.png binary
#*.jpg binary

View File

@ -1,3 +1,81 @@
Changes for PolyVox version 0.3
===============================
This release has focused on... (some introduction here).
*** Quick braindump of some changes ***
* SimpleVolume is now PagedVolume (slightly slower but can go larger).
* MarchingCubesSurfaceExtractor class is now a free function extractMarchingCubesSurface()
* Meshes are more templatized (e.g. on IndexType) and extracted meshes are encoded to save space. A 'decode' function is provided for these (or you can do it on the GPU).
* Generally more templatization - you will want to use a lot of the 'auto' keyword to stay sane.
* MarchingCubesController class gives more control over extraction process, but defaults should be fine for primative voxel types.
* Requires VS2013 on Windows (GCC 4.7/Clang should be ok).
* Support for 'WrapModes' when accessing outside volumes but I think these have bought a performance impact.
* Documentation is as poor (or wrong) as ever but all tests and examples work.
* New Array class is much faster
*** End of braindump ***
This line was added just for testing.
Voxel access
------------
The getVoxelAt() and setVoxelAt() functions have been deprecated and replaced by getVoxel() and setVoxel(). These new functions provide more control over how edge cases are handled and can potentially be faster as well. Please see the 'Volumes' section of the user manual for more information about how voxel access should be performed.
LargeVolume
-----------
Behaviour and interface of the LargeVolume has changed significantly and code which uses it will certainly need to be updated. Plese see the LargeVolume API docs for full details of how it now works.
It is now possible to provide custom compressors for the data which is stored in a LargeVolume. Two compressor implementation are provided with PolyVox - RLECompressor which is suitable for cubic-style terrain, and MinizCompressor which uses the 'miniz' zlib implementation for smooth terrain or general purpose use. Users can provide their own implementation of the compressor interface if they wish.
Note that the setCompressionEnabled() functionality has been removed and a compressor must always be provided when constructing the volume. The ability to disable compression was of questionable benefit and was complicating the logic in the code.
The LargeVolume also supports custom paging code which can be supplied by providing a subclass of Pager and implementing the relevant methods. This replaces the dataRequiredHandler() and dataOverflowHandler() functions.
These changes regarding compression and paging have also affected the LargeVolume constructors(s). Please see the API docs to see how they look now.
Error Handling
--------------
PolyVox now has it's own POLYVOX_ASSERT() macro rather than using the standard assert(). This has some advantages such as allowing a message to be printed and providing file/line information, and it is also possible to enable/disable it independantly of whether you are making a debug or release build.
A simple logging system has also been added, and the output can be redirected by user code.
Please see the 'Error Handling' section of the user manual for more information about these changes.
Volume wrap modes
-----------------
This release has seen a overhaul of the way PolyVox handles voxel positions which are outside of the volume. It used to be the case that you could specify a border value which would be returned whenever an out-of-volume access was performed, but this was not flexible enough for all use cases. You can now choose between different wrapping modes (border, clamp, etc) and apply them to both the volume itself or to samplers. If you have multiple samplers pointing at the same volume then you can choose to have different wrap modes for each of them.
Within the Volume class the getVoxelAt() and setBorderValue() functions have been deprecated. Please see the 'Volumes' section of the user manual for more information about how voxel access should now be performed.
Various algorithms have also been updated to allow wrap modes to be specified when executing them.
Region class
------------
The Region class has been tidied up and enhanced with new functionality. It now contains functions for growing and shrinking regions, as well as 'accumulate()' functions which ensure the Region contains a given point. The concept of an invalid region has also been introduced - this is one whose lower corner is greater than it's upper corner.
Vector class
------------
The Vector class has been tidied up. Most notably it now makes use of an 'OperationType' which is used for internal calculations and some results. The documentation has also been updated.
Deprecated functionality
------------------------
Vector::operator<() has been deprecated. It was only present to allow Vectors to be used as the key to an std::map, but it makes more sense for this to be specified seperatly as a std::map comparison function. This is now done in the OpenGLExample (search for VectorCompare).
getVoxelAt() and setBorderValue() have been deprecated in the Volume class. See the section of this file on 'Volume wrap modes' for details.
Removed functionality
--------------------
Functionality deprecated for the previous release has now been removed. This includes:
- Region::getWidth() and related functions. You should now use Region::getWidthInVoxels() or Region::getWidthInCells.
- The MeshDecimator. We don't have a direct replacement for this so you should consider an alternative such as downsampling the volume or using an external mesh processing library.
- The SimpleInterface. This was primarily for the bindings, and we are making other efforts to get those working.
- Serialisation. You should implement any required serialisation yourself.
- This had a number of problems and was a little too high-level for PolyVox. You should implement change tracking yourself.
Changes for PolyVox version 0.2 Changes for PolyVox version 0.2
=============================== ===============================
This is the first revision for which we have produced a changelog, as we are now trying to streamline our development and release process. Hence this changelog entry is not going to be as structured as we hope they will be in the future. We're writing it from memory, rather than having carefully kept track of all the relevant changes as we made them. This is the first revision for which we have produced a changelog, as we are now trying to streamline our development and release process. Hence this changelog entry is not going to be as structured as we hope they will be in the future. We're writing it from memory, rather than having carefully kept track of all the relevant changes as we made them.

View File

@ -1,26 +1,28 @@
# Copyright (c) 2007-2012 Matt Williams ################################################################################
# Copyright (c) 2007-2012 David Williams # The MIT License (MIT)
# #
# This software is provided 'as-is', without any express or implied # Copyright (c) 2015 Matthew Williams and David Williams
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
# #
# Permission is granted to anyone to use this software for any purpose, # Permission is hereby granted, free of charge, to any person obtaining a copy
# including commercial applications, and to alter it and redistribute it # of this software and associated documentation files (the "Software"), to deal
# freely, subject to the following restrictions: # in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# #
# 1. The origin of this software must not be misrepresented; you must not # The above copyright notice and this permission notice shall be included in all
# claim that you wrote the original software. If you use this software # copies or substantial portions of the Software.
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
# #
# 2. Altered source versions must be plainly marked as such, and must not be # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# misrepresented as being the original software. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# 3. This notice may not be removed or altered from any source # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# distribution. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
################################################################################
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.3) CMAKE_MINIMUM_REQUIRED(VERSION 2.8.6)
PROJECT(PolyVox) PROJECT(PolyVox)
@ -33,51 +35,19 @@ MARK_AS_ADVANCED(FORCE POLYVOX_VERSION)
SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON) SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)
include(FeatureSummary) include(FeatureSummary)
FIND_PACKAGE(Doxygen) IF(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") #Maybe "OR MINGW"
OPTION(ENABLE_EXAMPLES "Should the examples be built" ON)
SET(LIBRARY_TYPE "DYNAMIC" CACHE STRING "Should the library be STATIC or DYNAMIC")
SET_PROPERTY(CACHE LIBRARY_TYPE PROPERTY STRINGS DYNAMIC STATIC)
IF(WIN32)
SET(LIBRARY_TYPE "STATIC")
ENDIF()
# Qt is required for building the tests, the example and optionally for bundling the documentation
FIND_PACKAGE(Qt4 COMPONENTS QtCore QtGui QtOpenGL QtTest)
INCLUDE(${QT_USE_FILE})
if(CMAKE_VERSION VERSION_LESS "2.8.6")
set_package_info(Doxygen "API documentation generator" http://www.doxygen.org "Building the API documentation")
set_package_info(Qt4 "C++ framework" http://qt-project.org "Building the examples and tests")
else()
set_package_properties(Doxygen PROPERTIES URL http://www.doxygen.org DESCRIPTION "API documentation generator" TYPE OPTIONAL PURPOSE "Building the API documentation")
set_package_properties(Qt4 PROPERTIES DESCRIPTION "C++ framework" URL http://qt-project.org)
set_package_properties(Qt4 PROPERTIES TYPE RECOMMENDED PURPOSE "Building the examples")
set_package_properties(Qt4 PROPERTIES TYPE OPTIONAL PURPOSE "Building the tests")
endif()
if(MSVC AND (MSVC_VERSION LESS 1600))
# Require boost for older (pre-vc2010) Visual Studio compilers
# See library/include/polyvoxcore/impl/TypeDef.h
find_package(Boost REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
endif()
IF(CMAKE_COMPILER_IS_GNUCXX) #Maybe "OR MINGW"
ADD_DEFINITIONS(-std=c++0x) #Enable C++0x mode ADD_DEFINITIONS(-std=c++0x) #Enable C++0x mode
ENDIF() ENDIF()
if(CMAKE_CXX_COMPILER MATCHES "clang")
ADD_DEFINITIONS(-std=c++0x) #Enable C++0x mode
endif()
ADD_SUBDIRECTORY(library) IF(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
ENDIF()
ADD_SUBDIRECTORY(include)
OPTION(ENABLE_EXAMPLES "Should the examples be built" ON) OPTION(ENABLE_EXAMPLES "Should the examples be built" ON)
IF(ENABLE_EXAMPLES AND QT_QTOPENGL_FOUND) IF(ENABLE_EXAMPLES)
ADD_SUBDIRECTORY(examples/Basic) ADD_SUBDIRECTORY(examples)
ADD_SUBDIRECTORY(examples/Paging)
ADD_SUBDIRECTORY(examples/OpenGL)
ADD_SUBDIRECTORY(examples/SmoothLOD)
SET(BUILD_EXAMPLES ON)
ELSE() ELSE()
SET(BUILD_EXAMPLES OFF) SET(BUILD_EXAMPLES OFF)
ENDIF() ENDIF()
@ -85,30 +55,22 @@ ENDIF()
INCLUDE(Packaging.cmake) INCLUDE(Packaging.cmake)
OPTION(ENABLE_TESTS "Should the tests be built" ON) OPTION(ENABLE_TESTS "Should the tests be built" ON)
IF(ENABLE_TESTS AND QT_QTTEST_FOUND) IF(ENABLE_TESTS)
INCLUDE(CTest) INCLUDE(CTest)
MARK_AS_ADVANCED(FORCE DART_TESTING_TIMEOUT) #This is only needed to hide the variable in the GUI (CMake bug) until 2.8.5
MARK_AS_ADVANCED(FORCE BUILD_TESTING) MARK_AS_ADVANCED(FORCE BUILD_TESTING)
ADD_SUBDIRECTORY(tests) ADD_SUBDIRECTORY(tests)
SET(BUILD_TESTS ON)
ELSE() ELSE()
SET(BUILD_TESTS OFF) SET(BUILD_TESTS OFF)
ENDIF() ENDIF()
#Check if we will building _and_ bundling the docs
IF(DOXYGEN_FOUND AND QT_QCOLLECTIONGENERATOR_EXECUTABLE)
SET(BUILD_AND_BUNDLE_DOCS ON)
ELSE()
SET(BUILD_AND_BUNDLE_DOCS OFF)
ENDIF()
ADD_SUBDIRECTORY(documentation) ADD_SUBDIRECTORY(documentation)
ADD_SUBDIRECTORY(bindings)
add_feature_info("Examples" BUILD_EXAMPLES "Examples of PolyVox usage") add_feature_info("Examples" BUILD_EXAMPLES "Examples of PolyVox usage")
add_feature_info("Tests" BUILD_TESTS "Unit tests") add_feature_info("Tests" BUILD_TESTS "Unit tests")
add_feature_info("Bindings" BUILD_BINDINGS "SWIG bindings") add_feature_info("Bindings" BUILD_BINDINGS "SWIG bindings")
add_feature_info("API docs" DOXYGEN_FOUND "HTML documentation of the API") add_feature_info("API docs" BUILD_DOCS "HTML documentation of the API")
add_feature_info("Qt Help" BUILD_AND_BUNDLE_DOCS "API docs in Qt Help format")
add_feature_info("Manual" BUILD_MANUAL "HTML user's manual") add_feature_info("Manual" BUILD_MANUAL "HTML user's manual")
feature_summary(WHAT ALL) feature_summary(WHAT ALL)
@ -117,11 +79,9 @@ feature_summary(WHAT ALL)
MESSAGE(STATUS "") MESSAGE(STATUS "")
MESSAGE(STATUS "Summary") MESSAGE(STATUS "Summary")
MESSAGE(STATUS "-------") MESSAGE(STATUS "-------")
MESSAGE(STATUS "Library type: " ${LIBRARY_TYPE})
MESSAGE(STATUS "Build examples: " ${BUILD_EXAMPLES}) MESSAGE(STATUS "Build examples: " ${BUILD_EXAMPLES})
MESSAGE(STATUS "Build tests: " ${BUILD_TESTS}) MESSAGE(STATUS "Build tests: " ${BUILD_TESTS})
MESSAGE(STATUS "Build bindings: " ${BUILD_BINDINGS}) MESSAGE(STATUS "Build bindings: " ${BUILD_BINDINGS})
MESSAGE(STATUS "API Docs available: " ${DOXYGEN_FOUND}) MESSAGE(STATUS "API Docs available: " ${BUILD_DOCS})
MESSAGE(STATUS " - Qt Help bundling: " ${BUILD_AND_BUNDLE_DOCS})
MESSAGE(STATUS "Build manual: " ${BUILD_MANUAL}) MESSAGE(STATUS "Build manual: " ${BUILD_MANUAL})
MESSAGE(STATUS "") MESSAGE(STATUS "")

View File

@ -1,3 +1,7 @@
David Williams - Lead programmer. David Williams - Lead programmer.
Matthew Williams - Linux port, build system, support and maintenance. Matthew Williams - Linux port, build system, support and maintenance.
Oliver Schneider - Very large Volumes Oliver Schneider - Very large Volumes
Acknowledgements
----------------
PolyVox uses the 'miniz' for data compression. 'miniz' is public domain software and does not affect the license of PolyVox or of code using PolyVox. More details here: http://code.google.com/p/miniz/

View File

@ -1,23 +1,26 @@
# Copyright (c) 2010-2012 Matt Williams ################################################################################
# The MIT License (MIT)
# #
# This software is provided 'as-is', without any express or implied # Copyright (c) 2015 Matthew Williams and David Williams
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
# #
# Permission is granted to anyone to use this software for any purpose, # Permission is hereby granted, free of charge, to any person obtaining a copy
# including commercial applications, and to alter it and redistribute it # of this software and associated documentation files (the "Software"), to deal
# freely, subject to the following restrictions: # in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# #
# 1. The origin of this software must not be misrepresented; you must not # The above copyright notice and this permission notice shall be included in all
# claim that you wrote the original software. If you use this software # copies or substantial portions of the Software.
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
# #
# 2. Altered source versions must be plainly marked as such, and must not be # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# misrepresented as being the original software. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# 3. This notice may not be removed or altered from any source # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# distribution. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
################################################################################
set(CTEST_PROJECT_NAME "PolyVox") set(CTEST_PROJECT_NAME "PolyVox")
set(CTEST_NIGHTLY_START_TIME "00:00:00 GMT") set(CTEST_NIGHTLY_START_TIME "00:00:00 GMT")

View File

@ -2,21 +2,31 @@
Building PolyVox Building PolyVox
**************** ****************
.. warning ::
Before reading this information, be aware that *you may not actually need to build PolyVox in order to use it*. PolyVox is a header-only library and in many cases it is sufficient to simply copy the ``include/PolyVox`` folder into your source tree. This folder contains all the PolyVox header files, and you can probably then include them directly with ``#include "PolyVox/SomeHeaderHere.h"`` without even needing to change your compiler search paths.
That said, you *will* need to read the instructions below if you want to build the examples, tests, bindings or documentation which may be helpful in getting you started with PolyVox.
Requirements Requirements
============ ============
To build PolyVox you need: To build PolyVox you need:
* `CMake <http://cmake.org>`_ 2.8.3 or greater * `CMake <http://cmake.org>`_ (tested on version 2.8.12.2, later versions should also work)
* A C++ compiler with support for some C++0x features (GCC 4.3 or VC 2010 seem to work) * A C++ compiler with support for some C++11 features (tested on GCC 4.8 and VC 2013)
With the following optional packages: With the following optional packages:
* `Qt <http://qt.nokia.com>`_ for building the tests and the example applications * `Qt version 5.2 of later <https://www.qt.io/>`_ for building the tests and the example applications
* ``qcollectiongenerator`` which comes with Qt Assistant is used for bundling the docs for installation * ``qcollectiongenerator`` which comes with Qt Assistant is used for bundling the docs for installation
* `Doxygen <http://doxygen.org>`_ for building the documentation. Version 1.5.7 is needed to build the Qt Assistant docs. 1.7.0 or greater is recommended * `Doxygen <http://doxygen.org>`_ for building the documentation. Version 1.5.7 is needed to build the Qt Assistant docs. 1.7.0 or greater is recommended
* `Python <http://python.org>`_, `Sphinx <http://sphinx.pocoo.org>`_ and `PyParsing <http://pyparsing.wikispaces.com/>`_ for generating the PolyVox manual in HTML * `Python <http://python.org>`_, `Sphinx <http://sphinx.pocoo.org>`_ and `PyParsing <http://pyparsing.wikispaces.com/>`_ for generating the PolyVox manual in HTML
* Version 2 required - see note below.
* `Python development libraries <http://python.org>`_, `SWIG <http://swig.org/>`_ for generating the Python bindings * `Python development libraries <http://python.org>`_, `SWIG <http://swig.org/>`_ for generating the Python bindings
* Version 3 required - see note below.
.. note ::
Currently we use different versions of Python for generating the documentation (version 2) vs. building the bindings (version 3). However, it is unlikely that you as a user will want to build the documentation as it is available online, or you can view the source *.rst files directly. But if you do want to build both the documentation and the bindings yourself then you will need both versions of Python installed.
Linux Linux
===== =====
@ -51,9 +61,6 @@ The other available settings for PolyVox are:
``ENABLE_BINDINGS`` (``ON`` or ``OFF``) ``ENABLE_BINDINGS`` (``ON`` or ``OFF``)
Should the Python bindings to PolyVox be built. This requires the Python development libraries and SWIG to be installed. Defaults to ``ON``. Should the Python bindings to PolyVox be built. This requires the Python development libraries and SWIG to be installed. Defaults to ``ON``.
``LIBRARY_TYPE`` (``DYNAMIC`` or ``STATIC``)
Choose whether static (``.a``) or dynamic libraries (``.so``) should be built. On Linux ``DYNAMIC`` is the default and on Windows ``STATIC`` is the default.
``CMAKE_BUILD_TYPE`` (``Debug``, ``Release``, ``RelWithDebInfo`` or ``MinSizeRel``) ``CMAKE_BUILD_TYPE`` (``Debug``, ``Release``, ``RelWithDebInfo`` or ``MinSizeRel``)
String option to set the type of build. This will automatically set some compilation flags such as the optimisation level or define ``NDEBUG``. String option to set the type of build. This will automatically set some compilation flags such as the optimisation level or define ``NDEBUG``.
@ -114,14 +121,14 @@ If you do not have Python and Sphinx installed and do not want to install them t
Windows Windows
======= =======
For information about the dependencies, CMake configuration variables and buildable targets look at the Linux build information in the section above. The earlier information about the dependencies, CMake configuration variables and buildable targets is still valid for Windows, so look at the Linux build information in the section above. Then see the notes below on using the CMake GUI.
CMake CMake
----- -----
You need CMake installed so get the binary distribution from `CMake.org <http://cmake.org/cmake/resources/software.html>`_. Install it and run the CMake GUI. You need CMake installed so get the binary distribution from `CMake.org <http://cmake.org/cmake/resources/software.html>`_. Install it and run the CMake GUI.
Point the source directory to the directory holding this file and the build directory to the ``build`` subdirectory. Then, click the ``Configure`` button. Click through the dialog box that appears and once you've clicked ``Finish`` you should see text appearing in the bottom text area. Once this has finished, some options will appear in the top area. The purpose of these options in detailed in the Linux→CMake section above. Once you have set these options to what you please, click ``Configure`` again. If it completes without errors then you can click ``Generate`` which will generate your compilers project files in the build directory. Point the source directory to the PolyVox root directory (the directory holding the 'INSTALL.txt' file) and the build directory to the ``build`` subdirectory. Then, click the ``Configure`` button. Click through the dialog box that appears and once you've clicked ``Finish`` you should see text appearing in the bottom text area. Once this has finished, some options will appear in the top area. The purpose of these options in detailed in the Linux→CMake section above. Once you have set these options to what you please, click ``Configure`` again. If it completes without errors then you can click ``Generate`` which will generate your compilers project files in the build directory.
Building Building
-------- --------

View File

@ -1,20 +0,0 @@
Copyright (c) 2005-2012 David Williams and Matthew Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.

21
LICENSE.txt Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2015 David Williams and Matthew Williams
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,23 +1,26 @@
# Copyright (c) 2009-2012 Matt Williams ################################################################################
# The MIT License (MIT)
# #
# This software is provided 'as-is', without any express or implied # Copyright (c) 2015 Matthew Williams and David Williams
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
# #
# Permission is granted to anyone to use this software for any purpose, # Permission is hereby granted, free of charge, to any person obtaining a copy
# including commercial applications, and to alter it and redistribute it # of this software and associated documentation files (the "Software"), to deal
# freely, subject to the following restrictions: # in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# #
# 1. The origin of this software must not be misrepresented; you must not # The above copyright notice and this permission notice shall be included in all
# claim that you wrote the original software. If you use this software # copies or substantial portions of the Software.
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
# #
# 2. Altered source versions must be plainly marked as such, and must not be # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# misrepresented as being the original software. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# 3. This notice may not be removed or altered from any source # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# distribution. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
################################################################################
#INCLUDE(InstallRequiredSystemLibraries) #INCLUDE(InstallRequiredSystemLibraries)

View File

@ -1,5 +1,8 @@
PolyVox - The voxel management and manipulation library PolyVox - The voxel management and manipulation library
======================================================= =======================================================
PolyVox is the core technology which lies behind our games. It is a fast, lightweight C++ library for the storage and processing of volumetric (voxel-based) environments. It has applications in both games and medical/scientific visualisation, and is released under the terms of the `zlib license <http://www.tldrlegal.com/l/ZLIB>`_. .. attention ::
This system is no longer under active development. For more details please see this blog post: http://www.volumesoffun.com/wrapping-up-polyvox-development-to-focus-on-cubiquity-2/
PolyVox is the core technology which lies behind our games. It is a fast, lightweight C++ library for the storage and processing of volumetric (voxel-based) environments. It has applications in both games and medical/scientific visualisation, and is released under the terms of the `MIT license <https://www.tldrlegal.com/l/mit>`_.
PolyVox is a relatively low-level library, and you will need experience in C++ and computer graphics/shaders to use it effectively. It is designed to be easily integrated into existing applications and is independent of your chosen graphics API. For more details please see `this page <http://www.volumesoffun.com/polyvox-about/>`_ on our website. PolyVox is a relatively low-level library, and you will need experience in C++ and computer graphics/shaders to use it effectively. It is designed to be easily integrated into existing applications and is independent of your chosen graphics API. For more details please see `this page <http://www.volumesoffun.com/polyvox-about/>`_ on our website.

8
bindings/BaseVolume.i Normal file
View File

@ -0,0 +1,8 @@
%module SimpleVolume
%{
#include "BaseVolume.h"
%}
%include "BaseVolume.h"
VOLUMETYPES(BaseVolume)

9
bindings/Block.i Normal file
View File

@ -0,0 +1,9 @@
%module Block
%{
#include "Block.h"
%}
%include "Block.h"
VOLUMETYPES(Block)

View File

@ -0,0 +1,8 @@
%module BlockCompressor
%{
#include "BlockCompressor.h"
%}
%include "BlockCompressor.h"
VOLUMETYPES(BlockCompressor)

68
bindings/CMakeLists.txt Normal file
View File

@ -0,0 +1,68 @@
################################################################################
# The MIT License (MIT)
#
# Copyright (c) 2015 Matthew Williams and David Williams
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
################################################################################
option(ENABLE_BINDINGS "Build bindings" OFF) #Off by default
if(ENABLE_BINDINGS)
find_package(SWIG)
mark_as_advanced(SWIG_DIR SWIG_VERSION)
find_package(PythonLibs 3)
if(CMAKE_VERSION VERSION_LESS "2.8.6")
set_package_info(SWIG "Bindings generator" http://www.swig.org)
set_package_info(PythonLibs "Programming language" http://www.python.org)
else()
set_package_properties(SWIG PROPERTIES DESCRIPTION "Bindings generator" URL http://www.swig.org)
set_package_properties(PythonLibs PROPERTIES DESCRIPTION "Programming language" URL http://www.python.org)
endif()
if(SWIG_FOUND)
set(BUILD_BINDINGS ON CACHE BOOL "Will the bindings be built" FORCE)
include(${SWIG_USE_FILE})
set(CMAKE_SWIG_FLAGS "")
set_source_files_properties(PolyVoxCore.i PROPERTIES CPLUSPLUS ON)
include_directories(${PolyVoxHeaders_SOURCE_DIR} ${PolyVoxHeaders_SOURCE_DIR}/PolyVox)
if(PYTHONLIBS_FOUND)
include_directories(${PYTHON_INCLUDE_PATH})
link_directories(${PolyVoxCore_BINARY_DIR})
#set_source_files_properties(PolyVoxCore.i PROPERTIES SWIG_FLAGS "-builtin")
set(SWIG_MODULE_PolyVoxCorePython_EXTRA_FLAGS "-py3")
swig_add_module(PolyVoxCorePython python PolyVoxCore.i)
swig_link_libraries(PolyVoxCorePython ${PYTHON_LIBRARIES})
set_target_properties(${SWIG_MODULE_PolyVoxCorePython_REAL_NAME} PROPERTIES OUTPUT_NAME _PolyVoxCore)
#set_target_properties(${SWIG_MODULE_PolyVoxCore_REAL_NAME} PROPERTIES SUFFIX ".pyd")
SET_PROPERTY(TARGET ${SWIG_MODULE_PolyVoxCorePython_REAL_NAME} PROPERTY FOLDER "Bindings")
endif()
set(SWIG_MODULE_PolyVoxCoreCSharp_EXTRA_FLAGS "-dllimport;PolyVoxCoreCSharp") #This _should_ be inside UseSWIG.cmake - http://www.cmake.org/Bug/view.php?id=13814
swig_add_module(PolyVoxCoreCSharp csharp PolyVoxCore.i)
swig_link_libraries(PolyVoxCoreCSharp)
SET_PROPERTY(TARGET ${SWIG_MODULE_PolyVoxCoreCSharp_REAL_NAME} PROPERTY FOLDER "Bindings")
else()
set(BUILD_BINDINGS OFF CACHE BOOL "Will the bindings be built" FORCE)
endif()
else()
set(BUILD_BINDINGS OFF CACHE BOOL "Will the bindings be built" FORCE)
endif()
mark_as_advanced(FORCE BUILD_BINDINGS)

9
bindings/Chunk.i Normal file
View File

@ -0,0 +1,9 @@
%module Chunk
%{
#include "Chunk.h"
%}
%include "Chunk.h"
VOLUMETYPES(Chunk)

View File

@ -0,0 +1,8 @@
%module CompressedBlock
%{
#include "CompressedBlock.h"
%}
%include "CompressedBlock.h"
VOLUMETYPES(CompressedBlock)

View File

@ -0,0 +1,9 @@
%module CubicSurfaceExtractor
%{
#include "CubicSurfaceExtractor.h"
%}
%include "CubicSurfaceExtractor.h"
%template(extractCubicMeshSimpleVolumeuint8) extractCubicMesh<PolyVox::PagedVolume<uint8_t> >;
//EXTRACTORS(CubicSurfaceExtractor)

View File

@ -0,0 +1,8 @@
%module CubicSurfaceExtractorWithNormals
%{
#include "CubicSurfaceExtractorWithNormals.h"
%}
%include "CubicSurfaceExtractorWithNormals.h"
%template(CubicSurfaceExtractorWithNormalsSimpleVolumeuint8) PolyVox::CubicSurfaceExtractorWithNormals<PolyVox::SimpleVolume<uint8_t>, PolyVox::DefaultIsQuadNeeded<uint8_t> >;

6
bindings/FilePager.i Normal file
View File

@ -0,0 +1,6 @@
%module FilePager
%{
#include "FilePager.h"
%}
%include "FilePager.h"

8
bindings/LargeVolume.i Normal file
View File

@ -0,0 +1,8 @@
%module LargeVolume
%{
#include "LargeVolume.h"
%}
%include "LargeVolume.h"
VOLUMETYPES(LargeVolume)

View File

@ -0,0 +1,8 @@
%module MarchingCubesSurfaceExtractor
%{
#include "MarchingCubesSurfaceExtractor.h"
%}
%include "MarchingCubesSurfaceExtractor.h"
EXTRACTORS(MarchingCubesSurfaceExtractor)

View File

@ -0,0 +1,6 @@
%module MinizBlockCompressor
%{
#include "MinizBlockCompressor.h"
%}
%include "MinizBlockCompressor.h"

50
bindings/PagedVolume.i Normal file
View File

@ -0,0 +1,50 @@
%module PagedVolume
#pragma SWIG nowarn=SWIGWARN_PARSE_NESTED_CLASS
namespace PolyVox
{
class PolyVox::PagedVolume_Chunk {
public:
PagedVolume_Chunk(Vector3DInt32 v3dPosition, uint16_t uSideLength, PolyVox::PagedVolume_Pager* pPager = nullptr);
~PagedVolume_Chunk();
VoxelType* getData(void) const;
uint32_t getDataSizeInBytes(void) const;
VoxelType getVoxel(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const;
VoxelType getVoxel(const Vector3DUint16& v3dPos) const;
void setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue);
void setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue);
};
class PolyVox::PagedVolume_Pager {
public:
/// Constructor
PagedVolume_Pager() {};
/// Destructor
virtual ~PagedVolume_Pager() {};
virtual void pageIn(const Region& region, PagedVolume_Chunk* pChunk) = 0;
virtual void pageOut(const Region& region, PagedVolume_Chunk* pChunk) = 0;
};
}
%{
#include "PagedVolume.h"
%}
%include "PagedVolume.h"
%{
namespace PolyVox
{
// SWIG thinks that Inner is a global class, so we need to trick the C++
// compiler into understanding this so called global type.
typedef PagedVolume<int8_t>::Pager PagedVolume_Pager;
typedef PagedVolume<int8_t>::Chunk PagedVolume_Chunk;
}
%}
VOLUMETYPES(PagedVolume)

6
bindings/Pager.i Normal file
View File

@ -0,0 +1,6 @@
%module Pager
%{
#include "Pager.h"
%}
%include "Pager.h"

8
bindings/Picking.i Normal file
View File

@ -0,0 +1,8 @@
%module Picking
%{
#include "Picking.h"
%}
%include "Picking.h"
EXTRACTORS(pickVoxel)

93
bindings/PolyVoxCore.i Normal file
View File

@ -0,0 +1,93 @@
%module PolyVoxCore
#define POLYVOX_API
%include "Impl/PlatformDefinitions.h"
#define __attribute__(x) //Silence DEPRECATED errors
//This macro allows us to use Python properties on our classes
%define PROPERTY(type,name,getter,setter)
%extend type {
%pythoncode %{
__swig_getmethods__["name"] = getter
__swig_setmethods__["name"] = setter
if _newclass: name = property(getter, setter)
%}
};
%enddef
//Put this in an %extend section to wrap operator<< as __str__
%define STR()
const char* __str__() {
std::ostringstream out;
out << *$self;
return out.str().c_str();
}
%enddef
//Centralise this to avoid repeating ourselves
//This macro will be called in the volume interface files to define the various volume types.
%define VOLUMETYPES(class)
%template(class ## int8) PolyVox::class<int8_t>;
//%template(class ## int16) PolyVox::class<int16_t>;
//%template(class ## int32) PolyVox::class<int32_t>;
//%template(class ## uint8) PolyVox::class<uint8_t>;
//%template(class ## uint16) PolyVox::class<uint16_t>;
//%template(class ## uint32) PolyVox::class<uint32_t>;
//%template(class ## float) PolyVox::class<float>;
%enddef
//Template based on voxel type
%define EXTRACTOR(class, volumetype)
%template(class ## volumetype ## int8) PolyVox::class<PolyVox::volumetype<int8_t> >;
//%template(class ## volumetype ## int16) PolyVox::class<PolyVox::volumetype<int16_t> >;
//%template(class ## volumetype ## int32) PolyVox::class<PolyVox::volumetype<int32_t> >;
//%template(class ## volumetype ## uint8) PolyVox::class<PolyVox::volumetype<uint8_t> >;
//%template(class ## volumetype ## uint16) PolyVox::class<PolyVox::volumetype<uint16_t> >;
//%template(class ## volumetype ## uint32) PolyVox::class<PolyVox::volumetype<uint32_t> >;
//%template(class ## volumetype ## float) PolyVox::class<PolyVox::volumetype<float> >;
%enddef
//Template based on volume type
%define EXTRACTORS(shortname)
EXTRACTOR(shortname, PagedVolume)
EXTRACTOR(shortname, RawVolume)
%enddef
%feature("autodoc", "1");
#ifdef SWIGPYTHON
//This will rename "operator=" to "assign" since Python doesn't have assignment
%rename(assign) *::operator=;
#endif
#ifdef SWIGCSHARP
//These operators are not wrappable in C# and their function is provided by other means
%ignore *::operator=;
%ignore *::operator+=;
%ignore *::operator-=;
%ignore *::operator*=;
%ignore *::operator/=;
%ignore *::operator<<; //This is covered by STR()
#endif
%include "stdint.i"
%include "std_vector.i"
%include "Vector.i"
%include "DefaultMarchingCubesController.i"
%include "Region.i"
//%include "Chunk.i"
//%include "CompressedBlock.i"
//%include "UncompressedBlock.i"
//%include "BlockCompressor.i"
//%include "Pager.i"
//%include "FilePager.i"
//%include "MinizBlockCompressor.i"
//%include "RLEBlockCompressor.i"
%include "BaseVolume.i"
//%include "RawVolume.i"
//%include "PagedVolume.i"
//%include "VertexTypes.i"
//%include "SurfaceMesh.i"
////%include "MarchingCubesSurfaceExtractor.i"
////%include "CubicSurfaceExtractor.i"
//%include "Raycast.i"
//%include "Picking.i"

View File

@ -0,0 +1,6 @@
%module RLEBlockCompressor
%{
#include "RLEBlockCompressor.h"
%}
%include "RLEBlockCompressor.h"

8
bindings/RawVolume.i Normal file
View File

@ -0,0 +1,8 @@
%module RawVolume
%{
#include "RawVolume.h"
%}
%include "RawVolume.h"
VOLUMETYPES(RawVolume)

61
bindings/Raycast.i Normal file
View File

@ -0,0 +1,61 @@
%module Raycast
%{
#include "Raycast.h"
#ifdef SWIGPYTHON
template<typename VolumeType>
class PyCallback
{
private:
PyObject *func;
PyCallback& operator=(const PyCallback&); // Not allowed
public:
PyCallback(const PyCallback& o) : func(o.func)
{
Py_XINCREF(func);
}
PyCallback(PyObject *func) : func(func)
{
Py_XINCREF(this->func);
assert(PyCallable_Check(this->func));
}
~PyCallback()
{
Py_XDECREF(func);
}
bool operator()(const typename VolumeType::Sampler& sampler)
{
if (!func || Py_None == func || !PyCallable_Check(func))
{
return false; //Make this raise a Python exception
}
PyObject *args = Py_BuildValue("(l)", sampler.getVoxel()); //TODO pass the sampler object itself in
PyObject *result = PyObject_Call(func,args,0);
Py_DECREF(args);
Py_XDECREF(result);
return (PyInt_AsLong(result) == 0) ? false : true;
}
};
template<typename VolumeType, typename Callback>
PolyVox::RaycastResult raycastWithEndpointsPython(VolumeType* volData, const PolyVox::Vector3DFloat& v3dStart, const PolyVox::Vector3DFloat& v3dEnd, PyObject *callback)
{
PyCallback<VolumeType> newCallback(callback);
return PolyVox::raycastWithEndpoints(volData, v3dStart, v3dEnd, newCallback);
}
#endif
%}
%include "Raycast.h"
#ifdef SWIGPYTHON
template<typename VolumeType, typename Callback>
PolyVox::RaycastResult raycastWithEndpointsPython(VolumeType* volData, const PolyVox::Vector3DFloat& v3dStart, const PolyVox::Vector3DFloat& v3dEnd, PyObject *callback);
%template(raycastWithEndpointsSimpleVolumeuint8) raycastWithEndpointsPython<PolyVox::SimpleVolume<uint8_t>, PyCallback<PolyVox::SimpleVolume<uint8_t> > >;
#endif

View File

@ -4,6 +4,10 @@
#include "Region.h" #include "Region.h"
%} %}
%extend PolyVox::Region {
STR()
};
%ignore depth; %ignore depth;
%ignore height; %ignore height;
%ignore width; %ignore width;

8
bindings/SimpleVolume.i Normal file
View File

@ -0,0 +1,8 @@
%module SimpleVolume
%{
#include "SimpleVolume.h"
%}
%include "SimpleVolume.h"
VOLUMETYPES(SimpleVolume)

20
bindings/SurfaceMesh.i Normal file
View File

@ -0,0 +1,20 @@
%module SurfaceMesh
%{
#include "Region.h"
#include "Vertex.h"
#include "Mesh.h"
%}
%include "Region.h"
%include "Vertex.h"
%include "Mesh.h"
//%template(VertexTypeVector) std::vector<PolyVox::VertexType>;
//%template(PositionMaterialVector) std::vector<PolyVox::PositionMaterial>;
//%template(PositionMaterialNormalVector) std::vector<PolyVox::PositionMaterialNormal>;
//%template(LodRecordVector) std::vector<PolyVox::LodRecord>;
//%template(uint8Vector) std::vector<uint8_t>;
//%template(uint32Vector) std::vector<uint32_t>;
%template(MeshPositionMaterial) PolyVox::Mesh<PolyVox::CubicVertex<uint8_t>, uint16_t >;
%template(MeshPositionMaterialNormal) PolyVox::Mesh<PolyVox::MarchingCubesVertex<uint8_t>, uint16_t >;

View File

@ -0,0 +1,8 @@
%module UncompressedBlock
%{
#include "UncompressedBlock.h"
%}
%include "UncompressedBlock.h"
VOLUMETYPES(UncompressedBlock)

121
bindings/Vector.i Normal file
View File

@ -0,0 +1,121 @@
%module Vector
%{
#include "Vector.h"
#include <sstream>
%}
%include "Vector.h"
#ifdef SWIGPYTHON
PROPERTY(PolyVox::Vector, x, getX, setX)
PROPERTY(PolyVox::Vector, y, getY, setY)
PROPERTY(PolyVox::Vector, z, getZ, setZ)
#endif
%rename(Plus) operator +;
%rename(Minus) operator -;
%rename(Multiply) operator *;
%rename(Divide) operator /;
%rename(Equal) operator ==;
%rename(NotEqual) operator !=;
%extend PolyVox::Vector {
#ifdef SWIGPYTHON
PolyVox::Vector __add__(const PolyVox::Vector& rhs) {
return *$self + rhs;
}
PolyVox::Vector __sub__(const PolyVox::Vector& rhs) {
return *$self - rhs;
}
PolyVox::Vector __div__(const PolyVox::Vector& rhs) {
return *$self / rhs;
}
PolyVox::Vector __div__(const StorageType& rhs) {
return *$self / rhs;
}
PolyVox::Vector __mul__(const PolyVox::Vector& rhs) {
return *$self * rhs;
}
PolyVox::Vector __mul__(const StorageType& rhs) {
return *$self * rhs;
}
#endif
STR()
};
%feature("pythonprepend") PolyVox::Vector::operator< %{
import warnings
warnings.warn("deprecated", DeprecationWarning)
%}
//%csattributes PolyVox::Vector::operator< "[System.Obsolete(\"deprecated\")]"
%define VECTOR3(StorageType,OperationType,ReducedStorageType)
#if SWIGCSHARP
%extend PolyVox::Vector<3,StorageType,OperationType> {
PolyVox::Vector<3,StorageType,OperationType> operator+(const PolyVox::Vector<3,StorageType,OperationType>& rhs) {return *$self + rhs;}
PolyVox::Vector<3,StorageType,OperationType> operator-(const PolyVox::Vector<3,StorageType,OperationType>& rhs) {return *$self - rhs;}
PolyVox::Vector<3,StorageType,OperationType> operator*(const PolyVox::Vector<3,StorageType,OperationType>& rhs) {return *$self * rhs;}
PolyVox::Vector<3,StorageType,OperationType> operator/(const PolyVox::Vector<3,StorageType,OperationType>& rhs) {return *$self / rhs;}
PolyVox::Vector<3,StorageType,OperationType> operator*(const StorageType& rhs) {return *$self * rhs;}
PolyVox::Vector<3,StorageType,OperationType> operator/(const StorageType& rhs) {return *$self / rhs;}
};
%typemap(cscode) PolyVox::Vector<3,StorageType,OperationType> %{
public static Vector3D##StorageType operator+(Vector3D##StorageType lhs, Vector3D##StorageType rhs) {
Vector3D##StorageType newVec = new Vector3D##StorageType();
newVec = lhs.Plus(rhs);
return newVec;
}
public static Vector3D##StorageType operator-(Vector3D##StorageType lhs, Vector3D##StorageType rhs) {
Vector3D##StorageType newVec = new Vector3D##StorageType();
newVec = lhs.Minus(rhs);
return newVec;
}
public static Vector3D##StorageType operator*(Vector3D##StorageType lhs, Vector3D##StorageType rhs) {
Vector3D##StorageType newVec = new Vector3D##StorageType();
newVec = lhs.Multiply(rhs);
return newVec;
}
public static Vector3D##StorageType operator/(Vector3D##StorageType lhs, Vector3D##StorageType rhs) {
Vector3D##StorageType newVec = new Vector3D##StorageType();
newVec = lhs.Divide(rhs);
return newVec;
}
public static Vector3D##StorageType operator*(Vector3D##StorageType lhs, $typemap(cstype, StorageType) rhs) {
Vector3D##StorageType newVec = new Vector3D##StorageType();
newVec = lhs.Multiply(rhs);
return newVec;
}
public static Vector3D##StorageType operator/(Vector3D##StorageType lhs, $typemap(cstype, StorageType) rhs) {
Vector3D##StorageType newVec = new Vector3D##StorageType();
newVec = lhs.Divide(rhs);
return newVec;
}
public bool Equals(Vector3D##StorageType rhs) {
if ((object)rhs == null)
{
return false;
}
return Equal(rhs);
}
%}
%ignore PolyVox::Vector<3,StorageType,OperationType>::operator<; //This is deprecated
#endif
%ignore PolyVox::Vector<3,StorageType,OperationType>::Vector(ReducedStorageType,ReducedStorageType,ReducedStorageType,ReducedStorageType);
%ignore PolyVox::Vector<3,StorageType,OperationType>::Vector(ReducedStorageType,ReducedStorageType);
%ignore PolyVox::Vector<3,StorageType,OperationType>::getW() const;
%ignore PolyVox::Vector<3,StorageType,OperationType>::setW(ReducedStorageType);
%ignore PolyVox::Vector<3,StorageType,OperationType>::setElements(ReducedStorageType,ReducedStorageType,ReducedStorageType,ReducedStorageType);
%template(Vector3D ## StorageType) PolyVox::Vector<3,StorageType,OperationType>;
%enddef
VECTOR3(float,float,float)
VECTOR3(double,double,double)
VECTOR3(int8_t,int32_t,signed char)
VECTOR3(uint8_t,int32_t,unsigned char)
VECTOR3(int16_t,int32_t,signed short)
VECTOR3(uint16_t,int32_t,unsigned short)
VECTOR3(int32_t,int32_t,signed int)
VECTOR3(uint32_t,int32_t,unsigned int)
//%rename(assign) Vector3DFloat::operator=;

View File

@ -2,12 +2,12 @@
%{ %{
#include "Impl/TypeDef.h" #include "Impl/TypeDef.h"
#include "Vector.h" #include "Vector.h"
#include "VertexTypes.h" #include "Vertex.h"
%} %}
%include "Impl/TypeDef.h" %include "Impl/TypeDef.h"
%include "Vector.h" %include "Vector.h"
%include "VertexTypes.h" %include "Vertex.h"
//%template (PositionMaterial) PolyVox::PositionMaterial; //%template (PositionMaterial) PolyVox::PositionMaterial;
//%template (PositionMaterialNormal) PolyVox::PositionMaterialNormal; //%template (PositionMaterialNormal) PolyVox::PositionMaterialNormal;

View File

@ -1,23 +1,26 @@
# Copyright (c) 2010-2012 Matt Williams ################################################################################
# The MIT License (MIT)
# #
# This software is provided 'as-is', without any express or implied # Copyright (c) 2015 Matthew Williams and David Williams
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
# #
# Permission is granted to anyone to use this software for any purpose, # Permission is hereby granted, free of charge, to any person obtaining a copy
# including commercial applications, and to alter it and redistribute it # of this software and associated documentation files (the "Software"), to deal
# freely, subject to the following restrictions: # in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# #
# 1. The origin of this software must not be misrepresented; you must not # The above copyright notice and this permission notice shall be included in all
# claim that you wrote the original software. If you use this software # copies or substantial portions of the Software.
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
# #
# 2. Altered source versions must be plainly marked as such, and must not be # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# misrepresented as being the original software. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# 3. This notice may not be removed or altered from any source # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# distribution. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
################################################################################
find_program(SPHINXBUILD_EXECUTABLE sphinx-build DOC "The location of the sphinx-build executable") find_program(SPHINXBUILD_EXECUTABLE sphinx-build DOC "The location of the sphinx-build executable")

View File

@ -0,0 +1,70 @@
**************
Error Handling
**************
PolyVox includes a number of error handling features designed to help you identify and/or recover from problematic scenarios. This document describes these features and how they affect you as a user of the library.
Logging
=======
PolyVox has a simple logging mechanism which allows it to write messages with an associated severity (from Debug up to Fatal). This logging mechanism is not really intended for use by client code (i.e. calling the logging macros from your own application) but you can of course do so at your own risk. However, it is possible to redirect the output of these logging functions so you can integrate them with your application's logging framework or suppress them completely.
Fatal messages are only issued in non-recoverable scenarios when the application is about to crash, and may provide the last piece of information you have about what went wrong. Error messages are issued when something has happened which prevents successful completion of a task, for example if you provide invalid parameters to a function (error messages are also issued whenever an exception is thrown). Warning messages mean the system was able to continue but the results may not be what you expected. Info messages are used for general information about what PolyVox is doing. Debug and trace messages produce very verbose output and a lot of detail about what PolyVox is doing internally. In general, debug messages are used for tasks the user has directly initiated (e.g. they might provide timing information for surface extraction) while trace messages are used for things which happen spontaneously (such as data being paged out of memory).
To redirect log messages you can subclass Logger, create an instance, and set it as active as follows:
.. sourcecode :: c++
class CustomLogger : public Logger
{
public:
CustomLogger() : Logger() {}
virtual ~CustomLogger() {}
void logTraceMessage(const std::string& message) { /* Do something with the message */ }
void logDebugMessage(const std::string& message) { /* Do something with the message */ }
void logInfoMessage(const std::string& message) { /* Do something with the message */ }
void logWarningMessage(const std::string& message) { /* Do something with the message */ }
void logErrorMessage(const std::string& message) { /* Do something with the message */ }
void logFatalMessage(const std::string& message) { /* Do something with the message */ }
};
CustomLogger* myCustomLogger = new CustomLogger();
setLogger(myCustomLogger);
Note that the default implementation (DefaultLogger) sends the fatal, error and warning streams to std::cerr, the info stream to std:cout, and that the debug and trace streams are suppressed.
PolyVox logging can be disabled completely in Config.h by undefining POLYVOX_LOG_TRACE_ENABLED through to POLYVOX_LOG_FATAL_ENABLED. Each of these can be disabled individually and the corresponding code will then be completely stripped from PolyVox. This is a compile-time setting - if you wish to change the log level at run-time then in your own implementation you could implement a filtering mechanism which only does something with the messages if some 'log severity' setting is greater than a certain threshold which can be changed at runtime.
Exceptions
==========
Error handling in PolyVox is provided by using the C++ exception mechanism. Exceptions can be thrown for a variety of reasons and your code should be prepared to handle them to prevent your application from crashing. It is possible to disable the throwing of exceptions if they are not supported by your compiler.
Usage
-----
Most functions in PolyVox will validate their input parameters and throw an exception if the provided values do not meet the function's requirements (which should be specified in the API documentation). However, in certain performance critical cases we choose not to spend time validating the parameters and an exception will not be thrown, though we do still use an assertion if these are enabled.
The most notable example of this is when accessing volume data through the get/setVoxel() functions, as these are designed to be very fast. Validating an input position would require multiple conditional operations which we chose to avoid. Therefore, **accessing a voxel outside of a volume will cause undefined behaviour.**
Disabling exceptions
--------------------
Some platforms may not support the use of C++ exceptions (older Android SDKs are the only place we have seen this) so you may need to disable them completely. This is highly undesirable but you may have no choice. To do this you should undefine 'POLYVOX_THROW_ENABLED' in Config.h (we may expose this through CMake in the future).
If exceptions are disabled then PolyVox will call a 'ThrowHandler' instead of throwing an exception. This is defined as follows:
.. sourcecode :: c++
typedef void (*ThrowHandler)(std::exception& e, const char* file, int line);
The default throw handler will print an error and then terminate, but you can provide a custom throw handler matching the function definition above:
.. sourcecode :: c++
setThrowHandler(&myThrowHandler);
Asserts
=======
In addition to the C++ exception handling mechanism, PolyVox also makes use of assertions to verify the internal state of the library at various points. This functionality is provided by out own POLYVOX_ASSERT() macro rather than the standard C++ assert() as this has a number of advantages described `here <http://cnicholson.net/2009/02/stupid-c-tricks-adventures-in-assert/>`_.
Assertions inside PolyVox are enabled by defining 'POLYVOX_ASSERTS_ENABLED' in Config.h and again we may expose this through CMake. Note that the presence of assertions is independant of whether you are building a debug or release version of your application.
As a user you are not really expected to encounter an assertion inside PolyVox - they are mostly there for our purposes as developers of the library. So if you hit one in PolyVox then there is a good chance it is a bug in the library, as user errors should have been prevented by throwing an exceptions. Again, there are exceptions to this rule as some speed-critical functions (getVoxel(), etc) do not validate their parameters.

View File

@ -12,7 +12,7 @@ PolyVox volumes make it easy to access these neighbours, but the situation gets
Having established that edge cases can be problematic, we can now see that storing your data as a set of adjacent volumes is undesirable because these edge cases then exist throughout the data set. This causes a lot of problems such as gaps between pieces of extracted terrain or discontinuities in the computed normals. Having established that edge cases can be problematic, we can now see that storing your data as a set of adjacent volumes is undesirable because these edge cases then exist throughout the data set. This causes a lot of problems such as gaps between pieces of extracted terrain or discontinuities in the computed normals.
The usual reason why people attempt to break their terrain into separate volumes is so that they can perform some more advanced memory management for very big terrain, for example by only loading particular volumes into memory when they are within a certain distance from the camera. However, this kind of paging behaviour is already implemented by the LargeVolume class. The LargeVolume internally stores its data as a set of blocks, and does it in such a way that it is able to perform neighbourhood access across block boundaries. Whenever you find yourself trying to break terrain data into separate volumes you should probably use the LargeVolume instead. The usual reason why people attempt to break their terrain into separate volumes is so that they can perform some more advanced memory management for very big terrain, for example by only loading particular volumes into memory when they are within a certain distance from the camera. However, this kind of paging behaviour is already implemented by the PagedVolume class. The PagedVolume internally stores its data as a set of blocks, and does it in such a way that it is able to perform neighbourhood access across block boundaries. Whenever you find yourself trying to break terrain data into separate volumes you should probably use the PagedVolume instead.
Note that although you should only use a single volume for your data, it is still recommended that you split the mesh data into multiple pieces so that they can be culled against the view frustum, and so that you can update the smaller pieces more quickly when you need to. You can extract meshes from different parts of the volume by passing a Region to the surface extractor. Note that although you should only use a single volume for your data, it is still recommended that you split the mesh data into multiple pieces so that they can be culled against the view frustum, and so that you can update the smaller pieces more quickly when you need to. You can extract meshes from different parts of the volume by passing a Region to the surface extractor.
@ -20,6 +20,6 @@ Lastly, note that there are exceptions to the 'one volume' rule. An example migh
Can I combine smooth meshes with cubic ones? Can I combine smooth meshes with cubic ones?
-------------------------------------------- --------------------------------------------
We have never attempted to do this but in theory it should be possible. One option is simply to generate two meshes (one using the MarchingCubesSurfaceExtractor and the other using the CubicSurfaceExtractor) and render them on top of each other while allowing the depth buffer to resolve the intersections. Combining these two meshes into a single mesh is likely to be difficult as they use different vertex formats and have different texturing requirements (see the document on texture mapping). We have never attempted to do this but in theory it should be possible. One option is simply to generate two meshes (one using extractMarchingCubesSurface() and the other using extractCubicSurface()) and render them on top of each other while allowing the depth buffer to resolve the intersections. Combining these two meshes into a single mesh is likely to be difficult as they use different vertex formats and have different texturing requirements (see the document on texture mapping).
An alternative possibility may be to create a new surface extractor based on the Surface Nets (link) algorithm. The idea here is that the mesh would start with a cubic shape, but as the net was stretched it would be smoothed. The degree of smoothing could be controlled by a voxel property which could allow the full range from cubic to smooth to exist in a single mesh. As mentioned above, this may mean that some extra work has to be put into a fragment shader which is capable of texturing this kind of mesh. Come by the forums of you want to discuss this further. An alternative possibility may be to create a new surface extractor based on the Surface Nets (link) algorithm. The idea here is that the mesh would start with a cubic shape, but as the net was stretched it would be smoothed. The degree of smoothing could be controlled by a voxel property which could allow the full range from cubic to smooth to exist in a single mesh. As mentioned above, this may mean that some extra work has to be put into a fragment shader which is capable of texturing this kind of mesh. Come by the forums of you want to discuss this further.

View File

@ -7,20 +7,14 @@ For these reasons it is desirable to reduce the triangle count of the meshes as
Cubic Meshes Cubic Meshes
============ ============
A naive implementation of a cubic surface extractor would generate a mesh containing a quad for voxel face which lies on the boundary between a solid and an empty voxel. The CubicSurfaceExtractor is indeed capable of generating such a mesh, but it also provides the option to merge adjacent quads into a single quad subject to various conditions being satisfied (e.g. the faces must have the same material). This merging process drastically reduces the amount of geometry which must be drawn but does not modify the shape of the mesh. Because of these desirable properties such merging is performed by default, but it can be disabled if necessary. A naive implementation of a cubic surface extractor would generate a mesh containing a quad for each voxel face which lies on the boundary between a solid and an empty voxel. Our extractCubicSurface() function is indeed capable of generating such a mesh, but it also provides the option to merge adjacent quads into a single quad subject to various conditions being satisfied (e.g. the faces must have the same material). This merging process drastically reduces the amount of geometry which must be drawn but does not modify the shape of the mesh. Because of these desirable properties such merging is performed by default, but it can be disabled if necessary.
To our knowledge the only drawback of performing this quad merging is that it can create T-junctions in the resulting mesh. T-junctions are an undesirable property of mesh geometry because they can cause tiny cracks (usually just seen as flickering pixels) to occur between quads. The figure below shows a mesh before quad merging, a mesh where the merged quads have caused T-junctions, and how the resulting rendering might look (note the single pixel holes along the quad border). To our knowledge the only drawback of performing this quad merging is that it can create T-junctions in the resulting mesh. T-junctions are an undesirable property of mesh geometry because they can cause tiny cracks (usually just seen as flickering pixels) to occur between quads. Whether it's a problem in practice depends on hardware precision (16/32 bit), distance from origin, number of transforms which are applied, and probably a number of other factors. We have yet to investigate.
*Add figure here...*
Vertices C and D are supposed to lie exactly along the line which has A and B as its end points, so in theory the mesh should be valid and should render correctly. The reason T-junctions cause a problem in practice is due to limitations of the floating point number representation. Depending on the transformations which are applied, it may be that the positions of C and/or D can not be represented precisely enough to exactly lie on the line between A and B.
*Demo correct mesh. mention we don't have a solution to generate it.*
Whether it's a problem in practice depends on hardware precision (16/32 bit), distance from origin, number of transforms which are applied, and probably a number of other factors. We have yet to investigate.
We don't currently have a real solution to this problem. In Voxeliens the borders between voxels were darkened to simulate ambient occlusion and this had the desirable side effect of making any flickering pixels very hard to see. It's also possible that anti-aliasing strategies can reduce the problem, and storing vertex positions as integers may help as well. Lastly, it may be possible to construct some kind of post-process which would repair the image where it identifies single pixel discontinuities in the depth buffer. We don't currently have a real solution to this problem. In Voxeliens the borders between voxels were darkened to simulate ambient occlusion and this had the desirable side effect of making any flickering pixels very hard to see. It's also possible that anti-aliasing strategies can reduce the problem, and storing vertex positions as integers may help as well. Lastly, it may be possible to construct some kind of post-process which would repair the image where it identifies single pixel discontinuities in the depth buffer.
For more information on this topic we suggest the following article series: `Meshing in Voxel Engines <https://blackflux.wordpress.com/2014/02/23/meshing-in-voxel-engines-part-1/>`_
Smooth Meshes Smooth Meshes
============= =============
Level of detail for smooth meshes is a lot more complex than for cubic ones, and we'll admit upfront that we do not currently have a good solution to this problem. None the less, we do have a couple of partial solutions which you might be able to use or adapt for your specific scenario. Level of detail for smooth meshes is a lot more complex than for cubic ones, and we'll admit upfront that we do not currently have a good solution to this problem. None the less, we do have a couple of partial solutions which you might be able to use or adapt for your specific scenario.
@ -33,16 +27,16 @@ The VolumeResampler class can be used to copy volume data from a source region t
One of the problems with this approach is that the lower resolution mesh does not *exactly* line up with the higher resolution mesh, and this can cause cracks to be visible where the two meshes meet. The SmoothLOD sample attempts to avoid this problem by overlapping the meshes slightly but this may not be effective in all situations or from all viewpoints. One of the problems with this approach is that the lower resolution mesh does not *exactly* line up with the higher resolution mesh, and this can cause cracks to be visible where the two meshes meet. The SmoothLOD sample attempts to avoid this problem by overlapping the meshes slightly but this may not be effective in all situations or from all viewpoints.
An alternative is the Transvoxel algorithm (link) developed by Eric Lengyel. This essentially extends the original Marching Cubes lookup table with additional entries which handle seamless transitions between LOD levels, and it is a very promising solution to level of detail for voxel terrain. At this point in time we do not have an implementation of this algorithm but work is being undertaking in the area. For the latest developments see: http://www.volumesoffun.com/phpBB3/viewtopic.php?f=2&t=338 An alternative is the `Transvoxel algorithm <http://www.terathon.com/voxels/>`_ developed by Eric Lengyel. This essentially extends the original Marching Cubes lookup table with additional entries which handle seamless transitions between LOD levels, and it is a very promising solution to level of detail for voxel terrain. At this point in time we do not have an implementation of this algorithm.
However, in all volume reduction approaches there is some uncertainty about how materials should be handled. Creating a lower resolution volume means that several voxel values from the high resolution volume need to be combined into a single value. For density values this is straightforward as a simple average gives good results, but it is not clear how this extends to material identifiers. Averaging them doesn't make sense, and it is hard to imagine an approach which would not lead to visible artifacts as LOD levels change. Perhaps the visible effects can be reduced by blending between two LOD levels, but more investigation needs to be done here. However, in all volume reduction approaches there is some uncertainty about how materials should be handled. Creating a lower resolution volume means that several voxel values from the high resolution volume need to be combined into a single value. For density values this is straightforward as a simple average gives good results, but it is not clear how this extends to material identifiers. Averaging them doesn't make sense, and it is hard to imagine an approach which would not lead to visible artifacts as LOD levels change. Perhaps the visible effects can be reduced by blending between two LOD levels, but more investigation needs to be done here.
Mesh Simplification Mesh Simplification
------------------- -------------------
The other main approach is to generate the mesh at the full resolution and then reduce the number of triangles using a postprocessing step. This can draw on the large body of mesh simplification research (link to survey) and typically involves merging adjacent faces or collapsing vertices. When using this approach there are a couple of additional complications compared to the implementations which are normally seen. The other main approach is to generate the mesh at the full resolution and then reduce the number of triangles using a postprocessing step. This can draw on the large body of mesh simplification research and typically involves merging adjacent faces or collapsing vertices. When using this approach there are a couple of additional complications compared to the implementations which are normally seen.
The first additional complication is that the decimation algorithm needs to preserve material boundaries so that they don't move between LOD levels. When choosing whether a particular simplification can be made (i.e deciding if one vertex can be collapsed on to another or whether two faces can be merged) a metric is usually used to determine how much the simplification would affect the visual appearance of the mesh. When working with smooth voxel meshes this metric needs to also consider the material identifiers. The first additional complication is that the decimation algorithm needs to preserve material boundaries so that they don't move between LOD levels. When choosing whether a particular simplification can be made (i.e deciding if one vertex can be collapsed on to another or whether two faces can be merged) a metric is usually used to determine how much the simplification would affect the visual appearance of the mesh. When working with smooth voxel meshes this metric needs to also consider the material identifiers.
We also need to ensure that the metric preserves the geometric boundary of the mesh, so that no cracks are visible when a simplified mesh is place next to an original one. Maintaining this geometric boundary can be difficult, as the straightforward approach of locking the edge vertices in place will tend to limit the amount of simplification which can be performed. Alternatively, cracks can be allowed to develop if they are later hidden through the use of 'skirts' around the resulting mesh. We also need to ensure that the metric preserves the geometric boundary of the mesh, so that no cracks are visible when a simplified mesh is placed next to an original one. Maintaining this geometric boundary can be difficult, as the straightforward approach of locking the edge vertices in place will tend to limit the amount of simplification which can be performed. Alternatively, cracks can be allowed to develop if they are later hidden through the use of 'skirts' around the resulting mesh.
PolyVox used to contain code for performing simplification of the smooth voxel meshes, but unfortunately it had significant performance and functionality issues. Therefore it has been deprecated and it will be removed in a future version of the library. We will instead investigate the use of external mesh simplification libraries and OpenMesh (link) may be a good candidate here. PolyVox used to contain code for performing simplification of the smooth voxel meshes, but unfortunately it had significant performance and functionality issues and so it has been removed. We will instead investigate the use of external mesh simplification libraries and `OpenMesh <http://www.openmesh.org/>`_ may be a good candidate here.

View File

@ -11,7 +11,7 @@ Normal Calculation for Smooth Meshes
------------------------------------ ------------------------------------
When working with smooth voxel terrain meshes, PolyVox provides vertex normals as part of the extracted surface mesh. A common approach for computing these normals would be to compute normals for each face in the mesh, and then compute the vertex normals as a weighted average of the normals of the faces which share it. Actually this is not the approach used by PolyVox, as PolyVox instead computes the vertex normals directly from the underlying volume data. When working with smooth voxel terrain meshes, PolyVox provides vertex normals as part of the extracted surface mesh. A common approach for computing these normals would be to compute normals for each face in the mesh, and then compute the vertex normals as a weighted average of the normals of the faces which share it. Actually this is not the approach used by PolyVox, as PolyVox instead computes the vertex normals directly from the underlying volume data.
More specifically, PolyVox is able to compute the *gradient* of the volume data at any given point using well established image processing methods. The normalised gradient value is used as the vertex normal and in general it is smoother than the value computed by averaging neighbouring faces. Actually there are two approaches to this gradient computation known as *Central Differencing* and *Sobel Filter*. The central differencing approach is generally recommended but the Sobel filter can be used to obtain slightly smoother results but with lower performance. See the MarchingCubesSurfaceExtractor documentation for details on how to select between these (check this exists...). More specifically, PolyVox is able to compute the *gradient* of the volume data at any given point using well established image processing methods. The normalised gradient value is used as the vertex normal and in general it is smoother than the value computed by averaging neighbouring faces.
Normal Calculation for Cubic Meshes Normal Calculation for Cubic Meshes
----------------------------------- -----------------------------------
@ -19,18 +19,17 @@ For cubic meshes PolyVox doesn't actually generate any vertex normals at all, an
Therefore PolyVox does not generate per-vertex normals for cubic meshes, and as a result the cubic mesh's vertices are both smaller and less numerous. Of course, we still need a way to obtain normals for lighting calculations and so our suggestion is to compute the normals in a fragment program using the *derivative operations* which are provided by modern graphics hardware. Therefore PolyVox does not generate per-vertex normals for cubic meshes, and as a result the cubic mesh's vertices are both smaller and less numerous. Of course, we still need a way to obtain normals for lighting calculations and so our suggestion is to compute the normals in a fragment program using the *derivative operations* which are provided by modern graphics hardware.
The description here is rather oversimplified, but the idea behind these operation is that they can tell you how much a variable has changed between two adjacent pixels. If we use our fragment world space position as the input to these derivative operations then we can obtain two vectors which lie on the surface of our face. The cross product of these then gives us a vector which is perpendicular to both and which is therefore our normal. The description here is rather oversimplified, but the idea behind these operations is that they can tell you how much a variable has changed between two adjacent pixels. If we use our fragment world space position as the input to these derivative operations then we can obtain two vectors which lie on the surface of our face. The cross product of these then gives us a vector which is perpendicular to both and which is therefore our normal.
Further information about the derivative operations can be found in the OpenGL/Direct3D API documentation, but the implementation in code is quite simple. Firstly you need to make sure that you have access to the fragments world space position in your shader, which means you need to pass it through from the vertex shader. Then you can use the following code in your fragment shader: Further information about the derivative operations can be found in the OpenGL/Direct3D API documentation, but the implementation in code is quite simple. Firstly you need to make sure that you have access to the fragment's world space position in your shader, which means you need to pass it through from the vertex shader. Then you can use the following code in your fragment shader:
.. code-block:: glsl .. sourcecode:: glsl
vec3 worldNormal = cross(dFdy(inWorldPosition.xyz), dFdx(inWorldPosition.xyz)); vec3 worldNormal = cross(dFdy(inWorldPosition.xyz), dFdx(inWorldPosition.xyz));
worldNormal = normalize(worldNormal); worldNormal = normalize(worldNormal);
**TODO: Check the normal direction** .. note ::
Depending on your graphics API and/or engine setup, you may actually need to flip the resulting normal.
Similar code can be implemented in HLSL but you may need to invert the normal due to coordinate system differences between the two APIs. Also, be aware that it may be necessary to use OpenGL ES XXX extension in order to access this derivative functionality on mobile hardware.
Shadows Shadows
------- -------

View File

@ -5,13 +5,13 @@ The PolyVox library is aimed at experienced games and graphics programmers who w
As a result you will need a decent amount of graphics programming experience to effectively make use of the library. The purpose of this document is to highlight some of the core areas with which you will need to be familiar. In some cases we also provide links to places where you can find more information about the subject in question. As a result you will need a decent amount of graphics programming experience to effectively make use of the library. The purpose of this document is to highlight some of the core areas with which you will need to be familiar. In some cases we also provide links to places where you can find more information about the subject in question.
You should also be aware that voxel terrain is still an open research area and has not yet seen widespread adoption in games and simulations. There are many questions to which we do not currently know the best answer and so you may have to do some research and experimentation yourself when trying to obtain your desired result. Please do let us know if you come up with a trick or technique which you think could benefit other users. You should also be aware that voxel terrain is still an open research area which is only just seeing widespread adoption in games and simulations. There are many questions to which we do not currently know the best answer and so you may have to do some research and experimentation yourself when trying to obtain your desired result. Please do let us know if you come up with a trick or technique which you think could benefit other users.
Programming Programming
=========== ===========
This section describes some of the programming concepts with which you will need to be familiar: This section describes some of the programming concepts with which you will need to be familiar:
**C++:** PolyVox is written using the C++ language and we expect this is what the majority of our users will be developing in. You will need to be familiar with the basic process of building and linking against external libraries as well as setting up your development environment. Note that you do have the option of working with other languages via the SWIG bindings but you may not have as much flexibility with this approach. **C++:** PolyVox is written using the C++ language and we expect this is what the majority of our users will be developing in. Note that you do have the option of working with other languages via the SWIG bindings but you may not have as much flexibility with this approach, and you will need to undertake additional work as the bindings are not currently complete.
**Templates:** PolyVox also makes heavy use of template programming in order to be both fast and generic, so familiarity with templates will be very useful. You shouldn't need to do much template programming yourself but an understanding of them will help you understand errors and resolve any problems. **Templates:** PolyVox also makes heavy use of template programming in order to be both fast and generic, so familiarity with templates will be very useful. You shouldn't need to do much template programming yourself but an understanding of them will help you understand errors and resolve any problems.
@ -23,16 +23,16 @@ Several core graphics principles will be useful in understanding and using PolyV
**Volume representation:** PolyVox revolves around the idea of storing and manipulating volume data and using this as a representation of a 3d world. This is a fairly intuitive extension of traditional heightmap terrain but does require the ability to 'think in 3D'. You will need to understand that data stored in this way can become very large, and understand the idea that paging and compression can be used to combat this. **Volume representation:** PolyVox revolves around the idea of storing and manipulating volume data and using this as a representation of a 3d world. This is a fairly intuitive extension of traditional heightmap terrain but does require the ability to 'think in 3D'. You will need to understand that data stored in this way can become very large, and understand the idea that paging and compression can be used to combat this.
**Mesh representation:** Most PolyVox projects will involve using one of the surface extractors, which output their data as index and vertex buffers. Therefore you will need to understand this representation in order to pass the data to your rendering engine or in order to perform further modifications to it. You can find out about more about this here: (ADD LINK) **Mesh representation:** Most PolyVox projects will involve using one of the surface extractors, which output their data as index and vertex buffers. Therefore you will need to understand this representation in order to pass the data to your rendering engine or in order to perform further modifications to it. You can find out about more about this in the Wikipedia article on `Polygon Meshes <https://en.wikipedia.org/wiki/Polygon_mesh>`_
**Image processing:** For certain advanced application an understanding of image processing methods can be useful. For example the process of blurring an image via a low pass filter can be used to effectively smooth out voxel terrain. There are plans to add more image processing operations to PolyVox particularly with regard to morphological operations which you might want to use to modify your environment. **Image processing:** For certain advanced applications an understanding of image processing methods can be useful. For example, the process of blurring an image via a low pass filter can be used to effectively smooth out voxel terrain. There are plans to add more image processing operations to PolyVox particularly with regard to morphological operations which you might want to use to modify your environment.
Rendering Rendering
========= =========
**Runtime geometry creation:** PolyVox is independent of any particular graphics API which means it outputs its data using API-neutral structures such as index and vertex buffers (as mentioned above). You will need to write the code which converts these structures into a format which your API or engine can understand. This is not a difficult task but does require some knowledge of the rendering technology which you are using. **Runtime geometry creation:** PolyVox is independent of any particular graphics API which means it outputs its data using API-neutral structures such as index and vertex buffers (as mentioned above). You will need to write the code which converts these structures into a format which your API or engine can understand. This is not a difficult task but does require some knowledge of the rendering technology which you are using.
**Scene management:** PolyVox is only responsible for providing you with the mesh data to be displayed, so you application or engine will need to make sensible decisions about how this data should be organised in terms of a spatial structure (octree, bounding volumes tree, etc). It will also need to provide some approach to visibility determination such as frustum culling or a more advanced approach. If you are integrating PolyVox with an existing rendering engine then you should find that many of these aspects are already handled for you. **Scene management:** PolyVox is only responsible for providing you with the mesh data to be displayed, so your application or engine will need to make sensible decisions about how this data should be organised in terms of a spatial structure (octree, bounding volumes tree, etc). It will also need to provide some approach to visibility determination such as frustum culling or a more advanced approach. If you are integrating PolyVox with an existing rendering engine then you should find that many of these aspects are already handled for you.
**Shader programming:** The meshes which are generated by PolyVox are very basic in terms of the vertex data they provide. You get vertex positions, a material identifier, and sometimes vertex normals. It is the responsibility of application programmer to decide how to use this data to create visually interesting renderings. This means you will almost certainly want to make use of shader programs. Of course, in our texturing (LINK) and lighting (LINK) documents you will find many ideas and common solutions, but you will need strong shader programming experience to make effective use of these. **Shader programming:** The meshes which are generated by PolyVox are very basic in terms of the vertex data they provide. You get vertex positions, sometimes vertex normals, and sometimes additional data copied/interpolated from the volume. It is the responsibility of application programmer to decide how to use this data to create visually interesting renderings. This means you will almost certainly want to make use of shader programs. Of course, in our :doc:`texturing <texturing>` and :doc:`lighting <lighting>` documents you will find many ideas and common solutions, but you will need strong shader programming experience to make effective use of these.
If you don't have much experience with shader programming then there are many free resources available. The Cg Tutorial (LINK) provides a good introduction here (the concepts are applicable to other shader languages) as does the documentation for the main graphics (LINK to OpenGL docs) APIs (Link to D3D docs). there is nothing special about PolyVox meshes so you would be advised to practice development on simple meshes such as spheres and cubes before trying to apply it to the output of the mesh extractors. If you don't have much experience with shader programming then there are many free resources available. The Wikipedia page on `Shaders <https://en.wikipedia.org/wiki/Shader>`_ may provide a starting point, as may the documentation for the `OpenGL <https://www.opengl.org/documentation/>`_ and `Direct3D <https://msdn.microsoft.com/en-us/library/windows/desktop/ff476080>`_ libraries. There is nothing special about PolyVox meshes so you would be advised to practice development on simple meshes such as spheres and cubes before trying to apply it to the output of the mesh extractors.

View File

@ -31,9 +31,9 @@ The rational in the cubic case is almost the opposite. For Minecraft style terra
Triplanar Texturing Triplanar Texturing
------------------- -------------------
The most common approach to texture mapping smooth voxel terrain is to use *triplanar texturing*. The basic idea is to project a texture along all three main axes and blend between the three texture samples according to the surface normal. As an example, suppose that we wish to write a fragment shader to apply a single texture to our terrain, and assume that we have access to both the world space position of the fragment and also its normalised surface normal. Also, note that your textures should be set to wrap because the world space position will quickly go outside the bounds of 0.0-1.0. The world space position will need to have been passed through from earlier in the pipeline while the normal can be computed using one of the approaches in the lighting (link) document. The shader code would then look something like this [footnote: code is untested as is simplified compared to real world code. hopefully it compiles, but if not it should still give you an idea of how it works]: The most common approach to texture mapping smooth voxel terrain is to use *triplanar texturing*. The basic idea is to project a texture along all three main axes and blend between the three texture samples according to the surface normal. As an example, suppose that we wish to write a fragment shader to apply a single texture to our terrain, and assume that we have access to both the world space position of the fragment and also its normalised surface normal. Also, note that your textures should be set to wrap because the world space position will quickly go outside the bounds of 0.0-1.0. The world space position will need to have been passed through from earlier in the pipeline while the normal can be computed using one of the approaches in the :doc:`lighting <Lighting>` document. The shader code would then look something like this [footnote: code is untested as is simplified compared to real world code. hopefully it compiles, but if not it should still give you an idea of how it works]:
.. code-block:: glsl .. sourcecode:: glsl
// Take the three texture samples // Take the three texture samples
vec4 sampleX = texture2d(inputTexture, worldSpacePos.yz); // Project along x axis vec4 sampleX = texture2d(inputTexture, worldSpacePos.yz); // Project along x axis
@ -47,7 +47,7 @@ Note that this approach will lead to the texture repeating once every world unit
This idea of triplanar texturing can be applied to the cubic meshes as well, and in some ways it can be considered to be even simpler. With cubic meshes the normal always points exactly along one of the main axes, and so it is not necessary to sample the texture three times nor to blend the results. Instead you can use conditional branching in the fragment shader to determine which pair of values out of {x,y,z} should be used as the texture coordinates. Something like: This idea of triplanar texturing can be applied to the cubic meshes as well, and in some ways it can be considered to be even simpler. With cubic meshes the normal always points exactly along one of the main axes, and so it is not necessary to sample the texture three times nor to blend the results. Instead you can use conditional branching in the fragment shader to determine which pair of values out of {x,y,z} should be used as the texture coordinates. Something like:
.. code-block:: glsl .. sourcecode:: glsl
vec4 sample = vec4(0, 0, 0, 0); // We'll fill this in below vec4 sample = vec4(0, 0, 0, 0); // We'll fill this in below
// Assume the normal is normalised. // Assume the normal is normalised.
@ -67,11 +67,11 @@ Using the material identifier
----------------------------- -----------------------------
So far we have assumed that only a single material is being used for the entire voxel world, but this is seldom the case. It is common to associate a particular material with each voxel so that it can represent rock, wood, sand or any other type of material as required. The usual approach is to store a simple integer identifier with each voxel, and then map this identifier to material properties within your application. So far we have assumed that only a single material is being used for the entire voxel world, but this is seldom the case. It is common to associate a particular material with each voxel so that it can represent rock, wood, sand or any other type of material as required. The usual approach is to store a simple integer identifier with each voxel, and then map this identifier to material properties within your application.
Both the CubicSurfaceExtractor and the MarchingCubesSurfacExtractor understand the concept of a material being associated with a voxel, and they will take this into account when generating a mesh. Specifically, they will both copy the material identifier into the vertex data of the output mesh, so you can pass it through to your shaders and use it to affect the way the surface is rendered. Both extractCubicSurface() and the extractMarchingCubesSurface() include a 'data' member in their vertices, and this is copied/interpolated directly from the corresponding voxels. Therefore you can store a material identifier as part of your voxel type, and then pass this through to your shader as a vertex attribute. You can then use this to affect the way the surface is rendered.
The following code snippet assumes that you have passed the material identifier to your shaders and that you can access it in the fragment shader. It then chooses which colour to draw the polygon based on this identifier: The following code snippet assumes that you have passed a material identifier to your shaders and that you can access it in the fragment shader. It then chooses which colour to draw the polygon based on this identifier:
.. code-block:: glsl .. sourcecode:: glsl
vec4 fragmentColour = vec4(1, 1, 1, 1); // Default value vec4 fragmentColour = vec4(1, 1, 1, 1); // Default value
if(materialId < 0.5) //Avoid '==' when working with floats. if(materialId < 0.5) //Avoid '==' when working with floats.
@ -92,17 +92,13 @@ The following code snippet assumes that you have passed the material identifier
This is a very simple example, and such use of conditional branching within the shader may not be the best approach as it incurs some performance overhead and becomes unwieldy with a large number of materials. Other approaches include encoding a colour directly into the material identifier, or using the identifier as an index into a texture atlas or array. This is a very simple example, and such use of conditional branching within the shader may not be the best approach as it incurs some performance overhead and becomes unwieldy with a large number of materials. Other approaches include encoding a colour directly into the material identifier, or using the identifier as an index into a texture atlas or array.
Note that PolyVox currently stores that material identifier for the vertex as a float, but this will probably change in the future to use the same type as is stored in the volume. It will then be up to you which type you pass to the GPU (older GPUs may not support integer values) but if you do use floats then watch out for precision issues and avoid equality comparisons.
Blending between materials Blending between materials
-------------------------- --------------------------
An additional complication when working with smooth voxel terrain is that it is usually desirable to blend smoothly between adjacent voxels with different materials. This situation does not occur with cubic meshes because the texture is considered to be per-face instead of per-vertex, and PolyVox enforces this by ensuring that all the vertices of a given face have the same material. An additional complication when working with smooth voxel terrain is that it is usually desirable to blend smoothly between adjacent voxels with different materials. This situation does not occur with cubic meshes because the texture is considered to be per-face instead of per-vertex, and PolyVox enforces this by ensuring that all the vertices of a given face have the same material.
With a smooth mesh it is possible for each of the three vertices of any given triangle to have different material identifiers. If this is not explicitly handled then the graphics hardware will interpolate these material values across the face of the triangle. Fundamentally, the concept of interpolating between material identifiers does not make sense, because if we have (for example) 1='grass', 2='rock' and 3='sand' then it does not make sense to say rock is the average of grass and sand. With a smooth mesh it is possible for each of the three vertices of any given triangle to have different material identifiers. If this is not explicitly handled then the graphics hardware will interpolate these material values across the face of the triangle. Fundamentally, the concept of interpolating between material identifiers does not make sense, because if we have (for example) 1='grass', 2='rock' and 3='sand' then it does not make sense to say rock is the average of grass and sand.
Correctly handling of this is a surprising difficult problem. For now, the best approach is described in our article 'Volumetric representation of virtual terrain' which appeared in Game Engine Gems Volume 1 and which is freely available through the Google Books preview here: http://books.google.com/books?id=WNfD2u8nIlIC&lpg=PR1&dq=game%20engine%20gems&pg=PA39#v=onepage&q&f=false Correctly handling of this is a surprising difficult problem. For now, one approach is described in our article 'Volumetric representation of virtual terrain' which appeared in Game Engine Gems Volume 1 and which is freely available through the Google Books preview here: http://books.google.com/books?id=WNfD2u8nIlIC&lpg=PR1&dq=game%20engine%20gems&pg=PA39#v=onepage&q&f=false
As off October 2012 we are actively researching alternative solutions to this problem though it will be some time before the results become available.
Actual implementation of these material blending approaches is left as an exercise to the reader, though it is possible that in the future we will add some utility functions to PolyVox to assist with tasks such as splitting the mesh or adding the required extra vertex attributes. Our test implementations have performed the mesh processing on the CPU before the mesh is uploaded to the graphics card, but it does seem like there is a lot of potential for implementing these approaches in the geometry shader. Actual implementation of these material blending approaches is left as an exercise to the reader, though it is possible that in the future we will add some utility functions to PolyVox to assist with tasks such as splitting the mesh or adding the required extra vertex attributes. Our test implementations have performed the mesh processing on the CPU before the mesh is uploaded to the graphics card, but it does seem like there is a lot of potential for implementing these approaches in the geometry shader.
@ -110,7 +106,7 @@ Storage of textures
=================== ===================
The other major challenge in texturing voxel based geometry is handling the large number of textures which such environments often require. As an example, a game like Minecraft has hundreds of different material types each with their own texture. The traditional approach to mesh texturing is to bind textures to *texture units* on the GPU before rendering a batch, but even modern GPUs only allow between 16-64 textures to be bound at a time. In this section we discuss various solutions to overcoming this limitation. The other major challenge in texturing voxel based geometry is handling the large number of textures which such environments often require. As an example, a game like Minecraft has hundreds of different material types each with their own texture. The traditional approach to mesh texturing is to bind textures to *texture units* on the GPU before rendering a batch, but even modern GPUs only allow between 16-64 textures to be bound at a time. In this section we discuss various solutions to overcoming this limitation.
There are various trade offs involved, but if you are targeting hardware with support for *texture arrays* (available from OpenGL 3 and Direct3D 10 on-wards) then we can save you some time and tell you that they are almost certainly the best solution. Otherwise you have to understand the various pros and cons of the other approaches described below. There are various trade offs involved, but if you are targeting hardware with support for *texture arrays* (available from OpenGL 3 and Direct3D 10 onwards) then we can save you some time and tell you that they are almost certainly the best solution. Otherwise you have to understand the various pros and cons of the other approaches described below.
Separate texture units Separate texture units
---------------------- ----------------------
@ -122,7 +118,7 @@ If your required number of textures do indeed exceed the available number of tex
A more practical approach would be to break the mesh into a smaller number of pieces such that each mesh uses several textures but less than the maximum number of texture units. For example, our mesh with one hundred materials could be split into ten meshes, the first of which contains those triangles using materials 0-9, the seconds contains those triangles using materials 10-19, and so forth. There is a trade off here between the number of batches and the number of textures units used per batch. A more practical approach would be to break the mesh into a smaller number of pieces such that each mesh uses several textures but less than the maximum number of texture units. For example, our mesh with one hundred materials could be split into ten meshes, the first of which contains those triangles using materials 0-9, the seconds contains those triangles using materials 10-19, and so forth. There is a trade off here between the number of batches and the number of textures units used per batch.
Furthermore, you could realise that although your terrain may use hundreds of different textures, any given region is likely to use only a small fraction of those. We have yet to experiment with this, but it seems if you region uses only (for example) materials 12, 47, and 231, then you could conceptually map these materials to the first three textures slots. This means that for each region you draw the mapping between material IDs and texture units would be different. This may require some complex logic in the application but could allow you to do much more with only a few texture units. We will investigate this further in the future. Furthermore, you could realise that although your terrain may use hundreds of different textures, any given region is likely to use only a small fraction of those. We have yet to experiment with this, but it seems if you region uses only (for example) materials 12, 47, and 231, then you could conceptually map these materials to the first three textures slots. This means that for each region you draw the mapping between material IDs and texture units would be different. This may require some complex logic in the application but could allow you to do much more with only a few texture units.
Texture atlases Texture atlases
--------------- ---------------
@ -138,7 +134,7 @@ It is possible to combat these problems but the solutions are non-trivial. You w
3D texture slices 3D texture slices
----------------- -----------------
The idea here is similar to the texture atlas approach, but rather than packing texture side-by-side in an atlas they are instead packed as slices in a 3D texture. We haven't actually tested this but in theory it may have a couple of benefits. Firstly, it simplifies the addressing of the texture as there is no need to offset/scale the UV coordinates, and the W coordinate (the slice index) can be more easily computed from the material identifier. Secondly, a single volume texture will usually be able to hold more texels than a single 2D texture (for example, 512x512x512 is bigger than 4096x4096). Lastly, it should simplify the filtering problem as packed textures are no longer tiled and so should wrap correctly. The idea here is similar to the texture atlas approach, but rather than packing textures side-by-side in an atlas they are instead packed as slices in a 3D texture. We haven't actually tested this but in theory it may have a couple of benefits. Firstly, it simplifies the addressing of the texture as there is no need to offset/scale the UV coordinates, and the W coordinate (the slice index) can be more easily computed from the material identifier. Secondly, a single volume texture will usually be able to hold more texels than a single 2D texture (for example, 512x512x512 is bigger than 4096x4096). Lastly, it should simplify the filtering problem as packed textures are no longer tiled and so should wrap correctly.
However, MIP mapping will probably be more complex than the texture atlas case because even the first MIP level will involve combining adjacent slices. Volume textures are also not so widely supported and may be particularly problematic on mobile hardware. However, MIP mapping will probably be more complex than the texture atlas case because even the first MIP level will involve combining adjacent slices. Volume textures are also not so widely supported and may be particularly problematic on mobile hardware.

View File

@ -27,30 +27,30 @@ C++ does provide the 'volatile' keyword which can be used to ensure a variable i
Lastly, note that PolyVox volumes are templatised which means the voxel type might be something other than a simple int. However we don't think this actually makes a difference given that so few guarantees are made anyway, and it should still be safe to perform multiple concurrent reads for more complex types. Lastly, note that PolyVox volumes are templatised which means the voxel type might be something other than a simple int. However we don't think this actually makes a difference given that so few guarantees are made anyway, and it should still be safe to perform multiple concurrent reads for more complex types.
LargeVolume PagedVolume
----------- -----------
The LargeVolume provides even less thread safety than the RawVolume, in that even concurrent read operations can cause problems. The reason for this is the more complex memory management which is performed behind the scenes, and which allows pieces of volume data to be moved around and deleted. For example, a read of a single voxel may mean that the block of data associated with that voxel has to be paged in to memory, which in turn may mean that another block of data has to be paged out of memory. If second thread was halfway through reading a voxel in this second block of data then a problem will occur. The PagedVolume provides even less thread safety than the RawVolume, in that even concurrent read operations can cause problems. The reason for this is the more complex memory management which is performed behind the scenes, and which allows pieces of volume data to be moved around and deleted. For example, a read of a single voxel may mean that the block of data associated with that voxel has to be paged in to memory, which in turn may mean that another block of data has to be paged out of memory. If second thread was halfway through reading a voxel in this second block of data then a problem will occur.
In the future we may do a more comprehensive analysis of thread safety in the LargeVolume, but for now you should assume that any multithreaded access can cause problems. In the future we may do a more comprehensive analysis of thread safety in the PagedVolume, but for now you should assume that any multithreaded access can cause problems.
Consequences of abuse Consequences of abuse
--------------------- ---------------------
We have outlined above the rules for multithreaded access of volumes, but what actually happens if you violate these? There's a couple of things to watch out for: We have outlined above the rules for multithreaded access of volumes, but what actually happens if you violate these? There's a couple of things to watch out for:
- As mentioned, performing unprotected writes to the volume can cause problems because the data may be copied into the CPU cache and/or registers, and so a subsequent read could retrieve the old value. This is not what you want but probably won't be fatal (i.e. it shouldn't crash). It would basically manifest itself as data corruption. - As mentioned, performing unprotected writes to the volume can cause problems because the data may be copied into the CPU cache and/or registers, and so a subsequent read could retrieve the old value. This is not what you want but probably won't be fatal (i.e. it shouldn't crash). It would basically manifest itself as data corruption.
- If you access the LargeVolume in a multithreaded fashion then you risk trying to access data which has been removed by another thread, and in this case you will get undefined behaviour. This will probably be a crash (out of bounds access) but really anything could happen. - If you access the PagedVolume in a multithreaded fashion then you risk trying to access data which has been removed by another thread, and in this case you will get undefined behaviour. This will probably be a crash (out of bounds access) but really anything could happen.
Surface Extraction Surface Extraction
================== ==================
Despite the lack of thread safety built in to PolyVox, it is still possible and often desirable to make use of multiple threads for tasks such as surface extraction. Performing surface extraction does not require write access to the data, and we've already established that you can safely perform reads from different threads *provided you are not using the LargeVolume*. Despite the lack of thread safety built in to PolyVox, it is still possible and often desirable to make use of multiple threads for tasks such as surface extraction. Performing surface extraction does not require write access to the data, and we've already established that you can safely perform reads from different threads *provided you are not using the PagedVolume*.
Combining multiple surface extraction threads with the *LargeVolume* is something we will need to experiment with in the future, to determine how it can be improved. Combining multiple surface extraction threads with the *PagedVolume* is something we will need to experiment with in the future, to determine how it can be improved.
In the future we will expand this section to discuss how to split surface extraction across a number of threads, but for now please see Section XX of the book chapter 'Volumetric Representation of Virtual environments', available for free here: http://books.google.nl/books?id=WNfD2u8nIlIC&lpg=PR1&dq=game+engine+gems&pg=PA39&redir_esc=y#v=onepage&q&f=false In the future we will expand this section to discuss how to split surface extraction across a number of threads, but for now please see Section 3.4.3 of the book chapter 'Volumetric Representation of Virtual environments', available for free here: http://books.google.nl/books?id=WNfD2u8nIlIC&lpg=PR1&dq=game+engine+gems&pg=PA39&redir_esc=y#v=onepage&q&f=false
GPU thread safety GPU thread safety
================= =================
Be aware that even if you successfully perform surface across multiple threads you still need to take care when uploading the data to the GPU. For Direct3D 9.0 and OpenGL 2.0 it is only possible to upload data from the main thread (or more accurately the one which owns the rendering context). So after you have performed your multi-threaded surface extraction you need to bring the data back to the main thread for uploading to the GPU. Be aware that even if you successfully perform surface extraction across multiple threads then you still need to take care when uploading the data to the GPU. For Direct3D 9.0 and OpenGL 2.0 it is only possible to upload data from the main thread (or more accurately the one which owns the rendering context). So after you have performed your multi-threaded surface extraction you need to bring the data back to the main thread for uploading to the GPU.
More recent versions of the Direct3D and OpenGL APIs lift this restriction and provide means of accessing GPU resources from multiple threads. Please consult the documentation for your API for details. More recent versions of the Direct3D and OpenGL APIs lift this restriction and provide means of accessing GPU resources from multiple threads. Please consult the documentation for your API for details.

62
documentation/Volumes.rst Normal file
View File

@ -0,0 +1,62 @@
*******
Volumes
*******
The volume classes are the heart and soul of Polyvox, providing storage for the huge amounts of data which volumetric environments often require.
Volume concepts
===============
The main volume classes
=======================
Basic access to volume data
===========================
At the simplest level, individual voxels can be read and written by the getVoxel() and setVoxel() member functions which exist for each volume. We will focus on reading voxels first.
Reading voxels
--------------
The easiest way to read a particular voxel is as follows:
.. sourcecode :: c++
RawVolume<uint8_t>* volume = ... // Get a volume from somewhere.
uint8_t uVoxelValue = volume->getVoxel(x, y, z); // Read the voxel at the given position.
This works great as long as the provided position (x, y, z) does actually represent a valid position inside the volume. If this is not the case then the default behaviour is to throw an exception, so you should be prepared to handle this if you are not certain the position is valid.
Alternatively you can modify the behaviour which occurs when a position is outside the volume by providing a WrapMode as a fourth parameter to getVoxel(). For example:
.. sourcecode :: c++
// This will return the voxel, or '42' if the position is outside the volume
uint8_t uVoxelValue = volume->getVoxel(x, y, z, WrapModes::Border, 42);
Please see the documentation for WrapMode for more information on the avaiable options here. Note in particular that WrapModes::AssumeValid can be used to skip any bounds checking and so you should use this *if you are certain* that you are accessing a valid position, as it may be noticably faster in some cases.
.. sourcecode :: c++
// This will result in undefined behaviour if the position is outside the volume
uint8_t uVoxelValue = volume->getVoxel(x, y, z, WrapModes::AssumeValid);
Fast access to voxel data is very important in PolyVox, but the above functions have a drawback in that they need to contain logic to evaluate the provided WrapMode and decide how to proceed. This introduces branching into the execution flow and results in larger functions which may prevent inlining. For even more speed you can use version of the above functions which are templatised on the WrapMode rather than taking it as a parameter. This means the condition can be evaluated at compile time rather than run time: For example:
.. sourcecode :: c++
// This will return the voxel, or '42' if the position is outside the volume
uint8_t uVoxelValue = volume->getVoxel<WrapModes::Border>(x, y, z, 42);
Writing voxels
--------------
The setVoxel() function is used for writting to voxels instread of reading from them, and besides this it has two main behavoural differences when compared to getVoxel(). The first difference is that it is not templatised because the speed of setVoxel() is typically less important than getVoxel() (as writing to voxels is much less common than reading from them). However, we could add these temlatised version in the future if they are needed.
The second difference is that certain wrap modes such as WrapModes::Border or WrapModes::Clamp do not make much sense when writting to voxel data, and so these are no permitted and will result in an exception being thrown. You should only use WrapModes::Validate (the default) and WrapModes::AssumeValid. For example:
.. sourcecode :: c++
RawVolume<uint8_t>* volume = ... // Get a volume from somewhere.
volume->setVoxel(x, y, z, 57); // Write the voxel at the given position.
volume->setVoxel(x, y, z, 57, WrapMopdes::AssumeValid); // No bounds checks
Notes on error handling and performance
---------------------------------------
Overall, you should set the wrap mode to WrapModes::AssumeValid for maximum performance (and use templatised versions where available), but note that even this fast version does still contain a POLYVOX_ASSERT() to try and catch mistakes. It appears that this assert prevents inlining (probably due to the logging it performs), but it is anticipated that you will disable such asserts in the final build of your software.

View File

@ -41,7 +41,7 @@ master_doc = 'index'
# General information about the project. # General information about the project.
project = u'PolyVox' project = u'PolyVox'
copyright = u'2010, David Williams, Matt Williams' copyright = u'2013, David Williams, Matt Williams'
# The version info for the project you're documenting, acts as replacement for # The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the # |version| and |release|, also used in various other places throughout the

View File

@ -14,7 +14,7 @@ User Guide:
ModifyingTerrain ModifyingTerrain
LevelOfDetail LevelOfDetail
Threading Threading
ErrorHandling
Examples: Examples:
@ -22,6 +22,7 @@ Examples:
:maxdepth: 1 :maxdepth: 1
tutorial1 tutorial1
python-bindings
Other Information: Other Information:

View File

@ -3,12 +3,10 @@ Principles of PolyVox
********************** **********************
.. warning :: .. warning ::
This section is being written and is just a skeleton for now This section is yet to be fully written and is just a skeleton for now.
PolyVox provides a library for managing 3D arrays (volumes) of data (voxels). It gives you the tools to iterate through, randomly access, read and write volumes. It supports any type you'd like to represent each voxel whether it's just an ``int`` or a class which encapsulates both density and colour. PolyVox provides a library for managing 3D arrays (volumes) of data (voxels). It gives you the tools to iterate through, randomly access, read and write volumes. The volumes are templatized on voxel type, so that each voxel can be as simple as just an number or as complex as a class with a range of properties.
Once you have a volume, PolyVox provides a number of tools for turning it into something that you can pass to your rendering engine. These are called `surface extractors`. Once you have created a volume, PolyVox provides a number of tools for turning it into a mesh that you can pass to your rendering engine. These are called `surface extractors`. A 'Marching Cubes' surface extractor and a 'cubic' (Minecraft-style) surface extractor are included, and it is possible to write your own.
Each surface extractor needs to be told how to interperet your voxel type and that is done using... PolyVox primarily handles this task of storing volume data and extracting surfaces from it. Most other aspects of you voxel application or game will need to be implemented by you (rendering, logic, physics, AI, networking, etc) though PolyVox does have a few utility classes for things like the A* algorithm on a 3D grid.
Link to a page describing how to write your own voxel type and link it to a surface extractor...

View File

@ -0,0 +1,139 @@
***************
Python bindings
***************
Introduction
============
PolyVox itself is a C++ library but in order to make it useful to as many people as possible, we also provide bindings to a number of other languages.
These bindings are all generated by `SWIG <http://swig.org>`_ and provide a bridge to a compiled PolyVox library (*DLL* or *.so*) via an interafce which is native to the language.
This allows you in a Python script to simpy call ``import PolyVoxCore`` and get access to the whole library's functionality.
The Python bindings are available for Python 3.
Comparison with C++
-------------------
All the bindings available for PolyVox (so both the Python bindings and any future supported bindings such as for C♯) follow the PolyVox C++ API quite closely.
This means that many PolyVox code examples written in C++ are mostly applicable also to Python.
Classes and functions are named the same and take the same set of arguments.
The main place this falls down is with templated C++ classes.
Since C++ templates are essentially a code-generation system built into the C++ compiler there is no way for a user of the Python bindings to request, at run-time, a specific piece of code to be generated.
The way we work around this is by, as part of the bindings generation process, pre-compiling a number of different versions of each templated class.
For example, in C++ a 3D vector containing 32-bit integers would be declared as
.. sourcecode:: c++
PolyVox::Vector3D<int32_t> my_vec(0,1,4);
but in Python it would be accessed as
.. sourcecode:: python
my_vec = PolyVoxCore.Vector3Dint32_t(0,1,4)
As a rule, any time in C++ where you see a template instantiation with ``<>``, just remove the angle brackets and it will yield the Python class name.
The choice of which C++ templates to instantiate is made by the developers of PolyVox in order to try to cover the main use-cases that library users would have.
If, however, you want to add your own versions, this can be done by editing the SWIG interface files and recompiling PolyVox.
Buildings the bindings
======================
The bindings are built as part of the standard PolyVox build process. For details on this please follow the instructions at :doc:`install`.
The important things to note there are the requirements for building the bindings: *Python development libraries* and *SWIG*.
During the CMake phase of building, it should tell you whether or not the bindings will be built.
Compiling the whole PolyVox library should then give you two files inside the ``build/library/bindings`` directory:
``PolyVoxCore.py``
This is the main entry point to the library.
``_PolyVoxCore.so`` (or ``.dll`` on Windows)
This contains the compiled code of the PolyVox library.
This file has a link dependency the main ``libPolyVoxCore.so`` library as well as the Python shared library.
Using the bindings
==================
As discussed above, the Python API is very similar to the C++ one but none-the-less we'll go through an example to see how it works.
All the code in this section is taken from ``PythonExample.py`` found in the source distribution of PolyVox in the ``examples/Python`` folder.
Seting up the volume
--------------------
The first this we do is import the ``PolyVoxCore`` module. We rename it as ``pv`` to make our life easier.
.. literalinclude:: ../examples/Python/PythonExample.py
:language: python
:lines: 29
We create a ``Region`` from two vectors defining the bounds of the area - a volume 64×64×64.
Remember that ``pv.Vector3Dint32_t`` refers to a 3D :polyvox:`PolyVox::Vector` templated on a 32-bit integer.
The second line creates a :polyvox:`SimpleVolume` of the same size as the :polyvox:`Region` where each voxel in the volume is defined an unsigned 8-bit integer.
.. literalinclude:: ../examples/Python/PythonExample.py
:language: python
:lines: 31-33
We're going to fill our volume with a sphere and so we start by finding out where the centre of the volume is and defining the radius of our desired shape.
.. literalinclude:: ../examples/Python/PythonExample.py
:language: python
:lines: 35-37
Then we actually loop over each of the dimensions of the volume such that inside the loop, ``x``, ``y`` and ``z`` refer to the current location.
.. literalinclude:: ../examples/Python/PythonExample.py
:language: python
:lines: 38-41
All we do inside the loop is set all the voxels inside the sphere to have a value of ``255`` and all those outside to have a value of ``0``.
.. literalinclude:: ../examples/Python/PythonExample.py
:language: python
:lines: 42-53
Getting the mesh data
---------------------
Extracting the surface mesh for the volume is a two-step process.
First we tell PolyVox to generate the appropriate mesh, then we have to convert the PolyVox mesh data to something that our rendering library can understand.
First we define the sort of mesh that we want. For this example we want a mesh with information on the position, material and normal of each vertex.
Once we have out mesh object ready to be filled, we pass it to our surface extractor of choice.
PolyVox comes with a number of different surface extractors but for our example here, we want a cubic mesh.
You should also note that the ungainly looking ``CubicSurfaceExtractorWithNormalsSimpleVolumeuint8`` refers to the C++ class ``CubicSurfaceExtractorWithNormals<SimpleVolume<uint8_t>>``.
The ``execute()`` call is when PolyVox actually goes off and generates the requested mesh based on the data contained in the volume.
.. literalinclude:: ../examples/Python/PythonExample.py
:language: python
:lines: 55-58
Up until this point, the Python code has been totally generic with respect to your choice of rendering engine.
For this example we will be using `PyOpenGL <http://pyopengl.sourceforge.net/>`_ as it provides a nice pythonic API for many OpenGL functions.
Regardless of which rendering engine you are using, you will need to be able to wrangle the PolyVox mesh output into something you can insert into your engine.
In our case, we want two lists:
1. All the vertices along with their normals
2. The vertex indices which describes how the vertices are put together to make triangles.
PyOpenGL undersands `NumPy <http://numpy.org>`_ arrays and so we are going to copy our vertex data into two of these.
:polyvox:`SurfaceMesh` provides two useful functions here, ``getIndices()`` and ``getVertices()``, the Python versions of which return Python tuples.
The indices we can pass directly to NumPy as long as we make sure we specify the correct type for the data inside.
For the vertices, we want to rearange the data so that OpenGL can read it more efficiently.
To this end we explicitly retrieve the vertex positions and normals for each vertex and place them
such that the vertex ``x``, ``y`` and ``z`` positions are placed contiguously in memory followed by the normal vector's ``x``, ``y`` and ``z`` values.
.. literalinclude:: ../examples/Python/PythonExample.py
:language: python
:lines: 62-69
From this point on in the example, PolyVox is no longer used directly and all the code is standard PyOpenGL.
I won't go through every line here but the source code in ``PythonExample.py`` is commented and should be sufficient to understand how things work.

View File

@ -12,32 +12,32 @@ Creating a volume
================= =================
To get started, we need to include the following headers: To get started, we need to include the following headers:
.. code-block:: c++ .. sourcecode:: c++
#include "PolyVoxCore/CubicSurfaceExtractorWithNormals.h" #include "PolyVox/CubicSurfaceExtractor.h"
#include "PolyVoxCore/MarchingCubesSurfaceExtractor.h" #include "PolyVox/MarchingCubesSurfaceExtractor.h"
#include "PolyVoxCore/SurfaceMesh.h" #include "PolyVox/Mesh.h"
#include "PolyVoxCore/SimpleVolume.h" #include "PolyVox/RawVolume.h"
The most fundamental construct when working with PolyVox is that of the volume. This is represented by the :polyvox:`SimpleVolume` class which stores a 3D grid of voxels. Our basic example application creates a volume with the following line of code: The most fundamental construct when working with PolyVox is that of the volume. This is represented by the :polyvox:`RawVolume` class which stores a 3D grid of voxels. Our basic example application creates a volume with the following line of code:
.. code-block:: c++ .. sourcecode:: c++
SimpleVolume<uint8_t> volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63))); RawVolume<uint8_t> volData(PolyVox::Region(Vector3DInt32(0, 0, 0), Vector3DInt32(63, 63, 63)));
As can be seen, the SimpleVolume class is templated upon the voxel type. This means it is straightforward to create a volume of integers, floats, or a custom voxel type (see the :polyvox:`SimpleVolume documentation <PolyVox::SimpleVolume>` for more details). In this particular case we have created a volume in which each voxel is of type `uint8_t` which is an unsigned 8-bit integer. As can be seen, the RawVolume class is templated upon the voxel type. This means it is straightforward to create a volume of integers, floats, or a custom voxel type (see the :polyvox:`RawVolume documentation <PolyVox::RawVolume>` for more details). In this particular case we have created a volume in which each voxel is of type `uint8_t` which is an unsigned 8-bit integer.
Next, we set some of the voxels in the volume to be 'solid' in order to create a large sphere in the centre of the volume. We do this with the following function call: Next, we set some of the voxels in the volume to be 'solid' in order to create a large sphere in the centre of the volume. We do this with the following function call:
.. code-block:: c++ .. sourcecode:: c++
createSphereInVolume(volData, 30); createSphereInVolume(volData, 30);
Note that this function is part of the BasicExample (rather than being part of the PolyVox library) and is implemented as follows: Note that this function is part of the BasicExample (rather than being part of the PolyVox library) and is implemented as follows:
.. code-block:: c++ .. sourcecode:: c++
void createSphereInVolume(SimpleVolume<uint8_t>& volData, float fRadius) void createSphereInVolume(RawVolume<uint8_t>& volData, float fRadius)
{ {
//This vector hold the position of the center of the volume //This vector hold the position of the center of the volume
Vector3DFloat v3dVolCenter(volData.getWidth() / 2, volData.getHeight() / 2, volData.getDepth() / 2); Vector3DFloat v3dVolCenter(volData.getWidth() / 2, volData.getHeight() / 2, volData.getDepth() / 2);
@ -50,117 +50,145 @@ Note that this function is part of the BasicExample (rather than being part of t
for (int x = 0; x < volData.getWidth(); x++) for (int x = 0; x < volData.getWidth(); x++)
{ {
//Store our current position as a vector... //Store our current position as a vector...
Vector3DFloat v3dCurrentPos(x,y,z); Vector3DFloat v3dCurrentPos(x, y, z);
//And compute how far the current position is from the center of the volume //And compute how far the current position is from the center of the volume
float fDistToCenter = (v3dCurrentPos - v3dVolCenter).length(); float fDistToCenter = (v3dCurrentPos - v3dVolCenter).length();
uint8_t uVoxelValue = 0; uint8_t uVoxelValue = 0;
//If the current voxel is less than 'radius' units from the center then we make it solid. //If the current voxel is less than 'radius' units from the center then we make it solid.
if(fDistToCenter <= fRadius) if (fDistToCenter <= fRadius)
{ {
//Our new voxel value //Our new voxel value
uVoxelValue = 255; uVoxelValue = 255;
} }
//Wrte the voxel value into the volume //Wrte the voxel value into the volume
volData.setVoxelAt(x, y, z, uVoxelValue); volData.setVoxel(x, y, z, uVoxelValue);
} }
} }
} }
} }
This function takes as input the :polyvox:`SimpleVolume` in which we want to create the sphere, and also a radius specifying how large we want the sphere to be. In our case we have specified a radius of 30 voxels, which will fit nicely inside our :polyvox:`SimpleVolume` of dimensions 64x64x64. This function takes as input the :polyvox:`RawVolume` in which we want to create the sphere, and also a radius specifying how large we want the sphere to be. In our case we have specified a radius of 30 voxels, which will fit nicely inside our :polyvox:`RawVolume` of dimensions 64x64x64.
Because this is a simple example function it always places the sphere at the centre of the volume. It computes this centre by halving the dimensions of the volume as given by the functions :polyvox:`SimpleVolume::getWidth`, :polyvox:`SimpleVolume::getHeight` and :polyvox:`SimpleVolume::getDepth`. The resulting position is stored using a :polyvox:`Vector3DFloat`. This is simply a typedef from our templatised :polyvox:`Vector` class, meaning that other sizes and storage types are available if you need them. Because this is a simple example function it always places the sphere at the centre of the volume. It computes this centre by halving the dimensions of the volume as given by the functions :polyvox:`SimpleVolume::getWidth`, :polyvox:`SimpleVolume::getHeight` and :polyvox:`SimpleVolume::getDepth`. The resulting position is stored using a :polyvox:`Vector3DFloat`. This is simply a typedef from our templatised :polyvox:`Vector` class, meaning that other sizes and storage types are available if you need them.
Next, the function uses a three-level 'for' loop to iterate over each voxel in the volume. For each voxel it computes the distance from the voxel to the centre of the volume. If this distance is less than or equal to the specified radius then the voxel forms part of the sphere and is made solid. During surface extraction, the voxel will be considered empty if it has a value of zero, and otherwise it will be considered solid. In our case we simply set it to 255 which is the largest value a uint8_t can contain. Next, the function uses a three-level 'for' loop to iterate over each voxel in the volume. For each voxel it computes the distance from the voxel to the centre of the volume. If this distance is less than or equal to the specified radius then the voxel forms part of the sphere and is made solid.
Extracting the surface Extracting the surface
====================== ======================
Now that we have built our volume we need to convert it into a triangle mesh for rendering. This process can be performed by the :polyvox:`CubicSurfaceExtractorWithNormals` class. An instance of the :polyvox:`CubicSurfaceExtractorWithNormals` is created as follows: Now that we have built our volume we need to convert it into a triangle mesh for rendering. This process can be performed by the :polyvox:`extractCubicMesh` function:
.. code-block:: c++ .. sourcecode:: c++
SurfaceMesh<PositionMaterialNormal> mesh; auto mesh = extractCubicMesh(&volData, volData.getEnclosingRegion());
CubicSurfaceExtractorWithNormals< SimpleVolume<uint8_t> > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh);
The :polyvox:`CubicSurfaceExtractorWithNormals` takes a pointer to the volume data, and also it needs to be told which :polyvox:`Region` of the volume the extraction should be performed on (in more advanced applications this is useful for extracting only those parts of the volume which have been modified since the last extraction). For our purpose the :polyvox:`SimpleVolume` class provides a convenient :polyvox:`SimpleVolume::getEnclosingRegion` function which returns a :polyvox:`Region` representing the whole volume. The constructor also takes a pointer to a :polyvox:`SurfaceMesh` object where it will store the result, so we need to create one of these before we can construct the :polyvox:`CubicSurfaceExtractorWithNormals`. The :polyvox:`extractCubicMesh` function takes a pointer to the volume data, and also it needs to be told which :polyvox:`Region` of the volume the extraction should be performed on (in more advanced applications this is useful for extracting only those parts of the volume which have been modified since the last extraction). For our purpose the :polyvox:`RawVolume` class provides a convenient :polyvox:`RawVolume::getEnclosingRegion` function which returns a :polyvox:`Region` representing the whole volume.
The actual extraction happens in the :polyvox:`CubicSurfaceExtractorWithNormals::execute` function. This means you can set up a :polyvox:`CubicSurfaceExtractorWithNormals` with the required parameters and then actually execute it later. For this example we just call it straight away. The resulting mesh has a complex templatized type and so we assign it to a variable declared with 'auto', This way the compiler will determine the correct type for us. PolyVox also makes use of some compression techniques to store the vertex data in a compact way. Therefore the vertices of the mesh need to be decompressed ('decoded') before they can be used. For now the easiest approach is to use the provided ``decode()`` function, though advanced users can actually do this decoding on the GPU (see 'DecodeOnGPUExample'):
.. code-block:: c++ .. sourcecode:: c++
surfaceExtractor.execute(); auto decodedMesh = decodeMesh(mesh);
This fills in our :polyvox:`SurfaceMesh` object, which basically contains an index and vertex buffer representing the desired triangle mesh. Our ``decodedMesh`` variable contains an index and vertex buffer representing the desired triangle mesh.
Note: If you like you can try swapping the :polyvox:`CubicSurfaceExtractorWithNormals` for :polyvox:`MarchingCubesSurfaceExtractor`. We have already included the relevant header, and in the BasicExample you just need to change which line in commented out. The :polyvox:`MarchingCubesSurfaceExtractor` makes use of a smooth density field and will consider a voxel to be solid if it is above a threshold of half the voxel's maximum value (so in this case that's half of 255, which is 127). Note: If you like you can try swapping the :polyvox:`extractCubicMesh` for :polyvox:`extractMarchingCubesMesh`. We have already included the relevant header, and in the BasicExample you just need to change which line in commented out. The :polyvox:`MarchingCubesSurfaceExtractor` makes use of a smooth density field and will consider a voxel to be solid if it is above a threshold of half the voxel's maximum value (so in this case that's half of 255, which is 127).
Rendering the surface Rendering the surface
===================== =====================
Rendering the surface with OpenGL is handled by the OpenGLWidget class. Again, this is not part of PolyVox, it is simply an example based on Qt and OpenGL which demonstrates how rendering can be performed. Within this class there are mainly two functions which are of interest - the OpenGLWidget::setSurfaceMeshToRender() function which constructs OpenGL buffers from our :polyvox:`SurfaceMesh` and the OpenGLWidget::paintGL() function which is called each frame to perform the rendering. Rendering the surface with OpenGL is handled by our ``PolyVoxExample`` which is an ``OpenGLWidget`` subclass. Again, this is not part of PolyVox, it is simply an example based on Qt and OpenGL which demonstrates how rendering can be performed. Within this class there are mainly two functions which are of interest - the PolyVoxExample::addMesh() function which constructs OpenGL buffers from our :polyvox:`Mesh` and the PolyVoxExample::renderOneFrame() function which is called each frame to perform the rendering.
The OpenGLWidget::setSurfaceMeshToRender() function is implemented as follows: The PolyVoxExample::addMesh() function is implemented as follows:
.. code-block:: c++ .. sourcecode:: c++
void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PositionMaterialNormal>& surfaceMesh) template <typename MeshType>
void addMesh(const MeshType& surfaceMesh, const PolyVox::Vector3DInt32& translation = PolyVox::Vector3DInt32(0, 0, 0), float scale = 1.0f)
{ {
//Convienient access to the vertices and indices // This struct holds the OpenGL properties (buffer handles, etc) which will be used
const vector<uint32_t>& vecIndices = surfaceMesh.getIndices(); // to render our mesh. We copy the data from the PolyVox mesh into this structure.
const vector<PositionMaterialNormal>& vecVertices = surfaceMesh.getVertices(); OpenGLMeshData meshData;
//Build an OpenGL index buffer // Create the VAO for the mesh
glGenBuffers(1, &indexBuffer); glGenVertexArrays(1, &(meshData.vertexArrayObject));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer); glBindVertexArray(meshData.vertexArrayObject);
const GLvoid* pIndices = static_cast<const GLvoid*>(&(vecIndices[0]));
glBufferData(GL_ELEMENT_ARRAY_BUFFER, vecIndices.size() * sizeof(uint32_t), pIndices, GL_STATIC_DRAW);
//Build an OpenGL vertex buffer // The GL_ARRAY_BUFFER will contain the list of vertex positions
glGenBuffers(1, &vertexBuffer); glGenBuffers(1, &(meshData.vertexBuffer));
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, meshData.vertexBuffer);
const GLvoid* pVertices = static_cast<const GLvoid*>(&(vecVertices[0])); glBufferData(GL_ARRAY_BUFFER, surfaceMesh.getNoOfVertices() * sizeof(typename MeshType::VertexType), surfaceMesh.getRawVertexData(), GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(PositionMaterialNormal), pVertices, GL_STATIC_DRAW);
m_uBeginIndex = 0; // and GL_ELEMENT_ARRAY_BUFFER will contain the indices
m_uEndIndex = vecIndices.size(); glGenBuffers(1, &(meshData.indexBuffer));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, meshData.indexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, surfaceMesh.getNoOfIndices() * sizeof(typename MeshType::IndexType), surfaceMesh.getRawIndexData(), GL_STATIC_DRAW);
// Every surface extractor outputs valid positions for the vertices, so tell OpenGL how these are laid out
glEnableVertexAttribArray(0); // Attrib '0' is the vertex positions
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(typename MeshType::VertexType), (GLvoid*)(offsetof(typename MeshType::VertexType, position))); //take the first 3 floats from every sizeof(decltype(vecVertices)::value_type)
// Some surface extractors also generate normals, so tell OpenGL how these are laid out. If a surface extractor
// does not generate normals then nonsense values are written into the buffer here and sghould be ignored by the
// shader. This is mostly just to simplify this example code - in a real application you will know whether your
// chosen surface extractor generates normals and can skip uploading them if not.
glEnableVertexAttribArray(1); // Attrib '1' is the vertex normals.
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(typename MeshType::VertexType), (GLvoid*)(offsetof(typename MeshType::VertexType, normal)));
// Finally a surface extractor will probably output additional data. This is highly application dependant. For this example code
// we're just uploading it as a set of bytes which we can read individually, but real code will want to do something specialised here.
glEnableVertexAttribArray(2); //We're talking about shader attribute '2'
GLint size = (std::min)(sizeof(typename MeshType::VertexType::DataType), size_t(4)); // Can't upload more that 4 components (vec4 is GLSL's biggest type)
glVertexAttribIPointer(2, size, GL_UNSIGNED_BYTE, sizeof(typename MeshType::VertexType), (GLvoid*)(offsetof(typename MeshType::VertexType, data)));
// We're done uploading and can now unbind.
glBindVertexArray(0);
// A few additional properties can be copied across for use during rendering.
meshData.noOfIndices = surfaceMesh.getNoOfIndices();
meshData.translation = QVector3D(translation.getX(), translation.getY(), translation.getZ());
meshData.scale = scale;
// Set 16 or 32-bit index buffer size.
meshData.indexType = sizeof(typename MeshType::IndexType) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
// Now add the mesh to the list of meshes to render.
addMeshData(meshData);
} }
We begin by obtaining direct access to the index and vertex buffer in the :polyvox:`SurfaceMesh` class in order to make the following code slightly cleaner. Both the :polyvox:`SurfaceMesh::getIndices` and :polyvox:`SurfaceMesh::getVertices` functions return an std::vector containing the relevant data.
The OpenGL functions which are called to construct the index and vertex buffer are best explained by the OpenGL documentation. In both cases we are making an exact copy of the data stored in the :polyvox:`SurfaceMesh`.
The begin and end indices are used in the OpenGLWidget::paintGL() to control what part of the index buffer is actually rendered. For this simple example we will render the whole buffer from '0' to 'vecIndices.size()'.
With the OpenGL index and vertex buffers set up, we can now look at the code which is called each frame to render them: With the OpenGL index and vertex buffers set up, we can now look at the code which is called each frame to render them:
.. code-block:: c++ .. sourcecode:: c++
void OpenGLWidget::paintGL() void renderOneFrame() override
{ {
//Clear the screen // Our example framework only uses a single shader for the scene (for all meshes).
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); mShader->bind();
//Set up the viewing transformation // These two matrices are constant for all meshes.
glMatrixMode(GL_MODELVIEW); mShader->setUniformValue("viewMatrix", viewMatrix());
glLoadIdentity(); mShader->setUniformValue("projectionMatrix", projectionMatrix());
glTranslatef(0.0f,0.0f,-100.0f); //Centre volume and move back
glRotatef(-m_xRotation, 0.0f, 1.0f, 0.0f);
glRotatef(-m_yRotation, 1.0f, 0.0f, 0.0f);
glTranslatef(-32.0f,-32.0f,-32.0f); //Centre volume and move back
//Bind the index buffer // Iterate over each mesh which the user added to our list, and render it.
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer); for (OpenGLMeshData meshData : mMeshData)
{
//Set up the model matrrix based on provided translation and scale.
QMatrix4x4 modelMatrix;
modelMatrix.translate(meshData.translation);
modelMatrix.scale(meshData.scale);
mShader->setUniformValue("modelMatrix", modelMatrix);
//Bind the vertex buffer // Bind the vertex array for the current mesh
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); glBindVertexArray(meshData.vertexArrayObject);
glVertexPointer(3, GL_FLOAT, sizeof(PositionMaterialNormal), 0); // Draw the mesh
glNormalPointer(GL_FLOAT, sizeof(PositionMaterialNormal), (GLvoid*)12); glDrawElements(GL_TRIANGLES, meshData.noOfIndices, meshData.indexType, 0);
// Unbind the vertex array.
glBindVertexArray(0);
}
glDrawRangeElements(GL_TRIANGLES, m_uBeginIndex, m_uEndIndex-1, m_uEndIndex - m_uBeginIndex, GL_UNSIGNED_INT, 0); // We're done with the shader for this frame.
mShader->release();
//Error checking code here...
} }
Again, the explanation of this code is best left to the OpenGL documentation. Note that is is called automatically by Qt each time the display needs to be updated. Again, the explanation of this code is best left to the OpenGL documentation.

View File

@ -1,64 +1,62 @@
# Copyright (c) 2010-2012 David Williams ################################################################################
# The MIT License (MIT)
# #
# This software is provided 'as-is', without any express or implied # Copyright (c) 2015 Matthew Williams and David Williams
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
# #
# Permission is granted to anyone to use this software for any purpose, # Permission is hereby granted, free of charge, to any person obtaining a copy
# including commercial applications, and to alter it and redistribute it # of this software and associated documentation files (the "Software"), to deal
# freely, subject to the following restrictions: # in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# #
# 1. The origin of this software must not be misrepresented; you must not # The above copyright notice and this permission notice shall be included in all
# claim that you wrote the original software. If you use this software # copies or substantial portions of the Software.
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
# #
# 2. Altered source versions must be plainly marked as such, and must not be # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# misrepresented as being the original software. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# 3. This notice may not be removed or altered from any source # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# distribution. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
CMAKE_MINIMUM_REQUIRED(VERSION 2.6) # SOFTWARE.
################################################################################
PROJECT(BasicExample) PROJECT(BasicExample)
#Projects source files #Projects source files
SET(SRC_FILES SET(SRC_FILES
glew/glew.cpp
main.cpp main.cpp
OpenGLWidget.cpp ../common/PolyVoxExample.cpp
) )
#Projects headers files #Projects headers files
SET(INC_FILES SET(INC_FILES
glew/glew.h ../common/OpenGLWidget.h
glew/glxew.h ../common/OpenGLWidget.inl
glew/wglew.h ../common/PolyVoxExample.h
)
OpenGLWidget.h
)
ADD_DEFINITIONS(-DGLEW_STATIC)
#"Sources" and "Headers" are the group names in Visual Studio. #"Sources" and "Headers" are the group names in Visual Studio.
#They may have other uses too... #They may have other uses too...
SOURCE_GROUP("Sources" FILES ${SRC_FILES}) SOURCE_GROUP("Sources" FILES ${SRC_FILES})
SOURCE_GROUP("Headers" FILES ${INC_FILES}) SOURCE_GROUP("Headers" FILES ${INC_FILES})
FIND_PACKAGE(OpenGL REQUIRED)
#Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location) #Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location)
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_SOURCE_DIR}/include) INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxHeaders_SOURCE_DIR} ../common)
LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR})
#This will include the shader files inside the compiled binary
QT5_ADD_RESOURCES(COMMON_RESOURCES_RCC ../common/example.qrc)
# Put the resources in a seperate folder in Visual Studio
SOURCE_GROUP("Resource Files" FILES ../common/example.qrc ${COMMON_RESOURCES_RCC})
#Build #Build
ADD_EXECUTABLE(BasicExample ${SRC_FILES}) ADD_EXECUTABLE(BasicExample ${SRC_FILES} ${COMMON_RESOURCES_RCC})
IF(MSVC) IF(MSVC)
SET_TARGET_PROPERTIES(BasicExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") SET_TARGET_PROPERTIES(BasicExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") #All warnings
ENDIF(MSVC) ENDIF(MSVC)
TARGET_LINK_LIBRARIES(BasicExample ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) TARGET_LINK_LIBRARIES(BasicExample Qt5::OpenGL)
SET_PROPERTY(TARGET BasicExample PROPERTY FOLDER "Examples") SET_PROPERTY(TARGET BasicExample PROPERTY FOLDER "Examples")
#Install - Only install the example in Windows #Install - Only install the example in Windows

View File

@ -1,152 +0,0 @@
#include "OpenGLWidget.h"
#include <QMouseEvent>
using namespace PolyVox;
using namespace std;
OpenGLWidget::OpenGLWidget(QWidget *parent)
:QGLWidget(parent)
,m_xRotation(0)
,m_yRotation(0)
{
}
void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PositionMaterialNormal>& surfaceMesh)
{
//Convienient access to the vertices and indices
const vector<uint32_t>& vecIndices = surfaceMesh.getIndices();
const vector<PositionMaterialNormal>& vecVertices = surfaceMesh.getVertices();
//Build an OpenGL index buffer
glGenBuffers(1, &indexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
const GLvoid* pIndices = static_cast<const GLvoid*>(&(vecIndices[0]));
glBufferData(GL_ELEMENT_ARRAY_BUFFER, vecIndices.size() * sizeof(uint32_t), pIndices, GL_STATIC_DRAW);
//Build an OpenGL vertex buffer
glGenBuffers(1, &vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
const GLvoid* pVertices = static_cast<const GLvoid*>(&(vecVertices[0]));
glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(PositionMaterialNormal), pVertices, GL_STATIC_DRAW);
m_uBeginIndex = 0;
m_uEndIndex = vecIndices.size();
}
void OpenGLWidget::initializeGL()
{
//We need GLEW to access recent OpenGL functionality
std::cout << "Initialising GLEW...";
GLenum result = glewInit();
if (result == GLEW_OK)
{
std::cout << "success" << std::endl;
}
else
{
/* Problem: glewInit failed, something is seriously wrong. */
std::cout << "failed" << std::endl;
std::cout << "Initialising GLEW failed with the following error: " << glewGetErrorString(result) << std::endl;
exit(EXIT_FAILURE);
}
//Print out some information about the OpenGL implementation.
std::cout << "OpenGL Implementation Details:" << std::endl;
if(glGetString(GL_VENDOR))
std::cout << "\tGL_VENDOR: " << glGetString(GL_VENDOR) << std::endl;
if(glGetString(GL_RENDERER))
std::cout << "\tGL_RENDERER: " << glGetString(GL_RENDERER) << std::endl;
if(glGetString(GL_VERSION))
std::cout << "\tGL_VERSION: " << glGetString(GL_VERSION) << std::endl;
if(glGetString(GL_SHADING_LANGUAGE_VERSION))
std::cout << "\tGL_SHADING_LANGUAGE_VERSION: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;
//Check our version of OpenGL is recent enough.
//We need at least 1.5 for vertex buffer objects,
if (!GLEW_VERSION_1_5)
{
std::cout << "Error: You need OpenGL version 1.5 to run this example." << std::endl;
exit(EXIT_FAILURE);
}
//Set up the clear colour
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
//Enable the depth buffer
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
//Anable smooth lighting
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glShadeModel(GL_SMOOTH);
//We'll be rendering with index/vertex arrays
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
}
void OpenGLWidget::resizeGL(int w, int h)
{
//Setup the viewport
glViewport(0, 0, w, h);
//Set up the projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
float frustumSize = 32.0f; //Half the volume size
float aspect = static_cast<float>(width()) / static_cast<float>(height());
glOrtho(frustumSize*aspect, -frustumSize*aspect, frustumSize, -frustumSize, 1.0, 1000);
}
void OpenGLWidget::paintGL()
{
//Clear the screen
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//Set up the viewing transformation
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-100.0f); //Centre volume and move back
glRotatef(-m_xRotation, 0.0f, 1.0f, 0.0f);
glRotatef(-m_yRotation, 1.0f, 0.0f, 0.0f);
glTranslatef(-32.0f,-32.0f,-32.0f); //Centre volume and move back
//Bind the index buffer
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
//Bind the vertex buffer
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glVertexPointer(3, GL_FLOAT, sizeof(PositionMaterialNormal), 0);
glNormalPointer(GL_FLOAT, sizeof(PositionMaterialNormal), (GLvoid*)12);
glDrawRangeElements(GL_TRIANGLES, m_uBeginIndex, m_uEndIndex-1, m_uEndIndex - m_uBeginIndex, GL_UNSIGNED_INT, 0);
GLenum errCode = glGetError();
if(errCode != GL_NO_ERROR)
{
//What has replaced getErrorString() in the latest OpenGL?
std::cout << "OpenGL Error: " << errCode << std::endl;
}
}
void OpenGLWidget::mousePressEvent(QMouseEvent* event)
{
m_CurrentMousePos = event->pos();
m_LastFrameMousePos = m_CurrentMousePos;
update();
}
void OpenGLWidget::mouseMoveEvent(QMouseEvent* event)
{
m_CurrentMousePos = event->pos();
QPoint diff = m_CurrentMousePos - m_LastFrameMousePos;
m_xRotation += diff.x();
m_yRotation += diff.y();
m_LastFrameMousePos = m_CurrentMousePos;
update();
}

View File

@ -1,67 +0,0 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __BasicExample_OpenGLWidget_H__
#define __BasicExample_OpenGLWidget_H__
#include "PolyVoxCore/SurfaceMesh.h"
#include "glew/glew.h"
#include <QGLWidget>
class OpenGLWidget : public QGLWidget
{
public:
//Constructor
OpenGLWidget(QWidget *parent);
//Mouse handling
void mouseMoveEvent(QMouseEvent* event);
void mousePressEvent(QMouseEvent* event);
//Convert a SrfaceMesh to OpenGL index/vertex buffers
void setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal>& surfaceMesh);
protected:
//Qt OpenGL functions
void initializeGL();
void resizeGL(int w, int h);
void paintGL();
private:
//Index/vertex buffer data
GLuint m_uBeginIndex;
GLuint m_uEndIndex;
GLuint noOfIndices;
GLuint indexBuffer;
GLuint vertexBuffer;
//Mouse data
QPoint m_LastFrameMousePos;
QPoint m_CurrentMousePos;
int m_xRotation;
int m_yRotation;
};
#endif //__BasicExample_OpenGLWidget_H__

View File

@ -1,73 +0,0 @@
The OpenGL Extension Wrangler Library
Copyright (C) 2002-2007, Milan Ikits <milan ikits[]ieee org>
Copyright (C) 2002-2007, Marcelo E. Magallon <mmagallo[]debian org>
Copyright (C) 2002, Lev Povalahev
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* The name of the author may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
Mesa 3-D graphics library
Version: 7.0
Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright (c) 2007 The Khronos Group Inc.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and/or associated documentation files (the
"Materials"), to deal in the Materials without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Materials, and to
permit persons to whom the Materials are furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Materials.
THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,39 +1,40 @@
/******************************************************************************* /*******************************************************************************
Copyright (c) 2005-2009 David Williams The MIT License (MIT)
This software is provided 'as-is', without any express or implied Copyright (c) 2015 David Williams and Matthew Williams
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, Permission is hereby granted, free of charge, to any person obtaining a copy
including commercial applications, and to alter it and redistribute it of this software and associated documentation files (the "Software"), to deal
freely, subject to the following restrictions: in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
1. The origin of this software must not be misrepresented; you must not The above copyright notice and this permission notice shall be included in all
claim that you wrote the original software. If you use this software copies or substantial portions of the Software.
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
misrepresented as being the original software. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3. This notice may not be removed or altered from any source AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
distribution. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*******************************************************************************/ *******************************************************************************/
#include "OpenGLWidget.h" #include "PolyVoxExample.h"
#include "PolyVoxCore/CubicSurfaceExtractorWithNormals.h" #include "PolyVox/CubicSurfaceExtractor.h"
#include "PolyVoxCore/MarchingCubesSurfaceExtractor.h" #include "PolyVox/MarchingCubesSurfaceExtractor.h"
#include "PolyVoxCore/SurfaceMesh.h" #include "PolyVox/Mesh.h"
#include "PolyVoxCore/SimpleVolume.h" #include "PolyVox/RawVolume.h"
#include <QApplication> #include <QApplication>
//Use the PolyVox namespace //Use the PolyVox namespace
using namespace PolyVox; using namespace PolyVox;
void createSphereInVolume(SimpleVolume<uint8_t>& volData, float fRadius) void createSphereInVolume(RawVolume<uint8_t>& volData, float fRadius)
{ {
//This vector hold the position of the center of the volume //This vector hold the position of the center of the volume
Vector3DFloat v3dVolCenter(volData.getWidth() / 2, volData.getHeight() / 2, volData.getDepth() / 2); Vector3DFloat v3dVolCenter(volData.getWidth() / 2, volData.getHeight() / 2, volData.getDepth() / 2);
@ -46,50 +47,63 @@ void createSphereInVolume(SimpleVolume<uint8_t>& volData, float fRadius)
for (int x = 0; x < volData.getWidth(); x++) for (int x = 0; x < volData.getWidth(); x++)
{ {
//Store our current position as a vector... //Store our current position as a vector...
Vector3DFloat v3dCurrentPos(x,y,z); Vector3DFloat v3dCurrentPos(x, y, z);
//And compute how far the current position is from the center of the volume //And compute how far the current position is from the center of the volume
float fDistToCenter = (v3dCurrentPos - v3dVolCenter).length(); float fDistToCenter = (v3dCurrentPos - v3dVolCenter).length();
uint8_t uVoxelValue = 0; uint8_t uVoxelValue = 0;
//If the current voxel is less than 'radius' units from the center then we make it solid. //If the current voxel is less than 'radius' units from the center then we make it solid.
if(fDistToCenter <= fRadius) if (fDistToCenter <= fRadius)
{ {
//Our new voxel value //Our new voxel value
uVoxelValue = 255; uVoxelValue = 255;
} }
//Wrte the voxel value into the volume //Wrte the voxel value into the volume
volData.setVoxelAt(x, y, z, uVoxelValue); volData.setVoxel(x, y, z, uVoxelValue);
} }
} }
} }
} }
class BasicExample : public PolyVoxExample
{
public:
BasicExample(QWidget *parent)
:PolyVoxExample(parent)
{
}
protected:
void initializeExample() override
{
// Create an empty volume and then place a sphere in it
RawVolume<uint8_t> volData(PolyVox::Region(Vector3DInt32(0, 0, 0), Vector3DInt32(63, 63, 63)));
createSphereInVolume(volData, 30);
// Extract the surface for the specified region of the volume. Uncomment the line for the kind of surface extraction you want to see.
auto mesh = extractCubicMesh(&volData, volData.getEnclosingRegion());
//auto mesh = extractMarchingCubesMesh(&volData, volData.getEnclosingRegion());
// The surface extractor outputs the mesh in an efficient compressed format which is not directly suitable for rendering. The easiest approach is to
// decode this on the CPU as shown below, though more advanced applications can upload the compressed mesh to the GPU and decompress in shader code.
auto decodedMesh = decodeMesh(mesh);
//Pass the surface to the OpenGL window
addMesh(decodedMesh);
setCameraTransform(QVector3D(100.0f, 100.0f, 100.0f), -(PI / 4.0f), PI + (PI / 4.0f));
}
};
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
//Create and show the Qt OpenGL window //Create and show the Qt OpenGL window
QApplication app(argc, argv); QApplication app(argc, argv);
OpenGLWidget openGLWidget(0); BasicExample openGLWidget(0);
openGLWidget.show(); openGLWidget.show();
//Create an empty volume and then place a sphere in it
SimpleVolume<uint8_t> volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63)));
createSphereInVolume(volData, 30);
//A mesh object to hold the result of surface extraction
SurfaceMesh<PositionMaterialNormal> mesh;
//Create a surface extractor. Comment out one of the following two lines to decide which type gets created.
CubicSurfaceExtractorWithNormals< SimpleVolume<uint8_t> > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh);
//MarchingCubesSurfaceExtractor< SimpleVolume<uint8_t> > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh);
//Execute the surface extractor.
surfaceExtractor.execute();
//Pass the surface to the OpenGL window
openGLWidget.setSurfaceMeshToRender(mesh);
//Run the message pump. //Run the message pump.
return app.exec(); return app.exec();
} }

40
examples/CMakeLists.txt Normal file
View File

@ -0,0 +1,40 @@
################################################################################
# The MIT License (MIT)
#
# Copyright (c) 2015 Matthew Williams and David Williams
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
################################################################################
find_package(Qt5OpenGL 5.2)
set_package_properties(Qt5OpenGL PROPERTIES DESCRIPTION "C++ framework" URL http://qt-project.org)
set_package_properties(Qt5OpenGL PROPERTIES TYPE RECOMMENDED PURPOSE "Building the examples")
if(Qt5OpenGL_FOUND)
SET(BUILD_EXAMPLES ON PARENT_SCOPE)
ADD_SUBDIRECTORY(Basic)
ADD_SUBDIRECTORY(Paging)
ADD_SUBDIRECTORY(OpenGL)
ADD_SUBDIRECTORY(SmoothLOD)
ADD_SUBDIRECTORY(DecodeOnGPU)
ADD_SUBDIRECTORY(Python)
else()
SET(BUILD_EXAMPLES OFF PARENT_SCOPE)
endif()

View File

@ -0,0 +1,71 @@
################################################################################
# The MIT License (MIT)
#
# Copyright (c) 2015 Matthew Williams and David Williams
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
################################################################################
PROJECT(DecodeOnGPUExample)
#Projects source files
SET(SRC_FILES
main.cpp
../common/PolyVoxExample.cpp
)
#Projects headers files
SET(INC_FILES
../common/OpenGLWidget.h
../common/OpenGLWidget.inl
../common/PolyVoxExample.h
)
#"Sources" and "Headers" are the group names in Visual Studio.
#They may have other uses too...
SOURCE_GROUP("Sources" FILES ${SRC_FILES})
SOURCE_GROUP("Headers" FILES ${INC_FILES})
#Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location)
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxHeaders_SOURCE_DIR} ../common)
#This will include the shader files inside the compiled binary
QT5_ADD_RESOURCES(COMMON_RESOURCES_RCC ../common/example.qrc)
QT5_ADD_RESOURCES(DECODE_RESOURCES_RCC decode.qrc)
# Put the resources in a seperate folder in Visual Studio
SOURCE_GROUP("Resource Files" FILES ../common/example.qrc ${COMMON_RESOURCES_RCC} decode.qrc ${DECODE_RESOURCES_RCC})
#Build
ADD_EXECUTABLE(DecodeOnGPUExample ${SRC_FILES} ${COMMON_RESOURCES_RCC} ${DECODE_RESOURCES_RCC})
IF(MSVC)
SET_TARGET_PROPERTIES(DecodeOnGPUExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127")
ENDIF(MSVC)
TARGET_LINK_LIBRARIES(DecodeOnGPUExample Qt5::OpenGL)
SET_PROPERTY(TARGET DecodeOnGPUExample PROPERTY FOLDER "Examples")
#Install - Only install the example in Windows
IF(WIN32)
INSTALL(TARGETS DecodeOnGPUExample
RUNTIME DESTINATION Examples/OpenGL/bin
LIBRARY DESTINATION Examples/OpenGL/lib
ARCHIVE DESTINATION Examples/OpenGL/lib
COMPONENT example
)
ENDIF(WIN32)

View File

@ -0,0 +1,19 @@
#version 130
// Passed in from the vertex shader
in vec4 worldPosition;
in vec4 worldNormal;
// the color that gets written to the display
out vec4 outputColor;
void main()
{
// Again, for the purposes of these examples we cannot be sure that per-vertex normals are provided. A sensible fallback
// is to use this little trick to compute per-fragment flat-shaded normals from the world positions using derivative operations.
//vec3 normal = normalize(cross(dFdy(worldPosition.xyz), dFdx(worldPosition.xyz)));
// We are just using the normal as the output color, and making it lighter so it looks a bit nicer.
// Obviously a real shader would also do texuring, lighting, or whatever is required for the application.
outputColor = vec4(abs(worldNormal.xyz) * 0.5 + vec3(0.5, 0.5, 0.5), 1.0);
}

View File

@ -0,0 +1,6 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>decode.vert</file>
<file>decode.frag</file>
</qresource>
</RCC>

View File

@ -0,0 +1,46 @@
#version 140
in uvec4 position; // This will be the position of the vertex in model-space
in uint normal;
// The usual matrices are provided
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform mat4 modelMatrix;
// This will be used by the fragment shader to calculate flat-shaded normals. This is an unconventional approach
// but we use it in this example framework because not all surface extractor generate surface normals.
out vec4 worldPosition;
out vec4 worldNormal;
// Returns +/- 1
vec2 signNotZero(vec2 v)
{
return vec2((v.x >= 0.0) ? +1.0 : -1.0, (v.y >= 0.0) ? +1.0 : -1.0);
}
void main()
{
vec4 decodedPosition = position;
decodedPosition.xyz = decodedPosition.xyz * (1.0 / 256.0);
//Get the encoded bytes of the normal
uint encodedX = (normal >> 8u) & 0xFFu;
uint encodedY = (normal) & 0xFFu;
// Map to range [-1.0, +1.0]
vec2 e = vec2(encodedX, encodedY);
e = e * vec2(1.0 / 127.5, 1.0 / 127.5);
e = e - vec2(1.0, 1.0);
// Now decode normal using listing 2 of http://jcgt.org/published/0003/02/01/
vec3 v = vec3(e.xy, 1.0 - abs(e.x) - abs(e.y));
if (v.z < 0) v.xy = (1.0 - abs(v.yx)) * signNotZero(v.xy);
worldNormal.xyz = normalize(v);
worldNormal.w = 1.0;
// Standard sequence of OpenGL transformations.
worldPosition = modelMatrix * decodedPosition;
vec4 cameraPosition = viewMatrix * worldPosition;
gl_Position = projectionMatrix * cameraPosition;
}

View File

@ -0,0 +1,173 @@
/*******************************************************************************
The MIT License (MIT)
Copyright (c) 2015 David Williams and Matthew Williams
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*******************************************************************************/
#include "PolyVoxExample.h"
#include "PolyVox/CubicSurfaceExtractor.h"
#include "PolyVox/MarchingCubesSurfaceExtractor.h"
#include "PolyVox/Mesh.h"
#include "PolyVox/RawVolume.h"
#include <QApplication>
//Use the PolyVox namespace
using namespace PolyVox;
void createSphereInVolume(RawVolume<uint8_t>& volData, float fRadius)
{
//This vector hold the position of the center of the volume
Vector3DFloat v3dVolCenter(volData.getWidth() / 2, volData.getHeight() / 2, volData.getDepth() / 2);
//This three-level for loop iterates over every voxel in the volume
for (int z = 0; z < volData.getDepth(); z++)
{
for (int y = 0; y < volData.getHeight(); y++)
{
for (int x = 0; x < volData.getWidth(); x++)
{
//Store our current position as a vector...
Vector3DFloat v3dCurrentPos(x, y, z);
//And compute how far the current position is from the center of the volume
float fDistToCenter = (v3dCurrentPos - v3dVolCenter).length();
uint8_t uVoxelValue = 0;
//If the current voxel is less than 'radius' units from the center then we make it solid.
if (fDistToCenter <= fRadius)
{
//Our new voxel value
uVoxelValue = 255;
}
//Wrte the voxel value into the volume
volData.setVoxel(x, y, z, uVoxelValue);
}
}
}
}
class DecodeOnGPUExample : public PolyVoxExample
{
public:
DecodeOnGPUExample(QWidget *parent)
:PolyVoxExample(parent)
{
}
protected:
void initializeExample() override
{
QSharedPointer<QGLShaderProgram> shader(new QGLShaderProgram);
if (!shader->addShaderFromSourceFile(QGLShader::Vertex, ":/decode.vert"))
{
std::cerr << shader->log().toStdString() << std::endl;
exit(EXIT_FAILURE);
}
if (!shader->addShaderFromSourceFile(QGLShader::Fragment, ":/decode.frag"))
{
std::cerr << shader->log().toStdString() << std::endl;
exit(EXIT_FAILURE);
}
setShader(shader);
//Create an empty volume and then place a sphere in it
RawVolume<uint8_t> volData(PolyVox::Region(Vector3DInt32(0, 0, 0), Vector3DInt32(63, 63, 63)));
createSphereInVolume(volData, 30);
// Extract the surface for the specified region of the volume. Uncomment the line for the kind of surface extraction you want to see.
auto mesh = extractMarchingCubesMesh(&volData, volData.getEnclosingRegion());
//Pass the surface to the OpenGL window
OpenGLMeshData meshData = buildOpenGLMeshData(mesh);
addMeshData(meshData);
setCameraTransform(QVector3D(100.0f, 100.0f, 100.0f), -(PI / 4.0f), PI + (PI / 4.0f));
}
private:
OpenGLMeshData buildOpenGLMeshData(const PolyVox::Mesh< PolyVox::MarchingCubesVertex< uint8_t > >& surfaceMesh, const PolyVox::Vector3DInt32& translation = PolyVox::Vector3DInt32(0, 0, 0), float scale = 1.0f)
{
// This struct holds the OpenGL properties (buffer handles, etc) which will be used
// to render our mesh. We copy the data from the PolyVox mesh into this structure.
OpenGLMeshData meshData;
// Create the VAO for the mesh
glGenVertexArrays(1, &(meshData.vertexArrayObject));
glBindVertexArray(meshData.vertexArrayObject);
// The GL_ARRAY_BUFFER will contain the list of vertex positions
glGenBuffers(1, &(meshData.vertexBuffer));
glBindBuffer(GL_ARRAY_BUFFER, meshData.vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, surfaceMesh.getNoOfVertices() * sizeof(MarchingCubesVertex< uint8_t >), surfaceMesh.getRawVertexData(), GL_STATIC_DRAW);
// and GL_ELEMENT_ARRAY_BUFFER will contain the indices
glGenBuffers(1, &(meshData.indexBuffer));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, meshData.indexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, surfaceMesh.getNoOfIndices() * sizeof(uint32_t), surfaceMesh.getRawIndexData(), GL_STATIC_DRAW);
// Every surface extractor outputs valid positions for the vertices, so tell OpenGL how these are laid out
glEnableVertexAttribArray(0); // Attrib '0' is the vertex positions
glVertexAttribIPointer(0, 3, GL_UNSIGNED_SHORT, sizeof(MarchingCubesVertex< uint8_t >), (GLvoid*)(offsetof(MarchingCubesVertex< uint8_t >, encodedPosition))); //take the first 3 floats from every sizeof(decltype(vecVertices)::value_type)
// Some surface extractors also generate normals, so tell OpenGL how these are laid out. If a surface extractor
// does not generate normals then nonsense values are written into the buffer here and sghould be ignored by the
// shader. This is mostly just to simplify this example code - in a real application you will know whether your
// chosen surface extractor generates normals and can skip uploading them if not.
glEnableVertexAttribArray(1); // Attrib '1' is the vertex normals.
glVertexAttribIPointer(1, 1, GL_UNSIGNED_SHORT, sizeof(MarchingCubesVertex< uint8_t >), (GLvoid*)(offsetof(MarchingCubesVertex< uint8_t >, encodedNormal)));
// Finally a surface extractor will probably output additional data. This is highly application dependant. For this example code
// we're just uploading it as a set of bytes which we can read individually, but real code will want to do something specialised here.
glEnableVertexAttribArray(2); //We're talking about shader attribute '2'
GLint size = (std::min)(sizeof(uint8_t), size_t(4)); // Can't upload more that 4 components (vec4 is GLSL's biggest type)
glVertexAttribIPointer(2, size, GL_UNSIGNED_BYTE, sizeof(MarchingCubesVertex< uint8_t >), (GLvoid*)(offsetof(MarchingCubesVertex< uint8_t >, data)));
// We're done uploading and can now unbind.
glBindVertexArray(0);
// A few additional properties can be copied across for use during rendering.
meshData.noOfIndices = surfaceMesh.getNoOfIndices();
meshData.translation = QVector3D(translation.getX(), translation.getY(), translation.getZ());
meshData.scale = scale;
// Set 16 or 32-bit index buffer size.
meshData.indexType = sizeof(PolyVox::Mesh< PolyVox::MarchingCubesVertex< uint8_t > >::IndexType) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
return meshData;
}
};
int main(int argc, char *argv[])
{
//Create and show the Qt OpenGL window
QApplication app(argc, argv);
DecodeOnGPUExample openGLWidget(0);
openGLWidget.show();
//Run the message pump.
return app.exec();
}

View File

@ -1,23 +1,26 @@
# Copyright (c) 2010-2012 David Williams ################################################################################
# The MIT License (MIT)
# #
# This software is provided 'as-is', without any express or implied # Copyright (c) 2015 Matthew Williams and David Williams
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
# #
# Permission is granted to anyone to use this software for any purpose, # Permission is hereby granted, free of charge, to any person obtaining a copy
# including commercial applications, and to alter it and redistribute it # of this software and associated documentation files (the "Software"), to deal
# freely, subject to the following restrictions: # in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# #
# 1. The origin of this software must not be misrepresented; you must not # The above copyright notice and this permission notice shall be included in all
# claim that you wrote the original software. If you use this software # copies or substantial portions of the Software.
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
# #
# 2. Altered source versions must be plainly marked as such, and must not be # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# misrepresented as being the original software. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# 3. This notice may not be removed or altered from any source # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# distribution. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
################################################################################
CMAKE_MINIMUM_REQUIRED(VERSION 2.6) CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
@ -25,46 +28,46 @@ PROJECT(OpenGLExample)
#Projects source files #Projects source files
SET(SRC_FILES SET(SRC_FILES
glew/glew.cpp
main.cpp main.cpp
OpenGLImmediateModeSupport.cpp #OpenGLImmediateModeSupport.cpp
OpenGLSupport.cpp #OpenGLSupport.cpp
OpenGLVertexBufferObjectSupport.cpp #OpenGLVertexBufferObjectSupport.cpp
OpenGLWidget.cpp ../common/PolyVoxExample.cpp
Shapes.cpp Shapes.cpp
) )
#Projects headers files #Projects headers files
SET(INC_FILES SET(INC_FILES
glew/glew.h #OpenGLImmediateModeSupport.h
glew/glxew.h #OpenGLSupport.h
glew/wglew.h #OpenGLVertexBufferObjectSupport.h
OpenGLImmediateModeSupport.h ../common/OpenGLWidget.h
OpenGLSupport.h ../common/OpenGLWidget.inl
OpenGLVertexBufferObjectSupport.h ../common/PolyVoxExample.h
OpenGLWidget.h
Shapes.h Shapes.h
) )
ADD_DEFINITIONS(-DGLEW_STATIC)
#"Sources" and "Headers" are the group names in Visual Studio. #"Sources" and "Headers" are the group names in Visual Studio.
#They may have other uses too... #They may have other uses too...
SOURCE_GROUP("Sources" FILES ${SRC_FILES}) SOURCE_GROUP("Sources" FILES ${SRC_FILES})
SOURCE_GROUP("Headers" FILES ${INC_FILES}) SOURCE_GROUP("Headers" FILES ${INC_FILES})
FIND_PACKAGE(OpenGL REQUIRED)
#Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location) #Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location)
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_SOURCE_DIR}/include) INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxHeaders_SOURCE_DIR} ../common)
LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR})
#This will include the shader files inside the compiled binary
QT5_ADD_RESOURCES(COMMON_RESOURCES_RCC ../common/example.qrc)
QT5_ADD_RESOURCES(OPENGL_EXAMPLE_RESOURCES_RCC openglexample.qrc)
# Put the resources in a seperate folder in Visual Studio
SOURCE_GROUP("Resource Files" FILES ../common/example.qrc ${COMMON_RESOURCES_RCC})
#Build #Build
ADD_EXECUTABLE(OpenGLExample ${SRC_FILES}) ADD_EXECUTABLE(OpenGLExample ${SRC_FILES} ${COMMON_RESOURCES_RCC} ${OPENGL_EXAMPLE_RESOURCES_RCC})
IF(MSVC) IF(MSVC)
SET_TARGET_PROPERTIES(OpenGLExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") SET_TARGET_PROPERTIES(OpenGLExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127")
ENDIF(MSVC) ENDIF(MSVC)
TARGET_LINK_LIBRARIES(OpenGLExample ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) TARGET_LINK_LIBRARIES(OpenGLExample Qt5::OpenGL)
SET_PROPERTY(TARGET OpenGLExample PROPERTY FOLDER "Examples") SET_PROPERTY(TARGET OpenGLExample PROPERTY FOLDER "Examples")
#Install - Only install the example in Windows #Install - Only install the example in Windows

View File

@ -1,63 +0,0 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#include "OpenGLImmediateModeSupport.h"
#include "OpenGLSupport.h"
#include "PolyVoxCore/SurfaceMesh.h"
using namespace PolyVox;
using namespace std;
void renderRegionImmediateMode(PolyVox::SurfaceMesh<PositionMaterialNormal>& mesh, unsigned int uLodLevel)
{
const vector<PositionMaterialNormal>& vecVertices = mesh.getVertices();
const vector<uint32_t>& vecIndices = mesh.getIndices();
int beginIndex = mesh.m_vecLodRecords[uLodLevel].beginIndex;
int endIndex = mesh.m_vecLodRecords[uLodLevel].endIndex;
glBegin(GL_TRIANGLES);
//for(vector<PolyVox::uint32_t>::const_iterator iterIndex = vecIndices.begin(); iterIndex != vecIndices.end(); ++iterIndex)
for(int index = beginIndex; index < endIndex; ++index)
{
const PositionMaterialNormal& vertex = vecVertices[vecIndices[index]];
const Vector3DFloat& v3dVertexPos = vertex.getPosition();
//const Vector3DFloat v3dRegionOffset(uRegionX * g_uRegionSideLength, uRegionY * g_uRegionSideLength, uRegionZ * g_uRegionSideLength);
const Vector3DFloat v3dFinalVertexPos = v3dVertexPos + static_cast<Vector3DFloat>(mesh.m_Region.getLowerCorner());
uint8_t material = static_cast<uint8_t>(vertex.getMaterial() + 0.5);
OpenGLColour colour = convertMaterialIDToColour(material);
glColor3f(colour.red, colour.green, colour.blue);
glNormal3f(vertex.getNormal().getX(), vertex.getNormal().getY(), vertex.getNormal().getZ());
glVertex3f(v3dFinalVertexPos.getX(), v3dFinalVertexPos.getY(), v3dFinalVertexPos.getZ());
}
glEnd();
}

View File

@ -1,33 +0,0 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __OpenGLExample_OpenGLImmediateModeSupport_H__
#define __OpenGLExample_OpenGLImmediateModeSupport_H__
#include "PolyVoxCore/PolyVoxForwardDeclarations.h"
#include "glew/glew.h"
void renderRegionImmediateMode(PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal>& mesh, unsigned int uLodLevel);
#endif //__OpenGLExample_OpenGLImmediateModeSupport_H__

View File

@ -1,66 +0,0 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#include "OpenGLSupport.h"
using namespace PolyVox;
OpenGLColour convertMaterialIDToColour(uint8_t materialID)
{
OpenGLColour colour;
switch(materialID)
{
case 1:
colour.red = 1.0f;
colour.green = 0.0f;
colour.blue = 0.0f;
break;
case 2:
colour.red = 0.0f;
colour.green = 1.0f;
colour.blue = 0.0f;
break;
case 3:
colour.red = 0.0f;
colour.green = 0.0f;
colour.blue = 1.0f;
break;
case 4:
colour.red = 1.0f;
colour.green = 1.0f;
colour.blue = 0.0f;
break;
case 5:
colour.red = 1.0f;
colour.green = 0.0f;
colour.blue = 1.0f;
break;
default:
colour.red = 1.0f;
colour.green = 1.0f;
colour.blue = 1.0f;
}
return colour;
}

View File

@ -1,40 +0,0 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __OpenGLExample_OpenGLSupport_H__
#define __OpenGLExample_OpenGLSupport_H__
#include "PolyVoxCore/PolyVoxForwardDeclarations.h"
#include "glew/glew.h"
struct OpenGLColour
{
GLfloat red;
GLfloat green;
GLfloat blue;
};
OpenGLColour convertMaterialIDToColour(uint8_t materialID);
#endif //__OpenGLExample_OpenGLSupport_H__

View File

@ -1,124 +0,0 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#include "OpenGLSupport.h"
#include "OpenGLVertexBufferObjectSupport.h"
#include "PolyVoxCore/SurfaceMesh.h"
using namespace PolyVox;
using namespace std;
OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMesh<PositionMaterialNormal>& mesh)
{
//Represents our filled in OpenGL vertex and index buffer objects.
OpenGLSurfaceMesh result;
//The source
result.sourceMesh = &mesh;
//Convienient access to the vertices and indices
const vector<PositionMaterialNormal>& vecVertices = mesh.getVertices();
const vector<uint32_t>& vecIndices = mesh.getIndices();
//If we have any indices...
if(!vecIndices.empty())
{
//Create an OpenGL index buffer
glGenBuffers(1, &result.indexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, result.indexBuffer);
//Get a pointer to the first index
GLvoid* pIndices = (GLvoid*)(&(vecIndices[0]));
//Fill the OpenGL index buffer with our data.
glBufferData(GL_ELEMENT_ARRAY_BUFFER, vecIndices.size() * sizeof(uint32_t), pIndices, GL_STATIC_DRAW);
}
result.noOfIndices = vecIndices.size();
glGenBuffers(1, &result.vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, result.vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(GLfloat) * 9, 0, GL_STATIC_DRAW);
GLfloat* ptr = (GLfloat*)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
for(vector<PositionMaterialNormal>::const_iterator iterVertex = vecVertices.begin(); iterVertex != vecVertices.end(); ++iterVertex)
{
const PositionMaterialNormal& vertex = *iterVertex;
const Vector3DFloat& v3dVertexPos = vertex.getPosition();
//const Vector3DFloat v3dRegionOffset(uRegionX * g_uRegionSideLength, uRegionY * g_uRegionSideLength, uRegionZ * g_uRegionSideLength);
const Vector3DFloat v3dFinalVertexPos = v3dVertexPos + static_cast<Vector3DFloat>(mesh.m_Region.getLowerCorner());
*ptr = v3dFinalVertexPos.getX();
ptr++;
*ptr = v3dFinalVertexPos.getY();
ptr++;
*ptr = v3dFinalVertexPos.getZ();
ptr++;
*ptr = vertex.getNormal().getX();
ptr++;
*ptr = vertex.getNormal().getY();
ptr++;
*ptr = vertex.getNormal().getZ();
ptr++;
uint8_t material = static_cast<uint8_t>(vertex.getMaterial() + 0.5);
OpenGLColour colour = convertMaterialIDToColour(material);
*ptr = colour.red;
ptr++;
*ptr = colour.green;
ptr++;
*ptr = colour.blue;
ptr++;
}
glUnmapBuffer(GL_ARRAY_BUFFER);
return result;
}
void renderRegionVertexBufferObject(const OpenGLSurfaceMesh& openGLSurfaceMesh, unsigned int uLodLevel)
{
int beginIndex = openGLSurfaceMesh.sourceMesh->m_vecLodRecords[uLodLevel].beginIndex;
int endIndex = openGLSurfaceMesh.sourceMesh->m_vecLodRecords[uLodLevel].endIndex;
glBindBuffer(GL_ARRAY_BUFFER, openGLSurfaceMesh.vertexBuffer);
glVertexPointer(3, GL_FLOAT, 36, 0);
glNormalPointer(GL_FLOAT, 36, (GLvoid*)12);
glColorPointer(3, GL_FLOAT, 36, (GLvoid*)24);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, openGLSurfaceMesh.indexBuffer);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
//glDrawElements(GL_TRIANGLES, openGLSurfaceMesh.noOfIndices, GL_UNSIGNED_INT, 0);
glDrawRangeElements(GL_TRIANGLES, beginIndex, endIndex-1, endIndex - beginIndex,/* openGLSurfaceMesh.noOfIndices,*/ GL_UNSIGNED_INT, 0);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
}

View File

@ -1,42 +0,0 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __OpenGLExample_OpenGLVertexBufferObjectSupport_H__
#define __OpenGLExample_OpenGLVertexBufferObjectSupport_H__
#include "PolyVoxCore/PolyVoxForwardDeclarations.h"
#include "glew/glew.h"
struct OpenGLSurfaceMesh
{
GLulong noOfIndices;
GLuint indexBuffer;
GLuint vertexBuffer;
const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal>* sourceMesh;
};
OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal>& mesh);
void renderRegionVertexBufferObject(const OpenGLSurfaceMesh& openGLSurfaceMesh, unsigned int uLodLevel);
#endif //__OpenGLExample_OpenGLVertexBufferObjectSupport_H__

View File

@ -1,246 +0,0 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#include "OpenGLWidget.h"
#include <QMouseEvent>
#include "PolyVoxCore/GradientEstimators.h"
#include "PolyVoxCore/MaterialDensityPair.h"
#include "PolyVoxCore/MarchingCubesSurfaceExtractor.h"
//Some namespaces we need
using namespace std;
using namespace PolyVox;
using namespace std;
OpenGLWidget::OpenGLWidget(QWidget *parent)
:QGLWidget(parent)
,m_volData(0)
{
m_xRotation = 0;
m_yRotation = 0;
m_uRegionSideLength = 32;
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(0);
}
void OpenGLWidget::setVolume(PolyVox::LargeVolume<MaterialDensityPair44>* volData)
{
//First we free anything from the previous volume (if there was one).
m_mapOpenGLSurfaceMeshes.clear();
m_mapSurfaceMeshes.clear();
m_volData = volData;
//If we have any volume data then generate the new surface patches.
if(m_volData != 0)
{
m_uVolumeWidthInRegions = volData->getWidth() / m_uRegionSideLength;
m_uVolumeHeightInRegions = volData->getHeight() / m_uRegionSideLength;
m_uVolumeDepthInRegions = volData->getDepth() / m_uRegionSideLength;
//Our volume is broken down into cuboid regions, and we create one mesh for each region.
//This three-level for loop iterates over each region.
for(uint16_t uRegionZ = 0; uRegionZ < m_uVolumeDepthInRegions; ++uRegionZ)
{
std::cout << "uRegionZ = " << uRegionZ << " of " << m_uVolumeDepthInRegions << std::endl;
for(uint16_t uRegionY = 0; uRegionY < m_uVolumeHeightInRegions; ++uRegionY)
{
for(uint16_t uRegionX = 0; uRegionX < m_uVolumeWidthInRegions; ++uRegionX)
{
//Compute the extents of the current region
//FIXME - This is a little complex? PolyVox could
//provide more functions for dealing with regions?
int32_t regionStartX = uRegionX * m_uRegionSideLength;
int32_t regionStartY = uRegionY * m_uRegionSideLength;
int32_t regionStartZ = uRegionZ * m_uRegionSideLength;
int32_t regionEndX = regionStartX + m_uRegionSideLength;
int32_t regionEndY = regionStartY + m_uRegionSideLength;
int32_t regionEndZ = regionStartZ + m_uRegionSideLength;
Vector3DInt32 regLowerCorner(regionStartX, regionStartY, regionStartZ);
Vector3DInt32 regUpperCorner(regionEndX, regionEndY, regionEndZ);
//Extract the surface for this region
//extractSurface(m_volData, 0, PolyVox::Region(regLowerCorner, regUpperCorner), meshCurrent);
polyvox_shared_ptr< SurfaceMesh<PositionMaterialNormal> > mesh(new SurfaceMesh<PositionMaterialNormal>);
MarchingCubesSurfaceExtractor< LargeVolume<MaterialDensityPair44> > surfaceExtractor(volData, PolyVox::Region(regLowerCorner, regUpperCorner), mesh.get());
surfaceExtractor.execute();
//decimatedMesh->generateAveragedFaceNormals(true);
//computeNormalsForVertices(m_volData, *(decimatedMesh.get()), SOBEL_SMOOTHED);
//*meshCurrent = getSmoothedSurface(*meshCurrent);
//mesh->smooth(0.3f);
//meshCurrent->generateAveragedFaceNormals(true);
if(mesh->m_vecTriangleIndices.size() > 0)
{
Vector3DUint8 v3dRegPos(uRegionX,uRegionY,uRegionZ);
if(m_bUseOpenGLVertexBufferObjects)
{
OpenGLSurfaceMesh openGLSurfaceMesh = BuildOpenGLSurfaceMesh(*(mesh.get()));
m_mapOpenGLSurfaceMeshes.insert(make_pair(v3dRegPos, openGLSurfaceMesh));
}
//else
//{
m_mapSurfaceMeshes.insert(make_pair(v3dRegPos, mesh));
//}
//delete meshCurrent;
}
}
}
}
//Projection matrix is dependant on volume size, so we need to set it up again.
setupProjectionMatrix();
}
}
void OpenGLWidget::initializeGL()
{
m_bUseOpenGLVertexBufferObjects = true;
if(m_bUseOpenGLVertexBufferObjects)
{
//We need GLEW to access recent OpenGL functionality
GLenum err = glewInit();
if (GLEW_OK != err)
{
/* Problem: glewInit failed, something is seriously wrong. */
cout << "GLEW Error: " << glewGetErrorString(err) << endl;
}
}
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glEnable ( GL_COLOR_MATERIAL );
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_LIGHTING);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_LIGHT0);
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glShadeModel(GL_SMOOTH);
}
void OpenGLWidget::resizeGL(int w, int h)
{
//Setup the viewport based on the window size
glViewport(0, 0, w, h);
//Projection matrix is also dependant on the size of the current volume.
if(m_volData)
{
setupProjectionMatrix();
}
}
void OpenGLWidget::paintGL()
{
if(m_volData)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glMatrixMode(GL_MODELVIEW); // Select The Model View Matrix
glLoadIdentity(); // Reset The Current Modelview Matrix
//Moves the camera back so we can see the volume
glTranslatef(0.0f, 0.0f, -m_volData->getDiagonalLength());
glRotatef(m_xRotation, 1.0f, 0.0f, 0.0f);
glRotatef(m_yRotation, 0.0f, 1.0f, 0.0f);
//Centre the volume on the origin
glTranslatef(-g_uVolumeSideLength/2,-g_uVolumeSideLength/2,-g_uVolumeSideLength/2);
for(uint16_t uRegionZ = 0; uRegionZ < m_uVolumeDepthInRegions; ++uRegionZ)
{
for(uint16_t uRegionY = 0; uRegionY < m_uVolumeHeightInRegions; ++uRegionY)
{
for(uint16_t uRegionX = 0; uRegionX < m_uVolumeWidthInRegions; ++uRegionX)
{
Vector3DUint8 v3dRegPos(uRegionX,uRegionY,uRegionZ);
if(m_mapSurfaceMeshes.find(v3dRegPos) != m_mapSurfaceMeshes.end())
{
polyvox_shared_ptr< SurfaceMesh<PositionMaterialNormal> > meshCurrent = m_mapSurfaceMeshes[v3dRegPos];
unsigned int uLodLevel = 0; //meshCurrent->m_vecLodRecords.size() - 1;
if(m_bUseOpenGLVertexBufferObjects)
{
renderRegionVertexBufferObject(m_mapOpenGLSurfaceMeshes[v3dRegPos], uLodLevel);
}
else
{
renderRegionImmediateMode(*meshCurrent, uLodLevel);
}
}
}
}
}
GLenum errCode;
const GLubyte *errString;
if ((errCode = glGetError()) != GL_NO_ERROR)
{
errString = gluErrorString(errCode);
cout << "OpenGL Error: " << errString << endl;
}
}
}
void OpenGLWidget::mousePressEvent(QMouseEvent* event)
{
m_CurrentMousePos = event->pos();
m_LastFrameMousePos = m_CurrentMousePos;
}
void OpenGLWidget::mouseMoveEvent(QMouseEvent* event)
{
m_CurrentMousePos = event->pos();
QPoint diff = m_CurrentMousePos - m_LastFrameMousePos;
m_xRotation += diff.x();
m_yRotation += diff.y();
m_LastFrameMousePos = m_CurrentMousePos;;
}
void OpenGLWidget::setupProjectionMatrix(void)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
float frustumSize = m_volData->getDiagonalLength() / 2.0f;
float aspect = static_cast<float>(width()) / static_cast<float>(height());
glOrtho(frustumSize*aspect, -frustumSize*aspect, frustumSize, -frustumSize, 1.0, 5000);
}

View File

@ -1,83 +0,0 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_OpenGLWidget_H__
#define __PolyVox_OpenGLWidget_H__
#include "glew/glew.h"
#include <QGLWidget>
#include <QTimer>
#include "PolyVoxCore/LargeVolume.h"
#include "PolyVoxCore/SurfaceMesh.h"
#include "PolyVoxCore/Impl/Utility.h"
#include "OpenGLImmediateModeSupport.h"
#include "OpenGLVertexBufferObjectSupport.h"
#include "Shapes.h"
const int32_t g_uVolumeSideLength = 128;
class OpenGLWidget : public QGLWidget
{
public:
OpenGLWidget(QWidget *parent);
void setVolume(PolyVox::LargeVolume<PolyVox::MaterialDensityPair44>* volData);
void mouseMoveEvent(QMouseEvent* event);
void mousePressEvent(QMouseEvent* event);
protected:
void initializeGL();
void resizeGL(int w, int h);
void paintGL();
private:
void setupProjectionMatrix(void);
QPoint m_LastFrameMousePos;
QPoint m_CurrentMousePos;
int m_xRotation;
int m_yRotation;
QTimer *timer;
bool m_bUseOpenGLVertexBufferObjects;
//Creates a volume 128x128x128
PolyVox::LargeVolume<PolyVox::MaterialDensityPair44>* m_volData;
//Rather than storing one big mesh, the volume is broken into regions and a mesh is stored for each region
std::map<PolyVox::Vector3DUint8, OpenGLSurfaceMesh> m_mapOpenGLSurfaceMeshes;
std::map<PolyVox::Vector3DUint8, polyvox_shared_ptr<PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal> > > m_mapSurfaceMeshes;
unsigned int m_uRegionSideLength;
unsigned int m_uVolumeWidthInRegions;
unsigned int m_uVolumeHeightInRegions;
unsigned int m_uVolumeDepthInRegions;
};
#endif //__PolyVox_OpenGLWidget_H__

View File

@ -1,33 +1,34 @@
/******************************************************************************* /*******************************************************************************
Copyright (c) 2005-2009 David Williams The MIT License (MIT)
This software is provided 'as-is', without any express or implied Copyright (c) 2015 David Williams and Matthew Williams
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, Permission is hereby granted, free of charge, to any person obtaining a copy
including commercial applications, and to alter it and redistribute it of this software and associated documentation files (the "Software"), to deal
freely, subject to the following restrictions: in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
1. The origin of this software must not be misrepresented; you must not The above copyright notice and this permission notice shall be included in all
claim that you wrote the original software. If you use this software copies or substantial portions of the Software.
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
misrepresented as being the original software. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3. This notice may not be removed or altered from any source AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
distribution. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*******************************************************************************/ *******************************************************************************/
#include "Shapes.h" #include "Shapes.h"
#include "PolyVoxCore/MaterialDensityPair.h" #include "PolyVox/MaterialDensityPair.h"
using namespace PolyVox; using namespace PolyVox;
void createSphereInVolume(LargeVolume<MaterialDensityPair44>& volData, float fRadius, uint8_t uValue) void createSphereInVolume(RawVolume<MaterialDensityPair88>& volData, float fRadius, uint8_t uValue)
{ {
//This vector hold the position of the center of the volume //This vector hold the position of the center of the volume
Vector3DInt32 v3dVolCenter = (volData.getEnclosingRegion().getUpperCorner() - volData.getEnclosingRegion().getLowerCorner()) / static_cast<int32_t>(2); Vector3DInt32 v3dVolCenter = (volData.getEnclosingRegion().getUpperCorner() - volData.getEnclosingRegion().getLowerCorner()) / static_cast<int32_t>(2);
@ -40,33 +41,33 @@ void createSphereInVolume(LargeVolume<MaterialDensityPair44>& volData, float fRa
for (int x = 0; x < volData.getWidth(); x++) for (int x = 0; x < volData.getWidth(); x++)
{ {
//Store our current position as a vector... //Store our current position as a vector...
Vector3DInt32 v3dCurrentPos(x,y,z); Vector3DInt32 v3dCurrentPos(x, y, z);
//And compute how far the current position is from the center of the volume //And compute how far the current position is from the center of the volume
double fDistToCenter = (v3dCurrentPos - v3dVolCenter).length(); double fDistToCenter = (v3dCurrentPos - v3dVolCenter).length();
//If the current voxel is less than 'radius' units from the center //If the current voxel is less than 'radius' units from the center
//then we make it solid, otherwise we make it empty space. //then we make it solid, otherwise we make it empty space.
if(fDistToCenter <= fRadius) if (fDistToCenter <= fRadius)
{ {
volData.setVoxelAt(x,y,z, MaterialDensityPair44(uValue, uValue > 0 ? MaterialDensityPair44::getMaxDensity() : MaterialDensityPair44::getMinDensity())); volData.setVoxel(x, y, z, MaterialDensityPair88(uValue, uValue > 0 ? MaterialDensityPair88::getMaxDensity() : MaterialDensityPair88::getMinDensity()));
} }
} }
} }
} }
} }
void createCubeInVolume(LargeVolume<MaterialDensityPair44>& volData, Vector3DInt32 lowerCorner, Vector3DInt32 upperCorner, uint8_t uValue) void createCubeInVolume(RawVolume<MaterialDensityPair88>& volData, Vector3DInt32 lowerCorner, Vector3DInt32 upperCorner, uint8_t uValue)
{ {
uint8_t maxDen = MaterialDensityPair44::getMaxDensity(); uint8_t maxDen = static_cast<uint8_t>(MaterialDensityPair88::getMaxDensity());
uint8_t minDen = MaterialDensityPair44::getMinDensity(); uint8_t minDen = static_cast<uint8_t>(MaterialDensityPair88::getMinDensity());
//This three-level for loop iterates over every voxel between the specified corners //This three-level for loop iterates over every voxel between the specified corners
for (int z = lowerCorner.getZ(); z <= upperCorner.getZ(); z++) for (int z = lowerCorner.getZ(); z <= upperCorner.getZ(); z++)
{ {
for (int y = lowerCorner.getY(); y <= upperCorner.getY(); y++) for (int y = lowerCorner.getY(); y <= upperCorner.getY(); y++)
{ {
for (int x = lowerCorner.getX() ; x <= upperCorner.getX(); x++) for (int x = lowerCorner.getX(); x <= upperCorner.getX(); x++)
{ {
volData.setVoxelAt(x,y,z, MaterialDensityPair44(uValue, uValue > 0 ? maxDen : minDen)); volData.setVoxel(x, y, z, MaterialDensityPair88(uValue, uValue > 0 ? maxDen : minDen));
} }
} }
} }

View File

@ -1,33 +1,34 @@
/******************************************************************************* /*******************************************************************************
Copyright (c) 2005-2009 David Williams The MIT License (MIT)
This software is provided 'as-is', without any express or implied Copyright (c) 2015 David Williams and Matthew Williams
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, Permission is hereby granted, free of charge, to any person obtaining a copy
including commercial applications, and to alter it and redistribute it of this software and associated documentation files (the "Software"), to deal
freely, subject to the following restrictions: in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
1. The origin of this software must not be misrepresented; you must not The above copyright notice and this permission notice shall be included in all
claim that you wrote the original software. If you use this software copies or substantial portions of the Software.
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
misrepresented as being the original software. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3. This notice may not be removed or altered from any source AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
distribution. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*******************************************************************************/ *******************************************************************************/
#ifndef __OpenGLExample_Shapes_H__ #ifndef __OpenGLExample_Shapes_H__
#define __OpenGLExample_Shapes_H__ #define __OpenGLExample_Shapes_H__
#include "PolyVoxCore/LargeVolume.h" #include "PolyVox/RawVolume.h"
#include "PolyVoxCore/MaterialDensityPair.h" #include "PolyVox/MaterialDensityPair.h"
void createSphereInVolume(PolyVox::LargeVolume<PolyVox::MaterialDensityPair44>& volData, float fRadius, uint8_t uValue); void createSphereInVolume(PolyVox::RawVolume<PolyVox::MaterialDensityPair88>& volData, float fRadius, uint8_t uValue);
void createCubeInVolume(PolyVox::LargeVolume<PolyVox::MaterialDensityPair44>& volData, PolyVox::Vector3DInt32 lowerCorner, PolyVox::Vector3DInt32 upperCorner, uint8_t uValue); void createCubeInVolume(PolyVox::RawVolume<PolyVox::MaterialDensityPair88>& volData, PolyVox::Vector3DInt32 lowerCorner, PolyVox::Vector3DInt32 upperCorner, uint8_t uValue);
#endif //__OpenGLExample_Shapes_H__ #endif //__OpenGLExample_Shapes_H__

View File

@ -1,73 +0,0 @@
The OpenGL Extension Wrangler Library
Copyright (C) 2002-2007, Milan Ikits <milan ikits[]ieee org>
Copyright (C) 2002-2007, Marcelo E. Magallon <mmagallo[]debian org>
Copyright (C) 2002, Lev Povalahev
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* The name of the author may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
Mesa 3-D graphics library
Version: 7.0
Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright (c) 2007 The Khronos Group Inc.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and/or associated documentation files (the
"Materials"), to deal in the Materials without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Materials, and to
permit persons to whom the Materials are furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Materials.
THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,39 +1,38 @@
/******************************************************************************* /*******************************************************************************
Copyright (c) 2005-2009 David Williams The MIT License (MIT)
This software is provided 'as-is', without any express or implied Copyright (c) 2015 David Williams and Matthew Williams
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, Permission is hereby granted, free of charge, to any person obtaining a copy
including commercial applications, and to alter it and redistribute it of this software and associated documentation files (the "Software"), to deal
freely, subject to the following restrictions: in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
1. The origin of this software must not be misrepresented; you must not The above copyright notice and this permission notice shall be included in all
claim that you wrote the original software. If you use this software copies or substantial portions of the Software.
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
misrepresented as being the original software. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3. This notice may not be removed or altered from any source AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
distribution. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*******************************************************************************/ *******************************************************************************/
#include "PolyVoxCore/Log.h" #include "PolyVox/FilePager.h"
#include "PolyVoxCore/MaterialDensityPair.h" #include "PolyVox/MarchingCubesSurfaceExtractor.h"
#include "PolyVoxCore/LargeVolume.h" #include "PolyVox/MaterialDensityPair.h"
#include "PolyVoxCore/LowPassFilter.h" #include "PolyVox/LowPassFilter.h"
#include "PolyVoxCore/RawVolume.h" #include "PolyVox/RawVolume.h"
#include "PolyVoxCore/SurfaceMesh.h" #include "PolyVox/Mesh.h"
#include "PolyVoxCore/Impl/Utility.h" #include "PolyVox/Impl/Utility.h"
#include "OpenGLImmediateModeSupport.h"
#include "OpenGLVertexBufferObjectSupport.h"
#include "Shapes.h" #include "Shapes.h"
#include "OpenGLWidget.h" #include "PolyVoxExample.h"
#ifdef WIN32 #ifdef WIN32
#include <windows.h> // Standard Header For Most Programs #include <windows.h> // Standard Header For Most Programs
@ -47,82 +46,111 @@ using namespace std;
using namespace PolyVox; using namespace PolyVox;
using namespace std; using namespace std;
void exampleLog(string message, int severity) const int32_t g_uVolumeSideLength = 128;
class OpenGLExample : public PolyVoxExample
{ {
//Identify how severe the mesage is public:
switch(severity) OpenGLExample(QWidget *parent)
:PolyVoxExample(parent)
{ {
case LS_DEBUG:
cout << "DEBUG: ";
break;
case LS_INFO:
cout << "INFO: ";
break;
case LS_WARN:
cout << "WARN: ";
break;
case LS_ERROR:
cout << "ERROR: ";
break;
} }
//Print the message protected:
cout << message << endl; void initializeExample() override
} {
RawVolume<MaterialDensityPair88> volData(PolyVox::Region(Vector3DInt32(0, 0, 0), Vector3DInt32(g_uVolumeSideLength - 1, g_uVolumeSideLength - 1, g_uVolumeSideLength - 1)));
//Make our volume contain a sphere in the center.
int32_t minPos = 0;
int32_t midPos = g_uVolumeSideLength / 2;
int32_t maxPos = g_uVolumeSideLength - 1;
cout << "Creating sphere 1" << std::endl;
createSphereInVolume(volData, 60.0f, 5);
cout << "Creating sphere 2" << std::endl;
createSphereInVolume(volData, 50.0f, 4);
cout << "Creating sphere 3" << std::endl;
createSphereInVolume(volData, 40.0f, 3);
cout << "Creating sphere 4" << std::endl;
createSphereInVolume(volData, 30.0f, 2);
cout << "Creating sphere 5" << std::endl;
createSphereInVolume(volData, 20.0f, 1);
cout << "Creating cubes" << std::endl;
createCubeInVolume(volData, Vector3DInt32(minPos, minPos, midPos + 1), Vector3DInt32(midPos - 1, midPos - 1, maxPos), 0);
createCubeInVolume(volData, Vector3DInt32(midPos + 1, midPos + 1, midPos + 1), Vector3DInt32(maxPos, maxPos, maxPos), 0);
createCubeInVolume(volData, Vector3DInt32(minPos, midPos + 1, minPos), Vector3DInt32(midPos - 1, maxPos, midPos - 1), 0);
createCubeInVolume(volData, Vector3DInt32(midPos + 1, minPos, minPos), Vector3DInt32(maxPos, midPos - 1, midPos - 1), 0);
createCubeInVolume(volData, Vector3DInt32(1, midPos - 10, midPos - 10), Vector3DInt32(maxPos - 1, midPos + 10, midPos + 10), MaterialDensityPair44::getMaxDensity());
createCubeInVolume(volData, Vector3DInt32(midPos - 10, 1, midPos - 10), Vector3DInt32(midPos + 10, maxPos - 1, midPos + 10), MaterialDensityPair44::getMaxDensity());
createCubeInVolume(volData, Vector3DInt32(midPos - 10, midPos - 10, 1), Vector3DInt32(midPos + 10, midPos + 10, maxPos - 1), MaterialDensityPair44::getMaxDensity());
QSharedPointer<QGLShaderProgram> shader(new QGLShaderProgram);
if (!shader->addShaderFromSourceFile(QGLShader::Vertex, ":/openglexample.vert"))
{
std::cerr << shader->log().toStdString() << std::endl;
exit(EXIT_FAILURE);
}
if (!shader->addShaderFromSourceFile(QGLShader::Fragment, ":/openglexample.frag"))
{
std::cerr << shader->log().toStdString() << std::endl;
exit(EXIT_FAILURE);
}
setShader(shader);
QTime time;
time.start();
//openGLWidget.setVolume(&volData);
cout << endl << "Time taken = " << time.elapsed() / 1000.0f << "s" << endl << endl;
const int32_t extractedRegionSize = 32;
int meshCounter = 0;
for (int32_t z = 0; z < volData.getDepth(); z += extractedRegionSize)
{
for (int32_t y = 0; y < volData.getHeight(); y += extractedRegionSize)
{
for (int32_t x = 0; x < volData.getWidth(); x += extractedRegionSize)
{
// Specify the region to extract based on a starting position and the desired region sze.
PolyVox::Region regToExtract(x, y, z, x + extractedRegionSize, y + extractedRegionSize, z + extractedRegionSize);
// If you uncomment this line you will be able to see that the volume is rendered as multiple seperate meshes.
//regToExtract.shrink(1);
// Perform the extraction for this region of the volume
auto mesh = extractMarchingCubesMesh(&volData, regToExtract);
// The returned mesh needs to be decoded to be appropriate for GPU rendering.
auto decodedMesh = decodeMesh(mesh);
// Pass the surface to the OpenGL window. Note that we are also passing an offset in this multi-mesh example. This is because
// the surface extractors return a mesh with 'local space' positions to reduce storage requirements and precision problems.
addMesh(decodedMesh, decodedMesh.getOffset());
meshCounter++;
}
}
}
cout << "Rendering volume as " << meshCounter << " seperate meshes" << endl;
setCameraTransform(QVector3D(150.0f, 150.0f, 150.0f), -(PI / 4.0f), PI + (PI / 4.0f));
}
};
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
logHandler = &exampleLog; //Create and show the Qt OpenGL window
LargeVolume<MaterialDensityPair44> volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(g_uVolumeSideLength-1, g_uVolumeSideLength-1, g_uVolumeSideLength-1)));
//Make our volume contain a sphere in the center.
int32_t minPos = 0;
int32_t midPos = g_uVolumeSideLength / 2;
int32_t maxPos = g_uVolumeSideLength - 1;
cout << "Creating sphere 1" << std::endl;
createSphereInVolume(volData, 60.0f, 5);
cout << "Creating sphere 2" << std::endl;
createSphereInVolume(volData, 50.0f, 4);
cout << "Creating sphere 3" << std::endl;
createSphereInVolume(volData, 40.0f, 3);
cout << "Creating sphere 4" << std::endl;
createSphereInVolume(volData, 30.0f, 2);
cout << "Creating sphere 5" << std::endl;
createSphereInVolume(volData, 20.0f, 1);
cout << "Creating cubes" << std::endl;
createCubeInVolume(volData, Vector3DInt32(minPos, minPos, minPos), Vector3DInt32(midPos-1, midPos-1, midPos-1), 0);
createCubeInVolume(volData, Vector3DInt32(midPos+1, midPos+1, minPos), Vector3DInt32(maxPos, maxPos, midPos-1), 0);
createCubeInVolume(volData, Vector3DInt32(midPos+1, minPos, midPos+1), Vector3DInt32(maxPos, midPos-1, maxPos), 0);
createCubeInVolume(volData, Vector3DInt32(minPos, midPos+1, midPos+1), Vector3DInt32(midPos-1, maxPos, maxPos), 0);
createCubeInVolume(volData, Vector3DInt32(1, midPos-10, midPos-10), Vector3DInt32(maxPos-1, midPos+10, midPos+10), MaterialDensityPair44::getMaxDensity());
createCubeInVolume(volData, Vector3DInt32(midPos-10, 1, midPos-10), Vector3DInt32(midPos+10, maxPos-1, midPos+10), MaterialDensityPair44::getMaxDensity());
createCubeInVolume(volData, Vector3DInt32(midPos-10, midPos-10 ,1), Vector3DInt32(midPos+10, midPos+10, maxPos-1), MaterialDensityPair44::getMaxDensity());
//I've removed this smoothing because it doesn't really make sense to apply a low pass filter to a volume with material values.
//I could implement the mathematical operators for MaterialDensityPair in such a way that they ignores the materials but this
//seems to be setting a bad example. Users can add this operators in their own classes if they want smoothing.
//RawVolume<MaterialDensityPair44> tempVolume(PolyVox::Region(0,0,0,128, 128, 128));
//LowPassFilter< LargeVolume<MaterialDensityPair44>, RawVolume<MaterialDensityPair44> > pass1(&volData, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(126, 126, 126)), &tempVolume, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(126, 126, 126)), 3);
//pass1.executeSAT();
//LowPassFilter< RawVolume<MaterialDensityPair44>, LargeVolume<MaterialDensityPair44> > pass2(&tempVolume, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(126, 126, 126)), &volData, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(126, 126, 126)), 3);
//pass2.executeSAT();
QApplication app(argc, argv); QApplication app(argc, argv);
OpenGLExample openGLWidget(0);
OpenGLWidget openGLWidget(0);
openGLWidget.show(); openGLWidget.show();
QTime time; //Run the message pump.
time.start();
openGLWidget.setVolume(&volData);
cout << endl << "Time taken = " << time.elapsed() / 1000.0f << "s" << endl << endl;
//return 0;
return app.exec(); return app.exec();
} }

View File

@ -0,0 +1,45 @@
#version 130
in vec4 worldPosition; //Passed in from the vertex shader
in vec3 normalFromVS;
flat in ivec2 materialFromVS;
out vec4 outputColor;
void main()
{
// The first byte of our voxel data is the material.
// We use this to decide how to color the fragment.
vec4 surfaceColor;
switch(materialFromVS.x)
{
case 1:
surfaceColor = vec4(1.0, 0.0, 0.0, 1.0);
break;
case 2:
surfaceColor = vec4(0.0, 1.0, 0.0, 1.0);
break;
case 3:
surfaceColor = vec4(0.0, 0.0, 1.0, 1.0);
break;
case 4:
surfaceColor = vec4(1.0, 1.0, 0.0, 1.0);
break;
case 5:
surfaceColor = vec4(1.0, 0.0, 1.0, 1.0);
break;
default:
surfaceColor = vec4(1.0, 1.0, 1.0, 1.0);
break;
}
// Quick and dirty lighting, obviously a real implementation
// should pass light properties as shader parameters, etc.
vec3 lightDir = vec3(0.0, 0.0, 1.0);
float diffuse = clamp(dot(lightDir, normalFromVS), 0.0, 1.0);
diffuse *= 0.7; // Dim the diffuse a bit
float ambient = 0.3; // Add some ambient
float lightIntensity = diffuse + ambient; // Compute the final light intensity
outputColor = surfaceColor * lightIntensity; //Compute final rendered color
}

View File

@ -0,0 +1,6 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>openglexample.vert</file>
<file>openglexample.frag</file>
</qresource>
</RCC>

View File

@ -0,0 +1,26 @@
#version 140
in vec4 position; // This will be the position of the vertex in model-space
in vec4 normal; // The normal data may not have been set
in ivec2 material;
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform mat4 modelMatrix;
out vec4 worldPosition; //This is being passed to the fragment shader to calculate the normals
out vec3 normalFromVS;
flat out ivec2 materialFromVS;
void main()
{
// Compute the usual OpenGL transformation to clip space.
gl_Position = projectionMatrix * viewMatrix * modelMatrix * position;
// This example is demonstrating the marching cubes mesh, which does have per-vertex normals. We can
// just pass them through, though real code might want to deal with transforming normals appropriatly.
normalFromVS = normal.xyz;
// Nothing special here, we just pass the material through to the fragment shader.
materialFromVS = material;
}

View File

@ -1,66 +1,64 @@
# Copyright (c) 2010-2012 David Williams ################################################################################
# The MIT License (MIT)
# #
# This software is provided 'as-is', without any express or implied # Copyright (c) 2015 Matthew Williams and David Williams
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
# #
# Permission is granted to anyone to use this software for any purpose, # Permission is hereby granted, free of charge, to any person obtaining a copy
# including commercial applications, and to alter it and redistribute it # of this software and associated documentation files (the "Software"), to deal
# freely, subject to the following restrictions: # in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# #
# 1. The origin of this software must not be misrepresented; you must not # The above copyright notice and this permission notice shall be included in all
# claim that you wrote the original software. If you use this software # copies or substantial portions of the Software.
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
# #
# 2. Altered source versions must be plainly marked as such, and must not be # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# misrepresented as being the original software. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# 3. This notice may not be removed or altered from any source # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# distribution. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
CMAKE_MINIMUM_REQUIRED(VERSION 2.6) # SOFTWARE.
################################################################################
PROJECT(PagingExample) PROJECT(PagingExample)
#Projects source files #Projects source files
SET(SRC_FILES SET(SRC_FILES
glew/glew.cpp
main.cpp main.cpp
OpenGLWidget.cpp
Perlin.cpp Perlin.cpp
) ../common/PolyVoxExample.cpp
)
#Projects headers files #Projects headers files
SET(INC_FILES SET(INC_FILES
glew/glew.h ../common/OpenGLWidget.h
glew/glxew.h ../common/OpenGLWidget.inl
glew/wglew.h
OpenGLWidget.h
Perlin.h Perlin.h
) ../common/PolyVoxExample.h
)
ADD_DEFINITIONS(-DGLEW_STATIC)
#"Sources" and "Headers" are the group names in Visual Studio. #"Sources" and "Headers" are the group names in Visual Studio.
#They may have other uses too... #They may have other uses too...
SOURCE_GROUP("Sources" FILES ${SRC_FILES}) SOURCE_GROUP("Sources" FILES ${SRC_FILES})
SOURCE_GROUP("Headers" FILES ${INC_FILES}) SOURCE_GROUP("Headers" FILES ${INC_FILES})
FIND_PACKAGE(OpenGL REQUIRED)
#Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location) #Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location)
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_SOURCE_DIR}/include) INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxHeaders_SOURCE_DIR} ../common)
LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR})
#This will include the shader files inside the compiled binary
QT5_ADD_RESOURCES(COMMON_RESOURCES_RCC ../common/example.qrc)
# Put the resources in a seperate folder in Visual Studio
SOURCE_GROUP("Resource Files" FILES ../common/example.qrc ${COMMON_RESOURCES_RCC})
#Build #Build
ADD_EXECUTABLE(PagingExample ${SRC_FILES}) ADD_EXECUTABLE(PagingExample ${SRC_FILES} ${COMMON_RESOURCES_RCC})
IF(MSVC) IF(MSVC)
SET_TARGET_PROPERTIES(PagingExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") SET_TARGET_PROPERTIES(PagingExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127")
ENDIF(MSVC) ENDIF(MSVC)
TARGET_LINK_LIBRARIES(PagingExample ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) TARGET_LINK_LIBRARIES(PagingExample Qt5::OpenGL)
SET_PROPERTY(TARGET PagingExample PROPERTY FOLDER "Examples") SET_PROPERTY(TARGET PagingExample PROPERTY FOLDER "Examples")
#Install - Only install the example in Windows #Install - Only install the example in Windows

View File

@ -1,135 +0,0 @@
#include "OpenGLWidget.h"
#include <QMouseEvent>
using namespace PolyVox;
using namespace std;
OpenGLWidget::OpenGLWidget(QWidget *parent)
:QGLWidget(parent)
,m_uBeginIndex(0)
,m_uEndIndex(0)
,noOfIndices(0)
,m_xRotation(0)
,m_yRotation(0)
{
}
void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PositionMaterialNormal>& surfaceMesh)
{
if((surfaceMesh.getNoOfIndices() == 0) || (surfaceMesh.getNoOfVertices() == 0))
{
//We don't have a valid mesh
return;
}
//Convienient access to the vertices and indices
const vector<uint32_t>& vecIndices = surfaceMesh.getIndices();
const vector<PositionMaterialNormal>& vecVertices = surfaceMesh.getVertices();
//Build an OpenGL index buffer
glGenBuffers(1, &indexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
const GLvoid* pIndices = static_cast<const GLvoid*>(&(vecIndices[0]));
glBufferData(GL_ELEMENT_ARRAY_BUFFER, vecIndices.size() * sizeof(uint32_t), pIndices, GL_STATIC_DRAW);
//Build an OpenGL vertex buffer
glGenBuffers(1, &vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
const GLvoid* pVertices = static_cast<const GLvoid*>(&(vecVertices[0]));
glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(PositionMaterialNormal), pVertices, GL_STATIC_DRAW);
m_uBeginIndex = 0;
m_uEndIndex = vecIndices.size();
noOfIndices = surfaceMesh.getNoOfIndices();
}
void OpenGLWidget::initializeGL()
{
//We need GLEW to access recent OpenGL functionality
GLenum err = glewInit();
if (GLEW_OK != err)
{
/* Problem: glewInit failed, something is seriously wrong. */
std::cout << "GLEW Error: " << glewGetErrorString(err) << std::endl;
}
//Set up the clear colour
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
//Enable the depth buffer
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
//Anable smooth lighting
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glShadeModel(GL_SMOOTH);
//We'll be rendering with index/vertex arrays
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
}
void OpenGLWidget::resizeGL(int w, int h)
{
//Setup the viewport
glViewport(0, 0, w, h);
//Set up the projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
float frustumSize = 128.0f * 1.7f; //Half the volume diagonal
float aspect = static_cast<float>(width()) / static_cast<float>(height());
glOrtho(frustumSize*aspect, -frustumSize*aspect, frustumSize, -frustumSize, 10.0, 10000);
}
void OpenGLWidget::paintGL()
{
if(noOfIndices == 0)
{
//Nothing to render
return;
}
//Clear the screen
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//Set up the viewing transformation
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-5000.0f); //Centre volume and move back
glRotatef(m_xRotation, 1.0f, 0.0f, 0.0f);
glRotatef(m_yRotation, 0.0f, 1.0f, 0.0f);
glTranslatef(-128.0f,-128.0f,-128.0f); //Centre volume and move back
//Bind the index buffer
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
//Bind the vertex buffer
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glVertexPointer(3, GL_FLOAT, sizeof(PositionMaterialNormal), 0);
glNormalPointer(GL_FLOAT, sizeof(PositionMaterialNormal), (GLvoid*)12);
glDrawRangeElements(GL_TRIANGLES, m_uBeginIndex, m_uEndIndex-1, m_uEndIndex - m_uBeginIndex, GL_UNSIGNED_INT, 0);
}
void OpenGLWidget::mousePressEvent(QMouseEvent* event)
{
m_CurrentMousePos = event->pos();
m_LastFrameMousePos = m_CurrentMousePos;
update();
}
void OpenGLWidget::mouseMoveEvent(QMouseEvent* event)
{
m_CurrentMousePos = event->pos();
QPoint diff = m_CurrentMousePos - m_LastFrameMousePos;
m_xRotation += diff.x();
m_yRotation += diff.y();
m_LastFrameMousePos = m_CurrentMousePos;
update();
}

View File

@ -1,67 +0,0 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __BasicExample_OpenGLWidget_H__
#define __BasicExample_OpenGLWidget_H__
#include "PolyVoxCore/SurfaceMesh.h"
#include "glew/glew.h"
#include <QGLWidget>
class OpenGLWidget : public QGLWidget
{
public:
//Constructor
OpenGLWidget(QWidget *parent);
//Mouse handling
void mouseMoveEvent(QMouseEvent* event);
void mousePressEvent(QMouseEvent* event);
//Convert a SrfaceMesh to OpenGL index/vertex buffers
void setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal>& surfaceMesh);
protected:
//Qt OpenGL functions
void initializeGL();
void resizeGL(int w, int h);
void paintGL();
private:
//Index/vertex buffer data
GLuint m_uBeginIndex;
GLuint m_uEndIndex;
GLuint noOfIndices;
GLuint indexBuffer;
GLuint vertexBuffer;
//Mouse data
QPoint m_LastFrameMousePos;
QPoint m_CurrentMousePos;
int m_xRotation;
int m_yRotation;
};
#endif //__BasicExample_OpenGLWidget_H__

View File

@ -36,18 +36,18 @@ float Perlin::noise1(float arg)
vec[0] = arg; vec[0] = arg;
if (mStart) if (mStart)
{ {
srand(mSeed); srand(mSeed);
mStart = false; mStart = false;
init(); init();
} }
setup(0, bx0,bx1, rx0,rx1); setup(0, bx0, bx1, rx0, rx1);
sx = s_curve(rx0); sx = s_curve(rx0);
u = rx0 * g1[ p[ bx0 ] ]; u = rx0 * g1[p[bx0]];
v = rx1 * g1[ p[ bx1 ] ]; v = rx1 * g1[p[bx1]];
return lerp(sx, u, v); return lerp(sx, u, v);
} }
@ -59,14 +59,14 @@ float Perlin::noise2(float vec[2])
int i, j; int i, j;
if (mStart) if (mStart)
{ {
srand(mSeed); srand(mSeed);
mStart = false; mStart = false;
init(); init();
} }
setup(0,bx0,bx1,rx0,rx1); setup(0, bx0, bx1, rx0, rx1);
setup(1,by0,by1,ry0,ry1); setup(1, by0, by1, ry0, ry1);
i = p[bx0]; i = p[bx0];
j = p[bx1]; j = p[bx1];
@ -79,18 +79,18 @@ float Perlin::noise2(float vec[2])
sx = s_curve(rx0); sx = s_curve(rx0);
sy = s_curve(ry0); sy = s_curve(ry0);
#define at2(rx,ry) ( rx * q[0] + ry * q[1] ) #define at2(rx,ry) ( rx * q[0] + ry * q[1] )
q = g2[b00]; q = g2[b00];
u = at2(rx0,ry0); u = at2(rx0, ry0);
q = g2[b10]; q = g2[b10];
v = at2(rx1,ry0); v = at2(rx1, ry0);
a = lerp(sx, u, v); a = lerp(sx, u, v);
q = g2[b01]; q = g2[b01];
u = at2(rx0,ry1); u = at2(rx0, ry1);
q = g2[b11]; q = g2[b11];
v = at2(rx1,ry1); v = at2(rx1, ry1);
b = lerp(sx, u, v); b = lerp(sx, u, v);
return lerp(sy, a, b); return lerp(sy, a, b);
@ -103,46 +103,46 @@ float Perlin::noise3(float vec[3])
int i, j; int i, j;
if (mStart) if (mStart)
{ {
srand(mSeed); srand(mSeed);
mStart = false; mStart = false;
init(); init();
} }
setup(0, bx0,bx1, rx0,rx1); setup(0, bx0, bx1, rx0, rx1);
setup(1, by0,by1, ry0,ry1); setup(1, by0, by1, ry0, ry1);
setup(2, bz0,bz1, rz0,rz1); setup(2, bz0, bz1, rz0, rz1);
i = p[ bx0 ]; i = p[bx0];
j = p[ bx1 ]; j = p[bx1];
b00 = p[ i + by0 ]; b00 = p[i + by0];
b10 = p[ j + by0 ]; b10 = p[j + by0];
b01 = p[ i + by1 ]; b01 = p[i + by1];
b11 = p[ j + by1 ]; b11 = p[j + by1];
t = s_curve(rx0); t = s_curve(rx0);
sy = s_curve(ry0); sy = s_curve(ry0);
sz = s_curve(rz0); sz = s_curve(rz0);
#define at3(rx,ry,rz) ( rx * q[0] + ry * q[1] + rz * q[2] ) #define at3(rx,ry,rz) ( rx * q[0] + ry * q[1] + rz * q[2] )
q = g3[ b00 + bz0 ] ; u = at3(rx0,ry0,rz0); q = g3[b00 + bz0]; u = at3(rx0, ry0, rz0);
q = g3[ b10 + bz0 ] ; v = at3(rx1,ry0,rz0); q = g3[b10 + bz0]; v = at3(rx1, ry0, rz0);
a = lerp(t, u, v); a = lerp(t, u, v);
q = g3[ b01 + bz0 ] ; u = at3(rx0,ry1,rz0); q = g3[b01 + bz0]; u = at3(rx0, ry1, rz0);
q = g3[ b11 + bz0 ] ; v = at3(rx1,ry1,rz0); q = g3[b11 + bz0]; v = at3(rx1, ry1, rz0);
b = lerp(t, u, v); b = lerp(t, u, v);
c = lerp(sy, a, b); c = lerp(sy, a, b);
q = g3[ b00 + bz1 ] ; u = at3(rx0,ry0,rz1); q = g3[b00 + bz1]; u = at3(rx0, ry0, rz1);
q = g3[ b10 + bz1 ] ; v = at3(rx1,ry0,rz1); q = g3[b10 + bz1]; v = at3(rx1, ry0, rz1);
a = lerp(t, u, v); a = lerp(t, u, v);
q = g3[ b01 + bz1 ] ; u = at3(rx0,ry1,rz1); q = g3[b01 + bz1]; u = at3(rx0, ry1, rz1);
q = g3[ b11 + bz1 ] ; v = at3(rx1,ry1,rz1); q = g3[b11 + bz1]; v = at3(rx1, ry1, rz1);
b = lerp(t, u, v); b = lerp(t, u, v);
d = lerp(sy, a, b); d = lerp(sy, a, b);
@ -155,7 +155,7 @@ void Perlin::normalize2(float v[2])
float s; float s;
s = (float)sqrt(v[0] * v[0] + v[1] * v[1]); s = (float)sqrt(v[0] * v[0] + v[1] * v[1]);
s = 1.0f/s; s = 1.0f / s;
v[0] = v[0] * s; v[0] = v[0] * s;
v[1] = v[1] * s; v[1] = v[1] * s;
} }
@ -165,7 +165,7 @@ void Perlin::normalize3(float v[3])
float s; float s;
s = (float)sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); s = (float)sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
s = 1.0f/s; s = 1.0f / s;
v[0] = v[0] * s; v[0] = v[0] * s;
v[1] = v[1] * s; v[1] = v[1] * s;
@ -176,32 +176,32 @@ void Perlin::init(void)
{ {
int i, j, k; int i, j, k;
for (i = 0 ; i < B ; i++) for (i = 0; i < B; i++)
{ {
p[i] = i; p[i] = i;
g1[i] = (float)((rand() % (B + B)) - B) / B; g1[i] = (float)((rand() % (B + B)) - B) / B;
for (j = 0 ; j < 2 ; j++) for (j = 0; j < 2; j++)
g2[i][j] = (float)((rand() % (B + B)) - B) / B; g2[i][j] = (float)((rand() % (B + B)) - B) / B;
normalize2(g2[i]); normalize2(g2[i]);
for (j = 0 ; j < 3 ; j++) for (j = 0; j < 3; j++)
g3[i][j] = (float)((rand() % (B + B)) - B) / B; g3[i][j] = (float)((rand() % (B + B)) - B) / B;
normalize3(g3[i]); normalize3(g3[i]);
} }
while (--i) while (--i)
{ {
k = p[i]; k = p[i];
p[i] = p[j = rand() % B]; p[i] = p[j = rand() % B];
p[j] = k; p[j] = k;
} }
for (i = 0 ; i < B + 2 ; i++) for (i = 0; i < B + 2; i++)
{ {
p[B + i] = p[i]; p[B + i] = p[i];
g1[B + i] = g1[i]; g1[B + i] = g1[i];
for (j = 0 ; j < 2 ; j++) for (j = 0; j < 2; j++)
g2[B + i][j] = g2[i][j]; g2[B + i][j] = g2[i][j];
for (j = 0 ; j < 3 ; j++) for (j = 0; j < 3; j++)
g3[B + i][j] = g3[i][j]; g3[B + i][j] = g3[i][j];
} }
@ -210,19 +210,19 @@ void Perlin::init(void)
float Perlin::perlin_noise_2D(float vec[2]) float Perlin::perlin_noise_2D(float vec[2])
{ {
int terms = mOctaves; int terms = mOctaves;
float result = 0.0f; float result = 0.0f;
float amp = mAmplitude; float amp = mAmplitude;
vec[0]*=mFrequency; vec[0] *= mFrequency;
vec[1]*=mFrequency; vec[1] *= mFrequency;
for( int i=0; i<terms; i++ ) for (int i = 0; i < terms; i++)
{ {
result += noise2(vec)*amp; result += noise2(vec)*amp;
vec[0] *= 2.0f; vec[0] *= 2.0f;
vec[1] *= 2.0f; vec[1] *= 2.0f;
amp*=0.5f; amp *= 0.5f;
} }
@ -231,21 +231,21 @@ float Perlin::perlin_noise_2D(float vec[2])
float Perlin::perlin_noise_3D(float vec[3]) float Perlin::perlin_noise_3D(float vec[3])
{ {
int terms = mOctaves; int terms = mOctaves;
float result = 0.0f; float result = 0.0f;
float amp = mAmplitude; float amp = mAmplitude;
vec[0]*=mFrequency; vec[0] *= mFrequency;
vec[1]*=mFrequency; vec[1] *= mFrequency;
vec[2]*=mFrequency; vec[2] *= mFrequency;
for( int i=0; i<terms; i++ ) for (int i = 0; i < terms; i++)
{ {
result += noise3(vec)*amp; result += noise3(vec)*amp;
vec[0] *= 2.0f; vec[0] *= 2.0f;
vec[1] *= 2.0f; vec[1] *= 2.0f;
vec[2] *= 2.0f; vec[2] *= 2.0f;
amp*=0.5f; amp *= 0.5f;
} }
@ -254,12 +254,12 @@ float Perlin::perlin_noise_3D(float vec[3])
Perlin::Perlin(int octaves,float freq,float amp,int seed) Perlin::Perlin(int octaves, float freq, float amp, int seed)
{ {
mOctaves = octaves; mOctaves = octaves;
mFrequency = freq; mFrequency = freq;
mAmplitude = amp; mAmplitude = amp;
mSeed = seed; mSeed = seed;
mStart = true; mStart = true;
} }

View File

@ -1,73 +0,0 @@
The OpenGL Extension Wrangler Library
Copyright (C) 2002-2007, Milan Ikits <milan ikits[]ieee org>
Copyright (C) 2002-2007, Marcelo E. Magallon <mmagallo[]debian org>
Copyright (C) 2002, Lev Povalahev
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* The name of the author may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
Mesa 3-D graphics library
Version: 7.0
Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright (c) 2007 The Khronos Group Inc.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and/or associated documentation files (the
"Materials"), to deal in the Materials without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Materials, and to
permit persons to whom the Materials are furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Materials.
THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More