[vtkusers] Looking for zoom sample
Dean Inglis
dean.inglis at camris.ca
Wed Jun 16 12:55:17 EDT 2004
Hi Ingo,
Here is some C++ sample code wherein one can
place a smaller renderer in a main renderwindow.
An outline of this renderer is created and its
visbility is controlled depending on program state.
m_segmentActor is a vtkActor used to show
a copy of a traced outline from an image and
a vtkSplineWidget (m_spline) in the main renderer.
m_renderer is the small lower right corner
vtkRenderer.
m_renderWindow is the main vtkRenderWindow.
m_outline is a vtkPolyData.
m_outlineActor is a vtkActor2D.
<snip>
// intialize some vtk objects
vtkPolyDataMapper* segmentMapper = vtkPolyDataMapper::New();
segmentMapper->SetInput(m_tempPoly);
m_segmentActor->SetMapper(segmentMapper);
m_segmentActor->VisibilityOff();
segmentMapper->Delete();
vtkProperty* aprop = m_segmentActor->GetProperty();
aprop->SetRepresentationToWireframe();
aprop->SetColor(1,1,0);
aprop->SetLineWidth(2);
m_renderer->SetLayer(1);
m_renderer->InteractiveOff();
m_renderer->SetViewport(.8,0,1,.2);
m_renderWindow->AddRenderer(m_renderer);
m_renderWindow->SetNumberOfLayers(2);
m_renderer->AddProp(m_segmentActor);
double vp[4];
m_renderer->GetViewport( vp );
m_renderer->NormalizedDisplayToDisplay( vp[0], vp[1] );
m_renderer->NormalizedDisplayToDisplay( vp[2], vp[3] );
m_outline->Allocate();
vtkPoints *points = vtkPoints::New();
vtkIdType ptIds[5];
ptIds[4] = ptIds[0] = points->InsertNextPoint( 1, 1, 0 );
ptIds[1] = points->InsertNextPoint( 2, 1, 0 );
ptIds[2] = points->InsertNextPoint( 2, 2, 0 );
ptIds[3] = points->InsertNextPoint( 1, 2, 0 );
points->SetPoint( 0, vp[0]+1, vp[1]+1, 0 );
points->SetPoint( 1, vp[2]-1, vp[1]+1, 0 );
points->SetPoint( 2, vp[2]-1, vp[3]-1, 0 );
points->SetPoint( 3, vp[0]+1, vp[3]-1, 0 );
m_outline->SetPoints( points );
m_outline->InsertNextCell( VTK_POLY_LINE, 5, ptIds );
vtkCoordinate *tcoord = vtkCoordinate::New();
tcoord->SetCoordinateSystemToDisplay();
vtkPolyDataMapper2D *mapper = vtkPolyDataMapper2D::New();
mapper->SetInput( m_outline );
mapper->SetTransformCoordinate( tcoord );
mapper->ScalarVisibilityOff();
m_outlineActor->SetMapper( mapper );
m_outlineActor->SetPosition( 0, 0 );
m_outlineActor->SetPosition2( 1, 1 );
vtkProperty2D* prop = m_outlineActor->GetProperty();
prop->SetColor(1,0,0);
prop->SetLineWidth(2);
m_renderer->AddProp(m_outlineActor);
m_outlineActor->VisibilityOff();
<snip>
Now, when we have some polydata to display, turn on the
actors in the renderer...
<snip>
// add a copy of a spline's polydata to the small renderer
if(!m_spline->GetEnabled()){ return;}
vtkPolyData* poly = vtkPolyData::New();
m_spline->GetPolyData(poly);
if(poly->GetNumberOfPoints()<2)
{
poly->Delete();
return;
}
(vtkPolyDataMapper::SafeDownCast(m_segmentActor->GetMapper()))->SetInput(pol
y);
m_outlineActor->VisibilityOn();
m_segmentActor->VisibilityOn();
m_renderer->ResetCameraClippingRange();
m_renderer->ResetCamera();
m_renderer->Render();
poly->Delete();
<snip>
Dean
More information about the vtkusers
mailing list