Exemple #1
0
class PVGeoExtractTopography(ExtractTopography):
    def __init__(self):
        ExtractTopography.__init__(self)

    #### Seters and Geters ####

    @smproperty.doublevector(name="Tolerance", default_values=1.0)
    def set_tolerance(self, tol):
        ExtractTopography.set_tolerance(self, tol)

    @smproperty.doublevector(name="Offset", default_values=0.0)
    def set_offset(self, offset):
        ExtractTopography.set_offset(self, offset)

    @smproperty.xml(
        _helpers.get_drop_down_xml(
            name='Operation',
            command='set_operation',
            labels=ExtractTopography.get_operation_names(),
            help='This is the type of extraction operation to apply',
        ))
    def set_operation(self, op):
        ExtractTopography.set_operation(self, op)

    @smproperty.xml(
        _helpers.get_property_xml(
            name='Invert',
            command='set_invert',
            default_values=False,
            help=
            'A boolean to set whether on whether to invert the extraction.',
        ))
    def set_invert(self, flag):
        ExtractTopography.set_invert(self, flag)
Exemple #2
0
 def test_shifted_surface(self):
     """`ExtractTopography`: Test extraction for shifted surface"""
     extracted = ExtractTopography(op='intersection',
                                   tolerance=50,
                                   offset=-250).apply(
                                       self.grid, self.points)
     self.assertIsNotNone(extracted)
Exemple #3
0
    def test_simple_run(self):
        """`ExtractTopography`: Test extraction on simple data"""
        # Produce some input data
        data = vtk.vtkImageData()
        data.SetOrigin(0.0, 0.0, 0.0)
        data.SetSpacing(5.0, 5.0, 5.0)
        data.SetDimensions(20, 20, 20)
        x = y = np.linspace(0, 100, num=50, dtype=float)
        g = np.meshgrid(x, y)
        # Convert to XYZ points
        points = np.vstack(map(np.ravel, g)).T
        z = np.reshape(np.full(len(points), 55.0), (len(points), -1))
        #z = np.reshape(np.random.uniform(low=55.0, high=65.0, size=(len(points),)), (len(points), -1))
        points = np.concatenate((points, z), axis=1)
        topo = interface.points_to_poly_data(points)


        # # apply filter
        f = ExtractTopography()
        grd = f.apply(data, topo)

        # Test the output
        self.assertIsNotNone(grd)
        self.assertEqual(grd.GetDimensions(), data.GetDimensions())
        self.assertEqual(grd.GetSpacing(), data.GetSpacing())
        self.assertEqual(grd.GetOrigin(), data.GetOrigin())
        # Now check the active topo cell data?
        # TODO: implement
        active = dsa.WrapDataObject(grd).CellData['Extracted']
        for i in range(grd.GetNumberOfCells()):
            cell = grd.GetCell(i)
            bounds = cell.GetBounds()
            z = bounds[5]#(bounds[4]+bounds[5])/2.0
            if z <= 55.0:
                self.assertTrue(active[i])
            elif z > 55.0:
                self.assertFalse(active[i])
            else:
                self.fail(msg='Non-testable cell encountered')

        return
Exemple #4
0
 def test_intersection(self):
     """`ExtractTopography`: Test extraction on surface"""
     extracted = ExtractTopography(op='intersection', tolerance=50).apply(self.grid, self.points)
     self.assertIsNotNone(extracted)
Exemple #5
0
 def test_underneath(self):
     """`ExtractTopography`: Test extraction on underneath surface"""
     extracted = ExtractTopography(op='underneath').apply(self.grid, self.points)
     self.assertIsNotNone(extracted)
Exemple #6
0
 def set_invert(self, flag):
     ExtractTopography.set_invert(self, flag)
Exemple #7
0
 def set_operation(self, op):
     ExtractTopography.set_operation(self, op)
Exemple #8
0
 def set_offset(self, offset):
     ExtractTopography.set_offset(self, offset)
Exemple #9
0
 def set_tolerance(self, tol):
     ExtractTopography.set_tolerance(self, tol)
Exemple #10
0
 def __init__(self):
     ExtractTopography.__init__(self)
Exemple #11
0
# Now load the topography file from the example data:
link = 'https://dl.dropbox.com/s/gw5v3tiq68oge3l/Example-Extract-Topo.zip?dl=0'
examples.downloads._retrieve_file(link, 'Example-Extract-Topo.zip')
topo = pyvista.read(os.path.join(pyvista.EXAMPLES_PATH, 'topo.vtk'))

p = pyvista.Plotter()
p.add_mesh(topo, cmap='terrain')
p.add_mesh(mesh, color=True, show_edges=False, opacity=0.75)
p.show_grid()
p.show()

###############################################################################
# Now that you have the topography and a grid data set,
# let's go ahead and use the **Extract Topography** filter. Be sure to properly
# select the inputs to the algorithm.
extracted = ExtractTopography().apply(mesh, topo)
extracted.plot(scalars='Extracted')

###############################################################################
# op='underneath', tolerance=0.001, offset=0.0, invert=False, remove=False
# This will show the cells that are active underneath the topography surface
# (0 for above surface and 1 for below surface). Now we can threshold this gridded
# data set to remove parts of the model that are above the topography surface by
# applying a *Threshold* filter to chop out all values below 1.
#
# The resulting grid with cells above the topography extracted will look like the
# rendering below:
threshed = extracted.threshold(0.5)
threshed.plot(color=True, show_edges=True)

###############################################################################
# Now load the topography file from the example data:
link = "https://dl.dropbox.com/s/gw5v3tiq68oge3l/Example-Extract-Topo.zip?dl=0"
examples.downloads._retrieve_file(link, "Example-Extract-Topo.zip")
topo = pyvista.read(os.path.join(pyvista.EXAMPLES_PATH, "topo.vtk"))

p = pyvista.Plotter()
p.add_mesh(topo, cmap="terrain")
p.add_mesh(mesh, color=True, show_edges=False, opacity=0.75)
p.show_grid()
p.show()

###############################################################################
# Now that you have the topography and a grid data set,
# let's go ahead and use the **Extract Topography** filter. Be sure to properly
# select the inputs to the algorithm.
extracted = ExtractTopography().apply(mesh, topo)
extracted.plot(scalars="Extracted")

###############################################################################
# op='underneath', tolerance=0.001, offset=0.0, invert=False, remove=False
# This will show the cells that are active underneath the topography surface
# (0 for above surface and 1 for below surface). Now we can threshold this gridded
# data set to remove parts of the model that are above the topography surface by
# applying a *Threshold* filter to chop out all values below 1.
#
# The resulting grid with cells above the topography extracted will look like the
# rendering below:
threshed = extracted.threshold(0.5, scalars="Extracted")
threshed.plot(color=True, show_edges=True)

###############################################################################