Beispiel #1
0
    def from_data(cls, data):
        """Construct a PrintPoint from its data representation.

        Parameters
        ----------
        data: dict
            The data dictionary.

        Returns
        -------
        layer
            The constructed PrintPoint.

        """

        pp = cls(pt=Point.from_data(data['point']),
                 layer_height=data['layer_height'],
                 mesh_normal=Vector.from_data(data['mesh_normal']))

        pp.up_vector = Vector.from_data(data['up_vector'])
        pp.frame = Frame.from_data(data['frame'])

        pp.extruder_toggle = data['extruder_toggle']
        pp.velocity = data['velocity']
        pp.wait_time = data['wait_time']
        pp.blend_radius = data['blend_radius']

        pp.closest_support_pt = Point.from_data(data['closest_support_pt'])
        pp.distance_to_support = data['distance_to_support']

        pp.is_feasible = data['is_feasible']

        pp.attributes = data['attributes']
        return pp
Beispiel #2
0
    def from_data(cls, data):
        """Construct a BSpline surface from its data representation.

        Parameters
        ----------
        data : dict
            The data dictionary.

        Returns
        -------
        :class:`compas.geometry.NurbsSurface`
            The constructed surface.

        """
        points = [[Point.from_data(point) for point in row]
                  for row in data['points']]
        weights = data['weights']
        u_knots = data['u_knots']
        v_knots = data['v_knots']
        u_mults = data['u_mults']
        v_mults = data['v_mults']
        u_degree = data['u_degree']
        v_degree = data['v_degree']
        is_u_periodic = data['is_u_periodic']
        is_v_periodic = data['is_v_periodic']
        return cls.from_parameters(points, weights, u_knots, v_knots, u_mults,
                                   v_mults, u_degree, v_degree, is_u_periodic,
                                   is_v_periodic)
Beispiel #3
0
 def test_data():
     p = Point(0, 0, '0')
     assert p.data == p.validate_data()
     o = Point.from_data(p.data)
     assert p == o
     assert not (p is o)
     assert o.data == o.validate_data()
Beispiel #4
0
 def data(self, data):
     points = [Point.from_data(point) for point in data['points']]
     weights = data['weights']
     knots = data['knots']
     multiplicities = data['multiplicities']
     degree = data['degree']
     is_periodic = data['is_periodic']
     self.occ_curve = occ_curve_from_parameters(points, weights, knots,
                                                multiplicities, degree,
                                                is_periodic)
Beispiel #5
0
 def data(self, data):
     points = [Point.from_data(point) for point in data['points']]
     weights = data['weights']
     knots = data['knots']
     multiplicities = data['multiplicities']
     degree = data['degree']
     # is_periodic = data['is_periodic']
     # have not found a way to actually set this
     # not sure if that is actually possible...
     self.rhino_curve = rhino_curve_from_parameters(points, weights, knots, multiplicities, degree)
Beispiel #6
0
 def data(self, data):
     points = [[Point.from_data(point) for point in row]
               for row in data['points']]
     weights = data['weights']
     u_knots = data['u_knots']
     v_knots = data['v_knots']
     u_mults = data['u_mults']
     v_mults = data['v_mults']
     u_degree = data['u_degree']
     v_degree = data['v_degree']
     is_u_periodic = data['is_u_periodic']
     is_v_periodic = data['is_v_periodic']
     self.rhino_surface = NurbsSurface.from_parameters(
         points, weights, u_knots, v_knots, u_mults, v_mults, u_degree,
         v_degree, is_u_periodic, is_v_periodic)
Beispiel #7
0
def data_to_rhino_surface(data):
    """Convert a COMPAS surface to a Rhino surface.

    Parameters
    ----------
    data: dict

    Returns
    -------
    :rhino:`Rhino.Geometry.NurbsSurface`

    """
    points = [[Point.from_data(point) for point in row]
              for row in data['points']]

    nu = len(points[0])
    nv = len(points)

    nurbs = RhinoNurbsSurface.Create(3, False, data['u_degree'] + 1,
                                     data['v_degree'] + 1, nu, nv)
    for i in range(nu):
        for j in range(nv):
            nurbs.Points.SetPoint(i, j, point_to_rhino(points[j][i]))
            nurbs.Points.SetWeight(i, j, data['weights'][j][i])

    u_knotvector = []
    for knot, mult in zip(data['u_knots'], data['u_mults']):
        for i in range(mult):
            u_knotvector.append(knot)

    for index, knot in enumerate(u_knotvector):
        nurbs.KnotsU.Item[index] = knot

    v_knotvector = []
    for knot, mult in zip(data['v_knots'], data['v_mults']):
        for i in range(mult):
            v_knotvector.append(knot)

    for index, knot in enumerate(v_knotvector):
        nurbs.KnotsV.Item[index] = knot

    return nurbs
Beispiel #8
0
 def data(self, data):
     points = [[Point.from_data(point) for point in row]
               for row in data['points']]
     weights = data['weights']
     u_knots = data['u_knots']
     v_knots = data['v_knots']
     u_mults = data['u_mults']
     v_mults = data['v_mults']
     u_degree = data['u_degree']
     v_degree = data['v_degree']
     is_u_periodic = data['is_u_periodic']
     is_v_periodic = data['is_v_periodic']
     self.occ_surface = Geom_BSplineSurface(array2_from_points2(points),
                                            array1_from_floats1(weights),
                                            array1_from_floats1(u_knots),
                                            array1_from_floats1(v_knots),
                                            array1_from_integers1(u_mults),
                                            array1_from_integers1(v_mults),
                                            u_degree, v_degree,
                                            is_u_periodic, is_v_periodic)
Beispiel #9
0
    def from_data(cls, data):
        """Construct a sphere from its data representation.

        Parameters
        ----------
        data : dict
            The data dictionary.

        Returns
        -------
        :class:`compas.geometry.Sphere`
            The constructed sphere.

        Examples
        --------
        >>> from compas.geometry import Sphere
        >>> data = {'point': [1., 2., 3.], 'radius': 4.}
        >>> sphere = Sphere.from_data(data)

        """
        sphere = cls(Point.from_data(data['point']), data['radius'])
        return sphere
Beispiel #10
0
    def from_data(cls, data):
        """Construct a NURBS curve from its data representation.

        Parameters
        ----------
        data : dict
            The data dictionary.

        Returns
        -------
        :class:`compas.geometry.NurbsCurve`
            The constructed curve.

        """
        points = [Point.from_data(point) for point in data['points']]
        weights = data['weights']
        knots = data['knots']
        multiplicities = data['multiplicities']
        degree = data['degree']
        is_periodic = data['is_periodic']
        return cls.from_parameters(points, weights, knots, multiplicities,
                                   degree, is_periodic)
Beispiel #11
0
 def data(self, data):
     self.point = Point.from_data(data['point'])
     self.radius = data['radius']
Beispiel #12
0
 def data(self, data):
     self._points = [Point.from_data(point) for point in data['points']]