Пример #1
0
def create_roi():
    """ Attempts to create the region ROI. This places the center of the ROI region """
    # """at the midpoint of all of the scale bar markers. """
    # """NOTE: This doesn't actually do anything yet."""
    x_axis, y_axis, z_axis = 0, 0, 0
    for chunk in PhotoScan.app.document.chunks:
        if chunk.label == 'Aligned Side A':
            x_axis, y_axis, z_axis = 0, 0, 0
            num_markers = chunk.markers.__len__()
            for marker in chunk.markers:
                x_axis += marker.position.x
                y_axis += marker.position.y
                z_axis += marker.position.z

            cent_x = x_axis / num_markers
            cent_y = y_axis / num_markers
            cent_z = z_axis / num_markers

            newregion = PhotoScan.Region()
            newregion.size = chunk.region.size
            newregion.rot = chunk.region.rot
            newregion.center = PhotoScan.Vector([cent_x, cent_y, cent_z])
            chunk.region = newregion
    def splitChunks(self):

        self.gridX = self.spinX.value()
        self.gridY = self.spinY.value()
        partsX = self.gridX
        partsY = self.gridY

        print("Script started...")

        buildMesh = self.chkMesh.isChecked()
        buildDense = self.chkDense.isChecked()
        mergeBack = self.chkMerge.isChecked()
        autosave = self.chkSave.isChecked()

        quality = DENSE[self.denseBox.currentText()]
        mesh_mode = MESH[self.meshBox.currentText()]

        doc = PhotoScan.app.document
        chunk = doc.chunk

        if not chunk.transform.translation.norm():
            chunk.transform.matrix = chunk.transform.matrix
        elif chunk.transform.scale == 1:
            chunk.transform.matrix = chunk.transform.matrix
        elif isIdent(chunk.transform.rotation):
            chunk.transform.matrix = chunk.transform.matrix

        region = chunk.region
        r_center = region.center
        r_rotate = region.rot
        r_size = region.size

        x_scale = r_size.x / partsX
        y_scale = r_size.y / partsY
        z_scale = r_size.z

        offset = r_center - r_rotate * r_size / 2.

        for j in range(1, partsY +
                       1):  # creating new chunks and adjusting bounding box
            for i in range(1, partsX + 1):
                if not buildDense:
                    new_chunk = chunk.copy(items=[
                        PhotoScan.DataSource.DenseCloudData,
                        PhotoScan.DataSource.DepthMapsData
                    ])
                else:
                    new_chunk = chunk.copy(items=[])
                new_chunk.label = "Chunk " + str(i) + "\\" + str(j)
                if new_chunk.model:
                    new_chunk.model.clear()

                new_region = PhotoScan.Region()
                new_rot = r_rotate
                new_center = PhotoScan.Vector([(i - 0.5) * x_scale,
                                               (j - 0.5) * y_scale,
                                               0.5 * z_scale])
                new_center = offset + new_rot * new_center
                new_size = PhotoScan.Vector([x_scale, y_scale, z_scale])

                if self.edtOvp.text().isdigit():
                    new_region.size = new_size * (
                        1 + float(self.edtOvp.text()) / 100)
                else:
                    new_region.size = new_size

                new_region.center = new_center
                new_region.rot = new_rot

                new_chunk.region = new_region

                PhotoScan.app.update()

                if autosave:
                    doc.save()

                if buildDense:
                    if new_chunk.depth_maps:
                        reuse_depth = True
                        if new_chunk.depth_maps.meta['depth/depth_downscale']:
                            quality = QUALITY[new_chunk.depth_maps.
                                              meta['depth/depth_downscale']]
                        if new_chunk.depth_maps.meta[
                                'depth/depth_filter_mode']:
                            filtering = FILTERING[new_chunk.depth_maps.meta[
                                'depth/depth_filter_mode']]
                        try:
                            new_chunk.buildDepthMaps(quality=quality,
                                                     filter=filtering,
                                                     reuse_depth=reuse_depth)
                            new_chunk.buildDenseCloud(
                                max_neighbors=100)  # keep_depth=False
                        except RuntimeError:
                            print("Can't build dense cloud for " + chunk.label)

                    else:
                        reuse_depth = False
                        try:
                            new_chunk.buildDepthMaps(
                                quality=quality,
                                filter=PhotoScan.FilterMode.
                                AggressiveFiltering,
                                reuse_depth=reuse_depth)
                            new_chunk.buildDenseCloud(
                                max_neighbors=100)  # keep_depth=False
                        except RuntimeError:
                            print("Can't build dense cloud for " + chunk.label)

                    if autosave:
                        doc.save()

                if buildMesh:
                    if new_chunk.dense_cloud:
                        try:
                            new_chunk.buildModel(
                                surface=mesh_mode,
                                source=PhotoScan.DataSource.DenseCloudData,
                                interpolation=PhotoScan.Interpolation.
                                EnabledInterpolation,
                                face_count=PhotoScan.FaceCount.HighFaceCount)
                        except RuntimeError:
                            print("Can't build mesh for " + chunk.label)
                    else:
                        try:
                            new_chunk.buildModel(
                                surface=mesh_mode,
                                source=PhotoScan.DataSource.PointCloudData,
                                interpolation=PhotoScan.Interpolation.
                                EnabledInterpolation,
                                face_count=PhotoScan.FaceCount.HighFaceCount)
                        except RuntimeError:
                            print("Can't build mesh for " + chunk.label)
                    if autosave:
                        doc.save()

                if not buildDense:
                    if new_chunk.dense_cloud:
                        new_chunk.dense_cloud.clear()
                if new_chunk.depth_maps:
                    new_chunk.depth_maps.clear()
                # new_chunk = None

        if mergeBack:
            for i in range(1, len(doc.chunks)):
                chunk = doc.chunks[i]
                chunk.remove(chunk.cameras)
            doc.chunks[
                0].model = None  # hiding the mesh of the original chunk, just for case
            doc.mergeChunks(doc.chunks,
                            merge_dense_clouds=True,
                            merge_models=True,
                            merge_markers=True
                            )  # merging all smaller chunks into single one

            doc.remove(doc.chunks[1:-1])  # removing smaller chunks.
            if autosave:
                doc.save()

        if autosave:
            doc.save()

        print("Script finished!")
        return True
    def splitChunks(self):

        self.gridX = self.spinX.value()
        self.gridY = self.spinY.value()
        partsX = self.gridX
        partsY = self.gridY

        print("Script started")

        buildMesh = self.chkMesh.isChecked()
        buildDense = self.chkDense.isChecked()
        mergeBack = self.chkMerge.isChecked()

        doc = PhotoScan.app.document
        chunk = doc.chunk

        region = chunk.region
        r_center = region.center
        r_rotate = region.rot
        r_size = region.size

        x_scale = r_size.x / partsX
        y_scale = r_size.y / partsY
        z_scale = r_size.z

        offset = r_center - r_rotate * r_size /2.

        for j in range(1, partsY + 1):  #creating new chunks and adjusting bounding box
            for i in range(1, partsX + 1):
                new_chunk = chunk.copy()
                new_chunk.label = "Chunk "+ str(i)+ "\\" + str(j)
                new_chunk.model = None
                doc.addChunk(new_chunk)

                new_region = PhotoScan.Region()
                new_rot = r_rotate
                new_center = PhotoScan.Vector([(i - 0.5) * x_scale, (j - 0.5) * y_scale, 0.5 * z_scale])
                new_center = offset + new_rot * new_center
                new_size = PhotoScan.Vector([x_scale, y_scale, z_scale])
                new_region.size = new_size
                new_region.center = new_center
                new_region.rot = new_rot

                new_chunk.region = new_region

                PhotoScan.app.update()

                if buildDense:
                    new_chunk.buildDenseCloud(quality = PhotoScan.Quality.MediumQuality, filter = PhotoScan.FilterMode.AggressiveFiltering)

                if buildMesh:
                    if new_chunk.dense_cloud:
                        new_chunk.buildModel(surface = PhotoScan.SurfaceType.HeightField, source = PhotoScan.PointsSource.DensePoints, interpolation = PhotoScan.Interpolation.EnabledInterpolation, face_count = PhotoScan.FaceCount.HighFaceCount)
                    else:
                        new_chunk.buildModel(surface = PhotoScan.SurfaceType.HeightField, source = PhotoScan.PointsSource.SparsePoints, interpolation = PhotoScan.Interpolation.EnabledInterpolation, face_count = PhotoScan.FaceCount.HighFaceCount)

                new_chunk.depth_maps = None

        if mergeBack:
            for i in range(1, len(doc.chunks)):
                chunk = doc.chunks[i]
                chunk.remove(chunk.cameras)
            doc.chunks[0].model = None #removing model from original chunk, just for case
            doc.mergeChunks(doc.chunks, merge_dense_clouds = True, merge_models = True, merge_markers = True) #merging all smaller chunks into single one
            doc.remove(doc.chunks[1:-1]) #removing smaller chunks.

        print("Script finished")
        return True