<div dir="ltr">Awesome! Thanks in advance for contributing!<div><br></div><div>Cory</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jul 23, 2015 at 2:34 PM, Bengt Rosenberger <span dir="ltr"><<a 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">
  
    
  
  <div text="#000000" bgcolor="#FFFFFF">
    Cory,<br>
    <br>
    I can confirm a call to vtkDataArrayRoundIfNecessary fixes the
    issue. I will prepare and submit a patch.<br>
    <br>
    Thank you,<br>
    Bengt<br>
    <br>
    <div><br>
    </div>
    <blockquote type="cite">
      <div dir="ltr"><span class="">
        <div>Bengt,</div>
        <div><br>
        </div>
        That's what it looks like to me. Could you try to add a call to <span style="font-size:12.8000001907349px">vtkDataArrayRoundIfNecessary there
          and report back if it solves your problem? If so, would you be
          interested in contributing a patch to VTK? Developer
          instructions are available here:</span>
        <div><span style="font-size:12.8000001907349px"><br>
          </span></div>
        </span><div><span style="font-size:12.8000001907349px"><a href="https://gitlab.kitware.com/vtk/vtk/blob/master/CONTRIBUTING.md" target="_blank"></a><a href="https://gitlab.kitware.com/vtk/vtk/blob/master/CONTRIBUTING.md" target="_blank">https://gitlab.kitware.com/vtk/vtk/blob/master/CONTRIBUTING.md</a></span><br>
        </div><div><div class="h5">
        <div><span style="font-size:12.8000001907349px"><br>
          </span></div>
        <div><span style="font-size:12.8000001907349px">Feel free to add
            me as a reviewer: @cory-quammen is my username.</span></div>
        <div><span style="font-size:12.8000001907349px"><br>
          </span></div>
        <div><span style="font-size:12.8000001907349px">Thanks,</span></div>
        <div><span style="font-size:12.8000001907349px">Cory</span></div>
      </div></div></div>
      <div class="gmail_extra"><br>
        <div class="gmail_quote"><div><div class="h5">On Thu, Jul 23, 2015 at 1:01 PM, Bengt
          Rosenberger <span dir="ltr"><<a href="mailto:bengt@ctech.com" target="_blank">bengt@ctech.com</a>></span>
          wrote:<br>
          </div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div text="#000000" bgcolor="#FFFFFF"><div><div class="h5"> Small correction:
              vtkDataArrayInterpolateTuple is either called from
              vtkDataArray, ln 496 or ln 515. I can't exactly tell
              because I'm unable to step through that macro. However, I
              could see that vtkDataArrayInterpolateTuple, ln 103 was
              called.<br>
              <br>
              Is there just a vtkDataArrayRoundIfNecessary missing?<br>
              <br>
              Bye,<br>
              Bengt<span><br>
                <br>
                <div>Am 23.07.2015 um 18:50 schrieb Bengt Rosenberger:<br>
                </div>
              </span>
              </div></div><blockquote type="cite"><div><div class="h5"><span> 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>Am 23.07.2015 um 15:30 schrieb Cory Quammen:<br>
                  </div>
                </span>
                </div></div><blockquote type="cite"><div><div class="h5"><span>
                    <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>
                  </span>
                  </div></div><div>
                    <div>
                      <div class="gmail_extra"><br>
                        <div class="gmail_quote"><div><div class="h5">On Wed, Jul 22, 2015 at
                          6:05 PM, Bengt Rosenberger <span dir="ltr"><<a href="mailto:bengt@ctech.com" target="_blank"></a><a href="mailto:bengt@ctech.com" target="_blank">bengt@ctech.com</a>></span>
                          wrote:<br>
                          </div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">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 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 href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
                            <br>
                            Visit other Kitware open-source projects at
                            <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
                            <br></div></div><span class="">
                            Please keep messages on-topic and check the
                            VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
                            <br></span>
                            Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer" target="_blank"></a><a href="http://markmail.org/search/?q=vtkusers" target="_blank">http://markmail.org/search/?q=vtkusers</a><span class=""><br>
                            <br>
                            Follow this link to subscribe/unsubscribe:<br>
                            <a href="http://public.kitware.com/mailman/listinfo/vtkusers" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/vtkusers</a><br>
                          </span></blockquote>
                        </div><span class="">
                        <br>
                        <br clear="all">
                        <div><br>
                        </div>
                        -- <br>
                        <div>Cory Quammen<br>
                          R&D Engineer<br>
                          Kitware, Inc.</div>
                      </span></div>
                    </div>
                  </div>
                </blockquote><span class="">
                <div>
                  <div> <br>
                    <br>
                    <fieldset></fieldset>
                    <br>
                    <pre>_______________________________________________
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a>

Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a>

Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a>

Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" target="_blank">http://markmail.org/search/?q=vtkusers</a>

Follow this link to subscribe/unsubscribe:
<a href="http://public.kitware.com/mailman/listinfo/vtkusers" target="_blank">http://public.kitware.com/mailman/listinfo/vtkusers</a>
</pre>
                  </div>
                </div>
              </span></blockquote>
              <br>
            </div>
          </blockquote>
        </div><span class="">
        <br>
        <br clear="all">
        <div><br>
        </div>
        -- <br>
        <div>Cory Quammen<br>
          R&D Engineer<br>
          Kitware, Inc.</div>
      </span></div>
    </blockquote>
    <br>
  </div>

</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>