switch to git no-history version

This commit is contained in:
AndreaRigoni
2018-04-17 15:39:10 +02:00
commit b14311ce09
274 changed files with 27340 additions and 0 deletions

View File

@@ -0,0 +1,108 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "Math/Accumulator.h"
#include "testing-prototype.h"
#include <TRandom.h>
//#include <boost/accumulators/framework/accumulator_set.hpp>
//#include <boost/accumulators/statistics/count.hpp>
//#include <boost/accumulators/accumulators.hpp>
using namespace uLib;
int test_ABTrim() {
Accumulator_ABTrim<float> acc;
acc.SetABTrim(1,1);
Vector<float> v;
v << 1,5,5,5,300;
for(Vector<float>::Iterator itr=v.begin(); itr<v.end(); itr++)
acc += *itr;
std::cout << "Accumulating Trim(1,1) vector: "
<< v << " ... out = " << acc() << "\n";
return( acc() == 15.0 );
}
int test_Mean() {
Accumulator_Mean<float> mean;
TRandom rnd;
const int c = 10000000;
Vector<float> v;
v.reserve(c);
for(int i=0;i<c;++i) v.push_back( rnd.Gaus(2000,5) );
float m = 0;
for(int i=0;i<c;++i) m += v[i];
m /= c;
std::cout << "simple mean: " << m << "\n";
for(int i=0;i<c;++i) mean(v[i]);
std::cout << "mean pass: " << mean() << "\n";
mean.AddPass();
for(int i=0;i<c;++i) mean(v[i]);
std::cout << "mean pass: " << mean() << "\n";
mean.AddPass();
for(int i=0;i<c;++i) mean(v[i]);
std::cout << "mean pass: " << mean() << "\n";
mean.AddPass();
for(int i=0;i<c;++i) mean(v[i]);
std::cout << "mean pass: " << mean() << "\n";
mean.AddPass();
for(int i=0;i<c;++i) mean(v[i]);
std::cout << "mean pass: " << mean() << "\n";
mean.AddPass();
for(int i=0;i<c;++i) mean(v[i]);
std::cout << "mean pass: " << mean() << "\n";
mean.AddPass();
for(int i=0;i<c;++i) mean(v[i]);
std::cout << "mean pass: " << mean() << "\n";
}
int main(void) {
BEGIN_TESTING(Accumulator);
//TEST1( test_ABTrim() );
test_Mean();
END_TESTING;
}

View File

@@ -0,0 +1,19 @@
#include "testing-prototype.h"
#include "Math/Dense.h"
#include "Math/BitCode.h"
#include <iostream>
#include <math.h>
using namespace uLib;
int main() {
BEGIN_TESTING(BitCode Test);
BitCode<int,1,2> bc;
bc.PrintSelf();
END_TESTING;
}

View File

@@ -0,0 +1,18 @@
set(TESTS
MathVectorTest
GeometryTest
ContainerBoxTest
VoxImageTest
VoxRaytracerTest
StructuredDataTest
VoxImageFilterTest
PolicyTest
AccumulatorTest
VoxImageCopyTest
TriangleMeshTest
BitCodeTest
)
uLib_add_tests(${uLib-module})

View File

@@ -0,0 +1,94 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "testing-prototype.h"
#include "Math/Dense.h"
#include "Math/ContainerBox.h"
#include <iostream>
#include <math.h>
using namespace uLib;
int Vector4f0(Vector4f c)
{
c(3) = 0;
if ( fabs(c(0)) < 0.001 && fabs(c(1)) < 0.001 && fabs(c(2)) < 0.001 )
return 0;
else
return 1;
}
int main()
{
BEGIN_TESTING(Math ContainerBox);
ContainerBox Cnt;
// // Local transform:
Cnt.SetOrigin(Vector3f(-1,-1,-1));
Cnt.SetSize(Vector3f(2,2,2)); // scaling //
std::cout << "Container scale is: " << Cnt.GetSize().transpose() << "\n";
std::cout << "Container scale is: " << Cnt.GetSize().transpose() << "\n";
TEST0( Vector4f0(Cnt.GetSize().homogeneous() - HVector3f(2,2,2)) );
ContainerBox Box;
Box.SetPosition(Vector3f(1,1,1));
Box.SetSize(Vector3f(2,2,2));
Box.EulerYZYRotate(Vector3f(0,0,0));
HPoint3f pt = Box.GetLocalPoint(HPoint3f(2,3,2));
HPoint3f wp = Box.GetWorldPoint(pt);
TEST0( Vector4f0(wp - HPoint3f(2,3,2)) );
//// // Global
// Cnt.SetPosition(Vector3f(1,1,1));
// Cnt.EulerYZYRotate(Vector3f(M_PI_2,M_PI_2,0));
// HPoint3f p = Cnt.GetWorldPoint(1,1,1);
// //std::cout << p.transpose() << "\n";
// TEST0( Vector4f0(p - HVector3f(2,1,2)) );
// p = Cnt.GetWorldPoint(1,2,3);
// //std::cout << p.transpose() << "\n";
// TEST0( Vector4f0(p - HVector3f(4,1,3)) );
// // scaling //
END_TESTING;
}

View File

@@ -0,0 +1,98 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "testing-prototype.h"
#include "Math/Dense.h"
#include "Math/Geometry.h"
#include "Math/ContainerBox.h"
#include <iostream>
#include <math.h>
using namespace uLib;
int Vector4f0(Vector4f c)
{
c(3) = 0;
if ( fabs(c(0)) < 0.001 && fabs(c(1)) < 0.001 && fabs(c(2)) < 0.001 )
return 0;
else
return 1;
}
int main()
{
BEGIN_TESTING(Math Geometry);
//////////////////////////////////////////////////////////////////////////////
///////////////// GEOMETRY TESTING ///////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Geometry Geo;
Geo.SetPosition(Vector3f(1,1,1));
Geo.EulerYZYRotate(Vector3f(0,0,0));
HPoint3f pt = Geo.GetLocalPoint(HPoint3f(2,3,2));
HPoint3f wp = Geo.GetWorldPoint(pt);
TEST0( Vector4f0(wp - HPoint3f(2,3,2)) );
Geo.Scale(Vector3f(2,2,2));
wp = Geo.GetWorldPoint(HPoint3f(1,1,1));
TEST0( Vector4f0(wp - HPoint3f(3,3,3)) );
Geo.Scale(Vector3f( .5 , .5 , .5 ));
Geo.EulerYZYRotate(Vector3f(M_PI_2,0,0));
wp = Geo.GetWorldPoint(HPoint3f(1,1,1));
TEST0( Vector4f0(wp - HPoint3f(2,2,0)) );
Geo.EulerYZYRotate(Vector3f(0,M_PI_2,0));
wp = Geo.GetWorldPoint(HPoint3f(1,1,1));
TEST0( Vector4f0(wp - HPoint3f(2,2,2)) );
Geo.EulerYZYRotate(Vector3f(0,0,M_PI_2));
wp = Geo.GetWorldPoint(HPoint3f(1,1,1));
// std::cout << "Geometry matrix\n" << Geo.GetTransform() << "\n";
// std::cout << "World 1,1,1 coords\n" << wp << "\n";
TEST0( Vector4f0(wp - HPoint3f(0,2,2)) );
// TESTING FLIP AXES //
Geo.SetPosition(Vector3f(0,0,0));
Geo.EulerYZYRotate(Vector3f(-M_PI_2,-M_PI_2,-M_PI_2)); // reset previous
Geo.EulerYZYRotate(Vector3f(M_PI_2,0,0)); // PI_2 along X
Geo.FlipAxes(0,2); // flip X-Z
HPoint3f p = Geo.GetWorldPoint(Vector3f(1,0,0).homogeneous());
TEST0( Vector4f0(p - HVector3f(1,0,0)) ); // after flip and rotation X->X
END_TESTING;
}

View File

@@ -0,0 +1,28 @@
include $(top_srcdir)/Common.am
#AM_DEFAULT_SOURCE_EXT = .cpp
# if HAVE_CHECK
TESTS = MathVectorTest \
GeometryTest \
ContainerBoxTest \
VoxImageTest \
VoxRaytracerTest \
StructuredDataTest \
VoxImageFilterTest \
PolicyTest \
AccumulatorTest \
VoxImageCopyTest \
TriangleMeshTest
# else
# TEST =
# endif
LDADD = $(top_srcdir)/libmutom-${PACKAGE_VERSION}.la $(AM_LIBS_ALL)
all: ${TESTS}
check_PROGRAMS = $(TESTS)

View File

@@ -0,0 +1,129 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "testing-prototype.h"
#include "Math/Dense.h"
#include "Math/Geometry.h"
#include "Core/Archives.h"
#include <iostream>
#include <math.h>
using namespace uLib;
int Vector4f0(Vector4f c)
{
c(3) = 0;
if ( fabs(c(0)) < 0.001 && fabs(c(1)) < 0.001 && fabs(c(2)) < 0.001 )
return 0;
else
return 1;
}
int main()
{
BEGIN_TESTING(uLib Math);
//////////////////////////////////////////////////////////////////////////////
///////////////// VECTOR TESTING /////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
std::cout << "Testing Vectors\n";
{ // SIMPLE VECTOR TEST //
HPoint3f p1(1,1,1); // point with const float ctr
HVector3f v1; v1 << 1,1,1,1; // vector with void ctr and comma assignment
TEST0( Vector4f0(p1 - v1));
}
{ // ROW COLUMN ACCESSOR ORDER TEST //
Matrix2i test;
test << 1,2,3,4;
std::cout << "print row column test ";
std::cout << test(0,0) << " " <<
test(0,1) << " " <<
test(1,0) << " " <<
test(1,1) << " " << "\n";
TEST1( test(0,1) == 2 && test(1,0) == 3 );
}
{
Vector3i test(0,0,0);
++test(1);
std::cout << "increment of single dim inside vector: " << test.transpose() << "\n";
TEST1( test == Vector3i(0,1,0) );
}
{
Matrix4f mat;
mat << 1,0,0,0,
0,1,0,0,
0,0,1,0,
0,0,0,1;
std::cout << "determinant" << mat.determinant() << "\n";
}
{
Matrix1f f;
f << 5;
f.trace();
}
{
Vector3f v(1,2,3);
std::string str("2 3 5");
std::istringstream istr(str);
uLib::Archive::hrt_iarchive hi(istr);
hi >> v;
uLib::Archive::hrt_oarchive ho(std::cout);
ho << v;
}
{
Vector3f v;
std::string str("2 3 5");
str >> v;
std::cout << v.transpose() << "\n";
}
END_TESTING;
}

View File

@@ -0,0 +1,78 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include "testing-prototype.h"
// Curiously Recurring Template Pattern //
template < typename V, typename T >
class Base {
public:
Base(int a) : value(a) {
Algorithm = static_cast<T*>(this);
}
void Print()
{
std::cout << Algorithm->Value() << "\n";
}
int value;
V voxel;
T* Algorithm;
};
template < typename V >
class Derived : public Base< V ,Derived<V> > {
typedef Base< V ,Derived<V> > BaseClass;
public:
Derived(int a) : BaseClass(a) {}
int Value() { return this->value+1; }
};
int main()
{
BEGIN_TESTING(Policy);
Derived<int> my(5);
my.Print();
Base<int, Derived<int> > my2(5);
my2.Print();
END_TESTING;
}

View File

@@ -0,0 +1,93 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "testing-prototype.h"
#include "Math/Dense.h"
#include "Math/ContainerBox.h"
#include "Math/StructuredData.h"
#include <iostream>
using namespace uLib;
int main() {
BEGIN_TESTING(Structured Data);
{ // testing unmap function ////////////////////////////////////////////////
StructuredData sdata(Vector3i(2,3,4));
for(int i=0; i < sdata.GetDims().prod() ; ++i) {
Vector3i d = sdata.UnMap(i);
std::cout << "TEST1( sdata.UnMap(" << i << ") == Vector3i("
<< d(0) << "," << d(1) << "," << d(2) << ")); \n";
}
TEST1( sdata.UnMap(0) == Vector3i(0,0,0));
TEST1( sdata.UnMap(1) == Vector3i(0,1,0));
TEST1( sdata.UnMap(2) == Vector3i(0,2,0));
TEST1( sdata.UnMap(3) == Vector3i(1,0,0));
TEST1( sdata.UnMap(4) == Vector3i(1,1,0));
TEST1( sdata.UnMap(5) == Vector3i(1,2,0));
TEST1( sdata.UnMap(6) == Vector3i(0,0,1));
TEST1( sdata.UnMap(7) == Vector3i(0,1,1));
TEST1( sdata.UnMap(8) == Vector3i(0,2,1));
TEST1( sdata.UnMap(9) == Vector3i(1,0,1));
TEST1( sdata.UnMap(10) == Vector3i(1,1,1));
TEST1( sdata.UnMap(11) == Vector3i(1,2,1));
TEST1( sdata.UnMap(12) == Vector3i(0,0,2));
TEST1( sdata.UnMap(13) == Vector3i(0,1,2));
TEST1( sdata.UnMap(14) == Vector3i(0,2,2));
TEST1( sdata.UnMap(15) == Vector3i(1,0,2));
TEST1( sdata.UnMap(16) == Vector3i(1,1,2));
TEST1( sdata.UnMap(17) == Vector3i(1,2,2));
TEST1( sdata.UnMap(18) == Vector3i(0,0,3));
TEST1( sdata.UnMap(19) == Vector3i(0,1,3));
TEST1( sdata.UnMap(20) == Vector3i(0,2,3));
TEST1( sdata.UnMap(21) == Vector3i(1,0,3));
TEST1( sdata.UnMap(22) == Vector3i(1,1,3));
TEST1( sdata.UnMap(23) == Vector3i(1,2,3));
// testing map /////////////////////////////////////////////////////////
int i=0;
// PREDEFINED ORDER IS YXZ //
for(int z=0; z<sdata.GetDims()(2) ; ++z )
for(int x=0; x<sdata.GetDims()(0) ; ++x )
for(int y=0; y<sdata.GetDims()(1) ; ++y )
{
Vector3i index(x,y,z);
std::cout << sdata.Map(index) << " ";
TEST1( sdata.Map(index) == i++ );
}
std::cout << "\n";
}
END_TESTING;
}

View File

@@ -0,0 +1,72 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <Math/VoxImage.h>
#include "testing-prototype.h"
using namespace uLib;
int main()
{
BEGIN_TESTING(Math Structured Grid);
VoxImage<int> int_grid(Vector3i(100,100,100));
int_grid[Vector3i(1,2,3)] = 5552368;
TEST1( int_grid.At(30102) == 5552368 );
// TESTING MAP //
VoxImage<int> test_order(Vector3i(2,2,2));
int index =0;
for(int z=0;z<2;++z)
for(int y=0;y<2;++y)
for(int x=0;x<2;x++)
{
test_order[Vector3i(x,y,z)] = index;
std::cout << x << " " << y << " " << z << " -> " <<
test_order.At(Vector3i(x,y,z)) << "\n";
index++;
}
test_order.Data().PrintSelf(std::cout);
int result[8] = {0,2,1,3,4,6,5,7};
for(int i=0;i<8;++i)
TEST1( test_order.At(i) == result[i] );
// TESTING UNMAP //
std::cout << "unmap = " << test_order.UnMap(7).transpose() << "\n";
TEST1( test_order.UnMap(7) == Vector3i(1,1,1) );
TEST1( test_order.UnMap(6) == Vector3i(1,0,1) );
TEST1( test_order.UnMap(5) == Vector3i(0,1,1) );
// ...
END_TESTING
}

View File

@@ -0,0 +1,52 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "testing-prototype.h"
#include "Math/TriangleMesh.h"
using namespace uLib;
int main()
{
BEGIN_TESTING(Triangle Mesh);
TriangleMesh mesh;
mesh.AddPoint(Vector3f(0,0,0));
mesh.AddPoint(Vector3f(0,1,0));
mesh.AddPoint(Vector3f(1,0,0));
mesh.AddTriangle(Vector3i(0,1,2));
mesh.PrintSelf(std::cout);
END_TESTING;
}

View File

@@ -0,0 +1,77 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "testing-prototype.h"
#include "Math/VoxImage.h"
using namespace uLib;
struct TestVoxel {
Scalarf Value;
unsigned int Count;
};
int main() {
BEGIN_TESTING(Math VoxImage Copy);
{
VoxImage<TestVoxel> img(Vector3i(10,10,10));
TestVoxel zero = {0,0};
img.InitVoxels(zero);
TestVoxel nonzero = {5.552368, 0};
img[Vector3i(5,1,7)] = nonzero;
img[img.Find(HPoint3f(3,3,3))].Value = 5.552369;
TEST1( img.GetValue(Vector3i(5,1,7)) == 5.552368f );
img.SetOrigin(Vector3f(4,5,6));
std::cout << "\n";
img.PrintSelf(std::cout);
VoxImage<TestVoxel> img2 = img;
img2.PrintSelf(std::cout);
TEST1( img.GetOrigin() == img2.GetOrigin() );
TEST1( img.GetSpacing() == img2.GetSpacing() );
img2 = img;
}
std::cout << "returns " << _fail << "\n";
END_TESTING;
}

View File

@@ -0,0 +1,150 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "testing-prototype.h"
#include "Math/StructuredGrid.h"
#include "Math/VoxImage.h"
#include "Math/VoxImageFilter.h"
using namespace uLib;
struct TestVoxel {
Scalarf Value;
unsigned int Count;
};
float GaussianShape(float d)
{
// normalized manually .. fix //
return 4.5 * exp(-d * 4.5);
}
class GaussianShapeClass : public Interface::VoxImageFilterShape {
public:
GaussianShapeClass(float sigma) :
m_sigma(sigma)
{}
float operator ()(float d) {
return (1/m_sigma) * exp(-d/m_sigma);
}
private:
float m_sigma;
};
static float MaxInVector(const Vector<float> &v)
{
float max = 0;
for(int i=0; i<v.size(); ++i)
if(v.at(i) > max) max = v.at(i);
return max;
}
int main()
{
BEGIN_TESTING(VoxImageFilters);
VoxImage<TestVoxel> image(Vector3i(20,30,40));
image[Vector3i(10,10,10)].Value = 1;
//image[Vector3i(10,10,8)].Value = 1;
image.ExportToVtk("test_filter_original.vtk",0);
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// RPS //
{
VoxFilterAlgorithmSPR<TestVoxel> filter(Vector3i(2,3,4));
VoxImage<TestVoxel> filtered = image;
Vector<float> values;
for(int i=0; i < filter.GetKernelData().GetDims().prod(); ++i) {
values.push_back(1.);
std::cout << values[i] << " ";
}
std::cout << "\n";
filter.SetImage(&filtered);
filter.SetKernelNumericXZY(values);
filter.SetABTrim(0,2);
filter.GetKernelData().PrintSelf(std::cout);
filter.Run();
filtered.ExportToVtk("filter_RPS_out.vtk",0);
}
{
VoxImage<TestVoxel> image(Vector3i(20,30,40));
image[Vector3i(10,10,10)].Value = 1;
image[Vector3i(9,10,8)].Value = 2;
image.ExportToVtk("test_filter_max_original.vtk",0);
VoxFilterAlgorithmCustom<TestVoxel> filter(Vector3i(3,3,4));
Vector<float> values;
for(int i=0; i < filter.GetKernelData().GetDims().prod(); ++i) {
values.push_back(static_cast<float>(1));
}
filter.SetImage(&image);
filter.SetKernelNumericXZY(values);
filter.SetCustomEvaluate(MaxInVector);
filter.Run();
image.ExportToVtk("test_filter_max.vtk",0);
}
END_TESTING;
}

View File

@@ -0,0 +1,107 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "testing-prototype.h"
#include "Math/StructuredGrid.h"
#include "Math/VoxImage.h"
using namespace uLib;
struct TestVoxel {
Scalarf Value;
unsigned int Count;
};
int main() {
BEGIN_TESTING(Math StructuredGrid);
{ // SIMPLE TESTS //
StructuredGrid img(Vector3i(10,10,10));
img.SetSpacing(Vector3f(3,3,3));
TEST1( img.GetWorldPoint(2,0,0) == HPoint3f(6,0,0) );
TEST1( img.GetWorldPoint(1,1,1) == HPoint3f(3,3,3) );
img.SetPosition(Vector3f(1,1,1));
TEST1( img.GetWorldPoint(1,1,1) == HPoint3f(4,4,4) );
TEST1( img.GetLocalPoint(4,4,4) == HPoint3f(1,1,1) );
TEST0( img.IsInsideBounds(HPoint3f(5,33,-5)));
TEST0( img.IsInsideBounds(HPoint3f(0,0,0)));
TEST1( img.IsInsideBounds(HPoint3f(1,1,1)));
}
{ // TEST WITH ORIGIN //
StructuredGrid img(Vector3i(10,10,10));
img.SetSpacing(Vector3f(3,3,3));
img.SetOrigin(Vector3f(-1,1,-1));
img.SetPosition(Vector3f(1,1,1));
TEST1( img.GetWorldPoint(1,1,1) == HPoint3f(3,5,3) );
}
{
VoxImage<TestVoxel> img(Vector3i(10,10,10));
TestVoxel zero = {0,0};
img.InitVoxels(zero);
TestVoxel nonzero = {5.552368, 0};
img[Vector3i(5,1,7)] = nonzero;
img[img.Find(HPoint3f(3,3,3))].Value = 5.552369;
img.ExportToVtk("./test_vox_image.vtk",0);
img.ExportToVtkXml("./test_vox_image.vti",0);
TEST1( img.GetValue(Vector3i(5,1,7)) == 5.552368f );
}
{
VoxImage<TestVoxel> img(Vector3i(4,4,4));
TestVoxel zero = {0,0};
img.InitVoxels(zero);
img.SetSpacing(Vector3f(2,2,2));
img.SetPosition(Vector3f(-4,-4,-4));
TEST1( img.GetWorldPoint(img.GetLocalPoint(HPoint3f(5,5,5))) == HPoint3f(5,5,5));
}
{
VoxImage<TestVoxel> imgR(Vector3i(0,0,0));
imgR.ImportFromVtk("./test_vox_image.vtk");
imgR.ExportToVtk("./read_and_saved.vtk");
}
{
VoxImage<TestVoxel> img1(Vector3i(5,5,5));
VoxImage<TestVoxel> img2;
img2 = img1;
TEST1( img1.GetDims() == img2.GetDims() );
}
END_TESTING
}

View File

@@ -0,0 +1,151 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "Math/StructuredGrid.h"
#include "Math/VoxRaytracer.h"
#include "testing-prototype.h"
using namespace uLib;
int Vector4f0(Vector4f c)
{
c(3) = 0;
if ( fabs(c(0)) < 0.001 && fabs(c(1)) < 0.001 && fabs(c(2)) < 0.001 )
return 0;
else
return 1;
}
//bool Comapare(const &t1, const T2 &t2)
//{
// int out = 0;
// out += t1.vox_id != t2.vox_id;
// out += (fabs(t1.L) - fabs(t2.L)) > 0.001;
// return out == 0;
//}
typedef VoxRaytracer Raytracer;
int main()
{
BEGIN_TESTING(Math VoxRaytracer);
StructuredGrid img(Vector3i(2,2,2));
img.SetSpacing(Vector3f(2,2,2));
img.SetPosition(Vector3f(-2,0,-2));
{
HLine3f line;
line.origin << 0.1, 4.1, 0.1, 1;
line.direction << 0.1, -0.1, 0.1,0;
Raytracer rt(img);
HPoint3f pt;
TEST1( rt.GetEntryPoint(line,pt) );
TEST0( Vector4f0( pt - HPoint3f(0.2,4,0.2) ) );
}
{
HLine3f line;
line.origin << 4,0,4, 1;
line.direction << -0.1, 0.1, -0.1, 0;
Raytracer rt(img);
HPoint3f pt;
TEST1( rt.GetEntryPoint(line,pt) );
TEST0( Vector4f0( pt - HPoint3f(2,2,2) ) );
}
{ // Test a point inside image //
StructuredGrid img(Vector3i(4,4,4));
img.SetSpacing(Vector3f(2,2,2));
img.SetPosition(Vector3f(-4,-4,-4));
Raytracer ray(img);
HPoint3f pt;
HLine3f line;
line.origin = HPoint3f(-3,-3,-3);
// line.direction = HVector3f(1,1,1); //
TEST1( ray.GetEntryPoint(line,pt) );
TEST1( pt == HPoint3f(-3,-3,-3) );
Raytracer::RayData rdata = ray.TraceBetweenPoints(HPoint3f(-3,-3,-3), HPoint3f(3,3,3));
foreach (const Raytracer::RayData::Element &el, rdata.Data())
{
std::cout << " " << el.vox_id << " , " << el.L << "\n";
}
}
{
HPoint3f pt1(1,-0.5,1);
HPoint3f pt2(1,4.5,1);
Raytracer rt(img);
Raytracer::RayData ray = rt.TraceBetweenPoints(pt1,pt2);
TEST1( ray.Data().size() == 2 );
TEST1( ray.Data().at(0).vox_id == 6 );
TEST1( ray.Data().at(1).vox_id == 7 );
ray.PrintSelf(std::cout);
}
{
HPoint3f pt1(5,1,1);
HPoint3f pt2(-3,1,1);
Raytracer rt(img);
Raytracer::RayData ray = rt.TraceBetweenPoints(pt1,pt2);
TEST1( ray.Data().size() == 2 );
TEST1( ray.Data().at(0).vox_id == 6 );
TEST1( ray.Data().at(1).vox_id == 4 );
ray.PrintSelf(std::cout);
}
{
HPoint3f pt1(1,1,1);
HPoint3f pt2(-1,3,-1);
Raytracer rt(img);
Raytracer::RayData ray = rt.TraceBetweenPoints(pt1,pt2);
TEST1( ray.Data().size() == 4 );
TEST1( ray.Data().at(0).vox_id == 6 );
TEST1( ray.Data().at(1).vox_id == 4 );
TEST1( ray.Data().at(2).vox_id == 5 );
TEST1( ray.Data().at(3).vox_id == 1 );
ray.PrintSelf(std::cout);
}
END_TESTING
}

View File

@@ -0,0 +1,37 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <stdio.h>
#define BEGIN_TESTING(name) \
static int _fail = 0; \
printf("..:: Testing " #name " ::..\n");
#define TEST1(val) _fail += (val)==0
#define TEST0(val) _fail += (val)!=0
#define END_TESTING return _fail;