[vtkusers] transformation in vtk

walaa ahmed loloo_betos_1 at yahoo.com
Sat Apr 25 10:27:23 EDT 2009


hi
 
i need help in vtk i want to make transformation (rotation, translating) to stl image for teeth
i have tried to use boxwidget it works well but i want to display degree of transformation on label or text field  but this failed
i think there is something with mycallback function plz see my code and i will wait for a reply 
plz i need help as soon as possible
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using vtk;
namespace VTK_Eample4
{
public partial class Form1 : Form
{
vtkRenderer ren1 = new vtkRenderer();
vtkActor skin11 = new vtkActor();
vtkActor skin21 = new vtkActor();
vtkActor skin31 = new vtkActor();
vtkActor skin41 = new vtkActor();
vtkActor skin51 = new vtkActor();
vtkActor skin61 = new vtkActor();
vtkActor skin71 = new vtkActor();
vtkActor skin81 = new vtkActor();
vtkTransform t = new vtkTransform();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
 
static void myCallback(vtkObject caller, uint eventId,
object clientData, IntPtr callData)
{
System.Diagnostics.Debug.WriteLine("Callback has been called.");
vtkBoxWidget boxWidget = vtkBoxWidget.SafeDownCast(caller);
if ( null != boxWidget )
{
using (vtkTransform t = new vtkTransform())
{
boxWidget.ScalingEnabledOff();
boxWidget.GetTransform(t);
double[] s = new double[2];
s = t.GetOrientation();
Label label1= new Label();


label1.Text = s.ToString();
label1.Show();
// label1.

boxWidget.GetProp3D().SetUserTransform(t);
}
}
else
{
System.Diagnostics.Debug.WriteLine("Caller is not a box widget.");
}
}
 
void BoxWeidget(vtk.vtkRenderWindow renWin,vtkActor actor)
{

//vtkRenderWindow renWin = new vtkRenderWindow();
renWin.AddRenderer( ren1 );

vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();
iren.SetRenderWindow(renWin);
vtkInteractorStyleTrackballCamera style = 
new vtkInteractorStyleTrackballCamera();
iren.SetInteractorStyle(style);
 
//Here we use a vtkBoxWidget to transform the underlying coneActor (by
//manipulating its transformation matrix). 
vtkBoxWidget boxWidget = new vtkBoxWidget();
//boxWidget.();

boxWidget.SetInteractor(iren);
boxWidget.SetPlaceFactor(1f);

//Place the interactor initially. The input to a 3D widget is used to
//initially position and scale the widget. The EndInteractionEvent is
//observed which invokes the SelectPolygons callback.
boxWidget.SetProp3D(actor);
boxWidget.PlaceWidget();
 
// Now for every interaction event that is generated by the boxWidget,
//call our callback function.
boxWidget.AddObserver((uint) EventIds.InteractionEvent,
new vtkDotNetCallback(myCallback));
//label1.Text = s.ToString();
boxWidget.On();


iren.Initialize();
iren.Start();
vtkWin32OpenGLRenderWindow win32win =
vtkWin32OpenGLRenderWindow.SafeDownCast(renWin);
if ( null != win32win ) win32win.Clean();
}
private void button1_Click(object sender, EventArgs e)
{
// BoxWeidget(this.vtkFormsWindowControl1.GetRenderWindow());
}
private void button2_Click(object sender, EventArgs e)
{
// vtkRenderer ren1 = new vtkRenderer();
vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();
vtkRenderWindow renWin1;
renWin1 = this.vtkFormsWindowControl1.GetRenderWindow();
renWin1.AddRenderer(ren1);
iren.SetRenderWindow(renWin1);
 
 
vtkSTLReader reader11 = new vtkSTLReader();
vtkSTLReader reader21 = new vtkSTLReader();
vtkSTLReader reader31 = new vtkSTLReader();
vtkSTLReader reader41 = new vtkSTLReader();
vtkSTLReader reader51 = new vtkSTLReader();
vtkSTLReader reader61 = new vtkSTLReader();
vtkSTLReader reader71 = new vtkSTLReader();
vtkSTLReader reader81 = new vtkSTLReader();
 
reader11.SetFileName("C:\\Documents and Settings\\Bibo\\Desktop\\transformation isa\\Images\\teeth\\teeth1.stl");
reader21.SetFileName("C:\\Documents and Settings\\Bibo\\Desktop\\transformation isa\\Images\\teeth\\teeth2.stl");
reader31.SetFileName("C:\\Documents and Settings\\Bibo\\Desktop\\transformation isa\\Images\\teeth\\teeth3.stl");
reader41.SetFileName("C:\\Documents and Settings\\Bibo\\Desktop\\transformation isa\\Images\\teeth\\teeth4.stl");
reader51.SetFileName("C:\\Documents and Settings\\Bibo\\Desktop\\transformation isa\\Images\\teeth\\teeth5.stl");
reader61.SetFileName("C:\\Documents and Settings\\Bibo\\Desktop\\transformation isa\\Images\\teeth\\teeth6.stl");
reader71.SetFileName("C:\\Documents and Settings\\Bibo\\Desktop\\transformation isa\\Images\\teeth\\teeth7.stl");
reader81.SetFileName("C:\\Documents and Settings\\Bibo\\Desktop\\transformation isa\\Images\\teeth\\teeth8.stl");
vtkSmoothPolyDataFilter smoother11 = new vtkSmoothPolyDataFilter();
smoother11.SetInputConnection(reader11.GetOutputPort());
smoother11.SetNumberOfIterations(10);
vtkPolyDataNormals skinNormals11 = new vtkPolyDataNormals();
skinNormals11.SetInputConnection(smoother11.GetOutputPort());
skinNormals11.SetFeatureAngle(60.0);
vtkPolyDataMapper skinMapper11 = new vtkPolyDataMapper();
skinMapper11.SetInputConnection(skinNormals11.GetOutputPort());
skinMapper11.ScalarVisibilityOff();
//vtkActor skin11 = new vtkActor();
skin11.SetMapper(skinMapper11);
skin11.GetProperty().SetColor(1.0, 1.0, .9412);
 
 
vtkSmoothPolyDataFilter smoother21 = new vtkSmoothPolyDataFilter();
smoother21.SetInputConnection(reader21.GetOutputPort());
smoother21.SetNumberOfIterations(10);
vtkPolyDataNormals skinNormals21 = new vtkPolyDataNormals();
skinNormals21.SetInputConnection(smoother21.GetOutputPort());
skinNormals21.SetFeatureAngle(60.0);
vtkPolyDataMapper skinMapper21 = new vtkPolyDataMapper();
skinMapper21.SetInputConnection(skinNormals21.GetOutputPort());
skinMapper21.ScalarVisibilityOff();
//vtkActor skin21 = new vtkActor();
skin21.SetMapper(skinMapper21);
skin21.GetProperty().SetColor(1.0, 1.0, .9412);
 
vtkSmoothPolyDataFilter smoother31 = new vtkSmoothPolyDataFilter();
smoother31.SetInputConnection(reader31.GetOutputPort());
smoother31.SetNumberOfIterations(10);
vtkPolyDataNormals skinNormals31 = new vtkPolyDataNormals();
skinNormals31.SetInputConnection(smoother31.GetOutputPort());
skinNormals31.SetFeatureAngle(60.0);
vtkPolyDataMapper skinMapper31 = new vtkPolyDataMapper();
skinMapper31.SetInputConnection(skinNormals31.GetOutputPort());
skinMapper31.ScalarVisibilityOff();
//vtkActor skin31 = new vtkActor();
skin31.SetMapper(skinMapper31);
skin31.GetProperty().SetColor(1.0, 1.0, .9412);
 
 
vtkSmoothPolyDataFilter smoother41 = new vtkSmoothPolyDataFilter();
smoother41.SetInputConnection(reader41.GetOutputPort());
smoother41.SetNumberOfIterations(10);
vtkPolyDataNormals skinNormals41 = new vtkPolyDataNormals();
skinNormals41.SetInputConnection(smoother41.GetOutputPort());
skinNormals41.SetFeatureAngle(60.0);
vtkPolyDataMapper skinMapper41 = new vtkPolyDataMapper();
skinMapper41.SetInputConnection(skinNormals41.GetOutputPort());
skinMapper41.ScalarVisibilityOff();
//vtkActor skin41 = new vtkActor();
skin41.SetMapper(skinMapper41);
skin41.GetProperty().SetColor(1.0, 1.0, .9412);
 
vtkSmoothPolyDataFilter smoother51 = new vtkSmoothPolyDataFilter();
smoother51.SetInputConnection(reader51.GetOutputPort());
smoother51.SetNumberOfIterations(10);
vtkPolyDataNormals skinNormals51 = new vtkPolyDataNormals();
skinNormals51.SetInputConnection(smoother51.GetOutputPort());
skinNormals51.SetFeatureAngle(60.0);
vtkPolyDataMapper skinMapper51 = new vtkPolyDataMapper();
skinMapper51.SetInputConnection(skinNormals51.GetOutputPort());
skinMapper51.ScalarVisibilityOff();
//vtkActor skin51 = new vtkActor();
skin51.SetMapper(skinMapper51);
skin51.GetProperty().SetColor(1.0, 1.0, .9412);
vtkSmoothPolyDataFilter smoother61 = new vtkSmoothPolyDataFilter();
smoother61.SetInputConnection(reader61.GetOutputPort());
smoother61.SetNumberOfIterations(10);
vtkPolyDataNormals skinNormals61 = new vtkPolyDataNormals();
skinNormals61.SetInputConnection(smoother61.GetOutputPort());
skinNormals61.SetFeatureAngle(60.0);
vtkPolyDataMapper skinMapper61 = new vtkPolyDataMapper();
skinMapper61.SetInputConnection(skinNormals61.GetOutputPort());
skinMapper61.ScalarVisibilityOff();
//vtkActor skin61 = new vtkActor();
skin61.SetMapper(skinMapper61);
skin61.GetProperty().SetColor(1.0, 1.0, .9412);
 
vtkSmoothPolyDataFilter smoother71 = new vtkSmoothPolyDataFilter();
smoother71.SetInputConnection(reader71.GetOutputPort());
smoother71.SetNumberOfIterations(10);
vtkPolyDataNormals skinNormals71 = new vtkPolyDataNormals();
skinNormals71.SetInputConnection(smoother71.GetOutputPort());
skinNormals71.SetFeatureAngle(60.0);
vtkPolyDataMapper skinMapper71 = new vtkPolyDataMapper();
skinMapper71.SetInputConnection(skinNormals71.GetOutputPort());
skinMapper71.ScalarVisibilityOff();
//vtkActor skin71 = new vtkActor();
skin71.SetMapper(skinMapper71);
skin71.GetProperty().SetColor(1.0, 1.0, .9412);
 
vtkSmoothPolyDataFilter smoother81 = new vtkSmoothPolyDataFilter();
smoother81.SetInputConnection(reader81.GetOutputPort());
smoother81.SetNumberOfIterations(10);
vtkPolyDataNormals skinNormals81 = new vtkPolyDataNormals();
skinNormals81.SetInputConnection(smoother81.GetOutputPort());
skinNormals81.SetFeatureAngle(60.0);
vtkPolyDataMapper skinMapper81 = new vtkPolyDataMapper();
skinMapper81.SetInputConnection(skinNormals81.GetOutputPort());
//skinMapper81.ScalarVisibilityOff();
vtkActor skin81 = new vtkActor();
skin81.SetMapper(skinMapper81);
skin81.GetProperty().SetColor(1.0, 1.0, .9412);
/// vtkRenderer ManRender = new vtkRenderer();
ren1.AddActor(skin11);
ren1.AddActor(skin21);
ren1.AddActor(skin31);
ren1.AddActor(skin41);
ren1.AddActor(skin51);
ren1.AddActor(skin61);
ren1.AddActor(skin71);
ren1.AddActor(skin81);
 
ren1.SetBackground(0.1, 0.2, 0.4);
renWin1.AddRenderer(ren1);
 
// vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();
iren.SetRenderWindow(renWin1);
}
private void button3_Click(object sender, EventArgs e)
{
switch (listBox1.SelectedIndex)
{
case 0:
{

BoxWeidget(this.vtkFormsWindowControl1.GetRenderWindow(), skin11);
}
break;
case 1:
{
BoxWeidget(this.vtkFormsWindowControl1.GetRenderWindow(), skin21);
}
break;
case 2:
{
BoxWeidget(this.vtkFormsWindowControl1.GetRenderWindow(), skin31);
}
break;
case 3:
{
BoxWeidget(this.vtkFormsWindowControl1.GetRenderWindow(), skin41);
}
break;
case 4:
{
BoxWeidget(this.vtkFormsWindowControl1.GetRenderWindow(), skin51);
}
break;
default:
MessageBox.Show("Please select the distance you want to show from the list");
break;
}
}
private void label1_Click(object sender, EventArgs e)
{
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
 
 
}



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090425/a542dd4a/attachment.htm>


More information about the vtkusers mailing list