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