Need Help with StreamTracer using vtkMultiBlockDataSet

Hello everyone

I’m trying to create StreamTracer from an CASE file.
So far I’ve created StreamTracer from each block and combine them in a single file to render later but the result doesn’t seams correct and I’m pretty sure the way I’m doing it isn’t right.
I’m pretty sure I have to somehow combine all blocks and then create the StreamTracer but I don’t know how to do it.

Below is the code I’m using.
Could you please tell me what’s wrong\what need to be changed please?
Below code is assuming the array is a scalar and not a vector.

I really thank you in advance for your help

Best regards

private void RunStreamline()
{
    string FolderPath = System.IO.Path.GetDirectoryName(FilePath);
    string Filename = System.IO.Path.GetFileName(FilePath);


    vtkEnSightGoldBinaryReader reader = vtkEnSightGoldBinaryReader.New();
    reader.SetFilePath(FolderPath);
    reader.SetCaseFileName(Filename);
    reader.Update();

    List<vtkArrayCalculator> Calculators = new List<vtkArrayCalculator>();

    vtkMultiBlockDataSet dataset = reader.GetOutput();

    string TargetArrayName = "Static_Temperature";
    string Function = "iHat*" + TargetArrayName + "+jHat*" + TargetArrayName + "+kHat*" + TargetArrayName;

    uint TotalBlock = dataset.GetNumberOfBlocks();
    bool bGood = true;

    for (uint idxBlock = 0; idxBlock < TotalBlock; ++idxBlock)
    {
        vtkDataObject CurrentDataObjBlock = dataset.GetBlock(idxBlock);

        vtkCellDataToPointData c2p = vtkCellDataToPointData.New();
        c2p.SetInputData(CurrentDataObjBlock);
        c2p.Update();

        vtkPointData pointdata = c2p.GetOutput().GetPointData();

        int TotalArray = pointdata.GetNumberOfArrays();
        bGood = true;
		//CASE file seams to have some issue where sometimes Range at index 1 is lower than Range at index 0
        for (int IdxArray = 0; IdxArray < TotalArray; ++IdxArray)
        {
            string ArrayName = pointdata.GetArrayName(IdxArray);
            double[] CurrentRange = pointdata.GetArray(IdxArray).GetRange();
            if (CurrentRange[0] > CurrentRange[1])
            {
                bGood = false;
                continue;
            }
            double MinRangeVal = CurrentRange[0] < CurrentRange[1] ? CurrentRange[0] : CurrentRange[1];
            double MaxRangeVal = CurrentRange[0] > CurrentRange[1] ? CurrentRange[0] : CurrentRange[1];
            if (ArrayRange.ContainsKey(ArrayName))
            {
                double[] SelectedRange = ArrayRange[ArrayName];
                SelectedRange[0] = SelectedRange[0] < MinRangeVal ? SelectedRange[0] : MinRangeVal;
                SelectedRange[1] = SelectedRange[1] > MaxRangeVal ? SelectedRange[1] : MaxRangeVal;
                ArrayRange[ArrayName] = SelectedRange;
            }
            else
            {
                double[] NewRange = new double[2];
                NewRange[0] = MinRangeVal;
                NewRange[1] = MaxRangeVal;
                ArrayRange.Add(ArrayName, NewRange);
            }
        }
        if (bGood)
        {
            vtkArrayCalculator Calc = new vtkArrayCalculator();
            Calc.SetInputData(c2p.GetOutput());
            Calc.AddScalarArrayName(TargetArrayName, 0);
            Calc.SetFunction(Function);
            Calc.SetResultArrayName("output_res");
            Calc.Update();
            Calculators.Add(Calc);
        }
    }
    if (ArrayRange.Count == 0)
    {
        return;
    }
    CreateStreamline(Calculators);
}

private void CreateStreamline(List<vtkArrayCalculator> Calculators)
{
    int TotalCalculator = Calculators.Count;
    if (TotalCalculator == 0)
    {
        Debug.Log("no calculator found");
        return;
    }

    vtkPlaneSource PlaneSource = new vtkPlaneSource();
	//hard coded value for test purpose
    Vector3 Origin = new Vector3(0f, -1.88f, -0.35f);
    PlaneSource.SetOrigin(Origin.x, Origin.y, Origin.z);
    PlaneSource.SetPoint1(Origin.x, Origin.y, Origin.z + 0.01f);
    PlaneSource.SetPoint1(Origin.x+0.01f, Origin.y, Origin.z);
    PlaneSource.SetXResolution(10);
    PlaneSource.SetYResolution(10);
    PlaneSource.Update();

    string TargetArrayName = "output_res";

    double[] Range = null;

    for (int Index = 0; Index < TotalCalculator; ++Index)
    {
        vtkStreamTracer StreamTracer = vtkStreamTracer.New();
        StreamTracer.SetInputConnection(Calculators[Index].GetOutputPort());
        StreamTracer.SetSourceConnection(PlaneSource.GetOutputPort());
        StreamTracer.SetIntegratorTypeToRungeKutta45();

        StreamTracer.SetIntegrationDirectionToForward();
        StreamTracer.SetComputeVorticity(true);
        StreamTracer.SetMaximumPropagation(300);
        StreamTracer.SetInitialIntegrationStep(0.3);
        //WARNING: Set FIELD_NAME() so it can be processed by vtkAlgorithm
        vtkInformationVector inArrayVec = StreamTracer.GetInformation().Get(vtkAlgorithm.INPUT_ARRAYS_TO_PROCESS());

        vtkInformation inArrayInfo = inArrayVec.GetInformationObject(0);
        inArrayInfo.Set(vtkDataObject.FIELD_NAME(), TargetArrayName);
        StreamTracer.Update();

        vtkPolyData MyData = StreamTracer.GetOutput();
        StreamTracer.Update();
        MyData.BuildCells();
        MyData.BuildLinks(0);

        vtkPointData PointDatas = MyData.GetPointData();
        int NbArray = PointDatas.GetNumberOfArrays();
        vtkDataArray TargetArray = null;
        for (int Idx = 0; Idx < NbArray; ++Idx)
        {
            vtkDataArray TmpArray = PointDatas.GetArray(Idx);
            if (TmpArray.GetName().Equals(TargetArrayName))
            {
                TargetArray = TmpArray;
                break;
            }
        }

        if (TargetArray == null)
        {
            continue;
        }

        double[] CurrentRange = TargetArray.GetRange();
        if (Range == null)
        {
            Range = new double[2];
            Range[0] = CurrentRange[0];
            Range[1] = CurrentRange[1];
        }
        else
        {
            Range[0] = CurrentRange[0] < Range[0] ? CurrentRange[0] : Range[0];
            Range[1] = CurrentRange[1] > Range[1] ? CurrentRange[1] : Range[1];
        }
    }

    if (Range == null)
    {
        Debug.Log("no range found");
        return;
    }

    for (int Index = 0; Index < TotalCalculator; ++Index)
    {
        vtkStreamTracer StreamTracer = vtkStreamTracer.New();
        StreamTracer.SetInputConnection(Calculators[Index].GetOutputPort());
        StreamTracer.SetSourceConnection(PlaneSource.GetOutputPort());
        StreamTracer.SetIntegratorTypeToRungeKutta45();

        StreamTracer.SetIntegrationDirectionToForward();
        StreamTracer.SetComputeVorticity(true);
        StreamTracer.SetMaximumPropagation(300);//will be a parameter
        StreamTracer.SetInitialIntegrationStep(0.3);
        //WARNING: Set FIELD_NAME() so it can be processed by vtkAlgorithm
        vtkInformationVector inArrayVec = StreamTracer.GetInformation().Get(vtkAlgorithm.INPUT_ARRAYS_TO_PROCESS());

        vtkInformation inArrayInfo = inArrayVec.GetInformationObject(0);
        inArrayInfo.Set(vtkDataObject.FIELD_NAME(), TargetArrayName);
        StreamTracer.Update();

        vtkPolyData MyData = StreamTracer.GetOutput();
        StreamTracer.Update();
        MyData.BuildCells();
        MyData.BuildLinks(0);

        vtkPointData PointDatas = MyData.GetPointData();
        int NbArray = PointDatas.GetNumberOfArrays();
        vtkDataArray TargetArray = null;
        for (int Idx = 0; Idx < NbArray; ++Idx)
        {
            vtkDataArray TmpArray = PointDatas.GetArray(Idx);
            if (TmpArray.GetName().Equals(TargetArrayName))
            {
                TargetArray = TmpArray;
                break;
            }
        }

        if (TargetArray == null)
        {
            continue;
        }

        double[] CurrentRange = TargetArray.GetRange();

        vtkPoints Points = MyData.GetPoints();

        vtkCellArray Lines = MyData.GetLines();
        long TotalCells = Lines.GetNumberOfCells();

        vtkIdList IdList = vtkIdList.New();

        for (long CellIndex = 0; CellIndex < TotalCells; ++CellIndex)
        {
            MyData.GetCellPoints(CellIndex, IdList);

            long TotalIds = IdList.GetNumberOfIds();
            for (long IndexId = 0; IndexId < TotalIds; ++IndexId)
            {
                long VertexIndex = IdList.GetId(IndexId);

                double[] VertexPosition = Points.GetPoint(VertexIndex);
                double VertexValue = TargetArray.GetVariantValue(VertexIndex).ToDouble();

                //do something with position and value
            }

        }
    }
}