Calculate the average size of a mesh.
        This is the mean of the vertex distances from the center of mass.
960055
def averageSize(self):
        """"""
        cm = self.centerOfMass()
        coords = self.coordinates(copy=False)
        if not len(coords):
            return 0
        s, c = 0.0, 0.0
        n = len(coords)
        step = int(n / 10000.0) + 1
        for i in np.arange(0, n, step):
            s += utils.mag(coords[i] - cm)
            c += 1
        return s / c
149011
def distance_sqr(point, seg):
    ''''''
    centre_of_mass = segment_centre_of_mass(seg)
    return sum(pow(np.subtract(point, centre_of_mass), 2))
478673
def get_standard_mesh(self, scaled=True):
        
        # TODO: allow this to take etheta and retreive a mesh at that true anomaly
        theta = 0.0
        protomesh = self._standard_meshes[theta] #.copy() # if theta in self._standard_meshes.keys() else self.mesh.copy()

        if scaled:
            # TODO: be careful about self._scale... we may want self._instantaneous_scale
            return mesh.ScaledProtoMesh.from_proto(protomesh, self._scale)
        else:
            return protomesh.copy()
234428
def scale(self):
        
        # use vertices peak-peak rather than exact extents
        scale = float((self.vertices.ptp(axis=0) ** 2).sum() ** .5)
        return scale
1022407
def get_min_vertex_distance( coor, guess ):
    """"""
    # Sort by x.
    ix = nm.argsort( coor[:,0] )
    scoor = coor[ix]

    mvd = 1e16
    
    # Get mvd in chunks potentially smaller than guess.
    n_coor = coor.shape[0]
    print n_coor
    
    i0 = i1 = 0
    x0 = scoor[i0,0]
    while 1:
        while ((scoor[i1,0] - x0) < guess) and (i1 < (n_coor - 1)):
            i1 += 1

#        print i0, i1, x0, scoor[i1,0]
        aim, aa1, aa2, aux = get_min_vertex_distance_naive( scoor[i0:i1+1] )
        if aux < mvd:
            im, a1, a2 = aim, aa1 + i0, aa2 + i0
        mvd = min( mvd, aux )
        i0 = i1 = int( 0.5 * (i1 + i0 ) ) + 1
#        i0 += 1
        x0 = scoor[i0,0]
#        print '-', i0

        if i1 == n_coor - 1: break

    print im, ix[a1], ix[a2], a1, a2, scoor[a1], scoor[a2]

    return mvd
343052
def get_size(self, m):
        
        nrow, ncol = 0, 0
        if m[0] == 'F':
            nrow = self.n
        elif m[0] == 'G':
            nrow = self.m

        if m[1] == 'x':
            ncol = self.n
        elif m[1] == 'y':
            ncol = self.m

        return nrow, ncol
897039
def calculate_centre_of_mass(self):
        
        self.centre_of_mass = center_of_mass(self.elements, self.coordinates)
        self.properties['centre_of_mass'] = self.centre_of_mass
        return self.centre_of_mass
983860
def mesh_nmasked(self):
        

        return self._make_2d_array(
            np.ma.count_masked(self._data_sigclip, axis=1))
381265
public float getNormalY(int vertex) {
        if (!hasNormals()) {
            throw new IllegalStateException("mesh has no normals");
        }
        
        checkVertexIndexBounds(vertex);
        
        return m_normals.getFloat((vertex * 3 + 1) * SIZEOF_FLOAT);
    }
1347660
function findLargestInCol (M, i, startAtRow = 0) {
  let me = M.elements;
  let n = M.dimension;
  let offset = i * n;
  let maxIdx = startAtRow;
  let maxVal = _Math.abs(me[offset + maxIdx]);
  for (let i = maxIdx + 1; i < n; ++i) {
    let val = _Math.abs(me[offset + i]);
    if (val > maxVal) {
      maxIdx = i;
      maxVal = val;
    }
  }
  return maxIdx;
}
26332
private float calculateModuleSizeOneWay(ResultPoint pattern, ResultPoint otherPattern) {
    float moduleSizeEst1 = sizeOfBlackWhiteBlackRunBothWays((int) pattern.getX(),
        (int) pattern.getY(),
        (int) otherPattern.getX(),
        (int) otherPattern.getY());
    float moduleSizeEst2 = sizeOfBlackWhiteBlackRunBothWays((int) otherPattern.getX(),
        (int) otherPattern.getY(),
        (int) pattern.getX(),
        (int) pattern.getY());
    if (Float.isNaN(moduleSizeEst1)) {
      return moduleSizeEst2 / 7.0f;
    }
    if (Float.isNaN(moduleSizeEst2)) {
      return moduleSizeEst1 / 7.0f;
    }
    // Average them, and divide by 7 since we've counted the width of 3 black modules,
    // and 1 white and 1 black module on either side. Ergo, divide sum by 14.
    return (moduleSizeEst1 + moduleSizeEst2) / 14.0f;
  }
508477
public float getNormalZ(int vertex) {
        if (!hasNormals()) {
            throw new IllegalStateException("mesh has no normals");
        }
        
        checkVertexIndexBounds(vertex);
        
        return m_normals.getFloat((vertex * 3 + 2) * SIZEOF_FLOAT);
    }
1341196
def get_flat_size(self):
        
        return sum(
            np.prod(v.get_shape().as_list()) for v in self.variables.values())
727597
def calculate_size(name, index, value):
    
    data_size = 0
    data_size += calculate_size_str(name)
    data_size += INT_SIZE_IN_BYTES
    data_size += calculate_size_data(value)
    return data_size
84856
def get_min_distance(self, mesh):
        
        dists = [surf.get_min_distance(mesh) for surf in self.surfaces]

        return numpy.min(dists, axis=0)
15253
public static void scale(GVRMesh mesh, float x, float y, float z) {
        final float [] vertices = mesh.getVertices();
        final int vsize = vertices.length;

        for (int i = 0; i < vsize; i += 3) {
            vertices[i]     *= x;
            vertices[i + 1] *= y;
            vertices[i + 2] *= z;
        }

        mesh.setVertices(vertices);
    }
639741
def to_mesh(self, dist_thresh=0.01):
        
        # init vertex and triangle buffers
        vertices = []
        triangles = []
        vertex_indices = -1 * np.ones([self.height, self.width]).astype(np.int32)
        
        for i in range(self.height-1):
            for j in range(self.width-1):
                # read corners of square
                v0 = self.data[i,j,:]
                v1 = self.data[i,j+1,:]
                v2 = self.data[i+1,j,:]
                v3 = self.data[i+1,j+1,:]

                # check distances
                d01 = np.abs(v0[2] - v1[2])
                d02 = np.abs(v0[2] - v2[2])
                d03 = np.abs(v0[2] - v3[2])
                d13 = np.abs(v1[2] - v3[2])
                d23 = np.abs(v2[2] - v3[2])

                # add tri 1
                if max(d01, d03, d13) < dist_thresh:
                    # add vertices
                    if vertex_indices[i,j] == -1:
                        vertices.append(v0)
                        vertex_indices[i,j] = len(vertices)-1
                    if vertex_indices[i,j+1] == -1:
                        vertices.append(v1)
                        vertex_indices[i,j+1] = len(vertices)-1
                    if vertex_indices[i+1,j+1] == -1:
                        vertices.append(v3)
                        vertex_indices[i+1,j+1] = len(vertices)-1
                
                    # add tri
                    i0 = vertex_indices[i,j]
                    i1 = vertex_indices[i,j+1]
                    i3 = vertex_indices[i+1,j+1]
                    triangles.append([i0, i1, i3])

                # add tri 2
                if max(d01, d03, d23) < dist_thresh:
                    # add vertices
                    if vertex_indices[i,j] == -1:
                        vertices.append(v0)
                        vertex_indices[i,j] = len(vertices)-1
                    if vertex_indices[i+1,j] == -1:
                        vertices.append(v2)
                        vertex_indices[i+1,j] = len(vertices)-1
                    if vertex_indices[i+1,j+1] == -1:
                        vertices.append(v3)
                        vertex_indices[i+1,j+1] = len(vertices)-1
                
                    # add tri
                    i0 = vertex_indices[i,j]
                    i2 = vertex_indices[i+1,j]
                    i3 = vertex_indices[i+1,j+1]
                    triangles.append([i0, i3, i2])

        # return trimesh
        import trimesh
        mesh = trimesh.Trimesh(vertices, triangles)
        return mesh