Skip to content

Commit

Permalink
Adding SDF LevelSet (elalish#187)
Browse files Browse the repository at this point in the history
* polymorphic device functions working

* starting to flesh out algorithm

* getting closer

* fleshed out vert computation

* more progress

* BuildTris

* fixed some syntax

* updating to cpp

* added VecDc

* SDF compiles

* SDF runs

* fixed some bugs

* manifold output

* fixed out of memory bug

* flattened sides

* back to egg-crate

* works with CUDA too

* moved SDF

* Revert "moved SDF"

This reverts commit ba2348f.

* added gyroid sample

* added sdf_test

* added SDF tests

* tests pass

* updated gyroid_module

* fixed gyroid module

* added docs

* addressing feedback

* fix cuda detection

* clean up detect cuda

* fixed CUDA failure

* consistent execution policy in Boolean

* remove SDF wrapper class

* simplified tet logic

* use NeighborInside()

* optimized SDF

* moved RemoveUnreferencedVerts

* put printf statements behind MANIFOLD_DEBUG

* enable hashtable resize

* added test for hashtable resizing
  • Loading branch information
elalish authored Sep 1, 2022
1 parent 4a44022 commit aff7e6b
Show file tree
Hide file tree
Showing 25 changed files with 871 additions and 133 deletions.
2 changes: 1 addition & 1 deletion extras/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
38 changes: 30 additions & 8 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,48 @@
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

project (samples)
project(samples)

file(GLOB_RECURSE SOURCE_FILES CONFIGURE_DEPENDS *.cpp)
add_library(${PROJECT_NAME} ${SOURCE_FILES})
add_library(samples src/bracelet.cpp src/knot.cpp src/menger_sponge.cpp src/rounded_frame.cpp src/scallop.cpp src/tet_puzzle.cpp)

target_include_directories( ${PROJECT_NAME}
target_include_directories(samples
PUBLIC ${PROJECT_SOURCE_DIR}/include
)

target_link_libraries( ${PROJECT_NAME}
target_link_libraries(samples
PUBLIC manifold
)

target_compile_options(${PROJECT_NAME} PRIVATE ${MANIFOLD_FLAGS})
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_14)
target_compile_options(samples PRIVATE ${MANIFOLD_FLAGS})
target_compile_features(samples PUBLIC cxx_std_14)

project(samplesGPU)

add_library(samplesGPU src/gyroid_module.cpp)

if(MANIFOLD_USE_CUDA)
set_source_files_properties(src/gyroid_module.cpp PROPERTIES LANGUAGE CUDA)
set_property(TARGET samplesGPU PROPERTY CUDA_ARCHITECTURES 61)
endif()

target_include_directories(samplesGPU
PUBLIC ${PROJECT_SOURCE_DIR}/include
)

target_link_libraries(samplesGPU
PUBLIC manifold sdf
)

target_compile_options(samplesGPU PRIVATE ${MANIFOLD_FLAGS})
target_compile_features(samplesGPU
PUBLIC cxx_std_14
PRIVATE cxx_std_17
)
2 changes: 2 additions & 0 deletions samples/include/samples.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,7 @@ Manifold RoundedFrame(float edgeLength, float radius, int circularSegments = 0);
Manifold TetPuzzle(float edgeLength, float gap, int nDivisions);

Manifold Scallop();

Manifold GyroidModule(float size = 20, int n = 20);
/** @} */ // end of Samples
} // namespace manifold
57 changes: 57 additions & 0 deletions samples/src/gyroid_module.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2022 The Manifold Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "samples.h"
#include "sdf.h"

namespace {

struct Gyroid {
__host__ __device__ float operator()(glm::vec3 p) const {
p -= glm::pi<float>() / 4;
return cos(p.x) * sin(p.y) + cos(p.y) * sin(p.z) + cos(p.z) * sin(p.x);
}
};

Manifold RhombicDodecahedron(float size) {
Manifold box =
Manifold::Cube(size * glm::sqrt(2.0f) * glm::vec3(1, 1, 2), true);
Manifold result = box.Rotate(90, 45) ^ box.Rotate(90, 45, 90);
return result ^ box.Rotate(0, 0, 45);
}

} // namespace

namespace manifold {

/**
* Creates a rhombic dodecahedral module of a gyroid manifold, which can be
* assembled together to tile space continuously. This one is designed to be
* 3D-printable, as it is oriented with minimal overhangs. This sample
* demonstrates the use of a Signed Distance Function (SDF) to create smooth,
* complex manifolds.
*/
Manifold GyroidModule(float size, int n) {
auto gyroid = [&](float level) {
const float period = glm::two_pi<float>();
return Manifold(LevelSet(Gyroid(), {glm::vec3(-period), glm::vec3(period)},
period / n, level))
.Scale(glm::vec3(size / period));
};

Manifold result = (RhombicDodecahedron(size) ^ gyroid(-0.4)) - gyroid(0.4);

return result.Rotate(-45, 0, 90).Translate({0, 0, size / glm::sqrt(2.0f)});
}
} // namespace manifold
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -17,3 +17,4 @@ add_subdirectory(utilities)
add_subdirectory(collider)
add_subdirectory(polygon)
add_subdirectory(manifold)
add_subdirectory(sdf)
2 changes: 1 addition & 1 deletion src/collider/src/collider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ __host__ __device__ int Leaf2Node(int leaf) { return leaf * 2; }
struct CreateRadixTree {
int* nodeParent_;
thrust::pair<int, int>* internalChildren_;
const VecD<uint32_t> leafMorton_;
const VecDc<uint32_t> leafMorton_;

__host__ __device__ int PrefixLength(uint32_t a, uint32_t b) const {
// count-leading-zeros is used to find the number of identical highest-order
Expand Down
Loading

0 comments on commit aff7e6b

Please sign in to comment.