コード例 #1
0
    def __init__(self, slicer, parameters, DATA_PATH):
        assert isinstance(slicer, compas_slicer.slicers.InterpolationSlicer
                          ), 'Please provide an InterpolationSlicer'
        BasePrintOrganizer.__init__(self, slicer)
        self.DATA_PATH = DATA_PATH
        self.OUTPUT_PATH = utils.get_output_directory(DATA_PATH)
        self.parameters = parameters

        self.vertical_layers = slicer.vertical_layers
        self.horizontal_layers = slicer.horizontal_layers
        assert len(self.vertical_layers) + len(self.horizontal_layers) == len(
            slicer.layers)

        if len(self.horizontal_layers) > 0:
            assert len(
                self.horizontal_layers
            ) == 1, "Only one brim horizontal layer is currently supported."
            assert self.horizontal_layers[
                0].is_brim, "Only one brim horizontal layer is currently supported."
            logger.info('Slicer has one horizontal brim layer.')

        # topological sorting of vertical layers depending on their connectivity
        self.topo_sort_graph = None
        if len(self.vertical_layers) > 1:
            self.topological_sorting()
        self.selected_order = None

        # creation of one base boundary per vertical_layer
        self.base_boundaries = self.create_base_boundaries()
コード例 #2
0
 def __init__(self, mesh, segments, max_d_threshold, DATA_PATH):
     self.mesh = mesh
     self.segments = segments
     self.max_d_threshold = max_d_threshold
     self.DATA_PATH = DATA_PATH
     self.OUTPUT_PATH = utils.get_output_directory(DATA_PATH)
     DirectedGraph.__init__(self)
コード例 #3
0
    def __init__(self, mesh, parameters, DATA_PATH):
        self.mesh = mesh
        self.parameters = parameters
        self.DATA_PATH = DATA_PATH

        self.OUTPUT_PATH = utils.get_output_directory(DATA_PATH)
        self.target_LOW = None  # :class: 'compas_slicer.pre_processing.CompoundTarget'
        self.target_HIGH = None  # :class: 'compas_slicer.pre_processing.CompoundTarget'

        self.split_meshes = []  # list , :class: 'compas.datastructures.Mesh'
        # The meshes that result from the region splitting process.

        utils.utils.check_triangular_mesh(mesh)
コード例 #4
0
    def __init__(self, mesh, target_LOW, target_HIGH, DATA_PATH):
        self.mesh = mesh  # compas mesh
        self.DATA_PATH = DATA_PATH
        self.OUTPUT_PATH = utils.get_output_directory(DATA_PATH)
        self.target_LOW, self.target_HIGH = target_LOW, target_HIGH

        assign_interpolation_distance_to_mesh_vertices(
            self.mesh,
            weight=0.5,
            target_LOW=self.target_LOW,
            target_HIGH=self.target_HIGH)
        g_evaluation = GradientEvaluation(self.mesh, self.DATA_PATH)
        g_evaluation.find_critical_points(
        )  # First estimation of saddle points with weight = 0.5
        self.saddles = g_evaluation.saddles
        self.cut_indices = []
コード例 #5
0
    def __init__(self, slicer, parameters, DATA_PATH):
        assert isinstance(slicer, compas_slicer.slicers.ScalarFieldSlicer), 'Please provide a ScalarFieldSlicer'
        BasePrintOrganizer.__init__(self, slicer)
        self.DATA_PATH = DATA_PATH
        self.OUTPUT_PATH = utils.get_output_directory(DATA_PATH)
        self.parameters = parameters

        self.vertical_layers = slicer.vertical_layers
        self.horizontal_layers = slicer.horizontal_layers
        assert len(self.vertical_layers) + len(self.horizontal_layers) == len(slicer.layers)

        if len(self.horizontal_layers) > 0:
            assert len(self.horizontal_layers) == 1, "Only one brim horizontal layer is currently supported."
            assert self.horizontal_layers[0].is_brim, "Only one brim horizontal layer is currently supported."
            logger.info('Slicer has one horizontal brim layer.')

        self.g_evaluation = self.add_gradient_to_vertices()
コード例 #6
0
    def __init__(self, mesh, DATA_PATH):
        for v_key, data in mesh.vertices(data=True):
            assert 'scalar_field' in data, "Vertex %d does not have the attribute 'scalar_field'"

        print('')
        logger.info('Gradient evaluation')
        self.mesh = mesh
        self.DATA_PATH = DATA_PATH
        self.OUTPUT_PATH = utils.get_output_directory(DATA_PATH)

        self.minima, self.maxima, self.saddles = [], [], []

        self.face_gradient = [
        ]  # np.array (#F x 3) one gradient vector per face.
        self.vertex_gradient = [
        ]  # np.array (#V x 3) one gradient vector per vertex.
        self.face_gradient_norm = []  # list (#F x 1)
        self.vertex_gradient_norm = []  # list (#V x 1)
コード例 #7
0
    def __init__(self, mesh, v_attr, value, DATA_PATH, union_method='min', union_params=[],
                 geodesics_method='exact_igl', anisotropic_scaling=False):

        logger.info('Creating target with attribute : ' + v_attr + '=%d' % value)
        logger.info('union_method : ' + union_method + ', union_params =  ' + str(union_params))
        self.mesh = mesh
        self.v_attr = v_attr
        self.value = value
        self.DATA_PATH = DATA_PATH
        self.OUTPUT_PATH = utils.get_output_directory(DATA_PATH)

        self.union_method = union_method
        self.union_params = union_params

        self.geodesics_method = geodesics_method
        self.anisotropic_scaling = anisotropic_scaling  # Anisotropic scaling not yet implemented

        self.offset = 0
        self.VN = len(list(self.mesh.vertices()))

        # filled in by function 'self.find_targets_connected_components()'
        self.all_target_vkeys = []  # flattened list with all vi_starts
        self.clustered_vkeys = []  # nested list with all vi_starts
        self.number_of_boundaries = None  # int

        self.weight_max_per_cluster = []

        # geodesic distances
        # filled in by function 'self.update_distances_lists()'
        self._distances_lists = []  # nested list. Shape: number_of_boundaries x number_of_vertices
        self._distances_lists_flipped = []  # nested list. Shape: number_of_vertices x number_of_boundaries
        self._np_distances_lists_flipped = np.array([])  # numpy array of self._distances_lists_flipped
        self._max_dist = None  # maximum get_distance value from the target on any vertex of the mesh

        # compute
        self.find_targets_connected_components()
        self.compute_geodesic_distances()
コード例 #8
0
 def __init__(self, all_meshes, DATA_PATH):
     self.all_meshes = all_meshes
     self.DATA_PATH = DATA_PATH
     self.OUTPUT_PATH = utils.get_output_directory(DATA_PATH)
     DirectedGraph.__init__(self)
コード例 #9
0
from compas_view2 import app

from compas.datastructures import Mesh
from compas.geometry import Point

# ==============================================================================
# Logging
# ==============================================================================
logger = logging.getLogger('logger')
logging.basicConfig(format='%(levelname)s-%(message)s', level=logging.INFO)

# ==============================================================================
# Select location of data folder and specify model to slice
# ==============================================================================
DATA = os.path.join(os.path.dirname(__file__), 'data')
OUTPUT_DIR = utils.get_output_directory(
    DATA)  # creates 'output' folder if it doesn't already exist
MODEL = 'simple_vase_open_low_res.obj'


def main():
    start_time = time.time()

    # ==========================================================================
    # Load mesh
    # ==========================================================================
    compas_mesh = Mesh.from_obj(os.path.join(DATA, MODEL))

    # ==========================================================================
    # Move to origin
    # ==========================================================================
    move_mesh_to_point(compas_mesh, Point(0, 0, 0))
コード例 #10
0
import os
from compas.geometry import Point, Vector, distance_point_plane, normalize_vector
from compas.datastructures import Mesh
import compas_slicer.utilities as slicer_utils
from compas_slicer.post_processing import simplify_paths_rdp_igl
from compas_slicer.slicers import PlanarSlicer
import compas_slicer.utilities.utils as utils
from compas_slicer.utilities.attributes_transfer import transfer_mesh_attributes_to_printpoints
from compas_slicer.print_organization import PlanarPrintOrganizer
import numpy as np

logger = logging.getLogger('logger')
logging.basicConfig(format='%(levelname)s-%(message)s', level=logging.INFO)

DATA_PATH = os.path.join(os.path.dirname(__file__), 'data')
OUTPUT_PATH = slicer_utils.get_output_directory(DATA_PATH)
MODEL = 'distorted_v_closed_low_res.obj'

if __name__ == '__main__':
    # load mesh
    mesh = Mesh.from_obj(os.path.join(DATA_PATH, MODEL))

    # --------------- Add attributes to mesh
    # Face attributes can be anything (ex. float, bool, array, text ...)
    # Vertex attributes can only be entities that can be meaningfully multiplied with a float (ex. float, np.array ...)

    # overhand attribute - Scalar value (per face)
    mesh.update_default_face_attributes({'overhang': 0.0})
    for f_key, data in mesh.faces(data=True):
        face_normal = mesh.face_normal(f_key, unitized=True)
        data['overhang'] = Vector(0.0, 0.0, 1.0).dot(face_normal)
コード例 #11
0
import os
from compas.datastructures import Mesh
import logging
import compas_slicer.utilities as utils
from compas_slicer.slicers import CurvedSlicer
from compas_slicer.post_processing import simplify_paths_rdp
from compas_slicer.pre_processing import CurvedSlicingPreprocessor
from compas_slicer.pre_processing import create_mesh_boundary_attributes
from compas_slicer.print_organization import set_extruder_toggle
from compas_slicer.print_organization import add_safety_printpoints
from compas_slicer.print_organization import set_linear_velocity
from compas_slicer.print_organization import set_blend_radius
from compas_slicer.print_organization import CurvedPrintOrganizer
import time

logger = logging.getLogger('logger')
logging.basicConfig(format='%(levelname)s - %(message)s', level=logging.INFO)

DATA_PATH = os.path.join(os.path.dirname(__file__), 'data')
OUTPUT_PATH = utils.get_output_directory(DATA_PATH)
OBJ_INPUT_NAME = os.path.join(DATA_PATH, '_mesh.obj')