Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision 1f7801656c9e30ee4b174b6dede619f383555b5f authored by IuricichF on 14 May 2016, 20:29:04 UTC, committed by IuricichF on 14 May 2016, 20:29:04 UTC
Automatically set the absolute paths for the .pvsm files in dist/ folder
1 parent 1077952
  • Files
  • Changes
  • 681957e
  • /
  • source
  • /
  • main.cpp
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:1f7801656c9e30ee4b174b6dede619f383555b5f
directory badge Iframe embedding
swh:1:dir:cd72a8379712b7e38c02d40fae7b301ade7bfa6f
content badge Iframe embedding
swh:1:cnt:092d0f71bab0cdefa8f15bdb09a0a42daf4b557f

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
main.cpp
#include "./WatershedAlgs/simulatedimmersion.h"
#include "./LibForman/formangradientvector.h"

using namespace std;

void readInput(int argc, char** argv);

string meshFile("none");
string fieldFile("none");
string segmFile("none");


int main(int argc, char* argv[])
{

    MemoryUsage usage;
    Timer time;

    Mesh mesh = Mesh();

    readInput(argc, argv);
    if(meshFile.find(".tri") != string::npos)
        Reader::readMeshFile(mesh,meshFile);
    else if(meshFile.find(".off") != string::npos)
        Reader::readOFFMesh(mesh,meshFile);
    else if(meshFile.find(".vtk") != string::npos){
        Reader::readVTKFile(mesh, meshFile);
    }
    else{
        cout << "[Invalid input file] - supported formats: .off .tri .vtk" << endl;
        return 0;
    }

    mesh.build(); //build the mesh structure
    cout << "Mesh with " << mesh.getNumVertex() << " vertices and " << mesh.getTopSimplexesNum() << "triangles [LOADED]" << endl;

    if(fieldFile != "none"){
        Reader::readScalarField(mesh,fieldFile);
    }


    FormanGradientVector gradient = FormanGradientVector(&mesh);
    vector<int> segm;
    if(segmFile == "immersion"){
        time.start();
        //compute the watershed segmentation with a simulated immersion approach
        int nRegions = simulatedImmersionSegmentation(mesh,true,segm);
        cout << "Segmentation by Simulated immersion computed. " << nRegions << endl;
        //compute the Forman gradient using the watershe segmentation
        gradient.watershedToForman(segm);
    }
    else if(segmFile == "exp"){
        //Greedy discrimination of flat regions
        map<double, vector<int> > vert;
        for(int i=0; i<mesh.getNumVertex(); i++){
            vert[mesh.getVertex(i).getF()].push_back(i);
        }

        int count=0;
        for(auto m : vert){
            for(auto v : m.second){
                mesh.getVertex(v).setF(count++);
            }
        }
        time.start();
        //compute the Forman gradient via homotopty expansion
        gradient.homotopy_expansion();

    }
    else if(segmFile == "exp-improved"){
        //Improved simulation of simplicity

        priority_queue<pair<int,float>, vector<pair<int,float> >, Comparer> simpleOrder;
        priority_queue<pair<int,float>, vector<pair<int,float> >, Comparer> bfsOrder;

        int count=0;
        vector<int> newF(mesh.getNumVertex(),-1);

        for(int i=0; i<mesh.getNumVertex(); i++)
            simpleOrder.push(pair<int,double>(i,mesh.getVertex(i).getF()));

        while(!simpleOrder.empty()){

            if(bfsOrder.empty() || bfsOrder.top().second > simpleOrder.top().second){

                int vertex = simpleOrder.top().first;
                simpleOrder.pop();

                if(newF[vertex]!=-1)
                    continue;

                newF[vertex]=count++;

                vector<int> vv = mesh.VV(vertex);
                for(auto adj : vv){
                    if(newF[adj]==-1){
                        bfsOrder.push(pair<int,double>(adj,mesh.getVertex(adj).getF()));
                    }
                }
            }

            else {

                int vertex = bfsOrder.top().first;
                bfsOrder.pop();

                if(newF[vertex]!=-1)
                    continue;

                newF[vertex]=count++;

                vector<int> vv = mesh.VV(vertex);
                for(auto adj : vv){
                    if(newF[adj]==-1){
                        bfsOrder.push(pair<int,double>(adj,mesh.getVertex(adj).getF()));
                    }
                }
            }
        }


        for(int i=0; i<newF.size(); i++){
            assert(newF[i] != -1);
            mesh.getVertex(i).setF(newF[i]);
        }

        time.start();
        //compute the Forman gradient via homotopty expansion
        gradient.homotopy_expansion();

    }
    else{
        assert(fieldFile == "none");
        cout << "Select a method for computing the Forman gradient. " << endl;
        cout << "   [immersion] Forman gradient combined with the watershed segmentaiton " << endl;
        cout << "   [exp] simulation of simplicity + homotopy expansion " << endl;
        cout << "   [exp-improved] improved simulation of simplicity + homotopy expansion " << endl;
        return 1;
    }


    time.stop();
    cout << endl;
    cout << "Gradient computed in " << time.getElapsedTime() << " using " << usage.getValue_in_MB(false) << " MB" << endl;

    vector<int> cp = gradient.count_critical_simplexes();
    int numC = cp[0] + cp[1] + cp[2];
    cout << "Critical Points found (min sad max)" << cp[0] << " " << cp[1] << " " << cp[2] << " SUM: "<< numC << endl << endl;

    if(strstr(argv[2], "Crater") != NULL && argc > 4){
        gradient.writeVTK_criticalPoints("criticalPoints.vtk");
        gradient.descending_2cells_extraction(true);
        gradient.descending_1cells_extraction(true);
        gradient.ascending_1cells_extraction(true);
    }

    if(strstr(argv[2], "Rim01") != NULL && argc > 5){
        gradient.writeVTK_criticalPoints("criticalPoints.vtk");
        gradient.descending_2cells_extraction(true);
    }

/////Uncomment for printing vtk files for the Forman gradient and the critical points
//    cout << "Writing Forman gradient on file: " << endl;
//    gradient.writeVTK_gradient("gradient.vtk");
//    cout << "- gradient.vtk" << endl;
//    gradient.writeVTK_criticalPoints("criticalPoints.vtk");
//    cout << "- criticalPoints.vtk" << endl << endl;

///////Uncomment for printing vtk files with the Descending Morse complex
//    cout << "Writing Morse features on file: " << endl;
//    gradient.descending_2cells_extraction(true);
//    cout << "- descending2cells.vtk" << endl;
//    gradient.descending_1cells_extraction(true);
//    cout << "- descending1cells.vtk" << endl;

///////Uncomment for printing vtk files with the Ascending Morse complex
//    gradient.ascending_2cells_extraction(true);
//    cout << "- ascending2cells.vtk" << endl;
//    gradient.ascending_1cells_extraction(true);
//    cout << "- ascending1cells.vtk" << endl;

    return 0;
}

void readInput(int argc, char** argv){

    //assert(strcmp("-i", argv[1])==0);
    int par=3;

    if(strcmp("-f", argv[1])==0){
        fieldFile = string(argv[3]);
        par=4;
    }

    meshFile = string(argv[2]);

    cout << endl;
    cout << "Mesh file        : " << meshFile << endl;
    cout << "Scalar field file: " << fieldFile << endl;

    if(argc > 3){


        segmFile = string(argv[par]);
        cout << "Segmentation method: " << segmFile << endl;
        assert(segmFile == "immersion" || segmFile == "exp" || segmFile == "exp-improved" || segmFile == "filter");
    }
    cout << endl;
}


The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

back to top

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API