Exemplo n.º 1
0
def triangle_in_sample_even(vertices, facet, radius):
    """
	for as even as possible only sample the points in the triangle return the samples
	"""
    bdy_box = geometry.get_bounding_box(vertices)
    # get the origins of the rays
    origin = np.mgrid[bdy_box[0][0]:(bdy_box[0][0] + bdy_box[1][0]):radius,
                      bdy_box[0][1]:(bdy_box[0][1] + bdy_box[1][1]):radius,
                      bdy_box[0][2]:(bdy_box[0][2] + 0.1):1.].reshape(3, -1).T
    direction = np.array([0., 0., 1.])
    sect_info = [
        ray.ray_trimesh_intersect_all(vertices, facet, origin[k], direction)
        for k in range(len(origin))
    ]
    samples = []
    for k in range(len(origin)):
        if sect_info[k][0] == False:
            continue
        tvalue = sect_info[k][1]
        pair_num = len(tvalue) / 2
        for j in range(pair_num):
            sample_num = int((tvalue[2 * j + 1] - tvalue[2 * j]) / radius)
            if np.rint(sample_num) < 2.0:
                continue
            for i in range(1, sample_num):
                samples.append(
                    (origin[k] + (tvalue[2 * j] + radius * i) * direction))
    return samples
Exemplo n.º 2
0
 def __export_graph(self, mode, include_labels):
     """Export the current design as a graph"""
     regraph_graph = Regraph(
         reconstruction=self.design_state.reconstruction,
         logger=self.logger,
         mode=mode,
         use_temp_id=True,
         include_labels=include_labels
     )
     graph = regraph_graph.generate_from_bodies(
         self.design_state.reconstruction.bRepBodies
     )
     bbox = geometry.get_bounding_box(self.design_state.reconstruction)
     bbox_data = serialize.bounding_box3d(bbox)
     return {
         "graph": graph,
         "bounding_box": bbox_data
     }
Exemplo n.º 3
0
    def set_target(self, data):
        """Set the target design"""
        data_file, error = self.check_file(data, [".step", ".stp", ".smt"])
        suffix = data_file.suffix
        if error is not None:
            return self.runner.return_failure(error)
        # self.design.designType = adsk.fusion.DesignTypes.ParametricDesignType
        # Create the file locally
        temp_file = self.get_temp_file(data["file"])
        with open(temp_file, "w") as f:
            f.write(data["file_data"])
        # We clear the design before importing
        # This also clears the local state
        self.design_state.clear()
        self.design_state.set_target(temp_file)

        # Use temp_ids
        regraph_graph = Regraph(
            reconstruction=self.design_state.reconstruction,
            logger=self.logger,
            mode="PerFace",
            use_temp_id=True,
            include_labels=False)
        self.state["target_graph"] = regraph_graph.generate_from_bodies(
            self.design_state.target.bRepBodies)
        bbox = geometry.get_bounding_box(self.design_state.target)
        self.state["target_bounding_box"] = serialize.bounding_box3d(bbox)
        temp_file.unlink()
        # Setup the reconstructor
        self.state["reconstructor"] = FaceReconstructor(
            target=self.design_state.target,
            reconstruction=self.design_state.reconstruction)
        return self.runner.return_success({
            "graph":
            self.state["target_graph"],
            "bounding_box":
            self.state["target_bounding_box"]
        })
Exemplo n.º 4
0
def triangle_volume_sample_even(vertices, facet, radius):
    """
	for as even as possible to sample the volume 
	basic idea is first get the bounding box of the mesh
	and then emit parallel ray from the bottom of the bounding box(the direction is parallel with z positive axis)
	and get the intersections of the ray and mesh
	get the points in the mesh is equal to get the points in the each two intersections
	the intersections will be regarded as the surface samples, and the points in the mesh will be regarded as the volume sumples
	this sample method is specificly useful for constructing a mass spring sysytem from a triangle mesh
	return: surface samples,volume samples
	"""
    bdy_box = geometry.get_bounding_box(vertices)
    # get the origins of the rays
    origin = np.mgrid[bdy_box[0][0]:(bdy_box[0][0] + bdy_box[1][0]):radius,
                      bdy_box[0][1]:(bdy_box[0][1] + bdy_box[1][1]):radius,
                      bdy_box[0][2]:(bdy_box[0][2] + 0.1):1.].reshape(3, -1).T
    direction = np.array([0., 0., 1.])
    sect_info = [
        ray.ray_trimesh_intersect_all(vertices, facet, origin[k], direction)
        for k in range(len(origin))
    ]
    ssamples = []
    vsamples = []
    for k in range(len(origin)):
        if sect_info[k][0] == False:
            continue
        tvalue = sect_info[k][1]
        pair_num = len(tvalue) / 2
        for j in range(pair_num):
            ssamples.append((origin[k] + tvalue[2 * j] * direction))
            ssamples.append((origin[k] + tvalue[2 * j + 1] * direction))
            sample_num = int((tvalue[2 * j + 1] - tvalue[2 * j]) / radius)
            if sample_num < 2:
                continue
            for i in range(1, sample_num):
                vsamples.append(
                    (origin[k] + (tvalue[2 * j] + radius * i) * direction))
    return ssamples, vsamples
 def return_extrude_data(self, extrude):
     """Return data from an extrude operation"""
     regraph = Regraph(reconstruction=self.design_state.reconstruction,
                       logger=self.logger,
                       mode="PerFace",
                       use_temp_id=True,
                       include_labels=False)
     return_data = {}
     # Info on the extrude
     return_data["extrude"] = serialize.extrude_feature_brep(extrude)
     # Generate the graph from the reconstruction component
     return_data["graph"] = regraph.generate_from_bodies(
         self.design_state.reconstruction.bRepBodies)
     # Calculate the IoU
     if self.design_state.target is not None:
         return_data["iou"] = geometry.intersection_over_union(
             self.design_state.target, self.design_state.reconstruction)
         if return_data["iou"] is None:
             self.logger.log("Warning! IoU calculation returned None")
     # Bounding box of the reconstruction component
     bbox = geometry.get_bounding_box(self.design_state.reconstruction)
     return_data["bounding_box"] = serialize.bounding_box3d(bbox)
     return self.runner.return_success(return_data)