#ifndef _JRN_PROCESSING_H
#define _JRN_PROCESSING_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <float.h>
#include <math.h>
#include "layout.h"//graph
#include "globals.h"
#include "vcbcolor.h" //color table interpolation

#ifdef __cplusplus
extern "C" {
#endif

//------------------------------------------------------------------------
// Creates a color code index based upon normalized fiber features
//------------------------------------------------------------------------
void Normalize(const int numVerts, const short int minRange, const short int maxRange, short int** data);
void Normalize1sd(const short int min,      const short int max,
                  const short int minRange, const short int maxRange,
                  short int* data);

//------------------------------------------------------------------------
// Normalize the floating point vector
//------------------------------------------------------------------------
void Normalize4f(const float minRange, const float maxRange, float* data[4]);
void Normalizef(const float minRange, const float maxRange, int nelem, float** data);
void Normalize1f(const float startRange, const float endRange,
                const float minRange, const float maxRange,
                float* data);
void Normalizefv(const float startRange, const float endRange,
                const float minRange, const float maxRange,
                int nelem, float** data);

//------------------------------------------------------------------------
// Get the minimum and maximum from an array
//------------------------------------------------------------------------
void getMinMaxfv(int numElems, float* data, float* min, float* max);
void getMinMaxiv(int numElems, int* data, int* min, int* max);

/*
Function : kth_smallest()
In : array of elements, # of elements in the array, rank k
Out : one element
Job : find the kth smallest element in the array
Notice : use the median() macro defined below to get the median.
Reference:
Author: Wirth, Niklaus
Title: Algorithms + data structures = programs
Publisher: Englewood Cliffs: Prentice-Hall, 1976
Physical description: 366 p.
Series: Prentice-Hall Series in Automatic Computation
*/
float kth_smallest(float a[], int n, int k);
//
//These are used to compute the median
//
#define ELEM_SWAP(a,b) { register float t=(a);(a)=(b);(b)=t; }
#define median(a,n) kth_smallest(a,n,(((n)&1)?((n)/2):(((n)/2)-1)))

//------------------------------------------------------------------------
// Creates a randomized array of short ints
//------------------------------------------------------------------------
void initRandom(int numDims, short int min, short int max, const int numVerts, short int** location);

//------------------------------------------------------------------------
// Initialize voxels and point all normals randomly
//------------------------------------------------------------------------
void initVoxelsWithRandNormals(int numVerts,unsigned char** voxels, int colorIndex, viewData view);

//------------------------------------------------------------------------
// Initialize voxels with all normals pointing in the Z direction
//------------------------------------------------------------------------
void initVoxelsWithZNormals(int numVerts,unsigned char** voxels, int colorIndex, viewData view);

//------------------------------------------------------------------------
// Initialize voxels and point all normals for the data towards the viewer
//------------------------------------------------------------------------
void initNormals(int numVerts,unsigned char** voxels, int colorIndex, viewData view);

//------------------------------------------------------------------------
// Create float[256][4] color lookup table via HSV interpolation of given
// values: index1,R1,G1,B1,index2,R2,G2,B2
//------------------------------------------------------------------------
float** createTLUT(int numFilled, float* idxRGB);


#ifdef __cplusplus
}
#endif

#endif
