Example O3: Highlight a particle¶

from ovito.vis import ParticlesVis
from PySide2.QtCore import *
from PySide2.QtGui import *

def render(args):

# Get output data collection of first scene pipeline.
data = args.scene.pipelines[0].compute(args.frame)
positions = data.particles.positions
pindex = 0 # The index of the particle to be highlighted

# Project center point of particle.
xy = args.project_point(positions[pindex])
if xy is None: return

# Determine display radius of the particle.
if radius <= 0 and data.particles.particle_types is not None:
particle_type = data.particles.particle_types[pindex]

# Calculate screen-space size of the particle in pixels.

# Draw a dashed circle around the particle.
pen = QPen(Qt.DashLine)
pen.setWidth(3)
pen.setColor(QColor(0,0,255))
args.painter.setPen(pen)

# Draw an arrow pointing at the particle.
arrow_shape = QPolygonF()
arrow_shape.append(QPointF(0,0))
arrow_shape.append(QPointF(10,10))
arrow_shape.append(QPointF(10,5))
arrow_shape.append(QPointF(40,5))
arrow_shape.append(QPointF(40,-5))
arrow_shape.append(QPointF(10,-5))
arrow_shape.append(QPointF(10,-10))
args.painter.setPen(QPen())
args.painter.setBrush(QBrush(QColor(255,0,0)))
args.painter.translate(QPointF(xy[0], xy[1]))
args.painter.rotate(-45.0)