Example #1
0
DataObject::DataObject(const QString & name, vtkDataSet * dataSet)
    : d_ptr{ std::make_unique<DataObjectPrivate>(*this, name, dataSet) }
{
    setObjectName(name);

    if (dataSet)
    {
        connectObserver("dataChanged", *dataSet, vtkCommand::ModifiedEvent,
            *this, &DataObject::signal_dataChanged);

        connectObserver("attributeArraysChanged", *dataSet->GetPointData(),
            vtkCommand::ModifiedEvent, *this, &DataObject::signal_attributeArraysChanged);
        connectObserver("attributeArraysChanged", *dataSet->GetCellData(),
            vtkCommand::ModifiedEvent, *this, &DataObject::signal_attributeArraysChanged);
        connectObserver("attributeArraysChanged", *dataSet->GetFieldData(),
            vtkCommand::ModifiedEvent, *this, &DataObject::signal_attributeArraysChanged);

        bool resetName = true;
        auto fieldData = dataSet->GetFieldData();
        if (auto nameArray = fieldData->GetAbstractArray(nameAttributeName()))
        {
            const auto storedName = vtkArrayToQString(*nameArray);
            resetName = name != storedName;
        }

        if (resetName)
        {
            fieldData->RemoveArray(nameAttributeName());
            vtkSmartPointer<vtkCharArray> newArray = qstringToVtkArray(name);
            newArray->SetName(nameAttributeName());
            fieldData->AddArray(newArray);
        }
    }
}
Example #2
0
vtkSmartPointer<vtkCharArray> qstringToVtkArray(const QString & string)
{
    auto array = vtkSmartPointer<vtkCharArray>::New();

    qstringToVtkArray(string, *array);

    return array;
}