how to convert the 2d image into 3d object file using vtk - visual-c++

how to convert the image into object file like as .obj or .ply . I need some code written in visualization toolkit and c++.
Thanks

Image data is pixel data and .obj/ .ply or for that matter .stl is 3D geometry data with Point and Cell (for .obj Cell is Triangle) information.
Your question is not clear, but to give you some steps -
First, you need to identify how would you convert the pixels into points? vtkImageDataGeometryFilter might be of help here. Although it might not be sufficient as you will also need triangles data.
Once you get vtkPolyData from image data, you can write this data to STL or OBJ or PLY format. You can use following VTK classes for that
vtkSTLWriter, vtkOBJWriter and vtkPLYWriter.

Related

Does vtk mesh generation change coordinates?

I converted nifti file to vtk using python-implemented vtk. The main function was vtkMarchingCubes.
contour=vtk.vtkMarchingCubes()
The result vtk meshes have proper shape but their locations seem changed.
For example, when I load them with the pial surface made from exactly the same nifti image using different pipelines (freesurfer) in the same scene, the result is like below.
Does vtk converting of nifti changes the coordinate of vertices or somehow 'reset' them?
VTK's MarchingCubes filter should produce triangles in the same coordinate system as the volume. The only issue is that the Nifti image also includes a coordinate system of the image, and VTK is probably not correctly using it. I'd guess there's a transform in the Nifti that VTK isn't properly using.
Try using either Slicer (slicer.org) or ITK-Snap (itksnap.org). They do better at maintaining coordinate systems for medical images.
Yes, VTK changes the coordinate when read nifti.
-get Q-matrix using GetQFormMatrix()
-transform coordinate using vtkTransform()
is reqiured.

Importing Transient Data into Paraview

I have a 3D triangulated surface. Nodes and Conn variables store the coordinates and connectivity of the triangles. At each vertex, a scalar quantity, S, and a vector with three components, V, are stored. These data are time-dependent. Also, my geometry does not change over time and I have one surface for all the timesteps.
How should I approach for writing a VTK file that has the transient data over this surface? In other words, I want to write the value of S and V at different timestep on this 3D surface in a single VTK file. I ultimately want to import this VTK file into Paraview for visualization. vtkTemporalDataSet seems to be the solution for me but I could not find an example on how to write an ASCII or binary file for this VTK class. Could vtkPolyData somehow be used to define time so that Paraview knows the transient nature of my dataset? I would appreciate any help or comment.
The VTK file format does not support transient data. However, you can write a series of files that ParaView will interpret as a time sequence. This will work fine with poly data in the VTK file. The file series is defined as files of the same name with a number identifier in them. For example, if you have a series of files named:
MyFile_000.vtk
MyFile_001.vtk
MyFile_002.vtk
ParaView will group these files together in its file browser and when you read them together, it will treat them as a file sequence with 3 time steps.
The bad part of this representation is that you will have to replicate the Nodes and Conn in each file. If that is a problem, you will have to use a different file format that supports multiple time steps using the same connection information (such as the Exodus II file format).

Converting voxelized model into smooth form

I have a 3D model as mesh structure or in .stl/.obj format which I converted to voxels using binvox voxelization tool. Using a Java program, I have done some processing on the voxel grid thus obtained. Now, I wish to covert this voxelized model back into a "smooth" mesh structure (or any other format), which can later be exported to .stl or .obj format.
Can someone suggest how can I achieve the last part, i.e. converting the voxel grid into some format for retrieving back the "smooth" surfaces ? Any help, including pointing to existing tools, or relevant theory in this direction will be appreciated.
Give a try to Marching Cubes algorithm. See http://paulbourke.net/geometry/polygonise/ for more details.

Convert/export graphics from Pov-Ray in 2D vector format

By default, Pov-Ray renders a bitmap file. Is there a way to convert or export the same image, in a vector format like eps, pdf, svg etc?
POV-Ray does not have any sort of vector output. In general ray-tracers (like POV-Ray) work by tracing rays from screen pixels into the scene, to work out what colour pixels should be - so they are inherently pixel based.
To 'ray-trace' to a vector format, you would have to calculate illumination values for each visible polygon, and then project the polygons onto the viewing angle as vectors. I don't know of any available software that can do this.
I'll also add that if you take an image and convert it using most tools to a vector format like pdf or eps, it basically just wraps up the bitmap data into an array and still can only render it pixel by pixel.
But if you render with POV-Ray at high contrast so that you can convert it to a black and white image, you can then use free software called potrace to convert it to true vector graphics.
Firstly, you can export the POV-Ray graphic to an asc file. To do so, see the link and answer given here.
Then you can open this asc file in Meshlab, and then export it in the STL or OBJ format. Finally you can import the STL or the OBJ file in Wings3D, which allows to export to eps and svg.

Library for raster cartographic transformations. 'Unprojected' to ANY

I have many raster (bitmap) images that I'd like to transform from unprojected lat-lon to a projected rendering. (e.g. GIF, PNG).
I don't understand how to use PROJ.4 to render the resulting image. I'd like a library or software that can do this all automatically. GRASS GIS is large. The transforms are relatively simple transforms and of raster images only.
Or is there basic code or an example of how I would do this? using PROJ.4 and GraphicsMagick.
It is a little confusing about what you are asking for here.
If you are trying to convert from a LAT Long geo referenced image to another projection or if you just want to keep the current geo referencing of a bitmap and convert it to another format such as GIF or PNG.
If you wish to change formats I don't believe PNG or GIF supports geo referencing in its header so this will not be possible. If you are looking at trying to compress the image so it doesn't take up as much space you could look at JPEG or JPEG2000 as these support both. For a full list of image formats and what supports geo referencing and what does not this page is a good place to start:
Link
If you wish to change the co-ordinate projection from lat, long to something else (like Mercator mga zone XX) You can use something like GDAL to batch the process.
Download from here: http://trac.osgeo.org/gdal/wiki/DownloadingGdalBinaries
See here for a list of inlcuded utilities: Link
See here for the utility help for changing projections: Link
See here for utility that changes image formats: Link
Hopefully that will be of help to you.

Resources