[Bf-blender-cvs] [07628987fc9] soc-2020-soft-body: added sdf

over0219 noreply at git.blender.org
Wed Jul 15 05:09:06 CEST 2020


Commit: 07628987fc929254278c024b8ef5c0849ce9c7fe
Author: over0219
Date:   Tue Jul 14 12:17:25 2020 -0500
Branches: soc-2020-soft-body
https://developer.blender.org/rB07628987fc929254278c024b8ef5c0849ce9c7fe

added sdf

===================================================================

A	extern/softbody/src/sdfgen/CMakeLists.txt
A	extern/softbody/src/sdfgen/README.md
A	extern/softbody/src/sdfgen/array1.h
A	extern/softbody/src/sdfgen/array2.h
A	extern/softbody/src/sdfgen/array3.h
A	extern/softbody/src/sdfgen/config.h.in
A	extern/softbody/src/sdfgen/hashgrid.h
A	extern/softbody/src/sdfgen/hashtable.h
A	extern/softbody/src/sdfgen/main.cpp
A	extern/softbody/src/sdfgen/makelevelset3.cpp
A	extern/softbody/src/sdfgen/makelevelset3.h
A	extern/softbody/src/sdfgen/util.h
A	extern/softbody/src/sdfgen/vec.h

===================================================================

diff --git a/extern/softbody/src/sdfgen/CMakeLists.txt b/extern/softbody/src/sdfgen/CMakeLists.txt
new file mode 100644
index 00000000000..400c92beac7
--- /dev/null
+++ b/extern/softbody/src/sdfgen/CMakeLists.txt
@@ -0,0 +1,39 @@
+cmake_minimum_required(VERSION 2.6)
+Project("SDFGen")
+
+# Set the build type.  Options are:
+#  Coverage       : w/ debug symbols, w/o optimization, w/ code-coverage
+#  Debug          : w/ debug symbols, w/o optimization
+#  Release        : w/o debug symbols, w/ optimization
+#  RelWithDebInfo : w/ debug symbols, w/ optimization
+#  MinSizeRel     : w/o debug symbols, w/ optimization, stripped binaries
+
+# SET(CMAKE_BUILD_TYPE Coverage)
+SET(CMAKE_BUILD_TYPE Release)
+
+#set the default path for built executables to the "bin" directory
+set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/bin)
+
+#These flags might not work on every system, especially the release flags, comment out as needed
+set(CMAKE_CXX_FLAGS "-O3")
+set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
+set(CMAKE_CXX_FLAGS_RELEASE "-O3 -march=native")
+
+#checks if VTK is available
+find_package(VTK QUIET)
+if(VTK_FOUND)
+	set(HAVE_VTK 1)
+endif()
+
+#Generates config.h replacing expressions in config.h.in with actual values
+configure_file(
+  "${CMAKE_CURRENT_SOURCE_DIR}/config.h.in"
+  "${CMAKE_CURRENT_SOURCE_DIR}/config.h"
+)
+
+add_executable(${PROJECT_NAME} main.cpp  makelevelset3.cpp)
+
+if(VTK_FOUND)
+	include_directories(${VTK_INCLUDE_DIRS})
+	target_link_libraries(${PROJECT_NAME} ${VTK_LIBRARIES})
+endif()
\ No newline at end of file
diff --git a/extern/softbody/src/sdfgen/README.md b/extern/softbody/src/sdfgen/README.md
new file mode 100644
index 00000000000..ed85c981911
--- /dev/null
+++ b/extern/softbody/src/sdfgen/README.md
@@ -0,0 +1,25 @@
+# SDFGen
+A simple commandline utility to generate grid-based signed distance field (level set) generator from triangle meshes, using code from Robert Bridson's website.
+
+
+The MIT License (MIT)
+
+Copyright (c) 2015, Christopher Batty
+
+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.
diff --git a/extern/softbody/src/sdfgen/array1.h b/extern/softbody/src/sdfgen/array1.h
new file mode 100644
index 00000000000..08d39f2c284
--- /dev/null
+++ b/extern/softbody/src/sdfgen/array1.h
@@ -0,0 +1,798 @@
+#ifndef ARRAY1_H
+#define ARRAY1_H
+
+#include <algorithm>
+#include <cstring>
+#include <cassert>
+#include <climits>
+#include <cstdlib>
+#include <iostream>
+#include <stdexcept>
+#include <vector>
+
+// In this file:
+//   Array1<T>: a dynamic 1D array for plain-old-data (not objects)
+//   WrapArray1<T>: a 1D array wrapper around an existing array (perhaps objects, perhaps data)
+// For the most part std::vector operations are supported, though for the Wrap version
+// note that memory is never allocated/deleted and constructor/destructors are never called
+// from within the class, thus only shallow copies can be made and some operations such as
+// resize() and push_back() are limited.
+// Note: for the most part assertions are done with assert(), not exceptions...
+
+namespace sdfgen {
+
+// gross template hacking to determine if a type is integral or not
+struct Array1True {};
+struct Array1False {};
+template<typename T> struct Array1IsIntegral{ typedef Array1False type; }; // default: no (specializations to yes follow)
+template<> struct Array1IsIntegral<bool>{ typedef Array1True type; };
+template<> struct Array1IsIntegral<char>{ typedef Array1True type; };
+template<> struct Array1IsIntegral<signed char>{ typedef Array1True type; };
+template<> struct Array1IsIntegral<unsigned char>{ typedef Array1True type; };
+template<> struct Array1IsIntegral<short>{ typedef Array1True type; };
+template<> struct Array1IsIntegral<unsigned short>{ typedef Array1True type; };
+template<> struct Array1IsIntegral<int>{ typedef Array1True type; };
+template<> struct Array1IsIntegral<unsigned int>{ typedef Array1True type; };
+template<> struct Array1IsIntegral<long>{ typedef Array1True type; };
+template<> struct Array1IsIntegral<unsigned long>{ typedef Array1True type; };
+template<> struct Array1IsIntegral<long long>{ typedef Array1True type; };
+template<> struct Array1IsIntegral<unsigned long long>{ typedef Array1True type; };
+
+//============================================================================
+template<typename T>
+struct Array1
+{
+   // STL-friendly typedefs
+
+   typedef T* iterator;
+   typedef const T* const_iterator;
+   typedef unsigned long size_type;
+   typedef long difference_type;
+   typedef T& reference;
+   typedef const T& const_reference;
+   typedef T value_type;
+   typedef T* pointer;
+   typedef const T* const_pointer;
+   typedef std::reverse_iterator<iterator> reverse_iterator;
+   typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
+
+   // the actual representation
+
+   unsigned long n;
+   unsigned long max_n;
+   T* data;
+
+   // STL vector's interface, with additions, but only valid when used with plain-old-data
+
+   Array1(void)
+      : n(0), max_n(0), data(0)
+   {}
+
+   // note: default initial values are zero
+   Array1(unsigned long n_)
+      : n(0), max_n(0), data(0)
+   {
+      if(n_>ULONG_MAX/sizeof(T)) throw std::bad_alloc();
+      data=(T*)std::calloc(n_, sizeof(T));
+      if(!data) throw std::bad_alloc();
+      n=n_;
+      max_n=n_;
+   }
+
+   Array1(unsigned long n_, const T& value)
+      : n(0), max_n(0), data(0)
+   {
+      if(n_>ULONG_MAX/sizeof(T)) throw std::bad_alloc();
+      data=(T*)std::calloc(n_, sizeof(T));
+      if(!data) throw std::bad_alloc();
+      n=n_;
+      max_n=n_;
+      for(unsigned long i=0; i<n; ++i) data[i]=value;
+   }
+
+   Array1(unsigned long n_, const T& value, unsigned long max_n_)
+      : n(0), max_n(0), data(0)
+   {
+      assert(n_<=max_n_);
+      if(max_n_>ULONG_MAX/sizeof(T)) throw std::bad_alloc();
+      data=(T*)std::calloc(max_n_, sizeof(T));
+      if(!data) throw std::bad_alloc();
+      n=n_;
+      max_n=max_n_;
+      for(unsigned long i=0; i<n; ++i) data[i]=value;
+   }
+
+   Array1(unsigned long n_, const T* data_)
+      : n(0), max_n(0), data(0)
+   {
+      if(n_>ULONG_MAX/sizeof(T)) throw std::bad_alloc();
+      data=(T*)std::calloc(n_, sizeof(T));
+      if(!data) throw std::bad_alloc();
+      n=n_;
+      max_n=n_;
+      assert(data_);
+      std::memcpy(data, data_, n*sizeof(T));
+   }
+
+   Array1(unsigned long n_, const T* data_, unsigned long max_n_)
+      : n(0), max_n(0), data(0)
+   {
+      assert(n_<=max_n_);
+      if(max_n_>ULONG_MAX/sizeof(T)) throw std::bad_alloc();
+      data=(T*)std::calloc(max_n_, sizeof(T));
+      if(!data) throw std::bad_alloc();
+      max_n=max_n_;
+      n=n_;
+      assert(data_);
+      std::memcpy(data, data_, n*sizeof(T));
+   }
+
+   Array1(const Array1<T> &x)
+      : n(0), max_n(0), data(0)
+   {
+      data=(T*)std::malloc(x.n*sizeof(T));
+      if(!data) throw std::bad_alloc();
+      n=x.n;
+      max_n=x.n;
+      std::memcpy(data, x.data, n*sizeof(T));
+   }
+
+   ~Array1(void)
+   {
+      std::free(data);
+#ifndef NDEBUG
+      data=0;
+      n=max_n=0;
+#endif
+   }
+
+   const T& operator[](unsigned long i) const
+   { return data[i]; }
+
+   T& operator[](unsigned long i)
+   { return data[i]; }
+
+   // these are range-checked (in debug mode) versions of operator[], like at()
+   const T& operator()(unsigned long i) const
+   {
+      assert(i<n);
+      return data[i];
+   }
+
+   T& operator()(unsigned long i)
+   {
+      assert(i<n);
+      return data[i];
+   }
+
+   Array1<T>& operator=(const Array1<T>& x)
+   {
+      if(max_n<x.n){
+         T* new_data=(T*)std::malloc(x.n*sizeof(T));
+         if(!new_data) throw std::bad_alloc();
+         std::free(data);
+         data=new_data;
+         max_n=x.n;
+      }
+      n=x.n;
+      std::memcpy(data, x.data, n*sizeof(T));
+      return *this;
+   }
+
+   bool operator==(const Array1<T>& x) const
+   {
+      if(n!=x.n) return false;
+      for(unsigned long i=0; i<n; ++i) if(!(data[i]==x.data[i])) return false;
+      return true;
+   }
+ 
+   bool operator!=(const Array1<T>& x) const
+   {
+      if(n!=x.n) return true;
+      for(unsigned long i=0; i<n; ++i) if(data[i]!=x.data[i]) return true;
+      return false;
+   }
+
+   bool operator<(const Array1<T>& x) const
+   {
+      for(unsigned long i=0; i<n && i<x.n; ++i){
+         if(data[i]<x[i]) return true;
+         else if(x[i]<data[i]) return false;
+      }
+      return n<x.n;
+   }
+
+   bool operator>(const Array1<T>& x) const
+   {
+      for(unsigned long i=0; i<n && i<x.n; ++i){
+         if(data[i]>x[i]) return true;
+         else if(x[i]>data[i]) return false;
+      }
+      return n>x.n;
+   }
+
+   bool operator<=(const Array1<T>& x) const
+   {
+      for(unsigned long i=0; i<n && i<x.n; ++i){
+         if(data[i]<x[i]) return true;
+         else if(x[i]<data[i]) return false;
+      }
+      return n<=x.n;
+   }
+
+   bool operator>=(const Array1<T>& x) const
+   {
+      for(unsigned long i=0; i<n && i<x.n; ++i){
+         if(data[i]>x[i]) return true;
+         else if(x[i]>data[i]) return false;
+      }
+      return n>=x.n;
+   }
+
+   void add_unique(const T& value)
+   {
+      for(unsigned long i=0;

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list