[vtk-developers] save the coordinate with the color of point
kaouther
boutara.kaouther at gmail.com
Tue Jun 12 08:47:35 EDT 2012
hank you for your response
my mesh in the PLY format.I color my mesh by this code:
class KeyPressInteractorStyle : public vtkInteractorStyleTrackballCamera
{
public:
static KeyPressInteractorStyle* New();
vtkTypeMacro(KeyPressInteractorStyle,
vtkInteractorStyleTrackballCamera);
virtual void OnKeyPress()
{
// Get the keypress
vtkRenderWindowInteractor *rwi = this->Interactor;
std::string key = rwi->GetKeySym();
if(key == "a")
{
std::cout << "The a key was pressed." << std::endl;
int* pos = renderWindowInteractor->GetEventPosition();
vtkCellPicker *picker=vtkCellPicker::New();
// Pick from this location.
picker->Pick(pos[0], pos[1], 0, ren);
double* worldPosition = picker->GetPickPosition();
std::cout << "Cell id is: " << picker->GetCellId() << std::endl;
if(picker->GetCellId() != -1)
{
cellId =picker->GetCellId();
triangleFilter->GetOutput()->GetCellPoints(cellId, cellPointIds);
// neighbor cells may be listed multiple times
// use std::set instead of std::list if you want a unique list of
neighbors
std::list<vtkIdType> neighbors;
for(vtkIdType i = 0; i < cellPointIds->GetNumberOfIds(); i++)
{
idList = vtkSmartPointer<vtkIdList>::New();
idList->InsertNextId(cellPointIds->GetId(i));
//get the neighbors of the cell
neighborCellIds = vtkSmartPointer<vtkIdList>::New();
triangleFilter->GetOutput()->GetCellNeighbors(cellId, idList,
neighborCellIds);
for(vtkIdType j = 0; j < neighborCellIds->GetNumberOfIds(); j++)
{
neighbors.push_back(neighborCellIds->GetId(j));
}
}
std::cout << "Point neighbor ids are: " << std::endl;
for(std::list<vtkIdType>::iterator it1 = neighbors.begin(); it1 !=
neighbors.end(); it1++)
{
std::cout << " " << *it1;
}
std::cout << std::endl;
mainCellMapper = vtkSmartPointer<vtkDataSetMapper>::New();
neighborCellsMapper = vtkSmartPointer<vtkDataSetMapper>::New();
// Create a dataset with the cell of interest
{
ids = vtkSmartPointer<vtkIdTypeArray>::New();
ids->SetNumberOfComponents(1);
ids->InsertNextValue(cellId);
selectionNode = vtkSmartPointer<vtkSelectionNode>::New();
selectionNode->SetFieldType(vtkSelectionNode::CELL);
selectionNode->SetContentType(vtkSelectionNode::INDICES);
selectionNode->SetSelectionList(ids);
selection = vtkSmartPointer<vtkSelection>::New();
selection->AddNode(selectionNode);
extractSelection = vtkSmartPointer<vtkExtractSelection>::New();
extractSelection->SetInput(0, polyData);
#if VTK_MAJOR_VERSION <= 5
extractSelection->SetInput(1, selection);
#else
//extractSelection->SetInputData(1, selection);
#endif
extractSelection->Update();
mainCellMapper->SetInputConnection(extractSelection->GetOutputPort());
}
mainCellActor = vtkSmartPointer<vtkActor>::New();
mainCellActor->SetMapper(mainCellMapper);
//mainCellActor->GetProperty()->SetColor((ui->varierLumiereSlider->value())*0.01,0.1,0.1);
// mainCellMapper->SetScalarRange(0, tableSize - 1);
// mainCellMapper->SetLookupTable(lut);
if(ui->comboBox->currentText() == "Rouge")
{
mainCellActor->GetProperty()->SetColor((ui->varierLumiereSlider->value())*0.01,0.1,0.1);
}
if(ui->comboBox->currentText() == "Vert")
{
mainCellActor->GetProperty()->SetColor(0.1,
(ui->varierLumiereSlider->value())*0.01,0.1);
}
if(ui->comboBox->currentText() == "Bleu")
{
mainCellActor->GetProperty()->SetColor(0.1, 0.1,
(ui->varierLumiereSlider->value())*0.01);
}
if(ui->comboBox->currentText() == "koktel_Color")
{
mainCellActor->GetProperty()->SetColor((ui->varierLumiereSlider->value()),
(ui->varierLumiereSlider->value()), (ui->varierLumiereSlider->value()));
}
polyData->Modified();
// Create a dataset with the neighbor cells
{
ids = vtkSmartPointer<vtkIdTypeArray>::New();
ids->SetNumberOfComponents(1);
for(std::list<vtkIdType>::iterator it1 = neighbors.begin(); it1 !=
neighbors.end(); it1++)
{
ids->InsertNextValue(*it1);
}
selectionNode = vtkSmartPointer<vtkSelectionNode>::New();
selectionNode->SetFieldType(vtkSelectionNode::CELL);
selectionNode->SetContentType(vtkSelectionNode::INDICES);
selectionNode->SetSelectionList(ids);
selection = vtkSmartPointer<vtkSelection>::New();
selection->AddNode(selectionNode);
extractSelection = vtkSmartPointer<vtkExtractSelection>::New();
extractSelection->SetInput(0, polyData);
extractSelection->SetInput(1, selection);
extractSelection->Update();
neighborCellsMapper->SetInputConnection(extractSelection->GetOutputPort());
//neighborCellsMapper->SetScalarRange(0, tableSize - 1);
//neighborCellsMapper->GetLookupTable();
}
neighborCellsActor = vtkSmartPointer<vtkActor>::New();
neighborCellsActor->SetMapper(neighborCellsMapper);
//neighborCellsActor->GetProperty()->SetColor((ui->varierLumiereSlider->value())*0.01,0.1,0.1);
if(ui->comboBox->currentText() == "Rouge")
{
neighborCellsActor->GetProperty()->SetColor((ui->varierLumiereSlider->value())*0.01,0.1,0.1);
}
if(ui->comboBox->currentText() == "Vert")
{
neighborCellsActor->GetProperty()->SetColor(0.1,
(ui->varierLumiereSlider->value())*0.01,0.1);
}
if(ui->comboBox->currentText() == "Bleu")
{
neighborCellsActor->GetProperty()->SetColor(0.1, 0.1,
(ui->varierLumiereSlider->value())*0.01);
}
if(ui->comboBox->currentText() == "koktel_Color")
{
neighborCellsActor->GetProperty()->SetColor((ui->varierLumiereSlider->value()),
(ui->varierLumiereSlider->value()), (ui->varierLumiereSlider->value()));
}
polyData->Modified();
ren->AddActor(mainCellActor);
ren->AddActor(neighborCellsActor);
}
}
}
// Forward events
vtkInteractorStyleTrackballCamera::OnKeyPress();
}
};
vtkStandardNewMacro(KeyPressInteractorStyle);
//methode manual segmentation
void InterfaceProjet::slotSegmentationmanulle()
{
vtkRenderWindow* renderWindow = ui->qvtkWidget->GetRenderWindow();
renderWindow->AddRenderer(ren);
renderWindowInteractor
=vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
//read vtp crane_0.vtp
vtkPLYReader *atlas = vtkPLYReader::New();
atlas->SetFileName("crane3.ply");
atlas->Update();
polyData = atlas->GetOutput();
polyData->BuildLinks();
// cell et points.
vtkCellArray *in_lines = polyData->GetLines();
vtkPoints *in_points = polyData->GetPoints();
// Combien ?
vtkIdType num_cells = in_lines->GetNumberOfCells();
vtkIdType num_points = in_points->GetNumberOfPoints();
QString nbPts;QString nbPolys;QString nbPiece;
nbPts.setNum(polyData->GetNumberOfPoints());
nbPolys.setNum(polyData->GetNumberOfPolys());
nbPiece.setNum(polyData->GetNumberOfPieces());
ui->nb_Vertex->setText(nbPts);
ui->nb_Polys->setText(nbPolys);
ui->nb_Piece->setText(nbPiece);
triangleFilter = vtkSmartPointer<vtkTriangleFilter>::New();
triangleFilter->SetInputConnection(atlas->GetOutputPort());
triangleFilter->Update();
cellPointIds = vtkSmartPointer<vtkIdList>::New();
atlasMapper = vtkSmartPointer<vtkDataSetMapper>::New();
atlasMapper->SetInputConnection(atlas->GetOutputPort());
atlasActor = vtkSmartPointer<vtkActor>::New();
atlasActor->SetMapper(atlasMapper);
//atlasActor->SetPosition(50,20,10);
atlasActor->GetProperty()->SetEdgeColor(0, 0, 0);
atlasActor->GetProperty()->EdgeVisibilityOn();
vtkSmartPointer<KeyPressInteractorStyle> style =
vtkSmartPointer<KeyPressInteractorStyle>::New();
renderWindowInteractor->SetInteractorStyle(style);
style->SetCurrentRenderer(ren);
vtkSmartPointer<vtkSimplePointsWriter> writer =
vtkSmartPointer<vtkSimplePointsWriter>::New();
writer->SetFileName("test.xyz");
writer->SetInput(polyData);
writer->Write();
//Add the actors to the scene
ren->AddActor(atlasActor);
//Render and interact
renderWindow->Render();
renderWindowInteractor->Initialize();
renderWindowInteractor->Start();
}
--
View this message in context: http://vtk.1045678.n5.nabble.com/save-the-coordinate-with-the-color-of-point-tp5713782p5713799.html
Sent from the VTK - Dev mailing list archive at Nabble.com.
More information about the vtk-developers
mailing list