[vtkusers] problem with texture mapping
Ankur Deshmukh
adeshmuk at uccs.edu
Tue Jan 10 08:18:46 EST 2006
I have a couple of questions on texture mapping. I have a program which
lets the user select a specified area on the volumetric data. I want to
map certain texture in that area.
1. How do I go about mapping this texture? If any one can send me a
piece of code it would be greatly helpful.
I have a snippet of code which I had even posted earlier. The error of
running this program is a segmentation fault. Can anyone tell me whats
wrong with this code.
Any Help is highly appreciated
CODE:
//Extracting the skin
vtkContourFilter *skinExtractor = vtkContourFilter::New();
skinExtractor->SetInput(imageData);
skinExtractor->SetValue(0, 500);
vtkPolyDataNormals *skinNormals = vtkPolyDataNormals::New();
skinNormals->SetInput(skinExtractor->GetOutput());
skinNormals->SetFeatureAngle(60.0);
vtkStripper *skinStripper = vtkStripper::New();
skinStripper->SetInput(skinNormals->GetOutput());
vtkPolyDataMapper *skinMapper = vtkPolyDataMapper::New();
skinMapper->SetInput(skinStripper->GetOutput());
skinMapper->ScalarVisibilityOff();
vtkActor *skin = vtkActor::New();
skin->SetMapper(skinMapper);
skin->GetProperty()->SetDiffuseColor(1, .49, .25);
skin->GetProperty()->SetSpecular(.3);
skin->GetProperty()->SetSpecularPower(20);
skin->GetProperty()->SetOpacity(1.0);
// Extracting the bones
// vtkContourFilter *boneExtractor = vtkContourFilter::New();
boneExtractor->SetInput(imageData);
boneExtractor->SetValue(0, 1150);
vtkPolyDataNormals *boneNormals = vtkPolyDataNormals::New();
boneNormals->SetInput(boneExtractor->GetOutput());
boneNormals->SetFeatureAngle(60.0);
vtkStripper *boneStripper = vtkStripper::New();
boneStripper->SetInput(boneNormals->GetOutput());
vtkPolyDataMapper *boneMapper = vtkPolyDataMapper::New();
boneMapper->SetInput(boneStripper->GetOutput());
boneMapper->ScalarVisibilityOff();
vtkActor *bone = vtkActor::New();
bone->SetMapper(boneMapper);
bone->GetProperty()->SetDiffuseColor(1, 1, .9412);
/// An outline provides context around the data./
////
vtkOutlineFilter *outlineData = vtkOutlineFilter::New();
outlineData->SetInput(imageData);
vtkPolyDataMapper *mapOutline = vtkPolyDataMapper::New();
mapOutline->SetInput(outlineData->GetOutput());
vtkActor *outline = vtkActor::New();
outline->SetMapper(mapOutline);
outline->GetProperty()->SetColor(0,0,0);
//Texture mapping data
vtkTextureMapToPlane *texturePlane = vtkTextureMapToPlane::New();
texturePlane->SetInput((vtkDataSet *)skinNormals->GetOutput());
vtkTransformTextureCoords *transformTexture = vtkTransformTextureCoords::New();
transformTexture->SetInput(texturePlane->GetOutput());
vtkPolyDataMapper *textureDataMapper = vtkPolyDataMapper::New();
textureDataMapper->SetInput((vtkPolyData *)texturePlane->GetOutput());
vtkImageReader2Factory *createReader = vtkImageReader2Factory::New();
vtkImageReader2 *textureReader = vtkImageReader2::New();
textureReader = createReader->CreateImageReader2(argv[4]);
textureReader->SetFileName(argv[4]);
vtkTexture *texture = vtkTexture::New();
texture->SetInput(textureReader->GetOutput());
texture->InterpolateOn();
vtkActor *textureActor = vtkActor::New();
textureActor->SetMapper(textureDataMapper);
textureActor->SetTexture(texture);
More information about the vtkusers
mailing list