List of usage examples for java.lang Float isNaN
public boolean isNaN()
From source file:eu.uqasar.util.UQasarUtil.java
/** * /* www . j av a 2 s . c o m*/ * @param node Node whose value is studied * @return */ private static Multimap<SuggestionType, Object> getSuggestionForNode(TreeNode node) { // For storing the suggestion type and the payload Multimap<SuggestionType, Object> suggestionsMultimap = ArrayListMultimap.create(); final String EMPTY = ""; try { InitialContext ic = new InitialContext(); ProjectSimilarityService projectSimilarityService = (ProjectSimilarityService) ic .lookup("java:module/ProjectSimilarityService"); QualityObjectiveSimilarityService qoSimilarityService = (QualityObjectiveSimilarityService) ic .lookup("java:module/QualityObjectiveSimilarityService"); //TODO: Finding similar metrics if (node instanceof QualityObjective) { QualityObjective qo = (QualityObjective) node; Float value = qo.getValue(); // If the value of a quality objective cannot be computed, // attempt to obtain a suggestion if (value == null || value.isNaN()) { // Attempt to find a suitable project Project proj = qo.getProject(); Project similarProject = null; if (proj != null) { // Get a list of similar projects List<Project> similarProjects = projectSimilarityService.getSimilarProjects(proj); if (similarProjects != null && similarProjects.size() > 0) { // For now obtain the first suitable project similarProject = similarProjects.get(0); } } // If a suitable similar project was found, search for similar Quality Objective(s) to be suggested if (similarProject != null) { // Get similar QOs from a similar project List<QualityObjective> qos = qoSimilarityService.getSimilarQOs(qo, similarProject); // If results were found, construct a suggestion (for now obtain the first one). if (qos != null && qos.size() > 0) { suggestionsMultimap.put(SuggestionType.QO_REPLACE, qos.get(0)); return suggestionsMultimap; } } // Otherwise suggest the QO to be removed suggestionsMultimap.put(SuggestionType.QO_REMOVE, null); return suggestionsMultimap; } } // if a metric has no value / the value is 0, return a suggestion to // remove the metric if (node instanceof Metric) { Metric metric = (Metric) node; Float value = metric.getValue(); if (value == null || value.isNaN() || value.isInfinite()) { suggestionsMultimap.put(SuggestionType.METRIC_REMOVE, null); return suggestionsMultimap; } } } catch (NamingException e) { e.printStackTrace(); } // If no suggestion is to be provided, return an empty string // (overwrite the possible existing suggestion). suggestionsMultimap.put(SuggestionType.NO_SUGGESTION, ""); return suggestionsMultimap; }
From source file:svxconv.SVXConv.java
public void execute() throws IOException { int processors = Runtime.getRuntime().availableProcessors(); if (threadCount == 0) { threadCount = processors;/*from w w w . j a v a 2 s . co m*/ } else if (threadCount > processors) { printf("Capping threads to max processors: %d", processors); threadCount = processors; } AbFab3DGlobals.put(AbFab3DGlobals.MAX_PROCESSOR_COUNT_KEY, threadCount); // Load input into a grid String ext = FilenameUtils.getExtension(input); AttributeGrid grid = null; int subvoxelResolution = 255; if (ext.equalsIgnoreCase("svx")) { SVXReader reader = new SVXReader(); grid = reader.load(input); SVXManifest manifest = reader.getManifest(); Map<String, String> map = manifest.getMetadata(); String meshErrorFactor_st = map.get("meshErrorFactor"); String meshSmoothingWidth_st = map.get("meshSmoothingWidth"); if (meshErrorFactor_st != null) { meshErrorFactor = Double.parseDouble(meshErrorFactor_st); printf("Using user specified meshErrorFactor: %4.3f\n", meshErrorFactor); } if (meshSmoothingWidth_st != null) { meshSmoothingWidth = Double.parseDouble(meshSmoothingWidth_st); printf("Using user specified meshSmoothingWidth: %4.3f\n", meshSmoothingWidth); } } else if (ext.equalsIgnoreCase("stl") || ext.startsWith("x3d") || ext.startsWith("X3D")) { BoundingBoxCalculator bb = new BoundingBoxCalculator(); TriangleProducer tp = null; if (ext.startsWith("x3d") || ext.startsWith("X3D")) { tp = new X3DReader(input); tp.getTriangles(bb); } else { tp = new STLReader(input); tp.getTriangles(bb); } double bounds[] = new double[6]; bb.getBounds(bounds); printf(" orig bounds: [ %7.3f, %7.3f], [%7.3f, %7.3f], [%7.3f, %7.3f] mm; voxelSize: %7.3f mm\n", bounds[0] / MM, bounds[1] / MM, bounds[2] / MM, bounds[3] / MM, bounds[4] / MM, bounds[5] / MM, voxelSize / MM); // Add a margin around the model to get some space bounds = MathUtil.extendBounds(bounds, 1 * voxelSize); // // round up to the nearest voxel // MathUtil.roundBounds(bounds, voxelSize); int nx = (int) Math.round((bounds[1] - bounds[0]) / voxelSize); int ny = (int) Math.round((bounds[3] - bounds[2]) / voxelSize); int nz = (int) Math.round((bounds[5] - bounds[4]) / voxelSize); printf(" grid bounds: [ %7.3f, %7.3f], [%7.3f, %7.3f], [%7.3f, %7.3f] mm; voxelSize: %7.3f mm\n", bounds[0] / MM, bounds[1] / MM, bounds[2] / MM, bounds[3] / MM, bounds[4] / MM, bounds[5] / MM, voxelSize / MM); printf(" grid size: [%d x %d x %d]\n", nx, ny, nz); // range check bounds and voxelSized for (int i = 0; i < bounds.length; i++) { Float f = new Float(bounds[i]); if (f.isNaN()) { throw new IllegalArgumentException("Grid size[" + i + "] is Not a Number."); } } if (nx <= 0) { throw new IllegalArgumentException("Grid x size <= 0: " + nx); } if (ny <= 0) { throw new IllegalArgumentException("Grid y size <= 0" + ny); } if (nz <= 0) { throw new IllegalArgumentException("Grid z size <= 0" + nz); } grid = makeEmptyGrid(new int[] { nx, ny, nz }, voxelSize); grid.setGridBounds(bounds); WaveletRasterizer rasterizer = new WaveletRasterizer(bounds, nx, ny, nz); rasterizer.setMaxAttributeValue(subvoxelResolution); tp.getTriangles(rasterizer); rasterizer.getRaster(grid); } // Write output to a file ext = FilenameUtils.getExtension(output); if (ext.equalsIgnoreCase("svx")) { SVXWriter writer = new SVXWriter(); writer.write(grid, output); } else if (ext.equalsIgnoreCase("stl")) { TriangleMesh mesh = getMesh(grid, subvoxelResolution, meshMinVolume, meshMaxPartsCount); STLWriter stl = new STLWriter(output); mesh.getTriangles(stl); stl.close(); } else if (ext.startsWith("x3d") || ext.startsWith("X3D")) { WingedEdgeTriangleMesh mesh = (WingedEdgeTriangleMesh) getMesh(grid, subvoxelResolution, meshMinVolume, meshMaxPartsCount); GridSaver.writeMesh(mesh, output); } }
From source file:it.uniroma2.sag.kelp.data.representation.vector.SparseVector.java
@Override public void setDataFromText(String representationDescription) throws IOException { String[] feats = representationDescription.trim().split(FEATURE_SEPARATOR); if (feats[0].equals("")) { return;/*from w ww.j a v a 2 s .co m*/ } String dimTmp = null; String valueTmp = null; float value; for (String feature : feats) { int separatorIndex = feature.lastIndexOf(NAME_VALUE_SEPARATOR); if (separatorIndex <= 0) { throw new IOException( "Parsing error in SparseVector.init function: formatting error in the feat-value pair " + feature); } dimTmp = feature.substring(0, separatorIndex); valueTmp = feature.substring(separatorIndex + 1); Float val = Float.parseFloat(valueTmp); if (val.isNaN()) { logger.warn("NaN value in representation: " + representationDescription); } value = val.floatValue(); this.setFeatureValue(dimTmp, value); } }
From source file:pcgen.cdom.facet.analysis.ChallengeRatingFacet.java
public int getXPAward(CharID id) { Map<String, Integer> xpAwardsMap = SettingsHandler.getGame().getXPAwards(); if (xpAwardsMap.size() > 0) { Float cr = getCR(id); if (cr.isNaN() || cr == 0) { return 0; }// ww w . j a v a2s. co m String crString = ""; String crAsString = Float.toString(cr); String decimalPlaceValue = crAsString.substring(crAsString.length() - 2); // If the CR is a fractional CR then we convert to a 1/x format if (cr > 0 && cr < 1) { Fraction fraction = Fraction.getFraction(cr);// new Fraction(CR); int denominator = fraction.getDenominator(); int numerator = fraction.getNumerator(); crString = numerator + "/" + denominator; } else if (cr >= 1 || cr == 0) { int newCr = -99; if (decimalPlaceValue.equals(".0")) { newCr = (int) cr.floatValue(); } if (newCr > -99) { crString = crString + newCr; } else { crString = crString + cr; } } return xpAwardsMap.get(crString); } return 0; }
From source file:pcgen.cdom.facet.analysis.ChallengeRatingFacet.java
/** * Returns the Challenge Rating of the Player Character represented by the * given CharID/*from w w w .ja va 2 s .c o m*/ * * @param id * The CharID representing the Player Character for which the * Challenge Rating should be returned * @return The Challenge Rating of the Player Character represented by the * given CharID */ public Float getCR(CharID id) { Float CR = new Float(0); if (levelFacet.getMonsterLevelCount(id) == 0) { if (levelFacet.getNonMonsterLevelCount(id) == 0) { return Float.NaN; } // calculate and add class CR for 0-HD races CR += calcClassesCR(id); } else { // calculate and add race CR and classes CR for // races with racial hit dice Float classRaceCR = calcClassesForRaceCR(id); if (classRaceCR.isNaN()) { return Float.NaN; } CR += calcRaceCR(id); CR += classRaceCR; } // calculate and add CR bonus from templates CR += getTemplateCR(id); // calculate and add in the MISC bonus to CR CR += (float) bonusCheckingFacet.getBonus(id, "MISC", "CR"); // change calculated results of less than CR 1 to fraction format if (CR < 1) { Float crMod = SettingsHandler.getGame().getCRSteps().get((int) CR.floatValue()); if (crMod != null) { CR = crMod; } else { CR = Math.max(CR, 0); } } return CR; }
From source file:pcgen.cdom.facet.analysis.ChallengeRatingFacet.java
private Float calcClassesForRaceCR(CharID id) { Float CR = new Float(0); int levelsKey = 0; int levelsNonKey = 0; int levelsConverted = 0; int threshold = 0; List<String> raceRoleList = raceFacet.get(id).getListFor(ListKey.MONSTER_ROLES); if (raceRoleList == null || raceRoleList.isEmpty()) { raceRoleList = SettingsHandler.getGame().getMonsterRoleDefaultList(); }//from w w w. jav a 2 s .co m // Calculate and add the CR from the PC Classes for (PCClass pcClass : classFacet.getClassSet(id)) { Float levels = calcClassCR(id, pcClass); if (levels.isNaN()) { return Float.NaN; } List<String> classRoleList = pcClass.getListFor(ListKey.MONSTER_ROLES); if (classRoleList != null) { classRoleList.retainAll(raceRoleList); if (classRoleList.size() > 0) { levelsKey += (int) levels.floatValue(); } else { levelsNonKey += (int) levels.floatValue(); } } else { if (raceRoleList != null) { levelsNonKey += (int) levels.floatValue(); } else { levelsKey += (int) levels.floatValue(); } } } String sThreshold = SettingsHandler.getGame().getCRThreshold(); if (sThreshold != null) { threshold = formulaResolvingFacet.resolve(id, FormulaFactory.getFormulaFor(sThreshold), "").intValue(); } while (levelsNonKey > 1) { CR++; // TODO: maybe the divisor 2 should be be made configurable, // or the whole calculation put into a formula levelsNonKey -= 2; levelsConverted += 2; if (levelsConverted >= threshold) { break; } } if (levelsConverted > 0) { CR += levelsNonKey; } CR += levelsKey; return CR; }
From source file:abfab3d.shapejs.ShapeJSGlobal.java
/** * Create a new grid//from w w w .j a v a 2s . c o m * <p/> * This method is defined as a JavaScript function. */ public static Object createGrid(Context cx, Scriptable thisObj, Object[] args, Function funObj) { double[] grid_bounds = new double[6]; double vs = 0.1 * MM; for (int i = 0; i < args.length; i++) { String st = null; if (args[i] instanceof NativeJavaObject) { Object o = ((NativeJavaObject) args[i]).unwrap(); st = "JNO class=" + o.getClass() + " val: " + (o.toString()); } else { st = args[i].toString(); } //System.out.println("arg: " + i + " val: " + st); } if (args.length == 1) { if (args[0] instanceof AttributeGrid) { AttributeGrid grid = (AttributeGrid) args[0]; grid.getGridBounds(grid_bounds); vs = grid.getVoxelSize(); } else if (args[0] instanceof NativeJavaObject) { AttributeGrid grid = (AttributeGrid) ((NativeJavaObject) args[0]).unwrap(); grid.getGridBounds(grid_bounds); vs = grid.getVoxelSize(); } } else if (args.length == 4) { if (args[0] instanceof AttributeGrid) { AttributeGrid grid = (AttributeGrid) args[0]; grid.getGridBounds(grid_bounds); vs = grid.getVoxelSize(); } else if (args[0] instanceof NativeJavaObject) { AttributeGrid grid = (AttributeGrid) ((NativeJavaObject) args[0]).unwrap(); grid.getGridBounds(grid_bounds); vs = grid.getVoxelSize(); } double x = getDouble(args[1]); double y = getDouble(args[2]); double z = getDouble(args[3]); grid_bounds[0] -= x; grid_bounds[1] += x; grid_bounds[2] -= y; grid_bounds[3] += y; grid_bounds[4] -= z; grid_bounds[5] += z; } else if (args.length == 7) { grid_bounds[0] = getDouble(args[0]); grid_bounds[1] = getDouble(args[1]); grid_bounds[2] = getDouble(args[2]); grid_bounds[3] = getDouble(args[3]); grid_bounds[4] = getDouble(args[4]); grid_bounds[5] = getDouble(args[5]); vs = getDouble(args[6]); } else { throw new IllegalArgumentException( "Invalid number of arguments to CreateGrid(xmin,xmax,ymin,ymax,zmin,zmax,voxelSize)"); } // range check bounds and voxelSized for (int i = 0; i < grid_bounds.length; i++) { Float f = new Float(grid_bounds[i]); if (f.isNaN()) { throw new IllegalArgumentException("Grid size[" + i + "] is Not a Number."); } } if (args.length != 1) { // When passed a grid make sure its exactly the same size grid_bounds = MathUtil.roundBounds(grid_bounds, vs); } int[] gs = MathUtil.getGridSize(grid_bounds, vs); // range check bounds and voxelSized for (int i = 0; i < gs.length; i++) { if (gs[i] <= 0) { throw new IllegalArgumentException("Grid size[" + i + "] <= 0"); } } AttributeGrid dest = makeEmptyGrid(gs, vs); //System.out.println("Creating grid: " + java.util.Arrays.toString(gs) + java.util.Arrays.toString(grid_bounds) + " vs: " + vs); dest.setGridBounds(grid_bounds); return cx.getWrapFactory().wrapAsJavaObject(cx, funObj.getParentScope(), dest, null); }
From source file:abfab3d.shapejs.ShapeJSGlobal.java
/** * Load a model into a Grid//from w ww . java 2s. c o m * <p/> * This method is defined as a JavaScript function. */ public static Object loadModelDensity(Context cx, Scriptable thisObj, Object[] args, Function funObj) { if (args.length < 1) { throw Context.reportRuntimeError("No file provided for load() command"); } String filename = Context.toString(args[0]); printf("filename: %s\n", filename); AttributeGrid grid = null; if (filename == null || filename.length() == 0) { throw Context.reportRuntimeError("No file provided for load() command"); } // TODO: This needs URL caching double vs = 0.1 * MM; if (args.length > 1) { Object arg1 = unwrap(args[1]); printf("arg[1]: %s\n", arg1); if (arg1 instanceof Grid) { grid = (AttributeGrid) arg1; } else { vs = getDouble(arg1); } } double margin = vs; if (args.length > 2) { margin = getDouble(args[2]); } printf("load(%s, vs: %7.3f mm, margin: %7.3f mm)\n", filename, vs / MM, margin / MM); try { BoundingBoxCalculator bb = new BoundingBoxCalculator(); TriangleProducer tp = null; if (filename.endsWith(".x3d") || filename.endsWith(".x3db") || filename.endsWith(".x3dv")) { tp = new X3DReader(filename); tp.getTriangles(bb); } else if (filename.endsWith(".svx")) { SVXReader reader = new SVXReader(); return reader.load(filename); } else { tp = new STLReader(filename); tp.getTriangles(bb); } double bounds[] = new double[6]; bb.getBounds(bounds); printf(" orig bounds: [ %7.3f, %7.3f], [%7.3f, %7.3f], [%7.3f, %7.3f] mm; vs: %7.3f mm\n", bounds[0] / MM, bounds[1] / MM, bounds[2] / MM, bounds[3] / MM, bounds[4] / MM, bounds[5] / MM, vs / MM); // Add a margin around the model to get some space bounds = MathUtil.extendBounds(bounds, margin); // // round up to the nearest voxel // MathUtil.roundBounds(bounds, vs); int nx = (int) Math.round((bounds[1] - bounds[0]) / vs); int ny = (int) Math.round((bounds[3] - bounds[2]) / vs); int nz = (int) Math.round((bounds[5] - bounds[4]) / vs); printf(" grid bounds: [ %7.3f, %7.3f], [%7.3f, %7.3f], [%7.3f, %7.3f] mm; vs: %7.3f mm\n", bounds[0] / MM, bounds[1] / MM, bounds[2] / MM, bounds[3] / MM, bounds[4] / MM, bounds[5] / MM, vs / MM); printf(" grid size: [%d x %d x %d]\n", nx, ny, nz); // range check bounds and voxelSized for (int i = 0; i < bounds.length; i++) { Float f = new Float(bounds[i]); if (f.isNaN()) { throw new IllegalArgumentException("Grid size[" + i + "] is Not a Number."); } } if (nx <= 0) { throw new IllegalArgumentException("Grid x size <= 0: " + nx); } if (ny <= 0) { throw new IllegalArgumentException("Grid y size <= 0" + ny); } if (nz <= 0) { throw new IllegalArgumentException("Grid z size <= 0" + nz); } AttributeGrid dest = null; if (grid == null) { dest = makeEmptyGrid(new int[] { nx, ny, nz }, vs); } else { dest = grid; } dest.setGridBounds(bounds); WaveletRasterizer rasterizer = new WaveletRasterizer(bounds, nx, ny, nz); rasterizer.setMaxAttributeValue(m_svr); tp.getTriangles(rasterizer); rasterizer.getRaster(dest); System.out.println("Loaded: " + filename); return dest; } catch (Throwable t) { t.printStackTrace(); } throw Context.reportRuntimeError("Failed to load file: " + filename); }
From source file:org.caleydo.core.data.collection.table.Table.java
/** * Returns the 3-component color for the given table cell. This works independent of the data type. * * FIXME: inhomogeneous numerical is not implemented * * @param dimensionID/*from w ww . j a v a 2 s. c om*/ * @param recordID * @return */ public float[] getColor(Integer dimensionID, Integer recordID) { if (isDataHomogeneous()) { return getColorMapper().getColor(getNormalizedValue(dimensionID, recordID)); } else { if (EDataClass.CATEGORICAL.equals(getDataClass(dimensionID, recordID))) { CategoricalClassDescription<?> specific = (CategoricalClassDescription<?>) getDataClassSpecificDescription( dimensionID, recordID); Object category = getRaw(dimensionID, recordID); if (category == null) return Color.NOT_A_NUMBER_COLOR.getRGBA(); CategoryProperty<?> p = specific.getCategoryProperty(category); if (p == null) return Color.NOT_A_NUMBER_COLOR.getRGBA(); return specific.getCategoryProperty(category).getColor().getRGBA(); } else { // simple implementation just gray scale Float v = getNormalizedValue(dimensionID, recordID); if (v == null || v.isNaN()) return Color.NOT_A_NUMBER_COLOR.getRGBA(); return new Color(v.floatValue()).getRGBA(); // not implemented // throw new IllegalStateException("not implemented"); } } }
From source file:plugin.exporttokens.CRToken.java
/** * @see pcgen.io.exporttoken.Token#getToken(java.lang.String, pcgen.core.PlayerCharacter, pcgen.io.ExportHandler) *///from w ww.ja va2s . c o m @Override public String getToken(String tokenSource, CharacterDisplay display, ExportHandler eh) { String retString = ""; Float cr = display.calcCR(); String crAsString = Float.toString(cr); String decimalPlaceValue = crAsString.substring(crAsString.length() - 2); if (cr > 0 && cr < 1) { // If the CR is a fractional CR then we convert to a 1/x format Fraction fraction = Fraction.getFraction(cr);// new Fraction(CR); int denominator = fraction.getDenominator(); int numerator = fraction.getNumerator(); retString = numerator + "/" + denominator; } else if (cr >= 1 || cr == 0) { int newCr = -99; if (decimalPlaceValue.equals(".0")) { newCr = (int) cr.floatValue(); } if (newCr > -99) { retString = retString + newCr; } else { retString = retString + cr; } } else if (cr.isNaN()) { retString = "0"; } return retString; }