<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">Hi Bill,<br>
<br>
Thanks for the reply.<br>
<br>
This example don't reproduce my bug, but if I add a vtkTexture to
superquadricActor and I add a vtkActor2D to the sceneRenderer<span
class="sy2"></span>, the vtkActor2D doesn't display correctly.<br>
<br>
you can check my precedent simple example if you want with this<br>
<br>
CMakeLists.txt:<br>
<blockquote>cmake_minimum_required(VERSION 2.8)<br>
<br>
PROJECT(ImageMapper)<br>
<br>
# This project uses Qt4<br>
find_package(Qt4 REQUIRED)<br>
add_definitions(${QT_DEFINITIONS})<br>
include(${QT_USE_FILE})<br>
<br>
# VTK<br>
find_package(VTK REQUIRED)<br>
include(${VTK_USE_FILE})<br>
<br>
add_executable(ImageMapper ImageMapper)<br>
<br>
target_link_libraries(ImageMapper ${VTK_LIBRARIES}
${QT_LIBRARIES})<br>
</blockquote>
<br>
Thanks<br>
Dominic Plourde<br>
<br>
On 13-01-31 08:37 AM, Bill Lorensen wrote:<br>
</div>
<blockquote
cite="mid:CADZJ4hOHOfNrOG2bfSSoLav1Mi0-4YhJbGKpF-uQwY69JYb06g@mail.gmail.com"
type="cite">
<pre wrap="">See if this example helps:
<a class="moz-txt-link-freetext" href="http://vtk.org/Wiki/VTK/Examples/Cxx/Images/BackgroundImage">http://vtk.org/Wiki/VTK/Examples/Cxx/Images/BackgroundImage</a>
On Tue, Jan 29, 2013 at 10:57 AM, Dominic <a class="moz-txt-link-rfc2396E" href="mailto:domaniak@gmail.com"><domaniak@gmail.com></a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">On 13-01-18 10:45 AM, Dominic Plourde wrote:
I have a similar problem. I'm using VTK 5.10.1 on Ubuntu 11.10 The
vtkActor2D disappear when I moving other 3D actors outside the viewport. If
I remove the vtkAxesActor, my vtkActor2D is not visible. My test code:
#include <vtkVersion.h>
#include <vtkImageData.h>
#include <vtkSmartPointer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorStyleImage.h>
#include <vtkRenderer.h>
#include <vtkImageMapper.h>
#include <vtkActor2D.h>
#include <vtkPolygon.h>
#include <vtkPolyData.h>
#include <vtkProperty.h>
#include <vtkPolyDataMapper.h>
#include <vtkCellData.h>
#include <vtkCellArray.h>
#include <vtkTexture.h>
#include <vtkImageData.h>
#include <vtkFloatArray.h>
#include <vtkPointData.h>
#include <vtkQImageToImageSource.h>
#include <vtkAxesActor.h>
#include <vtkVersion.h>
#include <QImage>
#include <QApplication>
static void CreateColorImage(vtkImageData*);
int main(int i, char** c)
{
QApplication qapp(i, c);
vtkSmartPointer<vtkImageData> colorImage =
vtkSmartPointer<vtkImageData>::New();
CreateColorImage(colorImage);
vtkSmartPointer<vtkImageMapper> imageMapper =
vtkSmartPointer<vtkImageMapper>::New();
imageMapper->SetInputConnection(colorImage->GetProducerPort());
imageMapper->SetColorWindow(255);
imageMapper->SetColorLevel(127.5);
vtkSmartPointer<vtkActor2D> imageActor =
vtkSmartPointer<vtkActor2D>::New();
imageActor->SetMapper(imageMapper);
imageActor->SetPosition(0, 0);
// Create a vtkPoints object and store the points in it
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
// Create a cell array to store the polygon in and add the polygon to it
vtkSmartPointer<vtkCellArray> polygons =
vtkSmartPointer<vtkCellArray>::New();
// Read the image which will be the texture
QImage* qimage = new QImage("logo.png");
vtkSmartPointer<vtkQImageToImageSource> qImageToVtk =
vtkSmartPointer<vtkQImageToImageSource>::New();
qImageToVtk->SetQImage(qimage);
vtkSmartPointer<vtkTexture> texture = vtkSmartPointer<vtkTexture>::New();
texture->SetInputConnection(qImageToVtk->GetOutputPort());
vtkSmartPointer<vtkFloatArray> textureCoordinates =
vtkSmartPointer<vtkFloatArray>::New();
textureCoordinates->SetNumberOfComponents(3);
textureCoordinates->SetName("TextureCoordinates");
// Create a polydata to store everything in
vtkSmartPointer<vtkPolyData> polygonPolyData =
vtkSmartPointer<vtkPolyData>::New();
float tuple[3] = {0.0, 0.0, 0.0};
textureCoordinates->InsertNextTuple(tuple);
tuple[0] = 1.0; tuple[1] = 0.0; tuple[2] = 0.0;
textureCoordinates->InsertNextTuple(tuple);
tuple[0] = 1.0; tuple[1] = 1.0; tuple[2] = 0.0;
textureCoordinates->InsertNextTuple(tuple);
tuple[0] = 0.0; tuple[1] = 1.0; tuple[2] = 0.0;
textureCoordinates->InsertNextTuple(tuple);
// Add the points to the dataset
polygonPolyData->SetPoints(points);
polygonPolyData->SetPolys(polygons);
polygonPolyData->GetPointData()->SetTCoords(textureCoordinates);
// Setup actor and mapper
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInput(polygonPolyData);
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
actor->SetTexture(texture);
actor->GetProperty()->SetColor(0.0, 0.62, 0.85);
points->SetNumberOfPoints(4);
points->SetPoint(0, 0, 0, 0);
points->SetPoint(1, 10, 0, 0);
points->SetPoint(2, 10, 10, 0);
points->SetPoint(3, 0, 10, 0);
vtkSmartPointer<vtkPolygon> top = vtkSmartPointer<vtkPolygon>::New();
top->GetPointIds()->SetNumberOfIds(4);
top->GetPointIds()->SetId(3, 0);
top->GetPointIds()->SetId(2, 1);
top->GetPointIds()->SetId(1, 2);
top->GetPointIds()->SetId(0, 3);
polygons->InsertNextCell(top);
vtkSmartPointer<vtkAxesActor> axes = vtkSmartPointer<vtkAxesActor>::New();
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
// Setup render window interactor
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
vtkSmartPointer<vtkInteractorStyleImage> style =
vtkSmartPointer<vtkInteractorStyleImage>::New();
renderWindowInteractor->SetInteractorStyle(style);
// Render and start interaction
renderWindowInteractor->SetRenderWindow(renderWindow);
renderer->AddActor(actor);
renderer->AddActor(axes);
renderer->AddActor2D(imageActor);
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
void CreateColorImage(vtkImageData* image)
{
unsigned int dim = 50;
image->SetDimensions(dim, dim, 1);
#if VTK_MAJOR_VERSION <= 5
image->SetNumberOfScalarComponents(3);
image->SetScalarTypeToUnsignedChar();
image->AllocateScalars();
#else
image->AllocateScalars(VTK_UNSIGNED_CHAR,3);
#endif
for(unsigned int x = 0; x < dim; x++)
{
for(unsigned int y = 0; y < dim; y++)
{
unsigned char* pixel = static_cast<unsigned
char*>(image->GetScalarPointer(x,y,0));
if(x < dim/2)
        {
pixel[0] = 255;
pixel[1] = 0;
        }
else
        {
pixel[0] = 0;
pixel[1] = 255;
        }
pixel[2] = 0;
}
}
image->Modified();
}
Elvis Dowson wrote
Hi, In the following code, I cannot get both vtkActor2D and vtkActor to
display simultaneously. If I enable 2D map source and text source, it
displays the map and the text. If I enable the 3D cylinder source, the 3D
cylinder doesnt get displayed. However, if I disable the 2D map source, the
cylinder and the text message appears. How can I get the 2D map to display
below, and the 3D cylinder to appear to hover above the 2D map ? Am I mixing
things here? Should I be using vtkImageActor instead of vtkActor2D, so that
there is a 3D image plane and then display the 3D source? I really dont want
to do that at the moment. Please help! :-) Best regards, Elvis Dowson
#include "qapplication.h"
#include <QtGui>
#include <vtkActor.h>
#include <vtkActor2D.h>
#include <vtkImageActor.h>
#include <vtkTextActor.h>
#include <vtkJPEGReader.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkImageMapper.h>
#include <vtkPolyDataMapper.h>
#include <vtkCylinderSource.h>
#if QT_VERSION >= 0x040000
# include "ui_GUI4.h"
#endif
#define PROTOTYPE_2D_MAP_SOURCE
#define PROTOTYPE_2D_TEXT_SOURCE
#define PROTOTYPE_3D_CYLINDER_SOURCE
int main(int argc, char** argv)
{
QApplication app(argc, argv);
        
#if QT_VERSION >= 0x040000
        Ui::Dialog ui;
        QDialog dialog;
#endif
        
        ui.setupUi(&dialog);
        dialog.setAttribute(Qt::WA_QuitOnClose);
        
        // Qt vtk integration
        vtkRenderer* ren = NULL;
        ren = vtkRenderer::New();
                ui.qvtkWidget->GetRenderWindow()->AddRenderer(ren);
        
        // Prototype: 2D Map Source
        // ----------------------------
        #ifdef PROTOTYPE_2D_MAP_SOURCE
        {
        // Declare object instance variables
        vtkJPEGReader* imageReader        = NULL;
        vtkImageMapper* imageMapper = NULL;
        vtkActor2D* mapActor                = NULL;                        
                        
        // Read 2D image file
        imageReader = vtkJPEGReader::New();
                imageReader->SetFileName("/Users/elvis/Image/sample.jpg");
                imageReader->Update();
        
        // Map 2D image file
        imageMapper = vtkImageMapper::New();
                imageMapper->SetInput(imageReader->GetOutput());
                imageMapper->SetColorWindow(255);
                imageMapper->SetColorLevel(127.5);
                
        // Actor in scene
        mapActor = vtkActor2D::New();
                mapActor->SetMapper(imageMapper);        
        // Actor in scene
        mapActor = vtkActor2D::New();
                //mapActor->SetLayerNumber(0);
                mapActor->SetMapper(imageMapper);                        
        // Add Actor to renderer
        ren->AddActor2D(mapActor);
        }
        #endif
        // Prototype: 2D Text Source
        // -----------------------------
        #ifdef PROTOTYPE_2D_TEXT_SOURCE
        {
                // Declare object instance variables
                vtkTextActor* textActor;
                
                // Initialize objects
                textActor = NULL;
                
                // Actor in scene
                textActor = vtkTextActor::New();
                textActor->SetTextScaleMode(vtkTextActor::TEXT_SCALE_MODE_NONE);
                textActor->SetInput("This is a text message!");
                
                // Add Actor to renderer
                ren->AddActor2D(textActor);
        }
        #endif
        
        // Prototype: 3D Cyclinder Source
        // ----------------------------------
        #ifdef PROTOTYPE_3D_CYLINDER_SOURCE        
        {
        // Declare object instance variables
        vtkCylinderSource* source;
        vtkPolyDataMapper* mapper;
        vtkActor* actor;
        // Initialize objects
        source = NULL;
        mapper = NULL;
        actor = NULL;
        
        // Geometry
        source = vtkCylinderSource::New();
        
        // Mapper
        mapper = vtkPolyDataMapper::New();
        mapper->ImmediateModeRenderingOn();
        mapper->SetInputConnection(source->GetOutputPort());
        
        // Actor in scene
        actor = vtkActor::New();
        actor->SetMapper(mapper);
        
        // Add Actor to renderer
        ren->AddActor(actor);
        }
        #endif
        
        // Reset camera
        ren->ResetCamera();
        
        // Render the scene
        ren->GetRenderWindow()->Render();
        
        // Display the dialog window
        dialog.show();
return app.exec();
}
_______________________________________________ This is the private VTK
discussion list. Please keep messages on-topic. Check the FAQ at:
<a class="moz-txt-link-freetext" href="http://www.vtk.org/Wiki/VTK_FAQ">http://www.vtk.org/Wiki/VTK_FAQ</a> Follow this link to subscribe/unsubscribe:
<a class="moz-txt-link-freetext" href="http://www.vtk.org/mailman/listinfo/vtkusers">http://www.vtk.org/mailman/listinfo/vtkusers</a>
________________________________
View this message in context: Re: Problem getting vtkActor2D and vtkActor to
render simultaneously
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
Powered by <a class="moz-txt-link-abbreviated" href="http://www.kitware.com">www.kitware.com</a>
Visit other Kitware open-source projects at
<a class="moz-txt-link-freetext" href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a>
Please keep messages on-topic and check the VTK FAQ at:
<a class="moz-txt-link-freetext" href="http://www.vtk.org/Wiki/VTK_FAQ">http://www.vtk.org/Wiki/VTK_FAQ</a>
Follow this link to subscribe/unsubscribe:
<a class="moz-txt-link-freetext" href="http://www.vtk.org/mailman/listinfo/vtkusers">http://www.vtk.org/mailman/listinfo/vtkusers</a>
Has anyone encountered this?
Thanks,
Dominic
_______________________________________________
Powered by <a class="moz-txt-link-abbreviated" href="http://www.kitware.com">www.kitware.com</a>
Visit other Kitware open-source projects at
<a class="moz-txt-link-freetext" href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a>
Please keep messages on-topic and check the VTK FAQ at:
<a class="moz-txt-link-freetext" href="http://www.vtk.org/Wiki/VTK_FAQ">http://www.vtk.org/Wiki/VTK_FAQ</a>
Follow this link to subscribe/unsubscribe:
<a class="moz-txt-link-freetext" href="http://www.vtk.org/mailman/listinfo/vtkusers">http://www.vtk.org/mailman/listinfo/vtkusers</a>
</pre>
</blockquote>
<pre wrap="">
</pre>
</blockquote>
<br>
</body>
</html>