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"
39#include "DGtal/io/Color.h"
40#include "DGtal/io/colormaps/GradientColorMap.h"
41#include "DGtal/images/ImageSelector.h"
104typedef PolyscopeViewer<> Viewer;
106template <
typename TImage>
108processDisplay(PolyscopeViewer<> &viewer, TImage &image,
109 const typename TImage::Value &thresholdMin,
110 const typename TImage::Value &thresholdMax,
111 unsigned int numDisplayedMax)
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)
120 if(val<=thresholdMax && val >=thresholdMin)
122 viewer << WithQuantity(*it,
"value", val);
134 ImGuiIO& io = ImGui::GetIO();
138 if (ImGui::IsKeyPressed(ImGuiKey_W)) {
140 polyscope::options::buildGui = show_ui;
148int main(
int argc,
char** argv )
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;
165 string inputType {
""};
166 bool interactiveDisplayVoxCoords {
false};
167 bool transIntensity {
false};
168 bool transIntensitySq {
false};
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." )
172 ->check(CLI::ExistingFile);
174 app.add_option(
"--inputType", inputType,
"to specify the input image type (int or double).")
175 -> check(CLI::IsMember({
"int",
"double"}));
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 ")
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")
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);
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);
205 viewer.allowReuseList =
true;
207 typedef ImageContainerBySTLVector < Z3i::Domain, double > Image3D_D;
208 typedef ImageContainerBySTLVector < Z3i::Domain, int > Image3D_I;
209 typedef ImageSelector<Domain, unsigned char>::Type Image;
211 string extension = inputFileName.substr(inputFileName.find_last_of(
".") + 1);
213 std::vector<double> vectValD;
214 std::vector<int> vectValI;
215 std::vector<unsigned char> vectValUC;
219 Image3D_D imageD = Image3D_D(d);
220 Image3D_I imageI = Image3D_I(d);
221 Image image = Image(d);
223 if(extension !=
"sdp")
225 unsigned int numDisplayed=0;
228 if (inputType==
"double")
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);
235 else if (inputType==
"int")
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);
241 typedef DGtal::functors::Rescaling<DGtal::int64_t ,unsigned char > RescalFCT;
242 image = GenericReader< Image >::importWithValueFunctor( inputFileName,RescalFCT(rescaleInputMin,
245 trace.info() <<
"Image loaded: "<<image<< std::endl;
246 processDisplay(viewer, image, thresholdMin, thresholdMax, numDisplayedMax);
249 typedef DGtal::functors::Rescaling<DGtal::int64_t ,unsigned char > RescalFCT;
250 image = GenericReader< Image >::importWithValueFunctor( inputFileName,RescalFCT(rescaleInputMin,
253 trace.info() <<
"Image loaded: "<<image<< std::endl;
254 processDisplay(viewer, image, thresholdMin, thresholdMax, numDisplayedMax);
257 else if(extension==
"sdp")
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<>());
265 if(displayMesh !=
"")
267 if(colorMesh.size() != 0)
269 Color c(colorMesh[0], colorMesh[1], colorMesh[2], colorMesh[3]);
273 DGtal::Mesh<Z3i::RealPoint> aMesh(colorMesh.size() == 0);
274 MeshReader<Z3i::RealPoint>::importOFFFile(displayMesh, aMesh);
279 trace.info() <<
"[display ready]"<< std::endl;
280 polyscope::state::userCallback = myCallback;