-- How to link OpenCV with VTK (Viz module)

Linker->Input->Additional Dependencies:

-- Debug
opencv_core450d.lib
opencv_highgui450d.lib
opencv_imgcodecs450d.lib
opencv_imgproc450d.lib
opencv_flann450d.lib
opencv_viz450d.lib

-- Release
opencv_core450.lib
opencv_highgui450.lib
opencv_imgcodecs450.lib
opencv_imgproc450.lib
opencv_flann450.lib
opencv_viz450.lib


-- How to open VTK window in OpenCV and display some mesh:
#include <opencv2/opencv.hpp>
#include <opencv2/viz.hpp>
...
cv::viz::Viz3d window( "VD-SPH" );
window.spinOnce( 1, true );

cv::Vec3f cam_pos( 1.0f, 2.0f, 1.5f ), cam_focal_point( 0.0f, 0.0f, 0.25f ), cam_y_dir( 0.0f, 0.0f, -1.0f );
cv::Affine3f cam_pose = cv::viz::makeCameraPose( cam_pos, cam_focal_point, cam_y_dir );
window.setViewerPose( cam_pose );

cv::viz::WCube domain( cv::Point3d( -0.5, -0.5, 0.0 ), cv::Point3d( 0.5, 0.5, 1.0 ), true, cv::viz::Color::red() );
window.showWidget( "domain", domain );

cv::viz::WPlane plane( cv::Size2d( 1.0, 1.0 ), cv::viz::Color::yellow() );
window.showWidget( "plane", plane );
...
// TODO fill an array of triangles with output of Marching Cubes alg.
...
std::vector<cv::Point3d> cloud;
cloud.reserve( triangles.size() * 3 );
cv::Mat polygon = cv::Mat( 1, int( triangles.size() ) * 4, CV_32S );

for ( int i = 0, j = 0, k = 0; i < int(triangles.size()); ++i)		
{
  const Triangle & triangle = triangles[i];
  const Vector3f & v0 = triangle.vertices[0];
  const Vector3f & v1 = triangle.vertices[1];
  const Vector3f & v2 = triangle.vertices[2];

  cloud.push_back( cv::Point3f( v0.x, v0.y, v0.z ) );
  cloud.push_back( cv::Point3f( v1.x, v1.y, v1.z ) );
  cloud.push_back( cv::Point3f( v2.x, v2.y, v2.z ) );
 
  polygon.at<int>( 0, j++ ) = 3; // vertices count
  polygon.at<int>( 0, j++ ) = k++;
  polygon.at<int>( 0, j++ ) = k++;
  polygon.at<int>( 0, j++ ) = k++;
}

cv::viz::WMesh mesh( cloud, polygon );
window.showWidget( "Mesh", mesh );
...
window.spinOnce( 1, true );