All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.mines.jtk.mosaic.TensorsView Maven / Gradle / Ivy

There is a newer version: 1.1.0
Show newest version
/****************************************************************************
Copyright 2010, Colorado School of Mines and others.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
****************************************************************************/
package edu.mines.jtk.mosaic;

import java.awt.*;

import edu.mines.jtk.dsp.EigenTensors2;
import edu.mines.jtk.dsp.Sampling;
import static edu.mines.jtk.util.ArrayMath.*;

/**
 * A view of a 2D metric tensor field. A metric tensor corresponds to a 
 * symmetric positive-definite 2x2 matrix, and is displayed as an ellipse.
 * Ellipses are drawn for only a uniformly sampled subset of the tensors.
 *
 * @author Dave Hale, Colorado School of Mines
 * @version 2010.08.28
 */
public class TensorsView extends TiledView {

  /**
   * Orientation of sample axes x1 and x2. For example, the default 
   * orientation X1RIGHT_X2UP corresponds to x1 increasing horizontally 
   * from left to right, and x2 increasing vertically from bottom to top.
   */
  public enum Orientation {
    X1RIGHT_X2UP,
    X1DOWN_X2RIGHT
  }

  /**
   * Constructs a view of the specified tensors.
   * @param et the tensors.
   */
  public TensorsView(EigenTensors2 et) {
    this(new Sampling(et.getN1(),1.0,0.0),
         new Sampling(et.getN2(),1.0,0.0),
         et);
  }

  /**
   * Constructs a view of the specified tensors.
   * @param s1 sampling of 1st dimension.
   * @param s2 sampling of 2nd dimension.
   * @param et the tensors.
   */
  public TensorsView(Sampling s1, Sampling s2, EigenTensors2 et) {
    _s1 = s1;
    _s2 = s2;
    updateBestProjectors();
    set(et);
  }

  /**
   * Sets the tensors for this view.
   * @param et the tensors.
   */
  public void set(EigenTensors2 et) {
    _et = et;
    updateTensorEllipses();
  }

  /**
   * Sets the orientation of (x1,x2) axes.
   * @param orientation the orientation.
   */
  public void setOrientation(Orientation orientation) {
    if (_orientation!=orientation) {
      _orientation = orientation;
      updateBestProjectors();
      repaint();
    }
  }

  /**
   * Gets the orientation of (x1,x2) axes.
   * @return the orientation.
   */
  public Orientation getOrientation() {
    return _orientation;
  }

  /**
   * Sets the number of ellipses displayed along the larger dimension.
   * Ellipses are displayed for only a subset of the sampled tensors.
   * The specified number of ellipses roughly equals the number that 
   * will be displayed along the axis with the largest number of tensors.
   * 

* The sizes of the ellipses are chosen so that they never overlap. * Therefore, this parameter indirectly determines the size of the * the ellipses drawn. One can display either a large number of small * ellipses or a smaller number of larger ellipses. *

* The default number is 20. *

* Calling this method overrides any ellipse samplings specified * previously by calling the method * {@link #setEllipsesDisplayed(Sampling,Sampling)}. * @param ne the number of ellipses displayed along the larger dimension. */ public void setEllipsesDisplayed(int ne) { _ne = ne; updateTensorEllipses(); } /** * Sets the samplings of ellipses displayed. The specified ellipse * samplings are typically a subset of the samplings of the tensors * for this view. *

* Calling this method with non-null samplings overrides any number * of ellipses specified previously by calling the method * {@link #setEllipsesDisplayed(int)}. * @param e1 ellipse sampling in 1st dimension. * @param e2 ellipse sampling in 2nd dimension. */ public void setEllipsesDisplayed(Sampling e1, Sampling e2) { _e1 = e1; _e2 = e2; updateTensorEllipses(); } /** * Sets the scale factor for ellipse size. * @param scale the scale factor. */ public void setScale(double scale) { _scale = scale; updateTensorEllipses(); } /** * Sets the line width. * The default width is zero, for the thinnest lines. * @param width the line width. */ public void setLineWidth(float width) { if (_lineWidth!=width) { _lineWidth = width; updateBestProjectors(); repaint(); } } /** * Sets the line color. * The default line color is the tile foreground color. * That default is used if the specified line color is null. * @param color the line color; null, for tile foreground color. */ public void setLineColor(Color color) { if (!equalColors(_lineColor,color)) { _lineColor = color; repaint(); } } public void paint(Graphics2D g2d) { g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Projector hp = getHorizontalProjector(); Projector vp = getVerticalProjector(); Transcaler ts = getTranscaler(); ts = ts.combineWith(hp,vp); // Line width from graphics context. float lineWidth = 1.0f; Stroke stroke = g2d.getStroke(); if (stroke instanceof BasicStroke) { BasicStroke bs = (BasicStroke)stroke; lineWidth = bs.getLineWidth(); } // Graphics context for polygons. Graphics2D gpoly = (Graphics2D)g2d.create(); float width = lineWidth; if (_lineWidth!=0.0f) width *= _lineWidth; BasicStroke bs = new BasicStroke(width); gpoly.setStroke(bs); if (_lineColor!=null) gpoly.setColor(_lineColor); // Draw ellipses as polygons. int ne = _x1.length; int np = _x1[0].length; int[] xp = new int[np]; int[] yp = new int[np]; float[][] xv = null; float[][] yv = null; if (_orientation==Orientation.X1RIGHT_X2UP) { xv = _x1; yv = _x2; } else if (_orientation==Orientation.X1DOWN_X2RIGHT) { xv = _x2; yv = _x1; } for (int ie=0; ie0.0)?0.48*ratio/sqrt(emax):0.0; r *= _scale; // Ellipse (x1,x2) coordinates. _x1 = new float[nm][np]; _x2 = new float[nm][np]; float[] u = new float[2]; for (int i2=0,im=0; i2





© 2015 - 2024 Weber Informatics LLC | Privacy Policy