def plotTurbine(hubxy, basexy, turbR, NacYaw, name):
    # Some constants
    towerres = 100  # Resolution for tower
    nacellelength = 7.5

    # --- Plot the tower ---
    towerheight = hubxy[2] - basexy[2]
    plotTower(basexy, towerheight, name)
    # towerline = pvs.Line()
    # towerline.Point1 = basexy
    # towerline.Point2 = np.array(basexy) + towerheight*np.array([0,0,1])
    # towerline.Resolution = towerRes
    # pvs.RenameSource(name+'_tower', towerline)
    # --- Plot the nacelle ---
    plotNacelle(basexy, towerheight, NacYaw, name)
    # --- Plot the rotor disk ---
    plotRotorDisk(hubxy, turbR, NacYaw, name)
    # --- Group the datasets together ---
    turbine0_rotordisk = pvs.FindSource(name + '_rotordisk')
    turbine0_nacelle = pvs.FindSource(name + '_nacelle')
    turbine0_tower = pvs.FindSource(name + '_tower')
    groupDatasets1 = pvs.GroupDatasets(
        Input=[turbine0_rotordisk, turbine0_nacelle, turbine0_tower])
    pvs.RenameSource(name + '_allobjects', groupDatasets1)
    return
Exemplo n.º 2
0
def deleteDownstream(input=None):
    """Delete downstream filters for a given input. If no input provided, all
    filters on the pipeline will be deleted.

    Args:
        input (str): The name of the object on the pipeline to preserve. 

    """
    import paraview.simple as pvs
    if input is None:
        # The below snippet deletes all Filters on the pipeline
        #- i.e. deletes anything that has an input
        #- preserves readers and sources
        for f in pvs.GetSources().values():
            if f.GetProperty("Input") is not None:
                pvs.Delete(f)
    else:
        # Be able to specify upstream source
        src = pvs.FindSource(input)
        #print('src: ', src)
        # Delete ALL things downstream of input
        for f in pvs.GetSources().values():
            #print('f: ', f)
            #print('f.Input: ', f.GetProperty("Input"))
            if f.GetPropertyValue("Input") is src:
                #print('Deleting: ', f)
                pvs.Delete(f)
    # Done
    return None
Exemplo n.º 3
0
 def show(self, name='input'):
     print("show")
     source = simple.FindSource(name)
     if source:
         rep = simple.Show(source)
         return {'id': rep.SMProxy.GetGlobalIDAsString()} if rep else {}
     return {}
Exemplo n.º 4
0
def clipThrough(clip, ax, bounds, num=10, delay=1.0):
    """
    Description
    -----------
    This macro takes a clip source and progresses its location through a set of bounds in the data scene. The macro requires that the clip already exist in the pipeline. This is especially useful if you have many clips linked together as all will move through the seen as a result of this macro.

    Parameters
    ----------
    `clip` : string
    - The string name of the clip source to be translated.

    `ax` : int
    - This is the axis on which to translate (0 for x, 1 for y, 2 for z).
    - Think of this as the normal vector for the clip.

    `bounds` : 6-element list or tuple
    - These are the bounds to constrain the clip translation.

    `num` : int, optional
    - The number of discritizations in the clip translation.

    `delay` : float, optional
    - Time delay in seconds before conducting each clip translation.

    """

    if ax is not 0 and ax is not 1 and ax is not 2:
        raise Exception('Axis %d undefined.' % ax)

    if type(bounds) is not list and type(bounds) is not tuple:
        # TODO:
        raise Exception('getting bounds from data... not implemented')

    c = [(bounds[1] + bounds[0]) / 2, (bounds[3] + bounds[2]) / 2,
         (bounds[5] + bounds[4]) / 2]

    # disable automatic camera reset on 'Show'
    pvs._DisableFirstRenderCameraReset()
    # find source
    clp = pvs.FindSource(clip)
    # get active view
    renderView = pvs.GetActiveViewOrCreate('RenderView')

    for k in np.linspace(bounds[ax * 2], bounds[ax * 2 + 1], num=num):
        if ax == 0:
            o = [k, c[1], c[2]]
            n = [1, 0, 0]
        elif ax == 1:
            o = [c[0], k, c[2]]
            n = [0, 1, 0]
        elif ax == 2:
            o = [c[0], c[1], k]
            n = [0, 0, 1]
        clp.ClipType.Origin = o
        clp.ClipType.Normal = n
        renderView.Update()
        pvs.RenderAllViews()
        time.sleep(delay)
Exemplo n.º 5
0
def follow_path(
    gui_name,
    trajectory_data,
    num_keyframes,
    scene_time_range,
    normalized_time_from_scene,
):
    # Crop trajectory data
    trajectory_start_i = 0
    trajectory_end_i = len(trajectory_data)
    for i, traj_t in enumerate(trajectory_data[:, 0]):
        if traj_t < scene_time_range[0]:
            trajectory_start_i = i
        else:
            break
    for i, traj_t in enumerate(trajectory_data[::-1, 0]):
        if traj_t > scene_time_range[1]:
            trajectory_end_i = len(trajectory_data) - i
        else:
            break
    num_traj_datapoints = trajectory_end_i - trajectory_start_i
    logger.debug(f"Trajectory data for '{gui_name}' cropped to indices"
                 f" ({trajectory_start_i}, {trajectory_end_i}) (that's"
                 f" {num_traj_datapoints} data points between times"
                 f" {trajectory_data[trajectory_start_i, 0]} and"
                 f" {trajectory_data[trajectory_end_i - 1, 0]}).")
    assert num_keyframes <= num_traj_datapoints, (
        "Time resolution in trajectory file is not sufficient for"
        f" {num_keyframes} keyframes.")
    keep_every_n_traj_sample = int(num_traj_datapoints / num_keyframes)
    logger.debug(
        f"Keeping every {keep_every_n_traj_sample}th/nd/st sample in the"
        " trajectory data.")
    trajectory_data = trajectory_data[
        trajectory_start_i:trajectory_end_i:keep_every_n_traj_sample]
    trajectory = list(
        map(
            lambda i: pv.GetAnimationTrack(
                "Center", index=i, proxy=pv.FindSource(gui_name)),
            range(3),
        ))
    for i, track in enumerate(trajectory):
        keyframes = []
        for traj_sample in trajectory_data:
            key = pv.CompositeKeyFrame()
            key.KeyTime = normalized_time_from_scene(traj_sample[0])
            key.Interpolation = "Ramp"
            key.KeyValues = [traj_sample[i + 1]]
            keyframes.append(key)
        track.KeyFrames = keyframes
Exemplo n.º 6
0
Arquivo: axes.py Projeto: zoomvr/PVGeo
def setAxisLabelsFromBounds(name, num=(10, 10, 5)):
    """Sets the axis labels from a given input data source. Use the num argument
    to control the number of labels along each axis. If num is a scalar, then
    a uniform number of labels is used on each axis.

    Args:
        name (str): The string name of the input source on the data pipeline
        num (tuple(int) or int): the number of labels for each axis

    Example:
        >>> import pvmacros as pvm
        >>> pvm.vis.setAxisLabelsFromBounds('TableToPoints1', num=(5, 10, 2))

    """
    import paraview.simple as pvs
    import paraview.servermanager as sm
    import numpy as np
    # Get the input data
    src = pvs.FindSource(name)
    data = sm.Fetch(src)
    xmin, xmax, ymin, ymax, zmin, zmax = data.GetBounds()
    if not isinstance(num, (tuple, list)):
        num = list(num)
    # Cast as ints if needed
    for i, val in enumerate(num):
        if not isinstance(val, int):
            num[i] = int(val)
    # Calculate ranges for each axis
    xrng = np.linspace(xmin, xmax, num=num[0])
    yrng = np.linspace(ymin, ymax, num=num[1])
    zrng = np.linspace(zmin, zmax, num=num[2])

    # Set the axis labels
    customAxisTicks(xrng, axis=0, uniform=False)
    customAxisTicks(yrng, axis=1, uniform=False)
    customAxisTicks(zrng, axis=2, uniform=False)
    return
Exemplo n.º 7
0
 def updateEventCb(self, obj, event):
     name = self._getSourceToExtractName(obj)
     if not self.source:
         self.source = simple.FindSource(name)
     simple.SetActiveSource(self.source)
     if self.source and not self.rep:
         self.outline = simple.Outline(self.source)
         self.rep = simple.Show(self.source)
         self.outline.UpdatePipeline()
         self.outlineRep = simple.Show(self.outline)
         # TODO: this is for the demo
         # TODO: what would be the best way to change sources and representations from the client ?
         # create a protocol for liveInsituLink.GetInsituProxyManager() ?
         # or setActiveSource endpoint ?
         # or is there a better way ?
         info = self.source.GetPointDataInformation()
         if info.GetNumberOfArrays() > 0:
             arrName = info.GetArray(0).Name
             self.rep.ColorArrayName = ['POINTS', arrName]
             simple.ColorBy(self.rep, arrName)
         # Point gaussian
         props = simple.GetDisplayProperties(self.source)
         props.SetRepresentationType('Point Gaussian')
         props.GaussianRadius = 0.01
Exemplo n.º 8
0
def norm_slices_along_points(pointsNm,
                             dataNm,
                             numSlices=10,
                             exportpath='',
                             ext='.csv'):
    """
    This macro takes a series of points and a data source to be sliced. The
    points are used to construct a path through the data source and a slice is
    added at intervals of that path along the vector of that path at that point.
    This constructs `numSlices` slices through the dataset `dataNm`.

    Parameters
    ----------
    pointsNm : string
        The string name of the points source to construct the path.
    dataNm : string
        The string name of the data source to slice.
        Make sure this data source is slice-able.
    numSlices : int, optional
        The number of slices along the path.
    exportpath : string, optional
        The absolute file path of where to save each slice
    ext : string, optional
        The file extension for saving out the slices.
        Default to '.csv'

    Notes
    -----
    Make sure the input data source is slice-able.
    The SciPy module is required for this macro.

    """
    # import the simple module from the paraview and other needed libraries
    import paraview.simple as pvs
    import numpy as np
    from scipy.spatial import cKDTree
    from vtk.util import numpy_support as nps
    from vtk.numpy_interface import dataset_adapter as dsa

    # exportpath: Where to save data. Absolute path:

    # Specify Points for the Line Source:
    line = pvs.servermanager.Fetch(pvs.FindSource(pointsNm))

    # Specify data set to be sliced
    data = pvs.FindSource(dataNm)

    # get active view
    renderView = pvs.GetActiveViewOrCreate('RenderView')

    # Get the Points over the NumPy interface
    wpdi = dsa.WrapDataObject(line)  # NumPy wrapped points
    points = np.array(
        wpdi.Points)  # New NumPy array of points so we dont destroy input
    numPoints = line.GetNumberOfPoints()
    tree = cKDTree(points)
    dist, ptsi = tree.query(points[0], k=numPoints)

    # iterate of points in order (skips last point):
    num = 0
    for i in range(0, numPoints - 1, numPoints / numSlices):
        # get normal
        pts1 = points[ptsi[i]]
        pts2 = points[ptsi[i + 1]]
        x1, y1, z1 = pts1[0], pts1[1], pts1[2]
        x2, y2, z2 = pts2[0], pts2[1], pts2[2]
        norm = [x2 - x1, y2 - y1, z2 - z1]

        # create slice
        slc = pvs.Slice(Input=data)
        slc.SliceType = 'Plane'

        # set origin at points
        slc.SliceType.Origin = [x1, y1, z1]
        # set normal as vector from current point to next point
        slc.SliceType.Normal = norm

        if exportpath != '':
            # save out slice with good metadata: TODO: change name
            # This will use a value from the point data to add to the name
            #num = wpdi.PointData['Advance LL (S-558)'][ptsi[i]]
            filename = path + 'Slice_%d%s' % (num, ext)
            print(filename)
            pvs.SaveData(filename, proxy=slc)

        num += 1
        pvs.Show(slc, renderView)

    pvs.RenderAllViews()
    pvs.ResetCamera()
Exemplo n.º 9
0
def start_cue(self):
	""" function called at the beginning of the animation """
	self.image_index = 0	# image index

	# setup view parameters
	view = smp.GetActiveView()
	view.CameraParallelProjection = CameraParallelProjection
	view.Background = Background
	view.Background2 = Background2
	view.UseGradientBackground = UseGradientBackground
	view.CameraViewAngle = CameraViewAngle

	# setup initial opacity
	frames = smp.FindSource(pointclouds_name)
	self.frames_repr = smp.Show(frames)
	self.frames_repr.Opacity = opacity

	# get trajectory positions and orientations
	trajectory = smp.FindSource(trajectory_name)
	traj = trajectory.GetClientSideObject().GetOutput()
	self.pts = numpy_support.vtk_to_numpy(traj.GetPoints().GetData()).copy()

	# convert veloview axis angle to scipy Rotation
	orientations_data = traj.GetPointData().GetArray("Orientation(AxisAngle)")
	orientations = numpy_support.vtk_to_numpy(orientations_data).copy()
	axis = orientations[:, :3]
	angles = orientations[:, 3].reshape((-1, 1))
	axis_angles = axis * angles
	self.orientations = [Rotation.from_rotvec(a) for a in axis_angles]


	# get the 3D model
	self.model = None
	if len(cad_model_name) > 0:
		self.model = smp.FindSource(cad_model_name)


	# get all available timesteps and find the index corresponding to the start time
	time = view.ViewTime
	source_frames = smp.FindSource(temporal_source_name)
	timesteps = list(source_frames.TimestepValues)
	self.i = np.argmin(np.abs(np.asarray(timesteps) - time))
	print "Start timestep: ", self.i



# -----------------------------TO MODIFY--------------------------------------
	# Camera path definition (need to be specified)
	# This is an example, you can define your custom camera path
	c1 = FirstPersonView(self.i, self.i+40, focal_point=[0, 0, 1])

	c2 = FixedPositionView(self.i+40, self.i+100)
	c2.set_transition(c1, 5, "s-shape")		# transition from c1

	c3 = AbsoluteOrbit(self.i+100, self.i+200,
						center=[99.65169060331509, 35.559305816556, 37.233268868598536],
						up_vector=[0, 0, 1.0],
						initial_pos = [85.65169060331509, 35.559305816556, 37.233268868598536],
						focal_point=[99.65169060331509, 35.559305816556, 7.233268868598536])
	c3.set_transition(c2, 20, "s-shape")

	c4 = ThirdPersonView(self.i+200, self.i+280)
	c4.set_transition(c3, 20, "s-shape")

	c5 = RelativeOrbit(self.i+280, self.i+350, up_vector=[0, 0, 1.0], initial_pos = [0.0, -10, 10])
	c5.set_transition(c4, 20, "square")

	self.cameras = [c1, c2, c3, c4, c5]
Exemplo n.º 10
0
def manySlicesAlongAxis(dataNm, rng, axis=0, exportpath='', ext='.csv'):
    """
    Description
    -----------


    Parameters
    ----------
    `dataNm` : string
    - The string name of the data source to slice.
    - Make sure this data source is slice-able.

    `numSlices` : int, optional
    - The number of slices along the path.

    `exportpath` : string, optional
    - The absolute file path of where to save each slice

    `ext` : string, optional
    - The file extension for saving out the slices.
    - Default to '.csv'


    Notes
    -----
    - Make sure the input data source is slice-able.
    - The SciPy module is required for this macro.

    """

    # exportpath: Where to save data. Absolute path:
    if axis not in (0, 1, 2):
        raise Exception('Axis choice must be 0, 1, or 2 (x, y, or z)')

    # Specify data set to be sliced
    data = pvs.FindSource(dataNm)

    # get active view
    renderView = pvs.GetActiveViewOrCreate('RenderView')

    def getNorm():
        norm = [0, 0, 0]
        norm[axis] = 1
        return norm

    def updateOrigin(og, i):
        og[axis] = rng[i]
        return og

    norm = getNorm()

    num = 0
    inputs = []
    for i in range(len(rng)):
        # create slice
        slc = pvs.Slice(Input=data)
        slc.SliceType = 'Plane'

        # set origin at points
        og = slc.SliceType.Origin
        og = updateOrigin(og, i)
        # set normal as vector from current point to next point
        slc.SliceType.Normal = norm

        if exportpath != '':
            # save out slice with good metadata: TODO: change name
            # This will use a value from the point data to add to the name
            #num = wpdi.PointData['Advance LL (S-558)'][ptsi[i]]
            filename = path + 'Slice_%d%s' % (num, ext)
            print(filename)
            pvs.SaveData(filename, proxy=slc)

        num += 1
        inputs.append(slc)
        #pvs.Show(slc, renderView)

    # Now append all slices into once source for easy management
    app = pvs.AppendDatasets(Input=inputs)
    pvs.RenameSource('%s-Slices' % dataNm, app)
    pvs.Show(app, renderView)
    pvs.RenderAllViews()
    pvs.ResetCamera()
    return app