How to get the cut shell by a cutting plane


While HOOPS Visualize has a cutting plane geometry that allows the developer to visualize the cut model with the capping, HOOPS Visualize does not have a capability to get the cut shell geometry, that is necessary to calculate the area of the cut model, etc. Because HOOPS Visualize is not a modeler, you have to license a modeler SDK, or do it yourself. The following code snippet gives you an idea of how to do it. It uses one simple mathmatics equation, and simple HOOPS Shell handling.


        // Step 1 : Get Points and FaceList from HPS Shell
        HPS::PointArray Points;
        HPS::IntArray FaceList;

        m_key.ShowPoints(Points);
        m_key.ShowFacelist(FaceList);
        int iPointSize = (int)Points.size();
        int iFaceListSize = (int)FaceList.size();

        double a = cutting_plane_normal.x;
        double b = cutting_plane_normal.y;
        double c = cutting_plane_normal.z;
        double d = cutting_planes[translating_plane_offset].d;
        double x;
        double y;
        double z;

        // Step 2 : Extract Points and FaceList that are located in the positive side of the cutting plane
        int iPointCountOut = 0;

        HPS::BoolArray PointSide;
        HPS::IntArray PointMap;
        HPS::PointArray PointsOut;
        HPS::IntArray FaceListOut;

        // Evaluate which side each point belongs to, and make another point array with points that are all in positive side
        for (int i = 0; i < iPointSize; i++)
        {
                x = Points[i].x;
                y = Points[i].y;
                z = Points[i].z;
                if (a * x + b * y + c * z + d > 0)
                {
                        PointSide.push_back(true);
                        PointsOut.push_back(Points[i]);
                        PointMap.push_back(iPointCountOut++);
                }
                else
                {
                        PointSide.push_back(false);
                        PointMap.push_back(0);
                }
        }

        // Evaluate if each triangle belongs to the positive side, and make another face list array with points that are all on the positive side
        for (int i = 0; i < iFaceListSize; i += 4)
        {
                if (FaceList[i] != 3)
                {
                        char msg[1024];
                        sprintf_s(msg, 1024, "not a triangle");
                        MessageBoxA(NULL, msg, NULL, 0);
                }

                int u = FaceList[i + 1];
                int v = FaceList[i + 2];
                int w = FaceList[i + 3];

                if (PointSide[u] && PointSide[v] && PointSide[w])
                {
                        FaceListOut.push_back(3);
                        FaceListOut.push_back(PointMap[u]);
                        FaceListOut.push_back(PointMap[v]);
                        FaceListOut.push_back(PointMap[w]);
                }
        }

        // Step 3 : Insert Shell in order to visually check the result
        m_keyShellCut.Flush(HPS::Search::Type::Geometry);
        m_keyShellCut.InsertShell(PointsOut, FaceListOut);
1 Like