Ejemplo n.º 1
0
void MeshFileManager::writeShape(const Grid3D &grid, const QString &path)
{
    QFile file(getRootPath() + path);
    if (!file.open(QIODevice::WriteOnly)) {
        return;
    }

    QTextStream stream(&file);
    stream  << "MeshVersionFormatted 1" << endl
            << "Dimension" << endl
            << "3" << endl;

    stream  << "Vertices" << endl
            <<  grid.getNx() * grid.getNy() * grid.getNz() << endl;

    for (int z = 0; z < grid.getNz(); ++z) {
        for (int y = 0; y < grid.getNy(); ++y) {
            for (int x = 0; x < grid.getNx(); ++x) {
                Point3D currentPoint(grid.getOrigin().getX() + x,
                                     grid.getOrigin().getY() + y,
                                     grid.getOrigin().getZ() + z);

                if (grid.getProperty(currentPoint.getX(), currentPoint.getY(), currentPoint.getZ()) < 0) {
                    stream << currentPoint.format()
                           << endl;
                }
            }
        }
    }

    stream << "End" << endl;
}
Ejemplo n.º 2
0
void MeshFileManager::writeGeometry(const Grid3D &grid, const QString &path)
{
    QFile file(getRootPath() + path);
    if (!file.open(QIODevice::WriteOnly)) {
        return;
    }

    QTextStream stream(&file);
    stream  << "MeshVersionFormatted 1" << endl
            << "Dimension" << endl
            << "3" << endl;

    int nx = grid.getNx();
    int ny = grid.getNy();
    int nz = grid.getNz();
    Point3D origin = grid.getOrigin();

    stream  << "Vertices" << endl
            <<  nx * ny * nz << endl;
    QVector<Hexaedra> hexs;

    int xD = 1;
    int yD = nx;
    int zD = nx * ny;
    for (int z = 0; z < nz; ++z) {
        for (int y = 0; y < ny; ++y) {
            for (int x = 0; x < nx; ++x) {
                stream << Point3D(origin.getX() + x, origin.getY() + y, origin.getZ() + z).format()
                       << endl;

                if (!(x == nx - 1 || y == ny - 1 || z == nz - 1)) {
                    hexs.push_back(Hexaedra(
                        xD * (x + 0) + yD * (y + 0) + zD * (z + 0),
                        xD * (x + 1) + yD * (y + 0) + zD * (z + 0),
                        xD * (x + 1) + yD * (y + 1) + zD * (z + 0),
                        xD * (x + 0) + yD * (y + 1) + zD * (z + 0),
                        xD * (x + 0) + yD * (y + 0) + zD * (z + 1),
                        xD * (x + 1) + yD * (y + 0) + zD * (z + 1),
                        xD * (x + 1) + yD * (y + 1) + zD * (z + 1),
                        xD * (x + 0) + yD * (y + 1) + zD * (z + 1)
                    ));
                }
            }
        }
    }

    stream  << "Hexahedra" << endl
            << hexs.size() << endl;

    for (int i = 0; i < hexs.size(); ++i) {
        stream << hexs.at(i).format() << endl;
    }

    stream << "End" << endl;
}