簡體   English   中英

如何處理 output:trim_with_solid

[英]How to process output: trim_with_solid

trim_with_solid被稱為:

// Trim mesh A (m_VA and m_FA) with solid B (m_VB and m_FB)
igl::copyleft::cgal::trim_with_solid(
                                     m_VA, m_FA           // input: mesh A
                                     , m_VB, m_FB         // input: solid B
                                     , m_V, m_F, m_D, m_J // output
                                     );

output 處理:

    // Loop over output vertex data
    for (int i = 0; i < m_V.rows(); ++i) {
        // Access all the vertex data
    }

   // Loop over output triangle (face) data
    for (int i = 0; i < m_F.rows(); ++i) {
        // Condition to decide if facet is inside or outside the solid B
        if (m_D.coeff(i)) {
            // The output face is outside the solid B
        } else {
            // The output face is inside the solid B
        }
    }

結果很好

有時修剪結果很好。 就像這個用實心圓柱體修剪茶壺 model 的那樣:

圖片

圖片

結果不好

但有時修剪結果並不像預期的那樣:

圖片

圖片

圖片

如上面的線框視圖所示,茶壺和圓柱體的交點被正確識別。 但由於某種原因,此循環無法檢測到圓柱體外部的三角形:

   // Loop over output triangle (face) data
    for (int i = 0; i < m_F.rows(); ++i) {
        // Condition to decide if facet is inside or outside the solid B
        if (m_D.coeff(i)) {
            // Face is outside the solid B
        } else {
            // Face is inside the solid B
        }
    }

有人知道我可能缺少什么嗎?

以前,我使用Qt3DExtras::QCylinderMesh作為實體BVBFB )。 但它不是水密的。 我用以下代碼替換了它,該代碼創建了防水圓柱體。

Header:
 // Create a cylinder mesh which is exactly solid // without any open boundary // Down facing cylinder in Z direction with arguments: // r: radius // h: Height // ssteps: how many edges will create the base circle // sp: starting point static void cylinder( std::vector<QVector3D>& points, std::vector<std::array<int, 3>>& indices, const float r, const float h, const size_t ssteps = 45, const QVector3D &sp = QVector3D() );
資源:
 void EditorUtils::cylinder( std::vector<QVector3D> &points, std::vector<std::array<int, 3>> &indices, const float r, const float h, const size_t ssteps, const QVector3D &sp ) { assert(ssteps > 0); auto PI = M_PI; auto steps = int(ssteps); points.reserve(2*ssteps); double a = 2*PI/steps; QVector3D jp = sp; QVector3D endp = {sp.x(), sp.y(), sp.z() + h}; // Upper circle points for(int i = 0; i < steps; ++i) { double phi = i*a; double ex = endp.x() + r*std::cos(phi); double ey = endp.y() + r*std::sin(phi); points.emplace_back(ex, ey, endp.z()); } // Lower circle points for(int i = 0; i < steps; ++i) { double phi = i*a; double x = jp.x() + r*std::cos(phi); double y = jp.y() + r*std::sin(phi); points.emplace_back(x, y, jp.z()); } // Now create long triangles connecting upper and lower circles indices.reserve(2*ssteps); auto offs = steps; for(int i = 0; i < steps - 1; ++i) { indices.emplace_back(std::array<int, 3>{i, i + offs, offs + i + 1}); indices.emplace_back(std::array<int, 3>{i, offs + i + 1, i + 1}); } // Last triangle connecting the first and last vertices auto last = steps - 1; indices.emplace_back(std::array<int, 3>{0, last, offs}); indices.emplace_back(std::array<int, 3>{last, offs + last, offs}); // Try generating a watertight body. // So we create a triangle fan for the upper and lower // ending of the cylinder to close the geometry. points.emplace_back(jp); int ci = int(points.size() - 1); for(int i = 0; i < steps - 1; ++i) indices.emplace_back(std::array<int, 3>{i + offs + 1, i + offs, ci}); indices.emplace_back(std::array<int, 3>{offs, steps + offs - 1, ci}); points.emplace_back(endp); ci = int(points.size() - 1); for(int i = 0; i < steps - 1; ++i) indices.emplace_back(std::array<int, 3>{ci, i, i + 1}); indices.emplace_back(std::array<int, 3>{steps - 1, 0, ci}); return; }

現在孔已正確創建:

圖片

圖片

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM