ParaView/Examples/Plugins/Reader: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
(Created page with "==MyReader.h== <source lang="cpp"> </source> ==MyReader.cxx== <source lang="cpp"> </source> ==MyReader.xml== <source lang="xml"> </source> ==MyReaderGUI.xml== <source lang=...")
 
No edit summary
Line 1: Line 1:
This example shows how to turn a custom VTK reader into a ParaView Reader filter. In this example we do not actually read a file, but instead generate data (so this is really a source, not a reader, but this is simply to make it easier to try the example - the structure is setup as a reader). That is, once you load the plugin in ParaView, you must go to File -> Open and select a ".abc" file (the file can be empty). This is the file that would be read if the reader actually did some reading! You should see a single point/vertex in the resulting PolyData object.
==MyReader.h==
==MyReader.h==
<source lang="cpp">
<source lang="cpp">
#ifndef __MyReader_h
#define __MyReader_h
#include "vtkPolyDataAlgorithm.h"
class MyReader : public vtkPolyDataAlgorithm
{
public:
  vtkTypeMacro(MyReader,vtkPolyDataAlgorithm);
  void PrintSelf(ostream& os, vtkIndent indent);
  static MyReader *New();
  // Description:
  // Specify file name of the .abc file.
  vtkSetStringMacro(FileName);
  vtkGetStringMacro(FileName);
 
protected:
  MyReader();
  ~MyReader(){}
  int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
private:
  MyReader(const MyReader&);  // Not implemented.
  void operator=(const MyReader&);  // Not implemented.
  char* FileName;
};
#endif


</source>
</source>
Line 6: Line 40:
==MyReader.cxx==
==MyReader.cxx==
<source lang="cpp">
<source lang="cpp">
#include "MyReader.h"
#include "vtkObjectFactory.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkInformationVector.h"
#include "vtkInformation.h"
#include "vtkDataObject.h"
#include "vtkSmartPointer.h"
#include "vtkVertexGlyphFilter.h"
vtkStandardNewMacro(MyReader);
MyReader::MyReader()
{
  this->FileName = NULL;
  this->SetNumberOfInputPorts(0);
  this->SetNumberOfOutputPorts(1);
}
int MyReader::RequestData(
  vtkInformation *vtkNotUsed(request),
  vtkInformationVector **vtkNotUsed(inputVector),
  vtkInformationVector *outputVector)
{
  // get the info object
  vtkInformation *outInfo = outputVector->GetInformationObject(0);
  // get the ouptut
  vtkPolyData *output = vtkPolyData::SafeDownCast(
            outInfo->Get(vtkDataObject::DATA_OBJECT()));
  // Here is where you would read the data from the file. In this example,
  // we simply create a point.
  vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
  vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
  points->InsertNextPoint(0.0, 0.0, 0.0);
  polydata->SetPoints(points);
  vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter =
    vtkSmartPointer<vtkVertexGlyphFilter>::New();
  glyphFilter->SetInputConnection(polydata->GetProducerPort());
  glyphFilter->Update();
  output->ShallowCopy(glyphFilter->GetOutput());
  return 1;
}
void MyReader::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os,indent);
  os << indent << "File Name: "
      << (this->FileName ? this->FileName : "(none)") << "\n";
}


</source>
</source>
Line 11: Line 103:
==MyReader.xml==
==MyReader.xml==
<source lang="xml">
<source lang="xml">
<ServerManagerConfiguration>
  <ProxyGroup name="sources">
    <!-- ================================================================== -->
    <SourceProxy name="MyReader" class="MyReader" label="MyReader">
      <Documentation
        long_help="Read a .abc file."
        short_help="Read a .abc file.">
      </Documentation>
      <StringVectorProperty
            name="FileName"
            animateable="0"
            command="SetFileName"
            number_of_elements="1">
        <FileListDomain name="files"/>
        <Documentation>
          This property specifies the file name for the PNG reader.
        </Documentation>
      </StringVectorProperty>


      <Hints>
        <ReaderFactory extensions="abc"
                      file_description="Example File Format" />
    </Hints>
    </SourceProxy>
    <!-- End Reader -->
  </ProxyGroup>
  <!-- End Filters Group -->
</ServerManagerConfiguration>
</source>
</source>


==MyReaderGUI.xml==
==MyReaderGUI.xml==
<source lang="xml">
<source lang="xml">
 
<ParaViewReaders>
  <Reader name="MyReader" extensions="abc"
  file_description="Example (.abc) Files">
  </Reader>
</ParaViewReaders>
</source>
</source>


==CMakeLists.txt==
==CMakeLists.txt==
<source lang="cmake">
<source lang="cmake">
cmake_minimum_required(VERSION 2.8)
FIND_PACKAGE(ParaView REQUIRED)
INCLUDE(${PARAVIEW_USE_FILE})
ADD_PARAVIEW_PLUGIN(MyReader "1.0"
  SERVER_MANAGER_XML MyReader.xml
  SERVER_MANAGER_SOURCES MyReader.cxx
  GUI_RESOURCE_FILES MyReaderGUI.xml)


</source>
</source>

Revision as of 13:07, 7 January 2011

This example shows how to turn a custom VTK reader into a ParaView Reader filter. In this example we do not actually read a file, but instead generate data (so this is really a source, not a reader, but this is simply to make it easier to try the example - the structure is setup as a reader). That is, once you load the plugin in ParaView, you must go to File -> Open and select a ".abc" file (the file can be empty). This is the file that would be read if the reader actually did some reading! You should see a single point/vertex in the resulting PolyData object.

MyReader.h

<source lang="cpp">

  1. ifndef __MyReader_h
  2. define __MyReader_h
  1. include "vtkPolyDataAlgorithm.h"

class MyReader : public vtkPolyDataAlgorithm { public:

 vtkTypeMacro(MyReader,vtkPolyDataAlgorithm);
 void PrintSelf(ostream& os, vtkIndent indent);
 static MyReader *New();
 // Description:
 // Specify file name of the .abc file.
 vtkSetStringMacro(FileName);
 vtkGetStringMacro(FileName);
 

protected:

 MyReader();
 ~MyReader(){}
 int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *);

private:

 MyReader(const MyReader&);  // Not implemented.
 void operator=(const MyReader&);  // Not implemented.
 char* FileName;

};

  1. endif

</source>

MyReader.cxx

<source lang="cpp">

  1. include "MyReader.h"
  1. include "vtkObjectFactory.h"
  2. include "vtkStreamingDemandDrivenPipeline.h"
  3. include "vtkInformationVector.h"
  4. include "vtkInformation.h"
  5. include "vtkDataObject.h"
  6. include "vtkSmartPointer.h"
  7. include "vtkVertexGlyphFilter.h"

vtkStandardNewMacro(MyReader);

MyReader::MyReader() {

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

}

int MyReader::RequestData(

 vtkInformation *vtkNotUsed(request),
 vtkInformationVector **vtkNotUsed(inputVector),
 vtkInformationVector *outputVector)

{

 // get the info object
 vtkInformation *outInfo = outputVector->GetInformationObject(0);
 // get the ouptut
  vtkPolyData *output = vtkPolyData::SafeDownCast(
           outInfo->Get(vtkDataObject::DATA_OBJECT()));
 // Here is where you would read the data from the file. In this example,
 // we simply create a point.
 vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
 points->InsertNextPoint(0.0, 0.0, 0.0);
 polydata->SetPoints(points);
 vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter =
   vtkSmartPointer<vtkVertexGlyphFilter>::New();
 glyphFilter->SetInputConnection(polydata->GetProducerPort());
 glyphFilter->Update();
 output->ShallowCopy(glyphFilter->GetOutput());
 return 1;

}

void MyReader::PrintSelf(ostream& os, vtkIndent indent) {

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

}


</source>

MyReader.xml

<source lang="xml"> <ServerManagerConfiguration>

 <ProxyGroup name="sources">
   <SourceProxy name="MyReader" class="MyReader" label="MyReader">
     <Documentation
        long_help="Read a .abc file."
        short_help="Read a .abc file.">
     </Documentation>
     <StringVectorProperty
           name="FileName"
           animateable="0"
           command="SetFileName"
           number_of_elements="1">
       <FileListDomain name="files"/>
       <Documentation>
         This property specifies the file name for the PNG reader.
       </Documentation>
     </StringVectorProperty>
     <Hints>
       <ReaderFactory extensions="abc"
                      file_description="Example File Format" />
    </Hints>
   </SourceProxy>
 </ProxyGroup>

</ServerManagerConfiguration> </source>

MyReaderGUI.xml

<source lang="xml"> <ParaViewReaders>

 <Reader name="MyReader" extensions="abc"

file_description="Example (.abc) Files">

 </Reader>

</ParaViewReaders> </source>

CMakeLists.txt

<source lang="cmake"> cmake_minimum_required(VERSION 2.8)

FIND_PACKAGE(ParaView REQUIRED) INCLUDE(${PARAVIEW_USE_FILE})

ADD_PARAVIEW_PLUGIN(MyReader "1.0"
  SERVER_MANAGER_XML MyReader.xml
  SERVER_MANAGER_SOURCES MyReader.cxx
  GUI_RESOURCE_FILES MyReaderGUI.xml)


</source>