void VtkMeshConverter::convertArray(vtkDataArray &array, MeshLib::Properties &properties, MeshLib::MeshItemType type) { vtkIdType const nTuples (array.GetNumberOfTuples()); int const nComponents (array.GetNumberOfComponents()); char const*const array_name (array.GetName()); vtkDoubleArray* double_array = vtkDoubleArray::SafeDownCast(&array); if (double_array) { boost::optional<MeshLib::PropertyVector<double> &> vec (properties.createNewPropertyVector<double>(array_name, type, nComponents)); if (!vec) { WARN("vtkDoubleArray %s could not be converted to PropertyVector.", array_name); return; } vec->reserve(nTuples*nComponents); double* data_array = static_cast<double*>(double_array->GetVoidPointer(0)); std::copy(&data_array[0], &data_array[nTuples*nComponents], std::back_inserter(*vec)); return; } vtkIntArray* int_array = vtkIntArray::SafeDownCast(&array); if (int_array) { boost::optional<MeshLib::PropertyVector<int> &> vec (properties.createNewPropertyVector<int>(array_name, type, nComponents)); if (!vec) { WARN("vtkFloatArray %s could not be converted to PropertyVector.", array_name); return; } vec->reserve(nTuples*nComponents); int* data_array = static_cast<int*>(int_array->GetVoidPointer(0)); std::copy(&data_array[0], &data_array[nTuples*nComponents], std::back_inserter(*vec)); return; } ERR ("Array \"%s\" in VTU file uses unsupported data type.", array.GetName()); return; }
QVariant DataArrayModel::data(const QModelIndex &index, int role) const { if(role == Qt::DisplayRole) { // This role returns the string that is displayed in the cells. if(dataArray != 0) { vtkIdType id = index.internalId(); double value = 0.; if(id < dataArray->GetNumberOfTuples()) value = dataArray->GetTuple1(id); QString s; s.sprintf(formatString.toStdString().c_str(), value); // See if we need to prepend a pick letter. QSize key(index.row(), index.column()); QMap<QSize,QString>::const_iterator it = selectedCellLabels.find(key); if(it != selectedCellLabels.end()) s = it.value() + QString("=") + s; return QVariant(s); } else if(rgrid != 0) { vtkIdType id = index.row(); vtkDataArray *arr = rgrid->GetPointData()->GetScalars(); if(arr == 0) arr = rgrid->GetCellData()->GetScalars(); double value = 0.; if(index.column() == 0) value = rgrid->GetXCoordinates()->GetTuple1(id); else value = arr->GetTuple1(id); QString s; s.sprintf(formatString.toStdString().c_str(), value); return QVariant(s); } } else if(role == GetDataRole) { // This role returns the actual data so we can use it in various operations. if(dataArray != 0) { vtkIdType id = index.internalId(); double value = 0.; if(id < dataArray->GetNumberOfTuples()) value = dataArray->GetTuple1(id); return QVariant(value); } else if(rgrid != 0) { vtkIdType id = index.row(); vtkDataArray *arr = rgrid->GetPointData()->GetScalars(); if(arr == 0) arr = rgrid->GetCellData()->GetScalars(); double value = 0.; if(index.column() == 0) value = rgrid->GetXCoordinates()->GetTuple1(id); else value = arr->GetTuple1(id); return QVariant(value); } } else if(role == Qt::BackgroundRole) { // This role returns the background brush: gray for ghost, // pinkish gray for missing data, default otherwise. if(ghostArray != 0) { vtkIdType id = index.internalId(); // By convention, the ghost zones array contains unsigned char. const unsigned char *ghosts = (const unsigned char *)ghostArray-> GetVoidPointer(0); if(id < ghostArray->GetNumberOfTuples() && ghosts[id] > 0) return QVariant(QBrush(QColor(200,200,200))); } else if(missingDataArray != 0) { vtkIdType id = index.internalId(); // By convention, the missing data array contains unsigned char. const unsigned char *missingData = (const unsigned char *)missingDataArray->GetVoidPointer(0); if(id < missingDataArray->GetNumberOfTuples() && missingData[id] > 0) return QVariant(QBrush(QColor(255,200,200))); } } return QVariant(); }