<div dir="ltr">Hello,<div><br></div><div>I am attempting to extract scalar data from an unstructured grid dataset based on point locations using python. First I am importing some libraries:</div><div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">import vtk<br>from vtk.util.numpy_support import vtk_to_numpy<br>import os<br></blockquote><div><br></div><div>Then I define a list of tuples where the location coordinates are stored. </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Locations = [(0,0.2,0.0),(0,0.4,0.0),(0,0.5,0.0),(0,0.6,0.0)]<br></blockquote><div><br></div><div>Next I create a vtkUnstructuredGridReader object, provide the filename and scalar field and update it: </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">reader = vtk.vtkUnstructuredGridReader() <br>reader.SetFileName('MyData.vtk')<br>reader.SetScalarsName('mass_solid') <br>reader.Update()<br></blockquote><div><br></div><div>Then I create a SelectionList as a vtkFloatArray() instance. This was inspired from this example ( <a href="https://www.vtk.org/Wiki/VTK/Examples/Python/PolyData/ExtractSelectionCells">https://www.vtk.org/Wiki/VTK/Examples/Python/PolyData/ExtractSelectionCells</a> ). I also feed in the location tuples into my SelectionList object.<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">SelectionList = vtk.vtkFloatArray()<br>SelectionList.SetNumberOfComponents(3) #dimension of the components<br>for Location in Locations:<br><span style="white-space:pre">    </span>SelectionList.InsertNextTuple(Location)<br></blockquote><div><br></div><div>I create a SelectionNode object and define the parameters for selection. </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">SelectionNode = vtk.vtkSelectionNode() <br>SelectionNode.SetFieldType(vtk.vtkSelectionNode.POINT)<br>SelectionNode.SetContentType(vtk.vtkSelectionNode.LOCATIONS)<br>SelectionNode.SetSelectionList(SelectionList) <br></blockquote><div><br></div><div>I create a Selection and Add the SelectionNode object to it. </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Selection = vtk.vtkSelection() <br>Selection.AddNode(SelectionNode) <br></blockquote><div><br></div><div>I create an ExtractSelection, define input connection, selection etc, </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">ExtractSelection = vtk.vtkExtractSelection() <br>ExtractSelection.SetInputConnection(0, reader.GetOutputPort()) <br>ExtractSelection.SetInput(1,Selection)<br>ExtractSelection.Update()<br></blockquote><div><br></div><div>I generate a new Unstructured Grid from my selection:</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Selected = vtk.vtkUnstructuredGrid()<br>Selected.ShallowCopy(ExtractSelection.GetOutput())<br></blockquote><div><br></div><div>I attempt to return the extracted data: </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">PointData = Selected.GetPointData()<br>Data = vtk_to_numpy(PointData.GetScalars())</blockquote><div><br></div><div>This last line however throws an error, and when I check to see why, the PointData is indeed a vtkObject but what is output from it's GetPointData() method is NoneType. This is frustrating since I had already defined the scalars to extract and I know they are there. Does anyone know what I am doing Wrong?</div></div><div><br></div><div>Thanks</div><div><br></div><div>Amine</div><div><br></div></div>