def __init__(self, layer_dist=1.115, number_of_cells_per_side_=1, surface_density=0.1, unit_cell_size_=300): molar.pdb.Pdb.__init__(self) self.layer_dist = layer_dist self.step_num = int(32) self.marching_cubes = vtk.vtkMarchingCubes() self.poly_data = vtk.vtkPolyData() self.data = vtk.vtkDataObject() self.unit_cell_size = unit_cell_size_ self.form = "G" self.number_of_cells_per_side = number_of_cells_per_side_ self.cerebroside = False self.Update() self.units = [] self.units_transed = [] self.points = vtk.vtkPoints() #for visualization self.surf_dens = surface_density self.total_area = 0 self.total_pair = 0 for f in FILES: self.units.append(molar.pdb.Pdb()) self.units[-1].ReadFile(PATH + f) for f in FILES: self.units_transed.append(molar.pdb.Pdb()) self.units_transed[-1].ReadFile(PATH + f) self.units_transed[-1].RotateX(180) self.units[-1].BringToNegativeY()
def __init__(self, number_of_cells_per_side_=1, unit_cell_size_=200): molar.pdb.Pdb.__init__(self) self.surface_density = SURFACE_DENSITY self.step_num = int(32) self.marching_cubes = vtk.vtkMarchingCubes() self.poly_data = vtk.vtkPolyData() self.data = vtk.vtkDataObject() self.unit_cell_size = unit_cell_size_ self.form = "G" self.number_of_cells_per_side = number_of_cells_per_side_ self.cerebroside = False self.Update() self.units = [] self.units_transed = [] self.points = vtk.vtkPoints() #for visualization self.attempt = 0 self.collisioncounter = 0 self.total_area = 0 self.total_pair = 0 for f in FILES: self.units.append(molar.pdb.Pdb()) self.units[-1].ReadFile(PATH + f) for f in FILES: self.units_transed.append(molar.pdb.Pdb()) self.units_transed[-1].ReadFile(PATH + f) self.units_transed[-1].RotateX(180) self.pointlocator = vtk.vtkPointLocator() self.pointlocator.Initialize() self.pointlocator.SetDataSet(vtk.vtkPolyData()) self.pointlocator.InitPointInsertion( vtk.vtkPoints(), [0, unit_cell_size_, 0, unit_cell_size_, 0, unit_cell_size_])
def xyplot(points, title='', c='b', corner=1, lines=False): """ Return a vtkActor that is a plot of 2D points in x and y. Use corner to assign its position: 1=topleft, 2=topright, 3=bottomleft, 4=bottomright. """ c = vc.getColor(c) # allow different codings array_x = vtk.vtkFloatArray() array_y = vtk.vtkFloatArray() array_x.SetNumberOfTuples(len(points)) array_y.SetNumberOfTuples(len(points)) for i, p in enumerate(points): array_x.InsertValue(i, p[0]) array_y.InsertValue(i, p[1]) field = vtk.vtkFieldData() field.AddArray(array_x) field.AddArray(array_y) data = vtk.vtkDataObject() data.SetFieldData(field) plot = vtk.vtkXYPlotActor() plot.AddDataObjectInput(data) plot.SetDataObjectXComponent(0, 0) plot.SetDataObjectYComponent(0, 1) plot.SetXValuesToValue() plot.SetXTitle(title) plot.SetYTitle('') plot.ExchangeAxesOff() plot.PlotPointsOn() if not lines: plot.PlotLinesOff() plot.GetProperty().SetPointSize(5) plot.GetProperty().SetLineWidth(2) plot.SetNumberOfXLabels(3) #not working plot.GetProperty().SetColor(0, 0, 0) plot.GetProperty().SetOpacity(0.7) plot.SetPlotColor(0, c[0], c[1], c[2]) tprop = plot.GetAxisLabelTextProperty() tprop.SetColor(0, 0, 0) tprop.SetOpacity(0.7) tprop.SetFontFamily(0) tprop.BoldOff() tprop.ItalicOff() tprop.ShadowOff() tprop.SetFontSize(3) #not working plot.SetAxisTitleTextProperty(tprop) plot.SetAxisLabelTextProperty(tprop) plot.SetTitleTextProperty(tprop) if corner == 1: plot.GetPositionCoordinate().SetValue(.0, .8, 0) if corner == 2: plot.GetPositionCoordinate().SetValue(.7, .8, 0) if corner == 3: plot.GetPositionCoordinate().SetValue(.0, .0, 0) if corner == 4: plot.GetPositionCoordinate().SetValue(.7, .0, 0) plot.GetPosition2Coordinate().SetValue(.3, .2, 0) return plot
def GetSample(obj, ev): # Get the observed plane and bind it planeX = GetSample.planeX imageActor2.SetInputData(planeX.GetResliceOutput()) ren2.AddActor(imageActor2) renWin.AddRenderer(ren2) # Set the number of scalar components to 3, # otherwise vtkImageAccumulate can't process it. # planeX.GetResliceOutput().AllocateScalars(vtk.VTK_INT, 3) # Set the input data for histogram histogram.SetInputData(planeX.GetResliceOutput()) histogram.Update() # Construct an array to store the histogram red = [1, 0, 0] frequencies = vtk.vtkIntArray() frequencies.SetNumberOfComponents(1) frequencies.SetNumberOfTuples(256) o = histogram.GetOutput() output = o.GetPointData().GetScalars() j = 0 while j < 256: frequencies.SetTuple1(j, output.GetValue(j)) j = j + 1 # Convert the array to vtkDataObject dataObject = vtk.vtkDataObject() dataObject.GetFieldData().AddArray(frequencies) # Create a barChart to display the histogram barChart = vtk.vtkBarChartActor() barChart.SetInput(dataObject) barChart.SetTitle("Histogram") barChart.GetPositionCoordinate().SetValue(0.05, 0.05, 0.0) barChart.GetPosition2Coordinate().SetValue(0.95, 0.85, 0.0) barChart.GetProperty().SetColor(1, 1, 1) barChart.GetLegendActor().SetNumberOfEntries( dataObject.GetFieldData().GetArray(0).GetNumberOfTuples()) barChart.LegendVisibilityOff() barChart.LabelVisibilityOff() count = 0 while count < 256: barChart.SetBarColor(count, red) count += 1 # Visualize the histogram ren3 = vtk.vtkRenderer() ren3.SetViewport(0.5, 0, 1.0, 0.5) ren3.AddActor(barChart) renWin.AddRenderer(ren3)
def plotHistogram(self, renderer): barChart = vtk.vtkBarChartActor() dataObject = vtk.vtkDataObject() dataObject.GetFieldData().AddArray(self.FreqArray) for i in range(0, self.BinsCount): barChart.SetBarLabel(i, "{0:.2f}".format(self.getBinCenter(i))) barChart.SetInput(dataObject) barChart.GetLegendActor().SetNumberOfEntries(dataObject.GetFieldData().GetArray(0).GetNumberOfTuples()) barChart.LegendVisibilityOff() barChart.LabelVisibilityOn() barChart.GetProperty().SetColor(1, 1, 1) renderer.AddActor(barChart)
def plot(values): # convert data from python list of tuples => vtkFieldData xCoords = vtk.vtkFloatArray() yCoords = vtk.vtkFloatArray() xCoords.SetNumberOfTuples(len(values)) yCoords.SetNumberOfTuples(len(values)) for i, v in enumerate(values): xCoords.SetTuple1(i, v[0]) yCoords.SetTuple1(i, v[1]) curve = vtk.vtkFieldData() curve.AddArray(xCoords) curve.AddArray(yCoords) # create vtkDataObject plot = vtk.vtkDataObject() plot.SetFieldData(curve) # build a vtkXYPlotActor xyplot = vtk.vtkXYPlotActor() xyplot.AddDataObjectInput(plot) #xyplot.SetDataObjectPlotModeToRows() xyplot.SetDataObjectXComponent(0, 0) xyplot.SetDataObjectYComponent(0, 1) xyplot.GetPositionCoordinate().SetValue(0, 0.0, 0) xyplot.GetPosition2Coordinate().SetValue(1, 1, 0) xyplot.PlotPointsOn() xyplot.PlotLinesOn() xyplot.GetProperty().SetPointSize(5) #xyplot.SetXRange(0, 100) #xyplot.SetYRange(0, 20) xyplot.SetPlotColor(0, 1, 1, 0) # setup renderer / window / interactor ren = vtk.vtkRenderer() ren.SetBackground(0.1, 0.2, 0.4) ren.AddActor2D(xyplot) renWin = vtk.vtkRenderWindow() renWin.SetSize(1000, 800) renWin.AddRenderer(ren) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) renWin.Render() iren.Start()
def sliceDown(self): # Warp using the normals warp = vtk.vtkWarpVector() warp.SetInputData(fixMesh(downsample(self.currentPeel))) # fixMesh here updates normals needed for warping warp.SetInputArrayToProcess(0, 0, 0, vtk.vtkDataObject().FIELD_ASSOCIATION_POINTS, vtk.vtkDataSetAttributes().NORMALS) warp.SetScaleFactor(-1) warp.Update() out = vtk.vtkPolyData() out = upsample(warp.GetPolyDataOutput()) out = smooth(out) out = fixMesh(out) out = cleanMesh(out) self.currentPeel = out
# put the data into the data arrays for i in range(len(x)): _xData.SetTuple1(i,x[i]) _yData.SetTuple1(i,y[i]) # create a field data object # (I think this is as a containter to hold the data arrays) _fieldData = vtk.vtkFieldData() _fieldData.AllocateArrays(2) _fieldData.AddArray(_xData) _fieldData.AddArray(_yData) # now put the field data object into a data object so that can add it as # input to the xyPlotActor _dataObject = vtk.vtkDataObject() _dataObject.SetFieldData(_fieldData) # set up the actor _plot = vtk.vtkXYPlotActor() _plot.AddDataObjectInput(_dataObject) # set the title and stuff _plot.SetTitle("Example 2D plot") _plot.SetXTitle("x") _plot.SetYTitle("x^2") _plot.SetXValuesToValue() # set which parts of the data object are to be used for which axis _plot.SetDataObjectXComponent(0,0) _plot.SetDataObjectYComponent(0,1)
_fieldData4.AddArray(_xData) _fieldData4.AddArray(_yData4) _fieldData5 = vtk.vtkFieldData() _fieldData5.AllocateArrays(2) _fieldData5.AddArray(_xData) _fieldData5.AddArray(_yData5) _fieldData6 = vtk.vtkFieldData() _fieldData6.AllocateArrays(2) _fieldData6.AddArray(_xData) _fieldData6.AddArray(_yData6) # now put the field data object into a data object so that can add it as # input to the xyPlotActor _dataObject1 = vtk.vtkDataObject() _dataObject1.SetFieldData(_fieldData1) _dataObject2 = vtk.vtkDataObject() _dataObject2.SetFieldData(_fieldData2) _dataObject3 = vtk.vtkDataObject() _dataObject3.SetFieldData(_fieldData3) _dataObject4 = vtk.vtkDataObject() _dataObject4.SetFieldData(_fieldData4) _dataObject5 = vtk.vtkDataObject() _dataObject5.SetFieldData(_fieldData5) _dataObject6 = vtk.vtkDataObject()
_fieldData1.AddArray(_xData) _fieldData1.AddArray(_yData1) _fieldData2 = vtk.vtkFieldData() _fieldData2.AllocateArrays(2) _fieldData2.AddArray(_xData) _fieldData2.AddArray(_yData2) _fieldData3 = vtk.vtkFieldData() _fieldData3.AllocateArrays(2) _fieldData3.AddArray(_xData) _fieldData3.AddArray(_yData3) # now put the field data object into a data object so that can add it as # input to the xyPlotActor _dataObject1 = vtk.vtkDataObject() _dataObject1.SetFieldData(_fieldData1) _dataObject2 = vtk.vtkDataObject() _dataObject2.SetFieldData(_fieldData2) _dataObject3 = vtk.vtkDataObject() _dataObject3.SetFieldData(_fieldData3) # set up the actor _plot = vtk.vtkXYPlotActor() _plot.AddDataObjectInput(_dataObject1) _plot.AddDataObjectInput(_dataObject2) _plot.AddDataObjectInput(_dataObject3) # the size of the actor should be 80% of the render window
def main(): colors = vtk.vtkNamedColors() numTuples = 12 bitter = vtk.vtkFloatArray() bitter.SetNumberOfTuples(numTuples) crispy = vtk.vtkFloatArray() crispy.SetNumberOfTuples(numTuples) crunchy = vtk.vtkFloatArray() crunchy.SetNumberOfTuples(numTuples) salty = vtk.vtkFloatArray() salty.SetNumberOfTuples(numTuples) oily = vtk.vtkFloatArray() oily.SetNumberOfTuples(numTuples) rand_seq = vtk.vtkMinimalStandardRandomSequence() rand_seq.SetSeed(8775070) for i in range(numTuples): bitter.SetTuple1(i, rand_seq.GetRangeValue(1, 10)) rand_seq.Next() crispy.SetTuple1(i, rand_seq.GetRangeValue(-1, 1)) rand_seq.Next() crunchy.SetTuple1(i, rand_seq.GetRangeValue(1, 100)) rand_seq.Next() salty.SetTuple1(i, rand_seq.GetRangeValue(0, 10)) rand_seq.Next() oily.SetTuple1(i, rand_seq.GetRangeValue(5, 25)) rand_seq.Next() dobj = vtk.vtkDataObject() dobj.GetFieldData().AddArray(bitter) dobj.GetFieldData().AddArray(crispy) dobj.GetFieldData().AddArray(crunchy) dobj.GetFieldData().AddArray(salty) dobj.GetFieldData().AddArray(oily) actor = vtk.vtkSpiderPlotActor() actor.SetInputData(dobj) actor.SetTitle("Spider Plot") actor.SetIndependentVariablesToColumns() actor.GetPositionCoordinate().SetValue(0.05, 0.1, 0.0) actor.GetPosition2Coordinate().SetValue(0.95, 0.85, 0.0) actor.GetProperty().SetColor(colors.GetColor3d('Red')) actor.SetAxisLabel(0, "Bitter") actor.SetAxisRange(0, 1, 10) actor.SetAxisLabel(1, "Crispy") actor.SetAxisRange(1, -1, 1) actor.SetAxisLabel(2, "Crunchy") actor.SetAxisRange(2, 1, 100) actor.SetAxisLabel(3, "Salty") actor.SetAxisRange(3, 0, 10) actor.SetAxisLabel(4, "Oily") actor.SetAxisRange(4, 5, 25) actor.GetLegendActor().SetNumberOfEntries(numTuples) for i in range(numTuples): r = rand_seq.GetRangeValue(0.4, 1.0) rand_seq.Next() g = rand_seq.GetRangeValue(0.4, 1.0) rand_seq.Next() b = rand_seq.GetRangeValue(0.4, 1.0) rand_seq.Next() actor.SetPlotColor(i, r, g, b) actor.LegendVisibilityOn() actor.GetTitleTextProperty().SetColor(colors.GetColor3d('MistyRose')) actor.GetLabelTextProperty().SetColor(colors.GetColor3d('MistyRose')) ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) ren1.AddActor(actor) ren1.SetBackground(colors.GetColor3d('DarkSlateGray')) renWin.SetSize(600, 500) renWin.SetWindowName('SpiderPlot') iren.Initialize() renWin.Render() iren.Start()
def cornerPlot(points, pos=1, s=0.2, title="", c="b", bg="k", lines=True): """ Return a ``vtkXYPlotActor`` that is a plot of `x` versus `y`, where `points` is a list of `(x,y)` points. :param int pos: assign position: - 1, topleft, - 2, topright, - 3, bottomleft, - 4, bottomright. """ if len(points) == 2: # passing [allx, ally] #points = list(zip(points[0], points[1])) points = np.stack((points[0], points[1]), axis=1) c = colors.getColor(c) # allow different codings array_x = vtk.vtkFloatArray() array_y = vtk.vtkFloatArray() array_x.SetNumberOfTuples(len(points)) array_y.SetNumberOfTuples(len(points)) for i, p in enumerate(points): array_x.InsertValue(i, p[0]) array_y.InsertValue(i, p[1]) field = vtk.vtkFieldData() field.AddArray(array_x) field.AddArray(array_y) data = vtk.vtkDataObject() data.SetFieldData(field) plot = vtk.vtkXYPlotActor() plot.AddDataObjectInput(data) plot.SetDataObjectXComponent(0, 0) plot.SetDataObjectYComponent(0, 1) plot.SetXValuesToValue() plot.SetAdjustXLabels(0) plot.SetAdjustYLabels(0) plot.SetNumberOfXLabels(3) plot.GetProperty().SetPointSize(5) plot.GetProperty().SetLineWidth(2) plot.GetProperty().SetColor(colors.getColor(bg)) plot.SetPlotColor(0, c[0], c[1], c[2]) plot.SetXTitle(title) plot.SetYTitle("") plot.ExchangeAxesOff() plot.PlotPointsOn() if not lines: plot.PlotLinesOff() if pos == 1: plot.GetPositionCoordinate().SetValue(0.0, 0.8, 0) elif pos == 2: plot.GetPositionCoordinate().SetValue(0.76, 0.8, 0) elif pos == 3: plot.GetPositionCoordinate().SetValue(0.0, 0.0, 0) elif pos == 4: plot.GetPositionCoordinate().SetValue(0.76, 0.0, 0) else: plot.GetPositionCoordinate().SetValue(pos[0], pos[1], 0) plot.GetPosition2Coordinate().SetValue(s, s, 0) return plot
colors = [ 1, 4, 5, 8, 9, 10, 12, 1, 16, 16, 16,16 ,18] colors_numpy_array = np.asarray(colors) bitter = numpy_to_vtk(colors_numpy_array, deep=True, array_type=vtk.VTK_FLOAT) #print vtk_data_array #bitter = vtk.vtkFloatArray #bitter.SetNumberOfTuples(numTuples); #for i in range(0, numTuples):#(int i=0; i<numTuples; i++) # bitter.SetTuple1(i, vtk.vtkMath::Random(7,100)) dobj = vtk.vtkDataObject() dobj.GetFieldData().AddArray(bitter) actor = vtk.vtkBarChartActor() actor.SetInput(dobj); actor.SetTitle("Bar Chart"); actor.GetPositionCoordinate().SetValue(0.05,0.05,0.0); actor.GetPosition2Coordinate().SetValue(0.95,0.85,0.0); actor.GetProperty().SetColor(1,1,1); actor.GetLegendActor().SetNumberOfEntries(numTuples); ''' for (int i=0; i<numTuples; i++) { double red=vtkMath::Random(0,1); double green=vtkMath::Random(0,1);
crunchy.SetNumberOfTuples(numTuples) salty = vtk.vtkFloatArray() salty.SetNumberOfTuples(numTuples) oily = vtk.vtkFloatArray() oily.SetNumberOfTuples(numTuples) for i in range(numTuples): bitter.SetTuple1(i, random.randint(1, 10)) crispy.SetTuple1(i, random.randint(-1, 1)) crunchy.SetTuple1(i, random.randint(1, 100)) salty.SetTuple1(i, random.randint(0, 10)) oily.SetTuple1(i, random.randint(5, 25)) dobj = vtk.vtkDataObject() dobj.GetFieldData().AddArray(bitter) dobj.GetFieldData().AddArray(crispy) dobj.GetFieldData().AddArray(crunchy) dobj.GetFieldData().AddArray(salty) dobj.GetFieldData().AddArray(oily) actor = vtk.vtkSpiderPlotActor() actor.SetInputData(dobj) actor.SetTitle("spider plot") actor.SetIndependentVariablesToColumns() actor.GetPositionCoordinate().SetValue(0.05, 0.1, 0.0) actor.GetPosition2Coordinate().SetValue(0.95, 0.85, 0.0) actor.GetProperty().SetColor(1, 0, 0) actor.SetAxisLabel(0, "Bitter")
def main(): colors = vtk.vtkNamedColors() file_name, start_label, end_label = get_program_parameters() if start_label > end_label: end_label, start_label = start_label, end_label # Generate cubes from labels # 1) Read the meta file # 2) Convert point data to cell data # 3) Convert to geometry and display reader = vtk.vtkMetaImageReader() reader.SetFileName(file_name) reader.Update() # Pad the volume so that we can change the point data into cell # data. extent = reader.GetOutput().GetExtent() pad = vtk.vtkImageWrapPad() pad.SetInputConnection(reader.GetOutputPort()) pad.SetOutputWholeExtent(extent[0], extent[1] + 1, extent[2], extent[3] + 1, extent[4], extent[5] + 1) pad.Update() # Copy the scalar point data of the volume into the scalar cell data pad.GetOutput().GetCellData().SetScalars(reader.GetOutput().GetPointData().GetScalars()) selector = vtk.vtkThreshold() selector.SetInputArrayToProcess(0, 0, 0, vtk.vtkDataObject().FIELD_ASSOCIATION_CELLS, vtk.vtkDataSetAttributes().SCALARS) selector.SetInputConnection(pad.GetOutputPort()) selector.ThresholdBetween(start_label, end_label) selector.Update() # Shift the geometry by 1/2 transform = vtk.vtkTransform() transform.Translate(-0.5, -0.5, -0.5) transform_model = vtk.vtkTransformFilter() transform_model.SetTransform(transform) transform_model.SetInputConnection(selector.GetOutputPort()) geometry = vtk.vtkGeometryFilter() geometry.SetInputConnection(transform_model.GetOutputPort()) mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(geometry.GetOutputPort()) mapper.SetScalarRange(start_label, end_label) mapper.SetScalarModeToUseCellData() mapper.SetColorModeToMapScalars() actor = vtk.vtkActor() actor.SetMapper(mapper) renderer = vtk.vtkRenderer() render_window = vtk.vtkRenderWindow() render_window.AddRenderer(renderer) render_window.SetSize(640, 480) render_window.SetWindowName('GenerateCubesFromLabels') render_window_interactor = vtk.vtkRenderWindowInteractor() render_window_interactor.SetRenderWindow(render_window) renderer.AddActor(actor) renderer.SetBackground(colors.GetColor3d('DarkSlateBlue')) render_window.Render() camera = renderer.GetActiveCamera() camera.SetPosition(42.301174, 939.893457, -124.005030) camera.SetFocalPoint(224.697134, 221.301653, 146.823706) camera.SetViewUp(0.262286, -0.281321, -0.923073) camera.SetDistance(789.297581) camera.SetClippingRange(168.744328, 1509.660206) render_window_interactor.Start()
def main(): # vtkDiscreteFlyingEdges3D was introduced in VTK >= 8.2 use_flying_edges = vtk_version_ok(8, 2, 0) file_name, start_label, end_label = get_program_parameters() if start_label > end_label: end_label, start_label = start_label, end_label # Create all of the classes we will need reader = vtk.vtkMetaImageReader() histogram = vtk.vtkImageAccumulate() if use_flying_edges: try: using_marching_cubes = False discrete_cubes = vtk.vtkDiscreteFlyingEdges3D() except AttributeError: using_marching_cubes = True discrete_cubes = vtk.vtkDiscreteMarchingCubes() else: using_marching_cubes = True discrete_cubes = vtk.vtkDiscreteMarchingCubes() smoother = vtk.vtkWindowedSincPolyDataFilter() selector = vtk.vtkThreshold() scalars_off = vtk.vtkMaskFields() geometry = vtk.vtkGeometryFilter() writer = vtk.vtkXMLPolyDataWriter() # Define all of the variables file_prefix = 'Label' smoothing_iterations = 15 pass_band = 0.001 feature_angle = 120.0 # Generate models from labels # 1) Read the meta file # 2) Generate a histogram of the labels # 3) Generate models from the labeled volume # 4) Smooth the models # 5) Output each model into a separate file reader.SetFileName(file_name) histogram.SetInputConnection(reader.GetOutputPort()) histogram.SetComponentExtent(0, end_label, 0, 0, 0, 0) histogram.SetComponentOrigin(0, 0, 0) histogram.SetComponentSpacing(1, 1, 1) histogram.Update() discrete_cubes.SetInputConnection(reader.GetOutputPort()) discrete_cubes.GenerateValues(end_label - start_label + 1, start_label, end_label) smoother.SetInputConnection(discrete_cubes.GetOutputPort()) smoother.SetNumberOfIterations(smoothing_iterations) smoother.BoundarySmoothingOff() smoother.FeatureEdgeSmoothingOff() smoother.SetFeatureAngle(feature_angle) smoother.SetPassBand(pass_band) smoother.NonManifoldSmoothingOn() smoother.NormalizeCoordinatesOn() smoother.Update() selector.SetInputConnection(smoother.GetOutputPort()) if use_flying_edges: if using_marching_cubes: selector.SetInputArrayToProcess(0, 0, 0, vtk.vtkDataObject().FIELD_ASSOCIATION_CELLS, vtk.vtkDataSetAttributes().SCALARS) else: selector.SetInputArrayToProcess(0, 0, 0, vtk.vtkDataObject().FIELD_ASSOCIATION_POINTS, vtk.vtkDataSetAttributes().SCALARS) else: selector.SetInputArrayToProcess(0, 0, 0, vtk.vtkDataObject().FIELD_ASSOCIATION_CELLS, vtk.vtkDataSetAttributes().SCALARS) # Strip the scalars from the output scalars_off.SetInputConnection(selector.GetOutputPort()) scalars_off.CopyAttributeOff(vtk.vtkMaskFields().POINT_DATA, vtk.vtkDataSetAttributes().SCALARS) scalars_off.CopyAttributeOff(vtk.vtkMaskFields().CELL_DATA, vtk.vtkDataSetAttributes().SCALARS) geometry.SetInputConnection(scalars_off.GetOutputPort()) writer.SetInputConnection(geometry.GetOutputPort()) for i in range(start_label, end_label + 1): # see if the label exists, if not skip it frequency = histogram.GetOutput().GetPointData().GetScalars().GetTuple1(i) if frequency == 0.0: continue # select the cells for a given label selector.ThresholdBetween(i, i) # output the polydata output_fn = '{:s}{:d}.vtp'.format(file_prefix, i) print('{:s} writing {:s}'.format(os.path.basename(sys.argv[0]), output_fn)) writer.SetFileName(output_fn) writer.Write()