[Paraview-developers] [EXTERNAL] Re: Time-varying data reader

Joe Ping-Lin Hsiao phsiao at cs.unc.edu
Fri Sep 7 16:31:15 EDT 2012


I am not sure how to check the first file's name.
My reader code is not very long, so I paste it below:

BioFormatsReader::BioFormatsReader()
{
    this->FileName = NULL;
    this->SetNumberOfInputPorts(0);
    this->SetNumberOfOutputPorts(1);

        this->reader = ReaderType::New();
        this->connector = ConnectorType::New();

}

BioFormatsReader::~BioFormatsReader()
{
        if( this->reader )
                this->reader = NULL;

        if( this->connector )
                this->connector = NULL;
}

int BioFormatsReader::RequestInformation(
  vtkInformation *vtkNotUsed(request),
  vtkInformationVector **vtkNotUsed(inputVector),
  vtkInformationVector *outputVector)
{
        if (!this->FileName)
    {
                vtkErrorMacro(<< "A FileName must be specified.");
                return 0;
    }

        // Create an ITK reader and connect it to a Connector to get VTK output
        // --------------------------------------------------------------------
        this->reader->SetFileName(FileName);

        this->connector->SetInput(reader->GetOutput());
        this->connector->Update();

        vtkImageData *imageData = this->connector->GetOutput();
        // --------------------------------------------------------------------

        double spacing[3], origin[3];
        int extent[6];

        imageData->GetExtent(extent);
        imageData->GetOrigin(origin);
        imageData->GetSpacing(spacing);

        // get the info object
        vtkInformation *outInfo = outputVector->GetInformationObject(0);

        outInfo->Set(vtkDataObject::ORIGIN(),origin,3);
        outInfo->Set(vtkDataObject::SPACING(),spacing,3);
        outInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(),extent,6);

        this->GetOutput()->SetNumberOfScalarComponents(1);
        this->GetOutput()->SetScalarType(VTK_FLOAT);

        return 1;
}
int BioFormatsReader::RequestData(
  vtkInformation *vtkNotUsed(request),
  vtkInformationVector **vtkNotUsed(inputVector),
  vtkInformationVector *outputVector)
{

        vtkInformation *outInfo = outputVector->GetInformationObject(0);
    vtkImageData *output = vtkImageData::SafeDownCast(
          (outInfo->Get(vtkDataObject::DATA_OBJECT())));

        if (!output)
    {
                vtkErrorMacro("Output is not of type vtkImageData");
                return 0;
    }

        /*
        if (output->GetScalarType() != VTK_FLOAT)
        {
                vtkErrorMacro("Execute: This source only outputs floats.");
                return 1;
        }
        */

        output->ShallowCopy(this->connector->GetOutput());

        return 1;
}

void BioFormatsReader::PrintSelf(ostream& os, vtkIndent indent)
{
        this->Superclass::PrintSelf(os,indent);

        os << indent << "File Name: "
      << (this->FileName ? this->FileName : "(none)") << "\n";
}

On Fri, Sep 7, 2012 at 1:19 PM, Sebastien Jourdain
<sebastien.jourdain at kitware.com> wrote:
> Did you check in your reader that you get properly the file name of the
> first file ? When you switch back to the first time ?
>
> Seb
>
> On Fri, Sep 7, 2012 at 1:04 PM, Joe Ping-Lin Hsiao <phsiao at cs.unc.edu>
> wrote:
>>
>> Besides the capital letters, another error is my gui xml has a
>> mismatched source name. (Later I figure out that I don't need a gui
>> xml for the reader to run.) Now I can load data without crash.
>>
>> But the problem remains. The animation plays fine at the first time.
>> After it plays to the end, I click the 'Go back to the first frame'
>> button, but the rendering still stays at the last frame even though in
>> the information tab it says it's at frame 0. Am I missing something?
>>
>> Joe
>>
>> On Mon, Sep 3, 2012 at 10:12 AM, Sebastien Jourdain
>> <sebastien.jourdain at kitware.com> wrote:
>> > I've just fixed the wiki example to match the current ParaView version.
>> >
>> > The issue in your XML is due to the usage of capital letters in
>> > attributes
>> > here:
>> >
>> >       <SubProxy>
>> >         <Proxy name="Reader"
>> >           ProxyGroup="internal_sources"
>> > ProxyName="bioformatsreadercore">
>> >         </Proxy>
>> >       </SubProxy>
>> >
>> > === Should be ===
>> >
>> >       <SubProxy>
>> >         <Proxy name="Reader"
>> >           proxygroup="internal_sources"
>> > proxyname="bioformatsreadercore">
>> >         </Proxy>
>> >       </SubProxy>
>> >
>> > Seb
>> >
>> > On Fri, Aug 31, 2012 at 12:58 PM, Joe Ping-Lin Hsiao <phsiao at cs.unc.edu>
>> > wrote:
>> >>
>> >> It's me again.
>> >>
>> >> Turns out that my animation plugin is buggy. The symptom is after I
>> >> play the animation once, it doesn't go back to the first animation
>> >> position even I click rewind in ParaView. The frame number in the
>> >> Information tab doesn't match what is currently rendered.
>> >>
>> >> When I go back to check my xml, I found I was overwriting the .vtk
>> >> file series reader cause I just copied the whole SourceProxy section
>> >> over and didn't change the name field. (I confirm this because
>> >> ParaView doesn't recognize .vtk files anymore in the open file dialog
>> >> if I load my reader.)
>> >>
>> >> But after I assign this file series reader proxy a new name, ParaView
>> >> would just crash after I load files in and click 'Apply'. Also, the
>> >> messages in my core reader are not printed out. It looks like ParaView
>> >> is not using my core reader at all.
>> >>
>> >> I have attached my xml code below.
>> >>
>> >> <ServerManagerConfiguration>
>> >>   <ProxyGroup name="internal_sources">
>> >>     <SourceProxy name="bioformatsreadercore"
>> >>                      class="BioFormatsReader"
>> >>                                  label="BioFormats Reader">
>> >>       <Documentation
>> >>          long_help="Read Bio-Formats files."
>> >>          short_help="Read Bio-Formats files.">
>> >>       </Documentation>
>> >>       <StringVectorProperty
>> >>             name="FileName"
>> >>             animateable="0"
>> >>             command="SetFileName"
>> >>             number_of_elements="1">
>> >>         <FileListDomain name="files"/>
>> >>         <Documentation>
>> >>           This property specifies the input file name.
>> >>         </Documentation>
>> >>       </StringVectorProperty>
>> >>
>> >>     </SourceProxy>
>> >>   </ProxyGroup>
>> >>
>> >>   <ProxyGroup name="sources">
>> >>   <SourceProxy name="BioFormatsFileReader"
>> >>                           class="vtkFileSeriesReader"
>> >>                           label="Legacy VTK Reader"
>> >>                           si_class="vtkSIFileSeriesReaderProxy"
>> >>                           file_name_method="SetFileName">
>> >>      <Documentation
>> >>        short_help="Read legacy VTK files."
>> >>        long_help="Reads files stored in VTK's legacy file format.">
>> >>        The Legacy VTK reader loads files stored in VTK's legacy file
>> >> format (before VTK 4.2, although still supported). The expected file
>> >> extension is .vtk. The type of the dataset may be structured grid,
>> >> uniform rectilinear grid (image/volume), non-uniform rectiinear grid,
>> >> unstructured grid, or polygonal. This reader also supports file
>> >> series.
>> >>      </Documentation>
>> >>       <SubProxy>
>> >>         <Proxy name="Reader"
>> >>           ProxyGroup="internal_sources"
>> >> ProxyName="bioformatsreadercore">
>> >>         </Proxy>
>> >>       </SubProxy>
>> >>
>> >>      <StringVectorProperty name="FileNameInfo"
>> >>         command="GetCurrentFileName"
>> >>         information_only="1" >
>> >>         <SimpleStringInformationHelper />
>> >>      </StringVectorProperty>
>> >>
>> >>      <StringVectorProperty
>> >>         name="FileNames"
>> >>         clean_command="RemoveAllFileNames"
>> >>         command="AddFileName"
>> >>         animateable="0"
>> >>         number_of_elements="1"
>> >>         repeat_command="1"
>> >>         information_property="FileNameInfo" >
>> >>         <FileListDomain name="files"/>
>> >>        <Documentation>
>> >>          The list of files to be read by the reader. If more than one
>> >> file is specified, the reader will switch to file series mode in which
>> >> it will pretend that it can support time and provide one file per time
>> >> step.
>> >>        </Documentation>
>> >>      </StringVectorProperty>
>> >>
>> >>      <DoubleVectorProperty
>> >>         name="TimestepValues"
>> >>         repeatable="1"
>> >>         information_only="1">
>> >>         <TimeStepsInformationHelper/>
>> >>         <Documentation>
>> >>           Available timestep values.
>> >>         </Documentation>
>> >>      </DoubleVectorProperty>
>> >>
>> >>      <Hints>
>> >>       <ReaderFactory extensions="tif"
>> >>           file_description="Legacy VTK files" />
>> >>      </Hints>
>> >>      <!-- End LegacyVTKFileReader -->
>> >>    </SourceProxy>
>> >>   </ProxyGroup>
>> >>
>> >> </ServerManagerConfiguration>
>> >>
>> >>
>> >> On Fri, Aug 24, 2012 at 3:15 PM, Moreland, Kenneth <kmorel at sandia.gov>
>> >> wrote:
>> >> > In that case, someone should definitely update the wiki page.
>> >> >
>> >> > I see a note added by Jourdain on another page
>> >> > (http://paraview.org/Wiki/ServerManager_XML_Hints#TimeSeries_readers)
>> >> > that
>> >> > suggests a change in 3.12. Perhaps he can update the example.
>> >> >
>> >> > -Ken
>> >> >
>> >> > Sent from my iPad so blame autocorrect.
>> >> >
>> >> > On Aug 24, 2012, at 11:27 AM, "Joe Ping-Lin Hsiao"
>> >> > <phsiao at cs.unc.edu>
>> >> > wrote:
>> >> >
>> >> >> It's working!
>> >> >> I just followed the VTK reader code in readers.xml at
>> >> >> ParaView3.14.1\ParaViewCore\ServerImplementation\Resources.
>> >> >>
>> >> >> Ken,
>> >> >>  I first tried the xml code from the wiki, but I couldn't even read
>> >> >> a
>> >> >> file. I guess the xml scheme had changed in ParaView 3.14, and
>> >> >> what's
>> >> >> on the wiki is for older versions of ParaView.
>> >> >>
>> >> >> Thanks,
>> >> >> Joe
>> >> >>
>> >> >> On Thu, Aug 23, 2012 at 6:43 PM, Moreland, Kenneth
>> >> >> <kmorel at sandia.gov>
>> >> >> wrote:
>> >> >>> It looks like there is a Wiki page describing how to use the
>> >> >>> vtkFileSeriesReader to convert a reader to understand file series.
>> >> >>>
>> >> >>> http://www.paraview.org/Wiki/Animating_legacy_VTK_file_series
>> >> >>>
>> >> >>> -Ken
>> >> >>>
>> >> >>>
>> >> >>>
>> >> >>> On 8/23/12 3:35 PM, "David E DeMarle" <dave.demarle at kitware.com>
>> >> >>> wrote:
>> >> >>>
>> >> >>>> To make uniformly increasing time denoted in numbered file
>> >> >>>> sequences,
>> >> >>>> encapsulate your reader in a sub proxy of a vtkFileSeriesReader.
>> >> >>>> See
>> >> >>>> readers.xml for numerous examples of that.
>> >> >>>>
>> >> >>>> If you need nonuniform temporal spacing or need to improve upon
>> >> >>>> the
>> >> >>>> file series reader's IO performance, make your reader supply
>> >> >>>> temporal
>> >> >>>> information and respond to time requests appropriately in
>> >> >>>> RequestInformation and RequestData respectively. See
>> >> >>>> vtkTimeSourceExample for an example of that.
>> >> >>>>
>> >> >>>> David E DeMarle
>> >> >>>> Kitware, Inc.
>> >> >>>> R&D Engineer
>> >> >>>> 21 Corporate Drive
>> >> >>>> Clifton Park, NY 12065-8662
>> >> >>>> Phone: 518-881-4909
>> >> >>>>
>> >> >>>>
>> >> >>>> On Thu, Aug 23, 2012 at 5:22 PM, Joe Ping-Lin Hsiao
>> >> >>>> <phsiao at cs.unc.edu>
>> >> >>>> wrote:
>> >> >>>>> Hi,
>> >> >>>>>
>> >> >>>>> I have written a customized reader in ParaView which reads 3D
>> >> >>>>> stacks.
>> >> >>>>> Now I'd like to add the function of reading time-varying data to
>> >> >>>>> it,
>> >> >>>>> so I can create animations from stacks.
>> >> >>>>>
>> >> >>>>> ParaView has this function already. If I convert time-varying
>> >> >>>>> stacks
>> >> >>>>> and name them stack001.vtk, stack002.vtk, and etc, ParaView would
>> >> >>>>> recognize the sequence and load them in at once, and I'd be able
>> >> >>>>> to
>> >> >>>>> play the animation just by clicking the 'Play' icon.
>> >> >>>>>
>> >> >>>>> I wonder is there any example of how to do that to a reader?
>> >> >>>>>
>> >> >>>>> Thanks,
>> >> >>>>> Joe
>> >> >>>>> _______________________________________________
>> >> >>>>> Paraview-developers mailing list
>> >> >>>>> Paraview-developers at paraview.org
>> >> >>>>> http://public.kitware.com/mailman/listinfo/paraview-developers
>> >> >>>> _______________________________________________
>> >> >>>> Paraview-developers mailing list
>> >> >>>> Paraview-developers at paraview.org
>> >> >>>> http://public.kitware.com/mailman/listinfo/paraview-developers
>> >> >>>>
>> >> >>>
>> >> >>>
>> >> >>
>> >> >
>> >> _______________________________________________
>> >> Paraview-developers mailing list
>> >> Paraview-developers at paraview.org
>> >> http://public.kitware.com/mailman/listinfo/paraview-developers
>> >
>> >
>
>


More information about the Paraview-developers mailing list