def getVTKArc(pStart,pCenter,pEnd,res=32): """Returns VTK arc object defined through 3 points. Args: pStart (numpy.ndarray): Coordinate of start point. pCenter (numpy.ndarray): Coordinate of center point. pEnd (numpy.ndarray): Coordinate of end point. Keyword Args: res (int): Resolution of arc. Returns: vtk.vtkActor: VTK actor. """ arc = vtk.vtkArcSource() arc.SetCenter( pCenter[0], pCenter[1], pCenter[2] ) arc.SetPoint1( pStart[0], pStart[1], pStart[2] ) arc.SetPoint2( pEnd[0], pEnd[1], pEnd[2] ) arc.SetResolution( res ) return arc
def DrawArc(self): d1 = math.sqrt( vtk.vtkMath.Distance2BetweenPoints(self.points[0], self.points[1])) d2 = math.sqrt( vtk.vtkMath.Distance2BetweenPoints(self.points[2], self.points[1])) if d1 < d2: d = d1 p1 = self.points[0] a, b, c = [j - i for i, j in zip(self.points[1], self.points[2])] else: d = d2 p1 = self.points[2] a, b, c = [j - i for i, j in zip(self.points[1], self.points[0])] t = (d / math.sqrt(a**2 + b**2 + c**2)) x = self.points[1][0] + a * t y = self.points[1][1] + b * t z = self.points[1][2] + c * t p2 = (x, y, z) arc = vtk.vtkArcSource() arc.SetPoint1(p1) arc.SetPoint2(p2) arc.SetCenter(self.points[1]) arc.SetResolution(20) return arc
def DrawArc(self): d1 = math.sqrt(vtk.vtkMath.Distance2BetweenPoints(self.points[0], self.points[1])) d2 = math.sqrt(vtk.vtkMath.Distance2BetweenPoints(self.points[2], self.points[1])) if d1 < d2: d = d1 p1 = self.points[0] a,b,c = [j-i for i,j in zip(self.points[1], self.points[2])] else: d = d2 p1 = self.points[2] a,b,c = [j-i for i,j in zip(self.points[1], self.points[0])] t = (d / math.sqrt(a**2 + b**2 + c**2)) x = self.points[1][0] + a*t y = self.points[1][1] + b*t z = self.points[1][2] + c*t p2 = (x, y, z) arc = vtk.vtkArcSource() arc.SetPoint1(p1) arc.SetPoint2(p2) arc.SetCenter(self.points[1]) arc.SetResolution(20) return arc
def drawCurve(myscreen, curve, z): vertices = curve.getVertices() current = vertices[0].p #print "start at (%.2f, %.2f) z=%.2f" % (current.x, current.y, z) for v in vertices[1:]: if v.type == 0: #print "line to (%.2f,%.2f) z=%.2f" % (v.p.x, v.p.y, z) myscreen.addActor(camvtk.Line(p1=(current.x, current.y, z), p2 = (v.p.x, v.p.y, z))) else: r = math.hypot(v.p.x-v.c.x, v.p.y-v.c.y) #print "arc to (%.2f,%.2f) center=(%.2f,%.2f) r=%.2f z=%.2f" % (v.p.x, v.p.y, v.c.x, v.c.y, r, z) src = vtk.vtkArcSource() src.SetCenter(v.c.x, v.c.y, z) src.SetPoint1(current.x, current.y, z) src.SetPoint2(v.p.x, v.p.y, z) src.SetResolution(20) src.SetNegative(not IsNegative(current, v)) mapper = vtk.vtkPolyDataMapper() mapper.SetInput(src.GetOutput()) actor = camvtk.CamvtkActor() actor.SetMapper(mapper) myscreen.addActor(actor) current = v.p
def getVTKArc(pStart, pCenter, pEnd, res=32): """Returns VTK arc object defined through 3 points. Args: pStart (numpy.ndarray): Coordinate of start point. pCenter (numpy.ndarray): Coordinate of center point. pEnd (numpy.ndarray): Coordinate of end point. Keyword Args: res (int): Resolution of arc. Returns: vtk.vtkActor: VTK actor. """ arc = vtk.vtkArcSource() arc.SetCenter(pCenter[0], pCenter[1], pCenter[2]) arc.SetPoint1(pStart[0], pStart[1], pStart[2]) arc.SetPoint2(pEnd[0], pEnd[1], pEnd[2]) arc.SetResolution(res) return arc
def CircularArc(pointa, pointb, center, resolution=100, normal=None, polar=None, angle=None, negative=False): """Create a circular arc defined by two endpoints and a center. The number of segments composing the polyline is controlled by setting the object resolution. Alternatively, one can use a better API (that does not allow for inconsistent nor ambiguous inputs), using a starting point (polar vector, measured from the arc's center), a normal to the plane of the arc, and an angle defining the arc length. Parameters ---------- pointa : np.ndarray or list Position of the first end point. pointb : np.ndarray or list Position of the other end point. center : np.ndarray or list Center of the circle that defines the arc. resolution : int, optional The number of segments of the polyline that draws the arc. Resolution of 1 will just create a line. normal : np.ndarray or list The normal vector to the plane of the arc. By default it points in the positive Z direction. polar : np.ndarray or list (starting point of the arc). By default it is the unit vector in the positive x direction. Note: This is only used when normal has been input. angle : float Arc length (in degrees), beginning at the polar vector. The direction is counterclockwise by default; a negative value draws the arc in the clockwise direction. Note: This is only used when normal has been input. negative : bool, optional By default the arc spans the shortest angular sector point1 and point2. By setting this to true, the longest angular sector is used instead (i.e. the negative coterminal angle to the shortest one). This is only used when normal has not been input Examples -------- Quarter arc centered at the origin in the xy plane >>> import pyvista >>> arc = pyvista.CircularArc([-1, 0, 0], [0, 1, 0], [0, 0, 0]) >>> pl = pyvista.Plotter() >>> _ = pl.add_mesh(arc, color='k', line_width=4) >>> _ = pl.show_bounds(location='all') >>> _ = pl.view_xy() >>> pl.show() # doctest:+SKIP Quarter arc centered at the origin in the xz plane >>> arc = pyvista.CircularArc([-1, 0, 0], [1, 0, 0], [0, 0, 0], normal=[0, 0, 1]) >>> arc.plot() # doctest:+SKIP """ check_valid_vector(pointa, 'pointa') check_valid_vector(pointb, 'pointb') check_valid_vector(center, 'center') # fix half-arc bug: if a half arc travels directly through the # center point, it becomes a line pointb = list(pointb) pointb[0] -= 1E-10 pointb[1] -= 1E-10 arc = vtk.vtkArcSource() arc.SetPoint1(*pointa) arc.SetPoint2(*pointb) arc.SetCenter(*center) arc.SetResolution(resolution) arc.SetNegative(negative) if normal is not None: arc.UseNormalAndAngleOn() check_valid_vector(normal, 'normal') arc.SetNormal(*normal) if polar is not None: check_valid_vector(polar, 'polar') arc.SetPolarVector(*polar) if angle is not None: arc.SetAngle(angle) arc.Update() return pyvista.wrap(arc.GetOutput())
def CreateOutline9076(color=(255, 99, 71), depth=80.0): """ Create outline for the 9076 probe. The outline is contained in the XZ-plane """ # Avoid multiple generations if CreateOutline9076.output is not None and CreateOutline9076.depth == depth: print("reused outline") return CreateOutline9076.output nElements = 144 pitch = 0.2101 roc = 50.006 height = 5.0 azR = roc azArcLength = pitch * (nElements - 1.0) azSegment = azArcLength / azR dAz = azSegment / (nElements - 1.0) az = dAz * (np.r_[0:nElements] - 0.5 * (nElements - 1.0)) az0 = az[0] - 0.5 * dAz azN = az[nElements - 1] + 0.5 * dAz # Create first arc arc0 = vtk.vtkArcSource() arc0.SetCenter(0, 0, -azR) arc0.SetPoint1(azR * np.sin(az0), 0, azR * np.cos(az0) - azR) arc0.SetPoint2(azR * np.sin(azN), 0, azR * np.cos(azN) - azR) arc0.SetResolution(10) arc0.Update() arcData0 = arc0.GetOutput() # Create second arc arc1 = vtk.vtkArcSource() arc1.SetCenter(0, 0, -azR) arc1.SetPoint1((azR + depth) * np.sin(azN), 0, (azR + depth) * np.cos(azN) - azR) arc1.SetPoint2((azR + depth) * np.sin(az0), 0, (azR + depth) * np.cos(az0) - azR) arc1.SetResolution(10) arc1.Update() arcData1 = arc1.GetOutput() # Resulting poly data linesPolyData = vtk.vtkPolyData() lines = vtk.vtkCellArray() points = vtk.vtkPoints() if (0): # Old way # Iterate through points and and create new lines arcData0.GetLines().InitTraversal() idList = vtk.vtkIdList() while arcData0.GetLines().GetNextCell(idList): pointId = idList.GetId(0) points.InsertNextPoint(arcData0.GetPoint(pointId)) for i in range(1, idList.GetNumberOfIds()): pointId = idList.GetId(i) points.InsertNextPoint(arcData0.GetPoint(pointId)) line = vtk.vtkLine() line.GetPointIds().SetId(0, i - 1) line.GetPointIds().SetId(1, i) lines.InsertNextCell(line) arcData1.GetLines().InitTraversal() idList = vtk.vtkIdList() while arcData1.GetLines().GetNextCell(idList): pointId = idList.GetId(0) points.InsertNextPoint(arcData1.GetPoint(pointId)) for j in range(1, idList.GetNumberOfIds()): pointId = idList.GetId(j) points.InsertNextPoint(arcData1.GetPoint(pointId)) line = vtk.vtkLine() line.GetPointIds().SetId(0, i + j - 1) line.GetPointIds().SetId(1, i + j) lines.InsertNextCell(line) # Insert two extra lines joining the two arcs line = vtk.vtkLine() line.GetPointIds().SetId(0, i + j) line.GetPointIds().SetId(1, 0) lines.InsertNextCell(line) line = vtk.vtkLine() line.GetPointIds().SetId(0, i) line.GetPointIds().SetId(1, i + 1) lines.InsertNextCell(line) else: # Iterate through points and and create new lines arcData0.GetLines().InitTraversal() idList = vtk.vtkIdList() while arcData0.GetLines().GetNextCell(idList): pointId = idList.GetId(0) points.InsertNextPoint(arcData0.GetPoint(pointId)) for i in range(1, idList.GetNumberOfIds()): pointId = idList.GetId(i) points.InsertNextPoint(arcData0.GetPoint(pointId)) line = vtk.vtkLine() line.GetPointIds().SetId(0, i - 1) line.GetPointIds().SetId(1, i) # last i value is 10=resolution lines.InsertNextCell(line) # i = resolution arcData1.GetLines().InitTraversal() idList = vtk.vtkIdList() while arcData1.GetLines().GetNextCell(idList): pointId = idList.GetId(0) points.InsertNextPoint(arcData1.GetPoint(pointId)) # Line from 1st arc to second arc line = vtk.vtkLine() line.GetPointIds().SetId(0, i) j = 0 line.GetPointIds().SetId(1, i + 1 + j) lines.InsertNextCell(line) for j in range(1, idList.GetNumberOfIds()): pointId = idList.GetId(j) points.InsertNextPoint(arcData1.GetPoint(pointId)) line = vtk.vtkLine() line.GetPointIds().SetId(0, i + j - 1 + 1) line.GetPointIds().SetId(1, i + j + 1) lines.InsertNextCell(line) # Insert one extra line joining the two arcs line = vtk.vtkLine() line.GetPointIds().SetId(0, i + j + 1) line.GetPointIds().SetId(1, 0) lines.InsertNextCell(line) linesPolyData.SetPoints(points) linesPolyData.SetLines(lines) # Create polyline(s) from line segments. There will be # two due to the the ordering cutStrips = vtk.vtkStripper() cutStrips.SetInputData(linesPolyData) cutStrips.Update() outline = cutStrips.GetOutput() # Color the lines colors = vtk.vtkUnsignedCharArray() colors.SetNumberOfComponents(3) for i in range(outline.GetNumberOfCells()): colors.InsertNextTypedTuple(color) outline.GetCellData().SetScalars(colors) CreateOutline9076.depth = depth CreateOutline9076.output = outline return CreateOutline9076.output
def CreateOutline9076(color=(255, 99, 71), depth=80.0): """ Create outline for the 9076 probe. The outline is contained in the XZ-plane """ # Default color for the outline is "Tomato" nElements = 144 pitch = 0.2101 roc = 50.006 height = 5.0 azR = roc azArcLength = pitch * (nElements - 1.0) azSegment = azArcLength / azR dAz = azSegment / (nElements - 1.0) az = dAz * (np.r_[0:nElements] - 0.5 * (nElements - 1.0)) az0 = az[0] - 0.5 * dAz azN = az[nElements - 1] + 0.5 * dAz appendFilter = vtk.vtkAppendPolyData() # Create first arc arc0 = vtk.vtkArcSource() arc0.SetCenter(0, 0, -azR) arc0.SetPoint1(azR * np.sin(az0), 0, azR * np.cos(az0) - azR) arc0.SetPoint2(azR * np.sin(azN), 0, azR * np.cos(azN) - azR) arc0.SetResolution(10) arc0.Update() appendFilter.AddInputData(arc0.GetOutput()) appendFilter.Update() arc1 = vtk.vtkArcSource() arc1.SetCenter(0, 0, -azR) arc1.SetPoint1((azR + depth) * np.sin(az0), 0, (azR + depth) * np.cos(az0) - azR) arc1.SetPoint2((azR + depth) * np.sin(azN), 0, (azR + depth) * np.cos(azN) - azR) arc1.SetResolution(10) arc1.Update() appendFilter.AddInputData(arc1.GetOutput()) appendFilter.Update() # Create lines linesPolyData = vtk.vtkPolyData() pts = vtk.vtkPoints() pts.InsertNextPoint((azR * np.sin(az0), 0, azR * np.cos(az0) - azR)) pts.InsertNextPoint( ((azR + depth) * np.sin(az0), 0, (azR + depth) * np.cos(az0) - azR)) pts.InsertNextPoint((azR * np.sin(azN), 0, azR * np.cos(azN) - azR)) pts.InsertNextPoint( ((azR + depth) * np.sin(azN), 0, (azR + depth) * np.cos(azN) - azR)) linesPolyData.SetPoints(pts) line0 = vtk.vtkLine() line0.GetPointIds().SetId(0, 0) line0.GetPointIds().SetId(1, 1) line1 = vtk.vtkLine() line1.GetPointIds().SetId(0, 2) line1.GetPointIds().SetId(1, 3) # Create a vtkCellArray container and store the lines in it lines = vtk.vtkCellArray() lines.InsertNextCell(line0) lines.InsertNextCell(line1) linesPolyData.SetLines(lines) appendFilter.AddInputData(linesPolyData) appendFilter.Update() outline = appendFilter.GetOutput() colors = vtk.vtkUnsignedCharArray() colors.SetNumberOfComponents(3) for i in range(outline.GetNumberOfCells()): colors.InsertNextTypedTuple(color) outline.GetCellData().SetScalars(colors) return outline
azR = roc azArcLength = pitch * (nElements - 1.0) azSegment = azArcLength / azR dAz = azSegment / (nElements - 1.0) az = dAz * (np.r_[0:nElements] - 0.5*(nElements - 1.0)) az0 = az[0] - 0.5*dAz azN = az[nElements-1] + 0.5*dAz namedColors = vtk.vtkNamedColors() appendFilter = vtk.vtkAppendPolyData() # Create 2 arcs arc0 = vtk.vtkArcSource() arc0.SetCenter(0, 0, -azR) arc0.SetPoint1(azR*np.sin(az0), 0, azR*np.cos(az0) - azR) arc0.SetPoint2(azR*np.sin(azN), 0, azR*np.cos(azN) - azR) arc0.SetResolution( 10 ) arc0.Update() appendFilter.AddInputData(arc0.GetOutput()) appendFilter.Update() arc1 = vtk.vtkArcSource() arc1.SetCenter(0, 0, -azR) arc1.SetPoint1((azR+depth)*np.sin(az0), 0, (azR+depth)*np.cos(az0) - azR) arc1.SetPoint2((azR+depth)*np.sin(azN), 0, (azR+depth)*np.cos(azN) - azR) arc1.SetResolution( 10 ) arc1.Update()