コード例 #1
0
ファイル: VtkMeshConverter.cpp プロジェクト: envinf/ogs
void VtkMeshConverter::convertArray(vtkDataArray &array, MeshLib::Properties &properties, MeshLib::MeshItemType type)
{
    if (vtkDoubleArray::SafeDownCast(&array))
    {
        VtkMeshConverter::convertTypedArray<double>(array, properties, type);
        return;
    }

    if (vtkIntArray::SafeDownCast(&array))
    {
        VtkMeshConverter::convertTypedArray<int>(array, properties, type);
        return;
    }

    if (vtkUnsignedIntArray::SafeDownCast(&array))
    {
        // MaterialIDs are assumed to be integers
        if(std::strncmp(array.GetName(), "MaterialIDs", 11) == 0)
            VtkMeshConverter::convertTypedArray<int>(array, properties, type);
        else
            VtkMeshConverter::convertTypedArray<unsigned>(array, properties, type);

        return;
    }

    ERR ("Array \"%s\" in VTU file uses unsupported data type.", array.GetName());
    return;
}
コード例 #2
0
ファイル: VtkMeshConverter.cpp プロジェクト: LEONOB2014/ogs
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;
}