I have a PLY made from a stereophotogrammatic scanner. It also has a texture file in jpg format. I tried setting the option for these texture files to “scalar overlay” and asked it to apply to the model I already loaded. When I do that, nothing happens, no error message nor the trace of the texture files as far as I can tell. There is no scalar listed under the “Scalar” tab of the models module.
If you loaded the ply file as a model and the jpg texture file as a volume, then you can apply the texture to the model by using Texture model module of SlicerIGT extension.
@lassoan
I just installed IGT, I don’t seem to have textured mesh module as seen in video. I do have the texture model module, but it doesn’t seem to do anything when I choose the ply as the model, and the jpg as the texture and hit apply. If I check the “set color information as point data”, then I get these error messages.
Traceback (most recent call last):
File “C:/Users/Murat/AppData/Roaming/NA-MIC/Extensions-26813/SlicerIGT/lib/Slicer-4.8/qt-scripted-modules/TextureModel.py”, line 114, in onApplyButton
logic.applyTexture(self.inputModelSelector.currentNode(), self.inputTextureSelector.currentNode(), self.addColorAsPointAttributeCheckbox.checked)
File “C:/Users/Murat/AppData/Roaming/NA-MIC/Extensions-26813/SlicerIGT/lib/Slicer-4.8/qt-scripted-modules/TextureModel.py”, line 131, in applyTexture
self.convertTextureToPointAttribute(modelNode, textureImageNode)
File “C:/Users/Murat/AppData/Roaming/NA-MIC/Extensions-26813/SlicerIGT/lib/Slicer-4.8/qt-scripted-modules/TextureModel.py”, line 153, in convertTextureToPointAttribute
assert numOfPoints == tcoords.GetNumberOfTuples(), “Number of texture coordinates does not equal number of points”
AttributeError: ‘NoneType’ object has no attribute ‘GetNumberOfTuples’
Yes, the module has been renamed to Texture model, as I wrote above.
It seems that your PLY does not have texture coordinates, therefore, you cannot apply a texture. It would be nice if you could add a check there in line 153 to display a message box if tcoords is None instead of just logging the error message and send a pull request.
Have you applied any processing to the PLY file that could have removed the texture coordinates?
Sorry, I don’t normally work with this data, so I don’t know whether there has been any processing done to it. This is from 3dMD. All I can say texture is visible when I load the same file into the meshlab.
Thank you for the sample data. It seems that VTK cannot load texture coordinates from this .ply file. The simplest workaround is to load the data set in MeshLab and save as .obj file and load the .obj file into Slicer. Texture coordinates seems to be stored in a more standardized way in .obj files and VTK can find it there. If it is important for you to load .ply files directly then it should be possible to fix it quite easily.
Does the texture need to be an overlay? If you import the file into Meshlab, you can apply the filter: Transfer texture to vertex color, then transfer the vertex color to face color and export as a new ply mesh with only face color. Then open in 3D Slicer, go to Models and check the “Scalars Visible” box, select RGB from the dropdown and it will load. I also got it to work with an obj as long as the color is “face color.” For some reason, it would not read the color correctly if it was saved in the vertex.
If someone does not want to copy-paste scripts then the “Texture model” module in SlicerIGT extension can be used for this:
The module even has the option of assigning texture values to each mesh point, just in case you want to perform mesh processing based on texture values or want to save the textured model into a single vtk or ply file. The texture image can contain more details than what can be reconstructed from point data, so the point-sample-based color representation is not a complete replacement of texture mapping.
I am confused with how you imported the file as a volume, unless this was already a separate file to begin with that contained only the RGB values. How do you separate the RGB values from the OBJ file?
The texture image (png file) was loaded as usual, using “Add data”.
The user experience could be improved by automatically loading associated texture files; and by saving in the scene the information that a texture is associated with a model (currently, the association between the model and texture image is not stored persistently in the scene).
Ah, so this goes back to my original question then. I do not have a PNG file for the texture, but rather I have a OBJ file with both the vertices and texture values (similar to the way you said you can save OBJ files with these), and faces.
An OBJ file cannot store per-vertex color, just texture coordinates (see specification). The color is determined by mapping portions of the texture image (specified by the texture coordinates) on the rendered surface.
If you don’t have the texture image then you won’t have colors (other than the uniform colors that are defined in the material file).
There might be non-standard variations of file formats, so if you are sure that you have per-vertex color information in your OBJ files then you can upload an example somewhere and post the link here so that we can have a look.
Thanks, this snippet was useful. While vertex color cannot be stored in standard OBJ files, it seems that there is a workaround that is used in your file, too. VTK does not support this workaround, but probably you can find other software that does.
Therefore, I would recommend load the non-standard OBJ file using a software that supports per-vertex colors (you can try MeshLab) then save it into a standard PLY file (that supports per-vertex coloring). If you save the vertex colors in uchar type properties with the names red, green, and blue then Slicer will load the vertex colors.
ok thank you. Is there any chance that this might be something done in the future? I am collaborating with some people who would very much appreciate it, but I don’t want to get their hopes up.