[vtkusers] Deleting cells
Ricardo Seco VTK
secolasUA at gmail.com
Tue Jan 2 08:26:38 EST 2007
Hello!
I have a cloud of points and i need to delete some of the points. Anyone
has any ideas how to do this? Thanks in advance.
Here's the code...
Ricardo Seco
// Editor 3D para manipulação de nuvem de pontos e modelos triangulados
#include "stdio.h"
#include "vtkActor.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkProperty.h"
#include "vtkPointPicker.h"
#include "vtkCellPicker.h"
#include "vtkOpenGLActor.h"
#include "vtkCommand.h"
#include "vtkSphereSource.h"
#include "vtkPoints.h"
#include "vtkPointData.h"
#include "vtkPolyData.h"
#include "vtkCellArray.h"
#include "vtkPolyDataMapper.h"
/* IMPLEMENTAÇÂO DO OBSERVER PARA O CELL PICKER */
class vtkMyCallback : public vtkCommand
{
public:
vtkMyCallback::vtkMyCallback() { m_pvtkActorSelection = NULL; };
static vtkMyCallback *New() { return new vtkMyCallback; }
void SetSelectionActor(vtkActor* pvtkActorSelection) {
m_pvtkActorSelection = pvtkActorSelection; };
virtual void Execute(vtkObject *caller, unsigned long, void*)
{
vtkRenderWindowInteractor *iren =
reinterpret_cast<vtkRenderWindowInteractor*>(caller);
double coords[3];
vtkCellPicker *picker = (vtkCellPicker *)iren->GetPicker();
//picker->GetPCoords(coords);
//printf("Coords: x:%f y:%f z:%f \n
",coords[0],coords[1],coords[2] );
printf("Cell ID: %d \n",picker->GetCellId());
if (picker->GetCellId() != -1)
{
if (m_pvtkActorSelection)
m_pvtkActorSelection->SetPosition(picker->GetPickPosition());
iren->Render();
}
}
private:
vtkActor* m_pvtkActorSelection;
};
int main()
{
// Inicializações
int numPoints;
FILE *fp;
float fltData1,fltData2,fltData3;
char str[100];
vtkPoints *Points = vtkPoints::New();
vtkCellArray *Vertices = vtkCellArray::New();
vtkPolyData *dataSet = vtkPolyData::New();
numPoints = 0;
// Leitura dos dados do ficheiro
if ((fp = fopen("ASCII_Pontos_Guimaraes.txt","r")) != NULL )
{
while (!feof(fp))
{
fscanf(fp,"%f %f %f",&fltData1,&fltData2,&fltData3);
Points->InsertNextPoint(fltData1,fltData2,fltData3);
Points->InsertPoint(numPoints,fltData1,fltData2,fltData3);
Vertices->InsertNextCell(1,&numPoints);
numPoints++;
}
}
fclose(fp);
// Definição da esfera utilizada no Picking para assinalar a célula
escolhida
vtkSphereSource *sphere=vtkSphereSource::New();
sphere->SetThetaResolution(8);
sphere->SetPhiResolution(8);
sphere->SetRadius(5);
vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
sphereMapper->SetInput(sphere->GetOutput());
// Estabelecimento da esfera como sendo do tipo de actor
vtkOpenGLActor *myPicker=vtkOpenGLActor::New();
myPicker->GetProperty()->SetColor(1.0,0.0,0.0);
myPicker->SetMapper(sphereMapper);
// Transfere a informação dos pontos para o array de dados PolyData
dataSet->SetPoints(Points);
dataSet->SetVerts(Vertices);
dataSet->BuildCells();
dataSet->BuildLinks();
// Mapper and actor
vtkPolyDataMapper *polyMapper = vtkPolyDataMapper::New();
polyMapper->SetInput(dataSet);
vtkActor *polyActor = vtkActor::New();
polyActor->SetMapper(polyMapper);
// Criaçao do renderer, render window, e interactor.
vtkRenderer *ren1 = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren1);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
ren1->SetBackground(0,0,0);
ren1->AddActor(polyActor);
// render
//renWin->SetFullScreen(1);
// Início da interacção
iren->SetRenderWindow(renWin);
renWin->SetSize(800,600);
/* Definicao de um Cell Picker */
vtkCellPicker *picker=vtkCellPicker::New();
picker->SetTolerance(0.05);
iren->SetPicker(picker);
iren->Initialize();
// Código de atribuição do Observer
vtkMyCallback *callback = vtkMyCallback::New();
callback->SetSelectionActor(myPicker);
iren->AddObserver(vtkCommand::EndPickEvent, callback);
iren->Start();
Points->Delete();
Vertices->Delete();
dataSet->Delete();
polyMapper->Delete();
polyActor->Delete();
return 0;
}
More information about the vtkusers
mailing list