Skip to content

Commit

Permalink
Merge pull request #33 from dkazanc/cmaking
Browse files Browse the repository at this point in the history
CMake interface, major restructure of the package. Updated demos.
  • Loading branch information
dkazanc authored Oct 4, 2018
2 parents d78422d + 4cf19d6 commit 8e9d0c3
Show file tree
Hide file tree
Showing 82 changed files with 4,723 additions and 576 deletions.
37 changes: 37 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2017 Edoardo Pasca
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required (VERSION 3.0)

project(TomoPhantom)
#https://stackoverflow.com/questions/13298504/using-cmake-with-setup-py

# The version number.
set (CIL_VERSION_MAJOR 0)
set (CIL_VERSION_MINOR 11)
set (CIL_VERSION_PATCH 0)

set (CIL_VERSION '${CIL_VERSION_MAJOR}.${CIL_VERSION_MINOR}.${CIL_VERSION_PATCH}' CACHE INTERNAL "Core Imaging Library version" FORCE)

# set the Python variables for the Conda environment
#include(${CMAKE_SOURCE_DIR}/CMake/FindAnacondaEnvironment.cmake)

set(CMAKE_BUILD_TYPE "Release")

option (BUILD_MATLAB_WRAPPER "Build Matlab Wrappers" OFF)
option (BUILD_PYTHON_WRAPPER "Build Python Wrappers" ON)
option (CONDA_BUILD "Conda Build" OFF)

add_subdirectory(Core)
add_subdirectory(Wrappers)
47 changes: 47 additions & 0 deletions Core/CCPiDefines.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
# -*- coding: utf-8 -*-
# This work is part of the Core Imaging Library developed by
# Visual Analytics and Imaging System Group of the Science Technology
# Facilities Council, STFC
# Copyright 2018 CCPi
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Code is derived from code developed by Prof. Brian Bay
*/

#ifndef CCPIDEFINES_H
#define CCPIDEFINES_H

#if defined(_WIN32) || defined(__WIN32__)
#if defined(cilDVC_EXPORTS) || defined(CCPiNexusWidget_EXPORTS) || defined(CCPi_EXPORTS)// add by CMake
#define CCPI_EXPORT __declspec(dllexport)
#define EXPIMP_TEMPLATE
#else
#define CCPI_EXPORT __declspec(dllimport)
#define EXPIMP_TEMPLATE extern
#endif CCPi_EXPORTS
#elif defined(linux) || defined(__linux) || defined(__APPLE__)
#define CCPI_EXPORT
#endif

// Revised:

#define DAY_REV 25
#define MONTH_REV "Nov"
#define YEAR_REV 2017

#define VERSION 1.30

#endif
118 changes: 118 additions & 0 deletions Core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# Copyright 2018 Edoardo Pasca
#cmake_minimum_required (VERSION 3.0)

project(RGL_core)
#https://stackoverflow.com/questions/13298504/using-cmake-with-setup-py

# The version number.

#set (CIL_VERSION $ENV{CIL_VERSION} CACHE INTERNAL "Core Imaging Library version" FORCE)

# conda orchestrated build
message("CIL_VERSION ${CIL_VERSION}")
#include (GenerateExportHeader)


find_package(OpenMP REQUIRED)
if (OPENMP_FOUND)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS} ${OpenMP_CXX_FLAGS}")
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_SHARED_LINKER_FLAGS} ${OpenMP_CXX_FLAGS}")
set (CMAKE_STATIC_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_STATIC_LINKER_FLAGS} ${OpenMP_CXX_FLAGS}")

endif()

## Build the regularisers package as a library
message("Creating Regularisers as a shared library")

message("CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}")
message("CMAKE_C_FLAGS ${CMAKE_C_FLAGS}")
message("CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS}")
message("CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS}")
message("CMAKE_STATIC_LINKER_FLAGS ${CMAKE_STATIC_LINKER_FLAGS}")

set(CMAKE_BUILD_TYPE "Release")

if(WIN32)
set (FLAGS "/DWIN32 /EHsc /DCCPi_EXPORTS")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS}")
set (CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS}")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:MSVCRT.lib")

set (EXTRA_LIBRARIES)

message("library lib: ${LIBRARY_LIB}")

elseif(UNIX)
set (FLAGS "-O2 -funsigned-char -Wall -Wl,--no-undefined -DCCPiReconstructionIterative_EXPORTS ")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS}")
set (CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS}")
if (OPENMP_FOUND)
set (EXTRA_LIBRARIES
"gomp"
"m"
)
else()
set (EXTRA_LIBRARIES
"m"
)
endif()
endif()
message("CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}")

## Build the regularisers package as a library
message("Adding regularisers as a shared library")

#set(CMAKE_C_COMPILER /apps/pgi/linux86-64/17.4/bin/pgcc)
#set(CMAKE_C_FLAGS "-acc -Minfo -ta=tesla:cc20 -openmp")
#set(CMAKE_C_FLAGS "-acc -Minfo -ta=multicore -openmp -fPIC")
add_library(ctomophantom "SHARED"
${CMAKE_CURRENT_SOURCE_DIR}/TomoP2DModel_core.c
${CMAKE_CURRENT_SOURCE_DIR}/TomoP2DModelSino_core.c
${CMAKE_CURRENT_SOURCE_DIR}/TomoP3DModel_core.c
${CMAKE_CURRENT_SOURCE_DIR}/utils.c
${CMAKE_CURRENT_SOURCE_DIR}/TomoP2DSinoNum_core.c
)
#add_library(ctomophantom_static "STATIC"
# ${CMAKE_CURRENT_SOURCE_DIR}/TomoP2DModel_core.c
# ${CMAKE_CURRENT_SOURCE_DIR}/TomoP2DModelSino_core.c
# ${CMAKE_CURRENT_SOURCE_DIR}/TomoP3DModel_core.c
# ${CMAKE_CURRENT_SOURCE_DIR}/utils.c
# ${CMAKE_CURRENT_SOURCE_DIR}/TomoP2DSinoNum_core.c
# )
target_link_libraries(ctomophantom ${EXTRA_LIBRARIES} )
include_directories(ctomophantom PUBLIC
${LIBRARY_INC}/include
${CMAKE_CURRENT_SOURCE_DIR}
)

## Install

set(INSTALL_BIN_DIR ${CMAKE_INSTALL_PREFIX}/bin)
set(INSTALL_LIB_DIR ${CMAKE_INSTALL_PREFIX}/lib)
set(INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_PREFIX}/include)

if (UNIX)
message ("I'd install into ${CMAKE_INSTALL_PREFIX}/lib")
install(TARGETS ctomophantom
LIBRARY DESTINATION lib
CONFIGURATIONS ${CMAKE_BUILD_TYPE}
)
elseif(WIN32)
message ("I'd install into ${CMAKE_INSTALL_PREFIX} lib bin")
install(TARGETS ctomophantom
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
CONFIGURATIONS ${CMAKE_BUILD_TYPE}
)
endif()


#install(TARGETS ctomophantom
# LIBRARY DESTINATION "${INSTALL_LIB_DIR}" COMPONENT lib
# PUBLIC_HEADER DESTINATION "${INSTALL_INCLUDE_DIR}" COMPONENT dev
# RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT bin
# ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" COMPONENT lib
# CONFIGURATIONS ${CMAKE_BUILD_TYPE}
# )
17 changes: 6 additions & 11 deletions functions/TomoP2DModelSino_core.c → Core/TomoP2DModelSino_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@
* limitations under the License.
*/

#include <math.h>
#include <stdlib.h>
#include <memory.h>
#include <stdio.h>
#include "omp.h"
#include "utils.h"
#include "TomoP2DModelSino_core.h"

#define M_PI 3.14159265358979323846
#define EPS 0.000000001
Expand All @@ -38,9 +33,9 @@
*/

/* function to build a single sinogram - object */
float TomoP2DObjectSino_core(float *A, long N, long P, float *Th, long AngTot, int CenTypeIn, char *Object, float C0, float x0, float y0, float a, float b, float phi_rot, long tt)
float TomoP2DObjectSino_core(float *A, int N, int P, float *Th, int AngTot, int CenTypeIn, char *Object, float C0, float x0, float y0, float a, float b, float phi_rot, int tt)
{
long i, j;
int i, j;
float *Tomorange_X_Ar=NULL, Tomorange_Xmin, Tomorange_Xmax, Sinorange_Pmax, Sinorange_Pmin, H_p, H_x, C1, a22, b22, phi_rot_radian;
float *Sinorange_P_Ar=NULL, *AnglesRad=NULL;
float AA5, sin_2, cos_2, delta1, delta_sq, first_dr, AA2, AA3, AA6, under_exp, x00, y00;
Expand Down Expand Up @@ -373,7 +368,7 @@ float TomoP2DModelSino_core(float *A, int ModelSelected, int N, int P, float *Th
//mexErrMsgTxt("b (object size) must be positive in [0,2] range");
break; }
//printf("\nObject : %s \nC0 : %f \nx0 : %f \ny0 : %f \na : %f \nb : %f \n", tmpstr2, C0, x0, y0, a, b);
TomoP2DObjectSino_core(A, (long)N, (long)P, Th, (long)AngTot, CenTypeIn, tmpstr2, C0, x0, y0, b, a, -psi_gr1, 0l);
TomoP2DObjectSino_core(A, N, P, Th, AngTot, CenTypeIn, tmpstr2, C0, x0, y0, b, a, -psi_gr1, 0);
}
}
else {
Expand Down Expand Up @@ -433,14 +428,14 @@ float TomoP2DModelSino_core(float *A, int ModelSelected, int N, int P, float *Th
float b_step = (b1 - b)/(steps-1);
float phi_rot_step = (psi_gr1_1 - psi_gr1)/(steps-1);

long tt;
int tt;
float x_t, y_t, a_t, b_t, C_t, phi_t, d_step;
/* initialize */
x_t = x0; y_t = y0; a_t = a; b_t = b; C_t = C0; phi_t = psi_gr1; d_step = d_dist;
/*loop over time frames*/
for(tt=0; tt < steps; tt++) {

TomoP2DObjectSino_core(A, (long)N, (long)P, Th, (long)AngTot, CenTypeIn, tmpstr2, C_t, -y_t, x_t, b_t, a_t, -phi_t, tt);
TomoP2DObjectSino_core(A, N, P, Th, AngTot, CenTypeIn, tmpstr2, C_t, -y_t, x_t, b_t, a_t, -phi_t, tt);

/* calculating new coordinates of an object */
if (distance != 0.0f) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
#include <memory.h>
#include <stdio.h>
#include "omp.h"
#include "CCPiDefines.h"

float TomoP2DModelSino_core(float *A, int ModelSelected, int N, int P, float *Th, int AngTot, int CenTypeIn, char* ModelParametersFilename);
float TomoP2DObjectSino_core(float *A, long N, long P, float *Th, long AngTot, int CenTypeIn, char* Obj, float C0, float x0, float y0, float a, float b, float phi_rot, long tt);
CCPI_EXPORT float TomoP2DModelSino_core(float *A, int ModelSelected, int N, int P, float *Th, int AngTot, int CenTypeIn, char* ModelParametersFilename);
CCPI_EXPORT float TomoP2DObjectSino_core(float *A, int N, int P, float *Th, int AngTot, int CenTypeIn, char* Obj, float C0, float x0, float y0, float a, float b, float phi_rot, int tt);
19 changes: 7 additions & 12 deletions functions/TomoP2DModel_core.c → Core/TomoP2DModel_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@
* limitations under the License.
*/

#include <math.h>
#include <stdlib.h>
#include <memory.h>
#include <stdio.h>
#include "omp.h"
#include "utils.h"
#include "TomoP2DModel_core.h"

#define M_PI 3.14159265358979323846
#define MAXCHAR 1000
Expand All @@ -40,18 +35,18 @@
*/

/* function to build a single object */
float TomoP2DObject_core(float *A, long N, char *Object,
float TomoP2DObject_core(float *A, int N, char *Object,
float C0, /* intensity */
float x0, /* x0 position */
float y0, /* y0 position */
float a , /* a - size object */
float b , /* b - size object */
float phi_rot, /* phi - rotation angle */
long tt /* time frame loop */)
int tt /* time frame loop */)
{
printf ("Base C0 %.2e x0 %.2e y0 %.2e a %.2e b %.2e phi %.2e\n" , C0, x0, y0, a, b, phi_rot);

long i, j;
int i, j;
float *Tomorange_X_Ar=NULL, Tomorange_Xmin, Tomorange_Xmax, H_x, C1, a2, b2, phi_rot_radian, sin_phi, cos_phi;
float *Xdel = NULL, *Ydel = NULL, T;
Tomorange_X_Ar = malloc(N*sizeof(float));
Expand Down Expand Up @@ -236,7 +231,7 @@ float TomoP2DModel_core(float *A, int ModelSelected, int N, char *ModelParameter
//mexErrMsgTxt("Cannot find 'Object' string in parameters file");
break; }
printf ("C0 %.2e x0 %.2e y0 %.2e a %.2e b %.2e phi %.2e\n" , C0, x0, y0, a, b, psi_gr1);
TomoP2DObject_core(A, (long)N, tmpstr2, C0, y0, x0, a, b, psi_gr1, 0l); /* python */
TomoP2DObject_core(A, N, tmpstr2, C0, y0, x0, a, b, psi_gr1, 0); /* python */
}
}
else {
Expand Down Expand Up @@ -292,14 +287,14 @@ float TomoP2DModel_core(float *A, int ModelSelected, int N, char *ModelParameter
float b_step = (b1 - b)/(steps-1);
float phi_rot_step = (psi_gr1_1 - psi_gr1)/(steps-1);

long tt;
int tt;
float x_t, y_t, a_t, b_t, C_t, phi_t, d_step;
/* initialize */
x_t = x0; y_t = y0; a_t = a; b_t = b; C_t = C0; phi_t = psi_gr1; d_step = d_dist;
/*loop over time frames*/
for(tt=0; tt < steps; tt++) {

TomoP2DObject_core(A, (long)N, tmpstr2, C_t, x_t, -y_t, a_t, b_t, phi_t, tt); /* python */
TomoP2DObject_core(A, N, tmpstr2, C_t, x_t, -y_t, a_t, b_t, phi_t, tt); /* python */

/* calculating new coordinates of an object */
if (distance != 0.0f) {
Expand Down
8 changes: 5 additions & 3 deletions functions/TomoP2DModel_core.h → Core/TomoP2DModel_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#include <matrix.h>
//#include <matrix.h>
#include <math.h>
#include <stdlib.h>
#include <memory.h>
#include <stdio.h>
#include "omp.h"
#include "CCPiDefines.h"

float TomoP2DModel_core(float *A, int ModelSelected, int N, char *ModelParametersFilename);
float TomoP2DObject_core(float *A, long N, char *Object, float C0, float x0, float y0, float a, float b, float phi_rot, long tt);

CCPI_EXPORT float TomoP2DModel_core(float *A, int ModelSelected, int N, char *ModelParametersFilename);
CCPI_EXPORT float TomoP2DObject_core(float *A, int N, char *Object, float C0, float x0, float y0, float a, float b, float phi_rot, int tt);
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ limitations under the License.
#include <memory.h>
#include <stdio.h>
#include "omp.h"
#include "CCPiDefines.h"

float TomoP2DSinoNum_core(float *Sinogram, float *Phantom, int dimX, int DetSize, float *Theta, int ThetaLength, int sys);
float BilinearInterpolation(float *Phantom_pad, float *B, int DetSize, float ct, float st);
float padding(float *Phantom, float *Phantom_pad, int DetSize, int PhantSize, int padXY, int sys);
CCPI_EXPORT float TomoP2DSinoNum_core(float *Sinogram, float *Phantom, int dimX, int DetSize, float *Theta, int ThetaLength, int sys);
CCPI_EXPORT float BilinearInterpolation(float *Phantom_pad, float *B, int DetSize, float ct, float st);
CCPI_EXPORT float padding(float *Phantom, float *Phantom_pad, int DetSize, int PhantSize, int padXY, int sys);
Loading

0 comments on commit 8e9d0c3

Please sign in to comment.