<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-15">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    I am trying for some days now to plot a vector field from a vtu file
    where some "arrays/data" are in.<br>
    <br>
    My problem is similar to:     
<a class="moz-txt-link-freetext" href="http://vtk.1045678.n5.nabble.com/Visualizing-a-vector-field-from-a-vtkImageData-td4792007.html">http://vtk.1045678.n5.nabble.com/Visualizing-a-vector-field-from-a-vtkImageData-td4792007.html</a><br>
    <br>
    I translated the following examples into java and they work.<br>
<a class="moz-txt-link-freetext" href="http://www.vtk.org/Wiki/VTK/Examples/CSharp/PolyData/VectorFieldNonZeroExtraction">http://www.vtk.org/Wiki/VTK/Examples/CSharp/PolyData/VectorFieldNonZeroExtraction</a><br>
<a class="moz-txt-link-freetext" href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/WishList/Visualization/VectorField">http://www.vtk.org/Wiki/VTK/Examples/Cxx/WishList/Visualization/VectorField</a><br>
    <br>
    But if i try to visualize the field from the vtu file the vector are
    all paralell to the x-axis<br>
    <meta http-equiv="content-type" content="text/html;
      charset=ISO-8859-15">
    and neither of the vectors in the file are parallel to the x-axis
    (checked with ParaView).
    <br>
    <br>
    My Code is attached.<br>
    <br>
    <meta http-equiv="content-type" content="text/html;
      charset=ISO-8859-15">
    Any suggestions on how to get these glyphs to point in the direction
    specified by the data in the file?
    <br>
    <br>
    Thanks in advance,
    <br>
    Christian<br>
    <br>
    PS: Notice that the visualization class is a own written class that
    show the results.<br>
    <br>
     The console output:<br>
    <br>
    name of array[0]: c1<br>
    name of array[1]: c2<br>
    name of array[2]: SomeVector<br>
    name of array[3]: c<br>
    name of array[4]: Linker<br>
    name of array[5]: UserFct<br>
    name of array[6]: ElemDiscValue<br>
    name of array[7]: LuaFct<br>
    name of array[8]: ConstData<br>
    number of thresholded points: 0<br>
    <br>
    Value for the parameters: <br>
    <br>
    file = "path/to/file.vtu"<br>
    elementInFile = 2<br>
    threshold = 0.0001<br>
    <br>
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - <br>
    package edu.gcsc.vrl.vtk;<br>
    <br>
    import eu.mihosoft.vrl.annotation.ComponentInfo;<br>
    import eu.mihosoft.vrl.annotation.ParamInfo;<br>
    import java.io.File;<br>
    import java.io.Serializable;<br>
    import vtk.vtkActor;<br>
    import vtk.vtkArrowSource;<br>
    import vtk.vtkCubeSource;<br>
    import vtk.vtkGlyph3D;<br>
    import vtk.vtkPolyData;<br>
    import vtk.vtkPolyDataMapper;<br>
    import vtk.vtkThresholdPoints;<br>
    import vtk.vtkUnstructuredGrid;<br>
    import vtk.vtkXMLUnstructuredGridReader;<br>
    <br>
    public class VectorFieldExample implements Serializable {<br>
    <br>
        private static final long serialVersionUID = 1L;<br>
    <br>
        public Visualization VectorFieldNonZeroExtraction(<br>
                File file,<br>
                int elementInFile,<br>
                double threshold) {<br>
    <br>
            Visualization vis = new Visualization();<br>
    <br>
    <br>
    //        // Create an image<br>
    //        vtkImageData image = new vtkImageData();<br>
    //        <br>
    //        CreateVectorField(image);<br>
    <br>
            vtkXMLUnstructuredGridReader reader = new
    vtkXMLUnstructuredGridReader();<br>
    <br>
    //            System.out.println("-- reader = "+ reader);<br>
            reader.SetFileName(file.getAbsolutePath());<br>
            reader.Update();<br>
            vtkUnstructuredGrid image = reader.GetOutput();<br>
    <br>
    <br>
    //        // This filter produces a vtkImageData with an array named
    "Magnitude"<br>
    //        vtkImageMagnitude magnitudeFilter = new
    vtkImageMagnitude();<br>
    //       
    magnitudeFilter.SetInputConnection(image.GetProducerPort());<br>
    //        magnitudeFilter.Update();<br>
    //<br>
    //       
image.GetPointData().AddArray(magnitudeFilter.GetOutput().GetPointData().GetScalars());<br>
    //        image.GetPointData().SetActiveScalars("Magnitude");<br>
    <br>
            vtkThresholdPoints thresholdVector = new
    vtkThresholdPoints();<br>
            thresholdVector.SetInput(image);<br>
            thresholdVector.SetInputArrayToProcess(<br>
                    elementInFile,<br>
                    image.GetInformation());<br>
    <br>
            thresholdVector.ThresholdByUpper(threshold);<br>
            thresholdVector.Update();<br>
    <br>
            // in case you want to save imageData<br>
            //vtkXMLPolyDataWriter writer = vtkXMLPolyDataWriter.New();<br>
            //writer.SetFileName("output.vtp");<br>
           
    //writer.SetInputConnection(thresholdPoints.GetOutputPort());<br>
            //writer.Write();<br>
    <br>
            // repesents the pixels<br>
            vtkCubeSource cubeSource = new vtkCubeSource();<br>
            cubeSource.SetXLength(0.01);<br>
            cubeSource.SetYLength(0.01);<br>
            cubeSource.SetZLength(0.01);<br>
    <br>
            vtkGlyph3D glyph = new vtkGlyph3D();<br>
            glyph.SetInput(image);<br>
            glyph.SetSourceConnection(cubeSource.GetOutputPort());
    //show cubes<br>
            // don't scale glyphs according to any scalar data<br>
    //        glyph.SetScaleModeToDataScalingOff();<br>
    <br>
            vtkPolyDataMapper glyphMapper = new vtkPolyDataMapper();<br>
            glyphMapper.SetInputConnection(glyph.GetOutputPort());<br>
            // don't color glyphs according to scalar data<br>
    //        glyphMapper.ScalarVisibilityOff();<br>
    //        glyphMapper.SetScalarModeToDefault();<br>
            glyphMapper.SetScalarModeToUsePointData();<br>
    <br>
            vtkActor actor = new vtkActor();<br>
            actor.SetMapper(glyphMapper);<br>
            <br>
             vis.addActor(actor);<br>
            <br>
            <br>
            <br>
    <br>
            // represent vector field<br>
            vtkGlyph3D vectorGlyph = new vtkGlyph3D();<br>
            vtkArrowSource arrowSource = new vtkArrowSource();<br>
            vtkPolyDataMapper vectorGlyphMapper = new
    vtkPolyDataMapper();<br>
    <br>
            int n = image.GetPointData().GetNumberOfArrays();<br>
            for (int i = 0; i &lt; n; i++) {<br>
                System.out.println("name of array[" + i + "]: " +
    image.GetPointData().GetArrayName(i));<br>
            }<br>
    <br>
            vtkPolyData tmp = thresholdVector.GetOutput();<br>
            System.out.println("number of thresholded points: " +
    tmp.GetNumberOfPoints());<br>
    //       
    vectorGlyph.SetInputConnection(thresholdVector.GetOutputPort());<br>
    //       
    vectorGlyph.SetInputConnection(thresholdVector.GetOutputPort());<br>
    <br>
    //        vtkGlyph2D vectorfieldVector = new vtkGlyph2D();<br>
    //        <br>
    //        vectorfieldVector.SetInput(image);<br>
    //        vectorfieldVector.SetInputArrayToProcess(<br>
    //                elementInFile,<br>
    //                image.GetInformation());<br>
    //<br>
    //        <br>
    //        vectorfieldVector.Update();<br>
    <br>
            vectorGlyph.SetInputConnection(image.GetProducerPort());<br>
    <br>
    <br>
            // in case you want the point glyphs to be oriented
    according to <br>
            // scalar values in array "ImageScalars" uncomment the
    following line<br>
    //        image.GetPointData().SetActiveVectors("ImageScalars");<br>
    <br>
    //       
image.GetPointData().SetActiveVectors(image.GetPointData().GetArrayName(elementInFile));<br>
    <br>
           
    vectorGlyph.SetSourceConnection(arrowSource.GetOutputPort());<br>
            vectorGlyph.SetScaleModeToScaleByVector();<br>
            vectorGlyph.SetVectorModeToUseVector();<br>
            vectorGlyph.ScalingOn();<br>
            vectorGlyph.OrientOn();<br>
            vectorGlyph.SetInputArrayToProcess(<br>
                    1,<br>
                    image.GetInformation());<br>
    <br>
            vectorGlyph.SetScaleFactor(0.025);<br>
    <br>
            vectorGlyph.Update();<br>
    <br>
           
    vectorGlyphMapper.SetInputConnection(vectorGlyph.GetOutputPort());<br>
            vectorGlyphMapper.Update();<br>
    <br>
            vtkActor vectorActor = new vtkActor();<br>
            vectorActor.SetMapper(vectorGlyphMapper);<br>
    <br>
    <br>
            vis.addActor(vectorActor);<br>
    <br>
            return vis;<br>
        }<br>
       <br>
    }<br>
    <br>
    <br>
  </body>
</html>