Ejemplo n.º 1
0
    def compute_dr_wrt(self, wrt):

        if wrt not in (self.v, self.rt, self.t):
            return

        if wrt is self.t:
            if not hasattr(self,
                           '_drt') or self._drt.shape[0] != self.v.r.size:
                IS = np.arange(self.v.r.size)
                JS = IS % 3
                data = np.ones(len(IS))
                self._drt = sp.csc_matrix((data, (IS, JS)))
            return self._drt

        if wrt is self.rt:
            rot, rot_dr = cv2.Rodrigues(self.rt.r)
            rot_dr = rot_dr.reshape((3, 3, 3))
            dr = np.einsum('abc, zc -> zba', rot_dr, self.v.r).reshape((-1, 3))
            return dr

        if wrt is self.v:
            rot = cv2.Rodrigues(self.rt.r)[0]

            IS = np.repeat(np.arange(self.v.r.size), 3)
            JS = np.repeat(np.arange(self.v.r.size).reshape((-1, 3)),
                           3,
                           axis=0)
            data = np.vstack([rot for i in range(self.v.r.size / 3)])
            result = sp.csc_matrix((data.ravel(), (IS.ravel(), JS.ravel())))
            return result
Ejemplo n.º 2
0
    def compute_dr_wrt(self, wrt):
        if wrt not in [self.v, self.rt, self.t, self.f, self.c, self.k]:
            return None

        j = self.r_and_derivatives[1]
        if wrt is self.rt:
            return j[:, :3]
        elif wrt is self.t:
            return j[:, 3:6]
        elif wrt is self.f:
            return j[:, 6:8]
        elif wrt is self.c:
            return j[:, 8:10]
        elif wrt is self.k:
            return j[:, 10:10 + self.k.size]
        elif wrt is self.v:
            rot = cv2.Rodrigues(self.rt.r)[0]
            data = np.asarray(j[:, 3:6].dot(rot), order='C').ravel()
            IS = np.repeat(np.arange(self.v.r.size * 2 / 3), 3)
            JS = np.asarray(np.repeat(np.arange(self.v.r.size).reshape(
                (-1, 3)),
                                      2,
                                      axis=0),
                            order='C').ravel()
            result = sp.csc_matrix((data, (IS, JS)))
            return result
Ejemplo n.º 3
0
def draw_boundary_images(glf, glb, v, f, vpe, fpe, camera):
    """Assumes camera is set up correctly, and that glf has any texmapping on necessary."""
    glf.Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    glb.Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

    # Figure out which edges are on pairs of differently visible triangles
    from opendr.geometry import TriNormals
    tn = TriNormals(v, f).r.reshape((-1, 3))
    campos = -cv2.Rodrigues(camera.rt.r)[0].T.dot(camera.t.r)
    rays_to_verts = v.reshape((-1, 3)) - row(campos)
    rays_to_faces = rays_to_verts[f[:, 0]] + rays_to_verts[
        f[:, 1]] + rays_to_verts[f[:, 2]]
    dps = np.sum(rays_to_faces * tn, axis=1)
    dps = dps[fpe[:, 0]] * dps[fpe[:, 1]]
    silhouette_edges = np.asarray(np.nonzero(dps <= 0)[0], np.uint32)
    non_silhouette_edges = np.nonzero(dps > 0)[0]
    lines_e = vpe[silhouette_edges]
    lines_v = v

    visibility = draw_edge_visibility(glb,
                                      lines_v,
                                      lines_e,
                                      f,
                                      hidden_wireframe=True)
    shape = visibility.shape
    visibility = visibility.ravel()
    visible = np.nonzero(visibility.ravel() != 4294967295)[0]
    visibility[visible] = silhouette_edges[visibility[visible]]
    result = visibility.reshape(shape)
    return result
Ejemplo n.º 4
0
def compute_vpe_boundary_idxs(v, f, camera, fpe):
    # Figure out which edges are on pairs of differently visible triangles

    from geometry import TriNormals
    tn = TriNormals(v, f).r.reshape((-1, 3))

    #ray = cv2.Rodrigues(camera.rt.r)[0].T[:,2]
    campos = -cv2.Rodrigues(camera.rt.r)[0].T.dot(camera.t.r)
    rays_to_verts = v.reshape((-1, 3)) - row(campos)
    rays_to_faces = rays_to_verts[f[:, 0]] + rays_to_verts[
        f[:, 1]] + rays_to_verts[f[:, 2]]
    faces_invisible = np.sum(rays_to_faces * tn, axis=1)
    dps = faces_invisible[fpe[:, 0]] * faces_invisible[fpe[:, 1]]
    silhouette_edges = np.asarray(np.nonzero(dps <= 0)[0], np.uint32)
    return silhouette_edges, faces_invisible < 0
Ejemplo n.º 5
0
 def compute_r(self):
     return (cv2.Rodrigues(self.rt.r)[0].dot(self.v.r.T) +
             col(self.t.r)).T.copy()
Ejemplo n.º 6
0
 def view_matrix(self):
     R = cv2.Rodrigues(self.rt.r)[0]
     return np.hstack((R, col(self.t.r)))
Ejemplo n.º 7
0
 def compute_dr_wrt(self, wrt):
     if wrt is self.rt:
         return cv2.Rodrigues(self.rt.r)[1].T
Ejemplo n.º 8
0
 def compute_r(self):
     return cv2.Rodrigues(self.rt.r)[0]