summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md11
-rw-r--r--README.txt9
-rw-r--r--build/linux/Makefile.in2
-rw-r--r--build/linux/configure.ac2
-rw-r--r--cuda/2d/darthelper.cu13
-rw-r--r--cuda/2d/par_fp.cu2
-rw-r--r--cuda/3d/cone_fp.cu2
-rw-r--r--cuda/3d/par3d_fp.cu2
-rw-r--r--include/astra/AstraObjectFactory.h2
-rw-r--r--include/astra/Config.h7
-rw-r--r--include/astra/Float32ProjectionData2D.h25
-rw-r--r--include/astra/Float32ProjectionData3D.h5
-rw-r--r--include/astra/Float32VolumeData2D.h25
-rw-r--r--include/astra/Float32VolumeData3D.h5
-rw-r--r--include/astra/XMLDocument.h2
-rw-r--r--include/astra/XMLNode.h92
-rw-r--r--matlab/mex/astra_mex_algorithm_c.cpp2
-rw-r--r--matlab/mex/astra_mex_data2d_c.cpp4
-rw-r--r--matlab/mex/astra_mex_data3d_c.cpp114
-rw-r--r--matlab/mex/mexCopyDataHelpFunctions.cpp2
-rw-r--r--matlab/mex/mexDataManagerHelpFunctions.cpp2
-rw-r--r--matlab/mex/mexHelpFunctions.cpp68
-rw-r--r--matlab/mex/mexHelpFunctions.h6
-rw-r--r--python/astra/ASTRAProjector.py135
-rw-r--r--python/astra/CFloat32CustomPython.h17
-rw-r--r--python/astra/PyIncludes.pxd25
-rw-r--r--python/astra/PyXMLDocument.pxd10
-rw-r--r--python/astra/__init__.py2
-rw-r--r--python/astra/data2d.py21
-rw-r--r--python/astra/data2d_c.pyx31
-rw-r--r--python/astra/data3d.py33
-rw-r--r--python/astra/data3d_c.pyx93
-rw-r--r--python/astra/functions.py25
-rw-r--r--python/astra/optomo.py197
-rw-r--r--python/astra/pythonutils.py63
-rw-r--r--python/astra/utils.pyx64
-rw-r--r--python/docSRC/index.rst2
-rw-r--r--python/docSRC/operator.rst (renamed from python/docSRC/ASTRAProjector.rst)4
-rw-r--r--src/ArtAlgorithm.cpp6
-rw-r--r--src/ConeProjectionGeometry3D.cpp26
-rw-r--r--src/ConeVecProjectionGeometry3D.cpp25
-rw-r--r--src/Config.cpp24
-rw-r--r--src/CudaBackProjectionAlgorithm3D.cpp6
-rw-r--r--src/CudaCglsAlgorithm3D.cpp6
-rw-r--r--src/CudaDartMaskAlgorithm.cpp22
-rw-r--r--src/CudaDartMaskAlgorithm3D.cpp22
-rw-r--r--src/CudaDartSmoothingAlgorithm.cpp20
-rw-r--r--src/CudaDartSmoothingAlgorithm3D.cpp20
-rw-r--r--src/CudaDataOperationAlgorithm.cpp25
-rw-r--r--src/CudaFDKAlgorithm3D.cpp6
-rw-r--r--src/CudaFilteredBackProjectionAlgorithm.cpp44
-rw-r--r--src/CudaForwardProjectionAlgorithm.cpp23
-rw-r--r--src/CudaForwardProjectionAlgorithm3D.cpp21
-rw-r--r--src/CudaProjector2D.cpp5
-rw-r--r--src/CudaProjector3D.cpp5
-rw-r--r--src/CudaReconstructionAlgorithm2D.cpp49
-rw-r--r--src/CudaRoiSelectAlgorithm.cpp13
-rw-r--r--src/CudaSartAlgorithm.cpp4
-rw-r--r--src/CudaSirtAlgorithm.cpp8
-rw-r--r--src/CudaSirtAlgorithm3D.cpp6
-rw-r--r--src/FanFlatProjectionGeometry2D.cpp22
-rw-r--r--src/FanFlatVecProjectionGeometry2D.cpp18
-rw-r--r--src/FilteredBackProjectionAlgorithm.cpp20
-rw-r--r--src/Float32ProjectionData2D.cpp19
-rw-r--r--src/Float32ProjectionData3D.cpp9
-rw-r--r--src/Float32VolumeData2D.cpp20
-rw-r--r--src/Float32VolumeData3D.cpp9
-rw-r--r--src/ForwardProjectionAlgorithm.cpp23
-rw-r--r--src/ParallelBeamBlobKernelProjector2D.cpp22
-rw-r--r--src/ParallelProjectionGeometry2D.cpp8
-rw-r--r--src/ParallelProjectionGeometry3D.cpp12
-rw-r--r--src/ParallelVecProjectionGeometry3D.cpp25
-rw-r--r--src/ProjectionGeometry2D.cpp17
-rw-r--r--src/ProjectionGeometry3D.cpp25
-rw-r--r--src/Projector2D.cpp6
-rw-r--r--src/Projector3D.cpp11
-rw-r--r--src/ReconstructionAlgorithm2D.cpp39
-rw-r--r--src/ReconstructionAlgorithm3D.cpp36
-rw-r--r--src/SartAlgorithm.cpp4
-rw-r--r--src/SparseMatrixProjectionGeometry2D.cpp15
-rw-r--r--src/VolumeGeometry2D.cpp30
-rw-r--r--src/VolumeGeometry3D.cpp45
-rw-r--r--src/XMLDocument.cpp10
-rw-r--r--src/XMLNode.cpp284
-rw-r--r--tests/test_Fourier.cpp4
-rw-r--r--tests/test_ParallelBeamLineKernelProjector2D.cpp2
-rw-r--r--tests/test_XMLDocument.cpp76
87 files changed, 1389 insertions, 934 deletions
diff --git a/README.md b/README.md
index ec86136..03c29dd 100644
--- a/README.md
+++ b/README.md
@@ -64,9 +64,14 @@ Install by copying AstraCuda32.dll or AstraCuda64.dll from bin/ and
## References
-If you use parallel beam GPU code for your research, we would appreciate it if you would refer to the following paper:
+If you use the ASTRA Toolbox for your research, we would appreciate it if you would refer to the following paper:
+
+W. van Aarle, W. J. Palenstijn, J. De Beenhouwer, T. Altantzis, S. Bals, K J. Batenburg, and J. Sijbers, "The ASTRA Toolbox: A platform for advanced algorithm development in electron tomography", Ultramicroscopy (2015), http://dx.doi.org/10.1016/j.ultramic.2015.05.002
+
+Additionally, if you use parallel beam GPU code, we would appreciate it if you would refer to the following paper:
+
+W. J. Palenstijn, K J. Batenburg, and J. Sijbers, "Performance improvements for iterative electron tomography reconstruction using graphics processing units (GPUs)", Journal of Structural Biology, vol. 176, issue 2, pp. 250-253, 2011, http://dx.doi.org/10.1016/j.jsb.2011.07.017
-W. J. Palenstijn, K J. Batenburg, and J. Sijbers, "Performance improvements for iterative electron tomography reconstruction using graphics processing units (GPUs)", Journal of Structural Biology, vol. 176, issue 2, pp. 250-253, 2011.
## License
@@ -79,4 +84,4 @@ website: http://sf.net/projects/astra-toolbox
Copyright: 2010-2015, iMinds-Vision Lab, University of Antwerp
2014-2015, CWI, Amsterdam
- http://visielab.uantwerpen.be/ and http://www.cwi.nl/ \ No newline at end of file
+ http://visielab.uantwerpen.be/ and http://www.cwi.nl/
diff --git a/README.txt b/README.txt
index 2877594..eae5085 100644
--- a/README.txt
+++ b/README.txt
@@ -90,11 +90,14 @@ Install by copying AstraCuda32.dll or AstraCuda64.dll from bin/ and
References:
------------
-If you use parallel beam GPU code for your research, we would appreciate it if
-you would refer to the following paper:
+If you use the ASTRA Toolbox for your research, we would appreciate it if you would refer to the following paper:
+
+W. van Aarle, W. J. Palenstijn, J. De Beenhouwer, T. Altantzis, S. Bals, K J. Batenburg, and J. Sijbers, "The ASTRA Toolbox: A platform for advanced algorithm development in electron tomography", Ultramicroscopy (2015), http://dx.doi.org/10.1016/j.ultramic.2015.05.002
+
+Additionally, if you use parallel beam GPU code, we would appreciate it if you would refer to the following paper:
W. J. Palenstijn, K J. Batenburg, and J. Sijbers, "Performance improvements
for iterative electron tomography reconstruction using graphics processing
units (GPUs)", Journal of Structural Biology, vol. 176, issue 2, pp. 250-253,
-2011
+2011, http://dx.doi.org/10.1016/j.jsb.2011.07.017
diff --git a/build/linux/Makefile.in b/build/linux/Makefile.in
index 0dfa15a..2d862f2 100644
--- a/build/linux/Makefile.in
+++ b/build/linux/Makefile.in
@@ -28,7 +28,7 @@ CXXFLAGS=@SAVED_CXXFLAGS@
LDFLAGS=@SAVED_LDFLAGS@
LIBS=@SAVED_LIBS@
-CPPFLAGS+=-I../.. -I../../include -I../../lib/include/rapidxml
+CPPFLAGS+=-I../.. -I../../include -I../../lib/include
CXXFLAGS+=-g -O3 -Wall -Wshadow
LIBS+=-lpthread
LDFLAGS+=-g
diff --git a/build/linux/configure.ac b/build/linux/configure.ac
index d9e1f1a..58a3f4c 100644
--- a/build/linux/configure.ac
+++ b/build/linux/configure.ac
@@ -190,7 +190,7 @@ if test x"$with_python" != x -a x"$with_python" != xno; then
AC_MSG_CHECKING(for python)
ASTRA_RUN_LOGOUTPUT(echo 'import sys' | $PYTHON -)
if test $? -ne 0; then
- AC_MSG_ERROR(Python binary not found)]
+ AC_MSG_ERROR(Python binary not found)
fi
AC_MSG_RESULT([$PYTHON])
HAVEPYTHON=yes
diff --git a/cuda/2d/darthelper.cu b/cuda/2d/darthelper.cu
index 28ca557..1d10d49 100644
--- a/cuda/2d/darthelper.cu
+++ b/cuda/2d/darthelper.cu
@@ -57,7 +57,7 @@ void roiSelect(float* out, float radius, unsigned int width, unsigned int height
// We abuse dims here...
SDimensions dims;
dims.iVolWidth = width;
- dims.iVolHeight = width;
+ dims.iVolHeight = height;
allocateVolumeData(D_data, pitch, dims);
copyVolumeToDevice(out, width, dims, D_data, pitch);
@@ -245,7 +245,7 @@ void dartMask(float* mask, const float* segmentation, unsigned int conn, unsigne
// We abuse dims here...
SDimensions dims;
dims.iVolWidth = width;
- dims.iVolHeight = width;
+ dims.iVolHeight = height;
allocateVolumeData(D_segmentationData, pitch, dims);
copyVolumeToDevice(segmentation, width, dims, D_segmentationData, pitch);
@@ -278,7 +278,7 @@ __global__ void devDartSmoothingRadius(float* out, const float* in, float b, uns
unsigned int x = threadIdx.x + 16*blockIdx.x;
unsigned int y = threadIdx.y + 16*blockIdx.y;
- // Sacrifice the border pixels to simplify the implementation.
+ // Sacrifice the border pixels to simplify the implementation.
if (x > radius-1 && x < width - radius && y > radius-1 && y < height - radius)
{
float* d = (float*)in;
@@ -286,9 +286,10 @@ __global__ void devDartSmoothingRadius(float* out, const float* in, float b, uns
unsigned int o2 = y*pitch+x;
int r = radius;
+ float count = 4*r*(r+1);
float res = -d[o2];
- for (int row = -r; row < r; row++)
+ for (int row = -r; row <= r; row++)
{
unsigned int o1 = (y+row)*pitch+x;
for (int col = -r; col <= r; col++)
@@ -297,7 +298,7 @@ __global__ void devDartSmoothingRadius(float* out, const float* in, float b, uns
}
}
- res *= b / 4*r*(r+1);
+ res *= b / count;
res += (1.0f-b) * d[o2];
m[o2] = res;
@@ -333,7 +334,7 @@ void dartSmoothing(float* out, const float* in, float b, unsigned int radius, un
// We abuse dims here...
SDimensions dims;
dims.iVolWidth = width;
- dims.iVolHeight = width;
+ dims.iVolHeight = height;
allocateVolumeData(D_inData, pitch, dims);
copyVolumeToDevice(in, width, dims, D_inData, pitch);
diff --git a/cuda/2d/par_fp.cu b/cuda/2d/par_fp.cu
index d0ca7ff..bb8b909 100644
--- a/cuda/2d/par_fp.cu
+++ b/cuda/2d/par_fp.cu
@@ -487,7 +487,7 @@ bool FP_simple_internal(float* D_volumeData, unsigned int volumePitch,
unsigned int blockEnd = 0;
bool blockVertical = false;
for (unsigned int a = 0; a <= dims.iProjAngles; ++a) {
- bool vertical;
+ bool vertical = false;
// TODO: Having <= instead of < below causes a 5% speedup.
// Maybe we should detect corner cases and put them in the optimal
// group of angles.
diff --git a/cuda/3d/cone_fp.cu b/cuda/3d/cone_fp.cu
index bda71ba..b36d2bc 100644
--- a/cuda/3d/cone_fp.cu
+++ b/cuda/3d/cone_fp.cu
@@ -340,7 +340,7 @@ bool ConeFP_Array_internal(cudaPitchedPtr D_projData,
// tic(t);
for (unsigned int a = 0; a <= angleCount; ++a) {
- int dir;
+ int dir = -1;
if (a != angleCount) {
float dX = fabsf(angles[a].fSrcX - (angles[a].fDetSX + dims.iProjU*angles[a].fDetUX*0.5f + dims.iProjV*angles[a].fDetVX*0.5f));
float dY = fabsf(angles[a].fSrcY - (angles[a].fDetSY + dims.iProjU*angles[a].fDetUY*0.5f + dims.iProjV*angles[a].fDetVY*0.5f));
diff --git a/cuda/3d/par3d_fp.cu b/cuda/3d/par3d_fp.cu
index 8d44540..b14c494 100644
--- a/cuda/3d/par3d_fp.cu
+++ b/cuda/3d/par3d_fp.cu
@@ -440,7 +440,7 @@ bool Par3DFP_Array_internal(cudaPitchedPtr D_projData,
// tic(t);
for (unsigned int a = 0; a <= angleCount; ++a) {
- int dir;
+ int dir = -1;
if (a != dims.iProjAngles) {
float dX = fabsf(angles[a].fRayX);
float dY = fabsf(angles[a].fRayY);
diff --git a/include/astra/AstraObjectFactory.h b/include/astra/AstraObjectFactory.h
index ba4ec11..1ed4955 100644
--- a/include/astra/AstraObjectFactory.h
+++ b/include/astra/AstraObjectFactory.h
@@ -110,7 +110,7 @@ template <typename T, typename TypeList>
T* CAstraObjectFactory<T, TypeList>::create(const Config& _cfg)
{
functor_find<T> finder = functor_find<T>();
- finder.tofind = _cfg.self->getAttribute("type");
+ finder.tofind = _cfg.self.getAttribute("type");
CreateObject<TypeList>::find(finder);
if (finder.res == NULL) return NULL;
if (finder.res->initialize(_cfg))
diff --git a/include/astra/Config.h b/include/astra/Config.h
index 9893c90..c10a16e 100644
--- a/include/astra/Config.h
+++ b/include/astra/Config.h
@@ -44,13 +44,14 @@ namespace astra {
struct _AstraExport Config {
Config();
- Config(XMLNode* _self);
+ Config(XMLNode _self);
~Config();
void initialize(std::string rootname);
- XMLNode* self;
- XMLNode* global;
+ XMLNode self;
+
+ XMLDocument *_doc;
};
struct ConfigCheckData {
diff --git a/include/astra/Float32ProjectionData2D.h b/include/astra/Float32ProjectionData2D.h
index 7461491..bb99f4b 100644
--- a/include/astra/Float32ProjectionData2D.h
+++ b/include/astra/Float32ProjectionData2D.h
@@ -101,6 +101,19 @@ public:
* Copy constructor
*/
CFloat32ProjectionData2D(const CFloat32ProjectionData2D& _other);
+
+ /** Constructor. Create an instance of the CFloat32ProjectionData2D class with pre-allocated memory.
+ *
+ * Creates an instance of the CFloat32ProjectionData2D class. Memory
+ * is pre-allocated and passed via the abstract CFloat32CustomMemory handle
+ * class. The handle will be deleted when the memory can be freed.
+ * You should override the destructor to provide custom behaviour on free.
+ *
+ * @param _pGeometry Projection Geometry object. This object will be HARDCOPIED into this class.
+ * @param _pCustomMemory custom memory handle
+ *
+ */
+ CFloat32ProjectionData2D(CProjectionGeometry2D* _pGeometry, CFloat32CustomMemory* _pCustomMemory);
/**
* Assignment operator
@@ -148,6 +161,18 @@ public:
* @param _fScalar scalar value to be put at each index.
*/
bool initialize(CProjectionGeometry2D* _pGeometry, float32 _fScalar);
+
+ /** Initialization. Initializes an instance of the CFloat32ProjectionData2D class with pre-allocated memory.
+ *
+ * Memory is pre-allocated and passed via the abstract CFloat32CustomMemory handle
+ * class. The handle will be deleted when the memory can be freed.
+ * You should override the destructor to provide custom behaviour on free.
+ *
+ * @param _pGeometry Projection Geometry object. This object will be HARDCOPIED into this class.
+ * @param _pCustomMemory custom memory handle
+ *
+ */
+ bool initialize(CProjectionGeometry2D* _pGeometry, CFloat32CustomMemory* _pCustomMemory);
/** Get the number of detectors.
*
diff --git a/include/astra/Float32ProjectionData3D.h b/include/astra/Float32ProjectionData3D.h
index 79b762e..329c9a4 100644
--- a/include/astra/Float32ProjectionData3D.h
+++ b/include/astra/Float32ProjectionData3D.h
@@ -196,6 +196,11 @@ public:
* @return pointer to projection geometry.
*/
virtual CProjectionGeometry3D* getGeometry() const;
+
+ /** Change the projection geometry.
+ * Note that this can't change the dimensions of the data.
+ */
+ virtual void changeGeometry(CProjectionGeometry3D* pGeometry);
};
diff --git a/include/astra/Float32VolumeData2D.h b/include/astra/Float32VolumeData2D.h
index 4f44a8c..abecebf 100644
--- a/include/astra/Float32VolumeData2D.h
+++ b/include/astra/Float32VolumeData2D.h
@@ -92,6 +92,19 @@ public:
* Copy constructor
*/
CFloat32VolumeData2D(const CFloat32VolumeData2D& _other);
+
+ /** Constructor. Create an instance of the CFloat32VolumeData2D class with pre-allocated memory.
+ *
+ * Creates an instance of the CFloat32VolumeData2D class. Memory
+ * is pre-allocated and passed via the abstract CFloat32CustomMemory handle
+ * class. The handle will be deleted when the memory can be freed.
+ * You should override the destructor to provide custom behaviour on free.
+ *
+ * @param _pGeometry Volume Geometry object. This object will be HARDCOPIED into this class.
+ * @param _pCustomMemory custom memory handle
+ *
+ */
+ CFloat32VolumeData2D(CVolumeGeometry2D* _pGeometry, CFloat32CustomMemory* _pCustomMemory);
/**
* Assignment operator
@@ -132,6 +145,18 @@ public:
* @param _fScalar scalar value to be put at each index.
*/
bool initialize(CVolumeGeometry2D* _pGeometry, float32 _fScalar);
+
+ /** Initialization. Initializes an instance of the CFloat32VolumeData2D class with pre-allocated memory.
+ *
+ * Memory is pre-allocated and passed via the abstract CFloat32CustomMemory handle
+ * class. The handle will be deleted when the memory can be freed.
+ * You should override the destructor to provide custom behaviour on free.
+ *
+ * @param _pGeometry Volume Geometry object. This object will be HARDCOPIED into this class.
+ * @param _pCustomMemory custom memory handle
+ *
+ */
+ bool initialize(CVolumeGeometry2D* _pGeometry, CFloat32CustomMemory* _pCustomMemory);
/** Destructor.
*/
diff --git a/include/astra/Float32VolumeData3D.h b/include/astra/Float32VolumeData3D.h
index d8f0ae9..07df78f 100644
--- a/include/astra/Float32VolumeData3D.h
+++ b/include/astra/Float32VolumeData3D.h
@@ -214,6 +214,11 @@ public:
* @return The geometry describing the data stored in this volume
*/
virtual CVolumeGeometry3D* getGeometry() const;
+
+ /** Change the projection geometry.
+ * Note that this can't change the dimensions of the data.
+ */
+ virtual void changeGeometry(CVolumeGeometry3D* pGeometry);
};
//----------------------------------------------------------------------------------------
diff --git a/include/astra/XMLDocument.h b/include/astra/XMLDocument.h
index 869e1a3..eddd908 100644
--- a/include/astra/XMLDocument.h
+++ b/include/astra/XMLDocument.h
@@ -78,7 +78,7 @@ public:
*
* @return first XML node of the document
*/
- XMLNode* getRootNode();
+ XMLNode getRootNode();
/** Save an XML DOM tree to an XML file
*
diff --git a/include/astra/XMLNode.h b/include/astra/XMLNode.h
index eceffe1..4d29d5c 100644
--- a/include/astra/XMLNode.h
+++ b/include/astra/XMLNode.h
@@ -64,71 +64,68 @@ public:
/** Deconstructor
*/
~XMLNode();
-
+
+ /** Check validity
+ */
+ operator bool() const { return fDOMElement != 0; }
/** Get a single child XML node. If there are more, the first one is returned
*
* @param _sName tagname of the requested child node
* @return first child node with the correct tagname, null pointer if it doesn't exist
*/
- XMLNode* getSingleNode(string _sName);
+ XMLNode getSingleNode(string _sName) const;
/** Get all child XML nodes that have the tagname name
*
* @param _sName tagname of the requested child nodes
* @return list with all child nodes with the correct tagname
*/
- std::list<XMLNode*> getNodes(string _sName);
+ std::list<XMLNode> getNodes(string _sName) const;
/** Get all child XML nodes
*
* @return list with all child nodes
*/
- std::list<XMLNode*> getNodes();
+ std::list<XMLNode> getNodes() const;
/** Get the name of this node
*
* @return name of node
*/
- std::string getName();
+ std::string getName() const;
/** Get the content of the XML node as a single string.
*
* @return node content
*/
- string getContent();
+ string getContent() const;
/** Get the content of the XML node as a numerical.
*
* @return node content
*/
- float32 getContentNumerical();
+ float32 getContentNumerical() const;
/** Get the content of the XML node as a boolean.
*
* @return node content
*/
- bool getContentBool();
+ bool getContentBool() const;
/** Get the content of the XML node as a vector of strings.
*
* @return node content
*/
- vector<string> getContentArray();
-
- /** Get the content of the XML node as a c-array of float32 data.
- *
- * @param _pfData data array, shouldn't be initialized already.
- * @param _iSize number of elements stored in _pfData
- */
- void getContentNumericalArray(float32*& _pfData, int& _iSize);
+ vector<string> getContentArray() const;
/** Get the content of the XML node as a stl container of float32 data.
+ * NB: A 2D matrix is returned as a linear list
*
* @return node content
*/
- vector<float32> getContentNumericalArray();
- vector<double> getContentNumericalArrayDouble();
+ vector<float32> getContentNumericalArray() const;
+ vector<double> getContentNumericalArrayDouble() const;
@@ -137,7 +134,7 @@ public:
* @param _sName of the attribute.
* @return attribute value, empty string if it doesn't exist.
*/
- bool hasAttribute(string _sName);
+ bool hasAttribute(string _sName) const;
/** Get the value of an attribute.
*
@@ -145,7 +142,7 @@ public:
* @param _sDefaultValue value to return if the attribute isn't found
* @return attribute value, _sDefaultValue if it doesn't exist.
*/
- string getAttribute(string _sName, string _sDefaultValue = "");
+ string getAttribute(string _sName, string _sDefaultValue = "") const;
/** Get the value of a numerical attribute.
*
@@ -153,8 +150,8 @@ public:
* @param _fDefaultValue value to return if the attribute isn't found
* @return attribute value, _fDefaultValue if it doesn't exist.
*/
- float32 getAttributeNumerical(string _sName, float32 _fDefaultValue = 0);
- double getAttributeNumericalDouble(string _sName, double _fDefaultValue = 0);
+ float32 getAttributeNumerical(string _sName, float32 _fDefaultValue = 0) const;
+ double getAttributeNumericalDouble(string _sName, double _fDefaultValue = 0) const;
/** Get the value of a boolean attribute.
*
@@ -162,7 +159,7 @@ public:
* @param _bDefaultValue value to return if the attribute isn't found
* @return attribute value, _bDefaultValue if it doesn't exist.
*/
- bool getAttributeBool(string _sName, bool _bDefaultValue = false);
+ bool getAttributeBool(string _sName, bool _bDefaultValue = false) const;
@@ -172,7 +169,7 @@ public:
* @param _sKey option key
* @return true if option does exist
*/
- bool hasOption(string _sKey);
+ bool hasOption(string _sKey) const;
/** Get the value of an option within this XML Node
*
@@ -180,7 +177,7 @@ public:
* @param _sDefaultValue value to return if key isn't found
* @return option value, _sDefaultValue if the option doesn't exist
*/
- string getOption(string _sKey, string _sDefaultValue = "");
+ string getOption(string _sKey, string _sDefaultValue = "") const;
/** Get the value of an option within this XML Node
*
@@ -188,7 +185,7 @@ public:
* @param _fDefaultValue value to return if key isn't found
* @return option value, _fDefaultValue if the option doesn't exist
*/
- float32 getOptionNumerical(string _sKey, float32 _fDefaultValue = 0);
+ float32 getOptionNumerical(string _sKey, float32 _fDefaultValue = 0) const;
/** Get the value of an option within this XML Node
*
@@ -196,14 +193,14 @@ public:
* @param _bDefaultValue value to return if key isn't found
* @return option value, _bDefaultValue if the option doesn't exist
*/
- bool getOptionBool(string _sKey, bool _bDefaultValue = false);
+ bool getOptionBool(string _sKey, bool _bDefaultValue = false) const;
/** Get the value of an option within this XML Node
*
* @param _sKey option key
* @return numerical array
*/
- vector<float32> getOptionNumericalArray(string _sKey);
+ vector<float32> getOptionNumericalArray(string _sKey) const;
@@ -214,7 +211,7 @@ public:
* @param _sNodeName the name of the new childnode
* @return new child node
*/
- XMLNode* addChildNode(string _sNodeName);
+ XMLNode addChildNode(string _sNodeName);
/** Create a new XML node as a child to this one, also add some content:
* &lt;...&gt;&lt;_sNodeName&gt;_sValue&lt;/_sNodeName>&lt;/...&gt;
@@ -223,7 +220,7 @@ public:
* @param _sValue some node content
* @return new child node
*/
- XMLNode* addChildNode(string _sNodeName, string _sValue);
+ XMLNode addChildNode(string _sNodeName, string _sValue);
/** Create a new XML node as a child to this one, also add some numerical content:
* &lt;...&gt;&lt;_sNodeName&gt;_sValue&lt;/_sNodeName>&lt;/...&gt;
@@ -232,7 +229,7 @@ public:
* @param _fValue some node content
* @return new child node
*/
- XMLNode* addChildNode(string _sNodeName, float32 _fValue);
+ XMLNode addChildNode(string _sNodeName, float32 _fValue);
/** Create a new XML node as a child to this one, also add a list of numerical content:
* &lt;...&gt;&lt;_sNodeName&gt;_sValue&lt;/_sNodeName>&lt;/...&gt;
@@ -242,7 +239,7 @@ public:
* @param _iSize number of elements in _pfList
* @return new child node
*/
- XMLNode* addChildNode(string _sNodeName, float32* _pfList, int _iSize);
+ XMLNode addChildNode(string _sNodeName, float32* _pfList, int _iSize);
/** Add some text to the node: &lt;...&gt;_sText&lt;/...&gt;
*
@@ -256,13 +253,38 @@ public:
*/
void setContent(float32 _fValue);
- /** Add a list of numerical data to the node: &lt;...&gt;_sText&lt;/...&gt;
+ /** Add a list of numerical data to the node
*
* @param _pfList data
* @param _iSize number of elements in the list
*/
void setContent(float32* _pfList, int _iSize);
+ /** Add a list of numerical data to the node
+ *
+ * @param _pfList data
+ * @param _iSize number of elements in the list
+ */
+ void setContent(double* _pfList, int _iSize);
+
+ /** Add a (2D) matrix of numerical data to the node
+ *
+ * @param _pfMatrix data
+ * @param _iWidth width of the matrix
+ * @param _iHeight height of the matrix
+ * @param transposed true is C order, false is Fortran order
+ */
+ void setContent(float32* _pfMatrix, int _iWidth, int _iHeight, bool transposed);
+
+ /** Add a (2D) matrix of numerical data to the node
+ *
+ * @param _pfMatrix data
+ * @param _iWidth width of the matrix
+ * @param _iHeight height of the matrix
+ * @param transposed true is C order, false is Fortran order
+ */
+ void setContent(double* _pfMatrix, int _iWidth, int _iHeight, bool transposed);
+
/** Add an attribute to this node: &lt;... _sName="_sValue"&gt;
*
* @param _sName name of the attribute
@@ -294,11 +316,11 @@ public:
/** Print to String
*/
- std::string toString();
+ std::string toString() const;
/** Print the node
*/
- void print();
+ void print() const;
protected:
diff --git a/matlab/mex/astra_mex_algorithm_c.cpp b/matlab/mex/astra_mex_algorithm_c.cpp
index e4afa63..ec7aa72 100644
--- a/matlab/mex/astra_mex_algorithm_c.cpp
+++ b/matlab/mex/astra_mex_algorithm_c.cpp
@@ -81,7 +81,7 @@ void astra_mex_algorithm_create(int nlhs, mxArray* plhs[], int nrhs, const mxArr
// turn MATLAB struct to an XML-based Config object
Config* cfg = structToConfig("Algorithm", prhs[1]);
- CAlgorithm* pAlg = CAlgorithmFactory::getSingleton().create(cfg->self->getAttribute("type"));
+ CAlgorithm* pAlg = CAlgorithmFactory::getSingleton().create(cfg->self.getAttribute("type"));
if (!pAlg) {
delete cfg;
mexErrMsgTxt("Unknown algorithm. \n");
diff --git a/matlab/mex/astra_mex_data2d_c.cpp b/matlab/mex/astra_mex_data2d_c.cpp
index 9576896..909d229 100644
--- a/matlab/mex/astra_mex_data2d_c.cpp
+++ b/matlab/mex/astra_mex_data2d_c.cpp
@@ -149,7 +149,7 @@ void astra_mex_data2d_create(int& nlhs, mxArray* plhs[], int& nrhs, const mxArra
Config* cfg = structToConfig("ProjectionGeometry", prhs[2]);
// FIXME: Change how the base class is created. (This is duplicated
// in 'change_geometry' and Projector2D.cpp.)
- std::string type = cfg->self->getAttribute("type");
+ std::string type = cfg->self.getAttribute("type");
CProjectionGeometry2D* pGeometry;
if (type == "sparse_matrix") {
pGeometry = new CSparseMatrixProjectionGeometry2D();
@@ -438,7 +438,7 @@ void astra_mex_data2d_change_geometry(int nlhs, mxArray* plhs[], int nrhs, const
Config* cfg = structToConfig("ProjectionGeometry2D", prhs[2]);
// FIXME: Change how the base class is created. (This is duplicated
// in 'create' and Projector2D.cpp.)
- std::string type = cfg->self->getAttribute("type");
+ std::string type = cfg->self.getAttribute("type");
CProjectionGeometry2D* pGeometry;
if (type == "sparse_matrix") {
pGeometry = new CSparseMatrixProjectionGeometry2D();
diff --git a/matlab/mex/astra_mex_data3d_c.cpp b/matlab/mex/astra_mex_data3d_c.cpp
index 32b0ba7..fe4ce37 100644
--- a/matlab/mex/astra_mex_data3d_c.cpp
+++ b/matlab/mex/astra_mex_data3d_c.cpp
@@ -148,8 +148,8 @@ void astra_mex_data3d_link(int& nlhs, mxArray* plhs[], int& nrhs, const mxArray*
return;
}
- if (data && !checkDataType(data)) {
- mexErrMsgTxt("Data must be single or double.");
+ if (data && !mxIsSingle(data)) {
+ mexErrMsgTxt("Data must be single.");
return;
}
@@ -310,6 +310,112 @@ void astra_mex_data3d_get_geometry(int nlhs, mxArray* plhs[], int nrhs, const mx
}
//-----------------------------------------------------------------------------------------
+/** astra_mex_data3d('change_geometry', id, geom);
+ *
+ * Change the geometry of a 3d data object.
+ * id: identifier of the 3d data object as stored in the astra-library.
+ * geom: the new geometry struct, as created by astra_create_vol/proj_geom
+ */
+void astra_mex_data3d_change_geometry(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[])
+{
+ // parse input
+ if (nrhs < 3) {
+ mexErrMsgTxt("Not enough arguments. See the help document for a detailed argument list. \n");
+ return;
+ }
+
+ // get data object
+ CFloat32Data3DMemory* pDataObject = NULL;
+ if (!checkID(mxGetScalar(prhs[1]), pDataObject)) {
+ mexErrMsgTxt("Data object not found or not initialized properly.\n");
+ return;
+ }
+
+ const mxArray * const geometry = prhs[2];
+
+ if (!checkStructs(geometry)) {
+ mexErrMsgTxt("Argument 3 is not a valid MATLAB struct.\n");
+ return;
+ }
+
+ CFloat32ProjectionData3D* pProjData = dynamic_cast<CFloat32ProjectionData3D*>(pDataObject);
+ if (pProjData) {
+ // Projection data
+
+ // Read geometry
+ astra::Config* cfg = structToConfig("ProjectionGeometry3D", geometry);
+ // FIXME: Change how the base class is created. (This is duplicated
+ // in Projector3D.cpp.)
+ std::string type = cfg->self.getAttribute("type");
+ astra::CProjectionGeometry3D* pGeometry = 0;
+ if (type == "parallel3d") {
+ pGeometry = new astra::CParallelProjectionGeometry3D();
+ } else if (type == "parallel3d_vec") {
+ pGeometry = new astra::CParallelVecProjectionGeometry3D();
+ } else if (type == "cone") {
+ pGeometry = new astra::CConeProjectionGeometry3D();
+ } else if (type == "cone_vec") {
+ pGeometry = new astra::CConeVecProjectionGeometry3D();
+ } else {
+ mexErrMsgTxt("Invalid geometry type.\n");
+ return;
+ }
+
+ if (!pGeometry->initialize(*cfg)) {
+ mexErrMsgTxt("Geometry class not initialized. \n");
+ delete pGeometry;
+ delete cfg;
+ return;
+ }
+ delete cfg;
+
+ // Check dimensions
+ if (pGeometry->getDetectorColCount() != pProjData->getDetectorColCount() ||
+ pGeometry->getProjectionCount() != pProjData->getAngleCount() ||
+ pGeometry->getDetectorRowCount() != pProjData->getDetectorRowCount())
+ {
+ mexErrMsgTxt("The dimensions of the data do not match those specified in the geometry. \n");
+ delete pGeometry;
+ return;
+ }
+
+ // If ok, change geometry
+ pProjData->changeGeometry(pGeometry);
+ delete pGeometry;
+ } else {
+ // Volume data
+ CFloat32VolumeData3D* pVolData = dynamic_cast<CFloat32VolumeData3D*>(pDataObject);
+ assert(pVolData);
+
+ // Read geometry
+ astra::Config* cfg = structToConfig("VolumeGeometry3D", geometry);
+ astra::CVolumeGeometry3D* pGeometry = new astra::CVolumeGeometry3D();
+ if (!pGeometry->initialize(*cfg))
+ {
+ mexErrMsgTxt("Geometry class not initialized. \n");
+ delete pGeometry;
+ delete cfg;
+ return;
+ }
+ delete cfg;
+
+ // Check dimensions
+ if (pGeometry->getGridColCount() != pVolData->getColCount() ||
+ pGeometry->getGridRowCount() != pVolData->getRowCount() ||
+ pGeometry->getGridSliceCount() != pVolData->getSliceCount())
+ {
+ mexErrMsgTxt("The dimensions of the data do not match those specified in the geometry. \n");
+ delete pGeometry;
+ return;
+ }
+
+ // If ok, change geometry
+ pVolData->changeGeometry(pGeometry);
+ delete pGeometry;
+ }
+}
+
+//-----------------------------------------------------------------------------------------
/**
* astra_mex_data3d('delete', did1, did2, ...);
*/
@@ -351,7 +457,7 @@ static void printHelp()
{
mexPrintf("Please specify a mode of operation.\n");
mexPrintf("Valid modes: create, get, get_single, delete, clear, info\n");
- mexPrintf(" dimensions\n");
+ mexPrintf(" dimensions, get_geometry, change_geometry\n");
}
@@ -398,6 +504,8 @@ void mexFunction(int nlhs, mxArray* plhs[],
astra_mex_data3d_dimensions(nlhs, plhs, nrhs, prhs);
} else if (sMode == std::string("get_geometry")) {
astra_mex_data3d_get_geometry(nlhs, plhs, nrhs, prhs);
+ } else if (sMode == std::string("change_geometry")) {
+ astra_mex_data3d_change_geometry(nlhs, plhs, nrhs, prhs);
} else {
printHelp();
}
diff --git a/matlab/mex/mexCopyDataHelpFunctions.cpp b/matlab/mex/mexCopyDataHelpFunctions.cpp
index 80fb834..4db6abd 100644
--- a/matlab/mex/mexCopyDataHelpFunctions.cpp
+++ b/matlab/mex/mexCopyDataHelpFunctions.cpp
@@ -263,7 +263,7 @@ copyMexToCFloat32Array(const mxArray * const in,
#pragma omp parallel
{
// fill with scalar value
- if (mexIsScalar(in)) {
+ if (mexIsScalar(in) || mxIsEmpty(in)) {
astra::float32 fValue = 0.f;
if (!mxIsEmpty(in)) {
fValue = (astra::float32)mxGetScalar(in);
diff --git a/matlab/mex/mexDataManagerHelpFunctions.cpp b/matlab/mex/mexDataManagerHelpFunctions.cpp
index d482428..1794abb 100644
--- a/matlab/mex/mexDataManagerHelpFunctions.cpp
+++ b/matlab/mex/mexDataManagerHelpFunctions.cpp
@@ -285,7 +285,7 @@ allocateDataObject(const std::string & sDataType,
astra::Config* cfg = structToConfig("ProjectionGeometry3D", geometry);
// FIXME: Change how the base class is created. (This is duplicated
// in Projector3D.cpp.)
- std::string type = cfg->self->getAttribute("type");
+ std::string type = cfg->self.getAttribute("type");
astra::CProjectionGeometry3D* pGeometry = 0;
if (type == "parallel3d") {
pGeometry = new astra::CParallelProjectionGeometry3D();
diff --git a/matlab/mex/mexHelpFunctions.cpp b/matlab/mex/mexHelpFunctions.cpp
index c0ac711..87a9672 100644
--- a/matlab/mex/mexHelpFunctions.cpp
+++ b/matlab/mex/mexHelpFunctions.cpp
@@ -185,7 +185,7 @@ Config* structToConfig(string rootname, const mxArray* pStruct)
}
//-----------------------------------------------------------------------------------------
-bool structToXMLNode(XMLNode* node, const mxArray* pStruct)
+bool structToXMLNode(XMLNode node, const mxArray* pStruct)
{
// loop all fields
int nfields = mxGetNumberOfFields(pStruct);
@@ -199,16 +199,16 @@ bool structToXMLNode(XMLNode* node, const mxArray* pStruct)
if (mxIsChar(pField)) {
string sValue = mexToString(pField);
if (sFieldName == "type") {
- node->addAttribute("type", sValue);
+ node.addAttribute("type", sValue);
} else {
- delete node->addChildNode(sFieldName, sValue);
+ node.addChildNode(sFieldName, sValue);
}
}
// scalar
else if (mxIsNumeric(pField) && mxGetM(pField)*mxGetN(pField) == 1) {
string sValue = mexToString(pField);
- delete node->addChildNode(sFieldName, sValue);
+ node.addChildNode(sFieldName, sValue);
}
// numerical array
@@ -217,20 +217,9 @@ bool structToXMLNode(XMLNode* node, const mxArray* pStruct)
mexErrMsgTxt("Numeric input must be double.");
return false;
}
- XMLNode* listbase = node->addChildNode(sFieldName);
- listbase->addAttribute("listsize", mxGetM(pField)*mxGetN(pField));
+ XMLNode listbase = node.addChildNode(sFieldName);
double* pdValues = mxGetPr(pField);
- int index = 0;
- for (unsigned int row = 0; row < mxGetM(pField); row++) {
- for (unsigned int col = 0; col < mxGetN(pField); col++) {
- XMLNode* item = listbase->addChildNode("ListItem");
- item->addAttribute("index", index);
- item->addAttribute("value", pdValues[col*mxGetM(pField)+row]);
- index++;
- delete item;
- }
- }
- delete listbase;
+ listbase.setContent(pdValues, mxGetN(pField), mxGetM(pField), true);
}
// not castable to a single string
@@ -240,9 +229,8 @@ bool structToXMLNode(XMLNode* node, const mxArray* pStruct)
if (!ret)
return false;
} else {
- XMLNode* newNode = node->addChildNode(sFieldName);
+ XMLNode newNode = node.addChildNode(sFieldName);
bool ret = structToXMLNode(newNode, pField);
- delete newNode;
if (!ret)
return false;
}
@@ -254,7 +242,7 @@ bool structToXMLNode(XMLNode* node, const mxArray* pStruct)
}
//-----------------------------------------------------------------------------------------
// Options struct to xml node
-bool optionsToXMLNode(XMLNode* node, const mxArray* pOptionStruct)
+bool optionsToXMLNode(XMLNode node, const mxArray* pOptionStruct)
{
// loop all fields
int nfields = mxGetNumberOfFields(pOptionStruct);
@@ -262,7 +250,7 @@ bool optionsToXMLNode(XMLNode* node, const mxArray* pOptionStruct)
std::string sFieldName = std::string(mxGetFieldNameByNumber(pOptionStruct, i));
const mxArray* pField = mxGetFieldByNumber(pOptionStruct, 0, i);
- if (node->hasOption(sFieldName)) {
+ if (node.hasOption(sFieldName)) {
mexErrMsgTxt("Duplicate option");
return false;
}
@@ -270,7 +258,7 @@ bool optionsToXMLNode(XMLNode* node, const mxArray* pOptionStruct)
// string or scalar
if (mxIsChar(pField) || mexIsScalar(pField)) {
string sValue = mexToString(pField);
- node->addOption(sFieldName, sValue);
+ node.addOption(sFieldName, sValue);
}
// numerical array
else if (mxIsNumeric(pField) && mxGetM(pField)*mxGetN(pField) > 1) {
@@ -279,21 +267,10 @@ bool optionsToXMLNode(XMLNode* node, const mxArray* pOptionStruct)
return false;
}
- XMLNode* listbase = node->addChildNode("Option");
- listbase->addAttribute("key", sFieldName);
- listbase->addAttribute("listsize", mxGetM(pField)*mxGetN(pField));
+ XMLNode listbase = node.addChildNode("Option");
+ listbase.addAttribute("key", sFieldName);
double* pdValues = mxGetPr(pField);
- int index = 0;
- for (unsigned int row = 0; row < mxGetM(pField); row++) {
- for (unsigned int col = 0; col < mxGetN(pField); col++) {
- XMLNode* item = listbase->addChildNode("ListItem");
- item->addAttribute("index", index);
- item->addAttribute("value", pdValues[col*mxGetM(pField)+row]);
- index++;
- delete item;
- }
- }
- delete listbase;
+ listbase.setContent(pdValues, mxGetN(pField), mxGetM(pField), true);
} else {
mexErrMsgTxt("Unsupported option type");
return false;
@@ -343,30 +320,29 @@ mxArray* configToStruct(astra::Config* cfg)
}
//-----------------------------------------------------------------------------------------
-mxArray* XMLNodeToStruct(astra::XMLNode* node)
+mxArray* XMLNodeToStruct(astra::XMLNode node)
{
std::map<std::string, mxArray*> mList;
std::map<std::string, mxArray*> mOptions;
// type_attribute
- if (node->hasAttribute("type")) {
- mList["type"] = mxCreateString(node->getAttribute("type").c_str());
+ if (node.hasAttribute("type")) {
+ mList["type"] = mxCreateString(node.getAttribute("type").c_str());
}
- list<XMLNode*> nodes = node->getNodes();
- for (list<XMLNode*>::iterator it = nodes.begin(); it != nodes.end(); it++) {
- XMLNode* subnode = (*it);
+ list<XMLNode> nodes = node.getNodes();
+ for (list<XMLNode>::iterator it = nodes.begin(); it != nodes.end(); it++) {
+ XMLNode subnode = (*it);
// option
- if (subnode->getName() == "Option") {
- mOptions[subnode->getAttribute("key")] = stringToMxArray(subnode->getAttribute("value"));
+ if (subnode.getName() == "Option") {
+ mOptions[subnode.getAttribute("key")] = stringToMxArray(subnode.getAttribute("value"));
}
// regular content
else {
- mList[subnode->getName()] = stringToMxArray(subnode->getContent());
+ mList[subnode.getName()] = stringToMxArray(subnode.getContent());
}
- delete subnode;
}
if (mOptions.size() > 0) mList["options"] = buildStruct(mOptions);
diff --git a/matlab/mex/mexHelpFunctions.h b/matlab/mex/mexHelpFunctions.h
index f9ffcf2..3ac5bd8 100644
--- a/matlab/mex/mexHelpFunctions.h
+++ b/matlab/mex/mexHelpFunctions.h
@@ -58,13 +58,13 @@ mxArray* anyToMxArray(boost::any _any);
// turn a MATLAB struct into a Config object
astra::Config* structToConfig(string rootname, const mxArray* pStruct);
-bool structToXMLNode(astra::XMLNode* node, const mxArray* pStruct);
-bool optionsToXMLNode(astra::XMLNode* node, const mxArray* pOptionStruct);
+bool structToXMLNode(astra::XMLNode node, const mxArray* pStruct);
+bool optionsToXMLNode(astra::XMLNode node, const mxArray* pOptionStruct);
std::map<std::string, mxArray*> parseStruct(const mxArray* pInput);
// turn a Config object into a MATLAB struct
mxArray* configToStruct(astra::Config* cfg);
-mxArray* XMLNodeToStruct(astra::XMLNode* xml);
+mxArray* XMLNodeToStruct(astra::XMLNode xml);
mxArray* stringToMxArray(std::string input);
mxArray* buildStruct(std::map<std::string, mxArray*> mInput);
diff --git a/python/astra/ASTRAProjector.py b/python/astra/ASTRAProjector.py
deleted file mode 100644
index f282618..0000000
--- a/python/astra/ASTRAProjector.py
+++ /dev/null
@@ -1,135 +0,0 @@
-#-----------------------------------------------------------------------
-#Copyright 2013 Centrum Wiskunde & Informatica, Amsterdam
-#
-#Author: Daniel M. Pelt
-#Contact: D.M.Pelt@cwi.nl
-#Website: http://dmpelt.github.io/pyastratoolbox/
-#
-#
-#This file is part of the Python interface to the
-#All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA Toolbox").
-#
-#The Python interface to the ASTRA Toolbox is free software: you can redistribute it and/or modify
-#it under the terms of the GNU General Public License as published by
-#the Free Software Foundation, either version 3 of the License, or
-#(at your option) any later version.
-#
-#The Python interface to the ASTRA Toolbox 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 General Public License for more details.
-#
-#You should have received a copy of the GNU General Public License
-#along with the Python interface to the ASTRA Toolbox. If not, see <http://www.gnu.org/licenses/>.
-#
-#-----------------------------------------------------------------------
-
-import math
-from . import creators as ac
-from . import data2d
-
-
-class ASTRAProjector2DTranspose():
- """Implements the ``proj.T`` functionality.
-
- Do not use directly, since it can be accessed as member ``.T`` of
- an :class:`ASTRAProjector2D` object.
-
- """
- def __init__(self, parentProj):
- self.parentProj = parentProj
-
- def __mul__(self, data):
- return self.parentProj.backProject(data)
-
-
-class ASTRAProjector2D(object):
- """Helps with various common ASTRA Toolbox 2D operations.
-
- This class can perform several often used toolbox operations, such as:
-
- * Forward projecting
- * Back projecting
- * Reconstructing
-
- Note that this class has a some computational overhead, because it
- copies a lot of data. If you use many repeated operations, directly
- using the PyAstraToolbox methods directly is faster.
-
- You can use this class as an abstracted weight matrix :math:`W`: multiplying an instance
- ``proj`` of this class by an image results in a forward projection of the image, and multiplying
- ``proj.T`` by a sinogram results in a backprojection of the sinogram::
-
- proj = ASTRAProjector2D(...)
- fp = proj*image
- bp = proj.T*sinogram
-
- :param proj_geom: The projection geometry.
- :type proj_geom: :class:`dict`
- :param vol_geom: The volume geometry.
- :type vol_geom: :class:`dict`
- :param proj_type: Projector type, such as ``'line'``, ``'linear'``, ...
- :type proj_type: :class:`string`
- """
-
- def __init__(self, proj_geom, vol_geom, proj_type):
- self.vol_geom = vol_geom
- self.recSize = vol_geom['GridColCount']
- self.angles = proj_geom['ProjectionAngles']
- self.nDet = proj_geom['DetectorCount']
- nexpow = int(pow(2, math.ceil(math.log(2 * self.nDet, 2))))
- self.filterSize = nexpow / 2 + 1
- self.nProj = self.angles.shape[0]
- self.proj_geom = proj_geom
- self.proj_id = ac.create_projector(proj_type, proj_geom, vol_geom)
- self.T = ASTRAProjector2DTranspose(self)
-
- def backProject(self, data):
- """Backproject a sinogram.
-
- :param data: The sinogram data or ID.
- :type data: :class:`numpy.ndarray` or :class:`int`
- :returns: :class:`numpy.ndarray` -- The backprojection.
-
- """
- vol_id, vol = ac.create_backprojection(
- data, self.proj_id, returnData=True)
- data2d.delete(vol_id)
- return vol
-
- def forwardProject(self, data):
- """Forward project an image.
-
- :param data: The image data or ID.
- :type data: :class:`numpy.ndarray` or :class:`int`
- :returns: :class:`numpy.ndarray` -- The forward projection.
-
- """
- sin_id, sino = ac.create_sino(data, self.proj_id, returnData=True)
- data2d.delete(sin_id)
- return sino
-
- def reconstruct(self, data, method, **kwargs):
- """Reconstruct an image from a sinogram.
-
- :param data: The sinogram data or ID.
- :type data: :class:`numpy.ndarray` or :class:`int`
- :param method: Name of the reconstruction algorithm.
- :type method: :class:`string`
- :param kwargs: Additional named parameters to pass to :func:`astra.creators.create_reconstruction`.
- :returns: :class:`numpy.ndarray` -- The reconstruction.
-
- Example of a SIRT reconstruction using CUDA::
-
- proj = ASTRAProjector2D(...)
- rec = proj.reconstruct(sinogram,'SIRT_CUDA',iterations=1000)
-
- """
- kwargs['returnData'] = True
- rec_id, rec = ac.create_reconstruction(
- method, self.proj_id, data, **kwargs)
- data2d.delete(rec_id)
- return rec
-
- def __mul__(self, data):
- return self.forwardProject(data)
diff --git a/python/astra/CFloat32CustomPython.h b/python/astra/CFloat32CustomPython.h
new file mode 100644
index 0000000..d8593fc
--- /dev/null
+++ b/python/astra/CFloat32CustomPython.h
@@ -0,0 +1,17 @@
+class CFloat32CustomPython : public astra::CFloat32CustomMemory {
+public:
+ CFloat32CustomPython(PyObject * arrIn)
+ {
+ arr = arrIn;
+ // Set pointer to numpy data pointer
+ m_fPtr = (float *)PyArray_DATA(arr);
+ // Increase reference count since ASTRA has a reference
+ Py_INCREF(arr);
+ }
+ virtual ~CFloat32CustomPython() {
+ // Decrease reference count since ASTRA object is destroyed
+ Py_DECREF(arr);
+ }
+private:
+ PyObject* arr;
+}; \ No newline at end of file
diff --git a/python/astra/PyIncludes.pxd b/python/astra/PyIncludes.pxd
index 7df02c5..909f58f 100644
--- a/python/astra/PyIncludes.pxd
+++ b/python/astra/PyIncludes.pxd
@@ -43,7 +43,7 @@ cdef extern from "astra/Config.h" namespace "astra":
cdef cppclass Config:
Config()
void initialize(string rootname)
- XMLNode *self
+ XMLNode self
cdef extern from "astra/VolumeGeometry2D.h" namespace "astra":
cdef cppclass CVolumeGeometry2D:
@@ -63,10 +63,14 @@ cdef extern from "astra/VolumeGeometry2D.h" namespace "astra":
float32 getWindowMaxY()
Config* getConfiguration()
+cdef extern from "astra/Float32Data2D.h" namespace "astra":
+ cdef cppclass CFloat32CustomMemory:
+ pass
cdef extern from "astra/Float32VolumeData2D.h" namespace "astra":
cdef cppclass CFloat32VolumeData2D:
CFloat32VolumeData2D(CVolumeGeometry2D*)
+ CFloat32VolumeData2D(CVolumeGeometry2D*, CFloat32CustomMemory*)
CVolumeGeometry2D * getGeometry()
int getWidth()
int getHeight()
@@ -130,6 +134,7 @@ cdef extern from "astra/ParallelProjectionGeometry2D.h" namespace "astra":
cdef extern from "astra/Float32ProjectionData2D.h" namespace "astra":
cdef cppclass CFloat32ProjectionData2D:
CFloat32ProjectionData2D(CProjectionGeometry2D*)
+ CFloat32ProjectionData2D(CProjectionGeometry2D*, CFloat32CustomMemory*)
CProjectionGeometry2D * getGeometry()
void changeGeometry(CProjectionGeometry2D*)
int getDetectorCount()
@@ -196,18 +201,30 @@ cdef extern from "astra/VolumeGeometry3D.h" namespace "astra":
CVolumeGeometry3D()
bool initialize(Config)
Config * getConfiguration()
+ int getGridColCount()
+ int getGridRowCount()
+ int getGridSliceCount()
cdef extern from "astra/ProjectionGeometry3D.h" namespace "astra":
cdef cppclass CProjectionGeometry3D:
CProjectionGeometry3D()
bool initialize(Config)
Config * getConfiguration()
+ int getProjectionCount()
+ int getDetectorColCount()
+ int getDetectorRowCount()
cdef extern from "astra/Float32VolumeData3DMemory.h" namespace "astra":
cdef cppclass CFloat32VolumeData3DMemory:
CFloat32VolumeData3DMemory(CVolumeGeometry3D*)
+ CFloat32VolumeData3DMemory(CVolumeGeometry3D*, CFloat32CustomMemory*)
CVolumeGeometry3D* getGeometry()
+ void changeGeometry(CVolumeGeometry3D*)
+ int getRowCount()
+ int getColCount()
+ int getSliceCount()
+
cdef extern from "astra/ParallelProjectionGeometry3D.h" namespace "astra":
@@ -231,7 +248,13 @@ cdef extern from "astra/Float32ProjectionData3DMemory.h" namespace "astra":
cdef cppclass CFloat32ProjectionData3DMemory:
CFloat32ProjectionData3DMemory(CProjectionGeometry3D*)
CFloat32ProjectionData3DMemory(CConeProjectionGeometry3D*)
+ CFloat32ProjectionData3DMemory(CProjectionGeometry3D*, CFloat32CustomMemory*)
+ CFloat32ProjectionData3DMemory(CConeProjectionGeometry3D*, CFloat32CustomMemory*)
CProjectionGeometry3D* getGeometry()
+ void changeGeometry(CProjectionGeometry3D*)
+ int getDetectorColCount()
+ int getDetectorRowCount()
+ int getAngleCount()
cdef extern from "astra/Float32Data3D.h" namespace "astra":
cdef cppclass CFloat32Data3D:
diff --git a/python/astra/PyXMLDocument.pxd b/python/astra/PyXMLDocument.pxd
index 69781f1..033b8ef 100644
--- a/python/astra/PyXMLDocument.pxd
+++ b/python/astra/PyXMLDocument.pxd
@@ -44,22 +44,24 @@ cdef extern from "astra/Globals.h" namespace "astra":
cdef extern from "astra/XMLNode.h" namespace "astra":
cdef cppclass XMLNode:
string getName()
- XMLNode *addChildNode(string name)
- XMLNode *addChildNode(string, string)
+ XMLNode addChildNode(string name)
+ XMLNode addChildNode(string, string)
void addAttribute(string, string)
void addAttribute(string, float32)
void addOption(string, string)
bool hasOption(string)
string getAttribute(string)
- list[XMLNode *] getNodes()
+ list[XMLNode] getNodes()
vector[float32] getContentNumericalArray()
+ void setContent(double*, int, int, bool)
+ void setContent(double*, int)
string getContent()
bool hasAttribute(string)
cdef extern from "astra/XMLDocument.h" namespace "astra":
cdef cppclass XMLDocument:
void saveToFile(string sFilename)
- XMLNode *getRootNode()
+ XMLNode getRootNode()
cdef extern from "astra/XMLDocument.h" namespace "astra::XMLDocument":
cdef XMLDocument *createDocument(string rootname)
diff --git a/python/astra/__init__.py b/python/astra/__init__.py
index 063dc16..6c15d30 100644
--- a/python/astra/__init__.py
+++ b/python/astra/__init__.py
@@ -27,7 +27,6 @@ from . import matlab as m
from .creators import astra_dict,create_vol_geom, create_proj_geom, create_backprojection, create_sino, create_reconstruction, create_projector,create_sino3d_gpu, create_backprojection3d_gpu
from .functions import data_op, add_noise_to_sino, clear, move_vol_geom
from .extrautils import clipCircle
-from .ASTRAProjector import ASTRAProjector2D
from . import data2d
from . import astra
from . import data3d
@@ -36,6 +35,7 @@ from . import projector
from . import projector3d
from . import matrix
from . import log
+from .optomo import OpTomo
import os
try:
diff --git a/python/astra/data2d.py b/python/astra/data2d.py
index 8c4be03..f119f05 100644
--- a/python/astra/data2d.py
+++ b/python/astra/data2d.py
@@ -24,6 +24,7 @@
#
#-----------------------------------------------------------------------
from . import data2d_c as d
+import numpy as np
def clear():
"""Clear all 2D data objects."""
@@ -52,6 +53,26 @@ def create(datatype, geometry, data=None):
"""
return d.create(datatype,geometry,data)
+def link(datatype, geometry, data):
+ """Link a 2D numpy array with the toolbox.
+
+ :param datatype: Data object type, '-vol' or '-sino'.
+ :type datatype: :class:`string`
+ :param geometry: Volume or projection geometry.
+ :type geometry: :class:`dict`
+ :param data: Numpy array to link
+ :type data: :class:`numpy.ndarray`
+ :returns: :class:`int` -- the ID of the constructed object.
+
+ """
+ if not isinstance(data,np.ndarray):
+ raise ValueError("Input should be a numpy array")
+ if not data.dtype==np.float32:
+ raise ValueError("Numpy array should be float32")
+ if not (data.flags['C_CONTIGUOUS'] and data.flags['ALIGNED']):
+ raise ValueError("Numpy array should be C_CONTIGUOUS and ALIGNED")
+ return d.create(datatype,geometry,data,True)
+
def store(i, data):
"""Fill existing 2D object with data.
diff --git a/python/astra/data2d_c.pyx b/python/astra/data2d_c.pyx
index b9c105e..4919bf2 100644
--- a/python/astra/data2d_c.pyx
+++ b/python/astra/data2d_c.pyx
@@ -47,8 +47,18 @@ from .PyIncludes cimport *
cimport utils
from .utils import wrap_from_bytes
+from .pythonutils import geom_size
+
+import operator
+
+from six.moves import reduce
+
cdef CData2DManager * man2d = <CData2DManager * >PyData2DManager.getSingletonPtr()
+cdef extern from "CFloat32CustomPython.h":
+ cdef cppclass CFloat32CustomPython:
+ CFloat32CustomPython(arrIn)
+
def clear():
man2d.clear()
@@ -61,11 +71,16 @@ def delete(ids):
man2d.remove(ids)
-def create(datatype, geometry, data=None):
+def create(datatype, geometry, data=None, link=False):
cdef Config *cfg
cdef CVolumeGeometry2D * pGeometry
cdef CProjectionGeometry2D * ppGeometry
cdef CFloat32Data2D * pDataObject2D
+ cdef CFloat32CustomMemory * pCustom
+
+ if link and data.shape!=geom_size(geometry):
+ raise Exception("The dimensions of the data do not match those specified in the geometry.")
+
if datatype == '-vol':
cfg = utils.dictToConfig(six.b('VolumeGeometry'), geometry)
pGeometry = new CVolumeGeometry2D()
@@ -73,7 +88,11 @@ def create(datatype, geometry, data=None):
del cfg
del pGeometry
raise Exception('Geometry class not initialized.')
- pDataObject2D = <CFloat32Data2D * > new CFloat32VolumeData2D(pGeometry)
+ if link:
+ pCustom = <CFloat32CustomMemory*> new CFloat32CustomPython(data)
+ pDataObject2D = <CFloat32Data2D * > new CFloat32VolumeData2D(pGeometry, pCustom)
+ else:
+ pDataObject2D = <CFloat32Data2D * > new CFloat32VolumeData2D(pGeometry)
del cfg
del pGeometry
elif datatype == '-sino':
@@ -91,7 +110,11 @@ def create(datatype, geometry, data=None):
del cfg
del ppGeometry
raise Exception('Geometry class not initialized.')
- pDataObject2D = <CFloat32Data2D * > new CFloat32ProjectionData2D(ppGeometry)
+ if link:
+ pCustom = <CFloat32CustomMemory*> new CFloat32CustomPython(data)
+ pDataObject2D = <CFloat32Data2D * > new CFloat32ProjectionData2D(ppGeometry, pCustom)
+ else:
+ pDataObject2D = <CFloat32Data2D * > new CFloat32ProjectionData2D(ppGeometry)
del ppGeometry
del cfg
else:
@@ -101,7 +124,7 @@ def create(datatype, geometry, data=None):
del pDataObject2D
raise Exception("Couldn't initialize data object.")
- fillDataObject(pDataObject2D, data)
+ if not link: fillDataObject(pDataObject2D, data)
return man2d.store(pDataObject2D)
diff --git a/python/astra/data3d.py b/python/astra/data3d.py
index a2e9201..e5ef6b0 100644
--- a/python/astra/data3d.py
+++ b/python/astra/data3d.py
@@ -24,6 +24,7 @@
#
#-----------------------------------------------------------------------
from . import data3d_c as d
+import numpy as np
def create(datatype,geometry,data=None):
"""Create a 3D object.
@@ -39,6 +40,27 @@ def create(datatype,geometry,data=None):
"""
return d.create(datatype,geometry,data)
+def link(datatype, geometry, data):
+ """Link a 3D numpy array with the toolbox.
+
+ :param datatype: Data object type, '-vol' or '-sino'.
+ :type datatype: :class:`string`
+ :param geometry: Volume or projection geometry.
+ :type geometry: :class:`dict`
+ :param data: Numpy array to link
+ :type data: :class:`numpy.ndarray`
+ :returns: :class:`int` -- the ID of the constructed object.
+
+ """
+ if not isinstance(data,np.ndarray):
+ raise ValueError("Input should be a numpy array")
+ if not data.dtype==np.float32:
+ raise ValueError("Numpy array should be float32")
+ if not (data.flags['C_CONTIGUOUS'] and data.flags['ALIGNED']):
+ raise ValueError("Numpy array should be C_CONTIGUOUS and ALIGNED")
+ return d.create(datatype,geometry,data,True)
+
+
def get(i):
"""Get a 3D object.
@@ -90,6 +112,17 @@ def get_geometry(i):
"""
return d.get_geometry(i)
+def change_geometry(i, geometry):
+ """Change the geometry of a 3D object.
+
+ :param i: ID of object.
+ :type i: :class:`int`
+ :param geometry: Volume or projection geometry.
+ :type geometry: :class:`dict`
+
+ """
+ return d.change_geometry(i, geometry)
+
def dimensions(i):
"""Get dimensions of a 3D object.
diff --git a/python/astra/data3d_c.pyx b/python/astra/data3d_c.pyx
index 4b069f7..3b27ab7 100644
--- a/python/astra/data3d_c.pyx
+++ b/python/astra/data3d_c.pyx
@@ -45,17 +45,33 @@ from .PyXMLDocument cimport XMLDocument
cimport utils
from .utils import wrap_from_bytes
+from .pythonutils import geom_size
+
+import operator
+
+from six.moves import reduce
+
+
cdef CData3DManager * man3d = <CData3DManager * >PyData3DManager.getSingletonPtr()
cdef extern from *:
CFloat32Data3DMemory * dynamic_cast_mem "dynamic_cast<astra::CFloat32Data3DMemory*>" (CFloat32Data3D * ) except NULL
-def create(datatype,geometry,data=None):
+cdef extern from "CFloat32CustomPython.h":
+ cdef cppclass CFloat32CustomPython:
+ CFloat32CustomPython(arrIn)
+
+def create(datatype,geometry,data=None, link=False):
cdef Config *cfg
cdef CVolumeGeometry3D * pGeometry
cdef CProjectionGeometry3D * ppGeometry
cdef CFloat32Data3DMemory * pDataObject3D
cdef CConeProjectionGeometry3D* pppGeometry
+ cdef CFloat32CustomMemory * pCustom
+
+ if link and data.shape!=geom_size(geometry):
+ raise Exception("The dimensions of the data do not match those specified in the geometry.")
+
if datatype == '-vol':
cfg = utils.dictToConfig(six.b('VolumeGeometry'), geometry)
pGeometry = new CVolumeGeometry3D()
@@ -63,7 +79,11 @@ def create(datatype,geometry,data=None):
del cfg
del pGeometry
raise Exception('Geometry class not initialized.')
- pDataObject3D = <CFloat32Data3DMemory * > new CFloat32VolumeData3DMemory(pGeometry)
+ if link:
+ pCustom = <CFloat32CustomMemory*> new CFloat32CustomPython(data)
+ pDataObject3D = <CFloat32Data3DMemory * > new CFloat32VolumeData3DMemory(pGeometry, pCustom)
+ else:
+ pDataObject3D = <CFloat32Data3DMemory * > new CFloat32VolumeData3DMemory(pGeometry)
del cfg
del pGeometry
elif datatype == '-sino' or datatype == '-proj3d':
@@ -84,7 +104,11 @@ def create(datatype,geometry,data=None):
del cfg
del ppGeometry
raise Exception('Geometry class not initialized.')
- pDataObject3D = <CFloat32Data3DMemory * > new CFloat32ProjectionData3DMemory(ppGeometry)
+ if link:
+ pCustom = <CFloat32CustomMemory*> new CFloat32CustomPython(data)
+ pDataObject3D = <CFloat32Data3DMemory * > new CFloat32ProjectionData3DMemory(ppGeometry, pCustom)
+ else:
+ pDataObject3D = <CFloat32Data3DMemory * > new CFloat32ProjectionData3DMemory(ppGeometry)
del ppGeometry
del cfg
elif datatype == "-sinocone":
@@ -94,7 +118,11 @@ def create(datatype,geometry,data=None):
del cfg
del pppGeometry
raise Exception('Geometry class not initialized.')
- pDataObject3D = <CFloat32Data3DMemory * > new CFloat32ProjectionData3DMemory(pppGeometry)
+ if link:
+ pCustom = <CFloat32CustomMemory*> new CFloat32CustomPython(data)
+ pDataObject3D = <CFloat32Data3DMemory * > new CFloat32ProjectionData3DMemory(pppGeometry, pCustom)
+ else:
+ pDataObject3D = <CFloat32Data3DMemory * > new CFloat32ProjectionData3DMemory(pppGeometry)
else:
raise Exception("Invalid datatype. Please specify '-vol' or '-proj3d'.")
@@ -102,7 +130,7 @@ def create(datatype,geometry,data=None):
del pDataObject3D
raise Exception("Couldn't initialize data object.")
- fillDataObject(pDataObject3D, data)
+ if not link: fillDataObject(pDataObject3D, data)
pDataObject3D.updateStatistics()
@@ -122,6 +150,61 @@ def get_geometry(i):
raise Exception("Not a known data object")
return geom
+def change_geometry(i, geom):
+ cdef CFloat32Data3DMemory * pDataObject = dynamic_cast_mem(getObject(i))
+ cdef CFloat32ProjectionData3DMemory * pDataObject2
+ cdef CFloat32VolumeData3DMemory * pDataObject3
+ if pDataObject.getType() == THREEPROJECTION:
+ pDataObject2 = <CFloat32ProjectionData3DMemory * >pDataObject
+ # TODO: Reduce code duplication here
+ cfg = utils.dictToConfig(six.b('ProjectionGeometry'), geom)
+ tpe = wrap_from_bytes(cfg.self.getAttribute(six.b('type')))
+ if (tpe == "parallel3d"):
+ ppGeometry = <CProjectionGeometry3D*> new CParallelProjectionGeometry3D();
+ elif (tpe == "parallel3d_vec"):
+ ppGeometry = <CProjectionGeometry3D*> new CParallelVecProjectionGeometry3D();
+ elif (tpe == "cone"):
+ ppGeometry = <CProjectionGeometry3D*> new CConeProjectionGeometry3D();
+ elif (tpe == "cone_vec"):
+ ppGeometry = <CProjectionGeometry3D*> new CConeVecProjectionGeometry3D();
+ else:
+ raise Exception("Invalid geometry type.")
+ if not ppGeometry.initialize(cfg[0]):
+ del cfg
+ del ppGeometry
+ raise Exception('Geometry class not initialized.')
+ del cfg
+ if (ppGeometry.getDetectorColCount() != pDataObject2.getDetectorColCount() or \
+ ppGeometry.getProjectionCount() != pDataObject2.getAngleCount() or \
+ ppGeometry.getDetectorRowCount() != pDataObject2.getDetectorRowCount()):
+ del ppGeometry
+ raise Exception(
+ "The dimensions of the data do not match those specified in the geometry.")
+ pDataObject2.changeGeometry(ppGeometry)
+ del ppGeometry
+
+ elif pDataObject.getType() == THREEVOLUME:
+ pDataObject3 = <CFloat32VolumeData3DMemory * >pDataObject
+ cfg = utils.dictToConfig(six.b('VolumeGeometry'), geom)
+ pGeometry = new CVolumeGeometry3D()
+ if not pGeometry.initialize(cfg[0]):
+ del cfg
+ del pGeometry
+ raise Exception('Geometry class not initialized.')
+ del cfg
+ if (pGeometry.getGridColCount() != pDataObject3.getColCount() or \
+ pGeometry.getGridRowCount() != pDataObject3.getRowCount() or \
+ pGeometry.getGridSliceCount() != pDataObject3.getSliceCount()):
+ del pGeometry
+ raise Exception(
+ "The dimensions of the data do not match those specified in the geometry.")
+ pDataObject3.changeGeometry(pGeometry)
+ del pGeometry
+
+ else:
+ raise Exception("Not a known data object")
+
+
cdef fillDataObject(CFloat32Data3DMemory * obj, data):
if data is None:
fillDataObjectScalar(obj, 0)
diff --git a/python/astra/functions.py b/python/astra/functions.py
index 4025468..b826b86 100644
--- a/python/astra/functions.py
+++ b/python/astra/functions.py
@@ -38,6 +38,7 @@ from . import data2d
from . import data3d
from . import projector
from . import algorithm
+from . import pythonutils
@@ -158,29 +159,7 @@ def geom_size(geom, dim=None):
:param dim: Optional axis index to return
:type dim: :class:`int`
"""
-
- if 'GridSliceCount' in geom:
- # 3D Volume geometry?
- s = (geom['GridSliceCount'], geom[
- 'GridRowCount'], geom['GridColCount'])
- elif 'GridColCount' in geom:
- # 2D Volume geometry?
- s = (geom['GridRowCount'], geom['GridColCount'])
- elif geom['type'] == 'parallel' or geom['type'] == 'fanflat':
- s = (len(geom['ProjectionAngles']), geom['DetectorCount'])
- elif geom['type'] == 'parallel3d' or geom['type'] == 'cone':
- s = (geom['DetectorRowCount'], len(
- geom['ProjectionAngles']), geom['DetectorColCount'])
- elif geom['type'] == 'fanflat_vec':
- s = (geom['Vectors'].shape[0], geom['DetectorCount'])
- elif geom['type'] == 'parallel3d_vec' or geom['type'] == 'cone_vec':
- s = (geom['DetectorRowCount'], geom[
- 'Vectors'].shape[0], geom['DetectorColCount'])
-
- if dim != None:
- s = s[dim]
-
- return s
+ return pythonutils.geom_size(geom,dim)
def geom_2vec(proj_geom):
diff --git a/python/astra/optomo.py b/python/astra/optomo.py
new file mode 100644
index 0000000..0c37353
--- /dev/null
+++ b/python/astra/optomo.py
@@ -0,0 +1,197 @@
+#-----------------------------------------------------------------------
+#Copyright 2013 Centrum Wiskunde & Informatica, Amsterdam
+#
+#Author: Daniel M. Pelt
+#Contact: D.M.Pelt@cwi.nl
+#Website: http://dmpelt.github.io/pyastratoolbox/
+#
+#
+#This file is part of the Python interface to the
+#All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA Toolbox").
+#
+#The Python interface to the ASTRA Toolbox is free software: you can redistribute it and/or modify
+#it under the terms of the GNU General Public License as published by
+#the Free Software Foundation, either version 3 of the License, or
+#(at your option) any later version.
+#
+#The Python interface to the ASTRA Toolbox 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 General Public License for more details.
+#
+#You should have received a copy of the GNU General Public License
+#along with the Python interface to the ASTRA Toolbox. If not, see <http://www.gnu.org/licenses/>.
+#
+#-----------------------------------------------------------------------
+
+from . import data2d
+from . import data3d
+from . import projector
+from . import projector3d
+from . import creators
+from . import algorithm
+from . import functions
+import numpy as np
+from six.moves import range, reduce
+import operator
+import scipy.sparse.linalg
+
+class OpTomo(scipy.sparse.linalg.LinearOperator):
+ """Object that imitates a projection matrix with a given projector.
+
+ This object can do forward projection by using the ``*`` operator::
+
+ W = astra.OpTomo(proj_id)
+ fp = W*image
+ bp = W.T*sinogram
+
+ It can also be used in minimization methods of the :mod:`scipy.sparse.linalg` module::
+
+ W = astra.OpTomo(proj_id)
+ output = scipy.sparse.linalg.lsqr(W,sinogram)
+
+ :param proj_id: ID to a projector.
+ :type proj_id: :class:`int`
+ """
+
+ def __init__(self,proj_id):
+ self.dtype = np.float32
+ try:
+ self.vg = projector.volume_geometry(proj_id)
+ self.pg = projector.projection_geometry(proj_id)
+ self.data_mod = data2d
+ self.appendString = ""
+ if projector.is_cuda(proj_id):
+ self.appendString += "_CUDA"
+ except Exception:
+ self.vg = projector3d.volume_geometry(proj_id)
+ self.pg = projector3d.projection_geometry(proj_id)
+ self.data_mod = data3d
+ self.appendString = "3D"
+ if projector3d.is_cuda(proj_id):
+ self.appendString += "_CUDA"
+
+ self.vshape = functions.geom_size(self.vg)
+ self.vsize = reduce(operator.mul,self.vshape)
+ self.sshape = functions.geom_size(self.pg)
+ self.ssize = reduce(operator.mul,self.sshape)
+
+ self.shape = (self.ssize, self.vsize)
+
+ self.proj_id = proj_id
+
+ self.T = OpTomoTranspose(self)
+
+ def __checkArray(self, arr, shp):
+ if len(arr.shape)==1:
+ arr = arr.reshape(shp)
+ if arr.dtype != np.float32:
+ arr = arr.astype(np.float32)
+ if arr.flags['C_CONTIGUOUS']==False:
+ arr = np.ascontiguousarray(arr)
+ return arr
+
+ def _matvec(self,v):
+ """Implements the forward operator.
+
+ :param v: Volume to forward project.
+ :type v: :class:`numpy.ndarray`
+ """
+ v = self.__checkArray(v, self.vshape)
+ vid = self.data_mod.link('-vol',self.vg,v)
+ s = np.zeros(self.sshape,dtype=np.float32)
+ sid = self.data_mod.link('-sino',self.pg,s)
+
+ cfg = creators.astra_dict('FP'+self.appendString)
+ cfg['ProjectionDataId'] = sid
+ cfg['VolumeDataId'] = vid
+ cfg['ProjectorId'] = self.proj_id
+ fp_id = algorithm.create(cfg)
+ algorithm.run(fp_id)
+
+ algorithm.delete(fp_id)
+ self.data_mod.delete([vid,sid])
+ return s.flatten()
+
+ def rmatvec(self,s):
+ """Implements the transpose operator.
+
+ :param s: The projection data.
+ :type s: :class:`numpy.ndarray`
+ """
+ s = self.__checkArray(s, self.sshape)
+ sid = self.data_mod.link('-sino',self.pg,s)
+ v = np.zeros(self.vshape,dtype=np.float32)
+ vid = self.data_mod.link('-vol',self.vg,v)
+
+ cfg = creators.astra_dict('BP'+self.appendString)
+ cfg['ProjectionDataId'] = sid
+ cfg['ReconstructionDataId'] = vid
+ cfg['ProjectorId'] = self.proj_id
+ bp_id = algorithm.create(cfg)
+ algorithm.run(bp_id)
+
+ algorithm.delete(bp_id)
+ self.data_mod.delete([vid,sid])
+ return v.flatten()
+
+ def __mul__(self,v):
+ """Provides easy forward operator by *.
+
+ :param v: Volume to forward project.
+ :type v: :class:`numpy.ndarray`
+ """
+ # Catch the case of a forward projection of a 2D/3D image
+ if isinstance(v, np.ndarray) and v.shape==self.vshape:
+ return self._matvec(v)
+ return scipy.sparse.linalg.LinearOperator.__mul__(self, v)
+
+ def reconstruct(self, method, s, iterations=1, extraOptions = {}):
+ """Reconstruct an object.
+
+ :param method: Method to use for reconstruction.
+ :type method: :class:`string`
+ :param s: The projection data.
+ :type s: :class:`numpy.ndarray`
+ :param iterations: Number of iterations to use.
+ :type iterations: :class:`int`
+ :param extraOptions: Extra options to use during reconstruction (i.e. for cfg['option']).
+ :type extraOptions: :class:`dict`
+ """
+ self.__checkArray(s, self.sshape)
+ sid = self.data_mod.link('-sino',self.pg,s)
+ v = np.zeros(self.vshape,dtype=np.float32)
+ vid = self.data_mod.link('-vol',self.vg,v)
+ cfg = creators.astra_dict(method)
+ cfg['ProjectionDataId'] = sid
+ cfg['ReconstructionDataId'] = vid
+ cfg['ProjectorId'] = self.proj_id
+ cfg['option'] = extraOptions
+ alg_id = algorithm.create(cfg)
+ algorithm.run(alg_id,iterations)
+ algorithm.delete(alg_id)
+ self.data_mod.delete([vid,sid])
+ return v
+
+class OpTomoTranspose(scipy.sparse.linalg.LinearOperator):
+ """This object provides the transpose operation (``.T``) of the OpTomo object.
+
+ Do not use directly, since it can be accessed as member ``.T`` of
+ an :class:`OpTomo` object.
+ """
+ def __init__(self,parent):
+ self.parent = parent
+ self.dtype = np.float32
+ self.shape = (parent.shape[1], parent.shape[0])
+
+ def _matvec(self, s):
+ return self.parent.rmatvec(s)
+
+ def rmatvec(self, v):
+ return self.parent.matvec(v)
+
+ def __mul__(self,s):
+ # Catch the case of a backprojection of 2D/3D data
+ if isinstance(s, np.ndarray) and s.shape==self.parent.sshape:
+ return self._matvec(s)
+ return scipy.sparse.linalg.LinearOperator.__mul__(self, s)
diff --git a/python/astra/pythonutils.py b/python/astra/pythonutils.py
new file mode 100644
index 0000000..8ea4af5
--- /dev/null
+++ b/python/astra/pythonutils.py
@@ -0,0 +1,63 @@
+#-----------------------------------------------------------------------
+# Copyright 2013 Centrum Wiskunde & Informatica, Amsterdam
+#
+# Author: Daniel M. Pelt
+# Contact: D.M.Pelt@cwi.nl
+# Website: http://dmpelt.github.io/pyastratoolbox/
+#
+#
+# This file is part of the Python interface to the
+# All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA Toolbox").
+#
+# The Python interface to the ASTRA Toolbox is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+#(at your option) any later version.
+#
+# The Python interface to the ASTRA Toolbox 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with the Python interface to the ASTRA Toolbox. If not, see <http://www.gnu.org/licenses/>.
+#
+#-----------------------------------------------------------------------
+"""Additional purely Python functions for PyAstraToolbox.
+
+.. moduleauthor:: Daniel M. Pelt <D.M.Pelt@cwi.nl>
+
+
+"""
+
+def geom_size(geom, dim=None):
+ """Returns the size of a volume or sinogram, based on the projection or volume geometry.
+
+ :param geom: Geometry to calculate size from
+ :type geometry: :class:`dict`
+ :param dim: Optional axis index to return
+ :type dim: :class:`int`
+ """
+
+ if 'GridSliceCount' in geom:
+ # 3D Volume geometry?
+ s = (geom['GridSliceCount'], geom[
+ 'GridRowCount'], geom['GridColCount'])
+ elif 'GridColCount' in geom:
+ # 2D Volume geometry?
+ s = (geom['GridRowCount'], geom['GridColCount'])
+ elif geom['type'] == 'parallel' or geom['type'] == 'fanflat':
+ s = (len(geom['ProjectionAngles']), geom['DetectorCount'])
+ elif geom['type'] == 'parallel3d' or geom['type'] == 'cone':
+ s = (geom['DetectorRowCount'], len(
+ geom['ProjectionAngles']), geom['DetectorColCount'])
+ elif geom['type'] == 'fanflat_vec':
+ s = (geom['Vectors'].shape[0], geom['DetectorCount'])
+ elif geom['type'] == 'parallel3d_vec' or geom['type'] == 'cone_vec':
+ s = (geom['DetectorRowCount'], geom[
+ 'Vectors'].shape[0], geom['DetectorColCount'])
+
+ if dim != None:
+ s = s[dim]
+
+ return s
diff --git a/python/astra/utils.pyx b/python/astra/utils.pyx
index 0439f1b..ddb37aa 100644
--- a/python/astra/utils.pyx
+++ b/python/astra/utils.pyx
@@ -26,6 +26,7 @@
# distutils: language = c++
# distutils: libraries = astra
+cimport numpy as np
import numpy as np
import six
from libcpp.string cimport string
@@ -80,11 +81,12 @@ def wrap_from_bytes(value):
return s
-cdef void readDict(XMLNode * root, _dc):
- cdef XMLNode * listbase
- cdef XMLNode * itm
+cdef void readDict(XMLNode root, _dc):
+ cdef XMLNode listbase
+ cdef XMLNode itm
cdef int i
cdef int j
+ cdef double* data
dc = convert_item(_dc)
for item in dc:
@@ -93,45 +95,31 @@ cdef void readDict(XMLNode * root, _dc):
if val.size == 0:
break
listbase = root.addChildNode(item)
- listbase.addAttribute(< string > six.b('listsize'), < float32 > val.size)
- index = 0
+ data = <double*>np.PyArray_DATA(np.ascontiguousarray(val,dtype=np.float64))
if val.ndim == 2:
- for i in range(val.shape[0]):
- for j in range(val.shape[1]):
- itm = listbase.addChildNode(six.b('ListItem'))
- itm.addAttribute(< string > six.b('index'), < float32 > index)
- itm.addAttribute( < string > six.b('value'), < float32 > val[i, j])
- index += 1
- del itm
+ listbase.setContent(data, val.shape[1], val.shape[0], False)
elif val.ndim == 1:
- for i in range(val.shape[0]):
- itm = listbase.addChildNode(six.b('ListItem'))
- itm.addAttribute(< string > six.b('index'), < float32 > index)
- itm.addAttribute(< string > six.b('value'), < float32 > val[i])
- index += 1
- del itm
+ listbase.setContent(data, val.shape[0])
else:
raise Exception("Only 1 or 2 dimensions are allowed")
- del listbase
elif isinstance(val, dict):
if item == six.b('option') or item == six.b('options') or item == six.b('Option') or item == six.b('Options'):
readOptions(root, val)
else:
itm = root.addChildNode(item)
readDict(itm, val)
- del itm
else:
if item == six.b('type'):
root.addAttribute(< string > six.b('type'), <string> wrap_to_bytes(val))
else:
itm = root.addChildNode(item, wrap_to_bytes(val))
- del itm
-cdef void readOptions(XMLNode * node, dc):
- cdef XMLNode * listbase
- cdef XMLNode * itm
+cdef void readOptions(XMLNode node, dc):
+ cdef XMLNode listbase
+ cdef XMLNode itm
cdef int i
cdef int j
+ cdef double* data
for item in dc:
val = dc[item]
if node.hasOption(item):
@@ -141,26 +129,13 @@ cdef void readOptions(XMLNode * node, dc):
break
listbase = node.addChildNode(six.b('Option'))
listbase.addAttribute(< string > six.b('key'), < string > item)
- listbase.addAttribute(< string > six.b('listsize'), < float32 > val.size)
- index = 0
+ data = <double*>np.PyArray_DATA(np.ascontiguousarray(val,dtype=np.float64))
if val.ndim == 2:
- for i in range(val.shape[0]):
- for j in range(val.shape[1]):
- itm = listbase.addChildNode(six.b('ListItem'))
- itm.addAttribute(< string > six.b('index'), < float32 > index)
- itm.addAttribute( < string > six.b('value'), < float32 > val[i, j])
- index += 1
- del itm
+ listbase.setContent(data, val.shape[1], val.shape[0], False)
elif val.ndim == 1:
- for i in range(val.shape[0]):
- itm = listbase.addChildNode(six.b('ListItem'))
- itm.addAttribute(< string > six.b('index'), < float32 > index)
- itm.addAttribute(< string > six.b('value'), < float32 > val[i])
- index += 1
- del itm
+ listbase.setContent(data, val.shape[0])
else:
raise Exception("Only 1 or 2 dimensions are allowed")
- del listbase
else:
node.addOption(item, wrap_to_bytes(val))
@@ -214,10 +189,10 @@ def stringToPythonValue(inputIn):
return str(input)
-cdef XMLNode2dict(XMLNode * node):
- cdef XMLNode * subnode
- cdef list[XMLNode * ] nodes
- cdef list[XMLNode * ].iterator it
+cdef XMLNode2dict(XMLNode node):
+ cdef XMLNode subnode
+ cdef list[XMLNode] nodes
+ cdef list[XMLNode].iterator it
dct = {}
opts = {}
if node.hasAttribute(six.b('type')):
@@ -230,7 +205,6 @@ cdef XMLNode2dict(XMLNode * node):
opts[castString(subnode.getAttribute('key'))] = stringToPythonValue(subnode.getAttribute('value'))
else:
dct[castString(subnode.getName())] = stringToPythonValue(subnode.getContent())
- del subnode
inc(it)
if len(opts)>0: dct['options'] = opts
return dct
diff --git a/python/docSRC/index.rst b/python/docSRC/index.rst
index 8d17a4a..b7cc6d6 100644
--- a/python/docSRC/index.rst
+++ b/python/docSRC/index.rst
@@ -18,7 +18,7 @@ Contents:
matrix
creators
functions
- ASTRAProjector
+ operator
matlab
astra
.. astra
diff --git a/python/docSRC/ASTRAProjector.rst b/python/docSRC/operator.rst
index 1c267e3..f5369fa 100644
--- a/python/docSRC/ASTRAProjector.rst
+++ b/python/docSRC/operator.rst
@@ -1,7 +1,7 @@
-Helper class: the :mod:`ASTRAProjector` module
+OpTomo class: the :mod:`operator` module
==============================================
-.. automodule:: astra.ASTRAProjector
+.. automodule:: astra.operator
:members:
:undoc-members:
:show-inheritance:
diff --git a/src/ArtAlgorithm.cpp b/src/ArtAlgorithm.cpp
index 8f058a3..6a699ec 100644
--- a/src/ArtAlgorithm.cpp
+++ b/src/ArtAlgorithm.cpp
@@ -132,7 +132,7 @@ bool CArtAlgorithm::initialize(const Config& _cfg)
}
// ray order
- string projOrder = _cfg.self->getOption("RayOrder", "sequential");
+ string projOrder = _cfg.self.getOption("RayOrder", "sequential");
CC.markOptionParsed("RayOrder");
m_iCurrentRay = 0;
m_iRayCount = m_pProjector->getProjectionGeometry()->getProjectionAngleCount() *
@@ -145,7 +145,7 @@ bool CArtAlgorithm::initialize(const Config& _cfg)
m_piDetectorOrder[i] = i % m_pProjector->getProjectionGeometry()->getDetectorCount();
}
} else if (projOrder == "custom") {
- vector<float32> rayOrderList = _cfg.self->getOptionNumericalArray("RayOrderList");
+ vector<float32> rayOrderList = _cfg.self.getOptionNumericalArray("RayOrderList");
m_iRayCount = rayOrderList.size() / 2;
m_piProjectionOrder = new int[m_iRayCount];
m_piDetectorOrder = new int[m_iRayCount];
@@ -158,7 +158,7 @@ bool CArtAlgorithm::initialize(const Config& _cfg)
return false;
}
- m_fLambda = _cfg.self->getOptionNumerical("Lambda", 1.0f);
+ m_fLambda = _cfg.self.getOptionNumerical("Lambda", 1.0f);
CC.markOptionParsed("Lambda");
// success
diff --git a/src/ConeProjectionGeometry3D.cpp b/src/ConeProjectionGeometry3D.cpp
index 1976901..dd22eba 100644
--- a/src/ConeProjectionGeometry3D.cpp
+++ b/src/ConeProjectionGeometry3D.cpp
@@ -87,17 +87,15 @@ bool CConeProjectionGeometry3D::initialize(const Config& _cfg)
CProjectionGeometry3D::initialize(_cfg);
// Required: DistanceOriginDetector
- XMLNode* node = _cfg.self->getSingleNode("DistanceOriginDetector");
+ XMLNode node = _cfg.self.getSingleNode("DistanceOriginDetector");
ASTRA_CONFIG_CHECK(node, "ConeProjectionGeometry3D", "No DistanceOriginDetector tag specified.");
- m_fOriginDetectorDistance = boost::lexical_cast<float32>(node->getContent());
- ASTRA_DELETE(node);
+ m_fOriginDetectorDistance = boost::lexical_cast<float32>(node.getContent());
CC.markNodeParsed("DistanceOriginDetector");
// Required: DetectorOriginSource
- node = _cfg.self->getSingleNode("DistanceOriginSource");
+ node = _cfg.self.getSingleNode("DistanceOriginSource");
ASTRA_CONFIG_CHECK(node, "ConeProjectionGeometry3D", "No DistanceOriginSource tag specified.");
- m_fOriginSourceDistance = boost::lexical_cast<float32>(node->getContent());
- ASTRA_DELETE(node);
+ m_fOriginSourceDistance = boost::lexical_cast<float32>(node.getContent());
CC.markNodeParsed("DistanceOriginSource");
// success
@@ -193,14 +191,14 @@ Config* CConeProjectionGeometry3D::getConfiguration() const
{
Config* cfg = new Config();
cfg->initialize("ProjectionGeometry3D");
- cfg->self->addAttribute("type", "cone");
- cfg->self->addChildNode("DetectorSpacingX", m_fDetectorSpacingX);
- cfg->self->addChildNode("DetectorSpacingY", m_fDetectorSpacingY);
- cfg->self->addChildNode("DetectorRowCount", m_iDetectorRowCount);
- cfg->self->addChildNode("DetectorColCount", m_iDetectorColCount);
- cfg->self->addChildNode("DistanceOriginDetector", m_fOriginDetectorDistance);
- cfg->self->addChildNode("DistanceOriginSource", m_fOriginSourceDistance);
- cfg->self->addChildNode("ProjectionAngles", m_pfProjectionAngles, m_iProjectionAngleCount);
+ cfg->self.addAttribute("type", "cone");
+ cfg->self.addChildNode("DetectorSpacingX", m_fDetectorSpacingX);
+ cfg->self.addChildNode("DetectorSpacingY", m_fDetectorSpacingY);
+ cfg->self.addChildNode("DetectorRowCount", m_iDetectorRowCount);
+ cfg->self.addChildNode("DetectorColCount", m_iDetectorColCount);
+ cfg->self.addChildNode("DistanceOriginDetector", m_fOriginDetectorDistance);
+ cfg->self.addChildNode("DistanceOriginSource", m_fOriginSourceDistance);
+ cfg->self.addChildNode("ProjectionAngles", m_pfProjectionAngles, m_iProjectionAngleCount);
return cfg;
}
diff --git a/src/ConeVecProjectionGeometry3D.cpp b/src/ConeVecProjectionGeometry3D.cpp
index 9dc273d..47ed630 100644
--- a/src/ConeVecProjectionGeometry3D.cpp
+++ b/src/ConeVecProjectionGeometry3D.cpp
@@ -73,33 +73,30 @@ bool CConeVecProjectionGeometry3D::initialize(const Config& _cfg)
ASTRA_ASSERT(_cfg.self);
ConfigStackCheck<CProjectionGeometry3D> CC("ConeVecProjectionGeometry3D", this, _cfg);
- XMLNode* node;
+ XMLNode node;
// TODO: Fix up class hierarchy... this class doesn't fit very well.
// initialization of parent class
//CProjectionGeometry3D::initialize(_cfg);
// Required: DetectorRowCount
- node = _cfg.self->getSingleNode("DetectorRowCount");
+ node = _cfg.self.getSingleNode("DetectorRowCount");
ASTRA_CONFIG_CHECK(node, "ConeVecProjectionGeometry3D", "No DetectorRowCount tag specified.");
- m_iDetectorRowCount = boost::lexical_cast<int>(node->getContent());
- ASTRA_DELETE(node);
+ m_iDetectorRowCount = boost::lexical_cast<int>(node.getContent());
CC.markNodeParsed("DetectorRowCount");
// Required: DetectorColCount
- node = _cfg.self->getSingleNode("DetectorColCount");
+ node = _cfg.self.getSingleNode("DetectorColCount");
ASTRA_CONFIG_CHECK(node, "ConeVecProjectionGeometry3D", "No DetectorColCount tag specified.");
- m_iDetectorColCount = boost::lexical_cast<int>(node->getContent());
+ m_iDetectorColCount = boost::lexical_cast<int>(node.getContent());
m_iDetectorTotCount = m_iDetectorRowCount * m_iDetectorColCount;
- ASTRA_DELETE(node);
CC.markNodeParsed("DetectorColCount");
// Required: Vectors
- node = _cfg.self->getSingleNode("Vectors");
+ node = _cfg.self.getSingleNode("Vectors");
ASTRA_CONFIG_CHECK(node, "ConeVecProjectionGeometry3D", "No Vectors tag specified.");
- vector<double> data = node->getContentNumericalArrayDouble();
+ vector<double> data = node.getContentNumericalArrayDouble();
CC.markNodeParsed("Vectors");
- ASTRA_DELETE(node);
ASTRA_CONFIG_CHECK(data.size() % 12 == 0, "ConeVecProjectionGeometry3D", "Vectors doesn't consist of 12-tuples.");
m_iProjectionAngleCount = data.size() / 12;
m_pProjectionAngles = new SConeProjection[m_iProjectionAngleCount];
@@ -208,9 +205,9 @@ Config* CConeVecProjectionGeometry3D::getConfiguration() const
Config* cfg = new Config();
cfg->initialize("ProjectionGeometry3D");
- cfg->self->addAttribute("type", "cone_vec");
- cfg->self->addChildNode("DetectorRowCount", m_iDetectorRowCount);
- cfg->self->addChildNode("DetectorColCount", m_iDetectorColCount);
+ cfg->self.addAttribute("type", "cone_vec");
+ cfg->self.addChildNode("DetectorRowCount", m_iDetectorRowCount);
+ cfg->self.addChildNode("DetectorColCount", m_iDetectorColCount);
std::string vectors = "";
for (int i = 0; i < m_iProjectionAngleCount; ++i) {
@@ -229,7 +226,7 @@ Config* CConeVecProjectionGeometry3D::getConfiguration() const
vectors += boost::lexical_cast<string>(p.fDetVZ);
if (i < m_iProjectionAngleCount-1) vectors += ';';
}
- cfg->self->addChildNode("Vectors", vectors);
+ cfg->self.addChildNode("Vectors", vectors);
return cfg;
}
diff --git a/src/Config.cpp b/src/Config.cpp
index d860638..395080b 100644
--- a/src/Config.cpp
+++ b/src/Config.cpp
@@ -45,31 +45,33 @@ using namespace std;
//-----------------------------------------------------------------------------
// default constructor
-Config::Config()
+Config::Config() : self()
{
- self = 0;
+ _doc = 0;
}
//-----------------------------------------------------------------------------
// not so default constructor
-Config::Config(XMLNode* _self)
+Config::Config(XMLNode _self)
{
self = _self;
+ _doc = 0;
}
//-----------------------------------------------------------------------------
Config::~Config()
{
- delete self;
- self = 0;
+ delete _doc;
+ _doc = 0;
}
//-----------------------------------------------------------------------------
void Config::initialize(std::string rootname)
{
- if (self == 0) {
+ if (!self) {
XMLDocument* doc = XMLDocument::createDocument(rootname);
self = doc->getRootNode();
+ _doc = doc;
}
}
@@ -124,13 +126,13 @@ bool ConfigStackCheck<T>::stopParsing()
std::string errors;
- std::list<XMLNode*> nodes = cfg->self->getNodes();
- for (std::list<XMLNode*>::iterator i = nodes.begin(); i != nodes.end(); ++i)
+ std::list<XMLNode> nodes = cfg->self.getNodes();
+ for (std::list<XMLNode>::iterator i = nodes.begin(); i != nodes.end(); ++i)
{
- std::string nodeName = (*i)->getName();
+ std::string nodeName = i->getName();
if (nodeName == "Option") {
- nodeName = (*i)->getAttribute("key", "");
+ nodeName = i->getAttribute("key", "");
if (object->configCheckData->parsedOptions.find(nodeName) == object->configCheckData->parsedOptions.end()) {
if (!errors.empty()) errors += ", ";
errors += nodeName;
@@ -142,8 +144,6 @@ bool ConfigStackCheck<T>::stopParsing()
}
}
}
- for (std::list<XMLNode*>::iterator i = nodes.begin(); i != nodes.end(); ++i)
- delete (*i);
nodes.clear();
if (!errors.empty()) {
diff --git a/src/CudaBackProjectionAlgorithm3D.cpp b/src/CudaBackProjectionAlgorithm3D.cpp
index abcf096..fbb8f28 100644
--- a/src/CudaBackProjectionAlgorithm3D.cpp
+++ b/src/CudaBackProjectionAlgorithm3D.cpp
@@ -102,9 +102,9 @@ bool CCudaBackProjectionAlgorithm3D::initialize(const Config& _cfg)
return false;
}
- m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUindex", -1);
+ m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1);
CC.markOptionParsed("GPUindex");
- m_iVoxelSuperSampling = (int)_cfg.self->getOptionNumerical("VoxelSuperSampling", 1);
+ m_iVoxelSuperSampling = (int)_cfg.self.getOptionNumerical("VoxelSuperSampling", 1);
CC.markOptionParsed("VoxelSuperSampling");
CFloat32ProjectionData3DMemory* pSinoMem = dynamic_cast<CFloat32ProjectionData3DMemory*>(m_pSinogram);
@@ -114,7 +114,7 @@ const CParallelProjectionGeometry3D* par3dgeom = dynamic_cast<const CParallelPro
const CParallelVecProjectionGeometry3D* parvec3dgeom = dynamic_cast<const CParallelVecProjectionGeometry3D*>(projgeom);
if (parvec3dgeom || par3dgeom) {
// This option is only supported for Par3D currently
- m_bSIRTWeighting = _cfg.self->getOptionBool("SIRTWeighting", false);
+ m_bSIRTWeighting = _cfg.self.getOptionBool("SIRTWeighting", false);
CC.markOptionParsed("SIRTWeighting");
}
diff --git a/src/CudaCglsAlgorithm3D.cpp b/src/CudaCglsAlgorithm3D.cpp
index a5500d6..3457b81 100644
--- a/src/CudaCglsAlgorithm3D.cpp
+++ b/src/CudaCglsAlgorithm3D.cpp
@@ -106,11 +106,11 @@ bool CCudaCglsAlgorithm3D::initialize(const Config& _cfg)
return false;
}
- m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUindex", -1);
+ m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1);
CC.markOptionParsed("GPUindex");
- m_iDetectorSuperSampling = (int)_cfg.self->getOptionNumerical("DetectorSuperSampling", 1);
+ m_iDetectorSuperSampling = (int)_cfg.self.getOptionNumerical("DetectorSuperSampling", 1);
CC.markOptionParsed("DetectorSuperSampling");
- m_iVoxelSuperSampling = (int)_cfg.self->getOptionNumerical("VoxelSuperSampling", 1);
+ m_iVoxelSuperSampling = (int)_cfg.self.getOptionNumerical("VoxelSuperSampling", 1);
CC.markOptionParsed("VoxelSuperSampling");
m_pCgls = new AstraCGLS3d();
diff --git a/src/CudaDartMaskAlgorithm.cpp b/src/CudaDartMaskAlgorithm.cpp
index dcdefcc..950b428 100644
--- a/src/CudaDartMaskAlgorithm.cpp
+++ b/src/CudaDartMaskAlgorithm.cpp
@@ -65,38 +65,36 @@ bool CCudaDartMaskAlgorithm::initialize(const Config& _cfg)
ConfigStackCheck<CAlgorithm> CC("CudaDartMaskAlgorithm", this, _cfg);
// reconstruction data
- XMLNode* node = _cfg.self->getSingleNode("SegmentationDataId");
+ XMLNode node = _cfg.self.getSingleNode("SegmentationDataId");
ASTRA_CONFIG_CHECK(node, "CudaDartMask", "No SegmentationDataId tag specified.");
- int id = boost::lexical_cast<int>(node->getContent());
+ int id = boost::lexical_cast<int>(node.getContent());
m_pSegmentation = dynamic_cast<CFloat32VolumeData2D*>(CData2DManager::getSingleton().get(id));
- ASTRA_DELETE(node);
CC.markNodeParsed("SegmentationDataId");
// reconstruction data
- node = _cfg.self->getSingleNode("MaskDataId");
+ node = _cfg.self.getSingleNode("MaskDataId");
ASTRA_CONFIG_CHECK(node, "CudaDartMask", "No MaskDataId tag specified.");
- id = boost::lexical_cast<int>(node->getContent());
+ id = boost::lexical_cast<int>(node.getContent());
m_pMask = dynamic_cast<CFloat32VolumeData2D*>(CData2DManager::getSingleton().get(id));
- ASTRA_DELETE(node);
CC.markNodeParsed("MaskDataId");
// Option: GPU number
- m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUindex", -1);
- m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUIndex", m_iGPUIndex);
+ m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1);
+ m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUIndex", m_iGPUIndex);
CC.markOptionParsed("GPUindex");
- if (!_cfg.self->hasOption("GPUindex"))
+ if (!_cfg.self.hasOption("GPUindex"))
CC.markOptionParsed("GPUIndex");
// Option: Connectivity
- m_iConn = (unsigned int)_cfg.self->getOptionNumerical("Connectivity", 8);
+ m_iConn = (unsigned int)_cfg.self.getOptionNumerical("Connectivity", 8);
CC.markOptionParsed("Connectivity");
// Option: Threshold
- m_iThreshold = (unsigned int)_cfg.self->getOptionNumerical("Threshold", 1);
+ m_iThreshold = (unsigned int)_cfg.self.getOptionNumerical("Threshold", 1);
CC.markOptionParsed("Threshold");
// Option: Radius
- m_iRadius = (unsigned int)_cfg.self->getOptionNumerical("Radius", 1);
+ m_iRadius = (unsigned int)_cfg.self.getOptionNumerical("Radius", 1);
CC.markOptionParsed("Radius");
_check();
diff --git a/src/CudaDartMaskAlgorithm3D.cpp b/src/CudaDartMaskAlgorithm3D.cpp
index f3500b9..b0dfc5b 100644
--- a/src/CudaDartMaskAlgorithm3D.cpp
+++ b/src/CudaDartMaskAlgorithm3D.cpp
@@ -65,38 +65,36 @@ bool CCudaDartMaskAlgorithm3D::initialize(const Config& _cfg)
ConfigStackCheck<CAlgorithm> CC("CudaDartMaskAlgorithm", this, _cfg);
// reconstruction data
- XMLNode* node = _cfg.self->getSingleNode("SegmentationDataId");
+ XMLNode node = _cfg.self.getSingleNode("SegmentationDataId");
ASTRA_CONFIG_CHECK(node, "CudaDartMask", "No SegmentationDataId tag specified.");
- int id = boost::lexical_cast<int>(node->getContent());
+ int id = boost::lexical_cast<int>(node.getContent());
m_pSegmentation = dynamic_cast<CFloat32VolumeData3DMemory*>(CData3DManager::getSingleton().get(id));
- ASTRA_DELETE(node);
CC.markNodeParsed("SegmentationDataId");
// reconstruction data
- node = _cfg.self->getSingleNode("MaskDataId");
+ node = _cfg.self.getSingleNode("MaskDataId");
ASTRA_CONFIG_CHECK(node, "CudaDartMask", "No MaskDataId tag specified.");
- id = boost::lexical_cast<int>(node->getContent());
+ id = boost::lexical_cast<int>(node.getContent());
m_pMask = dynamic_cast<CFloat32VolumeData3DMemory*>(CData3DManager::getSingleton().get(id));
- ASTRA_DELETE(node);
CC.markNodeParsed("MaskDataId");
// Option: GPU number
- m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUindex", -1);
- m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUIndex", m_iGPUIndex);
+ m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1);
+ m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUIndex", m_iGPUIndex);
CC.markOptionParsed("GPUindex");
- if (!_cfg.self->hasOption("GPUindex"))
+ if (!_cfg.self.hasOption("GPUindex"))
CC.markOptionParsed("GPUIndex");
// Option: Connectivity
- m_iConn = (unsigned int)_cfg.self->getOptionNumerical("Connectivity", 8);
+ m_iConn = (unsigned int)_cfg.self.getOptionNumerical("Connectivity", 8);
CC.markOptionParsed("Connectivity");
// Option: Threshold
- m_iThreshold = (unsigned int)_cfg.self->getOptionNumerical("Threshold", 1);
+ m_iThreshold = (unsigned int)_cfg.self.getOptionNumerical("Threshold", 1);
CC.markOptionParsed("Threshold");
// Option: Radius
- m_iRadius = (unsigned int)_cfg.self->getOptionNumerical("Radius", 1);
+ m_iRadius = (unsigned int)_cfg.self.getOptionNumerical("Radius", 1);
CC.markOptionParsed("Radius");
_check();
diff --git a/src/CudaDartSmoothingAlgorithm.cpp b/src/CudaDartSmoothingAlgorithm.cpp
index 2f2103f..7e22809 100644
--- a/src/CudaDartSmoothingAlgorithm.cpp
+++ b/src/CudaDartSmoothingAlgorithm.cpp
@@ -65,34 +65,32 @@ bool CCudaDartSmoothingAlgorithm::initialize(const Config& _cfg)
ConfigStackCheck<CAlgorithm> CC("CudaDartSmoothingAlgorithm", this, _cfg);
// reconstruction data
- XMLNode* node = _cfg.self->getSingleNode("InDataId");
+ XMLNode node = _cfg.self.getSingleNode("InDataId");
ASTRA_CONFIG_CHECK(node, "CudaDartMask", "No InDataId tag specified.");
- int id = boost::lexical_cast<int>(node->getContent());
+ int id = boost::lexical_cast<int>(node.getContent());
m_pIn = dynamic_cast<CFloat32VolumeData2D*>(CData2DManager::getSingleton().get(id));
- ASTRA_DELETE(node);
CC.markNodeParsed("InDataId");
// reconstruction data
- node = _cfg.self->getSingleNode("OutDataId");
+ node = _cfg.self.getSingleNode("OutDataId");
ASTRA_CONFIG_CHECK(node, "CudaDartMask", "No OutDataId tag specified.");
- id = boost::lexical_cast<int>(node->getContent());
+ id = boost::lexical_cast<int>(node.getContent());
m_pOut = dynamic_cast<CFloat32VolumeData2D*>(CData2DManager::getSingleton().get(id));
- ASTRA_DELETE(node);
CC.markNodeParsed("OutDataId");
// Option: GPU number
- m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUindex", -1);
- m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUIndex", m_iGPUIndex);
+ m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1);
+ m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUIndex", m_iGPUIndex);
CC.markOptionParsed("GPUindex");
- if (!_cfg.self->hasOption("GPUindex"))
+ if (!_cfg.self.hasOption("GPUindex"))
CC.markOptionParsed("GPUIndex");
// Option: Radius
- m_fB = (float)_cfg.self->getOptionNumerical("Intensity", 0.3f);
+ m_fB = (float)_cfg.self.getOptionNumerical("Intensity", 0.3f);
CC.markOptionParsed("Intensity");
// Option: Radius
- m_iRadius = (unsigned int)_cfg.self->getOptionNumerical("Radius", 1);
+ m_iRadius = (unsigned int)_cfg.self.getOptionNumerical("Radius", 1);
CC.markOptionParsed("Radius");
diff --git a/src/CudaDartSmoothingAlgorithm3D.cpp b/src/CudaDartSmoothingAlgorithm3D.cpp
index f3cf015..9c4437a 100644
--- a/src/CudaDartSmoothingAlgorithm3D.cpp
+++ b/src/CudaDartSmoothingAlgorithm3D.cpp
@@ -65,34 +65,32 @@ bool CCudaDartSmoothingAlgorithm3D::initialize(const Config& _cfg)
ConfigStackCheck<CAlgorithm> CC("CudaDartSmoothingAlgorithm", this, _cfg);
// reconstruction data
- XMLNode* node = _cfg.self->getSingleNode("InDataId");
+ XMLNode node = _cfg.self.getSingleNode("InDataId");
ASTRA_CONFIG_CHECK(node, "CudaDartMask", "No InDataId tag specified.");
- int id = boost::lexical_cast<int>(node->getContent());
+ int id = boost::lexical_cast<int>(node.getContent());
m_pIn = dynamic_cast<CFloat32VolumeData3DMemory*>(CData3DManager::getSingleton().get(id));
- ASTRA_DELETE(node);
CC.markNodeParsed("InDataId");
// reconstruction data
- node = _cfg.self->getSingleNode("OutDataId");
+ node = _cfg.self.getSingleNode("OutDataId");
ASTRA_CONFIG_CHECK(node, "CudaDartMask", "No OutDataId tag specified.");
- id = boost::lexical_cast<int>(node->getContent());
+ id = boost::lexical_cast<int>(node.getContent());
m_pOut = dynamic_cast<CFloat32VolumeData3DMemory*>(CData3DManager::getSingleton().get(id));
- ASTRA_DELETE(node);
CC.markNodeParsed("OutDataId");
// Option: GPU number
- m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUindex", -1);
- m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUIndex", m_iGPUIndex);
+ m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1);
+ m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUIndex", m_iGPUIndex);
CC.markOptionParsed("GPUindex");
- if (!_cfg.self->hasOption("GPUindex"))
+ if (!_cfg.self.hasOption("GPUindex"))
CC.markOptionParsed("GPUIndex");
// Option: Intensity
- m_fB = (float)_cfg.self->getOptionNumerical("Intensity", 0.3f);
+ m_fB = (float)_cfg.self.getOptionNumerical("Intensity", 0.3f);
CC.markOptionParsed("Intensity");
// Option: Radius
- m_iRadius = (unsigned int)_cfg.self->getOptionNumerical("Radius", 1);
+ m_iRadius = (unsigned int)_cfg.self.getOptionNumerical("Radius", 1);
CC.markOptionParsed("Radius");
_check();
diff --git a/src/CudaDataOperationAlgorithm.cpp b/src/CudaDataOperationAlgorithm.cpp
index 79a9d7f..ae133c2 100644
--- a/src/CudaDataOperationAlgorithm.cpp
+++ b/src/CudaDataOperationAlgorithm.cpp
@@ -67,40 +67,37 @@ bool CCudaDataOperationAlgorithm::initialize(const Config& _cfg)
ConfigStackCheck<CAlgorithm> CC("CCudaDataOperationAlgorithm", this, _cfg);
// operation
- XMLNode* node = _cfg.self->getSingleNode("Operation");
+ XMLNode node = _cfg.self.getSingleNode("Operation");
ASTRA_CONFIG_CHECK(node, "CCudaDataOperationAlgorithm", "No Operation tag specified.");
- m_sOperation = node->getContent();
+ m_sOperation = node.getContent();
m_sOperation.erase(std::remove(m_sOperation.begin(), m_sOperation.end(), ' '), m_sOperation.end());
- ASTRA_DELETE(node);
CC.markNodeParsed("Operation");
// data
- node = _cfg.self->getSingleNode("DataId");
+ node = _cfg.self.getSingleNode("DataId");
ASTRA_CONFIG_CHECK(node, "CCudaDataOperationAlgorithm", "No DataId tag specified.");
- vector<string> data = node->getContentArray();
+ vector<string> data = node.getContentArray();
for (vector<string>::iterator it = data.begin(); it != data.end(); it++){
int id = boost::lexical_cast<int>(*it);
m_pData.push_back(dynamic_cast<CFloat32Data2D*>(CData2DManager::getSingleton().get(id)));
}
- ASTRA_DELETE(node);
CC.markNodeParsed("DataId");
// scalar
- node = _cfg.self->getSingleNode("Scalar");
+ node = _cfg.self.getSingleNode("Scalar");
ASTRA_CONFIG_CHECK(node, "CCudaDataOperationAlgorithm", "No Scalar tag specified.");
- m_fScalar = node->getContentNumericalArray();
- ASTRA_DELETE(node);
+ m_fScalar = node.getContentNumericalArray();
CC.markNodeParsed("Scalar");
// Option: GPU number
- m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUindex", -1);
- m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUIndex", m_iGPUIndex);
+ m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1);
+ m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUIndex", m_iGPUIndex);
CC.markOptionParsed("GPUindex");
- if (!_cfg.self->hasOption("GPUindex"))
+ if (!_cfg.self.hasOption("GPUindex"))
CC.markOptionParsed("GPUIndex");
- if (_cfg.self->hasOption("MaskId")) {
- int id = boost::lexical_cast<int>(_cfg.self->getOption("MaskId"));
+ if (_cfg.self.hasOption("MaskId")) {
+ int id = boost::lexical_cast<int>(_cfg.self.getOption("MaskId"));
m_pMask = dynamic_cast<CFloat32Data2D*>(CData2DManager::getSingleton().get(id));
}
CC.markOptionParsed("MaskId");
diff --git a/src/CudaFDKAlgorithm3D.cpp b/src/CudaFDKAlgorithm3D.cpp
index 7638696..467e641 100644
--- a/src/CudaFDKAlgorithm3D.cpp
+++ b/src/CudaFDKAlgorithm3D.cpp
@@ -100,12 +100,12 @@ bool CCudaFDKAlgorithm3D::initialize(const Config& _cfg)
return false;
}
- m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUindex", -1);
+ m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1);
CC.markOptionParsed("GPUindex");
- m_iVoxelSuperSampling = (int)_cfg.self->getOptionNumerical("VoxelSuperSampling", 1);
+ m_iVoxelSuperSampling = (int)_cfg.self.getOptionNumerical("VoxelSuperSampling", 1);
CC.markOptionParsed("VoxelSuperSampling");
- m_bShortScan = _cfg.self->getOptionBool("ShortScan", false);
+ m_bShortScan = _cfg.self.getOptionBool("ShortScan", false);
CC.markOptionParsed("ShortScan");
// success
diff --git a/src/CudaFilteredBackProjectionAlgorithm.cpp b/src/CudaFilteredBackProjectionAlgorithm.cpp
index 0badc20..5d6c166 100644
--- a/src/CudaFilteredBackProjectionAlgorithm.cpp
+++ b/src/CudaFilteredBackProjectionAlgorithm.cpp
@@ -78,39 +78,36 @@ bool CCudaFilteredBackProjectionAlgorithm::initialize(const Config& _cfg)
}
// sinogram data
- XMLNode* node = _cfg.self->getSingleNode("ProjectionDataId");
+ XMLNode node = _cfg.self.getSingleNode("ProjectionDataId");
ASTRA_CONFIG_CHECK(node, "CudaFBP", "No ProjectionDataId tag specified.");
- int id = boost::lexical_cast<int>(node->getContent());
+ int id = boost::lexical_cast<int>(node.getContent());
m_pSinogram = dynamic_cast<CFloat32ProjectionData2D*>(CData2DManager::getSingleton().get(id));
- ASTRA_DELETE(node);
CC.markNodeParsed("ProjectionDataId");
// reconstruction data
- node = _cfg.self->getSingleNode("ReconstructionDataId");
+ node = _cfg.self.getSingleNode("ReconstructionDataId");
ASTRA_CONFIG_CHECK(node, "CudaFBP", "No ReconstructionDataId tag specified.");
- id = boost::lexical_cast<int>(node->getContent());
+ id = boost::lexical_cast<int>(node.getContent());
m_pReconstruction = dynamic_cast<CFloat32VolumeData2D*>(CData2DManager::getSingleton().get(id));
- ASTRA_DELETE(node);
CC.markNodeParsed("ReconstructionDataId");
// filter type
- node = _cfg.self->getSingleNode("FilterType");
- if(node != NULL)
+ node = _cfg.self.getSingleNode("FilterType");
+ if (node)
{
- m_eFilter = _convertStringToFilter(node->getContent().c_str());
+ m_eFilter = _convertStringToFilter(node.getContent().c_str());
}
else
{
m_eFilter = FILTER_RAMLAK;
}
CC.markNodeParsed("FilterType");
- ASTRA_DELETE(node);
// filter
- node = _cfg.self->getSingleNode("FilterSinogramId");
- if(node != NULL)
+ node = _cfg.self.getSingleNode("FilterSinogramId");
+ if (node)
{
- id = boost::lexical_cast<int>(node->getContent());
+ id = boost::lexical_cast<int>(node.getContent());
const CFloat32ProjectionData2D * pFilterData = dynamic_cast<CFloat32ProjectionData2D*>(CData2DManager::getSingleton().get(id));
m_iFilterWidth = pFilterData->getGeometry()->getDetectorCount();
int iFilterProjectionCount = pFilterData->getGeometry()->getProjectionAngleCount();
@@ -124,13 +121,12 @@ bool CCudaFilteredBackProjectionAlgorithm::initialize(const Config& _cfg)
m_pfFilter = NULL;
}
CC.markNodeParsed("FilterSinogramId"); // TODO: Only for some types!
- ASTRA_DELETE(node);
// filter parameter
- node = _cfg.self->getSingleNode("FilterParameter");
- if(node != NULL)
+ node = _cfg.self.getSingleNode("FilterParameter");
+ if (node)
{
- float fParameter = boost::lexical_cast<float>(node->getContent());
+ float fParameter = boost::lexical_cast<float>(node.getContent());
m_fFilterParameter = fParameter;
}
else
@@ -138,13 +134,12 @@ bool CCudaFilteredBackProjectionAlgorithm::initialize(const Config& _cfg)
m_fFilterParameter = -1.0f;
}
CC.markNodeParsed("FilterParameter"); // TODO: Only for some types!
- ASTRA_DELETE(node);
// D value
- node = _cfg.self->getSingleNode("FilterD");
- if(node != NULL)
+ node = _cfg.self.getSingleNode("FilterD");
+ if (node)
{
- float fD = boost::lexical_cast<float>(node->getContent());
+ float fD = boost::lexical_cast<float>(node.getContent());
m_fFilterD = fD;
}
else
@@ -152,19 +147,18 @@ bool CCudaFilteredBackProjectionAlgorithm::initialize(const Config& _cfg)
m_fFilterD = 1.0f;
}
CC.markNodeParsed("FilterD"); // TODO: Only for some types!
- ASTRA_DELETE(node);
// GPU number
- m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUindex", -1);
+ m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1);
CC.markOptionParsed("GPUindex");
// Pixel supersampling factor
- m_iPixelSuperSampling = (int)_cfg.self->getOptionNumerical("PixelSuperSampling", 1);
+ m_iPixelSuperSampling = (int)_cfg.self.getOptionNumerical("PixelSuperSampling", 1);
CC.markOptionParsed("PixelSuperSampling");
// Fan beam short scan mode
if (m_pSinogram && dynamic_cast<CFanFlatProjectionGeometry2D*>(m_pSinogram->getGeometry())) {
- m_bShortScan = (int)_cfg.self->getOptionBool("ShortScan", false);
+ m_bShortScan = (int)_cfg.self.getOptionBool("ShortScan", false);
CC.markOptionParsed("ShortScan");
}
diff --git a/src/CudaForwardProjectionAlgorithm.cpp b/src/CudaForwardProjectionAlgorithm.cpp
index 95abb62..0f97d59 100644
--- a/src/CudaForwardProjectionAlgorithm.cpp
+++ b/src/CudaForwardProjectionAlgorithm.cpp
@@ -73,42 +73,39 @@ bool CCudaForwardProjectionAlgorithm::initialize(const Config& _cfg)
ConfigStackCheck<CAlgorithm> CC("CudaForwardProjectionAlgorithm", this, _cfg);
// sinogram data
- XMLNode* node = _cfg.self->getSingleNode("ProjectionDataId");
+ XMLNode node = _cfg.self.getSingleNode("ProjectionDataId");
ASTRA_CONFIG_CHECK(node, "FP_CUDA", "No ProjectionDataId tag specified.");
- int id = boost::lexical_cast<int>(node->getContent());
+ int id = boost::lexical_cast<int>(node.getContent());
m_pSinogram = dynamic_cast<CFloat32ProjectionData2D*>(CData2DManager::getSingleton().get(id));
- ASTRA_DELETE(node);
CC.markNodeParsed("ProjectionDataId");
// volume data
- node = _cfg.self->getSingleNode("VolumeDataId");
+ node = _cfg.self.getSingleNode("VolumeDataId");
ASTRA_CONFIG_CHECK(node, "FP_CUDA", "No VolumeDataId tag specified.");
- id = boost::lexical_cast<int>(node->getContent());
+ id = boost::lexical_cast<int>(node.getContent());
m_pVolume = dynamic_cast<CFloat32VolumeData2D*>(CData2DManager::getSingleton().get(id));
- ASTRA_DELETE(node);
CC.markNodeParsed("VolumeDataId");
// GPU number
- m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUindex", -1);
- m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUIndex", m_iGPUIndex);
+ m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1);
+ m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUIndex", m_iGPUIndex);
CC.markOptionParsed("GPUindex");
- if (!_cfg.self->hasOption("GPUindex"))
+ if (!_cfg.self.hasOption("GPUindex"))
CC.markOptionParsed("GPUIndex");
// Detector supersampling factor
- m_iDetectorSuperSampling = (int)_cfg.self->getOptionNumerical("DetectorSuperSampling", 1);
+ m_iDetectorSuperSampling = (int)_cfg.self.getOptionNumerical("DetectorSuperSampling", 1);
CC.markOptionParsed("DetectorSuperSampling");
// This isn't used yet, but passing it is not something to warn about
- node = _cfg.self->getSingleNode("ProjectorId");
+ node = _cfg.self.getSingleNode("ProjectorId");
if (node) {
- id = boost::lexical_cast<int>(node->getContent());
+ id = boost::lexical_cast<int>(node.getContent());
CProjector2D *projector = CProjector2DManager::getSingleton().get(id);
if (!dynamic_cast<CCudaProjector2D*>(projector)) {
ASTRA_WARN("non-CUDA Projector2D passed to FP_CUDA");
}
- delete node;
}
CC.markNodeParsed("ProjectorId");
diff --git a/src/CudaForwardProjectionAlgorithm3D.cpp b/src/CudaForwardProjectionAlgorithm3D.cpp
index 8e6bab5..e29b5a9 100644
--- a/src/CudaForwardProjectionAlgorithm3D.cpp
+++ b/src/CudaForwardProjectionAlgorithm3D.cpp
@@ -78,40 +78,37 @@ bool CCudaForwardProjectionAlgorithm3D::initialize(const Config& _cfg)
ASTRA_ASSERT(_cfg.self);
ConfigStackCheck<CAlgorithm> CC("CudaForwardProjectionAlgorithm3D", this, _cfg);
- XMLNode* node;
+ XMLNode node;
int id;
// sinogram data
- node = _cfg.self->getSingleNode("ProjectionDataId");
+ node = _cfg.self.getSingleNode("ProjectionDataId");
ASTRA_CONFIG_CHECK(node, "CudaForwardProjection3D", "No ProjectionDataId tag specified.");
- id = boost::lexical_cast<int>(node->getContent());
+ id = boost::lexical_cast<int>(node.getContent());
m_pProjections = dynamic_cast<CFloat32ProjectionData3DMemory*>(CData3DManager::getSingleton().get(id));
- ASTRA_DELETE(node);
CC.markNodeParsed("ProjectionDataId");
// reconstruction data
- node = _cfg.self->getSingleNode("VolumeDataId");
+ node = _cfg.self.getSingleNode("VolumeDataId");
ASTRA_CONFIG_CHECK(node, "CudaForwardProjection3D", "No VolumeDataId tag specified.");
- id = boost::lexical_cast<int>(node->getContent());
+ id = boost::lexical_cast<int>(node.getContent());
m_pVolume = dynamic_cast<CFloat32VolumeData3DMemory*>(CData3DManager::getSingleton().get(id));
- ASTRA_DELETE(node);
CC.markNodeParsed("VolumeDataId");
// optional: projector
- node = _cfg.self->getSingleNode("ProjectorId");
+ node = _cfg.self.getSingleNode("ProjectorId");
if (node) {
- id = boost::lexical_cast<int>(node->getContent());
+ id = boost::lexical_cast<int>(node.getContent());
m_pProjector = CProjector3DManager::getSingleton().get(id);
- ASTRA_DELETE(node);
} else {
m_pProjector = 0; // TODO: or manually construct default projector?
}
CC.markNodeParsed("ProjectorId");
// GPU number
- m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUindex", -1);
+ m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1);
CC.markOptionParsed("GPUindex");
- m_iDetectorSuperSampling = (int)_cfg.self->getOptionNumerical("DetectorSuperSampling", 1);
+ m_iDetectorSuperSampling = (int)_cfg.self.getOptionNumerical("DetectorSuperSampling", 1);
CC.markOptionParsed("DetectorSuperSampling");
// success
diff --git a/src/CudaProjector2D.cpp b/src/CudaProjector2D.cpp
index 056ea3b..fa024c8 100644
--- a/src/CudaProjector2D.cpp
+++ b/src/CudaProjector2D.cpp
@@ -104,10 +104,10 @@ bool CCudaProjector2D::initialize(const Config& _cfg)
// TODO: Check the projection geometry is a supported type
- XMLNode* node = _cfg.self->getSingleNode("ProjectionKernel");
+ XMLNode node = _cfg.self.getSingleNode("ProjectionKernel");
m_projectionKernel = ker2d_default;
if (node) {
- std::string sProjKernel = node->getContent();
+ std::string sProjKernel = node.getContent();
if (sProjKernel == "default") {
@@ -115,7 +115,6 @@ bool CCudaProjector2D::initialize(const Config& _cfg)
return false;
}
}
- ASTRA_DELETE(node);
CC.markNodeParsed("ProjectionKernel");
m_bIsInitialized = _check();
diff --git a/src/CudaProjector3D.cpp b/src/CudaProjector3D.cpp
index 2f4c799..41529a5 100644
--- a/src/CudaProjector3D.cpp
+++ b/src/CudaProjector3D.cpp
@@ -105,10 +105,10 @@ bool CCudaProjector3D::initialize(const Config& _cfg)
return false;
}
- XMLNode* node = _cfg.self->getSingleNode("ProjectionKernel");
+ XMLNode node = _cfg.self.getSingleNode("ProjectionKernel");
m_projectionKernel = ker3d_default;
if (node) {
- std::string sProjKernel = node->getContent();
+ std::string sProjKernel = node.getContent();
if (sProjKernel == "default") {
@@ -118,7 +118,6 @@ bool CCudaProjector3D::initialize(const Config& _cfg)
return false;
}
}
- ASTRA_DELETE(node);
CC.markNodeParsed("ProjectionKernel");
m_bIsInitialized = _check();
diff --git a/src/CudaReconstructionAlgorithm2D.cpp b/src/CudaReconstructionAlgorithm2D.cpp
index 1c6b763..db99d42 100644
--- a/src/CudaReconstructionAlgorithm2D.cpp
+++ b/src/CudaReconstructionAlgorithm2D.cpp
@@ -96,91 +96,88 @@ bool CCudaReconstructionAlgorithm2D::initialize(const Config& _cfg)
}
// sinogram data
- XMLNode* node = _cfg.self->getSingleNode("ProjectionDataId");
+ XMLNode node = _cfg.self.getSingleNode("ProjectionDataId");
ASTRA_CONFIG_CHECK(node, "CudaSirt2", "No ProjectionDataId tag specified.");
- int id = boost::lexical_cast<int>(node->getContent());
+ int id = boost::lexical_cast<int>(node.getContent());
m_pSinogram = dynamic_cast<CFloat32ProjectionData2D*>(CData2DManager::getSingleton().get(id));
- ASTRA_DELETE(node);
CC.markNodeParsed("ProjectionDataId");
// reconstruction data
- node = _cfg.self->getSingleNode("ReconstructionDataId");
+ node = _cfg.self.getSingleNode("ReconstructionDataId");
ASTRA_CONFIG_CHECK(node, "CudaSirt2", "No ReconstructionDataId tag specified.");
- id = boost::lexical_cast<int>(node->getContent());
+ id = boost::lexical_cast<int>(node.getContent());
m_pReconstruction = dynamic_cast<CFloat32VolumeData2D*>(CData2DManager::getSingleton().get(id));
- ASTRA_DELETE(node);
CC.markNodeParsed("ReconstructionDataId");
// fixed mask
- if (_cfg.self->hasOption("ReconstructionMaskId")) {
+ if (_cfg.self.hasOption("ReconstructionMaskId")) {
m_bUseReconstructionMask = true;
- id = boost::lexical_cast<int>(_cfg.self->getOption("ReconstructionMaskId"));
+ id = boost::lexical_cast<int>(_cfg.self.getOption("ReconstructionMaskId"));
m_pReconstructionMask = dynamic_cast<CFloat32VolumeData2D*>(CData2DManager::getSingleton().get(id));
ASTRA_CONFIG_CHECK(m_pReconstructionMask, "CudaReconstruction2D", "Invalid ReconstructionMaskId.");
}
CC.markOptionParsed("ReconstructionMaskId");
// fixed mask
- if (_cfg.self->hasOption("SinogramMaskId")) {
+ if (_cfg.self.hasOption("SinogramMaskId")) {
m_bUseSinogramMask = true;
- id = boost::lexical_cast<int>(_cfg.self->getOption("SinogramMaskId"));
+ id = boost::lexical_cast<int>(_cfg.self.getOption("SinogramMaskId"));
m_pSinogramMask = dynamic_cast<CFloat32ProjectionData2D*>(CData2DManager::getSingleton().get(id));
ASTRA_CONFIG_CHECK(m_pSinogramMask, "CudaReconstruction2D", "Invalid SinogramMaskId.");
}
CC.markOptionParsed("SinogramMaskId");
// Constraints - NEW
- if (_cfg.self->hasOption("MinConstraint")) {
+ if (_cfg.self.hasOption("MinConstraint")) {
m_bUseMinConstraint = true;
- m_fMinValue = _cfg.self->getOptionNumerical("MinConstraint", 0.0f);
+ m_fMinValue = _cfg.self.getOptionNumerical("MinConstraint", 0.0f);
CC.markOptionParsed("MinConstraint");
} else {
// Constraint - OLD
- m_bUseMinConstraint = _cfg.self->getOptionBool("UseMinConstraint", false);
+ m_bUseMinConstraint = _cfg.self.getOptionBool("UseMinConstraint", false);
CC.markOptionParsed("UseMinConstraint");
if (m_bUseMinConstraint) {
- m_fMinValue = _cfg.self->getOptionNumerical("MinConstraintValue", 0.0f);
+ m_fMinValue = _cfg.self.getOptionNumerical("MinConstraintValue", 0.0f);
CC.markOptionParsed("MinConstraintValue");
}
}
- if (_cfg.self->hasOption("MaxConstraint")) {
+ if (_cfg.self.hasOption("MaxConstraint")) {
m_bUseMaxConstraint = true;
- m_fMaxValue = _cfg.self->getOptionNumerical("MaxConstraint", 255.0f);
+ m_fMaxValue = _cfg.self.getOptionNumerical("MaxConstraint", 255.0f);
CC.markOptionParsed("MaxConstraint");
} else {
// Constraint - OLD
- m_bUseMaxConstraint = _cfg.self->getOptionBool("UseMaxConstraint", false);
+ m_bUseMaxConstraint = _cfg.self.getOptionBool("UseMaxConstraint", false);
CC.markOptionParsed("UseMaxConstraint");
if (m_bUseMaxConstraint) {
- m_fMaxValue = _cfg.self->getOptionNumerical("MaxConstraintValue", 0.0f);
+ m_fMaxValue = _cfg.self.getOptionNumerical("MaxConstraintValue", 0.0f);
CC.markOptionParsed("MaxConstraintValue");
}
}
// GPU number
- m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUindex", -1);
- m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUIndex", m_iGPUIndex);
+ m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1);
+ m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUIndex", m_iGPUIndex);
CC.markOptionParsed("GPUindex");
- if (!_cfg.self->hasOption("GPUindex"))
+ if (!_cfg.self.hasOption("GPUindex"))
CC.markOptionParsed("GPUIndex");
// Detector supersampling factor
- m_iDetectorSuperSampling = (int)_cfg.self->getOptionNumerical("DetectorSuperSampling", 1);
+ m_iDetectorSuperSampling = (int)_cfg.self.getOptionNumerical("DetectorSuperSampling", 1);
CC.markOptionParsed("DetectorSuperSampling");
// Pixel supersampling factor
- m_iPixelSuperSampling = (int)_cfg.self->getOptionNumerical("PixelSuperSampling", 1);
+ m_iPixelSuperSampling = (int)_cfg.self.getOptionNumerical("PixelSuperSampling", 1);
CC.markOptionParsed("PixelSuperSampling");
// This isn't used yet, but passing it is not something to warn about
- node = _cfg.self->getSingleNode("ProjectorId");
+ node = _cfg.self.getSingleNode("ProjectorId");
if (node) {
- id = boost::lexical_cast<int>(node->getContent());
+ id = boost::lexical_cast<int>(node.getContent());
CProjector2D *projector = CProjector2DManager::getSingleton().get(id);
if (!dynamic_cast<CCudaProjector2D*>(projector)) {
ASTRA_WARN("non-CUDA Projector2D passed");
}
- delete node;
}
CC.markNodeParsed("ProjectorId");
diff --git a/src/CudaRoiSelectAlgorithm.cpp b/src/CudaRoiSelectAlgorithm.cpp
index bfccb3a..7635c69 100644
--- a/src/CudaRoiSelectAlgorithm.cpp
+++ b/src/CudaRoiSelectAlgorithm.cpp
@@ -66,22 +66,21 @@ bool CCudaRoiSelectAlgorithm::initialize(const Config& _cfg)
ConfigStackCheck<CAlgorithm> CC("CudaDartMaskAlgorithm", this, _cfg);
// reconstruction data
- XMLNode* node = _cfg.self->getSingleNode("DataId");
+ XMLNode node = _cfg.self.getSingleNode("DataId");
ASTRA_CONFIG_CHECK(node, "CudaRoiSelect", "No DataId tag specified.");
- int id = boost::lexical_cast<int>(node->getContent());
+ int id = boost::lexical_cast<int>(node.getContent());
m_pData = dynamic_cast<CFloat32VolumeData2D*>(CData2DManager::getSingleton().get(id));
- ASTRA_DELETE(node);
CC.markNodeParsed("DataId");
// Option: GPU number
- m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUindex", -1);
- m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUIndex", m_iGPUIndex);
+ m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1);
+ m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUIndex", m_iGPUIndex);
CC.markOptionParsed("GPUindex");
- if (!_cfg.self->hasOption("GPUindex"))
+ if (!_cfg.self.hasOption("GPUindex"))
CC.markOptionParsed("GPUIndex");
// Option: Radius
- m_fRadius = (unsigned int)_cfg.self->getOptionNumerical("Radius", 0.0f);
+ m_fRadius = (unsigned int)_cfg.self.getOptionNumerical("Radius", 0.0f);
CC.markOptionParsed("Radius");
_check();
diff --git a/src/CudaSartAlgorithm.cpp b/src/CudaSartAlgorithm.cpp
index 8e22c59..8c0c6d7 100644
--- a/src/CudaSartAlgorithm.cpp
+++ b/src/CudaSartAlgorithm.cpp
@@ -74,7 +74,7 @@ bool CCudaSartAlgorithm::initialize(const Config& _cfg)
// projection order
int projectionCount = m_pSinogram->getGeometry()->getProjectionAngleCount();
int* projectionOrder = NULL;
- string projOrder = _cfg.self->getOption("ProjectionOrder", "random");
+ string projOrder = _cfg.self.getOption("ProjectionOrder", "random");
CC.markOptionParsed("ProjectionOrder");
if (projOrder == "sequential") {
projectionOrder = new int[projectionCount];
@@ -97,7 +97,7 @@ bool CCudaSartAlgorithm::initialize(const Config& _cfg)
sart->setProjectionOrder(projectionOrder, projectionCount);
delete[] projectionOrder;
} else if (projOrder == "custom") {
- vector<float32> projOrderList = _cfg.self->getOptionNumericalArray("ProjectionOrderList");
+ vector<float32> projOrderList = _cfg.self.getOptionNumericalArray("ProjectionOrderList");
projectionOrder = new int[projOrderList.size()];
for (int i = 0; i < projOrderList.size(); i++) {
projectionOrder[i] = static_cast<int>(projOrderList[i]);
diff --git a/src/CudaSirtAlgorithm.cpp b/src/CudaSirtAlgorithm.cpp
index f6eb79a..d424915 100644
--- a/src/CudaSirtAlgorithm.cpp
+++ b/src/CudaSirtAlgorithm.cpp
@@ -76,13 +76,13 @@ bool CCudaSirtAlgorithm::initialize(const Config& _cfg)
return false;
// min/max masks
- if (_cfg.self->hasOption("MinMaskId")) {
- int id = boost::lexical_cast<int>(_cfg.self->getOption("MinMaskId"));
+ if (_cfg.self.hasOption("MinMaskId")) {
+ int id = boost::lexical_cast<int>(_cfg.self.getOption("MinMaskId"));
m_pMinMask = dynamic_cast<CFloat32VolumeData2D*>(CData2DManager::getSingleton().get(id));
}
CC.markOptionParsed("MinMaskId");
- if (_cfg.self->hasOption("MaxMaskId")) {
- int id = boost::lexical_cast<int>(_cfg.self->getOption("MaxMaskId"));
+ if (_cfg.self.hasOption("MaxMaskId")) {
+ int id = boost::lexical_cast<int>(_cfg.self.getOption("MaxMaskId"));
m_pMaxMask = dynamic_cast<CFloat32VolumeData2D*>(CData2DManager::getSingleton().get(id));
}
CC.markOptionParsed("MaxMaskId");
diff --git a/src/CudaSirtAlgorithm3D.cpp b/src/CudaSirtAlgorithm3D.cpp
index da83c7e..5ad131b 100644
--- a/src/CudaSirtAlgorithm3D.cpp
+++ b/src/CudaSirtAlgorithm3D.cpp
@@ -107,11 +107,11 @@ bool CCudaSirtAlgorithm3D::initialize(const Config& _cfg)
return false;
}
- m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUindex", -1);
+ m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1);
CC.markOptionParsed("GPUindex");
- m_iDetectorSuperSampling = (int)_cfg.self->getOptionNumerical("DetectorSuperSampling", 1);
+ m_iDetectorSuperSampling = (int)_cfg.self.getOptionNumerical("DetectorSuperSampling", 1);
CC.markOptionParsed("DetectorSuperSampling");
- m_iVoxelSuperSampling = (int)_cfg.self->getOptionNumerical("VoxelSuperSampling", 1);
+ m_iVoxelSuperSampling = (int)_cfg.self.getOptionNumerical("VoxelSuperSampling", 1);
CC.markOptionParsed("VoxelSuperSampling");
m_pSirt = new AstraSIRT3d();
diff --git a/src/FanFlatProjectionGeometry2D.cpp b/src/FanFlatProjectionGeometry2D.cpp
index d757f18..32a19bc 100644
--- a/src/FanFlatProjectionGeometry2D.cpp
+++ b/src/FanFlatProjectionGeometry2D.cpp
@@ -134,17 +134,15 @@ bool CFanFlatProjectionGeometry2D::initialize(const Config& _cfg)
CProjectionGeometry2D::initialize(_cfg);
// Required: DistanceOriginDetector
- XMLNode* node = _cfg.self->getSingleNode("DistanceOriginDetector");
+ XMLNode node = _cfg.self.getSingleNode("DistanceOriginDetector");
ASTRA_CONFIG_CHECK(node, "FanFlatProjectionGeometry2D", "No DistanceOriginDetector tag specified.");
- m_fOriginDetectorDistance = boost::lexical_cast<float32>(node->getContent());
- ASTRA_DELETE(node);
+ m_fOriginDetectorDistance = boost::lexical_cast<float32>(node.getContent());
CC.markNodeParsed("DistanceOriginDetector");
// Required: DetectorOriginSource
- node = _cfg.self->getSingleNode("DistanceOriginSource");
+ node = _cfg.self.getSingleNode("DistanceOriginSource");
ASTRA_CONFIG_CHECK(node, "FanFlatProjectionGeometry2D", "No DistanceOriginSource tag specified.");
- m_fOriginSourceDistance = boost::lexical_cast<float32>(node->getContent());
- ASTRA_DELETE(node);
+ m_fOriginSourceDistance = boost::lexical_cast<float32>(node.getContent());
CC.markNodeParsed("DistanceOriginSource");
// success
@@ -209,12 +207,12 @@ Config* CFanFlatProjectionGeometry2D::getConfiguration() const
{
Config* cfg = new Config();
cfg->initialize("ProjectionGeometry2D");
- cfg->self->addAttribute("type", "fanflat");
- cfg->self->addChildNode("DetectorCount", getDetectorCount());
- cfg->self->addChildNode("DetectorWidth", getDetectorWidth());
- cfg->self->addChildNode("DistanceOriginSource", getOriginSourceDistance());
- cfg->self->addChildNode("DistanceOriginDetector", getOriginDetectorDistance());
- cfg->self->addChildNode("ProjectionAngles", m_pfProjectionAngles, m_iProjectionAngleCount);
+ cfg->self.addAttribute("type", "fanflat");
+ cfg->self.addChildNode("DetectorCount", getDetectorCount());
+ cfg->self.addChildNode("DetectorWidth", getDetectorWidth());
+ cfg->self.addChildNode("DistanceOriginSource", getOriginSourceDistance());
+ cfg->self.addChildNode("DistanceOriginDetector", getOriginDetectorDistance());
+ cfg->self.addChildNode("ProjectionAngles", m_pfProjectionAngles, m_iProjectionAngleCount);
return cfg;
}
//----------------------------------------------------------------------------------------
diff --git a/src/FanFlatVecProjectionGeometry2D.cpp b/src/FanFlatVecProjectionGeometry2D.cpp
index 9c7b596..4104379 100644
--- a/src/FanFlatVecProjectionGeometry2D.cpp
+++ b/src/FanFlatVecProjectionGeometry2D.cpp
@@ -116,25 +116,23 @@ bool CFanFlatVecProjectionGeometry2D::initialize(const Config& _cfg)
ASTRA_ASSERT(_cfg.self);
ConfigStackCheck<CProjectionGeometry2D> CC("FanFlatVecProjectionGeometry2D", this, _cfg);
- XMLNode* node;
+ XMLNode node;
// TODO: Fix up class hierarchy... this class doesn't fit very well.
// initialization of parent class
//CProjectionGeometry2D::initialize(_cfg);
// Required: DetectorCount
- node = _cfg.self->getSingleNode("DetectorCount");
+ node = _cfg.self.getSingleNode("DetectorCount");
ASTRA_CONFIG_CHECK(node, "FanFlatVecProjectionGeometry3D", "No DetectorRowCount tag specified.");
- m_iDetectorCount = boost::lexical_cast<int>(node->getContent());
- ASTRA_DELETE(node);
+ m_iDetectorCount = boost::lexical_cast<int>(node.getContent());
CC.markNodeParsed("DetectorCount");
// Required: Vectors
- node = _cfg.self->getSingleNode("Vectors");
+ node = _cfg.self.getSingleNode("Vectors");
ASTRA_CONFIG_CHECK(node, "FanFlatVecProjectionGeometry3D", "No Vectors tag specified.");
- vector<float32> data = node->getContentNumericalArray();
+ vector<float32> data = node.getContentNumericalArray();
CC.markNodeParsed("Vectors");
- ASTRA_DELETE(node);
ASTRA_CONFIG_CHECK(data.size() % 6 == 0, "FanFlatVecProjectionGeometry3D", "Vectors doesn't consist of 6-tuples.");
m_iProjectionAngleCount = data.size() / 6;
m_pProjectionAngles = new SFanProjection[m_iProjectionAngleCount];
@@ -232,8 +230,8 @@ Config* CFanFlatVecProjectionGeometry2D::getConfiguration() const
{
Config* cfg = new Config();
cfg->initialize("ProjectionGeometry2D");
- cfg->self->addAttribute("type", "fanflat_vec");
- cfg->self->addChildNode("DetectorCount", getDetectorCount());
+ cfg->self.addAttribute("type", "fanflat_vec");
+ cfg->self.addChildNode("DetectorCount", getDetectorCount());
std::string vectors = "";
for (int i = 0; i < m_iProjectionAngleCount; ++i) {
SFanProjection& p = m_pProjectionAngles[i];
@@ -245,7 +243,7 @@ Config* CFanFlatVecProjectionGeometry2D::getConfiguration() const
vectors += boost::lexical_cast<string>(p.fDetUY);
if (i < m_iProjectionAngleCount-1) vectors += ';';
}
- cfg->self->addChildNode("Vectors", vectors);
+ cfg->self.addChildNode("Vectors", vectors);
return cfg;
}
//----------------------------------------------------------------------------------------
diff --git a/src/FilteredBackProjectionAlgorithm.cpp b/src/FilteredBackProjectionAlgorithm.cpp
index 4a8e5ac..f494d22 100644
--- a/src/FilteredBackProjectionAlgorithm.cpp
+++ b/src/FilteredBackProjectionAlgorithm.cpp
@@ -94,30 +94,27 @@ bool CFilteredBackProjectionAlgorithm::initialize(const Config& _cfg)
ASTRA_ASSERT(_cfg.self);
// projector
- XMLNode* node = _cfg.self->getSingleNode("ProjectorId");
+ XMLNode node = _cfg.self.getSingleNode("ProjectorId");
ASTRA_CONFIG_CHECK(node, "FilteredBackProjection", "No ProjectorId tag specified.");
- int id = boost::lexical_cast<int>(node->getContent());
+ int id = boost::lexical_cast<int>(node.getContent());
m_pProjector = CProjector2DManager::getSingleton().get(id);
- ASTRA_DELETE(node);
// sinogram data
- node = _cfg.self->getSingleNode("ProjectionDataId");
+ node = _cfg.self.getSingleNode("ProjectionDataId");
ASTRA_CONFIG_CHECK(node, "FilteredBackProjection", "No ProjectionDataId tag specified.");
- id = boost::lexical_cast<int>(node->getContent());
+ id = boost::lexical_cast<int>(node.getContent());
m_pSinogram = dynamic_cast<CFloat32ProjectionData2D*>(CData2DManager::getSingleton().get(id));
- ASTRA_DELETE(node);
// volume data
- node = _cfg.self->getSingleNode("ReconstructionDataId");
+ node = _cfg.self.getSingleNode("ReconstructionDataId");
ASTRA_CONFIG_CHECK(node, "FilteredBackProjection", "No ReconstructionDataId tag specified.");
- id = boost::lexical_cast<int>(node->getContent());
+ id = boost::lexical_cast<int>(node.getContent());
m_pReconstruction = dynamic_cast<CFloat32VolumeData2D*>(CData2DManager::getSingleton().get(id));
- ASTRA_DELETE(node);
- node = _cfg.self->getSingleNode("ProjectionIndex");
+ node = _cfg.self.getSingleNode("ProjectionIndex");
if (node)
{
- vector<float32> projectionIndex = node->getContentNumericalArray();
+ vector<float32> projectionIndex = node.getContentNumericalArray();
int angleCount = projectionIndex.size();
int detectorCount = m_pProjector->getProjectionGeometry()->getDetectorCount();
@@ -154,7 +151,6 @@ bool CFilteredBackProjectionAlgorithm::initialize(const Config& _cfg)
m_pProjector = new CParallelBeamLineKernelProjector2D(pg,m_pReconstruction->getGeometry());
m_pSinogram = new CFloat32ProjectionData2D(pg, sinogramData2D);
}
- ASTRA_DELETE(node);
// TODO: check that the angles are linearly spaced between 0 and pi
diff --git a/src/Float32ProjectionData2D.cpp b/src/Float32ProjectionData2D.cpp
index 85e0cdd..f7f83e3 100644
--- a/src/Float32ProjectionData2D.cpp
+++ b/src/Float32ProjectionData2D.cpp
@@ -75,6 +75,16 @@ CFloat32ProjectionData2D::CFloat32ProjectionData2D(const CFloat32ProjectionData2
m_bInitialized = true;
}
+//----------------------------------------------------------------------------------------
+// Create an instance of the CFloat32ProjectionData2D class with pre-allocated data
+CFloat32ProjectionData2D::CFloat32ProjectionData2D(CProjectionGeometry2D* _pGeometry, CFloat32CustomMemory* _pCustomMemory)
+{
+ m_bInitialized = false;
+ m_bInitialized = initialize(_pGeometry, _pCustomMemory);
+}
+
+
+
// Assignment operator
CFloat32ProjectionData2D& CFloat32ProjectionData2D::operator=(const CFloat32ProjectionData2D& _other)
@@ -119,6 +129,15 @@ bool CFloat32ProjectionData2D::initialize(CProjectionGeometry2D* _pGeometry, flo
}
//----------------------------------------------------------------------------------------
+// Initialization
+bool CFloat32ProjectionData2D::initialize(CProjectionGeometry2D* _pGeometry, CFloat32CustomMemory* _pCustomMemory)
+{
+ m_pGeometry = _pGeometry->clone();
+ m_bInitialized = _initialize(m_pGeometry->getDetectorCount(), m_pGeometry->getProjectionAngleCount(), _pCustomMemory);
+ return m_bInitialized;
+}
+
+//----------------------------------------------------------------------------------------
// Destructor
CFloat32ProjectionData2D::~CFloat32ProjectionData2D()
{
diff --git a/src/Float32ProjectionData3D.cpp b/src/Float32ProjectionData3D.cpp
index d039c83..2bd0447 100644
--- a/src/Float32ProjectionData3D.cpp
+++ b/src/Float32ProjectionData3D.cpp
@@ -270,4 +270,13 @@ CFloat32ProjectionData3D& CFloat32ProjectionData3D::operator-=(const float32& _f
return *this;
}
+void CFloat32ProjectionData3D::changeGeometry(CProjectionGeometry3D* _pGeometry)
+{
+ if (!m_bInitialized) return;
+
+ delete m_pGeometry;
+ m_pGeometry = _pGeometry->clone();
+}
+
+
} // end namespace astra
diff --git a/src/Float32VolumeData2D.cpp b/src/Float32VolumeData2D.cpp
index e11c4e4..c903c66 100644
--- a/src/Float32VolumeData2D.cpp
+++ b/src/Float32VolumeData2D.cpp
@@ -72,6 +72,15 @@ CFloat32VolumeData2D::CFloat32VolumeData2D(const CFloat32VolumeData2D& _other) :
m_bInitialized = true;
}
+//----------------------------------------------------------------------------------------
+// Create an instance of the CFloat32VolumeData2D class with pre-allocated data
+CFloat32VolumeData2D::CFloat32VolumeData2D(CVolumeGeometry2D* _pGeometry, CFloat32CustomMemory* _pCustomMemory)
+{
+ m_bInitialized = false;
+ m_bInitialized = initialize(_pGeometry, _pCustomMemory);
+}
+
+
// Assignment operator
CFloat32VolumeData2D& CFloat32VolumeData2D::operator=(const CFloat32VolumeData2D& _other)
@@ -122,6 +131,17 @@ bool CFloat32VolumeData2D::initialize(CVolumeGeometry2D* _pGeometry, float32 _fS
m_bInitialized = _initialize(m_pGeometry->getGridColCount(), m_pGeometry->getGridRowCount(), _fScalar);
return m_bInitialized;
}
+
+//----------------------------------------------------------------------------------------
+// Initialization
+bool CFloat32VolumeData2D::initialize(CVolumeGeometry2D* _pGeometry, CFloat32CustomMemory* _pCustomMemory)
+{
+ m_pGeometry = _pGeometry->clone();
+ m_bInitialized = _initialize(m_pGeometry->getGridColCount(), m_pGeometry->getGridRowCount(), _pCustomMemory);
+ return m_bInitialized;
+}
+
+
//----------------------------------------------------------------------------------------
void CFloat32VolumeData2D::changeGeometry(CVolumeGeometry2D* _pGeometry)
{
diff --git a/src/Float32VolumeData3D.cpp b/src/Float32VolumeData3D.cpp
index ce00a10..bd78001 100644
--- a/src/Float32VolumeData3D.cpp
+++ b/src/Float32VolumeData3D.cpp
@@ -266,4 +266,13 @@ CFloat32VolumeData3D& CFloat32VolumeData3D::operator-=(const float32& _fScalar)
return *this;
}
+void CFloat32VolumeData3D::changeGeometry(CVolumeGeometry3D* _pGeometry)
+{
+ if (!m_bInitialized) return;
+
+ delete m_pGeometry;
+ m_pGeometry = _pGeometry->clone();
+}
+
+
} // end namespace astra
diff --git a/src/ForwardProjectionAlgorithm.cpp b/src/ForwardProjectionAlgorithm.cpp
index b530491..f356824 100644
--- a/src/ForwardProjectionAlgorithm.cpp
+++ b/src/ForwardProjectionAlgorithm.cpp
@@ -126,37 +126,34 @@ bool CForwardProjectionAlgorithm::initialize(const Config& _cfg)
}
// projector
- XMLNode* node = _cfg.self->getSingleNode("ProjectorId");
+ XMLNode node = _cfg.self.getSingleNode("ProjectorId");
ASTRA_CONFIG_CHECK(node, "ForwardProjection", "No ProjectorId tag specified.");
- int id = boost::lexical_cast<int>(node->getContent());
+ int id = boost::lexical_cast<int>(node.getContent());
m_pProjector = CProjector2DManager::getSingleton().get(id);
- ASTRA_DELETE(node);
// sinogram data
- node = _cfg.self->getSingleNode("ProjectionDataId");
+ node = _cfg.self.getSingleNode("ProjectionDataId");
ASTRA_CONFIG_CHECK(node, "ForwardProjection", "No ProjectionDataId tag specified.");
- id = boost::lexical_cast<int>(node->getContent());
+ id = boost::lexical_cast<int>(node.getContent());
m_pSinogram = dynamic_cast<CFloat32ProjectionData2D*>(CData2DManager::getSingleton().get(id));
- ASTRA_DELETE(node);
// volume data
- node = _cfg.self->getSingleNode("VolumeDataId");
+ node = _cfg.self.getSingleNode("VolumeDataId");
ASTRA_CONFIG_CHECK(node, "ForwardProjection", "No VolumeDataId tag specified.");
- id = boost::lexical_cast<int>(node->getContent());
+ id = boost::lexical_cast<int>(node.getContent());
m_pVolume = dynamic_cast<CFloat32VolumeData2D*>(CData2DManager::getSingleton().get(id));
- ASTRA_DELETE(node);
// volume mask
- if (_cfg.self->hasOption("VolumeMaskId")) {
+ if (_cfg.self.hasOption("VolumeMaskId")) {
m_bUseVolumeMask = true;
- id = boost::lexical_cast<int>(_cfg.self->getOption("VolumeMaskId"));
+ id = boost::lexical_cast<int>(_cfg.self.getOption("VolumeMaskId"));
m_pVolumeMask = dynamic_cast<CFloat32VolumeData2D*>(CData2DManager::getSingleton().get(id));
}
// sino mask
- if (_cfg.self->hasOption("SinogramMaskId")) {
+ if (_cfg.self.hasOption("SinogramMaskId")) {
m_bUseSinogramMask = true;
- id = boost::lexical_cast<int>(_cfg.self->getOption("SinogramMaskId"));
+ id = boost::lexical_cast<int>(_cfg.self.getOption("SinogramMaskId"));
m_pSinogramMask = dynamic_cast<CFloat32ProjectionData2D*>(CData2DManager::getSingleton().get(id));
}
diff --git a/src/ParallelBeamBlobKernelProjector2D.cpp b/src/ParallelBeamBlobKernelProjector2D.cpp
index 3253f88..4559a48 100644
--- a/src/ParallelBeamBlobKernelProjector2D.cpp
+++ b/src/ParallelBeamBlobKernelProjector2D.cpp
@@ -128,28 +128,28 @@ bool CParallelBeamBlobKernelProjector2D::initialize(const Config& _cfg)
}
// required: Kernel
- XMLNode* node = _cfg.self->getSingleNode("Kernel");
+ XMLNode node = _cfg.self.getSingleNode("Kernel");
ASTRA_CONFIG_CHECK(node, "BlobProjector", "No Kernel tag specified.");
{
// Required: KernelSize
- XMLNode* node2 = node->getSingleNode("KernelSize");
+ XMLNode node2 = node.getSingleNode("KernelSize");
ASTRA_CONFIG_CHECK(node2, "BlobProjector", "No Kernel/KernelSize tag specified.");
- m_fBlobSize = boost::lexical_cast<float32>(node2->getContent());
+ m_fBlobSize = boost::lexical_cast<float32>(node2.getContent());
// Required: SampleRate
- node2 = node->getSingleNode("SampleRate");
+ node2 = node.getSingleNode("SampleRate");
ASTRA_CONFIG_CHECK(node2, "BlobProjector", "No Kernel/SampleRate tag specified.");
- m_fBlobSampleRate = boost::lexical_cast<float32>(node2->getContent());
+ m_fBlobSampleRate = boost::lexical_cast<float32>(node2.getContent());
// Required: SampleCount
- node2 = node->getSingleNode("SampleCount");
+ node2 = node.getSingleNode("SampleCount");
ASTRA_CONFIG_CHECK(node2, "BlobProjector", "No Kernel/SampleCount tag specified.");
- m_iBlobSampleCount = boost::lexical_cast<int>(node2->getContent());
+ m_iBlobSampleCount = boost::lexical_cast<int>(node2.getContent());
// Required: KernelValues
- node2 = node->getSingleNode("KernelValues");
+ node2 = node.getSingleNode("KernelValues");
ASTRA_CONFIG_CHECK(node2, "BlobProjector", "No Kernel/KernelValues tag specified.");
- vector<float32> values = node2->getContentNumericalArray();
+ vector<float32> values = node2.getContentNumericalArray();
ASTRA_CONFIG_CHECK(values.size() == (unsigned int)m_iBlobSampleCount, "BlobProjector", "Number of specified values doesn't match SampleCount.");
m_pfBlobValues = new float32[m_iBlobSampleCount];
for (int i = 0; i < m_iBlobSampleCount; i++) {
@@ -157,9 +157,9 @@ bool CParallelBeamBlobKernelProjector2D::initialize(const Config& _cfg)
}
// Required: KernelValues
- node2 = node->getSingleNode("KernelValuesNeg");
+ node2 = node.getSingleNode("KernelValuesNeg");
ASTRA_CONFIG_CHECK(node2, "BlobProjector", "No Kernel/KernelValuesNeg tag specified.");
- vector<float32> values2 = node2->getContentNumericalArray();
+ vector<float32> values2 = node2.getContentNumericalArray();
ASTRA_CONFIG_CHECK(values2.size() == (unsigned int)m_iBlobSampleCount, "BlobProjector", "Number of specified values doesn't match SampleCount.");
m_pfBlobValuesNeg = new float32[m_iBlobSampleCount];
for (int i = 0; i < m_iBlobSampleCount; i++) {
diff --git a/src/ParallelProjectionGeometry2D.cpp b/src/ParallelProjectionGeometry2D.cpp
index cac8f30..699e141 100644
--- a/src/ParallelProjectionGeometry2D.cpp
+++ b/src/ParallelProjectionGeometry2D.cpp
@@ -176,10 +176,10 @@ Config* CParallelProjectionGeometry2D::getConfiguration() const
{
Config* cfg = new Config();
cfg->initialize("ProjectionGeometry2D");
- cfg->self->addAttribute("type", "parallel");
- cfg->self->addChildNode("DetectorCount", getDetectorCount());
- cfg->self->addChildNode("DetectorWidth", getDetectorWidth());
- cfg->self->addChildNode("ProjectionAngles", m_pfProjectionAngles, m_iProjectionAngleCount);
+ cfg->self.addAttribute("type", "parallel");
+ cfg->self.addChildNode("DetectorCount", getDetectorCount());
+ cfg->self.addChildNode("DetectorWidth", getDetectorWidth());
+ cfg->self.addChildNode("ProjectionAngles", m_pfProjectionAngles, m_iProjectionAngleCount);
return cfg;
}
//----------------------------------------------------------------------------------------
diff --git a/src/ParallelProjectionGeometry3D.cpp b/src/ParallelProjectionGeometry3D.cpp
index eb200f9..1c87157 100644
--- a/src/ParallelProjectionGeometry3D.cpp
+++ b/src/ParallelProjectionGeometry3D.cpp
@@ -164,12 +164,12 @@ Config* CParallelProjectionGeometry3D::getConfiguration() const
{
Config* cfg = new Config();
cfg->initialize("ProjectionGeometry3D");
- cfg->self->addAttribute("type", "parallel3d");
- cfg->self->addChildNode("DetectorRowCount", m_iDetectorRowCount);
- cfg->self->addChildNode("DetectorColCount", m_iDetectorColCount);
- cfg->self->addChildNode("DetectorSpacingX", m_fDetectorSpacingX);
- cfg->self->addChildNode("DetectorSpacingY", m_fDetectorSpacingY);
- cfg->self->addChildNode("ProjectionAngles", m_pfProjectionAngles, m_iProjectionAngleCount);
+ cfg->self.addAttribute("type", "parallel3d");
+ cfg->self.addChildNode("DetectorRowCount", m_iDetectorRowCount);
+ cfg->self.addChildNode("DetectorColCount", m_iDetectorColCount);
+ cfg->self.addChildNode("DetectorSpacingX", m_fDetectorSpacingX);
+ cfg->self.addChildNode("DetectorSpacingY", m_fDetectorSpacingY);
+ cfg->self.addChildNode("ProjectionAngles", m_pfProjectionAngles, m_iProjectionAngleCount);
return cfg;
}
//----------------------------------------------------------------------------------------
diff --git a/src/ParallelVecProjectionGeometry3D.cpp b/src/ParallelVecProjectionGeometry3D.cpp
index dc325e9..ffad6d0 100644
--- a/src/ParallelVecProjectionGeometry3D.cpp
+++ b/src/ParallelVecProjectionGeometry3D.cpp
@@ -73,33 +73,30 @@ bool CParallelVecProjectionGeometry3D::initialize(const Config& _cfg)
ASTRA_ASSERT(_cfg.self);
ConfigStackCheck<CProjectionGeometry3D> CC("ParallelVecProjectionGeometry3D", this, _cfg);
- XMLNode* node;
+ XMLNode node;
// TODO: Fix up class hierarchy... this class doesn't fit very well.
// initialization of parent class
//CProjectionGeometry3D::initialize(_cfg);
// Required: DetectorRowCount
- node = _cfg.self->getSingleNode("DetectorRowCount");
+ node = _cfg.self.getSingleNode("DetectorRowCount");
ASTRA_CONFIG_CHECK(node, "ParallelVecProjectionGeometry3D", "No DetectorRowCount tag specified.");
- m_iDetectorRowCount = boost::lexical_cast<int>(node->getContent());
- ASTRA_DELETE(node);
+ m_iDetectorRowCount = boost::lexical_cast<int>(node.getContent());
CC.markNodeParsed("DetectorRowCount");
// Required: DetectorCount
- node = _cfg.self->getSingleNode("DetectorColCount");
+ node = _cfg.self.getSingleNode("DetectorColCount");
ASTRA_CONFIG_CHECK(node, "", "No DetectorColCount tag specified.");
- m_iDetectorColCount = boost::lexical_cast<int>(node->getContent());
+ m_iDetectorColCount = boost::lexical_cast<int>(node.getContent());
m_iDetectorTotCount = m_iDetectorRowCount * m_iDetectorColCount;
- ASTRA_DELETE(node);
CC.markNodeParsed("DetectorColCount");
// Required: Vectors
- node = _cfg.self->getSingleNode("Vectors");
+ node = _cfg.self.getSingleNode("Vectors");
ASTRA_CONFIG_CHECK(node, "ParallelVecProjectionGeometry3D", "No Vectors tag specified.");
- vector<double> data = node->getContentNumericalArrayDouble();
+ vector<double> data = node.getContentNumericalArrayDouble();
CC.markNodeParsed("Vectors");
- ASTRA_DELETE(node);
ASTRA_CONFIG_CHECK(data.size() % 12 == 0, "ParallelVecProjectionGeometry3D", "Vectors doesn't consist of 12-tuples.");
m_iProjectionAngleCount = data.size() / 12;
m_pProjectionAngles = new SPar3DProjection[m_iProjectionAngleCount];
@@ -208,9 +205,9 @@ Config* CParallelVecProjectionGeometry3D::getConfiguration() const
Config* cfg = new Config();
cfg->initialize("ProjectionGeometry3D");
- cfg->self->addAttribute("type", "parallel3d_vec");
- cfg->self->addChildNode("DetectorRowCount", m_iDetectorRowCount);
- cfg->self->addChildNode("DetectorColCount", m_iDetectorColCount);
+ cfg->self.addAttribute("type", "parallel3d_vec");
+ cfg->self.addChildNode("DetectorRowCount", m_iDetectorRowCount);
+ cfg->self.addChildNode("DetectorColCount", m_iDetectorColCount);
std::string vectors = "";
for (int i = 0; i < m_iProjectionAngleCount; ++i) {
@@ -229,7 +226,7 @@ Config* CParallelVecProjectionGeometry3D::getConfiguration() const
vectors += boost::lexical_cast<string>(p.fDetVZ);
if (i < m_iProjectionAngleCount-1) vectors += ';';
}
- cfg->self->addChildNode("Vectors", vectors);
+ cfg->self.addChildNode("Vectors", vectors);
return cfg;
}
diff --git a/src/ProjectionGeometry2D.cpp b/src/ProjectionGeometry2D.cpp
index 89b5fe0..b89605b 100644
--- a/src/ProjectionGeometry2D.cpp
+++ b/src/ProjectionGeometry2D.cpp
@@ -124,24 +124,21 @@ bool CProjectionGeometry2D::initialize(const Config& _cfg)
}
// Required: DetectorWidth
- XMLNode* node = _cfg.self->getSingleNode("DetectorWidth");
+ XMLNode node = _cfg.self.getSingleNode("DetectorWidth");
ASTRA_CONFIG_CHECK(node, "ProjectionGeometry2D", "No DetectorWidth tag specified.");
- m_fDetectorWidth = boost::lexical_cast<float32>(node->getContent());
- ASTRA_DELETE(node);
+ m_fDetectorWidth = boost::lexical_cast<float32>(node.getContent());
CC.markNodeParsed("DetectorWidth");
// Required: DetectorCount
- node = _cfg.self->getSingleNode("DetectorCount");
+ node = _cfg.self.getSingleNode("DetectorCount");
ASTRA_CONFIG_CHECK(node, "ProjectionGeometry2D", "No DetectorCount tag specified.");
- m_iDetectorCount = boost::lexical_cast<int>(node->getContent());
- ASTRA_DELETE(node);
+ m_iDetectorCount = boost::lexical_cast<int>(node.getContent());
CC.markNodeParsed("DetectorCount");
// Required: ProjectionAngles
- node = _cfg.self->getSingleNode("ProjectionAngles");
+ node = _cfg.self.getSingleNode("ProjectionAngles");
ASTRA_CONFIG_CHECK(node, "ProjectionGeometry2D", "No ProjectionAngles tag specified.");
- vector<float32> angles = node->getContentNumericalArray();
- delete node;
+ vector<float32> angles = node.getContentNumericalArray();
m_iProjectionAngleCount = angles.size();
ASTRA_CONFIG_CHECK(m_iProjectionAngleCount > 0, "ProjectionGeometry2D", "Not enough ProjectionAngles specified.");
m_pfProjectionAngles = new float32[m_iProjectionAngleCount];
@@ -150,7 +147,7 @@ bool CProjectionGeometry2D::initialize(const Config& _cfg)
}
CC.markNodeParsed("ProjectionAngles");
- vector<float32> offset = _cfg.self->getOptionNumericalArray("ExtraDetectorOffset");
+ vector<float32> offset = _cfg.self.getOptionNumericalArray("ExtraDetectorOffset");
m_pfExtraDetectorOffset = new float32[m_iProjectionAngleCount];
if (offset.size() == (size_t)m_iProjectionAngleCount) {
for (int i = 0; i < m_iProjectionAngleCount; i++) {
diff --git a/src/ProjectionGeometry3D.cpp b/src/ProjectionGeometry3D.cpp
index 5b77767..ef0246c 100644
--- a/src/ProjectionGeometry3D.cpp
+++ b/src/ProjectionGeometry3D.cpp
@@ -149,38 +149,34 @@ bool CProjectionGeometry3D::initialize(const Config& _cfg)
ASTRA_ASSERT(_cfg.self);
// Required: DetectorWidth
- XMLNode* node = _cfg.self->getSingleNode("DetectorSpacingX");
+ XMLNode node = _cfg.self.getSingleNode("DetectorSpacingX");
ASTRA_CONFIG_CHECK(node, "ProjectionGeometry3D", "No DetectorSpacingX tag specified.");
- m_fDetectorSpacingX = boost::lexical_cast<float32>(node->getContent());
- ASTRA_DELETE(node);
+ m_fDetectorSpacingX = boost::lexical_cast<float32>(node.getContent());
CC.markNodeParsed("DetectorSpacingX");
// Required: DetectorHeight
- node = _cfg.self->getSingleNode("DetectorSpacingY");
+ node = _cfg.self.getSingleNode("DetectorSpacingY");
ASTRA_CONFIG_CHECK(node, "ProjectionGeometry3D", "No DetectorSpacingY tag specified.");
- m_fDetectorSpacingY = boost::lexical_cast<float32>(node->getContent());
- ASTRA_DELETE(node);
+ m_fDetectorSpacingY = boost::lexical_cast<float32>(node.getContent());
CC.markNodeParsed("DetectorSpacingY");
// Required: DetectorRowCount
- node = _cfg.self->getSingleNode("DetectorRowCount");
+ node = _cfg.self.getSingleNode("DetectorRowCount");
ASTRA_CONFIG_CHECK(node, "ProjectionGeometry3D", "No DetectorRowCount tag specified.");
- m_iDetectorRowCount = boost::lexical_cast<int>(node->getContent());
- ASTRA_DELETE(node);
+ m_iDetectorRowCount = boost::lexical_cast<int>(node.getContent());
CC.markNodeParsed("DetectorRowCount");
// Required: DetectorCount
- node = _cfg.self->getSingleNode("DetectorColCount");
+ node = _cfg.self.getSingleNode("DetectorColCount");
ASTRA_CONFIG_CHECK(node, "ProjectionGeometry3D", "No DetectorColCount tag specified.");
- m_iDetectorColCount = boost::lexical_cast<int>(node->getContent());
+ m_iDetectorColCount = boost::lexical_cast<int>(node.getContent());
m_iDetectorTotCount = m_iDetectorRowCount * m_iDetectorColCount;
- ASTRA_DELETE(node);
CC.markNodeParsed("DetectorColCount");
// Required: ProjectionAngles
- node = _cfg.self->getSingleNode("ProjectionAngles");
+ node = _cfg.self.getSingleNode("ProjectionAngles");
ASTRA_CONFIG_CHECK(node, "ProjectionGeometry3D", "No ProjectionAngles tag specified.");
- vector<float32> angles = node->getContentNumericalArray();
+ vector<float32> angles = node.getContentNumericalArray();
m_iProjectionAngleCount = angles.size();
ASTRA_CONFIG_CHECK(m_iProjectionAngleCount > 0, "ProjectionGeometry3D", "Not enough ProjectionAngles specified.");
m_pfProjectionAngles = new float32[m_iProjectionAngleCount];
@@ -188,7 +184,6 @@ bool CProjectionGeometry3D::initialize(const Config& _cfg)
m_pfProjectionAngles[i] = angles[i];
}
CC.markNodeParsed("ProjectionAngles");
- ASTRA_DELETE(node);
// Interface class, so don't return true
return false;
diff --git a/src/Projector2D.cpp b/src/Projector2D.cpp
index 32a2956..cf233a0 100644
--- a/src/Projector2D.cpp
+++ b/src/Projector2D.cpp
@@ -114,12 +114,12 @@ bool CProjector2D::initialize(const Config& _cfg)
}
// required: ProjectionGeometry
- XMLNode* node = _cfg.self->getSingleNode("ProjectionGeometry");
+ XMLNode node = _cfg.self.getSingleNode("ProjectionGeometry");
ASTRA_CONFIG_CHECK(node, "Projector2D", "No ProjectionGeometry tag specified.");
// FIXME: Change how the base class is created. (This is duplicated
// in astra_mex_data2d.cpp.)
- std::string type = node->getAttribute("type");
+ std::string type = node.getAttribute("type");
if (type == "sparse_matrix") {
m_pProjectionGeometry = new CSparseMatrixProjectionGeometry2D();
m_pProjectionGeometry->initialize(Config(node));
@@ -141,7 +141,7 @@ bool CProjector2D::initialize(const Config& _cfg)
// required: VolumeGeometry
- node = _cfg.self->getSingleNode("VolumeGeometry");
+ node = _cfg.self.getSingleNode("VolumeGeometry");
ASTRA_CONFIG_CHECK(node, "Projector2D", "No VolumeGeometry tag specified.");
m_pVolumeGeometry = new CVolumeGeometry2D();
m_pVolumeGeometry->initialize(Config(node));
diff --git a/src/Projector3D.cpp b/src/Projector3D.cpp
index b546ee9..5e22105 100644
--- a/src/Projector3D.cpp
+++ b/src/Projector3D.cpp
@@ -92,11 +92,11 @@ bool CProjector3D::initialize(const Config& _cfg)
assert(_cfg.self);
ConfigStackCheck<CProjector3D> CC("Projector3D", this, _cfg);
- XMLNode* node;
+ XMLNode node;
- node = _cfg.self->getSingleNode("ProjectionGeometry");
+ node = _cfg.self.getSingleNode("ProjectionGeometry");
ASTRA_CONFIG_CHECK(node, "Projector3D", "No ProjectionGeometry tag specified.");
- std::string type = node->getAttribute("type");
+ std::string type = node.getAttribute("type");
CProjectionGeometry3D* pProjGeometry = 0;
if (type == "parallel3d") {
pProjGeometry = new CParallelProjectionGeometry3D();
@@ -108,18 +108,19 @@ bool CProjector3D::initialize(const Config& _cfg)
pProjGeometry = new CConeVecProjectionGeometry3D();
} else {
// Invalid geometry type
+ ASTRA_CONFIG_CHECK(false, "Projector3D", "Invalid projection geometry type specified.");
}
pProjGeometry->initialize(Config(node)); // this deletes node
m_pProjectionGeometry = pProjGeometry;
ASTRA_CONFIG_CHECK(m_pProjectionGeometry->isInitialized(), "Projector3D", "ProjectionGeometry not initialized.");
CC.markNodeParsed("ProjectionGeometry");
- node = _cfg.self->getSingleNode("VolumeGeometry");
+ node = _cfg.self.getSingleNode("VolumeGeometry");
ASTRA_CONFIG_CHECK(node, "Projector3D", "No VolumeGeometry tag specified.");
CVolumeGeometry3D* pVolGeometry = new CVolumeGeometry3D();
pVolGeometry->initialize(Config(node)); // this deletes node
m_pVolumeGeometry = pVolGeometry;
- ASTRA_CONFIG_CHECK(m_pVolumeGeometry->isInitialized(), "Projector2D", "VolumeGeometry not initialized.");
+ ASTRA_CONFIG_CHECK(m_pVolumeGeometry->isInitialized(), "Projector3D", "VolumeGeometry not initialized.");
CC.markNodeParsed("VolumeGeometry");
return true;
diff --git a/src/ReconstructionAlgorithm2D.cpp b/src/ReconstructionAlgorithm2D.cpp
index e089fac..767efe6 100644
--- a/src/ReconstructionAlgorithm2D.cpp
+++ b/src/ReconstructionAlgorithm2D.cpp
@@ -84,71 +84,68 @@ bool CReconstructionAlgorithm2D::initialize(const Config& _cfg)
ConfigStackCheck<CAlgorithm> CC("ReconstructionAlgorithm2D", this, _cfg);
// projector
- XMLNode* node = _cfg.self->getSingleNode("ProjectorId");
+ XMLNode node = _cfg.self.getSingleNode("ProjectorId");
ASTRA_CONFIG_CHECK(node, "Reconstruction2D", "No ProjectorId tag specified.");
- int id = boost::lexical_cast<int>(node->getContent());
+ int id = boost::lexical_cast<int>(node.getContent());
m_pProjector = CProjector2DManager::getSingleton().get(id);
- ASTRA_DELETE(node);
CC.markNodeParsed("ProjectorId");
// sinogram data
- node = _cfg.self->getSingleNode("ProjectionDataId");
+ node = _cfg.self.getSingleNode("ProjectionDataId");
ASTRA_CONFIG_CHECK(node, "Reconstruction2D", "No ProjectionDataId tag specified.");
- id = boost::lexical_cast<int>(node->getContent());
+ id = boost::lexical_cast<int>(node.getContent());
m_pSinogram = dynamic_cast<CFloat32ProjectionData2D*>(CData2DManager::getSingleton().get(id));
- ASTRA_DELETE(node);
CC.markNodeParsed("ProjectionDataId");
// reconstruction data
- node = _cfg.self->getSingleNode("ReconstructionDataId");
+ node = _cfg.self.getSingleNode("ReconstructionDataId");
ASTRA_CONFIG_CHECK(node, "Reconstruction2D", "No ReconstructionDataId tag specified.");
- id = boost::lexical_cast<int>(node->getContent());
+ id = boost::lexical_cast<int>(node.getContent());
m_pReconstruction = dynamic_cast<CFloat32VolumeData2D*>(CData2DManager::getSingleton().get(id));
- ASTRA_DELETE(node);
CC.markNodeParsed("ReconstructionDataId");
// fixed mask
- if (_cfg.self->hasOption("ReconstructionMaskId")) {
+ if (_cfg.self.hasOption("ReconstructionMaskId")) {
m_bUseReconstructionMask = true;
- id = boost::lexical_cast<int>(_cfg.self->getOption("ReconstructionMaskId"));
+ id = boost::lexical_cast<int>(_cfg.self.getOption("ReconstructionMaskId"));
m_pReconstructionMask = dynamic_cast<CFloat32VolumeData2D*>(CData2DManager::getSingleton().get(id));
ASTRA_CONFIG_CHECK(m_pReconstructionMask, "Reconstruction2D", "Invalid ReconstructionMaskId.");
}
CC.markOptionParsed("ReconstructionMaskId");
// fixed mask
- if (_cfg.self->hasOption("SinogramMaskId")) {
+ if (_cfg.self.hasOption("SinogramMaskId")) {
m_bUseSinogramMask = true;
- id = boost::lexical_cast<int>(_cfg.self->getOption("SinogramMaskId"));
+ id = boost::lexical_cast<int>(_cfg.self.getOption("SinogramMaskId"));
m_pSinogramMask = dynamic_cast<CFloat32ProjectionData2D*>(CData2DManager::getSingleton().get(id));
ASTRA_CONFIG_CHECK(m_pSinogramMask, "Reconstruction2D", "Invalid SinogramMaskId.");
}
CC.markOptionParsed("SinogramMaskId");
// Constraints - NEW
- if (_cfg.self->hasOption("MinConstraint")) {
+ if (_cfg.self.hasOption("MinConstraint")) {
m_bUseMinConstraint = true;
- m_fMinValue = _cfg.self->getOptionNumerical("MinConstraint", 0.0f);
+ m_fMinValue = _cfg.self.getOptionNumerical("MinConstraint", 0.0f);
CC.markOptionParsed("MinConstraint");
} else {
// Constraint - OLD
- m_bUseMinConstraint = _cfg.self->getOptionBool("UseMinConstraint", false);
+ m_bUseMinConstraint = _cfg.self.getOptionBool("UseMinConstraint", false);
CC.markOptionParsed("UseMinConstraint");
if (m_bUseMinConstraint) {
- m_fMinValue = _cfg.self->getOptionNumerical("MinConstraintValue", 0.0f);
+ m_fMinValue = _cfg.self.getOptionNumerical("MinConstraintValue", 0.0f);
CC.markOptionParsed("MinConstraintValue");
}
}
- if (_cfg.self->hasOption("MaxConstraint")) {
+ if (_cfg.self.hasOption("MaxConstraint")) {
m_bUseMaxConstraint = true;
- m_fMaxValue = _cfg.self->getOptionNumerical("MaxConstraint", 255.0f);
+ m_fMaxValue = _cfg.self.getOptionNumerical("MaxConstraint", 255.0f);
CC.markOptionParsed("MaxConstraint");
} else {
// Constraint - OLD
- m_bUseMaxConstraint = _cfg.self->getOptionBool("UseMaxConstraint", false);
+ m_bUseMaxConstraint = _cfg.self.getOptionBool("UseMaxConstraint", false);
CC.markOptionParsed("UseMaxConstraint");
if (m_bUseMaxConstraint) {
- m_fMaxValue = _cfg.self->getOptionNumerical("MaxConstraintValue", 0.0f);
+ m_fMaxValue = _cfg.self.getOptionNumerical("MaxConstraintValue", 0.0f);
CC.markOptionParsed("MaxConstraintValue");
}
}
diff --git a/src/ReconstructionAlgorithm3D.cpp b/src/ReconstructionAlgorithm3D.cpp
index 13d069d..86b8ab2 100644
--- a/src/ReconstructionAlgorithm3D.cpp
+++ b/src/ReconstructionAlgorithm3D.cpp
@@ -104,7 +104,7 @@ bool CReconstructionAlgorithm3D::initialize(const Config& _cfg)
ASTRA_ASSERT(_cfg.self);
ConfigStackCheck<CAlgorithm> CC("ReconstructionAlgorithm3D", this, _cfg);
- XMLNode* node;
+ XMLNode node;
int id;
#if 0
// projector
@@ -116,60 +116,58 @@ bool CReconstructionAlgorithm3D::initialize(const Config& _cfg)
#endif
// sinogram data
- node = _cfg.self->getSingleNode("ProjectionDataId");
+ node = _cfg.self.getSingleNode("ProjectionDataId");
ASTRA_CONFIG_CHECK(node, "Reconstruction3D", "No ProjectionDataId tag specified.");
- id = boost::lexical_cast<int>(node->getContent());
+ id = boost::lexical_cast<int>(node.getContent());
m_pSinogram = dynamic_cast<CFloat32ProjectionData3D*>(CData3DManager::getSingleton().get(id));
- ASTRA_DELETE(node);
CC.markNodeParsed("ProjectionDataId");
// reconstruction data
- node = _cfg.self->getSingleNode("ReconstructionDataId");
+ node = _cfg.self.getSingleNode("ReconstructionDataId");
ASTRA_CONFIG_CHECK(node, "Reconstruction3D", "No ReconstructionDataId tag specified.");
- id = boost::lexical_cast<int>(node->getContent());
+ id = boost::lexical_cast<int>(node.getContent());
m_pReconstruction = dynamic_cast<CFloat32VolumeData3D*>(CData3DManager::getSingleton().get(id));
- ASTRA_DELETE(node);
CC.markNodeParsed("ReconstructionDataId");
// fixed mask
- if (_cfg.self->hasOption("ReconstructionMaskId")) {
+ if (_cfg.self.hasOption("ReconstructionMaskId")) {
m_bUseReconstructionMask = true;
- id = boost::lexical_cast<int>(_cfg.self->getOption("ReconstructionMaskId"));
+ id = boost::lexical_cast<int>(_cfg.self.getOption("ReconstructionMaskId"));
m_pReconstructionMask = dynamic_cast<CFloat32VolumeData3D*>(CData3DManager::getSingleton().get(id));
}
CC.markOptionParsed("ReconstructionMaskId");
// fixed mask
- if (_cfg.self->hasOption("SinogramMaskId")) {
+ if (_cfg.self.hasOption("SinogramMaskId")) {
m_bUseSinogramMask = true;
- id = boost::lexical_cast<int>(_cfg.self->getOption("SinogramMaskId"));
+ id = boost::lexical_cast<int>(_cfg.self.getOption("SinogramMaskId"));
m_pSinogramMask = dynamic_cast<CFloat32ProjectionData3D*>(CData3DManager::getSingleton().get(id));
}
// Constraints - NEW
- if (_cfg.self->hasOption("MinConstraint")) {
+ if (_cfg.self.hasOption("MinConstraint")) {
m_bUseMinConstraint = true;
- m_fMinValue = _cfg.self->getOptionNumerical("MinConstraint", 0.0f);
+ m_fMinValue = _cfg.self.getOptionNumerical("MinConstraint", 0.0f);
CC.markOptionParsed("MinConstraint");
} else {
// Constraint - OLD
- m_bUseMinConstraint = _cfg.self->getOptionBool("UseMinConstraint", false);
+ m_bUseMinConstraint = _cfg.self.getOptionBool("UseMinConstraint", false);
CC.markOptionParsed("UseMinConstraint");
if (m_bUseMinConstraint) {
- m_fMinValue = _cfg.self->getOptionNumerical("MinConstraintValue", 0.0f);
+ m_fMinValue = _cfg.self.getOptionNumerical("MinConstraintValue", 0.0f);
CC.markOptionParsed("MinConstraintValue");
}
}
- if (_cfg.self->hasOption("MaxConstraint")) {
+ if (_cfg.self.hasOption("MaxConstraint")) {
m_bUseMaxConstraint = true;
- m_fMaxValue = _cfg.self->getOptionNumerical("MaxConstraint", 255.0f);
+ m_fMaxValue = _cfg.self.getOptionNumerical("MaxConstraint", 255.0f);
CC.markOptionParsed("MaxConstraint");
} else {
// Constraint - OLD
- m_bUseMaxConstraint = _cfg.self->getOptionBool("UseMaxConstraint", false);
+ m_bUseMaxConstraint = _cfg.self.getOptionBool("UseMaxConstraint", false);
CC.markOptionParsed("UseMaxConstraint");
if (m_bUseMaxConstraint) {
- m_fMaxValue = _cfg.self->getOptionNumerical("MaxConstraintValue", 0.0f);
+ m_fMaxValue = _cfg.self.getOptionNumerical("MaxConstraintValue", 0.0f);
CC.markOptionParsed("MaxConstraintValue");
}
}
diff --git a/src/SartAlgorithm.cpp b/src/SartAlgorithm.cpp
index f7a1677..e4dc5c7 100644
--- a/src/SartAlgorithm.cpp
+++ b/src/SartAlgorithm.cpp
@@ -126,7 +126,7 @@ bool CSartAlgorithm::initialize(const Config& _cfg)
// projection order
m_iCurrentProjection = 0;
m_iProjectionCount = m_pProjector->getProjectionGeometry()->getProjectionAngleCount();
- string projOrder = _cfg.self->getOption("ProjectionOrder", "sequential");
+ string projOrder = _cfg.self.getOption("ProjectionOrder", "sequential");
CC.markOptionParsed("ProjectionOrder");
if (projOrder == "sequential") {
m_piProjectionOrder = new int[m_iProjectionCount];
@@ -145,7 +145,7 @@ bool CSartAlgorithm::initialize(const Config& _cfg)
m_piProjectionOrder[i + k] = t;
}
} else if (projOrder == "custom") {
- vector<float32> projOrderList = _cfg.self->getOptionNumericalArray("ProjectionOrderList");
+ vector<float32> projOrderList = _cfg.self.getOptionNumericalArray("ProjectionOrderList");
m_piProjectionOrder = new int[projOrderList.size()];
for (int i = 0; i < m_iProjectionCount; i++) {
m_piProjectionOrder[i] = static_cast<int>(projOrderList[i]);
diff --git a/src/SparseMatrixProjectionGeometry2D.cpp b/src/SparseMatrixProjectionGeometry2D.cpp
index 86357d2..073720f 100644
--- a/src/SparseMatrixProjectionGeometry2D.cpp
+++ b/src/SparseMatrixProjectionGeometry2D.cpp
@@ -98,11 +98,10 @@ bool CSparseMatrixProjectionGeometry2D::initialize(const Config& _cfg)
CProjectionGeometry2D::initialize(_cfg);
// get matrix
- XMLNode* node = _cfg.self->getSingleNode("MatrixID");
+ XMLNode node = _cfg.self.getSingleNode("MatrixID");
ASTRA_CONFIG_CHECK(node, "SparseMatrixProjectionGeometry2D", "No MatrixID tag specified.");
- int id = boost::lexical_cast<int>(node->getContent());
+ int id = boost::lexical_cast<int>(node.getContent());
m_pMatrix = CMatrixManager::getSingleton().get(id);
- ASTRA_DELETE(node);
CC.markNodeParsed("MatrixID");
// success
@@ -194,11 +193,11 @@ Config* CSparseMatrixProjectionGeometry2D::getConfiguration() const
{
Config* cfg = new Config();
cfg->initialize("ProjectionGeometry2D");
- cfg->self->addAttribute("type", "sparse matrix");
- cfg->self->addChildNode("DetectorCount", getDetectorCount());
- cfg->self->addChildNode("DetectorWidth", getDetectorWidth());
- cfg->self->addChildNode("ProjectionAngles", m_pfProjectionAngles, m_iProjectionAngleCount);
- cfg->self->addChildNode("MatrixID", CMatrixManager::getSingleton().getIndex(m_pMatrix));
+ cfg->self.addAttribute("type", "sparse matrix");
+ cfg->self.addChildNode("DetectorCount", getDetectorCount());
+ cfg->self.addChildNode("DetectorWidth", getDetectorWidth());
+ cfg->self.addChildNode("ProjectionAngles", m_pfProjectionAngles, m_iProjectionAngleCount);
+ cfg->self.addChildNode("MatrixID", CMatrixManager::getSingleton().getIndex(m_pMatrix));
return cfg;
}
diff --git a/src/VolumeGeometry2D.cpp b/src/VolumeGeometry2D.cpp
index d412914..6eea1b2 100644
--- a/src/VolumeGeometry2D.cpp
+++ b/src/VolumeGeometry2D.cpp
@@ -164,24 +164,22 @@ bool CVolumeGeometry2D::initialize(const Config& _cfg)
}
// Required: GridColCount
- XMLNode* node = _cfg.self->getSingleNode("GridColCount");
+ XMLNode node = _cfg.self.getSingleNode("GridColCount");
ASTRA_CONFIG_CHECK(node, "ReconstructionGeometry2D", "No GridColCount tag specified.");
- m_iGridColCount = boost::lexical_cast<int>(node->getContent());
- ASTRA_DELETE(node);
+ m_iGridColCount = boost::lexical_cast<int>(node.getContent());
CC.markNodeParsed("GridColCount");
// Required: GridRowCount
- node = _cfg.self->getSingleNode("GridRowCount");
+ node = _cfg.self.getSingleNode("GridRowCount");
ASTRA_CONFIG_CHECK(node, "ReconstructionGeometry2D", "No GridRowCount tag specified.");
- m_iGridRowCount = boost::lexical_cast<int>(node->getContent());
- ASTRA_DELETE(node);
+ m_iGridRowCount = boost::lexical_cast<int>(node.getContent());
CC.markNodeParsed("GridRowCount");
// Optional: Window minima and maxima
- m_fWindowMinX = _cfg.self->getOptionNumerical("WindowMinX", -m_iGridColCount/2.0f);
- m_fWindowMaxX = _cfg.self->getOptionNumerical("WindowMaxX", m_iGridColCount/2.0f);
- m_fWindowMinY = _cfg.self->getOptionNumerical("WindowMinY", -m_iGridRowCount/2.0f);
- m_fWindowMaxY = _cfg.self->getOptionNumerical("WindowMaxY", m_iGridRowCount/2.0f);
+ m_fWindowMinX = _cfg.self.getOptionNumerical("WindowMinX", -m_iGridColCount/2.0f);
+ m_fWindowMaxX = _cfg.self.getOptionNumerical("WindowMaxX", m_iGridColCount/2.0f);
+ m_fWindowMinY = _cfg.self.getOptionNumerical("WindowMinY", -m_iGridRowCount/2.0f);
+ m_fWindowMaxY = _cfg.self.getOptionNumerical("WindowMaxY", m_iGridRowCount/2.0f);
CC.markOptionParsed("WindowMinX");
CC.markOptionParsed("WindowMaxX");
CC.markOptionParsed("WindowMinY");
@@ -285,13 +283,13 @@ Config* CVolumeGeometry2D::getConfiguration() const
Config* cfg = new Config();
cfg->initialize("VolumeGeometry2D");
- cfg->self->addChildNode("GridColCount", m_iGridColCount);
- cfg->self->addChildNode("GridRowCount", m_iGridRowCount);
+ cfg->self.addChildNode("GridColCount", m_iGridColCount);
+ cfg->self.addChildNode("GridRowCount", m_iGridRowCount);
- cfg->self->addOption("WindowMinX", m_fWindowMinX);
- cfg->self->addOption("WindowMaxX", m_fWindowMaxX);
- cfg->self->addOption("WindowMinY", m_fWindowMinY);
- cfg->self->addOption("WindowMaxY", m_fWindowMaxY);
+ cfg->self.addOption("WindowMinX", m_fWindowMinX);
+ cfg->self.addOption("WindowMaxX", m_fWindowMaxX);
+ cfg->self.addOption("WindowMinY", m_fWindowMinY);
+ cfg->self.addOption("WindowMaxY", m_fWindowMaxY);
return cfg;
}
diff --git a/src/VolumeGeometry3D.cpp b/src/VolumeGeometry3D.cpp
index 66e6f0c..a1cf424 100644
--- a/src/VolumeGeometry3D.cpp
+++ b/src/VolumeGeometry3D.cpp
@@ -192,33 +192,30 @@ bool CVolumeGeometry3D::initialize(const Config& _cfg)
}
// Required: GridColCount
- XMLNode* node = _cfg.self->getSingleNode("GridColCount");
+ XMLNode node = _cfg.self.getSingleNode("GridColCount");
ASTRA_CONFIG_CHECK(node, "ReconstructionGeometry2D", "No GridColCount tag specified.");
- m_iGridColCount = boost::lexical_cast<int>(node->getContent());
- ASTRA_DELETE(node);
+ m_iGridColCount = boost::lexical_cast<int>(node.getContent());
CC.markNodeParsed("GridColCount");
// Required: GridRowCount
- node = _cfg.self->getSingleNode("GridRowCount");
+ node = _cfg.self.getSingleNode("GridRowCount");
ASTRA_CONFIG_CHECK(node, "ReconstructionGeometry2D", "No GridRowCount tag specified.");
- m_iGridRowCount = boost::lexical_cast<int>(node->getContent());
- ASTRA_DELETE(node);
+ m_iGridRowCount = boost::lexical_cast<int>(node.getContent());
CC.markNodeParsed("GridRowCount");
// Required: GridRowCount
- node = _cfg.self->getSingleNode("GridSliceCount");
+ node = _cfg.self.getSingleNode("GridSliceCount");
ASTRA_CONFIG_CHECK(node, "ReconstructionGeometry2D", "No GridSliceCount tag specified.");
- m_iGridSliceCount = boost::lexical_cast<int>(node->getContent());
- ASTRA_DELETE(node);
+ m_iGridSliceCount = boost::lexical_cast<int>(node.getContent());
CC.markNodeParsed("GridSliceCount");
// Optional: Window minima and maxima
- m_fWindowMinX = _cfg.self->getOptionNumerical("WindowMinX", -m_iGridColCount/2.0f);
- m_fWindowMaxX = _cfg.self->getOptionNumerical("WindowMaxX", m_iGridColCount/2.0f);
- m_fWindowMinY = _cfg.self->getOptionNumerical("WindowMinY", -m_iGridRowCount/2.0f);
- m_fWindowMaxY = _cfg.self->getOptionNumerical("WindowMaxY", m_iGridRowCount/2.0f);
- m_fWindowMinZ = _cfg.self->getOptionNumerical("WindowMinZ", -m_iGridSliceCount/2.0f);
- m_fWindowMaxZ = _cfg.self->getOptionNumerical("WindowMaxZ", m_iGridSliceCount/2.0f);
+ m_fWindowMinX = _cfg.self.getOptionNumerical("WindowMinX", -m_iGridColCount/2.0f);
+ m_fWindowMaxX = _cfg.self.getOptionNumerical("WindowMaxX", m_iGridColCount/2.0f);
+ m_fWindowMinY = _cfg.self.getOptionNumerical("WindowMinY", -m_iGridRowCount/2.0f);
+ m_fWindowMaxY = _cfg.self.getOptionNumerical("WindowMaxY", m_iGridRowCount/2.0f);
+ m_fWindowMinZ = _cfg.self.getOptionNumerical("WindowMinZ", -m_iGridSliceCount/2.0f);
+ m_fWindowMaxZ = _cfg.self.getOptionNumerical("WindowMaxZ", m_iGridSliceCount/2.0f);
CC.markOptionParsed("WindowMinX");
CC.markOptionParsed("WindowMaxX");
CC.markOptionParsed("WindowMinY");
@@ -386,16 +383,16 @@ Config* CVolumeGeometry3D::getConfiguration() const
Config* cfg = new Config();
cfg->initialize("VolumeGeometry3D");
- cfg->self->addChildNode("GridColCount", m_iGridColCount);
- cfg->self->addChildNode("GridRowCount", m_iGridRowCount);
- cfg->self->addChildNode("GridSliceCount", m_iGridSliceCount);
+ cfg->self.addChildNode("GridColCount", m_iGridColCount);
+ cfg->self.addChildNode("GridRowCount", m_iGridRowCount);
+ cfg->self.addChildNode("GridSliceCount", m_iGridSliceCount);
- cfg->self->addOption("WindowMinX", m_fWindowMinX);
- cfg->self->addOption("WindowMaxX", m_fWindowMaxX);
- cfg->self->addOption("WindowMinY", m_fWindowMinY);
- cfg->self->addOption("WindowMaxY", m_fWindowMaxY);
- cfg->self->addOption("WindowMinZ", m_fWindowMinZ);
- cfg->self->addOption("WindowMaxZ", m_fWindowMaxZ);
+ cfg->self.addOption("WindowMinX", m_fWindowMinX);
+ cfg->self.addOption("WindowMaxX", m_fWindowMaxX);
+ cfg->self.addOption("WindowMinY", m_fWindowMinY);
+ cfg->self.addOption("WindowMaxY", m_fWindowMaxY);
+ cfg->self.addOption("WindowMinZ", m_fWindowMinZ);
+ cfg->self.addOption("WindowMaxZ", m_fWindowMaxZ);
return cfg;
}
diff --git a/src/XMLDocument.cpp b/src/XMLDocument.cpp
index 406564f..716ed9e 100644
--- a/src/XMLDocument.cpp
+++ b/src/XMLDocument.cpp
@@ -32,13 +32,8 @@ $Id$
#include <iostream>
#include <sstream>
-#ifdef _MSC_VER
#include "rapidxml/rapidxml.hpp"
#include "rapidxml/rapidxml_print.hpp"
-#else
-#include "rapidxml.hpp"
-#include "rapidxml_print.hpp"
-#endif
using namespace rapidxml;
using namespace astra;
@@ -94,10 +89,9 @@ XMLDocument* XMLDocument::createDocument(string sRootName)
}
//-----------------------------------------------------------------------------
-XMLNode* XMLDocument::getRootNode()
+XMLNode XMLDocument::getRootNode()
{
- // TODO: clean up: this 'new' requires callers to do memory management
- return new XMLNode(fDOMDocument->first_node());
+ return XMLNode(fDOMDocument->first_node());
}
//-----------------------------------------------------------------------------
diff --git a/src/XMLNode.cpp b/src/XMLNode.cpp
index 4b2bdf4..0ec701f 100644
--- a/src/XMLNode.cpp
+++ b/src/XMLNode.cpp
@@ -28,15 +28,15 @@ $Id$
#include "astra/XMLNode.h"
-#ifdef _MSC_VER
#include "rapidxml/rapidxml.hpp"
#include "rapidxml/rapidxml_print.hpp"
-#else
-#include "rapidxml.hpp"
-#include "rapidxml_print.hpp"
-#endif
#include <boost/lexical_cast.hpp>
+#include <boost/algorithm/string.hpp>
+#include <boost/algorithm/string/split.hpp>
+#include <boost/algorithm/string/classification.hpp>
+
+
using namespace rapidxml;
using namespace astra;
@@ -44,21 +44,10 @@ using namespace std;
//-----------------------------------------------------------------------------
-// Utility function to delete a list of nodes
-static void deleteNodes(list<XMLNode*>& nodes)
-{
- for (list<XMLNode*>::iterator i = nodes.begin(); i != nodes.end(); ++i)
- delete (*i);
-
- nodes.clear();
-}
-
-
-//-----------------------------------------------------------------------------
// default constructor
XMLNode::XMLNode()
{
-
+ fDOMElement = 0;
}
//-----------------------------------------------------------------------------
@@ -84,14 +73,14 @@ void XMLNode::setDOMNode(xml_node<>* n)
//-----------------------------------------------------------------------------
// print XML Node
-void XMLNode::print()
+void XMLNode::print() const
{
std::cout << fDOMElement;
}
//-----------------------------------------------------------------------------
// print XML Node
-std::string XMLNode::toString()
+std::string XMLNode::toString() const
{
std::string s;
::print(std::back_inserter(s), *fDOMElement, 0);
@@ -100,64 +89,61 @@ std::string XMLNode::toString()
//-----------------------------------------------------------------------------
// Get single node
-XMLNode* XMLNode::getSingleNode(string name)
+XMLNode XMLNode::getSingleNode(string name) const
{
xml_node<> *node = fDOMElement->first_node(name.c_str());
- if (node)
- return new XMLNode(node);
- else
- return 0;
+ return XMLNode(node);
}
//-----------------------------------------------------------------------------
// Get list of nodes
-list<XMLNode*> XMLNode::getNodes(string name)
+list<XMLNode> XMLNode::getNodes(string name) const
{
- list<XMLNode*> result;
+ list<XMLNode> result;
xml_node<> *iter;
for (iter = fDOMElement->first_node(name.c_str()); iter; iter = iter->next_sibling(name.c_str())) {
- result.push_back(new XMLNode(iter));
+ result.push_back(XMLNode(iter));
}
return result;
}
//-----------------------------------------------------------------------------
// Get list of nodes
-list<XMLNode*> XMLNode::getNodes()
+list<XMLNode> XMLNode::getNodes() const
{
- list<XMLNode*> result;
+ list<XMLNode> result;
xml_node<> *iter;
for (iter = fDOMElement->first_node(); iter; iter = iter->next_sibling()) {
- result.push_back(new XMLNode(iter));
+ result.push_back(XMLNode(iter));
}
return result;
}
//-----------------------------------------------------------------------------
// Get name of this node
-std::string XMLNode::getName()
+std::string XMLNode::getName() const
{
return fDOMElement->name();
}
//-----------------------------------------------------------------------------
// Get node content - STRING
-string XMLNode::getContent()
+string XMLNode::getContent() const
{
return fDOMElement->value();
}
//-----------------------------------------------------------------------------
// Get node content - NUMERICAL
-float32 XMLNode::getContentNumerical()
+float32 XMLNode::getContentNumerical() const
{
return boost::lexical_cast<float32>(getContent());
}
//-----------------------------------------------------------------------------
// Get node content - BOOLEAN
-bool XMLNode::getContentBool()
+bool XMLNode::getContentBool() const
{
string res = getContent();
return ((res == "1") || (res == "yes") || (res == "true") || (res == "on"));
@@ -165,21 +151,20 @@ bool XMLNode::getContentBool()
//-----------------------------------------------------------------------------
// Get node content - STRING LIST
-vector<string> XMLNode::getContentArray()
+vector<string> XMLNode::getContentArray() const
{
// get listsize
int iSize = boost::lexical_cast<int>(getAttribute("listsize"));
// create result array
vector<string> res(iSize);
// loop all list item nodes
- list<XMLNode*> nodes = getNodes("ListItem");
- for (list<XMLNode*>::iterator it = nodes.begin(); it != nodes.end(); it++) {
- int iIndex = (*it)->getAttributeNumerical("index");
- string sValue = (*it)->getAttribute("value");
+ list<XMLNode> nodes = getNodes("ListItem");
+ for (list<XMLNode>::iterator it = nodes.begin(); it != nodes.end(); it++) {
+ int iIndex = it->getAttributeNumerical("index");
+ string sValue = it->getAttribute("value");
ASTRA_ASSERT(iIndex < iSize);
res[iIndex] = sValue;
}
- deleteNodes(nodes);
// return
return res;
@@ -187,85 +172,48 @@ vector<string> XMLNode::getContentArray()
//-----------------------------------------------------------------------------
// Get node content - NUMERICAL LIST
-vector<float32> XMLNode::getContentNumericalArray()
+// NB: A 2D matrix is returned as a linear list
+vector<float32> XMLNode::getContentNumericalArray() const
{
- // is scalar
- if (!hasAttribute("listsize")) {
- vector<float32> res(1);
- res[0] = getContentNumerical();
- return res;
- }
+ string input = getContent();
- int iSize = boost::lexical_cast<int>(getAttribute("listsize"));
- // create result array
- vector<float32> res(iSize);
- // loop all list item nodes
- list<XMLNode*> nodes = getNodes("ListItem");
- for (list<XMLNode*>::iterator it = nodes.begin(); it != nodes.end(); it++) {
- int iIndex = (*it)->getAttributeNumerical("index");
- float32 fValue = (*it)->getAttributeNumerical("value");
- ASTRA_ASSERT(iIndex < iSize);
- res[iIndex] = fValue;
- }
- deleteNodes(nodes);
- // return
- return res;
-}
+ // split
+ std::vector<std::string> items;
+ boost::split(items, input, boost::is_any_of(",;"));
-vector<double> XMLNode::getContentNumericalArrayDouble()
-{
- // is scalar
- if (!hasAttribute("listsize")) {
- vector<double> res(1);
- res[0] = getContentNumerical();
- return res;
- }
+ // init list
+ vector<float32> out;
+ out.resize(items.size());
- int iSize = boost::lexical_cast<int>(getAttribute("listsize"));
- // create result array
- vector<double> res(iSize);
- // loop all list item nodes
- list<XMLNode*> nodes = getNodes("ListItem");
- for (list<XMLNode*>::iterator it = nodes.begin(); it != nodes.end(); it++) {
- int iIndex = (*it)->getAttributeNumerical("index");
- double fValue = (*it)->getAttributeNumericalDouble("value");
- ASTRA_ASSERT(iIndex < iSize);
- res[iIndex] = fValue;
+ // loop elements
+ for (unsigned int i = 0; i < items.size(); i++) {
+ out[i] = boost::lexical_cast<float32>(items[i]);
}
- deleteNodes(nodes);
- // return
- return res;
+ return out;
}
-//-----------------------------------------------------------------------------
-// Get node content - NUMERICAL LIST 2
-void XMLNode::getContentNumericalArray(float32*& _pfData, int& _iSize)
+vector<double> XMLNode::getContentNumericalArrayDouble() const
{
- // is scalar
- if (!hasAttribute("listsize")) {
- _iSize = 1;
- _pfData = new float32[_iSize];
- _pfData[0] = getContentNumerical();
- return;
- }
- // get listsize
- _iSize = boost::lexical_cast<int>(getAttribute("listsize"));
- // create result array
- _pfData = new float32[_iSize];
- // loop all list item nodes
- list<XMLNode*> nodes = getNodes("ListItem");
- for (list<XMLNode*>::iterator it = nodes.begin(); it != nodes.end(); it++) {
- int iIndex = (*it)->getAttributeNumerical("index");
- float32 fValue = (*it)->getAttributeNumerical("value");
- ASTRA_ASSERT(iIndex < _iSize);
- _pfData[iIndex] = fValue;
+ string input = getContent();
+
+ // split
+ std::vector<std::string> items;
+ boost::split(items, input, boost::is_any_of(",;"));
+
+ // init list
+ vector<double> out;
+ out.resize(items.size());
+
+ // loop elements
+ for (unsigned int i = 0; i < items.size(); i++) {
+ out[i] = boost::lexical_cast<double>(items[i]);
}
- deleteNodes(nodes);
+ return out;
}
//-----------------------------------------------------------------------------
// Is attribute?
-bool XMLNode::hasAttribute(string _sName)
+bool XMLNode::hasAttribute(string _sName) const
{
xml_attribute<> *attr = fDOMElement->first_attribute(_sName.c_str());
return (attr != 0);
@@ -273,7 +221,7 @@ bool XMLNode::hasAttribute(string _sName)
//-----------------------------------------------------------------------------
// Get attribute - STRING
-string XMLNode::getAttribute(string _sName, string _sDefaultValue)
+string XMLNode::getAttribute(string _sName, string _sDefaultValue) const
{
xml_attribute<> *attr = fDOMElement->first_attribute(_sName.c_str());
@@ -284,12 +232,12 @@ string XMLNode::getAttribute(string _sName, string _sDefaultValue)
//-----------------------------------------------------------------------------
// Get attribute - NUMERICAL
-float32 XMLNode::getAttributeNumerical(string _sName, float32 _fDefaultValue)
+float32 XMLNode::getAttributeNumerical(string _sName, float32 _fDefaultValue) const
{
if (!hasAttribute(_sName)) return _fDefaultValue;
return boost::lexical_cast<float32>(getAttribute(_sName));
}
-double XMLNode::getAttributeNumericalDouble(string _sName, double _fDefaultValue)
+double XMLNode::getAttributeNumericalDouble(string _sName, double _fDefaultValue) const
{
if (!hasAttribute(_sName)) return _fDefaultValue;
return boost::lexical_cast<double>(getAttribute(_sName));
@@ -297,7 +245,7 @@ double XMLNode::getAttributeNumericalDouble(string _sName, double _fDefaultValue
//-----------------------------------------------------------------------------
// Get attribute - BOOLEAN
-bool XMLNode::getAttributeBool(string _sName, bool _bDefaultValue)
+bool XMLNode::getAttributeBool(string _sName, bool _bDefaultValue) const
{
if (!hasAttribute(_sName)) return _bDefaultValue;
string res = getAttribute(_sName);
@@ -306,7 +254,7 @@ bool XMLNode::getAttributeBool(string _sName, bool _bDefaultValue)
//-----------------------------------------------------------------------------
// Has option?
-bool XMLNode::hasOption(string _sKey)
+bool XMLNode::hasOption(string _sKey) const
{
xml_node<> *iter;
for (iter = fDOMElement->first_node("Option"); iter; iter = iter->next_sibling("Option")) {
@@ -319,7 +267,7 @@ bool XMLNode::hasOption(string _sKey)
//-----------------------------------------------------------------------------
// Get option - STRING
-string XMLNode::getOption(string _sKey, string _sDefaultValue)
+string XMLNode::getOption(string _sKey, string _sDefaultValue) const
{
xml_node<> *iter;
for (iter = fDOMElement->first_node("Option"); iter; iter = iter->next_sibling("Option")) {
@@ -336,7 +284,7 @@ string XMLNode::getOption(string _sKey, string _sDefaultValue)
//-----------------------------------------------------------------------------
// Get option - NUMERICAL
-float32 XMLNode::getOptionNumerical(string _sKey, float32 _fDefaultValue)
+float32 XMLNode::getOptionNumerical(string _sKey, float32 _fDefaultValue) const
{
if (!hasOption(_sKey)) return _fDefaultValue;
return boost::lexical_cast<float32>(getOption(_sKey));
@@ -344,7 +292,7 @@ float32 XMLNode::getOptionNumerical(string _sKey, float32 _fDefaultValue)
//-----------------------------------------------------------------------------
// Get option - BOOL
-bool XMLNode::getOptionBool(string _sKey, bool _bDefaultValue)
+bool XMLNode::getOptionBool(string _sKey, bool _bDefaultValue) const
{
bool bHasOption = hasOption(_sKey);
if (!bHasOption) return _bDefaultValue;
@@ -354,20 +302,18 @@ bool XMLNode::getOptionBool(string _sKey, bool _bDefaultValue)
//-----------------------------------------------------------------------------
// Get option - NUMERICAL ARRAY
-vector<float32> XMLNode::getOptionNumericalArray(string _sKey)
+vector<float32> XMLNode::getOptionNumericalArray(string _sKey) const
{
if (!hasOption(_sKey)) return vector<float32>();
- list<XMLNode*> nodes = getNodes("Option");
- for (list<XMLNode*>::iterator it = nodes.begin(); it != nodes.end(); it++) {
- if ((*it)->getAttribute("key") == _sKey) {
- vector<float32> vals = (*it)->getContentNumericalArray();
- deleteNodes(nodes);
+ list<XMLNode> nodes = getNodes("Option");
+ for (list<XMLNode>::iterator it = nodes.begin(); it != nodes.end(); it++) {
+ if (it->getAttribute("key") == _sKey) {
+ vector<float32> vals = it->getContentNumericalArray();
return vals;
}
}
- deleteNodes(nodes);
return vector<float32>();
}
@@ -390,41 +336,40 @@ vector<float32> XMLNode::getOptionNumericalArray(string _sKey)
//-----------------------------------------------------------------------------
// Add child node - EMPTY
-XMLNode* XMLNode::addChildNode(string _sNodeName)
+XMLNode XMLNode::addChildNode(string _sNodeName)
{
xml_document<> *doc = fDOMElement->document();
char *node_name = doc->allocate_string(_sNodeName.c_str());
xml_node<> *node = doc->allocate_node(node_element, node_name);
fDOMElement->append_node(node);
- // TODO: clean up: this 'new' requires callers to do memory management
- return new XMLNode(node);
+ return XMLNode(node);
}
//-----------------------------------------------------------------------------
// Add child node - STRING
-XMLNode* XMLNode::addChildNode(string _sNodeName, string _sText)
+XMLNode XMLNode::addChildNode(string _sNodeName, string _sText)
{
- XMLNode* res = addChildNode(_sNodeName);
- res->setContent(_sText);
+ XMLNode res = addChildNode(_sNodeName);
+ res.setContent(_sText);
return res;
}
//-----------------------------------------------------------------------------
// Add child node - FLOAT
-XMLNode* XMLNode::addChildNode(string _sNodeName, float32 _fValue)
+XMLNode XMLNode::addChildNode(string _sNodeName, float32 _fValue)
{
- XMLNode* res = addChildNode(_sNodeName);
- res->setContent(_fValue);
+ XMLNode res = addChildNode(_sNodeName);
+ res.setContent(_fValue);
return res;
}
//-----------------------------------------------------------------------------
// Add child node - LIST
-XMLNode* XMLNode::addChildNode(string _sNodeName, float32* _pfList, int _iSize)
+XMLNode XMLNode::addChildNode(string _sNodeName, float32* _pfList, int _iSize)
{
- XMLNode* res = addChildNode(_sNodeName);
- res->setContent(_pfList, _iSize);
+ XMLNode res = addChildNode(_sNodeName);
+ res.setContent(_pfList, _iSize);
return res;
}
@@ -446,15 +391,68 @@ void XMLNode::setContent(float32 _fValue)
//-----------------------------------------------------------------------------
// Set content - LIST
-void XMLNode::setContent(float32* pfList, int _iSize)
-{
+
+template<typename T>
+static std::string setContentList_internal(T* pfList, int _iSize) {
std::string str = (_iSize > 0) ? boost::lexical_cast<std::string>(pfList[0]) : "";
for (int i = 1; i < _iSize; i++) {
str += "," + boost::lexical_cast<std::string>(pfList[i]);
}
- setContent(str);
+ return str;
+}
+
+void XMLNode::setContent(float32* pfList, int _iSize)
+{
+ setContent(setContentList_internal<float32>(pfList, _iSize));
+}
+
+void XMLNode::setContent(double* pfList, int _iSize)
+{
+ setContent(setContentList_internal<double>(pfList, _iSize));
+}
+
+//-----------------------------------------------------------------------------
+// Set content - MATRIX
+
+template<typename T>
+static std::string setContentMatrix_internal(T* _pfMatrix, int _iWidth, int _iHeight, bool transposed)
+{
+ std::string str = "";
+
+ int s1,s2;
+
+ if (!transposed) {
+ s1 = 1;
+ s2 = _iWidth;
+ } else {
+ s1 = _iHeight;
+ s2 = 1;
+ }
+
+ for (int y = 0; y < _iHeight; ++y) {
+ if (_iWidth > 0)
+ str += boost::lexical_cast<std::string>(_pfMatrix[0*s1 + y*s2]);
+ for (int x = 1; x < _iWidth; x++)
+ str += "," + boost::lexical_cast<std::string>(_pfMatrix[x*s1 + y*s2]);
+
+ if (y != _iHeight-1)
+ str += ";";
+ }
+
+ return str;
}
+void XMLNode::setContent(float32* _pfMatrix, int _iWidth, int _iHeight, bool transposed)
+{
+ setContent(setContentMatrix_internal<float32>(_pfMatrix, _iWidth, _iHeight, transposed));
+}
+
+void XMLNode::setContent(double* _pfMatrix, int _iWidth, int _iHeight, bool transposed)
+{
+ setContent(setContentMatrix_internal<double>(_pfMatrix, _iWidth, _iHeight, transposed));
+}
+
+
//-----------------------------------------------------------------------------
// Add attribute - STRING
void XMLNode::addAttribute(string _sName, string _sText)
@@ -477,20 +475,18 @@ void XMLNode::addAttribute(string _sName, float32 _fValue)
// Add option - STRING
void XMLNode::addOption(string _sName, string _sText)
{
- XMLNode* node = addChildNode("Option");
- node->addAttribute("key", _sName);
- node->addAttribute("value", _sText);
- delete node;
+ XMLNode node = addChildNode("Option");
+ node.addAttribute("key", _sName);
+ node.addAttribute("value", _sText);
}
//-----------------------------------------------------------------------------
// Add option - FLOAT
void XMLNode::addOption(string _sName, float32 _sText)
{
- XMLNode* node = addChildNode("Option");
- node->addAttribute("key", _sName);
- node->addAttribute("value", _sText);
- delete node;
+ XMLNode node = addChildNode("Option");
+ node.addAttribute("key", _sName);
+ node.addAttribute("value", _sText);
}
//-----------------------------------------------------------------------------
diff --git a/tests/test_Fourier.cpp b/tests/test_Fourier.cpp
index 2602edb..ef12747 100644
--- a/tests/test_Fourier.cpp
+++ b/tests/test_Fourier.cpp
@@ -105,8 +105,8 @@ BOOST_AUTO_TEST_CASE( testFourier_FFT_1D_1 )
{
astra::float32 inR[8] = { 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f };
astra::float32 inI[8] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
- astra::float32 outR[5];
- astra::float32 outI[5];
+ astra::float32 outR[8];
+ astra::float32 outI[8];
astra::fastTwoPowerFourierTransform1D(8, inR, inI, outR, outI, 1, 1, false);
diff --git a/tests/test_ParallelBeamLineKernelProjector2D.cpp b/tests/test_ParallelBeamLineKernelProjector2D.cpp
index 86bc54f..c56ff37 100644
--- a/tests/test_ParallelBeamLineKernelProjector2D.cpp
+++ b/tests/test_ParallelBeamLineKernelProjector2D.cpp
@@ -77,6 +77,8 @@ BOOST_FIXTURE_TEST_CASE( testParallelBeamLineKernelProjector2D_Rectangle, TestPa
fWeight += pPix[i].m_fWeight;
BOOST_CHECK_SMALL(fWeight - 7.13037f, 0.00001f);
+
+ delete[] pPix;
}
diff --git a/tests/test_XMLDocument.cpp b/tests/test_XMLDocument.cpp
index adabdd6..95429cb 100644
--- a/tests/test_XMLDocument.cpp
+++ b/tests/test_XMLDocument.cpp
@@ -32,18 +32,22 @@ $Id$
#include <boost/test/auto_unit_test.hpp>
#include "astra/XMLDocument.h"
+#include "astra/Config.h"
BOOST_AUTO_TEST_CASE( testXMLDocument_Constructor1 )
{
astra::XMLDocument *doc = astra::XMLDocument::createDocument("test");
BOOST_REQUIRE(doc);
- astra::XMLNode *root = doc->getRootNode();
+ astra::XMLNode root = doc->getRootNode();
BOOST_REQUIRE(root);
- BOOST_CHECK(root->getName() == "test");
- BOOST_CHECK(root->getContent().empty());
+ BOOST_CHECK(root.getName() == "test");
+ BOOST_CHECK(root.getContent().empty());
+
+ delete doc;
+
}
BOOST_AUTO_TEST_CASE( testXMLDocument_FileIO )
@@ -53,12 +57,15 @@ BOOST_AUTO_TEST_CASE( testXMLDocument_FileIO )
doc->saveToFile("test.xml");
astra::XMLDocument *doc2 = astra::XMLDocument::readFromFile("test.xml");
- astra::XMLNode *root = doc2->getRootNode();
+ astra::XMLNode root = doc2->getRootNode();
BOOST_REQUIRE(root);
- BOOST_CHECK(root->getName() == "test");
- BOOST_CHECK(root->getContent().empty());
+ BOOST_CHECK(root.getName() == "test");
+ BOOST_CHECK(root.getContent().empty());
+
+ delete doc2;
+ delete doc;
}
@@ -67,32 +74,28 @@ BOOST_AUTO_TEST_CASE( testXMLDocument_CreateNodes )
astra::XMLDocument *doc = astra::XMLDocument::createDocument("test");
BOOST_REQUIRE(doc);
- astra::XMLNode *root = doc->getRootNode();
+ astra::XMLNode root = doc->getRootNode();
BOOST_REQUIRE(root);
- astra::XMLNode *node = root->addChildNode("child");
+ astra::XMLNode node = root.addChildNode("child");
BOOST_REQUIRE(node);
- node->addAttribute("attr", "val");
+ node.addAttribute("attr", "val");
doc->saveToFile("test2.xml");
- delete node;
- delete root;
delete doc;
doc = astra::XMLDocument::readFromFile("test2.xml");
BOOST_REQUIRE(doc);
root = doc->getRootNode();
BOOST_REQUIRE(node);
- node = root->getSingleNode("child");
+ node = root.getSingleNode("child");
BOOST_REQUIRE(node);
- BOOST_CHECK(node->hasAttribute("attr"));
- BOOST_CHECK(node->getAttribute("attr") == "val");
+ BOOST_CHECK(node.hasAttribute("attr"));
+ BOOST_CHECK(node.getAttribute("attr") == "val");
- delete node;
- delete root;
delete doc;
}
@@ -101,16 +104,18 @@ BOOST_AUTO_TEST_CASE( testXMLDocument_Options )
astra::XMLDocument *doc = astra::XMLDocument::createDocument("test");
BOOST_REQUIRE(doc);
- astra::XMLNode *root = doc->getRootNode();
+ astra::XMLNode root = doc->getRootNode();
BOOST_REQUIRE(root);
- BOOST_CHECK(!root->hasOption("opt"));
+ BOOST_CHECK(!root.hasOption("opt"));
+
+ root.addOption("opt", "val");
- root->addOption("opt", "val");
+ BOOST_CHECK(root.hasOption("opt"));
- BOOST_CHECK(root->hasOption("opt"));
+ BOOST_CHECK(root.getOption("opt") == "val");
- BOOST_CHECK(root->getOption("opt") == "val");
+ delete doc;
}
@@ -119,40 +124,51 @@ BOOST_AUTO_TEST_CASE( testXMLDocument_List )
astra::XMLDocument *doc = astra::XMLDocument::createDocument("test");
BOOST_REQUIRE(doc);
- astra::XMLNode *root = doc->getRootNode();
+ astra::XMLNode root = doc->getRootNode();
BOOST_REQUIRE(root);
- astra::XMLNode *node = root->addChildNode("child");
+ astra::XMLNode node = root.addChildNode("child");
BOOST_REQUIRE(node);
float fl[] = { 1.0, 3.5, 2.0, 4.75 };
- node->setContent(fl, sizeof(fl)/sizeof(fl[0]));
+ node.setContent(fl, sizeof(fl)/sizeof(fl[0]));
doc->saveToFile("test3.xml");
- delete node;
- delete root;
delete doc;
doc = astra::XMLDocument::readFromFile("test3.xml");
BOOST_REQUIRE(doc);
root = doc->getRootNode();
BOOST_REQUIRE(root);
- node = root->getSingleNode("child");
+ node = root.getSingleNode("child");
BOOST_REQUIRE(node);
- std::vector<astra::float32> f = node->getContentNumericalArray();
+ std::vector<astra::float32> f = node.getContentNumericalArray();
BOOST_CHECK(f[0] == fl[0]);
BOOST_CHECK(f[1] == fl[1]);
BOOST_CHECK(f[2] == fl[2]);
BOOST_CHECK(f[3] == fl[3]);
- delete node;
- delete root;
delete doc;
}
+BOOST_AUTO_TEST_CASE( testXMLDocument_Config )
+{
+ astra::Config* cfg = new astra::Config();
+ cfg->initialize("VolumeGeometry2D");
+
+ cfg->self.addChildNode("GridColCount", 1);
+ cfg->self.addChildNode("GridRowCount", 2);
+
+ cfg->self.addOption("WindowMinX", 3);
+ cfg->self.addOption("WindowMaxX", 4);
+ cfg->self.addOption("WindowMinY", 5);
+ cfg->self.addOption("WindowMaxY", 6);
+
+ delete cfg;
+}