[vtkusers] error message in subdividing a cell

tasnim hanene-jeder at hotmail.fr
Thu May 24 15:13:10 EDT 2012


thanks David.
OK, i tryed to keep just the basic code that i need. Normally, when i used
the VtkTriangleFilter, my newdata will be triangulated automatically,
isn't?? so , i don't know why it gives me that error :
#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkUnstructuredGrid.h>
#include <vtkCell.h>
#include <vtkCellArray.h>
#include <vtkIdList.h>
#include <vtkUnsignedCharArray.h>
#include <string>
#include <vtkRendererCollection.h>
#include <vtkDataSetMapper.h>
#include <vtkIdTypeArray.h>
#include <vtkTriangleFilter.h>
#include <vtkPolyData.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()
   {
     
     int* pos = this->GetInteractor()->GetEventPosition();

     vtkSmartPointer<vtkCellPicker> picker =
       vtkSmartPointer<vtkCellPicker>::New();
     picker->SetTolerance(0.0005);

     
     picker->Pick(pos[0], pos[1], 0, this->GetDefaultRenderer());

     double* worldPosition = picker->GetPickPosition();
     

     if(picker->GetCellId() != -1)
       {

       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();

       extractSelection->SetInput(0, this->Data);
       extractSelection->SetInput(1, selection);

       extractSelection->Update();

              vtkSmartPointer<vtkUnstructuredGrid> selected =
         vtkSmartPointer<vtkUnstructuredGrid>::New();
       selected->ShallowCopy(extractSelection->GetOutput()); 
	  
	     vtkSmartPointer<vtkPolyData> newdata = 
   vtkSmartPointer<vtkPolyData>::New(); 
vtkPoints* cellPoints = selected->GetPoints(); 
newdata->SetPoints(cellPoints); 

vtkSmartPointer< vtkTriangleFilter > triangleFilter = 
  vtkSmartPointer<vtkTriangleFilter>::New(); 
triangleFilter->SetInputConnection(newdata->GetProducerPort()); 
triangleFilter->Update(); 

  int numberOfSubdivisions = 1;

vtkSmartPointer< vtkLoopSubdivisionFilter > subdivisionFilter = 
	vtkSmartPointer<vtkLoopSubdivisionFilter>::New(); 
subdivisionFilter->SetNumberOfSubdivisions(numberOfSubdivisions); 
subdivisionFilter->SetInputConnection(triangleFilter->GetOutputPort()); 
subdivisionFilter->Update(); 

 vtkSmartPointer<vtkIdTypeArray> id =
vtkSmartPointer<vtkIdTypeArray>::New();
 id->SetNumberOfComponents(1);

        selectedMapper->SetInput(selected);

       selectedActor->SetMapper(selectedMapper);
       selectedActor->GetProperty()->EdgeVisibilityOn();
       selectedActor->GetProperty()->SetEdgeColor(1,0,0);
       selectedActor->GetProperty()->SetLineWidth(3);


this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->AddActor(selectedActor);

       }
     
     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();

  vtkSmartPointer<vtkTriangleFilter> triangleFilter =
   vtkSmartPointer<vtkTriangleFilter>::New();
  triangleFilter->SetInputConnection(sphereSource->GetOutputPort());
 triangleFilter->Update();

 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();
 
 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
 
 renderWindow->Render();
 renderWindowInteractor->Start();

 return EXIT_SUCCESS;
}
 and thanks for the answer

--
View this message in context: http://vtk.1045678.n5.nabble.com/error-message-in-subdividing-a-cell-tp5713334p5713383.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list