Hi Dieter,<br /><br />
it took me the last three hours to figure it out. Whenever we should meet: Toché! ;-)<br /><br />
Here we go:<br />
<pre> <span style=' color: Green;'>// Define interaction style</span>
<span style=' color: Blue;'>public</span> <span style=' color: Blue;'>class</span> InteractorStyle : vtkInteractorStyleRubberBandPick {
<span style=' color: Blue;'>private</span> vtkPolyData Points;
<span style=' color: Blue;'>private</span> vtkActor SelectedActor;
<span style=' color: Blue;'>private</span> vtkDataSetMapper SelectedMapper;
<span style=' color: Blue;'>private</span> <span style=' color: Blue;'>bool</span> IsInRubberbandMode;
<span style=' color: Blue;'>public</span> InteractorStyle() {
IsInRubberbandMode = <span style=' color: Maroon;'>false</span>;
<span style=' color: Blue;'>this</span>.SelectedMapper = vtkDataSetMapper.New();
<span style=' color: Blue;'>this</span>.SelectedActor = vtkActor.New();
<span style=' color: Blue;'>this</span>.SelectedActor.SetMapper(SelectedMapper);
<span style=' color: Blue;'>this</span>.LeftButtonReleaseEvt += <span style=' color: Blue;'>new</span> vtkObjectEventHandler(InteractorStyle_LeftButtonReleaseEvt);
<span style=' color: Blue;'>this</span>.CharEvt += <span style=' color: Blue;'>new</span> vtkObjectEventHandler(InteractorStyle_CharEvt);
}
<span style=' color: Blue;'>void</span> InteractorStyle_CharEvt(vtkObject sender, vtkObjectEventArgs e) {
<span style=' color: Green;'>// forward event to base class</span>
<span style=' color: Blue;'>base</span>.OnChar();
vtkInteractorStyleRubberBandPick caller = e.Caller <span style=' color: Blue;'>as</span> vtkInteractorStyleRubberBandPick;
<span style=' color: Blue;'>if</span>(caller != <span style=' color: Blue;'>null</span>) {
<span style=' color: Blue;'>switch</span>(caller.GetInteractor().GetKeyCode()) {
<span style=' color: Green;'>// r oder R is pressed</span>
<span style=' color: Blue;'>case</span> <span style=' color: Maroon;'>82</span>:
<span style=' color: Blue;'>case</span> <span style=' color: Maroon;'>114</span>:
IsInRubberbandMode = !IsInRubberbandMode;
<span style=' color: Blue;'>break</span>;
}
}
}
<span style=' color: Blue;'>void</span> InteractorStyle_LeftButtonReleaseEvt(vtkObject sender, vtkObjectEventArgs e) {
<span style=' color: Green;'>// forward event to base class</span>
<span style=' color: Blue;'>base</span>.OnLeftButtonUp();
<span style=' color: Blue;'>if</span>(!IsInRubberbandMode)
<span style=' color: Blue;'>return</span>;
Debug.WriteLine(<span style=' color: Maroon;'>"InteractorStyle_LeftButtonReleaseEvt"</span>);
vtkPlanes frustum = ( (vtkAreaPicker)<span style=' color: Blue;'>this</span>.GetInteractor().GetPicker() ).GetFrustum();
vtkExtractGeometry extractGeometry = vtkExtractGeometry.New();
extractGeometry.SetImplicitFunction(frustum);
extractGeometry.SetInput(<span style=' color: Blue;'>this</span>.Points);
extractGeometry.Update();
vtkVertexGlyphFilter glyphFilter = vtkVertexGlyphFilter.New();
glyphFilter.SetInputConnection(extractGeometry.GetOutputPort());
glyphFilter.Update();
vtkPolyData selected = glyphFilter.GetOutput();
Debug.WriteLine(<span style=' color: Maroon;'>"Selected "</span> + selected.GetNumberOfPoints() + <span style=' color: Maroon;'>" points."</span>);
Debug.WriteLine(<span style=' color: Maroon;'>"Selected "</span> + selected.GetNumberOfCells() + <span style=' color: Maroon;'>" cells."</span>);
<span style=' color: Blue;'>this</span>.SelectedMapper.SetInput(selected);
<span style=' color: Blue;'>this</span>.SelectedMapper.ScalarVisibilityOff();
vtkIdTypeArray ids = vtkIdTypeArray.SafeDownCast(selected.GetPointData().GetArray(<span style=' color: Maroon;'>"OriginalIds"</span>));
<span style=' color: Blue;'>for</span>(<span style=' color: Blue;'>int</span> i = <span style=' color: Maroon;'>0</span>; i < ids.GetNumberOfTuples(); i++) {
Debug.WriteLine(<span style=' color: Maroon;'>"Id "</span> + i + <span style=' color: Maroon;'>" : "</span> + ids.GetValue(i));
}
<span style=' color: Blue;'>this</span>.SelectedActor.GetProperty().SetColor(<span style=' color: Maroon;'>1</span><span style=' color: Maroon;'>.0</span>, <span style=' color: Maroon;'>0</span><span style=' color: Maroon;'>.0</span>, <span style=' color: Maroon;'>0</span><span style=' color: Maroon;'>.0</span>); <span style=' color: Green;'>//(R,G,B)</span>
<span style=' color: Blue;'>this</span>.SelectedActor.GetProperty().SetPointSize(<span style=' color: Maroon;'>5</span>);
<span style=' color: Blue;'>base</span>.GetCurrentRenderer().AddActor(SelectedActor);
<span style=' color: Blue;'>this</span>.GetInteractor().GetRenderWindow().Render();
<span style=' color: Blue;'>this</span>.HighlightProp(<span style=' color: Blue;'>null</span>);
}
<span style=' color: Blue;'>public</span> <span style=' color: Blue;'>void</span> SetPoints(vtkPolyData points) {
<span style=' color: Blue;'>this</span>.Points = points;
}
};
<span style=' color: Blue;'>private</span> <span style=' color: Blue;'>void</span> HighLightPoints() {
vtkPointSource pointSource = vtkPointSource.New();
pointSource.SetNumberOfPoints(<span style=' color: Maroon;'>20</span>);
pointSource.Update();
vtkIdFilter idFilter = vtkIdFilter.New();
idFilter.SetInputConnection(pointSource.GetOutputPort());
idFilter.SetIdsArrayName(<span style=' color: Maroon;'>"OriginalIds"</span>);
idFilter.Update();
vtkDataSetSurfaceFilter surfaceFilter = vtkDataSetSurfaceFilter.New();
surfaceFilter.SetInputConnection(idFilter.GetOutputPort());
surfaceFilter.Update();
vtkPolyData input = surfaceFilter.GetOutput();
<span style=' color: Green;'>// Create a mapper and actor</span>
vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
mapper.SetInputConnection(input.GetProducerPort());
mapper.ScalarVisibilityOff();
vtkActor actor = vtkActor.New();
actor.SetMapper(mapper);
actor.GetProperty().SetPointSize(<span style=' color: Maroon;'>5</span>);
<span style=' color: Green;'>// Visualize</span>
<span style=' color: Green;'>// get a reference to the renderwindow of our renderWindowControl1</span>
vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
<span style=' color: Green;'>// renderer</span>
vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer();
<span style=' color: Green;'>// set background color</span>
renderer.SetBackground(<span style=' color: Maroon;'>.2</span>, <span style=' color: Maroon;'>.3</span>, <span style=' color: Maroon;'>.4</span>);
<span style=' color: Green;'>// tell interactor to use an area picker</span>
vtkAreaPicker areaPicker = vtkAreaPicker.New();
vtkRenderWindowInteractor renderWindowInteractor = renderWindow.GetInteractor();
renderWindowInteractor.SetPicker(areaPicker);
<span style=' color: Green;'>// tell interactor to use our own style inherit from vtkInteractorStyleRubberBandPick</span>
InteractorStyle style = <span style=' color: Blue;'>new</span> InteractorStyle();
<span style=' color: Green;'>// give our style a reference to the polydata</span>
style.SetPoints(input);
renderWindowInteractor.SetInteractorStyle(style);
renderer.AddActor(actor);
renderWindow.Render();
}
</pre>
<br />
I'm a bit confused because inheritance from vtkInteractorStyleRubberBandPick is working more or less except methods can't be overridden. I will investigate further in a calm hour.<br /><br />
with best regards<br />
Jochen
        
<br/><hr align="left" width="300" />
View this message in context: <a href="http://vtk.1045678.n5.nabble.com/vtkCallbackCommand-in-ActiveViz-tp5714143p5714204.html">Re: vtkCallbackCommand in ActiveViz</a><br/>
Sent from the <a href="http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html">VTK - Users mailing list archive</a> at Nabble.com.<br/>