[vtkusers] vtkParticleReader and vtkGlyph3D

Sgouros, Thomas thomas_sgouros at brown.edu
Fri Apr 6 07:32:49 EDT 2018


Hi All:

Following up on this, can anyone advise me how to get the data out of a
ParticleReader? I think my best option is just to build up data in a
vtkPoints array by hand, as it were. But I can't find a
ParticleReader::GetParticleData method or even anything that looks remotely
like it. I tried converting it to a vtkTable, but that was rejected. The
file is an ASCII vtk file, so I can always read it by hand, but that can't
really be the right way to do this, can it?

Thank you,

 -Tom

On Tue, Apr 3, 2018 at 4:54 PM, Sgouros, Thomas <thomas_sgouros at brown.edu>
wrote:

> "It is often some unexpected minor thing that causes the failure."
>
> I'm certain of that.
>
> Here's the code, mostly pinched straight from the Glyph3D example. (And
> I've tried swapping the endianness, just for giggles.) The data is an ASCII
> vtk file that you can get from sgouros.com/output_p40.vtk.
>
> Thank you,
>
>  -Tom
>
>
> #include <vtkVersion.h>
> #include <vtkSmartPointer.h>
> #include <vtkCubeSource.h>
> #include <vtkPolyData.h>
> #include <vtkPoints.h>
> #include <vtkGlyph3D.h>
> #include <vtkCellArray.h>
> #include <vtkPolyDataMapper.h>
> #include <vtkActor.h>
> #include <vtkRenderWindow.h>
> #include <vtkRenderer.h>
> #include <vtkRenderWindowInteractor.h>
> #include <vtkParticleReader.h>
> #include <vtkPolyDataMapper.h>
>
>
> int main(int argc, char* argv[]) {
>
>   std::string filePath = argv[1];
>   vtkSmartPointer<vtkParticleReader> reader =
>     vtkSmartPointer<vtkParticleReader>::New();
>
>   reader->SetFileName ( filePath.c_str() );
>   // if nothing gets displayed or totally wrong, swap the endianness
>   reader->SetDataByteOrderToBigEndian();
>   reader->Update();
>
>   // Create anything you want here, we will use a cube for the demo.
>   vtkSmartPointer<vtkCubeSource> cubeSource =
>       vtkSmartPointer<vtkCubeSource>::New();
>
>   vtkSmartPointer<vtkGlyph3D> glyph3D =
>     vtkSmartPointer<vtkGlyph3D>::New();
>
>   glyph3D->SetSourceConnection(cubeSource->GetOutputPort());
>   glyph3D->SetInputConnection(reader->GetOutputPort());
>
>   glyph3D->Update();
>
>   std::cout << *(reader->GetOutput()) << std::endl;
>
>   // Visualize
>   vtkSmartPointer<vtkPolyDataMapper> mapper =
>     vtkSmartPointer<vtkPolyDataMapper>::New();
>   mapper->SetInputConnection(glyph3D->GetOutputPort());
>
>   vtkSmartPointer<vtkActor> actor =
>     vtkSmartPointer<vtkActor>::New();
>   actor->SetMapper(mapper);
>
>   vtkSmartPointer<vtkRenderer> renderer =
>     vtkSmartPointer<vtkRenderer>::New();
>   vtkSmartPointer<vtkRenderWindow> renderWindow =
>     vtkSmartPointer<vtkRenderWindow>::New();
>   renderWindow->AddRenderer(renderer);
>   vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
>     vtkSmartPointer<vtkRenderWindowInteractor>::New();
>   renderWindowInteractor->SetRenderWindow(renderWindow);
>
>   renderer->AddActor(actor);
>   renderer->SetBackground(.3, .6, .3); // Background color green
>
>   renderWindow->Render();
>   renderWindowInteractor->Start();
>
>   return EXIT_SUCCESS;
> }
>
>
> On Tue, Apr 3, 2018 at 4:46 PM, Bill Lorensen <bill.lorensen at gmail.com>
> wrote:
>
>> Post a small compilable example, please. It is often some unexpected
>> minor thing that causes the failure.
>>
>> Thanks,
>>
>> Bill
>>
>> BTW: The wiki examples have been replaced by VTKExamples here:
>>
>> https://lorensen.github.io/VTKExamples/site/
>>
>>
>> On Tue, Apr 3, 2018 at 1:43 PM, Sebastien Jourdain
>> <sebastien.jourdain at kitware.com> wrote:
>> > What you are doing seems correct and the data is valid (it has points).
>> >
>> > How do you render the glyph3d filter? Using a polydata mapper? I'm
>> guessing
>> > no issue on that end?
>> >
>> > Ideally you should use the glyph mapper instead of the filter. But if
>> memory
>> > is not a big deal, don't worry about it.
>> >
>> > Seb
>> >
>> > On Tue, Apr 3, 2018 at 1:47 PM, Sgouros, Thomas <
>> thomas_sgouros at brown.edu>
>> > wrote:
>> >>
>> >> This is reader->GetOutput()
>> >>
>> >> vtkPolyData (0x7f8ce050dad0)
>> >>
>> >>   Debug: Off
>> >>
>> >>   Modified Time: 217
>> >>
>> >>   Reference Count: 1
>> >>
>> >>   Registered Events: (none)
>> >>
>> >>   Information: 0x7f8ce050d9b0
>> >>
>> >>   Data Released: False
>> >>
>> >>   Global Release Data: Off
>> >>
>> >>   UpdateTime: 218
>> >>
>> >>   Field Data:
>> >>
>> >>     Debug: Off
>> >>
>> >>     Modified Time: 167
>> >>
>> >>     Reference Count: 1
>> >>
>> >>     Registered Events: (none)
>> >>
>> >>     Number Of Arrays: 0
>> >>
>> >>     Number Of Components: 0
>> >>
>> >>     Number Of Tuples: 0
>> >>
>> >>   Number Of Points: 10229
>> >>
>> >>   Number Of Cells: 10229
>> >>
>> >>
>> >> It goes on for quite a bit more. As I said, when I feed this to a
>> >> vtkPolyDataMapper, it displays and works fine, but I want little
>> spheres,
>> >> not little flat rectangles and I thought I could just redirect that
>> into the
>> >> vtkGlyph3D object, but I must be misunderstanding something.
>> >>
>> >> Thank you,
>> >>
>> >>  -Tom
>> >>
>> >> On Tue, Apr 3, 2018 at 3:26 PM, Sebastien Jourdain
>> >> <sebastien.jourdain at kitware.com> wrote:
>> >>>
>> >>> You can try to see what the GetOutput() contains as my assumption it
>> >>> would be empty (No points => Number of Points: 0).
>> >>>
>> >>> reader->GetOutput()->PrintSelf(cout, vtkIndent(2));
>> >>>
>> >>> What I mean was
>> >>>
>> >>> glyph3D->SetInputConnection(reader->GetOutputPort());
>> >>>
>> >>>
>> >>> On Tue, Apr 3, 2018 at 1:23 PM, Sgouros, Thomas
>> >>> <thomas_sgouros at brown.edu> wrote:
>> >>>>
>> >>>> Hi Sebastien:
>> >>>>
>> >>>> Sorry if that was unclear. The third block of code comes first, and
>> >>>> reader->Update() is called before I use its GetOutput().  In situ,
>> it looks
>> >>>> like this:
>> >>>>
>> >>>>  ...
>> >>>>   vtkSmartPointer<vtkParticleReader> reader =
>> >>>> vtkSmartPointer<vtkParticleReader>::New();
>> >>>>   reader->SetFileName ( filePath.c_str() );
>> >>>>   reader->SetDataByteOrderToBigEndian();
>> >>>>   reader->Update();
>> >>>>
>> >>>>   // Create anything you want here, we will use a cube for the demo.
>> >>>>   vtkSmartPointer<vtkCubeSource> cubeSource =
>> >>>>       vtkSmartPointer<vtkCubeSource>::New();
>> >>>>
>> >>>>   vtkSmartPointer<vtkGlyph3D> glyph3D =
>> >>>> vtkSmartPointer<vtkGlyph3D>::New();
>> >>>>   glyph3D->SetSourceConnection(cubeSource->GetOutputPort());
>> >>>>   glyph3D->SetInputData(reader->GetOutput());
>> >>>>   glyph3D->Update();
>> >>>>
>> >>>>   ...
>> >>>>
>> >>>> I don't think I understand what you mean by the connection instead of
>> >>>> the dataset directly.
>> >>>>
>> >>>> Is there a way to peek inside glyph3D and see what it thinks it has?
>> >>>>
>> >>>> Thank you,
>> >>>>
>> >>>>  -Tom
>> >>>>
>> >>>>
>> >>>> On Tue, Apr 3, 2018 at 2:53 PM, Sebastien Jourdain
>> >>>> <sebastien.jourdain at kitware.com> wrote:
>> >>>>>
>> >>>>> Tom,
>> >>>>>
>> >>>>> Just make sure that reader->Update(); was called before
>> >>>>> glyph3D->SetInputData(reader->GetOutput());
>> >>>>> But it would be better to use the connection instead of the dataset
>> >>>>> directly.
>> >>>>>
>> >>>>> Seb
>> >>>>>
>> >>>>> On Tue, Apr 3, 2018 at 12:27 PM, Sgouros, Thomas
>> >>>>> <thomas_sgouros at brown.edu> wrote:
>> >>>>>>
>> >>>>>> Hello all:
>> >>>>>>
>> >>>>>> Can someone help me understand why this code works:
>> >>>>>>
>> >>>>>>   vtkSmartPointer<vtkGlyph3D> glyph3D =
>> >>>>>> vtkSmartPointer<vtkGlyph3D>::New();
>> >>>>>>   glyph3D->SetSourceConnection(cubeSource->GetOutputPort());
>> >>>>>>   glyph3D->SetInputData(polydata);
>> >>>>>>   glyph3D->Update();
>> >>>>>>
>> >>>>>> And this does not (nothing displayed)?
>> >>>>>>
>> >>>>>>   vtkSmartPointer<vtkGlyph3D> glyph3D =
>> >>>>>> vtkSmartPointer<vtkGlyph3D>::New();
>> >>>>>>   glyph3D->SetSourceConnection(cubeSource->GetOutputPort());
>> >>>>>>   glyph3D->SetInputData(reader->GetOutput());
>> >>>>>>   glyph3D->Update();
>> >>>>>>
>> >>>>>> The first clip is from
>> >>>>>> https://www.vtk.org/Wiki/VTK/Examples/Cxx/Filtering/Glyph3D
>> >>>>>>
>> >>>>>> The 'reader' object is stolen from the ParticleReader example:
>> >>>>>>
>> >>>>>>   vtkSmartPointer<vtkParticleReader> reader =
>> >>>>>> vtkSmartPointer<vtkParticleReader>::New();
>> >>>>>>   reader->SetFileName ( filePath.c_str() );
>> >>>>>>   reader->SetDataByteOrderToBigEndian();
>> >>>>>>   reader->Update();
>> >>>>>>
>> >>>>>> The program compiles, but no data appears. It works fine (data
>> >>>>>> appears) in the context of the ParticleReader example, where it
>> shows all
>> >>>>>> the data points. But I want to see them as glyphs, not little
>> squares. I
>> >>>>>> seem to be misunderstanding something fundamental, but not seeing
>> what it
>> >>>>>> could be.
>> >>>>>>
>> >>>>>> Many thanks,
>> >>>>>>
>> >>>>>>  -Tom
>> >>>>>>
>> >>>>>>
>> >>>>>>
>> >>>>>> _______________________________________________
>> >>>>>> Powered by www.kitware.com
>> >>>>>>
>> >>>>>> Visit other Kitware open-source projects at
>> >>>>>> http://www.kitware.com/opensource/opensource.html
>> >>>>>>
>> >>>>>> Please keep messages on-topic and check the VTK FAQ at:
>> >>>>>> http://www.vtk.org/Wiki/VTK_FAQ
>> >>>>>>
>> >>>>>> Search the list archives at: http://markmail.org/search/?q=
>> vtkusers
>> >>>>>>
>> >>>>>> Follow this link to subscribe/unsubscribe:
>> >>>>>> https://vtk.org/mailman/listinfo/vtkusers
>> >>>>>>
>> >>>>>
>> >>>>
>> >>>
>> >>
>> >
>> >
>> > _______________________________________________
>> > Powered by www.kitware.com
>> >
>> > Visit other Kitware open-source projects at
>> > http://www.kitware.com/opensource/opensource.html
>> >
>> > Please keep messages on-topic and check the VTK FAQ at:
>> > http://www.vtk.org/Wiki/VTK_FAQ
>> >
>> > Search the list archives at: http://markmail.org/search/?q=vtkusers
>> >
>> > Follow this link to subscribe/unsubscribe:
>> > https://vtk.org/mailman/listinfo/vtkusers
>> >
>>
>>
>>
>> --
>> Unpaid intern in BillsParadise at noware dot com
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://vtk.org/pipermail/vtkusers/attachments/20180406/f5e24a46/attachment.html>


More information about the vtkusers mailing list