32#include "DGtal/base/Common.h"
33#include "DGtal/base/BasicFunctors.h"
34#include "DGtal/helpers/StdDefs.h"
35#include "DGtal/io/readers/VolReader.h"
36#include "DGtal/io/viewers/PolyscopeViewer.h"
37#include "DGtal/io/readers/PointListReader.h"
38#include "DGtal/io/readers/MeshReader.h"
39#include "DGtal/topology/helpers/Surfaces.h"
40#include "DGtal/topology/SurfelAdjacency.h"
42#include "DGtal/io/Color.h"
43#include "DGtal/io/colormaps/GradientColorMap.h"
44#include "DGtal/io/readers/GenericReader.h"
46#include "DGtal/io/readers/DicomReader.h"
49#include "DGtal/images/ImageSelector.h"
122int main(
int argc,
char** argv )
125 typedef DGtal::ImageContainerBySTLVector<DGtal::Z3i::Domain, unsigned char > Image3D;
126 typedef DGtal::ImageContainerBySTLVector<DGtal::Z2i::Domain, unsigned char > Image2D;
130 std::string inputFileName;
131 std::string inputFileNameSDP;
132 std::string inputFileNameMesh;
134 DGtal::int64_t rescaleInputMin {0};
135 DGtal::int64_t rescaleInputMax {255};
137 bool intergrid {
false};
138 bool emptyMode {
false};
139 bool displayDigitalSurface {
false};
140 bool thresholdImage {
false};
141 bool colorizeCC {
false};
142 int thresholdMin {0};
143 int thresholdMax {255};
144 std::vector<unsigned int> vectSDPIndex {0,1,2};
145 std::vector<unsigned int> colorSDP;
146 std::vector<unsigned int> colorMesh;
151 double ballRadius = {0.0};
152 unsigned char transp {255};
155 app.description(
"Displays volume file as a voxel set by using PolyscopeViewer\n 3dImageViewer $DGtal/examples/samples/lobster.vol --thresholdImage -m 180");
157 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." )
159 ->check(CLI::ExistingFile);
161 app.add_flag(
"--grid", grid ,
"draw slice images using grid mode.");
162 app.add_flag(
"--intergrid", grid ,
"draw slice images using inter grid mode.");
163 app.add_flag(
"--emptyMode", emptyMode,
"remove the default boundingbox display.");
164 app.add_flag(
"--thresholdImage", thresholdImage,
"threshold the image to define binary shape");
165 app.add_option(
"--thresholdMin", thresholdMin,
"threshold min to define binary shape");
166 app.add_option(
"--thresholdMax", thresholdMax,
"threshold maw to define binary shape");
167 app.add_option(
"--displaySDP,s",inputFileNameSDP,
"display a set of discrete points (.sdp)" );
168 app.add_option(
"--SDPindex", vectSDPIndex,
"specify the sdp index.")
170 app.add_option(
"--SDPball",ballRadius,
"use balls to display a set of discrete points (if not set to 0 and used with displaySDP option).");
172 app.add_option(
"--displayMesh", inputFileNameMesh,
"display a Mesh given in OFF or OFS format.");
173 app.add_flag(
"--displayDigitalSurface",displayDigitalSurface,
"display the digital surface instead of display all the set of voxels (used with thresholdImage or displaySDP options)" );
175 app.add_flag(
"--colorizeCC", colorizeCC,
"colorize each Connected Components of the surface displayed by displayDigitalSurface option.");
176 app.add_option(
"--colorSDP,-c", colorSDP,
"set the color discrete points: r g b a ")
178 app.add_option(
"--colorMesh", colorMesh,
"set the color of Mesh (given from displayMesh option) : r g b a ")
181 app.add_option(
"--scaleX,-x", sx,
"set the scale value in the X direction" );
182 app.add_option(
"--scaleY,-y", sy,
"set the scale value in the Y direction" );
183 app.add_option(
"--scaleZ,-z", sy,
"set the scale value in the Z direction" );
184 app.add_option(
"--rescaleInputMin",rescaleInputMin,
"min value used to rescale the input intensity (to avoid basic cast into 8 bits image)." );
185 app.add_option(
"--rescaleInputMax",rescaleInputMax,
"max value used to rescale the input intensity (to avoid basic cast into 8 bits image)." );
186 app.add_option(
"--transparency,-t",transp,
"change the default transparency" );
189 app.get_formatter()->column_width(40);
190 CLI11_PARSE(app, argc, argv);
194 string extension = inputFileName.substr(inputFileName.find_last_of(
".") + 1);
196 PolyscopeViewer<> viewer;
198 typedef DGtal::functors::Rescaling<DGtal::int64_t ,unsigned char > RescalFCT;
199 Image3D image = GenericReader< Image3D >::importWithValueFunctor( inputFileName,RescalFCT(rescaleInputMin,
203 Domain domain = image.domain();
205 trace.info() <<
"Image loaded: "<<image<< std::endl;
209 Z3i::DigitalSet set3d(domain);
212 viewer.newCubeList(
"Threshold image");
213 viewer.allowReuseList =
true;
214 for(Domain::ConstIterator it = domain.begin(), itend=domain.end(); it!=itend; ++it){
215 unsigned char val= image( (*it) );
216 if(val<=thresholdMax && val >=thresholdMin)
218 if(!displayDigitalSurface)
220 viewer << WithQuantity(*it,
"value", val);
227 viewer.endCurrentGroup();
230 if(inputFileNameSDP !=
"" ){
231 if(colorSDP.size()==4){
232 Color c(colorSDP[0], colorSDP[1], colorSDP[2], colorSDP[3]);
236 vector<Z3i::Point> vectVoxels;
237 if(vectSDPIndex.size()==3)
239 vectVoxels = PointListReader<Z3i::Point>::getPointsFromFile(inputFileNameSDP, vectSDPIndex);
242 vectVoxels = PointListReader<Z3i::Point>::getPointsFromFile(inputFileNameSDP);
245 if (ballRadius != 0.0) viewer.drawAsBalls();
246 for(
unsigned int i=0;i< vectVoxels.size(); i++)
248 if(!displayDigitalSurface)
250 viewer << vectVoxels.at(i);
254 set3d.insert(vectVoxels.at(i));
257 viewer.drawAsPaving();
260 if(inputFileNameMesh !=
"")
262 if(colorMesh.size() != 0)
264 Color c(colorMesh[0], colorMesh[1], colorMesh[2], colorMesh[3]);
267 DGtal::Mesh<Z3i::RealPoint> aMesh(colorMesh.size() == 0);
268 MeshReader<Z3i::RealPoint>::importOFFFile(inputFileNameMesh, aMesh);
272 if(displayDigitalSurface)
275 Point low = domain.lowerBound(); low[0]=low[0]-1; low[1]=low[1]-1; low[2]=low[2]-1;
276 Point upp = domain.upperBound(); upp[0]=upp[0]+1; upp[1]=upp[1]+1; upp[2]=upp[2]+1;
277 K.init(low, upp ,
true);
278 SurfelAdjacency<3> SAdj(
true );
279 vector<vector<SCell> > vectConnectedSCell;
280 trace.info() <<
"Extracting surface set ... " ;
281 Surfaces<KSpace>::extractAllConnectedSCell(vectConnectedSCell,K, SAdj, set3d,
true);
282 trace.info()<<
" [done] " <<std::endl;
284 viewer.drawAsSimplified();
285 for(
unsigned int i= 0; i <vectConnectedSCell.size(); i++)
287 for(
unsigned int j= 0; j <vectConnectedSCell.at(i).size(); j++)
289 const auto& toDraw = vectConnectedSCell.at(i).at(j);
292 viewer << WithQuantity(toDraw,
"index", i);
294 else if(colorSDP.size() != 0)
296 Color c(colorSDP[0], colorSDP[1], colorSDP[2], colorSDP[3]);
297 viewer << WithQuantity(toDraw,
"color", c);
307 DGtal::Z3i::Point size = image.domain().upperBound() - image.domain().lowerBound();
308 DGtal::Z3i::Point center = image.domain().lowerBound()+size/2;
309 unsigned int maxDist = std::max(std::max(size[2], size[1]), size[0]);