def mouseMoveEvent(self, event):
     if self._start_position is not None:
         # v_rot = v*cos(theta)+(wxv)*sin(theta)+w*(w.v)*(1-cos(theta))
         # v is our vector
         # w is the unit vector to rotate around
         # theta is the angle to rotate
         if self._start_position[0] == event.x() and self._start_position[1] == event.y():
             return
         centre_point = calculateCentroid(self._plane.getRotationPoint(), self._plane.getNormal(), self._get_dimension_method())
         centre_widget = self._zinc_view.project(centre_point[0], centre_point[1], centre_point[2])
         a = sub(centre_widget, [event.x(), -event.y(), centre_widget[2]])
         b = sub(centre_widget, [self._start_position[0], -self._start_position[1], centre_widget[2]])
         c = dot(a, b)
         d = magnitude(a) * magnitude(b)
         theta = acos(min(c / d, 1.0))
         if theta != 0.0:
             g = cross(a, b)
             lookat, eye, up, angle = self._zinc_view.getViewParameters()
             w = normalize(sub(lookat, eye))
             if copysign(1, dot(g, [0, 0, 1])) < 0:
                 theta = -theta
             v = up
             p1 = mult(v, cos(theta))
             p2 = mult(cross(w, v), sin(theta))
             p3a = mult(w, dot(w, v))
             p3 = mult(p3a, 1 - cos(theta))
             v_rot = add(p1, add(p2, p3))
             self._zinc_view.setViewParameters(lookat, eye, v_rot, angle)
             self._start_position = [event.x(), event.y()]
     else:
         super(Abstract2DHandler, self).mouseMoveEvent(event)
Beispiel #2
0
    def mouseMoveEvent(self, event):
        if self._glyph.getMaterial().getName(
        ) == self._selected_material.getName():
            pos = getGlyphPosition(self._glyph)
            screen_pos = self._zinc_view.project(pos[0], pos[1], pos[2])
            global_cur_pos = self._zinc_view.unproject(event.x(), -event.y(),
                                                       screen_pos[2])
            global_old_pos = self._zinc_view.unproject(
                self._previous_mouse_position[0],
                -self._previous_mouse_position[1], screen_pos[2])
            global_pos_diff = sub(global_cur_pos, global_old_pos)

            n = self._plane.getNormal()
            proj_n = mult(n, dot(global_pos_diff, n))
            new_pos = add(pos, proj_n)
            scene = self._glyph.getScene()
            scene.beginChange()

            plane_centre = calculateCentroid(new_pos, self._plane.getNormal(),
                                             self._get_dimension_method())
            if plane_centre is not None:
                self._plane.setRotationPoint(plane_centre)
                setGlyphPosition(self._glyph, plane_centre)

            scene.endChange()
            self._previous_mouse_position = [event.x(), event.y()]
        else:
            super(Normal, self).mouseMoveEvent(event)
Beispiel #3
0
 def enter(self):
     scene = self._glyph.getScene()
     scene.beginChange()
     super(Normal, self).enter()
     setGlyphPosition(
         self._glyph,
         calculateCentroid(self._plane.getRotationPoint(),
                           self._plane.getNormal(),
                           self._get_dimension_method()))
     scene.endChange()
 def setScale(self, scale):
     '''
     Don't call this 'setScale' method directly let the main model do that
     this way we can ensure that the two scale fields have the same
     values.
     '''
     fieldmodule = self._scale_field.getFieldmodule()
     fieldcache = fieldmodule.createFieldcache()
     fieldmodule.beginChange()
     self._scale_field.assignReal(fieldcache, scale)
     fieldmodule.endChange()
     # Do I also need to set the dimensions for the self._plane?
     # I'm going to go with yes.
     plane_centre = calculateCentroid(self._plane.getRotationPoint(), self._plane.getNormal(), elmult(self._dimensions_px, scale))
     self._plane.setRotationPoint(plane_centre)  # (elmult(self._dimensions_px, scale))
    def _createPlane(self):
        '''
        Sets up a number of fields to represent the image plane and stores
        a handle to an object encapsulating these fields in the 
        class attribute '_plane'.  The plane has a normal and a
        point of rotation.
        '''
        fieldmodule = self._region.getFieldmodule()

        fieldmodule.beginChange()
        plane = Plane(fieldmodule)
        plane_centre = calculateCentroid(plane.getRotationPoint(), plane.getNormal(), self._dimensions_px)
        plane.setRotationPoint(plane_centre)  # (elmult(self._dimensions_px, scale))
        fieldmodule.endChange()

        return plane
 def mouseMoveEvent(self, event):
     if self._start_position is not None:
         # v_rot = v*cos(theta)+(wxv)*sin(theta)+w*(w.v)*(1-cos(theta))
         # v is our vector
         # w is the unit vector to rotate around
         # theta is the angle to rotate
         if self._start_position[0] == event.x(
         ) and self._start_position[1] == event.y():
             return
         centre_point = calculateCentroid(self._plane.getRotationPoint(),
                                          self._plane.getNormal(),
                                          self._get_dimension_method())
         centre_widget = self._zinc_view.project(centre_point[0],
                                                 centre_point[1],
                                                 centre_point[2])
         a = sub(centre_widget, [event.x(), -event.y(), centre_widget[2]])
         b = sub(centre_widget, [
             self._start_position[0], -self._start_position[1],
             centre_widget[2]
         ])
         c = dot(a, b)
         d = magnitude(a) * magnitude(b)
         theta = acos(min(c / d, 1.0))
         if theta != 0.0:
             g = cross(a, b)
             lookat, eye, up, angle = self._zinc_view.getViewParameters()
             w = normalize(sub(lookat, eye))
             if copysign(1, dot(g, [0, 0, 1])) < 0:
                 theta = -theta
             v = up
             p1 = mult(v, cos(theta))
             p2 = mult(cross(w, v), sin(theta))
             p3a = mult(w, dot(w, v))
             p3 = mult(p3a, 1 - cos(theta))
             v_rot = add(p1, add(p2, p3))
             self._zinc_view.setViewParameters(lookat, eye, v_rot, angle)
             self._start_position = [event.x(), event.y()]
     else:
         super(Abstract2DHandler, self).mouseMoveEvent(event)
Beispiel #7
0
    def mouseMoveEvent(self, event):
        if self._glyph.getMaterial().getName() == self._selected_material.getName():
            pos = getGlyphPosition(self._glyph)
            screen_pos = self._zinc_view.project(pos[0], pos[1], pos[2])
            global_cur_pos = self._zinc_view.unproject(event.x(), -event.y(), screen_pos[2])
            global_old_pos = self._zinc_view.unproject(self._previous_mouse_position[0], -self._previous_mouse_position[1], screen_pos[2])
            global_pos_diff = sub(global_cur_pos, global_old_pos)

            n = self._plane.getNormal()
            proj_n = mult(n, dot(global_pos_diff, n))
            new_pos = add(pos, proj_n)
            scene = self._glyph.getScene()
            scene.beginChange()

            plane_centre = calculateCentroid(new_pos, self._plane.getNormal(), self._get_dimension_method())
            if plane_centre is not None:
                self._plane.setRotationPoint(plane_centre)
                setGlyphPosition(self._glyph, plane_centre)

            scene.endChange()
            self._previous_mouse_position = [event.x(), event.y()]
        else:
            super(Normal, self).mouseMoveEvent(event)
    def mouseMoveEvent(self, event):
        scene = self._glyph.getScene()
        scene.beginChange()
#         super(Orientation, self).mouseMoveEvent(event)
        if self._glyph.getMaterial().getName() == self._selected_material.getName():
            x = event.x()
            y = event.y()
            far_plane_point = self._zinc_view.unproject(x, -y, -1.0)
            near_plane_point = self._zinc_view.unproject(x, -y, 1.0)
            point_on_plane = calculateLinePlaneIntersection(near_plane_point, far_plane_point, self._plane.getRotationPoint(), self._plane.getNormal())
            if point_on_plane is not None:
                dimensions = self._get_dimension_method()
                centroid = calculateCentroid(self._plane.getRotationPoint(), self._plane.getNormal(), dimensions)
                point_on_plane = boundCoordinatesToCuboid(point_on_plane, centroid, dimensions)
                setGlyphPosition(self._glyph, point_on_plane)
        else:
            width = self._zinc_view.width()
            height = self._zinc_view.height()
            radius = min([width, height]) / 2.0
            delta_x = float(event.x() - self._previous_mouse_position[0])
            delta_y = float(event.y() - self._previous_mouse_position[1])
            tangent_dist = sqrt((delta_x * delta_x + delta_y * delta_y))
            if tangent_dist > 0.0:
                dx = -delta_y / tangent_dist;
                dy = delta_x / tangent_dist;

                d = dx * (event.x() - 0.5 * (width - 1)) + dy * ((event.y() - 0.5 * (height - 1)))
                if d > radius: d = radius
                if d < -radius: d = -radius

                phi = acos(d / radius) - 0.5 * pi
                angle = 1.0 * tangent_dist / radius

                eye, lookat, up, _ = self._zinc_view.getViewParameters()

                b = up[:]
                b = normalize(b)
                a = sub(lookat, eye)
                a = normalize(a)
                c = cross(b, a)
                c = normalize(c)
                e = [None, None, None]
                e[0] = dx * c[0] + dy * b[0]
                e[1] = dx * c[1] + dy * b[1]
                e[2] = dx * c[2] + dy * b[2]
                axis = [None, None, None]
                axis[0] = sin(phi) * a[0] + cos(phi) * e[0]
                axis[1] = sin(phi) * a[1] + cos(phi) * e[1]
                axis[2] = sin(phi) * a[2] + cos(phi) * e[2]

                plane_normal = self._plane.getNormal()
                point_on_plane = self._plane.getRotationPoint()

                plane_normal_prime_1 = mult(plane_normal, cos(angle))
                plane_normal_prime_2 = mult(plane_normal, dot(plane_normal, axis) * (1 - cos(angle)))
                plane_normal_prime_3 = mult(cross(axis, plane_normal), sin(angle))
                plane_normal_prime = add(add(plane_normal_prime_1, plane_normal_prime_2), plane_normal_prime_3)

                self._plane.setPlaneEquation(plane_normal_prime, point_on_plane)

                self._previous_mouse_position = [event.x(), event.y()]
        scene.endChange()
    def mouseMoveEvent(self, event):
        scene = self._glyph.getScene()
        scene.beginChange()
        #         super(Orientation, self).mouseMoveEvent(event)
        if self._glyph.getMaterial().getName(
        ) == self._selected_material.getName():
            x = event.x()
            y = event.y()
            far_plane_point = self._zinc_view.unproject(x, -y, -1.0)
            near_plane_point = self._zinc_view.unproject(x, -y, 1.0)
            point_on_plane = calculateLinePlaneIntersection(
                near_plane_point, far_plane_point,
                self._plane.getRotationPoint(), self._plane.getNormal())
            if point_on_plane is not None:
                dimensions = self._get_dimension_method()
                centroid = calculateCentroid(self._plane.getRotationPoint(),
                                             self._plane.getNormal(),
                                             dimensions)
                point_on_plane = boundCoordinatesToCuboid(
                    point_on_plane, centroid, dimensions)
                setGlyphPosition(self._glyph, point_on_plane)
        else:
            width = self._zinc_view.width()
            height = self._zinc_view.height()
            radius = min([width, height]) / 2.0
            delta_x = float(event.x() - self._previous_mouse_position[0])
            delta_y = float(event.y() - self._previous_mouse_position[1])
            tangent_dist = sqrt((delta_x * delta_x + delta_y * delta_y))
            if tangent_dist > 0.0:
                dx = -delta_y / tangent_dist
                dy = delta_x / tangent_dist

                d = dx * (event.x() - 0.5 *
                          (width - 1)) + dy * (event.y() - 0.5 * (height - 1))
                if d > radius: d = radius
                if d < -radius: d = -radius

                phi = acos(d / radius) - 0.5 * pi
                angle = 1.0 * tangent_dist / radius

                eye, lookat, up, _ = self._zinc_view.getViewParameters()

                b = up[:]
                b = normalize(b)
                a = sub(lookat, eye)
                a = normalize(a)
                c = cross(b, a)
                c = normalize(c)
                e = [None, None, None]
                e[0] = dx * c[0] + dy * b[0]
                e[1] = dx * c[1] + dy * b[1]
                e[2] = dx * c[2] + dy * b[2]
                axis = [None, None, None]
                axis[0] = sin(phi) * a[0] + cos(phi) * e[0]
                axis[1] = sin(phi) * a[1] + cos(phi) * e[1]
                axis[2] = sin(phi) * a[2] + cos(phi) * e[2]

                plane_normal = self._plane.getNormal()
                point_on_plane = self._plane.getRotationPoint()

                plane_normal_prime_1 = mult(plane_normal, cos(angle))
                plane_normal_prime_2 = mult(
                    plane_normal,
                    dot(plane_normal, axis) * (1 - cos(angle)))
                plane_normal_prime_3 = mult(cross(axis, plane_normal),
                                            sin(angle))
                plane_normal_prime = add(
                    add(plane_normal_prime_1, plane_normal_prime_2),
                    plane_normal_prime_3)

                self._plane.setPlaneEquation(plane_normal_prime,
                                             point_on_plane)

                self._previous_mouse_position = [event.x(), event.y()]
        scene.endChange()
Beispiel #10
0
 def enter(self):
     scene = self._glyph.getScene()
     scene.beginChange()
     super(Normal, self).enter()
     setGlyphPosition(self._glyph, calculateCentroid(self._plane.getRotationPoint(), self._plane.getNormal(), self._get_dimension_method()))
     scene.endChange()