<html><body><div style="color:#000; background-color:#fff; font-family:arial, helvetica, sans-serif;font-size:12pt"><div><span>Hi,</span></div>
<div><br>
<span></span></div>
<div><span>So, no one use selection with vtk ?</span></div><div><br></div><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt;"><div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"><font face="Arial" size="2"><hr size="1"><b><span style="font-weight:bold;">De :</span></b> R M <mlokida@yahoo.fr><br><b><span style="font-weight: bold;">À :</span></b> "vtkusers@vtk.org" <vtkusers@vtk.org><br><b><span style="font-weight: bold;">Envoyé le :</span></b> Lundi 17 Octobre 2011 15h52<br><b><span style="font-weight: bold;">Objet :</span></b> [vtkusers] Re : vtkHarswareSelector and vtkMultiBlockDataSet<br></font><br><meta http-equiv="x-dns-prefetch-control" content="off"><div id="yiv133207883"><div><div style="color:#000;background-color:#fff;font-family:arial, helvetica, sans-serif;font-size:12pt;"><div><span>Here's a sample code a</span><span>dapted from
http://www.vtk.org/Wiki/VTK/Examples/Cxx/Broken/Filtering/ExtractVisibleCells<br></span></div><div><br></div><div>Except my reader that make a vtkMultiBlockDataSet of vtkUnstructuredGrid the code is the same.</div><div><br></div><div>May be someone could tell me what's wrong with the selections I want to do.<br></div><div><br><span></span></div><div><span>#include <vtkSphereSource.h><br>#include <vtkPolyData.h><br>#include <vtkSmartPointer.h><br>#include <vtkPolyDataMapper.h><br>#include <vtkActor.h><br>#include <vtkRenderWindow.h><br>#include <vtkRenderer.h><br>#include <vtkRenderWindowInteractor.h><br>#include <vtkHardwareSelector.h><br>#include <vtkInteractorStyleTrackballCamera.h><br>#include
<vtkObjectFactory.h><br>#include <vtkRendererCollection.h><br>#include <vtkDataSetMapper.h><br>#include <vtkExtractSelection.h><br>#include <vtkSelection.h><br>#include <vtkProperty.h><br>#include <vtkMultiBlockDataSet.h><br>#include <vtkUnstructuredGrid.h><br>#include <vtkGeometryFilter.h><br>#include <vtkFieldData.h><br>#include <vtkSelectionNode.h><br>#include <vtkIdTypeArray.h><br>#include <vtkDataSetAttributes.h><br>#include <vtkInformation.h><br><br>// Define interaction style<br>class KeyPressInteractorStyle : public vtkInteractorStyleTrackballCamera<br>{<br>public:<br> static KeyPressInteractorStyle* New();<br> vtkTypeMacro(KeyPressInteractorStyle, vtkInteractorStyleTrackballCamera);<br><br> virtual void OnKeyPress()<br> {<br> // Get the
keypress<br> std::string key = this->Interactor->GetKeySym();<br><br> // "s" for "s"elect<br> if(key.compare("s") == 0)<br> {<br> vtkSmartPointer<vtkHardwareSelector> selector = vtkSmartPointer<vtkHardwareSelector>::New();<br> selector->SetRenderer(this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer());<br> int* temp = this->Interactor->GetRenderWindow()->GetSize();<br> unsigned int windowSize[4];<br> windowSize[0] = temp[2];<br>
windowSize[1] = temp[3];<br> windowSize[2] = temp[0];<br> windowSize[3] = temp[1];<br><br> /*<br> for(unsigned int i = 0; i < 4; i++)<br> {<br> windowSize[i] = temp[i];<br> }<br> */<br> <br> selector->SetArea(windowSize);<br> selector->SetFieldAssociation(vtkDataObject::FIELD_ASSOCIATION_CELLS);<br>
vtkSelection* selection = selector->Select();<br> <br> vtkSmartPointer<vtkExtractSelection> extractSelection = vtkSmartPointer<vtkExtractSelection>::New();<br> extractSelection->DebugOn();<br> extractSelection->SetInput(0, mbds);<br> extractSelection->SetInput(1, selection);<br> extractSelection->Update();<br><br> vtkMultiBlockDataSet *output = vtkMultiBlockDataSet::SafeDownCast( extractSelection->GetOutput() );<br><br> for(int i = 0; i <
output->GetNumberOfBlocks(); ++i)<br> {<br> vtkUnstructuredGrid * usg = vtkUnstructuredGrid::SafeDownCast( output->GetBlock(i) );<br><br> // Add the selection to the renderer<br> if(usg)<br> { <br> vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();<br>
mapper->SetInput(usg);<br> <br> vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();<br> actor->SetMapper(mapper);<br> actor->GetProperty()->SetColor(1,0,0);<br> this->Renderer->AddActor(actor);<br> } <br> }<br> }<br>
<br> // Forward events<br> vtkInteractorStyleTrackballCamera::OnKeyPress();<br> }<br><br> vtkMultiBlockDataSet * mbds;<br> vtkRenderer* Renderer;<br><br>};<br>vtkStandardNewMacro(KeyPressInteractorStyle);<br><br>int main(int , char *[])<br>{<br> <br> MyMultiBlockReader mbReader;<br> mbReader->Update();<br><br> vtkSmartPointer<vtkMultiBlockDataSet> mbds = mbReader->GetOutput();<br> <br> // Actors array<br> std::vector< vtkSmartPointer<vtkActor> > tabActor;<br><br> // For all blocks<br> for(unsigned int i = 0; i < mbds->GetNumberOfBlocks(); ++i)<br> {<br> // Block i<br>
vtkUnstructuredGrid *ptr_usg = vtkUnstructuredGrid::SafeDownCast( mbds->GetBlock(i) );<br><br> // vtkUnstructuredGrid to vtkPolyData<br> vtkSmartPointer<vtkGeometryFilter> geom = vtkSmartPointer<vtkGeometryFilter>::New();<br> geom->SetInput(mbds->GetBlock(i));<br> geom->Update();<br><br> // polyData<br> vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();<br> polyData->ShallowCopy( geom->GetOutput() );<br><br> // Mapper<br> vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();<br> mapper->SetInput(polyData);<br> <br> // Does not work with vtkHardwareSelector. Normal ?<br> //vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();<br> //mapper->SetInput(ptr_usg);<br><br> // Actor<br> vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();<br> actor->SetMapper(mapper);<br><br> actor->GetProperty()->EdgeVisibilityOn();<br><br> tabActor.push_back(actor);<br> }<br><br> // Create a renderer, render window,
and interactor<br> vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();<br> vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();<br> renderWindow->AddRenderer(renderer);<br> vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();<br> renderWindowInteractor->SetRenderWindow(renderWindow);<br><br> vtkSmartPointer<KeyPressInteractorStyle> style = vtkSmartPointer<KeyPressInteractorStyle>::New();<br> style->Renderer = renderer;<br> renderWindowInteractor->SetInteractorStyle(style);<br> style->SetCurrentRenderer(renderer);<br> style->mbds = mbds;<br><br> // Add the actors to the
scene<br> for(unsigned int i = 0; i < tabActor.size();i++)<br> {<br> renderer->AddActor(tabActor[i]);<br> }<br><br> renderer->SetBackground(.3, .6, .3); // Background color green<br><br> // Render and interact<br> renderWindow->Render();<br> renderWindowInteractor->Start();<br><br> return EXIT_SUCCESS;<br>}<br></span></div><div><br></div><div style="font-family:arial, helvetica, sans-serif;font-size:12pt;"><div style="font-family:times new roman, new york, times, serif;font-size:12pt;"><font face="Arial" size="2"><hr size="1"><b><span style="font-weight:bold;">De :</span></b> R M <mlokida@yahoo.fr><br><b><span style="font-weight:bold;">À :</span></b> "vtkusers@vtk.org" <vtkusers@vtk.org><br><b><span style="
font-weight:bold;">Envoyé le :</span></b> Lundi 17 Octobre 2011 13h35<br><b><span style="font-weight:bold;">Objet :</span></b> [vtkusers] vtkHarswareSelector and vtkMultiBlockDataSet<br></font><br><div id="yiv133207883"><div><div style="color:#000;background-color:#fff;font-family:arial, helvetica, sans-serif;font-size:12pt;"><div>Hello,</div><div><br></div><div>I want to select cells or points in my application. The geometry is a vtkMultiBlockDataset of vtkUnstructuredGrid.</div><div>I try to use the vtkHardwareSelector but I have a no good selection (no cells selection whereas visible, selection of unvisible cells)<br></div><div>So I must do something wrong but don't know what.</div><div><br></div><div>How should I manage the selection of visible cells and points on a vtkMultiBlockDataset of vtkUnstructuredGrid ? <br></div><div><br></div><div>I really don't know anymore how to
manage this.</div><div><br></div><div>Any ideas wil be very very welcome.</div><div><br></div><div>Thank you.<br></div><div><br></div><div><br></div></div></div></div><br>_______________________________________________<br>Powered by www.kitware.com<br><br>Visit other Kitware open-source projects at <a rel="nofollow" target="_blank" href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a><br><br>Please keep messages on-topic and check the VTK FAQ at: <a rel="nofollow" target="_blank" href="http://www.vtk.org/Wiki/VTK_FAQ">http://www.vtk.org/Wiki/VTK_FAQ</a><br><br>Follow this link to subscribe/unsubscribe:<br><a rel="nofollow" target="_blank" href="http://www.vtk.org/mailman/listinfo/vtkusers">http://www.vtk.org/mailman/listinfo/vtkusers</a><br><br><br></div></div></div></div></div><meta http-equiv="x-dns-prefetch-control" content="on"><br>_______________________________________________<br>Powered by
www.kitware.com<br><br>Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br><br>Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br><br>Follow this link to subscribe/unsubscribe:<br><a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br><br><br></div></div></div></body></html>