00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <iostream>
00028
00029 #include "vlvarlist.h"
00030 #include "vlvolume.h"
00031 #include "vlgenericfactory.h"
00032 #include "vlvoliterator.h"
00033
00034 #include "thresholding.h"
00035
00036
00037 typedef vlGenericFactory<vlVolProcessorThresh> vlVolProcessorThreshFactory;
00038 VL_EXPORT_COMPONENT_FACTORY( thresholder, vlVolProcessorThreshFactory );
00039
00043 vlVolProcessorThresh::vlVolProcessorThresh()
00044 {
00045 infoRef().setVersion(0, 1, 0);
00046 infoRef().setName("Thresholder");
00047 infoRef().setService("Thresholder", "Performs thresholding.");
00048 infoRef().addAuthor("Sarang Lakare");
00049 infoRef().setCopyrightText("2000-2002 Sarang Lakare");
00050 }
00051
00052
00056 vlVolProcessorThresh::~vlVolProcessorThresh()
00057 {
00058 }
00059
00060
00061 void vlVolProcessorThresh::init()
00062 {
00063 configRef().clear();
00064 configRef().add(vol()->dataType(), "thresholdHigh", "Threshold Value - High");
00065 configRef().add(vol()->dataType(), "thresholdLow", "Threshold Value - Low");
00066 vlVolume *vol;
00067 configRef().add(vol, "maskVolume", "Mask volume.");
00068 uint8 inMask(0xFF), outMask(0x00);
00069 configRef().add(inMask, "insideMask", "Mask for voxels inside the region.", true);
00070 configRef().add(outMask, "outsideMask", "Mask for voxels outside the region.", true);
00071 }
00072
00073 template <>
00074 bool vlVolProcessorThresh::runT<uint8>(uint8 & dummy)
00075 {
00076 return (thresholding(dummy));
00077 }
00078
00079 template <>
00080 bool vlVolProcessorThresh::runT<int8>(int8 & dummy)
00081 {
00082 return (thresholding(dummy));
00083 }
00084
00085 template <>
00086 bool vlVolProcessorThresh::runT<uint16>(uint16 & dummy)
00087 {
00088 return (thresholding(dummy));
00089 }
00090
00091 template <>
00092 bool vlVolProcessorThresh::runT<int16>(int16 & dummy)
00093 {
00094 return (thresholding(dummy));
00095 }
00096
00097
00098 template <>
00099 bool vlVolProcessorThresh::runT<uint32>(uint32 & dummy)
00100 {
00101 return (thresholding(dummy));
00102 }
00103
00104
00105 template <>
00106 bool vlVolProcessorThresh::runT<int32>(int32 & dummy)
00107 {
00108 return (thresholding(dummy));
00109 }
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 bool vlVolProcessorThresh::run()
00125 {
00126 if(!vol())
00127 return (false);
00128
00129 bool retValue(false);
00130
00131 callFunctionOnDataTypeNoArgs(vol()->dataType(), retValue, runT);
00132
00133 return (retValue);
00134 }
00135
00136
00137 template <class DataType>
00138 bool vlVolProcessorThresh::runT(DataType & dummy)
00139 {
00140 std::cout << "Cannot apply thresholding on this datatype [" << typeid(DataType).name() << "]" << std::endl;
00141 return (false);
00142 }
00143
00144
00145 template <class DataType>
00146 bool vlVolProcessorThresh::thresholding(DataType & dummy)
00147 {
00148 std::cout << "About to run thresholding.. " << std::endl;
00149
00150 vlVolume *maskVol;
00151
00152 if(!configRef().get("maskVolume", maskVol)) {
00153 std::cout << "ERROR : No mask volume specified." << std::endl;
00154 return (false);
00155 }
00156
00157 if(vol()->dim() != maskVol->dim()) {
00158 std::cout << "ERROR : Mask volume dimensions not same as the volume dimension." << std::endl;
00159 return (false);
00160 }
00161
00162 if(maskVol->dataType() != UnsignedInt8) {
00163 std::cout << "ERROR : Mask volume has to be of unsigned int8 data type." << std::endl;
00164 return (false);
00165 }
00166
00167 DataType threshLow, threshHigh;
00168 uint8 inVoxelMask(0x00);
00169 uint8 outVoxelMask(0x00);
00170
00171 uint64 regionVoxelCount(0);
00172
00173 if(!configRef().get("thresholdHigh", threshHigh)) {
00174 std::cout << "ERROR : Higher threshold not specified." << std::endl;
00175 return (false);
00176 }
00177
00178 if(!configRef().get("thresholdLow", threshLow)) {
00179 std::cout << "ERROR : Lower threshold not specified." << std::endl;
00180 return (false);
00181 }
00182
00183 configRef().get("insideMask", inVoxelMask);
00184 configRef().get("outsideMask", outVoxelMask);
00185
00186
00187 if(threshHigh < threshLow) {
00188 std::cout << "ERROR : thresholdHigh < thresholdLow. This is not allowed." << std::endl;
00189 return (false);
00190 }
00191
00192 std::cout << "Threshold value(s) set to : " << (int)threshLow << " -- " << (int)threshHigh << std::endl;
00193
00194 vlVolIter<DataType> iter(vol());
00195 vlVolIter<uint8> maskIter(maskVol);
00196
00197 do {
00198 DataType voxelValue = iter.get();
00199
00200 if (threshLow <= voxelValue && voxelValue <= threshHigh) {
00201
00202 ++regionVoxelCount;
00203 maskIter.set(inVoxelMask);
00204 } else {
00205 maskIter.set(outVoxelMask);
00206 }
00207 } while(iter.nextXYZ() && maskIter.nextXYZ());
00208
00209 resultsRef().add(regionVoxelCount, "voxelCount", "Count of the voxels in the threshold interval", true);
00210
00211 std::cout << "Total number of voxels in the region : " << regionVoxelCount << std::endl;
00212
00213 std::cout << "\n---- End of Thresholding ---- " << std::endl;
00214
00215 return (true);
00216 }
00217