[vtk-developers] Fwd: About constructing a 3D geographical surface

Andrew Maclean andrew.amaclean at gmail.com
Thu Oct 11 20:24:28 EDT 2007


Even simpler, you can just use vtkParticle reader. It wil;l read x,y,z data
along with a scalar.

Here is the code I use. Note it writes out a .vtp file that can be used for
further processing in either vtk or ParaView.



// Author: Andrew J. P. Maclean

// Purpose read in a dataset where each line consists of point

// with its position (x,y,z) and (possibly) a scalar.

// Then create and save a vtk polydata array suitable for further rendering.

#include <iostream>

#include <stdexcept>

#include <string>

#include <fstream>

#include <iomanip>

#include <algorithm>

#include <sstream>

#include <vtkRenderer.h>

#include <vtkRenderWindow.h>

#include <vtkRenderWindowInteractor.h>

#include <vtkPolyDataMapper.h>

#include <vtkActor.h>

#include <vtkXMLPolyDataWriter.h>

#include <vtkXMLPolyDataReader.h>

#include <vtkParticleReader.h>

#include <vtkSmartPointer.h>



int main ( int argc, char* argv[] )

{

if ( argc != 3 )

{

std::cout << "Need input file and output file." << std::endl;

return 1;

}

std::string ifn = argv[1];

std::string ofn = argv[2];

std::cerr << "Input file: " << ifn << std::endl;

std::cerr << "Output file: " << ofn << std::endl;

if ( ifn == ofn )

{

std::cerr << "File names cannot be the same." << std::endl;

return 1;

}

vtkSmartPointer<vtkParticleReader> reader =
vtkSmartPointer<vtkParticleReader>::New();

reader->SetFileName(ifn.c_str());

reader->Update();

vtkSmartPointer<vtkXMLPolyDataWriter> writer =
vtkSmartPointer<vtkXMLPolyDataWriter>::New();

writer->SetInput(reader->GetOutput());

writer->SetFileName(ofn.c_str());

writer->Write();

// Set up the pipeline.

vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();

mapper->SetInput(reader->GetOutput());

vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();

actor->SetMapper(mapper);

vtkSmartPointer<vtkRenderer> ren = vtkSmartPointer<vtkRenderer>::New();

ren->SetBackground(0.2,0.2 ,0.3);

vtkSmartPointer<vtkRenderWindow> renWin =
vtkSmartPointer<vtkRenderWindow>::New();

renWin->AddRenderer(ren);

renWin->SetSize(800 ,600);

vtkSmartPointer<vtkRenderWindowInteractor> iRen =
vtkSmartPointer<vtkRenderWindowInteractor>::New();

iRen->SetRenderWindow(renWin);

ren->AddViewProp(actor);

ren->Render();

iRen->Initialize();

iRen->Start();

}








On 10/11/07, Soeren Gebbert <soerengebbert at googlemail.com> wrote:
>
> Hi John,
> i dont know java so i can only provide some C++ code snips.
> But i guess you can do something like this:
>
> double x, y, z, value;
> vtkIdList *ids = vtkIdList::New();
> vtkPoints *points = vtkPoints::New();
> vtkDoubleArray *values = vtkDoubleArray::New();
> values->SetNumberOfTuples(NumberOfPointsInDataset);
> values->SetNumberOfComponents(1);
> values->SetName("resistivity");
>
> for(i = 0; i < NumberOfPointsInDataset; i++)
> {
>   // Read your data into x, y and z coordiantes
>   points->InsertPoint(i, x, y, z);
>
>   //Read your resistivity values
>   values->InsertValue(i, value);
>
>   //Create point ids for the cells
>   ids->InsertNextId(i);
> }
>
> // Build PolyData
> vtkPolyData *poly = vtkPolyData::New();
> poly->Allocate(NumberOfPointsInDataset);
> poly->SetPoints(points);
> points->Delete();
> poly->GetPointData()->SetScalars(values);
> values->Delete();
>
> //Now build the cells. You can build triangles if you know the order
> //of your points. If you dont know the order than just create a PolyVertex
> cell to render the points in VTK
> //use the delaunay triangulator: to triangluate the data
>
> poly->InsertNextCell(VTK_POLY_VERTEX, ids);
> ids->Delete();
> poly->Sqeeze();
>
> //Now use the delaunay triangulator to triangulate the poly data set
> vtkDelaunay2d ....
>
> //The code is untested and without any warranty :)
>
> //END
>
> References:
> http://www.vtk.org/doc/release/5.0/html/a01872.html
> http://www.vtk.org/doc/release/5.0/html/a01335.html
> http://www.vtk.org/doc/release/5.0/html/a01867.html
> http://www.vtk.org/doc/release/5.0/html/a01322.html
> http://www.vtk.org/doc/release/5.0/html/a01880.html
>
> Best regards
> Soeren
>
> 2007/10/11, John Ownsoul <mongwarrior at yahoo.com>:
> >
> >
> > Hi Soeran;
> >
> > Thanks for your attention and help. I can write my own program to map
> > the
> > geographical data to java. But, what must i do after than getting the
> > values
> > and coordinates? Could you send me a sample code or a reference about
> > this?
> > Thanks again; (I want to use only java and vtk)
> >
> > Best regards;
> >
> > John Ownsoul
> >
> >
> >
> >
> >
> >
> >
> >
> > Soeren Gebbert-2 wrote:
> > >
> > > Hi John,
> > > just an idea. If you have geographical data which you want to
> > visualize
> > > with
> > > vtk
> > > than try the combination of the gis grass and paraview. There are many
> > > options
> > > in grass to get your x,y,z ascii data into it. You can process the
> > data
> > > there and export it with the grass module r.out.vtk into the vtk
> > format to
> > > visualize
> > > the data with paraview, visit or mayavi.
> > >
> > > Or you can build in java a poly dataset with x,y,z point coordinates
> > > connected with triangles to
> > > each other and store the resistivity values in an point data double
> > array.
> > > If you have
> > > an ordered point set the triangulation should be no problem.
> > > AFAIC you have to import the data with your own program. There is no
> > > x,y,z,value import module in vtk. But im not sure.
> > >
> > > Best regards
> > > soeren
> > >
> > > Link to grass:
> > > grass.itc.it
> > >
> > > Link to some grass/vtk modules and related stuff:
> > > www-pool.math.tu-berlin.de/~soeren/grass/modules<http://www-pool.math.tu-berlin.de/%7Esoeren/grass/modules
> > <http://www-pool.math.tu-berlin.de/~soeren/grass/modules>>
> > >
> > > 2007/10/11, John Ownsoul <mongwarrior at yahoo.com>:
> > >>
> > >>
> > >> Dear Fellows;
> > >>
> > >> I have some data about a geographical surface, and i want to show an
> > >> image
> > >> in VTK (with Java).
> > >> But i am a beginner, so i don't know the syntax very well. I practice
> > >> with
> > >> VTK, but i don't know the file operations. Could you help me to
> > construct
> > >> the file and show the image in vtk??
> > >>
> > >> I use these datas at the below:
> > >>
> > >> x(m)   y(m)   z(m)    resistivity value(ohm.m)
> > >> 2        1    -1,406           204,934
> > >> 3        1    -1,406           108,021
> > >> 4        1    -1,406             62,275
> > >> 5        1    -1,406             47,608
> > >>                     ...
> > >>
> > >>
> > >> Thanks for everything...
> > >>
> > >> --
> > >> View this message in context:
> > >> http://www.nabble.com/About-constructing-a-3D-geographical-surface-tf4605431.html#a13150408
> >
> > >> Sent from the VTK - Dev mailing list archive at Nabble.com<http://nabble.com/>
> > .
> > >>
> > >> _______________________________________________
> > >> vtk-developers mailing list
> > >> vtk-developers at vtk.org
> > >> http://www.vtk.org/mailman/listinfo/vtk-developers
> > >>
> > >
> > > _______________________________________________
> > > vtk-developers mailing list
> > > vtk-developers at vtk.org
> > > http://www.vtk.org/mailman/listinfo/vtk-developers
> > >
> > >
> >
> > --
> > View this message in context: http://www.nabble.com/About-constructing-a-3D-geographical-surface-tf4605431.html#a13152207
> >
> > Sent from the VTK - Dev mailing list archive at Nabble.com<http://nabble.com/>
> > .
> >
> > _______________________________________________
> > vtk-developers mailing list
> > vtk-developers at vtk.org
> > http://www.vtk.org/mailman/listinfo/vtk-developers
> >
>
>
> _______________________________________________
> vtk-developers mailing list
> vtk-developers at vtk.org
> http://www.vtk.org/mailman/listinfo/vtk-developers
>
>


-- 
___________________________________________
Andrew J. P. Maclean
Centre for Autonomous Systems
The Rose Street Building J04
The University of Sydney  2006  NSW
AUSTRALIA
Ph: +61 2 9351 3283
Fax: +61 2 9351 7474
URL: http://www.acfr.usyd.edu.au/
___________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20071012/1e9880f4/attachment.html>


More information about the vtk-developers mailing list