Beispiel #1
0
    def notify(self, parent):
        if len(self._shapes) < 2:
            raise ValueError("'%s' requires at least two children" % self.tag)

        import instrument.geometry.operations as ops
        intersection = ops.intersect(*self._shapes)
        parent.onIntersection(intersection)
        return
 def test(self):
     """
     instrument.geometry.pml.render
     """
     from instrument.geometry.pml import render
     from instrument.geometry import shapes, operations
     cyl = shapes.cylinder(radius="1.*cm", height="5.*cm")
     sphere = shapes.sphere(radius="2.*cm")
     block = shapes.block(width="5*cm", height="4.*cm", thickness="1.*mm")
     u = operations.unite(cyl, sphere, block)
     t = operations.translate(u, vertical="0.2*cm")
     r = operations.rotate(t, vertical=1., angle=90.)
     pyramid = shapes.pyramid(width="4.*cm",
                              height="2.*cm",
                              thickness="1.*cm")
     i = operations.intersect(r, pyramid)
     cone = shapes.cone(radius="2.*cm", height="2.*cm")
     u = operations.unite(i, cone)
     sphere2 = shapes.sphere(radius="3.*cm")
     s = operations.subtract(sphere2, u)
     text = render(s, print_docs=False)
     print('\n'.join(text), file=open('test2.xml.rendered', 'w'))
     return
Beispiel #3
0
    def gen_one_col(self, collimator_Nosupport=True):
        pyr = self.solid_pyramid()

        big_cylinder = shapes.cylinder(radius='%s *mm' % (self.vertical_outer_radius),
                                       height='%s *mm' % (self.max_coll_height_detector * 10))

        big_box=self.generate_box_toIntersect_big_end()

        outside_sphere = shapes.sphere(radius='%s *mm' % self.vertical_outer_radius)


        channels=self.generate_collimator_channels()
        channels_border=self.generate_channels_border()

        conical_colli = operations.intersect(channels, pyr)

        conical_channels_border=operations.intersect(channels_border, pyr)


        cutoff_cylinder = shapes.cylinder(radius='%s *mm' % (self.inner_radius),
                                          height='%s *mm' % (self.max_coll_height_detector * 90.))

        blade_cutoff_cylinder = shapes.cylinder(radius='%s *mm' % (self.vertical_blade_dist_fr_sample_center),
                                          height='%s *mm' % (self.max_coll_height_detector * 10))



        cutoff_box = shapes.block(width='%s *mm' % (self.inner_radius*2), thickness='%s *mm' % (self.inner_radius*2),
                                          height='%s *mm' % (self.max_coll_height_detector * 90.))

        blade_cutoff_box = shapes.block(width='%s *mm' % (self.vertical_blade_dist_fr_sample_center*2),
                                        thickness='%s *mm' % (self.vertical_blade_dist_fr_sample_center*2),
                                                height='%s *mm' % (self.max_coll_height_detector * 10))


        # return (operations.subtract(conical_channels_border, cutoff_cylinder))

        if self.collimator_parts is True:
            open_collimator = operations.intersect(operations.subtract(conical_channels_border, cutoff_box),
                                                   big_box)

            collimator_with_blades = operations.intersect(operations.subtract(conical_colli, blade_cutoff_box),
                                                          big_box)

        else:
            open_collimator=operations.intersect(operations.subtract(conical_channels_border, cutoff_cylinder), big_box)



            collimator_with_blades = operations.intersect(operations.subtract(conical_colli, blade_cutoff_cylinder), big_box)


        collimator=operations.unite(open_collimator, collimator_with_blades)



        scale_pyr = 1.1
        pyr_ht = (self.horizontal_arc_length_detector / np.deg2rad(self.horizontal_acceptance_angle)) * scale_pyr

        thickness = (self.max_coll_height_detector + 1 * self.wall_thickness) * scale_pyr
        height = (self.horizontal_arc_length_detector / np.deg2rad(self.horizontal_acceptance_angle)) * scale_pyr
        width = (self.max_coll_width_detector + 1 * self.wall_thickness) * scale_pyr

        # pyr_ht = self.vertical_outer_radius * np.cos(np.deg2rad(self.horizontal_acceptance_angle/2.)) * scale_pyr
        pyr_lateral = shapes.pyramid(
            thickness='%s *mm' % (thickness),
            # height='%s *mm' % (height),
            height='%s *mm' % (height),
            width='%s *mm' % (width+900.))
        pyr_lateral = operations.rotate(pyr_lateral, transversal=1, angle='%s *degree' % (90))

        pyr_depth = shapes.pyramid(
            thickness='%s *mm' % (thickness+6900),
            # height='%s *mm' % (height),
            height='%s *mm' % (height),
            width='%s *mm' % (width ))
        pyr_depth = operations.rotate(pyr_depth, transversal=1, angle='%s *degree' % (90))

        # collimator_support = Collimator_support()
        # collimator_support.set_constraints(
        #     truss_base_thickness=30., trass_final_height_factor=0.45,
        #     touch_to_halfcircle=6, SNAP_acceptance_angle=False)
        #
        # supports = collimator_support.support()

        supports = self.support()


        support_top=operations.intersect(operations.subtract(supports, pyr_lateral), pyr_depth)



        # support_top =operations.subtract(self.support(), pyr_lateral)

        support_bottom=operations.rotate(operations.rotate(support_top, transversal=1, angle='%s *degree' %(-180)), vertical=1, angle='%s *degree' %180)


        supports=operations.subtract(operations.unite(support_top, support_bottom), cutoff_cylinder)

        if collimator_Nosupport is True:
            return(collimator)
        else:
            return(operations.unite(collimator,supports))
Beispiel #4
0
    def support(self):

        main_cylinder_radius = self.inner_radius * self.truss_height_factor

        main_cylinder_diameter = main_cylinder_radius * 2.

        height_support_main = main_cylinder_diameter - self.beam_dist_support

        base_width_support = self.truss_base_thickness

        cyli_radius = main_cylinder_radius * 2

        height_support = height_support_main

        cyli_dia = cyli_radius * 2.

        ################################################ cylinder_radius=self.inner_radius

        cylinder_radius = cyli_dia / 2.
        vertical_cylinder_height = cyli_dia + 100  ## big cylinder height should be greater than the cyli diameter

        suppert_end_distance_fr_source = self.inner_radius + base_width_support

        thickness_collimator_at_support_end = self.angle2span(
            suppert_end_distance_fr_source, self.vertical_acceptance_angle)

        height_factor = 1.
        height = thickness_collimator_at_support_end * height_factor

        cylinder = shapes.cylinder(radius='%s *mm' % (cylinder_radius),
                                   height='%s *mm' % (height * 2 + 10))

        cylinder_transversal = operations.rotate(cylinder,
                                                 beam=1,
                                                 angle='%s *degree' % 90)

        vertical_cylinder = shapes.cylinder(
            radius='%s *mm' % (cylinder_radius),
            height='%s *mm' % (vertical_cylinder_height))

        distance_fr_center_height_main = np.sqrt((main_cylinder_radius)**2 -
                                                 (height_support / 2)**2)

        angular_cut = self.span2angle(height_support,
                                      distance_fr_center_height_main) / 2.

        distance_fr_center_height = cylinder_radius * np.cos(
            np.deg2rad(angular_cut))

        vertical_cylinder_move_dist = abs(cylinder_radius -
                                          distance_fr_center_height)

        distance_fr_center_height = np.sqrt((cylinder_radius)**2 -
                                            (height_support / 2)**2)

        vertical_cylinder_move_dist = abs(cylinder_radius -
                                          distance_fr_center_height_main)

        unwanted_part_of_smallcircle0 = operations.subtract(
            cylinder_transversal,
            operations.translate(vertical_cylinder,
                                 beam='%s *mm' % -vertical_cylinder_move_dist))

        moving_dist_cylinder = 20

        # unwanted_part_of_smallcircle0= operations.translate(unwanted_part_of_smallcircle0, beam='%s *mm' %-moving_dist_cylinder)

        unwanted_part_of_bigcircle2 = operations.translate(
            unwanted_part_of_smallcircle0, beam='%s *mm' % (1))

        cylinder_radius = self.inner_radius

        cylinder_transversal_1_0 = operations.rotate(shapes.cylinder(
            radius='%s *mm' % (cylinder_radius),
            height='%s *mm' % ((height * 2))),
                                                     beam=1,
                                                     angle='%s *degree' % 90)

        # return(operations.unite(cylinder_transversal_1_0, operations.translate(vertical_cylinder, beam='%s *mm' % -vertical_cylinder_move_dist)))
        mod_cylinder_transversal = operations.subtract(
            cylinder_transversal_1_0, unwanted_part_of_smallcircle0)

        # return (operations.subtract(cylinder_transversal,operations.subtract(cylinder_transversal,operations.translate(vertical_cylinder, beam='%s *mm' % -vertical_cylinder_move_dist))))
        # return (operations.unite(cylinder_transversal_1_0,unwanted_part_of_smallcircle0 ))
        # return(mod_cylinder_transversal)
        # return (vertical_cylinder)
        # return (operations.subtract(vertical_cylinder, cylinder_transversal))

        ########################################################################################################################################
        #########################################################################################################################################

        solid_shape = mod_cylinder_transversal

        cylinder_transversal = mod_cylinder_transversal  ## small inside cylinder

        cylinder_2 = shapes.cylinder(
            radius='%s *mm' %
            (cylinder_radius + 1),  ###big cylinder (outside cylinder)
            height='%s *mm' % (height * 2))

        cylinder_transversal_2_0 = operations.rotate(cylinder_2,
                                                     beam=1,
                                                     angle='%s *degree' % 90)

        cylinder_transversal_2 = operations.subtract(
            cylinder_transversal_2_0, unwanted_part_of_bigcircle2)

        width_factor = 2.

        big_block = shapes.block(
            height='%s *mm' % cyli_dia,
            width='%s *mm' % (suppert_end_distance_fr_source * width_factor),
            thickness='%s *mm' % (height))

        big_block_rotate = operations.rotate(big_block,
                                             vertical=1,
                                             angle='%s *degree' % 90)

        big_block_2 = shapes.block(
            height='%s *mm' % (cyli_dia - 1),
            width='%s *mm' %
            ((suppert_end_distance_fr_source * width_factor) - 2),
            thickness='%s *mm' % (height + 1))  #### small blog

        big_block_rotate_2 = operations.rotate(big_block_2,
                                               vertical=1,
                                               angle='%s *degree' % 90)

        parts = operations.subtract(big_block_rotate, cylinder_transversal)

        # return(operations.unite(big_block_rotate, cylinder_transversal))

        # return(big_block_rotate)

        parts_2 = operations.subtract(big_block_rotate_2,
                                      cylinder_transversal_2)

        parts_frame = operations.subtract(parts, parts_2)

        # parts_frame=operations.unite(parts_frame, solid_shape)

        # return (parts_frame)
        # return (operations.subtract(parts_frame,parts_2))

        # return operations.unite(cylinder_transversal_1_0,unwanted_part_of_smallcircle0)
        # return(operations.unite(cylinder_transversal, cylinder_transversal_2))

        blades_in_frames = operations.subtract(self.support_design(),
                                               cylinder_transversal)

        parts_frame_blades_pre = operations.unite(parts_frame,
                                                  blades_in_frames)

        parts_frame_blades_pre = parts_frame

        # return (parts_frame_blades_pre)
        #############################################################CHANGES#####################################################
        #########################################################################################################################

        # solid=operations.subtract(vertical_cylinder, unwanted_part_of_bigcircle2)
        #
        # parts_frame_blades_pre = operations.unite(parts_frame_blades_pre, solid)

        side_cut_box = operations.translate(operations.rotate(
            shapes.block(height='%s *mm' % cyli_dia,
                         width='%s *mm' %
                         (suppert_end_distance_fr_source * width_factor),
                         thickness='%s *mm' % (height * 2)),
            vertical=1,
            angle='%s *degree' % 90),
                                            beam='%s *mm' %
                                            -(suppert_end_distance_fr_source))

        up_cut_box = operations.translate(
            operations.rotate(shapes.block(
                height='%s *mm' % cyli_dia,
                width='%s *mm' %
                ((suppert_end_distance_fr_source * width_factor) + 1),
                thickness='%s *mm' % (height * 2)),
                              vertical=1,
                              angle='%s *degree' % 90),
            vertical='%s *mm' % (cyli_dia / 2.))  ########################

        down_cut_box = operations.translate(operations.rotate(
            shapes.block(height='%s *mm' % cyli_dia,
                         width='%s *mm' %
                         ((suppert_end_distance_fr_source * width_factor) + 1),
                         thickness='%s *mm' % (height * 2)),
            vertical=1,
            angle='%s *degree' % 90),
                                            vertical='%s *mm' %
                                            (-(cyli_dia - 2)))

        parts_frame_blades = operations.subtract(
            operations.subtract(
                operations.subtract(parts_frame_blades_pre, side_cut_box),
                up_cut_box), down_cut_box)

        parts_frame_blades = operations.unite(parts_frame_blades,
                                              blades_in_frames)

        parts_frame_blades = operations.subtract(
            operations.subtract(parts_frame_blades, side_cut_box),
            down_cut_box)

        # return (parts_frame_blades)

        thickness_parts = ((suppert_end_distance_fr_source * width_factor) -
                           (self.inner_radius)) / 2

        parts_move_beam = operations.translate(
            parts_frame_blades,
            beam='%s *mm' %
            (-(self.inner_radius) * 2 - base_width_support + 1))
        angle = self.vertical_acceptance_angle  # 15
        # parts_move_up = operations.translate(parts_move_beam, vertical='%s *mm' % (
        #             self.inner_radius + (
        #                 self.curvature * self.inner_radius * np.tan(np.deg2rad(angle/2.)))))

        parts_move_up = operations.translate(
            parts_move_beam,
            vertical='%s *mm' %
            (self.inner_radius +
             (self.curvature * (self.inner_radius * 2. + base_width_support) *
              np.tan(np.deg2rad(angle / 2.)))))

        # return (parts_move_up)
        # return(parts_frame)
        return (operations.intersect(
            parts_move_up,
            self.generate_box_toCut_big_end(
                width=self.max_coll_height_detector *
                self.trass_final_height_factor,
                height=(self.inner_radius * 2. + base_width_support + 100.))))