HowToIntegrateNewReaderWriter

From user's Wiki!
Jump to: navigation, search

This page provides you some tips on how to add new readers/writers to Gimias framework.

You can read more in Extensible Input and Output Component.

Steps

1. Create the class for the Reader/Writer

2. Register it into your plugin

Remark: If you want to enable your reader/writer you will have to load the plugin where you registered it

Create class for the Reader

The header file will look like this:

#ifndef MyFileReader_H 
#define MyFileReader_H 

#include "coreBaseDataEntityReader.h"

/**  
\sa DataEntityReader
\author "author"
\date "date"
*/
class  MyFileReader : public Core::IO::BaseDataEntityReader
{
public:
	coreDeclareSmartPointerClassMacro(MyFileReader, BaseDataEntityReader);

	void ReadData();

protected:
	MyFileReader(void);
	virtual ~MyFileReader(void);

	boost::any ReadSingleTimeStep(
		int iTimeStep,
		const std::string &filename);
	

private:
	coreDeclareNoCopyConstructors(MyFileReader);
};

#endif //MyFileReader_H 

in the .cxx file you have to define the extensions for your reader like this and the type of dataEntity that it will give:

m_ValidExtensionsList.push_back(".ext1");
m_ValidExtensionsList.push_back(".ext2");
m_ValidTypesList.push_back(Core::ImageTypeId);

The dataEntityTypes can me more than one. Tipically you will have to implement the ReadData() function like this:

Core::DataEntityType dataEntityType;
[...] read or choose the dataEntity type from the file
// build the data entity
ReadAllTimeSteps( Core::VolumeMeshTypeId );

and you will have to implement the ReadSingleTimeStep(...) in order to return the C++ object that is the implementation of your dataEntity ( look at table here)

You can find an example in the classes: Core::IO::VTKUnstructuredGridReader, Core::IO::VTKPolyDataReader or Core::IO::VTKImageDataReader.

Create class for the Writer

#ifndef MyFileWriter_H
#define MyFileWriter_H

#include "coreBaseDataEntityWriter.h"
/** 
\sa DataEntityWriter
\author "author"
\date "date"
*/
class  MyFileWriter : public Core::IO::BaseDataEntityWriter
{
public:
	coreDeclareSmartPointerClassMacro(MyFileWriter, BaseDataEntityWriter);

	virtual void WriteData();

protected:
	MyFileWriter(void);
	virtual ~MyFileWriter(void);

private:
	coreDeclareNoCopyConstructors(MyFileWriter);
};
 #endif //MyFileWriter_H

in the .cxx file you have to define the extensions for your writer like this and the type of dataEntity that it will accept as input:

m_ValidExtensionsList.push_back(".ext1");
m_ValidExtensionsList.push_back(".ext2");
m_ValidTypesList.push_back(Core::ImageTypeId);

The function WriteData() will look like this:

void VTKImageDataWriter::WriteData()
{
	WriteAllTimeSteps( );
}

You can find an example in the classes: Core::IO::VTKUnstructuredGridWriter, Core::IO::VTKPolyDataWriter or Core::IO::VTKImageDataWriter.

Register the Reader/Writer

You can register the Reader and Writer in your own plugin in the file "*ProcessorCollective.cxx" in the constructor you can add:

#include "coreDataEntityReader.h"
#include "coreDataEntityWriter.h"
#include "MyFileReader.h"
#include "MyFileWriter.h"

ProcessorCollective::ProcessorCollective(){
	Core::IO::DataEntityReader::RegisterFormatReader( 
		Core::IO::BaseDataEntityReader::Pointer(MyFileReader::New()) );
	Core::IO::DataEntityWriter::RegisterFormatWriter( 
		Core::IO::BaseDataEntityWriter::Pointer(MyFileWriter::New()) );
}

ProcessorCollective::~ProcessorCollective(){

	Core::IO::DataEntityReader::UnRegisterFormatReader( 
		DataEntityReader::GetRegisteredReader( MyFileReader::GetNameClass() ) );

	Core::IO::DataEntityWriter::UnRegisterFormatWriter( 
		DataEntityWriter::GetRegisteredWriter( MyFileWriter::GetNameClass()) );

}

Go back to Developers