[ Prev ] [ Index ] [ Next ]

VTK using MinGW for Windows

Created Sunday 02 October 2016

Download and install: https://sourceforge.net/projects/tdm-gcc/


After the installation, we now have C:\TDM-GCC-64\bin in PATH variable.

To test this, open command prompt (cmd) and type:

From anylocation , we now are able to access mingw32-make. To make life easier, go to C:\TDM-GCC-64\bin and create a copy of mingw32-make and rename it to make. Now we can type make from any location in our system.

Download VTK

http://www.vtk.org/files/release/7.0/VTK-7.0.0.zip
Extract the file. In my case, I extracted it into E:\ASUS\VTK-7.0.0

Install and run cmake for Windows


cmake can be dowloaded from: https://cmake.org/download/
Set source code path and binaries path as shown in the picture below.

Click "Configure" and select MinGW Makefiles. Configuration then will start.

Some errors appear but don't worry about them. I clicked configure once again, and the error disappeared (the red labels). I am not sure why. We then click "Generate" button.

Compile and install


Now, we go to command prompt. Change to the build directory of VTK, and type make and followed by make install. The compilation takes quite a while.
By default, VTK will be installed in C:\Program Files (x86)\VTK. We need to simply move this into a directory wothout white space. As for me, I move it to C:\precompiled\VTK.

Configuring Eclipse


This is an exmaple of an Eclipse project (Eclipse Neon) for VTK:
./hello-vtk.7z
Extract and import the project to the Eclipse.
Make sure "Includes" and "Libraries" are pointing to correct location.

Now, we need to make sure that we have the right directory set into the project properties. Right click on the hello-vtk icon on project explorer, select "Properties". Go to C/C++ Build >> Settings.

Below is the hello-vtk code. The fist 4 lines are necessary as we are not using cmake anymore from this point onward.

#include 
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);

#include "vtkCylinderSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkProperty.h"
#include "vtkCamera.h"
#include "vtkSmartPointer.h"

int main()
{
  // This creates a polygonal cylinder model with eight circumferential facets
  // (i.e, in practice an octagonal prism).
  vtkSmartPointer cylinder =
    vtkSmartPointer::New();
  cylinder->SetResolution(8);

  // The mapper is responsible for pushing the geometry into the graphics library.
  // It may also do color mapping, if scalars or other attributes are defined.
  vtkSmartPointer cylinderMapper =
    vtkSmartPointer::New();
  cylinderMapper->SetInputConnection(cylinder->GetOutputPort());

  // The actor is a grouping mechanism: besides the geometry (mapper), it
  // also has a property, transformation matrix, and/or texture map.
  // Here we set its color and rotate it around the X and Y axes.
  vtkSmartPointer cylinderActor =
    vtkSmartPointer::New();
  cylinderActor->SetMapper(cylinderMapper);
  cylinderActor->GetProperty()->SetColor(1.0000, 0.3882, 0.2784);
  cylinderActor->RotateX(30.0);
  cylinderActor->RotateY(-45.0);

  // The renderer generates the image
  // which is then displayed on the render window.
  // It can be thought of as a scene to which the actor is added
  vtkSmartPointer renderer =
    vtkSmartPointer::New();
  renderer->AddActor(cylinderActor);
  renderer->SetBackground(0.1, 0.2, 0.4);
  // Zoom in a little by accessing the camera and invoking its "Zoom" method.
  renderer->ResetCamera();
  renderer->GetActiveCamera()->Zoom(1.5);

  // The render window is the actual GUI window
  // that appears on the computer screen
  vtkSmartPointer renderWindow =
    vtkSmartPointer::New();
  renderWindow->SetSize(200, 200);
  renderWindow->AddRenderer(renderer);

  // The render window interactor captures mouse events
  // and will perform appropriate camera or actor manipulation
  // depending on the nature of the events.
  vtkSmartPointer renderWindowInteractor =
    vtkSmartPointer::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);

  // This starts the event loop and as a side effect causes an initial render.
  renderWindowInteractor->Start();

  return 0;
}