Hi all,

Following  David's suggestion, I came up with the code attached that turns
the starting data file (rgb.txt, of the type [X Y Z R G B] (the first three
vector columns specify the location of the single point and the last three
one its color in RGB space)) into a parsed vtp format. Unfortunately, when I
try to open the VTP file in Paraview (after applying a Glyph filter) the
results are not what I expect, i.e. one point red, one point green, two
points blue.

I would greatly appreciate if someone could help me put reading correctly
the VTP file, I should admit that I'm not very familiar with the use of vtp
files in Paraview,

Cheers

Giulio


   

-----Messaggio originale-----
Da: David Doria [mailto:daviddo...@gmail.com]
Inviato: giovedì 23 febbraio 2012 02:48
A: giulio.re...@unisalento.it
Cc: paraview@paraview.org
Oggetto: Re: [Paraview] 3D point cloud with color

>> I have been working with 3D stereo reconstruction. So, I have huge 3d
point clouds co-registered with color in this format [X Y Z R G B] (the
first three vector columns specify the location of the single point and the
last three one its color in RGB space). I have been trying to display the
data in Paraview without success.
>>
>>
>>
>> I use the “table to points” filter to show the 3D coordinates but then I
do not know  how to specify the color of each single point using its RGB
components. Can you please help me out?

If you're more comfortable in c++ you could use VTK to parse the file,
construct a polydata, and then write a vtp file. Here are the examples you'd
need:
http://www.vtk.org/Wiki/VTK/Examples/Cxx/InfoVis/ReadDelimitedFile
http://www.vtk.org/Wiki/VTK/Examples/Cxx/IO/WriteVTP

Then Paraview can easily read this vtp file.

David
#include <vtkSmartPointer.h>
#include <vtkProperty.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkDelimitedTextReader.h>
#include <vtkDoubleArray.h>
#include <vtkTable.h>
#include <vtkPointData.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkVertexGlyphFilter.h>
#include <vtkCellArray.h>
#include <vtkPoints.h>
#include <vtkXMLPolyDataWriter.h>
#include <vtkPolyData.h>
#include <vtkSmartPointer.h>
 
int main(int argc, char* argv[])
{
  // Verify input arguments
  if(argc != 2)
    {
    std::cout << "Usage: " << argv[0]
              << " Filename(.txt)" << std::endl;
    return EXIT_FAILURE;
    }
 
  std::string inputFilename = argv[1];
 
  vtkSmartPointer<vtkDelimitedTextReader> reader =
    vtkSmartPointer<vtkDelimitedTextReader>::New();
  reader->SetFileName(inputFilename.c_str());
  reader->DetectNumericColumnsOn();
  reader->SetFieldDelimiterCharacters(" ");
  reader->Update();
 
  vtkTable* table = reader->GetOutput();
 
  vtkSmartPointer<vtkPoints> points =
    vtkSmartPointer<vtkPoints>::New();
  vtkSmartPointer<vtkDoubleArray> normals =
    vtkSmartPointer<vtkDoubleArray>::New();
 
  normals->SetNumberOfComponents(3); //3d normals (ie x,y,z)
 
  std::cout << "Table has " << table->GetNumberOfRows()
            << " rows." << std::endl;
  std::cout << "Table has " << table->GetNumberOfColumns()
            << " columns." << std::endl;
 
  for(vtkIdType i = 0; i < table->GetNumberOfRows(); i++)
    {
    std::cout << "x: " << (table->GetValue(i,0)).ToDouble()
              << " y: " << (table->GetValue(i,1)).ToDouble()
              << " z: " << (table->GetValue(i,2)).ToDouble();
 
    points->InsertNextPoint((table->GetValue(i,0)).ToDouble(),
                            (table->GetValue(i,1)).ToDouble(),
                            (table->GetValue(i,2)).ToDouble());
 
    double n[3];
    n[0] = (table->GetValue(i,3)).ToDouble();
    n[1] = (table->GetValue(i,4)).ToDouble();
    n[2] = (table->GetValue(i,5)).ToDouble();
 
    std::cout << " n: " << n[0] << " " << n[1] << " " << n[2] << std::endl;
    normals->InsertNextTuple(n);
    }
 
  std::cout << "There are " << points->GetNumberOfPoints()
            << " points." << std::endl;
 
  vtkSmartPointer<vtkPolyData> polydata =
    vtkSmartPointer<vtkPolyData>::New();
  polydata->SetPoints(points);
  polydata->GetPointData()->SetNormals(normals);
 
  vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter =
    vtkSmartPointer<vtkVertexGlyphFilter>::New();
#if VTK_MAJOR_VERSION <= 5
  glyphFilter->SetInputConnection(polydata->GetProducerPort());
#else
  glyphFilter->SetInputData(polydata);
#endif
  glyphFilter->Update();

  // Write the file
  vtkSmartPointer<vtkXMLPolyDataWriter> writer =  
    vtkSmartPointer<vtkXMLPolyDataWriter>::New();
  writer->SetFileName("test.vtp");
#if VTK_MAJOR_VERSION <= 5
  writer->SetInput(polydata);
#else
  writer->SetInputData(polydata);
#endif
    // Optional - set the mode. The default is binary.
  //writer->SetDataModeToBinary();
  //writer->SetDataModeToAscii();
 
  writer->Write();
 
  // Visualize
  vtkSmartPointer<vtkPolyDataMapper> mapper =
    vtkSmartPointer<vtkPolyDataMapper>::New();
  mapper->SetInputConnection(glyphFilter->GetOutputPort());
 
  vtkSmartPointer<vtkActor> actor =
    vtkSmartPointer<vtkActor>::New();
  actor->SetMapper(mapper);
  actor->GetProperty()->SetPointSize(3);
  actor->GetProperty()->SetColor(0,1,0);
 
  vtkSmartPointer<vtkRenderer> renderer =
    vtkSmartPointer<vtkRenderer>::New();
  vtkSmartPointer<vtkRenderWindow> renderWindow =
    vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->AddRenderer(renderer);
  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);
 
  renderer->AddActor(actor);
  renderer->SetBackground(1.0, 1.0, 1.0); // Background color green
 
  renderWindow->Render();
  renderWindowInteractor->Start();
 
  return EXIT_SUCCESS;
}
0.0 0.0 0.0 255 0 0
1.0 0.0 0.0 0 255 0
0.0 1.0 0.0 0 0 255
1.0 1.0 0.0 0 0 255

Attachment: test.vtp
Description: Binary data

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the ParaView Wiki at: 
http://paraview.org/Wiki/ParaView

Follow this link to subscribe/unsubscribe:
http://www.paraview.org/mailman/listinfo/paraview

Reply via email to