<div><div class="gmail_quote">On Fri, May 18, 2012 at 8:55 AM, tasnim <span dir="ltr"><<a href="mailto:hanene-jeder@hotmail.fr" target="_blank">hanene-jeder@hotmail.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi David,<br>
thanks for your answer.Ok, this is my new code with some modifications:<br>
<div class="im">#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 <vtkOBJReader.h><br>
#include <vtkUnstructuredGrid.h><br>
#include <vtkCell.h><br>
#include <vtkCellArray.h><br>
#include <vtkIdList.h><br>
#include <vtkUnsignedCharArray.h><br>
#include <vtkPointData.h><br>
#include <string><br>
</div><div class="im">#include <vtkVersion.h><br>
#include <vtkRendererCollection.h><br>
#include <vtkDataSetMapper.h><br>
#include <vtkIdTypeArray.h><br>
</div><div><div class="h5">#include <vtkCommand.h><br>
#include <vtkPolyData.h><br>
#include <vtkPoints.h><br>
#include <vtkCellPicker.h><br>
#include <vtkInteractorStyleTrackballCamera.h><br>
#include <vtkProperty.h><br>
#include <vtkSelectionNode.h><br>
#include <vtkSelection.h><br>
#include <vtkExtractSelection.h><br>
#include <vtkObjectFactory.h><br>
#include <vtkGenericCell.h><br>
#include <vtkLoopSubdivisionFilter.h><br>
#include <vtkSphereSource.h><br>
// Catch mouse events<br>
class MouseInteractorStyle : public vtkInteractorStyleTrackballCamera<br>
{<br>
public:<br>
static MouseInteractorStyle* New();<br>
<br>
MouseInteractorStyle()<br>
{<br>
selectedMapper = vtkSmartPointer<vtkDataSetMapper>::New();<br>
selectedActor = vtkSmartPointer<vtkActor>::New();<br>
}<br>
<br>
virtual void OnLeftButtonDown()<br>
{<br>
// Get the location of the click (in window coordinates)<br>
int* pos = this->GetInteractor()->GetEventPosition();<br>
<br>
vtkSmartPointer<vtkCellPicker> picker =<br>
vtkSmartPointer<vtkCellPicker>::New();<br>
picker->SetTolerance(0.0005);<br>
// Pick from this location.<br>
picker->Pick(pos[0], pos[1], 0, this->GetDefaultRenderer());<br>
<br>
double* worldPosition = picker->GetPickPosition();<br>
std::cout << "Cell id is: " << picker->GetCellId() << std::endl;<br>
<br>
if(picker->GetCellId() != -1)<br>
{<br>
<br>
std::cout << "Pick position is: " << worldPosition[0] << " " <<<br>
worldPosition[1]<br>
<< " " << worldPosition[2] << endl;<br>
<br>
vtkSmartPointer<vtkIdTypeArray> ids =<br>
vtkSmartPointer<vtkIdTypeArray>::New();<br>
ids->SetNumberOfComponents(1);<br>
ids->InsertNextValue(picker->GetCellId());<br>
<br>
vtkSmartPointer<vtkSelectionNode> selectionNode =<br>
vtkSmartPointer<vtkSelectionNode>::New();<br>
selectionNode->SetFieldType(vtkSelectionNode::CELL);<br>
selectionNode->SetContentType(vtkSelectionNode::INDICES);<br>
selectionNode->SetSelectionList(ids);<br>
vtkSmartPointer<vtkSelection> selection =<br>
vtkSmartPointer<vtkSelection>::New();<br>
selection->AddNode(selectionNode);<br>
<br>
vtkSmartPointer<vtkExtractSelection> extractSelection =<br>
vtkSmartPointer<vtkExtractSelection>::New();<br>
#if VTK_MAJOR_VERSION <= 5<br>
extractSelection->SetInput(0, this->Data);<br>
extractSelection->SetInput(1, selection);<br>
#else<br>
extractSelection->SetInputData(0, this->Data);<br>
extractSelection->SetInputData(1, selection);<br>
#endif<br>
extractSelection->Update();<br>
// In selection<br>
vtkSmartPointer<vtkUnstructuredGrid> selected =<br>
vtkSmartPointer<vtkUnstructuredGrid>::New();<br>
selected->ShallowCopy(extractSelection->GetOutput());<br>
std::cout << "There are " << selected->GetNumberOfPoints()<br>
<< " points in the selection." << std::endl;<br>
std::cout << "There are " << selected->GetNumberOfCells()<br>
<< " cells in the selection." << std::endl;<br>
</div></div><div class="im"> // Create a polydata object<br>
vtkSmartPointer<vtkPolyData> newdata =<br>
vtkSmartPointer<vtkPolyData>::New();<br>
<br>
vtkPoints* cellPoints = selected->GetPoints();<br>
newdata->SetPoints(cellPoints);<br>
<br>
int numberOfSubdivisions = 2;<br>
vtkSmartPointer<vtkPolyDataAlgorithm> subdivisionFilter;<br>
subdivisionFilter = vtkSmartPointer<vtkLoopSubdivisionFilter>::New();<br>
dynamic_cast<vtkLoopSubdivisionFilter *><br>
(subdivisionFilter.GetPointer())->SetNumberOfSubdivisions(numberOfSubdivisions);<br>
#if VTK_MAJOR_VERSION <= 5<br>
subdivisionFilter->SetInputConnection(newdata->GetProducerPort());<br>
#else<br>
subdivisionFilter->SetInputData(newdata);<br>
#endif<br>
subdivisionFilter->Update();<br>
</div><div class="im"> vtkSmartPointer<vtkIdTypeArray> id =<br>
vtkSmartPointer<vtkIdTypeArray>::New();<br>
id->SetNumberOfComponents(1);<br>
// Set values<br>
for(unsigned int i = 10; i < 20; i++)<br>
{<br>
ids->InsertNextValue(i);<br>
}<br>
<br>
</div><div class="im">#if VTK_MAJOR_VERSION <= 5<br>
selectedMapper->SetInputConnection(<br>
selected->GetProducerPort());<br>
#else<br>
selectedMapper->SetInputData(selected);<br>
#endif<br>
<br>
selectedActor->SetMapper(selectedMapper);<br>
selectedActor->GetProperty()->EdgeVisibilityOn();<br>
selectedActor->GetProperty()->SetEdgeColor(1,0,0);<br>
selectedActor->GetProperty()->SetLineWidth(3);<br>
<br>
<br>
this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->AddActor(selectedActor);<br>
<br>
}<br>
// Forward events<br>
vtkInteractorStyleTrackballCamera::OnLeftButtonDown();<br>
}<br>
<br>
vtkSmartPointer<vtkPolyData> Data;<br>
vtkSmartPointer<vtkDataSetMapper> selectedMapper;<br>
vtkSmartPointer<vtkActor> selectedActor;<br>
<br>
};<br>
<br>
vtkStandardNewMacro(MouseInteractorStyle);<br>
<br>
int main(int, char *[])<br>
{<br>
vtkSmartPointer<vtkSphereSource> sphereSource =<br>
vtkSmartPointer<vtkSphereSource>::New();<br>
sphereSource->Update();<br>
</div><div class="im"> // Visualize<br>
vtkSmartPointer<vtkPolyDataMapper> mapper =<br>
vtkSmartPointer<vtkPolyDataMapper>::New();<br>
</div> mapper->SetInputConnection(sphereSource->GetOutputPort());<br>
<div class="im"> vtkSmartPointer<vtkActor> actor =<br>
vtkSmartPointer<vtkActor>::New();<br>
actor->SetMapper(mapper);<br>
vtkSmartPointer<vtkRenderer> renderer =<br>
vtkSmartPointer<vtkRenderer>::New();<br>
vtkSmartPointer<vtkRenderWindow> renderWindow =<br>
vtkSmartPointer<vtkRenderWindow>::New();<br>
renderWindow->AddRenderer(renderer);<br>
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =<br>
vtkSmartPointer<vtkRenderWindowInteractor>::New();<br>
renderWindowInteractor->SetRenderWindow(renderWindow);<br>
renderWindowInteractor->Initialize();<br>
// Set the custom stype to use for interaction.<br>
vtkSmartPointer<MouseInteractorStyle> style =<br>
vtkSmartPointer<MouseInteractorStyle>::New();<br>
style->SetDefaultRenderer(renderer);<br>
</div> style->Data = sphereSource->GetOutput();<br>
<div class="im"> renderWindowInteractor->SetInteractorStyle(style);<br>
renderer->AddActor(actor);<br>
renderer->ResetCamera();<br>
renderer->SetBackground(0,0,1); // Blue<br>
</div><div class="im"> renderWindow->Render();<br>
renderWindowInteractor->Start();<br>
return EXIT_SUCCESS;<br>
}<br>
</div>I think the error is in these lines:<br>
<div class="im"> // Create a polydata object<br>
vtkSmartPointer<vtkPolyData> newdata =<br>
vtkSmartPointer<vtkPolyData>::New();<br>
<br>
vtkPoints* cellPoints = selected->GetPoints();<br>
newdata->SetPoints(cellPoints);<br>
<br>
int numberOfSubdivisions = 2;<br>
vtkSmartPointer<vtkPolyDataAlgorithm> subdivisionFilter;<br>
subdivisionFilter = vtkSmartPointer<vtkLoopSubdivisionFilter>::New();<br>
dynamic_cast<vtkLoopSubdivisionFilter *><br>
(subdivisionFilter.GetPointer())->SetNumberOfSubdivisions(numberOfSubdivisions);<br>
#if VTK_MAJOR_VERSION <= 5<br>
subdivisionFilter->SetInputConnection(newdata->GetProducerPort());<br>
#else<br>
subdivisionFilter->SetInputData(newdata);<br>
#endif<br>
subdivisionFilter->Update();<br>
</div>The message error says:<br>
Warning: In C:\vtk\Graphics\vtkLoopSubdivisionFilter.cxx, line 363<br>
vtkLoopSubdivisionFilter (01AEAA80): vtkLoopSubdivisionFilter only operates<br>
<div class="im">on triangles, but this data set has no triangles to operate on.<br>
<br>
</div>ERROR: In C:\vtk\Filtering\vtkExecutive.cxx, line 756<br>
vtkStreamingDemandDrivenPipeline (01AE4A48): Algorithm<br>
vtkLoopSubdivisionFilter(01AEAA80) returned failure for request:<br>
vtkInformation (01AE7E28)<br></blockquote><div><br></div>A few things:<div><br></div><div>1) You still didn't use a TriangleFilter</div><div><br></div><div>2) There is no need for all of the visualization code to demonstrate this problem. It is just polluting the problem.</div>
<div><br></div><div>3) Why are you doing this?</div><div><span style> vtkSmartPointer<</span><span style>vtkPolyDataAlgorithm> subdivisionFilter;</span></div><div><span style> subdivisionFilter = vtkSmartPointer<</span><span style>vtkLoopSubdivisionFilter>::</span><span style>New();</span><br style>
<span style> dynamic_cast<</span><span style>vtkLoopSubdivisionFilter *></span><br style><span style>(subdivisionFilter.GetPointer(</span><span style>))->SetNumberOfSubdivisions(</span><span style>numberOfSubdivisions);</span><br style>
<font color="#500050" face="arial, sans-serif"><br></font></div><div><font color="#500050" face="arial, sans-serif">instead of just </font></div><div><font color="#500050" face="arial, sans-serif"><br></font></div><div><div>
<span style>vtkSmartPointer<</span>
<span style>vtkLoopSubdivisionFilter</span> <span style>> subdivisionFilter</span><span style> = vtkSmartPointer<</span><span style>vtkLoopSubdivisionFilter>::</span><span style>New();</span></div><div><span style>subdivisionFilter</span><span style>->SetNumberOfSubdivisions(</span><span style>numberOfSubdivisions);</span><br style>
</div></div><div><span style><br></span></div><div><span style>?</span></div><div><span style><br></span></div><div>David </div></div></div>