/*=========================================================================

  Program:   Orbit Visualization Tool
  Source:    $Source: /stor/devel/ovt2g/ovt/object/Axes.java,v $
  Date:      $Date: 2001/03/21 13:33:52 $
  Version:   $Revision: 1.11 $


Copyright (c) 2000 OVT Team (Kristof Stasiewicz, Mykola Khotyaintsev, 
Yuri Khotyaintsev)
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification is permitted provided that the following conditions are met:

 * No part of the software can be included in any commercial package without
written consent from the OVT team.

 * Redistributions of the source or binary code must retain the above
copyright notice, this list of conditions and the following disclaimer.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT OR
INDIRECT DAMAGES  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE.

OVT Team (http://ovt.irfu.se)   K. Stasiewicz, M. Khotyaintsev, Y.
Khotyaintsev

=========================================================================*/

/*
 * Axes.java
 *
 * Created on March 28, 2000, 8:50 PM
 */
 
package ovt.object;

import ovt.*;

import vtk.*;

/** 
 *
 * @author  ko
 * @version 
 */
public class Axes extends VisualObject {

  
  /** Holds value of property length. */
  private double length = 3;
  /** Axes actor */
  protected vtkActor actor; 
  protected vtkFollower[] axeTitleActor = new vtkFollower[3];
  protected String[] axeTitle = {"x", "y", "z"};
  protected static final int[][] axeTitlePosition = { {1, 0, 0}, {0, 1, 0}, {0, 0, 1} };
  
  /** Creates new Axes */
  public Axes(OVTCore core) {
    super(core, "Axes", core.getImagesDir()+"axes.gif");
    
    vtkAxes axes = new vtkAxes();
      axes.SetOrigin(0, 0, 0);
      axes.SetScaleFactor(getLength());
    
    vtkTubeFilter tubeFilter = new vtkTubeFilter();
    tubeFilter.SetInput(axes.GetOutput());
    tubeFilter.SetRadius(0.01);
    
    vtkPolyDataMapper mapper = new vtkPolyDataMapper();
    mapper.SetInput(tubeFilter.GetOutput());
    
    actor = new vtkActor();
    actor.SetMapper(mapper);
    
    
    vtkVectorText atext;
    vtkFollower textActor;
    double[] x = new double[3];
    int k;
    // create axis titles
    for (int i=0; i<3; i++) {
      atext = new vtkVectorText();
        atext.SetText(axeTitle[i]);
      mapper = new vtkPolyDataMapper();
        mapper.SetInput(atext.GetOutput());
      axeTitleActor[i] = new vtkFollower();
        axeTitleActor[i].SetMapper(mapper);
        axeTitleActor[i].SetScale(0.2, 0.2, 0.2);
        for (k=0; k<3; k++) x[k] = axeTitlePosition[i][k]*getLength();
        axeTitleActor[i].AddPosition(x[0], x[1], x[2]);
        axeTitleActor[i].SetCamera(getRenderer().GetActiveCamera());
        axeTitleActor[i].GetProperty().SetColor(0, 0, 0);
    }
    setVisible(true);
  }
  
  /** Returns the length of one axe
   * @return Value of property length.
   */
  public double getLength() {
    return length;
  }
  /** Setter for property length.
   * @param length New value of property length.
   *
   * @throws PropertyVetoException
   */
  public void setLength(double length) throws java.beans.PropertyVetoException {
    double oldLength = this.length;
    vetoableChangeSupport.fireVetoableChange("length", new Double (oldLength), new Double (length));
    this.length = length;
    propertyChangeSupport.firePropertyChange ("length", new Double (oldLength), new Double (length));
  }
  
  public void show() {
    for (int k=0; k<3; k++) getRenderer().AddActor(axeTitleActor[k]);
    getRenderer().AddActor(actor);
  }
  
  public void hide() {
    for (int k=0; k<3; k++) getRenderer().RemoveActor(axeTitleActor[k]);
    getRenderer().RemoveActor(actor);
  }

  public void setVisible(boolean visible) {
    if (visible != isVisible()) {
      if (visible) show();
      else hide();
      super.setVisible(visible);
    }
  }

}