简体   繁体   中英

Converting several splines into 3D Mesh

I'm sorry if its a repeated question, but I have the following input and want to generate the output like that.

I'm confused about how the splines converted into quad mesh, can I know what terms should I search for? What is that process is called in computer graphics?

在此处输入图像描述

在此处输入图像描述

Sample files:

Curve1 
https://pastebin.com/KUmk04pY
Curve2
https://pastebin.com/BrpbADE9
Curve3
https://pastebin.com/MX6vWMJg

Sample code to read the curves:

std::vector<glm::vec3> read_cvs(std::string filename)
{
    vector<vector<string>> content;
    vector<string> row;
    string line, word;
    std::vector<glm::vec3> curve;
    fstream file(filename, ios::in);
    if (file.is_open())
    {
        while (getline(file, line))
        {
            row.clear();

            stringstream str(line);

            while (getline(str, word, ','))
                row.push_back(word);
            content.push_back(row);
        }
    }
    else
        cout << "Could not open the file\n";

    int c = 0;
    for (int i = 0; i < content.size(); i++)
    {
        vector<float> f;
        for (int j = 0; j < content[i].size(); j++)
        {
            f.push_back(std::stof(content[i][j]));
        }

        curve.push_back(glm::vec3(f[0], f[0 + 1], f[0 + 2]));

    }
    return curve;
}

You already have all the points you need.

  • Load the splines.
  • Walk the arrays, while summing the distance between consecutive points on each individual curve.
  • When you have reached the required length for your quad's edge, elect the closest point as the next summit for your quad. (you can also extrapolate to find a point in between points given if the exact distance is needed.

In the graph you uploaded, the 'quads' are actually lines. The lines on selected (by distance between each other) splines are made of many lines between the points given, to match the curve of the spline, and the lines across are drawn using glLine() or equivalent between points selected with the algorithm described above on every spline given.

It is plainly visible in the visual example given that additional points ("splines") were created by non-linear extrapolation, which does not really make the code more complex, but does indeed increase quite a bit the number of points needed to generate the graph.

I suggest you start with only the points given. The extrapolation can be added when that works. Whatever code you'll have written by then will be reusable as is with the extra splines added as input.

Selecting all the points necessary for drawing sounds a bit tedious, and it is. That's par for the course for this kind of operation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM