8000 windows compatibility support by yetigit · Pull Request #88 · elalish/manifold · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

windows compatibility support #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions collider/src/collider.cu
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,54 @@
#include "collider.cuh"
#include "utils.cuh"


#ifdef _MSC_VER
#include <intrin.h>
#endif

// Adjustable parameters
constexpr int kInitialLength = 128;
constexpr int kLengthMultiple = 4;
// Fundamental constants
constexpr int kRoot = 1;

#ifdef _MSC_VER

#ifndef _WINDEF_
typedef unsigned long DWORD;
#endif

uint32_t __inline ctz( uint32_t value )
{
DWORD trailing_zero = 0;

if ( _BitScanForward( &trailing_zero, value ) )
{
return trailing_zero;
}
else
{
// This is undefined, I better choose 32 than 0
return 32;
}
}

uint32_t __inline clz( uint32_t value )
{
DWORD leading_zero = 0;

if ( _BitScanReverse( &leading_zero, value ) )
{
return 31 - leading_zero;
}
else
{
// Same remarks as above
return 32;
}
}
#endif

namespace {
using namespace manifold;

Expand All @@ -42,7 +84,15 @@ struct CreateRadixTree {
#ifdef __CUDA_ARCH__
return __clz(a ^ b);
#else

#ifdef _MSC_VER
//return __lzcnt(a ^ b);
return clz(a ^ b);
#else

return __builtin_clz(a ^ b);
#endif

#endif
}

Expand Down
11 changes: 6 additions & 5 deletions manifold/src/boolean3.cu
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include "boolean3.cuh"
#include <limits>

// TODO: make this runtime configurable for quicker debug
constexpr bool kVerbose = false;
Expand Down Expand Up @@ -114,7 +115,7 @@ __host__ __device__ thrust::pair<int, glm::vec2> Shadow01(
Shadows(q1ex, p0x, expandP * normalP[q1e].x)
: Shadows(p0x, q1ex, expandP * normalP[p0].x) -
Shadows(p0x, q1sx, expandP * normalP[p0].x);
glm::vec2 yz01(0.0f / 0.0f);
glm::vec2 yz01(NAN);

if (s01 != 0) {
yz01 = Interpolate(vertPosQ[q1s], vertPosQ[q1e], vertPosP[p0].x);
Expand Down Expand Up @@ -215,7 +216,7 @@ struct Kernel11 {
}

if (s11 == 0) { // No intersection
xyzz11 = glm::vec4(0.0f / 0.0f);
xyzz11 = glm::vec4(NAN);
} else {
// Assert left and right were both found
if (k != 2) {
Expand Down Expand Up @@ -278,7 +279,7 @@ struct Kernel02 {
// intersection is between the left and right.
bool shadows;
int closestVert;
float minMetric = 1.0f / 0.0f;
float minMetric = std::numeric_limits<float>::infinity();
s02 = 0;

const glm::vec3 posP = vertPosP[p0];
Expand Down Expand Up @@ -312,7 +313,7 @@ struct Kernel02 {
}

if (s02 == 0) { // No intersection
z02 = 0.0f / 0.0f;
z02 = NAN;
} else {
// Assert left and right were both found
if (k != 2) {
Expand Down Expand Up @@ -427,7 +428,7 @@ struct Kernel12 {
}

if (x12 == 0) { // No intersection
v12 = glm::vec3(0.0f / 0.0f);
v12 = glm::vec3(NAN);
} else {
// Assert left and right were both found
if (k != 2) {
Expand Down
4 changes: 2 additions & 2 deletions manifold/src/edge_op.cu
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void Manifold::Impl::RemoveIfFolded(int edge) {
const glm::ivec3 tri1edge = TriOf(halfedge[edge].pairedHalfedge);
if (halfedge[tri0edge[1]].endVert == halfedge[tri1edge[1]].endVert) {
for (int i : {0, 1, 2}) {
vertPos[halfedge[tri0edge[i]].startVert] = glm::vec3(0.0f / 0.0f);
vertPos[halfedge[tri0edge[i]].startVert] = glm::vec3(NAN);
halfedge[tri0edge[i]] = {-1, -1, -1, -1};
halfedge[tri1edge[i]] = {-1, -1, -1, -1};
}
Expand Down Expand Up @@ -278,7 +278,7 @@ void Manifold::Impl::CollapseEdge(const int edge) {
}

// Remove toRemove.startVert and replace with endVert.
vertPos[toRemove.startVert] = glm::vec3(0.0f / 0.0f);
vertPos[toRemove.startVert] = glm::vec3(NAN);
CollapseTri(tri1edge);

// Orbit startVert
Expand Down
13 changes: 7 additions & 6 deletions manifold/src/properties.cu
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <thrust/execution_policy.h>
#include <thrust/logical.h>
#include <thrust/transform_reduce.h>
#include <limits>

#include "impl.cuh"

Expand Down Expand Up @@ -273,16 +274,16 @@ Curvature Manifold::Impl::GetCurvature() const {
NumVert(), NormalizeCurvature());
result.minMeanCurvature =
thrust::reduce(vertMeanCurvature.beginD(), vertMeanCurvature.endD(),
1.0f / 0.0f, thrust::minimum<float>());
std::numeric_limits<float>::infinity(), thrust::minimum<float>());
result.maxMeanCurvature =
thrust::reduce(vertMeanCurvature.beginD(), vertMeanCurvature.endD(),
-1.0f / 0.0f, thrust::maximum<float>());
-std::numeric_limits<float>::infinity(), thrust::maximum<float>());
result.minGaussianCurvature = thrust::reduce(
vertGaussianCurvature.beginD(), vertGaussianCurvature.endD(), 1.0f / 0.0f,
vertGaussianCurvature.beginD(), vertGaussianCurvature.endD(), std::numeric_limits<float>::infinity(),
thrust::minimum<float>());
result.maxGaussianCurvature = thrust::reduce(
vertGaussianCurvature.beginD(), vertGaussianCurvature.endD(),
-1.0f / 0.0f, thrust::maximum<float>());
-std::numeric_limits<float>::infinity(), thrust::maximum<float>());
result.vertMeanCurvature.insert(result.vertMeanCurvature.end(),
vertMeanCurvature.begin(),
vertMeanCurvature.end());
Expand All @@ -299,8 +300,8 @@ Curvature Manifold::Impl::GetCurvature() const {
*/
void Manifold::Impl::CalculateBBox() {
bBox_.min = thrust::reduce(vertPos_.beginD(), vertPos_.endD(),
glm::vec3(1 / 0.0f), PosMin());
glm::vec3(std::numeric_limits<float>::infinity()), PosMin());
bBox_.max = thrust::reduce(vertPos_.beginD(), vertPos_.endD(),
glm::vec3(-1 / 0.0f), PosMax());
glm::vec3(-std::numeric_limits<float>::infinity()), PosMax());
}
} // namespace manifold
2 changes: 1 addition & 1 deletion manifold/src/shared.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ __host__ __device__ inline glm::vec3 GetBarycentric(const glm::vec3& v,
const float area2 = glm::dot(crossP, crossP);
const float tol2 = precision * precision;
const float vol = glm::dot(crossP, v - triPos[2]);
if (vol * vol > area2 * tol2) return glm::vec3(0.0f / 0.0f);
if (vol * vol > area2 * tol2) return glm::vec3(NAN);

if (d2[longside] < tol2) { // point
return glm::vec3(1, 0, 0);
Expand Down
4 changes: 2 additions & 2 deletions meshIO/src/meshIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void ExportMesh(const std::string& filename, const Mesh& mesh,

scene->mRootNode = new aiNode();
scene->mRootNode->mNumMeshes = 1;
scene->mRootNode->mMeshes = new uint[scene->mRootNode->mNumMeshes];
scene->mRootNode->mMeshes = new glm::uint[scene->mRootNode->mNumMeshes];
scene->mRootNode->mMeshes[0] = 0;

aiMesh* mesh_out = scene->mMeshes[0];
Expand Down Expand Up @@ -180,7 +180,7 @@ void ExportMesh(const std::string& filename, const Mesh& mesh,
for (int i = 0; i < mesh_out->mNumFaces; ++i) {
aiFace& face = mesh_out->mFaces[i];
face.mNumIndices = 3;
face.mIndices = new uint[face.mNumIndices];
face.mIndices = new glm::uint[face.mNumIndices];
for (int j : {0, 1, 2}) face.mIndices[j] = mesh.triVerts[i][j];
}

Expand Down
5 changes: 3 additions & 2 deletions test/polygon_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <algorithm>
#include <random>
#include <limits>

#include "test.h"

Expand Down Expand Up @@ -60,8 +61,8 @@ Polygons Turn180(Polygons polys) {
}

Polygons Duplicate(Polygons polys) {
float xMin = 1.0 / 0.0;
float xMax = -1.0 / 0.0;
float xMin = std::numeric_limits<float>::infinity();
float xMax = -std::numeric_limits<float>::infinity();
int indexMax = 0;
for (SimplePolygon &poly : polys) {
for (PolyVert &vert : poly) {
Expand Down
2 changes: 1 addition & 1 deletion tools/perf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
using namespace manifold;

int main(int argc, char **argv) {
for (int i = 0; i < 8; ++i) {
for (int i = 0; i < 3; ++i) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need to change, but it doesn't really hurt anything.

Manifold sphere = Manifold::Sphere(1, (8 << i) * 4);
Manifold sphere2 = sphere;
sphere2.Translate(glm::vec3(0.5));
Expand Down
5 changes: 3 additions & 2 deletions utilities/include/structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once
#define GLM_FORCE_EXPLICIT_CTOR
#include <chrono>
#include <limits>
#include <glm/ext/matrix_transform.hpp>
#include <glm/glm.hpp>
#include <glm/gtc/constants.hpp>
Expand Down Expand Up @@ -274,8 +275,8 @@ struct MeshRelation {
* Axis-aligned bounding box
*/
struct Box {
glm::vec3 min = glm::vec3(1.0f / 0.0f);
glm::vec3 max = glm::vec3(-1.0f / 0.0f);
glm::vec3 min = glm::vec3(std::numeric_limits<float>::infinity());
glm::vec3 max = glm::vec3(-std::numeric_limits<float>::infinity());

/**
* Default constructor is an infinite box that contains all space.
Expand Down
0