<commit_before>// Source file for connectome visualization



// include files

#include "R3Graphics/R3Graphics.h"
#include "RNDataStructures/RNDataStructures.h"
#include "fglut/fglut.h"
#include <fstream>
#include <vector>


// GLUT defines

#define ENTER 13
#define ESCAPE 27
#define SPACEBAR 32

static const int OR_Z = 0;
static const int OR_Y = 1;
static const int OR_X = 2;



// program arguments

// I/O flags
static int print_debug = 0;
static int print_verbose = 0;
static const char* prefix = NULL;



// program variables

static double resolution[3] = { 30, 8, 8 };
static long grid_size[3] = { -1, -1, -1 };
static R3Affine transformation = R3null_affine;
static R3Viewer *viewer = NULL;
static R3Box world_box = R3null_box;



// display variables

static double background_color[3] = { 0.0, 0.0, 0.0 };



// GLUT variables

static int GLUTwindow = 0;
static int GLUTwindow_height = 720;
static int GLUTwindow_width = 1280;
static int GLUTmouse[2] = { 0, 0 };
static int GLUTbutton[3] = { 0, 0, 0 };
static int GLUTmodifiers = 0;



// random access variables

static std::vector<long> surfaces;
static std::vector<long> synapses;
static std::vector<long> connectome;
static std::vector<long> somae;


// display variables

static const int ncolor_opts = 24;
static int show_bbox = 1;
static int segmentation_index = 1;
static RNScalar downsample_rate = 0.5;
static int color_cycle = 0;
static int skeleton_method = 0;
static double skeleton_point_size = 3;
static double synapse_point_size = 100;



////////////////////////////////////////////////////////////////////////
// Input/output functions
////////////////////////////////////////////////////////////////////////


static int ReadSurfaceData(void)
{
    surfaces = std::vector<long>();

    char surface_filename[4096];
    sprintf(surface_filename, "surfaces/%s/%06d.pts", prefix, segmentation_index);

    FILE *fp = fopen(surface_filename, "rb");
    if (!fp) { fprintf(stderr, "Failed to read %s.\n", surface_filename); return 0; }

    long nsurface_points;
    if (fread(&(grid_size[OR_Z]), sizeof(long), 1, fp) != 1) { fprintf(stderr, "Failed to read %s.\n", surface_filename); return 0; }
    if (fread(&(grid_size[OR_Y]), sizeof(long), 1, fp) != 1) { fprintf(stderr, "Failed to read %s.\n", surface_filename); return 0; }
    if (fread(&(grid_size[OR_X]), sizeof(long), 1, fp) != 1) { fprintf(stderr, "Failed to read %s.\n", surface_filename); return 0; }
    if (fread(&nsurface_points, sizeof(long), 1, fp) != 1) { fprintf(stderr, "Failed to read %s.\n", surface_filename); return 0; }
    
    for (long iv = 0; iv < nsurface_points; ++iv) {
        long voxel_index;
        if (fread(&voxel_index, sizeof(long), 1, fp) != 1) { fprintf(stderr, "Failed to read %s.\n", surface_filename); return 0; }
        surfaces.push_back(voxel_index);
    }

    // return success
    return 1;
}



static int ReadSynapseData(void)
{
    synapses = std::vector<long>();

    char synapse_filename[4096];
    sprintf(synapse_filename, "synapses/%s/%06d.pts", prefix, segmentation_index);

    FILE *fp = fopen(synapse_filename, "rb");
    if (!fp) { fprintf(stderr, "Failed to read %s.\n", synapse_filename); return 0; }

    long nsynapse_points;
    if (fread(&(grid_size[OR_Z]), sizeof(long), 1, fp) != 1) { fprintf(stderr, "Failed to read %s.\n", synapse_filename); return 0; }
    if (fread(&(grid_size[OR_Y]), sizeof(long), 1, fp) != 1) { fprintf(stderr, "Failed to read %s.\n", synapse_filename); return 0; }
    if (fread(&(grid_size[OR_X]), sizeof(long), 1, fp) != 1) { fprintf(stderr, "Failed to read %s.\n", synapse_filename); return 0; }
    if (fread(&nsynapse_points, sizeof(long), 1, fp) != 1) { fprintf(stderr, "Failed to read %s.\n", synapse_filename); return 0; }

    for (long iv = 0; iv < nsynapse_points; ++iv) {
        long voxel_index;
        if (voxel_index < 0) {
            voxel_index = -1 * voxel_index;
        }
        if (fread(&voxel_index, sizeof(long), 1, fp) != 1) { fprintf(stderr, "Failed to read %s.\n", synapse_filename); return 0; }
        synapses.push_back(voxel_index);
    }

    // return success 
    return 1;
}



static int ReadConnectomeData(void)
{
    connectome = std::vector<long>();

    char connectome_filename[4096];
    if (skeleton_method == 0) sprintf(connectome_filename, "connectomes/%s/%06d.pts", prefix, segmentation_index);
    else if (skeleton_method == 1) sprintf(connectome_filename, "skeletons/%s/%06d.pts", prefix, segmentation_index);
    else if (skeleton_method == 2) sprintf(connectome_filename, "baselines/topological-thinnings-downsampled/%s/%06d.pts", prefix, segmentation_index);
    else if (skeleton_method == 3) sprintf(connectome_filename, "baselines/teasers/%s/%06d.pts", prefix, segmentation_index);
    else return 0;

    FILE *fp = fopen(connectome_filename, "rb"); <commit_msg>wiring: updated to newest version<commit_after>// Source file for connectome visualization



// include files

#include "R3Graphics/R3Graphics.h"
#include "RNDataStructures/RNDataStructures.h"
#include "fglut/fglut.h"
#include <fstream>
#include <vector>


// GLUT defines

#define ENTER 13
#define ESCAPE 27
#define SPACEBAR 32

static const int OR_Z = 0;
static const int OR_Y = 1;
static const int OR_X = 2;



// program arguments

// I/O flags
static int print_debug = 0;
static int print_verbose = 0;
static const char* prefix = NULL;



// program variables

static double resolution[3] = { 30, 8, 8 };
static long grid_size[3] = { -1, -1, -1 };
static R3Affine transformation = R3null_affine;
static R3Viewer *viewer = NULL;
static R3Box world_box = R3null_box;



// display variables

static double background_color[3] = { 0.0, 0.0, 0.0 };



// GLUT variables

static int GLUTwindow = 0;
static int GLUTwindow_height = 720;
static int GLUTwindow_width = 1280;
static int GLUTmouse[2] = { 0, 0 };
static int GLUTbutton[3] = { 0, 0, 0 };
static int GLUTmodifiers = 0;



// random access variables

static std::vector<long> surfaces;
static std::vector<long> synapses;
static std::vector<long> connectome;
static std::vector<long> somae;


// display variables

static const int ncolor_opts = 24;
static int show_bbox = 1;
static int segmentation_index = 1;
static RNScalar downsample_rate = 0.5;
static int color_cycle = 0;
static int skeleton_method = 0;
static double skeleton_point_size = 3;
static double synapse_point_size = 100;



////////////////////////////////////////////////////////////////////////
// Input/output functions
////////////////////////////////////////////////////////////////////////


static int ReadSurfaceData(void)
{
    surfaces = std::vector<long>();

    char surface_filename[4096];
    sprintf(surface_filename, "surfaces/%s/%06d.pts", prefix, segmentation_index);

    FILE *fp = fopen(surface_filename, "rb");
    if (!fp) { fprintf(stderr, "Failed to read %s.\n", surface_filename); return 0; }

    long nsurface_points;
    if (fread(&(grid_size[OR_Z]), sizeof(long), 1, fp) != 1) { fprintf(stderr, "Failed to read %s.\n", surface_filename); return 0; }
    if (fread(&(grid_size[OR_Y]), sizeof(long), 1, fp) != 1) { fprintf(stderr, "Failed to read %s.\n", surface_filename); return 0; }
    if (fread(&(grid_size[OR_X]), sizeof(long), 1, fp) != 1) { fprintf(stderr, "Failed to read %s.\n", surface_filename); return 0; }
    if (fread(&nsurface_points, sizeof(long), 1, fp) != 1) { fprintf(stderr, "Failed to read %s.\n", surface_filename); return 0; }
    
    for (long iv = 0; iv < nsurface_points; ++iv) {
        long voxel_index;
        if (fread(&voxel_index, sizeof(long), 1, fp) != 1) { fprintf(stderr, "Failed to read %s.\n", surface_filename); return 0; }
        surfaces.push_back(voxel_index);
    }

    // return success
    return 1;
}



static int ReadSynapseData(void)
{
    synapses = std::vector<long>();

    char synapse_filename[4096];
    sprintf(synapse_filename, "synapses/%s/%06d.pts", prefix, segmentation_index);

    FILE *fp = fopen(synapse_filename, "rb");
    if (!fp) { fprintf(stderr, "Failed to read %s.\n", synapse_filename); return 0; }

    long nsynapse_points;
    if (fread(&(grid_size[OR_Z]), sizeof(long), 1, fp) != 1) { fprintf(stderr, "Failed to read %s.\n", synapse_filename); return 0; }
    if (fread(&(grid_size[OR_Y]), sizeof(long), 1, fp) != 1) { fprintf(stderr, "Failed to read %s.\n", synapse_filename); return 0; }
    if (fread(&(grid_size[OR_X]), sizeof(long), 1, fp) != 1) { fprintf(stderr, "Failed to read %s.\n", synapse_filename); return 0; }
    if (fread(&nsynapse_points, sizeof(long), 1, fp) != 1) { fprintf(stderr, "Failed to read %s.\n", synapse_filename); return 0; }

    for (long iv = 0; iv < nsynapse_points; ++iv) {
        long voxel_index;
        if (voxel_index < 0) {
            voxel_index = -1 * voxel_index;
        }
        if (fread(&voxel_index, sizeof(long), 1, fp) != 1) { fprintf(stderr, "Failed to read %s.\n", synapse_filename); return 0; }
        synapses.push_back(voxel_index);
    }

    // return success 
    return 1;
}



static int ReadConnectomeData(void)
{
    connectome = std::vector<long>();

    char connectome_filename[4096];
    if (skeleton_method == 0) sprintf(connectome_filename, "connectomes/%s/%06d.pts", prefix, segmentation_index);
    else if (skeleton_method == 1) sprintf(connectome_filename, "skeletons/%s/%06d.pts", prefix, segmentation_index);
    else if (skeleton_method == 2) sprintf(connectome_filename, "baselines/topological-thinnings/%s/%06d.pts", prefix, segmentation_index);
    else if (skeleton_method == 3) sprintf(connectome_filename, "baselines/teasers/%s/%06d.pts", prefix, segmentation_index);
    else return 0;

    FILE *fp = fopen(connectome_filename, "rb"); 
{'fraction_non_alphanumeric': 0.1699629171817058, 'fraction_numerical': 0.02657601977750309, 'mean_word_length': 3.511617100371747, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '732416', 'n_tokens_mistral': 3496, 'n_tokens_neox': 3189, 'n_words': 902}