Skip to content

Commit 18977c1

Browse files
committed
Fail rather then compile stuff with faked TiffUtil methods (when APR_USE_LIBTIFF=OFF)
1 parent 748769a commit 18977c1

File tree

4 files changed

+38
-96
lines changed

4 files changed

+38
-96
lines changed

CMakeLists.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ if (NOT APR_BUILD_SHARED_LIB AND NOT APR_BUILD_STATIC_LIB)
2626
message(FATAL_ERROR "At least one target: APR_BUILD_SHARED_LIB or APR_BUILD_STATIC_LIB must be build!")
2727
endif()
2828
if (NOT APR_USE_LIBTIFF)
29-
if (APR_TESTS OR APR_BUILD_EXAMPLES)
30-
message(FATAL_ERROR "Building tests or examples not possible when APR_USE_LIBTIFF=OFF!")
29+
if (APR_TESTS OR APR_BUILD_EXAMPLES OR APR_BUILD_JAVA_WRAPPERS)
30+
message(FATAL_ERROR "Building tests, examples or java wrappers not possible when APR_USE_LIBTIFF=OFF!")
3131
endif()
3232
endif()
3333

@@ -63,8 +63,6 @@ if(APR_USE_LIBTIFF)
6363
find_package(TIFF)
6464
set(CMAKE_C_FLAGS "${CMAKE_CFLAGS} -DHAVE_LIBTIFF")
6565
set(CMAKE_CXX_FLAGS "${CMAKE_CXXFLAGS} -DHAVE_LIBTIFF")
66-
else()
67-
message(WARNING "LibTIFF support disable, this disables TIFF writing functionality.")
6866
endif()
6967

7068
# Handle OpenMP
@@ -188,7 +186,7 @@ if(APR_BUILD_SHARED_LIB)
188186
set_property(TARGET ${SHARED_TARGET_NAME} PROPERTY VERSION ${APR_VERSION_STRING})
189187
set_property(TARGET ${SHARED_TARGET_NAME} PROPERTY SOVERSION ${APR_VERSION_MAJOR})
190188

191-
target_link_libraries(${SHARED_TARGET_NAME} PRIVATE ${HDF5_LIBRARIES} ${TIFF_LIBRARIES} ${CUDA_CUDART_LIBRARY})
189+
target_link_libraries(${SHARED_TARGET_NAME} PRIVATE ${HDF5_LIBRARIES} ${TIFF_LIBRARIES} ${CUDA_CUDART_LIBRARY} ${ZLIB_LIBRARIES})
192190
if(BLOSC_FOUND)
193191
target_link_libraries(${SHARED_TARGET_NAME} PRIVATE ${BLOSC_LIBRARIES} ${ZLIB_LIBRARIES})
194192
else()

src/algorithm/APRConverter.hpp

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,7 @@ class APRConverter: public LocalIntensityScale, public ComputeGradient, public L
3636
APRTimer allocation_timer;
3737
APRTimer computation_timer;
3838

39-
bool get_apr(APR<ImageType> &aAPR) {
40-
apr = &aAPR;
41-
42-
TiffUtils::TiffInfo inputTiff(par.input_dir + par.input_image_name);
43-
if (!inputTiff.isFileOpened()) return false;
44-
45-
if (inputTiff.iType == TiffUtils::TiffInfo::TiffType::TIFF_UINT8) {
46-
return get_apr_method_from_file<uint8_t>(aAPR, inputTiff);
47-
} else if (inputTiff.iType == TiffUtils::TiffInfo::TiffType::TIFF_FLOAT) {
48-
return get_apr_method_from_file<float>(aAPR, inputTiff);
49-
} else if (inputTiff.iType == TiffUtils::TiffInfo::TiffType::TIFF_UINT16) {
50-
return get_apr_method_from_file<uint16_t>(aAPR, inputTiff);
51-
} else {
52-
std::cerr << "Wrong file type" << std::endl;
53-
return false;
54-
}
55-
};
39+
bool get_apr(APR<ImageType> &aAPR);
5640

5741
//get apr without setting parameters, and with an already loaded image.
5842
template<typename T>
@@ -70,14 +54,34 @@ class APRConverter: public LocalIntensityScale, public ComputeGradient, public L
7054
void init_apr(APR<ImageType>& aAPR, PixelData<T>& input_image);
7155

7256
template<typename T>
73-
bool get_apr_method_from_file(APR<ImageType> &aAPR, const TiffUtils::TiffInfo &aTiffFile);
57+
bool get_apr_method_from_file(APR<ImageType> &aAPR, PixelData<T> input_image);
7458

7559
public:
7660
void get_gradient(PixelData<ImageType> &image_temp, PixelData<ImageType> &grad_temp, PixelData<float> &local_scale_temp, PixelData<float> &local_scale_temp2, float bspline_offset, const APRParameters &par);
7761
void get_local_intensity_scale(PixelData<float> &local_scale_temp, PixelData<float> &local_scale_temp2, const APRParameters &par);
7862
void get_local_particle_cell_set(PixelData<ImageType> &grad_temp, PixelData<float> &local_scale_temp, PixelData<float> &local_scale_temp2);
7963
};
8064

65+
template<typename ImageType>
66+
inline bool APRConverter<ImageType>::get_apr(APR<ImageType> &aAPR) {
67+
apr = &aAPR;
68+
69+
TiffUtils::TiffInfo inputTiff(par.input_dir + par.input_image_name);
70+
if (!inputTiff.isFileOpened()) return false;
71+
72+
73+
if (inputTiff.iType == TiffUtils::TiffInfo::TiffType::TIFF_UINT8) {
74+
return get_apr_method_from_file<uint8_t>(aAPR, TiffUtils::getMesh<uint8_t>(inputTiff));
75+
} else if (inputTiff.iType == TiffUtils::TiffInfo::TiffType::TIFF_FLOAT) {
76+
return get_apr_method_from_file<float>(aAPR, TiffUtils::getMesh<float>(inputTiff));
77+
} else if (inputTiff.iType == TiffUtils::TiffInfo::TiffType::TIFF_UINT16) {
78+
return get_apr_method_from_file<uint16_t>(aAPR, TiffUtils::getMesh<uint16_t>(inputTiff));
79+
} else {
80+
std::cerr << "Wrong file type" << std::endl;
81+
return false;
82+
}
83+
};
84+
8185
template <typename T>
8286
struct MinMax{T min; T max; };
8387

@@ -102,10 +106,10 @@ MinMax<T> getMinMax(const PixelData<T>& input_image) {
102106
* Main method for constructing the APR from an input image
103107
*/
104108
template<typename ImageType> template<typename T>
105-
bool APRConverter<ImageType>::get_apr_method_from_file(APR<ImageType> &aAPR, const TiffUtils::TiffInfo &aTiffFile) {
106-
allocation_timer.start_timer("read tif input image");
107-
PixelData<T> inputImage = TiffUtils::getMesh<T>(aTiffFile);
108-
allocation_timer.stop_timer();
109+
bool APRConverter<ImageType>::get_apr_method_from_file(APR<ImageType> &aAPR, PixelData<T> inputImage) {
110+
// allocation_timer.start_timer("read tif input image");
111+
// PixelData<T> inputImage = TiffUtils::getMesh<T>(aTiffFile);
112+
// allocation_timer.stop_timer();
109113

110114
method_timer.start_timer("calculate automatic parameters");
111115

src/io/TiffUtils.hpp

Lines changed: 7 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
#ifndef TIFF_UTILS_HPP
77
#define TIFF_UTILS_HPP
88

9+
#ifdef HAVE_LIBTIFF
910

1011
#include <string>
11-
#ifdef HAVE_LIBTIFF
12-
#include <tiffio.h>
13-
#endif
12+
#include <tiffio.h>
1413
#include <sstream>
1514
#include "data_structures/Mesh/PixelData.hpp"
1615

@@ -58,9 +57,7 @@ namespace TiffUtils {
5857
outputStr << "NOT SUPPORTED";
5958
}
6059
outputStr << ", Photometric: " << iPhotometric;
61-
#ifdef HAVE_LIBTIFF
6260
outputStr << ", StripSize: " << TIFFStripSize(iFile);
63-
#endif /* HAVE_LIBTIFF */
6461

6562
return outputStr.str();
6663
}
@@ -71,12 +68,7 @@ namespace TiffUtils {
7168
bool isFileOpened() const { return iFile != nullptr; }
7269

7370
TiffType iType = TiffType::TIFF_INVALID;
74-
#ifdef HAVE_LIBTIFF
7571
TIFF *iFile = nullptr;
76-
#else
77-
void* iFile = nullptr;
78-
typedef unsigned int uint32;
79-
#endif /* HAVE_LIBTIFF */
8072
std::string iFileName = "";
8173
uint32 iImgWidth = 0;
8274
uint32 iImgHeight = 0;
@@ -90,12 +82,6 @@ namespace TiffUtils {
9082
TiffInfo(const TiffInfo&) = delete; // make it noncopyable
9183
TiffInfo& operator=(const TiffInfo&) = delete; // make it not assignable
9284

93-
friend std::ostream& operator<<(std::ostream &os, const TiffInfo &obj) {
94-
os << obj.toString();
95-
return os;
96-
}
97-
98-
#ifdef HAVE_LIBTIFF
9985
/**
10086
* opens TIFF
10187
**/
@@ -157,21 +143,12 @@ namespace TiffUtils {
157143
}
158144
}
159145

160-
#else
161-
bool open(const std::string &aFileName) {
162-
std::cerr << "libapr compiled without LibTIFF support, simulating TIFF reader functionality" << std::endl;
163-
std::cerr << "Trying to open file " << aFileName << ", returning false." << std::endl;
164-
return false;
165-
}
166-
167-
void close() {
168-
std::cerr << "libapr compiled without LibTIFF support, simulating TIFF reader functionality" << std::endl;
169-
std::cerr << "Shim-closing TIFF file" << std::endl;
146+
friend std::ostream& operator<<(std::ostream &os, const TiffInfo &obj) {
147+
os << obj.toString();
148+
return os;
170149
}
171-
#endif /* HAVE_LIBTIFF */
172150
};
173151

174-
#ifdef HAVE_LIBTIFF
175152

176153
/**
177154
* Reads TIFF file to mesh
@@ -311,46 +288,8 @@ namespace TiffUtils {
311288
PixelData<uint16_t> mesh16{aData, true /*copy data*/};
312289
saveMeshAsTiff(filename, mesh16);
313290
}
314-
#else
315-
template<typename T>
316-
PixelData<T> getMesh(const std::string &aFileName) {
317-
std::cerr << "libapr compiled without LibTIFF support, simulating TIFF reader functionality" << std::endl;
318-
std::cerr << "getMesh() called for " << &aFileName << ", returning empty mesh." << std::endl;
319-
320-
PixelData<T> mesh(1, 1, 1);
321-
return mesh;
322-
}
323-
324-
template<typename T>
325-
PixelData<T> getMesh(const TiffInfo &aTiff) {
326-
std::cerr << "libapr compiled without LibTIFF support, simulating TIFF reader functionality" << std::endl;
327-
std::cerr << "getMesh() called for TiffInfo, returning empty mesh." << std::endl;
328-
329-
PixelData<T> mesh(1, 1, 1);
330-
return mesh;
331-
}
332-
333-
template<typename T>
334-
void getMesh(const TiffInfo &aTiff, PixelData<T> &aInputMesh) {
335-
std::cerr << "libapr compiled without LibTIFF support, simulating TIFF reader functionality" << std::endl;
336-
std::cerr << "getMesh() called for inputMesh, returning empty inputMesh." << std::endl;
337-
338-
PixelData<T> mesh(1, 1, 1);
339-
aInputMesh.swap(mesh);
340-
}
341-
342-
template<typename T>
343-
void saveMeshAsTiff(const std::string &aFileName, const PixelData<T> &aData) {
344-
std::cerr << "libapr compiled without LibTIFF support, simulating TIFF reader functionality" << std::endl;
345-
std::cerr << "saveMeshAsTiff() called for " << aFileName << ", not doing anything." << std::endl;
346-
}
347-
348-
template<typename T>
349-
void saveMeshAsTiffUint16(const std::string &filename, const PixelData<T> &aData) {
350-
std::cerr << "libapr compiled without LibTIFF support, simulating TIFF reader functionality" << std::endl;
351-
std::cerr << "saveMeshAsTiff() called for " << filename << ", not doing anything." << std::endl;
352-
}
353-
#endif
354291
}
355292

293+
#endif // HAVE_LIBTIFF
294+
356295
#endif

src/numerics/APRRaycaster.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
#include <fstream>
1717
#include <ctime>
1818

19+
#include "../data_structures/APR/ExtraParticleData.hpp"
20+
#include "../data_structures/Mesh/PixelData.hpp"
1921
#include "../data_structures/APR/ExtraPartCellData.hpp"
20-
#include "../data_structures/APR/APR.hpp"
2122

2223
class APRRaycaster {
2324

0 commit comments

Comments
 (0)