Texturizing model

Hi,

I want to texturize a 3d model, but do not want to install the SlicerIGT extension. So, I tried to implement the application of the texture similar to this:

My code looks like this:

// assign as texture to model
vtkMRMLModelNode* modelNode = ...
vtkMRMLModelDisplayNode* modelDisplayNode = vtkMRMLModelDisplayNode::SafeDownCast(modelNode->GetDisplayNode());
modelDisplayNode->SetBackfaceCulling(0);
vtkSmartPointer<vtkImageFlip> textureImageFlipVert = vtkImageFlip::New();
textureImageFlipVert->SetFilteredAxis(1);
textureImageFlipVert->SetInputConnection(textureNode->GetImageDataConnection());
modelDisplayNode->SetTextureImageDataConnection(textureImageFlipVert->GetOutputPort());

The problem is, that VTK warns me that instances of vtkImageFlip are still around on program exit. What is the proper way to achieve my goal in this case? Ideally, I would be able to remove the volume node from the scene again after the application to the model, as I don’t need it anymore then.

vtkSmartPointer<vtkImageFlip> textureImageFlipVert = vtkImageFlip::New(); is the problem. A vtkSmartPointer must be initialized with a vtkSmartPointer<>::New.

A proper solution would be to add better support for textured models in Slicer core.

  • Add node reference to vtkMRMLModelNode to be able to refer to a vtkMRMLVolumeNode to store texture. This would ensure that if you save and load the scene, the texture would remain on the model node. This could be implemented in about 10-20 lines.
  • Add GUI to models module to select a texture volume. Minor edit, 20-30 lines of code.
  • Add function to models module to convert texture image to point or cell scalars. This is what is implemented in SlicerIGT, so it should not be too hard to port it to C++.

Ooh, sometimes blindness overcomes me… Thanks!

I will look into that, maybe I can provide a draft implementation for that.
One question to this:

  • Add node reference to vtkMRMLModelNode to be able to refer to a vtkMRMLVolumeNode to store texture. This would ensure that if you save and load the scene, the texture would remain on the model node. This could be implemented in about 10-20 lines.

Is setting a reference enough for that? After loading, of course the reference to the correct volume node would be there, but I guess that the texture is not applied automatically then? Can you point me to an example where a node association between two nodes is re-established after loading a scene? Thanks.