<commit_before>#include <pic2vtk/pic2vtk.h>
#include <vtkStructuredPointsReader.h>
#include <vtkImageCast.h> 
#include <vtkImageData.h> 
#include <vtkDataObject.h> 
#include <iostream>

/**
 * konvertiert ein vtkImageReader in ein pic-Image 
 */ 
ipPicDescriptor* Pic2vtk::convert( vtkImageData* vtkImage ) {

	if ( vtkImage == NULL )
		return NULL;

	ipPicDescriptor* pic = ipPicNew();

	if ( pic == NULL )
		return NULL;

	int dim[3];
	vtkImage->GetDimensions(dim);

	if ( dim[2] > 1 ) {
		pic->dim = 3;		
	} else if( dim[1] > 1 ) {
		pic->dim = 2;
	} else if ( dim[0] > 1 ) {
		pic->dim = 1;
	} else {
	  return NULL;
	}

	pic->n[0] = dim[0];
	pic->n[1] = dim[1];
	pic->n[2] = dim[2];

	register unsigned long size = dim[0] * dim[1] * dim[2] * vtkImage->GetNumberOfScalarComponents();

	switch ( vtkImage->GetScalarType () ) {

	case VTK_BIT: {

		pic->type = ipPicInt;
		pic->bpe = 8;
		unsigned int vtkSize = size>>3;

		if (vtkSize%8)
			vtkSize++;

		register char *s = (char*) vtkImage->GetScalarPointer();
		register char *a = (char*) malloc(sizeof(char)* size);
		pic->data = a;

		for ( register unsigned int i = 0; i < vtkSize; i++ ) {

			for ( int k=0; k < 8; k++ ) 
				*a++ = 0x80 & (*s<<k);	

			s++;
		}

		break;
	}
	case VTK_CHAR: {

		pic->type = ipPicInt;
		pic->bpe = 8*vtkImage->GetNumberOfScalarComponents();

		register char *s = (char*) vtkImage->GetScalarPointer();	
		register char *a = (char*) malloc(sizeof(char)* size);
		pic->data = a;

		for ( unsigned long i = 0; i < size; i++ )
			*a++ = *s++;

		break;
	}
	case VTK_UNSIGNED_CHAR: {

		pic->type = ipPicUInt;
		pic->bpe = 8*vtkImage->GetNumberOfScalarComponents();

		register unsigned char *s = (unsigned char*) vtkImage->GetScalarPointer();	
		register unsigned char *a = (unsigned char*) malloc(sizeof(unsigned char)* size);
		pic->data = a;

		for ( unsigned long i = 0; i < size; i++ )
			*a++ = *s++;

		break;
	}
	case VTK_SHORT: {

		pic->type = ipPicInt;
		pic->bpe = 16;

		register short *s = (short*) vtkImage->GetScalarPointer();	
		register short *a = (short*) malloc(sizeof(short)* size);
		pic->data = a;

		for ( unsigned long i = 0; i < size; i++ )
			*a++ = *s++;

		break;
	}
	case VTK_UNSIGNED_SHORT: {

		pic->type = ipPicUInt;
		pic->bpe = 16;

		register unsigned short *s = (unsigned short*) vtkImage->GetScalarPointer();	
		register unsigned short *a = (unsigned short*) malloc(sizeof(unsigned short)* size);
		pic->data = a;


		for ( unsigned long i = 0; i < size; i++ )
			*a++ = *s++;

		break;
	}
	case VTK_INT: {

		pic->type = ipPicInt;
		pic->bpe = 32;

		register int *s = (int*) vtkImage->GetScalarPointer();	
		register int *a = (int*) malloc(sizeof(int)* size);
		pic->data = a;

		for ( unsigned long i = 0; i < size; i++ )
			*a++ = *s++;

		break;
	}
	case VTK_UNSIGNED_INT: {

		pic->type = ipPicUInt;
		pic->bpe = 32;

		register unsigned int *s = (unsigned int*) vtkImage->GetScalarPointer();	
		register unsigned int *a = (unsigned int*) malloc(sizeof(unsigned int)* size);
		pic->data = a;

		for ( unsigned long i = 0; i < size; i++ )
			*a++ = *s++;

		break;
	}
	case VTK_LONG: {

		pic->type = ipPicInt;
		pic->bpe = 64;

		register long *s = (long*) vtkImage->GetScalarPointer();	
		register long *a = (long*) malloc(sizeof(long)* size);
		pic->data = a;

		for ( unsigned long i = 0; i < size; i++ )
			*a++ = *s++;

		break;
	}
	case VTK_UNSIGNED_LONG: {

		pic->type = ipPicUInt;
		pic->bpe = 64;

		register unsigned long *s = (unsigned long*) vtkImage->GetScalarPointer();	
		register unsigned long *a = (unsigned long*) malloc(sizeof(unsigned long)* size);
		pic->data = a;

		for ( unsigned long i = 0; i < size; i++ )
			*a++ = *s++;

		break;
	}
	case VTK_FLOAT: {

		pic->type = ipPicFloat;
		pic->bpe = 32;

		register float *s = (float*) vtkImage->GetScalarPointer();	
		register float *a = (float*) malloc(sizeof(float)* size);
		pic->data = a;

		for ( unsigned long i = 0; i < size; i++ )
			*a++ = *s++;

		break;
	}
	case VTK_DOUBLE: {

		pic->type = ipPicFloat;
		pic->bpe = 64;

		register double *s = (double*) vtkImage->GetScalarPointer();	
		register double *a = (double*) malloc(sizeof(double)* size);
		pic->data = a;


		for ( unsigned long i = 0; i < size; i++ )
			*a++ = *s++;

		break;
	}<commit_msg>FIX (#1112): Crash in image mapper for very large images<commit_after>#include <pic2vtk/pic2vtk.h>
#include <vtkStructuredPointsReader.h>
#include <vtkImageCast.h> 
#include <vtkImageData.h> 
#include <vtkDataObject.h> 
#include <iostream>

/**
 * konvertiert ein vtkImageReader in ein pic-Image 
 */ 
ipPicDescriptor* Pic2vtk::convert( vtkImageData* vtkImage ) {

	if ( vtkImage == NULL )
		return NULL;

	ipPicDescriptor* pic = ipPicNew();

	if ( pic == NULL )
		return NULL;

	int dim[3];
	vtkImage->GetDimensions(dim);

	if ( dim[2] > 1 ) {
		pic->dim = 3;		
	} else if( dim[1] > 1 ) {
		pic->dim = 2;
	} else if ( dim[0] > 1 ) {
		pic->dim = 1;
	} else {
	  return NULL;
	}

	pic->n[0] = dim[0];
	pic->n[1] = dim[1];
	pic->n[2] = dim[2];

	register unsigned long size = dim[0] * dim[1] * dim[2] * vtkImage->GetNumberOfScalarComponents();

	switch ( vtkImage->GetScalarType () ) {

	case VTK_BIT: {

		pic->type = ipPicInt;
		pic->bpe = 8;
		unsigned int vtkSize = size>>3;

		if (vtkSize%8)
			vtkSize++;

		register char *s = (char*) vtkImage->GetScalarPointer();
		register char *a = (char*) malloc(sizeof(char)* size);
    if(a==NULL)
    {
      ipPicFree( pic );
      return NULL;	
    }
		pic->data = a;

		for ( register unsigned int i = 0; i < vtkSize; i++ ) {

			for ( int k=0; k < 8; k++ ) 
				*a++ = 0x80 & (*s<<k);	

			s++;
		}

		break;
	}
	case VTK_CHAR: {

		pic->type = ipPicInt;
		pic->bpe = 8*vtkImage->GetNumberOfScalarComponents();

		register char *s = (char*) vtkImage->GetScalarPointer();	
		register char *a = (char*) malloc(sizeof(char)* size);
    if(a==NULL)
    {
      ipPicFree( pic );
      return NULL;	
    }
		pic->data = a;

		for ( unsigned long i = 0; i < size; i++ )
			*a++ = *s++;

		break;
	}
	case VTK_UNSIGNED_CHAR: {

		pic->type = ipPicUInt;
		pic->bpe = 8*vtkImage->GetNumberOfScalarComponents();

		register unsigned char *s = (unsigned char*) vtkImage->GetScalarPointer();	
		register unsigned char *a = (unsigned char*) malloc(sizeof(unsigned char)* size);
    if(a==NULL)
    {
      ipPicFree( pic );
      return NULL;	
    }
		pic->data = a;

		for ( unsigned long i = 0; i < size; i++ )
			*a++ = *s++;

		break;
	}
	case VTK_SHORT: {

		pic->type = ipPicInt;
		pic->bpe = 16;

		register short *s = (short*) vtkImage->GetScalarPointer();	
		register short *a = (short*) malloc(sizeof(short)* size);
    if(a==NULL)
    {
      ipPicFree( pic );
      return NULL;	
    }
		pic->data = a;

		for ( unsigned long i = 0; i < size; i++ )
			*a++ = *s++;

		break;
	}
	case VTK_UNSIGNED_SHORT: {

		pic->type = ipPicUInt;
		pic->bpe = 16;

		register unsigned short *s = (unsigned short*) vtkImage->GetScalarPointer();	
		register unsigned short *a = (unsigned short*) malloc(sizeof(unsigned short)* size);
    if(a==NULL)
    {
      ipPicFree( pic );
      return NULL;	
    }
		pic->data = a;


		for ( unsigned long i = 0; i < size; i++ )
			*a++ = *s++;

		break;
	}
	case VTK_INT: {

		pic->type = ipPicInt;
		pic->bpe = 32;

		register int *s = (int*) vtkImage->GetScalarPointer();	
		register int *a = (int*) malloc(sizeof(int)* size);
    if(a==NULL)
    {
      ipPicFree( pic );
      return NULL;	
    }
		pic->data = a;

		for ( unsigned long i = 0; i < size; i++ )
			*a++ = *s++;

		break;
	}
	case VTK_UNSIGNED_INT: {

		pic->type = ipPicUInt;
		pic->bpe = 32;

		register unsigned int *s = (unsigned int*) vtkImage->GetScalarPointer();	
		register unsigned int *a = (unsigned int*) malloc(sizeof(unsigned int)* size);
    if(a==NULL)
    {
      ipPicFree( pic );
      return NULL;	
    }
		pic->data = a;

		for ( unsigned long i = 0; i < size; i++ )
			*a++ = *s++;

		break;
	}
	case VTK_LONG: {

		pic->type = ipPicInt;
		pic->bpe = 64;

		register long *s = (long*) vtkImage->GetScalarPointer();	
		register long *a = (long*) malloc(sizeof(long)* size);
    if(a==NULL)
    {
      ipPicFree( pic );
      return NULL;	
    }
		pic->data = a;

		for ( unsigned long i = 0; i < size; i++ )
			*a++ = *s++;

		break;
	}
	case VTK_UNSIGNED_LONG: {

		pic->type = ipPicUInt;
		pic->bpe = 64;

		register unsigned long *s = (unsigned long*) vtkImage->GetScalarPointer();	
		register unsigned long *a = (unsigned long*) malloc(sizeof(unsigned long)* size);
    if(a==NULL)
    {
      ipPicFree( pic );
      return NULL;	
    }
		pic->data = a;

		for ( unsigned long i = 0; i < size; i++ )
			*a++ = *s++;

		break;
	}
	case VTK_FLOAT: {

		pic->type = ipPicFloat;
		pic->bpe = 32;

		register float *s = (float*) vtkImage->GetScalarPointer();	
		register float *a = (float*) malloc(sizeof(float)* size);
    if(a==NULL)
    {
      ipPicFree( pic );
      return NULL;	
    }
		pic->data = a;

		for ( unsigned long i = 0; i < size; i++ )
			*a++ = *s++;

		break;
	}
	case VTK_DOUBLE: {

		pic->type = ipPicFloat;
		pic->bpe = 64;

		register double *s = (double*) vtkImage->GetScalarPointer();	
		register double *a = (double*) malloc(sizeof(double)* size);
    if(a==NULL)
    {
      ipPicFree( pic );
      return NULL;	
    }
		pic->data = a;


		for ( unsigned long i = 0; i < size; i++ )
			*a++ = *s++;

		break;
	}
{'fraction_non_alphanumeric': 0.17543485220360688, 'fraction_numerical': 0.013018888058905134, 'mean_word_length': 2.8936435396759452, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 135, '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': '2825686', 'n_tokens_mistral': 4075, 'n_tokens_neox': 3583, 'n_words': 944}