I’m trying the ReadPLY example and it works. However, when I move the call to Readply()
from renderWindowControl1_Load1
to a a button click event, it doesn’t work. Is there a way I can do this in the button click event?
The vtkRenderer is not available until the window control has loaded, so you need to disable your button until you can obtain a reference to it (in the load event). Then after adding the actor, in the click event renderWindowControl1.Invalidate()
@Todd - This is what I have, but it still doesn’t work. I wasn’t able to attach the ply file, but
you can find it here
`
public partial class Form1 : Form
{
private vtkRenderWindow renderWindow;
private vtkRenderer renderer;
public Form1()
{
InitializeComponent();
}
private void renderWindowControl1_Load(object sender, EventArgs e)
{
try
{
button1.Enabled = false;
renderWindow = renderWindowControl1.RenderWindow;
renderer = renderWindow.GetRenderers().GetFirstRenderer();
//ReadPLY();
button1.Enabled = true;
}
catch (Exception)
{
throw;
}
}
private void ReadPLY()
{
string filePath = @"C:\temp\airplane.ply";
vtkPLYReader reader = vtkPLYReader.New();
reader.SetFileName(filePath);
reader.Update();
vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
mapper.SetInputConnection(reader.GetOutputPort());
vtkActor actor = vtkActor.New();
actor.SetMapper(mapper);
renderer.AddActor(actor);
}
private void button1_Click(object sender, EventArgs e)
{
try
{
ReadPLY();
renderWindowControl1.Invalidate();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
`
I assume when you say “it doesn’t work” you mean it doesn’t display? Please be more specific.
in the button click event try
renderer.ResetCamera();
renderWindowControl1.Invalidate();
Sorry, yes, it didn’t display anything. I added renderer.ResetCamera()
and now it does display, so thank you!