Browse Source

Add loader

master
wangxiaolong 5 months ago
parent
commit
ea0ff4c5e8
  1. 35
      algoim/organizer/loader.hpp
  2. 61
      examples/example_loader.cpp

35
algoim/organizer/loader.hpp

@ -349,7 +349,9 @@ public:
for (size_t i = 0; i < base.aabbs.size(); i++) { base.aabbs[i] = base.aabb; } for (size_t i = 0; i < base.aabbs.size(); i++) { base.aabbs[i] = base.aabb; }
this->m_allVisible.push_back(base); this->m_allVisible.push_back(base);
auto result = this->getAreaAndVolume(this->m_allVisible.size() - 1);
this->m_allArea.push_back(result.first);
this->m_allVolume.push_back(result.second);
return this->m_allVisible.size() - 1; return this->m_allVisible.size() - 1;
} }
@ -393,6 +395,9 @@ public:
for (int i = 0; i < 3; i++) { cone.aabbs.push_back(cone.aabb); } for (int i = 0; i < 3; i++) { cone.aabbs.push_back(cone.aabb); }
this->m_allVisible.push_back(cone); this->m_allVisible.push_back(cone);
auto result = this->getAreaAndVolume(this->m_allVisible.size() - 1);
this->m_allArea.push_back(result.first);
this->m_allVolume.push_back(result.second);
return this->m_allVisible.size() - 1; return this->m_allVisible.size() - 1;
} }
@ -420,6 +425,9 @@ public:
for (int i = 0; i < 6; i++) { box.aabbs.push_back(box.aabb); } for (int i = 0; i < 6; i++) { box.aabbs.push_back(box.aabb); }
this->m_allVisible.push_back(box); this->m_allVisible.push_back(box);
auto result = this->getAreaAndVolume(this->m_allVisible.size() - 1);
this->m_allArea.push_back(result.first);
this->m_allVolume.push_back(result.second);
return this->m_allVisible.size() - 1; return this->m_allVisible.size() - 1;
} }
@ -454,12 +462,16 @@ public:
std::vector<algoim::SparkStack<algoim::real>*> temp; std::vector<algoim::SparkStack<algoim::real>*> temp;
algoim::algoimSparkAllocHeapVector(temp, cylinder.tensors); algoim::algoimSparkAllocHeapVector(temp, cylinder.tensors);
algoim::organizer::CylinderDesc cylinderDesc(bottomOrigion.getUVector3Data(), radius, offset.length(), alignAxis); algoim::organizer::CylinderDesc cylinderDesc(bottomOrigion.getUVector3Data(), radius, offset.length(), alignAxis);
algoim::organizer::makeCylinder(cylinderDesc, cylinder);
for (auto& pointer : temp) { this->m_allPointer.push_back(pointer); } for (auto& pointer : temp) { this->m_allPointer.push_back(pointer); }
for (int i = 0; i < 3; i++) { cylinder.aabbs.push_back(cylinder.aabb); } for (int i = 0; i < 3; i++) { cylinder.aabbs.push_back(cylinder.aabb); }
this->m_allVisible.push_back(cylinder); this->m_allVisible.push_back(cylinder);
auto result = this->getAreaAndVolume(this->m_allVisible.size() - 1);
this->m_allArea.push_back(result.first);
this->m_allVolume.push_back(result.second);
return this->m_allVisible.size() - 1; return this->m_allVisible.size() - 1;
} }
@ -492,6 +504,9 @@ public:
for (size_t i = 0; i < faces.size(); i++) { mesh.aabbs.push_back(mesh.aabb); } for (size_t i = 0; i < faces.size(); i++) { mesh.aabbs.push_back(mesh.aabb); }
this->m_allVisible.push_back(mesh); this->m_allVisible.push_back(mesh);
auto result = this->getAreaAndVolume(this->m_allVisible.size() - 1);
this->m_allArea.push_back(result.first);
this->m_allVolume.push_back(result.second);
return this->m_allVisible.size() - 1; return this->m_allVisible.size() - 1;
} }
@ -503,6 +518,10 @@ public:
{ {
algoim::organizer::VisiblePrimitiveRep empty; algoim::organizer::VisiblePrimitiveRep empty;
this->m_allVisible.push_back(empty); this->m_allVisible.push_back(empty);
this->m_allArea.push_back(0);
this->m_allVolume.push_back(0);
return this->m_allVisible.size() - 1; return this->m_allVisible.size() - 1;
} }
@ -562,6 +581,15 @@ public:
return std::make_pair(area, volume); return std::make_pair(area, volume);
} }
void output()
{
for (auto& volume : this->m_allVolume) { std::cout << volume << ","; }
std::cout << std::endl;
for (auto& area : this->m_allArea) { std::cout << area << ","; }
std::cout << std::endl;
}
protected: protected:
/** /**
* @brief Compute the barycentric coordinates of polygon * @brief Compute the barycentric coordinates of polygon
@ -930,10 +958,15 @@ protected:
result = this->intersectNode(result, halfPlane2); result = this->intersectNode(result, halfPlane2);
this->m_allVisible.push_back(result); this->m_allVisible.push_back(result);
auto result1 = this->getAreaAndVolume(this->m_allVisible.size() - 1);
this->m_allArea.push_back(result1.first);
this->m_allVolume.push_back(result1.second);
return this->m_allVisible.size() - 1; return this->m_allVisible.size() - 1;
} }
private: private:
std::vector<algoim::organizer::VisiblePrimitiveRep> m_allVisible; std::vector<algoim::organizer::VisiblePrimitiveRep> m_allVisible;
std::vector<algoim::SparkStack<algoim::real>*> m_allPointer; std::vector<algoim::SparkStack<algoim::real>*> m_allPointer;
std::vector<double> m_allVolume;
std::vector<double> m_allArea;
}; };

61
examples/example_loader.cpp

@ -1,5 +1,5 @@
#include "organizer/loader.hpp"
#include "example_loader2.hpp" #include "example_loader2.hpp"
#include "organizer/loader.hpp"
void loaderTest1() void loaderTest1()
{ {
@ -782,15 +782,15 @@ void loaderTest2()
/* 体111和体13布尔并 */ /* 体111和体13布尔并 */
loader.unionNode(tag111, tag13); loader.unionNode(tag111, tag13);
before = loader.getAreaAndVolume(tag1); // before = loader.getAreaAndVolume(tag1);
/* 体1和体111布尔差 */ /* 体1和体111布尔差 */
loader.differentNode(tag1, tag111); loader.differentNode(tag1, tag111);
after = loader.getAreaAndVolume(tag1); // after = loader.getAreaAndVolume(tag1);
/* 获取体1 布尔前后的体积差和面积差 */ /* 获取体1 布尔前后的体积差和面积差 */
areaDifference = after.first - before.first; // areaDifference = after.first - before.first;
volumeDifference = after.second - before.second; // volumeDifference = after.second - before.second;
std::cout << areaDifference << ", " << volumeDifference << std::endl; // std::cout << areaDifference << ", " << volumeDifference << std::endl;
/* 定义空体 扣减体1 */ /* 定义空体 扣减体1 */
auto subTag1 = loader.addEmpty(); auto subTag1 = loader.addEmpty();
@ -902,15 +902,15 @@ void loaderTest2()
points.push_back(Point3D{-23121.583250388911, 11781.089681679974, -2900.0000000000000}); points.push_back(Point3D{-23121.583250388911, 11781.089681679974, -2900.0000000000000});
for (auto& point : points) { cycle(point); } for (auto& point : points) { cycle(point); }
before = loader.getAreaAndVolume(tag1); // before = loader.getAreaAndVolume(tag1);
/* 体1和扣减体1布尔差 */ /* 体1和扣减体1布尔差 */
loader.differentNode(tag1, subTag1); loader.differentNode(tag1, subTag1);
after = loader.getAreaAndVolume(tag1); // after = loader.getAreaAndVolume(tag1);
/* 获取 体1 布尔前后的 体积差 和 面积差 */ /* 获取 体1 布尔前后的 体积差 和 面积差 */
areaDifference = after.first - before.first; // areaDifference = after.first - before.first;
volumeDifference = after.second - before.second; // volumeDifference = after.second - before.second;
std::cout << areaDifference << ", " << volumeDifference << std::endl; // std::cout << areaDifference << ", " << volumeDifference << std::endl;
/* 体15:Ent1.bool */ /* 体15:Ent1.bool */
bottomPoint = Point3D{0.0000, 0.0000, -3600.0000}; bottomPoint = Point3D{0.0000, 0.0000, -3600.0000};
@ -1068,15 +1068,15 @@ void loaderTest2()
offset = -2900; offset = -2900;
loader.offset(tag22, direction, offset); loader.offset(tag22, direction, offset);
before = loader.getAreaAndVolume(tag1); // before = loader.getAreaAndVolume(tag1);
/* 体1和体22布尔差 */ /* 体1和体22布尔差 */
loader.differentNode(tag1, tag22); loader.differentNode(tag1, tag22);
after = loader.getAreaAndVolume(tag1); // after = loader.getAreaAndVolume(tag1);
/* 获取体1 布尔前后的体积差和面积差 */ /* 获取体1 布尔前后的体积差和面积差 */
areaDifference = after.first - before.first; // areaDifference = after.first - before.first;
volumeDifference = after.second - before.second; // volumeDifference = after.second - before.second;
std::cout << areaDifference << ", " << volumeDifference << std::endl; // std::cout << areaDifference << ", " << volumeDifference << std::endl;
/* 体23 */ /* 体23 */
points.clear(); points.clear();
@ -1097,15 +1097,15 @@ void loaderTest2()
offset = -2900; offset = -2900;
loader.offset(tag23, direction, offset); loader.offset(tag23, direction, offset);
before = loader.getAreaAndVolume(tag1); // before = loader.getAreaAndVolume(tag1);
/* 体1和体23布尔差 */ /* 体1和体23布尔差 */
loader.differentNode(tag1, tag23); loader.differentNode(tag1, tag23);
after = loader.getAreaAndVolume(tag1); // after = loader.getAreaAndVolume(tag1);
/* 获取体1 布尔前后的体积差和面积差 */ /* 获取体1 布尔前后的体积差和面积差 */
areaDifference = after.first - before.first; // areaDifference = after.first - before.first;
volumeDifference = after.second - before.second; // volumeDifference = after.second - before.second;
std::cout << areaDifference << ", " << volumeDifference << std::endl; // std::cout << areaDifference << ", " << volumeDifference << std::endl;
/* 以下为一个循环,凸度组固定,但点组不一样,其他操作一致 */ /* 以下为一个循环,凸度组固定,但点组不一样,其他操作一致 */
auto cycle1 = [&loader, tag1](const Point3D& point1, const Point3D point2) { auto cycle1 = [&loader, tag1](const Point3D& point1, const Point3D point2) {
@ -1326,20 +1326,25 @@ void loaderTest2()
points.push_back(Point3D{9439.2132826892957, -23922.043573038238, 0.0000000000000000}); points.push_back(Point3D{9439.2132826892957, -23922.043573038238, 0.0000000000000000});
points.push_back(Point3D{8993.7087385355990, -24149.036306706977, 0.0000000000000000}); points.push_back(Point3D{8993.7087385355990, -24149.036306706977, 0.0000000000000000});
before = loader.getAreaAndVolume(tag1); // before = loader.getAreaAndVolume(tag1);
for (size_t i = 0; i < points.size(); i += 4) { cycle2(points[i], points[i + 1], points[i + 2], points[i + 3]); } for (size_t i = 0; i < points.size(); i += 4) { cycle2(points[i], points[i + 1], points[i + 2], points[i + 3]); }
after = loader.getAreaAndVolume(tag1); // after = loader.getAreaAndVolume(tag1);
/* 获取体1 布尔前后的体积差和面积差 */ /* 获取体1 布尔前后的体积差和面积差 */
areaDifference = after.first - before.first; // areaDifference = after.first - before.first;
volumeDifference = after.second - before.second; // volumeDifference = after.second - before.second;
std::cout << areaDifference << ", " << volumeDifference << std::endl; // std::cout << areaDifference << ", " << volumeDifference << std::endl;
//auto result = loader.getAreaAndVolume(tag1);
//std::cout << "result:" << result.first << ", " << result.second << std::endl;
loader.output();
} }
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
// loaderTest1(); loaderTest2();
// loaderPolyTilted(); // loaderPolyTilted();
loaderPolyThickPlane(); // loaderPolyThickPlane();
return 0; return 0;
} }

Loading…
Cancel
Save