ParaView/Examples/Plugins/Reader: Difference between revisions
Daviddoria (talk | contribs) No edit summary |
No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
<span style="color:red">'''OUT OF DATE'''</span> | |||
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. | 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. | ||
Latest revision as of 10:34, 8 January 2016
OUT OF DATE
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">
- 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>
MyReader.cxx
<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>
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>