# Creation of a vtkPolyData child class

**URL:** https://discourse.paraview.org/t/creation-of-a-vtkpolydata-child-class/702
**Category:** Development
**Created:** [October 10, 2018, 9:11pm UTC](https://discourse.paraview.org/t/creation-of-a-vtkpolydata-child-class/702 "2018-10-10T21:11:32Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![HollowSun0](https://discourse.paraview.org/user_avatar/discourse.paraview.org/hollowsun0/32/431_2.png) [@HollowSun0](https://discourse.paraview.org/u/HollowSun0)
#### Post date: [October 10, 2018, 9:11pm UTC](https://discourse.paraview.org/t/creation-of-a-vtkpolydata-child-class/702/1 "2018-10-10T21:11:32Z")

</div>

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:

```auto
    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](https://gitlab.kitware.com/vtk/vtk/blob/master/Common/Core/vtkType.h)

```auto
    #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:

```auto
    [...]
    //----------------------------------------------------------------------------
    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](https://gitlab.kitware.com/vtk/vtk/blob/master/Common/DataModel/vtkDataObjectTypes.cxx)

```auto
  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](https://github.com/Kitware/ParaView/blob/master/ParaViewCore/ClientServerCore/Core/vtkPVDataInformation.cxx)

```auto
  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

---

<div class="post-metadata">

### Author: ![HollowSun0](https://discourse.paraview.org/user_avatar/discourse.paraview.org/hollowsun0/32/431_2.png) [@HollowSun0](https://discourse.paraview.org/u/HollowSun0)
#### Post date: [October 15, 2018, 12:48am UTC](https://discourse.paraview.org/t/creation-of-a-vtkpolydata-child-class/702/2 "2018-10-15T00:48:02Z")

</div>

Nevermind!
