|
|
@ -1,5 +1,6 @@ |
|
|
|
#include <array> |
|
|
|
#include <bitset> |
|
|
|
#include <cassert> |
|
|
|
#include <iostream> |
|
|
|
#include <booluarray.hpp> |
|
|
|
|
|
|
@ -10,6 +11,7 @@ |
|
|
|
#include <fstream> |
|
|
|
#include <vector> |
|
|
|
#include "bernstein.hpp" |
|
|
|
#include "factorial.hpp" |
|
|
|
#include "multiloop.hpp" |
|
|
|
#include "quadrature_multipoly.hpp" |
|
|
|
#include "binomial.hpp" |
|
|
@ -203,6 +205,109 @@ void caseScene() |
|
|
|
quadratureScene(primitiveDescriptions, uvector3(-0.8, -1.3, -1.6), uvector3(1.6, 1.6, 1.5), blobTree); |
|
|
|
} |
|
|
|
|
|
|
|
void caseScene30Objs() |
|
|
|
{ |
|
|
|
const int PRIMITIVE_CNT = 30; |
|
|
|
std::vector<std::shared_ptr<PrimitiveDesc>> primitiveDescriptions(PRIMITIVE_CNT); |
|
|
|
uvector3 sceneSize = 0.8, sceneCenter = 0.; |
|
|
|
for (MultiLoop<3> i(0, 2); ~i; ++i) { |
|
|
|
uvector3 center = sceneSize * i() - 0.5 * sceneSize + sceneCenter; |
|
|
|
int idx = organizer::detail::binary2Decimal(i()); |
|
|
|
primitiveDescriptions[2 * idx] = std::make_shared<CuboidDesc>(CuboidDesc(center, 0.16)); |
|
|
|
primitiveDescriptions[2 * idx + 1] = std::make_shared<SphereDesc>(SphereDesc(0.15, center, 1.)); |
|
|
|
} // 16 primitives
|
|
|
|
for (int dim = 0; dim < 3; ++dim) { |
|
|
|
for (MultiLoop<2> i(0, 2); ~i; ++i) { |
|
|
|
uvector3 bottomCenter = add_component(i(), dim, 0) * sceneSize - 0.5 * sceneSize + sceneCenter; |
|
|
|
primitiveDescriptions[organizer::detail::binary2Decimal(i()) + 4 * dim + 16] = |
|
|
|
std::make_shared<CylinderDesc>(CylinderDesc(bottomCenter, 0.1, sceneSize(dim), dim)); |
|
|
|
} |
|
|
|
} // 12 primitives
|
|
|
|
uvector3 coneBottom = uvector3(1, 0, 0) * sceneSize - 0.5 * sceneSize + sceneCenter; |
|
|
|
primitiveDescriptions[28] = std::make_shared<ConeDesc>(coneBottom, 0.2, 0.5, 1); |
|
|
|
uvector3 pyramidBottom = uvector3(0, 0, 1) * sceneSize - 0.5 * sceneSize + sceneCenter; |
|
|
|
std::vector<uvector3> pyramidBottomVertices = { |
|
|
|
0.2 * pyramidBottom + uvector3{-1, 0, -1}, |
|
|
|
0.2 * pyramidBottom + uvector3{1, 0, -1}, |
|
|
|
0.2 * pyramidBottom + uvector3{1, 0, 1 }, |
|
|
|
0.2 * pyramidBottom + uvector3{-1, 0, 1 } |
|
|
|
}; |
|
|
|
primitiveDescriptions[29] = std::make_shared<PyramidDesc>(pyramidBottomVertices, pyramidBottom + uvector3{0, 0.7, 0}); |
|
|
|
|
|
|
|
organizer::BlobTree blobTree; |
|
|
|
blobTree.structure.resize(PRIMITIVE_CNT * 2 - 1); |
|
|
|
blobTree.primitiveNodeIdx.resize(PRIMITIVE_CNT); |
|
|
|
blobTree.structure[0] = {1, 0, 0, 0, 1, 2}; // cube1
|
|
|
|
blobTree.structure[1] = {1, 0, 0, 0, 0, 0}; // sphere1
|
|
|
|
blobTree.structure[2] = {0, OP_DIFFERENCE, 0, 0, 1, 6 - 2}; // Dif of = opNode1
|
|
|
|
blobTree.structure[3] = {1, 0, 0, 0, 1, 5 - 3}; // cube2
|
|
|
|
blobTree.structure[4] = {1, 0, 0, 0, 0, 0}; // sphere2
|
|
|
|
blobTree.structure[5] = {0, OP_DIFFERENCE, 0, 0, 0, 0}; // Dif of = opNode2
|
|
|
|
blobTree.structure[6] = {0, OP_UNION, 0, 0, 1, 14 - 6}; // Union of = opNode3
|
|
|
|
blobTree.structure[7] = {1, 0, 0, 0, 1, 9 - 7}; // cube3
|
|
|
|
blobTree.structure[8] = {1, 0, 0, 0, 0, 0}; // sphere3
|
|
|
|
blobTree.structure[9] = {0, OP_DIFFERENCE, 0, 0, 1, 13 - 9}; // Dif of = opNode4
|
|
|
|
blobTree.structure[10] = {1, 0, 0, 0, 1, 12 - 10}; // cube4
|
|
|
|
blobTree.structure[11] = {1, 0, 0, 0, 0, 0}; // sphere4
|
|
|
|
blobTree.structure[12] = {0, OP_DIFFERENCE, 0, 0, 0, 0}; // Dif of = opNode5
|
|
|
|
blobTree.structure[13] = {0, OP_UNION, 0, 0, 0, 0}; // Union of = opNode6
|
|
|
|
blobTree.structure[14] = {0, OP_UNION, 0, 0, 1, 30 - 14}; // Union of = opNode7
|
|
|
|
blobTree.structure[15] = {1, 0, 0, 0, 1, 17 - 15}; // cube5
|
|
|
|
blobTree.structure[16] = {1, 0, 0, 0, 0, 0}; // sphere5
|
|
|
|
blobTree.structure[17] = {0, OP_DIFFERENCE, 0, 0, 1, 21 - 17}; // Dif of = opNode8
|
|
|
|
blobTree.structure[18] = {1, 0, 0, 0, 1, 20 - 18}; // cube6
|
|
|
|
blobTree.structure[19] = {1, 0, 0, 0, 0, 0}; // sphere6
|
|
|
|
blobTree.structure[20] = {0, OP_DIFFERENCE, 0, 0, 0, 0}; // Dif of = opNode9
|
|
|
|
blobTree.structure[21] = {0, OP_UNION, 0, 0, 1, 29 - 21}; // Union of = opNode10
|
|
|
|
blobTree.structure[22] = {1, 0, 0, 0, 1, 24 - 22}; // cube7
|
|
|
|
blobTree.structure[23] = {1, 0, 0, 0, 0, 0}; // sphere7
|
|
|
|
blobTree.structure[24] = {0, OP_DIFFERENCE, 0, 0, 1, 28 - 24}; // Dif of = opNode11
|
|
|
|
blobTree.structure[25] = {1, 0, 0, 0, 1, 27 - 25}; // cube8
|
|
|
|
blobTree.structure[26] = {1, 0, 0, 0, 0, 0}; // sphere8
|
|
|
|
blobTree.structure[27] = {0, OP_DIFFERENCE, 0, 0, 0, 0}; // Dif of = opNode12
|
|
|
|
blobTree.structure[28] = {0, OP_UNION, 0, 0, 0, 0}; // Union of = opNode13
|
|
|
|
blobTree.structure[29] = {0, OP_UNION, 0, 0, 0, 0}; // Union of = opNode14
|
|
|
|
blobTree.structure[30] = {0, OP_UNION, 0, 0, 1, 32 - 30}; // Dif of = opNode15
|
|
|
|
|
|
|
|
blobTree.structure[31] = {1, 0, 0, 0, 1, 33 - 31}; // cylinder1
|
|
|
|
blobTree.structure[32] = {1, 0, 0, 0, 0, 0}; // cylinder2
|
|
|
|
blobTree.structure[33] = {0, OP_UNION, 0, 0, 1, 37 - 33}; // Union of = opNode16
|
|
|
|
blobTree.structure[34] = {1, 0, 0, 0, 1, 36 - 34}; // cylinder3
|
|
|
|
blobTree.structure[35] = {1, 0, 0, 0, 0, 0}; // cylinder4
|
|
|
|
blobTree.structure[36] = {0, OP_UNION, 0, 0, 0, 0}; // Union of = opNode17
|
|
|
|
blobTree.structure[37] = {0, OP_UNION, 0, 0, 1, 45 - 37}; // Union of = opNode18
|
|
|
|
blobTree.structure[38] = {1, 0, 0, 0, 1, 40 - 38}; // cylinder5
|
|
|
|
blobTree.structure[39] = {1, 0, 0, 0, 0, 0}; // cylinder6
|
|
|
|
blobTree.structure[40] = {0, OP_UNION, 0, 0, 1, 44 - 40}; // Union of = opNode19
|
|
|
|
blobTree.structure[41] = {1, 0, 0, 0, 1, 43 - 41}; // cylinder7
|
|
|
|
blobTree.structure[42] = {1, 0, 0, 0, 0, 0}; // cylinder8
|
|
|
|
blobTree.structure[43] = {0, OP_UNION, 0, 0, 0, 0}; // Union of = opNode20
|
|
|
|
blobTree.structure[44] = {0, OP_UNION, 0, 0, 0, 0}; // Union of = opNode21
|
|
|
|
blobTree.structure[45] = {0, OP_UNION, 0, 0, 1, 53 - 45}; // Union of = opNode22
|
|
|
|
blobTree.structure[46] = {1, 0, 0, 0, 1, 48 - 46}; // cylinder9
|
|
|
|
blobTree.structure[47] = {1, 0, 0, 0, 0, 0}; // cylinder10
|
|
|
|
blobTree.structure[48] = {0, OP_UNION, 0, 0, 1, 52 - 48}; // Union of = opNode23
|
|
|
|
blobTree.structure[49] = {1, 0, 0, 0, 1, 51 - 49}; // cylinder11
|
|
|
|
blobTree.structure[50] = {1, 0, 0, 0, 0, 0}; // cylinder12
|
|
|
|
blobTree.structure[51] = {0, OP_UNION, 0, 0, 0, 0}; // Union of = opNode24
|
|
|
|
blobTree.structure[52] = {0, OP_UNION, 0, 0, 0, 0}; // Union of = opNode25
|
|
|
|
blobTree.structure[53] = {0, OP_UNION, 0, 0, 0, 0}; // Union of = opNode26
|
|
|
|
|
|
|
|
blobTree.structure[54] = {0, OP_UNION, 0, 0, 1, 58 - 54}; // UNION of = opNode27
|
|
|
|
|
|
|
|
blobTree.structure[55] = {1, 0, 0, 0, 1, 57 - 55}; // cone
|
|
|
|
blobTree.structure[56] = {1, 0, 0, 0, 0, 0}; // pyramid
|
|
|
|
blobTree.structure[57] = {0, OP_UNION, 0, 0, 1, 59 - 57}; // UNION of = opNode28
|
|
|
|
blobTree.structure[58] = {0, OP_UNION, 0, 0, 0, 0}; // UNION of = opNode29
|
|
|
|
|
|
|
|
int leafCnt = 0; |
|
|
|
for (int i = 0; i < blobTree.structure.size(); ++i) { |
|
|
|
if (blobTree.structure[i].isPrimitive) { blobTree.primitiveNodeIdx[leafCnt++] = i; } |
|
|
|
} |
|
|
|
assert(leafCnt == PRIMITIVE_CNT); |
|
|
|
quadratureScene(primitiveDescriptions, sceneCenter - 0.5 * sceneSize - 0.2, sceneCenter + 0.5 * sceneSize + 0.2, blobTree); |
|
|
|
} |
|
|
|
|
|
|
|
void caseScene1() |
|
|
|
{ |
|
|
|
const int PRIMITIVE_CNT = 2; |
|
|
@ -413,7 +518,7 @@ void testTensorInverse() |
|
|
|
|
|
|
|
void testRotation() |
|
|
|
{ |
|
|
|
auto desc = std::make_shared<SphereDesc>(SphereDesc(0.1, uvector3(0.1, 0.2, 0.1))); |
|
|
|
auto desc = std::make_shared<SphereDesc>(SphereDesc(0.1, uvector3(0, 0., 0.))); |
|
|
|
tensor3 power(nullptr, 3); |
|
|
|
algoim_spark_alloc(real, power); |
|
|
|
VisiblePrimitiveRep visiblePrimitiveRep{{power}, AABB{}, BlobTree()}; |
|
|
@ -422,18 +527,18 @@ void testRotation() |
|
|
|
real evalX = evalPower(power, testX); |
|
|
|
std::cout << "before rotation, evalX = " << evalX << std::endl; |
|
|
|
|
|
|
|
// tensor3 rotatedPower(nullptr, sum(power.ext()) - 3 + 1);
|
|
|
|
// algoim_spark_alloc(real, rotatedPower);
|
|
|
|
// uvector3 axis = uvector3(4, 2, 3);
|
|
|
|
// axis = axis / norm(axis);
|
|
|
|
|
|
|
|
// organizer::detail::powerRotation(axis, util::pi / 2, power, rotatedPower);
|
|
|
|
// evalX = evalPower(rotatedPower, testX);
|
|
|
|
// std::cout << "after rotation, evalX = " << evalX << std::endl;
|
|
|
|
// bool b = bernstein::autoReduction(rotatedPower, 1e4 * std::numeric_limits<real>::epsilon());
|
|
|
|
// std::cout << "auto reduction = " << b << std::endl;
|
|
|
|
// evalX = evalPower(rotatedPower, testX);
|
|
|
|
// std::cout << "after reduction, evalX = " << evalX << std::endl;
|
|
|
|
tensor3 rotatedPower(nullptr, sum(power.ext())); |
|
|
|
algoim_spark_alloc(real, rotatedPower); |
|
|
|
uvector3 axis = uvector3(4, 2, 3); |
|
|
|
axis = axis / norm(axis); |
|
|
|
|
|
|
|
organizer::detail::powerRotation(axis, util::pi / 2, power, rotatedPower); |
|
|
|
evalX = evalPower(rotatedPower, testX); |
|
|
|
std::cout << "after rotation, evalX = " << evalX << std::endl; |
|
|
|
bool b = bernstein::autoReduction(rotatedPower, 1e5 * std::numeric_limits<real>::epsilon()); |
|
|
|
std::cout << "auto reduction = " << b << std::endl; |
|
|
|
evalX = evalPower(rotatedPower, testX); |
|
|
|
std::cout << "after reduction, evalX = " << evalX << std::endl; |
|
|
|
} |
|
|
|
|
|
|
|
void testPrimitive() |
|
|
@ -443,8 +548,10 @@ void testPrimitive() |
|
|
|
// casePolyhedronSphere();
|
|
|
|
// testSubDivideWithDeCasteljau();
|
|
|
|
// testBlob();
|
|
|
|
// testRotation();
|
|
|
|
// caseScene();
|
|
|
|
testRotation(); |
|
|
|
|
|
|
|
caseScene30Objs(); |
|
|
|
// caseScene1();
|
|
|
|
// caseScene2();
|
|
|
|
// caseCone();
|
|
|
|