[vtkusers] How to integrate vtk render window into .NET forms?

Feng Ma mafeng at hotmail.com
Thu Jan 19 10:01:59 EST 2006


Hi, All:

  I have a question regarding integrating vtk render window into a .NET 
form. Here is what I do for the experiment:

  I create a simple .net form project. In the form, I create a button and a 
picture box inside. When I press the button, I wanted to connect the picture 
box to a vtk render window and display a sphere inside. Here is the code:

	private: System::Void button1_Click_1(System::Object *  sender, 
System::EventArgs *  e)
			 {
				vtkWin32OpenGLRenderWindow *m_RenderWindow;
				vtkRenderer *m_Renderer;
				vtkWin32RenderWindowInteractor *m_Interactor;

				m_Renderer = vtkRenderer::New();
				m_RenderWindow = vtkWin32OpenGLRenderWindow::New();
				m_RenderWindow->AddRenderer(m_Renderer);

				vtkSphereSource *sphere = vtkSphereSource::New();
				sphere->SetRadius(20.0);

				vtkPolyDataMapper *pSurfM = vtkPolyDataMapper::New();
				pSurfM->SetInput(sphere->GetOutput());
				vtkActor *pSurfActor = vtkActor::New();
				pSurfActor->SetMapper(pSurfM);

				// assign our actor to the renderer
				m_Renderer->AddActor(pSurfActor);

				// setup the parent window
				m_RenderWindow->SetParentId((HWND)((this->pictureBox1->Handle).ToPointer()));
				m_Interactor = vtkWin32RenderWindowInteractor::New();
				m_Interactor->SetRenderWindow(m_RenderWindow);

				m_Renderer->SetBackground( 1.0, 1.0, 1.0 );

				m_Renderer->Render();

				sphere->Delete();
				pSurfM->Delete();
				pSurfActor->Delete();

			 }

   When I compile the project, I got the following linking error. Any 
suggestions? Your helps are greatly appreciated.

-Feng


------ Build started: Project: VTKConnect, Configuration: Debug Win32 ------

Compiling...
AssemblyInfo.cpp
Form1.cpp
Compiling managed resources...
Read in 12 resources from 
'h:\Ma\ITKAppBuildW32\VTKConnect\VTKConnect\Form1.resX'
Writing resource file...  Done.
Linking...
msvcrt.lib(MSVCR71.dll) : error LNK2005: _exit already defined in 
LIBCMT.lib(crt0dat.obj)
msvcrt.lib(MSVCR71.dll) : error LNK2005: _free already defined in 
LIBCMT.lib(free.obj)
msvcrt.lib(MSVCR71.dll) : error LNK2005: _malloc already defined in 
LIBCMT.lib(malloc.obj)
msvcrt.lib(MSVCR71.dll) : error LNK2005: _getenv already defined in 
LIBCMT.lib(getenv.obj)
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: virtual __thiscall 
std::basic_streambuf<char,struct std::char_traits<char> 
 >::~basic_streambuf<char,struct std::char_traits<char> >(void)" 
(??1?$basic_streambuf at DU?$char_traits at D@std@@@std@@UAE at XZ) already defined 
in libcpmtd.lib(cerr.obj)
msvcprt.lib(MSVCP71.dll) : error LNK2005: "protected: void __thiscall 
std::strstreambuf::_Init(int,char *,char *,int)" 
(?_Init at strstreambuf@std@@IAEXHPAD0H at Z) already defined in 
libcpmtd.lib(strstrea.obj)
msvcprt.lib(MSVCP71.dll) : error LNK2005: "protected: __thiscall 
std::basic_streambuf<char,struct std::char_traits<char> 
 >::basic_streambuf<char,struct std::char_traits<char> >(void)" 
(??0?$basic_streambuf at DU?$char_traits at D@std@@@std@@IAE at XZ) already defined 
in libcpmtd.lib(cerr.obj)
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: void __thiscall 
std::strstreambuf::freeze(bool)" (?freeze at strstreambuf@std@@QAEX_N at Z) 
already defined in libcpmtd.lib(strstrea.obj)
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: virtual __thiscall 
std::strstreambuf::~strstreambuf(void)" (??1strstreambuf at std@@UAE at XZ) 
already defined in libcpmtd.lib(strstrea.obj)
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: virtual __thiscall 
std::basic_ostream<char,struct std::char_traits<char> 
 >::~basic_ostream<char,struct std::char_traits<char> >(void)" 
(??1?$basic_ostream at DU?$char_traits at D@std@@@std@@UAE at XZ) already defined in 
libcpmtd.lib(cerr.obj)
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: virtual __thiscall 
std::basic_ios<char,struct std::char_traits<char> >::~basic_ios<char,struct 
std::char_traits<char> >(void)" 
(??1?$basic_ios at DU?$char_traits at D@std@@@std@@UAE at XZ) already defined in 
libcpmtd.lib(cerr.obj)
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: __thiscall 
std::basic_ostream<char,struct std::char_traits<char> 
 >::basic_ostream<char,struct std::char_traits<char> >(class 
std::basic_streambuf<char,struct std::char_traits<char> > *,bool)" 
(??0?$basic_ostream at DU?$char_traits at D@std@@@std@@QAE at PAV?$basic_streambuf at DU?$char_traits at D@std@@@1 at _N@Z) 
already defined in libcpmtd.lib(cerr.obj)
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: virtual __thiscall 
std::ostrstream::~ostrstream(void)" (??1ostrstream at std@@UAE at XZ) already 
defined in libcpmtd.lib(strstrea.obj)
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: virtual __thiscall 
std::ios_base::~ios_base(void)" (??1ios_base at std@@UAE at XZ) already defined in 
libcpmtd.lib(ios.obj)
LINK : error LNK2020: unresolved token (0A000026) vtkObjectBase.__dtor
LINK : fatal error LNK1120: 1 unresolved externals

Build log was saved at 
"file://h:\Ma\ITKAppBuildW32\VTKConnect\VTKConnect\Debug\BuildLog.htm"
VTKConnect - 16 error(s), 0 warning(s)


---------------------- Done ----------------------

    Build: 0 succeeded, 1 failed, 0 skipped





More information about the vtkusers mailing list