Skip to content

Commit 54fd080

Browse files
committed
update test
1 parent 6225989 commit 54fd080

File tree

8 files changed

+183
-51
lines changed

8 files changed

+183
-51
lines changed

hdk/example-06 neighbor search/solver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include <SIM/SIM_DopDescription.h>
77
#include <SIM/SIM_Utils.h>
88

9+
#include <UT/UT_ParallelUtil.h>
10+
911
/// Very Simple Gravity and Collision With Plane Example
1012
class NeighborSearchSolver : public SIM_SingleSolver, public SIM_OptionsUser
1113
{

test/test1/CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,27 @@ target_include_directories(
4444
${CMAKE_CURRENT_SOURCE_DIR}
4545
)
4646
houdini_configure_target(${TARGET})
47+
48+
set(TEST_TARGET test)
49+
add_executable(
50+
${TEST_TARGET}
51+
test.cpp
52+
)
53+
# Link Houdini Toolkit
54+
target_link_libraries(
55+
${TEST_TARGET}
56+
PUBLIC
57+
${TARGET}
58+
Houdini
59+
)
60+
target_link_directories(
61+
${TEST_TARGET}
62+
PUBLIC
63+
${CMAKE_CURRENT_SOURCE_DIR}
64+
)
65+
target_include_directories(
66+
${TEST_TARGET}
67+
PUBLIC
68+
${CMAKE_CURRENT_BINARY_DIR}
69+
${CMAKE_CURRENT_SOURCE_DIR}
70+
)

test/test1/src/data.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
#ifndef SIM_PBF_DATA_H
22
#define SIM_PBF_DATA_H
33

4+
#include "utils.h"
45
#include <vector>
56

6-
namespace HinaPE_PBF
7-
{
8-
using real = float;
9-
using size = int32_t;
10-
117
struct PBF_DATA
128
{
139
// Sim Data
@@ -23,6 +19,5 @@ struct PBF_DATA
2319
std::vector<real> lambdas;
2420
std::vector<real> delta_p;
2521
};
26-
}
2722

2823
#endif //SIM_PBF_DATA_H

test/test1/src/solver.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
11
#include "solver.h"
22

3-
void InitPBFData(HinaPE_PBF::PBF_DATA &data, const GU_Detail &gdp)
4-
{
5-
6-
}

test/test1/src/solver.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
#ifndef SIM_PBF_SOLVER_H
22
#define SIM_PBF_SOLVER_H
33

4-
#include "data.h"
4+
#include "utils.h"
55

66
#include <GU/GU_Detail.h>
7-
void InitPBFData(HinaPE_PBF::PBF_DATA &data, const GU_Detail &gdp);
7+
#include <SIM/SIM_PointNeighbourList.h>
8+
#include <UT/UT_ParallelUtil.h>
89

10+
//void InitPBFData(HinaPE_PBF::PBF_DATA &data, const GU_Detail &gdp);
11+
12+
13+
14+
template<typename SRC>
15+
void BuildNeighbourList_Native(
16+
UT_Array<UT_Array<GA_Offset>> &OutNeighbourList, const UT_Vector3TArrayHandle<SRC> &InPoints, sz InPointsSize, sz StartIndex = 0)
17+
{
18+
19+
}
920
#endif //SIM_PBF_SOLVER_H

test/test1/src/utils.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1 @@
11
#include "utils.h"
2-
3-
void SyncParticlePositionFromGDP(HinaPE_PBF::PBF_DATA &data, const GU_Detail &gdp)
4-
{
5-
6-
}
7-
void SyncGDPFromParticlePosition(GU_Detail &gdp, const HinaPE_PBF::PBF_DATA &data)
8-
{
9-
10-
}

test/test1/src/utils.h

Lines changed: 79 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,103 @@
11
#ifndef SIM_PBF_UTILS_H
22
#define SIM_PBF_UTILS_H
33

4-
#include "data.h"
54
#include <GU/GU_Detail.h>
65

7-
namespace HinaPE_PBF
8-
{
9-
template<typename T, typename Prim>
10-
struct ArrayHandle
6+
#include <numeric>
7+
8+
using real = float;
9+
using sz = int32;
10+
11+
template<typename SRC>
12+
struct UT_Vector3TArrayHandle
1113
{
12-
ArrayHandle(T *_internal) : internal(_internal) {}
13-
~ArrayHandle() = default;
14+
explicit UT_Vector3TArrayHandle(SRC *_internal, std::function<sz(sz)> &&ito = [](sz i) { return i; })
15+
: internal(_internal), index_to_offset(std::move(ito)) {}
16+
virtual ~UT_Vector3TArrayHandle() = default;
1417

15-
virtual Prim get(int off) const = 0;
16-
virtual void set(int off, Prim p) = 0;
18+
virtual UT_Vector3T<real> geti(int idx) const { return geto(index_to_offset(idx)); }
19+
virtual void seti(int idx, UT_Vector3T<real> p) { seto(index_to_offset(idx), p); }
1720

18-
T *internal;
21+
virtual UT_Vector3T<real> geto(int off) const = 0;
22+
virtual void seto(int off, UT_Vector3T<real> p) = 0;
23+
24+
std::function<sz(sz)> index_to_offset;
25+
26+
protected:
27+
SRC *internal;
1928
};
2029

21-
template<typename T, typename Prim>
22-
struct ConstArrayHandle
30+
template<typename SRC>
31+
struct MultipleUT_Vector3TArrayHandle
2332
{
24-
ConstArrayHandle(ArrayHandle<T, Prim> *_internal) : internal(_internal) {}
25-
~ConstArrayHandle() = default;
33+
explicit MultipleUT_Vector3TArrayHandle(std::vector<std::pair<UT_Vector3TArrayHandle<SRC> *, sz>> *InArrays)
34+
: Arrays(InArrays) {}
35+
~MultipleUT_Vector3TArrayHandle() = default;
2636

27-
Prim get(int off) const { return internal->get(off); }
37+
virtual UT_Vector3T<real> geti(int idx) const
38+
{
39+
int sum = 0;
40+
int last_sum = 0;
41+
int iter = -1;
42+
while (sum <= idx)
43+
{
44+
iter++;
45+
last_sum = sum;
46+
sum += (*Arrays)[iter].second;
47+
}
48+
if (iter >= Arrays->size() || iter < 0)
49+
return UT_Vector3T<real>();
50+
int real_idx = idx - last_sum;
51+
return (*Arrays)[iter].first->geti(real_idx);
52+
}
53+
virtual void seti(int idx, UT_Vector3T<real> p)
54+
{
55+
int sum = 0;
56+
int last_sum = 0;
57+
int iter = -1;
58+
while (sum <= idx)
59+
{
60+
iter++;
61+
last_sum = sum;
62+
sum += (*Arrays)[iter].second;
63+
}
64+
if (iter >= Arrays->size() || iter < 0)
65+
return;
66+
int real_idx = idx - last_sum;
67+
(*Arrays)[iter].first->seti(real_idx, p);
68+
}
69+
virtual sz value_size()
70+
{
71+
return std::accumulate(Arrays->begin(), Arrays->end(), 0, [](sz acc, const std::pair<UT_Vector3TArrayHandle<SRC> *, sz> &p)
72+
{
73+
return acc + p.second;
74+
});
75+
}
76+
sz size()
77+
{
78+
return Arrays->size();
79+
}
2880

29-
ArrayHandle<T, Prim> *internal;
81+
protected:
82+
std::vector<std::pair<UT_Vector3TArrayHandle<SRC> *, sz>> *Arrays;
3083
};
3184

32-
struct NativeVector3Handle : public ArrayHandle<std::vector<real>, UT_Vector3T<real>>
85+
struct NativeArrayHandle : public UT_Vector3TArrayHandle<std::vector<real>>
3386
{
34-
NativeVector3Handle(std::vector<real> *_internal) : ArrayHandle(_internal) {}
35-
~NativeVector3Handle() = default;
87+
NativeArrayHandle(std::vector<real> *_internal) : UT_Vector3TArrayHandle(_internal) {}
88+
~NativeArrayHandle() override = default;
3689

37-
UT_Vector3T<real> get(int off) const override { return UT_Vector3T<real>(internal->data() + off * 3); }
38-
void set(int off, UT_Vector3T<real> p) override { memcpy(internal->data() + off * 3, p.data(), sizeof(real) * 3); }
90+
UT_Vector3T<real> geto(int off) const override { return UT_Vector3T<real>(internal->data() + off * 3); }
91+
void seto(int off, UT_Vector3T<real> p) override { memcpy(internal->data() + off * 3, p.data(), sizeof(real) * 3); }
3992
};
4093

41-
struct GDPVector3Handle : public ArrayHandle<GU_Detail, UT_Vector3T<real>>
94+
struct GA_ArrayHandle : public UT_Vector3TArrayHandle<GA_RWHandleT<UT_Vector3T<real>>>
4295
{
43-
GDPVector3Handle(GU_Detail *gdp) : ArrayHandle(gdp) {}
44-
~GDPVector3Handle() = default;
96+
GA_ArrayHandle(GA_RWHandleT<UT_Vector3T<real>> *handle) : UT_Vector3TArrayHandle(handle) {}
97+
~GA_ArrayHandle() override = default;
4598

46-
UT_Vector3T<real> get(int off) const override { return internal->getPos3(off); }
47-
void set(int off, UT_Vector3T<real> p) override { internal->setPos3(off, p); }
99+
UT_Vector3T<real> geto(int off) const override { return internal->get(off); }
100+
void seto(int off, UT_Vector3T<real> p) override { internal->set(off, p); }
48101
};
49-
}
50-
51-
void SyncParticlePositionFromGDP(HinaPE_PBF::PBF_DATA &data, const GU_Detail &gdp);
52-
void SyncGDPFromParticlePosition(GU_Detail &gdp, const HinaPE_PBF::PBF_DATA &data);
53102

54103
#endif //SIM_PBF_UTILS_H

test/test1/test.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#include "src/utils.h"
2+
3+
#include <random>
4+
#include <iostream>
5+
6+
bool Test_NativeArrayHandle()
7+
{
8+
std::vector<real> test;
9+
for (int i = 0; i < 3000; ++i)
10+
test.emplace_back(i);
11+
12+
NativeArrayHandle test_handle(&test);
13+
std::cout << test_handle.geti(0) << std::endl;
14+
std::cout << test_handle.geti(1) << std::endl;
15+
std::cout << test_handle.geti(2) << std::endl;
16+
std::cout << test_handle.geti(3) << std::endl;
17+
std::cout << test_handle.geti(4) << std::endl;
18+
19+
return true;
20+
}
21+
22+
bool Test_GA_ArrayHandle()
23+
{
24+
// TODO: Implement
25+
return true;
26+
}
27+
28+
bool Test_MultipleUT_Vector3TArrayHandle()
29+
{
30+
std::vector<real> test1, test2, test3;
31+
for (int i = 0; i < 3000; ++i)
32+
test1.emplace_back(i);
33+
for (int i = 0; i < 3000; ++i)
34+
test2.emplace_back(i + 3000);
35+
for (int i = 0; i < 3000; ++i)
36+
test3.emplace_back(i + 6000);
37+
NativeArrayHandle test_handle1(&test1);
38+
NativeArrayHandle test_handle2(&test2);
39+
NativeArrayHandle test_handle3(&test3);
40+
41+
std::vector<std::pair<UT_Vector3TArrayHandle<std::vector<real>> *, sz>> test_array;
42+
test_array.emplace_back(&test_handle1, 3000);
43+
test_array.emplace_back(&test_handle2, 3000);
44+
test_array.emplace_back(&test_handle3, 3000);
45+
46+
MultipleUT_Vector3TArrayHandle<std::vector<real>> test_handle(&test_array);
47+
std::cout << test_handle.geti(0) << std::endl;
48+
std::cout << test_handle.geti(1) << std::endl;
49+
std::cout << test_handle.geti(2) << std::endl;
50+
std::cout << test_handle.geti(3000) << std::endl;
51+
std::cout << test_handle.geti(3001) << std::endl;
52+
std::cout << test_handle.geti(3002) << std::endl;
53+
std::cout << test_handle.geti(6000) << std::endl;
54+
std::cout << test_handle.geti(6001) << std::endl;
55+
std::cout << test_handle.geti(6002) << std::endl;
56+
return true;
57+
};
58+
59+
int main()
60+
{
61+
Test_NativeArrayHandle();
62+
Test_MultipleUT_Vector3TArrayHandle();
63+
return 0;
64+
}

0 commit comments

Comments
 (0)