<div dir="ltr"><div>Done: <a href="https://gitlab.kitware.com/vtk/vtk/issues/17328">https://gitlab.kitware.com/vtk/vtk/issues/17328</a><br><br></div>Thanks<br></div><br><div class="gmail_quote"><div dir="ltr">Missatge de David E DeMarle <<a href="mailto:dave.demarle@kitware.com">dave.demarle@kitware.com</a>> del dia dt., 29 de maig 2018 a les 18:18:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Yes please do file a bug report on gitlab issue tracker.<div><br></div><div>Thanks</div><div><br></div></div><div class="gmail_extra"><br clear="all"><div><div class="m_1077065063318626690gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>David E DeMarle<br>Kitware, Inc.<br>Principal Engineer<br>21 Corporate Drive<br>Clifton Park, NY 12065-8662<br>Phone: 518-881-4909</div></div></div></div></div></div>
<br><div class="gmail_quote">On Mon, May 28, 2018 at 7:55 AM, Marc Ruiz Altisent <span dir="ltr"><<a href="mailto:marc.ruiz+vtk@gmail.com" target="_blank">marc.ruiz+vtk@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Should I create a new issue for this in the bug tracker?<br></div><br><div class="gmail_quote"><div dir="ltr">Missatge de Marc Ruiz Altisent <<a href="mailto:marc.ruiz%2Bvtk@gmail.com" target="_blank">marc.ruiz+vtk@gmail.com</a>> del dia dc., 23 de maig 2018 a les 19:29:<br></div><div><div class="m_1077065063318626690h5"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div>Hi everyone,<br><br></div>I have found an issue with vtkSmartVolumeMapper. If you create several vtkImageData objects, set one of them as the input of the mapper and render, then you won't be able to render one of the others at a later time: if you set one of the others as input the mapper will keep rendering the first one.<br><br></div>The issue is in the method vtkSmartVolumeMapper::ConnectMapperInput. It doesn't pass the original input to its internal mapper, but a shallow copy of it. The first time it will always perform the shallow copy, but afterwards it will only do it if the new input has been modified after creating the previous shallow copy, which is not always the case (e.g. if you create all the data before the first render).<br><br></div>Possible workarounds are to call Modified() on the input data when setting a new one or to create a new mapper each time.<br><br></div>Below is a sample program (adapted from a couple of examples) to proof the issue. Pressing 1 or 2 alternates between 2 datasets but only the first one is always rendered. Uncommenting the 2 Modified() calls makes it work as expected.<br><br>#include <vtkSmartPointer.h><br>#include <vtkSphere.h><br>#include <vtkBox.h><br>#include <vtkSampleFunction.h><br>#include <vtkSmartVolumeMapper.h><br>#include <vtkColorTransferFunction.h><br>#include <vtkPiecewiseFunction.h><br>#include <vtkRenderer.h><br>#include <vtkRenderWindow.h><br>#include <vtkRenderWindowInteractor.h><br>#include <vtkVolumeProperty.h><br>#include <vtkCamera.h><br>#include <vtkImageShiftScale.h><br>#include <vtkImageData.h><br>#include <vtkPointData.h><br>#include <vtkDataArray.h><br>#include <vtkInteractorStyleTrackballCamera.h><br>#include <vtkObjectFactory.h><br><br>// Define interaction style<br>class KeyPressInteractorStyle : public vtkInteractorStyleTrackballCamera<br>{<br> public:<br> static KeyPressInteractorStyle* New();<br> vtkTypeMacro(KeyPressInteractorStyle, vtkInteractorStyleTrackballCamera);<br><br> virtual void OnKeyPress()<br> {<br> // Get the keypress<br> vtkRenderWindowInteractor *rwi = this->Interactor;<br> std::string key = rwi->GetKeySym();<br><br> if(key == "1")<br> {<br> mapper->SetInputData(imageData1);<br> //imageData1->Modified();<br> rwi->Render();<br> }<br> else if(key == "2")<br> {<br> mapper->SetInputData(imageData2);<br> //imageData2->Modified();<br> rwi->Render();<br> }<br><br> // Forward events<br> vtkInteractorStyleTrackballCamera::OnKeyPress();<br> }<br> vtkSmartPointer<vtkVolumeMapper> mapper;<br> vtkSmartPointer<vtkImageData> imageData1, imageData2;<br>};<br>vtkStandardNewMacro(KeyPressInteractorStyle);<br><br>static void CreateImageData(vtkImageData* im, bool);<br><br>int main(int argc, char *argv[])<br>{<br> vtkSmartPointer<vtkImageData> imageData =<br> vtkSmartPointer<vtkImageData>::New();<br> vtkSmartPointer<vtkImageData> imageData2 =<br> vtkSmartPointer<vtkImageData>::New();<br><br> CreateImageData(imageData, true);<br> CreateImageData(imageData2, false);<br><br> vtkSmartPointer<vtkRenderWindow> renWin =<br> vtkSmartPointer<vtkRenderWindow>::New();<br> vtkSmartPointer<vtkRenderer> ren1 =<br> vtkSmartPointer<vtkRenderer>::New();<br> ren1->SetBackground(0.1,0.4,0.2);<br><br> renWin->AddRenderer(ren1);<br><br> renWin->SetSize(301,300); // intentional odd and NPOT width/height<br><br> vtkSmartPointer<vtkRenderWindowInteractor> iren =<br> vtkSmartPointer<vtkRenderWindowInteractor>::New();<br> iren->SetRenderWindow(renWin);<br> <br> vtkSmartPointer<KeyPressInteractorStyle> style =<br> vtkSmartPointer<KeyPressInteractorStyle>::New();<br> iren->SetInteractorStyle(style);<br> style->SetCurrentRenderer(ren1);<br><br> renWin->Render(); // make sure we have an OpenGL context.<br><br> vtkSmartPointer<vtkSmartVolumeMapper> volumeMapper =<br> vtkSmartPointer<vtkSmartVolumeMapper>::New();<br> volumeMapper->SetBlendModeToComposite(); // composite first<br> volumeMapper->SetInputData(imageData);<br> vtkSmartPointer<vtkVolumeProperty> volumeProperty =<br> vtkSmartPointer<vtkVolumeProperty>::New();<br> volumeProperty->ShadeOff();<br> volumeProperty->SetInterpolationType(VTK_LINEAR_INTERPOLATION);<br> <br> style->mapper = volumeMapper;<br> style->imageData1 = imageData;<br> style->imageData2 = imageData2;<br><br> vtkSmartPointer<vtkPiecewiseFunction> compositeOpacity =<br> vtkSmartPointer<vtkPiecewiseFunction>::New();<br> compositeOpacity->AddPoint(0.0,0.0);<br> compositeOpacity->AddPoint(80.0,1.0);<br> compositeOpacity->AddPoint(80.1,0.0);<br> compositeOpacity->AddPoint(255.0,0.0);<br> volumeProperty->SetScalarOpacity(compositeOpacity); // composite first.<br><br> vtkSmartPointer<vtkColorTransferFunction> color =<br> vtkSmartPointer<vtkColorTransferFunction>::New();<br> color->AddRGBPoint(0.0 ,0.0,0.0,1.0);<br> color->AddRGBPoint(40.0 ,1.0,0.0,0.0);<br> color->AddRGBPoint(255.0,1.0,1.0,1.0);<br> volumeProperty->SetColor(color);<br><br> vtkSmartPointer<vtkVolume> volume =<br> vtkSmartPointer<vtkVolume>::New();<br> volume->SetMapper(volumeMapper);<br> volume->SetProperty(volumeProperty);<br> ren1->AddViewProp(volume);<br> ren1->ResetCamera();<br><br> // Render composite. In default mode. For coverage.<br> renWin->Render();<br><br> iren->Start();<br><br> return EXIT_SUCCESS;<br>}<br><br>void CreateImageData(vtkImageData* imageData, bool spherical)<br>{<br> vtkSmartPointer<vtkImplicitFunction> implicitFunction;<br><br> if (spherical)<br> {<br> vtkSmartPointer<vtkSphere> sphere =<br> vtkSmartPointer<vtkSphere>::New();<br> sphere->SetRadius(0.1);<br> sphere->SetCenter(0.0,0.0,0.0);<br> implicitFunction = sphere;<br> }<br> else<br> {<br> vtkSmartPointer<vtkBox> box =<br> vtkSmartPointer<vtkBox>::New();<br> box->SetBounds(-0.1, 0.1, -0.1, 0.1, -0.1, 0.1);<br> implicitFunction = box;<br> }<br><br> vtkSmartPointer<vtkSampleFunction> sampleFunction =<br> vtkSmartPointer<vtkSampleFunction>::New();<br> sampleFunction->SetImplicitFunction(implicitFunction);<br> sampleFunction->SetOutputScalarTypeToDouble();<br> sampleFunction->SetSampleDimensions(127,127,127); // intentional NPOT dimensions.<br> sampleFunction->SetModelBounds(-1.0,1.0,-1.0,1.0,-1.0,1.0);<br> sampleFunction->SetCapping(false);<br> sampleFunction->SetComputeNormals(false);<br> sampleFunction->SetScalarArrayName("values");<br> sampleFunction->Update();<br><br> vtkDataArray* a = sampleFunction->GetOutput()->GetPointData()->GetScalars("values");<br> double range[2];<br> a->GetRange(range);<br><br> vtkSmartPointer<vtkImageShiftScale> t =<br> vtkSmartPointer<vtkImageShiftScale>::New();<br> t->SetInputConnection(sampleFunction->GetOutputPort());<br><br> t->SetShift(-range[0]);<br> double magnitude=range[1]-range[0];<br> if(magnitude==0.0)<br> {<br> magnitude=1.0;<br> }<br> t->SetScale(255.0/magnitude);<br> t->SetOutputScalarTypeToUnsignedChar();<br><br> t->Update();<br><br> imageData->ShallowCopy(t->GetOutput());<br>}<br></div></blockquote></div></div></div>
<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" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Search the list archives at: <a 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 href="https://vtk.org/mailman/listinfo/vtkusers" rel="noreferrer" target="_blank">https://vtk.org/mailman/listinfo/vtkusers</a><br>
<br></blockquote></div><br></div>
</blockquote></div>