[vtkusers] Using VTK in a Visual C++ project Express 2010

Frese Daniel Dr. frese at heidenhain.de
Mon Apr 18 10:23:10 EDT 2011


Hi Bob,

Yes, this should be possible. I tried it, although with the VS 2005 professional edition.
Here is a small sample program:

// clr_console.cpp : main project file.

#include "stdafx.h"

#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkWin32OpenGLRenderWindow.h>
#include <vtkWin32RenderWindowInteractor.h>


using namespace System;

int main(array<System::String ^> ^args)
{
	// create sphere geometry
    vtkSmartPointer<vtkSphereSource> sphere = vtkSmartPointer<vtkSphereSource>::New();

    // map to graphics library
    vtkSmartPointer<vtkPolyDataMapper> map = vtkSmartPointer<vtkPolyDataMapper>::New();
    map->SetInputConnection(sphere->GetOutputPort());

    // actor coordinates geometry, properties, transformation
    vtkSmartPointer<vtkActor> aSphere = vtkSmartPointer<vtkActor>::New();
    aSphere->SetMapper(map);

	// a renderer and render window
    vtkSmartPointer<vtkRenderer> Renderer = vtkSmartPointer<vtkRenderer>::New();
    vtkSmartPointer<vtkWin32OpenGLRenderWindow> RenderWindow = vtkSmartPointer<vtkWin32OpenGLRenderWindow>::New();
    RenderWindow->AddRenderer(Renderer);


    // add the actor to the scene and define Interactor
	vtkSmartPointer<vtkWin32RenderWindowInteractor> Interactor = vtkSmartPointer<vtkWin32RenderWindowInteractor>::New();
	Interactor->SetRenderWindow(RenderWindow);
    Renderer->AddActor(aSphere);

	// start to play around
	RenderWindow->Render();
	Interactor->Initialize();
	Interactor->Start();
}

To build and execute this one, I had to do the following:
1) new project of type clr console application; paste the above code into the new cpp file.
2) Add Include dir under projects->properties->C/C++->General->Additional Include Directories (in my case this is "C:\Programme\VTK\include\vtk-5.9")
3) Add Lib dir projects->properties->Linker->Additional Library Directories (in my case this is "C:\Programme\VTK\lib\vtk-5.9")
4) Add necessary vtk libs under projects->properties->Linker->Additional Dependencies (in my case the entry is 
	"Opengl32.lib Gdi32.lib User32.lib vtkFiltering.lib vtkCommon.lib vtkGraphics.lib vtkRendering.lib $(NoInherit)"; not sure if everything
	here is necessary, but it works).

I do get an annoying linker warning " warning LNK4248: unresolved typeref token (01000015) for 'vtkAlgorithmOutput'; image may not run" (also on other projects I work on), but so far it has been OK to ignore this; everything runs fine.

Daniel


 -----Ursprüngliche Nachricht-----
Von: vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] Im Auftrag von Bob Palank
Gesendet: Sonntag, 17. April 2011 17:42
An: vtkusers at vtk.org
Betreff: Re: [vtkusers] Using VTK in a Visual C++ project Express 2010

Can I run a vtk application using the clr console application template in
VC++ Express 2010 ?
Bob
-------------------------------------------------------------------------------------------------------
Registergericht: Traunstein / Registry Court: HRB 275 – Sitz / Head Office: Traunreut
Aufsichtsratsvorsitzender / Chairman of Supervisory Board: Rainer Burkhard
Geschäftsführung / Management Board: Thomas Sesselmann (Vorsitzender / Chairman),
Michael Grimm, Matthias Fauser, Sebastian Tondorf

E-Mail Haftungsausschluss / E-Mail Disclaimer: http://www.heidenhain.de/disclaimer



More information about the vtkusers mailing list