From b984807d99328ff9d5813d8b9305cc92f515645e Mon Sep 17 00:00:00 2001 From: cjd24 Date: Mon, 26 Feb 2018 00:36:01 +0000 Subject: Adding script to get Jxr conversion lib, and all my current C code for extracting and converting czi files to normal things --- src/conversion/czi/convertJxrs.py | 38 +++ src/conversion/czi/czi.ts | 0 src/conversion/czi/cziConvert.sh | 10 + src/conversion/czi/cziSegmentHeaders.h | 458 +++++++++++++++++++++++++++++++++ src/conversion/czi/cziconvert.c | 354 +++++++++++++++++++++++++ 5 files changed, 860 insertions(+) create mode 100644 src/conversion/czi/convertJxrs.py create mode 100644 src/conversion/czi/czi.ts create mode 100755 src/conversion/czi/cziConvert.sh create mode 100644 src/conversion/czi/cziSegmentHeaders.h create mode 100644 src/conversion/czi/cziconvert.c (limited to 'src') diff --git a/src/conversion/czi/convertJxrs.py b/src/conversion/czi/convertJxrs.py new file mode 100644 index 0000000..d19a59a --- /dev/null +++ b/src/conversion/czi/convertJxrs.py @@ -0,0 +1,38 @@ +from concurrent.futures import ThreadPoolExecutor +from subprocess import check_call +from glob import glob +from sys import argv + +totalFiles = 0 +coutner = 0 + + +def convertjxrs(filename): + global counter + global totalFiles + asTif = filename.rsplit('.',1)[0] + ".tif" + check_call(['./JxrDecApp', "-i", filename, "-o", asTif]) + check_call(['convert', asTif, filename.rsplit('.',1)[0] + ".png"]) + check_call(['rm', filename, asTif]) + counter += 1 + print (f"> Processed File: {counter}/{totalFiles} : {filename} --> {filename.rsplit('.',1)[0]}.png") + + +if __name__ == "__main__": + + if (len(argv) != 2): + print("\nMissing Argument!\n\nUsage:\npython3 convertJxrs.py ") + exit(0) + else: + print("=========== BEGIN JXR CONVERSION ===========") + print ('Files Dir: ' + argv[1] + '\n') + + filenames = glob(argv[1] + 'data-*.jxr') + counter = 0 + totalFiles = len(filenames) + + pool = ThreadPoolExecutor(5) + for f in pool.map(convertjxrs, filenames): + pass + pool.shutdown(True) + print("=========== FINISH JXR CONVERSION ===========") diff --git a/src/conversion/czi/czi.ts b/src/conversion/czi/czi.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/conversion/czi/cziConvert.sh b/src/conversion/czi/cziConvert.sh new file mode 100755 index 0000000..639251c --- /dev/null +++ b/src/conversion/czi/cziConvert.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +CZI_WORKING_DIR=${1:-"/cs/scratch"} +CZI_EXTRACTION_DIR=${2:-"0701-extraction"} +CZI_FILE=${3:-"2016_12_17__0701.czi"} + +gcc -Wall -Wextra --pedantic -std=c99 cziconvert.c +mkdir -p ${CZI_WORKING_DIR}/${USER}/${CZI_EXTRACTION_DIR} +./a.out ${CZI_WORKING_DIR}/${USER}/${CZI_FILE} ${CZI_WORKING_DIR}/${USER}/${CZI_EXTRACTION_DIR}/ ${PWD}/convertJxrs.py +rm ./a.out diff --git a/src/conversion/czi/cziSegmentHeaders.h b/src/conversion/czi/cziSegmentHeaders.h new file mode 100644 index 0000000..3ed0c60 --- /dev/null +++ b/src/conversion/czi/cziSegmentHeaders.h @@ -0,0 +1,458 @@ +#include +#include + +typedef uuid_t GUID; +extern char extractDirName[100]; + + +//START FILE WRITER //////////////////////////////////////////////////////////// +void writeDataToFile(const char* filename, int fileCount, const char* optionalFileExtension, void* content, long contentSize) { + FILE* outputFile; + char outputFileName[150]; + sprintf(outputFileName, "%s%s%d%s", extractDirName, filename, fileCount, optionalFileExtension); + if ((outputFile = fopen(outputFileName, "w"))==NULL){ + printf("Write error occurred, check file path."); + exit(1); + } + fwrite(content, 1, contentSize, outputFile); + fclose(outputFile); +} +//END FILE WRITER ////////////////////////////////////////////////////////////// + + + +//START SEGMENT HEADERS///////////////////////////////////////////////////////// +typedef struct { + char name[16]; + uint64_t allocated_size; + uint64_t used_size; +} __attribute__ ((__packed__)) SegmentHeader; + +void printSegmentHeader(SegmentHeader* header) { + printf("name: %s\n", header->name); + printf("allocated_size: %" PRIu64 "\n", header->allocated_size); + printf("used_size: %" PRIu64 "\n", header->used_size); + printf("\n"); +} +void writeSegmentHeader(SegmentHeader* header, FILE* outputFile) { + fprintf(outputFile, "\"Id\": \"%s\",\n", header->name); + fprintf(outputFile, "\"AllocatedSize\": %" PRIu64 ",\n", header->allocated_size); + fprintf(outputFile, "\"UsedSize\": %" PRIu64 ",\n", header->used_size); + fprintf(outputFile, "\"Data\": \n"); +} +//END SEGMENT HEADERS/////////////////////////////////////////////////////////// + + + +//START ZISRAWFILE ///////////////////////////////////////////////////////////// +typedef struct { + uint32_t major; + uint32_t minor; + uint32_t reserved1; + uint32_t reserved2; + GUID primary_file_guid; + GUID file_guid; + uint32_t file_part; + uint64_t directory_position; + uint64_t metadata_position; + uint32_t update_pending; + uint64_t attachment_directory_potition; +} __attribute__ ((__packed__)) ZisrawFile; + +void printZisrawFile(ZisrawFile* header) { + printf("major: %" PRIu32 "\n", header->major); + printf("minor: %" PRIu32 "\n", header->minor); + printf("reserved1: %" PRIu32 "\n", header->reserved1); + printf("reserved2: %" PRIu32 "\n", header->reserved2); + printf("primary_file_guid: "); + for (int i = 0; i < 16; i++) { + printf("%u ",header->primary_file_guid[i]); + } + printf("\nfile_guid: "); + for (int i = 0; i < 16; i++) { + printf("%u ",header->file_guid[i]); + } + printf("\nfile_part: %" PRIu32 "\n", header->file_part); + printf("directory_position: %" PRIu64 "\n", header->directory_position); + printf("metadata_position: %" PRIu64 "\n", header->metadata_position); + printf("update_pending: %" PRIu32 "\n", header->update_pending); + printf("attachment_directory_potition: %" PRIu64 "\n", header->attachment_directory_potition); + printf("\n"); +} +void writeZisrawFile(ZisrawFile* header, FILE* outputFile) { + fprintf(outputFile, "{\n"); + fprintf(outputFile, "\"Major\": %" PRIu32 ",\n", header->major); + fprintf(outputFile, "\"Minor\": %" PRIu32 ",\n", header->minor); + fprintf(outputFile, "\"Reserved1\": %" PRIu32 ",\n", header->reserved1); + fprintf(outputFile, "\"Reserved2\": %" PRIu32 ",\n", header->reserved2); + fprintf(outputFile, "\"PrimaryFileGuid\": \n["); + int i = 0; + for (; i < 15; i++) { + fprintf(outputFile, "%u, ",header->primary_file_guid[i]); + } + fprintf(outputFile, "%u],\n",header->primary_file_guid[i]); + fprintf(outputFile, "\"FileGuid\": \n["); + for (i = 0; i < 15; i++) { + fprintf(outputFile, "%u, ",header->file_guid[i]); + } + fprintf(outputFile, "%u],\n",header->file_guid[i]); + fprintf(outputFile, "\"FilePart\": %" PRIu32 ",\n", header->file_part); + fprintf(outputFile, "\"DirectoryPosition\": %" PRIu64 ",\n", header->directory_position); + fprintf(outputFile, "\"MetadataPosition\": %" PRIu64 ",\n", header->metadata_position); + fprintf(outputFile, "\"UpdatePending\": %" PRIu32 ",\n", header->update_pending); + fprintf(outputFile, "\"AttachmentDirectoryPosition\": %" PRIu64 "\n", header->attachment_directory_potition); + fprintf(outputFile, "}\n"); +} +//END ZISRAWFILE /////////////////////////////////////////////////////////////// + + + +//START SubBlockDirectory///////////////////////////////////////////////////////// +typedef struct { + char dimension[4]; + int32_t start; + uint32_t size; + float start_coordinate; + uint32_t stored_size; +} __attribute__ ((__packed__)) SubBlockDimentionEntry; + +typedef struct { + char schema[2]; + uint32_t pixel_type; + uint64_t file_position; + uint32_t file_part; + uint32_t compression; + char pyramidType; + char spare1; + char spare2[4]; + uint32_t dimension_count; + SubBlockDimentionEntry* dimension_entries; +} __attribute__ ((__packed__)) SubBlockDirectoryEntry; + +typedef struct { + uint32_t entry_count; + char reserved[124]; + SubBlockDirectoryEntry* directory_entries; +} __attribute__ ((__packed__)) SubBlockDirectory; + +void printSubBlockDimentionEntry(SubBlockDimentionEntry* dimensionEntry) { + // printf(" dimension: "); + // for (int i = 0; i < 4; i++) { + // printf("%c", dimensionEntry->dimension[i]); + // } + + printf(" dimension: %s\n", dimensionEntry->dimension); + + printf(" start: %" PRIi32 "\n", dimensionEntry->start); + printf(" size: %" PRIu32 "\n", dimensionEntry->size); + printf(" start_coordinate: %f\n", dimensionEntry->start_coordinate); + printf(" stored_size: %" PRIu32 "\n", dimensionEntry->stored_size); +} +void writeSubBlockDimentionEntry(SubBlockDimentionEntry* dimensionEntry, FILE* outputFile) { + fprintf(outputFile, "{\n"); + + // fprintf(outputFile, "\"Dimension\": \""); + // for(int i = 0; i < 4; i++) { + // fprintf(outputFile, "%c", dimensionEntry->dimension[i]); + // } + // fprintf(outputFile, "\",\n\"Start\": %" PRIi32 ",\n", dimensionEntry->start); + + fprintf(outputFile, "\"Dimension\": \"%s\",\n", dimensionEntry->dimension); + fprintf(outputFile, "\"Start\": %" PRIi32 ",\n", dimensionEntry->start); + + fprintf(outputFile, "\"Size\": %" PRIu32 ",\n", dimensionEntry->size); + fprintf(outputFile, "\"StartCoordinate\": %f,\n", dimensionEntry->start_coordinate); + fprintf(outputFile, "\"StoredSize\": %" PRIu32 "\n", dimensionEntry->stored_size); + fprintf(outputFile, "}\n"); +} + +void printSubBlockDirectoryEntry(SubBlockDirectoryEntry* directoryEntry) { + printf(" schema: %c%c\n", directoryEntry->schema[0], directoryEntry->schema[1]); + printf(" pixel_type: %" PRIu32 "\n", directoryEntry->pixel_type); + printf(" file_position: %" PRIu64 "\n", directoryEntry->file_position); + printf(" file_part: %" PRIu32 "\n", directoryEntry->file_part); + printf(" compression: %" PRIu32 "\n", directoryEntry->compression); + printf(" pyramidType: %u\n", directoryEntry->pyramidType); + printf(" spare1: %d\n", directoryEntry->spare1); + printf(" spare2: %d %d %d %d\n", directoryEntry->spare2[0], directoryEntry->spare2[1], directoryEntry->spare2[2], directoryEntry->spare2[3]); + printf(" dimension_count: %" PRIu32 "\n", directoryEntry->dimension_count); + printf(" dimension_entries: \n"); + for (uint32_t i = 0; i < directoryEntry->dimension_count; i++) { + printSubBlockDimentionEntry(&directoryEntry->dimension_entries[i]); + } + printf("\n"); +} +void writeSubBlockDirectoryEntry(SubBlockDirectoryEntry* directoryEntry, FILE* outputFile) { + fprintf(outputFile, "{\n"); + fprintf(outputFile, "\"SchemaType\": \"%c%c\",\n", directoryEntry->schema[0],directoryEntry->schema[1]); + fprintf(outputFile, "\"PixelType\": %" PRIu32 ",\n", directoryEntry->pixel_type); + fprintf(outputFile, "\"FilePosition\": %" PRIu64 ",\n", directoryEntry->file_position); + fprintf(outputFile, "\"FilePart\": %" PRIu32 ",\n", directoryEntry->file_part); + fprintf(outputFile, "\"Compression\": %" PRIu32 ",\n", directoryEntry->compression); + fprintf(outputFile, "\"PyramidType\": \"%u\",\n", directoryEntry->pyramidType); + fprintf(outputFile, "\"spare1\": %d,\n", directoryEntry->spare1); + fprintf(outputFile, "\"spare2\": \"%d %d %d %d\",\n", directoryEntry->spare2[0], directoryEntry->spare2[1], directoryEntry->spare2[2], directoryEntry->spare2[3]); + fprintf(outputFile, "\"DimensionCount\": %" PRIu32 ",\n", directoryEntry->dimension_count); + fprintf(outputFile, "\"DimensionEntries\": \n[\n"); + uint32_t i = 0; + for (; i < directoryEntry->dimension_count - 1; i++) { + writeSubBlockDimentionEntry(&directoryEntry->dimension_entries[i], outputFile); + fprintf(outputFile, ", "); + } + writeSubBlockDimentionEntry(&directoryEntry->dimension_entries[i], outputFile); + fprintf(outputFile, "]}\n"); +} + +void printSubBlockDirectory(SubBlockDirectory* zisDirectory) { + printf("entry_count: %" PRIu32 "\n", zisDirectory->entry_count); + printf("reserved: %s\n", zisDirectory->reserved); + printf("directory_entries: \n"); + for (uint32_t i = 0; i < zisDirectory->entry_count; i++) { + printSubBlockDirectoryEntry(&zisDirectory->directory_entries[i]); + } +} +void writeSubBlockDirectory(SubBlockDirectory* zisDirectory, FILE* outputFile) { + fprintf(outputFile, "{\n"); + fprintf(outputFile, "\"EntryCount\": %" PRIu32 ",\n", zisDirectory->entry_count); + fprintf(outputFile, "\"Reserved\": \"%s\",\n", zisDirectory->reserved); + fprintf(outputFile, "\"Entry\": \n[\n"); + uint32_t i = 0; + for (; i < zisDirectory->entry_count - 1; i++) { + writeSubBlockDirectoryEntry(&zisDirectory->directory_entries[i], outputFile); + fprintf(outputFile, ", "); + } + writeSubBlockDirectoryEntry(&zisDirectory->directory_entries[i], outputFile); + fprintf(outputFile, "]}\n"); +} +//END SubBlockDirectory/////////////////////////////////////////////////////////// + + + +//START METADATASEGMENT///////////////////////////////////////////////////////// +typedef struct { + uint32_t xml_size; + uint32_t attachment_size; + char spare[248]; +} __attribute__ ((__packed__)) MetadataSegment; + +void printMetadataSegment(MetadataSegment* metaSegement) { + printf("xml_size: %" PRIu32 "\n", metaSegement->xml_size); + printf("attachment_size: %" PRIu32 "\n", metaSegement->attachment_size); + printf("spare: \n"); + printf("Document Name: %s", "FILE-META-1.xml"); +} +void writeMetadataSegment(MetadataSegment* metaSegement, FILE* outputFile) { + fprintf(outputFile, "{\n"); + fprintf(outputFile, "\"XmlSize\": %" PRIu32 ",\n", metaSegement->xml_size); + fprintf(outputFile, "\"AttachmentSize\": %" PRIu32 ",\n", metaSegement->attachment_size); + fprintf(outputFile, "\"\": \"<256-8>\",\n"); + fprintf(outputFile, "\"XmlName\": \"FILE-META-1.xml\"\n"); + fprintf(outputFile, "}\n"); +} +//END METADATASEGMENT/////////////////////////////////////////////////////////// + + + +//START SUBBLOCKSEGMENT///////////////////////////////////////////////////////// +typedef struct { + uint32_t metadata_size; + uint32_t attachment_size; + uint64_t data_size; + SubBlockDirectoryEntry directory_entry; + char* metadata; + void* data; + void* attachments; +} __attribute__ ((__packed__)) SubBlockSegment; + +void printSubBlockSegment(SubBlockSegment* subBlockSegment) { + static int META_COUNT = 0; + static int DATA_COUNT = 0; + static int ATTACH_COUNT = 0; + printf("metadata_size: %" PRIu32 "\n", subBlockSegment->metadata_size); + printf("attachment_size: %" PRIu32 "\n", subBlockSegment->attachment_size); + printf("data_size: %" PRIu64 "\n", subBlockSegment->data_size); + printf("spare: \n"); + printSubBlockDirectoryEntry(&subBlockSegment->directory_entry); + if (strncmp(subBlockSegment->metadata, "", subBlockSegment->metadata_size) != 0) { + printf("metadata: \"metadata-%d\"\n", META_COUNT++); + } else { + printf("metadata: \"empty\"\n"); + } + printf("data: \"data-%d\"\n", DATA_COUNT++); + if (subBlockSegment->attachment_size != 0) { + printf("attatchments: \"attach-%d\"\n", ATTACH_COUNT++); + } else { + printf("attatchments: \"empty\"\n"); + } +} + +int findEqualDimension(SubBlockDirectoryEntry* directoryEntry, const char* dimensionName) { + + for (uint32_t i = 0; i < directoryEntry->dimension_count; i++) { + if (strcmp(directoryEntry->dimension_entries[i].dimension, dimensionName) == 0) { + if (directoryEntry->dimension_entries[i].size == directoryEntry->dimension_entries[i].stored_size) { + return 1; + } else { + return 0; + } + } + } + return 0; +} + +void writeSubBlockSegment(SubBlockSegment* subBlockSegment, FILE* outputFile) { + + static int META_COUNT = 0; + static int DATA_COUNT = 0; + static int ATTACH_COUNT = 0; + + fprintf(outputFile, "{\n"); + fprintf(outputFile, "\"MetadataSize\": %" PRIu32 ",\n", subBlockSegment->metadata_size); + fprintf(outputFile, "\"AttachmentSize\": %" PRIu32 ",\n", subBlockSegment->attachment_size); + fprintf(outputFile, "\"DataSize\": %" PRIu64 ",\n", subBlockSegment->data_size); + fprintf(outputFile, "\"DirectoryEntry\": "); + writeSubBlockDirectoryEntry(&subBlockSegment->directory_entry, outputFile); + fprintf(outputFile, ",\n\"Fill\": \"\",\n"); + + /* open file for Output */ + if (strncmp(subBlockSegment->metadata, "", subBlockSegment->metadata_size) != 0) { + writeDataToFile("metadata-", META_COUNT, ".xml", subBlockSegment->metadata, subBlockSegment->metadata_size); + fprintf(outputFile, "\"Metadata\": \"metadata-%d.xml\",\n", META_COUNT++); + } else { + fprintf(outputFile, "\"Metadata\": \"empty\",\n"); + } + + if (findEqualDimension(&subBlockSegment->directory_entry, "X") && findEqualDimension(&subBlockSegment->directory_entry, "Y")) { + writeDataToFile("data-", DATA_COUNT, ".jxr", subBlockSegment->data, subBlockSegment->data_size); + fprintf(outputFile, "\"Data\": \"data-%d.png\",\n", DATA_COUNT++); + } else { + fprintf(outputFile, "\"Data\": \"empty\",\n"); + } + + if (subBlockSegment->attachment_size != 0) { + writeDataToFile("attach-", ATTACH_COUNT, "", subBlockSegment->attachments, subBlockSegment->attachment_size); + fprintf(outputFile, "\"Attachments\": \"attach-%d\"\n", ATTACH_COUNT++); + } else { + fprintf(outputFile, "\"Attachments\": \"empty\"\n"); + } + fprintf(outputFile, "}\n"); +} +//END SUBBLOCKSEGMENT/////////////////////////////////////////////////////////// + + + + + + + +//START ATTACHMENTENTRY///////////////////////////////////////////////////////// +typedef struct { + char schema_type[2]; + char reserved[10]; + uint64_t file_position; + int file_part; + GUID content_guid; + char content_file_type[8]; + char name[80]; +} __attribute__ ((__packed__)) AttachmentEntry; + +void printAttachmentEntry(AttachmentEntry* attachmentSegment){ + printf(" schema_type: \"%c%c\"\n", attachmentSegment->schema_type[0],attachmentSegment->schema_type[1]); + printf(" reserved: %s\n", attachmentSegment->reserved); + printf(" file_position: %" PRIu64 "\n", attachmentSegment->file_position); + printf(" file_part: %d\n", attachmentSegment->file_part); + printf(" ContentGuid: ["); + int i = 0; + for (; i < 15; i++) { + printf("%u, ", attachmentSegment->content_guid[i]); + } + printf("%u]\n", attachmentSegment->content_guid[i]); + printf(" content_file_type: \"%s\"\n", attachmentSegment->content_file_type); + printf(" name: \"%s\"\n", attachmentSegment->name); +} +void writeAttachmentEntry(AttachmentEntry* attachmentSegment, FILE* outputFile){ + fprintf(outputFile, "{\n"); + fprintf(outputFile, "\"SchemaType\": \"%c%c\",\n", attachmentSegment->schema_type[0],attachmentSegment->schema_type[1]); + fprintf(outputFile, "\"Reserved\": \"%s\",\n", attachmentSegment->reserved); + fprintf(outputFile, "\"FilePosition\": %" PRIu64 ",\n", attachmentSegment->file_position); + fprintf(outputFile, "\"FilePart\": %d,\n", attachmentSegment->file_part); + fprintf(outputFile, "\"ContentGuid\": \n["); + int i = 0; + for (; i < 15; i++) { + fprintf(outputFile, "%u, ", attachmentSegment->content_guid[i]); + } + fprintf(outputFile, "%u],\n", attachmentSegment->content_guid[i]); + fprintf(outputFile, "\"ContentFileType\": \"%s\",\n", attachmentSegment->content_file_type); + fprintf(outputFile, "\"Name\": \"%s\"\n", attachmentSegment->name); + fprintf(outputFile, "}\n"); +} + +//END ATTACHMENTENTRY/////////////////////////////////////////////////////////// + + + + + + +//START ATTACHMENTSEGMENT/////////////////////////////////////////////////////// +typedef struct { + uint32_t data_size; + char spare1[12]; + AttachmentEntry attachment_entry; + char spare2[112]; + void* data; +} __attribute__ ((__packed__)) AttachmentSegment; + +void printAttachmentSegment(AttachmentSegment* attachmentSegment){ + + static int ATTACH_DATA_COUNT = 0; + + printf("data_size: %" PRIu32 "\n", attachmentSegment->data_size); + printAttachmentEntry(&attachmentSegment->attachment_entry); + printf("data: \"attach-data-%d\"\n", ATTACH_DATA_COUNT++); +} +void writeAttachmentSegment(AttachmentSegment* attachmentSegment, FILE* outputFile){ + + static int ATTACH_DATA_COUNT = 0; + + fprintf(outputFile, "{\n"); + fprintf(outputFile, "\"DataSize\": %" PRIu32 ",\n", attachmentSegment->data_size); + fprintf(outputFile, "\"AttachmentEntry\": "); + writeAttachmentEntry(&attachmentSegment->attachment_entry, outputFile); + + /* open file for Output */ + writeDataToFile("attach-data-", ATTACH_DATA_COUNT, "", attachmentSegment->data, attachmentSegment->data_size); + + fprintf(outputFile, ",\n\"Data\": \"attach-data-%d\"\n", ATTACH_DATA_COUNT++); + fprintf(outputFile, "}\n"); +} +//END ATTACHMENTSEGMENT///////////////////////////////////////////////////////// + + + +//END ATTACHMENTDIRECTORY/////////////////////////////////////////////////////// +typedef struct { + int entry_count; + char reserved[252]; + AttachmentEntry* attachment_entries; +} __attribute__ ((__packed__)) AttachmentDirectory; + +void printAttachmentDirectory(AttachmentDirectory* attachmentDirectory){ + printf("entry_count: %d\n", attachmentDirectory->entry_count); + for (int i = 0; i < attachmentDirectory->entry_count; i++) { + printAttachmentEntry(&attachmentDirectory->attachment_entries[i]); + } +} +void writeAttachmentDirectory(AttachmentDirectory* attachmentDirectory, FILE* outputFile){ + fprintf(outputFile, "{\n"); + fprintf(outputFile, "\"EntryCount\": %d,\n", attachmentDirectory->entry_count); + fprintf(outputFile, "\"Entry\": [\n"); + int i = 0; + for (; i < attachmentDirectory->entry_count - 1; i++) { + writeAttachmentEntry(&attachmentDirectory->attachment_entries[i], outputFile); + fprintf(outputFile, ", "); + } + writeAttachmentEntry(&attachmentDirectory->attachment_entries[i], outputFile); + fprintf(outputFile, "]}\n"); +} +//END ATTACHMENTDIRECTORY/////////////////////////////////////////////////////// diff --git a/src/conversion/czi/cziconvert.c b/src/conversion/czi/cziconvert.c new file mode 100644 index 0000000..85b925c --- /dev/null +++ b/src/conversion/czi/cziconvert.c @@ -0,0 +1,354 @@ +#include +#include +#include + +#include "cziSegmentHeaders.h" + +void writeDataToFile(const char* filename, int fileCount, const char* optionalFileExtension, void* content, long contentSize); +char extractDirName[100]; +long totalFileSize; +long lastPercentFileProgress = -1; +SegmentHeader* segHead; +SubBlockDirectory* zisDirectory; +SubBlockSegment* zisSubBlock; +AttachmentSegment* attachmentSegment; +AttachmentDirectory* attachmentDirectory; +MetadataSegment* metadataSegment; + + + +void setFileOffset(FILE* streamPointer, long currentPosition, SegmentHeader* segment) { + // if (segment->used_size == 0) { + fseek(streamPointer, currentPosition + segment->allocated_size, SEEK_SET); + // } else { + // fseek(streamPointer, currentPosition + segment->used_size, SEEK_SET); + // } +} + +int findSegmentID() { + + if (strcmp(segHead->name, "ZISRAWSUBBLOCK") == 0) { + return 3; + } + else if (strcmp(segHead->name, "ZISRAWATTACH") == 0) { + return 5; + } + else if (strcmp(segHead->name, "ZISRAWATTDIR") == 0) { + return 6; + } + else if (strcmp(segHead->name, "ZISRAWDIRECTORY") == 0) { + return 2; + } + else if (strcmp(segHead->name, "DELETED") == 0) { + return 7; + } + else if (strcmp(segHead->name, "ZISRAWMETADATA") == 0) { + return 4; + } + else if (strcmp(segHead->name, "ZISRAWFILE") == 0) { + return 1; + } + else { + return -1; + } +} + + +void loadMainHeader(FILE* imageFile, FILE* outputFile, long* fileOffset) { + + //initial thing. + fprintf(outputFile,"{\n"); + writeSegmentHeader(segHead, outputFile); + + //main file descriptor + ZisrawFile* zisFileHeader = malloc(sizeof(ZisrawFile)); + fread(zisFileHeader, sizeof(ZisrawFile), 1, imageFile); + + //print and write to file +// printZisrawFile(zisFileHeader); + writeZisrawFile(zisFileHeader, outputFile); + free(zisFileHeader); + fprintf(outputFile,"}\n"); + + //correct for Zero Paddings + setFileOffset(imageFile, *fileOffset, segHead); +} + + +void loadZisDirectories(SubBlockDirectory* zisrawDirectory, FILE* imageFile) { + + //Get the main directory; + fread(zisrawDirectory, sizeof(SubBlockDirectory), 1, imageFile); + //Take care for the fact that what we are using as a pointer value in struct size is actually just the first address. + fseek(imageFile, -8, SEEK_CUR); + //allocate space for each of the directory entries + zisrawDirectory->directory_entries = malloc(sizeof(SubBlockDirectoryEntry) * zisrawDirectory->entry_count); + + //now get each Directory entry + for (uint32_t i = 0; i < zisrawDirectory->entry_count; i++) { + + //read in the directory entry + fread(&zisrawDirectory->directory_entries[i], sizeof(SubBlockDirectoryEntry), 1, imageFile); + //Again cater for the struct pointer size difference + fseek(imageFile, -8, SEEK_CUR); + + //malloc the dimension entry requirements into the above directory entries pointer + zisrawDirectory->directory_entries[i].dimension_entries = malloc(sizeof(SubBlockDimentionEntry) * zisrawDirectory->directory_entries[i].dimension_count); + + //read in the dimension entries into the new malloc location + fread(zisrawDirectory->directory_entries[i].dimension_entries, sizeof(SubBlockDimentionEntry), zisrawDirectory->directory_entries[i].dimension_count, imageFile); + } +} +void freeZisDirectories(SubBlockDirectory* zisrawDirectory) { + //now get each Directory entry + for (uint32_t i = 0; i < zisrawDirectory->entry_count; i++) { + //free the dimension entry requirements into the above directory entries pointer + free(zisrawDirectory->directory_entries[i].dimension_entries); + } + //free space for each of the directory entries + free(zisrawDirectory->directory_entries); +} + + +void loadSubBlockSegment(SubBlockSegment* subBlockSegment, FILE* imageFile) { + + long offsetCorrection = ftell(imageFile); + //Get the fixed size content; + fread(subBlockSegment, sizeof(SubBlockDirectoryEntry) + 8, 1, imageFile); + //read in the directoryEntry + subBlockSegment->directory_entry.dimension_entries = malloc(subBlockSegment->directory_entry.dimension_count * sizeof(SubBlockDimentionEntry)); + //read in the dimensions + fread(subBlockSegment->directory_entry.dimension_entries, sizeof(SubBlockDimentionEntry), subBlockSegment->directory_entry.dimension_count, imageFile); + + //Deal with the "fill" block + offsetCorrection = ftell(imageFile) - offsetCorrection; + offsetCorrection = 256 - offsetCorrection; + if (offsetCorrection > 0) { + fseek(imageFile, offsetCorrection, SEEK_CUR); + } + + // metadata block + subBlockSegment->metadata = malloc(subBlockSegment->metadata_size); + fread(subBlockSegment->metadata, 1, subBlockSegment->metadata_size, imageFile); + + // data block + subBlockSegment->data = malloc(subBlockSegment->data_size); + fread(subBlockSegment->data, 1, subBlockSegment->data_size, imageFile); + + // attach block + subBlockSegment->attachments = malloc(subBlockSegment->attachment_size); + fread(subBlockSegment->attachments, 1, subBlockSegment->attachment_size, imageFile); +} +void freeSubBlockSegment(SubBlockSegment* subBlockSegment) { + //free the directoryEntry + free(subBlockSegment->directory_entry.dimension_entries); + + // metadata block + free(subBlockSegment->metadata); + + // data block + free(subBlockSegment->data); + + // attach block + free(subBlockSegment->attachments); +} + + +void loadAttachmentSegment(AttachmentSegment* attachmentSegment, FILE* imageFile) { + + //Get the fixed size content; + fread(attachmentSegment, sizeof(AttachmentSegment), 1, imageFile); + //account for the pointer space + fseek(imageFile, -8, SEEK_CUR); + + //make space for the data element; + attachmentSegment->data = malloc(attachmentSegment->data_size); + + //read in the data + fread(attachmentSegment->data, attachmentSegment->data_size, 1, imageFile); +} +void freeAttachmentSegment(AttachmentSegment* attachmentSegment) { + //free the data area + free(attachmentSegment->data); +} + + +void loadAttachmentDirectory(AttachmentDirectory* attachmentDirectory, FILE* imageFile) { + + //Get the fixed size content; + fread(attachmentDirectory, sizeof(AttachmentDirectory), 1, imageFile); + //account for the pointer space + fseek(imageFile, -8, SEEK_CUR); + //malloc the space for the attachments; + attachmentDirectory->attachment_entries = malloc(sizeof(AttachmentEntry) * attachmentDirectory->entry_count); + //read in the content; + fread(attachmentDirectory->attachment_entries, sizeof(AttachmentEntry), attachmentDirectory->entry_count, imageFile); +} +void freeAttachmentDirectory(AttachmentDirectory* attachmentDirectory) { + //free the entries area + free(attachmentDirectory->attachment_entries); +} + +void loadMetadataSegment(MetadataSegment* metadataSegment, FILE* imageFile) { + fread(metadataSegment, sizeof(MetadataSegment), 1, imageFile); +} +void loadAndWriteMetadataData(MetadataSegment* metadataSegment, FILE* imageFile) { + void* rawMetadata = malloc(metadataSegment->xml_size); + fread(rawMetadata, 1, metadataSegment->xml_size, imageFile); + writeDataToFile("FILE-META-", 1, ".xml", rawMetadata, metadataSegment->xml_size); + free(rawMetadata); +} + + +int functionRouter(FILE* imageFile, FILE* jsonOutput, long* fileOffset) { + + //next segment header + long newPercent = (100 * ftell(imageFile) / totalFileSize); + if (newPercent > lastPercentFileProgress) { + lastPercentFileProgress = newPercent; + printf("> Amount of CZI file extracted: %3ld%%\n", lastPercentFileProgress); + } + + if (fread(segHead, sizeof(SegmentHeader), 1, imageFile) != 1) { + return 0; + } + *fileOffset = ftell(imageFile); + + //"prettify + print lol" +// printSegmentHeader(segHead); + fprintf(jsonOutput,"{\n"); + writeSegmentHeader(segHead, jsonOutput); + + //deal with the specific kind of segement. + switch (findSegmentID()) { + + //FileTitle + case 1: + loadMainHeader(imageFile, jsonOutput, fileOffset); + break; + + //Directory + case 2: + loadZisDirectories(zisDirectory, imageFile); + writeSubBlockDirectory(zisDirectory, jsonOutput); + freeZisDirectories(zisDirectory); + break; + + //Subblock + case 3: + loadSubBlockSegment(zisSubBlock, imageFile); +// printSubBlockSegment(zisSubBlock); + writeSubBlockSegment(zisSubBlock, jsonOutput); + freeSubBlockSegment(zisSubBlock); + break; + + //MetaData + case 4: + loadMetadataSegment(metadataSegment, imageFile); +// printMetadataSegment(metadataSegment); + writeMetadataSegment(metadataSegment, jsonOutput); + loadAndWriteMetadataData(metadataSegment, imageFile); + break; + + //Attseg + case 5: + loadAttachmentSegment(attachmentSegment, imageFile); +// printAttachmentSegment(attachmentSegment); + writeAttachmentSegment(attachmentSegment, jsonOutput); + freeAttachmentSegment(attachmentSegment); + break; + + //Attdir + case 6: + loadAttachmentDirectory(attachmentDirectory, imageFile); +// printAttachmentDirectory(attachmentDirectory); + writeAttachmentDirectory(attachmentDirectory, jsonOutput); + freeAttachmentDirectory(attachmentDirectory); + break; + + //DELETED + case 7: + fprintf(jsonOutput, "{}"); + break; + + default: + fprintf(stderr, "FAILED TO PARSE SEGMENT HEADER: %s", segHead->name); + exit(1); + } + + setFileOffset(imageFile, *fileOffset, segHead); + fprintf(jsonOutput,"},\n"); + return 1; +} + +int main(int argc, char* argv[]) { + + //Check program input arguments. + if (argc < 2 || argc > 4) { + printf("Invalid number of arguments passed in.\nUsage:\n\n./prog \n\n"); + exit(1); + } + + //create file objects; + FILE* imageFile; + FILE* jsonOutput; + long fileOffset = 0; + strcpy(extractDirName, argv[2]); + + /* open file for input */ + if ((imageFile = fopen(argv[1], "r"))==NULL){ + printf("Read error occurred, check file path."); + exit(1); + } + fseek(imageFile, 0, SEEK_END); + totalFileSize = ftell(imageFile); + fseek(imageFile, 0, SEEK_SET); + + /* open file for Output */ + char jsonName[90]; + strcpy(jsonName, extractDirName); + strcat(jsonName, "outputjson.json"); + if ((jsonOutput = fopen(jsonName, "w"))==NULL){ + printf("Write error occurred, check file path."); + exit(1); + } + fprintf(jsonOutput,"{ \"czi\": [\n"); + + + //create heap space for a header and directory stuff. + segHead = malloc(sizeof(SegmentHeader)); + zisDirectory = malloc(sizeof(SubBlockDirectory)); + zisSubBlock = malloc(sizeof(SubBlockSegment)); + attachmentSegment = malloc(sizeof(AttachmentSegment)); + attachmentDirectory = malloc(sizeof(AttachmentDirectory)); + metadataSegment = malloc(sizeof(MetadataSegment)); + + + printf("\n=========== BEGIN CZI EXTRACTION ===========\n\n"); + while (functionRouter(imageFile, jsonOutput, &fileOffset)); + //get rid of the last comma + fseek(jsonOutput, -2, SEEK_CUR); + //close stuff + free(segHead); + free(zisDirectory); + free(zisSubBlock); + free(attachmentSegment); + free(attachmentDirectory); + free(metadataSegment); + fclose(imageFile); + fprintf(jsonOutput,"\n]}\n"); + fclose(jsonOutput); + + printf("\n=========== FINISH CZI EXTRACTION ===========\n\n\n\n"); + + //convert all the data's to jxr; + char jxrLoc[200]; + sprintf(jxrLoc, "%s %s %s", "python3", argv[3], argv[2]); + system(jxrLoc); + + + //begin work on re-factoring the image structure into a "smooth" grid + + + return 0; +} -- cgit v1.2.1 From 2a5095da5c568b6b63d4e438f3d83320300e3435 Mon Sep 17 00:00:00 2001 From: cjd24 Date: Sun, 4 Mar 2018 18:13:47 +0000 Subject: Playing around trying to get a list of base tiles we may be interested in for building pyramid --- src/conversion/czi/czi.ts | 114 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) (limited to 'src') diff --git a/src/conversion/czi/czi.ts b/src/conversion/czi/czi.ts index e69de29..7d7af1d 100644 --- a/src/conversion/czi/czi.ts +++ b/src/conversion/czi/czi.ts @@ -0,0 +1,114 @@ +var json = require('/cs/scratch/cjd24/0701-extraction/outputjson.json'); +json = json.czi; +let tileOverlap = 5; +let tileSize = 1024; + +var dataBlocks = json.filter((x: { Id: string, Data: { Data: string }}) => x.Id == 'ZISRAWSUBBLOCK' && x.Data.Data != 'empty'); + +var filterX = dataBlocks.map((x: {Data: {DirectoryEntry: {DimensionEntries: {Start: number}[]}}}) => x.Data.DirectoryEntry.DimensionEntries[0].Start); +var filterY = dataBlocks.map((x: {Data: {DirectoryEntry: {DimensionEntries: {Start: number}[]}}}) => x.Data.DirectoryEntry.DimensionEntries[1].Start); + +var uniqueX = filterX.filter(function(elem: any, pos: any) { + return filterX.indexOf(elem) == pos; +}) + +var uniqueY = filterY.filter(function(elem: any, pos: any) { + return filterY.indexOf(elem) == pos; +}) + + +//These values are normally stored at the big XML metadata under "Information/Image/SizeX or SizeY"; +var sizeX = 0; +var sizeY = 0; +for (var i = 0; i < uniqueX.length; i++) { + sizeX += dataBlocks[i].Data.DirectoryEntry.DimensionEntries[0].Size; +} +for (var i = 0; i < uniqueY.length; i++) { + sizeY += dataBlocks[i * uniqueX.length].Data.DirectoryEntry.DimensionEntries[1].Size; +} + + +console.log("\n\nSizeX : " + sizeX); +console.log("UNIQUE X VALUES:"); +console.log(uniqueX); +console.log("\n\nSizeY : " + sizeY); +console.log("UNIQUE Y VALUES:"); +console.log(uniqueY); +console.log("\n\n\n\n\n\n"); + + +console.log(findRelatedTiles(0, 0)); + + + + + + + + + + + + + + +function getOriginalTileCoordinates(originalTile: any): number[] | null{ + let xstart:number | null = null, + xsize:number | null = null, + ystart:number | null = null, + ysize:number | null = null; + + for (let dimension of originalTile.Data.DirectoryEntry) { + if (dimension.Dimension == 'X') { + xstart = dimension.Start; + xsize = dimension.Size; + continue; + } + if (dimension.Dimension == 'Y') { + ystart = dimension.Start; + ysize = dimension.Size; + continue; + } + } + + if (!xstart || !xsize || !ystart || !ysize) { + return null; + } else { + return [xstart, xsize, ystart, ysize]; + } +} + + +function findRelatedTiles(desiredX: number, desiredY: number): any[] { + let relatedTiles: any[] = []; + + for (let origTile in dataBlocks) { + let origCoords: number[] | null = getOriginalTileCoordinates(origTile); + if (origCoords === null) { + return ["There was a sad boi error"]; + } + + //desired X on left is within current tile + if ((((desiredX - tileOverlap) > origCoords[0]) && + ((desiredX - tileOverlap) < (origCoords[0] + origCoords[1]))) || + + //desired X on right is within the current tile + (((desiredX + tileSize + tileOverlap) > origCoords[0]) && + ((desiredX + tileSize + tileOverlap) < (origCoords[0] + origCoords[1])))) { + + + //desired Y on top is within current tile + if ((((desiredY - tileOverlap) > origCoords[2]) && + ((desiredY - tileOverlap) < (origCoords[2] + origCoords[3]))) || + + //desired Y on bottom is within the current tile + (((desiredY + tileSize + tileOverlap) > origCoords[2]) && + ((desiredY + tileSize + tileOverlap) < (origCoords[2] + origCoords[3])))) { + + relatedTiles.push(origTile); + } + } + } + + return relatedTiles; +} -- cgit v1.2.1 From 694b0bc100171c443e6abd053ad20110a01c2a91 Mon Sep 17 00:00:00 2001 From: cjd24 Date: Mon, 5 Mar 2018 19:44:09 +0000 Subject: Made the initial dabble into CZI tile builder type-scriptified --- src/conversion/czi/czi.ts | 274 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 202 insertions(+), 72 deletions(-) (limited to 'src') diff --git a/src/conversion/czi/czi.ts b/src/conversion/czi/czi.ts index 7d7af1d..720d711 100644 --- a/src/conversion/czi/czi.ts +++ b/src/conversion/czi/czi.ts @@ -1,114 +1,244 @@ -var json = require('/cs/scratch/cjd24/0701-extraction/outputjson.json'); +let json: any = require('/cs/scratch/cjd24/0701-extraction/outputjson.json'); json = json.czi; -let tileOverlap = 5; -let tileSize = 1024; -var dataBlocks = json.filter((x: { Id: string, Data: { Data: string }}) => x.Id == 'ZISRAWSUBBLOCK' && x.Data.Data != 'empty'); +let tileOverlap: number = 5; +let tileSize: number = 1024; -var filterX = dataBlocks.map((x: {Data: {DirectoryEntry: {DimensionEntries: {Start: number}[]}}}) => x.Data.DirectoryEntry.DimensionEntries[0].Start); -var filterY = dataBlocks.map((x: {Data: {DirectoryEntry: {DimensionEntries: {Start: number}[]}}}) => x.Data.DirectoryEntry.DimensionEntries[1].Start); - -var uniqueX = filterX.filter(function(elem: any, pos: any) { - return filterX.indexOf(elem) == pos; -}) - -var uniqueY = filterY.filter(function(elem: any, pos: any) { - return filterY.indexOf(elem) == pos; -}) - - -//These values are normally stored at the big XML metadata under "Information/Image/SizeX or SizeY"; -var sizeX = 0; -var sizeY = 0; -for (var i = 0; i < uniqueX.length; i++) { - sizeX += dataBlocks[i].Data.DirectoryEntry.DimensionEntries[0].Size; +interface Dimension { + Dimension: string; + Start: number; + Size: number; +} +interface DirectoryEntry { + DimensionCount: number; + DimensionEntries: Dimension[]; +} +interface SubBlock { + DirectoryEntry: DirectoryEntry; + Data: string; +} +interface Segment { + Id: string; + UsedSize: number; + Data: SubBlock; } -for (var i = 0; i < uniqueY.length; i++) { - sizeY += dataBlocks[i * uniqueX.length].Data.DirectoryEntry.DimensionEntries[1].Size; +class TileBounds { + left: number; + right: number; + top: number; + bottom: number; + constructor(left: number, right: number, top: number, bottom: number) { + this.left = left; + this.right = right; + this.top = top; + this.bottom = bottom; + }; } -console.log("\n\nSizeX : " + sizeX); -console.log("UNIQUE X VALUES:"); -console.log(uniqueX); -console.log("\n\nSizeY : " + sizeY); -console.log("UNIQUE Y VALUES:"); -console.log(uniqueY); -console.log("\n\n\n\n\n\n"); +//Get all subblocks that have an associated saved tile +let dataBlocks: Segment[] = json.filter((x: Segment) => x.Id == 'ZISRAWSUBBLOCK' && x.Data.Data != 'empty'); -console.log(findRelatedTiles(0, 0)); +function getOriginalTileBounds(originalTile: Segment): TileBounds | null { + let bounds: TileBounds = new TileBounds (-1, -1, -1, -1); + for (let dimension of originalTile.Data.DirectoryEntry.DimensionEntries) { + if (dimension.Dimension == 'X') { + bounds.left = dimension.Start; + bounds.right = bounds.left + dimension.Size; + continue; + } + else if (dimension.Dimension == 'Y') { + bounds.top = dimension.Start; + bounds.bottom = bounds.top + dimension.Size; + continue; + } + } + if (bounds.left < 0 || bounds.right < 0 || bounds.top < 0 || bounds.bottom < 0) { + return null; + } + return bounds; +} +function findRelatedTiles(activeSegments: Segment[], desiredX: number, desiredY: number): Segment[] { + let relatedTiles: Segment[] = []; + for (let origTile of activeSegments) { + let origCoords: TileBounds | null; + if ((origCoords = getOriginalTileBounds(origTile)) === null) { + throw new Error("There was a Sad Boi error"); + } + let desired = new TileBounds( + desiredX - tileOverlap, + desiredX + tileSize + tileOverlap, + desiredY - tileOverlap, + desiredY + tileSize + tileOverlap + ); + //desired X on left is within current tile + if (((desired.left >= origCoords.left) && + (desired.left <= origCoords.right)) || + //desired X on right is within the current tile + ((desired.right >= origCoords.left) && + (desired.right <= origCoords.right)) || + //desired tile X overlaps base tile + ((desired.left < origCoords.left) && + (desired.right > origCoords.right))) -function getOriginalTileCoordinates(originalTile: any): number[] | null{ - let xstart:number | null = null, - xsize:number | null = null, - ystart:number | null = null, - ysize:number | null = null; + { + //desired Y on top is within current tile + if (((desired.top >= origCoords.top) && + (desired.top <= origCoords.bottom)) || - for (let dimension of originalTile.Data.DirectoryEntry) { - if (dimension.Dimension == 'X') { - xstart = dimension.Start; - xsize = dimension.Size; - continue; - } - if (dimension.Dimension == 'Y') { - ystart = dimension.Start; - ysize = dimension.Size; - continue; + //desired Y on right is within the current tile + ((desired.bottom >= origCoords.top) && + (desired.bottom <= origCoords.bottom)) || + + //desired tile Y overlaps whole base tile + ((desired.top < origCoords.top) && + (desired.bottom > origCoords.bottom))) + + { + relatedTiles.push(origTile); + } } } - if (!xstart || !xsize || !ystart || !ysize) { - return null; - } else { - return [xstart, xsize, ystart, ysize]; + return relatedTiles; +} + + +function getDimension(segment:Segment, name:string): Dimension | null { + for (let dimension of segment.Data.DirectoryEntry.DimensionEntries) { + if (dimension.Dimension == name) { + return dimension; + } } + return null; } -function findRelatedTiles(desiredX: number, desiredY: number): any[] { - let relatedTiles: any[] = []; - for (let origTile in dataBlocks) { - let origCoords: number[] | null = getOriginalTileCoordinates(origTile); - if (origCoords === null) { - return ["There was a sad boi error"]; - } - //desired X on left is within current tile - if ((((desiredX - tileOverlap) > origCoords[0]) && - ((desiredX - tileOverlap) < (origCoords[0] + origCoords[1]))) || - //desired X on right is within the current tile - (((desiredX + tileSize + tileOverlap) > origCoords[0]) && - ((desiredX + tileSize + tileOverlap) < (origCoords[0] + origCoords[1])))) { - //desired Y on top is within current tile - if ((((desiredY - tileOverlap) > origCoords[2]) && - ((desiredY - tileOverlap) < (origCoords[2] + origCoords[3]))) || - //desired Y on bottom is within the current tile - (((desiredY + tileSize + tileOverlap) > origCoords[2]) && - ((desiredY + tileSize + tileOverlap) < (origCoords[2] + origCoords[3])))) { - relatedTiles.push(origTile); - } + + +//Get all values of X and Y respectively. +let filterX: number[] = dataBlocks.map((x: Segment) => + { + let y: Dimension | null = getDimension(x, 'X'); + return y == null ? -1 : y.Start + }); +let filterY: number[] = dataBlocks.map((x: Segment) => + { + let y: Dimension | null = getDimension(x, 'Y'); + return y == null ? -1 : y.Start + }); + + +//Filter all values to only keep the unique ones for X and Y coords respectively. +let uniqueX: number[] = filterX.filter(function(elem: any, pos: any) { + return filterX.indexOf(elem) == pos; +}); +let uniqueY: number[] = filterY.filter(function(elem: any, pos: any) { + return filterY.indexOf(elem) == pos; +}); + +/*These values are normally stored at the big XML metadata under "Information/Image/SizeX or SizeY"; +However for the sake of hacking around, assume that the tiles in memory are +going from left to right; top to bottom. like a book, then use this in order +to count up the total size (in pixels) of the image*/ +let sizeX: number = 0; +let sizeY: number = 0; +for (let i: number = 0; i < uniqueX.length; i++) { + let temp : Dimension | null = getDimension(dataBlocks[i], 'X'); + if (temp != null) { + sizeX += temp.Size; + } +}; +for (let i: number = 0; i < uniqueY.length; i++) { + let temp : Dimension | null = getDimension(dataBlocks[i * uniqueX.length], 'Y'); + if (temp != null) + sizeY += temp.Size; +}; +tileOverlap + +let uniqueTileSizes: number[][] = []; +for (let seg of dataBlocks) { + let newx = getDimension(seg, 'X'), newy = getDimension(seg, 'Y'); + if (newx == null || newy == null) {continue;}; + let x: number = newx.Size, y: number = newy.Size; + let found: boolean = false; + for (let dimPair of uniqueTileSizes) { + if (x == dimPair[0] && y == dimPair[1]) { + found = true; + break; } } + if (!found) { + uniqueTileSizes.push([x, y]); + } +}; - return relatedTiles; + + + + + +//TESTS TO SEE WHAT VARIOUS THINGS RETURN +// `npm bin`/ts-node czi.ts +console.log("\n\nUnique Tile Sizes:"); +console.log(uniqueTileSizes); +console.log("\n\nSizeX : " + sizeX); +console.log("UNIQUE X VALUES:"); +console.log("[" + uniqueX + "]"); +console.log("\n\nSizeY : " + sizeY); +console.log("UNIQUE Y VALUES:"); +console.log("[" + uniqueY + "]"); +console.log("\n\n\n\n\n\n"); + +let x: number = 1500, y: number = 1500, c_val: number = 0; +var c_filter: Segment[] = []; +function filterC(to: number): void { + c_filter = dataBlocks.filter((x: Segment) => + { + let y: Dimension | null = getDimension(x, 'C'); + if (y != null && y.Start == to) { + return y; + } + }); } +filterC(0); + +console.log("\n\nC Value: " + c_val + " TileSize: " + tileSize + " TileOverlap: " + tileOverlap + " Coords: " + `[X=${x}, Y=${y}]\nResults: `); +console.log(findRelatedTiles(c_filter, x, y).map((x: Segment) => x.Data.Data)); + +filterC(c_val = 1); +console.log("\n\nC Value: " + c_val + " TileSize: " + tileSize + " TileOverlap: " + tileOverlap + " Coords: " + `[X=${x}, Y=${y}]\nResults: `); +console.log(findRelatedTiles(c_filter, x, y).map((x: Segment) => x.Data.Data)); + +filterC(c_val = 0); x=0;y=0; +console.log("\n\nC Value: " + c_val + " TileSize: " + tileSize + " TileOverlap: " + tileOverlap + " Coords: " + `[X=${x}, Y=${y}]\nResults: `); +console.log(findRelatedTiles(c_filter, x, y).map((x: Segment) => x.Data.Data)); + +filterC(c_val = 0); x=41940;y=59240; +console.log("\n\nC Value: " + c_val + " TileSize: " + tileSize + " TileOverlap: " + tileOverlap + " Coords: " + `[X=${x}, Y=${y}]\nResults: `); +console.log(findRelatedTiles(c_filter, x, y).map((x: Segment) => x.Data.Data)); + +filterC(c_val = 0); x=41945;y=59245; +console.log("\n\nC Value: " + c_val + " TileSize: " + tileSize + " TileOverlap: " + tileOverlap + " Coords: " + `[X=${x}, Y=${y}]\nResults: `); +console.log(findRelatedTiles(c_filter, x, y).map((x: Segment) => x.Data.Data)); -- cgit v1.2.1 From 9f1ec11a7fd82939a48a4cad60b5eaa900f261b8 Mon Sep 17 00:00:00 2001 From: cjd24 Date: Mon, 5 Mar 2018 20:54:47 +0000 Subject: Small touchups of czi inspector for modularity and readability --- src/conversion/czi/czi.ts | 90 +++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 54 deletions(-) (limited to 'src') diff --git a/src/conversion/czi/czi.ts b/src/conversion/czi/czi.ts index 720d711..df61033 100644 --- a/src/conversion/czi/czi.ts +++ b/src/conversion/czi/czi.ts @@ -64,7 +64,7 @@ function getOriginalTileBounds(originalTile: Segment): TileBounds | null { } -function findRelatedTiles(activeSegments: Segment[], desiredX: number, desiredY: number): Segment[] { +function findRelatedTiles(activeSegments: Segment[], desired: TileBounds): Segment[] { let relatedTiles: Segment[] = []; @@ -76,13 +76,6 @@ function findRelatedTiles(activeSegments: Segment[], desiredX: number, desiredY: throw new Error("There was a Sad Boi error"); } - let desired = new TileBounds( - desiredX - tileOverlap, - desiredX + tileSize + tileOverlap, - desiredY - tileOverlap, - desiredY + tileSize + tileOverlap - ); - //desired X on left is within current tile if (((desired.left >= origCoords.left) && (desired.left <= origCoords.right)) || @@ -118,13 +111,13 @@ function findRelatedTiles(activeSegments: Segment[], desiredX: number, desiredY: } -function getDimension(segment:Segment, name:string): Dimension | null { +function getDimension(segment:Segment, name:string): Dimension { for (let dimension of segment.Data.DirectoryEntry.DimensionEntries) { if (dimension.Dimension == name) { return dimension; } } - return null; + throw new Error("Dimension: " + name + " doesn't exist for segment: " + segment); } @@ -138,17 +131,8 @@ function getDimension(segment:Segment, name:string): Dimension | null { //Get all values of X and Y respectively. -let filterX: number[] = dataBlocks.map((x: Segment) => - { - let y: Dimension | null = getDimension(x, 'X'); - return y == null ? -1 : y.Start - }); -let filterY: number[] = dataBlocks.map((x: Segment) => - { - let y: Dimension | null = getDimension(x, 'Y'); - return y == null ? -1 : y.Start - }); - +let filterX: number[] = dataBlocks.map((x: Segment) => getDimension(x, 'X').Start); +let filterY: number[] = dataBlocks.map((x: Segment) => getDimension(x, 'Y').Start); //Filter all values to only keep the unique ones for X and Y coords respectively. let uniqueX: number[] = filterX.filter(function(elem: any, pos: any) { @@ -162,26 +146,18 @@ let uniqueY: number[] = filterY.filter(function(elem: any, pos: any) { However for the sake of hacking around, assume that the tiles in memory are going from left to right; top to bottom. like a book, then use this in order to count up the total size (in pixels) of the image*/ -let sizeX: number = 0; -let sizeY: number = 0; +let sizeX: number = 0, sizeY: number = 0; for (let i: number = 0; i < uniqueX.length; i++) { - let temp : Dimension | null = getDimension(dataBlocks[i], 'X'); - if (temp != null) { - sizeX += temp.Size; - } + sizeX += getDimension(dataBlocks[i], 'X').Size; }; for (let i: number = 0; i < uniqueY.length; i++) { - let temp : Dimension | null = getDimension(dataBlocks[i * uniqueX.length], 'Y'); - if (temp != null) - sizeY += temp.Size; + sizeX += getDimension(dataBlocks[i], 'Y').Size; }; -tileOverlap let uniqueTileSizes: number[][] = []; for (let seg of dataBlocks) { - let newx = getDimension(seg, 'X'), newy = getDimension(seg, 'Y'); - if (newx == null || newy == null) {continue;}; - let x: number = newx.Size, y: number = newy.Size; + + let x: number = getDimension(seg, 'X').Size, y: number = getDimension(seg, 'Y').Size; let found: boolean = false; for (let dimPair of uniqueTileSizes) { if (x == dimPair[0] && y == dimPair[1]) { @@ -203,16 +179,15 @@ for (let seg of dataBlocks) { // `npm bin`/ts-node czi.ts console.log("\n\nUnique Tile Sizes:"); console.log(uniqueTileSizes); -console.log("\n\nSizeX : " + sizeX); +console.log("\n\n(tentative) SizeX : " + sizeX); console.log("UNIQUE X VALUES:"); console.log("[" + uniqueX + "]"); -console.log("\n\nSizeY : " + sizeY); +console.log("\n\n(tentative) SizeY : " + sizeY); console.log("UNIQUE Y VALUES:"); -console.log("[" + uniqueY + "]"); -console.log("\n\n\n\n\n\n"); +console.log("[" + uniqueY + "]\n\n"); let x: number = 1500, y: number = 1500, c_val: number = 0; -var c_filter: Segment[] = []; +let c_filter: Segment[] = []; function filterC(to: number): void { c_filter = dataBlocks.filter((x: Segment) => { @@ -222,23 +197,30 @@ function filterC(to: number): void { } }); } -filterC(0); +let desired = new TileBounds (0,0,0,0); + +function runTest(cval: number, tilesize:number, tileoverlap:number, x1:number, y1:number) { + desired = new TileBounds ( + x1 - tileoverlap, + x1 + tilesize + tileoverlap, + y1 - tileoverlap, + y1 + tilesize + tileoverlap + ); + filterC(cval); + console.log("\n\nC Value: " + cval + " TileSize: " + tilesize + " TileOverlap(px): " + tileoverlap + " Coords: " + `[X=${x1}, Y=${y1}]\nResults: `); + console.log(findRelatedTiles(c_filter, desired).map((x: Segment) => x.Data.Data)); +} + +runTest(0, 1024, 5, 1500, 1500); + +runTest(1, 5000, 5, 1500, 1500); -console.log("\n\nC Value: " + c_val + " TileSize: " + tileSize + " TileOverlap: " + tileOverlap + " Coords: " + `[X=${x}, Y=${y}]\nResults: `); -console.log(findRelatedTiles(c_filter, x, y).map((x: Segment) => x.Data.Data)); +runTest(0, 1024, 5, 0, 0); -filterC(c_val = 1); -console.log("\n\nC Value: " + c_val + " TileSize: " + tileSize + " TileOverlap: " + tileOverlap + " Coords: " + `[X=${x}, Y=${y}]\nResults: `); -console.log(findRelatedTiles(c_filter, x, y).map((x: Segment) => x.Data.Data)); +runTest(0, 1024, 5, 41940, 59240); -filterC(c_val = 0); x=0;y=0; -console.log("\n\nC Value: " + c_val + " TileSize: " + tileSize + " TileOverlap: " + tileOverlap + " Coords: " + `[X=${x}, Y=${y}]\nResults: `); -console.log(findRelatedTiles(c_filter, x, y).map((x: Segment) => x.Data.Data)); +runTest(0, 1024, 5, -tileSize - tileOverlap -1, 59240); -filterC(c_val = 0); x=41940;y=59240; -console.log("\n\nC Value: " + c_val + " TileSize: " + tileSize + " TileOverlap: " + tileOverlap + " Coords: " + `[X=${x}, Y=${y}]\nResults: `); -console.log(findRelatedTiles(c_filter, x, y).map((x: Segment) => x.Data.Data)); +runTest(0, 1024, 5, 41945, 59245); -filterC(c_val = 0); x=41945;y=59245; -console.log("\n\nC Value: " + c_val + " TileSize: " + tileSize + " TileOverlap: " + tileOverlap + " Coords: " + `[X=${x}, Y=${y}]\nResults: `); -console.log(findRelatedTiles(c_filter, x, y).map((x: Segment) => x.Data.Data)); +runTest(3, 1024, 5, 41940, 1500); -- cgit v1.2.1 From c7e95511d3f633e3c761456f69bb3d65ed98b238 Mon Sep 17 00:00:00 2001 From: cjd24 Date: Mon, 5 Mar 2018 22:50:50 +0000 Subject: small cleanup of things that wern't working, SAD COMMIT as need to look into another library for combining the images together --- src/conversion/czi/czi.ts | 7 + src/db/db.sql | 2209 --------------------------------------------- 2 files changed, 7 insertions(+), 2209 deletions(-) delete mode 100644 src/db/db.sql (limited to 'src') diff --git a/src/conversion/czi/czi.ts b/src/conversion/czi/czi.ts index df61033..9ca9ad7 100644 --- a/src/conversion/czi/czi.ts +++ b/src/conversion/czi/czi.ts @@ -224,3 +224,10 @@ runTest(0, 1024, 5, -tileSize - tileOverlap -1, 59240); runTest(0, 1024, 5, 41945, 59245); runTest(3, 1024, 5, 41940, 1500); + + + +filterC(0); +console.log("\n\n\n\n\n\n\n"); + +//begin work on getting the new tiles all nice diff --git a/src/db/db.sql b/src/db/db.sql deleted file mode 100644 index 45c2338..0000000 --- a/src/db/db.sql +++ /dev/null @@ -1,2209 +0,0 @@ --- --- PostgreSQL database dump --- - --- Dumped from database version 10.1 --- Dumped by pg_dump version 10.0 - --- Started on 2018-02-07 18:20:04 GMT - -SET statement_timeout = 0; -SET lock_timeout = 0; -SET idle_in_transaction_session_timeout = 0; -SET client_encoding = 'UTF8'; -SET standard_conforming_strings = on; -SET check_function_bodies = false; -SET client_min_messages = warning; -SET row_security = off; - --- --- TOC entry 10 (class 2615 OID 17274) --- Name: project_permissions; Type: SCHEMA; Schema: -; Owner: joshlee --- - -CREATE SCHEMA project_permissions; - - -ALTER SCHEMA project_permissions OWNER TO joshlee; - --- --- TOC entry 8 (class 2615 OID 16582) --- Name: user_permissions; Type: SCHEMA; Schema: -; Owner: joshlee --- - -CREATE SCHEMA user_permissions; - - -ALTER SCHEMA user_permissions OWNER TO joshlee; - --- --- TOC entry 1 (class 3079 OID 12544) --- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: --- - -CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog; - - --- --- TOC entry 2776 (class 0 OID 0) --- Dependencies: 1 --- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: --- - -COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language'; - - --- --- TOC entry 2 (class 3079 OID 17619) --- Name: pgcrypto; Type: EXTENSION; Schema: -; Owner: --- - -CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA public; - - --- --- TOC entry 2777 (class 0 OID 0) --- Dependencies: 2 --- Name: EXTENSION pgcrypto; Type: COMMENT; Schema: -; Owner: --- - -COMMENT ON EXTENSION pgcrypto IS 'cryptographic functions'; - - -SET search_path = project_permissions, pg_catalog; - --- --- TOC entry 240 (class 1255 OID 17515) --- Name: add_permission(); Type: FUNCTION; Schema: project_permissions; Owner: joshlee --- - -CREATE FUNCTION add_permission() RETURNS trigger - LANGUAGE plpgsql - AS $_$declare -var boolean; -begin -execute format('select exists (select project_name from project_permissions.project_permissions_list where $1.username = username and $1.project_name = project_name)') into var using new; - -if var then - execute format('UPDATE project_permissions.project_permissions_list SET %I=$1.permission_id WHERE username= $1.username AND project_name= $1.project_name',tg_table_name) using new; -else - execute format('insert into project_permissions.project_permissions_list (username,%I, project_name) values ($1.username, $1.permission_id,$1.project_name)',tg_table_name) using new; -end if; -return new; -end -$_$; - - -ALTER FUNCTION project_permissions.add_permission() OWNER TO joshlee; - --- --- TOC entry 254 (class 1255 OID 17371) --- Name: check_permission(text, text, text); Type: FUNCTION; Schema: project_permissions; Owner: joshlee --- - -CREATE FUNCTION check_permission(username text, permission text, project text) RETURNS boolean - LANGUAGE plpgsql - AS $_$ -declare var boolean; -begin -execute format('select exists(select * from project_permissions.%I where username = $1 and project_name = $2)',permission) into var using username,project; -return var; -end; - - -$_$; - - -ALTER FUNCTION project_permissions.check_permission(username text, permission text, project text) OWNER TO joshlee; - --- --- TOC entry 247 (class 1255 OID 17281) --- Name: prevent_edit(); Type: FUNCTION; Schema: project_permissions; Owner: joshlee --- - -CREATE FUNCTION prevent_edit() RETURNS trigger - LANGUAGE plpgsql - AS $$ -BEGIN - RAISE unique_violation USING MESSAGE = 'Cannot edit user permissions'; -END; - - - - - -$$; - - -ALTER FUNCTION project_permissions.prevent_edit() OWNER TO joshlee; - --- --- TOC entry 275 (class 1255 OID 17279) --- Name: prevent_owner_delete(); Type: FUNCTION; Schema: project_permissions; Owner: joshlee --- - -CREATE FUNCTION prevent_owner_delete() RETURNS trigger - LANGUAGE plpgsql - AS $_$declare -var text; -var2 integer; -begin - -select owner into var from project where old.project_name = project_name; -execute format('select count(*) from project_permissions.%I where username = $2 and $1.project_name = project_name',tg_table_name) into var2 using old,var; - if var2 >1 then - return old; - end if; - - - if var = old.username then - RAISE exception 'cannot delete project owner'; - end if; -return old; -end - - - -$_$; - - -ALTER FUNCTION project_permissions.prevent_owner_delete() OWNER TO joshlee; - --- --- TOC entry 262 (class 1255 OID 17280) --- Name: prevent_undefined_project_grant(); Type: FUNCTION; Schema: project_permissions; Owner: joshlee --- - -CREATE FUNCTION prevent_undefined_project_grant() RETURNS trigger - LANGUAGE plpgsql - AS $_$declare -var text; -var2 text; -var3 boolean; -begin - -execute format('select owner from project where $1.project_name = project_name') into var using new; -if var = new.username then - return new; -end if; - -execute format('select project_name from project_permissions.%I where $1.granted_by = permission_id',tg_table_name) into var2 using new; -if var2 != new.project_name or new.granted_by is null or new.permission_id = new.granted_by then - RAISE exception 'Must be granted permission'; -end if; - - - -return new; -end -$_$; - - -ALTER FUNCTION project_permissions.prevent_undefined_project_grant() OWNER TO joshlee; - -SET search_path = public, pg_catalog; - --- --- TOC entry 245 (class 1255 OID 17312) --- Name: give_owner_permissions(); Type: FUNCTION; Schema: public; Owner: joshlee --- - -CREATE FUNCTION give_owner_permissions() RETURNS trigger - LANGUAGE plpgsql - AS $_$declare - -BEGIN -execute format('insert into project_permissions.add_files (username,project_name ) values ($1.owner,$1.project_name) ') using new; -execute format('insert into project_permissions.edit_files (username,project_name ) values ($1.owner,$1.project_name) ') using new; -execute format('insert into project_permissions.remove_files (username,project_name ) values ($1.owner,$1.project_name) ') using new; -execute format('insert into project_permissions.view_files (username,project_name ) values ($1.owner,$1.project_name) ') using new; - - - - - - - -RETURN OLD; -END; - - - -$_$; - - -ALTER FUNCTION public.give_owner_permissions() OWNER TO joshlee; - --- --- TOC entry 286 (class 1255 OID 17577) --- Name: set_user_permissions(); Type: FUNCTION; Schema: public; Owner: joshlee --- - -CREATE FUNCTION set_user_permissions() RETURNS trigger - LANGUAGE plpgsql - AS $_$begin -execute format('insert into user_permissions.user_permissions_list (username) values ($1.username)') using new; -return new; -end -$_$; - - -ALTER FUNCTION public.set_user_permissions() OWNER TO joshlee; - -SET search_path = user_permissions, pg_catalog; - --- --- TOC entry 269 (class 1255 OID 17579) --- Name: add_permission(); Type: FUNCTION; Schema: user_permissions; Owner: joshlee --- - -CREATE FUNCTION add_permission() RETURNS trigger - LANGUAGE plpgsql - AS $_$ -begin - execute format('UPDATE user_permissions.user_permissions_list SET %I=$1.permission_id WHERE username= $1.username',tg_table_name) using new; - return new; -end - -$_$; - - -ALTER FUNCTION user_permissions.add_permission() OWNER TO joshlee; - --- --- TOC entry 292 (class 1255 OID 17370) --- Name: check_permission(text, text); Type: FUNCTION; Schema: user_permissions; Owner: joshlee --- - -CREATE FUNCTION check_permission(username text, permission text) RETURNS boolean - LANGUAGE plpgsql - AS $_$declare var boolean; -begin -execute format('select exists(select * from user_permissions.%I where username = $1)',permission) into var using username; -return var; -end; -$_$; - - -ALTER FUNCTION user_permissions.check_permission(username text, permission text) OWNER TO joshlee; - --- --- TOC entry 251 (class 1255 OID 16907) --- Name: prevent_admin_delete(); Type: FUNCTION; Schema: user_permissions; Owner: joshlee --- - -CREATE FUNCTION prevent_admin_delete() RETURNS trigger - LANGUAGE plpgsql - AS $$BEGIN -IF OLD.username = 'admin' THEN - RAISE unique_violation USING MESSAGE = 'Cannot delete admin user'; -END IF; -RETURN OLD; -END; - -$$; - - -ALTER FUNCTION user_permissions.prevent_admin_delete() OWNER TO joshlee; - --- --- TOC entry 255 (class 1255 OID 16911) --- Name: prevent_edit(); Type: FUNCTION; Schema: user_permissions; Owner: joshlee --- - -CREATE FUNCTION prevent_edit() RETURNS trigger - LANGUAGE plpgsql - AS $$BEGIN - RAISE unique_violation USING MESSAGE = 'Cannot edit user permissions'; -END; - - - -$$; - - -ALTER FUNCTION user_permissions.prevent_edit() OWNER TO joshlee; - --- --- TOC entry 274 (class 1255 OID 16924) --- Name: prevent_undefined_grant(); Type: FUNCTION; Schema: user_permissions; Owner: joshlee --- - -CREATE FUNCTION prevent_undefined_grant() RETURNS trigger - LANGUAGE plpgsql - AS $$BEGIN -if new.granted_by is NULL -or new.permission_id = new.granted_by then - RAISE unique_violation USING MESSAGE = 'access not granted'; -end if; -RETURN NEW; -END; -$$; - - -ALTER FUNCTION user_permissions.prevent_undefined_grant() OWNER TO joshlee; - --- --- TOC entry 288 (class 1255 OID 16726) --- Name: userexists(text); Type: FUNCTION; Schema: user_permissions; Owner: joshlee --- - -CREATE FUNCTION userexists(usertocheck text) RETURNS boolean - LANGUAGE plpgsql - AS $$ -begin -if ( -select exists(select * from user_info.user where username = usertocheck)) -then return true; -else return false; -end if; -end; -$$; - - -ALTER FUNCTION user_permissions.userexists(usertocheck text) OWNER TO joshlee; - -SET search_path = public, pg_catalog; - --- --- TOC entry 219 (class 1259 OID 17314) --- Name: af_id_seq; Type: SEQUENCE; Schema: public; Owner: joshlee --- - -CREATE SEQUENCE af_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE af_id_seq OWNER TO joshlee; - -SET search_path = project_permissions, pg_catalog; - -SET default_tablespace = ''; - -SET default_with_oids = false; - --- --- TOC entry 210 (class 1259 OID 17030) --- Name: add_files; Type: TABLE; Schema: project_permissions; Owner: joshlee --- - -CREATE TABLE add_files ( - username text NOT NULL, - permission_id integer DEFAULT nextval('public.af_id_seq'::regclass) NOT NULL, - granted_by integer, - project_name text NOT NULL -); - - -ALTER TABLE add_files OWNER TO joshlee; - -SET search_path = public, pg_catalog; - --- --- TOC entry 220 (class 1259 OID 17317) --- Name: ef_id_seq; Type: SEQUENCE; Schema: public; Owner: joshlee --- - -CREATE SEQUENCE ef_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE ef_id_seq OWNER TO joshlee; - -SET search_path = project_permissions, pg_catalog; - --- --- TOC entry 211 (class 1259 OID 17086) --- Name: edit_files; Type: TABLE; Schema: project_permissions; Owner: joshlee --- - -CREATE TABLE edit_files ( - username text NOT NULL, - permission_id integer DEFAULT nextval('public.ef_id_seq'::regclass) NOT NULL, - granted_by integer, - project_name text NOT NULL -); - - -ALTER TABLE edit_files OWNER TO joshlee; - --- --- TOC entry 230 (class 1259 OID 17475) --- Name: project_permissions_list; Type: TABLE; Schema: project_permissions; Owner: joshlee --- - -CREATE TABLE project_permissions_list ( - username text NOT NULL, - add_files integer, - edit_files integer, - remove_files integer, - view_files integer, - project_name text NOT NULL -); - - -ALTER TABLE project_permissions_list OWNER TO joshlee; - -SET search_path = public, pg_catalog; - --- --- TOC entry 221 (class 1259 OID 17320) --- Name: rf_id_seq; Type: SEQUENCE; Schema: public; Owner: joshlee --- - -CREATE SEQUENCE rf_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE rf_id_seq OWNER TO joshlee; - -SET search_path = project_permissions, pg_catalog; - --- --- TOC entry 212 (class 1259 OID 17110) --- Name: remove_files; Type: TABLE; Schema: project_permissions; Owner: joshlee --- - -CREATE TABLE remove_files ( - username text NOT NULL, - permission_id integer DEFAULT nextval('public.rf_id_seq'::regclass) NOT NULL, - granted_by integer, - project_name text NOT NULL -); - - -ALTER TABLE remove_files OWNER TO joshlee; - -SET search_path = public, pg_catalog; - --- --- TOC entry 223 (class 1259 OID 17326) --- Name: vf_id_seq; Type: SEQUENCE; Schema: public; Owner: joshlee --- - -CREATE SEQUENCE vf_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE vf_id_seq OWNER TO joshlee; - -SET search_path = project_permissions, pg_catalog; - --- --- TOC entry 213 (class 1259 OID 17158) --- Name: view_files; Type: TABLE; Schema: project_permissions; Owner: joshlee --- - -CREATE TABLE view_files ( - username text NOT NULL, - permission_id integer DEFAULT nextval('public.vf_id_seq'::regclass) NOT NULL, - granted_by integer, - project_name text NOT NULL -); - - -ALTER TABLE view_files OWNER TO joshlee; - -SET search_path = public, pg_catalog; - --- --- TOC entry 224 (class 1259 OID 17329) --- Name: cp_id_seq; Type: SEQUENCE; Schema: public; Owner: joshlee --- - -CREATE SEQUENCE cp_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE cp_id_seq OWNER TO joshlee; - --- --- TOC entry 225 (class 1259 OID 17332) --- Name: cu_id_seq; Type: SEQUENCE; Schema: public; Owner: joshlee --- - -CREATE SEQUENCE cu_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE cu_id_seq OWNER TO joshlee; - --- --- TOC entry 209 (class 1259 OID 16969) --- Name: dirent; Type: TABLE; Schema: public; Owner: joshlee --- - -CREATE TABLE dirent ( - project_name pg_catalog.text, - "UUID" uuid DEFAULT gen_random_uuid() NOT NULL, - super_folder uuid -); - - -ALTER TABLE dirent OWNER TO joshlee; - --- --- TOC entry 226 (class 1259 OID 17335) --- Name: eu_id_seq; Type: SEQUENCE; Schema: public; Owner: joshlee --- - -CREATE SEQUENCE eu_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE eu_id_seq OWNER TO joshlee; - --- --- TOC entry 200 (class 1259 OID 16447) --- Name: folder; Type: TABLE; Schema: public; Owner: joshlee --- - -CREATE TABLE folder ( - folder_name pg_catalog.text DEFAULT '"new folder"'::pg_catalog.text, - "UUID" uuid NOT NULL -); - - -ALTER TABLE folder OWNER TO joshlee; - --- --- TOC entry 201 (class 1259 OID 16494) --- Name: image; Type: TABLE; Schema: public; Owner: joshlee --- - -CREATE TABLE image ( - image_name pg_catalog.text, - "UUID" uuid NOT NULL -); - - -ALTER TABLE image OWNER TO joshlee; - --- --- TOC entry 208 (class 1259 OID 16963) --- Name: permission_id_seq; Type: SEQUENCE; Schema: public; Owner: joshlee --- - -CREATE SEQUENCE permission_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE permission_id_seq OWNER TO joshlee; - --- --- TOC entry 207 (class 1259 OID 16941) --- Name: permission_seq; Type: SEQUENCE; Schema: public; Owner: joshlee --- - -CREATE SEQUENCE permission_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE permission_seq OWNER TO joshlee; - --- --- TOC entry 199 (class 1259 OID 16396) --- Name: project; Type: TABLE; Schema: public; Owner: joshlee --- - -CREATE TABLE project ( - project_name pg_catalog.text NOT NULL, - owner pg_catalog.text NOT NULL, - public_metadata json, - private_metadata json, - admin_metadata json -); - - -ALTER TABLE project OWNER TO joshlee; - --- --- TOC entry 204 (class 1259 OID 16799) --- Name: project_name; Type: SEQUENCE; Schema: public; Owner: joshlee --- - -CREATE SEQUENCE project_name - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE project_name OWNER TO joshlee; - --- --- TOC entry 222 (class 1259 OID 17323) --- Name: rp_id_seq; Type: SEQUENCE; Schema: public; Owner: joshlee --- - -CREATE SEQUENCE rp_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE rp_id_seq OWNER TO joshlee; - --- --- TOC entry 227 (class 1259 OID 17338) --- Name: ru_id_seq; Type: SEQUENCE; Schema: public; Owner: joshlee --- - -CREATE SEQUENCE ru_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE ru_id_seq OWNER TO joshlee; - --- --- TOC entry 202 (class 1259 OID 16502) --- Name: text; Type: TABLE; Schema: public; Owner: joshlee --- - -CREATE TABLE text ( - text_name pg_catalog.text, - "UUID" uuid NOT NULL -); - - -ALTER TABLE text OWNER TO joshlee; - --- --- TOC entry 203 (class 1259 OID 16552) --- Name: user; Type: TABLE; Schema: public; Owner: joshlee --- - -CREATE TABLE "user" ( - username pg_catalog.text NOT NULL, - password character(32), - public_user_metadata json, - private_user_metadata json, - public_admin_metadata json, - private_admin_metadata json -); - - -ALTER TABLE "user" OWNER TO joshlee; - --- --- TOC entry 205 (class 1259 OID 16876) --- Name: user_id_seq; Type: SEQUENCE; Schema: public; Owner: joshlee --- - -CREATE SEQUENCE user_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE user_id_seq OWNER TO joshlee; - --- --- TOC entry 233 (class 1259 OID 17603) --- Name: view_current_user; Type: VIEW; Schema: public; Owner: joshlee --- - -CREATE VIEW view_current_user AS - SELECT "user".username, - "user".public_user_metadata, - "user".private_user_metadata, - "user".public_admin_metadata - FROM "user"; - - -ALTER TABLE view_current_user OWNER TO joshlee; - --- --- TOC entry 234 (class 1259 OID 17611) --- Name: view_projects_public; Type: VIEW; Schema: public; Owner: joshlee --- - -CREATE VIEW view_projects_public AS - SELECT project.project_name, - project.owner, - project.public_metadata - FROM project; - - -ALTER TABLE view_projects_public OWNER TO joshlee; - --- --- TOC entry 235 (class 1259 OID 17615) --- Name: view_projects_regular; Type: VIEW; Schema: public; Owner: joshlee --- - -CREATE VIEW view_projects_regular AS - SELECT project.project_name, - project.owner, - project.public_metadata, - project.private_metadata - FROM project; - - -ALTER TABLE view_projects_regular OWNER TO joshlee; - --- --- TOC entry 232 (class 1259 OID 17599) --- Name: view_users_public; Type: VIEW; Schema: public; Owner: joshlee --- - -CREATE VIEW view_users_public AS - SELECT "user".username, - "user".public_user_metadata, - "user".public_admin_metadata - FROM "user"; - - -ALTER TABLE view_users_public OWNER TO joshlee; - --- --- TOC entry 228 (class 1259 OID 17341) --- Name: vp_id_seq; Type: SEQUENCE; Schema: public; Owner: joshlee --- - -CREATE SEQUENCE vp_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE vp_id_seq OWNER TO joshlee; - --- --- TOC entry 229 (class 1259 OID 17344) --- Name: vu_id_seq; Type: SEQUENCE; Schema: public; Owner: joshlee --- - -CREATE SEQUENCE vu_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE vu_id_seq OWNER TO joshlee; - -SET search_path = user_permissions, pg_catalog; - --- --- TOC entry 214 (class 1259 OID 17182) --- Name: create_project; Type: TABLE; Schema: user_permissions; Owner: joshlee --- - -CREATE TABLE create_project ( - username text NOT NULL, - permission_id integer DEFAULT nextval('public.cp_id_seq'::regclass) NOT NULL, - granted_by integer -); - - -ALTER TABLE create_project OWNER TO joshlee; - --- --- TOC entry 206 (class 1259 OID 16887) --- Name: create_users; Type: TABLE; Schema: user_permissions; Owner: joshlee --- - -CREATE TABLE create_users ( - username text NOT NULL, - permission_id integer DEFAULT nextval('public.cu_id_seq'::regclass) NOT NULL, - granted_by integer -); - - -ALTER TABLE create_users OWNER TO joshlee; - --- --- TOC entry 215 (class 1259 OID 17201) --- Name: edit_users; Type: TABLE; Schema: user_permissions; Owner: joshlee --- - -CREATE TABLE edit_users ( - username text NOT NULL, - permission_id integer DEFAULT nextval('public.eu_id_seq'::regclass) NOT NULL, - granted_by integer -); - - -ALTER TABLE edit_users OWNER TO joshlee; - --- --- TOC entry 216 (class 1259 OID 17220) --- Name: remove_users; Type: TABLE; Schema: user_permissions; Owner: joshlee --- - -CREATE TABLE remove_users ( - username text NOT NULL, - permission_id integer DEFAULT nextval('public.ru_id_seq'::regclass) NOT NULL, - granted_by integer -); - - -ALTER TABLE remove_users OWNER TO joshlee; - --- --- TOC entry 231 (class 1259 OID 17533) --- Name: user_permissions_list; Type: TABLE; Schema: user_permissions; Owner: joshlee --- - -CREATE TABLE user_permissions_list ( - username text NOT NULL, - create_project integer, - create_users integer, - edit_users integer, - remove_users integer, - view_projects integer, - view_users integer -); - - -ALTER TABLE user_permissions_list OWNER TO joshlee; - --- --- TOC entry 217 (class 1259 OID 17233) --- Name: view_projects; Type: TABLE; Schema: user_permissions; Owner: joshlee --- - -CREATE TABLE view_projects ( - username text NOT NULL, - permission_id integer DEFAULT nextval('public.vp_id_seq'::regclass) NOT NULL, - granted_by integer -); - - -ALTER TABLE view_projects OWNER TO joshlee; - --- --- TOC entry 218 (class 1259 OID 17246) --- Name: view_users; Type: TABLE; Schema: user_permissions; Owner: joshlee --- - -CREATE TABLE view_users ( - username text NOT NULL, - permission_id integer DEFAULT nextval('public.vu_id_seq'::regclass) NOT NULL, - granted_by integer -); - - -ALTER TABLE view_users OWNER TO joshlee; - -SET search_path = project_permissions, pg_catalog; - --- --- TOC entry 2746 (class 0 OID 17030) --- Dependencies: 210 --- Data for Name: add_files; Type: TABLE DATA; Schema: project_permissions; Owner: joshlee --- - - - --- --- TOC entry 2747 (class 0 OID 17086) --- Dependencies: 211 --- Data for Name: edit_files; Type: TABLE DATA; Schema: project_permissions; Owner: joshlee --- - - - --- --- TOC entry 2766 (class 0 OID 17475) --- Dependencies: 230 --- Data for Name: project_permissions_list; Type: TABLE DATA; Schema: project_permissions; Owner: joshlee --- - - - --- --- TOC entry 2748 (class 0 OID 17110) --- Dependencies: 212 --- Data for Name: remove_files; Type: TABLE DATA; Schema: project_permissions; Owner: joshlee --- - - - --- --- TOC entry 2749 (class 0 OID 17158) --- Dependencies: 213 --- Data for Name: view_files; Type: TABLE DATA; Schema: project_permissions; Owner: joshlee --- - - - -SET search_path = public, pg_catalog; - --- --- TOC entry 2745 (class 0 OID 16969) --- Dependencies: 209 --- Data for Name: dirent; Type: TABLE DATA; Schema: public; Owner: joshlee --- - - - --- --- TOC entry 2736 (class 0 OID 16447) --- Dependencies: 200 --- Data for Name: folder; Type: TABLE DATA; Schema: public; Owner: joshlee --- - - - --- --- TOC entry 2737 (class 0 OID 16494) --- Dependencies: 201 --- Data for Name: image; Type: TABLE DATA; Schema: public; Owner: joshlee --- - - - --- --- TOC entry 2735 (class 0 OID 16396) --- Dependencies: 199 --- Data for Name: project; Type: TABLE DATA; Schema: public; Owner: joshlee --- - - - --- --- TOC entry 2738 (class 0 OID 16502) --- Dependencies: 202 --- Data for Name: text; Type: TABLE DATA; Schema: public; Owner: joshlee --- - - - --- --- TOC entry 2739 (class 0 OID 16552) --- Dependencies: 203 --- Data for Name: user; Type: TABLE DATA; Schema: public; Owner: joshlee --- - -INSERT INTO "user" VALUES ('admin', '21232f297a57a5a743894a0e4a801fc3', NULL, NULL, NULL, NULL); -INSERT INTO "user" VALUES ('josh', 'f94adcc3ddda04a8f34928d862f404b4', NULL, NULL, NULL, NULL); -INSERT INTO "user" VALUES ('user2', '7e58d63b60197ceb55a1c487989a3720', NULL, NULL, NULL, NULL); -INSERT INTO "user" VALUES ('user3', '92877af70a45fd6a2ed7fe81e1236b78', NULL, NULL, NULL, NULL); - - -SET search_path = user_permissions, pg_catalog; - --- --- TOC entry 2750 (class 0 OID 17182) --- Dependencies: 214 --- Data for Name: create_project; Type: TABLE DATA; Schema: user_permissions; Owner: joshlee --- - -INSERT INTO create_project VALUES ('admin', 1, 1); - - --- --- TOC entry 2742 (class 0 OID 16887) --- Dependencies: 206 --- Data for Name: create_users; Type: TABLE DATA; Schema: user_permissions; Owner: joshlee --- - -INSERT INTO create_users VALUES ('admin', 1, 1); - - --- --- TOC entry 2751 (class 0 OID 17201) --- Dependencies: 215 --- Data for Name: edit_users; Type: TABLE DATA; Schema: user_permissions; Owner: joshlee --- - -INSERT INTO edit_users VALUES ('admin', 1, 1); - - --- --- TOC entry 2752 (class 0 OID 17220) --- Dependencies: 216 --- Data for Name: remove_users; Type: TABLE DATA; Schema: user_permissions; Owner: joshlee --- - -INSERT INTO remove_users VALUES ('admin', 1, 1); - - --- --- TOC entry 2767 (class 0 OID 17533) --- Dependencies: 231 --- Data for Name: user_permissions_list; Type: TABLE DATA; Schema: user_permissions; Owner: joshlee --- - -INSERT INTO user_permissions_list VALUES ('josh', NULL, NULL, NULL, NULL, NULL, NULL); -INSERT INTO user_permissions_list VALUES ('user2', NULL, NULL, NULL, NULL, NULL, NULL); -INSERT INTO user_permissions_list VALUES ('user3', NULL, NULL, NULL, NULL, NULL, NULL); - - --- --- TOC entry 2753 (class 0 OID 17233) --- Dependencies: 217 --- Data for Name: view_projects; Type: TABLE DATA; Schema: user_permissions; Owner: joshlee --- - -INSERT INTO view_projects VALUES ('admin', 1, 1); - - --- --- TOC entry 2754 (class 0 OID 17246) --- Dependencies: 218 --- Data for Name: view_users; Type: TABLE DATA; Schema: user_permissions; Owner: joshlee --- - -INSERT INTO view_users VALUES ('admin', 1, 1); - - -SET search_path = public, pg_catalog; - --- --- TOC entry 2779 (class 0 OID 0) --- Dependencies: 219 --- Name: af_id_seq; Type: SEQUENCE SET; Schema: public; Owner: joshlee --- - -SELECT pg_catalog.setval('af_id_seq', 37, true); - - --- --- TOC entry 2780 (class 0 OID 0) --- Dependencies: 224 --- Name: cp_id_seq; Type: SEQUENCE SET; Schema: public; Owner: joshlee --- - -SELECT pg_catalog.setval('cp_id_seq', 5, true); - - --- --- TOC entry 2781 (class 0 OID 0) --- Dependencies: 225 --- Name: cu_id_seq; Type: SEQUENCE SET; Schema: public; Owner: joshlee --- - -SELECT pg_catalog.setval('cu_id_seq', 2, true); - - --- --- TOC entry 2782 (class 0 OID 0) --- Dependencies: 220 --- Name: ef_id_seq; Type: SEQUENCE SET; Schema: public; Owner: joshlee --- - -SELECT pg_catalog.setval('ef_id_seq', 32, true); - - --- --- TOC entry 2783 (class 0 OID 0) --- Dependencies: 226 --- Name: eu_id_seq; Type: SEQUENCE SET; Schema: public; Owner: joshlee --- - -SELECT pg_catalog.setval('eu_id_seq', 3, true); - - --- --- TOC entry 2784 (class 0 OID 0) --- Dependencies: 208 --- Name: permission_id_seq; Type: SEQUENCE SET; Schema: public; Owner: joshlee --- - -SELECT pg_catalog.setval('permission_id_seq', 145, true); - - --- --- TOC entry 2785 (class 0 OID 0) --- Dependencies: 207 --- Name: permission_seq; Type: SEQUENCE SET; Schema: public; Owner: joshlee --- - -SELECT pg_catalog.setval('permission_seq', 3, true); - - --- --- TOC entry 2786 (class 0 OID 0) --- Dependencies: 204 --- Name: project_name; Type: SEQUENCE SET; Schema: public; Owner: joshlee --- - -SELECT pg_catalog.setval('project_name', 1, true); - - --- --- TOC entry 2787 (class 0 OID 0) --- Dependencies: 221 --- Name: rf_id_seq; Type: SEQUENCE SET; Schema: public; Owner: joshlee --- - -SELECT pg_catalog.setval('rf_id_seq', 33, true); - - --- --- TOC entry 2788 (class 0 OID 0) --- Dependencies: 222 --- Name: rp_id_seq; Type: SEQUENCE SET; Schema: public; Owner: joshlee --- - -SELECT pg_catalog.setval('rp_id_seq', 2, true); - - --- --- TOC entry 2789 (class 0 OID 0) --- Dependencies: 227 --- Name: ru_id_seq; Type: SEQUENCE SET; Schema: public; Owner: joshlee --- - -SELECT pg_catalog.setval('ru_id_seq', 3, true); - - --- --- TOC entry 2790 (class 0 OID 0) --- Dependencies: 205 --- Name: user_id_seq; Type: SEQUENCE SET; Schema: public; Owner: joshlee --- - -SELECT pg_catalog.setval('user_id_seq', 3, true); - - --- --- TOC entry 2791 (class 0 OID 0) --- Dependencies: 223 --- Name: vf_id_seq; Type: SEQUENCE SET; Schema: public; Owner: joshlee --- - -SELECT pg_catalog.setval('vf_id_seq', 24, true); - - --- --- TOC entry 2792 (class 0 OID 0) --- Dependencies: 228 --- Name: vp_id_seq; Type: SEQUENCE SET; Schema: public; Owner: joshlee --- - -SELECT pg_catalog.setval('vp_id_seq', 3, true); - - --- --- TOC entry 2793 (class 0 OID 0) --- Dependencies: 229 --- Name: vu_id_seq; Type: SEQUENCE SET; Schema: public; Owner: joshlee --- - -SELECT pg_catalog.setval('vu_id_seq', 2, true); - - -SET search_path = project_permissions, pg_catalog; - --- --- TOC entry 2502 (class 2606 OID 17038) --- Name: add_files add_files_pkey; Type: CONSTRAINT; Schema: project_permissions; Owner: joshlee --- - -ALTER TABLE ONLY add_files - ADD CONSTRAINT add_files_pkey PRIMARY KEY (permission_id); - - --- --- TOC entry 2504 (class 2606 OID 17094) --- Name: edit_files edit_files_pkey; Type: CONSTRAINT; Schema: project_permissions; Owner: joshlee --- - -ALTER TABLE ONLY edit_files - ADD CONSTRAINT edit_files_pkey PRIMARY KEY (permission_id); - - --- --- TOC entry 2520 (class 2606 OID 17512) --- Name: project_permissions_list project_permissions_list_pkey; Type: CONSTRAINT; Schema: project_permissions; Owner: joshlee --- - -ALTER TABLE ONLY project_permissions_list - ADD CONSTRAINT project_permissions_list_pkey PRIMARY KEY (username, project_name); - - --- --- TOC entry 2506 (class 2606 OID 17118) --- Name: remove_files remove_files_pkey; Type: CONSTRAINT; Schema: project_permissions; Owner: joshlee --- - -ALTER TABLE ONLY remove_files - ADD CONSTRAINT remove_files_pkey PRIMARY KEY (permission_id); - - --- --- TOC entry 2508 (class 2606 OID 17166) --- Name: view_files view_files_pkey; Type: CONSTRAINT; Schema: project_permissions; Owner: joshlee --- - -ALTER TABLE ONLY view_files - ADD CONSTRAINT view_files_pkey PRIMARY KEY (permission_id); - - -SET search_path = public, pg_catalog; - --- --- TOC entry 2500 (class 2606 OID 17665) --- Name: dirent dirent_pkey; Type: CONSTRAINT; Schema: public; Owner: joshlee --- - -ALTER TABLE ONLY dirent - ADD CONSTRAINT dirent_pkey PRIMARY KEY ("UUID"); - - --- --- TOC entry 2488 (class 2606 OID 17667) --- Name: folder folder_pkey; Type: CONSTRAINT; Schema: public; Owner: joshlee --- - -ALTER TABLE ONLY folder - ADD CONSTRAINT folder_pkey PRIMARY KEY ("UUID"); - - --- --- TOC entry 2490 (class 2606 OID 17684) --- Name: image image_pkey; Type: CONSTRAINT; Schema: public; Owner: joshlee --- - -ALTER TABLE ONLY image - ADD CONSTRAINT image_pkey PRIMARY KEY ("UUID"); - - --- --- TOC entry 2484 (class 2606 OID 16668) --- Name: project project_pkey; Type: CONSTRAINT; Schema: public; Owner: joshlee --- - -ALTER TABLE ONLY project - ADD CONSTRAINT project_pkey PRIMARY KEY (project_name); - - --- --- TOC entry 2486 (class 2606 OID 16404) --- Name: project projects_project_name_key; Type: CONSTRAINT; Schema: public; Owner: joshlee --- - -ALTER TABLE ONLY project - ADD CONSTRAINT projects_project_name_key UNIQUE (project_name); - - --- --- TOC entry 2492 (class 2606 OID 17686) --- Name: text text_pkey; Type: CONSTRAINT; Schema: public; Owner: joshlee --- - -ALTER TABLE ONLY text - ADD CONSTRAINT text_pkey PRIMARY KEY ("UUID"); - - --- --- TOC entry 2494 (class 2606 OID 16562) --- Name: user user _username_key; Type: CONSTRAINT; Schema: public; Owner: joshlee --- - -ALTER TABLE ONLY "user" - ADD CONSTRAINT "user _username_key" UNIQUE (username); - - --- --- TOC entry 2496 (class 2606 OID 16770) --- Name: user user_pkey; Type: CONSTRAINT; Schema: public; Owner: joshlee --- - -ALTER TABLE ONLY "user" - ADD CONSTRAINT user_pkey PRIMARY KEY (username); - - -SET search_path = user_permissions, pg_catalog; - --- --- TOC entry 2510 (class 2606 OID 17190) --- Name: create_project create_project_pkey; Type: CONSTRAINT; Schema: user_permissions; Owner: joshlee --- - -ALTER TABLE ONLY create_project - ADD CONSTRAINT create_project_pkey PRIMARY KEY (permission_id); - - --- --- TOC entry 2498 (class 2606 OID 16950) --- Name: create_users create_user_pkey; Type: CONSTRAINT; Schema: user_permissions; Owner: joshlee --- - -ALTER TABLE ONLY create_users - ADD CONSTRAINT create_user_pkey PRIMARY KEY (permission_id); - - --- --- TOC entry 2514 (class 2606 OID 17227) --- Name: remove_users remove_users_pkey; Type: CONSTRAINT; Schema: user_permissions; Owner: joshlee --- - -ALTER TABLE ONLY remove_users - ADD CONSTRAINT remove_users_pkey PRIMARY KEY (permission_id); - - --- --- TOC entry 2512 (class 2606 OID 17208) --- Name: edit_users untitled_table_pkey; Type: CONSTRAINT; Schema: user_permissions; Owner: joshlee --- - -ALTER TABLE ONLY edit_users - ADD CONSTRAINT untitled_table_pkey PRIMARY KEY (permission_id); - - --- --- TOC entry 2522 (class 2606 OID 17540) --- Name: user_permissions_list user_permissions_list_pkey; Type: CONSTRAINT; Schema: user_permissions; Owner: joshlee --- - -ALTER TABLE ONLY user_permissions_list - ADD CONSTRAINT user_permissions_list_pkey PRIMARY KEY (username); - - --- --- TOC entry 2516 (class 2606 OID 17240) --- Name: view_projects view_projects_pkey; Type: CONSTRAINT; Schema: user_permissions; Owner: joshlee --- - -ALTER TABLE ONLY view_projects - ADD CONSTRAINT view_projects_pkey PRIMARY KEY (permission_id); - - --- --- TOC entry 2518 (class 2606 OID 17253) --- Name: view_users view_users_pkey; Type: CONSTRAINT; Schema: user_permissions; Owner: joshlee --- - -ALTER TABLE ONLY view_users - ADD CONSTRAINT view_users_pkey PRIMARY KEY (permission_id); - - -SET search_path = project_permissions, pg_catalog; - --- --- TOC entry 2575 (class 2620 OID 17298) --- Name: add_files edit_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee --- - -CREATE TRIGGER edit_permission BEFORE UPDATE ON add_files FOR EACH ROW EXECUTE PROCEDURE prevent_edit(); - - --- --- TOC entry 2580 (class 2620 OID 17302) --- Name: edit_files edit_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee --- - -CREATE TRIGGER edit_permission BEFORE UPDATE ON edit_files FOR EACH ROW EXECUTE PROCEDURE prevent_edit(); - - --- --- TOC entry 2582 (class 2620 OID 17305) --- Name: remove_files edit_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee --- - -CREATE TRIGGER edit_permission BEFORE UPDATE ON remove_files FOR EACH ROW EXECUTE PROCEDURE prevent_edit(); - - --- --- TOC entry 2588 (class 2620 OID 17311) --- Name: view_files edit_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee --- - -CREATE TRIGGER edit_permission BEFORE UPDATE ON view_files FOR EACH ROW EXECUTE PROCEDURE prevent_edit(); - - --- --- TOC entry 2574 (class 2620 OID 17297) --- Name: add_files grant_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee --- - -CREATE TRIGGER grant_permission BEFORE INSERT ON add_files FOR EACH ROW EXECUTE PROCEDURE prevent_undefined_project_grant(); - - --- --- TOC entry 2578 (class 2620 OID 17300) --- Name: edit_files grant_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee --- - -CREATE TRIGGER grant_permission BEFORE INSERT ON edit_files FOR EACH ROW EXECUTE PROCEDURE prevent_undefined_project_grant(); - - --- --- TOC entry 2583 (class 2620 OID 17303) --- Name: remove_files grant_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee --- - -CREATE TRIGGER grant_permission BEFORE INSERT ON remove_files FOR EACH ROW EXECUTE PROCEDURE prevent_undefined_project_grant(); - - --- --- TOC entry 2586 (class 2620 OID 17309) --- Name: view_files grant_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee --- - -CREATE TRIGGER grant_permission BEFORE INSERT ON view_files FOR EACH ROW EXECUTE PROCEDURE prevent_undefined_project_grant(); - - --- --- TOC entry 2577 (class 2620 OID 17516) --- Name: add_files insert_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee --- - -CREATE TRIGGER insert_permission AFTER INSERT ON add_files FOR EACH ROW EXECUTE PROCEDURE add_permission(); - - --- --- TOC entry 2581 (class 2620 OID 17517) --- Name: edit_files insert_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee --- - -CREATE TRIGGER insert_permission AFTER INSERT ON edit_files FOR EACH ROW EXECUTE PROCEDURE add_permission(); - - --- --- TOC entry 2585 (class 2620 OID 17518) --- Name: remove_files insert_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee --- - -CREATE TRIGGER insert_permission AFTER INSERT ON remove_files FOR EACH ROW EXECUTE PROCEDURE add_permission(); - - --- --- TOC entry 2589 (class 2620 OID 17519) --- Name: view_files insert_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee --- - -CREATE TRIGGER insert_permission AFTER INSERT ON view_files FOR EACH ROW EXECUTE PROCEDURE add_permission(); - - --- --- TOC entry 2576 (class 2620 OID 17299) --- Name: add_files remove_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee --- - -CREATE TRIGGER remove_permission BEFORE DELETE ON add_files FOR EACH ROW EXECUTE PROCEDURE prevent_owner_delete(); - - --- --- TOC entry 2579 (class 2620 OID 17301) --- Name: edit_files remove_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee --- - -CREATE TRIGGER remove_permission BEFORE DELETE ON edit_files FOR EACH ROW EXECUTE PROCEDURE prevent_owner_delete(); - - --- --- TOC entry 2584 (class 2620 OID 17304) --- Name: remove_files remove_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee --- - -CREATE TRIGGER remove_permission BEFORE DELETE ON remove_files FOR EACH ROW EXECUTE PROCEDURE prevent_owner_delete(); - - --- --- TOC entry 2587 (class 2620 OID 17310) --- Name: view_files remove_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee --- - -CREATE TRIGGER remove_permission BEFORE DELETE ON view_files FOR EACH ROW EXECUTE PROCEDURE prevent_owner_delete(); - - -SET search_path = public, pg_catalog; - --- --- TOC entry 2566 (class 2620 OID 17313) --- Name: project add_project; Type: TRIGGER; Schema: public; Owner: joshlee --- - -CREATE TRIGGER add_project AFTER INSERT ON project FOR EACH ROW EXECUTE PROCEDURE give_owner_permissions(); - - --- --- TOC entry 2569 (class 2620 OID 17578) --- Name: user add_user; Type: TRIGGER; Schema: public; Owner: joshlee --- - -CREATE TRIGGER add_user AFTER INSERT ON "user" FOR EACH ROW EXECUTE PROCEDURE set_user_permissions(); - - --- --- TOC entry 2567 (class 2620 OID 16912) --- Name: user user_delete; Type: TRIGGER; Schema: public; Owner: joshlee --- - -CREATE TRIGGER user_delete BEFORE DELETE ON "user" FOR EACH ROW EXECUTE PROCEDURE user_permissions.prevent_admin_delete(); - - --- --- TOC entry 2568 (class 2620 OID 16913) --- Name: user user_edit; Type: TRIGGER; Schema: public; Owner: joshlee --- - -CREATE TRIGGER user_edit BEFORE UPDATE ON "user" FOR EACH ROW EXECUTE PROCEDURE user_permissions.prevent_edit(); - - -SET search_path = user_permissions, pg_catalog; - --- --- TOC entry 2601 (class 2620 OID 17583) --- Name: remove_users add_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee --- - -CREATE TRIGGER add_permission AFTER INSERT ON remove_users FOR EACH ROW EXECUTE PROCEDURE add_permission(); - - --- --- TOC entry 2570 (class 2620 OID 16914) --- Name: create_users edit_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee --- - -CREATE TRIGGER edit_permission BEFORE UPDATE ON create_users FOR EACH ROW EXECUTE PROCEDURE prevent_edit(); - - --- --- TOC entry 2590 (class 2620 OID 17284) --- Name: create_project edit_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee --- - -CREATE TRIGGER edit_permission BEFORE UPDATE ON create_project FOR EACH ROW EXECUTE PROCEDURE prevent_edit(); - - --- --- TOC entry 2595 (class 2620 OID 17287) --- Name: edit_users edit_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee --- - -CREATE TRIGGER edit_permission BEFORE UPDATE ON edit_users FOR EACH ROW EXECUTE PROCEDURE prevent_edit(); - - --- --- TOC entry 2599 (class 2620 OID 17290) --- Name: remove_users edit_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee --- - -CREATE TRIGGER edit_permission BEFORE UPDATE ON remove_users FOR EACH ROW EXECUTE PROCEDURE prevent_edit(); - - --- --- TOC entry 2603 (class 2620 OID 17293) --- Name: view_projects edit_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee --- - -CREATE TRIGGER edit_permission BEFORE UPDATE ON view_projects FOR EACH ROW EXECUTE PROCEDURE prevent_edit(); - - --- --- TOC entry 2606 (class 2620 OID 17294) --- Name: view_users edit_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee --- - -CREATE TRIGGER edit_permission BEFORE UPDATE ON view_users FOR EACH ROW EXECUTE PROCEDURE prevent_edit(); - - --- --- TOC entry 2572 (class 2620 OID 16928) --- Name: create_users grant_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee --- - -CREATE TRIGGER grant_permission BEFORE INSERT ON create_users FOR EACH ROW EXECUTE PROCEDURE prevent_undefined_grant(); - - --- --- TOC entry 2592 (class 2620 OID 17282) --- Name: create_project grant_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee --- - -CREATE TRIGGER grant_permission BEFORE INSERT ON create_project FOR EACH ROW EXECUTE PROCEDURE prevent_undefined_grant(); - - --- --- TOC entry 2596 (class 2620 OID 17285) --- Name: edit_users grant_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee --- - -CREATE TRIGGER grant_permission BEFORE INSERT ON edit_users FOR EACH ROW EXECUTE PROCEDURE prevent_undefined_grant(); - - --- --- TOC entry 2600 (class 2620 OID 17289) --- Name: remove_users grant_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee --- - -CREATE TRIGGER grant_permission BEFORE INSERT ON remove_users FOR EACH ROW EXECUTE PROCEDURE prevent_undefined_grant(); - - --- --- TOC entry 2604 (class 2620 OID 17291) --- Name: view_projects grant_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee --- - -CREATE TRIGGER grant_permission BEFORE INSERT ON view_projects FOR EACH ROW EXECUTE PROCEDURE prevent_undefined_grant(); - - --- --- TOC entry 2608 (class 2620 OID 17295) --- Name: view_users grant_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee --- - -CREATE TRIGGER grant_permission BEFORE INSERT ON view_users FOR EACH ROW EXECUTE PROCEDURE prevent_undefined_grant(); - - --- --- TOC entry 2593 (class 2620 OID 17580) --- Name: create_project insert_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee --- - -CREATE TRIGGER insert_permission AFTER INSERT ON create_project FOR EACH ROW EXECUTE PROCEDURE add_permission(); - - --- --- TOC entry 2573 (class 2620 OID 17581) --- Name: create_users insert_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee --- - -CREATE TRIGGER insert_permission AFTER INSERT ON create_users FOR EACH ROW EXECUTE PROCEDURE add_permission(); - - --- --- TOC entry 2597 (class 2620 OID 17582) --- Name: edit_users insert_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee --- - -CREATE TRIGGER insert_permission AFTER INSERT ON edit_users FOR EACH ROW EXECUTE PROCEDURE add_permission(); - - --- --- TOC entry 2605 (class 2620 OID 17584) --- Name: view_projects insert_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee --- - -CREATE TRIGGER insert_permission AFTER INSERT ON view_projects FOR EACH ROW EXECUTE PROCEDURE add_permission(); - - --- --- TOC entry 2609 (class 2620 OID 17585) --- Name: view_users insert_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee --- - -CREATE TRIGGER insert_permission AFTER INSERT ON view_users FOR EACH ROW EXECUTE PROCEDURE add_permission(); - - --- --- TOC entry 2571 (class 2620 OID 16915) --- Name: create_users remove_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee --- - -CREATE TRIGGER remove_permission BEFORE DELETE ON create_users FOR EACH ROW EXECUTE PROCEDURE prevent_admin_delete(); - - --- --- TOC entry 2591 (class 2620 OID 17283) --- Name: create_project remove_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee --- - -CREATE TRIGGER remove_permission BEFORE DELETE ON create_project FOR EACH ROW EXECUTE PROCEDURE prevent_admin_delete(); - - --- --- TOC entry 2594 (class 2620 OID 17286) --- Name: edit_users remove_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee --- - -CREATE TRIGGER remove_permission BEFORE DELETE ON edit_users FOR EACH ROW EXECUTE PROCEDURE prevent_admin_delete(); - - --- --- TOC entry 2598 (class 2620 OID 17288) --- Name: remove_users remove_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee --- - -CREATE TRIGGER remove_permission BEFORE DELETE ON remove_users FOR EACH ROW EXECUTE PROCEDURE prevent_admin_delete(); - - --- --- TOC entry 2602 (class 2620 OID 17292) --- Name: view_projects remove_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee --- - -CREATE TRIGGER remove_permission BEFORE DELETE ON view_projects FOR EACH ROW EXECUTE PROCEDURE prevent_admin_delete(); - - --- --- TOC entry 2607 (class 2620 OID 17296) --- Name: view_users remove_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee --- - -CREATE TRIGGER remove_permission BEFORE DELETE ON view_users FOR EACH ROW EXECUTE PROCEDURE prevent_admin_delete(); - - -SET search_path = project_permissions, pg_catalog; - --- --- TOC entry 2531 (class 2606 OID 17049) --- Name: add_files add_files_granted_by_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee --- - -ALTER TABLE ONLY add_files - ADD CONSTRAINT add_files_granted_by_fkey FOREIGN KEY (granted_by) REFERENCES add_files(permission_id) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- TOC entry 2532 (class 2606 OID 17044) --- Name: add_files add_files_project_name_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee --- - -ALTER TABLE ONLY add_files - ADD CONSTRAINT add_files_project_name_fkey FOREIGN KEY (project_name) REFERENCES public.project(project_name) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- TOC entry 2533 (class 2606 OID 17039) --- Name: add_files add_files_username_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee --- - -ALTER TABLE ONLY add_files - ADD CONSTRAINT add_files_username_fkey FOREIGN KEY (username) REFERENCES public."user"(username) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- TOC entry 2536 (class 2606 OID 17105) --- Name: edit_files edit_files_granted_by_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee --- - -ALTER TABLE ONLY edit_files - ADD CONSTRAINT edit_files_granted_by_fkey FOREIGN KEY (granted_by) REFERENCES edit_files(permission_id) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- TOC entry 2535 (class 2606 OID 17100) --- Name: edit_files edit_files_project_name_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee --- - -ALTER TABLE ONLY edit_files - ADD CONSTRAINT edit_files_project_name_fkey FOREIGN KEY (project_name) REFERENCES public.project(project_name) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- TOC entry 2534 (class 2606 OID 17095) --- Name: edit_files edit_files_username_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee --- - -ALTER TABLE ONLY edit_files - ADD CONSTRAINT edit_files_username_fkey FOREIGN KEY (username) REFERENCES public."user"(username) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- TOC entry 2554 (class 2606 OID 17486) --- Name: project_permissions_list project_permissions_list_add_files_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee --- - -ALTER TABLE ONLY project_permissions_list - ADD CONSTRAINT project_permissions_list_add_files_fkey FOREIGN KEY (add_files) REFERENCES add_files(permission_id) ON UPDATE CASCADE ON DELETE SET NULL; - - --- --- TOC entry 2555 (class 2606 OID 17491) --- Name: project_permissions_list project_permissions_list_edit_files_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee --- - -ALTER TABLE ONLY project_permissions_list - ADD CONSTRAINT project_permissions_list_edit_files_fkey FOREIGN KEY (edit_files) REFERENCES edit_files(permission_id) ON UPDATE CASCADE ON DELETE SET NULL; - - --- --- TOC entry 2558 (class 2606 OID 17506) --- Name: project_permissions_list project_permissions_list_project_name_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee --- - -ALTER TABLE ONLY project_permissions_list - ADD CONSTRAINT project_permissions_list_project_name_fkey FOREIGN KEY (project_name) REFERENCES public.project(project_name) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- TOC entry 2556 (class 2606 OID 17496) --- Name: project_permissions_list project_permissions_list_remove_files_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee --- - -ALTER TABLE ONLY project_permissions_list - ADD CONSTRAINT project_permissions_list_remove_files_fkey FOREIGN KEY (remove_files) REFERENCES remove_files(permission_id) ON UPDATE CASCADE ON DELETE SET NULL; - - --- --- TOC entry 2553 (class 2606 OID 17481) --- Name: project_permissions_list project_permissions_list_username _fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee --- - -ALTER TABLE ONLY project_permissions_list - ADD CONSTRAINT "project_permissions_list_username _fkey" FOREIGN KEY (username) REFERENCES public."user"(username) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- TOC entry 2557 (class 2606 OID 17501) --- Name: project_permissions_list project_permissions_list_view_files_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee --- - -ALTER TABLE ONLY project_permissions_list - ADD CONSTRAINT project_permissions_list_view_files_fkey FOREIGN KEY (view_files) REFERENCES view_files(permission_id) ON UPDATE CASCADE ON DELETE SET NULL; - - --- --- TOC entry 2539 (class 2606 OID 17129) --- Name: remove_files remove_files_granted_by_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee --- - -ALTER TABLE ONLY remove_files - ADD CONSTRAINT remove_files_granted_by_fkey FOREIGN KEY (granted_by) REFERENCES remove_files(permission_id) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- TOC entry 2538 (class 2606 OID 17124) --- Name: remove_files remove_files_project_name_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee --- - -ALTER TABLE ONLY remove_files - ADD CONSTRAINT remove_files_project_name_fkey FOREIGN KEY (project_name) REFERENCES public.project(project_name) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- TOC entry 2537 (class 2606 OID 17119) --- Name: remove_files remove_files_username_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee --- - -ALTER TABLE ONLY remove_files - ADD CONSTRAINT remove_files_username_fkey FOREIGN KEY (username) REFERENCES public."user"(username) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- TOC entry 2542 (class 2606 OID 17177) --- Name: view_files view_files_granted_by_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee --- - -ALTER TABLE ONLY view_files - ADD CONSTRAINT view_files_granted_by_fkey FOREIGN KEY (granted_by) REFERENCES view_files(permission_id) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- TOC entry 2541 (class 2606 OID 17172) --- Name: view_files view_files_project_name_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee --- - -ALTER TABLE ONLY view_files - ADD CONSTRAINT view_files_project_name_fkey FOREIGN KEY (project_name) REFERENCES public.project(project_name) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- TOC entry 2540 (class 2606 OID 17167) --- Name: view_files view_files_username_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee --- - -ALTER TABLE ONLY view_files - ADD CONSTRAINT view_files_username_fkey FOREIGN KEY (username) REFERENCES public."user"(username) ON UPDATE CASCADE ON DELETE CASCADE; - - -SET search_path = public, pg_catalog; - --- --- TOC entry 2529 (class 2606 OID 17013) --- Name: dirent dirent_project_name_fkey; Type: FK CONSTRAINT; Schema: public; Owner: joshlee --- - -ALTER TABLE ONLY dirent - ADD CONSTRAINT dirent_project_name_fkey FOREIGN KEY (project_name) REFERENCES project(project_name) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- TOC entry 2530 (class 2606 OID 17673) --- Name: dirent dirent_super_folder_fkey; Type: FK CONSTRAINT; Schema: public; Owner: joshlee --- - -ALTER TABLE ONLY dirent - ADD CONSTRAINT dirent_super_folder_fkey FOREIGN KEY (super_folder) REFERENCES folder("UUID") ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- TOC entry 2524 (class 2606 OID 17668) --- Name: folder folder_uuid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: joshlee --- - -ALTER TABLE ONLY folder - ADD CONSTRAINT folder_uuid_fkey FOREIGN KEY ("UUID") REFERENCES dirent("UUID") ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- TOC entry 2525 (class 2606 OID 17678) --- Name: image image_uuid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: joshlee --- - -ALTER TABLE ONLY image - ADD CONSTRAINT image_uuid_fkey FOREIGN KEY ("UUID") REFERENCES dirent("UUID") ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- TOC entry 2523 (class 2606 OID 16777) --- Name: project project_owner _fkey; Type: FK CONSTRAINT; Schema: public; Owner: joshlee --- - -ALTER TABLE ONLY project - ADD CONSTRAINT "project_owner _fkey" FOREIGN KEY (owner) REFERENCES "user"(username) ON UPDATE CASCADE ON DELETE RESTRICT; - - --- --- TOC entry 2526 (class 2606 OID 17687) --- Name: text text_UUID_fkey; Type: FK CONSTRAINT; Schema: public; Owner: joshlee --- - -ALTER TABLE ONLY text - ADD CONSTRAINT "text_UUID_fkey" FOREIGN KEY ("UUID") REFERENCES dirent("UUID") ON UPDATE CASCADE ON DELETE CASCADE; - - -SET search_path = user_permissions, pg_catalog; - --- --- TOC entry 2543 (class 2606 OID 17196) --- Name: create_project create_project_granted_by_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee --- - -ALTER TABLE ONLY create_project - ADD CONSTRAINT create_project_granted_by_fkey FOREIGN KEY (granted_by) REFERENCES create_project(permission_id) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- TOC entry 2544 (class 2606 OID 17191) --- Name: create_project create_project_username_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee --- - -ALTER TABLE ONLY create_project - ADD CONSTRAINT create_project_username_fkey FOREIGN KEY (username) REFERENCES public."user"(username) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- TOC entry 2528 (class 2606 OID 17008) --- Name: create_users create_user_granted_by_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee --- - -ALTER TABLE ONLY create_users - ADD CONSTRAINT create_user_granted_by_fkey FOREIGN KEY (granted_by) REFERENCES create_users(permission_id) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- TOC entry 2527 (class 2606 OID 16931) --- Name: create_users create_user_username_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee --- - -ALTER TABLE ONLY create_users - ADD CONSTRAINT create_user_username_fkey FOREIGN KEY (username) REFERENCES public."user"(username) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- TOC entry 2546 (class 2606 OID 17215) --- Name: edit_users edit_user_granted_by_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee --- - -ALTER TABLE ONLY edit_users - ADD CONSTRAINT edit_user_granted_by_fkey FOREIGN KEY (granted_by) REFERENCES edit_users(permission_id) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- TOC entry 2548 (class 2606 OID 17259) --- Name: remove_users remove_users_granted_by_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee --- - -ALTER TABLE ONLY remove_users - ADD CONSTRAINT remove_users_granted_by_fkey FOREIGN KEY (granted_by) REFERENCES remove_users(permission_id) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- TOC entry 2547 (class 2606 OID 17228) --- Name: remove_users remove_users_username_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee --- - -ALTER TABLE ONLY remove_users - ADD CONSTRAINT remove_users_username_fkey FOREIGN KEY (username) REFERENCES public."user"(username) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- TOC entry 2545 (class 2606 OID 17209) --- Name: edit_users untitled_table_username_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee --- - -ALTER TABLE ONLY edit_users - ADD CONSTRAINT untitled_table_username_fkey FOREIGN KEY (username) REFERENCES public."user"(username) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- TOC entry 2560 (class 2606 OID 17546) --- Name: user_permissions_list user_permissions_list_create_project_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee --- - -ALTER TABLE ONLY user_permissions_list - ADD CONSTRAINT user_permissions_list_create_project_fkey FOREIGN KEY (create_project) REFERENCES create_project(permission_id) ON UPDATE CASCADE ON DELETE SET NULL; - - --- --- TOC entry 2561 (class 2606 OID 17551) --- Name: user_permissions_list user_permissions_list_create_users_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee --- - -ALTER TABLE ONLY user_permissions_list - ADD CONSTRAINT user_permissions_list_create_users_fkey FOREIGN KEY (create_users) REFERENCES create_users(permission_id) ON UPDATE CASCADE ON DELETE SET NULL; - - --- --- TOC entry 2562 (class 2606 OID 17556) --- Name: user_permissions_list user_permissions_list_edit_users_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee --- - -ALTER TABLE ONLY user_permissions_list - ADD CONSTRAINT user_permissions_list_edit_users_fkey FOREIGN KEY (edit_users) REFERENCES edit_users(permission_id) ON UPDATE CASCADE ON DELETE SET NULL; - - --- --- TOC entry 2563 (class 2606 OID 17561) --- Name: user_permissions_list user_permissions_list_remove_users_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee --- - -ALTER TABLE ONLY user_permissions_list - ADD CONSTRAINT user_permissions_list_remove_users_fkey FOREIGN KEY (remove_users) REFERENCES remove_users(permission_id) ON UPDATE CASCADE ON DELETE SET NULL; - - --- --- TOC entry 2559 (class 2606 OID 17541) --- Name: user_permissions_list user_permissions_list_username_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee --- - -ALTER TABLE ONLY user_permissions_list - ADD CONSTRAINT user_permissions_list_username_fkey FOREIGN KEY (username) REFERENCES public."user"(username) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- TOC entry 2564 (class 2606 OID 17566) --- Name: user_permissions_list user_permissions_list_view_projects_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee --- - -ALTER TABLE ONLY user_permissions_list - ADD CONSTRAINT user_permissions_list_view_projects_fkey FOREIGN KEY (view_projects) REFERENCES view_projects(permission_id) ON UPDATE CASCADE ON DELETE SET NULL; - - --- --- TOC entry 2565 (class 2606 OID 17571) --- Name: user_permissions_list user_permissions_list_view_users_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee --- - -ALTER TABLE ONLY user_permissions_list - ADD CONSTRAINT user_permissions_list_view_users_fkey FOREIGN KEY (view_users) REFERENCES view_users(permission_id) ON UPDATE CASCADE ON DELETE SET NULL; - - --- --- TOC entry 2550 (class 2606 OID 17264) --- Name: view_projects view_projects_granted_by_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee --- - -ALTER TABLE ONLY view_projects - ADD CONSTRAINT view_projects_granted_by_fkey FOREIGN KEY (granted_by) REFERENCES view_projects(permission_id) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- TOC entry 2549 (class 2606 OID 17241) --- Name: view_projects view_projects_username_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee --- - -ALTER TABLE ONLY view_projects - ADD CONSTRAINT view_projects_username_fkey FOREIGN KEY (username) REFERENCES public."user"(username) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- TOC entry 2552 (class 2606 OID 17269) --- Name: view_users view_users_granted_by_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee --- - -ALTER TABLE ONLY view_users - ADD CONSTRAINT view_users_granted_by_fkey FOREIGN KEY (granted_by) REFERENCES view_users(permission_id) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- TOC entry 2551 (class 2606 OID 17254) --- Name: view_users view_users_username_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee --- - -ALTER TABLE ONLY view_users - ADD CONSTRAINT view_users_username_fkey FOREIGN KEY (username) REFERENCES public."user"(username) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- TOC entry 2773 (class 0 OID 0) --- Dependencies: 10 --- Name: project_permissions; Type: ACL; Schema: -; Owner: joshlee --- - -GRANT USAGE ON SCHEMA project_permissions TO find_user; - - --- --- TOC entry 2775 (class 0 OID 0) --- Dependencies: 8 --- Name: user_permissions; Type: ACL; Schema: -; Owner: joshlee --- - -GRANT USAGE ON SCHEMA user_permissions TO find_user; - - -SET search_path = project_permissions, pg_catalog; - --- --- TOC entry 2778 (class 0 OID 0) --- Dependencies: 210 --- Name: add_files; Type: ACL; Schema: project_permissions; Owner: joshlee --- - -GRANT SELECT ON TABLE add_files TO find_user; - - --- Completed on 2018-02-07 18:20:05 GMT - --- --- PostgreSQL database dump complete --- - -- cgit v1.2.1 From 0ec15d6185ba07d9a3df3cf43443ae5c056f7c7d Mon Sep 17 00:00:00 2001 From: cjd24 Date: Tue, 6 Mar 2018 21:32:17 +0000 Subject: Committing to get the logger stuff --- src/conversion/czi/czi.ts | 159 ++++++++++++++++++++-------------------------- 1 file changed, 68 insertions(+), 91 deletions(-) (limited to 'src') diff --git a/src/conversion/czi/czi.ts b/src/conversion/czi/czi.ts index 9ca9ad7..bb998ad 100644 --- a/src/conversion/czi/czi.ts +++ b/src/conversion/czi/czi.ts @@ -1,5 +1,5 @@ -let json: any = require('/cs/scratch/cjd24/0701-extraction/outputjson.json'); -json = json.czi; +// tslint:disable-next-line +let json: Segment[] = require('/cs/scratch/cjd24/0701-extraction/outputjson.json').czi; let tileOverlap: number = 5; let tileSize: number = 1024; @@ -23,36 +23,36 @@ interface Segment { Data: SubBlock; } class TileBounds { - left: number; - right: number; - top: number; - bottom: number; - constructor(left: number, right: number, top: number, bottom: number) { + public left: number; + public right: number; + public top: number; + public bottom: number; + public constructor(left: number, right: number, top: number, bottom: number) { this.left = left; this.right = right; this.top = top; this.bottom = bottom; - }; + } } - -//Get all subblocks that have an associated saved tile -let dataBlocks: Segment[] = json.filter((x: Segment) => x.Id == 'ZISRAWSUBBLOCK' && x.Data.Data != 'empty'); - +// Get all subblocks that have an associated saved tile +let dataBlocks: Segment[] = json.filter((s: Segment) => s.Id === 'ZISRAWSUBBLOCK' && s.Data.Data !== 'empty'); function getOriginalTileBounds(originalTile: Segment): TileBounds | null { - let bounds: TileBounds = new TileBounds (-1, -1, -1, -1); - - for (let dimension of originalTile.Data.DirectoryEntry.DimensionEntries) { - if (dimension.Dimension == 'X') { - bounds.left = dimension.Start; - bounds.right = bounds.left + dimension.Size; - continue; - } - else if (dimension.Dimension == 'Y') { - bounds.top = dimension.Start; - bounds.bottom = bounds.top + dimension.Size; - continue; + const bounds: TileBounds = new TileBounds (-1, -1, -1, -1); + + for (const dimension of originalTile.Data.DirectoryEntry.DimensionEntries) { + switch (dimension.Dimension) { + case 'X': + bounds.left = dimension.Start; + bounds.right = bounds.left + dimension.Size; + continue; + case 'Y': + bounds.top = dimension.Start; + bounds.bottom = bounds.top + dimension.Size; + continue; + default: + continue; } } @@ -63,45 +63,39 @@ function getOriginalTileBounds(originalTile: Segment): TileBounds | null { return bounds; } - function findRelatedTiles(activeSegments: Segment[], desired: TileBounds): Segment[] { - let relatedTiles: Segment[] = []; + const relatedTiles: Segment[] = []; - - for (let origTile of activeSegments) { + for (const origTile of activeSegments) { let origCoords: TileBounds | null; if ((origCoords = getOriginalTileBounds(origTile)) === null) { - throw new Error("There was a Sad Boi error"); + throw new Error('There was a Sad Boi error'); } - //desired X on left is within current tile + // Desired X on left is within current tile if (((desired.left >= origCoords.left) && (desired.left <= origCoords.right)) || - //desired X on right is within the current tile + // Desired X on right is within the current tile ((desired.right >= origCoords.left) && (desired.right <= origCoords.right)) || - //desired tile X overlaps base tile + // Desired tile X overlaps base tile ((desired.left < origCoords.left) && - (desired.right > origCoords.right))) - - { - //desired Y on top is within current tile + (desired.right > origCoords.right))) { + // Desired Y on top is within current tile if (((desired.top >= origCoords.top) && (desired.top <= origCoords.bottom)) || - //desired Y on right is within the current tile + // Desired Y on right is within the current tile ((desired.bottom >= origCoords.top) && (desired.bottom <= origCoords.bottom)) || - //desired tile Y overlaps whole base tile + // Desired tile Y overlaps whole base tile ((desired.top < origCoords.top) && - (desired.bottom > origCoords.bottom))) - - { + (desired.bottom > origCoords.bottom))) { relatedTiles.push(origTile); } } @@ -110,57 +104,48 @@ function findRelatedTiles(activeSegments: Segment[], desired: TileBounds): Segme return relatedTiles; } - -function getDimension(segment:Segment, name:string): Dimension { - for (let dimension of segment.Data.DirectoryEntry.DimensionEntries) { +function getDimension(segment: Segment, name: string): Dimension { + for (const dimension of segment.Data.DirectoryEntry.DimensionEntries) { if (dimension.Dimension == name) { return dimension; } } - throw new Error("Dimension: " + name + " doesn't exist for segment: " + segment); + throw new Error('Dimension: ' + name + " doesn't exist for segment: " + segment); } - - - - - - - - - - -//Get all values of X and Y respectively. +// Get all values of X and Y respectively. let filterX: number[] = dataBlocks.map((x: Segment) => getDimension(x, 'X').Start); let filterY: number[] = dataBlocks.map((x: Segment) => getDimension(x, 'Y').Start); -//Filter all values to only keep the unique ones for X and Y coords respectively. +// Filter all values to only keep the unique ones for X and Y coords respectively. let uniqueX: number[] = filterX.filter(function(elem: any, pos: any) { - return filterX.indexOf(elem) == pos; + return filterX.indexOf(elem) === pos; }); let uniqueY: number[] = filterY.filter(function(elem: any, pos: any) { - return filterY.indexOf(elem) == pos; + return filterY.indexOf(elem) === pos; }); /*These values are normally stored at the big XML metadata under "Information/Image/SizeX or SizeY"; However for the sake of hacking around, assume that the tiles in memory are going from left to right; top to bottom. like a book, then use this in order to count up the total size (in pixels) of the image*/ -let sizeX: number = 0, sizeY: number = 0; +let sizeX: number = 0; +let sizeY: number = 0; for (let i: number = 0; i < uniqueX.length; i++) { sizeX += getDimension(dataBlocks[i], 'X').Size; -}; +} for (let i: number = 0; i < uniqueY.length; i++) { sizeX += getDimension(dataBlocks[i], 'Y').Size; -}; +} let uniqueTileSizes: number[][] = []; -for (let seg of dataBlocks) { +for (const seg of dataBlocks) { - let x: number = getDimension(seg, 'X').Size, y: number = getDimension(seg, 'Y').Size; + const x: number = getDimension(seg, 'X').Size; + const y: number = getDimension(seg, 'Y').Size; let found: boolean = false; - for (let dimPair of uniqueTileSizes) { - if (x == dimPair[0] && y == dimPair[1]) { + for (const dimPair of uniqueTileSizes) { + if (x === dimPair[0] && y === dimPair[1]) { found = true; break; } @@ -168,38 +153,32 @@ for (let seg of dataBlocks) { if (!found) { uniqueTileSizes.push([x, y]); } -}; - - - - - +} -//TESTS TO SEE WHAT VARIOUS THINGS RETURN +// TESTS TO SEE WHAT VARIOUS THINGS RETURN // `npm bin`/ts-node czi.ts -console.log("\n\nUnique Tile Sizes:"); +console.log('\n\nUnique Tile Sizes:'); console.log(uniqueTileSizes); -console.log("\n\n(tentative) SizeX : " + sizeX); -console.log("UNIQUE X VALUES:"); -console.log("[" + uniqueX + "]"); -console.log("\n\n(tentative) SizeY : " + sizeY); -console.log("UNIQUE Y VALUES:"); -console.log("[" + uniqueY + "]\n\n"); +console.log('\n\n(tentative) SizeX : ' + sizeX); +console.log('UNIQUE X VALUES:'); +console.log('[' + uniqueX + ']'); +console.log('\n\n(tentative) SizeY : ' + sizeY); +console.log('UNIQUE Y VALUES:'); +console.log('[' + uniqueY + ']\n\n'); let x: number = 1500, y: number = 1500, c_val: number = 0; let c_filter: Segment[] = []; function filterC(to: number): void { - c_filter = dataBlocks.filter((x: Segment) => - { - let y: Dimension | null = getDimension(x, 'C'); + c_filter = dataBlocks.filter((x: Segment) => { + const y: Dimension | null = getDimension(x, 'C'); if (y != null && y.Start == to) { return y; } }); } -let desired = new TileBounds (0,0,0,0); +let desired = new TileBounds (0, 0, 0, 0); -function runTest(cval: number, tilesize:number, tileoverlap:number, x1:number, y1:number) { +function runTest(cval: number, tilesize: number, tileoverlap: number, x1: number, y1: number) { desired = new TileBounds ( x1 - tileoverlap, x1 + tilesize + tileoverlap, @@ -207,7 +186,7 @@ function runTest(cval: number, tilesize:number, tileoverlap:number, x1:number, y y1 + tilesize + tileoverlap ); filterC(cval); - console.log("\n\nC Value: " + cval + " TileSize: " + tilesize + " TileOverlap(px): " + tileoverlap + " Coords: " + `[X=${x1}, Y=${y1}]\nResults: `); + console.log('\n\nC Value: ' + cval + ' TileSize: ' + tilesize + ' TileOverlap(px): ' + tileoverlap + ' Coords: ' + `[X=${x1}, Y=${y1}]\nResults: `); console.log(findRelatedTiles(c_filter, desired).map((x: Segment) => x.Data.Data)); } @@ -219,15 +198,13 @@ runTest(0, 1024, 5, 0, 0); runTest(0, 1024, 5, 41940, 59240); -runTest(0, 1024, 5, -tileSize - tileOverlap -1, 59240); +runTest(0, 1024, 5, -tileSize - tileOverlap - 1, 59240); runTest(0, 1024, 5, 41945, 59245); runTest(3, 1024, 5, 41940, 1500); - - filterC(0); -console.log("\n\n\n\n\n\n\n"); +console.log('\n\n\n\n\n\n\n'); -//begin work on getting the new tiles all nice +// Begin work on getting the new tiles all nice -- cgit v1.2.1 From bfc14f0a5a95351c9d800248886fd0887197fdd9 Mon Sep 17 00:00:00 2001 From: cjd24 Date: Wed, 7 Mar 2018 01:15:34 +0000 Subject: Added ordering support for base tiles, now need to cut out chunks and stitch tiles --- src/FileRouter.ts | 1 - src/conversion/czi/czi.ts | 215 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 171 insertions(+), 45 deletions(-) (limited to 'src') diff --git a/src/FileRouter.ts b/src/FileRouter.ts index 1cef85d..4dc3105 100644 --- a/src/FileRouter.ts +++ b/src/FileRouter.ts @@ -447,7 +447,6 @@ const postProjectName: Middleware = }); promise = file.save(); project = new Project({ - uuid: uuid.generate(), name: req.params.project_name, rootFolder: file }); diff --git a/src/conversion/czi/czi.ts b/src/conversion/czi/czi.ts index bb998ad..c924673 100644 --- a/src/conversion/czi/czi.ts +++ b/src/conversion/czi/czi.ts @@ -1,8 +1,6 @@ -// tslint:disable-next-line -let json: Segment[] = require('/cs/scratch/cjd24/0701-extraction/outputjson.json').czi; -let tileOverlap: number = 5; -let tileSize: number = 1024; +import { logger } from '../../logger'; +import * as sharp from 'sharp'; interface Dimension { Dimension: string; @@ -23,23 +21,25 @@ interface Segment { Data: SubBlock; } class TileBounds { - public left: number; - public right: number; - public top: number; - public bottom: number; - public constructor(left: number, right: number, top: number, bottom: number) { - this.left = left; - this.right = right; - this.top = top; - this.bottom = bottom; + public left!: number; + public right!: number; + public top!: number; + public bottom!: number; + public constructor(leftBound: number, rightBound: number, topBound: number, bottomBound: number) { + this.left = leftBound; + this.right = rightBound; + this.top = topBound; + this.bottom = bottomBound; } } -// Get all subblocks that have an associated saved tile -let dataBlocks: Segment[] = json.filter((s: Segment) => s.Id === 'ZISRAWSUBBLOCK' && s.Data.Data !== 'empty'); +const extractionDirectory: string = '/cs/scratch/cjd24/0701-extraction/'; +const json: Segment[] = require(`${extractionDirectory}outputjson.json`).czi; +const tileOverlap: number = 0; +const tileSize: number = 1024; -function getOriginalTileBounds(originalTile: Segment): TileBounds | null { - const bounds: TileBounds = new TileBounds (-1, -1, -1, -1); +const getOriginalTileBounds = function(originalTile: Segment): (TileBounds | null) { + const bounds: TileBounds = new TileBounds(-1, -1, -1, -1); for (const dimension of originalTile.Data.DirectoryEntry.DimensionEntries) { switch (dimension.Dimension) { @@ -63,40 +63,42 @@ function getOriginalTileBounds(originalTile: Segment): TileBounds | null { return bounds; } -function findRelatedTiles(activeSegments: Segment[], desired: TileBounds): Segment[] { +const findRelatedTiles = function(activeSegments: Segment[], desired: TileBounds): Segment[] { const relatedTiles: Segment[] = []; - for (const origTile of activeSegments) { + for (const baseTile of activeSegments) { let origCoords: TileBounds | null; - if ((origCoords = getOriginalTileBounds(origTile)) === null) { + if ((origCoords = getOriginalTileBounds(baseTile)) === null) { throw new Error('There was a Sad Boi error'); } - // Desired X on left is within current tile + // Desired X on left is within current tile if (((desired.left >= origCoords.left) && (desired.left <= origCoords.right)) || // Desired X on right is within the current tile ((desired.right >= origCoords.left) && - (desired.right <= origCoords.right)) || + (desired.right <= origCoords.right)) || // Desired tile X overlaps base tile ((desired.left < origCoords.left) && - (desired.right > origCoords.right))) { + (desired.right > origCoords.right))) { + // Desired Y on top is within current tile if (((desired.top >= origCoords.top) && (desired.top <= origCoords.bottom)) || // Desired Y on right is within the current tile ((desired.bottom >= origCoords.top) && - (desired.bottom <= origCoords.bottom)) || + (desired.bottom <= origCoords.bottom)) || // Desired tile Y overlaps whole base tile ((desired.top < origCoords.top) && - (desired.bottom > origCoords.bottom))) { - relatedTiles.push(origTile); + (desired.bottom > origCoords.bottom))) { + + relatedTiles.push(baseTile); } } } @@ -104,7 +106,7 @@ function findRelatedTiles(activeSegments: Segment[], desired: TileBounds): Segme return relatedTiles; } -function getDimension(segment: Segment, name: string): Dimension { +const getDimension = function(segment: Segment, name: string): Dimension { for (const dimension of segment.Data.DirectoryEntry.DimensionEntries) { if (dimension.Dimension == name) { return dimension; @@ -113,15 +115,93 @@ function getDimension(segment: Segment, name: string): Dimension { throw new Error('Dimension: ' + name + " doesn't exist for segment: " + segment); } +const orderSegments = function(segments: Segment[]): Segment[][] { + + const output: Segment[][] = []; + + if (segments.length > 1) { + let xCoords: number[] = []; + let yCoords: number[] = []; + + // Get all x/y's; + const initC: number = getDimension(segments[0], 'C').Start; + for (const seg of segments) { + if (getDimension(seg, 'C').Start !== initC) { + throw new Error("Segment array contains multiple values of C - this overlay is currently unsupported within this method"); + } + xCoords.push(getDimension(seg, 'X').Start); + yCoords.push(getDimension(seg, 'Y').Start); + } + // Filter to get Uniaue Values + xCoords = xCoords.filter((item: number, index: number, array: number[]) => array.indexOf(item) === index); + yCoords = yCoords.filter((item: number, index: number, array: number[]) => array.indexOf(item) === index); + + // Use the filtered list to order the segments into rows + for (const yVal of yCoords) { + + // Get all segments with the same y value + const row: Segment[] = []; + for (const seg of segments) { + if (getDimension(seg, 'Y').Start === yVal) { + row.push(seg); + } + } + + // Sort the row of y values by x value + const sortedRow: Segment[] = []; + for (const xVal of xCoords) { + for (const seg of row) { + if (getDimension(seg, 'X').Start === xVal) { + sortedRow.push(seg); + break; + } + } + } + + // Push this to the finalised grid + output.push(sortedRow); + } + + // Return the result + return output; + } + else { + output.push(segments); + return output; + } +} + + + + + + + + + + + + + + + + + + + + +// Get all subblocks that have an associated saved tile +const dataBlocks: Segment[] = json.filter((s: Segment) => s.Id === 'ZISRAWSUBBLOCK' && s.Data.Data !== 'empty'); + // Get all values of X and Y respectively. -let filterX: number[] = dataBlocks.map((x: Segment) => getDimension(x, 'X').Start); -let filterY: number[] = dataBlocks.map((x: Segment) => getDimension(x, 'Y').Start); +const filterX: number[] = dataBlocks.map((x: Segment) => getDimension(x, 'X').Start); +const filterY: number[] = dataBlocks.map((x: Segment) => getDimension(x, 'Y').Start); // Filter all values to only keep the unique ones for X and Y coords respectively. -let uniqueX: number[] = filterX.filter(function(elem: any, pos: any) { +const uniqueX: number[] = filterX.filter(function(elem: any, pos: any) { return filterX.indexOf(elem) === pos; }); -let uniqueY: number[] = filterY.filter(function(elem: any, pos: any) { +const uniqueY: number[] = filterY.filter(function(elem: any, pos: any) { return filterY.indexOf(elem) === pos; }); @@ -135,10 +215,10 @@ for (let i: number = 0; i < uniqueX.length; i++) { sizeX += getDimension(dataBlocks[i], 'X').Size; } for (let i: number = 0; i < uniqueY.length; i++) { - sizeX += getDimension(dataBlocks[i], 'Y').Size; + sizeY += getDimension(dataBlocks[i], 'Y').Size; } -let uniqueTileSizes: number[][] = []; +const uniqueTileSizes: number[][] = []; for (const seg of dataBlocks) { const x: number = getDimension(seg, 'X').Size; @@ -155,8 +235,8 @@ for (const seg of dataBlocks) { } } -// TESTS TO SEE WHAT VARIOUS THINGS RETURN -// `npm bin`/ts-node czi.ts +// // TESTS TO SEE WHAT VARIOUS THINGS RETURN +// // `npm bin`/ts-node czi.ts console.log('\n\nUnique Tile Sizes:'); console.log(uniqueTileSizes); console.log('\n\n(tentative) SizeX : ' + sizeX); @@ -176,9 +256,9 @@ function filterC(to: number): void { } }); } -let desired = new TileBounds (0, 0, 0, 0); -function runTest(cval: number, tilesize: number, tileoverlap: number, x1: number, y1: number) { +let desired = new TileBounds (0, 0, 0, 0); +function findRelatedTest(cval: number, tilesize: number, tileoverlap: number, x1: number, y1: number) { desired = new TileBounds ( x1 - tileoverlap, x1 + tilesize + tileoverlap, @@ -190,21 +270,68 @@ function runTest(cval: number, tilesize: number, tileoverlap: number, x1: number console.log(findRelatedTiles(c_filter, desired).map((x: Segment) => x.Data.Data)); } -runTest(0, 1024, 5, 1500, 1500); +findRelatedTest(0, 1024, 5, 1500, 1500); -runTest(1, 5000, 5, 1500, 1500); +findRelatedTest(1, 5000, 5, 1500, 1500); -runTest(0, 1024, 5, 0, 0); +findRelatedTest(0, 1024, 5, 0, 0); -runTest(0, 1024, 5, 41940, 59240); +findRelatedTest(0, 1024, 5, 41940, 59240); -runTest(0, 1024, 5, -tileSize - tileOverlap - 1, 59240); +findRelatedTest(0, 1024, 5, -tileSize - tileOverlap - 1, 59240); -runTest(0, 1024, 5, 41945, 59245); +findRelatedTest(0, 1024, 5, 41945, 59245); -runTest(3, 1024, 5, 41940, 1500); +findRelatedTest(3, 1024, 5, 41940, 1500); filterC(0); console.log('\n\n\n\n\n\n\n'); + + + + + + + + + + + + + + + + + + + + // Begin work on getting the new tiles all nice +function sortSegmentsTest(cval: number, tilesize: number, tileoverlap: number, x1: number, y1: number) { + desired = new TileBounds ( + x1 - tileoverlap, + x1 + tilesize + tileoverlap, + y1 - tileoverlap, + y1 + tilesize + tileoverlap + ); + filterC(cval); + console.log('\nC Value: ' + cval + ' TileSize: ' + tilesize + ' TileOverlap(px): ' + tileoverlap + ' Coords: ' + `[X=${x1}, Y=${y1}]`); + let outputGrid: Segment[][] = orderSegments(findRelatedTiles(c_filter, desired)); + + for (const row of outputGrid) { + let rowOutput: string = "[ "; + for (const col of row) { + rowOutput += ` '${col.Data.Data}', `; + } + rowOutput += ']'; + console.log(rowOutput); + } +} + + +for (let ys: number = 0; ys < sizeY; ys += tileSize) { + for (let xs: number = 0; xs < sizeX; xs += tileSize) { + sortSegmentsTest(0, tileSize, tileOverlap, xs, ys); + } +} -- cgit v1.2.1 From 79e192389adaf4368dcd3103bc2a633444fc990f Mon Sep 17 00:00:00 2001 From: cjd24 Date: Wed, 7 Mar 2018 03:21:14 +0000 Subject: fixed some random problems everywhere, and made typescript a little happier with czi.ts and XMLparsed to get max x and y instead of janky unreliable thing --- src/FileRouter.ts | 2 +- src/app.ts | 4 +- src/conversion/czi/czi.ts | 133 ++++++++++++++++++++++++---------------------- src/errors/errorware.ts | 1 - src/index.ts | 2 +- 5 files changed, 73 insertions(+), 69 deletions(-) (limited to 'src') diff --git a/src/FileRouter.ts b/src/FileRouter.ts index 4dc3105..f8f569d 100644 --- a/src/FileRouter.ts +++ b/src/FileRouter.ts @@ -536,7 +536,7 @@ export class FileRouter { */ public init(): void { // General - this.router.get ('/_supported_protocols_', getProtocols); + this.router.get ('/_supported_protocols_', getProtocols); this.router.get ('/log', getLog); this.router.post('/log', postLog); this.router.get ('/properties', getProperties); diff --git a/src/app.ts b/src/app.ts index 8bd488d..c9c6d33 100644 --- a/src/app.ts +++ b/src/app.ts @@ -38,7 +38,7 @@ class App { private middleware(): void { this.express.use(expressJwt({secret: 'Mr Secret'}) .unless({path: [ - '/cs3099group-be-4/login', + '/cs3099group-be-4/oauth/token', '/cs3099group-be-4/_supported_protocols_' ] }) ); @@ -61,7 +61,7 @@ class App { }); this.express.use('/', defRouter); this.express.use('/cs3099group-be-4', FileRouter); - this.express.use('/cs3099group-be-4', authRouter); + this.express.use('/cs3099group-be-4', authRouter); } private errorware(): void { diff --git a/src/conversion/czi/czi.ts b/src/conversion/czi/czi.ts index c924673..a52508a 100644 --- a/src/conversion/czi/czi.ts +++ b/src/conversion/czi/czi.ts @@ -1,6 +1,12 @@ +import * as fs from 'fs'; import { logger } from '../../logger'; import * as sharp from 'sharp'; +import * as parsexml from 'xml-parser'; + +const extractionDirectory: string = '/cs/scratch/cjd24/0701-extraction/'; +const tileOverlap: number = 0; +const tileSize: number = 1024; interface Dimension { Dimension: string; @@ -33,12 +39,7 @@ class TileBounds { } } -const extractionDirectory: string = '/cs/scratch/cjd24/0701-extraction/'; -const json: Segment[] = require(`${extractionDirectory}outputjson.json`).czi; -const tileOverlap: number = 0; -const tileSize: number = 1024; - -const getOriginalTileBounds = function(originalTile: Segment): (TileBounds | null) { +const getOriginalTileBounds: Function = function(originalTile: Segment): (TileBounds | null) { const bounds: TileBounds = new TileBounds(-1, -1, -1, -1); for (const dimension of originalTile.Data.DirectoryEntry.DimensionEntries) { @@ -61,9 +62,9 @@ const getOriginalTileBounds = function(originalTile: Segment): (TileBounds | nul } return bounds; -} +}; -const findRelatedTiles = function(activeSegments: Segment[], desired: TileBounds): Segment[] { +const findRelatedTiles: Function = function(activeSegments: Segment[], desired: TileBounds): Segment[] { const relatedTiles: Segment[] = []; for (const baseTile of activeSegments) { @@ -104,18 +105,18 @@ const findRelatedTiles = function(activeSegments: Segment[], desired: TileBounds } return relatedTiles; -} +}; -const getDimension = function(segment: Segment, name: string): Dimension { +const getDimension: Function = function(segment: Segment, name: string): Dimension { for (const dimension of segment.Data.DirectoryEntry.DimensionEntries) { - if (dimension.Dimension == name) { + if (dimension.Dimension === name) { return dimension; } } throw new Error('Dimension: ' + name + " doesn't exist for segment: " + segment); -} +}; -const orderSegments = function(segments: Segment[]): Segment[][] { +const orderSegments: Function = function(segments: Segment[]): Segment[][] { const output: Segment[][] = []; @@ -133,8 +134,10 @@ const orderSegments = function(segments: Segment[]): Segment[][] { yCoords.push(getDimension(seg, 'Y').Start); } // Filter to get Uniaue Values - xCoords = xCoords.filter((item: number, index: number, array: number[]) => array.indexOf(item) === index); - yCoords = yCoords.filter((item: number, index: number, array: number[]) => array.indexOf(item) === index); + xCoords = xCoords.filter( + (item: number, index: number, array: number[]) => array.indexOf(item) === index); + yCoords = yCoords.filter( + (item: number, index: number, array: number[]) => array.indexOf(item) === index); // Use the filtered list to order the segments into rows for (const yVal of yCoords) { @@ -164,12 +167,11 @@ const orderSegments = function(segments: Segment[]): Segment[][] { // Return the result return output; - } - else { + } else { output.push(segments); return output; } -} +}; @@ -189,35 +191,41 @@ const orderSegments = function(segments: Segment[]): Segment[][] { +const dataBlocks: Segment[] = require(`${extractionDirectory}outputjson.json`).czi.filter( + (s: Segment) => s.Id === 'ZISRAWSUBBLOCK' && s.Data.Data !== 'empty'); +const inspect: object = require('util').inspect; +const metaXML: parsexml.Node[] = parsexml(fs.readFileSync(`${extractionDirectory}FILE-META-1.xml`, 'utf8')).root.children; -// Get all subblocks that have an associated saved tile -const dataBlocks: Segment[] = json.filter((s: Segment) => s.Id === 'ZISRAWSUBBLOCK' && s.Data.Data !== 'empty'); +let totalSizeX: number = -1; +let totalSizeY: number = -1; -// Get all values of X and Y respectively. -const filterX: number[] = dataBlocks.map((x: Segment) => getDimension(x, 'X').Start); -const filterY: number[] = dataBlocks.map((x: Segment) => getDimension(x, 'Y').Start); - -// Filter all values to only keep the unique ones for X and Y coords respectively. -const uniqueX: number[] = filterX.filter(function(elem: any, pos: any) { - return filterX.indexOf(elem) === pos; -}); -const uniqueY: number[] = filterY.filter(function(elem: any, pos: any) { - return filterY.indexOf(elem) === pos; -}); - -/*These values are normally stored at the big XML metadata under "Information/Image/SizeX or SizeY"; -However for the sake of hacking around, assume that the tiles in memory are -going from left to right; top to bottom. like a book, then use this in order -to count up the total size (in pixels) of the image*/ -let sizeX: number = 0; -let sizeY: number = 0; -for (let i: number = 0; i < uniqueX.length; i++) { - sizeX += getDimension(dataBlocks[i], 'X').Size; -} -for (let i: number = 0; i < uniqueY.length; i++) { - sizeY += getDimension(dataBlocks[i], 'Y').Size; +// THE FOLLOWING FOR LOOP IS DISGUSTING AND I HATE IT, AND I WISH I DIDNT WRITE IT BUT DON'T SEE ANY OTHER WAY TO DO IT LOL :'( +for (const child of metaXML) { + if (child.name === 'Metadata') { + for (const entry of child.children) { + if (entry.name === 'Information') { + for (const properties of entry.children) { + if (properties.name === 'Image') { + for (const property of properties.children) { + if (property.name === 'SizeX' && property.content) { + totalSizeX = Number.parseInt(property.content, 10); + } else if (property.name === 'SizeY' && property.content) { + totalSizeY = Number.parseInt(property.content, 10); + } + } + } + } + } + } + } } +// Get all values of X and Y respectively. +const uniqueX: number[] = dataBlocks.map((x: Segment) => getDimension(x, 'X').Start).filter( + (item: number, index: number, array: number[]) => array.indexOf(item) === index); +const uniqueY: number[] = dataBlocks.map((x: Segment) => getDimension(x, 'Y').Start).filter( + (item: number, index: number, array: number[]) => array.indexOf(item) === index); + const uniqueTileSizes: number[][] = []; for (const seg of dataBlocks) { @@ -239,23 +247,23 @@ for (const seg of dataBlocks) { // // `npm bin`/ts-node czi.ts console.log('\n\nUnique Tile Sizes:'); console.log(uniqueTileSizes); -console.log('\n\n(tentative) SizeX : ' + sizeX); +console.log('\n\nSizeX : ' + totalSizeX); console.log('UNIQUE X VALUES:'); -console.log('[' + uniqueX + ']'); -console.log('\n\n(tentative) SizeY : ' + sizeY); +console.log(uniqueX); +console.log('\n\n(tentative) SizeY : ' + totalSizeY); console.log('UNIQUE Y VALUES:'); -console.log('[' + uniqueY + ']\n\n'); +console.log(uniqueY); -let x: number = 1500, y: number = 1500, c_val: number = 0; +let x: number = 1500, y: number = 1500; let c_filter: Segment[] = []; -function filterC(to: number): void { +const filterC: Function = function(to: number): void { c_filter = dataBlocks.filter((x: Segment) => { const y: Dimension | null = getDimension(x, 'C'); - if (y != null && y.Start == to) { + if (y != null && y.Start === to) { return y; } }); -} +}; let desired = new TileBounds (0, 0, 0, 0); function findRelatedTest(cval: number, tilesize: number, tileoverlap: number, x1: number, y1: number) { @@ -300,15 +308,10 @@ console.log('\n\n\n\n\n\n\n'); - - - - - - +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Begin work on getting the new tiles all nice -function sortSegmentsTest(cval: number, tilesize: number, tileoverlap: number, x1: number, y1: number) { +const sortSegmentsTest: Function = function(cval: number, tilesize: number, tileoverlap: number, x1: number, y1: number): Segment[][] { desired = new TileBounds ( x1 - tileoverlap, x1 + tilesize + tileoverlap, @@ -317,21 +320,23 @@ function sortSegmentsTest(cval: number, tilesize: number, tileoverlap: number, x ); filterC(cval); console.log('\nC Value: ' + cval + ' TileSize: ' + tilesize + ' TileOverlap(px): ' + tileoverlap + ' Coords: ' + `[X=${x1}, Y=${y1}]`); - let outputGrid: Segment[][] = orderSegments(findRelatedTiles(c_filter, desired)); + const outputGrid: Segment[][] = orderSegments(findRelatedTiles(c_filter, desired)); for (const row of outputGrid) { - let rowOutput: string = "[ "; + let rowOutput: string = '[ '; for (const col of row) { rowOutput += ` '${col.Data.Data}', `; } rowOutput += ']'; console.log(rowOutput); } -} + return outputGrid; +}; +// Print out all of the related tiles to every new tile to be created. +for (let ys: number = 0; ys < totalSizeY; ys += tileSize) { + for (let xs: number = 0; xs < totalSizeX; xs += tileSize) { + const sortedSegments: Segment[][] = sortSegmentsTest(0, tileSize, tileOverlap, xs, ys); -for (let ys: number = 0; ys < sizeY; ys += tileSize) { - for (let xs: number = 0; xs < sizeX; xs += tileSize) { - sortSegmentsTest(0, tileSize, tileOverlap, xs, ys); } } diff --git a/src/errors/errorware.ts b/src/errors/errorware.ts index e2355de..27040e7 100644 --- a/src/errors/errorware.ts +++ b/src/errors/errorware.ts @@ -55,7 +55,6 @@ export const errorHandler: Errorware = (err: Error, req: Request, res: Response, next: NextFunction): void => { console.log(err); if (RequestError.is(err)) { - console.log('fewkuihfklsfv'); res.status(err.code) .json(err.responseBlock()); } else { diff --git a/src/index.ts b/src/index.ts index 601f510..6ad2d81 100644 --- a/src/index.ts +++ b/src/index.ts @@ -56,7 +56,7 @@ logger.info(`Port ${port} chosen`); const root: User = new User({ username: 'hafeez', password: 'pass', - userGroup: admin + userGroups: [admin] }); root.save(); -- cgit v1.2.1 From bd097386cf45f8afe4aa3bec863955bfed156394 Mon Sep 17 00:00:00 2001 From: cjd24 Date: Wed, 7 Mar 2018 09:34:55 +0000 Subject: BASE LAYER EXTRACTION WORKS OMMMGGGG --- src/conversion/czi/czi.ts | 121 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 109 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/conversion/czi/czi.ts b/src/conversion/czi/czi.ts index a52508a..7e39d68 100644 --- a/src/conversion/czi/czi.ts +++ b/src/conversion/czi/czi.ts @@ -3,8 +3,10 @@ import * as fs from 'fs'; import { logger } from '../../logger'; import * as sharp from 'sharp'; import * as parsexml from 'xml-parser'; +import { SharpInstance } from 'sharp'; const extractionDirectory: string = '/cs/scratch/cjd24/0701-extraction/'; +const outputImageDirectory: string = '/cs/scratch/cjd24/0701-extraction-processed/' const tileOverlap: number = 0; const tileSize: number = 1024; @@ -77,27 +79,27 @@ const findRelatedTiles: Function = function(activeSegments: Segment[], desired: // Desired X on left is within current tile if (((desired.left >= origCoords.left) && - (desired.left <= origCoords.right)) || + (desired.left < origCoords.right)) || // Desired X on right is within the current tile - ((desired.right >= origCoords.left) && - (desired.right <= origCoords.right)) || + ((desired.right > origCoords.left) && + (desired.right <= origCoords.right)) || // Desired tile X overlaps base tile ((desired.left < origCoords.left) && - (desired.right > origCoords.right))) { + (desired.right > origCoords.right))) { // Desired Y on top is within current tile if (((desired.top >= origCoords.top) && - (desired.top <= origCoords.bottom)) || + (desired.top < origCoords.bottom)) || // Desired Y on right is within the current tile - ((desired.bottom >= origCoords.top) && - (desired.bottom <= origCoords.bottom)) || + ((desired.bottom > origCoords.top) && + (desired.bottom <= origCoords.bottom)) || // Desired tile Y overlaps whole base tile ((desired.top < origCoords.top) && - (desired.bottom > origCoords.bottom))) { + (desired.bottom > origCoords.bottom))) { relatedTiles.push(baseTile); } @@ -173,6 +175,89 @@ const orderSegments: Function = function(segments: Segment[]): Segment[][] { } }; +const findRegionToExtract: Function = function(segment: Segment, desired: TileBounds): TileBounds { + const baseBounds: TileBounds = getOriginalTileBounds(segment); + let chunkToExtract: TileBounds = new TileBounds(-1, -1, -1, -1); + + if (desired.left <= baseBounds.left) { + chunkToExtract.left = 0; + } else { + chunkToExtract.left = desired.left - baseBounds.left; + } + + if (desired.right >= baseBounds.right) { + chunkToExtract.right = baseBounds.right - baseBounds.left; + } else { + chunkToExtract.right = desired.right - baseBounds.left; + } + + if (desired.top <= baseBounds.top) { + chunkToExtract.top = 0; + } else { + chunkToExtract.top = desired.top - baseBounds.top; + } + + if (desired.bottom >= baseBounds.bottom) { + chunkToExtract.bottom = baseBounds.bottom - baseBounds.top; + } else { + chunkToExtract.bottom = desired.bottom - baseBounds.top; + } + + return chunkToExtract; +}; + +const extractAndStitchChunks: Function = async function(segments: Segment[][], desiredRegion: TileBounds): Promise { + + let tileVerticalBuffer: Buffer[] = []; + + for (const segRow of segments) { + let tileRow: Buffer[] = []; + let chunkToExtract: TileBounds = new TileBounds(-1, -1, -1, -1); + for (const segCol of segRow) { + chunkToExtract = findRegionToExtract(segCol, desiredRegion); + let data: Promise = + sharp(`${extractionDirectory}${segCol.Data.Data}`) + .extract({ + left: chunkToExtract.left, + top: chunkToExtract.top, + width: chunkToExtract.right - chunkToExtract.left, + height: chunkToExtract.bottom - chunkToExtract.top + }) + .toBuffer(); + + tileRow.push(await data); + } + + let imageVerticalSlice: SharpInstance = sharp(tileRow[0]); + let bufferBound = findRegionToExtract(segRow[0], desiredRegion); + if ((bufferBound.right - bufferBound.left) < (tileSize - tileOverlap)) { + imageVerticalSlice = await imageVerticalSlice.extend( + {top:0, left:0, bottom:0, right: (tileSize - (bufferBound.right - bufferBound.left))}); + } + for (let index = 1; index < segRow.length; index++) { + imageVerticalSlice = imageVerticalSlice + .overlayWith(tileRow[index], + {top: 0, left: (bufferBound.right - bufferBound.left) + ((index -1) * tileSize)}); + } + + tileVerticalBuffer.push(await imageVerticalSlice.toBuffer()); + } + + let finalImage: SharpInstance = sharp(tileVerticalBuffer[0]); + let bufferBound = findRegionToExtract(segments[0][0], desiredRegion); + if ((bufferBound.bottom - bufferBound.top) < (tileSize - tileOverlap)) { + finalImage = await finalImage.extend( + {top:0, left:0, bottom: (tileSize - (bufferBound.bottom - bufferBound.top)), right: 0}); + } + for (let index = 1; index < segments.length; index++) { + finalImage = finalImage.overlayWith( + tileVerticalBuffer[index], + {top: getDimension(segments[index -1][0], 'Y').Size, left: 0}); + } + + return finalImage; +}; + @@ -334,9 +419,21 @@ const sortSegmentsTest: Function = function(cval: number, tilesize: number, tile }; // Print out all of the related tiles to every new tile to be created. -for (let ys: number = 0; ys < totalSizeY; ys += tileSize) { - for (let xs: number = 0; xs < totalSizeX; xs += tileSize) { - const sortedSegments: Segment[][] = sortSegmentsTest(0, tileSize, tileOverlap, xs, ys); - +let filecoutner: number = 0; +async function main(): Promise { + // temper: + for (let ys: number = 0; ys < totalSizeY; ys += tileSize) { + for (let xs: number = 0; xs < totalSizeX; xs += tileSize) { + const sortedSegments: Segment[][] = sortSegmentsTest(0, tileSize, tileOverlap, xs, ys); + (await extractAndStitchChunks(sortedSegments, desired)).toFile(`${outputImageDirectory}img-${filecoutner++}`); + } + // break temper; } } + +main().then(v => { + //Write the json hierarchy map to file + console.log("complete"); +}, err => { + console.log(err); +}); -- cgit v1.2.1 From 7acbbac2bff4976a161ee724db91716659c1f881 Mon Sep 17 00:00:00 2001 From: cjd24 Date: Wed, 7 Mar 2018 15:40:54 +0000 Subject: Adding support for the protocol's supported_views thing and laid base work for building up multi-dimentional hierarchy --- src/conversion/czi/czi.ts | 220 ++++++++++++++++++++++------------------------ 1 file changed, 106 insertions(+), 114 deletions(-) (limited to 'src') diff --git a/src/conversion/czi/czi.ts b/src/conversion/czi/czi.ts index 7e39d68..addf43e 100644 --- a/src/conversion/czi/czi.ts +++ b/src/conversion/czi/czi.ts @@ -6,9 +6,10 @@ import * as parsexml from 'xml-parser'; import { SharpInstance } from 'sharp'; const extractionDirectory: string = '/cs/scratch/cjd24/0701-extraction/'; -const outputImageDirectory: string = '/cs/scratch/cjd24/0701-extraction-processed/' +const outputImageDirectory: string = '/cs/scratch/cjd24/0701-extraction-processed2/' const tileOverlap: number = 0; const tileSize: number = 1024; +const maxZoom: number = 64; interface Dimension { Dimension: string; @@ -40,6 +41,45 @@ class TileBounds { this.bottom = bottomBound; } } +interface SupportedViews { + scalable_image: { + width: number; + height: number; + channels: [ + { + channel_id: string; + channel_name: string; + metadata?: {}; + } + ]; + real_width?: { + value: number; + units: string; + }; + real_height?: { + value: number; + units: string; + }; + metadata?: {}; + } +} +interface CZITile { + x_offset: number; + y_offset: number; + width: number; + height: number; + file: string; +} +interface CZIHeightMap { + zoom_level: number, + plane: CZITile[][]; +} +interface WholeCZIHierarchy { + c_values: [{ + channel_id: string, + height_map: CZIHeightMap[]; + }]; +} const getOriginalTileBounds: Function = function(originalTile: Segment): (TileBounds | null) { const bounds: TileBounds = new TileBounds(-1, -1, -1, -1); @@ -130,7 +170,7 @@ const orderSegments: Function = function(segments: Segment[]): Segment[][] { const initC: number = getDimension(segments[0], 'C').Start; for (const seg of segments) { if (getDimension(seg, 'C').Start !== initC) { - throw new Error("Segment array contains multiple values of C - this overlay is currently unsupported within this method"); + throw new Error('Segment array contains multiple values of C - this overlay is currently unsupported within this method'); } xCoords.push(getDimension(seg, 'X').Start); yCoords.push(getDimension(seg, 'Y').Start); @@ -235,7 +275,7 @@ const extractAndStitchChunks: Function = async function(segments: Segment[][], d {top:0, left:0, bottom:0, right: (tileSize - (bufferBound.right - bufferBound.left))}); } for (let index = 1; index < segRow.length; index++) { - imageVerticalSlice = imageVerticalSlice + imageVerticalSlice = await imageVerticalSlice .overlayWith(tileRow[index], {top: 0, left: (bufferBound.right - bufferBound.left) + ((index -1) * tileSize)}); } @@ -261,31 +301,21 @@ const extractAndStitchChunks: Function = async function(segments: Segment[][], d - - - - - - - - - - - - - - +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// const dataBlocks: Segment[] = require(`${extractionDirectory}outputjson.json`).czi.filter( (s: Segment) => s.Id === 'ZISRAWSUBBLOCK' && s.Data.Data !== 'empty'); -const inspect: object = require('util').inspect; -const metaXML: parsexml.Node[] = parsexml(fs.readFileSync(`${extractionDirectory}FILE-META-1.xml`, 'utf8')).root.children; +const inspect = require('util').inspect; +const metaXML: parsexml.Document = parsexml(fs.readFileSync(`${extractionDirectory}FILE-META-1.xml`, 'utf8')); + +let supportedViews: SupportedViews = {scalable_image: {width: -1, height: -1, channels: [{channel_id: '-1', channel_name: ''}], metadata: metaXML}}; +supportedViews.scalable_image.channels.pop(); let totalSizeX: number = -1; let totalSizeY: number = -1; // THE FOLLOWING FOR LOOP IS DISGUSTING AND I HATE IT, AND I WISH I DIDNT WRITE IT BUT DON'T SEE ANY OTHER WAY TO DO IT LOL :'( -for (const child of metaXML) { +for (const child of metaXML.root.children) { if (child.name === 'Metadata') { for (const entry of child.children) { if (entry.name === 'Information') { @@ -294,8 +324,26 @@ for (const child of metaXML) { for (const property of properties.children) { if (property.name === 'SizeX' && property.content) { totalSizeX = Number.parseInt(property.content, 10); + supportedViews.scalable_image.width = totalSizeX; + continue; } else if (property.name === 'SizeY' && property.content) { totalSizeY = Number.parseInt(property.content, 10); + supportedViews.scalable_image.height = totalSizeY; + continue; + } else if(property.name === 'Dimensions') { + for (const chan of property.children) { + if (chan.name === 'Channels') { + for (const channel of chan.children) { + supportedViews.scalable_image.channels.push( + { + channel_id: channel.attributes.Id.split(":")[1], + channel_name: channel.attributes.Name, + metadata: channel.children + } + ); + } + } + } } } } @@ -328,112 +376,56 @@ for (const seg of dataBlocks) { } } -// // TESTS TO SEE WHAT VARIOUS THINGS RETURN -// // `npm bin`/ts-node czi.ts -console.log('\n\nUnique Tile Sizes:'); -console.log(uniqueTileSizes); -console.log('\n\nSizeX : ' + totalSizeX); -console.log('UNIQUE X VALUES:'); -console.log(uniqueX); -console.log('\n\n(tentative) SizeY : ' + totalSizeY); -console.log('UNIQUE Y VALUES:'); -console.log(uniqueY); - -let x: number = 1500, y: number = 1500; -let c_filter: Segment[] = []; +let filteredDataBlocks: Segment[] = []; const filterC: Function = function(to: number): void { - c_filter = dataBlocks.filter((x: Segment) => { - const y: Dimension | null = getDimension(x, 'C'); - if (y != null && y.Start === to) { - return y; - } - }); -}; - -let desired = new TileBounds (0, 0, 0, 0); -function findRelatedTest(cval: number, tilesize: number, tileoverlap: number, x1: number, y1: number) { - desired = new TileBounds ( - x1 - tileoverlap, - x1 + tilesize + tileoverlap, - y1 - tileoverlap, - y1 + tilesize + tileoverlap + filteredDataBlocks = dataBlocks.filter( + (item: Segment, index: number, array: Segment[]) => getDimension(item, 'C').Start === to ); - filterC(cval); - console.log('\n\nC Value: ' + cval + ' TileSize: ' + tilesize + ' TileOverlap(px): ' + tileoverlap + ' Coords: ' + `[X=${x1}, Y=${y1}]\nResults: `); - console.log(findRelatedTiles(c_filter, desired).map((x: Segment) => x.Data.Data)); -} - -findRelatedTest(0, 1024, 5, 1500, 1500); - -findRelatedTest(1, 5000, 5, 1500, 1500); - -findRelatedTest(0, 1024, 5, 0, 0); - -findRelatedTest(0, 1024, 5, 41940, 59240); - -findRelatedTest(0, 1024, 5, -tileSize - tileOverlap - 1, 59240); - -findRelatedTest(0, 1024, 5, 41945, 59245); - -findRelatedTest(3, 1024, 5, 41940, 1500); - -filterC(0); -console.log('\n\n\n\n\n\n\n'); - - - - - - - - - - - - +}; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Begin work on getting the new tiles all nice -const sortSegmentsTest: Function = function(cval: number, tilesize: number, tileoverlap: number, x1: number, y1: number): Segment[][] { - desired = new TileBounds ( - x1 - tileoverlap, - x1 + tilesize + tileoverlap, - y1 - tileoverlap, - y1 + tilesize + tileoverlap - ); - filterC(cval); - console.log('\nC Value: ' + cval + ' TileSize: ' + tilesize + ' TileOverlap(px): ' + tileoverlap + ' Coords: ' + `[X=${x1}, Y=${y1}]`); - const outputGrid: Segment[][] = orderSegments(findRelatedTiles(c_filter, desired)); - - for (const row of outputGrid) { - let rowOutput: string = '[ '; - for (const col of row) { - rowOutput += ` '${col.Data.Data}', `; - } - rowOutput += ']'; - console.log(rowOutput); - } - return outputGrid; -}; - // Print out all of the related tiles to every new tile to be created. let filecoutner: number = 0; -async function main(): Promise { - // temper: - for (let ys: number = 0; ys < totalSizeY; ys += tileSize) { +async function extrapolateDimension(cVal: number, totalCs: number, maxZoomLevel: number): Promise { + console.log(`Stage (${cVal + 1}/${totalCs}): Task(0/${Math.ceil(totalSizeY/tileSize)}): 0% complete.`) + for (let ys: number = 0; ys < totalSizeY;) { + var timing = process.hrtime(); for (let xs: number = 0; xs < totalSizeX; xs += tileSize) { - const sortedSegments: Segment[][] = sortSegmentsTest(0, tileSize, tileOverlap, xs, ys); + const desired = new TileBounds ( + xs - tileOverlap, + xs + tileSize + tileOverlap, + ys - tileOverlap, + ys + tileSize + tileOverlap + ); + filterC(cVal); + + // console.log(filteredDataBlocks.map((x: any) => x.Data.DirectoryEntry.DimensionEntries[2])); + const sortedSegments: Segment[][] = orderSegments(findRelatedTiles(filteredDataBlocks, desired)); (await extractAndStitchChunks(sortedSegments, desired)).toFile(`${outputImageDirectory}img-${filecoutner++}`); } - // break temper; + ys += tileSize; + timing = process.hrtime(timing); + console.log(`Stage (${cVal + 1}/${totalCs}): Task(${ys/tileSize}/${Math.ceil(totalSizeY/tileSize)}): ${Math.ceil(((ys/totalSizeY)*100) *100)/100}% complete. (${timing[0]} sec/iter)`); } + return []; } -main().then(v => { - //Write the json hierarchy map to file - console.log("complete"); -}, err => { - console.log(err); -}); +let finalCZIJson: WholeCZIHierarchy = {} as any; +async function main(): Promise { + for (const cval of supportedViews.scalable_image.channels) { + await extrapolateDimension(Number.parseInt(cval.channel_id, 10), supportedViews.scalable_image.channels.length, maxZoom).then(v => + { + finalCZIJson.c_values.push({channel_id: cval.channel_id, height_map: v}); + console.log(`Completed Tier: ${cval.channel_id}`); + return; + }, err => { + console.error(err); + } + ); + } + fs.writeFile(`${outputImageDirectory}layout.json`, JSON.stringify(finalCZIJson), (err) => console.error(err)); +} +main(); -- cgit v1.2.1