[vtkusers] Converting a Structured Points File to an Unstructured Points/Grid File

Ted Kord teddy.kord at googlemail.com
Wed May 12 18:50:02 EDT 2010


On 12 May 2010 23:48, Ted Kord <teddy.kord at googlemail.com> wrote:

>
>
> On 7 May 2010 23:15, <vtkusers-owner at vtk.org> wrote:
>
>> You are not allowed to post to this mailing list, and your message has
>> been automatically rejected.  If you think that your messages are
>> being rejected in error, contact the mailing list owner at
>> vtkusers-owner at vtk.org.
>>
>>
>>
>> ---------- Forwarded message ----------
>> From: Ted Kord <teddy.kord at googlemail.com>
>> To: "Eric E. Monson" <emonson at cs.duke.edu>
>> Date: Fri, 7 May 2010 23:15:36 +0100
>> Subject: Re: [vtkusers] Converting a Structured Points File to an
>> Unstructured Points/Grid File
>> I believe I've managed to obtain one solution. The code below works fine.
>>
>> int main(int argc, char *argv[])
>> {
>> //get all data from the file
>>  vtkSmartPointer<vtkStructuredPointsReader> reader =
>> vtkSmartPointer<vtkStructuredPointsReader>::New();
>> reader->SetFileName("geometry.vtk");
>>  reader->Update();
>>
>> vtkStructuredPoints* structuredPoints = reader->GetOutput();
>>
>> //get the number of points the file contains
>>   vtkIdType numPoints = structuredPoints->GetNumberOfPoints();
>>
>> std::cout << "There are " << numPoints << " points." << std::endl;
>>
>> vtkSmartPointer<vtkUnstructuredGrid> unstructuredGrid =
>> vtkSmartPointer<vtkUnstructuredGrid>::New();
>>
>> vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
>>
>> // Insert points
>>  for (int i = 0; i < numPoints; ++i) {
>> std::cout << i << std::endl;
>>  double* point = ((vtkImageData*)structuredPoints)->GetPoint(i);
>> points->InsertNextPoint(point);
>>  }
>>  unstructuredGrid->SetPoints(points);
>>  //vtkSmartPointer<vtkUnstructuredGridWriter> writer =
>> vtkSmartPointer<vtkUnstructuredGridWriter>::New();
>> vtkSmartPointer<vtkXMLUnstructuredGridWriter> writer =
>> vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();
>>  writer->SetFileName("unstructured_geometry.vtu");
>> writer->SetInput(unstructuredGrid);
>>  writer->Write();
>>
>>         return EXIT_SUCCESS;
>> }
>>
>>
>> I'll create a wiki example in due course.
>>
>> Thanks all
>>
>> Theodore
>>
>>
>> On 7 May 2010 21:22, Eric E. Monson <emonson at cs.duke.edu> wrote:
>>
>>> Hey Theodore,
>>>
>>> One quick way might be to send the output of the reader right into a
>>> vtkThreshold filter (that is set with a threshold range which will pass all
>>> of your data). I've never tried it with a vtkStructuredPoints, but it works
>>> well for vtkImageData, and I think it should work in your case.
>>>
>>> There are test code samples linked off of the Doxygen page:
>>>
>>> http://www.vtk.org/doc/nightly/html/classvtkThreshold.html
>>>
>>> Or, there is at least this one (and maybe more) on the VTK examples Wiki:
>>>
>>> http://www.itk.org/Wiki/VTK/Examples/ThresholdingCells
>>>
>>> (There's also a vtkThresholdPoints filter that outputs vtkPolyData)
>>>
>>> -Eric
>>>
>>> ------------------------------------------------------
>>> Eric E Monson
>>> Duke Visualization Technology Group
>>>
>>>
>>> On May 7, 2010, at 2:16 PM, Jack wrote:
>>>
>>> Hi
>>>
>>> I have a file with a dataset of structured points. I'd like to convert
>>> this to a dataset of unstructured points and/or unstructured grid. How can I
>>> do this?
>>>
>>> So far, this is what I have:
>>>
>>> int main()
>>> {
>>> //get all data from the file
>>> vtkSmartPointer< vtkStructuredPointsReader> reader = vtkSmartPointer<
>>> vtkStructuredPointsReader>:: New();
>>>  reader->SetFileName("geometry. vtk");
>>> reader->Update();
>>>
>>> vtkStructuredPoints* structuredPoints = reader->GetOutput();
>>>
>>> //get the number of points the file contains
>>>   vtkIdType numPoints = structuredPoints-> GetNumberOfPoints();
>>>
>>> std::cout << "There are " << numPoints << " points." << std::endl;
>>>
>>> vtkSmartPointer< vtkUnstructuredGrid> unstructuredGrid = vtkSmartPointer<
>>> vtkUnstructuredGrid>::New();
>>>
>>> }
>>>
>>> It's incomplete and I'm not sure how to proceed.
>>>
>>> Thanks in advance.
>>>
>>> Theodore
>>>
>>>

Hi again

I thought this was working but it turns out not to be.

I've tried several ways to do this but no success. I would have thought that
 vtkStructuredPointsToUnstructuredGrid would work but for some reason, I
keep getting compilation errors whenever I try to instantiate this.

I'd appreciate if someone could show me how to accomplish this.

Thanks

Theodore
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100512/c9c6885f/attachment.htm>


More information about the vtkusers mailing list