[vtkusers] Iterate over disjoint surfaces of an unstructured grid

Robert Sawko robertsawko at gmail.com
Sat Jan 20 11:02:22 EST 2018


I seem to be close but not quite there.

I am attaching my minimal code below. I am testing it on a file which
contains 3 surfaces and I am using "ExtractSpecifiedRegion" mode to get each
surface. When I render it the results look correct but the "is surface
closed code" consistently returns "not closed", which I find a bit surprisng
as on inspection it seems that all surfaces are actually closed.

If you have any thoughts on this or how to simplify the code below, please
let me know.


#include <vtkXMLUnstructuredGridReader.h>
#include <vtkSmartPointer.h>
#include <vtkConnectivityFilter.h>
#include <vtkGeometryFilter.h>
#include <vtkFeatureEdges.h>
#include <vtkTriangleFilter.h>
#include <vtkMassProperties.h>
#include <iostream>
 
int main ( int argc, char *argv[] )
{
    //parse command line arguments
    if(argc != 2) {
        std::cerr << "Usage: " << argv[0]
            << " Filename(.vtu)" << std::endl;
        return EXIT_FAILURE;
    }

    std::string filename = argv[1];

    //read all the data from the file
    vtkSmartPointer<vtkXMLUnstructuredGridReader> reader =
        vtkSmartPointer<vtkXMLUnstructuredGridReader>::New();
    reader->SetFileName(filename.c_str());
    reader->Update();

    vtkSmartPointer<vtkConnectivityFilter> connectivity = 
        vtkSmartPointer<vtkConnectivityFilter>::New();
    connectivity->SetInputConnection(reader->GetOutputPort());
    connectivity->SetExtractionModeToSpecifiedRegions(); 
    connectivity->InitializeSpecifiedRegionList();
    connectivity->Update(); 

    std::cout << "Number of extracted regions: " 
        << connectivity->GetNumberOfExtractedRegions()
        << "\nNumber of output ports: "
        << connectivity->GetNumberOfOutputPorts()
        << "\nExtraction mode: "
        << connectivity->GetExtractionModeAsString()
        << " ("  << connectivity->GetExtractionMode() <<  ")"
        << std::endl;
    
    vtkSmartPointer<vtkGeometryFilter> geometry = 
        vtkSmartPointer<vtkGeometryFilter>::New();
    geometry->SetInputConnection(connectivity->GetOutputPort());
    geometry->Update(); 

    vtkSmartPointer<vtkFeatureEdges> featureEdges = 
        vtkSmartPointer<vtkFeatureEdges>::New();
    featureEdges->SetInputConnection(geometry->GetOutputPort());
    vtkSmartPointer<vtkMassProperties> mass =
        vtkSmartPointer<vtkMassProperties>::New();
    mass->SetInputConnection(geometry->GetOutputPort());

    for(int i = 0; i < connectivity->GetNumberOfExtractedRegions(); i++)
    {
        connectivity->AddSpecifiedRegion(i);
        featureEdges->Update();

        int numberOfOpenEdges =
featureEdges->GetOutput()->GetNumberOfCells();

        mass->Update();
        std::cout << "Region " << i
            << "\n\tSurface area: " << mass->GetSurfaceArea();

        if(numberOfOpenEdges > 0)
        {
            std::cout << "\n\tSurface is not closed" << std::endl;
        }
        else
        {
            std::cout << "\n\tSurface is closed" << std::endl;
            std::cout << "\n\tVolume is: "
                << mass->GetVolume() << std::endl;
        }

    }
    return EXIT_SUCCESS;
}




--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html


More information about the vtkusers mailing list