forked from RaymondMcGuire/Particle-Based-Fluid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcuda_searcher_struct.cuh
107 lines (93 loc) · 3.47 KB
/
cuda_searcher_struct.cuh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* @Author: Xu.WANG
* @Date: 2020-07-21 16:37:22
* @LastEditTime: 2021-02-25 02:48:03
* @LastEditors: Xu.WANG
* @Description:
* @FilePath: \Kiri\KiriPBSCuda\include\kiri_pbs_cuda\cuda_searcher_struct.cuh
*/
#ifndef _CUDA_SEARCHER_STRUCT_CUH_
#define _CUDA_SEARCHER_STRUCT_CUH_
#pragma once
#include <kiri_pbs_cuda/kiri_pbs_pch.cuh>
struct ComputeGridXYZByPos
{
float3 LowestPoint;
float cellWidth;
int3 GridSize;
__host__ __device__ ComputeGridXYZByPos(const float3 &mLowestPoint,
const float mCellSize, const int3 &mGridSize)
: LowestPoint(mLowestPoint), cellWidth(mCellSize), GridSize(mGridSize) {}
__host__ __device__ int3 operator()(float3 pos)
{
float3 diff = pos - LowestPoint;
int x = min(max(int(diff.x / cellWidth), 0), GridSize.x - 1),
y = min(max(int(diff.y / cellWidth), 0), GridSize.y - 1),
z = min(max(int(diff.z / cellWidth), 0), GridSize.z - 1);
return make_int3(x, y, z);
}
};
struct ComputePolyGridXYZByPos
{
float3 LowestPoint;
float cellWidth;
int3 GridSize;
__host__ __device__ ComputePolyGridXYZByPos(const float3 &mLowestPoint,
const float mCellSize, const int3 &mGridSize)
: LowestPoint(mLowestPoint), cellWidth(mCellSize), GridSize(mGridSize) {}
__host__ __device__ int3 operator()(float3 pos)
{
float3 diff = pos - LowestPoint;
int x = min(int(diff.x / cellWidth), GridSize.x - 1),
y = min(int(diff.y / cellWidth), GridSize.y - 1),
z = min(int(diff.z / cellWidth), GridSize.z - 1);
return make_int3(x, y, z);
}
};
struct ComputeGridHashByPos
{
float3 LowestPoint;
float cellWidth;
int3 GridSize;
__host__ __device__ ComputeGridHashByPos(const float3 &mLowestPoint,
const float mCellSize, const int3 &mGridSize)
: LowestPoint(mLowestPoint), cellWidth(mCellSize), GridSize(mGridSize) {}
__host__ __device__ int operator()(float3 pos)
{
float3 diff = pos - LowestPoint;
int x = min(max((int)(diff.x / cellWidth), 0), GridSize.x - 1),
y = min(max((int)(diff.y / cellWidth), 0), GridSize.y - 1),
z = min(max((int)(diff.z / cellWidth), 0), GridSize.z - 1);
return x * GridSize.y * GridSize.z + y * GridSize.z + z;
}
};
struct ComputeGridHashByPos4
{
float3 LowestPoint;
float cellWidth;
int3 GridSize;
__host__ __device__ ComputeGridHashByPos4(const float3 &mLowestPoint,
const float mCellSize, const int3 &mGridSize)
: LowestPoint(mLowestPoint), cellWidth(mCellSize), GridSize(mGridSize) {}
__host__ __device__ int operator()(float4 pos)
{
float3 pos3 = make_float3(pos.x, pos.y, pos.z);
float3 diff = pos3 - LowestPoint;
int x = min(max((int)(diff.x / cellWidth), 0), GridSize.x - 1),
y = min(max((int)(diff.y / cellWidth), 0), GridSize.y - 1),
z = min(max((int)(diff.z / cellWidth), 0), GridSize.z - 1);
return x * GridSize.y * GridSize.z + y * GridSize.z + z;
}
};
struct GridXYZ2GridHash
{
int3 GridSize;
__host__ __device__ GridXYZ2GridHash(const int3 &mGridSize)
: GridSize(mGridSize) {}
template <typename T>
__host__ __device__ uint operator()(T x, T y, T z)
{
return x * GridSize.y * GridSize.z + y * GridSize.z + z;
}
};
#endif