[vtkusers] error message in subdividing a cell
tasnim
hanene-jeder at hotmail.fr
Wed May 23 13:03:33 EDT 2012
you can use vtkTriangleFilter to triangulate the polydata and then play
with the subdivision
On Wed, May 23, 2012 at 12:49 PM, tasnim <hanene-jeder@> wrote:
> Hi everybody,
> i create a program which creates a spheresource, then i select a cell,
> create a vtkPolyData from it, and try to subdivide it with the
> vtkLoopsubdivisionFilter.But, when I pick a cell, a message error appears:
>
> *Warning: In C:\vtk-download\vtk
> source\Graphics\vtkLoopSubdivisionFilter.cxx, line 363
> vtkLoopSubdivisionFilter (019BAE58): vtkLoopSubdivisionFilter only
> operates
> on triangles, but this data set has no triangles to operate on. ERROR: In
> C:\vtk-download\vtk source\Filtering\vtkExecutive.cxx, line 756
> vtkStreamingDemandDrivenPipeline (019BB448): Algorithm
> vtkLoopSubdivisionFilter(019BAE58) returned failure for request:
> vtkInformation (019CD1B8) Debug: Off Modified Time: 3532 Reference Count:
> 1
> Registered Events: (none) Request: REQUEST_DATA FORWARD_DIRECTION: 0
> ALGORITHM_AFTER_FORWARD: 1 FROM_OUTPUT_PORT: 0*
> This message shows that my new polyData didn't contain triangles.
> Any Help please, and thanks
>
> --
> View this message in context:
> http://vtk.1045678.n5.nabble.com/error-message-in-subdividing-a-cell-tp5713334.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
Yes, I used the vtkTriangleFilter before that i applied the subdivision
filter. I can put my code here if you accept to verify it for me and thanks:
#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkOBJReader.h>
#include <vtkUnstructuredGrid.h>
#include <vtkCell.h>
#include <vtkCellArray.h>
#include <vtkIdList.h>
#include <vtkUnsignedCharArray.h>
#include <vtkPointData.h>
#include <string>
#include <vtkVersion.h>
#include <vtkRendererCollection.h>
#include <vtkDataSetMapper.h>
#include <vtkIdTypeArray.h>
#include <vtkTriangleFilter.h>
#include <vtkCommand.h>
#include <vtkPolyData.h>
#include <vtkPoints.h>
#include <vtkCellPicker.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkProperty.h>
#include <vtkSelectionNode.h>
#include <vtkSelection.h>
#include <vtkExtractSelection.h>
#include <vtkObjectFactory.h>
#include <vtkGenericCell.h>
#include <vtkLoopSubdivisionFilter.h>
#include <vtkSphereSource.h>
// Catch mouse events
class MouseInteractorStyle : public vtkInteractorStyleTrackballCamera
{
public:
static MouseInteractorStyle* New();
MouseInteractorStyle()
{
selectedMapper = vtkSmartPointer<vtkDataSetMapper>::New();
selectedActor = vtkSmartPointer<vtkActor>::New();
}
virtual void OnLeftButtonDown()
{
// Get the location of the click (in window coordinates)
int* pos = this->GetInteractor()->GetEventPosition();
vtkSmartPointer<vtkCellPicker> picker =
vtkSmartPointer<vtkCellPicker>::New();
picker->SetTolerance(0.0005);
// Pick from this location.
picker->Pick(pos[0], pos[1], 0, this->GetDefaultRenderer());
double* worldPosition = picker->GetPickPosition();
std::cout << "Cell id is: " << picker->GetCellId() << std::endl;
if(picker->GetCellId() != -1)
{
std::cout << "Pick position is: " << worldPosition[0] << " " <<
worldPosition[1]
<< " " << worldPosition[2] << endl;
vtkSmartPointer<vtkIdTypeArray> ids =
vtkSmartPointer<vtkIdTypeArray>::New();
ids->SetNumberOfComponents(1);
ids->InsertNextValue(picker->GetCellId());
vtkSmartPointer<vtkSelectionNode> selectionNode =
vtkSmartPointer<vtkSelectionNode>::New();
selectionNode->SetFieldType(vtkSelectionNode::CELL);
selectionNode->SetContentType(vtkSelectionNode::INDICES);
selectionNode->SetSelectionList(ids);
vtkSmartPointer<vtkSelection> selection =
vtkSmartPointer<vtkSelection>::New();
selection->AddNode(selectionNode);
vtkSmartPointer<vtkExtractSelection> extractSelection =
vtkSmartPointer<vtkExtractSelection>::New();
#if VTK_MAJOR_VERSION <= 5
extractSelection->SetInput(0, this->Data);
extractSelection->SetInput(1, selection);
#else
extractSelection->SetInputData(0, this->Data);
extractSelection->SetInputData(1, selection);
#endif
extractSelection->Update();
// In selection
vtkSmartPointer<vtkUnstructuredGrid> selected =
vtkSmartPointer<vtkUnstructuredGrid>::New();
selected->ShallowCopy(extractSelection->GetOutput());
std::cout << "There are " << selected->GetNumberOfPoints()
<< " points in the selection." << std::endl;
std::cout << "There are " << selected->GetNumberOfCells()
<< " cells in the selection." << std::endl;
// Create a polydata object
vtkSmartPointer<vtkPolyData> newdata =
vtkSmartPointer<vtkPolyData>::New();
vtkPoints* cellPoints = selected->GetPoints();
newdata->SetPoints(cellPoints);
int numberOfSubdivisions = 1;
vtkSmartPointer< vtkTriangleFilter > triangleFilter =
vtkSmartPointer<vtkTriangleFilter>::New();
triangleFilter->SetInputConnection(newdata->GetProducerPort());
triangleFilter->Update();
vtkSmartPointer< vtkLoopSubdivisionFilter > subdivisionFilter =
vtkSmartPointer<vtkLoopSubdivisionFilter>::New();
subdivisionFilter->SetNumberOfSubdivisions(numberOfSubdivisions);
subdivisionFilter->SetInputConnection(triangleFilter->GetOutputPort());
subdivisionFilter->Update();
vtkSmartPointer<vtkIdTypeArray> id =
vtkSmartPointer<vtkIdTypeArray>::New();
id->SetNumberOfComponents(1);
// Set values
for(unsigned int i = 10; i < 20; i++)
{
ids->InsertNextValue(i);
}
///////////////
#if VTK_MAJOR_VERSION <= 5
selectedMapper->SetInputConnection(
selected->GetProducerPort());
#else
selectedMapper->SetInputData(selected);
#endif
selectedActor->SetMapper(selectedMapper);
selectedActor->GetProperty()->EdgeVisibilityOn();
selectedActor->GetProperty()->SetEdgeColor(1,0,0);
selectedActor->GetProperty()->SetLineWidth(3);
this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->AddActor(selectedActor);
}
// Forward events
vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
}
vtkSmartPointer<vtkPolyData> Data;
vtkSmartPointer<vtkDataSetMapper> selectedMapper;
vtkSmartPointer<vtkActor> selectedActor;
};
vtkStandardNewMacro(MouseInteractorStyle);
int main(int, char *[])
{
vtkSmartPointer<vtkSphereSource> sphereSource =
vtkSmartPointer<vtkSphereSource>::New();
sphereSource->Update();
// filtre de triangle
vtkSmartPointer<vtkTriangleFilter> triangleFilter =
vtkSmartPointer<vtkTriangleFilter>::New();
triangleFilter->SetInputConnection(sphereSource->GetOutputPort());
triangleFilter->Update();
// Visualize
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(triangleFilter->GetOutputPort());
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
renderWindowInteractor->Initialize();
// Set the custom stype to use for interaction.
vtkSmartPointer<MouseInteractorStyle> style =
vtkSmartPointer<MouseInteractorStyle>::New();
style->SetDefaultRenderer(renderer);
style->Data = triangleFilter->GetOutput();
renderWindowInteractor->SetInteractorStyle(style);
renderer->AddActor(actor);
renderer->ResetCamera();
renderer->SetBackground(0,0,1); // Blue
//renderer->SetBackground(.3, .6, .3); // Background color green
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
--
View this message in context: http://vtk.1045678.n5.nabble.com/error-message-in-subdividing-a-cell-tp5713334p5713336.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list