[vtkusers] Using vtkExternalOpenGLCamera

Elaine Jiang elainejiang8 at gmail.com
Thu Jul 20 13:31:17 EDT 2017


Hi Sankhesh,

Here's my initialization function and my render function. The external
camera set up is highlighted.

*vtkNew<ExternalVTKWidget> externalVTKWidget;*
*vtkSmartPointer<vtkRenderer> ren = externalVTKWidget->AddRenderer();*
*static int windowId = -1;*
*static int windowH = 800;*
*static int windowW = 800;*
*vtkSmartPointer<vtkActor> actors[7];*

*vtkNew<vtkTransform> transform;*
*int press_x, press_y;*
*int release_x, release_y;*
*float x_angle = 0.0;*
*float y_angle = 0.0;*
*float scale_size = 1;*
*int xform_mode = 0;*
*#define XFORM_NONE    0*
*#define XFORM_ROTATE  1*
*#define XFORM_SCALE 2*


*void initialize() {*
    *vtkNew<vtkExternalOpenGLRenderWindow> renWin;*
*    externalVTKWidget->SetRenderWindow(renWin.GetPointer());*

    *std::string files[7] = {"../data/newsi-ascii.vtk",
"../data/newjets-ascii.vtk", "../data/fekcorr-ascii.vtk",
"../data/newar-ascii.vtk", "../data/newhetg-ascii.vtk",
"../data/newopt-ascii.vtk", "../data/newsi-ascii.vtk"};*

*    for(int i = 0; i < 7; i++) {*
       * vtkSmartPointer<vtkPolyDataReader> reader =*
*        vtkSmartPointer<vtkPolyDataReader>::New();*
*        reader->SetFileName(files[i].c_str());*
*        reader->Update();*
*        vtkSmartPointer<vtkPolyData> inputPolyData = reader->GetOutput();*

*        vtkSmartPointer<vtkCleanPolyData> clean =*
*        vtkSmartPointer<vtkCleanPolyData>::New();*
*        clean->SetInputData(inputPolyData);*

        // Generate normals
        *vtkSmartPointer<vtkPolyDataNormals> normals =*
*        vtkSmartPointer<vtkPolyDataNormals>::New();*
*        normals->SetInputConnection(clean->GetOutputPort());*
*        normals->SplittingOff();*


        *vtkSmartPointer<vtkPolyDataMapper> mapper =*
*        vtkSmartPointer<vtkPolyDataMapper>::New();*
*        mapper->SetInputConnection(normals->GetOutputPort());*

        *vtkSmartPointer<vtkActor> actor =*
*        vtkSmartPointer<vtkActor>::New();*
*        actor->SetMapper(mapper);*
*        actor->GetProperty()->SetInterpolationToFlat();*

*        ren->AddActor(actor);*
*        actors[i] = actor;*
*    }*

    *ren->SetBackground(0, 0, 0);*
*    ren->MakeCamera();*
*    ren->ResetCamera();*
*    renWin->AddRenderer(ren);*
*}*

// Render function
*void display() {*
    // Enable depth testing. Demonstrates OpenGL context being managed by
external
    // application i.e. GLUT in this case.
    *glEnable(GL_DEPTH_TEST);*

    // Buffers being managed by external application i.e. GLUT in this case.
    *glClearColor(0.0f, 0.0f, 0.0f, 1.0f);* // Set background color to
black and opaque
    *glClearDepth(1.0f);*
    *glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);* // Clear the
color buffer

    *glFlush();*  // Render now

    *glEnable(GL_LIGHTING);*
*    glEnable(GL_LIGHT0);*

    *GLfloat diffuse[] = {1.0f, 1.0f, 1.0f, 1.0f};*
*    glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);*
*    GLfloat specular[] = {0.5f, 0.0f, 0.0f, 1.0f};*
*    glLightfv(GL_LIGHT0, GL_SPECULAR, specular);*
*    GLfloat ambient[] = {1.0f, 1.0f, 0.2f,  1.0f};*
*    glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);*


    *vtkExternalOpenGLCamera *camera = (vtkExternalOpenGLCamera
*)ren->GetActiveCamera();*
*    camera->SetPosition(0,0,-100);*
*    camera->SetFocalPoint(0,0,0); *
*    camera->SetViewUp(0,1,0); *


    *for(int i = 0; i < 7; i++) {*
*        // transpose - vtk*
*        actors[i]->SetOrientation(0,0,0);*
*        actors[i]->RotateX(y_angle);*
*        actors[i]->RotateY(x_angle);*
*        actors[i]->SetScale(scale_size);*

*        // transpose - opengl*
*        double f[16];*
*        actors[i]->GetMatrix(f);*

*        // transpose*
*        double g[16];*
*        g[0] = f[0]; g[1] = f[4]; g[2] = f[8]; g[3] = f[12];*
*        g[4] = f[1]; g[5] = f[5]; g[6] = f[9]; g[7] = f[13];*
*        g[8] = f[2]; g[9] = f[6]; g[10]= f[10];g[11]= f[14];*
*        g[12]= f[3]; g[13]= f[7]; g[14]= f[11];g[15]= f[15];*
*        glMultMatrixd(g); // multiply current matrix with specified matrix*
*    }*

    *externalVTKWidget->GetRenderWindow()->Render();*
*    glutSwapBuffers();*
*}*

Thanks,
Elaine

On Thu, Jul 20, 2017 at 1:11 PM, Sankhesh Jhaveri <
sankhesh.jhaveri at kitware.com> wrote:

> Hi Elaine,
>
> You shouldn’t have to set that flag for using the matrices set on the
> external camera. Could you share some sample code that doesn’t work?
>
> Thanks,
> Sankhesh
>>
> On Thu, Jul 20, 2017 at 11:38 AM Elaine Jiang <elainejiang8 at gmail.com>
> wrote:
>
>> Hi Sankhesh,
>>
>> I've tried setting the camera and focal point parameters without using
>> SetProjectionMatrix() and SetModelViewTransformMatrix(), and I've also
>> tried just calling SetProjectionMatrix() and SetModelViewTransformMatrix()
>> by themselves. Neither approach seemed to have an effect on the scene. I
>> was looking through the documentation and was wondering if I need to use
>> the function vtkCamera::vtkSetUseExplicitProjectionTransformMatrix(bool)
>> to solve the problem?
>>
>> Thanks,
>> Elaine
>>
>> On Thu, Jul 20, 2017 at 11:12 AM, Sankhesh Jhaveri <
>> sankhesh.jhaveri at kitware.com> wrote:
>>
>>> Hi,
>>>
>>> Could you please provide more details on how you’re trying to set the
>>> camera parameters?
>>> The way the external camera works is that it ignores the camera position
>>> and focal point parameters if the projection and model view matrices are
>>> set explicitly using vtkExternalOpenGLCamera::SetProjectionMatrix() and
>>> vtkExternalOpenGLCamera::SetModelViewTransformMatrix()
>>>
>>> Thanks,
>>> Sankhesh
>>>>>>
>>> On Wed, Jul 19, 2017 at 9:59 AM elainejiang8 <elainejiang8 at gmail.com>
>>> wrote:
>>>
>>>> Hi everyone!
>>>>
>>>> I'm building a program that uses the externalVTKWidget to volume render
>>>> an
>>>> object in an OpenGL context. Right now, I'm calling
>>>>
>>>> *ren->GetActiveCamera();
>>>> *
>>>>
>>>> (where ren is a vtkExternalOpenGLRenderWindow instance) in my render
>>>> function so I can control the position and focal point of the camera.
>>>> However, I'm unable to get the camera to actually have any effect on the
>>>> scene. The documentation for vtkExternalOpenGLCamera is rather slim,
>>>> and I
>>>> can't find any similar examples, so I am a bit stuck on this issue.
>>>>
>>>> Does anyone have any insight into how I could approach this problem?
>>>> Thanks
>>>> in advance!
>>>>
>>>> Elaine
>>>>
>>>>
>>>>
>>>> --
>>>> View this message in context: http://vtk.1045678.n5.nabble.com/Using-
>>>> vtkExternalOpenGLCamera-tp5744015.html
>>>> Sent from the VTK - Users mailing list archive at Nabble.com.
>>>> _______________________________________________
>>>> Powered by www.kitware.com
>>>>
>>>> Visit other Kitware open-source projects at http://www.kitware.com/
>>>> opensource/opensource.html
>>>>
>>>> Please keep messages on-topic and check the VTK FAQ at:
>>>> http://www.vtk.org/Wiki/VTK_FAQ
>>>>
>>>> Search the list archives at: http://markmail.org/search/?q=vtkusers
>>>>
>>>> Follow this link to subscribe/unsubscribe:
>>>> http://public.kitware.com/mailman/listinfo/vtkusers
>>>>
>>> --
>>> Sankhesh Jhaveri *Sr. Research & Development Engineer* | Kitware
>>> <http://www.kitware.com/> | (518) 881-4417
>>>>>>
>>
>> --
> Sankhesh Jhaveri *Sr. Research & Development Engineer* | Kitware
> <http://www.kitware.com/> | (518) 881-4417
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170720/d412e144/attachment.html>


More information about the vtkusers mailing list