Browse Source

Add Loader

master
wangxiaolong 5 months ago
parent
commit
e41ddafec1
  1. 68
      algoim/organizer/loader.hpp
  2. 14
      examples/example_loader.cpp

68
algoim/organizer/loader.hpp

@ -207,21 +207,21 @@ public:
tree.structure.push_back(blob0);
algoim::organizer::Blob blob1;
blob0.isPrimitive = 1;
blob0.nodeOp = 0;
blob0.inOut = 0;
blob0.oneChildInOut = 0;
blob0.isLeft = 0;
blob0.ancestor = 0;
blob1.isPrimitive = 1;
blob1.nodeOp = 0;
blob1.inOut = 0;
blob1.oneChildInOut = 0;
blob1.isLeft = 0;
blob1.ancestor = 0;
tree.structure.push_back(blob1);
algoim::organizer::Blob blob2;
blob0.isPrimitive = 0;
blob0.nodeOp = 3; // no set
blob0.inOut = 0;
blob0.oneChildInOut = 0;
blob0.isLeft = 0;
blob0.ancestor = 0;
blob2.isPrimitive = 0;
blob2.nodeOp = 3; // no set
blob2.inOut = 0;
blob2.oneChildInOut = 0;
blob2.isLeft = 0;
blob2.ancestor = 0;
tree.structure.push_back(blob2);
tree.primitiveNodeIdx.push_back(0);
@ -540,7 +540,7 @@ public:
result.tensors[0] = cylinder.tensors[0];
result.aabb = cylinder.aabb;
result.subBlobTree.primitiveNodeIdx.push_back(0);
result.subBlobTree.structure.push_back(algoim::organizer::Blob{1, 2, 0, 0, 0, 0});
result.subBlobTree.structure.push_back(algoim::organizer::Blob{1, 0, 0, 0, 0, 0});
return result;
}
@ -665,8 +665,8 @@ public:
auto halfPlane1 = createHalfPlane(points[0], -normal);
auto halfPlane2 = createHalfPlane(points[0] + extusion, normal);
result = this->unionNode(result, halfPlane1);
result = this->unionNode(result, halfPlane2);
result = this->intersectNode(result, halfPlane1);
result = this->intersectNode(result, halfPlane2);
this->m_allVisible.push_back(result);
return this->m_allVisible.size() - 1;
@ -719,36 +719,38 @@ public:
double sinHalfTheta = 2 * bulge / (1 + bulge * bulge);
double radius = halfDistance / sinHalfTheta;
double scalar = std::sqrt(radius * radius - halfDistance * halfDistance);
auto origion = middlePoint + middleToOrigion * scalar;
/* Determine whether to merge or subtract */
/* The operation is merge if flag is true, otherwise it is subtract */
bool flag;
/* */
auto centroidPoint = computePolygonCentroid(points);
auto middleToCentroid = Direction3D(centroidPoint - middlePoint);
/* out */
if (middleToCentroid.dot(middleToOrigion) > 0.0)
{
if (bulge > 0.0)
{
flag = true;
}
else
/* |bulge| > 1 */
if (std::abs(bulge) > 1.0 + 1e-8)
{
flag = false;
scalar *= -1;
}
flag = true;
}
/* in */
else
{
if (bulge > 0.0)
{
flag = false;
}
else
/* |bulge| > 1 */
if (std::abs(bulge) > 1.0 + 1e-8)
{
flag = true;
scalar *= -1;
}
flag = false;
}
Point3D origion = middlePoint + middleToOrigion * scalar;
/* Determine which axis is aligned */
int alignAxis;
if (normal.isParallel(Direction3D(1, 0, 0)))
@ -792,13 +794,13 @@ public:
auto halfPlane1 = createHalfPlane(points[0], -normal);
auto halfPlane2 = createHalfPlane(points[0] + extusion, normal);
base = this->unionNode(base, halfPlane1);
base = this->unionNode(base, halfPlane2);
base = this->intersectNode(base, halfPlane1);
base = this->intersectNode(base, halfPlane2);
for (size_t i = 0; i < base.aabbs.size(); i++)
{
for (size_t i = 0; i < base.aabbs.size(); i++)
{
base.aabbs[i] = base.aabb;
}
}
this->m_allVisible.push_back(base);

14
examples/example_loader.cpp

@ -24,6 +24,8 @@ void loaderTest1()
extusion = Vector3D{0.0000000000000000, 0.0000000000000000, 3300.0000000000000};
auto tag1 = loader.addExtrude(points, bulges, extusion);
loader.getAreaAndVolume(tag1);
/* 体2 */
points.clear();
bulges.clear();
@ -38,6 +40,8 @@ void loaderTest1()
extusion = Vector3D{0.0000000000000000, 0.0000000000000000, 3300.0000000000000};
auto tag2 = loader.addExtrude(points, bulges, extusion);
loader.getAreaAndVolume(tag2);
/* 体3 */
points.clear();
bulges.clear();
@ -52,6 +56,8 @@ void loaderTest1()
extusion = Vector3D{0.0000000000000000, 0.0000000000000000, 3300.0000000000000};
auto tag3 = loader.addExtrude(points, bulges, extusion);
loader.getAreaAndVolume(tag3);
/* 体4 */
topPoint = Point3D{-1.1224183253943920e-06, -3.8391322798592142e-07, 0.0000000000000000};
bottomPoint = Point3D{-1.1224183253943920e-06, -3.8391322798592142e-07, 3300.0000000000000000};
@ -59,14 +65,20 @@ void loaderTest1()
radius2 = 33539.000000000000;
auto tag4 = loader.addCone(topPoint, bottomPoint, radius1, radius2);
loader.getAreaAndVolume(tag4);
/* 体3被切割 */
basePoint = Point3D{-1.1224183253943920e-06, -3.8391322798592142e-07, 0.0000000000000000};
direction = Direction3D{0, 0, 1};
loader.split(tag3, basePoint, direction);
loader.getAreaAndVolume(tag3);
/* 体3和体4布尔差 */
loader.differentNode(tag3, tag4);
loader.getAreaAndVolume(tag3);
/* 体5 */
points.clear();
bulges.clear();
@ -277,7 +289,7 @@ void loaderTest1()
extusion = Vector3D{0.0000000000000000, 0.0000000000000000, 600.0000000000000};
auto tag13 = loader.addExtrude(points, bulges, extusion);
/* Με13 */
/* Ìå14 */
points.clear();
bulges.clear();
points.push_back(Point3D{-673.66711640879771, 5999.2409883221790, 0.0000000000000000});

Loading…
Cancel
Save