# How to import a transfer function exported from ParaView into VTK?

**URL:** https://discourse.vtk.org/t/how-to-import-a-transfer-function-exported-from-paraview-into-vtk/5217
**Category:** Support
**Created:** [February 19, 2021, 8:24am UTC](https://discourse.vtk.org/t/how-to-import-a-transfer-function-exported-from-paraview-into-vtk/5217 "2021-02-19T08:24:51Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![acdemiralp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/acdemiralp/32/3035_2.png) [@acdemiralp](https://discourse.vtk.org/u/acdemiralp)
#### Post date: [February 19, 2021, 8:24am UTC](https://discourse.vtk.org/t/how-to-import-a-transfer-function-exported-from-paraview-into-vtk/5217/1 "2021-02-19T08:24:51Z")

</div>

Dear all,

here is how I import a ParaView exported transfer function into VTK:

```cpp
class transfer_function
{
public:
  explicit transfer_function (const std::string& filepath)
  {
    std::ifstream file_stream(filepath);
    vtkJson::Reader reader;
    vtkJson::Value root;
    reader.parse(file_stream, root);

    std::vector<double> points ;
    std::vector<double> rgb_points;
    for (auto& iteratee : root["Points"]) points .push_back(iteratee.asFloat());
    for (auto& iteratee : root["RGBPoints"]) rgb_points.push_back(iteratee.asFloat());
    opacity_function->FillFromDataPointer(points .size(), points .data());
    color_function ->FillFromDataPointer(rgb_points.size(), rgb_points.data());
    color_function ->SetColorSpace (root["ColorSpace"].asInt());
  }
  transfer_function (const transfer_function& that) = default;
  transfer_function ( transfer_function&& temp) = default;
 ~transfer_function () = default;
  transfer_function& operator=(const transfer_function& that) = default;
  transfer_function& operator=( transfer_function&& temp) = default; 

  vtkSmartPointer<vtkPiecewiseFunction> opacity_function = vtkSmartPointer<vtkPiecewiseFunction> ::New();
  vtkSmartPointer<vtkColorTransferFunction> color_function = vtkSmartPointer<vtkColorTransferFunction>::New();
};

```

I then load up an unstructured volume exported from ParaView and set its color and opacity transfer functions.

```cpp
  ug_volume->GetProperty()->SetColor (transfer_function.color_function );
  ug_volume->GetProperty()->SetScalarOpacity(transfer_function.opacity_function);

```

Which makes the volume completely disappear. If I remove these two lines, the volume renders and is semi-transparent gray, meaning the default transfer function works.

Any ideas on what I’m doing wrong?
