Hello!<br>I have read in the mailing lists that you have done with a
reader plugin very well. So, I am wondering whether you can help me to
point out what's wrong with my code!<br>Thank you!<br>I have written a reader plugin, and I have installed into the
paraview source code. So, now I can find my custom extension file type
in the Open File dialog!<br>But Now, the plugin seems does NOT work
properly. When I try to open a sgn file which I defined, the ParaView
just crash. So, could you please check my code and find where I was
wrong!<br>
Thank you so much!!!<br><br>Here is my code:<br>vtkSgnReader.h<br>/*============================<div>=============================================<br>#ifndef __vtkSgnReader_h_<br>#define __vtkSgnReader_h_<br>
<br>#include "vtkImageAlgorithm.h"<br>
<br>class VTK_EXPORT vtkSgnReader : public vtkImageAlgorithm<br>{<br>public:<br> static vtkSgnReader *New();<br> vtkTypeRevisionMacro(vtkSgnReader, vtkImageAlgorithm);<br> virtual void PrintSelf(ostream& os, vtkIndent indent);<br>
<br> vtkSetStringMacro( FileName );<br> vtkGetStringMacro( FileName );<br><br> int ReadMetaData(vtkInformation *outInfo);<br>protected:<br> vtkSgnReader();<br> ~vtkSgnReader();<br> int RequestData(vtkInformation *, vtkInformationVector **,<br>
vtkInformationVector *);<br> int RequestInformation(vtkInformation *, vtkInformationVector **,<br> vtkInformationVector *);<br><br>public:<br> char *FileName;<br> //BTX<br> class vtkSgn;<br> vtkSgn* sgnfile;<br>
//ETX<br>private:<br> vtkSgnReader(const vtkSgnReader&); //Not implemented<br> void operator=(const vtkSgnReader&); //Not implemented<br>};<br>#endif<br>/*=========================================================================<br>
vtkSgnReader.cxx:<br>/*=========================================================================<br>#include "vtkSgnReader.h"<br>#include "vtkByteSwap.h"<br>#include "vtkDataArray.h"<br>#include "vtkShortArray.h"<br>
#include "vtkFieldData.h"<br>#include "vtkImageData.h"<br>#include "vtkInformation.h"<br>#include "vtkInformationVector.h"<br>#include "vtkObjectFactory.h"<br>#include "vtkPointData.h"<br>
#include "vtkStreamingDemandDrivenPipeline.h"<br><br>// Standard VTK Macros for vtkObject derived Classes<br>vtkCxxRevisionMacro(vtkSgnReader, "1.0");<br>vtkStandardNewMacro(vtkSgnReader);<br><br>class vtkSgnReader::vtkSgn<br>
{<br>public:<br> vtkSgn():m_Dx(NULL),m_Dy(NULL),m_Dz(NULL),m_SgnData(NULL)<br> {<br> }<br> ~vtkSgn()<br> {<br> delete []m_Dx;<br> delete []m_Dy;<br> delete []m_Dz;<br> delete []m_SgnData;<br>
}<br> .......<br>};<br>bool vtkSgnReader::vtkSgn::Readsgn(char* name)<br>{<br> ......<br> return true;<br>}<br><br>char* vtkSgnReader::vtkSgn::GetFileName() { return m_SgnName;}<br><br>short vtkSgnReader::vtkSgn::GetNx() { return m_Nx;}<br>
<br>short vtkSgnReader::vtkSgn::GetNy() { return m_Ny;}<br><br>short vtkSgnReader::vtkSgn::GetNz() { return m_Nz;}<br><br>short* vtkSgnReader::vtkSgn::GetData() { return m_SgnData;}<br>
<br>
vtkSgnReader::vtkSgnReader()<br>{ <br> this->SetNumberOfInputPorts(0);<br>}<br><br>vtkSgnReader::~vtkSgnReader()<br>{<br> this->SetFileName(0);<br>}<br>int vtkSgnReader::ReadMetaData(vtkInformation *outInfo)<br>
{<br> if (!sgnfile->Readsgn(FileName))<br> {<br> return 1;<br> }<br> int dim[3];<br> dim[0]=sgnfile->GetNx();<br> dim[1]=sgnfile->GetNy();<br> dim[2]=sgnfile->GetNz();<br> //Set the extent<br>
outInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(),<br> 0, dim[0]-1, 0, dim[1]-1, 0, dim[2]-1);<br> return 1;<br>}<br><br>int vtkSgnReader::RequestInformation(vtkInformation *, vtkInformationVector **,<br>
vtkInformationVector *outputVector)<br>{<br> vtkInformation *outInfo = outputVector->GetInformationObject(0);<br> return this->ReadMetaData(outInfo);<br><br>
}<br><br>int vtkSgnReader::RequestData(vtkInformation *, vtkInformationVector **,<br> vtkInformationVector *outputVector)<br>{<br> vtkInformation *outInfo = outputVector->GetInformationObject(0);<br>
vtkImageData *output = vtkImageData::GetData(outInfo);<br> int *extent = output->GetUpdateExtent();<br> int numPts=0;<br> int L, M, N;<br> if (!sgnfile->Readsgn(FileName))<br> {<br> return 1;<br>
}<br> int dim[3];<br> dim[0] = sgnfile->GetNx();<br> L = dim[0];<br> dim[1] = sgnfile->GetNy();<br> M = dim[1];<br> dim[2] = sgnfile->GetNz();<br> N = dim[2];<br> numPts = dim[0]*dim[1]*dim[2];<br>
output->SetExtent(extent);<br><br> double origin[3];<br> origin[0] = 0.0;<br> origin[1] = 0.0;<br> origin[2] = 0.0; <br> output->SetOrigin(origin);<br><br> double ar[3];<br> ar[0] = 1.0;<br>
ar[1] = 1.0;<br> ar[2] = 1.0;<br> output->SetSpacing(ar);<br><br> //set the scalar data<br> vtkShortArray *castkey = vtkShortArray::New();<br> castkey->SetName("casting_type");<br> castkey->SetNumberOfComponents(1);<br>
castkey->SetNumberOfTuples(numPts);<br> for (int i=0; i<L; i++) for (int j=0;j<M; j++) for (int k=0; k<N; k++)<br> { <br> int idx = i*M*N+j*N+k;<br> castkey->SetTupleValue(idx, &(sgnfile->GetData()[idx] )); <br>
}<br> output->GetPointData()->AddArray(castkey);<br> castkey->Delete(); <br> return 1;<br>}<br><br>void vtkSgnReader::PrintSelf(ostream& os, vtkIndent indent)<br>{<br> this->Superclass::PrintSelf( os, indent );<br>
}<br clear="all"><br>/*=========================================================================<br><br>These codes seems do NOT work with my own type file. Did I not write the code correctly?<br>Please help me out!<br>Thank you so much!<br>
<br>-Seven</div><br clear="all"><br>-- <br><a href="mailto:shenyanwen@gmail.com">shenyanwen@gmail.com</a><br>Mobile Phone:13476177952<br>Tel: 027-87558144<br>