001/*
002 * Copyright 2010, 2011 Institut Pasteur.
003 * 
004 * This file is part of ICY.
005 * 
006 * ICY is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 * 
011 * ICY is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014 * GNU General Public License for more details.
015 * 
016 * You should have received a copy of the GNU General Public License
017 * along with ICY. If not, see <http://www.gnu.org/licenses/>.
018 */
019package plugins.tutorial.vtk;
020
021import icy.painter.Overlay;
022import icy.painter.VtkPainter;
023import vtk.vtkProp;
024import vtk.vtkTextActor;
025import vtk.vtkTextProperty;
026
027/**
028 * This class shows how to use VTK to render a simple 2D text as 3D painter
029 * 
030 * @author Stephane
031 */
032public class VtkText2DPainter extends Overlay implements VtkPainter
033{
034    // vtk object
035    private vtkTextActor textActor;
036
037    public VtkText2DPainter()
038    {
039        super("VTK 2D text");
040
041        init();
042    }
043
044    // init vtk objects
045    private void init()
046    {
047        // VTK 2D text object
048        textActor = new vtkTextActor();
049        textActor.SetInput("VTK text test");
050
051        final vtkTextProperty textProperty = textActor.GetTextProperty();
052
053        // change text properties
054        textProperty.SetFontFamilyToArial();
055        textProperty.BoldOn();
056        textProperty.ShadowOn();
057        textProperty.SetFontSize(30);
058        textProperty.SetColor(0.5, 0.5, 0.5);
059        textProperty.SetShadowOffset(2, 2);
060
061        // set text position
062        textActor.SetPosition(100, 300);
063    }
064
065    @Override
066    public vtkProp[] getProps()
067    {
068        return new vtkProp[] {textActor};
069    }
070}