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

David.Pont at ForestResearch.co.nz David.Pont at ForestResearch.co.nz
Wed Apr 9 17:22:42 EDT 2003


Hi Ingo,
   Your plane has height 0.5, width fAspectRatio*.5, ie around 0.5. The
sphere has radius 0.5 and thus diameter 1 and is clipping everything! Try a
smaller sphere, eg 0.25.
If you really want to clip with a polygon you might want to look at
vtkImplicitSelectionLoop and vtkImplicitDataSet, or wait to see if I ever
complete an experimantal class I have that uses polydata as an implicit
function.
  regards
     Dave Pont


                                                                                                                                                
                    "De Boer Ingo"                                                                                                              
                    <I.deBoer at poly       To:     <David.Pont at ForestResearch.co.nz>                                                              
                    tec.de>              cc:     <vtkusers at public.kitware.com>                                                                  
                                         Subject:     Re: [vtkusers] How to create a polygon hole in a texture ?                                
                    09/04/2003                                                                                                                  
                    20:35                                                                                                                       
                                                                                                                                                
                                                                                                                                                





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