[vtkusers] vtkPNGWriter: Write reduced vtkUnstructuredGrid field data to PNG-file via vtkResampleWithDataset

Bill Lorensen bill.lorensen at gmail.com
Tue Jan 16 09:37:54 EST 2018


After
 resample->SetInputData( image );
do
resample->Update();


On Tue, Jan 16, 2018 at 5:36 AM, David E DeMarle
<dave.demarle at kitware.com> wrote:
> My guess is that the PNG writer expect three components, not a single
> component array. vtkImageAppendComponents would be one way to make a three
> tuple, but it would be more straightforward to do it in the array
> construction with
> SetNumberOfComponents(3) followed by
> yourloop {
>    InsertNextTuple3(Tint,Tint,Tint);
> }
>
>
> David E DeMarle
> Kitware, Inc.
> Principal Engineer
> 21 Corporate Drive
> Clifton Park, NY 12065-8662
> Phone: 518-881-4909
>
> On Tue, Jan 16, 2018 at 3:49 AM, Stephan Lenz <stephan.lenz at tu-bs.de> wrote:
>>
>> Hello everybody,
>>
>> I have problems setting up a pipeline to write data to an PNG-file.
>>
>> I have a 2-D simulation on a large rectangular non-uniform grid (
>> ~60.000.000 Cells ). For visualization of the results I would like to write
>> PNG files (or other Imagefiles) in order to create an animation.
>>
>> I am already able to write VTK-ImageData files (.vti) and make an
>> animation in Paraview. Nevertheless I would prefer to generate the animation
>> directly from images, as the simulation domain should fill the whole
>> animation domain. With paraview fitting the simulation domain seamlessly in
>> the view is not trivial.
>>
>> My current pipeline is:
>>
>>           // this adapter function couples my simulation datastructures to
>> VTK
>>             vtkSmartPointer<vtkUnstructuredGrid> grid =
>> getVtkUnstructuredGrid(dataBase);
>>
>>             // generate the field data
>>             vtkSmartPointer<vtkUnsignedCharArray> data =
>> vtkSmartPointer<vtkUnsignedCharArray>::New();
>>             data->SetNumberOfComponents( 1 );
>>             data->SetName( "T" );
>>             for( Idx cellIdx = 0; cellIdx < numberOfCells; cellIdx++ ){
>>                 unsigned char value = getValue( cellIdx );
>>                 data->InsertNextValue( Tint );
>>             }
>>             grid->GetCellData()->AddArray( data );
>>
>>             // define the grid for the output
>>             vtkSmartPointer<vtkImageData> image =
>> vtkSmartPointer<vtkImageData>::New();
>>             image->SetDimensions(512+1,256+1,1);
>>             image->SetSpacing( L/512, H/256, 0 );
>>
>>             // resample the field data to the coarser vtkImageData
>>             vtkSmartPointer<vtkResampleWithDataSet> resample =
>> vtkSmartPointer<vtkResampleWithDataSet>::New();
>>             resample->SetSourceData( grid );
>>             resample->SetInputData( image );
>>
>>             // write the data to PNG-file (does not work!)
>>             vtkSmartPointer<vtkPNGWriter> writerPNG =
>> vtkSmartPointer<vtkPNGWriter>::New();
>>             writerPNG->SetFileName( ( simulationName + ".png").c_str() );
>>             writerPNG->SetInputData( resample->GetOutput() );
>>             writerPNG->Write();
>>
>>             // write the data to VTI-file (works!)
>>             vtkSmartPointer<vtkXMLImageDataWriter> writer =
>> vtkSmartPointer<vtkXMLImageDataWriter>::New();
>>             writer->SetFileName( ( simulationName + "." +
>> writer->GetDefaultFileExtension() ).c_str() );
>>             writer->SetDataMode( vtkXMLWriter::Binary );
>>             writer->SetInputData( resample->GetOutput() );
>>             writer->Write();
>>
>> The above code compiles and runs without errors, but I do not get any
>> PNG-Files. The VTI-files are written and I can open them in Paraview, as
>> usual. I tried many different things, but did not get single PNG-file out of
>> this.
>>
>> When I, for example, change
>>
>> writerPNG->SetInputData( resample->GetOutput() );
>>
>> to
>>
>> writerPNG->SetInputConnection( resample->GetOutputPort() );
>>
>> I get a VTK Error message, that says "PNGWriter only supports unsigned
>> char and unsigned short inputs". But as far as I see it the field data is
>> unsigned char and this is confirmed by Paraview, when I look into the
>> VTI-files (generated with both SetInputData and SetInputConnection).
>>
>> Do you see any obvious mistakes I make? How do I have to set up such a
>> pipeline to get a PNG (or other image file) output. I would be glad for any
>> help.
>>
>> Thank you very much,
>>
>> Stephan Lenz
>>
>> _______________________________________________
>> 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 BillsBasement at noware dot com


More information about the vtkusers mailing list