<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix"><br>
      On 13-02-01 11:36 AM, Bill Lorensen wrote:<br>
    </div>
    <blockquote
cite="mid:CADZJ4hNSw89-EJih0mDoCWSQSt0nRMDzAgOrGpj1Zjtm_Bu7MA@mail.gmail.com"
      type="cite">
      <pre wrap="">Can you change the wiki example to illustrate your problem? You don't
need qt to do that.

</pre>
    </blockquote>
    Yes, in this exemple, if you move the superquadricActor away of the
    viewport with your mouse, the vtkActor2D color change.<br>
    <blockquote>#include &lt;vtkVersion.h&gt;<br>
      #include &lt;vtkActor.h&gt;<br>
      #include &lt;vtkCamera.h&gt;<br>
      #include &lt;vtkImageCanvasSource2D.h&gt;<br>
      #include &lt;vtkImageActor.h&gt;<br>
      #include &lt;vtkImageData.h&gt;<br>
      #include &lt;vtkJPEGReader.h&gt;<br>
      #include &lt;vtkPolyData.h&gt;<br>
      #include &lt;vtkPolyDataMapper.h&gt;<br>
      #include &lt;vtkRenderer.h&gt;<br>
      #include &lt;vtkRenderWindow.h&gt;<br>
      #include &lt;vtkRenderWindowInteractor.h&gt;<br>
      #include &lt;vtkSmartPointer.h&gt;<br>
      #include &lt;vtkSuperquadricSource.h&gt;<br>
      &nbsp;<br>
      #include &lt;vtkImageMapper.h&gt;<br>
      #include &lt;vtkActor2D.h&gt;<br>
      #include &lt;vtkTexture.h&gt;<br>
      #include &lt;vtkFloatArray.h&gt;<br>
      #include &lt;vtkPointData.h&gt;<br>
      <br>
      static void CreateColorImage(vtkImageData*);<br>
      <br>
      int main(int argc, char *argv[])<br>
      {<br>
      &nbsp; vtkSmartPointer&lt;vtkImageData&gt; imageData;<br>
      &nbsp;<br>
      &nbsp; // Verify input arguments<br>
      &nbsp; if ( argc &gt; 1 )<br>
      &nbsp;&nbsp;&nbsp; {<br>
      &nbsp;&nbsp;&nbsp; //Read the image<br>
      &nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkJPEGReader&gt; jpegReader =<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkJPEGReader&gt;::New();<br>
      &nbsp;&nbsp;&nbsp; if( !jpegReader-&gt;CanReadFile( argv[1] ) )<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; "Error reading file " &lt;&lt; argv[1]
      &lt;&lt; std::endl;<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return EXIT_FAILURE;<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
      &nbsp;&nbsp;&nbsp; jpegReader-&gt;SetFileName ( argv[1] );<br>
      &nbsp;&nbsp;&nbsp; jpegReader-&gt;Update();<br>
      &nbsp;&nbsp;&nbsp; imageData = jpegReader-&gt;GetOutput();<br>
      &nbsp;&nbsp;&nbsp; }<br>
      &nbsp; else<br>
      &nbsp;&nbsp;&nbsp; {<br>
      &nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkImageCanvasSource2D&gt; canvasSource =<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkImageCanvasSource2D&gt;::New();<br>
      &nbsp;&nbsp;&nbsp; canvasSource-&gt;SetExtent(0, 100, 0, 100, 0, 0);<br>
      &nbsp;&nbsp;&nbsp; canvasSource-&gt;SetScalarTypeToUnsignedChar();<br>
      &nbsp;&nbsp;&nbsp; canvasSource-&gt;SetNumberOfScalarComponents(3);<br>
      &nbsp;&nbsp;&nbsp; canvasSource-&gt;SetDrawColor(127, 127, 100);<br>
      &nbsp;&nbsp;&nbsp; canvasSource-&gt;FillBox(0, 100, 0, 100);<br>
      &nbsp;&nbsp;&nbsp; canvasSource-&gt;SetDrawColor(100, 255, 255);<br>
      &nbsp;&nbsp;&nbsp; canvasSource-&gt;FillTriangle(10, 10, 25, 10, 25, 25);<br>
      &nbsp;&nbsp;&nbsp; canvasSource-&gt;SetDrawColor(255, 100, 255);<br>
      &nbsp;&nbsp;&nbsp; canvasSource-&gt;FillTube(75, 75, 0, 75, 5.0);<br>
      &nbsp;&nbsp;&nbsp; canvasSource-&gt;Update();<br>
      &nbsp;&nbsp;&nbsp; imageData = canvasSource-&gt;GetOutput();<br>
      &nbsp;&nbsp;&nbsp; }<br>
      &nbsp; // Create an image actor to display the image<br>
      &nbsp; vtkSmartPointer&lt;vtkImageActor&gt; imageActor =<br>
      &nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkImageActor&gt;::New();<br>
      #if VTK_MAJOR_VERSION &lt;= 5<br>
      &nbsp; imageActor-&gt;SetInput(imageData);<br>
      #else<br>
      &nbsp; imageActor-&gt;SetInputData(imageData);<br>
      #endif<br>
      &nbsp;<br>
      &nbsp; // Create a renderer to display the image in the background<br>
      &nbsp; vtkSmartPointer&lt;vtkRenderer&gt; backgroundRenderer = <br>
      &nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkRenderer&gt;::New();<br>
      <br>
      &nbsp; vtkSmartPointer&lt;vtkImageData&gt; colorImage =
      vtkSmartPointer&lt;vtkImageData&gt;::New();<br>
      &nbsp; CreateColorImage(colorImage);<br>
      <br>
      &nbsp; vtkSmartPointer&lt;vtkImageMapper&gt; imageMapper =
      vtkSmartPointer&lt;vtkImageMapper&gt;::New();<br>
      &nbsp;
      imageMapper-&gt;SetInputConnection(colorImage-&gt;GetProducerPort());<br>
      &nbsp; imageMapper-&gt;SetColorWindow(255);<br>
      &nbsp; imageMapper-&gt;SetColorLevel(127.5);<br>
      <br>
      &nbsp; vtkSmartPointer&lt;vtkActor2D&gt; imageActor2D =
      vtkSmartPointer&lt;vtkActor2D&gt;::New();<br>
      &nbsp; imageActor2D-&gt;SetMapper(imageMapper);<br>
      &nbsp; imageActor2D-&gt;SetPosition(0, 0);<br>
      <br>
      <br>
      &nbsp;<br>
      &nbsp; vtkSmartPointer&lt;vtkTexture&gt; texture =
      vtkSmartPointer&lt;vtkTexture&gt;::New();<br>
      &nbsp;
      texture-&gt;SetInputConnection(colorImage-&gt;GetProducerPort());<br>
      <br>
      &nbsp; // Create a superquadric<br>
      &nbsp; vtkSmartPointer&lt;vtkSuperquadricSource&gt; superquadricSource
      =<br>
      &nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkSuperquadricSource&gt;::New();<br>
      &nbsp; superquadricSource-&gt;SetPhiRoundness(1.1);<br>
      &nbsp; superquadricSource-&gt;SetThetaRoundness(.2);<br>
      <br>
      &nbsp; // Create a mapper and actor<br>
      &nbsp; vtkSmartPointer&lt;vtkPolyDataMapper&gt; superquadricMapper = <br>
      &nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkPolyDataMapper&gt;::New();<br>
      &nbsp;
superquadricMapper-&gt;SetInputConnection(superquadricSource-&gt;GetOutputPort());<br>
      &nbsp;<br>
      &nbsp; vtkSmartPointer&lt;vtkActor&gt; superquadricActor = <br>
      &nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkActor&gt;::New();<br>
      &nbsp; superquadricActor-&gt;SetMapper(superquadricMapper);<br>
      &nbsp; superquadricActor-&gt;SetTexture(texture);<br>
      &nbsp;<br>
      <br>
      &nbsp; vtkSmartPointer&lt;vtkRenderer&gt; sceneRenderer = <br>
      &nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkRenderer&gt;::New();<br>
      &nbsp;<br>
      &nbsp; vtkSmartPointer&lt;vtkRenderWindow&gt; renderWindow = <br>
      &nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkRenderWindow&gt;::New();<br>
      &nbsp;<br>
      &nbsp; // Set up the render window and renderers such that there is<br>
      &nbsp; // a background layer and a foreground layer<br>
      &nbsp; backgroundRenderer-&gt;SetLayer(0);<br>
      &nbsp; backgroundRenderer-&gt;InteractiveOff();<br>
      &nbsp; sceneRenderer-&gt;SetLayer(1);<br>
      &nbsp; renderWindow-&gt;SetNumberOfLayers(2);<br>
      &nbsp; renderWindow-&gt;AddRenderer(backgroundRenderer);<br>
      &nbsp; renderWindow-&gt;AddRenderer(sceneRenderer);<br>
      &nbsp;<br>
      &nbsp; vtkSmartPointer&lt;vtkRenderWindowInteractor&gt;
      renderWindowInteractor = <br>
      &nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkRenderWindowInteractor&gt;::New();<br>
      &nbsp; renderWindowInteractor-&gt;SetRenderWindow(renderWindow);<br>
      &nbsp;<br>
      &nbsp; // Add actors to the renderers<br>
      &nbsp; sceneRenderer-&gt;AddActor(superquadricActor);<br>
      &nbsp; sceneRenderer-&gt;AddActor2D(imageActor2D);<br>
      &nbsp; backgroundRenderer-&gt;AddActor(imageActor);<br>
      &nbsp;<br>
      &nbsp; // Render once to figure out where the background camera will be<br>
      &nbsp; renderWindow-&gt;Render();<br>
      &nbsp;<br>
      &nbsp; // Set up the background camera to fill the renderer with the
      image<br>
      &nbsp; double origin[3];<br>
      &nbsp; double spacing[3];<br>
      &nbsp; int extent[6];<br>
      &nbsp; imageData-&gt;GetOrigin( origin );<br>
      &nbsp; imageData-&gt;GetSpacing( spacing );<br>
      &nbsp; imageData-&gt;GetExtent( extent );<br>
      &nbsp;<br>
      &nbsp; vtkCamera* camera = backgroundRenderer-&gt;GetActiveCamera();<br>
      &nbsp; camera-&gt;ParallelProjectionOn();<br>
      &nbsp;<br>
      &nbsp; double xc = origin[0] + 0.5*(extent[0] + extent[1])*spacing[0];<br>
      &nbsp; double yc = origin[1] + 0.5*(extent[2] + extent[3])*spacing[1];<br>
      &nbsp; //double xd = (extent[1] - extent[0] + 1)*spacing[0];<br>
      &nbsp; double yd = (extent[3] - extent[2] + 1)*spacing[1];<br>
      &nbsp; double d = camera-&gt;GetDistance();<br>
      &nbsp; camera-&gt;SetParallelScale(0.5*yd);<br>
      &nbsp; camera-&gt;SetFocalPoint(xc,yc,0.0);<br>
      &nbsp; camera-&gt;SetPosition(xc,yc,d);<br>
      &nbsp;<br>
      &nbsp; // Render again to set the correct view<br>
      &nbsp; renderWindow-&gt;Render();<br>
      &nbsp;<br>
      &nbsp; // Interact with the window<br>
      &nbsp; renderWindowInteractor-&gt;Start();<br>
      &nbsp;<br>
      &nbsp; return EXIT_SUCCESS;<br>
      }<br>
      <br>
      void CreateColorImage(vtkImageData* image)<br>
      {<br>
      &nbsp; unsigned int dim = 50;<br>
      <br>
      &nbsp; image-&gt;SetDimensions(dim, dim, 1);<br>
      #if VTK_MAJOR_VERSION &lt;= 5<br>
      &nbsp; image-&gt;SetNumberOfScalarComponents(3);<br>
      &nbsp; image-&gt;SetScalarTypeToUnsignedChar();<br>
      &nbsp; image-&gt;AllocateScalars();<br>
      #else<br>
      &nbsp; image-&gt;AllocateScalars(VTK_UNSIGNED_CHAR,3);<br>
      #endif<br>
      &nbsp; for(unsigned int x = 0; x &lt; dim; x++)<br>
      &nbsp; {<br>
      &nbsp;&nbsp;&nbsp;&nbsp; for(unsigned int y = 0; y &lt; dim; y++)<br>
      &nbsp;&nbsp;&nbsp;&nbsp; {<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned char* pixel = static_cast&lt;unsigned
      char*&gt;(image-&gt;GetScalarPointer(x,y,0));<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(x &lt; dim/2)<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pixel[0] = 255;<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pixel[1] = 0;<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pixel[0] = 0;<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pixel[1] = 255;<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
      <br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pixel[2] = 0;<br>
      &nbsp;&nbsp;&nbsp;&nbsp; }<br>
      &nbsp; }<br>
      &nbsp; image-&gt;Modified();<br>
      }<br>
    </blockquote>
    <br>
  </body>
</html>