【问题标题】:How to process output: trim_with_solid如何处理输出:trim_with_solid
【发布时间】:2020-11-26 07:41:03
【问题描述】:

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
                                     );

处理输出:

    // 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
        }
    }

效果不错

有时修剪结果很好。就像这个用实心圆柱体修剪茶壶模型的例子:

不好的结果

但有时修剪结果并不如预期:

如上面的wire-frame视图所示,茶壶和圆柱的交点被正确识别。但由于某种原因,这个循环无法检测到圆柱体外部的三角形:

   // 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
        }
    }

有人知道我可能遗漏了什么吗?

【问题讨论】:

    标签: c++ graphics computational-geometry cgal libigl


    【解决方案1】:

    以前,我将Qt3DExtras::QCylinderMesh 用作实心BVBFB)。但它不是防水。我用以下代码替换了它,该代码创建了防水圆柱体。

    标题:
        // 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;
    }
    

    现在已经正确创建了孔:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-22
      • 2012-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-19
      相关资源
      最近更新 更多