Zeb Rehman

Zeb Rehman

  • NA
  • 67
  • 46.9k

Show reulting image of vtk in Win Form

May 3 2011 10:14 AM
Hi everybody i want to show the resulting image of the given below code in windows form. There should be a button under which i have to write this vtk code and when i press the button it show me the resulting image in the form. Please can somebody tell me how to perform this task. The code should be in C#....... I shall be really thankful to you
.............................................Thanks in advance

//VTK code.
#include "vtkSmartPointer.h"
#include "vtkStructuredPointsReader.h"
#include "vtkThresholdPoints.h"
#include "vtkMaskPoints.h"
#include "vtkConeSource.h"
#include "vtkGlyph3D.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkStructuredPoints.h"
#include "vtkOutlineFilter.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkContourFilter.h"
#include "vtkProperty.h"

//The goal of this project/lab is primarily to represent/show the flow of blood in the carotid artery.
//The data is provided not as an image (although one can have even image data from an MRA) but as a .vtk
//file. These files are typically used to contain text data. Other kinds of files such as XML files can also
//be used for the VTK data. For more details on the VTK dataformats check www.vtk.org/VTK/img/file-formats.pdf

//In this lab we are going to create a pipeline which starts from a vtkStructuredPointsReader (used to read) the
//.vtk files such as the carotid.vtk file which we are going to use today. Then the pipeline tri-furcates into three
//pipelines: (i) The piprline for showing the vector flow; (ii) Pipeline for showing the outline; (iii) Pipeline for
//displaying the boundaries of the arteries.

int main()
{
//THIS IS THE FIRST PIPELINE FOR SHOWING THE VECTOR FLOW.
//Create a data reader of type vtkStructuredPointsReader since we are dealing with .vtk files and
//read the carotid.vtk datafile
vtkSmartPointer<vtkStructuredPointsReader> DataReader = vtkSmartPointer<vtkStructuredPointsReader>::New();
DataReader->SetFileName("carotid.vtk");
// So now your data source has been specified.

//Create the Threshold Points Object
vtkSmartPointer<vtkThresholdPoints> Threshold = vtkSmartPointer<vtkThresholdPoints>::New();
Threshold->SetInput(DataReader->GetOutput());
Threshold->ThresholdByUpper(200);

//The role of the vtkMaskPoints is basically to mask/ignore certain data points. Here we are reading every
//10th data point and then ignoring the next 9 daata points, if we were to read all datapoints in that
//case you would have two many vectors in the
// display and you wont be able to get a clear picture of the flow. So this filter is used to parse and
// ignore parts of the data.
vtkSmartPointer<vtkMaskPoints> Mask = vtkSmartPointer<vtkMaskPoints>::New();
Mask->SetInput(Threshold->GetOutput());
Mask->SetOnRatio(10); //Take every 10th Point

//We are using the cone as the structure which will be used to display each and every vector.
vtkSmartPointer<vtkConeSource> Cone = vtkSmartPointer<vtkConeSource>::New();
Cone->SetResolution(3);
Cone->SetHeight(1);
Cone->SetRadius(0.25);

//This class integrates the data from the pipeline with the geometric object used for display such as
//the cone in this example. You can use any kind of glyph that you want, arrow etc.
vtkSmartPointer<vtkGlyph3D> Cones = vtkSmartPointer<vtkGlyph3D>::New();
Cones->SetInput(Mask->GetOutput());
Cones->SetSource(Cone->GetOutput());
Cones->SetScaleFactor(0.5);
Cones->SetScaleModeToScaleByVector();

//Mapper you guys already know !!!
vtkSmartPointer<vtkPolyDataMapper> Mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
Mapper->SetInput(Cones->GetOutput());
Mapper->SetScalarRange(2,10); //Color coding of the glyphs

//Same for Actor !!!
vtkSmartPointer<vtkActor> FlowActor = vtkSmartPointer<vtkActor>::New();
FlowActor->SetMapper(Mapper);


//THIS IS THE SECOND PIPELINE FOR SHOWING THE OUTLINE OF THE BOUNDING BOX.
//Code for building the outline

//Create an outline filter as you guys have done multiple times previously. and connect it to the
//data reader so that the program can get the dimensions of the data and make an outline around it.
vtkSmartPointer<vtkOutlineFilter> OutlineFilter = vtkSmartPointer<vtkOutlineFilter>::New();
OutlineFilter->SetInput(DataReader->GetOutput());

//Connect the outline filter to Mapper.
vtkSmartPointer<vtkPolyDataMapper> OutlineMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
OutlineMapper->SetInput(OutlineFilter->GetOutput());

//Connect the Mapper to Actor etc....
vtkSmartPointer<vtkActor> OutlineActor = vtkSmartPointer<vtkActor>::New();
OutlineActor->SetMapper(OutlineMapper);


//THIS IS THE THIRDLINE PIPELINE FOR SHOWING THE SEMI-OPAQUE ARTERIES USING ISOSURFACES.
//Code for showing the arteries
//Create a contour filter and connect it to the dataset with a specified iso-value.
vtkSmartPointer<vtkContourFilter> Arteries = vtkSmartPointer<vtkContourFilter>::New();
Arteries->SetInput(DataReader->GetOutput());
Arteries->SetValue(0,190);

//Mapper
vtkSmartPointer<vtkPolyDataMapper> ArteryMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
ArteryMapper->SetInput(Arteries->GetOutput());
ArteryMapper->ScalarVisibilityOff();

//Actor
vtkSmartPointer<vtkActor> ArteryActor = vtkSmartPointer<vtkActor>::New();
ArteryActor->SetMapper(ArteryMapper);
vtkProperty* Temp = ArteryActor->GetProperty();
Temp->SetRepresentationToWireframe();
Temp->SetOpacity(0.25);

//SET UP THE THREE RENDERING COMPONENTS (RENDERER, WINDOW, INTERACTOR) AND CONNECT THEM TO THE THREE PIPELINES
vtkSmartPointer<vtkRenderer> Renderer = vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> RenderWindow = vtkSmartPointer<vtkRenderWindow>::New();
RenderWindow->AddRenderer(Renderer);
vtkSmartPointer<vtkRenderWindowInteractor> Interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
Interactor->SetRenderWindow(RenderWindow);

//Connect the rendering components with the rest of the pipeline
Renderer->AddActor(OutlineActor);
Renderer->AddActor(FlowActor);
Renderer->AddActor(ArteryActor);

//Set Window Size and Background.
RenderWindow->SetSize(500, 500);
Renderer->SetBackground(0.1,0.2,0.4);

//And MAGIC !!!!!!!
Interactor->Initialize();
Interactor->Start();

return 0;
}