@Override public void writeExternal(ObjectOutput out) throws IOException { out.writeObject(name); out.writeObject(color); if (metadata != null) out.writeObject(metadata); out.writeObject(measurements); int n = nChildObjects(); out.writeInt(n); if (n > 0) { for (PathObject pathObject : childList) { out.writeObject(pathObject); } } }
public static int nLabelledObjectsForClass(final PathObjectHierarchy hierarchy, final PathClass pathClass) { int n = 0; for (PathObject pathObject : getAnnotationsForClass(hierarchy, pathClass)) { n += pathObject.nChildObjects(); } return n; // return getLabelledObjectsForClass(hierarchy, pathClass).size(); // TODO: Consider a more efficient implementation }
/** * Count the descendants of a PathObject recursively. * * @param pathObject * @return */ public static int countDescendants(final PathObject pathObject) { int count = pathObject.nChildObjects(); for (PathObject childObject : pathObject.getChildObjects().toArray(new PathObject[0])) count += countDescendants(childObject); return count; }
private void addPathObjectImpl(PathObject pathObject) { ensureChildList(nChildObjects() + 1); // Make sure the object is removed from any other parent if (pathObject.parent != this) { if (pathObject.parent != null && pathObject.parent.childList != null) pathObject.parent.childList.remove(pathObject); pathObject.parent = this; } childList.add(pathObject); if (!isRootObject()) Collections.sort(childList, DefaultPathObjectComparator.getInstance()); }
private void addPathObjectsImpl(Collection<? extends PathObject> pathObjects) { if (pathObjects == null || pathObjects.isEmpty()) return; ensureChildList(nChildObjects() + pathObjects.size());