S - real time fem nonlinear software license manager piracy copy ...

plainspecialΛογισμικό & κατασκευή λογ/κού

14 Δεκ 2013 (πριν από 3 χρόνια και 8 μήνες)

409 εμφανίσεις















S.E.D.


Scientific Engineering DLL.


Version 1.01.


Important notes:


(*)
The
functions included in the S.E.D. contain

highly complicated algorithms and subjected inaccuracies
or malfunctions in some cases, depending on user inputs
, usage co
rrectn
ess and computer accuracy
limitations..


(**) Although the code was thoroughly checked, it may still contain undetected bugs or any other error
type.


Table of conten
t
:


General usage instructions of the S.E.D. functions

Special data
structures

List of functions grouped

by subject

Optimization

Curve fitting

Encryption and decryption

Random numbers

Signal and image processing

Differential equations

Array operations

Matrix operations

Equations system

Complex numbers

2D graphics

2D geometry

3D graphics

3D ge
ometry

3D vector operations

Surfaces

Optics

Sound

Symbolic calculations

Strin
gs operations

Utility functions

Optimization

BestFitCircle

Best fit circle to 3D points cloud. The sum of the circle
-
point distance
squares is minimized.

B
estFitLine

Best fit line to 3D points cloud. The sum of the line
-
point distance
squares is minimized.

BestFitPlain

Best fit plain to 3D points cloud. The sum of the plain
-
point distance
squares is minimized.

Find_N_dimLocalMin

Find local minimum of multidimensional function.

Find_N_dimLocalMin_constraint

Find local minimum of multidimensional function under constraints.

FindLocalMinimum_z_Fxy

Find local minimum point of 2D function
.

FindMultiMinimum_z_Fxy

Find multiple minimum point of 2D function
.

FindMultiMinimumF_1D

Find multiple local minimum of a continues function in a defined
interval.

FindOneLocalMinF_1D

Find local minimum of a continues function in a defi
ned interval.

FindZeroCrossFX

Find roots of a continues function in a defined interval.


Curve fitting

2D and 3D

_3DcubicCurve

Calculate the coefficients of 3 cubic polynomials of

3D parametric
cubic curve.

CubicPolynom

Find cubic polynomial according to 2 points and the derivatives at
those points.

CurveMidPoints3D

Calculate the coefficients of cascaded cubi
c parametric curves passing
threw cascaded control points mid
-
values and tangent to these point
connecting lines.

Calculate a point on the calculated curve.

CurvePoints3D

Calculate the coefficients of cascaded cubic para
metric curves passing
threw control points.

Calculate a point on the calculated curve.

PointsToXYpolynom

Find a polynomial
that contains an array of 2D input
points.


Encryption and decryption

FileDec

Decrypt a file previously encrypted using FileEnc.

FileEnc

Encrypt file.


Random numbers

NonUniformRandom

Generate random double precision number with
in an interval
according to user
defined
probability distribution function (PDF).

RandomDouble

Generate random double precision number within a interval.


Signal and image processing:

FIR_filter_design

Find FIR filter coefficients that gives the closest impulse response to
user defined function.

SignalFlatFilter

Filter a 1D signal using flat window filter.

YL_1D_cyclic_convolution

YL_1D_cyclic_convolution_s32

Cyclic convolution of 2 complex vectors.

Double and single precision.

YL_fft
,YL_fft_s32

1D complex FFT.

Double and single precision.

YL_fft_s32_real_pair

2
1D FFT or 2
different
real input arrays in parallel.

YL_fft_2D
,YL_fft_2D_s32

2D complex FFT.

Double and single precision.

YL_fft_2D_image

M*N 2D comple
x FFT of single color component 0
-
255 range.

YL_ifft
,YL_ifft_s32

1D complex inverse FFT.

Double and single precision.

YL_ifft_2D
, YL_fft_2D_s32

2D complex inverse FFT.

Double and single precisi
on.

YL_ifft_2D_image

inverse FFT on complex 2D signal.

YL_zero_pad_1D_complex

Zero padding of 1D complex vector.

Calc_Gray_histogra
m

Calculate histogram of 8 bits per pixel image.

Calc_RGB_Gray_histogram

Calculate RGB image histograms


one for each color component and
gray level histogram.

ImageEdge
Detector

8 bit per pixel image edge detector.

ImageGrayLevel_to_RGB

Expand B&W to UB_RGB array.

ImageHistogramOperation

Apply histogram operations on the input 8 bit
s per pixel image
including user defined histogram operations using general purpose
functions.

ImageLineSample

Sample
8 bits per pixel image along a generic line.

ImageRGBedgeD
etector

Apply edge detection algorithm on RGB image.

ImageRGBhistogramOperation

Apply histogram operations on the input RGB image including user
defined histogram operations using general purpose functions.



Differential equations

RungeKutta4

4
th

order Runge
-
Kutta integration of ordinary differential equation
from the type

with fixed or variable step size.

RungeKutta4_1st_Order_Eq_Sys

4
th

order Runge
-
Kutta integration of ordinary differential equations
system from the type

with fixed or variable
integration step size.

RungeKutta4_2

4
th

order
Runge
-
Kutta integration of ordinary differential equation
from the type

with fixed or variable integration
step size.

Solve_dy_dx_FXY

Solve differential equation from the type


using polynomial interpolation method with fixed
integration step.

Solve2ndOrderDifEq

Solve differential equation from the type


using polynomial interpolation method with
fixed integra
tion step.


Array operations

Array1Dpeaks

Detect all local peaks of doubles array, ascending sorted with their
original indexes of the input array.

ArrayMinMax_d64

Find minimum and ma
ximum values of doubles array using fast
SSE code.

ArrayUniqueElements_long

Extract unique elements from integers array using O(N) algorithm.

Average1Darray

Arithmetic a
ver
age of doubles array.

BlendArrays_s32
,

BlendArrays_
d64

Blend
2

arrays into one array. Even elements are from input1 and
odd elements are input 2.

CalcArrayRMS

Calculate RMS of double
s array.

Dot_d80_d80

Dot product between the 2 input arrays of doubles using 80 bits
extended double precision.

Dot_s80_d80

Dot product between
the 2 input array, one of
singles and
the ot
her
of
doubles
,
using 80 bits extended double precision.

Dot_s80_s80

Dot product between the 2 input arrays of singles using 80 bits
extended double precision.

FindNearestElement

Fi
nd the nearest element of sorted array
equal or
below an input
value.

Sum1Darray_d64

Fast sum all the element of double precision

array.

Sum1Darray_d80

High 80 bits extended double p
recision array element sum.

Sum1DarrayComplex

Sum all the element of complex numbers array.

SumArrays_d64

Fast sum 2 doubles arrays using SSE.

Su
mArrays_s32

Fast sum 2 singles arrays using SSE.

Sample1Darray

Uniform sample of the input array using linear interpolation.

Scale1Darray

Scale array of double precision numbers accord
ing to minimum and
maximum values.

ScrambleArrayDouble

Random s
cramble an array of double precision
elements

with index
exchange output.

Set1DarrayFirstLast

Scale array of
double precision numbers according to first and last
elements.

Sort
SingleElement

Find an element of the input array as if it was sorted.

SortDouble

Sort an array of double type numbers.

VariableSample1Darray

Sample an array at user defined points using linear interpolation.


Matrix operations

CholesDecomp

Cholesky decomposition of symmetric positive matrix.

Determinant33_s32
,
Determinant33_d64

Fast
single

or double

precision of 3 by 3 matrix determinant
calculation.

Matrix_Determinant_Inverse_Complex

Find complex

matrix inverse and determinant.

Matrix_Determinant_Inverse_Real

Find real matrix inverse and determinant.

Matrix88_mul_vec8_s32

Fast single precision 8x8 ma
trix multiplied with 8 elements
vector.

Matrix_12_mul_vec_1_s32

Fast single precision 12x12 matrix multiplied with 12 elements
vector.

Matrix_16_mul_vec_1_s32

Fast
single precision 16x16 matrix multiplied with 16 elements
vector.

Matrix44_mul_vector_d64

Fast double precision 4x4 matrix multiplied with 4 element
vector.

Matrix44
_mul_vector_s32

Fast single precision 4x4 matrix multiplied with 4 element
vector.

Matrix_mul_vector_d80_d80

Matrix_mul_vector_d80_s80

Matrix_mul_vector_s80_d80

Matrix_mul_vector_s80_s80

80 bits extended double precision matrix

vector multiply.

Matrix and vector can be float or double precision. There is one
function for each o
ption.

SparseMatrix_mul_vector_s80

80 bits extended double precision matrix


vector multiply.
Inputs are 32 bits single precision.

SparseMatrix_mul_vector_d
80

80 bits extended double precision matrix


vector multiply.
Inputs are 64 bits double precision.


Equations system

Solve_Ax_b_Band_Sparse_Complex

Solve linear system Ax=b with complex coefficients
wh
en A is banded or sparse matrix with single non
-
zero segment in each row.

Solve_Ax_b_Band_Sparse_Real

Solve linear system Ax=b with real coefficient
when A is banded or sparse matrix with single non
-
zero se
gment in each row.

Solve_Ax_b_GausElim_Complex

Solve linear system of equations with complex
coefficient using Gauss elimination.

Solve_Ax_b_GausElim_Real

Solv
e linear system of equations with real using
coefficient Gauss elimination.

SolveNonLinearSystem

Solve system of generic nonlinear equations.


Complex numbers

ComplexDiv

Divide 2 c
omplex numbers.

ComplexMul

Multiply 2 complex numbers.

ComplexVectorsMul
,
ComplexVectorsMul
_s32

Multiply 2 arrays of complex numbers.

ComplexVec
torsSum

Sum 2 arrays of complex numbers.


2D graphics

Close2Dgraph

Close 2D graph window that was previously opened with
Open2DgraphicsWindow.

CloseRGBdisplay

Close window that was p
reviously opened with DisplayRGBimage.

DisplayRGBimage

Opens a window and display in it the input image.

Draw2DcoordinateSystem

Draw 2D coordinate system.

Draw2Dgraph

Draw 2D graph.

Draw2Dgrid

Draw 2D grid.

graphics_2d_Scene

Draw 2D graphics scene to the selected window previously opened with
Open2DgraphicsWindow

DrawNumbersAlongLine

Draw number along line, rotated according to line direction.

Open2DgraphicsWindow

Opens 2D graphics window.

SaveRGBa
rrayToFile

Save image data to image file.

SaveScreenToFile

Save the screen, partly or entirely, to an image file.

IsPointIn_2D

Check is a point is in a polygon.

ExtractImageDataFromFile

Extract width, height and bytes per pixel from image file.

ExtractPixelsFromImageFile

Extract pixels from image file to 2D UB_RGB array.


2D geometry

_2DpointsSetToTriangleMesh

Delaunay triangulation of given planar points set
.

_3points_to_circle

Calculate center position and squared radius of a circle containing 3 i
nput
points.



3D geometry

_2_5_DpointsSetToTriangleMesh

Generate triangles surface based on 3D points

_3DpointsSetToTetraederMesh

Generate
tetrahedral mesh us
ing
Delaunay spheres
algorithms
based
on 3D points set.

_3points_to_sphere

Calculate center position and
squared
radius of the smallest sphere
containing 3 input points. All 3 points are on this sphere surface.

_4points_to_sphere

Calculate center position and
squared
radius of sphere
surface
containing 4 input points.

_3Daligned_bounding_box_s32

_3Daligned_bounding_box_d64

Find axes aligned bounding box of 3D points cloud.


3D graphics

AttachPicture

Get image from image file and prepare it to attach it to an OpenGL
surface.

CloseGraphicsWindow

Close OpenGL window previously opened with
OpenGraphicsWindow.

Draw_Grid_Plane_Curve

Draw the intersection curve of a quads grid and a plain.

Draw3DtextDirection

Draw 3D text headed toward specified direction vector and rotated
around this vector at a specified angle.

DrawAngleText

Draw 2D text at the desired angle.

DrawBarChart

Draw an OpenGL bar chart.

DrawCoordinateSystem

Draw simple coordinate system to an OpenGL window.

DrawCoordinateSystemExtended

Draw 3D

coordinate system with labels, axes titles, axes geometry,
grids and values along the axes.

DrawCubicCurve

Draw 3D cubic curve to an OpenGL window.

DrawPlanarWireframeGrid

Draw an OpenGL
planar
wire
-
frame grid.

glEulerRotation

Apply Euler angles rotation on the current OpenGL scene.

glReverseEulerRotation

Reverse operation of glEulerRotation f
unction.

gluArrow

Draw an OpenGL arrow.

gluBox

Draw an OpenGL box with different 6 textures, one for each facet.

gluElipCurve

Draw an OpenGL elliptic curve.

gluElipsoid

Draw an OpenGL ellipsoid surface.

gluParametricSurf

Draw parametric surface to an OpenGL window with texture option.

gluPipe

Draw an OpenGL circ
ular envelop around a centerline curve using
passing threw control point using linear interpolation. Has a texture
option.

gluPipe3Dspline

Draw an OpenGL circular envelop around a spline centerline curve
passing threw
control point. Has a texture option.

gluQuadsNormalsGrid

Draw anOpenGL surface made using points grid and the normal at
each points.

gluSpring

Draw an OpenGL spring shape with textur
e option.

gluTorus

Draw an OpenGL torus surface with texture option.

glVectorRotationFromZaxis

Apply the OpenGL function “glRotated” such that it will perform
rotation from the
Z axis to the input vector.

MoveResizeOpenGLwindow

Move and resize OpenGL window previously opened with
OpenGraphicsWindow.

OpenGL_Scene

Draw OpenGL scene to the selected wind
ow previously opened with
OpenGraphicsWindow function.

OpenGraphicsWindow

Open an OpenGL graphics window.

PointsCloudToTrianglesSurf

Generate triangles mesh based on 3D points cloud
.

StartTexture

Get user defined image data stream and prepare it to attach it to an
OpenGL surface.


3D vector operations

_3DvectorAmp
_d80

Amplitude of 3D vector.

Extended d
ouble precision.

_3DvectorAmp_
s
32

Amplitude of 3D vector.

Single precision.

_3DvectorAmp_
s
32_arrays

Amplitude
s

of 3D vector
s in an array
.

Single
precision.

_3DvectorAmp_
d
80_array

Amplitude
s

of 3D vector
s in an array
.

80 bits
extended double precision.

_3DvectorCross
_d64

Cross product of 2 3D vectors.

Double precision.

_3DvectorCross_d64_arrays

Cross product of 2 3D vector

arrays
.

Double
precision.

_3DvectorCross_
s
32_arrays

Cross product of 2 3D vector arrays
.

Single
precision.

_3DvectorCross_
s
32

Cross product of 2 3D vectors
.

Single precision.

_3DvectorDot
_d64

Dot product of 2 3D vectors.

Double precision.

_3DvectorDot_
d64_
array
s

Dot

product of 2 3D vector arrays
.

Double
precision.

_3DvectorDot_
s
32

Dot product of 2 3D vectors.

Single precision.

_3DvectorDot_
s
32_array
s

Dot product of 2 3D vector
arrays. Single precision.

_3DvectorNorm
_d64

Normalize 3D vector.

Double precision.

_3DvectorNorm_
s
32

Normalize 3D vector.

Single precision.

_3DvectorScale
_d64

Multiply 3D vector with a scalar.

Double precision.

_3DvectorScale_
d64_
array

Scale 3D vectors array

using fast SSE code
. Double
precision.

_3DvectorScale_
s
32

Multiply 3D vector with a scalar.

Single precision.

_3DvectorScale_
s
32_array

Scale 3D vectors array

using fast SSE code
. Single
precision.

_3DvectorSub
_
d
64

Subtract 2 3D vectors.
Double precision.

_3DvectorSub_
d64_
arrays

Subtract 2 3D vector arrays. Double precision.

_3DvectorSub_
s
32

Subtract 2 3D vec
tors.
Single precision.

_3DvectorSub_
s
32_arrays

Subtract 2 3D vector arrays. Single precision.

_3DvectorSum
_d64

Sum 2 3D vectors.

Double precision.

_3DvectorSum_
d64_
arrays

Sum 2 3D vector arrays. Double precision.

_3DvectorSum_
s
32

Sum 2 3D vectors.

Single precision.

_3DvectorSum_
s
32_array
s

Sum 2 3D vector arrays. Single precision.


Surfaces

NumericalNormal_Z_Fxy

Calculate approximated normal to a surface from
the type z=f(x,y).

NumericalNormalPa
rametricSurf

Calculate approximated normal to a surface from
the type x=fx(u,y)
,
y=fy(u,y)
,
z=fz(u,y)
.

PointsToPolySurf

Find a 2D polynomial that contains 3D points cloud.

PolySurfP
oint

Calculate 2D polynomial value at a point.


Optics

_3Dreflection

Optical Reflection in 3D.

_3Dsnel

Snel low of optics in 3D.


Sound

Activat
eMicrophone

Activate the PC microphone.

ActivateSound

Play sound signal.

ReadWavFile

Read wav file to sound signal.

SaveWavFile

Save sound signal to wa
v file.

SoundBufferSize

Calculate the number of bytes required for the sound signal.


Symbolic calculations

SymbolicExpressionDerivative

Symbolic differentiation of C
expression.

SymbolicExpressionValue

Symbolic C expression to numerical value.


Strings operations

Common_Different_Strings

Find all common strings and different st
rings in 2 input strings arrays.

SortStrings

Sort an array of strings. Ascending.


Utility

AccurTimer

Accurate timer capable of high time measuring resolution.

AlignedMemAlloc

Allocated 16 bytes aligned memory block for the usage of S.E.D.
functions.

AlignedMemFree

Free memory block allocated by AlignedMemAlloc.

BitReverse32

Reverse
32 bits order.

BitReverseByte

Reverse byte bits order.

Cartez2Drotation

2D rotation of point.

CartezToPolar

Convert 2D Cartesian coordinates to
polar coordinates.

CartezToSpherical

Convert 3D Cartesian coordinates to spherical coordinates.

CheckSSE_2_3
_4

Check for SSE, SSE2, SSE3
,
SSSE3
, SSE4.1,
SSE4.2
, cache size,
proce
ssor brand string and cache line size.

ProcessWindowsEvents

An optional alternative for windows message processing loop boby.

PlainPointDistance

Distance between plain point
and nearest point on plain to input point, in
3D space.

PlainLineIntersection

Calculation of plain and line intersection in 3D space.

Rotate3DpointAroundAxis

Rotate
3D point around an axis.


General usage instructions of the S.E.D. functions.


The S.E.D. is delivered in a protected package using “Protect It
!” licensing and protection tool
.

Detailed
user manual of “Protect It!” is in the link

genesim.fatehost.net/protect_it_manual.doc
.

Briefly, t
he use of the S.E.D. protected functions is easy and done as follows:


1.

Unzip the file “
sed_1_0.zip
” you have downloaded from


genesim.fatehost.net
/sed_1_0.zip

2.

Run “setup.exe”, read the agreement, fill in first and last words as explained, and click on “I
agree” if you wish to proceed with the agreement terms.

3.

Add
the lib file “protect_it_sciLibDLL.lib”
from

the S.E.D. package
to your resource files as
shown below.



4.

Include the header file
s

“protect_it_sciLibDLL.h”
and “sciLibDLL7.h”
in your code.

Both headers
are included in the S.E.D. package.

The header
file
“sciLibDLL7.h”

contains the constants and
func
tion pointers definitions required by the S.E.D. functions.

5.

Define pointers to the functions you wish to use.
All the functions types are already defined in the
header “sciLibDLL7.h” with ‘_’ (underscore) and the function name.
For example, for the
functio
n

YL_fft,

the pointer definition is

_
YL_fft

YL_fft
;

6.

Once
the
pointer is defined you need to use
the function
YL_GetFunctionAddress

as follows:

YL_fft
=(
_YL_fft
)YL_GetFunctionAddress(“
YL_fft
”,&err);

Now the function
Y
L_fft

is ready to
use.
The example below

demonstrates

the

usage of the function YL_fft along with
AlignedMemAlloc

and
AlignedMemFr
ee

functions which allocates the aligne
d memory blocks
YL_fft requires and free them when prog
ram ends.


#include <windows.h>

#include <math.h>

#include "sciLibDLL7.h"

#include "protect_it_sciLibDLL.h"


int APIENTRY WinMain(HINSTANCE hInstance,





HINSTANCE hPrevInstance,



LPSTR lpCmdLine,



int nCmdShow)

{

int err;

_YL_fft YL_fft;

_AlignedMemAlloc AlignedMemAlloc;

_AlignedMemFree AlignedMemFree;


YL_fft=(_YL_fft)YL_GetFunctionAddress("YL_fft",&err);

AlignedMemAlloc=(_AlignedMemAlloc)
YL_GetFunctionAddress("AlignedMemAlloc",&err);

AlignedMemFree=(_AlignedMemFree)YL_GetFunctionAddress("AlignedMemFree",&err);


P
COMPLEX x,f;

unsigned long n,N=1024;


// Allocate required aligned memory blocks:

unsigned elementSize=sizeof(COMPLEX);

x=(
P
COMPL
EX)AlignedMemAlloc(N*elementSize);

f=(
P
COMPLEX)AlignedMemAlloc(N*elementSize);


// Generate the signal:

for (n=0; n<N; ++n)

{

x[n].real=cos(0.2*n);

x[n].imag=0.0;

}


// Performing the FFT:

YL_fft
(x,f,N);


// Free the previously
allocated aligned memory blocks:

AlignedMemFree(x);

AlignedMemFree(f);


return 0;

}

Special data
structures


Some of the S.E.D. functions uses SSE (Streaming SIMD Extensions) assembly instructions
that required
16 bytes memory alignment
and therefore req
u
ired data to be 16 bytes memory aligned. S.E.D. provides the
functionality to easily achieve this alignment using ALIGN_16 for variables and the AlignedMemAlloc for
pointers memory allocation.


In order to fulfill this 16 bytes alignment when working with
3D points arrays, the data structures of a 3D
point, both single and doubl
e precision, is padded to be 16 bytes multiply in size.


typedef struct

{


double x;


double y;


double z;


double w;

// Padding to 32 bytes. Not used.

} DOUBLE_3D,*PDOUBLE_3D;


typedef struct

{


float x;


float y;


float z;


float w;
// Padding to
16

bytes. Not used.

} FLOAT_3D,PFLOAT_3D;


The last unused component w must be initialized to zero.
long

_3DcubicCurve(DOUBEL_3D *p1,

DOUBEL_3D *d1,

double u1,




DOUBEL_3D *p2,

DOUBLE_3D *d2,

double u2,


double *fxCoef,

double *fyCoef, double *fzCoef);


Purpose

Calculate coefficients of 3D cubic spline curve based on 2 3D points and the curve tangent in each point.


Each fun
ction f is a cubic polynomial:



Parameters

Input

Name

Type

Range

Notes

p1

DOUBLE_3D*


A point on the 3D spline curve.

d1

DOUBLE_3D*


The tngent to the 3D spline curve at point p1.

u1

d
ouble


Value of u at p1.

p2

DOUBLE_3D*


A po
int on the 3D spline curve.

d2

DOUBEL_3D*


The tngent to the 3D spline curve at point p2.

u2

d
ouble




Outout

Name

Type

Range

Notes

fxCoef

double*


Array of 4 elements containing 4 coefficients of fx
polynomial.

fyCoef

double*


Array of 4 elements con
taining 4 coefficients of fy
polynomial.

fzCoef

double*


Array of 4 elements containing 4 coefficients of fz
polynomial.



Returned value


The value return by this function is OK in case of success. Else there was an error as detailed in the header file
sciLibDLL7.h


Remarks

Make sure you use different p1 and p2 points as well as different u1 and u2.


Usage example


The example below draw 4 different 3D cubic spline curves in 4 different OpenGL windows.


#include <windows.h>

#include <GL
\
gl.h>

#include "s
ciLibDLL7.h"

#include "protect_it_sciLibDLL.h"


// Spline subdivision.

#define N 100


_DrawCoordinateSystem DrawCoordinateSystem;

__3DcubicCurve _3DcubicCurve;

_OpenGraphicsWindow OpenGraphicsWindow;

_CloseGraphicsWindow CloseGraphicsWindow;

_OpenGL_Scene
OpenGL_Scene;

_ProcessWindowsEvents ProcessWindowsEvents;

_DrawCubicCurve DrawCubicCurve;


DOUBLE_3D sPoints[N];

DOUBLE_3D origin={0,0,0};

double u1=1,u2=2;


long myDrawFunc0(long param)

{


static ft=TRUE;


static double fxCoef[4],fyCoef[4],fzCoef[4];




if (ft)


{


DOUBLE_3D p1={1,0,0},p2={0, 0,1};


DOUBLE_3D d1={0,0,
-
1},d2={0,0,1};




// Calculate the coefficients.


_3DcubicCurve(&p1,&d1,u1,



&p2,&d2,u2,




fxCoef,fyCoef,fzCoef);



ft=FALSE;


}




// Draw the cubic spline curve.


DrawCubicCurve(fxCoef,fyCoef,fzCoef,u1,u2,N,sPoints);



// Draw the coordinate system.


DrawCoordinateSystem(&origin,0,0,0,1);


return 0;

}



long myDrawFunc1(long param)

{


static ft=TRUE;


stati
c double fxCoef[4],fyCoef[4],fzCoef[4];



if (ft)


{


DOUBLE_3D p1={ 1, 0, 0}, p2={0,0,0};


DOUBLE_3D d1={
-
1,
-
1,
-
1},d2={1,1,1};




// Calculate the coefficients.


_3DcubicCurve(&p1,&d1,u1,



&p2,&d2,u2,





fxCoef,fyCoef,fzCoef);


ft=FALSE;


}




// Draw the cubic spline curve.


DrawCubicCurve(fxCoef,fyCoef,fzCoef,u1,u2,N,sPoints);



// Draw the coordinate system.


DrawCoordinateSystem(&origin,0,0,0,1);


return 0;

}


long myD
rawFunc2(long param)

{


static ft=TRUE;


static double fxCoef[4],fyCoef[4],fzCoef[4];



if (ft)


{


DOUBLE_3D p1={0,0,0},p2={ 1,1, 1};


DOUBLE_3D d1={1,1,1},d2={
-
1,3,
-
2};




// Calculate the coefficients.


_3DcubicCurve(&p1,&d1,u1,




&p2,&d2,u2,




fxCoef,fyCoef,fzCoef);


ft=FALSE;


}





// Draw the cubic spline curve.


DrawCubicCurve
(fxCoef,fyCoef,fzCoef,u1,u2,N,sPoints);



// Draw the coo
rdinate system.


DrawCoordinateSystem
(&origin,0,0,0,1);


return 0;

}


long myDrawFunc3(long param)

{


static ft=TRUE;


static double fxCoef[4],fyCoef[4],fzCoef[4];



if (ft)


{


DOUBLE_3D p1={.1,.1,.1},p2=
{1,.5,1};


DOUBLE_3D d1={0,1,
-
1},d2={0,
-
1,0};




// Calculate the coefficients.


_3DcubicCurve(&p1,&d1,u1,


&p2,&d2,u2,


fxCoef,fyCoef,fzCoef);


ft=FALSE;


}





// Draw the cubi
c spline curve.


DrawCubicCurve(fxCoef,fyCoef,fzCoef,u1,u2,N,sPoints);



// Draw the coordinate system.


DrawCoordinateSystem(&origin,0,0,0,1);


return 0;

}



int APIENTRY WinMain(HINSTANCE hInstance,




HINSTANCE hPrevInstance,



LPSTR lpCmdLine,


int nCmdShow)

{


int err;




_3DcubicCurve=(__3DcubicCurve)YL_GetFunctionAddress("_3DcubicCurve",&err);


DrawCoordinateSystem=(_DrawCoordinateSystem)YL_GetFunctionAddress("DrawCoordinateSystem",&err
);


OpenGraphicsWindow=(_OpenGraphicsWindow)YL_GetFunctionAddress("OpenGraphicsWindow",&err);


OpenGL_Scene=(_OpenGL_Scene)YL_GetFunctionAddress("OpenGL_Scene",&err);


DrawCubicCurve=(_DrawCubicCurve)YL_GetFunctionAddress("DrawCubicCurve",&err);


Proce
ssWindowsEvents=(_ProcessWindowsEvents)YL_GetFunctionAddress("ProcessWindowsEvents",&err);


CloseGraphicsWindow=(_CloseGraphicsWindow)YL_GetFunctionAddress("CloseGraphicsWindow",&err);




// Open 4 graphics windows.


HWND hWnd;


MSG msg;


OpenGraphicsWindow
(1,1,400,400,&hWnd,0,myDrawFunc0);


OpenGraphicsWindow(401,1,400,400,&hWnd,1,myDrawFunc1);


OpenGraphicsWindow(1,401,400,400,&hWnd,2,myDrawFunc2);


OpenGraphicsWindow(401,401,400,400,&hWnd,3,myDrawFunc3);




do


{


ProcessWindowsEvents
(&msg,GET_MSG);


} while (msg.message!=WM_KEYDOWN);




// Close the windows:


CloseGraphicsWindow
(0);


CloseGraphicsWindow(1);


CloseGra
phicsWindow(2);


CloseGraphicsWindow(3);



return 0;

}


Usage example output:



long _3Dreflection(DOUBLE_3D *s,



DOUBLE_3D *rIn,




DOUBLE_3D *rOut);


Purpose

Calculate 3D ray reflection

based on incident ray and surface normal.


Parameters

Input

Name

Type

Range

Notes

s

DOUBLE_3D*

Non zero
vector.

Normal to surface vector.

rIn

DOUBLE_3D*


Incident ray vector.


Outout

Name

Type

Range

Notes

rOut

DOUBLE_3D*


Reflected ray.


Returned val
ue


The value return by this function is OK in case of success. Else there was an error as detailed in the header
file sciLibDLL7.h.


long _3Dsnel(DOUBLE_3D *s, DOUBLE_3D *rIn, DOUBLE_3D *rOut, double nIn, double nOut);


Purpose

3D implementation of Snel

low.


Parameters

Input

Name

Type

Range

Notes

s

DOUBLE_3D*

Non zero
vector.

Normal to surface vector.

rIn

DOUBLE_3D*


Incident ray vector.

nIn

double

Positive

Refraction index for incident ray.

nOut

double

Positive

Refraction index for outgoing ray.


Outout

Name

Type

Range

Notes

rOut

DOUBLE_3D*


Refracted

ray.

Calculated according to Snel low:



Returned value

The value return by this function is OK in case of success. Else there was an error as detailed in the header
file sciL
ibDLL7.h.

double

_3DvectorAmp
_d80
(DOUBLE_3D *in);

float _3DvectorAmp_s32(FLOAT_3D *in);



Purpose

Calculate the amplitude of 3D vec
tor using extended double precision.


Parameters

Input

Name

Type

Range

Notes

in

DOUBLE_3D*

or

FLOAT_3D*


3D input vector.

M
ust be allocated and assigned prior
calling this function. For the single precision function
alignment

is also required.


Returned value

The input vector amplitude.


Remark

_3DvectorAmp_d80

is using 80 extended double
precision.

_3DvectorAmp_
s32 is using fast SSE code.


void _3DvectorAmp_d80_array(PDOUBLE_3D in, double *out,

unsigned long N)
;

void
_
3DvectorAmp_s32_arrays(PFLOAT_3D in,

float *out,

unsigned long N)


Purpose

Calculate amplitudes or 3D vector arrays using f
ast code.


Parameters

Input

Name

Type

Range

Notes

in

DOUBLE_3D*

or

FLOAT_3D*


Pointer to an array of 3D vectors. Must be allocated and
assigned prior calling this function. For the single
precision function
alignment

i
s also required.

N

unsigned long

1 and up.

Number of 3D vectors in the input array.


Outout

Name

Type

Range

Notes

out

double*


Pointer to N elements array containing the amplitudes of
the input vectors array.


Returned value

Th
ese

function
s

does not re
turn value.


Remark

1.
_3DvectorAmp_d80
_array is using 80 extended double precision.

2.
_3DvectorAmp_
s32_array is using fast SSE code.

void _3DvectorCross_d64(DOUBLE_3D *in1,DOUBLE_3D *in2,DOUBLE_3D *out)
;

void _3DvectorCross_s32(PFLOAT_3D in1,PFLOAT_3D i
n2,PFLOAT_3D out)
;


Purpose

3D cross product using fast optimized SSE code.


Parameters

Input

Name

Type

Range

Notes

in1
, in2

DOUBLE_3D*

or FLOAT_3D*


Pointer to
3D input vector.

Must be properly
aligned

and
assigned pr
ior calling this function.


Outout

Name

Type

Range

Notes

out

DOUBLE_3D*

or FLOAT_3D*


Pointer to c
ross product of the 2 input vectors.

Must be
properly
aligned
.


Returned value

This function does not return value.


v
oid
F
_3DvectorCross_d64_arrays(PDOUBLE_3D in1, PDOUBLE_3D in2,



PDOUBLE_3D out,unsigned long N);


void _3DvectorCross_s32_arrays(PFLOAT_3D in1,PFLOAT_3D in2,




PFLOAT_3D out,unsigned long N);


Purpose


Calculate
cross product between the element of 2 vector array using fast optimized SSE code.



Parameters

Input

Name

Type

Range

Notes

in1
, in2

DOUBLE_3D*

or FLOAT_3D*


Point
er to
3D input vector

array
.

Must be properly
aligned

and assigned prior calling this function.


Outout

Name

Type

Range

Notes

out

DOUBLE_3D*

or FLOAT_3D*


Pointer to c
ros
s product array of the 2 input vector arrays
.

M
ust be properly
aligned
.


Returned value

This function does not return value.

double

_3DvectorDot
_d64
(
P
DOUBLE_3D in1,

P
DOUBLE_3D in2);

float _3DvectorDot_s32(PFLOAT_3D in1, PFLOAT_3D in2)
;


Purpose

3D dot product.


Pa
rameters

Input

Name

Type

Range

Notes

in1
,in2

DOUBLE_3D*

or FLOAT_3D*


Pointer to
3D input vector.


Returned value

The dot product of the 2 input vectors.



void _3DvectorDot_d64_arrays(PDOUBLE_3D in1
,
PDOUBLE_3D in2
,



unsigned long N, double *out);


void _3DvectorDot_s32_arrays(PFLOAT_3D in1
,
PFLOAT_3D in2
,


unsigned long N, float *out);


Purpose

Calculate dot product between the elements of the 2 inpu
t arrays using fast optimized SSE code.



Parameters

Input

Name

Type

Range

Notes

in1
,in2

DOUBLE_3D*

or FLOAT_3D*


Pointer to 3D input vector arrays. Must be
properly
aligned

and assigned prior ca
lling
this function.

N

unsigned long

1 and up



Outout

Name

Type

Range

Notes

out

double* or float*


Pointer to dot products array of the 2 input vector arrays
.


Returned value

This function does not return value.


double _3DvectorNorm_d64(PDOUBLE_3D i
n,PDOUBLE_3D out)
;

float _3DvectorNorm_s32(PFLOAT_3D in,PFLOAT_3D out)
;


Purpose

Calculate unit vector of the input vector.


Parameters

Input

Name

Type

Range

Notes

in

DOUBLE_3D*

or FLOAT_3D*


Pointer to
3D input vector.

Must be
aligned

and assigned
prior calling this function.


Outout

Name

Type

Range

Notes

out

DOUBLE_3D*

or FLOAT_3D



Must be
aligned
.


Returned value


The length of the input vector.


void _3
DvectorScale_d64(DOUBLE_3D *in,

DOUBLE_3D *out,

double scale)
;

void _3DvectorScale_s32(FLOAT_3D *in,FLOAT_3D *out,float scale)
;


Purpose

Multiply 3D vector by

a scalar using optimized SSE code.


Parameters

Input

Name

Type

Range

Notes

in1

DOUBLE_3D*

or FLO
AT_3D*


Pointer to
3D input vector.

Must be
aligned
.

scale

double

or float


The scaling

factor that multiplies the
components of in1.


Outout

Name

Type

Range

Notes

out

DOUBLE_3D*

or FLOAT_3D*


Pointer to the scaled v
ector. Must be
aligned
.


Returned value

This function does not return value.

void _3DvectorScale_d64_array(PDOUBLE_3
D in,

PDOUBLE_3
D out,


double *
scale,

unsign
ed long N);


void _3DvectorScale_s32_array(PFLOAT_3D in, PFLOAT_3
D out,


float *scale, unsigned long N)
;


Purpose

Sca
le an array of 3D vectors using fast optimized SSE code.



out[n]=in[n]*scale[n].


Pa
rameters

Input

Name

Type

Range

Notes

in

DOUBLE_3D*

or FLOAT_3D*


Pointer to
3D input vector
s array
.

Must be
aligned

and
assigned prior calling this function.

scale

double
*

or float
*


The scaling factor
s

array.

N

unsi
gned long

1 and up.

Number of


Outout

Name

Type

Range

Notes

out

DOUBLE_3D*

or FLOAT_3D*


Pointer to the scaled vector
s array
. Must be
aligned
.


Returned value

This function does not return value.


void _3DvectorSub
_
d64
(
P
DOUBLE_3D in1,

P
DOUBLE_3D in2,

P
DOUBLE_3D out);

void _3DvectorSum
_d64
(DOUBLE_3D *in1, DOUBLE_3D *in2,

DOUBLE_3D *out);

void _3DvectorSub_s32(PFLOAT_3D in1,PFLOAT_3D in2,PFLOAT_3D out);

void _3DvectorSum_s32(PFLOAT_3D in1,PFLOAT_3D in2,PFLOAT_3D out)
;


Purpose

Subtract
/Sum

2 3D vector using fast SSE code.


Parameters

Input

Name

Type

Range

Notes

in1
, in2

DOUBLE_3D*

or FLOAT_3D*


Pointer to
3D input vector.

Must be
aligned
.


Outout

Name

Type

Range

Notes

out

DOUBLE_3
D*

or FLOAT_3D*


Pointer to 3D vector.

Must be
aligned
.


Returned value

This function does not return value.

long _2DpointsSetToTriangleMesh(PDOUBLE_2D points,long N,PTRIANGLE_INDEXES mesh);


Pu
rpose

Generate Delaunay triangulation based on 2D points set.


Parameters

Input

Name

Type

Range

Notes

points

DOUBLE_2D*


Pointer to N 2D points array.

N

long

3 and up.

Number of points.


Outout

Name

Type

Range

Notes

mesh

TRIANGLE_
INDEXES
*


Pointer to t
riangles indexes structure.


Returned value

The value return by this function is OK in case of success. Else there was an error as detailed in the header
file sciLibDLL7.h.


long _3points_to_circle(PDOUBLE_2D p0, PDOUBLE_2D p1
,



PDOUBLE_2D p2, PCIRCLE circle);


Purpose

Calculation of circle center and
square
d

radius as defined by the 3 input points.


Parameters

Input

Name

Type

Range

Notes

p0, p1, p2

DOUBLE_2D*


Pointer to 2D point on the circle.


Outout

Name

Type

Range

Notes

out

CIRCLE*


Pointer circle data structure.

typedef struct

{


DOUBLE_2D center;


double radius2;

} CIRCLE,*PCIRCLE;

Defined in sciLibDLL7.h header file.


Returned value

The value return by this function is OK in case of success. Else the
re was an error as detailed in the header
file sciLibDLL7.h.

long _2_5_DpointsSetToTriangleMesh(PDOUBLE_3D points, long N,



PTRIANGLE_INDEXES mesh);


Purpose

Generate triangles mesh based o
n the input 3D points set.


Parameters

Input

Name

Type

Range

Notes

points

DOUBLE_3D*


Pointer to N 3D points array.

N

long

3 and up.

Number of points.


Outout

Name

Type

Range

Notes

mesh

TRIANGLE_INDEXES
*


Pointer to triangles indexes structure
s array
.


Returned value

The value return by this function is OK in case of success. Else there was an error as detailed in the header
file sciLibDLL7.h.


long _3DpointsSetToTetraederMesh(PDOUBLE_3D points,long N,



PTETRAEDER_INDEXES mesh)
;


Purpose

Generate tetrahedral mesh based on the input 3D points set using Delaunay spheres algorithm.


Parameters

Input

Name

Type

Range

Notes

points

DOUBLE_3D*


Pointer to N 3D points array.

N

long

3 and up.

Numbe
r of points.


Outout

Name

Type

Range

Notes

mesh

TETRAEDER
_INDEXES
*


Pointer to
tetraeder

indexes structure
s array
.


Returned value

The value return by this function is OK in case of success. Else there was an error as detailed in the header
file sciLibD
LL7.h.

long _3points_to_sphere(PDOUBLE_3D p0, PDOUBLE_3D p1,



PDOUBLE_3D p2, PSPHERE sphere);


Purpose

Calculate center position and squared radius of of the smallest sphere containing the 3 input points.

The
cent
er of the sphere is in the plain of the 3 points.


Parameters

Input

Name

Type

Range

Notes

p0, p1, p2

DOUBLE_3D*


Pointer to 3D point on the
sphere
.


Outout

Name

Type

Range

Notes

out

SPHERE
*


Pointer
sphere

data structure.

typedef struct

{


DOUBEL_3D c
enter;


double radius2;

} SPHERE,*PSPHERE;

Defined in sciLibDLL7.h header file.


Returned value

The value return by this function is OK in case of success. Else there was an error as detailed in the header
file sciLibDLL7.h.

long _4points_to_sphere(PDO
UBLE_3D p0,

PDOUBLE_3D p1,


PDOUBLE_3D p2,

PDOUBLE_3D p3,

PSPHERE sphere);


Purpose

Calculate the center position and squared radius of a sphere surface containing the 4 input points.


Parameters

Input

Name

Type

Ra
nge

Notes

p0, p1, p2, p3

P
DOUBLE_3D


Pointer to 3D point on the sphere.


Outout

Name

Type

Range

Notes

out

P
SPHERE


Pointer sphere data structure.

typedef struct

{


DOUBEL_3D center;


double radius2;

} SPHERE,*PSPHERE;

Defined in sciLibDLL7.h header
file.


Returned value

The value return by this function is OK in case of success. Else there was an error as detailed in the header
file sciLibDLL7.h.


void _3Daligned_bounding_box_s32(PFLOAT_3D r, long N,




PFLOAT_3D min, PFLOAT_3D max);


void _3Daligned_bounding_box_d64(PDOUBLE_3D r, long N,



PDOUBLE_3D min, PDOUBLE_3D max);


Purpose

Find axes aligned bounding of the input 3D points

cloud using fast SSE code.


Parameters

Input

Name

Type

Range

Notes

r

PDOUBLE_3D

or

PFLOAT_3D


Pointer to an
aligned

array of 3D points.

N

long

2 and up.

Number of 3D input points.


Outout

Name

Type

Range

Notes

min,

max

PDOUBLE_3D

or

PFLOAT_3D


The minimum and maximum values of the bounding box.


Returned value

This function does not return value.

void _3DvectorSub_d64_arrays(PDOUBLE_3D in1, PDOUBLE_3D in2,



PDO
UBLE_3D out, long N);


void _3DvectorS
ub
_s32_arrays(PFLOAT_3D in1,PFLOAT_3D in2,






PFLOAT_3D out,

long N);


void _3DvectorSu
m
_d64_arrays(PDOUBLE_3D in1, PDOUBLE_3D in2,



PDOUBLE_3D out,

lo
ng N);


void _3DvectorSum_s32_arrays(PFLOAT_3D in1,PFLOAT_3D in2,






PFLOAT_3D out,

long N);



Purpose

Subtract/Sum 2 3D vector arrays using fast optimized SSE code.


Parameters

Input

Name

Type

Range

Notes

in1
, in2

DOUBLE_3D*
or FLOAT_3D*


P
ointer to
3D input vector

arrays
.

Must be
aligned


Outout

Name

Type

Range

Notes

out

DOUBLE_3D*
or FLOAT_3D*


Pointer to 3D vector.

Must be
aligned


Returne
d value

This function does not return value.

long AccurTimer(double *time, double *res);


Purpose

Accurate time measurement.


Parameters


Outout

Name

Type

Range

Notes

time

double*


Number of seconds from the first call to this function in
the program.

r
es

double*


The time measurement accuracy in seconds.


Returned value

The value return by this function is OK in case of success. Else there was an error as detailed in the header
file sciLibDLL7.h.

long ActivateMicrophone(SOUND_SIGNAL *soundSignal);


Pu
rpose

Activate the PC microphone, if available.


Parameters

Input/Output
. See remarks section for more details.


Name

Type

Range

Notes

soundSignal

SOUND_SIGNAL*


Pointer to SOUND_SIGNAL data
structure, defined in
“sciLibDLL7.h” header file.


Returned val
ue

The value return by this function is OK in case of success. Else there was an error as detailed in the header
file sciLibDLL7.h.



Remarks:

Before calling this function some of the fields of the SOUND_SIGNAL data structure must be properly
filled:


nSec
ond



number of seconds to activate the microphone.

sampleFreqIndex



Sampling frequency. Allowed constants:

_8000_HZ,_11025_HZ,_12000_HZ,_16000_HZ,_22050_HZ,_24000_HZ,_32000_HZ,_44100_HZ,_48000
_HZ. These constants are defined in sciLibDLL7.h.

stereoFlag



0 for mono, 1 for stereo.

bitsPerSampleFlag



0
for

8
bit ber sample. 1
for

16 bit per sample.


The function returns once
nSecond

seconds passed. Then the data field contains a pointer to the collected
sound data and dataN is the number of samples.
long A
ctivateSound(SOUND_SIGNAL *soundSignal);


Purpose

Play sound signal
in the computer’s speakers.


Parameters

Input.

Name

Type

Range

Notes

soundSignal

SOUND_SIGNAL*


Pointer

to SOUND_SIGNAL data structure, defined in
“sciLibDLL7.h” header file.


Returned
value

The value return by this function is OK in case of success. Else there was an error as detailed in the header
file sciLibDLL7.h.


void *AlignedMemAlloc(unsigned long nBytes);


Purpose

Allocates aligned memory block according
to some of th
e

S.E.D.
fu
nctions
requirements.


Parameters


Input.

Name

Type

Range

Notes

nBytes

unsigned long

1 and up.

Number of aligned bytes to allocate.


Returned value

Address of the allocated memory block or NULL in case of failure.


Remark

In case a non
-
dynamic array or
single variable is required to be 16 bytes memory aligned, use
ALIGN_16
prior the array or variable declaration.
ALIGN_16

is defined in the header file “sciLibDLL7.h”


Examples

double *x=(double*)
AlignedMemAlloc
(sizeof(double)*13);

double
ALIGN_16

a[17];

d
ouble
ALIGN_16

b;



void AlignedMemFree(void *x)
;


Purpose

Free memory block previously allocated by
AlignedMemAlloc
Function.


Parameters


Input.

Name

Type

Range

Notes

x

void*

As previously allocated by
AlignedMemAlloc

Pointer to memory block

to be freed.


Returned value

This function does not return a value.



long Array1Dpeaks(double *x,

long xN,

PEAKS_DATA *peaks);


Purpose

Det
ect and up order sort peaks in the input
array, wit
h index exchange
.


Parameters

Input

Name

Type

Range

Notes

x

double*


The input array.

Must be properly allocated and assigned
prior t
o

calling this function.

xN

long

2 and up.

Number of elements in x.


Outout

Name

Type

Range

Notes

P
eaks

PEAKS_DATA*


Po
inter to data structure containing the peaks data.


typedef struct

{


double *peak;


long *index;


long N

} PEAKS_DATA;


Defined in “sciLibDLL7.h” header file.

p敡ks
-
㹰敡k

doub汥l


䅮 慲ray 捯n瑡tning th攠up ord敲 sor瑥t p敡ks v慬u敳f
瑨攠楮pu琠t
rray.

m敡k d敦楮楴楯n for non 敤g攠e汥men琠tW

xxn
-
Nz㱸xnz and xxnz>xxn⬱z.

m敡k d敦楮楴楯n for 敤g攠敬emen琠t㴰W

xxnz>xxn⬱z.

m敡k d敦楮楴楯n for 敤g攠敬emen琠t=xk
-


xxxk
-
Oz㱸xxk
-
Nz.

p敡ks
-
㹩>dex

汯ngG


䅮 慲ray 捯n瑡tning th攠or楧in慬a楮d數es of 瑨攠sor
瑥t
p敡k 慲r慹 in th攠楮pu琠trray x.

p敡ks
-


汯ngG


mo楮瑥t 瑯 瑨攠numb敲 of 敬em敮瑳 of
p敡ks
-
㹩nd數

慮d
p敡ks
-
㹰敡k

慲rays.


Returned value

The value return by this function is OK in case of success. Else there was an error as detailed in the header
f
ile sciLibDLL7.h.

Usage example:


#include <windows.h>

#include <stdio.h>

#include "sciLibDLL7.h"

#include "protect_it_sciLibDLL.h"


int APIENTRY WinMain(HINSTANCE hInstance,




HINSTANCE hPrevInstance,



LPSTR lpCmdLine,


int nCmdShow)

{


int err;


_Array1Dpeaks Array1Dpeaks;


Array1Dpeaks=(_Array1Dpeaks)YL_GetFunctionAddress("Array1Dpeaks",&err);



double *x;


long n,N=10;


PEAKS_D
ATA peaks;



x=(double*)malloc(8*N);


for (n=0; n<N; ++n) x[n] = n%2
-

0.1*n;



Array1Dpeaks(x,N,&peaks);



// Print results to text file:



FILE *p;


p=fopen("c:
\
\
Array1Dpeaks_res.txt","w");



fprintf(p,"Input array:
\
n");


for (n=0; n<N; ++n)


{


fprintf(p,"%0.1lf ",x[n]);


}



fprintf(p,"
\
n
\
n%d peaks found. The sorted peaks:
\
n", peaks.N);


for (n=0; n<peaks.N; ++n)


{


fprintf(p,"%0.1lf at index %d
\
n",peaks.peak[n],peaks.index[n]);


}



fclose(p);


free(x);




return 0;

}


Output
:


Input array:

0.0 0.9
-
0.2 0.7
-
0.4 0.5
-
0.6 0.3
-
0.8 0.1


5 peaks found. The sorted peaks:

0.1 at index 9

0.3 at index 7

0.5 at index 5

0.7 at index 3

0.9 at index 1

long

ArrayMinMax_d64(double *x,

long N,

double *min,

double *max);


Purpose

Find mini
mum and maximum values of the input array using optimized SSE code.


Parameters

Input

Name

Type

Range

Notes

x

double*


Pointer to the input array. Must be
aligned

and assigned prior
calling this function.

N

long

2 and

up.

Number of elements of x.


Outout

Name

Type

Range

Notes

*
min

double


The minimum value of x array when the function returns.

*max

double


The maximum value of x array when the function returns.


Returned value

The value return by this function is O
K in case of success. Else there was an error as detailed in the header
file sciLibDLL7.h.


long ArrayUniqueElements_long(long *x, long *N);


Purpose

Find all uni
que elements of the input array using O(N) time complexity algorithm.


Parameters

Input

Name

Type

Range

Notes

x

long*


Pointer to the input array. Must be properly allocated and assigned
prior calling this function.

N

long*

*N > 1

Pointer to the number of elements of x.


Outout

Name

Type

Range

Notes

x

long*


Pointer to an array containing the
unique elements of x
input.

N

long*


Pointer to the number of unique elements
of x input.


Returned value

The value return by this function is OK in case of success. Else there was an error as detailed in the header
file sciLibDLL7.h.


Remark
s

1.

The
functi
on runs

over the input array and its size pointer with the outputs. Make sure to back up
the original inputs if required.

2.

This uses memory which is kept between consequtive calls. This memory is freed when your
program ends. In case you wish to free this m
emory call this function with *N = 0. However, if
you call this function often it is highly recommended not to free this memory during program. It
will signifinatly slow down performance.

Exmaple

long M=10,a[]={3,1,7,6,3,2,7,2,3,1};

ArrayUniqueElements_lon
g(a,&M);


Example results

M=5.

a=3,1,7,6,2

long AttachPicture(char *fileName,

unsigned
long

*id,

long wndIndex);


Purpose

Prepare image from file to attach

to OpenGL
objects
.


Parameters

Input

Name

Type

Range

Notes

fileName

char*


Name of the image fil
e to attached. Currently, only
bmp format is supported.

JPG and PNG format
will added in the near future.

wndIndex

long

[0,MAX_WINDOW_NUM]

an
d

according to OpenGL
windows previously opened
using OpenGraphicsWindow
function.

OpenGL window number for it the

image is
prepared.


Outout

Name

Type

Range

Notes

id

unsigned

long
*


An identifier of the new texture. This number
is
used to
attach the image to OpenGL objects in OpenGL window
number wndIndex.


Returned value

The value return by this function is OK i
n case of success. Else there was an error as detailed in the header
file sciLibDLL7.h.

Usage example

The example below takes picture below and present it on a torus surface.

c:
\
textureImage.bmp
:



#include <windows.h>

#include <GL
\
\
gl.h>

#include "sciLi
bDLL7.h"

#include "protect_it_sciLibDLL.h"


_OpenGraphicsWindow OpenGraphicsWindow;

_AttachPicture AttachPicture;

_gluTorus gluTorus;

_ProcessWindowsEvents ProcessWindowsEvents;

_CloseGraphicsWindow CloseGraphicsWindow;

unsigned texID;


long my_opengl_func
tion(long data)

{


gluTorus(1.0,0.5,20,10,GL_SMOOTH,TRUE,texID);


return 0;

}


int APIENTRY WinMain(HINSTANCE hInstance,


HINSTANCE hPrevInstance,


LPSTR lpCmdLine,



int nCmdShow)

{


int err;


long window_index=0;


OpenGraphicsWindow=(_OpenGraphicsWindow)YL_GetFunctionAddress("OpenGraphicsWindow",&err);


AttachPicture=(_AttachPicture)YL_GetFunctionAddress("AttachPic
ture",&err);


gluTorus=(_gluTorus)YL_GetFunctionAddress("gluTorus",&err);


ProcessWindowsEvents=(_ProcessWindowsEvents)YL_GetFunctionAddress("ProcessWindowsEvents",&err);


CloseGraphicsWindow=(_CloseGraphicsWindow)YL_GetFunctionAddress("CloseGraph
icsWindow",&err);




// Open an OpenGL window:


HWND hWnd;


OpenGraphicsWindow(100,200,500,500,&hWnd,window_index,my_opengl_function);



// Prepare the image to attach:


AttachPicture("c:
\
\
textureImage.bmp",&texID,window_index);





MSG msg;


while (1)


{


ProcessWindowsEvents(&msg,GET_MSG);


if (msg.message==WM_KEYDOWN

&& LOWORD(msg.wParam)=='Q'
) break;


}



CloseGraphicsWindow(0);



return 0;

}


Output


long Average1Darray(double *x,

long N,

double

*average);


Purpose

Calculate
arithmetic
average of the input array using SSE2 code.



Parameters

Input

Name

Type

Range

Notes

x

double*


The input array. Must be properly allocated using
AlignedM
emAlloc

and assigned prior calling this
function.

N

long

1 and up.

Number of elements of x input array.


Outout

Name

Type

Notes

average

double*

The arithmetic average of x.



Returned value

The value return by this function is O
K in case of success. Else there was an error as detailed i
n the header
file sciLibDLL7.h.


long BlendArrays_s32(float *in1,float *in2, float *outAr, long N);

long BlendArrays_d64(double *in1,double *in2, double *outAr, long N);


Purpose

Blend
2 arrays int
o one array. Even elements are in1 and odd elements are in2.


Parameters

Input

Name

Type

Range

Notes

in1, in2

float* or double*


Pointer to input array. Must be
allocated

to N elements and
assigned prior calling this f
unction.


Outout

Name

Type

Range

Notes

outAr

float* or double*


Pointer to output array. Must be
allocated

to 2*N elements.

outAr[2n]=in1[n].

outAr[2n+1]=in2[n].


Returned value

The value return by this function is O
K in case of success. Else there was an error as detailed in the header
file sciLibDLL7.h.

long BestFitCircle(DOUBLE_3D *cloud, DOUBLE_3D *nearest,


long nCloud, DOUBLE_3D *center,



DOUBLE_3
D *normal, double *radius);


Purpose

Find the best fit circle to a cloud of points in 3D space.

Best fit


the sum of squared distances from the circle to the points is minimized.


Parameters

Input

Name

Type

Range

Notes

cloud

DOUBLE_3D*


An array of 3D po
ints cloud.

Must be properly
allocated and assigned prior calling this function.

nCloud

long

1 and up.

Number of points in the points cloud
.


Outout

Name

Type

Range

Notes

nearest

DOUBLE_3D
*


Array of the nearest points on the circle

to the cloud
point.
Every cloud point has a nearest point on the circle.

center

DOUBLE_3D*


The center point of the circle.

normal

DOUBLE_3D*


Normal to the circle plain.

radius

double*


Radius of the circle.


Returned value

The value return by this function is OK in case

of success. Else there was an error as detailed in the header
file sciLibDLL7.h.


Example code


#include <windows.h>

#include <GL
\
\
gl.h>

#include <stdio.h>

#include <math.h>

#include "sciLibDLL7.h"

#include "protect_it_sciLibDLL.h"


_OpenGraphicsWindow Op
enGraphicsWindow;

_ProcessWindowsEvents ProcessWindowsEvents;

_CloseGraphicsWindow CloseGraphicsWindow;

_gluElipCurve gluElipCurve;

_DrawCoordinateSystemExtended DrawCoordinateSystemExtended;

_AlignedMemAlloc AlignedMemAlloc;

_BestFitCircle BestFitCircle;

_RandomDouble RandomDouble;

_AssignEqualSpacingArray AssignEqualSpacingArray;

_glVectorRotationFromZaxis glVectorRotationFromZaxis;

_gluElipsoid gluElipsoid;

_gluArrow gluArrow;


DOUBLE_3D *points_cloud,*nearest_points;

DOUBLE_3D circleCenter,circleNormal;

double circleRadius;

long window_index=0;

long N_points=100;


int SetFunctionPointers()

{


int err;



OpenGraphicsWindow=(_OpenGraphicsWindow)YL_GetFunctionAddress("OpenGraphicsWindow",&err);


if (err) return err;


ProcessWindowsEvents=(_ProcessWindow
sEvents)YL_GetFunctionAddress("ProcessWindowsEvents",&err);


if (err) return err;


CloseGraphicsWindow=(_CloseGraphicsWindow)YL_GetFunctionAddress("CloseGraphicsWindow",&err);


if (err) return err;


gluElipCurve=(_gluElipCurve)YL_GetFunctionAddress("gl
uElipCurve",&err);


if (err) return err;


DrawCoordinateSystemExtended=(_DrawCoordinateSystemExtended)YL_GetFunctionAddress("DrawCoordinateSystemExtended",
&err);


if (err) return err;


AlignedMemAlloc=(_AlignedMemAlloc)YL_GetFunctionAddress("AlignedMem
Alloc",&err);


if (err) return err;


BestFitCircle=(_BestFitCircle)YL_GetFunctionAddress("BestFitCircle",&err);


if (err) return err;


RandomDouble=(_RandomDouble)YL_GetFunctionAddress("RandomDouble",&err);


if (err) return err;


AssignEqualSpacingAr
ray=(_AssignEqualSpacingArray)YL_GetFunctionAddress("AssignEqualSpacingArray",&err);


if (err) return err;


glVectorRotationFromZaxis=(_glVectorRotationFromZaxis)YL_GetFunctionAddress("glVectorRotationFromZaxis",&err);


if (err) return err;


gluElipsoi
d=(_gluElipsoid)YL_GetFunctionAddress("gluElipsoid",&err);


if (err) return err;


gluArrow=(_gluArrow)YL_GetFunctionAddress("gluArrow",&err);


return 0;

}


long my_opengl_function(long data)

{


DOUBLE_3D translate={
-
1.1,
-
1.1,0.0};


DOUBLE_3D axesLengt
h={2.2,2.2,1.0};


DOUBLE_3D shaftPart={0.85,0.85,0.85};


DOUBLE_3D elipDim={0.015,0.02,0.025};



double shaftRadius=0.05,headRadius=0.1;


long xGridDiv=5;


long yGridDiv=5;



long zGridDiv=5;



double xVals[6];


double yVals[6];


double zVals[6];



long n;



AssignEqualSpacingArray(
-
1.1, 1.1, xGridDiv, xVals);


AssignEqualSpacingArray(
-
1.1, 1.1, yGridDiv, yVals);


AssignEqualSpacingArray(
-
1.1, 1.1, zGridDiv, zVals);



// Draw coordinate system:


DrawCoordinateSystemExtended(0,// Window index
from OpenGraphicsWindow function




&translate, // Origin position.



&axesLength,




&shaftPart
,



shaftRadius,// For all 3 axes.




headRadius,// For all 3 axes.



"X axis","Y axis","Z axis
",




xGridDiv,yGridDiv,zGridDiv,



xVals,yVals,zVals);




// Draw the circle:


glColor3ub(255,255,255);


glPushMatrix();


glTranslated(circleCen
ter.x,circleCenter.y,circleCenter.z);


glVectorRotationFromZaxis(&circleNormal);


gluElipCurve(circleRadius,circleRadius,100,0,_2PI);


// Dtaw the normal from the circle center:


gluArrow(circleRadius/2.0,.85,circleRadius/40.0,circleRadius/20.0,10);


glPopMatrix();



// Draw the points:



for (n=0; n<N_points; ++n)


{


glColor3ub(255,130,100);


glPushMatrix();


glTranslated(points_cloud[n].x,points_cloud[n].y,points_cloud[n].z);


gluElipsoid(&elipDim,10,7);


glPopMatrix();



glCol
or3ub(28,180,230);


glPushMatrix();


glTranslated(nearest_points[n].x,nearest_points[n].y,nearest_points[n].z);


gluElipsoid(&elipDim,10,7);


glPopMatrix();


}



return 0;

}


int APIENTRY WinMain(HINSTANCE hInstance,

HINSTANCE hPrevInstance,

LPSTR lpCmdLine,

int nCmdShow)

{


long window_index=0;



// Set the points cloud within a cylinderical shell.


long n;


double angle,radius;



if (SetFunctionPointers()) return 0;




points_cloud=(DOUBLE_3D*)AlignedMemAlloc(N_points*sizeof(DOUBLE_3D
));


nearest_points=(DOUBLE_3D*)AlignedMemAlloc(N_points*sizeof(DOUBLE_3D));


for (n=0; n<N_points; ++n)


{


RandomDouble(0.0,_2PI,&angle);


RandomDouble(0.9,1.1,&radius);


RandomDouble(0.4,0.6,&points_cloud[n].z);




points_cloud[n].x=ra
dius*cos(angle);


points_cloud[n].y=radius*sin(angle);


points_cloud[n].z
-
= .3*(points_cloud[n].x+points_cloud[n].y);


}




// Find the best fit circle to the points cloud set above.


BestFitCircle(points_cloud,nearest_points,N_points,






&circleCenter,&circleNormal,&circleRadius);




// Print results to text file:


FILE *p=fopen("c:
\
\
bestCirc.txt","w");


fprintf(p,"Center:
\
nx=%lf
\
ny=%lf
\
nz=%lf
\
n",circleCenter.x,circleCenter.y,circleCenter.z);


fprintf(p,"Normal:
\
nx=%lf
\
ny=%lf
\
nz=%lf
\
n",circleNormal.x,circleNormal.y,circleNormal.z);


fprintf(p,"Radius=%lf",circleRadius);


fclose(p);



// Open an OpenGL window:


HWND hWnd;


OpenGraphicsWindow(100,200,500,500,&hWnd,window_index,my_opengl_function);



MSG msg;


while

(1)


{


ProcessWindowsEvents(&msg,GET_MSG);


if (msg.message==WM_KEYDOWN && LOWORD(msg.wParam)=='Q') break;


}



CloseGraphicsWindow(0);



return 0;

}


Output window


Best circle data:

Center:

x=
-
0.011997

y=0.008014

z=0.504485

Normal:

x=0.278719

y=0.
284435

z=0.917285

Radius=1.049431
long BestFitLine(
P
DOUBLE_3D cloud,

long nCloud,


P
DOUBLE_3D p,

P
DOUBLE_3D d);


Purpose

Find the best fit
line

to a cloud of points in 3D space.

Best fit


the sum of squared distances from the
line

to the points is minimized.


Parameters

Input

Name

Type

Range

Notes

cloud

P
DOUBLE_3D


An array of 3D points cloud.

Must be properly
allocated and assigned prior calling this
function.

nCloud

long

1 and up.

Number of points in the points cloud.


Out
out

Name

Type

Range

Notes

p

P
DOUBLE_3D


Point on the best fit line.

d

P
DOUBLE_3D


Direction vector of the best fit line.


Returned value

The value return by this function is OK in case of success. Else there was an error as detailed in the header
file s
ciLibDLL7.h.

long BestFitPlain(DOUBLE_3D *plainPoint,

DOUBLE_3D *plainNormal,



DOUBLE_3D *cloud,

long nCloud);


Purpose

Find the best fit
plain

to a cloud of points in 3D space.

Best fit


the sum of squared distances from th
e
plain

to the points is minimized.


Parameters

Input

Name

Type

Range

Notes

cloud

DOUBLE_3D*


An array of 3D points cloud.

Must be properly
allocated and assigned prior calling this
function.

nCloud

long

1 and up.

Number of points in the points cloud.


Outout

Name

Type

Range

Notes

plainPoint

DOUBLE_3D*


Point on the best fit
plain
.

plainNormal

DOUBLE_3D*


Normal vector to the plain.


Returned value

The value return by this function is OK in case of success. Else there was an error as detailed in the h
eader
file sciLibDLL7.h.


void BitReverse32(unsigned long *x);


Purpose

Reverse bit order of the input.




Parameters

Input
/output.

Name

Type

Range

Notes

x

unsigned long*

[0,0xffffffff] for
the pointed value.

Input for bit reversal.


Returned value

This
function does not return a value.

void BitReverseByte(unsigned
long
*x);


Purpose

Reverse bit order of the input least significant byte.


Parameters

Input
/output.

Name

Type

Range

Notes

x

unsigned
long
*

[0,0xff] for the
pointed value.

Input for bit revers
al.


Returned value

This function does not return a value.


Remark

Only the least significant byte is referenced
. The other bytes o
f the
input are

ignored.


long Calc_Gray_histogram(unsigned char **pixel,

long width,



long height,

long
*grayHis);


Purpose

Calculate histogram of gray level image.


Parameters

Input

Name

Type

Range

Notes

pixel

unsigned char**


2D array of the gray level image. Each byte in this
array represents 1 pixel.

width

long

1 and up.

Ima
ge width in pixels.

height

long

1 and up.

Image height in pixels.


Outout

Name

Type

Range

Notes

grayHis

long
*


Histogram array. This array has 256 elements. Each
element contains the number of pixels in the image
with gray level as the element index.


Returned value

The value return by this function is OK in case of success. Else there was an error as detailed in the header
file sciLibDLL7.h.

long Calc_RGB_Gray_histogram(UB_RGB **pixel,

long width,
long height,




long

*redHis,
long

*greenHis,
long

*blueHis,



long

*grayHis);


Purpose

Calculate histograms of RGB image.