[vtkusers] display .vtk files in window

vikrant manne vikrant.manne at gmail.com
Tue Jul 28 17:40:13 EDT 2009


Hi Gurujan,
You can try implementing the following cpp code to java. I guess this works
for VtkPolyData files.
Try using different Data readers (PolyDataReader, UnstructuredGridReader or
DataSetReader) depending on your VTK file.



// necessary headers from VTK Library
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkProperty.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkRenderWindowInteractor.h"
#include <vtkDataSetWriter.h>
#include <vtkSphereSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkDataSetMapper.h>
#include <vtkActor.h>
#include <vtkProperty.h>
#include <vtkPolyData.h>
#include <vtkDataSetReader.h>
#include <vtkDataSet.h>
#include <vtkPolyDataNormals.h>
#include <vtkTriangleFilter.h>
#include <vtkStripper.h>
#include <vtkPointData.h>
#include <vtkPolyDataWriter.h>
#include "vtkPolyDataReader.h"

#include <string>

// MAIN

int main ()
{
    std::string strCurFile = "VtkFile.vtk";
    // Initialising a reader to read the VTK files
    vtkPolyDataReader * pGridReader = vtkPolyDataReader::New();
    pGridReader->SetFileName (strCurFile.c_str());
    pGridReader->Update();

    vtkPolyData* pData=vtkPolyData::New();
    pData->DeepCopy(pGridReader->GetOutput());

    // Mapper to map polygonal data to graphics primitives
    vtkPolyDataMapper *Tmap = vtkPolyDataMapper::New();
    Tmap->SetInput(pData);
// Updating the polydatamapper
    Tmap->Update();
    // Actor - used to display all the geometry
    vtkActor* Actor = vtkActor::New();
    Actor->SetMapper(Tmap);
    Actor->VisibilityOn();

    // a renderer and render window
  vtkRenderer *ren1 = vtkRenderer::New();
      vtkRenderWindow *renWin = vtkRenderWindow::New();
      renWin->AddRenderer(ren1);

      // a window interactor
      vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
      iren->SetRenderWindow(renWin);

    // add the actors to the scene
      ren1->AddActor(Actor);

    //  ren1->AddActor(outlineActor);
      ren1->SetBackground(0.5,0.5,0.5); // Background color white

      // render an image (lights and cameras are created automatically)
      renWin->Render();

      // begin mouse interaction
      iren->Start();
    // Deleting all instances after rendering
    pGridReader->Delete();
    Tmap->Delete();
    pData->Delete();
    Actor->Delete();


}

Thanks,
Vikrant Manne


On Tue, Jul 28, 2009 at 4:00 PM, Gururajan <gururajan.r at raster.in> wrote:

> john,
>
> but i need it for java. how can i plug and please give some examples.
>
> very kind to you
>
> Thanks
> Guru
>
> John Drescher wrote:
> > On Tue, Jul 28, 2009 at 4:52 PM, Gururajan<gururajan.r at raster.in> wrote:
> >
> >> david,
> >>
> >> thanks to the links,
> >> but i need some examples which exactly takes .vtk file as input to make
> >> 3d rendering and display.
> >> in those links there is no provision for .vtk files as input.
> >>
> >> Please help me in this
> >> Thanks for your valuable reply
> >> Guru
> >>
> >> David Doria wrote:
> >>
> >>> On Tue, Jul 28, 2009 at 4:36 PM, Gururajan <gururajan.r at raster.in
> >>> <mailto:gururajan.r at raster.in>> wrote:
> >>>
> >>>     Hi all,
> >>>     Please any one can help me in this.
> >>>
> >>>     I have converted dicom series into .vtk format.,  but i do not
> >>>     know how
> >>>     to display this .vtk file in 3d view.
> >>>
> >>>     am using java eclipse with vtk.jar
> >>>
> >>>
> >>>
> >
> > Paraview definitely loads .vtk files and can display them in 3D.
> >
> > John
> >
>
> _______________________________________________
> 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 VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090728/de80ec63/attachment.htm>


More information about the vtkusers mailing list