Exporting RGB Polydata to .OBJ or .PLY

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Exporting RGB Polydata to .OBJ or .PLY

Radosław Furmaniak
Hello,
I have set up PolyData and added 4 component scalar array to it. When I create PolyDataMapper, set scalar visibility and add actor to the scene, all colors are rendered properly. 
However, I have a problem with exporting this scene or just the polydata to the .OBJ (+mtl) file or to the .PLY. When I open it up in Blender, geometry is exported correctly, however OBJ is created all white, and .PLY has a single, grayish color (apart from the shadows of course), which I don't think is even present in input PolyData. 

I am trying to do it like this:
plyWriter = vtk.vtkPLYWriter()
plyWriter.SetInputData(polydata)
plyWriter.SetFileTypeToBinary()
plyWriter.SetDataByteOrderToLittleEndian()
plyWriter.SetArrayName("Scalars")
plyWriter.SetFileName("model.ply")
plyWriter.Write()
I have also tried setting up different color modes in plyWriter,
 but the results are always the same. 

Scalar array is set up like this:
scalarArray = vtk.vtkDoubleArray()
scalarArray.SetNumberOfComponents(4)
scalarArray.SetName("Scalars")
polydata.GetPointData().AddArray(scalarArray)
polydata.GetPointData().SetActiveScalars("Scalars")
(I am omitting the part where I am actually setting elements of this array)
I have also tried using the OBJExporter:
writer = vtk.vtkOBJExporter()
writer.SetFilePrefix(output_prefix)
writer.SetInput(renWin)
writer.Write()
where renWin is rendering window with a single actor made from polydata mentioned above.
I am using Python 3.6 and VTK 8.1.1.
Any help how to export geometry and colors, so they can be reused in other programs?
Thanks in advance.

_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Exporting RGB Polydata to .OBJ or .PLY

kenichiro yoshimi
Hi,

You can use the vtkX3DExporter or vtkVRMLExporter to export VTK scene
and render the meshes and colors in blender.
https://www.vtk.org/gitweb?p=VTK.git;a=blob;f=IO/Export/Testing/Cxx/X3DTest.cxx
https://www.vtk.org/gitweb?p=VTK.git;a=blob;f=Rendering/Core/Testing/Python/cells.py

Regards
2018年12月7日(金) 3:13 Radosław Furmaniak <[hidden email]>:

>
> Hello,
> I have set up PolyData and added 4 component scalar array to it. When I create PolyDataMapper, set scalar visibility and add actor to the scene, all colors are rendered properly.
> However, I have a problem with exporting this scene or just the polydata to the .OBJ (+mtl) file or to the .PLY. When I open it up in Blender, geometry is exported correctly, however OBJ is created all white, and .PLY has a single, grayish color (apart from the shadows of course), which I don't think is even present in input PolyData.
>
> I am trying to do it like this:
>
> plyWriter = vtk.vtkPLYWriter()
> plyWriter.SetInputData(polydata)
> plyWriter.SetFileTypeToBinary()
> plyWriter.SetDataByteOrderToLittleEndian()
> plyWriter.SetArrayName("Scalars")
> plyWriter.SetFileName("model.ply")
> plyWriter.Write()
>
> I have also tried setting up different color modes in plyWriter,
>  but the results are always the same.
>
> Scalar array is set up like this:
>
> scalarArray = vtk.vtkDoubleArray()
> scalarArray.SetNumberOfComponents(4)
> scalarArray.SetName("Scalars")
>
> polydata.GetPointData().AddArray(scalarArray)
>
> polydata.GetPointData().SetActiveScalars("Scalars")
>
> (I am omitting the part where I am actually setting elements of this array)
>
> I have also tried using the OBJExporter:
>
> writer = vtk.vtkOBJExporter()
> writer.SetFilePrefix(output_prefix)
> writer.SetInput(renWin)
> writer.Write()
>
> where renWin is rendering window with a single actor made from polydata mentioned above.
>
> I am using Python 3.6 and VTK 8.1.1.
>
> Any help how to export geometry and colors, so they can be reused in other programs?
>
> Thanks in advance.
>
> _______________________________________________
> 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
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> https://public.kitware.com/mailman/listinfo/vtkusers
_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Exporting RGB Polydata to .OBJ or .PLY

Andras Lasso
VTK's OBJ exporter can save solid color that is set in the actor's property and Blender can use that. Point scalar data could be exported to texture and probably Blender would use that, but that has not been implemented in VTK's OBJ exporter yet - contributions are welcome.

VTK's PLY writer can write RGB point scalars and some software, for example MeshLab can display the colored model correctly. However, Blender ignores this color information (at least it does not show up when you simply import the file; maybe there are plug-ins or some settings that would fix this). MeshLab may be able to export the colored model into a format that Blender can read.

Andras

From: kenichiro yoshimi <[hidden email]>
Sent: Saturday, December 8, 2018 5:01 AM
To: [hidden email]
Cc: [hidden email]
Subject: Re: [vtkusers] Exporting RGB Polydata to .OBJ or .PLY

Hi,

You can use the vtkX3DExporter or vtkVRMLExporter to export VTK scene
and render the meshes and colors in blender.
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.vtk.org%2Fgitweb%3Fp%3DVTK.git%3Ba%3Dblob%3Bf%3DIO%2FExport%2FTesting%2FCxx%2FX3DTest.cxx&amp;data=02%7C01%7Classo%40queensu.ca%7C1e8d31503e08484147da08d65cf4124d%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636798600696862805&amp;sdata=YaDsvSv7gjU5x3ilese0EXWFXXP%2FwfbM36CNGZFT2xM%3D&amp;reserved=0
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.vtk.org%2Fgitweb%3Fp%3DVTK.git%3Ba%3Dblob%3Bf%3DRendering%2FCore%2FTesting%2FPython%2Fcells.py&amp;data=02%7C01%7Classo%40queensu.ca%7C1e8d31503e08484147da08d65cf4124d%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636798600696862805&amp;sdata=s3zn9M6VhL8ISVFAq6pXutgYLsC1tT4%2BQGOcuB%2F7%2Bgo%3D&amp;reserved=0

Regards
2018年12月7日(金) 3:13 Radosław Furmaniak <[hidden email]>:
>
> Hello,
> I have set up PolyData and added 4 component scalar array to it. When I create PolyDataMapper, set scalar visibility and add actor to the scene, all colors are rendered properly.
> However, I have a problem with exporting this scene or just the polydata to the .OBJ (+mtl) file or to the .PLY. When I open it up in Blender, geometry is exported correctly, however OBJ is created all white, and .PLY has a single, grayish color (apart from the shadows of course), which I don't think is even present in input PolyData.
>
> I am trying to do it like this:
>
> plyWriter = vtk.vtkPLYWriter()
> plyWriter.SetInputData(polydata)
> plyWriter.SetFileTypeToBinary()
> plyWriter.SetDataByteOrderToLittleEndian()
> plyWriter.SetArrayName("Scalars")
> plyWriter.SetFileName("model.ply")
> plyWriter.Write()
>
> I have also tried setting up different color modes in plyWriter,
>  but the results are always the same.
>
> Scalar array is set up like this:
>
> scalarArray = vtk.vtkDoubleArray()
> scalarArray.SetNumberOfComponents(4)
> scalarArray.SetName("Scalars")
>
> polydata.GetPointData().AddArray(scalarArray)
>
> polydata.GetPointData().SetActiveScalars("Scalars")
>
> (I am omitting the part where I am actually setting elements of this array)
>
> I have also tried using the OBJExporter:
>
> writer = vtk.vtkOBJExporter()
> writer.SetFilePrefix(output_prefix)
> writer.SetInput(renWin)
> writer.Write()
>
> where renWin is rendering window with a single actor made from polydata mentioned above.
>
> I am using Python 3.6 and VTK 8.1.1.
>
> Any help how to export geometry and colors, so they can be reused in other programs?
>
> Thanks in advance.
>
> _______________________________________________
> Powered by https://na01.safelinks.protection.outlook.com/?url=www.kitware.com&amp;data=02%7C01%7Classo%40queensu.ca%7C1e8d31503e08484147da08d65cf4124d%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636798600696862805&amp;sdata=PeaSVC7fX37vaEEQwDU9tjq%2FRKKkqqekeYXkr1xuvBA%3D&amp;reserved=0
>
> Visit other Kitware open-source projects at https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.kitware.com%2Fopensource%2Fopensource.html&amp;data=02%7C01%7Classo%40queensu.ca%7C1e8d31503e08484147da08d65cf4124d%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636798600696862805&amp;sdata=3RrDlN1d5fM25xQ9EsSRczIGHKV3dBkig4LeYNLuX%2B0%3D&amp;reserved=0
>
> Please keep messages on-topic and check the VTK FAQ at: https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.vtk.org%2FWiki%2FVTK_FAQ&amp;data=02%7C01%7Classo%40queensu.ca%7C1e8d31503e08484147da08d65cf4124d%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636798600696862805&amp;sdata=Pmqn82Jp7%2FGZuwY6IZ5ipdL0qa8vlnHpqEar9fDkUjk%3D&amp;reserved=0
>
> Search the list archives at: https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmarkmail.org%2Fsearch%2F%3Fq%3Dvtkusers&amp;data=02%7C01%7Classo%40queensu.ca%7C1e8d31503e08484147da08d65cf4124d%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636798600696862805&amp;sdata=B6DlpR1Z4bStYhDE4jPKthNVzS7f%2BWIkcl2roYr3Z9E%3D&amp;reserved=0
>
> Follow this link to subscribe/unsubscribe:
> https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpublic.kitware.com%2Fmailman%2Flistinfo%2Fvtkusers&amp;data=02%7C01%7Classo%40queensu.ca%7C1e8d31503e08484147da08d65cf4124d%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636798600696862805&amp;sdata=q5CzMjBx1OH7rByxI0E1gaDDKYSnHx292eNNVf9rcIQ%3D&amp;reserved=0
_______________________________________________
Powered by https://na01.safelinks.protection.outlook.com/?url=www.kitware.com&amp;data=02%7C01%7Classo%40queensu.ca%7C1e8d31503e08484147da08d65cf4124d%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636798600696862805&amp;sdata=PeaSVC7fX37vaEEQwDU9tjq%2FRKKkqqekeYXkr1xuvBA%3D&amp;reserved=0

Visit other Kitware open-source projects at https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.kitware.com%2Fopensource%2Fopensource.html&amp;data=02%7C01%7Classo%40queensu.ca%7C1e8d31503e08484147da08d65cf4124d%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636798600696862805&amp;sdata=3RrDlN1d5fM25xQ9EsSRczIGHKV3dBkig4LeYNLuX%2B0%3D&amp;reserved=0

Please keep messages on-topic and check the VTK FAQ at: https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.vtk.org%2FWiki%2FVTK_FAQ&amp;data=02%7C01%7Classo%40queensu.ca%7C1e8d31503e08484147da08d65cf4124d%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636798600696862805&amp;sdata=Pmqn82Jp7%2FGZuwY6IZ5ipdL0qa8vlnHpqEar9fDkUjk%3D&amp;reserved=0

Search the list archives at: https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmarkmail.org%2Fsearch%2F%3Fq%3Dvtkusers&amp;data=02%7C01%7Classo%40queensu.ca%7C1e8d31503e08484147da08d65cf4124d%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636798600696862805&amp;sdata=B6DlpR1Z4bStYhDE4jPKthNVzS7f%2BWIkcl2roYr3Z9E%3D&amp;reserved=0

Follow this link to subscribe/unsubscribe:
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpublic.kitware.com%2Fmailman%2Flistinfo%2Fvtkusers&amp;data=02%7C01%7Classo%40queensu.ca%7C1e8d31503e08484147da08d65cf4124d%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636798600696862805&amp;sdata=q5CzMjBx1OH7rByxI0E1gaDDKYSnHx292eNNVf9rcIQ%3D&amp;reserved=0

_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers