Creation of a vtkPolyData child class


(Patrick Laurin) #1

Hello dear developers,

I’m having a hard time showing a custom-built data set in the information panel of ParaView. This custom dataset is a child of vtkPolyData in the form of:

    class MODULE_EXPORT meshDataSet : public vtkPolyData
    {
    public:
	    static meshDataSet *New();

	    vtkTypeMacro(meshDataSet, vtkPolyData);
	    void PrintSelf(ostream& os, vtkIndent indent) override;

	    /**
	    * Datasets are composite objects and need to check each part for MTime
	    * THIS METHOD IS THREAD SAFE
	    */
	    vtkMTimeType GetMTime() override;

	    /**
	    * Return the type of data object.
	    */
	    int GetDataObjectType() override { return MESH_DATA_SET; }
	    
    protected:
	    // Constructor with default bounds (0,1, 0,1, 0,1).
	    meshDataSet();
	    ~meshDataSet() override;

    private:
	    meshDataSet(const meshDataSet&) = delete;
	    void operator=(const meshDataSet&) = delete;
	    };

This almost works. I had to modify Common/Core/vtkType.h to include my new data type:

Link: https://gitlab.kitware.com/vtk/vtk/blob/master/Common/Core/vtkType.h

    #define VTK_PISTON_DATA_OBJECT  34
    #define VTK_PATH  35
    #define VTK_UNSTRUCTURED_GRID_BASE  36
    #define VTK_PARTITIONED_DATA_SET  37
    #define VTK_PARTITIONED_DATA_SET_COLLECTION  38
    #define MESH_DATA_SET  39

(I feel like another approach would be better here since more datatypes will be added in the future.)

Now, I created another class called “MeshReader”, a source proxy, which does nothing except initializing an object through a single output port in the ParaView pipeline:

    [...]
    //----------------------------------------------------------------------------
    int MeshReader::RequestData(
    	vtkInformation* vtkNotUsed(request),
    	vtkInformationVector** vtkNotUsed(inputVector),
    	vtkInformationVector* outputVector)
    {
    	vtkInformation* outInfo0 = outputVector->GetInformationObject(0);
    	meshDataSet *output = meshDataSet::SafeDownCast(
            outInfo0->Get(vtkDataObject::DATA_OBJECT()));
    }

    //----------------------------------------------------------------------------
    int MeshReader::FillOutputPortInformation(
    	int vtkNotUsed(port), vtkInformation* info)
    {
    	info->Set(vtkDataObject::DATA_TYPE_NAME(), "meshDataSet");
    	return 1;
    }

Then, I added a new vtkDataObjectType:

Link: https://gitlab.kitware.com/vtk/vtk/blob/master/Common/DataModel/vtkDataObjectTypes.cxx

  else if(strcmp(type, "vtkMolecule") == 0)
  {
    return vtkMolecule::New();
  }
  else if(strcmp(type, "vtkArrayData") == 0)
  {
    return vtkArrayData::New();
  }
  else if(strcmp(type, "vtkPath") == 0)
  {
    return vtkPath::New();
  }
  else if(strcmp(type, "vtkPartitionedDataSet") == 0)
  {
    return vtkPartitionedDataSet::New();
  }
  else if(strcmp(type, "vtkPartitionedDataSetCollection") == 0)
  {
    return vtkPartitionedDataSetCollection::New();
  }
  else if (strcmp(type, "meshDataSet") == 0)**
  {
	vtkStringArray* meshDataSetInfo = vtkStringArray::New();
	meshDataSetInfo->SetName("meshDataSet");
	meshDataSetInfo->InsertNextValue("meshDataSet");

	vtkPolyData* meshDataSet = vtkPolyData::New();
	meshDataSet->GetFieldData()->AddArray(meshDataSetInfo);

	return meshDataSet;
  }

Here, I used a StringArray to differentiate it from a usual vtkPolyData because I can’t link my meshDataSet.cxx class with vtkDataObjectTypes.cxx in CMake.

To be able to show “meshDataSet” in the information panel, I added my own detector:

Link: https://github.com/Kitware/ParaView/blob/master/ParaViewCore/ClientServerCore/Core/vtkPVDataInformation.cxx

  int dataType = this->DataSetType;
  if (this->CompositeDataSetType >= 0)
  {
    dataType = this->CompositeDataSetType;
  }

  // Custom types
  if (this->FieldDataInformation->GetNumberOfArrays() > 0)
  {
	  if (this->FieldDataInformation->GetArrayInformation("meshDataSet"))
		  return "Mesh Dataset";
  }

  switch (dataType)
  {
    case VTK_POLY_DATA:
      return "Polygonal Mesh";
    [...]

This code is able to show me “Mesh Dataset” in the Information Panel when I instantiate my “MeshReader”, but as soon as I press “Apply” in the properties panel, the data type switches to “Polygonal Mesh”. What could be wrong about this approach? Am I forced to link vtkDataObjectTypes.cxx with meshDataSet.cxx?

Thank you,

Patrick


(Patrick Laurin) #2

Nevermind!