Exemple #1
0
bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read
(
    const fileName& filename
)
{
    const bool mustTriangulate = this->isTri();
    this->clear();

    fileName baseName = filename.lessExt();

    // STAR-CD index of points
    List<label> pointId;

    // read points from .vrt file
    readPoints
    (
        IFstream(baseName + ".vrt")(),
        this->storedPoints(),
        pointId
    );

    // Build inverse mapping (STAR-CD pointId -> index)
    Map<label> mapPointId(2*pointId.size());
    forAll(pointId, i)
    {
        mapPointId.insert(pointId[i], i);
    }
Foam::autoPtr<Foam::edgeMesh> Foam::edgeMesh::New(const fileName& name)
{
    word ext = name.ext();
    if (ext == "gz")
    {
        ext = name.lessExt().ext();
    }
    return New(name, ext);
}
Foam::autoPtr<Foam::UnsortedMeshedSurface<Face>>
Foam::UnsortedMeshedSurface<Face>::New(const fileName& name)
{
    word ext = name.ext();
    if (ext == "gz")
    {
        ext = name.lessExt().ext();
    }

    return New(name, ext);
}
Exemple #4
0
bool isoBubble::write(fileName file) const
{
    fileName fullPath = file.lessExt(); 
    mkDir(fullPath); 

    fullPath = fullPath + "/" + paddWithZeros(file); 

    bubblePtr_->write(fullPath); 

    return true;
}
bool Foam::edgeMesh::canRead
(
    const fileName& name,
    const bool verbose
)
{
    word ext = name.ext();
    if (ext == "gz")
    {
        ext = name.lessExt().ext();
    }
    return canReadType(ext, verbose);
}
bool Foam::UnsortedMeshedSurface<Face>::canRead
(
    const fileName& name,
    const bool verbose
)
{
    word ext = name.ext();
    if (ext == "gz")
    {
        ext = name.lessExt().ext();
    }
    return canReadType(ext, verbose);
}
bool Foam::edgeMesh::read(const fileName& name)
{
    word ext = name.ext();
    if (ext == "gz")
    {
        fileName unzipName = name.lessExt();
        return read(unzipName, unzipName.ext());
    }
    else
    {
        return read(name, ext);
    }
}
int main(int argc, char *argv[])
{
    argList::noParallel();
    argList::validArgs.clear();
    argList::validArgs.append("input surface file");
    argList args(argc, argv);

    const fileName inFileName(args.args()[1]);
    if( inFileName.ext() == "fms" )
        FatalError << "trying to convert a fms file to itself"
            << exit(FatalError);

    fileName outFileName(inFileName.lessExt()+".fms");

    const triSurf surface(inFileName);

    surface.writeSurface(outFileName);

    Info << "End\n" << endl;

    return 0;
}
int main(int argc, char *argv[])
{
    argList::addNote
    (
        "write surface mesh regions to separate files"
    );

    argList::noParallel();
    argList::validArgs.append("input surfaceFile");
    argList args(argc, argv);

    const fileName surfName = args[1];

    Info<< "Reading surf from " << surfName << " ..." << nl << endl;

    fileName surfBase = surfName.lessExt();

    word extension = surfName.ext();

    triSurface surf(surfName);

    Info<< "Writing regions to separate files ..."
        << nl << endl;


    const geometricSurfacePatchList& patches = surf.patches();

    forAll(patches, patchi)
    {
        const geometricSurfacePatch& pp = patches[patchi];

        word patchName = pp.name();

        if (patchName.empty())
        {
            patchName = "patch" + Foam::name(patchi);
        }

        fileName outFile(surfBase + '_' + patchName + '.' + extension);

        Info<< "   Writing patch " << patchName << " to file " << outFile
            << endl;


        // Collect faces of region
        boolList includeMap(surf.size(), false);

        forAll(surf, facei)
        {
            const labelledTri& f = surf[facei];

            if (f.region() == patchi)
            {
                includeMap[facei] = true;
            }
        }

        // Subset triSurface
        labelList pointMap;
        labelList faceMap;

        triSurface subSurf
        (
            surf.subsetMesh
            (
                includeMap,
                pointMap,
                faceMap
            )
        );

        subSurf.write(outFile);
    }

    Info<< "End\n" << endl;

    return 0;
}
    void extractFeatures
    (
        const fileName& surfaceFileName,
        const Time& runTime,
        const dictionary& dict
    )
    {
        const fileName sFeatFileName = surfaceFileName.lessExt().name();

        Info<< "Surface            : " << surfaceFileName << nl << endl;

        const Switch writeVTK =
            dict.lookupOrDefault<Switch>("writeVTK", "off");
        const Switch writeObj =
            dict.lookupOrDefault<Switch>("writeObj", "off");
        const Switch verboseObj =
            dict.lookupOrDefault<Switch>("verboseObj", "off");

        const Switch curvature =
            dict.lookupOrDefault<Switch>("curvature", "off");
        const Switch featureProximity =
            dict.lookupOrDefault<Switch>("featureProximity", "off");
        const Switch closeness =
            dict.lookupOrDefault<Switch>("closeness", "off");


        Info<< nl << "Feature line extraction is only valid on closed manifold "
            << "surfaces." << endl;

        // Read
        // ~~~~

        triSurface surf(runTime.constantPath()/"triSurface"/surfaceFileName);

        Info<< "Statistics:" << endl;
        surf.writeStats(Info);
        Info<< endl;

        const faceList faces(surf.faces());

        // Either construct features from surface & featureAngle or read set.
        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        const scalar includedAngle = readScalar(dict.lookup("includedAngle"));

        autoPtr<surfaceFeatures> set
        (
            surfaceFeatureSet
            (
                surfaceFileName,
                surf,
                dict,
                includedAngle
            )
        );

        // Trim set
        // ~~~~~~~~

        if (dict.isDict("trimFeatures"))
        {
            dictionary trimDict = dict.subDict("trimFeatures");

            scalar minLen =
                trimDict.lookupOrAddDefault<scalar>("minLen", -great);

            label minElem = trimDict.lookupOrAddDefault<label>("minElem", 0);

            // Trim away small groups of features
            if (minElem > 0 || minLen > 0)
            {
                Info<< "Removing features of length < "
                    << minLen << endl;
                Info<< "Removing features with number of edges < "
                    << minElem << endl;

                set().trimFeatures(minLen, minElem, includedAngle);
            }
        }


        // Subset
        // ~~~~~~

        // Convert to marked edges, points
        List<surfaceFeatures::edgeStatus> edgeStat(set().toStatus());

        if (dict.isDict("subsetFeatures"))
        {
            const dictionary& subsetDict = dict.subDict
            (
                "subsetFeatures"
            );

            if (subsetDict.found("insideBox"))
            {
                treeBoundBox bb(subsetDict.lookup("insideBox")());

                Info<< "Selecting edges inside bb " << bb;
                if (writeObj)
                {
                    Info << " see insideBox.obj";
                    bb.writeOBJ("insideBox.obj");
                }
                Info<< endl;

                selectBox(surf, bb, true, edgeStat);
            }
            else if (subsetDict.found("outsideBox"))
            {
                treeBoundBox bb(subsetDict.lookup("outsideBox")());

                Info<< "Removing all edges inside bb " << bb;
                if (writeObj)
                {
                    Info<< " see outsideBox.obj" << endl;
                    bb.writeOBJ("outsideBox.obj");
                }
                Info<< endl;

                selectBox(surf, bb, false, edgeStat);
            }

            const Switch nonManifoldEdges =
                subsetDict.lookupOrDefault<Switch>("nonManifoldEdges", "yes");

            if (!nonManifoldEdges)
            {
                Info<< "Removing all non-manifold edges"
                    << " (edges with > 2 connected faces) unless they"
                    << " cross multiple regions" << endl;

                selectManifoldEdges(surf, 1e-5, includedAngle, edgeStat);
            }

            const Switch openEdges =
                subsetDict.lookupOrDefault<Switch>("openEdges", "yes");

            if (!openEdges)
            {
                Info<< "Removing all open edges"
                    << " (edges with 1 connected face)" << endl;

                forAll(edgeStat, edgei)
                {
                    if (surf.edgeFaces()[edgei].size() == 1)
                    {
                        edgeStat[edgei] = surfaceFeatures::NONE;
                    }
                }
            }

            if (subsetDict.found("plane"))
            {
                const plane cutPlane(subsetDict.lookup("plane")());

                selectCutEdges(surf, cutPlane, edgeStat);

                Info<< "Only edges that intersect the plane with normal "
                    << cutPlane.normal()
                    << " and base point " << cutPlane.refPoint()
                    << " will be included as feature edges."<< endl;
            }
        }