[vtkusers] How to create a polygon hole in a texture ?

De Boer Ingo I.deBoer at polytec.de
Wed Apr 9 04:35:34 EDT 2003


Hi David,

that doesn't work. I still don't see anything.
Here's comes the code snip. Any further suggestions ?
Actually it doesn't have to a sphere. I need a polygon
of n sides.

greets
  Ingo

void CVtkData::CreateFromColorIndex(BYTE *pBuffer, int iWidth, int iHeight)
{
	float fAspectRatio  = (float)iWidth/(float)iHeight;

	vtkImageData *image = vtkImageData::New();
	image->SetExtent(0, iWidth, 0, iHeight, 0, 0);	
	image->SetUpdateExtent(0, iWidth, 0, iHeight, 0, 0);
	image->SetScalarTypeToUnsignedChar();

	for (int j = 0; j < iHeight; j++)
		for (int i = 0; i < iWidth; i++)
			*((BYTE*)image->GetScalarPointer(i,j,0)) = *pBuffer++;

	if (m_pvtkTexture) m_pvtkTexture->Delete();
	m_pvtkTexture = vtkTexture::New();
	m_pvtkTexture->SetInput(image);
	m_pvtkTexture->InterpolateOn();

	vtkPlaneSource *plane = vtkPlaneSource::New();
	plane->SetOrigin( 0.0, 0.0, 0.0);
	plane->SetPoint1( fAspectRatio*0.5, 0.0, 0.0);
	plane->SetPoint2( 0.0, 0.5, 0.0);
	plane->SetCenter( 0.0, 0.0, 0.0);
	plane->SetXResolution(64);
	plane->SetYResolution(64);

	vtkPolyDataMapper *planeMapper = vtkPolyDataMapper::New();
#define MAKE_HOLE

#ifdef MAKE_HOLE
	vtkSphere *sphere = vtkSphere::New();
	sphere->SetRadius(.5);
	sphere->SetCenter(0,0,0);
	vtkClipPolyData *clipper = vtkClipPolyData::New();
	clipper->SetInput(plane->GetOutput());
	clipper->SetClipFunction(sphere);
	clipper->GenerateClipScalarsOn();
	clipper->GenerateClippedOutputOn();
	clipper->SetValue(0);
	planeMapper->SetInput(clipper->GetOutput());
#else
	planeMapper->SetInput(plane->GetOutput());
#endif

	m_pvtkActor->SetMapper(planeMapper);
	m_pvtkActor->SetTexture(m_pvtkTexture);
	m_pvtkRenderer->AddActor(m_pvtkActor);
	m_pvtkRenderer->SetBackground(1, 1, 1);

	planeMapper->Delete();
	plane->Delete();
	image->Delete();
}



More information about the vtkusers mailing list