Hi,
I am adding a filter to paraview and I think the output object is instanciated twice.
Here is my little POC:
First take the example of a source filter here: https://examples.vtk.org/site/Cxx/Developers/AlgorithmSource/
Then add a simple Reader class for Test (imagine it is a file format):
class vtkTestReaderInternal;
class FILTERSPLUGIN_EXPORT vtkTestReader : public vtkTestAlgorithmSource
{
public:
static vtkTestReader *New();
vtkTypeMacro(vtkTestReader, vtkTestAlgorithmSource);
void PrintSelf(ostream &os, vtkIndent indent) final;
void AddFileName(const char *fname);
void ClearFileNames();
protected:
vtkTestReader();
~vtkTestReader() final;
private:
vtkTestReader(const vtkTestReader &) = delete;
void operator=(const vtkTestReader &) = delete;
vtkTestReaderInternal *Internal;
};
and
#include <vtkTestReader.h>
#include <algorithm>
#include <exception>
#include <iterator>
#include <limits>
#include <vtkDataObject.h>
#include <vtkObjectFactory.h>
#include "vtkCommand.h"
vtkStandardNewMacro(vtkTestReader);
struct vtkTestReaderInternal
{
using FileNamesType = std::vector<std::string>;
FileNamesType FileNames;
};
//----------------------------------------------------------------------------
vtkTestReader::vtkTestReader()
{
this->Internal = new vtkTestReaderInternal;
}
//----------------------------------------------------------------------------
vtkTestReader::~vtkTestReader()
{
delete this->Internal;
}
//----------------------------------------------------------------------------
void vtkTestReader::PrintSelf(ostream &os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//----------------------------------------------------------------------------
void vtkTestReader::AddFileName(const char *fname)
{
if (fname == nullptr || *fname == '\0')
{
return;
}
this->Internal->FileNames.emplace_back(fname);
this->Modified();
}
//----------------------------------------------------------------------------
void vtkTestReader::ClearFileNames()
{
this->Internal->FileNames.clear();
this->Modified();
}
and
<ServerManagerConfiguration>
<ProxyGroup name="sources">
<SourceProxy name="TestReader" class="vtkTestReader" label="test Reader">
<Hints>
<PipelineIcon name="CINEMA_MARK"/>
<View type="None"/>
<Display type="None"/>
<RepresentationType view="None"/>
</Hints>
<!-- File to load: -->
<StringVectorProperty name="FileName" clean_command="ClearFileNames" command="AddFileName" number_of_elements="1" repeat_command="1" label="Add File">
<FileListDomain name="files"/>
<Documentation>This property specifies the file name for the test reader.</Documentation>
<Hints>
<FileChooser extensions="test" file_description="test file to load"/>
</Hints>
</StringVectorProperty>
</ProxyGroup>
</ServerManagerConfiguration>
The vtkTest constructor is called twice:
- one time when I click on the source in the paraview GUI
- one time when I click on apply
I don’t understand why… Could someone explain me what I am doing wrong ?