30#include "DGtal/base/Common.h"
31#include "DGtal/base/BasicFunctors.h"
32#include "DGtal/helpers/StdDefs.h"
33#include "DGtal/io/readers/GenericReader.h"
34#include "DGtal/io/viewers/PolyscopeViewer.h"
35#include "DGtal/io/readers/PointListReader.h"
36#include "DGtal/io/readers/MeshReader.h"
38#include "DGtal/io/Color.h"
39#include "DGtal/io/colormaps/GradientColorMap.h"
40#include "DGtal/images/ImageSelector.h"
102typedef PolyscopeViewer<> Viewer;
104template <
typename TImage>
106processDisplay(PolyscopeViewer<> &viewer, TImage &image,
107 const typename TImage::Value &thresholdMin,
108 const typename TImage::Value &thresholdMax,
109 unsigned int numDisplayedMax)
111 unsigned int numDisplayed = 0;
112 Domain domain = image.domain();
113 for(Domain::ConstIterator it = domain.begin(), itend=domain.end(); it!=itend; ++it) {
114 typename TImage::Value val= image( (*it) );
115 if(numDisplayed > numDisplayedMax)
118 if(val<=thresholdMax && val >=thresholdMin)
120 viewer << WithQuantity(*it,
"value", val);
129int main(
int argc,
char** argv )
133 app.description(
"Display volume file as a voxel set by using QGLviewer. \n Example: \n \t 3dVolViewer $DGtal/examples/samples/lobster.vol -m 60 -t 10");
134 std::string inputFileName;
135 DGtal::int64_t rescaleInputMin {0};
136 DGtal::int64_t rescaleInputMax {255};
137 double thresholdMin {0};
138 double thresholdMax {255};
139 unsigned int transparency {255};
140 unsigned int numDisplayedMax {500000};
141 std::string displayMesh;
142 std::string snapShotFile;
143 std::vector<unsigned int> colorMesh;
144 std::vector<unsigned int > customBGColor;
146 string inputType {
""};
147 bool interactiveDisplayVoxCoords {
false};
148 bool transIntensity {
false};
149 bool transIntensitySq {
false};
151 app.add_option(
"-i,--input,1", inputFileName,
"vol file (.vol, .longvol .p3d, .pgm3d and if DGTAL_WITH_ITK is selected: dicom, dcm, mha, mhd). For longvol, dicom, dcm, mha or mhd formats, the input values are linearly scaled between 0 and 255." )
153 ->check(CLI::ExistingFile);
155 app.add_option(
"--inputType", inputType,
"to specify the input image type (int or double).")
156 -> check(CLI::IsMember({
"int",
"double"}));
158 app.add_option(
"--thresholdMin,-m", thresholdMin,
"threshold min (excluded) to define binary shape.");
159 app.add_option(
"--thresholdMax,-M", thresholdMax,
"threshold max (included) to define binary shape.");
160 app.add_option(
"--rescaleInputMin", rescaleInputMin,
"min value used to rescale the input intensity (to avoid basic cast into 8 bits image).");
161 app.add_option(
"--rescaleInputMax", rescaleInputMax,
"max value used to rescale the input intensity (to avoid basic cast into 8 bits image).");
162 app.add_option(
"--numMaxVoxel,-n", numDisplayedMax,
"set the maximal voxel number to be displayed.");
163 app.add_option(
"--displayMesh", displayMesh,
"display a Mesh given in OFF or OFS format.");
164 app.add_option(
"--colorMesh", colorMesh,
"set the color of Mesh (given from displayMesh option) : r g b a ")
166 app.add_option(
"--doSnapShotAndExit,-d", snapShotFile,
"save display snapshot into file. Notes that the camera setting is set by default according the last saved configuration (use SHIFT+Key_M to save current camera setting in the Viewer3D). If the camera setting was not saved it will use the default camera setting.");
167 app.add_option(
"--customBGColor,-b", customBGColor,
"set the R, G, B, A components of the colors of the sdp view")
169 app.add_option(
"--transparency,-t", transparency,
"change the defaukt transparency");
170 app.add_flag(
"--transIntensity",transIntensity ,
"Used vocel intensity to define transparency valeue");
171 app.add_flag(
"--transIntensitySq",transIntensitySq ,
"Used squared vocel intensity to define transparency valeue");
172 app.add_flag(
"--interactiveDisplayVoxCoords,-c", interactiveDisplayVoxCoords,
" by using this option the coordinates can be displayed after selection (shift+left click on voxel).");
173 app.get_formatter()->column_width(40);
174 CLI11_PARSE(app, argc, argv);
178 viewer.allowReuseList =
true;
179 typedef ImageContainerBySTLVector < Z3i::Domain, double > Image3D_D;
180 typedef ImageContainerBySTLVector < Z3i::Domain, int > Image3D_I;
181 typedef ImageSelector<Domain, unsigned char>::Type Image;
183 string extension = inputFileName.substr(inputFileName.find_last_of(
".") + 1);
185 std::vector<double> vectValD;
186 std::vector<int> vectValI;
187 std::vector<unsigned char> vectValUC;
191 Image3D_D imageD = Image3D_D(d);
192 Image3D_I imageI = Image3D_I(d);
193 Image image = Image(d);
195 if(extension !=
"sdp")
197 unsigned int numDisplayed=0;
200 if (inputType==
"double")
202 imageD = DGtal::GenericReader<Image3D_D>::import(inputFileName);
203 trace.info() <<
"[done]"<< std::endl;
204 trace.info() <<
"Image loaded: D "<<imageD<< std::endl;
205 processDisplay(viewer, imageD, thresholdMin, thresholdMax, numDisplayedMax);
207 else if (inputType==
"int")
209 imageI= DGtal::GenericReader<Image3D_I>::import(inputFileName);
210 trace.info() <<
"Image loaded: "<<image<< std::endl;
211 processDisplay(viewer, imageI, (
int)thresholdMin, (
int)thresholdMax, numDisplayedMax);
213 typedef DGtal::functors::Rescaling<DGtal::int64_t ,unsigned char > RescalFCT;
214 image = GenericReader< Image >::importWithValueFunctor( inputFileName,RescalFCT(rescaleInputMin,
217 trace.info() <<
"Image loaded: "<<image<< std::endl;
218 processDisplay(viewer, image, thresholdMin, thresholdMax, numDisplayedMax);
221 typedef DGtal::functors::Rescaling<DGtal::int64_t ,unsigned char > RescalFCT;
222 image = GenericReader< Image >::importWithValueFunctor( inputFileName,RescalFCT(rescaleInputMin,
225 trace.info() <<
"Image loaded: "<<image<< std::endl;
226 processDisplay(viewer, image, thresholdMin, thresholdMax, numDisplayedMax);
229 else if(extension==
"sdp")
231 vector<Z3i::RealPoint> vectVoxels = PointListReader<Z3i::RealPoint>::getPointsFromFile(inputFileName);
232 for(
unsigned int i=0;i< vectVoxels.size(); i++){
233 viewer << Z3i::Point(vectVoxels.at(i), functors::Round<>());
237 if(displayMesh !=
"")
239 if(colorMesh.size() != 0)
241 Color c(colorMesh[0], colorMesh[1], colorMesh[2], colorMesh[3]);
245 DGtal::Mesh<Z3i::RealPoint> aMesh(colorMesh.size() == 0);
246 MeshReader<Z3i::RealPoint>::importOFFFile(displayMesh, aMesh);
251 trace.info() <<
"[display ready]"<< std::endl;