DGtalTools 2.0.0
Loading...
Searching...
No Matches
3dVolViewer.cpp
1
28#include <iostream>
29
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"
37
38#include "DGtal/io/Color.h"
39#include "DGtal/io/colormaps/GradientColorMap.h"
40#include "DGtal/images/ImageSelector.h"
41
42#include "CLI11.hpp"
43
44using namespace std;
45using namespace DGtal;
46using namespace Z3i;
47
48
102typedef PolyscopeViewer<> Viewer;
103
104template <typename TImage>
105void
106processDisplay(PolyscopeViewer<> &viewer, TImage &image,
107 const typename TImage::Value &thresholdMin,
108 const typename TImage::Value &thresholdMax,
109 unsigned int numDisplayedMax)
110{
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)
116 break;
117
118 if(val<=thresholdMax && val >=thresholdMin)
119 {
120 viewer << WithQuantity(*it, "value", val);
121 numDisplayed++;
122 }
123 }
124}
125
126
127
128
129int main( int argc, char** argv )
130{
131 // parse command line using CLI ----------------------------------------------
132 CLI::App app;
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;
145
146 string inputType {""};
147 bool interactiveDisplayVoxCoords {false};
148 bool transIntensity {false};
149 bool transIntensitySq {false};
150
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." )
152 ->required()
153 ->check(CLI::ExistingFile);
154#ifdef DGTAL_WITH_ITK
155 app.add_option("--inputType", inputType, "to specify the input image type (int or double).")
156 -> check(CLI::IsMember({"int", "double"}));
157#endif
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 ")
165 ->expected(4);
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")
168 ->expected(3);
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);
175 // END parse command line using CLI ----------------------------------------------
176
177 Viewer viewer;
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;
182
183 string extension = inputFileName.substr(inputFileName.find_last_of(".") + 1);
184
185 std::vector<double> vectValD;
186 std::vector<int> vectValI;
187 std::vector<unsigned char> vectValUC;
188 // Image of different types are pre constructed here else it will be deleted after the type selection
189 // (and it is used in display callback)
190 Z3i::Domain d;
191 Image3D_D imageD = Image3D_D(d);
192 Image3D_I imageI = Image3D_I(d);
193 Image image = Image(d);
194
195 if(extension != "sdp")
196 {
197 unsigned int numDisplayed=0;
198
199#ifdef DGTAL_WITH_ITK
200 if (inputType=="double")
201 {
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);
206 }
207 else if (inputType=="int")
208 {
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);
212 } else {
213 typedef DGtal::functors::Rescaling<DGtal::int64_t ,unsigned char > RescalFCT;
214 image = GenericReader< Image >::importWithValueFunctor( inputFileName,RescalFCT(rescaleInputMin,
215 rescaleInputMax,
216 0, 255) );
217 trace.info() << "Image loaded: "<<image<< std::endl;
218 processDisplay(viewer, image, thresholdMin, thresholdMax, numDisplayedMax);
219 }
220#else
221 typedef DGtal::functors::Rescaling<DGtal::int64_t ,unsigned char > RescalFCT;
222 image = GenericReader< Image >::importWithValueFunctor( inputFileName,RescalFCT(rescaleInputMin,
223 rescaleInputMax,
224 0, 255) );
225 trace.info() << "Image loaded: "<<image<< std::endl;
226 processDisplay(viewer, image, thresholdMin, thresholdMax, numDisplayedMax);
227#endif
228 }
229 else if(extension=="sdp")
230 {
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<>());
234 }
235 }
236
237 if(displayMesh != "")
238 {
239 if(colorMesh.size() != 0)
240 {
241 Color c(colorMesh[0], colorMesh[1], colorMesh[2], colorMesh[3]);
242 viewer.drawColor(c);
243 }
244
245 DGtal::Mesh<Z3i::RealPoint> aMesh(colorMesh.size() == 0);
246 MeshReader<Z3i::RealPoint>::importOFFFile(displayMesh, aMesh);
247 viewer << aMesh;
248 }
249
250 // First display transparency improve
251 trace.info() << "[display ready]"<< std::endl;
252 viewer.show();
253 return 0;
254}
Definition ATu0v1.h:57