<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    Hi Cory,<br>
    <br>
    thanks for the reply.<br>
    <br>
    When you run the provided code with the provided data, the
    interpolation for the int data ultimately happens in
    vtkDataArray::InterpolateEdge, ln 520, which in turn calls
    vtkDataArrayInterpolateTuple, ln 103. This one performs a
    multiplication with double and then casts back to the type Scalar,
    it does not round the final interpolant. The overload above it does
    tho, but it's not called.<br>
    <br>
    Hope that helps,<br>
    Bengt<br>
    <br>
    <div class="moz-cite-prefix">Am 23.07.2015 um 15:30 schrieb Cory
      Quammen:<br>
    </div>
    <blockquote
cite="mid:CAB5Fpx7bQbCvAu_h0dnda15JBKVUZ7cuDWwqKwAVV1yh_yL-nw@mail.gmail.com"
      type="cite">
      <div dir="ltr">Bengt,
        <div><br>
        </div>
        <div>From what I can tell looking at the interpolating code in
          vtkDataArray.cxx, it looks like integer types should be
          rounded, and it looks like this support has been in VTK for a
          long time. Can you point out where in VTK you are seeing the
          casting back to integer type instead of rounding? You may have
          discovered a bug.</div>
        <div><br>
        </div>
        <div>Thanks,</div>
        <div>Cory</div>
      </div>
      <div class="gmail_extra"><br>
        <div class="gmail_quote">On Wed, Jul 22, 2015 at 6:05 PM, Bengt
          Rosenberger <span dir="ltr"><<a moz-do-not-send="true"
              href="mailto:bengt@ctech.com" target="_blank">bengt@ctech.com</a>></span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello
            everyone!<br>
            <br>
            Sorry if this may appear twice on the mailing list, the
            first time I've submitted this the attachment prevented this
            to show up. This time I'll provide a link to my DropBox for
            the data.<br>
            <br>
            Anyway, we encountered an issue with vtkContourFilter.
            Specifically, we have an unstructured grid containing the
            data to contour with and an additional vtkIntArray. The data
            in the int array is supposed to be of all the same value, in
            this case 3. However, after running the field through the
            contour filter, the int data contains values of 2 as well.<br>
            <br>
            After digging deeper into the VTK code, we discovered that
            the data for the int array is cast to double, interpolated
            and then cast back to int.<br>
            <br>
            So my question is:<br>
            Why aren't the data values being rounded after
            interpolation, but instead just cast back to int? Is there a
            way to enable rounding or copying for only a single array in
            the grid?<br>
            <br>
            Thank you!<br>
            <br>
            Here's the data: <a moz-do-not-send="true"
              href="https://dl.dropboxusercontent.com/u/16837761/test1.7z"
              rel="noreferrer" target="_blank">https://dl.dropboxusercontent.com/u/16837761/test1.7z</a><br>
            And here's the code we used for testing:<br>
            <br>
            #include <cstdint><br>
            #include <vtkSmartPointer.h><br>
            #include <vtkUnstructuredGrid.h><br>
            #include <vtkCellArray.h><br>
            #include <vtkContourFilter.h><br>
            #include <vtkPointData.h><br>
            #include <vtkXMLUnstructuredGridReader.h><br>
            <br>
            // Checks whether the geo_layer values are all constant<br>
            void check_geo_layer(vtkDataSet* ds)<br>
            {<br>
                if (ds->GetNumberOfCells() == 0)<br>
                {<br>
                    assert(false);<br>
                }<br>
            <br>
                vtkDataArray* geoLayerData =
            ds->GetPointData()->GetArray("Geo_Layer");<br>
            <br>
                double geoLayer =
            geoLayerData->GetComponent(ds->GetCell(0)->GetPointId(0),
            0);<br>
                for (uint32_t i = 0; i < ds->GetNumberOfCells();
            ++i)<br>
                {<br>
                    vtkCell* c = ds->GetCell(i);<br>
                    for (uint32_t j = 0; j <
            c->GetNumberOfPoints(); ++j)<br>
                    {<br>
                        double gl =
            geoLayerData->GetComponent(c->GetPointId(j), 0);<br>
                        if (gl != geoLayer)<br>
                        {<br>
                            assert(false);<br>
                        }<br>
                    }<br>
                }<br>
            }<br>
            <br>
            template <class T><br>
            void check_geo_layer(vtkSmartPointer<T> vtkFilter)<br>
            {<br>
                vtkFilter->Update();<br>
                auto result = vtkFilter->GetOutput();<br>
                vtkDataSet* ds = vtkDataSet::SafeDownCast(result);<br>
            <br>
                check_geo_layer(ds);<br>
            }<br>
            <br>
            int _tmain(int argc, _TCHAR* argv[])<br>
            {<br>
                // Read the test field<br>
                // Field has one vtkDoubleArray ("TOTHC") and one
            vtkIntArray ("Geo_Layer")<br>
                vtkSmartPointer<vtkXMLUnstructuredGridReader>
            reader =
            vtkSmartPointer<vtkXMLUnstructuredGridReader>::New();<br>
                reader->SetFileName("C:\\test1.vtk");<br>
                reader->Update();<br>
                vtkDataSet* g1 = reader->GetOutputAsDataSet();<br>
            <br>
                // Values in Geo_Layer are supposed to be all 3's. Check
            that now for the input.<br>
                check_geo_layer(g1);<br>
            <br>
                const double isoValue = 0.98712348937988281;<br>
            <br>
                vtkSmartPointer<vtkContourFilter> contour =
            vtkContourFilter::New();<br>
                contour->SetInputData(g1);<br>
                contour->ReleaseDataFlagOn();<br>
                contour->GenerateTrianglesOn();<br>
                contour->ComputeGradientsOff();<br>
                contour->ComputeNormalsOff();<br>
                contour->ComputeScalarsOff();<br>
                contour->SetNumberOfContours(1);<br>
                contour->SetValue(0, isoValue);<br>
                contour->SetInputArrayToProcess(0, 0, 0,
            vtkDataObject::FIELD_ASSOCIATION_POINTS, "TOTHC");<br>
            <br>
                // Check again whether values in Geo_Layer are only 3's.<br>
                // PROBLEM: They are not. There are 2's in there as
            well, which occur from interpolating integers and not
            rounding in the end.<br>
                //            You can see the problem if you convert
            Geo_Layer to a vtkDoubleArray, in which case values of
            2.9999999998 may appear after contouring.<br>
                check_geo_layer(contour);<br>
            <br>
                std::cin.ignore();<br>
            }<br>
            _______________________________________________<br>
            Powered by <a moz-do-not-send="true"
              href="http://www.kitware.com" rel="noreferrer"
              target="_blank">www.kitware.com</a><br>
            <br>
            Visit other Kitware open-source projects at <a
              moz-do-not-send="true"
              href="http://www.kitware.com/opensource/opensource.html"
              rel="noreferrer" target="_blank"><a class="moz-txt-link-freetext" href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a></a><br>
            <br>
            Please keep messages on-topic and check the VTK FAQ at: <a
              moz-do-not-send="true"
              href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer"
              target="_blank"><a class="moz-txt-link-freetext" href="http://www.vtk.org/Wiki/VTK_FAQ">http://www.vtk.org/Wiki/VTK_FAQ</a></a><br>
            <br>
            Search the list archives at: <a moz-do-not-send="true"
              href="http://markmail.org/search/?q=vtkusers"
              rel="noreferrer" target="_blank">http://markmail.org/search/?q=vtkusers</a><br>
            <br>
            Follow this link to subscribe/unsubscribe:<br>
            <a moz-do-not-send="true"
              href="http://public.kitware.com/mailman/listinfo/vtkusers"
              rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/vtkusers</a><br>
          </blockquote>
        </div>
        <br>
        <br clear="all">
        <div><br>
        </div>
        -- <br>
        <div class="gmail_signature">Cory Quammen<br>
          R&D Engineer<br>
          Kitware, Inc.</div>
      </div>
    </blockquote>
    <br>
  </body>
</html>