From 924ba1aa028403b2e80bdf1df36628497638fe47 Mon Sep 17 00:00:00 2001 From: RainerHeintzmann Date: Fri, 29 Nov 2024 10:27:25 +0100 Subject: [PATCH] User colormaps with divergent tag fully supported --- javacAll | 7 +- src/main/java/view5d/Bundle.java | 332 ++++++++++++---------- src/main/java/view5d/ImageCanvas.java | 22 +- src/main/java/view5d/My3DData.java | 199 ++++++++----- src/main/java/view5d/MyMenuProcessor.java | 18 +- src/main/java/view5d/View5D.java | 6 +- src/main/java/view5d/View5D_.java | 2 +- 7 files changed, 330 insertions(+), 256 deletions(-) diff --git a/javacAll b/javacAll index 777f1fb..dc6370b 100644 --- a/javacAll +++ b/javacAll @@ -19,8 +19,10 @@ cp "$myjar" "/mnt/c/Users/pi96doc/.julia/artifacts/View5D.jar" cp "$myjar" "/mnt/c/NoBackup/DeconvCompileTest/DIPlib_3_2019/share/DIPimage/private/View5D.jar" cp "$myjar" "/mnt/c/NoBackup/DeconvCompileTest/DIPlib_3_2017/share/DIPimage/private/View5D.jar" cp "$myjar" "/mnt/c/Users/pi96doc/Desktop/UserPrograms/fiji-win64/Fiji.app/plugins/" -tar -czf "${myjar%.jar}-jar.tar.gz" "$myjar" -echo "${myjar%.jar}.jar.tar.gz" +cd target +totar=$(find -name '*.jar' | grep -v sources | grep -v javadoc) +tar -czf "${totar%.jar}-jar.tar.gz" "$totar" +echo "${totar%.jar}.jar.tar.gz" # cp /*.class /usr/local/ImageJ/plugins/View5D/ #cp View5D_.jar /usr/local/ImageJ/plugins/View5D/ # cp View5D_.jar /windows/C/DriveF/JavaProgs/ImageJ/plugins/View5D/ @@ -43,3 +45,4 @@ echo "${myjar%.jar}.jar.tar.gz" # cp -r examples /net/mobi1/data1/WinApps/ImageJ/plugins/View5D/ # cp *.class /net/mobi1/data1/MacOSX_local/ImageJ/plugins/View5D/ + diff --git a/src/main/java/view5d/Bundle.java b/src/main/java/view5d/Bundle.java index 0bf0924..bbb2d45 100644 --- a/src/main/java/view5d/Bundle.java +++ b/src/main/java/view5d/Bundle.java @@ -58,10 +58,13 @@ public class Bundle extends Object implements Cloneable { // this class bundles public int ElementModelNr=0; // just a number for the current model final static int ElementModels=15; // Nr of element models final static String ElementModelName[]={"GrayScale","Red","Green","Blue","Purple","Glow Red","Glow Green-Blue","Glow Green-Yellow","Glow Blue","Glow Purple","Rainbow","Random","Cyclic","RdBu", "RdBu_r"}; // Nr of element models + final static int ElementModelType[]={0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}; // 0=linear, 1=diverging byte cmapRed[],cmapGreen[],cmapBlue[]; static Vector MapSizes = new Vector(); + static Vector MapTypes = new Vector(); static Vector RedMaps = new Vector(),GreenMaps = new Vector(),BlueMaps = new Vector(); // For user-supplied colormaps boolean cmapIsInverse=false; + boolean cmapIsDivergent=false; IndexColorModel ElementModel; boolean ShowOvUn=false; boolean LogScale=false; @@ -107,6 +110,8 @@ public class Bundle extends Object implements Cloneable { // this class bundles void SetMincs(double val) { mincs=val;}; void SetMaxcs(double val) { maxcs=val;}; + boolean IsDivergentColormap() {return cmapIsDivergent;} // ElementModelType[ElementModelNr] == 1; + void ToggleROI() { if (ActiveROI == rectROI) ActiveROI = polyROI; @@ -172,11 +177,11 @@ public static double MClip(double c) { // mirror clip 1 .. 2 -> 1 .. 0 public Color GetCMapColor(int pos,int mysize) { int cpos = (pos*(cmapcHigh-cmapcLow))/mysize + cmapcLow; - if (cpos >= MaxCTable) cpos = MaxCTable-1; - if (cpos < 0) cpos = 0; - int red = cmapRed[cpos] & 0xff; - int green = cmapGreen[cpos]& 0xff; - int blue = cmapBlue[cpos]& 0xff; + if (cpos >= MaxCTable) cpos = MaxCTable-1; + if (cpos < 0) cpos = 0; + int red = cmapRed[cpos] & 0xff; + int green = cmapGreen[cpos]& 0xff; + int blue = cmapBlue[cpos]& 0xff; return new Color(red,green,blue); } @@ -191,8 +196,14 @@ public void CompCMap() { // computes the color map of this element double LogGain = (double) MaxCTable; double LogCalib = java.lang.Math.log(LogGain+1.0); Random myrnd= new Random(0); - - for (int i=0;i= 0) + cmapIsDivergent = (MapTypes.elementAt(elem) == 1); + else + cmapIsDivergent = ElementModelType[ElementModelNr] == 1; + + for (int i=0;i= 1/3.0 && tmp < 2/3.0) - { - cmapRed[i]=(byte) 0; - cmapGreen[i]=(byte) (255*MClip(1-(tmp-1/3.0)*3)); - cmapBlue[i]=(byte) (255*MClip((tmp-1/3.0)*3)); - } - if (tmp>= 2/3.0) - { - cmapRed[i]=(byte) (255*MClip((tmp-2/3.0)*3)); - cmapGreen[i]=(byte) 0; - cmapBlue[i]=(byte) (255*MClip(1-(tmp-2/3.0)*3)); - } - if (i==0) - { - cmapRed[i]=(byte) (0); - cmapGreen[i]=(byte) (0); - cmapBlue[i]=(byte) (0); - } - break; - case 13: // RdBu - if (tmp < 1/2.0) - { // high reference (103, 0, 5) - double lb = MClip(1-tmp*2); - cmapRed[i]=(byte) (255-152*lb); - cmapGreen[i]=(byte) (255-255*lb); - // cmapBlue[i]=(byte) (255-224*lb); - cmapBlue[i]=(byte) (255-250*lb); - } - else - { // low reference (5, 48, 97) - double rb = MClip(tmp*2-1); - cmapRed[i]=(byte) (255-250*rb); - cmapGreen[i]=(byte) (255-207*rb); - cmapBlue[i]=(byte) (255-158*rb); - } - break; - case 14: // RdBu_r - if (tmp < 1/2.0) - { // low reference (5, 48, 97) - double lb = MClip(1-tmp*2); - cmapRed[i]=(byte) (255-250*lb); - cmapGreen[i]=(byte) (255-207*lb); - cmapBlue[i]=(byte) (255-158*lb); - } - else - { // high reference (103, 0, 5) - double rb = MClip(tmp*2-1); - cmapRed[i]=(byte) (255-152*rb); - cmapGreen[i]=(byte) (255-255*rb); - cmapBlue[i]=(byte) (255-250*rb); - } - break; - default: // a user supplied colormap - int elem=ElementModelNr-ElementModels; - int MapSize=MapSizes.elementAt(elem).intValue(); - //int MapSize=((byte []) RedMaps.elementAt(elem)).length; - int index=(int) ((MapSize-1)*tmp); - cmapRed[i]=RedMaps.elementAt(elem)[index]; - cmapGreen[i]=GreenMaps.elementAt(elem)[index]; - cmapBlue[i]=BlueMaps.elementAt(elem)[index]; - } + case 1: // Red + cmapRed[i]=(byte) (tmp * 255); + cmapGreen[i]=0; + cmapBlue[i]=0; + break; + case 2: // Green + cmapRed[i]=0; + cmapGreen[i]=(byte) (tmp * 255); + cmapBlue[i]=0; + break; + case 3: // Blue + cmapRed[i]=0; + cmapGreen[i]=0; + cmapBlue[i]=(byte) (tmp * 255); + break; + case 4: // Violet + cmapRed[i]=(byte) (tmp * 255); + cmapGreen[i]=0; + cmapBlue[i]=(byte) (tmp * 255); + break; + case 5: // Nonlin GlowRed + cmapRed[i]=(byte) (255*CClip(tmp*3.0)); + cmapGreen[i]=(byte) (255*CClip(tmp*3.0-1.0)); + cmapBlue[i]=(byte) (255*CClip(tmp*3.0-2.0)); + break; + case 6: // Nonlin GlowGreen + cmapRed[i]=(byte) (255.0*CClip(tmp*3.0-2.0)); + cmapGreen[i]=(byte) (255.0*CClip(tmp*3.0)); + cmapBlue[i]=(byte) (255.0*CClip(tmp*3.0-1.0)); + break; + case 7: // Nonlin glow Green-Yellow + cmapRed[i]=(byte) (255*CClip(tmp*3.0-1.0)); + cmapGreen[i]=(byte) (255*CClip(tmp*3.0)); + cmapBlue[i]=(byte) (255*CClip(tmp*3.0-2.0)); + break; + case 8: // Nonlin glow Blue + cmapBlue[i]=(byte) (255*CClip(tmp*3.0)); + cmapGreen[i]=(byte) (255*CClip(tmp*3.0-1.0)); + cmapRed[i]=(byte) (255*CClip(tmp*3.0-2.0)); + break; + case 9: // Nonlin glow Violet + cmapRed[i]=(byte) (255*CClip(tmp*2.0)); + cmapGreen[i]=(byte) (255*CClip(tmp*2.0-1.0)); + cmapBlue[i]=(byte) (255*CClip(tmp*2.0)); + break; + case 10: // Rainbow + cmapRed[i]=(byte) (255*MClip(tmp*1.5+1.0)); + cmapGreen[i]=(byte) (255*MClip(tmp*1.5+0.25)); + cmapBlue[i]=(byte) (255*MClip(tmp*1.5-0.5)); + if (i==0) + { + cmapRed[i]=(byte) (0); + cmapGreen[i]=(byte) (0); + cmapBlue[i]=(byte) (0); + } + break; + case 11: // Cyclic Colors + if (i==0) + { + cmapRed[i]=(byte) (0); + cmapGreen[i]=(byte) (0); + cmapBlue[i]=(byte) (0); + } + else + { + cmapRed[i]=(byte) (255.0 * myrnd.nextDouble()); + cmapGreen[i]=(byte) (255.0 * myrnd.nextDouble()); + cmapBlue[i]=(byte) (255.0 * myrnd.nextDouble()); + } + break; + case 12: // Random Colors + if (tmp < 1/3.0) + { + cmapRed[i]=(byte) (255*MClip(1-tmp*3)); + cmapGreen[i]=(byte) (255*MClip(tmp*3)); + cmapBlue[i]=(byte) 0; + } + if (tmp>= 1/3.0 && tmp < 2/3.0) + { + cmapRed[i]=(byte) 0; + cmapGreen[i]=(byte) (255*MClip(1-(tmp-1/3.0)*3)); + cmapBlue[i]=(byte) (255*MClip((tmp-1/3.0)*3)); + } + if (tmp>= 2/3.0) + { + cmapRed[i]=(byte) (255*MClip((tmp-2/3.0)*3)); + cmapGreen[i]=(byte) 0; + cmapBlue[i]=(byte) (255*MClip(1-(tmp-2/3.0)*3)); + } + if (i==0) + { + cmapRed[i]=(byte) (0); + cmapGreen[i]=(byte) (0); + cmapBlue[i]=(byte) (0); + } + break; + case 13: // RdBu + if (tmp < 1/2.0) + { // high reference (103, 0, 5) + double lb = MClip(1-tmp*2); + cmapRed[i]=(byte) (255-152*lb); + cmapGreen[i]=(byte) (255-255*lb); + // cmapBlue[i]=(byte) (255-224*lb); + cmapBlue[i]=(byte) (255-250*lb); + } + else + { // low reference (5, 48, 97) + double rb = MClip(tmp*2-1); + cmapRed[i]=(byte) (255-250*rb); + cmapGreen[i]=(byte) (255-207*rb); + cmapBlue[i]=(byte) (255-158*rb); + } + break; + case 14: // RdBu_r + if (tmp < 1/2.0) + { // low reference (5, 48, 97) + double lb = MClip(1-tmp*2); + cmapRed[i]=(byte) (255-250*lb); + cmapGreen[i]=(byte) (255-207*lb); + cmapBlue[i]=(byte) (255-158*lb); + } + else + { // high reference (103, 0, 5) + double rb = MClip(tmp*2-1); + cmapRed[i]=(byte) (255-152*rb); + cmapGreen[i]=(byte) (255-255*rb); + cmapBlue[i]=(byte) (255-250*rb); + } + break; + default: // a user supplied colormap + // int elem=ElementModelNr-ElementModels; + int MapSize=MapSizes.elementAt(elem).intValue(); + //int MapSize=((byte []) RedMaps.elementAt(elem)).length; + int index=(int) ((MapSize-1)*tmp); + cmapRed[i]=RedMaps.elementAt(elem)[index]; + cmapGreen[i]=GreenMaps.elementAt(elem)[index]; + cmapBlue[i]=BlueMaps.elementAt(elem)[index]; + } if (cmapIsInverse) { cmapRed[i] = (byte) (255-cmapRed[i]); @@ -390,22 +409,29 @@ public void GenCMap() { CompCMap(); } - public static int AddLookUpTable(int TableSize, byte reds[], byte greens[], byte blues[]) + public static int AddLookUpTable(int TableSize, byte reds[], byte greens[], byte blues[], int type) { MapSizes.addElement(Integer.valueOf(TableSize)); RedMaps.addElement(reds); GreenMaps.addElement(greens); BlueMaps.addElement(blues); + MapTypes.addElement(Integer.valueOf(type)); return MapSizes.size()-1; // returns the index of the last user-model } public void ToggleModel(int actModel) { // int oldmodel = ElementModelNr; - if (actModel < 0) + if (actModel == -1) ElementModelNr = ElementModelNr+1; - else ElementModelNr = actModel; + else if (actModel < -1) + ElementModelNr = ElementModelNr-1; + else ElementModelNr = actModel; - if (ElementModelNr >= ElementModels+MapSizes.size()) ElementModelNr=0; + if (ElementModelNr < 0) + ElementModelNr = ElementModels+MapSizes.size()-1; + if (ElementModelNr >= ElementModels+MapSizes.size()) + ElementModelNr = 0; + // if (oldmodel != ElementModelNr) // since a colormap can be inv CompCMap(); } diff --git a/src/main/java/view5d/ImageCanvas.java b/src/main/java/view5d/ImageCanvas.java index da84f5f..fe8ea81 100644 --- a/src/main/java/view5d/ImageCanvas.java +++ b/src/main/java/view5d/ImageCanvas.java @@ -1999,26 +1999,26 @@ else if ((my3ddata.Times > 1)) //my3ddata.MyHistogram.UpdateAll(); return; case 'C': - my3ddata.ToggleColor(); - UpdateAll(); + my3ddata.ToggleColor(); + UpdateAll(); return ; case 'c': - my3ddata.ToggleModel(-1); - UpdateAll(); + my3ddata.ToggleModel(-1); + UpdateAll(); return ; case 'd': - my3ddata.InvertCMap(); - my3ddata.ToggleModel(-1); - my3ddata.InvertCMap(); + // my3ddata.InvertCMap(); + my3ddata.ToggleModel(-2); + // my3ddata.InvertCMap(); UpdateAll(); return ; case 'o': // in color mode, all will be set to the current state - my3ddata.ToggleOvUn(-1); - UpdateAll(); + my3ddata.ToggleOvUn(-1); + UpdateAll(); return ; case 'O': - my3ddata.ToggleLog(-1); - UpdateAll(); + my3ddata.ToggleLog(-1); + UpdateAll(); return ; case ',': // moves along time direction myPanel.RememberOffset(); diff --git a/src/main/java/view5d/My3DData.java b/src/main/java/view5d/My3DData.java index e5fe254..8e03f42 100644 --- a/src/main/java/view5d/My3DData.java +++ b/src/main/java/view5d/My3DData.java @@ -288,10 +288,10 @@ APoint MarkerFromPosition(double px, double py, int dir, double dx, double dy) return Pt; } - public int AddLookUpTable(int MapSize,byte Reds[],byte Greens[],byte Blues[]) + public int AddLookUpTable(int MapSize,byte Reds[],byte Greens[],byte Blues[], int type) { int lastLUT=0; - lastLUT=Bundle.ElementModels+Bundle.AddLookUpTable(MapSize,Reds,Greens,Blues); + lastLUT=Bundle.ElementModels+Bundle.AddLookUpTable(MapSize,Reds,Greens,Blues,type); SetColorModelNr (ActiveElement,lastLUT); GetBundleAt(ActiveElement).CompCMap(); return lastLUT; // returns the last existing total LUT index @@ -988,30 +988,32 @@ public void ToggleOvUn(int newVal) { copyLinkedProperties(ActiveElement); } - public void ToggleModel(int elem,int newModel ) { - GetBundleAt(elem).ToggleModel(newModel); - if (elem == ActiveElement) - { - IndexColorModel mymodel = GetBundleAt(elem).ElementModel; - MySlice[0].TakeModel(mymodel); - MySlice[1].TakeModel(mymodel); - MySlice[2].TakeModel(mymodel); - } - if (GetBundleAt(elem).DispOverlay) // This element is displayed in the overlay - { - InvalidateColor(); - } - if (elementsLinked) - copyLinkedProperties(elem); + public void ToggleModel(int elem, int newModel ) { + Bundle myBundle = GetBundleAt(elem); + myBundle.ToggleModel(newModel); + if (elem == ActiveElement) + { + IndexColorModel mymodel = myBundle.ElementModel; + MySlice[0].TakeModel(mymodel); + MySlice[1].TakeModel(mymodel); + MySlice[2].TakeModel(mymodel); + } + if (myBundle.DispOverlay) // This element is displayed in the overlay + { + InvalidateColor(); + } + if (elementsLinked) + copyLinkedProperties(elem); } public void ToggleModel(int newModel ) { - ToggleModel(ActiveElement,newModel); + ToggleModel(ActiveElement, newModel); } - public void InvertCMap() + public void SetInvertCMap(boolean inverse) { - GetBundleAt(ActiveElement).cmapIsInverse = ! GetBundleAt(ActiveElement).cmapIsInverse; + GetBundleAt(ActiveElement).cmapIsInverse = inverse; + // ! GetBundleAt(ActiveElement).cmapIsInverse; } /*private void Setmincs(int elem, double val) { GetBundleAt(elem).SetMincs(val); @@ -1049,6 +1051,7 @@ public double GetScaledRange(int elem) { //return ElementAt(elem).ScaleV*(Getmaxcs(elem)-Getmincs(elem)); } + // transfers the threshold values to all time steps as a scale and shift public void transferThresh(int elem) { for (int t=0;t < Times;t++) { ElementAt(elem, t).SetScaleShift(Getmincs(elem), Getmaxcs(elem)); @@ -1081,11 +1084,19 @@ public boolean SetScaledMinMaxcs(int elem, double Min, double Max) { public boolean AdjustThresh(int elementNum) { boolean valid=true; - GetBundleAt(elementNum).cmapcHigh = Bundle.MaxCTable-1; // set the color map thresholds back to normal - GetBundleAt(elementNum).cmapcLow = 0; - GetBundleAt(elementNum).CompCMap(); + Bundle myBundle = GetBundleAt(elementNum); + myBundle.cmapcHigh = Bundle.MaxCTable-1; // set the color map thresholds back to normal + myBundle.cmapcLow = 0; + //System.out.println("is-inv"+myBundle.cmapIsInverse+"\n"); + myBundle.CompCMap(); + //System.out.println("is-inv"+myBundle.cmapIsInverse+"\n"); double min = ElementAt(elementNum).ROIMinimum(ROIAt(elementNum)); double max = ElementAt(elementNum).ROIMaximum(ROIAt(elementNum)); + if (myBundle.IsDivergentColormap()) { + max = Math.max(Math.abs(min), Math.abs(max)); + min = -max; + // System.out.println("min"+min+" max"+max+"\n"); + } valid = SetThresh(elementNum,min,max); transferThresh(elementNum); return valid; @@ -1155,24 +1166,26 @@ public boolean AdjustThreshGlobal() { // adjusts the threshold globally for al } public void copyLinkedProperties(int anElement) { // copies a particular element threshold values to all element - double TLow = GetBundleAt(anElement).GetMincs(); - double THigh = GetBundleAt(anElement).GetMaxcs(); - boolean ShowOvUn = GetBundleAt(anElement).ShowOvUn; - boolean LogScale = GetBundleAt(anElement).LogScale; - boolean cmapIsInverse = GetBundleAt(anElement).cmapIsInverse; - int ElementModelNr = GetBundleAt(anElement).ElementModelNr; // just a number for the current model - double Gamma = GetBundleAt(anElement).Gamma; + Bundle myBundle = GetBundleAt(anElement); + double TLow = myBundle.GetMincs(); + double THigh = myBundle.GetMaxcs(); + boolean ShowOvUn = myBundle.ShowOvUn; + boolean LogScale = myBundle.LogScale; + boolean cmapIsInverse = myBundle.cmapIsInverse; + int ElementModelNr = myBundle.ElementModelNr; // just a number for the current model + double Gamma = myBundle.Gamma; for (int elementNum=0;elementNum 0) - GetBundleAt(elementNum).CompCMap(); // This is usually faster than recomputing images + myBundle = GetBundleAt(elementNum); + myBundle.SetMincs(TLow); + myBundle.SetMaxcs(THigh); + myBundle.ShowOvUn = ShowOvUn; + myBundle.LogScale = LogScale; + myBundle.cmapIsInverse = cmapIsInverse; + myBundle.ElementModelNr = ElementModelNr; + myBundle.Gamma = Gamma; + if (myBundle.cmapcLow > 0) + myBundle.CompCMap(); // This is usually faster than recomputing images else CThreshToValThresh(elementNum,0.25,1.0); // If underflow a recomputation becomes necessary, but with 25% extra space } @@ -1180,10 +1193,11 @@ public void copyLinkedProperties(int anElement) { // copies a particular element public void setColorMapThresh(int elem, int low, int high) // These functions are far quicker for the display especially for large images { - GetBundleAt(elem).cmapcLow = low; - GetBundleAt(elem).cmapcHigh = high; + Bundle myBundle = GetBundleAt(elem); + myBundle.cmapcLow = low; + myBundle.cmapcHigh = high; - GetBundleAt(elem).CompCMap(); // This is usually faster than recomputing images + myBundle.CompCMap(); // This is usually faster than recomputing images // if (GetBundleAt(elem).cmapcLow > 0) // GetBundleAt(elem).CompCMap(); // This is usually faster than recomputing images // else @@ -1199,37 +1213,61 @@ public void setColorMapThresh(int elem, int low, int high) // These functions a public void adjustColorMapLThresh(double howmuch) // These functions are far quicker for the display especially for large images { double howmany= (howmuch*Bundle.MaxCTable); - double max = GetBundleAt(ActiveElement).cmapcHigh; - double min = GetBundleAt(ActiveElement).cmapcLow; + Bundle myBundle = GetBundleAt(ActiveElement); + double max = myBundle.cmapcHigh; + double min = myBundle.cmapcLow; if (howmany < 0 || max > min + howmany) - GetBundleAt(ActiveElement).cmapcLow += (int) howmany; + myBundle.cmapcLow += (int) howmany; + if (myBundle.IsDivergentColormap()) { + if (myBundle.cmapcLow > Bundle.MaxCTable/2) + myBundle.cmapcLow = Bundle.MaxCTable/2; + if (howmany > 0 || max - howmany > min) + myBundle.cmapcHigh -= (int) howmany; + if (myBundle.cmapcHigh < Bundle.MaxCTable/2) + myBundle.cmapcHigh = Bundle.MaxCTable/2; + } - if (GetBundleAt(ActiveElement).cmapcLow > 0) - GetBundleAt(ActiveElement).CompCMap(); // This is usually faster than recomputing images + if (myBundle.cmapcLow > 0) + myBundle.CompCMap(); // This is usually faster than recomputing images else - CThreshToValThresh(ActiveElement,0.25,1.0); // If underflow a recomputation becomes necessary, but with 25% extra space + if (myBundle.IsDivergentColormap()) + CThreshToValThresh(ActiveElement,0.25,0.75); // If underflow a recomputation becomes necessary, but with 25% extra space + else + CThreshToValThresh(ActiveElement,0.25,1.0); // If underflow a recomputation becomes necessary, but with 25% extra space } public void adjustColorMapUThresh(double howmuch) { double howmany= (howmuch*Bundle.MaxCTable); - double max = GetBundleAt(ActiveElement).cmapcHigh; - double min = GetBundleAt(ActiveElement).cmapcLow; + Bundle myBundle = GetBundleAt(ActiveElement); + double max = myBundle.cmapcHigh; + double min = myBundle.cmapcLow; if (howmany > 0 || max + howmany > min) - GetBundleAt(ActiveElement).cmapcHigh += (int) howmany; - - if (GetBundleAt(ActiveElement).cmapcHigh <= Bundle.MaxCTable-1) - GetBundleAt(ActiveElement).CompCMap(); // This is usually faster than recomputing images + myBundle.cmapcHigh += (int) howmany; + if (myBundle.IsDivergentColormap()) { + if (myBundle.cmapcHigh < Bundle.MaxCTable/2) + myBundle.cmapcHigh = Bundle.MaxCTable/2; + if (howmany > 0 || max > min - howmany) + myBundle.cmapcLow -= (int) howmany; + if (myBundle.cmapcLow > Bundle.MaxCTable/2) + myBundle.cmapcLow = Bundle.MaxCTable/2; + } + if (myBundle.cmapcHigh <= Bundle.MaxCTable-1) + myBundle.CompCMap(); // This is usually faster than recomputing images + else + if (myBundle.IsDivergentColormap()) + CThreshToValThresh(ActiveElement,0.25,0.75); // If underflow a recomputation becomes necessary, but with 25% extra space else CThreshToValThresh(ActiveElement,0.0,0.75); // If underflow a recomputation becomes necessary, but with 25% extra space } public double GetMinThresh(int elem) // returns the Effective threshold independent of which part of it is colormap and which is Mincs { - double max = GetBundleAt(elem).GetMaxcs(); // These are the datavalues to which the min and max of the colormap point - double min = GetBundleAt(elem).GetMincs(); + Bundle myBundle = GetBundleAt(elem); + double max = myBundle.GetMaxcs(); // These are the datavalues to which the min and max of the colormap point + double min = myBundle.GetMincs(); // double cmax = GetBundleAt(elem).cmapcHigh; // These are the current indices into the colormap - double cmin = GetBundleAt(elem).cmapcLow; // index of the lowest currently used entry in the colortable + double cmin = myBundle.cmapcLow; // index of the lowest currently used entry in the colortable // double scale = (max-min) / Bundle.MaxCTable; double nmin = min + (max-min)*cmin / (Bundle.MaxCTable-1); // scale*cmin; @@ -1238,9 +1276,10 @@ public double GetMinThresh(int elem) // returns the Effective threshold indepe public double GetMaxThresh(int elem) // returns the Effective threshold independent of which part of it is colormap and which is Mincs { - double max = GetBundleAt(elem).GetMaxcs(); // These are the datavalues to which the min and max of the colormap point - double min = GetBundleAt(elem).GetMincs(); - double cmax = GetBundleAt(elem).cmapcHigh; // index of the highest currently used entry in the colortable + Bundle myBundle = GetBundleAt(elem); + double max = myBundle.GetMaxcs(); // These are the datavalues to which the min and max of the colormap point + double min = myBundle.GetMincs(); + double cmax = myBundle.cmapcHigh; // index of the highest currently used entry in the colortable // double cmin = GetBundleAt(elem).cmapcLow; double nmax = min + (max-min)*cmax/(Bundle.MaxCTable-1); @@ -1248,13 +1287,15 @@ public double GetMaxThresh(int elem) // returns the Effective threshold indepe } - public void CThreshToValThresh(int elem, double facmin, double facmax) // copies the color-map threshold to a real value threshold + // copies the color-map threshold to a real value threshold + public void CThreshToValThresh(int elem, double facmin, double facmax) { // The factor determines the percentage at of the colormap at which the new min/max position will point (defaults = 0,1.0) + Bundle myBundle = GetBundleAt(elem); if (elem < 0) elem=ActiveElement; - double max = GetBundleAt(elem).GetMaxcs(); // These are the datavalues to which the min and max of the colormap point - double min = GetBundleAt(elem).GetMincs(); - double cmax = GetBundleAt(elem).cmapcHigh; // These are the current indices into the colormap - double cmin = GetBundleAt(elem).cmapcLow; + double max = myBundle.GetMaxcs(); // These are the datavalues to which the min and max of the colormap point + double min = myBundle.GetMincs(); + double cmax = myBundle.cmapcHigh; // These are the current indices into the colormap + double cmin = myBundle.cmapcLow; // if (cmin == 0 && cmax == Bundle.MaxCTable-1) return; // No need to change anything! double cmaxnew = (int) ((Bundle.MaxCTable-1)*facmax); // new indices into colormap @@ -1265,34 +1306,36 @@ public void CThreshToValThresh(int elem, double facmin, double facmax) // copi double nmax = max - scale*(Bundle.MaxCTable - (cmax+scale2*(Bundle.MaxCTable-1-cmaxnew))); double nmin = min + scale*(cmin - scale2*cminnew); - GetBundleAt(elem).SetMincs(nmin); - GetBundleAt(elem).SetMaxcs(nmax); - GetBundleAt(elem).cmapcLow = (int) cminnew; - GetBundleAt(elem).cmapcHigh = (int) cmaxnew; + myBundle.SetMincs(nmin); + myBundle.SetMaxcs(nmax); + myBundle.cmapcLow = (int) cminnew; + myBundle.cmapcHigh = (int) cmaxnew; InvalidateSlices();InvalidateProjs(elem); transferThresh(elem); - GetBundleAt(elem).CompCMap(); + myBundle.CompCMap(); } public void addLThresh(double howmuch) { - double howmany= (howmuch*ActElement().MaxValue); - double max = GetBundleAt(ActiveElement).GetMaxcs(); - double min = GetBundleAt(ActiveElement).GetMincs(); + Bundle myBundle = GetBundleAt(ActiveElement); + double howmany= (howmuch*ActElement().MaxValue); + double max = myBundle.GetMaxcs(); + double min = myBundle.GetMincs(); if (howmany < 0 || max > min + howmany) { - GetBundleAt(ActiveElement).SetMincs(min + howmany); + myBundle.SetMincs(min + howmany); InvalidateSlices();InvalidateProjs(ActiveElement); } transferThresh(ActiveElement); } public void addUThresh(double howmuch) { - double howmany=(howmuch*ActElement().MaxValue); - double max = GetBundleAt(ActiveElement).GetMaxcs(); - double min = GetBundleAt(ActiveElement).GetMincs(); + Bundle myBundle = GetBundleAt(ActiveElement); + double howmany=(howmuch*ActElement().MaxValue); + double max = myBundle.GetMaxcs(); + double min = myBundle.GetMincs(); if (howmany > 0 || max + howmany > min) { - GetBundleAt(ActiveElement).SetMaxcs(max + howmany); + myBundle.SetMaxcs(max + howmany); InvalidateSlices();InvalidateProjs(ActiveElement); } transferThresh(ActiveElement); diff --git a/src/main/java/view5d/MyMenuProcessor.java b/src/main/java/view5d/MyMenuProcessor.java index 9ccd8a5..bb993a1 100644 --- a/src/main/java/view5d/MyMenuProcessor.java +++ b/src/main/java/view5d/MyMenuProcessor.java @@ -80,11 +80,11 @@ public MyMenuProcessor(PixelDisplay myp,char key) public MyMenuProcessor(PixelDisplay myp,ImageCanvas mypc, boolean inv, int colormap) { - data3d=myp.data3d; - mycanvas=mypc; - mypix=myp; - myPosL=null; - mycolor=colormap; + data3d=myp.data3d; + mycanvas=mypc; + mypix=myp; + myPosL=null; + mycolor=colormap; inverse=inv; } @@ -102,11 +102,11 @@ public void actionPerformed(ActionEvent e) // System.out.println("Action: :"+e); if (data3d != null) { - if (inverse) - data3d.InvertCMap(); + // if (inverse) + data3d.SetInvertCMap(inverse); data3d.ToggleModel(mycolor); - if (inverse) - data3d.InvertCMap(); + //if (inverse) + // data3d.InvertCMap(); mycanvas.UpdateAll(); mypix.CoordinatesChanged(); } diff --git a/src/main/java/view5d/View5D.java b/src/main/java/view5d/View5D.java index 9144428..1d459cf 100644 --- a/src/main/java/view5d/View5D.java +++ b/src/main/java/view5d/View5D.java @@ -1158,14 +1158,16 @@ public void set_colormap_no(int nr, int elem) { data3d.ToggleModel(elem, nr); mypan.c1.UpdateAll(); } + public int get_active_element() { return data3d.ActiveElement; } public int get_active_time() { return data3d.ActiveTime; } - public void add_colormap(int sz, byte reds[], byte greens[], byte blues[]) { - int lastLUT=data3d.AddLookUpTable(sz, reds, greens, blues); + + public void add_colormap(int sz, byte reds[], byte greens[], byte blues[], int type) { + int lastLUT=data3d.AddLookUpTable(sz, reds, greens, blues, type); NumberFormat nf = java.text.NumberFormat.getNumberInstance(Locale.US); String LUTName="User defined "+nf.format(lastLUT - Bundle.ElementModels+1); // System.out.println("CP 2 "+LUTName); diff --git a/src/main/java/view5d/View5D_.java b/src/main/java/view5d/View5D_.java index 8c8e4a4..1795e3c 100644 --- a/src/main/java/view5d/View5D_.java +++ b/src/main/java/view5d/View5D_.java @@ -370,7 +370,7 @@ public void CheckforLUT() // if (! lt.isGrayscale()) { // IJ.showMessage("Found LUT, importing ..."); - int lastLUT=data3d.AddLookUpTable(lt.getMapSize(),lt.getReds(),lt.getGreens(),lt.getBlues()); + int lastLUT=data3d.AddLookUpTable(lt.getMapSize(),lt.getReds(),lt.getGreens(),lt.getBlues(), 0); NumberFormat nf = java.text.NumberFormat.getNumberInstance(Locale.US); String LUTName="User defined "+nf.format(lastLUT-Bundle.ElementModels+1);