[vtkusers] Error Calculating Vector Field From Scalars (when using vtkArrayCalculator)

Bill Lorensen bill.lorensen at gmail.com
Fri Nov 21 15:49:49 EST 2014


Here is a working version.
#include "vtkSmartPointer.h"
#include "vtkTecplotReader.h"
#include "vtkArrayCalculator.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkUnstructuredGrid.h"
#include "vtkPointData.h"
#include "vtkDoubleArray.h"
#include "vtkFloatArray.h"

int main(int argc, char** argv)
{

  std::cout << "Loading tecplot file" << std::endl;
  vtkSmartPointer<vtkTecplotReader> reader =
    vtkSmartPointer<vtkTecplotReader>::New();
  reader->SetFileName("sphere.tec");
  reader->Update();

  std::cout << "Data arrays: " << std::endl;
  for (int i = 0; i < reader->GetNumberOfDataArrays(); ++i)
    {
    std::cout << "\t" << reader->GetDataArrayName(i) << std::endl;
    }
  std::cout << std::endl;

  std::cout << "Calculating vector field from scalars" << endl;
  vtkSmartPointer<vtkArrayCalculator> mag =
    vtkSmartPointer<vtkArrayCalculator>::New();
  mag->SetAttributeModeToUsePointData();
  mag->AddScalarArrayName("Mx");
  mag->AddScalarArrayName("My");
  mag->AddScalarArrayName("Mz");
  mag->SetFunction("Mx*iHat + My*jHat + Mz*kHat");
  mag->SetResultArrayName("mag");
  mag->SetInputData(reader->GetOutput()->GetBlock(0));
  mag->Update();

  vtkUnstructuredGrid * usg =
    vtkUnstructuredGrid::SafeDownCast(mag->GetOutput());

  vtkSmartPointer<vtkDoubleArray> magArray=
    vtkDoubleArray::SafeDownCast(
      usg->GetPointData()->GetArray("mag"));

  vtkSmartPointer<vtkFloatArray> mxArray=
    vtkFloatArray::SafeDownCast(
      usg->GetPointData()->GetArray("Mx"));

  vtkSmartPointer<vtkFloatArray> myArray=
    vtkFloatArray::SafeDownCast(
      usg->GetPointData()->GetArray("My"));

  vtkSmartPointer<vtkFloatArray> mzArray=
    vtkFloatArray::SafeDownCast(
      usg->GetPointData()->GetArray("Mz"));

  for(vtkIdType i = 0; i < magArray->GetNumberOfTuples(); i++)
    {
    double magVal[3];
    magArray->GetTuple(i, magVal);
    std::cout << i << ": "
              << mxArray->GetValue(i) << " , "
              << myArray->GetValue(i) << " , "
              << mzArray->GetValue(i) << " = "
              << "(" << magVal[0] << ", "
              << magVal[1] << ", "
              << magVal[2] << ")" << std::endl;
    }

  return EXIT_SUCCESS;
}


On Fri, Nov 21, 2014 at 4:40 AM, Lesleis Nagy <l.nagy at ed.ac.uk> wrote:
> Hello,
>
> Apologies, I just realised that I've posted this question multiple times to
> the list. I've been re-ordering my mailboxes and was only seeing responses
> from vtkusers-owner!
>
> Apologies again for spamming the list.
> Les
>
> On 21 Nov 2014, at 09:29, Lesleis Nagy <l.nagy at ed.ac.uk> wrote:
>
> Hello,
>
> I'm having some trouble calculating a vector field from a list of three
> scalars using the vtkArrayCalculator. When I attempt to run my program vtk
> gives me the following error message:
>
> ERROR: In /tmp/vtk5-Sa5a/VTK5.10.1/Filtering/vtkExecutive.cxx, line 756
> vtkStreamingDemandDrivenPipeline (0x7fe8b9426170): Algorithm
> vtkArrayCalculator(0x7fe8b9425150) returned failure for request:
> vtkInformation (0x7fe8b94263c0)
>   Debug: Off
>   Modified Time: 207
>   Reference Count: 1
>   Registered Events: (none)
>   Request: REQUEST_DATA_OBJECT
>   FORWARD_DIRECTION: 0
>   ALGORITHM_AFTER_FORWARD: 1
>
> I have included a minimal sample program which is based on the
> vtkArrayCalculator unit tests, along with a sample tecplot data file that
> reproduces the error in a zipped tar file (attached). Additionally I'm
> compiling my code on OSX 10.9.5 using the homebrew installation of VTK5 (if
> any more information is required regarding my platform please let me know).
> Could someone please offer any assistance/advice as to where I'm going
> wrong?
>
> Kind regards
> Lesleis Nagy
>
> <example.tar.gz>
> The University of Edinburgh is a charitable body, registered in
> Scotland, with registration number SC005336.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
>
>
> The University of Edinburgh is a charitable body, registered in
> Scotland, with registration number SC005336.
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>



-- 
Unpaid intern in BillsBasement at noware dot com


More information about the vtkusers mailing list