<div dir="ltr">Hi Eric,<div>Thanks for the response. </div><div>they `actor.key` hack works fine in python but what would be equivalent of that in c++?</div><div>I don't think there is an easy way in C++ and that's why I was going through vtkinformationStringKey.</div><div>Any thoughts?</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Nov 7, 2018 at 1:57 AM Fahlgren, Eric <<a href="mailto:eric.fahlgren@smith-nephew.com">eric.fahlgren@smith-nephew.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-US" link="blue" vlink="purple">
<div class="m_-2728531087243161357WordSection1">
<p class="MsoNormal">I can’t tell what version of VTK you are running, but your code fails for me on the GetProperty().GetInformation() calls (I’m using VTK 8.0 today), so I just hacked a local member on the actor:<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"># info = actor.GetProperty().GetInformation()<u></u><u></u></p>
<p class="MsoNormal"># key = vtk.vtkInformationStringKey.MakeKey("CPHY_ID", "vtkActor")<u></u><u></u></p>
<p class="MsoNormal"># info.Set(key, "CON_"+str(i))<u></u><u></u></p>
<p class="MsoNormal"> actor.key = "CON_"+str(i)<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Ran with that, and the “CON_nnn” values are reported as expected.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><b>From:</b> vtkusers <<a href="mailto:vtkusers-bounces@public.kitware.com" target="_blank">vtkusers-bounces@public.kitware.com</a>> <b>
On Behalf Of </b>Abhishek<br>
<b>Sent:</b> Monday, November 5, 2018 9:40 PM<br>
<b>To:</b> <a href="mailto:vtkusers@public.kitware.com" target="_blank">vtkusers@public.kitware.com</a><br>
<b>Subject:</b> Re: [vtkusers] Retriving vtkInformation from the actor<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">Anyone? how to determine which object it is in the mouse event?<u></u><u></u></p>
<div>
<div>
<p class="MsoNormal">On Mon, Nov 5, 2018 at 4:10 PM Abhishek <<a href="mailto:abhishekworld@gmail.com" target="_blank">abhishekworld@gmail.com</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal">Hello,<u></u><u></u></p>
<div>
<p class="MsoNormal">I have multiple actors in the scene, and I have re-implemented the vtkInteractorStyleTrackballCamera to capture the click event on them (modified
<a href="https://lorensen.github.io/VTKExamples/site/Python/Interaction/HighlightPickedActor/" target="_blank">
https://lorensen.github.io/VTKExamples/site/Python/Interaction/HighlightPickedActor/</a>)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">In the click event, I want to know which actor has been clicked to do so I am adding vtkInformationStringKey to every actor. But at the click event, I am not able to retrieve it back.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Please let me know what am I missing? Or what am I doing wrong?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Here is my code: <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">```<u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">import vtk<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">NUMBER_OF_SPHERES = 10<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">class MouseInteractorHighLightActor(vtk.vtkInteractorStyleTrackballCamera):<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> def __init__(self, parent=None):<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> self.AddObserver("LeftButtonPressEvent", self.leftButtonPressEvent)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> self.LastPickedActor = None<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> self.LastPickedProperty = vtk.vtkProperty()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> def leftButtonPressEvent(self, obj, event):<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> clickPos = self.GetInteractor().GetEventPosition()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> picker = vtk.vtkPropPicker()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> picker.Pick(clickPos[0], clickPos[1], 0, self.GetDefaultRenderer())<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> # get the new<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> self.NewPickedActor = picker.GetActor()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> # If something was selected<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> if self.NewPickedActor:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> # get the information from the new Actor<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> info = self.NewPickedActor.GetProperty().GetInformation()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> # prepare the key<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> key = vtk.vtkInformationStringKey.MakeKey("CPHY_ID", "vtkActor")<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> # get the value for the key<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> id = info.Get(key)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> print("Id is : ")<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> print(id)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> # If we picked something before, reset its property<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> if self.LastPickedActor:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> self.LastPickedActor.GetProperty().DeepCopy(self.LastPickedProperty)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> # Save the property of the picked actor so that we can<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> # restore it next time<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> self.LastPickedProperty.DeepCopy(self.NewPickedActor.GetProperty())<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> # Highlight the picked actor by changing its properties<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> self.NewPickedActor.GetProperty().SetColor(1.0, 0.0, 0.0)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> self.NewPickedActor.GetProperty().SetDiffuse(1.0)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> self.NewPickedActor.GetProperty().SetSpecular(0.0)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> # save the last picked actor<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> self.LastPickedActor = self.NewPickedActor<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> self.OnLeftButtonDown()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> return<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"># A renderer and render window<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">renderer = vtk.vtkRenderer()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">renderer.SetBackground(.3, .4, .5)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">renwin = vtk.vtkRenderWindow()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">renwin.AddRenderer(renderer)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"># An interactor<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">interactor = vtk.vtkRenderWindowInteractor()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">interactor.SetRenderWindow(renwin)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"># add the custom style<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">style = MouseInteractorHighLightActor()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">style.SetDefaultRenderer(renderer)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">interactor.SetInteractorStyle(style)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"># Add spheres to play with<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">for i in range(NUMBER_OF_SPHERES):<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> source = vtk.vtkSphereSource()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> # random position and radius<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> x = vtk.vtkMath.Random(-5, 5)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> y = vtk.vtkMath.Random(-5, 5)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> z = vtk.vtkMath.Random(-5, 5)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> radius = vtk.vtkMath.Random(.5, 1.0)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> source.SetRadius(radius)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> source.SetCenter(x, y, z)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> source.SetPhiResolution(11)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> source.SetThetaResolution(21)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> mapper = vtk.vtkPolyDataMapper()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> mapper.SetInputConnection(source.GetOutputPort())<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> actor = vtk.vtkActor()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> actor.SetMapper(mapper)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> r = vtk.vtkMath.Random(.4, 1.0)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> g = vtk.vtkMath.Random(.4, 1.0)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> b = vtk.vtkMath.Random(.4, 1.0)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> actor.GetProperty().SetDiffuseColor(r, g, b)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> actor.GetProperty().SetDiffuse(.8)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> actor.GetProperty().SetSpecular(.5)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> actor.GetProperty().SetSpecularColor(1.0, 1.0, 1.0)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> actor.GetProperty().SetSpecularPower(30.0)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> info = actor.GetProperty().GetInformation()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> key = vtk.vtkInformationStringKey.MakeKey("CPHY_ID", "vtkActor")<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> info.Set(key, "SPH_"+str(i))<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> #actor.GetProperty().SetInformation(info)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> renderer.AddActor(actor)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">for i in range(NUMBER_OF_SPHERES):<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> source = vtk.vtkConeSource()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> # random position and radius<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> x = vtk.vtkMath.Random(-8, 5)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> y = vtk.vtkMath.Random(-8, 5)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> z = vtk.vtkMath.Random(-8, 5)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> radius = vtk.vtkMath.Random(.5, 1.0)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> angle = vtk.vtkMath.Random(5, 10)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> source.SetAngle(angle)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> source.SetRadius(radius)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> source.SetCenter(x, y, z)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> # source.SetPhiResolution(11)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> # source.SetThetaResolution(21)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> mapper = vtk.vtkPolyDataMapper()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> mapper.SetInputConnection(source.GetOutputPort())<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> actor = vtk.vtkActor()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> actor.SetMapper(mapper)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> r = vtk.vtkMath.Random(.4, 1.0)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> g = vtk.vtkMath.Random(.4, 1.0)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> b = vtk.vtkMath.Random(.4, 1.0)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> actor.GetProperty().SetDiffuseColor(r, g, b)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> actor.GetProperty().SetDiffuse(.8)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> actor.GetProperty().SetSpecular(.5)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> actor.GetProperty().SetSpecularColor(1.0, 1.0, 1.0)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> actor.GetProperty().SetSpecularPower(30.0)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> info = actor.GetProperty().GetInformation()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> key = vtk.vtkInformationStringKey.MakeKey("CPHY_ID", "vtkActor")<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> info.Set(key, "CON_"+str(i))<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> #actor.GetProperty().SetInformation(info)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> renderer.AddActor(actor)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"># Start<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">interactor.Initialize()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">interactor.Start()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">```<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Regards,<u></u><u></u></p>
</div>
<p class="MsoNormal">-- <u></u><u></u></p>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">Abhishek<br>
<a href="http://zeroth.me" target="_blank">http://zeroth.me</a><u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><br clear="all">
<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<p class="MsoNormal">-- <u></u><u></u></p>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">Abhishek<br>
<a href="http://zeroth.me" target="_blank">http://zeroth.me</a><u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Abhishek<br><a href="http://zeroth.me" target="_blank">http://zeroth.me</a><br><br></div></div></div>