<div class="gmail_quote">On Fri, May 18, 2012 at 6:19 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">
Good Morning,<br>
Since my last post was without a title( i forget to set a title), I will<br>
post my little problem again. I have a program which create a<br>
vtkspheresource and pick a cell.I tryed to create a vtkPolyData from the<br>
selected cell, in order to apply the subdivisionFilter on it. But it didn't<br>
work.Any Help please!!!! here is my code:<br>
//////////////////////////////<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 <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>
<br>
/// pour la selection d'un triangle<br>
#include <vtkVersion.h><br>
#include <vtkRendererCollection.h><br>
#include <vtkDataSetMapper.h><br>
#include <vtkIdTypeArray.h><br>
#include <vtkTriangleFilter.h><br>
#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>
<br>
#include <vtkGenericCell.h><br>
#include <vtkLoopSubdivisionFilter.h><br>
#include <vtkSphereSource.h><br>
<br>
<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>
<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>
<br>
<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>
<br>
// In selection<br>
vtkSmartPointer<vtkUnstructuredGrid> selected =<br>
vtkSmartPointer<vtkUnstructuredGrid>::New();<br>
selected->ShallowCopy(extractSelection->GetOutput());<br>
<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>
/////////////////////<br>
<br>
// 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>
<br>
<br>
/////////////:<br>
vtkSmartPointer<vtkIdTypeArray> id =<br>
vtkSmartPointer<vtkIdTypeArray>::New();<br>
id->SetNumberOfComponents(1);<br>
<br>
// Set values<br>
for(unsigned int i = 10; i < 20; i++)<br>
{<br>
ids->InsertNextValue(i);<br>
}<br>
<br>
<br>
///////////////<br>
<br>
<br>
#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>
<br>
int main(int, char *[])<br>
{<br>
vtkSmartPointer<vtkSphereSource> sphereSource =<br>
vtkSmartPointer<vtkSphereSource>::New();<br>
sphereSource->Update();<br>
<br>
// filtre de triangle<br>
vtkSmartPointer<vtkTriangleFilter> triangleFilter =<br>
vtkSmartPointer<vtkTriangleFilter>::New();<br>
triangleFilter->SetInputConnection(sphereSource->GetOutputPort());<br>
triangleFilter->Update();<br>
<br>
<br>
// Visualize<br>
vtkSmartPointer<vtkPolyDataMapper> mapper =<br>
vtkSmartPointer<vtkPolyDataMapper>::New();<br>
mapper->SetInputConnection(triangleFilter->GetOutputPort());<br>
<br>
vtkSmartPointer<vtkActor> actor =<br>
vtkSmartPointer<vtkActor>::New();<br>
actor->SetMapper(mapper);<br>
<br>
vtkSmartPointer<vtkRenderer> renderer =<br>
vtkSmartPointer<vtkRenderer>::New();<br>
vtkSmartPointer<vtkRenderWindow> renderWindow =<br>
vtkSmartPointer<vtkRenderWindow>::New();<br>
renderWindow->AddRenderer(renderer);<br>
<br>
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =<br>
vtkSmartPointer<vtkRenderWindowInteractor>::New();<br>
renderWindowInteractor->SetRenderWindow(renderWindow);<br>
renderWindowInteractor->Initialize();<br>
<br>
// Set the custom stype to use for interaction.<br>
vtkSmartPointer<MouseInteractorStyle> style =<br>
vtkSmartPointer<MouseInteractorStyle>::New();<br>
style->SetDefaultRenderer(renderer);<br>
style->Data = triangleFilter->GetOutput();<br>
renderWindowInteractor->SetInteractorStyle(style);<br>
<br>
<br>
renderer->AddActor(actor);<br>
renderer->ResetCamera();<br>
renderer->SetBackground(0,0,1); // Blue<br>
//renderer->SetBackground(.3, .6, .3); // Background color green<br>
<br>
renderWindow->Render();<br>
renderWindowInteractor->Start();<br>
<br>
return EXIT_SUCCESS;<br>
}<br>
<br>
i'd like to apply the loopSubdivisionFilter on my selected cell.But one i<br>
pick on a cell, it shows me his error message:<br>
vtkLoopSubdivisionFilter (009D6CD0): vtkLoopSubdivisionFilter only operates<br>
on triangles, but this data set has no triangles to operate on.<br>
Any Help please, and thanks fo all<br></blockquote><div><br></div>That code is much too long to troubleshoot (though you definitely need a vtkTriangleFilter before the LoopSubdivisionFilter in this case). I suggest you make a very minimal (compilable) example of the part of the code that is causing the problem.<br clear="all">
<br><div>David </div></div>