DGtalTools 2.1.0
Loading...
Searching...
No Matches
3dVolViewer.cpp
1
28#include <iostream>
29#include <sstream>
30
31#include "DGtal/base/Common.h"
32#include "DGtal/base/BasicFunctors.h"
33#include "DGtal/helpers/StdDefs.h"
34#include "DGtal/io/readers/GenericReader.h"
35#include "DGtal/io/viewers/PolyscopeViewer.h"
36#include "DGtal/io/readers/PointListReader.h"
37#include "DGtal/io/readers/MeshReader.h"
38
39#include "DGtal/io/Color.h"
40#include "DGtal/io/colormaps/GradientColorMap.h"
41#include "DGtal/images/ImageSelector.h"
42
43#include "CLI11.hpp"
44
45using namespace std;
46using namespace DGtal;
47using namespace Z3i;
48
49
104typedef PolyscopeViewer<> Viewer;
105
106template <typename TImage>
107void
108processDisplay(PolyscopeViewer<> &viewer, TImage &image,
109 const typename TImage::Value &thresholdMin,
110 const typename TImage::Value &thresholdMax,
111 unsigned int numDisplayedMax)
112{
113 unsigned int numDisplayed = 0;
114 Domain domain = image.domain();
115 for(Domain::ConstIterator it = domain.begin(), itend=domain.end(); it!=itend; ++it) {
116 typename TImage::Value val= image( (*it) );
117 if(numDisplayed > numDisplayedMax)
118 break;
119
120 if(val<=thresholdMax && val >=thresholdMin)
121 {
122 viewer << WithQuantity(*it, "value", val);
123 numDisplayed++;
124 }
125 }
126}
127
128
129
130// Variable globale pour activer/désactiver l'UI
131bool show_ui = false;
132
133void myCallback() {
134 ImGuiIO& io = ImGui::GetIO();
135
136
137 // Si la touche W est enfoncée ce frame
138 if (ImGui::IsKeyPressed(ImGuiKey_W)) {
139 show_ui = !show_ui;
140 polyscope::options::buildGui = show_ui;
141 }
142
143
144}
145
146
147
148int main( int argc, char** argv )
149{
150 // parse command line using CLI ----------------------------------------------
151 CLI::App app;
152 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");
153 std::string inputFileName;
154 DGtal::int64_t rescaleInputMin {0};
155 DGtal::int64_t rescaleInputMax {255};
156 double thresholdMin {0};
157 double thresholdMax {255};
158 unsigned int transparency {255};
159 unsigned int numDisplayedMax {500000};
160 std::string displayMesh;
161 std::string snapShotFile;
162 std::vector<unsigned int> colorMesh;
163 std::vector<unsigned int > customBGColor;
164
165 string inputType {""};
166 bool interactiveDisplayVoxCoords {false};
167 bool transIntensity {false};
168 bool transIntensitySq {false};
169
170 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." )
171 ->required()
172 ->check(CLI::ExistingFile);
173#ifdef DGTAL_WITH_ITK
174 app.add_option("--inputType", inputType, "to specify the input image type (int or double).")
175 -> check(CLI::IsMember({"int", "double"}));
176#endif
177 app.add_option("--thresholdMin,-m", thresholdMin, "threshold min (excluded) to define binary shape.");
178 app.add_option("--thresholdMax,-M", thresholdMax, "threshold max (included) to define binary shape.");
179 app.add_option("--rescaleInputMin", rescaleInputMin, "min value used to rescale the input intensity (to avoid basic cast into 8 bits image).");
180 app.add_option("--rescaleInputMax", rescaleInputMax, "max value used to rescale the input intensity (to avoid basic cast into 8 bits image).");
181 app.add_option("--numMaxVoxel,-n", numDisplayedMax, "set the maximal voxel number to be displayed.");
182 app.add_option("--displayMesh", displayMesh, "display a Mesh given in OFF or OFS format.");
183 app.add_option("--colorMesh", colorMesh, "set the color of Mesh (given from displayMesh option) : r g b a ")
184 ->expected(4);
185 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.");
186 app.add_option("--customBGColor,-b", customBGColor, "set the R, G, B, A components of the colors of the sdp view")
187 ->expected(3);
188 app.add_option("--transparency,-t", transparency, "change the defaukt transparency");
189 app.add_flag("--transIntensity",transIntensity , "Used vocel intensity to define transparency valeue");
190 app.add_flag("--transIntensitySq",transIntensitySq , "Used squared vocel intensity to define transparency valeue");
191 app.add_flag("--interactiveDisplayVoxCoords,-c", interactiveDisplayVoxCoords, " by using this option the coordinates can be displayed after selection (shift+left click on voxel).");
192 app.get_formatter()->column_width(40);
193 CLI11_PARSE(app, argc, argv);
194 // END parse command line using CLI ----------------------------------------------
195 stringstream s;
196 s << "3dVolViewer - DGtalTools: ";
197 string name = inputFileName.substr(inputFileName.find_last_of("/")+1,inputFileName.size()) ;
198 s << " " << name << " (W key to display settings)";
199 polyscope::options::programName = s.str();
200 polyscope::options::buildGui=false;
201 polyscope::options::groundPlaneMode = polyscope::GroundPlaneMode::None;
202 polyscope::view::setNavigateStyle(polyscope::NavigateStyle::Free);
203
204 Viewer viewer;
205 viewer.allowReuseList = true;
206
207 typedef ImageContainerBySTLVector < Z3i::Domain, double > Image3D_D;
208 typedef ImageContainerBySTLVector < Z3i::Domain, int > Image3D_I;
209 typedef ImageSelector<Domain, unsigned char>::Type Image;
210
211 string extension = inputFileName.substr(inputFileName.find_last_of(".") + 1);
212
213 std::vector<double> vectValD;
214 std::vector<int> vectValI;
215 std::vector<unsigned char> vectValUC;
216 // Image of different types are pre constructed here else it will be deleted after the type selection
217 // (and it is used in display callback)
218 Z3i::Domain d;
219 Image3D_D imageD = Image3D_D(d);
220 Image3D_I imageI = Image3D_I(d);
221 Image image = Image(d);
222
223 if(extension != "sdp")
224 {
225 unsigned int numDisplayed=0;
226
227#ifdef DGTAL_WITH_ITK
228 if (inputType=="double")
229 {
230 imageD = DGtal::GenericReader<Image3D_D>::import(inputFileName);
231 trace.info() << "[done]"<< std::endl;
232 trace.info() << "Image loaded: D "<<imageD<< std::endl;
233 processDisplay(viewer, imageD, thresholdMin, thresholdMax, numDisplayedMax);
234 }
235 else if (inputType=="int")
236 {
237 imageI= DGtal::GenericReader<Image3D_I>::import(inputFileName);
238 trace.info() << "Image loaded: "<<image<< std::endl;
239 processDisplay(viewer, imageI, (int)thresholdMin, (int)thresholdMax, numDisplayedMax);
240 } else {
241 typedef DGtal::functors::Rescaling<DGtal::int64_t ,unsigned char > RescalFCT;
242 image = GenericReader< Image >::importWithValueFunctor( inputFileName,RescalFCT(rescaleInputMin,
243 rescaleInputMax,
244 0, 255) );
245 trace.info() << "Image loaded: "<<image<< std::endl;
246 processDisplay(viewer, image, thresholdMin, thresholdMax, numDisplayedMax);
247 }
248#else
249 typedef DGtal::functors::Rescaling<DGtal::int64_t ,unsigned char > RescalFCT;
250 image = GenericReader< Image >::importWithValueFunctor( inputFileName,RescalFCT(rescaleInputMin,
251 rescaleInputMax,
252 0, 255) );
253 trace.info() << "Image loaded: "<<image<< std::endl;
254 processDisplay(viewer, image, thresholdMin, thresholdMax, numDisplayedMax);
255#endif
256 }
257 else if(extension=="sdp")
258 {
259 vector<Z3i::RealPoint> vectVoxels = PointListReader<Z3i::RealPoint>::getPointsFromFile(inputFileName);
260 for(unsigned int i=0;i< vectVoxels.size(); i++){
261 viewer << Z3i::Point(vectVoxels.at(i), functors::Round<>());
262 }
263 }
264
265 if(displayMesh != "")
266 {
267 if(colorMesh.size() != 0)
268 {
269 Color c(colorMesh[0], colorMesh[1], colorMesh[2], colorMesh[3]);
270 viewer.drawColor(c);
271 }
272
273 DGtal::Mesh<Z3i::RealPoint> aMesh(colorMesh.size() == 0);
274 MeshReader<Z3i::RealPoint>::importOFFFile(displayMesh, aMesh);
275 viewer << aMesh;
276 }
277
278 // First display transparency improve
279 trace.info() << "[display ready]"<< std::endl;
280 polyscope::state::userCallback = myCallback;
281 viewer.show();
282 return 0;
283}
Definition ATu0v1.h:57