Package clips.dicom.model

Source Code of clips.dicom.model.ImageModel

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package clips.dicom.model;

import clips.dicom.Image.DICOMImage;
import clips.dicom.dicombaseclass.DICOMChekup;
import framework.utils.events.TypedChangeEvent;
import java.util.ArrayList;
import javax.swing.event.ChangeEvent;
import framework.utils.events.TypedChangeListener;

/**
*
* @author finder
*/
public class ImageModel extends DicomModel<ImageModel.Params> {
  private ArrayList<DICOMImage>    images = new ArrayList<DICOMImage>();

  static public enum Params{
    brigth,
    contrast,
    minmax,
    gamma,
    orentationChange,
    imageChange
  }

  @SuppressWarnings({"unchecked"})
  ImageModel(AgregatorItem imagesItem) {
    super(imagesItem);
    setImages(imagesItem.getItems());
  }


  public final void notifyListeners(Params notifyType) {
    ChangeEvent      evt = new TypedChangeEvent<Params>(this, notifyType);
    if (notifyType == null){
        notifyAllListeners(null, evt);
    }
    else {
      switch (notifyType) {
        case brigth:
          notifyTypeListeners(Params.brigth, evt);
          notifyTypeListeners(Params.minmax, evt);
          notifyTypeListeners(null, evt);
          break;
        case contrast:
          notifyTypeListeners(Params.contrast, evt);
          notifyTypeListeners(Params.minmax, evt);
          notifyTypeListeners(null, evt);
          break;
        case minmax:
          notifyTypeListeners(Params.minmax, evt);
          notifyTypeListeners(Params.brigth, evt);
          notifyTypeListeners(Params.contrast, evt);
          notifyTypeListeners(null, evt);
          break;
        case gamma:
          notifyTypeListeners(Params.gamma, evt);
          notifyTypeListeners(null, evt);
          break;
        case orentationChange:
          notifyTypeListeners(Params.orentationChange, evt);
          notifyTypeListeners(null, evt);
          break;
        case imageChange:
          notifyAllListeners(null, evt);
          break;
      }
    }
  }

  public void autoWindow(int curImageID, double beginPocent, double endProcent) {
    DICOMImage    img = getImage(curImageID);
    if (img == null){
      return;
    }
    img.autoWindow(beginPocent, endProcent);
    setMinMax(curImageID, img.getMin(), img.getMax());
  }

  public ArrayList<DICOMImage> getImages() {
    return new ArrayList<DICOMImage>(images);
  }
 
  public int getImageCount(){
    if (images != null){
      return images.size();
    }
    else {
      return 0;
    }
  }
 
  public DICOMImage getImage(int curImageID) {
    if (images != null){
      if (curImageID >= 0 && curImageID < images.size()){
        return images.get(curImageID);
      }
    }
    return null;
  }     
 
  /*public DICOMImage getCurImage() {
    if (images != null){
      if (curImageID >= 0 && curImageID < images.size()){
        return images.get(curImageID);
      }
      else if (images.size() > 0) {
        return images.get(0);
      }
    }
    return null;
  }
 
  public boolean isHaveCurImage(){
    return getCurImage() != null;
  }

  public int getCurImageID() {
    return curImageID;
  }

  public void setCurImageID(int curImageID) {
    this.curImageID = Math.max(Math.min(curImageID, getImageCount() - 1), 0);
    notifyListeners(Params.imageChange); 
  }*/

  public boolean isValidImage(int curImageID){
    return getImage(curImageID) != null;
  }
 
  public void setMinMax(int curImageID, double min, double max) {
    for (DICOMImage image : images) {
      image.setMinMax(min, max);
    }
    notifyListeners(Params.minmax)
  }

  public void setGamma(int curImageID, double gamma) {
    for (DICOMImage image : images) {
      image.setGamma(gamma);
    }
    notifyListeners(Params.gamma)
  }

  public void setContrast(int curImageID, double contrast) {
    for (DICOMImage image : images) {
      image.setContrast(contrast);
    }
    notifyListeners(Params.contrast)
  }

  public void setBright(int curImageID, double bright) {
    for (DICOMImage image : images) {
      image.setBright(bright);
    }
    notifyListeners(Params.brigth)
  }

  public double getMin(int curImageID) {
    if (isValidImage(curImageID)) {
      return getImage(curImageID).getMin();
    }
    else{
      return 0;
    }
  }

  public double getMax(int curImageID) {
    if (isValidImage(curImageID)) {
      return getImage(curImageID).getMax();
    }
    else{
      return 65535;
    }
  }

  public double getGamma(int curImageID) {
    if (isValidImage(curImageID)) {
      return getImage(curImageID).getGamma();
    }
    else{
      return 1;
    }
  }

  public double getContrast(int curImageID) {
    if (isValidImage(curImageID)) {
      return getImage(curImageID).getContrast();
    }
    else{
      return 0;
    }
  }

  public double getBright(int curImageID) {
    if (isValidImage(curImageID)) {
      return getImage(curImageID).getBright();
    }
    else{
      return 0;
    }
  }
 
 

  /*@SuppressWarnings("unchecked")
  public void setImagesItem(AgregatorItem newImagesItem) {
    if (newImagesItem != imagesItem){
      if (imagesItem != null) {
        imagesItem.removeListener(this);
      }
      if (newImagesItem != null) {
        newImagesItem.addListener(this);
      }
      imagesItem = newImagesItem;
      curImageID = 0;
      setImages((ArrayList<DICOMImage>)(ArrayList)imagesItem.getItems());
    }
  }
 
  @SuppressWarnings("unchecked")
  public final void itemStateChanged(ItemEvent e) {
    setImages((ArrayList<DICOMImage>)(ArrayList)imagesItem.getItems());
  }*/


  @SuppressWarnings("unchecked")
  final void setImages(ArrayList<? extends DICOMChekup> newImages) {
    images = (ArrayList<DICOMImage>) newImages;

    if (images == null){
      images = new ArrayList<DICOMImage>();
    }
    notifyListeners(Params.imageChange);
  }
 
  public long getOrentationID(int curImageID) {
    if (isValidImage(curImageID)) {
      return getImage(curImageID).getOrentationID();
    }
    else{
      return 0;
    }
  }

  public void setOrentationID(int curImageID, long orentationID) {
    if (isValidImage(curImageID)) {
       getImage(curImageID).setOrentationID(orentationID);
    }
    notifyListeners(Params.orentationChange);
  }

}
TOP

Related Classes of clips.dicom.model.ImageModel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.