New classes for new algorithm

This commit is contained in:
Paolo Andreetto
2019-12-19 13:52:32 +00:00
parent 884f5ca084
commit 3236b9e599
5 changed files with 418 additions and 0 deletions

View File

@@ -22,6 +22,8 @@ set(HEADERS
Accumulator.h
TriangleMesh.h
BitCode.h
Structured2DGrid.h
Structured4DGrid.h
)
@@ -33,6 +35,8 @@ set(SOURCES
VoxImage.cpp
TriangleMesh.cpp
Dense.cpp
Structured2DGrid.cpp
Structured4DGrid.cpp
)
set(LIBRARIES

View File

@@ -0,0 +1,130 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Sara Vanini < sara.vanini@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 "Structured2DGrid.h"
using namespace uLib;
//_____________________________________________________________
Structured2DGrid::Structured2DGrid()
{
// reset uni-dim space
m_Dims = Vector2i(0,0);
m_Origin = Vector2f(0.,0.);
m_Increments = Vector2i(0,0);
m_binW = Vector2f(1.,1.);
m_debug = true;
}
//_____________________________________________________________
void Structured2DGrid::SetDims(const Vector2i &size)
{
this->m_Dims = size;
// set increments
this->m_Increments[0] = 1;
this->m_Increments[1] = m_Dims[0];
}
//_____________________________________________________________
void Structured2DGrid::SetPhysicalSpace(const Vector2f &origin, const Vector2f &spacing)
{
m_Origin = origin;
m_binW = spacing;
m_uni2phys_T = Translation<float,2>(m_Origin) * Scaling(m_binW);
m_phys2uni_T = m_uni2phys_T.matrix().inverse();
return;
}
//_____________________________________________________________
bool Structured2DGrid::IsInsideBounds(const Vector2f &pt) const
{
Vector2i pLoc = this->PhysicsToUnitSpace(pt);
return this->IsInsideGrid(pLoc);
}
//_____________________________________________________________
Vector2i Structured2DGrid::UnMap(int index) const
{
Vector2i v( 0,0 );
Vector2i iv = m_Increments;
int id = 0;
for(int k=0; k<2; ++k) {
int inc = iv.maxCoeff(&id);
v(id) = index / inc;
index -= v(id) * inc;
iv(id) = 0;
}
return v;
}
//_____________________________________________________________
bool Structured2DGrid::IsInsideGrid(const Vector2i &v) const
{
int vok = 1;
vok *= (v(0) >= 0 && v(0) < m_Dims[0]);
vok *= (v(1) >= 0 && v(1) < m_Dims[1]);
return vok;
}
//_____________________________________________________________
Vector2i Structured2DGrid::PhysicsToUnitSpace(const Vector2f &pt) const
{
Vector2i out;
Vector2f pLoc = m_phys2uni_T * pt;
out << (int)floor(pLoc(0)),
(int)floor(pLoc(1));
return out;
}
//_____________________________________________________________
Vector2f Structured2DGrid::UnitToPhysicsSpace(const Vector2i &ind) const
{
Vector2f p;
p = m_uni2phys_T * ind.cast<float>();
return p;
}
//_____________________________________________________________
void Structured2DGrid::PrintSelf(std::ostream &o)
{
o << "uLib Structured Data 2D: \n"
<< "dim = " << this->GetDims().transpose() << "\n"
<< "spacing = " << this->GetSpacing().transpose() << "\n";
}

View File

@@ -0,0 +1,74 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Sara Vanini < sara.vanini@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.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef Structured2DGrid_H
#define Structured2DGrid_H
#include "Math/Dense.h"
#include <Eigen/Dense>
#include <Eigen/Geometry>
using namespace Eigen;
namespace uLib {
class Structured2DGrid {
public:
Structured2DGrid();
/// unit-space
void SetDims(const Vector2i &size);
inline Vector2i GetDims() {return m_Dims; }
bool IsInsideGrid(const Vector2i &v) const;
inline int Map(Vector2i index) const { return (m_Increments.transpose() * index);}
Vector2i UnMap(int index) const;
/// physics-space
void SetPhysicalSpace(const Vector2f &origin, const Vector2f &spacing);
inline Vector2f GetSpacing() const { return m_binW; }
inline Vector2f GetOrigin() const { return m_Origin; }
bool IsInsideBounds(const Vector2f &pt) const;
/// operations
Vector2i PhysicsToUnitSpace(const Vector2f &pt) const;
Vector2f UnitToPhysicsSpace(const Vector2i &ind) const;
void PrintSelf(std::ostream &o);
void SetDebug(bool debug){ m_debug = debug; };
private:
Vector2i m_Dims;
Vector2i m_Increments;
Vector2f m_binW;
Vector2f m_Origin;
bool m_debug;
Transform<float, 2, Eigen::Affine> m_uni2phys_T;
Transform<float, 2, Eigen::Affine> m_phys2uni_T;
};
}
#endif // Structured2DGrid_H

View File

@@ -0,0 +1,136 @@
/*//////////////////////////////////////////////////////////////////////////////
// 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 "Structured4DGrid.h"
using namespace uLib;
//_____________________________________________________________
Structured4DGrid::Structured4DGrid()
{
// reset uni-dim space
m_Dims = Vector4i(0,0,0,0);
m_Origin = Vector4f(0.,0.,0.,0.);
m_Increments = Vector4i(0,0,0,0);
m_binW = Vector4f(1.,1.,1.,1.);
m_debug = true;
}
//_____________________________________________________________
void Structured4DGrid::SetDims(const Vector4i &size)
{
this->m_Dims = size;
// set increments
this->m_Increments[0] = 1;
this->m_Increments[1] = m_Dims[0];
this->m_Increments[2] = m_Dims[0] * m_Dims[1];
this->m_Increments[3] = m_Dims[0] * m_Dims[1] * m_Dims[2];
}
//_____________________________________________________________
void Structured4DGrid::SetPhysicalSpace(const Vector4f &origin, const Vector4f &spacing)
{
m_Origin = origin;
m_binW = spacing;
m_uni2phys_T = Translation<float,4>(m_Origin) * Scaling(m_binW);
m_phys2uni_T = m_uni2phys_T.matrix().inverse();
return;
}
//_____________________________________________________________
bool Structured4DGrid::IsInsideBounds(const Vector4f &pt) const
{
Vector4i pLoc = this->PhysicsToUnitSpace(pt);
return this->IsInsideGrid(pLoc);
}
//_____________________________________________________________
Vector4i Structured4DGrid::UnMap(int index) const
{
Vector4i v( 0,0,0, 0 );
Vector4i iv = m_Increments;
int id = 0;
for(int k=0; k<4; ++k) {
int inc = iv.maxCoeff(&id);
v(id) = index / inc;
index -= v(id) * inc;
iv(id) = 0;
}
return v;
}
//_____________________________________________________________
bool Structured4DGrid::IsInsideGrid(const Vector4i &v) const
{
int vok = 1;
vok *= (v(0) >= 0 && v(0) < m_Dims[0]);
vok *= (v(1) >= 0 && v(1) < m_Dims[1]);
vok *= (v(2) >= 0 && v(2) < m_Dims[2]);
vok *= (v(3) >= 0 && v(3) < m_Dims[3]);
return vok;
}
//_____________________________________________________________
Vector4i Structured4DGrid::PhysicsToUnitSpace(const Vector4f &pt) const
{
Vector4i out;
Vector4f pLoc = m_phys2uni_T * pt;
out << (int)floor(pLoc(0)),
(int)floor(pLoc(1)),
(int)floor(pLoc(2)),
(int)floor(pLoc(3));
return out;
}
//_____________________________________________________________
Vector4f Structured4DGrid::UnitToPhysicsSpace(const Vector4i &ind) const
{
Vector4f p;
p = m_uni2phys_T * ind.cast<float>();
return p;
}
//_____________________________________________________________
void Structured4DGrid::PrintSelf(std::ostream &o)
{
o << "uLib Structured Data 4D: \n"
<< "dim = " << this->GetDims().transpose() << "\n"
<< "spacing = " << this->GetSpacing().transpose() << "\n";
}

View File

@@ -0,0 +1,74 @@
/*//////////////////////////////////////////////////////////////////////////////
// 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.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef Structured4DGrid_H
#define Structured4DGrid_H
#include "Math/Dense.h"
#include <Eigen/Dense>
#include <Eigen/Geometry>
using namespace Eigen;
namespace uLib {
class Structured4DGrid {
public:
Structured4DGrid();
/// unit-space
void SetDims(const Vector4i &size);
inline Vector4i GetDims() {return m_Dims; }
bool IsInsideGrid(const Vector4i &v) const;
inline int Map(Vector4i index) const { return (m_Increments.transpose() * index);}
Vector4i UnMap(int index) const;
/// physics-space
void SetPhysicalSpace(const Vector4f &origin, const Vector4f &spacing);
inline Vector4f GetSpacing() const { return m_binW; }
inline Vector4f GetOrigin() const { return m_Origin; }
bool IsInsideBounds(const Vector4f &pt) const;
/// operations
Vector4i PhysicsToUnitSpace(const Vector4f &pt) const;
Vector4f UnitToPhysicsSpace(const Vector4i &ind) const;
void PrintSelf(std::ostream &o);
void SetDebug(bool debug){ m_debug = debug; };
private:
Vector4i m_Dims;
Vector4i m_Increments;
Vector4f m_binW;
Vector4f m_Origin;
bool m_debug;
Transform<float, 4, Eigen::Affine> m_uni2phys_T;
Transform<float, 4, Eigen::Affine> m_phys2uni_T;
};
}
#endif // Structured4DGrid_H