FLTK logo

Re: [fltk.general] Does anyone use vtk with fltk?

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: Does anyone use vtk with fltk? Amanjit Gill Feb 15, 2006  
 
Chunyan Jiang wrote:

Hi all,
Does anybody use vtk with fltk?
How to render vtk object in fltk window?

Looking forward your reply.

Chunyan

Hi, apart from the recommended solution "vtkfltk" I dug into my sourcecode archive and discovered this prototype I created a few years ago. This toy may help you start daddling around, but I would stick with the real "vtkfltk" solution in the long run. Was win32 but should be no problem on other platforms (use appropriate RenderWindow). link with vtkCommon.lib vtkRendering.lib vtkGraphics.lib vtkFiltering.lib

---------------------------------------------
/**
 * Simple vtk tryout
 */

#include <vld.h>
#include <FL/Fl.H>
#include <FL/x.H>
#include <FL/Fl_Window.H>
#define VTK_USE_ANSI_STDLIB // <iostream> not <iostream.h>
#include <vtk/vtkRenderer.h>
#include <vtk/vtkWin32OpenGLRenderWindow.h>
#include <vtk/vtkPolyDataMapper.h>
#include <vtk/vtkActor.h>
#include <vtk/vtkSphereSource.h>

/**
 * @brief simple VTK window
 */
class SimpleVTKWnd : public Fl_Window {
public:
  SimpleVTKWnd(int iW, int iH, const char* psCapt =0)
      : Fl_Window(iW,iH,psCapt) {
    m_pRen          = vtkRenderer::New();
    m_pRenWin       = vtkWin32OpenGLRenderWindow::New();
    m_pSphere       = vtkSphereSource::New();
    m_pSphereMapper = vtkPolyDataMapper::New();
    m_pSphereActor  = vtkActor::New();
  }

  virtual ~SimpleVTKWnd() {
    m_pSphereActor->Delete();
    m_pSphereMapper->Delete();
    m_pSphere->Delete();
    m_pRenWin->Delete();
    m_pRen->Delete();
  }

  virtual void draw() {
    static bool bInit(false);
    if (!bInit) {
      m_pRenWin->AddRenderer(m_pRen);
      m_pRenWin->SetParentId(fl_xid(this));
      m_pRenWin->SetSize(w(),h());
      m_pRen->ResetCamera();
      m_pSphere->SetRadius(5);
      m_pSphere->SetThetaResolution(24);
      m_pSphere->SetPhiResolution(24);
      m_pSphere->LatLongTessellationOn();
      m_pSphereMapper->SetInput(m_pSphere->GetOutput());
      m_pSphereMapper->SetColorModeToMapScalars();
      m_pSphereMapper->SetScalarRange(-1,1);
      m_pSphereActor->SetMapper(m_pSphereMapper);
      m_pRen->AddActor(m_pSphereActor);
      bInit = true;
    }
    m_pRenWin->Render();
  }

private:
  vtkRenderer*                m_pRen;
  vtkWin32OpenGLRenderWindow* m_pRenWin;
  vtkSphereSource*            m_pSphere;
  vtkPolyDataMapper*          m_pSphereMapper;
  vtkActor*                   m_pSphereActor;
};

/**
 * @brief Main method
 */
int main(int argc, char **argv) {
  SimpleVTKWnd vtkWnd(500,500);
  vtkWnd.end();
  vtkWnd.show(argc, argv);
  return Fl::run();
}
---------------------------------------------
Cheers

Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.